blob: 5487cd775b6fd9bc7c167bb1d5aea08393181983 [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 },
Samuel Ortiz67fbb162009-11-24 23:59:15 +0100294 [NL80211_ATTR_PMKID] = { .type = NLA_BINARY,
295 .len = WLAN_PMKID_LEN },
Jouni Malinen9588bbd2009-12-23 13:15:41 +0100296 [NL80211_ATTR_DURATION] = { .type = NLA_U32 },
297 [NL80211_ATTR_COOKIE] = { .type = NLA_U64 },
Jouni Malinen13ae75b2009-12-29 12:59:45 +0200298 [NL80211_ATTR_TX_RATES] = { .type = NLA_NESTED },
Jouni Malinen026331c2010-02-15 12:53:10 +0200299 [NL80211_ATTR_FRAME] = { .type = NLA_BINARY,
300 .len = IEEE80211_MAX_DATA_LEN },
301 [NL80211_ATTR_FRAME_MATCH] = { .type = NLA_BINARY, },
Kalle Valoffb9eb32010-02-17 17:58:10 +0200302 [NL80211_ATTR_PS_STATE] = { .type = NLA_U32 },
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +0200303 [NL80211_ATTR_CQM] = { .type = NLA_NESTED, },
Jouni Malinend5cdfac2010-04-04 09:37:19 +0300304 [NL80211_ATTR_LOCAL_STATE_CHANGE] = { .type = NLA_FLAG },
Felix Fietkaufd8aaaf2010-04-27 01:23:35 +0200305 [NL80211_ATTR_AP_ISOLATE] = { .type = NLA_U8 },
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +0300306 [NL80211_ATTR_WIPHY_TX_POWER_SETTING] = { .type = NLA_U32 },
307 [NL80211_ATTR_WIPHY_TX_POWER_LEVEL] = { .type = NLA_U32 },
Johannes Berg2e161f72010-08-12 15:38:38 +0200308 [NL80211_ATTR_FRAME_TYPE] = { .type = NLA_U16 },
Bruno Randolfafe0cbf2010-11-10 12:50:50 +0900309 [NL80211_ATTR_WIPHY_ANTENNA_TX] = { .type = NLA_U32 },
310 [NL80211_ATTR_WIPHY_ANTENNA_RX] = { .type = NLA_U32 },
Felix Fietkau885a46d2010-11-11 15:07:22 +0100311 [NL80211_ATTR_MCAST_RATE] = { .type = NLA_U32 },
Johannes Bergf7ca38d2010-11-25 10:02:29 +0100312 [NL80211_ATTR_OFFCHANNEL_TX_OK] = { .type = NLA_FLAG },
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100313 [NL80211_ATTR_KEY_DEFAULT_TYPES] = { .type = NLA_NESTED },
Johannes Bergff1b6e62011-05-04 15:37:28 +0200314 [NL80211_ATTR_WOWLAN_TRIGGERS] = { .type = NLA_NESTED },
Javier Cardona9c3990a2011-05-03 16:57:11 -0700315 [NL80211_ATTR_STA_PLINK_STATE] = { .type = NLA_U8 },
Luciano Coelhobbe6ad62011-05-11 17:09:37 +0300316 [NL80211_ATTR_SCHED_SCAN_INTERVAL] = { .type = NLA_U32 },
Johannes Berge5497d72011-07-05 16:35:40 +0200317 [NL80211_ATTR_REKEY_DATA] = { .type = NLA_NESTED },
Johannes Berg34850ab2011-07-18 18:08:35 +0200318 [NL80211_ATTR_SCAN_SUPP_RATES] = { .type = NLA_NESTED },
Jouni Malinen32e9de82011-08-10 23:53:31 +0300319 [NL80211_ATTR_HIDDEN_SSID] = { .type = NLA_U32 },
Jouni Malinen9946ecf2011-08-10 23:55:56 +0300320 [NL80211_ATTR_IE_PROBE_RESP] = { .type = NLA_BINARY,
321 .len = IEEE80211_MAX_DATA_LEN },
322 [NL80211_ATTR_IE_ASSOC_RESP] = { .type = NLA_BINARY,
323 .len = IEEE80211_MAX_DATA_LEN },
Vivek Natarajanf4b34b52011-08-29 14:23:03 +0530324 [NL80211_ATTR_ROAM_SUPPORT] = { .type = NLA_FLAG },
Luciano Coelhoa1f1c212011-08-31 16:01:48 +0300325 [NL80211_ATTR_SCHED_SCAN_MATCH] = { .type = NLA_NESTED },
Rajkumar Manoharane9f935e2011-09-25 14:53:30 +0530326 [NL80211_ATTR_TX_NO_CCK_RATE] = { .type = NLA_FLAG },
Arik Nemtsov109086c2011-09-28 14:12:50 +0300327 [NL80211_ATTR_TDLS_ACTION] = { .type = NLA_U8 },
328 [NL80211_ATTR_TDLS_DIALOG_TOKEN] = { .type = NLA_U8 },
329 [NL80211_ATTR_TDLS_OPERATION] = { .type = NLA_U8 },
330 [NL80211_ATTR_TDLS_SUPPORT] = { .type = NLA_FLAG },
331 [NL80211_ATTR_TDLS_EXTERNAL_SETUP] = { .type = NLA_FLAG },
Arik Nemtsov31fa97c2014-06-11 17:18:21 +0300332 [NL80211_ATTR_TDLS_INITIATOR] = { .type = NLA_FLAG },
Johannes Berge247bd902011-11-04 11:18:21 +0100333 [NL80211_ATTR_DONT_WAIT_FOR_ACK] = { .type = NLA_FLAG },
Arik Nemtsov00f740e2011-11-10 11:28:56 +0200334 [NL80211_ATTR_PROBE_RESP] = { .type = NLA_BINARY,
335 .len = IEEE80211_MAX_DATA_LEN },
Luis R. Rodriguez8b60b072011-10-11 10:59:02 -0700336 [NL80211_ATTR_DFS_REGION] = { .type = NLA_U8 },
Ben Greear7e7c8922011-11-18 11:31:59 -0800337 [NL80211_ATTR_DISABLE_HT] = { .type = NLA_FLAG },
338 [NL80211_ATTR_HT_CAPABILITY_MASK] = {
339 .len = NL80211_HT_CAPABILITY_LEN
340 },
Simon Wunderlich1d9d9212011-11-18 14:20:43 +0100341 [NL80211_ATTR_NOACK_MAP] = { .type = NLA_U16 },
Vasanthakumar Thiagarajan1b658f12012-03-02 15:50:02 +0530342 [NL80211_ATTR_INACTIVITY_TIMEOUT] = { .type = NLA_U16 },
Bala Shanmugam4486ea92012-03-07 17:27:12 +0530343 [NL80211_ATTR_BG_SCAN_PERIOD] = { .type = NLA_U16 },
Johannes Berg89a54e42012-06-15 14:33:17 +0200344 [NL80211_ATTR_WDEV] = { .type = NLA_U64 },
Luis R. Rodriguez57b5ce02012-07-12 11:49:18 -0700345 [NL80211_ATTR_USER_REG_HINT_TYPE] = { .type = NLA_U32 },
Jouni Malinen11b6b5a2016-10-27 00:41:58 +0300346 [NL80211_ATTR_AUTH_DATA] = { .type = NLA_BINARY, },
Mahesh Palivelaf461be3e2012-10-11 08:04:52 +0000347 [NL80211_ATTR_VHT_CAPABILITY] = { .len = NL80211_VHT_CAPABILITY_LEN },
Sam Lefflered4737712012-10-11 21:03:31 -0700348 [NL80211_ATTR_SCAN_FLAGS] = { .type = NLA_U32 },
Johannes Berg53cabad2012-11-14 15:17:28 +0100349 [NL80211_ATTR_P2P_CTWINDOW] = { .type = NLA_U8 },
350 [NL80211_ATTR_P2P_OPPPS] = { .type = NLA_U8 },
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +0530351 [NL80211_ATTR_ACL_POLICY] = {. type = NLA_U32 },
352 [NL80211_ATTR_MAC_ADDRS] = { .type = NLA_NESTED },
Jouni Malinen9d62a982013-02-14 21:10:13 +0200353 [NL80211_ATTR_STA_CAPABILITY] = { .type = NLA_U16 },
354 [NL80211_ATTR_STA_EXT_CAPABILITY] = { .type = NLA_BINARY, },
Johannes Berg3713b4e2013-02-14 16:19:38 +0100355 [NL80211_ATTR_SPLIT_WIPHY_DUMP] = { .type = NLA_FLAG, },
Johannes Bergee2aca32013-02-21 17:36:01 +0100356 [NL80211_ATTR_DISABLE_VHT] = { .type = NLA_FLAG },
357 [NL80211_ATTR_VHT_CAPABILITY_MASK] = {
358 .len = NL80211_VHT_CAPABILITY_LEN,
359 },
Jouni Malinen355199e2013-02-27 17:14:27 +0200360 [NL80211_ATTR_MDID] = { .type = NLA_U16 },
361 [NL80211_ATTR_IE_RIC] = { .type = NLA_BINARY,
362 .len = IEEE80211_MAX_DATA_LEN },
Jouni Malinen5e4b6f52013-05-16 20:11:08 +0300363 [NL80211_ATTR_PEER_AID] = { .type = NLA_U16 },
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +0200364 [NL80211_ATTR_CH_SWITCH_COUNT] = { .type = NLA_U32 },
365 [NL80211_ATTR_CH_SWITCH_BLOCK_TX] = { .type = NLA_FLAG },
366 [NL80211_ATTR_CSA_IES] = { .type = NLA_NESTED },
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +0300367 [NL80211_ATTR_CSA_C_OFF_BEACON] = { .type = NLA_BINARY },
368 [NL80211_ATTR_CSA_C_OFF_PRESP] = { .type = NLA_BINARY },
Sunil Duttc01fc9a2013-10-09 20:45:21 +0530369 [NL80211_ATTR_STA_SUPPORTED_CHANNELS] = { .type = NLA_BINARY },
370 [NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES] = { .type = NLA_BINARY },
Simon Wunderlich5336fa82013-10-07 18:41:05 +0200371 [NL80211_ATTR_HANDLE_DFS] = { .type = NLA_FLAG },
Marek Kwaczynski60f4a7b2013-12-03 10:04:59 +0100372 [NL80211_ATTR_OPMODE_NOTIF] = { .type = NLA_U8 },
Johannes Bergad7e7182013-11-13 13:37:47 +0100373 [NL80211_ATTR_VENDOR_ID] = { .type = NLA_U32 },
374 [NL80211_ATTR_VENDOR_SUBCMD] = { .type = NLA_U32 },
375 [NL80211_ATTR_VENDOR_DATA] = { .type = NLA_BINARY },
Kyeyoon Parkfa9ffc72013-12-16 23:01:30 -0800376 [NL80211_ATTR_QOS_MAP] = { .type = NLA_BINARY,
377 .len = IEEE80211_QOS_MAP_LEN_MAX },
Jouni Malinen1df4a512014-01-15 00:00:47 +0200378 [NL80211_ATTR_MAC_HINT] = { .len = ETH_ALEN },
379 [NL80211_ATTR_WIPHY_FREQ_HINT] = { .type = NLA_U32 },
Sunil Dutt Undekaridf942e72014-02-20 16:22:09 +0530380 [NL80211_ATTR_TDLS_PEER_CAPABILITY] = { .type = NLA_U32 },
Jukka Rissanen18e5ca62014-11-13 17:25:14 +0200381 [NL80211_ATTR_SOCKET_OWNER] = { .type = NLA_FLAG },
Andrei Otcheretianski34d22ce2014-05-09 14:11:44 +0300382 [NL80211_ATTR_CSA_C_OFFSETS_TX] = { .type = NLA_BINARY },
Assaf Kraussbab5ab72014-09-03 15:25:01 +0300383 [NL80211_ATTR_USE_RRM] = { .type = NLA_FLAG },
Johannes Berg960d01a2014-09-09 22:55:35 +0300384 [NL80211_ATTR_TSID] = { .type = NLA_U8 },
385 [NL80211_ATTR_USER_PRIO] = { .type = NLA_U8 },
386 [NL80211_ATTR_ADMITTED_TIME] = { .type = NLA_U16 },
Eliad Peller18998c32014-09-10 14:07:34 +0300387 [NL80211_ATTR_SMPS_MODE] = { .type = NLA_U8 },
Johannes Bergad2b26a2014-06-12 21:39:05 +0200388 [NL80211_ATTR_MAC_MASK] = { .len = ETH_ALEN },
Arik Nemtsov1bdd7162014-12-15 19:26:01 +0200389 [NL80211_ATTR_WIPHY_SELF_MANAGED_REG] = { .type = NLA_FLAG },
Vadim Kochan4b681c82015-01-12 16:34:05 +0200390 [NL80211_ATTR_NETNS_FD] = { .type = NLA_U32 },
Luciano Coelho9c748932015-01-16 16:04:09 +0200391 [NL80211_ATTR_SCHED_SCAN_DELAY] = { .type = NLA_U32 },
Ilan peer05050752015-03-04 00:32:06 -0500392 [NL80211_ATTR_REG_INDOOR] = { .type = NLA_FLAG },
Lior David34d50512016-01-28 10:58:25 +0200393 [NL80211_ATTR_PBSS] = { .type = NLA_FLAG },
Arend van Spriel38de03d2016-03-02 20:37:18 +0100394 [NL80211_ATTR_BSS_SELECT] = { .type = NLA_NESTED },
Ayala Beker17b94242016-03-17 15:41:38 +0200395 [NL80211_ATTR_STA_SUPPORT_P2P_PS] = { .type = NLA_U8 },
Aviya Erenfeldc6e6a0c2016-07-05 15:23:08 +0300396 [NL80211_ATTR_MU_MIMO_GROUP_DATA] = {
397 .len = VHT_MUMIMO_GROUPS_DATA_LEN
398 },
399 [NL80211_ATTR_MU_MIMO_FOLLOW_MAC_ADDR] = { .len = ETH_ALEN },
Ayala Bekercb3b7d82016-09-20 17:31:13 +0300400 [NL80211_ATTR_NAN_MASTER_PREF] = { .type = NLA_U8 },
Luca Coelho85859892017-02-08 15:00:34 +0200401 [NL80211_ATTR_BANDS] = { .type = NLA_U32 },
Ayala Bekera442b762016-09-20 17:31:15 +0300402 [NL80211_ATTR_NAN_FUNC] = { .type = NLA_NESTED },
Jouni Malinen348bd452016-10-27 00:42:03 +0300403 [NL80211_ATTR_FILS_KEK] = { .type = NLA_BINARY,
404 .len = FILS_MAX_KEK_LEN },
405 [NL80211_ATTR_FILS_NONCES] = { .len = 2 * FILS_NONCE_LEN },
Michael Braunce0ce132016-10-10 19:12:22 +0200406 [NL80211_ATTR_MULTICAST_TO_UNICAST_ENABLED] = { .type = NLA_FLAG, },
Vamsi Krishna2fa436b2016-12-02 23:59:08 +0200407 [NL80211_ATTR_BSSID] = { .len = ETH_ALEN },
vamsi krishnabf95ecd2017-01-13 01:12:20 +0200408 [NL80211_ATTR_SCHED_SCAN_RELATIVE_RSSI] = { .type = NLA_S8 },
409 [NL80211_ATTR_SCHED_SCAN_RSSI_ADJUST] = {
410 .len = sizeof(struct nl80211_bss_select_rssi_adjust)
411 },
Purushottam Kushwaha3093ebbeab2017-01-13 01:12:21 +0200412 [NL80211_ATTR_TIMEOUT_REASON] = { .type = NLA_U32 },
Vidyullatha Kanchanapallya3caf742017-03-31 00:22:34 +0300413 [NL80211_ATTR_FILS_ERP_USERNAME] = { .type = NLA_BINARY,
414 .len = FILS_ERP_MAX_USERNAME_LEN },
415 [NL80211_ATTR_FILS_ERP_REALM] = { .type = NLA_BINARY,
416 .len = FILS_ERP_MAX_REALM_LEN },
417 [NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM] = { .type = NLA_U16 },
418 [NL80211_ATTR_FILS_ERP_RRK] = { .type = NLA_BINARY,
419 .len = FILS_ERP_MAX_RRK_LEN },
420 [NL80211_ATTR_FILS_CACHE_ID] = { .len = 2 },
421 [NL80211_ATTR_PMK] = { .type = NLA_BINARY, .len = PMK_MAX_LEN },
Arend Van Sprielca986ad2017-04-21 13:05:00 +0100422 [NL80211_ATTR_SCHED_SCAN_MULTI] = { .type = NLA_FLAG },
Johannes Berg55682962007-09-20 13:09:35 -0400423};
424
Johannes Berge31b8212010-10-05 19:39:30 +0200425/* policy for the key attributes */
Alexey Dobriyanb54452b2010-02-18 08:14:31 +0000426static const struct nla_policy nl80211_key_policy[NL80211_KEY_MAX + 1] = {
Johannes Bergfffd0932009-07-08 14:22:54 +0200427 [NL80211_KEY_DATA] = { .type = NLA_BINARY, .len = WLAN_MAX_KEY_LEN },
Johannes Bergb9454e82009-07-08 13:29:08 +0200428 [NL80211_KEY_IDX] = { .type = NLA_U8 },
429 [NL80211_KEY_CIPHER] = { .type = NLA_U32 },
Jouni Malinen81962262011-11-02 23:36:31 +0200430 [NL80211_KEY_SEQ] = { .type = NLA_BINARY, .len = 16 },
Johannes Bergb9454e82009-07-08 13:29:08 +0200431 [NL80211_KEY_DEFAULT] = { .type = NLA_FLAG },
432 [NL80211_KEY_DEFAULT_MGMT] = { .type = NLA_FLAG },
Johannes Berge31b8212010-10-05 19:39:30 +0200433 [NL80211_KEY_TYPE] = { .type = NLA_U32 },
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100434 [NL80211_KEY_DEFAULT_TYPES] = { .type = NLA_NESTED },
435};
436
437/* policy for the key default flags */
438static const struct nla_policy
439nl80211_key_default_policy[NUM_NL80211_KEY_DEFAULT_TYPES] = {
440 [NL80211_KEY_DEFAULT_TYPE_UNICAST] = { .type = NLA_FLAG },
441 [NL80211_KEY_DEFAULT_TYPE_MULTICAST] = { .type = NLA_FLAG },
Johannes Bergb9454e82009-07-08 13:29:08 +0200442};
443
Johannes Bergf83ace32016-10-17 08:04:07 +0200444#ifdef CONFIG_PM
Johannes Bergff1b6e62011-05-04 15:37:28 +0200445/* policy for WoWLAN attributes */
446static const struct nla_policy
447nl80211_wowlan_policy[NUM_NL80211_WOWLAN_TRIG] = {
448 [NL80211_WOWLAN_TRIG_ANY] = { .type = NLA_FLAG },
449 [NL80211_WOWLAN_TRIG_DISCONNECT] = { .type = NLA_FLAG },
450 [NL80211_WOWLAN_TRIG_MAGIC_PKT] = { .type = NLA_FLAG },
451 [NL80211_WOWLAN_TRIG_PKT_PATTERN] = { .type = NLA_NESTED },
Johannes Berg77dbbb12011-07-13 10:48:55 +0200452 [NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE] = { .type = NLA_FLAG },
453 [NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST] = { .type = NLA_FLAG },
454 [NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE] = { .type = NLA_FLAG },
455 [NL80211_WOWLAN_TRIG_RFKILL_RELEASE] = { .type = NLA_FLAG },
Johannes Berg2a0e0472013-01-23 22:57:40 +0100456 [NL80211_WOWLAN_TRIG_TCP_CONNECTION] = { .type = NLA_NESTED },
Luciano Coelho8cd4d452014-09-17 11:55:28 +0300457 [NL80211_WOWLAN_TRIG_NET_DETECT] = { .type = NLA_NESTED },
Johannes Berg2a0e0472013-01-23 22:57:40 +0100458};
459
460static const struct nla_policy
461nl80211_wowlan_tcp_policy[NUM_NL80211_WOWLAN_TCP] = {
462 [NL80211_WOWLAN_TCP_SRC_IPV4] = { .type = NLA_U32 },
463 [NL80211_WOWLAN_TCP_DST_IPV4] = { .type = NLA_U32 },
464 [NL80211_WOWLAN_TCP_DST_MAC] = { .len = ETH_ALEN },
465 [NL80211_WOWLAN_TCP_SRC_PORT] = { .type = NLA_U16 },
466 [NL80211_WOWLAN_TCP_DST_PORT] = { .type = NLA_U16 },
467 [NL80211_WOWLAN_TCP_DATA_PAYLOAD] = { .len = 1 },
468 [NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ] = {
469 .len = sizeof(struct nl80211_wowlan_tcp_data_seq)
470 },
471 [NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN] = {
472 .len = sizeof(struct nl80211_wowlan_tcp_data_token)
473 },
474 [NL80211_WOWLAN_TCP_DATA_INTERVAL] = { .type = NLA_U32 },
475 [NL80211_WOWLAN_TCP_WAKE_PAYLOAD] = { .len = 1 },
476 [NL80211_WOWLAN_TCP_WAKE_MASK] = { .len = 1 },
Johannes Bergff1b6e62011-05-04 15:37:28 +0200477};
Johannes Bergf83ace32016-10-17 08:04:07 +0200478#endif /* CONFIG_PM */
Johannes Bergff1b6e62011-05-04 15:37:28 +0200479
Amitkumar Karwarbe29b99a2013-06-28 11:51:26 -0700480/* policy for coalesce rule attributes */
481static const struct nla_policy
482nl80211_coalesce_policy[NUM_NL80211_ATTR_COALESCE_RULE] = {
483 [NL80211_ATTR_COALESCE_RULE_DELAY] = { .type = NLA_U32 },
484 [NL80211_ATTR_COALESCE_RULE_CONDITION] = { .type = NLA_U32 },
485 [NL80211_ATTR_COALESCE_RULE_PKT_PATTERN] = { .type = NLA_NESTED },
486};
487
Johannes Berge5497d72011-07-05 16:35:40 +0200488/* policy for GTK rekey offload attributes */
489static const struct nla_policy
490nl80211_rekey_policy[NUM_NL80211_REKEY_DATA] = {
491 [NL80211_REKEY_DATA_KEK] = { .len = NL80211_KEK_LEN },
492 [NL80211_REKEY_DATA_KCK] = { .len = NL80211_KCK_LEN },
493 [NL80211_REKEY_DATA_REPLAY_CTR] = { .len = NL80211_REPLAY_CTR_LEN },
494};
495
Luciano Coelhoa1f1c212011-08-31 16:01:48 +0300496static const struct nla_policy
497nl80211_match_policy[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1] = {
Johannes Berg4a4ab0d2012-06-13 11:17:11 +0200498 [NL80211_SCHED_SCAN_MATCH_ATTR_SSID] = { .type = NLA_BINARY,
Luciano Coelhoa1f1c212011-08-31 16:01:48 +0300499 .len = IEEE80211_MAX_SSID_LEN },
Arend Van Spriel3007e352017-04-21 13:05:01 +0100500 [NL80211_SCHED_SCAN_MATCH_ATTR_BSSID] = { .len = ETH_ALEN },
Thomas Pedersen88e920b2012-06-21 11:09:54 -0700501 [NL80211_SCHED_SCAN_MATCH_ATTR_RSSI] = { .type = NLA_U32 },
Luciano Coelhoa1f1c212011-08-31 16:01:48 +0300502};
503
Avraham Stern3b06d272015-10-12 09:51:34 +0300504static const struct nla_policy
505nl80211_plan_policy[NL80211_SCHED_SCAN_PLAN_MAX + 1] = {
506 [NL80211_SCHED_SCAN_PLAN_INTERVAL] = { .type = NLA_U32 },
507 [NL80211_SCHED_SCAN_PLAN_ITERATIONS] = { .type = NLA_U32 },
508};
509
Arend van Spriel38de03d2016-03-02 20:37:18 +0100510static const struct nla_policy
511nl80211_bss_select_policy[NL80211_BSS_SELECT_ATTR_MAX + 1] = {
512 [NL80211_BSS_SELECT_ATTR_RSSI] = { .type = NLA_FLAG },
513 [NL80211_BSS_SELECT_ATTR_BAND_PREF] = { .type = NLA_U32 },
514 [NL80211_BSS_SELECT_ATTR_RSSI_ADJUST] = {
515 .len = sizeof(struct nl80211_bss_select_rssi_adjust)
516 },
517};
518
Ayala Bekera442b762016-09-20 17:31:15 +0300519/* policy for NAN function attributes */
520static const struct nla_policy
521nl80211_nan_func_policy[NL80211_NAN_FUNC_ATTR_MAX + 1] = {
522 [NL80211_NAN_FUNC_TYPE] = { .type = NLA_U8 },
523 [NL80211_NAN_FUNC_SERVICE_ID] = { .type = NLA_BINARY,
524 .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
Johannes Berg97990a02013-04-19 01:02:55 +0200552static int nl80211_prepare_wdev_dump(struct sk_buff *skb,
553 struct netlink_callback *cb,
554 struct cfg80211_registered_device **rdev,
555 struct wireless_dev **wdev)
Holger Schuriga0438972009-11-11 11:30:02 +0100556{
Johannes Berg67748892010-10-04 21:14:06 +0200557 int err;
558
Johannes Berg97990a02013-04-19 01:02:55 +0200559 if (!cb->args[0]) {
560 err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize,
Johannes Bergc90c39d2016-10-24 14:40:01 +0200561 genl_family_attrbuf(&nl80211_fam),
Johannes Bergfceb6432017-04-12 14:34:07 +0200562 nl80211_fam.maxattr, nl80211_policy, NULL);
Johannes Berg97990a02013-04-19 01:02:55 +0200563 if (err)
Johannes Bergea90e0d2017-03-15 14:26:04 +0100564 return err;
Johannes Berg97990a02013-04-19 01:02:55 +0200565
Johannes Bergc90c39d2016-10-24 14:40:01 +0200566 *wdev = __cfg80211_wdev_from_attrs(
567 sock_net(skb->sk),
568 genl_family_attrbuf(&nl80211_fam));
Johannes Bergea90e0d2017-03-15 14:26:04 +0100569 if (IS_ERR(*wdev))
570 return PTR_ERR(*wdev);
Zhao, Gangf26cbf42014-04-21 12:53:03 +0800571 *rdev = wiphy_to_rdev((*wdev)->wiphy);
Johannes Bergc319d502013-07-30 22:34:28 +0200572 /* 0 is the first index - add 1 to parse only once */
573 cb->args[0] = (*rdev)->wiphy_idx + 1;
Johannes Berg97990a02013-04-19 01:02:55 +0200574 cb->args[1] = (*wdev)->identifier;
575 } else {
Johannes Bergc319d502013-07-30 22:34:28 +0200576 /* subtract the 1 again here */
577 struct wiphy *wiphy = wiphy_idx_to_wiphy(cb->args[0] - 1);
Johannes Berg97990a02013-04-19 01:02:55 +0200578 struct wireless_dev *tmp;
579
Johannes Bergea90e0d2017-03-15 14:26:04 +0100580 if (!wiphy)
581 return -ENODEV;
Zhao, Gangf26cbf42014-04-21 12:53:03 +0800582 *rdev = wiphy_to_rdev(wiphy);
Johannes Berg97990a02013-04-19 01:02:55 +0200583 *wdev = NULL;
584
Johannes Berg53873f12016-05-03 16:52:04 +0300585 list_for_each_entry(tmp, &(*rdev)->wiphy.wdev_list, list) {
Johannes Berg97990a02013-04-19 01:02:55 +0200586 if (tmp->identifier == cb->args[1]) {
587 *wdev = tmp;
588 break;
589 }
590 }
Johannes Berg97990a02013-04-19 01:02:55 +0200591
Johannes Bergea90e0d2017-03-15 14:26:04 +0100592 if (!*wdev)
593 return -ENODEV;
Johannes Berg67748892010-10-04 21:14:06 +0200594 }
595
Johannes Berg67748892010-10-04 21:14:06 +0200596 return 0;
Johannes Berg67748892010-10-04 21:14:06 +0200597}
598
Johannes Bergf4a11bb2009-03-27 12:40:28 +0100599/* IE validation */
600static bool is_valid_ie_attr(const struct nlattr *attr)
601{
602 const u8 *pos;
603 int len;
604
605 if (!attr)
606 return true;
607
608 pos = nla_data(attr);
609 len = nla_len(attr);
610
611 while (len) {
612 u8 elemlen;
613
614 if (len < 2)
615 return false;
616 len -= 2;
617
618 elemlen = pos[1];
619 if (elemlen > len)
620 return false;
621
622 len -= elemlen;
623 pos += 2 + elemlen;
624 }
625
626 return true;
627}
628
Johannes Berg55682962007-09-20 13:09:35 -0400629/* message building helper */
Eric W. Biederman15e47302012-09-07 20:12:54 +0000630static inline void *nl80211hdr_put(struct sk_buff *skb, u32 portid, u32 seq,
Johannes Berg55682962007-09-20 13:09:35 -0400631 int flags, u8 cmd)
632{
633 /* since there is no private header just add the generic one */
Eric W. Biederman15e47302012-09-07 20:12:54 +0000634 return genlmsg_put(skb, portid, seq, &nl80211_fam, flags, cmd);
Johannes Berg55682962007-09-20 13:09:35 -0400635}
636
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400637static int nl80211_msg_put_channel(struct sk_buff *msg,
Johannes Bergcdc89b92013-02-18 23:54:36 +0100638 struct ieee80211_channel *chan,
639 bool large)
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400640{
Rostislav Lisovyea077c12014-04-15 14:37:55 +0200641 /* Some channels must be completely excluded from the
642 * list to protect old user-space tools from breaking
643 */
644 if (!large && chan->flags &
645 (IEEE80211_CHAN_NO_10MHZ | IEEE80211_CHAN_NO_20MHZ))
646 return 0;
647
David S. Miller9360ffd2012-03-29 04:41:26 -0400648 if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_FREQ,
649 chan->center_freq))
650 goto nla_put_failure;
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400651
David S. Miller9360ffd2012-03-29 04:41:26 -0400652 if ((chan->flags & IEEE80211_CHAN_DISABLED) &&
653 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_DISABLED))
654 goto nla_put_failure;
Luis R. Rodriguez8fe02e12013-10-21 19:22:25 +0200655 if (chan->flags & IEEE80211_CHAN_NO_IR) {
656 if (nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_IR))
657 goto nla_put_failure;
658 if (nla_put_flag(msg, __NL80211_FREQUENCY_ATTR_NO_IBSS))
659 goto nla_put_failure;
660 }
Johannes Bergcdc89b92013-02-18 23:54:36 +0100661 if (chan->flags & IEEE80211_CHAN_RADAR) {
662 if (nla_put_flag(msg, NL80211_FREQUENCY_ATTR_RADAR))
663 goto nla_put_failure;
664 if (large) {
665 u32 time;
666
667 time = elapsed_jiffies_msecs(chan->dfs_state_entered);
668
669 if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_DFS_STATE,
670 chan->dfs_state))
671 goto nla_put_failure;
672 if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_DFS_TIME,
673 time))
674 goto nla_put_failure;
Janusz Dziedzic089027e2014-02-21 19:46:12 +0100675 if (nla_put_u32(msg,
676 NL80211_FREQUENCY_ATTR_DFS_CAC_TIME,
677 chan->dfs_cac_ms))
678 goto nla_put_failure;
Johannes Bergcdc89b92013-02-18 23:54:36 +0100679 }
680 }
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400681
Johannes Bergfe1abaf2013-02-27 15:39:45 +0100682 if (large) {
683 if ((chan->flags & IEEE80211_CHAN_NO_HT40MINUS) &&
684 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_HT40_MINUS))
685 goto nla_put_failure;
686 if ((chan->flags & IEEE80211_CHAN_NO_HT40PLUS) &&
687 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_HT40_PLUS))
688 goto nla_put_failure;
689 if ((chan->flags & IEEE80211_CHAN_NO_80MHZ) &&
690 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_80MHZ))
691 goto nla_put_failure;
692 if ((chan->flags & IEEE80211_CHAN_NO_160MHZ) &&
693 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_160MHZ))
694 goto nla_put_failure;
David Spinadel570dbde2014-02-23 09:12:59 +0200695 if ((chan->flags & IEEE80211_CHAN_INDOOR_ONLY) &&
696 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_INDOOR_ONLY))
697 goto nla_put_failure;
Arik Nemtsov06f207f2015-05-06 16:28:31 +0300698 if ((chan->flags & IEEE80211_CHAN_IR_CONCURRENT) &&
699 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_IR_CONCURRENT))
David Spinadel570dbde2014-02-23 09:12:59 +0200700 goto nla_put_failure;
Rostislav Lisovyea077c12014-04-15 14:37:55 +0200701 if ((chan->flags & IEEE80211_CHAN_NO_20MHZ) &&
702 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_20MHZ))
703 goto nla_put_failure;
704 if ((chan->flags & IEEE80211_CHAN_NO_10MHZ) &&
705 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_10MHZ))
706 goto nla_put_failure;
Johannes Bergfe1abaf2013-02-27 15:39:45 +0100707 }
708
David S. Miller9360ffd2012-03-29 04:41:26 -0400709 if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_MAX_TX_POWER,
710 DBM_TO_MBM(chan->max_power)))
711 goto nla_put_failure;
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400712
713 return 0;
714
715 nla_put_failure:
716 return -ENOBUFS;
717}
718
Johannes Berg55682962007-09-20 13:09:35 -0400719/* netlink command implementations */
720
Johannes Bergb9454e82009-07-08 13:29:08 +0200721struct key_parse {
722 struct key_params p;
723 int idx;
Johannes Berge31b8212010-10-05 19:39:30 +0200724 int type;
Johannes Bergb9454e82009-07-08 13:29:08 +0200725 bool def, defmgmt;
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100726 bool def_uni, def_multi;
Johannes Bergb9454e82009-07-08 13:29:08 +0200727};
728
729static int nl80211_parse_key_new(struct nlattr *key, struct key_parse *k)
730{
731 struct nlattr *tb[NL80211_KEY_MAX + 1];
732 int err = nla_parse_nested(tb, NL80211_KEY_MAX, key,
Johannes Bergfceb6432017-04-12 14:34:07 +0200733 nl80211_key_policy, NULL);
Johannes Bergb9454e82009-07-08 13:29:08 +0200734 if (err)
735 return err;
736
737 k->def = !!tb[NL80211_KEY_DEFAULT];
738 k->defmgmt = !!tb[NL80211_KEY_DEFAULT_MGMT];
739
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100740 if (k->def) {
741 k->def_uni = true;
742 k->def_multi = true;
743 }
744 if (k->defmgmt)
745 k->def_multi = true;
746
Johannes Bergb9454e82009-07-08 13:29:08 +0200747 if (tb[NL80211_KEY_IDX])
748 k->idx = nla_get_u8(tb[NL80211_KEY_IDX]);
749
750 if (tb[NL80211_KEY_DATA]) {
751 k->p.key = nla_data(tb[NL80211_KEY_DATA]);
752 k->p.key_len = nla_len(tb[NL80211_KEY_DATA]);
753 }
754
755 if (tb[NL80211_KEY_SEQ]) {
756 k->p.seq = nla_data(tb[NL80211_KEY_SEQ]);
757 k->p.seq_len = nla_len(tb[NL80211_KEY_SEQ]);
758 }
759
760 if (tb[NL80211_KEY_CIPHER])
761 k->p.cipher = nla_get_u32(tb[NL80211_KEY_CIPHER]);
762
Johannes Berge31b8212010-10-05 19:39:30 +0200763 if (tb[NL80211_KEY_TYPE]) {
764 k->type = nla_get_u32(tb[NL80211_KEY_TYPE]);
765 if (k->type < 0 || k->type >= NUM_NL80211_KEYTYPES)
766 return -EINVAL;
767 }
768
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100769 if (tb[NL80211_KEY_DEFAULT_TYPES]) {
770 struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES];
Kirtika Ruchandani7a087e72016-05-29 19:51:23 -0700771
Johannes Berg2da8f412012-01-20 13:52:37 +0100772 err = nla_parse_nested(kdt, NUM_NL80211_KEY_DEFAULT_TYPES - 1,
773 tb[NL80211_KEY_DEFAULT_TYPES],
Johannes Bergfceb6432017-04-12 14:34:07 +0200774 nl80211_key_default_policy, NULL);
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100775 if (err)
776 return err;
777
778 k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST];
779 k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST];
780 }
781
Johannes Bergb9454e82009-07-08 13:29:08 +0200782 return 0;
783}
784
785static int nl80211_parse_key_old(struct genl_info *info, struct key_parse *k)
786{
787 if (info->attrs[NL80211_ATTR_KEY_DATA]) {
788 k->p.key = nla_data(info->attrs[NL80211_ATTR_KEY_DATA]);
789 k->p.key_len = nla_len(info->attrs[NL80211_ATTR_KEY_DATA]);
790 }
791
792 if (info->attrs[NL80211_ATTR_KEY_SEQ]) {
793 k->p.seq = nla_data(info->attrs[NL80211_ATTR_KEY_SEQ]);
794 k->p.seq_len = nla_len(info->attrs[NL80211_ATTR_KEY_SEQ]);
795 }
796
797 if (info->attrs[NL80211_ATTR_KEY_IDX])
798 k->idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]);
799
800 if (info->attrs[NL80211_ATTR_KEY_CIPHER])
801 k->p.cipher = nla_get_u32(info->attrs[NL80211_ATTR_KEY_CIPHER]);
802
803 k->def = !!info->attrs[NL80211_ATTR_KEY_DEFAULT];
804 k->defmgmt = !!info->attrs[NL80211_ATTR_KEY_DEFAULT_MGMT];
805
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100806 if (k->def) {
807 k->def_uni = true;
808 k->def_multi = true;
809 }
810 if (k->defmgmt)
811 k->def_multi = true;
812
Johannes Berge31b8212010-10-05 19:39:30 +0200813 if (info->attrs[NL80211_ATTR_KEY_TYPE]) {
814 k->type = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]);
815 if (k->type < 0 || k->type >= NUM_NL80211_KEYTYPES)
816 return -EINVAL;
817 }
818
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100819 if (info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES]) {
820 struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES];
Johannes Bergfceb6432017-04-12 14:34:07 +0200821 int err = nla_parse_nested(kdt,
822 NUM_NL80211_KEY_DEFAULT_TYPES - 1,
823 info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES],
Johannes Bergfe521452017-04-12 14:34:08 +0200824 nl80211_key_default_policy,
825 info->extack);
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100826 if (err)
827 return err;
828
829 k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST];
830 k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST];
831 }
832
Johannes Bergb9454e82009-07-08 13:29:08 +0200833 return 0;
834}
835
836static int nl80211_parse_key(struct genl_info *info, struct key_parse *k)
837{
838 int err;
839
840 memset(k, 0, sizeof(*k));
841 k->idx = -1;
Johannes Berge31b8212010-10-05 19:39:30 +0200842 k->type = -1;
Johannes Bergb9454e82009-07-08 13:29:08 +0200843
844 if (info->attrs[NL80211_ATTR_KEY])
845 err = nl80211_parse_key_new(info->attrs[NL80211_ATTR_KEY], k);
846 else
847 err = nl80211_parse_key_old(info, k);
848
849 if (err)
850 return err;
851
852 if (k->def && k->defmgmt)
853 return -EINVAL;
854
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100855 if (k->defmgmt) {
856 if (k->def_uni || !k->def_multi)
857 return -EINVAL;
858 }
859
Johannes Bergb9454e82009-07-08 13:29:08 +0200860 if (k->idx != -1) {
861 if (k->defmgmt) {
862 if (k->idx < 4 || k->idx > 5)
863 return -EINVAL;
864 } else if (k->def) {
865 if (k->idx < 0 || k->idx > 3)
866 return -EINVAL;
867 } else {
868 if (k->idx < 0 || k->idx > 5)
869 return -EINVAL;
870 }
871 }
872
873 return 0;
874}
875
Johannes Bergfffd0932009-07-08 14:22:54 +0200876static struct cfg80211_cached_keys *
877nl80211_parse_connkeys(struct cfg80211_registered_device *rdev,
Sujith Manoharande7044e2012-10-18 10:19:28 +0530878 struct nlattr *keys, bool *no_ht)
Johannes Bergfffd0932009-07-08 14:22:54 +0200879{
880 struct key_parse parse;
881 struct nlattr *key;
882 struct cfg80211_cached_keys *result;
883 int rem, err, def = 0;
Johannes Bergf1c1f172016-09-13 17:08:23 +0200884 bool have_key = false;
885
886 nla_for_each_nested(key, keys, rem) {
887 have_key = true;
888 break;
889 }
890
891 if (!have_key)
892 return NULL;
Johannes Bergfffd0932009-07-08 14:22:54 +0200893
894 result = kzalloc(sizeof(*result), GFP_KERNEL);
895 if (!result)
896 return ERR_PTR(-ENOMEM);
897
898 result->def = -1;
Johannes Bergfffd0932009-07-08 14:22:54 +0200899
900 nla_for_each_nested(key, keys, rem) {
901 memset(&parse, 0, sizeof(parse));
902 parse.idx = -1;
903
904 err = nl80211_parse_key_new(key, &parse);
905 if (err)
906 goto error;
907 err = -EINVAL;
908 if (!parse.p.key)
909 goto error;
Johannes Berg42ee2312016-09-13 15:51:03 +0200910 if (parse.idx < 0 || parse.idx > 3)
Johannes Bergfffd0932009-07-08 14:22:54 +0200911 goto error;
912 if (parse.def) {
913 if (def)
914 goto error;
915 def = 1;
916 result->def = parse.idx;
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100917 if (!parse.def_uni || !parse.def_multi)
918 goto error;
Johannes Bergfffd0932009-07-08 14:22:54 +0200919 } else if (parse.defmgmt)
920 goto error;
921 err = cfg80211_validate_key_settings(rdev, &parse.p,
Johannes Berge31b8212010-10-05 19:39:30 +0200922 parse.idx, false, NULL);
Johannes Bergfffd0932009-07-08 14:22:54 +0200923 if (err)
924 goto error;
Johannes Berg386b1f22016-09-13 16:10:02 +0200925 if (parse.p.cipher != WLAN_CIPHER_SUITE_WEP40 &&
926 parse.p.cipher != WLAN_CIPHER_SUITE_WEP104) {
927 err = -EINVAL;
928 goto error;
929 }
Johannes Bergfffd0932009-07-08 14:22:54 +0200930 result->params[parse.idx].cipher = parse.p.cipher;
931 result->params[parse.idx].key_len = parse.p.key_len;
932 result->params[parse.idx].key = result->data[parse.idx];
933 memcpy(result->data[parse.idx], parse.p.key, parse.p.key_len);
Sujith Manoharande7044e2012-10-18 10:19:28 +0530934
Johannes Berg386b1f22016-09-13 16:10:02 +0200935 /* must be WEP key if we got here */
936 if (no_ht)
937 *no_ht = true;
Johannes Bergfffd0932009-07-08 14:22:54 +0200938 }
939
Johannes Bergf1c1f172016-09-13 17:08:23 +0200940 if (result->def < 0) {
941 err = -EINVAL;
942 goto error;
943 }
944
Johannes Bergfffd0932009-07-08 14:22:54 +0200945 return result;
946 error:
947 kfree(result);
948 return ERR_PTR(err);
949}
950
951static int nl80211_key_allowed(struct wireless_dev *wdev)
952{
953 ASSERT_WDEV_LOCK(wdev);
954
Johannes Bergfffd0932009-07-08 14:22:54 +0200955 switch (wdev->iftype) {
956 case NL80211_IFTYPE_AP:
957 case NL80211_IFTYPE_AP_VLAN:
Johannes Berg074ac8d2010-09-16 14:58:22 +0200958 case NL80211_IFTYPE_P2P_GO:
Thomas Pedersenff973af2011-05-03 16:57:12 -0700959 case NL80211_IFTYPE_MESH_POINT:
Johannes Bergfffd0932009-07-08 14:22:54 +0200960 break;
961 case NL80211_IFTYPE_ADHOC:
Johannes Bergfffd0932009-07-08 14:22:54 +0200962 case NL80211_IFTYPE_STATION:
Johannes Berg074ac8d2010-09-16 14:58:22 +0200963 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Bergceca7b72013-05-16 00:55:45 +0200964 if (!wdev->current_bss)
Johannes Bergfffd0932009-07-08 14:22:54 +0200965 return -ENOLINK;
966 break;
Johannes Bergde4fcba2014-10-31 14:16:12 +0100967 case NL80211_IFTYPE_UNSPECIFIED:
Rostislav Lisovy6e0bd6c2014-11-03 10:33:18 +0100968 case NL80211_IFTYPE_OCB:
Johannes Bergde4fcba2014-10-31 14:16:12 +0100969 case NL80211_IFTYPE_MONITOR:
Ayala Bekercb3b7d82016-09-20 17:31:13 +0300970 case NL80211_IFTYPE_NAN:
Johannes Bergde4fcba2014-10-31 14:16:12 +0100971 case NL80211_IFTYPE_P2P_DEVICE:
972 case NL80211_IFTYPE_WDS:
973 case NUM_NL80211_IFTYPES:
Johannes Bergfffd0932009-07-08 14:22:54 +0200974 return -EINVAL;
975 }
976
977 return 0;
978}
979
Jouni Malinen664834d2014-01-15 00:01:44 +0200980static struct ieee80211_channel *nl80211_get_valid_chan(struct wiphy *wiphy,
981 struct nlattr *tb)
982{
983 struct ieee80211_channel *chan;
984
985 if (tb == NULL)
986 return NULL;
987 chan = ieee80211_get_channel(wiphy, nla_get_u32(tb));
988 if (!chan || chan->flags & IEEE80211_CHAN_DISABLED)
989 return NULL;
990 return chan;
991}
992
Johannes Berg7527a782011-05-13 10:58:57 +0200993static int nl80211_put_iftypes(struct sk_buff *msg, u32 attr, u16 ifmodes)
994{
995 struct nlattr *nl_modes = nla_nest_start(msg, attr);
996 int i;
997
998 if (!nl_modes)
999 goto nla_put_failure;
1000
1001 i = 0;
1002 while (ifmodes) {
David S. Miller9360ffd2012-03-29 04:41:26 -04001003 if ((ifmodes & 1) && nla_put_flag(msg, i))
1004 goto nla_put_failure;
Johannes Berg7527a782011-05-13 10:58:57 +02001005 ifmodes >>= 1;
1006 i++;
1007 }
1008
1009 nla_nest_end(msg, nl_modes);
1010 return 0;
1011
1012nla_put_failure:
1013 return -ENOBUFS;
1014}
1015
1016static int nl80211_put_iface_combinations(struct wiphy *wiphy,
Johannes Bergcdc89b92013-02-18 23:54:36 +01001017 struct sk_buff *msg,
1018 bool large)
Johannes Berg7527a782011-05-13 10:58:57 +02001019{
1020 struct nlattr *nl_combis;
1021 int i, j;
1022
1023 nl_combis = nla_nest_start(msg,
1024 NL80211_ATTR_INTERFACE_COMBINATIONS);
1025 if (!nl_combis)
1026 goto nla_put_failure;
1027
1028 for (i = 0; i < wiphy->n_iface_combinations; i++) {
1029 const struct ieee80211_iface_combination *c;
1030 struct nlattr *nl_combi, *nl_limits;
1031
1032 c = &wiphy->iface_combinations[i];
1033
1034 nl_combi = nla_nest_start(msg, i + 1);
1035 if (!nl_combi)
1036 goto nla_put_failure;
1037
1038 nl_limits = nla_nest_start(msg, NL80211_IFACE_COMB_LIMITS);
1039 if (!nl_limits)
1040 goto nla_put_failure;
1041
1042 for (j = 0; j < c->n_limits; j++) {
1043 struct nlattr *nl_limit;
1044
1045 nl_limit = nla_nest_start(msg, j + 1);
1046 if (!nl_limit)
1047 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04001048 if (nla_put_u32(msg, NL80211_IFACE_LIMIT_MAX,
1049 c->limits[j].max))
1050 goto nla_put_failure;
Johannes Berg7527a782011-05-13 10:58:57 +02001051 if (nl80211_put_iftypes(msg, NL80211_IFACE_LIMIT_TYPES,
1052 c->limits[j].types))
1053 goto nla_put_failure;
1054 nla_nest_end(msg, nl_limit);
1055 }
1056
1057 nla_nest_end(msg, nl_limits);
1058
David S. Miller9360ffd2012-03-29 04:41:26 -04001059 if (c->beacon_int_infra_match &&
1060 nla_put_flag(msg, NL80211_IFACE_COMB_STA_AP_BI_MATCH))
1061 goto nla_put_failure;
1062 if (nla_put_u32(msg, NL80211_IFACE_COMB_NUM_CHANNELS,
1063 c->num_different_channels) ||
1064 nla_put_u32(msg, NL80211_IFACE_COMB_MAXNUM,
1065 c->max_interfaces))
1066 goto nla_put_failure;
Johannes Bergcdc89b92013-02-18 23:54:36 +01001067 if (large &&
Felix Fietkau8c48b502014-05-05 11:48:40 +02001068 (nla_put_u32(msg, NL80211_IFACE_COMB_RADAR_DETECT_WIDTHS,
1069 c->radar_detect_widths) ||
1070 nla_put_u32(msg, NL80211_IFACE_COMB_RADAR_DETECT_REGIONS,
1071 c->radar_detect_regions)))
Johannes Bergcdc89b92013-02-18 23:54:36 +01001072 goto nla_put_failure;
Purushottam Kushwaha0c317a02016-10-12 18:26:51 +05301073 if (c->beacon_int_min_gcd &&
1074 nla_put_u32(msg, NL80211_IFACE_COMB_BI_MIN_GCD,
1075 c->beacon_int_min_gcd))
1076 goto nla_put_failure;
Johannes Berg7527a782011-05-13 10:58:57 +02001077
1078 nla_nest_end(msg, nl_combi);
1079 }
1080
1081 nla_nest_end(msg, nl_combis);
1082
1083 return 0;
1084nla_put_failure:
1085 return -ENOBUFS;
1086}
1087
Johannes Berg3713b4e2013-02-14 16:19:38 +01001088#ifdef CONFIG_PM
Johannes Bergb56cf722013-02-20 01:02:38 +01001089static int nl80211_send_wowlan_tcp_caps(struct cfg80211_registered_device *rdev,
1090 struct sk_buff *msg)
1091{
Johannes Berg964dc9e2013-06-03 17:25:34 +02001092 const struct wiphy_wowlan_tcp_support *tcp = rdev->wiphy.wowlan->tcp;
Johannes Bergb56cf722013-02-20 01:02:38 +01001093 struct nlattr *nl_tcp;
1094
1095 if (!tcp)
1096 return 0;
1097
1098 nl_tcp = nla_nest_start(msg, NL80211_WOWLAN_TRIG_TCP_CONNECTION);
1099 if (!nl_tcp)
1100 return -ENOBUFS;
1101
1102 if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD,
1103 tcp->data_payload_max))
1104 return -ENOBUFS;
1105
1106 if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD,
1107 tcp->data_payload_max))
1108 return -ENOBUFS;
1109
1110 if (tcp->seq && nla_put_flag(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ))
1111 return -ENOBUFS;
1112
1113 if (tcp->tok && nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN,
1114 sizeof(*tcp->tok), tcp->tok))
1115 return -ENOBUFS;
1116
1117 if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_INTERVAL,
1118 tcp->data_interval_max))
1119 return -ENOBUFS;
1120
1121 if (nla_put_u32(msg, NL80211_WOWLAN_TCP_WAKE_PAYLOAD,
1122 tcp->wake_payload_max))
1123 return -ENOBUFS;
1124
1125 nla_nest_end(msg, nl_tcp);
1126 return 0;
1127}
1128
Johannes Berg3713b4e2013-02-14 16:19:38 +01001129static int nl80211_send_wowlan(struct sk_buff *msg,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001130 struct cfg80211_registered_device *rdev,
Johannes Bergb56cf722013-02-20 01:02:38 +01001131 bool large)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001132{
1133 struct nlattr *nl_wowlan;
1134
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001135 if (!rdev->wiphy.wowlan)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001136 return 0;
1137
1138 nl_wowlan = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS_SUPPORTED);
1139 if (!nl_wowlan)
1140 return -ENOBUFS;
1141
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001142 if (((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_ANY) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001143 nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) ||
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001144 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_DISCONNECT) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001145 nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) ||
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001146 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001147 nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) ||
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001148 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_SUPPORTS_GTK_REKEY) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001149 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED)) ||
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001150 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001151 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) ||
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001152 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001153 nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) ||
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001154 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001155 nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) ||
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001156 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001157 nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE)))
1158 return -ENOBUFS;
1159
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001160 if (rdev->wiphy.wowlan->n_patterns) {
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07001161 struct nl80211_pattern_support pat = {
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001162 .max_patterns = rdev->wiphy.wowlan->n_patterns,
1163 .min_pattern_len = rdev->wiphy.wowlan->pattern_min_len,
1164 .max_pattern_len = rdev->wiphy.wowlan->pattern_max_len,
1165 .max_pkt_offset = rdev->wiphy.wowlan->max_pkt_offset,
Johannes Berg3713b4e2013-02-14 16:19:38 +01001166 };
1167
1168 if (nla_put(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN,
1169 sizeof(pat), &pat))
1170 return -ENOBUFS;
1171 }
1172
Luciano Coelho75453cc2015-01-09 14:06:37 +02001173 if ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_NET_DETECT) &&
1174 nla_put_u32(msg, NL80211_WOWLAN_TRIG_NET_DETECT,
1175 rdev->wiphy.wowlan->max_nd_match_sets))
1176 return -ENOBUFS;
1177
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001178 if (large && nl80211_send_wowlan_tcp_caps(rdev, msg))
Johannes Bergb56cf722013-02-20 01:02:38 +01001179 return -ENOBUFS;
1180
Johannes Berg3713b4e2013-02-14 16:19:38 +01001181 nla_nest_end(msg, nl_wowlan);
1182
1183 return 0;
1184}
1185#endif
1186
Amitkumar Karwarbe29b99a2013-06-28 11:51:26 -07001187static int nl80211_send_coalesce(struct sk_buff *msg,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001188 struct cfg80211_registered_device *rdev)
Amitkumar Karwarbe29b99a2013-06-28 11:51:26 -07001189{
1190 struct nl80211_coalesce_rule_support rule;
1191
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001192 if (!rdev->wiphy.coalesce)
Amitkumar Karwarbe29b99a2013-06-28 11:51:26 -07001193 return 0;
1194
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001195 rule.max_rules = rdev->wiphy.coalesce->n_rules;
1196 rule.max_delay = rdev->wiphy.coalesce->max_delay;
1197 rule.pat.max_patterns = rdev->wiphy.coalesce->n_patterns;
1198 rule.pat.min_pattern_len = rdev->wiphy.coalesce->pattern_min_len;
1199 rule.pat.max_pattern_len = rdev->wiphy.coalesce->pattern_max_len;
1200 rule.pat.max_pkt_offset = rdev->wiphy.coalesce->max_pkt_offset;
Amitkumar Karwarbe29b99a2013-06-28 11:51:26 -07001201
1202 if (nla_put(msg, NL80211_ATTR_COALESCE_RULE, sizeof(rule), &rule))
1203 return -ENOBUFS;
1204
1205 return 0;
1206}
1207
Johannes Berg3713b4e2013-02-14 16:19:38 +01001208static int nl80211_send_band_rateinfo(struct sk_buff *msg,
1209 struct ieee80211_supported_band *sband)
1210{
1211 struct nlattr *nl_rates, *nl_rate;
1212 struct ieee80211_rate *rate;
1213 int i;
1214
1215 /* add HT info */
1216 if (sband->ht_cap.ht_supported &&
1217 (nla_put(msg, NL80211_BAND_ATTR_HT_MCS_SET,
1218 sizeof(sband->ht_cap.mcs),
1219 &sband->ht_cap.mcs) ||
1220 nla_put_u16(msg, NL80211_BAND_ATTR_HT_CAPA,
1221 sband->ht_cap.cap) ||
1222 nla_put_u8(msg, NL80211_BAND_ATTR_HT_AMPDU_FACTOR,
1223 sband->ht_cap.ampdu_factor) ||
1224 nla_put_u8(msg, NL80211_BAND_ATTR_HT_AMPDU_DENSITY,
1225 sband->ht_cap.ampdu_density)))
1226 return -ENOBUFS;
1227
1228 /* add VHT info */
1229 if (sband->vht_cap.vht_supported &&
1230 (nla_put(msg, NL80211_BAND_ATTR_VHT_MCS_SET,
1231 sizeof(sband->vht_cap.vht_mcs),
1232 &sband->vht_cap.vht_mcs) ||
1233 nla_put_u32(msg, NL80211_BAND_ATTR_VHT_CAPA,
1234 sband->vht_cap.cap)))
1235 return -ENOBUFS;
1236
1237 /* add bitrates */
1238 nl_rates = nla_nest_start(msg, NL80211_BAND_ATTR_RATES);
1239 if (!nl_rates)
1240 return -ENOBUFS;
1241
1242 for (i = 0; i < sband->n_bitrates; i++) {
1243 nl_rate = nla_nest_start(msg, i);
1244 if (!nl_rate)
1245 return -ENOBUFS;
1246
1247 rate = &sband->bitrates[i];
1248 if (nla_put_u32(msg, NL80211_BITRATE_ATTR_RATE,
1249 rate->bitrate))
1250 return -ENOBUFS;
1251 if ((rate->flags & IEEE80211_RATE_SHORT_PREAMBLE) &&
1252 nla_put_flag(msg,
1253 NL80211_BITRATE_ATTR_2GHZ_SHORTPREAMBLE))
1254 return -ENOBUFS;
1255
1256 nla_nest_end(msg, nl_rate);
1257 }
1258
1259 nla_nest_end(msg, nl_rates);
1260
1261 return 0;
1262}
1263
1264static int
1265nl80211_send_mgmt_stypes(struct sk_buff *msg,
1266 const struct ieee80211_txrx_stypes *mgmt_stypes)
1267{
1268 u16 stypes;
1269 struct nlattr *nl_ftypes, *nl_ifs;
1270 enum nl80211_iftype ift;
1271 int i;
1272
1273 if (!mgmt_stypes)
1274 return 0;
1275
1276 nl_ifs = nla_nest_start(msg, NL80211_ATTR_TX_FRAME_TYPES);
1277 if (!nl_ifs)
1278 return -ENOBUFS;
1279
1280 for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) {
1281 nl_ftypes = nla_nest_start(msg, ift);
1282 if (!nl_ftypes)
1283 return -ENOBUFS;
1284 i = 0;
1285 stypes = mgmt_stypes[ift].tx;
1286 while (stypes) {
1287 if ((stypes & 1) &&
1288 nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE,
1289 (i << 4) | IEEE80211_FTYPE_MGMT))
1290 return -ENOBUFS;
1291 stypes >>= 1;
1292 i++;
1293 }
1294 nla_nest_end(msg, nl_ftypes);
1295 }
1296
1297 nla_nest_end(msg, nl_ifs);
1298
1299 nl_ifs = nla_nest_start(msg, NL80211_ATTR_RX_FRAME_TYPES);
1300 if (!nl_ifs)
1301 return -ENOBUFS;
1302
1303 for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) {
1304 nl_ftypes = nla_nest_start(msg, ift);
1305 if (!nl_ftypes)
1306 return -ENOBUFS;
1307 i = 0;
1308 stypes = mgmt_stypes[ift].rx;
1309 while (stypes) {
1310 if ((stypes & 1) &&
1311 nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE,
1312 (i << 4) | IEEE80211_FTYPE_MGMT))
1313 return -ENOBUFS;
1314 stypes >>= 1;
1315 i++;
1316 }
1317 nla_nest_end(msg, nl_ftypes);
1318 }
1319 nla_nest_end(msg, nl_ifs);
1320
1321 return 0;
1322}
1323
Johannes Berg17948992016-10-26 11:42:04 +02001324#define CMD(op, n) \
1325 do { \
1326 if (rdev->ops->op) { \
1327 i++; \
1328 if (nla_put_u32(msg, i, NL80211_CMD_ ## n)) \
1329 goto nla_put_failure; \
1330 } \
1331 } while (0)
1332
1333static int nl80211_add_commands_unsplit(struct cfg80211_registered_device *rdev,
1334 struct sk_buff *msg)
1335{
1336 int i = 0;
1337
1338 /*
1339 * do *NOT* add anything into this function, new things need to be
1340 * advertised only to new versions of userspace that can deal with
1341 * the split (and they can't possibly care about new features...
1342 */
1343 CMD(add_virtual_intf, NEW_INTERFACE);
1344 CMD(change_virtual_intf, SET_INTERFACE);
1345 CMD(add_key, NEW_KEY);
1346 CMD(start_ap, START_AP);
1347 CMD(add_station, NEW_STATION);
1348 CMD(add_mpath, NEW_MPATH);
1349 CMD(update_mesh_config, SET_MESH_CONFIG);
1350 CMD(change_bss, SET_BSS);
1351 CMD(auth, AUTHENTICATE);
1352 CMD(assoc, ASSOCIATE);
1353 CMD(deauth, DEAUTHENTICATE);
1354 CMD(disassoc, DISASSOCIATE);
1355 CMD(join_ibss, JOIN_IBSS);
1356 CMD(join_mesh, JOIN_MESH);
1357 CMD(set_pmksa, SET_PMKSA);
1358 CMD(del_pmksa, DEL_PMKSA);
1359 CMD(flush_pmksa, FLUSH_PMKSA);
1360 if (rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL)
1361 CMD(remain_on_channel, REMAIN_ON_CHANNEL);
1362 CMD(set_bitrate_mask, SET_TX_BITRATE_MASK);
1363 CMD(mgmt_tx, FRAME);
1364 CMD(mgmt_tx_cancel_wait, FRAME_WAIT_CANCEL);
1365 if (rdev->wiphy.flags & WIPHY_FLAG_NETNS_OK) {
1366 i++;
1367 if (nla_put_u32(msg, i, NL80211_CMD_SET_WIPHY_NETNS))
1368 goto nla_put_failure;
1369 }
1370 if (rdev->ops->set_monitor_channel || rdev->ops->start_ap ||
1371 rdev->ops->join_mesh) {
1372 i++;
1373 if (nla_put_u32(msg, i, NL80211_CMD_SET_CHANNEL))
1374 goto nla_put_failure;
1375 }
1376 CMD(set_wds_peer, SET_WDS_PEER);
1377 if (rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) {
1378 CMD(tdls_mgmt, TDLS_MGMT);
1379 CMD(tdls_oper, TDLS_OPER);
1380 }
Arend Van Sprielca986ad2017-04-21 13:05:00 +01001381 if (rdev->wiphy.max_sched_scan_reqs)
Johannes Berg17948992016-10-26 11:42:04 +02001382 CMD(sched_scan_start, START_SCHED_SCAN);
1383 CMD(probe_client, PROBE_CLIENT);
1384 CMD(set_noack_map, SET_NOACK_MAP);
1385 if (rdev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS) {
1386 i++;
1387 if (nla_put_u32(msg, i, NL80211_CMD_REGISTER_BEACONS))
1388 goto nla_put_failure;
1389 }
1390 CMD(start_p2p_device, START_P2P_DEVICE);
1391 CMD(set_mcast_rate, SET_MCAST_RATE);
1392#ifdef CONFIG_NL80211_TESTMODE
1393 CMD(testmode_cmd, TESTMODE);
1394#endif
1395
1396 if (rdev->ops->connect || rdev->ops->auth) {
1397 i++;
1398 if (nla_put_u32(msg, i, NL80211_CMD_CONNECT))
1399 goto nla_put_failure;
1400 }
1401
1402 if (rdev->ops->disconnect || rdev->ops->deauth) {
1403 i++;
1404 if (nla_put_u32(msg, i, NL80211_CMD_DISCONNECT))
1405 goto nla_put_failure;
1406 }
1407
1408 return i;
1409 nla_put_failure:
1410 return -ENOBUFS;
1411}
1412
Johannes Berg86e8cf92013-06-19 10:57:22 +02001413struct nl80211_dump_wiphy_state {
1414 s64 filter_wiphy;
1415 long start;
Kanchanapally, Vidyullatha019ae3a2016-05-16 10:41:04 +05301416 long split_start, band_start, chan_start, capa_start;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001417 bool split;
1418};
1419
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001420static int nl80211_send_wiphy(struct cfg80211_registered_device *rdev,
Johannes Berg3bb20552014-05-26 13:52:25 +02001421 enum nl80211_commands cmd,
Johannes Berg3713b4e2013-02-14 16:19:38 +01001422 struct sk_buff *msg, u32 portid, u32 seq,
Johannes Berg86e8cf92013-06-19 10:57:22 +02001423 int flags, struct nl80211_dump_wiphy_state *state)
Johannes Berg55682962007-09-20 13:09:35 -04001424{
1425 void *hdr;
Johannes Bergee688b002008-01-24 19:38:39 +01001426 struct nlattr *nl_bands, *nl_band;
1427 struct nlattr *nl_freqs, *nl_freq;
Johannes Berg8fdc6212009-03-14 09:34:01 +01001428 struct nlattr *nl_cmds;
Johannes Berg57fbcce2016-04-12 15:56:15 +02001429 enum nl80211_band band;
Johannes Bergee688b002008-01-24 19:38:39 +01001430 struct ieee80211_channel *chan;
Johannes Bergee688b002008-01-24 19:38:39 +01001431 int i;
Johannes Berg2e161f72010-08-12 15:38:38 +02001432 const struct ieee80211_txrx_stypes *mgmt_stypes =
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001433 rdev->wiphy.mgmt_stypes;
Johannes Bergfe1abaf2013-02-27 15:39:45 +01001434 u32 features;
Johannes Berg55682962007-09-20 13:09:35 -04001435
Johannes Berg3bb20552014-05-26 13:52:25 +02001436 hdr = nl80211hdr_put(msg, portid, seq, flags, cmd);
Johannes Berg55682962007-09-20 13:09:35 -04001437 if (!hdr)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001438 return -ENOBUFS;
1439
Johannes Berg86e8cf92013-06-19 10:57:22 +02001440 if (WARN_ON(!state))
1441 return -EINVAL;
Johannes Berg55682962007-09-20 13:09:35 -04001442
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001443 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001444 nla_put_string(msg, NL80211_ATTR_WIPHY_NAME,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001445 wiphy_name(&rdev->wiphy)) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04001446 nla_put_u32(msg, NL80211_ATTR_GENERATION,
Johannes Berg3713b4e2013-02-14 16:19:38 +01001447 cfg80211_rdev_list_generation))
David S. Miller9360ffd2012-03-29 04:41:26 -04001448 goto nla_put_failure;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02001449
Johannes Berg3bb20552014-05-26 13:52:25 +02001450 if (cmd != NL80211_CMD_NEW_WIPHY)
1451 goto finish;
1452
Johannes Berg86e8cf92013-06-19 10:57:22 +02001453 switch (state->split_start) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001454 case 0:
1455 if (nla_put_u8(msg, NL80211_ATTR_WIPHY_RETRY_SHORT,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001456 rdev->wiphy.retry_short) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001457 nla_put_u8(msg, NL80211_ATTR_WIPHY_RETRY_LONG,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001458 rdev->wiphy.retry_long) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001459 nla_put_u32(msg, NL80211_ATTR_WIPHY_FRAG_THRESHOLD,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001460 rdev->wiphy.frag_threshold) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001461 nla_put_u32(msg, NL80211_ATTR_WIPHY_RTS_THRESHOLD,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001462 rdev->wiphy.rts_threshold) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001463 nla_put_u8(msg, NL80211_ATTR_WIPHY_COVERAGE_CLASS,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001464 rdev->wiphy.coverage_class) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001465 nla_put_u8(msg, NL80211_ATTR_MAX_NUM_SCAN_SSIDS,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001466 rdev->wiphy.max_scan_ssids) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001467 nla_put_u8(msg, NL80211_ATTR_MAX_NUM_SCHED_SCAN_SSIDS,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001468 rdev->wiphy.max_sched_scan_ssids) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001469 nla_put_u16(msg, NL80211_ATTR_MAX_SCAN_IE_LEN,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001470 rdev->wiphy.max_scan_ie_len) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001471 nla_put_u16(msg, NL80211_ATTR_MAX_SCHED_SCAN_IE_LEN,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001472 rdev->wiphy.max_sched_scan_ie_len) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001473 nla_put_u8(msg, NL80211_ATTR_MAX_MATCH_SETS,
Avraham Stern3b06d272015-10-12 09:51:34 +03001474 rdev->wiphy.max_match_sets) ||
1475 nla_put_u32(msg, NL80211_ATTR_MAX_NUM_SCHED_SCAN_PLANS,
1476 rdev->wiphy.max_sched_scan_plans) ||
1477 nla_put_u32(msg, NL80211_ATTR_MAX_SCAN_PLAN_INTERVAL,
1478 rdev->wiphy.max_sched_scan_plan_interval) ||
1479 nla_put_u32(msg, NL80211_ATTR_MAX_SCAN_PLAN_ITERATIONS,
1480 rdev->wiphy.max_sched_scan_plan_iterations))
Johannes Bergee688b002008-01-24 19:38:39 +01001481 goto nla_put_failure;
1482
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001483 if ((rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001484 nla_put_flag(msg, NL80211_ATTR_SUPPORT_IBSS_RSN))
1485 goto nla_put_failure;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001486 if ((rdev->wiphy.flags & WIPHY_FLAG_MESH_AUTH) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001487 nla_put_flag(msg, NL80211_ATTR_SUPPORT_MESH_AUTH))
1488 goto nla_put_failure;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001489 if ((rdev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001490 nla_put_flag(msg, NL80211_ATTR_SUPPORT_AP_UAPSD))
1491 goto nla_put_failure;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001492 if ((rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_FW_ROAM) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001493 nla_put_flag(msg, NL80211_ATTR_ROAM_SUPPORT))
1494 goto nla_put_failure;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001495 if ((rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001496 nla_put_flag(msg, NL80211_ATTR_TDLS_SUPPORT))
1497 goto nla_put_failure;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001498 if ((rdev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001499 nla_put_flag(msg, NL80211_ATTR_TDLS_EXTERNAL_SETUP))
David S. Miller9360ffd2012-03-29 04:41:26 -04001500 goto nla_put_failure;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001501 state->split_start++;
1502 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001503 break;
1504 case 1:
1505 if (nla_put(msg, NL80211_ATTR_CIPHER_SUITES,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001506 sizeof(u32) * rdev->wiphy.n_cipher_suites,
1507 rdev->wiphy.cipher_suites))
Mahesh Palivelabf0c111e2012-06-22 07:27:46 +00001508 goto nla_put_failure;
1509
Johannes Berg3713b4e2013-02-14 16:19:38 +01001510 if (nla_put_u8(msg, NL80211_ATTR_MAX_NUM_PMKIDS,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001511 rdev->wiphy.max_num_pmkids))
Johannes Bergee688b002008-01-24 19:38:39 +01001512 goto nla_put_failure;
1513
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001514 if ((rdev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001515 nla_put_flag(msg, NL80211_ATTR_CONTROL_PORT_ETHERTYPE))
1516 goto nla_put_failure;
Johannes Bergee688b002008-01-24 19:38:39 +01001517
Johannes Berg3713b4e2013-02-14 16:19:38 +01001518 if (nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_TX,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001519 rdev->wiphy.available_antennas_tx) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001520 nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_RX,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001521 rdev->wiphy.available_antennas_rx))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001522 goto nla_put_failure;
Johannes Bergee688b002008-01-24 19:38:39 +01001523
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001524 if ((rdev->wiphy.flags & WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001525 nla_put_u32(msg, NL80211_ATTR_PROBE_RESP_OFFLOAD,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001526 rdev->wiphy.probe_resp_offload))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001527 goto nla_put_failure;
Jouni Malinene2f367f262008-11-21 19:01:30 +02001528
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001529 if ((rdev->wiphy.available_antennas_tx ||
1530 rdev->wiphy.available_antennas_rx) &&
1531 rdev->ops->get_antenna) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001532 u32 tx_ant = 0, rx_ant = 0;
1533 int res;
Kirtika Ruchandani7a087e72016-05-29 19:51:23 -07001534
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001535 res = rdev_get_antenna(rdev, &tx_ant, &rx_ant);
Johannes Berg3713b4e2013-02-14 16:19:38 +01001536 if (!res) {
1537 if (nla_put_u32(msg,
1538 NL80211_ATTR_WIPHY_ANTENNA_TX,
1539 tx_ant) ||
1540 nla_put_u32(msg,
1541 NL80211_ATTR_WIPHY_ANTENNA_RX,
1542 rx_ant))
1543 goto nla_put_failure;
1544 }
Johannes Bergee688b002008-01-24 19:38:39 +01001545 }
1546
Johannes Berg86e8cf92013-06-19 10:57:22 +02001547 state->split_start++;
1548 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001549 break;
1550 case 2:
1551 if (nl80211_put_iftypes(msg, NL80211_ATTR_SUPPORTED_IFTYPES,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001552 rdev->wiphy.interface_modes))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001553 goto nla_put_failure;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001554 state->split_start++;
1555 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001556 break;
1557 case 3:
1558 nl_bands = nla_nest_start(msg, NL80211_ATTR_WIPHY_BANDS);
1559 if (!nl_bands)
Johannes Bergee688b002008-01-24 19:38:39 +01001560 goto nla_put_failure;
1561
Johannes Berg86e8cf92013-06-19 10:57:22 +02001562 for (band = state->band_start;
Johannes Berg57fbcce2016-04-12 15:56:15 +02001563 band < NUM_NL80211_BANDS; band++) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001564 struct ieee80211_supported_band *sband;
1565
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001566 sband = rdev->wiphy.bands[band];
Johannes Berg3713b4e2013-02-14 16:19:38 +01001567
1568 if (!sband)
1569 continue;
1570
1571 nl_band = nla_nest_start(msg, band);
1572 if (!nl_band)
Johannes Bergee688b002008-01-24 19:38:39 +01001573 goto nla_put_failure;
1574
Johannes Berg86e8cf92013-06-19 10:57:22 +02001575 switch (state->chan_start) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001576 case 0:
1577 if (nl80211_send_band_rateinfo(msg, sband))
1578 goto nla_put_failure;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001579 state->chan_start++;
1580 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001581 break;
1582 default:
1583 /* add frequencies */
1584 nl_freqs = nla_nest_start(
1585 msg, NL80211_BAND_ATTR_FREQS);
1586 if (!nl_freqs)
1587 goto nla_put_failure;
Johannes Bergee688b002008-01-24 19:38:39 +01001588
Johannes Berg86e8cf92013-06-19 10:57:22 +02001589 for (i = state->chan_start - 1;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001590 i < sband->n_channels;
1591 i++) {
1592 nl_freq = nla_nest_start(msg, i);
1593 if (!nl_freq)
1594 goto nla_put_failure;
1595
1596 chan = &sband->channels[i];
1597
Johannes Berg86e8cf92013-06-19 10:57:22 +02001598 if (nl80211_msg_put_channel(
1599 msg, chan,
1600 state->split))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001601 goto nla_put_failure;
1602
1603 nla_nest_end(msg, nl_freq);
Johannes Berg86e8cf92013-06-19 10:57:22 +02001604 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001605 break;
1606 }
1607 if (i < sband->n_channels)
Johannes Berg86e8cf92013-06-19 10:57:22 +02001608 state->chan_start = i + 2;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001609 else
Johannes Berg86e8cf92013-06-19 10:57:22 +02001610 state->chan_start = 0;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001611 nla_nest_end(msg, nl_freqs);
1612 }
1613
1614 nla_nest_end(msg, nl_band);
1615
Johannes Berg86e8cf92013-06-19 10:57:22 +02001616 if (state->split) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001617 /* start again here */
Johannes Berg86e8cf92013-06-19 10:57:22 +02001618 if (state->chan_start)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001619 band--;
1620 break;
1621 }
Johannes Bergee688b002008-01-24 19:38:39 +01001622 }
Johannes Berg3713b4e2013-02-14 16:19:38 +01001623 nla_nest_end(msg, nl_bands);
Johannes Bergee688b002008-01-24 19:38:39 +01001624
Johannes Berg57fbcce2016-04-12 15:56:15 +02001625 if (band < NUM_NL80211_BANDS)
Johannes Berg86e8cf92013-06-19 10:57:22 +02001626 state->band_start = band + 1;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001627 else
Johannes Berg86e8cf92013-06-19 10:57:22 +02001628 state->band_start = 0;
Johannes Bergee688b002008-01-24 19:38:39 +01001629
Johannes Berg3713b4e2013-02-14 16:19:38 +01001630 /* if bands & channels are done, continue outside */
Johannes Berg86e8cf92013-06-19 10:57:22 +02001631 if (state->band_start == 0 && state->chan_start == 0)
1632 state->split_start++;
1633 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001634 break;
1635 case 4:
1636 nl_cmds = nla_nest_start(msg, NL80211_ATTR_SUPPORTED_COMMANDS);
1637 if (!nl_cmds)
David S. Miller9360ffd2012-03-29 04:41:26 -04001638 goto nla_put_failure;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001639
Johannes Berg17948992016-10-26 11:42:04 +02001640 i = nl80211_add_commands_unsplit(rdev, msg);
1641 if (i < 0)
1642 goto nla_put_failure;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001643 if (state->split) {
Arend van Spriel5de17982013-04-18 15:49:00 +02001644 CMD(crit_proto_start, CRIT_PROTOCOL_START);
1645 CMD(crit_proto_stop, CRIT_PROTOCOL_STOP);
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001646 if (rdev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH)
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02001647 CMD(channel_switch, CHANNEL_SWITCH);
Johannes Berg02df00e2014-06-10 14:06:25 +02001648 CMD(set_qos_map, SET_QOS_MAP);
Johannes Berg723e73a2014-10-22 09:25:06 +02001649 if (rdev->wiphy.features &
1650 NL80211_FEATURE_SUPPORTS_WMM_ADMISSION)
Johannes Berg960d01a2014-09-09 22:55:35 +03001651 CMD(add_tx_ts, ADD_TX_TS);
Michael Braunce0ce132016-10-10 19:12:22 +02001652 CMD(set_multicast_to_unicast, SET_MULTICAST_TO_UNICAST);
vamsi krishna088e8df2016-10-27 16:51:11 +03001653 CMD(update_connect_params, UPDATE_CONNECT_PARAMS);
Arend van Spriel5de17982013-04-18 15:49:00 +02001654 }
Johannes Berg8fdc6212009-03-14 09:34:01 +01001655#undef CMD
Samuel Ortizb23aa672009-07-01 21:26:54 +02001656
Johannes Berg3713b4e2013-02-14 16:19:38 +01001657 nla_nest_end(msg, nl_cmds);
Johannes Berg86e8cf92013-06-19 10:57:22 +02001658 state->split_start++;
1659 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001660 break;
1661 case 5:
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001662 if (rdev->ops->remain_on_channel &&
1663 (rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001664 nla_put_u32(msg,
1665 NL80211_ATTR_MAX_REMAIN_ON_CHANNEL_DURATION,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001666 rdev->wiphy.max_remain_on_channel_duration))
Johannes Berg2e161f72010-08-12 15:38:38 +02001667 goto nla_put_failure;
1668
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001669 if ((rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001670 nla_put_flag(msg, NL80211_ATTR_OFFCHANNEL_TX_OK))
1671 goto nla_put_failure;
Johannes Berg2e161f72010-08-12 15:38:38 +02001672
Johannes Berg3713b4e2013-02-14 16:19:38 +01001673 if (nl80211_send_mgmt_stypes(msg, mgmt_stypes))
1674 goto nla_put_failure;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001675 state->split_start++;
1676 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001677 break;
1678 case 6:
Johannes Bergdfb89c52012-06-27 09:23:48 +02001679#ifdef CONFIG_PM
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001680 if (nl80211_send_wowlan(msg, rdev, state->split))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001681 goto nla_put_failure;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001682 state->split_start++;
1683 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001684 break;
1685#else
Johannes Berg86e8cf92013-06-19 10:57:22 +02001686 state->split_start++;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001687#endif
1688 case 7:
1689 if (nl80211_put_iftypes(msg, NL80211_ATTR_SOFTWARE_IFTYPES,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001690 rdev->wiphy.software_iftypes))
Johannes Bergff1b6e62011-05-04 15:37:28 +02001691 goto nla_put_failure;
1692
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001693 if (nl80211_put_iface_combinations(&rdev->wiphy, msg,
Johannes Berg86e8cf92013-06-19 10:57:22 +02001694 state->split))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001695 goto nla_put_failure;
Johannes Bergff1b6e62011-05-04 15:37:28 +02001696
Johannes Berg86e8cf92013-06-19 10:57:22 +02001697 state->split_start++;
1698 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001699 break;
1700 case 8:
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001701 if ((rdev->wiphy.flags & WIPHY_FLAG_HAVE_AP_SME) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001702 nla_put_u32(msg, NL80211_ATTR_DEVICE_AP_SME,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001703 rdev->wiphy.ap_sme_capa))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001704 goto nla_put_failure;
1705
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001706 features = rdev->wiphy.features;
Johannes Bergfe1abaf2013-02-27 15:39:45 +01001707 /*
1708 * We can only add the per-channel limit information if the
1709 * dump is split, otherwise it makes it too big. Therefore
1710 * only advertise it in that case.
1711 */
Johannes Berg86e8cf92013-06-19 10:57:22 +02001712 if (state->split)
Johannes Bergfe1abaf2013-02-27 15:39:45 +01001713 features |= NL80211_FEATURE_ADVERTISE_CHAN_LIMITS;
1714 if (nla_put_u32(msg, NL80211_ATTR_FEATURE_FLAGS, features))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001715 goto nla_put_failure;
1716
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001717 if (rdev->wiphy.ht_capa_mod_mask &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001718 nla_put(msg, NL80211_ATTR_HT_CAPABILITY_MASK,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001719 sizeof(*rdev->wiphy.ht_capa_mod_mask),
1720 rdev->wiphy.ht_capa_mod_mask))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001721 goto nla_put_failure;
1722
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001723 if (rdev->wiphy.flags & WIPHY_FLAG_HAVE_AP_SME &&
1724 rdev->wiphy.max_acl_mac_addrs &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001725 nla_put_u32(msg, NL80211_ATTR_MAC_ACL_MAX,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001726 rdev->wiphy.max_acl_mac_addrs))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001727 goto nla_put_failure;
1728
1729 /*
1730 * Any information below this point is only available to
1731 * applications that can deal with it being split. This
1732 * helps ensure that newly added capabilities don't break
1733 * older tools by overrunning their buffers.
1734 *
1735 * We still increment split_start so that in the split
1736 * case we'll continue with more data in the next round,
1737 * but break unconditionally so unsplit data stops here.
1738 */
Johannes Berg86e8cf92013-06-19 10:57:22 +02001739 state->split_start++;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001740 break;
1741 case 9:
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001742 if (rdev->wiphy.extended_capabilities &&
Johannes Bergfe1abaf2013-02-27 15:39:45 +01001743 (nla_put(msg, NL80211_ATTR_EXT_CAPA,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001744 rdev->wiphy.extended_capabilities_len,
1745 rdev->wiphy.extended_capabilities) ||
Johannes Bergfe1abaf2013-02-27 15:39:45 +01001746 nla_put(msg, NL80211_ATTR_EXT_CAPA_MASK,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001747 rdev->wiphy.extended_capabilities_len,
1748 rdev->wiphy.extended_capabilities_mask)))
Johannes Bergfe1abaf2013-02-27 15:39:45 +01001749 goto nla_put_failure;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001750
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001751 if (rdev->wiphy.vht_capa_mod_mask &&
Johannes Bergee2aca32013-02-21 17:36:01 +01001752 nla_put(msg, NL80211_ATTR_VHT_CAPABILITY_MASK,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001753 sizeof(*rdev->wiphy.vht_capa_mod_mask),
1754 rdev->wiphy.vht_capa_mod_mask))
Johannes Bergee2aca32013-02-21 17:36:01 +01001755 goto nla_put_failure;
1756
Amitkumar Karwarbe29b99a2013-06-28 11:51:26 -07001757 state->split_start++;
1758 break;
1759 case 10:
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001760 if (nl80211_send_coalesce(msg, rdev))
Amitkumar Karwarbe29b99a2013-06-28 11:51:26 -07001761 goto nla_put_failure;
1762
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001763 if ((rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_5_10_MHZ) &&
Felix Fietkau01e0daa2013-11-09 14:57:54 +01001764 (nla_put_flag(msg, NL80211_ATTR_SUPPORT_5_MHZ) ||
1765 nla_put_flag(msg, NL80211_ATTR_SUPPORT_10_MHZ)))
1766 goto nla_put_failure;
Jouni Malinenb43504c2014-01-15 00:01:08 +02001767
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001768 if (rdev->wiphy.max_ap_assoc_sta &&
Jouni Malinenb43504c2014-01-15 00:01:08 +02001769 nla_put_u32(msg, NL80211_ATTR_MAX_AP_ASSOC_STA,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001770 rdev->wiphy.max_ap_assoc_sta))
Jouni Malinenb43504c2014-01-15 00:01:08 +02001771 goto nla_put_failure;
1772
Johannes Bergad7e7182013-11-13 13:37:47 +01001773 state->split_start++;
1774 break;
1775 case 11:
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001776 if (rdev->wiphy.n_vendor_commands) {
Johannes Berg567ffc32013-12-18 14:43:31 +01001777 const struct nl80211_vendor_cmd_info *info;
1778 struct nlattr *nested;
Johannes Bergad7e7182013-11-13 13:37:47 +01001779
Johannes Berg567ffc32013-12-18 14:43:31 +01001780 nested = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA);
1781 if (!nested)
Johannes Bergad7e7182013-11-13 13:37:47 +01001782 goto nla_put_failure;
Johannes Berg567ffc32013-12-18 14:43:31 +01001783
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001784 for (i = 0; i < rdev->wiphy.n_vendor_commands; i++) {
1785 info = &rdev->wiphy.vendor_commands[i].info;
Johannes Berg567ffc32013-12-18 14:43:31 +01001786 if (nla_put(msg, i + 1, sizeof(*info), info))
1787 goto nla_put_failure;
1788 }
1789 nla_nest_end(msg, nested);
1790 }
1791
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001792 if (rdev->wiphy.n_vendor_events) {
Johannes Berg567ffc32013-12-18 14:43:31 +01001793 const struct nl80211_vendor_cmd_info *info;
1794 struct nlattr *nested;
1795
1796 nested = nla_nest_start(msg,
1797 NL80211_ATTR_VENDOR_EVENTS);
1798 if (!nested)
1799 goto nla_put_failure;
1800
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001801 for (i = 0; i < rdev->wiphy.n_vendor_events; i++) {
1802 info = &rdev->wiphy.vendor_events[i];
Johannes Berg567ffc32013-12-18 14:43:31 +01001803 if (nla_put(msg, i + 1, sizeof(*info), info))
1804 goto nla_put_failure;
1805 }
1806 nla_nest_end(msg, nested);
1807 }
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03001808 state->split_start++;
1809 break;
1810 case 12:
1811 if (rdev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH &&
1812 nla_put_u8(msg, NL80211_ATTR_MAX_CSA_COUNTERS,
1813 rdev->wiphy.max_num_csa_counters))
1814 goto nla_put_failure;
Felix Fietkau01e0daa2013-11-09 14:57:54 +01001815
Arik Nemtsov1bdd7162014-12-15 19:26:01 +02001816 if (rdev->wiphy.regulatory_flags & REGULATORY_WIPHY_SELF_MANAGED &&
1817 nla_put_flag(msg, NL80211_ATTR_WIPHY_SELF_MANAGED_REG))
1818 goto nla_put_failure;
1819
Arend Van Sprielca986ad2017-04-21 13:05:00 +01001820 if (rdev->wiphy.max_sched_scan_reqs &&
1821 nla_put_u32(msg, NL80211_ATTR_SCHED_SCAN_MAX_REQS,
1822 rdev->wiphy.max_sched_scan_reqs))
1823 goto nla_put_failure;
1824
Gautam Kumar Shuklad75bb062014-12-23 16:55:19 +01001825 if (nla_put(msg, NL80211_ATTR_EXT_FEATURES,
1826 sizeof(rdev->wiphy.ext_features),
1827 rdev->wiphy.ext_features))
1828 goto nla_put_failure;
1829
Arend van Spriel38de03d2016-03-02 20:37:18 +01001830 if (rdev->wiphy.bss_select_support) {
1831 struct nlattr *nested;
1832 u32 bss_select_support = rdev->wiphy.bss_select_support;
1833
1834 nested = nla_nest_start(msg, NL80211_ATTR_BSS_SELECT);
1835 if (!nested)
1836 goto nla_put_failure;
1837
1838 i = 0;
1839 while (bss_select_support) {
1840 if ((bss_select_support & 1) &&
1841 nla_put_flag(msg, i))
1842 goto nla_put_failure;
1843 i++;
1844 bss_select_support >>= 1;
1845 }
1846 nla_nest_end(msg, nested);
1847 }
1848
Kanchanapally, Vidyullatha019ae3a2016-05-16 10:41:04 +05301849 state->split_start++;
1850 break;
1851 case 13:
1852 if (rdev->wiphy.num_iftype_ext_capab &&
1853 rdev->wiphy.iftype_ext_capab) {
1854 struct nlattr *nested_ext_capab, *nested;
1855
1856 nested = nla_nest_start(msg,
1857 NL80211_ATTR_IFTYPE_EXT_CAPA);
1858 if (!nested)
1859 goto nla_put_failure;
1860
1861 for (i = state->capa_start;
1862 i < rdev->wiphy.num_iftype_ext_capab; i++) {
1863 const struct wiphy_iftype_ext_capab *capab;
1864
1865 capab = &rdev->wiphy.iftype_ext_capab[i];
1866
1867 nested_ext_capab = nla_nest_start(msg, i);
1868 if (!nested_ext_capab ||
1869 nla_put_u32(msg, NL80211_ATTR_IFTYPE,
1870 capab->iftype) ||
1871 nla_put(msg, NL80211_ATTR_EXT_CAPA,
1872 capab->extended_capabilities_len,
1873 capab->extended_capabilities) ||
1874 nla_put(msg, NL80211_ATTR_EXT_CAPA_MASK,
1875 capab->extended_capabilities_len,
1876 capab->extended_capabilities_mask))
1877 goto nla_put_failure;
1878
1879 nla_nest_end(msg, nested_ext_capab);
1880 if (state->split)
1881 break;
1882 }
1883 nla_nest_end(msg, nested);
1884 if (i < rdev->wiphy.num_iftype_ext_capab) {
1885 state->capa_start = i + 1;
1886 break;
1887 }
1888 }
1889
Luca Coelho85859892017-02-08 15:00:34 +02001890 if (nla_put_u32(msg, NL80211_ATTR_BANDS,
1891 rdev->wiphy.nan_supported_bands))
1892 goto nla_put_failure;
1893
Johannes Berg3713b4e2013-02-14 16:19:38 +01001894 /* done */
Johannes Berg86e8cf92013-06-19 10:57:22 +02001895 state->split_start = 0;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001896 break;
Johannes Bergff1b6e62011-05-04 15:37:28 +02001897 }
Johannes Berg3bb20552014-05-26 13:52:25 +02001898 finish:
Johannes Berg053c0952015-01-16 22:09:00 +01001899 genlmsg_end(msg, hdr);
1900 return 0;
Johannes Berg55682962007-09-20 13:09:35 -04001901
1902 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07001903 genlmsg_cancel(msg, hdr);
1904 return -EMSGSIZE;
Johannes Berg55682962007-09-20 13:09:35 -04001905}
1906
Johannes Berg86e8cf92013-06-19 10:57:22 +02001907static int nl80211_dump_wiphy_parse(struct sk_buff *skb,
1908 struct netlink_callback *cb,
1909 struct nl80211_dump_wiphy_state *state)
1910{
Johannes Bergc90c39d2016-10-24 14:40:01 +02001911 struct nlattr **tb = genl_family_attrbuf(&nl80211_fam);
Johannes Bergfceb6432017-04-12 14:34:07 +02001912 int ret = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize, tb,
1913 nl80211_fam.maxattr, nl80211_policy, NULL);
Johannes Berg86e8cf92013-06-19 10:57:22 +02001914 /* ignore parse errors for backward compatibility */
1915 if (ret)
1916 return 0;
1917
1918 state->split = tb[NL80211_ATTR_SPLIT_WIPHY_DUMP];
1919 if (tb[NL80211_ATTR_WIPHY])
1920 state->filter_wiphy = nla_get_u32(tb[NL80211_ATTR_WIPHY]);
1921 if (tb[NL80211_ATTR_WDEV])
1922 state->filter_wiphy = nla_get_u64(tb[NL80211_ATTR_WDEV]) >> 32;
1923 if (tb[NL80211_ATTR_IFINDEX]) {
1924 struct net_device *netdev;
1925 struct cfg80211_registered_device *rdev;
1926 int ifidx = nla_get_u32(tb[NL80211_ATTR_IFINDEX]);
1927
Ying Xue7f2b8562014-01-15 10:23:45 +08001928 netdev = __dev_get_by_index(sock_net(skb->sk), ifidx);
Johannes Berg86e8cf92013-06-19 10:57:22 +02001929 if (!netdev)
1930 return -ENODEV;
1931 if (netdev->ieee80211_ptr) {
Zhao, Gangf26cbf42014-04-21 12:53:03 +08001932 rdev = wiphy_to_rdev(
Johannes Berg86e8cf92013-06-19 10:57:22 +02001933 netdev->ieee80211_ptr->wiphy);
1934 state->filter_wiphy = rdev->wiphy_idx;
1935 }
Johannes Berg86e8cf92013-06-19 10:57:22 +02001936 }
1937
1938 return 0;
1939}
1940
Johannes Berg55682962007-09-20 13:09:35 -04001941static int nl80211_dump_wiphy(struct sk_buff *skb, struct netlink_callback *cb)
1942{
Johannes Berg645e77d2013-03-01 14:03:49 +01001943 int idx = 0, ret;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001944 struct nl80211_dump_wiphy_state *state = (void *)cb->args[0];
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001945 struct cfg80211_registered_device *rdev;
Johannes Berg3a5a4232013-06-19 10:09:57 +02001946
Johannes Berg5fe231e2013-05-08 21:45:15 +02001947 rtnl_lock();
Johannes Berg86e8cf92013-06-19 10:57:22 +02001948 if (!state) {
1949 state = kzalloc(sizeof(*state), GFP_KERNEL);
John W. Linville57ed5cd2013-06-28 13:18:21 -04001950 if (!state) {
1951 rtnl_unlock();
Johannes Berg86e8cf92013-06-19 10:57:22 +02001952 return -ENOMEM;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001953 }
Johannes Berg86e8cf92013-06-19 10:57:22 +02001954 state->filter_wiphy = -1;
1955 ret = nl80211_dump_wiphy_parse(skb, cb, state);
1956 if (ret) {
1957 kfree(state);
1958 rtnl_unlock();
1959 return ret;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001960 }
Johannes Berg86e8cf92013-06-19 10:57:22 +02001961 cb->args[0] = (long)state;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001962 }
1963
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001964 list_for_each_entry(rdev, &cfg80211_rdev_list, list) {
1965 if (!net_eq(wiphy_net(&rdev->wiphy), sock_net(skb->sk)))
Johannes Berg463d0182009-07-14 00:33:35 +02001966 continue;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001967 if (++idx <= state->start)
Johannes Berg55682962007-09-20 13:09:35 -04001968 continue;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001969 if (state->filter_wiphy != -1 &&
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001970 state->filter_wiphy != rdev->wiphy_idx)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001971 continue;
1972 /* attempt to fit multiple wiphy data chunks into the skb */
1973 do {
Johannes Berg3bb20552014-05-26 13:52:25 +02001974 ret = nl80211_send_wiphy(rdev, NL80211_CMD_NEW_WIPHY,
1975 skb,
Johannes Berg3713b4e2013-02-14 16:19:38 +01001976 NETLINK_CB(cb->skb).portid,
1977 cb->nlh->nlmsg_seq,
Johannes Berg86e8cf92013-06-19 10:57:22 +02001978 NLM_F_MULTI, state);
Johannes Berg3713b4e2013-02-14 16:19:38 +01001979 if (ret < 0) {
1980 /*
1981 * If sending the wiphy data didn't fit (ENOBUFS
1982 * or EMSGSIZE returned), this SKB is still
1983 * empty (so it's not too big because another
1984 * wiphy dataset is already in the skb) and
1985 * we've not tried to adjust the dump allocation
1986 * yet ... then adjust the alloc size to be
1987 * bigger, and return 1 but with the empty skb.
1988 * This results in an empty message being RX'ed
1989 * in userspace, but that is ignored.
1990 *
1991 * We can then retry with the larger buffer.
1992 */
1993 if ((ret == -ENOBUFS || ret == -EMSGSIZE) &&
Pontus Fuchsf12cb282014-01-16 15:00:40 +01001994 !skb->len && !state->split &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001995 cb->min_dump_alloc < 4096) {
1996 cb->min_dump_alloc = 4096;
Pontus Fuchsf12cb282014-01-16 15:00:40 +01001997 state->split_start = 0;
David S. Millerd98cae64e2013-06-19 16:49:39 -07001998 rtnl_unlock();
Johannes Berg3713b4e2013-02-14 16:19:38 +01001999 return 1;
2000 }
2001 idx--;
2002 break;
Johannes Berg645e77d2013-03-01 14:03:49 +01002003 }
Johannes Berg86e8cf92013-06-19 10:57:22 +02002004 } while (state->split_start > 0);
Johannes Berg3713b4e2013-02-14 16:19:38 +01002005 break;
Johannes Berg55682962007-09-20 13:09:35 -04002006 }
Johannes Berg5fe231e2013-05-08 21:45:15 +02002007 rtnl_unlock();
Johannes Berg55682962007-09-20 13:09:35 -04002008
Johannes Berg86e8cf92013-06-19 10:57:22 +02002009 state->start = idx;
Johannes Berg55682962007-09-20 13:09:35 -04002010
2011 return skb->len;
2012}
2013
Johannes Berg86e8cf92013-06-19 10:57:22 +02002014static int nl80211_dump_wiphy_done(struct netlink_callback *cb)
2015{
2016 kfree((void *)cb->args[0]);
2017 return 0;
2018}
2019
Johannes Berg55682962007-09-20 13:09:35 -04002020static int nl80211_get_wiphy(struct sk_buff *skb, struct genl_info *info)
2021{
2022 struct sk_buff *msg;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002023 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg86e8cf92013-06-19 10:57:22 +02002024 struct nl80211_dump_wiphy_state state = {};
Johannes Berg55682962007-09-20 13:09:35 -04002025
Johannes Berg645e77d2013-03-01 14:03:49 +01002026 msg = nlmsg_new(4096, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -04002027 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02002028 return -ENOMEM;
Johannes Berg55682962007-09-20 13:09:35 -04002029
Johannes Berg3bb20552014-05-26 13:52:25 +02002030 if (nl80211_send_wiphy(rdev, NL80211_CMD_NEW_WIPHY, msg,
2031 info->snd_portid, info->snd_seq, 0,
Johannes Berg86e8cf92013-06-19 10:57:22 +02002032 &state) < 0) {
Johannes Berg4c476992010-10-04 21:36:35 +02002033 nlmsg_free(msg);
2034 return -ENOBUFS;
2035 }
Johannes Berg55682962007-09-20 13:09:35 -04002036
Johannes Berg134e6372009-07-10 09:51:34 +00002037 return genlmsg_reply(msg, info);
Johannes Berg55682962007-09-20 13:09:35 -04002038}
2039
Jouni Malinen31888482008-10-30 16:59:24 +02002040static const struct nla_policy txq_params_policy[NL80211_TXQ_ATTR_MAX + 1] = {
2041 [NL80211_TXQ_ATTR_QUEUE] = { .type = NLA_U8 },
2042 [NL80211_TXQ_ATTR_TXOP] = { .type = NLA_U16 },
2043 [NL80211_TXQ_ATTR_CWMIN] = { .type = NLA_U16 },
2044 [NL80211_TXQ_ATTR_CWMAX] = { .type = NLA_U16 },
2045 [NL80211_TXQ_ATTR_AIFS] = { .type = NLA_U8 },
2046};
2047
2048static int parse_txq_params(struct nlattr *tb[],
2049 struct ieee80211_txq_params *txq_params)
2050{
Johannes Berga3304b02012-03-28 11:04:24 +02002051 if (!tb[NL80211_TXQ_ATTR_AC] || !tb[NL80211_TXQ_ATTR_TXOP] ||
Jouni Malinen31888482008-10-30 16:59:24 +02002052 !tb[NL80211_TXQ_ATTR_CWMIN] || !tb[NL80211_TXQ_ATTR_CWMAX] ||
2053 !tb[NL80211_TXQ_ATTR_AIFS])
2054 return -EINVAL;
2055
Johannes Berga3304b02012-03-28 11:04:24 +02002056 txq_params->ac = nla_get_u8(tb[NL80211_TXQ_ATTR_AC]);
Jouni Malinen31888482008-10-30 16:59:24 +02002057 txq_params->txop = nla_get_u16(tb[NL80211_TXQ_ATTR_TXOP]);
2058 txq_params->cwmin = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMIN]);
2059 txq_params->cwmax = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMAX]);
2060 txq_params->aifs = nla_get_u8(tb[NL80211_TXQ_ATTR_AIFS]);
2061
Johannes Berga3304b02012-03-28 11:04:24 +02002062 if (txq_params->ac >= NL80211_NUM_ACS)
2063 return -EINVAL;
2064
Jouni Malinen31888482008-10-30 16:59:24 +02002065 return 0;
2066}
2067
Johannes Bergf444de02010-05-05 15:25:02 +02002068static bool nl80211_can_set_dev_channel(struct wireless_dev *wdev)
2069{
2070 /*
Johannes Bergcc1d2802012-05-16 23:50:20 +02002071 * You can only set the channel explicitly for WDS interfaces,
2072 * all others have their channel managed via their respective
2073 * "establish a connection" command (connect, join, ...)
2074 *
2075 * For AP/GO and mesh mode, the channel can be set with the
2076 * channel userspace API, but is only stored and passed to the
2077 * low-level driver when the AP starts or the mesh is joined.
2078 * This is for backward compatibility, userspace can also give
2079 * the channel in the start-ap or join-mesh commands instead.
Johannes Bergf444de02010-05-05 15:25:02 +02002080 *
2081 * Monitors are special as they are normally slaved to
Johannes Berge8c9bd52012-06-06 08:18:22 +02002082 * whatever else is going on, so they have their own special
2083 * operation to set the monitor channel if possible.
Johannes Bergf444de02010-05-05 15:25:02 +02002084 */
2085 return !wdev ||
2086 wdev->iftype == NL80211_IFTYPE_AP ||
Johannes Bergf444de02010-05-05 15:25:02 +02002087 wdev->iftype == NL80211_IFTYPE_MESH_POINT ||
Johannes Berg074ac8d2010-09-16 14:58:22 +02002088 wdev->iftype == NL80211_IFTYPE_MONITOR ||
2089 wdev->iftype == NL80211_IFTYPE_P2P_GO;
Johannes Bergf444de02010-05-05 15:25:02 +02002090}
2091
Johannes Berg683b6d32012-11-08 21:25:48 +01002092static int nl80211_parse_chandef(struct cfg80211_registered_device *rdev,
2093 struct genl_info *info,
2094 struct cfg80211_chan_def *chandef)
2095{
Mahesh Paliveladbeca2e2012-11-29 14:11:07 +05302096 u32 control_freq;
Johannes Berg683b6d32012-11-08 21:25:48 +01002097
2098 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ])
2099 return -EINVAL;
2100
2101 control_freq = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]);
2102
2103 chandef->chan = ieee80211_get_channel(&rdev->wiphy, control_freq);
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002104 chandef->width = NL80211_CHAN_WIDTH_20_NOHT;
2105 chandef->center_freq1 = control_freq;
2106 chandef->center_freq2 = 0;
Johannes Berg683b6d32012-11-08 21:25:48 +01002107
2108 /* Primary channel not allowed */
2109 if (!chandef->chan || chandef->chan->flags & IEEE80211_CHAN_DISABLED)
2110 return -EINVAL;
2111
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002112 if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]) {
2113 enum nl80211_channel_type chantype;
Johannes Berg683b6d32012-11-08 21:25:48 +01002114
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002115 chantype = nla_get_u32(
2116 info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]);
2117
2118 switch (chantype) {
2119 case NL80211_CHAN_NO_HT:
2120 case NL80211_CHAN_HT20:
2121 case NL80211_CHAN_HT40PLUS:
2122 case NL80211_CHAN_HT40MINUS:
2123 cfg80211_chandef_create(chandef, chandef->chan,
2124 chantype);
2125 break;
2126 default:
Johannes Berg683b6d32012-11-08 21:25:48 +01002127 return -EINVAL;
Johannes Berg683b6d32012-11-08 21:25:48 +01002128 }
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002129 } else if (info->attrs[NL80211_ATTR_CHANNEL_WIDTH]) {
2130 chandef->width =
2131 nla_get_u32(info->attrs[NL80211_ATTR_CHANNEL_WIDTH]);
2132 if (info->attrs[NL80211_ATTR_CENTER_FREQ1])
2133 chandef->center_freq1 =
2134 nla_get_u32(
2135 info->attrs[NL80211_ATTR_CENTER_FREQ1]);
2136 if (info->attrs[NL80211_ATTR_CENTER_FREQ2])
2137 chandef->center_freq2 =
2138 nla_get_u32(
2139 info->attrs[NL80211_ATTR_CENTER_FREQ2]);
2140 }
2141
Johannes Berg9f5e8f62012-11-22 16:59:45 +01002142 if (!cfg80211_chandef_valid(chandef))
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002143 return -EINVAL;
2144
Johannes Berg9f5e8f62012-11-22 16:59:45 +01002145 if (!cfg80211_chandef_usable(&rdev->wiphy, chandef,
2146 IEEE80211_CHAN_DISABLED))
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002147 return -EINVAL;
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002148
Simon Wunderlich2f301ab2013-05-16 13:00:28 +02002149 if ((chandef->width == NL80211_CHAN_WIDTH_5 ||
2150 chandef->width == NL80211_CHAN_WIDTH_10) &&
2151 !(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_5_10_MHZ))
2152 return -EINVAL;
2153
Johannes Berg683b6d32012-11-08 21:25:48 +01002154 return 0;
2155}
2156
Johannes Bergf444de02010-05-05 15:25:02 +02002157static int __nl80211_set_channel(struct cfg80211_registered_device *rdev,
Jouni Malinene16821b2014-04-28 11:22:08 +03002158 struct net_device *dev,
Johannes Bergf444de02010-05-05 15:25:02 +02002159 struct genl_info *info)
2160{
Johannes Berg683b6d32012-11-08 21:25:48 +01002161 struct cfg80211_chan_def chandef;
Johannes Bergf444de02010-05-05 15:25:02 +02002162 int result;
Johannes Berge8c9bd52012-06-06 08:18:22 +02002163 enum nl80211_iftype iftype = NL80211_IFTYPE_MONITOR;
Jouni Malinene16821b2014-04-28 11:22:08 +03002164 struct wireless_dev *wdev = NULL;
Johannes Berge8c9bd52012-06-06 08:18:22 +02002165
Jouni Malinene16821b2014-04-28 11:22:08 +03002166 if (dev)
2167 wdev = dev->ieee80211_ptr;
Johannes Bergf444de02010-05-05 15:25:02 +02002168 if (!nl80211_can_set_dev_channel(wdev))
2169 return -EOPNOTSUPP;
Jouni Malinene16821b2014-04-28 11:22:08 +03002170 if (wdev)
2171 iftype = wdev->iftype;
Johannes Bergf444de02010-05-05 15:25:02 +02002172
Johannes Berg683b6d32012-11-08 21:25:48 +01002173 result = nl80211_parse_chandef(rdev, info, &chandef);
2174 if (result)
2175 return result;
Johannes Bergf444de02010-05-05 15:25:02 +02002176
Johannes Berge8c9bd52012-06-06 08:18:22 +02002177 switch (iftype) {
Johannes Bergaa430da2012-05-16 23:50:18 +02002178 case NL80211_IFTYPE_AP:
2179 case NL80211_IFTYPE_P2P_GO:
Arik Nemtsov923b3522015-07-08 15:41:44 +03002180 if (!cfg80211_reg_can_beacon_relax(&rdev->wiphy, &chandef,
2181 iftype)) {
Johannes Bergaa430da2012-05-16 23:50:18 +02002182 result = -EINVAL;
2183 break;
2184 }
Jouni Malinene16821b2014-04-28 11:22:08 +03002185 if (wdev->beacon_interval) {
2186 if (!dev || !rdev->ops->set_ap_chanwidth ||
2187 !(rdev->wiphy.features &
2188 NL80211_FEATURE_AP_MODE_CHAN_WIDTH_CHANGE)) {
2189 result = -EBUSY;
2190 break;
2191 }
2192
2193 /* Only allow dynamic channel width changes */
2194 if (chandef.chan != wdev->preset_chandef.chan) {
2195 result = -EBUSY;
2196 break;
2197 }
2198 result = rdev_set_ap_chanwidth(rdev, dev, &chandef);
2199 if (result)
2200 break;
2201 }
Johannes Berg683b6d32012-11-08 21:25:48 +01002202 wdev->preset_chandef = chandef;
Johannes Bergaa430da2012-05-16 23:50:18 +02002203 result = 0;
2204 break;
Johannes Bergcc1d2802012-05-16 23:50:20 +02002205 case NL80211_IFTYPE_MESH_POINT:
Johannes Berg683b6d32012-11-08 21:25:48 +01002206 result = cfg80211_set_mesh_channel(rdev, wdev, &chandef);
Johannes Bergcc1d2802012-05-16 23:50:20 +02002207 break;
Johannes Berge8c9bd52012-06-06 08:18:22 +02002208 case NL80211_IFTYPE_MONITOR:
Johannes Berg683b6d32012-11-08 21:25:48 +01002209 result = cfg80211_set_monitor_channel(rdev, &chandef);
Johannes Berge8c9bd52012-06-06 08:18:22 +02002210 break;
Johannes Bergaa430da2012-05-16 23:50:18 +02002211 default:
Johannes Berge8c9bd52012-06-06 08:18:22 +02002212 result = -EINVAL;
Johannes Bergf444de02010-05-05 15:25:02 +02002213 }
Johannes Bergf444de02010-05-05 15:25:02 +02002214
2215 return result;
2216}
2217
2218static int nl80211_set_channel(struct sk_buff *skb, struct genl_info *info)
2219{
Johannes Berg4c476992010-10-04 21:36:35 +02002220 struct cfg80211_registered_device *rdev = info->user_ptr[0];
2221 struct net_device *netdev = info->user_ptr[1];
Johannes Bergf444de02010-05-05 15:25:02 +02002222
Jouni Malinene16821b2014-04-28 11:22:08 +03002223 return __nl80211_set_channel(rdev, netdev, info);
Johannes Bergf444de02010-05-05 15:25:02 +02002224}
2225
Bill Jordane8347eb2010-10-01 13:54:28 -04002226static int nl80211_set_wds_peer(struct sk_buff *skb, struct genl_info *info)
2227{
Johannes Berg43b19952010-10-07 13:10:30 +02002228 struct cfg80211_registered_device *rdev = info->user_ptr[0];
2229 struct net_device *dev = info->user_ptr[1];
2230 struct wireless_dev *wdev = dev->ieee80211_ptr;
Johannes Berg388ac772010-10-07 13:11:09 +02002231 const u8 *bssid;
Bill Jordane8347eb2010-10-01 13:54:28 -04002232
2233 if (!info->attrs[NL80211_ATTR_MAC])
2234 return -EINVAL;
2235
Johannes Berg43b19952010-10-07 13:10:30 +02002236 if (netif_running(dev))
2237 return -EBUSY;
Bill Jordane8347eb2010-10-01 13:54:28 -04002238
Johannes Berg43b19952010-10-07 13:10:30 +02002239 if (!rdev->ops->set_wds_peer)
2240 return -EOPNOTSUPP;
Bill Jordane8347eb2010-10-01 13:54:28 -04002241
Johannes Berg43b19952010-10-07 13:10:30 +02002242 if (wdev->iftype != NL80211_IFTYPE_WDS)
2243 return -EOPNOTSUPP;
Bill Jordane8347eb2010-10-01 13:54:28 -04002244
2245 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Hila Gonene35e4d22012-06-27 17:19:42 +03002246 return rdev_set_wds_peer(rdev, dev, bssid);
Bill Jordane8347eb2010-10-01 13:54:28 -04002247}
2248
Johannes Berg55682962007-09-20 13:09:35 -04002249static int nl80211_set_wiphy(struct sk_buff *skb, struct genl_info *info)
2250{
2251 struct cfg80211_registered_device *rdev;
Johannes Bergf444de02010-05-05 15:25:02 +02002252 struct net_device *netdev = NULL;
2253 struct wireless_dev *wdev;
Bill Jordana1e567c2010-09-10 11:22:32 -04002254 int result = 0, rem_txq_params = 0;
Jouni Malinen31888482008-10-30 16:59:24 +02002255 struct nlattr *nl_txq_params;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002256 u32 changed;
2257 u8 retry_short = 0, retry_long = 0;
2258 u32 frag_threshold = 0, rts_threshold = 0;
Lukáš Turek81077e82009-12-21 22:50:47 +01002259 u8 coverage_class = 0;
Johannes Berg55682962007-09-20 13:09:35 -04002260
Johannes Berg5fe231e2013-05-08 21:45:15 +02002261 ASSERT_RTNL();
2262
Johannes Bergf444de02010-05-05 15:25:02 +02002263 /*
2264 * Try to find the wiphy and netdev. Normally this
2265 * function shouldn't need the netdev, but this is
2266 * done for backward compatibility -- previously
2267 * setting the channel was done per wiphy, but now
2268 * it is per netdev. Previous userland like hostapd
2269 * also passed a netdev to set_wiphy, so that it is
2270 * possible to let that go to the right netdev!
2271 */
Johannes Berg4bbf4d52009-03-24 09:35:46 +01002272
Johannes Bergf444de02010-05-05 15:25:02 +02002273 if (info->attrs[NL80211_ATTR_IFINDEX]) {
2274 int ifindex = nla_get_u32(info->attrs[NL80211_ATTR_IFINDEX]);
2275
Ying Xue7f2b8562014-01-15 10:23:45 +08002276 netdev = __dev_get_by_index(genl_info_net(info), ifindex);
Johannes Berg5fe231e2013-05-08 21:45:15 +02002277 if (netdev && netdev->ieee80211_ptr)
Zhao, Gangf26cbf42014-04-21 12:53:03 +08002278 rdev = wiphy_to_rdev(netdev->ieee80211_ptr->wiphy);
Johannes Berg5fe231e2013-05-08 21:45:15 +02002279 else
Johannes Bergf444de02010-05-05 15:25:02 +02002280 netdev = NULL;
Johannes Berg4bbf4d52009-03-24 09:35:46 +01002281 }
2282
Johannes Bergf444de02010-05-05 15:25:02 +02002283 if (!netdev) {
Johannes Berg878d9ec2012-06-15 14:18:32 +02002284 rdev = __cfg80211_rdev_from_attrs(genl_info_net(info),
2285 info->attrs);
Johannes Berg5fe231e2013-05-08 21:45:15 +02002286 if (IS_ERR(rdev))
Johannes Berg4c476992010-10-04 21:36:35 +02002287 return PTR_ERR(rdev);
Johannes Bergf444de02010-05-05 15:25:02 +02002288 wdev = NULL;
2289 netdev = NULL;
2290 result = 0;
Johannes Berg71fe96b2012-10-24 10:04:58 +02002291 } else
Johannes Bergf444de02010-05-05 15:25:02 +02002292 wdev = netdev->ieee80211_ptr;
Johannes Bergf444de02010-05-05 15:25:02 +02002293
2294 /*
2295 * end workaround code, by now the rdev is available
2296 * and locked, and wdev may or may not be NULL.
2297 */
Johannes Berg4bbf4d52009-03-24 09:35:46 +01002298
2299 if (info->attrs[NL80211_ATTR_WIPHY_NAME])
Jouni Malinen31888482008-10-30 16:59:24 +02002300 result = cfg80211_dev_rename(
2301 rdev, nla_data(info->attrs[NL80211_ATTR_WIPHY_NAME]));
Johannes Berg4bbf4d52009-03-24 09:35:46 +01002302
Johannes Berg4bbf4d52009-03-24 09:35:46 +01002303 if (result)
Ying Xue7f2b8562014-01-15 10:23:45 +08002304 return result;
Johannes Berg55682962007-09-20 13:09:35 -04002305
Jouni Malinen31888482008-10-30 16:59:24 +02002306 if (info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS]) {
2307 struct ieee80211_txq_params txq_params;
2308 struct nlattr *tb[NL80211_TXQ_ATTR_MAX + 1];
2309
Ying Xue7f2b8562014-01-15 10:23:45 +08002310 if (!rdev->ops->set_txq_params)
2311 return -EOPNOTSUPP;
Jouni Malinen31888482008-10-30 16:59:24 +02002312
Ying Xue7f2b8562014-01-15 10:23:45 +08002313 if (!netdev)
2314 return -EINVAL;
Eliad Pellerf70f01c2011-09-25 20:06:53 +03002315
Johannes Berg133a3ff2011-11-03 14:50:13 +01002316 if (netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
Ying Xue7f2b8562014-01-15 10:23:45 +08002317 netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
2318 return -EINVAL;
Johannes Berg133a3ff2011-11-03 14:50:13 +01002319
Ying Xue7f2b8562014-01-15 10:23:45 +08002320 if (!netif_running(netdev))
2321 return -ENETDOWN;
Johannes Berg2b5f8b02012-04-02 10:51:55 +02002322
Jouni Malinen31888482008-10-30 16:59:24 +02002323 nla_for_each_nested(nl_txq_params,
2324 info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS],
2325 rem_txq_params) {
Johannes Bergbfe2c7b2016-10-26 14:42:21 +02002326 result = nla_parse_nested(tb, NL80211_TXQ_ATTR_MAX,
2327 nl_txq_params,
Johannes Bergfe521452017-04-12 14:34:08 +02002328 txq_params_policy,
2329 info->extack);
Johannes Bergae811e22014-01-24 10:17:47 +01002330 if (result)
2331 return result;
Jouni Malinen31888482008-10-30 16:59:24 +02002332 result = parse_txq_params(tb, &txq_params);
2333 if (result)
Ying Xue7f2b8562014-01-15 10:23:45 +08002334 return result;
Jouni Malinen31888482008-10-30 16:59:24 +02002335
Hila Gonene35e4d22012-06-27 17:19:42 +03002336 result = rdev_set_txq_params(rdev, netdev,
2337 &txq_params);
Jouni Malinen31888482008-10-30 16:59:24 +02002338 if (result)
Ying Xue7f2b8562014-01-15 10:23:45 +08002339 return result;
Jouni Malinen31888482008-10-30 16:59:24 +02002340 }
2341 }
2342
Jouni Malinen72bdcf32008-11-26 16:15:24 +02002343 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
Jouni Malinene16821b2014-04-28 11:22:08 +03002344 result = __nl80211_set_channel(
2345 rdev,
2346 nl80211_can_set_dev_channel(wdev) ? netdev : NULL,
2347 info);
Jouni Malinen72bdcf32008-11-26 16:15:24 +02002348 if (result)
Ying Xue7f2b8562014-01-15 10:23:45 +08002349 return result;
Jouni Malinen72bdcf32008-11-26 16:15:24 +02002350 }
2351
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03002352 if (info->attrs[NL80211_ATTR_WIPHY_TX_POWER_SETTING]) {
Johannes Bergc8442112012-10-24 10:17:18 +02002353 struct wireless_dev *txp_wdev = wdev;
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03002354 enum nl80211_tx_power_setting type;
2355 int idx, mbm = 0;
2356
Johannes Bergc8442112012-10-24 10:17:18 +02002357 if (!(rdev->wiphy.features & NL80211_FEATURE_VIF_TXPOWER))
2358 txp_wdev = NULL;
2359
Ying Xue7f2b8562014-01-15 10:23:45 +08002360 if (!rdev->ops->set_tx_power)
2361 return -EOPNOTSUPP;
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03002362
2363 idx = NL80211_ATTR_WIPHY_TX_POWER_SETTING;
2364 type = nla_get_u32(info->attrs[idx]);
2365
2366 if (!info->attrs[NL80211_ATTR_WIPHY_TX_POWER_LEVEL] &&
Ying Xue7f2b8562014-01-15 10:23:45 +08002367 (type != NL80211_TX_POWER_AUTOMATIC))
2368 return -EINVAL;
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03002369
2370 if (type != NL80211_TX_POWER_AUTOMATIC) {
2371 idx = NL80211_ATTR_WIPHY_TX_POWER_LEVEL;
2372 mbm = nla_get_u32(info->attrs[idx]);
2373 }
2374
Johannes Bergc8442112012-10-24 10:17:18 +02002375 result = rdev_set_tx_power(rdev, txp_wdev, type, mbm);
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03002376 if (result)
Ying Xue7f2b8562014-01-15 10:23:45 +08002377 return result;
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03002378 }
2379
Bruno Randolfafe0cbf2010-11-10 12:50:50 +09002380 if (info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX] &&
2381 info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]) {
2382 u32 tx_ant, rx_ant;
Kirtika Ruchandani7a087e72016-05-29 19:51:23 -07002383
Bruno Randolf7f531e02010-12-16 11:30:22 +09002384 if ((!rdev->wiphy.available_antennas_tx &&
2385 !rdev->wiphy.available_antennas_rx) ||
Ying Xue7f2b8562014-01-15 10:23:45 +08002386 !rdev->ops->set_antenna)
2387 return -EOPNOTSUPP;
Bruno Randolfafe0cbf2010-11-10 12:50:50 +09002388
2389 tx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX]);
2390 rx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]);
2391
Bruno Randolfa7ffac92010-12-08 13:59:24 +09002392 /* reject antenna configurations which don't match the
Bruno Randolf7f531e02010-12-16 11:30:22 +09002393 * available antenna masks, except for the "all" mask */
2394 if ((~tx_ant && (tx_ant & ~rdev->wiphy.available_antennas_tx)) ||
Ying Xue7f2b8562014-01-15 10:23:45 +08002395 (~rx_ant && (rx_ant & ~rdev->wiphy.available_antennas_rx)))
2396 return -EINVAL;
Bruno Randolfa7ffac92010-12-08 13:59:24 +09002397
Bruno Randolf7f531e02010-12-16 11:30:22 +09002398 tx_ant = tx_ant & rdev->wiphy.available_antennas_tx;
2399 rx_ant = rx_ant & rdev->wiphy.available_antennas_rx;
Bruno Randolfa7ffac92010-12-08 13:59:24 +09002400
Hila Gonene35e4d22012-06-27 17:19:42 +03002401 result = rdev_set_antenna(rdev, tx_ant, rx_ant);
Bruno Randolfafe0cbf2010-11-10 12:50:50 +09002402 if (result)
Ying Xue7f2b8562014-01-15 10:23:45 +08002403 return result;
Bruno Randolfafe0cbf2010-11-10 12:50:50 +09002404 }
2405
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002406 changed = 0;
2407
2408 if (info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]) {
2409 retry_short = nla_get_u8(
2410 info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]);
Ying Xue7f2b8562014-01-15 10:23:45 +08002411 if (retry_short == 0)
2412 return -EINVAL;
2413
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002414 changed |= WIPHY_PARAM_RETRY_SHORT;
2415 }
2416
2417 if (info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]) {
2418 retry_long = nla_get_u8(
2419 info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]);
Ying Xue7f2b8562014-01-15 10:23:45 +08002420 if (retry_long == 0)
2421 return -EINVAL;
2422
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002423 changed |= WIPHY_PARAM_RETRY_LONG;
2424 }
2425
2426 if (info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]) {
2427 frag_threshold = nla_get_u32(
2428 info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]);
Ying Xue7f2b8562014-01-15 10:23:45 +08002429 if (frag_threshold < 256)
2430 return -EINVAL;
2431
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002432 if (frag_threshold != (u32) -1) {
2433 /*
2434 * Fragments (apart from the last one) are required to
2435 * have even length. Make the fragmentation code
2436 * simpler by stripping LSB should someone try to use
2437 * odd threshold value.
2438 */
2439 frag_threshold &= ~0x1;
2440 }
2441 changed |= WIPHY_PARAM_FRAG_THRESHOLD;
2442 }
2443
2444 if (info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]) {
2445 rts_threshold = nla_get_u32(
2446 info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]);
2447 changed |= WIPHY_PARAM_RTS_THRESHOLD;
2448 }
2449
Lukáš Turek81077e82009-12-21 22:50:47 +01002450 if (info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]) {
Lorenzo Bianconi3057dbf2014-09-04 23:57:40 +02002451 if (info->attrs[NL80211_ATTR_WIPHY_DYN_ACK])
2452 return -EINVAL;
2453
Lukáš Turek81077e82009-12-21 22:50:47 +01002454 coverage_class = nla_get_u8(
2455 info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]);
2456 changed |= WIPHY_PARAM_COVERAGE_CLASS;
2457 }
2458
Lorenzo Bianconi3057dbf2014-09-04 23:57:40 +02002459 if (info->attrs[NL80211_ATTR_WIPHY_DYN_ACK]) {
2460 if (!(rdev->wiphy.features & NL80211_FEATURE_ACKTO_ESTIMATION))
2461 return -EOPNOTSUPP;
2462
2463 changed |= WIPHY_PARAM_DYN_ACK;
2464 }
2465
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002466 if (changed) {
2467 u8 old_retry_short, old_retry_long;
2468 u32 old_frag_threshold, old_rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01002469 u8 old_coverage_class;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002470
Ying Xue7f2b8562014-01-15 10:23:45 +08002471 if (!rdev->ops->set_wiphy_params)
2472 return -EOPNOTSUPP;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002473
2474 old_retry_short = rdev->wiphy.retry_short;
2475 old_retry_long = rdev->wiphy.retry_long;
2476 old_frag_threshold = rdev->wiphy.frag_threshold;
2477 old_rts_threshold = rdev->wiphy.rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01002478 old_coverage_class = rdev->wiphy.coverage_class;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002479
2480 if (changed & WIPHY_PARAM_RETRY_SHORT)
2481 rdev->wiphy.retry_short = retry_short;
2482 if (changed & WIPHY_PARAM_RETRY_LONG)
2483 rdev->wiphy.retry_long = retry_long;
2484 if (changed & WIPHY_PARAM_FRAG_THRESHOLD)
2485 rdev->wiphy.frag_threshold = frag_threshold;
2486 if (changed & WIPHY_PARAM_RTS_THRESHOLD)
2487 rdev->wiphy.rts_threshold = rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01002488 if (changed & WIPHY_PARAM_COVERAGE_CLASS)
2489 rdev->wiphy.coverage_class = coverage_class;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002490
Hila Gonene35e4d22012-06-27 17:19:42 +03002491 result = rdev_set_wiphy_params(rdev, changed);
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002492 if (result) {
2493 rdev->wiphy.retry_short = old_retry_short;
2494 rdev->wiphy.retry_long = old_retry_long;
2495 rdev->wiphy.frag_threshold = old_frag_threshold;
2496 rdev->wiphy.rts_threshold = old_rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01002497 rdev->wiphy.coverage_class = old_coverage_class;
Michal Kazior9189ee32015-08-03 10:55:24 +02002498 return result;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002499 }
2500 }
Ying Xue7f2b8562014-01-15 10:23:45 +08002501 return 0;
Johannes Berg55682962007-09-20 13:09:35 -04002502}
2503
Johannes Berg71bbc992012-06-15 15:30:18 +02002504static inline u64 wdev_id(struct wireless_dev *wdev)
2505{
2506 return (u64)wdev->identifier |
Zhao, Gangf26cbf42014-04-21 12:53:03 +08002507 ((u64)wiphy_to_rdev(wdev->wiphy)->wiphy_idx << 32);
Johannes Berg71bbc992012-06-15 15:30:18 +02002508}
Johannes Berg55682962007-09-20 13:09:35 -04002509
Johannes Berg683b6d32012-11-08 21:25:48 +01002510static int nl80211_send_chandef(struct sk_buff *msg,
Janusz Dziedzicd2859df2013-11-06 13:55:51 +01002511 const struct cfg80211_chan_def *chandef)
Johannes Berg683b6d32012-11-08 21:25:48 +01002512{
Johannes Berg601555c2014-11-27 17:26:56 +01002513 if (WARN_ON(!cfg80211_chandef_valid(chandef)))
2514 return -EINVAL;
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002515
Johannes Berg683b6d32012-11-08 21:25:48 +01002516 if (nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ,
2517 chandef->chan->center_freq))
2518 return -ENOBUFS;
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002519 switch (chandef->width) {
2520 case NL80211_CHAN_WIDTH_20_NOHT:
2521 case NL80211_CHAN_WIDTH_20:
2522 case NL80211_CHAN_WIDTH_40:
2523 if (nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE,
2524 cfg80211_get_chandef_type(chandef)))
2525 return -ENOBUFS;
2526 break;
2527 default:
2528 break;
2529 }
2530 if (nla_put_u32(msg, NL80211_ATTR_CHANNEL_WIDTH, chandef->width))
2531 return -ENOBUFS;
2532 if (nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ1, chandef->center_freq1))
2533 return -ENOBUFS;
2534 if (chandef->center_freq2 &&
2535 nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ2, chandef->center_freq2))
Johannes Berg683b6d32012-11-08 21:25:48 +01002536 return -ENOBUFS;
2537 return 0;
2538}
2539
Eric W. Biederman15e47302012-09-07 20:12:54 +00002540static int nl80211_send_iface(struct sk_buff *msg, u32 portid, u32 seq, int flags,
Johannes Bergd7264052009-04-19 16:23:20 +02002541 struct cfg80211_registered_device *rdev,
Tomasz Bursztyka8f894be2014-11-12 16:26:45 +02002542 struct wireless_dev *wdev, bool removal)
Johannes Berg55682962007-09-20 13:09:35 -04002543{
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002544 struct net_device *dev = wdev->netdev;
Tomasz Bursztyka8f894be2014-11-12 16:26:45 +02002545 u8 cmd = NL80211_CMD_NEW_INTERFACE;
Johannes Berg55682962007-09-20 13:09:35 -04002546 void *hdr;
2547
Tomasz Bursztyka8f894be2014-11-12 16:26:45 +02002548 if (removal)
2549 cmd = NL80211_CMD_DEL_INTERFACE;
2550
2551 hdr = nl80211hdr_put(msg, portid, seq, flags, cmd);
Johannes Berg55682962007-09-20 13:09:35 -04002552 if (!hdr)
2553 return -1;
2554
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002555 if (dev &&
2556 (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
Johannes Berg98104fde2012-06-16 00:19:54 +02002557 nla_put_string(msg, NL80211_ATTR_IFNAME, dev->name)))
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002558 goto nla_put_failure;
2559
2560 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
2561 nla_put_u32(msg, NL80211_ATTR_IFTYPE, wdev->iftype) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02002562 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
2563 NL80211_ATTR_PAD) ||
Johannes Berg98104fde2012-06-16 00:19:54 +02002564 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, wdev_address(wdev)) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04002565 nla_put_u32(msg, NL80211_ATTR_GENERATION,
2566 rdev->devlist_generation ^
2567 (cfg80211_rdev_list_generation << 2)))
2568 goto nla_put_failure;
Johannes Bergf5ea9122009-08-07 16:17:38 +02002569
Johannes Berg5b7ccaf2012-07-12 19:45:08 +02002570 if (rdev->ops->get_channel) {
Johannes Berg683b6d32012-11-08 21:25:48 +01002571 int ret;
2572 struct cfg80211_chan_def chandef;
Johannes Berg5b7ccaf2012-07-12 19:45:08 +02002573
Johannes Berg683b6d32012-11-08 21:25:48 +01002574 ret = rdev_get_channel(rdev, wdev, &chandef);
2575 if (ret == 0) {
2576 if (nl80211_send_chandef(msg, &chandef))
2577 goto nla_put_failure;
2578 }
Pontus Fuchsd91df0e2012-04-03 16:39:58 +02002579 }
2580
Rafał Miłeckid55d0d52015-08-31 22:59:38 +02002581 if (rdev->ops->get_tx_power) {
2582 int dbm, ret;
2583
2584 ret = rdev_get_tx_power(rdev, wdev, &dbm);
2585 if (ret == 0 &&
2586 nla_put_u32(msg, NL80211_ATTR_WIPHY_TX_POWER_LEVEL,
2587 DBM_TO_MBM(dbm)))
2588 goto nla_put_failure;
2589 }
2590
Antonio Quartullib84e7a02012-11-07 12:52:20 +01002591 if (wdev->ssid_len) {
2592 if (nla_put(msg, NL80211_ATTR_SSID, wdev->ssid_len, wdev->ssid))
2593 goto nla_put_failure;
2594 }
2595
Johannes Berg053c0952015-01-16 22:09:00 +01002596 genlmsg_end(msg, hdr);
2597 return 0;
Johannes Berg55682962007-09-20 13:09:35 -04002598
2599 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07002600 genlmsg_cancel(msg, hdr);
2601 return -EMSGSIZE;
Johannes Berg55682962007-09-20 13:09:35 -04002602}
2603
2604static int nl80211_dump_interface(struct sk_buff *skb, struct netlink_callback *cb)
2605{
2606 int wp_idx = 0;
2607 int if_idx = 0;
2608 int wp_start = cb->args[0];
2609 int if_start = cb->args[1];
Denis Kenziorb7fb44d2016-08-03 17:02:15 -05002610 int filter_wiphy = -1;
Johannes Bergf5ea9122009-08-07 16:17:38 +02002611 struct cfg80211_registered_device *rdev;
Johannes Berg55682962007-09-20 13:09:35 -04002612 struct wireless_dev *wdev;
Johannes Bergea90e0d2017-03-15 14:26:04 +01002613 int ret;
Johannes Berg55682962007-09-20 13:09:35 -04002614
Johannes Berg5fe231e2013-05-08 21:45:15 +02002615 rtnl_lock();
Denis Kenziorb7fb44d2016-08-03 17:02:15 -05002616 if (!cb->args[2]) {
2617 struct nl80211_dump_wiphy_state state = {
2618 .filter_wiphy = -1,
2619 };
Denis Kenziorb7fb44d2016-08-03 17:02:15 -05002620
2621 ret = nl80211_dump_wiphy_parse(skb, cb, &state);
2622 if (ret)
Johannes Bergea90e0d2017-03-15 14:26:04 +01002623 goto out_unlock;
Denis Kenziorb7fb44d2016-08-03 17:02:15 -05002624
2625 filter_wiphy = state.filter_wiphy;
2626
2627 /*
2628 * if filtering, set cb->args[2] to +1 since 0 is the default
2629 * value needed to determine that parsing is necessary.
2630 */
2631 if (filter_wiphy >= 0)
2632 cb->args[2] = filter_wiphy + 1;
2633 else
2634 cb->args[2] = -1;
2635 } else if (cb->args[2] > 0) {
2636 filter_wiphy = cb->args[2] - 1;
2637 }
2638
Johannes Bergf5ea9122009-08-07 16:17:38 +02002639 list_for_each_entry(rdev, &cfg80211_rdev_list, list) {
2640 if (!net_eq(wiphy_net(&rdev->wiphy), sock_net(skb->sk)))
Johannes Berg463d0182009-07-14 00:33:35 +02002641 continue;
Johannes Bergbba95fe2008-07-29 13:22:51 +02002642 if (wp_idx < wp_start) {
2643 wp_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04002644 continue;
Johannes Bergbba95fe2008-07-29 13:22:51 +02002645 }
Denis Kenziorb7fb44d2016-08-03 17:02:15 -05002646
2647 if (filter_wiphy >= 0 && filter_wiphy != rdev->wiphy_idx)
2648 continue;
2649
Johannes Berg55682962007-09-20 13:09:35 -04002650 if_idx = 0;
2651
Johannes Berg53873f12016-05-03 16:52:04 +03002652 list_for_each_entry(wdev, &rdev->wiphy.wdev_list, list) {
Johannes Bergbba95fe2008-07-29 13:22:51 +02002653 if (if_idx < if_start) {
2654 if_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04002655 continue;
Johannes Bergbba95fe2008-07-29 13:22:51 +02002656 }
Eric W. Biederman15e47302012-09-07 20:12:54 +00002657 if (nl80211_send_iface(skb, NETLINK_CB(cb->skb).portid,
Johannes Berg55682962007-09-20 13:09:35 -04002658 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Tomasz Bursztyka8f894be2014-11-12 16:26:45 +02002659 rdev, wdev, false) < 0) {
Johannes Bergbba95fe2008-07-29 13:22:51 +02002660 goto out;
2661 }
2662 if_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04002663 }
Johannes Bergbba95fe2008-07-29 13:22:51 +02002664
2665 wp_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04002666 }
Johannes Bergbba95fe2008-07-29 13:22:51 +02002667 out:
Johannes Berg55682962007-09-20 13:09:35 -04002668 cb->args[0] = wp_idx;
2669 cb->args[1] = if_idx;
2670
Johannes Bergea90e0d2017-03-15 14:26:04 +01002671 ret = skb->len;
2672 out_unlock:
2673 rtnl_unlock();
2674
2675 return ret;
Johannes Berg55682962007-09-20 13:09:35 -04002676}
2677
2678static int nl80211_get_interface(struct sk_buff *skb, struct genl_info *info)
2679{
2680 struct sk_buff *msg;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002681 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002682 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg55682962007-09-20 13:09:35 -04002683
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07002684 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -04002685 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02002686 return -ENOMEM;
Johannes Berg55682962007-09-20 13:09:35 -04002687
Eric W. Biederman15e47302012-09-07 20:12:54 +00002688 if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0,
Tomasz Bursztyka8f894be2014-11-12 16:26:45 +02002689 rdev, wdev, false) < 0) {
Johannes Berg4c476992010-10-04 21:36:35 +02002690 nlmsg_free(msg);
2691 return -ENOBUFS;
2692 }
Johannes Berg55682962007-09-20 13:09:35 -04002693
Johannes Berg134e6372009-07-10 09:51:34 +00002694 return genlmsg_reply(msg, info);
Johannes Berg55682962007-09-20 13:09:35 -04002695}
2696
Michael Wu66f7ac52008-01-31 19:48:22 +01002697static const struct nla_policy mntr_flags_policy[NL80211_MNTR_FLAG_MAX + 1] = {
2698 [NL80211_MNTR_FLAG_FCSFAIL] = { .type = NLA_FLAG },
2699 [NL80211_MNTR_FLAG_PLCPFAIL] = { .type = NLA_FLAG },
2700 [NL80211_MNTR_FLAG_CONTROL] = { .type = NLA_FLAG },
2701 [NL80211_MNTR_FLAG_OTHER_BSS] = { .type = NLA_FLAG },
2702 [NL80211_MNTR_FLAG_COOK_FRAMES] = { .type = NLA_FLAG },
Felix Fietkaue057d3c2013-05-28 13:01:52 +02002703 [NL80211_MNTR_FLAG_ACTIVE] = { .type = NLA_FLAG },
Michael Wu66f7ac52008-01-31 19:48:22 +01002704};
2705
2706static int parse_monitor_flags(struct nlattr *nla, u32 *mntrflags)
2707{
2708 struct nlattr *flags[NL80211_MNTR_FLAG_MAX + 1];
2709 int flag;
2710
2711 *mntrflags = 0;
2712
2713 if (!nla)
2714 return -EINVAL;
2715
Johannes Bergfceb6432017-04-12 14:34:07 +02002716 if (nla_parse_nested(flags, NL80211_MNTR_FLAG_MAX, nla,
2717 mntr_flags_policy, NULL))
Michael Wu66f7ac52008-01-31 19:48:22 +01002718 return -EINVAL;
2719
2720 for (flag = 1; flag <= NL80211_MNTR_FLAG_MAX; flag++)
2721 if (flags[flag])
2722 *mntrflags |= (1<<flag);
2723
Johannes Berg818a9862017-04-12 11:23:28 +02002724 *mntrflags |= MONITOR_FLAG_CHANGED;
2725
Michael Wu66f7ac52008-01-31 19:48:22 +01002726 return 0;
2727}
2728
Johannes Berg1db77592017-04-12 11:36:31 +02002729static int nl80211_parse_mon_options(struct cfg80211_registered_device *rdev,
2730 enum nl80211_iftype type,
2731 struct genl_info *info,
2732 struct vif_params *params)
2733{
2734 bool change = false;
2735 int err;
2736
2737 if (info->attrs[NL80211_ATTR_MNTR_FLAGS]) {
2738 if (type != NL80211_IFTYPE_MONITOR)
2739 return -EINVAL;
2740
2741 err = parse_monitor_flags(info->attrs[NL80211_ATTR_MNTR_FLAGS],
2742 &params->flags);
2743 if (err)
2744 return err;
2745
2746 change = true;
2747 }
2748
2749 if (params->flags & MONITOR_FLAG_ACTIVE &&
2750 !(rdev->wiphy.features & NL80211_FEATURE_ACTIVE_MONITOR))
2751 return -EOPNOTSUPP;
2752
2753 if (info->attrs[NL80211_ATTR_MU_MIMO_GROUP_DATA]) {
2754 const u8 *mumimo_groups;
2755 u32 cap_flag = NL80211_EXT_FEATURE_MU_MIMO_AIR_SNIFFER;
2756
2757 if (type != NL80211_IFTYPE_MONITOR)
2758 return -EINVAL;
2759
2760 if (!wiphy_ext_feature_isset(&rdev->wiphy, cap_flag))
2761 return -EOPNOTSUPP;
2762
2763 mumimo_groups =
2764 nla_data(info->attrs[NL80211_ATTR_MU_MIMO_GROUP_DATA]);
2765
2766 /* bits 0 and 63 are reserved and must be zero */
Johannes Berg49546012017-04-27 09:13:38 +02002767 if ((mumimo_groups[0] & BIT(0)) ||
2768 (mumimo_groups[VHT_MUMIMO_GROUPS_DATA_LEN - 1] & BIT(7)))
Johannes Berg1db77592017-04-12 11:36:31 +02002769 return -EINVAL;
2770
2771 params->vht_mumimo_groups = mumimo_groups;
2772 change = true;
2773 }
2774
2775 if (info->attrs[NL80211_ATTR_MU_MIMO_FOLLOW_MAC_ADDR]) {
2776 u32 cap_flag = NL80211_EXT_FEATURE_MU_MIMO_AIR_SNIFFER;
2777
2778 if (type != NL80211_IFTYPE_MONITOR)
2779 return -EINVAL;
2780
2781 if (!wiphy_ext_feature_isset(&rdev->wiphy, cap_flag))
2782 return -EOPNOTSUPP;
2783
2784 params->vht_mumimo_follow_addr =
2785 nla_data(info->attrs[NL80211_ATTR_MU_MIMO_FOLLOW_MAC_ADDR]);
2786 change = true;
2787 }
2788
2789 return change ? 1 : 0;
2790}
2791
Johannes Berg9bc383d2009-11-19 11:55:19 +01002792static int nl80211_valid_4addr(struct cfg80211_registered_device *rdev,
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002793 struct net_device *netdev, u8 use_4addr,
2794 enum nl80211_iftype iftype)
Johannes Berg9bc383d2009-11-19 11:55:19 +01002795{
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002796 if (!use_4addr) {
Jiri Pirkof350a0a82010-06-15 06:50:45 +00002797 if (netdev && (netdev->priv_flags & IFF_BRIDGE_PORT))
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002798 return -EBUSY;
Johannes Berg9bc383d2009-11-19 11:55:19 +01002799 return 0;
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002800 }
Johannes Berg9bc383d2009-11-19 11:55:19 +01002801
2802 switch (iftype) {
2803 case NL80211_IFTYPE_AP_VLAN:
2804 if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_AP)
2805 return 0;
2806 break;
2807 case NL80211_IFTYPE_STATION:
2808 if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_STATION)
2809 return 0;
2810 break;
2811 default:
2812 break;
2813 }
2814
2815 return -EOPNOTSUPP;
2816}
2817
Johannes Berg55682962007-09-20 13:09:35 -04002818static int nl80211_set_interface(struct sk_buff *skb, struct genl_info *info)
2819{
Johannes Berg4c476992010-10-04 21:36:35 +02002820 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002821 struct vif_params params;
Johannes Berge36d56b2009-06-09 21:04:43 +02002822 int err;
Johannes Berg04a773a2009-04-19 21:24:32 +02002823 enum nl80211_iftype otype, ntype;
Johannes Berg4c476992010-10-04 21:36:35 +02002824 struct net_device *dev = info->user_ptr[1];
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002825 bool change = false;
Johannes Berg55682962007-09-20 13:09:35 -04002826
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002827 memset(&params, 0, sizeof(params));
2828
Johannes Berg04a773a2009-04-19 21:24:32 +02002829 otype = ntype = dev->ieee80211_ptr->iftype;
Johannes Berg55682962007-09-20 13:09:35 -04002830
Johannes Berg723b0382008-09-16 20:22:09 +02002831 if (info->attrs[NL80211_ATTR_IFTYPE]) {
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002832 ntype = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]);
Johannes Berg04a773a2009-04-19 21:24:32 +02002833 if (otype != ntype)
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002834 change = true;
Johannes Berg4c476992010-10-04 21:36:35 +02002835 if (ntype > NL80211_IFTYPE_MAX)
2836 return -EINVAL;
Johannes Berg723b0382008-09-16 20:22:09 +02002837 }
2838
Johannes Berg92ffe052008-09-16 20:39:36 +02002839 if (info->attrs[NL80211_ATTR_MESH_ID]) {
Johannes Berg29cbe682010-12-03 09:20:44 +01002840 struct wireless_dev *wdev = dev->ieee80211_ptr;
2841
Johannes Berg4c476992010-10-04 21:36:35 +02002842 if (ntype != NL80211_IFTYPE_MESH_POINT)
2843 return -EINVAL;
Johannes Berg29cbe682010-12-03 09:20:44 +01002844 if (netif_running(dev))
2845 return -EBUSY;
2846
2847 wdev_lock(wdev);
2848 BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN !=
2849 IEEE80211_MAX_MESH_ID_LEN);
2850 wdev->mesh_id_up_len =
2851 nla_len(info->attrs[NL80211_ATTR_MESH_ID]);
2852 memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]),
2853 wdev->mesh_id_up_len);
2854 wdev_unlock(wdev);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002855 }
2856
Felix Fietkau8b787642009-11-10 18:53:10 +01002857 if (info->attrs[NL80211_ATTR_4ADDR]) {
2858 params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]);
2859 change = true;
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002860 err = nl80211_valid_4addr(rdev, dev, params.use_4addr, ntype);
Johannes Berg9bc383d2009-11-19 11:55:19 +01002861 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02002862 return err;
Felix Fietkau8b787642009-11-10 18:53:10 +01002863 } else {
2864 params.use_4addr = -1;
2865 }
2866
Johannes Berg1db77592017-04-12 11:36:31 +02002867 err = nl80211_parse_mon_options(rdev, ntype, info, &params);
2868 if (err < 0)
2869 return err;
2870 if (err > 0)
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002871 change = true;
Felix Fietkaue057d3c2013-05-28 13:01:52 +02002872
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002873 if (change)
Johannes Berg818a9862017-04-12 11:23:28 +02002874 err = cfg80211_change_iface(rdev, dev, ntype, &params);
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002875 else
2876 err = 0;
Johannes Berg60719ff2008-09-16 14:55:09 +02002877
Johannes Berg9bc383d2009-11-19 11:55:19 +01002878 if (!err && params.use_4addr != -1)
2879 dev->ieee80211_ptr->use_4addr = params.use_4addr;
2880
Johannes Berg55682962007-09-20 13:09:35 -04002881 return err;
2882}
2883
2884static int nl80211_new_interface(struct sk_buff *skb, struct genl_info *info)
2885{
Johannes Berg4c476992010-10-04 21:36:35 +02002886 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002887 struct vif_params params;
Johannes Berg84efbb82012-06-16 00:00:26 +02002888 struct wireless_dev *wdev;
Denis Kenzior896ff062016-08-03 16:58:33 -05002889 struct sk_buff *msg;
Johannes Berg55682962007-09-20 13:09:35 -04002890 int err;
2891 enum nl80211_iftype type = NL80211_IFTYPE_UNSPECIFIED;
2892
Johannes Berg78f22b62014-03-24 17:57:27 +01002893 /* to avoid failing a new interface creation due to pending removal */
2894 cfg80211_destroy_ifaces(rdev);
2895
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002896 memset(&params, 0, sizeof(params));
2897
Johannes Berg55682962007-09-20 13:09:35 -04002898 if (!info->attrs[NL80211_ATTR_IFNAME])
2899 return -EINVAL;
2900
2901 if (info->attrs[NL80211_ATTR_IFTYPE]) {
2902 type = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]);
2903 if (type > NL80211_IFTYPE_MAX)
2904 return -EINVAL;
2905 }
2906
Johannes Berg79c97e92009-07-07 03:56:12 +02002907 if (!rdev->ops->add_virtual_intf ||
Johannes Berg4c476992010-10-04 21:36:35 +02002908 !(rdev->wiphy.interface_modes & (1 << type)))
2909 return -EOPNOTSUPP;
Johannes Berg55682962007-09-20 13:09:35 -04002910
Ayala Bekercb3b7d82016-09-20 17:31:13 +03002911 if ((type == NL80211_IFTYPE_P2P_DEVICE || type == NL80211_IFTYPE_NAN ||
Ben Greeare8f479b2014-10-22 12:23:05 -07002912 rdev->wiphy.features & NL80211_FEATURE_MAC_ON_CREATE) &&
2913 info->attrs[NL80211_ATTR_MAC]) {
Arend van Spriel1c18f142013-01-08 10:17:27 +01002914 nla_memcpy(params.macaddr, info->attrs[NL80211_ATTR_MAC],
2915 ETH_ALEN);
2916 if (!is_valid_ether_addr(params.macaddr))
2917 return -EADDRNOTAVAIL;
2918 }
2919
Johannes Berg9bc383d2009-11-19 11:55:19 +01002920 if (info->attrs[NL80211_ATTR_4ADDR]) {
Felix Fietkau8b787642009-11-10 18:53:10 +01002921 params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]);
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002922 err = nl80211_valid_4addr(rdev, NULL, params.use_4addr, type);
Johannes Berg9bc383d2009-11-19 11:55:19 +01002923 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02002924 return err;
Johannes Berg9bc383d2009-11-19 11:55:19 +01002925 }
Felix Fietkau8b787642009-11-10 18:53:10 +01002926
Johannes Berg1db77592017-04-12 11:36:31 +02002927 err = nl80211_parse_mon_options(rdev, type, info, &params);
2928 if (err < 0)
2929 return err;
Felix Fietkaue057d3c2013-05-28 13:01:52 +02002930
Johannes Berga18c7192015-02-24 10:56:42 +01002931 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
2932 if (!msg)
2933 return -ENOMEM;
2934
Hila Gonene35e4d22012-06-27 17:19:42 +03002935 wdev = rdev_add_virtual_intf(rdev,
2936 nla_data(info->attrs[NL80211_ATTR_IFNAME]),
Johannes Berg818a9862017-04-12 11:23:28 +02002937 NET_NAME_USER, type, &params);
Rafał Miłeckid687cbb2014-11-14 18:43:28 +01002938 if (WARN_ON(!wdev)) {
2939 nlmsg_free(msg);
2940 return -EPROTO;
2941 } else if (IS_ERR(wdev)) {
Johannes Berg1c90f9d2012-06-16 00:05:37 +02002942 nlmsg_free(msg);
Johannes Berg84efbb82012-06-16 00:00:26 +02002943 return PTR_ERR(wdev);
Johannes Berg1c90f9d2012-06-16 00:05:37 +02002944 }
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002945
Jukka Rissanen18e5ca62014-11-13 17:25:14 +02002946 if (info->attrs[NL80211_ATTR_SOCKET_OWNER])
Johannes Berg78f22b62014-03-24 17:57:27 +01002947 wdev->owner_nlportid = info->snd_portid;
2948
Johannes Berg98104fde2012-06-16 00:19:54 +02002949 switch (type) {
2950 case NL80211_IFTYPE_MESH_POINT:
2951 if (!info->attrs[NL80211_ATTR_MESH_ID])
2952 break;
Johannes Berg29cbe682010-12-03 09:20:44 +01002953 wdev_lock(wdev);
2954 BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN !=
2955 IEEE80211_MAX_MESH_ID_LEN);
2956 wdev->mesh_id_up_len =
2957 nla_len(info->attrs[NL80211_ATTR_MESH_ID]);
2958 memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]),
2959 wdev->mesh_id_up_len);
2960 wdev_unlock(wdev);
Johannes Berg98104fde2012-06-16 00:19:54 +02002961 break;
Ayala Bekercb3b7d82016-09-20 17:31:13 +03002962 case NL80211_IFTYPE_NAN:
Johannes Berg98104fde2012-06-16 00:19:54 +02002963 case NL80211_IFTYPE_P2P_DEVICE:
2964 /*
Ayala Bekercb3b7d82016-09-20 17:31:13 +03002965 * P2P Device and NAN do not have a netdev, so don't go
Johannes Berg98104fde2012-06-16 00:19:54 +02002966 * through the netdev notifier and must be added here
2967 */
2968 mutex_init(&wdev->mtx);
2969 INIT_LIST_HEAD(&wdev->event_list);
2970 spin_lock_init(&wdev->event_lock);
2971 INIT_LIST_HEAD(&wdev->mgmt_registrations);
2972 spin_lock_init(&wdev->mgmt_registrations_lock);
2973
Johannes Berg98104fde2012-06-16 00:19:54 +02002974 wdev->identifier = ++rdev->wdev_id;
Johannes Berg53873f12016-05-03 16:52:04 +03002975 list_add_rcu(&wdev->list, &rdev->wiphy.wdev_list);
Johannes Berg98104fde2012-06-16 00:19:54 +02002976 rdev->devlist_generation++;
Johannes Berg98104fde2012-06-16 00:19:54 +02002977 break;
2978 default:
2979 break;
Johannes Berg29cbe682010-12-03 09:20:44 +01002980 }
2981
Eric W. Biederman15e47302012-09-07 20:12:54 +00002982 if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0,
Tomasz Bursztyka8f894be2014-11-12 16:26:45 +02002983 rdev, wdev, false) < 0) {
Johannes Berg1c90f9d2012-06-16 00:05:37 +02002984 nlmsg_free(msg);
2985 return -ENOBUFS;
2986 }
2987
Denis Kenzior896ff062016-08-03 16:58:33 -05002988 /*
2989 * For wdevs which have no associated netdev object (e.g. of type
2990 * NL80211_IFTYPE_P2P_DEVICE), emit the NEW_INTERFACE event here.
2991 * For all other types, the event will be generated from the
2992 * netdev notifier
2993 */
2994 if (!wdev->netdev)
2995 nl80211_notify_iface(rdev, wdev, NL80211_CMD_NEW_INTERFACE);
Tomasz Bursztyka8f894be2014-11-12 16:26:45 +02002996
Johannes Berg1c90f9d2012-06-16 00:05:37 +02002997 return genlmsg_reply(msg, info);
Johannes Berg55682962007-09-20 13:09:35 -04002998}
2999
3000static int nl80211_del_interface(struct sk_buff *skb, struct genl_info *info)
3001{
Johannes Berg4c476992010-10-04 21:36:35 +02003002 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg84efbb82012-06-16 00:00:26 +02003003 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg55682962007-09-20 13:09:35 -04003004
Johannes Berg4c476992010-10-04 21:36:35 +02003005 if (!rdev->ops->del_virtual_intf)
3006 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01003007
Johannes Berg84efbb82012-06-16 00:00:26 +02003008 /*
3009 * If we remove a wireless device without a netdev then clear
3010 * user_ptr[1] so that nl80211_post_doit won't dereference it
3011 * to check if it needs to do dev_put(). Otherwise it crashes
3012 * since the wdev has been freed, unlike with a netdev where
3013 * we need the dev_put() for the netdev to really be freed.
3014 */
3015 if (!wdev->netdev)
3016 info->user_ptr[1] = NULL;
3017
Denis Kenzior7f8ed012016-08-03 16:58:35 -05003018 return rdev_del_virtual_intf(rdev, wdev);
Johannes Berg55682962007-09-20 13:09:35 -04003019}
3020
Simon Wunderlich1d9d9212011-11-18 14:20:43 +01003021static int nl80211_set_noack_map(struct sk_buff *skb, struct genl_info *info)
3022{
3023 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3024 struct net_device *dev = info->user_ptr[1];
3025 u16 noack_map;
3026
3027 if (!info->attrs[NL80211_ATTR_NOACK_MAP])
3028 return -EINVAL;
3029
3030 if (!rdev->ops->set_noack_map)
3031 return -EOPNOTSUPP;
3032
3033 noack_map = nla_get_u16(info->attrs[NL80211_ATTR_NOACK_MAP]);
3034
Hila Gonene35e4d22012-06-27 17:19:42 +03003035 return rdev_set_noack_map(rdev, dev, noack_map);
Simon Wunderlich1d9d9212011-11-18 14:20:43 +01003036}
3037
Johannes Berg41ade002007-12-19 02:03:29 +01003038struct get_key_cookie {
3039 struct sk_buff *msg;
3040 int error;
Johannes Bergb9454e82009-07-08 13:29:08 +02003041 int idx;
Johannes Berg41ade002007-12-19 02:03:29 +01003042};
3043
3044static void get_key_callback(void *c, struct key_params *params)
3045{
Johannes Bergb9454e82009-07-08 13:29:08 +02003046 struct nlattr *key;
Johannes Berg41ade002007-12-19 02:03:29 +01003047 struct get_key_cookie *cookie = c;
3048
David S. Miller9360ffd2012-03-29 04:41:26 -04003049 if ((params->key &&
3050 nla_put(cookie->msg, NL80211_ATTR_KEY_DATA,
3051 params->key_len, params->key)) ||
3052 (params->seq &&
3053 nla_put(cookie->msg, NL80211_ATTR_KEY_SEQ,
3054 params->seq_len, params->seq)) ||
3055 (params->cipher &&
3056 nla_put_u32(cookie->msg, NL80211_ATTR_KEY_CIPHER,
3057 params->cipher)))
3058 goto nla_put_failure;
Johannes Berg41ade002007-12-19 02:03:29 +01003059
Johannes Bergb9454e82009-07-08 13:29:08 +02003060 key = nla_nest_start(cookie->msg, NL80211_ATTR_KEY);
3061 if (!key)
3062 goto nla_put_failure;
3063
David S. Miller9360ffd2012-03-29 04:41:26 -04003064 if ((params->key &&
3065 nla_put(cookie->msg, NL80211_KEY_DATA,
3066 params->key_len, params->key)) ||
3067 (params->seq &&
3068 nla_put(cookie->msg, NL80211_KEY_SEQ,
3069 params->seq_len, params->seq)) ||
3070 (params->cipher &&
3071 nla_put_u32(cookie->msg, NL80211_KEY_CIPHER,
3072 params->cipher)))
3073 goto nla_put_failure;
Johannes Bergb9454e82009-07-08 13:29:08 +02003074
David S. Miller9360ffd2012-03-29 04:41:26 -04003075 if (nla_put_u8(cookie->msg, NL80211_ATTR_KEY_IDX, cookie->idx))
3076 goto nla_put_failure;
Johannes Bergb9454e82009-07-08 13:29:08 +02003077
3078 nla_nest_end(cookie->msg, key);
3079
Johannes Berg41ade002007-12-19 02:03:29 +01003080 return;
3081 nla_put_failure:
3082 cookie->error = 1;
3083}
3084
3085static int nl80211_get_key(struct sk_buff *skb, struct genl_info *info)
3086{
Johannes Berg4c476992010-10-04 21:36:35 +02003087 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg41ade002007-12-19 02:03:29 +01003088 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02003089 struct net_device *dev = info->user_ptr[1];
Johannes Berg41ade002007-12-19 02:03:29 +01003090 u8 key_idx = 0;
Johannes Berge31b8212010-10-05 19:39:30 +02003091 const u8 *mac_addr = NULL;
3092 bool pairwise;
Johannes Berg41ade002007-12-19 02:03:29 +01003093 struct get_key_cookie cookie = {
3094 .error = 0,
3095 };
3096 void *hdr;
3097 struct sk_buff *msg;
3098
3099 if (info->attrs[NL80211_ATTR_KEY_IDX])
3100 key_idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]);
3101
Jouni Malinen3cfcf6ac2009-01-08 13:32:02 +02003102 if (key_idx > 5)
Johannes Berg41ade002007-12-19 02:03:29 +01003103 return -EINVAL;
3104
3105 if (info->attrs[NL80211_ATTR_MAC])
3106 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
3107
Johannes Berge31b8212010-10-05 19:39:30 +02003108 pairwise = !!mac_addr;
3109 if (info->attrs[NL80211_ATTR_KEY_TYPE]) {
3110 u32 kt = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]);
Kirtika Ruchandani7a087e72016-05-29 19:51:23 -07003111
Johannes Berge31b8212010-10-05 19:39:30 +02003112 if (kt >= NUM_NL80211_KEYTYPES)
3113 return -EINVAL;
3114 if (kt != NL80211_KEYTYPE_GROUP &&
3115 kt != NL80211_KEYTYPE_PAIRWISE)
3116 return -EINVAL;
3117 pairwise = kt == NL80211_KEYTYPE_PAIRWISE;
3118 }
3119
Johannes Berg4c476992010-10-04 21:36:35 +02003120 if (!rdev->ops->get_key)
3121 return -EOPNOTSUPP;
Johannes Berg41ade002007-12-19 02:03:29 +01003122
Johannes Berg0fa7b392015-01-23 11:10:12 +01003123 if (!pairwise && mac_addr && !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN))
3124 return -ENOENT;
3125
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07003126 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02003127 if (!msg)
3128 return -ENOMEM;
Johannes Berg41ade002007-12-19 02:03:29 +01003129
Eric W. Biederman15e47302012-09-07 20:12:54 +00003130 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berg41ade002007-12-19 02:03:29 +01003131 NL80211_CMD_NEW_KEY);
Dan Carpentercb35fba2013-08-14 14:50:01 +03003132 if (!hdr)
Johannes Berg9fe271a2013-10-25 11:15:12 +02003133 goto nla_put_failure;
Johannes Berg41ade002007-12-19 02:03:29 +01003134
3135 cookie.msg = msg;
Johannes Bergb9454e82009-07-08 13:29:08 +02003136 cookie.idx = key_idx;
Johannes Berg41ade002007-12-19 02:03:29 +01003137
David S. Miller9360ffd2012-03-29 04:41:26 -04003138 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
3139 nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_idx))
3140 goto nla_put_failure;
3141 if (mac_addr &&
3142 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr))
3143 goto nla_put_failure;
Johannes Berg41ade002007-12-19 02:03:29 +01003144
Hila Gonene35e4d22012-06-27 17:19:42 +03003145 err = rdev_get_key(rdev, dev, key_idx, pairwise, mac_addr, &cookie,
3146 get_key_callback);
Johannes Berg41ade002007-12-19 02:03:29 +01003147
3148 if (err)
Niko Jokinen6c95e2a2009-07-15 11:00:53 +03003149 goto free_msg;
Johannes Berg41ade002007-12-19 02:03:29 +01003150
3151 if (cookie.error)
3152 goto nla_put_failure;
3153
3154 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02003155 return genlmsg_reply(msg, info);
Johannes Berg41ade002007-12-19 02:03:29 +01003156
3157 nla_put_failure:
3158 err = -ENOBUFS;
Niko Jokinen6c95e2a2009-07-15 11:00:53 +03003159 free_msg:
Johannes Berg41ade002007-12-19 02:03:29 +01003160 nlmsg_free(msg);
Johannes Berg41ade002007-12-19 02:03:29 +01003161 return err;
3162}
3163
3164static int nl80211_set_key(struct sk_buff *skb, struct genl_info *info)
3165{
Johannes Berg4c476992010-10-04 21:36:35 +02003166 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Bergb9454e82009-07-08 13:29:08 +02003167 struct key_parse key;
Johannes Berg41ade002007-12-19 02:03:29 +01003168 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02003169 struct net_device *dev = info->user_ptr[1];
Johannes Berg41ade002007-12-19 02:03:29 +01003170
Johannes Bergb9454e82009-07-08 13:29:08 +02003171 err = nl80211_parse_key(info, &key);
3172 if (err)
3173 return err;
3174
3175 if (key.idx < 0)
Johannes Berg41ade002007-12-19 02:03:29 +01003176 return -EINVAL;
3177
Johannes Bergb9454e82009-07-08 13:29:08 +02003178 /* only support setting default key */
3179 if (!key.def && !key.defmgmt)
Johannes Berg41ade002007-12-19 02:03:29 +01003180 return -EINVAL;
3181
Johannes Bergfffd0932009-07-08 14:22:54 +02003182 wdev_lock(dev->ieee80211_ptr);
Johannes Bergdbd2fd62010-12-09 19:58:59 +01003183
3184 if (key.def) {
3185 if (!rdev->ops->set_default_key) {
3186 err = -EOPNOTSUPP;
3187 goto out;
3188 }
3189
3190 err = nl80211_key_allowed(dev->ieee80211_ptr);
3191 if (err)
3192 goto out;
3193
Hila Gonene35e4d22012-06-27 17:19:42 +03003194 err = rdev_set_default_key(rdev, dev, key.idx,
Johannes Bergdbd2fd62010-12-09 19:58:59 +01003195 key.def_uni, key.def_multi);
3196
3197 if (err)
3198 goto out;
Johannes Bergfffd0932009-07-08 14:22:54 +02003199
Johannes Berg3d23e342009-09-29 23:27:28 +02003200#ifdef CONFIG_CFG80211_WEXT
Johannes Bergdbd2fd62010-12-09 19:58:59 +01003201 dev->ieee80211_ptr->wext.default_key = key.idx;
Johannes Berg08645122009-05-11 13:54:58 +02003202#endif
Johannes Bergdbd2fd62010-12-09 19:58:59 +01003203 } else {
3204 if (key.def_uni || !key.def_multi) {
3205 err = -EINVAL;
3206 goto out;
3207 }
3208
3209 if (!rdev->ops->set_default_mgmt_key) {
3210 err = -EOPNOTSUPP;
3211 goto out;
3212 }
3213
3214 err = nl80211_key_allowed(dev->ieee80211_ptr);
3215 if (err)
3216 goto out;
3217
Hila Gonene35e4d22012-06-27 17:19:42 +03003218 err = rdev_set_default_mgmt_key(rdev, dev, key.idx);
Johannes Bergdbd2fd62010-12-09 19:58:59 +01003219 if (err)
3220 goto out;
3221
3222#ifdef CONFIG_CFG80211_WEXT
3223 dev->ieee80211_ptr->wext.default_mgmt_key = key.idx;
3224#endif
3225 }
3226
3227 out:
Johannes Bergfffd0932009-07-08 14:22:54 +02003228 wdev_unlock(dev->ieee80211_ptr);
Johannes Berg41ade002007-12-19 02:03:29 +01003229
Johannes Berg41ade002007-12-19 02:03:29 +01003230 return err;
3231}
3232
3233static int nl80211_new_key(struct sk_buff *skb, struct genl_info *info)
3234{
Johannes Berg4c476992010-10-04 21:36:35 +02003235 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Bergfffd0932009-07-08 14:22:54 +02003236 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02003237 struct net_device *dev = info->user_ptr[1];
Johannes Bergb9454e82009-07-08 13:29:08 +02003238 struct key_parse key;
Johannes Berge31b8212010-10-05 19:39:30 +02003239 const u8 *mac_addr = NULL;
Johannes Berg41ade002007-12-19 02:03:29 +01003240
Johannes Bergb9454e82009-07-08 13:29:08 +02003241 err = nl80211_parse_key(info, &key);
3242 if (err)
3243 return err;
Johannes Berg41ade002007-12-19 02:03:29 +01003244
Johannes Bergb9454e82009-07-08 13:29:08 +02003245 if (!key.p.key)
Johannes Berg41ade002007-12-19 02:03:29 +01003246 return -EINVAL;
3247
Johannes Berg41ade002007-12-19 02:03:29 +01003248 if (info->attrs[NL80211_ATTR_MAC])
3249 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
3250
Johannes Berge31b8212010-10-05 19:39:30 +02003251 if (key.type == -1) {
3252 if (mac_addr)
3253 key.type = NL80211_KEYTYPE_PAIRWISE;
3254 else
3255 key.type = NL80211_KEYTYPE_GROUP;
3256 }
3257
3258 /* for now */
3259 if (key.type != NL80211_KEYTYPE_PAIRWISE &&
3260 key.type != NL80211_KEYTYPE_GROUP)
3261 return -EINVAL;
3262
Johannes Berg4c476992010-10-04 21:36:35 +02003263 if (!rdev->ops->add_key)
3264 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01003265
Johannes Berge31b8212010-10-05 19:39:30 +02003266 if (cfg80211_validate_key_settings(rdev, &key.p, key.idx,
3267 key.type == NL80211_KEYTYPE_PAIRWISE,
3268 mac_addr))
Johannes Berg4c476992010-10-04 21:36:35 +02003269 return -EINVAL;
Johannes Bergfffd0932009-07-08 14:22:54 +02003270
3271 wdev_lock(dev->ieee80211_ptr);
3272 err = nl80211_key_allowed(dev->ieee80211_ptr);
3273 if (!err)
Hila Gonene35e4d22012-06-27 17:19:42 +03003274 err = rdev_add_key(rdev, dev, key.idx,
3275 key.type == NL80211_KEYTYPE_PAIRWISE,
3276 mac_addr, &key.p);
Johannes Bergfffd0932009-07-08 14:22:54 +02003277 wdev_unlock(dev->ieee80211_ptr);
Johannes Berg41ade002007-12-19 02:03:29 +01003278
Johannes Berg41ade002007-12-19 02:03:29 +01003279 return err;
3280}
3281
3282static int nl80211_del_key(struct sk_buff *skb, struct genl_info *info)
3283{
Johannes Berg4c476992010-10-04 21:36:35 +02003284 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg41ade002007-12-19 02:03:29 +01003285 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02003286 struct net_device *dev = info->user_ptr[1];
Johannes Berg41ade002007-12-19 02:03:29 +01003287 u8 *mac_addr = NULL;
Johannes Bergb9454e82009-07-08 13:29:08 +02003288 struct key_parse key;
Johannes Berg41ade002007-12-19 02:03:29 +01003289
Johannes Bergb9454e82009-07-08 13:29:08 +02003290 err = nl80211_parse_key(info, &key);
3291 if (err)
3292 return err;
Johannes Berg41ade002007-12-19 02:03:29 +01003293
3294 if (info->attrs[NL80211_ATTR_MAC])
3295 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
3296
Johannes Berge31b8212010-10-05 19:39:30 +02003297 if (key.type == -1) {
3298 if (mac_addr)
3299 key.type = NL80211_KEYTYPE_PAIRWISE;
3300 else
3301 key.type = NL80211_KEYTYPE_GROUP;
3302 }
3303
3304 /* for now */
3305 if (key.type != NL80211_KEYTYPE_PAIRWISE &&
3306 key.type != NL80211_KEYTYPE_GROUP)
3307 return -EINVAL;
3308
Johannes Berg4c476992010-10-04 21:36:35 +02003309 if (!rdev->ops->del_key)
3310 return -EOPNOTSUPP;
Johannes Berg41ade002007-12-19 02:03:29 +01003311
Johannes Bergfffd0932009-07-08 14:22:54 +02003312 wdev_lock(dev->ieee80211_ptr);
3313 err = nl80211_key_allowed(dev->ieee80211_ptr);
Johannes Berge31b8212010-10-05 19:39:30 +02003314
Johannes Berg0fa7b392015-01-23 11:10:12 +01003315 if (key.type == NL80211_KEYTYPE_GROUP && mac_addr &&
Johannes Berge31b8212010-10-05 19:39:30 +02003316 !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN))
3317 err = -ENOENT;
3318
Johannes Bergfffd0932009-07-08 14:22:54 +02003319 if (!err)
Hila Gonene35e4d22012-06-27 17:19:42 +03003320 err = rdev_del_key(rdev, dev, key.idx,
3321 key.type == NL80211_KEYTYPE_PAIRWISE,
3322 mac_addr);
Johannes Berg41ade002007-12-19 02:03:29 +01003323
Johannes Berg3d23e342009-09-29 23:27:28 +02003324#ifdef CONFIG_CFG80211_WEXT
Johannes Berg08645122009-05-11 13:54:58 +02003325 if (!err) {
Johannes Bergb9454e82009-07-08 13:29:08 +02003326 if (key.idx == dev->ieee80211_ptr->wext.default_key)
Johannes Berg08645122009-05-11 13:54:58 +02003327 dev->ieee80211_ptr->wext.default_key = -1;
Johannes Bergb9454e82009-07-08 13:29:08 +02003328 else if (key.idx == dev->ieee80211_ptr->wext.default_mgmt_key)
Johannes Berg08645122009-05-11 13:54:58 +02003329 dev->ieee80211_ptr->wext.default_mgmt_key = -1;
3330 }
3331#endif
Johannes Bergfffd0932009-07-08 14:22:54 +02003332 wdev_unlock(dev->ieee80211_ptr);
Johannes Berg08645122009-05-11 13:54:58 +02003333
Johannes Berg41ade002007-12-19 02:03:29 +01003334 return err;
3335}
3336
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +05303337/* This function returns an error or the number of nested attributes */
3338static int validate_acl_mac_addrs(struct nlattr *nl_attr)
3339{
3340 struct nlattr *attr;
3341 int n_entries = 0, tmp;
3342
3343 nla_for_each_nested(attr, nl_attr, tmp) {
3344 if (nla_len(attr) != ETH_ALEN)
3345 return -EINVAL;
3346
3347 n_entries++;
3348 }
3349
3350 return n_entries;
3351}
3352
3353/*
3354 * This function parses ACL information and allocates memory for ACL data.
3355 * On successful return, the calling function is responsible to free the
3356 * ACL buffer returned by this function.
3357 */
3358static struct cfg80211_acl_data *parse_acl_data(struct wiphy *wiphy,
3359 struct genl_info *info)
3360{
3361 enum nl80211_acl_policy acl_policy;
3362 struct nlattr *attr;
3363 struct cfg80211_acl_data *acl;
3364 int i = 0, n_entries, tmp;
3365
3366 if (!wiphy->max_acl_mac_addrs)
3367 return ERR_PTR(-EOPNOTSUPP);
3368
3369 if (!info->attrs[NL80211_ATTR_ACL_POLICY])
3370 return ERR_PTR(-EINVAL);
3371
3372 acl_policy = nla_get_u32(info->attrs[NL80211_ATTR_ACL_POLICY]);
3373 if (acl_policy != NL80211_ACL_POLICY_ACCEPT_UNLESS_LISTED &&
3374 acl_policy != NL80211_ACL_POLICY_DENY_UNLESS_LISTED)
3375 return ERR_PTR(-EINVAL);
3376
3377 if (!info->attrs[NL80211_ATTR_MAC_ADDRS])
3378 return ERR_PTR(-EINVAL);
3379
3380 n_entries = validate_acl_mac_addrs(info->attrs[NL80211_ATTR_MAC_ADDRS]);
3381 if (n_entries < 0)
3382 return ERR_PTR(n_entries);
3383
3384 if (n_entries > wiphy->max_acl_mac_addrs)
3385 return ERR_PTR(-ENOTSUPP);
3386
3387 acl = kzalloc(sizeof(*acl) + (sizeof(struct mac_address) * n_entries),
3388 GFP_KERNEL);
3389 if (!acl)
3390 return ERR_PTR(-ENOMEM);
3391
3392 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_MAC_ADDRS], tmp) {
3393 memcpy(acl->mac_addrs[i].addr, nla_data(attr), ETH_ALEN);
3394 i++;
3395 }
3396
3397 acl->n_acl_entries = n_entries;
3398 acl->acl_policy = acl_policy;
3399
3400 return acl;
3401}
3402
3403static int nl80211_set_mac_acl(struct sk_buff *skb, struct genl_info *info)
3404{
3405 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3406 struct net_device *dev = info->user_ptr[1];
3407 struct cfg80211_acl_data *acl;
3408 int err;
3409
3410 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
3411 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
3412 return -EOPNOTSUPP;
3413
3414 if (!dev->ieee80211_ptr->beacon_interval)
3415 return -EINVAL;
3416
3417 acl = parse_acl_data(&rdev->wiphy, info);
3418 if (IS_ERR(acl))
3419 return PTR_ERR(acl);
3420
3421 err = rdev_set_mac_acl(rdev, dev, acl);
3422
3423 kfree(acl);
3424
3425 return err;
3426}
3427
Purushottam Kushwahaa7c7fbf2016-09-14 17:38:44 +05303428static u32 rateset_to_mask(struct ieee80211_supported_band *sband,
3429 u8 *rates, u8 rates_len)
3430{
3431 u8 i;
3432 u32 mask = 0;
3433
3434 for (i = 0; i < rates_len; i++) {
3435 int rate = (rates[i] & 0x7f) * 5;
3436 int ridx;
3437
3438 for (ridx = 0; ridx < sband->n_bitrates; ridx++) {
3439 struct ieee80211_rate *srate =
3440 &sband->bitrates[ridx];
3441 if (rate == srate->bitrate) {
3442 mask |= 1 << ridx;
3443 break;
3444 }
3445 }
3446 if (ridx == sband->n_bitrates)
3447 return 0; /* rate not found */
3448 }
3449
3450 return mask;
3451}
3452
3453static bool ht_rateset_to_mask(struct ieee80211_supported_band *sband,
3454 u8 *rates, u8 rates_len,
3455 u8 mcs[IEEE80211_HT_MCS_MASK_LEN])
3456{
3457 u8 i;
3458
3459 memset(mcs, 0, IEEE80211_HT_MCS_MASK_LEN);
3460
3461 for (i = 0; i < rates_len; i++) {
3462 int ridx, rbit;
3463
3464 ridx = rates[i] / 8;
3465 rbit = BIT(rates[i] % 8);
3466
3467 /* check validity */
3468 if ((ridx < 0) || (ridx >= IEEE80211_HT_MCS_MASK_LEN))
3469 return false;
3470
3471 /* check availability */
3472 if (sband->ht_cap.mcs.rx_mask[ridx] & rbit)
3473 mcs[ridx] |= rbit;
3474 else
3475 return false;
3476 }
3477
3478 return true;
3479}
3480
3481static u16 vht_mcs_map_to_mcs_mask(u8 vht_mcs_map)
3482{
3483 u16 mcs_mask = 0;
3484
3485 switch (vht_mcs_map) {
3486 case IEEE80211_VHT_MCS_NOT_SUPPORTED:
3487 break;
3488 case IEEE80211_VHT_MCS_SUPPORT_0_7:
3489 mcs_mask = 0x00FF;
3490 break;
3491 case IEEE80211_VHT_MCS_SUPPORT_0_8:
3492 mcs_mask = 0x01FF;
3493 break;
3494 case IEEE80211_VHT_MCS_SUPPORT_0_9:
3495 mcs_mask = 0x03FF;
3496 break;
3497 default:
3498 break;
3499 }
3500
3501 return mcs_mask;
3502}
3503
3504static void vht_build_mcs_mask(u16 vht_mcs_map,
3505 u16 vht_mcs_mask[NL80211_VHT_NSS_MAX])
3506{
3507 u8 nss;
3508
3509 for (nss = 0; nss < NL80211_VHT_NSS_MAX; nss++) {
3510 vht_mcs_mask[nss] = vht_mcs_map_to_mcs_mask(vht_mcs_map & 0x03);
3511 vht_mcs_map >>= 2;
3512 }
3513}
3514
3515static bool vht_set_mcs_mask(struct ieee80211_supported_band *sband,
3516 struct nl80211_txrate_vht *txrate,
3517 u16 mcs[NL80211_VHT_NSS_MAX])
3518{
3519 u16 tx_mcs_map = le16_to_cpu(sband->vht_cap.vht_mcs.tx_mcs_map);
3520 u16 tx_mcs_mask[NL80211_VHT_NSS_MAX] = {};
3521 u8 i;
3522
3523 if (!sband->vht_cap.vht_supported)
3524 return false;
3525
3526 memset(mcs, 0, sizeof(u16) * NL80211_VHT_NSS_MAX);
3527
3528 /* Build vht_mcs_mask from VHT capabilities */
3529 vht_build_mcs_mask(tx_mcs_map, tx_mcs_mask);
3530
3531 for (i = 0; i < NL80211_VHT_NSS_MAX; i++) {
3532 if ((tx_mcs_mask[i] & txrate->mcs[i]) == txrate->mcs[i])
3533 mcs[i] = txrate->mcs[i];
3534 else
3535 return false;
3536 }
3537
3538 return true;
3539}
3540
3541static const struct nla_policy nl80211_txattr_policy[NL80211_TXRATE_MAX + 1] = {
3542 [NL80211_TXRATE_LEGACY] = { .type = NLA_BINARY,
3543 .len = NL80211_MAX_SUPP_RATES },
3544 [NL80211_TXRATE_HT] = { .type = NLA_BINARY,
3545 .len = NL80211_MAX_SUPP_HT_RATES },
3546 [NL80211_TXRATE_VHT] = { .len = sizeof(struct nl80211_txrate_vht)},
3547 [NL80211_TXRATE_GI] = { .type = NLA_U8 },
3548};
3549
3550static int nl80211_parse_tx_bitrate_mask(struct genl_info *info,
3551 struct cfg80211_bitrate_mask *mask)
3552{
3553 struct nlattr *tb[NL80211_TXRATE_MAX + 1];
3554 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3555 int rem, i;
3556 struct nlattr *tx_rates;
3557 struct ieee80211_supported_band *sband;
3558 u16 vht_tx_mcs_map;
3559
3560 memset(mask, 0, sizeof(*mask));
3561 /* Default to all rates enabled */
3562 for (i = 0; i < NUM_NL80211_BANDS; i++) {
3563 sband = rdev->wiphy.bands[i];
3564
3565 if (!sband)
3566 continue;
3567
3568 mask->control[i].legacy = (1 << sband->n_bitrates) - 1;
3569 memcpy(mask->control[i].ht_mcs,
3570 sband->ht_cap.mcs.rx_mask,
3571 sizeof(mask->control[i].ht_mcs));
3572
3573 if (!sband->vht_cap.vht_supported)
3574 continue;
3575
3576 vht_tx_mcs_map = le16_to_cpu(sband->vht_cap.vht_mcs.tx_mcs_map);
3577 vht_build_mcs_mask(vht_tx_mcs_map, mask->control[i].vht_mcs);
3578 }
3579
3580 /* if no rates are given set it back to the defaults */
3581 if (!info->attrs[NL80211_ATTR_TX_RATES])
3582 goto out;
3583
3584 /* The nested attribute uses enum nl80211_band as the index. This maps
3585 * directly to the enum nl80211_band values used in cfg80211.
3586 */
3587 BUILD_BUG_ON(NL80211_MAX_SUPP_HT_RATES > IEEE80211_HT_MCS_MASK_LEN * 8);
3588 nla_for_each_nested(tx_rates, info->attrs[NL80211_ATTR_TX_RATES], rem) {
3589 enum nl80211_band band = nla_type(tx_rates);
3590 int err;
3591
3592 if (band < 0 || band >= NUM_NL80211_BANDS)
3593 return -EINVAL;
3594 sband = rdev->wiphy.bands[band];
3595 if (sband == NULL)
3596 return -EINVAL;
Johannes Bergbfe2c7b2016-10-26 14:42:21 +02003597 err = nla_parse_nested(tb, NL80211_TXRATE_MAX, tx_rates,
Johannes Bergfe521452017-04-12 14:34:08 +02003598 nl80211_txattr_policy, info->extack);
Purushottam Kushwahaa7c7fbf2016-09-14 17:38:44 +05303599 if (err)
3600 return err;
3601 if (tb[NL80211_TXRATE_LEGACY]) {
3602 mask->control[band].legacy = rateset_to_mask(
3603 sband,
3604 nla_data(tb[NL80211_TXRATE_LEGACY]),
3605 nla_len(tb[NL80211_TXRATE_LEGACY]));
3606 if ((mask->control[band].legacy == 0) &&
3607 nla_len(tb[NL80211_TXRATE_LEGACY]))
3608 return -EINVAL;
3609 }
3610 if (tb[NL80211_TXRATE_HT]) {
3611 if (!ht_rateset_to_mask(
3612 sband,
3613 nla_data(tb[NL80211_TXRATE_HT]),
3614 nla_len(tb[NL80211_TXRATE_HT]),
3615 mask->control[band].ht_mcs))
3616 return -EINVAL;
3617 }
3618 if (tb[NL80211_TXRATE_VHT]) {
3619 if (!vht_set_mcs_mask(
3620 sband,
3621 nla_data(tb[NL80211_TXRATE_VHT]),
3622 mask->control[band].vht_mcs))
3623 return -EINVAL;
3624 }
3625 if (tb[NL80211_TXRATE_GI]) {
3626 mask->control[band].gi =
3627 nla_get_u8(tb[NL80211_TXRATE_GI]);
3628 if (mask->control[band].gi > NL80211_TXRATE_FORCE_LGI)
3629 return -EINVAL;
3630 }
3631
3632 if (mask->control[band].legacy == 0) {
3633 /* don't allow empty legacy rates if HT or VHT
3634 * are not even supported.
3635 */
3636 if (!(rdev->wiphy.bands[band]->ht_cap.ht_supported ||
3637 rdev->wiphy.bands[band]->vht_cap.vht_supported))
3638 return -EINVAL;
3639
3640 for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++)
3641 if (mask->control[band].ht_mcs[i])
3642 goto out;
3643
3644 for (i = 0; i < NL80211_VHT_NSS_MAX; i++)
3645 if (mask->control[band].vht_mcs[i])
3646 goto out;
3647
3648 /* legacy and mcs rates may not be both empty */
3649 return -EINVAL;
3650 }
3651 }
3652
3653out:
3654 return 0;
3655}
3656
Johannes Berg8564e382016-09-19 09:44:44 +02003657static int validate_beacon_tx_rate(struct cfg80211_registered_device *rdev,
3658 enum nl80211_band band,
3659 struct cfg80211_bitrate_mask *beacon_rate)
Purushottam Kushwahaa7c7fbf2016-09-14 17:38:44 +05303660{
Johannes Berg8564e382016-09-19 09:44:44 +02003661 u32 count_ht, count_vht, i;
3662 u32 rate = beacon_rate->control[band].legacy;
Purushottam Kushwahaa7c7fbf2016-09-14 17:38:44 +05303663
3664 /* Allow only one rate */
3665 if (hweight32(rate) > 1)
3666 return -EINVAL;
3667
3668 count_ht = 0;
3669 for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++) {
Johannes Berg8564e382016-09-19 09:44:44 +02003670 if (hweight8(beacon_rate->control[band].ht_mcs[i]) > 1) {
Purushottam Kushwahaa7c7fbf2016-09-14 17:38:44 +05303671 return -EINVAL;
Johannes Berg8564e382016-09-19 09:44:44 +02003672 } else if (beacon_rate->control[band].ht_mcs[i]) {
Purushottam Kushwahaa7c7fbf2016-09-14 17:38:44 +05303673 count_ht++;
3674 if (count_ht > 1)
3675 return -EINVAL;
3676 }
3677 if (count_ht && rate)
3678 return -EINVAL;
3679 }
3680
3681 count_vht = 0;
3682 for (i = 0; i < NL80211_VHT_NSS_MAX; i++) {
Johannes Berg8564e382016-09-19 09:44:44 +02003683 if (hweight16(beacon_rate->control[band].vht_mcs[i]) > 1) {
Purushottam Kushwahaa7c7fbf2016-09-14 17:38:44 +05303684 return -EINVAL;
Johannes Berg8564e382016-09-19 09:44:44 +02003685 } else if (beacon_rate->control[band].vht_mcs[i]) {
Purushottam Kushwahaa7c7fbf2016-09-14 17:38:44 +05303686 count_vht++;
3687 if (count_vht > 1)
3688 return -EINVAL;
3689 }
3690 if (count_vht && rate)
3691 return -EINVAL;
3692 }
3693
3694 if ((count_ht && count_vht) || (!rate && !count_ht && !count_vht))
3695 return -EINVAL;
3696
Johannes Berg8564e382016-09-19 09:44:44 +02003697 if (rate &&
3698 !wiphy_ext_feature_isset(&rdev->wiphy,
3699 NL80211_EXT_FEATURE_BEACON_RATE_LEGACY))
3700 return -EINVAL;
3701 if (count_ht &&
3702 !wiphy_ext_feature_isset(&rdev->wiphy,
3703 NL80211_EXT_FEATURE_BEACON_RATE_HT))
3704 return -EINVAL;
3705 if (count_vht &&
3706 !wiphy_ext_feature_isset(&rdev->wiphy,
3707 NL80211_EXT_FEATURE_BEACON_RATE_VHT))
3708 return -EINVAL;
3709
Purushottam Kushwahaa7c7fbf2016-09-14 17:38:44 +05303710 return 0;
3711}
3712
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003713static int nl80211_parse_beacon(struct nlattr *attrs[],
Johannes Berg88600202012-02-13 15:17:18 +01003714 struct cfg80211_beacon_data *bcn)
Johannes Berged1b6cc2007-12-19 02:03:32 +01003715{
Johannes Berg88600202012-02-13 15:17:18 +01003716 bool haveinfo = false;
Johannes Berged1b6cc2007-12-19 02:03:32 +01003717
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003718 if (!is_valid_ie_attr(attrs[NL80211_ATTR_BEACON_TAIL]) ||
3719 !is_valid_ie_attr(attrs[NL80211_ATTR_IE]) ||
3720 !is_valid_ie_attr(attrs[NL80211_ATTR_IE_PROBE_RESP]) ||
3721 !is_valid_ie_attr(attrs[NL80211_ATTR_IE_ASSOC_RESP]))
Johannes Bergf4a11bb2009-03-27 12:40:28 +01003722 return -EINVAL;
3723
Johannes Berg88600202012-02-13 15:17:18 +01003724 memset(bcn, 0, sizeof(*bcn));
Johannes Berged1b6cc2007-12-19 02:03:32 +01003725
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003726 if (attrs[NL80211_ATTR_BEACON_HEAD]) {
3727 bcn->head = nla_data(attrs[NL80211_ATTR_BEACON_HEAD]);
3728 bcn->head_len = nla_len(attrs[NL80211_ATTR_BEACON_HEAD]);
Johannes Berg88600202012-02-13 15:17:18 +01003729 if (!bcn->head_len)
3730 return -EINVAL;
3731 haveinfo = true;
Johannes Berged1b6cc2007-12-19 02:03:32 +01003732 }
3733
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003734 if (attrs[NL80211_ATTR_BEACON_TAIL]) {
3735 bcn->tail = nla_data(attrs[NL80211_ATTR_BEACON_TAIL]);
3736 bcn->tail_len = nla_len(attrs[NL80211_ATTR_BEACON_TAIL]);
Johannes Berg88600202012-02-13 15:17:18 +01003737 haveinfo = true;
Johannes Berged1b6cc2007-12-19 02:03:32 +01003738 }
3739
Johannes Berg4c476992010-10-04 21:36:35 +02003740 if (!haveinfo)
3741 return -EINVAL;
Johannes Berged1b6cc2007-12-19 02:03:32 +01003742
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003743 if (attrs[NL80211_ATTR_IE]) {
3744 bcn->beacon_ies = nla_data(attrs[NL80211_ATTR_IE]);
3745 bcn->beacon_ies_len = nla_len(attrs[NL80211_ATTR_IE]);
Jouni Malinen9946ecf2011-08-10 23:55:56 +03003746 }
3747
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003748 if (attrs[NL80211_ATTR_IE_PROBE_RESP]) {
Johannes Berg88600202012-02-13 15:17:18 +01003749 bcn->proberesp_ies =
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003750 nla_data(attrs[NL80211_ATTR_IE_PROBE_RESP]);
Johannes Berg88600202012-02-13 15:17:18 +01003751 bcn->proberesp_ies_len =
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003752 nla_len(attrs[NL80211_ATTR_IE_PROBE_RESP]);
Jouni Malinen9946ecf2011-08-10 23:55:56 +03003753 }
3754
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003755 if (attrs[NL80211_ATTR_IE_ASSOC_RESP]) {
Johannes Berg88600202012-02-13 15:17:18 +01003756 bcn->assocresp_ies =
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003757 nla_data(attrs[NL80211_ATTR_IE_ASSOC_RESP]);
Johannes Berg88600202012-02-13 15:17:18 +01003758 bcn->assocresp_ies_len =
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003759 nla_len(attrs[NL80211_ATTR_IE_ASSOC_RESP]);
Jouni Malinen9946ecf2011-08-10 23:55:56 +03003760 }
3761
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003762 if (attrs[NL80211_ATTR_PROBE_RESP]) {
3763 bcn->probe_resp = nla_data(attrs[NL80211_ATTR_PROBE_RESP]);
3764 bcn->probe_resp_len = nla_len(attrs[NL80211_ATTR_PROBE_RESP]);
Arik Nemtsov00f740e2011-11-10 11:28:56 +02003765 }
3766
Johannes Berg88600202012-02-13 15:17:18 +01003767 return 0;
3768}
3769
Johannes Berg66cd7942017-02-07 22:40:44 +02003770static void nl80211_check_ap_rate_selectors(struct cfg80211_ap_settings *params,
3771 const u8 *rates)
3772{
3773 int i;
3774
3775 if (!rates)
3776 return;
3777
3778 for (i = 0; i < rates[1]; i++) {
3779 if (rates[2 + i] == BSS_MEMBERSHIP_SELECTOR_HT_PHY)
3780 params->ht_required = true;
3781 if (rates[2 + i] == BSS_MEMBERSHIP_SELECTOR_VHT_PHY)
3782 params->vht_required = true;
3783 }
3784}
3785
3786/*
3787 * Since the nl80211 API didn't include, from the beginning, attributes about
3788 * HT/VHT requirements/capabilities, we parse them out of the IEs for the
3789 * benefit of drivers that rebuild IEs in the firmware.
3790 */
3791static void nl80211_calculate_ap_params(struct cfg80211_ap_settings *params)
3792{
3793 const struct cfg80211_beacon_data *bcn = &params->beacon;
3794 size_t ies_len = bcn->beacon_ies_len;
3795 const u8 *ies = bcn->beacon_ies;
3796 const u8 *rates;
3797 const u8 *cap;
3798
3799 rates = cfg80211_find_ie(WLAN_EID_SUPP_RATES, ies, ies_len);
3800 nl80211_check_ap_rate_selectors(params, rates);
3801
3802 rates = cfg80211_find_ie(WLAN_EID_EXT_SUPP_RATES, ies, ies_len);
3803 nl80211_check_ap_rate_selectors(params, rates);
3804
3805 cap = cfg80211_find_ie(WLAN_EID_HT_CAPABILITY, ies, ies_len);
3806 if (cap && cap[1] >= sizeof(*params->ht_cap))
3807 params->ht_cap = (void *)(cap + 2);
3808 cap = cfg80211_find_ie(WLAN_EID_VHT_CAPABILITY, ies, ies_len);
3809 if (cap && cap[1] >= sizeof(*params->vht_cap))
3810 params->vht_cap = (void *)(cap + 2);
3811}
3812
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003813static bool nl80211_get_ap_channel(struct cfg80211_registered_device *rdev,
3814 struct cfg80211_ap_settings *params)
3815{
3816 struct wireless_dev *wdev;
3817 bool ret = false;
3818
Johannes Berg53873f12016-05-03 16:52:04 +03003819 list_for_each_entry(wdev, &rdev->wiphy.wdev_list, list) {
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003820 if (wdev->iftype != NL80211_IFTYPE_AP &&
3821 wdev->iftype != NL80211_IFTYPE_P2P_GO)
3822 continue;
3823
Johannes Berg683b6d32012-11-08 21:25:48 +01003824 if (!wdev->preset_chandef.chan)
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003825 continue;
3826
Johannes Berg683b6d32012-11-08 21:25:48 +01003827 params->chandef = wdev->preset_chandef;
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003828 ret = true;
3829 break;
3830 }
3831
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003832 return ret;
3833}
3834
Jouni Malinene39e5b52012-09-30 19:29:39 +03003835static bool nl80211_valid_auth_type(struct cfg80211_registered_device *rdev,
3836 enum nl80211_auth_type auth_type,
3837 enum nl80211_commands cmd)
3838{
3839 if (auth_type > NL80211_AUTHTYPE_MAX)
3840 return false;
3841
3842 switch (cmd) {
3843 case NL80211_CMD_AUTHENTICATE:
3844 if (!(rdev->wiphy.features & NL80211_FEATURE_SAE) &&
3845 auth_type == NL80211_AUTHTYPE_SAE)
3846 return false;
Jouni Malinen63181062016-10-27 00:42:02 +03003847 if (!wiphy_ext_feature_isset(&rdev->wiphy,
3848 NL80211_EXT_FEATURE_FILS_STA) &&
3849 (auth_type == NL80211_AUTHTYPE_FILS_SK ||
3850 auth_type == NL80211_AUTHTYPE_FILS_SK_PFS ||
3851 auth_type == NL80211_AUTHTYPE_FILS_PK))
3852 return false;
Jouni Malinene39e5b52012-09-30 19:29:39 +03003853 return true;
3854 case NL80211_CMD_CONNECT:
Vidyullatha Kanchanapallya3caf742017-03-31 00:22:34 +03003855 /* SAE not supported yet */
3856 if (auth_type == NL80211_AUTHTYPE_SAE)
3857 return false;
3858 /* FILS with SK PFS or PK not supported yet */
3859 if (auth_type == NL80211_AUTHTYPE_FILS_SK_PFS ||
3860 auth_type == NL80211_AUTHTYPE_FILS_PK)
3861 return false;
3862 if (!wiphy_ext_feature_isset(
3863 &rdev->wiphy,
3864 NL80211_EXT_FEATURE_FILS_SK_OFFLOAD) &&
3865 auth_type == NL80211_AUTHTYPE_FILS_SK)
3866 return false;
3867 return true;
Jouni Malinene39e5b52012-09-30 19:29:39 +03003868 case NL80211_CMD_START_AP:
3869 /* SAE not supported yet */
3870 if (auth_type == NL80211_AUTHTYPE_SAE)
3871 return false;
Jouni Malinen63181062016-10-27 00:42:02 +03003872 /* FILS not supported yet */
3873 if (auth_type == NL80211_AUTHTYPE_FILS_SK ||
3874 auth_type == NL80211_AUTHTYPE_FILS_SK_PFS ||
3875 auth_type == NL80211_AUTHTYPE_FILS_PK)
3876 return false;
Jouni Malinene39e5b52012-09-30 19:29:39 +03003877 return true;
3878 default:
3879 return false;
3880 }
3881}
3882
Johannes Berg88600202012-02-13 15:17:18 +01003883static int nl80211_start_ap(struct sk_buff *skb, struct genl_info *info)
3884{
3885 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3886 struct net_device *dev = info->user_ptr[1];
3887 struct wireless_dev *wdev = dev->ieee80211_ptr;
3888 struct cfg80211_ap_settings params;
3889 int err;
3890
3891 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
3892 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
3893 return -EOPNOTSUPP;
3894
3895 if (!rdev->ops->start_ap)
3896 return -EOPNOTSUPP;
3897
3898 if (wdev->beacon_interval)
3899 return -EALREADY;
3900
3901 memset(&params, 0, sizeof(params));
3902
3903 /* these are required for START_AP */
3904 if (!info->attrs[NL80211_ATTR_BEACON_INTERVAL] ||
3905 !info->attrs[NL80211_ATTR_DTIM_PERIOD] ||
3906 !info->attrs[NL80211_ATTR_BEACON_HEAD])
3907 return -EINVAL;
3908
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003909 err = nl80211_parse_beacon(info->attrs, &params.beacon);
Johannes Berg88600202012-02-13 15:17:18 +01003910 if (err)
3911 return err;
3912
3913 params.beacon_interval =
3914 nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]);
3915 params.dtim_period =
3916 nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]);
3917
Purushottam Kushwaha0c317a02016-10-12 18:26:51 +05303918 err = cfg80211_validate_beacon_int(rdev, dev->ieee80211_ptr->iftype,
3919 params.beacon_interval);
Johannes Berg88600202012-02-13 15:17:18 +01003920 if (err)
3921 return err;
3922
3923 /*
3924 * In theory, some of these attributes should be required here
3925 * but since they were not used when the command was originally
3926 * added, keep them optional for old user space programs to let
3927 * them continue to work with drivers that do not need the
3928 * additional information -- drivers must check!
3929 */
3930 if (info->attrs[NL80211_ATTR_SSID]) {
3931 params.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
3932 params.ssid_len =
3933 nla_len(info->attrs[NL80211_ATTR_SSID]);
3934 if (params.ssid_len == 0 ||
3935 params.ssid_len > IEEE80211_MAX_SSID_LEN)
3936 return -EINVAL;
3937 }
3938
3939 if (info->attrs[NL80211_ATTR_HIDDEN_SSID]) {
3940 params.hidden_ssid = nla_get_u32(
3941 info->attrs[NL80211_ATTR_HIDDEN_SSID]);
3942 if (params.hidden_ssid != NL80211_HIDDEN_SSID_NOT_IN_USE &&
3943 params.hidden_ssid != NL80211_HIDDEN_SSID_ZERO_LEN &&
3944 params.hidden_ssid != NL80211_HIDDEN_SSID_ZERO_CONTENTS)
3945 return -EINVAL;
3946 }
3947
3948 params.privacy = !!info->attrs[NL80211_ATTR_PRIVACY];
3949
3950 if (info->attrs[NL80211_ATTR_AUTH_TYPE]) {
3951 params.auth_type = nla_get_u32(
3952 info->attrs[NL80211_ATTR_AUTH_TYPE]);
Jouni Malinene39e5b52012-09-30 19:29:39 +03003953 if (!nl80211_valid_auth_type(rdev, params.auth_type,
3954 NL80211_CMD_START_AP))
Johannes Berg88600202012-02-13 15:17:18 +01003955 return -EINVAL;
3956 } else
3957 params.auth_type = NL80211_AUTHTYPE_AUTOMATIC;
3958
3959 err = nl80211_crypto_settings(rdev, info, &params.crypto,
3960 NL80211_MAX_NR_CIPHER_SUITES);
3961 if (err)
3962 return err;
3963
Vasanthakumar Thiagarajan1b658f12012-03-02 15:50:02 +05303964 if (info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]) {
3965 if (!(rdev->wiphy.features & NL80211_FEATURE_INACTIVITY_TIMER))
3966 return -EOPNOTSUPP;
3967 params.inactivity_timeout = nla_get_u16(
3968 info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]);
3969 }
3970
Johannes Berg53cabad2012-11-14 15:17:28 +01003971 if (info->attrs[NL80211_ATTR_P2P_CTWINDOW]) {
3972 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
3973 return -EINVAL;
3974 params.p2p_ctwindow =
3975 nla_get_u8(info->attrs[NL80211_ATTR_P2P_CTWINDOW]);
3976 if (params.p2p_ctwindow > 127)
3977 return -EINVAL;
3978 if (params.p2p_ctwindow != 0 &&
3979 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_CTWIN))
3980 return -EINVAL;
3981 }
3982
3983 if (info->attrs[NL80211_ATTR_P2P_OPPPS]) {
3984 u8 tmp;
3985
3986 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
3987 return -EINVAL;
3988 tmp = nla_get_u8(info->attrs[NL80211_ATTR_P2P_OPPPS]);
3989 if (tmp > 1)
3990 return -EINVAL;
3991 params.p2p_opp_ps = tmp;
3992 if (params.p2p_opp_ps != 0 &&
3993 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_OPPPS))
3994 return -EINVAL;
3995 }
3996
Johannes Bergaa430da2012-05-16 23:50:18 +02003997 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
Johannes Berg683b6d32012-11-08 21:25:48 +01003998 err = nl80211_parse_chandef(rdev, info, &params.chandef);
3999 if (err)
4000 return err;
4001 } else if (wdev->preset_chandef.chan) {
4002 params.chandef = wdev->preset_chandef;
Felix Fietkau46c1dd02012-06-19 02:50:57 +02004003 } else if (!nl80211_get_ap_channel(rdev, &params))
Johannes Bergaa430da2012-05-16 23:50:18 +02004004 return -EINVAL;
4005
Arik Nemtsov923b3522015-07-08 15:41:44 +03004006 if (!cfg80211_reg_can_beacon_relax(&rdev->wiphy, &params.chandef,
4007 wdev->iftype))
Johannes Bergaa430da2012-05-16 23:50:18 +02004008 return -EINVAL;
4009
Purushottam Kushwahaa7c7fbf2016-09-14 17:38:44 +05304010 if (info->attrs[NL80211_ATTR_TX_RATES]) {
4011 err = nl80211_parse_tx_bitrate_mask(info, &params.beacon_rate);
4012 if (err)
4013 return err;
4014
Johannes Berg8564e382016-09-19 09:44:44 +02004015 err = validate_beacon_tx_rate(rdev, params.chandef.chan->band,
4016 &params.beacon_rate);
Purushottam Kushwahaa7c7fbf2016-09-14 17:38:44 +05304017 if (err)
4018 return err;
4019 }
4020
Eliad Peller18998c32014-09-10 14:07:34 +03004021 if (info->attrs[NL80211_ATTR_SMPS_MODE]) {
4022 params.smps_mode =
4023 nla_get_u8(info->attrs[NL80211_ATTR_SMPS_MODE]);
4024 switch (params.smps_mode) {
4025 case NL80211_SMPS_OFF:
4026 break;
4027 case NL80211_SMPS_STATIC:
4028 if (!(rdev->wiphy.features &
4029 NL80211_FEATURE_STATIC_SMPS))
4030 return -EINVAL;
4031 break;
4032 case NL80211_SMPS_DYNAMIC:
4033 if (!(rdev->wiphy.features &
4034 NL80211_FEATURE_DYNAMIC_SMPS))
4035 return -EINVAL;
4036 break;
4037 default:
4038 return -EINVAL;
4039 }
4040 } else {
4041 params.smps_mode = NL80211_SMPS_OFF;
4042 }
4043
Purushottam Kushwaha6e8ef842016-07-05 13:44:51 +05304044 params.pbss = nla_get_flag(info->attrs[NL80211_ATTR_PBSS]);
4045 if (params.pbss && !rdev->wiphy.bands[NL80211_BAND_60GHZ])
4046 return -EOPNOTSUPP;
4047
Ola Olsson4baf6be2015-10-29 07:04:58 +01004048 if (info->attrs[NL80211_ATTR_ACL_POLICY]) {
4049 params.acl = parse_acl_data(&rdev->wiphy, info);
4050 if (IS_ERR(params.acl))
4051 return PTR_ERR(params.acl);
4052 }
4053
Johannes Berg66cd7942017-02-07 22:40:44 +02004054 nl80211_calculate_ap_params(&params);
4055
Simon Wunderlichc56589e2013-11-21 18:19:49 +01004056 wdev_lock(wdev);
Hila Gonene35e4d22012-06-27 17:19:42 +03004057 err = rdev_start_ap(rdev, dev, &params);
Felix Fietkau46c1dd02012-06-19 02:50:57 +02004058 if (!err) {
Johannes Berg683b6d32012-11-08 21:25:48 +01004059 wdev->preset_chandef = params.chandef;
Johannes Berg88600202012-02-13 15:17:18 +01004060 wdev->beacon_interval = params.beacon_interval;
Michal Kazior9e0e2962014-01-29 14:22:27 +01004061 wdev->chandef = params.chandef;
Antonio Quartulli06e191e2012-11-07 12:52:19 +01004062 wdev->ssid_len = params.ssid_len;
4063 memcpy(wdev->ssid, params.ssid, wdev->ssid_len);
Felix Fietkau46c1dd02012-06-19 02:50:57 +02004064 }
Simon Wunderlichc56589e2013-11-21 18:19:49 +01004065 wdev_unlock(wdev);
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +05304066
4067 kfree(params.acl);
4068
Johannes Berg56d18932011-05-09 18:41:15 +02004069 return err;
Johannes Berged1b6cc2007-12-19 02:03:32 +01004070}
4071
Johannes Berg88600202012-02-13 15:17:18 +01004072static int nl80211_set_beacon(struct sk_buff *skb, struct genl_info *info)
4073{
4074 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4075 struct net_device *dev = info->user_ptr[1];
4076 struct wireless_dev *wdev = dev->ieee80211_ptr;
4077 struct cfg80211_beacon_data params;
4078 int err;
4079
4080 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
4081 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
4082 return -EOPNOTSUPP;
4083
4084 if (!rdev->ops->change_beacon)
4085 return -EOPNOTSUPP;
4086
4087 if (!wdev->beacon_interval)
4088 return -EINVAL;
4089
Simon Wunderlicha1193be2013-06-14 14:15:19 +02004090 err = nl80211_parse_beacon(info->attrs, &params);
Johannes Berg88600202012-02-13 15:17:18 +01004091 if (err)
4092 return err;
4093
Simon Wunderlichc56589e2013-11-21 18:19:49 +01004094 wdev_lock(wdev);
4095 err = rdev_change_beacon(rdev, dev, &params);
4096 wdev_unlock(wdev);
4097
4098 return err;
Johannes Berg88600202012-02-13 15:17:18 +01004099}
4100
4101static int nl80211_stop_ap(struct sk_buff *skb, struct genl_info *info)
Johannes Berged1b6cc2007-12-19 02:03:32 +01004102{
Johannes Berg4c476992010-10-04 21:36:35 +02004103 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4104 struct net_device *dev = info->user_ptr[1];
Johannes Berged1b6cc2007-12-19 02:03:32 +01004105
Ilan Peer7c8d5e02014-02-25 15:33:38 +02004106 return cfg80211_stop_ap(rdev, dev, false);
Johannes Berged1b6cc2007-12-19 02:03:32 +01004107}
4108
Johannes Berg5727ef12007-12-19 02:03:34 +01004109static const struct nla_policy sta_flags_policy[NL80211_STA_FLAG_MAX + 1] = {
4110 [NL80211_STA_FLAG_AUTHORIZED] = { .type = NLA_FLAG },
4111 [NL80211_STA_FLAG_SHORT_PREAMBLE] = { .type = NLA_FLAG },
4112 [NL80211_STA_FLAG_WME] = { .type = NLA_FLAG },
Jouni Malinen0e467242009-05-11 21:57:55 +03004113 [NL80211_STA_FLAG_MFP] = { .type = NLA_FLAG },
Javier Cardonab39c48f2011-04-07 15:08:30 -07004114 [NL80211_STA_FLAG_AUTHENTICATED] = { .type = NLA_FLAG },
Johannes Bergd83023d2011-12-14 09:29:15 +01004115 [NL80211_STA_FLAG_TDLS_PEER] = { .type = NLA_FLAG },
Johannes Berg5727ef12007-12-19 02:03:34 +01004116};
4117
Johannes Bergeccb8e82009-05-11 21:57:56 +03004118static int parse_station_flags(struct genl_info *info,
Johannes Bergbdd3ae32012-01-02 13:30:03 +01004119 enum nl80211_iftype iftype,
Johannes Bergeccb8e82009-05-11 21:57:56 +03004120 struct station_parameters *params)
Johannes Berg5727ef12007-12-19 02:03:34 +01004121{
4122 struct nlattr *flags[NL80211_STA_FLAG_MAX + 1];
Johannes Bergeccb8e82009-05-11 21:57:56 +03004123 struct nlattr *nla;
Johannes Berg5727ef12007-12-19 02:03:34 +01004124 int flag;
4125
Johannes Bergeccb8e82009-05-11 21:57:56 +03004126 /*
4127 * Try parsing the new attribute first so userspace
4128 * can specify both for older kernels.
4129 */
4130 nla = info->attrs[NL80211_ATTR_STA_FLAGS2];
4131 if (nla) {
4132 struct nl80211_sta_flag_update *sta_flags;
Johannes Berg5727ef12007-12-19 02:03:34 +01004133
Johannes Bergeccb8e82009-05-11 21:57:56 +03004134 sta_flags = nla_data(nla);
4135 params->sta_flags_mask = sta_flags->mask;
4136 params->sta_flags_set = sta_flags->set;
Johannes Berg77ee7c82013-02-15 00:48:33 +01004137 params->sta_flags_set &= params->sta_flags_mask;
Johannes Bergeccb8e82009-05-11 21:57:56 +03004138 if ((params->sta_flags_mask |
4139 params->sta_flags_set) & BIT(__NL80211_STA_FLAG_INVALID))
4140 return -EINVAL;
4141 return 0;
4142 }
4143
4144 /* if present, parse the old attribute */
4145
4146 nla = info->attrs[NL80211_ATTR_STA_FLAGS];
Johannes Berg5727ef12007-12-19 02:03:34 +01004147 if (!nla)
4148 return 0;
4149
Johannes Bergfceb6432017-04-12 14:34:07 +02004150 if (nla_parse_nested(flags, NL80211_STA_FLAG_MAX, nla,
Johannes Bergfe521452017-04-12 14:34:08 +02004151 sta_flags_policy, info->extack))
Johannes Berg5727ef12007-12-19 02:03:34 +01004152 return -EINVAL;
4153
Johannes Bergbdd3ae32012-01-02 13:30:03 +01004154 /*
4155 * Only allow certain flags for interface types so that
4156 * other attributes are silently ignored. Remember that
4157 * this is backward compatibility code with old userspace
4158 * and shouldn't be hit in other cases anyway.
4159 */
4160 switch (iftype) {
4161 case NL80211_IFTYPE_AP:
4162 case NL80211_IFTYPE_AP_VLAN:
4163 case NL80211_IFTYPE_P2P_GO:
4164 params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) |
4165 BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) |
4166 BIT(NL80211_STA_FLAG_WME) |
4167 BIT(NL80211_STA_FLAG_MFP);
4168 break;
4169 case NL80211_IFTYPE_P2P_CLIENT:
4170 case NL80211_IFTYPE_STATION:
4171 params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) |
4172 BIT(NL80211_STA_FLAG_TDLS_PEER);
4173 break;
4174 case NL80211_IFTYPE_MESH_POINT:
4175 params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHENTICATED) |
4176 BIT(NL80211_STA_FLAG_MFP) |
4177 BIT(NL80211_STA_FLAG_AUTHORIZED);
4178 default:
4179 return -EINVAL;
4180 }
Johannes Berg5727ef12007-12-19 02:03:34 +01004181
Johannes Berg3383b5a2012-05-10 20:14:43 +02004182 for (flag = 1; flag <= NL80211_STA_FLAG_MAX; flag++) {
4183 if (flags[flag]) {
Johannes Bergeccb8e82009-05-11 21:57:56 +03004184 params->sta_flags_set |= (1<<flag);
Johannes Berg5727ef12007-12-19 02:03:34 +01004185
Johannes Berg3383b5a2012-05-10 20:14:43 +02004186 /* no longer support new API additions in old API */
4187 if (flag > NL80211_STA_FLAG_MAX_OLD_API)
4188 return -EINVAL;
4189 }
4190 }
4191
Johannes Berg5727ef12007-12-19 02:03:34 +01004192 return 0;
4193}
4194
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01004195static bool nl80211_put_sta_rate(struct sk_buff *msg, struct rate_info *info,
4196 int attr)
4197{
4198 struct nlattr *rate;
Vladimir Kondratiev8eb41c82012-07-05 14:25:49 +03004199 u32 bitrate;
4200 u16 bitrate_compat;
Matthias Kaehlckebbf67e42017-04-17 15:59:52 -07004201 enum nl80211_rate_info rate_flg;
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01004202
4203 rate = nla_nest_start(msg, attr);
4204 if (!rate)
Johannes Bergdb9c64c2012-11-09 14:56:41 +01004205 return false;
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01004206
4207 /* cfg80211_calculate_bitrate will return 0 for mcs >= 32 */
4208 bitrate = cfg80211_calculate_bitrate(info);
Vladimir Kondratiev8eb41c82012-07-05 14:25:49 +03004209 /* report 16-bit bitrate only if we can */
4210 bitrate_compat = bitrate < (1UL << 16) ? bitrate : 0;
Johannes Bergdb9c64c2012-11-09 14:56:41 +01004211 if (bitrate > 0 &&
4212 nla_put_u32(msg, NL80211_RATE_INFO_BITRATE32, bitrate))
4213 return false;
4214 if (bitrate_compat > 0 &&
4215 nla_put_u16(msg, NL80211_RATE_INFO_BITRATE, bitrate_compat))
4216 return false;
4217
Johannes Bergb51f3be2015-01-15 16:14:02 +01004218 switch (info->bw) {
4219 case RATE_INFO_BW_5:
4220 rate_flg = NL80211_RATE_INFO_5_MHZ_WIDTH;
4221 break;
4222 case RATE_INFO_BW_10:
4223 rate_flg = NL80211_RATE_INFO_10_MHZ_WIDTH;
4224 break;
4225 default:
4226 WARN_ON(1);
4227 /* fall through */
4228 case RATE_INFO_BW_20:
4229 rate_flg = 0;
4230 break;
4231 case RATE_INFO_BW_40:
4232 rate_flg = NL80211_RATE_INFO_40_MHZ_WIDTH;
4233 break;
4234 case RATE_INFO_BW_80:
4235 rate_flg = NL80211_RATE_INFO_80_MHZ_WIDTH;
4236 break;
4237 case RATE_INFO_BW_160:
4238 rate_flg = NL80211_RATE_INFO_160_MHZ_WIDTH;
4239 break;
4240 }
4241
4242 if (rate_flg && nla_put_flag(msg, rate_flg))
4243 return false;
4244
Johannes Bergdb9c64c2012-11-09 14:56:41 +01004245 if (info->flags & RATE_INFO_FLAGS_MCS) {
4246 if (nla_put_u8(msg, NL80211_RATE_INFO_MCS, info->mcs))
4247 return false;
Johannes Bergdb9c64c2012-11-09 14:56:41 +01004248 if (info->flags & RATE_INFO_FLAGS_SHORT_GI &&
4249 nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI))
4250 return false;
4251 } else if (info->flags & RATE_INFO_FLAGS_VHT_MCS) {
4252 if (nla_put_u8(msg, NL80211_RATE_INFO_VHT_MCS, info->mcs))
4253 return false;
4254 if (nla_put_u8(msg, NL80211_RATE_INFO_VHT_NSS, info->nss))
4255 return false;
Johannes Bergdb9c64c2012-11-09 14:56:41 +01004256 if (info->flags & RATE_INFO_FLAGS_SHORT_GI &&
4257 nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI))
4258 return false;
4259 }
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01004260
4261 nla_nest_end(msg, rate);
4262 return true;
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01004263}
4264
Felix Fietkau119363c2013-04-22 16:29:30 +02004265static bool nl80211_put_signal(struct sk_buff *msg, u8 mask, s8 *signal,
4266 int id)
4267{
4268 void *attr;
4269 int i = 0;
4270
4271 if (!mask)
4272 return true;
4273
4274 attr = nla_nest_start(msg, id);
4275 if (!attr)
4276 return false;
4277
4278 for (i = 0; i < IEEE80211_MAX_CHAINS; i++) {
4279 if (!(mask & BIT(i)))
4280 continue;
4281
4282 if (nla_put_u8(msg, i, signal[i]))
4283 return false;
4284 }
4285
4286 nla_nest_end(msg, attr);
4287
4288 return true;
4289}
4290
Johannes Bergcf5ead82014-11-14 17:14:00 +01004291static int nl80211_send_station(struct sk_buff *msg, u32 cmd, u32 portid,
4292 u32 seq, int flags,
John W. Linville66266b32012-03-15 13:25:41 -04004293 struct cfg80211_registered_device *rdev,
4294 struct net_device *dev,
Johannes Berg98b62182009-12-23 13:15:44 +01004295 const u8 *mac_addr, struct station_info *sinfo)
Johannes Bergfd5b74d2007-12-19 02:03:36 +01004296{
4297 void *hdr;
Paul Stewartf4263c92011-03-31 09:25:41 -07004298 struct nlattr *sinfoattr, *bss_param;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01004299
Johannes Bergcf5ead82014-11-14 17:14:00 +01004300 hdr = nl80211hdr_put(msg, portid, seq, flags, cmd);
Johannes Bergfd5b74d2007-12-19 02:03:36 +01004301 if (!hdr)
4302 return -1;
4303
David S. Miller9360ffd2012-03-29 04:41:26 -04004304 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
4305 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) ||
4306 nla_put_u32(msg, NL80211_ATTR_GENERATION, sinfo->generation))
4307 goto nla_put_failure;
Johannes Bergf5ea9122009-08-07 16:17:38 +02004308
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004309 sinfoattr = nla_nest_start(msg, NL80211_ATTR_STA_INFO);
4310 if (!sinfoattr)
Johannes Bergfd5b74d2007-12-19 02:03:36 +01004311 goto nla_put_failure;
Johannes Berg319090b2014-11-17 14:08:11 +01004312
4313#define PUT_SINFO(attr, memb, type) do { \
Johannes Bergd686b922016-04-26 09:54:11 +02004314 BUILD_BUG_ON(sizeof(type) == sizeof(u64)); \
Mohammed Shafi Shajakhan739960f2016-04-07 19:59:34 +05304315 if (sinfo->filled & (1ULL << NL80211_STA_INFO_ ## attr) && \
Johannes Berg319090b2014-11-17 14:08:11 +01004316 nla_put_ ## type(msg, NL80211_STA_INFO_ ## attr, \
4317 sinfo->memb)) \
4318 goto nla_put_failure; \
4319 } while (0)
Johannes Bergd686b922016-04-26 09:54:11 +02004320#define PUT_SINFO_U64(attr, memb) do { \
4321 if (sinfo->filled & (1ULL << NL80211_STA_INFO_ ## attr) && \
4322 nla_put_u64_64bit(msg, NL80211_STA_INFO_ ## attr, \
4323 sinfo->memb, NL80211_STA_INFO_PAD)) \
4324 goto nla_put_failure; \
4325 } while (0)
Johannes Berg319090b2014-11-17 14:08:11 +01004326
4327 PUT_SINFO(CONNECTED_TIME, connected_time, u32);
4328 PUT_SINFO(INACTIVE_TIME, inactive_time, u32);
4329
4330 if (sinfo->filled & (BIT(NL80211_STA_INFO_RX_BYTES) |
4331 BIT(NL80211_STA_INFO_RX_BYTES64)) &&
David S. Miller9360ffd2012-03-29 04:41:26 -04004332 nla_put_u32(msg, NL80211_STA_INFO_RX_BYTES,
Vladimir Kondratiev42745e02013-02-04 13:53:11 +02004333 (u32)sinfo->rx_bytes))
4334 goto nla_put_failure;
Johannes Berg319090b2014-11-17 14:08:11 +01004335
4336 if (sinfo->filled & (BIT(NL80211_STA_INFO_TX_BYTES) |
4337 BIT(NL80211_STA_INFO_TX_BYTES64)) &&
Vladimir Kondratiev42745e02013-02-04 13:53:11 +02004338 nla_put_u32(msg, NL80211_STA_INFO_TX_BYTES,
4339 (u32)sinfo->tx_bytes))
4340 goto nla_put_failure;
Johannes Berg319090b2014-11-17 14:08:11 +01004341
Johannes Bergd686b922016-04-26 09:54:11 +02004342 PUT_SINFO_U64(RX_BYTES64, rx_bytes);
4343 PUT_SINFO_U64(TX_BYTES64, tx_bytes);
Johannes Berg319090b2014-11-17 14:08:11 +01004344 PUT_SINFO(LLID, llid, u16);
4345 PUT_SINFO(PLID, plid, u16);
4346 PUT_SINFO(PLINK_STATE, plink_state, u8);
Johannes Bergd686b922016-04-26 09:54:11 +02004347 PUT_SINFO_U64(RX_DURATION, rx_duration);
Johannes Berg319090b2014-11-17 14:08:11 +01004348
John W. Linville66266b32012-03-15 13:25:41 -04004349 switch (rdev->wiphy.signal_type) {
4350 case CFG80211_SIGNAL_TYPE_MBM:
Johannes Berg319090b2014-11-17 14:08:11 +01004351 PUT_SINFO(SIGNAL, signal, u8);
4352 PUT_SINFO(SIGNAL_AVG, signal_avg, u8);
John W. Linville66266b32012-03-15 13:25:41 -04004353 break;
4354 default:
4355 break;
4356 }
Johannes Berg319090b2014-11-17 14:08:11 +01004357 if (sinfo->filled & BIT(NL80211_STA_INFO_CHAIN_SIGNAL)) {
Felix Fietkau119363c2013-04-22 16:29:30 +02004358 if (!nl80211_put_signal(msg, sinfo->chains,
4359 sinfo->chain_signal,
4360 NL80211_STA_INFO_CHAIN_SIGNAL))
4361 goto nla_put_failure;
4362 }
Johannes Berg319090b2014-11-17 14:08:11 +01004363 if (sinfo->filled & BIT(NL80211_STA_INFO_CHAIN_SIGNAL_AVG)) {
Felix Fietkau119363c2013-04-22 16:29:30 +02004364 if (!nl80211_put_signal(msg, sinfo->chains,
4365 sinfo->chain_signal_avg,
4366 NL80211_STA_INFO_CHAIN_SIGNAL_AVG))
4367 goto nla_put_failure;
4368 }
Johannes Berg319090b2014-11-17 14:08:11 +01004369 if (sinfo->filled & BIT(NL80211_STA_INFO_TX_BITRATE)) {
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01004370 if (!nl80211_put_sta_rate(msg, &sinfo->txrate,
4371 NL80211_STA_INFO_TX_BITRATE))
Henning Rogge420e7fa2008-12-11 22:04:19 +01004372 goto nla_put_failure;
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01004373 }
Johannes Berg319090b2014-11-17 14:08:11 +01004374 if (sinfo->filled & BIT(NL80211_STA_INFO_RX_BITRATE)) {
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01004375 if (!nl80211_put_sta_rate(msg, &sinfo->rxrate,
4376 NL80211_STA_INFO_RX_BITRATE))
4377 goto nla_put_failure;
Henning Rogge420e7fa2008-12-11 22:04:19 +01004378 }
Johannes Berg319090b2014-11-17 14:08:11 +01004379
4380 PUT_SINFO(RX_PACKETS, rx_packets, u32);
4381 PUT_SINFO(TX_PACKETS, tx_packets, u32);
4382 PUT_SINFO(TX_RETRIES, tx_retries, u32);
4383 PUT_SINFO(TX_FAILED, tx_failed, u32);
4384 PUT_SINFO(EXPECTED_THROUGHPUT, expected_throughput, u32);
4385 PUT_SINFO(BEACON_LOSS, beacon_loss_count, u32);
4386 PUT_SINFO(LOCAL_PM, local_pm, u32);
4387 PUT_SINFO(PEER_PM, peer_pm, u32);
4388 PUT_SINFO(NONPEER_PM, nonpeer_pm, u32);
4389
4390 if (sinfo->filled & BIT(NL80211_STA_INFO_BSS_PARAM)) {
Paul Stewartf4263c92011-03-31 09:25:41 -07004391 bss_param = nla_nest_start(msg, NL80211_STA_INFO_BSS_PARAM);
4392 if (!bss_param)
4393 goto nla_put_failure;
4394
David S. Miller9360ffd2012-03-29 04:41:26 -04004395 if (((sinfo->bss_param.flags & BSS_PARAM_FLAGS_CTS_PROT) &&
4396 nla_put_flag(msg, NL80211_STA_BSS_PARAM_CTS_PROT)) ||
4397 ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_PREAMBLE) &&
4398 nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_PREAMBLE)) ||
4399 ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_SLOT_TIME) &&
4400 nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_SLOT_TIME)) ||
4401 nla_put_u8(msg, NL80211_STA_BSS_PARAM_DTIM_PERIOD,
4402 sinfo->bss_param.dtim_period) ||
4403 nla_put_u16(msg, NL80211_STA_BSS_PARAM_BEACON_INTERVAL,
4404 sinfo->bss_param.beacon_interval))
4405 goto nla_put_failure;
Paul Stewartf4263c92011-03-31 09:25:41 -07004406
4407 nla_nest_end(msg, bss_param);
4408 }
Johannes Berg319090b2014-11-17 14:08:11 +01004409 if ((sinfo->filled & BIT(NL80211_STA_INFO_STA_FLAGS)) &&
David S. Miller9360ffd2012-03-29 04:41:26 -04004410 nla_put(msg, NL80211_STA_INFO_STA_FLAGS,
4411 sizeof(struct nl80211_sta_flag_update),
4412 &sinfo->sta_flags))
4413 goto nla_put_failure;
Johannes Berg319090b2014-11-17 14:08:11 +01004414
Johannes Bergd686b922016-04-26 09:54:11 +02004415 PUT_SINFO_U64(T_OFFSET, t_offset);
4416 PUT_SINFO_U64(RX_DROP_MISC, rx_dropped_misc);
4417 PUT_SINFO_U64(BEACON_RX, rx_beacon);
Johannes Berga76b1942014-11-17 14:12:22 +01004418 PUT_SINFO(BEACON_SIGNAL_AVG, rx_beacon_signal_avg, u8);
Johannes Berg319090b2014-11-17 14:08:11 +01004419
4420#undef PUT_SINFO
Johannes Bergd686b922016-04-26 09:54:11 +02004421#undef PUT_SINFO_U64
Johannes Berg6de39802014-12-19 12:34:00 +01004422
4423 if (sinfo->filled & BIT(NL80211_STA_INFO_TID_STATS)) {
4424 struct nlattr *tidsattr;
4425 int tid;
4426
4427 tidsattr = nla_nest_start(msg, NL80211_STA_INFO_TID_STATS);
4428 if (!tidsattr)
4429 goto nla_put_failure;
4430
4431 for (tid = 0; tid < IEEE80211_NUM_TIDS + 1; tid++) {
4432 struct cfg80211_tid_stats *tidstats;
4433 struct nlattr *tidattr;
4434
4435 tidstats = &sinfo->pertid[tid];
4436
4437 if (!tidstats->filled)
4438 continue;
4439
4440 tidattr = nla_nest_start(msg, tid + 1);
4441 if (!tidattr)
4442 goto nla_put_failure;
4443
Johannes Bergd686b922016-04-26 09:54:11 +02004444#define PUT_TIDVAL_U64(attr, memb) do { \
Johannes Berg6de39802014-12-19 12:34:00 +01004445 if (tidstats->filled & BIT(NL80211_TID_STATS_ ## attr) && \
Johannes Bergd686b922016-04-26 09:54:11 +02004446 nla_put_u64_64bit(msg, NL80211_TID_STATS_ ## attr, \
4447 tidstats->memb, NL80211_TID_STATS_PAD)) \
Johannes Berg6de39802014-12-19 12:34:00 +01004448 goto nla_put_failure; \
4449 } while (0)
4450
Johannes Bergd686b922016-04-26 09:54:11 +02004451 PUT_TIDVAL_U64(RX_MSDU, rx_msdu);
4452 PUT_TIDVAL_U64(TX_MSDU, tx_msdu);
4453 PUT_TIDVAL_U64(TX_MSDU_RETRIES, tx_msdu_retries);
4454 PUT_TIDVAL_U64(TX_MSDU_FAILED, tx_msdu_failed);
Johannes Berg6de39802014-12-19 12:34:00 +01004455
Johannes Bergd686b922016-04-26 09:54:11 +02004456#undef PUT_TIDVAL_U64
Johannes Berg6de39802014-12-19 12:34:00 +01004457 nla_nest_end(msg, tidattr);
4458 }
4459
4460 nla_nest_end(msg, tidsattr);
4461 }
4462
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004463 nla_nest_end(msg, sinfoattr);
Johannes Bergfd5b74d2007-12-19 02:03:36 +01004464
Johannes Berg319090b2014-11-17 14:08:11 +01004465 if (sinfo->assoc_req_ies_len &&
David S. Miller9360ffd2012-03-29 04:41:26 -04004466 nla_put(msg, NL80211_ATTR_IE, sinfo->assoc_req_ies_len,
4467 sinfo->assoc_req_ies))
4468 goto nla_put_failure;
Jouni Malinen50d3dfb2011-08-08 12:11:52 +03004469
Johannes Berg053c0952015-01-16 22:09:00 +01004470 genlmsg_end(msg, hdr);
4471 return 0;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01004472
4473 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07004474 genlmsg_cancel(msg, hdr);
4475 return -EMSGSIZE;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01004476}
4477
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004478static int nl80211_dump_station(struct sk_buff *skb,
Johannes Bergbba95fe2008-07-29 13:22:51 +02004479 struct netlink_callback *cb)
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004480{
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004481 struct station_info sinfo;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08004482 struct cfg80211_registered_device *rdev;
Johannes Berg97990a02013-04-19 01:02:55 +02004483 struct wireless_dev *wdev;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004484 u8 mac_addr[ETH_ALEN];
Johannes Berg97990a02013-04-19 01:02:55 +02004485 int sta_idx = cb->args[2];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004486 int err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004487
Johannes Bergea90e0d2017-03-15 14:26:04 +01004488 rtnl_lock();
Zhao, Gang1b8ec872014-04-21 12:53:02 +08004489 err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev);
Johannes Berg67748892010-10-04 21:14:06 +02004490 if (err)
Johannes Bergea90e0d2017-03-15 14:26:04 +01004491 goto out_err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004492
Johannes Berg97990a02013-04-19 01:02:55 +02004493 if (!wdev->netdev) {
4494 err = -EINVAL;
4495 goto out_err;
4496 }
4497
Zhao, Gang1b8ec872014-04-21 12:53:02 +08004498 if (!rdev->ops->dump_station) {
Jouni Malineneec60b02009-03-20 21:21:19 +02004499 err = -EOPNOTSUPP;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004500 goto out_err;
4501 }
4502
Johannes Bergbba95fe2008-07-29 13:22:51 +02004503 while (1) {
Jouni Malinenf612ced2011-08-11 11:46:22 +03004504 memset(&sinfo, 0, sizeof(sinfo));
Zhao, Gang1b8ec872014-04-21 12:53:02 +08004505 err = rdev_dump_station(rdev, wdev->netdev, sta_idx,
Hila Gonene35e4d22012-06-27 17:19:42 +03004506 mac_addr, &sinfo);
Johannes Bergbba95fe2008-07-29 13:22:51 +02004507 if (err == -ENOENT)
4508 break;
4509 if (err)
Johannes Berg3b858752009-03-12 09:55:09 +01004510 goto out_err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004511
Johannes Bergcf5ead82014-11-14 17:14:00 +01004512 if (nl80211_send_station(skb, NL80211_CMD_NEW_STATION,
Eric W. Biederman15e47302012-09-07 20:12:54 +00004513 NETLINK_CB(cb->skb).portid,
Johannes Bergbba95fe2008-07-29 13:22:51 +02004514 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08004515 rdev, wdev->netdev, mac_addr,
Johannes Bergbba95fe2008-07-29 13:22:51 +02004516 &sinfo) < 0)
4517 goto out;
4518
4519 sta_idx++;
4520 }
4521
Johannes Bergbba95fe2008-07-29 13:22:51 +02004522 out:
Johannes Berg97990a02013-04-19 01:02:55 +02004523 cb->args[2] = sta_idx;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004524 err = skb->len;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004525 out_err:
Johannes Bergea90e0d2017-03-15 14:26:04 +01004526 rtnl_unlock();
Johannes Bergbba95fe2008-07-29 13:22:51 +02004527
4528 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004529}
Johannes Bergfd5b74d2007-12-19 02:03:36 +01004530
Johannes Berg5727ef12007-12-19 02:03:34 +01004531static int nl80211_get_station(struct sk_buff *skb, struct genl_info *info)
4532{
Johannes Berg4c476992010-10-04 21:36:35 +02004533 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4534 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004535 struct station_info sinfo;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01004536 struct sk_buff *msg;
4537 u8 *mac_addr = NULL;
Johannes Berg4c476992010-10-04 21:36:35 +02004538 int err;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01004539
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004540 memset(&sinfo, 0, sizeof(sinfo));
Johannes Bergfd5b74d2007-12-19 02:03:36 +01004541
4542 if (!info->attrs[NL80211_ATTR_MAC])
4543 return -EINVAL;
4544
4545 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
4546
Johannes Berg4c476992010-10-04 21:36:35 +02004547 if (!rdev->ops->get_station)
4548 return -EOPNOTSUPP;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01004549
Hila Gonene35e4d22012-06-27 17:19:42 +03004550 err = rdev_get_station(rdev, dev, mac_addr, &sinfo);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004551 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02004552 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004553
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07004554 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Bergfd5b74d2007-12-19 02:03:36 +01004555 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02004556 return -ENOMEM;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01004557
Johannes Bergcf5ead82014-11-14 17:14:00 +01004558 if (nl80211_send_station(msg, NL80211_CMD_NEW_STATION,
4559 info->snd_portid, info->snd_seq, 0,
John W. Linville66266b32012-03-15 13:25:41 -04004560 rdev, dev, mac_addr, &sinfo) < 0) {
Johannes Berg4c476992010-10-04 21:36:35 +02004561 nlmsg_free(msg);
4562 return -ENOBUFS;
4563 }
Johannes Bergfd5b74d2007-12-19 02:03:36 +01004564
Johannes Berg4c476992010-10-04 21:36:35 +02004565 return genlmsg_reply(msg, info);
Johannes Berg5727ef12007-12-19 02:03:34 +01004566}
4567
Johannes Berg77ee7c82013-02-15 00:48:33 +01004568int cfg80211_check_station_change(struct wiphy *wiphy,
4569 struct station_parameters *params,
4570 enum cfg80211_station_type statype)
4571{
Ayala Bekere4208422015-10-23 11:20:06 +03004572 if (params->listen_interval != -1 &&
4573 statype != CFG80211_STA_AP_CLIENT_UNASSOC)
Johannes Berg77ee7c82013-02-15 00:48:33 +01004574 return -EINVAL;
Ayala Bekere4208422015-10-23 11:20:06 +03004575
Ayala Beker17b94242016-03-17 15:41:38 +02004576 if (params->support_p2p_ps != -1 &&
4577 statype != CFG80211_STA_AP_CLIENT_UNASSOC)
4578 return -EINVAL;
4579
Arik Nemtsovc72e1142014-07-17 17:14:29 +03004580 if (params->aid &&
Ayala Bekere4208422015-10-23 11:20:06 +03004581 !(params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) &&
4582 statype != CFG80211_STA_AP_CLIENT_UNASSOC)
Johannes Berg77ee7c82013-02-15 00:48:33 +01004583 return -EINVAL;
4584
4585 /* When you run into this, adjust the code below for the new flag */
4586 BUILD_BUG_ON(NL80211_STA_FLAG_MAX != 7);
4587
4588 switch (statype) {
Thomas Pederseneef941e2013-03-04 13:06:11 -08004589 case CFG80211_STA_MESH_PEER_KERNEL:
4590 case CFG80211_STA_MESH_PEER_USER:
Johannes Berg77ee7c82013-02-15 00:48:33 +01004591 /*
4592 * No ignoring the TDLS flag here -- the userspace mesh
4593 * code doesn't have the bug of including TDLS in the
4594 * mask everywhere.
4595 */
4596 if (params->sta_flags_mask &
4597 ~(BIT(NL80211_STA_FLAG_AUTHENTICATED) |
4598 BIT(NL80211_STA_FLAG_MFP) |
4599 BIT(NL80211_STA_FLAG_AUTHORIZED)))
4600 return -EINVAL;
4601 break;
4602 case CFG80211_STA_TDLS_PEER_SETUP:
4603 case CFG80211_STA_TDLS_PEER_ACTIVE:
4604 if (!(params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)))
4605 return -EINVAL;
4606 /* ignore since it can't change */
4607 params->sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER);
4608 break;
4609 default:
4610 /* disallow mesh-specific things */
4611 if (params->plink_action != NL80211_PLINK_ACTION_NO_ACTION)
4612 return -EINVAL;
4613 if (params->local_pm)
4614 return -EINVAL;
4615 if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE)
4616 return -EINVAL;
4617 }
4618
4619 if (statype != CFG80211_STA_TDLS_PEER_SETUP &&
4620 statype != CFG80211_STA_TDLS_PEER_ACTIVE) {
4621 /* TDLS can't be set, ... */
4622 if (params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))
4623 return -EINVAL;
4624 /*
4625 * ... but don't bother the driver with it. This works around
4626 * a hostapd/wpa_supplicant issue -- it always includes the
4627 * TLDS_PEER flag in the mask even for AP mode.
4628 */
4629 params->sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER);
4630 }
4631
Ayala Beker47edb112015-09-21 15:49:53 +03004632 if (statype != CFG80211_STA_TDLS_PEER_SETUP &&
4633 statype != CFG80211_STA_AP_CLIENT_UNASSOC) {
Johannes Berg77ee7c82013-02-15 00:48:33 +01004634 /* reject other things that can't change */
4635 if (params->sta_modify_mask & STATION_PARAM_APPLY_UAPSD)
4636 return -EINVAL;
4637 if (params->sta_modify_mask & STATION_PARAM_APPLY_CAPABILITY)
4638 return -EINVAL;
4639 if (params->supported_rates)
4640 return -EINVAL;
4641 if (params->ext_capab || params->ht_capa || params->vht_capa)
4642 return -EINVAL;
4643 }
4644
Ayala Beker47edb112015-09-21 15:49:53 +03004645 if (statype != CFG80211_STA_AP_CLIENT &&
4646 statype != CFG80211_STA_AP_CLIENT_UNASSOC) {
Johannes Berg77ee7c82013-02-15 00:48:33 +01004647 if (params->vlan)
4648 return -EINVAL;
4649 }
4650
4651 switch (statype) {
4652 case CFG80211_STA_AP_MLME_CLIENT:
4653 /* Use this only for authorizing/unauthorizing a station */
4654 if (!(params->sta_flags_mask & BIT(NL80211_STA_FLAG_AUTHORIZED)))
4655 return -EOPNOTSUPP;
4656 break;
4657 case CFG80211_STA_AP_CLIENT:
Ayala Beker47edb112015-09-21 15:49:53 +03004658 case CFG80211_STA_AP_CLIENT_UNASSOC:
Johannes Berg77ee7c82013-02-15 00:48:33 +01004659 /* accept only the listed bits */
4660 if (params->sta_flags_mask &
4661 ~(BIT(NL80211_STA_FLAG_AUTHORIZED) |
4662 BIT(NL80211_STA_FLAG_AUTHENTICATED) |
4663 BIT(NL80211_STA_FLAG_ASSOCIATED) |
4664 BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) |
4665 BIT(NL80211_STA_FLAG_WME) |
4666 BIT(NL80211_STA_FLAG_MFP)))
4667 return -EINVAL;
4668
4669 /* but authenticated/associated only if driver handles it */
4670 if (!(wiphy->features & NL80211_FEATURE_FULL_AP_CLIENT_STATE) &&
4671 params->sta_flags_mask &
4672 (BIT(NL80211_STA_FLAG_AUTHENTICATED) |
4673 BIT(NL80211_STA_FLAG_ASSOCIATED)))
4674 return -EINVAL;
4675 break;
4676 case CFG80211_STA_IBSS:
4677 case CFG80211_STA_AP_STA:
4678 /* reject any changes other than AUTHORIZED */
4679 if (params->sta_flags_mask & ~BIT(NL80211_STA_FLAG_AUTHORIZED))
4680 return -EINVAL;
4681 break;
4682 case CFG80211_STA_TDLS_PEER_SETUP:
4683 /* reject any changes other than AUTHORIZED or WME */
4684 if (params->sta_flags_mask & ~(BIT(NL80211_STA_FLAG_AUTHORIZED) |
4685 BIT(NL80211_STA_FLAG_WME)))
4686 return -EINVAL;
4687 /* force (at least) rates when authorizing */
4688 if (params->sta_flags_set & BIT(NL80211_STA_FLAG_AUTHORIZED) &&
4689 !params->supported_rates)
4690 return -EINVAL;
4691 break;
4692 case CFG80211_STA_TDLS_PEER_ACTIVE:
4693 /* reject any changes */
4694 return -EINVAL;
Thomas Pederseneef941e2013-03-04 13:06:11 -08004695 case CFG80211_STA_MESH_PEER_KERNEL:
Johannes Berg77ee7c82013-02-15 00:48:33 +01004696 if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE)
4697 return -EINVAL;
4698 break;
Thomas Pederseneef941e2013-03-04 13:06:11 -08004699 case CFG80211_STA_MESH_PEER_USER:
Chun-Yeow Yeoh42925042015-04-18 01:30:02 +08004700 if (params->plink_action != NL80211_PLINK_ACTION_NO_ACTION &&
4701 params->plink_action != NL80211_PLINK_ACTION_BLOCK)
Johannes Berg77ee7c82013-02-15 00:48:33 +01004702 return -EINVAL;
4703 break;
4704 }
4705
Beni Lev06f7c882016-07-19 19:28:56 +03004706 /*
4707 * Older kernel versions ignored this attribute entirely, so don't
4708 * reject attempts to update it but mark it as unused instead so the
4709 * driver won't look at the data.
4710 */
4711 if (statype != CFG80211_STA_AP_CLIENT_UNASSOC &&
4712 statype != CFG80211_STA_TDLS_PEER_SETUP)
4713 params->opmode_notif_used = false;
4714
Johannes Berg77ee7c82013-02-15 00:48:33 +01004715 return 0;
4716}
4717EXPORT_SYMBOL(cfg80211_check_station_change);
4718
Johannes Berg5727ef12007-12-19 02:03:34 +01004719/*
Felix Fietkauc258d2d2009-11-11 17:23:31 +01004720 * Get vlan interface making sure it is running and on the right wiphy.
Johannes Berg5727ef12007-12-19 02:03:34 +01004721 */
Johannes Berg80b99892011-11-18 16:23:01 +01004722static struct net_device *get_vlan(struct genl_info *info,
4723 struct cfg80211_registered_device *rdev)
Johannes Berg5727ef12007-12-19 02:03:34 +01004724{
Johannes Berg463d0182009-07-14 00:33:35 +02004725 struct nlattr *vlanattr = info->attrs[NL80211_ATTR_STA_VLAN];
Johannes Berg80b99892011-11-18 16:23:01 +01004726 struct net_device *v;
4727 int ret;
Johannes Berg5727ef12007-12-19 02:03:34 +01004728
Johannes Berg80b99892011-11-18 16:23:01 +01004729 if (!vlanattr)
4730 return NULL;
4731
4732 v = dev_get_by_index(genl_info_net(info), nla_get_u32(vlanattr));
4733 if (!v)
4734 return ERR_PTR(-ENODEV);
4735
4736 if (!v->ieee80211_ptr || v->ieee80211_ptr->wiphy != &rdev->wiphy) {
4737 ret = -EINVAL;
4738 goto error;
Johannes Berg5727ef12007-12-19 02:03:34 +01004739 }
Johannes Berg80b99892011-11-18 16:23:01 +01004740
Johannes Berg77ee7c82013-02-15 00:48:33 +01004741 if (v->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN &&
4742 v->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
4743 v->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) {
4744 ret = -EINVAL;
4745 goto error;
4746 }
4747
Johannes Berg80b99892011-11-18 16:23:01 +01004748 if (!netif_running(v)) {
4749 ret = -ENETDOWN;
4750 goto error;
4751 }
4752
4753 return v;
4754 error:
4755 dev_put(v);
4756 return ERR_PTR(ret);
Johannes Berg5727ef12007-12-19 02:03:34 +01004757}
4758
Johannes Berg94e860f2014-01-20 23:58:15 +01004759static const struct nla_policy
4760nl80211_sta_wme_policy[NL80211_STA_WME_MAX + 1] = {
Jouni Malinendf881292013-02-14 21:10:54 +02004761 [NL80211_STA_WME_UAPSD_QUEUES] = { .type = NLA_U8 },
4762 [NL80211_STA_WME_MAX_SP] = { .type = NLA_U8 },
4763};
4764
Johannes Bergff276692013-02-15 00:09:01 +01004765static int nl80211_parse_sta_wme(struct genl_info *info,
4766 struct station_parameters *params)
Jouni Malinendf881292013-02-14 21:10:54 +02004767{
Jouni Malinendf881292013-02-14 21:10:54 +02004768 struct nlattr *tb[NL80211_STA_WME_MAX + 1];
4769 struct nlattr *nla;
4770 int err;
4771
Jouni Malinendf881292013-02-14 21:10:54 +02004772 /* parse WME attributes if present */
4773 if (!info->attrs[NL80211_ATTR_STA_WME])
4774 return 0;
4775
4776 nla = info->attrs[NL80211_ATTR_STA_WME];
4777 err = nla_parse_nested(tb, NL80211_STA_WME_MAX, nla,
Johannes Bergfe521452017-04-12 14:34:08 +02004778 nl80211_sta_wme_policy, info->extack);
Jouni Malinendf881292013-02-14 21:10:54 +02004779 if (err)
4780 return err;
4781
4782 if (tb[NL80211_STA_WME_UAPSD_QUEUES])
4783 params->uapsd_queues = nla_get_u8(
4784 tb[NL80211_STA_WME_UAPSD_QUEUES]);
4785 if (params->uapsd_queues & ~IEEE80211_WMM_IE_STA_QOSINFO_AC_MASK)
4786 return -EINVAL;
4787
4788 if (tb[NL80211_STA_WME_MAX_SP])
4789 params->max_sp = nla_get_u8(tb[NL80211_STA_WME_MAX_SP]);
4790
4791 if (params->max_sp & ~IEEE80211_WMM_IE_STA_QOSINFO_SP_MASK)
4792 return -EINVAL;
4793
4794 params->sta_modify_mask |= STATION_PARAM_APPLY_UAPSD;
4795
4796 return 0;
4797}
4798
Sunil Duttc01fc9a2013-10-09 20:45:21 +05304799static int nl80211_parse_sta_channel_info(struct genl_info *info,
4800 struct station_parameters *params)
4801{
4802 if (info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]) {
4803 params->supported_channels =
4804 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]);
4805 params->supported_channels_len =
4806 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]);
4807 /*
4808 * Need to include at least one (first channel, number of
4809 * channels) tuple for each subband, and must have proper
4810 * tuples for the rest of the data as well.
4811 */
4812 if (params->supported_channels_len < 2)
4813 return -EINVAL;
4814 if (params->supported_channels_len % 2)
4815 return -EINVAL;
4816 }
4817
4818 if (info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]) {
4819 params->supported_oper_classes =
4820 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]);
4821 params->supported_oper_classes_len =
4822 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]);
4823 /*
4824 * The value of the Length field of the Supported Operating
4825 * Classes element is between 2 and 253.
4826 */
4827 if (params->supported_oper_classes_len < 2 ||
4828 params->supported_oper_classes_len > 253)
4829 return -EINVAL;
4830 }
4831 return 0;
4832}
4833
Johannes Bergff276692013-02-15 00:09:01 +01004834static int nl80211_set_station_tdls(struct genl_info *info,
4835 struct station_parameters *params)
4836{
Sunil Duttc01fc9a2013-10-09 20:45:21 +05304837 int err;
Johannes Bergff276692013-02-15 00:09:01 +01004838 /* Dummy STA entry gets updated once the peer capabilities are known */
Jouni Malinen5e4b6f52013-05-16 20:11:08 +03004839 if (info->attrs[NL80211_ATTR_PEER_AID])
4840 params->aid = nla_get_u16(info->attrs[NL80211_ATTR_PEER_AID]);
Johannes Bergff276692013-02-15 00:09:01 +01004841 if (info->attrs[NL80211_ATTR_HT_CAPABILITY])
4842 params->ht_capa =
4843 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]);
4844 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY])
4845 params->vht_capa =
4846 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]);
4847
Sunil Duttc01fc9a2013-10-09 20:45:21 +05304848 err = nl80211_parse_sta_channel_info(info, params);
4849 if (err)
4850 return err;
4851
Johannes Bergff276692013-02-15 00:09:01 +01004852 return nl80211_parse_sta_wme(info, params);
4853}
4854
Johannes Berg5727ef12007-12-19 02:03:34 +01004855static int nl80211_set_station(struct sk_buff *skb, struct genl_info *info)
4856{
Johannes Berg4c476992010-10-04 21:36:35 +02004857 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg4c476992010-10-04 21:36:35 +02004858 struct net_device *dev = info->user_ptr[1];
Johannes Berg5727ef12007-12-19 02:03:34 +01004859 struct station_parameters params;
Johannes Berg77ee7c82013-02-15 00:48:33 +01004860 u8 *mac_addr;
4861 int err;
Johannes Berg5727ef12007-12-19 02:03:34 +01004862
4863 memset(&params, 0, sizeof(params));
4864
Johannes Berg77ee7c82013-02-15 00:48:33 +01004865 if (!rdev->ops->change_station)
4866 return -EOPNOTSUPP;
4867
Ayala Bekere4208422015-10-23 11:20:06 +03004868 /*
4869 * AID and listen_interval properties can be set only for unassociated
4870 * station. Include these parameters here and will check them in
4871 * cfg80211_check_station_change().
4872 */
Ayala Bekera9bc31e2015-11-26 16:26:12 +01004873 if (info->attrs[NL80211_ATTR_STA_AID])
4874 params.aid = nla_get_u16(info->attrs[NL80211_ATTR_STA_AID]);
Ayala Bekere4208422015-10-23 11:20:06 +03004875
4876 if (info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL])
4877 params.listen_interval =
4878 nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]);
4879 else
4880 params.listen_interval = -1;
Johannes Berg5727ef12007-12-19 02:03:34 +01004881
Ayala Beker17b94242016-03-17 15:41:38 +02004882 if (info->attrs[NL80211_ATTR_STA_SUPPORT_P2P_PS]) {
4883 u8 tmp;
4884
4885 tmp = nla_get_u8(info->attrs[NL80211_ATTR_STA_SUPPORT_P2P_PS]);
4886 if (tmp >= NUM_NL80211_P2P_PS_STATUS)
4887 return -EINVAL;
4888
4889 params.support_p2p_ps = tmp;
4890 } else {
4891 params.support_p2p_ps = -1;
4892 }
4893
Johannes Berg5727ef12007-12-19 02:03:34 +01004894 if (!info->attrs[NL80211_ATTR_MAC])
4895 return -EINVAL;
4896
4897 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
4898
4899 if (info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) {
4900 params.supported_rates =
4901 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
4902 params.supported_rates_len =
4903 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
4904 }
4905
Jouni Malinen9d62a982013-02-14 21:10:13 +02004906 if (info->attrs[NL80211_ATTR_STA_CAPABILITY]) {
4907 params.capability =
4908 nla_get_u16(info->attrs[NL80211_ATTR_STA_CAPABILITY]);
4909 params.sta_modify_mask |= STATION_PARAM_APPLY_CAPABILITY;
4910 }
4911
4912 if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]) {
4913 params.ext_capab =
4914 nla_data(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
4915 params.ext_capab_len =
4916 nla_len(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
4917 }
4918
Johannes Bergbdd3ae32012-01-02 13:30:03 +01004919 if (parse_station_flags(info, dev->ieee80211_ptr->iftype, &params))
Johannes Berg5727ef12007-12-19 02:03:34 +01004920 return -EINVAL;
4921
Johannes Bergf8bacc22013-02-14 23:27:01 +01004922 if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) {
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004923 params.plink_action =
Johannes Bergf8bacc22013-02-14 23:27:01 +01004924 nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]);
4925 if (params.plink_action >= NUM_NL80211_PLINK_ACTIONS)
4926 return -EINVAL;
4927 }
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004928
Johannes Bergf8bacc22013-02-14 23:27:01 +01004929 if (info->attrs[NL80211_ATTR_STA_PLINK_STATE]) {
Javier Cardona9c3990a2011-05-03 16:57:11 -07004930 params.plink_state =
Johannes Bergf8bacc22013-02-14 23:27:01 +01004931 nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_STATE]);
4932 if (params.plink_state >= NUM_NL80211_PLINK_STATES)
4933 return -EINVAL;
Masashi Honma7d27a0b2016-07-01 10:19:34 +09004934 if (info->attrs[NL80211_ATTR_MESH_PEER_AID]) {
4935 params.peer_aid = nla_get_u16(
4936 info->attrs[NL80211_ATTR_MESH_PEER_AID]);
4937 if (params.peer_aid > IEEE80211_MAX_AID)
4938 return -EINVAL;
4939 }
Johannes Bergf8bacc22013-02-14 23:27:01 +01004940 params.sta_modify_mask |= STATION_PARAM_APPLY_PLINK_STATE;
4941 }
Javier Cardona9c3990a2011-05-03 16:57:11 -07004942
Marco Porsch3b1c5a52013-01-07 16:04:52 +01004943 if (info->attrs[NL80211_ATTR_LOCAL_MESH_POWER_MODE]) {
4944 enum nl80211_mesh_power_mode pm = nla_get_u32(
4945 info->attrs[NL80211_ATTR_LOCAL_MESH_POWER_MODE]);
4946
4947 if (pm <= NL80211_MESH_POWER_UNKNOWN ||
4948 pm > NL80211_MESH_POWER_MAX)
4949 return -EINVAL;
4950
4951 params.local_pm = pm;
4952 }
4953
Beni Lev06f7c882016-07-19 19:28:56 +03004954 if (info->attrs[NL80211_ATTR_OPMODE_NOTIF]) {
4955 params.opmode_notif_used = true;
4956 params.opmode_notif =
4957 nla_get_u8(info->attrs[NL80211_ATTR_OPMODE_NOTIF]);
4958 }
4959
Johannes Berg77ee7c82013-02-15 00:48:33 +01004960 /* Include parameters for TDLS peer (will check later) */
4961 err = nl80211_set_station_tdls(info, &params);
4962 if (err)
4963 return err;
4964
4965 params.vlan = get_vlan(info, rdev);
4966 if (IS_ERR(params.vlan))
4967 return PTR_ERR(params.vlan);
4968
Johannes Berga97f4422009-06-18 17:23:43 +02004969 switch (dev->ieee80211_ptr->iftype) {
4970 case NL80211_IFTYPE_AP:
4971 case NL80211_IFTYPE_AP_VLAN:
Johannes Berg074ac8d2010-09-16 14:58:22 +02004972 case NL80211_IFTYPE_P2P_GO:
Johannes Berg074ac8d2010-09-16 14:58:22 +02004973 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Berga97f4422009-06-18 17:23:43 +02004974 case NL80211_IFTYPE_STATION:
Antonio Quartulli267335d2012-01-31 20:25:47 +01004975 case NL80211_IFTYPE_ADHOC:
Johannes Berga97f4422009-06-18 17:23:43 +02004976 case NL80211_IFTYPE_MESH_POINT:
Johannes Berga97f4422009-06-18 17:23:43 +02004977 break;
4978 default:
Johannes Berg77ee7c82013-02-15 00:48:33 +01004979 err = -EOPNOTSUPP;
4980 goto out_put_vlan;
Johannes Berg034d6552009-05-27 10:35:29 +02004981 }
4982
Johannes Berg77ee7c82013-02-15 00:48:33 +01004983 /* driver will call cfg80211_check_station_change() */
Hila Gonene35e4d22012-06-27 17:19:42 +03004984 err = rdev_change_station(rdev, dev, mac_addr, &params);
Johannes Berg5727ef12007-12-19 02:03:34 +01004985
Johannes Berg77ee7c82013-02-15 00:48:33 +01004986 out_put_vlan:
Johannes Berg5727ef12007-12-19 02:03:34 +01004987 if (params.vlan)
4988 dev_put(params.vlan);
Johannes Berg3b858752009-03-12 09:55:09 +01004989
Johannes Berg5727ef12007-12-19 02:03:34 +01004990 return err;
4991}
4992
4993static int nl80211_new_station(struct sk_buff *skb, struct genl_info *info)
4994{
Johannes Berg4c476992010-10-04 21:36:35 +02004995 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg5727ef12007-12-19 02:03:34 +01004996 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02004997 struct net_device *dev = info->user_ptr[1];
Johannes Berg5727ef12007-12-19 02:03:34 +01004998 struct station_parameters params;
4999 u8 *mac_addr = NULL;
Johannes Bergbda95eb2015-11-26 16:26:13 +01005000 u32 auth_assoc = BIT(NL80211_STA_FLAG_AUTHENTICATED) |
5001 BIT(NL80211_STA_FLAG_ASSOCIATED);
Johannes Berg5727ef12007-12-19 02:03:34 +01005002
5003 memset(&params, 0, sizeof(params));
5004
Johannes Berg984c3112013-02-14 23:43:25 +01005005 if (!rdev->ops->add_station)
5006 return -EOPNOTSUPP;
5007
Johannes Berg5727ef12007-12-19 02:03:34 +01005008 if (!info->attrs[NL80211_ATTR_MAC])
5009 return -EINVAL;
5010
Johannes Berg5727ef12007-12-19 02:03:34 +01005011 if (!info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL])
5012 return -EINVAL;
5013
5014 if (!info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES])
5015 return -EINVAL;
5016
Jouni Malinen5e4b6f52013-05-16 20:11:08 +03005017 if (!info->attrs[NL80211_ATTR_STA_AID] &&
5018 !info->attrs[NL80211_ATTR_PEER_AID])
Thadeu Lima de Souza Cascardo0e956c12010-02-12 12:34:50 -02005019 return -EINVAL;
5020
Johannes Berg5727ef12007-12-19 02:03:34 +01005021 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
5022 params.supported_rates =
5023 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
5024 params.supported_rates_len =
5025 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
5026 params.listen_interval =
5027 nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]);
Johannes Berg51b50fb2009-05-24 16:42:30 +02005028
Ayala Beker17b94242016-03-17 15:41:38 +02005029 if (info->attrs[NL80211_ATTR_STA_SUPPORT_P2P_PS]) {
5030 u8 tmp;
5031
5032 tmp = nla_get_u8(info->attrs[NL80211_ATTR_STA_SUPPORT_P2P_PS]);
5033 if (tmp >= NUM_NL80211_P2P_PS_STATUS)
5034 return -EINVAL;
5035
5036 params.support_p2p_ps = tmp;
5037 } else {
5038 /*
5039 * if not specified, assume it's supported for P2P GO interface,
5040 * and is NOT supported for AP interface
5041 */
5042 params.support_p2p_ps =
5043 dev->ieee80211_ptr->iftype == NL80211_IFTYPE_P2P_GO;
5044 }
5045
Jouni Malinen3d124ea2013-05-27 18:24:02 +03005046 if (info->attrs[NL80211_ATTR_PEER_AID])
Jouni Malinen5e4b6f52013-05-16 20:11:08 +03005047 params.aid = nla_get_u16(info->attrs[NL80211_ATTR_PEER_AID]);
Jouni Malinen3d124ea2013-05-27 18:24:02 +03005048 else
5049 params.aid = nla_get_u16(info->attrs[NL80211_ATTR_STA_AID]);
Thadeu Lima de Souza Cascardo0e956c12010-02-12 12:34:50 -02005050 if (!params.aid || params.aid > IEEE80211_MAX_AID)
5051 return -EINVAL;
Johannes Berg51b50fb2009-05-24 16:42:30 +02005052
Jouni Malinen9d62a982013-02-14 21:10:13 +02005053 if (info->attrs[NL80211_ATTR_STA_CAPABILITY]) {
5054 params.capability =
5055 nla_get_u16(info->attrs[NL80211_ATTR_STA_CAPABILITY]);
5056 params.sta_modify_mask |= STATION_PARAM_APPLY_CAPABILITY;
5057 }
5058
5059 if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]) {
5060 params.ext_capab =
5061 nla_data(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
5062 params.ext_capab_len =
5063 nla_len(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
5064 }
5065
Jouni Malinen36aedc92008-08-25 11:58:58 +03005066 if (info->attrs[NL80211_ATTR_HT_CAPABILITY])
5067 params.ht_capa =
5068 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]);
Johannes Berg5727ef12007-12-19 02:03:34 +01005069
Mahesh Palivelaf461be3e2012-10-11 08:04:52 +00005070 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY])
5071 params.vht_capa =
5072 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]);
5073
Marek Kwaczynski60f4a7b2013-12-03 10:04:59 +01005074 if (info->attrs[NL80211_ATTR_OPMODE_NOTIF]) {
5075 params.opmode_notif_used = true;
5076 params.opmode_notif =
5077 nla_get_u8(info->attrs[NL80211_ATTR_OPMODE_NOTIF]);
5078 }
5079
Johannes Bergf8bacc22013-02-14 23:27:01 +01005080 if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) {
Javier Cardona96b78df2011-04-07 15:08:33 -07005081 params.plink_action =
Johannes Bergf8bacc22013-02-14 23:27:01 +01005082 nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]);
5083 if (params.plink_action >= NUM_NL80211_PLINK_ACTIONS)
5084 return -EINVAL;
5085 }
Javier Cardona96b78df2011-04-07 15:08:33 -07005086
Sunil Duttc01fc9a2013-10-09 20:45:21 +05305087 err = nl80211_parse_sta_channel_info(info, &params);
5088 if (err)
5089 return err;
5090
Johannes Bergff276692013-02-15 00:09:01 +01005091 err = nl80211_parse_sta_wme(info, &params);
5092 if (err)
5093 return err;
Johannes Bergbdd90d52011-12-14 12:20:27 +01005094
Johannes Bergbdd3ae32012-01-02 13:30:03 +01005095 if (parse_station_flags(info, dev->ieee80211_ptr->iftype, &params))
Johannes Berg5727ef12007-12-19 02:03:34 +01005096 return -EINVAL;
5097
Johannes Berg496fcc22015-03-12 08:53:27 +02005098 /* HT/VHT requires QoS, but if we don't have that just ignore HT/VHT
5099 * as userspace might just pass through the capabilities from the IEs
5100 * directly, rather than enforcing this restriction and returning an
5101 * error in this case.
5102 */
5103 if (!(params.sta_flags_set & BIT(NL80211_STA_FLAG_WME))) {
5104 params.ht_capa = NULL;
5105 params.vht_capa = NULL;
5106 }
5107
Johannes Berg77ee7c82013-02-15 00:48:33 +01005108 /* When you run into this, adjust the code below for the new flag */
5109 BUILD_BUG_ON(NL80211_STA_FLAG_MAX != 7);
5110
Johannes Bergbdd90d52011-12-14 12:20:27 +01005111 switch (dev->ieee80211_ptr->iftype) {
5112 case NL80211_IFTYPE_AP:
5113 case NL80211_IFTYPE_AP_VLAN:
5114 case NL80211_IFTYPE_P2P_GO:
Johannes Berg984c3112013-02-14 23:43:25 +01005115 /* ignore WME attributes if iface/sta is not capable */
5116 if (!(rdev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) ||
5117 !(params.sta_flags_set & BIT(NL80211_STA_FLAG_WME)))
5118 params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD;
Eliad Pellerc75786c2011-08-23 14:37:46 +03005119
Johannes Bergbdd90d52011-12-14 12:20:27 +01005120 /* TDLS peers cannot be added */
Jouni Malinen3d124ea2013-05-27 18:24:02 +03005121 if ((params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) ||
5122 info->attrs[NL80211_ATTR_PEER_AID])
Johannes Berg4319e192011-09-07 11:50:48 +02005123 return -EINVAL;
Johannes Bergbdd90d52011-12-14 12:20:27 +01005124 /* but don't bother the driver with it */
5125 params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER);
Eliad Pellerc75786c2011-08-23 14:37:46 +03005126
Johannes Bergd582cff2012-10-26 17:53:44 +02005127 /* allow authenticated/associated only if driver handles it */
5128 if (!(rdev->wiphy.features &
5129 NL80211_FEATURE_FULL_AP_CLIENT_STATE) &&
Johannes Bergbda95eb2015-11-26 16:26:13 +01005130 params.sta_flags_mask & auth_assoc)
Johannes Bergd582cff2012-10-26 17:53:44 +02005131 return -EINVAL;
5132
Johannes Bergbda95eb2015-11-26 16:26:13 +01005133 /* Older userspace, or userspace wanting to be compatible with
5134 * !NL80211_FEATURE_FULL_AP_CLIENT_STATE, will not set the auth
5135 * and assoc flags in the mask, but assumes the station will be
5136 * added as associated anyway since this was the required driver
5137 * behaviour before NL80211_FEATURE_FULL_AP_CLIENT_STATE was
5138 * introduced.
5139 * In order to not bother drivers with this quirk in the API
5140 * set the flags in both the mask and set for new stations in
5141 * this case.
5142 */
5143 if (!(params.sta_flags_mask & auth_assoc)) {
5144 params.sta_flags_mask |= auth_assoc;
5145 params.sta_flags_set |= auth_assoc;
5146 }
5147
Johannes Bergbdd90d52011-12-14 12:20:27 +01005148 /* must be last in here for error handling */
5149 params.vlan = get_vlan(info, rdev);
5150 if (IS_ERR(params.vlan))
5151 return PTR_ERR(params.vlan);
5152 break;
5153 case NL80211_IFTYPE_MESH_POINT:
Johannes Berg984c3112013-02-14 23:43:25 +01005154 /* ignore uAPSD data */
5155 params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD;
5156
Johannes Bergd582cff2012-10-26 17:53:44 +02005157 /* associated is disallowed */
5158 if (params.sta_flags_mask & BIT(NL80211_STA_FLAG_ASSOCIATED))
5159 return -EINVAL;
Johannes Bergbdd90d52011-12-14 12:20:27 +01005160 /* TDLS peers cannot be added */
Jouni Malinen3d124ea2013-05-27 18:24:02 +03005161 if ((params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) ||
5162 info->attrs[NL80211_ATTR_PEER_AID])
Johannes Berg4319e192011-09-07 11:50:48 +02005163 return -EINVAL;
Johannes Bergbdd90d52011-12-14 12:20:27 +01005164 break;
5165 case NL80211_IFTYPE_STATION:
Johannes Berg93d08f02013-03-04 09:29:46 +01005166 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Berg984c3112013-02-14 23:43:25 +01005167 /* ignore uAPSD data */
5168 params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD;
5169
Johannes Berg77ee7c82013-02-15 00:48:33 +01005170 /* these are disallowed */
5171 if (params.sta_flags_mask &
5172 (BIT(NL80211_STA_FLAG_ASSOCIATED) |
5173 BIT(NL80211_STA_FLAG_AUTHENTICATED)))
Johannes Bergd582cff2012-10-26 17:53:44 +02005174 return -EINVAL;
Johannes Bergbdd90d52011-12-14 12:20:27 +01005175 /* Only TDLS peers can be added */
5176 if (!(params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)))
5177 return -EINVAL;
5178 /* Can only add if TDLS ... */
5179 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS))
5180 return -EOPNOTSUPP;
5181 /* ... with external setup is supported */
5182 if (!(rdev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP))
5183 return -EOPNOTSUPP;
Johannes Berg77ee7c82013-02-15 00:48:33 +01005184 /*
5185 * Older wpa_supplicant versions always mark the TDLS peer
5186 * as authorized, but it shouldn't yet be.
5187 */
5188 params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_AUTHORIZED);
Johannes Bergbdd90d52011-12-14 12:20:27 +01005189 break;
5190 default:
5191 return -EOPNOTSUPP;
Eliad Pellerc75786c2011-08-23 14:37:46 +03005192 }
5193
Johannes Bergbdd90d52011-12-14 12:20:27 +01005194 /* be aware of params.vlan when changing code here */
Johannes Berg5727ef12007-12-19 02:03:34 +01005195
Hila Gonene35e4d22012-06-27 17:19:42 +03005196 err = rdev_add_station(rdev, dev, mac_addr, &params);
Johannes Berg5727ef12007-12-19 02:03:34 +01005197
Johannes Berg5727ef12007-12-19 02:03:34 +01005198 if (params.vlan)
5199 dev_put(params.vlan);
Johannes Berg5727ef12007-12-19 02:03:34 +01005200 return err;
5201}
5202
5203static int nl80211_del_station(struct sk_buff *skb, struct genl_info *info)
5204{
Johannes Berg4c476992010-10-04 21:36:35 +02005205 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5206 struct net_device *dev = info->user_ptr[1];
Jouni Malinen89c771e2014-10-10 20:52:40 +03005207 struct station_del_parameters params;
5208
5209 memset(&params, 0, sizeof(params));
Johannes Berg5727ef12007-12-19 02:03:34 +01005210
5211 if (info->attrs[NL80211_ATTR_MAC])
Jouni Malinen89c771e2014-10-10 20:52:40 +03005212 params.mac = nla_data(info->attrs[NL80211_ATTR_MAC]);
Johannes Berg5727ef12007-12-19 02:03:34 +01005213
Johannes Berge80cf852009-05-11 14:43:13 +02005214 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
Marco Porschd5d9de02010-03-30 10:00:16 +02005215 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN &&
Johannes Berg074ac8d2010-09-16 14:58:22 +02005216 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT &&
Johannes Berg4c476992010-10-04 21:36:35 +02005217 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
5218 return -EINVAL;
Johannes Berge80cf852009-05-11 14:43:13 +02005219
Johannes Berg4c476992010-10-04 21:36:35 +02005220 if (!rdev->ops->del_station)
5221 return -EOPNOTSUPP;
Johannes Berg5727ef12007-12-19 02:03:34 +01005222
Jouni Malinen98856862014-10-20 13:20:45 +03005223 if (info->attrs[NL80211_ATTR_MGMT_SUBTYPE]) {
5224 params.subtype =
5225 nla_get_u8(info->attrs[NL80211_ATTR_MGMT_SUBTYPE]);
5226 if (params.subtype != IEEE80211_STYPE_DISASSOC >> 4 &&
5227 params.subtype != IEEE80211_STYPE_DEAUTH >> 4)
5228 return -EINVAL;
5229 } else {
5230 /* Default to Deauthentication frame */
5231 params.subtype = IEEE80211_STYPE_DEAUTH >> 4;
5232 }
5233
5234 if (info->attrs[NL80211_ATTR_REASON_CODE]) {
5235 params.reason_code =
5236 nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
5237 if (params.reason_code == 0)
5238 return -EINVAL; /* 0 is reserved */
5239 } else {
5240 /* Default to reason code 2 */
5241 params.reason_code = WLAN_REASON_PREV_AUTH_NOT_VALID;
5242 }
5243
Jouni Malinen89c771e2014-10-10 20:52:40 +03005244 return rdev_del_station(rdev, dev, &params);
Johannes Berg5727ef12007-12-19 02:03:34 +01005245}
5246
Eric W. Biederman15e47302012-09-07 20:12:54 +00005247static int nl80211_send_mpath(struct sk_buff *msg, u32 portid, u32 seq,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005248 int flags, struct net_device *dev,
5249 u8 *dst, u8 *next_hop,
5250 struct mpath_info *pinfo)
5251{
5252 void *hdr;
5253 struct nlattr *pinfoattr;
5254
Henning Rogge1ef4c852014-11-04 16:14:58 +01005255 hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_MPATH);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005256 if (!hdr)
5257 return -1;
5258
David S. Miller9360ffd2012-03-29 04:41:26 -04005259 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
5260 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, dst) ||
5261 nla_put(msg, NL80211_ATTR_MPATH_NEXT_HOP, ETH_ALEN, next_hop) ||
5262 nla_put_u32(msg, NL80211_ATTR_GENERATION, pinfo->generation))
5263 goto nla_put_failure;
Johannes Bergf5ea9122009-08-07 16:17:38 +02005264
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005265 pinfoattr = nla_nest_start(msg, NL80211_ATTR_MPATH_INFO);
5266 if (!pinfoattr)
5267 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04005268 if ((pinfo->filled & MPATH_INFO_FRAME_QLEN) &&
5269 nla_put_u32(msg, NL80211_MPATH_INFO_FRAME_QLEN,
5270 pinfo->frame_qlen))
5271 goto nla_put_failure;
5272 if (((pinfo->filled & MPATH_INFO_SN) &&
5273 nla_put_u32(msg, NL80211_MPATH_INFO_SN, pinfo->sn)) ||
5274 ((pinfo->filled & MPATH_INFO_METRIC) &&
5275 nla_put_u32(msg, NL80211_MPATH_INFO_METRIC,
5276 pinfo->metric)) ||
5277 ((pinfo->filled & MPATH_INFO_EXPTIME) &&
5278 nla_put_u32(msg, NL80211_MPATH_INFO_EXPTIME,
5279 pinfo->exptime)) ||
5280 ((pinfo->filled & MPATH_INFO_FLAGS) &&
5281 nla_put_u8(msg, NL80211_MPATH_INFO_FLAGS,
5282 pinfo->flags)) ||
5283 ((pinfo->filled & MPATH_INFO_DISCOVERY_TIMEOUT) &&
5284 nla_put_u32(msg, NL80211_MPATH_INFO_DISCOVERY_TIMEOUT,
5285 pinfo->discovery_timeout)) ||
5286 ((pinfo->filled & MPATH_INFO_DISCOVERY_RETRIES) &&
5287 nla_put_u8(msg, NL80211_MPATH_INFO_DISCOVERY_RETRIES,
5288 pinfo->discovery_retries)))
5289 goto nla_put_failure;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005290
5291 nla_nest_end(msg, pinfoattr);
5292
Johannes Berg053c0952015-01-16 22:09:00 +01005293 genlmsg_end(msg, hdr);
5294 return 0;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005295
5296 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07005297 genlmsg_cancel(msg, hdr);
5298 return -EMSGSIZE;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005299}
5300
5301static int nl80211_dump_mpath(struct sk_buff *skb,
Johannes Bergbba95fe2008-07-29 13:22:51 +02005302 struct netlink_callback *cb)
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005303{
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005304 struct mpath_info pinfo;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08005305 struct cfg80211_registered_device *rdev;
Johannes Berg97990a02013-04-19 01:02:55 +02005306 struct wireless_dev *wdev;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005307 u8 dst[ETH_ALEN];
5308 u8 next_hop[ETH_ALEN];
Johannes Berg97990a02013-04-19 01:02:55 +02005309 int path_idx = cb->args[2];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005310 int err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005311
Johannes Bergea90e0d2017-03-15 14:26:04 +01005312 rtnl_lock();
Zhao, Gang1b8ec872014-04-21 12:53:02 +08005313 err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev);
Johannes Berg67748892010-10-04 21:14:06 +02005314 if (err)
Johannes Bergea90e0d2017-03-15 14:26:04 +01005315 goto out_err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02005316
Zhao, Gang1b8ec872014-04-21 12:53:02 +08005317 if (!rdev->ops->dump_mpath) {
Jouni Malineneec60b02009-03-20 21:21:19 +02005318 err = -EOPNOTSUPP;
Johannes Bergbba95fe2008-07-29 13:22:51 +02005319 goto out_err;
5320 }
5321
Johannes Berg97990a02013-04-19 01:02:55 +02005322 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) {
Jouni Malineneec60b02009-03-20 21:21:19 +02005323 err = -EOPNOTSUPP;
Roel Kluin0448b5f2009-08-22 21:15:49 +02005324 goto out_err;
Jouni Malineneec60b02009-03-20 21:21:19 +02005325 }
5326
Johannes Bergbba95fe2008-07-29 13:22:51 +02005327 while (1) {
Zhao, Gang1b8ec872014-04-21 12:53:02 +08005328 err = rdev_dump_mpath(rdev, wdev->netdev, path_idx, dst,
Johannes Berg97990a02013-04-19 01:02:55 +02005329 next_hop, &pinfo);
Johannes Bergbba95fe2008-07-29 13:22:51 +02005330 if (err == -ENOENT)
5331 break;
5332 if (err)
Johannes Berg3b858752009-03-12 09:55:09 +01005333 goto out_err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02005334
Eric W. Biederman15e47302012-09-07 20:12:54 +00005335 if (nl80211_send_mpath(skb, NETLINK_CB(cb->skb).portid,
Johannes Bergbba95fe2008-07-29 13:22:51 +02005336 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Johannes Berg97990a02013-04-19 01:02:55 +02005337 wdev->netdev, dst, next_hop,
Johannes Bergbba95fe2008-07-29 13:22:51 +02005338 &pinfo) < 0)
5339 goto out;
5340
5341 path_idx++;
5342 }
5343
Johannes Bergbba95fe2008-07-29 13:22:51 +02005344 out:
Johannes Berg97990a02013-04-19 01:02:55 +02005345 cb->args[2] = path_idx;
Johannes Bergbba95fe2008-07-29 13:22:51 +02005346 err = skb->len;
Johannes Bergbba95fe2008-07-29 13:22:51 +02005347 out_err:
Johannes Bergea90e0d2017-03-15 14:26:04 +01005348 rtnl_unlock();
Johannes Bergbba95fe2008-07-29 13:22:51 +02005349 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005350}
5351
5352static int nl80211_get_mpath(struct sk_buff *skb, struct genl_info *info)
5353{
Johannes Berg4c476992010-10-04 21:36:35 +02005354 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005355 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02005356 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005357 struct mpath_info pinfo;
5358 struct sk_buff *msg;
5359 u8 *dst = NULL;
5360 u8 next_hop[ETH_ALEN];
5361
5362 memset(&pinfo, 0, sizeof(pinfo));
5363
5364 if (!info->attrs[NL80211_ATTR_MAC])
5365 return -EINVAL;
5366
5367 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
5368
Johannes Berg4c476992010-10-04 21:36:35 +02005369 if (!rdev->ops->get_mpath)
5370 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01005371
Johannes Berg4c476992010-10-04 21:36:35 +02005372 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
5373 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02005374
Hila Gonene35e4d22012-06-27 17:19:42 +03005375 err = rdev_get_mpath(rdev, dev, dst, next_hop, &pinfo);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005376 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02005377 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005378
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07005379 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005380 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02005381 return -ENOMEM;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005382
Eric W. Biederman15e47302012-09-07 20:12:54 +00005383 if (nl80211_send_mpath(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berg4c476992010-10-04 21:36:35 +02005384 dev, dst, next_hop, &pinfo) < 0) {
5385 nlmsg_free(msg);
5386 return -ENOBUFS;
5387 }
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005388
Johannes Berg4c476992010-10-04 21:36:35 +02005389 return genlmsg_reply(msg, info);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005390}
5391
5392static int nl80211_set_mpath(struct sk_buff *skb, struct genl_info *info)
5393{
Johannes Berg4c476992010-10-04 21:36:35 +02005394 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5395 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005396 u8 *dst = NULL;
5397 u8 *next_hop = NULL;
5398
5399 if (!info->attrs[NL80211_ATTR_MAC])
5400 return -EINVAL;
5401
5402 if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP])
5403 return -EINVAL;
5404
5405 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
5406 next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]);
5407
Johannes Berg4c476992010-10-04 21:36:35 +02005408 if (!rdev->ops->change_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;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005413
Hila Gonene35e4d22012-06-27 17:19:42 +03005414 return rdev_change_mpath(rdev, dev, dst, next_hop);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005415}
Johannes Berg4c476992010-10-04 21:36:35 +02005416
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005417static int nl80211_new_mpath(struct sk_buff *skb, struct genl_info *info)
5418{
Johannes Berg4c476992010-10-04 21:36:35 +02005419 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5420 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005421 u8 *dst = NULL;
5422 u8 *next_hop = NULL;
5423
5424 if (!info->attrs[NL80211_ATTR_MAC])
5425 return -EINVAL;
5426
5427 if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP])
5428 return -EINVAL;
5429
5430 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
5431 next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]);
5432
Johannes Berg4c476992010-10-04 21:36:35 +02005433 if (!rdev->ops->add_mpath)
5434 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01005435
Johannes Berg4c476992010-10-04 21:36:35 +02005436 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
5437 return -EOPNOTSUPP;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005438
Hila Gonene35e4d22012-06-27 17:19:42 +03005439 return rdev_add_mpath(rdev, dev, dst, next_hop);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005440}
5441
5442static int nl80211_del_mpath(struct sk_buff *skb, struct genl_info *info)
5443{
Johannes Berg4c476992010-10-04 21:36:35 +02005444 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5445 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005446 u8 *dst = NULL;
5447
5448 if (info->attrs[NL80211_ATTR_MAC])
5449 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
5450
Johannes Berg4c476992010-10-04 21:36:35 +02005451 if (!rdev->ops->del_mpath)
5452 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01005453
Hila Gonene35e4d22012-06-27 17:19:42 +03005454 return rdev_del_mpath(rdev, dev, dst);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005455}
5456
Henning Rogge66be7d22014-09-12 08:58:49 +02005457static int nl80211_get_mpp(struct sk_buff *skb, struct genl_info *info)
5458{
5459 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5460 int err;
5461 struct net_device *dev = info->user_ptr[1];
5462 struct mpath_info pinfo;
5463 struct sk_buff *msg;
5464 u8 *dst = NULL;
5465 u8 mpp[ETH_ALEN];
5466
5467 memset(&pinfo, 0, sizeof(pinfo));
5468
5469 if (!info->attrs[NL80211_ATTR_MAC])
5470 return -EINVAL;
5471
5472 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
5473
5474 if (!rdev->ops->get_mpp)
5475 return -EOPNOTSUPP;
5476
5477 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
5478 return -EOPNOTSUPP;
5479
5480 err = rdev_get_mpp(rdev, dev, dst, mpp, &pinfo);
5481 if (err)
5482 return err;
5483
5484 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
5485 if (!msg)
5486 return -ENOMEM;
5487
5488 if (nl80211_send_mpath(msg, info->snd_portid, info->snd_seq, 0,
5489 dev, dst, mpp, &pinfo) < 0) {
5490 nlmsg_free(msg);
5491 return -ENOBUFS;
5492 }
5493
5494 return genlmsg_reply(msg, info);
5495}
5496
5497static int nl80211_dump_mpp(struct sk_buff *skb,
5498 struct netlink_callback *cb)
5499{
5500 struct mpath_info pinfo;
5501 struct cfg80211_registered_device *rdev;
5502 struct wireless_dev *wdev;
5503 u8 dst[ETH_ALEN];
5504 u8 mpp[ETH_ALEN];
5505 int path_idx = cb->args[2];
5506 int err;
5507
Johannes Bergea90e0d2017-03-15 14:26:04 +01005508 rtnl_lock();
Henning Rogge66be7d22014-09-12 08:58:49 +02005509 err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev);
5510 if (err)
Johannes Bergea90e0d2017-03-15 14:26:04 +01005511 goto out_err;
Henning Rogge66be7d22014-09-12 08:58:49 +02005512
5513 if (!rdev->ops->dump_mpp) {
5514 err = -EOPNOTSUPP;
5515 goto out_err;
5516 }
5517
5518 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) {
5519 err = -EOPNOTSUPP;
5520 goto out_err;
5521 }
5522
5523 while (1) {
5524 err = rdev_dump_mpp(rdev, wdev->netdev, path_idx, dst,
5525 mpp, &pinfo);
5526 if (err == -ENOENT)
5527 break;
5528 if (err)
5529 goto out_err;
5530
5531 if (nl80211_send_mpath(skb, NETLINK_CB(cb->skb).portid,
5532 cb->nlh->nlmsg_seq, NLM_F_MULTI,
5533 wdev->netdev, dst, mpp,
5534 &pinfo) < 0)
5535 goto out;
5536
5537 path_idx++;
5538 }
5539
5540 out:
5541 cb->args[2] = path_idx;
5542 err = skb->len;
5543 out_err:
Johannes Bergea90e0d2017-03-15 14:26:04 +01005544 rtnl_unlock();
Henning Rogge66be7d22014-09-12 08:58:49 +02005545 return err;
5546}
5547
Jouni Malinen9f1ba902008-08-07 20:07:01 +03005548static int nl80211_set_bss(struct sk_buff *skb, struct genl_info *info)
5549{
Johannes Berg4c476992010-10-04 21:36:35 +02005550 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5551 struct net_device *dev = info->user_ptr[1];
Simon Wunderlichc56589e2013-11-21 18:19:49 +01005552 struct wireless_dev *wdev = dev->ieee80211_ptr;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03005553 struct bss_parameters params;
Simon Wunderlichc56589e2013-11-21 18:19:49 +01005554 int err;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03005555
5556 memset(&params, 0, sizeof(params));
5557 /* default to not changing parameters */
5558 params.use_cts_prot = -1;
5559 params.use_short_preamble = -1;
5560 params.use_short_slot_time = -1;
Felix Fietkaufd8aaaf2010-04-27 01:23:35 +02005561 params.ap_isolate = -1;
Helmut Schaa50b12f52010-11-19 12:40:25 +01005562 params.ht_opmode = -1;
Johannes Berg53cabad2012-11-14 15:17:28 +01005563 params.p2p_ctwindow = -1;
5564 params.p2p_opp_ps = -1;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03005565
5566 if (info->attrs[NL80211_ATTR_BSS_CTS_PROT])
5567 params.use_cts_prot =
5568 nla_get_u8(info->attrs[NL80211_ATTR_BSS_CTS_PROT]);
5569 if (info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE])
5570 params.use_short_preamble =
5571 nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]);
5572 if (info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME])
5573 params.use_short_slot_time =
5574 nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]);
Jouni Malinen90c97a02008-10-30 16:59:22 +02005575 if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) {
5576 params.basic_rates =
5577 nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
5578 params.basic_rates_len =
5579 nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
5580 }
Felix Fietkaufd8aaaf2010-04-27 01:23:35 +02005581 if (info->attrs[NL80211_ATTR_AP_ISOLATE])
5582 params.ap_isolate = !!nla_get_u8(info->attrs[NL80211_ATTR_AP_ISOLATE]);
Helmut Schaa50b12f52010-11-19 12:40:25 +01005583 if (info->attrs[NL80211_ATTR_BSS_HT_OPMODE])
5584 params.ht_opmode =
5585 nla_get_u16(info->attrs[NL80211_ATTR_BSS_HT_OPMODE]);
Jouni Malinen9f1ba902008-08-07 20:07:01 +03005586
Johannes Berg53cabad2012-11-14 15:17:28 +01005587 if (info->attrs[NL80211_ATTR_P2P_CTWINDOW]) {
5588 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
5589 return -EINVAL;
5590 params.p2p_ctwindow =
5591 nla_get_s8(info->attrs[NL80211_ATTR_P2P_CTWINDOW]);
5592 if (params.p2p_ctwindow < 0)
5593 return -EINVAL;
5594 if (params.p2p_ctwindow != 0 &&
5595 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_CTWIN))
5596 return -EINVAL;
5597 }
5598
5599 if (info->attrs[NL80211_ATTR_P2P_OPPPS]) {
5600 u8 tmp;
5601
5602 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
5603 return -EINVAL;
5604 tmp = nla_get_u8(info->attrs[NL80211_ATTR_P2P_OPPPS]);
5605 if (tmp > 1)
5606 return -EINVAL;
5607 params.p2p_opp_ps = tmp;
5608 if (params.p2p_opp_ps &&
5609 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_OPPPS))
5610 return -EINVAL;
5611 }
5612
Johannes Berg4c476992010-10-04 21:36:35 +02005613 if (!rdev->ops->change_bss)
5614 return -EOPNOTSUPP;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03005615
Johannes Berg074ac8d2010-09-16 14:58:22 +02005616 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
Johannes Berg4c476992010-10-04 21:36:35 +02005617 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
5618 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02005619
Simon Wunderlichc56589e2013-11-21 18:19:49 +01005620 wdev_lock(wdev);
5621 err = rdev_change_bss(rdev, dev, &params);
5622 wdev_unlock(wdev);
5623
5624 return err;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03005625}
5626
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005627static int nl80211_req_set_reg(struct sk_buff *skb, struct genl_info *info)
5628{
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005629 char *data = NULL;
Ilan peer05050752015-03-04 00:32:06 -05005630 bool is_indoor;
Luis R. Rodriguez57b5ce02012-07-12 11:49:18 -07005631 enum nl80211_user_reg_hint_type user_reg_hint_type;
Ilan peer05050752015-03-04 00:32:06 -05005632 u32 owner_nlportid;
5633
Luis R. Rodriguez80778f12009-02-21 00:04:22 -05005634 /*
5635 * You should only get this when cfg80211 hasn't yet initialized
5636 * completely when built-in to the kernel right between the time
5637 * window between nl80211_init() and regulatory_init(), if that is
5638 * even possible.
5639 */
Johannes Berg458f4f92012-12-06 15:47:38 +01005640 if (unlikely(!rcu_access_pointer(cfg80211_regdomain)))
Luis R. Rodriguezfe33eb32009-02-21 00:04:30 -05005641 return -EINPROGRESS;
Luis R. Rodriguez80778f12009-02-21 00:04:22 -05005642
Luis R. Rodriguez57b5ce02012-07-12 11:49:18 -07005643 if (info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE])
5644 user_reg_hint_type =
5645 nla_get_u32(info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE]);
5646 else
5647 user_reg_hint_type = NL80211_USER_REG_HINT_USER;
5648
5649 switch (user_reg_hint_type) {
5650 case NL80211_USER_REG_HINT_USER:
5651 case NL80211_USER_REG_HINT_CELL_BASE:
Ilan Peer52616f22014-02-25 16:26:00 +02005652 if (!info->attrs[NL80211_ATTR_REG_ALPHA2])
5653 return -EINVAL;
5654
5655 data = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]);
5656 return regulatory_hint_user(data, user_reg_hint_type);
5657 case NL80211_USER_REG_HINT_INDOOR:
Ilan peer05050752015-03-04 00:32:06 -05005658 if (info->attrs[NL80211_ATTR_SOCKET_OWNER]) {
5659 owner_nlportid = info->snd_portid;
5660 is_indoor = !!info->attrs[NL80211_ATTR_REG_INDOOR];
5661 } else {
5662 owner_nlportid = 0;
5663 is_indoor = true;
5664 }
5665
5666 return regulatory_hint_indoor(is_indoor, owner_nlportid);
Luis R. Rodriguez57b5ce02012-07-12 11:49:18 -07005667 default:
5668 return -EINVAL;
5669 }
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005670}
5671
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005672static int nl80211_get_mesh_config(struct sk_buff *skb,
Johannes Berg29cbe682010-12-03 09:20:44 +01005673 struct genl_info *info)
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005674{
Johannes Berg4c476992010-10-04 21:36:35 +02005675 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg4c476992010-10-04 21:36:35 +02005676 struct net_device *dev = info->user_ptr[1];
Johannes Berg29cbe682010-12-03 09:20:44 +01005677 struct wireless_dev *wdev = dev->ieee80211_ptr;
5678 struct mesh_config cur_params;
5679 int err = 0;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005680 void *hdr;
5681 struct nlattr *pinfoattr;
5682 struct sk_buff *msg;
5683
Johannes Berg29cbe682010-12-03 09:20:44 +01005684 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT)
5685 return -EOPNOTSUPP;
5686
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005687 if (!rdev->ops->get_mesh_config)
Johannes Berg4c476992010-10-04 21:36:35 +02005688 return -EOPNOTSUPP;
Jouni Malinenf3f92582009-03-20 17:57:36 +02005689
Johannes Berg29cbe682010-12-03 09:20:44 +01005690 wdev_lock(wdev);
5691 /* If not connected, get default parameters */
5692 if (!wdev->mesh_id_len)
5693 memcpy(&cur_params, &default_mesh_config, sizeof(cur_params));
5694 else
Hila Gonene35e4d22012-06-27 17:19:42 +03005695 err = rdev_get_mesh_config(rdev, dev, &cur_params);
Johannes Berg29cbe682010-12-03 09:20:44 +01005696 wdev_unlock(wdev);
5697
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005698 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02005699 return err;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005700
5701 /* Draw up a netlink message to send back */
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07005702 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02005703 if (!msg)
5704 return -ENOMEM;
Eric W. Biederman15e47302012-09-07 20:12:54 +00005705 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005706 NL80211_CMD_GET_MESH_CONFIG);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005707 if (!hdr)
Julia Lawallefe1cf02011-01-28 15:17:11 +01005708 goto out;
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005709 pinfoattr = nla_nest_start(msg, NL80211_ATTR_MESH_CONFIG);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005710 if (!pinfoattr)
5711 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04005712 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
5713 nla_put_u16(msg, NL80211_MESHCONF_RETRY_TIMEOUT,
5714 cur_params.dot11MeshRetryTimeout) ||
5715 nla_put_u16(msg, NL80211_MESHCONF_CONFIRM_TIMEOUT,
5716 cur_params.dot11MeshConfirmTimeout) ||
5717 nla_put_u16(msg, NL80211_MESHCONF_HOLDING_TIMEOUT,
5718 cur_params.dot11MeshHoldingTimeout) ||
5719 nla_put_u16(msg, NL80211_MESHCONF_MAX_PEER_LINKS,
5720 cur_params.dot11MeshMaxPeerLinks) ||
5721 nla_put_u8(msg, NL80211_MESHCONF_MAX_RETRIES,
5722 cur_params.dot11MeshMaxRetries) ||
5723 nla_put_u8(msg, NL80211_MESHCONF_TTL,
5724 cur_params.dot11MeshTTL) ||
5725 nla_put_u8(msg, NL80211_MESHCONF_ELEMENT_TTL,
5726 cur_params.element_ttl) ||
5727 nla_put_u8(msg, NL80211_MESHCONF_AUTO_OPEN_PLINKS,
5728 cur_params.auto_open_plinks) ||
John W. Linville7eab0f62012-04-12 14:25:14 -04005729 nla_put_u32(msg, NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR,
5730 cur_params.dot11MeshNbrOffsetMaxNeighbor) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04005731 nla_put_u8(msg, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES,
5732 cur_params.dot11MeshHWMPmaxPREQretries) ||
5733 nla_put_u32(msg, NL80211_MESHCONF_PATH_REFRESH_TIME,
5734 cur_params.path_refresh_time) ||
5735 nla_put_u16(msg, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT,
5736 cur_params.min_discovery_timeout) ||
5737 nla_put_u32(msg, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT,
5738 cur_params.dot11MeshHWMPactivePathTimeout) ||
5739 nla_put_u16(msg, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL,
5740 cur_params.dot11MeshHWMPpreqMinInterval) ||
5741 nla_put_u16(msg, NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL,
5742 cur_params.dot11MeshHWMPperrMinInterval) ||
5743 nla_put_u16(msg, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME,
5744 cur_params.dot11MeshHWMPnetDiameterTraversalTime) ||
5745 nla_put_u8(msg, NL80211_MESHCONF_HWMP_ROOTMODE,
5746 cur_params.dot11MeshHWMPRootMode) ||
5747 nla_put_u16(msg, NL80211_MESHCONF_HWMP_RANN_INTERVAL,
5748 cur_params.dot11MeshHWMPRannInterval) ||
5749 nla_put_u8(msg, NL80211_MESHCONF_GATE_ANNOUNCEMENTS,
5750 cur_params.dot11MeshGateAnnouncementProtocol) ||
5751 nla_put_u8(msg, NL80211_MESHCONF_FORWARDING,
5752 cur_params.dot11MeshForwarding) ||
Masashi Honma335d5342017-03-16 10:57:17 +09005753 nla_put_s32(msg, NL80211_MESHCONF_RSSI_THRESHOLD,
Ashok Nagarajan70c33ea2012-04-30 14:20:32 -07005754 cur_params.rssi_threshold) ||
5755 nla_put_u32(msg, NL80211_MESHCONF_HT_OPMODE,
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08005756 cur_params.ht_opmode) ||
5757 nla_put_u32(msg, NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT,
5758 cur_params.dot11MeshHWMPactivePathToRootTimeout) ||
5759 nla_put_u16(msg, NL80211_MESHCONF_HWMP_ROOT_INTERVAL,
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +08005760 cur_params.dot11MeshHWMProotInterval) ||
5761 nla_put_u16(msg, NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL,
Marco Porsch3b1c5a52013-01-07 16:04:52 +01005762 cur_params.dot11MeshHWMPconfirmationInterval) ||
5763 nla_put_u32(msg, NL80211_MESHCONF_POWER_MODE,
5764 cur_params.power_mode) ||
5765 nla_put_u16(msg, NL80211_MESHCONF_AWAKE_WINDOW,
Colleen Twitty8e7c0532013-06-03 09:53:39 -07005766 cur_params.dot11MeshAwakeWindowDuration) ||
5767 nla_put_u32(msg, NL80211_MESHCONF_PLINK_TIMEOUT,
5768 cur_params.plink_timeout))
David S. Miller9360ffd2012-03-29 04:41:26 -04005769 goto nla_put_failure;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005770 nla_nest_end(msg, pinfoattr);
5771 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02005772 return genlmsg_reply(msg, info);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005773
Johannes Berg3b858752009-03-12 09:55:09 +01005774 nla_put_failure:
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005775 genlmsg_cancel(msg, hdr);
Julia Lawallefe1cf02011-01-28 15:17:11 +01005776 out:
Yuri Ershovd080e272010-06-29 15:08:07 +04005777 nlmsg_free(msg);
Johannes Berg4c476992010-10-04 21:36:35 +02005778 return -ENOBUFS;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005779}
5780
Alexey Dobriyanb54452b2010-02-18 08:14:31 +00005781static const struct nla_policy nl80211_meshconf_params_policy[NL80211_MESHCONF_ATTR_MAX+1] = {
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005782 [NL80211_MESHCONF_RETRY_TIMEOUT] = { .type = NLA_U16 },
5783 [NL80211_MESHCONF_CONFIRM_TIMEOUT] = { .type = NLA_U16 },
5784 [NL80211_MESHCONF_HOLDING_TIMEOUT] = { .type = NLA_U16 },
5785 [NL80211_MESHCONF_MAX_PEER_LINKS] = { .type = NLA_U16 },
5786 [NL80211_MESHCONF_MAX_RETRIES] = { .type = NLA_U8 },
5787 [NL80211_MESHCONF_TTL] = { .type = NLA_U8 },
Javier Cardona45904f22010-12-03 09:20:40 +01005788 [NL80211_MESHCONF_ELEMENT_TTL] = { .type = NLA_U8 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005789 [NL80211_MESHCONF_AUTO_OPEN_PLINKS] = { .type = NLA_U8 },
Javier Cardonad299a1f2012-03-31 11:31:33 -07005790 [NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR] = { .type = NLA_U32 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005791 [NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES] = { .type = NLA_U8 },
5792 [NL80211_MESHCONF_PATH_REFRESH_TIME] = { .type = NLA_U32 },
5793 [NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT] = { .type = NLA_U16 },
5794 [NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT] = { .type = NLA_U32 },
5795 [NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL] = { .type = NLA_U16 },
Thomas Pedersendca7e942011-11-24 17:15:24 -08005796 [NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL] = { .type = NLA_U16 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005797 [NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME] = { .type = NLA_U16 },
Javier Cardona699403d2011-08-09 16:45:09 -07005798 [NL80211_MESHCONF_HWMP_ROOTMODE] = { .type = NLA_U8 },
Javier Cardona0507e152011-08-09 16:45:10 -07005799 [NL80211_MESHCONF_HWMP_RANN_INTERVAL] = { .type = NLA_U16 },
Javier Cardona16dd7262011-08-09 16:45:11 -07005800 [NL80211_MESHCONF_GATE_ANNOUNCEMENTS] = { .type = NLA_U8 },
Chun-Yeow Yeoh94f90652012-01-21 01:02:16 +08005801 [NL80211_MESHCONF_FORWARDING] = { .type = NLA_U8 },
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005802 [NL80211_MESHCONF_RSSI_THRESHOLD] = { .type = NLA_U32 },
5803 [NL80211_MESHCONF_HT_OPMODE] = { .type = NLA_U16 },
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08005804 [NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT] = { .type = NLA_U32 },
5805 [NL80211_MESHCONF_HWMP_ROOT_INTERVAL] = { .type = NLA_U16 },
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +08005806 [NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL] = { .type = NLA_U16 },
Marco Porsch3b1c5a52013-01-07 16:04:52 +01005807 [NL80211_MESHCONF_POWER_MODE] = { .type = NLA_U32 },
5808 [NL80211_MESHCONF_AWAKE_WINDOW] = { .type = NLA_U16 },
Colleen Twitty8e7c0532013-06-03 09:53:39 -07005809 [NL80211_MESHCONF_PLINK_TIMEOUT] = { .type = NLA_U32 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005810};
5811
Javier Cardonac80d5452010-12-16 17:37:49 -08005812static const struct nla_policy
5813 nl80211_mesh_setup_params_policy[NL80211_MESH_SETUP_ATTR_MAX+1] = {
Javier Cardonad299a1f2012-03-31 11:31:33 -07005814 [NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC] = { .type = NLA_U8 },
Javier Cardonac80d5452010-12-16 17:37:49 -08005815 [NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL] = { .type = NLA_U8 },
5816 [NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC] = { .type = NLA_U8 },
Javier Cardona15d5dda2011-04-07 15:08:28 -07005817 [NL80211_MESH_SETUP_USERSPACE_AUTH] = { .type = NLA_FLAG },
Colleen Twitty6e16d902013-05-08 11:45:59 -07005818 [NL80211_MESH_SETUP_AUTH_PROTOCOL] = { .type = NLA_U8 },
Thomas Pedersenbb2798d2013-03-04 13:06:10 -08005819 [NL80211_MESH_SETUP_USERSPACE_MPM] = { .type = NLA_FLAG },
Javier Cardona581a8b02011-04-07 15:08:27 -07005820 [NL80211_MESH_SETUP_IE] = { .type = NLA_BINARY,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005821 .len = IEEE80211_MAX_DATA_LEN },
Javier Cardonab130e5c2011-05-03 16:57:07 -07005822 [NL80211_MESH_SETUP_USERSPACE_AMPE] = { .type = NLA_FLAG },
Javier Cardonac80d5452010-12-16 17:37:49 -08005823};
5824
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005825static int nl80211_check_bool(const struct nlattr *nla, u8 min, u8 max, bool *out)
5826{
5827 u8 val = nla_get_u8(nla);
5828 if (val < min || val > max)
5829 return -EINVAL;
5830 *out = val;
5831 return 0;
5832}
5833
5834static int nl80211_check_u8(const struct nlattr *nla, u8 min, u8 max, u8 *out)
5835{
5836 u8 val = nla_get_u8(nla);
5837 if (val < min || val > max)
5838 return -EINVAL;
5839 *out = val;
5840 return 0;
5841}
5842
5843static int nl80211_check_u16(const struct nlattr *nla, u16 min, u16 max, u16 *out)
5844{
5845 u16 val = nla_get_u16(nla);
5846 if (val < min || val > max)
5847 return -EINVAL;
5848 *out = val;
5849 return 0;
5850}
5851
5852static int nl80211_check_u32(const struct nlattr *nla, u32 min, u32 max, u32 *out)
5853{
5854 u32 val = nla_get_u32(nla);
5855 if (val < min || val > max)
5856 return -EINVAL;
5857 *out = val;
5858 return 0;
5859}
5860
5861static int nl80211_check_s32(const struct nlattr *nla, s32 min, s32 max, s32 *out)
5862{
5863 s32 val = nla_get_s32(nla);
5864 if (val < min || val > max)
5865 return -EINVAL;
5866 *out = val;
5867 return 0;
5868}
5869
Johannes Bergff9a71a2016-08-11 14:59:53 +02005870static int nl80211_check_power_mode(const struct nlattr *nla,
5871 enum nl80211_mesh_power_mode min,
5872 enum nl80211_mesh_power_mode max,
5873 enum nl80211_mesh_power_mode *out)
5874{
5875 u32 val = nla_get_u32(nla);
5876 if (val < min || val > max)
5877 return -EINVAL;
5878 *out = val;
5879 return 0;
5880}
5881
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005882static int nl80211_parse_mesh_config(struct genl_info *info,
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005883 struct mesh_config *cfg,
5884 u32 *mask_out)
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005885{
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005886 struct nlattr *tb[NL80211_MESHCONF_ATTR_MAX + 1];
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005887 u32 mask = 0;
Masashi Honma97572352016-08-03 10:07:44 +09005888 u16 ht_opmode;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005889
Marco Porschea54fba2013-01-07 16:04:48 +01005890#define FILL_IN_MESH_PARAM_IF_SET(tb, cfg, param, min, max, mask, attr, fn) \
5891do { \
5892 if (tb[attr]) { \
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005893 if (fn(tb[attr], min, max, &cfg->param)) \
Marco Porschea54fba2013-01-07 16:04:48 +01005894 return -EINVAL; \
Marco Porschea54fba2013-01-07 16:04:48 +01005895 mask |= (1 << (attr - 1)); \
5896 } \
5897} while (0)
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005898
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005899 if (!info->attrs[NL80211_ATTR_MESH_CONFIG])
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005900 return -EINVAL;
5901 if (nla_parse_nested(tb, NL80211_MESHCONF_ATTR_MAX,
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005902 info->attrs[NL80211_ATTR_MESH_CONFIG],
Johannes Bergfe521452017-04-12 14:34:08 +02005903 nl80211_meshconf_params_policy, info->extack))
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005904 return -EINVAL;
5905
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005906 /* This makes sure that there aren't more than 32 mesh config
5907 * parameters (otherwise our bitfield scheme would not work.) */
5908 BUILD_BUG_ON(NL80211_MESHCONF_ATTR_MAX > 32);
5909
5910 /* Fill in the params struct */
Marco Porschea54fba2013-01-07 16:04:48 +01005911 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshRetryTimeout, 1, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005912 mask, NL80211_MESHCONF_RETRY_TIMEOUT,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005913 nl80211_check_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01005914 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshConfirmTimeout, 1, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005915 mask, NL80211_MESHCONF_CONFIRM_TIMEOUT,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005916 nl80211_check_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01005917 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHoldingTimeout, 1, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005918 mask, NL80211_MESHCONF_HOLDING_TIMEOUT,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005919 nl80211_check_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01005920 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxPeerLinks, 0, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005921 mask, NL80211_MESHCONF_MAX_PEER_LINKS,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005922 nl80211_check_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01005923 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxRetries, 0, 16,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005924 mask, NL80211_MESHCONF_MAX_RETRIES,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005925 nl80211_check_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01005926 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshTTL, 1, 255,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005927 mask, NL80211_MESHCONF_TTL, nl80211_check_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01005928 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, element_ttl, 1, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005929 mask, NL80211_MESHCONF_ELEMENT_TTL,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005930 nl80211_check_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01005931 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, auto_open_plinks, 0, 1,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005932 mask, NL80211_MESHCONF_AUTO_OPEN_PLINKS,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005933 nl80211_check_bool);
Marco Porschea54fba2013-01-07 16:04:48 +01005934 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshNbrOffsetMaxNeighbor,
5935 1, 255, mask,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005936 NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005937 nl80211_check_u32);
Marco Porschea54fba2013-01-07 16:04:48 +01005938 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPmaxPREQretries, 0, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005939 mask, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005940 nl80211_check_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01005941 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, path_refresh_time, 1, 65535,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005942 mask, NL80211_MESHCONF_PATH_REFRESH_TIME,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005943 nl80211_check_u32);
Marco Porschea54fba2013-01-07 16:04:48 +01005944 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, min_discovery_timeout, 1, 65535,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005945 mask, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005946 nl80211_check_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01005947 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathTimeout,
5948 1, 65535, mask,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005949 NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005950 nl80211_check_u32);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005951 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPpreqMinInterval,
Marco Porschea54fba2013-01-07 16:04:48 +01005952 1, 65535, mask,
5953 NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005954 nl80211_check_u16);
Thomas Pedersendca7e942011-11-24 17:15:24 -08005955 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPperrMinInterval,
Marco Porschea54fba2013-01-07 16:04:48 +01005956 1, 65535, mask,
5957 NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005958 nl80211_check_u16);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005959 FILL_IN_MESH_PARAM_IF_SET(tb, cfg,
Marco Porschea54fba2013-01-07 16:04:48 +01005960 dot11MeshHWMPnetDiameterTraversalTime,
5961 1, 65535, mask,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005962 NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME,
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, dot11MeshHWMPRootMode, 0, 4,
5965 mask, NL80211_MESHCONF_HWMP_ROOTMODE,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005966 nl80211_check_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01005967 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRannInterval, 1, 65535,
5968 mask, NL80211_MESHCONF_HWMP_RANN_INTERVAL,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005969 nl80211_check_u16);
Rui Paulo63c57232009-11-09 23:46:57 +00005970 FILL_IN_MESH_PARAM_IF_SET(tb, cfg,
Marco Porschea54fba2013-01-07 16:04:48 +01005971 dot11MeshGateAnnouncementProtocol, 0, 1,
5972 mask, NL80211_MESHCONF_GATE_ANNOUNCEMENTS,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005973 nl80211_check_bool);
Marco Porschea54fba2013-01-07 16:04:48 +01005974 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshForwarding, 0, 1,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005975 mask, NL80211_MESHCONF_FORWARDING,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005976 nl80211_check_bool);
Chun-Yeow Yeoh83374fe2013-07-11 18:24:03 +08005977 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, rssi_threshold, -255, 0,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005978 mask, NL80211_MESHCONF_RSSI_THRESHOLD,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005979 nl80211_check_s32);
Masashi Honma97572352016-08-03 10:07:44 +09005980 /*
5981 * Check HT operation mode based on
5982 * IEEE 802.11 2012 8.4.2.59 HT Operation element.
5983 */
5984 if (tb[NL80211_MESHCONF_HT_OPMODE]) {
5985 ht_opmode = nla_get_u16(tb[NL80211_MESHCONF_HT_OPMODE]);
5986
5987 if (ht_opmode & ~(IEEE80211_HT_OP_MODE_PROTECTION |
5988 IEEE80211_HT_OP_MODE_NON_GF_STA_PRSNT |
5989 IEEE80211_HT_OP_MODE_NON_HT_STA_PRSNT))
5990 return -EINVAL;
5991
5992 if ((ht_opmode & IEEE80211_HT_OP_MODE_NON_GF_STA_PRSNT) &&
5993 (ht_opmode & IEEE80211_HT_OP_MODE_NON_HT_STA_PRSNT))
5994 return -EINVAL;
5995
5996 switch (ht_opmode & IEEE80211_HT_OP_MODE_PROTECTION) {
5997 case IEEE80211_HT_OP_MODE_PROTECTION_NONE:
5998 case IEEE80211_HT_OP_MODE_PROTECTION_20MHZ:
5999 if (ht_opmode & IEEE80211_HT_OP_MODE_NON_HT_STA_PRSNT)
6000 return -EINVAL;
6001 break;
6002 case IEEE80211_HT_OP_MODE_PROTECTION_NONMEMBER:
6003 case IEEE80211_HT_OP_MODE_PROTECTION_NONHT_MIXED:
6004 if (!(ht_opmode & IEEE80211_HT_OP_MODE_NON_HT_STA_PRSNT))
6005 return -EINVAL;
6006 break;
6007 }
6008 cfg->ht_opmode = ht_opmode;
Masashi Honmafd551ba2017-01-26 08:56:13 +09006009 mask |= (1 << (NL80211_MESHCONF_HT_OPMODE - 1));
Masashi Honma97572352016-08-03 10:07:44 +09006010 }
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08006011 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathToRootTimeout,
Marco Porschea54fba2013-01-07 16:04:48 +01006012 1, 65535, mask,
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08006013 NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02006014 nl80211_check_u32);
Marco Porschea54fba2013-01-07 16:04:48 +01006015 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMProotInterval, 1, 65535,
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08006016 mask, NL80211_MESHCONF_HWMP_ROOT_INTERVAL,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02006017 nl80211_check_u16);
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +08006018 FILL_IN_MESH_PARAM_IF_SET(tb, cfg,
Marco Porschea54fba2013-01-07 16:04:48 +01006019 dot11MeshHWMPconfirmationInterval,
6020 1, 65535, mask,
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +08006021 NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02006022 nl80211_check_u16);
Marco Porsch3b1c5a52013-01-07 16:04:52 +01006023 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, power_mode,
6024 NL80211_MESH_POWER_ACTIVE,
6025 NL80211_MESH_POWER_MAX,
6026 mask, NL80211_MESHCONF_POWER_MODE,
Johannes Bergff9a71a2016-08-11 14:59:53 +02006027 nl80211_check_power_mode);
Marco Porsch3b1c5a52013-01-07 16:04:52 +01006028 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshAwakeWindowDuration,
6029 0, 65535, mask,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02006030 NL80211_MESHCONF_AWAKE_WINDOW, nl80211_check_u16);
Masashi Honma31f909a2015-02-24 22:42:16 +09006031 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, plink_timeout, 0, 0xffffffff,
Colleen Twitty8e7c0532013-06-03 09:53:39 -07006032 mask, NL80211_MESHCONF_PLINK_TIMEOUT,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02006033 nl80211_check_u32);
Johannes Bergbd90fdc2010-12-03 09:20:43 +01006034 if (mask_out)
6035 *mask_out = mask;
Javier Cardonac80d5452010-12-16 17:37:49 -08006036
Johannes Bergbd90fdc2010-12-03 09:20:43 +01006037 return 0;
6038
6039#undef FILL_IN_MESH_PARAM_IF_SET
6040}
6041
Javier Cardonac80d5452010-12-16 17:37:49 -08006042static int nl80211_parse_mesh_setup(struct genl_info *info,
6043 struct mesh_setup *setup)
6044{
Thomas Pedersenbb2798d2013-03-04 13:06:10 -08006045 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Javier Cardonac80d5452010-12-16 17:37:49 -08006046 struct nlattr *tb[NL80211_MESH_SETUP_ATTR_MAX + 1];
6047
6048 if (!info->attrs[NL80211_ATTR_MESH_SETUP])
6049 return -EINVAL;
6050 if (nla_parse_nested(tb, NL80211_MESH_SETUP_ATTR_MAX,
6051 info->attrs[NL80211_ATTR_MESH_SETUP],
Johannes Bergfe521452017-04-12 14:34:08 +02006052 nl80211_mesh_setup_params_policy, info->extack))
Javier Cardonac80d5452010-12-16 17:37:49 -08006053 return -EINVAL;
6054
Javier Cardonad299a1f2012-03-31 11:31:33 -07006055 if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC])
6056 setup->sync_method =
6057 (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC])) ?
6058 IEEE80211_SYNC_METHOD_VENDOR :
6059 IEEE80211_SYNC_METHOD_NEIGHBOR_OFFSET;
6060
Javier Cardonac80d5452010-12-16 17:37:49 -08006061 if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL])
6062 setup->path_sel_proto =
6063 (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL])) ?
6064 IEEE80211_PATH_PROTOCOL_VENDOR :
6065 IEEE80211_PATH_PROTOCOL_HWMP;
6066
6067 if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC])
6068 setup->path_metric =
6069 (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC])) ?
6070 IEEE80211_PATH_METRIC_VENDOR :
6071 IEEE80211_PATH_METRIC_AIRTIME;
6072
Javier Cardona581a8b02011-04-07 15:08:27 -07006073 if (tb[NL80211_MESH_SETUP_IE]) {
Javier Cardonac80d5452010-12-16 17:37:49 -08006074 struct nlattr *ieattr =
Javier Cardona581a8b02011-04-07 15:08:27 -07006075 tb[NL80211_MESH_SETUP_IE];
Javier Cardonac80d5452010-12-16 17:37:49 -08006076 if (!is_valid_ie_attr(ieattr))
6077 return -EINVAL;
Javier Cardona581a8b02011-04-07 15:08:27 -07006078 setup->ie = nla_data(ieattr);
6079 setup->ie_len = nla_len(ieattr);
Javier Cardonac80d5452010-12-16 17:37:49 -08006080 }
Thomas Pedersenbb2798d2013-03-04 13:06:10 -08006081 if (tb[NL80211_MESH_SETUP_USERSPACE_MPM] &&
6082 !(rdev->wiphy.features & NL80211_FEATURE_USERSPACE_MPM))
6083 return -EINVAL;
6084 setup->user_mpm = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_MPM]);
Javier Cardonab130e5c2011-05-03 16:57:07 -07006085 setup->is_authenticated = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AUTH]);
6086 setup->is_secure = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AMPE]);
Thomas Pedersenbb2798d2013-03-04 13:06:10 -08006087 if (setup->is_secure)
6088 setup->user_mpm = true;
Javier Cardonac80d5452010-12-16 17:37:49 -08006089
Colleen Twitty6e16d902013-05-08 11:45:59 -07006090 if (tb[NL80211_MESH_SETUP_AUTH_PROTOCOL]) {
6091 if (!setup->user_mpm)
6092 return -EINVAL;
6093 setup->auth_id =
6094 nla_get_u8(tb[NL80211_MESH_SETUP_AUTH_PROTOCOL]);
6095 }
6096
Javier Cardonac80d5452010-12-16 17:37:49 -08006097 return 0;
6098}
6099
Javier Cardona24bdd9f2010-12-16 17:37:48 -08006100static int nl80211_update_mesh_config(struct sk_buff *skb,
Johannes Berg29cbe682010-12-03 09:20:44 +01006101 struct genl_info *info)
Johannes Bergbd90fdc2010-12-03 09:20:43 +01006102{
6103 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6104 struct net_device *dev = info->user_ptr[1];
Johannes Berg29cbe682010-12-03 09:20:44 +01006105 struct wireless_dev *wdev = dev->ieee80211_ptr;
Johannes Bergbd90fdc2010-12-03 09:20:43 +01006106 struct mesh_config cfg;
6107 u32 mask;
6108 int err;
6109
Johannes Berg29cbe682010-12-03 09:20:44 +01006110 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT)
6111 return -EOPNOTSUPP;
6112
Javier Cardona24bdd9f2010-12-16 17:37:48 -08006113 if (!rdev->ops->update_mesh_config)
Johannes Bergbd90fdc2010-12-03 09:20:43 +01006114 return -EOPNOTSUPP;
6115
Javier Cardona24bdd9f2010-12-16 17:37:48 -08006116 err = nl80211_parse_mesh_config(info, &cfg, &mask);
Johannes Bergbd90fdc2010-12-03 09:20:43 +01006117 if (err)
6118 return err;
6119
Johannes Berg29cbe682010-12-03 09:20:44 +01006120 wdev_lock(wdev);
6121 if (!wdev->mesh_id_len)
6122 err = -ENOLINK;
6123
6124 if (!err)
Hila Gonene35e4d22012-06-27 17:19:42 +03006125 err = rdev_update_mesh_config(rdev, dev, mask, &cfg);
Johannes Berg29cbe682010-12-03 09:20:44 +01006126
6127 wdev_unlock(wdev);
6128
6129 return err;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07006130}
6131
Arik Nemtsovad30ca22014-12-15 19:25:59 +02006132static int nl80211_put_regdom(const struct ieee80211_regdomain *regdom,
6133 struct sk_buff *msg)
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08006134{
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08006135 struct nlattr *nl_reg_rules;
6136 unsigned int i;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08006137
Johannes Berg458f4f92012-12-06 15:47:38 +01006138 if (nla_put_string(msg, NL80211_ATTR_REG_ALPHA2, regdom->alpha2) ||
6139 (regdom->dfs_region &&
6140 nla_put_u8(msg, NL80211_ATTR_DFS_REGION, regdom->dfs_region)))
Arik Nemtsovad30ca22014-12-15 19:25:59 +02006141 goto nla_put_failure;
Johannes Berg458f4f92012-12-06 15:47:38 +01006142
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08006143 nl_reg_rules = nla_nest_start(msg, NL80211_ATTR_REG_RULES);
6144 if (!nl_reg_rules)
Arik Nemtsovad30ca22014-12-15 19:25:59 +02006145 goto nla_put_failure;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08006146
Johannes Berg458f4f92012-12-06 15:47:38 +01006147 for (i = 0; i < regdom->n_reg_rules; i++) {
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08006148 struct nlattr *nl_reg_rule;
6149 const struct ieee80211_reg_rule *reg_rule;
6150 const struct ieee80211_freq_range *freq_range;
6151 const struct ieee80211_power_rule *power_rule;
Janusz Dziedzic97524822014-01-30 09:52:20 +01006152 unsigned int max_bandwidth_khz;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08006153
Johannes Berg458f4f92012-12-06 15:47:38 +01006154 reg_rule = &regdom->reg_rules[i];
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08006155 freq_range = &reg_rule->freq_range;
6156 power_rule = &reg_rule->power_rule;
6157
6158 nl_reg_rule = nla_nest_start(msg, i);
6159 if (!nl_reg_rule)
Arik Nemtsovad30ca22014-12-15 19:25:59 +02006160 goto nla_put_failure;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08006161
Janusz Dziedzic97524822014-01-30 09:52:20 +01006162 max_bandwidth_khz = freq_range->max_bandwidth_khz;
6163 if (!max_bandwidth_khz)
6164 max_bandwidth_khz = reg_get_max_bandwidth(regdom,
6165 reg_rule);
6166
David S. Miller9360ffd2012-03-29 04:41:26 -04006167 if (nla_put_u32(msg, NL80211_ATTR_REG_RULE_FLAGS,
6168 reg_rule->flags) ||
6169 nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_START,
6170 freq_range->start_freq_khz) ||
6171 nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_END,
6172 freq_range->end_freq_khz) ||
6173 nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_MAX_BW,
Janusz Dziedzic97524822014-01-30 09:52:20 +01006174 max_bandwidth_khz) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04006175 nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN,
6176 power_rule->max_antenna_gain) ||
6177 nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_EIRP,
Janusz Dziedzic089027e2014-02-21 19:46:12 +01006178 power_rule->max_eirp) ||
6179 nla_put_u32(msg, NL80211_ATTR_DFS_CAC_TIME,
6180 reg_rule->dfs_cac_ms))
Arik Nemtsovad30ca22014-12-15 19:25:59 +02006181 goto nla_put_failure;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08006182
6183 nla_nest_end(msg, nl_reg_rule);
6184 }
6185
6186 nla_nest_end(msg, nl_reg_rules);
Arik Nemtsovad30ca22014-12-15 19:25:59 +02006187 return 0;
6188
6189nla_put_failure:
6190 return -EMSGSIZE;
6191}
6192
6193static int nl80211_get_reg_do(struct sk_buff *skb, struct genl_info *info)
6194{
6195 const struct ieee80211_regdomain *regdom = NULL;
6196 struct cfg80211_registered_device *rdev;
6197 struct wiphy *wiphy = NULL;
6198 struct sk_buff *msg;
6199 void *hdr;
6200
6201 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
6202 if (!msg)
6203 return -ENOBUFS;
6204
6205 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
6206 NL80211_CMD_GET_REG);
6207 if (!hdr)
6208 goto put_failure;
6209
6210 if (info->attrs[NL80211_ATTR_WIPHY]) {
Arik Nemtsov1bdd7162014-12-15 19:26:01 +02006211 bool self_managed;
6212
Arik Nemtsovad30ca22014-12-15 19:25:59 +02006213 rdev = cfg80211_get_dev_from_info(genl_info_net(info), info);
6214 if (IS_ERR(rdev)) {
6215 nlmsg_free(msg);
6216 return PTR_ERR(rdev);
6217 }
6218
6219 wiphy = &rdev->wiphy;
Arik Nemtsov1bdd7162014-12-15 19:26:01 +02006220 self_managed = wiphy->regulatory_flags &
6221 REGULATORY_WIPHY_SELF_MANAGED;
Arik Nemtsovad30ca22014-12-15 19:25:59 +02006222 regdom = get_wiphy_regdom(wiphy);
6223
Arik Nemtsov1bdd7162014-12-15 19:26:01 +02006224 /* a self-managed-reg device must have a private regdom */
6225 if (WARN_ON(!regdom && self_managed)) {
6226 nlmsg_free(msg);
6227 return -EINVAL;
6228 }
6229
Arik Nemtsovad30ca22014-12-15 19:25:59 +02006230 if (regdom &&
6231 nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy)))
6232 goto nla_put_failure;
6233 }
6234
6235 if (!wiphy && reg_last_request_cell_base() &&
6236 nla_put_u32(msg, NL80211_ATTR_USER_REG_HINT_TYPE,
6237 NL80211_USER_REG_HINT_CELL_BASE))
6238 goto nla_put_failure;
6239
6240 rcu_read_lock();
6241
6242 if (!regdom)
6243 regdom = rcu_dereference(cfg80211_regdomain);
6244
6245 if (nl80211_put_regdom(regdom, msg))
6246 goto nla_put_failure_rcu;
6247
6248 rcu_read_unlock();
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08006249
6250 genlmsg_end(msg, hdr);
Johannes Berg5fe231e2013-05-08 21:45:15 +02006251 return genlmsg_reply(msg, info);
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08006252
Johannes Berg458f4f92012-12-06 15:47:38 +01006253nla_put_failure_rcu:
6254 rcu_read_unlock();
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08006255nla_put_failure:
6256 genlmsg_cancel(msg, hdr);
Julia Lawallefe1cf02011-01-28 15:17:11 +01006257put_failure:
Yuri Ershovd080e272010-06-29 15:08:07 +04006258 nlmsg_free(msg);
Johannes Berg5fe231e2013-05-08 21:45:15 +02006259 return -EMSGSIZE;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08006260}
6261
Arik Nemtsovad30ca22014-12-15 19:25:59 +02006262static int nl80211_send_regdom(struct sk_buff *msg, struct netlink_callback *cb,
6263 u32 seq, int flags, struct wiphy *wiphy,
6264 const struct ieee80211_regdomain *regdom)
6265{
6266 void *hdr = nl80211hdr_put(msg, NETLINK_CB(cb->skb).portid, seq, flags,
6267 NL80211_CMD_GET_REG);
6268
6269 if (!hdr)
6270 return -1;
6271
6272 genl_dump_check_consistent(cb, hdr, &nl80211_fam);
6273
6274 if (nl80211_put_regdom(regdom, msg))
6275 goto nla_put_failure;
6276
6277 if (!wiphy && reg_last_request_cell_base() &&
6278 nla_put_u32(msg, NL80211_ATTR_USER_REG_HINT_TYPE,
6279 NL80211_USER_REG_HINT_CELL_BASE))
6280 goto nla_put_failure;
6281
6282 if (wiphy &&
6283 nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy)))
6284 goto nla_put_failure;
6285
Arik Nemtsov1bdd7162014-12-15 19:26:01 +02006286 if (wiphy && wiphy->regulatory_flags & REGULATORY_WIPHY_SELF_MANAGED &&
6287 nla_put_flag(msg, NL80211_ATTR_WIPHY_SELF_MANAGED_REG))
6288 goto nla_put_failure;
6289
Johannes Berg053c0952015-01-16 22:09:00 +01006290 genlmsg_end(msg, hdr);
6291 return 0;
Arik Nemtsovad30ca22014-12-15 19:25:59 +02006292
6293nla_put_failure:
6294 genlmsg_cancel(msg, hdr);
6295 return -EMSGSIZE;
6296}
6297
6298static int nl80211_get_reg_dump(struct sk_buff *skb,
6299 struct netlink_callback *cb)
6300{
6301 const struct ieee80211_regdomain *regdom = NULL;
6302 struct cfg80211_registered_device *rdev;
6303 int err, reg_idx, start = cb->args[2];
6304
6305 rtnl_lock();
6306
6307 if (cfg80211_regdomain && start == 0) {
6308 err = nl80211_send_regdom(skb, cb, cb->nlh->nlmsg_seq,
6309 NLM_F_MULTI, NULL,
6310 rtnl_dereference(cfg80211_regdomain));
6311 if (err < 0)
6312 goto out_err;
6313 }
6314
6315 /* the global regdom is idx 0 */
6316 reg_idx = 1;
6317 list_for_each_entry(rdev, &cfg80211_rdev_list, list) {
6318 regdom = get_wiphy_regdom(&rdev->wiphy);
6319 if (!regdom)
6320 continue;
6321
6322 if (++reg_idx <= start)
6323 continue;
6324
6325 err = nl80211_send_regdom(skb, cb, cb->nlh->nlmsg_seq,
6326 NLM_F_MULTI, &rdev->wiphy, regdom);
6327 if (err < 0) {
6328 reg_idx--;
6329 break;
6330 }
6331 }
6332
6333 cb->args[2] = reg_idx;
6334 err = skb->len;
6335out_err:
6336 rtnl_unlock();
6337 return err;
6338}
6339
Johannes Bergb6863032015-10-15 09:25:18 +02006340#ifdef CONFIG_CFG80211_CRDA_SUPPORT
6341static const struct nla_policy reg_rule_policy[NL80211_REG_RULE_ATTR_MAX + 1] = {
6342 [NL80211_ATTR_REG_RULE_FLAGS] = { .type = NLA_U32 },
6343 [NL80211_ATTR_FREQ_RANGE_START] = { .type = NLA_U32 },
6344 [NL80211_ATTR_FREQ_RANGE_END] = { .type = NLA_U32 },
6345 [NL80211_ATTR_FREQ_RANGE_MAX_BW] = { .type = NLA_U32 },
6346 [NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN] = { .type = NLA_U32 },
6347 [NL80211_ATTR_POWER_RULE_MAX_EIRP] = { .type = NLA_U32 },
6348 [NL80211_ATTR_DFS_CAC_TIME] = { .type = NLA_U32 },
6349};
6350
6351static int parse_reg_rule(struct nlattr *tb[],
6352 struct ieee80211_reg_rule *reg_rule)
6353{
6354 struct ieee80211_freq_range *freq_range = &reg_rule->freq_range;
6355 struct ieee80211_power_rule *power_rule = &reg_rule->power_rule;
6356
6357 if (!tb[NL80211_ATTR_REG_RULE_FLAGS])
6358 return -EINVAL;
6359 if (!tb[NL80211_ATTR_FREQ_RANGE_START])
6360 return -EINVAL;
6361 if (!tb[NL80211_ATTR_FREQ_RANGE_END])
6362 return -EINVAL;
6363 if (!tb[NL80211_ATTR_FREQ_RANGE_MAX_BW])
6364 return -EINVAL;
6365 if (!tb[NL80211_ATTR_POWER_RULE_MAX_EIRP])
6366 return -EINVAL;
6367
6368 reg_rule->flags = nla_get_u32(tb[NL80211_ATTR_REG_RULE_FLAGS]);
6369
6370 freq_range->start_freq_khz =
6371 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_START]);
6372 freq_range->end_freq_khz =
6373 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_END]);
6374 freq_range->max_bandwidth_khz =
6375 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]);
6376
6377 power_rule->max_eirp =
6378 nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]);
6379
6380 if (tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN])
6381 power_rule->max_antenna_gain =
6382 nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]);
6383
6384 if (tb[NL80211_ATTR_DFS_CAC_TIME])
6385 reg_rule->dfs_cac_ms =
6386 nla_get_u32(tb[NL80211_ATTR_DFS_CAC_TIME]);
6387
6388 return 0;
6389}
6390
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07006391static int nl80211_set_reg(struct sk_buff *skb, struct genl_info *info)
6392{
6393 struct nlattr *tb[NL80211_REG_RULE_ATTR_MAX + 1];
6394 struct nlattr *nl_reg_rule;
Johannes Bergea372c52014-11-28 14:54:31 +01006395 char *alpha2;
6396 int rem_reg_rules, r;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07006397 u32 num_rules = 0, rule_idx = 0, size_of_regd;
Luis R. Rodriguez4c7d3982013-11-13 18:54:02 +01006398 enum nl80211_dfs_regions dfs_region = NL80211_DFS_UNSET;
Johannes Bergea372c52014-11-28 14:54:31 +01006399 struct ieee80211_regdomain *rd;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07006400
6401 if (!info->attrs[NL80211_ATTR_REG_ALPHA2])
6402 return -EINVAL;
6403
6404 if (!info->attrs[NL80211_ATTR_REG_RULES])
6405 return -EINVAL;
6406
6407 alpha2 = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]);
6408
Luis R. Rodriguez8b60b072011-10-11 10:59:02 -07006409 if (info->attrs[NL80211_ATTR_DFS_REGION])
6410 dfs_region = nla_get_u8(info->attrs[NL80211_ATTR_DFS_REGION]);
6411
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07006412 nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES],
Johannes Berg1a919312012-12-03 17:21:11 +01006413 rem_reg_rules) {
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07006414 num_rules++;
6415 if (num_rules > NL80211_MAX_SUPP_REG_RULES)
Luis R. Rodriguez4776c6e2009-05-13 17:04:39 -04006416 return -EINVAL;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07006417 }
6418
Luis R. Rodrigueze4387682013-11-05 09:18:01 -08006419 if (!reg_is_valid_request(alpha2))
6420 return -EINVAL;
6421
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07006422 size_of_regd = sizeof(struct ieee80211_regdomain) +
Johannes Berg1a919312012-12-03 17:21:11 +01006423 num_rules * sizeof(struct ieee80211_reg_rule);
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07006424
6425 rd = kzalloc(size_of_regd, GFP_KERNEL);
Johannes Berg6913b492012-12-04 00:48:59 +01006426 if (!rd)
6427 return -ENOMEM;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07006428
6429 rd->n_reg_rules = num_rules;
6430 rd->alpha2[0] = alpha2[0];
6431 rd->alpha2[1] = alpha2[1];
6432
Luis R. Rodriguez8b60b072011-10-11 10:59:02 -07006433 /*
6434 * Disable DFS master mode if the DFS region was
6435 * not supported or known on this kernel.
6436 */
6437 if (reg_supported_dfs_region(dfs_region))
6438 rd->dfs_region = dfs_region;
6439
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07006440 nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES],
Johannes Berg1a919312012-12-03 17:21:11 +01006441 rem_reg_rules) {
Johannes Bergbfe2c7b2016-10-26 14:42:21 +02006442 r = nla_parse_nested(tb, NL80211_REG_RULE_ATTR_MAX,
Johannes Bergfe521452017-04-12 14:34:08 +02006443 nl_reg_rule, reg_rule_policy,
6444 info->extack);
Johannes Bergae811e22014-01-24 10:17:47 +01006445 if (r)
6446 goto bad_reg;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07006447 r = parse_reg_rule(tb, &rd->reg_rules[rule_idx]);
6448 if (r)
6449 goto bad_reg;
6450
6451 rule_idx++;
6452
Luis R. Rodriguezd0e18f82009-05-13 17:04:40 -04006453 if (rule_idx > NL80211_MAX_SUPP_REG_RULES) {
6454 r = -EINVAL;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07006455 goto bad_reg;
Luis R. Rodriguezd0e18f82009-05-13 17:04:40 -04006456 }
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07006457 }
6458
Johannes Berg06627992016-06-09 10:40:09 +02006459 /* set_regdom takes ownership of rd */
6460 return set_regdom(rd, REGD_SOURCE_CRDA);
Johannes Bergd2372b32008-10-24 20:32:20 +02006461 bad_reg:
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07006462 kfree(rd);
Luis R. Rodriguezd0e18f82009-05-13 17:04:40 -04006463 return r;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07006464}
Johannes Bergb6863032015-10-15 09:25:18 +02006465#endif /* CONFIG_CFG80211_CRDA_SUPPORT */
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07006466
Johannes Berg83f5e2c2009-06-17 17:41:49 +02006467static int validate_scan_freqs(struct nlattr *freqs)
6468{
6469 struct nlattr *attr1, *attr2;
6470 int n_channels = 0, tmp1, tmp2;
6471
6472 nla_for_each_nested(attr1, freqs, tmp1) {
6473 n_channels++;
6474 /*
6475 * Some hardware has a limited channel list for
6476 * scanning, and it is pretty much nonsensical
6477 * to scan for a channel twice, so disallow that
6478 * and don't require drivers to check that the
6479 * channel list they get isn't longer than what
6480 * they can scan, as long as they can scan all
6481 * the channels they registered at once.
6482 */
6483 nla_for_each_nested(attr2, freqs, tmp2)
6484 if (attr1 != attr2 &&
6485 nla_get_u32(attr1) == nla_get_u32(attr2))
6486 return 0;
6487 }
6488
6489 return n_channels;
6490}
6491
Johannes Berg57fbcce2016-04-12 15:56:15 +02006492static bool is_band_valid(struct wiphy *wiphy, enum nl80211_band b)
Arend van Spriel38de03d2016-03-02 20:37:18 +01006493{
Johannes Berg57fbcce2016-04-12 15:56:15 +02006494 return b < NUM_NL80211_BANDS && wiphy->bands[b];
Arend van Spriel38de03d2016-03-02 20:37:18 +01006495}
6496
6497static int parse_bss_select(struct nlattr *nla, struct wiphy *wiphy,
6498 struct cfg80211_bss_selection *bss_select)
6499{
6500 struct nlattr *attr[NL80211_BSS_SELECT_ATTR_MAX + 1];
6501 struct nlattr *nest;
6502 int err;
6503 bool found = false;
6504 int i;
6505
6506 /* only process one nested attribute */
6507 nest = nla_data(nla);
6508 if (!nla_ok(nest, nla_len(nest)))
6509 return -EINVAL;
6510
Johannes Bergbfe2c7b2016-10-26 14:42:21 +02006511 err = nla_parse_nested(attr, NL80211_BSS_SELECT_ATTR_MAX, nest,
Johannes Bergfceb6432017-04-12 14:34:07 +02006512 nl80211_bss_select_policy, NULL);
Arend van Spriel38de03d2016-03-02 20:37:18 +01006513 if (err)
6514 return err;
6515
6516 /* only one attribute may be given */
6517 for (i = 0; i <= NL80211_BSS_SELECT_ATTR_MAX; i++) {
6518 if (attr[i]) {
6519 if (found)
6520 return -EINVAL;
6521 found = true;
6522 }
6523 }
6524
6525 bss_select->behaviour = __NL80211_BSS_SELECT_ATTR_INVALID;
6526
6527 if (attr[NL80211_BSS_SELECT_ATTR_RSSI])
6528 bss_select->behaviour = NL80211_BSS_SELECT_ATTR_RSSI;
6529
6530 if (attr[NL80211_BSS_SELECT_ATTR_BAND_PREF]) {
6531 bss_select->behaviour = NL80211_BSS_SELECT_ATTR_BAND_PREF;
6532 bss_select->param.band_pref =
6533 nla_get_u32(attr[NL80211_BSS_SELECT_ATTR_BAND_PREF]);
6534 if (!is_band_valid(wiphy, bss_select->param.band_pref))
6535 return -EINVAL;
6536 }
6537
6538 if (attr[NL80211_BSS_SELECT_ATTR_RSSI_ADJUST]) {
6539 struct nl80211_bss_select_rssi_adjust *adj_param;
6540
6541 adj_param = nla_data(attr[NL80211_BSS_SELECT_ATTR_RSSI_ADJUST]);
6542 bss_select->behaviour = NL80211_BSS_SELECT_ATTR_RSSI_ADJUST;
6543 bss_select->param.adjust.band = adj_param->band;
6544 bss_select->param.adjust.delta = adj_param->delta;
6545 if (!is_band_valid(wiphy, bss_select->param.adjust.band))
6546 return -EINVAL;
6547 }
6548
6549 /* user-space did not provide behaviour attribute */
6550 if (bss_select->behaviour == __NL80211_BSS_SELECT_ATTR_INVALID)
6551 return -EINVAL;
6552
6553 if (!(wiphy->bss_select_support & BIT(bss_select->behaviour)))
6554 return -EINVAL;
6555
6556 return 0;
6557}
6558
Johannes Bergad2b26a2014-06-12 21:39:05 +02006559static int nl80211_parse_random_mac(struct nlattr **attrs,
6560 u8 *mac_addr, u8 *mac_addr_mask)
6561{
6562 int i;
6563
6564 if (!attrs[NL80211_ATTR_MAC] && !attrs[NL80211_ATTR_MAC_MASK]) {
Joe Perchesd2beae12015-03-02 19:54:58 -08006565 eth_zero_addr(mac_addr);
6566 eth_zero_addr(mac_addr_mask);
Johannes Bergad2b26a2014-06-12 21:39:05 +02006567 mac_addr[0] = 0x2;
6568 mac_addr_mask[0] = 0x3;
6569
6570 return 0;
6571 }
6572
6573 /* need both or none */
6574 if (!attrs[NL80211_ATTR_MAC] || !attrs[NL80211_ATTR_MAC_MASK])
6575 return -EINVAL;
6576
6577 memcpy(mac_addr, nla_data(attrs[NL80211_ATTR_MAC]), ETH_ALEN);
6578 memcpy(mac_addr_mask, nla_data(attrs[NL80211_ATTR_MAC_MASK]), ETH_ALEN);
6579
6580 /* don't allow or configure an mcast address */
6581 if (!is_multicast_ether_addr(mac_addr_mask) ||
6582 is_multicast_ether_addr(mac_addr))
6583 return -EINVAL;
6584
6585 /*
6586 * allow users to pass a MAC address that has bits set outside
6587 * of the mask, but don't bother drivers with having to deal
6588 * with such bits
6589 */
6590 for (i = 0; i < ETH_ALEN; i++)
6591 mac_addr[i] &= mac_addr_mask[i];
6592
6593 return 0;
6594}
6595
Vasanthakumar Thiagarajan34373d12017-02-27 17:04:34 +05306596static bool cfg80211_off_channel_oper_allowed(struct wireless_dev *wdev)
6597{
6598 ASSERT_WDEV_LOCK(wdev);
6599
6600 if (!cfg80211_beaconing_iface_active(wdev))
6601 return true;
6602
6603 if (!(wdev->chandef.chan->flags & IEEE80211_CHAN_RADAR))
6604 return true;
6605
6606 return regulatory_pre_cac_allowed(wdev->wiphy);
6607}
6608
Johannes Berg2a519312009-02-10 21:25:55 +01006609static int nl80211_trigger_scan(struct sk_buff *skb, struct genl_info *info)
6610{
Johannes Berg4c476992010-10-04 21:36:35 +02006611 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Bergfd014282012-06-18 19:17:03 +02006612 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg2a519312009-02-10 21:25:55 +01006613 struct cfg80211_scan_request *request;
Johannes Berg2a519312009-02-10 21:25:55 +01006614 struct nlattr *attr;
6615 struct wiphy *wiphy;
Johannes Berg83f5e2c2009-06-17 17:41:49 +02006616 int err, tmp, n_ssids = 0, n_channels, i;
Jouni Malinen70692ad2009-02-16 19:39:13 +02006617 size_t ie_len;
Johannes Berg2a519312009-02-10 21:25:55 +01006618
Johannes Bergf4a11bb2009-03-27 12:40:28 +01006619 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
6620 return -EINVAL;
6621
Johannes Berg79c97e92009-07-07 03:56:12 +02006622 wiphy = &rdev->wiphy;
Johannes Berg2a519312009-02-10 21:25:55 +01006623
Ayala Bekercb3b7d82016-09-20 17:31:13 +03006624 if (wdev->iftype == NL80211_IFTYPE_NAN)
6625 return -EOPNOTSUPP;
6626
Johannes Berg4c476992010-10-04 21:36:35 +02006627 if (!rdev->ops->scan)
6628 return -EOPNOTSUPP;
Johannes Berg2a519312009-02-10 21:25:55 +01006629
Johannes Bergf9d15d12014-01-22 11:14:19 +02006630 if (rdev->scan_req || rdev->scan_msg) {
Johannes Bergf9f47522013-03-19 15:04:07 +01006631 err = -EBUSY;
6632 goto unlock;
6633 }
Johannes Berg2a519312009-02-10 21:25:55 +01006634
6635 if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
Johannes Berg83f5e2c2009-06-17 17:41:49 +02006636 n_channels = validate_scan_freqs(
6637 info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]);
Johannes Bergf9f47522013-03-19 15:04:07 +01006638 if (!n_channels) {
6639 err = -EINVAL;
6640 goto unlock;
6641 }
Johannes Berg2a519312009-02-10 21:25:55 +01006642 } else {
Ilan Peerbdfbec22014-01-09 11:37:23 +02006643 n_channels = ieee80211_get_num_supported_channels(wiphy);
Johannes Berg2a519312009-02-10 21:25:55 +01006644 }
6645
6646 if (info->attrs[NL80211_ATTR_SCAN_SSIDS])
6647 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp)
6648 n_ssids++;
6649
Johannes Bergf9f47522013-03-19 15:04:07 +01006650 if (n_ssids > wiphy->max_scan_ssids) {
6651 err = -EINVAL;
6652 goto unlock;
6653 }
Johannes Berg2a519312009-02-10 21:25:55 +01006654
Jouni Malinen70692ad2009-02-16 19:39:13 +02006655 if (info->attrs[NL80211_ATTR_IE])
6656 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
6657 else
6658 ie_len = 0;
6659
Johannes Bergf9f47522013-03-19 15:04:07 +01006660 if (ie_len > wiphy->max_scan_ie_len) {
6661 err = -EINVAL;
6662 goto unlock;
6663 }
Johannes Berg18a83652009-03-31 12:12:05 +02006664
Johannes Berg2a519312009-02-10 21:25:55 +01006665 request = kzalloc(sizeof(*request)
Luciano Coelhoa2cd43c2011-05-18 11:42:03 +03006666 + sizeof(*request->ssids) * n_ssids
6667 + sizeof(*request->channels) * n_channels
Jouni Malinen70692ad2009-02-16 19:39:13 +02006668 + ie_len, GFP_KERNEL);
Johannes Bergf9f47522013-03-19 15:04:07 +01006669 if (!request) {
6670 err = -ENOMEM;
6671 goto unlock;
6672 }
Johannes Berg2a519312009-02-10 21:25:55 +01006673
Johannes Berg2a519312009-02-10 21:25:55 +01006674 if (n_ssids)
Johannes Berg5ba63532009-08-07 17:54:07 +02006675 request->ssids = (void *)&request->channels[n_channels];
Johannes Berg2a519312009-02-10 21:25:55 +01006676 request->n_ssids = n_ssids;
Jouni Malinen70692ad2009-02-16 19:39:13 +02006677 if (ie_len) {
Johannes Berg13874e42015-01-23 11:25:20 +01006678 if (n_ssids)
Jouni Malinen70692ad2009-02-16 19:39:13 +02006679 request->ie = (void *)(request->ssids + n_ssids);
6680 else
6681 request->ie = (void *)(request->channels + n_channels);
6682 }
Johannes Berg2a519312009-02-10 21:25:55 +01006683
Johannes Berg584991d2009-11-02 13:32:03 +01006684 i = 0;
Johannes Berg2a519312009-02-10 21:25:55 +01006685 if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
6686 /* user specified, bail out if channel not found */
Johannes Berg2a519312009-02-10 21:25:55 +01006687 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_FREQUENCIES], tmp) {
Johannes Berg584991d2009-11-02 13:32:03 +01006688 struct ieee80211_channel *chan;
6689
6690 chan = ieee80211_get_channel(wiphy, nla_get_u32(attr));
6691
6692 if (!chan) {
Johannes Berg2a519312009-02-10 21:25:55 +01006693 err = -EINVAL;
6694 goto out_free;
6695 }
Johannes Berg584991d2009-11-02 13:32:03 +01006696
6697 /* ignore disabled channels */
6698 if (chan->flags & IEEE80211_CHAN_DISABLED)
6699 continue;
6700
6701 request->channels[i] = chan;
Johannes Berg2a519312009-02-10 21:25:55 +01006702 i++;
6703 }
6704 } else {
Johannes Berg57fbcce2016-04-12 15:56:15 +02006705 enum nl80211_band band;
Johannes Berg34850ab2011-07-18 18:08:35 +02006706
Johannes Berg2a519312009-02-10 21:25:55 +01006707 /* all channels */
Johannes Berg57fbcce2016-04-12 15:56:15 +02006708 for (band = 0; band < NUM_NL80211_BANDS; band++) {
Johannes Berg2a519312009-02-10 21:25:55 +01006709 int j;
Kirtika Ruchandani7a087e72016-05-29 19:51:23 -07006710
Johannes Berg2a519312009-02-10 21:25:55 +01006711 if (!wiphy->bands[band])
6712 continue;
6713 for (j = 0; j < wiphy->bands[band]->n_channels; j++) {
Johannes Berg584991d2009-11-02 13:32:03 +01006714 struct ieee80211_channel *chan;
6715
6716 chan = &wiphy->bands[band]->channels[j];
6717
6718 if (chan->flags & IEEE80211_CHAN_DISABLED)
6719 continue;
6720
6721 request->channels[i] = chan;
Johannes Berg2a519312009-02-10 21:25:55 +01006722 i++;
6723 }
6724 }
6725 }
6726
Johannes Berg584991d2009-11-02 13:32:03 +01006727 if (!i) {
6728 err = -EINVAL;
6729 goto out_free;
6730 }
6731
6732 request->n_channels = i;
6733
Vasanthakumar Thiagarajan34373d12017-02-27 17:04:34 +05306734 wdev_lock(wdev);
6735 if (!cfg80211_off_channel_oper_allowed(wdev)) {
6736 struct ieee80211_channel *chan;
6737
6738 if (request->n_channels != 1) {
6739 wdev_unlock(wdev);
6740 err = -EBUSY;
6741 goto out_free;
6742 }
6743
6744 chan = request->channels[0];
6745 if (chan->center_freq != wdev->chandef.chan->center_freq) {
6746 wdev_unlock(wdev);
6747 err = -EBUSY;
6748 goto out_free;
6749 }
6750 }
6751 wdev_unlock(wdev);
6752
Johannes Berg2a519312009-02-10 21:25:55 +01006753 i = 0;
Johannes Berg13874e42015-01-23 11:25:20 +01006754 if (n_ssids) {
Johannes Berg2a519312009-02-10 21:25:55 +01006755 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) {
Luciano Coelho57a27e12011-06-07 20:42:26 +03006756 if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) {
Johannes Berg2a519312009-02-10 21:25:55 +01006757 err = -EINVAL;
6758 goto out_free;
6759 }
Luciano Coelho57a27e12011-06-07 20:42:26 +03006760 request->ssids[i].ssid_len = nla_len(attr);
Johannes Berg2a519312009-02-10 21:25:55 +01006761 memcpy(request->ssids[i].ssid, nla_data(attr), nla_len(attr));
Johannes Berg2a519312009-02-10 21:25:55 +01006762 i++;
6763 }
6764 }
6765
Jouni Malinen70692ad2009-02-16 19:39:13 +02006766 if (info->attrs[NL80211_ATTR_IE]) {
6767 request->ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Johannes Bergde95a542009-04-01 11:58:36 +02006768 memcpy((void *)request->ie,
6769 nla_data(info->attrs[NL80211_ATTR_IE]),
Jouni Malinen70692ad2009-02-16 19:39:13 +02006770 request->ie_len);
6771 }
6772
Johannes Berg57fbcce2016-04-12 15:56:15 +02006773 for (i = 0; i < NUM_NL80211_BANDS; i++)
Johannes Berga401d2b2011-07-20 00:52:16 +02006774 if (wiphy->bands[i])
6775 request->rates[i] =
6776 (1 << wiphy->bands[i]->n_bitrates) - 1;
Johannes Berg34850ab2011-07-18 18:08:35 +02006777
6778 if (info->attrs[NL80211_ATTR_SCAN_SUPP_RATES]) {
6779 nla_for_each_nested(attr,
6780 info->attrs[NL80211_ATTR_SCAN_SUPP_RATES],
6781 tmp) {
Johannes Berg57fbcce2016-04-12 15:56:15 +02006782 enum nl80211_band band = nla_type(attr);
Johannes Berg34850ab2011-07-18 18:08:35 +02006783
Johannes Berg57fbcce2016-04-12 15:56:15 +02006784 if (band < 0 || band >= NUM_NL80211_BANDS) {
Johannes Berg34850ab2011-07-18 18:08:35 +02006785 err = -EINVAL;
6786 goto out_free;
6787 }
Felix Fietkau1b09cd82013-11-20 19:40:41 +01006788
6789 if (!wiphy->bands[band])
6790 continue;
6791
Johannes Berg34850ab2011-07-18 18:08:35 +02006792 err = ieee80211_get_ratemask(wiphy->bands[band],
6793 nla_data(attr),
6794 nla_len(attr),
6795 &request->rates[band]);
6796 if (err)
6797 goto out_free;
6798 }
6799 }
6800
Avraham Stern1d762502016-07-05 17:10:13 +03006801 if (info->attrs[NL80211_ATTR_MEASUREMENT_DURATION]) {
6802 if (!wiphy_ext_feature_isset(wiphy,
6803 NL80211_EXT_FEATURE_SET_SCAN_DWELL)) {
6804 err = -EOPNOTSUPP;
6805 goto out_free;
6806 }
6807
6808 request->duration =
6809 nla_get_u16(info->attrs[NL80211_ATTR_MEASUREMENT_DURATION]);
6810 request->duration_mandatory =
6811 nla_get_flag(info->attrs[NL80211_ATTR_MEASUREMENT_DURATION_MANDATORY]);
6812 }
6813
Sam Leffler46856bb2012-10-11 21:03:32 -07006814 if (info->attrs[NL80211_ATTR_SCAN_FLAGS]) {
Sam Lefflered4737712012-10-11 21:03:31 -07006815 request->flags = nla_get_u32(
6816 info->attrs[NL80211_ATTR_SCAN_FLAGS]);
Johannes Berg00c3a6e2013-10-26 17:14:38 +02006817 if ((request->flags & NL80211_SCAN_FLAG_LOW_PRIORITY) &&
6818 !(wiphy->features & NL80211_FEATURE_LOW_PRIORITY_SCAN)) {
Sam Leffler46856bb2012-10-11 21:03:32 -07006819 err = -EOPNOTSUPP;
6820 goto out_free;
6821 }
Johannes Bergad2b26a2014-06-12 21:39:05 +02006822
6823 if (request->flags & NL80211_SCAN_FLAG_RANDOM_ADDR) {
6824 if (!(wiphy->features &
6825 NL80211_FEATURE_SCAN_RANDOM_MAC_ADDR)) {
6826 err = -EOPNOTSUPP;
6827 goto out_free;
6828 }
6829
6830 if (wdev->current_bss) {
6831 err = -EOPNOTSUPP;
6832 goto out_free;
6833 }
6834
6835 err = nl80211_parse_random_mac(info->attrs,
6836 request->mac_addr,
6837 request->mac_addr_mask);
6838 if (err)
6839 goto out_free;
6840 }
Sam Leffler46856bb2012-10-11 21:03:32 -07006841 }
Sam Lefflered4737712012-10-11 21:03:31 -07006842
Rajkumar Manoharane9f935e2011-09-25 14:53:30 +05306843 request->no_cck =
6844 nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]);
6845
Vamsi Krishna2fa436b2016-12-02 23:59:08 +02006846 /* Initial implementation used NL80211_ATTR_MAC to set the specific
6847 * BSSID to scan for. This was problematic because that same attribute
6848 * was already used for another purpose (local random MAC address). The
6849 * NL80211_ATTR_BSSID attribute was added to fix this. For backwards
6850 * compatibility with older userspace components, also use the
6851 * NL80211_ATTR_MAC value here if it can be determined to be used for
6852 * the specific BSSID use case instead of the random MAC address
6853 * (NL80211_ATTR_SCAN_FLAGS is used to enable random MAC address use).
6854 */
6855 if (info->attrs[NL80211_ATTR_BSSID])
6856 memcpy(request->bssid,
6857 nla_data(info->attrs[NL80211_ATTR_BSSID]), ETH_ALEN);
6858 else if (!(request->flags & NL80211_SCAN_FLAG_RANDOM_ADDR) &&
6859 info->attrs[NL80211_ATTR_MAC])
Jouni Malinen818965d2016-02-26 22:12:47 +02006860 memcpy(request->bssid, nla_data(info->attrs[NL80211_ATTR_MAC]),
6861 ETH_ALEN);
6862 else
6863 eth_broadcast_addr(request->bssid);
6864
Johannes Bergfd014282012-06-18 19:17:03 +02006865 request->wdev = wdev;
Johannes Berg79c97e92009-07-07 03:56:12 +02006866 request->wiphy = &rdev->wiphy;
Sam Leffler15d60302012-10-11 21:03:34 -07006867 request->scan_start = jiffies;
Johannes Berg2a519312009-02-10 21:25:55 +01006868
Johannes Berg79c97e92009-07-07 03:56:12 +02006869 rdev->scan_req = request;
Hila Gonene35e4d22012-06-27 17:19:42 +03006870 err = rdev_scan(rdev, request);
Johannes Berg2a519312009-02-10 21:25:55 +01006871
Johannes Berg463d0182009-07-14 00:33:35 +02006872 if (!err) {
Johannes Bergfd014282012-06-18 19:17:03 +02006873 nl80211_send_scan_start(rdev, wdev);
6874 if (wdev->netdev)
6875 dev_hold(wdev->netdev);
Johannes Berg4c476992010-10-04 21:36:35 +02006876 } else {
Johannes Berg2a519312009-02-10 21:25:55 +01006877 out_free:
Johannes Berg79c97e92009-07-07 03:56:12 +02006878 rdev->scan_req = NULL;
Johannes Berg2a519312009-02-10 21:25:55 +01006879 kfree(request);
6880 }
Johannes Berg3b858752009-03-12 09:55:09 +01006881
Johannes Bergf9f47522013-03-19 15:04:07 +01006882 unlock:
Johannes Berg2a519312009-02-10 21:25:55 +01006883 return err;
6884}
6885
Vidyullatha Kanchanapally91d3ab42015-10-30 19:14:49 +05306886static int nl80211_abort_scan(struct sk_buff *skb, struct genl_info *info)
6887{
6888 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6889 struct wireless_dev *wdev = info->user_ptr[1];
6890
6891 if (!rdev->ops->abort_scan)
6892 return -EOPNOTSUPP;
6893
6894 if (rdev->scan_msg)
6895 return 0;
6896
6897 if (!rdev->scan_req)
6898 return -ENOENT;
6899
6900 rdev_abort_scan(rdev, wdev);
6901 return 0;
6902}
6903
Avraham Stern3b06d272015-10-12 09:51:34 +03006904static int
6905nl80211_parse_sched_scan_plans(struct wiphy *wiphy, int n_plans,
6906 struct cfg80211_sched_scan_request *request,
6907 struct nlattr **attrs)
6908{
6909 int tmp, err, i = 0;
6910 struct nlattr *attr;
6911
6912 if (!attrs[NL80211_ATTR_SCHED_SCAN_PLANS]) {
6913 u32 interval;
6914
6915 /*
6916 * If scan plans are not specified,
Arend Van Spriel5a88de52016-11-17 09:02:40 +00006917 * %NL80211_ATTR_SCHED_SCAN_INTERVAL will be specified. In this
Avraham Stern3b06d272015-10-12 09:51:34 +03006918 * case one scan plan will be set with the specified scan
6919 * interval and infinite number of iterations.
6920 */
Avraham Stern3b06d272015-10-12 09:51:34 +03006921 interval = nla_get_u32(attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]);
6922 if (!interval)
6923 return -EINVAL;
6924
6925 request->scan_plans[0].interval =
6926 DIV_ROUND_UP(interval, MSEC_PER_SEC);
6927 if (!request->scan_plans[0].interval)
6928 return -EINVAL;
6929
6930 if (request->scan_plans[0].interval >
6931 wiphy->max_sched_scan_plan_interval)
6932 request->scan_plans[0].interval =
6933 wiphy->max_sched_scan_plan_interval;
6934
6935 return 0;
6936 }
6937
6938 nla_for_each_nested(attr, attrs[NL80211_ATTR_SCHED_SCAN_PLANS], tmp) {
6939 struct nlattr *plan[NL80211_SCHED_SCAN_PLAN_MAX + 1];
6940
6941 if (WARN_ON(i >= n_plans))
6942 return -EINVAL;
6943
Johannes Bergbfe2c7b2016-10-26 14:42:21 +02006944 err = nla_parse_nested(plan, NL80211_SCHED_SCAN_PLAN_MAX,
Johannes Bergfceb6432017-04-12 14:34:07 +02006945 attr, nl80211_plan_policy, NULL);
Avraham Stern3b06d272015-10-12 09:51:34 +03006946 if (err)
6947 return err;
6948
6949 if (!plan[NL80211_SCHED_SCAN_PLAN_INTERVAL])
6950 return -EINVAL;
6951
6952 request->scan_plans[i].interval =
6953 nla_get_u32(plan[NL80211_SCHED_SCAN_PLAN_INTERVAL]);
6954 if (!request->scan_plans[i].interval ||
6955 request->scan_plans[i].interval >
6956 wiphy->max_sched_scan_plan_interval)
6957 return -EINVAL;
6958
6959 if (plan[NL80211_SCHED_SCAN_PLAN_ITERATIONS]) {
6960 request->scan_plans[i].iterations =
6961 nla_get_u32(plan[NL80211_SCHED_SCAN_PLAN_ITERATIONS]);
6962 if (!request->scan_plans[i].iterations ||
6963 (request->scan_plans[i].iterations >
6964 wiphy->max_sched_scan_plan_iterations))
6965 return -EINVAL;
6966 } else if (i < n_plans - 1) {
6967 /*
6968 * All scan plans but the last one must specify
6969 * a finite number of iterations
6970 */
6971 return -EINVAL;
6972 }
6973
6974 i++;
6975 }
6976
6977 /*
6978 * The last scan plan must not specify the number of
6979 * iterations, it is supposed to run infinitely
6980 */
6981 if (request->scan_plans[n_plans - 1].iterations)
6982 return -EINVAL;
6983
6984 return 0;
6985}
6986
Luciano Coelho256da022014-11-10 16:13:46 +02006987static struct cfg80211_sched_scan_request *
Johannes Bergad2b26a2014-06-12 21:39:05 +02006988nl80211_parse_sched_scan(struct wiphy *wiphy, struct wireless_dev *wdev,
Arend Van Sprielaad1e812017-01-27 12:27:44 +00006989 struct nlattr **attrs, int max_match_sets)
Luciano Coelho807f8a82011-05-11 17:09:35 +03006990{
6991 struct cfg80211_sched_scan_request *request;
Luciano Coelho807f8a82011-05-11 17:09:35 +03006992 struct nlattr *attr;
Avraham Stern3b06d272015-10-12 09:51:34 +03006993 int err, tmp, n_ssids = 0, n_match_sets = 0, n_channels, i, n_plans = 0;
Johannes Berg57fbcce2016-04-12 15:56:15 +02006994 enum nl80211_band band;
Luciano Coelho807f8a82011-05-11 17:09:35 +03006995 size_t ie_len;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03006996 struct nlattr *tb[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1];
Johannes Bergea73cbc2014-01-24 10:53:53 +01006997 s32 default_match_rssi = NL80211_SCAN_RSSI_THOLD_OFF;
Luciano Coelho807f8a82011-05-11 17:09:35 +03006998
Luciano Coelho256da022014-11-10 16:13:46 +02006999 if (!is_valid_ie_attr(attrs[NL80211_ATTR_IE]))
7000 return ERR_PTR(-EINVAL);
Luciano Coelho807f8a82011-05-11 17:09:35 +03007001
Luciano Coelho256da022014-11-10 16:13:46 +02007002 if (attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
Luciano Coelho807f8a82011-05-11 17:09:35 +03007003 n_channels = validate_scan_freqs(
Luciano Coelho256da022014-11-10 16:13:46 +02007004 attrs[NL80211_ATTR_SCAN_FREQUENCIES]);
Luciano Coelho807f8a82011-05-11 17:09:35 +03007005 if (!n_channels)
Luciano Coelho256da022014-11-10 16:13:46 +02007006 return ERR_PTR(-EINVAL);
Luciano Coelho807f8a82011-05-11 17:09:35 +03007007 } else {
Ilan Peerbdfbec22014-01-09 11:37:23 +02007008 n_channels = ieee80211_get_num_supported_channels(wiphy);
Luciano Coelho807f8a82011-05-11 17:09:35 +03007009 }
7010
Luciano Coelho256da022014-11-10 16:13:46 +02007011 if (attrs[NL80211_ATTR_SCAN_SSIDS])
7012 nla_for_each_nested(attr, attrs[NL80211_ATTR_SCAN_SSIDS],
Luciano Coelho807f8a82011-05-11 17:09:35 +03007013 tmp)
7014 n_ssids++;
7015
Luciano Coelho93b6aa62011-07-13 14:57:28 +03007016 if (n_ssids > wiphy->max_sched_scan_ssids)
Luciano Coelho256da022014-11-10 16:13:46 +02007017 return ERR_PTR(-EINVAL);
Luciano Coelho807f8a82011-05-11 17:09:35 +03007018
Johannes Bergea73cbc2014-01-24 10:53:53 +01007019 /*
7020 * First, count the number of 'real' matchsets. Due to an issue with
7021 * the old implementation, matchsets containing only the RSSI attribute
7022 * (NL80211_SCHED_SCAN_MATCH_ATTR_RSSI) are considered as the 'default'
7023 * RSSI for all matchsets, rather than their own matchset for reporting
7024 * all APs with a strong RSSI. This is needed to be compatible with
7025 * older userspace that treated a matchset with only the RSSI as the
7026 * global RSSI for all other matchsets - if there are other matchsets.
7027 */
Luciano Coelho256da022014-11-10 16:13:46 +02007028 if (attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) {
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03007029 nla_for_each_nested(attr,
Luciano Coelho256da022014-11-10 16:13:46 +02007030 attrs[NL80211_ATTR_SCHED_SCAN_MATCH],
Johannes Bergea73cbc2014-01-24 10:53:53 +01007031 tmp) {
7032 struct nlattr *rssi;
7033
Johannes Bergbfe2c7b2016-10-26 14:42:21 +02007034 err = nla_parse_nested(tb,
7035 NL80211_SCHED_SCAN_MATCH_ATTR_MAX,
Johannes Bergfceb6432017-04-12 14:34:07 +02007036 attr, nl80211_match_policy,
7037 NULL);
Johannes Bergea73cbc2014-01-24 10:53:53 +01007038 if (err)
Luciano Coelho256da022014-11-10 16:13:46 +02007039 return ERR_PTR(err);
Arend Van Spriel3007e352017-04-21 13:05:01 +01007040
7041 /* SSID and BSSID are mutually exclusive */
7042 if (tb[NL80211_SCHED_SCAN_MATCH_ATTR_SSID] &&
7043 tb[NL80211_SCHED_SCAN_MATCH_ATTR_BSSID])
7044 return ERR_PTR(-EINVAL);
7045
Johannes Bergea73cbc2014-01-24 10:53:53 +01007046 /* add other standalone attributes here */
Arend Van Spriel3007e352017-04-21 13:05:01 +01007047 if (tb[NL80211_SCHED_SCAN_MATCH_ATTR_SSID] ||
7048 tb[NL80211_SCHED_SCAN_MATCH_ATTR_BSSID]) {
Johannes Bergea73cbc2014-01-24 10:53:53 +01007049 n_match_sets++;
7050 continue;
7051 }
7052 rssi = tb[NL80211_SCHED_SCAN_MATCH_ATTR_RSSI];
7053 if (rssi)
7054 default_match_rssi = nla_get_s32(rssi);
7055 }
7056 }
7057
7058 /* However, if there's no other matchset, add the RSSI one */
7059 if (!n_match_sets && default_match_rssi != NL80211_SCAN_RSSI_THOLD_OFF)
7060 n_match_sets = 1;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03007061
Arend Van Sprielaad1e812017-01-27 12:27:44 +00007062 if (n_match_sets > max_match_sets)
Luciano Coelho256da022014-11-10 16:13:46 +02007063 return ERR_PTR(-EINVAL);
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03007064
Luciano Coelho256da022014-11-10 16:13:46 +02007065 if (attrs[NL80211_ATTR_IE])
7066 ie_len = nla_len(attrs[NL80211_ATTR_IE]);
Luciano Coelho807f8a82011-05-11 17:09:35 +03007067 else
7068 ie_len = 0;
7069
Luciano Coelho5a865ba2011-07-13 14:57:29 +03007070 if (ie_len > wiphy->max_sched_scan_ie_len)
Luciano Coelho256da022014-11-10 16:13:46 +02007071 return ERR_PTR(-EINVAL);
Luciano Coelhoc10841c2011-06-30 08:32:41 +03007072
Avraham Stern3b06d272015-10-12 09:51:34 +03007073 if (attrs[NL80211_ATTR_SCHED_SCAN_PLANS]) {
7074 /*
7075 * NL80211_ATTR_SCHED_SCAN_INTERVAL must not be specified since
7076 * each scan plan already specifies its own interval
7077 */
7078 if (attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL])
7079 return ERR_PTR(-EINVAL);
7080
7081 nla_for_each_nested(attr,
7082 attrs[NL80211_ATTR_SCHED_SCAN_PLANS], tmp)
7083 n_plans++;
7084 } else {
7085 /*
7086 * The scan interval attribute is kept for backward
7087 * compatibility. If no scan plans are specified and sched scan
7088 * interval is specified, one scan plan will be set with this
7089 * scan interval and infinite number of iterations.
7090 */
7091 if (!attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL])
7092 return ERR_PTR(-EINVAL);
7093
7094 n_plans = 1;
7095 }
7096
7097 if (!n_plans || n_plans > wiphy->max_sched_scan_plans)
7098 return ERR_PTR(-EINVAL);
7099
vamsi krishnabf95ecd2017-01-13 01:12:20 +02007100 if (!wiphy_ext_feature_isset(
7101 wiphy, NL80211_EXT_FEATURE_SCHED_SCAN_RELATIVE_RSSI) &&
7102 (attrs[NL80211_ATTR_SCHED_SCAN_RELATIVE_RSSI] ||
7103 attrs[NL80211_ATTR_SCHED_SCAN_RSSI_ADJUST]))
7104 return ERR_PTR(-EINVAL);
7105
Luciano Coelho807f8a82011-05-11 17:09:35 +03007106 request = kzalloc(sizeof(*request)
Luciano Coelhoa2cd43c2011-05-18 11:42:03 +03007107 + sizeof(*request->ssids) * n_ssids
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03007108 + sizeof(*request->match_sets) * n_match_sets
Avraham Stern3b06d272015-10-12 09:51:34 +03007109 + sizeof(*request->scan_plans) * n_plans
Luciano Coelhoa2cd43c2011-05-18 11:42:03 +03007110 + sizeof(*request->channels) * n_channels
Luciano Coelho807f8a82011-05-11 17:09:35 +03007111 + ie_len, GFP_KERNEL);
Luciano Coelho256da022014-11-10 16:13:46 +02007112 if (!request)
7113 return ERR_PTR(-ENOMEM);
Luciano Coelho807f8a82011-05-11 17:09:35 +03007114
7115 if (n_ssids)
7116 request->ssids = (void *)&request->channels[n_channels];
7117 request->n_ssids = n_ssids;
7118 if (ie_len) {
Johannes Berg13874e42015-01-23 11:25:20 +01007119 if (n_ssids)
Luciano Coelho807f8a82011-05-11 17:09:35 +03007120 request->ie = (void *)(request->ssids + n_ssids);
7121 else
7122 request->ie = (void *)(request->channels + n_channels);
7123 }
7124
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03007125 if (n_match_sets) {
7126 if (request->ie)
7127 request->match_sets = (void *)(request->ie + ie_len);
Johannes Berg13874e42015-01-23 11:25:20 +01007128 else if (n_ssids)
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03007129 request->match_sets =
7130 (void *)(request->ssids + n_ssids);
7131 else
7132 request->match_sets =
7133 (void *)(request->channels + n_channels);
7134 }
7135 request->n_match_sets = n_match_sets;
7136
Avraham Stern3b06d272015-10-12 09:51:34 +03007137 if (n_match_sets)
7138 request->scan_plans = (void *)(request->match_sets +
7139 n_match_sets);
7140 else if (request->ie)
7141 request->scan_plans = (void *)(request->ie + ie_len);
7142 else if (n_ssids)
7143 request->scan_plans = (void *)(request->ssids + n_ssids);
7144 else
7145 request->scan_plans = (void *)(request->channels + n_channels);
7146
7147 request->n_scan_plans = n_plans;
7148
Luciano Coelho807f8a82011-05-11 17:09:35 +03007149 i = 0;
Luciano Coelho256da022014-11-10 16:13:46 +02007150 if (attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
Luciano Coelho807f8a82011-05-11 17:09:35 +03007151 /* user specified, bail out if channel not found */
7152 nla_for_each_nested(attr,
Luciano Coelho256da022014-11-10 16:13:46 +02007153 attrs[NL80211_ATTR_SCAN_FREQUENCIES],
Luciano Coelho807f8a82011-05-11 17:09:35 +03007154 tmp) {
7155 struct ieee80211_channel *chan;
7156
7157 chan = ieee80211_get_channel(wiphy, nla_get_u32(attr));
7158
7159 if (!chan) {
7160 err = -EINVAL;
7161 goto out_free;
7162 }
7163
7164 /* ignore disabled channels */
7165 if (chan->flags & IEEE80211_CHAN_DISABLED)
7166 continue;
7167
7168 request->channels[i] = chan;
7169 i++;
7170 }
7171 } else {
7172 /* all channels */
Johannes Berg57fbcce2016-04-12 15:56:15 +02007173 for (band = 0; band < NUM_NL80211_BANDS; band++) {
Luciano Coelho807f8a82011-05-11 17:09:35 +03007174 int j;
Kirtika Ruchandani7a087e72016-05-29 19:51:23 -07007175
Luciano Coelho807f8a82011-05-11 17:09:35 +03007176 if (!wiphy->bands[band])
7177 continue;
7178 for (j = 0; j < wiphy->bands[band]->n_channels; j++) {
7179 struct ieee80211_channel *chan;
7180
7181 chan = &wiphy->bands[band]->channels[j];
7182
7183 if (chan->flags & IEEE80211_CHAN_DISABLED)
7184 continue;
7185
7186 request->channels[i] = chan;
7187 i++;
7188 }
7189 }
7190 }
7191
7192 if (!i) {
7193 err = -EINVAL;
7194 goto out_free;
7195 }
7196
7197 request->n_channels = i;
7198
7199 i = 0;
Johannes Berg13874e42015-01-23 11:25:20 +01007200 if (n_ssids) {
Luciano Coelho256da022014-11-10 16:13:46 +02007201 nla_for_each_nested(attr, attrs[NL80211_ATTR_SCAN_SSIDS],
Luciano Coelho807f8a82011-05-11 17:09:35 +03007202 tmp) {
Luciano Coelho57a27e12011-06-07 20:42:26 +03007203 if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) {
Luciano Coelho807f8a82011-05-11 17:09:35 +03007204 err = -EINVAL;
7205 goto out_free;
7206 }
Luciano Coelho57a27e12011-06-07 20:42:26 +03007207 request->ssids[i].ssid_len = nla_len(attr);
Luciano Coelho807f8a82011-05-11 17:09:35 +03007208 memcpy(request->ssids[i].ssid, nla_data(attr),
7209 nla_len(attr));
Luciano Coelho807f8a82011-05-11 17:09:35 +03007210 i++;
7211 }
7212 }
7213
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03007214 i = 0;
Luciano Coelho256da022014-11-10 16:13:46 +02007215 if (attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) {
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03007216 nla_for_each_nested(attr,
Luciano Coelho256da022014-11-10 16:13:46 +02007217 attrs[NL80211_ATTR_SCHED_SCAN_MATCH],
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03007218 tmp) {
Arend Van Spriel3007e352017-04-21 13:05:01 +01007219 struct nlattr *ssid, *bssid, *rssi;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03007220
Johannes Bergbfe2c7b2016-10-26 14:42:21 +02007221 err = nla_parse_nested(tb,
7222 NL80211_SCHED_SCAN_MATCH_ATTR_MAX,
Johannes Bergfceb6432017-04-12 14:34:07 +02007223 attr, nl80211_match_policy,
7224 NULL);
Johannes Bergae811e22014-01-24 10:17:47 +01007225 if (err)
7226 goto out_free;
Johannes Berg4a4ab0d2012-06-13 11:17:11 +02007227 ssid = tb[NL80211_SCHED_SCAN_MATCH_ATTR_SSID];
Arend Van Spriel3007e352017-04-21 13:05:01 +01007228 bssid = tb[NL80211_SCHED_SCAN_MATCH_ATTR_BSSID];
7229 if (ssid || bssid) {
Johannes Bergea73cbc2014-01-24 10:53:53 +01007230 if (WARN_ON(i >= n_match_sets)) {
7231 /* this indicates a programming error,
7232 * the loop above should have verified
7233 * things properly
7234 */
7235 err = -EINVAL;
7236 goto out_free;
7237 }
7238
Arend Van Spriel3007e352017-04-21 13:05:01 +01007239 if (ssid) {
7240 if (nla_len(ssid) > IEEE80211_MAX_SSID_LEN) {
7241 err = -EINVAL;
7242 goto out_free;
7243 }
7244 memcpy(request->match_sets[i].ssid.ssid,
7245 nla_data(ssid), nla_len(ssid));
7246 request->match_sets[i].ssid.ssid_len =
7247 nla_len(ssid);
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03007248 }
Arend Van Spriel3007e352017-04-21 13:05:01 +01007249 if (bssid) {
7250 if (nla_len(bssid) != ETH_ALEN) {
7251 err = -EINVAL;
7252 goto out_free;
7253 }
7254 memcpy(request->match_sets[i].bssid,
7255 nla_data(bssid), ETH_ALEN);
7256 }
7257
Kirtika Ruchandani56ab3642016-05-29 19:54:10 -07007258 /* special attribute - old implementation w/a */
Johannes Bergea73cbc2014-01-24 10:53:53 +01007259 request->match_sets[i].rssi_thold =
7260 default_match_rssi;
7261 rssi = tb[NL80211_SCHED_SCAN_MATCH_ATTR_RSSI];
7262 if (rssi)
7263 request->match_sets[i].rssi_thold =
7264 nla_get_s32(rssi);
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03007265 }
7266 i++;
7267 }
Johannes Bergea73cbc2014-01-24 10:53:53 +01007268
7269 /* there was no other matchset, so the RSSI one is alone */
Luciano Coelhof89f46c2014-12-01 11:32:09 +02007270 if (i == 0 && n_match_sets)
Johannes Bergea73cbc2014-01-24 10:53:53 +01007271 request->match_sets[0].rssi_thold = default_match_rssi;
7272
7273 request->min_rssi_thold = INT_MAX;
7274 for (i = 0; i < n_match_sets; i++)
7275 request->min_rssi_thold =
7276 min(request->match_sets[i].rssi_thold,
7277 request->min_rssi_thold);
7278 } else {
7279 request->min_rssi_thold = NL80211_SCAN_RSSI_THOLD_OFF;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03007280 }
7281
Johannes Berg9900e482014-02-04 21:01:25 +01007282 if (ie_len) {
7283 request->ie_len = ie_len;
Luciano Coelho807f8a82011-05-11 17:09:35 +03007284 memcpy((void *)request->ie,
Luciano Coelho256da022014-11-10 16:13:46 +02007285 nla_data(attrs[NL80211_ATTR_IE]),
Luciano Coelho807f8a82011-05-11 17:09:35 +03007286 request->ie_len);
7287 }
7288
Luciano Coelho256da022014-11-10 16:13:46 +02007289 if (attrs[NL80211_ATTR_SCAN_FLAGS]) {
Sam Lefflered4737712012-10-11 21:03:31 -07007290 request->flags = nla_get_u32(
Luciano Coelho256da022014-11-10 16:13:46 +02007291 attrs[NL80211_ATTR_SCAN_FLAGS]);
Johannes Berg00c3a6e2013-10-26 17:14:38 +02007292 if ((request->flags & NL80211_SCAN_FLAG_LOW_PRIORITY) &&
7293 !(wiphy->features & NL80211_FEATURE_LOW_PRIORITY_SCAN)) {
Sam Leffler46856bb2012-10-11 21:03:32 -07007294 err = -EOPNOTSUPP;
7295 goto out_free;
7296 }
Johannes Bergad2b26a2014-06-12 21:39:05 +02007297
7298 if (request->flags & NL80211_SCAN_FLAG_RANDOM_ADDR) {
7299 u32 flg = NL80211_FEATURE_SCHED_SCAN_RANDOM_MAC_ADDR;
7300
7301 if (!wdev) /* must be net-detect */
7302 flg = NL80211_FEATURE_ND_RANDOM_MAC_ADDR;
7303
7304 if (!(wiphy->features & flg)) {
7305 err = -EOPNOTSUPP;
7306 goto out_free;
7307 }
7308
7309 if (wdev && wdev->current_bss) {
7310 err = -EOPNOTSUPP;
7311 goto out_free;
7312 }
7313
7314 err = nl80211_parse_random_mac(attrs, request->mac_addr,
7315 request->mac_addr_mask);
7316 if (err)
7317 goto out_free;
7318 }
Sam Leffler46856bb2012-10-11 21:03:32 -07007319 }
Sam Lefflered4737712012-10-11 21:03:31 -07007320
Luciano Coelho9c748932015-01-16 16:04:09 +02007321 if (attrs[NL80211_ATTR_SCHED_SCAN_DELAY])
7322 request->delay =
7323 nla_get_u32(attrs[NL80211_ATTR_SCHED_SCAN_DELAY]);
7324
vamsi krishnabf95ecd2017-01-13 01:12:20 +02007325 if (attrs[NL80211_ATTR_SCHED_SCAN_RELATIVE_RSSI]) {
7326 request->relative_rssi = nla_get_s8(
7327 attrs[NL80211_ATTR_SCHED_SCAN_RELATIVE_RSSI]);
7328 request->relative_rssi_set = true;
7329 }
7330
7331 if (request->relative_rssi_set &&
7332 attrs[NL80211_ATTR_SCHED_SCAN_RSSI_ADJUST]) {
7333 struct nl80211_bss_select_rssi_adjust *rssi_adjust;
7334
7335 rssi_adjust = nla_data(
7336 attrs[NL80211_ATTR_SCHED_SCAN_RSSI_ADJUST]);
7337 request->rssi_adjust.band = rssi_adjust->band;
7338 request->rssi_adjust.delta = rssi_adjust->delta;
7339 if (!is_band_valid(wiphy, request->rssi_adjust.band)) {
7340 err = -EINVAL;
7341 goto out_free;
7342 }
7343 }
7344
Avraham Stern3b06d272015-10-12 09:51:34 +03007345 err = nl80211_parse_sched_scan_plans(wiphy, n_plans, request, attrs);
7346 if (err)
7347 goto out_free;
7348
Sam Leffler15d60302012-10-11 21:03:34 -07007349 request->scan_start = jiffies;
Luciano Coelho807f8a82011-05-11 17:09:35 +03007350
Luciano Coelho256da022014-11-10 16:13:46 +02007351 return request;
Luciano Coelho807f8a82011-05-11 17:09:35 +03007352
7353out_free:
7354 kfree(request);
Luciano Coelho256da022014-11-10 16:13:46 +02007355 return ERR_PTR(err);
7356}
7357
7358static int nl80211_start_sched_scan(struct sk_buff *skb,
7359 struct genl_info *info)
7360{
7361 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7362 struct net_device *dev = info->user_ptr[1];
Johannes Bergad2b26a2014-06-12 21:39:05 +02007363 struct wireless_dev *wdev = dev->ieee80211_ptr;
Jukka Rissanen31a60ed2014-12-15 13:25:38 +02007364 struct cfg80211_sched_scan_request *sched_scan_req;
Arend Van Sprielca986ad2017-04-21 13:05:00 +01007365 bool want_multi;
Luciano Coelho256da022014-11-10 16:13:46 +02007366 int err;
7367
Arend Van Sprielca986ad2017-04-21 13:05:00 +01007368 if (!rdev->wiphy.max_sched_scan_reqs || !rdev->ops->sched_scan_start)
Luciano Coelho256da022014-11-10 16:13:46 +02007369 return -EOPNOTSUPP;
7370
Arend Van Sprielca986ad2017-04-21 13:05:00 +01007371 want_multi = info->attrs[NL80211_ATTR_SCHED_SCAN_MULTI];
7372 err = cfg80211_sched_scan_req_possible(rdev, want_multi);
7373 if (err)
7374 return err;
Luciano Coelho256da022014-11-10 16:13:46 +02007375
Jukka Rissanen31a60ed2014-12-15 13:25:38 +02007376 sched_scan_req = nl80211_parse_sched_scan(&rdev->wiphy, wdev,
Arend Van Sprielaad1e812017-01-27 12:27:44 +00007377 info->attrs,
7378 rdev->wiphy.max_match_sets);
Jukka Rissanen31a60ed2014-12-15 13:25:38 +02007379
7380 err = PTR_ERR_OR_ZERO(sched_scan_req);
Luciano Coelho256da022014-11-10 16:13:46 +02007381 if (err)
7382 goto out_err;
7383
Arend Van Sprielca986ad2017-04-21 13:05:00 +01007384 /* leave request id zero for legacy request
7385 * or if driver does not support multi-scheduled scan
7386 */
7387 if (want_multi && rdev->wiphy.max_sched_scan_reqs > 1) {
7388 while (!sched_scan_req->reqid)
7389 sched_scan_req->reqid = rdev->wiphy.cookie_counter++;
7390 }
7391
Jukka Rissanen31a60ed2014-12-15 13:25:38 +02007392 err = rdev_sched_scan_start(rdev, dev, sched_scan_req);
Luciano Coelho256da022014-11-10 16:13:46 +02007393 if (err)
7394 goto out_free;
7395
Jukka Rissanen31a60ed2014-12-15 13:25:38 +02007396 sched_scan_req->dev = dev;
7397 sched_scan_req->wiphy = &rdev->wiphy;
7398
Jukka Rissanen93a1e862014-12-15 13:25:39 +02007399 if (info->attrs[NL80211_ATTR_SOCKET_OWNER])
7400 sched_scan_req->owner_nlportid = info->snd_portid;
7401
Arend Van Sprielca986ad2017-04-21 13:05:00 +01007402 cfg80211_add_sched_scan_req(rdev, sched_scan_req);
Luciano Coelho256da022014-11-10 16:13:46 +02007403
Arend Van Spriel96b08fd2017-04-13 13:06:27 +01007404 nl80211_send_sched_scan(sched_scan_req, NL80211_CMD_START_SCHED_SCAN);
Luciano Coelho256da022014-11-10 16:13:46 +02007405 return 0;
7406
7407out_free:
Jukka Rissanen31a60ed2014-12-15 13:25:38 +02007408 kfree(sched_scan_req);
Luciano Coelho256da022014-11-10 16:13:46 +02007409out_err:
Luciano Coelho807f8a82011-05-11 17:09:35 +03007410 return err;
7411}
7412
7413static int nl80211_stop_sched_scan(struct sk_buff *skb,
7414 struct genl_info *info)
7415{
Arend Van Sprielca986ad2017-04-21 13:05:00 +01007416 struct cfg80211_sched_scan_request *req;
Luciano Coelho807f8a82011-05-11 17:09:35 +03007417 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Arend Van Sprielca986ad2017-04-21 13:05:00 +01007418 u64 cookie;
Luciano Coelho807f8a82011-05-11 17:09:35 +03007419
Arend Van Sprielca986ad2017-04-21 13:05:00 +01007420 if (!rdev->wiphy.max_sched_scan_reqs || !rdev->ops->sched_scan_stop)
Luciano Coelho807f8a82011-05-11 17:09:35 +03007421 return -EOPNOTSUPP;
7422
Arend Van Sprielca986ad2017-04-21 13:05:00 +01007423 if (info->attrs[NL80211_ATTR_COOKIE]) {
7424 cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]);
7425 return __cfg80211_stop_sched_scan(rdev, cookie, false);
7426 }
7427
7428 req = list_first_or_null_rcu(&rdev->sched_scan_req_list,
7429 struct cfg80211_sched_scan_request,
7430 list);
7431 if (!req || req->reqid ||
7432 (req->owner_nlportid &&
7433 req->owner_nlportid != info->snd_portid))
7434 return -ENOENT;
7435
7436 return cfg80211_stop_sched_scan_req(rdev, req, false);
Luciano Coelho807f8a82011-05-11 17:09:35 +03007437}
7438
Simon Wunderlich04f39042013-02-08 18:16:19 +01007439static int nl80211_start_radar_detection(struct sk_buff *skb,
7440 struct genl_info *info)
7441{
7442 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7443 struct net_device *dev = info->user_ptr[1];
7444 struct wireless_dev *wdev = dev->ieee80211_ptr;
7445 struct cfg80211_chan_def chandef;
Luis R. Rodriguez55f74352013-11-25 20:56:10 +01007446 enum nl80211_dfs_regions dfs_region;
Janusz Dziedzic31559f32014-02-21 19:46:13 +01007447 unsigned int cac_time_ms;
Simon Wunderlich04f39042013-02-08 18:16:19 +01007448 int err;
7449
Luis R. Rodriguez55f74352013-11-25 20:56:10 +01007450 dfs_region = reg_get_dfs_region(wdev->wiphy);
7451 if (dfs_region == NL80211_DFS_UNSET)
7452 return -EINVAL;
7453
Simon Wunderlich04f39042013-02-08 18:16:19 +01007454 err = nl80211_parse_chandef(rdev, info, &chandef);
7455 if (err)
7456 return err;
7457
Simon Wunderlichff311bc2013-09-03 19:43:18 +02007458 if (netif_carrier_ok(dev))
7459 return -EBUSY;
7460
Simon Wunderlich04f39042013-02-08 18:16:19 +01007461 if (wdev->cac_started)
7462 return -EBUSY;
7463
Luciano Coelho2beb6dab2014-02-18 11:40:36 +02007464 err = cfg80211_chandef_dfs_required(wdev->wiphy, &chandef,
Luciano Coelho00ec75f2014-05-15 13:05:39 +03007465 wdev->iftype);
Simon Wunderlich04f39042013-02-08 18:16:19 +01007466 if (err < 0)
7467 return err;
7468
7469 if (err == 0)
7470 return -EINVAL;
7471
Janusz Dziedzicfe7c3a12013-11-05 14:48:48 +01007472 if (!cfg80211_chandef_dfs_usable(wdev->wiphy, &chandef))
Simon Wunderlich04f39042013-02-08 18:16:19 +01007473 return -EINVAL;
7474
7475 if (!rdev->ops->start_radar_detection)
7476 return -EOPNOTSUPP;
7477
Janusz Dziedzic31559f32014-02-21 19:46:13 +01007478 cac_time_ms = cfg80211_chandef_dfs_cac_time(&rdev->wiphy, &chandef);
7479 if (WARN_ON(!cac_time_ms))
7480 cac_time_ms = IEEE80211_DFS_MIN_CAC_TIME_MS;
7481
Ilan Peera1056b1b2015-10-22 22:27:46 +03007482 err = rdev_start_radar_detection(rdev, dev, &chandef, cac_time_ms);
Simon Wunderlich04f39042013-02-08 18:16:19 +01007483 if (!err) {
Michal Kazior9e0e2962014-01-29 14:22:27 +01007484 wdev->chandef = chandef;
Simon Wunderlich04f39042013-02-08 18:16:19 +01007485 wdev->cac_started = true;
7486 wdev->cac_start_time = jiffies;
Janusz Dziedzic31559f32014-02-21 19:46:13 +01007487 wdev->cac_time_ms = cac_time_ms;
Simon Wunderlich04f39042013-02-08 18:16:19 +01007488 }
Simon Wunderlich04f39042013-02-08 18:16:19 +01007489 return err;
7490}
7491
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02007492static int nl80211_channel_switch(struct sk_buff *skb, struct genl_info *info)
7493{
7494 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7495 struct net_device *dev = info->user_ptr[1];
7496 struct wireless_dev *wdev = dev->ieee80211_ptr;
7497 struct cfg80211_csa_settings params;
7498 /* csa_attrs is defined static to avoid waste of stack size - this
7499 * function is called under RTNL lock, so this should not be a problem.
7500 */
7501 static struct nlattr *csa_attrs[NL80211_ATTR_MAX+1];
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02007502 int err;
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02007503 bool need_new_beacon = false;
Benjamin Berg8d9de162017-05-16 11:23:12 +02007504 bool need_handle_dfs_flag = true;
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03007505 int len, i;
Luciano Coelho252e07c2014-10-08 09:48:34 +03007506 u32 cs_count;
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02007507
7508 if (!rdev->ops->channel_switch ||
7509 !(rdev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH))
7510 return -EOPNOTSUPP;
7511
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02007512 switch (dev->ieee80211_ptr->iftype) {
7513 case NL80211_IFTYPE_AP:
7514 case NL80211_IFTYPE_P2P_GO:
7515 need_new_beacon = true;
Benjamin Berg8d9de162017-05-16 11:23:12 +02007516 /* For all modes except AP the handle_dfs flag needs to be
7517 * supplied to tell the kernel that userspace will handle radar
7518 * events when they happen. Otherwise a switch to a channel
7519 * requiring DFS will be rejected.
7520 */
7521 need_handle_dfs_flag = false;
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02007522
7523 /* useless if AP is not running */
7524 if (!wdev->beacon_interval)
Johannes Berg1ff79df2014-01-22 10:05:27 +01007525 return -ENOTCONN;
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02007526 break;
7527 case NL80211_IFTYPE_ADHOC:
Johannes Berg1ff79df2014-01-22 10:05:27 +01007528 if (!wdev->ssid_len)
7529 return -ENOTCONN;
7530 break;
Chun-Yeow Yeohc6da6742013-10-14 19:08:28 -07007531 case NL80211_IFTYPE_MESH_POINT:
Johannes Berg1ff79df2014-01-22 10:05:27 +01007532 if (!wdev->mesh_id_len)
7533 return -ENOTCONN;
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02007534 break;
7535 default:
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02007536 return -EOPNOTSUPP;
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02007537 }
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02007538
7539 memset(&params, 0, sizeof(params));
7540
7541 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] ||
7542 !info->attrs[NL80211_ATTR_CH_SWITCH_COUNT])
7543 return -EINVAL;
7544
7545 /* only important for AP, IBSS and mesh create IEs internally */
Andrei Otcheretianskid0a361a2013-10-17 10:52:17 +02007546 if (need_new_beacon && !info->attrs[NL80211_ATTR_CSA_IES])
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02007547 return -EINVAL;
7548
Luciano Coelho252e07c2014-10-08 09:48:34 +03007549 /* Even though the attribute is u32, the specification says
7550 * u8, so let's make sure we don't overflow.
7551 */
7552 cs_count = nla_get_u32(info->attrs[NL80211_ATTR_CH_SWITCH_COUNT]);
7553 if (cs_count > 255)
7554 return -EINVAL;
7555
7556 params.count = cs_count;
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02007557
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02007558 if (!need_new_beacon)
7559 goto skip_beacons;
7560
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02007561 err = nl80211_parse_beacon(info->attrs, &params.beacon_after);
7562 if (err)
7563 return err;
7564
7565 err = nla_parse_nested(csa_attrs, NL80211_ATTR_MAX,
7566 info->attrs[NL80211_ATTR_CSA_IES],
Johannes Bergfe521452017-04-12 14:34:08 +02007567 nl80211_policy, info->extack);
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02007568 if (err)
7569 return err;
7570
7571 err = nl80211_parse_beacon(csa_attrs, &params.beacon_csa);
7572 if (err)
7573 return err;
7574
7575 if (!csa_attrs[NL80211_ATTR_CSA_C_OFF_BEACON])
7576 return -EINVAL;
7577
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03007578 len = nla_len(csa_attrs[NL80211_ATTR_CSA_C_OFF_BEACON]);
7579 if (!len || (len % sizeof(u16)))
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02007580 return -EINVAL;
7581
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03007582 params.n_counter_offsets_beacon = len / sizeof(u16);
7583 if (rdev->wiphy.max_num_csa_counters &&
7584 (params.n_counter_offsets_beacon >
7585 rdev->wiphy.max_num_csa_counters))
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02007586 return -EINVAL;
7587
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03007588 params.counter_offsets_beacon =
7589 nla_data(csa_attrs[NL80211_ATTR_CSA_C_OFF_BEACON]);
7590
7591 /* sanity checks - counters should fit and be the same */
7592 for (i = 0; i < params.n_counter_offsets_beacon; i++) {
7593 u16 offset = params.counter_offsets_beacon[i];
7594
7595 if (offset >= params.beacon_csa.tail_len)
7596 return -EINVAL;
7597
7598 if (params.beacon_csa.tail[offset] != params.count)
7599 return -EINVAL;
7600 }
7601
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02007602 if (csa_attrs[NL80211_ATTR_CSA_C_OFF_PRESP]) {
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03007603 len = nla_len(csa_attrs[NL80211_ATTR_CSA_C_OFF_PRESP]);
7604 if (!len || (len % sizeof(u16)))
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02007605 return -EINVAL;
7606
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03007607 params.n_counter_offsets_presp = len / sizeof(u16);
7608 if (rdev->wiphy.max_num_csa_counters &&
Johannes Bergad5987b2016-09-13 15:53:55 +02007609 (params.n_counter_offsets_presp >
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03007610 rdev->wiphy.max_num_csa_counters))
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02007611 return -EINVAL;
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03007612
7613 params.counter_offsets_presp =
7614 nla_data(csa_attrs[NL80211_ATTR_CSA_C_OFF_PRESP]);
7615
7616 /* sanity checks - counters should fit and be the same */
7617 for (i = 0; i < params.n_counter_offsets_presp; i++) {
7618 u16 offset = params.counter_offsets_presp[i];
7619
7620 if (offset >= params.beacon_csa.probe_resp_len)
7621 return -EINVAL;
7622
7623 if (params.beacon_csa.probe_resp[offset] !=
7624 params.count)
7625 return -EINVAL;
7626 }
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02007627 }
7628
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02007629skip_beacons:
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02007630 err = nl80211_parse_chandef(rdev, info, &params.chandef);
7631 if (err)
7632 return err;
7633
Arik Nemtsov923b3522015-07-08 15:41:44 +03007634 if (!cfg80211_reg_can_beacon_relax(&rdev->wiphy, &params.chandef,
7635 wdev->iftype))
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02007636 return -EINVAL;
7637
Luciano Coelho2beb6dab2014-02-18 11:40:36 +02007638 err = cfg80211_chandef_dfs_required(wdev->wiphy,
7639 &params.chandef,
7640 wdev->iftype);
7641 if (err < 0)
7642 return err;
7643
Benjamin Berg8d9de162017-05-16 11:23:12 +02007644 if (err > 0) {
Luciano Coelho2beb6dab2014-02-18 11:40:36 +02007645 params.radar_required = true;
Benjamin Berg8d9de162017-05-16 11:23:12 +02007646 if (need_handle_dfs_flag &&
7647 !nla_get_flag(info->attrs[NL80211_ATTR_HANDLE_DFS])) {
7648 return -EINVAL;
7649 }
7650 }
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02007651
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02007652 if (info->attrs[NL80211_ATTR_CH_SWITCH_BLOCK_TX])
7653 params.block_tx = true;
7654
Simon Wunderlichc56589e2013-11-21 18:19:49 +01007655 wdev_lock(wdev);
7656 err = rdev_channel_switch(rdev, dev, &params);
7657 wdev_unlock(wdev);
7658
7659 return err;
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02007660}
7661
Johannes Berg9720bb32011-06-21 09:45:33 +02007662static int nl80211_send_bss(struct sk_buff *msg, struct netlink_callback *cb,
7663 u32 seq, int flags,
Johannes Berg2a519312009-02-10 21:25:55 +01007664 struct cfg80211_registered_device *rdev,
Johannes Berg48ab9052009-07-10 18:42:31 +02007665 struct wireless_dev *wdev,
7666 struct cfg80211_internal_bss *intbss)
Johannes Berg2a519312009-02-10 21:25:55 +01007667{
Johannes Berg48ab9052009-07-10 18:42:31 +02007668 struct cfg80211_bss *res = &intbss->pub;
Johannes Berg9caf0362012-11-29 01:25:20 +01007669 const struct cfg80211_bss_ies *ies;
Johannes Berg2a519312009-02-10 21:25:55 +01007670 void *hdr;
7671 struct nlattr *bss;
Johannes Berg48ab9052009-07-10 18:42:31 +02007672
7673 ASSERT_WDEV_LOCK(wdev);
Johannes Berg2a519312009-02-10 21:25:55 +01007674
Eric W. Biederman15e47302012-09-07 20:12:54 +00007675 hdr = nl80211hdr_put(msg, NETLINK_CB(cb->skb).portid, seq, flags,
Johannes Berg2a519312009-02-10 21:25:55 +01007676 NL80211_CMD_NEW_SCAN_RESULTS);
7677 if (!hdr)
7678 return -1;
7679
Johannes Berg9720bb32011-06-21 09:45:33 +02007680 genl_dump_check_consistent(cb, hdr, &nl80211_fam);
7681
Johannes Berg97990a02013-04-19 01:02:55 +02007682 if (nla_put_u32(msg, NL80211_ATTR_GENERATION, rdev->bss_generation))
7683 goto nla_put_failure;
7684 if (wdev->netdev &&
David S. Miller9360ffd2012-03-29 04:41:26 -04007685 nla_put_u32(msg, NL80211_ATTR_IFINDEX, wdev->netdev->ifindex))
7686 goto nla_put_failure;
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02007687 if (nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
7688 NL80211_ATTR_PAD))
Johannes Berg97990a02013-04-19 01:02:55 +02007689 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01007690
7691 bss = nla_nest_start(msg, NL80211_ATTR_BSS);
7692 if (!bss)
7693 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04007694 if ((!is_zero_ether_addr(res->bssid) &&
Johannes Berg9caf0362012-11-29 01:25:20 +01007695 nla_put(msg, NL80211_BSS_BSSID, ETH_ALEN, res->bssid)))
David S. Miller9360ffd2012-03-29 04:41:26 -04007696 goto nla_put_failure;
Johannes Berg9caf0362012-11-29 01:25:20 +01007697
7698 rcu_read_lock();
Johannes Berg0e227082014-08-12 20:34:30 +02007699 /* indicate whether we have probe response data or not */
7700 if (rcu_access_pointer(res->proberesp_ies) &&
7701 nla_put_flag(msg, NL80211_BSS_PRESP_DATA))
7702 goto fail_unlock_rcu;
7703
7704 /* this pointer prefers to be pointed to probe response data
7705 * but is always valid
7706 */
Johannes Berg9caf0362012-11-29 01:25:20 +01007707 ies = rcu_dereference(res->ies);
Johannes Berg8cef2c92013-02-05 16:54:31 +01007708 if (ies) {
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02007709 if (nla_put_u64_64bit(msg, NL80211_BSS_TSF, ies->tsf,
7710 NL80211_BSS_PAD))
Johannes Berg8cef2c92013-02-05 16:54:31 +01007711 goto fail_unlock_rcu;
Johannes Berg8cef2c92013-02-05 16:54:31 +01007712 if (ies->len && nla_put(msg, NL80211_BSS_INFORMATION_ELEMENTS,
7713 ies->len, ies->data))
7714 goto fail_unlock_rcu;
Johannes Berg9caf0362012-11-29 01:25:20 +01007715 }
Johannes Berg0e227082014-08-12 20:34:30 +02007716
7717 /* and this pointer is always (unless driver didn't know) beacon data */
Johannes Berg9caf0362012-11-29 01:25:20 +01007718 ies = rcu_dereference(res->beacon_ies);
Johannes Berg0e227082014-08-12 20:34:30 +02007719 if (ies && ies->from_beacon) {
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02007720 if (nla_put_u64_64bit(msg, NL80211_BSS_BEACON_TSF, ies->tsf,
7721 NL80211_BSS_PAD))
Johannes Berg8cef2c92013-02-05 16:54:31 +01007722 goto fail_unlock_rcu;
7723 if (ies->len && nla_put(msg, NL80211_BSS_BEACON_IES,
7724 ies->len, ies->data))
7725 goto fail_unlock_rcu;
Johannes Berg9caf0362012-11-29 01:25:20 +01007726 }
7727 rcu_read_unlock();
7728
David S. Miller9360ffd2012-03-29 04:41:26 -04007729 if (res->beacon_interval &&
7730 nla_put_u16(msg, NL80211_BSS_BEACON_INTERVAL, res->beacon_interval))
7731 goto nla_put_failure;
7732 if (nla_put_u16(msg, NL80211_BSS_CAPABILITY, res->capability) ||
7733 nla_put_u32(msg, NL80211_BSS_FREQUENCY, res->channel->center_freq) ||
Simon Wunderlichdcd6eac2013-07-08 16:55:49 +02007734 nla_put_u32(msg, NL80211_BSS_CHAN_WIDTH, res->scan_width) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04007735 nla_put_u32(msg, NL80211_BSS_SEEN_MS_AGO,
7736 jiffies_to_msecs(jiffies - intbss->ts)))
7737 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01007738
Avraham Stern1d762502016-07-05 17:10:13 +03007739 if (intbss->parent_tsf &&
7740 (nla_put_u64_64bit(msg, NL80211_BSS_PARENT_TSF,
7741 intbss->parent_tsf, NL80211_BSS_PAD) ||
7742 nla_put(msg, NL80211_BSS_PARENT_BSSID, ETH_ALEN,
7743 intbss->parent_bssid)))
7744 goto nla_put_failure;
7745
Dmitry Shmidt6e19bc42015-10-07 11:32:53 +02007746 if (intbss->ts_boottime &&
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02007747 nla_put_u64_64bit(msg, NL80211_BSS_LAST_SEEN_BOOTTIME,
7748 intbss->ts_boottime, NL80211_BSS_PAD))
Dmitry Shmidt6e19bc42015-10-07 11:32:53 +02007749 goto nla_put_failure;
7750
Johannes Berg77965c92009-02-18 18:45:06 +01007751 switch (rdev->wiphy.signal_type) {
Johannes Berg2a519312009-02-10 21:25:55 +01007752 case CFG80211_SIGNAL_TYPE_MBM:
David S. Miller9360ffd2012-03-29 04:41:26 -04007753 if (nla_put_u32(msg, NL80211_BSS_SIGNAL_MBM, res->signal))
7754 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01007755 break;
7756 case CFG80211_SIGNAL_TYPE_UNSPEC:
David S. Miller9360ffd2012-03-29 04:41:26 -04007757 if (nla_put_u8(msg, NL80211_BSS_SIGNAL_UNSPEC, res->signal))
7758 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01007759 break;
7760 default:
7761 break;
7762 }
7763
Johannes Berg48ab9052009-07-10 18:42:31 +02007764 switch (wdev->iftype) {
Johannes Berg074ac8d2010-09-16 14:58:22 +02007765 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Berg48ab9052009-07-10 18:42:31 +02007766 case NL80211_IFTYPE_STATION:
David S. Miller9360ffd2012-03-29 04:41:26 -04007767 if (intbss == wdev->current_bss &&
7768 nla_put_u32(msg, NL80211_BSS_STATUS,
7769 NL80211_BSS_STATUS_ASSOCIATED))
7770 goto nla_put_failure;
Johannes Berg48ab9052009-07-10 18:42:31 +02007771 break;
7772 case NL80211_IFTYPE_ADHOC:
David S. Miller9360ffd2012-03-29 04:41:26 -04007773 if (intbss == wdev->current_bss &&
7774 nla_put_u32(msg, NL80211_BSS_STATUS,
7775 NL80211_BSS_STATUS_IBSS_JOINED))
7776 goto nla_put_failure;
Johannes Berg48ab9052009-07-10 18:42:31 +02007777 break;
7778 default:
7779 break;
7780 }
7781
Johannes Berg2a519312009-02-10 21:25:55 +01007782 nla_nest_end(msg, bss);
7783
Johannes Berg053c0952015-01-16 22:09:00 +01007784 genlmsg_end(msg, hdr);
7785 return 0;
Johannes Berg2a519312009-02-10 21:25:55 +01007786
Johannes Berg8cef2c92013-02-05 16:54:31 +01007787 fail_unlock_rcu:
7788 rcu_read_unlock();
Johannes Berg2a519312009-02-10 21:25:55 +01007789 nla_put_failure:
7790 genlmsg_cancel(msg, hdr);
7791 return -EMSGSIZE;
7792}
7793
Johannes Berg97990a02013-04-19 01:02:55 +02007794static int nl80211_dump_scan(struct sk_buff *skb, struct netlink_callback *cb)
Johannes Berg2a519312009-02-10 21:25:55 +01007795{
Johannes Berg48ab9052009-07-10 18:42:31 +02007796 struct cfg80211_registered_device *rdev;
Johannes Berg2a519312009-02-10 21:25:55 +01007797 struct cfg80211_internal_bss *scan;
Johannes Berg48ab9052009-07-10 18:42:31 +02007798 struct wireless_dev *wdev;
Johannes Berg97990a02013-04-19 01:02:55 +02007799 int start = cb->args[2], idx = 0;
Johannes Berg2a519312009-02-10 21:25:55 +01007800 int err;
7801
Johannes Bergea90e0d2017-03-15 14:26:04 +01007802 rtnl_lock();
Johannes Berg97990a02013-04-19 01:02:55 +02007803 err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev);
Johannes Bergea90e0d2017-03-15 14:26:04 +01007804 if (err) {
7805 rtnl_unlock();
Johannes Berg67748892010-10-04 21:14:06 +02007806 return err;
Johannes Bergea90e0d2017-03-15 14:26:04 +01007807 }
Johannes Berg2a519312009-02-10 21:25:55 +01007808
Johannes Berg48ab9052009-07-10 18:42:31 +02007809 wdev_lock(wdev);
7810 spin_lock_bh(&rdev->bss_lock);
7811 cfg80211_bss_expire(rdev);
7812
Johannes Berg9720bb32011-06-21 09:45:33 +02007813 cb->seq = rdev->bss_generation;
7814
Johannes Berg48ab9052009-07-10 18:42:31 +02007815 list_for_each_entry(scan, &rdev->bss_list, list) {
Johannes Berg2a519312009-02-10 21:25:55 +01007816 if (++idx <= start)
7817 continue;
Johannes Berg9720bb32011-06-21 09:45:33 +02007818 if (nl80211_send_bss(skb, cb,
Johannes Berg2a519312009-02-10 21:25:55 +01007819 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Johannes Berg48ab9052009-07-10 18:42:31 +02007820 rdev, wdev, scan) < 0) {
Johannes Berg2a519312009-02-10 21:25:55 +01007821 idx--;
Johannes Berg67748892010-10-04 21:14:06 +02007822 break;
Johannes Berg2a519312009-02-10 21:25:55 +01007823 }
7824 }
7825
Johannes Berg48ab9052009-07-10 18:42:31 +02007826 spin_unlock_bh(&rdev->bss_lock);
7827 wdev_unlock(wdev);
Johannes Berg2a519312009-02-10 21:25:55 +01007828
Johannes Berg97990a02013-04-19 01:02:55 +02007829 cb->args[2] = idx;
Johannes Bergea90e0d2017-03-15 14:26:04 +01007830 rtnl_unlock();
Johannes Berg2a519312009-02-10 21:25:55 +01007831
Johannes Berg67748892010-10-04 21:14:06 +02007832 return skb->len;
Johannes Berg2a519312009-02-10 21:25:55 +01007833}
7834
Eric W. Biederman15e47302012-09-07 20:12:54 +00007835static int nl80211_send_survey(struct sk_buff *msg, u32 portid, u32 seq,
Johannes Berg11f78ac2014-11-14 16:43:50 +01007836 int flags, struct net_device *dev,
7837 bool allow_radio_stats,
7838 struct survey_info *survey)
Holger Schurig61fa7132009-11-11 12:25:40 +01007839{
7840 void *hdr;
7841 struct nlattr *infoattr;
7842
Johannes Berg11f78ac2014-11-14 16:43:50 +01007843 /* skip radio stats if userspace didn't request them */
7844 if (!survey->channel && !allow_radio_stats)
7845 return 0;
7846
Eric W. Biederman15e47302012-09-07 20:12:54 +00007847 hdr = nl80211hdr_put(msg, portid, seq, flags,
Holger Schurig61fa7132009-11-11 12:25:40 +01007848 NL80211_CMD_NEW_SURVEY_RESULTS);
7849 if (!hdr)
7850 return -ENOMEM;
7851
David S. Miller9360ffd2012-03-29 04:41:26 -04007852 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex))
7853 goto nla_put_failure;
Holger Schurig61fa7132009-11-11 12:25:40 +01007854
7855 infoattr = nla_nest_start(msg, NL80211_ATTR_SURVEY_INFO);
7856 if (!infoattr)
7857 goto nla_put_failure;
7858
Johannes Berg11f78ac2014-11-14 16:43:50 +01007859 if (survey->channel &&
7860 nla_put_u32(msg, NL80211_SURVEY_INFO_FREQUENCY,
David S. Miller9360ffd2012-03-29 04:41:26 -04007861 survey->channel->center_freq))
7862 goto nla_put_failure;
7863
7864 if ((survey->filled & SURVEY_INFO_NOISE_DBM) &&
7865 nla_put_u8(msg, NL80211_SURVEY_INFO_NOISE, survey->noise))
7866 goto nla_put_failure;
7867 if ((survey->filled & SURVEY_INFO_IN_USE) &&
7868 nla_put_flag(msg, NL80211_SURVEY_INFO_IN_USE))
7869 goto nla_put_failure;
Johannes Berg4ed20be2014-11-14 16:35:34 +01007870 if ((survey->filled & SURVEY_INFO_TIME) &&
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02007871 nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME,
7872 survey->time, NL80211_SURVEY_INFO_PAD))
David S. Miller9360ffd2012-03-29 04:41:26 -04007873 goto nla_put_failure;
Johannes Berg4ed20be2014-11-14 16:35:34 +01007874 if ((survey->filled & SURVEY_INFO_TIME_BUSY) &&
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02007875 nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME_BUSY,
7876 survey->time_busy, NL80211_SURVEY_INFO_PAD))
David S. Miller9360ffd2012-03-29 04:41:26 -04007877 goto nla_put_failure;
Johannes Berg4ed20be2014-11-14 16:35:34 +01007878 if ((survey->filled & SURVEY_INFO_TIME_EXT_BUSY) &&
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02007879 nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME_EXT_BUSY,
7880 survey->time_ext_busy, NL80211_SURVEY_INFO_PAD))
David S. Miller9360ffd2012-03-29 04:41:26 -04007881 goto nla_put_failure;
Johannes Berg4ed20be2014-11-14 16:35:34 +01007882 if ((survey->filled & SURVEY_INFO_TIME_RX) &&
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02007883 nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME_RX,
7884 survey->time_rx, NL80211_SURVEY_INFO_PAD))
David S. Miller9360ffd2012-03-29 04:41:26 -04007885 goto nla_put_failure;
Johannes Berg4ed20be2014-11-14 16:35:34 +01007886 if ((survey->filled & SURVEY_INFO_TIME_TX) &&
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02007887 nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME_TX,
7888 survey->time_tx, NL80211_SURVEY_INFO_PAD))
David S. Miller9360ffd2012-03-29 04:41:26 -04007889 goto nla_put_failure;
Johannes Berg052536a2014-11-14 16:44:11 +01007890 if ((survey->filled & SURVEY_INFO_TIME_SCAN) &&
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02007891 nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME_SCAN,
7892 survey->time_scan, NL80211_SURVEY_INFO_PAD))
Johannes Berg052536a2014-11-14 16:44:11 +01007893 goto nla_put_failure;
Holger Schurig61fa7132009-11-11 12:25:40 +01007894
7895 nla_nest_end(msg, infoattr);
7896
Johannes Berg053c0952015-01-16 22:09:00 +01007897 genlmsg_end(msg, hdr);
7898 return 0;
Holger Schurig61fa7132009-11-11 12:25:40 +01007899
7900 nla_put_failure:
7901 genlmsg_cancel(msg, hdr);
7902 return -EMSGSIZE;
7903}
7904
Johannes Berg11f78ac2014-11-14 16:43:50 +01007905static int nl80211_dump_survey(struct sk_buff *skb, struct netlink_callback *cb)
Holger Schurig61fa7132009-11-11 12:25:40 +01007906{
Johannes Bergc90c39d2016-10-24 14:40:01 +02007907 struct nlattr **attrbuf = genl_family_attrbuf(&nl80211_fam);
Holger Schurig61fa7132009-11-11 12:25:40 +01007908 struct survey_info survey;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08007909 struct cfg80211_registered_device *rdev;
Johannes Berg97990a02013-04-19 01:02:55 +02007910 struct wireless_dev *wdev;
7911 int survey_idx = cb->args[2];
Holger Schurig61fa7132009-11-11 12:25:40 +01007912 int res;
Johannes Berg11f78ac2014-11-14 16:43:50 +01007913 bool radio_stats;
Holger Schurig61fa7132009-11-11 12:25:40 +01007914
Johannes Bergea90e0d2017-03-15 14:26:04 +01007915 rtnl_lock();
Zhao, Gang1b8ec872014-04-21 12:53:02 +08007916 res = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev);
Johannes Berg67748892010-10-04 21:14:06 +02007917 if (res)
Johannes Bergea90e0d2017-03-15 14:26:04 +01007918 goto out_err;
Holger Schurig61fa7132009-11-11 12:25:40 +01007919
Johannes Berg11f78ac2014-11-14 16:43:50 +01007920 /* prepare_wdev_dump parsed the attributes */
Johannes Bergc90c39d2016-10-24 14:40:01 +02007921 radio_stats = attrbuf[NL80211_ATTR_SURVEY_RADIO_STATS];
Johannes Berg11f78ac2014-11-14 16:43:50 +01007922
Johannes Berg97990a02013-04-19 01:02:55 +02007923 if (!wdev->netdev) {
7924 res = -EINVAL;
7925 goto out_err;
7926 }
7927
Zhao, Gang1b8ec872014-04-21 12:53:02 +08007928 if (!rdev->ops->dump_survey) {
Holger Schurig61fa7132009-11-11 12:25:40 +01007929 res = -EOPNOTSUPP;
7930 goto out_err;
7931 }
7932
7933 while (1) {
Zhao, Gang1b8ec872014-04-21 12:53:02 +08007934 res = rdev_dump_survey(rdev, wdev->netdev, survey_idx, &survey);
Holger Schurig61fa7132009-11-11 12:25:40 +01007935 if (res == -ENOENT)
7936 break;
7937 if (res)
7938 goto out_err;
7939
Johannes Berg11f78ac2014-11-14 16:43:50 +01007940 /* don't send disabled channels, but do send non-channel data */
7941 if (survey.channel &&
7942 survey.channel->flags & IEEE80211_CHAN_DISABLED) {
Luis R. Rodriguez180cdc72011-05-27 07:24:02 -07007943 survey_idx++;
7944 continue;
7945 }
7946
Holger Schurig61fa7132009-11-11 12:25:40 +01007947 if (nl80211_send_survey(skb,
Eric W. Biederman15e47302012-09-07 20:12:54 +00007948 NETLINK_CB(cb->skb).portid,
Holger Schurig61fa7132009-11-11 12:25:40 +01007949 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Johannes Berg11f78ac2014-11-14 16:43:50 +01007950 wdev->netdev, radio_stats, &survey) < 0)
Holger Schurig61fa7132009-11-11 12:25:40 +01007951 goto out;
7952 survey_idx++;
7953 }
7954
7955 out:
Johannes Berg97990a02013-04-19 01:02:55 +02007956 cb->args[2] = survey_idx;
Holger Schurig61fa7132009-11-11 12:25:40 +01007957 res = skb->len;
7958 out_err:
Johannes Bergea90e0d2017-03-15 14:26:04 +01007959 rtnl_unlock();
Holger Schurig61fa7132009-11-11 12:25:40 +01007960 return res;
7961}
7962
Samuel Ortizb23aa672009-07-01 21:26:54 +02007963static bool nl80211_valid_wpa_versions(u32 wpa_versions)
7964{
7965 return !(wpa_versions & ~(NL80211_WPA_VERSION_1 |
7966 NL80211_WPA_VERSION_2));
7967}
7968
Jouni Malinen636a5d32009-03-19 13:39:22 +02007969static int nl80211_authenticate(struct sk_buff *skb, struct genl_info *info)
7970{
Johannes Berg4c476992010-10-04 21:36:35 +02007971 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7972 struct net_device *dev = info->user_ptr[1];
Johannes Berg19957bb2009-07-02 17:20:43 +02007973 struct ieee80211_channel *chan;
Jouni Malinen11b6b5a2016-10-27 00:41:58 +03007974 const u8 *bssid, *ssid, *ie = NULL, *auth_data = NULL;
7975 int err, ssid_len, ie_len = 0, auth_data_len = 0;
Johannes Berg19957bb2009-07-02 17:20:43 +02007976 enum nl80211_auth_type auth_type;
Johannes Bergfffd0932009-07-08 14:22:54 +02007977 struct key_parse key;
Jouni Malinend5cdfac2010-04-04 09:37:19 +03007978 bool local_state_change;
Jouni Malinen636a5d32009-03-19 13:39:22 +02007979
Johannes Bergf4a11bb2009-03-27 12:40:28 +01007980 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
7981 return -EINVAL;
7982
7983 if (!info->attrs[NL80211_ATTR_MAC])
7984 return -EINVAL;
7985
Jouni Malinen17780922009-03-27 20:52:47 +02007986 if (!info->attrs[NL80211_ATTR_AUTH_TYPE])
7987 return -EINVAL;
7988
Johannes Berg19957bb2009-07-02 17:20:43 +02007989 if (!info->attrs[NL80211_ATTR_SSID])
7990 return -EINVAL;
7991
7992 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ])
7993 return -EINVAL;
7994
Johannes Bergfffd0932009-07-08 14:22:54 +02007995 err = nl80211_parse_key(info, &key);
7996 if (err)
7997 return err;
7998
7999 if (key.idx >= 0) {
Johannes Berge31b8212010-10-05 19:39:30 +02008000 if (key.type != -1 && key.type != NL80211_KEYTYPE_GROUP)
8001 return -EINVAL;
Johannes Bergfffd0932009-07-08 14:22:54 +02008002 if (!key.p.key || !key.p.key_len)
8003 return -EINVAL;
8004 if ((key.p.cipher != WLAN_CIPHER_SUITE_WEP40 ||
8005 key.p.key_len != WLAN_KEY_LEN_WEP40) &&
8006 (key.p.cipher != WLAN_CIPHER_SUITE_WEP104 ||
8007 key.p.key_len != WLAN_KEY_LEN_WEP104))
8008 return -EINVAL;
Johannes Bergb6b55552016-09-13 16:25:58 +02008009 if (key.idx > 3)
Johannes Bergfffd0932009-07-08 14:22:54 +02008010 return -EINVAL;
8011 } else {
8012 key.p.key_len = 0;
8013 key.p.key = NULL;
8014 }
8015
Johannes Bergafea0b72010-08-10 09:46:42 +02008016 if (key.idx >= 0) {
8017 int i;
8018 bool ok = false;
Kirtika Ruchandani7a087e72016-05-29 19:51:23 -07008019
Johannes Bergafea0b72010-08-10 09:46:42 +02008020 for (i = 0; i < rdev->wiphy.n_cipher_suites; i++) {
8021 if (key.p.cipher == rdev->wiphy.cipher_suites[i]) {
8022 ok = true;
8023 break;
8024 }
8025 }
Johannes Berg4c476992010-10-04 21:36:35 +02008026 if (!ok)
8027 return -EINVAL;
Johannes Bergafea0b72010-08-10 09:46:42 +02008028 }
8029
Johannes Berg4c476992010-10-04 21:36:35 +02008030 if (!rdev->ops->auth)
8031 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02008032
Johannes Berg074ac8d2010-09-16 14:58:22 +02008033 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02008034 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
8035 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02008036
Johannes Berg19957bb2009-07-02 17:20:43 +02008037 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen664834d2014-01-15 00:01:44 +02008038 chan = nl80211_get_valid_chan(&rdev->wiphy,
8039 info->attrs[NL80211_ATTR_WIPHY_FREQ]);
8040 if (!chan)
Johannes Berg4c476992010-10-04 21:36:35 +02008041 return -EINVAL;
Jouni Malinen636a5d32009-03-19 13:39:22 +02008042
Johannes Berg19957bb2009-07-02 17:20:43 +02008043 ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
8044 ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
8045
8046 if (info->attrs[NL80211_ATTR_IE]) {
8047 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
8048 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
8049 }
8050
8051 auth_type = nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]);
Jouni Malinene39e5b52012-09-30 19:29:39 +03008052 if (!nl80211_valid_auth_type(rdev, auth_type, NL80211_CMD_AUTHENTICATE))
Johannes Berg4c476992010-10-04 21:36:35 +02008053 return -EINVAL;
Johannes Berg19957bb2009-07-02 17:20:43 +02008054
Jouni Malinen63181062016-10-27 00:42:02 +03008055 if ((auth_type == NL80211_AUTHTYPE_SAE ||
8056 auth_type == NL80211_AUTHTYPE_FILS_SK ||
8057 auth_type == NL80211_AUTHTYPE_FILS_SK_PFS ||
8058 auth_type == NL80211_AUTHTYPE_FILS_PK) &&
Jouni Malinen11b6b5a2016-10-27 00:41:58 +03008059 !info->attrs[NL80211_ATTR_AUTH_DATA])
Jouni Malinene39e5b52012-09-30 19:29:39 +03008060 return -EINVAL;
8061
Jouni Malinen11b6b5a2016-10-27 00:41:58 +03008062 if (info->attrs[NL80211_ATTR_AUTH_DATA]) {
Jouni Malinen63181062016-10-27 00:42:02 +03008063 if (auth_type != NL80211_AUTHTYPE_SAE &&
8064 auth_type != NL80211_AUTHTYPE_FILS_SK &&
8065 auth_type != NL80211_AUTHTYPE_FILS_SK_PFS &&
8066 auth_type != NL80211_AUTHTYPE_FILS_PK)
Jouni Malinene39e5b52012-09-30 19:29:39 +03008067 return -EINVAL;
Jouni Malinen11b6b5a2016-10-27 00:41:58 +03008068 auth_data = nla_data(info->attrs[NL80211_ATTR_AUTH_DATA]);
8069 auth_data_len = nla_len(info->attrs[NL80211_ATTR_AUTH_DATA]);
Jouni Malinene39e5b52012-09-30 19:29:39 +03008070 /* need to include at least Auth Transaction and Status Code */
Jouni Malinen11b6b5a2016-10-27 00:41:58 +03008071 if (auth_data_len < 4)
Jouni Malinene39e5b52012-09-30 19:29:39 +03008072 return -EINVAL;
8073 }
8074
Jouni Malinend5cdfac2010-04-04 09:37:19 +03008075 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE];
8076
Johannes Berg95de8172012-01-20 13:55:25 +01008077 /*
8078 * Since we no longer track auth state, ignore
8079 * requests to only change local state.
8080 */
8081 if (local_state_change)
8082 return 0;
8083
Johannes Berg91bf9b22013-05-15 17:44:01 +02008084 wdev_lock(dev->ieee80211_ptr);
8085 err = cfg80211_mlme_auth(rdev, dev, chan, auth_type, bssid,
8086 ssid, ssid_len, ie, ie_len,
8087 key.p.key, key.p.key_len, key.idx,
Jouni Malinen11b6b5a2016-10-27 00:41:58 +03008088 auth_data, auth_data_len);
Johannes Berg91bf9b22013-05-15 17:44:01 +02008089 wdev_unlock(dev->ieee80211_ptr);
8090 return err;
Jouni Malinen636a5d32009-03-19 13:39:22 +02008091}
8092
Johannes Bergc0692b82010-08-27 14:26:53 +03008093static int nl80211_crypto_settings(struct cfg80211_registered_device *rdev,
8094 struct genl_info *info,
Johannes Berg3dc27d22009-07-02 21:36:37 +02008095 struct cfg80211_crypto_settings *settings,
8096 int cipher_limit)
Samuel Ortizb23aa672009-07-01 21:26:54 +02008097{
Johannes Bergc0b2bbd2009-07-25 16:54:36 +02008098 memset(settings, 0, sizeof(*settings));
8099
Samuel Ortizb23aa672009-07-01 21:26:54 +02008100 settings->control_port = info->attrs[NL80211_ATTR_CONTROL_PORT];
8101
Johannes Bergc0692b82010-08-27 14:26:53 +03008102 if (info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]) {
8103 u16 proto;
Kirtika Ruchandani7a087e72016-05-29 19:51:23 -07008104
Johannes Bergc0692b82010-08-27 14:26:53 +03008105 proto = nla_get_u16(
8106 info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]);
8107 settings->control_port_ethertype = cpu_to_be16(proto);
8108 if (!(rdev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) &&
8109 proto != ETH_P_PAE)
8110 return -EINVAL;
8111 if (info->attrs[NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT])
8112 settings->control_port_no_encrypt = true;
8113 } else
8114 settings->control_port_ethertype = cpu_to_be16(ETH_P_PAE);
8115
Samuel Ortizb23aa672009-07-01 21:26:54 +02008116 if (info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]) {
8117 void *data;
8118 int len, i;
8119
8120 data = nla_data(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]);
8121 len = nla_len(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]);
8122 settings->n_ciphers_pairwise = len / sizeof(u32);
8123
8124 if (len % sizeof(u32))
8125 return -EINVAL;
8126
Johannes Berg3dc27d22009-07-02 21:36:37 +02008127 if (settings->n_ciphers_pairwise > cipher_limit)
Samuel Ortizb23aa672009-07-01 21:26:54 +02008128 return -EINVAL;
8129
8130 memcpy(settings->ciphers_pairwise, data, len);
8131
8132 for (i = 0; i < settings->n_ciphers_pairwise; i++)
Jouni Malinen38ba3c52011-09-21 18:14:56 +03008133 if (!cfg80211_supported_cipher_suite(
8134 &rdev->wiphy,
Samuel Ortizb23aa672009-07-01 21:26:54 +02008135 settings->ciphers_pairwise[i]))
8136 return -EINVAL;
8137 }
8138
8139 if (info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]) {
8140 settings->cipher_group =
8141 nla_get_u32(info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]);
Jouni Malinen38ba3c52011-09-21 18:14:56 +03008142 if (!cfg80211_supported_cipher_suite(&rdev->wiphy,
8143 settings->cipher_group))
Samuel Ortizb23aa672009-07-01 21:26:54 +02008144 return -EINVAL;
8145 }
8146
8147 if (info->attrs[NL80211_ATTR_WPA_VERSIONS]) {
8148 settings->wpa_versions =
8149 nla_get_u32(info->attrs[NL80211_ATTR_WPA_VERSIONS]);
8150 if (!nl80211_valid_wpa_versions(settings->wpa_versions))
8151 return -EINVAL;
8152 }
8153
8154 if (info->attrs[NL80211_ATTR_AKM_SUITES]) {
8155 void *data;
Jouni Malinen6d302402011-09-21 18:11:33 +03008156 int len;
Samuel Ortizb23aa672009-07-01 21:26:54 +02008157
8158 data = nla_data(info->attrs[NL80211_ATTR_AKM_SUITES]);
8159 len = nla_len(info->attrs[NL80211_ATTR_AKM_SUITES]);
8160 settings->n_akm_suites = len / sizeof(u32);
8161
8162 if (len % sizeof(u32))
8163 return -EINVAL;
8164
Jouni Malinen1b9ca022011-09-21 16:13:07 +03008165 if (settings->n_akm_suites > NL80211_MAX_NR_AKM_SUITES)
8166 return -EINVAL;
8167
Samuel Ortizb23aa672009-07-01 21:26:54 +02008168 memcpy(settings->akm_suites, data, len);
Samuel Ortizb23aa672009-07-01 21:26:54 +02008169 }
8170
Eliad Peller91b5ab62017-06-09 13:08:42 +01008171 if (info->attrs[NL80211_ATTR_PMK]) {
8172 if (nla_len(info->attrs[NL80211_ATTR_PMK]) != WLAN_PMK_LEN)
8173 return -EINVAL;
8174 if (!wiphy_ext_feature_isset(&rdev->wiphy,
8175 NL80211_EXT_FEATURE_4WAY_HANDSHAKE_STA_PSK))
8176 return -EINVAL;
8177 settings->psk = nla_data(info->attrs[NL80211_ATTR_PMK]);
8178 }
8179
Samuel Ortizb23aa672009-07-01 21:26:54 +02008180 return 0;
8181}
8182
Jouni Malinen636a5d32009-03-19 13:39:22 +02008183static int nl80211_associate(struct sk_buff *skb, struct genl_info *info)
8184{
Johannes Berg4c476992010-10-04 21:36:35 +02008185 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8186 struct net_device *dev = info->user_ptr[1];
Johannes Bergf444de02010-05-05 15:25:02 +02008187 struct ieee80211_channel *chan;
Johannes Bergf62fab72013-02-21 20:09:09 +01008188 struct cfg80211_assoc_request req = {};
8189 const u8 *bssid, *ssid;
8190 int err, ssid_len = 0;
Jouni Malinen636a5d32009-03-19 13:39:22 +02008191
Johannes Bergf4a11bb2009-03-27 12:40:28 +01008192 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
8193 return -EINVAL;
8194
8195 if (!info->attrs[NL80211_ATTR_MAC] ||
Johannes Berg19957bb2009-07-02 17:20:43 +02008196 !info->attrs[NL80211_ATTR_SSID] ||
8197 !info->attrs[NL80211_ATTR_WIPHY_FREQ])
Johannes Bergf4a11bb2009-03-27 12:40:28 +01008198 return -EINVAL;
8199
Johannes Berg4c476992010-10-04 21:36:35 +02008200 if (!rdev->ops->assoc)
8201 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02008202
Johannes Berg074ac8d2010-09-16 14:58:22 +02008203 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02008204 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
8205 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02008206
Johannes Berg19957bb2009-07-02 17:20:43 +02008207 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02008208
Jouni Malinen664834d2014-01-15 00:01:44 +02008209 chan = nl80211_get_valid_chan(&rdev->wiphy,
8210 info->attrs[NL80211_ATTR_WIPHY_FREQ]);
8211 if (!chan)
Johannes Berg4c476992010-10-04 21:36:35 +02008212 return -EINVAL;
Jouni Malinen636a5d32009-03-19 13:39:22 +02008213
Johannes Berg19957bb2009-07-02 17:20:43 +02008214 ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
8215 ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02008216
8217 if (info->attrs[NL80211_ATTR_IE]) {
Johannes Bergf62fab72013-02-21 20:09:09 +01008218 req.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
8219 req.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02008220 }
8221
Jouni Malinendc6382ce2009-05-06 22:09:37 +03008222 if (info->attrs[NL80211_ATTR_USE_MFP]) {
Johannes Berg4f5dadc2009-07-07 03:56:10 +02008223 enum nl80211_mfp mfp =
Jouni Malinendc6382ce2009-05-06 22:09:37 +03008224 nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]);
Johannes Berg4f5dadc2009-07-07 03:56:10 +02008225 if (mfp == NL80211_MFP_REQUIRED)
Johannes Bergf62fab72013-02-21 20:09:09 +01008226 req.use_mfp = true;
Johannes Berg4c476992010-10-04 21:36:35 +02008227 else if (mfp != NL80211_MFP_NO)
8228 return -EINVAL;
Jouni Malinendc6382ce2009-05-06 22:09:37 +03008229 }
8230
Johannes Berg3e5d7642009-07-07 14:37:26 +02008231 if (info->attrs[NL80211_ATTR_PREV_BSSID])
Johannes Bergf62fab72013-02-21 20:09:09 +01008232 req.prev_bssid = nla_data(info->attrs[NL80211_ATTR_PREV_BSSID]);
Johannes Berg3e5d7642009-07-07 14:37:26 +02008233
Ben Greear7e7c8922011-11-18 11:31:59 -08008234 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT]))
Johannes Bergf62fab72013-02-21 20:09:09 +01008235 req.flags |= ASSOC_REQ_DISABLE_HT;
Ben Greear7e7c8922011-11-18 11:31:59 -08008236
8237 if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
Johannes Bergf62fab72013-02-21 20:09:09 +01008238 memcpy(&req.ht_capa_mask,
8239 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]),
8240 sizeof(req.ht_capa_mask));
Ben Greear7e7c8922011-11-18 11:31:59 -08008241
8242 if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) {
Johannes Bergf62fab72013-02-21 20:09:09 +01008243 if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
Ben Greear7e7c8922011-11-18 11:31:59 -08008244 return -EINVAL;
Johannes Bergf62fab72013-02-21 20:09:09 +01008245 memcpy(&req.ht_capa,
8246 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]),
8247 sizeof(req.ht_capa));
Ben Greear7e7c8922011-11-18 11:31:59 -08008248 }
8249
Johannes Bergee2aca32013-02-21 17:36:01 +01008250 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_VHT]))
Johannes Bergf62fab72013-02-21 20:09:09 +01008251 req.flags |= ASSOC_REQ_DISABLE_VHT;
Johannes Bergee2aca32013-02-21 17:36:01 +01008252
8253 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK])
Johannes Bergf62fab72013-02-21 20:09:09 +01008254 memcpy(&req.vht_capa_mask,
8255 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]),
8256 sizeof(req.vht_capa_mask));
Johannes Bergee2aca32013-02-21 17:36:01 +01008257
8258 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) {
Johannes Bergf62fab72013-02-21 20:09:09 +01008259 if (!info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK])
Johannes Bergee2aca32013-02-21 17:36:01 +01008260 return -EINVAL;
Johannes Bergf62fab72013-02-21 20:09:09 +01008261 memcpy(&req.vht_capa,
8262 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]),
8263 sizeof(req.vht_capa));
Johannes Bergee2aca32013-02-21 17:36:01 +01008264 }
8265
Assaf Kraussbab5ab72014-09-03 15:25:01 +03008266 if (nla_get_flag(info->attrs[NL80211_ATTR_USE_RRM])) {
Beni Lev0c9ca112016-02-17 20:30:00 +02008267 if (!((rdev->wiphy.features &
8268 NL80211_FEATURE_DS_PARAM_SET_IE_IN_PROBES) &&
8269 (rdev->wiphy.features & NL80211_FEATURE_QUIET)) &&
8270 !wiphy_ext_feature_isset(&rdev->wiphy,
8271 NL80211_EXT_FEATURE_RRM))
Assaf Kraussbab5ab72014-09-03 15:25:01 +03008272 return -EINVAL;
8273 req.flags |= ASSOC_REQ_USE_RRM;
8274 }
8275
Jouni Malinen348bd452016-10-27 00:42:03 +03008276 if (info->attrs[NL80211_ATTR_FILS_KEK]) {
8277 req.fils_kek = nla_data(info->attrs[NL80211_ATTR_FILS_KEK]);
8278 req.fils_kek_len = nla_len(info->attrs[NL80211_ATTR_FILS_KEK]);
8279 if (!info->attrs[NL80211_ATTR_FILS_NONCES])
8280 return -EINVAL;
8281 req.fils_nonces =
8282 nla_data(info->attrs[NL80211_ATTR_FILS_NONCES]);
8283 }
8284
Johannes Bergf62fab72013-02-21 20:09:09 +01008285 err = nl80211_crypto_settings(rdev, info, &req.crypto, 1);
Johannes Berg91bf9b22013-05-15 17:44:01 +02008286 if (!err) {
8287 wdev_lock(dev->ieee80211_ptr);
Andrzej Zaborowskibd2522b2017-01-06 16:33:43 -05008288
Johannes Bergf62fab72013-02-21 20:09:09 +01008289 err = cfg80211_mlme_assoc(rdev, dev, chan, bssid,
8290 ssid, ssid_len, &req);
Andrzej Zaborowskibd2522b2017-01-06 16:33:43 -05008291
8292 if (!err && info->attrs[NL80211_ATTR_SOCKET_OWNER]) {
8293 dev->ieee80211_ptr->conn_owner_nlportid =
8294 info->snd_portid;
8295 memcpy(dev->ieee80211_ptr->disconnect_bssid,
8296 bssid, ETH_ALEN);
8297 }
8298
Johannes Berg91bf9b22013-05-15 17:44:01 +02008299 wdev_unlock(dev->ieee80211_ptr);
8300 }
Jouni Malinen636a5d32009-03-19 13:39:22 +02008301
Jouni Malinen636a5d32009-03-19 13:39:22 +02008302 return err;
8303}
8304
8305static int nl80211_deauthenticate(struct sk_buff *skb, struct genl_info *info)
8306{
Johannes Berg4c476992010-10-04 21:36:35 +02008307 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8308 struct net_device *dev = info->user_ptr[1];
Johannes Berg19957bb2009-07-02 17:20:43 +02008309 const u8 *ie = NULL, *bssid;
Johannes Berg91bf9b22013-05-15 17:44:01 +02008310 int ie_len = 0, err;
Johannes Berg19957bb2009-07-02 17:20:43 +02008311 u16 reason_code;
Jouni Malinend5cdfac2010-04-04 09:37:19 +03008312 bool local_state_change;
Jouni Malinen636a5d32009-03-19 13:39:22 +02008313
Johannes Bergf4a11bb2009-03-27 12:40:28 +01008314 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
8315 return -EINVAL;
8316
8317 if (!info->attrs[NL80211_ATTR_MAC])
8318 return -EINVAL;
8319
8320 if (!info->attrs[NL80211_ATTR_REASON_CODE])
8321 return -EINVAL;
8322
Johannes Berg4c476992010-10-04 21:36:35 +02008323 if (!rdev->ops->deauth)
8324 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02008325
Johannes Berg074ac8d2010-09-16 14:58:22 +02008326 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02008327 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
8328 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02008329
Johannes Berg19957bb2009-07-02 17:20:43 +02008330 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02008331
Johannes Berg19957bb2009-07-02 17:20:43 +02008332 reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
8333 if (reason_code == 0) {
Johannes Bergf4a11bb2009-03-27 12:40:28 +01008334 /* Reason Code 0 is reserved */
Johannes Berg4c476992010-10-04 21:36:35 +02008335 return -EINVAL;
Jouni Malinen255e7372009-03-20 21:21:17 +02008336 }
Jouni Malinen636a5d32009-03-19 13:39:22 +02008337
8338 if (info->attrs[NL80211_ATTR_IE]) {
Johannes Berg19957bb2009-07-02 17:20:43 +02008339 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
8340 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02008341 }
8342
Jouni Malinend5cdfac2010-04-04 09:37:19 +03008343 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE];
8344
Johannes Berg91bf9b22013-05-15 17:44:01 +02008345 wdev_lock(dev->ieee80211_ptr);
8346 err = cfg80211_mlme_deauth(rdev, dev, bssid, ie, ie_len, reason_code,
8347 local_state_change);
8348 wdev_unlock(dev->ieee80211_ptr);
8349 return err;
Jouni Malinen636a5d32009-03-19 13:39:22 +02008350}
8351
8352static int nl80211_disassociate(struct sk_buff *skb, struct genl_info *info)
8353{
Johannes Berg4c476992010-10-04 21:36:35 +02008354 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8355 struct net_device *dev = info->user_ptr[1];
Johannes Berg19957bb2009-07-02 17:20:43 +02008356 const u8 *ie = NULL, *bssid;
Johannes Berg91bf9b22013-05-15 17:44:01 +02008357 int ie_len = 0, err;
Johannes Berg19957bb2009-07-02 17:20:43 +02008358 u16 reason_code;
Jouni Malinend5cdfac2010-04-04 09:37:19 +03008359 bool local_state_change;
Jouni Malinen636a5d32009-03-19 13:39:22 +02008360
Johannes Bergf4a11bb2009-03-27 12:40:28 +01008361 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
8362 return -EINVAL;
8363
8364 if (!info->attrs[NL80211_ATTR_MAC])
8365 return -EINVAL;
8366
8367 if (!info->attrs[NL80211_ATTR_REASON_CODE])
8368 return -EINVAL;
8369
Johannes Berg4c476992010-10-04 21:36:35 +02008370 if (!rdev->ops->disassoc)
8371 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02008372
Johannes Berg074ac8d2010-09-16 14:58:22 +02008373 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02008374 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
8375 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02008376
Johannes Berg19957bb2009-07-02 17:20:43 +02008377 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02008378
Johannes Berg19957bb2009-07-02 17:20:43 +02008379 reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
8380 if (reason_code == 0) {
Johannes Bergf4a11bb2009-03-27 12:40:28 +01008381 /* Reason Code 0 is reserved */
Johannes Berg4c476992010-10-04 21:36:35 +02008382 return -EINVAL;
Jouni Malinen255e7372009-03-20 21:21:17 +02008383 }
Jouni Malinen636a5d32009-03-19 13:39:22 +02008384
8385 if (info->attrs[NL80211_ATTR_IE]) {
Johannes Berg19957bb2009-07-02 17:20:43 +02008386 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
8387 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02008388 }
8389
Jouni Malinend5cdfac2010-04-04 09:37:19 +03008390 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE];
8391
Johannes Berg91bf9b22013-05-15 17:44:01 +02008392 wdev_lock(dev->ieee80211_ptr);
8393 err = cfg80211_mlme_disassoc(rdev, dev, bssid, ie, ie_len, reason_code,
8394 local_state_change);
8395 wdev_unlock(dev->ieee80211_ptr);
8396 return err;
Jouni Malinen636a5d32009-03-19 13:39:22 +02008397}
8398
Felix Fietkaudd5b4cc2010-11-22 20:58:24 +01008399static bool
8400nl80211_parse_mcast_rate(struct cfg80211_registered_device *rdev,
Johannes Berg57fbcce2016-04-12 15:56:15 +02008401 int mcast_rate[NUM_NL80211_BANDS],
Felix Fietkaudd5b4cc2010-11-22 20:58:24 +01008402 int rateval)
8403{
8404 struct wiphy *wiphy = &rdev->wiphy;
8405 bool found = false;
8406 int band, i;
8407
Johannes Berg57fbcce2016-04-12 15:56:15 +02008408 for (band = 0; band < NUM_NL80211_BANDS; band++) {
Felix Fietkaudd5b4cc2010-11-22 20:58:24 +01008409 struct ieee80211_supported_band *sband;
8410
8411 sband = wiphy->bands[band];
8412 if (!sband)
8413 continue;
8414
8415 for (i = 0; i < sband->n_bitrates; i++) {
8416 if (sband->bitrates[i].bitrate == rateval) {
8417 mcast_rate[band] = i + 1;
8418 found = true;
8419 break;
8420 }
8421 }
8422 }
8423
8424 return found;
8425}
8426
Johannes Berg04a773a2009-04-19 21:24:32 +02008427static int nl80211_join_ibss(struct sk_buff *skb, struct genl_info *info)
8428{
Johannes Berg4c476992010-10-04 21:36:35 +02008429 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8430 struct net_device *dev = info->user_ptr[1];
Johannes Berg04a773a2009-04-19 21:24:32 +02008431 struct cfg80211_ibss_params ibss;
8432 struct wiphy *wiphy;
Johannes Bergfffd0932009-07-08 14:22:54 +02008433 struct cfg80211_cached_keys *connkeys = NULL;
Johannes Berg04a773a2009-04-19 21:24:32 +02008434 int err;
8435
Johannes Berg8e30bc52009-04-22 17:45:38 +02008436 memset(&ibss, 0, sizeof(ibss));
8437
Johannes Berg04a773a2009-04-19 21:24:32 +02008438 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
8439 return -EINVAL;
8440
Johannes Berg683b6d32012-11-08 21:25:48 +01008441 if (!info->attrs[NL80211_ATTR_SSID] ||
Johannes Berg04a773a2009-04-19 21:24:32 +02008442 !nla_len(info->attrs[NL80211_ATTR_SSID]))
8443 return -EINVAL;
8444
Johannes Berg8e30bc52009-04-22 17:45:38 +02008445 ibss.beacon_interval = 100;
8446
Purushottam Kushwaha12d20fc92016-08-11 15:14:02 +05308447 if (info->attrs[NL80211_ATTR_BEACON_INTERVAL])
Johannes Berg8e30bc52009-04-22 17:45:38 +02008448 ibss.beacon_interval =
8449 nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]);
Purushottam Kushwaha12d20fc92016-08-11 15:14:02 +05308450
Purushottam Kushwaha0c317a02016-10-12 18:26:51 +05308451 err = cfg80211_validate_beacon_int(rdev, NL80211_IFTYPE_ADHOC,
8452 ibss.beacon_interval);
Purushottam Kushwaha12d20fc92016-08-11 15:14:02 +05308453 if (err)
8454 return err;
Johannes Berg8e30bc52009-04-22 17:45:38 +02008455
Johannes Berg4c476992010-10-04 21:36:35 +02008456 if (!rdev->ops->join_ibss)
8457 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02008458
Johannes Berg4c476992010-10-04 21:36:35 +02008459 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC)
8460 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02008461
Johannes Berg79c97e92009-07-07 03:56:12 +02008462 wiphy = &rdev->wiphy;
Johannes Berg04a773a2009-04-19 21:24:32 +02008463
Johannes Berg39193492011-09-16 13:45:25 +02008464 if (info->attrs[NL80211_ATTR_MAC]) {
Johannes Berg04a773a2009-04-19 21:24:32 +02008465 ibss.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Johannes Berg39193492011-09-16 13:45:25 +02008466
8467 if (!is_valid_ether_addr(ibss.bssid))
8468 return -EINVAL;
8469 }
Johannes Berg04a773a2009-04-19 21:24:32 +02008470 ibss.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
8471 ibss.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
8472
8473 if (info->attrs[NL80211_ATTR_IE]) {
8474 ibss.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
8475 ibss.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
8476 }
8477
Johannes Berg683b6d32012-11-08 21:25:48 +01008478 err = nl80211_parse_chandef(rdev, info, &ibss.chandef);
8479 if (err)
8480 return err;
Alexander Simon54858ee5b2011-11-30 16:56:32 +01008481
Ilan Peer174e0cd2014-02-23 09:13:01 +02008482 if (!cfg80211_reg_can_beacon(&rdev->wiphy, &ibss.chandef,
8483 NL80211_IFTYPE_ADHOC))
Alexander Simon54858ee5b2011-11-30 16:56:32 +01008484 return -EINVAL;
8485
Simon Wunderlich2f301ab2013-05-16 13:00:28 +02008486 switch (ibss.chandef.width) {
Simon Wunderlichbf372642013-07-08 16:55:58 +02008487 case NL80211_CHAN_WIDTH_5:
8488 case NL80211_CHAN_WIDTH_10:
Simon Wunderlich2f301ab2013-05-16 13:00:28 +02008489 case NL80211_CHAN_WIDTH_20_NOHT:
8490 break;
8491 case NL80211_CHAN_WIDTH_20:
8492 case NL80211_CHAN_WIDTH_40:
Janusz.Dziedzic@tieto.comffc11992015-02-21 16:52:39 +01008493 if (!(rdev->wiphy.features & NL80211_FEATURE_HT_IBSS))
8494 return -EINVAL;
8495 break;
8496 case NL80211_CHAN_WIDTH_80:
8497 case NL80211_CHAN_WIDTH_80P80:
8498 case NL80211_CHAN_WIDTH_160:
8499 if (!(rdev->wiphy.features & NL80211_FEATURE_HT_IBSS))
8500 return -EINVAL;
8501 if (!wiphy_ext_feature_isset(&rdev->wiphy,
8502 NL80211_EXT_FEATURE_VHT_IBSS))
8503 return -EINVAL;
8504 break;
Simon Wunderlich2f301ab2013-05-16 13:00:28 +02008505 default:
Johannes Bergdb9c64c2012-11-09 14:56:41 +01008506 return -EINVAL;
Simon Wunderlich2f301ab2013-05-16 13:00:28 +02008507 }
Johannes Bergdb9c64c2012-11-09 14:56:41 +01008508
Johannes Berg04a773a2009-04-19 21:24:32 +02008509 ibss.channel_fixed = !!info->attrs[NL80211_ATTR_FREQ_FIXED];
Johannes Bergfffd0932009-07-08 14:22:54 +02008510 ibss.privacy = !!info->attrs[NL80211_ATTR_PRIVACY];
Johannes Berg04a773a2009-04-19 21:24:32 +02008511
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03008512 if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) {
8513 u8 *rates =
8514 nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
8515 int n_rates =
8516 nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
8517 struct ieee80211_supported_band *sband =
Johannes Berg683b6d32012-11-08 21:25:48 +01008518 wiphy->bands[ibss.chandef.chan->band];
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03008519
Johannes Berg34850ab2011-07-18 18:08:35 +02008520 err = ieee80211_get_ratemask(sband, rates, n_rates,
8521 &ibss.basic_rates);
8522 if (err)
8523 return err;
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03008524 }
Felix Fietkaudd5b4cc2010-11-22 20:58:24 +01008525
Simon Wunderlich803768f2013-06-28 10:39:58 +02008526 if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
8527 memcpy(&ibss.ht_capa_mask,
8528 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]),
8529 sizeof(ibss.ht_capa_mask));
8530
8531 if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) {
8532 if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
8533 return -EINVAL;
8534 memcpy(&ibss.ht_capa,
8535 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]),
8536 sizeof(ibss.ht_capa));
8537 }
8538
Felix Fietkaudd5b4cc2010-11-22 20:58:24 +01008539 if (info->attrs[NL80211_ATTR_MCAST_RATE] &&
8540 !nl80211_parse_mcast_rate(rdev, ibss.mcast_rate,
8541 nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE])))
8542 return -EINVAL;
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03008543
Johannes Berg4c476992010-10-04 21:36:35 +02008544 if (ibss.privacy && info->attrs[NL80211_ATTR_KEYS]) {
Sujith Manoharande7044e2012-10-18 10:19:28 +05308545 bool no_ht = false;
8546
Johannes Berg4c476992010-10-04 21:36:35 +02008547 connkeys = nl80211_parse_connkeys(rdev,
Sujith Manoharande7044e2012-10-18 10:19:28 +05308548 info->attrs[NL80211_ATTR_KEYS],
8549 &no_ht);
Johannes Berg4c476992010-10-04 21:36:35 +02008550 if (IS_ERR(connkeys))
8551 return PTR_ERR(connkeys);
Sujith Manoharande7044e2012-10-18 10:19:28 +05308552
Johannes Berg3d9d1d62012-11-08 23:14:50 +01008553 if ((ibss.chandef.width != NL80211_CHAN_WIDTH_20_NOHT) &&
8554 no_ht) {
Ola Olsson5e950a72016-02-11 01:00:22 +01008555 kzfree(connkeys);
Sujith Manoharande7044e2012-10-18 10:19:28 +05308556 return -EINVAL;
8557 }
Johannes Berg4c476992010-10-04 21:36:35 +02008558 }
Johannes Berg04a773a2009-04-19 21:24:32 +02008559
Antonio Quartulli267335d2012-01-31 20:25:47 +01008560 ibss.control_port =
8561 nla_get_flag(info->attrs[NL80211_ATTR_CONTROL_PORT]);
8562
Simon Wunderlich5336fa82013-10-07 18:41:05 +02008563 ibss.userspace_handles_dfs =
8564 nla_get_flag(info->attrs[NL80211_ATTR_HANDLE_DFS]);
8565
Johannes Berg4c476992010-10-04 21:36:35 +02008566 err = cfg80211_join_ibss(rdev, dev, &ibss, connkeys);
Johannes Bergfffd0932009-07-08 14:22:54 +02008567 if (err)
Johannes Bergb47f6102014-09-10 13:39:54 +03008568 kzfree(connkeys);
Johannes Berg04a773a2009-04-19 21:24:32 +02008569 return err;
8570}
8571
8572static int nl80211_leave_ibss(struct sk_buff *skb, struct genl_info *info)
8573{
Johannes Berg4c476992010-10-04 21:36:35 +02008574 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8575 struct net_device *dev = info->user_ptr[1];
Johannes Berg04a773a2009-04-19 21:24:32 +02008576
Johannes Berg4c476992010-10-04 21:36:35 +02008577 if (!rdev->ops->leave_ibss)
8578 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02008579
Johannes Berg4c476992010-10-04 21:36:35 +02008580 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC)
8581 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02008582
Johannes Berg4c476992010-10-04 21:36:35 +02008583 return cfg80211_leave_ibss(rdev, dev, false);
Johannes Berg04a773a2009-04-19 21:24:32 +02008584}
8585
Antonio Quartullif4e583c2012-11-02 13:27:48 +01008586static int nl80211_set_mcast_rate(struct sk_buff *skb, struct genl_info *info)
8587{
8588 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8589 struct net_device *dev = info->user_ptr[1];
Johannes Berg57fbcce2016-04-12 15:56:15 +02008590 int mcast_rate[NUM_NL80211_BANDS];
Antonio Quartullif4e583c2012-11-02 13:27:48 +01008591 u32 nla_rate;
8592 int err;
8593
8594 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC &&
Bertold Van den Bergh876dc932015-08-05 16:02:21 +02008595 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT &&
8596 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_OCB)
Antonio Quartullif4e583c2012-11-02 13:27:48 +01008597 return -EOPNOTSUPP;
8598
8599 if (!rdev->ops->set_mcast_rate)
8600 return -EOPNOTSUPP;
8601
8602 memset(mcast_rate, 0, sizeof(mcast_rate));
8603
8604 if (!info->attrs[NL80211_ATTR_MCAST_RATE])
8605 return -EINVAL;
8606
8607 nla_rate = nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]);
8608 if (!nl80211_parse_mcast_rate(rdev, mcast_rate, nla_rate))
8609 return -EINVAL;
8610
Ilan Peera1056b1b2015-10-22 22:27:46 +03008611 err = rdev_set_mcast_rate(rdev, dev, mcast_rate);
Antonio Quartullif4e583c2012-11-02 13:27:48 +01008612
8613 return err;
8614}
8615
Johannes Bergad7e7182013-11-13 13:37:47 +01008616static struct sk_buff *
8617__cfg80211_alloc_vendor_skb(struct cfg80211_registered_device *rdev,
Ahmad Kholaif6c09e792015-02-26 15:26:53 +02008618 struct wireless_dev *wdev, int approxlen,
8619 u32 portid, u32 seq, enum nl80211_commands cmd,
Johannes Berg567ffc32013-12-18 14:43:31 +01008620 enum nl80211_attrs attr,
8621 const struct nl80211_vendor_cmd_info *info,
8622 gfp_t gfp)
Johannes Bergad7e7182013-11-13 13:37:47 +01008623{
8624 struct sk_buff *skb;
8625 void *hdr;
8626 struct nlattr *data;
8627
8628 skb = nlmsg_new(approxlen + 100, gfp);
8629 if (!skb)
8630 return NULL;
8631
8632 hdr = nl80211hdr_put(skb, portid, seq, 0, cmd);
8633 if (!hdr) {
8634 kfree_skb(skb);
8635 return NULL;
8636 }
8637
8638 if (nla_put_u32(skb, NL80211_ATTR_WIPHY, rdev->wiphy_idx))
8639 goto nla_put_failure;
Johannes Berg567ffc32013-12-18 14:43:31 +01008640
8641 if (info) {
8642 if (nla_put_u32(skb, NL80211_ATTR_VENDOR_ID,
8643 info->vendor_id))
8644 goto nla_put_failure;
8645 if (nla_put_u32(skb, NL80211_ATTR_VENDOR_SUBCMD,
8646 info->subcmd))
8647 goto nla_put_failure;
8648 }
8649
Ahmad Kholaif6c09e792015-02-26 15:26:53 +02008650 if (wdev) {
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02008651 if (nla_put_u64_64bit(skb, NL80211_ATTR_WDEV,
8652 wdev_id(wdev), NL80211_ATTR_PAD))
Ahmad Kholaif6c09e792015-02-26 15:26:53 +02008653 goto nla_put_failure;
8654 if (wdev->netdev &&
8655 nla_put_u32(skb, NL80211_ATTR_IFINDEX,
8656 wdev->netdev->ifindex))
8657 goto nla_put_failure;
8658 }
8659
Johannes Bergad7e7182013-11-13 13:37:47 +01008660 data = nla_nest_start(skb, attr);
Johannes Berg76e1fb42016-09-14 09:55:57 +02008661 if (!data)
8662 goto nla_put_failure;
Johannes Bergad7e7182013-11-13 13:37:47 +01008663
8664 ((void **)skb->cb)[0] = rdev;
8665 ((void **)skb->cb)[1] = hdr;
8666 ((void **)skb->cb)[2] = data;
8667
8668 return skb;
8669
8670 nla_put_failure:
8671 kfree_skb(skb);
8672 return NULL;
8673}
Antonio Quartullif4e583c2012-11-02 13:27:48 +01008674
Johannes Berge03ad6e2014-01-01 17:22:30 +01008675struct sk_buff *__cfg80211_alloc_event_skb(struct wiphy *wiphy,
Ahmad Kholaif6c09e792015-02-26 15:26:53 +02008676 struct wireless_dev *wdev,
Johannes Berge03ad6e2014-01-01 17:22:30 +01008677 enum nl80211_commands cmd,
8678 enum nl80211_attrs attr,
8679 int vendor_event_idx,
8680 int approxlen, gfp_t gfp)
8681{
Zhao, Gangf26cbf42014-04-21 12:53:03 +08008682 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berge03ad6e2014-01-01 17:22:30 +01008683 const struct nl80211_vendor_cmd_info *info;
8684
8685 switch (cmd) {
8686 case NL80211_CMD_TESTMODE:
8687 if (WARN_ON(vendor_event_idx != -1))
8688 return NULL;
8689 info = NULL;
8690 break;
8691 case NL80211_CMD_VENDOR:
8692 if (WARN_ON(vendor_event_idx < 0 ||
8693 vendor_event_idx >= wiphy->n_vendor_events))
8694 return NULL;
8695 info = &wiphy->vendor_events[vendor_event_idx];
8696 break;
8697 default:
8698 WARN_ON(1);
8699 return NULL;
8700 }
8701
Ahmad Kholaif6c09e792015-02-26 15:26:53 +02008702 return __cfg80211_alloc_vendor_skb(rdev, wdev, approxlen, 0, 0,
Johannes Berge03ad6e2014-01-01 17:22:30 +01008703 cmd, attr, info, gfp);
8704}
8705EXPORT_SYMBOL(__cfg80211_alloc_event_skb);
8706
8707void __cfg80211_send_event_skb(struct sk_buff *skb, gfp_t gfp)
8708{
8709 struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0];
8710 void *hdr = ((void **)skb->cb)[1];
8711 struct nlattr *data = ((void **)skb->cb)[2];
8712 enum nl80211_multicast_groups mcgrp = NL80211_MCGRP_TESTMODE;
8713
Johannes Bergbd8c78e2014-07-30 14:55:26 +02008714 /* clear CB data for netlink core to own from now on */
8715 memset(skb->cb, 0, sizeof(skb->cb));
8716
Johannes Berge03ad6e2014-01-01 17:22:30 +01008717 nla_nest_end(skb, data);
8718 genlmsg_end(skb, hdr);
8719
8720 if (data->nla_type == NL80211_ATTR_VENDOR_DATA)
8721 mcgrp = NL80211_MCGRP_VENDOR;
8722
8723 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), skb, 0,
8724 mcgrp, gfp);
8725}
8726EXPORT_SYMBOL(__cfg80211_send_event_skb);
8727
Johannes Bergaff89a92009-07-01 21:26:51 +02008728#ifdef CONFIG_NL80211_TESTMODE
Johannes Bergaff89a92009-07-01 21:26:51 +02008729static int nl80211_testmode_do(struct sk_buff *skb, struct genl_info *info)
8730{
Johannes Berg4c476992010-10-04 21:36:35 +02008731 struct cfg80211_registered_device *rdev = info->user_ptr[0];
David Spinadelfc73f112013-07-31 18:04:15 +03008732 struct wireless_dev *wdev =
8733 __cfg80211_wdev_from_attrs(genl_info_net(info), info->attrs);
Johannes Bergaff89a92009-07-01 21:26:51 +02008734 int err;
8735
David Spinadelfc73f112013-07-31 18:04:15 +03008736 if (!rdev->ops->testmode_cmd)
8737 return -EOPNOTSUPP;
8738
8739 if (IS_ERR(wdev)) {
8740 err = PTR_ERR(wdev);
8741 if (err != -EINVAL)
8742 return err;
8743 wdev = NULL;
8744 } else if (wdev->wiphy != &rdev->wiphy) {
8745 return -EINVAL;
8746 }
8747
Johannes Bergaff89a92009-07-01 21:26:51 +02008748 if (!info->attrs[NL80211_ATTR_TESTDATA])
8749 return -EINVAL;
8750
Johannes Bergad7e7182013-11-13 13:37:47 +01008751 rdev->cur_cmd_info = info;
David Spinadelfc73f112013-07-31 18:04:15 +03008752 err = rdev_testmode_cmd(rdev, wdev,
Johannes Bergaff89a92009-07-01 21:26:51 +02008753 nla_data(info->attrs[NL80211_ATTR_TESTDATA]),
8754 nla_len(info->attrs[NL80211_ATTR_TESTDATA]));
Johannes Bergad7e7182013-11-13 13:37:47 +01008755 rdev->cur_cmd_info = NULL;
Johannes Bergaff89a92009-07-01 21:26:51 +02008756
Johannes Bergaff89a92009-07-01 21:26:51 +02008757 return err;
8758}
8759
Wey-Yi Guy71063f02011-05-20 09:05:54 -07008760static int nl80211_testmode_dump(struct sk_buff *skb,
8761 struct netlink_callback *cb)
8762{
Johannes Berg00918d32011-12-13 17:22:05 +01008763 struct cfg80211_registered_device *rdev;
Wey-Yi Guy71063f02011-05-20 09:05:54 -07008764 int err;
8765 long phy_idx;
8766 void *data = NULL;
8767 int data_len = 0;
8768
Johannes Berg5fe231e2013-05-08 21:45:15 +02008769 rtnl_lock();
8770
Wey-Yi Guy71063f02011-05-20 09:05:54 -07008771 if (cb->args[0]) {
8772 /*
8773 * 0 is a valid index, but not valid for args[0],
8774 * so we need to offset by 1.
8775 */
8776 phy_idx = cb->args[0] - 1;
Luca Coelhoa4956dc2017-02-07 22:13:56 +02008777
8778 rdev = cfg80211_rdev_by_wiphy_idx(phy_idx);
8779 if (!rdev) {
8780 err = -ENOENT;
8781 goto out_err;
8782 }
Wey-Yi Guy71063f02011-05-20 09:05:54 -07008783 } else {
Johannes Bergc90c39d2016-10-24 14:40:01 +02008784 struct nlattr **attrbuf = genl_family_attrbuf(&nl80211_fam);
8785
Wey-Yi Guy71063f02011-05-20 09:05:54 -07008786 err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize,
Johannes Bergfceb6432017-04-12 14:34:07 +02008787 attrbuf, nl80211_fam.maxattr,
8788 nl80211_policy, NULL);
Wey-Yi Guy71063f02011-05-20 09:05:54 -07008789 if (err)
Johannes Berg5fe231e2013-05-08 21:45:15 +02008790 goto out_err;
Johannes Berg00918d32011-12-13 17:22:05 +01008791
Johannes Bergc90c39d2016-10-24 14:40:01 +02008792 rdev = __cfg80211_rdev_from_attrs(sock_net(skb->sk), attrbuf);
Johannes Berg2bd7e352012-06-15 14:23:16 +02008793 if (IS_ERR(rdev)) {
Johannes Berg5fe231e2013-05-08 21:45:15 +02008794 err = PTR_ERR(rdev);
8795 goto out_err;
Johannes Berg00918d32011-12-13 17:22:05 +01008796 }
Johannes Berg2bd7e352012-06-15 14:23:16 +02008797 phy_idx = rdev->wiphy_idx;
Johannes Berg2bd7e352012-06-15 14:23:16 +02008798
Johannes Bergc90c39d2016-10-24 14:40:01 +02008799 if (attrbuf[NL80211_ATTR_TESTDATA])
8800 cb->args[1] = (long)attrbuf[NL80211_ATTR_TESTDATA];
Wey-Yi Guy71063f02011-05-20 09:05:54 -07008801 }
8802
8803 if (cb->args[1]) {
8804 data = nla_data((void *)cb->args[1]);
8805 data_len = nla_len((void *)cb->args[1]);
8806 }
8807
Johannes Berg00918d32011-12-13 17:22:05 +01008808 if (!rdev->ops->testmode_dump) {
Wey-Yi Guy71063f02011-05-20 09:05:54 -07008809 err = -EOPNOTSUPP;
8810 goto out_err;
8811 }
8812
8813 while (1) {
Eric W. Biederman15e47302012-09-07 20:12:54 +00008814 void *hdr = nl80211hdr_put(skb, NETLINK_CB(cb->skb).portid,
Wey-Yi Guy71063f02011-05-20 09:05:54 -07008815 cb->nlh->nlmsg_seq, NLM_F_MULTI,
8816 NL80211_CMD_TESTMODE);
8817 struct nlattr *tmdata;
8818
Dan Carpentercb35fba2013-08-14 14:50:01 +03008819 if (!hdr)
8820 break;
8821
David S. Miller9360ffd2012-03-29 04:41:26 -04008822 if (nla_put_u32(skb, NL80211_ATTR_WIPHY, phy_idx)) {
Wey-Yi Guy71063f02011-05-20 09:05:54 -07008823 genlmsg_cancel(skb, hdr);
8824 break;
8825 }
8826
8827 tmdata = nla_nest_start(skb, NL80211_ATTR_TESTDATA);
8828 if (!tmdata) {
8829 genlmsg_cancel(skb, hdr);
8830 break;
8831 }
Hila Gonene35e4d22012-06-27 17:19:42 +03008832 err = rdev_testmode_dump(rdev, skb, cb, data, data_len);
Wey-Yi Guy71063f02011-05-20 09:05:54 -07008833 nla_nest_end(skb, tmdata);
8834
8835 if (err == -ENOBUFS || err == -ENOENT) {
8836 genlmsg_cancel(skb, hdr);
8837 break;
8838 } else if (err) {
8839 genlmsg_cancel(skb, hdr);
8840 goto out_err;
8841 }
8842
8843 genlmsg_end(skb, hdr);
8844 }
8845
8846 err = skb->len;
8847 /* see above */
8848 cb->args[0] = phy_idx + 1;
8849 out_err:
Johannes Berg5fe231e2013-05-08 21:45:15 +02008850 rtnl_unlock();
Wey-Yi Guy71063f02011-05-20 09:05:54 -07008851 return err;
8852}
Johannes Bergaff89a92009-07-01 21:26:51 +02008853#endif
8854
Samuel Ortizb23aa672009-07-01 21:26:54 +02008855static int nl80211_connect(struct sk_buff *skb, struct genl_info *info)
8856{
Johannes Berg4c476992010-10-04 21:36:35 +02008857 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8858 struct net_device *dev = info->user_ptr[1];
Samuel Ortizb23aa672009-07-01 21:26:54 +02008859 struct cfg80211_connect_params connect;
8860 struct wiphy *wiphy;
Johannes Bergfffd0932009-07-08 14:22:54 +02008861 struct cfg80211_cached_keys *connkeys = NULL;
Samuel Ortizb23aa672009-07-01 21:26:54 +02008862 int err;
8863
8864 memset(&connect, 0, sizeof(connect));
8865
8866 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
8867 return -EINVAL;
8868
8869 if (!info->attrs[NL80211_ATTR_SSID] ||
8870 !nla_len(info->attrs[NL80211_ATTR_SSID]))
8871 return -EINVAL;
8872
8873 if (info->attrs[NL80211_ATTR_AUTH_TYPE]) {
8874 connect.auth_type =
8875 nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]);
Jouni Malinene39e5b52012-09-30 19:29:39 +03008876 if (!nl80211_valid_auth_type(rdev, connect.auth_type,
8877 NL80211_CMD_CONNECT))
Samuel Ortizb23aa672009-07-01 21:26:54 +02008878 return -EINVAL;
8879 } else
8880 connect.auth_type = NL80211_AUTHTYPE_AUTOMATIC;
8881
8882 connect.privacy = info->attrs[NL80211_ATTR_PRIVACY];
8883
Avraham Stern3a00df52017-06-09 13:08:43 +01008884 if (info->attrs[NL80211_ATTR_WANT_1X_4WAY_HS] &&
8885 !wiphy_ext_feature_isset(&rdev->wiphy,
8886 NL80211_EXT_FEATURE_4WAY_HANDSHAKE_STA_1X))
8887 return -EINVAL;
8888 connect.want_1x = info->attrs[NL80211_ATTR_WANT_1X_4WAY_HS];
8889
Johannes Bergc0692b82010-08-27 14:26:53 +03008890 err = nl80211_crypto_settings(rdev, info, &connect.crypto,
Johannes Berg3dc27d22009-07-02 21:36:37 +02008891 NL80211_MAX_NR_CIPHER_SUITES);
Samuel Ortizb23aa672009-07-01 21:26:54 +02008892 if (err)
8893 return err;
Samuel Ortizb23aa672009-07-01 21:26:54 +02008894
Johannes Berg074ac8d2010-09-16 14:58:22 +02008895 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02008896 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
8897 return -EOPNOTSUPP;
Samuel Ortizb23aa672009-07-01 21:26:54 +02008898
Johannes Berg79c97e92009-07-07 03:56:12 +02008899 wiphy = &rdev->wiphy;
Samuel Ortizb23aa672009-07-01 21:26:54 +02008900
Bala Shanmugam4486ea92012-03-07 17:27:12 +05308901 connect.bg_scan_period = -1;
8902 if (info->attrs[NL80211_ATTR_BG_SCAN_PERIOD] &&
8903 (wiphy->flags & WIPHY_FLAG_SUPPORTS_FW_ROAM)) {
8904 connect.bg_scan_period =
8905 nla_get_u16(info->attrs[NL80211_ATTR_BG_SCAN_PERIOD]);
8906 }
8907
Samuel Ortizb23aa672009-07-01 21:26:54 +02008908 if (info->attrs[NL80211_ATTR_MAC])
8909 connect.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen1df4a512014-01-15 00:00:47 +02008910 else if (info->attrs[NL80211_ATTR_MAC_HINT])
8911 connect.bssid_hint =
8912 nla_data(info->attrs[NL80211_ATTR_MAC_HINT]);
Samuel Ortizb23aa672009-07-01 21:26:54 +02008913 connect.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
8914 connect.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
8915
8916 if (info->attrs[NL80211_ATTR_IE]) {
8917 connect.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
8918 connect.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
8919 }
8920
Jouni Malinencee00a92013-01-15 17:15:57 +02008921 if (info->attrs[NL80211_ATTR_USE_MFP]) {
8922 connect.mfp = nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]);
8923 if (connect.mfp != NL80211_MFP_REQUIRED &&
8924 connect.mfp != NL80211_MFP_NO)
8925 return -EINVAL;
8926 } else {
8927 connect.mfp = NL80211_MFP_NO;
8928 }
8929
Jouni Malinenba6fbac2016-03-29 13:53:27 +03008930 if (info->attrs[NL80211_ATTR_PREV_BSSID])
8931 connect.prev_bssid =
8932 nla_data(info->attrs[NL80211_ATTR_PREV_BSSID]);
8933
Samuel Ortizb23aa672009-07-01 21:26:54 +02008934 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
Jouni Malinen664834d2014-01-15 00:01:44 +02008935 connect.channel = nl80211_get_valid_chan(
8936 wiphy, info->attrs[NL80211_ATTR_WIPHY_FREQ]);
8937 if (!connect.channel)
Johannes Berg4c476992010-10-04 21:36:35 +02008938 return -EINVAL;
Jouni Malinen1df4a512014-01-15 00:00:47 +02008939 } else if (info->attrs[NL80211_ATTR_WIPHY_FREQ_HINT]) {
Jouni Malinen664834d2014-01-15 00:01:44 +02008940 connect.channel_hint = nl80211_get_valid_chan(
8941 wiphy, info->attrs[NL80211_ATTR_WIPHY_FREQ_HINT]);
8942 if (!connect.channel_hint)
Jouni Malinen1df4a512014-01-15 00:00:47 +02008943 return -EINVAL;
Samuel Ortizb23aa672009-07-01 21:26:54 +02008944 }
8945
Johannes Bergfffd0932009-07-08 14:22:54 +02008946 if (connect.privacy && info->attrs[NL80211_ATTR_KEYS]) {
8947 connkeys = nl80211_parse_connkeys(rdev,
Sujith Manoharande7044e2012-10-18 10:19:28 +05308948 info->attrs[NL80211_ATTR_KEYS], NULL);
Johannes Berg4c476992010-10-04 21:36:35 +02008949 if (IS_ERR(connkeys))
8950 return PTR_ERR(connkeys);
Johannes Bergfffd0932009-07-08 14:22:54 +02008951 }
8952
Ben Greear7e7c8922011-11-18 11:31:59 -08008953 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT]))
8954 connect.flags |= ASSOC_REQ_DISABLE_HT;
8955
8956 if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
8957 memcpy(&connect.ht_capa_mask,
8958 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]),
8959 sizeof(connect.ht_capa_mask));
8960
8961 if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) {
Wei Yongjunb4e4f472012-09-02 21:41:04 +08008962 if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) {
Johannes Bergb47f6102014-09-10 13:39:54 +03008963 kzfree(connkeys);
Ben Greear7e7c8922011-11-18 11:31:59 -08008964 return -EINVAL;
Wei Yongjunb4e4f472012-09-02 21:41:04 +08008965 }
Ben Greear7e7c8922011-11-18 11:31:59 -08008966 memcpy(&connect.ht_capa,
8967 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]),
8968 sizeof(connect.ht_capa));
8969 }
8970
Johannes Bergee2aca32013-02-21 17:36:01 +01008971 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_VHT]))
8972 connect.flags |= ASSOC_REQ_DISABLE_VHT;
8973
8974 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK])
8975 memcpy(&connect.vht_capa_mask,
8976 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]),
8977 sizeof(connect.vht_capa_mask));
8978
8979 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) {
8980 if (!info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) {
Johannes Bergb47f6102014-09-10 13:39:54 +03008981 kzfree(connkeys);
Johannes Bergee2aca32013-02-21 17:36:01 +01008982 return -EINVAL;
8983 }
8984 memcpy(&connect.vht_capa,
8985 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]),
8986 sizeof(connect.vht_capa));
8987 }
8988
Assaf Kraussbab5ab72014-09-03 15:25:01 +03008989 if (nla_get_flag(info->attrs[NL80211_ATTR_USE_RRM])) {
Beni Lev0c9ca112016-02-17 20:30:00 +02008990 if (!((rdev->wiphy.features &
8991 NL80211_FEATURE_DS_PARAM_SET_IE_IN_PROBES) &&
8992 (rdev->wiphy.features & NL80211_FEATURE_QUIET)) &&
8993 !wiphy_ext_feature_isset(&rdev->wiphy,
8994 NL80211_EXT_FEATURE_RRM)) {
Ola Olsson707554b2015-12-11 21:04:52 +01008995 kzfree(connkeys);
Assaf Kraussbab5ab72014-09-03 15:25:01 +03008996 return -EINVAL;
Ola Olsson707554b2015-12-11 21:04:52 +01008997 }
Assaf Kraussbab5ab72014-09-03 15:25:01 +03008998 connect.flags |= ASSOC_REQ_USE_RRM;
8999 }
9000
Lior David34d50512016-01-28 10:58:25 +02009001 connect.pbss = nla_get_flag(info->attrs[NL80211_ATTR_PBSS]);
Johannes Berg57fbcce2016-04-12 15:56:15 +02009002 if (connect.pbss && !rdev->wiphy.bands[NL80211_BAND_60GHZ]) {
Lior David34d50512016-01-28 10:58:25 +02009003 kzfree(connkeys);
9004 return -EOPNOTSUPP;
9005 }
9006
Arend van Spriel38de03d2016-03-02 20:37:18 +01009007 if (info->attrs[NL80211_ATTR_BSS_SELECT]) {
9008 /* bss selection makes no sense if bssid is set */
9009 if (connect.bssid) {
9010 kzfree(connkeys);
9011 return -EINVAL;
9012 }
9013
9014 err = parse_bss_select(info->attrs[NL80211_ATTR_BSS_SELECT],
9015 wiphy, &connect.bss_select);
9016 if (err) {
9017 kzfree(connkeys);
9018 return err;
9019 }
9020 }
9021
Vidyullatha Kanchanapallya3caf742017-03-31 00:22:34 +03009022 if (wiphy_ext_feature_isset(&rdev->wiphy,
9023 NL80211_EXT_FEATURE_FILS_SK_OFFLOAD) &&
9024 info->attrs[NL80211_ATTR_FILS_ERP_USERNAME] &&
9025 info->attrs[NL80211_ATTR_FILS_ERP_REALM] &&
9026 info->attrs[NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM] &&
9027 info->attrs[NL80211_ATTR_FILS_ERP_RRK]) {
9028 connect.fils_erp_username =
9029 nla_data(info->attrs[NL80211_ATTR_FILS_ERP_USERNAME]);
9030 connect.fils_erp_username_len =
9031 nla_len(info->attrs[NL80211_ATTR_FILS_ERP_USERNAME]);
9032 connect.fils_erp_realm =
9033 nla_data(info->attrs[NL80211_ATTR_FILS_ERP_REALM]);
9034 connect.fils_erp_realm_len =
9035 nla_len(info->attrs[NL80211_ATTR_FILS_ERP_REALM]);
9036 connect.fils_erp_next_seq_num =
9037 nla_get_u16(
9038 info->attrs[NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM]);
9039 connect.fils_erp_rrk =
9040 nla_data(info->attrs[NL80211_ATTR_FILS_ERP_RRK]);
9041 connect.fils_erp_rrk_len =
9042 nla_len(info->attrs[NL80211_ATTR_FILS_ERP_RRK]);
9043 } else if (info->attrs[NL80211_ATTR_FILS_ERP_USERNAME] ||
9044 info->attrs[NL80211_ATTR_FILS_ERP_REALM] ||
9045 info->attrs[NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM] ||
9046 info->attrs[NL80211_ATTR_FILS_ERP_RRK]) {
9047 kzfree(connkeys);
9048 return -EINVAL;
9049 }
9050
Johannes Berg83739b02013-05-15 17:44:01 +02009051 wdev_lock(dev->ieee80211_ptr);
Andrzej Zaborowskibd2522b2017-01-06 16:33:43 -05009052
Jouni Malinen4ce2bd9c42016-03-29 13:53:28 +03009053 err = cfg80211_connect(rdev, dev, &connect, connkeys,
9054 connect.prev_bssid);
Johannes Bergfffd0932009-07-08 14:22:54 +02009055 if (err)
Johannes Bergb47f6102014-09-10 13:39:54 +03009056 kzfree(connkeys);
Andrzej Zaborowskibd2522b2017-01-06 16:33:43 -05009057
9058 if (!err && info->attrs[NL80211_ATTR_SOCKET_OWNER]) {
9059 dev->ieee80211_ptr->conn_owner_nlportid = info->snd_portid;
9060 if (connect.bssid)
9061 memcpy(dev->ieee80211_ptr->disconnect_bssid,
9062 connect.bssid, ETH_ALEN);
9063 else
9064 memset(dev->ieee80211_ptr->disconnect_bssid,
9065 0, ETH_ALEN);
9066 }
9067
9068 wdev_unlock(dev->ieee80211_ptr);
9069
Samuel Ortizb23aa672009-07-01 21:26:54 +02009070 return err;
9071}
9072
vamsi krishna088e8df2016-10-27 16:51:11 +03009073static int nl80211_update_connect_params(struct sk_buff *skb,
9074 struct genl_info *info)
9075{
9076 struct cfg80211_connect_params connect = {};
9077 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9078 struct net_device *dev = info->user_ptr[1];
9079 struct wireless_dev *wdev = dev->ieee80211_ptr;
9080 u32 changed = 0;
9081 int ret;
9082
9083 if (!rdev->ops->update_connect_params)
9084 return -EOPNOTSUPP;
9085
9086 if (info->attrs[NL80211_ATTR_IE]) {
9087 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
9088 return -EINVAL;
9089 connect.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
9090 connect.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
9091 changed |= UPDATE_ASSOC_IES;
9092 }
9093
9094 wdev_lock(dev->ieee80211_ptr);
9095 if (!wdev->current_bss)
9096 ret = -ENOLINK;
9097 else
9098 ret = rdev_update_connect_params(rdev, dev, &connect, changed);
9099 wdev_unlock(dev->ieee80211_ptr);
9100
9101 return ret;
9102}
9103
Samuel Ortizb23aa672009-07-01 21:26:54 +02009104static int nl80211_disconnect(struct sk_buff *skb, struct genl_info *info)
9105{
Johannes Berg4c476992010-10-04 21:36:35 +02009106 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9107 struct net_device *dev = info->user_ptr[1];
Samuel Ortizb23aa672009-07-01 21:26:54 +02009108 u16 reason;
Johannes Berg83739b02013-05-15 17:44:01 +02009109 int ret;
Samuel Ortizb23aa672009-07-01 21:26:54 +02009110
9111 if (!info->attrs[NL80211_ATTR_REASON_CODE])
9112 reason = WLAN_REASON_DEAUTH_LEAVING;
9113 else
9114 reason = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
9115
9116 if (reason == 0)
9117 return -EINVAL;
9118
Johannes Berg074ac8d2010-09-16 14:58:22 +02009119 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02009120 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
9121 return -EOPNOTSUPP;
Samuel Ortizb23aa672009-07-01 21:26:54 +02009122
Johannes Berg83739b02013-05-15 17:44:01 +02009123 wdev_lock(dev->ieee80211_ptr);
9124 ret = cfg80211_disconnect(rdev, dev, reason, true);
9125 wdev_unlock(dev->ieee80211_ptr);
9126 return ret;
Samuel Ortizb23aa672009-07-01 21:26:54 +02009127}
9128
Johannes Berg463d0182009-07-14 00:33:35 +02009129static int nl80211_wiphy_netns(struct sk_buff *skb, struct genl_info *info)
9130{
Johannes Berg4c476992010-10-04 21:36:35 +02009131 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg463d0182009-07-14 00:33:35 +02009132 struct net *net;
9133 int err;
Johannes Berg463d0182009-07-14 00:33:35 +02009134
Vadim Kochan4b681c82015-01-12 16:34:05 +02009135 if (info->attrs[NL80211_ATTR_PID]) {
9136 u32 pid = nla_get_u32(info->attrs[NL80211_ATTR_PID]);
9137
9138 net = get_net_ns_by_pid(pid);
9139 } else if (info->attrs[NL80211_ATTR_NETNS_FD]) {
9140 u32 fd = nla_get_u32(info->attrs[NL80211_ATTR_NETNS_FD]);
9141
9142 net = get_net_ns_by_fd(fd);
9143 } else {
Johannes Berg463d0182009-07-14 00:33:35 +02009144 return -EINVAL;
Vadim Kochan4b681c82015-01-12 16:34:05 +02009145 }
Johannes Berg463d0182009-07-14 00:33:35 +02009146
Johannes Berg4c476992010-10-04 21:36:35 +02009147 if (IS_ERR(net))
9148 return PTR_ERR(net);
Johannes Berg463d0182009-07-14 00:33:35 +02009149
9150 err = 0;
9151
9152 /* check if anything to do */
Johannes Berg4c476992010-10-04 21:36:35 +02009153 if (!net_eq(wiphy_net(&rdev->wiphy), net))
9154 err = cfg80211_switch_netns(rdev, net);
Johannes Berg463d0182009-07-14 00:33:35 +02009155
Johannes Berg463d0182009-07-14 00:33:35 +02009156 put_net(net);
Johannes Berg463d0182009-07-14 00:33:35 +02009157 return err;
9158}
9159
Samuel Ortiz67fbb162009-11-24 23:59:15 +01009160static int nl80211_setdel_pmksa(struct sk_buff *skb, struct genl_info *info)
9161{
Johannes Berg4c476992010-10-04 21:36:35 +02009162 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Samuel Ortiz67fbb162009-11-24 23:59:15 +01009163 int (*rdev_ops)(struct wiphy *wiphy, struct net_device *dev,
9164 struct cfg80211_pmksa *pmksa) = NULL;
Johannes Berg4c476992010-10-04 21:36:35 +02009165 struct net_device *dev = info->user_ptr[1];
Samuel Ortiz67fbb162009-11-24 23:59:15 +01009166 struct cfg80211_pmksa pmksa;
9167
9168 memset(&pmksa, 0, sizeof(struct cfg80211_pmksa));
9169
Samuel Ortiz67fbb162009-11-24 23:59:15 +01009170 if (!info->attrs[NL80211_ATTR_PMKID])
9171 return -EINVAL;
9172
Samuel Ortiz67fbb162009-11-24 23:59:15 +01009173 pmksa.pmkid = nla_data(info->attrs[NL80211_ATTR_PMKID]);
Vidyullatha Kanchanapallya3caf742017-03-31 00:22:34 +03009174
9175 if (info->attrs[NL80211_ATTR_MAC]) {
9176 pmksa.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
9177 } else if (info->attrs[NL80211_ATTR_SSID] &&
9178 info->attrs[NL80211_ATTR_FILS_CACHE_ID] &&
9179 (info->genlhdr->cmd == NL80211_CMD_DEL_PMKSA ||
9180 info->attrs[NL80211_ATTR_PMK])) {
9181 pmksa.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
9182 pmksa.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
9183 pmksa.cache_id =
9184 nla_data(info->attrs[NL80211_ATTR_FILS_CACHE_ID]);
9185 } else {
9186 return -EINVAL;
9187 }
9188 if (info->attrs[NL80211_ATTR_PMK]) {
9189 pmksa.pmk = nla_data(info->attrs[NL80211_ATTR_PMK]);
9190 pmksa.pmk_len = nla_len(info->attrs[NL80211_ATTR_PMK]);
9191 }
Samuel Ortiz67fbb162009-11-24 23:59:15 +01009192
Johannes Berg074ac8d2010-09-16 14:58:22 +02009193 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02009194 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
9195 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01009196
9197 switch (info->genlhdr->cmd) {
9198 case NL80211_CMD_SET_PMKSA:
9199 rdev_ops = rdev->ops->set_pmksa;
9200 break;
9201 case NL80211_CMD_DEL_PMKSA:
9202 rdev_ops = rdev->ops->del_pmksa;
9203 break;
9204 default:
9205 WARN_ON(1);
9206 break;
9207 }
9208
Johannes Berg4c476992010-10-04 21:36:35 +02009209 if (!rdev_ops)
9210 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01009211
Johannes Berg4c476992010-10-04 21:36:35 +02009212 return rdev_ops(&rdev->wiphy, dev, &pmksa);
Samuel Ortiz67fbb162009-11-24 23:59:15 +01009213}
9214
9215static int nl80211_flush_pmksa(struct sk_buff *skb, struct genl_info *info)
9216{
Johannes Berg4c476992010-10-04 21:36:35 +02009217 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9218 struct net_device *dev = info->user_ptr[1];
Samuel Ortiz67fbb162009-11-24 23:59:15 +01009219
Johannes Berg074ac8d2010-09-16 14:58:22 +02009220 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02009221 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
9222 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01009223
Johannes Berg4c476992010-10-04 21:36:35 +02009224 if (!rdev->ops->flush_pmksa)
9225 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01009226
Hila Gonene35e4d22012-06-27 17:19:42 +03009227 return rdev_flush_pmksa(rdev, dev);
Samuel Ortiz67fbb162009-11-24 23:59:15 +01009228}
9229
Arik Nemtsov109086c2011-09-28 14:12:50 +03009230static int nl80211_tdls_mgmt(struct sk_buff *skb, struct genl_info *info)
9231{
9232 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9233 struct net_device *dev = info->user_ptr[1];
9234 u8 action_code, dialog_token;
Sunil Dutt Undekaridf942e72014-02-20 16:22:09 +05309235 u32 peer_capability = 0;
Arik Nemtsov109086c2011-09-28 14:12:50 +03009236 u16 status_code;
9237 u8 *peer;
Arik Nemtsov31fa97c2014-06-11 17:18:21 +03009238 bool initiator;
Arik Nemtsov109086c2011-09-28 14:12:50 +03009239
9240 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) ||
9241 !rdev->ops->tdls_mgmt)
9242 return -EOPNOTSUPP;
9243
9244 if (!info->attrs[NL80211_ATTR_TDLS_ACTION] ||
9245 !info->attrs[NL80211_ATTR_STATUS_CODE] ||
9246 !info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN] ||
9247 !info->attrs[NL80211_ATTR_IE] ||
9248 !info->attrs[NL80211_ATTR_MAC])
9249 return -EINVAL;
9250
9251 peer = nla_data(info->attrs[NL80211_ATTR_MAC]);
9252 action_code = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_ACTION]);
9253 status_code = nla_get_u16(info->attrs[NL80211_ATTR_STATUS_CODE]);
9254 dialog_token = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN]);
Arik Nemtsov31fa97c2014-06-11 17:18:21 +03009255 initiator = nla_get_flag(info->attrs[NL80211_ATTR_TDLS_INITIATOR]);
Sunil Dutt Undekaridf942e72014-02-20 16:22:09 +05309256 if (info->attrs[NL80211_ATTR_TDLS_PEER_CAPABILITY])
9257 peer_capability =
9258 nla_get_u32(info->attrs[NL80211_ATTR_TDLS_PEER_CAPABILITY]);
Arik Nemtsov109086c2011-09-28 14:12:50 +03009259
Hila Gonene35e4d22012-06-27 17:19:42 +03009260 return rdev_tdls_mgmt(rdev, dev, peer, action_code,
Sunil Dutt Undekaridf942e72014-02-20 16:22:09 +05309261 dialog_token, status_code, peer_capability,
Arik Nemtsov31fa97c2014-06-11 17:18:21 +03009262 initiator,
Hila Gonene35e4d22012-06-27 17:19:42 +03009263 nla_data(info->attrs[NL80211_ATTR_IE]),
9264 nla_len(info->attrs[NL80211_ATTR_IE]));
Arik Nemtsov109086c2011-09-28 14:12:50 +03009265}
9266
9267static int nl80211_tdls_oper(struct sk_buff *skb, struct genl_info *info)
9268{
9269 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9270 struct net_device *dev = info->user_ptr[1];
9271 enum nl80211_tdls_operation operation;
9272 u8 *peer;
9273
9274 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) ||
9275 !rdev->ops->tdls_oper)
9276 return -EOPNOTSUPP;
9277
9278 if (!info->attrs[NL80211_ATTR_TDLS_OPERATION] ||
9279 !info->attrs[NL80211_ATTR_MAC])
9280 return -EINVAL;
9281
9282 operation = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_OPERATION]);
9283 peer = nla_data(info->attrs[NL80211_ATTR_MAC]);
9284
Hila Gonene35e4d22012-06-27 17:19:42 +03009285 return rdev_tdls_oper(rdev, dev, peer, operation);
Arik Nemtsov109086c2011-09-28 14:12:50 +03009286}
9287
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009288static int nl80211_remain_on_channel(struct sk_buff *skb,
9289 struct genl_info *info)
9290{
Johannes Berg4c476992010-10-04 21:36:35 +02009291 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02009292 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg683b6d32012-11-08 21:25:48 +01009293 struct cfg80211_chan_def chandef;
Vasanthakumar Thiagarajan34373d12017-02-27 17:04:34 +05309294 const struct cfg80211_chan_def *compat_chandef;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009295 struct sk_buff *msg;
9296 void *hdr;
9297 u64 cookie;
Johannes Berg683b6d32012-11-08 21:25:48 +01009298 u32 duration;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009299 int err;
9300
9301 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] ||
9302 !info->attrs[NL80211_ATTR_DURATION])
9303 return -EINVAL;
9304
9305 duration = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]);
9306
Johannes Berg7c4ef712011-11-18 15:33:48 +01009307 if (!rdev->ops->remain_on_channel ||
9308 !(rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL))
Johannes Berg4c476992010-10-04 21:36:35 +02009309 return -EOPNOTSUPP;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009310
Johannes Bergebf348f2012-06-01 12:50:54 +02009311 /*
9312 * We should be on that channel for at least a minimum amount of
9313 * time (10ms) but no longer than the driver supports.
9314 */
9315 if (duration < NL80211_MIN_REMAIN_ON_CHANNEL_TIME ||
9316 duration > rdev->wiphy.max_remain_on_channel_duration)
9317 return -EINVAL;
9318
Johannes Berg683b6d32012-11-08 21:25:48 +01009319 err = nl80211_parse_chandef(rdev, info, &chandef);
9320 if (err)
9321 return err;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009322
Vasanthakumar Thiagarajan34373d12017-02-27 17:04:34 +05309323 wdev_lock(wdev);
9324 if (!cfg80211_off_channel_oper_allowed(wdev) &&
9325 !cfg80211_chandef_identical(&wdev->chandef, &chandef)) {
9326 compat_chandef = cfg80211_chandef_compatible(&wdev->chandef,
9327 &chandef);
9328 if (compat_chandef != &chandef) {
9329 wdev_unlock(wdev);
9330 return -EBUSY;
9331 }
9332 }
9333 wdev_unlock(wdev);
9334
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009335 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02009336 if (!msg)
9337 return -ENOMEM;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009338
Eric W. Biederman15e47302012-09-07 20:12:54 +00009339 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009340 NL80211_CMD_REMAIN_ON_CHANNEL);
Dan Carpentercb35fba2013-08-14 14:50:01 +03009341 if (!hdr) {
9342 err = -ENOBUFS;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009343 goto free_msg;
9344 }
9345
Johannes Berg683b6d32012-11-08 21:25:48 +01009346 err = rdev_remain_on_channel(rdev, wdev, chandef.chan,
9347 duration, &cookie);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009348
9349 if (err)
9350 goto free_msg;
9351
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02009352 if (nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie,
9353 NL80211_ATTR_PAD))
David S. Miller9360ffd2012-03-29 04:41:26 -04009354 goto nla_put_failure;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009355
9356 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02009357
9358 return genlmsg_reply(msg, info);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009359
9360 nla_put_failure:
9361 err = -ENOBUFS;
9362 free_msg:
9363 nlmsg_free(msg);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009364 return err;
9365}
9366
9367static int nl80211_cancel_remain_on_channel(struct sk_buff *skb,
9368 struct genl_info *info)
9369{
Johannes Berg4c476992010-10-04 21:36:35 +02009370 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02009371 struct wireless_dev *wdev = info->user_ptr[1];
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009372 u64 cookie;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009373
9374 if (!info->attrs[NL80211_ATTR_COOKIE])
9375 return -EINVAL;
9376
Johannes Berg4c476992010-10-04 21:36:35 +02009377 if (!rdev->ops->cancel_remain_on_channel)
9378 return -EOPNOTSUPP;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009379
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009380 cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]);
9381
Hila Gonene35e4d22012-06-27 17:19:42 +03009382 return rdev_cancel_remain_on_channel(rdev, wdev, cookie);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009383}
9384
Jouni Malinen13ae75b2009-12-29 12:59:45 +02009385static int nl80211_set_tx_bitrate_mask(struct sk_buff *skb,
9386 struct genl_info *info)
9387{
Jouni Malinen13ae75b2009-12-29 12:59:45 +02009388 struct cfg80211_bitrate_mask mask;
Purushottam Kushwahaa7c7fbf2016-09-14 17:38:44 +05309389 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg4c476992010-10-04 21:36:35 +02009390 struct net_device *dev = info->user_ptr[1];
Purushottam Kushwahaa7c7fbf2016-09-14 17:38:44 +05309391 int err;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02009392
Johannes Berg4c476992010-10-04 21:36:35 +02009393 if (!rdev->ops->set_bitrate_mask)
9394 return -EOPNOTSUPP;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02009395
Purushottam Kushwahaa7c7fbf2016-09-14 17:38:44 +05309396 err = nl80211_parse_tx_bitrate_mask(info, &mask);
9397 if (err)
9398 return err;
Janusz Dziedzic78693032013-12-03 09:50:44 +01009399
Hila Gonene35e4d22012-06-27 17:19:42 +03009400 return rdev_set_bitrate_mask(rdev, dev, NULL, &mask);
Jouni Malinen13ae75b2009-12-29 12:59:45 +02009401}
9402
Johannes Berg2e161f72010-08-12 15:38:38 +02009403static int nl80211_register_mgmt(struct sk_buff *skb, struct genl_info *info)
Jouni Malinen026331c2010-02-15 12:53:10 +02009404{
Johannes Berg4c476992010-10-04 21:36:35 +02009405 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02009406 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg2e161f72010-08-12 15:38:38 +02009407 u16 frame_type = IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_ACTION;
Jouni Malinen026331c2010-02-15 12:53:10 +02009408
9409 if (!info->attrs[NL80211_ATTR_FRAME_MATCH])
9410 return -EINVAL;
9411
Johannes Berg2e161f72010-08-12 15:38:38 +02009412 if (info->attrs[NL80211_ATTR_FRAME_TYPE])
9413 frame_type = nla_get_u16(info->attrs[NL80211_ATTR_FRAME_TYPE]);
Jouni Malinen026331c2010-02-15 12:53:10 +02009414
Johannes Berg71bbc992012-06-15 15:30:18 +02009415 switch (wdev->iftype) {
9416 case NL80211_IFTYPE_STATION:
9417 case NL80211_IFTYPE_ADHOC:
9418 case NL80211_IFTYPE_P2P_CLIENT:
9419 case NL80211_IFTYPE_AP:
9420 case NL80211_IFTYPE_AP_VLAN:
9421 case NL80211_IFTYPE_MESH_POINT:
9422 case NL80211_IFTYPE_P2P_GO:
Johannes Berg98104fde2012-06-16 00:19:54 +02009423 case NL80211_IFTYPE_P2P_DEVICE:
Johannes Berg71bbc992012-06-15 15:30:18 +02009424 break;
Ayala Bekercb3b7d82016-09-20 17:31:13 +03009425 case NL80211_IFTYPE_NAN:
Johannes Berg71bbc992012-06-15 15:30:18 +02009426 default:
Johannes Berg4c476992010-10-04 21:36:35 +02009427 return -EOPNOTSUPP;
Johannes Berg71bbc992012-06-15 15:30:18 +02009428 }
Jouni Malinen026331c2010-02-15 12:53:10 +02009429
9430 /* not much point in registering if we can't reply */
Johannes Berg4c476992010-10-04 21:36:35 +02009431 if (!rdev->ops->mgmt_tx)
9432 return -EOPNOTSUPP;
Jouni Malinen026331c2010-02-15 12:53:10 +02009433
Eric W. Biederman15e47302012-09-07 20:12:54 +00009434 return cfg80211_mlme_register_mgmt(wdev, info->snd_portid, frame_type,
Jouni Malinen026331c2010-02-15 12:53:10 +02009435 nla_data(info->attrs[NL80211_ATTR_FRAME_MATCH]),
9436 nla_len(info->attrs[NL80211_ATTR_FRAME_MATCH]));
Jouni Malinen026331c2010-02-15 12:53:10 +02009437}
9438
Johannes Berg2e161f72010-08-12 15:38:38 +02009439static int nl80211_tx_mgmt(struct sk_buff *skb, struct genl_info *info)
Jouni Malinen026331c2010-02-15 12:53:10 +02009440{
Johannes Berg4c476992010-10-04 21:36:35 +02009441 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02009442 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg683b6d32012-11-08 21:25:48 +01009443 struct cfg80211_chan_def chandef;
Jouni Malinen026331c2010-02-15 12:53:10 +02009444 int err;
Johannes Bergd64d3732011-11-10 09:44:46 +01009445 void *hdr = NULL;
Jouni Malinen026331c2010-02-15 12:53:10 +02009446 u64 cookie;
Johannes Berge247bd902011-11-04 11:18:21 +01009447 struct sk_buff *msg = NULL;
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02009448 struct cfg80211_mgmt_tx_params params = {
9449 .dont_wait_for_ack =
9450 info->attrs[NL80211_ATTR_DONT_WAIT_FOR_ACK],
9451 };
Jouni Malinen026331c2010-02-15 12:53:10 +02009452
Johannes Berg683b6d32012-11-08 21:25:48 +01009453 if (!info->attrs[NL80211_ATTR_FRAME])
Jouni Malinen026331c2010-02-15 12:53:10 +02009454 return -EINVAL;
9455
Johannes Berg4c476992010-10-04 21:36:35 +02009456 if (!rdev->ops->mgmt_tx)
9457 return -EOPNOTSUPP;
Jouni Malinen026331c2010-02-15 12:53:10 +02009458
Johannes Berg71bbc992012-06-15 15:30:18 +02009459 switch (wdev->iftype) {
Antonio Quartulliea141b752013-06-11 14:20:03 +02009460 case NL80211_IFTYPE_P2P_DEVICE:
9461 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ])
9462 return -EINVAL;
Johannes Berg71bbc992012-06-15 15:30:18 +02009463 case NL80211_IFTYPE_STATION:
9464 case NL80211_IFTYPE_ADHOC:
9465 case NL80211_IFTYPE_P2P_CLIENT:
9466 case NL80211_IFTYPE_AP:
9467 case NL80211_IFTYPE_AP_VLAN:
9468 case NL80211_IFTYPE_MESH_POINT:
9469 case NL80211_IFTYPE_P2P_GO:
9470 break;
Ayala Bekercb3b7d82016-09-20 17:31:13 +03009471 case NL80211_IFTYPE_NAN:
Johannes Berg71bbc992012-06-15 15:30:18 +02009472 default:
Johannes Berg4c476992010-10-04 21:36:35 +02009473 return -EOPNOTSUPP;
Johannes Berg71bbc992012-06-15 15:30:18 +02009474 }
Jouni Malinen026331c2010-02-15 12:53:10 +02009475
Johannes Bergf7ca38d2010-11-25 10:02:29 +01009476 if (info->attrs[NL80211_ATTR_DURATION]) {
Johannes Berg7c4ef712011-11-18 15:33:48 +01009477 if (!(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX))
Johannes Bergf7ca38d2010-11-25 10:02:29 +01009478 return -EINVAL;
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02009479 params.wait = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]);
Johannes Bergebf348f2012-06-01 12:50:54 +02009480
9481 /*
9482 * We should wait on the channel for at least a minimum amount
9483 * of time (10ms) but no longer than the driver supports.
9484 */
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02009485 if (params.wait < NL80211_MIN_REMAIN_ON_CHANNEL_TIME ||
9486 params.wait > rdev->wiphy.max_remain_on_channel_duration)
Johannes Bergebf348f2012-06-01 12:50:54 +02009487 return -EINVAL;
Johannes Bergf7ca38d2010-11-25 10:02:29 +01009488 }
9489
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02009490 params.offchan = info->attrs[NL80211_ATTR_OFFCHANNEL_TX_OK];
Johannes Bergf7ca38d2010-11-25 10:02:29 +01009491
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02009492 if (params.offchan && !(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX))
Johannes Berg7c4ef712011-11-18 15:33:48 +01009493 return -EINVAL;
9494
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02009495 params.no_cck = nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]);
Rajkumar Manoharane9f935e2011-09-25 14:53:30 +05309496
Antonio Quartulliea141b752013-06-11 14:20:03 +02009497 /* get the channel if any has been specified, otherwise pass NULL to
9498 * the driver. The latter will use the current one
9499 */
9500 chandef.chan = NULL;
9501 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
9502 err = nl80211_parse_chandef(rdev, info, &chandef);
9503 if (err)
9504 return err;
9505 }
9506
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02009507 if (!chandef.chan && params.offchan)
Antonio Quartulliea141b752013-06-11 14:20:03 +02009508 return -EINVAL;
Jouni Malinen026331c2010-02-15 12:53:10 +02009509
Vasanthakumar Thiagarajan34373d12017-02-27 17:04:34 +05309510 wdev_lock(wdev);
9511 if (params.offchan && !cfg80211_off_channel_oper_allowed(wdev)) {
9512 wdev_unlock(wdev);
9513 return -EBUSY;
9514 }
9515 wdev_unlock(wdev);
9516
Andrei Otcheretianski34d22ce2014-05-09 14:11:44 +03009517 params.buf = nla_data(info->attrs[NL80211_ATTR_FRAME]);
9518 params.len = nla_len(info->attrs[NL80211_ATTR_FRAME]);
9519
9520 if (info->attrs[NL80211_ATTR_CSA_C_OFFSETS_TX]) {
9521 int len = nla_len(info->attrs[NL80211_ATTR_CSA_C_OFFSETS_TX]);
9522 int i;
9523
9524 if (len % sizeof(u16))
9525 return -EINVAL;
9526
9527 params.n_csa_offsets = len / sizeof(u16);
9528 params.csa_offsets =
9529 nla_data(info->attrs[NL80211_ATTR_CSA_C_OFFSETS_TX]);
9530
9531 /* check that all the offsets fit the frame */
9532 for (i = 0; i < params.n_csa_offsets; i++) {
9533 if (params.csa_offsets[i] >= params.len)
9534 return -EINVAL;
9535 }
9536 }
9537
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02009538 if (!params.dont_wait_for_ack) {
Johannes Berge247bd902011-11-04 11:18:21 +01009539 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
9540 if (!msg)
9541 return -ENOMEM;
Jouni Malinen026331c2010-02-15 12:53:10 +02009542
Eric W. Biederman15e47302012-09-07 20:12:54 +00009543 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berge247bd902011-11-04 11:18:21 +01009544 NL80211_CMD_FRAME);
Dan Carpentercb35fba2013-08-14 14:50:01 +03009545 if (!hdr) {
9546 err = -ENOBUFS;
Johannes Berge247bd902011-11-04 11:18:21 +01009547 goto free_msg;
9548 }
Jouni Malinen026331c2010-02-15 12:53:10 +02009549 }
Johannes Berge247bd902011-11-04 11:18:21 +01009550
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02009551 params.chan = chandef.chan;
9552 err = cfg80211_mlme_mgmt_tx(rdev, wdev, &params, &cookie);
Jouni Malinen026331c2010-02-15 12:53:10 +02009553 if (err)
9554 goto free_msg;
9555
Johannes Berge247bd902011-11-04 11:18:21 +01009556 if (msg) {
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02009557 if (nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie,
9558 NL80211_ATTR_PAD))
David S. Miller9360ffd2012-03-29 04:41:26 -04009559 goto nla_put_failure;
Jouni Malinen026331c2010-02-15 12:53:10 +02009560
Johannes Berge247bd902011-11-04 11:18:21 +01009561 genlmsg_end(msg, hdr);
9562 return genlmsg_reply(msg, info);
9563 }
9564
9565 return 0;
Jouni Malinen026331c2010-02-15 12:53:10 +02009566
9567 nla_put_failure:
9568 err = -ENOBUFS;
9569 free_msg:
9570 nlmsg_free(msg);
Jouni Malinen026331c2010-02-15 12:53:10 +02009571 return err;
9572}
9573
Johannes Bergf7ca38d2010-11-25 10:02:29 +01009574static int nl80211_tx_mgmt_cancel_wait(struct sk_buff *skb, struct genl_info *info)
9575{
9576 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02009577 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Bergf7ca38d2010-11-25 10:02:29 +01009578 u64 cookie;
9579
9580 if (!info->attrs[NL80211_ATTR_COOKIE])
9581 return -EINVAL;
9582
9583 if (!rdev->ops->mgmt_tx_cancel_wait)
9584 return -EOPNOTSUPP;
9585
Johannes Berg71bbc992012-06-15 15:30:18 +02009586 switch (wdev->iftype) {
9587 case NL80211_IFTYPE_STATION:
9588 case NL80211_IFTYPE_ADHOC:
9589 case NL80211_IFTYPE_P2P_CLIENT:
9590 case NL80211_IFTYPE_AP:
9591 case NL80211_IFTYPE_AP_VLAN:
9592 case NL80211_IFTYPE_P2P_GO:
Johannes Berg98104fde2012-06-16 00:19:54 +02009593 case NL80211_IFTYPE_P2P_DEVICE:
Johannes Berg71bbc992012-06-15 15:30:18 +02009594 break;
Ayala Bekercb3b7d82016-09-20 17:31:13 +03009595 case NL80211_IFTYPE_NAN:
Johannes Berg71bbc992012-06-15 15:30:18 +02009596 default:
Johannes Bergf7ca38d2010-11-25 10:02:29 +01009597 return -EOPNOTSUPP;
Johannes Berg71bbc992012-06-15 15:30:18 +02009598 }
Johannes Bergf7ca38d2010-11-25 10:02:29 +01009599
9600 cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]);
9601
Hila Gonene35e4d22012-06-27 17:19:42 +03009602 return rdev_mgmt_tx_cancel_wait(rdev, wdev, cookie);
Johannes Bergf7ca38d2010-11-25 10:02:29 +01009603}
9604
Kalle Valoffb9eb32010-02-17 17:58:10 +02009605static int nl80211_set_power_save(struct sk_buff *skb, struct genl_info *info)
9606{
Johannes Berg4c476992010-10-04 21:36:35 +02009607 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Kalle Valoffb9eb32010-02-17 17:58:10 +02009608 struct wireless_dev *wdev;
Johannes Berg4c476992010-10-04 21:36:35 +02009609 struct net_device *dev = info->user_ptr[1];
Kalle Valoffb9eb32010-02-17 17:58:10 +02009610 u8 ps_state;
9611 bool state;
9612 int err;
9613
Johannes Berg4c476992010-10-04 21:36:35 +02009614 if (!info->attrs[NL80211_ATTR_PS_STATE])
9615 return -EINVAL;
Kalle Valoffb9eb32010-02-17 17:58:10 +02009616
9617 ps_state = nla_get_u32(info->attrs[NL80211_ATTR_PS_STATE]);
9618
Johannes Berg4c476992010-10-04 21:36:35 +02009619 if (ps_state != NL80211_PS_DISABLED && ps_state != NL80211_PS_ENABLED)
9620 return -EINVAL;
Kalle Valoffb9eb32010-02-17 17:58:10 +02009621
9622 wdev = dev->ieee80211_ptr;
9623
Johannes Berg4c476992010-10-04 21:36:35 +02009624 if (!rdev->ops->set_power_mgmt)
9625 return -EOPNOTSUPP;
Kalle Valoffb9eb32010-02-17 17:58:10 +02009626
9627 state = (ps_state == NL80211_PS_ENABLED) ? true : false;
9628
9629 if (state == wdev->ps)
Johannes Berg4c476992010-10-04 21:36:35 +02009630 return 0;
Kalle Valoffb9eb32010-02-17 17:58:10 +02009631
Hila Gonene35e4d22012-06-27 17:19:42 +03009632 err = rdev_set_power_mgmt(rdev, dev, state, wdev->ps_timeout);
Johannes Berg4c476992010-10-04 21:36:35 +02009633 if (!err)
9634 wdev->ps = state;
Kalle Valoffb9eb32010-02-17 17:58:10 +02009635 return err;
9636}
9637
9638static int nl80211_get_power_save(struct sk_buff *skb, struct genl_info *info)
9639{
Johannes Berg4c476992010-10-04 21:36:35 +02009640 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Kalle Valoffb9eb32010-02-17 17:58:10 +02009641 enum nl80211_ps_state ps_state;
9642 struct wireless_dev *wdev;
Johannes Berg4c476992010-10-04 21:36:35 +02009643 struct net_device *dev = info->user_ptr[1];
Kalle Valoffb9eb32010-02-17 17:58:10 +02009644 struct sk_buff *msg;
9645 void *hdr;
9646 int err;
9647
Kalle Valoffb9eb32010-02-17 17:58:10 +02009648 wdev = dev->ieee80211_ptr;
9649
Johannes Berg4c476992010-10-04 21:36:35 +02009650 if (!rdev->ops->set_power_mgmt)
9651 return -EOPNOTSUPP;
Kalle Valoffb9eb32010-02-17 17:58:10 +02009652
9653 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02009654 if (!msg)
9655 return -ENOMEM;
Kalle Valoffb9eb32010-02-17 17:58:10 +02009656
Eric W. Biederman15e47302012-09-07 20:12:54 +00009657 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Kalle Valoffb9eb32010-02-17 17:58:10 +02009658 NL80211_CMD_GET_POWER_SAVE);
9659 if (!hdr) {
Johannes Berg4c476992010-10-04 21:36:35 +02009660 err = -ENOBUFS;
Kalle Valoffb9eb32010-02-17 17:58:10 +02009661 goto free_msg;
9662 }
9663
9664 if (wdev->ps)
9665 ps_state = NL80211_PS_ENABLED;
9666 else
9667 ps_state = NL80211_PS_DISABLED;
9668
David S. Miller9360ffd2012-03-29 04:41:26 -04009669 if (nla_put_u32(msg, NL80211_ATTR_PS_STATE, ps_state))
9670 goto nla_put_failure;
Kalle Valoffb9eb32010-02-17 17:58:10 +02009671
9672 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02009673 return genlmsg_reply(msg, info);
Kalle Valoffb9eb32010-02-17 17:58:10 +02009674
Johannes Berg4c476992010-10-04 21:36:35 +02009675 nla_put_failure:
Kalle Valoffb9eb32010-02-17 17:58:10 +02009676 err = -ENOBUFS;
Johannes Berg4c476992010-10-04 21:36:35 +02009677 free_msg:
Kalle Valoffb9eb32010-02-17 17:58:10 +02009678 nlmsg_free(msg);
Kalle Valoffb9eb32010-02-17 17:58:10 +02009679 return err;
9680}
9681
Johannes Berg94e860f2014-01-20 23:58:15 +01009682static const struct nla_policy
9683nl80211_attr_cqm_policy[NL80211_ATTR_CQM_MAX + 1] = {
Andrew Zaborowski4a4b8162017-02-10 10:02:31 +01009684 [NL80211_ATTR_CQM_RSSI_THOLD] = { .type = NLA_BINARY },
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02009685 [NL80211_ATTR_CQM_RSSI_HYST] = { .type = NLA_U32 },
9686 [NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT] = { .type = NLA_U32 },
Thomas Pedersen84f10702012-07-12 16:17:33 -07009687 [NL80211_ATTR_CQM_TXE_RATE] = { .type = NLA_U32 },
9688 [NL80211_ATTR_CQM_TXE_PKTS] = { .type = NLA_U32 },
9689 [NL80211_ATTR_CQM_TXE_INTVL] = { .type = NLA_U32 },
Andrzej Zaborowskibee427b2017-01-25 12:43:41 +01009690 [NL80211_ATTR_CQM_RSSI_LEVEL] = { .type = NLA_S32 },
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02009691};
9692
Thomas Pedersen84f10702012-07-12 16:17:33 -07009693static int nl80211_set_cqm_txe(struct genl_info *info,
Johannes Bergd9d8b012012-11-26 12:51:52 +01009694 u32 rate, u32 pkts, u32 intvl)
Thomas Pedersen84f10702012-07-12 16:17:33 -07009695{
9696 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Thomas Pedersen84f10702012-07-12 16:17:33 -07009697 struct net_device *dev = info->user_ptr[1];
Johannes Berg1da5fcc2013-08-06 14:10:48 +02009698 struct wireless_dev *wdev = dev->ieee80211_ptr;
Thomas Pedersen84f10702012-07-12 16:17:33 -07009699
Johannes Bergd9d8b012012-11-26 12:51:52 +01009700 if (rate > 100 || intvl > NL80211_CQM_TXE_MAX_INTVL)
Thomas Pedersen84f10702012-07-12 16:17:33 -07009701 return -EINVAL;
9702
Thomas Pedersen84f10702012-07-12 16:17:33 -07009703 if (!rdev->ops->set_cqm_txe_config)
9704 return -EOPNOTSUPP;
9705
9706 if (wdev->iftype != NL80211_IFTYPE_STATION &&
9707 wdev->iftype != NL80211_IFTYPE_P2P_CLIENT)
9708 return -EOPNOTSUPP;
9709
Hila Gonene35e4d22012-06-27 17:19:42 +03009710 return rdev_set_cqm_txe_config(rdev, dev, rate, pkts, intvl);
Thomas Pedersen84f10702012-07-12 16:17:33 -07009711}
9712
Andrew Zaborowski4a4b8162017-02-10 10:02:31 +01009713static int cfg80211_cqm_rssi_update(struct cfg80211_registered_device *rdev,
9714 struct net_device *dev)
9715{
9716 struct wireless_dev *wdev = dev->ieee80211_ptr;
9717 s32 last, low, high;
9718 u32 hyst;
9719 int i, n;
9720 int err;
9721
9722 /* RSSI reporting disabled? */
9723 if (!wdev->cqm_config)
9724 return rdev_set_cqm_rssi_range_config(rdev, dev, 0, 0);
9725
9726 /*
9727 * Obtain current RSSI value if possible, if not and no RSSI threshold
9728 * event has been received yet, we should receive an event after a
9729 * connection is established and enough beacons received to calculate
9730 * the average.
9731 */
9732 if (!wdev->cqm_config->last_rssi_event_value && wdev->current_bss &&
9733 rdev->ops->get_station) {
9734 struct station_info sinfo;
9735 u8 *mac_addr;
9736
9737 mac_addr = wdev->current_bss->pub.bssid;
9738
9739 err = rdev_get_station(rdev, dev, mac_addr, &sinfo);
9740 if (err)
9741 return err;
9742
9743 if (sinfo.filled & BIT(NL80211_STA_INFO_BEACON_SIGNAL_AVG))
9744 wdev->cqm_config->last_rssi_event_value =
9745 (s8) sinfo.rx_beacon_signal_avg;
9746 }
9747
9748 last = wdev->cqm_config->last_rssi_event_value;
9749 hyst = wdev->cqm_config->rssi_hyst;
9750 n = wdev->cqm_config->n_rssi_thresholds;
9751
9752 for (i = 0; i < n; i++)
9753 if (last < wdev->cqm_config->rssi_thresholds[i])
9754 break;
9755
9756 low = i > 0 ?
9757 (wdev->cqm_config->rssi_thresholds[i - 1] - hyst) : S32_MIN;
9758 high = i < n ?
9759 (wdev->cqm_config->rssi_thresholds[i] + hyst - 1) : S32_MAX;
9760
9761 return rdev_set_cqm_rssi_range_config(rdev, dev, low, high);
9762}
9763
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02009764static int nl80211_set_cqm_rssi(struct genl_info *info,
Andrew Zaborowski4a4b8162017-02-10 10:02:31 +01009765 const s32 *thresholds, int n_thresholds,
9766 u32 hysteresis)
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02009767{
Johannes Berg4c476992010-10-04 21:36:35 +02009768 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg4c476992010-10-04 21:36:35 +02009769 struct net_device *dev = info->user_ptr[1];
Johannes Berg1da5fcc2013-08-06 14:10:48 +02009770 struct wireless_dev *wdev = dev->ieee80211_ptr;
Andrew Zaborowski4a4b8162017-02-10 10:02:31 +01009771 int i, err;
9772 s32 prev = S32_MIN;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02009773
Andrew Zaborowski4a4b8162017-02-10 10:02:31 +01009774 /* Check all values negative and sorted */
9775 for (i = 0; i < n_thresholds; i++) {
9776 if (thresholds[i] > 0 || thresholds[i] <= prev)
9777 return -EINVAL;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02009778
Andrew Zaborowski4a4b8162017-02-10 10:02:31 +01009779 prev = thresholds[i];
9780 }
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02009781
Johannes Berg074ac8d2010-09-16 14:58:22 +02009782 if (wdev->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02009783 wdev->iftype != NL80211_IFTYPE_P2P_CLIENT)
9784 return -EOPNOTSUPP;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02009785
Andrew Zaborowski4a4b8162017-02-10 10:02:31 +01009786 wdev_lock(wdev);
9787 cfg80211_cqm_config_free(wdev);
9788 wdev_unlock(wdev);
9789
9790 if (n_thresholds <= 1 && rdev->ops->set_cqm_rssi_config) {
9791 if (n_thresholds == 0 || thresholds[0] == 0) /* Disabling */
9792 return rdev_set_cqm_rssi_config(rdev, dev, 0, 0);
9793
9794 return rdev_set_cqm_rssi_config(rdev, dev,
9795 thresholds[0], hysteresis);
9796 }
9797
9798 if (!wiphy_ext_feature_isset(&rdev->wiphy,
9799 NL80211_EXT_FEATURE_CQM_RSSI_LIST))
9800 return -EOPNOTSUPP;
9801
9802 if (n_thresholds == 1 && thresholds[0] == 0) /* Disabling */
9803 n_thresholds = 0;
9804
9805 wdev_lock(wdev);
9806 if (n_thresholds) {
9807 struct cfg80211_cqm_config *cqm_config;
9808
9809 cqm_config = kzalloc(sizeof(struct cfg80211_cqm_config) +
9810 n_thresholds * sizeof(s32), GFP_KERNEL);
9811 if (!cqm_config) {
9812 err = -ENOMEM;
9813 goto unlock;
9814 }
9815
9816 cqm_config->rssi_hyst = hysteresis;
9817 cqm_config->n_rssi_thresholds = n_thresholds;
9818 memcpy(cqm_config->rssi_thresholds, thresholds,
9819 n_thresholds * sizeof(s32));
9820
9821 wdev->cqm_config = cqm_config;
9822 }
9823
9824 err = cfg80211_cqm_rssi_update(rdev, dev);
9825
9826unlock:
9827 wdev_unlock(wdev);
9828
9829 return err;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02009830}
9831
9832static int nl80211_set_cqm(struct sk_buff *skb, struct genl_info *info)
9833{
9834 struct nlattr *attrs[NL80211_ATTR_CQM_MAX + 1];
9835 struct nlattr *cqm;
9836 int err;
9837
9838 cqm = info->attrs[NL80211_ATTR_CQM];
Johannes Berg1da5fcc2013-08-06 14:10:48 +02009839 if (!cqm)
9840 return -EINVAL;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02009841
9842 err = nla_parse_nested(attrs, NL80211_ATTR_CQM_MAX, cqm,
Johannes Bergfe521452017-04-12 14:34:08 +02009843 nl80211_attr_cqm_policy, info->extack);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02009844 if (err)
Johannes Berg1da5fcc2013-08-06 14:10:48 +02009845 return err;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02009846
9847 if (attrs[NL80211_ATTR_CQM_RSSI_THOLD] &&
9848 attrs[NL80211_ATTR_CQM_RSSI_HYST]) {
Andrew Zaborowski4a4b8162017-02-10 10:02:31 +01009849 const s32 *thresholds =
9850 nla_data(attrs[NL80211_ATTR_CQM_RSSI_THOLD]);
9851 int len = nla_len(attrs[NL80211_ATTR_CQM_RSSI_THOLD]);
Johannes Berg1da5fcc2013-08-06 14:10:48 +02009852 u32 hysteresis = nla_get_u32(attrs[NL80211_ATTR_CQM_RSSI_HYST]);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02009853
Andrew Zaborowski4a4b8162017-02-10 10:02:31 +01009854 if (len % 4)
9855 return -EINVAL;
9856
9857 return nl80211_set_cqm_rssi(info, thresholds, len / 4,
9858 hysteresis);
Johannes Berg1da5fcc2013-08-06 14:10:48 +02009859 }
9860
9861 if (attrs[NL80211_ATTR_CQM_TXE_RATE] &&
9862 attrs[NL80211_ATTR_CQM_TXE_PKTS] &&
9863 attrs[NL80211_ATTR_CQM_TXE_INTVL]) {
9864 u32 rate = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_RATE]);
9865 u32 pkts = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_PKTS]);
9866 u32 intvl = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_INTVL]);
9867
9868 return nl80211_set_cqm_txe(info, rate, pkts, intvl);
9869 }
9870
9871 return -EINVAL;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02009872}
9873
Rostislav Lisovy6e0bd6c2014-11-03 10:33:18 +01009874static int nl80211_join_ocb(struct sk_buff *skb, struct genl_info *info)
9875{
9876 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9877 struct net_device *dev = info->user_ptr[1];
9878 struct ocb_setup setup = {};
9879 int err;
9880
9881 err = nl80211_parse_chandef(rdev, info, &setup.chandef);
9882 if (err)
9883 return err;
9884
9885 return cfg80211_join_ocb(rdev, dev, &setup);
9886}
9887
9888static int nl80211_leave_ocb(struct sk_buff *skb, struct genl_info *info)
9889{
9890 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9891 struct net_device *dev = info->user_ptr[1];
9892
9893 return cfg80211_leave_ocb(rdev, dev);
9894}
9895
Johannes Berg29cbe682010-12-03 09:20:44 +01009896static int nl80211_join_mesh(struct sk_buff *skb, struct genl_info *info)
9897{
9898 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9899 struct net_device *dev = info->user_ptr[1];
9900 struct mesh_config cfg;
Javier Cardonac80d5452010-12-16 17:37:49 -08009901 struct mesh_setup setup;
Johannes Berg29cbe682010-12-03 09:20:44 +01009902 int err;
9903
9904 /* start with default */
9905 memcpy(&cfg, &default_mesh_config, sizeof(cfg));
Javier Cardonac80d5452010-12-16 17:37:49 -08009906 memcpy(&setup, &default_mesh_setup, sizeof(setup));
Johannes Berg29cbe682010-12-03 09:20:44 +01009907
Javier Cardona24bdd9f2010-12-16 17:37:48 -08009908 if (info->attrs[NL80211_ATTR_MESH_CONFIG]) {
Johannes Berg29cbe682010-12-03 09:20:44 +01009909 /* and parse parameters if given */
Javier Cardona24bdd9f2010-12-16 17:37:48 -08009910 err = nl80211_parse_mesh_config(info, &cfg, NULL);
Johannes Berg29cbe682010-12-03 09:20:44 +01009911 if (err)
9912 return err;
9913 }
9914
9915 if (!info->attrs[NL80211_ATTR_MESH_ID] ||
9916 !nla_len(info->attrs[NL80211_ATTR_MESH_ID]))
9917 return -EINVAL;
9918
Javier Cardonac80d5452010-12-16 17:37:49 -08009919 setup.mesh_id = nla_data(info->attrs[NL80211_ATTR_MESH_ID]);
9920 setup.mesh_id_len = nla_len(info->attrs[NL80211_ATTR_MESH_ID]);
9921
Chun-Yeow Yeoh4bb62342011-11-24 17:15:20 -08009922 if (info->attrs[NL80211_ATTR_MCAST_RATE] &&
9923 !nl80211_parse_mcast_rate(rdev, setup.mcast_rate,
9924 nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE])))
9925 return -EINVAL;
9926
Marco Porsch9bdbf042013-01-07 16:04:51 +01009927 if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) {
9928 setup.beacon_interval =
9929 nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]);
Purushottam Kushwaha12d20fc92016-08-11 15:14:02 +05309930
Purushottam Kushwaha0c317a02016-10-12 18:26:51 +05309931 err = cfg80211_validate_beacon_int(rdev,
9932 NL80211_IFTYPE_MESH_POINT,
9933 setup.beacon_interval);
Purushottam Kushwaha12d20fc92016-08-11 15:14:02 +05309934 if (err)
9935 return err;
Marco Porsch9bdbf042013-01-07 16:04:51 +01009936 }
9937
9938 if (info->attrs[NL80211_ATTR_DTIM_PERIOD]) {
9939 setup.dtim_period =
9940 nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]);
9941 if (setup.dtim_period < 1 || setup.dtim_period > 100)
9942 return -EINVAL;
9943 }
9944
Javier Cardonac80d5452010-12-16 17:37:49 -08009945 if (info->attrs[NL80211_ATTR_MESH_SETUP]) {
9946 /* parse additional setup parameters if given */
9947 err = nl80211_parse_mesh_setup(info, &setup);
9948 if (err)
9949 return err;
9950 }
9951
Thomas Pedersend37bb182013-03-04 13:06:13 -08009952 if (setup.user_mpm)
9953 cfg.auto_open_plinks = false;
9954
Johannes Bergcc1d2802012-05-16 23:50:20 +02009955 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
Johannes Berg683b6d32012-11-08 21:25:48 +01009956 err = nl80211_parse_chandef(rdev, info, &setup.chandef);
9957 if (err)
9958 return err;
Johannes Bergcc1d2802012-05-16 23:50:20 +02009959 } else {
9960 /* cfg80211_join_mesh() will sort it out */
Johannes Berg683b6d32012-11-08 21:25:48 +01009961 setup.chandef.chan = NULL;
Johannes Bergcc1d2802012-05-16 23:50:20 +02009962 }
9963
Ashok Nagarajanffb3cf32013-06-03 10:33:36 -07009964 if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) {
9965 u8 *rates = nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
9966 int n_rates =
9967 nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
9968 struct ieee80211_supported_band *sband;
9969
9970 if (!setup.chandef.chan)
9971 return -EINVAL;
9972
9973 sband = rdev->wiphy.bands[setup.chandef.chan->band];
9974
9975 err = ieee80211_get_ratemask(sband, rates, n_rates,
9976 &setup.basic_rates);
9977 if (err)
9978 return err;
9979 }
9980
Johannes Berg8564e382016-09-19 09:44:44 +02009981 if (info->attrs[NL80211_ATTR_TX_RATES]) {
9982 err = nl80211_parse_tx_bitrate_mask(info, &setup.beacon_rate);
9983 if (err)
9984 return err;
9985
9986 err = validate_beacon_tx_rate(rdev, setup.chandef.chan->band,
9987 &setup.beacon_rate);
9988 if (err)
9989 return err;
9990 }
9991
Benjamin Bergd37d49c2017-05-16 11:23:11 +02009992 setup.userspace_handles_dfs =
9993 nla_get_flag(info->attrs[NL80211_ATTR_HANDLE_DFS]);
9994
Javier Cardonac80d5452010-12-16 17:37:49 -08009995 return cfg80211_join_mesh(rdev, dev, &setup, &cfg);
Johannes Berg29cbe682010-12-03 09:20:44 +01009996}
9997
9998static int nl80211_leave_mesh(struct sk_buff *skb, struct genl_info *info)
9999{
10000 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10001 struct net_device *dev = info->user_ptr[1];
10002
10003 return cfg80211_leave_mesh(rdev, dev);
10004}
10005
Johannes Bergdfb89c52012-06-27 09:23:48 +020010006#ifdef CONFIG_PM
Amitkumar Karwarbb92d192013-02-12 12:16:26 -080010007static int nl80211_send_wowlan_patterns(struct sk_buff *msg,
10008 struct cfg80211_registered_device *rdev)
10009{
Johannes Berg6abb9cb2013-05-15 09:30:07 +020010010 struct cfg80211_wowlan *wowlan = rdev->wiphy.wowlan_config;
Amitkumar Karwarbb92d192013-02-12 12:16:26 -080010011 struct nlattr *nl_pats, *nl_pat;
10012 int i, pat_len;
10013
Johannes Berg6abb9cb2013-05-15 09:30:07 +020010014 if (!wowlan->n_patterns)
Amitkumar Karwarbb92d192013-02-12 12:16:26 -080010015 return 0;
10016
10017 nl_pats = nla_nest_start(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN);
10018 if (!nl_pats)
10019 return -ENOBUFS;
10020
Johannes Berg6abb9cb2013-05-15 09:30:07 +020010021 for (i = 0; i < wowlan->n_patterns; i++) {
Amitkumar Karwarbb92d192013-02-12 12:16:26 -080010022 nl_pat = nla_nest_start(msg, i + 1);
10023 if (!nl_pat)
10024 return -ENOBUFS;
Johannes Berg6abb9cb2013-05-15 09:30:07 +020010025 pat_len = wowlan->patterns[i].pattern_len;
Amitkumar Karwar50ac6602013-06-25 19:03:56 -070010026 if (nla_put(msg, NL80211_PKTPAT_MASK, DIV_ROUND_UP(pat_len, 8),
Johannes Berg6abb9cb2013-05-15 09:30:07 +020010027 wowlan->patterns[i].mask) ||
Amitkumar Karwar50ac6602013-06-25 19:03:56 -070010028 nla_put(msg, NL80211_PKTPAT_PATTERN, pat_len,
10029 wowlan->patterns[i].pattern) ||
10030 nla_put_u32(msg, NL80211_PKTPAT_OFFSET,
Johannes Berg6abb9cb2013-05-15 09:30:07 +020010031 wowlan->patterns[i].pkt_offset))
Amitkumar Karwarbb92d192013-02-12 12:16:26 -080010032 return -ENOBUFS;
10033 nla_nest_end(msg, nl_pat);
10034 }
10035 nla_nest_end(msg, nl_pats);
10036
10037 return 0;
10038}
10039
Johannes Berg2a0e0472013-01-23 22:57:40 +010010040static int nl80211_send_wowlan_tcp(struct sk_buff *msg,
10041 struct cfg80211_wowlan_tcp *tcp)
10042{
10043 struct nlattr *nl_tcp;
10044
10045 if (!tcp)
10046 return 0;
10047
10048 nl_tcp = nla_nest_start(msg, NL80211_WOWLAN_TRIG_TCP_CONNECTION);
10049 if (!nl_tcp)
10050 return -ENOBUFS;
10051
Jiri Benc930345e2015-03-29 16:59:25 +020010052 if (nla_put_in_addr(msg, NL80211_WOWLAN_TCP_SRC_IPV4, tcp->src) ||
10053 nla_put_in_addr(msg, NL80211_WOWLAN_TCP_DST_IPV4, tcp->dst) ||
Johannes Berg2a0e0472013-01-23 22:57:40 +010010054 nla_put(msg, NL80211_WOWLAN_TCP_DST_MAC, ETH_ALEN, tcp->dst_mac) ||
10055 nla_put_u16(msg, NL80211_WOWLAN_TCP_SRC_PORT, tcp->src_port) ||
10056 nla_put_u16(msg, NL80211_WOWLAN_TCP_DST_PORT, tcp->dst_port) ||
10057 nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD,
10058 tcp->payload_len, tcp->payload) ||
10059 nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_INTERVAL,
10060 tcp->data_interval) ||
10061 nla_put(msg, NL80211_WOWLAN_TCP_WAKE_PAYLOAD,
10062 tcp->wake_len, tcp->wake_data) ||
10063 nla_put(msg, NL80211_WOWLAN_TCP_WAKE_MASK,
10064 DIV_ROUND_UP(tcp->wake_len, 8), tcp->wake_mask))
10065 return -ENOBUFS;
10066
10067 if (tcp->payload_seq.len &&
10068 nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ,
10069 sizeof(tcp->payload_seq), &tcp->payload_seq))
10070 return -ENOBUFS;
10071
10072 if (tcp->payload_tok.len &&
10073 nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN,
10074 sizeof(tcp->payload_tok) + tcp->tokens_size,
10075 &tcp->payload_tok))
10076 return -ENOBUFS;
10077
Johannes Berge248ad32013-05-16 10:24:28 +020010078 nla_nest_end(msg, nl_tcp);
10079
Johannes Berg2a0e0472013-01-23 22:57:40 +010010080 return 0;
10081}
10082
Luciano Coelho75453cc2015-01-09 14:06:37 +020010083static int nl80211_send_wowlan_nd(struct sk_buff *msg,
10084 struct cfg80211_sched_scan_request *req)
10085{
Avraham Stern3b06d272015-10-12 09:51:34 +030010086 struct nlattr *nd, *freqs, *matches, *match, *scan_plans, *scan_plan;
Luciano Coelho75453cc2015-01-09 14:06:37 +020010087 int i;
10088
10089 if (!req)
10090 return 0;
10091
10092 nd = nla_nest_start(msg, NL80211_WOWLAN_TRIG_NET_DETECT);
10093 if (!nd)
10094 return -ENOBUFS;
10095
Avraham Stern3b06d272015-10-12 09:51:34 +030010096 if (req->n_scan_plans == 1 &&
10097 nla_put_u32(msg, NL80211_ATTR_SCHED_SCAN_INTERVAL,
10098 req->scan_plans[0].interval * 1000))
Luciano Coelho75453cc2015-01-09 14:06:37 +020010099 return -ENOBUFS;
10100
Luciano Coelho21fea562015-03-17 16:36:01 +020010101 if (nla_put_u32(msg, NL80211_ATTR_SCHED_SCAN_DELAY, req->delay))
10102 return -ENOBUFS;
10103
vamsi krishnabf95ecd2017-01-13 01:12:20 +020010104 if (req->relative_rssi_set) {
10105 struct nl80211_bss_select_rssi_adjust rssi_adjust;
10106
10107 if (nla_put_s8(msg, NL80211_ATTR_SCHED_SCAN_RELATIVE_RSSI,
10108 req->relative_rssi))
10109 return -ENOBUFS;
10110
10111 rssi_adjust.band = req->rssi_adjust.band;
10112 rssi_adjust.delta = req->rssi_adjust.delta;
10113 if (nla_put(msg, NL80211_ATTR_SCHED_SCAN_RSSI_ADJUST,
10114 sizeof(rssi_adjust), &rssi_adjust))
10115 return -ENOBUFS;
10116 }
10117
Luciano Coelho75453cc2015-01-09 14:06:37 +020010118 freqs = nla_nest_start(msg, NL80211_ATTR_SCAN_FREQUENCIES);
10119 if (!freqs)
10120 return -ENOBUFS;
10121
Johannes Berg53b18982016-09-14 09:59:21 +020010122 for (i = 0; i < req->n_channels; i++) {
10123 if (nla_put_u32(msg, i, req->channels[i]->center_freq))
10124 return -ENOBUFS;
10125 }
Luciano Coelho75453cc2015-01-09 14:06:37 +020010126
10127 nla_nest_end(msg, freqs);
10128
10129 if (req->n_match_sets) {
10130 matches = nla_nest_start(msg, NL80211_ATTR_SCHED_SCAN_MATCH);
Johannes Berg76e1fb42016-09-14 09:55:57 +020010131 if (!matches)
10132 return -ENOBUFS;
10133
Luciano Coelho75453cc2015-01-09 14:06:37 +020010134 for (i = 0; i < req->n_match_sets; i++) {
10135 match = nla_nest_start(msg, i);
Johannes Berg76e1fb42016-09-14 09:55:57 +020010136 if (!match)
10137 return -ENOBUFS;
10138
Johannes Berg53b18982016-09-14 09:59:21 +020010139 if (nla_put(msg, NL80211_SCHED_SCAN_MATCH_ATTR_SSID,
10140 req->match_sets[i].ssid.ssid_len,
10141 req->match_sets[i].ssid.ssid))
10142 return -ENOBUFS;
Luciano Coelho75453cc2015-01-09 14:06:37 +020010143 nla_nest_end(msg, match);
10144 }
10145 nla_nest_end(msg, matches);
10146 }
10147
Avraham Stern3b06d272015-10-12 09:51:34 +030010148 scan_plans = nla_nest_start(msg, NL80211_ATTR_SCHED_SCAN_PLANS);
10149 if (!scan_plans)
10150 return -ENOBUFS;
10151
10152 for (i = 0; i < req->n_scan_plans; i++) {
10153 scan_plan = nla_nest_start(msg, i + 1);
Johannes Berg76e1fb42016-09-14 09:55:57 +020010154 if (!scan_plan)
10155 return -ENOBUFS;
10156
Avraham Stern3b06d272015-10-12 09:51:34 +030010157 if (!scan_plan ||
10158 nla_put_u32(msg, NL80211_SCHED_SCAN_PLAN_INTERVAL,
10159 req->scan_plans[i].interval) ||
10160 (req->scan_plans[i].iterations &&
10161 nla_put_u32(msg, NL80211_SCHED_SCAN_PLAN_ITERATIONS,
10162 req->scan_plans[i].iterations)))
10163 return -ENOBUFS;
10164 nla_nest_end(msg, scan_plan);
10165 }
10166 nla_nest_end(msg, scan_plans);
10167
Luciano Coelho75453cc2015-01-09 14:06:37 +020010168 nla_nest_end(msg, nd);
10169
10170 return 0;
10171}
10172
Johannes Bergff1b6e62011-05-04 15:37:28 +020010173static int nl80211_get_wowlan(struct sk_buff *skb, struct genl_info *info)
10174{
10175 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10176 struct sk_buff *msg;
10177 void *hdr;
Johannes Berg2a0e0472013-01-23 22:57:40 +010010178 u32 size = NLMSG_DEFAULT_SIZE;
Johannes Bergff1b6e62011-05-04 15:37:28 +020010179
Johannes Berg964dc9e2013-06-03 17:25:34 +020010180 if (!rdev->wiphy.wowlan)
Johannes Bergff1b6e62011-05-04 15:37:28 +020010181 return -EOPNOTSUPP;
10182
Johannes Berg6abb9cb2013-05-15 09:30:07 +020010183 if (rdev->wiphy.wowlan_config && rdev->wiphy.wowlan_config->tcp) {
Johannes Berg2a0e0472013-01-23 22:57:40 +010010184 /* adjust size to have room for all the data */
Johannes Berg6abb9cb2013-05-15 09:30:07 +020010185 size += rdev->wiphy.wowlan_config->tcp->tokens_size +
10186 rdev->wiphy.wowlan_config->tcp->payload_len +
10187 rdev->wiphy.wowlan_config->tcp->wake_len +
10188 rdev->wiphy.wowlan_config->tcp->wake_len / 8;
Johannes Berg2a0e0472013-01-23 22:57:40 +010010189 }
10190
10191 msg = nlmsg_new(size, GFP_KERNEL);
Johannes Bergff1b6e62011-05-04 15:37:28 +020010192 if (!msg)
10193 return -ENOMEM;
10194
Eric W. Biederman15e47302012-09-07 20:12:54 +000010195 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Johannes Bergff1b6e62011-05-04 15:37:28 +020010196 NL80211_CMD_GET_WOWLAN);
10197 if (!hdr)
10198 goto nla_put_failure;
10199
Johannes Berg6abb9cb2013-05-15 09:30:07 +020010200 if (rdev->wiphy.wowlan_config) {
Johannes Bergff1b6e62011-05-04 15:37:28 +020010201 struct nlattr *nl_wowlan;
10202
10203 nl_wowlan = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS);
10204 if (!nl_wowlan)
10205 goto nla_put_failure;
10206
Johannes Berg6abb9cb2013-05-15 09:30:07 +020010207 if ((rdev->wiphy.wowlan_config->any &&
David S. Miller9360ffd2012-03-29 04:41:26 -040010208 nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +020010209 (rdev->wiphy.wowlan_config->disconnect &&
David S. Miller9360ffd2012-03-29 04:41:26 -040010210 nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +020010211 (rdev->wiphy.wowlan_config->magic_pkt &&
David S. Miller9360ffd2012-03-29 04:41:26 -040010212 nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +020010213 (rdev->wiphy.wowlan_config->gtk_rekey_failure &&
David S. Miller9360ffd2012-03-29 04:41:26 -040010214 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +020010215 (rdev->wiphy.wowlan_config->eap_identity_req &&
David S. Miller9360ffd2012-03-29 04:41:26 -040010216 nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +020010217 (rdev->wiphy.wowlan_config->four_way_handshake &&
David S. Miller9360ffd2012-03-29 04:41:26 -040010218 nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +020010219 (rdev->wiphy.wowlan_config->rfkill_release &&
David S. Miller9360ffd2012-03-29 04:41:26 -040010220 nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE)))
10221 goto nla_put_failure;
Johannes Berg2a0e0472013-01-23 22:57:40 +010010222
Amitkumar Karwarbb92d192013-02-12 12:16:26 -080010223 if (nl80211_send_wowlan_patterns(msg, rdev))
10224 goto nla_put_failure;
Johannes Berg2a0e0472013-01-23 22:57:40 +010010225
Johannes Berg6abb9cb2013-05-15 09:30:07 +020010226 if (nl80211_send_wowlan_tcp(msg,
10227 rdev->wiphy.wowlan_config->tcp))
Johannes Berg2a0e0472013-01-23 22:57:40 +010010228 goto nla_put_failure;
10229
Luciano Coelho75453cc2015-01-09 14:06:37 +020010230 if (nl80211_send_wowlan_nd(
10231 msg,
10232 rdev->wiphy.wowlan_config->nd_config))
10233 goto nla_put_failure;
10234
Johannes Bergff1b6e62011-05-04 15:37:28 +020010235 nla_nest_end(msg, nl_wowlan);
10236 }
10237
10238 genlmsg_end(msg, hdr);
10239 return genlmsg_reply(msg, info);
10240
10241nla_put_failure:
10242 nlmsg_free(msg);
10243 return -ENOBUFS;
10244}
10245
Johannes Berg2a0e0472013-01-23 22:57:40 +010010246static int nl80211_parse_wowlan_tcp(struct cfg80211_registered_device *rdev,
10247 struct nlattr *attr,
10248 struct cfg80211_wowlan *trig)
10249{
10250 struct nlattr *tb[NUM_NL80211_WOWLAN_TCP];
10251 struct cfg80211_wowlan_tcp *cfg;
10252 struct nl80211_wowlan_tcp_data_token *tok = NULL;
10253 struct nl80211_wowlan_tcp_data_seq *seq = NULL;
10254 u32 size;
10255 u32 data_size, wake_size, tokens_size = 0, wake_mask_size;
10256 int err, port;
10257
Johannes Berg964dc9e2013-06-03 17:25:34 +020010258 if (!rdev->wiphy.wowlan->tcp)
Johannes Berg2a0e0472013-01-23 22:57:40 +010010259 return -EINVAL;
10260
Johannes Bergbfe2c7b2016-10-26 14:42:21 +020010261 err = nla_parse_nested(tb, MAX_NL80211_WOWLAN_TCP, attr,
Johannes Bergfceb6432017-04-12 14:34:07 +020010262 nl80211_wowlan_tcp_policy, NULL);
Johannes Berg2a0e0472013-01-23 22:57:40 +010010263 if (err)
10264 return err;
10265
10266 if (!tb[NL80211_WOWLAN_TCP_SRC_IPV4] ||
10267 !tb[NL80211_WOWLAN_TCP_DST_IPV4] ||
10268 !tb[NL80211_WOWLAN_TCP_DST_MAC] ||
10269 !tb[NL80211_WOWLAN_TCP_DST_PORT] ||
10270 !tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD] ||
10271 !tb[NL80211_WOWLAN_TCP_DATA_INTERVAL] ||
10272 !tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD] ||
10273 !tb[NL80211_WOWLAN_TCP_WAKE_MASK])
10274 return -EINVAL;
10275
10276 data_size = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]);
Johannes Berg964dc9e2013-06-03 17:25:34 +020010277 if (data_size > rdev->wiphy.wowlan->tcp->data_payload_max)
Johannes Berg2a0e0472013-01-23 22:57:40 +010010278 return -EINVAL;
10279
10280 if (nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]) >
Johannes Berg964dc9e2013-06-03 17:25:34 +020010281 rdev->wiphy.wowlan->tcp->data_interval_max ||
Johannes Berg723d5682013-02-26 13:56:40 +010010282 nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]) == 0)
Johannes Berg2a0e0472013-01-23 22:57:40 +010010283 return -EINVAL;
10284
10285 wake_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]);
Johannes Berg964dc9e2013-06-03 17:25:34 +020010286 if (wake_size > rdev->wiphy.wowlan->tcp->wake_payload_max)
Johannes Berg2a0e0472013-01-23 22:57:40 +010010287 return -EINVAL;
10288
10289 wake_mask_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_MASK]);
10290 if (wake_mask_size != DIV_ROUND_UP(wake_size, 8))
10291 return -EINVAL;
10292
10293 if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]) {
10294 u32 tokln = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]);
10295
10296 tok = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]);
10297 tokens_size = tokln - sizeof(*tok);
10298
10299 if (!tok->len || tokens_size % tok->len)
10300 return -EINVAL;
Johannes Berg964dc9e2013-06-03 17:25:34 +020010301 if (!rdev->wiphy.wowlan->tcp->tok)
Johannes Berg2a0e0472013-01-23 22:57:40 +010010302 return -EINVAL;
Johannes Berg964dc9e2013-06-03 17:25:34 +020010303 if (tok->len > rdev->wiphy.wowlan->tcp->tok->max_len)
Johannes Berg2a0e0472013-01-23 22:57:40 +010010304 return -EINVAL;
Johannes Berg964dc9e2013-06-03 17:25:34 +020010305 if (tok->len < rdev->wiphy.wowlan->tcp->tok->min_len)
Johannes Berg2a0e0472013-01-23 22:57:40 +010010306 return -EINVAL;
Johannes Berg964dc9e2013-06-03 17:25:34 +020010307 if (tokens_size > rdev->wiphy.wowlan->tcp->tok->bufsize)
Johannes Berg2a0e0472013-01-23 22:57:40 +010010308 return -EINVAL;
10309 if (tok->offset + tok->len > data_size)
10310 return -EINVAL;
10311 }
10312
10313 if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]) {
10314 seq = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]);
Johannes Berg964dc9e2013-06-03 17:25:34 +020010315 if (!rdev->wiphy.wowlan->tcp->seq)
Johannes Berg2a0e0472013-01-23 22:57:40 +010010316 return -EINVAL;
10317 if (seq->len == 0 || seq->len > 4)
10318 return -EINVAL;
10319 if (seq->len + seq->offset > data_size)
10320 return -EINVAL;
10321 }
10322
10323 size = sizeof(*cfg);
10324 size += data_size;
10325 size += wake_size + wake_mask_size;
10326 size += tokens_size;
10327
10328 cfg = kzalloc(size, GFP_KERNEL);
10329 if (!cfg)
10330 return -ENOMEM;
Jiri Benc67b61f62015-03-29 16:59:26 +020010331 cfg->src = nla_get_in_addr(tb[NL80211_WOWLAN_TCP_SRC_IPV4]);
10332 cfg->dst = nla_get_in_addr(tb[NL80211_WOWLAN_TCP_DST_IPV4]);
Johannes Berg2a0e0472013-01-23 22:57:40 +010010333 memcpy(cfg->dst_mac, nla_data(tb[NL80211_WOWLAN_TCP_DST_MAC]),
10334 ETH_ALEN);
10335 if (tb[NL80211_WOWLAN_TCP_SRC_PORT])
10336 port = nla_get_u16(tb[NL80211_WOWLAN_TCP_SRC_PORT]);
10337 else
10338 port = 0;
10339#ifdef CONFIG_INET
10340 /* allocate a socket and port for it and use it */
10341 err = __sock_create(wiphy_net(&rdev->wiphy), PF_INET, SOCK_STREAM,
10342 IPPROTO_TCP, &cfg->sock, 1);
10343 if (err) {
10344 kfree(cfg);
10345 return err;
10346 }
10347 if (inet_csk_get_port(cfg->sock->sk, port)) {
10348 sock_release(cfg->sock);
10349 kfree(cfg);
10350 return -EADDRINUSE;
10351 }
10352 cfg->src_port = inet_sk(cfg->sock->sk)->inet_num;
10353#else
10354 if (!port) {
10355 kfree(cfg);
10356 return -EINVAL;
10357 }
10358 cfg->src_port = port;
10359#endif
10360
10361 cfg->dst_port = nla_get_u16(tb[NL80211_WOWLAN_TCP_DST_PORT]);
10362 cfg->payload_len = data_size;
10363 cfg->payload = (u8 *)cfg + sizeof(*cfg) + tokens_size;
10364 memcpy((void *)cfg->payload,
10365 nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]),
10366 data_size);
10367 if (seq)
10368 cfg->payload_seq = *seq;
10369 cfg->data_interval = nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]);
10370 cfg->wake_len = wake_size;
10371 cfg->wake_data = (u8 *)cfg + sizeof(*cfg) + tokens_size + data_size;
10372 memcpy((void *)cfg->wake_data,
10373 nla_data(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]),
10374 wake_size);
10375 cfg->wake_mask = (u8 *)cfg + sizeof(*cfg) + tokens_size +
10376 data_size + wake_size;
10377 memcpy((void *)cfg->wake_mask,
10378 nla_data(tb[NL80211_WOWLAN_TCP_WAKE_MASK]),
10379 wake_mask_size);
10380 if (tok) {
10381 cfg->tokens_size = tokens_size;
10382 memcpy(&cfg->payload_tok, tok, sizeof(*tok) + tokens_size);
10383 }
10384
10385 trig->tcp = cfg;
10386
10387 return 0;
10388}
10389
Luciano Coelho8cd4d452014-09-17 11:55:28 +030010390static int nl80211_parse_wowlan_nd(struct cfg80211_registered_device *rdev,
10391 const struct wiphy_wowlan_support *wowlan,
10392 struct nlattr *attr,
10393 struct cfg80211_wowlan *trig)
10394{
10395 struct nlattr **tb;
10396 int err;
10397
10398 tb = kzalloc(NUM_NL80211_ATTR * sizeof(*tb), GFP_KERNEL);
10399 if (!tb)
10400 return -ENOMEM;
10401
10402 if (!(wowlan->flags & WIPHY_WOWLAN_NET_DETECT)) {
10403 err = -EOPNOTSUPP;
10404 goto out;
10405 }
10406
Johannes Bergfceb6432017-04-12 14:34:07 +020010407 err = nla_parse_nested(tb, NL80211_ATTR_MAX, attr, nl80211_policy,
10408 NULL);
Luciano Coelho8cd4d452014-09-17 11:55:28 +030010409 if (err)
10410 goto out;
10411
Arend Van Sprielaad1e812017-01-27 12:27:44 +000010412 trig->nd_config = nl80211_parse_sched_scan(&rdev->wiphy, NULL, tb,
10413 wowlan->max_nd_match_sets);
Luciano Coelho8cd4d452014-09-17 11:55:28 +030010414 err = PTR_ERR_OR_ZERO(trig->nd_config);
10415 if (err)
10416 trig->nd_config = NULL;
10417
10418out:
10419 kfree(tb);
10420 return err;
10421}
10422
Johannes Bergff1b6e62011-05-04 15:37:28 +020010423static int nl80211_set_wowlan(struct sk_buff *skb, struct genl_info *info)
10424{
10425 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10426 struct nlattr *tb[NUM_NL80211_WOWLAN_TRIG];
Johannes Bergff1b6e62011-05-04 15:37:28 +020010427 struct cfg80211_wowlan new_triggers = {};
Johannes Bergae33bd82012-07-12 16:25:02 +020010428 struct cfg80211_wowlan *ntrig;
Johannes Berg964dc9e2013-06-03 17:25:34 +020010429 const struct wiphy_wowlan_support *wowlan = rdev->wiphy.wowlan;
Johannes Bergff1b6e62011-05-04 15:37:28 +020010430 int err, i;
Johannes Berg6abb9cb2013-05-15 09:30:07 +020010431 bool prev_enabled = rdev->wiphy.wowlan_config;
Johannes Berg98fc4382015-03-01 09:10:13 +020010432 bool regular = false;
Johannes Bergff1b6e62011-05-04 15:37:28 +020010433
Johannes Berg964dc9e2013-06-03 17:25:34 +020010434 if (!wowlan)
Johannes Bergff1b6e62011-05-04 15:37:28 +020010435 return -EOPNOTSUPP;
10436
Johannes Bergae33bd82012-07-12 16:25:02 +020010437 if (!info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]) {
10438 cfg80211_rdev_free_wowlan(rdev);
Johannes Berg6abb9cb2013-05-15 09:30:07 +020010439 rdev->wiphy.wowlan_config = NULL;
Johannes Bergae33bd82012-07-12 16:25:02 +020010440 goto set_wakeup;
10441 }
Johannes Bergff1b6e62011-05-04 15:37:28 +020010442
Johannes Bergbfe2c7b2016-10-26 14:42:21 +020010443 err = nla_parse_nested(tb, MAX_NL80211_WOWLAN_TRIG,
10444 info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS],
Johannes Bergfe521452017-04-12 14:34:08 +020010445 nl80211_wowlan_policy, info->extack);
Johannes Bergff1b6e62011-05-04 15:37:28 +020010446 if (err)
10447 return err;
10448
10449 if (tb[NL80211_WOWLAN_TRIG_ANY]) {
10450 if (!(wowlan->flags & WIPHY_WOWLAN_ANY))
10451 return -EINVAL;
10452 new_triggers.any = true;
10453 }
10454
10455 if (tb[NL80211_WOWLAN_TRIG_DISCONNECT]) {
10456 if (!(wowlan->flags & WIPHY_WOWLAN_DISCONNECT))
10457 return -EINVAL;
10458 new_triggers.disconnect = true;
Johannes Berg98fc4382015-03-01 09:10:13 +020010459 regular = true;
Johannes Bergff1b6e62011-05-04 15:37:28 +020010460 }
10461
10462 if (tb[NL80211_WOWLAN_TRIG_MAGIC_PKT]) {
10463 if (!(wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT))
10464 return -EINVAL;
10465 new_triggers.magic_pkt = true;
Johannes Berg98fc4382015-03-01 09:10:13 +020010466 regular = true;
Johannes Bergff1b6e62011-05-04 15:37:28 +020010467 }
10468
Johannes Berg77dbbb12011-07-13 10:48:55 +020010469 if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED])
10470 return -EINVAL;
10471
10472 if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE]) {
10473 if (!(wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE))
10474 return -EINVAL;
10475 new_triggers.gtk_rekey_failure = true;
Johannes Berg98fc4382015-03-01 09:10:13 +020010476 regular = true;
Johannes Berg77dbbb12011-07-13 10:48:55 +020010477 }
10478
10479 if (tb[NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST]) {
10480 if (!(wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ))
10481 return -EINVAL;
10482 new_triggers.eap_identity_req = true;
Johannes Berg98fc4382015-03-01 09:10:13 +020010483 regular = true;
Johannes Berg77dbbb12011-07-13 10:48:55 +020010484 }
10485
10486 if (tb[NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE]) {
10487 if (!(wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE))
10488 return -EINVAL;
10489 new_triggers.four_way_handshake = true;
Johannes Berg98fc4382015-03-01 09:10:13 +020010490 regular = true;
Johannes Berg77dbbb12011-07-13 10:48:55 +020010491 }
10492
10493 if (tb[NL80211_WOWLAN_TRIG_RFKILL_RELEASE]) {
10494 if (!(wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE))
10495 return -EINVAL;
10496 new_triggers.rfkill_release = true;
Johannes Berg98fc4382015-03-01 09:10:13 +020010497 regular = true;
Johannes Berg77dbbb12011-07-13 10:48:55 +020010498 }
10499
Johannes Bergff1b6e62011-05-04 15:37:28 +020010500 if (tb[NL80211_WOWLAN_TRIG_PKT_PATTERN]) {
10501 struct nlattr *pat;
10502 int n_patterns = 0;
Amitkumar Karwarbb92d192013-02-12 12:16:26 -080010503 int rem, pat_len, mask_len, pkt_offset;
Amitkumar Karwar50ac6602013-06-25 19:03:56 -070010504 struct nlattr *pat_tb[NUM_NL80211_PKTPAT];
Johannes Bergff1b6e62011-05-04 15:37:28 +020010505
Johannes Berg98fc4382015-03-01 09:10:13 +020010506 regular = true;
10507
Johannes Bergff1b6e62011-05-04 15:37:28 +020010508 nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN],
10509 rem)
10510 n_patterns++;
10511 if (n_patterns > wowlan->n_patterns)
10512 return -EINVAL;
10513
10514 new_triggers.patterns = kcalloc(n_patterns,
10515 sizeof(new_triggers.patterns[0]),
10516 GFP_KERNEL);
10517 if (!new_triggers.patterns)
10518 return -ENOMEM;
10519
10520 new_triggers.n_patterns = n_patterns;
10521 i = 0;
10522
10523 nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN],
10524 rem) {
Johannes Berg922bd802014-05-19 17:59:50 +020010525 u8 *mask_pat;
10526
Johannes Bergbfe2c7b2016-10-26 14:42:21 +020010527 nla_parse_nested(pat_tb, MAX_NL80211_PKTPAT, pat,
Johannes Bergfe521452017-04-12 14:34:08 +020010528 NULL, info->extack);
Johannes Bergff1b6e62011-05-04 15:37:28 +020010529 err = -EINVAL;
Amitkumar Karwar50ac6602013-06-25 19:03:56 -070010530 if (!pat_tb[NL80211_PKTPAT_MASK] ||
10531 !pat_tb[NL80211_PKTPAT_PATTERN])
Johannes Bergff1b6e62011-05-04 15:37:28 +020010532 goto error;
Amitkumar Karwar50ac6602013-06-25 19:03:56 -070010533 pat_len = nla_len(pat_tb[NL80211_PKTPAT_PATTERN]);
Johannes Bergff1b6e62011-05-04 15:37:28 +020010534 mask_len = DIV_ROUND_UP(pat_len, 8);
Amitkumar Karwar50ac6602013-06-25 19:03:56 -070010535 if (nla_len(pat_tb[NL80211_PKTPAT_MASK]) != mask_len)
Johannes Bergff1b6e62011-05-04 15:37:28 +020010536 goto error;
10537 if (pat_len > wowlan->pattern_max_len ||
10538 pat_len < wowlan->pattern_min_len)
10539 goto error;
10540
Amitkumar Karwar50ac6602013-06-25 19:03:56 -070010541 if (!pat_tb[NL80211_PKTPAT_OFFSET])
Amitkumar Karwarbb92d192013-02-12 12:16:26 -080010542 pkt_offset = 0;
10543 else
10544 pkt_offset = nla_get_u32(
Amitkumar Karwar50ac6602013-06-25 19:03:56 -070010545 pat_tb[NL80211_PKTPAT_OFFSET]);
Amitkumar Karwarbb92d192013-02-12 12:16:26 -080010546 if (pkt_offset > wowlan->max_pkt_offset)
10547 goto error;
10548 new_triggers.patterns[i].pkt_offset = pkt_offset;
10549
Johannes Berg922bd802014-05-19 17:59:50 +020010550 mask_pat = kmalloc(mask_len + pat_len, GFP_KERNEL);
10551 if (!mask_pat) {
Johannes Bergff1b6e62011-05-04 15:37:28 +020010552 err = -ENOMEM;
10553 goto error;
10554 }
Johannes Berg922bd802014-05-19 17:59:50 +020010555 new_triggers.patterns[i].mask = mask_pat;
10556 memcpy(mask_pat, nla_data(pat_tb[NL80211_PKTPAT_MASK]),
Johannes Bergff1b6e62011-05-04 15:37:28 +020010557 mask_len);
Johannes Berg922bd802014-05-19 17:59:50 +020010558 mask_pat += mask_len;
10559 new_triggers.patterns[i].pattern = mask_pat;
Johannes Bergff1b6e62011-05-04 15:37:28 +020010560 new_triggers.patterns[i].pattern_len = pat_len;
Johannes Berg922bd802014-05-19 17:59:50 +020010561 memcpy(mask_pat,
Amitkumar Karwar50ac6602013-06-25 19:03:56 -070010562 nla_data(pat_tb[NL80211_PKTPAT_PATTERN]),
Johannes Bergff1b6e62011-05-04 15:37:28 +020010563 pat_len);
10564 i++;
10565 }
10566 }
10567
Johannes Berg2a0e0472013-01-23 22:57:40 +010010568 if (tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION]) {
Johannes Berg98fc4382015-03-01 09:10:13 +020010569 regular = true;
Johannes Berg2a0e0472013-01-23 22:57:40 +010010570 err = nl80211_parse_wowlan_tcp(
10571 rdev, tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION],
10572 &new_triggers);
10573 if (err)
10574 goto error;
10575 }
10576
Luciano Coelho8cd4d452014-09-17 11:55:28 +030010577 if (tb[NL80211_WOWLAN_TRIG_NET_DETECT]) {
Johannes Berg98fc4382015-03-01 09:10:13 +020010578 regular = true;
Luciano Coelho8cd4d452014-09-17 11:55:28 +030010579 err = nl80211_parse_wowlan_nd(
10580 rdev, wowlan, tb[NL80211_WOWLAN_TRIG_NET_DETECT],
10581 &new_triggers);
10582 if (err)
10583 goto error;
10584 }
10585
Johannes Berg98fc4382015-03-01 09:10:13 +020010586 /* The 'any' trigger means the device continues operating more or less
10587 * as in its normal operation mode and wakes up the host on most of the
10588 * normal interrupts (like packet RX, ...)
10589 * It therefore makes little sense to combine with the more constrained
10590 * wakeup trigger modes.
10591 */
10592 if (new_triggers.any && regular) {
10593 err = -EINVAL;
10594 goto error;
10595 }
10596
Johannes Bergae33bd82012-07-12 16:25:02 +020010597 ntrig = kmemdup(&new_triggers, sizeof(new_triggers), GFP_KERNEL);
10598 if (!ntrig) {
10599 err = -ENOMEM;
10600 goto error;
Johannes Bergff1b6e62011-05-04 15:37:28 +020010601 }
Johannes Bergae33bd82012-07-12 16:25:02 +020010602 cfg80211_rdev_free_wowlan(rdev);
Johannes Berg6abb9cb2013-05-15 09:30:07 +020010603 rdev->wiphy.wowlan_config = ntrig;
Johannes Bergff1b6e62011-05-04 15:37:28 +020010604
Johannes Bergae33bd82012-07-12 16:25:02 +020010605 set_wakeup:
Johannes Berg6abb9cb2013-05-15 09:30:07 +020010606 if (rdev->ops->set_wakeup &&
10607 prev_enabled != !!rdev->wiphy.wowlan_config)
10608 rdev_set_wakeup(rdev, rdev->wiphy.wowlan_config);
Johannes Berg6d525632012-04-04 15:05:25 +020010609
Johannes Bergff1b6e62011-05-04 15:37:28 +020010610 return 0;
10611 error:
10612 for (i = 0; i < new_triggers.n_patterns; i++)
10613 kfree(new_triggers.patterns[i].mask);
10614 kfree(new_triggers.patterns);
Johannes Berg2a0e0472013-01-23 22:57:40 +010010615 if (new_triggers.tcp && new_triggers.tcp->sock)
10616 sock_release(new_triggers.tcp->sock);
10617 kfree(new_triggers.tcp);
Ola Olssone5dbe072015-12-12 23:17:17 +010010618 kfree(new_triggers.nd_config);
Johannes Bergff1b6e62011-05-04 15:37:28 +020010619 return err;
10620}
Johannes Bergdfb89c52012-06-27 09:23:48 +020010621#endif
Johannes Bergff1b6e62011-05-04 15:37:28 +020010622
Amitkumar Karwarbe29b99a2013-06-28 11:51:26 -070010623static int nl80211_send_coalesce_rules(struct sk_buff *msg,
10624 struct cfg80211_registered_device *rdev)
10625{
10626 struct nlattr *nl_pats, *nl_pat, *nl_rule, *nl_rules;
10627 int i, j, pat_len;
10628 struct cfg80211_coalesce_rules *rule;
10629
10630 if (!rdev->coalesce->n_rules)
10631 return 0;
10632
10633 nl_rules = nla_nest_start(msg, NL80211_ATTR_COALESCE_RULE);
10634 if (!nl_rules)
10635 return -ENOBUFS;
10636
10637 for (i = 0; i < rdev->coalesce->n_rules; i++) {
10638 nl_rule = nla_nest_start(msg, i + 1);
10639 if (!nl_rule)
10640 return -ENOBUFS;
10641
10642 rule = &rdev->coalesce->rules[i];
10643 if (nla_put_u32(msg, NL80211_ATTR_COALESCE_RULE_DELAY,
10644 rule->delay))
10645 return -ENOBUFS;
10646
10647 if (nla_put_u32(msg, NL80211_ATTR_COALESCE_RULE_CONDITION,
10648 rule->condition))
10649 return -ENOBUFS;
10650
10651 nl_pats = nla_nest_start(msg,
10652 NL80211_ATTR_COALESCE_RULE_PKT_PATTERN);
10653 if (!nl_pats)
10654 return -ENOBUFS;
10655
10656 for (j = 0; j < rule->n_patterns; j++) {
10657 nl_pat = nla_nest_start(msg, j + 1);
10658 if (!nl_pat)
10659 return -ENOBUFS;
10660 pat_len = rule->patterns[j].pattern_len;
10661 if (nla_put(msg, NL80211_PKTPAT_MASK,
10662 DIV_ROUND_UP(pat_len, 8),
10663 rule->patterns[j].mask) ||
10664 nla_put(msg, NL80211_PKTPAT_PATTERN, pat_len,
10665 rule->patterns[j].pattern) ||
10666 nla_put_u32(msg, NL80211_PKTPAT_OFFSET,
10667 rule->patterns[j].pkt_offset))
10668 return -ENOBUFS;
10669 nla_nest_end(msg, nl_pat);
10670 }
10671 nla_nest_end(msg, nl_pats);
10672 nla_nest_end(msg, nl_rule);
10673 }
10674 nla_nest_end(msg, nl_rules);
10675
10676 return 0;
10677}
10678
10679static int nl80211_get_coalesce(struct sk_buff *skb, struct genl_info *info)
10680{
10681 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10682 struct sk_buff *msg;
10683 void *hdr;
10684
10685 if (!rdev->wiphy.coalesce)
10686 return -EOPNOTSUPP;
10687
10688 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
10689 if (!msg)
10690 return -ENOMEM;
10691
10692 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
10693 NL80211_CMD_GET_COALESCE);
10694 if (!hdr)
10695 goto nla_put_failure;
10696
10697 if (rdev->coalesce && nl80211_send_coalesce_rules(msg, rdev))
10698 goto nla_put_failure;
10699
10700 genlmsg_end(msg, hdr);
10701 return genlmsg_reply(msg, info);
10702
10703nla_put_failure:
10704 nlmsg_free(msg);
10705 return -ENOBUFS;
10706}
10707
10708void cfg80211_rdev_free_coalesce(struct cfg80211_registered_device *rdev)
10709{
10710 struct cfg80211_coalesce *coalesce = rdev->coalesce;
10711 int i, j;
10712 struct cfg80211_coalesce_rules *rule;
10713
10714 if (!coalesce)
10715 return;
10716
10717 for (i = 0; i < coalesce->n_rules; i++) {
10718 rule = &coalesce->rules[i];
10719 for (j = 0; j < rule->n_patterns; j++)
10720 kfree(rule->patterns[j].mask);
10721 kfree(rule->patterns);
10722 }
10723 kfree(coalesce->rules);
10724 kfree(coalesce);
10725 rdev->coalesce = NULL;
10726}
10727
10728static int nl80211_parse_coalesce_rule(struct cfg80211_registered_device *rdev,
10729 struct nlattr *rule,
10730 struct cfg80211_coalesce_rules *new_rule)
10731{
10732 int err, i;
10733 const struct wiphy_coalesce_support *coalesce = rdev->wiphy.coalesce;
10734 struct nlattr *tb[NUM_NL80211_ATTR_COALESCE_RULE], *pat;
10735 int rem, pat_len, mask_len, pkt_offset, n_patterns = 0;
10736 struct nlattr *pat_tb[NUM_NL80211_PKTPAT];
10737
Johannes Bergbfe2c7b2016-10-26 14:42:21 +020010738 err = nla_parse_nested(tb, NL80211_ATTR_COALESCE_RULE_MAX, rule,
Johannes Bergfceb6432017-04-12 14:34:07 +020010739 nl80211_coalesce_policy, NULL);
Amitkumar Karwarbe29b99a2013-06-28 11:51:26 -070010740 if (err)
10741 return err;
10742
10743 if (tb[NL80211_ATTR_COALESCE_RULE_DELAY])
10744 new_rule->delay =
10745 nla_get_u32(tb[NL80211_ATTR_COALESCE_RULE_DELAY]);
10746 if (new_rule->delay > coalesce->max_delay)
10747 return -EINVAL;
10748
10749 if (tb[NL80211_ATTR_COALESCE_RULE_CONDITION])
10750 new_rule->condition =
10751 nla_get_u32(tb[NL80211_ATTR_COALESCE_RULE_CONDITION]);
10752 if (new_rule->condition != NL80211_COALESCE_CONDITION_MATCH &&
10753 new_rule->condition != NL80211_COALESCE_CONDITION_NO_MATCH)
10754 return -EINVAL;
10755
10756 if (!tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN])
10757 return -EINVAL;
10758
10759 nla_for_each_nested(pat, tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN],
10760 rem)
10761 n_patterns++;
10762 if (n_patterns > coalesce->n_patterns)
10763 return -EINVAL;
10764
10765 new_rule->patterns = kcalloc(n_patterns, sizeof(new_rule->patterns[0]),
10766 GFP_KERNEL);
10767 if (!new_rule->patterns)
10768 return -ENOMEM;
10769
10770 new_rule->n_patterns = n_patterns;
10771 i = 0;
10772
10773 nla_for_each_nested(pat, tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN],
10774 rem) {
Johannes Berg922bd802014-05-19 17:59:50 +020010775 u8 *mask_pat;
10776
Johannes Bergfceb6432017-04-12 14:34:07 +020010777 nla_parse_nested(pat_tb, MAX_NL80211_PKTPAT, pat, NULL, NULL);
Amitkumar Karwarbe29b99a2013-06-28 11:51:26 -070010778 if (!pat_tb[NL80211_PKTPAT_MASK] ||
10779 !pat_tb[NL80211_PKTPAT_PATTERN])
10780 return -EINVAL;
10781 pat_len = nla_len(pat_tb[NL80211_PKTPAT_PATTERN]);
10782 mask_len = DIV_ROUND_UP(pat_len, 8);
10783 if (nla_len(pat_tb[NL80211_PKTPAT_MASK]) != mask_len)
10784 return -EINVAL;
10785 if (pat_len > coalesce->pattern_max_len ||
10786 pat_len < coalesce->pattern_min_len)
10787 return -EINVAL;
10788
10789 if (!pat_tb[NL80211_PKTPAT_OFFSET])
10790 pkt_offset = 0;
10791 else
10792 pkt_offset = nla_get_u32(pat_tb[NL80211_PKTPAT_OFFSET]);
10793 if (pkt_offset > coalesce->max_pkt_offset)
10794 return -EINVAL;
10795 new_rule->patterns[i].pkt_offset = pkt_offset;
10796
Johannes Berg922bd802014-05-19 17:59:50 +020010797 mask_pat = kmalloc(mask_len + pat_len, GFP_KERNEL);
10798 if (!mask_pat)
Amitkumar Karwarbe29b99a2013-06-28 11:51:26 -070010799 return -ENOMEM;
Johannes Berg922bd802014-05-19 17:59:50 +020010800
10801 new_rule->patterns[i].mask = mask_pat;
10802 memcpy(mask_pat, nla_data(pat_tb[NL80211_PKTPAT_MASK]),
10803 mask_len);
10804
10805 mask_pat += mask_len;
10806 new_rule->patterns[i].pattern = mask_pat;
Amitkumar Karwarbe29b99a2013-06-28 11:51:26 -070010807 new_rule->patterns[i].pattern_len = pat_len;
Johannes Berg922bd802014-05-19 17:59:50 +020010808 memcpy(mask_pat, nla_data(pat_tb[NL80211_PKTPAT_PATTERN]),
10809 pat_len);
Amitkumar Karwarbe29b99a2013-06-28 11:51:26 -070010810 i++;
10811 }
10812
10813 return 0;
10814}
10815
10816static int nl80211_set_coalesce(struct sk_buff *skb, struct genl_info *info)
10817{
10818 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10819 const struct wiphy_coalesce_support *coalesce = rdev->wiphy.coalesce;
10820 struct cfg80211_coalesce new_coalesce = {};
10821 struct cfg80211_coalesce *n_coalesce;
10822 int err, rem_rule, n_rules = 0, i, j;
10823 struct nlattr *rule;
10824 struct cfg80211_coalesce_rules *tmp_rule;
10825
10826 if (!rdev->wiphy.coalesce || !rdev->ops->set_coalesce)
10827 return -EOPNOTSUPP;
10828
10829 if (!info->attrs[NL80211_ATTR_COALESCE_RULE]) {
10830 cfg80211_rdev_free_coalesce(rdev);
Ilan Peera1056b1b2015-10-22 22:27:46 +030010831 rdev_set_coalesce(rdev, NULL);
Amitkumar Karwarbe29b99a2013-06-28 11:51:26 -070010832 return 0;
10833 }
10834
10835 nla_for_each_nested(rule, info->attrs[NL80211_ATTR_COALESCE_RULE],
10836 rem_rule)
10837 n_rules++;
10838 if (n_rules > coalesce->n_rules)
10839 return -EINVAL;
10840
10841 new_coalesce.rules = kcalloc(n_rules, sizeof(new_coalesce.rules[0]),
10842 GFP_KERNEL);
10843 if (!new_coalesce.rules)
10844 return -ENOMEM;
10845
10846 new_coalesce.n_rules = n_rules;
10847 i = 0;
10848
10849 nla_for_each_nested(rule, info->attrs[NL80211_ATTR_COALESCE_RULE],
10850 rem_rule) {
10851 err = nl80211_parse_coalesce_rule(rdev, rule,
10852 &new_coalesce.rules[i]);
10853 if (err)
10854 goto error;
10855
10856 i++;
10857 }
10858
Ilan Peera1056b1b2015-10-22 22:27:46 +030010859 err = rdev_set_coalesce(rdev, &new_coalesce);
Amitkumar Karwarbe29b99a2013-06-28 11:51:26 -070010860 if (err)
10861 goto error;
10862
10863 n_coalesce = kmemdup(&new_coalesce, sizeof(new_coalesce), GFP_KERNEL);
10864 if (!n_coalesce) {
10865 err = -ENOMEM;
10866 goto error;
10867 }
10868 cfg80211_rdev_free_coalesce(rdev);
10869 rdev->coalesce = n_coalesce;
10870
10871 return 0;
10872error:
10873 for (i = 0; i < new_coalesce.n_rules; i++) {
10874 tmp_rule = &new_coalesce.rules[i];
10875 for (j = 0; j < tmp_rule->n_patterns; j++)
10876 kfree(tmp_rule->patterns[j].mask);
10877 kfree(tmp_rule->patterns);
10878 }
10879 kfree(new_coalesce.rules);
10880
10881 return err;
10882}
10883
Johannes Berge5497d72011-07-05 16:35:40 +020010884static int nl80211_set_rekey_data(struct sk_buff *skb, struct genl_info *info)
10885{
10886 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10887 struct net_device *dev = info->user_ptr[1];
10888 struct wireless_dev *wdev = dev->ieee80211_ptr;
10889 struct nlattr *tb[NUM_NL80211_REKEY_DATA];
10890 struct cfg80211_gtk_rekey_data rekey_data;
10891 int err;
10892
10893 if (!info->attrs[NL80211_ATTR_REKEY_DATA])
10894 return -EINVAL;
10895
Johannes Bergbfe2c7b2016-10-26 14:42:21 +020010896 err = nla_parse_nested(tb, MAX_NL80211_REKEY_DATA,
10897 info->attrs[NL80211_ATTR_REKEY_DATA],
Johannes Bergfe521452017-04-12 14:34:08 +020010898 nl80211_rekey_policy, info->extack);
Johannes Berge5497d72011-07-05 16:35:40 +020010899 if (err)
10900 return err;
10901
10902 if (nla_len(tb[NL80211_REKEY_DATA_REPLAY_CTR]) != NL80211_REPLAY_CTR_LEN)
10903 return -ERANGE;
10904 if (nla_len(tb[NL80211_REKEY_DATA_KEK]) != NL80211_KEK_LEN)
10905 return -ERANGE;
10906 if (nla_len(tb[NL80211_REKEY_DATA_KCK]) != NL80211_KCK_LEN)
10907 return -ERANGE;
10908
Johannes Berg78f686c2014-09-10 22:28:06 +030010909 rekey_data.kek = nla_data(tb[NL80211_REKEY_DATA_KEK]);
10910 rekey_data.kck = nla_data(tb[NL80211_REKEY_DATA_KCK]);
10911 rekey_data.replay_ctr = nla_data(tb[NL80211_REKEY_DATA_REPLAY_CTR]);
Johannes Berge5497d72011-07-05 16:35:40 +020010912
10913 wdev_lock(wdev);
10914 if (!wdev->current_bss) {
10915 err = -ENOTCONN;
10916 goto out;
10917 }
10918
10919 if (!rdev->ops->set_rekey_data) {
10920 err = -EOPNOTSUPP;
10921 goto out;
10922 }
10923
Hila Gonene35e4d22012-06-27 17:19:42 +030010924 err = rdev_set_rekey_data(rdev, dev, &rekey_data);
Johannes Berge5497d72011-07-05 16:35:40 +020010925 out:
10926 wdev_unlock(wdev);
10927 return err;
10928}
10929
Johannes Berg28946da2011-11-04 11:18:12 +010010930static int nl80211_register_unexpected_frame(struct sk_buff *skb,
10931 struct genl_info *info)
10932{
10933 struct net_device *dev = info->user_ptr[1];
10934 struct wireless_dev *wdev = dev->ieee80211_ptr;
10935
10936 if (wdev->iftype != NL80211_IFTYPE_AP &&
10937 wdev->iftype != NL80211_IFTYPE_P2P_GO)
10938 return -EINVAL;
10939
Eric W. Biederman15e47302012-09-07 20:12:54 +000010940 if (wdev->ap_unexpected_nlportid)
Johannes Berg28946da2011-11-04 11:18:12 +010010941 return -EBUSY;
10942
Eric W. Biederman15e47302012-09-07 20:12:54 +000010943 wdev->ap_unexpected_nlportid = info->snd_portid;
Johannes Berg28946da2011-11-04 11:18:12 +010010944 return 0;
10945}
10946
Johannes Berg7f6cf312011-11-04 11:18:15 +010010947static int nl80211_probe_client(struct sk_buff *skb,
10948 struct genl_info *info)
10949{
10950 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10951 struct net_device *dev = info->user_ptr[1];
10952 struct wireless_dev *wdev = dev->ieee80211_ptr;
10953 struct sk_buff *msg;
10954 void *hdr;
10955 const u8 *addr;
10956 u64 cookie;
10957 int err;
10958
10959 if (wdev->iftype != NL80211_IFTYPE_AP &&
10960 wdev->iftype != NL80211_IFTYPE_P2P_GO)
10961 return -EOPNOTSUPP;
10962
10963 if (!info->attrs[NL80211_ATTR_MAC])
10964 return -EINVAL;
10965
10966 if (!rdev->ops->probe_client)
10967 return -EOPNOTSUPP;
10968
10969 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
10970 if (!msg)
10971 return -ENOMEM;
10972
Eric W. Biederman15e47302012-09-07 20:12:54 +000010973 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berg7f6cf312011-11-04 11:18:15 +010010974 NL80211_CMD_PROBE_CLIENT);
Dan Carpentercb35fba2013-08-14 14:50:01 +030010975 if (!hdr) {
10976 err = -ENOBUFS;
Johannes Berg7f6cf312011-11-04 11:18:15 +010010977 goto free_msg;
10978 }
10979
10980 addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
10981
Hila Gonene35e4d22012-06-27 17:19:42 +030010982 err = rdev_probe_client(rdev, dev, addr, &cookie);
Johannes Berg7f6cf312011-11-04 11:18:15 +010010983 if (err)
10984 goto free_msg;
10985
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020010986 if (nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie,
10987 NL80211_ATTR_PAD))
David S. Miller9360ffd2012-03-29 04:41:26 -040010988 goto nla_put_failure;
Johannes Berg7f6cf312011-11-04 11:18:15 +010010989
10990 genlmsg_end(msg, hdr);
10991
10992 return genlmsg_reply(msg, info);
10993
10994 nla_put_failure:
10995 err = -ENOBUFS;
10996 free_msg:
10997 nlmsg_free(msg);
10998 return err;
10999}
11000
Johannes Berg5e760232011-11-04 11:18:17 +010011001static int nl80211_register_beacons(struct sk_buff *skb, struct genl_info *info)
11002{
11003 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Ben Greear37c73b52012-10-26 14:49:25 -070011004 struct cfg80211_beacon_registration *reg, *nreg;
11005 int rv;
Johannes Berg5e760232011-11-04 11:18:17 +010011006
11007 if (!(rdev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS))
11008 return -EOPNOTSUPP;
11009
Ben Greear37c73b52012-10-26 14:49:25 -070011010 nreg = kzalloc(sizeof(*nreg), GFP_KERNEL);
11011 if (!nreg)
11012 return -ENOMEM;
Johannes Berg5e760232011-11-04 11:18:17 +010011013
Ben Greear37c73b52012-10-26 14:49:25 -070011014 /* First, check if already registered. */
11015 spin_lock_bh(&rdev->beacon_registrations_lock);
11016 list_for_each_entry(reg, &rdev->beacon_registrations, list) {
11017 if (reg->nlportid == info->snd_portid) {
11018 rv = -EALREADY;
11019 goto out_err;
11020 }
11021 }
11022 /* Add it to the list */
11023 nreg->nlportid = info->snd_portid;
11024 list_add(&nreg->list, &rdev->beacon_registrations);
11025
11026 spin_unlock_bh(&rdev->beacon_registrations_lock);
Johannes Berg5e760232011-11-04 11:18:17 +010011027
11028 return 0;
Ben Greear37c73b52012-10-26 14:49:25 -070011029out_err:
11030 spin_unlock_bh(&rdev->beacon_registrations_lock);
11031 kfree(nreg);
11032 return rv;
Johannes Berg5e760232011-11-04 11:18:17 +010011033}
11034
Johannes Berg98104fde2012-06-16 00:19:54 +020011035static int nl80211_start_p2p_device(struct sk_buff *skb, struct genl_info *info)
11036{
11037 struct cfg80211_registered_device *rdev = info->user_ptr[0];
11038 struct wireless_dev *wdev = info->user_ptr[1];
11039 int err;
11040
11041 if (!rdev->ops->start_p2p_device)
11042 return -EOPNOTSUPP;
11043
11044 if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE)
11045 return -EOPNOTSUPP;
11046
Arend Van Spriel73c7da32016-10-20 20:08:22 +010011047 if (wdev_running(wdev))
Johannes Berg98104fde2012-06-16 00:19:54 +020011048 return 0;
11049
Luciano Coelhob6a55012014-02-27 11:07:21 +020011050 if (rfkill_blocked(rdev->rfkill))
11051 return -ERFKILL;
Johannes Berg98104fde2012-06-16 00:19:54 +020011052
Johannes Bergeeb126e2012-10-23 15:16:50 +020011053 err = rdev_start_p2p_device(rdev, wdev);
Johannes Berg98104fde2012-06-16 00:19:54 +020011054 if (err)
11055 return err;
11056
Arend Van Spriel73c7da32016-10-20 20:08:22 +010011057 wdev->is_running = true;
Johannes Berg98104fde2012-06-16 00:19:54 +020011058 rdev->opencount++;
Johannes Berg98104fde2012-06-16 00:19:54 +020011059
11060 return 0;
11061}
11062
11063static int nl80211_stop_p2p_device(struct sk_buff *skb, struct genl_info *info)
11064{
11065 struct cfg80211_registered_device *rdev = info->user_ptr[0];
11066 struct wireless_dev *wdev = info->user_ptr[1];
11067
11068 if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE)
11069 return -EOPNOTSUPP;
11070
11071 if (!rdev->ops->stop_p2p_device)
11072 return -EOPNOTSUPP;
11073
Johannes Bergf9f47522013-03-19 15:04:07 +010011074 cfg80211_stop_p2p_device(rdev, wdev);
Johannes Berg98104fde2012-06-16 00:19:54 +020011075
11076 return 0;
11077}
11078
Ayala Bekercb3b7d82016-09-20 17:31:13 +030011079static int nl80211_start_nan(struct sk_buff *skb, struct genl_info *info)
11080{
11081 struct cfg80211_registered_device *rdev = info->user_ptr[0];
11082 struct wireless_dev *wdev = info->user_ptr[1];
11083 struct cfg80211_nan_conf conf = {};
11084 int err;
11085
11086 if (wdev->iftype != NL80211_IFTYPE_NAN)
11087 return -EOPNOTSUPP;
11088
Johannes Bergeeb04a92016-11-21 13:55:48 +010011089 if (wdev_running(wdev))
Ayala Bekercb3b7d82016-09-20 17:31:13 +030011090 return -EEXIST;
11091
11092 if (rfkill_blocked(rdev->rfkill))
11093 return -ERFKILL;
11094
11095 if (!info->attrs[NL80211_ATTR_NAN_MASTER_PREF])
11096 return -EINVAL;
11097
Ayala Bekercb3b7d82016-09-20 17:31:13 +030011098 conf.master_pref =
11099 nla_get_u8(info->attrs[NL80211_ATTR_NAN_MASTER_PREF]);
11100 if (!conf.master_pref)
11101 return -EINVAL;
11102
Luca Coelho85859892017-02-08 15:00:34 +020011103 if (info->attrs[NL80211_ATTR_BANDS]) {
11104 u32 bands = nla_get_u32(info->attrs[NL80211_ATTR_BANDS]);
11105
11106 if (bands & ~(u32)wdev->wiphy->nan_supported_bands)
11107 return -EOPNOTSUPP;
11108
11109 if (bands && !(bands & BIT(NL80211_BAND_2GHZ)))
11110 return -EINVAL;
11111
11112 conf.bands = bands;
11113 }
Ayala Bekercb3b7d82016-09-20 17:31:13 +030011114
11115 err = rdev_start_nan(rdev, wdev, &conf);
11116 if (err)
11117 return err;
11118
Arend Van Spriel73c7da32016-10-20 20:08:22 +010011119 wdev->is_running = true;
Ayala Bekercb3b7d82016-09-20 17:31:13 +030011120 rdev->opencount++;
11121
11122 return 0;
11123}
11124
11125static int nl80211_stop_nan(struct sk_buff *skb, struct genl_info *info)
11126{
11127 struct cfg80211_registered_device *rdev = info->user_ptr[0];
11128 struct wireless_dev *wdev = info->user_ptr[1];
11129
11130 if (wdev->iftype != NL80211_IFTYPE_NAN)
11131 return -EOPNOTSUPP;
11132
11133 cfg80211_stop_nan(rdev, wdev);
11134
11135 return 0;
11136}
11137
Ayala Bekera442b762016-09-20 17:31:15 +030011138static int validate_nan_filter(struct nlattr *filter_attr)
11139{
11140 struct nlattr *attr;
11141 int len = 0, n_entries = 0, rem;
11142
11143 nla_for_each_nested(attr, filter_attr, rem) {
11144 len += nla_len(attr);
11145 n_entries++;
11146 }
11147
11148 if (len >= U8_MAX)
11149 return -EINVAL;
11150
11151 return n_entries;
11152}
11153
11154static int handle_nan_filter(struct nlattr *attr_filter,
11155 struct cfg80211_nan_func *func,
11156 bool tx)
11157{
11158 struct nlattr *attr;
11159 int n_entries, rem, i;
11160 struct cfg80211_nan_func_filter *filter;
11161
11162 n_entries = validate_nan_filter(attr_filter);
11163 if (n_entries < 0)
11164 return n_entries;
11165
11166 BUILD_BUG_ON(sizeof(*func->rx_filters) != sizeof(*func->tx_filters));
11167
11168 filter = kcalloc(n_entries, sizeof(*func->rx_filters), GFP_KERNEL);
11169 if (!filter)
11170 return -ENOMEM;
11171
11172 i = 0;
11173 nla_for_each_nested(attr, attr_filter, rem) {
Thomas Grafb15ca182016-10-26 10:53:16 +020011174 filter[i].filter = nla_memdup(attr, GFP_KERNEL);
Ayala Bekera442b762016-09-20 17:31:15 +030011175 filter[i].len = nla_len(attr);
11176 i++;
11177 }
11178 if (tx) {
11179 func->num_tx_filters = n_entries;
11180 func->tx_filters = filter;
11181 } else {
11182 func->num_rx_filters = n_entries;
11183 func->rx_filters = filter;
11184 }
11185
11186 return 0;
11187}
11188
11189static int nl80211_nan_add_func(struct sk_buff *skb,
11190 struct genl_info *info)
11191{
11192 struct cfg80211_registered_device *rdev = info->user_ptr[0];
11193 struct wireless_dev *wdev = info->user_ptr[1];
11194 struct nlattr *tb[NUM_NL80211_NAN_FUNC_ATTR], *func_attr;
11195 struct cfg80211_nan_func *func;
11196 struct sk_buff *msg = NULL;
11197 void *hdr = NULL;
11198 int err = 0;
11199
11200 if (wdev->iftype != NL80211_IFTYPE_NAN)
11201 return -EOPNOTSUPP;
11202
Arend Van Spriel73c7da32016-10-20 20:08:22 +010011203 if (!wdev_running(wdev))
Ayala Bekera442b762016-09-20 17:31:15 +030011204 return -ENOTCONN;
11205
11206 if (!info->attrs[NL80211_ATTR_NAN_FUNC])
11207 return -EINVAL;
11208
11209 if (wdev->owner_nlportid &&
11210 wdev->owner_nlportid != info->snd_portid)
11211 return -ENOTCONN;
11212
Johannes Bergbfe2c7b2016-10-26 14:42:21 +020011213 err = nla_parse_nested(tb, NL80211_NAN_FUNC_ATTR_MAX,
11214 info->attrs[NL80211_ATTR_NAN_FUNC],
Johannes Bergfe521452017-04-12 14:34:08 +020011215 nl80211_nan_func_policy, info->extack);
Ayala Bekera442b762016-09-20 17:31:15 +030011216 if (err)
11217 return err;
11218
11219 func = kzalloc(sizeof(*func), GFP_KERNEL);
11220 if (!func)
11221 return -ENOMEM;
11222
11223 func->cookie = wdev->wiphy->cookie_counter++;
11224
11225 if (!tb[NL80211_NAN_FUNC_TYPE] ||
11226 nla_get_u8(tb[NL80211_NAN_FUNC_TYPE]) > NL80211_NAN_FUNC_MAX_TYPE) {
11227 err = -EINVAL;
11228 goto out;
11229 }
11230
11231
11232 func->type = nla_get_u8(tb[NL80211_NAN_FUNC_TYPE]);
11233
11234 if (!tb[NL80211_NAN_FUNC_SERVICE_ID]) {
11235 err = -EINVAL;
11236 goto out;
11237 }
11238
11239 memcpy(func->service_id, nla_data(tb[NL80211_NAN_FUNC_SERVICE_ID]),
11240 sizeof(func->service_id));
11241
11242 func->close_range =
11243 nla_get_flag(tb[NL80211_NAN_FUNC_CLOSE_RANGE]);
11244
11245 if (tb[NL80211_NAN_FUNC_SERVICE_INFO]) {
11246 func->serv_spec_info_len =
11247 nla_len(tb[NL80211_NAN_FUNC_SERVICE_INFO]);
11248 func->serv_spec_info =
11249 kmemdup(nla_data(tb[NL80211_NAN_FUNC_SERVICE_INFO]),
11250 func->serv_spec_info_len,
11251 GFP_KERNEL);
11252 if (!func->serv_spec_info) {
11253 err = -ENOMEM;
11254 goto out;
11255 }
11256 }
11257
11258 if (tb[NL80211_NAN_FUNC_TTL])
11259 func->ttl = nla_get_u32(tb[NL80211_NAN_FUNC_TTL]);
11260
11261 switch (func->type) {
11262 case NL80211_NAN_FUNC_PUBLISH:
11263 if (!tb[NL80211_NAN_FUNC_PUBLISH_TYPE]) {
11264 err = -EINVAL;
11265 goto out;
11266 }
11267
11268 func->publish_type =
11269 nla_get_u8(tb[NL80211_NAN_FUNC_PUBLISH_TYPE]);
11270 func->publish_bcast =
11271 nla_get_flag(tb[NL80211_NAN_FUNC_PUBLISH_BCAST]);
11272
11273 if ((!(func->publish_type & NL80211_NAN_SOLICITED_PUBLISH)) &&
11274 func->publish_bcast) {
11275 err = -EINVAL;
11276 goto out;
11277 }
11278 break;
11279 case NL80211_NAN_FUNC_SUBSCRIBE:
11280 func->subscribe_active =
11281 nla_get_flag(tb[NL80211_NAN_FUNC_SUBSCRIBE_ACTIVE]);
11282 break;
11283 case NL80211_NAN_FUNC_FOLLOW_UP:
11284 if (!tb[NL80211_NAN_FUNC_FOLLOW_UP_ID] ||
11285 !tb[NL80211_NAN_FUNC_FOLLOW_UP_REQ_ID]) {
11286 err = -EINVAL;
11287 goto out;
11288 }
11289
11290 func->followup_id =
11291 nla_get_u8(tb[NL80211_NAN_FUNC_FOLLOW_UP_ID]);
11292 func->followup_reqid =
11293 nla_get_u8(tb[NL80211_NAN_FUNC_FOLLOW_UP_REQ_ID]);
11294 memcpy(func->followup_dest.addr,
11295 nla_data(tb[NL80211_NAN_FUNC_FOLLOW_UP_DEST]),
11296 sizeof(func->followup_dest.addr));
11297 if (func->ttl) {
11298 err = -EINVAL;
11299 goto out;
11300 }
11301 break;
11302 default:
11303 err = -EINVAL;
11304 goto out;
11305 }
11306
11307 if (tb[NL80211_NAN_FUNC_SRF]) {
11308 struct nlattr *srf_tb[NUM_NL80211_NAN_SRF_ATTR];
11309
Johannes Bergbfe2c7b2016-10-26 14:42:21 +020011310 err = nla_parse_nested(srf_tb, NL80211_NAN_SRF_ATTR_MAX,
11311 tb[NL80211_NAN_FUNC_SRF],
Johannes Bergfe521452017-04-12 14:34:08 +020011312 nl80211_nan_srf_policy, info->extack);
Ayala Bekera442b762016-09-20 17:31:15 +030011313 if (err)
11314 goto out;
11315
11316 func->srf_include =
11317 nla_get_flag(srf_tb[NL80211_NAN_SRF_INCLUDE]);
11318
11319 if (srf_tb[NL80211_NAN_SRF_BF]) {
11320 if (srf_tb[NL80211_NAN_SRF_MAC_ADDRS] ||
11321 !srf_tb[NL80211_NAN_SRF_BF_IDX]) {
11322 err = -EINVAL;
11323 goto out;
11324 }
11325
11326 func->srf_bf_len =
11327 nla_len(srf_tb[NL80211_NAN_SRF_BF]);
11328 func->srf_bf =
11329 kmemdup(nla_data(srf_tb[NL80211_NAN_SRF_BF]),
11330 func->srf_bf_len, GFP_KERNEL);
11331 if (!func->srf_bf) {
11332 err = -ENOMEM;
11333 goto out;
11334 }
11335
11336 func->srf_bf_idx =
11337 nla_get_u8(srf_tb[NL80211_NAN_SRF_BF_IDX]);
11338 } else {
11339 struct nlattr *attr, *mac_attr =
11340 srf_tb[NL80211_NAN_SRF_MAC_ADDRS];
11341 int n_entries, rem, i = 0;
11342
11343 if (!mac_attr) {
11344 err = -EINVAL;
11345 goto out;
11346 }
11347
11348 n_entries = validate_acl_mac_addrs(mac_attr);
11349 if (n_entries <= 0) {
11350 err = -EINVAL;
11351 goto out;
11352 }
11353
11354 func->srf_num_macs = n_entries;
11355 func->srf_macs =
11356 kzalloc(sizeof(*func->srf_macs) * n_entries,
11357 GFP_KERNEL);
11358 if (!func->srf_macs) {
11359 err = -ENOMEM;
11360 goto out;
11361 }
11362
11363 nla_for_each_nested(attr, mac_attr, rem)
11364 memcpy(func->srf_macs[i++].addr, nla_data(attr),
11365 sizeof(*func->srf_macs));
11366 }
11367 }
11368
11369 if (tb[NL80211_NAN_FUNC_TX_MATCH_FILTER]) {
11370 err = handle_nan_filter(tb[NL80211_NAN_FUNC_TX_MATCH_FILTER],
11371 func, true);
11372 if (err)
11373 goto out;
11374 }
11375
11376 if (tb[NL80211_NAN_FUNC_RX_MATCH_FILTER]) {
11377 err = handle_nan_filter(tb[NL80211_NAN_FUNC_RX_MATCH_FILTER],
11378 func, false);
11379 if (err)
11380 goto out;
11381 }
11382
11383 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
11384 if (!msg) {
11385 err = -ENOMEM;
11386 goto out;
11387 }
11388
11389 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
11390 NL80211_CMD_ADD_NAN_FUNCTION);
11391 /* This can't really happen - we just allocated 4KB */
11392 if (WARN_ON(!hdr)) {
11393 err = -ENOMEM;
11394 goto out;
11395 }
11396
11397 err = rdev_add_nan_func(rdev, wdev, func);
11398out:
11399 if (err < 0) {
11400 cfg80211_free_nan_func(func);
11401 nlmsg_free(msg);
11402 return err;
11403 }
11404
11405 /* propagate the instance id and cookie to userspace */
11406 if (nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, func->cookie,
11407 NL80211_ATTR_PAD))
11408 goto nla_put_failure;
11409
11410 func_attr = nla_nest_start(msg, NL80211_ATTR_NAN_FUNC);
11411 if (!func_attr)
11412 goto nla_put_failure;
11413
11414 if (nla_put_u8(msg, NL80211_NAN_FUNC_INSTANCE_ID,
11415 func->instance_id))
11416 goto nla_put_failure;
11417
11418 nla_nest_end(msg, func_attr);
11419
11420 genlmsg_end(msg, hdr);
11421 return genlmsg_reply(msg, info);
11422
11423nla_put_failure:
11424 nlmsg_free(msg);
11425 return -ENOBUFS;
11426}
11427
11428static int nl80211_nan_del_func(struct sk_buff *skb,
11429 struct genl_info *info)
11430{
11431 struct cfg80211_registered_device *rdev = info->user_ptr[0];
11432 struct wireless_dev *wdev = info->user_ptr[1];
11433 u64 cookie;
11434
11435 if (wdev->iftype != NL80211_IFTYPE_NAN)
11436 return -EOPNOTSUPP;
11437
Arend Van Spriel73c7da32016-10-20 20:08:22 +010011438 if (!wdev_running(wdev))
Ayala Bekera442b762016-09-20 17:31:15 +030011439 return -ENOTCONN;
11440
11441 if (!info->attrs[NL80211_ATTR_COOKIE])
11442 return -EINVAL;
11443
11444 if (wdev->owner_nlportid &&
11445 wdev->owner_nlportid != info->snd_portid)
11446 return -ENOTCONN;
11447
11448 cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]);
11449
11450 rdev_del_nan_func(rdev, wdev, cookie);
11451
11452 return 0;
11453}
11454
Ayala Bekera5a9dcf2016-09-20 17:31:16 +030011455static int nl80211_nan_change_config(struct sk_buff *skb,
11456 struct genl_info *info)
11457{
11458 struct cfg80211_registered_device *rdev = info->user_ptr[0];
11459 struct wireless_dev *wdev = info->user_ptr[1];
11460 struct cfg80211_nan_conf conf = {};
11461 u32 changed = 0;
11462
11463 if (wdev->iftype != NL80211_IFTYPE_NAN)
11464 return -EOPNOTSUPP;
11465
Arend Van Spriel73c7da32016-10-20 20:08:22 +010011466 if (!wdev_running(wdev))
Ayala Bekera5a9dcf2016-09-20 17:31:16 +030011467 return -ENOTCONN;
11468
11469 if (info->attrs[NL80211_ATTR_NAN_MASTER_PREF]) {
11470 conf.master_pref =
11471 nla_get_u8(info->attrs[NL80211_ATTR_NAN_MASTER_PREF]);
11472 if (conf.master_pref <= 1 || conf.master_pref == 255)
11473 return -EINVAL;
11474
11475 changed |= CFG80211_NAN_CONF_CHANGED_PREF;
11476 }
11477
Luca Coelho85859892017-02-08 15:00:34 +020011478 if (info->attrs[NL80211_ATTR_BANDS]) {
11479 u32 bands = nla_get_u32(info->attrs[NL80211_ATTR_BANDS]);
11480
11481 if (bands & ~(u32)wdev->wiphy->nan_supported_bands)
11482 return -EOPNOTSUPP;
11483
11484 if (bands && !(bands & BIT(NL80211_BAND_2GHZ)))
11485 return -EINVAL;
11486
11487 conf.bands = bands;
11488 changed |= CFG80211_NAN_CONF_CHANGED_BANDS;
Ayala Bekera5a9dcf2016-09-20 17:31:16 +030011489 }
11490
11491 if (!changed)
11492 return -EINVAL;
11493
11494 return rdev_nan_change_conf(rdev, wdev, &conf, changed);
11495}
11496
Ayala Beker50bcd312016-09-20 17:31:17 +030011497void cfg80211_nan_match(struct wireless_dev *wdev,
11498 struct cfg80211_nan_match_params *match, gfp_t gfp)
11499{
11500 struct wiphy *wiphy = wdev->wiphy;
11501 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
11502 struct nlattr *match_attr, *local_func_attr, *peer_func_attr;
11503 struct sk_buff *msg;
11504 void *hdr;
11505
11506 if (WARN_ON(!match->inst_id || !match->peer_inst_id || !match->addr))
11507 return;
11508
11509 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
11510 if (!msg)
11511 return;
11512
11513 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NAN_MATCH);
11514 if (!hdr) {
11515 nlmsg_free(msg);
11516 return;
11517 }
11518
11519 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
11520 (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
11521 wdev->netdev->ifindex)) ||
11522 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
11523 NL80211_ATTR_PAD))
11524 goto nla_put_failure;
11525
11526 if (nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, match->cookie,
11527 NL80211_ATTR_PAD) ||
11528 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, match->addr))
11529 goto nla_put_failure;
11530
11531 match_attr = nla_nest_start(msg, NL80211_ATTR_NAN_MATCH);
11532 if (!match_attr)
11533 goto nla_put_failure;
11534
11535 local_func_attr = nla_nest_start(msg, NL80211_NAN_MATCH_FUNC_LOCAL);
11536 if (!local_func_attr)
11537 goto nla_put_failure;
11538
11539 if (nla_put_u8(msg, NL80211_NAN_FUNC_INSTANCE_ID, match->inst_id))
11540 goto nla_put_failure;
11541
11542 nla_nest_end(msg, local_func_attr);
11543
11544 peer_func_attr = nla_nest_start(msg, NL80211_NAN_MATCH_FUNC_PEER);
11545 if (!peer_func_attr)
11546 goto nla_put_failure;
11547
11548 if (nla_put_u8(msg, NL80211_NAN_FUNC_TYPE, match->type) ||
11549 nla_put_u8(msg, NL80211_NAN_FUNC_INSTANCE_ID, match->peer_inst_id))
11550 goto nla_put_failure;
11551
11552 if (match->info && match->info_len &&
11553 nla_put(msg, NL80211_NAN_FUNC_SERVICE_INFO, match->info_len,
11554 match->info))
11555 goto nla_put_failure;
11556
11557 nla_nest_end(msg, peer_func_attr);
11558 nla_nest_end(msg, match_attr);
11559 genlmsg_end(msg, hdr);
11560
11561 if (!wdev->owner_nlportid)
11562 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy),
11563 msg, 0, NL80211_MCGRP_NAN, gfp);
11564 else
11565 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg,
11566 wdev->owner_nlportid);
11567
11568 return;
11569
11570nla_put_failure:
11571 nlmsg_free(msg);
11572}
11573EXPORT_SYMBOL(cfg80211_nan_match);
11574
Ayala Beker368e5a72016-09-20 17:31:18 +030011575void cfg80211_nan_func_terminated(struct wireless_dev *wdev,
11576 u8 inst_id,
11577 enum nl80211_nan_func_term_reason reason,
11578 u64 cookie, gfp_t gfp)
11579{
11580 struct wiphy *wiphy = wdev->wiphy;
11581 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
11582 struct sk_buff *msg;
11583 struct nlattr *func_attr;
11584 void *hdr;
11585
11586 if (WARN_ON(!inst_id))
11587 return;
11588
11589 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
11590 if (!msg)
11591 return;
11592
11593 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DEL_NAN_FUNCTION);
11594 if (!hdr) {
11595 nlmsg_free(msg);
11596 return;
11597 }
11598
11599 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
11600 (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
11601 wdev->netdev->ifindex)) ||
11602 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
11603 NL80211_ATTR_PAD))
11604 goto nla_put_failure;
11605
11606 if (nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie,
11607 NL80211_ATTR_PAD))
11608 goto nla_put_failure;
11609
11610 func_attr = nla_nest_start(msg, NL80211_ATTR_NAN_FUNC);
11611 if (!func_attr)
11612 goto nla_put_failure;
11613
11614 if (nla_put_u8(msg, NL80211_NAN_FUNC_INSTANCE_ID, inst_id) ||
11615 nla_put_u8(msg, NL80211_NAN_FUNC_TERM_REASON, reason))
11616 goto nla_put_failure;
11617
11618 nla_nest_end(msg, func_attr);
11619 genlmsg_end(msg, hdr);
11620
11621 if (!wdev->owner_nlportid)
11622 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy),
11623 msg, 0, NL80211_MCGRP_NAN, gfp);
11624 else
11625 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg,
11626 wdev->owner_nlportid);
11627
11628 return;
11629
11630nla_put_failure:
11631 nlmsg_free(msg);
11632}
11633EXPORT_SYMBOL(cfg80211_nan_func_terminated);
11634
Johannes Berg3713b4e2013-02-14 16:19:38 +010011635static int nl80211_get_protocol_features(struct sk_buff *skb,
11636 struct genl_info *info)
11637{
11638 void *hdr;
11639 struct sk_buff *msg;
11640
11641 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
11642 if (!msg)
11643 return -ENOMEM;
11644
11645 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
11646 NL80211_CMD_GET_PROTOCOL_FEATURES);
11647 if (!hdr)
11648 goto nla_put_failure;
11649
11650 if (nla_put_u32(msg, NL80211_ATTR_PROTOCOL_FEATURES,
11651 NL80211_PROTOCOL_FEATURE_SPLIT_WIPHY_DUMP))
11652 goto nla_put_failure;
11653
11654 genlmsg_end(msg, hdr);
11655 return genlmsg_reply(msg, info);
11656
11657 nla_put_failure:
11658 kfree_skb(msg);
11659 return -ENOBUFS;
11660}
11661
Jouni Malinen355199e2013-02-27 17:14:27 +020011662static int nl80211_update_ft_ies(struct sk_buff *skb, struct genl_info *info)
11663{
11664 struct cfg80211_registered_device *rdev = info->user_ptr[0];
11665 struct cfg80211_update_ft_ies_params ft_params;
11666 struct net_device *dev = info->user_ptr[1];
11667
11668 if (!rdev->ops->update_ft_ies)
11669 return -EOPNOTSUPP;
11670
11671 if (!info->attrs[NL80211_ATTR_MDID] ||
11672 !is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
11673 return -EINVAL;
11674
11675 memset(&ft_params, 0, sizeof(ft_params));
11676 ft_params.md = nla_get_u16(info->attrs[NL80211_ATTR_MDID]);
11677 ft_params.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
11678 ft_params.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
11679
11680 return rdev_update_ft_ies(rdev, dev, &ft_params);
11681}
11682
Arend van Spriel5de17982013-04-18 15:49:00 +020011683static int nl80211_crit_protocol_start(struct sk_buff *skb,
11684 struct genl_info *info)
11685{
11686 struct cfg80211_registered_device *rdev = info->user_ptr[0];
11687 struct wireless_dev *wdev = info->user_ptr[1];
11688 enum nl80211_crit_proto_id proto = NL80211_CRIT_PROTO_UNSPEC;
11689 u16 duration;
11690 int ret;
11691
11692 if (!rdev->ops->crit_proto_start)
11693 return -EOPNOTSUPP;
11694
11695 if (WARN_ON(!rdev->ops->crit_proto_stop))
11696 return -EINVAL;
11697
11698 if (rdev->crit_proto_nlportid)
11699 return -EBUSY;
11700
11701 /* determine protocol if provided */
11702 if (info->attrs[NL80211_ATTR_CRIT_PROT_ID])
11703 proto = nla_get_u16(info->attrs[NL80211_ATTR_CRIT_PROT_ID]);
11704
11705 if (proto >= NUM_NL80211_CRIT_PROTO)
11706 return -EINVAL;
11707
11708 /* timeout must be provided */
11709 if (!info->attrs[NL80211_ATTR_MAX_CRIT_PROT_DURATION])
11710 return -EINVAL;
11711
11712 duration =
11713 nla_get_u16(info->attrs[NL80211_ATTR_MAX_CRIT_PROT_DURATION]);
11714
11715 if (duration > NL80211_CRIT_PROTO_MAX_DURATION)
11716 return -ERANGE;
11717
11718 ret = rdev_crit_proto_start(rdev, wdev, proto, duration);
11719 if (!ret)
11720 rdev->crit_proto_nlportid = info->snd_portid;
11721
11722 return ret;
11723}
11724
11725static int nl80211_crit_protocol_stop(struct sk_buff *skb,
11726 struct genl_info *info)
11727{
11728 struct cfg80211_registered_device *rdev = info->user_ptr[0];
11729 struct wireless_dev *wdev = info->user_ptr[1];
11730
11731 if (!rdev->ops->crit_proto_stop)
11732 return -EOPNOTSUPP;
11733
11734 if (rdev->crit_proto_nlportid) {
11735 rdev->crit_proto_nlportid = 0;
11736 rdev_crit_proto_stop(rdev, wdev);
11737 }
11738 return 0;
11739}
11740
Johannes Bergad7e7182013-11-13 13:37:47 +010011741static int nl80211_vendor_cmd(struct sk_buff *skb, struct genl_info *info)
11742{
11743 struct cfg80211_registered_device *rdev = info->user_ptr[0];
11744 struct wireless_dev *wdev =
11745 __cfg80211_wdev_from_attrs(genl_info_net(info), info->attrs);
11746 int i, err;
11747 u32 vid, subcmd;
11748
11749 if (!rdev->wiphy.vendor_commands)
11750 return -EOPNOTSUPP;
11751
11752 if (IS_ERR(wdev)) {
11753 err = PTR_ERR(wdev);
11754 if (err != -EINVAL)
11755 return err;
11756 wdev = NULL;
11757 } else if (wdev->wiphy != &rdev->wiphy) {
11758 return -EINVAL;
11759 }
11760
11761 if (!info->attrs[NL80211_ATTR_VENDOR_ID] ||
11762 !info->attrs[NL80211_ATTR_VENDOR_SUBCMD])
11763 return -EINVAL;
11764
11765 vid = nla_get_u32(info->attrs[NL80211_ATTR_VENDOR_ID]);
11766 subcmd = nla_get_u32(info->attrs[NL80211_ATTR_VENDOR_SUBCMD]);
11767 for (i = 0; i < rdev->wiphy.n_vendor_commands; i++) {
11768 const struct wiphy_vendor_command *vcmd;
11769 void *data = NULL;
11770 int len = 0;
11771
11772 vcmd = &rdev->wiphy.vendor_commands[i];
11773
11774 if (vcmd->info.vendor_id != vid || vcmd->info.subcmd != subcmd)
11775 continue;
11776
11777 if (vcmd->flags & (WIPHY_VENDOR_CMD_NEED_WDEV |
11778 WIPHY_VENDOR_CMD_NEED_NETDEV)) {
11779 if (!wdev)
11780 return -EINVAL;
11781 if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_NETDEV &&
11782 !wdev->netdev)
11783 return -EINVAL;
11784
11785 if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_RUNNING) {
Arend Van Spriel73c7da32016-10-20 20:08:22 +010011786 if (!wdev_running(wdev))
Johannes Bergad7e7182013-11-13 13:37:47 +010011787 return -ENETDOWN;
11788 }
Johannes Berg7bdbe402015-08-15 22:39:49 +030011789
11790 if (!vcmd->doit)
11791 return -EOPNOTSUPP;
Johannes Bergad7e7182013-11-13 13:37:47 +010011792 } else {
11793 wdev = NULL;
11794 }
11795
11796 if (info->attrs[NL80211_ATTR_VENDOR_DATA]) {
11797 data = nla_data(info->attrs[NL80211_ATTR_VENDOR_DATA]);
11798 len = nla_len(info->attrs[NL80211_ATTR_VENDOR_DATA]);
11799 }
11800
11801 rdev->cur_cmd_info = info;
11802 err = rdev->wiphy.vendor_commands[i].doit(&rdev->wiphy, wdev,
11803 data, len);
11804 rdev->cur_cmd_info = NULL;
11805 return err;
11806 }
11807
11808 return -EOPNOTSUPP;
11809}
11810
Johannes Berg7bdbe402015-08-15 22:39:49 +030011811static int nl80211_prepare_vendor_dump(struct sk_buff *skb,
11812 struct netlink_callback *cb,
11813 struct cfg80211_registered_device **rdev,
11814 struct wireless_dev **wdev)
11815{
Johannes Bergc90c39d2016-10-24 14:40:01 +020011816 struct nlattr **attrbuf = genl_family_attrbuf(&nl80211_fam);
Johannes Berg7bdbe402015-08-15 22:39:49 +030011817 u32 vid, subcmd;
11818 unsigned int i;
11819 int vcmd_idx = -1;
11820 int err;
11821 void *data = NULL;
11822 unsigned int data_len = 0;
11823
Johannes Berg7bdbe402015-08-15 22:39:49 +030011824 if (cb->args[0]) {
11825 /* subtract the 1 again here */
11826 struct wiphy *wiphy = wiphy_idx_to_wiphy(cb->args[0] - 1);
11827 struct wireless_dev *tmp;
11828
Johannes Bergea90e0d2017-03-15 14:26:04 +010011829 if (!wiphy)
11830 return -ENODEV;
Johannes Berg7bdbe402015-08-15 22:39:49 +030011831 *rdev = wiphy_to_rdev(wiphy);
11832 *wdev = NULL;
11833
11834 if (cb->args[1]) {
Johannes Berg53873f12016-05-03 16:52:04 +030011835 list_for_each_entry(tmp, &wiphy->wdev_list, list) {
Johannes Berg7bdbe402015-08-15 22:39:49 +030011836 if (tmp->identifier == cb->args[1] - 1) {
11837 *wdev = tmp;
11838 break;
11839 }
11840 }
11841 }
11842
11843 /* keep rtnl locked in successful case */
11844 return 0;
11845 }
11846
Johannes Bergfceb6432017-04-12 14:34:07 +020011847 err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize, attrbuf,
11848 nl80211_fam.maxattr, nl80211_policy, NULL);
Johannes Berg7bdbe402015-08-15 22:39:49 +030011849 if (err)
Johannes Bergea90e0d2017-03-15 14:26:04 +010011850 return err;
Johannes Berg7bdbe402015-08-15 22:39:49 +030011851
Johannes Bergc90c39d2016-10-24 14:40:01 +020011852 if (!attrbuf[NL80211_ATTR_VENDOR_ID] ||
Johannes Bergea90e0d2017-03-15 14:26:04 +010011853 !attrbuf[NL80211_ATTR_VENDOR_SUBCMD])
11854 return -EINVAL;
Johannes Berg7bdbe402015-08-15 22:39:49 +030011855
Johannes Bergc90c39d2016-10-24 14:40:01 +020011856 *wdev = __cfg80211_wdev_from_attrs(sock_net(skb->sk), attrbuf);
Johannes Berg7bdbe402015-08-15 22:39:49 +030011857 if (IS_ERR(*wdev))
11858 *wdev = NULL;
11859
Johannes Bergc90c39d2016-10-24 14:40:01 +020011860 *rdev = __cfg80211_rdev_from_attrs(sock_net(skb->sk), attrbuf);
Johannes Bergea90e0d2017-03-15 14:26:04 +010011861 if (IS_ERR(*rdev))
11862 return PTR_ERR(*rdev);
Johannes Berg7bdbe402015-08-15 22:39:49 +030011863
Johannes Bergc90c39d2016-10-24 14:40:01 +020011864 vid = nla_get_u32(attrbuf[NL80211_ATTR_VENDOR_ID]);
11865 subcmd = nla_get_u32(attrbuf[NL80211_ATTR_VENDOR_SUBCMD]);
Johannes Berg7bdbe402015-08-15 22:39:49 +030011866
11867 for (i = 0; i < (*rdev)->wiphy.n_vendor_commands; i++) {
11868 const struct wiphy_vendor_command *vcmd;
11869
11870 vcmd = &(*rdev)->wiphy.vendor_commands[i];
11871
11872 if (vcmd->info.vendor_id != vid || vcmd->info.subcmd != subcmd)
11873 continue;
11874
Johannes Bergea90e0d2017-03-15 14:26:04 +010011875 if (!vcmd->dumpit)
11876 return -EOPNOTSUPP;
Johannes Berg7bdbe402015-08-15 22:39:49 +030011877
11878 vcmd_idx = i;
11879 break;
11880 }
11881
Johannes Bergea90e0d2017-03-15 14:26:04 +010011882 if (vcmd_idx < 0)
11883 return -EOPNOTSUPP;
Johannes Berg7bdbe402015-08-15 22:39:49 +030011884
Johannes Bergc90c39d2016-10-24 14:40:01 +020011885 if (attrbuf[NL80211_ATTR_VENDOR_DATA]) {
11886 data = nla_data(attrbuf[NL80211_ATTR_VENDOR_DATA]);
11887 data_len = nla_len(attrbuf[NL80211_ATTR_VENDOR_DATA]);
Johannes Berg7bdbe402015-08-15 22:39:49 +030011888 }
11889
11890 /* 0 is the first index - add 1 to parse only once */
11891 cb->args[0] = (*rdev)->wiphy_idx + 1;
11892 /* add 1 to know if it was NULL */
11893 cb->args[1] = *wdev ? (*wdev)->identifier + 1 : 0;
11894 cb->args[2] = vcmd_idx;
11895 cb->args[3] = (unsigned long)data;
11896 cb->args[4] = data_len;
11897
11898 /* keep rtnl locked in successful case */
11899 return 0;
Johannes Berg7bdbe402015-08-15 22:39:49 +030011900}
11901
11902static int nl80211_vendor_cmd_dump(struct sk_buff *skb,
11903 struct netlink_callback *cb)
11904{
11905 struct cfg80211_registered_device *rdev;
11906 struct wireless_dev *wdev;
11907 unsigned int vcmd_idx;
11908 const struct wiphy_vendor_command *vcmd;
11909 void *data;
11910 int data_len;
11911 int err;
11912 struct nlattr *vendor_data;
11913
Johannes Bergea90e0d2017-03-15 14:26:04 +010011914 rtnl_lock();
Johannes Berg7bdbe402015-08-15 22:39:49 +030011915 err = nl80211_prepare_vendor_dump(skb, cb, &rdev, &wdev);
11916 if (err)
Johannes Bergea90e0d2017-03-15 14:26:04 +010011917 goto out;
Johannes Berg7bdbe402015-08-15 22:39:49 +030011918
11919 vcmd_idx = cb->args[2];
11920 data = (void *)cb->args[3];
11921 data_len = cb->args[4];
11922 vcmd = &rdev->wiphy.vendor_commands[vcmd_idx];
11923
11924 if (vcmd->flags & (WIPHY_VENDOR_CMD_NEED_WDEV |
11925 WIPHY_VENDOR_CMD_NEED_NETDEV)) {
Johannes Bergea90e0d2017-03-15 14:26:04 +010011926 if (!wdev) {
11927 err = -EINVAL;
11928 goto out;
11929 }
Johannes Berg7bdbe402015-08-15 22:39:49 +030011930 if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_NETDEV &&
Johannes Bergea90e0d2017-03-15 14:26:04 +010011931 !wdev->netdev) {
11932 err = -EINVAL;
11933 goto out;
11934 }
Johannes Berg7bdbe402015-08-15 22:39:49 +030011935
11936 if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_RUNNING) {
Johannes Bergea90e0d2017-03-15 14:26:04 +010011937 if (!wdev_running(wdev)) {
11938 err = -ENETDOWN;
11939 goto out;
11940 }
Johannes Berg7bdbe402015-08-15 22:39:49 +030011941 }
11942 }
11943
11944 while (1) {
11945 void *hdr = nl80211hdr_put(skb, NETLINK_CB(cb->skb).portid,
11946 cb->nlh->nlmsg_seq, NLM_F_MULTI,
11947 NL80211_CMD_VENDOR);
11948 if (!hdr)
11949 break;
11950
11951 if (nla_put_u32(skb, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020011952 (wdev && nla_put_u64_64bit(skb, NL80211_ATTR_WDEV,
11953 wdev_id(wdev),
11954 NL80211_ATTR_PAD))) {
Johannes Berg7bdbe402015-08-15 22:39:49 +030011955 genlmsg_cancel(skb, hdr);
11956 break;
11957 }
11958
11959 vendor_data = nla_nest_start(skb, NL80211_ATTR_VENDOR_DATA);
11960 if (!vendor_data) {
11961 genlmsg_cancel(skb, hdr);
11962 break;
11963 }
11964
11965 err = vcmd->dumpit(&rdev->wiphy, wdev, skb, data, data_len,
11966 (unsigned long *)&cb->args[5]);
11967 nla_nest_end(skb, vendor_data);
11968
11969 if (err == -ENOBUFS || err == -ENOENT) {
11970 genlmsg_cancel(skb, hdr);
11971 break;
11972 } else if (err) {
11973 genlmsg_cancel(skb, hdr);
11974 goto out;
11975 }
11976
11977 genlmsg_end(skb, hdr);
11978 }
11979
11980 err = skb->len;
11981 out:
11982 rtnl_unlock();
11983 return err;
11984}
11985
Johannes Bergad7e7182013-11-13 13:37:47 +010011986struct sk_buff *__cfg80211_alloc_reply_skb(struct wiphy *wiphy,
11987 enum nl80211_commands cmd,
11988 enum nl80211_attrs attr,
11989 int approxlen)
11990{
Zhao, Gangf26cbf42014-04-21 12:53:03 +080011991 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Bergad7e7182013-11-13 13:37:47 +010011992
11993 if (WARN_ON(!rdev->cur_cmd_info))
11994 return NULL;
11995
Ahmad Kholaif6c09e792015-02-26 15:26:53 +020011996 return __cfg80211_alloc_vendor_skb(rdev, NULL, approxlen,
Johannes Bergad7e7182013-11-13 13:37:47 +010011997 rdev->cur_cmd_info->snd_portid,
11998 rdev->cur_cmd_info->snd_seq,
Johannes Berg567ffc32013-12-18 14:43:31 +010011999 cmd, attr, NULL, GFP_KERNEL);
Johannes Bergad7e7182013-11-13 13:37:47 +010012000}
12001EXPORT_SYMBOL(__cfg80211_alloc_reply_skb);
12002
12003int cfg80211_vendor_cmd_reply(struct sk_buff *skb)
12004{
12005 struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0];
12006 void *hdr = ((void **)skb->cb)[1];
12007 struct nlattr *data = ((void **)skb->cb)[2];
12008
Johannes Bergbd8c78e2014-07-30 14:55:26 +020012009 /* clear CB data for netlink core to own from now on */
12010 memset(skb->cb, 0, sizeof(skb->cb));
12011
Johannes Bergad7e7182013-11-13 13:37:47 +010012012 if (WARN_ON(!rdev->cur_cmd_info)) {
12013 kfree_skb(skb);
12014 return -EINVAL;
12015 }
12016
12017 nla_nest_end(skb, data);
12018 genlmsg_end(skb, hdr);
12019 return genlmsg_reply(skb, rdev->cur_cmd_info);
12020}
12021EXPORT_SYMBOL_GPL(cfg80211_vendor_cmd_reply);
12022
Kyeyoon Parkfa9ffc72013-12-16 23:01:30 -080012023static int nl80211_set_qos_map(struct sk_buff *skb,
12024 struct genl_info *info)
12025{
12026 struct cfg80211_registered_device *rdev = info->user_ptr[0];
12027 struct cfg80211_qos_map *qos_map = NULL;
12028 struct net_device *dev = info->user_ptr[1];
12029 u8 *pos, len, num_des, des_len, des;
12030 int ret;
12031
12032 if (!rdev->ops->set_qos_map)
12033 return -EOPNOTSUPP;
12034
12035 if (info->attrs[NL80211_ATTR_QOS_MAP]) {
12036 pos = nla_data(info->attrs[NL80211_ATTR_QOS_MAP]);
12037 len = nla_len(info->attrs[NL80211_ATTR_QOS_MAP]);
12038
12039 if (len % 2 || len < IEEE80211_QOS_MAP_LEN_MIN ||
12040 len > IEEE80211_QOS_MAP_LEN_MAX)
12041 return -EINVAL;
12042
12043 qos_map = kzalloc(sizeof(struct cfg80211_qos_map), GFP_KERNEL);
12044 if (!qos_map)
12045 return -ENOMEM;
12046
12047 num_des = (len - IEEE80211_QOS_MAP_LEN_MIN) >> 1;
12048 if (num_des) {
12049 des_len = num_des *
12050 sizeof(struct cfg80211_dscp_exception);
12051 memcpy(qos_map->dscp_exception, pos, des_len);
12052 qos_map->num_des = num_des;
12053 for (des = 0; des < num_des; des++) {
12054 if (qos_map->dscp_exception[des].up > 7) {
12055 kfree(qos_map);
12056 return -EINVAL;
12057 }
12058 }
12059 pos += des_len;
12060 }
12061 memcpy(qos_map->up, pos, IEEE80211_QOS_MAP_LEN_MIN);
12062 }
12063
12064 wdev_lock(dev->ieee80211_ptr);
12065 ret = nl80211_key_allowed(dev->ieee80211_ptr);
12066 if (!ret)
12067 ret = rdev_set_qos_map(rdev, dev, qos_map);
12068 wdev_unlock(dev->ieee80211_ptr);
12069
12070 kfree(qos_map);
12071 return ret;
12072}
12073
Johannes Berg960d01a2014-09-09 22:55:35 +030012074static int nl80211_add_tx_ts(struct sk_buff *skb, struct genl_info *info)
12075{
12076 struct cfg80211_registered_device *rdev = info->user_ptr[0];
12077 struct net_device *dev = info->user_ptr[1];
12078 struct wireless_dev *wdev = dev->ieee80211_ptr;
12079 const u8 *peer;
12080 u8 tsid, up;
12081 u16 admitted_time = 0;
12082 int err;
12083
Johannes Berg723e73a2014-10-22 09:25:06 +020012084 if (!(rdev->wiphy.features & NL80211_FEATURE_SUPPORTS_WMM_ADMISSION))
Johannes Berg960d01a2014-09-09 22:55:35 +030012085 return -EOPNOTSUPP;
12086
12087 if (!info->attrs[NL80211_ATTR_TSID] || !info->attrs[NL80211_ATTR_MAC] ||
12088 !info->attrs[NL80211_ATTR_USER_PRIO])
12089 return -EINVAL;
12090
12091 tsid = nla_get_u8(info->attrs[NL80211_ATTR_TSID]);
12092 if (tsid >= IEEE80211_NUM_TIDS)
12093 return -EINVAL;
12094
12095 up = nla_get_u8(info->attrs[NL80211_ATTR_USER_PRIO]);
12096 if (up >= IEEE80211_NUM_UPS)
12097 return -EINVAL;
12098
12099 /* WMM uses TIDs 0-7 even for TSPEC */
Johannes Berg723e73a2014-10-22 09:25:06 +020012100 if (tsid >= IEEE80211_FIRST_TSPEC_TSID) {
Johannes Berg960d01a2014-09-09 22:55:35 +030012101 /* TODO: handle 802.11 TSPEC/admission control
Johannes Berg723e73a2014-10-22 09:25:06 +020012102 * need more attributes for that (e.g. BA session requirement);
12103 * change the WMM adminssion test above to allow both then
Johannes Berg960d01a2014-09-09 22:55:35 +030012104 */
12105 return -EINVAL;
12106 }
12107
12108 peer = nla_data(info->attrs[NL80211_ATTR_MAC]);
12109
12110 if (info->attrs[NL80211_ATTR_ADMITTED_TIME]) {
12111 admitted_time =
12112 nla_get_u16(info->attrs[NL80211_ATTR_ADMITTED_TIME]);
12113 if (!admitted_time)
12114 return -EINVAL;
12115 }
12116
12117 wdev_lock(wdev);
12118 switch (wdev->iftype) {
12119 case NL80211_IFTYPE_STATION:
12120 case NL80211_IFTYPE_P2P_CLIENT:
12121 if (wdev->current_bss)
12122 break;
12123 err = -ENOTCONN;
12124 goto out;
12125 default:
12126 err = -EOPNOTSUPP;
12127 goto out;
12128 }
12129
12130 err = rdev_add_tx_ts(rdev, dev, tsid, peer, up, admitted_time);
12131
12132 out:
12133 wdev_unlock(wdev);
12134 return err;
12135}
12136
12137static int nl80211_del_tx_ts(struct sk_buff *skb, struct genl_info *info)
12138{
12139 struct cfg80211_registered_device *rdev = info->user_ptr[0];
12140 struct net_device *dev = info->user_ptr[1];
12141 struct wireless_dev *wdev = dev->ieee80211_ptr;
12142 const u8 *peer;
12143 u8 tsid;
12144 int err;
12145
12146 if (!info->attrs[NL80211_ATTR_TSID] || !info->attrs[NL80211_ATTR_MAC])
12147 return -EINVAL;
12148
12149 tsid = nla_get_u8(info->attrs[NL80211_ATTR_TSID]);
12150 peer = nla_data(info->attrs[NL80211_ATTR_MAC]);
12151
12152 wdev_lock(wdev);
12153 err = rdev_del_tx_ts(rdev, dev, tsid, peer);
12154 wdev_unlock(wdev);
12155
12156 return err;
12157}
12158
Arik Nemtsov1057d352014-11-19 12:54:26 +020012159static int nl80211_tdls_channel_switch(struct sk_buff *skb,
12160 struct genl_info *info)
12161{
12162 struct cfg80211_registered_device *rdev = info->user_ptr[0];
12163 struct net_device *dev = info->user_ptr[1];
12164 struct wireless_dev *wdev = dev->ieee80211_ptr;
12165 struct cfg80211_chan_def chandef = {};
12166 const u8 *addr;
12167 u8 oper_class;
12168 int err;
12169
12170 if (!rdev->ops->tdls_channel_switch ||
12171 !(rdev->wiphy.features & NL80211_FEATURE_TDLS_CHANNEL_SWITCH))
12172 return -EOPNOTSUPP;
12173
12174 switch (dev->ieee80211_ptr->iftype) {
12175 case NL80211_IFTYPE_STATION:
12176 case NL80211_IFTYPE_P2P_CLIENT:
12177 break;
12178 default:
12179 return -EOPNOTSUPP;
12180 }
12181
12182 if (!info->attrs[NL80211_ATTR_MAC] ||
12183 !info->attrs[NL80211_ATTR_OPER_CLASS])
12184 return -EINVAL;
12185
12186 err = nl80211_parse_chandef(rdev, info, &chandef);
12187 if (err)
12188 return err;
12189
12190 /*
12191 * Don't allow wide channels on the 2.4Ghz band, as per IEEE802.11-2012
12192 * section 10.22.6.2.1. Disallow 5/10Mhz channels as well for now, the
12193 * specification is not defined for them.
12194 */
Johannes Berg57fbcce2016-04-12 15:56:15 +020012195 if (chandef.chan->band == NL80211_BAND_2GHZ &&
Arik Nemtsov1057d352014-11-19 12:54:26 +020012196 chandef.width != NL80211_CHAN_WIDTH_20_NOHT &&
12197 chandef.width != NL80211_CHAN_WIDTH_20)
12198 return -EINVAL;
12199
12200 /* we will be active on the TDLS link */
Arik Nemtsov923b3522015-07-08 15:41:44 +030012201 if (!cfg80211_reg_can_beacon_relax(&rdev->wiphy, &chandef,
12202 wdev->iftype))
Arik Nemtsov1057d352014-11-19 12:54:26 +020012203 return -EINVAL;
12204
12205 /* don't allow switching to DFS channels */
12206 if (cfg80211_chandef_dfs_required(wdev->wiphy, &chandef, wdev->iftype))
12207 return -EINVAL;
12208
12209 addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
12210 oper_class = nla_get_u8(info->attrs[NL80211_ATTR_OPER_CLASS]);
12211
12212 wdev_lock(wdev);
12213 err = rdev_tdls_channel_switch(rdev, dev, addr, oper_class, &chandef);
12214 wdev_unlock(wdev);
12215
12216 return err;
12217}
12218
12219static int nl80211_tdls_cancel_channel_switch(struct sk_buff *skb,
12220 struct genl_info *info)
12221{
12222 struct cfg80211_registered_device *rdev = info->user_ptr[0];
12223 struct net_device *dev = info->user_ptr[1];
12224 struct wireless_dev *wdev = dev->ieee80211_ptr;
12225 const u8 *addr;
12226
12227 if (!rdev->ops->tdls_channel_switch ||
12228 !rdev->ops->tdls_cancel_channel_switch ||
12229 !(rdev->wiphy.features & NL80211_FEATURE_TDLS_CHANNEL_SWITCH))
12230 return -EOPNOTSUPP;
12231
12232 switch (dev->ieee80211_ptr->iftype) {
12233 case NL80211_IFTYPE_STATION:
12234 case NL80211_IFTYPE_P2P_CLIENT:
12235 break;
12236 default:
12237 return -EOPNOTSUPP;
12238 }
12239
12240 if (!info->attrs[NL80211_ATTR_MAC])
12241 return -EINVAL;
12242
12243 addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
12244
12245 wdev_lock(wdev);
12246 rdev_tdls_cancel_channel_switch(rdev, dev, addr);
12247 wdev_unlock(wdev);
12248
12249 return 0;
12250}
12251
Michael Braunce0ce132016-10-10 19:12:22 +020012252static int nl80211_set_multicast_to_unicast(struct sk_buff *skb,
12253 struct genl_info *info)
12254{
12255 struct cfg80211_registered_device *rdev = info->user_ptr[0];
12256 struct net_device *dev = info->user_ptr[1];
12257 struct wireless_dev *wdev = dev->ieee80211_ptr;
12258 const struct nlattr *nla;
12259 bool enabled;
12260
Michael Braunce0ce132016-10-10 19:12:22 +020012261 if (!rdev->ops->set_multicast_to_unicast)
12262 return -EOPNOTSUPP;
12263
12264 if (wdev->iftype != NL80211_IFTYPE_AP &&
12265 wdev->iftype != NL80211_IFTYPE_P2P_GO)
12266 return -EOPNOTSUPP;
12267
12268 nla = info->attrs[NL80211_ATTR_MULTICAST_TO_UNICAST_ENABLED];
12269 enabled = nla_get_flag(nla);
12270
12271 return rdev_set_multicast_to_unicast(rdev, dev, enabled);
12272}
12273
Avraham Stern3a00df52017-06-09 13:08:43 +010012274static int nl80211_set_pmk(struct sk_buff *skb, struct genl_info *info)
12275{
12276 struct cfg80211_registered_device *rdev = info->user_ptr[0];
12277 struct net_device *dev = info->user_ptr[1];
12278 struct wireless_dev *wdev = dev->ieee80211_ptr;
12279 struct cfg80211_pmk_conf pmk_conf = {};
12280 int ret;
12281
12282 if (wdev->iftype != NL80211_IFTYPE_STATION &&
12283 wdev->iftype != NL80211_IFTYPE_P2P_CLIENT)
12284 return -EOPNOTSUPP;
12285
12286 if (!wiphy_ext_feature_isset(&rdev->wiphy,
12287 NL80211_EXT_FEATURE_4WAY_HANDSHAKE_STA_1X))
12288 return -EOPNOTSUPP;
12289
12290 if (!info->attrs[NL80211_ATTR_MAC] || !info->attrs[NL80211_ATTR_PMK])
12291 return -EINVAL;
12292
12293 wdev_lock(wdev);
12294 if (!wdev->current_bss) {
12295 ret = -ENOTCONN;
12296 goto out;
12297 }
12298
12299 pmk_conf.aa = nla_data(info->attrs[NL80211_ATTR_MAC]);
12300 if (memcmp(pmk_conf.aa, wdev->current_bss->pub.bssid, ETH_ALEN)) {
12301 ret = -EINVAL;
12302 goto out;
12303 }
12304
12305 pmk_conf.pmk = nla_data(info->attrs[NL80211_ATTR_PMK]);
12306 pmk_conf.pmk_len = nla_len(info->attrs[NL80211_ATTR_PMK]);
12307 if (pmk_conf.pmk_len != WLAN_PMK_LEN &&
12308 pmk_conf.pmk_len != WLAN_PMK_LEN_SUITE_B_192) {
12309 ret = -EINVAL;
12310 goto out;
12311 }
12312
12313 if (info->attrs[NL80211_ATTR_PMKR0_NAME]) {
12314 int r0_name_len = nla_len(info->attrs[NL80211_ATTR_PMKR0_NAME]);
12315
12316 if (r0_name_len != WLAN_PMK_NAME_LEN) {
12317 ret = -EINVAL;
12318 goto out;
12319 }
12320
12321 pmk_conf.pmk_r0_name =
12322 nla_data(info->attrs[NL80211_ATTR_PMKR0_NAME]);
12323 }
12324
12325 ret = rdev_set_pmk(rdev, dev, &pmk_conf);
12326out:
12327 wdev_unlock(wdev);
12328 return ret;
12329}
12330
12331static int nl80211_del_pmk(struct sk_buff *skb, struct genl_info *info)
12332{
12333 struct cfg80211_registered_device *rdev = info->user_ptr[0];
12334 struct net_device *dev = info->user_ptr[1];
12335 struct wireless_dev *wdev = dev->ieee80211_ptr;
12336 const u8 *aa;
12337 int ret;
12338
12339 if (wdev->iftype != NL80211_IFTYPE_STATION &&
12340 wdev->iftype != NL80211_IFTYPE_P2P_CLIENT)
12341 return -EOPNOTSUPP;
12342
12343 if (!wiphy_ext_feature_isset(&rdev->wiphy,
12344 NL80211_EXT_FEATURE_4WAY_HANDSHAKE_STA_1X))
12345 return -EOPNOTSUPP;
12346
12347 if (!info->attrs[NL80211_ATTR_MAC])
12348 return -EINVAL;
12349
12350 wdev_lock(wdev);
12351 aa = nla_data(info->attrs[NL80211_ATTR_MAC]);
12352 ret = rdev_del_pmk(rdev, dev, aa);
12353 wdev_unlock(wdev);
12354
12355 return ret;
12356}
12357
Johannes Berg4c476992010-10-04 21:36:35 +020012358#define NL80211_FLAG_NEED_WIPHY 0x01
12359#define NL80211_FLAG_NEED_NETDEV 0x02
12360#define NL80211_FLAG_NEED_RTNL 0x04
Johannes Berg41265712010-10-04 21:14:05 +020012361#define NL80211_FLAG_CHECK_NETDEV_UP 0x08
12362#define NL80211_FLAG_NEED_NETDEV_UP (NL80211_FLAG_NEED_NETDEV |\
12363 NL80211_FLAG_CHECK_NETDEV_UP)
Johannes Berg1bf614e2012-06-15 15:23:36 +020012364#define NL80211_FLAG_NEED_WDEV 0x10
Johannes Berg98104fde2012-06-16 00:19:54 +020012365/* If a netdev is associated, it must be UP, P2P must be started */
Johannes Berg1bf614e2012-06-15 15:23:36 +020012366#define NL80211_FLAG_NEED_WDEV_UP (NL80211_FLAG_NEED_WDEV |\
12367 NL80211_FLAG_CHECK_NETDEV_UP)
Johannes Berg5393b912014-09-10 15:00:16 +030012368#define NL80211_FLAG_CLEAR_SKB 0x20
Johannes Berg4c476992010-10-04 21:36:35 +020012369
Johannes Bergf84f7712013-11-14 17:14:45 +010012370static int nl80211_pre_doit(const struct genl_ops *ops, struct sk_buff *skb,
Johannes Berg4c476992010-10-04 21:36:35 +020012371 struct genl_info *info)
12372{
12373 struct cfg80211_registered_device *rdev;
Johannes Berg89a54e42012-06-15 14:33:17 +020012374 struct wireless_dev *wdev;
Johannes Berg4c476992010-10-04 21:36:35 +020012375 struct net_device *dev;
Johannes Berg4c476992010-10-04 21:36:35 +020012376 bool rtnl = ops->internal_flags & NL80211_FLAG_NEED_RTNL;
12377
12378 if (rtnl)
12379 rtnl_lock();
12380
12381 if (ops->internal_flags & NL80211_FLAG_NEED_WIPHY) {
Johannes Berg4f7eff12012-06-15 14:14:22 +020012382 rdev = cfg80211_get_dev_from_info(genl_info_net(info), info);
Johannes Berg4c476992010-10-04 21:36:35 +020012383 if (IS_ERR(rdev)) {
12384 if (rtnl)
12385 rtnl_unlock();
12386 return PTR_ERR(rdev);
12387 }
12388 info->user_ptr[0] = rdev;
Johannes Berg1bf614e2012-06-15 15:23:36 +020012389 } else if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV ||
12390 ops->internal_flags & NL80211_FLAG_NEED_WDEV) {
Johannes Berg5fe231e2013-05-08 21:45:15 +020012391 ASSERT_RTNL();
12392
Johannes Berg89a54e42012-06-15 14:33:17 +020012393 wdev = __cfg80211_wdev_from_attrs(genl_info_net(info),
12394 info->attrs);
12395 if (IS_ERR(wdev)) {
Johannes Berg4c476992010-10-04 21:36:35 +020012396 if (rtnl)
12397 rtnl_unlock();
Johannes Berg89a54e42012-06-15 14:33:17 +020012398 return PTR_ERR(wdev);
Johannes Berg4c476992010-10-04 21:36:35 +020012399 }
Johannes Berg89a54e42012-06-15 14:33:17 +020012400
Johannes Berg89a54e42012-06-15 14:33:17 +020012401 dev = wdev->netdev;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080012402 rdev = wiphy_to_rdev(wdev->wiphy);
Johannes Berg89a54e42012-06-15 14:33:17 +020012403
Johannes Berg1bf614e2012-06-15 15:23:36 +020012404 if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV) {
12405 if (!dev) {
Johannes Berg1bf614e2012-06-15 15:23:36 +020012406 if (rtnl)
12407 rtnl_unlock();
12408 return -EINVAL;
12409 }
12410
12411 info->user_ptr[1] = dev;
12412 } else {
12413 info->user_ptr[1] = wdev;
Johannes Berg41265712010-10-04 21:14:05 +020012414 }
Johannes Berg89a54e42012-06-15 14:33:17 +020012415
Arend Van Spriel73c7da32016-10-20 20:08:22 +010012416 if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP &&
12417 !wdev_running(wdev)) {
12418 if (rtnl)
12419 rtnl_unlock();
12420 return -ENETDOWN;
Johannes Berg1bf614e2012-06-15 15:23:36 +020012421 }
12422
Arend Van Spriel73c7da32016-10-20 20:08:22 +010012423 if (dev)
12424 dev_hold(dev);
12425
Johannes Berg4c476992010-10-04 21:36:35 +020012426 info->user_ptr[0] = rdev;
Johannes Berg4c476992010-10-04 21:36:35 +020012427 }
12428
12429 return 0;
12430}
12431
Johannes Bergf84f7712013-11-14 17:14:45 +010012432static void nl80211_post_doit(const struct genl_ops *ops, struct sk_buff *skb,
Johannes Berg4c476992010-10-04 21:36:35 +020012433 struct genl_info *info)
12434{
Johannes Berg1bf614e2012-06-15 15:23:36 +020012435 if (info->user_ptr[1]) {
12436 if (ops->internal_flags & NL80211_FLAG_NEED_WDEV) {
12437 struct wireless_dev *wdev = info->user_ptr[1];
12438
12439 if (wdev->netdev)
12440 dev_put(wdev->netdev);
12441 } else {
12442 dev_put(info->user_ptr[1]);
12443 }
12444 }
Johannes Berg5393b912014-09-10 15:00:16 +030012445
Johannes Berg4c476992010-10-04 21:36:35 +020012446 if (ops->internal_flags & NL80211_FLAG_NEED_RTNL)
12447 rtnl_unlock();
Johannes Berg5393b912014-09-10 15:00:16 +030012448
12449 /* If needed, clear the netlink message payload from the SKB
12450 * as it might contain key data that shouldn't stick around on
12451 * the heap after the SKB is freed. The netlink message header
12452 * is still needed for further processing, so leave it intact.
12453 */
12454 if (ops->internal_flags & NL80211_FLAG_CLEAR_SKB) {
12455 struct nlmsghdr *nlh = nlmsg_hdr(skb);
12456
12457 memset(nlmsg_data(nlh), 0, nlmsg_len(nlh));
12458 }
Johannes Berg4c476992010-10-04 21:36:35 +020012459}
12460
Johannes Berg4534de82013-11-14 17:14:46 +010012461static const struct genl_ops nl80211_ops[] = {
Johannes Berg55682962007-09-20 13:09:35 -040012462 {
12463 .cmd = NL80211_CMD_GET_WIPHY,
12464 .doit = nl80211_get_wiphy,
12465 .dumpit = nl80211_dump_wiphy,
Johannes Berg86e8cf92013-06-19 10:57:22 +020012466 .done = nl80211_dump_wiphy_done,
Johannes Berg55682962007-09-20 13:09:35 -040012467 .policy = nl80211_policy,
12468 /* can be retrieved by unprivileged users */
Johannes Berg5fe231e2013-05-08 21:45:15 +020012469 .internal_flags = NL80211_FLAG_NEED_WIPHY |
12470 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -040012471 },
12472 {
12473 .cmd = NL80211_CMD_SET_WIPHY,
12474 .doit = nl80211_set_wiphy,
12475 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012476 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020012477 .internal_flags = NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -040012478 },
12479 {
12480 .cmd = NL80211_CMD_GET_INTERFACE,
12481 .doit = nl80211_get_interface,
12482 .dumpit = nl80211_dump_interface,
12483 .policy = nl80211_policy,
12484 /* can be retrieved by unprivileged users */
Johannes Berg5fe231e2013-05-08 21:45:15 +020012485 .internal_flags = NL80211_FLAG_NEED_WDEV |
12486 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -040012487 },
12488 {
12489 .cmd = NL80211_CMD_SET_INTERFACE,
12490 .doit = nl80211_set_interface,
12491 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012492 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020012493 .internal_flags = NL80211_FLAG_NEED_NETDEV |
12494 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -040012495 },
12496 {
12497 .cmd = NL80211_CMD_NEW_INTERFACE,
12498 .doit = nl80211_new_interface,
12499 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012500 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020012501 .internal_flags = NL80211_FLAG_NEED_WIPHY |
12502 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -040012503 },
12504 {
12505 .cmd = NL80211_CMD_DEL_INTERFACE,
12506 .doit = nl80211_del_interface,
12507 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012508 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg84efbb82012-06-16 00:00:26 +020012509 .internal_flags = NL80211_FLAG_NEED_WDEV |
Johannes Berg4c476992010-10-04 21:36:35 +020012510 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -040012511 },
Johannes Berg41ade002007-12-19 02:03:29 +010012512 {
12513 .cmd = NL80211_CMD_GET_KEY,
12514 .doit = nl80211_get_key,
12515 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012516 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020012517 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020012518 NL80211_FLAG_NEED_RTNL,
Johannes Berg41ade002007-12-19 02:03:29 +010012519 },
12520 {
12521 .cmd = NL80211_CMD_SET_KEY,
12522 .doit = nl80211_set_key,
12523 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012524 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020012525 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg5393b912014-09-10 15:00:16 +030012526 NL80211_FLAG_NEED_RTNL |
12527 NL80211_FLAG_CLEAR_SKB,
Johannes Berg41ade002007-12-19 02:03:29 +010012528 },
12529 {
12530 .cmd = NL80211_CMD_NEW_KEY,
12531 .doit = nl80211_new_key,
12532 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012533 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020012534 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg5393b912014-09-10 15:00:16 +030012535 NL80211_FLAG_NEED_RTNL |
12536 NL80211_FLAG_CLEAR_SKB,
Johannes Berg41ade002007-12-19 02:03:29 +010012537 },
12538 {
12539 .cmd = NL80211_CMD_DEL_KEY,
12540 .doit = nl80211_del_key,
12541 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012542 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020012543 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020012544 NL80211_FLAG_NEED_RTNL,
Johannes Berg41ade002007-12-19 02:03:29 +010012545 },
Johannes Berged1b6cc2007-12-19 02:03:32 +010012546 {
12547 .cmd = NL80211_CMD_SET_BEACON,
12548 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012549 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg88600202012-02-13 15:17:18 +010012550 .doit = nl80211_set_beacon,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020012551 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020012552 NL80211_FLAG_NEED_RTNL,
Johannes Berged1b6cc2007-12-19 02:03:32 +010012553 },
12554 {
Johannes Berg88600202012-02-13 15:17:18 +010012555 .cmd = NL80211_CMD_START_AP,
Johannes Berged1b6cc2007-12-19 02:03:32 +010012556 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012557 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg88600202012-02-13 15:17:18 +010012558 .doit = nl80211_start_ap,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020012559 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020012560 NL80211_FLAG_NEED_RTNL,
Johannes Berged1b6cc2007-12-19 02:03:32 +010012561 },
12562 {
Johannes Berg88600202012-02-13 15:17:18 +010012563 .cmd = NL80211_CMD_STOP_AP,
Johannes Berged1b6cc2007-12-19 02:03:32 +010012564 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012565 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg88600202012-02-13 15:17:18 +010012566 .doit = nl80211_stop_ap,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020012567 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020012568 NL80211_FLAG_NEED_RTNL,
Johannes Berged1b6cc2007-12-19 02:03:32 +010012569 },
Johannes Berg5727ef12007-12-19 02:03:34 +010012570 {
12571 .cmd = NL80211_CMD_GET_STATION,
12572 .doit = nl80211_get_station,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010012573 .dumpit = nl80211_dump_station,
Johannes Berg5727ef12007-12-19 02:03:34 +010012574 .policy = nl80211_policy,
Johannes Berg4c476992010-10-04 21:36:35 +020012575 .internal_flags = NL80211_FLAG_NEED_NETDEV |
12576 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +010012577 },
12578 {
12579 .cmd = NL80211_CMD_SET_STATION,
12580 .doit = nl80211_set_station,
12581 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012582 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020012583 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020012584 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +010012585 },
12586 {
12587 .cmd = NL80211_CMD_NEW_STATION,
12588 .doit = nl80211_new_station,
12589 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012590 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020012591 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020012592 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +010012593 },
12594 {
12595 .cmd = NL80211_CMD_DEL_STATION,
12596 .doit = nl80211_del_station,
12597 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012598 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020012599 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020012600 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +010012601 },
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010012602 {
12603 .cmd = NL80211_CMD_GET_MPATH,
12604 .doit = nl80211_get_mpath,
12605 .dumpit = nl80211_dump_mpath,
12606 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012607 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020012608 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020012609 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010012610 },
12611 {
Henning Rogge66be7d22014-09-12 08:58:49 +020012612 .cmd = NL80211_CMD_GET_MPP,
12613 .doit = nl80211_get_mpp,
12614 .dumpit = nl80211_dump_mpp,
12615 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012616 .flags = GENL_UNS_ADMIN_PERM,
Henning Rogge66be7d22014-09-12 08:58:49 +020012617 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
12618 NL80211_FLAG_NEED_RTNL,
12619 },
12620 {
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010012621 .cmd = NL80211_CMD_SET_MPATH,
12622 .doit = nl80211_set_mpath,
12623 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012624 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020012625 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020012626 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010012627 },
12628 {
12629 .cmd = NL80211_CMD_NEW_MPATH,
12630 .doit = nl80211_new_mpath,
12631 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012632 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020012633 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020012634 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010012635 },
12636 {
12637 .cmd = NL80211_CMD_DEL_MPATH,
12638 .doit = nl80211_del_mpath,
12639 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012640 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020012641 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020012642 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010012643 },
Jouni Malinen9f1ba902008-08-07 20:07:01 +030012644 {
12645 .cmd = NL80211_CMD_SET_BSS,
12646 .doit = nl80211_set_bss,
12647 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012648 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020012649 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020012650 NL80211_FLAG_NEED_RTNL,
Jouni Malinen9f1ba902008-08-07 20:07:01 +030012651 },
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -070012652 {
Luis R. Rodriguezf1303472009-01-30 09:26:42 -080012653 .cmd = NL80211_CMD_GET_REG,
Arik Nemtsovad30ca22014-12-15 19:25:59 +020012654 .doit = nl80211_get_reg_do,
12655 .dumpit = nl80211_get_reg_dump,
Luis R. Rodriguezf1303472009-01-30 09:26:42 -080012656 .policy = nl80211_policy,
Johannes Berg5fe231e2013-05-08 21:45:15 +020012657 .internal_flags = NL80211_FLAG_NEED_RTNL,
Luis R. Rodriguezf1303472009-01-30 09:26:42 -080012658 /* can be retrieved by unprivileged users */
12659 },
Johannes Bergb6863032015-10-15 09:25:18 +020012660#ifdef CONFIG_CFG80211_CRDA_SUPPORT
Luis R. Rodriguezf1303472009-01-30 09:26:42 -080012661 {
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -070012662 .cmd = NL80211_CMD_SET_REG,
12663 .doit = nl80211_set_reg,
12664 .policy = nl80211_policy,
12665 .flags = GENL_ADMIN_PERM,
Johannes Berg5fe231e2013-05-08 21:45:15 +020012666 .internal_flags = NL80211_FLAG_NEED_RTNL,
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -070012667 },
Johannes Bergb6863032015-10-15 09:25:18 +020012668#endif
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -070012669 {
12670 .cmd = NL80211_CMD_REQ_SET_REG,
12671 .doit = nl80211_req_set_reg,
12672 .policy = nl80211_policy,
12673 .flags = GENL_ADMIN_PERM,
12674 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -070012675 {
Javier Cardona24bdd9f2010-12-16 17:37:48 -080012676 .cmd = NL80211_CMD_GET_MESH_CONFIG,
12677 .doit = nl80211_get_mesh_config,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -070012678 .policy = nl80211_policy,
12679 /* can be retrieved by unprivileged users */
Johannes Berg2b5f8b02012-04-02 10:51:55 +020012680 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020012681 NL80211_FLAG_NEED_RTNL,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -070012682 },
12683 {
Javier Cardona24bdd9f2010-12-16 17:37:48 -080012684 .cmd = NL80211_CMD_SET_MESH_CONFIG,
12685 .doit = nl80211_update_mesh_config,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -070012686 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012687 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg29cbe682010-12-03 09:20:44 +010012688 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020012689 NL80211_FLAG_NEED_RTNL,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -070012690 },
Jouni Malinen9aed3cc2009-01-13 16:03:29 +020012691 {
Johannes Berg2a519312009-02-10 21:25:55 +010012692 .cmd = NL80211_CMD_TRIGGER_SCAN,
12693 .doit = nl80211_trigger_scan,
12694 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012695 .flags = GENL_UNS_ADMIN_PERM,
Johannes Bergfd014282012-06-18 19:17:03 +020012696 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020012697 NL80211_FLAG_NEED_RTNL,
Johannes Berg2a519312009-02-10 21:25:55 +010012698 },
12699 {
Vidyullatha Kanchanapally91d3ab42015-10-30 19:14:49 +053012700 .cmd = NL80211_CMD_ABORT_SCAN,
12701 .doit = nl80211_abort_scan,
12702 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012703 .flags = GENL_UNS_ADMIN_PERM,
Vidyullatha Kanchanapally91d3ab42015-10-30 19:14:49 +053012704 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
12705 NL80211_FLAG_NEED_RTNL,
12706 },
12707 {
Johannes Berg2a519312009-02-10 21:25:55 +010012708 .cmd = NL80211_CMD_GET_SCAN,
12709 .policy = nl80211_policy,
12710 .dumpit = nl80211_dump_scan,
12711 },
Jouni Malinen636a5d32009-03-19 13:39:22 +020012712 {
Luciano Coelho807f8a82011-05-11 17:09:35 +030012713 .cmd = NL80211_CMD_START_SCHED_SCAN,
12714 .doit = nl80211_start_sched_scan,
12715 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012716 .flags = GENL_UNS_ADMIN_PERM,
Luciano Coelho807f8a82011-05-11 17:09:35 +030012717 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
12718 NL80211_FLAG_NEED_RTNL,
12719 },
12720 {
12721 .cmd = NL80211_CMD_STOP_SCHED_SCAN,
12722 .doit = nl80211_stop_sched_scan,
12723 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012724 .flags = GENL_UNS_ADMIN_PERM,
Luciano Coelho807f8a82011-05-11 17:09:35 +030012725 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
12726 NL80211_FLAG_NEED_RTNL,
12727 },
12728 {
Jouni Malinen636a5d32009-03-19 13:39:22 +020012729 .cmd = NL80211_CMD_AUTHENTICATE,
12730 .doit = nl80211_authenticate,
12731 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012732 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020012733 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg5393b912014-09-10 15:00:16 +030012734 NL80211_FLAG_NEED_RTNL |
12735 NL80211_FLAG_CLEAR_SKB,
Jouni Malinen636a5d32009-03-19 13:39:22 +020012736 },
12737 {
12738 .cmd = NL80211_CMD_ASSOCIATE,
12739 .doit = nl80211_associate,
12740 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012741 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020012742 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020012743 NL80211_FLAG_NEED_RTNL,
Jouni Malinen636a5d32009-03-19 13:39:22 +020012744 },
12745 {
12746 .cmd = NL80211_CMD_DEAUTHENTICATE,
12747 .doit = nl80211_deauthenticate,
12748 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012749 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020012750 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020012751 NL80211_FLAG_NEED_RTNL,
Jouni Malinen636a5d32009-03-19 13:39:22 +020012752 },
12753 {
12754 .cmd = NL80211_CMD_DISASSOCIATE,
12755 .doit = nl80211_disassociate,
12756 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012757 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020012758 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020012759 NL80211_FLAG_NEED_RTNL,
Jouni Malinen636a5d32009-03-19 13:39:22 +020012760 },
Johannes Berg04a773a2009-04-19 21:24:32 +020012761 {
12762 .cmd = NL80211_CMD_JOIN_IBSS,
12763 .doit = nl80211_join_ibss,
12764 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012765 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020012766 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020012767 NL80211_FLAG_NEED_RTNL,
Johannes Berg04a773a2009-04-19 21:24:32 +020012768 },
12769 {
12770 .cmd = NL80211_CMD_LEAVE_IBSS,
12771 .doit = nl80211_leave_ibss,
12772 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012773 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020012774 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020012775 NL80211_FLAG_NEED_RTNL,
Johannes Berg04a773a2009-04-19 21:24:32 +020012776 },
Johannes Bergaff89a92009-07-01 21:26:51 +020012777#ifdef CONFIG_NL80211_TESTMODE
12778 {
12779 .cmd = NL80211_CMD_TESTMODE,
12780 .doit = nl80211_testmode_do,
Wey-Yi Guy71063f02011-05-20 09:05:54 -070012781 .dumpit = nl80211_testmode_dump,
Johannes Bergaff89a92009-07-01 21:26:51 +020012782 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012783 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020012784 .internal_flags = NL80211_FLAG_NEED_WIPHY |
12785 NL80211_FLAG_NEED_RTNL,
Johannes Bergaff89a92009-07-01 21:26:51 +020012786 },
12787#endif
Samuel Ortizb23aa672009-07-01 21:26:54 +020012788 {
12789 .cmd = NL80211_CMD_CONNECT,
12790 .doit = nl80211_connect,
12791 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012792 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020012793 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020012794 NL80211_FLAG_NEED_RTNL,
Samuel Ortizb23aa672009-07-01 21:26:54 +020012795 },
12796 {
vamsi krishna088e8df2016-10-27 16:51:11 +030012797 .cmd = NL80211_CMD_UPDATE_CONNECT_PARAMS,
12798 .doit = nl80211_update_connect_params,
12799 .policy = nl80211_policy,
12800 .flags = GENL_ADMIN_PERM,
12801 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
12802 NL80211_FLAG_NEED_RTNL,
12803 },
12804 {
Samuel Ortizb23aa672009-07-01 21:26:54 +020012805 .cmd = NL80211_CMD_DISCONNECT,
12806 .doit = nl80211_disconnect,
12807 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012808 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020012809 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020012810 NL80211_FLAG_NEED_RTNL,
Samuel Ortizb23aa672009-07-01 21:26:54 +020012811 },
Johannes Berg463d0182009-07-14 00:33:35 +020012812 {
12813 .cmd = NL80211_CMD_SET_WIPHY_NETNS,
12814 .doit = nl80211_wiphy_netns,
12815 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012816 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020012817 .internal_flags = NL80211_FLAG_NEED_WIPHY |
12818 NL80211_FLAG_NEED_RTNL,
Johannes Berg463d0182009-07-14 00:33:35 +020012819 },
Holger Schurig61fa7132009-11-11 12:25:40 +010012820 {
12821 .cmd = NL80211_CMD_GET_SURVEY,
12822 .policy = nl80211_policy,
12823 .dumpit = nl80211_dump_survey,
12824 },
Samuel Ortiz67fbb162009-11-24 23:59:15 +010012825 {
12826 .cmd = NL80211_CMD_SET_PMKSA,
12827 .doit = nl80211_setdel_pmksa,
12828 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012829 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020012830 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020012831 NL80211_FLAG_NEED_RTNL,
Samuel Ortiz67fbb162009-11-24 23:59:15 +010012832 },
12833 {
12834 .cmd = NL80211_CMD_DEL_PMKSA,
12835 .doit = nl80211_setdel_pmksa,
12836 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012837 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020012838 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020012839 NL80211_FLAG_NEED_RTNL,
Samuel Ortiz67fbb162009-11-24 23:59:15 +010012840 },
12841 {
12842 .cmd = NL80211_CMD_FLUSH_PMKSA,
12843 .doit = nl80211_flush_pmksa,
12844 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012845 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020012846 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020012847 NL80211_FLAG_NEED_RTNL,
Samuel Ortiz67fbb162009-11-24 23:59:15 +010012848 },
Jouni Malinen9588bbd2009-12-23 13:15:41 +010012849 {
12850 .cmd = NL80211_CMD_REMAIN_ON_CHANNEL,
12851 .doit = nl80211_remain_on_channel,
12852 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012853 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +020012854 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020012855 NL80211_FLAG_NEED_RTNL,
Jouni Malinen9588bbd2009-12-23 13:15:41 +010012856 },
12857 {
12858 .cmd = NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL,
12859 .doit = nl80211_cancel_remain_on_channel,
12860 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012861 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +020012862 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020012863 NL80211_FLAG_NEED_RTNL,
Jouni Malinen9588bbd2009-12-23 13:15:41 +010012864 },
Jouni Malinen13ae75b2009-12-29 12:59:45 +020012865 {
12866 .cmd = NL80211_CMD_SET_TX_BITRATE_MASK,
12867 .doit = nl80211_set_tx_bitrate_mask,
12868 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012869 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020012870 .internal_flags = NL80211_FLAG_NEED_NETDEV |
12871 NL80211_FLAG_NEED_RTNL,
Jouni Malinen13ae75b2009-12-29 12:59:45 +020012872 },
Jouni Malinen026331c2010-02-15 12:53:10 +020012873 {
Johannes Berg2e161f72010-08-12 15:38:38 +020012874 .cmd = NL80211_CMD_REGISTER_FRAME,
12875 .doit = nl80211_register_mgmt,
Jouni Malinen026331c2010-02-15 12:53:10 +020012876 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012877 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +020012878 .internal_flags = NL80211_FLAG_NEED_WDEV |
Johannes Berg4c476992010-10-04 21:36:35 +020012879 NL80211_FLAG_NEED_RTNL,
Jouni Malinen026331c2010-02-15 12:53:10 +020012880 },
12881 {
Johannes Berg2e161f72010-08-12 15:38:38 +020012882 .cmd = NL80211_CMD_FRAME,
12883 .doit = nl80211_tx_mgmt,
Jouni Malinen026331c2010-02-15 12:53:10 +020012884 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012885 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +020012886 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020012887 NL80211_FLAG_NEED_RTNL,
Jouni Malinen026331c2010-02-15 12:53:10 +020012888 },
Kalle Valoffb9eb32010-02-17 17:58:10 +020012889 {
Johannes Bergf7ca38d2010-11-25 10:02:29 +010012890 .cmd = NL80211_CMD_FRAME_WAIT_CANCEL,
12891 .doit = nl80211_tx_mgmt_cancel_wait,
12892 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012893 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +020012894 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Bergf7ca38d2010-11-25 10:02:29 +010012895 NL80211_FLAG_NEED_RTNL,
12896 },
12897 {
Kalle Valoffb9eb32010-02-17 17:58:10 +020012898 .cmd = NL80211_CMD_SET_POWER_SAVE,
12899 .doit = nl80211_set_power_save,
12900 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012901 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020012902 .internal_flags = NL80211_FLAG_NEED_NETDEV |
12903 NL80211_FLAG_NEED_RTNL,
Kalle Valoffb9eb32010-02-17 17:58:10 +020012904 },
12905 {
12906 .cmd = NL80211_CMD_GET_POWER_SAVE,
12907 .doit = nl80211_get_power_save,
12908 .policy = nl80211_policy,
12909 /* can be retrieved by unprivileged users */
Johannes Berg4c476992010-10-04 21:36:35 +020012910 .internal_flags = NL80211_FLAG_NEED_NETDEV |
12911 NL80211_FLAG_NEED_RTNL,
Kalle Valoffb9eb32010-02-17 17:58:10 +020012912 },
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020012913 {
12914 .cmd = NL80211_CMD_SET_CQM,
12915 .doit = nl80211_set_cqm,
12916 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012917 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020012918 .internal_flags = NL80211_FLAG_NEED_NETDEV |
12919 NL80211_FLAG_NEED_RTNL,
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020012920 },
Johannes Bergf444de02010-05-05 15:25:02 +020012921 {
12922 .cmd = NL80211_CMD_SET_CHANNEL,
12923 .doit = nl80211_set_channel,
12924 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012925 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020012926 .internal_flags = NL80211_FLAG_NEED_NETDEV |
12927 NL80211_FLAG_NEED_RTNL,
Johannes Bergf444de02010-05-05 15:25:02 +020012928 },
Bill Jordane8347eb2010-10-01 13:54:28 -040012929 {
12930 .cmd = NL80211_CMD_SET_WDS_PEER,
12931 .doit = nl80211_set_wds_peer,
12932 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012933 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg43b19952010-10-07 13:10:30 +020012934 .internal_flags = NL80211_FLAG_NEED_NETDEV |
12935 NL80211_FLAG_NEED_RTNL,
Bill Jordane8347eb2010-10-01 13:54:28 -040012936 },
Johannes Berg29cbe682010-12-03 09:20:44 +010012937 {
12938 .cmd = NL80211_CMD_JOIN_MESH,
12939 .doit = nl80211_join_mesh,
12940 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012941 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg29cbe682010-12-03 09:20:44 +010012942 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
12943 NL80211_FLAG_NEED_RTNL,
12944 },
12945 {
12946 .cmd = NL80211_CMD_LEAVE_MESH,
12947 .doit = nl80211_leave_mesh,
12948 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012949 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg29cbe682010-12-03 09:20:44 +010012950 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
12951 NL80211_FLAG_NEED_RTNL,
12952 },
Rostislav Lisovy6e0bd6c2014-11-03 10:33:18 +010012953 {
12954 .cmd = NL80211_CMD_JOIN_OCB,
12955 .doit = nl80211_join_ocb,
12956 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012957 .flags = GENL_UNS_ADMIN_PERM,
Rostislav Lisovy6e0bd6c2014-11-03 10:33:18 +010012958 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
12959 NL80211_FLAG_NEED_RTNL,
12960 },
12961 {
12962 .cmd = NL80211_CMD_LEAVE_OCB,
12963 .doit = nl80211_leave_ocb,
12964 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012965 .flags = GENL_UNS_ADMIN_PERM,
Rostislav Lisovy6e0bd6c2014-11-03 10:33:18 +010012966 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
12967 NL80211_FLAG_NEED_RTNL,
12968 },
Johannes Bergdfb89c52012-06-27 09:23:48 +020012969#ifdef CONFIG_PM
Johannes Bergff1b6e62011-05-04 15:37:28 +020012970 {
12971 .cmd = NL80211_CMD_GET_WOWLAN,
12972 .doit = nl80211_get_wowlan,
12973 .policy = nl80211_policy,
12974 /* can be retrieved by unprivileged users */
12975 .internal_flags = NL80211_FLAG_NEED_WIPHY |
12976 NL80211_FLAG_NEED_RTNL,
12977 },
12978 {
12979 .cmd = NL80211_CMD_SET_WOWLAN,
12980 .doit = nl80211_set_wowlan,
12981 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012982 .flags = GENL_UNS_ADMIN_PERM,
Johannes Bergff1b6e62011-05-04 15:37:28 +020012983 .internal_flags = NL80211_FLAG_NEED_WIPHY |
12984 NL80211_FLAG_NEED_RTNL,
12985 },
Johannes Bergdfb89c52012-06-27 09:23:48 +020012986#endif
Johannes Berge5497d72011-07-05 16:35:40 +020012987 {
12988 .cmd = NL80211_CMD_SET_REKEY_OFFLOAD,
12989 .doit = nl80211_set_rekey_data,
12990 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012991 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berge5497d72011-07-05 16:35:40 +020012992 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg5393b912014-09-10 15:00:16 +030012993 NL80211_FLAG_NEED_RTNL |
12994 NL80211_FLAG_CLEAR_SKB,
Johannes Berge5497d72011-07-05 16:35:40 +020012995 },
Arik Nemtsov109086c2011-09-28 14:12:50 +030012996 {
12997 .cmd = NL80211_CMD_TDLS_MGMT,
12998 .doit = nl80211_tdls_mgmt,
12999 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013000 .flags = GENL_UNS_ADMIN_PERM,
Arik Nemtsov109086c2011-09-28 14:12:50 +030013001 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
13002 NL80211_FLAG_NEED_RTNL,
13003 },
13004 {
13005 .cmd = NL80211_CMD_TDLS_OPER,
13006 .doit = nl80211_tdls_oper,
13007 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013008 .flags = GENL_UNS_ADMIN_PERM,
Arik Nemtsov109086c2011-09-28 14:12:50 +030013009 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
13010 NL80211_FLAG_NEED_RTNL,
13011 },
Johannes Berg28946da2011-11-04 11:18:12 +010013012 {
13013 .cmd = NL80211_CMD_UNEXPECTED_FRAME,
13014 .doit = nl80211_register_unexpected_frame,
13015 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013016 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg28946da2011-11-04 11:18:12 +010013017 .internal_flags = NL80211_FLAG_NEED_NETDEV |
13018 NL80211_FLAG_NEED_RTNL,
13019 },
Johannes Berg7f6cf312011-11-04 11:18:15 +010013020 {
13021 .cmd = NL80211_CMD_PROBE_CLIENT,
13022 .doit = nl80211_probe_client,
13023 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013024 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020013025 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg7f6cf312011-11-04 11:18:15 +010013026 NL80211_FLAG_NEED_RTNL,
13027 },
Johannes Berg5e760232011-11-04 11:18:17 +010013028 {
13029 .cmd = NL80211_CMD_REGISTER_BEACONS,
13030 .doit = nl80211_register_beacons,
13031 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013032 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg5e760232011-11-04 11:18:17 +010013033 .internal_flags = NL80211_FLAG_NEED_WIPHY |
13034 NL80211_FLAG_NEED_RTNL,
13035 },
Simon Wunderlich1d9d9212011-11-18 14:20:43 +010013036 {
13037 .cmd = NL80211_CMD_SET_NOACK_MAP,
13038 .doit = nl80211_set_noack_map,
13039 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013040 .flags = GENL_UNS_ADMIN_PERM,
Simon Wunderlich1d9d9212011-11-18 14:20:43 +010013041 .internal_flags = NL80211_FLAG_NEED_NETDEV |
13042 NL80211_FLAG_NEED_RTNL,
13043 },
Johannes Berg98104fde2012-06-16 00:19:54 +020013044 {
13045 .cmd = NL80211_CMD_START_P2P_DEVICE,
13046 .doit = nl80211_start_p2p_device,
13047 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013048 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg98104fde2012-06-16 00:19:54 +020013049 .internal_flags = NL80211_FLAG_NEED_WDEV |
13050 NL80211_FLAG_NEED_RTNL,
13051 },
13052 {
13053 .cmd = NL80211_CMD_STOP_P2P_DEVICE,
13054 .doit = nl80211_stop_p2p_device,
13055 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013056 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg98104fde2012-06-16 00:19:54 +020013057 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
13058 NL80211_FLAG_NEED_RTNL,
13059 },
Antonio Quartullif4e583c2012-11-02 13:27:48 +010013060 {
Ayala Bekercb3b7d82016-09-20 17:31:13 +030013061 .cmd = NL80211_CMD_START_NAN,
13062 .doit = nl80211_start_nan,
13063 .policy = nl80211_policy,
13064 .flags = GENL_ADMIN_PERM,
13065 .internal_flags = NL80211_FLAG_NEED_WDEV |
13066 NL80211_FLAG_NEED_RTNL,
13067 },
13068 {
13069 .cmd = NL80211_CMD_STOP_NAN,
13070 .doit = nl80211_stop_nan,
13071 .policy = nl80211_policy,
13072 .flags = GENL_ADMIN_PERM,
13073 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
13074 NL80211_FLAG_NEED_RTNL,
13075 },
13076 {
Ayala Bekera442b762016-09-20 17:31:15 +030013077 .cmd = NL80211_CMD_ADD_NAN_FUNCTION,
13078 .doit = nl80211_nan_add_func,
13079 .policy = nl80211_policy,
13080 .flags = GENL_ADMIN_PERM,
13081 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
13082 NL80211_FLAG_NEED_RTNL,
13083 },
13084 {
13085 .cmd = NL80211_CMD_DEL_NAN_FUNCTION,
13086 .doit = nl80211_nan_del_func,
13087 .policy = nl80211_policy,
13088 .flags = GENL_ADMIN_PERM,
13089 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
13090 NL80211_FLAG_NEED_RTNL,
13091 },
13092 {
Ayala Bekera5a9dcf2016-09-20 17:31:16 +030013093 .cmd = NL80211_CMD_CHANGE_NAN_CONFIG,
13094 .doit = nl80211_nan_change_config,
13095 .policy = nl80211_policy,
13096 .flags = GENL_ADMIN_PERM,
13097 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
13098 NL80211_FLAG_NEED_RTNL,
13099 },
13100 {
Antonio Quartullif4e583c2012-11-02 13:27:48 +010013101 .cmd = NL80211_CMD_SET_MCAST_RATE,
13102 .doit = nl80211_set_mcast_rate,
13103 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013104 .flags = GENL_UNS_ADMIN_PERM,
Antonio Quartullif4e583c2012-11-02 13:27:48 +010013105 .internal_flags = NL80211_FLAG_NEED_NETDEV |
13106 NL80211_FLAG_NEED_RTNL,
13107 },
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +053013108 {
13109 .cmd = NL80211_CMD_SET_MAC_ACL,
13110 .doit = nl80211_set_mac_acl,
13111 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013112 .flags = GENL_UNS_ADMIN_PERM,
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +053013113 .internal_flags = NL80211_FLAG_NEED_NETDEV |
13114 NL80211_FLAG_NEED_RTNL,
13115 },
Simon Wunderlich04f39042013-02-08 18:16:19 +010013116 {
13117 .cmd = NL80211_CMD_RADAR_DETECT,
13118 .doit = nl80211_start_radar_detection,
13119 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013120 .flags = GENL_UNS_ADMIN_PERM,
Simon Wunderlich04f39042013-02-08 18:16:19 +010013121 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
13122 NL80211_FLAG_NEED_RTNL,
13123 },
Johannes Berg3713b4e2013-02-14 16:19:38 +010013124 {
13125 .cmd = NL80211_CMD_GET_PROTOCOL_FEATURES,
13126 .doit = nl80211_get_protocol_features,
13127 .policy = nl80211_policy,
13128 },
Jouni Malinen355199e2013-02-27 17:14:27 +020013129 {
13130 .cmd = NL80211_CMD_UPDATE_FT_IES,
13131 .doit = nl80211_update_ft_ies,
13132 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013133 .flags = GENL_UNS_ADMIN_PERM,
Jouni Malinen355199e2013-02-27 17:14:27 +020013134 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
13135 NL80211_FLAG_NEED_RTNL,
13136 },
Arend van Spriel5de17982013-04-18 15:49:00 +020013137 {
13138 .cmd = NL80211_CMD_CRIT_PROTOCOL_START,
13139 .doit = nl80211_crit_protocol_start,
13140 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013141 .flags = GENL_UNS_ADMIN_PERM,
Arend van Spriel5de17982013-04-18 15:49:00 +020013142 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
13143 NL80211_FLAG_NEED_RTNL,
13144 },
13145 {
13146 .cmd = NL80211_CMD_CRIT_PROTOCOL_STOP,
13147 .doit = nl80211_crit_protocol_stop,
13148 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013149 .flags = GENL_UNS_ADMIN_PERM,
Arend van Spriel5de17982013-04-18 15:49:00 +020013150 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
13151 NL80211_FLAG_NEED_RTNL,
Amitkumar Karwarbe29b99a2013-06-28 11:51:26 -070013152 },
13153 {
13154 .cmd = NL80211_CMD_GET_COALESCE,
13155 .doit = nl80211_get_coalesce,
13156 .policy = nl80211_policy,
13157 .internal_flags = NL80211_FLAG_NEED_WIPHY |
13158 NL80211_FLAG_NEED_RTNL,
13159 },
13160 {
13161 .cmd = NL80211_CMD_SET_COALESCE,
13162 .doit = nl80211_set_coalesce,
13163 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013164 .flags = GENL_UNS_ADMIN_PERM,
Amitkumar Karwarbe29b99a2013-06-28 11:51:26 -070013165 .internal_flags = NL80211_FLAG_NEED_WIPHY |
13166 NL80211_FLAG_NEED_RTNL,
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +020013167 },
13168 {
13169 .cmd = NL80211_CMD_CHANNEL_SWITCH,
13170 .doit = nl80211_channel_switch,
13171 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013172 .flags = GENL_UNS_ADMIN_PERM,
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +020013173 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
13174 NL80211_FLAG_NEED_RTNL,
13175 },
Johannes Bergad7e7182013-11-13 13:37:47 +010013176 {
13177 .cmd = NL80211_CMD_VENDOR,
13178 .doit = nl80211_vendor_cmd,
Johannes Berg7bdbe402015-08-15 22:39:49 +030013179 .dumpit = nl80211_vendor_cmd_dump,
Johannes Bergad7e7182013-11-13 13:37:47 +010013180 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013181 .flags = GENL_UNS_ADMIN_PERM,
Johannes Bergad7e7182013-11-13 13:37:47 +010013182 .internal_flags = NL80211_FLAG_NEED_WIPHY |
13183 NL80211_FLAG_NEED_RTNL,
13184 },
Kyeyoon Parkfa9ffc72013-12-16 23:01:30 -080013185 {
13186 .cmd = NL80211_CMD_SET_QOS_MAP,
13187 .doit = nl80211_set_qos_map,
13188 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013189 .flags = GENL_UNS_ADMIN_PERM,
Kyeyoon Parkfa9ffc72013-12-16 23:01:30 -080013190 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
13191 NL80211_FLAG_NEED_RTNL,
13192 },
Johannes Berg960d01a2014-09-09 22:55:35 +030013193 {
13194 .cmd = NL80211_CMD_ADD_TX_TS,
13195 .doit = nl80211_add_tx_ts,
13196 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013197 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg960d01a2014-09-09 22:55:35 +030013198 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
13199 NL80211_FLAG_NEED_RTNL,
13200 },
13201 {
13202 .cmd = NL80211_CMD_DEL_TX_TS,
13203 .doit = nl80211_del_tx_ts,
13204 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013205 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg960d01a2014-09-09 22:55:35 +030013206 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
13207 NL80211_FLAG_NEED_RTNL,
13208 },
Arik Nemtsov1057d352014-11-19 12:54:26 +020013209 {
13210 .cmd = NL80211_CMD_TDLS_CHANNEL_SWITCH,
13211 .doit = nl80211_tdls_channel_switch,
13212 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013213 .flags = GENL_UNS_ADMIN_PERM,
Arik Nemtsov1057d352014-11-19 12:54:26 +020013214 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
13215 NL80211_FLAG_NEED_RTNL,
13216 },
13217 {
13218 .cmd = NL80211_CMD_TDLS_CANCEL_CHANNEL_SWITCH,
13219 .doit = nl80211_tdls_cancel_channel_switch,
13220 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013221 .flags = GENL_UNS_ADMIN_PERM,
Arik Nemtsov1057d352014-11-19 12:54:26 +020013222 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
13223 NL80211_FLAG_NEED_RTNL,
13224 },
Michael Braunce0ce132016-10-10 19:12:22 +020013225 {
13226 .cmd = NL80211_CMD_SET_MULTICAST_TO_UNICAST,
13227 .doit = nl80211_set_multicast_to_unicast,
13228 .policy = nl80211_policy,
13229 .flags = GENL_UNS_ADMIN_PERM,
13230 .internal_flags = NL80211_FLAG_NEED_NETDEV |
13231 NL80211_FLAG_NEED_RTNL,
13232 },
Avraham Stern3a00df52017-06-09 13:08:43 +010013233 {
13234 .cmd = NL80211_CMD_SET_PMK,
13235 .doit = nl80211_set_pmk,
13236 .policy = nl80211_policy,
13237 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
13238 NL80211_FLAG_NEED_RTNL,
13239 },
13240 {
13241 .cmd = NL80211_CMD_DEL_PMK,
13242 .doit = nl80211_del_pmk,
13243 .policy = nl80211_policy,
13244 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
13245 NL80211_FLAG_NEED_RTNL,
13246 },
13247
Johannes Berg55682962007-09-20 13:09:35 -040013248};
Jouni Malinen9588bbd2009-12-23 13:15:41 +010013249
Johannes Berg56989f62016-10-24 14:40:05 +020013250static struct genl_family nl80211_fam __ro_after_init = {
Johannes Berg489111e2016-10-24 14:40:03 +020013251 .name = NL80211_GENL_NAME, /* have users key off the name instead */
13252 .hdrsize = 0, /* no private header */
13253 .version = 1, /* no particular meaning now */
13254 .maxattr = NL80211_ATTR_MAX,
13255 .netnsok = true,
13256 .pre_doit = nl80211_pre_doit,
13257 .post_doit = nl80211_post_doit,
13258 .module = THIS_MODULE,
13259 .ops = nl80211_ops,
13260 .n_ops = ARRAY_SIZE(nl80211_ops),
13261 .mcgrps = nl80211_mcgrps,
13262 .n_mcgrps = ARRAY_SIZE(nl80211_mcgrps),
13263};
13264
Johannes Berg55682962007-09-20 13:09:35 -040013265/* notification functions */
13266
Johannes Berg3bb20552014-05-26 13:52:25 +020013267void nl80211_notify_wiphy(struct cfg80211_registered_device *rdev,
13268 enum nl80211_commands cmd)
Johannes Berg55682962007-09-20 13:09:35 -040013269{
13270 struct sk_buff *msg;
Johannes Berg86e8cf92013-06-19 10:57:22 +020013271 struct nl80211_dump_wiphy_state state = {};
Johannes Berg55682962007-09-20 13:09:35 -040013272
Johannes Berg3bb20552014-05-26 13:52:25 +020013273 WARN_ON(cmd != NL80211_CMD_NEW_WIPHY &&
13274 cmd != NL80211_CMD_DEL_WIPHY);
13275
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -070013276 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -040013277 if (!msg)
13278 return;
13279
Johannes Berg3bb20552014-05-26 13:52:25 +020013280 if (nl80211_send_wiphy(rdev, cmd, msg, 0, 0, 0, &state) < 0) {
Johannes Berg55682962007-09-20 13:09:35 -040013281 nlmsg_free(msg);
13282 return;
13283 }
13284
Johannes Berg68eb5502013-11-19 15:19:38 +010013285 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010013286 NL80211_MCGRP_CONFIG, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -040013287}
13288
Denis Kenzior896ff062016-08-03 16:58:33 -050013289void nl80211_notify_iface(struct cfg80211_registered_device *rdev,
13290 struct wireless_dev *wdev,
13291 enum nl80211_commands cmd)
13292{
13293 struct sk_buff *msg;
13294
13295 WARN_ON(cmd != NL80211_CMD_NEW_INTERFACE &&
13296 cmd != NL80211_CMD_DEL_INTERFACE);
13297
13298 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
13299 if (!msg)
13300 return;
13301
13302 if (nl80211_send_iface(msg, 0, 0, 0, rdev, wdev,
13303 cmd == NL80211_CMD_DEL_INTERFACE) < 0) {
13304 nlmsg_free(msg);
13305 return;
13306 }
13307
13308 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
13309 NL80211_MCGRP_CONFIG, GFP_KERNEL);
13310}
13311
Johannes Berg362a4152009-05-24 16:43:15 +020013312static int nl80211_add_scan_req(struct sk_buff *msg,
13313 struct cfg80211_registered_device *rdev)
13314{
13315 struct cfg80211_scan_request *req = rdev->scan_req;
13316 struct nlattr *nest;
13317 int i;
13318
13319 if (WARN_ON(!req))
13320 return 0;
13321
13322 nest = nla_nest_start(msg, NL80211_ATTR_SCAN_SSIDS);
13323 if (!nest)
13324 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -040013325 for (i = 0; i < req->n_ssids; i++) {
13326 if (nla_put(msg, i, req->ssids[i].ssid_len, req->ssids[i].ssid))
13327 goto nla_put_failure;
13328 }
Johannes Berg362a4152009-05-24 16:43:15 +020013329 nla_nest_end(msg, nest);
13330
13331 nest = nla_nest_start(msg, NL80211_ATTR_SCAN_FREQUENCIES);
13332 if (!nest)
13333 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -040013334 for (i = 0; i < req->n_channels; i++) {
13335 if (nla_put_u32(msg, i, req->channels[i]->center_freq))
13336 goto nla_put_failure;
13337 }
Johannes Berg362a4152009-05-24 16:43:15 +020013338 nla_nest_end(msg, nest);
13339
David S. Miller9360ffd2012-03-29 04:41:26 -040013340 if (req->ie &&
13341 nla_put(msg, NL80211_ATTR_IE, req->ie_len, req->ie))
13342 goto nla_put_failure;
Johannes Berg362a4152009-05-24 16:43:15 +020013343
Johannes Bergae917c92013-10-25 11:05:22 +020013344 if (req->flags &&
13345 nla_put_u32(msg, NL80211_ATTR_SCAN_FLAGS, req->flags))
13346 goto nla_put_failure;
Sam Lefflered4737712012-10-11 21:03:31 -070013347
Avraham Stern1d762502016-07-05 17:10:13 +030013348 if (req->info.scan_start_tsf &&
13349 (nla_put_u64_64bit(msg, NL80211_ATTR_SCAN_START_TIME_TSF,
13350 req->info.scan_start_tsf, NL80211_BSS_PAD) ||
13351 nla_put(msg, NL80211_ATTR_SCAN_START_TIME_TSF_BSSID, ETH_ALEN,
13352 req->info.tsf_bssid)))
13353 goto nla_put_failure;
13354
Johannes Berg362a4152009-05-24 16:43:15 +020013355 return 0;
13356 nla_put_failure:
13357 return -ENOBUFS;
13358}
13359
Arend Van Spriel505a2e82016-12-16 11:21:54 +000013360static int nl80211_prep_scan_msg(struct sk_buff *msg,
Johannes Berga538e2d2009-06-16 19:56:42 +020013361 struct cfg80211_registered_device *rdev,
Johannes Bergfd014282012-06-18 19:17:03 +020013362 struct wireless_dev *wdev,
Eric W. Biederman15e47302012-09-07 20:12:54 +000013363 u32 portid, u32 seq, int flags,
Johannes Berga538e2d2009-06-16 19:56:42 +020013364 u32 cmd)
Johannes Berg2a519312009-02-10 21:25:55 +010013365{
13366 void *hdr;
13367
Eric W. Biederman15e47302012-09-07 20:12:54 +000013368 hdr = nl80211hdr_put(msg, portid, seq, flags, cmd);
Johannes Berg2a519312009-02-10 21:25:55 +010013369 if (!hdr)
13370 return -1;
13371
David S. Miller9360ffd2012-03-29 04:41:26 -040013372 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Bergfd014282012-06-18 19:17:03 +020013373 (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
13374 wdev->netdev->ifindex)) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020013375 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
13376 NL80211_ATTR_PAD))
David S. Miller9360ffd2012-03-29 04:41:26 -040013377 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +010013378
Johannes Berg362a4152009-05-24 16:43:15 +020013379 /* ignore errors and send incomplete event anyway */
13380 nl80211_add_scan_req(msg, rdev);
Johannes Berg2a519312009-02-10 21:25:55 +010013381
Johannes Berg053c0952015-01-16 22:09:00 +010013382 genlmsg_end(msg, hdr);
13383 return 0;
Johannes Berg2a519312009-02-10 21:25:55 +010013384
13385 nla_put_failure:
13386 genlmsg_cancel(msg, hdr);
13387 return -EMSGSIZE;
13388}
13389
Luciano Coelho807f8a82011-05-11 17:09:35 +030013390static int
Arend Van Spriel505a2e82016-12-16 11:21:54 +000013391nl80211_prep_sched_scan_msg(struct sk_buff *msg,
Arend Van Spriel96b08fd2017-04-13 13:06:27 +010013392 struct cfg80211_sched_scan_request *req, u32 cmd)
Luciano Coelho807f8a82011-05-11 17:09:35 +030013393{
13394 void *hdr;
13395
Arend Van Spriel96b08fd2017-04-13 13:06:27 +010013396 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
Luciano Coelho807f8a82011-05-11 17:09:35 +030013397 if (!hdr)
13398 return -1;
13399
Arend Van Spriel96b08fd2017-04-13 13:06:27 +010013400 if (nla_put_u32(msg, NL80211_ATTR_WIPHY,
13401 wiphy_to_rdev(req->wiphy)->wiphy_idx) ||
13402 nla_put_u32(msg, NL80211_ATTR_IFINDEX, req->dev->ifindex) ||
13403 nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, req->reqid,
13404 NL80211_ATTR_PAD))
David S. Miller9360ffd2012-03-29 04:41:26 -040013405 goto nla_put_failure;
Luciano Coelho807f8a82011-05-11 17:09:35 +030013406
Johannes Berg053c0952015-01-16 22:09:00 +010013407 genlmsg_end(msg, hdr);
13408 return 0;
Luciano Coelho807f8a82011-05-11 17:09:35 +030013409
13410 nla_put_failure:
13411 genlmsg_cancel(msg, hdr);
13412 return -EMSGSIZE;
13413}
13414
Johannes Berga538e2d2009-06-16 19:56:42 +020013415void nl80211_send_scan_start(struct cfg80211_registered_device *rdev,
Johannes Bergfd014282012-06-18 19:17:03 +020013416 struct wireless_dev *wdev)
Johannes Berga538e2d2009-06-16 19:56:42 +020013417{
13418 struct sk_buff *msg;
13419
Thomas Graf58050fc2012-06-28 03:57:45 +000013420 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berga538e2d2009-06-16 19:56:42 +020013421 if (!msg)
13422 return;
13423
Arend Van Spriel505a2e82016-12-16 11:21:54 +000013424 if (nl80211_prep_scan_msg(msg, rdev, wdev, 0, 0, 0,
Johannes Berga538e2d2009-06-16 19:56:42 +020013425 NL80211_CMD_TRIGGER_SCAN) < 0) {
13426 nlmsg_free(msg);
13427 return;
13428 }
13429
Johannes Berg68eb5502013-11-19 15:19:38 +010013430 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010013431 NL80211_MCGRP_SCAN, GFP_KERNEL);
Johannes Berga538e2d2009-06-16 19:56:42 +020013432}
13433
Johannes Bergf9d15d12014-01-22 11:14:19 +020013434struct sk_buff *nl80211_build_scan_msg(struct cfg80211_registered_device *rdev,
13435 struct wireless_dev *wdev, bool aborted)
Johannes Berg2a519312009-02-10 21:25:55 +010013436{
13437 struct sk_buff *msg;
13438
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -070013439 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg2a519312009-02-10 21:25:55 +010013440 if (!msg)
Johannes Bergf9d15d12014-01-22 11:14:19 +020013441 return NULL;
Johannes Berg2a519312009-02-10 21:25:55 +010013442
Arend Van Spriel505a2e82016-12-16 11:21:54 +000013443 if (nl80211_prep_scan_msg(msg, rdev, wdev, 0, 0, 0,
Johannes Bergf9d15d12014-01-22 11:14:19 +020013444 aborted ? NL80211_CMD_SCAN_ABORTED :
13445 NL80211_CMD_NEW_SCAN_RESULTS) < 0) {
Johannes Berg2a519312009-02-10 21:25:55 +010013446 nlmsg_free(msg);
Johannes Bergf9d15d12014-01-22 11:14:19 +020013447 return NULL;
Johannes Berg2a519312009-02-10 21:25:55 +010013448 }
13449
Johannes Bergf9d15d12014-01-22 11:14:19 +020013450 return msg;
Johannes Berg2a519312009-02-10 21:25:55 +010013451}
13452
Arend Van Spriel505a2e82016-12-16 11:21:54 +000013453/* send message created by nl80211_build_scan_msg() */
13454void nl80211_send_scan_msg(struct cfg80211_registered_device *rdev,
13455 struct sk_buff *msg)
Johannes Berg2a519312009-02-10 21:25:55 +010013456{
Johannes Berg2a519312009-02-10 21:25:55 +010013457 if (!msg)
13458 return;
13459
Johannes Berg68eb5502013-11-19 15:19:38 +010013460 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010013461 NL80211_MCGRP_SCAN, GFP_KERNEL);
Johannes Berg2a519312009-02-10 21:25:55 +010013462}
13463
Arend Van Spriel96b08fd2017-04-13 13:06:27 +010013464void nl80211_send_sched_scan(struct cfg80211_sched_scan_request *req, u32 cmd)
Luciano Coelho807f8a82011-05-11 17:09:35 +030013465{
13466 struct sk_buff *msg;
13467
Thomas Graf58050fc2012-06-28 03:57:45 +000013468 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Luciano Coelho807f8a82011-05-11 17:09:35 +030013469 if (!msg)
13470 return;
13471
Arend Van Spriel96b08fd2017-04-13 13:06:27 +010013472 if (nl80211_prep_sched_scan_msg(msg, req, cmd) < 0) {
Luciano Coelho807f8a82011-05-11 17:09:35 +030013473 nlmsg_free(msg);
13474 return;
13475 }
13476
Arend Van Spriel96b08fd2017-04-13 13:06:27 +010013477 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(req->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010013478 NL80211_MCGRP_SCAN, GFP_KERNEL);
Luciano Coelho807f8a82011-05-11 17:09:35 +030013479}
13480
Jonathan Doronb0d7aa52014-12-15 19:26:00 +020013481static bool nl80211_reg_change_event_fill(struct sk_buff *msg,
13482 struct regulatory_request *request)
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040013483{
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040013484 /* Userspace can always count this one always being set */
David S. Miller9360ffd2012-03-29 04:41:26 -040013485 if (nla_put_u8(msg, NL80211_ATTR_REG_INITIATOR, request->initiator))
13486 goto nla_put_failure;
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040013487
David S. Miller9360ffd2012-03-29 04:41:26 -040013488 if (request->alpha2[0] == '0' && request->alpha2[1] == '0') {
13489 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
13490 NL80211_REGDOM_TYPE_WORLD))
13491 goto nla_put_failure;
13492 } else if (request->alpha2[0] == '9' && request->alpha2[1] == '9') {
13493 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
13494 NL80211_REGDOM_TYPE_CUSTOM_WORLD))
13495 goto nla_put_failure;
13496 } else if ((request->alpha2[0] == '9' && request->alpha2[1] == '8') ||
13497 request->intersect) {
13498 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
13499 NL80211_REGDOM_TYPE_INTERSECTION))
13500 goto nla_put_failure;
13501 } else {
13502 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
13503 NL80211_REGDOM_TYPE_COUNTRY) ||
13504 nla_put_string(msg, NL80211_ATTR_REG_ALPHA2,
13505 request->alpha2))
13506 goto nla_put_failure;
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040013507 }
13508
Arik Nemtsovad30ca22014-12-15 19:25:59 +020013509 if (request->wiphy_idx != WIPHY_IDX_INVALID) {
13510 struct wiphy *wiphy = wiphy_idx_to_wiphy(request->wiphy_idx);
13511
13512 if (wiphy &&
13513 nla_put_u32(msg, NL80211_ATTR_WIPHY, request->wiphy_idx))
13514 goto nla_put_failure;
Arik Nemtsov1bdd7162014-12-15 19:26:01 +020013515
13516 if (wiphy &&
13517 wiphy->regulatory_flags & REGULATORY_WIPHY_SELF_MANAGED &&
13518 nla_put_flag(msg, NL80211_ATTR_WIPHY_SELF_MANAGED_REG))
13519 goto nla_put_failure;
Arik Nemtsovad30ca22014-12-15 19:25:59 +020013520 }
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040013521
Jonathan Doronb0d7aa52014-12-15 19:26:00 +020013522 return true;
13523
13524nla_put_failure:
13525 return false;
13526}
13527
13528/*
13529 * This can happen on global regulatory changes or device specific settings
13530 * based on custom regulatory domains.
13531 */
13532void nl80211_common_reg_change_event(enum nl80211_commands cmd_id,
13533 struct regulatory_request *request)
13534{
13535 struct sk_buff *msg;
13536 void *hdr;
13537
13538 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
13539 if (!msg)
13540 return;
13541
13542 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd_id);
13543 if (!hdr) {
13544 nlmsg_free(msg);
13545 return;
13546 }
13547
13548 if (nl80211_reg_change_event_fill(msg, request) == false)
13549 goto nla_put_failure;
13550
Johannes Berg3b7b72e2011-10-22 19:05:51 +020013551 genlmsg_end(msg, hdr);
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040013552
Johannes Bergbc43b282009-07-25 10:54:13 +020013553 rcu_read_lock();
Johannes Berg68eb5502013-11-19 15:19:38 +010013554 genlmsg_multicast_allns(&nl80211_fam, msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010013555 NL80211_MCGRP_REGULATORY, GFP_ATOMIC);
Johannes Bergbc43b282009-07-25 10:54:13 +020013556 rcu_read_unlock();
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040013557
13558 return;
13559
13560nla_put_failure:
13561 genlmsg_cancel(msg, hdr);
13562 nlmsg_free(msg);
13563}
13564
Jouni Malinen6039f6d2009-03-19 13:39:21 +020013565static void nl80211_send_mlme_event(struct cfg80211_registered_device *rdev,
13566 struct net_device *netdev,
13567 const u8 *buf, size_t len,
Eliad Pellerb0b6aa22014-09-09 17:09:45 +030013568 enum nl80211_commands cmd, gfp_t gfp,
13569 int uapsd_queues)
Jouni Malinen6039f6d2009-03-19 13:39:21 +020013570{
13571 struct sk_buff *msg;
13572 void *hdr;
13573
Johannes Berg4ef8c1c2017-01-09 11:10:42 +010013574 msg = nlmsg_new(100 + len, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020013575 if (!msg)
13576 return;
13577
13578 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
13579 if (!hdr) {
13580 nlmsg_free(msg);
13581 return;
13582 }
13583
David S. Miller9360ffd2012-03-29 04:41:26 -040013584 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
13585 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
13586 nla_put(msg, NL80211_ATTR_FRAME, len, buf))
13587 goto nla_put_failure;
Jouni Malinen6039f6d2009-03-19 13:39:21 +020013588
Eliad Pellerb0b6aa22014-09-09 17:09:45 +030013589 if (uapsd_queues >= 0) {
13590 struct nlattr *nla_wmm =
13591 nla_nest_start(msg, NL80211_ATTR_STA_WME);
13592 if (!nla_wmm)
13593 goto nla_put_failure;
13594
13595 if (nla_put_u8(msg, NL80211_STA_WME_UAPSD_QUEUES,
13596 uapsd_queues))
13597 goto nla_put_failure;
13598
13599 nla_nest_end(msg, nla_wmm);
13600 }
13601
Johannes Berg3b7b72e2011-10-22 19:05:51 +020013602 genlmsg_end(msg, hdr);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020013603
Johannes Berg68eb5502013-11-19 15:19:38 +010013604 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010013605 NL80211_MCGRP_MLME, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020013606 return;
13607
13608 nla_put_failure:
13609 genlmsg_cancel(msg, hdr);
13610 nlmsg_free(msg);
13611}
13612
13613void nl80211_send_rx_auth(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +020013614 struct net_device *netdev, const u8 *buf,
13615 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +020013616{
13617 nl80211_send_mlme_event(rdev, netdev, buf, len,
Eliad Pellerb0b6aa22014-09-09 17:09:45 +030013618 NL80211_CMD_AUTHENTICATE, gfp, -1);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020013619}
13620
13621void nl80211_send_rx_assoc(struct cfg80211_registered_device *rdev,
13622 struct net_device *netdev, const u8 *buf,
Eliad Pellerb0b6aa22014-09-09 17:09:45 +030013623 size_t len, gfp_t gfp, int uapsd_queues)
Jouni Malinen6039f6d2009-03-19 13:39:21 +020013624{
Johannes Berge6d6e342009-07-01 21:26:47 +020013625 nl80211_send_mlme_event(rdev, netdev, buf, len,
Eliad Pellerb0b6aa22014-09-09 17:09:45 +030013626 NL80211_CMD_ASSOCIATE, gfp, uapsd_queues);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020013627}
13628
Jouni Malinen53b46b82009-03-27 20:53:56 +020013629void nl80211_send_deauth(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +020013630 struct net_device *netdev, const u8 *buf,
13631 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +020013632{
13633 nl80211_send_mlme_event(rdev, netdev, buf, len,
Eliad Pellerb0b6aa22014-09-09 17:09:45 +030013634 NL80211_CMD_DEAUTHENTICATE, gfp, -1);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020013635}
13636
Jouni Malinen53b46b82009-03-27 20:53:56 +020013637void nl80211_send_disassoc(struct cfg80211_registered_device *rdev,
13638 struct net_device *netdev, const u8 *buf,
Johannes Berge6d6e342009-07-01 21:26:47 +020013639 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +020013640{
13641 nl80211_send_mlme_event(rdev, netdev, buf, len,
Eliad Pellerb0b6aa22014-09-09 17:09:45 +030013642 NL80211_CMD_DISASSOCIATE, gfp, -1);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020013643}
13644
Johannes Berg6ff57cf2013-05-16 00:55:00 +020013645void cfg80211_rx_unprot_mlme_mgmt(struct net_device *dev, const u8 *buf,
13646 size_t len)
Jouni Malinencf4e5942010-12-16 00:52:40 +020013647{
Johannes Berg947add32013-02-22 22:05:20 +010013648 struct wireless_dev *wdev = dev->ieee80211_ptr;
13649 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080013650 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg6ff57cf2013-05-16 00:55:00 +020013651 const struct ieee80211_mgmt *mgmt = (void *)buf;
13652 u32 cmd;
Jouni Malinencf4e5942010-12-16 00:52:40 +020013653
Johannes Berg6ff57cf2013-05-16 00:55:00 +020013654 if (WARN_ON(len < 2))
13655 return;
13656
13657 if (ieee80211_is_deauth(mgmt->frame_control))
13658 cmd = NL80211_CMD_UNPROT_DEAUTHENTICATE;
13659 else
13660 cmd = NL80211_CMD_UNPROT_DISASSOCIATE;
13661
13662 trace_cfg80211_rx_unprot_mlme_mgmt(dev, buf, len);
Eliad Pellerb0b6aa22014-09-09 17:09:45 +030013663 nl80211_send_mlme_event(rdev, dev, buf, len, cmd, GFP_ATOMIC, -1);
Jouni Malinencf4e5942010-12-16 00:52:40 +020013664}
Johannes Berg6ff57cf2013-05-16 00:55:00 +020013665EXPORT_SYMBOL(cfg80211_rx_unprot_mlme_mgmt);
Jouni Malinencf4e5942010-12-16 00:52:40 +020013666
Luis R. Rodriguez1b06bb42009-05-02 00:34:48 -040013667static void nl80211_send_mlme_timeout(struct cfg80211_registered_device *rdev,
13668 struct net_device *netdev, int cmd,
Johannes Berge6d6e342009-07-01 21:26:47 +020013669 const u8 *addr, gfp_t gfp)
Jouni Malinen1965c852009-04-22 21:38:25 +030013670{
13671 struct sk_buff *msg;
13672 void *hdr;
13673
Johannes Berge6d6e342009-07-01 21:26:47 +020013674 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +030013675 if (!msg)
13676 return;
13677
13678 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
13679 if (!hdr) {
13680 nlmsg_free(msg);
13681 return;
13682 }
13683
David S. Miller9360ffd2012-03-29 04:41:26 -040013684 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
13685 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
13686 nla_put_flag(msg, NL80211_ATTR_TIMED_OUT) ||
13687 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr))
13688 goto nla_put_failure;
Jouni Malinen1965c852009-04-22 21:38:25 +030013689
Johannes Berg3b7b72e2011-10-22 19:05:51 +020013690 genlmsg_end(msg, hdr);
Jouni Malinen1965c852009-04-22 21:38:25 +030013691
Johannes Berg68eb5502013-11-19 15:19:38 +010013692 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010013693 NL80211_MCGRP_MLME, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +030013694 return;
13695
13696 nla_put_failure:
13697 genlmsg_cancel(msg, hdr);
13698 nlmsg_free(msg);
13699}
13700
13701void nl80211_send_auth_timeout(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +020013702 struct net_device *netdev, const u8 *addr,
13703 gfp_t gfp)
Jouni Malinen1965c852009-04-22 21:38:25 +030013704{
13705 nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_AUTHENTICATE,
Johannes Berge6d6e342009-07-01 21:26:47 +020013706 addr, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +030013707}
13708
13709void nl80211_send_assoc_timeout(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +020013710 struct net_device *netdev, const u8 *addr,
13711 gfp_t gfp)
Jouni Malinen1965c852009-04-22 21:38:25 +030013712{
Johannes Berge6d6e342009-07-01 21:26:47 +020013713 nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_ASSOCIATE,
13714 addr, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +030013715}
13716
Samuel Ortizb23aa672009-07-01 21:26:54 +020013717void nl80211_send_connect_result(struct cfg80211_registered_device *rdev,
Vidyullatha Kanchanapally5349a0f2017-03-31 00:22:33 +030013718 struct net_device *netdev,
13719 struct cfg80211_connect_resp_params *cr,
Purushottam Kushwaha3093ebbeab2017-01-13 01:12:21 +020013720 gfp_t gfp)
Samuel Ortizb23aa672009-07-01 21:26:54 +020013721{
13722 struct sk_buff *msg;
13723 void *hdr;
13724
Vidyullatha Kanchanapallya3caf742017-03-31 00:22:34 +030013725 msg = nlmsg_new(100 + cr->req_ie_len + cr->resp_ie_len +
13726 cr->fils_kek_len + cr->pmk_len +
13727 (cr->pmkid ? WLAN_PMKID_LEN : 0), gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +020013728 if (!msg)
13729 return;
13730
13731 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONNECT);
13732 if (!hdr) {
13733 nlmsg_free(msg);
13734 return;
13735 }
13736
David S. Miller9360ffd2012-03-29 04:41:26 -040013737 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
13738 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
Vidyullatha Kanchanapally5349a0f2017-03-31 00:22:33 +030013739 (cr->bssid &&
13740 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, cr->bssid)) ||
Jouni Malinenbf1ecd22016-05-31 00:16:50 +030013741 nla_put_u16(msg, NL80211_ATTR_STATUS_CODE,
Vidyullatha Kanchanapally5349a0f2017-03-31 00:22:33 +030013742 cr->status < 0 ? WLAN_STATUS_UNSPECIFIED_FAILURE :
13743 cr->status) ||
13744 (cr->status < 0 &&
Purushottam Kushwaha3093ebbeab2017-01-13 01:12:21 +020013745 (nla_put_flag(msg, NL80211_ATTR_TIMED_OUT) ||
Vidyullatha Kanchanapally5349a0f2017-03-31 00:22:33 +030013746 nla_put_u32(msg, NL80211_ATTR_TIMEOUT_REASON,
13747 cr->timeout_reason))) ||
13748 (cr->req_ie &&
13749 nla_put(msg, NL80211_ATTR_REQ_IE, cr->req_ie_len, cr->req_ie)) ||
13750 (cr->resp_ie &&
13751 nla_put(msg, NL80211_ATTR_RESP_IE, cr->resp_ie_len,
Vidyullatha Kanchanapallya3caf742017-03-31 00:22:34 +030013752 cr->resp_ie)) ||
13753 (cr->update_erp_next_seq_num &&
13754 nla_put_u16(msg, NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM,
13755 cr->fils_erp_next_seq_num)) ||
13756 (cr->status == WLAN_STATUS_SUCCESS &&
13757 ((cr->fils_kek &&
13758 nla_put(msg, NL80211_ATTR_FILS_KEK, cr->fils_kek_len,
13759 cr->fils_kek)) ||
13760 (cr->pmk &&
13761 nla_put(msg, NL80211_ATTR_PMK, cr->pmk_len, cr->pmk)) ||
13762 (cr->pmkid &&
13763 nla_put(msg, NL80211_ATTR_PMKID, WLAN_PMKID_LEN, cr->pmkid)))))
David S. Miller9360ffd2012-03-29 04:41:26 -040013764 goto nla_put_failure;
Samuel Ortizb23aa672009-07-01 21:26:54 +020013765
Johannes Berg3b7b72e2011-10-22 19:05:51 +020013766 genlmsg_end(msg, hdr);
Samuel Ortizb23aa672009-07-01 21:26:54 +020013767
Johannes Berg68eb5502013-11-19 15:19:38 +010013768 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010013769 NL80211_MCGRP_MLME, gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +020013770 return;
13771
13772 nla_put_failure:
13773 genlmsg_cancel(msg, hdr);
13774 nlmsg_free(msg);
Samuel Ortizb23aa672009-07-01 21:26:54 +020013775}
13776
13777void nl80211_send_roamed(struct cfg80211_registered_device *rdev,
Avraham Stern29ce6ec2017-04-26 10:58:49 +030013778 struct net_device *netdev,
13779 struct cfg80211_roam_info *info, gfp_t gfp)
Samuel Ortizb23aa672009-07-01 21:26:54 +020013780{
13781 struct sk_buff *msg;
13782 void *hdr;
Avraham Stern29ce6ec2017-04-26 10:58:49 +030013783 const u8 *bssid = info->bss ? info->bss->bssid : info->bssid;
Samuel Ortizb23aa672009-07-01 21:26:54 +020013784
Avraham Stern29ce6ec2017-04-26 10:58:49 +030013785 msg = nlmsg_new(100 + info->req_ie_len + info->resp_ie_len, gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +020013786 if (!msg)
13787 return;
13788
13789 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_ROAM);
13790 if (!hdr) {
13791 nlmsg_free(msg);
13792 return;
13793 }
13794
David S. Miller9360ffd2012-03-29 04:41:26 -040013795 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
13796 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
13797 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid) ||
Avraham Stern29ce6ec2017-04-26 10:58:49 +030013798 (info->req_ie &&
13799 nla_put(msg, NL80211_ATTR_REQ_IE, info->req_ie_len,
13800 info->req_ie)) ||
13801 (info->resp_ie &&
13802 nla_put(msg, NL80211_ATTR_RESP_IE, info->resp_ie_len,
Avraham Sternf45cbe62017-06-09 13:08:45 +010013803 info->resp_ie)) ||
13804 (info->authorized &&
13805 nla_put_flag(msg, NL80211_ATTR_PORT_AUTHORIZED)))
David S. Miller9360ffd2012-03-29 04:41:26 -040013806 goto nla_put_failure;
Samuel Ortizb23aa672009-07-01 21:26:54 +020013807
Johannes Berg3b7b72e2011-10-22 19:05:51 +020013808 genlmsg_end(msg, hdr);
Samuel Ortizb23aa672009-07-01 21:26:54 +020013809
Johannes Berg68eb5502013-11-19 15:19:38 +010013810 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010013811 NL80211_MCGRP_MLME, gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +020013812 return;
13813
13814 nla_put_failure:
13815 genlmsg_cancel(msg, hdr);
13816 nlmsg_free(msg);
Samuel Ortizb23aa672009-07-01 21:26:54 +020013817}
13818
13819void nl80211_send_disconnected(struct cfg80211_registered_device *rdev,
13820 struct net_device *netdev, u16 reason,
Johannes Berg667503d2009-07-07 03:56:11 +020013821 const u8 *ie, size_t ie_len, bool from_ap)
Samuel Ortizb23aa672009-07-01 21:26:54 +020013822{
13823 struct sk_buff *msg;
13824 void *hdr;
13825
Johannes Berg4ef8c1c2017-01-09 11:10:42 +010013826 msg = nlmsg_new(100 + ie_len, GFP_KERNEL);
Samuel Ortizb23aa672009-07-01 21:26:54 +020013827 if (!msg)
13828 return;
13829
13830 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DISCONNECT);
13831 if (!hdr) {
13832 nlmsg_free(msg);
13833 return;
13834 }
13835
David S. Miller9360ffd2012-03-29 04:41:26 -040013836 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
13837 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
13838 (from_ap && reason &&
13839 nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason)) ||
13840 (from_ap &&
13841 nla_put_flag(msg, NL80211_ATTR_DISCONNECTED_BY_AP)) ||
13842 (ie && nla_put(msg, NL80211_ATTR_IE, ie_len, ie)))
13843 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_KERNEL);
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
Johannes Berg04a773a2009-04-19 21:24:32 +020013856void nl80211_send_ibss_bssid(struct cfg80211_registered_device *rdev,
13857 struct net_device *netdev, const u8 *bssid,
13858 gfp_t gfp)
13859{
13860 struct sk_buff *msg;
13861 void *hdr;
13862
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -070013863 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Johannes Berg04a773a2009-04-19 21:24:32 +020013864 if (!msg)
13865 return;
13866
13867 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_JOIN_IBSS);
13868 if (!hdr) {
13869 nlmsg_free(msg);
13870 return;
13871 }
13872
David S. Miller9360ffd2012-03-29 04:41:26 -040013873 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
13874 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
13875 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid))
13876 goto nla_put_failure;
Johannes Berg04a773a2009-04-19 21:24:32 +020013877
Johannes Berg3b7b72e2011-10-22 19:05:51 +020013878 genlmsg_end(msg, hdr);
Johannes Berg04a773a2009-04-19 21:24:32 +020013879
Johannes Berg68eb5502013-11-19 15:19:38 +010013880 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010013881 NL80211_MCGRP_MLME, gfp);
Johannes Berg04a773a2009-04-19 21:24:32 +020013882 return;
13883
13884 nla_put_failure:
13885 genlmsg_cancel(msg, hdr);
13886 nlmsg_free(msg);
13887}
13888
Johannes Berg947add32013-02-22 22:05:20 +010013889void cfg80211_notify_new_peer_candidate(struct net_device *dev, const u8 *addr,
13890 const u8* ie, u8 ie_len, gfp_t gfp)
Javier Cardonac93b5e72011-04-07 15:08:34 -070013891{
Johannes Berg947add32013-02-22 22:05:20 +010013892 struct wireless_dev *wdev = dev->ieee80211_ptr;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080013893 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Javier Cardonac93b5e72011-04-07 15:08:34 -070013894 struct sk_buff *msg;
13895 void *hdr;
13896
Johannes Berg947add32013-02-22 22:05:20 +010013897 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_MESH_POINT))
13898 return;
13899
13900 trace_cfg80211_notify_new_peer_candidate(dev, addr);
13901
Johannes Berg4ef8c1c2017-01-09 11:10:42 +010013902 msg = nlmsg_new(100 + ie_len, gfp);
Javier Cardonac93b5e72011-04-07 15:08:34 -070013903 if (!msg)
13904 return;
13905
13906 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NEW_PEER_CANDIDATE);
13907 if (!hdr) {
13908 nlmsg_free(msg);
13909 return;
13910 }
13911
David S. Miller9360ffd2012-03-29 04:41:26 -040013912 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg947add32013-02-22 22:05:20 +010013913 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
13914 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040013915 (ie_len && ie &&
13916 nla_put(msg, NL80211_ATTR_IE, ie_len , ie)))
13917 goto nla_put_failure;
Javier Cardonac93b5e72011-04-07 15:08:34 -070013918
Johannes Berg3b7b72e2011-10-22 19:05:51 +020013919 genlmsg_end(msg, hdr);
Javier Cardonac93b5e72011-04-07 15:08:34 -070013920
Johannes Berg68eb5502013-11-19 15:19:38 +010013921 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010013922 NL80211_MCGRP_MLME, gfp);
Javier Cardonac93b5e72011-04-07 15:08:34 -070013923 return;
13924
13925 nla_put_failure:
13926 genlmsg_cancel(msg, hdr);
13927 nlmsg_free(msg);
13928}
Johannes Berg947add32013-02-22 22:05:20 +010013929EXPORT_SYMBOL(cfg80211_notify_new_peer_candidate);
Javier Cardonac93b5e72011-04-07 15:08:34 -070013930
Jouni Malinena3b8b052009-03-27 21:59:49 +020013931void nl80211_michael_mic_failure(struct cfg80211_registered_device *rdev,
13932 struct net_device *netdev, const u8 *addr,
13933 enum nl80211_key_type key_type, int key_id,
Johannes Berge6d6e342009-07-01 21:26:47 +020013934 const u8 *tsc, gfp_t gfp)
Jouni Malinena3b8b052009-03-27 21:59:49 +020013935{
13936 struct sk_buff *msg;
13937 void *hdr;
13938
Johannes Berge6d6e342009-07-01 21:26:47 +020013939 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinena3b8b052009-03-27 21:59:49 +020013940 if (!msg)
13941 return;
13942
13943 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_MICHAEL_MIC_FAILURE);
13944 if (!hdr) {
13945 nlmsg_free(msg);
13946 return;
13947 }
13948
David S. Miller9360ffd2012-03-29 04:41:26 -040013949 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
13950 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
13951 (addr && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) ||
13952 nla_put_u32(msg, NL80211_ATTR_KEY_TYPE, key_type) ||
13953 (key_id != -1 &&
13954 nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_id)) ||
13955 (tsc && nla_put(msg, NL80211_ATTR_KEY_SEQ, 6, tsc)))
13956 goto nla_put_failure;
Jouni Malinena3b8b052009-03-27 21:59:49 +020013957
Johannes Berg3b7b72e2011-10-22 19:05:51 +020013958 genlmsg_end(msg, hdr);
Jouni Malinena3b8b052009-03-27 21:59:49 +020013959
Johannes Berg68eb5502013-11-19 15:19:38 +010013960 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010013961 NL80211_MCGRP_MLME, gfp);
Jouni Malinena3b8b052009-03-27 21:59:49 +020013962 return;
13963
13964 nla_put_failure:
13965 genlmsg_cancel(msg, hdr);
13966 nlmsg_free(msg);
13967}
13968
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040013969void nl80211_send_beacon_hint_event(struct wiphy *wiphy,
13970 struct ieee80211_channel *channel_before,
13971 struct ieee80211_channel *channel_after)
13972{
13973 struct sk_buff *msg;
13974 void *hdr;
13975 struct nlattr *nl_freq;
13976
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -070013977 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_ATOMIC);
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040013978 if (!msg)
13979 return;
13980
13981 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_BEACON_HINT);
13982 if (!hdr) {
13983 nlmsg_free(msg);
13984 return;
13985 }
13986
13987 /*
13988 * Since we are applying the beacon hint to a wiphy we know its
13989 * wiphy_idx is valid
13990 */
David S. Miller9360ffd2012-03-29 04:41:26 -040013991 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy)))
13992 goto nla_put_failure;
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040013993
13994 /* Before */
13995 nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_BEFORE);
13996 if (!nl_freq)
13997 goto nla_put_failure;
Johannes Bergcdc89b92013-02-18 23:54:36 +010013998 if (nl80211_msg_put_channel(msg, channel_before, false))
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040013999 goto nla_put_failure;
14000 nla_nest_end(msg, nl_freq);
14001
14002 /* After */
14003 nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_AFTER);
14004 if (!nl_freq)
14005 goto nla_put_failure;
Johannes Bergcdc89b92013-02-18 23:54:36 +010014006 if (nl80211_msg_put_channel(msg, channel_after, false))
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040014007 goto nla_put_failure;
14008 nla_nest_end(msg, nl_freq);
14009
Johannes Berg3b7b72e2011-10-22 19:05:51 +020014010 genlmsg_end(msg, hdr);
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040014011
Johannes Berg463d0182009-07-14 00:33:35 +020014012 rcu_read_lock();
Johannes Berg68eb5502013-11-19 15:19:38 +010014013 genlmsg_multicast_allns(&nl80211_fam, msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010014014 NL80211_MCGRP_REGULATORY, GFP_ATOMIC);
Johannes Berg463d0182009-07-14 00:33:35 +020014015 rcu_read_unlock();
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040014016
14017 return;
14018
14019nla_put_failure:
14020 genlmsg_cancel(msg, hdr);
14021 nlmsg_free(msg);
14022}
14023
Jouni Malinen9588bbd2009-12-23 13:15:41 +010014024static void nl80211_send_remain_on_chan_event(
14025 int cmd, struct cfg80211_registered_device *rdev,
Johannes Berg71bbc992012-06-15 15:30:18 +020014026 struct wireless_dev *wdev, u64 cookie,
Jouni Malinen9588bbd2009-12-23 13:15:41 +010014027 struct ieee80211_channel *chan,
Jouni Malinen9588bbd2009-12-23 13:15:41 +010014028 unsigned int duration, gfp_t gfp)
14029{
14030 struct sk_buff *msg;
14031 void *hdr;
14032
14033 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
14034 if (!msg)
14035 return;
14036
14037 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
14038 if (!hdr) {
14039 nlmsg_free(msg);
14040 return;
14041 }
14042
David S. Miller9360ffd2012-03-29 04:41:26 -040014043 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg71bbc992012-06-15 15:30:18 +020014044 (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
14045 wdev->netdev->ifindex)) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020014046 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
14047 NL80211_ATTR_PAD) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040014048 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, chan->center_freq) ||
Johannes Berg42d97a52012-11-08 18:31:02 +010014049 nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE,
14050 NL80211_CHAN_NO_HT) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020014051 nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie,
14052 NL80211_ATTR_PAD))
David S. Miller9360ffd2012-03-29 04:41:26 -040014053 goto nla_put_failure;
Jouni Malinen9588bbd2009-12-23 13:15:41 +010014054
David S. Miller9360ffd2012-03-29 04:41:26 -040014055 if (cmd == NL80211_CMD_REMAIN_ON_CHANNEL &&
14056 nla_put_u32(msg, NL80211_ATTR_DURATION, duration))
14057 goto nla_put_failure;
Jouni Malinen9588bbd2009-12-23 13:15:41 +010014058
Johannes Berg3b7b72e2011-10-22 19:05:51 +020014059 genlmsg_end(msg, hdr);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010014060
Johannes Berg68eb5502013-11-19 15:19:38 +010014061 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010014062 NL80211_MCGRP_MLME, gfp);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010014063 return;
14064
14065 nla_put_failure:
14066 genlmsg_cancel(msg, hdr);
14067 nlmsg_free(msg);
14068}
14069
Johannes Berg947add32013-02-22 22:05:20 +010014070void cfg80211_ready_on_channel(struct wireless_dev *wdev, u64 cookie,
14071 struct ieee80211_channel *chan,
14072 unsigned int duration, gfp_t gfp)
Jouni Malinen9588bbd2009-12-23 13:15:41 +010014073{
Johannes Berg947add32013-02-22 22:05:20 +010014074 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080014075 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg947add32013-02-22 22:05:20 +010014076
14077 trace_cfg80211_ready_on_channel(wdev, cookie, chan, duration);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010014078 nl80211_send_remain_on_chan_event(NL80211_CMD_REMAIN_ON_CHANNEL,
Johannes Berg71bbc992012-06-15 15:30:18 +020014079 rdev, wdev, cookie, chan,
Johannes Berg42d97a52012-11-08 18:31:02 +010014080 duration, gfp);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010014081}
Johannes Berg947add32013-02-22 22:05:20 +010014082EXPORT_SYMBOL(cfg80211_ready_on_channel);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010014083
Johannes Berg947add32013-02-22 22:05:20 +010014084void cfg80211_remain_on_channel_expired(struct wireless_dev *wdev, u64 cookie,
14085 struct ieee80211_channel *chan,
14086 gfp_t gfp)
Jouni Malinen9588bbd2009-12-23 13:15:41 +010014087{
Johannes Berg947add32013-02-22 22:05:20 +010014088 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080014089 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg947add32013-02-22 22:05:20 +010014090
14091 trace_cfg80211_ready_on_channel_expired(wdev, cookie, chan);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010014092 nl80211_send_remain_on_chan_event(NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL,
Johannes Berg42d97a52012-11-08 18:31:02 +010014093 rdev, wdev, cookie, chan, 0, gfp);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010014094}
Johannes Berg947add32013-02-22 22:05:20 +010014095EXPORT_SYMBOL(cfg80211_remain_on_channel_expired);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010014096
Johannes Berg947add32013-02-22 22:05:20 +010014097void cfg80211_new_sta(struct net_device *dev, const u8 *mac_addr,
14098 struct station_info *sinfo, gfp_t gfp)
Johannes Berg98b62182009-12-23 13:15:44 +010014099{
Johannes Berg947add32013-02-22 22:05:20 +010014100 struct wiphy *wiphy = dev->ieee80211_ptr->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080014101 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg98b62182009-12-23 13:15:44 +010014102 struct sk_buff *msg;
14103
Johannes Berg947add32013-02-22 22:05:20 +010014104 trace_cfg80211_new_sta(dev, mac_addr, sinfo);
14105
Thomas Graf58050fc2012-06-28 03:57:45 +000014106 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Johannes Berg98b62182009-12-23 13:15:44 +010014107 if (!msg)
14108 return;
14109
Johannes Bergcf5ead82014-11-14 17:14:00 +010014110 if (nl80211_send_station(msg, NL80211_CMD_NEW_STATION, 0, 0, 0,
John W. Linville66266b32012-03-15 13:25:41 -040014111 rdev, dev, mac_addr, sinfo) < 0) {
Johannes Berg98b62182009-12-23 13:15:44 +010014112 nlmsg_free(msg);
14113 return;
14114 }
14115
Johannes Berg68eb5502013-11-19 15:19:38 +010014116 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010014117 NL80211_MCGRP_MLME, gfp);
Johannes Berg98b62182009-12-23 13:15:44 +010014118}
Johannes Berg947add32013-02-22 22:05:20 +010014119EXPORT_SYMBOL(cfg80211_new_sta);
Johannes Berg98b62182009-12-23 13:15:44 +010014120
Johannes Bergcf5ead82014-11-14 17:14:00 +010014121void cfg80211_del_sta_sinfo(struct net_device *dev, const u8 *mac_addr,
14122 struct station_info *sinfo, gfp_t gfp)
Jouni Malinenec15e682011-03-23 15:29:52 +020014123{
Johannes Berg947add32013-02-22 22:05:20 +010014124 struct wiphy *wiphy = dev->ieee80211_ptr->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080014125 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Jouni Malinenec15e682011-03-23 15:29:52 +020014126 struct sk_buff *msg;
Johannes Bergcf5ead82014-11-14 17:14:00 +010014127 struct station_info empty_sinfo = {};
14128
14129 if (!sinfo)
14130 sinfo = &empty_sinfo;
Jouni Malinenec15e682011-03-23 15:29:52 +020014131
Johannes Berg947add32013-02-22 22:05:20 +010014132 trace_cfg80211_del_sta(dev, mac_addr);
14133
Thomas Graf58050fc2012-06-28 03:57:45 +000014134 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinenec15e682011-03-23 15:29:52 +020014135 if (!msg)
14136 return;
14137
Johannes Bergcf5ead82014-11-14 17:14:00 +010014138 if (nl80211_send_station(msg, NL80211_CMD_DEL_STATION, 0, 0, 0,
Johannes Berg57007122015-01-16 21:05:02 +010014139 rdev, dev, mac_addr, sinfo) < 0) {
Jouni Malinenec15e682011-03-23 15:29:52 +020014140 nlmsg_free(msg);
14141 return;
14142 }
14143
Johannes Berg68eb5502013-11-19 15:19:38 +010014144 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010014145 NL80211_MCGRP_MLME, gfp);
Jouni Malinenec15e682011-03-23 15:29:52 +020014146}
Johannes Bergcf5ead82014-11-14 17:14:00 +010014147EXPORT_SYMBOL(cfg80211_del_sta_sinfo);
Jouni Malinenec15e682011-03-23 15:29:52 +020014148
Johannes Berg947add32013-02-22 22:05:20 +010014149void cfg80211_conn_failed(struct net_device *dev, const u8 *mac_addr,
14150 enum nl80211_connect_failed_reason reason,
14151 gfp_t gfp)
Pandiyarajan Pitchaimuthued44a952012-09-18 16:50:49 +053014152{
Johannes Berg947add32013-02-22 22:05:20 +010014153 struct wiphy *wiphy = dev->ieee80211_ptr->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080014154 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Pandiyarajan Pitchaimuthued44a952012-09-18 16:50:49 +053014155 struct sk_buff *msg;
14156 void *hdr;
14157
14158 msg = nlmsg_new(NLMSG_GOODSIZE, gfp);
14159 if (!msg)
14160 return;
14161
14162 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONN_FAILED);
14163 if (!hdr) {
14164 nlmsg_free(msg);
14165 return;
14166 }
14167
14168 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
14169 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) ||
14170 nla_put_u32(msg, NL80211_ATTR_CONN_FAILED_REASON, reason))
14171 goto nla_put_failure;
14172
14173 genlmsg_end(msg, hdr);
14174
Johannes Berg68eb5502013-11-19 15:19:38 +010014175 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010014176 NL80211_MCGRP_MLME, gfp);
Pandiyarajan Pitchaimuthued44a952012-09-18 16:50:49 +053014177 return;
14178
14179 nla_put_failure:
14180 genlmsg_cancel(msg, hdr);
14181 nlmsg_free(msg);
14182}
Johannes Berg947add32013-02-22 22:05:20 +010014183EXPORT_SYMBOL(cfg80211_conn_failed);
Pandiyarajan Pitchaimuthued44a952012-09-18 16:50:49 +053014184
Johannes Bergb92ab5d2011-11-04 11:18:19 +010014185static bool __nl80211_unexpected_frame(struct net_device *dev, u8 cmd,
14186 const u8 *addr, gfp_t gfp)
Johannes Berg28946da2011-11-04 11:18:12 +010014187{
14188 struct wireless_dev *wdev = dev->ieee80211_ptr;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080014189 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Johannes Berg28946da2011-11-04 11:18:12 +010014190 struct sk_buff *msg;
14191 void *hdr;
Eric W. Biederman15e47302012-09-07 20:12:54 +000014192 u32 nlportid = ACCESS_ONCE(wdev->ap_unexpected_nlportid);
Johannes Berg28946da2011-11-04 11:18:12 +010014193
Eric W. Biederman15e47302012-09-07 20:12:54 +000014194 if (!nlportid)
Johannes Berg28946da2011-11-04 11:18:12 +010014195 return false;
14196
14197 msg = nlmsg_new(100, gfp);
14198 if (!msg)
14199 return true;
14200
Johannes Bergb92ab5d2011-11-04 11:18:19 +010014201 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
Johannes Berg28946da2011-11-04 11:18:12 +010014202 if (!hdr) {
14203 nlmsg_free(msg);
14204 return true;
14205 }
14206
David S. Miller9360ffd2012-03-29 04:41:26 -040014207 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
14208 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
14209 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr))
14210 goto nla_put_failure;
Johannes Berg28946da2011-11-04 11:18:12 +010014211
Johannes Berg9c90a9f2013-06-04 12:46:03 +020014212 genlmsg_end(msg, hdr);
Eric W. Biederman15e47302012-09-07 20:12:54 +000014213 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid);
Johannes Berg28946da2011-11-04 11:18:12 +010014214 return true;
14215
14216 nla_put_failure:
14217 genlmsg_cancel(msg, hdr);
14218 nlmsg_free(msg);
14219 return true;
14220}
14221
Johannes Berg947add32013-02-22 22:05:20 +010014222bool cfg80211_rx_spurious_frame(struct net_device *dev,
14223 const u8 *addr, gfp_t gfp)
Johannes Bergb92ab5d2011-11-04 11:18:19 +010014224{
Johannes Berg947add32013-02-22 22:05:20 +010014225 struct wireless_dev *wdev = dev->ieee80211_ptr;
14226 bool ret;
Johannes Bergb92ab5d2011-11-04 11:18:19 +010014227
Johannes Berg947add32013-02-22 22:05:20 +010014228 trace_cfg80211_rx_spurious_frame(dev, addr);
14229
14230 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP &&
14231 wdev->iftype != NL80211_IFTYPE_P2P_GO)) {
14232 trace_cfg80211_return_bool(false);
14233 return false;
14234 }
14235 ret = __nl80211_unexpected_frame(dev, NL80211_CMD_UNEXPECTED_FRAME,
14236 addr, gfp);
14237 trace_cfg80211_return_bool(ret);
14238 return ret;
Johannes Bergb92ab5d2011-11-04 11:18:19 +010014239}
Johannes Berg947add32013-02-22 22:05:20 +010014240EXPORT_SYMBOL(cfg80211_rx_spurious_frame);
14241
14242bool cfg80211_rx_unexpected_4addr_frame(struct net_device *dev,
14243 const u8 *addr, gfp_t gfp)
14244{
14245 struct wireless_dev *wdev = dev->ieee80211_ptr;
14246 bool ret;
14247
14248 trace_cfg80211_rx_unexpected_4addr_frame(dev, addr);
14249
14250 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP &&
14251 wdev->iftype != NL80211_IFTYPE_P2P_GO &&
14252 wdev->iftype != NL80211_IFTYPE_AP_VLAN)) {
14253 trace_cfg80211_return_bool(false);
14254 return false;
14255 }
14256 ret = __nl80211_unexpected_frame(dev,
14257 NL80211_CMD_UNEXPECTED_4ADDR_FRAME,
14258 addr, gfp);
14259 trace_cfg80211_return_bool(ret);
14260 return ret;
14261}
14262EXPORT_SYMBOL(cfg80211_rx_unexpected_4addr_frame);
Johannes Bergb92ab5d2011-11-04 11:18:19 +010014263
Johannes Berg2e161f72010-08-12 15:38:38 +020014264int nl80211_send_mgmt(struct cfg80211_registered_device *rdev,
Eric W. Biederman15e47302012-09-07 20:12:54 +000014265 struct wireless_dev *wdev, u32 nlportid,
Johannes Berg804483e2012-03-05 22:18:41 +010014266 int freq, int sig_dbm,
Vladimir Kondratiev19504cf2013-08-15 14:51:28 +030014267 const u8 *buf, size_t len, u32 flags, gfp_t gfp)
Jouni Malinen026331c2010-02-15 12:53:10 +020014268{
Johannes Berg71bbc992012-06-15 15:30:18 +020014269 struct net_device *netdev = wdev->netdev;
Jouni Malinen026331c2010-02-15 12:53:10 +020014270 struct sk_buff *msg;
14271 void *hdr;
Jouni Malinen026331c2010-02-15 12:53:10 +020014272
Johannes Berg4ef8c1c2017-01-09 11:10:42 +010014273 msg = nlmsg_new(100 + len, gfp);
Jouni Malinen026331c2010-02-15 12:53:10 +020014274 if (!msg)
14275 return -ENOMEM;
14276
Johannes Berg2e161f72010-08-12 15:38:38 +020014277 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME);
Jouni Malinen026331c2010-02-15 12:53:10 +020014278 if (!hdr) {
14279 nlmsg_free(msg);
14280 return -ENOMEM;
14281 }
14282
David S. Miller9360ffd2012-03-29 04:41:26 -040014283 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg71bbc992012-06-15 15:30:18 +020014284 (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
14285 netdev->ifindex)) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020014286 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
14287 NL80211_ATTR_PAD) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040014288 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq) ||
14289 (sig_dbm &&
14290 nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) ||
Vladimir Kondratiev19504cf2013-08-15 14:51:28 +030014291 nla_put(msg, NL80211_ATTR_FRAME, len, buf) ||
14292 (flags &&
14293 nla_put_u32(msg, NL80211_ATTR_RXMGMT_FLAGS, flags)))
David S. Miller9360ffd2012-03-29 04:41:26 -040014294 goto nla_put_failure;
Jouni Malinen026331c2010-02-15 12:53:10 +020014295
Johannes Berg3b7b72e2011-10-22 19:05:51 +020014296 genlmsg_end(msg, hdr);
Jouni Malinen026331c2010-02-15 12:53:10 +020014297
Eric W. Biederman15e47302012-09-07 20:12:54 +000014298 return genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid);
Jouni Malinen026331c2010-02-15 12:53:10 +020014299
14300 nla_put_failure:
14301 genlmsg_cancel(msg, hdr);
14302 nlmsg_free(msg);
14303 return -ENOBUFS;
14304}
14305
Johannes Berg947add32013-02-22 22:05:20 +010014306void cfg80211_mgmt_tx_status(struct wireless_dev *wdev, u64 cookie,
14307 const u8 *buf, size_t len, bool ack, gfp_t gfp)
Jouni Malinen026331c2010-02-15 12:53:10 +020014308{
Johannes Berg947add32013-02-22 22:05:20 +010014309 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080014310 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg71bbc992012-06-15 15:30:18 +020014311 struct net_device *netdev = wdev->netdev;
Jouni Malinen026331c2010-02-15 12:53:10 +020014312 struct sk_buff *msg;
14313 void *hdr;
14314
Johannes Berg947add32013-02-22 22:05:20 +010014315 trace_cfg80211_mgmt_tx_status(wdev, cookie, ack);
14316
Johannes Berg4ef8c1c2017-01-09 11:10:42 +010014317 msg = nlmsg_new(100 + len, gfp);
Jouni Malinen026331c2010-02-15 12:53:10 +020014318 if (!msg)
14319 return;
14320
Johannes Berg2e161f72010-08-12 15:38:38 +020014321 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME_TX_STATUS);
Jouni Malinen026331c2010-02-15 12:53:10 +020014322 if (!hdr) {
14323 nlmsg_free(msg);
14324 return;
14325 }
14326
David S. Miller9360ffd2012-03-29 04:41:26 -040014327 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg71bbc992012-06-15 15:30:18 +020014328 (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
14329 netdev->ifindex)) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020014330 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
14331 NL80211_ATTR_PAD) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040014332 nla_put(msg, NL80211_ATTR_FRAME, len, buf) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020014333 nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie,
14334 NL80211_ATTR_PAD) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040014335 (ack && nla_put_flag(msg, NL80211_ATTR_ACK)))
14336 goto nla_put_failure;
Jouni Malinen026331c2010-02-15 12:53:10 +020014337
Johannes Berg3b7b72e2011-10-22 19:05:51 +020014338 genlmsg_end(msg, hdr);
Jouni Malinen026331c2010-02-15 12:53:10 +020014339
Johannes Berg68eb5502013-11-19 15:19:38 +010014340 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010014341 NL80211_MCGRP_MLME, gfp);
Jouni Malinen026331c2010-02-15 12:53:10 +020014342 return;
14343
14344 nla_put_failure:
14345 genlmsg_cancel(msg, hdr);
14346 nlmsg_free(msg);
14347}
Johannes Berg947add32013-02-22 22:05:20 +010014348EXPORT_SYMBOL(cfg80211_mgmt_tx_status);
Jouni Malinen026331c2010-02-15 12:53:10 +020014349
Johannes Berg5b97f492014-11-26 12:37:43 +010014350static struct sk_buff *cfg80211_prepare_cqm(struct net_device *dev,
14351 const char *mac, gfp_t gfp)
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020014352{
Johannes Berg947add32013-02-22 22:05:20 +010014353 struct wireless_dev *wdev = dev->ieee80211_ptr;
Johannes Berg5b97f492014-11-26 12:37:43 +010014354 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
14355 struct sk_buff *msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
14356 void **cb;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020014357
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020014358 if (!msg)
Johannes Berg5b97f492014-11-26 12:37:43 +010014359 return NULL;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020014360
Johannes Berg5b97f492014-11-26 12:37:43 +010014361 cb = (void **)msg->cb;
14362
14363 cb[0] = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM);
14364 if (!cb[0]) {
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020014365 nlmsg_free(msg);
Johannes Berg5b97f492014-11-26 12:37:43 +010014366 return NULL;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020014367 }
14368
David S. Miller9360ffd2012-03-29 04:41:26 -040014369 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg947add32013-02-22 22:05:20 +010014370 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex))
David S. Miller9360ffd2012-03-29 04:41:26 -040014371 goto nla_put_failure;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020014372
Johannes Berg5b97f492014-11-26 12:37:43 +010014373 if (mac && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac))
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020014374 goto nla_put_failure;
14375
Johannes Berg5b97f492014-11-26 12:37:43 +010014376 cb[1] = nla_nest_start(msg, NL80211_ATTR_CQM);
14377 if (!cb[1])
14378 goto nla_put_failure;
14379
14380 cb[2] = rdev;
14381
14382 return msg;
14383 nla_put_failure:
14384 nlmsg_free(msg);
14385 return NULL;
14386}
14387
14388static void cfg80211_send_cqm(struct sk_buff *msg, gfp_t gfp)
14389{
14390 void **cb = (void **)msg->cb;
14391 struct cfg80211_registered_device *rdev = cb[2];
14392
14393 nla_nest_end(msg, cb[1]);
14394 genlmsg_end(msg, cb[0]);
14395
14396 memset(msg->cb, 0, sizeof(msg->cb));
14397
14398 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
14399 NL80211_MCGRP_MLME, gfp);
14400}
14401
14402void cfg80211_cqm_rssi_notify(struct net_device *dev,
14403 enum nl80211_cqm_rssi_threshold_event rssi_event,
Andrzej Zaborowskibee427b2017-01-25 12:43:41 +010014404 s32 rssi_level, gfp_t gfp)
Johannes Berg5b97f492014-11-26 12:37:43 +010014405{
14406 struct sk_buff *msg;
Andrew Zaborowski4a4b8162017-02-10 10:02:31 +010014407 struct wireless_dev *wdev = dev->ieee80211_ptr;
14408 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Johannes Berg5b97f492014-11-26 12:37:43 +010014409
Andrzej Zaborowskibee427b2017-01-25 12:43:41 +010014410 trace_cfg80211_cqm_rssi_notify(dev, rssi_event, rssi_level);
Johannes Berg5b97f492014-11-26 12:37:43 +010014411
Johannes Berg98f03342014-11-26 12:42:02 +010014412 if (WARN_ON(rssi_event != NL80211_CQM_RSSI_THRESHOLD_EVENT_LOW &&
14413 rssi_event != NL80211_CQM_RSSI_THRESHOLD_EVENT_HIGH))
14414 return;
14415
Andrew Zaborowski4a4b8162017-02-10 10:02:31 +010014416 if (wdev->cqm_config) {
14417 wdev->cqm_config->last_rssi_event_value = rssi_level;
14418
14419 cfg80211_cqm_rssi_update(rdev, dev);
14420
14421 if (rssi_level == 0)
14422 rssi_level = wdev->cqm_config->last_rssi_event_value;
14423 }
14424
Johannes Berg5b97f492014-11-26 12:37:43 +010014425 msg = cfg80211_prepare_cqm(dev, NULL, gfp);
14426 if (!msg)
14427 return;
14428
David S. Miller9360ffd2012-03-29 04:41:26 -040014429 if (nla_put_u32(msg, NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT,
14430 rssi_event))
14431 goto nla_put_failure;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020014432
Andrzej Zaborowskibee427b2017-01-25 12:43:41 +010014433 if (rssi_level && nla_put_s32(msg, NL80211_ATTR_CQM_RSSI_LEVEL,
14434 rssi_level))
14435 goto nla_put_failure;
14436
Johannes Berg5b97f492014-11-26 12:37:43 +010014437 cfg80211_send_cqm(msg, gfp);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020014438
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020014439 return;
14440
14441 nla_put_failure:
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020014442 nlmsg_free(msg);
14443}
Johannes Berg947add32013-02-22 22:05:20 +010014444EXPORT_SYMBOL(cfg80211_cqm_rssi_notify);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020014445
Johannes Berg5b97f492014-11-26 12:37:43 +010014446void cfg80211_cqm_txe_notify(struct net_device *dev,
14447 const u8 *peer, u32 num_packets,
14448 u32 rate, u32 intvl, gfp_t gfp)
14449{
14450 struct sk_buff *msg;
14451
14452 msg = cfg80211_prepare_cqm(dev, peer, gfp);
14453 if (!msg)
14454 return;
14455
14456 if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_PKTS, num_packets))
14457 goto nla_put_failure;
14458
14459 if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_RATE, rate))
14460 goto nla_put_failure;
14461
14462 if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_INTVL, intvl))
14463 goto nla_put_failure;
14464
14465 cfg80211_send_cqm(msg, gfp);
14466 return;
14467
14468 nla_put_failure:
14469 nlmsg_free(msg);
14470}
14471EXPORT_SYMBOL(cfg80211_cqm_txe_notify);
14472
14473void cfg80211_cqm_pktloss_notify(struct net_device *dev,
14474 const u8 *peer, u32 num_packets, gfp_t gfp)
14475{
14476 struct sk_buff *msg;
14477
14478 trace_cfg80211_cqm_pktloss_notify(dev, peer, num_packets);
14479
14480 msg = cfg80211_prepare_cqm(dev, peer, gfp);
14481 if (!msg)
14482 return;
14483
14484 if (nla_put_u32(msg, NL80211_ATTR_CQM_PKT_LOSS_EVENT, num_packets))
14485 goto nla_put_failure;
14486
14487 cfg80211_send_cqm(msg, gfp);
14488 return;
14489
14490 nla_put_failure:
14491 nlmsg_free(msg);
14492}
14493EXPORT_SYMBOL(cfg80211_cqm_pktloss_notify);
14494
Johannes Berg98f03342014-11-26 12:42:02 +010014495void cfg80211_cqm_beacon_loss_notify(struct net_device *dev, gfp_t gfp)
14496{
14497 struct sk_buff *msg;
14498
14499 msg = cfg80211_prepare_cqm(dev, NULL, gfp);
14500 if (!msg)
14501 return;
14502
14503 if (nla_put_flag(msg, NL80211_ATTR_CQM_BEACON_LOSS_EVENT))
14504 goto nla_put_failure;
14505
14506 cfg80211_send_cqm(msg, gfp);
14507 return;
14508
14509 nla_put_failure:
14510 nlmsg_free(msg);
14511}
14512EXPORT_SYMBOL(cfg80211_cqm_beacon_loss_notify);
14513
Johannes Berg947add32013-02-22 22:05:20 +010014514static void nl80211_gtk_rekey_notify(struct cfg80211_registered_device *rdev,
14515 struct net_device *netdev, const u8 *bssid,
14516 const u8 *replay_ctr, gfp_t gfp)
Johannes Berge5497d72011-07-05 16:35:40 +020014517{
14518 struct sk_buff *msg;
14519 struct nlattr *rekey_attr;
14520 void *hdr;
14521
Thomas Graf58050fc2012-06-28 03:57:45 +000014522 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Johannes Berge5497d72011-07-05 16:35:40 +020014523 if (!msg)
14524 return;
14525
14526 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_REKEY_OFFLOAD);
14527 if (!hdr) {
14528 nlmsg_free(msg);
14529 return;
14530 }
14531
David S. Miller9360ffd2012-03-29 04:41:26 -040014532 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
14533 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
14534 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid))
14535 goto nla_put_failure;
Johannes Berge5497d72011-07-05 16:35:40 +020014536
14537 rekey_attr = nla_nest_start(msg, NL80211_ATTR_REKEY_DATA);
14538 if (!rekey_attr)
14539 goto nla_put_failure;
14540
David S. Miller9360ffd2012-03-29 04:41:26 -040014541 if (nla_put(msg, NL80211_REKEY_DATA_REPLAY_CTR,
14542 NL80211_REPLAY_CTR_LEN, replay_ctr))
14543 goto nla_put_failure;
Johannes Berge5497d72011-07-05 16:35:40 +020014544
14545 nla_nest_end(msg, rekey_attr);
14546
Johannes Berg3b7b72e2011-10-22 19:05:51 +020014547 genlmsg_end(msg, hdr);
Johannes Berge5497d72011-07-05 16:35:40 +020014548
Johannes Berg68eb5502013-11-19 15:19:38 +010014549 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010014550 NL80211_MCGRP_MLME, gfp);
Johannes Berge5497d72011-07-05 16:35:40 +020014551 return;
14552
14553 nla_put_failure:
14554 genlmsg_cancel(msg, hdr);
14555 nlmsg_free(msg);
14556}
14557
Johannes Berg947add32013-02-22 22:05:20 +010014558void cfg80211_gtk_rekey_notify(struct net_device *dev, const u8 *bssid,
14559 const u8 *replay_ctr, gfp_t gfp)
14560{
14561 struct wireless_dev *wdev = dev->ieee80211_ptr;
14562 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080014563 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg947add32013-02-22 22:05:20 +010014564
14565 trace_cfg80211_gtk_rekey_notify(dev, bssid);
14566 nl80211_gtk_rekey_notify(rdev, dev, bssid, replay_ctr, gfp);
14567}
14568EXPORT_SYMBOL(cfg80211_gtk_rekey_notify);
14569
14570static void
14571nl80211_pmksa_candidate_notify(struct cfg80211_registered_device *rdev,
14572 struct net_device *netdev, int index,
14573 const u8 *bssid, bool preauth, gfp_t gfp)
Jouni Malinenc9df56b2011-09-16 18:56:23 +030014574{
14575 struct sk_buff *msg;
14576 struct nlattr *attr;
14577 void *hdr;
14578
Thomas Graf58050fc2012-06-28 03:57:45 +000014579 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinenc9df56b2011-09-16 18:56:23 +030014580 if (!msg)
14581 return;
14582
14583 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PMKSA_CANDIDATE);
14584 if (!hdr) {
14585 nlmsg_free(msg);
14586 return;
14587 }
14588
David S. Miller9360ffd2012-03-29 04:41:26 -040014589 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
14590 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex))
14591 goto nla_put_failure;
Jouni Malinenc9df56b2011-09-16 18:56:23 +030014592
14593 attr = nla_nest_start(msg, NL80211_ATTR_PMKSA_CANDIDATE);
14594 if (!attr)
14595 goto nla_put_failure;
14596
David S. Miller9360ffd2012-03-29 04:41:26 -040014597 if (nla_put_u32(msg, NL80211_PMKSA_CANDIDATE_INDEX, index) ||
14598 nla_put(msg, NL80211_PMKSA_CANDIDATE_BSSID, ETH_ALEN, bssid) ||
14599 (preauth &&
14600 nla_put_flag(msg, NL80211_PMKSA_CANDIDATE_PREAUTH)))
14601 goto nla_put_failure;
Jouni Malinenc9df56b2011-09-16 18:56:23 +030014602
14603 nla_nest_end(msg, attr);
14604
Johannes Berg3b7b72e2011-10-22 19:05:51 +020014605 genlmsg_end(msg, hdr);
Jouni Malinenc9df56b2011-09-16 18:56:23 +030014606
Johannes Berg68eb5502013-11-19 15:19:38 +010014607 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010014608 NL80211_MCGRP_MLME, gfp);
Jouni Malinenc9df56b2011-09-16 18:56:23 +030014609 return;
14610
14611 nla_put_failure:
14612 genlmsg_cancel(msg, hdr);
14613 nlmsg_free(msg);
14614}
14615
Johannes Berg947add32013-02-22 22:05:20 +010014616void cfg80211_pmksa_candidate_notify(struct net_device *dev, int index,
14617 const u8 *bssid, bool preauth, gfp_t gfp)
14618{
14619 struct wireless_dev *wdev = dev->ieee80211_ptr;
14620 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080014621 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg947add32013-02-22 22:05:20 +010014622
14623 trace_cfg80211_pmksa_candidate_notify(dev, index, bssid, preauth);
14624 nl80211_pmksa_candidate_notify(rdev, dev, index, bssid, preauth, gfp);
14625}
14626EXPORT_SYMBOL(cfg80211_pmksa_candidate_notify);
14627
14628static void nl80211_ch_switch_notify(struct cfg80211_registered_device *rdev,
14629 struct net_device *netdev,
14630 struct cfg80211_chan_def *chandef,
Luciano Coelhof8d75522014-11-07 14:31:35 +020014631 gfp_t gfp,
14632 enum nl80211_commands notif,
14633 u8 count)
Thomas Pedersen53145262012-04-06 13:35:47 -070014634{
14635 struct sk_buff *msg;
14636 void *hdr;
14637
Thomas Graf58050fc2012-06-28 03:57:45 +000014638 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Thomas Pedersen53145262012-04-06 13:35:47 -070014639 if (!msg)
14640 return;
14641
Luciano Coelhof8d75522014-11-07 14:31:35 +020014642 hdr = nl80211hdr_put(msg, 0, 0, 0, notif);
Thomas Pedersen53145262012-04-06 13:35:47 -070014643 if (!hdr) {
14644 nlmsg_free(msg);
14645 return;
14646 }
14647
Johannes Berg683b6d32012-11-08 21:25:48 +010014648 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex))
14649 goto nla_put_failure;
14650
14651 if (nl80211_send_chandef(msg, chandef))
John W. Linville7eab0f62012-04-12 14:25:14 -040014652 goto nla_put_failure;
Thomas Pedersen53145262012-04-06 13:35:47 -070014653
Luciano Coelhof8d75522014-11-07 14:31:35 +020014654 if ((notif == NL80211_CMD_CH_SWITCH_STARTED_NOTIFY) &&
14655 (nla_put_u32(msg, NL80211_ATTR_CH_SWITCH_COUNT, count)))
14656 goto nla_put_failure;
14657
Thomas Pedersen53145262012-04-06 13:35:47 -070014658 genlmsg_end(msg, hdr);
14659
Johannes Berg68eb5502013-11-19 15:19:38 +010014660 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010014661 NL80211_MCGRP_MLME, gfp);
Thomas Pedersen53145262012-04-06 13:35:47 -070014662 return;
14663
14664 nla_put_failure:
14665 genlmsg_cancel(msg, hdr);
14666 nlmsg_free(msg);
14667}
14668
Johannes Berg947add32013-02-22 22:05:20 +010014669void cfg80211_ch_switch_notify(struct net_device *dev,
14670 struct cfg80211_chan_def *chandef)
Thomas Pedersen84f10702012-07-12 16:17:33 -070014671{
Johannes Berg947add32013-02-22 22:05:20 +010014672 struct wireless_dev *wdev = dev->ieee80211_ptr;
14673 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080014674 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg947add32013-02-22 22:05:20 +010014675
Simon Wunderliche487eae2013-11-21 18:19:51 +010014676 ASSERT_WDEV_LOCK(wdev);
Johannes Berg947add32013-02-22 22:05:20 +010014677
Simon Wunderliche487eae2013-11-21 18:19:51 +010014678 trace_cfg80211_ch_switch_notify(dev, chandef);
Johannes Berg947add32013-02-22 22:05:20 +010014679
Michal Kazior9e0e2962014-01-29 14:22:27 +010014680 wdev->chandef = *chandef;
Janusz Dziedzic96f55f12014-01-24 14:29:21 +010014681 wdev->preset_chandef = *chandef;
Luciano Coelhof8d75522014-11-07 14:31:35 +020014682 nl80211_ch_switch_notify(rdev, dev, chandef, GFP_KERNEL,
14683 NL80211_CMD_CH_SWITCH_NOTIFY, 0);
Johannes Berg947add32013-02-22 22:05:20 +010014684}
14685EXPORT_SYMBOL(cfg80211_ch_switch_notify);
14686
Luciano Coelhof8d75522014-11-07 14:31:35 +020014687void cfg80211_ch_switch_started_notify(struct net_device *dev,
14688 struct cfg80211_chan_def *chandef,
14689 u8 count)
14690{
14691 struct wireless_dev *wdev = dev->ieee80211_ptr;
14692 struct wiphy *wiphy = wdev->wiphy;
14693 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
14694
14695 trace_cfg80211_ch_switch_started_notify(dev, chandef);
14696
14697 nl80211_ch_switch_notify(rdev, dev, chandef, GFP_KERNEL,
14698 NL80211_CMD_CH_SWITCH_STARTED_NOTIFY, count);
14699}
14700EXPORT_SYMBOL(cfg80211_ch_switch_started_notify);
14701
Thomas Pedersen84f10702012-07-12 16:17:33 -070014702void
Simon Wunderlich04f39042013-02-08 18:16:19 +010014703nl80211_radar_notify(struct cfg80211_registered_device *rdev,
Janusz Dziedzicd2859df2013-11-06 13:55:51 +010014704 const struct cfg80211_chan_def *chandef,
Simon Wunderlich04f39042013-02-08 18:16:19 +010014705 enum nl80211_radar_event event,
14706 struct net_device *netdev, gfp_t gfp)
14707{
14708 struct sk_buff *msg;
14709 void *hdr;
14710
14711 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
14712 if (!msg)
14713 return;
14714
14715 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_RADAR_DETECT);
14716 if (!hdr) {
14717 nlmsg_free(msg);
14718 return;
14719 }
14720
14721 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx))
14722 goto nla_put_failure;
14723
14724 /* NOP and radar events don't need a netdev parameter */
14725 if (netdev) {
14726 struct wireless_dev *wdev = netdev->ieee80211_ptr;
14727
14728 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020014729 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
14730 NL80211_ATTR_PAD))
Simon Wunderlich04f39042013-02-08 18:16:19 +010014731 goto nla_put_failure;
14732 }
14733
14734 if (nla_put_u32(msg, NL80211_ATTR_RADAR_EVENT, event))
14735 goto nla_put_failure;
14736
14737 if (nl80211_send_chandef(msg, chandef))
14738 goto nla_put_failure;
14739
Johannes Berg9c90a9f2013-06-04 12:46:03 +020014740 genlmsg_end(msg, hdr);
Simon Wunderlich04f39042013-02-08 18:16:19 +010014741
Johannes Berg68eb5502013-11-19 15:19:38 +010014742 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010014743 NL80211_MCGRP_MLME, gfp);
Simon Wunderlich04f39042013-02-08 18:16:19 +010014744 return;
14745
14746 nla_put_failure:
14747 genlmsg_cancel(msg, hdr);
14748 nlmsg_free(msg);
14749}
14750
Johannes Berg7f6cf312011-11-04 11:18:15 +010014751void cfg80211_probe_status(struct net_device *dev, const u8 *addr,
14752 u64 cookie, bool acked, gfp_t gfp)
14753{
14754 struct wireless_dev *wdev = dev->ieee80211_ptr;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080014755 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Johannes Berg7f6cf312011-11-04 11:18:15 +010014756 struct sk_buff *msg;
14757 void *hdr;
Johannes Berg7f6cf312011-11-04 11:18:15 +010014758
Beni Lev4ee3e062012-08-27 12:49:39 +030014759 trace_cfg80211_probe_status(dev, addr, cookie, acked);
14760
Thomas Graf58050fc2012-06-28 03:57:45 +000014761 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Beni Lev4ee3e062012-08-27 12:49:39 +030014762
Johannes Berg7f6cf312011-11-04 11:18:15 +010014763 if (!msg)
14764 return;
14765
14766 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PROBE_CLIENT);
14767 if (!hdr) {
14768 nlmsg_free(msg);
14769 return;
14770 }
14771
David S. Miller9360ffd2012-03-29 04:41:26 -040014772 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
14773 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
14774 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020014775 nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie,
14776 NL80211_ATTR_PAD) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040014777 (acked && nla_put_flag(msg, NL80211_ATTR_ACK)))
14778 goto nla_put_failure;
Johannes Berg7f6cf312011-11-04 11:18:15 +010014779
Johannes Berg9c90a9f2013-06-04 12:46:03 +020014780 genlmsg_end(msg, hdr);
Johannes Berg7f6cf312011-11-04 11:18:15 +010014781
Johannes Berg68eb5502013-11-19 15:19:38 +010014782 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010014783 NL80211_MCGRP_MLME, gfp);
Johannes Berg7f6cf312011-11-04 11:18:15 +010014784 return;
14785
14786 nla_put_failure:
14787 genlmsg_cancel(msg, hdr);
14788 nlmsg_free(msg);
14789}
14790EXPORT_SYMBOL(cfg80211_probe_status);
14791
Johannes Berg5e760232011-11-04 11:18:17 +010014792void cfg80211_report_obss_beacon(struct wiphy *wiphy,
14793 const u8 *frame, size_t len,
Ben Greear37c73b52012-10-26 14:49:25 -070014794 int freq, int sig_dbm)
Johannes Berg5e760232011-11-04 11:18:17 +010014795{
Zhao, Gangf26cbf42014-04-21 12:53:03 +080014796 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg5e760232011-11-04 11:18:17 +010014797 struct sk_buff *msg;
14798 void *hdr;
Ben Greear37c73b52012-10-26 14:49:25 -070014799 struct cfg80211_beacon_registration *reg;
Johannes Berg5e760232011-11-04 11:18:17 +010014800
Beni Lev4ee3e062012-08-27 12:49:39 +030014801 trace_cfg80211_report_obss_beacon(wiphy, frame, len, freq, sig_dbm);
14802
Ben Greear37c73b52012-10-26 14:49:25 -070014803 spin_lock_bh(&rdev->beacon_registrations_lock);
14804 list_for_each_entry(reg, &rdev->beacon_registrations, list) {
14805 msg = nlmsg_new(len + 100, GFP_ATOMIC);
14806 if (!msg) {
14807 spin_unlock_bh(&rdev->beacon_registrations_lock);
14808 return;
14809 }
Johannes Berg5e760232011-11-04 11:18:17 +010014810
Ben Greear37c73b52012-10-26 14:49:25 -070014811 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME);
14812 if (!hdr)
14813 goto nla_put_failure;
Johannes Berg5e760232011-11-04 11:18:17 +010014814
Ben Greear37c73b52012-10-26 14:49:25 -070014815 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
14816 (freq &&
14817 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq)) ||
14818 (sig_dbm &&
14819 nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) ||
14820 nla_put(msg, NL80211_ATTR_FRAME, len, frame))
14821 goto nla_put_failure;
14822
14823 genlmsg_end(msg, hdr);
14824
14825 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, reg->nlportid);
Johannes Berg5e760232011-11-04 11:18:17 +010014826 }
Ben Greear37c73b52012-10-26 14:49:25 -070014827 spin_unlock_bh(&rdev->beacon_registrations_lock);
Johannes Berg5e760232011-11-04 11:18:17 +010014828 return;
14829
14830 nla_put_failure:
Ben Greear37c73b52012-10-26 14:49:25 -070014831 spin_unlock_bh(&rdev->beacon_registrations_lock);
14832 if (hdr)
14833 genlmsg_cancel(msg, hdr);
Johannes Berg5e760232011-11-04 11:18:17 +010014834 nlmsg_free(msg);
14835}
14836EXPORT_SYMBOL(cfg80211_report_obss_beacon);
14837
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010014838#ifdef CONFIG_PM
Luciano Coelho8cd4d452014-09-17 11:55:28 +030014839static int cfg80211_net_detect_results(struct sk_buff *msg,
14840 struct cfg80211_wowlan_wakeup *wakeup)
14841{
14842 struct cfg80211_wowlan_nd_info *nd = wakeup->net_detect;
14843 struct nlattr *nl_results, *nl_match, *nl_freqs;
14844 int i, j;
14845
14846 nl_results = nla_nest_start(
14847 msg, NL80211_WOWLAN_TRIG_NET_DETECT_RESULTS);
14848 if (!nl_results)
14849 return -EMSGSIZE;
14850
14851 for (i = 0; i < nd->n_matches; i++) {
14852 struct cfg80211_wowlan_nd_match *match = nd->matches[i];
14853
14854 nl_match = nla_nest_start(msg, i);
14855 if (!nl_match)
14856 break;
14857
14858 /* The SSID attribute is optional in nl80211, but for
14859 * simplicity reasons it's always present in the
14860 * cfg80211 structure. If a driver can't pass the
14861 * SSID, that needs to be changed. A zero length SSID
14862 * is still a valid SSID (wildcard), so it cannot be
14863 * used for this purpose.
14864 */
14865 if (nla_put(msg, NL80211_ATTR_SSID, match->ssid.ssid_len,
14866 match->ssid.ssid)) {
14867 nla_nest_cancel(msg, nl_match);
14868 goto out;
14869 }
14870
14871 if (match->n_channels) {
14872 nl_freqs = nla_nest_start(
14873 msg, NL80211_ATTR_SCAN_FREQUENCIES);
14874 if (!nl_freqs) {
14875 nla_nest_cancel(msg, nl_match);
14876 goto out;
14877 }
14878
14879 for (j = 0; j < match->n_channels; j++) {
Samuel Tan5528fae82015-02-09 21:29:15 +020014880 if (nla_put_u32(msg, j, match->channels[j])) {
Luciano Coelho8cd4d452014-09-17 11:55:28 +030014881 nla_nest_cancel(msg, nl_freqs);
14882 nla_nest_cancel(msg, nl_match);
14883 goto out;
14884 }
14885 }
14886
14887 nla_nest_end(msg, nl_freqs);
14888 }
14889
14890 nla_nest_end(msg, nl_match);
14891 }
14892
14893out:
14894 nla_nest_end(msg, nl_results);
14895 return 0;
14896}
14897
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010014898void cfg80211_report_wowlan_wakeup(struct wireless_dev *wdev,
14899 struct cfg80211_wowlan_wakeup *wakeup,
14900 gfp_t gfp)
14901{
Zhao, Gangf26cbf42014-04-21 12:53:03 +080014902 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010014903 struct sk_buff *msg;
14904 void *hdr;
Johannes Berg9c90a9f2013-06-04 12:46:03 +020014905 int size = 200;
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010014906
14907 trace_cfg80211_report_wowlan_wakeup(wdev->wiphy, wdev, wakeup);
14908
14909 if (wakeup)
14910 size += wakeup->packet_present_len;
14911
14912 msg = nlmsg_new(size, gfp);
14913 if (!msg)
14914 return;
14915
14916 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_WOWLAN);
14917 if (!hdr)
14918 goto free_msg;
14919
14920 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020014921 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
14922 NL80211_ATTR_PAD))
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010014923 goto free_msg;
14924
14925 if (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
14926 wdev->netdev->ifindex))
14927 goto free_msg;
14928
14929 if (wakeup) {
14930 struct nlattr *reasons;
14931
14932 reasons = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS);
Johannes Berg7fa322c2013-10-25 11:16:58 +020014933 if (!reasons)
14934 goto free_msg;
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010014935
14936 if (wakeup->disconnect &&
14937 nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT))
14938 goto free_msg;
14939 if (wakeup->magic_pkt &&
14940 nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT))
14941 goto free_msg;
14942 if (wakeup->gtk_rekey_failure &&
14943 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE))
14944 goto free_msg;
14945 if (wakeup->eap_identity_req &&
14946 nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST))
14947 goto free_msg;
14948 if (wakeup->four_way_handshake &&
14949 nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE))
14950 goto free_msg;
14951 if (wakeup->rfkill_release &&
14952 nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE))
14953 goto free_msg;
14954
14955 if (wakeup->pattern_idx >= 0 &&
14956 nla_put_u32(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN,
14957 wakeup->pattern_idx))
14958 goto free_msg;
14959
Johannes Bergae917c92013-10-25 11:05:22 +020014960 if (wakeup->tcp_match &&
14961 nla_put_flag(msg, NL80211_WOWLAN_TRIG_WAKEUP_TCP_MATCH))
14962 goto free_msg;
Johannes Berg2a0e0472013-01-23 22:57:40 +010014963
Johannes Bergae917c92013-10-25 11:05:22 +020014964 if (wakeup->tcp_connlost &&
14965 nla_put_flag(msg, NL80211_WOWLAN_TRIG_WAKEUP_TCP_CONNLOST))
14966 goto free_msg;
Johannes Berg2a0e0472013-01-23 22:57:40 +010014967
Johannes Bergae917c92013-10-25 11:05:22 +020014968 if (wakeup->tcp_nomoretokens &&
14969 nla_put_flag(msg,
14970 NL80211_WOWLAN_TRIG_WAKEUP_TCP_NOMORETOKENS))
14971 goto free_msg;
Johannes Berg2a0e0472013-01-23 22:57:40 +010014972
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010014973 if (wakeup->packet) {
14974 u32 pkt_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211;
14975 u32 len_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211_LEN;
14976
14977 if (!wakeup->packet_80211) {
14978 pkt_attr =
14979 NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023;
14980 len_attr =
14981 NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023_LEN;
14982 }
14983
14984 if (wakeup->packet_len &&
14985 nla_put_u32(msg, len_attr, wakeup->packet_len))
14986 goto free_msg;
14987
14988 if (nla_put(msg, pkt_attr, wakeup->packet_present_len,
14989 wakeup->packet))
14990 goto free_msg;
14991 }
14992
Luciano Coelho8cd4d452014-09-17 11:55:28 +030014993 if (wakeup->net_detect &&
14994 cfg80211_net_detect_results(msg, wakeup))
14995 goto free_msg;
14996
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010014997 nla_nest_end(msg, reasons);
14998 }
14999
Johannes Berg9c90a9f2013-06-04 12:46:03 +020015000 genlmsg_end(msg, hdr);
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010015001
Johannes Berg68eb5502013-11-19 15:19:38 +010015002 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010015003 NL80211_MCGRP_MLME, gfp);
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010015004 return;
15005
15006 free_msg:
15007 nlmsg_free(msg);
15008}
15009EXPORT_SYMBOL(cfg80211_report_wowlan_wakeup);
15010#endif
15011
Jouni Malinen3475b092012-11-16 22:49:57 +020015012void cfg80211_tdls_oper_request(struct net_device *dev, const u8 *peer,
15013 enum nl80211_tdls_operation oper,
15014 u16 reason_code, gfp_t gfp)
15015{
15016 struct wireless_dev *wdev = dev->ieee80211_ptr;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080015017 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Jouni Malinen3475b092012-11-16 22:49:57 +020015018 struct sk_buff *msg;
15019 void *hdr;
Jouni Malinen3475b092012-11-16 22:49:57 +020015020
15021 trace_cfg80211_tdls_oper_request(wdev->wiphy, dev, peer, oper,
15022 reason_code);
15023
15024 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
15025 if (!msg)
15026 return;
15027
15028 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_TDLS_OPER);
15029 if (!hdr) {
15030 nlmsg_free(msg);
15031 return;
15032 }
15033
15034 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
15035 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
15036 nla_put_u8(msg, NL80211_ATTR_TDLS_OPERATION, oper) ||
15037 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer) ||
15038 (reason_code > 0 &&
15039 nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason_code)))
15040 goto nla_put_failure;
15041
Johannes Berg9c90a9f2013-06-04 12:46:03 +020015042 genlmsg_end(msg, hdr);
Jouni Malinen3475b092012-11-16 22:49:57 +020015043
Johannes Berg68eb5502013-11-19 15:19:38 +010015044 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010015045 NL80211_MCGRP_MLME, gfp);
Jouni Malinen3475b092012-11-16 22:49:57 +020015046 return;
15047
15048 nla_put_failure:
15049 genlmsg_cancel(msg, hdr);
15050 nlmsg_free(msg);
15051}
15052EXPORT_SYMBOL(cfg80211_tdls_oper_request);
15053
Jouni Malinen026331c2010-02-15 12:53:10 +020015054static int nl80211_netlink_notify(struct notifier_block * nb,
15055 unsigned long state,
15056 void *_notify)
15057{
15058 struct netlink_notify *notify = _notify;
15059 struct cfg80211_registered_device *rdev;
15060 struct wireless_dev *wdev;
Ben Greear37c73b52012-10-26 14:49:25 -070015061 struct cfg80211_beacon_registration *reg, *tmp;
Jouni Malinen026331c2010-02-15 12:53:10 +020015062
Dmitry Ivanov8f815cd2016-04-06 17:23:18 +030015063 if (state != NETLINK_URELEASE || notify->protocol != NETLINK_GENERIC)
Jouni Malinen026331c2010-02-15 12:53:10 +020015064 return NOTIFY_DONE;
15065
15066 rcu_read_lock();
15067
Johannes Berg5e760232011-11-04 11:18:17 +010015068 list_for_each_entry_rcu(rdev, &cfg80211_rdev_list, list) {
Arend Van Sprielca986ad2017-04-21 13:05:00 +010015069 struct cfg80211_sched_scan_request *sched_scan_req;
Jukka Rissanen93a1e862014-12-15 13:25:39 +020015070
Arend Van Sprielca986ad2017-04-21 13:05:00 +010015071 list_for_each_entry_rcu(sched_scan_req,
15072 &rdev->sched_scan_req_list,
15073 list) {
15074 if (sched_scan_req->owner_nlportid == notify->portid) {
15075 sched_scan_req->nl_owner_dead = true;
Johannes Berg753aacf2017-01-05 10:57:14 +010015076 schedule_work(&rdev->sched_scan_stop_wk);
Arend Van Sprielca986ad2017-04-21 13:05:00 +010015077 }
Johannes Berg753aacf2017-01-05 10:57:14 +010015078 }
Johannes Berg78f22b62014-03-24 17:57:27 +010015079
Johannes Berg53873f12016-05-03 16:52:04 +030015080 list_for_each_entry_rcu(wdev, &rdev->wiphy.wdev_list, list) {
Eric W. Biederman15e47302012-09-07 20:12:54 +000015081 cfg80211_mlme_unregister_socket(wdev, notify->portid);
Ben Greear37c73b52012-10-26 14:49:25 -070015082
Johannes Bergab810072017-04-26 07:43:41 +020015083 if (wdev->owner_nlportid == notify->portid) {
15084 wdev->nl_owner_dead = true;
15085 schedule_work(&rdev->destroy_work);
15086 } else if (wdev->conn_owner_nlportid == notify->portid) {
Andrzej Zaborowskibd2522b2017-01-06 16:33:43 -050015087 schedule_work(&wdev->disconnect_wk);
Johannes Bergab810072017-04-26 07:43:41 +020015088 }
Johannes Berg78f22b62014-03-24 17:57:27 +010015089 }
15090
Ben Greear37c73b52012-10-26 14:49:25 -070015091 spin_lock_bh(&rdev->beacon_registrations_lock);
15092 list_for_each_entry_safe(reg, tmp, &rdev->beacon_registrations,
15093 list) {
15094 if (reg->nlportid == notify->portid) {
15095 list_del(&reg->list);
15096 kfree(reg);
15097 break;
15098 }
15099 }
15100 spin_unlock_bh(&rdev->beacon_registrations_lock);
Johannes Berg5e760232011-11-04 11:18:17 +010015101 }
Jouni Malinen026331c2010-02-15 12:53:10 +020015102
15103 rcu_read_unlock();
15104
Ilan peer05050752015-03-04 00:32:06 -050015105 /*
15106 * It is possible that the user space process that is controlling the
15107 * indoor setting disappeared, so notify the regulatory core.
15108 */
15109 regulatory_netlink_notify(notify->portid);
Zhao, Gang6784c7d2014-04-21 12:53:04 +080015110 return NOTIFY_OK;
Jouni Malinen026331c2010-02-15 12:53:10 +020015111}
15112
15113static struct notifier_block nl80211_netlink_notifier = {
15114 .notifier_call = nl80211_netlink_notify,
15115};
15116
Jouni Malinen355199e2013-02-27 17:14:27 +020015117void cfg80211_ft_event(struct net_device *netdev,
15118 struct cfg80211_ft_event_params *ft_event)
15119{
15120 struct wiphy *wiphy = netdev->ieee80211_ptr->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080015121 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Jouni Malinen355199e2013-02-27 17:14:27 +020015122 struct sk_buff *msg;
15123 void *hdr;
Jouni Malinen355199e2013-02-27 17:14:27 +020015124
15125 trace_cfg80211_ft_event(wiphy, netdev, ft_event);
15126
15127 if (!ft_event->target_ap)
15128 return;
15129
Johannes Berg4ef8c1c2017-01-09 11:10:42 +010015130 msg = nlmsg_new(100 + ft_event->ric_ies_len, GFP_KERNEL);
Jouni Malinen355199e2013-02-27 17:14:27 +020015131 if (!msg)
15132 return;
15133
15134 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FT_EVENT);
Johannes Bergae917c92013-10-25 11:05:22 +020015135 if (!hdr)
15136 goto out;
Jouni Malinen355199e2013-02-27 17:14:27 +020015137
Johannes Bergae917c92013-10-25 11:05:22 +020015138 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
15139 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
15140 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, ft_event->target_ap))
15141 goto out;
15142
15143 if (ft_event->ies &&
15144 nla_put(msg, NL80211_ATTR_IE, ft_event->ies_len, ft_event->ies))
15145 goto out;
15146 if (ft_event->ric_ies &&
15147 nla_put(msg, NL80211_ATTR_IE_RIC, ft_event->ric_ies_len,
15148 ft_event->ric_ies))
15149 goto out;
Jouni Malinen355199e2013-02-27 17:14:27 +020015150
Johannes Berg9c90a9f2013-06-04 12:46:03 +020015151 genlmsg_end(msg, hdr);
Jouni Malinen355199e2013-02-27 17:14:27 +020015152
Johannes Berg68eb5502013-11-19 15:19:38 +010015153 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010015154 NL80211_MCGRP_MLME, GFP_KERNEL);
Johannes Bergae917c92013-10-25 11:05:22 +020015155 return;
15156 out:
15157 nlmsg_free(msg);
Jouni Malinen355199e2013-02-27 17:14:27 +020015158}
15159EXPORT_SYMBOL(cfg80211_ft_event);
15160
Arend van Spriel5de17982013-04-18 15:49:00 +020015161void cfg80211_crit_proto_stopped(struct wireless_dev *wdev, gfp_t gfp)
15162{
15163 struct cfg80211_registered_device *rdev;
15164 struct sk_buff *msg;
15165 void *hdr;
15166 u32 nlportid;
15167
Zhao, Gangf26cbf42014-04-21 12:53:03 +080015168 rdev = wiphy_to_rdev(wdev->wiphy);
Arend van Spriel5de17982013-04-18 15:49:00 +020015169 if (!rdev->crit_proto_nlportid)
15170 return;
15171
15172 nlportid = rdev->crit_proto_nlportid;
15173 rdev->crit_proto_nlportid = 0;
15174
15175 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
15176 if (!msg)
15177 return;
15178
15179 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CRIT_PROTOCOL_STOP);
15180 if (!hdr)
15181 goto nla_put_failure;
15182
15183 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020015184 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
15185 NL80211_ATTR_PAD))
Arend van Spriel5de17982013-04-18 15:49:00 +020015186 goto nla_put_failure;
15187
15188 genlmsg_end(msg, hdr);
15189
15190 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid);
15191 return;
15192
15193 nla_put_failure:
15194 if (hdr)
15195 genlmsg_cancel(msg, hdr);
15196 nlmsg_free(msg);
Arend van Spriel5de17982013-04-18 15:49:00 +020015197}
15198EXPORT_SYMBOL(cfg80211_crit_proto_stopped);
15199
Johannes Berg348baf02014-01-24 14:06:29 +010015200void nl80211_send_ap_stopped(struct wireless_dev *wdev)
15201{
15202 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080015203 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg348baf02014-01-24 14:06:29 +010015204 struct sk_buff *msg;
15205 void *hdr;
15206
15207 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
15208 if (!msg)
15209 return;
15210
15211 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_STOP_AP);
15212 if (!hdr)
15213 goto out;
15214
15215 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
15216 nla_put_u32(msg, NL80211_ATTR_IFINDEX, wdev->netdev->ifindex) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020015217 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
15218 NL80211_ATTR_PAD))
Johannes Berg348baf02014-01-24 14:06:29 +010015219 goto out;
15220
15221 genlmsg_end(msg, hdr);
15222
15223 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(wiphy), msg, 0,
15224 NL80211_MCGRP_MLME, GFP_KERNEL);
15225 return;
15226 out:
15227 nlmsg_free(msg);
15228}
15229
Johannes Berg55682962007-09-20 13:09:35 -040015230/* initialisation/exit functions */
15231
Johannes Berg56989f62016-10-24 14:40:05 +020015232int __init nl80211_init(void)
Johannes Berg55682962007-09-20 13:09:35 -040015233{
Michał Mirosław0d63cbb2009-05-21 10:34:06 +000015234 int err;
Johannes Berg55682962007-09-20 13:09:35 -040015235
Johannes Berg489111e2016-10-24 14:40:03 +020015236 err = genl_register_family(&nl80211_fam);
Johannes Berg55682962007-09-20 13:09:35 -040015237 if (err)
15238 return err;
15239
Jouni Malinen026331c2010-02-15 12:53:10 +020015240 err = netlink_register_notifier(&nl80211_netlink_notifier);
15241 if (err)
15242 goto err_out;
15243
Johannes Berg55682962007-09-20 13:09:35 -040015244 return 0;
15245 err_out:
15246 genl_unregister_family(&nl80211_fam);
15247 return err;
15248}
15249
15250void nl80211_exit(void)
15251{
Jouni Malinen026331c2010-02-15 12:53:10 +020015252 netlink_unregister_notifier(&nl80211_netlink_notifier);
Johannes Berg55682962007-09-20 13:09:35 -040015253 genl_unregister_family(&nl80211_fam);
15254}