blob: 90e212db68893f6172ee604d8f4dfa277f6b57a8 [file] [log] [blame]
Johannes Berg55682962007-09-20 13:09:35 -04001/*
2 * This is the new netlink-based wireless configuration interface.
3 *
Jouni Malinen026331c2010-02-15 12:53:10 +02004 * Copyright 2006-2010 Johannes Berg <johannes@sipsolutions.net>
Johannes Berg2740f0c2014-09-03 15:24:58 +03005 * Copyright 2013-2014 Intel Mobile Communications GmbH
Johannes Berg66cd7942017-02-07 22:40:44 +02006 * Copyright 2015-2017 Intel Deutschland GmbH
Johannes Berg55682962007-09-20 13:09:35 -04007 */
8
9#include <linux/if.h>
10#include <linux/module.h>
11#include <linux/err.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090012#include <linux/slab.h>
Johannes Berg55682962007-09-20 13:09:35 -040013#include <linux/list.h>
14#include <linux/if_ether.h>
15#include <linux/ieee80211.h>
16#include <linux/nl80211.h>
17#include <linux/rtnetlink.h>
18#include <linux/netlink.h>
Johannes Berg2a519312009-02-10 21:25:55 +010019#include <linux/etherdevice.h>
Johannes Berg463d0182009-07-14 00:33:35 +020020#include <net/net_namespace.h>
Johannes Berg55682962007-09-20 13:09:35 -040021#include <net/genetlink.h>
22#include <net/cfg80211.h>
Johannes Berg463d0182009-07-14 00:33:35 +020023#include <net/sock.h>
Johannes Berg2a0e0472013-01-23 22:57:40 +010024#include <net/inet_connection_sock.h>
Johannes Berg55682962007-09-20 13:09:35 -040025#include "core.h"
26#include "nl80211.h"
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -070027#include "reg.h"
Hila Gonene35e4d22012-06-27 17:19:42 +030028#include "rdev-ops.h"
Johannes Berg55682962007-09-20 13:09:35 -040029
Jouni Malinen5fb628e2011-08-10 23:54:35 +030030static int nl80211_crypto_settings(struct cfg80211_registered_device *rdev,
31 struct genl_info *info,
32 struct cfg80211_crypto_settings *settings,
33 int cipher_limit);
34
Johannes Berg55682962007-09-20 13:09:35 -040035/* the netlink family */
Johannes Berg489111e2016-10-24 14:40:03 +020036static struct genl_family nl80211_fam;
Johannes Berg55682962007-09-20 13:09:35 -040037
Johannes Berg2a94fe42013-11-19 15:19:39 +010038/* multicast groups */
39enum nl80211_multicast_groups {
40 NL80211_MCGRP_CONFIG,
41 NL80211_MCGRP_SCAN,
42 NL80211_MCGRP_REGULATORY,
43 NL80211_MCGRP_MLME,
Johannes Berg567ffc32013-12-18 14:43:31 +010044 NL80211_MCGRP_VENDOR,
Ayala Beker50bcd312016-09-20 17:31:17 +030045 NL80211_MCGRP_NAN,
Johannes Berg2a94fe42013-11-19 15:19:39 +010046 NL80211_MCGRP_TESTMODE /* keep last - ifdef! */
47};
48
49static const struct genl_multicast_group nl80211_mcgrps[] = {
Johannes Berg71b836e2014-12-23 17:17:38 +010050 [NL80211_MCGRP_CONFIG] = { .name = NL80211_MULTICAST_GROUP_CONFIG },
51 [NL80211_MCGRP_SCAN] = { .name = NL80211_MULTICAST_GROUP_SCAN },
52 [NL80211_MCGRP_REGULATORY] = { .name = NL80211_MULTICAST_GROUP_REG },
53 [NL80211_MCGRP_MLME] = { .name = NL80211_MULTICAST_GROUP_MLME },
54 [NL80211_MCGRP_VENDOR] = { .name = NL80211_MULTICAST_GROUP_VENDOR },
Ayala Beker50bcd312016-09-20 17:31:17 +030055 [NL80211_MCGRP_NAN] = { .name = NL80211_MULTICAST_GROUP_NAN },
Johannes Berg2a94fe42013-11-19 15:19:39 +010056#ifdef CONFIG_NL80211_TESTMODE
Johannes Berg71b836e2014-12-23 17:17:38 +010057 [NL80211_MCGRP_TESTMODE] = { .name = NL80211_MULTICAST_GROUP_TESTMODE }
Johannes Berg2a94fe42013-11-19 15:19:39 +010058#endif
59};
60
Johannes Berg89a54e42012-06-15 14:33:17 +020061/* returns ERR_PTR values */
62static struct wireless_dev *
63__cfg80211_wdev_from_attrs(struct net *netns, struct nlattr **attrs)
Johannes Berg55682962007-09-20 13:09:35 -040064{
Johannes Berg89a54e42012-06-15 14:33:17 +020065 struct cfg80211_registered_device *rdev;
66 struct wireless_dev *result = NULL;
67 bool have_ifidx = attrs[NL80211_ATTR_IFINDEX];
68 bool have_wdev_id = attrs[NL80211_ATTR_WDEV];
69 u64 wdev_id;
70 int wiphy_idx = -1;
71 int ifidx = -1;
Johannes Berg55682962007-09-20 13:09:35 -040072
Johannes Berg5fe231e2013-05-08 21:45:15 +020073 ASSERT_RTNL();
Johannes Berg55682962007-09-20 13:09:35 -040074
Johannes Berg89a54e42012-06-15 14:33:17 +020075 if (!have_ifidx && !have_wdev_id)
76 return ERR_PTR(-EINVAL);
Johannes Berg55682962007-09-20 13:09:35 -040077
Johannes Berg89a54e42012-06-15 14:33:17 +020078 if (have_ifidx)
79 ifidx = nla_get_u32(attrs[NL80211_ATTR_IFINDEX]);
80 if (have_wdev_id) {
81 wdev_id = nla_get_u64(attrs[NL80211_ATTR_WDEV]);
82 wiphy_idx = wdev_id >> 32;
Johannes Berg55682962007-09-20 13:09:35 -040083 }
84
Johannes Berg89a54e42012-06-15 14:33:17 +020085 list_for_each_entry(rdev, &cfg80211_rdev_list, list) {
86 struct wireless_dev *wdev;
87
88 if (wiphy_net(&rdev->wiphy) != netns)
89 continue;
90
91 if (have_wdev_id && rdev->wiphy_idx != wiphy_idx)
92 continue;
93
Johannes Berg53873f12016-05-03 16:52:04 +030094 list_for_each_entry(wdev, &rdev->wiphy.wdev_list, list) {
Johannes Berg89a54e42012-06-15 14:33:17 +020095 if (have_ifidx && wdev->netdev &&
96 wdev->netdev->ifindex == ifidx) {
97 result = wdev;
98 break;
99 }
100 if (have_wdev_id && wdev->identifier == (u32)wdev_id) {
101 result = wdev;
102 break;
103 }
104 }
Johannes Berg89a54e42012-06-15 14:33:17 +0200105
106 if (result)
107 break;
108 }
109
110 if (result)
111 return result;
112 return ERR_PTR(-ENODEV);
Johannes Berg55682962007-09-20 13:09:35 -0400113}
114
Johannes Berga9455402012-06-15 13:32:49 +0200115static struct cfg80211_registered_device *
Johannes Berg878d9ec2012-06-15 14:18:32 +0200116__cfg80211_rdev_from_attrs(struct net *netns, struct nlattr **attrs)
Johannes Berga9455402012-06-15 13:32:49 +0200117{
Johannes Berg7fee4772012-06-15 14:09:58 +0200118 struct cfg80211_registered_device *rdev = NULL, *tmp;
119 struct net_device *netdev;
Johannes Berga9455402012-06-15 13:32:49 +0200120
Johannes Berg5fe231e2013-05-08 21:45:15 +0200121 ASSERT_RTNL();
Johannes Berga9455402012-06-15 13:32:49 +0200122
Johannes Berg878d9ec2012-06-15 14:18:32 +0200123 if (!attrs[NL80211_ATTR_WIPHY] &&
Johannes Berg89a54e42012-06-15 14:33:17 +0200124 !attrs[NL80211_ATTR_IFINDEX] &&
125 !attrs[NL80211_ATTR_WDEV])
Johannes Berg7fee4772012-06-15 14:09:58 +0200126 return ERR_PTR(-EINVAL);
127
Johannes Berg878d9ec2012-06-15 14:18:32 +0200128 if (attrs[NL80211_ATTR_WIPHY])
Johannes Berg7fee4772012-06-15 14:09:58 +0200129 rdev = cfg80211_rdev_by_wiphy_idx(
Johannes Berg878d9ec2012-06-15 14:18:32 +0200130 nla_get_u32(attrs[NL80211_ATTR_WIPHY]));
Johannes Berga9455402012-06-15 13:32:49 +0200131
Johannes Berg89a54e42012-06-15 14:33:17 +0200132 if (attrs[NL80211_ATTR_WDEV]) {
133 u64 wdev_id = nla_get_u64(attrs[NL80211_ATTR_WDEV]);
134 struct wireless_dev *wdev;
135 bool found = false;
136
137 tmp = cfg80211_rdev_by_wiphy_idx(wdev_id >> 32);
138 if (tmp) {
139 /* make sure wdev exists */
Johannes Berg53873f12016-05-03 16:52:04 +0300140 list_for_each_entry(wdev, &tmp->wiphy.wdev_list, list) {
Johannes Berg89a54e42012-06-15 14:33:17 +0200141 if (wdev->identifier != (u32)wdev_id)
142 continue;
143 found = true;
144 break;
145 }
Johannes Berg89a54e42012-06-15 14:33:17 +0200146
147 if (!found)
148 tmp = NULL;
149
150 if (rdev && tmp != rdev)
151 return ERR_PTR(-EINVAL);
152 rdev = tmp;
153 }
154 }
155
Johannes Berg878d9ec2012-06-15 14:18:32 +0200156 if (attrs[NL80211_ATTR_IFINDEX]) {
157 int ifindex = nla_get_u32(attrs[NL80211_ATTR_IFINDEX]);
Kirtika Ruchandani7a087e72016-05-29 19:51:23 -0700158
Ying Xue7f2b8562014-01-15 10:23:45 +0800159 netdev = __dev_get_by_index(netns, ifindex);
Johannes Berg7fee4772012-06-15 14:09:58 +0200160 if (netdev) {
161 if (netdev->ieee80211_ptr)
Zhao, Gangf26cbf42014-04-21 12:53:03 +0800162 tmp = wiphy_to_rdev(
163 netdev->ieee80211_ptr->wiphy);
Johannes Berg7fee4772012-06-15 14:09:58 +0200164 else
165 tmp = NULL;
166
Johannes Berg7fee4772012-06-15 14:09:58 +0200167 /* not wireless device -- return error */
168 if (!tmp)
169 return ERR_PTR(-EINVAL);
170
171 /* mismatch -- return error */
172 if (rdev && tmp != rdev)
173 return ERR_PTR(-EINVAL);
174
175 rdev = tmp;
Johannes Berga9455402012-06-15 13:32:49 +0200176 }
Johannes Berga9455402012-06-15 13:32:49 +0200177 }
178
Johannes Berg4f7eff12012-06-15 14:14:22 +0200179 if (!rdev)
180 return ERR_PTR(-ENODEV);
Johannes Berga9455402012-06-15 13:32:49 +0200181
Johannes Berg4f7eff12012-06-15 14:14:22 +0200182 if (netns != wiphy_net(&rdev->wiphy))
183 return ERR_PTR(-ENODEV);
184
185 return rdev;
Johannes Berga9455402012-06-15 13:32:49 +0200186}
187
188/*
189 * This function returns a pointer to the driver
190 * that the genl_info item that is passed refers to.
Johannes Berga9455402012-06-15 13:32:49 +0200191 *
192 * The result of this can be a PTR_ERR and hence must
193 * be checked with IS_ERR() for errors.
194 */
195static struct cfg80211_registered_device *
Johannes Berg4f7eff12012-06-15 14:14:22 +0200196cfg80211_get_dev_from_info(struct net *netns, struct genl_info *info)
Johannes Berga9455402012-06-15 13:32:49 +0200197{
Johannes Berg5fe231e2013-05-08 21:45:15 +0200198 return __cfg80211_rdev_from_attrs(netns, info->attrs);
Johannes Berga9455402012-06-15 13:32:49 +0200199}
200
Johannes Berg55682962007-09-20 13:09:35 -0400201/* policy for the attributes */
Luciano Coelho8cd4d452014-09-17 11:55:28 +0300202static const struct nla_policy nl80211_policy[NUM_NL80211_ATTR] = {
Johannes Berg55682962007-09-20 13:09:35 -0400203 [NL80211_ATTR_WIPHY] = { .type = NLA_U32 },
204 [NL80211_ATTR_WIPHY_NAME] = { .type = NLA_NUL_STRING,
David S. Miller079e24e2009-05-26 21:15:00 -0700205 .len = 20-1 },
Jouni Malinen31888482008-10-30 16:59:24 +0200206 [NL80211_ATTR_WIPHY_TXQ_PARAMS] = { .type = NLA_NESTED },
Johannes Berg3d9d1d62012-11-08 23:14:50 +0100207
Jouni Malinen72bdcf32008-11-26 16:15:24 +0200208 [NL80211_ATTR_WIPHY_FREQ] = { .type = NLA_U32 },
Sujith094d05d2008-12-12 11:57:43 +0530209 [NL80211_ATTR_WIPHY_CHANNEL_TYPE] = { .type = NLA_U32 },
Johannes Berg3d9d1d62012-11-08 23:14:50 +0100210 [NL80211_ATTR_CHANNEL_WIDTH] = { .type = NLA_U32 },
211 [NL80211_ATTR_CENTER_FREQ1] = { .type = NLA_U32 },
212 [NL80211_ATTR_CENTER_FREQ2] = { .type = NLA_U32 },
213
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +0200214 [NL80211_ATTR_WIPHY_RETRY_SHORT] = { .type = NLA_U8 },
215 [NL80211_ATTR_WIPHY_RETRY_LONG] = { .type = NLA_U8 },
216 [NL80211_ATTR_WIPHY_FRAG_THRESHOLD] = { .type = NLA_U32 },
217 [NL80211_ATTR_WIPHY_RTS_THRESHOLD] = { .type = NLA_U32 },
Lukáš Turek81077e82009-12-21 22:50:47 +0100218 [NL80211_ATTR_WIPHY_COVERAGE_CLASS] = { .type = NLA_U8 },
Lorenzo Bianconi3057dbf2014-09-04 23:57:40 +0200219 [NL80211_ATTR_WIPHY_DYN_ACK] = { .type = NLA_FLAG },
Johannes Berg55682962007-09-20 13:09:35 -0400220
221 [NL80211_ATTR_IFTYPE] = { .type = NLA_U32 },
222 [NL80211_ATTR_IFINDEX] = { .type = NLA_U32 },
223 [NL80211_ATTR_IFNAME] = { .type = NLA_NUL_STRING, .len = IFNAMSIZ-1 },
Johannes Berg41ade002007-12-19 02:03:29 +0100224
Eliad Pellere007b852011-11-24 18:13:56 +0200225 [NL80211_ATTR_MAC] = { .len = ETH_ALEN },
226 [NL80211_ATTR_PREV_BSSID] = { .len = ETH_ALEN },
Johannes Berg41ade002007-12-19 02:03:29 +0100227
Johannes Bergb9454e82009-07-08 13:29:08 +0200228 [NL80211_ATTR_KEY] = { .type = NLA_NESTED, },
Johannes Berg41ade002007-12-19 02:03:29 +0100229 [NL80211_ATTR_KEY_DATA] = { .type = NLA_BINARY,
230 .len = WLAN_MAX_KEY_LEN },
231 [NL80211_ATTR_KEY_IDX] = { .type = NLA_U8 },
232 [NL80211_ATTR_KEY_CIPHER] = { .type = NLA_U32 },
233 [NL80211_ATTR_KEY_DEFAULT] = { .type = NLA_FLAG },
Jouni Malinen81962262011-11-02 23:36:31 +0200234 [NL80211_ATTR_KEY_SEQ] = { .type = NLA_BINARY, .len = 16 },
Johannes Berge31b8212010-10-05 19:39:30 +0200235 [NL80211_ATTR_KEY_TYPE] = { .type = NLA_U32 },
Johannes Berged1b6cc2007-12-19 02:03:32 +0100236
237 [NL80211_ATTR_BEACON_INTERVAL] = { .type = NLA_U32 },
238 [NL80211_ATTR_DTIM_PERIOD] = { .type = NLA_U32 },
239 [NL80211_ATTR_BEACON_HEAD] = { .type = NLA_BINARY,
240 .len = IEEE80211_MAX_DATA_LEN },
241 [NL80211_ATTR_BEACON_TAIL] = { .type = NLA_BINARY,
242 .len = IEEE80211_MAX_DATA_LEN },
Johannes Berg5727ef12007-12-19 02:03:34 +0100243 [NL80211_ATTR_STA_AID] = { .type = NLA_U16 },
244 [NL80211_ATTR_STA_FLAGS] = { .type = NLA_NESTED },
245 [NL80211_ATTR_STA_LISTEN_INTERVAL] = { .type = NLA_U16 },
246 [NL80211_ATTR_STA_SUPPORTED_RATES] = { .type = NLA_BINARY,
247 .len = NL80211_MAX_SUPP_RATES },
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +0100248 [NL80211_ATTR_STA_PLINK_ACTION] = { .type = NLA_U8 },
Johannes Berg5727ef12007-12-19 02:03:34 +0100249 [NL80211_ATTR_STA_VLAN] = { .type = NLA_U32 },
Johannes Berg0a9542e2008-10-15 11:54:04 +0200250 [NL80211_ATTR_MNTR_FLAGS] = { /* NLA_NESTED can't be empty */ },
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +0100251 [NL80211_ATTR_MESH_ID] = { .type = NLA_BINARY,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +0800252 .len = IEEE80211_MAX_MESH_ID_LEN },
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +0100253 [NL80211_ATTR_MPATH_NEXT_HOP] = { .type = NLA_U32 },
Jouni Malinen9f1ba902008-08-07 20:07:01 +0300254
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -0700255 [NL80211_ATTR_REG_ALPHA2] = { .type = NLA_STRING, .len = 2 },
256 [NL80211_ATTR_REG_RULES] = { .type = NLA_NESTED },
257
Jouni Malinen9f1ba902008-08-07 20:07:01 +0300258 [NL80211_ATTR_BSS_CTS_PROT] = { .type = NLA_U8 },
259 [NL80211_ATTR_BSS_SHORT_PREAMBLE] = { .type = NLA_U8 },
260 [NL80211_ATTR_BSS_SHORT_SLOT_TIME] = { .type = NLA_U8 },
Jouni Malinen90c97a02008-10-30 16:59:22 +0200261 [NL80211_ATTR_BSS_BASIC_RATES] = { .type = NLA_BINARY,
262 .len = NL80211_MAX_SUPP_RATES },
Helmut Schaa50b12f52010-11-19 12:40:25 +0100263 [NL80211_ATTR_BSS_HT_OPMODE] = { .type = NLA_U16 },
Jouni Malinen36aedc92008-08-25 11:58:58 +0300264
Javier Cardona24bdd9f2010-12-16 17:37:48 -0800265 [NL80211_ATTR_MESH_CONFIG] = { .type = NLA_NESTED },
Javier Cardona15d5dda2011-04-07 15:08:28 -0700266 [NL80211_ATTR_SUPPORT_MESH_AUTH] = { .type = NLA_FLAG },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -0700267
Johannes Berg6c739412011-11-03 09:27:01 +0100268 [NL80211_ATTR_HT_CAPABILITY] = { .len = NL80211_HT_CAPABILITY_LEN },
Jouni Malinen9aed3cc2009-01-13 16:03:29 +0200269
270 [NL80211_ATTR_MGMT_SUBTYPE] = { .type = NLA_U8 },
271 [NL80211_ATTR_IE] = { .type = NLA_BINARY,
272 .len = IEEE80211_MAX_DATA_LEN },
Johannes Berg2a519312009-02-10 21:25:55 +0100273 [NL80211_ATTR_SCAN_FREQUENCIES] = { .type = NLA_NESTED },
274 [NL80211_ATTR_SCAN_SSIDS] = { .type = NLA_NESTED },
Jouni Malinen636a5d32009-03-19 13:39:22 +0200275
276 [NL80211_ATTR_SSID] = { .type = NLA_BINARY,
277 .len = IEEE80211_MAX_SSID_LEN },
278 [NL80211_ATTR_AUTH_TYPE] = { .type = NLA_U32 },
279 [NL80211_ATTR_REASON_CODE] = { .type = NLA_U16 },
Johannes Berg04a773a2009-04-19 21:24:32 +0200280 [NL80211_ATTR_FREQ_FIXED] = { .type = NLA_FLAG },
Jouni Malinen1965c852009-04-22 21:38:25 +0300281 [NL80211_ATTR_TIMED_OUT] = { .type = NLA_FLAG },
Jouni Malinendc6382ce2009-05-06 22:09:37 +0300282 [NL80211_ATTR_USE_MFP] = { .type = NLA_U32 },
Johannes Bergeccb8e82009-05-11 21:57:56 +0300283 [NL80211_ATTR_STA_FLAGS2] = {
284 .len = sizeof(struct nl80211_sta_flag_update),
285 },
Jouni Malinen3f77316c2009-05-11 21:57:57 +0300286 [NL80211_ATTR_CONTROL_PORT] = { .type = NLA_FLAG },
Johannes Bergc0692b82010-08-27 14:26:53 +0300287 [NL80211_ATTR_CONTROL_PORT_ETHERTYPE] = { .type = NLA_U16 },
288 [NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT] = { .type = NLA_FLAG },
Samuel Ortizb23aa672009-07-01 21:26:54 +0200289 [NL80211_ATTR_PRIVACY] = { .type = NLA_FLAG },
290 [NL80211_ATTR_CIPHER_SUITE_GROUP] = { .type = NLA_U32 },
291 [NL80211_ATTR_WPA_VERSIONS] = { .type = NLA_U32 },
Johannes Berg463d0182009-07-14 00:33:35 +0200292 [NL80211_ATTR_PID] = { .type = NLA_U32 },
Felix Fietkau8b787642009-11-10 18:53:10 +0100293 [NL80211_ATTR_4ADDR] = { .type = NLA_U8 },
Srinivas Dasari9361df12017-07-07 01:43:39 +0300294 [NL80211_ATTR_PMKID] = { .len = WLAN_PMKID_LEN },
Jouni Malinen9588bbd2009-12-23 13:15:41 +0100295 [NL80211_ATTR_DURATION] = { .type = NLA_U32 },
296 [NL80211_ATTR_COOKIE] = { .type = NLA_U64 },
Jouni Malinen13ae75b2009-12-29 12:59:45 +0200297 [NL80211_ATTR_TX_RATES] = { .type = NLA_NESTED },
Jouni Malinen026331c2010-02-15 12:53:10 +0200298 [NL80211_ATTR_FRAME] = { .type = NLA_BINARY,
299 .len = IEEE80211_MAX_DATA_LEN },
300 [NL80211_ATTR_FRAME_MATCH] = { .type = NLA_BINARY, },
Kalle Valoffb9eb32010-02-17 17:58:10 +0200301 [NL80211_ATTR_PS_STATE] = { .type = NLA_U32 },
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +0200302 [NL80211_ATTR_CQM] = { .type = NLA_NESTED, },
Jouni Malinend5cdfac2010-04-04 09:37:19 +0300303 [NL80211_ATTR_LOCAL_STATE_CHANGE] = { .type = NLA_FLAG },
Felix Fietkaufd8aaaf2010-04-27 01:23:35 +0200304 [NL80211_ATTR_AP_ISOLATE] = { .type = NLA_U8 },
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +0300305 [NL80211_ATTR_WIPHY_TX_POWER_SETTING] = { .type = NLA_U32 },
306 [NL80211_ATTR_WIPHY_TX_POWER_LEVEL] = { .type = NLA_U32 },
Johannes Berg2e161f72010-08-12 15:38:38 +0200307 [NL80211_ATTR_FRAME_TYPE] = { .type = NLA_U16 },
Bruno Randolfafe0cbf2010-11-10 12:50:50 +0900308 [NL80211_ATTR_WIPHY_ANTENNA_TX] = { .type = NLA_U32 },
309 [NL80211_ATTR_WIPHY_ANTENNA_RX] = { .type = NLA_U32 },
Felix Fietkau885a46d2010-11-11 15:07:22 +0100310 [NL80211_ATTR_MCAST_RATE] = { .type = NLA_U32 },
Johannes Bergf7ca38d2010-11-25 10:02:29 +0100311 [NL80211_ATTR_OFFCHANNEL_TX_OK] = { .type = NLA_FLAG },
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100312 [NL80211_ATTR_KEY_DEFAULT_TYPES] = { .type = NLA_NESTED },
Johannes Bergff1b6e62011-05-04 15:37:28 +0200313 [NL80211_ATTR_WOWLAN_TRIGGERS] = { .type = NLA_NESTED },
Javier Cardona9c3990a2011-05-03 16:57:11 -0700314 [NL80211_ATTR_STA_PLINK_STATE] = { .type = NLA_U8 },
Luciano Coelhobbe6ad62011-05-11 17:09:37 +0300315 [NL80211_ATTR_SCHED_SCAN_INTERVAL] = { .type = NLA_U32 },
Johannes Berge5497d72011-07-05 16:35:40 +0200316 [NL80211_ATTR_REKEY_DATA] = { .type = NLA_NESTED },
Johannes Berg34850ab2011-07-18 18:08:35 +0200317 [NL80211_ATTR_SCAN_SUPP_RATES] = { .type = NLA_NESTED },
Jouni Malinen32e9de82011-08-10 23:53:31 +0300318 [NL80211_ATTR_HIDDEN_SSID] = { .type = NLA_U32 },
Jouni Malinen9946ecf2011-08-10 23:55:56 +0300319 [NL80211_ATTR_IE_PROBE_RESP] = { .type = NLA_BINARY,
320 .len = IEEE80211_MAX_DATA_LEN },
321 [NL80211_ATTR_IE_ASSOC_RESP] = { .type = NLA_BINARY,
322 .len = IEEE80211_MAX_DATA_LEN },
Vivek Natarajanf4b34b52011-08-29 14:23:03 +0530323 [NL80211_ATTR_ROAM_SUPPORT] = { .type = NLA_FLAG },
Luciano Coelhoa1f1c212011-08-31 16:01:48 +0300324 [NL80211_ATTR_SCHED_SCAN_MATCH] = { .type = NLA_NESTED },
Rajkumar Manoharane9f935e2011-09-25 14:53:30 +0530325 [NL80211_ATTR_TX_NO_CCK_RATE] = { .type = NLA_FLAG },
Arik Nemtsov109086c2011-09-28 14:12:50 +0300326 [NL80211_ATTR_TDLS_ACTION] = { .type = NLA_U8 },
327 [NL80211_ATTR_TDLS_DIALOG_TOKEN] = { .type = NLA_U8 },
328 [NL80211_ATTR_TDLS_OPERATION] = { .type = NLA_U8 },
329 [NL80211_ATTR_TDLS_SUPPORT] = { .type = NLA_FLAG },
330 [NL80211_ATTR_TDLS_EXTERNAL_SETUP] = { .type = NLA_FLAG },
Arik Nemtsov31fa97c2014-06-11 17:18:21 +0300331 [NL80211_ATTR_TDLS_INITIATOR] = { .type = NLA_FLAG },
Johannes Berge247bd902011-11-04 11:18:21 +0100332 [NL80211_ATTR_DONT_WAIT_FOR_ACK] = { .type = NLA_FLAG },
Arik Nemtsov00f740e2011-11-10 11:28:56 +0200333 [NL80211_ATTR_PROBE_RESP] = { .type = NLA_BINARY,
334 .len = IEEE80211_MAX_DATA_LEN },
Luis R. Rodriguez8b60b072011-10-11 10:59:02 -0700335 [NL80211_ATTR_DFS_REGION] = { .type = NLA_U8 },
Ben Greear7e7c8922011-11-18 11:31:59 -0800336 [NL80211_ATTR_DISABLE_HT] = { .type = NLA_FLAG },
337 [NL80211_ATTR_HT_CAPABILITY_MASK] = {
338 .len = NL80211_HT_CAPABILITY_LEN
339 },
Simon Wunderlich1d9d9212011-11-18 14:20:43 +0100340 [NL80211_ATTR_NOACK_MAP] = { .type = NLA_U16 },
Vasanthakumar Thiagarajan1b658f12012-03-02 15:50:02 +0530341 [NL80211_ATTR_INACTIVITY_TIMEOUT] = { .type = NLA_U16 },
Bala Shanmugam4486ea92012-03-07 17:27:12 +0530342 [NL80211_ATTR_BG_SCAN_PERIOD] = { .type = NLA_U16 },
Johannes Berg89a54e42012-06-15 14:33:17 +0200343 [NL80211_ATTR_WDEV] = { .type = NLA_U64 },
Luis R. Rodriguez57b5ce02012-07-12 11:49:18 -0700344 [NL80211_ATTR_USER_REG_HINT_TYPE] = { .type = NLA_U32 },
Jouni Malinen11b6b5a2016-10-27 00:41:58 +0300345 [NL80211_ATTR_AUTH_DATA] = { .type = NLA_BINARY, },
Mahesh Palivelaf461be3e2012-10-11 08:04:52 +0000346 [NL80211_ATTR_VHT_CAPABILITY] = { .len = NL80211_VHT_CAPABILITY_LEN },
Sam Lefflered4737712012-10-11 21:03:31 -0700347 [NL80211_ATTR_SCAN_FLAGS] = { .type = NLA_U32 },
Johannes Berg53cabad2012-11-14 15:17:28 +0100348 [NL80211_ATTR_P2P_CTWINDOW] = { .type = NLA_U8 },
349 [NL80211_ATTR_P2P_OPPPS] = { .type = NLA_U8 },
Srinivas Dasari8feb69c2017-07-07 01:43:41 +0300350 [NL80211_ATTR_LOCAL_MESH_POWER_MODE] = {. type = NLA_U32 },
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +0530351 [NL80211_ATTR_ACL_POLICY] = {. type = NLA_U32 },
352 [NL80211_ATTR_MAC_ADDRS] = { .type = NLA_NESTED },
Jouni Malinen9d62a982013-02-14 21:10:13 +0200353 [NL80211_ATTR_STA_CAPABILITY] = { .type = NLA_U16 },
354 [NL80211_ATTR_STA_EXT_CAPABILITY] = { .type = NLA_BINARY, },
Johannes Berg3713b4e2013-02-14 16:19:38 +0100355 [NL80211_ATTR_SPLIT_WIPHY_DUMP] = { .type = NLA_FLAG, },
Johannes Bergee2aca32013-02-21 17:36:01 +0100356 [NL80211_ATTR_DISABLE_VHT] = { .type = NLA_FLAG },
357 [NL80211_ATTR_VHT_CAPABILITY_MASK] = {
358 .len = NL80211_VHT_CAPABILITY_LEN,
359 },
Jouni Malinen355199e2013-02-27 17:14:27 +0200360 [NL80211_ATTR_MDID] = { .type = NLA_U16 },
361 [NL80211_ATTR_IE_RIC] = { .type = NLA_BINARY,
362 .len = IEEE80211_MAX_DATA_LEN },
Jouni Malinen5e4b6f52013-05-16 20:11:08 +0300363 [NL80211_ATTR_PEER_AID] = { .type = NLA_U16 },
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +0200364 [NL80211_ATTR_CH_SWITCH_COUNT] = { .type = NLA_U32 },
365 [NL80211_ATTR_CH_SWITCH_BLOCK_TX] = { .type = NLA_FLAG },
366 [NL80211_ATTR_CSA_IES] = { .type = NLA_NESTED },
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +0300367 [NL80211_ATTR_CSA_C_OFF_BEACON] = { .type = NLA_BINARY },
368 [NL80211_ATTR_CSA_C_OFF_PRESP] = { .type = NLA_BINARY },
Sunil Duttc01fc9a2013-10-09 20:45:21 +0530369 [NL80211_ATTR_STA_SUPPORTED_CHANNELS] = { .type = NLA_BINARY },
370 [NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES] = { .type = NLA_BINARY },
Simon Wunderlich5336fa82013-10-07 18:41:05 +0200371 [NL80211_ATTR_HANDLE_DFS] = { .type = NLA_FLAG },
Marek Kwaczynski60f4a7b2013-12-03 10:04:59 +0100372 [NL80211_ATTR_OPMODE_NOTIF] = { .type = NLA_U8 },
Johannes Bergad7e7182013-11-13 13:37:47 +0100373 [NL80211_ATTR_VENDOR_ID] = { .type = NLA_U32 },
374 [NL80211_ATTR_VENDOR_SUBCMD] = { .type = NLA_U32 },
375 [NL80211_ATTR_VENDOR_DATA] = { .type = NLA_BINARY },
Kyeyoon Parkfa9ffc72013-12-16 23:01:30 -0800376 [NL80211_ATTR_QOS_MAP] = { .type = NLA_BINARY,
377 .len = IEEE80211_QOS_MAP_LEN_MAX },
Jouni Malinen1df4a512014-01-15 00:00:47 +0200378 [NL80211_ATTR_MAC_HINT] = { .len = ETH_ALEN },
379 [NL80211_ATTR_WIPHY_FREQ_HINT] = { .type = NLA_U32 },
Sunil Dutt Undekaridf942e72014-02-20 16:22:09 +0530380 [NL80211_ATTR_TDLS_PEER_CAPABILITY] = { .type = NLA_U32 },
Jukka Rissanen18e5ca62014-11-13 17:25:14 +0200381 [NL80211_ATTR_SOCKET_OWNER] = { .type = NLA_FLAG },
Andrei Otcheretianski34d22ce2014-05-09 14:11:44 +0300382 [NL80211_ATTR_CSA_C_OFFSETS_TX] = { .type = NLA_BINARY },
Assaf Kraussbab5ab72014-09-03 15:25:01 +0300383 [NL80211_ATTR_USE_RRM] = { .type = NLA_FLAG },
Johannes Berg960d01a2014-09-09 22:55:35 +0300384 [NL80211_ATTR_TSID] = { .type = NLA_U8 },
385 [NL80211_ATTR_USER_PRIO] = { .type = NLA_U8 },
386 [NL80211_ATTR_ADMITTED_TIME] = { .type = NLA_U16 },
Eliad Peller18998c32014-09-10 14:07:34 +0300387 [NL80211_ATTR_SMPS_MODE] = { .type = NLA_U8 },
Johannes Bergad2b26a2014-06-12 21:39:05 +0200388 [NL80211_ATTR_MAC_MASK] = { .len = ETH_ALEN },
Arik Nemtsov1bdd7162014-12-15 19:26:01 +0200389 [NL80211_ATTR_WIPHY_SELF_MANAGED_REG] = { .type = NLA_FLAG },
Vadim Kochan4b681c82015-01-12 16:34:05 +0200390 [NL80211_ATTR_NETNS_FD] = { .type = NLA_U32 },
Luciano Coelho9c748932015-01-16 16:04:09 +0200391 [NL80211_ATTR_SCHED_SCAN_DELAY] = { .type = NLA_U32 },
Ilan peer05050752015-03-04 00:32:06 -0500392 [NL80211_ATTR_REG_INDOOR] = { .type = NLA_FLAG },
Lior David34d50512016-01-28 10:58:25 +0200393 [NL80211_ATTR_PBSS] = { .type = NLA_FLAG },
Arend van Spriel38de03d2016-03-02 20:37:18 +0100394 [NL80211_ATTR_BSS_SELECT] = { .type = NLA_NESTED },
Ayala Beker17b94242016-03-17 15:41:38 +0200395 [NL80211_ATTR_STA_SUPPORT_P2P_PS] = { .type = NLA_U8 },
Aviya Erenfeldc6e6a0c2016-07-05 15:23:08 +0300396 [NL80211_ATTR_MU_MIMO_GROUP_DATA] = {
397 .len = VHT_MUMIMO_GROUPS_DATA_LEN
398 },
399 [NL80211_ATTR_MU_MIMO_FOLLOW_MAC_ADDR] = { .len = ETH_ALEN },
Ayala Bekercb3b7d82016-09-20 17:31:13 +0300400 [NL80211_ATTR_NAN_MASTER_PREF] = { .type = NLA_U8 },
Luca Coelho85859892017-02-08 15:00:34 +0200401 [NL80211_ATTR_BANDS] = { .type = NLA_U32 },
Ayala Bekera442b762016-09-20 17:31:15 +0300402 [NL80211_ATTR_NAN_FUNC] = { .type = NLA_NESTED },
Jouni Malinen348bd452016-10-27 00:42:03 +0300403 [NL80211_ATTR_FILS_KEK] = { .type = NLA_BINARY,
404 .len = FILS_MAX_KEK_LEN },
405 [NL80211_ATTR_FILS_NONCES] = { .len = 2 * FILS_NONCE_LEN },
Michael Braunce0ce132016-10-10 19:12:22 +0200406 [NL80211_ATTR_MULTICAST_TO_UNICAST_ENABLED] = { .type = NLA_FLAG, },
Vamsi Krishna2fa436b2016-12-02 23:59:08 +0200407 [NL80211_ATTR_BSSID] = { .len = ETH_ALEN },
vamsi krishnabf95ecd2017-01-13 01:12:20 +0200408 [NL80211_ATTR_SCHED_SCAN_RELATIVE_RSSI] = { .type = NLA_S8 },
409 [NL80211_ATTR_SCHED_SCAN_RSSI_ADJUST] = {
410 .len = sizeof(struct nl80211_bss_select_rssi_adjust)
411 },
Purushottam Kushwaha3093ebbeab2017-01-13 01:12:21 +0200412 [NL80211_ATTR_TIMEOUT_REASON] = { .type = NLA_U32 },
Vidyullatha Kanchanapallya3caf742017-03-31 00:22:34 +0300413 [NL80211_ATTR_FILS_ERP_USERNAME] = { .type = NLA_BINARY,
414 .len = FILS_ERP_MAX_USERNAME_LEN },
415 [NL80211_ATTR_FILS_ERP_REALM] = { .type = NLA_BINARY,
416 .len = FILS_ERP_MAX_REALM_LEN },
417 [NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM] = { .type = NLA_U16 },
418 [NL80211_ATTR_FILS_ERP_RRK] = { .type = NLA_BINARY,
419 .len = FILS_ERP_MAX_RRK_LEN },
420 [NL80211_ATTR_FILS_CACHE_ID] = { .len = 2 },
421 [NL80211_ATTR_PMK] = { .type = NLA_BINARY, .len = PMK_MAX_LEN },
Arend Van Sprielca986ad2017-04-21 13:05:00 +0100422 [NL80211_ATTR_SCHED_SCAN_MULTI] = { .type = NLA_FLAG },
Johannes Berg55682962007-09-20 13:09:35 -0400423};
424
Johannes Berge31b8212010-10-05 19:39:30 +0200425/* policy for the key attributes */
Alexey Dobriyanb54452b2010-02-18 08:14:31 +0000426static const struct nla_policy nl80211_key_policy[NL80211_KEY_MAX + 1] = {
Johannes Bergfffd0932009-07-08 14:22:54 +0200427 [NL80211_KEY_DATA] = { .type = NLA_BINARY, .len = WLAN_MAX_KEY_LEN },
Johannes Bergb9454e82009-07-08 13:29:08 +0200428 [NL80211_KEY_IDX] = { .type = NLA_U8 },
429 [NL80211_KEY_CIPHER] = { .type = NLA_U32 },
Jouni Malinen81962262011-11-02 23:36:31 +0200430 [NL80211_KEY_SEQ] = { .type = NLA_BINARY, .len = 16 },
Johannes Bergb9454e82009-07-08 13:29:08 +0200431 [NL80211_KEY_DEFAULT] = { .type = NLA_FLAG },
432 [NL80211_KEY_DEFAULT_MGMT] = { .type = NLA_FLAG },
Johannes Berge31b8212010-10-05 19:39:30 +0200433 [NL80211_KEY_TYPE] = { .type = NLA_U32 },
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100434 [NL80211_KEY_DEFAULT_TYPES] = { .type = NLA_NESTED },
435};
436
437/* policy for the key default flags */
438static const struct nla_policy
439nl80211_key_default_policy[NUM_NL80211_KEY_DEFAULT_TYPES] = {
440 [NL80211_KEY_DEFAULT_TYPE_UNICAST] = { .type = NLA_FLAG },
441 [NL80211_KEY_DEFAULT_TYPE_MULTICAST] = { .type = NLA_FLAG },
Johannes Bergb9454e82009-07-08 13:29:08 +0200442};
443
Johannes Bergf83ace32016-10-17 08:04:07 +0200444#ifdef CONFIG_PM
Johannes Bergff1b6e62011-05-04 15:37:28 +0200445/* policy for WoWLAN attributes */
446static const struct nla_policy
447nl80211_wowlan_policy[NUM_NL80211_WOWLAN_TRIG] = {
448 [NL80211_WOWLAN_TRIG_ANY] = { .type = NLA_FLAG },
449 [NL80211_WOWLAN_TRIG_DISCONNECT] = { .type = NLA_FLAG },
450 [NL80211_WOWLAN_TRIG_MAGIC_PKT] = { .type = NLA_FLAG },
451 [NL80211_WOWLAN_TRIG_PKT_PATTERN] = { .type = NLA_NESTED },
Johannes Berg77dbbb12011-07-13 10:48:55 +0200452 [NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE] = { .type = NLA_FLAG },
453 [NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST] = { .type = NLA_FLAG },
454 [NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE] = { .type = NLA_FLAG },
455 [NL80211_WOWLAN_TRIG_RFKILL_RELEASE] = { .type = NLA_FLAG },
Johannes Berg2a0e0472013-01-23 22:57:40 +0100456 [NL80211_WOWLAN_TRIG_TCP_CONNECTION] = { .type = NLA_NESTED },
Luciano Coelho8cd4d452014-09-17 11:55:28 +0300457 [NL80211_WOWLAN_TRIG_NET_DETECT] = { .type = NLA_NESTED },
Johannes Berg2a0e0472013-01-23 22:57:40 +0100458};
459
460static const struct nla_policy
461nl80211_wowlan_tcp_policy[NUM_NL80211_WOWLAN_TCP] = {
462 [NL80211_WOWLAN_TCP_SRC_IPV4] = { .type = NLA_U32 },
463 [NL80211_WOWLAN_TCP_DST_IPV4] = { .type = NLA_U32 },
464 [NL80211_WOWLAN_TCP_DST_MAC] = { .len = ETH_ALEN },
465 [NL80211_WOWLAN_TCP_SRC_PORT] = { .type = NLA_U16 },
466 [NL80211_WOWLAN_TCP_DST_PORT] = { .type = NLA_U16 },
467 [NL80211_WOWLAN_TCP_DATA_PAYLOAD] = { .len = 1 },
468 [NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ] = {
469 .len = sizeof(struct nl80211_wowlan_tcp_data_seq)
470 },
471 [NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN] = {
472 .len = sizeof(struct nl80211_wowlan_tcp_data_token)
473 },
474 [NL80211_WOWLAN_TCP_DATA_INTERVAL] = { .type = NLA_U32 },
475 [NL80211_WOWLAN_TCP_WAKE_PAYLOAD] = { .len = 1 },
476 [NL80211_WOWLAN_TCP_WAKE_MASK] = { .len = 1 },
Johannes Bergff1b6e62011-05-04 15:37:28 +0200477};
Johannes Bergf83ace32016-10-17 08:04:07 +0200478#endif /* CONFIG_PM */
Johannes Bergff1b6e62011-05-04 15:37:28 +0200479
Amitkumar Karwarbe29b992013-06-28 11:51:26 -0700480/* policy for coalesce rule attributes */
481static const struct nla_policy
482nl80211_coalesce_policy[NUM_NL80211_ATTR_COALESCE_RULE] = {
483 [NL80211_ATTR_COALESCE_RULE_DELAY] = { .type = NLA_U32 },
484 [NL80211_ATTR_COALESCE_RULE_CONDITION] = { .type = NLA_U32 },
485 [NL80211_ATTR_COALESCE_RULE_PKT_PATTERN] = { .type = NLA_NESTED },
486};
487
Johannes Berge5497d72011-07-05 16:35:40 +0200488/* policy for GTK rekey offload attributes */
489static const struct nla_policy
490nl80211_rekey_policy[NUM_NL80211_REKEY_DATA] = {
491 [NL80211_REKEY_DATA_KEK] = { .len = NL80211_KEK_LEN },
492 [NL80211_REKEY_DATA_KCK] = { .len = NL80211_KCK_LEN },
493 [NL80211_REKEY_DATA_REPLAY_CTR] = { .len = NL80211_REPLAY_CTR_LEN },
494};
495
Luciano Coelhoa1f1c212011-08-31 16:01:48 +0300496static const struct nla_policy
497nl80211_match_policy[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1] = {
Johannes Berg4a4ab0d2012-06-13 11:17:11 +0200498 [NL80211_SCHED_SCAN_MATCH_ATTR_SSID] = { .type = NLA_BINARY,
Luciano Coelhoa1f1c212011-08-31 16:01:48 +0300499 .len = IEEE80211_MAX_SSID_LEN },
Arend Van Spriel3007e352017-04-21 13:05:01 +0100500 [NL80211_SCHED_SCAN_MATCH_ATTR_BSSID] = { .len = ETH_ALEN },
Thomas Pedersen88e920b2012-06-21 11:09:54 -0700501 [NL80211_SCHED_SCAN_MATCH_ATTR_RSSI] = { .type = NLA_U32 },
Luciano Coelhoa1f1c212011-08-31 16:01:48 +0300502};
503
Avraham Stern3b06d272015-10-12 09:51:34 +0300504static const struct nla_policy
505nl80211_plan_policy[NL80211_SCHED_SCAN_PLAN_MAX + 1] = {
506 [NL80211_SCHED_SCAN_PLAN_INTERVAL] = { .type = NLA_U32 },
507 [NL80211_SCHED_SCAN_PLAN_ITERATIONS] = { .type = NLA_U32 },
508};
509
Arend van Spriel38de03d2016-03-02 20:37:18 +0100510static const struct nla_policy
511nl80211_bss_select_policy[NL80211_BSS_SELECT_ATTR_MAX + 1] = {
512 [NL80211_BSS_SELECT_ATTR_RSSI] = { .type = NLA_FLAG },
513 [NL80211_BSS_SELECT_ATTR_BAND_PREF] = { .type = NLA_U32 },
514 [NL80211_BSS_SELECT_ATTR_RSSI_ADJUST] = {
515 .len = sizeof(struct nl80211_bss_select_rssi_adjust)
516 },
517};
518
Ayala Bekera442b762016-09-20 17:31:15 +0300519/* policy for NAN function attributes */
520static const struct nla_policy
521nl80211_nan_func_policy[NL80211_NAN_FUNC_ATTR_MAX + 1] = {
522 [NL80211_NAN_FUNC_TYPE] = { .type = NLA_U8 },
Srinivas Dasari0a278442017-07-07 01:43:40 +0300523 [NL80211_NAN_FUNC_SERVICE_ID] = {
Ayala Bekera442b762016-09-20 17:31:15 +0300524 .len = NL80211_NAN_FUNC_SERVICE_ID_LEN },
525 [NL80211_NAN_FUNC_PUBLISH_TYPE] = { .type = NLA_U8 },
526 [NL80211_NAN_FUNC_PUBLISH_BCAST] = { .type = NLA_FLAG },
527 [NL80211_NAN_FUNC_SUBSCRIBE_ACTIVE] = { .type = NLA_FLAG },
528 [NL80211_NAN_FUNC_FOLLOW_UP_ID] = { .type = NLA_U8 },
529 [NL80211_NAN_FUNC_FOLLOW_UP_REQ_ID] = { .type = NLA_U8 },
530 [NL80211_NAN_FUNC_FOLLOW_UP_DEST] = { .len = ETH_ALEN },
531 [NL80211_NAN_FUNC_CLOSE_RANGE] = { .type = NLA_FLAG },
532 [NL80211_NAN_FUNC_TTL] = { .type = NLA_U32 },
533 [NL80211_NAN_FUNC_SERVICE_INFO] = { .type = NLA_BINARY,
534 .len = NL80211_NAN_FUNC_SERVICE_SPEC_INFO_MAX_LEN },
535 [NL80211_NAN_FUNC_SRF] = { .type = NLA_NESTED },
536 [NL80211_NAN_FUNC_RX_MATCH_FILTER] = { .type = NLA_NESTED },
537 [NL80211_NAN_FUNC_TX_MATCH_FILTER] = { .type = NLA_NESTED },
538 [NL80211_NAN_FUNC_INSTANCE_ID] = { .type = NLA_U8 },
539 [NL80211_NAN_FUNC_TERM_REASON] = { .type = NLA_U8 },
540};
541
542/* policy for Service Response Filter attributes */
543static const struct nla_policy
544nl80211_nan_srf_policy[NL80211_NAN_SRF_ATTR_MAX + 1] = {
545 [NL80211_NAN_SRF_INCLUDE] = { .type = NLA_FLAG },
546 [NL80211_NAN_SRF_BF] = { .type = NLA_BINARY,
547 .len = NL80211_NAN_FUNC_SRF_MAX_LEN },
548 [NL80211_NAN_SRF_BF_IDX] = { .type = NLA_U8 },
549 [NL80211_NAN_SRF_MAC_ADDRS] = { .type = NLA_NESTED },
550};
551
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 Karwarbe29b992013-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 Karwarbe29b992013-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 Karwarbe29b992013-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 Karwarbe29b992013-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 Karwarbe29b992013-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 Karwarbe29b992013-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);
Tova Mussaiffa46292017-08-05 11:44:38 +03002125 /* user input for center_freq is incorrect */
2126 if (info->attrs[NL80211_ATTR_CENTER_FREQ1] &&
2127 chandef->center_freq1 != nla_get_u32(
2128 info->attrs[NL80211_ATTR_CENTER_FREQ1]))
2129 return -EINVAL;
2130 /* center_freq2 must be zero */
2131 if (info->attrs[NL80211_ATTR_CENTER_FREQ2] &&
2132 nla_get_u32(info->attrs[NL80211_ATTR_CENTER_FREQ2]))
2133 return -EINVAL;
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002134 break;
2135 default:
Johannes Berg683b6d32012-11-08 21:25:48 +01002136 return -EINVAL;
Johannes Berg683b6d32012-11-08 21:25:48 +01002137 }
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002138 } else if (info->attrs[NL80211_ATTR_CHANNEL_WIDTH]) {
2139 chandef->width =
2140 nla_get_u32(info->attrs[NL80211_ATTR_CHANNEL_WIDTH]);
2141 if (info->attrs[NL80211_ATTR_CENTER_FREQ1])
2142 chandef->center_freq1 =
2143 nla_get_u32(
2144 info->attrs[NL80211_ATTR_CENTER_FREQ1]);
2145 if (info->attrs[NL80211_ATTR_CENTER_FREQ2])
2146 chandef->center_freq2 =
2147 nla_get_u32(
2148 info->attrs[NL80211_ATTR_CENTER_FREQ2]);
2149 }
2150
Johannes Berg9f5e8f62012-11-22 16:59:45 +01002151 if (!cfg80211_chandef_valid(chandef))
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002152 return -EINVAL;
2153
Johannes Berg9f5e8f62012-11-22 16:59:45 +01002154 if (!cfg80211_chandef_usable(&rdev->wiphy, chandef,
2155 IEEE80211_CHAN_DISABLED))
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002156 return -EINVAL;
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002157
Simon Wunderlich2f301ab2013-05-16 13:00:28 +02002158 if ((chandef->width == NL80211_CHAN_WIDTH_5 ||
2159 chandef->width == NL80211_CHAN_WIDTH_10) &&
2160 !(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_5_10_MHZ))
2161 return -EINVAL;
2162
Johannes Berg683b6d32012-11-08 21:25:48 +01002163 return 0;
2164}
2165
Johannes Bergf444de02010-05-05 15:25:02 +02002166static int __nl80211_set_channel(struct cfg80211_registered_device *rdev,
Jouni Malinene16821b2014-04-28 11:22:08 +03002167 struct net_device *dev,
Johannes Bergf444de02010-05-05 15:25:02 +02002168 struct genl_info *info)
2169{
Johannes Berg683b6d32012-11-08 21:25:48 +01002170 struct cfg80211_chan_def chandef;
Johannes Bergf444de02010-05-05 15:25:02 +02002171 int result;
Johannes Berge8c9bd52012-06-06 08:18:22 +02002172 enum nl80211_iftype iftype = NL80211_IFTYPE_MONITOR;
Jouni Malinene16821b2014-04-28 11:22:08 +03002173 struct wireless_dev *wdev = NULL;
Johannes Berge8c9bd52012-06-06 08:18:22 +02002174
Jouni Malinene16821b2014-04-28 11:22:08 +03002175 if (dev)
2176 wdev = dev->ieee80211_ptr;
Johannes Bergf444de02010-05-05 15:25:02 +02002177 if (!nl80211_can_set_dev_channel(wdev))
2178 return -EOPNOTSUPP;
Jouni Malinene16821b2014-04-28 11:22:08 +03002179 if (wdev)
2180 iftype = wdev->iftype;
Johannes Bergf444de02010-05-05 15:25:02 +02002181
Johannes Berg683b6d32012-11-08 21:25:48 +01002182 result = nl80211_parse_chandef(rdev, info, &chandef);
2183 if (result)
2184 return result;
Johannes Bergf444de02010-05-05 15:25:02 +02002185
Johannes Berge8c9bd52012-06-06 08:18:22 +02002186 switch (iftype) {
Johannes Bergaa430da2012-05-16 23:50:18 +02002187 case NL80211_IFTYPE_AP:
2188 case NL80211_IFTYPE_P2P_GO:
Arik Nemtsov923b3522015-07-08 15:41:44 +03002189 if (!cfg80211_reg_can_beacon_relax(&rdev->wiphy, &chandef,
2190 iftype)) {
Johannes Bergaa430da2012-05-16 23:50:18 +02002191 result = -EINVAL;
2192 break;
2193 }
Jouni Malinene16821b2014-04-28 11:22:08 +03002194 if (wdev->beacon_interval) {
2195 if (!dev || !rdev->ops->set_ap_chanwidth ||
2196 !(rdev->wiphy.features &
2197 NL80211_FEATURE_AP_MODE_CHAN_WIDTH_CHANGE)) {
2198 result = -EBUSY;
2199 break;
2200 }
2201
2202 /* Only allow dynamic channel width changes */
2203 if (chandef.chan != wdev->preset_chandef.chan) {
2204 result = -EBUSY;
2205 break;
2206 }
2207 result = rdev_set_ap_chanwidth(rdev, dev, &chandef);
2208 if (result)
2209 break;
2210 }
Johannes Berg683b6d32012-11-08 21:25:48 +01002211 wdev->preset_chandef = chandef;
Johannes Bergaa430da2012-05-16 23:50:18 +02002212 result = 0;
2213 break;
Johannes Bergcc1d2802012-05-16 23:50:20 +02002214 case NL80211_IFTYPE_MESH_POINT:
Johannes Berg683b6d32012-11-08 21:25:48 +01002215 result = cfg80211_set_mesh_channel(rdev, wdev, &chandef);
Johannes Bergcc1d2802012-05-16 23:50:20 +02002216 break;
Johannes Berge8c9bd52012-06-06 08:18:22 +02002217 case NL80211_IFTYPE_MONITOR:
Johannes Berg683b6d32012-11-08 21:25:48 +01002218 result = cfg80211_set_monitor_channel(rdev, &chandef);
Johannes Berge8c9bd52012-06-06 08:18:22 +02002219 break;
Johannes Bergaa430da2012-05-16 23:50:18 +02002220 default:
Johannes Berge8c9bd52012-06-06 08:18:22 +02002221 result = -EINVAL;
Johannes Bergf444de02010-05-05 15:25:02 +02002222 }
Johannes Bergf444de02010-05-05 15:25:02 +02002223
2224 return result;
2225}
2226
2227static int nl80211_set_channel(struct sk_buff *skb, struct genl_info *info)
2228{
Johannes Berg4c476992010-10-04 21:36:35 +02002229 struct cfg80211_registered_device *rdev = info->user_ptr[0];
2230 struct net_device *netdev = info->user_ptr[1];
Johannes Bergf444de02010-05-05 15:25:02 +02002231
Jouni Malinene16821b2014-04-28 11:22:08 +03002232 return __nl80211_set_channel(rdev, netdev, info);
Johannes Bergf444de02010-05-05 15:25:02 +02002233}
2234
Bill Jordane8347eb2010-10-01 13:54:28 -04002235static int nl80211_set_wds_peer(struct sk_buff *skb, struct genl_info *info)
2236{
Johannes Berg43b19952010-10-07 13:10:30 +02002237 struct cfg80211_registered_device *rdev = info->user_ptr[0];
2238 struct net_device *dev = info->user_ptr[1];
2239 struct wireless_dev *wdev = dev->ieee80211_ptr;
Johannes Berg388ac772010-10-07 13:11:09 +02002240 const u8 *bssid;
Bill Jordane8347eb2010-10-01 13:54:28 -04002241
2242 if (!info->attrs[NL80211_ATTR_MAC])
2243 return -EINVAL;
2244
Johannes Berg43b19952010-10-07 13:10:30 +02002245 if (netif_running(dev))
2246 return -EBUSY;
Bill Jordane8347eb2010-10-01 13:54:28 -04002247
Johannes Berg43b19952010-10-07 13:10:30 +02002248 if (!rdev->ops->set_wds_peer)
2249 return -EOPNOTSUPP;
Bill Jordane8347eb2010-10-01 13:54:28 -04002250
Johannes Berg43b19952010-10-07 13:10:30 +02002251 if (wdev->iftype != NL80211_IFTYPE_WDS)
2252 return -EOPNOTSUPP;
Bill Jordane8347eb2010-10-01 13:54:28 -04002253
2254 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Hila Gonene35e4d22012-06-27 17:19:42 +03002255 return rdev_set_wds_peer(rdev, dev, bssid);
Bill Jordane8347eb2010-10-01 13:54:28 -04002256}
2257
Johannes Berg55682962007-09-20 13:09:35 -04002258static int nl80211_set_wiphy(struct sk_buff *skb, struct genl_info *info)
2259{
2260 struct cfg80211_registered_device *rdev;
Johannes Bergf444de02010-05-05 15:25:02 +02002261 struct net_device *netdev = NULL;
2262 struct wireless_dev *wdev;
Bill Jordana1e567c2010-09-10 11:22:32 -04002263 int result = 0, rem_txq_params = 0;
Jouni Malinen31888482008-10-30 16:59:24 +02002264 struct nlattr *nl_txq_params;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002265 u32 changed;
2266 u8 retry_short = 0, retry_long = 0;
2267 u32 frag_threshold = 0, rts_threshold = 0;
Lukáš Turek81077e82009-12-21 22:50:47 +01002268 u8 coverage_class = 0;
Johannes Berg55682962007-09-20 13:09:35 -04002269
Johannes Berg5fe231e2013-05-08 21:45:15 +02002270 ASSERT_RTNL();
2271
Johannes Bergf444de02010-05-05 15:25:02 +02002272 /*
2273 * Try to find the wiphy and netdev. Normally this
2274 * function shouldn't need the netdev, but this is
2275 * done for backward compatibility -- previously
2276 * setting the channel was done per wiphy, but now
2277 * it is per netdev. Previous userland like hostapd
2278 * also passed a netdev to set_wiphy, so that it is
2279 * possible to let that go to the right netdev!
2280 */
Johannes Berg4bbf4d52009-03-24 09:35:46 +01002281
Johannes Bergf444de02010-05-05 15:25:02 +02002282 if (info->attrs[NL80211_ATTR_IFINDEX]) {
2283 int ifindex = nla_get_u32(info->attrs[NL80211_ATTR_IFINDEX]);
2284
Ying Xue7f2b8562014-01-15 10:23:45 +08002285 netdev = __dev_get_by_index(genl_info_net(info), ifindex);
Johannes Berg5fe231e2013-05-08 21:45:15 +02002286 if (netdev && netdev->ieee80211_ptr)
Zhao, Gangf26cbf42014-04-21 12:53:03 +08002287 rdev = wiphy_to_rdev(netdev->ieee80211_ptr->wiphy);
Johannes Berg5fe231e2013-05-08 21:45:15 +02002288 else
Johannes Bergf444de02010-05-05 15:25:02 +02002289 netdev = NULL;
Johannes Berg4bbf4d52009-03-24 09:35:46 +01002290 }
2291
Johannes Bergf444de02010-05-05 15:25:02 +02002292 if (!netdev) {
Johannes Berg878d9ec2012-06-15 14:18:32 +02002293 rdev = __cfg80211_rdev_from_attrs(genl_info_net(info),
2294 info->attrs);
Johannes Berg5fe231e2013-05-08 21:45:15 +02002295 if (IS_ERR(rdev))
Johannes Berg4c476992010-10-04 21:36:35 +02002296 return PTR_ERR(rdev);
Johannes Bergf444de02010-05-05 15:25:02 +02002297 wdev = NULL;
2298 netdev = NULL;
2299 result = 0;
Johannes Berg71fe96b2012-10-24 10:04:58 +02002300 } else
Johannes Bergf444de02010-05-05 15:25:02 +02002301 wdev = netdev->ieee80211_ptr;
Johannes Bergf444de02010-05-05 15:25:02 +02002302
2303 /*
2304 * end workaround code, by now the rdev is available
2305 * and locked, and wdev may or may not be NULL.
2306 */
Johannes Berg4bbf4d52009-03-24 09:35:46 +01002307
2308 if (info->attrs[NL80211_ATTR_WIPHY_NAME])
Jouni Malinen31888482008-10-30 16:59:24 +02002309 result = cfg80211_dev_rename(
2310 rdev, nla_data(info->attrs[NL80211_ATTR_WIPHY_NAME]));
Johannes Berg4bbf4d52009-03-24 09:35:46 +01002311
Johannes Berg4bbf4d52009-03-24 09:35:46 +01002312 if (result)
Ying Xue7f2b8562014-01-15 10:23:45 +08002313 return result;
Johannes Berg55682962007-09-20 13:09:35 -04002314
Jouni Malinen31888482008-10-30 16:59:24 +02002315 if (info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS]) {
2316 struct ieee80211_txq_params txq_params;
2317 struct nlattr *tb[NL80211_TXQ_ATTR_MAX + 1];
2318
Ying Xue7f2b8562014-01-15 10:23:45 +08002319 if (!rdev->ops->set_txq_params)
2320 return -EOPNOTSUPP;
Jouni Malinen31888482008-10-30 16:59:24 +02002321
Ying Xue7f2b8562014-01-15 10:23:45 +08002322 if (!netdev)
2323 return -EINVAL;
Eliad Pellerf70f01c2011-09-25 20:06:53 +03002324
Johannes Berg133a3ff2011-11-03 14:50:13 +01002325 if (netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
Ying Xue7f2b8562014-01-15 10:23:45 +08002326 netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
2327 return -EINVAL;
Johannes Berg133a3ff2011-11-03 14:50:13 +01002328
Ying Xue7f2b8562014-01-15 10:23:45 +08002329 if (!netif_running(netdev))
2330 return -ENETDOWN;
Johannes Berg2b5f8b02012-04-02 10:51:55 +02002331
Jouni Malinen31888482008-10-30 16:59:24 +02002332 nla_for_each_nested(nl_txq_params,
2333 info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS],
2334 rem_txq_params) {
Johannes Bergbfe2c7b2016-10-26 14:42:21 +02002335 result = nla_parse_nested(tb, NL80211_TXQ_ATTR_MAX,
2336 nl_txq_params,
Johannes Bergfe521452017-04-12 14:34:08 +02002337 txq_params_policy,
2338 info->extack);
Johannes Bergae811e22014-01-24 10:17:47 +01002339 if (result)
2340 return result;
Jouni Malinen31888482008-10-30 16:59:24 +02002341 result = parse_txq_params(tb, &txq_params);
2342 if (result)
Ying Xue7f2b8562014-01-15 10:23:45 +08002343 return result;
Jouni Malinen31888482008-10-30 16:59:24 +02002344
Hila Gonene35e4d22012-06-27 17:19:42 +03002345 result = rdev_set_txq_params(rdev, netdev,
2346 &txq_params);
Jouni Malinen31888482008-10-30 16:59:24 +02002347 if (result)
Ying Xue7f2b8562014-01-15 10:23:45 +08002348 return result;
Jouni Malinen31888482008-10-30 16:59:24 +02002349 }
2350 }
2351
Jouni Malinen72bdcf32008-11-26 16:15:24 +02002352 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
Jouni Malinene16821b2014-04-28 11:22:08 +03002353 result = __nl80211_set_channel(
2354 rdev,
2355 nl80211_can_set_dev_channel(wdev) ? netdev : NULL,
2356 info);
Jouni Malinen72bdcf32008-11-26 16:15:24 +02002357 if (result)
Ying Xue7f2b8562014-01-15 10:23:45 +08002358 return result;
Jouni Malinen72bdcf32008-11-26 16:15:24 +02002359 }
2360
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03002361 if (info->attrs[NL80211_ATTR_WIPHY_TX_POWER_SETTING]) {
Johannes Bergc8442112012-10-24 10:17:18 +02002362 struct wireless_dev *txp_wdev = wdev;
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03002363 enum nl80211_tx_power_setting type;
2364 int idx, mbm = 0;
2365
Johannes Bergc8442112012-10-24 10:17:18 +02002366 if (!(rdev->wiphy.features & NL80211_FEATURE_VIF_TXPOWER))
2367 txp_wdev = NULL;
2368
Ying Xue7f2b8562014-01-15 10:23:45 +08002369 if (!rdev->ops->set_tx_power)
2370 return -EOPNOTSUPP;
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03002371
2372 idx = NL80211_ATTR_WIPHY_TX_POWER_SETTING;
2373 type = nla_get_u32(info->attrs[idx]);
2374
2375 if (!info->attrs[NL80211_ATTR_WIPHY_TX_POWER_LEVEL] &&
Ying Xue7f2b8562014-01-15 10:23:45 +08002376 (type != NL80211_TX_POWER_AUTOMATIC))
2377 return -EINVAL;
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03002378
2379 if (type != NL80211_TX_POWER_AUTOMATIC) {
2380 idx = NL80211_ATTR_WIPHY_TX_POWER_LEVEL;
2381 mbm = nla_get_u32(info->attrs[idx]);
2382 }
2383
Johannes Bergc8442112012-10-24 10:17:18 +02002384 result = rdev_set_tx_power(rdev, txp_wdev, type, mbm);
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03002385 if (result)
Ying Xue7f2b8562014-01-15 10:23:45 +08002386 return result;
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03002387 }
2388
Bruno Randolfafe0cbf2010-11-10 12:50:50 +09002389 if (info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX] &&
2390 info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]) {
2391 u32 tx_ant, rx_ant;
Kirtika Ruchandani7a087e72016-05-29 19:51:23 -07002392
Bruno Randolf7f531e02010-12-16 11:30:22 +09002393 if ((!rdev->wiphy.available_antennas_tx &&
2394 !rdev->wiphy.available_antennas_rx) ||
Ying Xue7f2b8562014-01-15 10:23:45 +08002395 !rdev->ops->set_antenna)
2396 return -EOPNOTSUPP;
Bruno Randolfafe0cbf2010-11-10 12:50:50 +09002397
2398 tx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX]);
2399 rx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]);
2400
Bruno Randolfa7ffac92010-12-08 13:59:24 +09002401 /* reject antenna configurations which don't match the
Bruno Randolf7f531e02010-12-16 11:30:22 +09002402 * available antenna masks, except for the "all" mask */
2403 if ((~tx_ant && (tx_ant & ~rdev->wiphy.available_antennas_tx)) ||
Ying Xue7f2b8562014-01-15 10:23:45 +08002404 (~rx_ant && (rx_ant & ~rdev->wiphy.available_antennas_rx)))
2405 return -EINVAL;
Bruno Randolfa7ffac92010-12-08 13:59:24 +09002406
Bruno Randolf7f531e02010-12-16 11:30:22 +09002407 tx_ant = tx_ant & rdev->wiphy.available_antennas_tx;
2408 rx_ant = rx_ant & rdev->wiphy.available_antennas_rx;
Bruno Randolfa7ffac92010-12-08 13:59:24 +09002409
Hila Gonene35e4d22012-06-27 17:19:42 +03002410 result = rdev_set_antenna(rdev, tx_ant, rx_ant);
Bruno Randolfafe0cbf2010-11-10 12:50:50 +09002411 if (result)
Ying Xue7f2b8562014-01-15 10:23:45 +08002412 return result;
Bruno Randolfafe0cbf2010-11-10 12:50:50 +09002413 }
2414
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002415 changed = 0;
2416
2417 if (info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]) {
2418 retry_short = nla_get_u8(
2419 info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]);
Ying Xue7f2b8562014-01-15 10:23:45 +08002420 if (retry_short == 0)
2421 return -EINVAL;
2422
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002423 changed |= WIPHY_PARAM_RETRY_SHORT;
2424 }
2425
2426 if (info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]) {
2427 retry_long = nla_get_u8(
2428 info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]);
Ying Xue7f2b8562014-01-15 10:23:45 +08002429 if (retry_long == 0)
2430 return -EINVAL;
2431
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002432 changed |= WIPHY_PARAM_RETRY_LONG;
2433 }
2434
2435 if (info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]) {
2436 frag_threshold = nla_get_u32(
2437 info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]);
Ying Xue7f2b8562014-01-15 10:23:45 +08002438 if (frag_threshold < 256)
2439 return -EINVAL;
2440
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002441 if (frag_threshold != (u32) -1) {
2442 /*
2443 * Fragments (apart from the last one) are required to
2444 * have even length. Make the fragmentation code
2445 * simpler by stripping LSB should someone try to use
2446 * odd threshold value.
2447 */
2448 frag_threshold &= ~0x1;
2449 }
2450 changed |= WIPHY_PARAM_FRAG_THRESHOLD;
2451 }
2452
2453 if (info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]) {
2454 rts_threshold = nla_get_u32(
2455 info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]);
2456 changed |= WIPHY_PARAM_RTS_THRESHOLD;
2457 }
2458
Lukáš Turek81077e82009-12-21 22:50:47 +01002459 if (info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]) {
Lorenzo Bianconi3057dbf2014-09-04 23:57:40 +02002460 if (info->attrs[NL80211_ATTR_WIPHY_DYN_ACK])
2461 return -EINVAL;
2462
Lukáš Turek81077e82009-12-21 22:50:47 +01002463 coverage_class = nla_get_u8(
2464 info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]);
2465 changed |= WIPHY_PARAM_COVERAGE_CLASS;
2466 }
2467
Lorenzo Bianconi3057dbf2014-09-04 23:57:40 +02002468 if (info->attrs[NL80211_ATTR_WIPHY_DYN_ACK]) {
2469 if (!(rdev->wiphy.features & NL80211_FEATURE_ACKTO_ESTIMATION))
2470 return -EOPNOTSUPP;
2471
2472 changed |= WIPHY_PARAM_DYN_ACK;
2473 }
2474
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002475 if (changed) {
2476 u8 old_retry_short, old_retry_long;
2477 u32 old_frag_threshold, old_rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01002478 u8 old_coverage_class;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002479
Ying Xue7f2b8562014-01-15 10:23:45 +08002480 if (!rdev->ops->set_wiphy_params)
2481 return -EOPNOTSUPP;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002482
2483 old_retry_short = rdev->wiphy.retry_short;
2484 old_retry_long = rdev->wiphy.retry_long;
2485 old_frag_threshold = rdev->wiphy.frag_threshold;
2486 old_rts_threshold = rdev->wiphy.rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01002487 old_coverage_class = rdev->wiphy.coverage_class;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002488
2489 if (changed & WIPHY_PARAM_RETRY_SHORT)
2490 rdev->wiphy.retry_short = retry_short;
2491 if (changed & WIPHY_PARAM_RETRY_LONG)
2492 rdev->wiphy.retry_long = retry_long;
2493 if (changed & WIPHY_PARAM_FRAG_THRESHOLD)
2494 rdev->wiphy.frag_threshold = frag_threshold;
2495 if (changed & WIPHY_PARAM_RTS_THRESHOLD)
2496 rdev->wiphy.rts_threshold = rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01002497 if (changed & WIPHY_PARAM_COVERAGE_CLASS)
2498 rdev->wiphy.coverage_class = coverage_class;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002499
Hila Gonene35e4d22012-06-27 17:19:42 +03002500 result = rdev_set_wiphy_params(rdev, changed);
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002501 if (result) {
2502 rdev->wiphy.retry_short = old_retry_short;
2503 rdev->wiphy.retry_long = old_retry_long;
2504 rdev->wiphy.frag_threshold = old_frag_threshold;
2505 rdev->wiphy.rts_threshold = old_rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01002506 rdev->wiphy.coverage_class = old_coverage_class;
Michal Kazior9189ee32015-08-03 10:55:24 +02002507 return result;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002508 }
2509 }
Ying Xue7f2b8562014-01-15 10:23:45 +08002510 return 0;
Johannes Berg55682962007-09-20 13:09:35 -04002511}
2512
Johannes Berg71bbc992012-06-15 15:30:18 +02002513static inline u64 wdev_id(struct wireless_dev *wdev)
2514{
2515 return (u64)wdev->identifier |
Zhao, Gangf26cbf42014-04-21 12:53:03 +08002516 ((u64)wiphy_to_rdev(wdev->wiphy)->wiphy_idx << 32);
Johannes Berg71bbc992012-06-15 15:30:18 +02002517}
Johannes Berg55682962007-09-20 13:09:35 -04002518
Johannes Berg683b6d32012-11-08 21:25:48 +01002519static int nl80211_send_chandef(struct sk_buff *msg,
Janusz Dziedzicd2859df2013-11-06 13:55:51 +01002520 const struct cfg80211_chan_def *chandef)
Johannes Berg683b6d32012-11-08 21:25:48 +01002521{
Johannes Berg601555c2014-11-27 17:26:56 +01002522 if (WARN_ON(!cfg80211_chandef_valid(chandef)))
2523 return -EINVAL;
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002524
Johannes Berg683b6d32012-11-08 21:25:48 +01002525 if (nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ,
2526 chandef->chan->center_freq))
2527 return -ENOBUFS;
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002528 switch (chandef->width) {
2529 case NL80211_CHAN_WIDTH_20_NOHT:
2530 case NL80211_CHAN_WIDTH_20:
2531 case NL80211_CHAN_WIDTH_40:
2532 if (nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE,
2533 cfg80211_get_chandef_type(chandef)))
2534 return -ENOBUFS;
2535 break;
2536 default:
2537 break;
2538 }
2539 if (nla_put_u32(msg, NL80211_ATTR_CHANNEL_WIDTH, chandef->width))
2540 return -ENOBUFS;
2541 if (nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ1, chandef->center_freq1))
2542 return -ENOBUFS;
2543 if (chandef->center_freq2 &&
2544 nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ2, chandef->center_freq2))
Johannes Berg683b6d32012-11-08 21:25:48 +01002545 return -ENOBUFS;
2546 return 0;
2547}
2548
Eric W. Biederman15e47302012-09-07 20:12:54 +00002549static int nl80211_send_iface(struct sk_buff *msg, u32 portid, u32 seq, int flags,
Johannes Bergd7264052009-04-19 16:23:20 +02002550 struct cfg80211_registered_device *rdev,
Tomasz Bursztyka8f894be2014-11-12 16:26:45 +02002551 struct wireless_dev *wdev, bool removal)
Johannes Berg55682962007-09-20 13:09:35 -04002552{
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002553 struct net_device *dev = wdev->netdev;
Tomasz Bursztyka8f894be2014-11-12 16:26:45 +02002554 u8 cmd = NL80211_CMD_NEW_INTERFACE;
Johannes Berg55682962007-09-20 13:09:35 -04002555 void *hdr;
2556
Tomasz Bursztyka8f894be2014-11-12 16:26:45 +02002557 if (removal)
2558 cmd = NL80211_CMD_DEL_INTERFACE;
2559
2560 hdr = nl80211hdr_put(msg, portid, seq, flags, cmd);
Johannes Berg55682962007-09-20 13:09:35 -04002561 if (!hdr)
2562 return -1;
2563
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002564 if (dev &&
2565 (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
Johannes Berg98104fde2012-06-16 00:19:54 +02002566 nla_put_string(msg, NL80211_ATTR_IFNAME, dev->name)))
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002567 goto nla_put_failure;
2568
2569 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
2570 nla_put_u32(msg, NL80211_ATTR_IFTYPE, wdev->iftype) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02002571 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
2572 NL80211_ATTR_PAD) ||
Johannes Berg98104fde2012-06-16 00:19:54 +02002573 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, wdev_address(wdev)) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04002574 nla_put_u32(msg, NL80211_ATTR_GENERATION,
2575 rdev->devlist_generation ^
2576 (cfg80211_rdev_list_generation << 2)))
2577 goto nla_put_failure;
Johannes Bergf5ea9122009-08-07 16:17:38 +02002578
Johannes Berg5b7ccaf2012-07-12 19:45:08 +02002579 if (rdev->ops->get_channel) {
Johannes Berg683b6d32012-11-08 21:25:48 +01002580 int ret;
2581 struct cfg80211_chan_def chandef;
Johannes Berg5b7ccaf2012-07-12 19:45:08 +02002582
Johannes Berg683b6d32012-11-08 21:25:48 +01002583 ret = rdev_get_channel(rdev, wdev, &chandef);
2584 if (ret == 0) {
2585 if (nl80211_send_chandef(msg, &chandef))
2586 goto nla_put_failure;
2587 }
Pontus Fuchsd91df0e2012-04-03 16:39:58 +02002588 }
2589
Rafał Miłeckid55d0d52015-08-31 22:59:38 +02002590 if (rdev->ops->get_tx_power) {
2591 int dbm, ret;
2592
2593 ret = rdev_get_tx_power(rdev, wdev, &dbm);
2594 if (ret == 0 &&
2595 nla_put_u32(msg, NL80211_ATTR_WIPHY_TX_POWER_LEVEL,
2596 DBM_TO_MBM(dbm)))
2597 goto nla_put_failure;
2598 }
2599
Antonio Quartullib84e7a02012-11-07 12:52:20 +01002600 if (wdev->ssid_len) {
2601 if (nla_put(msg, NL80211_ATTR_SSID, wdev->ssid_len, wdev->ssid))
2602 goto nla_put_failure;
2603 }
2604
Johannes Berg053c0952015-01-16 22:09:00 +01002605 genlmsg_end(msg, hdr);
2606 return 0;
Johannes Berg55682962007-09-20 13:09:35 -04002607
2608 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07002609 genlmsg_cancel(msg, hdr);
2610 return -EMSGSIZE;
Johannes Berg55682962007-09-20 13:09:35 -04002611}
2612
2613static int nl80211_dump_interface(struct sk_buff *skb, struct netlink_callback *cb)
2614{
2615 int wp_idx = 0;
2616 int if_idx = 0;
2617 int wp_start = cb->args[0];
2618 int if_start = cb->args[1];
Denis Kenziorb7fb44d2016-08-03 17:02:15 -05002619 int filter_wiphy = -1;
Johannes Bergf5ea9122009-08-07 16:17:38 +02002620 struct cfg80211_registered_device *rdev;
Johannes Berg55682962007-09-20 13:09:35 -04002621 struct wireless_dev *wdev;
Johannes Bergea90e0d2017-03-15 14:26:04 +01002622 int ret;
Johannes Berg55682962007-09-20 13:09:35 -04002623
Johannes Berg5fe231e2013-05-08 21:45:15 +02002624 rtnl_lock();
Denis Kenziorb7fb44d2016-08-03 17:02:15 -05002625 if (!cb->args[2]) {
2626 struct nl80211_dump_wiphy_state state = {
2627 .filter_wiphy = -1,
2628 };
Denis Kenziorb7fb44d2016-08-03 17:02:15 -05002629
2630 ret = nl80211_dump_wiphy_parse(skb, cb, &state);
2631 if (ret)
Johannes Bergea90e0d2017-03-15 14:26:04 +01002632 goto out_unlock;
Denis Kenziorb7fb44d2016-08-03 17:02:15 -05002633
2634 filter_wiphy = state.filter_wiphy;
2635
2636 /*
2637 * if filtering, set cb->args[2] to +1 since 0 is the default
2638 * value needed to determine that parsing is necessary.
2639 */
2640 if (filter_wiphy >= 0)
2641 cb->args[2] = filter_wiphy + 1;
2642 else
2643 cb->args[2] = -1;
2644 } else if (cb->args[2] > 0) {
2645 filter_wiphy = cb->args[2] - 1;
2646 }
2647
Johannes Bergf5ea9122009-08-07 16:17:38 +02002648 list_for_each_entry(rdev, &cfg80211_rdev_list, list) {
2649 if (!net_eq(wiphy_net(&rdev->wiphy), sock_net(skb->sk)))
Johannes Berg463d0182009-07-14 00:33:35 +02002650 continue;
Johannes Bergbba95fe2008-07-29 13:22:51 +02002651 if (wp_idx < wp_start) {
2652 wp_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04002653 continue;
Johannes Bergbba95fe2008-07-29 13:22:51 +02002654 }
Denis Kenziorb7fb44d2016-08-03 17:02:15 -05002655
2656 if (filter_wiphy >= 0 && filter_wiphy != rdev->wiphy_idx)
2657 continue;
2658
Johannes Berg55682962007-09-20 13:09:35 -04002659 if_idx = 0;
2660
Johannes Berg53873f12016-05-03 16:52:04 +03002661 list_for_each_entry(wdev, &rdev->wiphy.wdev_list, list) {
Johannes Bergbba95fe2008-07-29 13:22:51 +02002662 if (if_idx < if_start) {
2663 if_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04002664 continue;
Johannes Bergbba95fe2008-07-29 13:22:51 +02002665 }
Eric W. Biederman15e47302012-09-07 20:12:54 +00002666 if (nl80211_send_iface(skb, NETLINK_CB(cb->skb).portid,
Johannes Berg55682962007-09-20 13:09:35 -04002667 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Tomasz Bursztyka8f894be2014-11-12 16:26:45 +02002668 rdev, wdev, false) < 0) {
Johannes Bergbba95fe2008-07-29 13:22:51 +02002669 goto out;
2670 }
2671 if_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04002672 }
Johannes Bergbba95fe2008-07-29 13:22:51 +02002673
2674 wp_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04002675 }
Johannes Bergbba95fe2008-07-29 13:22:51 +02002676 out:
Johannes Berg55682962007-09-20 13:09:35 -04002677 cb->args[0] = wp_idx;
2678 cb->args[1] = if_idx;
2679
Johannes Bergea90e0d2017-03-15 14:26:04 +01002680 ret = skb->len;
2681 out_unlock:
2682 rtnl_unlock();
2683
2684 return ret;
Johannes Berg55682962007-09-20 13:09:35 -04002685}
2686
2687static int nl80211_get_interface(struct sk_buff *skb, struct genl_info *info)
2688{
2689 struct sk_buff *msg;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002690 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002691 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg55682962007-09-20 13:09:35 -04002692
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07002693 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -04002694 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02002695 return -ENOMEM;
Johannes Berg55682962007-09-20 13:09:35 -04002696
Eric W. Biederman15e47302012-09-07 20:12:54 +00002697 if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0,
Tomasz Bursztyka8f894be2014-11-12 16:26:45 +02002698 rdev, wdev, false) < 0) {
Johannes Berg4c476992010-10-04 21:36:35 +02002699 nlmsg_free(msg);
2700 return -ENOBUFS;
2701 }
Johannes Berg55682962007-09-20 13:09:35 -04002702
Johannes Berg134e6372009-07-10 09:51:34 +00002703 return genlmsg_reply(msg, info);
Johannes Berg55682962007-09-20 13:09:35 -04002704}
2705
Michael Wu66f7ac52008-01-31 19:48:22 +01002706static const struct nla_policy mntr_flags_policy[NL80211_MNTR_FLAG_MAX + 1] = {
2707 [NL80211_MNTR_FLAG_FCSFAIL] = { .type = NLA_FLAG },
2708 [NL80211_MNTR_FLAG_PLCPFAIL] = { .type = NLA_FLAG },
2709 [NL80211_MNTR_FLAG_CONTROL] = { .type = NLA_FLAG },
2710 [NL80211_MNTR_FLAG_OTHER_BSS] = { .type = NLA_FLAG },
2711 [NL80211_MNTR_FLAG_COOK_FRAMES] = { .type = NLA_FLAG },
Felix Fietkaue057d3c2013-05-28 13:01:52 +02002712 [NL80211_MNTR_FLAG_ACTIVE] = { .type = NLA_FLAG },
Michael Wu66f7ac52008-01-31 19:48:22 +01002713};
2714
2715static int parse_monitor_flags(struct nlattr *nla, u32 *mntrflags)
2716{
2717 struct nlattr *flags[NL80211_MNTR_FLAG_MAX + 1];
2718 int flag;
2719
2720 *mntrflags = 0;
2721
2722 if (!nla)
2723 return -EINVAL;
2724
Johannes Bergfceb6432017-04-12 14:34:07 +02002725 if (nla_parse_nested(flags, NL80211_MNTR_FLAG_MAX, nla,
2726 mntr_flags_policy, NULL))
Michael Wu66f7ac52008-01-31 19:48:22 +01002727 return -EINVAL;
2728
2729 for (flag = 1; flag <= NL80211_MNTR_FLAG_MAX; flag++)
2730 if (flags[flag])
2731 *mntrflags |= (1<<flag);
2732
Johannes Berg818a9862017-04-12 11:23:28 +02002733 *mntrflags |= MONITOR_FLAG_CHANGED;
2734
Michael Wu66f7ac52008-01-31 19:48:22 +01002735 return 0;
2736}
2737
Johannes Berg1db77592017-04-12 11:36:31 +02002738static int nl80211_parse_mon_options(struct cfg80211_registered_device *rdev,
2739 enum nl80211_iftype type,
2740 struct genl_info *info,
2741 struct vif_params *params)
2742{
2743 bool change = false;
2744 int err;
2745
2746 if (info->attrs[NL80211_ATTR_MNTR_FLAGS]) {
2747 if (type != NL80211_IFTYPE_MONITOR)
2748 return -EINVAL;
2749
2750 err = parse_monitor_flags(info->attrs[NL80211_ATTR_MNTR_FLAGS],
2751 &params->flags);
2752 if (err)
2753 return err;
2754
2755 change = true;
2756 }
2757
2758 if (params->flags & MONITOR_FLAG_ACTIVE &&
2759 !(rdev->wiphy.features & NL80211_FEATURE_ACTIVE_MONITOR))
2760 return -EOPNOTSUPP;
2761
2762 if (info->attrs[NL80211_ATTR_MU_MIMO_GROUP_DATA]) {
2763 const u8 *mumimo_groups;
2764 u32 cap_flag = NL80211_EXT_FEATURE_MU_MIMO_AIR_SNIFFER;
2765
2766 if (type != NL80211_IFTYPE_MONITOR)
2767 return -EINVAL;
2768
2769 if (!wiphy_ext_feature_isset(&rdev->wiphy, cap_flag))
2770 return -EOPNOTSUPP;
2771
2772 mumimo_groups =
2773 nla_data(info->attrs[NL80211_ATTR_MU_MIMO_GROUP_DATA]);
2774
2775 /* bits 0 and 63 are reserved and must be zero */
Johannes Berg49546012017-04-27 09:13:38 +02002776 if ((mumimo_groups[0] & BIT(0)) ||
2777 (mumimo_groups[VHT_MUMIMO_GROUPS_DATA_LEN - 1] & BIT(7)))
Johannes Berg1db77592017-04-12 11:36:31 +02002778 return -EINVAL;
2779
2780 params->vht_mumimo_groups = mumimo_groups;
2781 change = true;
2782 }
2783
2784 if (info->attrs[NL80211_ATTR_MU_MIMO_FOLLOW_MAC_ADDR]) {
2785 u32 cap_flag = NL80211_EXT_FEATURE_MU_MIMO_AIR_SNIFFER;
2786
2787 if (type != NL80211_IFTYPE_MONITOR)
2788 return -EINVAL;
2789
2790 if (!wiphy_ext_feature_isset(&rdev->wiphy, cap_flag))
2791 return -EOPNOTSUPP;
2792
2793 params->vht_mumimo_follow_addr =
2794 nla_data(info->attrs[NL80211_ATTR_MU_MIMO_FOLLOW_MAC_ADDR]);
2795 change = true;
2796 }
2797
2798 return change ? 1 : 0;
2799}
2800
Johannes Berg9bc383d2009-11-19 11:55:19 +01002801static int nl80211_valid_4addr(struct cfg80211_registered_device *rdev,
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002802 struct net_device *netdev, u8 use_4addr,
2803 enum nl80211_iftype iftype)
Johannes Berg9bc383d2009-11-19 11:55:19 +01002804{
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002805 if (!use_4addr) {
Jiri Pirkof350a0a82010-06-15 06:50:45 +00002806 if (netdev && (netdev->priv_flags & IFF_BRIDGE_PORT))
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002807 return -EBUSY;
Johannes Berg9bc383d2009-11-19 11:55:19 +01002808 return 0;
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002809 }
Johannes Berg9bc383d2009-11-19 11:55:19 +01002810
2811 switch (iftype) {
2812 case NL80211_IFTYPE_AP_VLAN:
2813 if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_AP)
2814 return 0;
2815 break;
2816 case NL80211_IFTYPE_STATION:
2817 if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_STATION)
2818 return 0;
2819 break;
2820 default:
2821 break;
2822 }
2823
2824 return -EOPNOTSUPP;
2825}
2826
Johannes Berg55682962007-09-20 13:09:35 -04002827static int nl80211_set_interface(struct sk_buff *skb, struct genl_info *info)
2828{
Johannes Berg4c476992010-10-04 21:36:35 +02002829 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002830 struct vif_params params;
Johannes Berge36d56b2009-06-09 21:04:43 +02002831 int err;
Johannes Berg04a773a2009-04-19 21:24:32 +02002832 enum nl80211_iftype otype, ntype;
Johannes Berg4c476992010-10-04 21:36:35 +02002833 struct net_device *dev = info->user_ptr[1];
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002834 bool change = false;
Johannes Berg55682962007-09-20 13:09:35 -04002835
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002836 memset(&params, 0, sizeof(params));
2837
Johannes Berg04a773a2009-04-19 21:24:32 +02002838 otype = ntype = dev->ieee80211_ptr->iftype;
Johannes Berg55682962007-09-20 13:09:35 -04002839
Johannes Berg723b0382008-09-16 20:22:09 +02002840 if (info->attrs[NL80211_ATTR_IFTYPE]) {
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002841 ntype = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]);
Johannes Berg04a773a2009-04-19 21:24:32 +02002842 if (otype != ntype)
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002843 change = true;
Johannes Berg4c476992010-10-04 21:36:35 +02002844 if (ntype > NL80211_IFTYPE_MAX)
2845 return -EINVAL;
Johannes Berg723b0382008-09-16 20:22:09 +02002846 }
2847
Johannes Berg92ffe052008-09-16 20:39:36 +02002848 if (info->attrs[NL80211_ATTR_MESH_ID]) {
Johannes Berg29cbe682010-12-03 09:20:44 +01002849 struct wireless_dev *wdev = dev->ieee80211_ptr;
2850
Johannes Berg4c476992010-10-04 21:36:35 +02002851 if (ntype != NL80211_IFTYPE_MESH_POINT)
2852 return -EINVAL;
Johannes Berg29cbe682010-12-03 09:20:44 +01002853 if (netif_running(dev))
2854 return -EBUSY;
2855
2856 wdev_lock(wdev);
2857 BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN !=
2858 IEEE80211_MAX_MESH_ID_LEN);
2859 wdev->mesh_id_up_len =
2860 nla_len(info->attrs[NL80211_ATTR_MESH_ID]);
2861 memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]),
2862 wdev->mesh_id_up_len);
2863 wdev_unlock(wdev);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002864 }
2865
Felix Fietkau8b787642009-11-10 18:53:10 +01002866 if (info->attrs[NL80211_ATTR_4ADDR]) {
2867 params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]);
2868 change = true;
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002869 err = nl80211_valid_4addr(rdev, dev, params.use_4addr, ntype);
Johannes Berg9bc383d2009-11-19 11:55:19 +01002870 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02002871 return err;
Felix Fietkau8b787642009-11-10 18:53:10 +01002872 } else {
2873 params.use_4addr = -1;
2874 }
2875
Johannes Berg1db77592017-04-12 11:36:31 +02002876 err = nl80211_parse_mon_options(rdev, ntype, info, &params);
2877 if (err < 0)
2878 return err;
2879 if (err > 0)
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002880 change = true;
Felix Fietkaue057d3c2013-05-28 13:01:52 +02002881
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002882 if (change)
Johannes Berg818a9862017-04-12 11:23:28 +02002883 err = cfg80211_change_iface(rdev, dev, ntype, &params);
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002884 else
2885 err = 0;
Johannes Berg60719ff2008-09-16 14:55:09 +02002886
Johannes Berg9bc383d2009-11-19 11:55:19 +01002887 if (!err && params.use_4addr != -1)
2888 dev->ieee80211_ptr->use_4addr = params.use_4addr;
2889
Johannes Berg55682962007-09-20 13:09:35 -04002890 return err;
2891}
2892
2893static int nl80211_new_interface(struct sk_buff *skb, struct genl_info *info)
2894{
Johannes Berg4c476992010-10-04 21:36:35 +02002895 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002896 struct vif_params params;
Johannes Berg84efbb82012-06-16 00:00:26 +02002897 struct wireless_dev *wdev;
Denis Kenzior896ff062016-08-03 16:58:33 -05002898 struct sk_buff *msg;
Johannes Berg55682962007-09-20 13:09:35 -04002899 int err;
2900 enum nl80211_iftype type = NL80211_IFTYPE_UNSPECIFIED;
2901
Johannes Berg78f22b62014-03-24 17:57:27 +01002902 /* to avoid failing a new interface creation due to pending removal */
2903 cfg80211_destroy_ifaces(rdev);
2904
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002905 memset(&params, 0, sizeof(params));
2906
Johannes Berg55682962007-09-20 13:09:35 -04002907 if (!info->attrs[NL80211_ATTR_IFNAME])
2908 return -EINVAL;
2909
2910 if (info->attrs[NL80211_ATTR_IFTYPE]) {
2911 type = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]);
2912 if (type > NL80211_IFTYPE_MAX)
2913 return -EINVAL;
2914 }
2915
Johannes Berg79c97e92009-07-07 03:56:12 +02002916 if (!rdev->ops->add_virtual_intf ||
Johannes Berg4c476992010-10-04 21:36:35 +02002917 !(rdev->wiphy.interface_modes & (1 << type)))
2918 return -EOPNOTSUPP;
Johannes Berg55682962007-09-20 13:09:35 -04002919
Ayala Bekercb3b7d82016-09-20 17:31:13 +03002920 if ((type == NL80211_IFTYPE_P2P_DEVICE || type == NL80211_IFTYPE_NAN ||
Ben Greeare8f479b2014-10-22 12:23:05 -07002921 rdev->wiphy.features & NL80211_FEATURE_MAC_ON_CREATE) &&
2922 info->attrs[NL80211_ATTR_MAC]) {
Arend van Spriel1c18f142013-01-08 10:17:27 +01002923 nla_memcpy(params.macaddr, info->attrs[NL80211_ATTR_MAC],
2924 ETH_ALEN);
2925 if (!is_valid_ether_addr(params.macaddr))
2926 return -EADDRNOTAVAIL;
2927 }
2928
Johannes Berg9bc383d2009-11-19 11:55:19 +01002929 if (info->attrs[NL80211_ATTR_4ADDR]) {
Felix Fietkau8b787642009-11-10 18:53:10 +01002930 params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]);
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002931 err = nl80211_valid_4addr(rdev, NULL, params.use_4addr, type);
Johannes Berg9bc383d2009-11-19 11:55:19 +01002932 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02002933 return err;
Johannes Berg9bc383d2009-11-19 11:55:19 +01002934 }
Felix Fietkau8b787642009-11-10 18:53:10 +01002935
Johannes Berg1db77592017-04-12 11:36:31 +02002936 err = nl80211_parse_mon_options(rdev, type, info, &params);
2937 if (err < 0)
2938 return err;
Felix Fietkaue057d3c2013-05-28 13:01:52 +02002939
Johannes Berga18c7192015-02-24 10:56:42 +01002940 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
2941 if (!msg)
2942 return -ENOMEM;
2943
Hila Gonene35e4d22012-06-27 17:19:42 +03002944 wdev = rdev_add_virtual_intf(rdev,
2945 nla_data(info->attrs[NL80211_ATTR_IFNAME]),
Johannes Berg818a9862017-04-12 11:23:28 +02002946 NET_NAME_USER, type, &params);
Rafał Miłeckid687cbb2014-11-14 18:43:28 +01002947 if (WARN_ON(!wdev)) {
2948 nlmsg_free(msg);
2949 return -EPROTO;
2950 } else if (IS_ERR(wdev)) {
Johannes Berg1c90f9d2012-06-16 00:05:37 +02002951 nlmsg_free(msg);
Johannes Berg84efbb82012-06-16 00:00:26 +02002952 return PTR_ERR(wdev);
Johannes Berg1c90f9d2012-06-16 00:05:37 +02002953 }
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002954
Jukka Rissanen18e5ca62014-11-13 17:25:14 +02002955 if (info->attrs[NL80211_ATTR_SOCKET_OWNER])
Johannes Berg78f22b62014-03-24 17:57:27 +01002956 wdev->owner_nlportid = info->snd_portid;
2957
Johannes Berg98104fde2012-06-16 00:19:54 +02002958 switch (type) {
2959 case NL80211_IFTYPE_MESH_POINT:
2960 if (!info->attrs[NL80211_ATTR_MESH_ID])
2961 break;
Johannes Berg29cbe682010-12-03 09:20:44 +01002962 wdev_lock(wdev);
2963 BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN !=
2964 IEEE80211_MAX_MESH_ID_LEN);
2965 wdev->mesh_id_up_len =
2966 nla_len(info->attrs[NL80211_ATTR_MESH_ID]);
2967 memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]),
2968 wdev->mesh_id_up_len);
2969 wdev_unlock(wdev);
Johannes Berg98104fde2012-06-16 00:19:54 +02002970 break;
Ayala Bekercb3b7d82016-09-20 17:31:13 +03002971 case NL80211_IFTYPE_NAN:
Johannes Berg98104fde2012-06-16 00:19:54 +02002972 case NL80211_IFTYPE_P2P_DEVICE:
2973 /*
Ayala Bekercb3b7d82016-09-20 17:31:13 +03002974 * P2P Device and NAN do not have a netdev, so don't go
Johannes Berg98104fde2012-06-16 00:19:54 +02002975 * through the netdev notifier and must be added here
2976 */
2977 mutex_init(&wdev->mtx);
2978 INIT_LIST_HEAD(&wdev->event_list);
2979 spin_lock_init(&wdev->event_lock);
2980 INIT_LIST_HEAD(&wdev->mgmt_registrations);
2981 spin_lock_init(&wdev->mgmt_registrations_lock);
2982
Johannes Berg98104fde2012-06-16 00:19:54 +02002983 wdev->identifier = ++rdev->wdev_id;
Johannes Berg53873f12016-05-03 16:52:04 +03002984 list_add_rcu(&wdev->list, &rdev->wiphy.wdev_list);
Johannes Berg98104fde2012-06-16 00:19:54 +02002985 rdev->devlist_generation++;
Johannes Berg98104fde2012-06-16 00:19:54 +02002986 break;
2987 default:
2988 break;
Johannes Berg29cbe682010-12-03 09:20:44 +01002989 }
2990
Eric W. Biederman15e47302012-09-07 20:12:54 +00002991 if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0,
Tomasz Bursztyka8f894be2014-11-12 16:26:45 +02002992 rdev, wdev, false) < 0) {
Johannes Berg1c90f9d2012-06-16 00:05:37 +02002993 nlmsg_free(msg);
2994 return -ENOBUFS;
2995 }
2996
Denis Kenzior896ff062016-08-03 16:58:33 -05002997 /*
2998 * For wdevs which have no associated netdev object (e.g. of type
2999 * NL80211_IFTYPE_P2P_DEVICE), emit the NEW_INTERFACE event here.
3000 * For all other types, the event will be generated from the
3001 * netdev notifier
3002 */
3003 if (!wdev->netdev)
3004 nl80211_notify_iface(rdev, wdev, NL80211_CMD_NEW_INTERFACE);
Tomasz Bursztyka8f894be2014-11-12 16:26:45 +02003005
Johannes Berg1c90f9d2012-06-16 00:05:37 +02003006 return genlmsg_reply(msg, info);
Johannes Berg55682962007-09-20 13:09:35 -04003007}
3008
3009static int nl80211_del_interface(struct sk_buff *skb, struct genl_info *info)
3010{
Johannes Berg4c476992010-10-04 21:36:35 +02003011 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg84efbb82012-06-16 00:00:26 +02003012 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg55682962007-09-20 13:09:35 -04003013
Johannes Berg4c476992010-10-04 21:36:35 +02003014 if (!rdev->ops->del_virtual_intf)
3015 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01003016
Johannes Berg84efbb82012-06-16 00:00:26 +02003017 /*
3018 * If we remove a wireless device without a netdev then clear
3019 * user_ptr[1] so that nl80211_post_doit won't dereference it
3020 * to check if it needs to do dev_put(). Otherwise it crashes
3021 * since the wdev has been freed, unlike with a netdev where
3022 * we need the dev_put() for the netdev to really be freed.
3023 */
3024 if (!wdev->netdev)
3025 info->user_ptr[1] = NULL;
3026
Denis Kenzior7f8ed012016-08-03 16:58:35 -05003027 return rdev_del_virtual_intf(rdev, wdev);
Johannes Berg55682962007-09-20 13:09:35 -04003028}
3029
Simon Wunderlich1d9d9212011-11-18 14:20:43 +01003030static int nl80211_set_noack_map(struct sk_buff *skb, struct genl_info *info)
3031{
3032 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3033 struct net_device *dev = info->user_ptr[1];
3034 u16 noack_map;
3035
3036 if (!info->attrs[NL80211_ATTR_NOACK_MAP])
3037 return -EINVAL;
3038
3039 if (!rdev->ops->set_noack_map)
3040 return -EOPNOTSUPP;
3041
3042 noack_map = nla_get_u16(info->attrs[NL80211_ATTR_NOACK_MAP]);
3043
Hila Gonene35e4d22012-06-27 17:19:42 +03003044 return rdev_set_noack_map(rdev, dev, noack_map);
Simon Wunderlich1d9d9212011-11-18 14:20:43 +01003045}
3046
Johannes Berg41ade002007-12-19 02:03:29 +01003047struct get_key_cookie {
3048 struct sk_buff *msg;
3049 int error;
Johannes Bergb9454e82009-07-08 13:29:08 +02003050 int idx;
Johannes Berg41ade002007-12-19 02:03:29 +01003051};
3052
3053static void get_key_callback(void *c, struct key_params *params)
3054{
Johannes Bergb9454e82009-07-08 13:29:08 +02003055 struct nlattr *key;
Johannes Berg41ade002007-12-19 02:03:29 +01003056 struct get_key_cookie *cookie = c;
3057
David S. Miller9360ffd2012-03-29 04:41:26 -04003058 if ((params->key &&
3059 nla_put(cookie->msg, NL80211_ATTR_KEY_DATA,
3060 params->key_len, params->key)) ||
3061 (params->seq &&
3062 nla_put(cookie->msg, NL80211_ATTR_KEY_SEQ,
3063 params->seq_len, params->seq)) ||
3064 (params->cipher &&
3065 nla_put_u32(cookie->msg, NL80211_ATTR_KEY_CIPHER,
3066 params->cipher)))
3067 goto nla_put_failure;
Johannes Berg41ade002007-12-19 02:03:29 +01003068
Johannes Bergb9454e82009-07-08 13:29:08 +02003069 key = nla_nest_start(cookie->msg, NL80211_ATTR_KEY);
3070 if (!key)
3071 goto nla_put_failure;
3072
David S. Miller9360ffd2012-03-29 04:41:26 -04003073 if ((params->key &&
3074 nla_put(cookie->msg, NL80211_KEY_DATA,
3075 params->key_len, params->key)) ||
3076 (params->seq &&
3077 nla_put(cookie->msg, NL80211_KEY_SEQ,
3078 params->seq_len, params->seq)) ||
3079 (params->cipher &&
3080 nla_put_u32(cookie->msg, NL80211_KEY_CIPHER,
3081 params->cipher)))
3082 goto nla_put_failure;
Johannes Bergb9454e82009-07-08 13:29:08 +02003083
David S. Miller9360ffd2012-03-29 04:41:26 -04003084 if (nla_put_u8(cookie->msg, NL80211_ATTR_KEY_IDX, cookie->idx))
3085 goto nla_put_failure;
Johannes Bergb9454e82009-07-08 13:29:08 +02003086
3087 nla_nest_end(cookie->msg, key);
3088
Johannes Berg41ade002007-12-19 02:03:29 +01003089 return;
3090 nla_put_failure:
3091 cookie->error = 1;
3092}
3093
3094static int nl80211_get_key(struct sk_buff *skb, struct genl_info *info)
3095{
Johannes Berg4c476992010-10-04 21:36:35 +02003096 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg41ade002007-12-19 02:03:29 +01003097 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02003098 struct net_device *dev = info->user_ptr[1];
Johannes Berg41ade002007-12-19 02:03:29 +01003099 u8 key_idx = 0;
Johannes Berge31b8212010-10-05 19:39:30 +02003100 const u8 *mac_addr = NULL;
3101 bool pairwise;
Johannes Berg41ade002007-12-19 02:03:29 +01003102 struct get_key_cookie cookie = {
3103 .error = 0,
3104 };
3105 void *hdr;
3106 struct sk_buff *msg;
3107
3108 if (info->attrs[NL80211_ATTR_KEY_IDX])
3109 key_idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]);
3110
Jouni Malinen3cfcf6ac2009-01-08 13:32:02 +02003111 if (key_idx > 5)
Johannes Berg41ade002007-12-19 02:03:29 +01003112 return -EINVAL;
3113
3114 if (info->attrs[NL80211_ATTR_MAC])
3115 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
3116
Johannes Berge31b8212010-10-05 19:39:30 +02003117 pairwise = !!mac_addr;
3118 if (info->attrs[NL80211_ATTR_KEY_TYPE]) {
3119 u32 kt = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]);
Kirtika Ruchandani7a087e72016-05-29 19:51:23 -07003120
Johannes Berge31b8212010-10-05 19:39:30 +02003121 if (kt >= NUM_NL80211_KEYTYPES)
3122 return -EINVAL;
3123 if (kt != NL80211_KEYTYPE_GROUP &&
3124 kt != NL80211_KEYTYPE_PAIRWISE)
3125 return -EINVAL;
3126 pairwise = kt == NL80211_KEYTYPE_PAIRWISE;
3127 }
3128
Johannes Berg4c476992010-10-04 21:36:35 +02003129 if (!rdev->ops->get_key)
3130 return -EOPNOTSUPP;
Johannes Berg41ade002007-12-19 02:03:29 +01003131
Johannes Berg0fa7b392015-01-23 11:10:12 +01003132 if (!pairwise && mac_addr && !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN))
3133 return -ENOENT;
3134
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07003135 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02003136 if (!msg)
3137 return -ENOMEM;
Johannes Berg41ade002007-12-19 02:03:29 +01003138
Eric W. Biederman15e47302012-09-07 20:12:54 +00003139 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berg41ade002007-12-19 02:03:29 +01003140 NL80211_CMD_NEW_KEY);
Dan Carpentercb35fba2013-08-14 14:50:01 +03003141 if (!hdr)
Johannes Berg9fe271a2013-10-25 11:15:12 +02003142 goto nla_put_failure;
Johannes Berg41ade002007-12-19 02:03:29 +01003143
3144 cookie.msg = msg;
Johannes Bergb9454e82009-07-08 13:29:08 +02003145 cookie.idx = key_idx;
Johannes Berg41ade002007-12-19 02:03:29 +01003146
David S. Miller9360ffd2012-03-29 04:41:26 -04003147 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
3148 nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_idx))
3149 goto nla_put_failure;
3150 if (mac_addr &&
3151 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr))
3152 goto nla_put_failure;
Johannes Berg41ade002007-12-19 02:03:29 +01003153
Hila Gonene35e4d22012-06-27 17:19:42 +03003154 err = rdev_get_key(rdev, dev, key_idx, pairwise, mac_addr, &cookie,
3155 get_key_callback);
Johannes Berg41ade002007-12-19 02:03:29 +01003156
3157 if (err)
Niko Jokinen6c95e2a2009-07-15 11:00:53 +03003158 goto free_msg;
Johannes Berg41ade002007-12-19 02:03:29 +01003159
3160 if (cookie.error)
3161 goto nla_put_failure;
3162
3163 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02003164 return genlmsg_reply(msg, info);
Johannes Berg41ade002007-12-19 02:03:29 +01003165
3166 nla_put_failure:
3167 err = -ENOBUFS;
Niko Jokinen6c95e2a2009-07-15 11:00:53 +03003168 free_msg:
Johannes Berg41ade002007-12-19 02:03:29 +01003169 nlmsg_free(msg);
Johannes Berg41ade002007-12-19 02:03:29 +01003170 return err;
3171}
3172
3173static int nl80211_set_key(struct sk_buff *skb, struct genl_info *info)
3174{
Johannes Berg4c476992010-10-04 21:36:35 +02003175 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Bergb9454e82009-07-08 13:29:08 +02003176 struct key_parse key;
Johannes Berg41ade002007-12-19 02:03:29 +01003177 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02003178 struct net_device *dev = info->user_ptr[1];
Johannes Berg41ade002007-12-19 02:03:29 +01003179
Johannes Bergb9454e82009-07-08 13:29:08 +02003180 err = nl80211_parse_key(info, &key);
3181 if (err)
3182 return err;
3183
3184 if (key.idx < 0)
Johannes Berg41ade002007-12-19 02:03:29 +01003185 return -EINVAL;
3186
Johannes Bergb9454e82009-07-08 13:29:08 +02003187 /* only support setting default key */
3188 if (!key.def && !key.defmgmt)
Johannes Berg41ade002007-12-19 02:03:29 +01003189 return -EINVAL;
3190
Johannes Bergfffd0932009-07-08 14:22:54 +02003191 wdev_lock(dev->ieee80211_ptr);
Johannes Bergdbd2fd62010-12-09 19:58:59 +01003192
3193 if (key.def) {
3194 if (!rdev->ops->set_default_key) {
3195 err = -EOPNOTSUPP;
3196 goto out;
3197 }
3198
3199 err = nl80211_key_allowed(dev->ieee80211_ptr);
3200 if (err)
3201 goto out;
3202
Hila Gonene35e4d22012-06-27 17:19:42 +03003203 err = rdev_set_default_key(rdev, dev, key.idx,
Johannes Bergdbd2fd62010-12-09 19:58:59 +01003204 key.def_uni, key.def_multi);
3205
3206 if (err)
3207 goto out;
Johannes Bergfffd0932009-07-08 14:22:54 +02003208
Johannes Berg3d23e342009-09-29 23:27:28 +02003209#ifdef CONFIG_CFG80211_WEXT
Johannes Bergdbd2fd62010-12-09 19:58:59 +01003210 dev->ieee80211_ptr->wext.default_key = key.idx;
Johannes Berg08645122009-05-11 13:54:58 +02003211#endif
Johannes Bergdbd2fd62010-12-09 19:58:59 +01003212 } else {
3213 if (key.def_uni || !key.def_multi) {
3214 err = -EINVAL;
3215 goto out;
3216 }
3217
3218 if (!rdev->ops->set_default_mgmt_key) {
3219 err = -EOPNOTSUPP;
3220 goto out;
3221 }
3222
3223 err = nl80211_key_allowed(dev->ieee80211_ptr);
3224 if (err)
3225 goto out;
3226
Hila Gonene35e4d22012-06-27 17:19:42 +03003227 err = rdev_set_default_mgmt_key(rdev, dev, key.idx);
Johannes Bergdbd2fd62010-12-09 19:58:59 +01003228 if (err)
3229 goto out;
3230
3231#ifdef CONFIG_CFG80211_WEXT
3232 dev->ieee80211_ptr->wext.default_mgmt_key = key.idx;
3233#endif
3234 }
3235
3236 out:
Johannes Bergfffd0932009-07-08 14:22:54 +02003237 wdev_unlock(dev->ieee80211_ptr);
Johannes Berg41ade002007-12-19 02:03:29 +01003238
Johannes Berg41ade002007-12-19 02:03:29 +01003239 return err;
3240}
3241
3242static int nl80211_new_key(struct sk_buff *skb, struct genl_info *info)
3243{
Johannes Berg4c476992010-10-04 21:36:35 +02003244 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Bergfffd0932009-07-08 14:22:54 +02003245 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02003246 struct net_device *dev = info->user_ptr[1];
Johannes Bergb9454e82009-07-08 13:29:08 +02003247 struct key_parse key;
Johannes Berge31b8212010-10-05 19:39:30 +02003248 const u8 *mac_addr = NULL;
Johannes Berg41ade002007-12-19 02:03:29 +01003249
Johannes Bergb9454e82009-07-08 13:29:08 +02003250 err = nl80211_parse_key(info, &key);
3251 if (err)
3252 return err;
Johannes Berg41ade002007-12-19 02:03:29 +01003253
Johannes Bergb9454e82009-07-08 13:29:08 +02003254 if (!key.p.key)
Johannes Berg41ade002007-12-19 02:03:29 +01003255 return -EINVAL;
3256
Johannes Berg41ade002007-12-19 02:03:29 +01003257 if (info->attrs[NL80211_ATTR_MAC])
3258 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
3259
Johannes Berge31b8212010-10-05 19:39:30 +02003260 if (key.type == -1) {
3261 if (mac_addr)
3262 key.type = NL80211_KEYTYPE_PAIRWISE;
3263 else
3264 key.type = NL80211_KEYTYPE_GROUP;
3265 }
3266
3267 /* for now */
3268 if (key.type != NL80211_KEYTYPE_PAIRWISE &&
3269 key.type != NL80211_KEYTYPE_GROUP)
3270 return -EINVAL;
3271
Johannes Berg4c476992010-10-04 21:36:35 +02003272 if (!rdev->ops->add_key)
3273 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01003274
Johannes Berge31b8212010-10-05 19:39:30 +02003275 if (cfg80211_validate_key_settings(rdev, &key.p, key.idx,
3276 key.type == NL80211_KEYTYPE_PAIRWISE,
3277 mac_addr))
Johannes Berg4c476992010-10-04 21:36:35 +02003278 return -EINVAL;
Johannes Bergfffd0932009-07-08 14:22:54 +02003279
3280 wdev_lock(dev->ieee80211_ptr);
3281 err = nl80211_key_allowed(dev->ieee80211_ptr);
3282 if (!err)
Hila Gonene35e4d22012-06-27 17:19:42 +03003283 err = rdev_add_key(rdev, dev, key.idx,
3284 key.type == NL80211_KEYTYPE_PAIRWISE,
3285 mac_addr, &key.p);
Johannes Bergfffd0932009-07-08 14:22:54 +02003286 wdev_unlock(dev->ieee80211_ptr);
Johannes Berg41ade002007-12-19 02:03:29 +01003287
Johannes Berg41ade002007-12-19 02:03:29 +01003288 return err;
3289}
3290
3291static int nl80211_del_key(struct sk_buff *skb, struct genl_info *info)
3292{
Johannes Berg4c476992010-10-04 21:36:35 +02003293 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg41ade002007-12-19 02:03:29 +01003294 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02003295 struct net_device *dev = info->user_ptr[1];
Johannes Berg41ade002007-12-19 02:03:29 +01003296 u8 *mac_addr = NULL;
Johannes Bergb9454e82009-07-08 13:29:08 +02003297 struct key_parse key;
Johannes Berg41ade002007-12-19 02:03:29 +01003298
Johannes Bergb9454e82009-07-08 13:29:08 +02003299 err = nl80211_parse_key(info, &key);
3300 if (err)
3301 return err;
Johannes Berg41ade002007-12-19 02:03:29 +01003302
3303 if (info->attrs[NL80211_ATTR_MAC])
3304 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
3305
Johannes Berge31b8212010-10-05 19:39:30 +02003306 if (key.type == -1) {
3307 if (mac_addr)
3308 key.type = NL80211_KEYTYPE_PAIRWISE;
3309 else
3310 key.type = NL80211_KEYTYPE_GROUP;
3311 }
3312
3313 /* for now */
3314 if (key.type != NL80211_KEYTYPE_PAIRWISE &&
3315 key.type != NL80211_KEYTYPE_GROUP)
3316 return -EINVAL;
3317
Johannes Berg4c476992010-10-04 21:36:35 +02003318 if (!rdev->ops->del_key)
3319 return -EOPNOTSUPP;
Johannes Berg41ade002007-12-19 02:03:29 +01003320
Johannes Bergfffd0932009-07-08 14:22:54 +02003321 wdev_lock(dev->ieee80211_ptr);
3322 err = nl80211_key_allowed(dev->ieee80211_ptr);
Johannes Berge31b8212010-10-05 19:39:30 +02003323
Johannes Berg0fa7b392015-01-23 11:10:12 +01003324 if (key.type == NL80211_KEYTYPE_GROUP && mac_addr &&
Johannes Berge31b8212010-10-05 19:39:30 +02003325 !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN))
3326 err = -ENOENT;
3327
Johannes Bergfffd0932009-07-08 14:22:54 +02003328 if (!err)
Hila Gonene35e4d22012-06-27 17:19:42 +03003329 err = rdev_del_key(rdev, dev, key.idx,
3330 key.type == NL80211_KEYTYPE_PAIRWISE,
3331 mac_addr);
Johannes Berg41ade002007-12-19 02:03:29 +01003332
Johannes Berg3d23e342009-09-29 23:27:28 +02003333#ifdef CONFIG_CFG80211_WEXT
Johannes Berg08645122009-05-11 13:54:58 +02003334 if (!err) {
Johannes Bergb9454e82009-07-08 13:29:08 +02003335 if (key.idx == dev->ieee80211_ptr->wext.default_key)
Johannes Berg08645122009-05-11 13:54:58 +02003336 dev->ieee80211_ptr->wext.default_key = -1;
Johannes Bergb9454e82009-07-08 13:29:08 +02003337 else if (key.idx == dev->ieee80211_ptr->wext.default_mgmt_key)
Johannes Berg08645122009-05-11 13:54:58 +02003338 dev->ieee80211_ptr->wext.default_mgmt_key = -1;
3339 }
3340#endif
Johannes Bergfffd0932009-07-08 14:22:54 +02003341 wdev_unlock(dev->ieee80211_ptr);
Johannes Berg08645122009-05-11 13:54:58 +02003342
Johannes Berg41ade002007-12-19 02:03:29 +01003343 return err;
3344}
3345
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +05303346/* This function returns an error or the number of nested attributes */
3347static int validate_acl_mac_addrs(struct nlattr *nl_attr)
3348{
3349 struct nlattr *attr;
3350 int n_entries = 0, tmp;
3351
3352 nla_for_each_nested(attr, nl_attr, tmp) {
3353 if (nla_len(attr) != ETH_ALEN)
3354 return -EINVAL;
3355
3356 n_entries++;
3357 }
3358
3359 return n_entries;
3360}
3361
3362/*
3363 * This function parses ACL information and allocates memory for ACL data.
3364 * On successful return, the calling function is responsible to free the
3365 * ACL buffer returned by this function.
3366 */
3367static struct cfg80211_acl_data *parse_acl_data(struct wiphy *wiphy,
3368 struct genl_info *info)
3369{
3370 enum nl80211_acl_policy acl_policy;
3371 struct nlattr *attr;
3372 struct cfg80211_acl_data *acl;
3373 int i = 0, n_entries, tmp;
3374
3375 if (!wiphy->max_acl_mac_addrs)
3376 return ERR_PTR(-EOPNOTSUPP);
3377
3378 if (!info->attrs[NL80211_ATTR_ACL_POLICY])
3379 return ERR_PTR(-EINVAL);
3380
3381 acl_policy = nla_get_u32(info->attrs[NL80211_ATTR_ACL_POLICY]);
3382 if (acl_policy != NL80211_ACL_POLICY_ACCEPT_UNLESS_LISTED &&
3383 acl_policy != NL80211_ACL_POLICY_DENY_UNLESS_LISTED)
3384 return ERR_PTR(-EINVAL);
3385
3386 if (!info->attrs[NL80211_ATTR_MAC_ADDRS])
3387 return ERR_PTR(-EINVAL);
3388
3389 n_entries = validate_acl_mac_addrs(info->attrs[NL80211_ATTR_MAC_ADDRS]);
3390 if (n_entries < 0)
3391 return ERR_PTR(n_entries);
3392
3393 if (n_entries > wiphy->max_acl_mac_addrs)
3394 return ERR_PTR(-ENOTSUPP);
3395
3396 acl = kzalloc(sizeof(*acl) + (sizeof(struct mac_address) * n_entries),
3397 GFP_KERNEL);
3398 if (!acl)
3399 return ERR_PTR(-ENOMEM);
3400
3401 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_MAC_ADDRS], tmp) {
3402 memcpy(acl->mac_addrs[i].addr, nla_data(attr), ETH_ALEN);
3403 i++;
3404 }
3405
3406 acl->n_acl_entries = n_entries;
3407 acl->acl_policy = acl_policy;
3408
3409 return acl;
3410}
3411
3412static int nl80211_set_mac_acl(struct sk_buff *skb, struct genl_info *info)
3413{
3414 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3415 struct net_device *dev = info->user_ptr[1];
3416 struct cfg80211_acl_data *acl;
3417 int err;
3418
3419 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
3420 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
3421 return -EOPNOTSUPP;
3422
3423 if (!dev->ieee80211_ptr->beacon_interval)
3424 return -EINVAL;
3425
3426 acl = parse_acl_data(&rdev->wiphy, info);
3427 if (IS_ERR(acl))
3428 return PTR_ERR(acl);
3429
3430 err = rdev_set_mac_acl(rdev, dev, acl);
3431
3432 kfree(acl);
3433
3434 return err;
3435}
3436
Purushottam Kushwahaa7c7fbf2016-09-14 17:38:44 +05303437static u32 rateset_to_mask(struct ieee80211_supported_band *sband,
3438 u8 *rates, u8 rates_len)
3439{
3440 u8 i;
3441 u32 mask = 0;
3442
3443 for (i = 0; i < rates_len; i++) {
3444 int rate = (rates[i] & 0x7f) * 5;
3445 int ridx;
3446
3447 for (ridx = 0; ridx < sband->n_bitrates; ridx++) {
3448 struct ieee80211_rate *srate =
3449 &sband->bitrates[ridx];
3450 if (rate == srate->bitrate) {
3451 mask |= 1 << ridx;
3452 break;
3453 }
3454 }
3455 if (ridx == sband->n_bitrates)
3456 return 0; /* rate not found */
3457 }
3458
3459 return mask;
3460}
3461
3462static bool ht_rateset_to_mask(struct ieee80211_supported_band *sband,
3463 u8 *rates, u8 rates_len,
3464 u8 mcs[IEEE80211_HT_MCS_MASK_LEN])
3465{
3466 u8 i;
3467
3468 memset(mcs, 0, IEEE80211_HT_MCS_MASK_LEN);
3469
3470 for (i = 0; i < rates_len; i++) {
3471 int ridx, rbit;
3472
3473 ridx = rates[i] / 8;
3474 rbit = BIT(rates[i] % 8);
3475
3476 /* check validity */
3477 if ((ridx < 0) || (ridx >= IEEE80211_HT_MCS_MASK_LEN))
3478 return false;
3479
3480 /* check availability */
3481 if (sband->ht_cap.mcs.rx_mask[ridx] & rbit)
3482 mcs[ridx] |= rbit;
3483 else
3484 return false;
3485 }
3486
3487 return true;
3488}
3489
3490static u16 vht_mcs_map_to_mcs_mask(u8 vht_mcs_map)
3491{
3492 u16 mcs_mask = 0;
3493
3494 switch (vht_mcs_map) {
3495 case IEEE80211_VHT_MCS_NOT_SUPPORTED:
3496 break;
3497 case IEEE80211_VHT_MCS_SUPPORT_0_7:
3498 mcs_mask = 0x00FF;
3499 break;
3500 case IEEE80211_VHT_MCS_SUPPORT_0_8:
3501 mcs_mask = 0x01FF;
3502 break;
3503 case IEEE80211_VHT_MCS_SUPPORT_0_9:
3504 mcs_mask = 0x03FF;
3505 break;
3506 default:
3507 break;
3508 }
3509
3510 return mcs_mask;
3511}
3512
3513static void vht_build_mcs_mask(u16 vht_mcs_map,
3514 u16 vht_mcs_mask[NL80211_VHT_NSS_MAX])
3515{
3516 u8 nss;
3517
3518 for (nss = 0; nss < NL80211_VHT_NSS_MAX; nss++) {
3519 vht_mcs_mask[nss] = vht_mcs_map_to_mcs_mask(vht_mcs_map & 0x03);
3520 vht_mcs_map >>= 2;
3521 }
3522}
3523
3524static bool vht_set_mcs_mask(struct ieee80211_supported_band *sband,
3525 struct nl80211_txrate_vht *txrate,
3526 u16 mcs[NL80211_VHT_NSS_MAX])
3527{
3528 u16 tx_mcs_map = le16_to_cpu(sband->vht_cap.vht_mcs.tx_mcs_map);
3529 u16 tx_mcs_mask[NL80211_VHT_NSS_MAX] = {};
3530 u8 i;
3531
3532 if (!sband->vht_cap.vht_supported)
3533 return false;
3534
3535 memset(mcs, 0, sizeof(u16) * NL80211_VHT_NSS_MAX);
3536
3537 /* Build vht_mcs_mask from VHT capabilities */
3538 vht_build_mcs_mask(tx_mcs_map, tx_mcs_mask);
3539
3540 for (i = 0; i < NL80211_VHT_NSS_MAX; i++) {
3541 if ((tx_mcs_mask[i] & txrate->mcs[i]) == txrate->mcs[i])
3542 mcs[i] = txrate->mcs[i];
3543 else
3544 return false;
3545 }
3546
3547 return true;
3548}
3549
3550static const struct nla_policy nl80211_txattr_policy[NL80211_TXRATE_MAX + 1] = {
3551 [NL80211_TXRATE_LEGACY] = { .type = NLA_BINARY,
3552 .len = NL80211_MAX_SUPP_RATES },
3553 [NL80211_TXRATE_HT] = { .type = NLA_BINARY,
3554 .len = NL80211_MAX_SUPP_HT_RATES },
3555 [NL80211_TXRATE_VHT] = { .len = sizeof(struct nl80211_txrate_vht)},
3556 [NL80211_TXRATE_GI] = { .type = NLA_U8 },
3557};
3558
3559static int nl80211_parse_tx_bitrate_mask(struct genl_info *info,
3560 struct cfg80211_bitrate_mask *mask)
3561{
3562 struct nlattr *tb[NL80211_TXRATE_MAX + 1];
3563 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3564 int rem, i;
3565 struct nlattr *tx_rates;
3566 struct ieee80211_supported_band *sband;
3567 u16 vht_tx_mcs_map;
3568
3569 memset(mask, 0, sizeof(*mask));
3570 /* Default to all rates enabled */
3571 for (i = 0; i < NUM_NL80211_BANDS; i++) {
3572 sband = rdev->wiphy.bands[i];
3573
3574 if (!sband)
3575 continue;
3576
3577 mask->control[i].legacy = (1 << sband->n_bitrates) - 1;
3578 memcpy(mask->control[i].ht_mcs,
3579 sband->ht_cap.mcs.rx_mask,
3580 sizeof(mask->control[i].ht_mcs));
3581
3582 if (!sband->vht_cap.vht_supported)
3583 continue;
3584
3585 vht_tx_mcs_map = le16_to_cpu(sband->vht_cap.vht_mcs.tx_mcs_map);
3586 vht_build_mcs_mask(vht_tx_mcs_map, mask->control[i].vht_mcs);
3587 }
3588
3589 /* if no rates are given set it back to the defaults */
3590 if (!info->attrs[NL80211_ATTR_TX_RATES])
3591 goto out;
3592
3593 /* The nested attribute uses enum nl80211_band as the index. This maps
3594 * directly to the enum nl80211_band values used in cfg80211.
3595 */
3596 BUILD_BUG_ON(NL80211_MAX_SUPP_HT_RATES > IEEE80211_HT_MCS_MASK_LEN * 8);
3597 nla_for_each_nested(tx_rates, info->attrs[NL80211_ATTR_TX_RATES], rem) {
3598 enum nl80211_band band = nla_type(tx_rates);
3599 int err;
3600
3601 if (band < 0 || band >= NUM_NL80211_BANDS)
3602 return -EINVAL;
3603 sband = rdev->wiphy.bands[band];
3604 if (sband == NULL)
3605 return -EINVAL;
Johannes Bergbfe2c7b2016-10-26 14:42:21 +02003606 err = nla_parse_nested(tb, NL80211_TXRATE_MAX, tx_rates,
Johannes Bergfe521452017-04-12 14:34:08 +02003607 nl80211_txattr_policy, info->extack);
Purushottam Kushwahaa7c7fbf2016-09-14 17:38:44 +05303608 if (err)
3609 return err;
3610 if (tb[NL80211_TXRATE_LEGACY]) {
3611 mask->control[band].legacy = rateset_to_mask(
3612 sband,
3613 nla_data(tb[NL80211_TXRATE_LEGACY]),
3614 nla_len(tb[NL80211_TXRATE_LEGACY]));
3615 if ((mask->control[band].legacy == 0) &&
3616 nla_len(tb[NL80211_TXRATE_LEGACY]))
3617 return -EINVAL;
3618 }
3619 if (tb[NL80211_TXRATE_HT]) {
3620 if (!ht_rateset_to_mask(
3621 sband,
3622 nla_data(tb[NL80211_TXRATE_HT]),
3623 nla_len(tb[NL80211_TXRATE_HT]),
3624 mask->control[band].ht_mcs))
3625 return -EINVAL;
3626 }
3627 if (tb[NL80211_TXRATE_VHT]) {
3628 if (!vht_set_mcs_mask(
3629 sband,
3630 nla_data(tb[NL80211_TXRATE_VHT]),
3631 mask->control[band].vht_mcs))
3632 return -EINVAL;
3633 }
3634 if (tb[NL80211_TXRATE_GI]) {
3635 mask->control[band].gi =
3636 nla_get_u8(tb[NL80211_TXRATE_GI]);
3637 if (mask->control[band].gi > NL80211_TXRATE_FORCE_LGI)
3638 return -EINVAL;
3639 }
3640
3641 if (mask->control[band].legacy == 0) {
3642 /* don't allow empty legacy rates if HT or VHT
3643 * are not even supported.
3644 */
3645 if (!(rdev->wiphy.bands[band]->ht_cap.ht_supported ||
3646 rdev->wiphy.bands[band]->vht_cap.vht_supported))
3647 return -EINVAL;
3648
3649 for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++)
3650 if (mask->control[band].ht_mcs[i])
3651 goto out;
3652
3653 for (i = 0; i < NL80211_VHT_NSS_MAX; i++)
3654 if (mask->control[band].vht_mcs[i])
3655 goto out;
3656
3657 /* legacy and mcs rates may not be both empty */
3658 return -EINVAL;
3659 }
3660 }
3661
3662out:
3663 return 0;
3664}
3665
Johannes Berg8564e382016-09-19 09:44:44 +02003666static int validate_beacon_tx_rate(struct cfg80211_registered_device *rdev,
3667 enum nl80211_band band,
3668 struct cfg80211_bitrate_mask *beacon_rate)
Purushottam Kushwahaa7c7fbf2016-09-14 17:38:44 +05303669{
Johannes Berg8564e382016-09-19 09:44:44 +02003670 u32 count_ht, count_vht, i;
3671 u32 rate = beacon_rate->control[band].legacy;
Purushottam Kushwahaa7c7fbf2016-09-14 17:38:44 +05303672
3673 /* Allow only one rate */
3674 if (hweight32(rate) > 1)
3675 return -EINVAL;
3676
3677 count_ht = 0;
3678 for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++) {
Johannes Berg8564e382016-09-19 09:44:44 +02003679 if (hweight8(beacon_rate->control[band].ht_mcs[i]) > 1) {
Purushottam Kushwahaa7c7fbf2016-09-14 17:38:44 +05303680 return -EINVAL;
Johannes Berg8564e382016-09-19 09:44:44 +02003681 } else if (beacon_rate->control[band].ht_mcs[i]) {
Purushottam Kushwahaa7c7fbf2016-09-14 17:38:44 +05303682 count_ht++;
3683 if (count_ht > 1)
3684 return -EINVAL;
3685 }
3686 if (count_ht && rate)
3687 return -EINVAL;
3688 }
3689
3690 count_vht = 0;
3691 for (i = 0; i < NL80211_VHT_NSS_MAX; i++) {
Johannes Berg8564e382016-09-19 09:44:44 +02003692 if (hweight16(beacon_rate->control[band].vht_mcs[i]) > 1) {
Purushottam Kushwahaa7c7fbf2016-09-14 17:38:44 +05303693 return -EINVAL;
Johannes Berg8564e382016-09-19 09:44:44 +02003694 } else if (beacon_rate->control[band].vht_mcs[i]) {
Purushottam Kushwahaa7c7fbf2016-09-14 17:38:44 +05303695 count_vht++;
3696 if (count_vht > 1)
3697 return -EINVAL;
3698 }
3699 if (count_vht && rate)
3700 return -EINVAL;
3701 }
3702
3703 if ((count_ht && count_vht) || (!rate && !count_ht && !count_vht))
3704 return -EINVAL;
3705
Johannes Berg8564e382016-09-19 09:44:44 +02003706 if (rate &&
3707 !wiphy_ext_feature_isset(&rdev->wiphy,
3708 NL80211_EXT_FEATURE_BEACON_RATE_LEGACY))
3709 return -EINVAL;
3710 if (count_ht &&
3711 !wiphy_ext_feature_isset(&rdev->wiphy,
3712 NL80211_EXT_FEATURE_BEACON_RATE_HT))
3713 return -EINVAL;
3714 if (count_vht &&
3715 !wiphy_ext_feature_isset(&rdev->wiphy,
3716 NL80211_EXT_FEATURE_BEACON_RATE_VHT))
3717 return -EINVAL;
3718
Purushottam Kushwahaa7c7fbf2016-09-14 17:38:44 +05303719 return 0;
3720}
3721
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003722static int nl80211_parse_beacon(struct nlattr *attrs[],
Johannes Berg88600202012-02-13 15:17:18 +01003723 struct cfg80211_beacon_data *bcn)
Johannes Berged1b6cc2007-12-19 02:03:32 +01003724{
Johannes Berg88600202012-02-13 15:17:18 +01003725 bool haveinfo = false;
Johannes Berged1b6cc2007-12-19 02:03:32 +01003726
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003727 if (!is_valid_ie_attr(attrs[NL80211_ATTR_BEACON_TAIL]) ||
3728 !is_valid_ie_attr(attrs[NL80211_ATTR_IE]) ||
3729 !is_valid_ie_attr(attrs[NL80211_ATTR_IE_PROBE_RESP]) ||
3730 !is_valid_ie_attr(attrs[NL80211_ATTR_IE_ASSOC_RESP]))
Johannes Bergf4a11bb2009-03-27 12:40:28 +01003731 return -EINVAL;
3732
Johannes Berg88600202012-02-13 15:17:18 +01003733 memset(bcn, 0, sizeof(*bcn));
Johannes Berged1b6cc2007-12-19 02:03:32 +01003734
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003735 if (attrs[NL80211_ATTR_BEACON_HEAD]) {
3736 bcn->head = nla_data(attrs[NL80211_ATTR_BEACON_HEAD]);
3737 bcn->head_len = nla_len(attrs[NL80211_ATTR_BEACON_HEAD]);
Johannes Berg88600202012-02-13 15:17:18 +01003738 if (!bcn->head_len)
3739 return -EINVAL;
3740 haveinfo = true;
Johannes Berged1b6cc2007-12-19 02:03:32 +01003741 }
3742
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003743 if (attrs[NL80211_ATTR_BEACON_TAIL]) {
3744 bcn->tail = nla_data(attrs[NL80211_ATTR_BEACON_TAIL]);
3745 bcn->tail_len = nla_len(attrs[NL80211_ATTR_BEACON_TAIL]);
Johannes Berg88600202012-02-13 15:17:18 +01003746 haveinfo = true;
Johannes Berged1b6cc2007-12-19 02:03:32 +01003747 }
3748
Johannes Berg4c476992010-10-04 21:36:35 +02003749 if (!haveinfo)
3750 return -EINVAL;
Johannes Berged1b6cc2007-12-19 02:03:32 +01003751
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003752 if (attrs[NL80211_ATTR_IE]) {
3753 bcn->beacon_ies = nla_data(attrs[NL80211_ATTR_IE]);
3754 bcn->beacon_ies_len = nla_len(attrs[NL80211_ATTR_IE]);
Jouni Malinen9946ecf2011-08-10 23:55:56 +03003755 }
3756
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003757 if (attrs[NL80211_ATTR_IE_PROBE_RESP]) {
Johannes Berg88600202012-02-13 15:17:18 +01003758 bcn->proberesp_ies =
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003759 nla_data(attrs[NL80211_ATTR_IE_PROBE_RESP]);
Johannes Berg88600202012-02-13 15:17:18 +01003760 bcn->proberesp_ies_len =
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003761 nla_len(attrs[NL80211_ATTR_IE_PROBE_RESP]);
Jouni Malinen9946ecf2011-08-10 23:55:56 +03003762 }
3763
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003764 if (attrs[NL80211_ATTR_IE_ASSOC_RESP]) {
Johannes Berg88600202012-02-13 15:17:18 +01003765 bcn->assocresp_ies =
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003766 nla_data(attrs[NL80211_ATTR_IE_ASSOC_RESP]);
Johannes Berg88600202012-02-13 15:17:18 +01003767 bcn->assocresp_ies_len =
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003768 nla_len(attrs[NL80211_ATTR_IE_ASSOC_RESP]);
Jouni Malinen9946ecf2011-08-10 23:55:56 +03003769 }
3770
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003771 if (attrs[NL80211_ATTR_PROBE_RESP]) {
3772 bcn->probe_resp = nla_data(attrs[NL80211_ATTR_PROBE_RESP]);
3773 bcn->probe_resp_len = nla_len(attrs[NL80211_ATTR_PROBE_RESP]);
Arik Nemtsov00f740e2011-11-10 11:28:56 +02003774 }
3775
Johannes Berg88600202012-02-13 15:17:18 +01003776 return 0;
3777}
3778
Johannes Berg66cd7942017-02-07 22:40:44 +02003779static void nl80211_check_ap_rate_selectors(struct cfg80211_ap_settings *params,
3780 const u8 *rates)
3781{
3782 int i;
3783
3784 if (!rates)
3785 return;
3786
3787 for (i = 0; i < rates[1]; i++) {
3788 if (rates[2 + i] == BSS_MEMBERSHIP_SELECTOR_HT_PHY)
3789 params->ht_required = true;
3790 if (rates[2 + i] == BSS_MEMBERSHIP_SELECTOR_VHT_PHY)
3791 params->vht_required = true;
3792 }
3793}
3794
3795/*
3796 * Since the nl80211 API didn't include, from the beginning, attributes about
3797 * HT/VHT requirements/capabilities, we parse them out of the IEs for the
3798 * benefit of drivers that rebuild IEs in the firmware.
3799 */
3800static void nl80211_calculate_ap_params(struct cfg80211_ap_settings *params)
3801{
3802 const struct cfg80211_beacon_data *bcn = &params->beacon;
Igor Mitsyankoba83bfb2017-08-30 13:52:25 -07003803 size_t ies_len = bcn->tail_len;
3804 const u8 *ies = bcn->tail;
Johannes Berg66cd7942017-02-07 22:40:44 +02003805 const u8 *rates;
3806 const u8 *cap;
3807
3808 rates = cfg80211_find_ie(WLAN_EID_SUPP_RATES, ies, ies_len);
3809 nl80211_check_ap_rate_selectors(params, rates);
3810
3811 rates = cfg80211_find_ie(WLAN_EID_EXT_SUPP_RATES, ies, ies_len);
3812 nl80211_check_ap_rate_selectors(params, rates);
3813
3814 cap = cfg80211_find_ie(WLAN_EID_HT_CAPABILITY, ies, ies_len);
3815 if (cap && cap[1] >= sizeof(*params->ht_cap))
3816 params->ht_cap = (void *)(cap + 2);
3817 cap = cfg80211_find_ie(WLAN_EID_VHT_CAPABILITY, ies, ies_len);
3818 if (cap && cap[1] >= sizeof(*params->vht_cap))
3819 params->vht_cap = (void *)(cap + 2);
3820}
3821
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003822static bool nl80211_get_ap_channel(struct cfg80211_registered_device *rdev,
3823 struct cfg80211_ap_settings *params)
3824{
3825 struct wireless_dev *wdev;
3826 bool ret = false;
3827
Johannes Berg53873f12016-05-03 16:52:04 +03003828 list_for_each_entry(wdev, &rdev->wiphy.wdev_list, list) {
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003829 if (wdev->iftype != NL80211_IFTYPE_AP &&
3830 wdev->iftype != NL80211_IFTYPE_P2P_GO)
3831 continue;
3832
Johannes Berg683b6d32012-11-08 21:25:48 +01003833 if (!wdev->preset_chandef.chan)
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003834 continue;
3835
Johannes Berg683b6d32012-11-08 21:25:48 +01003836 params->chandef = wdev->preset_chandef;
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003837 ret = true;
3838 break;
3839 }
3840
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003841 return ret;
3842}
3843
Jouni Malinene39e5b52012-09-30 19:29:39 +03003844static bool nl80211_valid_auth_type(struct cfg80211_registered_device *rdev,
3845 enum nl80211_auth_type auth_type,
3846 enum nl80211_commands cmd)
3847{
3848 if (auth_type > NL80211_AUTHTYPE_MAX)
3849 return false;
3850
3851 switch (cmd) {
3852 case NL80211_CMD_AUTHENTICATE:
3853 if (!(rdev->wiphy.features & NL80211_FEATURE_SAE) &&
3854 auth_type == NL80211_AUTHTYPE_SAE)
3855 return false;
Jouni Malinen63181062016-10-27 00:42:02 +03003856 if (!wiphy_ext_feature_isset(&rdev->wiphy,
3857 NL80211_EXT_FEATURE_FILS_STA) &&
3858 (auth_type == NL80211_AUTHTYPE_FILS_SK ||
3859 auth_type == NL80211_AUTHTYPE_FILS_SK_PFS ||
3860 auth_type == NL80211_AUTHTYPE_FILS_PK))
3861 return false;
Jouni Malinene39e5b52012-09-30 19:29:39 +03003862 return true;
3863 case NL80211_CMD_CONNECT:
Vidyullatha Kanchanapallya3caf742017-03-31 00:22:34 +03003864 /* SAE not supported yet */
3865 if (auth_type == NL80211_AUTHTYPE_SAE)
3866 return false;
3867 /* FILS with SK PFS or PK not supported yet */
3868 if (auth_type == NL80211_AUTHTYPE_FILS_SK_PFS ||
3869 auth_type == NL80211_AUTHTYPE_FILS_PK)
3870 return false;
3871 if (!wiphy_ext_feature_isset(
3872 &rdev->wiphy,
3873 NL80211_EXT_FEATURE_FILS_SK_OFFLOAD) &&
3874 auth_type == NL80211_AUTHTYPE_FILS_SK)
3875 return false;
3876 return true;
Jouni Malinene39e5b52012-09-30 19:29:39 +03003877 case NL80211_CMD_START_AP:
3878 /* SAE not supported yet */
3879 if (auth_type == NL80211_AUTHTYPE_SAE)
3880 return false;
Jouni Malinen63181062016-10-27 00:42:02 +03003881 /* FILS not supported yet */
3882 if (auth_type == NL80211_AUTHTYPE_FILS_SK ||
3883 auth_type == NL80211_AUTHTYPE_FILS_SK_PFS ||
3884 auth_type == NL80211_AUTHTYPE_FILS_PK)
3885 return false;
Jouni Malinene39e5b52012-09-30 19:29:39 +03003886 return true;
3887 default:
3888 return false;
3889 }
3890}
3891
Johannes Berg88600202012-02-13 15:17:18 +01003892static int nl80211_start_ap(struct sk_buff *skb, struct genl_info *info)
3893{
3894 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3895 struct net_device *dev = info->user_ptr[1];
3896 struct wireless_dev *wdev = dev->ieee80211_ptr;
3897 struct cfg80211_ap_settings params;
3898 int err;
3899
3900 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
3901 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
3902 return -EOPNOTSUPP;
3903
3904 if (!rdev->ops->start_ap)
3905 return -EOPNOTSUPP;
3906
3907 if (wdev->beacon_interval)
3908 return -EALREADY;
3909
3910 memset(&params, 0, sizeof(params));
3911
3912 /* these are required for START_AP */
3913 if (!info->attrs[NL80211_ATTR_BEACON_INTERVAL] ||
3914 !info->attrs[NL80211_ATTR_DTIM_PERIOD] ||
3915 !info->attrs[NL80211_ATTR_BEACON_HEAD])
3916 return -EINVAL;
3917
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003918 err = nl80211_parse_beacon(info->attrs, &params.beacon);
Johannes Berg88600202012-02-13 15:17:18 +01003919 if (err)
3920 return err;
3921
3922 params.beacon_interval =
3923 nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]);
3924 params.dtim_period =
3925 nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]);
3926
Purushottam Kushwaha0c317a02016-10-12 18:26:51 +05303927 err = cfg80211_validate_beacon_int(rdev, dev->ieee80211_ptr->iftype,
3928 params.beacon_interval);
Johannes Berg88600202012-02-13 15:17:18 +01003929 if (err)
3930 return err;
3931
3932 /*
3933 * In theory, some of these attributes should be required here
3934 * but since they were not used when the command was originally
3935 * added, keep them optional for old user space programs to let
3936 * them continue to work with drivers that do not need the
3937 * additional information -- drivers must check!
3938 */
3939 if (info->attrs[NL80211_ATTR_SSID]) {
3940 params.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
3941 params.ssid_len =
3942 nla_len(info->attrs[NL80211_ATTR_SSID]);
3943 if (params.ssid_len == 0 ||
3944 params.ssid_len > IEEE80211_MAX_SSID_LEN)
3945 return -EINVAL;
3946 }
3947
3948 if (info->attrs[NL80211_ATTR_HIDDEN_SSID]) {
3949 params.hidden_ssid = nla_get_u32(
3950 info->attrs[NL80211_ATTR_HIDDEN_SSID]);
3951 if (params.hidden_ssid != NL80211_HIDDEN_SSID_NOT_IN_USE &&
3952 params.hidden_ssid != NL80211_HIDDEN_SSID_ZERO_LEN &&
3953 params.hidden_ssid != NL80211_HIDDEN_SSID_ZERO_CONTENTS)
3954 return -EINVAL;
3955 }
3956
3957 params.privacy = !!info->attrs[NL80211_ATTR_PRIVACY];
3958
3959 if (info->attrs[NL80211_ATTR_AUTH_TYPE]) {
3960 params.auth_type = nla_get_u32(
3961 info->attrs[NL80211_ATTR_AUTH_TYPE]);
Jouni Malinene39e5b52012-09-30 19:29:39 +03003962 if (!nl80211_valid_auth_type(rdev, params.auth_type,
3963 NL80211_CMD_START_AP))
Johannes Berg88600202012-02-13 15:17:18 +01003964 return -EINVAL;
3965 } else
3966 params.auth_type = NL80211_AUTHTYPE_AUTOMATIC;
3967
3968 err = nl80211_crypto_settings(rdev, info, &params.crypto,
3969 NL80211_MAX_NR_CIPHER_SUITES);
3970 if (err)
3971 return err;
3972
Vasanthakumar Thiagarajan1b658f12012-03-02 15:50:02 +05303973 if (info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]) {
3974 if (!(rdev->wiphy.features & NL80211_FEATURE_INACTIVITY_TIMER))
3975 return -EOPNOTSUPP;
3976 params.inactivity_timeout = nla_get_u16(
3977 info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]);
3978 }
3979
Johannes Berg53cabad2012-11-14 15:17:28 +01003980 if (info->attrs[NL80211_ATTR_P2P_CTWINDOW]) {
3981 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
3982 return -EINVAL;
3983 params.p2p_ctwindow =
3984 nla_get_u8(info->attrs[NL80211_ATTR_P2P_CTWINDOW]);
3985 if (params.p2p_ctwindow > 127)
3986 return -EINVAL;
3987 if (params.p2p_ctwindow != 0 &&
3988 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_CTWIN))
3989 return -EINVAL;
3990 }
3991
3992 if (info->attrs[NL80211_ATTR_P2P_OPPPS]) {
3993 u8 tmp;
3994
3995 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
3996 return -EINVAL;
3997 tmp = nla_get_u8(info->attrs[NL80211_ATTR_P2P_OPPPS]);
3998 if (tmp > 1)
3999 return -EINVAL;
4000 params.p2p_opp_ps = tmp;
4001 if (params.p2p_opp_ps != 0 &&
4002 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_OPPPS))
4003 return -EINVAL;
4004 }
4005
Johannes Bergaa430da2012-05-16 23:50:18 +02004006 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
Johannes Berg683b6d32012-11-08 21:25:48 +01004007 err = nl80211_parse_chandef(rdev, info, &params.chandef);
4008 if (err)
4009 return err;
4010 } else if (wdev->preset_chandef.chan) {
4011 params.chandef = wdev->preset_chandef;
Felix Fietkau46c1dd02012-06-19 02:50:57 +02004012 } else if (!nl80211_get_ap_channel(rdev, &params))
Johannes Bergaa430da2012-05-16 23:50:18 +02004013 return -EINVAL;
4014
Arik Nemtsov923b3522015-07-08 15:41:44 +03004015 if (!cfg80211_reg_can_beacon_relax(&rdev->wiphy, &params.chandef,
4016 wdev->iftype))
Johannes Bergaa430da2012-05-16 23:50:18 +02004017 return -EINVAL;
4018
Purushottam Kushwahaa7c7fbf2016-09-14 17:38:44 +05304019 if (info->attrs[NL80211_ATTR_TX_RATES]) {
4020 err = nl80211_parse_tx_bitrate_mask(info, &params.beacon_rate);
4021 if (err)
4022 return err;
4023
Johannes Berg8564e382016-09-19 09:44:44 +02004024 err = validate_beacon_tx_rate(rdev, params.chandef.chan->band,
4025 &params.beacon_rate);
Purushottam Kushwahaa7c7fbf2016-09-14 17:38:44 +05304026 if (err)
4027 return err;
4028 }
4029
Eliad Peller18998c32014-09-10 14:07:34 +03004030 if (info->attrs[NL80211_ATTR_SMPS_MODE]) {
4031 params.smps_mode =
4032 nla_get_u8(info->attrs[NL80211_ATTR_SMPS_MODE]);
4033 switch (params.smps_mode) {
4034 case NL80211_SMPS_OFF:
4035 break;
4036 case NL80211_SMPS_STATIC:
4037 if (!(rdev->wiphy.features &
4038 NL80211_FEATURE_STATIC_SMPS))
4039 return -EINVAL;
4040 break;
4041 case NL80211_SMPS_DYNAMIC:
4042 if (!(rdev->wiphy.features &
4043 NL80211_FEATURE_DYNAMIC_SMPS))
4044 return -EINVAL;
4045 break;
4046 default:
4047 return -EINVAL;
4048 }
4049 } else {
4050 params.smps_mode = NL80211_SMPS_OFF;
4051 }
4052
Purushottam Kushwaha6e8ef842016-07-05 13:44:51 +05304053 params.pbss = nla_get_flag(info->attrs[NL80211_ATTR_PBSS]);
4054 if (params.pbss && !rdev->wiphy.bands[NL80211_BAND_60GHZ])
4055 return -EOPNOTSUPP;
4056
Ola Olsson4baf6be2015-10-29 07:04:58 +01004057 if (info->attrs[NL80211_ATTR_ACL_POLICY]) {
4058 params.acl = parse_acl_data(&rdev->wiphy, info);
4059 if (IS_ERR(params.acl))
4060 return PTR_ERR(params.acl);
4061 }
4062
Johannes Berg66cd7942017-02-07 22:40:44 +02004063 nl80211_calculate_ap_params(&params);
4064
Simon Wunderlichc56589e2013-11-21 18:19:49 +01004065 wdev_lock(wdev);
Hila Gonene35e4d22012-06-27 17:19:42 +03004066 err = rdev_start_ap(rdev, dev, &params);
Felix Fietkau46c1dd02012-06-19 02:50:57 +02004067 if (!err) {
Johannes Berg683b6d32012-11-08 21:25:48 +01004068 wdev->preset_chandef = params.chandef;
Johannes Berg88600202012-02-13 15:17:18 +01004069 wdev->beacon_interval = params.beacon_interval;
Michal Kazior9e0e2962014-01-29 14:22:27 +01004070 wdev->chandef = params.chandef;
Antonio Quartulli06e191e2012-11-07 12:52:19 +01004071 wdev->ssid_len = params.ssid_len;
4072 memcpy(wdev->ssid, params.ssid, wdev->ssid_len);
Felix Fietkau46c1dd02012-06-19 02:50:57 +02004073 }
Simon Wunderlichc56589e2013-11-21 18:19:49 +01004074 wdev_unlock(wdev);
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +05304075
4076 kfree(params.acl);
4077
Johannes Berg56d18932011-05-09 18:41:15 +02004078 return err;
Johannes Berged1b6cc2007-12-19 02:03:32 +01004079}
4080
Johannes Berg88600202012-02-13 15:17:18 +01004081static int nl80211_set_beacon(struct sk_buff *skb, struct genl_info *info)
4082{
4083 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4084 struct net_device *dev = info->user_ptr[1];
4085 struct wireless_dev *wdev = dev->ieee80211_ptr;
4086 struct cfg80211_beacon_data params;
4087 int err;
4088
4089 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
4090 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
4091 return -EOPNOTSUPP;
4092
4093 if (!rdev->ops->change_beacon)
4094 return -EOPNOTSUPP;
4095
4096 if (!wdev->beacon_interval)
4097 return -EINVAL;
4098
Simon Wunderlicha1193be2013-06-14 14:15:19 +02004099 err = nl80211_parse_beacon(info->attrs, &params);
Johannes Berg88600202012-02-13 15:17:18 +01004100 if (err)
4101 return err;
4102
Simon Wunderlichc56589e2013-11-21 18:19:49 +01004103 wdev_lock(wdev);
4104 err = rdev_change_beacon(rdev, dev, &params);
4105 wdev_unlock(wdev);
4106
4107 return err;
Johannes Berg88600202012-02-13 15:17:18 +01004108}
4109
4110static int nl80211_stop_ap(struct sk_buff *skb, struct genl_info *info)
Johannes Berged1b6cc2007-12-19 02:03:32 +01004111{
Johannes Berg4c476992010-10-04 21:36:35 +02004112 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4113 struct net_device *dev = info->user_ptr[1];
Johannes Berged1b6cc2007-12-19 02:03:32 +01004114
Ilan Peer7c8d5e02014-02-25 15:33:38 +02004115 return cfg80211_stop_ap(rdev, dev, false);
Johannes Berged1b6cc2007-12-19 02:03:32 +01004116}
4117
Johannes Berg5727ef12007-12-19 02:03:34 +01004118static const struct nla_policy sta_flags_policy[NL80211_STA_FLAG_MAX + 1] = {
4119 [NL80211_STA_FLAG_AUTHORIZED] = { .type = NLA_FLAG },
4120 [NL80211_STA_FLAG_SHORT_PREAMBLE] = { .type = NLA_FLAG },
4121 [NL80211_STA_FLAG_WME] = { .type = NLA_FLAG },
Jouni Malinen0e467242009-05-11 21:57:55 +03004122 [NL80211_STA_FLAG_MFP] = { .type = NLA_FLAG },
Javier Cardonab39c48f2011-04-07 15:08:30 -07004123 [NL80211_STA_FLAG_AUTHENTICATED] = { .type = NLA_FLAG },
Johannes Bergd83023d2011-12-14 09:29:15 +01004124 [NL80211_STA_FLAG_TDLS_PEER] = { .type = NLA_FLAG },
Johannes Berg5727ef12007-12-19 02:03:34 +01004125};
4126
Johannes Bergeccb8e82009-05-11 21:57:56 +03004127static int parse_station_flags(struct genl_info *info,
Johannes Bergbdd3ae32012-01-02 13:30:03 +01004128 enum nl80211_iftype iftype,
Johannes Bergeccb8e82009-05-11 21:57:56 +03004129 struct station_parameters *params)
Johannes Berg5727ef12007-12-19 02:03:34 +01004130{
4131 struct nlattr *flags[NL80211_STA_FLAG_MAX + 1];
Johannes Bergeccb8e82009-05-11 21:57:56 +03004132 struct nlattr *nla;
Johannes Berg5727ef12007-12-19 02:03:34 +01004133 int flag;
4134
Johannes Bergeccb8e82009-05-11 21:57:56 +03004135 /*
4136 * Try parsing the new attribute first so userspace
4137 * can specify both for older kernels.
4138 */
4139 nla = info->attrs[NL80211_ATTR_STA_FLAGS2];
4140 if (nla) {
4141 struct nl80211_sta_flag_update *sta_flags;
Johannes Berg5727ef12007-12-19 02:03:34 +01004142
Johannes Bergeccb8e82009-05-11 21:57:56 +03004143 sta_flags = nla_data(nla);
4144 params->sta_flags_mask = sta_flags->mask;
4145 params->sta_flags_set = sta_flags->set;
Johannes Berg77ee7c82013-02-15 00:48:33 +01004146 params->sta_flags_set &= params->sta_flags_mask;
Johannes Bergeccb8e82009-05-11 21:57:56 +03004147 if ((params->sta_flags_mask |
4148 params->sta_flags_set) & BIT(__NL80211_STA_FLAG_INVALID))
4149 return -EINVAL;
4150 return 0;
4151 }
4152
4153 /* if present, parse the old attribute */
4154
4155 nla = info->attrs[NL80211_ATTR_STA_FLAGS];
Johannes Berg5727ef12007-12-19 02:03:34 +01004156 if (!nla)
4157 return 0;
4158
Johannes Bergfceb6432017-04-12 14:34:07 +02004159 if (nla_parse_nested(flags, NL80211_STA_FLAG_MAX, nla,
Johannes Bergfe521452017-04-12 14:34:08 +02004160 sta_flags_policy, info->extack))
Johannes Berg5727ef12007-12-19 02:03:34 +01004161 return -EINVAL;
4162
Johannes Bergbdd3ae32012-01-02 13:30:03 +01004163 /*
4164 * Only allow certain flags for interface types so that
4165 * other attributes are silently ignored. Remember that
4166 * this is backward compatibility code with old userspace
4167 * and shouldn't be hit in other cases anyway.
4168 */
4169 switch (iftype) {
4170 case NL80211_IFTYPE_AP:
4171 case NL80211_IFTYPE_AP_VLAN:
4172 case NL80211_IFTYPE_P2P_GO:
4173 params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) |
4174 BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) |
4175 BIT(NL80211_STA_FLAG_WME) |
4176 BIT(NL80211_STA_FLAG_MFP);
4177 break;
4178 case NL80211_IFTYPE_P2P_CLIENT:
4179 case NL80211_IFTYPE_STATION:
4180 params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) |
4181 BIT(NL80211_STA_FLAG_TDLS_PEER);
4182 break;
4183 case NL80211_IFTYPE_MESH_POINT:
4184 params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHENTICATED) |
4185 BIT(NL80211_STA_FLAG_MFP) |
4186 BIT(NL80211_STA_FLAG_AUTHORIZED);
4187 default:
4188 return -EINVAL;
4189 }
Johannes Berg5727ef12007-12-19 02:03:34 +01004190
Johannes Berg3383b5a2012-05-10 20:14:43 +02004191 for (flag = 1; flag <= NL80211_STA_FLAG_MAX; flag++) {
4192 if (flags[flag]) {
Johannes Bergeccb8e82009-05-11 21:57:56 +03004193 params->sta_flags_set |= (1<<flag);
Johannes Berg5727ef12007-12-19 02:03:34 +01004194
Johannes Berg3383b5a2012-05-10 20:14:43 +02004195 /* no longer support new API additions in old API */
4196 if (flag > NL80211_STA_FLAG_MAX_OLD_API)
4197 return -EINVAL;
4198 }
4199 }
4200
Johannes Berg5727ef12007-12-19 02:03:34 +01004201 return 0;
4202}
4203
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01004204static bool nl80211_put_sta_rate(struct sk_buff *msg, struct rate_info *info,
4205 int attr)
4206{
4207 struct nlattr *rate;
Vladimir Kondratiev8eb41c82012-07-05 14:25:49 +03004208 u32 bitrate;
4209 u16 bitrate_compat;
Matthias Kaehlckebbf67e42017-04-17 15:59:52 -07004210 enum nl80211_rate_info rate_flg;
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01004211
4212 rate = nla_nest_start(msg, attr);
4213 if (!rate)
Johannes Bergdb9c64c2012-11-09 14:56:41 +01004214 return false;
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01004215
4216 /* cfg80211_calculate_bitrate will return 0 for mcs >= 32 */
4217 bitrate = cfg80211_calculate_bitrate(info);
Vladimir Kondratiev8eb41c82012-07-05 14:25:49 +03004218 /* report 16-bit bitrate only if we can */
4219 bitrate_compat = bitrate < (1UL << 16) ? bitrate : 0;
Johannes Bergdb9c64c2012-11-09 14:56:41 +01004220 if (bitrate > 0 &&
4221 nla_put_u32(msg, NL80211_RATE_INFO_BITRATE32, bitrate))
4222 return false;
4223 if (bitrate_compat > 0 &&
4224 nla_put_u16(msg, NL80211_RATE_INFO_BITRATE, bitrate_compat))
4225 return false;
4226
Johannes Bergb51f3be2015-01-15 16:14:02 +01004227 switch (info->bw) {
4228 case RATE_INFO_BW_5:
4229 rate_flg = NL80211_RATE_INFO_5_MHZ_WIDTH;
4230 break;
4231 case RATE_INFO_BW_10:
4232 rate_flg = NL80211_RATE_INFO_10_MHZ_WIDTH;
4233 break;
4234 default:
4235 WARN_ON(1);
4236 /* fall through */
4237 case RATE_INFO_BW_20:
4238 rate_flg = 0;
4239 break;
4240 case RATE_INFO_BW_40:
4241 rate_flg = NL80211_RATE_INFO_40_MHZ_WIDTH;
4242 break;
4243 case RATE_INFO_BW_80:
4244 rate_flg = NL80211_RATE_INFO_80_MHZ_WIDTH;
4245 break;
4246 case RATE_INFO_BW_160:
4247 rate_flg = NL80211_RATE_INFO_160_MHZ_WIDTH;
4248 break;
4249 }
4250
4251 if (rate_flg && nla_put_flag(msg, rate_flg))
4252 return false;
4253
Johannes Bergdb9c64c2012-11-09 14:56:41 +01004254 if (info->flags & RATE_INFO_FLAGS_MCS) {
4255 if (nla_put_u8(msg, NL80211_RATE_INFO_MCS, info->mcs))
4256 return false;
Johannes Bergdb9c64c2012-11-09 14:56:41 +01004257 if (info->flags & RATE_INFO_FLAGS_SHORT_GI &&
4258 nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI))
4259 return false;
4260 } else if (info->flags & RATE_INFO_FLAGS_VHT_MCS) {
4261 if (nla_put_u8(msg, NL80211_RATE_INFO_VHT_MCS, info->mcs))
4262 return false;
4263 if (nla_put_u8(msg, NL80211_RATE_INFO_VHT_NSS, info->nss))
4264 return false;
Johannes Bergdb9c64c2012-11-09 14:56:41 +01004265 if (info->flags & RATE_INFO_FLAGS_SHORT_GI &&
4266 nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI))
4267 return false;
4268 }
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01004269
4270 nla_nest_end(msg, rate);
4271 return true;
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01004272}
4273
Felix Fietkau119363c2013-04-22 16:29:30 +02004274static bool nl80211_put_signal(struct sk_buff *msg, u8 mask, s8 *signal,
4275 int id)
4276{
4277 void *attr;
4278 int i = 0;
4279
4280 if (!mask)
4281 return true;
4282
4283 attr = nla_nest_start(msg, id);
4284 if (!attr)
4285 return false;
4286
4287 for (i = 0; i < IEEE80211_MAX_CHAINS; i++) {
4288 if (!(mask & BIT(i)))
4289 continue;
4290
4291 if (nla_put_u8(msg, i, signal[i]))
4292 return false;
4293 }
4294
4295 nla_nest_end(msg, attr);
4296
4297 return true;
4298}
4299
Johannes Bergcf5ead82014-11-14 17:14:00 +01004300static int nl80211_send_station(struct sk_buff *msg, u32 cmd, u32 portid,
4301 u32 seq, int flags,
John W. Linville66266b32012-03-15 13:25:41 -04004302 struct cfg80211_registered_device *rdev,
4303 struct net_device *dev,
Johannes Berg98b62182009-12-23 13:15:44 +01004304 const u8 *mac_addr, struct station_info *sinfo)
Johannes Bergfd5b74d2007-12-19 02:03:36 +01004305{
4306 void *hdr;
Paul Stewartf4263c92011-03-31 09:25:41 -07004307 struct nlattr *sinfoattr, *bss_param;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01004308
Johannes Bergcf5ead82014-11-14 17:14:00 +01004309 hdr = nl80211hdr_put(msg, portid, seq, flags, cmd);
Johannes Bergfd5b74d2007-12-19 02:03:36 +01004310 if (!hdr)
4311 return -1;
4312
David S. Miller9360ffd2012-03-29 04:41:26 -04004313 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
4314 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) ||
4315 nla_put_u32(msg, NL80211_ATTR_GENERATION, sinfo->generation))
4316 goto nla_put_failure;
Johannes Bergf5ea9122009-08-07 16:17:38 +02004317
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004318 sinfoattr = nla_nest_start(msg, NL80211_ATTR_STA_INFO);
4319 if (!sinfoattr)
Johannes Bergfd5b74d2007-12-19 02:03:36 +01004320 goto nla_put_failure;
Johannes Berg319090b2014-11-17 14:08:11 +01004321
4322#define PUT_SINFO(attr, memb, type) do { \
Johannes Bergd686b922016-04-26 09:54:11 +02004323 BUILD_BUG_ON(sizeof(type) == sizeof(u64)); \
Mohammed Shafi Shajakhan739960f2016-04-07 19:59:34 +05304324 if (sinfo->filled & (1ULL << NL80211_STA_INFO_ ## attr) && \
Johannes Berg319090b2014-11-17 14:08:11 +01004325 nla_put_ ## type(msg, NL80211_STA_INFO_ ## attr, \
4326 sinfo->memb)) \
4327 goto nla_put_failure; \
4328 } while (0)
Johannes Bergd686b922016-04-26 09:54:11 +02004329#define PUT_SINFO_U64(attr, memb) do { \
4330 if (sinfo->filled & (1ULL << NL80211_STA_INFO_ ## attr) && \
4331 nla_put_u64_64bit(msg, NL80211_STA_INFO_ ## attr, \
4332 sinfo->memb, NL80211_STA_INFO_PAD)) \
4333 goto nla_put_failure; \
4334 } while (0)
Johannes Berg319090b2014-11-17 14:08:11 +01004335
4336 PUT_SINFO(CONNECTED_TIME, connected_time, u32);
4337 PUT_SINFO(INACTIVE_TIME, inactive_time, u32);
4338
4339 if (sinfo->filled & (BIT(NL80211_STA_INFO_RX_BYTES) |
4340 BIT(NL80211_STA_INFO_RX_BYTES64)) &&
David S. Miller9360ffd2012-03-29 04:41:26 -04004341 nla_put_u32(msg, NL80211_STA_INFO_RX_BYTES,
Vladimir Kondratiev42745e02013-02-04 13:53:11 +02004342 (u32)sinfo->rx_bytes))
4343 goto nla_put_failure;
Johannes Berg319090b2014-11-17 14:08:11 +01004344
4345 if (sinfo->filled & (BIT(NL80211_STA_INFO_TX_BYTES) |
4346 BIT(NL80211_STA_INFO_TX_BYTES64)) &&
Vladimir Kondratiev42745e02013-02-04 13:53:11 +02004347 nla_put_u32(msg, NL80211_STA_INFO_TX_BYTES,
4348 (u32)sinfo->tx_bytes))
4349 goto nla_put_failure;
Johannes Berg319090b2014-11-17 14:08:11 +01004350
Johannes Bergd686b922016-04-26 09:54:11 +02004351 PUT_SINFO_U64(RX_BYTES64, rx_bytes);
4352 PUT_SINFO_U64(TX_BYTES64, tx_bytes);
Johannes Berg319090b2014-11-17 14:08:11 +01004353 PUT_SINFO(LLID, llid, u16);
4354 PUT_SINFO(PLID, plid, u16);
4355 PUT_SINFO(PLINK_STATE, plink_state, u8);
Johannes Bergd686b922016-04-26 09:54:11 +02004356 PUT_SINFO_U64(RX_DURATION, rx_duration);
Johannes Berg319090b2014-11-17 14:08:11 +01004357
John W. Linville66266b32012-03-15 13:25:41 -04004358 switch (rdev->wiphy.signal_type) {
4359 case CFG80211_SIGNAL_TYPE_MBM:
Johannes Berg319090b2014-11-17 14:08:11 +01004360 PUT_SINFO(SIGNAL, signal, u8);
4361 PUT_SINFO(SIGNAL_AVG, signal_avg, u8);
John W. Linville66266b32012-03-15 13:25:41 -04004362 break;
4363 default:
4364 break;
4365 }
Johannes Berg319090b2014-11-17 14:08:11 +01004366 if (sinfo->filled & BIT(NL80211_STA_INFO_CHAIN_SIGNAL)) {
Felix Fietkau119363c2013-04-22 16:29:30 +02004367 if (!nl80211_put_signal(msg, sinfo->chains,
4368 sinfo->chain_signal,
4369 NL80211_STA_INFO_CHAIN_SIGNAL))
4370 goto nla_put_failure;
4371 }
Johannes Berg319090b2014-11-17 14:08:11 +01004372 if (sinfo->filled & BIT(NL80211_STA_INFO_CHAIN_SIGNAL_AVG)) {
Felix Fietkau119363c2013-04-22 16:29:30 +02004373 if (!nl80211_put_signal(msg, sinfo->chains,
4374 sinfo->chain_signal_avg,
4375 NL80211_STA_INFO_CHAIN_SIGNAL_AVG))
4376 goto nla_put_failure;
4377 }
Johannes Berg319090b2014-11-17 14:08:11 +01004378 if (sinfo->filled & BIT(NL80211_STA_INFO_TX_BITRATE)) {
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01004379 if (!nl80211_put_sta_rate(msg, &sinfo->txrate,
4380 NL80211_STA_INFO_TX_BITRATE))
Henning Rogge420e7fa2008-12-11 22:04:19 +01004381 goto nla_put_failure;
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01004382 }
Johannes Berg319090b2014-11-17 14:08:11 +01004383 if (sinfo->filled & BIT(NL80211_STA_INFO_RX_BITRATE)) {
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01004384 if (!nl80211_put_sta_rate(msg, &sinfo->rxrate,
4385 NL80211_STA_INFO_RX_BITRATE))
4386 goto nla_put_failure;
Henning Rogge420e7fa2008-12-11 22:04:19 +01004387 }
Johannes Berg319090b2014-11-17 14:08:11 +01004388
4389 PUT_SINFO(RX_PACKETS, rx_packets, u32);
4390 PUT_SINFO(TX_PACKETS, tx_packets, u32);
4391 PUT_SINFO(TX_RETRIES, tx_retries, u32);
4392 PUT_SINFO(TX_FAILED, tx_failed, u32);
4393 PUT_SINFO(EXPECTED_THROUGHPUT, expected_throughput, u32);
4394 PUT_SINFO(BEACON_LOSS, beacon_loss_count, u32);
4395 PUT_SINFO(LOCAL_PM, local_pm, u32);
4396 PUT_SINFO(PEER_PM, peer_pm, u32);
4397 PUT_SINFO(NONPEER_PM, nonpeer_pm, u32);
4398
4399 if (sinfo->filled & BIT(NL80211_STA_INFO_BSS_PARAM)) {
Paul Stewartf4263c92011-03-31 09:25:41 -07004400 bss_param = nla_nest_start(msg, NL80211_STA_INFO_BSS_PARAM);
4401 if (!bss_param)
4402 goto nla_put_failure;
4403
David S. Miller9360ffd2012-03-29 04:41:26 -04004404 if (((sinfo->bss_param.flags & BSS_PARAM_FLAGS_CTS_PROT) &&
4405 nla_put_flag(msg, NL80211_STA_BSS_PARAM_CTS_PROT)) ||
4406 ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_PREAMBLE) &&
4407 nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_PREAMBLE)) ||
4408 ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_SLOT_TIME) &&
4409 nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_SLOT_TIME)) ||
4410 nla_put_u8(msg, NL80211_STA_BSS_PARAM_DTIM_PERIOD,
4411 sinfo->bss_param.dtim_period) ||
4412 nla_put_u16(msg, NL80211_STA_BSS_PARAM_BEACON_INTERVAL,
4413 sinfo->bss_param.beacon_interval))
4414 goto nla_put_failure;
Paul Stewartf4263c92011-03-31 09:25:41 -07004415
4416 nla_nest_end(msg, bss_param);
4417 }
Johannes Berg319090b2014-11-17 14:08:11 +01004418 if ((sinfo->filled & BIT(NL80211_STA_INFO_STA_FLAGS)) &&
David S. Miller9360ffd2012-03-29 04:41:26 -04004419 nla_put(msg, NL80211_STA_INFO_STA_FLAGS,
4420 sizeof(struct nl80211_sta_flag_update),
4421 &sinfo->sta_flags))
4422 goto nla_put_failure;
Johannes Berg319090b2014-11-17 14:08:11 +01004423
Johannes Bergd686b922016-04-26 09:54:11 +02004424 PUT_SINFO_U64(T_OFFSET, t_offset);
4425 PUT_SINFO_U64(RX_DROP_MISC, rx_dropped_misc);
4426 PUT_SINFO_U64(BEACON_RX, rx_beacon);
Johannes Berga76b1942014-11-17 14:12:22 +01004427 PUT_SINFO(BEACON_SIGNAL_AVG, rx_beacon_signal_avg, u8);
Johannes Berg319090b2014-11-17 14:08:11 +01004428
4429#undef PUT_SINFO
Johannes Bergd686b922016-04-26 09:54:11 +02004430#undef PUT_SINFO_U64
Johannes Berg6de39802014-12-19 12:34:00 +01004431
4432 if (sinfo->filled & BIT(NL80211_STA_INFO_TID_STATS)) {
4433 struct nlattr *tidsattr;
4434 int tid;
4435
4436 tidsattr = nla_nest_start(msg, NL80211_STA_INFO_TID_STATS);
4437 if (!tidsattr)
4438 goto nla_put_failure;
4439
4440 for (tid = 0; tid < IEEE80211_NUM_TIDS + 1; tid++) {
4441 struct cfg80211_tid_stats *tidstats;
4442 struct nlattr *tidattr;
4443
4444 tidstats = &sinfo->pertid[tid];
4445
4446 if (!tidstats->filled)
4447 continue;
4448
4449 tidattr = nla_nest_start(msg, tid + 1);
4450 if (!tidattr)
4451 goto nla_put_failure;
4452
Johannes Bergd686b922016-04-26 09:54:11 +02004453#define PUT_TIDVAL_U64(attr, memb) do { \
Johannes Berg6de39802014-12-19 12:34:00 +01004454 if (tidstats->filled & BIT(NL80211_TID_STATS_ ## attr) && \
Johannes Bergd686b922016-04-26 09:54:11 +02004455 nla_put_u64_64bit(msg, NL80211_TID_STATS_ ## attr, \
4456 tidstats->memb, NL80211_TID_STATS_PAD)) \
Johannes Berg6de39802014-12-19 12:34:00 +01004457 goto nla_put_failure; \
4458 } while (0)
4459
Johannes Bergd686b922016-04-26 09:54:11 +02004460 PUT_TIDVAL_U64(RX_MSDU, rx_msdu);
4461 PUT_TIDVAL_U64(TX_MSDU, tx_msdu);
4462 PUT_TIDVAL_U64(TX_MSDU_RETRIES, tx_msdu_retries);
4463 PUT_TIDVAL_U64(TX_MSDU_FAILED, tx_msdu_failed);
Johannes Berg6de39802014-12-19 12:34:00 +01004464
Johannes Bergd686b922016-04-26 09:54:11 +02004465#undef PUT_TIDVAL_U64
Johannes Berg6de39802014-12-19 12:34:00 +01004466 nla_nest_end(msg, tidattr);
4467 }
4468
4469 nla_nest_end(msg, tidsattr);
4470 }
4471
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004472 nla_nest_end(msg, sinfoattr);
Johannes Bergfd5b74d2007-12-19 02:03:36 +01004473
Johannes Berg319090b2014-11-17 14:08:11 +01004474 if (sinfo->assoc_req_ies_len &&
David S. Miller9360ffd2012-03-29 04:41:26 -04004475 nla_put(msg, NL80211_ATTR_IE, sinfo->assoc_req_ies_len,
4476 sinfo->assoc_req_ies))
4477 goto nla_put_failure;
Jouni Malinen50d3dfb2011-08-08 12:11:52 +03004478
Johannes Berg053c0952015-01-16 22:09:00 +01004479 genlmsg_end(msg, hdr);
4480 return 0;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01004481
4482 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07004483 genlmsg_cancel(msg, hdr);
4484 return -EMSGSIZE;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01004485}
4486
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004487static int nl80211_dump_station(struct sk_buff *skb,
Johannes Bergbba95fe2008-07-29 13:22:51 +02004488 struct netlink_callback *cb)
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004489{
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004490 struct station_info sinfo;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08004491 struct cfg80211_registered_device *rdev;
Johannes Berg97990a02013-04-19 01:02:55 +02004492 struct wireless_dev *wdev;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004493 u8 mac_addr[ETH_ALEN];
Johannes Berg97990a02013-04-19 01:02:55 +02004494 int sta_idx = cb->args[2];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004495 int err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004496
Johannes Bergea90e0d2017-03-15 14:26:04 +01004497 rtnl_lock();
Zhao, Gang1b8ec872014-04-21 12:53:02 +08004498 err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev);
Johannes Berg67748892010-10-04 21:14:06 +02004499 if (err)
Johannes Bergea90e0d2017-03-15 14:26:04 +01004500 goto out_err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004501
Johannes Berg97990a02013-04-19 01:02:55 +02004502 if (!wdev->netdev) {
4503 err = -EINVAL;
4504 goto out_err;
4505 }
4506
Zhao, Gang1b8ec872014-04-21 12:53:02 +08004507 if (!rdev->ops->dump_station) {
Jouni Malineneec60b02009-03-20 21:21:19 +02004508 err = -EOPNOTSUPP;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004509 goto out_err;
4510 }
4511
Johannes Bergbba95fe2008-07-29 13:22:51 +02004512 while (1) {
Jouni Malinenf612ced2011-08-11 11:46:22 +03004513 memset(&sinfo, 0, sizeof(sinfo));
Zhao, Gang1b8ec872014-04-21 12:53:02 +08004514 err = rdev_dump_station(rdev, wdev->netdev, sta_idx,
Hila Gonene35e4d22012-06-27 17:19:42 +03004515 mac_addr, &sinfo);
Johannes Bergbba95fe2008-07-29 13:22:51 +02004516 if (err == -ENOENT)
4517 break;
4518 if (err)
Johannes Berg3b858752009-03-12 09:55:09 +01004519 goto out_err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004520
Johannes Bergcf5ead82014-11-14 17:14:00 +01004521 if (nl80211_send_station(skb, NL80211_CMD_NEW_STATION,
Eric W. Biederman15e47302012-09-07 20:12:54 +00004522 NETLINK_CB(cb->skb).portid,
Johannes Bergbba95fe2008-07-29 13:22:51 +02004523 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08004524 rdev, wdev->netdev, mac_addr,
Johannes Bergbba95fe2008-07-29 13:22:51 +02004525 &sinfo) < 0)
4526 goto out;
4527
4528 sta_idx++;
4529 }
4530
Johannes Bergbba95fe2008-07-29 13:22:51 +02004531 out:
Johannes Berg97990a02013-04-19 01:02:55 +02004532 cb->args[2] = sta_idx;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004533 err = skb->len;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004534 out_err:
Johannes Bergea90e0d2017-03-15 14:26:04 +01004535 rtnl_unlock();
Johannes Bergbba95fe2008-07-29 13:22:51 +02004536
4537 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004538}
Johannes Bergfd5b74d2007-12-19 02:03:36 +01004539
Johannes Berg5727ef12007-12-19 02:03:34 +01004540static int nl80211_get_station(struct sk_buff *skb, struct genl_info *info)
4541{
Johannes Berg4c476992010-10-04 21:36:35 +02004542 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4543 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004544 struct station_info sinfo;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01004545 struct sk_buff *msg;
4546 u8 *mac_addr = NULL;
Johannes Berg4c476992010-10-04 21:36:35 +02004547 int err;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01004548
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004549 memset(&sinfo, 0, sizeof(sinfo));
Johannes Bergfd5b74d2007-12-19 02:03:36 +01004550
4551 if (!info->attrs[NL80211_ATTR_MAC])
4552 return -EINVAL;
4553
4554 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
4555
Johannes Berg4c476992010-10-04 21:36:35 +02004556 if (!rdev->ops->get_station)
4557 return -EOPNOTSUPP;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01004558
Hila Gonene35e4d22012-06-27 17:19:42 +03004559 err = rdev_get_station(rdev, dev, mac_addr, &sinfo);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004560 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02004561 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004562
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07004563 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Bergfd5b74d2007-12-19 02:03:36 +01004564 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02004565 return -ENOMEM;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01004566
Johannes Bergcf5ead82014-11-14 17:14:00 +01004567 if (nl80211_send_station(msg, NL80211_CMD_NEW_STATION,
4568 info->snd_portid, info->snd_seq, 0,
John W. Linville66266b32012-03-15 13:25:41 -04004569 rdev, dev, mac_addr, &sinfo) < 0) {
Johannes Berg4c476992010-10-04 21:36:35 +02004570 nlmsg_free(msg);
4571 return -ENOBUFS;
4572 }
Johannes Bergfd5b74d2007-12-19 02:03:36 +01004573
Johannes Berg4c476992010-10-04 21:36:35 +02004574 return genlmsg_reply(msg, info);
Johannes Berg5727ef12007-12-19 02:03:34 +01004575}
4576
Johannes Berg77ee7c82013-02-15 00:48:33 +01004577int cfg80211_check_station_change(struct wiphy *wiphy,
4578 struct station_parameters *params,
4579 enum cfg80211_station_type statype)
4580{
Ayala Bekere4208422015-10-23 11:20:06 +03004581 if (params->listen_interval != -1 &&
4582 statype != CFG80211_STA_AP_CLIENT_UNASSOC)
Johannes Berg77ee7c82013-02-15 00:48:33 +01004583 return -EINVAL;
Ayala Bekere4208422015-10-23 11:20:06 +03004584
Ayala Beker17b94242016-03-17 15:41:38 +02004585 if (params->support_p2p_ps != -1 &&
4586 statype != CFG80211_STA_AP_CLIENT_UNASSOC)
4587 return -EINVAL;
4588
Arik Nemtsovc72e1142014-07-17 17:14:29 +03004589 if (params->aid &&
Ayala Bekere4208422015-10-23 11:20:06 +03004590 !(params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) &&
4591 statype != CFG80211_STA_AP_CLIENT_UNASSOC)
Johannes Berg77ee7c82013-02-15 00:48:33 +01004592 return -EINVAL;
4593
4594 /* When you run into this, adjust the code below for the new flag */
4595 BUILD_BUG_ON(NL80211_STA_FLAG_MAX != 7);
4596
4597 switch (statype) {
Thomas Pederseneef941e2013-03-04 13:06:11 -08004598 case CFG80211_STA_MESH_PEER_KERNEL:
4599 case CFG80211_STA_MESH_PEER_USER:
Johannes Berg77ee7c82013-02-15 00:48:33 +01004600 /*
4601 * No ignoring the TDLS flag here -- the userspace mesh
4602 * code doesn't have the bug of including TDLS in the
4603 * mask everywhere.
4604 */
4605 if (params->sta_flags_mask &
4606 ~(BIT(NL80211_STA_FLAG_AUTHENTICATED) |
4607 BIT(NL80211_STA_FLAG_MFP) |
4608 BIT(NL80211_STA_FLAG_AUTHORIZED)))
4609 return -EINVAL;
4610 break;
4611 case CFG80211_STA_TDLS_PEER_SETUP:
4612 case CFG80211_STA_TDLS_PEER_ACTIVE:
4613 if (!(params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)))
4614 return -EINVAL;
4615 /* ignore since it can't change */
4616 params->sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER);
4617 break;
4618 default:
4619 /* disallow mesh-specific things */
4620 if (params->plink_action != NL80211_PLINK_ACTION_NO_ACTION)
4621 return -EINVAL;
4622 if (params->local_pm)
4623 return -EINVAL;
4624 if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE)
4625 return -EINVAL;
4626 }
4627
4628 if (statype != CFG80211_STA_TDLS_PEER_SETUP &&
4629 statype != CFG80211_STA_TDLS_PEER_ACTIVE) {
4630 /* TDLS can't be set, ... */
4631 if (params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))
4632 return -EINVAL;
4633 /*
4634 * ... but don't bother the driver with it. This works around
4635 * a hostapd/wpa_supplicant issue -- it always includes the
4636 * TLDS_PEER flag in the mask even for AP mode.
4637 */
4638 params->sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER);
4639 }
4640
Ayala Beker47edb112015-09-21 15:49:53 +03004641 if (statype != CFG80211_STA_TDLS_PEER_SETUP &&
4642 statype != CFG80211_STA_AP_CLIENT_UNASSOC) {
Johannes Berg77ee7c82013-02-15 00:48:33 +01004643 /* reject other things that can't change */
4644 if (params->sta_modify_mask & STATION_PARAM_APPLY_UAPSD)
4645 return -EINVAL;
4646 if (params->sta_modify_mask & STATION_PARAM_APPLY_CAPABILITY)
4647 return -EINVAL;
4648 if (params->supported_rates)
4649 return -EINVAL;
4650 if (params->ext_capab || params->ht_capa || params->vht_capa)
4651 return -EINVAL;
4652 }
4653
Ayala Beker47edb112015-09-21 15:49:53 +03004654 if (statype != CFG80211_STA_AP_CLIENT &&
4655 statype != CFG80211_STA_AP_CLIENT_UNASSOC) {
Johannes Berg77ee7c82013-02-15 00:48:33 +01004656 if (params->vlan)
4657 return -EINVAL;
4658 }
4659
4660 switch (statype) {
4661 case CFG80211_STA_AP_MLME_CLIENT:
4662 /* Use this only for authorizing/unauthorizing a station */
4663 if (!(params->sta_flags_mask & BIT(NL80211_STA_FLAG_AUTHORIZED)))
4664 return -EOPNOTSUPP;
4665 break;
4666 case CFG80211_STA_AP_CLIENT:
Ayala Beker47edb112015-09-21 15:49:53 +03004667 case CFG80211_STA_AP_CLIENT_UNASSOC:
Johannes Berg77ee7c82013-02-15 00:48:33 +01004668 /* accept only the listed bits */
4669 if (params->sta_flags_mask &
4670 ~(BIT(NL80211_STA_FLAG_AUTHORIZED) |
4671 BIT(NL80211_STA_FLAG_AUTHENTICATED) |
4672 BIT(NL80211_STA_FLAG_ASSOCIATED) |
4673 BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) |
4674 BIT(NL80211_STA_FLAG_WME) |
4675 BIT(NL80211_STA_FLAG_MFP)))
4676 return -EINVAL;
4677
4678 /* but authenticated/associated only if driver handles it */
4679 if (!(wiphy->features & NL80211_FEATURE_FULL_AP_CLIENT_STATE) &&
4680 params->sta_flags_mask &
4681 (BIT(NL80211_STA_FLAG_AUTHENTICATED) |
4682 BIT(NL80211_STA_FLAG_ASSOCIATED)))
4683 return -EINVAL;
4684 break;
4685 case CFG80211_STA_IBSS:
4686 case CFG80211_STA_AP_STA:
4687 /* reject any changes other than AUTHORIZED */
4688 if (params->sta_flags_mask & ~BIT(NL80211_STA_FLAG_AUTHORIZED))
4689 return -EINVAL;
4690 break;
4691 case CFG80211_STA_TDLS_PEER_SETUP:
4692 /* reject any changes other than AUTHORIZED or WME */
4693 if (params->sta_flags_mask & ~(BIT(NL80211_STA_FLAG_AUTHORIZED) |
4694 BIT(NL80211_STA_FLAG_WME)))
4695 return -EINVAL;
4696 /* force (at least) rates when authorizing */
4697 if (params->sta_flags_set & BIT(NL80211_STA_FLAG_AUTHORIZED) &&
4698 !params->supported_rates)
4699 return -EINVAL;
4700 break;
4701 case CFG80211_STA_TDLS_PEER_ACTIVE:
4702 /* reject any changes */
4703 return -EINVAL;
Thomas Pederseneef941e2013-03-04 13:06:11 -08004704 case CFG80211_STA_MESH_PEER_KERNEL:
Johannes Berg77ee7c82013-02-15 00:48:33 +01004705 if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE)
4706 return -EINVAL;
4707 break;
Thomas Pederseneef941e2013-03-04 13:06:11 -08004708 case CFG80211_STA_MESH_PEER_USER:
Chun-Yeow Yeoh42925042015-04-18 01:30:02 +08004709 if (params->plink_action != NL80211_PLINK_ACTION_NO_ACTION &&
4710 params->plink_action != NL80211_PLINK_ACTION_BLOCK)
Johannes Berg77ee7c82013-02-15 00:48:33 +01004711 return -EINVAL;
4712 break;
4713 }
4714
Beni Lev06f7c882016-07-19 19:28:56 +03004715 /*
4716 * Older kernel versions ignored this attribute entirely, so don't
4717 * reject attempts to update it but mark it as unused instead so the
4718 * driver won't look at the data.
4719 */
4720 if (statype != CFG80211_STA_AP_CLIENT_UNASSOC &&
4721 statype != CFG80211_STA_TDLS_PEER_SETUP)
4722 params->opmode_notif_used = false;
4723
Johannes Berg77ee7c82013-02-15 00:48:33 +01004724 return 0;
4725}
4726EXPORT_SYMBOL(cfg80211_check_station_change);
4727
Johannes Berg5727ef12007-12-19 02:03:34 +01004728/*
Felix Fietkauc258d2d2009-11-11 17:23:31 +01004729 * Get vlan interface making sure it is running and on the right wiphy.
Johannes Berg5727ef12007-12-19 02:03:34 +01004730 */
Johannes Berg80b99892011-11-18 16:23:01 +01004731static struct net_device *get_vlan(struct genl_info *info,
4732 struct cfg80211_registered_device *rdev)
Johannes Berg5727ef12007-12-19 02:03:34 +01004733{
Johannes Berg463d0182009-07-14 00:33:35 +02004734 struct nlattr *vlanattr = info->attrs[NL80211_ATTR_STA_VLAN];
Johannes Berg80b99892011-11-18 16:23:01 +01004735 struct net_device *v;
4736 int ret;
Johannes Berg5727ef12007-12-19 02:03:34 +01004737
Johannes Berg80b99892011-11-18 16:23:01 +01004738 if (!vlanattr)
4739 return NULL;
4740
4741 v = dev_get_by_index(genl_info_net(info), nla_get_u32(vlanattr));
4742 if (!v)
4743 return ERR_PTR(-ENODEV);
4744
4745 if (!v->ieee80211_ptr || v->ieee80211_ptr->wiphy != &rdev->wiphy) {
4746 ret = -EINVAL;
4747 goto error;
Johannes Berg5727ef12007-12-19 02:03:34 +01004748 }
Johannes Berg80b99892011-11-18 16:23:01 +01004749
Johannes Berg77ee7c82013-02-15 00:48:33 +01004750 if (v->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN &&
4751 v->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
4752 v->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) {
4753 ret = -EINVAL;
4754 goto error;
4755 }
4756
Johannes Berg80b99892011-11-18 16:23:01 +01004757 if (!netif_running(v)) {
4758 ret = -ENETDOWN;
4759 goto error;
4760 }
4761
4762 return v;
4763 error:
4764 dev_put(v);
4765 return ERR_PTR(ret);
Johannes Berg5727ef12007-12-19 02:03:34 +01004766}
4767
Johannes Berg94e860f2014-01-20 23:58:15 +01004768static const struct nla_policy
4769nl80211_sta_wme_policy[NL80211_STA_WME_MAX + 1] = {
Jouni Malinendf881292013-02-14 21:10:54 +02004770 [NL80211_STA_WME_UAPSD_QUEUES] = { .type = NLA_U8 },
4771 [NL80211_STA_WME_MAX_SP] = { .type = NLA_U8 },
4772};
4773
Johannes Bergff276692013-02-15 00:09:01 +01004774static int nl80211_parse_sta_wme(struct genl_info *info,
4775 struct station_parameters *params)
Jouni Malinendf881292013-02-14 21:10:54 +02004776{
Jouni Malinendf881292013-02-14 21:10:54 +02004777 struct nlattr *tb[NL80211_STA_WME_MAX + 1];
4778 struct nlattr *nla;
4779 int err;
4780
Jouni Malinendf881292013-02-14 21:10:54 +02004781 /* parse WME attributes if present */
4782 if (!info->attrs[NL80211_ATTR_STA_WME])
4783 return 0;
4784
4785 nla = info->attrs[NL80211_ATTR_STA_WME];
4786 err = nla_parse_nested(tb, NL80211_STA_WME_MAX, nla,
Johannes Bergfe521452017-04-12 14:34:08 +02004787 nl80211_sta_wme_policy, info->extack);
Jouni Malinendf881292013-02-14 21:10:54 +02004788 if (err)
4789 return err;
4790
4791 if (tb[NL80211_STA_WME_UAPSD_QUEUES])
4792 params->uapsd_queues = nla_get_u8(
4793 tb[NL80211_STA_WME_UAPSD_QUEUES]);
4794 if (params->uapsd_queues & ~IEEE80211_WMM_IE_STA_QOSINFO_AC_MASK)
4795 return -EINVAL;
4796
4797 if (tb[NL80211_STA_WME_MAX_SP])
4798 params->max_sp = nla_get_u8(tb[NL80211_STA_WME_MAX_SP]);
4799
4800 if (params->max_sp & ~IEEE80211_WMM_IE_STA_QOSINFO_SP_MASK)
4801 return -EINVAL;
4802
4803 params->sta_modify_mask |= STATION_PARAM_APPLY_UAPSD;
4804
4805 return 0;
4806}
4807
Sunil Duttc01fc9a2013-10-09 20:45:21 +05304808static int nl80211_parse_sta_channel_info(struct genl_info *info,
4809 struct station_parameters *params)
4810{
4811 if (info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]) {
4812 params->supported_channels =
4813 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]);
4814 params->supported_channels_len =
4815 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]);
4816 /*
4817 * Need to include at least one (first channel, number of
4818 * channels) tuple for each subband, and must have proper
4819 * tuples for the rest of the data as well.
4820 */
4821 if (params->supported_channels_len < 2)
4822 return -EINVAL;
4823 if (params->supported_channels_len % 2)
4824 return -EINVAL;
4825 }
4826
4827 if (info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]) {
4828 params->supported_oper_classes =
4829 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]);
4830 params->supported_oper_classes_len =
4831 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]);
4832 /*
4833 * The value of the Length field of the Supported Operating
4834 * Classes element is between 2 and 253.
4835 */
4836 if (params->supported_oper_classes_len < 2 ||
4837 params->supported_oper_classes_len > 253)
4838 return -EINVAL;
4839 }
4840 return 0;
4841}
4842
Johannes Bergff276692013-02-15 00:09:01 +01004843static int nl80211_set_station_tdls(struct genl_info *info,
4844 struct station_parameters *params)
4845{
Sunil Duttc01fc9a2013-10-09 20:45:21 +05304846 int err;
Johannes Bergff276692013-02-15 00:09:01 +01004847 /* Dummy STA entry gets updated once the peer capabilities are known */
Jouni Malinen5e4b6f52013-05-16 20:11:08 +03004848 if (info->attrs[NL80211_ATTR_PEER_AID])
4849 params->aid = nla_get_u16(info->attrs[NL80211_ATTR_PEER_AID]);
Johannes Bergff276692013-02-15 00:09:01 +01004850 if (info->attrs[NL80211_ATTR_HT_CAPABILITY])
4851 params->ht_capa =
4852 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]);
4853 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY])
4854 params->vht_capa =
4855 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]);
4856
Sunil Duttc01fc9a2013-10-09 20:45:21 +05304857 err = nl80211_parse_sta_channel_info(info, params);
4858 if (err)
4859 return err;
4860
Johannes Bergff276692013-02-15 00:09:01 +01004861 return nl80211_parse_sta_wme(info, params);
4862}
4863
Johannes Berg5727ef12007-12-19 02:03:34 +01004864static int nl80211_set_station(struct sk_buff *skb, struct genl_info *info)
4865{
Johannes Berg4c476992010-10-04 21:36:35 +02004866 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg4c476992010-10-04 21:36:35 +02004867 struct net_device *dev = info->user_ptr[1];
Johannes Berg5727ef12007-12-19 02:03:34 +01004868 struct station_parameters params;
Johannes Berg77ee7c82013-02-15 00:48:33 +01004869 u8 *mac_addr;
4870 int err;
Johannes Berg5727ef12007-12-19 02:03:34 +01004871
4872 memset(&params, 0, sizeof(params));
4873
Johannes Berg77ee7c82013-02-15 00:48:33 +01004874 if (!rdev->ops->change_station)
4875 return -EOPNOTSUPP;
4876
Ayala Bekere4208422015-10-23 11:20:06 +03004877 /*
4878 * AID and listen_interval properties can be set only for unassociated
4879 * station. Include these parameters here and will check them in
4880 * cfg80211_check_station_change().
4881 */
Ayala Bekera9bc31e2015-11-26 16:26:12 +01004882 if (info->attrs[NL80211_ATTR_STA_AID])
4883 params.aid = nla_get_u16(info->attrs[NL80211_ATTR_STA_AID]);
Ayala Bekere4208422015-10-23 11:20:06 +03004884
4885 if (info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL])
4886 params.listen_interval =
4887 nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]);
4888 else
4889 params.listen_interval = -1;
Johannes Berg5727ef12007-12-19 02:03:34 +01004890
Ayala Beker17b94242016-03-17 15:41:38 +02004891 if (info->attrs[NL80211_ATTR_STA_SUPPORT_P2P_PS]) {
4892 u8 tmp;
4893
4894 tmp = nla_get_u8(info->attrs[NL80211_ATTR_STA_SUPPORT_P2P_PS]);
4895 if (tmp >= NUM_NL80211_P2P_PS_STATUS)
4896 return -EINVAL;
4897
4898 params.support_p2p_ps = tmp;
4899 } else {
4900 params.support_p2p_ps = -1;
4901 }
4902
Johannes Berg5727ef12007-12-19 02:03:34 +01004903 if (!info->attrs[NL80211_ATTR_MAC])
4904 return -EINVAL;
4905
4906 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
4907
4908 if (info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) {
4909 params.supported_rates =
4910 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
4911 params.supported_rates_len =
4912 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
4913 }
4914
Jouni Malinen9d62a982013-02-14 21:10:13 +02004915 if (info->attrs[NL80211_ATTR_STA_CAPABILITY]) {
4916 params.capability =
4917 nla_get_u16(info->attrs[NL80211_ATTR_STA_CAPABILITY]);
4918 params.sta_modify_mask |= STATION_PARAM_APPLY_CAPABILITY;
4919 }
4920
4921 if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]) {
4922 params.ext_capab =
4923 nla_data(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
4924 params.ext_capab_len =
4925 nla_len(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
4926 }
4927
Johannes Bergbdd3ae32012-01-02 13:30:03 +01004928 if (parse_station_flags(info, dev->ieee80211_ptr->iftype, &params))
Johannes Berg5727ef12007-12-19 02:03:34 +01004929 return -EINVAL;
4930
Johannes Bergf8bacc22013-02-14 23:27:01 +01004931 if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) {
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004932 params.plink_action =
Johannes Bergf8bacc22013-02-14 23:27:01 +01004933 nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]);
4934 if (params.plink_action >= NUM_NL80211_PLINK_ACTIONS)
4935 return -EINVAL;
4936 }
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004937
Johannes Bergf8bacc22013-02-14 23:27:01 +01004938 if (info->attrs[NL80211_ATTR_STA_PLINK_STATE]) {
Javier Cardona9c3990a2011-05-03 16:57:11 -07004939 params.plink_state =
Johannes Bergf8bacc22013-02-14 23:27:01 +01004940 nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_STATE]);
4941 if (params.plink_state >= NUM_NL80211_PLINK_STATES)
4942 return -EINVAL;
Masashi Honma7d27a0b2016-07-01 10:19:34 +09004943 if (info->attrs[NL80211_ATTR_MESH_PEER_AID]) {
4944 params.peer_aid = nla_get_u16(
4945 info->attrs[NL80211_ATTR_MESH_PEER_AID]);
4946 if (params.peer_aid > IEEE80211_MAX_AID)
4947 return -EINVAL;
4948 }
Johannes Bergf8bacc22013-02-14 23:27:01 +01004949 params.sta_modify_mask |= STATION_PARAM_APPLY_PLINK_STATE;
4950 }
Javier Cardona9c3990a2011-05-03 16:57:11 -07004951
Marco Porsch3b1c5a52013-01-07 16:04:52 +01004952 if (info->attrs[NL80211_ATTR_LOCAL_MESH_POWER_MODE]) {
4953 enum nl80211_mesh_power_mode pm = nla_get_u32(
4954 info->attrs[NL80211_ATTR_LOCAL_MESH_POWER_MODE]);
4955
4956 if (pm <= NL80211_MESH_POWER_UNKNOWN ||
4957 pm > NL80211_MESH_POWER_MAX)
4958 return -EINVAL;
4959
4960 params.local_pm = pm;
4961 }
4962
Beni Lev06f7c882016-07-19 19:28:56 +03004963 if (info->attrs[NL80211_ATTR_OPMODE_NOTIF]) {
4964 params.opmode_notif_used = true;
4965 params.opmode_notif =
4966 nla_get_u8(info->attrs[NL80211_ATTR_OPMODE_NOTIF]);
4967 }
4968
Johannes Berg77ee7c82013-02-15 00:48:33 +01004969 /* Include parameters for TDLS peer (will check later) */
4970 err = nl80211_set_station_tdls(info, &params);
4971 if (err)
4972 return err;
4973
4974 params.vlan = get_vlan(info, rdev);
4975 if (IS_ERR(params.vlan))
4976 return PTR_ERR(params.vlan);
4977
Johannes Berga97f4422009-06-18 17:23:43 +02004978 switch (dev->ieee80211_ptr->iftype) {
4979 case NL80211_IFTYPE_AP:
4980 case NL80211_IFTYPE_AP_VLAN:
Johannes Berg074ac8d2010-09-16 14:58:22 +02004981 case NL80211_IFTYPE_P2P_GO:
Johannes Berg074ac8d2010-09-16 14:58:22 +02004982 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Berga97f4422009-06-18 17:23:43 +02004983 case NL80211_IFTYPE_STATION:
Antonio Quartulli267335d2012-01-31 20:25:47 +01004984 case NL80211_IFTYPE_ADHOC:
Johannes Berga97f4422009-06-18 17:23:43 +02004985 case NL80211_IFTYPE_MESH_POINT:
Johannes Berga97f4422009-06-18 17:23:43 +02004986 break;
4987 default:
Johannes Berg77ee7c82013-02-15 00:48:33 +01004988 err = -EOPNOTSUPP;
4989 goto out_put_vlan;
Johannes Berg034d6552009-05-27 10:35:29 +02004990 }
4991
Johannes Berg77ee7c82013-02-15 00:48:33 +01004992 /* driver will call cfg80211_check_station_change() */
Hila Gonene35e4d22012-06-27 17:19:42 +03004993 err = rdev_change_station(rdev, dev, mac_addr, &params);
Johannes Berg5727ef12007-12-19 02:03:34 +01004994
Johannes Berg77ee7c82013-02-15 00:48:33 +01004995 out_put_vlan:
Johannes Berg5727ef12007-12-19 02:03:34 +01004996 if (params.vlan)
4997 dev_put(params.vlan);
Johannes Berg3b858752009-03-12 09:55:09 +01004998
Johannes Berg5727ef12007-12-19 02:03:34 +01004999 return err;
5000}
5001
5002static int nl80211_new_station(struct sk_buff *skb, struct genl_info *info)
5003{
Johannes Berg4c476992010-10-04 21:36:35 +02005004 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg5727ef12007-12-19 02:03:34 +01005005 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02005006 struct net_device *dev = info->user_ptr[1];
Johannes Berg5727ef12007-12-19 02:03:34 +01005007 struct station_parameters params;
5008 u8 *mac_addr = NULL;
Johannes Bergbda95eb2015-11-26 16:26:13 +01005009 u32 auth_assoc = BIT(NL80211_STA_FLAG_AUTHENTICATED) |
5010 BIT(NL80211_STA_FLAG_ASSOCIATED);
Johannes Berg5727ef12007-12-19 02:03:34 +01005011
5012 memset(&params, 0, sizeof(params));
5013
Johannes Berg984c3112013-02-14 23:43:25 +01005014 if (!rdev->ops->add_station)
5015 return -EOPNOTSUPP;
5016
Johannes Berg5727ef12007-12-19 02:03:34 +01005017 if (!info->attrs[NL80211_ATTR_MAC])
5018 return -EINVAL;
5019
Johannes Berg5727ef12007-12-19 02:03:34 +01005020 if (!info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL])
5021 return -EINVAL;
5022
5023 if (!info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES])
5024 return -EINVAL;
5025
Jouni Malinen5e4b6f52013-05-16 20:11:08 +03005026 if (!info->attrs[NL80211_ATTR_STA_AID] &&
5027 !info->attrs[NL80211_ATTR_PEER_AID])
Thadeu Lima de Souza Cascardo0e956c12010-02-12 12:34:50 -02005028 return -EINVAL;
5029
Johannes Berg5727ef12007-12-19 02:03:34 +01005030 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
5031 params.supported_rates =
5032 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
5033 params.supported_rates_len =
5034 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
5035 params.listen_interval =
5036 nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]);
Johannes Berg51b50fb2009-05-24 16:42:30 +02005037
Ayala Beker17b94242016-03-17 15:41:38 +02005038 if (info->attrs[NL80211_ATTR_STA_SUPPORT_P2P_PS]) {
5039 u8 tmp;
5040
5041 tmp = nla_get_u8(info->attrs[NL80211_ATTR_STA_SUPPORT_P2P_PS]);
5042 if (tmp >= NUM_NL80211_P2P_PS_STATUS)
5043 return -EINVAL;
5044
5045 params.support_p2p_ps = tmp;
5046 } else {
5047 /*
5048 * if not specified, assume it's supported for P2P GO interface,
5049 * and is NOT supported for AP interface
5050 */
5051 params.support_p2p_ps =
5052 dev->ieee80211_ptr->iftype == NL80211_IFTYPE_P2P_GO;
5053 }
5054
Jouni Malinen3d124ea2013-05-27 18:24:02 +03005055 if (info->attrs[NL80211_ATTR_PEER_AID])
Jouni Malinen5e4b6f52013-05-16 20:11:08 +03005056 params.aid = nla_get_u16(info->attrs[NL80211_ATTR_PEER_AID]);
Jouni Malinen3d124ea2013-05-27 18:24:02 +03005057 else
5058 params.aid = nla_get_u16(info->attrs[NL80211_ATTR_STA_AID]);
Thadeu Lima de Souza Cascardo0e956c12010-02-12 12:34:50 -02005059 if (!params.aid || params.aid > IEEE80211_MAX_AID)
5060 return -EINVAL;
Johannes Berg51b50fb2009-05-24 16:42:30 +02005061
Jouni Malinen9d62a982013-02-14 21:10:13 +02005062 if (info->attrs[NL80211_ATTR_STA_CAPABILITY]) {
5063 params.capability =
5064 nla_get_u16(info->attrs[NL80211_ATTR_STA_CAPABILITY]);
5065 params.sta_modify_mask |= STATION_PARAM_APPLY_CAPABILITY;
5066 }
5067
5068 if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]) {
5069 params.ext_capab =
5070 nla_data(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
5071 params.ext_capab_len =
5072 nla_len(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
5073 }
5074
Jouni Malinen36aedc92008-08-25 11:58:58 +03005075 if (info->attrs[NL80211_ATTR_HT_CAPABILITY])
5076 params.ht_capa =
5077 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]);
Johannes Berg5727ef12007-12-19 02:03:34 +01005078
Mahesh Palivelaf461be3e2012-10-11 08:04:52 +00005079 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY])
5080 params.vht_capa =
5081 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]);
5082
Marek Kwaczynski60f4a7b2013-12-03 10:04:59 +01005083 if (info->attrs[NL80211_ATTR_OPMODE_NOTIF]) {
5084 params.opmode_notif_used = true;
5085 params.opmode_notif =
5086 nla_get_u8(info->attrs[NL80211_ATTR_OPMODE_NOTIF]);
5087 }
5088
Johannes Bergf8bacc22013-02-14 23:27:01 +01005089 if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) {
Javier Cardona96b78df2011-04-07 15:08:33 -07005090 params.plink_action =
Johannes Bergf8bacc22013-02-14 23:27:01 +01005091 nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]);
5092 if (params.plink_action >= NUM_NL80211_PLINK_ACTIONS)
5093 return -EINVAL;
5094 }
Javier Cardona96b78df2011-04-07 15:08:33 -07005095
Sunil Duttc01fc9a2013-10-09 20:45:21 +05305096 err = nl80211_parse_sta_channel_info(info, &params);
5097 if (err)
5098 return err;
5099
Johannes Bergff276692013-02-15 00:09:01 +01005100 err = nl80211_parse_sta_wme(info, &params);
5101 if (err)
5102 return err;
Johannes Bergbdd90d52011-12-14 12:20:27 +01005103
Johannes Bergbdd3ae32012-01-02 13:30:03 +01005104 if (parse_station_flags(info, dev->ieee80211_ptr->iftype, &params))
Johannes Berg5727ef12007-12-19 02:03:34 +01005105 return -EINVAL;
5106
Johannes Berg496fcc22015-03-12 08:53:27 +02005107 /* HT/VHT requires QoS, but if we don't have that just ignore HT/VHT
5108 * as userspace might just pass through the capabilities from the IEs
5109 * directly, rather than enforcing this restriction and returning an
5110 * error in this case.
5111 */
5112 if (!(params.sta_flags_set & BIT(NL80211_STA_FLAG_WME))) {
5113 params.ht_capa = NULL;
5114 params.vht_capa = NULL;
5115 }
5116
Johannes Berg77ee7c82013-02-15 00:48:33 +01005117 /* When you run into this, adjust the code below for the new flag */
5118 BUILD_BUG_ON(NL80211_STA_FLAG_MAX != 7);
5119
Johannes Bergbdd90d52011-12-14 12:20:27 +01005120 switch (dev->ieee80211_ptr->iftype) {
5121 case NL80211_IFTYPE_AP:
5122 case NL80211_IFTYPE_AP_VLAN:
5123 case NL80211_IFTYPE_P2P_GO:
Johannes Berg984c3112013-02-14 23:43:25 +01005124 /* ignore WME attributes if iface/sta is not capable */
5125 if (!(rdev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) ||
5126 !(params.sta_flags_set & BIT(NL80211_STA_FLAG_WME)))
5127 params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD;
Eliad Pellerc75786c2011-08-23 14:37:46 +03005128
Johannes Bergbdd90d52011-12-14 12:20:27 +01005129 /* TDLS peers cannot be added */
Jouni Malinen3d124ea2013-05-27 18:24:02 +03005130 if ((params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) ||
5131 info->attrs[NL80211_ATTR_PEER_AID])
Johannes Berg4319e192011-09-07 11:50:48 +02005132 return -EINVAL;
Johannes Bergbdd90d52011-12-14 12:20:27 +01005133 /* but don't bother the driver with it */
5134 params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER);
Eliad Pellerc75786c2011-08-23 14:37:46 +03005135
Johannes Bergd582cff2012-10-26 17:53:44 +02005136 /* allow authenticated/associated only if driver handles it */
5137 if (!(rdev->wiphy.features &
5138 NL80211_FEATURE_FULL_AP_CLIENT_STATE) &&
Johannes Bergbda95eb2015-11-26 16:26:13 +01005139 params.sta_flags_mask & auth_assoc)
Johannes Bergd582cff2012-10-26 17:53:44 +02005140 return -EINVAL;
5141
Johannes Bergbda95eb2015-11-26 16:26:13 +01005142 /* Older userspace, or userspace wanting to be compatible with
5143 * !NL80211_FEATURE_FULL_AP_CLIENT_STATE, will not set the auth
5144 * and assoc flags in the mask, but assumes the station will be
5145 * added as associated anyway since this was the required driver
5146 * behaviour before NL80211_FEATURE_FULL_AP_CLIENT_STATE was
5147 * introduced.
5148 * In order to not bother drivers with this quirk in the API
5149 * set the flags in both the mask and set for new stations in
5150 * this case.
5151 */
5152 if (!(params.sta_flags_mask & auth_assoc)) {
5153 params.sta_flags_mask |= auth_assoc;
5154 params.sta_flags_set |= auth_assoc;
5155 }
5156
Johannes Bergbdd90d52011-12-14 12:20:27 +01005157 /* must be last in here for error handling */
5158 params.vlan = get_vlan(info, rdev);
5159 if (IS_ERR(params.vlan))
5160 return PTR_ERR(params.vlan);
5161 break;
5162 case NL80211_IFTYPE_MESH_POINT:
Johannes Berg984c3112013-02-14 23:43:25 +01005163 /* ignore uAPSD data */
5164 params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD;
5165
Johannes Bergd582cff2012-10-26 17:53:44 +02005166 /* associated is disallowed */
5167 if (params.sta_flags_mask & BIT(NL80211_STA_FLAG_ASSOCIATED))
5168 return -EINVAL;
Johannes Bergbdd90d52011-12-14 12:20:27 +01005169 /* TDLS peers cannot be added */
Jouni Malinen3d124ea2013-05-27 18:24:02 +03005170 if ((params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) ||
5171 info->attrs[NL80211_ATTR_PEER_AID])
Johannes Berg4319e192011-09-07 11:50:48 +02005172 return -EINVAL;
Johannes Bergbdd90d52011-12-14 12:20:27 +01005173 break;
5174 case NL80211_IFTYPE_STATION:
Johannes Berg93d08f02013-03-04 09:29:46 +01005175 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Berg984c3112013-02-14 23:43:25 +01005176 /* ignore uAPSD data */
5177 params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD;
5178
Johannes Berg77ee7c82013-02-15 00:48:33 +01005179 /* these are disallowed */
5180 if (params.sta_flags_mask &
5181 (BIT(NL80211_STA_FLAG_ASSOCIATED) |
5182 BIT(NL80211_STA_FLAG_AUTHENTICATED)))
Johannes Bergd582cff2012-10-26 17:53:44 +02005183 return -EINVAL;
Johannes Bergbdd90d52011-12-14 12:20:27 +01005184 /* Only TDLS peers can be added */
5185 if (!(params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)))
5186 return -EINVAL;
5187 /* Can only add if TDLS ... */
5188 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS))
5189 return -EOPNOTSUPP;
5190 /* ... with external setup is supported */
5191 if (!(rdev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP))
5192 return -EOPNOTSUPP;
Johannes Berg77ee7c82013-02-15 00:48:33 +01005193 /*
5194 * Older wpa_supplicant versions always mark the TDLS peer
5195 * as authorized, but it shouldn't yet be.
5196 */
5197 params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_AUTHORIZED);
Johannes Bergbdd90d52011-12-14 12:20:27 +01005198 break;
5199 default:
5200 return -EOPNOTSUPP;
Eliad Pellerc75786c2011-08-23 14:37:46 +03005201 }
5202
Johannes Bergbdd90d52011-12-14 12:20:27 +01005203 /* be aware of params.vlan when changing code here */
Johannes Berg5727ef12007-12-19 02:03:34 +01005204
Hila Gonene35e4d22012-06-27 17:19:42 +03005205 err = rdev_add_station(rdev, dev, mac_addr, &params);
Johannes Berg5727ef12007-12-19 02:03:34 +01005206
Johannes Berg5727ef12007-12-19 02:03:34 +01005207 if (params.vlan)
5208 dev_put(params.vlan);
Johannes Berg5727ef12007-12-19 02:03:34 +01005209 return err;
5210}
5211
5212static int nl80211_del_station(struct sk_buff *skb, struct genl_info *info)
5213{
Johannes Berg4c476992010-10-04 21:36:35 +02005214 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5215 struct net_device *dev = info->user_ptr[1];
Jouni Malinen89c771e2014-10-10 20:52:40 +03005216 struct station_del_parameters params;
5217
5218 memset(&params, 0, sizeof(params));
Johannes Berg5727ef12007-12-19 02:03:34 +01005219
5220 if (info->attrs[NL80211_ATTR_MAC])
Jouni Malinen89c771e2014-10-10 20:52:40 +03005221 params.mac = nla_data(info->attrs[NL80211_ATTR_MAC]);
Johannes Berg5727ef12007-12-19 02:03:34 +01005222
Johannes Berge80cf852009-05-11 14:43:13 +02005223 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
Marco Porschd5d9de02010-03-30 10:00:16 +02005224 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN &&
Johannes Berg074ac8d2010-09-16 14:58:22 +02005225 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT &&
Johannes Berg4c476992010-10-04 21:36:35 +02005226 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
5227 return -EINVAL;
Johannes Berge80cf852009-05-11 14:43:13 +02005228
Johannes Berg4c476992010-10-04 21:36:35 +02005229 if (!rdev->ops->del_station)
5230 return -EOPNOTSUPP;
Johannes Berg5727ef12007-12-19 02:03:34 +01005231
Jouni Malinen98856862014-10-20 13:20:45 +03005232 if (info->attrs[NL80211_ATTR_MGMT_SUBTYPE]) {
5233 params.subtype =
5234 nla_get_u8(info->attrs[NL80211_ATTR_MGMT_SUBTYPE]);
5235 if (params.subtype != IEEE80211_STYPE_DISASSOC >> 4 &&
5236 params.subtype != IEEE80211_STYPE_DEAUTH >> 4)
5237 return -EINVAL;
5238 } else {
5239 /* Default to Deauthentication frame */
5240 params.subtype = IEEE80211_STYPE_DEAUTH >> 4;
5241 }
5242
5243 if (info->attrs[NL80211_ATTR_REASON_CODE]) {
5244 params.reason_code =
5245 nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
5246 if (params.reason_code == 0)
5247 return -EINVAL; /* 0 is reserved */
5248 } else {
5249 /* Default to reason code 2 */
5250 params.reason_code = WLAN_REASON_PREV_AUTH_NOT_VALID;
5251 }
5252
Jouni Malinen89c771e2014-10-10 20:52:40 +03005253 return rdev_del_station(rdev, dev, &params);
Johannes Berg5727ef12007-12-19 02:03:34 +01005254}
5255
Eric W. Biederman15e47302012-09-07 20:12:54 +00005256static int nl80211_send_mpath(struct sk_buff *msg, u32 portid, u32 seq,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005257 int flags, struct net_device *dev,
5258 u8 *dst, u8 *next_hop,
5259 struct mpath_info *pinfo)
5260{
5261 void *hdr;
5262 struct nlattr *pinfoattr;
5263
Henning Rogge1ef4c852014-11-04 16:14:58 +01005264 hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_MPATH);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005265 if (!hdr)
5266 return -1;
5267
David S. Miller9360ffd2012-03-29 04:41:26 -04005268 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
5269 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, dst) ||
5270 nla_put(msg, NL80211_ATTR_MPATH_NEXT_HOP, ETH_ALEN, next_hop) ||
5271 nla_put_u32(msg, NL80211_ATTR_GENERATION, pinfo->generation))
5272 goto nla_put_failure;
Johannes Bergf5ea9122009-08-07 16:17:38 +02005273
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005274 pinfoattr = nla_nest_start(msg, NL80211_ATTR_MPATH_INFO);
5275 if (!pinfoattr)
5276 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04005277 if ((pinfo->filled & MPATH_INFO_FRAME_QLEN) &&
5278 nla_put_u32(msg, NL80211_MPATH_INFO_FRAME_QLEN,
5279 pinfo->frame_qlen))
5280 goto nla_put_failure;
5281 if (((pinfo->filled & MPATH_INFO_SN) &&
5282 nla_put_u32(msg, NL80211_MPATH_INFO_SN, pinfo->sn)) ||
5283 ((pinfo->filled & MPATH_INFO_METRIC) &&
5284 nla_put_u32(msg, NL80211_MPATH_INFO_METRIC,
5285 pinfo->metric)) ||
5286 ((pinfo->filled & MPATH_INFO_EXPTIME) &&
5287 nla_put_u32(msg, NL80211_MPATH_INFO_EXPTIME,
5288 pinfo->exptime)) ||
5289 ((pinfo->filled & MPATH_INFO_FLAGS) &&
5290 nla_put_u8(msg, NL80211_MPATH_INFO_FLAGS,
5291 pinfo->flags)) ||
5292 ((pinfo->filled & MPATH_INFO_DISCOVERY_TIMEOUT) &&
5293 nla_put_u32(msg, NL80211_MPATH_INFO_DISCOVERY_TIMEOUT,
5294 pinfo->discovery_timeout)) ||
5295 ((pinfo->filled & MPATH_INFO_DISCOVERY_RETRIES) &&
5296 nla_put_u8(msg, NL80211_MPATH_INFO_DISCOVERY_RETRIES,
5297 pinfo->discovery_retries)))
5298 goto nla_put_failure;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005299
5300 nla_nest_end(msg, pinfoattr);
5301
Johannes Berg053c0952015-01-16 22:09:00 +01005302 genlmsg_end(msg, hdr);
5303 return 0;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005304
5305 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07005306 genlmsg_cancel(msg, hdr);
5307 return -EMSGSIZE;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005308}
5309
5310static int nl80211_dump_mpath(struct sk_buff *skb,
Johannes Bergbba95fe2008-07-29 13:22:51 +02005311 struct netlink_callback *cb)
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005312{
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005313 struct mpath_info pinfo;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08005314 struct cfg80211_registered_device *rdev;
Johannes Berg97990a02013-04-19 01:02:55 +02005315 struct wireless_dev *wdev;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005316 u8 dst[ETH_ALEN];
5317 u8 next_hop[ETH_ALEN];
Johannes Berg97990a02013-04-19 01:02:55 +02005318 int path_idx = cb->args[2];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005319 int err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005320
Johannes Bergea90e0d2017-03-15 14:26:04 +01005321 rtnl_lock();
Zhao, Gang1b8ec872014-04-21 12:53:02 +08005322 err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev);
Johannes Berg67748892010-10-04 21:14:06 +02005323 if (err)
Johannes Bergea90e0d2017-03-15 14:26:04 +01005324 goto out_err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02005325
Zhao, Gang1b8ec872014-04-21 12:53:02 +08005326 if (!rdev->ops->dump_mpath) {
Jouni Malineneec60b02009-03-20 21:21:19 +02005327 err = -EOPNOTSUPP;
Johannes Bergbba95fe2008-07-29 13:22:51 +02005328 goto out_err;
5329 }
5330
Johannes Berg97990a02013-04-19 01:02:55 +02005331 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) {
Jouni Malineneec60b02009-03-20 21:21:19 +02005332 err = -EOPNOTSUPP;
Roel Kluin0448b5f2009-08-22 21:15:49 +02005333 goto out_err;
Jouni Malineneec60b02009-03-20 21:21:19 +02005334 }
5335
Johannes Bergbba95fe2008-07-29 13:22:51 +02005336 while (1) {
Zhao, Gang1b8ec872014-04-21 12:53:02 +08005337 err = rdev_dump_mpath(rdev, wdev->netdev, path_idx, dst,
Johannes Berg97990a02013-04-19 01:02:55 +02005338 next_hop, &pinfo);
Johannes Bergbba95fe2008-07-29 13:22:51 +02005339 if (err == -ENOENT)
5340 break;
5341 if (err)
Johannes Berg3b858752009-03-12 09:55:09 +01005342 goto out_err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02005343
Eric W. Biederman15e47302012-09-07 20:12:54 +00005344 if (nl80211_send_mpath(skb, NETLINK_CB(cb->skb).portid,
Johannes Bergbba95fe2008-07-29 13:22:51 +02005345 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Johannes Berg97990a02013-04-19 01:02:55 +02005346 wdev->netdev, dst, next_hop,
Johannes Bergbba95fe2008-07-29 13:22:51 +02005347 &pinfo) < 0)
5348 goto out;
5349
5350 path_idx++;
5351 }
5352
Johannes Bergbba95fe2008-07-29 13:22:51 +02005353 out:
Johannes Berg97990a02013-04-19 01:02:55 +02005354 cb->args[2] = path_idx;
Johannes Bergbba95fe2008-07-29 13:22:51 +02005355 err = skb->len;
Johannes Bergbba95fe2008-07-29 13:22:51 +02005356 out_err:
Johannes Bergea90e0d2017-03-15 14:26:04 +01005357 rtnl_unlock();
Johannes Bergbba95fe2008-07-29 13:22:51 +02005358 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005359}
5360
5361static int nl80211_get_mpath(struct sk_buff *skb, struct genl_info *info)
5362{
Johannes Berg4c476992010-10-04 21:36:35 +02005363 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005364 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02005365 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005366 struct mpath_info pinfo;
5367 struct sk_buff *msg;
5368 u8 *dst = NULL;
5369 u8 next_hop[ETH_ALEN];
5370
5371 memset(&pinfo, 0, sizeof(pinfo));
5372
5373 if (!info->attrs[NL80211_ATTR_MAC])
5374 return -EINVAL;
5375
5376 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
5377
Johannes Berg4c476992010-10-04 21:36:35 +02005378 if (!rdev->ops->get_mpath)
5379 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01005380
Johannes Berg4c476992010-10-04 21:36:35 +02005381 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
5382 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02005383
Hila Gonene35e4d22012-06-27 17:19:42 +03005384 err = rdev_get_mpath(rdev, dev, dst, next_hop, &pinfo);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005385 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02005386 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005387
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07005388 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005389 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02005390 return -ENOMEM;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005391
Eric W. Biederman15e47302012-09-07 20:12:54 +00005392 if (nl80211_send_mpath(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berg4c476992010-10-04 21:36:35 +02005393 dev, dst, next_hop, &pinfo) < 0) {
5394 nlmsg_free(msg);
5395 return -ENOBUFS;
5396 }
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005397
Johannes Berg4c476992010-10-04 21:36:35 +02005398 return genlmsg_reply(msg, info);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005399}
5400
5401static int nl80211_set_mpath(struct sk_buff *skb, struct genl_info *info)
5402{
Johannes Berg4c476992010-10-04 21:36:35 +02005403 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5404 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005405 u8 *dst = NULL;
5406 u8 *next_hop = NULL;
5407
5408 if (!info->attrs[NL80211_ATTR_MAC])
5409 return -EINVAL;
5410
5411 if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP])
5412 return -EINVAL;
5413
5414 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
5415 next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]);
5416
Johannes Berg4c476992010-10-04 21:36:35 +02005417 if (!rdev->ops->change_mpath)
5418 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01005419
Johannes Berg4c476992010-10-04 21:36:35 +02005420 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
5421 return -EOPNOTSUPP;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005422
Hila Gonene35e4d22012-06-27 17:19:42 +03005423 return rdev_change_mpath(rdev, dev, dst, next_hop);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005424}
Johannes Berg4c476992010-10-04 21:36:35 +02005425
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005426static int nl80211_new_mpath(struct sk_buff *skb, struct genl_info *info)
5427{
Johannes Berg4c476992010-10-04 21:36:35 +02005428 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5429 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005430 u8 *dst = NULL;
5431 u8 *next_hop = NULL;
5432
5433 if (!info->attrs[NL80211_ATTR_MAC])
5434 return -EINVAL;
5435
5436 if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP])
5437 return -EINVAL;
5438
5439 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
5440 next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]);
5441
Johannes Berg4c476992010-10-04 21:36:35 +02005442 if (!rdev->ops->add_mpath)
5443 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01005444
Johannes Berg4c476992010-10-04 21:36:35 +02005445 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
5446 return -EOPNOTSUPP;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005447
Hila Gonene35e4d22012-06-27 17:19:42 +03005448 return rdev_add_mpath(rdev, dev, dst, next_hop);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005449}
5450
5451static int nl80211_del_mpath(struct sk_buff *skb, struct genl_info *info)
5452{
Johannes Berg4c476992010-10-04 21:36:35 +02005453 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5454 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005455 u8 *dst = NULL;
5456
5457 if (info->attrs[NL80211_ATTR_MAC])
5458 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
5459
Johannes Berg4c476992010-10-04 21:36:35 +02005460 if (!rdev->ops->del_mpath)
5461 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01005462
Hila Gonene35e4d22012-06-27 17:19:42 +03005463 return rdev_del_mpath(rdev, dev, dst);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005464}
5465
Henning Rogge66be7d22014-09-12 08:58:49 +02005466static int nl80211_get_mpp(struct sk_buff *skb, struct genl_info *info)
5467{
5468 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5469 int err;
5470 struct net_device *dev = info->user_ptr[1];
5471 struct mpath_info pinfo;
5472 struct sk_buff *msg;
5473 u8 *dst = NULL;
5474 u8 mpp[ETH_ALEN];
5475
5476 memset(&pinfo, 0, sizeof(pinfo));
5477
5478 if (!info->attrs[NL80211_ATTR_MAC])
5479 return -EINVAL;
5480
5481 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
5482
5483 if (!rdev->ops->get_mpp)
5484 return -EOPNOTSUPP;
5485
5486 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
5487 return -EOPNOTSUPP;
5488
5489 err = rdev_get_mpp(rdev, dev, dst, mpp, &pinfo);
5490 if (err)
5491 return err;
5492
5493 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
5494 if (!msg)
5495 return -ENOMEM;
5496
5497 if (nl80211_send_mpath(msg, info->snd_portid, info->snd_seq, 0,
5498 dev, dst, mpp, &pinfo) < 0) {
5499 nlmsg_free(msg);
5500 return -ENOBUFS;
5501 }
5502
5503 return genlmsg_reply(msg, info);
5504}
5505
5506static int nl80211_dump_mpp(struct sk_buff *skb,
5507 struct netlink_callback *cb)
5508{
5509 struct mpath_info pinfo;
5510 struct cfg80211_registered_device *rdev;
5511 struct wireless_dev *wdev;
5512 u8 dst[ETH_ALEN];
5513 u8 mpp[ETH_ALEN];
5514 int path_idx = cb->args[2];
5515 int err;
5516
Johannes Bergea90e0d2017-03-15 14:26:04 +01005517 rtnl_lock();
Henning Rogge66be7d22014-09-12 08:58:49 +02005518 err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev);
5519 if (err)
Johannes Bergea90e0d2017-03-15 14:26:04 +01005520 goto out_err;
Henning Rogge66be7d22014-09-12 08:58:49 +02005521
5522 if (!rdev->ops->dump_mpp) {
5523 err = -EOPNOTSUPP;
5524 goto out_err;
5525 }
5526
5527 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) {
5528 err = -EOPNOTSUPP;
5529 goto out_err;
5530 }
5531
5532 while (1) {
5533 err = rdev_dump_mpp(rdev, wdev->netdev, path_idx, dst,
5534 mpp, &pinfo);
5535 if (err == -ENOENT)
5536 break;
5537 if (err)
5538 goto out_err;
5539
5540 if (nl80211_send_mpath(skb, NETLINK_CB(cb->skb).portid,
5541 cb->nlh->nlmsg_seq, NLM_F_MULTI,
5542 wdev->netdev, dst, mpp,
5543 &pinfo) < 0)
5544 goto out;
5545
5546 path_idx++;
5547 }
5548
5549 out:
5550 cb->args[2] = path_idx;
5551 err = skb->len;
5552 out_err:
Johannes Bergea90e0d2017-03-15 14:26:04 +01005553 rtnl_unlock();
Henning Rogge66be7d22014-09-12 08:58:49 +02005554 return err;
5555}
5556
Jouni Malinen9f1ba902008-08-07 20:07:01 +03005557static int nl80211_set_bss(struct sk_buff *skb, struct genl_info *info)
5558{
Johannes Berg4c476992010-10-04 21:36:35 +02005559 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5560 struct net_device *dev = info->user_ptr[1];
Simon Wunderlichc56589e2013-11-21 18:19:49 +01005561 struct wireless_dev *wdev = dev->ieee80211_ptr;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03005562 struct bss_parameters params;
Simon Wunderlichc56589e2013-11-21 18:19:49 +01005563 int err;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03005564
5565 memset(&params, 0, sizeof(params));
5566 /* default to not changing parameters */
5567 params.use_cts_prot = -1;
5568 params.use_short_preamble = -1;
5569 params.use_short_slot_time = -1;
Felix Fietkaufd8aaaf2010-04-27 01:23:35 +02005570 params.ap_isolate = -1;
Helmut Schaa50b12f52010-11-19 12:40:25 +01005571 params.ht_opmode = -1;
Johannes Berg53cabad2012-11-14 15:17:28 +01005572 params.p2p_ctwindow = -1;
5573 params.p2p_opp_ps = -1;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03005574
5575 if (info->attrs[NL80211_ATTR_BSS_CTS_PROT])
5576 params.use_cts_prot =
5577 nla_get_u8(info->attrs[NL80211_ATTR_BSS_CTS_PROT]);
5578 if (info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE])
5579 params.use_short_preamble =
5580 nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]);
5581 if (info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME])
5582 params.use_short_slot_time =
5583 nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]);
Jouni Malinen90c97a02008-10-30 16:59:22 +02005584 if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) {
5585 params.basic_rates =
5586 nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
5587 params.basic_rates_len =
5588 nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
5589 }
Felix Fietkaufd8aaaf2010-04-27 01:23:35 +02005590 if (info->attrs[NL80211_ATTR_AP_ISOLATE])
5591 params.ap_isolate = !!nla_get_u8(info->attrs[NL80211_ATTR_AP_ISOLATE]);
Helmut Schaa50b12f52010-11-19 12:40:25 +01005592 if (info->attrs[NL80211_ATTR_BSS_HT_OPMODE])
5593 params.ht_opmode =
5594 nla_get_u16(info->attrs[NL80211_ATTR_BSS_HT_OPMODE]);
Jouni Malinen9f1ba902008-08-07 20:07:01 +03005595
Johannes Berg53cabad2012-11-14 15:17:28 +01005596 if (info->attrs[NL80211_ATTR_P2P_CTWINDOW]) {
5597 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
5598 return -EINVAL;
5599 params.p2p_ctwindow =
5600 nla_get_s8(info->attrs[NL80211_ATTR_P2P_CTWINDOW]);
5601 if (params.p2p_ctwindow < 0)
5602 return -EINVAL;
5603 if (params.p2p_ctwindow != 0 &&
5604 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_CTWIN))
5605 return -EINVAL;
5606 }
5607
5608 if (info->attrs[NL80211_ATTR_P2P_OPPPS]) {
5609 u8 tmp;
5610
5611 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
5612 return -EINVAL;
5613 tmp = nla_get_u8(info->attrs[NL80211_ATTR_P2P_OPPPS]);
5614 if (tmp > 1)
5615 return -EINVAL;
5616 params.p2p_opp_ps = tmp;
5617 if (params.p2p_opp_ps &&
5618 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_OPPPS))
5619 return -EINVAL;
5620 }
5621
Johannes Berg4c476992010-10-04 21:36:35 +02005622 if (!rdev->ops->change_bss)
5623 return -EOPNOTSUPP;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03005624
Johannes Berg074ac8d2010-09-16 14:58:22 +02005625 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
Johannes Berg4c476992010-10-04 21:36:35 +02005626 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
5627 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02005628
Simon Wunderlichc56589e2013-11-21 18:19:49 +01005629 wdev_lock(wdev);
5630 err = rdev_change_bss(rdev, dev, &params);
5631 wdev_unlock(wdev);
5632
5633 return err;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03005634}
5635
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005636static int nl80211_req_set_reg(struct sk_buff *skb, struct genl_info *info)
5637{
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005638 char *data = NULL;
Ilan peer05050752015-03-04 00:32:06 -05005639 bool is_indoor;
Luis R. Rodriguez57b5ce02012-07-12 11:49:18 -07005640 enum nl80211_user_reg_hint_type user_reg_hint_type;
Ilan peer05050752015-03-04 00:32:06 -05005641 u32 owner_nlportid;
5642
Luis R. Rodriguez80778f12009-02-21 00:04:22 -05005643 /*
5644 * You should only get this when cfg80211 hasn't yet initialized
5645 * completely when built-in to the kernel right between the time
5646 * window between nl80211_init() and regulatory_init(), if that is
5647 * even possible.
5648 */
Johannes Berg458f4f92012-12-06 15:47:38 +01005649 if (unlikely(!rcu_access_pointer(cfg80211_regdomain)))
Luis R. Rodriguezfe33eb32009-02-21 00:04:30 -05005650 return -EINPROGRESS;
Luis R. Rodriguez80778f12009-02-21 00:04:22 -05005651
Luis R. Rodriguez57b5ce02012-07-12 11:49:18 -07005652 if (info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE])
5653 user_reg_hint_type =
5654 nla_get_u32(info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE]);
5655 else
5656 user_reg_hint_type = NL80211_USER_REG_HINT_USER;
5657
5658 switch (user_reg_hint_type) {
5659 case NL80211_USER_REG_HINT_USER:
5660 case NL80211_USER_REG_HINT_CELL_BASE:
Ilan Peer52616f22014-02-25 16:26:00 +02005661 if (!info->attrs[NL80211_ATTR_REG_ALPHA2])
5662 return -EINVAL;
5663
5664 data = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]);
5665 return regulatory_hint_user(data, user_reg_hint_type);
5666 case NL80211_USER_REG_HINT_INDOOR:
Ilan peer05050752015-03-04 00:32:06 -05005667 if (info->attrs[NL80211_ATTR_SOCKET_OWNER]) {
5668 owner_nlportid = info->snd_portid;
5669 is_indoor = !!info->attrs[NL80211_ATTR_REG_INDOOR];
5670 } else {
5671 owner_nlportid = 0;
5672 is_indoor = true;
5673 }
5674
5675 return regulatory_hint_indoor(is_indoor, owner_nlportid);
Luis R. Rodriguez57b5ce02012-07-12 11:49:18 -07005676 default:
5677 return -EINVAL;
5678 }
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005679}
5680
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005681static int nl80211_get_mesh_config(struct sk_buff *skb,
Johannes Berg29cbe682010-12-03 09:20:44 +01005682 struct genl_info *info)
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005683{
Johannes Berg4c476992010-10-04 21:36:35 +02005684 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg4c476992010-10-04 21:36:35 +02005685 struct net_device *dev = info->user_ptr[1];
Johannes Berg29cbe682010-12-03 09:20:44 +01005686 struct wireless_dev *wdev = dev->ieee80211_ptr;
5687 struct mesh_config cur_params;
5688 int err = 0;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005689 void *hdr;
5690 struct nlattr *pinfoattr;
5691 struct sk_buff *msg;
5692
Johannes Berg29cbe682010-12-03 09:20:44 +01005693 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT)
5694 return -EOPNOTSUPP;
5695
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005696 if (!rdev->ops->get_mesh_config)
Johannes Berg4c476992010-10-04 21:36:35 +02005697 return -EOPNOTSUPP;
Jouni Malinenf3f92582009-03-20 17:57:36 +02005698
Johannes Berg29cbe682010-12-03 09:20:44 +01005699 wdev_lock(wdev);
5700 /* If not connected, get default parameters */
5701 if (!wdev->mesh_id_len)
5702 memcpy(&cur_params, &default_mesh_config, sizeof(cur_params));
5703 else
Hila Gonene35e4d22012-06-27 17:19:42 +03005704 err = rdev_get_mesh_config(rdev, dev, &cur_params);
Johannes Berg29cbe682010-12-03 09:20:44 +01005705 wdev_unlock(wdev);
5706
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005707 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02005708 return err;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005709
5710 /* Draw up a netlink message to send back */
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07005711 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02005712 if (!msg)
5713 return -ENOMEM;
Eric W. Biederman15e47302012-09-07 20:12:54 +00005714 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005715 NL80211_CMD_GET_MESH_CONFIG);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005716 if (!hdr)
Julia Lawallefe1cf02011-01-28 15:17:11 +01005717 goto out;
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005718 pinfoattr = nla_nest_start(msg, NL80211_ATTR_MESH_CONFIG);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005719 if (!pinfoattr)
5720 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04005721 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
5722 nla_put_u16(msg, NL80211_MESHCONF_RETRY_TIMEOUT,
5723 cur_params.dot11MeshRetryTimeout) ||
5724 nla_put_u16(msg, NL80211_MESHCONF_CONFIRM_TIMEOUT,
5725 cur_params.dot11MeshConfirmTimeout) ||
5726 nla_put_u16(msg, NL80211_MESHCONF_HOLDING_TIMEOUT,
5727 cur_params.dot11MeshHoldingTimeout) ||
5728 nla_put_u16(msg, NL80211_MESHCONF_MAX_PEER_LINKS,
5729 cur_params.dot11MeshMaxPeerLinks) ||
5730 nla_put_u8(msg, NL80211_MESHCONF_MAX_RETRIES,
5731 cur_params.dot11MeshMaxRetries) ||
5732 nla_put_u8(msg, NL80211_MESHCONF_TTL,
5733 cur_params.dot11MeshTTL) ||
5734 nla_put_u8(msg, NL80211_MESHCONF_ELEMENT_TTL,
5735 cur_params.element_ttl) ||
5736 nla_put_u8(msg, NL80211_MESHCONF_AUTO_OPEN_PLINKS,
5737 cur_params.auto_open_plinks) ||
John W. Linville7eab0f62012-04-12 14:25:14 -04005738 nla_put_u32(msg, NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR,
5739 cur_params.dot11MeshNbrOffsetMaxNeighbor) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04005740 nla_put_u8(msg, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES,
5741 cur_params.dot11MeshHWMPmaxPREQretries) ||
5742 nla_put_u32(msg, NL80211_MESHCONF_PATH_REFRESH_TIME,
5743 cur_params.path_refresh_time) ||
5744 nla_put_u16(msg, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT,
5745 cur_params.min_discovery_timeout) ||
5746 nla_put_u32(msg, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT,
5747 cur_params.dot11MeshHWMPactivePathTimeout) ||
5748 nla_put_u16(msg, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL,
5749 cur_params.dot11MeshHWMPpreqMinInterval) ||
5750 nla_put_u16(msg, NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL,
5751 cur_params.dot11MeshHWMPperrMinInterval) ||
5752 nla_put_u16(msg, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME,
5753 cur_params.dot11MeshHWMPnetDiameterTraversalTime) ||
5754 nla_put_u8(msg, NL80211_MESHCONF_HWMP_ROOTMODE,
5755 cur_params.dot11MeshHWMPRootMode) ||
5756 nla_put_u16(msg, NL80211_MESHCONF_HWMP_RANN_INTERVAL,
5757 cur_params.dot11MeshHWMPRannInterval) ||
5758 nla_put_u8(msg, NL80211_MESHCONF_GATE_ANNOUNCEMENTS,
5759 cur_params.dot11MeshGateAnnouncementProtocol) ||
5760 nla_put_u8(msg, NL80211_MESHCONF_FORWARDING,
5761 cur_params.dot11MeshForwarding) ||
Masashi Honma335d5342017-03-16 10:57:17 +09005762 nla_put_s32(msg, NL80211_MESHCONF_RSSI_THRESHOLD,
Ashok Nagarajan70c33ea2012-04-30 14:20:32 -07005763 cur_params.rssi_threshold) ||
5764 nla_put_u32(msg, NL80211_MESHCONF_HT_OPMODE,
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08005765 cur_params.ht_opmode) ||
5766 nla_put_u32(msg, NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT,
5767 cur_params.dot11MeshHWMPactivePathToRootTimeout) ||
5768 nla_put_u16(msg, NL80211_MESHCONF_HWMP_ROOT_INTERVAL,
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +08005769 cur_params.dot11MeshHWMProotInterval) ||
5770 nla_put_u16(msg, NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL,
Marco Porsch3b1c5a52013-01-07 16:04:52 +01005771 cur_params.dot11MeshHWMPconfirmationInterval) ||
5772 nla_put_u32(msg, NL80211_MESHCONF_POWER_MODE,
5773 cur_params.power_mode) ||
5774 nla_put_u16(msg, NL80211_MESHCONF_AWAKE_WINDOW,
Colleen Twitty8e7c0532013-06-03 09:53:39 -07005775 cur_params.dot11MeshAwakeWindowDuration) ||
5776 nla_put_u32(msg, NL80211_MESHCONF_PLINK_TIMEOUT,
5777 cur_params.plink_timeout))
David S. Miller9360ffd2012-03-29 04:41:26 -04005778 goto nla_put_failure;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005779 nla_nest_end(msg, pinfoattr);
5780 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02005781 return genlmsg_reply(msg, info);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005782
Johannes Berg3b858752009-03-12 09:55:09 +01005783 nla_put_failure:
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005784 genlmsg_cancel(msg, hdr);
Julia Lawallefe1cf02011-01-28 15:17:11 +01005785 out:
Yuri Ershovd080e272010-06-29 15:08:07 +04005786 nlmsg_free(msg);
Johannes Berg4c476992010-10-04 21:36:35 +02005787 return -ENOBUFS;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005788}
5789
Alexey Dobriyanb54452b2010-02-18 08:14:31 +00005790static const struct nla_policy nl80211_meshconf_params_policy[NL80211_MESHCONF_ATTR_MAX+1] = {
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005791 [NL80211_MESHCONF_RETRY_TIMEOUT] = { .type = NLA_U16 },
5792 [NL80211_MESHCONF_CONFIRM_TIMEOUT] = { .type = NLA_U16 },
5793 [NL80211_MESHCONF_HOLDING_TIMEOUT] = { .type = NLA_U16 },
5794 [NL80211_MESHCONF_MAX_PEER_LINKS] = { .type = NLA_U16 },
5795 [NL80211_MESHCONF_MAX_RETRIES] = { .type = NLA_U8 },
5796 [NL80211_MESHCONF_TTL] = { .type = NLA_U8 },
Javier Cardona45904f22010-12-03 09:20:40 +01005797 [NL80211_MESHCONF_ELEMENT_TTL] = { .type = NLA_U8 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005798 [NL80211_MESHCONF_AUTO_OPEN_PLINKS] = { .type = NLA_U8 },
Javier Cardonad299a1f2012-03-31 11:31:33 -07005799 [NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR] = { .type = NLA_U32 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005800 [NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES] = { .type = NLA_U8 },
5801 [NL80211_MESHCONF_PATH_REFRESH_TIME] = { .type = NLA_U32 },
5802 [NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT] = { .type = NLA_U16 },
5803 [NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT] = { .type = NLA_U32 },
5804 [NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL] = { .type = NLA_U16 },
Thomas Pedersendca7e942011-11-24 17:15:24 -08005805 [NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL] = { .type = NLA_U16 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005806 [NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME] = { .type = NLA_U16 },
Javier Cardona699403d2011-08-09 16:45:09 -07005807 [NL80211_MESHCONF_HWMP_ROOTMODE] = { .type = NLA_U8 },
Javier Cardona0507e152011-08-09 16:45:10 -07005808 [NL80211_MESHCONF_HWMP_RANN_INTERVAL] = { .type = NLA_U16 },
Javier Cardona16dd7262011-08-09 16:45:11 -07005809 [NL80211_MESHCONF_GATE_ANNOUNCEMENTS] = { .type = NLA_U8 },
Chun-Yeow Yeoh94f90652012-01-21 01:02:16 +08005810 [NL80211_MESHCONF_FORWARDING] = { .type = NLA_U8 },
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005811 [NL80211_MESHCONF_RSSI_THRESHOLD] = { .type = NLA_U32 },
5812 [NL80211_MESHCONF_HT_OPMODE] = { .type = NLA_U16 },
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08005813 [NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT] = { .type = NLA_U32 },
5814 [NL80211_MESHCONF_HWMP_ROOT_INTERVAL] = { .type = NLA_U16 },
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +08005815 [NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL] = { .type = NLA_U16 },
Marco Porsch3b1c5a52013-01-07 16:04:52 +01005816 [NL80211_MESHCONF_POWER_MODE] = { .type = NLA_U32 },
5817 [NL80211_MESHCONF_AWAKE_WINDOW] = { .type = NLA_U16 },
Colleen Twitty8e7c0532013-06-03 09:53:39 -07005818 [NL80211_MESHCONF_PLINK_TIMEOUT] = { .type = NLA_U32 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005819};
5820
Javier Cardonac80d5452010-12-16 17:37:49 -08005821static const struct nla_policy
5822 nl80211_mesh_setup_params_policy[NL80211_MESH_SETUP_ATTR_MAX+1] = {
Javier Cardonad299a1f2012-03-31 11:31:33 -07005823 [NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC] = { .type = NLA_U8 },
Javier Cardonac80d5452010-12-16 17:37:49 -08005824 [NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL] = { .type = NLA_U8 },
5825 [NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC] = { .type = NLA_U8 },
Javier Cardona15d5dda2011-04-07 15:08:28 -07005826 [NL80211_MESH_SETUP_USERSPACE_AUTH] = { .type = NLA_FLAG },
Colleen Twitty6e16d902013-05-08 11:45:59 -07005827 [NL80211_MESH_SETUP_AUTH_PROTOCOL] = { .type = NLA_U8 },
Thomas Pedersenbb2798d2013-03-04 13:06:10 -08005828 [NL80211_MESH_SETUP_USERSPACE_MPM] = { .type = NLA_FLAG },
Javier Cardona581a8b02011-04-07 15:08:27 -07005829 [NL80211_MESH_SETUP_IE] = { .type = NLA_BINARY,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005830 .len = IEEE80211_MAX_DATA_LEN },
Javier Cardonab130e5c2011-05-03 16:57:07 -07005831 [NL80211_MESH_SETUP_USERSPACE_AMPE] = { .type = NLA_FLAG },
Javier Cardonac80d5452010-12-16 17:37:49 -08005832};
5833
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005834static int nl80211_check_bool(const struct nlattr *nla, u8 min, u8 max, bool *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_u8(const struct nlattr *nla, u8 min, u8 max, u8 *out)
5844{
5845 u8 val = nla_get_u8(nla);
5846 if (val < min || val > max)
5847 return -EINVAL;
5848 *out = val;
5849 return 0;
5850}
5851
5852static int nl80211_check_u16(const struct nlattr *nla, u16 min, u16 max, u16 *out)
5853{
5854 u16 val = nla_get_u16(nla);
5855 if (val < min || val > max)
5856 return -EINVAL;
5857 *out = val;
5858 return 0;
5859}
5860
5861static int nl80211_check_u32(const struct nlattr *nla, u32 min, u32 max, u32 *out)
5862{
5863 u32 val = nla_get_u32(nla);
5864 if (val < min || val > max)
5865 return -EINVAL;
5866 *out = val;
5867 return 0;
5868}
5869
5870static int nl80211_check_s32(const struct nlattr *nla, s32 min, s32 max, s32 *out)
5871{
5872 s32 val = nla_get_s32(nla);
5873 if (val < min || val > max)
5874 return -EINVAL;
5875 *out = val;
5876 return 0;
5877}
5878
Johannes Bergff9a71a2016-08-11 14:59:53 +02005879static int nl80211_check_power_mode(const struct nlattr *nla,
5880 enum nl80211_mesh_power_mode min,
5881 enum nl80211_mesh_power_mode max,
5882 enum nl80211_mesh_power_mode *out)
5883{
5884 u32 val = nla_get_u32(nla);
5885 if (val < min || val > max)
5886 return -EINVAL;
5887 *out = val;
5888 return 0;
5889}
5890
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005891static int nl80211_parse_mesh_config(struct genl_info *info,
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005892 struct mesh_config *cfg,
5893 u32 *mask_out)
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005894{
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005895 struct nlattr *tb[NL80211_MESHCONF_ATTR_MAX + 1];
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005896 u32 mask = 0;
Masashi Honma97572352016-08-03 10:07:44 +09005897 u16 ht_opmode;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005898
Marco Porschea54fba2013-01-07 16:04:48 +01005899#define FILL_IN_MESH_PARAM_IF_SET(tb, cfg, param, min, max, mask, attr, fn) \
5900do { \
5901 if (tb[attr]) { \
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005902 if (fn(tb[attr], min, max, &cfg->param)) \
Marco Porschea54fba2013-01-07 16:04:48 +01005903 return -EINVAL; \
Marco Porschea54fba2013-01-07 16:04:48 +01005904 mask |= (1 << (attr - 1)); \
5905 } \
5906} while (0)
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005907
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005908 if (!info->attrs[NL80211_ATTR_MESH_CONFIG])
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005909 return -EINVAL;
5910 if (nla_parse_nested(tb, NL80211_MESHCONF_ATTR_MAX,
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005911 info->attrs[NL80211_ATTR_MESH_CONFIG],
Johannes Bergfe521452017-04-12 14:34:08 +02005912 nl80211_meshconf_params_policy, info->extack))
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005913 return -EINVAL;
5914
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005915 /* This makes sure that there aren't more than 32 mesh config
5916 * parameters (otherwise our bitfield scheme would not work.) */
5917 BUILD_BUG_ON(NL80211_MESHCONF_ATTR_MAX > 32);
5918
5919 /* Fill in the params struct */
Marco Porschea54fba2013-01-07 16:04:48 +01005920 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshRetryTimeout, 1, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005921 mask, NL80211_MESHCONF_RETRY_TIMEOUT,
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, dot11MeshConfirmTimeout, 1, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005924 mask, NL80211_MESHCONF_CONFIRM_TIMEOUT,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005925 nl80211_check_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01005926 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHoldingTimeout, 1, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005927 mask, NL80211_MESHCONF_HOLDING_TIMEOUT,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005928 nl80211_check_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01005929 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxPeerLinks, 0, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005930 mask, NL80211_MESHCONF_MAX_PEER_LINKS,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005931 nl80211_check_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01005932 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxRetries, 0, 16,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005933 mask, NL80211_MESHCONF_MAX_RETRIES,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005934 nl80211_check_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01005935 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshTTL, 1, 255,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005936 mask, NL80211_MESHCONF_TTL, nl80211_check_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01005937 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, element_ttl, 1, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005938 mask, NL80211_MESHCONF_ELEMENT_TTL,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005939 nl80211_check_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01005940 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, auto_open_plinks, 0, 1,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005941 mask, NL80211_MESHCONF_AUTO_OPEN_PLINKS,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005942 nl80211_check_bool);
Marco Porschea54fba2013-01-07 16:04:48 +01005943 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshNbrOffsetMaxNeighbor,
5944 1, 255, mask,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005945 NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005946 nl80211_check_u32);
Marco Porschea54fba2013-01-07 16:04:48 +01005947 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPmaxPREQretries, 0, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005948 mask, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005949 nl80211_check_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01005950 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, path_refresh_time, 1, 65535,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005951 mask, NL80211_MESHCONF_PATH_REFRESH_TIME,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005952 nl80211_check_u32);
Marco Porschea54fba2013-01-07 16:04:48 +01005953 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, min_discovery_timeout, 1, 65535,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005954 mask, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005955 nl80211_check_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01005956 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathTimeout,
5957 1, 65535, mask,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005958 NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005959 nl80211_check_u32);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005960 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPpreqMinInterval,
Marco Porschea54fba2013-01-07 16:04:48 +01005961 1, 65535, mask,
5962 NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005963 nl80211_check_u16);
Thomas Pedersendca7e942011-11-24 17:15:24 -08005964 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPperrMinInterval,
Marco Porschea54fba2013-01-07 16:04:48 +01005965 1, 65535, mask,
5966 NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005967 nl80211_check_u16);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005968 FILL_IN_MESH_PARAM_IF_SET(tb, cfg,
Marco Porschea54fba2013-01-07 16:04:48 +01005969 dot11MeshHWMPnetDiameterTraversalTime,
5970 1, 65535, mask,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005971 NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005972 nl80211_check_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01005973 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRootMode, 0, 4,
5974 mask, NL80211_MESHCONF_HWMP_ROOTMODE,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005975 nl80211_check_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01005976 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRannInterval, 1, 65535,
5977 mask, NL80211_MESHCONF_HWMP_RANN_INTERVAL,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005978 nl80211_check_u16);
Rui Paulo63c57232009-11-09 23:46:57 +00005979 FILL_IN_MESH_PARAM_IF_SET(tb, cfg,
Marco Porschea54fba2013-01-07 16:04:48 +01005980 dot11MeshGateAnnouncementProtocol, 0, 1,
5981 mask, NL80211_MESHCONF_GATE_ANNOUNCEMENTS,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005982 nl80211_check_bool);
Marco Porschea54fba2013-01-07 16:04:48 +01005983 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshForwarding, 0, 1,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005984 mask, NL80211_MESHCONF_FORWARDING,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005985 nl80211_check_bool);
Chun-Yeow Yeoh83374fe2013-07-11 18:24:03 +08005986 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, rssi_threshold, -255, 0,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005987 mask, NL80211_MESHCONF_RSSI_THRESHOLD,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005988 nl80211_check_s32);
Masashi Honma97572352016-08-03 10:07:44 +09005989 /*
5990 * Check HT operation mode based on
5991 * IEEE 802.11 2012 8.4.2.59 HT Operation element.
5992 */
5993 if (tb[NL80211_MESHCONF_HT_OPMODE]) {
5994 ht_opmode = nla_get_u16(tb[NL80211_MESHCONF_HT_OPMODE]);
5995
5996 if (ht_opmode & ~(IEEE80211_HT_OP_MODE_PROTECTION |
5997 IEEE80211_HT_OP_MODE_NON_GF_STA_PRSNT |
5998 IEEE80211_HT_OP_MODE_NON_HT_STA_PRSNT))
5999 return -EINVAL;
6000
6001 if ((ht_opmode & IEEE80211_HT_OP_MODE_NON_GF_STA_PRSNT) &&
6002 (ht_opmode & IEEE80211_HT_OP_MODE_NON_HT_STA_PRSNT))
6003 return -EINVAL;
6004
6005 switch (ht_opmode & IEEE80211_HT_OP_MODE_PROTECTION) {
6006 case IEEE80211_HT_OP_MODE_PROTECTION_NONE:
6007 case IEEE80211_HT_OP_MODE_PROTECTION_20MHZ:
6008 if (ht_opmode & IEEE80211_HT_OP_MODE_NON_HT_STA_PRSNT)
6009 return -EINVAL;
6010 break;
6011 case IEEE80211_HT_OP_MODE_PROTECTION_NONMEMBER:
6012 case IEEE80211_HT_OP_MODE_PROTECTION_NONHT_MIXED:
6013 if (!(ht_opmode & IEEE80211_HT_OP_MODE_NON_HT_STA_PRSNT))
6014 return -EINVAL;
6015 break;
6016 }
6017 cfg->ht_opmode = ht_opmode;
Masashi Honmafd551ba2017-01-26 08:56:13 +09006018 mask |= (1 << (NL80211_MESHCONF_HT_OPMODE - 1));
Masashi Honma97572352016-08-03 10:07:44 +09006019 }
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08006020 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathToRootTimeout,
Marco Porschea54fba2013-01-07 16:04:48 +01006021 1, 65535, mask,
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08006022 NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02006023 nl80211_check_u32);
Marco Porschea54fba2013-01-07 16:04:48 +01006024 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMProotInterval, 1, 65535,
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08006025 mask, NL80211_MESHCONF_HWMP_ROOT_INTERVAL,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02006026 nl80211_check_u16);
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +08006027 FILL_IN_MESH_PARAM_IF_SET(tb, cfg,
Marco Porschea54fba2013-01-07 16:04:48 +01006028 dot11MeshHWMPconfirmationInterval,
6029 1, 65535, mask,
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +08006030 NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02006031 nl80211_check_u16);
Marco Porsch3b1c5a52013-01-07 16:04:52 +01006032 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, power_mode,
6033 NL80211_MESH_POWER_ACTIVE,
6034 NL80211_MESH_POWER_MAX,
6035 mask, NL80211_MESHCONF_POWER_MODE,
Johannes Bergff9a71a2016-08-11 14:59:53 +02006036 nl80211_check_power_mode);
Marco Porsch3b1c5a52013-01-07 16:04:52 +01006037 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshAwakeWindowDuration,
6038 0, 65535, mask,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02006039 NL80211_MESHCONF_AWAKE_WINDOW, nl80211_check_u16);
Masashi Honma31f909a2015-02-24 22:42:16 +09006040 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, plink_timeout, 0, 0xffffffff,
Colleen Twitty8e7c0532013-06-03 09:53:39 -07006041 mask, NL80211_MESHCONF_PLINK_TIMEOUT,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02006042 nl80211_check_u32);
Johannes Bergbd90fdc2010-12-03 09:20:43 +01006043 if (mask_out)
6044 *mask_out = mask;
Javier Cardonac80d5452010-12-16 17:37:49 -08006045
Johannes Bergbd90fdc2010-12-03 09:20:43 +01006046 return 0;
6047
6048#undef FILL_IN_MESH_PARAM_IF_SET
6049}
6050
Javier Cardonac80d5452010-12-16 17:37:49 -08006051static int nl80211_parse_mesh_setup(struct genl_info *info,
6052 struct mesh_setup *setup)
6053{
Thomas Pedersenbb2798d2013-03-04 13:06:10 -08006054 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Javier Cardonac80d5452010-12-16 17:37:49 -08006055 struct nlattr *tb[NL80211_MESH_SETUP_ATTR_MAX + 1];
6056
6057 if (!info->attrs[NL80211_ATTR_MESH_SETUP])
6058 return -EINVAL;
6059 if (nla_parse_nested(tb, NL80211_MESH_SETUP_ATTR_MAX,
6060 info->attrs[NL80211_ATTR_MESH_SETUP],
Johannes Bergfe521452017-04-12 14:34:08 +02006061 nl80211_mesh_setup_params_policy, info->extack))
Javier Cardonac80d5452010-12-16 17:37:49 -08006062 return -EINVAL;
6063
Javier Cardonad299a1f2012-03-31 11:31:33 -07006064 if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC])
6065 setup->sync_method =
6066 (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC])) ?
6067 IEEE80211_SYNC_METHOD_VENDOR :
6068 IEEE80211_SYNC_METHOD_NEIGHBOR_OFFSET;
6069
Javier Cardonac80d5452010-12-16 17:37:49 -08006070 if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL])
6071 setup->path_sel_proto =
6072 (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL])) ?
6073 IEEE80211_PATH_PROTOCOL_VENDOR :
6074 IEEE80211_PATH_PROTOCOL_HWMP;
6075
6076 if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC])
6077 setup->path_metric =
6078 (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC])) ?
6079 IEEE80211_PATH_METRIC_VENDOR :
6080 IEEE80211_PATH_METRIC_AIRTIME;
6081
Javier Cardona581a8b02011-04-07 15:08:27 -07006082 if (tb[NL80211_MESH_SETUP_IE]) {
Javier Cardonac80d5452010-12-16 17:37:49 -08006083 struct nlattr *ieattr =
Javier Cardona581a8b02011-04-07 15:08:27 -07006084 tb[NL80211_MESH_SETUP_IE];
Javier Cardonac80d5452010-12-16 17:37:49 -08006085 if (!is_valid_ie_attr(ieattr))
6086 return -EINVAL;
Javier Cardona581a8b02011-04-07 15:08:27 -07006087 setup->ie = nla_data(ieattr);
6088 setup->ie_len = nla_len(ieattr);
Javier Cardonac80d5452010-12-16 17:37:49 -08006089 }
Thomas Pedersenbb2798d2013-03-04 13:06:10 -08006090 if (tb[NL80211_MESH_SETUP_USERSPACE_MPM] &&
6091 !(rdev->wiphy.features & NL80211_FEATURE_USERSPACE_MPM))
6092 return -EINVAL;
6093 setup->user_mpm = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_MPM]);
Javier Cardonab130e5c2011-05-03 16:57:07 -07006094 setup->is_authenticated = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AUTH]);
6095 setup->is_secure = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AMPE]);
Thomas Pedersenbb2798d2013-03-04 13:06:10 -08006096 if (setup->is_secure)
6097 setup->user_mpm = true;
Javier Cardonac80d5452010-12-16 17:37:49 -08006098
Colleen Twitty6e16d902013-05-08 11:45:59 -07006099 if (tb[NL80211_MESH_SETUP_AUTH_PROTOCOL]) {
6100 if (!setup->user_mpm)
6101 return -EINVAL;
6102 setup->auth_id =
6103 nla_get_u8(tb[NL80211_MESH_SETUP_AUTH_PROTOCOL]);
6104 }
6105
Javier Cardonac80d5452010-12-16 17:37:49 -08006106 return 0;
6107}
6108
Javier Cardona24bdd9f2010-12-16 17:37:48 -08006109static int nl80211_update_mesh_config(struct sk_buff *skb,
Johannes Berg29cbe682010-12-03 09:20:44 +01006110 struct genl_info *info)
Johannes Bergbd90fdc2010-12-03 09:20:43 +01006111{
6112 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6113 struct net_device *dev = info->user_ptr[1];
Johannes Berg29cbe682010-12-03 09:20:44 +01006114 struct wireless_dev *wdev = dev->ieee80211_ptr;
Johannes Bergbd90fdc2010-12-03 09:20:43 +01006115 struct mesh_config cfg;
6116 u32 mask;
6117 int err;
6118
Johannes Berg29cbe682010-12-03 09:20:44 +01006119 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT)
6120 return -EOPNOTSUPP;
6121
Javier Cardona24bdd9f2010-12-16 17:37:48 -08006122 if (!rdev->ops->update_mesh_config)
Johannes Bergbd90fdc2010-12-03 09:20:43 +01006123 return -EOPNOTSUPP;
6124
Javier Cardona24bdd9f2010-12-16 17:37:48 -08006125 err = nl80211_parse_mesh_config(info, &cfg, &mask);
Johannes Bergbd90fdc2010-12-03 09:20:43 +01006126 if (err)
6127 return err;
6128
Johannes Berg29cbe682010-12-03 09:20:44 +01006129 wdev_lock(wdev);
6130 if (!wdev->mesh_id_len)
6131 err = -ENOLINK;
6132
6133 if (!err)
Hila Gonene35e4d22012-06-27 17:19:42 +03006134 err = rdev_update_mesh_config(rdev, dev, mask, &cfg);
Johannes Berg29cbe682010-12-03 09:20:44 +01006135
6136 wdev_unlock(wdev);
6137
6138 return err;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07006139}
6140
Arik Nemtsovad30ca22014-12-15 19:25:59 +02006141static int nl80211_put_regdom(const struct ieee80211_regdomain *regdom,
6142 struct sk_buff *msg)
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08006143{
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08006144 struct nlattr *nl_reg_rules;
6145 unsigned int i;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08006146
Johannes Berg458f4f92012-12-06 15:47:38 +01006147 if (nla_put_string(msg, NL80211_ATTR_REG_ALPHA2, regdom->alpha2) ||
6148 (regdom->dfs_region &&
6149 nla_put_u8(msg, NL80211_ATTR_DFS_REGION, regdom->dfs_region)))
Arik Nemtsovad30ca22014-12-15 19:25:59 +02006150 goto nla_put_failure;
Johannes Berg458f4f92012-12-06 15:47:38 +01006151
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08006152 nl_reg_rules = nla_nest_start(msg, NL80211_ATTR_REG_RULES);
6153 if (!nl_reg_rules)
Arik Nemtsovad30ca22014-12-15 19:25:59 +02006154 goto nla_put_failure;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08006155
Johannes Berg458f4f92012-12-06 15:47:38 +01006156 for (i = 0; i < regdom->n_reg_rules; i++) {
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08006157 struct nlattr *nl_reg_rule;
6158 const struct ieee80211_reg_rule *reg_rule;
6159 const struct ieee80211_freq_range *freq_range;
6160 const struct ieee80211_power_rule *power_rule;
Janusz Dziedzic97524822014-01-30 09:52:20 +01006161 unsigned int max_bandwidth_khz;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08006162
Johannes Berg458f4f92012-12-06 15:47:38 +01006163 reg_rule = &regdom->reg_rules[i];
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08006164 freq_range = &reg_rule->freq_range;
6165 power_rule = &reg_rule->power_rule;
6166
6167 nl_reg_rule = nla_nest_start(msg, i);
6168 if (!nl_reg_rule)
Arik Nemtsovad30ca22014-12-15 19:25:59 +02006169 goto nla_put_failure;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08006170
Janusz Dziedzic97524822014-01-30 09:52:20 +01006171 max_bandwidth_khz = freq_range->max_bandwidth_khz;
6172 if (!max_bandwidth_khz)
6173 max_bandwidth_khz = reg_get_max_bandwidth(regdom,
6174 reg_rule);
6175
David S. Miller9360ffd2012-03-29 04:41:26 -04006176 if (nla_put_u32(msg, NL80211_ATTR_REG_RULE_FLAGS,
6177 reg_rule->flags) ||
6178 nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_START,
6179 freq_range->start_freq_khz) ||
6180 nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_END,
6181 freq_range->end_freq_khz) ||
6182 nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_MAX_BW,
Janusz Dziedzic97524822014-01-30 09:52:20 +01006183 max_bandwidth_khz) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04006184 nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN,
6185 power_rule->max_antenna_gain) ||
6186 nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_EIRP,
Janusz Dziedzic089027e2014-02-21 19:46:12 +01006187 power_rule->max_eirp) ||
6188 nla_put_u32(msg, NL80211_ATTR_DFS_CAC_TIME,
6189 reg_rule->dfs_cac_ms))
Arik Nemtsovad30ca22014-12-15 19:25:59 +02006190 goto nla_put_failure;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08006191
6192 nla_nest_end(msg, nl_reg_rule);
6193 }
6194
6195 nla_nest_end(msg, nl_reg_rules);
Arik Nemtsovad30ca22014-12-15 19:25:59 +02006196 return 0;
6197
6198nla_put_failure:
6199 return -EMSGSIZE;
6200}
6201
6202static int nl80211_get_reg_do(struct sk_buff *skb, struct genl_info *info)
6203{
6204 const struct ieee80211_regdomain *regdom = NULL;
6205 struct cfg80211_registered_device *rdev;
6206 struct wiphy *wiphy = NULL;
6207 struct sk_buff *msg;
6208 void *hdr;
6209
6210 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
6211 if (!msg)
6212 return -ENOBUFS;
6213
6214 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
6215 NL80211_CMD_GET_REG);
6216 if (!hdr)
6217 goto put_failure;
6218
6219 if (info->attrs[NL80211_ATTR_WIPHY]) {
Arik Nemtsov1bdd7162014-12-15 19:26:01 +02006220 bool self_managed;
6221
Arik Nemtsovad30ca22014-12-15 19:25:59 +02006222 rdev = cfg80211_get_dev_from_info(genl_info_net(info), info);
6223 if (IS_ERR(rdev)) {
6224 nlmsg_free(msg);
6225 return PTR_ERR(rdev);
6226 }
6227
6228 wiphy = &rdev->wiphy;
Arik Nemtsov1bdd7162014-12-15 19:26:01 +02006229 self_managed = wiphy->regulatory_flags &
6230 REGULATORY_WIPHY_SELF_MANAGED;
Arik Nemtsovad30ca22014-12-15 19:25:59 +02006231 regdom = get_wiphy_regdom(wiphy);
6232
Arik Nemtsov1bdd7162014-12-15 19:26:01 +02006233 /* a self-managed-reg device must have a private regdom */
6234 if (WARN_ON(!regdom && self_managed)) {
6235 nlmsg_free(msg);
6236 return -EINVAL;
6237 }
6238
Arik Nemtsovad30ca22014-12-15 19:25:59 +02006239 if (regdom &&
6240 nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy)))
6241 goto nla_put_failure;
6242 }
6243
6244 if (!wiphy && reg_last_request_cell_base() &&
6245 nla_put_u32(msg, NL80211_ATTR_USER_REG_HINT_TYPE,
6246 NL80211_USER_REG_HINT_CELL_BASE))
6247 goto nla_put_failure;
6248
6249 rcu_read_lock();
6250
6251 if (!regdom)
6252 regdom = rcu_dereference(cfg80211_regdomain);
6253
6254 if (nl80211_put_regdom(regdom, msg))
6255 goto nla_put_failure_rcu;
6256
6257 rcu_read_unlock();
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08006258
6259 genlmsg_end(msg, hdr);
Johannes Berg5fe231e2013-05-08 21:45:15 +02006260 return genlmsg_reply(msg, info);
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08006261
Johannes Berg458f4f92012-12-06 15:47:38 +01006262nla_put_failure_rcu:
6263 rcu_read_unlock();
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08006264nla_put_failure:
6265 genlmsg_cancel(msg, hdr);
Julia Lawallefe1cf02011-01-28 15:17:11 +01006266put_failure:
Yuri Ershovd080e272010-06-29 15:08:07 +04006267 nlmsg_free(msg);
Johannes Berg5fe231e2013-05-08 21:45:15 +02006268 return -EMSGSIZE;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08006269}
6270
Arik Nemtsovad30ca22014-12-15 19:25:59 +02006271static int nl80211_send_regdom(struct sk_buff *msg, struct netlink_callback *cb,
6272 u32 seq, int flags, struct wiphy *wiphy,
6273 const struct ieee80211_regdomain *regdom)
6274{
6275 void *hdr = nl80211hdr_put(msg, NETLINK_CB(cb->skb).portid, seq, flags,
6276 NL80211_CMD_GET_REG);
6277
6278 if (!hdr)
6279 return -1;
6280
6281 genl_dump_check_consistent(cb, hdr, &nl80211_fam);
6282
6283 if (nl80211_put_regdom(regdom, msg))
6284 goto nla_put_failure;
6285
6286 if (!wiphy && reg_last_request_cell_base() &&
6287 nla_put_u32(msg, NL80211_ATTR_USER_REG_HINT_TYPE,
6288 NL80211_USER_REG_HINT_CELL_BASE))
6289 goto nla_put_failure;
6290
6291 if (wiphy &&
6292 nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy)))
6293 goto nla_put_failure;
6294
Arik Nemtsov1bdd7162014-12-15 19:26:01 +02006295 if (wiphy && wiphy->regulatory_flags & REGULATORY_WIPHY_SELF_MANAGED &&
6296 nla_put_flag(msg, NL80211_ATTR_WIPHY_SELF_MANAGED_REG))
6297 goto nla_put_failure;
6298
Johannes Berg053c0952015-01-16 22:09:00 +01006299 genlmsg_end(msg, hdr);
6300 return 0;
Arik Nemtsovad30ca22014-12-15 19:25:59 +02006301
6302nla_put_failure:
6303 genlmsg_cancel(msg, hdr);
6304 return -EMSGSIZE;
6305}
6306
6307static int nl80211_get_reg_dump(struct sk_buff *skb,
6308 struct netlink_callback *cb)
6309{
6310 const struct ieee80211_regdomain *regdom = NULL;
6311 struct cfg80211_registered_device *rdev;
6312 int err, reg_idx, start = cb->args[2];
6313
6314 rtnl_lock();
6315
6316 if (cfg80211_regdomain && start == 0) {
6317 err = nl80211_send_regdom(skb, cb, cb->nlh->nlmsg_seq,
6318 NLM_F_MULTI, NULL,
6319 rtnl_dereference(cfg80211_regdomain));
6320 if (err < 0)
6321 goto out_err;
6322 }
6323
6324 /* the global regdom is idx 0 */
6325 reg_idx = 1;
6326 list_for_each_entry(rdev, &cfg80211_rdev_list, list) {
6327 regdom = get_wiphy_regdom(&rdev->wiphy);
6328 if (!regdom)
6329 continue;
6330
6331 if (++reg_idx <= start)
6332 continue;
6333
6334 err = nl80211_send_regdom(skb, cb, cb->nlh->nlmsg_seq,
6335 NLM_F_MULTI, &rdev->wiphy, regdom);
6336 if (err < 0) {
6337 reg_idx--;
6338 break;
6339 }
6340 }
6341
6342 cb->args[2] = reg_idx;
6343 err = skb->len;
6344out_err:
6345 rtnl_unlock();
6346 return err;
6347}
6348
Johannes Bergb6863032015-10-15 09:25:18 +02006349#ifdef CONFIG_CFG80211_CRDA_SUPPORT
6350static const struct nla_policy reg_rule_policy[NL80211_REG_RULE_ATTR_MAX + 1] = {
6351 [NL80211_ATTR_REG_RULE_FLAGS] = { .type = NLA_U32 },
6352 [NL80211_ATTR_FREQ_RANGE_START] = { .type = NLA_U32 },
6353 [NL80211_ATTR_FREQ_RANGE_END] = { .type = NLA_U32 },
6354 [NL80211_ATTR_FREQ_RANGE_MAX_BW] = { .type = NLA_U32 },
6355 [NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN] = { .type = NLA_U32 },
6356 [NL80211_ATTR_POWER_RULE_MAX_EIRP] = { .type = NLA_U32 },
6357 [NL80211_ATTR_DFS_CAC_TIME] = { .type = NLA_U32 },
6358};
6359
6360static int parse_reg_rule(struct nlattr *tb[],
6361 struct ieee80211_reg_rule *reg_rule)
6362{
6363 struct ieee80211_freq_range *freq_range = &reg_rule->freq_range;
6364 struct ieee80211_power_rule *power_rule = &reg_rule->power_rule;
6365
6366 if (!tb[NL80211_ATTR_REG_RULE_FLAGS])
6367 return -EINVAL;
6368 if (!tb[NL80211_ATTR_FREQ_RANGE_START])
6369 return -EINVAL;
6370 if (!tb[NL80211_ATTR_FREQ_RANGE_END])
6371 return -EINVAL;
6372 if (!tb[NL80211_ATTR_FREQ_RANGE_MAX_BW])
6373 return -EINVAL;
6374 if (!tb[NL80211_ATTR_POWER_RULE_MAX_EIRP])
6375 return -EINVAL;
6376
6377 reg_rule->flags = nla_get_u32(tb[NL80211_ATTR_REG_RULE_FLAGS]);
6378
6379 freq_range->start_freq_khz =
6380 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_START]);
6381 freq_range->end_freq_khz =
6382 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_END]);
6383 freq_range->max_bandwidth_khz =
6384 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]);
6385
6386 power_rule->max_eirp =
6387 nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]);
6388
6389 if (tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN])
6390 power_rule->max_antenna_gain =
6391 nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]);
6392
6393 if (tb[NL80211_ATTR_DFS_CAC_TIME])
6394 reg_rule->dfs_cac_ms =
6395 nla_get_u32(tb[NL80211_ATTR_DFS_CAC_TIME]);
6396
6397 return 0;
6398}
6399
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07006400static int nl80211_set_reg(struct sk_buff *skb, struct genl_info *info)
6401{
6402 struct nlattr *tb[NL80211_REG_RULE_ATTR_MAX + 1];
6403 struct nlattr *nl_reg_rule;
Johannes Bergea372c52014-11-28 14:54:31 +01006404 char *alpha2;
6405 int rem_reg_rules, r;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07006406 u32 num_rules = 0, rule_idx = 0, size_of_regd;
Luis R. Rodriguez4c7d3982013-11-13 18:54:02 +01006407 enum nl80211_dfs_regions dfs_region = NL80211_DFS_UNSET;
Johannes Bergea372c52014-11-28 14:54:31 +01006408 struct ieee80211_regdomain *rd;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07006409
6410 if (!info->attrs[NL80211_ATTR_REG_ALPHA2])
6411 return -EINVAL;
6412
6413 if (!info->attrs[NL80211_ATTR_REG_RULES])
6414 return -EINVAL;
6415
6416 alpha2 = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]);
6417
Luis R. Rodriguez8b60b072011-10-11 10:59:02 -07006418 if (info->attrs[NL80211_ATTR_DFS_REGION])
6419 dfs_region = nla_get_u8(info->attrs[NL80211_ATTR_DFS_REGION]);
6420
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07006421 nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES],
Johannes Berg1a919312012-12-03 17:21:11 +01006422 rem_reg_rules) {
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07006423 num_rules++;
6424 if (num_rules > NL80211_MAX_SUPP_REG_RULES)
Luis R. Rodriguez4776c6e2009-05-13 17:04:39 -04006425 return -EINVAL;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07006426 }
6427
Luis R. Rodrigueze4387682013-11-05 09:18:01 -08006428 if (!reg_is_valid_request(alpha2))
6429 return -EINVAL;
6430
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07006431 size_of_regd = sizeof(struct ieee80211_regdomain) +
Johannes Berg1a919312012-12-03 17:21:11 +01006432 num_rules * sizeof(struct ieee80211_reg_rule);
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07006433
6434 rd = kzalloc(size_of_regd, GFP_KERNEL);
Johannes Berg6913b492012-12-04 00:48:59 +01006435 if (!rd)
6436 return -ENOMEM;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07006437
6438 rd->n_reg_rules = num_rules;
6439 rd->alpha2[0] = alpha2[0];
6440 rd->alpha2[1] = alpha2[1];
6441
Luis R. Rodriguez8b60b072011-10-11 10:59:02 -07006442 /*
6443 * Disable DFS master mode if the DFS region was
6444 * not supported or known on this kernel.
6445 */
6446 if (reg_supported_dfs_region(dfs_region))
6447 rd->dfs_region = dfs_region;
6448
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07006449 nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES],
Johannes Berg1a919312012-12-03 17:21:11 +01006450 rem_reg_rules) {
Johannes Bergbfe2c7b2016-10-26 14:42:21 +02006451 r = nla_parse_nested(tb, NL80211_REG_RULE_ATTR_MAX,
Johannes Bergfe521452017-04-12 14:34:08 +02006452 nl_reg_rule, reg_rule_policy,
6453 info->extack);
Johannes Bergae811e22014-01-24 10:17:47 +01006454 if (r)
6455 goto bad_reg;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07006456 r = parse_reg_rule(tb, &rd->reg_rules[rule_idx]);
6457 if (r)
6458 goto bad_reg;
6459
6460 rule_idx++;
6461
Luis R. Rodriguezd0e18f82009-05-13 17:04:40 -04006462 if (rule_idx > NL80211_MAX_SUPP_REG_RULES) {
6463 r = -EINVAL;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07006464 goto bad_reg;
Luis R. Rodriguezd0e18f82009-05-13 17:04:40 -04006465 }
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07006466 }
6467
Johannes Berg06627992016-06-09 10:40:09 +02006468 /* set_regdom takes ownership of rd */
6469 return set_regdom(rd, REGD_SOURCE_CRDA);
Johannes Bergd2372b32008-10-24 20:32:20 +02006470 bad_reg:
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07006471 kfree(rd);
Luis R. Rodriguezd0e18f82009-05-13 17:04:40 -04006472 return r;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07006473}
Johannes Bergb6863032015-10-15 09:25:18 +02006474#endif /* CONFIG_CFG80211_CRDA_SUPPORT */
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07006475
Johannes Berg83f5e2c2009-06-17 17:41:49 +02006476static int validate_scan_freqs(struct nlattr *freqs)
6477{
6478 struct nlattr *attr1, *attr2;
6479 int n_channels = 0, tmp1, tmp2;
6480
Srinivas Dasarid7f13f72017-07-07 01:43:42 +03006481 nla_for_each_nested(attr1, freqs, tmp1)
6482 if (nla_len(attr1) != sizeof(u32))
6483 return 0;
6484
Johannes Berg83f5e2c2009-06-17 17:41:49 +02006485 nla_for_each_nested(attr1, freqs, tmp1) {
6486 n_channels++;
6487 /*
6488 * Some hardware has a limited channel list for
6489 * scanning, and it is pretty much nonsensical
6490 * to scan for a channel twice, so disallow that
6491 * and don't require drivers to check that the
6492 * channel list they get isn't longer than what
6493 * they can scan, as long as they can scan all
6494 * the channels they registered at once.
6495 */
6496 nla_for_each_nested(attr2, freqs, tmp2)
6497 if (attr1 != attr2 &&
6498 nla_get_u32(attr1) == nla_get_u32(attr2))
6499 return 0;
6500 }
6501
6502 return n_channels;
6503}
6504
Johannes Berg57fbcce2016-04-12 15:56:15 +02006505static bool is_band_valid(struct wiphy *wiphy, enum nl80211_band b)
Arend van Spriel38de03d2016-03-02 20:37:18 +01006506{
Johannes Berg57fbcce2016-04-12 15:56:15 +02006507 return b < NUM_NL80211_BANDS && wiphy->bands[b];
Arend van Spriel38de03d2016-03-02 20:37:18 +01006508}
6509
6510static int parse_bss_select(struct nlattr *nla, struct wiphy *wiphy,
6511 struct cfg80211_bss_selection *bss_select)
6512{
6513 struct nlattr *attr[NL80211_BSS_SELECT_ATTR_MAX + 1];
6514 struct nlattr *nest;
6515 int err;
6516 bool found = false;
6517 int i;
6518
6519 /* only process one nested attribute */
6520 nest = nla_data(nla);
6521 if (!nla_ok(nest, nla_len(nest)))
6522 return -EINVAL;
6523
Johannes Bergbfe2c7b2016-10-26 14:42:21 +02006524 err = nla_parse_nested(attr, NL80211_BSS_SELECT_ATTR_MAX, nest,
Johannes Bergfceb6432017-04-12 14:34:07 +02006525 nl80211_bss_select_policy, NULL);
Arend van Spriel38de03d2016-03-02 20:37:18 +01006526 if (err)
6527 return err;
6528
6529 /* only one attribute may be given */
6530 for (i = 0; i <= NL80211_BSS_SELECT_ATTR_MAX; i++) {
6531 if (attr[i]) {
6532 if (found)
6533 return -EINVAL;
6534 found = true;
6535 }
6536 }
6537
6538 bss_select->behaviour = __NL80211_BSS_SELECT_ATTR_INVALID;
6539
6540 if (attr[NL80211_BSS_SELECT_ATTR_RSSI])
6541 bss_select->behaviour = NL80211_BSS_SELECT_ATTR_RSSI;
6542
6543 if (attr[NL80211_BSS_SELECT_ATTR_BAND_PREF]) {
6544 bss_select->behaviour = NL80211_BSS_SELECT_ATTR_BAND_PREF;
6545 bss_select->param.band_pref =
6546 nla_get_u32(attr[NL80211_BSS_SELECT_ATTR_BAND_PREF]);
6547 if (!is_band_valid(wiphy, bss_select->param.band_pref))
6548 return -EINVAL;
6549 }
6550
6551 if (attr[NL80211_BSS_SELECT_ATTR_RSSI_ADJUST]) {
6552 struct nl80211_bss_select_rssi_adjust *adj_param;
6553
6554 adj_param = nla_data(attr[NL80211_BSS_SELECT_ATTR_RSSI_ADJUST]);
6555 bss_select->behaviour = NL80211_BSS_SELECT_ATTR_RSSI_ADJUST;
6556 bss_select->param.adjust.band = adj_param->band;
6557 bss_select->param.adjust.delta = adj_param->delta;
6558 if (!is_band_valid(wiphy, bss_select->param.adjust.band))
6559 return -EINVAL;
6560 }
6561
6562 /* user-space did not provide behaviour attribute */
6563 if (bss_select->behaviour == __NL80211_BSS_SELECT_ATTR_INVALID)
6564 return -EINVAL;
6565
6566 if (!(wiphy->bss_select_support & BIT(bss_select->behaviour)))
6567 return -EINVAL;
6568
6569 return 0;
6570}
6571
Johannes Bergad2b26a2014-06-12 21:39:05 +02006572static int nl80211_parse_random_mac(struct nlattr **attrs,
6573 u8 *mac_addr, u8 *mac_addr_mask)
6574{
6575 int i;
6576
6577 if (!attrs[NL80211_ATTR_MAC] && !attrs[NL80211_ATTR_MAC_MASK]) {
Joe Perchesd2beae12015-03-02 19:54:58 -08006578 eth_zero_addr(mac_addr);
6579 eth_zero_addr(mac_addr_mask);
Johannes Bergad2b26a2014-06-12 21:39:05 +02006580 mac_addr[0] = 0x2;
6581 mac_addr_mask[0] = 0x3;
6582
6583 return 0;
6584 }
6585
6586 /* need both or none */
6587 if (!attrs[NL80211_ATTR_MAC] || !attrs[NL80211_ATTR_MAC_MASK])
6588 return -EINVAL;
6589
6590 memcpy(mac_addr, nla_data(attrs[NL80211_ATTR_MAC]), ETH_ALEN);
6591 memcpy(mac_addr_mask, nla_data(attrs[NL80211_ATTR_MAC_MASK]), ETH_ALEN);
6592
6593 /* don't allow or configure an mcast address */
6594 if (!is_multicast_ether_addr(mac_addr_mask) ||
6595 is_multicast_ether_addr(mac_addr))
6596 return -EINVAL;
6597
6598 /*
6599 * allow users to pass a MAC address that has bits set outside
6600 * of the mask, but don't bother drivers with having to deal
6601 * with such bits
6602 */
6603 for (i = 0; i < ETH_ALEN; i++)
6604 mac_addr[i] &= mac_addr_mask[i];
6605
6606 return 0;
6607}
6608
Vasanthakumar Thiagarajan34373d12017-02-27 17:04:34 +05306609static bool cfg80211_off_channel_oper_allowed(struct wireless_dev *wdev)
6610{
6611 ASSERT_WDEV_LOCK(wdev);
6612
6613 if (!cfg80211_beaconing_iface_active(wdev))
6614 return true;
6615
6616 if (!(wdev->chandef.chan->flags & IEEE80211_CHAN_RADAR))
6617 return true;
6618
6619 return regulatory_pre_cac_allowed(wdev->wiphy);
6620}
6621
Roee Zamir2d23d072017-08-06 11:38:22 +03006622static int
6623nl80211_check_scan_flags(struct wiphy *wiphy, struct wireless_dev *wdev,
6624 void *request, struct nlattr **attrs,
6625 bool is_sched_scan)
6626{
6627 u8 *mac_addr, *mac_addr_mask;
6628 u32 *flags;
6629 enum nl80211_feature_flags randomness_flag;
6630
6631 if (!attrs[NL80211_ATTR_SCAN_FLAGS])
6632 return 0;
6633
6634 if (is_sched_scan) {
6635 struct cfg80211_sched_scan_request *req = request;
6636
6637 randomness_flag = wdev ?
6638 NL80211_FEATURE_SCHED_SCAN_RANDOM_MAC_ADDR :
6639 NL80211_FEATURE_ND_RANDOM_MAC_ADDR;
6640 flags = &req->flags;
6641 mac_addr = req->mac_addr;
6642 mac_addr_mask = req->mac_addr_mask;
6643 } else {
6644 struct cfg80211_scan_request *req = request;
6645
6646 randomness_flag = NL80211_FEATURE_SCAN_RANDOM_MAC_ADDR;
6647 flags = &req->flags;
6648 mac_addr = req->mac_addr;
6649 mac_addr_mask = req->mac_addr_mask;
6650 }
6651
6652 *flags = nla_get_u32(attrs[NL80211_ATTR_SCAN_FLAGS]);
6653
6654 if ((*flags & NL80211_SCAN_FLAG_LOW_PRIORITY) &&
6655 !(wiphy->features & NL80211_FEATURE_LOW_PRIORITY_SCAN))
6656 return -EOPNOTSUPP;
6657
6658 if (*flags & NL80211_SCAN_FLAG_RANDOM_ADDR) {
6659 int err;
6660
6661 if (!(wiphy->features & randomness_flag) ||
6662 (wdev && wdev->current_bss))
6663 return -EOPNOTSUPP;
6664
6665 err = nl80211_parse_random_mac(attrs, mac_addr, mac_addr_mask);
6666 if (err)
6667 return err;
6668 }
6669
6670 if ((*flags & NL80211_SCAN_FLAG_FILS_MAX_CHANNEL_TIME) &&
6671 !wiphy_ext_feature_isset(wiphy,
6672 NL80211_EXT_FEATURE_FILS_MAX_CHANNEL_TIME))
6673 return -EOPNOTSUPP;
6674
6675 if ((*flags & NL80211_SCAN_FLAG_ACCEPT_BCAST_PROBE_RESP) &&
6676 !wiphy_ext_feature_isset(wiphy,
6677 NL80211_EXT_FEATURE_ACCEPT_BCAST_PROBE_RESP))
6678 return -EOPNOTSUPP;
6679
6680 if ((*flags & NL80211_SCAN_FLAG_OCE_PROBE_REQ_DEFERRAL_SUPPRESSION) &&
6681 !wiphy_ext_feature_isset(wiphy,
6682 NL80211_EXT_FEATURE_OCE_PROBE_REQ_DEFERRAL_SUPPRESSION))
6683 return -EOPNOTSUPP;
6684
6685 if ((*flags & NL80211_SCAN_FLAG_OCE_PROBE_REQ_HIGH_TX_RATE) &&
6686 !wiphy_ext_feature_isset(wiphy,
6687 NL80211_EXT_FEATURE_OCE_PROBE_REQ_HIGH_TX_RATE))
6688 return -EOPNOTSUPP;
6689
6690 return 0;
6691}
6692
Johannes Berg2a519312009-02-10 21:25:55 +01006693static int nl80211_trigger_scan(struct sk_buff *skb, struct genl_info *info)
6694{
Johannes Berg4c476992010-10-04 21:36:35 +02006695 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Bergfd014282012-06-18 19:17:03 +02006696 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg2a519312009-02-10 21:25:55 +01006697 struct cfg80211_scan_request *request;
Johannes Berg2a519312009-02-10 21:25:55 +01006698 struct nlattr *attr;
6699 struct wiphy *wiphy;
Johannes Berg83f5e2c2009-06-17 17:41:49 +02006700 int err, tmp, n_ssids = 0, n_channels, i;
Jouni Malinen70692ad2009-02-16 19:39:13 +02006701 size_t ie_len;
Johannes Berg2a519312009-02-10 21:25:55 +01006702
Johannes Bergf4a11bb2009-03-27 12:40:28 +01006703 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
6704 return -EINVAL;
6705
Johannes Berg79c97e92009-07-07 03:56:12 +02006706 wiphy = &rdev->wiphy;
Johannes Berg2a519312009-02-10 21:25:55 +01006707
Ayala Bekercb3b7d82016-09-20 17:31:13 +03006708 if (wdev->iftype == NL80211_IFTYPE_NAN)
6709 return -EOPNOTSUPP;
6710
Johannes Berg4c476992010-10-04 21:36:35 +02006711 if (!rdev->ops->scan)
6712 return -EOPNOTSUPP;
Johannes Berg2a519312009-02-10 21:25:55 +01006713
Johannes Bergf9d15d12014-01-22 11:14:19 +02006714 if (rdev->scan_req || rdev->scan_msg) {
Johannes Bergf9f47522013-03-19 15:04:07 +01006715 err = -EBUSY;
6716 goto unlock;
6717 }
Johannes Berg2a519312009-02-10 21:25:55 +01006718
6719 if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
Johannes Berg83f5e2c2009-06-17 17:41:49 +02006720 n_channels = validate_scan_freqs(
6721 info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]);
Johannes Bergf9f47522013-03-19 15:04:07 +01006722 if (!n_channels) {
6723 err = -EINVAL;
6724 goto unlock;
6725 }
Johannes Berg2a519312009-02-10 21:25:55 +01006726 } else {
Ilan Peerbdfbec22014-01-09 11:37:23 +02006727 n_channels = ieee80211_get_num_supported_channels(wiphy);
Johannes Berg2a519312009-02-10 21:25:55 +01006728 }
6729
6730 if (info->attrs[NL80211_ATTR_SCAN_SSIDS])
6731 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp)
6732 n_ssids++;
6733
Johannes Bergf9f47522013-03-19 15:04:07 +01006734 if (n_ssids > wiphy->max_scan_ssids) {
6735 err = -EINVAL;
6736 goto unlock;
6737 }
Johannes Berg2a519312009-02-10 21:25:55 +01006738
Jouni Malinen70692ad2009-02-16 19:39:13 +02006739 if (info->attrs[NL80211_ATTR_IE])
6740 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
6741 else
6742 ie_len = 0;
6743
Johannes Bergf9f47522013-03-19 15:04:07 +01006744 if (ie_len > wiphy->max_scan_ie_len) {
6745 err = -EINVAL;
6746 goto unlock;
6747 }
Johannes Berg18a83652009-03-31 12:12:05 +02006748
Johannes Berg2a519312009-02-10 21:25:55 +01006749 request = kzalloc(sizeof(*request)
Luciano Coelhoa2cd43c2011-05-18 11:42:03 +03006750 + sizeof(*request->ssids) * n_ssids
6751 + sizeof(*request->channels) * n_channels
Jouni Malinen70692ad2009-02-16 19:39:13 +02006752 + ie_len, GFP_KERNEL);
Johannes Bergf9f47522013-03-19 15:04:07 +01006753 if (!request) {
6754 err = -ENOMEM;
6755 goto unlock;
6756 }
Johannes Berg2a519312009-02-10 21:25:55 +01006757
Johannes Berg2a519312009-02-10 21:25:55 +01006758 if (n_ssids)
Johannes Berg5ba63532009-08-07 17:54:07 +02006759 request->ssids = (void *)&request->channels[n_channels];
Johannes Berg2a519312009-02-10 21:25:55 +01006760 request->n_ssids = n_ssids;
Jouni Malinen70692ad2009-02-16 19:39:13 +02006761 if (ie_len) {
Johannes Berg13874e42015-01-23 11:25:20 +01006762 if (n_ssids)
Jouni Malinen70692ad2009-02-16 19:39:13 +02006763 request->ie = (void *)(request->ssids + n_ssids);
6764 else
6765 request->ie = (void *)(request->channels + n_channels);
6766 }
Johannes Berg2a519312009-02-10 21:25:55 +01006767
Johannes Berg584991d2009-11-02 13:32:03 +01006768 i = 0;
Johannes Berg2a519312009-02-10 21:25:55 +01006769 if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
6770 /* user specified, bail out if channel not found */
Johannes Berg2a519312009-02-10 21:25:55 +01006771 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_FREQUENCIES], tmp) {
Johannes Berg584991d2009-11-02 13:32:03 +01006772 struct ieee80211_channel *chan;
6773
6774 chan = ieee80211_get_channel(wiphy, nla_get_u32(attr));
6775
6776 if (!chan) {
Johannes Berg2a519312009-02-10 21:25:55 +01006777 err = -EINVAL;
6778 goto out_free;
6779 }
Johannes Berg584991d2009-11-02 13:32:03 +01006780
6781 /* ignore disabled channels */
6782 if (chan->flags & IEEE80211_CHAN_DISABLED)
6783 continue;
6784
6785 request->channels[i] = chan;
Johannes Berg2a519312009-02-10 21:25:55 +01006786 i++;
6787 }
6788 } else {
Johannes Berg57fbcce2016-04-12 15:56:15 +02006789 enum nl80211_band band;
Johannes Berg34850ab2011-07-18 18:08:35 +02006790
Johannes Berg2a519312009-02-10 21:25:55 +01006791 /* all channels */
Johannes Berg57fbcce2016-04-12 15:56:15 +02006792 for (band = 0; band < NUM_NL80211_BANDS; band++) {
Johannes Berg2a519312009-02-10 21:25:55 +01006793 int j;
Kirtika Ruchandani7a087e72016-05-29 19:51:23 -07006794
Johannes Berg2a519312009-02-10 21:25:55 +01006795 if (!wiphy->bands[band])
6796 continue;
6797 for (j = 0; j < wiphy->bands[band]->n_channels; j++) {
Johannes Berg584991d2009-11-02 13:32:03 +01006798 struct ieee80211_channel *chan;
6799
6800 chan = &wiphy->bands[band]->channels[j];
6801
6802 if (chan->flags & IEEE80211_CHAN_DISABLED)
6803 continue;
6804
6805 request->channels[i] = chan;
Johannes Berg2a519312009-02-10 21:25:55 +01006806 i++;
6807 }
6808 }
6809 }
6810
Johannes Berg584991d2009-11-02 13:32:03 +01006811 if (!i) {
6812 err = -EINVAL;
6813 goto out_free;
6814 }
6815
6816 request->n_channels = i;
6817
Vasanthakumar Thiagarajan34373d12017-02-27 17:04:34 +05306818 wdev_lock(wdev);
6819 if (!cfg80211_off_channel_oper_allowed(wdev)) {
6820 struct ieee80211_channel *chan;
6821
6822 if (request->n_channels != 1) {
6823 wdev_unlock(wdev);
6824 err = -EBUSY;
6825 goto out_free;
6826 }
6827
6828 chan = request->channels[0];
6829 if (chan->center_freq != wdev->chandef.chan->center_freq) {
6830 wdev_unlock(wdev);
6831 err = -EBUSY;
6832 goto out_free;
6833 }
6834 }
6835 wdev_unlock(wdev);
6836
Johannes Berg2a519312009-02-10 21:25:55 +01006837 i = 0;
Johannes Berg13874e42015-01-23 11:25:20 +01006838 if (n_ssids) {
Johannes Berg2a519312009-02-10 21:25:55 +01006839 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) {
Luciano Coelho57a27e12011-06-07 20:42:26 +03006840 if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) {
Johannes Berg2a519312009-02-10 21:25:55 +01006841 err = -EINVAL;
6842 goto out_free;
6843 }
Luciano Coelho57a27e12011-06-07 20:42:26 +03006844 request->ssids[i].ssid_len = nla_len(attr);
Johannes Berg2a519312009-02-10 21:25:55 +01006845 memcpy(request->ssids[i].ssid, nla_data(attr), nla_len(attr));
Johannes Berg2a519312009-02-10 21:25:55 +01006846 i++;
6847 }
6848 }
6849
Jouni Malinen70692ad2009-02-16 19:39:13 +02006850 if (info->attrs[NL80211_ATTR_IE]) {
6851 request->ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Johannes Bergde95a542009-04-01 11:58:36 +02006852 memcpy((void *)request->ie,
6853 nla_data(info->attrs[NL80211_ATTR_IE]),
Jouni Malinen70692ad2009-02-16 19:39:13 +02006854 request->ie_len);
6855 }
6856
Johannes Berg57fbcce2016-04-12 15:56:15 +02006857 for (i = 0; i < NUM_NL80211_BANDS; i++)
Johannes Berga401d2b2011-07-20 00:52:16 +02006858 if (wiphy->bands[i])
6859 request->rates[i] =
6860 (1 << wiphy->bands[i]->n_bitrates) - 1;
Johannes Berg34850ab2011-07-18 18:08:35 +02006861
6862 if (info->attrs[NL80211_ATTR_SCAN_SUPP_RATES]) {
6863 nla_for_each_nested(attr,
6864 info->attrs[NL80211_ATTR_SCAN_SUPP_RATES],
6865 tmp) {
Johannes Berg57fbcce2016-04-12 15:56:15 +02006866 enum nl80211_band band = nla_type(attr);
Johannes Berg34850ab2011-07-18 18:08:35 +02006867
Johannes Berg57fbcce2016-04-12 15:56:15 +02006868 if (band < 0 || band >= NUM_NL80211_BANDS) {
Johannes Berg34850ab2011-07-18 18:08:35 +02006869 err = -EINVAL;
6870 goto out_free;
6871 }
Felix Fietkau1b09cd82013-11-20 19:40:41 +01006872
6873 if (!wiphy->bands[band])
6874 continue;
6875
Johannes Berg34850ab2011-07-18 18:08:35 +02006876 err = ieee80211_get_ratemask(wiphy->bands[band],
6877 nla_data(attr),
6878 nla_len(attr),
6879 &request->rates[band]);
6880 if (err)
6881 goto out_free;
6882 }
6883 }
6884
Avraham Stern1d762502016-07-05 17:10:13 +03006885 if (info->attrs[NL80211_ATTR_MEASUREMENT_DURATION]) {
6886 if (!wiphy_ext_feature_isset(wiphy,
6887 NL80211_EXT_FEATURE_SET_SCAN_DWELL)) {
6888 err = -EOPNOTSUPP;
6889 goto out_free;
6890 }
6891
6892 request->duration =
6893 nla_get_u16(info->attrs[NL80211_ATTR_MEASUREMENT_DURATION]);
6894 request->duration_mandatory =
6895 nla_get_flag(info->attrs[NL80211_ATTR_MEASUREMENT_DURATION_MANDATORY]);
6896 }
6897
Roee Zamir2d23d072017-08-06 11:38:22 +03006898 err = nl80211_check_scan_flags(wiphy, wdev, request, info->attrs,
6899 false);
6900 if (err)
6901 goto out_free;
Sam Lefflered4737712012-10-11 21:03:31 -07006902
Rajkumar Manoharane9f935e2011-09-25 14:53:30 +05306903 request->no_cck =
6904 nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]);
6905
Vamsi Krishna2fa436b2016-12-02 23:59:08 +02006906 /* Initial implementation used NL80211_ATTR_MAC to set the specific
6907 * BSSID to scan for. This was problematic because that same attribute
6908 * was already used for another purpose (local random MAC address). The
6909 * NL80211_ATTR_BSSID attribute was added to fix this. For backwards
6910 * compatibility with older userspace components, also use the
6911 * NL80211_ATTR_MAC value here if it can be determined to be used for
6912 * the specific BSSID use case instead of the random MAC address
6913 * (NL80211_ATTR_SCAN_FLAGS is used to enable random MAC address use).
6914 */
6915 if (info->attrs[NL80211_ATTR_BSSID])
6916 memcpy(request->bssid,
6917 nla_data(info->attrs[NL80211_ATTR_BSSID]), ETH_ALEN);
6918 else if (!(request->flags & NL80211_SCAN_FLAG_RANDOM_ADDR) &&
6919 info->attrs[NL80211_ATTR_MAC])
Jouni Malinen818965d2016-02-26 22:12:47 +02006920 memcpy(request->bssid, nla_data(info->attrs[NL80211_ATTR_MAC]),
6921 ETH_ALEN);
6922 else
6923 eth_broadcast_addr(request->bssid);
6924
Johannes Bergfd014282012-06-18 19:17:03 +02006925 request->wdev = wdev;
Johannes Berg79c97e92009-07-07 03:56:12 +02006926 request->wiphy = &rdev->wiphy;
Sam Leffler15d60302012-10-11 21:03:34 -07006927 request->scan_start = jiffies;
Johannes Berg2a519312009-02-10 21:25:55 +01006928
Johannes Berg79c97e92009-07-07 03:56:12 +02006929 rdev->scan_req = request;
Hila Gonene35e4d22012-06-27 17:19:42 +03006930 err = rdev_scan(rdev, request);
Johannes Berg2a519312009-02-10 21:25:55 +01006931
Johannes Berg463d0182009-07-14 00:33:35 +02006932 if (!err) {
Johannes Bergfd014282012-06-18 19:17:03 +02006933 nl80211_send_scan_start(rdev, wdev);
6934 if (wdev->netdev)
6935 dev_hold(wdev->netdev);
Johannes Berg4c476992010-10-04 21:36:35 +02006936 } else {
Johannes Berg2a519312009-02-10 21:25:55 +01006937 out_free:
Johannes Berg79c97e92009-07-07 03:56:12 +02006938 rdev->scan_req = NULL;
Johannes Berg2a519312009-02-10 21:25:55 +01006939 kfree(request);
6940 }
Johannes Berg3b858752009-03-12 09:55:09 +01006941
Johannes Bergf9f47522013-03-19 15:04:07 +01006942 unlock:
Johannes Berg2a519312009-02-10 21:25:55 +01006943 return err;
6944}
6945
Vidyullatha Kanchanapally91d3ab42015-10-30 19:14:49 +05306946static int nl80211_abort_scan(struct sk_buff *skb, struct genl_info *info)
6947{
6948 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6949 struct wireless_dev *wdev = info->user_ptr[1];
6950
6951 if (!rdev->ops->abort_scan)
6952 return -EOPNOTSUPP;
6953
6954 if (rdev->scan_msg)
6955 return 0;
6956
6957 if (!rdev->scan_req)
6958 return -ENOENT;
6959
6960 rdev_abort_scan(rdev, wdev);
6961 return 0;
6962}
6963
Avraham Stern3b06d272015-10-12 09:51:34 +03006964static int
6965nl80211_parse_sched_scan_plans(struct wiphy *wiphy, int n_plans,
6966 struct cfg80211_sched_scan_request *request,
6967 struct nlattr **attrs)
6968{
6969 int tmp, err, i = 0;
6970 struct nlattr *attr;
6971
6972 if (!attrs[NL80211_ATTR_SCHED_SCAN_PLANS]) {
6973 u32 interval;
6974
6975 /*
6976 * If scan plans are not specified,
Arend Van Spriel5a88de52016-11-17 09:02:40 +00006977 * %NL80211_ATTR_SCHED_SCAN_INTERVAL will be specified. In this
Avraham Stern3b06d272015-10-12 09:51:34 +03006978 * case one scan plan will be set with the specified scan
6979 * interval and infinite number of iterations.
6980 */
Avraham Stern3b06d272015-10-12 09:51:34 +03006981 interval = nla_get_u32(attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]);
6982 if (!interval)
6983 return -EINVAL;
6984
6985 request->scan_plans[0].interval =
6986 DIV_ROUND_UP(interval, MSEC_PER_SEC);
6987 if (!request->scan_plans[0].interval)
6988 return -EINVAL;
6989
6990 if (request->scan_plans[0].interval >
6991 wiphy->max_sched_scan_plan_interval)
6992 request->scan_plans[0].interval =
6993 wiphy->max_sched_scan_plan_interval;
6994
6995 return 0;
6996 }
6997
6998 nla_for_each_nested(attr, attrs[NL80211_ATTR_SCHED_SCAN_PLANS], tmp) {
6999 struct nlattr *plan[NL80211_SCHED_SCAN_PLAN_MAX + 1];
7000
7001 if (WARN_ON(i >= n_plans))
7002 return -EINVAL;
7003
Johannes Bergbfe2c7b2016-10-26 14:42:21 +02007004 err = nla_parse_nested(plan, NL80211_SCHED_SCAN_PLAN_MAX,
Johannes Bergfceb6432017-04-12 14:34:07 +02007005 attr, nl80211_plan_policy, NULL);
Avraham Stern3b06d272015-10-12 09:51:34 +03007006 if (err)
7007 return err;
7008
7009 if (!plan[NL80211_SCHED_SCAN_PLAN_INTERVAL])
7010 return -EINVAL;
7011
7012 request->scan_plans[i].interval =
7013 nla_get_u32(plan[NL80211_SCHED_SCAN_PLAN_INTERVAL]);
7014 if (!request->scan_plans[i].interval ||
7015 request->scan_plans[i].interval >
7016 wiphy->max_sched_scan_plan_interval)
7017 return -EINVAL;
7018
7019 if (plan[NL80211_SCHED_SCAN_PLAN_ITERATIONS]) {
7020 request->scan_plans[i].iterations =
7021 nla_get_u32(plan[NL80211_SCHED_SCAN_PLAN_ITERATIONS]);
7022 if (!request->scan_plans[i].iterations ||
7023 (request->scan_plans[i].iterations >
7024 wiphy->max_sched_scan_plan_iterations))
7025 return -EINVAL;
7026 } else if (i < n_plans - 1) {
7027 /*
7028 * All scan plans but the last one must specify
7029 * a finite number of iterations
7030 */
7031 return -EINVAL;
7032 }
7033
7034 i++;
7035 }
7036
7037 /*
7038 * The last scan plan must not specify the number of
7039 * iterations, it is supposed to run infinitely
7040 */
7041 if (request->scan_plans[n_plans - 1].iterations)
7042 return -EINVAL;
7043
7044 return 0;
7045}
7046
Luciano Coelho256da022014-11-10 16:13:46 +02007047static struct cfg80211_sched_scan_request *
Johannes Bergad2b26a2014-06-12 21:39:05 +02007048nl80211_parse_sched_scan(struct wiphy *wiphy, struct wireless_dev *wdev,
Arend Van Sprielaad1e812017-01-27 12:27:44 +00007049 struct nlattr **attrs, int max_match_sets)
Luciano Coelho807f8a82011-05-11 17:09:35 +03007050{
7051 struct cfg80211_sched_scan_request *request;
Luciano Coelho807f8a82011-05-11 17:09:35 +03007052 struct nlattr *attr;
Avraham Stern3b06d272015-10-12 09:51:34 +03007053 int err, tmp, n_ssids = 0, n_match_sets = 0, n_channels, i, n_plans = 0;
Johannes Berg57fbcce2016-04-12 15:56:15 +02007054 enum nl80211_band band;
Luciano Coelho807f8a82011-05-11 17:09:35 +03007055 size_t ie_len;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03007056 struct nlattr *tb[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1];
Johannes Bergea73cbc2014-01-24 10:53:53 +01007057 s32 default_match_rssi = NL80211_SCAN_RSSI_THOLD_OFF;
Luciano Coelho807f8a82011-05-11 17:09:35 +03007058
Luciano Coelho256da022014-11-10 16:13:46 +02007059 if (!is_valid_ie_attr(attrs[NL80211_ATTR_IE]))
7060 return ERR_PTR(-EINVAL);
Luciano Coelho807f8a82011-05-11 17:09:35 +03007061
Luciano Coelho256da022014-11-10 16:13:46 +02007062 if (attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
Luciano Coelho807f8a82011-05-11 17:09:35 +03007063 n_channels = validate_scan_freqs(
Luciano Coelho256da022014-11-10 16:13:46 +02007064 attrs[NL80211_ATTR_SCAN_FREQUENCIES]);
Luciano Coelho807f8a82011-05-11 17:09:35 +03007065 if (!n_channels)
Luciano Coelho256da022014-11-10 16:13:46 +02007066 return ERR_PTR(-EINVAL);
Luciano Coelho807f8a82011-05-11 17:09:35 +03007067 } else {
Ilan Peerbdfbec22014-01-09 11:37:23 +02007068 n_channels = ieee80211_get_num_supported_channels(wiphy);
Luciano Coelho807f8a82011-05-11 17:09:35 +03007069 }
7070
Luciano Coelho256da022014-11-10 16:13:46 +02007071 if (attrs[NL80211_ATTR_SCAN_SSIDS])
7072 nla_for_each_nested(attr, attrs[NL80211_ATTR_SCAN_SSIDS],
Luciano Coelho807f8a82011-05-11 17:09:35 +03007073 tmp)
7074 n_ssids++;
7075
Luciano Coelho93b6aa62011-07-13 14:57:28 +03007076 if (n_ssids > wiphy->max_sched_scan_ssids)
Luciano Coelho256da022014-11-10 16:13:46 +02007077 return ERR_PTR(-EINVAL);
Luciano Coelho807f8a82011-05-11 17:09:35 +03007078
Johannes Bergea73cbc2014-01-24 10:53:53 +01007079 /*
7080 * First, count the number of 'real' matchsets. Due to an issue with
7081 * the old implementation, matchsets containing only the RSSI attribute
7082 * (NL80211_SCHED_SCAN_MATCH_ATTR_RSSI) are considered as the 'default'
7083 * RSSI for all matchsets, rather than their own matchset for reporting
7084 * all APs with a strong RSSI. This is needed to be compatible with
7085 * older userspace that treated a matchset with only the RSSI as the
7086 * global RSSI for all other matchsets - if there are other matchsets.
7087 */
Luciano Coelho256da022014-11-10 16:13:46 +02007088 if (attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) {
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03007089 nla_for_each_nested(attr,
Luciano Coelho256da022014-11-10 16:13:46 +02007090 attrs[NL80211_ATTR_SCHED_SCAN_MATCH],
Johannes Bergea73cbc2014-01-24 10:53:53 +01007091 tmp) {
7092 struct nlattr *rssi;
7093
Johannes Bergbfe2c7b2016-10-26 14:42:21 +02007094 err = nla_parse_nested(tb,
7095 NL80211_SCHED_SCAN_MATCH_ATTR_MAX,
Johannes Bergfceb6432017-04-12 14:34:07 +02007096 attr, nl80211_match_policy,
7097 NULL);
Johannes Bergea73cbc2014-01-24 10:53:53 +01007098 if (err)
Luciano Coelho256da022014-11-10 16:13:46 +02007099 return ERR_PTR(err);
Arend Van Spriel3007e352017-04-21 13:05:01 +01007100
7101 /* SSID and BSSID are mutually exclusive */
7102 if (tb[NL80211_SCHED_SCAN_MATCH_ATTR_SSID] &&
7103 tb[NL80211_SCHED_SCAN_MATCH_ATTR_BSSID])
7104 return ERR_PTR(-EINVAL);
7105
Johannes Bergea73cbc2014-01-24 10:53:53 +01007106 /* add other standalone attributes here */
Arend Van Spriel3007e352017-04-21 13:05:01 +01007107 if (tb[NL80211_SCHED_SCAN_MATCH_ATTR_SSID] ||
7108 tb[NL80211_SCHED_SCAN_MATCH_ATTR_BSSID]) {
Johannes Bergea73cbc2014-01-24 10:53:53 +01007109 n_match_sets++;
7110 continue;
7111 }
7112 rssi = tb[NL80211_SCHED_SCAN_MATCH_ATTR_RSSI];
7113 if (rssi)
7114 default_match_rssi = nla_get_s32(rssi);
7115 }
7116 }
7117
7118 /* However, if there's no other matchset, add the RSSI one */
7119 if (!n_match_sets && default_match_rssi != NL80211_SCAN_RSSI_THOLD_OFF)
7120 n_match_sets = 1;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03007121
Arend Van Sprielaad1e812017-01-27 12:27:44 +00007122 if (n_match_sets > max_match_sets)
Luciano Coelho256da022014-11-10 16:13:46 +02007123 return ERR_PTR(-EINVAL);
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03007124
Luciano Coelho256da022014-11-10 16:13:46 +02007125 if (attrs[NL80211_ATTR_IE])
7126 ie_len = nla_len(attrs[NL80211_ATTR_IE]);
Luciano Coelho807f8a82011-05-11 17:09:35 +03007127 else
7128 ie_len = 0;
7129
Luciano Coelho5a865ba2011-07-13 14:57:29 +03007130 if (ie_len > wiphy->max_sched_scan_ie_len)
Luciano Coelho256da022014-11-10 16:13:46 +02007131 return ERR_PTR(-EINVAL);
Luciano Coelhoc10841c2011-06-30 08:32:41 +03007132
Avraham Stern3b06d272015-10-12 09:51:34 +03007133 if (attrs[NL80211_ATTR_SCHED_SCAN_PLANS]) {
7134 /*
7135 * NL80211_ATTR_SCHED_SCAN_INTERVAL must not be specified since
7136 * each scan plan already specifies its own interval
7137 */
7138 if (attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL])
7139 return ERR_PTR(-EINVAL);
7140
7141 nla_for_each_nested(attr,
7142 attrs[NL80211_ATTR_SCHED_SCAN_PLANS], tmp)
7143 n_plans++;
7144 } else {
7145 /*
7146 * The scan interval attribute is kept for backward
7147 * compatibility. If no scan plans are specified and sched scan
7148 * interval is specified, one scan plan will be set with this
7149 * scan interval and infinite number of iterations.
7150 */
7151 if (!attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL])
7152 return ERR_PTR(-EINVAL);
7153
7154 n_plans = 1;
7155 }
7156
7157 if (!n_plans || n_plans > wiphy->max_sched_scan_plans)
7158 return ERR_PTR(-EINVAL);
7159
vamsi krishnabf95ecd2017-01-13 01:12:20 +02007160 if (!wiphy_ext_feature_isset(
7161 wiphy, NL80211_EXT_FEATURE_SCHED_SCAN_RELATIVE_RSSI) &&
7162 (attrs[NL80211_ATTR_SCHED_SCAN_RELATIVE_RSSI] ||
7163 attrs[NL80211_ATTR_SCHED_SCAN_RSSI_ADJUST]))
7164 return ERR_PTR(-EINVAL);
7165
Luciano Coelho807f8a82011-05-11 17:09:35 +03007166 request = kzalloc(sizeof(*request)
Luciano Coelhoa2cd43c2011-05-18 11:42:03 +03007167 + sizeof(*request->ssids) * n_ssids
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03007168 + sizeof(*request->match_sets) * n_match_sets
Avraham Stern3b06d272015-10-12 09:51:34 +03007169 + sizeof(*request->scan_plans) * n_plans
Luciano Coelhoa2cd43c2011-05-18 11:42:03 +03007170 + sizeof(*request->channels) * n_channels
Luciano Coelho807f8a82011-05-11 17:09:35 +03007171 + ie_len, GFP_KERNEL);
Luciano Coelho256da022014-11-10 16:13:46 +02007172 if (!request)
7173 return ERR_PTR(-ENOMEM);
Luciano Coelho807f8a82011-05-11 17:09:35 +03007174
7175 if (n_ssids)
7176 request->ssids = (void *)&request->channels[n_channels];
7177 request->n_ssids = n_ssids;
7178 if (ie_len) {
Johannes Berg13874e42015-01-23 11:25:20 +01007179 if (n_ssids)
Luciano Coelho807f8a82011-05-11 17:09:35 +03007180 request->ie = (void *)(request->ssids + n_ssids);
7181 else
7182 request->ie = (void *)(request->channels + n_channels);
7183 }
7184
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03007185 if (n_match_sets) {
7186 if (request->ie)
7187 request->match_sets = (void *)(request->ie + ie_len);
Johannes Berg13874e42015-01-23 11:25:20 +01007188 else if (n_ssids)
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03007189 request->match_sets =
7190 (void *)(request->ssids + n_ssids);
7191 else
7192 request->match_sets =
7193 (void *)(request->channels + n_channels);
7194 }
7195 request->n_match_sets = n_match_sets;
7196
Avraham Stern3b06d272015-10-12 09:51:34 +03007197 if (n_match_sets)
7198 request->scan_plans = (void *)(request->match_sets +
7199 n_match_sets);
7200 else if (request->ie)
7201 request->scan_plans = (void *)(request->ie + ie_len);
7202 else if (n_ssids)
7203 request->scan_plans = (void *)(request->ssids + n_ssids);
7204 else
7205 request->scan_plans = (void *)(request->channels + n_channels);
7206
7207 request->n_scan_plans = n_plans;
7208
Luciano Coelho807f8a82011-05-11 17:09:35 +03007209 i = 0;
Luciano Coelho256da022014-11-10 16:13:46 +02007210 if (attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
Luciano Coelho807f8a82011-05-11 17:09:35 +03007211 /* user specified, bail out if channel not found */
7212 nla_for_each_nested(attr,
Luciano Coelho256da022014-11-10 16:13:46 +02007213 attrs[NL80211_ATTR_SCAN_FREQUENCIES],
Luciano Coelho807f8a82011-05-11 17:09:35 +03007214 tmp) {
7215 struct ieee80211_channel *chan;
7216
7217 chan = ieee80211_get_channel(wiphy, nla_get_u32(attr));
7218
7219 if (!chan) {
7220 err = -EINVAL;
7221 goto out_free;
7222 }
7223
7224 /* ignore disabled channels */
7225 if (chan->flags & IEEE80211_CHAN_DISABLED)
7226 continue;
7227
7228 request->channels[i] = chan;
7229 i++;
7230 }
7231 } else {
7232 /* all channels */
Johannes Berg57fbcce2016-04-12 15:56:15 +02007233 for (band = 0; band < NUM_NL80211_BANDS; band++) {
Luciano Coelho807f8a82011-05-11 17:09:35 +03007234 int j;
Kirtika Ruchandani7a087e72016-05-29 19:51:23 -07007235
Luciano Coelho807f8a82011-05-11 17:09:35 +03007236 if (!wiphy->bands[band])
7237 continue;
7238 for (j = 0; j < wiphy->bands[band]->n_channels; j++) {
7239 struct ieee80211_channel *chan;
7240
7241 chan = &wiphy->bands[band]->channels[j];
7242
7243 if (chan->flags & IEEE80211_CHAN_DISABLED)
7244 continue;
7245
7246 request->channels[i] = chan;
7247 i++;
7248 }
7249 }
7250 }
7251
7252 if (!i) {
7253 err = -EINVAL;
7254 goto out_free;
7255 }
7256
7257 request->n_channels = i;
7258
7259 i = 0;
Johannes Berg13874e42015-01-23 11:25:20 +01007260 if (n_ssids) {
Luciano Coelho256da022014-11-10 16:13:46 +02007261 nla_for_each_nested(attr, attrs[NL80211_ATTR_SCAN_SSIDS],
Luciano Coelho807f8a82011-05-11 17:09:35 +03007262 tmp) {
Luciano Coelho57a27e12011-06-07 20:42:26 +03007263 if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) {
Luciano Coelho807f8a82011-05-11 17:09:35 +03007264 err = -EINVAL;
7265 goto out_free;
7266 }
Luciano Coelho57a27e12011-06-07 20:42:26 +03007267 request->ssids[i].ssid_len = nla_len(attr);
Luciano Coelho807f8a82011-05-11 17:09:35 +03007268 memcpy(request->ssids[i].ssid, nla_data(attr),
7269 nla_len(attr));
Luciano Coelho807f8a82011-05-11 17:09:35 +03007270 i++;
7271 }
7272 }
7273
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03007274 i = 0;
Luciano Coelho256da022014-11-10 16:13:46 +02007275 if (attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) {
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03007276 nla_for_each_nested(attr,
Luciano Coelho256da022014-11-10 16:13:46 +02007277 attrs[NL80211_ATTR_SCHED_SCAN_MATCH],
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03007278 tmp) {
Arend Van Spriel3007e352017-04-21 13:05:01 +01007279 struct nlattr *ssid, *bssid, *rssi;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03007280
Johannes Bergbfe2c7b2016-10-26 14:42:21 +02007281 err = nla_parse_nested(tb,
7282 NL80211_SCHED_SCAN_MATCH_ATTR_MAX,
Johannes Bergfceb6432017-04-12 14:34:07 +02007283 attr, nl80211_match_policy,
7284 NULL);
Johannes Bergae811e22014-01-24 10:17:47 +01007285 if (err)
7286 goto out_free;
Johannes Berg4a4ab0d2012-06-13 11:17:11 +02007287 ssid = tb[NL80211_SCHED_SCAN_MATCH_ATTR_SSID];
Arend Van Spriel3007e352017-04-21 13:05:01 +01007288 bssid = tb[NL80211_SCHED_SCAN_MATCH_ATTR_BSSID];
7289 if (ssid || bssid) {
Johannes Bergea73cbc2014-01-24 10:53:53 +01007290 if (WARN_ON(i >= n_match_sets)) {
7291 /* this indicates a programming error,
7292 * the loop above should have verified
7293 * things properly
7294 */
7295 err = -EINVAL;
7296 goto out_free;
7297 }
7298
Arend Van Spriel3007e352017-04-21 13:05:01 +01007299 if (ssid) {
7300 if (nla_len(ssid) > IEEE80211_MAX_SSID_LEN) {
7301 err = -EINVAL;
7302 goto out_free;
7303 }
7304 memcpy(request->match_sets[i].ssid.ssid,
7305 nla_data(ssid), nla_len(ssid));
7306 request->match_sets[i].ssid.ssid_len =
7307 nla_len(ssid);
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03007308 }
Arend Van Spriel3007e352017-04-21 13:05:01 +01007309 if (bssid) {
7310 if (nla_len(bssid) != ETH_ALEN) {
7311 err = -EINVAL;
7312 goto out_free;
7313 }
7314 memcpy(request->match_sets[i].bssid,
7315 nla_data(bssid), ETH_ALEN);
7316 }
7317
Kirtika Ruchandani56ab3642016-05-29 19:54:10 -07007318 /* special attribute - old implementation w/a */
Johannes Bergea73cbc2014-01-24 10:53:53 +01007319 request->match_sets[i].rssi_thold =
7320 default_match_rssi;
7321 rssi = tb[NL80211_SCHED_SCAN_MATCH_ATTR_RSSI];
7322 if (rssi)
7323 request->match_sets[i].rssi_thold =
7324 nla_get_s32(rssi);
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03007325 }
7326 i++;
7327 }
Johannes Bergea73cbc2014-01-24 10:53:53 +01007328
7329 /* there was no other matchset, so the RSSI one is alone */
Luciano Coelhof89f46c2014-12-01 11:32:09 +02007330 if (i == 0 && n_match_sets)
Johannes Bergea73cbc2014-01-24 10:53:53 +01007331 request->match_sets[0].rssi_thold = default_match_rssi;
7332
7333 request->min_rssi_thold = INT_MAX;
7334 for (i = 0; i < n_match_sets; i++)
7335 request->min_rssi_thold =
7336 min(request->match_sets[i].rssi_thold,
7337 request->min_rssi_thold);
7338 } else {
7339 request->min_rssi_thold = NL80211_SCAN_RSSI_THOLD_OFF;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03007340 }
7341
Johannes Berg9900e482014-02-04 21:01:25 +01007342 if (ie_len) {
7343 request->ie_len = ie_len;
Luciano Coelho807f8a82011-05-11 17:09:35 +03007344 memcpy((void *)request->ie,
Luciano Coelho256da022014-11-10 16:13:46 +02007345 nla_data(attrs[NL80211_ATTR_IE]),
Luciano Coelho807f8a82011-05-11 17:09:35 +03007346 request->ie_len);
7347 }
7348
Roee Zamir2d23d072017-08-06 11:38:22 +03007349 err = nl80211_check_scan_flags(wiphy, wdev, request, attrs, true);
7350 if (err)
7351 goto out_free;
Sam Lefflered4737712012-10-11 21:03:31 -07007352
Luciano Coelho9c748932015-01-16 16:04:09 +02007353 if (attrs[NL80211_ATTR_SCHED_SCAN_DELAY])
7354 request->delay =
7355 nla_get_u32(attrs[NL80211_ATTR_SCHED_SCAN_DELAY]);
7356
vamsi krishnabf95ecd2017-01-13 01:12:20 +02007357 if (attrs[NL80211_ATTR_SCHED_SCAN_RELATIVE_RSSI]) {
7358 request->relative_rssi = nla_get_s8(
7359 attrs[NL80211_ATTR_SCHED_SCAN_RELATIVE_RSSI]);
7360 request->relative_rssi_set = true;
7361 }
7362
7363 if (request->relative_rssi_set &&
7364 attrs[NL80211_ATTR_SCHED_SCAN_RSSI_ADJUST]) {
7365 struct nl80211_bss_select_rssi_adjust *rssi_adjust;
7366
7367 rssi_adjust = nla_data(
7368 attrs[NL80211_ATTR_SCHED_SCAN_RSSI_ADJUST]);
7369 request->rssi_adjust.band = rssi_adjust->band;
7370 request->rssi_adjust.delta = rssi_adjust->delta;
7371 if (!is_band_valid(wiphy, request->rssi_adjust.band)) {
7372 err = -EINVAL;
7373 goto out_free;
7374 }
7375 }
7376
Avraham Stern3b06d272015-10-12 09:51:34 +03007377 err = nl80211_parse_sched_scan_plans(wiphy, n_plans, request, attrs);
7378 if (err)
7379 goto out_free;
7380
Sam Leffler15d60302012-10-11 21:03:34 -07007381 request->scan_start = jiffies;
Luciano Coelho807f8a82011-05-11 17:09:35 +03007382
Luciano Coelho256da022014-11-10 16:13:46 +02007383 return request;
Luciano Coelho807f8a82011-05-11 17:09:35 +03007384
7385out_free:
7386 kfree(request);
Luciano Coelho256da022014-11-10 16:13:46 +02007387 return ERR_PTR(err);
7388}
7389
7390static int nl80211_start_sched_scan(struct sk_buff *skb,
7391 struct genl_info *info)
7392{
7393 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7394 struct net_device *dev = info->user_ptr[1];
Johannes Bergad2b26a2014-06-12 21:39:05 +02007395 struct wireless_dev *wdev = dev->ieee80211_ptr;
Jukka Rissanen31a60ed2014-12-15 13:25:38 +02007396 struct cfg80211_sched_scan_request *sched_scan_req;
Arend Van Sprielca986ad2017-04-21 13:05:00 +01007397 bool want_multi;
Luciano Coelho256da022014-11-10 16:13:46 +02007398 int err;
7399
Arend Van Sprielca986ad2017-04-21 13:05:00 +01007400 if (!rdev->wiphy.max_sched_scan_reqs || !rdev->ops->sched_scan_start)
Luciano Coelho256da022014-11-10 16:13:46 +02007401 return -EOPNOTSUPP;
7402
Arend Van Sprielca986ad2017-04-21 13:05:00 +01007403 want_multi = info->attrs[NL80211_ATTR_SCHED_SCAN_MULTI];
7404 err = cfg80211_sched_scan_req_possible(rdev, want_multi);
7405 if (err)
7406 return err;
Luciano Coelho256da022014-11-10 16:13:46 +02007407
Jukka Rissanen31a60ed2014-12-15 13:25:38 +02007408 sched_scan_req = nl80211_parse_sched_scan(&rdev->wiphy, wdev,
Arend Van Sprielaad1e812017-01-27 12:27:44 +00007409 info->attrs,
7410 rdev->wiphy.max_match_sets);
Jukka Rissanen31a60ed2014-12-15 13:25:38 +02007411
7412 err = PTR_ERR_OR_ZERO(sched_scan_req);
Luciano Coelho256da022014-11-10 16:13:46 +02007413 if (err)
7414 goto out_err;
7415
Arend Van Sprielca986ad2017-04-21 13:05:00 +01007416 /* leave request id zero for legacy request
7417 * or if driver does not support multi-scheduled scan
7418 */
7419 if (want_multi && rdev->wiphy.max_sched_scan_reqs > 1) {
7420 while (!sched_scan_req->reqid)
7421 sched_scan_req->reqid = rdev->wiphy.cookie_counter++;
7422 }
7423
Jukka Rissanen31a60ed2014-12-15 13:25:38 +02007424 err = rdev_sched_scan_start(rdev, dev, sched_scan_req);
Luciano Coelho256da022014-11-10 16:13:46 +02007425 if (err)
7426 goto out_free;
7427
Jukka Rissanen31a60ed2014-12-15 13:25:38 +02007428 sched_scan_req->dev = dev;
7429 sched_scan_req->wiphy = &rdev->wiphy;
7430
Jukka Rissanen93a1e862014-12-15 13:25:39 +02007431 if (info->attrs[NL80211_ATTR_SOCKET_OWNER])
7432 sched_scan_req->owner_nlportid = info->snd_portid;
7433
Arend Van Sprielca986ad2017-04-21 13:05:00 +01007434 cfg80211_add_sched_scan_req(rdev, sched_scan_req);
Luciano Coelho256da022014-11-10 16:13:46 +02007435
Arend Van Spriel96b08fd2017-04-13 13:06:27 +01007436 nl80211_send_sched_scan(sched_scan_req, NL80211_CMD_START_SCHED_SCAN);
Luciano Coelho256da022014-11-10 16:13:46 +02007437 return 0;
7438
7439out_free:
Jukka Rissanen31a60ed2014-12-15 13:25:38 +02007440 kfree(sched_scan_req);
Luciano Coelho256da022014-11-10 16:13:46 +02007441out_err:
Luciano Coelho807f8a82011-05-11 17:09:35 +03007442 return err;
7443}
7444
7445static int nl80211_stop_sched_scan(struct sk_buff *skb,
7446 struct genl_info *info)
7447{
Arend Van Sprielca986ad2017-04-21 13:05:00 +01007448 struct cfg80211_sched_scan_request *req;
Luciano Coelho807f8a82011-05-11 17:09:35 +03007449 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Arend Van Sprielca986ad2017-04-21 13:05:00 +01007450 u64 cookie;
Luciano Coelho807f8a82011-05-11 17:09:35 +03007451
Arend Van Sprielca986ad2017-04-21 13:05:00 +01007452 if (!rdev->wiphy.max_sched_scan_reqs || !rdev->ops->sched_scan_stop)
Luciano Coelho807f8a82011-05-11 17:09:35 +03007453 return -EOPNOTSUPP;
7454
Arend Van Sprielca986ad2017-04-21 13:05:00 +01007455 if (info->attrs[NL80211_ATTR_COOKIE]) {
7456 cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]);
7457 return __cfg80211_stop_sched_scan(rdev, cookie, false);
7458 }
7459
7460 req = list_first_or_null_rcu(&rdev->sched_scan_req_list,
7461 struct cfg80211_sched_scan_request,
7462 list);
7463 if (!req || req->reqid ||
7464 (req->owner_nlportid &&
7465 req->owner_nlportid != info->snd_portid))
7466 return -ENOENT;
7467
7468 return cfg80211_stop_sched_scan_req(rdev, req, false);
Luciano Coelho807f8a82011-05-11 17:09:35 +03007469}
7470
Simon Wunderlich04f39042013-02-08 18:16:19 +01007471static int nl80211_start_radar_detection(struct sk_buff *skb,
7472 struct genl_info *info)
7473{
7474 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7475 struct net_device *dev = info->user_ptr[1];
7476 struct wireless_dev *wdev = dev->ieee80211_ptr;
7477 struct cfg80211_chan_def chandef;
Luis R. Rodriguez55f74352013-11-25 20:56:10 +01007478 enum nl80211_dfs_regions dfs_region;
Janusz Dziedzic31559f32014-02-21 19:46:13 +01007479 unsigned int cac_time_ms;
Simon Wunderlich04f39042013-02-08 18:16:19 +01007480 int err;
7481
Luis R. Rodriguez55f74352013-11-25 20:56:10 +01007482 dfs_region = reg_get_dfs_region(wdev->wiphy);
7483 if (dfs_region == NL80211_DFS_UNSET)
7484 return -EINVAL;
7485
Simon Wunderlich04f39042013-02-08 18:16:19 +01007486 err = nl80211_parse_chandef(rdev, info, &chandef);
7487 if (err)
7488 return err;
7489
Simon Wunderlichff311bc2013-09-03 19:43:18 +02007490 if (netif_carrier_ok(dev))
7491 return -EBUSY;
7492
Simon Wunderlich04f39042013-02-08 18:16:19 +01007493 if (wdev->cac_started)
7494 return -EBUSY;
7495
Luciano Coelho2beb6dab2014-02-18 11:40:36 +02007496 err = cfg80211_chandef_dfs_required(wdev->wiphy, &chandef,
Luciano Coelho00ec75f2014-05-15 13:05:39 +03007497 wdev->iftype);
Simon Wunderlich04f39042013-02-08 18:16:19 +01007498 if (err < 0)
7499 return err;
7500
7501 if (err == 0)
7502 return -EINVAL;
7503
Janusz Dziedzicfe7c3a12013-11-05 14:48:48 +01007504 if (!cfg80211_chandef_dfs_usable(wdev->wiphy, &chandef))
Simon Wunderlich04f39042013-02-08 18:16:19 +01007505 return -EINVAL;
7506
7507 if (!rdev->ops->start_radar_detection)
7508 return -EOPNOTSUPP;
7509
Janusz Dziedzic31559f32014-02-21 19:46:13 +01007510 cac_time_ms = cfg80211_chandef_dfs_cac_time(&rdev->wiphy, &chandef);
7511 if (WARN_ON(!cac_time_ms))
7512 cac_time_ms = IEEE80211_DFS_MIN_CAC_TIME_MS;
7513
Ilan Peera1056b12015-10-22 22:27:46 +03007514 err = rdev_start_radar_detection(rdev, dev, &chandef, cac_time_ms);
Simon Wunderlich04f39042013-02-08 18:16:19 +01007515 if (!err) {
Michal Kazior9e0e2962014-01-29 14:22:27 +01007516 wdev->chandef = chandef;
Simon Wunderlich04f39042013-02-08 18:16:19 +01007517 wdev->cac_started = true;
7518 wdev->cac_start_time = jiffies;
Janusz Dziedzic31559f32014-02-21 19:46:13 +01007519 wdev->cac_time_ms = cac_time_ms;
Simon Wunderlich04f39042013-02-08 18:16:19 +01007520 }
Simon Wunderlich04f39042013-02-08 18:16:19 +01007521 return err;
7522}
7523
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02007524static int nl80211_channel_switch(struct sk_buff *skb, struct genl_info *info)
7525{
7526 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7527 struct net_device *dev = info->user_ptr[1];
7528 struct wireless_dev *wdev = dev->ieee80211_ptr;
7529 struct cfg80211_csa_settings params;
7530 /* csa_attrs is defined static to avoid waste of stack size - this
7531 * function is called under RTNL lock, so this should not be a problem.
7532 */
7533 static struct nlattr *csa_attrs[NL80211_ATTR_MAX+1];
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02007534 int err;
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02007535 bool need_new_beacon = false;
Benjamin Berg8d9de162017-05-16 11:23:12 +02007536 bool need_handle_dfs_flag = true;
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03007537 int len, i;
Luciano Coelho252e07c2014-10-08 09:48:34 +03007538 u32 cs_count;
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02007539
7540 if (!rdev->ops->channel_switch ||
7541 !(rdev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH))
7542 return -EOPNOTSUPP;
7543
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02007544 switch (dev->ieee80211_ptr->iftype) {
7545 case NL80211_IFTYPE_AP:
7546 case NL80211_IFTYPE_P2P_GO:
7547 need_new_beacon = true;
Benjamin Berg8d9de162017-05-16 11:23:12 +02007548 /* For all modes except AP the handle_dfs flag needs to be
7549 * supplied to tell the kernel that userspace will handle radar
7550 * events when they happen. Otherwise a switch to a channel
7551 * requiring DFS will be rejected.
7552 */
7553 need_handle_dfs_flag = false;
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02007554
7555 /* useless if AP is not running */
7556 if (!wdev->beacon_interval)
Johannes Berg1ff79df2014-01-22 10:05:27 +01007557 return -ENOTCONN;
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02007558 break;
7559 case NL80211_IFTYPE_ADHOC:
Johannes Berg1ff79df2014-01-22 10:05:27 +01007560 if (!wdev->ssid_len)
7561 return -ENOTCONN;
7562 break;
Chun-Yeow Yeohc6da6742013-10-14 19:08:28 -07007563 case NL80211_IFTYPE_MESH_POINT:
Johannes Berg1ff79df2014-01-22 10:05:27 +01007564 if (!wdev->mesh_id_len)
7565 return -ENOTCONN;
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02007566 break;
7567 default:
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02007568 return -EOPNOTSUPP;
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02007569 }
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02007570
7571 memset(&params, 0, sizeof(params));
7572
7573 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] ||
7574 !info->attrs[NL80211_ATTR_CH_SWITCH_COUNT])
7575 return -EINVAL;
7576
7577 /* only important for AP, IBSS and mesh create IEs internally */
Andrei Otcheretianskid0a361a2013-10-17 10:52:17 +02007578 if (need_new_beacon && !info->attrs[NL80211_ATTR_CSA_IES])
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02007579 return -EINVAL;
7580
Luciano Coelho252e07c2014-10-08 09:48:34 +03007581 /* Even though the attribute is u32, the specification says
7582 * u8, so let's make sure we don't overflow.
7583 */
7584 cs_count = nla_get_u32(info->attrs[NL80211_ATTR_CH_SWITCH_COUNT]);
7585 if (cs_count > 255)
7586 return -EINVAL;
7587
7588 params.count = cs_count;
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02007589
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02007590 if (!need_new_beacon)
7591 goto skip_beacons;
7592
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02007593 err = nl80211_parse_beacon(info->attrs, &params.beacon_after);
7594 if (err)
7595 return err;
7596
7597 err = nla_parse_nested(csa_attrs, NL80211_ATTR_MAX,
7598 info->attrs[NL80211_ATTR_CSA_IES],
Johannes Bergfe521452017-04-12 14:34:08 +02007599 nl80211_policy, info->extack);
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02007600 if (err)
7601 return err;
7602
7603 err = nl80211_parse_beacon(csa_attrs, &params.beacon_csa);
7604 if (err)
7605 return err;
7606
7607 if (!csa_attrs[NL80211_ATTR_CSA_C_OFF_BEACON])
7608 return -EINVAL;
7609
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03007610 len = nla_len(csa_attrs[NL80211_ATTR_CSA_C_OFF_BEACON]);
7611 if (!len || (len % sizeof(u16)))
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02007612 return -EINVAL;
7613
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03007614 params.n_counter_offsets_beacon = len / sizeof(u16);
7615 if (rdev->wiphy.max_num_csa_counters &&
7616 (params.n_counter_offsets_beacon >
7617 rdev->wiphy.max_num_csa_counters))
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02007618 return -EINVAL;
7619
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03007620 params.counter_offsets_beacon =
7621 nla_data(csa_attrs[NL80211_ATTR_CSA_C_OFF_BEACON]);
7622
7623 /* sanity checks - counters should fit and be the same */
7624 for (i = 0; i < params.n_counter_offsets_beacon; i++) {
7625 u16 offset = params.counter_offsets_beacon[i];
7626
7627 if (offset >= params.beacon_csa.tail_len)
7628 return -EINVAL;
7629
7630 if (params.beacon_csa.tail[offset] != params.count)
7631 return -EINVAL;
7632 }
7633
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02007634 if (csa_attrs[NL80211_ATTR_CSA_C_OFF_PRESP]) {
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03007635 len = nla_len(csa_attrs[NL80211_ATTR_CSA_C_OFF_PRESP]);
7636 if (!len || (len % sizeof(u16)))
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02007637 return -EINVAL;
7638
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03007639 params.n_counter_offsets_presp = len / sizeof(u16);
7640 if (rdev->wiphy.max_num_csa_counters &&
Johannes Bergad5987b2016-09-13 15:53:55 +02007641 (params.n_counter_offsets_presp >
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03007642 rdev->wiphy.max_num_csa_counters))
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02007643 return -EINVAL;
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03007644
7645 params.counter_offsets_presp =
7646 nla_data(csa_attrs[NL80211_ATTR_CSA_C_OFF_PRESP]);
7647
7648 /* sanity checks - counters should fit and be the same */
7649 for (i = 0; i < params.n_counter_offsets_presp; i++) {
7650 u16 offset = params.counter_offsets_presp[i];
7651
7652 if (offset >= params.beacon_csa.probe_resp_len)
7653 return -EINVAL;
7654
7655 if (params.beacon_csa.probe_resp[offset] !=
7656 params.count)
7657 return -EINVAL;
7658 }
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02007659 }
7660
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02007661skip_beacons:
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02007662 err = nl80211_parse_chandef(rdev, info, &params.chandef);
7663 if (err)
7664 return err;
7665
Arik Nemtsov923b3522015-07-08 15:41:44 +03007666 if (!cfg80211_reg_can_beacon_relax(&rdev->wiphy, &params.chandef,
7667 wdev->iftype))
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02007668 return -EINVAL;
7669
Luciano Coelho2beb6dab2014-02-18 11:40:36 +02007670 err = cfg80211_chandef_dfs_required(wdev->wiphy,
7671 &params.chandef,
7672 wdev->iftype);
7673 if (err < 0)
7674 return err;
7675
Benjamin Berg8d9de162017-05-16 11:23:12 +02007676 if (err > 0) {
Luciano Coelho2beb6dab2014-02-18 11:40:36 +02007677 params.radar_required = true;
Benjamin Berg8d9de162017-05-16 11:23:12 +02007678 if (need_handle_dfs_flag &&
7679 !nla_get_flag(info->attrs[NL80211_ATTR_HANDLE_DFS])) {
7680 return -EINVAL;
7681 }
7682 }
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02007683
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02007684 if (info->attrs[NL80211_ATTR_CH_SWITCH_BLOCK_TX])
7685 params.block_tx = true;
7686
Simon Wunderlichc56589e2013-11-21 18:19:49 +01007687 wdev_lock(wdev);
7688 err = rdev_channel_switch(rdev, dev, &params);
7689 wdev_unlock(wdev);
7690
7691 return err;
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02007692}
7693
Johannes Berg9720bb32011-06-21 09:45:33 +02007694static int nl80211_send_bss(struct sk_buff *msg, struct netlink_callback *cb,
7695 u32 seq, int flags,
Johannes Berg2a519312009-02-10 21:25:55 +01007696 struct cfg80211_registered_device *rdev,
Johannes Berg48ab9052009-07-10 18:42:31 +02007697 struct wireless_dev *wdev,
7698 struct cfg80211_internal_bss *intbss)
Johannes Berg2a519312009-02-10 21:25:55 +01007699{
Johannes Berg48ab9052009-07-10 18:42:31 +02007700 struct cfg80211_bss *res = &intbss->pub;
Johannes Berg9caf0362012-11-29 01:25:20 +01007701 const struct cfg80211_bss_ies *ies;
Johannes Berg2a519312009-02-10 21:25:55 +01007702 void *hdr;
7703 struct nlattr *bss;
Johannes Berg48ab9052009-07-10 18:42:31 +02007704
7705 ASSERT_WDEV_LOCK(wdev);
Johannes Berg2a519312009-02-10 21:25:55 +01007706
Eric W. Biederman15e47302012-09-07 20:12:54 +00007707 hdr = nl80211hdr_put(msg, NETLINK_CB(cb->skb).portid, seq, flags,
Johannes Berg2a519312009-02-10 21:25:55 +01007708 NL80211_CMD_NEW_SCAN_RESULTS);
7709 if (!hdr)
7710 return -1;
7711
Johannes Berg9720bb32011-06-21 09:45:33 +02007712 genl_dump_check_consistent(cb, hdr, &nl80211_fam);
7713
Johannes Berg97990a02013-04-19 01:02:55 +02007714 if (nla_put_u32(msg, NL80211_ATTR_GENERATION, rdev->bss_generation))
7715 goto nla_put_failure;
7716 if (wdev->netdev &&
David S. Miller9360ffd2012-03-29 04:41:26 -04007717 nla_put_u32(msg, NL80211_ATTR_IFINDEX, wdev->netdev->ifindex))
7718 goto nla_put_failure;
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02007719 if (nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
7720 NL80211_ATTR_PAD))
Johannes Berg97990a02013-04-19 01:02:55 +02007721 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01007722
7723 bss = nla_nest_start(msg, NL80211_ATTR_BSS);
7724 if (!bss)
7725 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04007726 if ((!is_zero_ether_addr(res->bssid) &&
Johannes Berg9caf0362012-11-29 01:25:20 +01007727 nla_put(msg, NL80211_BSS_BSSID, ETH_ALEN, res->bssid)))
David S. Miller9360ffd2012-03-29 04:41:26 -04007728 goto nla_put_failure;
Johannes Berg9caf0362012-11-29 01:25:20 +01007729
7730 rcu_read_lock();
Johannes Berg0e227082014-08-12 20:34:30 +02007731 /* indicate whether we have probe response data or not */
7732 if (rcu_access_pointer(res->proberesp_ies) &&
7733 nla_put_flag(msg, NL80211_BSS_PRESP_DATA))
7734 goto fail_unlock_rcu;
7735
7736 /* this pointer prefers to be pointed to probe response data
7737 * but is always valid
7738 */
Johannes Berg9caf0362012-11-29 01:25:20 +01007739 ies = rcu_dereference(res->ies);
Johannes Berg8cef2c92013-02-05 16:54:31 +01007740 if (ies) {
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02007741 if (nla_put_u64_64bit(msg, NL80211_BSS_TSF, ies->tsf,
7742 NL80211_BSS_PAD))
Johannes Berg8cef2c92013-02-05 16:54:31 +01007743 goto fail_unlock_rcu;
Johannes Berg8cef2c92013-02-05 16:54:31 +01007744 if (ies->len && nla_put(msg, NL80211_BSS_INFORMATION_ELEMENTS,
7745 ies->len, ies->data))
7746 goto fail_unlock_rcu;
Johannes Berg9caf0362012-11-29 01:25:20 +01007747 }
Johannes Berg0e227082014-08-12 20:34:30 +02007748
7749 /* and this pointer is always (unless driver didn't know) beacon data */
Johannes Berg9caf0362012-11-29 01:25:20 +01007750 ies = rcu_dereference(res->beacon_ies);
Johannes Berg0e227082014-08-12 20:34:30 +02007751 if (ies && ies->from_beacon) {
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02007752 if (nla_put_u64_64bit(msg, NL80211_BSS_BEACON_TSF, ies->tsf,
7753 NL80211_BSS_PAD))
Johannes Berg8cef2c92013-02-05 16:54:31 +01007754 goto fail_unlock_rcu;
7755 if (ies->len && nla_put(msg, NL80211_BSS_BEACON_IES,
7756 ies->len, ies->data))
7757 goto fail_unlock_rcu;
Johannes Berg9caf0362012-11-29 01:25:20 +01007758 }
7759 rcu_read_unlock();
7760
David S. Miller9360ffd2012-03-29 04:41:26 -04007761 if (res->beacon_interval &&
7762 nla_put_u16(msg, NL80211_BSS_BEACON_INTERVAL, res->beacon_interval))
7763 goto nla_put_failure;
7764 if (nla_put_u16(msg, NL80211_BSS_CAPABILITY, res->capability) ||
7765 nla_put_u32(msg, NL80211_BSS_FREQUENCY, res->channel->center_freq) ||
Simon Wunderlichdcd6eac2013-07-08 16:55:49 +02007766 nla_put_u32(msg, NL80211_BSS_CHAN_WIDTH, res->scan_width) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04007767 nla_put_u32(msg, NL80211_BSS_SEEN_MS_AGO,
7768 jiffies_to_msecs(jiffies - intbss->ts)))
7769 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01007770
Avraham Stern1d762502016-07-05 17:10:13 +03007771 if (intbss->parent_tsf &&
7772 (nla_put_u64_64bit(msg, NL80211_BSS_PARENT_TSF,
7773 intbss->parent_tsf, NL80211_BSS_PAD) ||
7774 nla_put(msg, NL80211_BSS_PARENT_BSSID, ETH_ALEN,
7775 intbss->parent_bssid)))
7776 goto nla_put_failure;
7777
Dmitry Shmidt6e19bc42015-10-07 11:32:53 +02007778 if (intbss->ts_boottime &&
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02007779 nla_put_u64_64bit(msg, NL80211_BSS_LAST_SEEN_BOOTTIME,
7780 intbss->ts_boottime, NL80211_BSS_PAD))
Dmitry Shmidt6e19bc42015-10-07 11:32:53 +02007781 goto nla_put_failure;
7782
Johannes Berg77965c92009-02-18 18:45:06 +01007783 switch (rdev->wiphy.signal_type) {
Johannes Berg2a519312009-02-10 21:25:55 +01007784 case CFG80211_SIGNAL_TYPE_MBM:
David S. Miller9360ffd2012-03-29 04:41:26 -04007785 if (nla_put_u32(msg, NL80211_BSS_SIGNAL_MBM, res->signal))
7786 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01007787 break;
7788 case CFG80211_SIGNAL_TYPE_UNSPEC:
David S. Miller9360ffd2012-03-29 04:41:26 -04007789 if (nla_put_u8(msg, NL80211_BSS_SIGNAL_UNSPEC, res->signal))
7790 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01007791 break;
7792 default:
7793 break;
7794 }
7795
Johannes Berg48ab9052009-07-10 18:42:31 +02007796 switch (wdev->iftype) {
Johannes Berg074ac8d2010-09-16 14:58:22 +02007797 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Berg48ab9052009-07-10 18:42:31 +02007798 case NL80211_IFTYPE_STATION:
David S. Miller9360ffd2012-03-29 04:41:26 -04007799 if (intbss == wdev->current_bss &&
7800 nla_put_u32(msg, NL80211_BSS_STATUS,
7801 NL80211_BSS_STATUS_ASSOCIATED))
7802 goto nla_put_failure;
Johannes Berg48ab9052009-07-10 18:42:31 +02007803 break;
7804 case NL80211_IFTYPE_ADHOC:
David S. Miller9360ffd2012-03-29 04:41:26 -04007805 if (intbss == wdev->current_bss &&
7806 nla_put_u32(msg, NL80211_BSS_STATUS,
7807 NL80211_BSS_STATUS_IBSS_JOINED))
7808 goto nla_put_failure;
Johannes Berg48ab9052009-07-10 18:42:31 +02007809 break;
7810 default:
7811 break;
7812 }
7813
Johannes Berg2a519312009-02-10 21:25:55 +01007814 nla_nest_end(msg, bss);
7815
Johannes Berg053c0952015-01-16 22:09:00 +01007816 genlmsg_end(msg, hdr);
7817 return 0;
Johannes Berg2a519312009-02-10 21:25:55 +01007818
Johannes Berg8cef2c92013-02-05 16:54:31 +01007819 fail_unlock_rcu:
7820 rcu_read_unlock();
Johannes Berg2a519312009-02-10 21:25:55 +01007821 nla_put_failure:
7822 genlmsg_cancel(msg, hdr);
7823 return -EMSGSIZE;
7824}
7825
Johannes Berg97990a02013-04-19 01:02:55 +02007826static int nl80211_dump_scan(struct sk_buff *skb, struct netlink_callback *cb)
Johannes Berg2a519312009-02-10 21:25:55 +01007827{
Johannes Berg48ab9052009-07-10 18:42:31 +02007828 struct cfg80211_registered_device *rdev;
Johannes Berg2a519312009-02-10 21:25:55 +01007829 struct cfg80211_internal_bss *scan;
Johannes Berg48ab9052009-07-10 18:42:31 +02007830 struct wireless_dev *wdev;
Johannes Berg97990a02013-04-19 01:02:55 +02007831 int start = cb->args[2], idx = 0;
Johannes Berg2a519312009-02-10 21:25:55 +01007832 int err;
7833
Johannes Bergea90e0d2017-03-15 14:26:04 +01007834 rtnl_lock();
Johannes Berg97990a02013-04-19 01:02:55 +02007835 err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev);
Johannes Bergea90e0d2017-03-15 14:26:04 +01007836 if (err) {
7837 rtnl_unlock();
Johannes Berg67748892010-10-04 21:14:06 +02007838 return err;
Johannes Bergea90e0d2017-03-15 14:26:04 +01007839 }
Johannes Berg2a519312009-02-10 21:25:55 +01007840
Johannes Berg48ab9052009-07-10 18:42:31 +02007841 wdev_lock(wdev);
7842 spin_lock_bh(&rdev->bss_lock);
7843 cfg80211_bss_expire(rdev);
7844
Johannes Berg9720bb32011-06-21 09:45:33 +02007845 cb->seq = rdev->bss_generation;
7846
Johannes Berg48ab9052009-07-10 18:42:31 +02007847 list_for_each_entry(scan, &rdev->bss_list, list) {
Johannes Berg2a519312009-02-10 21:25:55 +01007848 if (++idx <= start)
7849 continue;
Johannes Berg9720bb32011-06-21 09:45:33 +02007850 if (nl80211_send_bss(skb, cb,
Johannes Berg2a519312009-02-10 21:25:55 +01007851 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Johannes Berg48ab9052009-07-10 18:42:31 +02007852 rdev, wdev, scan) < 0) {
Johannes Berg2a519312009-02-10 21:25:55 +01007853 idx--;
Johannes Berg67748892010-10-04 21:14:06 +02007854 break;
Johannes Berg2a519312009-02-10 21:25:55 +01007855 }
7856 }
7857
Johannes Berg48ab9052009-07-10 18:42:31 +02007858 spin_unlock_bh(&rdev->bss_lock);
7859 wdev_unlock(wdev);
Johannes Berg2a519312009-02-10 21:25:55 +01007860
Johannes Berg97990a02013-04-19 01:02:55 +02007861 cb->args[2] = idx;
Johannes Bergea90e0d2017-03-15 14:26:04 +01007862 rtnl_unlock();
Johannes Berg2a519312009-02-10 21:25:55 +01007863
Johannes Berg67748892010-10-04 21:14:06 +02007864 return skb->len;
Johannes Berg2a519312009-02-10 21:25:55 +01007865}
7866
Eric W. Biederman15e47302012-09-07 20:12:54 +00007867static int nl80211_send_survey(struct sk_buff *msg, u32 portid, u32 seq,
Johannes Berg11f78ac2014-11-14 16:43:50 +01007868 int flags, struct net_device *dev,
7869 bool allow_radio_stats,
7870 struct survey_info *survey)
Holger Schurig61fa7132009-11-11 12:25:40 +01007871{
7872 void *hdr;
7873 struct nlattr *infoattr;
7874
Johannes Berg11f78ac2014-11-14 16:43:50 +01007875 /* skip radio stats if userspace didn't request them */
7876 if (!survey->channel && !allow_radio_stats)
7877 return 0;
7878
Eric W. Biederman15e47302012-09-07 20:12:54 +00007879 hdr = nl80211hdr_put(msg, portid, seq, flags,
Holger Schurig61fa7132009-11-11 12:25:40 +01007880 NL80211_CMD_NEW_SURVEY_RESULTS);
7881 if (!hdr)
7882 return -ENOMEM;
7883
David S. Miller9360ffd2012-03-29 04:41:26 -04007884 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex))
7885 goto nla_put_failure;
Holger Schurig61fa7132009-11-11 12:25:40 +01007886
7887 infoattr = nla_nest_start(msg, NL80211_ATTR_SURVEY_INFO);
7888 if (!infoattr)
7889 goto nla_put_failure;
7890
Johannes Berg11f78ac2014-11-14 16:43:50 +01007891 if (survey->channel &&
7892 nla_put_u32(msg, NL80211_SURVEY_INFO_FREQUENCY,
David S. Miller9360ffd2012-03-29 04:41:26 -04007893 survey->channel->center_freq))
7894 goto nla_put_failure;
7895
7896 if ((survey->filled & SURVEY_INFO_NOISE_DBM) &&
7897 nla_put_u8(msg, NL80211_SURVEY_INFO_NOISE, survey->noise))
7898 goto nla_put_failure;
7899 if ((survey->filled & SURVEY_INFO_IN_USE) &&
7900 nla_put_flag(msg, NL80211_SURVEY_INFO_IN_USE))
7901 goto nla_put_failure;
Johannes Berg4ed20be2014-11-14 16:35:34 +01007902 if ((survey->filled & SURVEY_INFO_TIME) &&
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02007903 nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME,
7904 survey->time, NL80211_SURVEY_INFO_PAD))
David S. Miller9360ffd2012-03-29 04:41:26 -04007905 goto nla_put_failure;
Johannes Berg4ed20be2014-11-14 16:35:34 +01007906 if ((survey->filled & SURVEY_INFO_TIME_BUSY) &&
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02007907 nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME_BUSY,
7908 survey->time_busy, NL80211_SURVEY_INFO_PAD))
David S. Miller9360ffd2012-03-29 04:41:26 -04007909 goto nla_put_failure;
Johannes Berg4ed20be2014-11-14 16:35:34 +01007910 if ((survey->filled & SURVEY_INFO_TIME_EXT_BUSY) &&
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02007911 nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME_EXT_BUSY,
7912 survey->time_ext_busy, NL80211_SURVEY_INFO_PAD))
David S. Miller9360ffd2012-03-29 04:41:26 -04007913 goto nla_put_failure;
Johannes Berg4ed20be2014-11-14 16:35:34 +01007914 if ((survey->filled & SURVEY_INFO_TIME_RX) &&
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02007915 nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME_RX,
7916 survey->time_rx, NL80211_SURVEY_INFO_PAD))
David S. Miller9360ffd2012-03-29 04:41:26 -04007917 goto nla_put_failure;
Johannes Berg4ed20be2014-11-14 16:35:34 +01007918 if ((survey->filled & SURVEY_INFO_TIME_TX) &&
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02007919 nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME_TX,
7920 survey->time_tx, NL80211_SURVEY_INFO_PAD))
David S. Miller9360ffd2012-03-29 04:41:26 -04007921 goto nla_put_failure;
Johannes Berg052536a2014-11-14 16:44:11 +01007922 if ((survey->filled & SURVEY_INFO_TIME_SCAN) &&
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02007923 nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME_SCAN,
7924 survey->time_scan, NL80211_SURVEY_INFO_PAD))
Johannes Berg052536a2014-11-14 16:44:11 +01007925 goto nla_put_failure;
Holger Schurig61fa7132009-11-11 12:25:40 +01007926
7927 nla_nest_end(msg, infoattr);
7928
Johannes Berg053c0952015-01-16 22:09:00 +01007929 genlmsg_end(msg, hdr);
7930 return 0;
Holger Schurig61fa7132009-11-11 12:25:40 +01007931
7932 nla_put_failure:
7933 genlmsg_cancel(msg, hdr);
7934 return -EMSGSIZE;
7935}
7936
Johannes Berg11f78ac2014-11-14 16:43:50 +01007937static int nl80211_dump_survey(struct sk_buff *skb, struct netlink_callback *cb)
Holger Schurig61fa7132009-11-11 12:25:40 +01007938{
Johannes Bergc90c39d2016-10-24 14:40:01 +02007939 struct nlattr **attrbuf = genl_family_attrbuf(&nl80211_fam);
Holger Schurig61fa7132009-11-11 12:25:40 +01007940 struct survey_info survey;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08007941 struct cfg80211_registered_device *rdev;
Johannes Berg97990a02013-04-19 01:02:55 +02007942 struct wireless_dev *wdev;
7943 int survey_idx = cb->args[2];
Holger Schurig61fa7132009-11-11 12:25:40 +01007944 int res;
Johannes Berg11f78ac2014-11-14 16:43:50 +01007945 bool radio_stats;
Holger Schurig61fa7132009-11-11 12:25:40 +01007946
Johannes Bergea90e0d2017-03-15 14:26:04 +01007947 rtnl_lock();
Zhao, Gang1b8ec872014-04-21 12:53:02 +08007948 res = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev);
Johannes Berg67748892010-10-04 21:14:06 +02007949 if (res)
Johannes Bergea90e0d2017-03-15 14:26:04 +01007950 goto out_err;
Holger Schurig61fa7132009-11-11 12:25:40 +01007951
Johannes Berg11f78ac2014-11-14 16:43:50 +01007952 /* prepare_wdev_dump parsed the attributes */
Johannes Bergc90c39d2016-10-24 14:40:01 +02007953 radio_stats = attrbuf[NL80211_ATTR_SURVEY_RADIO_STATS];
Johannes Berg11f78ac2014-11-14 16:43:50 +01007954
Johannes Berg97990a02013-04-19 01:02:55 +02007955 if (!wdev->netdev) {
7956 res = -EINVAL;
7957 goto out_err;
7958 }
7959
Zhao, Gang1b8ec872014-04-21 12:53:02 +08007960 if (!rdev->ops->dump_survey) {
Holger Schurig61fa7132009-11-11 12:25:40 +01007961 res = -EOPNOTSUPP;
7962 goto out_err;
7963 }
7964
7965 while (1) {
Zhao, Gang1b8ec872014-04-21 12:53:02 +08007966 res = rdev_dump_survey(rdev, wdev->netdev, survey_idx, &survey);
Holger Schurig61fa7132009-11-11 12:25:40 +01007967 if (res == -ENOENT)
7968 break;
7969 if (res)
7970 goto out_err;
7971
Johannes Berg11f78ac2014-11-14 16:43:50 +01007972 /* don't send disabled channels, but do send non-channel data */
7973 if (survey.channel &&
7974 survey.channel->flags & IEEE80211_CHAN_DISABLED) {
Luis R. Rodriguez180cdc72011-05-27 07:24:02 -07007975 survey_idx++;
7976 continue;
7977 }
7978
Holger Schurig61fa7132009-11-11 12:25:40 +01007979 if (nl80211_send_survey(skb,
Eric W. Biederman15e47302012-09-07 20:12:54 +00007980 NETLINK_CB(cb->skb).portid,
Holger Schurig61fa7132009-11-11 12:25:40 +01007981 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Johannes Berg11f78ac2014-11-14 16:43:50 +01007982 wdev->netdev, radio_stats, &survey) < 0)
Holger Schurig61fa7132009-11-11 12:25:40 +01007983 goto out;
7984 survey_idx++;
7985 }
7986
7987 out:
Johannes Berg97990a02013-04-19 01:02:55 +02007988 cb->args[2] = survey_idx;
Holger Schurig61fa7132009-11-11 12:25:40 +01007989 res = skb->len;
7990 out_err:
Johannes Bergea90e0d2017-03-15 14:26:04 +01007991 rtnl_unlock();
Holger Schurig61fa7132009-11-11 12:25:40 +01007992 return res;
7993}
7994
Samuel Ortizb23aa672009-07-01 21:26:54 +02007995static bool nl80211_valid_wpa_versions(u32 wpa_versions)
7996{
7997 return !(wpa_versions & ~(NL80211_WPA_VERSION_1 |
7998 NL80211_WPA_VERSION_2));
7999}
8000
Jouni Malinen636a5d32009-03-19 13:39:22 +02008001static int nl80211_authenticate(struct sk_buff *skb, struct genl_info *info)
8002{
Johannes Berg4c476992010-10-04 21:36:35 +02008003 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8004 struct net_device *dev = info->user_ptr[1];
Johannes Berg19957bb2009-07-02 17:20:43 +02008005 struct ieee80211_channel *chan;
Jouni Malinen11b6b5a2016-10-27 00:41:58 +03008006 const u8 *bssid, *ssid, *ie = NULL, *auth_data = NULL;
8007 int err, ssid_len, ie_len = 0, auth_data_len = 0;
Johannes Berg19957bb2009-07-02 17:20:43 +02008008 enum nl80211_auth_type auth_type;
Johannes Bergfffd0932009-07-08 14:22:54 +02008009 struct key_parse key;
Jouni Malinend5cdfac2010-04-04 09:37:19 +03008010 bool local_state_change;
Jouni Malinen636a5d32009-03-19 13:39:22 +02008011
Johannes Bergf4a11bb2009-03-27 12:40:28 +01008012 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
8013 return -EINVAL;
8014
8015 if (!info->attrs[NL80211_ATTR_MAC])
8016 return -EINVAL;
8017
Jouni Malinen17780922009-03-27 20:52:47 +02008018 if (!info->attrs[NL80211_ATTR_AUTH_TYPE])
8019 return -EINVAL;
8020
Johannes Berg19957bb2009-07-02 17:20:43 +02008021 if (!info->attrs[NL80211_ATTR_SSID])
8022 return -EINVAL;
8023
8024 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ])
8025 return -EINVAL;
8026
Johannes Bergfffd0932009-07-08 14:22:54 +02008027 err = nl80211_parse_key(info, &key);
8028 if (err)
8029 return err;
8030
8031 if (key.idx >= 0) {
Johannes Berge31b8212010-10-05 19:39:30 +02008032 if (key.type != -1 && key.type != NL80211_KEYTYPE_GROUP)
8033 return -EINVAL;
Johannes Bergfffd0932009-07-08 14:22:54 +02008034 if (!key.p.key || !key.p.key_len)
8035 return -EINVAL;
8036 if ((key.p.cipher != WLAN_CIPHER_SUITE_WEP40 ||
8037 key.p.key_len != WLAN_KEY_LEN_WEP40) &&
8038 (key.p.cipher != WLAN_CIPHER_SUITE_WEP104 ||
8039 key.p.key_len != WLAN_KEY_LEN_WEP104))
8040 return -EINVAL;
Johannes Bergb6b55552016-09-13 16:25:58 +02008041 if (key.idx > 3)
Johannes Bergfffd0932009-07-08 14:22:54 +02008042 return -EINVAL;
8043 } else {
8044 key.p.key_len = 0;
8045 key.p.key = NULL;
8046 }
8047
Johannes Bergafea0b72010-08-10 09:46:42 +02008048 if (key.idx >= 0) {
8049 int i;
8050 bool ok = false;
Kirtika Ruchandani7a087e72016-05-29 19:51:23 -07008051
Johannes Bergafea0b72010-08-10 09:46:42 +02008052 for (i = 0; i < rdev->wiphy.n_cipher_suites; i++) {
8053 if (key.p.cipher == rdev->wiphy.cipher_suites[i]) {
8054 ok = true;
8055 break;
8056 }
8057 }
Johannes Berg4c476992010-10-04 21:36:35 +02008058 if (!ok)
8059 return -EINVAL;
Johannes Bergafea0b72010-08-10 09:46:42 +02008060 }
8061
Johannes Berg4c476992010-10-04 21:36:35 +02008062 if (!rdev->ops->auth)
8063 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02008064
Johannes Berg074ac8d2010-09-16 14:58:22 +02008065 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02008066 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
8067 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02008068
Johannes Berg19957bb2009-07-02 17:20:43 +02008069 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen664834d2014-01-15 00:01:44 +02008070 chan = nl80211_get_valid_chan(&rdev->wiphy,
8071 info->attrs[NL80211_ATTR_WIPHY_FREQ]);
8072 if (!chan)
Johannes Berg4c476992010-10-04 21:36:35 +02008073 return -EINVAL;
Jouni Malinen636a5d32009-03-19 13:39:22 +02008074
Johannes Berg19957bb2009-07-02 17:20:43 +02008075 ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
8076 ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
8077
8078 if (info->attrs[NL80211_ATTR_IE]) {
8079 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
8080 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
8081 }
8082
8083 auth_type = nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]);
Jouni Malinene39e5b52012-09-30 19:29:39 +03008084 if (!nl80211_valid_auth_type(rdev, auth_type, NL80211_CMD_AUTHENTICATE))
Johannes Berg4c476992010-10-04 21:36:35 +02008085 return -EINVAL;
Johannes Berg19957bb2009-07-02 17:20:43 +02008086
Jouni Malinen63181062016-10-27 00:42:02 +03008087 if ((auth_type == NL80211_AUTHTYPE_SAE ||
8088 auth_type == NL80211_AUTHTYPE_FILS_SK ||
8089 auth_type == NL80211_AUTHTYPE_FILS_SK_PFS ||
8090 auth_type == NL80211_AUTHTYPE_FILS_PK) &&
Jouni Malinen11b6b5a2016-10-27 00:41:58 +03008091 !info->attrs[NL80211_ATTR_AUTH_DATA])
Jouni Malinene39e5b52012-09-30 19:29:39 +03008092 return -EINVAL;
8093
Jouni Malinen11b6b5a2016-10-27 00:41:58 +03008094 if (info->attrs[NL80211_ATTR_AUTH_DATA]) {
Jouni Malinen63181062016-10-27 00:42:02 +03008095 if (auth_type != NL80211_AUTHTYPE_SAE &&
8096 auth_type != NL80211_AUTHTYPE_FILS_SK &&
8097 auth_type != NL80211_AUTHTYPE_FILS_SK_PFS &&
8098 auth_type != NL80211_AUTHTYPE_FILS_PK)
Jouni Malinene39e5b52012-09-30 19:29:39 +03008099 return -EINVAL;
Jouni Malinen11b6b5a2016-10-27 00:41:58 +03008100 auth_data = nla_data(info->attrs[NL80211_ATTR_AUTH_DATA]);
8101 auth_data_len = nla_len(info->attrs[NL80211_ATTR_AUTH_DATA]);
Jouni Malinene39e5b52012-09-30 19:29:39 +03008102 /* need to include at least Auth Transaction and Status Code */
Jouni Malinen11b6b5a2016-10-27 00:41:58 +03008103 if (auth_data_len < 4)
Jouni Malinene39e5b52012-09-30 19:29:39 +03008104 return -EINVAL;
8105 }
8106
Jouni Malinend5cdfac2010-04-04 09:37:19 +03008107 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE];
8108
Johannes Berg95de8172012-01-20 13:55:25 +01008109 /*
8110 * Since we no longer track auth state, ignore
8111 * requests to only change local state.
8112 */
8113 if (local_state_change)
8114 return 0;
8115
Johannes Berg91bf9b22013-05-15 17:44:01 +02008116 wdev_lock(dev->ieee80211_ptr);
8117 err = cfg80211_mlme_auth(rdev, dev, chan, auth_type, bssid,
8118 ssid, ssid_len, ie, ie_len,
8119 key.p.key, key.p.key_len, key.idx,
Jouni Malinen11b6b5a2016-10-27 00:41:58 +03008120 auth_data, auth_data_len);
Johannes Berg91bf9b22013-05-15 17:44:01 +02008121 wdev_unlock(dev->ieee80211_ptr);
8122 return err;
Jouni Malinen636a5d32009-03-19 13:39:22 +02008123}
8124
Johannes Bergc0692b82010-08-27 14:26:53 +03008125static int nl80211_crypto_settings(struct cfg80211_registered_device *rdev,
8126 struct genl_info *info,
Johannes Berg3dc27d22009-07-02 21:36:37 +02008127 struct cfg80211_crypto_settings *settings,
8128 int cipher_limit)
Samuel Ortizb23aa672009-07-01 21:26:54 +02008129{
Johannes Bergc0b2bbd2009-07-25 16:54:36 +02008130 memset(settings, 0, sizeof(*settings));
8131
Samuel Ortizb23aa672009-07-01 21:26:54 +02008132 settings->control_port = info->attrs[NL80211_ATTR_CONTROL_PORT];
8133
Johannes Bergc0692b82010-08-27 14:26:53 +03008134 if (info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]) {
8135 u16 proto;
Kirtika Ruchandani7a087e72016-05-29 19:51:23 -07008136
Johannes Bergc0692b82010-08-27 14:26:53 +03008137 proto = nla_get_u16(
8138 info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]);
8139 settings->control_port_ethertype = cpu_to_be16(proto);
8140 if (!(rdev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) &&
8141 proto != ETH_P_PAE)
8142 return -EINVAL;
8143 if (info->attrs[NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT])
8144 settings->control_port_no_encrypt = true;
8145 } else
8146 settings->control_port_ethertype = cpu_to_be16(ETH_P_PAE);
8147
Samuel Ortizb23aa672009-07-01 21:26:54 +02008148 if (info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]) {
8149 void *data;
8150 int len, i;
8151
8152 data = nla_data(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]);
8153 len = nla_len(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]);
8154 settings->n_ciphers_pairwise = len / sizeof(u32);
8155
8156 if (len % sizeof(u32))
8157 return -EINVAL;
8158
Johannes Berg3dc27d22009-07-02 21:36:37 +02008159 if (settings->n_ciphers_pairwise > cipher_limit)
Samuel Ortizb23aa672009-07-01 21:26:54 +02008160 return -EINVAL;
8161
8162 memcpy(settings->ciphers_pairwise, data, len);
8163
8164 for (i = 0; i < settings->n_ciphers_pairwise; i++)
Jouni Malinen38ba3c52011-09-21 18:14:56 +03008165 if (!cfg80211_supported_cipher_suite(
8166 &rdev->wiphy,
Samuel Ortizb23aa672009-07-01 21:26:54 +02008167 settings->ciphers_pairwise[i]))
8168 return -EINVAL;
8169 }
8170
8171 if (info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]) {
8172 settings->cipher_group =
8173 nla_get_u32(info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]);
Jouni Malinen38ba3c52011-09-21 18:14:56 +03008174 if (!cfg80211_supported_cipher_suite(&rdev->wiphy,
8175 settings->cipher_group))
Samuel Ortizb23aa672009-07-01 21:26:54 +02008176 return -EINVAL;
8177 }
8178
8179 if (info->attrs[NL80211_ATTR_WPA_VERSIONS]) {
8180 settings->wpa_versions =
8181 nla_get_u32(info->attrs[NL80211_ATTR_WPA_VERSIONS]);
8182 if (!nl80211_valid_wpa_versions(settings->wpa_versions))
8183 return -EINVAL;
8184 }
8185
8186 if (info->attrs[NL80211_ATTR_AKM_SUITES]) {
8187 void *data;
Jouni Malinen6d302402011-09-21 18:11:33 +03008188 int len;
Samuel Ortizb23aa672009-07-01 21:26:54 +02008189
8190 data = nla_data(info->attrs[NL80211_ATTR_AKM_SUITES]);
8191 len = nla_len(info->attrs[NL80211_ATTR_AKM_SUITES]);
8192 settings->n_akm_suites = len / sizeof(u32);
8193
8194 if (len % sizeof(u32))
8195 return -EINVAL;
8196
Jouni Malinen1b9ca022011-09-21 16:13:07 +03008197 if (settings->n_akm_suites > NL80211_MAX_NR_AKM_SUITES)
8198 return -EINVAL;
8199
Samuel Ortizb23aa672009-07-01 21:26:54 +02008200 memcpy(settings->akm_suites, data, len);
Samuel Ortizb23aa672009-07-01 21:26:54 +02008201 }
8202
Eliad Peller91b5ab62017-06-09 13:08:42 +01008203 if (info->attrs[NL80211_ATTR_PMK]) {
8204 if (nla_len(info->attrs[NL80211_ATTR_PMK]) != WLAN_PMK_LEN)
8205 return -EINVAL;
8206 if (!wiphy_ext_feature_isset(&rdev->wiphy,
8207 NL80211_EXT_FEATURE_4WAY_HANDSHAKE_STA_PSK))
8208 return -EINVAL;
8209 settings->psk = nla_data(info->attrs[NL80211_ATTR_PMK]);
8210 }
8211
Samuel Ortizb23aa672009-07-01 21:26:54 +02008212 return 0;
8213}
8214
Jouni Malinen636a5d32009-03-19 13:39:22 +02008215static int nl80211_associate(struct sk_buff *skb, struct genl_info *info)
8216{
Johannes Berg4c476992010-10-04 21:36:35 +02008217 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8218 struct net_device *dev = info->user_ptr[1];
Johannes Bergf444de02010-05-05 15:25:02 +02008219 struct ieee80211_channel *chan;
Johannes Bergf62fab72013-02-21 20:09:09 +01008220 struct cfg80211_assoc_request req = {};
8221 const u8 *bssid, *ssid;
8222 int err, ssid_len = 0;
Jouni Malinen636a5d32009-03-19 13:39:22 +02008223
Johannes Bergf4a11bb2009-03-27 12:40:28 +01008224 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
8225 return -EINVAL;
8226
8227 if (!info->attrs[NL80211_ATTR_MAC] ||
Johannes Berg19957bb2009-07-02 17:20:43 +02008228 !info->attrs[NL80211_ATTR_SSID] ||
8229 !info->attrs[NL80211_ATTR_WIPHY_FREQ])
Johannes Bergf4a11bb2009-03-27 12:40:28 +01008230 return -EINVAL;
8231
Johannes Berg4c476992010-10-04 21:36:35 +02008232 if (!rdev->ops->assoc)
8233 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02008234
Johannes Berg074ac8d2010-09-16 14:58:22 +02008235 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02008236 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
8237 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02008238
Johannes Berg19957bb2009-07-02 17:20:43 +02008239 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02008240
Jouni Malinen664834d2014-01-15 00:01:44 +02008241 chan = nl80211_get_valid_chan(&rdev->wiphy,
8242 info->attrs[NL80211_ATTR_WIPHY_FREQ]);
8243 if (!chan)
Johannes Berg4c476992010-10-04 21:36:35 +02008244 return -EINVAL;
Jouni Malinen636a5d32009-03-19 13:39:22 +02008245
Johannes Berg19957bb2009-07-02 17:20:43 +02008246 ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
8247 ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02008248
8249 if (info->attrs[NL80211_ATTR_IE]) {
Johannes Bergf62fab72013-02-21 20:09:09 +01008250 req.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
8251 req.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02008252 }
8253
Jouni Malinendc6382ce2009-05-06 22:09:37 +03008254 if (info->attrs[NL80211_ATTR_USE_MFP]) {
Johannes Berg4f5dadc2009-07-07 03:56:10 +02008255 enum nl80211_mfp mfp =
Jouni Malinendc6382ce2009-05-06 22:09:37 +03008256 nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]);
Johannes Berg4f5dadc2009-07-07 03:56:10 +02008257 if (mfp == NL80211_MFP_REQUIRED)
Johannes Bergf62fab72013-02-21 20:09:09 +01008258 req.use_mfp = true;
Johannes Berg4c476992010-10-04 21:36:35 +02008259 else if (mfp != NL80211_MFP_NO)
8260 return -EINVAL;
Jouni Malinendc6382ce2009-05-06 22:09:37 +03008261 }
8262
Johannes Berg3e5d7642009-07-07 14:37:26 +02008263 if (info->attrs[NL80211_ATTR_PREV_BSSID])
Johannes Bergf62fab72013-02-21 20:09:09 +01008264 req.prev_bssid = nla_data(info->attrs[NL80211_ATTR_PREV_BSSID]);
Johannes Berg3e5d7642009-07-07 14:37:26 +02008265
Ben Greear7e7c8922011-11-18 11:31:59 -08008266 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT]))
Johannes Bergf62fab72013-02-21 20:09:09 +01008267 req.flags |= ASSOC_REQ_DISABLE_HT;
Ben Greear7e7c8922011-11-18 11:31:59 -08008268
8269 if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
Johannes Bergf62fab72013-02-21 20:09:09 +01008270 memcpy(&req.ht_capa_mask,
8271 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]),
8272 sizeof(req.ht_capa_mask));
Ben Greear7e7c8922011-11-18 11:31:59 -08008273
8274 if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) {
Johannes Bergf62fab72013-02-21 20:09:09 +01008275 if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
Ben Greear7e7c8922011-11-18 11:31:59 -08008276 return -EINVAL;
Johannes Bergf62fab72013-02-21 20:09:09 +01008277 memcpy(&req.ht_capa,
8278 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]),
8279 sizeof(req.ht_capa));
Ben Greear7e7c8922011-11-18 11:31:59 -08008280 }
8281
Johannes Bergee2aca32013-02-21 17:36:01 +01008282 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_VHT]))
Johannes Bergf62fab72013-02-21 20:09:09 +01008283 req.flags |= ASSOC_REQ_DISABLE_VHT;
Johannes Bergee2aca32013-02-21 17:36:01 +01008284
8285 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK])
Johannes Bergf62fab72013-02-21 20:09:09 +01008286 memcpy(&req.vht_capa_mask,
8287 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]),
8288 sizeof(req.vht_capa_mask));
Johannes Bergee2aca32013-02-21 17:36:01 +01008289
8290 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) {
Johannes Bergf62fab72013-02-21 20:09:09 +01008291 if (!info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK])
Johannes Bergee2aca32013-02-21 17:36:01 +01008292 return -EINVAL;
Johannes Bergf62fab72013-02-21 20:09:09 +01008293 memcpy(&req.vht_capa,
8294 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]),
8295 sizeof(req.vht_capa));
Johannes Bergee2aca32013-02-21 17:36:01 +01008296 }
8297
Assaf Kraussbab5ab72014-09-03 15:25:01 +03008298 if (nla_get_flag(info->attrs[NL80211_ATTR_USE_RRM])) {
Beni Lev0c9ca112016-02-17 20:30:00 +02008299 if (!((rdev->wiphy.features &
8300 NL80211_FEATURE_DS_PARAM_SET_IE_IN_PROBES) &&
8301 (rdev->wiphy.features & NL80211_FEATURE_QUIET)) &&
8302 !wiphy_ext_feature_isset(&rdev->wiphy,
8303 NL80211_EXT_FEATURE_RRM))
Assaf Kraussbab5ab72014-09-03 15:25:01 +03008304 return -EINVAL;
8305 req.flags |= ASSOC_REQ_USE_RRM;
8306 }
8307
Jouni Malinen348bd452016-10-27 00:42:03 +03008308 if (info->attrs[NL80211_ATTR_FILS_KEK]) {
8309 req.fils_kek = nla_data(info->attrs[NL80211_ATTR_FILS_KEK]);
8310 req.fils_kek_len = nla_len(info->attrs[NL80211_ATTR_FILS_KEK]);
8311 if (!info->attrs[NL80211_ATTR_FILS_NONCES])
8312 return -EINVAL;
8313 req.fils_nonces =
8314 nla_data(info->attrs[NL80211_ATTR_FILS_NONCES]);
8315 }
8316
Johannes Bergf62fab72013-02-21 20:09:09 +01008317 err = nl80211_crypto_settings(rdev, info, &req.crypto, 1);
Johannes Berg91bf9b22013-05-15 17:44:01 +02008318 if (!err) {
8319 wdev_lock(dev->ieee80211_ptr);
Andrzej Zaborowskibd2522b2017-01-06 16:33:43 -05008320
Johannes Bergf62fab72013-02-21 20:09:09 +01008321 err = cfg80211_mlme_assoc(rdev, dev, chan, bssid,
8322 ssid, ssid_len, &req);
Andrzej Zaborowskibd2522b2017-01-06 16:33:43 -05008323
8324 if (!err && info->attrs[NL80211_ATTR_SOCKET_OWNER]) {
8325 dev->ieee80211_ptr->conn_owner_nlportid =
8326 info->snd_portid;
8327 memcpy(dev->ieee80211_ptr->disconnect_bssid,
8328 bssid, ETH_ALEN);
8329 }
8330
Johannes Berg91bf9b22013-05-15 17:44:01 +02008331 wdev_unlock(dev->ieee80211_ptr);
8332 }
Jouni Malinen636a5d32009-03-19 13:39:22 +02008333
Jouni Malinen636a5d32009-03-19 13:39:22 +02008334 return err;
8335}
8336
8337static int nl80211_deauthenticate(struct sk_buff *skb, struct genl_info *info)
8338{
Johannes Berg4c476992010-10-04 21:36:35 +02008339 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8340 struct net_device *dev = info->user_ptr[1];
Johannes Berg19957bb2009-07-02 17:20:43 +02008341 const u8 *ie = NULL, *bssid;
Johannes Berg91bf9b22013-05-15 17:44:01 +02008342 int ie_len = 0, err;
Johannes Berg19957bb2009-07-02 17:20:43 +02008343 u16 reason_code;
Jouni Malinend5cdfac2010-04-04 09:37:19 +03008344 bool local_state_change;
Jouni Malinen636a5d32009-03-19 13:39:22 +02008345
Johannes Bergf4a11bb2009-03-27 12:40:28 +01008346 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
8347 return -EINVAL;
8348
8349 if (!info->attrs[NL80211_ATTR_MAC])
8350 return -EINVAL;
8351
8352 if (!info->attrs[NL80211_ATTR_REASON_CODE])
8353 return -EINVAL;
8354
Johannes Berg4c476992010-10-04 21:36:35 +02008355 if (!rdev->ops->deauth)
8356 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02008357
Johannes Berg074ac8d2010-09-16 14:58:22 +02008358 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02008359 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
8360 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02008361
Johannes Berg19957bb2009-07-02 17:20:43 +02008362 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02008363
Johannes Berg19957bb2009-07-02 17:20:43 +02008364 reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
8365 if (reason_code == 0) {
Johannes Bergf4a11bb2009-03-27 12:40:28 +01008366 /* Reason Code 0 is reserved */
Johannes Berg4c476992010-10-04 21:36:35 +02008367 return -EINVAL;
Jouni Malinen255e7372009-03-20 21:21:17 +02008368 }
Jouni Malinen636a5d32009-03-19 13:39:22 +02008369
8370 if (info->attrs[NL80211_ATTR_IE]) {
Johannes Berg19957bb2009-07-02 17:20:43 +02008371 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
8372 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02008373 }
8374
Jouni Malinend5cdfac2010-04-04 09:37:19 +03008375 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE];
8376
Johannes Berg91bf9b22013-05-15 17:44:01 +02008377 wdev_lock(dev->ieee80211_ptr);
8378 err = cfg80211_mlme_deauth(rdev, dev, bssid, ie, ie_len, reason_code,
8379 local_state_change);
8380 wdev_unlock(dev->ieee80211_ptr);
8381 return err;
Jouni Malinen636a5d32009-03-19 13:39:22 +02008382}
8383
8384static int nl80211_disassociate(struct sk_buff *skb, struct genl_info *info)
8385{
Johannes Berg4c476992010-10-04 21:36:35 +02008386 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8387 struct net_device *dev = info->user_ptr[1];
Johannes Berg19957bb2009-07-02 17:20:43 +02008388 const u8 *ie = NULL, *bssid;
Johannes Berg91bf9b22013-05-15 17:44:01 +02008389 int ie_len = 0, err;
Johannes Berg19957bb2009-07-02 17:20:43 +02008390 u16 reason_code;
Jouni Malinend5cdfac2010-04-04 09:37:19 +03008391 bool local_state_change;
Jouni Malinen636a5d32009-03-19 13:39:22 +02008392
Johannes Bergf4a11bb2009-03-27 12:40:28 +01008393 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
8394 return -EINVAL;
8395
8396 if (!info->attrs[NL80211_ATTR_MAC])
8397 return -EINVAL;
8398
8399 if (!info->attrs[NL80211_ATTR_REASON_CODE])
8400 return -EINVAL;
8401
Johannes Berg4c476992010-10-04 21:36:35 +02008402 if (!rdev->ops->disassoc)
8403 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02008404
Johannes Berg074ac8d2010-09-16 14:58:22 +02008405 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02008406 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
8407 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02008408
Johannes Berg19957bb2009-07-02 17:20:43 +02008409 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02008410
Johannes Berg19957bb2009-07-02 17:20:43 +02008411 reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
8412 if (reason_code == 0) {
Johannes Bergf4a11bb2009-03-27 12:40:28 +01008413 /* Reason Code 0 is reserved */
Johannes Berg4c476992010-10-04 21:36:35 +02008414 return -EINVAL;
Jouni Malinen255e7372009-03-20 21:21:17 +02008415 }
Jouni Malinen636a5d32009-03-19 13:39:22 +02008416
8417 if (info->attrs[NL80211_ATTR_IE]) {
Johannes Berg19957bb2009-07-02 17:20:43 +02008418 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
8419 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02008420 }
8421
Jouni Malinend5cdfac2010-04-04 09:37:19 +03008422 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE];
8423
Johannes Berg91bf9b22013-05-15 17:44:01 +02008424 wdev_lock(dev->ieee80211_ptr);
8425 err = cfg80211_mlme_disassoc(rdev, dev, bssid, ie, ie_len, reason_code,
8426 local_state_change);
8427 wdev_unlock(dev->ieee80211_ptr);
8428 return err;
Jouni Malinen636a5d32009-03-19 13:39:22 +02008429}
8430
Felix Fietkaudd5b4cc2010-11-22 20:58:24 +01008431static bool
8432nl80211_parse_mcast_rate(struct cfg80211_registered_device *rdev,
Johannes Berg57fbcce2016-04-12 15:56:15 +02008433 int mcast_rate[NUM_NL80211_BANDS],
Felix Fietkaudd5b4cc2010-11-22 20:58:24 +01008434 int rateval)
8435{
8436 struct wiphy *wiphy = &rdev->wiphy;
8437 bool found = false;
8438 int band, i;
8439
Johannes Berg57fbcce2016-04-12 15:56:15 +02008440 for (band = 0; band < NUM_NL80211_BANDS; band++) {
Felix Fietkaudd5b4cc2010-11-22 20:58:24 +01008441 struct ieee80211_supported_band *sband;
8442
8443 sband = wiphy->bands[band];
8444 if (!sband)
8445 continue;
8446
8447 for (i = 0; i < sband->n_bitrates; i++) {
8448 if (sband->bitrates[i].bitrate == rateval) {
8449 mcast_rate[band] = i + 1;
8450 found = true;
8451 break;
8452 }
8453 }
8454 }
8455
8456 return found;
8457}
8458
Johannes Berg04a773a2009-04-19 21:24:32 +02008459static int nl80211_join_ibss(struct sk_buff *skb, struct genl_info *info)
8460{
Johannes Berg4c476992010-10-04 21:36:35 +02008461 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8462 struct net_device *dev = info->user_ptr[1];
Johannes Berg04a773a2009-04-19 21:24:32 +02008463 struct cfg80211_ibss_params ibss;
8464 struct wiphy *wiphy;
Johannes Bergfffd0932009-07-08 14:22:54 +02008465 struct cfg80211_cached_keys *connkeys = NULL;
Johannes Berg04a773a2009-04-19 21:24:32 +02008466 int err;
8467
Johannes Berg8e30bc52009-04-22 17:45:38 +02008468 memset(&ibss, 0, sizeof(ibss));
8469
Johannes Berg04a773a2009-04-19 21:24:32 +02008470 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
8471 return -EINVAL;
8472
Johannes Berg683b6d32012-11-08 21:25:48 +01008473 if (!info->attrs[NL80211_ATTR_SSID] ||
Johannes Berg04a773a2009-04-19 21:24:32 +02008474 !nla_len(info->attrs[NL80211_ATTR_SSID]))
8475 return -EINVAL;
8476
Johannes Berg8e30bc52009-04-22 17:45:38 +02008477 ibss.beacon_interval = 100;
8478
Purushottam Kushwaha12d20fc92016-08-11 15:14:02 +05308479 if (info->attrs[NL80211_ATTR_BEACON_INTERVAL])
Johannes Berg8e30bc52009-04-22 17:45:38 +02008480 ibss.beacon_interval =
8481 nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]);
Purushottam Kushwaha12d20fc92016-08-11 15:14:02 +05308482
Purushottam Kushwaha0c317a02016-10-12 18:26:51 +05308483 err = cfg80211_validate_beacon_int(rdev, NL80211_IFTYPE_ADHOC,
8484 ibss.beacon_interval);
Purushottam Kushwaha12d20fc92016-08-11 15:14:02 +05308485 if (err)
8486 return err;
Johannes Berg8e30bc52009-04-22 17:45:38 +02008487
Johannes Berg4c476992010-10-04 21:36:35 +02008488 if (!rdev->ops->join_ibss)
8489 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02008490
Johannes Berg4c476992010-10-04 21:36:35 +02008491 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC)
8492 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02008493
Johannes Berg79c97e92009-07-07 03:56:12 +02008494 wiphy = &rdev->wiphy;
Johannes Berg04a773a2009-04-19 21:24:32 +02008495
Johannes Berg39193492011-09-16 13:45:25 +02008496 if (info->attrs[NL80211_ATTR_MAC]) {
Johannes Berg04a773a2009-04-19 21:24:32 +02008497 ibss.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Johannes Berg39193492011-09-16 13:45:25 +02008498
8499 if (!is_valid_ether_addr(ibss.bssid))
8500 return -EINVAL;
8501 }
Johannes Berg04a773a2009-04-19 21:24:32 +02008502 ibss.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
8503 ibss.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
8504
8505 if (info->attrs[NL80211_ATTR_IE]) {
8506 ibss.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
8507 ibss.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
8508 }
8509
Johannes Berg683b6d32012-11-08 21:25:48 +01008510 err = nl80211_parse_chandef(rdev, info, &ibss.chandef);
8511 if (err)
8512 return err;
Alexander Simon54858ee5b2011-11-30 16:56:32 +01008513
Ilan Peer174e0cd2014-02-23 09:13:01 +02008514 if (!cfg80211_reg_can_beacon(&rdev->wiphy, &ibss.chandef,
8515 NL80211_IFTYPE_ADHOC))
Alexander Simon54858ee5b2011-11-30 16:56:32 +01008516 return -EINVAL;
8517
Simon Wunderlich2f301ab2013-05-16 13:00:28 +02008518 switch (ibss.chandef.width) {
Simon Wunderlichbf372642013-07-08 16:55:58 +02008519 case NL80211_CHAN_WIDTH_5:
8520 case NL80211_CHAN_WIDTH_10:
Simon Wunderlich2f301ab2013-05-16 13:00:28 +02008521 case NL80211_CHAN_WIDTH_20_NOHT:
8522 break;
8523 case NL80211_CHAN_WIDTH_20:
8524 case NL80211_CHAN_WIDTH_40:
Janusz.Dziedzic@tieto.comffc11992015-02-21 16:52:39 +01008525 if (!(rdev->wiphy.features & NL80211_FEATURE_HT_IBSS))
8526 return -EINVAL;
8527 break;
8528 case NL80211_CHAN_WIDTH_80:
8529 case NL80211_CHAN_WIDTH_80P80:
8530 case NL80211_CHAN_WIDTH_160:
8531 if (!(rdev->wiphy.features & NL80211_FEATURE_HT_IBSS))
8532 return -EINVAL;
8533 if (!wiphy_ext_feature_isset(&rdev->wiphy,
8534 NL80211_EXT_FEATURE_VHT_IBSS))
8535 return -EINVAL;
8536 break;
Simon Wunderlich2f301ab2013-05-16 13:00:28 +02008537 default:
Johannes Bergdb9c64c2012-11-09 14:56:41 +01008538 return -EINVAL;
Simon Wunderlich2f301ab2013-05-16 13:00:28 +02008539 }
Johannes Bergdb9c64c2012-11-09 14:56:41 +01008540
Johannes Berg04a773a2009-04-19 21:24:32 +02008541 ibss.channel_fixed = !!info->attrs[NL80211_ATTR_FREQ_FIXED];
Johannes Bergfffd0932009-07-08 14:22:54 +02008542 ibss.privacy = !!info->attrs[NL80211_ATTR_PRIVACY];
Johannes Berg04a773a2009-04-19 21:24:32 +02008543
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03008544 if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) {
8545 u8 *rates =
8546 nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
8547 int n_rates =
8548 nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
8549 struct ieee80211_supported_band *sband =
Johannes Berg683b6d32012-11-08 21:25:48 +01008550 wiphy->bands[ibss.chandef.chan->band];
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03008551
Johannes Berg34850ab2011-07-18 18:08:35 +02008552 err = ieee80211_get_ratemask(sband, rates, n_rates,
8553 &ibss.basic_rates);
8554 if (err)
8555 return err;
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03008556 }
Felix Fietkaudd5b4cc2010-11-22 20:58:24 +01008557
Simon Wunderlich803768f2013-06-28 10:39:58 +02008558 if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
8559 memcpy(&ibss.ht_capa_mask,
8560 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]),
8561 sizeof(ibss.ht_capa_mask));
8562
8563 if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) {
8564 if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
8565 return -EINVAL;
8566 memcpy(&ibss.ht_capa,
8567 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]),
8568 sizeof(ibss.ht_capa));
8569 }
8570
Felix Fietkaudd5b4cc2010-11-22 20:58:24 +01008571 if (info->attrs[NL80211_ATTR_MCAST_RATE] &&
8572 !nl80211_parse_mcast_rate(rdev, ibss.mcast_rate,
8573 nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE])))
8574 return -EINVAL;
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03008575
Johannes Berg4c476992010-10-04 21:36:35 +02008576 if (ibss.privacy && info->attrs[NL80211_ATTR_KEYS]) {
Sujith Manoharande7044e2012-10-18 10:19:28 +05308577 bool no_ht = false;
8578
Johannes Berg4c476992010-10-04 21:36:35 +02008579 connkeys = nl80211_parse_connkeys(rdev,
Sujith Manoharande7044e2012-10-18 10:19:28 +05308580 info->attrs[NL80211_ATTR_KEYS],
8581 &no_ht);
Johannes Berg4c476992010-10-04 21:36:35 +02008582 if (IS_ERR(connkeys))
8583 return PTR_ERR(connkeys);
Sujith Manoharande7044e2012-10-18 10:19:28 +05308584
Johannes Berg3d9d1d62012-11-08 23:14:50 +01008585 if ((ibss.chandef.width != NL80211_CHAN_WIDTH_20_NOHT) &&
8586 no_ht) {
Ola Olsson5e950a72016-02-11 01:00:22 +01008587 kzfree(connkeys);
Sujith Manoharande7044e2012-10-18 10:19:28 +05308588 return -EINVAL;
8589 }
Johannes Berg4c476992010-10-04 21:36:35 +02008590 }
Johannes Berg04a773a2009-04-19 21:24:32 +02008591
Antonio Quartulli267335d2012-01-31 20:25:47 +01008592 ibss.control_port =
8593 nla_get_flag(info->attrs[NL80211_ATTR_CONTROL_PORT]);
8594
Simon Wunderlich5336fa82013-10-07 18:41:05 +02008595 ibss.userspace_handles_dfs =
8596 nla_get_flag(info->attrs[NL80211_ATTR_HANDLE_DFS]);
8597
Johannes Berg4c476992010-10-04 21:36:35 +02008598 err = cfg80211_join_ibss(rdev, dev, &ibss, connkeys);
Johannes Bergfffd0932009-07-08 14:22:54 +02008599 if (err)
Johannes Bergb47f6102014-09-10 13:39:54 +03008600 kzfree(connkeys);
Johannes Berg04a773a2009-04-19 21:24:32 +02008601 return err;
8602}
8603
8604static int nl80211_leave_ibss(struct sk_buff *skb, struct genl_info *info)
8605{
Johannes Berg4c476992010-10-04 21:36:35 +02008606 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8607 struct net_device *dev = info->user_ptr[1];
Johannes Berg04a773a2009-04-19 21:24:32 +02008608
Johannes Berg4c476992010-10-04 21:36:35 +02008609 if (!rdev->ops->leave_ibss)
8610 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02008611
Johannes Berg4c476992010-10-04 21:36:35 +02008612 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC)
8613 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02008614
Johannes Berg4c476992010-10-04 21:36:35 +02008615 return cfg80211_leave_ibss(rdev, dev, false);
Johannes Berg04a773a2009-04-19 21:24:32 +02008616}
8617
Antonio Quartullif4e583c2012-11-02 13:27:48 +01008618static int nl80211_set_mcast_rate(struct sk_buff *skb, struct genl_info *info)
8619{
8620 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8621 struct net_device *dev = info->user_ptr[1];
Johannes Berg57fbcce2016-04-12 15:56:15 +02008622 int mcast_rate[NUM_NL80211_BANDS];
Antonio Quartullif4e583c2012-11-02 13:27:48 +01008623 u32 nla_rate;
8624 int err;
8625
8626 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC &&
Bertold Van den Bergh876dc932015-08-05 16:02:21 +02008627 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT &&
8628 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_OCB)
Antonio Quartullif4e583c2012-11-02 13:27:48 +01008629 return -EOPNOTSUPP;
8630
8631 if (!rdev->ops->set_mcast_rate)
8632 return -EOPNOTSUPP;
8633
8634 memset(mcast_rate, 0, sizeof(mcast_rate));
8635
8636 if (!info->attrs[NL80211_ATTR_MCAST_RATE])
8637 return -EINVAL;
8638
8639 nla_rate = nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]);
8640 if (!nl80211_parse_mcast_rate(rdev, mcast_rate, nla_rate))
8641 return -EINVAL;
8642
Ilan Peera1056b12015-10-22 22:27:46 +03008643 err = rdev_set_mcast_rate(rdev, dev, mcast_rate);
Antonio Quartullif4e583c2012-11-02 13:27:48 +01008644
8645 return err;
8646}
8647
Johannes Bergad7e7182013-11-13 13:37:47 +01008648static struct sk_buff *
8649__cfg80211_alloc_vendor_skb(struct cfg80211_registered_device *rdev,
Ahmad Kholaif6c09e792015-02-26 15:26:53 +02008650 struct wireless_dev *wdev, int approxlen,
8651 u32 portid, u32 seq, enum nl80211_commands cmd,
Johannes Berg567ffc32013-12-18 14:43:31 +01008652 enum nl80211_attrs attr,
8653 const struct nl80211_vendor_cmd_info *info,
8654 gfp_t gfp)
Johannes Bergad7e7182013-11-13 13:37:47 +01008655{
8656 struct sk_buff *skb;
8657 void *hdr;
8658 struct nlattr *data;
8659
8660 skb = nlmsg_new(approxlen + 100, gfp);
8661 if (!skb)
8662 return NULL;
8663
8664 hdr = nl80211hdr_put(skb, portid, seq, 0, cmd);
8665 if (!hdr) {
8666 kfree_skb(skb);
8667 return NULL;
8668 }
8669
8670 if (nla_put_u32(skb, NL80211_ATTR_WIPHY, rdev->wiphy_idx))
8671 goto nla_put_failure;
Johannes Berg567ffc32013-12-18 14:43:31 +01008672
8673 if (info) {
8674 if (nla_put_u32(skb, NL80211_ATTR_VENDOR_ID,
8675 info->vendor_id))
8676 goto nla_put_failure;
8677 if (nla_put_u32(skb, NL80211_ATTR_VENDOR_SUBCMD,
8678 info->subcmd))
8679 goto nla_put_failure;
8680 }
8681
Ahmad Kholaif6c09e792015-02-26 15:26:53 +02008682 if (wdev) {
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02008683 if (nla_put_u64_64bit(skb, NL80211_ATTR_WDEV,
8684 wdev_id(wdev), NL80211_ATTR_PAD))
Ahmad Kholaif6c09e792015-02-26 15:26:53 +02008685 goto nla_put_failure;
8686 if (wdev->netdev &&
8687 nla_put_u32(skb, NL80211_ATTR_IFINDEX,
8688 wdev->netdev->ifindex))
8689 goto nla_put_failure;
8690 }
8691
Johannes Bergad7e7182013-11-13 13:37:47 +01008692 data = nla_nest_start(skb, attr);
Johannes Berg76e1fb42016-09-14 09:55:57 +02008693 if (!data)
8694 goto nla_put_failure;
Johannes Bergad7e7182013-11-13 13:37:47 +01008695
8696 ((void **)skb->cb)[0] = rdev;
8697 ((void **)skb->cb)[1] = hdr;
8698 ((void **)skb->cb)[2] = data;
8699
8700 return skb;
8701
8702 nla_put_failure:
8703 kfree_skb(skb);
8704 return NULL;
8705}
Antonio Quartullif4e583c2012-11-02 13:27:48 +01008706
Johannes Berge03ad6e2014-01-01 17:22:30 +01008707struct sk_buff *__cfg80211_alloc_event_skb(struct wiphy *wiphy,
Ahmad Kholaif6c09e792015-02-26 15:26:53 +02008708 struct wireless_dev *wdev,
Johannes Berge03ad6e2014-01-01 17:22:30 +01008709 enum nl80211_commands cmd,
8710 enum nl80211_attrs attr,
8711 int vendor_event_idx,
8712 int approxlen, gfp_t gfp)
8713{
Zhao, Gangf26cbf42014-04-21 12:53:03 +08008714 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berge03ad6e2014-01-01 17:22:30 +01008715 const struct nl80211_vendor_cmd_info *info;
8716
8717 switch (cmd) {
8718 case NL80211_CMD_TESTMODE:
8719 if (WARN_ON(vendor_event_idx != -1))
8720 return NULL;
8721 info = NULL;
8722 break;
8723 case NL80211_CMD_VENDOR:
8724 if (WARN_ON(vendor_event_idx < 0 ||
8725 vendor_event_idx >= wiphy->n_vendor_events))
8726 return NULL;
8727 info = &wiphy->vendor_events[vendor_event_idx];
8728 break;
8729 default:
8730 WARN_ON(1);
8731 return NULL;
8732 }
8733
Ahmad Kholaif6c09e792015-02-26 15:26:53 +02008734 return __cfg80211_alloc_vendor_skb(rdev, wdev, approxlen, 0, 0,
Johannes Berge03ad6e2014-01-01 17:22:30 +01008735 cmd, attr, info, gfp);
8736}
8737EXPORT_SYMBOL(__cfg80211_alloc_event_skb);
8738
8739void __cfg80211_send_event_skb(struct sk_buff *skb, gfp_t gfp)
8740{
8741 struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0];
8742 void *hdr = ((void **)skb->cb)[1];
8743 struct nlattr *data = ((void **)skb->cb)[2];
8744 enum nl80211_multicast_groups mcgrp = NL80211_MCGRP_TESTMODE;
8745
Johannes Bergbd8c78e2014-07-30 14:55:26 +02008746 /* clear CB data for netlink core to own from now on */
8747 memset(skb->cb, 0, sizeof(skb->cb));
8748
Johannes Berge03ad6e2014-01-01 17:22:30 +01008749 nla_nest_end(skb, data);
8750 genlmsg_end(skb, hdr);
8751
8752 if (data->nla_type == NL80211_ATTR_VENDOR_DATA)
8753 mcgrp = NL80211_MCGRP_VENDOR;
8754
8755 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), skb, 0,
8756 mcgrp, gfp);
8757}
8758EXPORT_SYMBOL(__cfg80211_send_event_skb);
8759
Johannes Bergaff89a92009-07-01 21:26:51 +02008760#ifdef CONFIG_NL80211_TESTMODE
Johannes Bergaff89a92009-07-01 21:26:51 +02008761static int nl80211_testmode_do(struct sk_buff *skb, struct genl_info *info)
8762{
Johannes Berg4c476992010-10-04 21:36:35 +02008763 struct cfg80211_registered_device *rdev = info->user_ptr[0];
David Spinadelfc73f112013-07-31 18:04:15 +03008764 struct wireless_dev *wdev =
8765 __cfg80211_wdev_from_attrs(genl_info_net(info), info->attrs);
Johannes Bergaff89a92009-07-01 21:26:51 +02008766 int err;
8767
David Spinadelfc73f112013-07-31 18:04:15 +03008768 if (!rdev->ops->testmode_cmd)
8769 return -EOPNOTSUPP;
8770
8771 if (IS_ERR(wdev)) {
8772 err = PTR_ERR(wdev);
8773 if (err != -EINVAL)
8774 return err;
8775 wdev = NULL;
8776 } else if (wdev->wiphy != &rdev->wiphy) {
8777 return -EINVAL;
8778 }
8779
Johannes Bergaff89a92009-07-01 21:26:51 +02008780 if (!info->attrs[NL80211_ATTR_TESTDATA])
8781 return -EINVAL;
8782
Johannes Bergad7e7182013-11-13 13:37:47 +01008783 rdev->cur_cmd_info = info;
David Spinadelfc73f112013-07-31 18:04:15 +03008784 err = rdev_testmode_cmd(rdev, wdev,
Johannes Bergaff89a92009-07-01 21:26:51 +02008785 nla_data(info->attrs[NL80211_ATTR_TESTDATA]),
8786 nla_len(info->attrs[NL80211_ATTR_TESTDATA]));
Johannes Bergad7e7182013-11-13 13:37:47 +01008787 rdev->cur_cmd_info = NULL;
Johannes Bergaff89a92009-07-01 21:26:51 +02008788
Johannes Bergaff89a92009-07-01 21:26:51 +02008789 return err;
8790}
8791
Wey-Yi Guy71063f02011-05-20 09:05:54 -07008792static int nl80211_testmode_dump(struct sk_buff *skb,
8793 struct netlink_callback *cb)
8794{
Johannes Berg00918d32011-12-13 17:22:05 +01008795 struct cfg80211_registered_device *rdev;
Wey-Yi Guy71063f02011-05-20 09:05:54 -07008796 int err;
8797 long phy_idx;
8798 void *data = NULL;
8799 int data_len = 0;
8800
Johannes Berg5fe231e2013-05-08 21:45:15 +02008801 rtnl_lock();
8802
Wey-Yi Guy71063f02011-05-20 09:05:54 -07008803 if (cb->args[0]) {
8804 /*
8805 * 0 is a valid index, but not valid for args[0],
8806 * so we need to offset by 1.
8807 */
8808 phy_idx = cb->args[0] - 1;
Luca Coelhoa4956dc2017-02-07 22:13:56 +02008809
8810 rdev = cfg80211_rdev_by_wiphy_idx(phy_idx);
8811 if (!rdev) {
8812 err = -ENOENT;
8813 goto out_err;
8814 }
Wey-Yi Guy71063f02011-05-20 09:05:54 -07008815 } else {
Johannes Bergc90c39d2016-10-24 14:40:01 +02008816 struct nlattr **attrbuf = genl_family_attrbuf(&nl80211_fam);
8817
Wey-Yi Guy71063f02011-05-20 09:05:54 -07008818 err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize,
Johannes Bergfceb6432017-04-12 14:34:07 +02008819 attrbuf, nl80211_fam.maxattr,
8820 nl80211_policy, NULL);
Wey-Yi Guy71063f02011-05-20 09:05:54 -07008821 if (err)
Johannes Berg5fe231e2013-05-08 21:45:15 +02008822 goto out_err;
Johannes Berg00918d32011-12-13 17:22:05 +01008823
Johannes Bergc90c39d2016-10-24 14:40:01 +02008824 rdev = __cfg80211_rdev_from_attrs(sock_net(skb->sk), attrbuf);
Johannes Berg2bd7e352012-06-15 14:23:16 +02008825 if (IS_ERR(rdev)) {
Johannes Berg5fe231e2013-05-08 21:45:15 +02008826 err = PTR_ERR(rdev);
8827 goto out_err;
Johannes Berg00918d32011-12-13 17:22:05 +01008828 }
Johannes Berg2bd7e352012-06-15 14:23:16 +02008829 phy_idx = rdev->wiphy_idx;
Johannes Berg2bd7e352012-06-15 14:23:16 +02008830
Johannes Bergc90c39d2016-10-24 14:40:01 +02008831 if (attrbuf[NL80211_ATTR_TESTDATA])
8832 cb->args[1] = (long)attrbuf[NL80211_ATTR_TESTDATA];
Wey-Yi Guy71063f02011-05-20 09:05:54 -07008833 }
8834
8835 if (cb->args[1]) {
8836 data = nla_data((void *)cb->args[1]);
8837 data_len = nla_len((void *)cb->args[1]);
8838 }
8839
Johannes Berg00918d32011-12-13 17:22:05 +01008840 if (!rdev->ops->testmode_dump) {
Wey-Yi Guy71063f02011-05-20 09:05:54 -07008841 err = -EOPNOTSUPP;
8842 goto out_err;
8843 }
8844
8845 while (1) {
Eric W. Biederman15e47302012-09-07 20:12:54 +00008846 void *hdr = nl80211hdr_put(skb, NETLINK_CB(cb->skb).portid,
Wey-Yi Guy71063f02011-05-20 09:05:54 -07008847 cb->nlh->nlmsg_seq, NLM_F_MULTI,
8848 NL80211_CMD_TESTMODE);
8849 struct nlattr *tmdata;
8850
Dan Carpentercb35fba2013-08-14 14:50:01 +03008851 if (!hdr)
8852 break;
8853
David S. Miller9360ffd2012-03-29 04:41:26 -04008854 if (nla_put_u32(skb, NL80211_ATTR_WIPHY, phy_idx)) {
Wey-Yi Guy71063f02011-05-20 09:05:54 -07008855 genlmsg_cancel(skb, hdr);
8856 break;
8857 }
8858
8859 tmdata = nla_nest_start(skb, NL80211_ATTR_TESTDATA);
8860 if (!tmdata) {
8861 genlmsg_cancel(skb, hdr);
8862 break;
8863 }
Hila Gonene35e4d22012-06-27 17:19:42 +03008864 err = rdev_testmode_dump(rdev, skb, cb, data, data_len);
Wey-Yi Guy71063f02011-05-20 09:05:54 -07008865 nla_nest_end(skb, tmdata);
8866
8867 if (err == -ENOBUFS || err == -ENOENT) {
8868 genlmsg_cancel(skb, hdr);
8869 break;
8870 } else if (err) {
8871 genlmsg_cancel(skb, hdr);
8872 goto out_err;
8873 }
8874
8875 genlmsg_end(skb, hdr);
8876 }
8877
8878 err = skb->len;
8879 /* see above */
8880 cb->args[0] = phy_idx + 1;
8881 out_err:
Johannes Berg5fe231e2013-05-08 21:45:15 +02008882 rtnl_unlock();
Wey-Yi Guy71063f02011-05-20 09:05:54 -07008883 return err;
8884}
Johannes Bergaff89a92009-07-01 21:26:51 +02008885#endif
8886
Samuel Ortizb23aa672009-07-01 21:26:54 +02008887static int nl80211_connect(struct sk_buff *skb, struct genl_info *info)
8888{
Johannes Berg4c476992010-10-04 21:36:35 +02008889 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8890 struct net_device *dev = info->user_ptr[1];
Samuel Ortizb23aa672009-07-01 21:26:54 +02008891 struct cfg80211_connect_params connect;
8892 struct wiphy *wiphy;
Johannes Bergfffd0932009-07-08 14:22:54 +02008893 struct cfg80211_cached_keys *connkeys = NULL;
Samuel Ortizb23aa672009-07-01 21:26:54 +02008894 int err;
8895
8896 memset(&connect, 0, sizeof(connect));
8897
8898 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
8899 return -EINVAL;
8900
8901 if (!info->attrs[NL80211_ATTR_SSID] ||
8902 !nla_len(info->attrs[NL80211_ATTR_SSID]))
8903 return -EINVAL;
8904
8905 if (info->attrs[NL80211_ATTR_AUTH_TYPE]) {
8906 connect.auth_type =
8907 nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]);
Jouni Malinene39e5b52012-09-30 19:29:39 +03008908 if (!nl80211_valid_auth_type(rdev, connect.auth_type,
8909 NL80211_CMD_CONNECT))
Samuel Ortizb23aa672009-07-01 21:26:54 +02008910 return -EINVAL;
8911 } else
8912 connect.auth_type = NL80211_AUTHTYPE_AUTOMATIC;
8913
8914 connect.privacy = info->attrs[NL80211_ATTR_PRIVACY];
8915
Avraham Stern3a00df52017-06-09 13:08:43 +01008916 if (info->attrs[NL80211_ATTR_WANT_1X_4WAY_HS] &&
8917 !wiphy_ext_feature_isset(&rdev->wiphy,
8918 NL80211_EXT_FEATURE_4WAY_HANDSHAKE_STA_1X))
8919 return -EINVAL;
8920 connect.want_1x = info->attrs[NL80211_ATTR_WANT_1X_4WAY_HS];
8921
Johannes Bergc0692b82010-08-27 14:26:53 +03008922 err = nl80211_crypto_settings(rdev, info, &connect.crypto,
Johannes Berg3dc27d22009-07-02 21:36:37 +02008923 NL80211_MAX_NR_CIPHER_SUITES);
Samuel Ortizb23aa672009-07-01 21:26:54 +02008924 if (err)
8925 return err;
Samuel Ortizb23aa672009-07-01 21:26:54 +02008926
Johannes Berg074ac8d2010-09-16 14:58:22 +02008927 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02008928 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
8929 return -EOPNOTSUPP;
Samuel Ortizb23aa672009-07-01 21:26:54 +02008930
Johannes Berg79c97e92009-07-07 03:56:12 +02008931 wiphy = &rdev->wiphy;
Samuel Ortizb23aa672009-07-01 21:26:54 +02008932
Bala Shanmugam4486ea92012-03-07 17:27:12 +05308933 connect.bg_scan_period = -1;
8934 if (info->attrs[NL80211_ATTR_BG_SCAN_PERIOD] &&
8935 (wiphy->flags & WIPHY_FLAG_SUPPORTS_FW_ROAM)) {
8936 connect.bg_scan_period =
8937 nla_get_u16(info->attrs[NL80211_ATTR_BG_SCAN_PERIOD]);
8938 }
8939
Samuel Ortizb23aa672009-07-01 21:26:54 +02008940 if (info->attrs[NL80211_ATTR_MAC])
8941 connect.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen1df4a512014-01-15 00:00:47 +02008942 else if (info->attrs[NL80211_ATTR_MAC_HINT])
8943 connect.bssid_hint =
8944 nla_data(info->attrs[NL80211_ATTR_MAC_HINT]);
Samuel Ortizb23aa672009-07-01 21:26:54 +02008945 connect.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
8946 connect.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
8947
8948 if (info->attrs[NL80211_ATTR_IE]) {
8949 connect.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
8950 connect.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
8951 }
8952
Jouni Malinencee00a92013-01-15 17:15:57 +02008953 if (info->attrs[NL80211_ATTR_USE_MFP]) {
8954 connect.mfp = nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]);
Emmanuel Grumbach65026002017-08-18 15:31:41 +03008955 if (connect.mfp == NL80211_MFP_OPTIONAL &&
8956 !wiphy_ext_feature_isset(&rdev->wiphy,
8957 NL80211_EXT_FEATURE_MFP_OPTIONAL))
8958 return -EOPNOTSUPP;
8959
Jouni Malinencee00a92013-01-15 17:15:57 +02008960 if (connect.mfp != NL80211_MFP_REQUIRED &&
Emmanuel Grumbach65026002017-08-18 15:31:41 +03008961 connect.mfp != NL80211_MFP_NO &&
8962 connect.mfp != NL80211_MFP_OPTIONAL)
Jouni Malinencee00a92013-01-15 17:15:57 +02008963 return -EINVAL;
8964 } else {
8965 connect.mfp = NL80211_MFP_NO;
8966 }
8967
Jouni Malinenba6fbac2016-03-29 13:53:27 +03008968 if (info->attrs[NL80211_ATTR_PREV_BSSID])
8969 connect.prev_bssid =
8970 nla_data(info->attrs[NL80211_ATTR_PREV_BSSID]);
8971
Samuel Ortizb23aa672009-07-01 21:26:54 +02008972 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
Jouni Malinen664834d2014-01-15 00:01:44 +02008973 connect.channel = nl80211_get_valid_chan(
8974 wiphy, info->attrs[NL80211_ATTR_WIPHY_FREQ]);
8975 if (!connect.channel)
Johannes Berg4c476992010-10-04 21:36:35 +02008976 return -EINVAL;
Jouni Malinen1df4a512014-01-15 00:00:47 +02008977 } else if (info->attrs[NL80211_ATTR_WIPHY_FREQ_HINT]) {
Jouni Malinen664834d2014-01-15 00:01:44 +02008978 connect.channel_hint = nl80211_get_valid_chan(
8979 wiphy, info->attrs[NL80211_ATTR_WIPHY_FREQ_HINT]);
8980 if (!connect.channel_hint)
Jouni Malinen1df4a512014-01-15 00:00:47 +02008981 return -EINVAL;
Samuel Ortizb23aa672009-07-01 21:26:54 +02008982 }
8983
Johannes Bergfffd0932009-07-08 14:22:54 +02008984 if (connect.privacy && info->attrs[NL80211_ATTR_KEYS]) {
8985 connkeys = nl80211_parse_connkeys(rdev,
Sujith Manoharande7044e2012-10-18 10:19:28 +05308986 info->attrs[NL80211_ATTR_KEYS], NULL);
Johannes Berg4c476992010-10-04 21:36:35 +02008987 if (IS_ERR(connkeys))
8988 return PTR_ERR(connkeys);
Johannes Bergfffd0932009-07-08 14:22:54 +02008989 }
8990
Ben Greear7e7c8922011-11-18 11:31:59 -08008991 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT]))
8992 connect.flags |= ASSOC_REQ_DISABLE_HT;
8993
8994 if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
8995 memcpy(&connect.ht_capa_mask,
8996 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]),
8997 sizeof(connect.ht_capa_mask));
8998
8999 if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) {
Wei Yongjunb4e4f472012-09-02 21:41:04 +08009000 if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) {
Johannes Bergb47f6102014-09-10 13:39:54 +03009001 kzfree(connkeys);
Ben Greear7e7c8922011-11-18 11:31:59 -08009002 return -EINVAL;
Wei Yongjunb4e4f472012-09-02 21:41:04 +08009003 }
Ben Greear7e7c8922011-11-18 11:31:59 -08009004 memcpy(&connect.ht_capa,
9005 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]),
9006 sizeof(connect.ht_capa));
9007 }
9008
Johannes Bergee2aca32013-02-21 17:36:01 +01009009 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_VHT]))
9010 connect.flags |= ASSOC_REQ_DISABLE_VHT;
9011
9012 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK])
9013 memcpy(&connect.vht_capa_mask,
9014 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]),
9015 sizeof(connect.vht_capa_mask));
9016
9017 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) {
9018 if (!info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) {
Johannes Bergb47f6102014-09-10 13:39:54 +03009019 kzfree(connkeys);
Johannes Bergee2aca32013-02-21 17:36:01 +01009020 return -EINVAL;
9021 }
9022 memcpy(&connect.vht_capa,
9023 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]),
9024 sizeof(connect.vht_capa));
9025 }
9026
Assaf Kraussbab5ab72014-09-03 15:25:01 +03009027 if (nla_get_flag(info->attrs[NL80211_ATTR_USE_RRM])) {
Beni Lev0c9ca112016-02-17 20:30:00 +02009028 if (!((rdev->wiphy.features &
9029 NL80211_FEATURE_DS_PARAM_SET_IE_IN_PROBES) &&
9030 (rdev->wiphy.features & NL80211_FEATURE_QUIET)) &&
9031 !wiphy_ext_feature_isset(&rdev->wiphy,
9032 NL80211_EXT_FEATURE_RRM)) {
Ola Olsson707554b2015-12-11 21:04:52 +01009033 kzfree(connkeys);
Assaf Kraussbab5ab72014-09-03 15:25:01 +03009034 return -EINVAL;
Ola Olsson707554b2015-12-11 21:04:52 +01009035 }
Assaf Kraussbab5ab72014-09-03 15:25:01 +03009036 connect.flags |= ASSOC_REQ_USE_RRM;
9037 }
9038
Lior David34d50512016-01-28 10:58:25 +02009039 connect.pbss = nla_get_flag(info->attrs[NL80211_ATTR_PBSS]);
Johannes Berg57fbcce2016-04-12 15:56:15 +02009040 if (connect.pbss && !rdev->wiphy.bands[NL80211_BAND_60GHZ]) {
Lior David34d50512016-01-28 10:58:25 +02009041 kzfree(connkeys);
9042 return -EOPNOTSUPP;
9043 }
9044
Arend van Spriel38de03d2016-03-02 20:37:18 +01009045 if (info->attrs[NL80211_ATTR_BSS_SELECT]) {
9046 /* bss selection makes no sense if bssid is set */
9047 if (connect.bssid) {
9048 kzfree(connkeys);
9049 return -EINVAL;
9050 }
9051
9052 err = parse_bss_select(info->attrs[NL80211_ATTR_BSS_SELECT],
9053 wiphy, &connect.bss_select);
9054 if (err) {
9055 kzfree(connkeys);
9056 return err;
9057 }
9058 }
9059
Vidyullatha Kanchanapallya3caf742017-03-31 00:22:34 +03009060 if (wiphy_ext_feature_isset(&rdev->wiphy,
9061 NL80211_EXT_FEATURE_FILS_SK_OFFLOAD) &&
9062 info->attrs[NL80211_ATTR_FILS_ERP_USERNAME] &&
9063 info->attrs[NL80211_ATTR_FILS_ERP_REALM] &&
9064 info->attrs[NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM] &&
9065 info->attrs[NL80211_ATTR_FILS_ERP_RRK]) {
9066 connect.fils_erp_username =
9067 nla_data(info->attrs[NL80211_ATTR_FILS_ERP_USERNAME]);
9068 connect.fils_erp_username_len =
9069 nla_len(info->attrs[NL80211_ATTR_FILS_ERP_USERNAME]);
9070 connect.fils_erp_realm =
9071 nla_data(info->attrs[NL80211_ATTR_FILS_ERP_REALM]);
9072 connect.fils_erp_realm_len =
9073 nla_len(info->attrs[NL80211_ATTR_FILS_ERP_REALM]);
9074 connect.fils_erp_next_seq_num =
9075 nla_get_u16(
9076 info->attrs[NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM]);
9077 connect.fils_erp_rrk =
9078 nla_data(info->attrs[NL80211_ATTR_FILS_ERP_RRK]);
9079 connect.fils_erp_rrk_len =
9080 nla_len(info->attrs[NL80211_ATTR_FILS_ERP_RRK]);
9081 } else if (info->attrs[NL80211_ATTR_FILS_ERP_USERNAME] ||
9082 info->attrs[NL80211_ATTR_FILS_ERP_REALM] ||
9083 info->attrs[NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM] ||
9084 info->attrs[NL80211_ATTR_FILS_ERP_RRK]) {
9085 kzfree(connkeys);
9086 return -EINVAL;
9087 }
9088
Johannes Berg83739b02013-05-15 17:44:01 +02009089 wdev_lock(dev->ieee80211_ptr);
Andrzej Zaborowskibd2522b2017-01-06 16:33:43 -05009090
Jouni Malinen4ce2bd92016-03-29 13:53:28 +03009091 err = cfg80211_connect(rdev, dev, &connect, connkeys,
9092 connect.prev_bssid);
Johannes Bergfffd0932009-07-08 14:22:54 +02009093 if (err)
Johannes Bergb47f6102014-09-10 13:39:54 +03009094 kzfree(connkeys);
Andrzej Zaborowskibd2522b2017-01-06 16:33:43 -05009095
9096 if (!err && info->attrs[NL80211_ATTR_SOCKET_OWNER]) {
9097 dev->ieee80211_ptr->conn_owner_nlportid = info->snd_portid;
9098 if (connect.bssid)
9099 memcpy(dev->ieee80211_ptr->disconnect_bssid,
9100 connect.bssid, ETH_ALEN);
9101 else
9102 memset(dev->ieee80211_ptr->disconnect_bssid,
9103 0, ETH_ALEN);
9104 }
9105
9106 wdev_unlock(dev->ieee80211_ptr);
9107
Samuel Ortizb23aa672009-07-01 21:26:54 +02009108 return err;
9109}
9110
vamsi krishna088e8df2016-10-27 16:51:11 +03009111static int nl80211_update_connect_params(struct sk_buff *skb,
9112 struct genl_info *info)
9113{
9114 struct cfg80211_connect_params connect = {};
9115 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9116 struct net_device *dev = info->user_ptr[1];
9117 struct wireless_dev *wdev = dev->ieee80211_ptr;
9118 u32 changed = 0;
9119 int ret;
9120
9121 if (!rdev->ops->update_connect_params)
9122 return -EOPNOTSUPP;
9123
9124 if (info->attrs[NL80211_ATTR_IE]) {
9125 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
9126 return -EINVAL;
9127 connect.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
9128 connect.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
9129 changed |= UPDATE_ASSOC_IES;
9130 }
9131
9132 wdev_lock(dev->ieee80211_ptr);
9133 if (!wdev->current_bss)
9134 ret = -ENOLINK;
9135 else
9136 ret = rdev_update_connect_params(rdev, dev, &connect, changed);
9137 wdev_unlock(dev->ieee80211_ptr);
9138
9139 return ret;
9140}
9141
Samuel Ortizb23aa672009-07-01 21:26:54 +02009142static int nl80211_disconnect(struct sk_buff *skb, struct genl_info *info)
9143{
Johannes Berg4c476992010-10-04 21:36:35 +02009144 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9145 struct net_device *dev = info->user_ptr[1];
Samuel Ortizb23aa672009-07-01 21:26:54 +02009146 u16 reason;
Johannes Berg83739b02013-05-15 17:44:01 +02009147 int ret;
Samuel Ortizb23aa672009-07-01 21:26:54 +02009148
9149 if (!info->attrs[NL80211_ATTR_REASON_CODE])
9150 reason = WLAN_REASON_DEAUTH_LEAVING;
9151 else
9152 reason = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
9153
9154 if (reason == 0)
9155 return -EINVAL;
9156
Johannes Berg074ac8d2010-09-16 14:58:22 +02009157 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02009158 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
9159 return -EOPNOTSUPP;
Samuel Ortizb23aa672009-07-01 21:26:54 +02009160
Johannes Berg83739b02013-05-15 17:44:01 +02009161 wdev_lock(dev->ieee80211_ptr);
9162 ret = cfg80211_disconnect(rdev, dev, reason, true);
9163 wdev_unlock(dev->ieee80211_ptr);
9164 return ret;
Samuel Ortizb23aa672009-07-01 21:26:54 +02009165}
9166
Johannes Berg463d0182009-07-14 00:33:35 +02009167static int nl80211_wiphy_netns(struct sk_buff *skb, struct genl_info *info)
9168{
Johannes Berg4c476992010-10-04 21:36:35 +02009169 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg463d0182009-07-14 00:33:35 +02009170 struct net *net;
9171 int err;
Johannes Berg463d0182009-07-14 00:33:35 +02009172
Vadim Kochan4b681c82015-01-12 16:34:05 +02009173 if (info->attrs[NL80211_ATTR_PID]) {
9174 u32 pid = nla_get_u32(info->attrs[NL80211_ATTR_PID]);
9175
9176 net = get_net_ns_by_pid(pid);
9177 } else if (info->attrs[NL80211_ATTR_NETNS_FD]) {
9178 u32 fd = nla_get_u32(info->attrs[NL80211_ATTR_NETNS_FD]);
9179
9180 net = get_net_ns_by_fd(fd);
9181 } else {
Johannes Berg463d0182009-07-14 00:33:35 +02009182 return -EINVAL;
Vadim Kochan4b681c82015-01-12 16:34:05 +02009183 }
Johannes Berg463d0182009-07-14 00:33:35 +02009184
Johannes Berg4c476992010-10-04 21:36:35 +02009185 if (IS_ERR(net))
9186 return PTR_ERR(net);
Johannes Berg463d0182009-07-14 00:33:35 +02009187
9188 err = 0;
9189
9190 /* check if anything to do */
Johannes Berg4c476992010-10-04 21:36:35 +02009191 if (!net_eq(wiphy_net(&rdev->wiphy), net))
9192 err = cfg80211_switch_netns(rdev, net);
Johannes Berg463d0182009-07-14 00:33:35 +02009193
Johannes Berg463d0182009-07-14 00:33:35 +02009194 put_net(net);
Johannes Berg463d0182009-07-14 00:33:35 +02009195 return err;
9196}
9197
Samuel Ortiz67fbb162009-11-24 23:59:15 +01009198static int nl80211_setdel_pmksa(struct sk_buff *skb, struct genl_info *info)
9199{
Johannes Berg4c476992010-10-04 21:36:35 +02009200 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Samuel Ortiz67fbb162009-11-24 23:59:15 +01009201 int (*rdev_ops)(struct wiphy *wiphy, struct net_device *dev,
9202 struct cfg80211_pmksa *pmksa) = NULL;
Johannes Berg4c476992010-10-04 21:36:35 +02009203 struct net_device *dev = info->user_ptr[1];
Samuel Ortiz67fbb162009-11-24 23:59:15 +01009204 struct cfg80211_pmksa pmksa;
9205
9206 memset(&pmksa, 0, sizeof(struct cfg80211_pmksa));
9207
Samuel Ortiz67fbb162009-11-24 23:59:15 +01009208 if (!info->attrs[NL80211_ATTR_PMKID])
9209 return -EINVAL;
9210
Samuel Ortiz67fbb162009-11-24 23:59:15 +01009211 pmksa.pmkid = nla_data(info->attrs[NL80211_ATTR_PMKID]);
Vidyullatha Kanchanapallya3caf742017-03-31 00:22:34 +03009212
9213 if (info->attrs[NL80211_ATTR_MAC]) {
9214 pmksa.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
9215 } else if (info->attrs[NL80211_ATTR_SSID] &&
9216 info->attrs[NL80211_ATTR_FILS_CACHE_ID] &&
9217 (info->genlhdr->cmd == NL80211_CMD_DEL_PMKSA ||
9218 info->attrs[NL80211_ATTR_PMK])) {
9219 pmksa.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
9220 pmksa.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
9221 pmksa.cache_id =
9222 nla_data(info->attrs[NL80211_ATTR_FILS_CACHE_ID]);
9223 } else {
9224 return -EINVAL;
9225 }
9226 if (info->attrs[NL80211_ATTR_PMK]) {
9227 pmksa.pmk = nla_data(info->attrs[NL80211_ATTR_PMK]);
9228 pmksa.pmk_len = nla_len(info->attrs[NL80211_ATTR_PMK]);
9229 }
Samuel Ortiz67fbb162009-11-24 23:59:15 +01009230
Johannes Berg074ac8d2010-09-16 14:58:22 +02009231 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02009232 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
9233 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01009234
9235 switch (info->genlhdr->cmd) {
9236 case NL80211_CMD_SET_PMKSA:
9237 rdev_ops = rdev->ops->set_pmksa;
9238 break;
9239 case NL80211_CMD_DEL_PMKSA:
9240 rdev_ops = rdev->ops->del_pmksa;
9241 break;
9242 default:
9243 WARN_ON(1);
9244 break;
9245 }
9246
Johannes Berg4c476992010-10-04 21:36:35 +02009247 if (!rdev_ops)
9248 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01009249
Johannes Berg4c476992010-10-04 21:36:35 +02009250 return rdev_ops(&rdev->wiphy, dev, &pmksa);
Samuel Ortiz67fbb162009-11-24 23:59:15 +01009251}
9252
9253static int nl80211_flush_pmksa(struct sk_buff *skb, struct genl_info *info)
9254{
Johannes Berg4c476992010-10-04 21:36:35 +02009255 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9256 struct net_device *dev = info->user_ptr[1];
Samuel Ortiz67fbb162009-11-24 23:59:15 +01009257
Johannes Berg074ac8d2010-09-16 14:58:22 +02009258 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02009259 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
9260 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01009261
Johannes Berg4c476992010-10-04 21:36:35 +02009262 if (!rdev->ops->flush_pmksa)
9263 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01009264
Hila Gonene35e4d22012-06-27 17:19:42 +03009265 return rdev_flush_pmksa(rdev, dev);
Samuel Ortiz67fbb162009-11-24 23:59:15 +01009266}
9267
Arik Nemtsov109086c2011-09-28 14:12:50 +03009268static int nl80211_tdls_mgmt(struct sk_buff *skb, struct genl_info *info)
9269{
9270 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9271 struct net_device *dev = info->user_ptr[1];
9272 u8 action_code, dialog_token;
Sunil Dutt Undekaridf942e72014-02-20 16:22:09 +05309273 u32 peer_capability = 0;
Arik Nemtsov109086c2011-09-28 14:12:50 +03009274 u16 status_code;
9275 u8 *peer;
Arik Nemtsov31fa97c2014-06-11 17:18:21 +03009276 bool initiator;
Arik Nemtsov109086c2011-09-28 14:12:50 +03009277
9278 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) ||
9279 !rdev->ops->tdls_mgmt)
9280 return -EOPNOTSUPP;
9281
9282 if (!info->attrs[NL80211_ATTR_TDLS_ACTION] ||
9283 !info->attrs[NL80211_ATTR_STATUS_CODE] ||
9284 !info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN] ||
9285 !info->attrs[NL80211_ATTR_IE] ||
9286 !info->attrs[NL80211_ATTR_MAC])
9287 return -EINVAL;
9288
9289 peer = nla_data(info->attrs[NL80211_ATTR_MAC]);
9290 action_code = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_ACTION]);
9291 status_code = nla_get_u16(info->attrs[NL80211_ATTR_STATUS_CODE]);
9292 dialog_token = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN]);
Arik Nemtsov31fa97c2014-06-11 17:18:21 +03009293 initiator = nla_get_flag(info->attrs[NL80211_ATTR_TDLS_INITIATOR]);
Sunil Dutt Undekaridf942e72014-02-20 16:22:09 +05309294 if (info->attrs[NL80211_ATTR_TDLS_PEER_CAPABILITY])
9295 peer_capability =
9296 nla_get_u32(info->attrs[NL80211_ATTR_TDLS_PEER_CAPABILITY]);
Arik Nemtsov109086c2011-09-28 14:12:50 +03009297
Hila Gonene35e4d22012-06-27 17:19:42 +03009298 return rdev_tdls_mgmt(rdev, dev, peer, action_code,
Sunil Dutt Undekaridf942e72014-02-20 16:22:09 +05309299 dialog_token, status_code, peer_capability,
Arik Nemtsov31fa97c2014-06-11 17:18:21 +03009300 initiator,
Hila Gonene35e4d22012-06-27 17:19:42 +03009301 nla_data(info->attrs[NL80211_ATTR_IE]),
9302 nla_len(info->attrs[NL80211_ATTR_IE]));
Arik Nemtsov109086c2011-09-28 14:12:50 +03009303}
9304
9305static int nl80211_tdls_oper(struct sk_buff *skb, struct genl_info *info)
9306{
9307 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9308 struct net_device *dev = info->user_ptr[1];
9309 enum nl80211_tdls_operation operation;
9310 u8 *peer;
9311
9312 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) ||
9313 !rdev->ops->tdls_oper)
9314 return -EOPNOTSUPP;
9315
9316 if (!info->attrs[NL80211_ATTR_TDLS_OPERATION] ||
9317 !info->attrs[NL80211_ATTR_MAC])
9318 return -EINVAL;
9319
9320 operation = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_OPERATION]);
9321 peer = nla_data(info->attrs[NL80211_ATTR_MAC]);
9322
Hila Gonene35e4d22012-06-27 17:19:42 +03009323 return rdev_tdls_oper(rdev, dev, peer, operation);
Arik Nemtsov109086c2011-09-28 14:12:50 +03009324}
9325
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009326static int nl80211_remain_on_channel(struct sk_buff *skb,
9327 struct genl_info *info)
9328{
Johannes Berg4c476992010-10-04 21:36:35 +02009329 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02009330 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg683b6d32012-11-08 21:25:48 +01009331 struct cfg80211_chan_def chandef;
Vasanthakumar Thiagarajan34373d12017-02-27 17:04:34 +05309332 const struct cfg80211_chan_def *compat_chandef;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009333 struct sk_buff *msg;
9334 void *hdr;
9335 u64 cookie;
Johannes Berg683b6d32012-11-08 21:25:48 +01009336 u32 duration;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009337 int err;
9338
9339 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] ||
9340 !info->attrs[NL80211_ATTR_DURATION])
9341 return -EINVAL;
9342
9343 duration = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]);
9344
Johannes Berg7c4ef712011-11-18 15:33:48 +01009345 if (!rdev->ops->remain_on_channel ||
9346 !(rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL))
Johannes Berg4c476992010-10-04 21:36:35 +02009347 return -EOPNOTSUPP;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009348
Johannes Bergebf348f2012-06-01 12:50:54 +02009349 /*
9350 * We should be on that channel for at least a minimum amount of
9351 * time (10ms) but no longer than the driver supports.
9352 */
9353 if (duration < NL80211_MIN_REMAIN_ON_CHANNEL_TIME ||
9354 duration > rdev->wiphy.max_remain_on_channel_duration)
9355 return -EINVAL;
9356
Johannes Berg683b6d32012-11-08 21:25:48 +01009357 err = nl80211_parse_chandef(rdev, info, &chandef);
9358 if (err)
9359 return err;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009360
Vasanthakumar Thiagarajan34373d12017-02-27 17:04:34 +05309361 wdev_lock(wdev);
9362 if (!cfg80211_off_channel_oper_allowed(wdev) &&
9363 !cfg80211_chandef_identical(&wdev->chandef, &chandef)) {
9364 compat_chandef = cfg80211_chandef_compatible(&wdev->chandef,
9365 &chandef);
9366 if (compat_chandef != &chandef) {
9367 wdev_unlock(wdev);
9368 return -EBUSY;
9369 }
9370 }
9371 wdev_unlock(wdev);
9372
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009373 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02009374 if (!msg)
9375 return -ENOMEM;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009376
Eric W. Biederman15e47302012-09-07 20:12:54 +00009377 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009378 NL80211_CMD_REMAIN_ON_CHANNEL);
Dan Carpentercb35fba2013-08-14 14:50:01 +03009379 if (!hdr) {
9380 err = -ENOBUFS;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009381 goto free_msg;
9382 }
9383
Johannes Berg683b6d32012-11-08 21:25:48 +01009384 err = rdev_remain_on_channel(rdev, wdev, chandef.chan,
9385 duration, &cookie);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009386
9387 if (err)
9388 goto free_msg;
9389
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02009390 if (nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie,
9391 NL80211_ATTR_PAD))
David S. Miller9360ffd2012-03-29 04:41:26 -04009392 goto nla_put_failure;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009393
9394 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02009395
9396 return genlmsg_reply(msg, info);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009397
9398 nla_put_failure:
9399 err = -ENOBUFS;
9400 free_msg:
9401 nlmsg_free(msg);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009402 return err;
9403}
9404
9405static int nl80211_cancel_remain_on_channel(struct sk_buff *skb,
9406 struct genl_info *info)
9407{
Johannes Berg4c476992010-10-04 21:36:35 +02009408 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02009409 struct wireless_dev *wdev = info->user_ptr[1];
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009410 u64 cookie;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009411
9412 if (!info->attrs[NL80211_ATTR_COOKIE])
9413 return -EINVAL;
9414
Johannes Berg4c476992010-10-04 21:36:35 +02009415 if (!rdev->ops->cancel_remain_on_channel)
9416 return -EOPNOTSUPP;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009417
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009418 cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]);
9419
Hila Gonene35e4d22012-06-27 17:19:42 +03009420 return rdev_cancel_remain_on_channel(rdev, wdev, cookie);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009421}
9422
Jouni Malinen13ae75b2009-12-29 12:59:45 +02009423static int nl80211_set_tx_bitrate_mask(struct sk_buff *skb,
9424 struct genl_info *info)
9425{
Jouni Malinen13ae75b2009-12-29 12:59:45 +02009426 struct cfg80211_bitrate_mask mask;
Purushottam Kushwahaa7c7fbf2016-09-14 17:38:44 +05309427 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg4c476992010-10-04 21:36:35 +02009428 struct net_device *dev = info->user_ptr[1];
Purushottam Kushwahaa7c7fbf2016-09-14 17:38:44 +05309429 int err;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02009430
Johannes Berg4c476992010-10-04 21:36:35 +02009431 if (!rdev->ops->set_bitrate_mask)
9432 return -EOPNOTSUPP;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02009433
Purushottam Kushwahaa7c7fbf2016-09-14 17:38:44 +05309434 err = nl80211_parse_tx_bitrate_mask(info, &mask);
9435 if (err)
9436 return err;
Janusz Dziedzic78693032013-12-03 09:50:44 +01009437
Hila Gonene35e4d22012-06-27 17:19:42 +03009438 return rdev_set_bitrate_mask(rdev, dev, NULL, &mask);
Jouni Malinen13ae75b2009-12-29 12:59:45 +02009439}
9440
Johannes Berg2e161f72010-08-12 15:38:38 +02009441static int nl80211_register_mgmt(struct sk_buff *skb, struct genl_info *info)
Jouni Malinen026331c2010-02-15 12:53:10 +02009442{
Johannes Berg4c476992010-10-04 21:36:35 +02009443 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02009444 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg2e161f72010-08-12 15:38:38 +02009445 u16 frame_type = IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_ACTION;
Jouni Malinen026331c2010-02-15 12:53:10 +02009446
9447 if (!info->attrs[NL80211_ATTR_FRAME_MATCH])
9448 return -EINVAL;
9449
Johannes Berg2e161f72010-08-12 15:38:38 +02009450 if (info->attrs[NL80211_ATTR_FRAME_TYPE])
9451 frame_type = nla_get_u16(info->attrs[NL80211_ATTR_FRAME_TYPE]);
Jouni Malinen026331c2010-02-15 12:53:10 +02009452
Johannes Berg71bbc992012-06-15 15:30:18 +02009453 switch (wdev->iftype) {
9454 case NL80211_IFTYPE_STATION:
9455 case NL80211_IFTYPE_ADHOC:
9456 case NL80211_IFTYPE_P2P_CLIENT:
9457 case NL80211_IFTYPE_AP:
9458 case NL80211_IFTYPE_AP_VLAN:
9459 case NL80211_IFTYPE_MESH_POINT:
9460 case NL80211_IFTYPE_P2P_GO:
Johannes Berg98104fde2012-06-16 00:19:54 +02009461 case NL80211_IFTYPE_P2P_DEVICE:
Johannes Berg71bbc992012-06-15 15:30:18 +02009462 break;
Ayala Bekercb3b7d82016-09-20 17:31:13 +03009463 case NL80211_IFTYPE_NAN:
Johannes Berg71bbc992012-06-15 15:30:18 +02009464 default:
Johannes Berg4c476992010-10-04 21:36:35 +02009465 return -EOPNOTSUPP;
Johannes Berg71bbc992012-06-15 15:30:18 +02009466 }
Jouni Malinen026331c2010-02-15 12:53:10 +02009467
9468 /* not much point in registering if we can't reply */
Johannes Berg4c476992010-10-04 21:36:35 +02009469 if (!rdev->ops->mgmt_tx)
9470 return -EOPNOTSUPP;
Jouni Malinen026331c2010-02-15 12:53:10 +02009471
Eric W. Biederman15e47302012-09-07 20:12:54 +00009472 return cfg80211_mlme_register_mgmt(wdev, info->snd_portid, frame_type,
Jouni Malinen026331c2010-02-15 12:53:10 +02009473 nla_data(info->attrs[NL80211_ATTR_FRAME_MATCH]),
9474 nla_len(info->attrs[NL80211_ATTR_FRAME_MATCH]));
Jouni Malinen026331c2010-02-15 12:53:10 +02009475}
9476
Johannes Berg2e161f72010-08-12 15:38:38 +02009477static int nl80211_tx_mgmt(struct sk_buff *skb, struct genl_info *info)
Jouni Malinen026331c2010-02-15 12:53:10 +02009478{
Johannes Berg4c476992010-10-04 21:36:35 +02009479 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02009480 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg683b6d32012-11-08 21:25:48 +01009481 struct cfg80211_chan_def chandef;
Jouni Malinen026331c2010-02-15 12:53:10 +02009482 int err;
Johannes Bergd64d3732011-11-10 09:44:46 +01009483 void *hdr = NULL;
Jouni Malinen026331c2010-02-15 12:53:10 +02009484 u64 cookie;
Johannes Berge247bd902011-11-04 11:18:21 +01009485 struct sk_buff *msg = NULL;
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02009486 struct cfg80211_mgmt_tx_params params = {
9487 .dont_wait_for_ack =
9488 info->attrs[NL80211_ATTR_DONT_WAIT_FOR_ACK],
9489 };
Jouni Malinen026331c2010-02-15 12:53:10 +02009490
Johannes Berg683b6d32012-11-08 21:25:48 +01009491 if (!info->attrs[NL80211_ATTR_FRAME])
Jouni Malinen026331c2010-02-15 12:53:10 +02009492 return -EINVAL;
9493
Johannes Berg4c476992010-10-04 21:36:35 +02009494 if (!rdev->ops->mgmt_tx)
9495 return -EOPNOTSUPP;
Jouni Malinen026331c2010-02-15 12:53:10 +02009496
Johannes Berg71bbc992012-06-15 15:30:18 +02009497 switch (wdev->iftype) {
Antonio Quartulliea141b752013-06-11 14:20:03 +02009498 case NL80211_IFTYPE_P2P_DEVICE:
9499 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ])
9500 return -EINVAL;
Johannes Berg71bbc992012-06-15 15:30:18 +02009501 case NL80211_IFTYPE_STATION:
9502 case NL80211_IFTYPE_ADHOC:
9503 case NL80211_IFTYPE_P2P_CLIENT:
9504 case NL80211_IFTYPE_AP:
9505 case NL80211_IFTYPE_AP_VLAN:
9506 case NL80211_IFTYPE_MESH_POINT:
9507 case NL80211_IFTYPE_P2P_GO:
9508 break;
Ayala Bekercb3b7d82016-09-20 17:31:13 +03009509 case NL80211_IFTYPE_NAN:
Johannes Berg71bbc992012-06-15 15:30:18 +02009510 default:
Johannes Berg4c476992010-10-04 21:36:35 +02009511 return -EOPNOTSUPP;
Johannes Berg71bbc992012-06-15 15:30:18 +02009512 }
Jouni Malinen026331c2010-02-15 12:53:10 +02009513
Johannes Bergf7ca38d2010-11-25 10:02:29 +01009514 if (info->attrs[NL80211_ATTR_DURATION]) {
Johannes Berg7c4ef712011-11-18 15:33:48 +01009515 if (!(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX))
Johannes Bergf7ca38d2010-11-25 10:02:29 +01009516 return -EINVAL;
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02009517 params.wait = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]);
Johannes Bergebf348f2012-06-01 12:50:54 +02009518
9519 /*
9520 * We should wait on the channel for at least a minimum amount
9521 * of time (10ms) but no longer than the driver supports.
9522 */
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02009523 if (params.wait < NL80211_MIN_REMAIN_ON_CHANNEL_TIME ||
9524 params.wait > rdev->wiphy.max_remain_on_channel_duration)
Johannes Bergebf348f2012-06-01 12:50:54 +02009525 return -EINVAL;
Johannes Bergf7ca38d2010-11-25 10:02:29 +01009526 }
9527
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02009528 params.offchan = info->attrs[NL80211_ATTR_OFFCHANNEL_TX_OK];
Johannes Bergf7ca38d2010-11-25 10:02:29 +01009529
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02009530 if (params.offchan && !(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX))
Johannes Berg7c4ef712011-11-18 15:33:48 +01009531 return -EINVAL;
9532
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02009533 params.no_cck = nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]);
Rajkumar Manoharane9f935e2011-09-25 14:53:30 +05309534
Antonio Quartulliea141b752013-06-11 14:20:03 +02009535 /* get the channel if any has been specified, otherwise pass NULL to
9536 * the driver. The latter will use the current one
9537 */
9538 chandef.chan = NULL;
9539 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
9540 err = nl80211_parse_chandef(rdev, info, &chandef);
9541 if (err)
9542 return err;
9543 }
9544
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02009545 if (!chandef.chan && params.offchan)
Antonio Quartulliea141b752013-06-11 14:20:03 +02009546 return -EINVAL;
Jouni Malinen026331c2010-02-15 12:53:10 +02009547
Vasanthakumar Thiagarajan34373d12017-02-27 17:04:34 +05309548 wdev_lock(wdev);
9549 if (params.offchan && !cfg80211_off_channel_oper_allowed(wdev)) {
9550 wdev_unlock(wdev);
9551 return -EBUSY;
9552 }
9553 wdev_unlock(wdev);
9554
Andrei Otcheretianski34d22ce2014-05-09 14:11:44 +03009555 params.buf = nla_data(info->attrs[NL80211_ATTR_FRAME]);
9556 params.len = nla_len(info->attrs[NL80211_ATTR_FRAME]);
9557
9558 if (info->attrs[NL80211_ATTR_CSA_C_OFFSETS_TX]) {
9559 int len = nla_len(info->attrs[NL80211_ATTR_CSA_C_OFFSETS_TX]);
9560 int i;
9561
9562 if (len % sizeof(u16))
9563 return -EINVAL;
9564
9565 params.n_csa_offsets = len / sizeof(u16);
9566 params.csa_offsets =
9567 nla_data(info->attrs[NL80211_ATTR_CSA_C_OFFSETS_TX]);
9568
9569 /* check that all the offsets fit the frame */
9570 for (i = 0; i < params.n_csa_offsets; i++) {
9571 if (params.csa_offsets[i] >= params.len)
9572 return -EINVAL;
9573 }
9574 }
9575
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02009576 if (!params.dont_wait_for_ack) {
Johannes Berge247bd902011-11-04 11:18:21 +01009577 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
9578 if (!msg)
9579 return -ENOMEM;
Jouni Malinen026331c2010-02-15 12:53:10 +02009580
Eric W. Biederman15e47302012-09-07 20:12:54 +00009581 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berge247bd902011-11-04 11:18:21 +01009582 NL80211_CMD_FRAME);
Dan Carpentercb35fba2013-08-14 14:50:01 +03009583 if (!hdr) {
9584 err = -ENOBUFS;
Johannes Berge247bd902011-11-04 11:18:21 +01009585 goto free_msg;
9586 }
Jouni Malinen026331c2010-02-15 12:53:10 +02009587 }
Johannes Berge247bd902011-11-04 11:18:21 +01009588
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02009589 params.chan = chandef.chan;
9590 err = cfg80211_mlme_mgmt_tx(rdev, wdev, &params, &cookie);
Jouni Malinen026331c2010-02-15 12:53:10 +02009591 if (err)
9592 goto free_msg;
9593
Johannes Berge247bd902011-11-04 11:18:21 +01009594 if (msg) {
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02009595 if (nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie,
9596 NL80211_ATTR_PAD))
David S. Miller9360ffd2012-03-29 04:41:26 -04009597 goto nla_put_failure;
Jouni Malinen026331c2010-02-15 12:53:10 +02009598
Johannes Berge247bd902011-11-04 11:18:21 +01009599 genlmsg_end(msg, hdr);
9600 return genlmsg_reply(msg, info);
9601 }
9602
9603 return 0;
Jouni Malinen026331c2010-02-15 12:53:10 +02009604
9605 nla_put_failure:
9606 err = -ENOBUFS;
9607 free_msg:
9608 nlmsg_free(msg);
Jouni Malinen026331c2010-02-15 12:53:10 +02009609 return err;
9610}
9611
Johannes Bergf7ca38d2010-11-25 10:02:29 +01009612static int nl80211_tx_mgmt_cancel_wait(struct sk_buff *skb, struct genl_info *info)
9613{
9614 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02009615 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Bergf7ca38d2010-11-25 10:02:29 +01009616 u64 cookie;
9617
9618 if (!info->attrs[NL80211_ATTR_COOKIE])
9619 return -EINVAL;
9620
9621 if (!rdev->ops->mgmt_tx_cancel_wait)
9622 return -EOPNOTSUPP;
9623
Johannes Berg71bbc992012-06-15 15:30:18 +02009624 switch (wdev->iftype) {
9625 case NL80211_IFTYPE_STATION:
9626 case NL80211_IFTYPE_ADHOC:
9627 case NL80211_IFTYPE_P2P_CLIENT:
9628 case NL80211_IFTYPE_AP:
9629 case NL80211_IFTYPE_AP_VLAN:
9630 case NL80211_IFTYPE_P2P_GO:
Johannes Berg98104fde2012-06-16 00:19:54 +02009631 case NL80211_IFTYPE_P2P_DEVICE:
Johannes Berg71bbc992012-06-15 15:30:18 +02009632 break;
Ayala Bekercb3b7d82016-09-20 17:31:13 +03009633 case NL80211_IFTYPE_NAN:
Johannes Berg71bbc992012-06-15 15:30:18 +02009634 default:
Johannes Bergf7ca38d2010-11-25 10:02:29 +01009635 return -EOPNOTSUPP;
Johannes Berg71bbc992012-06-15 15:30:18 +02009636 }
Johannes Bergf7ca38d2010-11-25 10:02:29 +01009637
9638 cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]);
9639
Hila Gonene35e4d22012-06-27 17:19:42 +03009640 return rdev_mgmt_tx_cancel_wait(rdev, wdev, cookie);
Johannes Bergf7ca38d2010-11-25 10:02:29 +01009641}
9642
Kalle Valoffb9eb32010-02-17 17:58:10 +02009643static int nl80211_set_power_save(struct sk_buff *skb, struct genl_info *info)
9644{
Johannes Berg4c476992010-10-04 21:36:35 +02009645 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Kalle Valoffb9eb32010-02-17 17:58:10 +02009646 struct wireless_dev *wdev;
Johannes Berg4c476992010-10-04 21:36:35 +02009647 struct net_device *dev = info->user_ptr[1];
Kalle Valoffb9eb32010-02-17 17:58:10 +02009648 u8 ps_state;
9649 bool state;
9650 int err;
9651
Johannes Berg4c476992010-10-04 21:36:35 +02009652 if (!info->attrs[NL80211_ATTR_PS_STATE])
9653 return -EINVAL;
Kalle Valoffb9eb32010-02-17 17:58:10 +02009654
9655 ps_state = nla_get_u32(info->attrs[NL80211_ATTR_PS_STATE]);
9656
Johannes Berg4c476992010-10-04 21:36:35 +02009657 if (ps_state != NL80211_PS_DISABLED && ps_state != NL80211_PS_ENABLED)
9658 return -EINVAL;
Kalle Valoffb9eb32010-02-17 17:58:10 +02009659
9660 wdev = dev->ieee80211_ptr;
9661
Johannes Berg4c476992010-10-04 21:36:35 +02009662 if (!rdev->ops->set_power_mgmt)
9663 return -EOPNOTSUPP;
Kalle Valoffb9eb32010-02-17 17:58:10 +02009664
9665 state = (ps_state == NL80211_PS_ENABLED) ? true : false;
9666
9667 if (state == wdev->ps)
Johannes Berg4c476992010-10-04 21:36:35 +02009668 return 0;
Kalle Valoffb9eb32010-02-17 17:58:10 +02009669
Hila Gonene35e4d22012-06-27 17:19:42 +03009670 err = rdev_set_power_mgmt(rdev, dev, state, wdev->ps_timeout);
Johannes Berg4c476992010-10-04 21:36:35 +02009671 if (!err)
9672 wdev->ps = state;
Kalle Valoffb9eb32010-02-17 17:58:10 +02009673 return err;
9674}
9675
9676static int nl80211_get_power_save(struct sk_buff *skb, struct genl_info *info)
9677{
Johannes Berg4c476992010-10-04 21:36:35 +02009678 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Kalle Valoffb9eb32010-02-17 17:58:10 +02009679 enum nl80211_ps_state ps_state;
9680 struct wireless_dev *wdev;
Johannes Berg4c476992010-10-04 21:36:35 +02009681 struct net_device *dev = info->user_ptr[1];
Kalle Valoffb9eb32010-02-17 17:58:10 +02009682 struct sk_buff *msg;
9683 void *hdr;
9684 int err;
9685
Kalle Valoffb9eb32010-02-17 17:58:10 +02009686 wdev = dev->ieee80211_ptr;
9687
Johannes Berg4c476992010-10-04 21:36:35 +02009688 if (!rdev->ops->set_power_mgmt)
9689 return -EOPNOTSUPP;
Kalle Valoffb9eb32010-02-17 17:58:10 +02009690
9691 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02009692 if (!msg)
9693 return -ENOMEM;
Kalle Valoffb9eb32010-02-17 17:58:10 +02009694
Eric W. Biederman15e47302012-09-07 20:12:54 +00009695 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Kalle Valoffb9eb32010-02-17 17:58:10 +02009696 NL80211_CMD_GET_POWER_SAVE);
9697 if (!hdr) {
Johannes Berg4c476992010-10-04 21:36:35 +02009698 err = -ENOBUFS;
Kalle Valoffb9eb32010-02-17 17:58:10 +02009699 goto free_msg;
9700 }
9701
9702 if (wdev->ps)
9703 ps_state = NL80211_PS_ENABLED;
9704 else
9705 ps_state = NL80211_PS_DISABLED;
9706
David S. Miller9360ffd2012-03-29 04:41:26 -04009707 if (nla_put_u32(msg, NL80211_ATTR_PS_STATE, ps_state))
9708 goto nla_put_failure;
Kalle Valoffb9eb32010-02-17 17:58:10 +02009709
9710 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02009711 return genlmsg_reply(msg, info);
Kalle Valoffb9eb32010-02-17 17:58:10 +02009712
Johannes Berg4c476992010-10-04 21:36:35 +02009713 nla_put_failure:
Kalle Valoffb9eb32010-02-17 17:58:10 +02009714 err = -ENOBUFS;
Johannes Berg4c476992010-10-04 21:36:35 +02009715 free_msg:
Kalle Valoffb9eb32010-02-17 17:58:10 +02009716 nlmsg_free(msg);
Kalle Valoffb9eb32010-02-17 17:58:10 +02009717 return err;
9718}
9719
Johannes Berg94e860f2014-01-20 23:58:15 +01009720static const struct nla_policy
9721nl80211_attr_cqm_policy[NL80211_ATTR_CQM_MAX + 1] = {
Andrew Zaborowski4a4b8162017-02-10 10:02:31 +01009722 [NL80211_ATTR_CQM_RSSI_THOLD] = { .type = NLA_BINARY },
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02009723 [NL80211_ATTR_CQM_RSSI_HYST] = { .type = NLA_U32 },
9724 [NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT] = { .type = NLA_U32 },
Thomas Pedersen84f10702012-07-12 16:17:33 -07009725 [NL80211_ATTR_CQM_TXE_RATE] = { .type = NLA_U32 },
9726 [NL80211_ATTR_CQM_TXE_PKTS] = { .type = NLA_U32 },
9727 [NL80211_ATTR_CQM_TXE_INTVL] = { .type = NLA_U32 },
Andrzej Zaborowskibee427b2017-01-25 12:43:41 +01009728 [NL80211_ATTR_CQM_RSSI_LEVEL] = { .type = NLA_S32 },
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02009729};
9730
Thomas Pedersen84f10702012-07-12 16:17:33 -07009731static int nl80211_set_cqm_txe(struct genl_info *info,
Johannes Bergd9d8b012012-11-26 12:51:52 +01009732 u32 rate, u32 pkts, u32 intvl)
Thomas Pedersen84f10702012-07-12 16:17:33 -07009733{
9734 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Thomas Pedersen84f10702012-07-12 16:17:33 -07009735 struct net_device *dev = info->user_ptr[1];
Johannes Berg1da5fcc2013-08-06 14:10:48 +02009736 struct wireless_dev *wdev = dev->ieee80211_ptr;
Thomas Pedersen84f10702012-07-12 16:17:33 -07009737
Johannes Bergd9d8b012012-11-26 12:51:52 +01009738 if (rate > 100 || intvl > NL80211_CQM_TXE_MAX_INTVL)
Thomas Pedersen84f10702012-07-12 16:17:33 -07009739 return -EINVAL;
9740
Thomas Pedersen84f10702012-07-12 16:17:33 -07009741 if (!rdev->ops->set_cqm_txe_config)
9742 return -EOPNOTSUPP;
9743
9744 if (wdev->iftype != NL80211_IFTYPE_STATION &&
9745 wdev->iftype != NL80211_IFTYPE_P2P_CLIENT)
9746 return -EOPNOTSUPP;
9747
Hila Gonene35e4d22012-06-27 17:19:42 +03009748 return rdev_set_cqm_txe_config(rdev, dev, rate, pkts, intvl);
Thomas Pedersen84f10702012-07-12 16:17:33 -07009749}
9750
Andrew Zaborowski4a4b8162017-02-10 10:02:31 +01009751static int cfg80211_cqm_rssi_update(struct cfg80211_registered_device *rdev,
9752 struct net_device *dev)
9753{
9754 struct wireless_dev *wdev = dev->ieee80211_ptr;
9755 s32 last, low, high;
9756 u32 hyst;
9757 int i, n;
9758 int err;
9759
9760 /* RSSI reporting disabled? */
9761 if (!wdev->cqm_config)
9762 return rdev_set_cqm_rssi_range_config(rdev, dev, 0, 0);
9763
9764 /*
9765 * Obtain current RSSI value if possible, if not and no RSSI threshold
9766 * event has been received yet, we should receive an event after a
9767 * connection is established and enough beacons received to calculate
9768 * the average.
9769 */
9770 if (!wdev->cqm_config->last_rssi_event_value && wdev->current_bss &&
9771 rdev->ops->get_station) {
9772 struct station_info sinfo;
9773 u8 *mac_addr;
9774
9775 mac_addr = wdev->current_bss->pub.bssid;
9776
9777 err = rdev_get_station(rdev, dev, mac_addr, &sinfo);
9778 if (err)
9779 return err;
9780
9781 if (sinfo.filled & BIT(NL80211_STA_INFO_BEACON_SIGNAL_AVG))
9782 wdev->cqm_config->last_rssi_event_value =
9783 (s8) sinfo.rx_beacon_signal_avg;
9784 }
9785
9786 last = wdev->cqm_config->last_rssi_event_value;
9787 hyst = wdev->cqm_config->rssi_hyst;
9788 n = wdev->cqm_config->n_rssi_thresholds;
9789
9790 for (i = 0; i < n; i++)
9791 if (last < wdev->cqm_config->rssi_thresholds[i])
9792 break;
9793
9794 low = i > 0 ?
9795 (wdev->cqm_config->rssi_thresholds[i - 1] - hyst) : S32_MIN;
9796 high = i < n ?
9797 (wdev->cqm_config->rssi_thresholds[i] + hyst - 1) : S32_MAX;
9798
9799 return rdev_set_cqm_rssi_range_config(rdev, dev, low, high);
9800}
9801
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02009802static int nl80211_set_cqm_rssi(struct genl_info *info,
Andrew Zaborowski4a4b8162017-02-10 10:02:31 +01009803 const s32 *thresholds, int n_thresholds,
9804 u32 hysteresis)
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02009805{
Johannes Berg4c476992010-10-04 21:36:35 +02009806 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg4c476992010-10-04 21:36:35 +02009807 struct net_device *dev = info->user_ptr[1];
Johannes Berg1da5fcc2013-08-06 14:10:48 +02009808 struct wireless_dev *wdev = dev->ieee80211_ptr;
Andrew Zaborowski4a4b8162017-02-10 10:02:31 +01009809 int i, err;
9810 s32 prev = S32_MIN;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02009811
Andrew Zaborowski4a4b8162017-02-10 10:02:31 +01009812 /* Check all values negative and sorted */
9813 for (i = 0; i < n_thresholds; i++) {
9814 if (thresholds[i] > 0 || thresholds[i] <= prev)
9815 return -EINVAL;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02009816
Andrew Zaborowski4a4b8162017-02-10 10:02:31 +01009817 prev = thresholds[i];
9818 }
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02009819
Johannes Berg074ac8d2010-09-16 14:58:22 +02009820 if (wdev->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02009821 wdev->iftype != NL80211_IFTYPE_P2P_CLIENT)
9822 return -EOPNOTSUPP;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02009823
Andrew Zaborowski4a4b8162017-02-10 10:02:31 +01009824 wdev_lock(wdev);
9825 cfg80211_cqm_config_free(wdev);
9826 wdev_unlock(wdev);
9827
9828 if (n_thresholds <= 1 && rdev->ops->set_cqm_rssi_config) {
9829 if (n_thresholds == 0 || thresholds[0] == 0) /* Disabling */
9830 return rdev_set_cqm_rssi_config(rdev, dev, 0, 0);
9831
9832 return rdev_set_cqm_rssi_config(rdev, dev,
9833 thresholds[0], hysteresis);
9834 }
9835
9836 if (!wiphy_ext_feature_isset(&rdev->wiphy,
9837 NL80211_EXT_FEATURE_CQM_RSSI_LIST))
9838 return -EOPNOTSUPP;
9839
9840 if (n_thresholds == 1 && thresholds[0] == 0) /* Disabling */
9841 n_thresholds = 0;
9842
9843 wdev_lock(wdev);
9844 if (n_thresholds) {
9845 struct cfg80211_cqm_config *cqm_config;
9846
9847 cqm_config = kzalloc(sizeof(struct cfg80211_cqm_config) +
9848 n_thresholds * sizeof(s32), GFP_KERNEL);
9849 if (!cqm_config) {
9850 err = -ENOMEM;
9851 goto unlock;
9852 }
9853
9854 cqm_config->rssi_hyst = hysteresis;
9855 cqm_config->n_rssi_thresholds = n_thresholds;
9856 memcpy(cqm_config->rssi_thresholds, thresholds,
9857 n_thresholds * sizeof(s32));
9858
9859 wdev->cqm_config = cqm_config;
9860 }
9861
9862 err = cfg80211_cqm_rssi_update(rdev, dev);
9863
9864unlock:
9865 wdev_unlock(wdev);
9866
9867 return err;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02009868}
9869
9870static int nl80211_set_cqm(struct sk_buff *skb, struct genl_info *info)
9871{
9872 struct nlattr *attrs[NL80211_ATTR_CQM_MAX + 1];
9873 struct nlattr *cqm;
9874 int err;
9875
9876 cqm = info->attrs[NL80211_ATTR_CQM];
Johannes Berg1da5fcc2013-08-06 14:10:48 +02009877 if (!cqm)
9878 return -EINVAL;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02009879
9880 err = nla_parse_nested(attrs, NL80211_ATTR_CQM_MAX, cqm,
Johannes Bergfe521452017-04-12 14:34:08 +02009881 nl80211_attr_cqm_policy, info->extack);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02009882 if (err)
Johannes Berg1da5fcc2013-08-06 14:10:48 +02009883 return err;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02009884
9885 if (attrs[NL80211_ATTR_CQM_RSSI_THOLD] &&
9886 attrs[NL80211_ATTR_CQM_RSSI_HYST]) {
Andrew Zaborowski4a4b8162017-02-10 10:02:31 +01009887 const s32 *thresholds =
9888 nla_data(attrs[NL80211_ATTR_CQM_RSSI_THOLD]);
9889 int len = nla_len(attrs[NL80211_ATTR_CQM_RSSI_THOLD]);
Johannes Berg1da5fcc2013-08-06 14:10:48 +02009890 u32 hysteresis = nla_get_u32(attrs[NL80211_ATTR_CQM_RSSI_HYST]);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02009891
Andrew Zaborowski4a4b8162017-02-10 10:02:31 +01009892 if (len % 4)
9893 return -EINVAL;
9894
9895 return nl80211_set_cqm_rssi(info, thresholds, len / 4,
9896 hysteresis);
Johannes Berg1da5fcc2013-08-06 14:10:48 +02009897 }
9898
9899 if (attrs[NL80211_ATTR_CQM_TXE_RATE] &&
9900 attrs[NL80211_ATTR_CQM_TXE_PKTS] &&
9901 attrs[NL80211_ATTR_CQM_TXE_INTVL]) {
9902 u32 rate = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_RATE]);
9903 u32 pkts = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_PKTS]);
9904 u32 intvl = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_INTVL]);
9905
9906 return nl80211_set_cqm_txe(info, rate, pkts, intvl);
9907 }
9908
9909 return -EINVAL;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02009910}
9911
Rostislav Lisovy6e0bd6c2014-11-03 10:33:18 +01009912static int nl80211_join_ocb(struct sk_buff *skb, struct genl_info *info)
9913{
9914 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9915 struct net_device *dev = info->user_ptr[1];
9916 struct ocb_setup setup = {};
9917 int err;
9918
9919 err = nl80211_parse_chandef(rdev, info, &setup.chandef);
9920 if (err)
9921 return err;
9922
9923 return cfg80211_join_ocb(rdev, dev, &setup);
9924}
9925
9926static int nl80211_leave_ocb(struct sk_buff *skb, struct genl_info *info)
9927{
9928 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9929 struct net_device *dev = info->user_ptr[1];
9930
9931 return cfg80211_leave_ocb(rdev, dev);
9932}
9933
Johannes Berg29cbe682010-12-03 09:20:44 +01009934static int nl80211_join_mesh(struct sk_buff *skb, struct genl_info *info)
9935{
9936 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9937 struct net_device *dev = info->user_ptr[1];
9938 struct mesh_config cfg;
Javier Cardonac80d5452010-12-16 17:37:49 -08009939 struct mesh_setup setup;
Johannes Berg29cbe682010-12-03 09:20:44 +01009940 int err;
9941
9942 /* start with default */
9943 memcpy(&cfg, &default_mesh_config, sizeof(cfg));
Javier Cardonac80d5452010-12-16 17:37:49 -08009944 memcpy(&setup, &default_mesh_setup, sizeof(setup));
Johannes Berg29cbe682010-12-03 09:20:44 +01009945
Javier Cardona24bdd9f2010-12-16 17:37:48 -08009946 if (info->attrs[NL80211_ATTR_MESH_CONFIG]) {
Johannes Berg29cbe682010-12-03 09:20:44 +01009947 /* and parse parameters if given */
Javier Cardona24bdd9f2010-12-16 17:37:48 -08009948 err = nl80211_parse_mesh_config(info, &cfg, NULL);
Johannes Berg29cbe682010-12-03 09:20:44 +01009949 if (err)
9950 return err;
9951 }
9952
9953 if (!info->attrs[NL80211_ATTR_MESH_ID] ||
9954 !nla_len(info->attrs[NL80211_ATTR_MESH_ID]))
9955 return -EINVAL;
9956
Javier Cardonac80d5452010-12-16 17:37:49 -08009957 setup.mesh_id = nla_data(info->attrs[NL80211_ATTR_MESH_ID]);
9958 setup.mesh_id_len = nla_len(info->attrs[NL80211_ATTR_MESH_ID]);
9959
Chun-Yeow Yeoh4bb62342011-11-24 17:15:20 -08009960 if (info->attrs[NL80211_ATTR_MCAST_RATE] &&
9961 !nl80211_parse_mcast_rate(rdev, setup.mcast_rate,
9962 nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE])))
9963 return -EINVAL;
9964
Marco Porsch9bdbf042013-01-07 16:04:51 +01009965 if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) {
9966 setup.beacon_interval =
9967 nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]);
Purushottam Kushwaha12d20fc92016-08-11 15:14:02 +05309968
Purushottam Kushwaha0c317a02016-10-12 18:26:51 +05309969 err = cfg80211_validate_beacon_int(rdev,
9970 NL80211_IFTYPE_MESH_POINT,
9971 setup.beacon_interval);
Purushottam Kushwaha12d20fc92016-08-11 15:14:02 +05309972 if (err)
9973 return err;
Marco Porsch9bdbf042013-01-07 16:04:51 +01009974 }
9975
9976 if (info->attrs[NL80211_ATTR_DTIM_PERIOD]) {
9977 setup.dtim_period =
9978 nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]);
9979 if (setup.dtim_period < 1 || setup.dtim_period > 100)
9980 return -EINVAL;
9981 }
9982
Javier Cardonac80d5452010-12-16 17:37:49 -08009983 if (info->attrs[NL80211_ATTR_MESH_SETUP]) {
9984 /* parse additional setup parameters if given */
9985 err = nl80211_parse_mesh_setup(info, &setup);
9986 if (err)
9987 return err;
9988 }
9989
Thomas Pedersend37bb182013-03-04 13:06:13 -08009990 if (setup.user_mpm)
9991 cfg.auto_open_plinks = false;
9992
Johannes Bergcc1d2802012-05-16 23:50:20 +02009993 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
Johannes Berg683b6d32012-11-08 21:25:48 +01009994 err = nl80211_parse_chandef(rdev, info, &setup.chandef);
9995 if (err)
9996 return err;
Johannes Bergcc1d2802012-05-16 23:50:20 +02009997 } else {
9998 /* cfg80211_join_mesh() will sort it out */
Johannes Berg683b6d32012-11-08 21:25:48 +01009999 setup.chandef.chan = NULL;
Johannes Bergcc1d2802012-05-16 23:50:20 +020010000 }
10001
Ashok Nagarajanffb3cf32013-06-03 10:33:36 -070010002 if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) {
10003 u8 *rates = nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
10004 int n_rates =
10005 nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
10006 struct ieee80211_supported_band *sband;
10007
10008 if (!setup.chandef.chan)
10009 return -EINVAL;
10010
10011 sband = rdev->wiphy.bands[setup.chandef.chan->band];
10012
10013 err = ieee80211_get_ratemask(sband, rates, n_rates,
10014 &setup.basic_rates);
10015 if (err)
10016 return err;
10017 }
10018
Johannes Berg8564e382016-09-19 09:44:44 +020010019 if (info->attrs[NL80211_ATTR_TX_RATES]) {
10020 err = nl80211_parse_tx_bitrate_mask(info, &setup.beacon_rate);
10021 if (err)
10022 return err;
10023
10024 err = validate_beacon_tx_rate(rdev, setup.chandef.chan->band,
10025 &setup.beacon_rate);
10026 if (err)
10027 return err;
10028 }
10029
Benjamin Bergd37d49c2017-05-16 11:23:11 +020010030 setup.userspace_handles_dfs =
10031 nla_get_flag(info->attrs[NL80211_ATTR_HANDLE_DFS]);
10032
Javier Cardonac80d5452010-12-16 17:37:49 -080010033 return cfg80211_join_mesh(rdev, dev, &setup, &cfg);
Johannes Berg29cbe682010-12-03 09:20:44 +010010034}
10035
10036static int nl80211_leave_mesh(struct sk_buff *skb, struct genl_info *info)
10037{
10038 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10039 struct net_device *dev = info->user_ptr[1];
10040
10041 return cfg80211_leave_mesh(rdev, dev);
10042}
10043
Johannes Bergdfb89c52012-06-27 09:23:48 +020010044#ifdef CONFIG_PM
Amitkumar Karwarbb92d192013-02-12 12:16:26 -080010045static int nl80211_send_wowlan_patterns(struct sk_buff *msg,
10046 struct cfg80211_registered_device *rdev)
10047{
Johannes Berg6abb9cb2013-05-15 09:30:07 +020010048 struct cfg80211_wowlan *wowlan = rdev->wiphy.wowlan_config;
Amitkumar Karwarbb92d192013-02-12 12:16:26 -080010049 struct nlattr *nl_pats, *nl_pat;
10050 int i, pat_len;
10051
Johannes Berg6abb9cb2013-05-15 09:30:07 +020010052 if (!wowlan->n_patterns)
Amitkumar Karwarbb92d192013-02-12 12:16:26 -080010053 return 0;
10054
10055 nl_pats = nla_nest_start(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN);
10056 if (!nl_pats)
10057 return -ENOBUFS;
10058
Johannes Berg6abb9cb2013-05-15 09:30:07 +020010059 for (i = 0; i < wowlan->n_patterns; i++) {
Amitkumar Karwarbb92d192013-02-12 12:16:26 -080010060 nl_pat = nla_nest_start(msg, i + 1);
10061 if (!nl_pat)
10062 return -ENOBUFS;
Johannes Berg6abb9cb2013-05-15 09:30:07 +020010063 pat_len = wowlan->patterns[i].pattern_len;
Amitkumar Karwar50ac6602013-06-25 19:03:56 -070010064 if (nla_put(msg, NL80211_PKTPAT_MASK, DIV_ROUND_UP(pat_len, 8),
Johannes Berg6abb9cb2013-05-15 09:30:07 +020010065 wowlan->patterns[i].mask) ||
Amitkumar Karwar50ac6602013-06-25 19:03:56 -070010066 nla_put(msg, NL80211_PKTPAT_PATTERN, pat_len,
10067 wowlan->patterns[i].pattern) ||
10068 nla_put_u32(msg, NL80211_PKTPAT_OFFSET,
Johannes Berg6abb9cb2013-05-15 09:30:07 +020010069 wowlan->patterns[i].pkt_offset))
Amitkumar Karwarbb92d192013-02-12 12:16:26 -080010070 return -ENOBUFS;
10071 nla_nest_end(msg, nl_pat);
10072 }
10073 nla_nest_end(msg, nl_pats);
10074
10075 return 0;
10076}
10077
Johannes Berg2a0e0472013-01-23 22:57:40 +010010078static int nl80211_send_wowlan_tcp(struct sk_buff *msg,
10079 struct cfg80211_wowlan_tcp *tcp)
10080{
10081 struct nlattr *nl_tcp;
10082
10083 if (!tcp)
10084 return 0;
10085
10086 nl_tcp = nla_nest_start(msg, NL80211_WOWLAN_TRIG_TCP_CONNECTION);
10087 if (!nl_tcp)
10088 return -ENOBUFS;
10089
Jiri Benc930345e2015-03-29 16:59:25 +020010090 if (nla_put_in_addr(msg, NL80211_WOWLAN_TCP_SRC_IPV4, tcp->src) ||
10091 nla_put_in_addr(msg, NL80211_WOWLAN_TCP_DST_IPV4, tcp->dst) ||
Johannes Berg2a0e0472013-01-23 22:57:40 +010010092 nla_put(msg, NL80211_WOWLAN_TCP_DST_MAC, ETH_ALEN, tcp->dst_mac) ||
10093 nla_put_u16(msg, NL80211_WOWLAN_TCP_SRC_PORT, tcp->src_port) ||
10094 nla_put_u16(msg, NL80211_WOWLAN_TCP_DST_PORT, tcp->dst_port) ||
10095 nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD,
10096 tcp->payload_len, tcp->payload) ||
10097 nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_INTERVAL,
10098 tcp->data_interval) ||
10099 nla_put(msg, NL80211_WOWLAN_TCP_WAKE_PAYLOAD,
10100 tcp->wake_len, tcp->wake_data) ||
10101 nla_put(msg, NL80211_WOWLAN_TCP_WAKE_MASK,
10102 DIV_ROUND_UP(tcp->wake_len, 8), tcp->wake_mask))
10103 return -ENOBUFS;
10104
10105 if (tcp->payload_seq.len &&
10106 nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ,
10107 sizeof(tcp->payload_seq), &tcp->payload_seq))
10108 return -ENOBUFS;
10109
10110 if (tcp->payload_tok.len &&
10111 nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN,
10112 sizeof(tcp->payload_tok) + tcp->tokens_size,
10113 &tcp->payload_tok))
10114 return -ENOBUFS;
10115
Johannes Berge248ad32013-05-16 10:24:28 +020010116 nla_nest_end(msg, nl_tcp);
10117
Johannes Berg2a0e0472013-01-23 22:57:40 +010010118 return 0;
10119}
10120
Luciano Coelho75453cc2015-01-09 14:06:37 +020010121static int nl80211_send_wowlan_nd(struct sk_buff *msg,
10122 struct cfg80211_sched_scan_request *req)
10123{
Avraham Stern3b06d272015-10-12 09:51:34 +030010124 struct nlattr *nd, *freqs, *matches, *match, *scan_plans, *scan_plan;
Luciano Coelho75453cc2015-01-09 14:06:37 +020010125 int i;
10126
10127 if (!req)
10128 return 0;
10129
10130 nd = nla_nest_start(msg, NL80211_WOWLAN_TRIG_NET_DETECT);
10131 if (!nd)
10132 return -ENOBUFS;
10133
Avraham Stern3b06d272015-10-12 09:51:34 +030010134 if (req->n_scan_plans == 1 &&
10135 nla_put_u32(msg, NL80211_ATTR_SCHED_SCAN_INTERVAL,
10136 req->scan_plans[0].interval * 1000))
Luciano Coelho75453cc2015-01-09 14:06:37 +020010137 return -ENOBUFS;
10138
Luciano Coelho21fea562015-03-17 16:36:01 +020010139 if (nla_put_u32(msg, NL80211_ATTR_SCHED_SCAN_DELAY, req->delay))
10140 return -ENOBUFS;
10141
vamsi krishnabf95ecd2017-01-13 01:12:20 +020010142 if (req->relative_rssi_set) {
10143 struct nl80211_bss_select_rssi_adjust rssi_adjust;
10144
10145 if (nla_put_s8(msg, NL80211_ATTR_SCHED_SCAN_RELATIVE_RSSI,
10146 req->relative_rssi))
10147 return -ENOBUFS;
10148
10149 rssi_adjust.band = req->rssi_adjust.band;
10150 rssi_adjust.delta = req->rssi_adjust.delta;
10151 if (nla_put(msg, NL80211_ATTR_SCHED_SCAN_RSSI_ADJUST,
10152 sizeof(rssi_adjust), &rssi_adjust))
10153 return -ENOBUFS;
10154 }
10155
Luciano Coelho75453cc2015-01-09 14:06:37 +020010156 freqs = nla_nest_start(msg, NL80211_ATTR_SCAN_FREQUENCIES);
10157 if (!freqs)
10158 return -ENOBUFS;
10159
Johannes Berg53b18982016-09-14 09:59:21 +020010160 for (i = 0; i < req->n_channels; i++) {
10161 if (nla_put_u32(msg, i, req->channels[i]->center_freq))
10162 return -ENOBUFS;
10163 }
Luciano Coelho75453cc2015-01-09 14:06:37 +020010164
10165 nla_nest_end(msg, freqs);
10166
10167 if (req->n_match_sets) {
10168 matches = nla_nest_start(msg, NL80211_ATTR_SCHED_SCAN_MATCH);
Johannes Berg76e1fb42016-09-14 09:55:57 +020010169 if (!matches)
10170 return -ENOBUFS;
10171
Luciano Coelho75453cc2015-01-09 14:06:37 +020010172 for (i = 0; i < req->n_match_sets; i++) {
10173 match = nla_nest_start(msg, i);
Johannes Berg76e1fb42016-09-14 09:55:57 +020010174 if (!match)
10175 return -ENOBUFS;
10176
Johannes Berg53b18982016-09-14 09:59:21 +020010177 if (nla_put(msg, NL80211_SCHED_SCAN_MATCH_ATTR_SSID,
10178 req->match_sets[i].ssid.ssid_len,
10179 req->match_sets[i].ssid.ssid))
10180 return -ENOBUFS;
Luciano Coelho75453cc2015-01-09 14:06:37 +020010181 nla_nest_end(msg, match);
10182 }
10183 nla_nest_end(msg, matches);
10184 }
10185
Avraham Stern3b06d272015-10-12 09:51:34 +030010186 scan_plans = nla_nest_start(msg, NL80211_ATTR_SCHED_SCAN_PLANS);
10187 if (!scan_plans)
10188 return -ENOBUFS;
10189
10190 for (i = 0; i < req->n_scan_plans; i++) {
10191 scan_plan = nla_nest_start(msg, i + 1);
Johannes Berg76e1fb42016-09-14 09:55:57 +020010192 if (!scan_plan)
10193 return -ENOBUFS;
10194
Avraham Stern3b06d272015-10-12 09:51:34 +030010195 if (!scan_plan ||
10196 nla_put_u32(msg, NL80211_SCHED_SCAN_PLAN_INTERVAL,
10197 req->scan_plans[i].interval) ||
10198 (req->scan_plans[i].iterations &&
10199 nla_put_u32(msg, NL80211_SCHED_SCAN_PLAN_ITERATIONS,
10200 req->scan_plans[i].iterations)))
10201 return -ENOBUFS;
10202 nla_nest_end(msg, scan_plan);
10203 }
10204 nla_nest_end(msg, scan_plans);
10205
Luciano Coelho75453cc2015-01-09 14:06:37 +020010206 nla_nest_end(msg, nd);
10207
10208 return 0;
10209}
10210
Johannes Bergff1b6e62011-05-04 15:37:28 +020010211static int nl80211_get_wowlan(struct sk_buff *skb, struct genl_info *info)
10212{
10213 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10214 struct sk_buff *msg;
10215 void *hdr;
Johannes Berg2a0e0472013-01-23 22:57:40 +010010216 u32 size = NLMSG_DEFAULT_SIZE;
Johannes Bergff1b6e62011-05-04 15:37:28 +020010217
Johannes Berg964dc9e2013-06-03 17:25:34 +020010218 if (!rdev->wiphy.wowlan)
Johannes Bergff1b6e62011-05-04 15:37:28 +020010219 return -EOPNOTSUPP;
10220
Johannes Berg6abb9cb2013-05-15 09:30:07 +020010221 if (rdev->wiphy.wowlan_config && rdev->wiphy.wowlan_config->tcp) {
Johannes Berg2a0e0472013-01-23 22:57:40 +010010222 /* adjust size to have room for all the data */
Johannes Berg6abb9cb2013-05-15 09:30:07 +020010223 size += rdev->wiphy.wowlan_config->tcp->tokens_size +
10224 rdev->wiphy.wowlan_config->tcp->payload_len +
10225 rdev->wiphy.wowlan_config->tcp->wake_len +
10226 rdev->wiphy.wowlan_config->tcp->wake_len / 8;
Johannes Berg2a0e0472013-01-23 22:57:40 +010010227 }
10228
10229 msg = nlmsg_new(size, GFP_KERNEL);
Johannes Bergff1b6e62011-05-04 15:37:28 +020010230 if (!msg)
10231 return -ENOMEM;
10232
Eric W. Biederman15e47302012-09-07 20:12:54 +000010233 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Johannes Bergff1b6e62011-05-04 15:37:28 +020010234 NL80211_CMD_GET_WOWLAN);
10235 if (!hdr)
10236 goto nla_put_failure;
10237
Johannes Berg6abb9cb2013-05-15 09:30:07 +020010238 if (rdev->wiphy.wowlan_config) {
Johannes Bergff1b6e62011-05-04 15:37:28 +020010239 struct nlattr *nl_wowlan;
10240
10241 nl_wowlan = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS);
10242 if (!nl_wowlan)
10243 goto nla_put_failure;
10244
Johannes Berg6abb9cb2013-05-15 09:30:07 +020010245 if ((rdev->wiphy.wowlan_config->any &&
David S. Miller9360ffd2012-03-29 04:41:26 -040010246 nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +020010247 (rdev->wiphy.wowlan_config->disconnect &&
David S. Miller9360ffd2012-03-29 04:41:26 -040010248 nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +020010249 (rdev->wiphy.wowlan_config->magic_pkt &&
David S. Miller9360ffd2012-03-29 04:41:26 -040010250 nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +020010251 (rdev->wiphy.wowlan_config->gtk_rekey_failure &&
David S. Miller9360ffd2012-03-29 04:41:26 -040010252 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +020010253 (rdev->wiphy.wowlan_config->eap_identity_req &&
David S. Miller9360ffd2012-03-29 04:41:26 -040010254 nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +020010255 (rdev->wiphy.wowlan_config->four_way_handshake &&
David S. Miller9360ffd2012-03-29 04:41:26 -040010256 nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +020010257 (rdev->wiphy.wowlan_config->rfkill_release &&
David S. Miller9360ffd2012-03-29 04:41:26 -040010258 nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE)))
10259 goto nla_put_failure;
Johannes Berg2a0e0472013-01-23 22:57:40 +010010260
Amitkumar Karwarbb92d192013-02-12 12:16:26 -080010261 if (nl80211_send_wowlan_patterns(msg, rdev))
10262 goto nla_put_failure;
Johannes Berg2a0e0472013-01-23 22:57:40 +010010263
Johannes Berg6abb9cb2013-05-15 09:30:07 +020010264 if (nl80211_send_wowlan_tcp(msg,
10265 rdev->wiphy.wowlan_config->tcp))
Johannes Berg2a0e0472013-01-23 22:57:40 +010010266 goto nla_put_failure;
10267
Luciano Coelho75453cc2015-01-09 14:06:37 +020010268 if (nl80211_send_wowlan_nd(
10269 msg,
10270 rdev->wiphy.wowlan_config->nd_config))
10271 goto nla_put_failure;
10272
Johannes Bergff1b6e62011-05-04 15:37:28 +020010273 nla_nest_end(msg, nl_wowlan);
10274 }
10275
10276 genlmsg_end(msg, hdr);
10277 return genlmsg_reply(msg, info);
10278
10279nla_put_failure:
10280 nlmsg_free(msg);
10281 return -ENOBUFS;
10282}
10283
Johannes Berg2a0e0472013-01-23 22:57:40 +010010284static int nl80211_parse_wowlan_tcp(struct cfg80211_registered_device *rdev,
10285 struct nlattr *attr,
10286 struct cfg80211_wowlan *trig)
10287{
10288 struct nlattr *tb[NUM_NL80211_WOWLAN_TCP];
10289 struct cfg80211_wowlan_tcp *cfg;
10290 struct nl80211_wowlan_tcp_data_token *tok = NULL;
10291 struct nl80211_wowlan_tcp_data_seq *seq = NULL;
10292 u32 size;
10293 u32 data_size, wake_size, tokens_size = 0, wake_mask_size;
10294 int err, port;
10295
Johannes Berg964dc9e2013-06-03 17:25:34 +020010296 if (!rdev->wiphy.wowlan->tcp)
Johannes Berg2a0e0472013-01-23 22:57:40 +010010297 return -EINVAL;
10298
Johannes Bergbfe2c7b2016-10-26 14:42:21 +020010299 err = nla_parse_nested(tb, MAX_NL80211_WOWLAN_TCP, attr,
Johannes Bergfceb6432017-04-12 14:34:07 +020010300 nl80211_wowlan_tcp_policy, NULL);
Johannes Berg2a0e0472013-01-23 22:57:40 +010010301 if (err)
10302 return err;
10303
10304 if (!tb[NL80211_WOWLAN_TCP_SRC_IPV4] ||
10305 !tb[NL80211_WOWLAN_TCP_DST_IPV4] ||
10306 !tb[NL80211_WOWLAN_TCP_DST_MAC] ||
10307 !tb[NL80211_WOWLAN_TCP_DST_PORT] ||
10308 !tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD] ||
10309 !tb[NL80211_WOWLAN_TCP_DATA_INTERVAL] ||
10310 !tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD] ||
10311 !tb[NL80211_WOWLAN_TCP_WAKE_MASK])
10312 return -EINVAL;
10313
10314 data_size = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]);
Johannes Berg964dc9e2013-06-03 17:25:34 +020010315 if (data_size > rdev->wiphy.wowlan->tcp->data_payload_max)
Johannes Berg2a0e0472013-01-23 22:57:40 +010010316 return -EINVAL;
10317
10318 if (nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]) >
Johannes Berg964dc9e2013-06-03 17:25:34 +020010319 rdev->wiphy.wowlan->tcp->data_interval_max ||
Johannes Berg723d5682013-02-26 13:56:40 +010010320 nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]) == 0)
Johannes Berg2a0e0472013-01-23 22:57:40 +010010321 return -EINVAL;
10322
10323 wake_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]);
Johannes Berg964dc9e2013-06-03 17:25:34 +020010324 if (wake_size > rdev->wiphy.wowlan->tcp->wake_payload_max)
Johannes Berg2a0e0472013-01-23 22:57:40 +010010325 return -EINVAL;
10326
10327 wake_mask_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_MASK]);
10328 if (wake_mask_size != DIV_ROUND_UP(wake_size, 8))
10329 return -EINVAL;
10330
10331 if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]) {
10332 u32 tokln = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]);
10333
10334 tok = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]);
10335 tokens_size = tokln - sizeof(*tok);
10336
10337 if (!tok->len || tokens_size % tok->len)
10338 return -EINVAL;
Johannes Berg964dc9e2013-06-03 17:25:34 +020010339 if (!rdev->wiphy.wowlan->tcp->tok)
Johannes Berg2a0e0472013-01-23 22:57:40 +010010340 return -EINVAL;
Johannes Berg964dc9e2013-06-03 17:25:34 +020010341 if (tok->len > rdev->wiphy.wowlan->tcp->tok->max_len)
Johannes Berg2a0e0472013-01-23 22:57:40 +010010342 return -EINVAL;
Johannes Berg964dc9e2013-06-03 17:25:34 +020010343 if (tok->len < rdev->wiphy.wowlan->tcp->tok->min_len)
Johannes Berg2a0e0472013-01-23 22:57:40 +010010344 return -EINVAL;
Johannes Berg964dc9e2013-06-03 17:25:34 +020010345 if (tokens_size > rdev->wiphy.wowlan->tcp->tok->bufsize)
Johannes Berg2a0e0472013-01-23 22:57:40 +010010346 return -EINVAL;
10347 if (tok->offset + tok->len > data_size)
10348 return -EINVAL;
10349 }
10350
10351 if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]) {
10352 seq = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]);
Johannes Berg964dc9e2013-06-03 17:25:34 +020010353 if (!rdev->wiphy.wowlan->tcp->seq)
Johannes Berg2a0e0472013-01-23 22:57:40 +010010354 return -EINVAL;
10355 if (seq->len == 0 || seq->len > 4)
10356 return -EINVAL;
10357 if (seq->len + seq->offset > data_size)
10358 return -EINVAL;
10359 }
10360
10361 size = sizeof(*cfg);
10362 size += data_size;
10363 size += wake_size + wake_mask_size;
10364 size += tokens_size;
10365
10366 cfg = kzalloc(size, GFP_KERNEL);
10367 if (!cfg)
10368 return -ENOMEM;
Jiri Benc67b61f62015-03-29 16:59:26 +020010369 cfg->src = nla_get_in_addr(tb[NL80211_WOWLAN_TCP_SRC_IPV4]);
10370 cfg->dst = nla_get_in_addr(tb[NL80211_WOWLAN_TCP_DST_IPV4]);
Johannes Berg2a0e0472013-01-23 22:57:40 +010010371 memcpy(cfg->dst_mac, nla_data(tb[NL80211_WOWLAN_TCP_DST_MAC]),
10372 ETH_ALEN);
10373 if (tb[NL80211_WOWLAN_TCP_SRC_PORT])
10374 port = nla_get_u16(tb[NL80211_WOWLAN_TCP_SRC_PORT]);
10375 else
10376 port = 0;
10377#ifdef CONFIG_INET
10378 /* allocate a socket and port for it and use it */
10379 err = __sock_create(wiphy_net(&rdev->wiphy), PF_INET, SOCK_STREAM,
10380 IPPROTO_TCP, &cfg->sock, 1);
10381 if (err) {
10382 kfree(cfg);
10383 return err;
10384 }
10385 if (inet_csk_get_port(cfg->sock->sk, port)) {
10386 sock_release(cfg->sock);
10387 kfree(cfg);
10388 return -EADDRINUSE;
10389 }
10390 cfg->src_port = inet_sk(cfg->sock->sk)->inet_num;
10391#else
10392 if (!port) {
10393 kfree(cfg);
10394 return -EINVAL;
10395 }
10396 cfg->src_port = port;
10397#endif
10398
10399 cfg->dst_port = nla_get_u16(tb[NL80211_WOWLAN_TCP_DST_PORT]);
10400 cfg->payload_len = data_size;
10401 cfg->payload = (u8 *)cfg + sizeof(*cfg) + tokens_size;
10402 memcpy((void *)cfg->payload,
10403 nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]),
10404 data_size);
10405 if (seq)
10406 cfg->payload_seq = *seq;
10407 cfg->data_interval = nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]);
10408 cfg->wake_len = wake_size;
10409 cfg->wake_data = (u8 *)cfg + sizeof(*cfg) + tokens_size + data_size;
10410 memcpy((void *)cfg->wake_data,
10411 nla_data(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]),
10412 wake_size);
10413 cfg->wake_mask = (u8 *)cfg + sizeof(*cfg) + tokens_size +
10414 data_size + wake_size;
10415 memcpy((void *)cfg->wake_mask,
10416 nla_data(tb[NL80211_WOWLAN_TCP_WAKE_MASK]),
10417 wake_mask_size);
10418 if (tok) {
10419 cfg->tokens_size = tokens_size;
10420 memcpy(&cfg->payload_tok, tok, sizeof(*tok) + tokens_size);
10421 }
10422
10423 trig->tcp = cfg;
10424
10425 return 0;
10426}
10427
Luciano Coelho8cd4d452014-09-17 11:55:28 +030010428static int nl80211_parse_wowlan_nd(struct cfg80211_registered_device *rdev,
10429 const struct wiphy_wowlan_support *wowlan,
10430 struct nlattr *attr,
10431 struct cfg80211_wowlan *trig)
10432{
10433 struct nlattr **tb;
10434 int err;
10435
10436 tb = kzalloc(NUM_NL80211_ATTR * sizeof(*tb), GFP_KERNEL);
10437 if (!tb)
10438 return -ENOMEM;
10439
10440 if (!(wowlan->flags & WIPHY_WOWLAN_NET_DETECT)) {
10441 err = -EOPNOTSUPP;
10442 goto out;
10443 }
10444
Johannes Bergfceb6432017-04-12 14:34:07 +020010445 err = nla_parse_nested(tb, NL80211_ATTR_MAX, attr, nl80211_policy,
10446 NULL);
Luciano Coelho8cd4d452014-09-17 11:55:28 +030010447 if (err)
10448 goto out;
10449
Arend Van Sprielaad1e812017-01-27 12:27:44 +000010450 trig->nd_config = nl80211_parse_sched_scan(&rdev->wiphy, NULL, tb,
10451 wowlan->max_nd_match_sets);
Luciano Coelho8cd4d452014-09-17 11:55:28 +030010452 err = PTR_ERR_OR_ZERO(trig->nd_config);
10453 if (err)
10454 trig->nd_config = NULL;
10455
10456out:
10457 kfree(tb);
10458 return err;
10459}
10460
Johannes Bergff1b6e62011-05-04 15:37:28 +020010461static int nl80211_set_wowlan(struct sk_buff *skb, struct genl_info *info)
10462{
10463 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10464 struct nlattr *tb[NUM_NL80211_WOWLAN_TRIG];
Johannes Bergff1b6e62011-05-04 15:37:28 +020010465 struct cfg80211_wowlan new_triggers = {};
Johannes Bergae33bd82012-07-12 16:25:02 +020010466 struct cfg80211_wowlan *ntrig;
Johannes Berg964dc9e2013-06-03 17:25:34 +020010467 const struct wiphy_wowlan_support *wowlan = rdev->wiphy.wowlan;
Johannes Bergff1b6e62011-05-04 15:37:28 +020010468 int err, i;
Johannes Berg6abb9cb2013-05-15 09:30:07 +020010469 bool prev_enabled = rdev->wiphy.wowlan_config;
Johannes Berg98fc4382015-03-01 09:10:13 +020010470 bool regular = false;
Johannes Bergff1b6e62011-05-04 15:37:28 +020010471
Johannes Berg964dc9e2013-06-03 17:25:34 +020010472 if (!wowlan)
Johannes Bergff1b6e62011-05-04 15:37:28 +020010473 return -EOPNOTSUPP;
10474
Johannes Bergae33bd82012-07-12 16:25:02 +020010475 if (!info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]) {
10476 cfg80211_rdev_free_wowlan(rdev);
Johannes Berg6abb9cb2013-05-15 09:30:07 +020010477 rdev->wiphy.wowlan_config = NULL;
Johannes Bergae33bd82012-07-12 16:25:02 +020010478 goto set_wakeup;
10479 }
Johannes Bergff1b6e62011-05-04 15:37:28 +020010480
Johannes Bergbfe2c7b2016-10-26 14:42:21 +020010481 err = nla_parse_nested(tb, MAX_NL80211_WOWLAN_TRIG,
10482 info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS],
Johannes Bergfe521452017-04-12 14:34:08 +020010483 nl80211_wowlan_policy, info->extack);
Johannes Bergff1b6e62011-05-04 15:37:28 +020010484 if (err)
10485 return err;
10486
10487 if (tb[NL80211_WOWLAN_TRIG_ANY]) {
10488 if (!(wowlan->flags & WIPHY_WOWLAN_ANY))
10489 return -EINVAL;
10490 new_triggers.any = true;
10491 }
10492
10493 if (tb[NL80211_WOWLAN_TRIG_DISCONNECT]) {
10494 if (!(wowlan->flags & WIPHY_WOWLAN_DISCONNECT))
10495 return -EINVAL;
10496 new_triggers.disconnect = true;
Johannes Berg98fc4382015-03-01 09:10:13 +020010497 regular = true;
Johannes Bergff1b6e62011-05-04 15:37:28 +020010498 }
10499
10500 if (tb[NL80211_WOWLAN_TRIG_MAGIC_PKT]) {
10501 if (!(wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT))
10502 return -EINVAL;
10503 new_triggers.magic_pkt = true;
Johannes Berg98fc4382015-03-01 09:10:13 +020010504 regular = true;
Johannes Bergff1b6e62011-05-04 15:37:28 +020010505 }
10506
Johannes Berg77dbbb12011-07-13 10:48:55 +020010507 if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED])
10508 return -EINVAL;
10509
10510 if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE]) {
10511 if (!(wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE))
10512 return -EINVAL;
10513 new_triggers.gtk_rekey_failure = true;
Johannes Berg98fc4382015-03-01 09:10:13 +020010514 regular = true;
Johannes Berg77dbbb12011-07-13 10:48:55 +020010515 }
10516
10517 if (tb[NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST]) {
10518 if (!(wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ))
10519 return -EINVAL;
10520 new_triggers.eap_identity_req = true;
Johannes Berg98fc4382015-03-01 09:10:13 +020010521 regular = true;
Johannes Berg77dbbb12011-07-13 10:48:55 +020010522 }
10523
10524 if (tb[NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE]) {
10525 if (!(wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE))
10526 return -EINVAL;
10527 new_triggers.four_way_handshake = true;
Johannes Berg98fc4382015-03-01 09:10:13 +020010528 regular = true;
Johannes Berg77dbbb12011-07-13 10:48:55 +020010529 }
10530
10531 if (tb[NL80211_WOWLAN_TRIG_RFKILL_RELEASE]) {
10532 if (!(wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE))
10533 return -EINVAL;
10534 new_triggers.rfkill_release = true;
Johannes Berg98fc4382015-03-01 09:10:13 +020010535 regular = true;
Johannes Berg77dbbb12011-07-13 10:48:55 +020010536 }
10537
Johannes Bergff1b6e62011-05-04 15:37:28 +020010538 if (tb[NL80211_WOWLAN_TRIG_PKT_PATTERN]) {
10539 struct nlattr *pat;
10540 int n_patterns = 0;
Amitkumar Karwarbb92d192013-02-12 12:16:26 -080010541 int rem, pat_len, mask_len, pkt_offset;
Amitkumar Karwar50ac6602013-06-25 19:03:56 -070010542 struct nlattr *pat_tb[NUM_NL80211_PKTPAT];
Johannes Bergff1b6e62011-05-04 15:37:28 +020010543
Johannes Berg98fc4382015-03-01 09:10:13 +020010544 regular = true;
10545
Johannes Bergff1b6e62011-05-04 15:37:28 +020010546 nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN],
10547 rem)
10548 n_patterns++;
10549 if (n_patterns > wowlan->n_patterns)
10550 return -EINVAL;
10551
10552 new_triggers.patterns = kcalloc(n_patterns,
10553 sizeof(new_triggers.patterns[0]),
10554 GFP_KERNEL);
10555 if (!new_triggers.patterns)
10556 return -ENOMEM;
10557
10558 new_triggers.n_patterns = n_patterns;
10559 i = 0;
10560
10561 nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN],
10562 rem) {
Johannes Berg922bd802014-05-19 17:59:50 +020010563 u8 *mask_pat;
10564
Johannes Bergbfe2c7b2016-10-26 14:42:21 +020010565 nla_parse_nested(pat_tb, MAX_NL80211_PKTPAT, pat,
Johannes Bergfe521452017-04-12 14:34:08 +020010566 NULL, info->extack);
Johannes Bergff1b6e62011-05-04 15:37:28 +020010567 err = -EINVAL;
Amitkumar Karwar50ac6602013-06-25 19:03:56 -070010568 if (!pat_tb[NL80211_PKTPAT_MASK] ||
10569 !pat_tb[NL80211_PKTPAT_PATTERN])
Johannes Bergff1b6e62011-05-04 15:37:28 +020010570 goto error;
Amitkumar Karwar50ac6602013-06-25 19:03:56 -070010571 pat_len = nla_len(pat_tb[NL80211_PKTPAT_PATTERN]);
Johannes Bergff1b6e62011-05-04 15:37:28 +020010572 mask_len = DIV_ROUND_UP(pat_len, 8);
Amitkumar Karwar50ac6602013-06-25 19:03:56 -070010573 if (nla_len(pat_tb[NL80211_PKTPAT_MASK]) != mask_len)
Johannes Bergff1b6e62011-05-04 15:37:28 +020010574 goto error;
10575 if (pat_len > wowlan->pattern_max_len ||
10576 pat_len < wowlan->pattern_min_len)
10577 goto error;
10578
Amitkumar Karwar50ac6602013-06-25 19:03:56 -070010579 if (!pat_tb[NL80211_PKTPAT_OFFSET])
Amitkumar Karwarbb92d192013-02-12 12:16:26 -080010580 pkt_offset = 0;
10581 else
10582 pkt_offset = nla_get_u32(
Amitkumar Karwar50ac6602013-06-25 19:03:56 -070010583 pat_tb[NL80211_PKTPAT_OFFSET]);
Amitkumar Karwarbb92d192013-02-12 12:16:26 -080010584 if (pkt_offset > wowlan->max_pkt_offset)
10585 goto error;
10586 new_triggers.patterns[i].pkt_offset = pkt_offset;
10587
Johannes Berg922bd802014-05-19 17:59:50 +020010588 mask_pat = kmalloc(mask_len + pat_len, GFP_KERNEL);
10589 if (!mask_pat) {
Johannes Bergff1b6e62011-05-04 15:37:28 +020010590 err = -ENOMEM;
10591 goto error;
10592 }
Johannes Berg922bd802014-05-19 17:59:50 +020010593 new_triggers.patterns[i].mask = mask_pat;
10594 memcpy(mask_pat, nla_data(pat_tb[NL80211_PKTPAT_MASK]),
Johannes Bergff1b6e62011-05-04 15:37:28 +020010595 mask_len);
Johannes Berg922bd802014-05-19 17:59:50 +020010596 mask_pat += mask_len;
10597 new_triggers.patterns[i].pattern = mask_pat;
Johannes Bergff1b6e62011-05-04 15:37:28 +020010598 new_triggers.patterns[i].pattern_len = pat_len;
Johannes Berg922bd802014-05-19 17:59:50 +020010599 memcpy(mask_pat,
Amitkumar Karwar50ac6602013-06-25 19:03:56 -070010600 nla_data(pat_tb[NL80211_PKTPAT_PATTERN]),
Johannes Bergff1b6e62011-05-04 15:37:28 +020010601 pat_len);
10602 i++;
10603 }
10604 }
10605
Johannes Berg2a0e0472013-01-23 22:57:40 +010010606 if (tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION]) {
Johannes Berg98fc4382015-03-01 09:10:13 +020010607 regular = true;
Johannes Berg2a0e0472013-01-23 22:57:40 +010010608 err = nl80211_parse_wowlan_tcp(
10609 rdev, tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION],
10610 &new_triggers);
10611 if (err)
10612 goto error;
10613 }
10614
Luciano Coelho8cd4d452014-09-17 11:55:28 +030010615 if (tb[NL80211_WOWLAN_TRIG_NET_DETECT]) {
Johannes Berg98fc4382015-03-01 09:10:13 +020010616 regular = true;
Luciano Coelho8cd4d452014-09-17 11:55:28 +030010617 err = nl80211_parse_wowlan_nd(
10618 rdev, wowlan, tb[NL80211_WOWLAN_TRIG_NET_DETECT],
10619 &new_triggers);
10620 if (err)
10621 goto error;
10622 }
10623
Johannes Berg98fc4382015-03-01 09:10:13 +020010624 /* The 'any' trigger means the device continues operating more or less
10625 * as in its normal operation mode and wakes up the host on most of the
10626 * normal interrupts (like packet RX, ...)
10627 * It therefore makes little sense to combine with the more constrained
10628 * wakeup trigger modes.
10629 */
10630 if (new_triggers.any && regular) {
10631 err = -EINVAL;
10632 goto error;
10633 }
10634
Johannes Bergae33bd82012-07-12 16:25:02 +020010635 ntrig = kmemdup(&new_triggers, sizeof(new_triggers), GFP_KERNEL);
10636 if (!ntrig) {
10637 err = -ENOMEM;
10638 goto error;
Johannes Bergff1b6e62011-05-04 15:37:28 +020010639 }
Johannes Bergae33bd82012-07-12 16:25:02 +020010640 cfg80211_rdev_free_wowlan(rdev);
Johannes Berg6abb9cb2013-05-15 09:30:07 +020010641 rdev->wiphy.wowlan_config = ntrig;
Johannes Bergff1b6e62011-05-04 15:37:28 +020010642
Johannes Bergae33bd82012-07-12 16:25:02 +020010643 set_wakeup:
Johannes Berg6abb9cb2013-05-15 09:30:07 +020010644 if (rdev->ops->set_wakeup &&
10645 prev_enabled != !!rdev->wiphy.wowlan_config)
10646 rdev_set_wakeup(rdev, rdev->wiphy.wowlan_config);
Johannes Berg6d525632012-04-04 15:05:25 +020010647
Johannes Bergff1b6e62011-05-04 15:37:28 +020010648 return 0;
10649 error:
10650 for (i = 0; i < new_triggers.n_patterns; i++)
10651 kfree(new_triggers.patterns[i].mask);
10652 kfree(new_triggers.patterns);
Johannes Berg2a0e0472013-01-23 22:57:40 +010010653 if (new_triggers.tcp && new_triggers.tcp->sock)
10654 sock_release(new_triggers.tcp->sock);
10655 kfree(new_triggers.tcp);
Ola Olssone5dbe072015-12-12 23:17:17 +010010656 kfree(new_triggers.nd_config);
Johannes Bergff1b6e62011-05-04 15:37:28 +020010657 return err;
10658}
Johannes Bergdfb89c52012-06-27 09:23:48 +020010659#endif
Johannes Bergff1b6e62011-05-04 15:37:28 +020010660
Amitkumar Karwarbe29b992013-06-28 11:51:26 -070010661static int nl80211_send_coalesce_rules(struct sk_buff *msg,
10662 struct cfg80211_registered_device *rdev)
10663{
10664 struct nlattr *nl_pats, *nl_pat, *nl_rule, *nl_rules;
10665 int i, j, pat_len;
10666 struct cfg80211_coalesce_rules *rule;
10667
10668 if (!rdev->coalesce->n_rules)
10669 return 0;
10670
10671 nl_rules = nla_nest_start(msg, NL80211_ATTR_COALESCE_RULE);
10672 if (!nl_rules)
10673 return -ENOBUFS;
10674
10675 for (i = 0; i < rdev->coalesce->n_rules; i++) {
10676 nl_rule = nla_nest_start(msg, i + 1);
10677 if (!nl_rule)
10678 return -ENOBUFS;
10679
10680 rule = &rdev->coalesce->rules[i];
10681 if (nla_put_u32(msg, NL80211_ATTR_COALESCE_RULE_DELAY,
10682 rule->delay))
10683 return -ENOBUFS;
10684
10685 if (nla_put_u32(msg, NL80211_ATTR_COALESCE_RULE_CONDITION,
10686 rule->condition))
10687 return -ENOBUFS;
10688
10689 nl_pats = nla_nest_start(msg,
10690 NL80211_ATTR_COALESCE_RULE_PKT_PATTERN);
10691 if (!nl_pats)
10692 return -ENOBUFS;
10693
10694 for (j = 0; j < rule->n_patterns; j++) {
10695 nl_pat = nla_nest_start(msg, j + 1);
10696 if (!nl_pat)
10697 return -ENOBUFS;
10698 pat_len = rule->patterns[j].pattern_len;
10699 if (nla_put(msg, NL80211_PKTPAT_MASK,
10700 DIV_ROUND_UP(pat_len, 8),
10701 rule->patterns[j].mask) ||
10702 nla_put(msg, NL80211_PKTPAT_PATTERN, pat_len,
10703 rule->patterns[j].pattern) ||
10704 nla_put_u32(msg, NL80211_PKTPAT_OFFSET,
10705 rule->patterns[j].pkt_offset))
10706 return -ENOBUFS;
10707 nla_nest_end(msg, nl_pat);
10708 }
10709 nla_nest_end(msg, nl_pats);
10710 nla_nest_end(msg, nl_rule);
10711 }
10712 nla_nest_end(msg, nl_rules);
10713
10714 return 0;
10715}
10716
10717static int nl80211_get_coalesce(struct sk_buff *skb, struct genl_info *info)
10718{
10719 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10720 struct sk_buff *msg;
10721 void *hdr;
10722
10723 if (!rdev->wiphy.coalesce)
10724 return -EOPNOTSUPP;
10725
10726 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
10727 if (!msg)
10728 return -ENOMEM;
10729
10730 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
10731 NL80211_CMD_GET_COALESCE);
10732 if (!hdr)
10733 goto nla_put_failure;
10734
10735 if (rdev->coalesce && nl80211_send_coalesce_rules(msg, rdev))
10736 goto nla_put_failure;
10737
10738 genlmsg_end(msg, hdr);
10739 return genlmsg_reply(msg, info);
10740
10741nla_put_failure:
10742 nlmsg_free(msg);
10743 return -ENOBUFS;
10744}
10745
10746void cfg80211_rdev_free_coalesce(struct cfg80211_registered_device *rdev)
10747{
10748 struct cfg80211_coalesce *coalesce = rdev->coalesce;
10749 int i, j;
10750 struct cfg80211_coalesce_rules *rule;
10751
10752 if (!coalesce)
10753 return;
10754
10755 for (i = 0; i < coalesce->n_rules; i++) {
10756 rule = &coalesce->rules[i];
10757 for (j = 0; j < rule->n_patterns; j++)
10758 kfree(rule->patterns[j].mask);
10759 kfree(rule->patterns);
10760 }
10761 kfree(coalesce->rules);
10762 kfree(coalesce);
10763 rdev->coalesce = NULL;
10764}
10765
10766static int nl80211_parse_coalesce_rule(struct cfg80211_registered_device *rdev,
10767 struct nlattr *rule,
10768 struct cfg80211_coalesce_rules *new_rule)
10769{
10770 int err, i;
10771 const struct wiphy_coalesce_support *coalesce = rdev->wiphy.coalesce;
10772 struct nlattr *tb[NUM_NL80211_ATTR_COALESCE_RULE], *pat;
10773 int rem, pat_len, mask_len, pkt_offset, n_patterns = 0;
10774 struct nlattr *pat_tb[NUM_NL80211_PKTPAT];
10775
Johannes Bergbfe2c7b2016-10-26 14:42:21 +020010776 err = nla_parse_nested(tb, NL80211_ATTR_COALESCE_RULE_MAX, rule,
Johannes Bergfceb6432017-04-12 14:34:07 +020010777 nl80211_coalesce_policy, NULL);
Amitkumar Karwarbe29b992013-06-28 11:51:26 -070010778 if (err)
10779 return err;
10780
10781 if (tb[NL80211_ATTR_COALESCE_RULE_DELAY])
10782 new_rule->delay =
10783 nla_get_u32(tb[NL80211_ATTR_COALESCE_RULE_DELAY]);
10784 if (new_rule->delay > coalesce->max_delay)
10785 return -EINVAL;
10786
10787 if (tb[NL80211_ATTR_COALESCE_RULE_CONDITION])
10788 new_rule->condition =
10789 nla_get_u32(tb[NL80211_ATTR_COALESCE_RULE_CONDITION]);
10790 if (new_rule->condition != NL80211_COALESCE_CONDITION_MATCH &&
10791 new_rule->condition != NL80211_COALESCE_CONDITION_NO_MATCH)
10792 return -EINVAL;
10793
10794 if (!tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN])
10795 return -EINVAL;
10796
10797 nla_for_each_nested(pat, tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN],
10798 rem)
10799 n_patterns++;
10800 if (n_patterns > coalesce->n_patterns)
10801 return -EINVAL;
10802
10803 new_rule->patterns = kcalloc(n_patterns, sizeof(new_rule->patterns[0]),
10804 GFP_KERNEL);
10805 if (!new_rule->patterns)
10806 return -ENOMEM;
10807
10808 new_rule->n_patterns = n_patterns;
10809 i = 0;
10810
10811 nla_for_each_nested(pat, tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN],
10812 rem) {
Johannes Berg922bd802014-05-19 17:59:50 +020010813 u8 *mask_pat;
10814
Johannes Bergfceb6432017-04-12 14:34:07 +020010815 nla_parse_nested(pat_tb, MAX_NL80211_PKTPAT, pat, NULL, NULL);
Amitkumar Karwarbe29b992013-06-28 11:51:26 -070010816 if (!pat_tb[NL80211_PKTPAT_MASK] ||
10817 !pat_tb[NL80211_PKTPAT_PATTERN])
10818 return -EINVAL;
10819 pat_len = nla_len(pat_tb[NL80211_PKTPAT_PATTERN]);
10820 mask_len = DIV_ROUND_UP(pat_len, 8);
10821 if (nla_len(pat_tb[NL80211_PKTPAT_MASK]) != mask_len)
10822 return -EINVAL;
10823 if (pat_len > coalesce->pattern_max_len ||
10824 pat_len < coalesce->pattern_min_len)
10825 return -EINVAL;
10826
10827 if (!pat_tb[NL80211_PKTPAT_OFFSET])
10828 pkt_offset = 0;
10829 else
10830 pkt_offset = nla_get_u32(pat_tb[NL80211_PKTPAT_OFFSET]);
10831 if (pkt_offset > coalesce->max_pkt_offset)
10832 return -EINVAL;
10833 new_rule->patterns[i].pkt_offset = pkt_offset;
10834
Johannes Berg922bd802014-05-19 17:59:50 +020010835 mask_pat = kmalloc(mask_len + pat_len, GFP_KERNEL);
10836 if (!mask_pat)
Amitkumar Karwarbe29b992013-06-28 11:51:26 -070010837 return -ENOMEM;
Johannes Berg922bd802014-05-19 17:59:50 +020010838
10839 new_rule->patterns[i].mask = mask_pat;
10840 memcpy(mask_pat, nla_data(pat_tb[NL80211_PKTPAT_MASK]),
10841 mask_len);
10842
10843 mask_pat += mask_len;
10844 new_rule->patterns[i].pattern = mask_pat;
Amitkumar Karwarbe29b992013-06-28 11:51:26 -070010845 new_rule->patterns[i].pattern_len = pat_len;
Johannes Berg922bd802014-05-19 17:59:50 +020010846 memcpy(mask_pat, nla_data(pat_tb[NL80211_PKTPAT_PATTERN]),
10847 pat_len);
Amitkumar Karwarbe29b992013-06-28 11:51:26 -070010848 i++;
10849 }
10850
10851 return 0;
10852}
10853
10854static int nl80211_set_coalesce(struct sk_buff *skb, struct genl_info *info)
10855{
10856 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10857 const struct wiphy_coalesce_support *coalesce = rdev->wiphy.coalesce;
10858 struct cfg80211_coalesce new_coalesce = {};
10859 struct cfg80211_coalesce *n_coalesce;
10860 int err, rem_rule, n_rules = 0, i, j;
10861 struct nlattr *rule;
10862 struct cfg80211_coalesce_rules *tmp_rule;
10863
10864 if (!rdev->wiphy.coalesce || !rdev->ops->set_coalesce)
10865 return -EOPNOTSUPP;
10866
10867 if (!info->attrs[NL80211_ATTR_COALESCE_RULE]) {
10868 cfg80211_rdev_free_coalesce(rdev);
Ilan Peera1056b12015-10-22 22:27:46 +030010869 rdev_set_coalesce(rdev, NULL);
Amitkumar Karwarbe29b992013-06-28 11:51:26 -070010870 return 0;
10871 }
10872
10873 nla_for_each_nested(rule, info->attrs[NL80211_ATTR_COALESCE_RULE],
10874 rem_rule)
10875 n_rules++;
10876 if (n_rules > coalesce->n_rules)
10877 return -EINVAL;
10878
10879 new_coalesce.rules = kcalloc(n_rules, sizeof(new_coalesce.rules[0]),
10880 GFP_KERNEL);
10881 if (!new_coalesce.rules)
10882 return -ENOMEM;
10883
10884 new_coalesce.n_rules = n_rules;
10885 i = 0;
10886
10887 nla_for_each_nested(rule, info->attrs[NL80211_ATTR_COALESCE_RULE],
10888 rem_rule) {
10889 err = nl80211_parse_coalesce_rule(rdev, rule,
10890 &new_coalesce.rules[i]);
10891 if (err)
10892 goto error;
10893
10894 i++;
10895 }
10896
Ilan Peera1056b12015-10-22 22:27:46 +030010897 err = rdev_set_coalesce(rdev, &new_coalesce);
Amitkumar Karwarbe29b992013-06-28 11:51:26 -070010898 if (err)
10899 goto error;
10900
10901 n_coalesce = kmemdup(&new_coalesce, sizeof(new_coalesce), GFP_KERNEL);
10902 if (!n_coalesce) {
10903 err = -ENOMEM;
10904 goto error;
10905 }
10906 cfg80211_rdev_free_coalesce(rdev);
10907 rdev->coalesce = n_coalesce;
10908
10909 return 0;
10910error:
10911 for (i = 0; i < new_coalesce.n_rules; i++) {
10912 tmp_rule = &new_coalesce.rules[i];
10913 for (j = 0; j < tmp_rule->n_patterns; j++)
10914 kfree(tmp_rule->patterns[j].mask);
10915 kfree(tmp_rule->patterns);
10916 }
10917 kfree(new_coalesce.rules);
10918
10919 return err;
10920}
10921
Johannes Berge5497d72011-07-05 16:35:40 +020010922static int nl80211_set_rekey_data(struct sk_buff *skb, struct genl_info *info)
10923{
10924 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10925 struct net_device *dev = info->user_ptr[1];
10926 struct wireless_dev *wdev = dev->ieee80211_ptr;
10927 struct nlattr *tb[NUM_NL80211_REKEY_DATA];
10928 struct cfg80211_gtk_rekey_data rekey_data;
10929 int err;
10930
10931 if (!info->attrs[NL80211_ATTR_REKEY_DATA])
10932 return -EINVAL;
10933
Johannes Bergbfe2c7b2016-10-26 14:42:21 +020010934 err = nla_parse_nested(tb, MAX_NL80211_REKEY_DATA,
10935 info->attrs[NL80211_ATTR_REKEY_DATA],
Johannes Bergfe521452017-04-12 14:34:08 +020010936 nl80211_rekey_policy, info->extack);
Johannes Berge5497d72011-07-05 16:35:40 +020010937 if (err)
10938 return err;
10939
10940 if (nla_len(tb[NL80211_REKEY_DATA_REPLAY_CTR]) != NL80211_REPLAY_CTR_LEN)
10941 return -ERANGE;
10942 if (nla_len(tb[NL80211_REKEY_DATA_KEK]) != NL80211_KEK_LEN)
10943 return -ERANGE;
10944 if (nla_len(tb[NL80211_REKEY_DATA_KCK]) != NL80211_KCK_LEN)
10945 return -ERANGE;
10946
Johannes Berg78f686c2014-09-10 22:28:06 +030010947 rekey_data.kek = nla_data(tb[NL80211_REKEY_DATA_KEK]);
10948 rekey_data.kck = nla_data(tb[NL80211_REKEY_DATA_KCK]);
10949 rekey_data.replay_ctr = nla_data(tb[NL80211_REKEY_DATA_REPLAY_CTR]);
Johannes Berge5497d72011-07-05 16:35:40 +020010950
10951 wdev_lock(wdev);
10952 if (!wdev->current_bss) {
10953 err = -ENOTCONN;
10954 goto out;
10955 }
10956
10957 if (!rdev->ops->set_rekey_data) {
10958 err = -EOPNOTSUPP;
10959 goto out;
10960 }
10961
Hila Gonene35e4d22012-06-27 17:19:42 +030010962 err = rdev_set_rekey_data(rdev, dev, &rekey_data);
Johannes Berge5497d72011-07-05 16:35:40 +020010963 out:
10964 wdev_unlock(wdev);
10965 return err;
10966}
10967
Johannes Berg28946da2011-11-04 11:18:12 +010010968static int nl80211_register_unexpected_frame(struct sk_buff *skb,
10969 struct genl_info *info)
10970{
10971 struct net_device *dev = info->user_ptr[1];
10972 struct wireless_dev *wdev = dev->ieee80211_ptr;
10973
10974 if (wdev->iftype != NL80211_IFTYPE_AP &&
10975 wdev->iftype != NL80211_IFTYPE_P2P_GO)
10976 return -EINVAL;
10977
Eric W. Biederman15e47302012-09-07 20:12:54 +000010978 if (wdev->ap_unexpected_nlportid)
Johannes Berg28946da2011-11-04 11:18:12 +010010979 return -EBUSY;
10980
Eric W. Biederman15e47302012-09-07 20:12:54 +000010981 wdev->ap_unexpected_nlportid = info->snd_portid;
Johannes Berg28946da2011-11-04 11:18:12 +010010982 return 0;
10983}
10984
Johannes Berg7f6cf312011-11-04 11:18:15 +010010985static int nl80211_probe_client(struct sk_buff *skb,
10986 struct genl_info *info)
10987{
10988 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10989 struct net_device *dev = info->user_ptr[1];
10990 struct wireless_dev *wdev = dev->ieee80211_ptr;
10991 struct sk_buff *msg;
10992 void *hdr;
10993 const u8 *addr;
10994 u64 cookie;
10995 int err;
10996
10997 if (wdev->iftype != NL80211_IFTYPE_AP &&
10998 wdev->iftype != NL80211_IFTYPE_P2P_GO)
10999 return -EOPNOTSUPP;
11000
11001 if (!info->attrs[NL80211_ATTR_MAC])
11002 return -EINVAL;
11003
11004 if (!rdev->ops->probe_client)
11005 return -EOPNOTSUPP;
11006
11007 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
11008 if (!msg)
11009 return -ENOMEM;
11010
Eric W. Biederman15e47302012-09-07 20:12:54 +000011011 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berg7f6cf312011-11-04 11:18:15 +010011012 NL80211_CMD_PROBE_CLIENT);
Dan Carpentercb35fba2013-08-14 14:50:01 +030011013 if (!hdr) {
11014 err = -ENOBUFS;
Johannes Berg7f6cf312011-11-04 11:18:15 +010011015 goto free_msg;
11016 }
11017
11018 addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
11019
Hila Gonene35e4d22012-06-27 17:19:42 +030011020 err = rdev_probe_client(rdev, dev, addr, &cookie);
Johannes Berg7f6cf312011-11-04 11:18:15 +010011021 if (err)
11022 goto free_msg;
11023
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020011024 if (nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie,
11025 NL80211_ATTR_PAD))
David S. Miller9360ffd2012-03-29 04:41:26 -040011026 goto nla_put_failure;
Johannes Berg7f6cf312011-11-04 11:18:15 +010011027
11028 genlmsg_end(msg, hdr);
11029
11030 return genlmsg_reply(msg, info);
11031
11032 nla_put_failure:
11033 err = -ENOBUFS;
11034 free_msg:
11035 nlmsg_free(msg);
11036 return err;
11037}
11038
Johannes Berg5e760232011-11-04 11:18:17 +010011039static int nl80211_register_beacons(struct sk_buff *skb, struct genl_info *info)
11040{
11041 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Ben Greear37c73b52012-10-26 14:49:25 -070011042 struct cfg80211_beacon_registration *reg, *nreg;
11043 int rv;
Johannes Berg5e760232011-11-04 11:18:17 +010011044
11045 if (!(rdev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS))
11046 return -EOPNOTSUPP;
11047
Ben Greear37c73b52012-10-26 14:49:25 -070011048 nreg = kzalloc(sizeof(*nreg), GFP_KERNEL);
11049 if (!nreg)
11050 return -ENOMEM;
Johannes Berg5e760232011-11-04 11:18:17 +010011051
Ben Greear37c73b52012-10-26 14:49:25 -070011052 /* First, check if already registered. */
11053 spin_lock_bh(&rdev->beacon_registrations_lock);
11054 list_for_each_entry(reg, &rdev->beacon_registrations, list) {
11055 if (reg->nlportid == info->snd_portid) {
11056 rv = -EALREADY;
11057 goto out_err;
11058 }
11059 }
11060 /* Add it to the list */
11061 nreg->nlportid = info->snd_portid;
11062 list_add(&nreg->list, &rdev->beacon_registrations);
11063
11064 spin_unlock_bh(&rdev->beacon_registrations_lock);
Johannes Berg5e760232011-11-04 11:18:17 +010011065
11066 return 0;
Ben Greear37c73b52012-10-26 14:49:25 -070011067out_err:
11068 spin_unlock_bh(&rdev->beacon_registrations_lock);
11069 kfree(nreg);
11070 return rv;
Johannes Berg5e760232011-11-04 11:18:17 +010011071}
11072
Johannes Berg98104fde2012-06-16 00:19:54 +020011073static int nl80211_start_p2p_device(struct sk_buff *skb, struct genl_info *info)
11074{
11075 struct cfg80211_registered_device *rdev = info->user_ptr[0];
11076 struct wireless_dev *wdev = info->user_ptr[1];
11077 int err;
11078
11079 if (!rdev->ops->start_p2p_device)
11080 return -EOPNOTSUPP;
11081
11082 if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE)
11083 return -EOPNOTSUPP;
11084
Arend Van Spriel73c7da32016-10-20 20:08:22 +010011085 if (wdev_running(wdev))
Johannes Berg98104fde2012-06-16 00:19:54 +020011086 return 0;
11087
Luciano Coelhob6a55012014-02-27 11:07:21 +020011088 if (rfkill_blocked(rdev->rfkill))
11089 return -ERFKILL;
Johannes Berg98104fde2012-06-16 00:19:54 +020011090
Johannes Bergeeb126e2012-10-23 15:16:50 +020011091 err = rdev_start_p2p_device(rdev, wdev);
Johannes Berg98104fde2012-06-16 00:19:54 +020011092 if (err)
11093 return err;
11094
Arend Van Spriel73c7da32016-10-20 20:08:22 +010011095 wdev->is_running = true;
Johannes Berg98104fde2012-06-16 00:19:54 +020011096 rdev->opencount++;
Johannes Berg98104fde2012-06-16 00:19:54 +020011097
11098 return 0;
11099}
11100
11101static int nl80211_stop_p2p_device(struct sk_buff *skb, struct genl_info *info)
11102{
11103 struct cfg80211_registered_device *rdev = info->user_ptr[0];
11104 struct wireless_dev *wdev = info->user_ptr[1];
11105
11106 if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE)
11107 return -EOPNOTSUPP;
11108
11109 if (!rdev->ops->stop_p2p_device)
11110 return -EOPNOTSUPP;
11111
Johannes Bergf9f47522013-03-19 15:04:07 +010011112 cfg80211_stop_p2p_device(rdev, wdev);
Johannes Berg98104fde2012-06-16 00:19:54 +020011113
11114 return 0;
11115}
11116
Ayala Bekercb3b7d82016-09-20 17:31:13 +030011117static int nl80211_start_nan(struct sk_buff *skb, struct genl_info *info)
11118{
11119 struct cfg80211_registered_device *rdev = info->user_ptr[0];
11120 struct wireless_dev *wdev = info->user_ptr[1];
11121 struct cfg80211_nan_conf conf = {};
11122 int err;
11123
11124 if (wdev->iftype != NL80211_IFTYPE_NAN)
11125 return -EOPNOTSUPP;
11126
Johannes Bergeeb04a92016-11-21 13:55:48 +010011127 if (wdev_running(wdev))
Ayala Bekercb3b7d82016-09-20 17:31:13 +030011128 return -EEXIST;
11129
11130 if (rfkill_blocked(rdev->rfkill))
11131 return -ERFKILL;
11132
11133 if (!info->attrs[NL80211_ATTR_NAN_MASTER_PREF])
11134 return -EINVAL;
11135
Ayala Bekercb3b7d82016-09-20 17:31:13 +030011136 conf.master_pref =
11137 nla_get_u8(info->attrs[NL80211_ATTR_NAN_MASTER_PREF]);
11138 if (!conf.master_pref)
11139 return -EINVAL;
11140
Luca Coelho85859892017-02-08 15:00:34 +020011141 if (info->attrs[NL80211_ATTR_BANDS]) {
11142 u32 bands = nla_get_u32(info->attrs[NL80211_ATTR_BANDS]);
11143
11144 if (bands & ~(u32)wdev->wiphy->nan_supported_bands)
11145 return -EOPNOTSUPP;
11146
11147 if (bands && !(bands & BIT(NL80211_BAND_2GHZ)))
11148 return -EINVAL;
11149
11150 conf.bands = bands;
11151 }
Ayala Bekercb3b7d82016-09-20 17:31:13 +030011152
11153 err = rdev_start_nan(rdev, wdev, &conf);
11154 if (err)
11155 return err;
11156
Arend Van Spriel73c7da32016-10-20 20:08:22 +010011157 wdev->is_running = true;
Ayala Bekercb3b7d82016-09-20 17:31:13 +030011158 rdev->opencount++;
11159
11160 return 0;
11161}
11162
11163static int nl80211_stop_nan(struct sk_buff *skb, struct genl_info *info)
11164{
11165 struct cfg80211_registered_device *rdev = info->user_ptr[0];
11166 struct wireless_dev *wdev = info->user_ptr[1];
11167
11168 if (wdev->iftype != NL80211_IFTYPE_NAN)
11169 return -EOPNOTSUPP;
11170
11171 cfg80211_stop_nan(rdev, wdev);
11172
11173 return 0;
11174}
11175
Ayala Bekera442b762016-09-20 17:31:15 +030011176static int validate_nan_filter(struct nlattr *filter_attr)
11177{
11178 struct nlattr *attr;
11179 int len = 0, n_entries = 0, rem;
11180
11181 nla_for_each_nested(attr, filter_attr, rem) {
11182 len += nla_len(attr);
11183 n_entries++;
11184 }
11185
11186 if (len >= U8_MAX)
11187 return -EINVAL;
11188
11189 return n_entries;
11190}
11191
11192static int handle_nan_filter(struct nlattr *attr_filter,
11193 struct cfg80211_nan_func *func,
11194 bool tx)
11195{
11196 struct nlattr *attr;
11197 int n_entries, rem, i;
11198 struct cfg80211_nan_func_filter *filter;
11199
11200 n_entries = validate_nan_filter(attr_filter);
11201 if (n_entries < 0)
11202 return n_entries;
11203
11204 BUILD_BUG_ON(sizeof(*func->rx_filters) != sizeof(*func->tx_filters));
11205
11206 filter = kcalloc(n_entries, sizeof(*func->rx_filters), GFP_KERNEL);
11207 if (!filter)
11208 return -ENOMEM;
11209
11210 i = 0;
11211 nla_for_each_nested(attr, attr_filter, rem) {
Thomas Grafb15ca182016-10-26 10:53:16 +020011212 filter[i].filter = nla_memdup(attr, GFP_KERNEL);
Ayala Bekera442b762016-09-20 17:31:15 +030011213 filter[i].len = nla_len(attr);
11214 i++;
11215 }
11216 if (tx) {
11217 func->num_tx_filters = n_entries;
11218 func->tx_filters = filter;
11219 } else {
11220 func->num_rx_filters = n_entries;
11221 func->rx_filters = filter;
11222 }
11223
11224 return 0;
11225}
11226
11227static int nl80211_nan_add_func(struct sk_buff *skb,
11228 struct genl_info *info)
11229{
11230 struct cfg80211_registered_device *rdev = info->user_ptr[0];
11231 struct wireless_dev *wdev = info->user_ptr[1];
11232 struct nlattr *tb[NUM_NL80211_NAN_FUNC_ATTR], *func_attr;
11233 struct cfg80211_nan_func *func;
11234 struct sk_buff *msg = NULL;
11235 void *hdr = NULL;
11236 int err = 0;
11237
11238 if (wdev->iftype != NL80211_IFTYPE_NAN)
11239 return -EOPNOTSUPP;
11240
Arend Van Spriel73c7da32016-10-20 20:08:22 +010011241 if (!wdev_running(wdev))
Ayala Bekera442b762016-09-20 17:31:15 +030011242 return -ENOTCONN;
11243
11244 if (!info->attrs[NL80211_ATTR_NAN_FUNC])
11245 return -EINVAL;
11246
Johannes Bergbfe2c7b2016-10-26 14:42:21 +020011247 err = nla_parse_nested(tb, NL80211_NAN_FUNC_ATTR_MAX,
11248 info->attrs[NL80211_ATTR_NAN_FUNC],
Johannes Bergfe521452017-04-12 14:34:08 +020011249 nl80211_nan_func_policy, info->extack);
Ayala Bekera442b762016-09-20 17:31:15 +030011250 if (err)
11251 return err;
11252
11253 func = kzalloc(sizeof(*func), GFP_KERNEL);
11254 if (!func)
11255 return -ENOMEM;
11256
11257 func->cookie = wdev->wiphy->cookie_counter++;
11258
11259 if (!tb[NL80211_NAN_FUNC_TYPE] ||
11260 nla_get_u8(tb[NL80211_NAN_FUNC_TYPE]) > NL80211_NAN_FUNC_MAX_TYPE) {
11261 err = -EINVAL;
11262 goto out;
11263 }
11264
11265
11266 func->type = nla_get_u8(tb[NL80211_NAN_FUNC_TYPE]);
11267
11268 if (!tb[NL80211_NAN_FUNC_SERVICE_ID]) {
11269 err = -EINVAL;
11270 goto out;
11271 }
11272
11273 memcpy(func->service_id, nla_data(tb[NL80211_NAN_FUNC_SERVICE_ID]),
11274 sizeof(func->service_id));
11275
11276 func->close_range =
11277 nla_get_flag(tb[NL80211_NAN_FUNC_CLOSE_RANGE]);
11278
11279 if (tb[NL80211_NAN_FUNC_SERVICE_INFO]) {
11280 func->serv_spec_info_len =
11281 nla_len(tb[NL80211_NAN_FUNC_SERVICE_INFO]);
11282 func->serv_spec_info =
11283 kmemdup(nla_data(tb[NL80211_NAN_FUNC_SERVICE_INFO]),
11284 func->serv_spec_info_len,
11285 GFP_KERNEL);
11286 if (!func->serv_spec_info) {
11287 err = -ENOMEM;
11288 goto out;
11289 }
11290 }
11291
11292 if (tb[NL80211_NAN_FUNC_TTL])
11293 func->ttl = nla_get_u32(tb[NL80211_NAN_FUNC_TTL]);
11294
11295 switch (func->type) {
11296 case NL80211_NAN_FUNC_PUBLISH:
11297 if (!tb[NL80211_NAN_FUNC_PUBLISH_TYPE]) {
11298 err = -EINVAL;
11299 goto out;
11300 }
11301
11302 func->publish_type =
11303 nla_get_u8(tb[NL80211_NAN_FUNC_PUBLISH_TYPE]);
11304 func->publish_bcast =
11305 nla_get_flag(tb[NL80211_NAN_FUNC_PUBLISH_BCAST]);
11306
11307 if ((!(func->publish_type & NL80211_NAN_SOLICITED_PUBLISH)) &&
11308 func->publish_bcast) {
11309 err = -EINVAL;
11310 goto out;
11311 }
11312 break;
11313 case NL80211_NAN_FUNC_SUBSCRIBE:
11314 func->subscribe_active =
11315 nla_get_flag(tb[NL80211_NAN_FUNC_SUBSCRIBE_ACTIVE]);
11316 break;
11317 case NL80211_NAN_FUNC_FOLLOW_UP:
11318 if (!tb[NL80211_NAN_FUNC_FOLLOW_UP_ID] ||
11319 !tb[NL80211_NAN_FUNC_FOLLOW_UP_REQ_ID]) {
11320 err = -EINVAL;
11321 goto out;
11322 }
11323
11324 func->followup_id =
11325 nla_get_u8(tb[NL80211_NAN_FUNC_FOLLOW_UP_ID]);
11326 func->followup_reqid =
11327 nla_get_u8(tb[NL80211_NAN_FUNC_FOLLOW_UP_REQ_ID]);
11328 memcpy(func->followup_dest.addr,
11329 nla_data(tb[NL80211_NAN_FUNC_FOLLOW_UP_DEST]),
11330 sizeof(func->followup_dest.addr));
11331 if (func->ttl) {
11332 err = -EINVAL;
11333 goto out;
11334 }
11335 break;
11336 default:
11337 err = -EINVAL;
11338 goto out;
11339 }
11340
11341 if (tb[NL80211_NAN_FUNC_SRF]) {
11342 struct nlattr *srf_tb[NUM_NL80211_NAN_SRF_ATTR];
11343
Johannes Bergbfe2c7b2016-10-26 14:42:21 +020011344 err = nla_parse_nested(srf_tb, NL80211_NAN_SRF_ATTR_MAX,
11345 tb[NL80211_NAN_FUNC_SRF],
Johannes Bergfe521452017-04-12 14:34:08 +020011346 nl80211_nan_srf_policy, info->extack);
Ayala Bekera442b762016-09-20 17:31:15 +030011347 if (err)
11348 goto out;
11349
11350 func->srf_include =
11351 nla_get_flag(srf_tb[NL80211_NAN_SRF_INCLUDE]);
11352
11353 if (srf_tb[NL80211_NAN_SRF_BF]) {
11354 if (srf_tb[NL80211_NAN_SRF_MAC_ADDRS] ||
11355 !srf_tb[NL80211_NAN_SRF_BF_IDX]) {
11356 err = -EINVAL;
11357 goto out;
11358 }
11359
11360 func->srf_bf_len =
11361 nla_len(srf_tb[NL80211_NAN_SRF_BF]);
11362 func->srf_bf =
11363 kmemdup(nla_data(srf_tb[NL80211_NAN_SRF_BF]),
11364 func->srf_bf_len, GFP_KERNEL);
11365 if (!func->srf_bf) {
11366 err = -ENOMEM;
11367 goto out;
11368 }
11369
11370 func->srf_bf_idx =
11371 nla_get_u8(srf_tb[NL80211_NAN_SRF_BF_IDX]);
11372 } else {
11373 struct nlattr *attr, *mac_attr =
11374 srf_tb[NL80211_NAN_SRF_MAC_ADDRS];
11375 int n_entries, rem, i = 0;
11376
11377 if (!mac_attr) {
11378 err = -EINVAL;
11379 goto out;
11380 }
11381
11382 n_entries = validate_acl_mac_addrs(mac_attr);
11383 if (n_entries <= 0) {
11384 err = -EINVAL;
11385 goto out;
11386 }
11387
11388 func->srf_num_macs = n_entries;
11389 func->srf_macs =
11390 kzalloc(sizeof(*func->srf_macs) * n_entries,
11391 GFP_KERNEL);
11392 if (!func->srf_macs) {
11393 err = -ENOMEM;
11394 goto out;
11395 }
11396
11397 nla_for_each_nested(attr, mac_attr, rem)
11398 memcpy(func->srf_macs[i++].addr, nla_data(attr),
11399 sizeof(*func->srf_macs));
11400 }
11401 }
11402
11403 if (tb[NL80211_NAN_FUNC_TX_MATCH_FILTER]) {
11404 err = handle_nan_filter(tb[NL80211_NAN_FUNC_TX_MATCH_FILTER],
11405 func, true);
11406 if (err)
11407 goto out;
11408 }
11409
11410 if (tb[NL80211_NAN_FUNC_RX_MATCH_FILTER]) {
11411 err = handle_nan_filter(tb[NL80211_NAN_FUNC_RX_MATCH_FILTER],
11412 func, false);
11413 if (err)
11414 goto out;
11415 }
11416
11417 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
11418 if (!msg) {
11419 err = -ENOMEM;
11420 goto out;
11421 }
11422
11423 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
11424 NL80211_CMD_ADD_NAN_FUNCTION);
11425 /* This can't really happen - we just allocated 4KB */
11426 if (WARN_ON(!hdr)) {
11427 err = -ENOMEM;
11428 goto out;
11429 }
11430
11431 err = rdev_add_nan_func(rdev, wdev, func);
11432out:
11433 if (err < 0) {
11434 cfg80211_free_nan_func(func);
11435 nlmsg_free(msg);
11436 return err;
11437 }
11438
11439 /* propagate the instance id and cookie to userspace */
11440 if (nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, func->cookie,
11441 NL80211_ATTR_PAD))
11442 goto nla_put_failure;
11443
11444 func_attr = nla_nest_start(msg, NL80211_ATTR_NAN_FUNC);
11445 if (!func_attr)
11446 goto nla_put_failure;
11447
11448 if (nla_put_u8(msg, NL80211_NAN_FUNC_INSTANCE_ID,
11449 func->instance_id))
11450 goto nla_put_failure;
11451
11452 nla_nest_end(msg, func_attr);
11453
11454 genlmsg_end(msg, hdr);
11455 return genlmsg_reply(msg, info);
11456
11457nla_put_failure:
11458 nlmsg_free(msg);
11459 return -ENOBUFS;
11460}
11461
11462static int nl80211_nan_del_func(struct sk_buff *skb,
11463 struct genl_info *info)
11464{
11465 struct cfg80211_registered_device *rdev = info->user_ptr[0];
11466 struct wireless_dev *wdev = info->user_ptr[1];
11467 u64 cookie;
11468
11469 if (wdev->iftype != NL80211_IFTYPE_NAN)
11470 return -EOPNOTSUPP;
11471
Arend Van Spriel73c7da32016-10-20 20:08:22 +010011472 if (!wdev_running(wdev))
Ayala Bekera442b762016-09-20 17:31:15 +030011473 return -ENOTCONN;
11474
11475 if (!info->attrs[NL80211_ATTR_COOKIE])
11476 return -EINVAL;
11477
Ayala Bekera442b762016-09-20 17:31:15 +030011478 cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]);
11479
11480 rdev_del_nan_func(rdev, wdev, cookie);
11481
11482 return 0;
11483}
11484
Ayala Bekera5a9dcf2016-09-20 17:31:16 +030011485static int nl80211_nan_change_config(struct sk_buff *skb,
11486 struct genl_info *info)
11487{
11488 struct cfg80211_registered_device *rdev = info->user_ptr[0];
11489 struct wireless_dev *wdev = info->user_ptr[1];
11490 struct cfg80211_nan_conf conf = {};
11491 u32 changed = 0;
11492
11493 if (wdev->iftype != NL80211_IFTYPE_NAN)
11494 return -EOPNOTSUPP;
11495
Arend Van Spriel73c7da32016-10-20 20:08:22 +010011496 if (!wdev_running(wdev))
Ayala Bekera5a9dcf2016-09-20 17:31:16 +030011497 return -ENOTCONN;
11498
11499 if (info->attrs[NL80211_ATTR_NAN_MASTER_PREF]) {
11500 conf.master_pref =
11501 nla_get_u8(info->attrs[NL80211_ATTR_NAN_MASTER_PREF]);
11502 if (conf.master_pref <= 1 || conf.master_pref == 255)
11503 return -EINVAL;
11504
11505 changed |= CFG80211_NAN_CONF_CHANGED_PREF;
11506 }
11507
Luca Coelho85859892017-02-08 15:00:34 +020011508 if (info->attrs[NL80211_ATTR_BANDS]) {
11509 u32 bands = nla_get_u32(info->attrs[NL80211_ATTR_BANDS]);
11510
11511 if (bands & ~(u32)wdev->wiphy->nan_supported_bands)
11512 return -EOPNOTSUPP;
11513
11514 if (bands && !(bands & BIT(NL80211_BAND_2GHZ)))
11515 return -EINVAL;
11516
11517 conf.bands = bands;
11518 changed |= CFG80211_NAN_CONF_CHANGED_BANDS;
Ayala Bekera5a9dcf2016-09-20 17:31:16 +030011519 }
11520
11521 if (!changed)
11522 return -EINVAL;
11523
11524 return rdev_nan_change_conf(rdev, wdev, &conf, changed);
11525}
11526
Ayala Beker50bcd312016-09-20 17:31:17 +030011527void cfg80211_nan_match(struct wireless_dev *wdev,
11528 struct cfg80211_nan_match_params *match, gfp_t gfp)
11529{
11530 struct wiphy *wiphy = wdev->wiphy;
11531 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
11532 struct nlattr *match_attr, *local_func_attr, *peer_func_attr;
11533 struct sk_buff *msg;
11534 void *hdr;
11535
11536 if (WARN_ON(!match->inst_id || !match->peer_inst_id || !match->addr))
11537 return;
11538
11539 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
11540 if (!msg)
11541 return;
11542
11543 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NAN_MATCH);
11544 if (!hdr) {
11545 nlmsg_free(msg);
11546 return;
11547 }
11548
11549 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
11550 (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
11551 wdev->netdev->ifindex)) ||
11552 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
11553 NL80211_ATTR_PAD))
11554 goto nla_put_failure;
11555
11556 if (nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, match->cookie,
11557 NL80211_ATTR_PAD) ||
11558 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, match->addr))
11559 goto nla_put_failure;
11560
11561 match_attr = nla_nest_start(msg, NL80211_ATTR_NAN_MATCH);
11562 if (!match_attr)
11563 goto nla_put_failure;
11564
11565 local_func_attr = nla_nest_start(msg, NL80211_NAN_MATCH_FUNC_LOCAL);
11566 if (!local_func_attr)
11567 goto nla_put_failure;
11568
11569 if (nla_put_u8(msg, NL80211_NAN_FUNC_INSTANCE_ID, match->inst_id))
11570 goto nla_put_failure;
11571
11572 nla_nest_end(msg, local_func_attr);
11573
11574 peer_func_attr = nla_nest_start(msg, NL80211_NAN_MATCH_FUNC_PEER);
11575 if (!peer_func_attr)
11576 goto nla_put_failure;
11577
11578 if (nla_put_u8(msg, NL80211_NAN_FUNC_TYPE, match->type) ||
11579 nla_put_u8(msg, NL80211_NAN_FUNC_INSTANCE_ID, match->peer_inst_id))
11580 goto nla_put_failure;
11581
11582 if (match->info && match->info_len &&
11583 nla_put(msg, NL80211_NAN_FUNC_SERVICE_INFO, match->info_len,
11584 match->info))
11585 goto nla_put_failure;
11586
11587 nla_nest_end(msg, peer_func_attr);
11588 nla_nest_end(msg, match_attr);
11589 genlmsg_end(msg, hdr);
11590
11591 if (!wdev->owner_nlportid)
11592 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy),
11593 msg, 0, NL80211_MCGRP_NAN, gfp);
11594 else
11595 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg,
11596 wdev->owner_nlportid);
11597
11598 return;
11599
11600nla_put_failure:
11601 nlmsg_free(msg);
11602}
11603EXPORT_SYMBOL(cfg80211_nan_match);
11604
Ayala Beker368e5a72016-09-20 17:31:18 +030011605void cfg80211_nan_func_terminated(struct wireless_dev *wdev,
11606 u8 inst_id,
11607 enum nl80211_nan_func_term_reason reason,
11608 u64 cookie, gfp_t gfp)
11609{
11610 struct wiphy *wiphy = wdev->wiphy;
11611 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
11612 struct sk_buff *msg;
11613 struct nlattr *func_attr;
11614 void *hdr;
11615
11616 if (WARN_ON(!inst_id))
11617 return;
11618
11619 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
11620 if (!msg)
11621 return;
11622
11623 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DEL_NAN_FUNCTION);
11624 if (!hdr) {
11625 nlmsg_free(msg);
11626 return;
11627 }
11628
11629 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
11630 (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
11631 wdev->netdev->ifindex)) ||
11632 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
11633 NL80211_ATTR_PAD))
11634 goto nla_put_failure;
11635
11636 if (nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie,
11637 NL80211_ATTR_PAD))
11638 goto nla_put_failure;
11639
11640 func_attr = nla_nest_start(msg, NL80211_ATTR_NAN_FUNC);
11641 if (!func_attr)
11642 goto nla_put_failure;
11643
11644 if (nla_put_u8(msg, NL80211_NAN_FUNC_INSTANCE_ID, inst_id) ||
11645 nla_put_u8(msg, NL80211_NAN_FUNC_TERM_REASON, reason))
11646 goto nla_put_failure;
11647
11648 nla_nest_end(msg, func_attr);
11649 genlmsg_end(msg, hdr);
11650
11651 if (!wdev->owner_nlportid)
11652 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy),
11653 msg, 0, NL80211_MCGRP_NAN, gfp);
11654 else
11655 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg,
11656 wdev->owner_nlportid);
11657
11658 return;
11659
11660nla_put_failure:
11661 nlmsg_free(msg);
11662}
11663EXPORT_SYMBOL(cfg80211_nan_func_terminated);
11664
Johannes Berg3713b4e2013-02-14 16:19:38 +010011665static int nl80211_get_protocol_features(struct sk_buff *skb,
11666 struct genl_info *info)
11667{
11668 void *hdr;
11669 struct sk_buff *msg;
11670
11671 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
11672 if (!msg)
11673 return -ENOMEM;
11674
11675 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
11676 NL80211_CMD_GET_PROTOCOL_FEATURES);
11677 if (!hdr)
11678 goto nla_put_failure;
11679
11680 if (nla_put_u32(msg, NL80211_ATTR_PROTOCOL_FEATURES,
11681 NL80211_PROTOCOL_FEATURE_SPLIT_WIPHY_DUMP))
11682 goto nla_put_failure;
11683
11684 genlmsg_end(msg, hdr);
11685 return genlmsg_reply(msg, info);
11686
11687 nla_put_failure:
11688 kfree_skb(msg);
11689 return -ENOBUFS;
11690}
11691
Jouni Malinen355199e2013-02-27 17:14:27 +020011692static int nl80211_update_ft_ies(struct sk_buff *skb, struct genl_info *info)
11693{
11694 struct cfg80211_registered_device *rdev = info->user_ptr[0];
11695 struct cfg80211_update_ft_ies_params ft_params;
11696 struct net_device *dev = info->user_ptr[1];
11697
11698 if (!rdev->ops->update_ft_ies)
11699 return -EOPNOTSUPP;
11700
11701 if (!info->attrs[NL80211_ATTR_MDID] ||
11702 !is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
11703 return -EINVAL;
11704
11705 memset(&ft_params, 0, sizeof(ft_params));
11706 ft_params.md = nla_get_u16(info->attrs[NL80211_ATTR_MDID]);
11707 ft_params.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
11708 ft_params.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
11709
11710 return rdev_update_ft_ies(rdev, dev, &ft_params);
11711}
11712
Arend van Spriel5de17982013-04-18 15:49:00 +020011713static int nl80211_crit_protocol_start(struct sk_buff *skb,
11714 struct genl_info *info)
11715{
11716 struct cfg80211_registered_device *rdev = info->user_ptr[0];
11717 struct wireless_dev *wdev = info->user_ptr[1];
11718 enum nl80211_crit_proto_id proto = NL80211_CRIT_PROTO_UNSPEC;
11719 u16 duration;
11720 int ret;
11721
11722 if (!rdev->ops->crit_proto_start)
11723 return -EOPNOTSUPP;
11724
11725 if (WARN_ON(!rdev->ops->crit_proto_stop))
11726 return -EINVAL;
11727
11728 if (rdev->crit_proto_nlportid)
11729 return -EBUSY;
11730
11731 /* determine protocol if provided */
11732 if (info->attrs[NL80211_ATTR_CRIT_PROT_ID])
11733 proto = nla_get_u16(info->attrs[NL80211_ATTR_CRIT_PROT_ID]);
11734
11735 if (proto >= NUM_NL80211_CRIT_PROTO)
11736 return -EINVAL;
11737
11738 /* timeout must be provided */
11739 if (!info->attrs[NL80211_ATTR_MAX_CRIT_PROT_DURATION])
11740 return -EINVAL;
11741
11742 duration =
11743 nla_get_u16(info->attrs[NL80211_ATTR_MAX_CRIT_PROT_DURATION]);
11744
11745 if (duration > NL80211_CRIT_PROTO_MAX_DURATION)
11746 return -ERANGE;
11747
11748 ret = rdev_crit_proto_start(rdev, wdev, proto, duration);
11749 if (!ret)
11750 rdev->crit_proto_nlportid = info->snd_portid;
11751
11752 return ret;
11753}
11754
11755static int nl80211_crit_protocol_stop(struct sk_buff *skb,
11756 struct genl_info *info)
11757{
11758 struct cfg80211_registered_device *rdev = info->user_ptr[0];
11759 struct wireless_dev *wdev = info->user_ptr[1];
11760
11761 if (!rdev->ops->crit_proto_stop)
11762 return -EOPNOTSUPP;
11763
11764 if (rdev->crit_proto_nlportid) {
11765 rdev->crit_proto_nlportid = 0;
11766 rdev_crit_proto_stop(rdev, wdev);
11767 }
11768 return 0;
11769}
11770
Johannes Bergad7e7182013-11-13 13:37:47 +010011771static int nl80211_vendor_cmd(struct sk_buff *skb, struct genl_info *info)
11772{
11773 struct cfg80211_registered_device *rdev = info->user_ptr[0];
11774 struct wireless_dev *wdev =
11775 __cfg80211_wdev_from_attrs(genl_info_net(info), info->attrs);
11776 int i, err;
11777 u32 vid, subcmd;
11778
11779 if (!rdev->wiphy.vendor_commands)
11780 return -EOPNOTSUPP;
11781
11782 if (IS_ERR(wdev)) {
11783 err = PTR_ERR(wdev);
11784 if (err != -EINVAL)
11785 return err;
11786 wdev = NULL;
11787 } else if (wdev->wiphy != &rdev->wiphy) {
11788 return -EINVAL;
11789 }
11790
11791 if (!info->attrs[NL80211_ATTR_VENDOR_ID] ||
11792 !info->attrs[NL80211_ATTR_VENDOR_SUBCMD])
11793 return -EINVAL;
11794
11795 vid = nla_get_u32(info->attrs[NL80211_ATTR_VENDOR_ID]);
11796 subcmd = nla_get_u32(info->attrs[NL80211_ATTR_VENDOR_SUBCMD]);
11797 for (i = 0; i < rdev->wiphy.n_vendor_commands; i++) {
11798 const struct wiphy_vendor_command *vcmd;
11799 void *data = NULL;
11800 int len = 0;
11801
11802 vcmd = &rdev->wiphy.vendor_commands[i];
11803
11804 if (vcmd->info.vendor_id != vid || vcmd->info.subcmd != subcmd)
11805 continue;
11806
11807 if (vcmd->flags & (WIPHY_VENDOR_CMD_NEED_WDEV |
11808 WIPHY_VENDOR_CMD_NEED_NETDEV)) {
11809 if (!wdev)
11810 return -EINVAL;
11811 if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_NETDEV &&
11812 !wdev->netdev)
11813 return -EINVAL;
11814
11815 if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_RUNNING) {
Arend Van Spriel73c7da32016-10-20 20:08:22 +010011816 if (!wdev_running(wdev))
Johannes Bergad7e7182013-11-13 13:37:47 +010011817 return -ENETDOWN;
11818 }
Johannes Berg7bdbe402015-08-15 22:39:49 +030011819
11820 if (!vcmd->doit)
11821 return -EOPNOTSUPP;
Johannes Bergad7e7182013-11-13 13:37:47 +010011822 } else {
11823 wdev = NULL;
11824 }
11825
11826 if (info->attrs[NL80211_ATTR_VENDOR_DATA]) {
11827 data = nla_data(info->attrs[NL80211_ATTR_VENDOR_DATA]);
11828 len = nla_len(info->attrs[NL80211_ATTR_VENDOR_DATA]);
11829 }
11830
11831 rdev->cur_cmd_info = info;
11832 err = rdev->wiphy.vendor_commands[i].doit(&rdev->wiphy, wdev,
11833 data, len);
11834 rdev->cur_cmd_info = NULL;
11835 return err;
11836 }
11837
11838 return -EOPNOTSUPP;
11839}
11840
Johannes Berg7bdbe402015-08-15 22:39:49 +030011841static int nl80211_prepare_vendor_dump(struct sk_buff *skb,
11842 struct netlink_callback *cb,
11843 struct cfg80211_registered_device **rdev,
11844 struct wireless_dev **wdev)
11845{
Johannes Bergc90c39d2016-10-24 14:40:01 +020011846 struct nlattr **attrbuf = genl_family_attrbuf(&nl80211_fam);
Johannes Berg7bdbe402015-08-15 22:39:49 +030011847 u32 vid, subcmd;
11848 unsigned int i;
11849 int vcmd_idx = -1;
11850 int err;
11851 void *data = NULL;
11852 unsigned int data_len = 0;
11853
Johannes Berg7bdbe402015-08-15 22:39:49 +030011854 if (cb->args[0]) {
11855 /* subtract the 1 again here */
11856 struct wiphy *wiphy = wiphy_idx_to_wiphy(cb->args[0] - 1);
11857 struct wireless_dev *tmp;
11858
Johannes Bergea90e0d2017-03-15 14:26:04 +010011859 if (!wiphy)
11860 return -ENODEV;
Johannes Berg7bdbe402015-08-15 22:39:49 +030011861 *rdev = wiphy_to_rdev(wiphy);
11862 *wdev = NULL;
11863
11864 if (cb->args[1]) {
Johannes Berg53873f12016-05-03 16:52:04 +030011865 list_for_each_entry(tmp, &wiphy->wdev_list, list) {
Johannes Berg7bdbe402015-08-15 22:39:49 +030011866 if (tmp->identifier == cb->args[1] - 1) {
11867 *wdev = tmp;
11868 break;
11869 }
11870 }
11871 }
11872
11873 /* keep rtnl locked in successful case */
11874 return 0;
11875 }
11876
Johannes Bergfceb6432017-04-12 14:34:07 +020011877 err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize, attrbuf,
11878 nl80211_fam.maxattr, nl80211_policy, NULL);
Johannes Berg7bdbe402015-08-15 22:39:49 +030011879 if (err)
Johannes Bergea90e0d2017-03-15 14:26:04 +010011880 return err;
Johannes Berg7bdbe402015-08-15 22:39:49 +030011881
Johannes Bergc90c39d2016-10-24 14:40:01 +020011882 if (!attrbuf[NL80211_ATTR_VENDOR_ID] ||
Johannes Bergea90e0d2017-03-15 14:26:04 +010011883 !attrbuf[NL80211_ATTR_VENDOR_SUBCMD])
11884 return -EINVAL;
Johannes Berg7bdbe402015-08-15 22:39:49 +030011885
Johannes Bergc90c39d2016-10-24 14:40:01 +020011886 *wdev = __cfg80211_wdev_from_attrs(sock_net(skb->sk), attrbuf);
Johannes Berg7bdbe402015-08-15 22:39:49 +030011887 if (IS_ERR(*wdev))
11888 *wdev = NULL;
11889
Johannes Bergc90c39d2016-10-24 14:40:01 +020011890 *rdev = __cfg80211_rdev_from_attrs(sock_net(skb->sk), attrbuf);
Johannes Bergea90e0d2017-03-15 14:26:04 +010011891 if (IS_ERR(*rdev))
11892 return PTR_ERR(*rdev);
Johannes Berg7bdbe402015-08-15 22:39:49 +030011893
Johannes Bergc90c39d2016-10-24 14:40:01 +020011894 vid = nla_get_u32(attrbuf[NL80211_ATTR_VENDOR_ID]);
11895 subcmd = nla_get_u32(attrbuf[NL80211_ATTR_VENDOR_SUBCMD]);
Johannes Berg7bdbe402015-08-15 22:39:49 +030011896
11897 for (i = 0; i < (*rdev)->wiphy.n_vendor_commands; i++) {
11898 const struct wiphy_vendor_command *vcmd;
11899
11900 vcmd = &(*rdev)->wiphy.vendor_commands[i];
11901
11902 if (vcmd->info.vendor_id != vid || vcmd->info.subcmd != subcmd)
11903 continue;
11904
Johannes Bergea90e0d2017-03-15 14:26:04 +010011905 if (!vcmd->dumpit)
11906 return -EOPNOTSUPP;
Johannes Berg7bdbe402015-08-15 22:39:49 +030011907
11908 vcmd_idx = i;
11909 break;
11910 }
11911
Johannes Bergea90e0d2017-03-15 14:26:04 +010011912 if (vcmd_idx < 0)
11913 return -EOPNOTSUPP;
Johannes Berg7bdbe402015-08-15 22:39:49 +030011914
Johannes Bergc90c39d2016-10-24 14:40:01 +020011915 if (attrbuf[NL80211_ATTR_VENDOR_DATA]) {
11916 data = nla_data(attrbuf[NL80211_ATTR_VENDOR_DATA]);
11917 data_len = nla_len(attrbuf[NL80211_ATTR_VENDOR_DATA]);
Johannes Berg7bdbe402015-08-15 22:39:49 +030011918 }
11919
11920 /* 0 is the first index - add 1 to parse only once */
11921 cb->args[0] = (*rdev)->wiphy_idx + 1;
11922 /* add 1 to know if it was NULL */
11923 cb->args[1] = *wdev ? (*wdev)->identifier + 1 : 0;
11924 cb->args[2] = vcmd_idx;
11925 cb->args[3] = (unsigned long)data;
11926 cb->args[4] = data_len;
11927
11928 /* keep rtnl locked in successful case */
11929 return 0;
Johannes Berg7bdbe402015-08-15 22:39:49 +030011930}
11931
11932static int nl80211_vendor_cmd_dump(struct sk_buff *skb,
11933 struct netlink_callback *cb)
11934{
11935 struct cfg80211_registered_device *rdev;
11936 struct wireless_dev *wdev;
11937 unsigned int vcmd_idx;
11938 const struct wiphy_vendor_command *vcmd;
11939 void *data;
11940 int data_len;
11941 int err;
11942 struct nlattr *vendor_data;
11943
Johannes Bergea90e0d2017-03-15 14:26:04 +010011944 rtnl_lock();
Johannes Berg7bdbe402015-08-15 22:39:49 +030011945 err = nl80211_prepare_vendor_dump(skb, cb, &rdev, &wdev);
11946 if (err)
Johannes Bergea90e0d2017-03-15 14:26:04 +010011947 goto out;
Johannes Berg7bdbe402015-08-15 22:39:49 +030011948
11949 vcmd_idx = cb->args[2];
11950 data = (void *)cb->args[3];
11951 data_len = cb->args[4];
11952 vcmd = &rdev->wiphy.vendor_commands[vcmd_idx];
11953
11954 if (vcmd->flags & (WIPHY_VENDOR_CMD_NEED_WDEV |
11955 WIPHY_VENDOR_CMD_NEED_NETDEV)) {
Johannes Bergea90e0d2017-03-15 14:26:04 +010011956 if (!wdev) {
11957 err = -EINVAL;
11958 goto out;
11959 }
Johannes Berg7bdbe402015-08-15 22:39:49 +030011960 if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_NETDEV &&
Johannes Bergea90e0d2017-03-15 14:26:04 +010011961 !wdev->netdev) {
11962 err = -EINVAL;
11963 goto out;
11964 }
Johannes Berg7bdbe402015-08-15 22:39:49 +030011965
11966 if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_RUNNING) {
Johannes Bergea90e0d2017-03-15 14:26:04 +010011967 if (!wdev_running(wdev)) {
11968 err = -ENETDOWN;
11969 goto out;
11970 }
Johannes Berg7bdbe402015-08-15 22:39:49 +030011971 }
11972 }
11973
11974 while (1) {
11975 void *hdr = nl80211hdr_put(skb, NETLINK_CB(cb->skb).portid,
11976 cb->nlh->nlmsg_seq, NLM_F_MULTI,
11977 NL80211_CMD_VENDOR);
11978 if (!hdr)
11979 break;
11980
11981 if (nla_put_u32(skb, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020011982 (wdev && nla_put_u64_64bit(skb, NL80211_ATTR_WDEV,
11983 wdev_id(wdev),
11984 NL80211_ATTR_PAD))) {
Johannes Berg7bdbe402015-08-15 22:39:49 +030011985 genlmsg_cancel(skb, hdr);
11986 break;
11987 }
11988
11989 vendor_data = nla_nest_start(skb, NL80211_ATTR_VENDOR_DATA);
11990 if (!vendor_data) {
11991 genlmsg_cancel(skb, hdr);
11992 break;
11993 }
11994
11995 err = vcmd->dumpit(&rdev->wiphy, wdev, skb, data, data_len,
11996 (unsigned long *)&cb->args[5]);
11997 nla_nest_end(skb, vendor_data);
11998
11999 if (err == -ENOBUFS || err == -ENOENT) {
12000 genlmsg_cancel(skb, hdr);
12001 break;
12002 } else if (err) {
12003 genlmsg_cancel(skb, hdr);
12004 goto out;
12005 }
12006
12007 genlmsg_end(skb, hdr);
12008 }
12009
12010 err = skb->len;
12011 out:
12012 rtnl_unlock();
12013 return err;
12014}
12015
Johannes Bergad7e7182013-11-13 13:37:47 +010012016struct sk_buff *__cfg80211_alloc_reply_skb(struct wiphy *wiphy,
12017 enum nl80211_commands cmd,
12018 enum nl80211_attrs attr,
12019 int approxlen)
12020{
Zhao, Gangf26cbf42014-04-21 12:53:03 +080012021 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Bergad7e7182013-11-13 13:37:47 +010012022
12023 if (WARN_ON(!rdev->cur_cmd_info))
12024 return NULL;
12025
Ahmad Kholaif6c09e792015-02-26 15:26:53 +020012026 return __cfg80211_alloc_vendor_skb(rdev, NULL, approxlen,
Johannes Bergad7e7182013-11-13 13:37:47 +010012027 rdev->cur_cmd_info->snd_portid,
12028 rdev->cur_cmd_info->snd_seq,
Johannes Berg567ffc32013-12-18 14:43:31 +010012029 cmd, attr, NULL, GFP_KERNEL);
Johannes Bergad7e7182013-11-13 13:37:47 +010012030}
12031EXPORT_SYMBOL(__cfg80211_alloc_reply_skb);
12032
12033int cfg80211_vendor_cmd_reply(struct sk_buff *skb)
12034{
12035 struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0];
12036 void *hdr = ((void **)skb->cb)[1];
12037 struct nlattr *data = ((void **)skb->cb)[2];
12038
Johannes Bergbd8c78e2014-07-30 14:55:26 +020012039 /* clear CB data for netlink core to own from now on */
12040 memset(skb->cb, 0, sizeof(skb->cb));
12041
Johannes Bergad7e7182013-11-13 13:37:47 +010012042 if (WARN_ON(!rdev->cur_cmd_info)) {
12043 kfree_skb(skb);
12044 return -EINVAL;
12045 }
12046
12047 nla_nest_end(skb, data);
12048 genlmsg_end(skb, hdr);
12049 return genlmsg_reply(skb, rdev->cur_cmd_info);
12050}
12051EXPORT_SYMBOL_GPL(cfg80211_vendor_cmd_reply);
12052
Kyeyoon Parkfa9ffc72013-12-16 23:01:30 -080012053static int nl80211_set_qos_map(struct sk_buff *skb,
12054 struct genl_info *info)
12055{
12056 struct cfg80211_registered_device *rdev = info->user_ptr[0];
12057 struct cfg80211_qos_map *qos_map = NULL;
12058 struct net_device *dev = info->user_ptr[1];
12059 u8 *pos, len, num_des, des_len, des;
12060 int ret;
12061
12062 if (!rdev->ops->set_qos_map)
12063 return -EOPNOTSUPP;
12064
12065 if (info->attrs[NL80211_ATTR_QOS_MAP]) {
12066 pos = nla_data(info->attrs[NL80211_ATTR_QOS_MAP]);
12067 len = nla_len(info->attrs[NL80211_ATTR_QOS_MAP]);
12068
12069 if (len % 2 || len < IEEE80211_QOS_MAP_LEN_MIN ||
12070 len > IEEE80211_QOS_MAP_LEN_MAX)
12071 return -EINVAL;
12072
12073 qos_map = kzalloc(sizeof(struct cfg80211_qos_map), GFP_KERNEL);
12074 if (!qos_map)
12075 return -ENOMEM;
12076
12077 num_des = (len - IEEE80211_QOS_MAP_LEN_MIN) >> 1;
12078 if (num_des) {
12079 des_len = num_des *
12080 sizeof(struct cfg80211_dscp_exception);
12081 memcpy(qos_map->dscp_exception, pos, des_len);
12082 qos_map->num_des = num_des;
12083 for (des = 0; des < num_des; des++) {
12084 if (qos_map->dscp_exception[des].up > 7) {
12085 kfree(qos_map);
12086 return -EINVAL;
12087 }
12088 }
12089 pos += des_len;
12090 }
12091 memcpy(qos_map->up, pos, IEEE80211_QOS_MAP_LEN_MIN);
12092 }
12093
12094 wdev_lock(dev->ieee80211_ptr);
12095 ret = nl80211_key_allowed(dev->ieee80211_ptr);
12096 if (!ret)
12097 ret = rdev_set_qos_map(rdev, dev, qos_map);
12098 wdev_unlock(dev->ieee80211_ptr);
12099
12100 kfree(qos_map);
12101 return ret;
12102}
12103
Johannes Berg960d01a2014-09-09 22:55:35 +030012104static int nl80211_add_tx_ts(struct sk_buff *skb, struct genl_info *info)
12105{
12106 struct cfg80211_registered_device *rdev = info->user_ptr[0];
12107 struct net_device *dev = info->user_ptr[1];
12108 struct wireless_dev *wdev = dev->ieee80211_ptr;
12109 const u8 *peer;
12110 u8 tsid, up;
12111 u16 admitted_time = 0;
12112 int err;
12113
Johannes Berg723e73a2014-10-22 09:25:06 +020012114 if (!(rdev->wiphy.features & NL80211_FEATURE_SUPPORTS_WMM_ADMISSION))
Johannes Berg960d01a2014-09-09 22:55:35 +030012115 return -EOPNOTSUPP;
12116
12117 if (!info->attrs[NL80211_ATTR_TSID] || !info->attrs[NL80211_ATTR_MAC] ||
12118 !info->attrs[NL80211_ATTR_USER_PRIO])
12119 return -EINVAL;
12120
12121 tsid = nla_get_u8(info->attrs[NL80211_ATTR_TSID]);
12122 if (tsid >= IEEE80211_NUM_TIDS)
12123 return -EINVAL;
12124
12125 up = nla_get_u8(info->attrs[NL80211_ATTR_USER_PRIO]);
12126 if (up >= IEEE80211_NUM_UPS)
12127 return -EINVAL;
12128
12129 /* WMM uses TIDs 0-7 even for TSPEC */
Johannes Berg723e73a2014-10-22 09:25:06 +020012130 if (tsid >= IEEE80211_FIRST_TSPEC_TSID) {
Johannes Berg960d01a2014-09-09 22:55:35 +030012131 /* TODO: handle 802.11 TSPEC/admission control
Johannes Berg723e73a2014-10-22 09:25:06 +020012132 * need more attributes for that (e.g. BA session requirement);
12133 * change the WMM adminssion test above to allow both then
Johannes Berg960d01a2014-09-09 22:55:35 +030012134 */
12135 return -EINVAL;
12136 }
12137
12138 peer = nla_data(info->attrs[NL80211_ATTR_MAC]);
12139
12140 if (info->attrs[NL80211_ATTR_ADMITTED_TIME]) {
12141 admitted_time =
12142 nla_get_u16(info->attrs[NL80211_ATTR_ADMITTED_TIME]);
12143 if (!admitted_time)
12144 return -EINVAL;
12145 }
12146
12147 wdev_lock(wdev);
12148 switch (wdev->iftype) {
12149 case NL80211_IFTYPE_STATION:
12150 case NL80211_IFTYPE_P2P_CLIENT:
12151 if (wdev->current_bss)
12152 break;
12153 err = -ENOTCONN;
12154 goto out;
12155 default:
12156 err = -EOPNOTSUPP;
12157 goto out;
12158 }
12159
12160 err = rdev_add_tx_ts(rdev, dev, tsid, peer, up, admitted_time);
12161
12162 out:
12163 wdev_unlock(wdev);
12164 return err;
12165}
12166
12167static int nl80211_del_tx_ts(struct sk_buff *skb, struct genl_info *info)
12168{
12169 struct cfg80211_registered_device *rdev = info->user_ptr[0];
12170 struct net_device *dev = info->user_ptr[1];
12171 struct wireless_dev *wdev = dev->ieee80211_ptr;
12172 const u8 *peer;
12173 u8 tsid;
12174 int err;
12175
12176 if (!info->attrs[NL80211_ATTR_TSID] || !info->attrs[NL80211_ATTR_MAC])
12177 return -EINVAL;
12178
12179 tsid = nla_get_u8(info->attrs[NL80211_ATTR_TSID]);
12180 peer = nla_data(info->attrs[NL80211_ATTR_MAC]);
12181
12182 wdev_lock(wdev);
12183 err = rdev_del_tx_ts(rdev, dev, tsid, peer);
12184 wdev_unlock(wdev);
12185
12186 return err;
12187}
12188
Arik Nemtsov1057d352014-11-19 12:54:26 +020012189static int nl80211_tdls_channel_switch(struct sk_buff *skb,
12190 struct genl_info *info)
12191{
12192 struct cfg80211_registered_device *rdev = info->user_ptr[0];
12193 struct net_device *dev = info->user_ptr[1];
12194 struct wireless_dev *wdev = dev->ieee80211_ptr;
12195 struct cfg80211_chan_def chandef = {};
12196 const u8 *addr;
12197 u8 oper_class;
12198 int err;
12199
12200 if (!rdev->ops->tdls_channel_switch ||
12201 !(rdev->wiphy.features & NL80211_FEATURE_TDLS_CHANNEL_SWITCH))
12202 return -EOPNOTSUPP;
12203
12204 switch (dev->ieee80211_ptr->iftype) {
12205 case NL80211_IFTYPE_STATION:
12206 case NL80211_IFTYPE_P2P_CLIENT:
12207 break;
12208 default:
12209 return -EOPNOTSUPP;
12210 }
12211
12212 if (!info->attrs[NL80211_ATTR_MAC] ||
12213 !info->attrs[NL80211_ATTR_OPER_CLASS])
12214 return -EINVAL;
12215
12216 err = nl80211_parse_chandef(rdev, info, &chandef);
12217 if (err)
12218 return err;
12219
12220 /*
12221 * Don't allow wide channels on the 2.4Ghz band, as per IEEE802.11-2012
12222 * section 10.22.6.2.1. Disallow 5/10Mhz channels as well for now, the
12223 * specification is not defined for them.
12224 */
Johannes Berg57fbcce2016-04-12 15:56:15 +020012225 if (chandef.chan->band == NL80211_BAND_2GHZ &&
Arik Nemtsov1057d352014-11-19 12:54:26 +020012226 chandef.width != NL80211_CHAN_WIDTH_20_NOHT &&
12227 chandef.width != NL80211_CHAN_WIDTH_20)
12228 return -EINVAL;
12229
12230 /* we will be active on the TDLS link */
Arik Nemtsov923b3522015-07-08 15:41:44 +030012231 if (!cfg80211_reg_can_beacon_relax(&rdev->wiphy, &chandef,
12232 wdev->iftype))
Arik Nemtsov1057d352014-11-19 12:54:26 +020012233 return -EINVAL;
12234
12235 /* don't allow switching to DFS channels */
12236 if (cfg80211_chandef_dfs_required(wdev->wiphy, &chandef, wdev->iftype))
12237 return -EINVAL;
12238
12239 addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
12240 oper_class = nla_get_u8(info->attrs[NL80211_ATTR_OPER_CLASS]);
12241
12242 wdev_lock(wdev);
12243 err = rdev_tdls_channel_switch(rdev, dev, addr, oper_class, &chandef);
12244 wdev_unlock(wdev);
12245
12246 return err;
12247}
12248
12249static int nl80211_tdls_cancel_channel_switch(struct sk_buff *skb,
12250 struct genl_info *info)
12251{
12252 struct cfg80211_registered_device *rdev = info->user_ptr[0];
12253 struct net_device *dev = info->user_ptr[1];
12254 struct wireless_dev *wdev = dev->ieee80211_ptr;
12255 const u8 *addr;
12256
12257 if (!rdev->ops->tdls_channel_switch ||
12258 !rdev->ops->tdls_cancel_channel_switch ||
12259 !(rdev->wiphy.features & NL80211_FEATURE_TDLS_CHANNEL_SWITCH))
12260 return -EOPNOTSUPP;
12261
12262 switch (dev->ieee80211_ptr->iftype) {
12263 case NL80211_IFTYPE_STATION:
12264 case NL80211_IFTYPE_P2P_CLIENT:
12265 break;
12266 default:
12267 return -EOPNOTSUPP;
12268 }
12269
12270 if (!info->attrs[NL80211_ATTR_MAC])
12271 return -EINVAL;
12272
12273 addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
12274
12275 wdev_lock(wdev);
12276 rdev_tdls_cancel_channel_switch(rdev, dev, addr);
12277 wdev_unlock(wdev);
12278
12279 return 0;
12280}
12281
Michael Braunce0ce132016-10-10 19:12:22 +020012282static int nl80211_set_multicast_to_unicast(struct sk_buff *skb,
12283 struct genl_info *info)
12284{
12285 struct cfg80211_registered_device *rdev = info->user_ptr[0];
12286 struct net_device *dev = info->user_ptr[1];
12287 struct wireless_dev *wdev = dev->ieee80211_ptr;
12288 const struct nlattr *nla;
12289 bool enabled;
12290
Michael Braunce0ce132016-10-10 19:12:22 +020012291 if (!rdev->ops->set_multicast_to_unicast)
12292 return -EOPNOTSUPP;
12293
12294 if (wdev->iftype != NL80211_IFTYPE_AP &&
12295 wdev->iftype != NL80211_IFTYPE_P2P_GO)
12296 return -EOPNOTSUPP;
12297
12298 nla = info->attrs[NL80211_ATTR_MULTICAST_TO_UNICAST_ENABLED];
12299 enabled = nla_get_flag(nla);
12300
12301 return rdev_set_multicast_to_unicast(rdev, dev, enabled);
12302}
12303
Avraham Stern3a00df52017-06-09 13:08:43 +010012304static int nl80211_set_pmk(struct sk_buff *skb, struct genl_info *info)
12305{
12306 struct cfg80211_registered_device *rdev = info->user_ptr[0];
12307 struct net_device *dev = info->user_ptr[1];
12308 struct wireless_dev *wdev = dev->ieee80211_ptr;
12309 struct cfg80211_pmk_conf pmk_conf = {};
12310 int ret;
12311
12312 if (wdev->iftype != NL80211_IFTYPE_STATION &&
12313 wdev->iftype != NL80211_IFTYPE_P2P_CLIENT)
12314 return -EOPNOTSUPP;
12315
12316 if (!wiphy_ext_feature_isset(&rdev->wiphy,
12317 NL80211_EXT_FEATURE_4WAY_HANDSHAKE_STA_1X))
12318 return -EOPNOTSUPP;
12319
12320 if (!info->attrs[NL80211_ATTR_MAC] || !info->attrs[NL80211_ATTR_PMK])
12321 return -EINVAL;
12322
12323 wdev_lock(wdev);
12324 if (!wdev->current_bss) {
12325 ret = -ENOTCONN;
12326 goto out;
12327 }
12328
12329 pmk_conf.aa = nla_data(info->attrs[NL80211_ATTR_MAC]);
12330 if (memcmp(pmk_conf.aa, wdev->current_bss->pub.bssid, ETH_ALEN)) {
12331 ret = -EINVAL;
12332 goto out;
12333 }
12334
12335 pmk_conf.pmk = nla_data(info->attrs[NL80211_ATTR_PMK]);
12336 pmk_conf.pmk_len = nla_len(info->attrs[NL80211_ATTR_PMK]);
12337 if (pmk_conf.pmk_len != WLAN_PMK_LEN &&
12338 pmk_conf.pmk_len != WLAN_PMK_LEN_SUITE_B_192) {
12339 ret = -EINVAL;
12340 goto out;
12341 }
12342
12343 if (info->attrs[NL80211_ATTR_PMKR0_NAME]) {
12344 int r0_name_len = nla_len(info->attrs[NL80211_ATTR_PMKR0_NAME]);
12345
12346 if (r0_name_len != WLAN_PMK_NAME_LEN) {
12347 ret = -EINVAL;
12348 goto out;
12349 }
12350
12351 pmk_conf.pmk_r0_name =
12352 nla_data(info->attrs[NL80211_ATTR_PMKR0_NAME]);
12353 }
12354
12355 ret = rdev_set_pmk(rdev, dev, &pmk_conf);
12356out:
12357 wdev_unlock(wdev);
12358 return ret;
12359}
12360
12361static int nl80211_del_pmk(struct sk_buff *skb, struct genl_info *info)
12362{
12363 struct cfg80211_registered_device *rdev = info->user_ptr[0];
12364 struct net_device *dev = info->user_ptr[1];
12365 struct wireless_dev *wdev = dev->ieee80211_ptr;
12366 const u8 *aa;
12367 int ret;
12368
12369 if (wdev->iftype != NL80211_IFTYPE_STATION &&
12370 wdev->iftype != NL80211_IFTYPE_P2P_CLIENT)
12371 return -EOPNOTSUPP;
12372
12373 if (!wiphy_ext_feature_isset(&rdev->wiphy,
12374 NL80211_EXT_FEATURE_4WAY_HANDSHAKE_STA_1X))
12375 return -EOPNOTSUPP;
12376
12377 if (!info->attrs[NL80211_ATTR_MAC])
12378 return -EINVAL;
12379
12380 wdev_lock(wdev);
12381 aa = nla_data(info->attrs[NL80211_ATTR_MAC]);
12382 ret = rdev_del_pmk(rdev, dev, aa);
12383 wdev_unlock(wdev);
12384
12385 return ret;
12386}
12387
Johannes Berg4c476992010-10-04 21:36:35 +020012388#define NL80211_FLAG_NEED_WIPHY 0x01
12389#define NL80211_FLAG_NEED_NETDEV 0x02
12390#define NL80211_FLAG_NEED_RTNL 0x04
Johannes Berg41265712010-10-04 21:14:05 +020012391#define NL80211_FLAG_CHECK_NETDEV_UP 0x08
12392#define NL80211_FLAG_NEED_NETDEV_UP (NL80211_FLAG_NEED_NETDEV |\
12393 NL80211_FLAG_CHECK_NETDEV_UP)
Johannes Berg1bf614e2012-06-15 15:23:36 +020012394#define NL80211_FLAG_NEED_WDEV 0x10
Johannes Berg98104fde2012-06-16 00:19:54 +020012395/* If a netdev is associated, it must be UP, P2P must be started */
Johannes Berg1bf614e2012-06-15 15:23:36 +020012396#define NL80211_FLAG_NEED_WDEV_UP (NL80211_FLAG_NEED_WDEV |\
12397 NL80211_FLAG_CHECK_NETDEV_UP)
Johannes Berg5393b912014-09-10 15:00:16 +030012398#define NL80211_FLAG_CLEAR_SKB 0x20
Johannes Berg4c476992010-10-04 21:36:35 +020012399
Johannes Bergf84f7712013-11-14 17:14:45 +010012400static int nl80211_pre_doit(const struct genl_ops *ops, struct sk_buff *skb,
Johannes Berg4c476992010-10-04 21:36:35 +020012401 struct genl_info *info)
12402{
12403 struct cfg80211_registered_device *rdev;
Johannes Berg89a54e42012-06-15 14:33:17 +020012404 struct wireless_dev *wdev;
Johannes Berg4c476992010-10-04 21:36:35 +020012405 struct net_device *dev;
Johannes Berg4c476992010-10-04 21:36:35 +020012406 bool rtnl = ops->internal_flags & NL80211_FLAG_NEED_RTNL;
12407
12408 if (rtnl)
12409 rtnl_lock();
12410
12411 if (ops->internal_flags & NL80211_FLAG_NEED_WIPHY) {
Johannes Berg4f7eff12012-06-15 14:14:22 +020012412 rdev = cfg80211_get_dev_from_info(genl_info_net(info), info);
Johannes Berg4c476992010-10-04 21:36:35 +020012413 if (IS_ERR(rdev)) {
12414 if (rtnl)
12415 rtnl_unlock();
12416 return PTR_ERR(rdev);
12417 }
12418 info->user_ptr[0] = rdev;
Johannes Berg1bf614e2012-06-15 15:23:36 +020012419 } else if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV ||
12420 ops->internal_flags & NL80211_FLAG_NEED_WDEV) {
Johannes Berg5fe231e2013-05-08 21:45:15 +020012421 ASSERT_RTNL();
12422
Johannes Berg89a54e42012-06-15 14:33:17 +020012423 wdev = __cfg80211_wdev_from_attrs(genl_info_net(info),
12424 info->attrs);
12425 if (IS_ERR(wdev)) {
Johannes Berg4c476992010-10-04 21:36:35 +020012426 if (rtnl)
12427 rtnl_unlock();
Johannes Berg89a54e42012-06-15 14:33:17 +020012428 return PTR_ERR(wdev);
Johannes Berg4c476992010-10-04 21:36:35 +020012429 }
Johannes Berg89a54e42012-06-15 14:33:17 +020012430
Johannes Berg89a54e42012-06-15 14:33:17 +020012431 dev = wdev->netdev;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080012432 rdev = wiphy_to_rdev(wdev->wiphy);
Johannes Berg89a54e42012-06-15 14:33:17 +020012433
Johannes Berg1bf614e2012-06-15 15:23:36 +020012434 if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV) {
12435 if (!dev) {
Johannes Berg1bf614e2012-06-15 15:23:36 +020012436 if (rtnl)
12437 rtnl_unlock();
12438 return -EINVAL;
12439 }
12440
12441 info->user_ptr[1] = dev;
12442 } else {
12443 info->user_ptr[1] = wdev;
Johannes Berg41265712010-10-04 21:14:05 +020012444 }
Johannes Berg89a54e42012-06-15 14:33:17 +020012445
Arend Van Spriel73c7da32016-10-20 20:08:22 +010012446 if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP &&
12447 !wdev_running(wdev)) {
12448 if (rtnl)
12449 rtnl_unlock();
12450 return -ENETDOWN;
Johannes Berg1bf614e2012-06-15 15:23:36 +020012451 }
12452
Arend Van Spriel73c7da32016-10-20 20:08:22 +010012453 if (dev)
12454 dev_hold(dev);
12455
Johannes Berg4c476992010-10-04 21:36:35 +020012456 info->user_ptr[0] = rdev;
Johannes Berg4c476992010-10-04 21:36:35 +020012457 }
12458
12459 return 0;
12460}
12461
Johannes Bergf84f7712013-11-14 17:14:45 +010012462static void nl80211_post_doit(const struct genl_ops *ops, struct sk_buff *skb,
Johannes Berg4c476992010-10-04 21:36:35 +020012463 struct genl_info *info)
12464{
Johannes Berg1bf614e2012-06-15 15:23:36 +020012465 if (info->user_ptr[1]) {
12466 if (ops->internal_flags & NL80211_FLAG_NEED_WDEV) {
12467 struct wireless_dev *wdev = info->user_ptr[1];
12468
12469 if (wdev->netdev)
12470 dev_put(wdev->netdev);
12471 } else {
12472 dev_put(info->user_ptr[1]);
12473 }
12474 }
Johannes Berg5393b912014-09-10 15:00:16 +030012475
Johannes Berg4c476992010-10-04 21:36:35 +020012476 if (ops->internal_flags & NL80211_FLAG_NEED_RTNL)
12477 rtnl_unlock();
Johannes Berg5393b912014-09-10 15:00:16 +030012478
12479 /* If needed, clear the netlink message payload from the SKB
12480 * as it might contain key data that shouldn't stick around on
12481 * the heap after the SKB is freed. The netlink message header
12482 * is still needed for further processing, so leave it intact.
12483 */
12484 if (ops->internal_flags & NL80211_FLAG_CLEAR_SKB) {
12485 struct nlmsghdr *nlh = nlmsg_hdr(skb);
12486
12487 memset(nlmsg_data(nlh), 0, nlmsg_len(nlh));
12488 }
Johannes Berg4c476992010-10-04 21:36:35 +020012489}
12490
Johannes Berg4534de82013-11-14 17:14:46 +010012491static const struct genl_ops nl80211_ops[] = {
Johannes Berg55682962007-09-20 13:09:35 -040012492 {
12493 .cmd = NL80211_CMD_GET_WIPHY,
12494 .doit = nl80211_get_wiphy,
12495 .dumpit = nl80211_dump_wiphy,
Johannes Berg86e8cf92013-06-19 10:57:22 +020012496 .done = nl80211_dump_wiphy_done,
Johannes Berg55682962007-09-20 13:09:35 -040012497 .policy = nl80211_policy,
12498 /* can be retrieved by unprivileged users */
Johannes Berg5fe231e2013-05-08 21:45:15 +020012499 .internal_flags = NL80211_FLAG_NEED_WIPHY |
12500 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -040012501 },
12502 {
12503 .cmd = NL80211_CMD_SET_WIPHY,
12504 .doit = nl80211_set_wiphy,
12505 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012506 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020012507 .internal_flags = NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -040012508 },
12509 {
12510 .cmd = NL80211_CMD_GET_INTERFACE,
12511 .doit = nl80211_get_interface,
12512 .dumpit = nl80211_dump_interface,
12513 .policy = nl80211_policy,
12514 /* can be retrieved by unprivileged users */
Johannes Berg5fe231e2013-05-08 21:45:15 +020012515 .internal_flags = NL80211_FLAG_NEED_WDEV |
12516 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -040012517 },
12518 {
12519 .cmd = NL80211_CMD_SET_INTERFACE,
12520 .doit = nl80211_set_interface,
12521 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012522 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020012523 .internal_flags = NL80211_FLAG_NEED_NETDEV |
12524 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -040012525 },
12526 {
12527 .cmd = NL80211_CMD_NEW_INTERFACE,
12528 .doit = nl80211_new_interface,
12529 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012530 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020012531 .internal_flags = NL80211_FLAG_NEED_WIPHY |
12532 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -040012533 },
12534 {
12535 .cmd = NL80211_CMD_DEL_INTERFACE,
12536 .doit = nl80211_del_interface,
12537 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012538 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg84efbb82012-06-16 00:00:26 +020012539 .internal_flags = NL80211_FLAG_NEED_WDEV |
Johannes Berg4c476992010-10-04 21:36:35 +020012540 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -040012541 },
Johannes Berg41ade002007-12-19 02:03:29 +010012542 {
12543 .cmd = NL80211_CMD_GET_KEY,
12544 .doit = nl80211_get_key,
12545 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012546 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020012547 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020012548 NL80211_FLAG_NEED_RTNL,
Johannes Berg41ade002007-12-19 02:03:29 +010012549 },
12550 {
12551 .cmd = NL80211_CMD_SET_KEY,
12552 .doit = nl80211_set_key,
12553 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012554 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020012555 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg5393b912014-09-10 15:00:16 +030012556 NL80211_FLAG_NEED_RTNL |
12557 NL80211_FLAG_CLEAR_SKB,
Johannes Berg41ade002007-12-19 02:03:29 +010012558 },
12559 {
12560 .cmd = NL80211_CMD_NEW_KEY,
12561 .doit = nl80211_new_key,
12562 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012563 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020012564 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg5393b912014-09-10 15:00:16 +030012565 NL80211_FLAG_NEED_RTNL |
12566 NL80211_FLAG_CLEAR_SKB,
Johannes Berg41ade002007-12-19 02:03:29 +010012567 },
12568 {
12569 .cmd = NL80211_CMD_DEL_KEY,
12570 .doit = nl80211_del_key,
12571 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012572 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020012573 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020012574 NL80211_FLAG_NEED_RTNL,
Johannes Berg41ade002007-12-19 02:03:29 +010012575 },
Johannes Berged1b6cc2007-12-19 02:03:32 +010012576 {
12577 .cmd = NL80211_CMD_SET_BEACON,
12578 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012579 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg88600202012-02-13 15:17:18 +010012580 .doit = nl80211_set_beacon,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020012581 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020012582 NL80211_FLAG_NEED_RTNL,
Johannes Berged1b6cc2007-12-19 02:03:32 +010012583 },
12584 {
Johannes Berg88600202012-02-13 15:17:18 +010012585 .cmd = NL80211_CMD_START_AP,
Johannes Berged1b6cc2007-12-19 02:03:32 +010012586 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012587 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg88600202012-02-13 15:17:18 +010012588 .doit = nl80211_start_ap,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020012589 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020012590 NL80211_FLAG_NEED_RTNL,
Johannes Berged1b6cc2007-12-19 02:03:32 +010012591 },
12592 {
Johannes Berg88600202012-02-13 15:17:18 +010012593 .cmd = NL80211_CMD_STOP_AP,
Johannes Berged1b6cc2007-12-19 02:03:32 +010012594 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012595 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg88600202012-02-13 15:17:18 +010012596 .doit = nl80211_stop_ap,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020012597 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020012598 NL80211_FLAG_NEED_RTNL,
Johannes Berged1b6cc2007-12-19 02:03:32 +010012599 },
Johannes Berg5727ef12007-12-19 02:03:34 +010012600 {
12601 .cmd = NL80211_CMD_GET_STATION,
12602 .doit = nl80211_get_station,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010012603 .dumpit = nl80211_dump_station,
Johannes Berg5727ef12007-12-19 02:03:34 +010012604 .policy = nl80211_policy,
Johannes Berg4c476992010-10-04 21:36:35 +020012605 .internal_flags = NL80211_FLAG_NEED_NETDEV |
12606 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +010012607 },
12608 {
12609 .cmd = NL80211_CMD_SET_STATION,
12610 .doit = nl80211_set_station,
12611 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012612 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020012613 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020012614 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +010012615 },
12616 {
12617 .cmd = NL80211_CMD_NEW_STATION,
12618 .doit = nl80211_new_station,
12619 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012620 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020012621 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020012622 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +010012623 },
12624 {
12625 .cmd = NL80211_CMD_DEL_STATION,
12626 .doit = nl80211_del_station,
12627 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012628 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020012629 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020012630 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +010012631 },
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010012632 {
12633 .cmd = NL80211_CMD_GET_MPATH,
12634 .doit = nl80211_get_mpath,
12635 .dumpit = nl80211_dump_mpath,
12636 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012637 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020012638 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020012639 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010012640 },
12641 {
Henning Rogge66be7d22014-09-12 08:58:49 +020012642 .cmd = NL80211_CMD_GET_MPP,
12643 .doit = nl80211_get_mpp,
12644 .dumpit = nl80211_dump_mpp,
12645 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012646 .flags = GENL_UNS_ADMIN_PERM,
Henning Rogge66be7d22014-09-12 08:58:49 +020012647 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
12648 NL80211_FLAG_NEED_RTNL,
12649 },
12650 {
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010012651 .cmd = NL80211_CMD_SET_MPATH,
12652 .doit = nl80211_set_mpath,
12653 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012654 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020012655 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020012656 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010012657 },
12658 {
12659 .cmd = NL80211_CMD_NEW_MPATH,
12660 .doit = nl80211_new_mpath,
12661 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012662 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020012663 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020012664 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010012665 },
12666 {
12667 .cmd = NL80211_CMD_DEL_MPATH,
12668 .doit = nl80211_del_mpath,
12669 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012670 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020012671 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020012672 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010012673 },
Jouni Malinen9f1ba902008-08-07 20:07:01 +030012674 {
12675 .cmd = NL80211_CMD_SET_BSS,
12676 .doit = nl80211_set_bss,
12677 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012678 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020012679 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020012680 NL80211_FLAG_NEED_RTNL,
Jouni Malinen9f1ba902008-08-07 20:07:01 +030012681 },
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -070012682 {
Luis R. Rodriguezf1303472009-01-30 09:26:42 -080012683 .cmd = NL80211_CMD_GET_REG,
Arik Nemtsovad30ca22014-12-15 19:25:59 +020012684 .doit = nl80211_get_reg_do,
12685 .dumpit = nl80211_get_reg_dump,
Luis R. Rodriguezf1303472009-01-30 09:26:42 -080012686 .policy = nl80211_policy,
Johannes Berg5fe231e2013-05-08 21:45:15 +020012687 .internal_flags = NL80211_FLAG_NEED_RTNL,
Luis R. Rodriguezf1303472009-01-30 09:26:42 -080012688 /* can be retrieved by unprivileged users */
12689 },
Johannes Bergb6863032015-10-15 09:25:18 +020012690#ifdef CONFIG_CFG80211_CRDA_SUPPORT
Luis R. Rodriguezf1303472009-01-30 09:26:42 -080012691 {
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -070012692 .cmd = NL80211_CMD_SET_REG,
12693 .doit = nl80211_set_reg,
12694 .policy = nl80211_policy,
12695 .flags = GENL_ADMIN_PERM,
Johannes Berg5fe231e2013-05-08 21:45:15 +020012696 .internal_flags = NL80211_FLAG_NEED_RTNL,
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -070012697 },
Johannes Bergb6863032015-10-15 09:25:18 +020012698#endif
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -070012699 {
12700 .cmd = NL80211_CMD_REQ_SET_REG,
12701 .doit = nl80211_req_set_reg,
12702 .policy = nl80211_policy,
12703 .flags = GENL_ADMIN_PERM,
12704 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -070012705 {
Javier Cardona24bdd9f2010-12-16 17:37:48 -080012706 .cmd = NL80211_CMD_GET_MESH_CONFIG,
12707 .doit = nl80211_get_mesh_config,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -070012708 .policy = nl80211_policy,
12709 /* can be retrieved by unprivileged users */
Johannes Berg2b5f8b02012-04-02 10:51:55 +020012710 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020012711 NL80211_FLAG_NEED_RTNL,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -070012712 },
12713 {
Javier Cardona24bdd9f2010-12-16 17:37:48 -080012714 .cmd = NL80211_CMD_SET_MESH_CONFIG,
12715 .doit = nl80211_update_mesh_config,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -070012716 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012717 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg29cbe682010-12-03 09:20:44 +010012718 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020012719 NL80211_FLAG_NEED_RTNL,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -070012720 },
Jouni Malinen9aed3cc2009-01-13 16:03:29 +020012721 {
Johannes Berg2a519312009-02-10 21:25:55 +010012722 .cmd = NL80211_CMD_TRIGGER_SCAN,
12723 .doit = nl80211_trigger_scan,
12724 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012725 .flags = GENL_UNS_ADMIN_PERM,
Johannes Bergfd014282012-06-18 19:17:03 +020012726 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020012727 NL80211_FLAG_NEED_RTNL,
Johannes Berg2a519312009-02-10 21:25:55 +010012728 },
12729 {
Vidyullatha Kanchanapally91d3ab42015-10-30 19:14:49 +053012730 .cmd = NL80211_CMD_ABORT_SCAN,
12731 .doit = nl80211_abort_scan,
12732 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012733 .flags = GENL_UNS_ADMIN_PERM,
Vidyullatha Kanchanapally91d3ab42015-10-30 19:14:49 +053012734 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
12735 NL80211_FLAG_NEED_RTNL,
12736 },
12737 {
Johannes Berg2a519312009-02-10 21:25:55 +010012738 .cmd = NL80211_CMD_GET_SCAN,
12739 .policy = nl80211_policy,
12740 .dumpit = nl80211_dump_scan,
12741 },
Jouni Malinen636a5d32009-03-19 13:39:22 +020012742 {
Luciano Coelho807f8a82011-05-11 17:09:35 +030012743 .cmd = NL80211_CMD_START_SCHED_SCAN,
12744 .doit = nl80211_start_sched_scan,
12745 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012746 .flags = GENL_UNS_ADMIN_PERM,
Luciano Coelho807f8a82011-05-11 17:09:35 +030012747 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
12748 NL80211_FLAG_NEED_RTNL,
12749 },
12750 {
12751 .cmd = NL80211_CMD_STOP_SCHED_SCAN,
12752 .doit = nl80211_stop_sched_scan,
12753 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012754 .flags = GENL_UNS_ADMIN_PERM,
Luciano Coelho807f8a82011-05-11 17:09:35 +030012755 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
12756 NL80211_FLAG_NEED_RTNL,
12757 },
12758 {
Jouni Malinen636a5d32009-03-19 13:39:22 +020012759 .cmd = NL80211_CMD_AUTHENTICATE,
12760 .doit = nl80211_authenticate,
12761 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012762 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020012763 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg5393b912014-09-10 15:00:16 +030012764 NL80211_FLAG_NEED_RTNL |
12765 NL80211_FLAG_CLEAR_SKB,
Jouni Malinen636a5d32009-03-19 13:39:22 +020012766 },
12767 {
12768 .cmd = NL80211_CMD_ASSOCIATE,
12769 .doit = nl80211_associate,
12770 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012771 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020012772 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020012773 NL80211_FLAG_NEED_RTNL,
Jouni Malinen636a5d32009-03-19 13:39:22 +020012774 },
12775 {
12776 .cmd = NL80211_CMD_DEAUTHENTICATE,
12777 .doit = nl80211_deauthenticate,
12778 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012779 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020012780 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020012781 NL80211_FLAG_NEED_RTNL,
Jouni Malinen636a5d32009-03-19 13:39:22 +020012782 },
12783 {
12784 .cmd = NL80211_CMD_DISASSOCIATE,
12785 .doit = nl80211_disassociate,
12786 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012787 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020012788 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020012789 NL80211_FLAG_NEED_RTNL,
Jouni Malinen636a5d32009-03-19 13:39:22 +020012790 },
Johannes Berg04a773a2009-04-19 21:24:32 +020012791 {
12792 .cmd = NL80211_CMD_JOIN_IBSS,
12793 .doit = nl80211_join_ibss,
12794 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012795 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020012796 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020012797 NL80211_FLAG_NEED_RTNL,
Johannes Berg04a773a2009-04-19 21:24:32 +020012798 },
12799 {
12800 .cmd = NL80211_CMD_LEAVE_IBSS,
12801 .doit = nl80211_leave_ibss,
12802 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012803 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020012804 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020012805 NL80211_FLAG_NEED_RTNL,
Johannes Berg04a773a2009-04-19 21:24:32 +020012806 },
Johannes Bergaff89a92009-07-01 21:26:51 +020012807#ifdef CONFIG_NL80211_TESTMODE
12808 {
12809 .cmd = NL80211_CMD_TESTMODE,
12810 .doit = nl80211_testmode_do,
Wey-Yi Guy71063f02011-05-20 09:05:54 -070012811 .dumpit = nl80211_testmode_dump,
Johannes Bergaff89a92009-07-01 21:26:51 +020012812 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012813 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020012814 .internal_flags = NL80211_FLAG_NEED_WIPHY |
12815 NL80211_FLAG_NEED_RTNL,
Johannes Bergaff89a92009-07-01 21:26:51 +020012816 },
12817#endif
Samuel Ortizb23aa672009-07-01 21:26:54 +020012818 {
12819 .cmd = NL80211_CMD_CONNECT,
12820 .doit = nl80211_connect,
12821 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012822 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020012823 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020012824 NL80211_FLAG_NEED_RTNL,
Samuel Ortizb23aa672009-07-01 21:26:54 +020012825 },
12826 {
vamsi krishna088e8df2016-10-27 16:51:11 +030012827 .cmd = NL80211_CMD_UPDATE_CONNECT_PARAMS,
12828 .doit = nl80211_update_connect_params,
12829 .policy = nl80211_policy,
12830 .flags = GENL_ADMIN_PERM,
12831 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
12832 NL80211_FLAG_NEED_RTNL,
12833 },
12834 {
Samuel Ortizb23aa672009-07-01 21:26:54 +020012835 .cmd = NL80211_CMD_DISCONNECT,
12836 .doit = nl80211_disconnect,
12837 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012838 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020012839 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020012840 NL80211_FLAG_NEED_RTNL,
Samuel Ortizb23aa672009-07-01 21:26:54 +020012841 },
Johannes Berg463d0182009-07-14 00:33:35 +020012842 {
12843 .cmd = NL80211_CMD_SET_WIPHY_NETNS,
12844 .doit = nl80211_wiphy_netns,
12845 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012846 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020012847 .internal_flags = NL80211_FLAG_NEED_WIPHY |
12848 NL80211_FLAG_NEED_RTNL,
Johannes Berg463d0182009-07-14 00:33:35 +020012849 },
Holger Schurig61fa7132009-11-11 12:25:40 +010012850 {
12851 .cmd = NL80211_CMD_GET_SURVEY,
12852 .policy = nl80211_policy,
12853 .dumpit = nl80211_dump_survey,
12854 },
Samuel Ortiz67fbb162009-11-24 23:59:15 +010012855 {
12856 .cmd = NL80211_CMD_SET_PMKSA,
12857 .doit = nl80211_setdel_pmksa,
12858 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012859 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020012860 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020012861 NL80211_FLAG_NEED_RTNL,
Samuel Ortiz67fbb162009-11-24 23:59:15 +010012862 },
12863 {
12864 .cmd = NL80211_CMD_DEL_PMKSA,
12865 .doit = nl80211_setdel_pmksa,
12866 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012867 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020012868 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020012869 NL80211_FLAG_NEED_RTNL,
Samuel Ortiz67fbb162009-11-24 23:59:15 +010012870 },
12871 {
12872 .cmd = NL80211_CMD_FLUSH_PMKSA,
12873 .doit = nl80211_flush_pmksa,
12874 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012875 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020012876 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020012877 NL80211_FLAG_NEED_RTNL,
Samuel Ortiz67fbb162009-11-24 23:59:15 +010012878 },
Jouni Malinen9588bbd2009-12-23 13:15:41 +010012879 {
12880 .cmd = NL80211_CMD_REMAIN_ON_CHANNEL,
12881 .doit = nl80211_remain_on_channel,
12882 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012883 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +020012884 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020012885 NL80211_FLAG_NEED_RTNL,
Jouni Malinen9588bbd2009-12-23 13:15:41 +010012886 },
12887 {
12888 .cmd = NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL,
12889 .doit = nl80211_cancel_remain_on_channel,
12890 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012891 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +020012892 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020012893 NL80211_FLAG_NEED_RTNL,
Jouni Malinen9588bbd2009-12-23 13:15:41 +010012894 },
Jouni Malinen13ae75b2009-12-29 12:59:45 +020012895 {
12896 .cmd = NL80211_CMD_SET_TX_BITRATE_MASK,
12897 .doit = nl80211_set_tx_bitrate_mask,
12898 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012899 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020012900 .internal_flags = NL80211_FLAG_NEED_NETDEV |
12901 NL80211_FLAG_NEED_RTNL,
Jouni Malinen13ae75b2009-12-29 12:59:45 +020012902 },
Jouni Malinen026331c2010-02-15 12:53:10 +020012903 {
Johannes Berg2e161f72010-08-12 15:38:38 +020012904 .cmd = NL80211_CMD_REGISTER_FRAME,
12905 .doit = nl80211_register_mgmt,
Jouni Malinen026331c2010-02-15 12:53:10 +020012906 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012907 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +020012908 .internal_flags = NL80211_FLAG_NEED_WDEV |
Johannes Berg4c476992010-10-04 21:36:35 +020012909 NL80211_FLAG_NEED_RTNL,
Jouni Malinen026331c2010-02-15 12:53:10 +020012910 },
12911 {
Johannes Berg2e161f72010-08-12 15:38:38 +020012912 .cmd = NL80211_CMD_FRAME,
12913 .doit = nl80211_tx_mgmt,
Jouni Malinen026331c2010-02-15 12:53:10 +020012914 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012915 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +020012916 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020012917 NL80211_FLAG_NEED_RTNL,
Jouni Malinen026331c2010-02-15 12:53:10 +020012918 },
Kalle Valoffb9eb32010-02-17 17:58:10 +020012919 {
Johannes Bergf7ca38d2010-11-25 10:02:29 +010012920 .cmd = NL80211_CMD_FRAME_WAIT_CANCEL,
12921 .doit = nl80211_tx_mgmt_cancel_wait,
12922 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012923 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +020012924 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Bergf7ca38d2010-11-25 10:02:29 +010012925 NL80211_FLAG_NEED_RTNL,
12926 },
12927 {
Kalle Valoffb9eb32010-02-17 17:58:10 +020012928 .cmd = NL80211_CMD_SET_POWER_SAVE,
12929 .doit = nl80211_set_power_save,
12930 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012931 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020012932 .internal_flags = NL80211_FLAG_NEED_NETDEV |
12933 NL80211_FLAG_NEED_RTNL,
Kalle Valoffb9eb32010-02-17 17:58:10 +020012934 },
12935 {
12936 .cmd = NL80211_CMD_GET_POWER_SAVE,
12937 .doit = nl80211_get_power_save,
12938 .policy = nl80211_policy,
12939 /* can be retrieved by unprivileged users */
Johannes Berg4c476992010-10-04 21:36:35 +020012940 .internal_flags = NL80211_FLAG_NEED_NETDEV |
12941 NL80211_FLAG_NEED_RTNL,
Kalle Valoffb9eb32010-02-17 17:58:10 +020012942 },
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020012943 {
12944 .cmd = NL80211_CMD_SET_CQM,
12945 .doit = nl80211_set_cqm,
12946 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012947 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020012948 .internal_flags = NL80211_FLAG_NEED_NETDEV |
12949 NL80211_FLAG_NEED_RTNL,
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020012950 },
Johannes Bergf444de02010-05-05 15:25:02 +020012951 {
12952 .cmd = NL80211_CMD_SET_CHANNEL,
12953 .doit = nl80211_set_channel,
12954 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012955 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020012956 .internal_flags = NL80211_FLAG_NEED_NETDEV |
12957 NL80211_FLAG_NEED_RTNL,
Johannes Bergf444de02010-05-05 15:25:02 +020012958 },
Bill Jordane8347eb2010-10-01 13:54:28 -040012959 {
12960 .cmd = NL80211_CMD_SET_WDS_PEER,
12961 .doit = nl80211_set_wds_peer,
12962 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012963 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg43b19952010-10-07 13:10:30 +020012964 .internal_flags = NL80211_FLAG_NEED_NETDEV |
12965 NL80211_FLAG_NEED_RTNL,
Bill Jordane8347eb2010-10-01 13:54:28 -040012966 },
Johannes Berg29cbe682010-12-03 09:20:44 +010012967 {
12968 .cmd = NL80211_CMD_JOIN_MESH,
12969 .doit = nl80211_join_mesh,
12970 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012971 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg29cbe682010-12-03 09:20:44 +010012972 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
12973 NL80211_FLAG_NEED_RTNL,
12974 },
12975 {
12976 .cmd = NL80211_CMD_LEAVE_MESH,
12977 .doit = nl80211_leave_mesh,
12978 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012979 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg29cbe682010-12-03 09:20:44 +010012980 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
12981 NL80211_FLAG_NEED_RTNL,
12982 },
Rostislav Lisovy6e0bd6c2014-11-03 10:33:18 +010012983 {
12984 .cmd = NL80211_CMD_JOIN_OCB,
12985 .doit = nl80211_join_ocb,
12986 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012987 .flags = GENL_UNS_ADMIN_PERM,
Rostislav Lisovy6e0bd6c2014-11-03 10:33:18 +010012988 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
12989 NL80211_FLAG_NEED_RTNL,
12990 },
12991 {
12992 .cmd = NL80211_CMD_LEAVE_OCB,
12993 .doit = nl80211_leave_ocb,
12994 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012995 .flags = GENL_UNS_ADMIN_PERM,
Rostislav Lisovy6e0bd6c2014-11-03 10:33:18 +010012996 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
12997 NL80211_FLAG_NEED_RTNL,
12998 },
Johannes Bergdfb89c52012-06-27 09:23:48 +020012999#ifdef CONFIG_PM
Johannes Bergff1b6e62011-05-04 15:37:28 +020013000 {
13001 .cmd = NL80211_CMD_GET_WOWLAN,
13002 .doit = nl80211_get_wowlan,
13003 .policy = nl80211_policy,
13004 /* can be retrieved by unprivileged users */
13005 .internal_flags = NL80211_FLAG_NEED_WIPHY |
13006 NL80211_FLAG_NEED_RTNL,
13007 },
13008 {
13009 .cmd = NL80211_CMD_SET_WOWLAN,
13010 .doit = nl80211_set_wowlan,
13011 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013012 .flags = GENL_UNS_ADMIN_PERM,
Johannes Bergff1b6e62011-05-04 15:37:28 +020013013 .internal_flags = NL80211_FLAG_NEED_WIPHY |
13014 NL80211_FLAG_NEED_RTNL,
13015 },
Johannes Bergdfb89c52012-06-27 09:23:48 +020013016#endif
Johannes Berge5497d72011-07-05 16:35:40 +020013017 {
13018 .cmd = NL80211_CMD_SET_REKEY_OFFLOAD,
13019 .doit = nl80211_set_rekey_data,
13020 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013021 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berge5497d72011-07-05 16:35:40 +020013022 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg5393b912014-09-10 15:00:16 +030013023 NL80211_FLAG_NEED_RTNL |
13024 NL80211_FLAG_CLEAR_SKB,
Johannes Berge5497d72011-07-05 16:35:40 +020013025 },
Arik Nemtsov109086c2011-09-28 14:12:50 +030013026 {
13027 .cmd = NL80211_CMD_TDLS_MGMT,
13028 .doit = nl80211_tdls_mgmt,
13029 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013030 .flags = GENL_UNS_ADMIN_PERM,
Arik Nemtsov109086c2011-09-28 14:12:50 +030013031 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
13032 NL80211_FLAG_NEED_RTNL,
13033 },
13034 {
13035 .cmd = NL80211_CMD_TDLS_OPER,
13036 .doit = nl80211_tdls_oper,
13037 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013038 .flags = GENL_UNS_ADMIN_PERM,
Arik Nemtsov109086c2011-09-28 14:12:50 +030013039 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
13040 NL80211_FLAG_NEED_RTNL,
13041 },
Johannes Berg28946da2011-11-04 11:18:12 +010013042 {
13043 .cmd = NL80211_CMD_UNEXPECTED_FRAME,
13044 .doit = nl80211_register_unexpected_frame,
13045 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013046 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg28946da2011-11-04 11:18:12 +010013047 .internal_flags = NL80211_FLAG_NEED_NETDEV |
13048 NL80211_FLAG_NEED_RTNL,
13049 },
Johannes Berg7f6cf312011-11-04 11:18:15 +010013050 {
13051 .cmd = NL80211_CMD_PROBE_CLIENT,
13052 .doit = nl80211_probe_client,
13053 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013054 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020013055 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg7f6cf312011-11-04 11:18:15 +010013056 NL80211_FLAG_NEED_RTNL,
13057 },
Johannes Berg5e760232011-11-04 11:18:17 +010013058 {
13059 .cmd = NL80211_CMD_REGISTER_BEACONS,
13060 .doit = nl80211_register_beacons,
13061 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013062 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg5e760232011-11-04 11:18:17 +010013063 .internal_flags = NL80211_FLAG_NEED_WIPHY |
13064 NL80211_FLAG_NEED_RTNL,
13065 },
Simon Wunderlich1d9d9212011-11-18 14:20:43 +010013066 {
13067 .cmd = NL80211_CMD_SET_NOACK_MAP,
13068 .doit = nl80211_set_noack_map,
13069 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013070 .flags = GENL_UNS_ADMIN_PERM,
Simon Wunderlich1d9d9212011-11-18 14:20:43 +010013071 .internal_flags = NL80211_FLAG_NEED_NETDEV |
13072 NL80211_FLAG_NEED_RTNL,
13073 },
Johannes Berg98104fde2012-06-16 00:19:54 +020013074 {
13075 .cmd = NL80211_CMD_START_P2P_DEVICE,
13076 .doit = nl80211_start_p2p_device,
13077 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013078 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg98104fde2012-06-16 00:19:54 +020013079 .internal_flags = NL80211_FLAG_NEED_WDEV |
13080 NL80211_FLAG_NEED_RTNL,
13081 },
13082 {
13083 .cmd = NL80211_CMD_STOP_P2P_DEVICE,
13084 .doit = nl80211_stop_p2p_device,
13085 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013086 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg98104fde2012-06-16 00:19:54 +020013087 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
13088 NL80211_FLAG_NEED_RTNL,
13089 },
Antonio Quartullif4e583c2012-11-02 13:27:48 +010013090 {
Ayala Bekercb3b7d82016-09-20 17:31:13 +030013091 .cmd = NL80211_CMD_START_NAN,
13092 .doit = nl80211_start_nan,
13093 .policy = nl80211_policy,
13094 .flags = GENL_ADMIN_PERM,
13095 .internal_flags = NL80211_FLAG_NEED_WDEV |
13096 NL80211_FLAG_NEED_RTNL,
13097 },
13098 {
13099 .cmd = NL80211_CMD_STOP_NAN,
13100 .doit = nl80211_stop_nan,
13101 .policy = nl80211_policy,
13102 .flags = GENL_ADMIN_PERM,
13103 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
13104 NL80211_FLAG_NEED_RTNL,
13105 },
13106 {
Ayala Bekera442b762016-09-20 17:31:15 +030013107 .cmd = NL80211_CMD_ADD_NAN_FUNCTION,
13108 .doit = nl80211_nan_add_func,
13109 .policy = nl80211_policy,
13110 .flags = GENL_ADMIN_PERM,
13111 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
13112 NL80211_FLAG_NEED_RTNL,
13113 },
13114 {
13115 .cmd = NL80211_CMD_DEL_NAN_FUNCTION,
13116 .doit = nl80211_nan_del_func,
13117 .policy = nl80211_policy,
13118 .flags = GENL_ADMIN_PERM,
13119 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
13120 NL80211_FLAG_NEED_RTNL,
13121 },
13122 {
Ayala Bekera5a9dcf2016-09-20 17:31:16 +030013123 .cmd = NL80211_CMD_CHANGE_NAN_CONFIG,
13124 .doit = nl80211_nan_change_config,
13125 .policy = nl80211_policy,
13126 .flags = GENL_ADMIN_PERM,
13127 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
13128 NL80211_FLAG_NEED_RTNL,
13129 },
13130 {
Antonio Quartullif4e583c2012-11-02 13:27:48 +010013131 .cmd = NL80211_CMD_SET_MCAST_RATE,
13132 .doit = nl80211_set_mcast_rate,
13133 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013134 .flags = GENL_UNS_ADMIN_PERM,
Antonio Quartullif4e583c2012-11-02 13:27:48 +010013135 .internal_flags = NL80211_FLAG_NEED_NETDEV |
13136 NL80211_FLAG_NEED_RTNL,
13137 },
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +053013138 {
13139 .cmd = NL80211_CMD_SET_MAC_ACL,
13140 .doit = nl80211_set_mac_acl,
13141 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013142 .flags = GENL_UNS_ADMIN_PERM,
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +053013143 .internal_flags = NL80211_FLAG_NEED_NETDEV |
13144 NL80211_FLAG_NEED_RTNL,
13145 },
Simon Wunderlich04f39042013-02-08 18:16:19 +010013146 {
13147 .cmd = NL80211_CMD_RADAR_DETECT,
13148 .doit = nl80211_start_radar_detection,
13149 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013150 .flags = GENL_UNS_ADMIN_PERM,
Simon Wunderlich04f39042013-02-08 18:16:19 +010013151 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
13152 NL80211_FLAG_NEED_RTNL,
13153 },
Johannes Berg3713b4e2013-02-14 16:19:38 +010013154 {
13155 .cmd = NL80211_CMD_GET_PROTOCOL_FEATURES,
13156 .doit = nl80211_get_protocol_features,
13157 .policy = nl80211_policy,
13158 },
Jouni Malinen355199e2013-02-27 17:14:27 +020013159 {
13160 .cmd = NL80211_CMD_UPDATE_FT_IES,
13161 .doit = nl80211_update_ft_ies,
13162 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013163 .flags = GENL_UNS_ADMIN_PERM,
Jouni Malinen355199e2013-02-27 17:14:27 +020013164 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
13165 NL80211_FLAG_NEED_RTNL,
13166 },
Arend van Spriel5de17982013-04-18 15:49:00 +020013167 {
13168 .cmd = NL80211_CMD_CRIT_PROTOCOL_START,
13169 .doit = nl80211_crit_protocol_start,
13170 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013171 .flags = GENL_UNS_ADMIN_PERM,
Arend van Spriel5de17982013-04-18 15:49:00 +020013172 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
13173 NL80211_FLAG_NEED_RTNL,
13174 },
13175 {
13176 .cmd = NL80211_CMD_CRIT_PROTOCOL_STOP,
13177 .doit = nl80211_crit_protocol_stop,
13178 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013179 .flags = GENL_UNS_ADMIN_PERM,
Arend van Spriel5de17982013-04-18 15:49:00 +020013180 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
13181 NL80211_FLAG_NEED_RTNL,
Amitkumar Karwarbe29b992013-06-28 11:51:26 -070013182 },
13183 {
13184 .cmd = NL80211_CMD_GET_COALESCE,
13185 .doit = nl80211_get_coalesce,
13186 .policy = nl80211_policy,
13187 .internal_flags = NL80211_FLAG_NEED_WIPHY |
13188 NL80211_FLAG_NEED_RTNL,
13189 },
13190 {
13191 .cmd = NL80211_CMD_SET_COALESCE,
13192 .doit = nl80211_set_coalesce,
13193 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013194 .flags = GENL_UNS_ADMIN_PERM,
Amitkumar Karwarbe29b992013-06-28 11:51:26 -070013195 .internal_flags = NL80211_FLAG_NEED_WIPHY |
13196 NL80211_FLAG_NEED_RTNL,
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +020013197 },
13198 {
13199 .cmd = NL80211_CMD_CHANNEL_SWITCH,
13200 .doit = nl80211_channel_switch,
13201 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013202 .flags = GENL_UNS_ADMIN_PERM,
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +020013203 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
13204 NL80211_FLAG_NEED_RTNL,
13205 },
Johannes Bergad7e7182013-11-13 13:37:47 +010013206 {
13207 .cmd = NL80211_CMD_VENDOR,
13208 .doit = nl80211_vendor_cmd,
Johannes Berg7bdbe402015-08-15 22:39:49 +030013209 .dumpit = nl80211_vendor_cmd_dump,
Johannes Bergad7e7182013-11-13 13:37:47 +010013210 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013211 .flags = GENL_UNS_ADMIN_PERM,
Johannes Bergad7e7182013-11-13 13:37:47 +010013212 .internal_flags = NL80211_FLAG_NEED_WIPHY |
13213 NL80211_FLAG_NEED_RTNL,
13214 },
Kyeyoon Parkfa9ffc72013-12-16 23:01:30 -080013215 {
13216 .cmd = NL80211_CMD_SET_QOS_MAP,
13217 .doit = nl80211_set_qos_map,
13218 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013219 .flags = GENL_UNS_ADMIN_PERM,
Kyeyoon Parkfa9ffc72013-12-16 23:01:30 -080013220 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
13221 NL80211_FLAG_NEED_RTNL,
13222 },
Johannes Berg960d01a2014-09-09 22:55:35 +030013223 {
13224 .cmd = NL80211_CMD_ADD_TX_TS,
13225 .doit = nl80211_add_tx_ts,
13226 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013227 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg960d01a2014-09-09 22:55:35 +030013228 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
13229 NL80211_FLAG_NEED_RTNL,
13230 },
13231 {
13232 .cmd = NL80211_CMD_DEL_TX_TS,
13233 .doit = nl80211_del_tx_ts,
13234 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013235 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg960d01a2014-09-09 22:55:35 +030013236 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
13237 NL80211_FLAG_NEED_RTNL,
13238 },
Arik Nemtsov1057d352014-11-19 12:54:26 +020013239 {
13240 .cmd = NL80211_CMD_TDLS_CHANNEL_SWITCH,
13241 .doit = nl80211_tdls_channel_switch,
13242 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013243 .flags = GENL_UNS_ADMIN_PERM,
Arik Nemtsov1057d352014-11-19 12:54:26 +020013244 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
13245 NL80211_FLAG_NEED_RTNL,
13246 },
13247 {
13248 .cmd = NL80211_CMD_TDLS_CANCEL_CHANNEL_SWITCH,
13249 .doit = nl80211_tdls_cancel_channel_switch,
13250 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020013251 .flags = GENL_UNS_ADMIN_PERM,
Arik Nemtsov1057d352014-11-19 12:54:26 +020013252 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
13253 NL80211_FLAG_NEED_RTNL,
13254 },
Michael Braunce0ce132016-10-10 19:12:22 +020013255 {
13256 .cmd = NL80211_CMD_SET_MULTICAST_TO_UNICAST,
13257 .doit = nl80211_set_multicast_to_unicast,
13258 .policy = nl80211_policy,
13259 .flags = GENL_UNS_ADMIN_PERM,
13260 .internal_flags = NL80211_FLAG_NEED_NETDEV |
13261 NL80211_FLAG_NEED_RTNL,
13262 },
Avraham Stern3a00df52017-06-09 13:08:43 +010013263 {
13264 .cmd = NL80211_CMD_SET_PMK,
13265 .doit = nl80211_set_pmk,
13266 .policy = nl80211_policy,
13267 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
13268 NL80211_FLAG_NEED_RTNL,
13269 },
13270 {
13271 .cmd = NL80211_CMD_DEL_PMK,
13272 .doit = nl80211_del_pmk,
13273 .policy = nl80211_policy,
13274 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
13275 NL80211_FLAG_NEED_RTNL,
13276 },
13277
Johannes Berg55682962007-09-20 13:09:35 -040013278};
Jouni Malinen9588bbd2009-12-23 13:15:41 +010013279
Johannes Berg56989f62016-10-24 14:40:05 +020013280static struct genl_family nl80211_fam __ro_after_init = {
Johannes Berg489111e2016-10-24 14:40:03 +020013281 .name = NL80211_GENL_NAME, /* have users key off the name instead */
13282 .hdrsize = 0, /* no private header */
13283 .version = 1, /* no particular meaning now */
13284 .maxattr = NL80211_ATTR_MAX,
13285 .netnsok = true,
13286 .pre_doit = nl80211_pre_doit,
13287 .post_doit = nl80211_post_doit,
13288 .module = THIS_MODULE,
13289 .ops = nl80211_ops,
13290 .n_ops = ARRAY_SIZE(nl80211_ops),
13291 .mcgrps = nl80211_mcgrps,
13292 .n_mcgrps = ARRAY_SIZE(nl80211_mcgrps),
13293};
13294
Johannes Berg55682962007-09-20 13:09:35 -040013295/* notification functions */
13296
Johannes Berg3bb20552014-05-26 13:52:25 +020013297void nl80211_notify_wiphy(struct cfg80211_registered_device *rdev,
13298 enum nl80211_commands cmd)
Johannes Berg55682962007-09-20 13:09:35 -040013299{
13300 struct sk_buff *msg;
Johannes Berg86e8cf92013-06-19 10:57:22 +020013301 struct nl80211_dump_wiphy_state state = {};
Johannes Berg55682962007-09-20 13:09:35 -040013302
Johannes Berg3bb20552014-05-26 13:52:25 +020013303 WARN_ON(cmd != NL80211_CMD_NEW_WIPHY &&
13304 cmd != NL80211_CMD_DEL_WIPHY);
13305
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -070013306 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -040013307 if (!msg)
13308 return;
13309
Johannes Berg3bb20552014-05-26 13:52:25 +020013310 if (nl80211_send_wiphy(rdev, cmd, msg, 0, 0, 0, &state) < 0) {
Johannes Berg55682962007-09-20 13:09:35 -040013311 nlmsg_free(msg);
13312 return;
13313 }
13314
Johannes Berg68eb5502013-11-19 15:19:38 +010013315 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010013316 NL80211_MCGRP_CONFIG, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -040013317}
13318
Denis Kenzior896ff062016-08-03 16:58:33 -050013319void nl80211_notify_iface(struct cfg80211_registered_device *rdev,
13320 struct wireless_dev *wdev,
13321 enum nl80211_commands cmd)
13322{
13323 struct sk_buff *msg;
13324
13325 WARN_ON(cmd != NL80211_CMD_NEW_INTERFACE &&
13326 cmd != NL80211_CMD_DEL_INTERFACE);
13327
13328 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
13329 if (!msg)
13330 return;
13331
13332 if (nl80211_send_iface(msg, 0, 0, 0, rdev, wdev,
13333 cmd == NL80211_CMD_DEL_INTERFACE) < 0) {
13334 nlmsg_free(msg);
13335 return;
13336 }
13337
13338 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
13339 NL80211_MCGRP_CONFIG, GFP_KERNEL);
13340}
13341
Johannes Berg362a4152009-05-24 16:43:15 +020013342static int nl80211_add_scan_req(struct sk_buff *msg,
13343 struct cfg80211_registered_device *rdev)
13344{
13345 struct cfg80211_scan_request *req = rdev->scan_req;
13346 struct nlattr *nest;
13347 int i;
13348
13349 if (WARN_ON(!req))
13350 return 0;
13351
13352 nest = nla_nest_start(msg, NL80211_ATTR_SCAN_SSIDS);
13353 if (!nest)
13354 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -040013355 for (i = 0; i < req->n_ssids; i++) {
13356 if (nla_put(msg, i, req->ssids[i].ssid_len, req->ssids[i].ssid))
13357 goto nla_put_failure;
13358 }
Johannes Berg362a4152009-05-24 16:43:15 +020013359 nla_nest_end(msg, nest);
13360
13361 nest = nla_nest_start(msg, NL80211_ATTR_SCAN_FREQUENCIES);
13362 if (!nest)
13363 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -040013364 for (i = 0; i < req->n_channels; i++) {
13365 if (nla_put_u32(msg, i, req->channels[i]->center_freq))
13366 goto nla_put_failure;
13367 }
Johannes Berg362a4152009-05-24 16:43:15 +020013368 nla_nest_end(msg, nest);
13369
David S. Miller9360ffd2012-03-29 04:41:26 -040013370 if (req->ie &&
13371 nla_put(msg, NL80211_ATTR_IE, req->ie_len, req->ie))
13372 goto nla_put_failure;
Johannes Berg362a4152009-05-24 16:43:15 +020013373
Johannes Bergae917c92013-10-25 11:05:22 +020013374 if (req->flags &&
13375 nla_put_u32(msg, NL80211_ATTR_SCAN_FLAGS, req->flags))
13376 goto nla_put_failure;
Sam Lefflered4737712012-10-11 21:03:31 -070013377
Avraham Stern1d762502016-07-05 17:10:13 +030013378 if (req->info.scan_start_tsf &&
13379 (nla_put_u64_64bit(msg, NL80211_ATTR_SCAN_START_TIME_TSF,
13380 req->info.scan_start_tsf, NL80211_BSS_PAD) ||
13381 nla_put(msg, NL80211_ATTR_SCAN_START_TIME_TSF_BSSID, ETH_ALEN,
13382 req->info.tsf_bssid)))
13383 goto nla_put_failure;
13384
Johannes Berg362a4152009-05-24 16:43:15 +020013385 return 0;
13386 nla_put_failure:
13387 return -ENOBUFS;
13388}
13389
Arend Van Spriel505a2e82016-12-16 11:21:54 +000013390static int nl80211_prep_scan_msg(struct sk_buff *msg,
Johannes Berga538e2d2009-06-16 19:56:42 +020013391 struct cfg80211_registered_device *rdev,
Johannes Bergfd014282012-06-18 19:17:03 +020013392 struct wireless_dev *wdev,
Eric W. Biederman15e47302012-09-07 20:12:54 +000013393 u32 portid, u32 seq, int flags,
Johannes Berga538e2d2009-06-16 19:56:42 +020013394 u32 cmd)
Johannes Berg2a519312009-02-10 21:25:55 +010013395{
13396 void *hdr;
13397
Eric W. Biederman15e47302012-09-07 20:12:54 +000013398 hdr = nl80211hdr_put(msg, portid, seq, flags, cmd);
Johannes Berg2a519312009-02-10 21:25:55 +010013399 if (!hdr)
13400 return -1;
13401
David S. Miller9360ffd2012-03-29 04:41:26 -040013402 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Bergfd014282012-06-18 19:17:03 +020013403 (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
13404 wdev->netdev->ifindex)) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020013405 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
13406 NL80211_ATTR_PAD))
David S. Miller9360ffd2012-03-29 04:41:26 -040013407 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +010013408
Johannes Berg362a4152009-05-24 16:43:15 +020013409 /* ignore errors and send incomplete event anyway */
13410 nl80211_add_scan_req(msg, rdev);
Johannes Berg2a519312009-02-10 21:25:55 +010013411
Johannes Berg053c0952015-01-16 22:09:00 +010013412 genlmsg_end(msg, hdr);
13413 return 0;
Johannes Berg2a519312009-02-10 21:25:55 +010013414
13415 nla_put_failure:
13416 genlmsg_cancel(msg, hdr);
13417 return -EMSGSIZE;
13418}
13419
Luciano Coelho807f8a82011-05-11 17:09:35 +030013420static int
Arend Van Spriel505a2e82016-12-16 11:21:54 +000013421nl80211_prep_sched_scan_msg(struct sk_buff *msg,
Arend Van Spriel96b08fd2017-04-13 13:06:27 +010013422 struct cfg80211_sched_scan_request *req, u32 cmd)
Luciano Coelho807f8a82011-05-11 17:09:35 +030013423{
13424 void *hdr;
13425
Arend Van Spriel96b08fd2017-04-13 13:06:27 +010013426 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
Luciano Coelho807f8a82011-05-11 17:09:35 +030013427 if (!hdr)
13428 return -1;
13429
Arend Van Spriel96b08fd2017-04-13 13:06:27 +010013430 if (nla_put_u32(msg, NL80211_ATTR_WIPHY,
13431 wiphy_to_rdev(req->wiphy)->wiphy_idx) ||
13432 nla_put_u32(msg, NL80211_ATTR_IFINDEX, req->dev->ifindex) ||
13433 nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, req->reqid,
13434 NL80211_ATTR_PAD))
David S. Miller9360ffd2012-03-29 04:41:26 -040013435 goto nla_put_failure;
Luciano Coelho807f8a82011-05-11 17:09:35 +030013436
Johannes Berg053c0952015-01-16 22:09:00 +010013437 genlmsg_end(msg, hdr);
13438 return 0;
Luciano Coelho807f8a82011-05-11 17:09:35 +030013439
13440 nla_put_failure:
13441 genlmsg_cancel(msg, hdr);
13442 return -EMSGSIZE;
13443}
13444
Johannes Berga538e2d2009-06-16 19:56:42 +020013445void nl80211_send_scan_start(struct cfg80211_registered_device *rdev,
Johannes Bergfd014282012-06-18 19:17:03 +020013446 struct wireless_dev *wdev)
Johannes Berga538e2d2009-06-16 19:56:42 +020013447{
13448 struct sk_buff *msg;
13449
Thomas Graf58050fc2012-06-28 03:57:45 +000013450 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berga538e2d2009-06-16 19:56:42 +020013451 if (!msg)
13452 return;
13453
Arend Van Spriel505a2e82016-12-16 11:21:54 +000013454 if (nl80211_prep_scan_msg(msg, rdev, wdev, 0, 0, 0,
Johannes Berga538e2d2009-06-16 19:56:42 +020013455 NL80211_CMD_TRIGGER_SCAN) < 0) {
13456 nlmsg_free(msg);
13457 return;
13458 }
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 Berga538e2d2009-06-16 19:56:42 +020013462}
13463
Johannes Bergf9d15d12014-01-22 11:14:19 +020013464struct sk_buff *nl80211_build_scan_msg(struct cfg80211_registered_device *rdev,
13465 struct wireless_dev *wdev, bool aborted)
Johannes Berg2a519312009-02-10 21:25:55 +010013466{
13467 struct sk_buff *msg;
13468
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -070013469 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg2a519312009-02-10 21:25:55 +010013470 if (!msg)
Johannes Bergf9d15d12014-01-22 11:14:19 +020013471 return NULL;
Johannes Berg2a519312009-02-10 21:25:55 +010013472
Arend Van Spriel505a2e82016-12-16 11:21:54 +000013473 if (nl80211_prep_scan_msg(msg, rdev, wdev, 0, 0, 0,
Johannes Bergf9d15d12014-01-22 11:14:19 +020013474 aborted ? NL80211_CMD_SCAN_ABORTED :
13475 NL80211_CMD_NEW_SCAN_RESULTS) < 0) {
Johannes Berg2a519312009-02-10 21:25:55 +010013476 nlmsg_free(msg);
Johannes Bergf9d15d12014-01-22 11:14:19 +020013477 return NULL;
Johannes Berg2a519312009-02-10 21:25:55 +010013478 }
13479
Johannes Bergf9d15d12014-01-22 11:14:19 +020013480 return msg;
Johannes Berg2a519312009-02-10 21:25:55 +010013481}
13482
Arend Van Spriel505a2e82016-12-16 11:21:54 +000013483/* send message created by nl80211_build_scan_msg() */
13484void nl80211_send_scan_msg(struct cfg80211_registered_device *rdev,
13485 struct sk_buff *msg)
Johannes Berg2a519312009-02-10 21:25:55 +010013486{
Johannes Berg2a519312009-02-10 21:25:55 +010013487 if (!msg)
13488 return;
13489
Johannes Berg68eb5502013-11-19 15:19:38 +010013490 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010013491 NL80211_MCGRP_SCAN, GFP_KERNEL);
Johannes Berg2a519312009-02-10 21:25:55 +010013492}
13493
Arend Van Spriel96b08fd2017-04-13 13:06:27 +010013494void nl80211_send_sched_scan(struct cfg80211_sched_scan_request *req, u32 cmd)
Luciano Coelho807f8a82011-05-11 17:09:35 +030013495{
13496 struct sk_buff *msg;
13497
Thomas Graf58050fc2012-06-28 03:57:45 +000013498 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Luciano Coelho807f8a82011-05-11 17:09:35 +030013499 if (!msg)
13500 return;
13501
Arend Van Spriel96b08fd2017-04-13 13:06:27 +010013502 if (nl80211_prep_sched_scan_msg(msg, req, cmd) < 0) {
Luciano Coelho807f8a82011-05-11 17:09:35 +030013503 nlmsg_free(msg);
13504 return;
13505 }
13506
Arend Van Spriel96b08fd2017-04-13 13:06:27 +010013507 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(req->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010013508 NL80211_MCGRP_SCAN, GFP_KERNEL);
Luciano Coelho807f8a82011-05-11 17:09:35 +030013509}
13510
Jonathan Doronb0d7aa52014-12-15 19:26:00 +020013511static bool nl80211_reg_change_event_fill(struct sk_buff *msg,
13512 struct regulatory_request *request)
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040013513{
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040013514 /* Userspace can always count this one always being set */
David S. Miller9360ffd2012-03-29 04:41:26 -040013515 if (nla_put_u8(msg, NL80211_ATTR_REG_INITIATOR, request->initiator))
13516 goto nla_put_failure;
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040013517
David S. Miller9360ffd2012-03-29 04:41:26 -040013518 if (request->alpha2[0] == '0' && request->alpha2[1] == '0') {
13519 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
13520 NL80211_REGDOM_TYPE_WORLD))
13521 goto nla_put_failure;
13522 } else if (request->alpha2[0] == '9' && request->alpha2[1] == '9') {
13523 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
13524 NL80211_REGDOM_TYPE_CUSTOM_WORLD))
13525 goto nla_put_failure;
13526 } else if ((request->alpha2[0] == '9' && request->alpha2[1] == '8') ||
13527 request->intersect) {
13528 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
13529 NL80211_REGDOM_TYPE_INTERSECTION))
13530 goto nla_put_failure;
13531 } else {
13532 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
13533 NL80211_REGDOM_TYPE_COUNTRY) ||
13534 nla_put_string(msg, NL80211_ATTR_REG_ALPHA2,
13535 request->alpha2))
13536 goto nla_put_failure;
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040013537 }
13538
Arik Nemtsovad30ca22014-12-15 19:25:59 +020013539 if (request->wiphy_idx != WIPHY_IDX_INVALID) {
13540 struct wiphy *wiphy = wiphy_idx_to_wiphy(request->wiphy_idx);
13541
13542 if (wiphy &&
13543 nla_put_u32(msg, NL80211_ATTR_WIPHY, request->wiphy_idx))
13544 goto nla_put_failure;
Arik Nemtsov1bdd7162014-12-15 19:26:01 +020013545
13546 if (wiphy &&
13547 wiphy->regulatory_flags & REGULATORY_WIPHY_SELF_MANAGED &&
13548 nla_put_flag(msg, NL80211_ATTR_WIPHY_SELF_MANAGED_REG))
13549 goto nla_put_failure;
Arik Nemtsovad30ca22014-12-15 19:25:59 +020013550 }
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040013551
Jonathan Doronb0d7aa52014-12-15 19:26:00 +020013552 return true;
13553
13554nla_put_failure:
13555 return false;
13556}
13557
13558/*
13559 * This can happen on global regulatory changes or device specific settings
13560 * based on custom regulatory domains.
13561 */
13562void nl80211_common_reg_change_event(enum nl80211_commands cmd_id,
13563 struct regulatory_request *request)
13564{
13565 struct sk_buff *msg;
13566 void *hdr;
13567
13568 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
13569 if (!msg)
13570 return;
13571
13572 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd_id);
13573 if (!hdr) {
13574 nlmsg_free(msg);
13575 return;
13576 }
13577
13578 if (nl80211_reg_change_event_fill(msg, request) == false)
13579 goto nla_put_failure;
13580
Johannes Berg3b7b72e2011-10-22 19:05:51 +020013581 genlmsg_end(msg, hdr);
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040013582
Johannes Bergbc43b282009-07-25 10:54:13 +020013583 rcu_read_lock();
Johannes Berg68eb5502013-11-19 15:19:38 +010013584 genlmsg_multicast_allns(&nl80211_fam, msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010013585 NL80211_MCGRP_REGULATORY, GFP_ATOMIC);
Johannes Bergbc43b282009-07-25 10:54:13 +020013586 rcu_read_unlock();
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040013587
13588 return;
13589
13590nla_put_failure:
13591 genlmsg_cancel(msg, hdr);
13592 nlmsg_free(msg);
13593}
13594
Jouni Malinen6039f6d2009-03-19 13:39:21 +020013595static void nl80211_send_mlme_event(struct cfg80211_registered_device *rdev,
13596 struct net_device *netdev,
13597 const u8 *buf, size_t len,
Eliad Pellerb0b6aa22014-09-09 17:09:45 +030013598 enum nl80211_commands cmd, gfp_t gfp,
13599 int uapsd_queues)
Jouni Malinen6039f6d2009-03-19 13:39:21 +020013600{
13601 struct sk_buff *msg;
13602 void *hdr;
13603
Johannes Berg4ef8c1c2017-01-09 11:10:42 +010013604 msg = nlmsg_new(100 + len, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020013605 if (!msg)
13606 return;
13607
13608 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
13609 if (!hdr) {
13610 nlmsg_free(msg);
13611 return;
13612 }
13613
David S. Miller9360ffd2012-03-29 04:41:26 -040013614 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
13615 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
13616 nla_put(msg, NL80211_ATTR_FRAME, len, buf))
13617 goto nla_put_failure;
Jouni Malinen6039f6d2009-03-19 13:39:21 +020013618
Eliad Pellerb0b6aa22014-09-09 17:09:45 +030013619 if (uapsd_queues >= 0) {
13620 struct nlattr *nla_wmm =
13621 nla_nest_start(msg, NL80211_ATTR_STA_WME);
13622 if (!nla_wmm)
13623 goto nla_put_failure;
13624
13625 if (nla_put_u8(msg, NL80211_STA_WME_UAPSD_QUEUES,
13626 uapsd_queues))
13627 goto nla_put_failure;
13628
13629 nla_nest_end(msg, nla_wmm);
13630 }
13631
Johannes Berg3b7b72e2011-10-22 19:05:51 +020013632 genlmsg_end(msg, hdr);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020013633
Johannes Berg68eb5502013-11-19 15:19:38 +010013634 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010013635 NL80211_MCGRP_MLME, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020013636 return;
13637
13638 nla_put_failure:
13639 genlmsg_cancel(msg, hdr);
13640 nlmsg_free(msg);
13641}
13642
13643void nl80211_send_rx_auth(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +020013644 struct net_device *netdev, const u8 *buf,
13645 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +020013646{
13647 nl80211_send_mlme_event(rdev, netdev, buf, len,
Eliad Pellerb0b6aa22014-09-09 17:09:45 +030013648 NL80211_CMD_AUTHENTICATE, gfp, -1);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020013649}
13650
13651void nl80211_send_rx_assoc(struct cfg80211_registered_device *rdev,
13652 struct net_device *netdev, const u8 *buf,
Eliad Pellerb0b6aa22014-09-09 17:09:45 +030013653 size_t len, gfp_t gfp, int uapsd_queues)
Jouni Malinen6039f6d2009-03-19 13:39:21 +020013654{
Johannes Berge6d6e342009-07-01 21:26:47 +020013655 nl80211_send_mlme_event(rdev, netdev, buf, len,
Eliad Pellerb0b6aa22014-09-09 17:09:45 +030013656 NL80211_CMD_ASSOCIATE, gfp, uapsd_queues);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020013657}
13658
Jouni Malinen53b46b82009-03-27 20:53:56 +020013659void nl80211_send_deauth(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +020013660 struct net_device *netdev, const u8 *buf,
13661 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +020013662{
13663 nl80211_send_mlme_event(rdev, netdev, buf, len,
Eliad Pellerb0b6aa22014-09-09 17:09:45 +030013664 NL80211_CMD_DEAUTHENTICATE, gfp, -1);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020013665}
13666
Jouni Malinen53b46b82009-03-27 20:53:56 +020013667void nl80211_send_disassoc(struct cfg80211_registered_device *rdev,
13668 struct net_device *netdev, const u8 *buf,
Johannes Berge6d6e342009-07-01 21:26:47 +020013669 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +020013670{
13671 nl80211_send_mlme_event(rdev, netdev, buf, len,
Eliad Pellerb0b6aa22014-09-09 17:09:45 +030013672 NL80211_CMD_DISASSOCIATE, gfp, -1);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020013673}
13674
Johannes Berg6ff57cf2013-05-16 00:55:00 +020013675void cfg80211_rx_unprot_mlme_mgmt(struct net_device *dev, const u8 *buf,
13676 size_t len)
Jouni Malinencf4e5942010-12-16 00:52:40 +020013677{
Johannes Berg947add32013-02-22 22:05:20 +010013678 struct wireless_dev *wdev = dev->ieee80211_ptr;
13679 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080013680 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg6ff57cf2013-05-16 00:55:00 +020013681 const struct ieee80211_mgmt *mgmt = (void *)buf;
13682 u32 cmd;
Jouni Malinencf4e5942010-12-16 00:52:40 +020013683
Johannes Berg6ff57cf2013-05-16 00:55:00 +020013684 if (WARN_ON(len < 2))
13685 return;
13686
13687 if (ieee80211_is_deauth(mgmt->frame_control))
13688 cmd = NL80211_CMD_UNPROT_DEAUTHENTICATE;
13689 else
13690 cmd = NL80211_CMD_UNPROT_DISASSOCIATE;
13691
13692 trace_cfg80211_rx_unprot_mlme_mgmt(dev, buf, len);
Eliad Pellerb0b6aa22014-09-09 17:09:45 +030013693 nl80211_send_mlme_event(rdev, dev, buf, len, cmd, GFP_ATOMIC, -1);
Jouni Malinencf4e5942010-12-16 00:52:40 +020013694}
Johannes Berg6ff57cf2013-05-16 00:55:00 +020013695EXPORT_SYMBOL(cfg80211_rx_unprot_mlme_mgmt);
Jouni Malinencf4e5942010-12-16 00:52:40 +020013696
Luis R. Rodriguez1b06bb42009-05-02 00:34:48 -040013697static void nl80211_send_mlme_timeout(struct cfg80211_registered_device *rdev,
13698 struct net_device *netdev, int cmd,
Johannes Berge6d6e342009-07-01 21:26:47 +020013699 const u8 *addr, gfp_t gfp)
Jouni Malinen1965c852009-04-22 21:38:25 +030013700{
13701 struct sk_buff *msg;
13702 void *hdr;
13703
Johannes Berge6d6e342009-07-01 21:26:47 +020013704 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +030013705 if (!msg)
13706 return;
13707
13708 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
13709 if (!hdr) {
13710 nlmsg_free(msg);
13711 return;
13712 }
13713
David S. Miller9360ffd2012-03-29 04:41:26 -040013714 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
13715 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
13716 nla_put_flag(msg, NL80211_ATTR_TIMED_OUT) ||
13717 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr))
13718 goto nla_put_failure;
Jouni Malinen1965c852009-04-22 21:38:25 +030013719
Johannes Berg3b7b72e2011-10-22 19:05:51 +020013720 genlmsg_end(msg, hdr);
Jouni Malinen1965c852009-04-22 21:38:25 +030013721
Johannes Berg68eb5502013-11-19 15:19:38 +010013722 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010013723 NL80211_MCGRP_MLME, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +030013724 return;
13725
13726 nla_put_failure:
13727 genlmsg_cancel(msg, hdr);
13728 nlmsg_free(msg);
13729}
13730
13731void nl80211_send_auth_timeout(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +020013732 struct net_device *netdev, const u8 *addr,
13733 gfp_t gfp)
Jouni Malinen1965c852009-04-22 21:38:25 +030013734{
13735 nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_AUTHENTICATE,
Johannes Berge6d6e342009-07-01 21:26:47 +020013736 addr, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +030013737}
13738
13739void nl80211_send_assoc_timeout(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +020013740 struct net_device *netdev, const u8 *addr,
13741 gfp_t gfp)
Jouni Malinen1965c852009-04-22 21:38:25 +030013742{
Johannes Berge6d6e342009-07-01 21:26:47 +020013743 nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_ASSOCIATE,
13744 addr, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +030013745}
13746
Samuel Ortizb23aa672009-07-01 21:26:54 +020013747void nl80211_send_connect_result(struct cfg80211_registered_device *rdev,
Vidyullatha Kanchanapally5349a0f2017-03-31 00:22:33 +030013748 struct net_device *netdev,
13749 struct cfg80211_connect_resp_params *cr,
Purushottam Kushwaha3093ebbeab2017-01-13 01:12:21 +020013750 gfp_t gfp)
Samuel Ortizb23aa672009-07-01 21:26:54 +020013751{
13752 struct sk_buff *msg;
13753 void *hdr;
13754
Vidyullatha Kanchanapallya3caf742017-03-31 00:22:34 +030013755 msg = nlmsg_new(100 + cr->req_ie_len + cr->resp_ie_len +
13756 cr->fils_kek_len + cr->pmk_len +
13757 (cr->pmkid ? WLAN_PMKID_LEN : 0), gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +020013758 if (!msg)
13759 return;
13760
13761 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONNECT);
13762 if (!hdr) {
13763 nlmsg_free(msg);
13764 return;
13765 }
13766
David S. Miller9360ffd2012-03-29 04:41:26 -040013767 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
13768 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
Vidyullatha Kanchanapally5349a0f2017-03-31 00:22:33 +030013769 (cr->bssid &&
13770 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, cr->bssid)) ||
Jouni Malinenbf1ecd22016-05-31 00:16:50 +030013771 nla_put_u16(msg, NL80211_ATTR_STATUS_CODE,
Vidyullatha Kanchanapally5349a0f2017-03-31 00:22:33 +030013772 cr->status < 0 ? WLAN_STATUS_UNSPECIFIED_FAILURE :
13773 cr->status) ||
13774 (cr->status < 0 &&
Purushottam Kushwaha3093ebbeab2017-01-13 01:12:21 +020013775 (nla_put_flag(msg, NL80211_ATTR_TIMED_OUT) ||
Vidyullatha Kanchanapally5349a0f2017-03-31 00:22:33 +030013776 nla_put_u32(msg, NL80211_ATTR_TIMEOUT_REASON,
13777 cr->timeout_reason))) ||
13778 (cr->req_ie &&
13779 nla_put(msg, NL80211_ATTR_REQ_IE, cr->req_ie_len, cr->req_ie)) ||
13780 (cr->resp_ie &&
13781 nla_put(msg, NL80211_ATTR_RESP_IE, cr->resp_ie_len,
Vidyullatha Kanchanapallya3caf742017-03-31 00:22:34 +030013782 cr->resp_ie)) ||
13783 (cr->update_erp_next_seq_num &&
13784 nla_put_u16(msg, NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM,
13785 cr->fils_erp_next_seq_num)) ||
13786 (cr->status == WLAN_STATUS_SUCCESS &&
13787 ((cr->fils_kek &&
13788 nla_put(msg, NL80211_ATTR_FILS_KEK, cr->fils_kek_len,
13789 cr->fils_kek)) ||
13790 (cr->pmk &&
13791 nla_put(msg, NL80211_ATTR_PMK, cr->pmk_len, cr->pmk)) ||
13792 (cr->pmkid &&
13793 nla_put(msg, NL80211_ATTR_PMKID, WLAN_PMKID_LEN, cr->pmkid)))))
David S. Miller9360ffd2012-03-29 04:41:26 -040013794 goto nla_put_failure;
Samuel Ortizb23aa672009-07-01 21:26:54 +020013795
Johannes Berg3b7b72e2011-10-22 19:05:51 +020013796 genlmsg_end(msg, hdr);
Samuel Ortizb23aa672009-07-01 21:26:54 +020013797
Johannes Berg68eb5502013-11-19 15:19:38 +010013798 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010013799 NL80211_MCGRP_MLME, gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +020013800 return;
13801
13802 nla_put_failure:
13803 genlmsg_cancel(msg, hdr);
13804 nlmsg_free(msg);
Samuel Ortizb23aa672009-07-01 21:26:54 +020013805}
13806
13807void nl80211_send_roamed(struct cfg80211_registered_device *rdev,
Avraham Stern29ce6ec2017-04-26 10:58:49 +030013808 struct net_device *netdev,
13809 struct cfg80211_roam_info *info, gfp_t gfp)
Samuel Ortizb23aa672009-07-01 21:26:54 +020013810{
13811 struct sk_buff *msg;
13812 void *hdr;
Avraham Stern29ce6ec2017-04-26 10:58:49 +030013813 const u8 *bssid = info->bss ? info->bss->bssid : info->bssid;
Samuel Ortizb23aa672009-07-01 21:26:54 +020013814
Avraham Stern29ce6ec2017-04-26 10:58:49 +030013815 msg = nlmsg_new(100 + info->req_ie_len + info->resp_ie_len, gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +020013816 if (!msg)
13817 return;
13818
13819 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_ROAM);
13820 if (!hdr) {
13821 nlmsg_free(msg);
13822 return;
13823 }
13824
David S. Miller9360ffd2012-03-29 04:41:26 -040013825 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
13826 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
13827 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid) ||
Avraham Stern29ce6ec2017-04-26 10:58:49 +030013828 (info->req_ie &&
13829 nla_put(msg, NL80211_ATTR_REQ_IE, info->req_ie_len,
13830 info->req_ie)) ||
13831 (info->resp_ie &&
13832 nla_put(msg, NL80211_ATTR_RESP_IE, info->resp_ie_len,
Avraham Stern503c1fb2017-09-29 14:21:49 +020013833 info->resp_ie)))
David S. Miller9360ffd2012-03-29 04:41:26 -040013834 goto nla_put_failure;
Samuel Ortizb23aa672009-07-01 21:26:54 +020013835
Johannes Berg3b7b72e2011-10-22 19:05:51 +020013836 genlmsg_end(msg, hdr);
Samuel Ortizb23aa672009-07-01 21:26:54 +020013837
Johannes Berg68eb5502013-11-19 15:19:38 +010013838 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010013839 NL80211_MCGRP_MLME, gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +020013840 return;
13841
13842 nla_put_failure:
13843 genlmsg_cancel(msg, hdr);
13844 nlmsg_free(msg);
Samuel Ortizb23aa672009-07-01 21:26:54 +020013845}
13846
Avraham Stern503c1fb2017-09-29 14:21:49 +020013847void nl80211_send_port_authorized(struct cfg80211_registered_device *rdev,
13848 struct net_device *netdev, const u8 *bssid)
13849{
13850 struct sk_buff *msg;
13851 void *hdr;
13852
13853 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
13854 if (!msg)
13855 return;
13856
13857 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PORT_AUTHORIZED);
13858 if (!hdr) {
13859 nlmsg_free(msg);
13860 return;
13861 }
13862
13863 if (nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid))
13864 goto nla_put_failure;
13865
13866 genlmsg_end(msg, hdr);
13867
13868 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
13869 NL80211_MCGRP_MLME, GFP_KERNEL);
13870 return;
13871
13872 nla_put_failure:
13873 genlmsg_cancel(msg, hdr);
13874 nlmsg_free(msg);
13875}
13876
Samuel Ortizb23aa672009-07-01 21:26:54 +020013877void nl80211_send_disconnected(struct cfg80211_registered_device *rdev,
13878 struct net_device *netdev, u16 reason,
Johannes Berg667503d2009-07-07 03:56:11 +020013879 const u8 *ie, size_t ie_len, bool from_ap)
Samuel Ortizb23aa672009-07-01 21:26:54 +020013880{
13881 struct sk_buff *msg;
13882 void *hdr;
13883
Johannes Berg4ef8c1c2017-01-09 11:10:42 +010013884 msg = nlmsg_new(100 + ie_len, GFP_KERNEL);
Samuel Ortizb23aa672009-07-01 21:26:54 +020013885 if (!msg)
13886 return;
13887
13888 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DISCONNECT);
13889 if (!hdr) {
13890 nlmsg_free(msg);
13891 return;
13892 }
13893
David S. Miller9360ffd2012-03-29 04:41:26 -040013894 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
13895 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
13896 (from_ap && reason &&
13897 nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason)) ||
13898 (from_ap &&
13899 nla_put_flag(msg, NL80211_ATTR_DISCONNECTED_BY_AP)) ||
13900 (ie && nla_put(msg, NL80211_ATTR_IE, ie_len, ie)))
13901 goto nla_put_failure;
Samuel Ortizb23aa672009-07-01 21:26:54 +020013902
Johannes Berg3b7b72e2011-10-22 19:05:51 +020013903 genlmsg_end(msg, hdr);
Samuel Ortizb23aa672009-07-01 21:26:54 +020013904
Johannes Berg68eb5502013-11-19 15:19:38 +010013905 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010013906 NL80211_MCGRP_MLME, GFP_KERNEL);
Samuel Ortizb23aa672009-07-01 21:26:54 +020013907 return;
13908
13909 nla_put_failure:
13910 genlmsg_cancel(msg, hdr);
13911 nlmsg_free(msg);
Samuel Ortizb23aa672009-07-01 21:26:54 +020013912}
13913
Johannes Berg04a773a2009-04-19 21:24:32 +020013914void nl80211_send_ibss_bssid(struct cfg80211_registered_device *rdev,
13915 struct net_device *netdev, const u8 *bssid,
13916 gfp_t gfp)
13917{
13918 struct sk_buff *msg;
13919 void *hdr;
13920
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -070013921 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Johannes Berg04a773a2009-04-19 21:24:32 +020013922 if (!msg)
13923 return;
13924
13925 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_JOIN_IBSS);
13926 if (!hdr) {
13927 nlmsg_free(msg);
13928 return;
13929 }
13930
David S. Miller9360ffd2012-03-29 04:41:26 -040013931 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
13932 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
13933 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid))
13934 goto nla_put_failure;
Johannes Berg04a773a2009-04-19 21:24:32 +020013935
Johannes Berg3b7b72e2011-10-22 19:05:51 +020013936 genlmsg_end(msg, hdr);
Johannes Berg04a773a2009-04-19 21:24:32 +020013937
Johannes Berg68eb5502013-11-19 15:19:38 +010013938 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010013939 NL80211_MCGRP_MLME, gfp);
Johannes Berg04a773a2009-04-19 21:24:32 +020013940 return;
13941
13942 nla_put_failure:
13943 genlmsg_cancel(msg, hdr);
13944 nlmsg_free(msg);
13945}
13946
Johannes Berg947add32013-02-22 22:05:20 +010013947void cfg80211_notify_new_peer_candidate(struct net_device *dev, const u8 *addr,
13948 const u8* ie, u8 ie_len, gfp_t gfp)
Javier Cardonac93b5e72011-04-07 15:08:34 -070013949{
Johannes Berg947add32013-02-22 22:05:20 +010013950 struct wireless_dev *wdev = dev->ieee80211_ptr;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080013951 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Javier Cardonac93b5e72011-04-07 15:08:34 -070013952 struct sk_buff *msg;
13953 void *hdr;
13954
Johannes Berg947add32013-02-22 22:05:20 +010013955 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_MESH_POINT))
13956 return;
13957
13958 trace_cfg80211_notify_new_peer_candidate(dev, addr);
13959
Johannes Berg4ef8c1c2017-01-09 11:10:42 +010013960 msg = nlmsg_new(100 + ie_len, gfp);
Javier Cardonac93b5e72011-04-07 15:08:34 -070013961 if (!msg)
13962 return;
13963
13964 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NEW_PEER_CANDIDATE);
13965 if (!hdr) {
13966 nlmsg_free(msg);
13967 return;
13968 }
13969
David S. Miller9360ffd2012-03-29 04:41:26 -040013970 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg947add32013-02-22 22:05:20 +010013971 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
13972 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040013973 (ie_len && ie &&
13974 nla_put(msg, NL80211_ATTR_IE, ie_len , ie)))
13975 goto nla_put_failure;
Javier Cardonac93b5e72011-04-07 15:08:34 -070013976
Johannes Berg3b7b72e2011-10-22 19:05:51 +020013977 genlmsg_end(msg, hdr);
Javier Cardonac93b5e72011-04-07 15:08:34 -070013978
Johannes Berg68eb5502013-11-19 15:19:38 +010013979 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010013980 NL80211_MCGRP_MLME, gfp);
Javier Cardonac93b5e72011-04-07 15:08:34 -070013981 return;
13982
13983 nla_put_failure:
13984 genlmsg_cancel(msg, hdr);
13985 nlmsg_free(msg);
13986}
Johannes Berg947add32013-02-22 22:05:20 +010013987EXPORT_SYMBOL(cfg80211_notify_new_peer_candidate);
Javier Cardonac93b5e72011-04-07 15:08:34 -070013988
Jouni Malinena3b8b052009-03-27 21:59:49 +020013989void nl80211_michael_mic_failure(struct cfg80211_registered_device *rdev,
13990 struct net_device *netdev, const u8 *addr,
13991 enum nl80211_key_type key_type, int key_id,
Johannes Berge6d6e342009-07-01 21:26:47 +020013992 const u8 *tsc, gfp_t gfp)
Jouni Malinena3b8b052009-03-27 21:59:49 +020013993{
13994 struct sk_buff *msg;
13995 void *hdr;
13996
Johannes Berge6d6e342009-07-01 21:26:47 +020013997 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinena3b8b052009-03-27 21:59:49 +020013998 if (!msg)
13999 return;
14000
14001 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_MICHAEL_MIC_FAILURE);
14002 if (!hdr) {
14003 nlmsg_free(msg);
14004 return;
14005 }
14006
David S. Miller9360ffd2012-03-29 04:41:26 -040014007 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
14008 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
14009 (addr && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) ||
14010 nla_put_u32(msg, NL80211_ATTR_KEY_TYPE, key_type) ||
14011 (key_id != -1 &&
14012 nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_id)) ||
14013 (tsc && nla_put(msg, NL80211_ATTR_KEY_SEQ, 6, tsc)))
14014 goto nla_put_failure;
Jouni Malinena3b8b052009-03-27 21:59:49 +020014015
Johannes Berg3b7b72e2011-10-22 19:05:51 +020014016 genlmsg_end(msg, hdr);
Jouni Malinena3b8b052009-03-27 21:59:49 +020014017
Johannes Berg68eb5502013-11-19 15:19:38 +010014018 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010014019 NL80211_MCGRP_MLME, gfp);
Jouni Malinena3b8b052009-03-27 21:59:49 +020014020 return;
14021
14022 nla_put_failure:
14023 genlmsg_cancel(msg, hdr);
14024 nlmsg_free(msg);
14025}
14026
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040014027void nl80211_send_beacon_hint_event(struct wiphy *wiphy,
14028 struct ieee80211_channel *channel_before,
14029 struct ieee80211_channel *channel_after)
14030{
14031 struct sk_buff *msg;
14032 void *hdr;
14033 struct nlattr *nl_freq;
14034
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -070014035 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_ATOMIC);
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040014036 if (!msg)
14037 return;
14038
14039 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_BEACON_HINT);
14040 if (!hdr) {
14041 nlmsg_free(msg);
14042 return;
14043 }
14044
14045 /*
14046 * Since we are applying the beacon hint to a wiphy we know its
14047 * wiphy_idx is valid
14048 */
David S. Miller9360ffd2012-03-29 04:41:26 -040014049 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy)))
14050 goto nla_put_failure;
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040014051
14052 /* Before */
14053 nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_BEFORE);
14054 if (!nl_freq)
14055 goto nla_put_failure;
Johannes Bergcdc89b92013-02-18 23:54:36 +010014056 if (nl80211_msg_put_channel(msg, channel_before, false))
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040014057 goto nla_put_failure;
14058 nla_nest_end(msg, nl_freq);
14059
14060 /* After */
14061 nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_AFTER);
14062 if (!nl_freq)
14063 goto nla_put_failure;
Johannes Bergcdc89b92013-02-18 23:54:36 +010014064 if (nl80211_msg_put_channel(msg, channel_after, false))
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040014065 goto nla_put_failure;
14066 nla_nest_end(msg, nl_freq);
14067
Johannes Berg3b7b72e2011-10-22 19:05:51 +020014068 genlmsg_end(msg, hdr);
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040014069
Johannes Berg463d0182009-07-14 00:33:35 +020014070 rcu_read_lock();
Johannes Berg68eb5502013-11-19 15:19:38 +010014071 genlmsg_multicast_allns(&nl80211_fam, msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010014072 NL80211_MCGRP_REGULATORY, GFP_ATOMIC);
Johannes Berg463d0182009-07-14 00:33:35 +020014073 rcu_read_unlock();
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040014074
14075 return;
14076
14077nla_put_failure:
14078 genlmsg_cancel(msg, hdr);
14079 nlmsg_free(msg);
14080}
14081
Jouni Malinen9588bbd2009-12-23 13:15:41 +010014082static void nl80211_send_remain_on_chan_event(
14083 int cmd, struct cfg80211_registered_device *rdev,
Johannes Berg71bbc992012-06-15 15:30:18 +020014084 struct wireless_dev *wdev, u64 cookie,
Jouni Malinen9588bbd2009-12-23 13:15:41 +010014085 struct ieee80211_channel *chan,
Jouni Malinen9588bbd2009-12-23 13:15:41 +010014086 unsigned int duration, gfp_t gfp)
14087{
14088 struct sk_buff *msg;
14089 void *hdr;
14090
14091 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
14092 if (!msg)
14093 return;
14094
14095 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
14096 if (!hdr) {
14097 nlmsg_free(msg);
14098 return;
14099 }
14100
David S. Miller9360ffd2012-03-29 04:41:26 -040014101 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg71bbc992012-06-15 15:30:18 +020014102 (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
14103 wdev->netdev->ifindex)) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020014104 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
14105 NL80211_ATTR_PAD) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040014106 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, chan->center_freq) ||
Johannes Berg42d97a52012-11-08 18:31:02 +010014107 nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE,
14108 NL80211_CHAN_NO_HT) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020014109 nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie,
14110 NL80211_ATTR_PAD))
David S. Miller9360ffd2012-03-29 04:41:26 -040014111 goto nla_put_failure;
Jouni Malinen9588bbd2009-12-23 13:15:41 +010014112
David S. Miller9360ffd2012-03-29 04:41:26 -040014113 if (cmd == NL80211_CMD_REMAIN_ON_CHANNEL &&
14114 nla_put_u32(msg, NL80211_ATTR_DURATION, duration))
14115 goto nla_put_failure;
Jouni Malinen9588bbd2009-12-23 13:15:41 +010014116
Johannes Berg3b7b72e2011-10-22 19:05:51 +020014117 genlmsg_end(msg, hdr);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010014118
Johannes Berg68eb5502013-11-19 15:19:38 +010014119 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010014120 NL80211_MCGRP_MLME, gfp);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010014121 return;
14122
14123 nla_put_failure:
14124 genlmsg_cancel(msg, hdr);
14125 nlmsg_free(msg);
14126}
14127
Johannes Berg947add32013-02-22 22:05:20 +010014128void cfg80211_ready_on_channel(struct wireless_dev *wdev, u64 cookie,
14129 struct ieee80211_channel *chan,
14130 unsigned int duration, gfp_t gfp)
Jouni Malinen9588bbd2009-12-23 13:15:41 +010014131{
Johannes Berg947add32013-02-22 22:05:20 +010014132 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080014133 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg947add32013-02-22 22:05:20 +010014134
14135 trace_cfg80211_ready_on_channel(wdev, cookie, chan, duration);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010014136 nl80211_send_remain_on_chan_event(NL80211_CMD_REMAIN_ON_CHANNEL,
Johannes Berg71bbc992012-06-15 15:30:18 +020014137 rdev, wdev, cookie, chan,
Johannes Berg42d97a52012-11-08 18:31:02 +010014138 duration, gfp);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010014139}
Johannes Berg947add32013-02-22 22:05:20 +010014140EXPORT_SYMBOL(cfg80211_ready_on_channel);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010014141
Johannes Berg947add32013-02-22 22:05:20 +010014142void cfg80211_remain_on_channel_expired(struct wireless_dev *wdev, u64 cookie,
14143 struct ieee80211_channel *chan,
14144 gfp_t gfp)
Jouni Malinen9588bbd2009-12-23 13:15:41 +010014145{
Johannes Berg947add32013-02-22 22:05:20 +010014146 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080014147 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg947add32013-02-22 22:05:20 +010014148
14149 trace_cfg80211_ready_on_channel_expired(wdev, cookie, chan);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010014150 nl80211_send_remain_on_chan_event(NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL,
Johannes Berg42d97a52012-11-08 18:31:02 +010014151 rdev, wdev, cookie, chan, 0, gfp);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010014152}
Johannes Berg947add32013-02-22 22:05:20 +010014153EXPORT_SYMBOL(cfg80211_remain_on_channel_expired);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010014154
Johannes Berg947add32013-02-22 22:05:20 +010014155void cfg80211_new_sta(struct net_device *dev, const u8 *mac_addr,
14156 struct station_info *sinfo, gfp_t gfp)
Johannes Berg98b62182009-12-23 13:15:44 +010014157{
Johannes Berg947add32013-02-22 22:05:20 +010014158 struct wiphy *wiphy = dev->ieee80211_ptr->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080014159 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg98b62182009-12-23 13:15:44 +010014160 struct sk_buff *msg;
14161
Johannes Berg947add32013-02-22 22:05:20 +010014162 trace_cfg80211_new_sta(dev, mac_addr, sinfo);
14163
Thomas Graf58050fc2012-06-28 03:57:45 +000014164 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Johannes Berg98b62182009-12-23 13:15:44 +010014165 if (!msg)
14166 return;
14167
Johannes Bergcf5ead82014-11-14 17:14:00 +010014168 if (nl80211_send_station(msg, NL80211_CMD_NEW_STATION, 0, 0, 0,
John W. Linville66266b32012-03-15 13:25:41 -040014169 rdev, dev, mac_addr, sinfo) < 0) {
Johannes Berg98b62182009-12-23 13:15:44 +010014170 nlmsg_free(msg);
14171 return;
14172 }
14173
Johannes Berg68eb5502013-11-19 15:19:38 +010014174 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010014175 NL80211_MCGRP_MLME, gfp);
Johannes Berg98b62182009-12-23 13:15:44 +010014176}
Johannes Berg947add32013-02-22 22:05:20 +010014177EXPORT_SYMBOL(cfg80211_new_sta);
Johannes Berg98b62182009-12-23 13:15:44 +010014178
Johannes Bergcf5ead82014-11-14 17:14:00 +010014179void cfg80211_del_sta_sinfo(struct net_device *dev, const u8 *mac_addr,
14180 struct station_info *sinfo, gfp_t gfp)
Jouni Malinenec15e682011-03-23 15:29:52 +020014181{
Johannes Berg947add32013-02-22 22:05:20 +010014182 struct wiphy *wiphy = dev->ieee80211_ptr->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080014183 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Jouni Malinenec15e682011-03-23 15:29:52 +020014184 struct sk_buff *msg;
Johannes Bergcf5ead82014-11-14 17:14:00 +010014185 struct station_info empty_sinfo = {};
14186
14187 if (!sinfo)
14188 sinfo = &empty_sinfo;
Jouni Malinenec15e682011-03-23 15:29:52 +020014189
Johannes Berg947add32013-02-22 22:05:20 +010014190 trace_cfg80211_del_sta(dev, mac_addr);
14191
Thomas Graf58050fc2012-06-28 03:57:45 +000014192 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinenec15e682011-03-23 15:29:52 +020014193 if (!msg)
14194 return;
14195
Johannes Bergcf5ead82014-11-14 17:14:00 +010014196 if (nl80211_send_station(msg, NL80211_CMD_DEL_STATION, 0, 0, 0,
Johannes Berg57007122015-01-16 21:05:02 +010014197 rdev, dev, mac_addr, sinfo) < 0) {
Jouni Malinenec15e682011-03-23 15:29:52 +020014198 nlmsg_free(msg);
14199 return;
14200 }
14201
Johannes Berg68eb5502013-11-19 15:19:38 +010014202 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010014203 NL80211_MCGRP_MLME, gfp);
Jouni Malinenec15e682011-03-23 15:29:52 +020014204}
Johannes Bergcf5ead82014-11-14 17:14:00 +010014205EXPORT_SYMBOL(cfg80211_del_sta_sinfo);
Jouni Malinenec15e682011-03-23 15:29:52 +020014206
Johannes Berg947add32013-02-22 22:05:20 +010014207void cfg80211_conn_failed(struct net_device *dev, const u8 *mac_addr,
14208 enum nl80211_connect_failed_reason reason,
14209 gfp_t gfp)
Pandiyarajan Pitchaimuthued44a952012-09-18 16:50:49 +053014210{
Johannes Berg947add32013-02-22 22:05:20 +010014211 struct wiphy *wiphy = dev->ieee80211_ptr->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080014212 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Pandiyarajan Pitchaimuthued44a952012-09-18 16:50:49 +053014213 struct sk_buff *msg;
14214 void *hdr;
14215
14216 msg = nlmsg_new(NLMSG_GOODSIZE, gfp);
14217 if (!msg)
14218 return;
14219
14220 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONN_FAILED);
14221 if (!hdr) {
14222 nlmsg_free(msg);
14223 return;
14224 }
14225
14226 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
14227 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) ||
14228 nla_put_u32(msg, NL80211_ATTR_CONN_FAILED_REASON, reason))
14229 goto nla_put_failure;
14230
14231 genlmsg_end(msg, hdr);
14232
Johannes Berg68eb5502013-11-19 15:19:38 +010014233 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010014234 NL80211_MCGRP_MLME, gfp);
Pandiyarajan Pitchaimuthued44a952012-09-18 16:50:49 +053014235 return;
14236
14237 nla_put_failure:
14238 genlmsg_cancel(msg, hdr);
14239 nlmsg_free(msg);
14240}
Johannes Berg947add32013-02-22 22:05:20 +010014241EXPORT_SYMBOL(cfg80211_conn_failed);
Pandiyarajan Pitchaimuthued44a952012-09-18 16:50:49 +053014242
Johannes Bergb92ab5d2011-11-04 11:18:19 +010014243static bool __nl80211_unexpected_frame(struct net_device *dev, u8 cmd,
14244 const u8 *addr, gfp_t gfp)
Johannes Berg28946da2011-11-04 11:18:12 +010014245{
14246 struct wireless_dev *wdev = dev->ieee80211_ptr;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080014247 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Johannes Berg28946da2011-11-04 11:18:12 +010014248 struct sk_buff *msg;
14249 void *hdr;
Eric W. Biederman15e47302012-09-07 20:12:54 +000014250 u32 nlportid = ACCESS_ONCE(wdev->ap_unexpected_nlportid);
Johannes Berg28946da2011-11-04 11:18:12 +010014251
Eric W. Biederman15e47302012-09-07 20:12:54 +000014252 if (!nlportid)
Johannes Berg28946da2011-11-04 11:18:12 +010014253 return false;
14254
14255 msg = nlmsg_new(100, gfp);
14256 if (!msg)
14257 return true;
14258
Johannes Bergb92ab5d2011-11-04 11:18:19 +010014259 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
Johannes Berg28946da2011-11-04 11:18:12 +010014260 if (!hdr) {
14261 nlmsg_free(msg);
14262 return true;
14263 }
14264
David S. Miller9360ffd2012-03-29 04:41:26 -040014265 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
14266 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
14267 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr))
14268 goto nla_put_failure;
Johannes Berg28946da2011-11-04 11:18:12 +010014269
Johannes Berg9c90a9f2013-06-04 12:46:03 +020014270 genlmsg_end(msg, hdr);
Eric W. Biederman15e47302012-09-07 20:12:54 +000014271 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid);
Johannes Berg28946da2011-11-04 11:18:12 +010014272 return true;
14273
14274 nla_put_failure:
14275 genlmsg_cancel(msg, hdr);
14276 nlmsg_free(msg);
14277 return true;
14278}
14279
Johannes Berg947add32013-02-22 22:05:20 +010014280bool cfg80211_rx_spurious_frame(struct net_device *dev,
14281 const u8 *addr, gfp_t gfp)
Johannes Bergb92ab5d2011-11-04 11:18:19 +010014282{
Johannes Berg947add32013-02-22 22:05:20 +010014283 struct wireless_dev *wdev = dev->ieee80211_ptr;
14284 bool ret;
Johannes Bergb92ab5d2011-11-04 11:18:19 +010014285
Johannes Berg947add32013-02-22 22:05:20 +010014286 trace_cfg80211_rx_spurious_frame(dev, addr);
14287
14288 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP &&
14289 wdev->iftype != NL80211_IFTYPE_P2P_GO)) {
14290 trace_cfg80211_return_bool(false);
14291 return false;
14292 }
14293 ret = __nl80211_unexpected_frame(dev, NL80211_CMD_UNEXPECTED_FRAME,
14294 addr, gfp);
14295 trace_cfg80211_return_bool(ret);
14296 return ret;
Johannes Bergb92ab5d2011-11-04 11:18:19 +010014297}
Johannes Berg947add32013-02-22 22:05:20 +010014298EXPORT_SYMBOL(cfg80211_rx_spurious_frame);
14299
14300bool cfg80211_rx_unexpected_4addr_frame(struct net_device *dev,
14301 const u8 *addr, gfp_t gfp)
14302{
14303 struct wireless_dev *wdev = dev->ieee80211_ptr;
14304 bool ret;
14305
14306 trace_cfg80211_rx_unexpected_4addr_frame(dev, addr);
14307
14308 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP &&
14309 wdev->iftype != NL80211_IFTYPE_P2P_GO &&
14310 wdev->iftype != NL80211_IFTYPE_AP_VLAN)) {
14311 trace_cfg80211_return_bool(false);
14312 return false;
14313 }
14314 ret = __nl80211_unexpected_frame(dev,
14315 NL80211_CMD_UNEXPECTED_4ADDR_FRAME,
14316 addr, gfp);
14317 trace_cfg80211_return_bool(ret);
14318 return ret;
14319}
14320EXPORT_SYMBOL(cfg80211_rx_unexpected_4addr_frame);
Johannes Bergb92ab5d2011-11-04 11:18:19 +010014321
Johannes Berg2e161f72010-08-12 15:38:38 +020014322int nl80211_send_mgmt(struct cfg80211_registered_device *rdev,
Eric W. Biederman15e47302012-09-07 20:12:54 +000014323 struct wireless_dev *wdev, u32 nlportid,
Johannes Berg804483e2012-03-05 22:18:41 +010014324 int freq, int sig_dbm,
Vladimir Kondratiev19504cf2013-08-15 14:51:28 +030014325 const u8 *buf, size_t len, u32 flags, gfp_t gfp)
Jouni Malinen026331c2010-02-15 12:53:10 +020014326{
Johannes Berg71bbc992012-06-15 15:30:18 +020014327 struct net_device *netdev = wdev->netdev;
Jouni Malinen026331c2010-02-15 12:53:10 +020014328 struct sk_buff *msg;
14329 void *hdr;
Jouni Malinen026331c2010-02-15 12:53:10 +020014330
Johannes Berg4ef8c1c2017-01-09 11:10:42 +010014331 msg = nlmsg_new(100 + len, gfp);
Jouni Malinen026331c2010-02-15 12:53:10 +020014332 if (!msg)
14333 return -ENOMEM;
14334
Johannes Berg2e161f72010-08-12 15:38:38 +020014335 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME);
Jouni Malinen026331c2010-02-15 12:53:10 +020014336 if (!hdr) {
14337 nlmsg_free(msg);
14338 return -ENOMEM;
14339 }
14340
David S. Miller9360ffd2012-03-29 04:41:26 -040014341 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg71bbc992012-06-15 15:30:18 +020014342 (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
14343 netdev->ifindex)) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020014344 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
14345 NL80211_ATTR_PAD) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040014346 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq) ||
14347 (sig_dbm &&
14348 nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) ||
Vladimir Kondratiev19504cf2013-08-15 14:51:28 +030014349 nla_put(msg, NL80211_ATTR_FRAME, len, buf) ||
14350 (flags &&
14351 nla_put_u32(msg, NL80211_ATTR_RXMGMT_FLAGS, flags)))
David S. Miller9360ffd2012-03-29 04:41:26 -040014352 goto nla_put_failure;
Jouni Malinen026331c2010-02-15 12:53:10 +020014353
Johannes Berg3b7b72e2011-10-22 19:05:51 +020014354 genlmsg_end(msg, hdr);
Jouni Malinen026331c2010-02-15 12:53:10 +020014355
Eric W. Biederman15e47302012-09-07 20:12:54 +000014356 return genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid);
Jouni Malinen026331c2010-02-15 12:53:10 +020014357
14358 nla_put_failure:
14359 genlmsg_cancel(msg, hdr);
14360 nlmsg_free(msg);
14361 return -ENOBUFS;
14362}
14363
Johannes Berg947add32013-02-22 22:05:20 +010014364void cfg80211_mgmt_tx_status(struct wireless_dev *wdev, u64 cookie,
14365 const u8 *buf, size_t len, bool ack, gfp_t gfp)
Jouni Malinen026331c2010-02-15 12:53:10 +020014366{
Johannes Berg947add32013-02-22 22:05:20 +010014367 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080014368 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg71bbc992012-06-15 15:30:18 +020014369 struct net_device *netdev = wdev->netdev;
Jouni Malinen026331c2010-02-15 12:53:10 +020014370 struct sk_buff *msg;
14371 void *hdr;
14372
Johannes Berg947add32013-02-22 22:05:20 +010014373 trace_cfg80211_mgmt_tx_status(wdev, cookie, ack);
14374
Johannes Berg4ef8c1c2017-01-09 11:10:42 +010014375 msg = nlmsg_new(100 + len, gfp);
Jouni Malinen026331c2010-02-15 12:53:10 +020014376 if (!msg)
14377 return;
14378
Johannes Berg2e161f72010-08-12 15:38:38 +020014379 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME_TX_STATUS);
Jouni Malinen026331c2010-02-15 12:53:10 +020014380 if (!hdr) {
14381 nlmsg_free(msg);
14382 return;
14383 }
14384
David S. Miller9360ffd2012-03-29 04:41:26 -040014385 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg71bbc992012-06-15 15:30:18 +020014386 (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
14387 netdev->ifindex)) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020014388 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
14389 NL80211_ATTR_PAD) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040014390 nla_put(msg, NL80211_ATTR_FRAME, len, buf) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020014391 nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie,
14392 NL80211_ATTR_PAD) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040014393 (ack && nla_put_flag(msg, NL80211_ATTR_ACK)))
14394 goto nla_put_failure;
Jouni Malinen026331c2010-02-15 12:53:10 +020014395
Johannes Berg3b7b72e2011-10-22 19:05:51 +020014396 genlmsg_end(msg, hdr);
Jouni Malinen026331c2010-02-15 12:53:10 +020014397
Johannes Berg68eb5502013-11-19 15:19:38 +010014398 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010014399 NL80211_MCGRP_MLME, gfp);
Jouni Malinen026331c2010-02-15 12:53:10 +020014400 return;
14401
14402 nla_put_failure:
14403 genlmsg_cancel(msg, hdr);
14404 nlmsg_free(msg);
14405}
Johannes Berg947add32013-02-22 22:05:20 +010014406EXPORT_SYMBOL(cfg80211_mgmt_tx_status);
Jouni Malinen026331c2010-02-15 12:53:10 +020014407
Johannes Berg5b97f492014-11-26 12:37:43 +010014408static struct sk_buff *cfg80211_prepare_cqm(struct net_device *dev,
14409 const char *mac, gfp_t gfp)
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020014410{
Johannes Berg947add32013-02-22 22:05:20 +010014411 struct wireless_dev *wdev = dev->ieee80211_ptr;
Johannes Berg5b97f492014-11-26 12:37:43 +010014412 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
14413 struct sk_buff *msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
14414 void **cb;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020014415
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020014416 if (!msg)
Johannes Berg5b97f492014-11-26 12:37:43 +010014417 return NULL;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020014418
Johannes Berg5b97f492014-11-26 12:37:43 +010014419 cb = (void **)msg->cb;
14420
14421 cb[0] = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM);
14422 if (!cb[0]) {
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020014423 nlmsg_free(msg);
Johannes Berg5b97f492014-11-26 12:37:43 +010014424 return NULL;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020014425 }
14426
David S. Miller9360ffd2012-03-29 04:41:26 -040014427 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg947add32013-02-22 22:05:20 +010014428 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex))
David S. Miller9360ffd2012-03-29 04:41:26 -040014429 goto nla_put_failure;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020014430
Johannes Berg5b97f492014-11-26 12:37:43 +010014431 if (mac && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac))
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020014432 goto nla_put_failure;
14433
Johannes Berg5b97f492014-11-26 12:37:43 +010014434 cb[1] = nla_nest_start(msg, NL80211_ATTR_CQM);
14435 if (!cb[1])
14436 goto nla_put_failure;
14437
14438 cb[2] = rdev;
14439
14440 return msg;
14441 nla_put_failure:
14442 nlmsg_free(msg);
14443 return NULL;
14444}
14445
14446static void cfg80211_send_cqm(struct sk_buff *msg, gfp_t gfp)
14447{
14448 void **cb = (void **)msg->cb;
14449 struct cfg80211_registered_device *rdev = cb[2];
14450
14451 nla_nest_end(msg, cb[1]);
14452 genlmsg_end(msg, cb[0]);
14453
14454 memset(msg->cb, 0, sizeof(msg->cb));
14455
14456 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
14457 NL80211_MCGRP_MLME, gfp);
14458}
14459
14460void cfg80211_cqm_rssi_notify(struct net_device *dev,
14461 enum nl80211_cqm_rssi_threshold_event rssi_event,
Andrzej Zaborowskibee427b2017-01-25 12:43:41 +010014462 s32 rssi_level, gfp_t gfp)
Johannes Berg5b97f492014-11-26 12:37:43 +010014463{
14464 struct sk_buff *msg;
Andrew Zaborowski4a4b8162017-02-10 10:02:31 +010014465 struct wireless_dev *wdev = dev->ieee80211_ptr;
14466 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Johannes Berg5b97f492014-11-26 12:37:43 +010014467
Andrzej Zaborowskibee427b2017-01-25 12:43:41 +010014468 trace_cfg80211_cqm_rssi_notify(dev, rssi_event, rssi_level);
Johannes Berg5b97f492014-11-26 12:37:43 +010014469
Johannes Berg98f03342014-11-26 12:42:02 +010014470 if (WARN_ON(rssi_event != NL80211_CQM_RSSI_THRESHOLD_EVENT_LOW &&
14471 rssi_event != NL80211_CQM_RSSI_THRESHOLD_EVENT_HIGH))
14472 return;
14473
Andrew Zaborowski4a4b8162017-02-10 10:02:31 +010014474 if (wdev->cqm_config) {
14475 wdev->cqm_config->last_rssi_event_value = rssi_level;
14476
14477 cfg80211_cqm_rssi_update(rdev, dev);
14478
14479 if (rssi_level == 0)
14480 rssi_level = wdev->cqm_config->last_rssi_event_value;
14481 }
14482
Johannes Berg5b97f492014-11-26 12:37:43 +010014483 msg = cfg80211_prepare_cqm(dev, NULL, gfp);
14484 if (!msg)
14485 return;
14486
David S. Miller9360ffd2012-03-29 04:41:26 -040014487 if (nla_put_u32(msg, NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT,
14488 rssi_event))
14489 goto nla_put_failure;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020014490
Andrzej Zaborowskibee427b2017-01-25 12:43:41 +010014491 if (rssi_level && nla_put_s32(msg, NL80211_ATTR_CQM_RSSI_LEVEL,
14492 rssi_level))
14493 goto nla_put_failure;
14494
Johannes Berg5b97f492014-11-26 12:37:43 +010014495 cfg80211_send_cqm(msg, gfp);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020014496
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020014497 return;
14498
14499 nla_put_failure:
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020014500 nlmsg_free(msg);
14501}
Johannes Berg947add32013-02-22 22:05:20 +010014502EXPORT_SYMBOL(cfg80211_cqm_rssi_notify);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020014503
Johannes Berg5b97f492014-11-26 12:37:43 +010014504void cfg80211_cqm_txe_notify(struct net_device *dev,
14505 const u8 *peer, u32 num_packets,
14506 u32 rate, u32 intvl, gfp_t gfp)
14507{
14508 struct sk_buff *msg;
14509
14510 msg = cfg80211_prepare_cqm(dev, peer, gfp);
14511 if (!msg)
14512 return;
14513
14514 if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_PKTS, num_packets))
14515 goto nla_put_failure;
14516
14517 if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_RATE, rate))
14518 goto nla_put_failure;
14519
14520 if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_INTVL, intvl))
14521 goto nla_put_failure;
14522
14523 cfg80211_send_cqm(msg, gfp);
14524 return;
14525
14526 nla_put_failure:
14527 nlmsg_free(msg);
14528}
14529EXPORT_SYMBOL(cfg80211_cqm_txe_notify);
14530
14531void cfg80211_cqm_pktloss_notify(struct net_device *dev,
14532 const u8 *peer, u32 num_packets, gfp_t gfp)
14533{
14534 struct sk_buff *msg;
14535
14536 trace_cfg80211_cqm_pktloss_notify(dev, peer, num_packets);
14537
14538 msg = cfg80211_prepare_cqm(dev, peer, gfp);
14539 if (!msg)
14540 return;
14541
14542 if (nla_put_u32(msg, NL80211_ATTR_CQM_PKT_LOSS_EVENT, num_packets))
14543 goto nla_put_failure;
14544
14545 cfg80211_send_cqm(msg, gfp);
14546 return;
14547
14548 nla_put_failure:
14549 nlmsg_free(msg);
14550}
14551EXPORT_SYMBOL(cfg80211_cqm_pktloss_notify);
14552
Johannes Berg98f03342014-11-26 12:42:02 +010014553void cfg80211_cqm_beacon_loss_notify(struct net_device *dev, gfp_t gfp)
14554{
14555 struct sk_buff *msg;
14556
14557 msg = cfg80211_prepare_cqm(dev, NULL, gfp);
14558 if (!msg)
14559 return;
14560
14561 if (nla_put_flag(msg, NL80211_ATTR_CQM_BEACON_LOSS_EVENT))
14562 goto nla_put_failure;
14563
14564 cfg80211_send_cqm(msg, gfp);
14565 return;
14566
14567 nla_put_failure:
14568 nlmsg_free(msg);
14569}
14570EXPORT_SYMBOL(cfg80211_cqm_beacon_loss_notify);
14571
Johannes Berg947add32013-02-22 22:05:20 +010014572static void nl80211_gtk_rekey_notify(struct cfg80211_registered_device *rdev,
14573 struct net_device *netdev, const u8 *bssid,
14574 const u8 *replay_ctr, gfp_t gfp)
Johannes Berge5497d72011-07-05 16:35:40 +020014575{
14576 struct sk_buff *msg;
14577 struct nlattr *rekey_attr;
14578 void *hdr;
14579
Thomas Graf58050fc2012-06-28 03:57:45 +000014580 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Johannes Berge5497d72011-07-05 16:35:40 +020014581 if (!msg)
14582 return;
14583
14584 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_REKEY_OFFLOAD);
14585 if (!hdr) {
14586 nlmsg_free(msg);
14587 return;
14588 }
14589
David S. Miller9360ffd2012-03-29 04:41:26 -040014590 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
14591 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
14592 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid))
14593 goto nla_put_failure;
Johannes Berge5497d72011-07-05 16:35:40 +020014594
14595 rekey_attr = nla_nest_start(msg, NL80211_ATTR_REKEY_DATA);
14596 if (!rekey_attr)
14597 goto nla_put_failure;
14598
David S. Miller9360ffd2012-03-29 04:41:26 -040014599 if (nla_put(msg, NL80211_REKEY_DATA_REPLAY_CTR,
14600 NL80211_REPLAY_CTR_LEN, replay_ctr))
14601 goto nla_put_failure;
Johannes Berge5497d72011-07-05 16:35:40 +020014602
14603 nla_nest_end(msg, rekey_attr);
14604
Johannes Berg3b7b72e2011-10-22 19:05:51 +020014605 genlmsg_end(msg, hdr);
Johannes Berge5497d72011-07-05 16:35:40 +020014606
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);
Johannes Berge5497d72011-07-05 16:35:40 +020014609 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_gtk_rekey_notify(struct net_device *dev, const u8 *bssid,
14617 const u8 *replay_ctr, 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_gtk_rekey_notify(dev, bssid);
14624 nl80211_gtk_rekey_notify(rdev, dev, bssid, replay_ctr, gfp);
14625}
14626EXPORT_SYMBOL(cfg80211_gtk_rekey_notify);
14627
14628static void
14629nl80211_pmksa_candidate_notify(struct cfg80211_registered_device *rdev,
14630 struct net_device *netdev, int index,
14631 const u8 *bssid, bool preauth, gfp_t gfp)
Jouni Malinenc9df56b2011-09-16 18:56:23 +030014632{
14633 struct sk_buff *msg;
14634 struct nlattr *attr;
14635 void *hdr;
14636
Thomas Graf58050fc2012-06-28 03:57:45 +000014637 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinenc9df56b2011-09-16 18:56:23 +030014638 if (!msg)
14639 return;
14640
14641 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PMKSA_CANDIDATE);
14642 if (!hdr) {
14643 nlmsg_free(msg);
14644 return;
14645 }
14646
David S. Miller9360ffd2012-03-29 04:41:26 -040014647 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
14648 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex))
14649 goto nla_put_failure;
Jouni Malinenc9df56b2011-09-16 18:56:23 +030014650
14651 attr = nla_nest_start(msg, NL80211_ATTR_PMKSA_CANDIDATE);
14652 if (!attr)
14653 goto nla_put_failure;
14654
David S. Miller9360ffd2012-03-29 04:41:26 -040014655 if (nla_put_u32(msg, NL80211_PMKSA_CANDIDATE_INDEX, index) ||
14656 nla_put(msg, NL80211_PMKSA_CANDIDATE_BSSID, ETH_ALEN, bssid) ||
14657 (preauth &&
14658 nla_put_flag(msg, NL80211_PMKSA_CANDIDATE_PREAUTH)))
14659 goto nla_put_failure;
Jouni Malinenc9df56b2011-09-16 18:56:23 +030014660
14661 nla_nest_end(msg, attr);
14662
Johannes Berg3b7b72e2011-10-22 19:05:51 +020014663 genlmsg_end(msg, hdr);
Jouni Malinenc9df56b2011-09-16 18:56:23 +030014664
Johannes Berg68eb5502013-11-19 15:19:38 +010014665 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010014666 NL80211_MCGRP_MLME, gfp);
Jouni Malinenc9df56b2011-09-16 18:56:23 +030014667 return;
14668
14669 nla_put_failure:
14670 genlmsg_cancel(msg, hdr);
14671 nlmsg_free(msg);
14672}
14673
Johannes Berg947add32013-02-22 22:05:20 +010014674void cfg80211_pmksa_candidate_notify(struct net_device *dev, int index,
14675 const u8 *bssid, bool preauth, gfp_t gfp)
14676{
14677 struct wireless_dev *wdev = dev->ieee80211_ptr;
14678 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080014679 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg947add32013-02-22 22:05:20 +010014680
14681 trace_cfg80211_pmksa_candidate_notify(dev, index, bssid, preauth);
14682 nl80211_pmksa_candidate_notify(rdev, dev, index, bssid, preauth, gfp);
14683}
14684EXPORT_SYMBOL(cfg80211_pmksa_candidate_notify);
14685
14686static void nl80211_ch_switch_notify(struct cfg80211_registered_device *rdev,
14687 struct net_device *netdev,
14688 struct cfg80211_chan_def *chandef,
Luciano Coelhof8d75522014-11-07 14:31:35 +020014689 gfp_t gfp,
14690 enum nl80211_commands notif,
14691 u8 count)
Thomas Pedersen53145262012-04-06 13:35:47 -070014692{
14693 struct sk_buff *msg;
14694 void *hdr;
14695
Thomas Graf58050fc2012-06-28 03:57:45 +000014696 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Thomas Pedersen53145262012-04-06 13:35:47 -070014697 if (!msg)
14698 return;
14699
Luciano Coelhof8d75522014-11-07 14:31:35 +020014700 hdr = nl80211hdr_put(msg, 0, 0, 0, notif);
Thomas Pedersen53145262012-04-06 13:35:47 -070014701 if (!hdr) {
14702 nlmsg_free(msg);
14703 return;
14704 }
14705
Johannes Berg683b6d32012-11-08 21:25:48 +010014706 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex))
14707 goto nla_put_failure;
14708
14709 if (nl80211_send_chandef(msg, chandef))
John W. Linville7eab0f62012-04-12 14:25:14 -040014710 goto nla_put_failure;
Thomas Pedersen53145262012-04-06 13:35:47 -070014711
Luciano Coelhof8d75522014-11-07 14:31:35 +020014712 if ((notif == NL80211_CMD_CH_SWITCH_STARTED_NOTIFY) &&
14713 (nla_put_u32(msg, NL80211_ATTR_CH_SWITCH_COUNT, count)))
14714 goto nla_put_failure;
14715
Thomas Pedersen53145262012-04-06 13:35:47 -070014716 genlmsg_end(msg, hdr);
14717
Johannes Berg68eb5502013-11-19 15:19:38 +010014718 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010014719 NL80211_MCGRP_MLME, gfp);
Thomas Pedersen53145262012-04-06 13:35:47 -070014720 return;
14721
14722 nla_put_failure:
14723 genlmsg_cancel(msg, hdr);
14724 nlmsg_free(msg);
14725}
14726
Johannes Berg947add32013-02-22 22:05:20 +010014727void cfg80211_ch_switch_notify(struct net_device *dev,
14728 struct cfg80211_chan_def *chandef)
Thomas Pedersen84f10702012-07-12 16:17:33 -070014729{
Johannes Berg947add32013-02-22 22:05:20 +010014730 struct wireless_dev *wdev = dev->ieee80211_ptr;
14731 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080014732 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg947add32013-02-22 22:05:20 +010014733
Simon Wunderliche487eae2013-11-21 18:19:51 +010014734 ASSERT_WDEV_LOCK(wdev);
Johannes Berg947add32013-02-22 22:05:20 +010014735
Simon Wunderliche487eae2013-11-21 18:19:51 +010014736 trace_cfg80211_ch_switch_notify(dev, chandef);
Johannes Berg947add32013-02-22 22:05:20 +010014737
Michal Kazior9e0e2962014-01-29 14:22:27 +010014738 wdev->chandef = *chandef;
Janusz Dziedzic96f55f12014-01-24 14:29:21 +010014739 wdev->preset_chandef = *chandef;
Luciano Coelhof8d75522014-11-07 14:31:35 +020014740 nl80211_ch_switch_notify(rdev, dev, chandef, GFP_KERNEL,
14741 NL80211_CMD_CH_SWITCH_NOTIFY, 0);
Johannes Berg947add32013-02-22 22:05:20 +010014742}
14743EXPORT_SYMBOL(cfg80211_ch_switch_notify);
14744
Luciano Coelhof8d75522014-11-07 14:31:35 +020014745void cfg80211_ch_switch_started_notify(struct net_device *dev,
14746 struct cfg80211_chan_def *chandef,
14747 u8 count)
14748{
14749 struct wireless_dev *wdev = dev->ieee80211_ptr;
14750 struct wiphy *wiphy = wdev->wiphy;
14751 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
14752
14753 trace_cfg80211_ch_switch_started_notify(dev, chandef);
14754
14755 nl80211_ch_switch_notify(rdev, dev, chandef, GFP_KERNEL,
14756 NL80211_CMD_CH_SWITCH_STARTED_NOTIFY, count);
14757}
14758EXPORT_SYMBOL(cfg80211_ch_switch_started_notify);
14759
Thomas Pedersen84f10702012-07-12 16:17:33 -070014760void
Simon Wunderlich04f39042013-02-08 18:16:19 +010014761nl80211_radar_notify(struct cfg80211_registered_device *rdev,
Janusz Dziedzicd2859df2013-11-06 13:55:51 +010014762 const struct cfg80211_chan_def *chandef,
Simon Wunderlich04f39042013-02-08 18:16:19 +010014763 enum nl80211_radar_event event,
14764 struct net_device *netdev, gfp_t gfp)
14765{
14766 struct sk_buff *msg;
14767 void *hdr;
14768
14769 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
14770 if (!msg)
14771 return;
14772
14773 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_RADAR_DETECT);
14774 if (!hdr) {
14775 nlmsg_free(msg);
14776 return;
14777 }
14778
14779 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx))
14780 goto nla_put_failure;
14781
14782 /* NOP and radar events don't need a netdev parameter */
14783 if (netdev) {
14784 struct wireless_dev *wdev = netdev->ieee80211_ptr;
14785
14786 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020014787 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
14788 NL80211_ATTR_PAD))
Simon Wunderlich04f39042013-02-08 18:16:19 +010014789 goto nla_put_failure;
14790 }
14791
14792 if (nla_put_u32(msg, NL80211_ATTR_RADAR_EVENT, event))
14793 goto nla_put_failure;
14794
14795 if (nl80211_send_chandef(msg, chandef))
14796 goto nla_put_failure;
14797
Johannes Berg9c90a9f2013-06-04 12:46:03 +020014798 genlmsg_end(msg, hdr);
Simon Wunderlich04f39042013-02-08 18:16:19 +010014799
Johannes Berg68eb5502013-11-19 15:19:38 +010014800 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010014801 NL80211_MCGRP_MLME, gfp);
Simon Wunderlich04f39042013-02-08 18:16:19 +010014802 return;
14803
14804 nla_put_failure:
14805 genlmsg_cancel(msg, hdr);
14806 nlmsg_free(msg);
14807}
14808
Johannes Berg7f6cf312011-11-04 11:18:15 +010014809void cfg80211_probe_status(struct net_device *dev, const u8 *addr,
14810 u64 cookie, bool acked, gfp_t gfp)
14811{
14812 struct wireless_dev *wdev = dev->ieee80211_ptr;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080014813 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Johannes Berg7f6cf312011-11-04 11:18:15 +010014814 struct sk_buff *msg;
14815 void *hdr;
Johannes Berg7f6cf312011-11-04 11:18:15 +010014816
Beni Lev4ee3e062012-08-27 12:49:39 +030014817 trace_cfg80211_probe_status(dev, addr, cookie, acked);
14818
Thomas Graf58050fc2012-06-28 03:57:45 +000014819 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Beni Lev4ee3e062012-08-27 12:49:39 +030014820
Johannes Berg7f6cf312011-11-04 11:18:15 +010014821 if (!msg)
14822 return;
14823
14824 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PROBE_CLIENT);
14825 if (!hdr) {
14826 nlmsg_free(msg);
14827 return;
14828 }
14829
David S. Miller9360ffd2012-03-29 04:41:26 -040014830 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
14831 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
14832 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020014833 nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie,
14834 NL80211_ATTR_PAD) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040014835 (acked && nla_put_flag(msg, NL80211_ATTR_ACK)))
14836 goto nla_put_failure;
Johannes Berg7f6cf312011-11-04 11:18:15 +010014837
Johannes Berg9c90a9f2013-06-04 12:46:03 +020014838 genlmsg_end(msg, hdr);
Johannes Berg7f6cf312011-11-04 11:18:15 +010014839
Johannes Berg68eb5502013-11-19 15:19:38 +010014840 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010014841 NL80211_MCGRP_MLME, gfp);
Johannes Berg7f6cf312011-11-04 11:18:15 +010014842 return;
14843
14844 nla_put_failure:
14845 genlmsg_cancel(msg, hdr);
14846 nlmsg_free(msg);
14847}
14848EXPORT_SYMBOL(cfg80211_probe_status);
14849
Johannes Berg5e760232011-11-04 11:18:17 +010014850void cfg80211_report_obss_beacon(struct wiphy *wiphy,
14851 const u8 *frame, size_t len,
Ben Greear37c73b52012-10-26 14:49:25 -070014852 int freq, int sig_dbm)
Johannes Berg5e760232011-11-04 11:18:17 +010014853{
Zhao, Gangf26cbf42014-04-21 12:53:03 +080014854 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg5e760232011-11-04 11:18:17 +010014855 struct sk_buff *msg;
14856 void *hdr;
Ben Greear37c73b52012-10-26 14:49:25 -070014857 struct cfg80211_beacon_registration *reg;
Johannes Berg5e760232011-11-04 11:18:17 +010014858
Beni Lev4ee3e062012-08-27 12:49:39 +030014859 trace_cfg80211_report_obss_beacon(wiphy, frame, len, freq, sig_dbm);
14860
Ben Greear37c73b52012-10-26 14:49:25 -070014861 spin_lock_bh(&rdev->beacon_registrations_lock);
14862 list_for_each_entry(reg, &rdev->beacon_registrations, list) {
14863 msg = nlmsg_new(len + 100, GFP_ATOMIC);
14864 if (!msg) {
14865 spin_unlock_bh(&rdev->beacon_registrations_lock);
14866 return;
14867 }
Johannes Berg5e760232011-11-04 11:18:17 +010014868
Ben Greear37c73b52012-10-26 14:49:25 -070014869 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME);
14870 if (!hdr)
14871 goto nla_put_failure;
Johannes Berg5e760232011-11-04 11:18:17 +010014872
Ben Greear37c73b52012-10-26 14:49:25 -070014873 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
14874 (freq &&
14875 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq)) ||
14876 (sig_dbm &&
14877 nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) ||
14878 nla_put(msg, NL80211_ATTR_FRAME, len, frame))
14879 goto nla_put_failure;
14880
14881 genlmsg_end(msg, hdr);
14882
14883 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, reg->nlportid);
Johannes Berg5e760232011-11-04 11:18:17 +010014884 }
Ben Greear37c73b52012-10-26 14:49:25 -070014885 spin_unlock_bh(&rdev->beacon_registrations_lock);
Johannes Berg5e760232011-11-04 11:18:17 +010014886 return;
14887
14888 nla_put_failure:
Ben Greear37c73b52012-10-26 14:49:25 -070014889 spin_unlock_bh(&rdev->beacon_registrations_lock);
14890 if (hdr)
14891 genlmsg_cancel(msg, hdr);
Johannes Berg5e760232011-11-04 11:18:17 +010014892 nlmsg_free(msg);
14893}
14894EXPORT_SYMBOL(cfg80211_report_obss_beacon);
14895
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010014896#ifdef CONFIG_PM
Luciano Coelho8cd4d452014-09-17 11:55:28 +030014897static int cfg80211_net_detect_results(struct sk_buff *msg,
14898 struct cfg80211_wowlan_wakeup *wakeup)
14899{
14900 struct cfg80211_wowlan_nd_info *nd = wakeup->net_detect;
14901 struct nlattr *nl_results, *nl_match, *nl_freqs;
14902 int i, j;
14903
14904 nl_results = nla_nest_start(
14905 msg, NL80211_WOWLAN_TRIG_NET_DETECT_RESULTS);
14906 if (!nl_results)
14907 return -EMSGSIZE;
14908
14909 for (i = 0; i < nd->n_matches; i++) {
14910 struct cfg80211_wowlan_nd_match *match = nd->matches[i];
14911
14912 nl_match = nla_nest_start(msg, i);
14913 if (!nl_match)
14914 break;
14915
14916 /* The SSID attribute is optional in nl80211, but for
14917 * simplicity reasons it's always present in the
14918 * cfg80211 structure. If a driver can't pass the
14919 * SSID, that needs to be changed. A zero length SSID
14920 * is still a valid SSID (wildcard), so it cannot be
14921 * used for this purpose.
14922 */
14923 if (nla_put(msg, NL80211_ATTR_SSID, match->ssid.ssid_len,
14924 match->ssid.ssid)) {
14925 nla_nest_cancel(msg, nl_match);
14926 goto out;
14927 }
14928
14929 if (match->n_channels) {
14930 nl_freqs = nla_nest_start(
14931 msg, NL80211_ATTR_SCAN_FREQUENCIES);
14932 if (!nl_freqs) {
14933 nla_nest_cancel(msg, nl_match);
14934 goto out;
14935 }
14936
14937 for (j = 0; j < match->n_channels; j++) {
Samuel Tan5528fae82015-02-09 21:29:15 +020014938 if (nla_put_u32(msg, j, match->channels[j])) {
Luciano Coelho8cd4d452014-09-17 11:55:28 +030014939 nla_nest_cancel(msg, nl_freqs);
14940 nla_nest_cancel(msg, nl_match);
14941 goto out;
14942 }
14943 }
14944
14945 nla_nest_end(msg, nl_freqs);
14946 }
14947
14948 nla_nest_end(msg, nl_match);
14949 }
14950
14951out:
14952 nla_nest_end(msg, nl_results);
14953 return 0;
14954}
14955
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010014956void cfg80211_report_wowlan_wakeup(struct wireless_dev *wdev,
14957 struct cfg80211_wowlan_wakeup *wakeup,
14958 gfp_t gfp)
14959{
Zhao, Gangf26cbf42014-04-21 12:53:03 +080014960 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010014961 struct sk_buff *msg;
14962 void *hdr;
Johannes Berg9c90a9f2013-06-04 12:46:03 +020014963 int size = 200;
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010014964
14965 trace_cfg80211_report_wowlan_wakeup(wdev->wiphy, wdev, wakeup);
14966
14967 if (wakeup)
14968 size += wakeup->packet_present_len;
14969
14970 msg = nlmsg_new(size, gfp);
14971 if (!msg)
14972 return;
14973
14974 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_WOWLAN);
14975 if (!hdr)
14976 goto free_msg;
14977
14978 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020014979 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
14980 NL80211_ATTR_PAD))
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010014981 goto free_msg;
14982
14983 if (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
14984 wdev->netdev->ifindex))
14985 goto free_msg;
14986
14987 if (wakeup) {
14988 struct nlattr *reasons;
14989
14990 reasons = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS);
Johannes Berg7fa322c2013-10-25 11:16:58 +020014991 if (!reasons)
14992 goto free_msg;
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010014993
14994 if (wakeup->disconnect &&
14995 nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT))
14996 goto free_msg;
14997 if (wakeup->magic_pkt &&
14998 nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT))
14999 goto free_msg;
15000 if (wakeup->gtk_rekey_failure &&
15001 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE))
15002 goto free_msg;
15003 if (wakeup->eap_identity_req &&
15004 nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST))
15005 goto free_msg;
15006 if (wakeup->four_way_handshake &&
15007 nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE))
15008 goto free_msg;
15009 if (wakeup->rfkill_release &&
15010 nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE))
15011 goto free_msg;
15012
15013 if (wakeup->pattern_idx >= 0 &&
15014 nla_put_u32(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN,
15015 wakeup->pattern_idx))
15016 goto free_msg;
15017
Johannes Bergae917c92013-10-25 11:05:22 +020015018 if (wakeup->tcp_match &&
15019 nla_put_flag(msg, NL80211_WOWLAN_TRIG_WAKEUP_TCP_MATCH))
15020 goto free_msg;
Johannes Berg2a0e0472013-01-23 22:57:40 +010015021
Johannes Bergae917c92013-10-25 11:05:22 +020015022 if (wakeup->tcp_connlost &&
15023 nla_put_flag(msg, NL80211_WOWLAN_TRIG_WAKEUP_TCP_CONNLOST))
15024 goto free_msg;
Johannes Berg2a0e0472013-01-23 22:57:40 +010015025
Johannes Bergae917c92013-10-25 11:05:22 +020015026 if (wakeup->tcp_nomoretokens &&
15027 nla_put_flag(msg,
15028 NL80211_WOWLAN_TRIG_WAKEUP_TCP_NOMORETOKENS))
15029 goto free_msg;
Johannes Berg2a0e0472013-01-23 22:57:40 +010015030
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010015031 if (wakeup->packet) {
15032 u32 pkt_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211;
15033 u32 len_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211_LEN;
15034
15035 if (!wakeup->packet_80211) {
15036 pkt_attr =
15037 NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023;
15038 len_attr =
15039 NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023_LEN;
15040 }
15041
15042 if (wakeup->packet_len &&
15043 nla_put_u32(msg, len_attr, wakeup->packet_len))
15044 goto free_msg;
15045
15046 if (nla_put(msg, pkt_attr, wakeup->packet_present_len,
15047 wakeup->packet))
15048 goto free_msg;
15049 }
15050
Luciano Coelho8cd4d452014-09-17 11:55:28 +030015051 if (wakeup->net_detect &&
15052 cfg80211_net_detect_results(msg, wakeup))
15053 goto free_msg;
15054
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010015055 nla_nest_end(msg, reasons);
15056 }
15057
Johannes Berg9c90a9f2013-06-04 12:46:03 +020015058 genlmsg_end(msg, hdr);
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010015059
Johannes Berg68eb5502013-11-19 15:19:38 +010015060 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010015061 NL80211_MCGRP_MLME, gfp);
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010015062 return;
15063
15064 free_msg:
15065 nlmsg_free(msg);
15066}
15067EXPORT_SYMBOL(cfg80211_report_wowlan_wakeup);
15068#endif
15069
Jouni Malinen3475b092012-11-16 22:49:57 +020015070void cfg80211_tdls_oper_request(struct net_device *dev, const u8 *peer,
15071 enum nl80211_tdls_operation oper,
15072 u16 reason_code, gfp_t gfp)
15073{
15074 struct wireless_dev *wdev = dev->ieee80211_ptr;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080015075 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Jouni Malinen3475b092012-11-16 22:49:57 +020015076 struct sk_buff *msg;
15077 void *hdr;
Jouni Malinen3475b092012-11-16 22:49:57 +020015078
15079 trace_cfg80211_tdls_oper_request(wdev->wiphy, dev, peer, oper,
15080 reason_code);
15081
15082 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
15083 if (!msg)
15084 return;
15085
15086 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_TDLS_OPER);
15087 if (!hdr) {
15088 nlmsg_free(msg);
15089 return;
15090 }
15091
15092 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
15093 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
15094 nla_put_u8(msg, NL80211_ATTR_TDLS_OPERATION, oper) ||
15095 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer) ||
15096 (reason_code > 0 &&
15097 nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason_code)))
15098 goto nla_put_failure;
15099
Johannes Berg9c90a9f2013-06-04 12:46:03 +020015100 genlmsg_end(msg, hdr);
Jouni Malinen3475b092012-11-16 22:49:57 +020015101
Johannes Berg68eb5502013-11-19 15:19:38 +010015102 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010015103 NL80211_MCGRP_MLME, gfp);
Jouni Malinen3475b092012-11-16 22:49:57 +020015104 return;
15105
15106 nla_put_failure:
15107 genlmsg_cancel(msg, hdr);
15108 nlmsg_free(msg);
15109}
15110EXPORT_SYMBOL(cfg80211_tdls_oper_request);
15111
Jouni Malinen026331c2010-02-15 12:53:10 +020015112static int nl80211_netlink_notify(struct notifier_block * nb,
15113 unsigned long state,
15114 void *_notify)
15115{
15116 struct netlink_notify *notify = _notify;
15117 struct cfg80211_registered_device *rdev;
15118 struct wireless_dev *wdev;
Ben Greear37c73b52012-10-26 14:49:25 -070015119 struct cfg80211_beacon_registration *reg, *tmp;
Jouni Malinen026331c2010-02-15 12:53:10 +020015120
Dmitry Ivanov8f815cd2016-04-06 17:23:18 +030015121 if (state != NETLINK_URELEASE || notify->protocol != NETLINK_GENERIC)
Jouni Malinen026331c2010-02-15 12:53:10 +020015122 return NOTIFY_DONE;
15123
15124 rcu_read_lock();
15125
Johannes Berg5e760232011-11-04 11:18:17 +010015126 list_for_each_entry_rcu(rdev, &cfg80211_rdev_list, list) {
Arend Van Sprielca986ad2017-04-21 13:05:00 +010015127 struct cfg80211_sched_scan_request *sched_scan_req;
Jukka Rissanen93a1e862014-12-15 13:25:39 +020015128
Arend Van Sprielca986ad2017-04-21 13:05:00 +010015129 list_for_each_entry_rcu(sched_scan_req,
15130 &rdev->sched_scan_req_list,
15131 list) {
15132 if (sched_scan_req->owner_nlportid == notify->portid) {
15133 sched_scan_req->nl_owner_dead = true;
Johannes Berg753aacf2017-01-05 10:57:14 +010015134 schedule_work(&rdev->sched_scan_stop_wk);
Arend Van Sprielca986ad2017-04-21 13:05:00 +010015135 }
Johannes Berg753aacf2017-01-05 10:57:14 +010015136 }
Johannes Berg78f22b62014-03-24 17:57:27 +010015137
Johannes Berg53873f12016-05-03 16:52:04 +030015138 list_for_each_entry_rcu(wdev, &rdev->wiphy.wdev_list, list) {
Eric W. Biederman15e47302012-09-07 20:12:54 +000015139 cfg80211_mlme_unregister_socket(wdev, notify->portid);
Ben Greear37c73b52012-10-26 14:49:25 -070015140
Johannes Bergab810072017-04-26 07:43:41 +020015141 if (wdev->owner_nlportid == notify->portid) {
15142 wdev->nl_owner_dead = true;
15143 schedule_work(&rdev->destroy_work);
15144 } else if (wdev->conn_owner_nlportid == notify->portid) {
Andrzej Zaborowskibd2522b2017-01-06 16:33:43 -050015145 schedule_work(&wdev->disconnect_wk);
Johannes Bergab810072017-04-26 07:43:41 +020015146 }
Johannes Berg78f22b62014-03-24 17:57:27 +010015147 }
15148
Ben Greear37c73b52012-10-26 14:49:25 -070015149 spin_lock_bh(&rdev->beacon_registrations_lock);
15150 list_for_each_entry_safe(reg, tmp, &rdev->beacon_registrations,
15151 list) {
15152 if (reg->nlportid == notify->portid) {
15153 list_del(&reg->list);
15154 kfree(reg);
15155 break;
15156 }
15157 }
15158 spin_unlock_bh(&rdev->beacon_registrations_lock);
Johannes Berg5e760232011-11-04 11:18:17 +010015159 }
Jouni Malinen026331c2010-02-15 12:53:10 +020015160
15161 rcu_read_unlock();
15162
Ilan peer05050752015-03-04 00:32:06 -050015163 /*
15164 * It is possible that the user space process that is controlling the
15165 * indoor setting disappeared, so notify the regulatory core.
15166 */
15167 regulatory_netlink_notify(notify->portid);
Zhao, Gang6784c7d2014-04-21 12:53:04 +080015168 return NOTIFY_OK;
Jouni Malinen026331c2010-02-15 12:53:10 +020015169}
15170
15171static struct notifier_block nl80211_netlink_notifier = {
15172 .notifier_call = nl80211_netlink_notify,
15173};
15174
Jouni Malinen355199e2013-02-27 17:14:27 +020015175void cfg80211_ft_event(struct net_device *netdev,
15176 struct cfg80211_ft_event_params *ft_event)
15177{
15178 struct wiphy *wiphy = netdev->ieee80211_ptr->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080015179 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Jouni Malinen355199e2013-02-27 17:14:27 +020015180 struct sk_buff *msg;
15181 void *hdr;
Jouni Malinen355199e2013-02-27 17:14:27 +020015182
15183 trace_cfg80211_ft_event(wiphy, netdev, ft_event);
15184
15185 if (!ft_event->target_ap)
15186 return;
15187
Johannes Berg4ef8c1c2017-01-09 11:10:42 +010015188 msg = nlmsg_new(100 + ft_event->ric_ies_len, GFP_KERNEL);
Jouni Malinen355199e2013-02-27 17:14:27 +020015189 if (!msg)
15190 return;
15191
15192 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FT_EVENT);
Johannes Bergae917c92013-10-25 11:05:22 +020015193 if (!hdr)
15194 goto out;
Jouni Malinen355199e2013-02-27 17:14:27 +020015195
Johannes Bergae917c92013-10-25 11:05:22 +020015196 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
15197 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
15198 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, ft_event->target_ap))
15199 goto out;
15200
15201 if (ft_event->ies &&
15202 nla_put(msg, NL80211_ATTR_IE, ft_event->ies_len, ft_event->ies))
15203 goto out;
15204 if (ft_event->ric_ies &&
15205 nla_put(msg, NL80211_ATTR_IE_RIC, ft_event->ric_ies_len,
15206 ft_event->ric_ies))
15207 goto out;
Jouni Malinen355199e2013-02-27 17:14:27 +020015208
Johannes Berg9c90a9f2013-06-04 12:46:03 +020015209 genlmsg_end(msg, hdr);
Jouni Malinen355199e2013-02-27 17:14:27 +020015210
Johannes Berg68eb5502013-11-19 15:19:38 +010015211 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010015212 NL80211_MCGRP_MLME, GFP_KERNEL);
Johannes Bergae917c92013-10-25 11:05:22 +020015213 return;
15214 out:
15215 nlmsg_free(msg);
Jouni Malinen355199e2013-02-27 17:14:27 +020015216}
15217EXPORT_SYMBOL(cfg80211_ft_event);
15218
Arend van Spriel5de17982013-04-18 15:49:00 +020015219void cfg80211_crit_proto_stopped(struct wireless_dev *wdev, gfp_t gfp)
15220{
15221 struct cfg80211_registered_device *rdev;
15222 struct sk_buff *msg;
15223 void *hdr;
15224 u32 nlportid;
15225
Zhao, Gangf26cbf42014-04-21 12:53:03 +080015226 rdev = wiphy_to_rdev(wdev->wiphy);
Arend van Spriel5de17982013-04-18 15:49:00 +020015227 if (!rdev->crit_proto_nlportid)
15228 return;
15229
15230 nlportid = rdev->crit_proto_nlportid;
15231 rdev->crit_proto_nlportid = 0;
15232
15233 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
15234 if (!msg)
15235 return;
15236
15237 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CRIT_PROTOCOL_STOP);
15238 if (!hdr)
15239 goto nla_put_failure;
15240
15241 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020015242 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
15243 NL80211_ATTR_PAD))
Arend van Spriel5de17982013-04-18 15:49:00 +020015244 goto nla_put_failure;
15245
15246 genlmsg_end(msg, hdr);
15247
15248 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid);
15249 return;
15250
15251 nla_put_failure:
15252 if (hdr)
15253 genlmsg_cancel(msg, hdr);
15254 nlmsg_free(msg);
Arend van Spriel5de17982013-04-18 15:49:00 +020015255}
15256EXPORT_SYMBOL(cfg80211_crit_proto_stopped);
15257
Johannes Berg348baf02014-01-24 14:06:29 +010015258void nl80211_send_ap_stopped(struct wireless_dev *wdev)
15259{
15260 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080015261 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg348baf02014-01-24 14:06:29 +010015262 struct sk_buff *msg;
15263 void *hdr;
15264
15265 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
15266 if (!msg)
15267 return;
15268
15269 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_STOP_AP);
15270 if (!hdr)
15271 goto out;
15272
15273 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
15274 nla_put_u32(msg, NL80211_ATTR_IFINDEX, wdev->netdev->ifindex) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020015275 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
15276 NL80211_ATTR_PAD))
Johannes Berg348baf02014-01-24 14:06:29 +010015277 goto out;
15278
15279 genlmsg_end(msg, hdr);
15280
15281 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(wiphy), msg, 0,
15282 NL80211_MCGRP_MLME, GFP_KERNEL);
15283 return;
15284 out:
15285 nlmsg_free(msg);
15286}
15287
Johannes Berg55682962007-09-20 13:09:35 -040015288/* initialisation/exit functions */
15289
Johannes Berg56989f62016-10-24 14:40:05 +020015290int __init nl80211_init(void)
Johannes Berg55682962007-09-20 13:09:35 -040015291{
Michał Mirosław0d63cbb2009-05-21 10:34:06 +000015292 int err;
Johannes Berg55682962007-09-20 13:09:35 -040015293
Johannes Berg489111e2016-10-24 14:40:03 +020015294 err = genl_register_family(&nl80211_fam);
Johannes Berg55682962007-09-20 13:09:35 -040015295 if (err)
15296 return err;
15297
Jouni Malinen026331c2010-02-15 12:53:10 +020015298 err = netlink_register_notifier(&nl80211_netlink_notifier);
15299 if (err)
15300 goto err_out;
15301
Johannes Berg55682962007-09-20 13:09:35 -040015302 return 0;
15303 err_out:
15304 genl_unregister_family(&nl80211_fam);
15305 return err;
15306}
15307
15308void nl80211_exit(void)
15309{
Jouni Malinen026331c2010-02-15 12:53:10 +020015310 netlink_unregister_notifier(&nl80211_netlink_notifier);
Johannes Berg55682962007-09-20 13:09:35 -040015311 genl_unregister_family(&nl80211_fam);
15312}