blob: bd5959fd29c530671063db64d2a23e5c44591686 [file] [log] [blame]
Johannes Berg55682962007-09-20 13:09:35 -04001/*
2 * This is the new netlink-based wireless configuration interface.
3 *
Jouni Malinen026331c2010-02-15 12:53:10 +02004 * Copyright 2006-2010 Johannes Berg <johannes@sipsolutions.net>
Johannes Berg2740f0c2014-09-03 15:24:58 +03005 * Copyright 2013-2014 Intel Mobile Communications GmbH
Johannes Berg66cd7942017-02-07 22:40:44 +02006 * Copyright 2015-2017 Intel Deutschland GmbH
Johannes Berg55682962007-09-20 13:09:35 -04007 */
8
9#include <linux/if.h>
10#include <linux/module.h>
11#include <linux/err.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090012#include <linux/slab.h>
Johannes Berg55682962007-09-20 13:09:35 -040013#include <linux/list.h>
14#include <linux/if_ether.h>
15#include <linux/ieee80211.h>
16#include <linux/nl80211.h>
17#include <linux/rtnetlink.h>
18#include <linux/netlink.h>
Johannes Berg2a519312009-02-10 21:25:55 +010019#include <linux/etherdevice.h>
Johannes Berg463d0182009-07-14 00:33:35 +020020#include <net/net_namespace.h>
Johannes Berg55682962007-09-20 13:09:35 -040021#include <net/genetlink.h>
22#include <net/cfg80211.h>
Johannes Berg463d0182009-07-14 00:33:35 +020023#include <net/sock.h>
Johannes Berg2a0e0472013-01-23 22:57:40 +010024#include <net/inet_connection_sock.h>
Johannes Berg55682962007-09-20 13:09:35 -040025#include "core.h"
26#include "nl80211.h"
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -070027#include "reg.h"
Hila Gonene35e4d22012-06-27 17:19:42 +030028#include "rdev-ops.h"
Johannes Berg55682962007-09-20 13:09:35 -040029
Jouni Malinen5fb628e2011-08-10 23:54:35 +030030static int nl80211_crypto_settings(struct cfg80211_registered_device *rdev,
31 struct genl_info *info,
32 struct cfg80211_crypto_settings *settings,
33 int cipher_limit);
34
Johannes Berg55682962007-09-20 13:09:35 -040035/* the netlink family */
Johannes Berg489111e2016-10-24 14:40:03 +020036static struct genl_family nl80211_fam;
Johannes Berg55682962007-09-20 13:09:35 -040037
Johannes Berg2a94fe42013-11-19 15:19:39 +010038/* multicast groups */
39enum nl80211_multicast_groups {
40 NL80211_MCGRP_CONFIG,
41 NL80211_MCGRP_SCAN,
42 NL80211_MCGRP_REGULATORY,
43 NL80211_MCGRP_MLME,
Johannes Berg567ffc32013-12-18 14:43:31 +010044 NL80211_MCGRP_VENDOR,
Ayala Beker50bcd312016-09-20 17:31:17 +030045 NL80211_MCGRP_NAN,
Johannes Berg2a94fe42013-11-19 15:19:39 +010046 NL80211_MCGRP_TESTMODE /* keep last - ifdef! */
47};
48
49static const struct genl_multicast_group nl80211_mcgrps[] = {
Johannes Berg71b836e2014-12-23 17:17:38 +010050 [NL80211_MCGRP_CONFIG] = { .name = NL80211_MULTICAST_GROUP_CONFIG },
51 [NL80211_MCGRP_SCAN] = { .name = NL80211_MULTICAST_GROUP_SCAN },
52 [NL80211_MCGRP_REGULATORY] = { .name = NL80211_MULTICAST_GROUP_REG },
53 [NL80211_MCGRP_MLME] = { .name = NL80211_MULTICAST_GROUP_MLME },
54 [NL80211_MCGRP_VENDOR] = { .name = NL80211_MULTICAST_GROUP_VENDOR },
Ayala Beker50bcd312016-09-20 17:31:17 +030055 [NL80211_MCGRP_NAN] = { .name = NL80211_MULTICAST_GROUP_NAN },
Johannes Berg2a94fe42013-11-19 15:19:39 +010056#ifdef CONFIG_NL80211_TESTMODE
Johannes Berg71b836e2014-12-23 17:17:38 +010057 [NL80211_MCGRP_TESTMODE] = { .name = NL80211_MULTICAST_GROUP_TESTMODE }
Johannes Berg2a94fe42013-11-19 15:19:39 +010058#endif
59};
60
Johannes Berg89a54e42012-06-15 14:33:17 +020061/* returns ERR_PTR values */
62static struct wireless_dev *
63__cfg80211_wdev_from_attrs(struct net *netns, struct nlattr **attrs)
Johannes Berg55682962007-09-20 13:09:35 -040064{
Johannes Berg89a54e42012-06-15 14:33:17 +020065 struct cfg80211_registered_device *rdev;
66 struct wireless_dev *result = NULL;
67 bool have_ifidx = attrs[NL80211_ATTR_IFINDEX];
68 bool have_wdev_id = attrs[NL80211_ATTR_WDEV];
69 u64 wdev_id;
70 int wiphy_idx = -1;
71 int ifidx = -1;
Johannes Berg55682962007-09-20 13:09:35 -040072
Johannes Berg5fe231e2013-05-08 21:45:15 +020073 ASSERT_RTNL();
Johannes Berg55682962007-09-20 13:09:35 -040074
Johannes Berg89a54e42012-06-15 14:33:17 +020075 if (!have_ifidx && !have_wdev_id)
76 return ERR_PTR(-EINVAL);
Johannes Berg55682962007-09-20 13:09:35 -040077
Johannes Berg89a54e42012-06-15 14:33:17 +020078 if (have_ifidx)
79 ifidx = nla_get_u32(attrs[NL80211_ATTR_IFINDEX]);
80 if (have_wdev_id) {
81 wdev_id = nla_get_u64(attrs[NL80211_ATTR_WDEV]);
82 wiphy_idx = wdev_id >> 32;
Johannes Berg55682962007-09-20 13:09:35 -040083 }
84
Johannes Berg89a54e42012-06-15 14:33:17 +020085 list_for_each_entry(rdev, &cfg80211_rdev_list, list) {
86 struct wireless_dev *wdev;
87
88 if (wiphy_net(&rdev->wiphy) != netns)
89 continue;
90
91 if (have_wdev_id && rdev->wiphy_idx != wiphy_idx)
92 continue;
93
Johannes Berg53873f12016-05-03 16:52:04 +030094 list_for_each_entry(wdev, &rdev->wiphy.wdev_list, list) {
Johannes Berg89a54e42012-06-15 14:33:17 +020095 if (have_ifidx && wdev->netdev &&
96 wdev->netdev->ifindex == ifidx) {
97 result = wdev;
98 break;
99 }
100 if (have_wdev_id && wdev->identifier == (u32)wdev_id) {
101 result = wdev;
102 break;
103 }
104 }
Johannes Berg89a54e42012-06-15 14:33:17 +0200105
106 if (result)
107 break;
108 }
109
110 if (result)
111 return result;
112 return ERR_PTR(-ENODEV);
Johannes Berg55682962007-09-20 13:09:35 -0400113}
114
Johannes Berga9455402012-06-15 13:32:49 +0200115static struct cfg80211_registered_device *
Johannes Berg878d9ec2012-06-15 14:18:32 +0200116__cfg80211_rdev_from_attrs(struct net *netns, struct nlattr **attrs)
Johannes Berga9455402012-06-15 13:32:49 +0200117{
Johannes Berg7fee4772012-06-15 14:09:58 +0200118 struct cfg80211_registered_device *rdev = NULL, *tmp;
119 struct net_device *netdev;
Johannes Berga9455402012-06-15 13:32:49 +0200120
Johannes Berg5fe231e2013-05-08 21:45:15 +0200121 ASSERT_RTNL();
Johannes Berga9455402012-06-15 13:32:49 +0200122
Johannes Berg878d9ec2012-06-15 14:18:32 +0200123 if (!attrs[NL80211_ATTR_WIPHY] &&
Johannes Berg89a54e42012-06-15 14:33:17 +0200124 !attrs[NL80211_ATTR_IFINDEX] &&
125 !attrs[NL80211_ATTR_WDEV])
Johannes Berg7fee4772012-06-15 14:09:58 +0200126 return ERR_PTR(-EINVAL);
127
Johannes Berg878d9ec2012-06-15 14:18:32 +0200128 if (attrs[NL80211_ATTR_WIPHY])
Johannes Berg7fee4772012-06-15 14:09:58 +0200129 rdev = cfg80211_rdev_by_wiphy_idx(
Johannes Berg878d9ec2012-06-15 14:18:32 +0200130 nla_get_u32(attrs[NL80211_ATTR_WIPHY]));
Johannes Berga9455402012-06-15 13:32:49 +0200131
Johannes Berg89a54e42012-06-15 14:33:17 +0200132 if (attrs[NL80211_ATTR_WDEV]) {
133 u64 wdev_id = nla_get_u64(attrs[NL80211_ATTR_WDEV]);
134 struct wireless_dev *wdev;
135 bool found = false;
136
137 tmp = cfg80211_rdev_by_wiphy_idx(wdev_id >> 32);
138 if (tmp) {
139 /* make sure wdev exists */
Johannes Berg53873f12016-05-03 16:52:04 +0300140 list_for_each_entry(wdev, &tmp->wiphy.wdev_list, list) {
Johannes Berg89a54e42012-06-15 14:33:17 +0200141 if (wdev->identifier != (u32)wdev_id)
142 continue;
143 found = true;
144 break;
145 }
Johannes Berg89a54e42012-06-15 14:33:17 +0200146
147 if (!found)
148 tmp = NULL;
149
150 if (rdev && tmp != rdev)
151 return ERR_PTR(-EINVAL);
152 rdev = tmp;
153 }
154 }
155
Johannes Berg878d9ec2012-06-15 14:18:32 +0200156 if (attrs[NL80211_ATTR_IFINDEX]) {
157 int ifindex = nla_get_u32(attrs[NL80211_ATTR_IFINDEX]);
Kirtika Ruchandani7a087e72016-05-29 19:51:23 -0700158
Ying Xue7f2b8562014-01-15 10:23:45 +0800159 netdev = __dev_get_by_index(netns, ifindex);
Johannes Berg7fee4772012-06-15 14:09:58 +0200160 if (netdev) {
161 if (netdev->ieee80211_ptr)
Zhao, Gangf26cbf42014-04-21 12:53:03 +0800162 tmp = wiphy_to_rdev(
163 netdev->ieee80211_ptr->wiphy);
Johannes Berg7fee4772012-06-15 14:09:58 +0200164 else
165 tmp = NULL;
166
Johannes Berg7fee4772012-06-15 14:09:58 +0200167 /* not wireless device -- return error */
168 if (!tmp)
169 return ERR_PTR(-EINVAL);
170
171 /* mismatch -- return error */
172 if (rdev && tmp != rdev)
173 return ERR_PTR(-EINVAL);
174
175 rdev = tmp;
Johannes Berga9455402012-06-15 13:32:49 +0200176 }
Johannes Berga9455402012-06-15 13:32:49 +0200177 }
178
Johannes Berg4f7eff12012-06-15 14:14:22 +0200179 if (!rdev)
180 return ERR_PTR(-ENODEV);
Johannes Berga9455402012-06-15 13:32:49 +0200181
Johannes Berg4f7eff12012-06-15 14:14:22 +0200182 if (netns != wiphy_net(&rdev->wiphy))
183 return ERR_PTR(-ENODEV);
184
185 return rdev;
Johannes Berga9455402012-06-15 13:32:49 +0200186}
187
188/*
189 * This function returns a pointer to the driver
190 * that the genl_info item that is passed refers to.
Johannes Berga9455402012-06-15 13:32:49 +0200191 *
192 * The result of this can be a PTR_ERR and hence must
193 * be checked with IS_ERR() for errors.
194 */
195static struct cfg80211_registered_device *
Johannes Berg4f7eff12012-06-15 14:14:22 +0200196cfg80211_get_dev_from_info(struct net *netns, struct genl_info *info)
Johannes Berga9455402012-06-15 13:32:49 +0200197{
Johannes Berg5fe231e2013-05-08 21:45:15 +0200198 return __cfg80211_rdev_from_attrs(netns, info->attrs);
Johannes Berga9455402012-06-15 13:32:49 +0200199}
200
Johannes Berg55682962007-09-20 13:09:35 -0400201/* policy for the attributes */
Luciano Coelho8cd4d452014-09-17 11:55:28 +0300202static const struct nla_policy nl80211_policy[NUM_NL80211_ATTR] = {
Johannes Berg55682962007-09-20 13:09:35 -0400203 [NL80211_ATTR_WIPHY] = { .type = NLA_U32 },
204 [NL80211_ATTR_WIPHY_NAME] = { .type = NLA_NUL_STRING,
David S. Miller079e24e2009-05-26 21:15:00 -0700205 .len = 20-1 },
Jouni Malinen31888482008-10-30 16:59:24 +0200206 [NL80211_ATTR_WIPHY_TXQ_PARAMS] = { .type = NLA_NESTED },
Johannes Berg3d9d1d62012-11-08 23:14:50 +0100207
Jouni Malinen72bdcf32008-11-26 16:15:24 +0200208 [NL80211_ATTR_WIPHY_FREQ] = { .type = NLA_U32 },
Sujith094d05d2008-12-12 11:57:43 +0530209 [NL80211_ATTR_WIPHY_CHANNEL_TYPE] = { .type = NLA_U32 },
Johannes Berg3d9d1d62012-11-08 23:14:50 +0100210 [NL80211_ATTR_CHANNEL_WIDTH] = { .type = NLA_U32 },
211 [NL80211_ATTR_CENTER_FREQ1] = { .type = NLA_U32 },
212 [NL80211_ATTR_CENTER_FREQ2] = { .type = NLA_U32 },
213
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +0200214 [NL80211_ATTR_WIPHY_RETRY_SHORT] = { .type = NLA_U8 },
215 [NL80211_ATTR_WIPHY_RETRY_LONG] = { .type = NLA_U8 },
216 [NL80211_ATTR_WIPHY_FRAG_THRESHOLD] = { .type = NLA_U32 },
217 [NL80211_ATTR_WIPHY_RTS_THRESHOLD] = { .type = NLA_U32 },
Lukáš Turek81077e82009-12-21 22:50:47 +0100218 [NL80211_ATTR_WIPHY_COVERAGE_CLASS] = { .type = NLA_U8 },
Lorenzo Bianconi3057dbf2014-09-04 23:57:40 +0200219 [NL80211_ATTR_WIPHY_DYN_ACK] = { .type = NLA_FLAG },
Johannes Berg55682962007-09-20 13:09:35 -0400220
221 [NL80211_ATTR_IFTYPE] = { .type = NLA_U32 },
222 [NL80211_ATTR_IFINDEX] = { .type = NLA_U32 },
223 [NL80211_ATTR_IFNAME] = { .type = NLA_NUL_STRING, .len = IFNAMSIZ-1 },
Johannes Berg41ade002007-12-19 02:03:29 +0100224
Eliad Pellere007b852011-11-24 18:13:56 +0200225 [NL80211_ATTR_MAC] = { .len = ETH_ALEN },
226 [NL80211_ATTR_PREV_BSSID] = { .len = ETH_ALEN },
Johannes Berg41ade002007-12-19 02:03:29 +0100227
Johannes Bergb9454e82009-07-08 13:29:08 +0200228 [NL80211_ATTR_KEY] = { .type = NLA_NESTED, },
Johannes Berg41ade002007-12-19 02:03:29 +0100229 [NL80211_ATTR_KEY_DATA] = { .type = NLA_BINARY,
230 .len = WLAN_MAX_KEY_LEN },
231 [NL80211_ATTR_KEY_IDX] = { .type = NLA_U8 },
232 [NL80211_ATTR_KEY_CIPHER] = { .type = NLA_U32 },
233 [NL80211_ATTR_KEY_DEFAULT] = { .type = NLA_FLAG },
Jouni Malinen81962262011-11-02 23:36:31 +0200234 [NL80211_ATTR_KEY_SEQ] = { .type = NLA_BINARY, .len = 16 },
Johannes Berge31b8212010-10-05 19:39:30 +0200235 [NL80211_ATTR_KEY_TYPE] = { .type = NLA_U32 },
Johannes Berged1b6cc2007-12-19 02:03:32 +0100236
237 [NL80211_ATTR_BEACON_INTERVAL] = { .type = NLA_U32 },
238 [NL80211_ATTR_DTIM_PERIOD] = { .type = NLA_U32 },
239 [NL80211_ATTR_BEACON_HEAD] = { .type = NLA_BINARY,
240 .len = IEEE80211_MAX_DATA_LEN },
241 [NL80211_ATTR_BEACON_TAIL] = { .type = NLA_BINARY,
242 .len = IEEE80211_MAX_DATA_LEN },
Johannes Berg5727ef12007-12-19 02:03:34 +0100243 [NL80211_ATTR_STA_AID] = { .type = NLA_U16 },
244 [NL80211_ATTR_STA_FLAGS] = { .type = NLA_NESTED },
245 [NL80211_ATTR_STA_LISTEN_INTERVAL] = { .type = NLA_U16 },
246 [NL80211_ATTR_STA_SUPPORTED_RATES] = { .type = NLA_BINARY,
247 .len = NL80211_MAX_SUPP_RATES },
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +0100248 [NL80211_ATTR_STA_PLINK_ACTION] = { .type = NLA_U8 },
Johannes Berg5727ef12007-12-19 02:03:34 +0100249 [NL80211_ATTR_STA_VLAN] = { .type = NLA_U32 },
Johannes Berg0a9542e2008-10-15 11:54:04 +0200250 [NL80211_ATTR_MNTR_FLAGS] = { /* NLA_NESTED can't be empty */ },
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +0100251 [NL80211_ATTR_MESH_ID] = { .type = NLA_BINARY,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +0800252 .len = IEEE80211_MAX_MESH_ID_LEN },
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +0100253 [NL80211_ATTR_MPATH_NEXT_HOP] = { .type = NLA_U32 },
Jouni Malinen9f1ba902008-08-07 20:07:01 +0300254
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -0700255 [NL80211_ATTR_REG_ALPHA2] = { .type = NLA_STRING, .len = 2 },
256 [NL80211_ATTR_REG_RULES] = { .type = NLA_NESTED },
257
Jouni Malinen9f1ba902008-08-07 20:07:01 +0300258 [NL80211_ATTR_BSS_CTS_PROT] = { .type = NLA_U8 },
259 [NL80211_ATTR_BSS_SHORT_PREAMBLE] = { .type = NLA_U8 },
260 [NL80211_ATTR_BSS_SHORT_SLOT_TIME] = { .type = NLA_U8 },
Jouni Malinen90c97a02008-10-30 16:59:22 +0200261 [NL80211_ATTR_BSS_BASIC_RATES] = { .type = NLA_BINARY,
262 .len = NL80211_MAX_SUPP_RATES },
Helmut Schaa50b12f52010-11-19 12:40:25 +0100263 [NL80211_ATTR_BSS_HT_OPMODE] = { .type = NLA_U16 },
Jouni Malinen36aedc92008-08-25 11:58:58 +0300264
Javier Cardona24bdd9f2010-12-16 17:37:48 -0800265 [NL80211_ATTR_MESH_CONFIG] = { .type = NLA_NESTED },
Javier Cardona15d5dda2011-04-07 15:08:28 -0700266 [NL80211_ATTR_SUPPORT_MESH_AUTH] = { .type = NLA_FLAG },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -0700267
Johannes Berg6c739412011-11-03 09:27:01 +0100268 [NL80211_ATTR_HT_CAPABILITY] = { .len = NL80211_HT_CAPABILITY_LEN },
Jouni Malinen9aed3cc2009-01-13 16:03:29 +0200269
270 [NL80211_ATTR_MGMT_SUBTYPE] = { .type = NLA_U8 },
271 [NL80211_ATTR_IE] = { .type = NLA_BINARY,
272 .len = IEEE80211_MAX_DATA_LEN },
Johannes Berg2a519312009-02-10 21:25:55 +0100273 [NL80211_ATTR_SCAN_FREQUENCIES] = { .type = NLA_NESTED },
274 [NL80211_ATTR_SCAN_SSIDS] = { .type = NLA_NESTED },
Jouni Malinen636a5d32009-03-19 13:39:22 +0200275
276 [NL80211_ATTR_SSID] = { .type = NLA_BINARY,
277 .len = IEEE80211_MAX_SSID_LEN },
278 [NL80211_ATTR_AUTH_TYPE] = { .type = NLA_U32 },
279 [NL80211_ATTR_REASON_CODE] = { .type = NLA_U16 },
Johannes Berg04a773a2009-04-19 21:24:32 +0200280 [NL80211_ATTR_FREQ_FIXED] = { .type = NLA_FLAG },
Jouni Malinen1965c852009-04-22 21:38:25 +0300281 [NL80211_ATTR_TIMED_OUT] = { .type = NLA_FLAG },
Jouni Malinendc6382ce2009-05-06 22:09:37 +0300282 [NL80211_ATTR_USE_MFP] = { .type = NLA_U32 },
Johannes Bergeccb8e82009-05-11 21:57:56 +0300283 [NL80211_ATTR_STA_FLAGS2] = {
284 .len = sizeof(struct nl80211_sta_flag_update),
285 },
Jouni Malinen3f77316c2009-05-11 21:57:57 +0300286 [NL80211_ATTR_CONTROL_PORT] = { .type = NLA_FLAG },
Johannes Bergc0692b82010-08-27 14:26:53 +0300287 [NL80211_ATTR_CONTROL_PORT_ETHERTYPE] = { .type = NLA_U16 },
288 [NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT] = { .type = NLA_FLAG },
Samuel Ortizb23aa672009-07-01 21:26:54 +0200289 [NL80211_ATTR_PRIVACY] = { .type = NLA_FLAG },
290 [NL80211_ATTR_CIPHER_SUITE_GROUP] = { .type = NLA_U32 },
291 [NL80211_ATTR_WPA_VERSIONS] = { .type = NLA_U32 },
Johannes Berg463d0182009-07-14 00:33:35 +0200292 [NL80211_ATTR_PID] = { .type = NLA_U32 },
Felix Fietkau8b787642009-11-10 18:53:10 +0100293 [NL80211_ATTR_4ADDR] = { .type = NLA_U8 },
Samuel Ortiz67fbb162009-11-24 23:59:15 +0100294 [NL80211_ATTR_PMKID] = { .type = NLA_BINARY,
295 .len = WLAN_PMKID_LEN },
Jouni Malinen9588bbd2009-12-23 13:15:41 +0100296 [NL80211_ATTR_DURATION] = { .type = NLA_U32 },
297 [NL80211_ATTR_COOKIE] = { .type = NLA_U64 },
Jouni Malinen13ae75b2009-12-29 12:59:45 +0200298 [NL80211_ATTR_TX_RATES] = { .type = NLA_NESTED },
Jouni Malinen026331c2010-02-15 12:53:10 +0200299 [NL80211_ATTR_FRAME] = { .type = NLA_BINARY,
300 .len = IEEE80211_MAX_DATA_LEN },
301 [NL80211_ATTR_FRAME_MATCH] = { .type = NLA_BINARY, },
Kalle Valoffb9eb32010-02-17 17:58:10 +0200302 [NL80211_ATTR_PS_STATE] = { .type = NLA_U32 },
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +0200303 [NL80211_ATTR_CQM] = { .type = NLA_NESTED, },
Jouni Malinend5cdfac2010-04-04 09:37:19 +0300304 [NL80211_ATTR_LOCAL_STATE_CHANGE] = { .type = NLA_FLAG },
Felix Fietkaufd8aaaf2010-04-27 01:23:35 +0200305 [NL80211_ATTR_AP_ISOLATE] = { .type = NLA_U8 },
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +0300306 [NL80211_ATTR_WIPHY_TX_POWER_SETTING] = { .type = NLA_U32 },
307 [NL80211_ATTR_WIPHY_TX_POWER_LEVEL] = { .type = NLA_U32 },
Johannes Berg2e161f72010-08-12 15:38:38 +0200308 [NL80211_ATTR_FRAME_TYPE] = { .type = NLA_U16 },
Bruno Randolfafe0cbf2010-11-10 12:50:50 +0900309 [NL80211_ATTR_WIPHY_ANTENNA_TX] = { .type = NLA_U32 },
310 [NL80211_ATTR_WIPHY_ANTENNA_RX] = { .type = NLA_U32 },
Felix Fietkau885a46d2010-11-11 15:07:22 +0100311 [NL80211_ATTR_MCAST_RATE] = { .type = NLA_U32 },
Johannes Bergf7ca38d2010-11-25 10:02:29 +0100312 [NL80211_ATTR_OFFCHANNEL_TX_OK] = { .type = NLA_FLAG },
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100313 [NL80211_ATTR_KEY_DEFAULT_TYPES] = { .type = NLA_NESTED },
Johannes Bergff1b6e62011-05-04 15:37:28 +0200314 [NL80211_ATTR_WOWLAN_TRIGGERS] = { .type = NLA_NESTED },
Javier Cardona9c3990a2011-05-03 16:57:11 -0700315 [NL80211_ATTR_STA_PLINK_STATE] = { .type = NLA_U8 },
Luciano Coelhobbe6ad62011-05-11 17:09:37 +0300316 [NL80211_ATTR_SCHED_SCAN_INTERVAL] = { .type = NLA_U32 },
Johannes Berge5497d72011-07-05 16:35:40 +0200317 [NL80211_ATTR_REKEY_DATA] = { .type = NLA_NESTED },
Johannes Berg34850ab2011-07-18 18:08:35 +0200318 [NL80211_ATTR_SCAN_SUPP_RATES] = { .type = NLA_NESTED },
Jouni Malinen32e9de82011-08-10 23:53:31 +0300319 [NL80211_ATTR_HIDDEN_SSID] = { .type = NLA_U32 },
Jouni Malinen9946ecf2011-08-10 23:55:56 +0300320 [NL80211_ATTR_IE_PROBE_RESP] = { .type = NLA_BINARY,
321 .len = IEEE80211_MAX_DATA_LEN },
322 [NL80211_ATTR_IE_ASSOC_RESP] = { .type = NLA_BINARY,
323 .len = IEEE80211_MAX_DATA_LEN },
Vivek Natarajanf4b34b52011-08-29 14:23:03 +0530324 [NL80211_ATTR_ROAM_SUPPORT] = { .type = NLA_FLAG },
Luciano Coelhoa1f1c212011-08-31 16:01:48 +0300325 [NL80211_ATTR_SCHED_SCAN_MATCH] = { .type = NLA_NESTED },
Rajkumar Manoharane9f935e2011-09-25 14:53:30 +0530326 [NL80211_ATTR_TX_NO_CCK_RATE] = { .type = NLA_FLAG },
Arik Nemtsov109086c2011-09-28 14:12:50 +0300327 [NL80211_ATTR_TDLS_ACTION] = { .type = NLA_U8 },
328 [NL80211_ATTR_TDLS_DIALOG_TOKEN] = { .type = NLA_U8 },
329 [NL80211_ATTR_TDLS_OPERATION] = { .type = NLA_U8 },
330 [NL80211_ATTR_TDLS_SUPPORT] = { .type = NLA_FLAG },
331 [NL80211_ATTR_TDLS_EXTERNAL_SETUP] = { .type = NLA_FLAG },
Arik Nemtsov31fa97c2014-06-11 17:18:21 +0300332 [NL80211_ATTR_TDLS_INITIATOR] = { .type = NLA_FLAG },
Johannes Berge247bd902011-11-04 11:18:21 +0100333 [NL80211_ATTR_DONT_WAIT_FOR_ACK] = { .type = NLA_FLAG },
Arik Nemtsov00f740e2011-11-10 11:28:56 +0200334 [NL80211_ATTR_PROBE_RESP] = { .type = NLA_BINARY,
335 .len = IEEE80211_MAX_DATA_LEN },
Luis R. Rodriguez8b60b072011-10-11 10:59:02 -0700336 [NL80211_ATTR_DFS_REGION] = { .type = NLA_U8 },
Ben Greear7e7c8922011-11-18 11:31:59 -0800337 [NL80211_ATTR_DISABLE_HT] = { .type = NLA_FLAG },
338 [NL80211_ATTR_HT_CAPABILITY_MASK] = {
339 .len = NL80211_HT_CAPABILITY_LEN
340 },
Simon Wunderlich1d9d9212011-11-18 14:20:43 +0100341 [NL80211_ATTR_NOACK_MAP] = { .type = NLA_U16 },
Vasanthakumar Thiagarajan1b658f12012-03-02 15:50:02 +0530342 [NL80211_ATTR_INACTIVITY_TIMEOUT] = { .type = NLA_U16 },
Bala Shanmugam4486ea92012-03-07 17:27:12 +0530343 [NL80211_ATTR_BG_SCAN_PERIOD] = { .type = NLA_U16 },
Johannes Berg89a54e42012-06-15 14:33:17 +0200344 [NL80211_ATTR_WDEV] = { .type = NLA_U64 },
Luis R. Rodriguez57b5ce02012-07-12 11:49:18 -0700345 [NL80211_ATTR_USER_REG_HINT_TYPE] = { .type = NLA_U32 },
Jouni Malinen11b6b5a2016-10-27 00:41:58 +0300346 [NL80211_ATTR_AUTH_DATA] = { .type = NLA_BINARY, },
Mahesh Palivelaf461be3e2012-10-11 08:04:52 +0000347 [NL80211_ATTR_VHT_CAPABILITY] = { .len = NL80211_VHT_CAPABILITY_LEN },
Sam Lefflered4737712012-10-11 21:03:31 -0700348 [NL80211_ATTR_SCAN_FLAGS] = { .type = NLA_U32 },
Johannes Berg53cabad2012-11-14 15:17:28 +0100349 [NL80211_ATTR_P2P_CTWINDOW] = { .type = NLA_U8 },
350 [NL80211_ATTR_P2P_OPPPS] = { .type = NLA_U8 },
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +0530351 [NL80211_ATTR_ACL_POLICY] = {. type = NLA_U32 },
352 [NL80211_ATTR_MAC_ADDRS] = { .type = NLA_NESTED },
Jouni Malinen9d62a982013-02-14 21:10:13 +0200353 [NL80211_ATTR_STA_CAPABILITY] = { .type = NLA_U16 },
354 [NL80211_ATTR_STA_EXT_CAPABILITY] = { .type = NLA_BINARY, },
Johannes Berg3713b4e2013-02-14 16:19:38 +0100355 [NL80211_ATTR_SPLIT_WIPHY_DUMP] = { .type = NLA_FLAG, },
Johannes Bergee2aca32013-02-21 17:36:01 +0100356 [NL80211_ATTR_DISABLE_VHT] = { .type = NLA_FLAG },
357 [NL80211_ATTR_VHT_CAPABILITY_MASK] = {
358 .len = NL80211_VHT_CAPABILITY_LEN,
359 },
Jouni Malinen355199e2013-02-27 17:14:27 +0200360 [NL80211_ATTR_MDID] = { .type = NLA_U16 },
361 [NL80211_ATTR_IE_RIC] = { .type = NLA_BINARY,
362 .len = IEEE80211_MAX_DATA_LEN },
Jouni Malinen5e4b6f52013-05-16 20:11:08 +0300363 [NL80211_ATTR_PEER_AID] = { .type = NLA_U16 },
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +0200364 [NL80211_ATTR_CH_SWITCH_COUNT] = { .type = NLA_U32 },
365 [NL80211_ATTR_CH_SWITCH_BLOCK_TX] = { .type = NLA_FLAG },
366 [NL80211_ATTR_CSA_IES] = { .type = NLA_NESTED },
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +0300367 [NL80211_ATTR_CSA_C_OFF_BEACON] = { .type = NLA_BINARY },
368 [NL80211_ATTR_CSA_C_OFF_PRESP] = { .type = NLA_BINARY },
Sunil Duttc01fc9a2013-10-09 20:45:21 +0530369 [NL80211_ATTR_STA_SUPPORTED_CHANNELS] = { .type = NLA_BINARY },
370 [NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES] = { .type = NLA_BINARY },
Simon Wunderlich5336fa82013-10-07 18:41:05 +0200371 [NL80211_ATTR_HANDLE_DFS] = { .type = NLA_FLAG },
Marek Kwaczynski60f4a7b2013-12-03 10:04:59 +0100372 [NL80211_ATTR_OPMODE_NOTIF] = { .type = NLA_U8 },
Johannes Bergad7e7182013-11-13 13:37:47 +0100373 [NL80211_ATTR_VENDOR_ID] = { .type = NLA_U32 },
374 [NL80211_ATTR_VENDOR_SUBCMD] = { .type = NLA_U32 },
375 [NL80211_ATTR_VENDOR_DATA] = { .type = NLA_BINARY },
Kyeyoon Parkfa9ffc72013-12-16 23:01:30 -0800376 [NL80211_ATTR_QOS_MAP] = { .type = NLA_BINARY,
377 .len = IEEE80211_QOS_MAP_LEN_MAX },
Jouni Malinen1df4a512014-01-15 00:00:47 +0200378 [NL80211_ATTR_MAC_HINT] = { .len = ETH_ALEN },
379 [NL80211_ATTR_WIPHY_FREQ_HINT] = { .type = NLA_U32 },
Sunil Dutt Undekaridf942e72014-02-20 16:22:09 +0530380 [NL80211_ATTR_TDLS_PEER_CAPABILITY] = { .type = NLA_U32 },
Jukka Rissanen18e5ca62014-11-13 17:25:14 +0200381 [NL80211_ATTR_SOCKET_OWNER] = { .type = NLA_FLAG },
Andrei Otcheretianski34d22ce2014-05-09 14:11:44 +0300382 [NL80211_ATTR_CSA_C_OFFSETS_TX] = { .type = NLA_BINARY },
Assaf Kraussbab5ab72014-09-03 15:25:01 +0300383 [NL80211_ATTR_USE_RRM] = { .type = NLA_FLAG },
Johannes Berg960d01a2014-09-09 22:55:35 +0300384 [NL80211_ATTR_TSID] = { .type = NLA_U8 },
385 [NL80211_ATTR_USER_PRIO] = { .type = NLA_U8 },
386 [NL80211_ATTR_ADMITTED_TIME] = { .type = NLA_U16 },
Eliad Peller18998c32014-09-10 14:07:34 +0300387 [NL80211_ATTR_SMPS_MODE] = { .type = NLA_U8 },
Johannes Bergad2b26a2014-06-12 21:39:05 +0200388 [NL80211_ATTR_MAC_MASK] = { .len = ETH_ALEN },
Arik Nemtsov1bdd7162014-12-15 19:26:01 +0200389 [NL80211_ATTR_WIPHY_SELF_MANAGED_REG] = { .type = NLA_FLAG },
Vadim Kochan4b681c82015-01-12 16:34:05 +0200390 [NL80211_ATTR_NETNS_FD] = { .type = NLA_U32 },
Luciano Coelho9c748932015-01-16 16:04:09 +0200391 [NL80211_ATTR_SCHED_SCAN_DELAY] = { .type = NLA_U32 },
Ilan peer05050752015-03-04 00:32:06 -0500392 [NL80211_ATTR_REG_INDOOR] = { .type = NLA_FLAG },
Lior David34d50512016-01-28 10:58:25 +0200393 [NL80211_ATTR_PBSS] = { .type = NLA_FLAG },
Arend van Spriel38de03d2016-03-02 20:37:18 +0100394 [NL80211_ATTR_BSS_SELECT] = { .type = NLA_NESTED },
Ayala Beker17b94242016-03-17 15:41:38 +0200395 [NL80211_ATTR_STA_SUPPORT_P2P_PS] = { .type = NLA_U8 },
Aviya Erenfeldc6e6a0c2016-07-05 15:23:08 +0300396 [NL80211_ATTR_MU_MIMO_GROUP_DATA] = {
397 .len = VHT_MUMIMO_GROUPS_DATA_LEN
398 },
399 [NL80211_ATTR_MU_MIMO_FOLLOW_MAC_ADDR] = { .len = ETH_ALEN },
Ayala Bekercb3b7d82016-09-20 17:31:13 +0300400 [NL80211_ATTR_NAN_MASTER_PREF] = { .type = NLA_U8 },
Luca Coelho85859892017-02-08 15:00:34 +0200401 [NL80211_ATTR_BANDS] = { .type = NLA_U32 },
Ayala Bekera442b762016-09-20 17:31:15 +0300402 [NL80211_ATTR_NAN_FUNC] = { .type = NLA_NESTED },
Jouni Malinen348bd452016-10-27 00:42:03 +0300403 [NL80211_ATTR_FILS_KEK] = { .type = NLA_BINARY,
404 .len = FILS_MAX_KEK_LEN },
405 [NL80211_ATTR_FILS_NONCES] = { .len = 2 * FILS_NONCE_LEN },
Michael Braunce0ce132016-10-10 19:12:22 +0200406 [NL80211_ATTR_MULTICAST_TO_UNICAST_ENABLED] = { .type = NLA_FLAG, },
Vamsi Krishna2fa436b2016-12-02 23:59:08 +0200407 [NL80211_ATTR_BSSID] = { .len = ETH_ALEN },
vamsi krishnabf95ecd2017-01-13 01:12:20 +0200408 [NL80211_ATTR_SCHED_SCAN_RELATIVE_RSSI] = { .type = NLA_S8 },
409 [NL80211_ATTR_SCHED_SCAN_RSSI_ADJUST] = {
410 .len = sizeof(struct nl80211_bss_select_rssi_adjust)
411 },
Purushottam Kushwaha3093ebbeab2017-01-13 01:12:21 +0200412 [NL80211_ATTR_TIMEOUT_REASON] = { .type = NLA_U32 },
Johannes Berg55682962007-09-20 13:09:35 -0400413};
414
Johannes Berge31b8212010-10-05 19:39:30 +0200415/* policy for the key attributes */
Alexey Dobriyanb54452b2010-02-18 08:14:31 +0000416static const struct nla_policy nl80211_key_policy[NL80211_KEY_MAX + 1] = {
Johannes Bergfffd0932009-07-08 14:22:54 +0200417 [NL80211_KEY_DATA] = { .type = NLA_BINARY, .len = WLAN_MAX_KEY_LEN },
Johannes Bergb9454e82009-07-08 13:29:08 +0200418 [NL80211_KEY_IDX] = { .type = NLA_U8 },
419 [NL80211_KEY_CIPHER] = { .type = NLA_U32 },
Jouni Malinen81962262011-11-02 23:36:31 +0200420 [NL80211_KEY_SEQ] = { .type = NLA_BINARY, .len = 16 },
Johannes Bergb9454e82009-07-08 13:29:08 +0200421 [NL80211_KEY_DEFAULT] = { .type = NLA_FLAG },
422 [NL80211_KEY_DEFAULT_MGMT] = { .type = NLA_FLAG },
Johannes Berge31b8212010-10-05 19:39:30 +0200423 [NL80211_KEY_TYPE] = { .type = NLA_U32 },
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100424 [NL80211_KEY_DEFAULT_TYPES] = { .type = NLA_NESTED },
425};
426
427/* policy for the key default flags */
428static const struct nla_policy
429nl80211_key_default_policy[NUM_NL80211_KEY_DEFAULT_TYPES] = {
430 [NL80211_KEY_DEFAULT_TYPE_UNICAST] = { .type = NLA_FLAG },
431 [NL80211_KEY_DEFAULT_TYPE_MULTICAST] = { .type = NLA_FLAG },
Johannes Bergb9454e82009-07-08 13:29:08 +0200432};
433
Johannes Bergf83ace32016-10-17 08:04:07 +0200434#ifdef CONFIG_PM
Johannes Bergff1b6e62011-05-04 15:37:28 +0200435/* policy for WoWLAN attributes */
436static const struct nla_policy
437nl80211_wowlan_policy[NUM_NL80211_WOWLAN_TRIG] = {
438 [NL80211_WOWLAN_TRIG_ANY] = { .type = NLA_FLAG },
439 [NL80211_WOWLAN_TRIG_DISCONNECT] = { .type = NLA_FLAG },
440 [NL80211_WOWLAN_TRIG_MAGIC_PKT] = { .type = NLA_FLAG },
441 [NL80211_WOWLAN_TRIG_PKT_PATTERN] = { .type = NLA_NESTED },
Johannes Berg77dbbb12011-07-13 10:48:55 +0200442 [NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE] = { .type = NLA_FLAG },
443 [NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST] = { .type = NLA_FLAG },
444 [NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE] = { .type = NLA_FLAG },
445 [NL80211_WOWLAN_TRIG_RFKILL_RELEASE] = { .type = NLA_FLAG },
Johannes Berg2a0e0472013-01-23 22:57:40 +0100446 [NL80211_WOWLAN_TRIG_TCP_CONNECTION] = { .type = NLA_NESTED },
Luciano Coelho8cd4d452014-09-17 11:55:28 +0300447 [NL80211_WOWLAN_TRIG_NET_DETECT] = { .type = NLA_NESTED },
Johannes Berg2a0e0472013-01-23 22:57:40 +0100448};
449
450static const struct nla_policy
451nl80211_wowlan_tcp_policy[NUM_NL80211_WOWLAN_TCP] = {
452 [NL80211_WOWLAN_TCP_SRC_IPV4] = { .type = NLA_U32 },
453 [NL80211_WOWLAN_TCP_DST_IPV4] = { .type = NLA_U32 },
454 [NL80211_WOWLAN_TCP_DST_MAC] = { .len = ETH_ALEN },
455 [NL80211_WOWLAN_TCP_SRC_PORT] = { .type = NLA_U16 },
456 [NL80211_WOWLAN_TCP_DST_PORT] = { .type = NLA_U16 },
457 [NL80211_WOWLAN_TCP_DATA_PAYLOAD] = { .len = 1 },
458 [NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ] = {
459 .len = sizeof(struct nl80211_wowlan_tcp_data_seq)
460 },
461 [NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN] = {
462 .len = sizeof(struct nl80211_wowlan_tcp_data_token)
463 },
464 [NL80211_WOWLAN_TCP_DATA_INTERVAL] = { .type = NLA_U32 },
465 [NL80211_WOWLAN_TCP_WAKE_PAYLOAD] = { .len = 1 },
466 [NL80211_WOWLAN_TCP_WAKE_MASK] = { .len = 1 },
Johannes Bergff1b6e62011-05-04 15:37:28 +0200467};
Johannes Bergf83ace32016-10-17 08:04:07 +0200468#endif /* CONFIG_PM */
Johannes Bergff1b6e62011-05-04 15:37:28 +0200469
Amitkumar Karwarbe29b99a2013-06-28 11:51:26 -0700470/* policy for coalesce rule attributes */
471static const struct nla_policy
472nl80211_coalesce_policy[NUM_NL80211_ATTR_COALESCE_RULE] = {
473 [NL80211_ATTR_COALESCE_RULE_DELAY] = { .type = NLA_U32 },
474 [NL80211_ATTR_COALESCE_RULE_CONDITION] = { .type = NLA_U32 },
475 [NL80211_ATTR_COALESCE_RULE_PKT_PATTERN] = { .type = NLA_NESTED },
476};
477
Johannes Berge5497d72011-07-05 16:35:40 +0200478/* policy for GTK rekey offload attributes */
479static const struct nla_policy
480nl80211_rekey_policy[NUM_NL80211_REKEY_DATA] = {
481 [NL80211_REKEY_DATA_KEK] = { .len = NL80211_KEK_LEN },
482 [NL80211_REKEY_DATA_KCK] = { .len = NL80211_KCK_LEN },
483 [NL80211_REKEY_DATA_REPLAY_CTR] = { .len = NL80211_REPLAY_CTR_LEN },
484};
485
Luciano Coelhoa1f1c212011-08-31 16:01:48 +0300486static const struct nla_policy
487nl80211_match_policy[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1] = {
Johannes Berg4a4ab0d2012-06-13 11:17:11 +0200488 [NL80211_SCHED_SCAN_MATCH_ATTR_SSID] = { .type = NLA_BINARY,
Luciano Coelhoa1f1c212011-08-31 16:01:48 +0300489 .len = IEEE80211_MAX_SSID_LEN },
Thomas Pedersen88e920b2012-06-21 11:09:54 -0700490 [NL80211_SCHED_SCAN_MATCH_ATTR_RSSI] = { .type = NLA_U32 },
Luciano Coelhoa1f1c212011-08-31 16:01:48 +0300491};
492
Avraham Stern3b06d272015-10-12 09:51:34 +0300493static const struct nla_policy
494nl80211_plan_policy[NL80211_SCHED_SCAN_PLAN_MAX + 1] = {
495 [NL80211_SCHED_SCAN_PLAN_INTERVAL] = { .type = NLA_U32 },
496 [NL80211_SCHED_SCAN_PLAN_ITERATIONS] = { .type = NLA_U32 },
497};
498
Arend van Spriel38de03d2016-03-02 20:37:18 +0100499static const struct nla_policy
500nl80211_bss_select_policy[NL80211_BSS_SELECT_ATTR_MAX + 1] = {
501 [NL80211_BSS_SELECT_ATTR_RSSI] = { .type = NLA_FLAG },
502 [NL80211_BSS_SELECT_ATTR_BAND_PREF] = { .type = NLA_U32 },
503 [NL80211_BSS_SELECT_ATTR_RSSI_ADJUST] = {
504 .len = sizeof(struct nl80211_bss_select_rssi_adjust)
505 },
506};
507
Ayala Bekera442b762016-09-20 17:31:15 +0300508/* policy for NAN function attributes */
509static const struct nla_policy
510nl80211_nan_func_policy[NL80211_NAN_FUNC_ATTR_MAX + 1] = {
511 [NL80211_NAN_FUNC_TYPE] = { .type = NLA_U8 },
512 [NL80211_NAN_FUNC_SERVICE_ID] = { .type = NLA_BINARY,
513 .len = NL80211_NAN_FUNC_SERVICE_ID_LEN },
514 [NL80211_NAN_FUNC_PUBLISH_TYPE] = { .type = NLA_U8 },
515 [NL80211_NAN_FUNC_PUBLISH_BCAST] = { .type = NLA_FLAG },
516 [NL80211_NAN_FUNC_SUBSCRIBE_ACTIVE] = { .type = NLA_FLAG },
517 [NL80211_NAN_FUNC_FOLLOW_UP_ID] = { .type = NLA_U8 },
518 [NL80211_NAN_FUNC_FOLLOW_UP_REQ_ID] = { .type = NLA_U8 },
519 [NL80211_NAN_FUNC_FOLLOW_UP_DEST] = { .len = ETH_ALEN },
520 [NL80211_NAN_FUNC_CLOSE_RANGE] = { .type = NLA_FLAG },
521 [NL80211_NAN_FUNC_TTL] = { .type = NLA_U32 },
522 [NL80211_NAN_FUNC_SERVICE_INFO] = { .type = NLA_BINARY,
523 .len = NL80211_NAN_FUNC_SERVICE_SPEC_INFO_MAX_LEN },
524 [NL80211_NAN_FUNC_SRF] = { .type = NLA_NESTED },
525 [NL80211_NAN_FUNC_RX_MATCH_FILTER] = { .type = NLA_NESTED },
526 [NL80211_NAN_FUNC_TX_MATCH_FILTER] = { .type = NLA_NESTED },
527 [NL80211_NAN_FUNC_INSTANCE_ID] = { .type = NLA_U8 },
528 [NL80211_NAN_FUNC_TERM_REASON] = { .type = NLA_U8 },
529};
530
531/* policy for Service Response Filter attributes */
532static const struct nla_policy
533nl80211_nan_srf_policy[NL80211_NAN_SRF_ATTR_MAX + 1] = {
534 [NL80211_NAN_SRF_INCLUDE] = { .type = NLA_FLAG },
535 [NL80211_NAN_SRF_BF] = { .type = NLA_BINARY,
536 .len = NL80211_NAN_FUNC_SRF_MAX_LEN },
537 [NL80211_NAN_SRF_BF_IDX] = { .type = NLA_U8 },
538 [NL80211_NAN_SRF_MAC_ADDRS] = { .type = NLA_NESTED },
539};
540
Johannes Berg97990a02013-04-19 01:02:55 +0200541static int nl80211_prepare_wdev_dump(struct sk_buff *skb,
542 struct netlink_callback *cb,
543 struct cfg80211_registered_device **rdev,
544 struct wireless_dev **wdev)
Holger Schuriga0438972009-11-11 11:30:02 +0100545{
Johannes Berg67748892010-10-04 21:14:06 +0200546 int err;
547
Johannes Berg67748892010-10-04 21:14:06 +0200548 rtnl_lock();
549
Johannes Berg97990a02013-04-19 01:02:55 +0200550 if (!cb->args[0]) {
551 err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize,
Johannes Bergc90c39d2016-10-24 14:40:01 +0200552 genl_family_attrbuf(&nl80211_fam),
553 nl80211_fam.maxattr, nl80211_policy);
Johannes Berg97990a02013-04-19 01:02:55 +0200554 if (err)
555 goto out_unlock;
556
Johannes Bergc90c39d2016-10-24 14:40:01 +0200557 *wdev = __cfg80211_wdev_from_attrs(
558 sock_net(skb->sk),
559 genl_family_attrbuf(&nl80211_fam));
Johannes Berg97990a02013-04-19 01:02:55 +0200560 if (IS_ERR(*wdev)) {
561 err = PTR_ERR(*wdev);
562 goto out_unlock;
563 }
Zhao, Gangf26cbf42014-04-21 12:53:03 +0800564 *rdev = wiphy_to_rdev((*wdev)->wiphy);
Johannes Bergc319d502013-07-30 22:34:28 +0200565 /* 0 is the first index - add 1 to parse only once */
566 cb->args[0] = (*rdev)->wiphy_idx + 1;
Johannes Berg97990a02013-04-19 01:02:55 +0200567 cb->args[1] = (*wdev)->identifier;
568 } else {
Johannes Bergc319d502013-07-30 22:34:28 +0200569 /* subtract the 1 again here */
570 struct wiphy *wiphy = wiphy_idx_to_wiphy(cb->args[0] - 1);
Johannes Berg97990a02013-04-19 01:02:55 +0200571 struct wireless_dev *tmp;
572
573 if (!wiphy) {
574 err = -ENODEV;
575 goto out_unlock;
576 }
Zhao, Gangf26cbf42014-04-21 12:53:03 +0800577 *rdev = wiphy_to_rdev(wiphy);
Johannes Berg97990a02013-04-19 01:02:55 +0200578 *wdev = NULL;
579
Johannes Berg53873f12016-05-03 16:52:04 +0300580 list_for_each_entry(tmp, &(*rdev)->wiphy.wdev_list, list) {
Johannes Berg97990a02013-04-19 01:02:55 +0200581 if (tmp->identifier == cb->args[1]) {
582 *wdev = tmp;
583 break;
584 }
585 }
Johannes Berg97990a02013-04-19 01:02:55 +0200586
587 if (!*wdev) {
588 err = -ENODEV;
589 goto out_unlock;
590 }
Johannes Berg67748892010-10-04 21:14:06 +0200591 }
592
Johannes Berg67748892010-10-04 21:14:06 +0200593 return 0;
Johannes Berg97990a02013-04-19 01:02:55 +0200594 out_unlock:
Johannes Berg67748892010-10-04 21:14:06 +0200595 rtnl_unlock();
596 return err;
597}
598
Johannes Berg97990a02013-04-19 01:02:55 +0200599static void nl80211_finish_wdev_dump(struct cfg80211_registered_device *rdev)
Johannes Berg67748892010-10-04 21:14:06 +0200600{
Johannes Berg67748892010-10-04 21:14:06 +0200601 rtnl_unlock();
602}
603
Johannes Bergf4a11bb2009-03-27 12:40:28 +0100604/* IE validation */
605static bool is_valid_ie_attr(const struct nlattr *attr)
606{
607 const u8 *pos;
608 int len;
609
610 if (!attr)
611 return true;
612
613 pos = nla_data(attr);
614 len = nla_len(attr);
615
616 while (len) {
617 u8 elemlen;
618
619 if (len < 2)
620 return false;
621 len -= 2;
622
623 elemlen = pos[1];
624 if (elemlen > len)
625 return false;
626
627 len -= elemlen;
628 pos += 2 + elemlen;
629 }
630
631 return true;
632}
633
Johannes Berg55682962007-09-20 13:09:35 -0400634/* message building helper */
Eric W. Biederman15e47302012-09-07 20:12:54 +0000635static inline void *nl80211hdr_put(struct sk_buff *skb, u32 portid, u32 seq,
Johannes Berg55682962007-09-20 13:09:35 -0400636 int flags, u8 cmd)
637{
638 /* since there is no private header just add the generic one */
Eric W. Biederman15e47302012-09-07 20:12:54 +0000639 return genlmsg_put(skb, portid, seq, &nl80211_fam, flags, cmd);
Johannes Berg55682962007-09-20 13:09:35 -0400640}
641
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400642static int nl80211_msg_put_channel(struct sk_buff *msg,
Johannes Bergcdc89b92013-02-18 23:54:36 +0100643 struct ieee80211_channel *chan,
644 bool large)
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400645{
Rostislav Lisovyea077c12014-04-15 14:37:55 +0200646 /* Some channels must be completely excluded from the
647 * list to protect old user-space tools from breaking
648 */
649 if (!large && chan->flags &
650 (IEEE80211_CHAN_NO_10MHZ | IEEE80211_CHAN_NO_20MHZ))
651 return 0;
652
David S. Miller9360ffd2012-03-29 04:41:26 -0400653 if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_FREQ,
654 chan->center_freq))
655 goto nla_put_failure;
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400656
David S. Miller9360ffd2012-03-29 04:41:26 -0400657 if ((chan->flags & IEEE80211_CHAN_DISABLED) &&
658 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_DISABLED))
659 goto nla_put_failure;
Luis R. Rodriguez8fe02e12013-10-21 19:22:25 +0200660 if (chan->flags & IEEE80211_CHAN_NO_IR) {
661 if (nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_IR))
662 goto nla_put_failure;
663 if (nla_put_flag(msg, __NL80211_FREQUENCY_ATTR_NO_IBSS))
664 goto nla_put_failure;
665 }
Johannes Bergcdc89b92013-02-18 23:54:36 +0100666 if (chan->flags & IEEE80211_CHAN_RADAR) {
667 if (nla_put_flag(msg, NL80211_FREQUENCY_ATTR_RADAR))
668 goto nla_put_failure;
669 if (large) {
670 u32 time;
671
672 time = elapsed_jiffies_msecs(chan->dfs_state_entered);
673
674 if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_DFS_STATE,
675 chan->dfs_state))
676 goto nla_put_failure;
677 if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_DFS_TIME,
678 time))
679 goto nla_put_failure;
Janusz Dziedzic089027e2014-02-21 19:46:12 +0100680 if (nla_put_u32(msg,
681 NL80211_FREQUENCY_ATTR_DFS_CAC_TIME,
682 chan->dfs_cac_ms))
683 goto nla_put_failure;
Johannes Bergcdc89b92013-02-18 23:54:36 +0100684 }
685 }
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400686
Johannes Bergfe1abaf2013-02-27 15:39:45 +0100687 if (large) {
688 if ((chan->flags & IEEE80211_CHAN_NO_HT40MINUS) &&
689 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_HT40_MINUS))
690 goto nla_put_failure;
691 if ((chan->flags & IEEE80211_CHAN_NO_HT40PLUS) &&
692 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_HT40_PLUS))
693 goto nla_put_failure;
694 if ((chan->flags & IEEE80211_CHAN_NO_80MHZ) &&
695 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_80MHZ))
696 goto nla_put_failure;
697 if ((chan->flags & IEEE80211_CHAN_NO_160MHZ) &&
698 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_160MHZ))
699 goto nla_put_failure;
David Spinadel570dbde2014-02-23 09:12:59 +0200700 if ((chan->flags & IEEE80211_CHAN_INDOOR_ONLY) &&
701 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_INDOOR_ONLY))
702 goto nla_put_failure;
Arik Nemtsov06f207f2015-05-06 16:28:31 +0300703 if ((chan->flags & IEEE80211_CHAN_IR_CONCURRENT) &&
704 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_IR_CONCURRENT))
David Spinadel570dbde2014-02-23 09:12:59 +0200705 goto nla_put_failure;
Rostislav Lisovyea077c12014-04-15 14:37:55 +0200706 if ((chan->flags & IEEE80211_CHAN_NO_20MHZ) &&
707 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_20MHZ))
708 goto nla_put_failure;
709 if ((chan->flags & IEEE80211_CHAN_NO_10MHZ) &&
710 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_10MHZ))
711 goto nla_put_failure;
Johannes Bergfe1abaf2013-02-27 15:39:45 +0100712 }
713
David S. Miller9360ffd2012-03-29 04:41:26 -0400714 if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_MAX_TX_POWER,
715 DBM_TO_MBM(chan->max_power)))
716 goto nla_put_failure;
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400717
718 return 0;
719
720 nla_put_failure:
721 return -ENOBUFS;
722}
723
Johannes Berg55682962007-09-20 13:09:35 -0400724/* netlink command implementations */
725
Johannes Bergb9454e82009-07-08 13:29:08 +0200726struct key_parse {
727 struct key_params p;
728 int idx;
Johannes Berge31b8212010-10-05 19:39:30 +0200729 int type;
Johannes Bergb9454e82009-07-08 13:29:08 +0200730 bool def, defmgmt;
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100731 bool def_uni, def_multi;
Johannes Bergb9454e82009-07-08 13:29:08 +0200732};
733
734static int nl80211_parse_key_new(struct nlattr *key, struct key_parse *k)
735{
736 struct nlattr *tb[NL80211_KEY_MAX + 1];
737 int err = nla_parse_nested(tb, NL80211_KEY_MAX, key,
738 nl80211_key_policy);
739 if (err)
740 return err;
741
742 k->def = !!tb[NL80211_KEY_DEFAULT];
743 k->defmgmt = !!tb[NL80211_KEY_DEFAULT_MGMT];
744
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100745 if (k->def) {
746 k->def_uni = true;
747 k->def_multi = true;
748 }
749 if (k->defmgmt)
750 k->def_multi = true;
751
Johannes Bergb9454e82009-07-08 13:29:08 +0200752 if (tb[NL80211_KEY_IDX])
753 k->idx = nla_get_u8(tb[NL80211_KEY_IDX]);
754
755 if (tb[NL80211_KEY_DATA]) {
756 k->p.key = nla_data(tb[NL80211_KEY_DATA]);
757 k->p.key_len = nla_len(tb[NL80211_KEY_DATA]);
758 }
759
760 if (tb[NL80211_KEY_SEQ]) {
761 k->p.seq = nla_data(tb[NL80211_KEY_SEQ]);
762 k->p.seq_len = nla_len(tb[NL80211_KEY_SEQ]);
763 }
764
765 if (tb[NL80211_KEY_CIPHER])
766 k->p.cipher = nla_get_u32(tb[NL80211_KEY_CIPHER]);
767
Johannes Berge31b8212010-10-05 19:39:30 +0200768 if (tb[NL80211_KEY_TYPE]) {
769 k->type = nla_get_u32(tb[NL80211_KEY_TYPE]);
770 if (k->type < 0 || k->type >= NUM_NL80211_KEYTYPES)
771 return -EINVAL;
772 }
773
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100774 if (tb[NL80211_KEY_DEFAULT_TYPES]) {
775 struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES];
Kirtika Ruchandani7a087e72016-05-29 19:51:23 -0700776
Johannes Berg2da8f412012-01-20 13:52:37 +0100777 err = nla_parse_nested(kdt, NUM_NL80211_KEY_DEFAULT_TYPES - 1,
778 tb[NL80211_KEY_DEFAULT_TYPES],
779 nl80211_key_default_policy);
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100780 if (err)
781 return err;
782
783 k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST];
784 k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST];
785 }
786
Johannes Bergb9454e82009-07-08 13:29:08 +0200787 return 0;
788}
789
790static int nl80211_parse_key_old(struct genl_info *info, struct key_parse *k)
791{
792 if (info->attrs[NL80211_ATTR_KEY_DATA]) {
793 k->p.key = nla_data(info->attrs[NL80211_ATTR_KEY_DATA]);
794 k->p.key_len = nla_len(info->attrs[NL80211_ATTR_KEY_DATA]);
795 }
796
797 if (info->attrs[NL80211_ATTR_KEY_SEQ]) {
798 k->p.seq = nla_data(info->attrs[NL80211_ATTR_KEY_SEQ]);
799 k->p.seq_len = nla_len(info->attrs[NL80211_ATTR_KEY_SEQ]);
800 }
801
802 if (info->attrs[NL80211_ATTR_KEY_IDX])
803 k->idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]);
804
805 if (info->attrs[NL80211_ATTR_KEY_CIPHER])
806 k->p.cipher = nla_get_u32(info->attrs[NL80211_ATTR_KEY_CIPHER]);
807
808 k->def = !!info->attrs[NL80211_ATTR_KEY_DEFAULT];
809 k->defmgmt = !!info->attrs[NL80211_ATTR_KEY_DEFAULT_MGMT];
810
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100811 if (k->def) {
812 k->def_uni = true;
813 k->def_multi = true;
814 }
815 if (k->defmgmt)
816 k->def_multi = true;
817
Johannes Berge31b8212010-10-05 19:39:30 +0200818 if (info->attrs[NL80211_ATTR_KEY_TYPE]) {
819 k->type = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]);
820 if (k->type < 0 || k->type >= NUM_NL80211_KEYTYPES)
821 return -EINVAL;
822 }
823
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100824 if (info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES]) {
825 struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES];
826 int err = nla_parse_nested(
827 kdt, NUM_NL80211_KEY_DEFAULT_TYPES - 1,
828 info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES],
829 nl80211_key_default_policy);
830 if (err)
831 return err;
832
833 k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST];
834 k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST];
835 }
836
Johannes Bergb9454e82009-07-08 13:29:08 +0200837 return 0;
838}
839
840static int nl80211_parse_key(struct genl_info *info, struct key_parse *k)
841{
842 int err;
843
844 memset(k, 0, sizeof(*k));
845 k->idx = -1;
Johannes Berge31b8212010-10-05 19:39:30 +0200846 k->type = -1;
Johannes Bergb9454e82009-07-08 13:29:08 +0200847
848 if (info->attrs[NL80211_ATTR_KEY])
849 err = nl80211_parse_key_new(info->attrs[NL80211_ATTR_KEY], k);
850 else
851 err = nl80211_parse_key_old(info, k);
852
853 if (err)
854 return err;
855
856 if (k->def && k->defmgmt)
857 return -EINVAL;
858
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100859 if (k->defmgmt) {
860 if (k->def_uni || !k->def_multi)
861 return -EINVAL;
862 }
863
Johannes Bergb9454e82009-07-08 13:29:08 +0200864 if (k->idx != -1) {
865 if (k->defmgmt) {
866 if (k->idx < 4 || k->idx > 5)
867 return -EINVAL;
868 } else if (k->def) {
869 if (k->idx < 0 || k->idx > 3)
870 return -EINVAL;
871 } else {
872 if (k->idx < 0 || k->idx > 5)
873 return -EINVAL;
874 }
875 }
876
877 return 0;
878}
879
Johannes Bergfffd0932009-07-08 14:22:54 +0200880static struct cfg80211_cached_keys *
881nl80211_parse_connkeys(struct cfg80211_registered_device *rdev,
Sujith Manoharande7044e2012-10-18 10:19:28 +0530882 struct nlattr *keys, bool *no_ht)
Johannes Bergfffd0932009-07-08 14:22:54 +0200883{
884 struct key_parse parse;
885 struct nlattr *key;
886 struct cfg80211_cached_keys *result;
887 int rem, err, def = 0;
Johannes Bergf1c1f172016-09-13 17:08:23 +0200888 bool have_key = false;
889
890 nla_for_each_nested(key, keys, rem) {
891 have_key = true;
892 break;
893 }
894
895 if (!have_key)
896 return NULL;
Johannes Bergfffd0932009-07-08 14:22:54 +0200897
898 result = kzalloc(sizeof(*result), GFP_KERNEL);
899 if (!result)
900 return ERR_PTR(-ENOMEM);
901
902 result->def = -1;
Johannes Bergfffd0932009-07-08 14:22:54 +0200903
904 nla_for_each_nested(key, keys, rem) {
905 memset(&parse, 0, sizeof(parse));
906 parse.idx = -1;
907
908 err = nl80211_parse_key_new(key, &parse);
909 if (err)
910 goto error;
911 err = -EINVAL;
912 if (!parse.p.key)
913 goto error;
Johannes Berg42ee2312016-09-13 15:51:03 +0200914 if (parse.idx < 0 || parse.idx > 3)
Johannes Bergfffd0932009-07-08 14:22:54 +0200915 goto error;
916 if (parse.def) {
917 if (def)
918 goto error;
919 def = 1;
920 result->def = parse.idx;
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100921 if (!parse.def_uni || !parse.def_multi)
922 goto error;
Johannes Bergfffd0932009-07-08 14:22:54 +0200923 } else if (parse.defmgmt)
924 goto error;
925 err = cfg80211_validate_key_settings(rdev, &parse.p,
Johannes Berge31b8212010-10-05 19:39:30 +0200926 parse.idx, false, NULL);
Johannes Bergfffd0932009-07-08 14:22:54 +0200927 if (err)
928 goto error;
Johannes Berg386b1f22016-09-13 16:10:02 +0200929 if (parse.p.cipher != WLAN_CIPHER_SUITE_WEP40 &&
930 parse.p.cipher != WLAN_CIPHER_SUITE_WEP104) {
931 err = -EINVAL;
932 goto error;
933 }
Johannes Bergfffd0932009-07-08 14:22:54 +0200934 result->params[parse.idx].cipher = parse.p.cipher;
935 result->params[parse.idx].key_len = parse.p.key_len;
936 result->params[parse.idx].key = result->data[parse.idx];
937 memcpy(result->data[parse.idx], parse.p.key, parse.p.key_len);
Sujith Manoharande7044e2012-10-18 10:19:28 +0530938
Johannes Berg386b1f22016-09-13 16:10:02 +0200939 /* must be WEP key if we got here */
940 if (no_ht)
941 *no_ht = true;
Johannes Bergfffd0932009-07-08 14:22:54 +0200942 }
943
Johannes Bergf1c1f172016-09-13 17:08:23 +0200944 if (result->def < 0) {
945 err = -EINVAL;
946 goto error;
947 }
948
Johannes Bergfffd0932009-07-08 14:22:54 +0200949 return result;
950 error:
951 kfree(result);
952 return ERR_PTR(err);
953}
954
955static int nl80211_key_allowed(struct wireless_dev *wdev)
956{
957 ASSERT_WDEV_LOCK(wdev);
958
Johannes Bergfffd0932009-07-08 14:22:54 +0200959 switch (wdev->iftype) {
960 case NL80211_IFTYPE_AP:
961 case NL80211_IFTYPE_AP_VLAN:
Johannes Berg074ac8d2010-09-16 14:58:22 +0200962 case NL80211_IFTYPE_P2P_GO:
Thomas Pedersenff973af2011-05-03 16:57:12 -0700963 case NL80211_IFTYPE_MESH_POINT:
Johannes Bergfffd0932009-07-08 14:22:54 +0200964 break;
965 case NL80211_IFTYPE_ADHOC:
Johannes Bergfffd0932009-07-08 14:22:54 +0200966 case NL80211_IFTYPE_STATION:
Johannes Berg074ac8d2010-09-16 14:58:22 +0200967 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Bergceca7b72013-05-16 00:55:45 +0200968 if (!wdev->current_bss)
Johannes Bergfffd0932009-07-08 14:22:54 +0200969 return -ENOLINK;
970 break;
Johannes Bergde4fcba2014-10-31 14:16:12 +0100971 case NL80211_IFTYPE_UNSPECIFIED:
Rostislav Lisovy6e0bd6c2014-11-03 10:33:18 +0100972 case NL80211_IFTYPE_OCB:
Johannes Bergde4fcba2014-10-31 14:16:12 +0100973 case NL80211_IFTYPE_MONITOR:
Ayala Bekercb3b7d82016-09-20 17:31:13 +0300974 case NL80211_IFTYPE_NAN:
Johannes Bergde4fcba2014-10-31 14:16:12 +0100975 case NL80211_IFTYPE_P2P_DEVICE:
976 case NL80211_IFTYPE_WDS:
977 case NUM_NL80211_IFTYPES:
Johannes Bergfffd0932009-07-08 14:22:54 +0200978 return -EINVAL;
979 }
980
981 return 0;
982}
983
Jouni Malinen664834d2014-01-15 00:01:44 +0200984static struct ieee80211_channel *nl80211_get_valid_chan(struct wiphy *wiphy,
985 struct nlattr *tb)
986{
987 struct ieee80211_channel *chan;
988
989 if (tb == NULL)
990 return NULL;
991 chan = ieee80211_get_channel(wiphy, nla_get_u32(tb));
992 if (!chan || chan->flags & IEEE80211_CHAN_DISABLED)
993 return NULL;
994 return chan;
995}
996
Johannes Berg7527a782011-05-13 10:58:57 +0200997static int nl80211_put_iftypes(struct sk_buff *msg, u32 attr, u16 ifmodes)
998{
999 struct nlattr *nl_modes = nla_nest_start(msg, attr);
1000 int i;
1001
1002 if (!nl_modes)
1003 goto nla_put_failure;
1004
1005 i = 0;
1006 while (ifmodes) {
David S. Miller9360ffd2012-03-29 04:41:26 -04001007 if ((ifmodes & 1) && nla_put_flag(msg, i))
1008 goto nla_put_failure;
Johannes Berg7527a782011-05-13 10:58:57 +02001009 ifmodes >>= 1;
1010 i++;
1011 }
1012
1013 nla_nest_end(msg, nl_modes);
1014 return 0;
1015
1016nla_put_failure:
1017 return -ENOBUFS;
1018}
1019
1020static int nl80211_put_iface_combinations(struct wiphy *wiphy,
Johannes Bergcdc89b92013-02-18 23:54:36 +01001021 struct sk_buff *msg,
1022 bool large)
Johannes Berg7527a782011-05-13 10:58:57 +02001023{
1024 struct nlattr *nl_combis;
1025 int i, j;
1026
1027 nl_combis = nla_nest_start(msg,
1028 NL80211_ATTR_INTERFACE_COMBINATIONS);
1029 if (!nl_combis)
1030 goto nla_put_failure;
1031
1032 for (i = 0; i < wiphy->n_iface_combinations; i++) {
1033 const struct ieee80211_iface_combination *c;
1034 struct nlattr *nl_combi, *nl_limits;
1035
1036 c = &wiphy->iface_combinations[i];
1037
1038 nl_combi = nla_nest_start(msg, i + 1);
1039 if (!nl_combi)
1040 goto nla_put_failure;
1041
1042 nl_limits = nla_nest_start(msg, NL80211_IFACE_COMB_LIMITS);
1043 if (!nl_limits)
1044 goto nla_put_failure;
1045
1046 for (j = 0; j < c->n_limits; j++) {
1047 struct nlattr *nl_limit;
1048
1049 nl_limit = nla_nest_start(msg, j + 1);
1050 if (!nl_limit)
1051 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04001052 if (nla_put_u32(msg, NL80211_IFACE_LIMIT_MAX,
1053 c->limits[j].max))
1054 goto nla_put_failure;
Johannes Berg7527a782011-05-13 10:58:57 +02001055 if (nl80211_put_iftypes(msg, NL80211_IFACE_LIMIT_TYPES,
1056 c->limits[j].types))
1057 goto nla_put_failure;
1058 nla_nest_end(msg, nl_limit);
1059 }
1060
1061 nla_nest_end(msg, nl_limits);
1062
David S. Miller9360ffd2012-03-29 04:41:26 -04001063 if (c->beacon_int_infra_match &&
1064 nla_put_flag(msg, NL80211_IFACE_COMB_STA_AP_BI_MATCH))
1065 goto nla_put_failure;
1066 if (nla_put_u32(msg, NL80211_IFACE_COMB_NUM_CHANNELS,
1067 c->num_different_channels) ||
1068 nla_put_u32(msg, NL80211_IFACE_COMB_MAXNUM,
1069 c->max_interfaces))
1070 goto nla_put_failure;
Johannes Bergcdc89b92013-02-18 23:54:36 +01001071 if (large &&
Felix Fietkau8c48b502014-05-05 11:48:40 +02001072 (nla_put_u32(msg, NL80211_IFACE_COMB_RADAR_DETECT_WIDTHS,
1073 c->radar_detect_widths) ||
1074 nla_put_u32(msg, NL80211_IFACE_COMB_RADAR_DETECT_REGIONS,
1075 c->radar_detect_regions)))
Johannes Bergcdc89b92013-02-18 23:54:36 +01001076 goto nla_put_failure;
Purushottam Kushwaha0c317a02016-10-12 18:26:51 +05301077 if (c->beacon_int_min_gcd &&
1078 nla_put_u32(msg, NL80211_IFACE_COMB_BI_MIN_GCD,
1079 c->beacon_int_min_gcd))
1080 goto nla_put_failure;
Johannes Berg7527a782011-05-13 10:58:57 +02001081
1082 nla_nest_end(msg, nl_combi);
1083 }
1084
1085 nla_nest_end(msg, nl_combis);
1086
1087 return 0;
1088nla_put_failure:
1089 return -ENOBUFS;
1090}
1091
Johannes Berg3713b4e2013-02-14 16:19:38 +01001092#ifdef CONFIG_PM
Johannes Bergb56cf722013-02-20 01:02:38 +01001093static int nl80211_send_wowlan_tcp_caps(struct cfg80211_registered_device *rdev,
1094 struct sk_buff *msg)
1095{
Johannes Berg964dc9e2013-06-03 17:25:34 +02001096 const struct wiphy_wowlan_tcp_support *tcp = rdev->wiphy.wowlan->tcp;
Johannes Bergb56cf722013-02-20 01:02:38 +01001097 struct nlattr *nl_tcp;
1098
1099 if (!tcp)
1100 return 0;
1101
1102 nl_tcp = nla_nest_start(msg, NL80211_WOWLAN_TRIG_TCP_CONNECTION);
1103 if (!nl_tcp)
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 (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD,
1111 tcp->data_payload_max))
1112 return -ENOBUFS;
1113
1114 if (tcp->seq && nla_put_flag(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ))
1115 return -ENOBUFS;
1116
1117 if (tcp->tok && nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN,
1118 sizeof(*tcp->tok), tcp->tok))
1119 return -ENOBUFS;
1120
1121 if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_INTERVAL,
1122 tcp->data_interval_max))
1123 return -ENOBUFS;
1124
1125 if (nla_put_u32(msg, NL80211_WOWLAN_TCP_WAKE_PAYLOAD,
1126 tcp->wake_payload_max))
1127 return -ENOBUFS;
1128
1129 nla_nest_end(msg, nl_tcp);
1130 return 0;
1131}
1132
Johannes Berg3713b4e2013-02-14 16:19:38 +01001133static int nl80211_send_wowlan(struct sk_buff *msg,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001134 struct cfg80211_registered_device *rdev,
Johannes Bergb56cf722013-02-20 01:02:38 +01001135 bool large)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001136{
1137 struct nlattr *nl_wowlan;
1138
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001139 if (!rdev->wiphy.wowlan)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001140 return 0;
1141
1142 nl_wowlan = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS_SUPPORTED);
1143 if (!nl_wowlan)
1144 return -ENOBUFS;
1145
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001146 if (((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_ANY) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001147 nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) ||
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001148 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_DISCONNECT) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001149 nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) ||
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001150 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001151 nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) ||
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001152 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_SUPPORTS_GTK_REKEY) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001153 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED)) ||
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001154 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001155 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) ||
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001156 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001157 nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) ||
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001158 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001159 nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) ||
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001160 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001161 nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE)))
1162 return -ENOBUFS;
1163
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001164 if (rdev->wiphy.wowlan->n_patterns) {
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07001165 struct nl80211_pattern_support pat = {
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001166 .max_patterns = rdev->wiphy.wowlan->n_patterns,
1167 .min_pattern_len = rdev->wiphy.wowlan->pattern_min_len,
1168 .max_pattern_len = rdev->wiphy.wowlan->pattern_max_len,
1169 .max_pkt_offset = rdev->wiphy.wowlan->max_pkt_offset,
Johannes Berg3713b4e2013-02-14 16:19:38 +01001170 };
1171
1172 if (nla_put(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN,
1173 sizeof(pat), &pat))
1174 return -ENOBUFS;
1175 }
1176
Luciano Coelho75453cc2015-01-09 14:06:37 +02001177 if ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_NET_DETECT) &&
1178 nla_put_u32(msg, NL80211_WOWLAN_TRIG_NET_DETECT,
1179 rdev->wiphy.wowlan->max_nd_match_sets))
1180 return -ENOBUFS;
1181
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001182 if (large && nl80211_send_wowlan_tcp_caps(rdev, msg))
Johannes Bergb56cf722013-02-20 01:02:38 +01001183 return -ENOBUFS;
1184
Johannes Berg3713b4e2013-02-14 16:19:38 +01001185 nla_nest_end(msg, nl_wowlan);
1186
1187 return 0;
1188}
1189#endif
1190
Amitkumar Karwarbe29b99a2013-06-28 11:51:26 -07001191static int nl80211_send_coalesce(struct sk_buff *msg,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001192 struct cfg80211_registered_device *rdev)
Amitkumar Karwarbe29b99a2013-06-28 11:51:26 -07001193{
1194 struct nl80211_coalesce_rule_support rule;
1195
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001196 if (!rdev->wiphy.coalesce)
Amitkumar Karwarbe29b99a2013-06-28 11:51:26 -07001197 return 0;
1198
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001199 rule.max_rules = rdev->wiphy.coalesce->n_rules;
1200 rule.max_delay = rdev->wiphy.coalesce->max_delay;
1201 rule.pat.max_patterns = rdev->wiphy.coalesce->n_patterns;
1202 rule.pat.min_pattern_len = rdev->wiphy.coalesce->pattern_min_len;
1203 rule.pat.max_pattern_len = rdev->wiphy.coalesce->pattern_max_len;
1204 rule.pat.max_pkt_offset = rdev->wiphy.coalesce->max_pkt_offset;
Amitkumar Karwarbe29b99a2013-06-28 11:51:26 -07001205
1206 if (nla_put(msg, NL80211_ATTR_COALESCE_RULE, sizeof(rule), &rule))
1207 return -ENOBUFS;
1208
1209 return 0;
1210}
1211
Johannes Berg3713b4e2013-02-14 16:19:38 +01001212static int nl80211_send_band_rateinfo(struct sk_buff *msg,
1213 struct ieee80211_supported_band *sband)
1214{
1215 struct nlattr *nl_rates, *nl_rate;
1216 struct ieee80211_rate *rate;
1217 int i;
1218
1219 /* add HT info */
1220 if (sband->ht_cap.ht_supported &&
1221 (nla_put(msg, NL80211_BAND_ATTR_HT_MCS_SET,
1222 sizeof(sband->ht_cap.mcs),
1223 &sband->ht_cap.mcs) ||
1224 nla_put_u16(msg, NL80211_BAND_ATTR_HT_CAPA,
1225 sband->ht_cap.cap) ||
1226 nla_put_u8(msg, NL80211_BAND_ATTR_HT_AMPDU_FACTOR,
1227 sband->ht_cap.ampdu_factor) ||
1228 nla_put_u8(msg, NL80211_BAND_ATTR_HT_AMPDU_DENSITY,
1229 sband->ht_cap.ampdu_density)))
1230 return -ENOBUFS;
1231
1232 /* add VHT info */
1233 if (sband->vht_cap.vht_supported &&
1234 (nla_put(msg, NL80211_BAND_ATTR_VHT_MCS_SET,
1235 sizeof(sband->vht_cap.vht_mcs),
1236 &sband->vht_cap.vht_mcs) ||
1237 nla_put_u32(msg, NL80211_BAND_ATTR_VHT_CAPA,
1238 sband->vht_cap.cap)))
1239 return -ENOBUFS;
1240
1241 /* add bitrates */
1242 nl_rates = nla_nest_start(msg, NL80211_BAND_ATTR_RATES);
1243 if (!nl_rates)
1244 return -ENOBUFS;
1245
1246 for (i = 0; i < sband->n_bitrates; i++) {
1247 nl_rate = nla_nest_start(msg, i);
1248 if (!nl_rate)
1249 return -ENOBUFS;
1250
1251 rate = &sband->bitrates[i];
1252 if (nla_put_u32(msg, NL80211_BITRATE_ATTR_RATE,
1253 rate->bitrate))
1254 return -ENOBUFS;
1255 if ((rate->flags & IEEE80211_RATE_SHORT_PREAMBLE) &&
1256 nla_put_flag(msg,
1257 NL80211_BITRATE_ATTR_2GHZ_SHORTPREAMBLE))
1258 return -ENOBUFS;
1259
1260 nla_nest_end(msg, nl_rate);
1261 }
1262
1263 nla_nest_end(msg, nl_rates);
1264
1265 return 0;
1266}
1267
1268static int
1269nl80211_send_mgmt_stypes(struct sk_buff *msg,
1270 const struct ieee80211_txrx_stypes *mgmt_stypes)
1271{
1272 u16 stypes;
1273 struct nlattr *nl_ftypes, *nl_ifs;
1274 enum nl80211_iftype ift;
1275 int i;
1276
1277 if (!mgmt_stypes)
1278 return 0;
1279
1280 nl_ifs = nla_nest_start(msg, NL80211_ATTR_TX_FRAME_TYPES);
1281 if (!nl_ifs)
1282 return -ENOBUFS;
1283
1284 for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) {
1285 nl_ftypes = nla_nest_start(msg, ift);
1286 if (!nl_ftypes)
1287 return -ENOBUFS;
1288 i = 0;
1289 stypes = mgmt_stypes[ift].tx;
1290 while (stypes) {
1291 if ((stypes & 1) &&
1292 nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE,
1293 (i << 4) | IEEE80211_FTYPE_MGMT))
1294 return -ENOBUFS;
1295 stypes >>= 1;
1296 i++;
1297 }
1298 nla_nest_end(msg, nl_ftypes);
1299 }
1300
1301 nla_nest_end(msg, nl_ifs);
1302
1303 nl_ifs = nla_nest_start(msg, NL80211_ATTR_RX_FRAME_TYPES);
1304 if (!nl_ifs)
1305 return -ENOBUFS;
1306
1307 for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) {
1308 nl_ftypes = nla_nest_start(msg, ift);
1309 if (!nl_ftypes)
1310 return -ENOBUFS;
1311 i = 0;
1312 stypes = mgmt_stypes[ift].rx;
1313 while (stypes) {
1314 if ((stypes & 1) &&
1315 nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE,
1316 (i << 4) | IEEE80211_FTYPE_MGMT))
1317 return -ENOBUFS;
1318 stypes >>= 1;
1319 i++;
1320 }
1321 nla_nest_end(msg, nl_ftypes);
1322 }
1323 nla_nest_end(msg, nl_ifs);
1324
1325 return 0;
1326}
1327
Johannes Berg17948992016-10-26 11:42:04 +02001328#define CMD(op, n) \
1329 do { \
1330 if (rdev->ops->op) { \
1331 i++; \
1332 if (nla_put_u32(msg, i, NL80211_CMD_ ## n)) \
1333 goto nla_put_failure; \
1334 } \
1335 } while (0)
1336
1337static int nl80211_add_commands_unsplit(struct cfg80211_registered_device *rdev,
1338 struct sk_buff *msg)
1339{
1340 int i = 0;
1341
1342 /*
1343 * do *NOT* add anything into this function, new things need to be
1344 * advertised only to new versions of userspace that can deal with
1345 * the split (and they can't possibly care about new features...
1346 */
1347 CMD(add_virtual_intf, NEW_INTERFACE);
1348 CMD(change_virtual_intf, SET_INTERFACE);
1349 CMD(add_key, NEW_KEY);
1350 CMD(start_ap, START_AP);
1351 CMD(add_station, NEW_STATION);
1352 CMD(add_mpath, NEW_MPATH);
1353 CMD(update_mesh_config, SET_MESH_CONFIG);
1354 CMD(change_bss, SET_BSS);
1355 CMD(auth, AUTHENTICATE);
1356 CMD(assoc, ASSOCIATE);
1357 CMD(deauth, DEAUTHENTICATE);
1358 CMD(disassoc, DISASSOCIATE);
1359 CMD(join_ibss, JOIN_IBSS);
1360 CMD(join_mesh, JOIN_MESH);
1361 CMD(set_pmksa, SET_PMKSA);
1362 CMD(del_pmksa, DEL_PMKSA);
1363 CMD(flush_pmksa, FLUSH_PMKSA);
1364 if (rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL)
1365 CMD(remain_on_channel, REMAIN_ON_CHANNEL);
1366 CMD(set_bitrate_mask, SET_TX_BITRATE_MASK);
1367 CMD(mgmt_tx, FRAME);
1368 CMD(mgmt_tx_cancel_wait, FRAME_WAIT_CANCEL);
1369 if (rdev->wiphy.flags & WIPHY_FLAG_NETNS_OK) {
1370 i++;
1371 if (nla_put_u32(msg, i, NL80211_CMD_SET_WIPHY_NETNS))
1372 goto nla_put_failure;
1373 }
1374 if (rdev->ops->set_monitor_channel || rdev->ops->start_ap ||
1375 rdev->ops->join_mesh) {
1376 i++;
1377 if (nla_put_u32(msg, i, NL80211_CMD_SET_CHANNEL))
1378 goto nla_put_failure;
1379 }
1380 CMD(set_wds_peer, SET_WDS_PEER);
1381 if (rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) {
1382 CMD(tdls_mgmt, TDLS_MGMT);
1383 CMD(tdls_oper, TDLS_OPER);
1384 }
1385 if (rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN)
1386 CMD(sched_scan_start, START_SCHED_SCAN);
1387 CMD(probe_client, PROBE_CLIENT);
1388 CMD(set_noack_map, SET_NOACK_MAP);
1389 if (rdev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS) {
1390 i++;
1391 if (nla_put_u32(msg, i, NL80211_CMD_REGISTER_BEACONS))
1392 goto nla_put_failure;
1393 }
1394 CMD(start_p2p_device, START_P2P_DEVICE);
1395 CMD(set_mcast_rate, SET_MCAST_RATE);
1396#ifdef CONFIG_NL80211_TESTMODE
1397 CMD(testmode_cmd, TESTMODE);
1398#endif
1399
1400 if (rdev->ops->connect || rdev->ops->auth) {
1401 i++;
1402 if (nla_put_u32(msg, i, NL80211_CMD_CONNECT))
1403 goto nla_put_failure;
1404 }
1405
1406 if (rdev->ops->disconnect || rdev->ops->deauth) {
1407 i++;
1408 if (nla_put_u32(msg, i, NL80211_CMD_DISCONNECT))
1409 goto nla_put_failure;
1410 }
1411
1412 return i;
1413 nla_put_failure:
1414 return -ENOBUFS;
1415}
1416
Johannes Berg86e8cf92013-06-19 10:57:22 +02001417struct nl80211_dump_wiphy_state {
1418 s64 filter_wiphy;
1419 long start;
Kanchanapally, Vidyullatha019ae3a2016-05-16 10:41:04 +05301420 long split_start, band_start, chan_start, capa_start;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001421 bool split;
1422};
1423
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001424static int nl80211_send_wiphy(struct cfg80211_registered_device *rdev,
Johannes Berg3bb20552014-05-26 13:52:25 +02001425 enum nl80211_commands cmd,
Johannes Berg3713b4e2013-02-14 16:19:38 +01001426 struct sk_buff *msg, u32 portid, u32 seq,
Johannes Berg86e8cf92013-06-19 10:57:22 +02001427 int flags, struct nl80211_dump_wiphy_state *state)
Johannes Berg55682962007-09-20 13:09:35 -04001428{
1429 void *hdr;
Johannes Bergee688b002008-01-24 19:38:39 +01001430 struct nlattr *nl_bands, *nl_band;
1431 struct nlattr *nl_freqs, *nl_freq;
Johannes Berg8fdc6212009-03-14 09:34:01 +01001432 struct nlattr *nl_cmds;
Johannes Berg57fbcce2016-04-12 15:56:15 +02001433 enum nl80211_band band;
Johannes Bergee688b002008-01-24 19:38:39 +01001434 struct ieee80211_channel *chan;
Johannes Bergee688b002008-01-24 19:38:39 +01001435 int i;
Johannes Berg2e161f72010-08-12 15:38:38 +02001436 const struct ieee80211_txrx_stypes *mgmt_stypes =
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001437 rdev->wiphy.mgmt_stypes;
Johannes Bergfe1abaf2013-02-27 15:39:45 +01001438 u32 features;
Johannes Berg55682962007-09-20 13:09:35 -04001439
Johannes Berg3bb20552014-05-26 13:52:25 +02001440 hdr = nl80211hdr_put(msg, portid, seq, flags, cmd);
Johannes Berg55682962007-09-20 13:09:35 -04001441 if (!hdr)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001442 return -ENOBUFS;
1443
Johannes Berg86e8cf92013-06-19 10:57:22 +02001444 if (WARN_ON(!state))
1445 return -EINVAL;
Johannes Berg55682962007-09-20 13:09:35 -04001446
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001447 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001448 nla_put_string(msg, NL80211_ATTR_WIPHY_NAME,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001449 wiphy_name(&rdev->wiphy)) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04001450 nla_put_u32(msg, NL80211_ATTR_GENERATION,
Johannes Berg3713b4e2013-02-14 16:19:38 +01001451 cfg80211_rdev_list_generation))
David S. Miller9360ffd2012-03-29 04:41:26 -04001452 goto nla_put_failure;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02001453
Johannes Berg3bb20552014-05-26 13:52:25 +02001454 if (cmd != NL80211_CMD_NEW_WIPHY)
1455 goto finish;
1456
Johannes Berg86e8cf92013-06-19 10:57:22 +02001457 switch (state->split_start) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001458 case 0:
1459 if (nla_put_u8(msg, NL80211_ATTR_WIPHY_RETRY_SHORT,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001460 rdev->wiphy.retry_short) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001461 nla_put_u8(msg, NL80211_ATTR_WIPHY_RETRY_LONG,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001462 rdev->wiphy.retry_long) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001463 nla_put_u32(msg, NL80211_ATTR_WIPHY_FRAG_THRESHOLD,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001464 rdev->wiphy.frag_threshold) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001465 nla_put_u32(msg, NL80211_ATTR_WIPHY_RTS_THRESHOLD,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001466 rdev->wiphy.rts_threshold) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001467 nla_put_u8(msg, NL80211_ATTR_WIPHY_COVERAGE_CLASS,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001468 rdev->wiphy.coverage_class) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001469 nla_put_u8(msg, NL80211_ATTR_MAX_NUM_SCAN_SSIDS,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001470 rdev->wiphy.max_scan_ssids) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001471 nla_put_u8(msg, NL80211_ATTR_MAX_NUM_SCHED_SCAN_SSIDS,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001472 rdev->wiphy.max_sched_scan_ssids) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001473 nla_put_u16(msg, NL80211_ATTR_MAX_SCAN_IE_LEN,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001474 rdev->wiphy.max_scan_ie_len) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001475 nla_put_u16(msg, NL80211_ATTR_MAX_SCHED_SCAN_IE_LEN,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001476 rdev->wiphy.max_sched_scan_ie_len) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001477 nla_put_u8(msg, NL80211_ATTR_MAX_MATCH_SETS,
Avraham Stern3b06d272015-10-12 09:51:34 +03001478 rdev->wiphy.max_match_sets) ||
1479 nla_put_u32(msg, NL80211_ATTR_MAX_NUM_SCHED_SCAN_PLANS,
1480 rdev->wiphy.max_sched_scan_plans) ||
1481 nla_put_u32(msg, NL80211_ATTR_MAX_SCAN_PLAN_INTERVAL,
1482 rdev->wiphy.max_sched_scan_plan_interval) ||
1483 nla_put_u32(msg, NL80211_ATTR_MAX_SCAN_PLAN_ITERATIONS,
1484 rdev->wiphy.max_sched_scan_plan_iterations))
Johannes Bergee688b002008-01-24 19:38:39 +01001485 goto nla_put_failure;
1486
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001487 if ((rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001488 nla_put_flag(msg, NL80211_ATTR_SUPPORT_IBSS_RSN))
1489 goto nla_put_failure;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001490 if ((rdev->wiphy.flags & WIPHY_FLAG_MESH_AUTH) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001491 nla_put_flag(msg, NL80211_ATTR_SUPPORT_MESH_AUTH))
1492 goto nla_put_failure;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001493 if ((rdev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001494 nla_put_flag(msg, NL80211_ATTR_SUPPORT_AP_UAPSD))
1495 goto nla_put_failure;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001496 if ((rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_FW_ROAM) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001497 nla_put_flag(msg, NL80211_ATTR_ROAM_SUPPORT))
1498 goto nla_put_failure;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001499 if ((rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001500 nla_put_flag(msg, NL80211_ATTR_TDLS_SUPPORT))
1501 goto nla_put_failure;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001502 if ((rdev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001503 nla_put_flag(msg, NL80211_ATTR_TDLS_EXTERNAL_SETUP))
David S. Miller9360ffd2012-03-29 04:41:26 -04001504 goto nla_put_failure;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001505 state->split_start++;
1506 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001507 break;
1508 case 1:
1509 if (nla_put(msg, NL80211_ATTR_CIPHER_SUITES,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001510 sizeof(u32) * rdev->wiphy.n_cipher_suites,
1511 rdev->wiphy.cipher_suites))
Mahesh Palivelabf0c111e2012-06-22 07:27:46 +00001512 goto nla_put_failure;
1513
Johannes Berg3713b4e2013-02-14 16:19:38 +01001514 if (nla_put_u8(msg, NL80211_ATTR_MAX_NUM_PMKIDS,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001515 rdev->wiphy.max_num_pmkids))
Johannes Bergee688b002008-01-24 19:38:39 +01001516 goto nla_put_failure;
1517
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001518 if ((rdev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001519 nla_put_flag(msg, NL80211_ATTR_CONTROL_PORT_ETHERTYPE))
1520 goto nla_put_failure;
Johannes Bergee688b002008-01-24 19:38:39 +01001521
Johannes Berg3713b4e2013-02-14 16:19:38 +01001522 if (nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_TX,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001523 rdev->wiphy.available_antennas_tx) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001524 nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_RX,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001525 rdev->wiphy.available_antennas_rx))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001526 goto nla_put_failure;
Johannes Bergee688b002008-01-24 19:38:39 +01001527
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001528 if ((rdev->wiphy.flags & WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001529 nla_put_u32(msg, NL80211_ATTR_PROBE_RESP_OFFLOAD,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001530 rdev->wiphy.probe_resp_offload))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001531 goto nla_put_failure;
Jouni Malinene2f367f262008-11-21 19:01:30 +02001532
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001533 if ((rdev->wiphy.available_antennas_tx ||
1534 rdev->wiphy.available_antennas_rx) &&
1535 rdev->ops->get_antenna) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001536 u32 tx_ant = 0, rx_ant = 0;
1537 int res;
Kirtika Ruchandani7a087e72016-05-29 19:51:23 -07001538
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001539 res = rdev_get_antenna(rdev, &tx_ant, &rx_ant);
Johannes Berg3713b4e2013-02-14 16:19:38 +01001540 if (!res) {
1541 if (nla_put_u32(msg,
1542 NL80211_ATTR_WIPHY_ANTENNA_TX,
1543 tx_ant) ||
1544 nla_put_u32(msg,
1545 NL80211_ATTR_WIPHY_ANTENNA_RX,
1546 rx_ant))
1547 goto nla_put_failure;
1548 }
Johannes Bergee688b002008-01-24 19:38:39 +01001549 }
1550
Johannes Berg86e8cf92013-06-19 10:57:22 +02001551 state->split_start++;
1552 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001553 break;
1554 case 2:
1555 if (nl80211_put_iftypes(msg, NL80211_ATTR_SUPPORTED_IFTYPES,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001556 rdev->wiphy.interface_modes))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001557 goto nla_put_failure;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001558 state->split_start++;
1559 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001560 break;
1561 case 3:
1562 nl_bands = nla_nest_start(msg, NL80211_ATTR_WIPHY_BANDS);
1563 if (!nl_bands)
Johannes Bergee688b002008-01-24 19:38:39 +01001564 goto nla_put_failure;
1565
Johannes Berg86e8cf92013-06-19 10:57:22 +02001566 for (band = state->band_start;
Johannes Berg57fbcce2016-04-12 15:56:15 +02001567 band < NUM_NL80211_BANDS; band++) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001568 struct ieee80211_supported_band *sband;
1569
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001570 sband = rdev->wiphy.bands[band];
Johannes Berg3713b4e2013-02-14 16:19:38 +01001571
1572 if (!sband)
1573 continue;
1574
1575 nl_band = nla_nest_start(msg, band);
1576 if (!nl_band)
Johannes Bergee688b002008-01-24 19:38:39 +01001577 goto nla_put_failure;
1578
Johannes Berg86e8cf92013-06-19 10:57:22 +02001579 switch (state->chan_start) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001580 case 0:
1581 if (nl80211_send_band_rateinfo(msg, sband))
1582 goto nla_put_failure;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001583 state->chan_start++;
1584 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001585 break;
1586 default:
1587 /* add frequencies */
1588 nl_freqs = nla_nest_start(
1589 msg, NL80211_BAND_ATTR_FREQS);
1590 if (!nl_freqs)
1591 goto nla_put_failure;
Johannes Bergee688b002008-01-24 19:38:39 +01001592
Johannes Berg86e8cf92013-06-19 10:57:22 +02001593 for (i = state->chan_start - 1;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001594 i < sband->n_channels;
1595 i++) {
1596 nl_freq = nla_nest_start(msg, i);
1597 if (!nl_freq)
1598 goto nla_put_failure;
1599
1600 chan = &sband->channels[i];
1601
Johannes Berg86e8cf92013-06-19 10:57:22 +02001602 if (nl80211_msg_put_channel(
1603 msg, chan,
1604 state->split))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001605 goto nla_put_failure;
1606
1607 nla_nest_end(msg, nl_freq);
Johannes Berg86e8cf92013-06-19 10:57:22 +02001608 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001609 break;
1610 }
1611 if (i < sband->n_channels)
Johannes Berg86e8cf92013-06-19 10:57:22 +02001612 state->chan_start = i + 2;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001613 else
Johannes Berg86e8cf92013-06-19 10:57:22 +02001614 state->chan_start = 0;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001615 nla_nest_end(msg, nl_freqs);
1616 }
1617
1618 nla_nest_end(msg, nl_band);
1619
Johannes Berg86e8cf92013-06-19 10:57:22 +02001620 if (state->split) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001621 /* start again here */
Johannes Berg86e8cf92013-06-19 10:57:22 +02001622 if (state->chan_start)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001623 band--;
1624 break;
1625 }
Johannes Bergee688b002008-01-24 19:38:39 +01001626 }
Johannes Berg3713b4e2013-02-14 16:19:38 +01001627 nla_nest_end(msg, nl_bands);
Johannes Bergee688b002008-01-24 19:38:39 +01001628
Johannes Berg57fbcce2016-04-12 15:56:15 +02001629 if (band < NUM_NL80211_BANDS)
Johannes Berg86e8cf92013-06-19 10:57:22 +02001630 state->band_start = band + 1;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001631 else
Johannes Berg86e8cf92013-06-19 10:57:22 +02001632 state->band_start = 0;
Johannes Bergee688b002008-01-24 19:38:39 +01001633
Johannes Berg3713b4e2013-02-14 16:19:38 +01001634 /* if bands & channels are done, continue outside */
Johannes Berg86e8cf92013-06-19 10:57:22 +02001635 if (state->band_start == 0 && state->chan_start == 0)
1636 state->split_start++;
1637 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001638 break;
1639 case 4:
1640 nl_cmds = nla_nest_start(msg, NL80211_ATTR_SUPPORTED_COMMANDS);
1641 if (!nl_cmds)
David S. Miller9360ffd2012-03-29 04:41:26 -04001642 goto nla_put_failure;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001643
Johannes Berg17948992016-10-26 11:42:04 +02001644 i = nl80211_add_commands_unsplit(rdev, msg);
1645 if (i < 0)
1646 goto nla_put_failure;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001647 if (state->split) {
Arend van Spriel5de17982013-04-18 15:49:00 +02001648 CMD(crit_proto_start, CRIT_PROTOCOL_START);
1649 CMD(crit_proto_stop, CRIT_PROTOCOL_STOP);
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001650 if (rdev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH)
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02001651 CMD(channel_switch, CHANNEL_SWITCH);
Johannes Berg02df00e2014-06-10 14:06:25 +02001652 CMD(set_qos_map, SET_QOS_MAP);
Johannes Berg723e73a2014-10-22 09:25:06 +02001653 if (rdev->wiphy.features &
1654 NL80211_FEATURE_SUPPORTS_WMM_ADMISSION)
Johannes Berg960d01a2014-09-09 22:55:35 +03001655 CMD(add_tx_ts, ADD_TX_TS);
Michael Braunce0ce132016-10-10 19:12:22 +02001656 CMD(set_multicast_to_unicast, SET_MULTICAST_TO_UNICAST);
vamsi krishna088e8df2016-10-27 16:51:11 +03001657 CMD(update_connect_params, UPDATE_CONNECT_PARAMS);
Arend van Spriel5de17982013-04-18 15:49:00 +02001658 }
Johannes Berg8fdc6212009-03-14 09:34:01 +01001659#undef CMD
Samuel Ortizb23aa672009-07-01 21:26:54 +02001660
Johannes Berg3713b4e2013-02-14 16:19:38 +01001661 nla_nest_end(msg, nl_cmds);
Johannes Berg86e8cf92013-06-19 10:57:22 +02001662 state->split_start++;
1663 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001664 break;
1665 case 5:
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001666 if (rdev->ops->remain_on_channel &&
1667 (rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001668 nla_put_u32(msg,
1669 NL80211_ATTR_MAX_REMAIN_ON_CHANNEL_DURATION,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001670 rdev->wiphy.max_remain_on_channel_duration))
Johannes Berg2e161f72010-08-12 15:38:38 +02001671 goto nla_put_failure;
1672
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001673 if ((rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001674 nla_put_flag(msg, NL80211_ATTR_OFFCHANNEL_TX_OK))
1675 goto nla_put_failure;
Johannes Berg2e161f72010-08-12 15:38:38 +02001676
Johannes Berg3713b4e2013-02-14 16:19:38 +01001677 if (nl80211_send_mgmt_stypes(msg, mgmt_stypes))
1678 goto nla_put_failure;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001679 state->split_start++;
1680 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001681 break;
1682 case 6:
Johannes Bergdfb89c52012-06-27 09:23:48 +02001683#ifdef CONFIG_PM
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001684 if (nl80211_send_wowlan(msg, rdev, state->split))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001685 goto nla_put_failure;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001686 state->split_start++;
1687 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001688 break;
1689#else
Johannes Berg86e8cf92013-06-19 10:57:22 +02001690 state->split_start++;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001691#endif
1692 case 7:
1693 if (nl80211_put_iftypes(msg, NL80211_ATTR_SOFTWARE_IFTYPES,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001694 rdev->wiphy.software_iftypes))
Johannes Bergff1b6e62011-05-04 15:37:28 +02001695 goto nla_put_failure;
1696
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001697 if (nl80211_put_iface_combinations(&rdev->wiphy, msg,
Johannes Berg86e8cf92013-06-19 10:57:22 +02001698 state->split))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001699 goto nla_put_failure;
Johannes Bergff1b6e62011-05-04 15:37:28 +02001700
Johannes Berg86e8cf92013-06-19 10:57:22 +02001701 state->split_start++;
1702 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001703 break;
1704 case 8:
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001705 if ((rdev->wiphy.flags & WIPHY_FLAG_HAVE_AP_SME) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001706 nla_put_u32(msg, NL80211_ATTR_DEVICE_AP_SME,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001707 rdev->wiphy.ap_sme_capa))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001708 goto nla_put_failure;
1709
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001710 features = rdev->wiphy.features;
Johannes Bergfe1abaf2013-02-27 15:39:45 +01001711 /*
1712 * We can only add the per-channel limit information if the
1713 * dump is split, otherwise it makes it too big. Therefore
1714 * only advertise it in that case.
1715 */
Johannes Berg86e8cf92013-06-19 10:57:22 +02001716 if (state->split)
Johannes Bergfe1abaf2013-02-27 15:39:45 +01001717 features |= NL80211_FEATURE_ADVERTISE_CHAN_LIMITS;
1718 if (nla_put_u32(msg, NL80211_ATTR_FEATURE_FLAGS, features))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001719 goto nla_put_failure;
1720
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001721 if (rdev->wiphy.ht_capa_mod_mask &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001722 nla_put(msg, NL80211_ATTR_HT_CAPABILITY_MASK,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001723 sizeof(*rdev->wiphy.ht_capa_mod_mask),
1724 rdev->wiphy.ht_capa_mod_mask))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001725 goto nla_put_failure;
1726
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001727 if (rdev->wiphy.flags & WIPHY_FLAG_HAVE_AP_SME &&
1728 rdev->wiphy.max_acl_mac_addrs &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001729 nla_put_u32(msg, NL80211_ATTR_MAC_ACL_MAX,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001730 rdev->wiphy.max_acl_mac_addrs))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001731 goto nla_put_failure;
1732
1733 /*
1734 * Any information below this point is only available to
1735 * applications that can deal with it being split. This
1736 * helps ensure that newly added capabilities don't break
1737 * older tools by overrunning their buffers.
1738 *
1739 * We still increment split_start so that in the split
1740 * case we'll continue with more data in the next round,
1741 * but break unconditionally so unsplit data stops here.
1742 */
Johannes Berg86e8cf92013-06-19 10:57:22 +02001743 state->split_start++;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001744 break;
1745 case 9:
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001746 if (rdev->wiphy.extended_capabilities &&
Johannes Bergfe1abaf2013-02-27 15:39:45 +01001747 (nla_put(msg, NL80211_ATTR_EXT_CAPA,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001748 rdev->wiphy.extended_capabilities_len,
1749 rdev->wiphy.extended_capabilities) ||
Johannes Bergfe1abaf2013-02-27 15:39:45 +01001750 nla_put(msg, NL80211_ATTR_EXT_CAPA_MASK,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001751 rdev->wiphy.extended_capabilities_len,
1752 rdev->wiphy.extended_capabilities_mask)))
Johannes Bergfe1abaf2013-02-27 15:39:45 +01001753 goto nla_put_failure;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001754
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001755 if (rdev->wiphy.vht_capa_mod_mask &&
Johannes Bergee2aca32013-02-21 17:36:01 +01001756 nla_put(msg, NL80211_ATTR_VHT_CAPABILITY_MASK,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001757 sizeof(*rdev->wiphy.vht_capa_mod_mask),
1758 rdev->wiphy.vht_capa_mod_mask))
Johannes Bergee2aca32013-02-21 17:36:01 +01001759 goto nla_put_failure;
1760
Amitkumar Karwarbe29b99a2013-06-28 11:51:26 -07001761 state->split_start++;
1762 break;
1763 case 10:
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001764 if (nl80211_send_coalesce(msg, rdev))
Amitkumar Karwarbe29b99a2013-06-28 11:51:26 -07001765 goto nla_put_failure;
1766
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001767 if ((rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_5_10_MHZ) &&
Felix Fietkau01e0daa2013-11-09 14:57:54 +01001768 (nla_put_flag(msg, NL80211_ATTR_SUPPORT_5_MHZ) ||
1769 nla_put_flag(msg, NL80211_ATTR_SUPPORT_10_MHZ)))
1770 goto nla_put_failure;
Jouni Malinenb43504c2014-01-15 00:01:08 +02001771
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001772 if (rdev->wiphy.max_ap_assoc_sta &&
Jouni Malinenb43504c2014-01-15 00:01:08 +02001773 nla_put_u32(msg, NL80211_ATTR_MAX_AP_ASSOC_STA,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001774 rdev->wiphy.max_ap_assoc_sta))
Jouni Malinenb43504c2014-01-15 00:01:08 +02001775 goto nla_put_failure;
1776
Johannes Bergad7e7182013-11-13 13:37:47 +01001777 state->split_start++;
1778 break;
1779 case 11:
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001780 if (rdev->wiphy.n_vendor_commands) {
Johannes Berg567ffc32013-12-18 14:43:31 +01001781 const struct nl80211_vendor_cmd_info *info;
1782 struct nlattr *nested;
Johannes Bergad7e7182013-11-13 13:37:47 +01001783
Johannes Berg567ffc32013-12-18 14:43:31 +01001784 nested = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA);
1785 if (!nested)
Johannes Bergad7e7182013-11-13 13:37:47 +01001786 goto nla_put_failure;
Johannes Berg567ffc32013-12-18 14:43:31 +01001787
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001788 for (i = 0; i < rdev->wiphy.n_vendor_commands; i++) {
1789 info = &rdev->wiphy.vendor_commands[i].info;
Johannes Berg567ffc32013-12-18 14:43:31 +01001790 if (nla_put(msg, i + 1, sizeof(*info), info))
1791 goto nla_put_failure;
1792 }
1793 nla_nest_end(msg, nested);
1794 }
1795
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001796 if (rdev->wiphy.n_vendor_events) {
Johannes Berg567ffc32013-12-18 14:43:31 +01001797 const struct nl80211_vendor_cmd_info *info;
1798 struct nlattr *nested;
1799
1800 nested = nla_nest_start(msg,
1801 NL80211_ATTR_VENDOR_EVENTS);
1802 if (!nested)
1803 goto nla_put_failure;
1804
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001805 for (i = 0; i < rdev->wiphy.n_vendor_events; i++) {
1806 info = &rdev->wiphy.vendor_events[i];
Johannes Berg567ffc32013-12-18 14:43:31 +01001807 if (nla_put(msg, i + 1, sizeof(*info), info))
1808 goto nla_put_failure;
1809 }
1810 nla_nest_end(msg, nested);
1811 }
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03001812 state->split_start++;
1813 break;
1814 case 12:
1815 if (rdev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH &&
1816 nla_put_u8(msg, NL80211_ATTR_MAX_CSA_COUNTERS,
1817 rdev->wiphy.max_num_csa_counters))
1818 goto nla_put_failure;
Felix Fietkau01e0daa2013-11-09 14:57:54 +01001819
Arik Nemtsov1bdd7162014-12-15 19:26:01 +02001820 if (rdev->wiphy.regulatory_flags & REGULATORY_WIPHY_SELF_MANAGED &&
1821 nla_put_flag(msg, NL80211_ATTR_WIPHY_SELF_MANAGED_REG))
1822 goto nla_put_failure;
1823
Gautam Kumar Shuklad75bb062014-12-23 16:55:19 +01001824 if (nla_put(msg, NL80211_ATTR_EXT_FEATURES,
1825 sizeof(rdev->wiphy.ext_features),
1826 rdev->wiphy.ext_features))
1827 goto nla_put_failure;
1828
Arend van Spriel38de03d2016-03-02 20:37:18 +01001829 if (rdev->wiphy.bss_select_support) {
1830 struct nlattr *nested;
1831 u32 bss_select_support = rdev->wiphy.bss_select_support;
1832
1833 nested = nla_nest_start(msg, NL80211_ATTR_BSS_SELECT);
1834 if (!nested)
1835 goto nla_put_failure;
1836
1837 i = 0;
1838 while (bss_select_support) {
1839 if ((bss_select_support & 1) &&
1840 nla_put_flag(msg, i))
1841 goto nla_put_failure;
1842 i++;
1843 bss_select_support >>= 1;
1844 }
1845 nla_nest_end(msg, nested);
1846 }
1847
Kanchanapally, Vidyullatha019ae3a2016-05-16 10:41:04 +05301848 state->split_start++;
1849 break;
1850 case 13:
1851 if (rdev->wiphy.num_iftype_ext_capab &&
1852 rdev->wiphy.iftype_ext_capab) {
1853 struct nlattr *nested_ext_capab, *nested;
1854
1855 nested = nla_nest_start(msg,
1856 NL80211_ATTR_IFTYPE_EXT_CAPA);
1857 if (!nested)
1858 goto nla_put_failure;
1859
1860 for (i = state->capa_start;
1861 i < rdev->wiphy.num_iftype_ext_capab; i++) {
1862 const struct wiphy_iftype_ext_capab *capab;
1863
1864 capab = &rdev->wiphy.iftype_ext_capab[i];
1865
1866 nested_ext_capab = nla_nest_start(msg, i);
1867 if (!nested_ext_capab ||
1868 nla_put_u32(msg, NL80211_ATTR_IFTYPE,
1869 capab->iftype) ||
1870 nla_put(msg, NL80211_ATTR_EXT_CAPA,
1871 capab->extended_capabilities_len,
1872 capab->extended_capabilities) ||
1873 nla_put(msg, NL80211_ATTR_EXT_CAPA_MASK,
1874 capab->extended_capabilities_len,
1875 capab->extended_capabilities_mask))
1876 goto nla_put_failure;
1877
1878 nla_nest_end(msg, nested_ext_capab);
1879 if (state->split)
1880 break;
1881 }
1882 nla_nest_end(msg, nested);
1883 if (i < rdev->wiphy.num_iftype_ext_capab) {
1884 state->capa_start = i + 1;
1885 break;
1886 }
1887 }
1888
Luca Coelho85859892017-02-08 15:00:34 +02001889 if (nla_put_u32(msg, NL80211_ATTR_BANDS,
1890 rdev->wiphy.nan_supported_bands))
1891 goto nla_put_failure;
1892
Johannes Berg3713b4e2013-02-14 16:19:38 +01001893 /* done */
Johannes Berg86e8cf92013-06-19 10:57:22 +02001894 state->split_start = 0;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001895 break;
Johannes Bergff1b6e62011-05-04 15:37:28 +02001896 }
Johannes Berg3bb20552014-05-26 13:52:25 +02001897 finish:
Johannes Berg053c0952015-01-16 22:09:00 +01001898 genlmsg_end(msg, hdr);
1899 return 0;
Johannes Berg55682962007-09-20 13:09:35 -04001900
1901 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07001902 genlmsg_cancel(msg, hdr);
1903 return -EMSGSIZE;
Johannes Berg55682962007-09-20 13:09:35 -04001904}
1905
Johannes Berg86e8cf92013-06-19 10:57:22 +02001906static int nl80211_dump_wiphy_parse(struct sk_buff *skb,
1907 struct netlink_callback *cb,
1908 struct nl80211_dump_wiphy_state *state)
1909{
Johannes Bergc90c39d2016-10-24 14:40:01 +02001910 struct nlattr **tb = genl_family_attrbuf(&nl80211_fam);
Johannes Berg86e8cf92013-06-19 10:57:22 +02001911 int ret = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize,
1912 tb, nl80211_fam.maxattr, nl80211_policy);
1913 /* ignore parse errors for backward compatibility */
1914 if (ret)
1915 return 0;
1916
1917 state->split = tb[NL80211_ATTR_SPLIT_WIPHY_DUMP];
1918 if (tb[NL80211_ATTR_WIPHY])
1919 state->filter_wiphy = nla_get_u32(tb[NL80211_ATTR_WIPHY]);
1920 if (tb[NL80211_ATTR_WDEV])
1921 state->filter_wiphy = nla_get_u64(tb[NL80211_ATTR_WDEV]) >> 32;
1922 if (tb[NL80211_ATTR_IFINDEX]) {
1923 struct net_device *netdev;
1924 struct cfg80211_registered_device *rdev;
1925 int ifidx = nla_get_u32(tb[NL80211_ATTR_IFINDEX]);
1926
Ying Xue7f2b8562014-01-15 10:23:45 +08001927 netdev = __dev_get_by_index(sock_net(skb->sk), ifidx);
Johannes Berg86e8cf92013-06-19 10:57:22 +02001928 if (!netdev)
1929 return -ENODEV;
1930 if (netdev->ieee80211_ptr) {
Zhao, Gangf26cbf42014-04-21 12:53:03 +08001931 rdev = wiphy_to_rdev(
Johannes Berg86e8cf92013-06-19 10:57:22 +02001932 netdev->ieee80211_ptr->wiphy);
1933 state->filter_wiphy = rdev->wiphy_idx;
1934 }
Johannes Berg86e8cf92013-06-19 10:57:22 +02001935 }
1936
1937 return 0;
1938}
1939
Johannes Berg55682962007-09-20 13:09:35 -04001940static int nl80211_dump_wiphy(struct sk_buff *skb, struct netlink_callback *cb)
1941{
Johannes Berg645e77d2013-03-01 14:03:49 +01001942 int idx = 0, ret;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001943 struct nl80211_dump_wiphy_state *state = (void *)cb->args[0];
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001944 struct cfg80211_registered_device *rdev;
Johannes Berg3a5a4232013-06-19 10:09:57 +02001945
Johannes Berg5fe231e2013-05-08 21:45:15 +02001946 rtnl_lock();
Johannes Berg86e8cf92013-06-19 10:57:22 +02001947 if (!state) {
1948 state = kzalloc(sizeof(*state), GFP_KERNEL);
John W. Linville57ed5cd2013-06-28 13:18:21 -04001949 if (!state) {
1950 rtnl_unlock();
Johannes Berg86e8cf92013-06-19 10:57:22 +02001951 return -ENOMEM;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001952 }
Johannes Berg86e8cf92013-06-19 10:57:22 +02001953 state->filter_wiphy = -1;
1954 ret = nl80211_dump_wiphy_parse(skb, cb, state);
1955 if (ret) {
1956 kfree(state);
1957 rtnl_unlock();
1958 return ret;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001959 }
Johannes Berg86e8cf92013-06-19 10:57:22 +02001960 cb->args[0] = (long)state;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001961 }
1962
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001963 list_for_each_entry(rdev, &cfg80211_rdev_list, list) {
1964 if (!net_eq(wiphy_net(&rdev->wiphy), sock_net(skb->sk)))
Johannes Berg463d0182009-07-14 00:33:35 +02001965 continue;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001966 if (++idx <= state->start)
Johannes Berg55682962007-09-20 13:09:35 -04001967 continue;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001968 if (state->filter_wiphy != -1 &&
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001969 state->filter_wiphy != rdev->wiphy_idx)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001970 continue;
1971 /* attempt to fit multiple wiphy data chunks into the skb */
1972 do {
Johannes Berg3bb20552014-05-26 13:52:25 +02001973 ret = nl80211_send_wiphy(rdev, NL80211_CMD_NEW_WIPHY,
1974 skb,
Johannes Berg3713b4e2013-02-14 16:19:38 +01001975 NETLINK_CB(cb->skb).portid,
1976 cb->nlh->nlmsg_seq,
Johannes Berg86e8cf92013-06-19 10:57:22 +02001977 NLM_F_MULTI, state);
Johannes Berg3713b4e2013-02-14 16:19:38 +01001978 if (ret < 0) {
1979 /*
1980 * If sending the wiphy data didn't fit (ENOBUFS
1981 * or EMSGSIZE returned), this SKB is still
1982 * empty (so it's not too big because another
1983 * wiphy dataset is already in the skb) and
1984 * we've not tried to adjust the dump allocation
1985 * yet ... then adjust the alloc size to be
1986 * bigger, and return 1 but with the empty skb.
1987 * This results in an empty message being RX'ed
1988 * in userspace, but that is ignored.
1989 *
1990 * We can then retry with the larger buffer.
1991 */
1992 if ((ret == -ENOBUFS || ret == -EMSGSIZE) &&
Pontus Fuchsf12cb282014-01-16 15:00:40 +01001993 !skb->len && !state->split &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001994 cb->min_dump_alloc < 4096) {
1995 cb->min_dump_alloc = 4096;
Pontus Fuchsf12cb282014-01-16 15:00:40 +01001996 state->split_start = 0;
David S. Millerd98cae64e2013-06-19 16:49:39 -07001997 rtnl_unlock();
Johannes Berg3713b4e2013-02-14 16:19:38 +01001998 return 1;
1999 }
2000 idx--;
2001 break;
Johannes Berg645e77d2013-03-01 14:03:49 +01002002 }
Johannes Berg86e8cf92013-06-19 10:57:22 +02002003 } while (state->split_start > 0);
Johannes Berg3713b4e2013-02-14 16:19:38 +01002004 break;
Johannes Berg55682962007-09-20 13:09:35 -04002005 }
Johannes Berg5fe231e2013-05-08 21:45:15 +02002006 rtnl_unlock();
Johannes Berg55682962007-09-20 13:09:35 -04002007
Johannes Berg86e8cf92013-06-19 10:57:22 +02002008 state->start = idx;
Johannes Berg55682962007-09-20 13:09:35 -04002009
2010 return skb->len;
2011}
2012
Johannes Berg86e8cf92013-06-19 10:57:22 +02002013static int nl80211_dump_wiphy_done(struct netlink_callback *cb)
2014{
2015 kfree((void *)cb->args[0]);
2016 return 0;
2017}
2018
Johannes Berg55682962007-09-20 13:09:35 -04002019static int nl80211_get_wiphy(struct sk_buff *skb, struct genl_info *info)
2020{
2021 struct sk_buff *msg;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002022 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg86e8cf92013-06-19 10:57:22 +02002023 struct nl80211_dump_wiphy_state state = {};
Johannes Berg55682962007-09-20 13:09:35 -04002024
Johannes Berg645e77d2013-03-01 14:03:49 +01002025 msg = nlmsg_new(4096, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -04002026 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02002027 return -ENOMEM;
Johannes Berg55682962007-09-20 13:09:35 -04002028
Johannes Berg3bb20552014-05-26 13:52:25 +02002029 if (nl80211_send_wiphy(rdev, NL80211_CMD_NEW_WIPHY, msg,
2030 info->snd_portid, info->snd_seq, 0,
Johannes Berg86e8cf92013-06-19 10:57:22 +02002031 &state) < 0) {
Johannes Berg4c476992010-10-04 21:36:35 +02002032 nlmsg_free(msg);
2033 return -ENOBUFS;
2034 }
Johannes Berg55682962007-09-20 13:09:35 -04002035
Johannes Berg134e6372009-07-10 09:51:34 +00002036 return genlmsg_reply(msg, info);
Johannes Berg55682962007-09-20 13:09:35 -04002037}
2038
Jouni Malinen31888482008-10-30 16:59:24 +02002039static const struct nla_policy txq_params_policy[NL80211_TXQ_ATTR_MAX + 1] = {
2040 [NL80211_TXQ_ATTR_QUEUE] = { .type = NLA_U8 },
2041 [NL80211_TXQ_ATTR_TXOP] = { .type = NLA_U16 },
2042 [NL80211_TXQ_ATTR_CWMIN] = { .type = NLA_U16 },
2043 [NL80211_TXQ_ATTR_CWMAX] = { .type = NLA_U16 },
2044 [NL80211_TXQ_ATTR_AIFS] = { .type = NLA_U8 },
2045};
2046
2047static int parse_txq_params(struct nlattr *tb[],
2048 struct ieee80211_txq_params *txq_params)
2049{
Johannes Berga3304b02012-03-28 11:04:24 +02002050 if (!tb[NL80211_TXQ_ATTR_AC] || !tb[NL80211_TXQ_ATTR_TXOP] ||
Jouni Malinen31888482008-10-30 16:59:24 +02002051 !tb[NL80211_TXQ_ATTR_CWMIN] || !tb[NL80211_TXQ_ATTR_CWMAX] ||
2052 !tb[NL80211_TXQ_ATTR_AIFS])
2053 return -EINVAL;
2054
Johannes Berga3304b02012-03-28 11:04:24 +02002055 txq_params->ac = nla_get_u8(tb[NL80211_TXQ_ATTR_AC]);
Jouni Malinen31888482008-10-30 16:59:24 +02002056 txq_params->txop = nla_get_u16(tb[NL80211_TXQ_ATTR_TXOP]);
2057 txq_params->cwmin = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMIN]);
2058 txq_params->cwmax = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMAX]);
2059 txq_params->aifs = nla_get_u8(tb[NL80211_TXQ_ATTR_AIFS]);
2060
Johannes Berga3304b02012-03-28 11:04:24 +02002061 if (txq_params->ac >= NL80211_NUM_ACS)
2062 return -EINVAL;
2063
Jouni Malinen31888482008-10-30 16:59:24 +02002064 return 0;
2065}
2066
Johannes Bergf444de02010-05-05 15:25:02 +02002067static bool nl80211_can_set_dev_channel(struct wireless_dev *wdev)
2068{
2069 /*
Johannes Bergcc1d2802012-05-16 23:50:20 +02002070 * You can only set the channel explicitly for WDS interfaces,
2071 * all others have their channel managed via their respective
2072 * "establish a connection" command (connect, join, ...)
2073 *
2074 * For AP/GO and mesh mode, the channel can be set with the
2075 * channel userspace API, but is only stored and passed to the
2076 * low-level driver when the AP starts or the mesh is joined.
2077 * This is for backward compatibility, userspace can also give
2078 * the channel in the start-ap or join-mesh commands instead.
Johannes Bergf444de02010-05-05 15:25:02 +02002079 *
2080 * Monitors are special as they are normally slaved to
Johannes Berge8c9bd52012-06-06 08:18:22 +02002081 * whatever else is going on, so they have their own special
2082 * operation to set the monitor channel if possible.
Johannes Bergf444de02010-05-05 15:25:02 +02002083 */
2084 return !wdev ||
2085 wdev->iftype == NL80211_IFTYPE_AP ||
Johannes Bergf444de02010-05-05 15:25:02 +02002086 wdev->iftype == NL80211_IFTYPE_MESH_POINT ||
Johannes Berg074ac8d2010-09-16 14:58:22 +02002087 wdev->iftype == NL80211_IFTYPE_MONITOR ||
2088 wdev->iftype == NL80211_IFTYPE_P2P_GO;
Johannes Bergf444de02010-05-05 15:25:02 +02002089}
2090
Johannes Berg683b6d32012-11-08 21:25:48 +01002091static int nl80211_parse_chandef(struct cfg80211_registered_device *rdev,
2092 struct genl_info *info,
2093 struct cfg80211_chan_def *chandef)
2094{
Mahesh Paliveladbeca2e2012-11-29 14:11:07 +05302095 u32 control_freq;
Johannes Berg683b6d32012-11-08 21:25:48 +01002096
2097 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ])
2098 return -EINVAL;
2099
2100 control_freq = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]);
2101
2102 chandef->chan = ieee80211_get_channel(&rdev->wiphy, control_freq);
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002103 chandef->width = NL80211_CHAN_WIDTH_20_NOHT;
2104 chandef->center_freq1 = control_freq;
2105 chandef->center_freq2 = 0;
Johannes Berg683b6d32012-11-08 21:25:48 +01002106
2107 /* Primary channel not allowed */
2108 if (!chandef->chan || chandef->chan->flags & IEEE80211_CHAN_DISABLED)
2109 return -EINVAL;
2110
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002111 if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]) {
2112 enum nl80211_channel_type chantype;
Johannes Berg683b6d32012-11-08 21:25:48 +01002113
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002114 chantype = nla_get_u32(
2115 info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]);
2116
2117 switch (chantype) {
2118 case NL80211_CHAN_NO_HT:
2119 case NL80211_CHAN_HT20:
2120 case NL80211_CHAN_HT40PLUS:
2121 case NL80211_CHAN_HT40MINUS:
2122 cfg80211_chandef_create(chandef, chandef->chan,
2123 chantype);
2124 break;
2125 default:
Johannes Berg683b6d32012-11-08 21:25:48 +01002126 return -EINVAL;
Johannes Berg683b6d32012-11-08 21:25:48 +01002127 }
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002128 } else if (info->attrs[NL80211_ATTR_CHANNEL_WIDTH]) {
2129 chandef->width =
2130 nla_get_u32(info->attrs[NL80211_ATTR_CHANNEL_WIDTH]);
2131 if (info->attrs[NL80211_ATTR_CENTER_FREQ1])
2132 chandef->center_freq1 =
2133 nla_get_u32(
2134 info->attrs[NL80211_ATTR_CENTER_FREQ1]);
2135 if (info->attrs[NL80211_ATTR_CENTER_FREQ2])
2136 chandef->center_freq2 =
2137 nla_get_u32(
2138 info->attrs[NL80211_ATTR_CENTER_FREQ2]);
2139 }
2140
Johannes Berg9f5e8f62012-11-22 16:59:45 +01002141 if (!cfg80211_chandef_valid(chandef))
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002142 return -EINVAL;
2143
Johannes Berg9f5e8f62012-11-22 16:59:45 +01002144 if (!cfg80211_chandef_usable(&rdev->wiphy, chandef,
2145 IEEE80211_CHAN_DISABLED))
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002146 return -EINVAL;
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002147
Simon Wunderlich2f301ab2013-05-16 13:00:28 +02002148 if ((chandef->width == NL80211_CHAN_WIDTH_5 ||
2149 chandef->width == NL80211_CHAN_WIDTH_10) &&
2150 !(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_5_10_MHZ))
2151 return -EINVAL;
2152
Johannes Berg683b6d32012-11-08 21:25:48 +01002153 return 0;
2154}
2155
Johannes Bergf444de02010-05-05 15:25:02 +02002156static int __nl80211_set_channel(struct cfg80211_registered_device *rdev,
Jouni Malinene16821b2014-04-28 11:22:08 +03002157 struct net_device *dev,
Johannes Bergf444de02010-05-05 15:25:02 +02002158 struct genl_info *info)
2159{
Johannes Berg683b6d32012-11-08 21:25:48 +01002160 struct cfg80211_chan_def chandef;
Johannes Bergf444de02010-05-05 15:25:02 +02002161 int result;
Johannes Berge8c9bd52012-06-06 08:18:22 +02002162 enum nl80211_iftype iftype = NL80211_IFTYPE_MONITOR;
Jouni Malinene16821b2014-04-28 11:22:08 +03002163 struct wireless_dev *wdev = NULL;
Johannes Berge8c9bd52012-06-06 08:18:22 +02002164
Jouni Malinene16821b2014-04-28 11:22:08 +03002165 if (dev)
2166 wdev = dev->ieee80211_ptr;
Johannes Bergf444de02010-05-05 15:25:02 +02002167 if (!nl80211_can_set_dev_channel(wdev))
2168 return -EOPNOTSUPP;
Jouni Malinene16821b2014-04-28 11:22:08 +03002169 if (wdev)
2170 iftype = wdev->iftype;
Johannes Bergf444de02010-05-05 15:25:02 +02002171
Johannes Berg683b6d32012-11-08 21:25:48 +01002172 result = nl80211_parse_chandef(rdev, info, &chandef);
2173 if (result)
2174 return result;
Johannes Bergf444de02010-05-05 15:25:02 +02002175
Johannes Berge8c9bd52012-06-06 08:18:22 +02002176 switch (iftype) {
Johannes Bergaa430da2012-05-16 23:50:18 +02002177 case NL80211_IFTYPE_AP:
2178 case NL80211_IFTYPE_P2P_GO:
Arik Nemtsov923b3522015-07-08 15:41:44 +03002179 if (!cfg80211_reg_can_beacon_relax(&rdev->wiphy, &chandef,
2180 iftype)) {
Johannes Bergaa430da2012-05-16 23:50:18 +02002181 result = -EINVAL;
2182 break;
2183 }
Jouni Malinene16821b2014-04-28 11:22:08 +03002184 if (wdev->beacon_interval) {
2185 if (!dev || !rdev->ops->set_ap_chanwidth ||
2186 !(rdev->wiphy.features &
2187 NL80211_FEATURE_AP_MODE_CHAN_WIDTH_CHANGE)) {
2188 result = -EBUSY;
2189 break;
2190 }
2191
2192 /* Only allow dynamic channel width changes */
2193 if (chandef.chan != wdev->preset_chandef.chan) {
2194 result = -EBUSY;
2195 break;
2196 }
2197 result = rdev_set_ap_chanwidth(rdev, dev, &chandef);
2198 if (result)
2199 break;
2200 }
Johannes Berg683b6d32012-11-08 21:25:48 +01002201 wdev->preset_chandef = chandef;
Johannes Bergaa430da2012-05-16 23:50:18 +02002202 result = 0;
2203 break;
Johannes Bergcc1d2802012-05-16 23:50:20 +02002204 case NL80211_IFTYPE_MESH_POINT:
Johannes Berg683b6d32012-11-08 21:25:48 +01002205 result = cfg80211_set_mesh_channel(rdev, wdev, &chandef);
Johannes Bergcc1d2802012-05-16 23:50:20 +02002206 break;
Johannes Berge8c9bd52012-06-06 08:18:22 +02002207 case NL80211_IFTYPE_MONITOR:
Johannes Berg683b6d32012-11-08 21:25:48 +01002208 result = cfg80211_set_monitor_channel(rdev, &chandef);
Johannes Berge8c9bd52012-06-06 08:18:22 +02002209 break;
Johannes Bergaa430da2012-05-16 23:50:18 +02002210 default:
Johannes Berge8c9bd52012-06-06 08:18:22 +02002211 result = -EINVAL;
Johannes Bergf444de02010-05-05 15:25:02 +02002212 }
Johannes Bergf444de02010-05-05 15:25:02 +02002213
2214 return result;
2215}
2216
2217static int nl80211_set_channel(struct sk_buff *skb, struct genl_info *info)
2218{
Johannes Berg4c476992010-10-04 21:36:35 +02002219 struct cfg80211_registered_device *rdev = info->user_ptr[0];
2220 struct net_device *netdev = info->user_ptr[1];
Johannes Bergf444de02010-05-05 15:25:02 +02002221
Jouni Malinene16821b2014-04-28 11:22:08 +03002222 return __nl80211_set_channel(rdev, netdev, info);
Johannes Bergf444de02010-05-05 15:25:02 +02002223}
2224
Bill Jordane8347eb2010-10-01 13:54:28 -04002225static int nl80211_set_wds_peer(struct sk_buff *skb, struct genl_info *info)
2226{
Johannes Berg43b19952010-10-07 13:10:30 +02002227 struct cfg80211_registered_device *rdev = info->user_ptr[0];
2228 struct net_device *dev = info->user_ptr[1];
2229 struct wireless_dev *wdev = dev->ieee80211_ptr;
Johannes Berg388ac772010-10-07 13:11:09 +02002230 const u8 *bssid;
Bill Jordane8347eb2010-10-01 13:54:28 -04002231
2232 if (!info->attrs[NL80211_ATTR_MAC])
2233 return -EINVAL;
2234
Johannes Berg43b19952010-10-07 13:10:30 +02002235 if (netif_running(dev))
2236 return -EBUSY;
Bill Jordane8347eb2010-10-01 13:54:28 -04002237
Johannes Berg43b19952010-10-07 13:10:30 +02002238 if (!rdev->ops->set_wds_peer)
2239 return -EOPNOTSUPP;
Bill Jordane8347eb2010-10-01 13:54:28 -04002240
Johannes Berg43b19952010-10-07 13:10:30 +02002241 if (wdev->iftype != NL80211_IFTYPE_WDS)
2242 return -EOPNOTSUPP;
Bill Jordane8347eb2010-10-01 13:54:28 -04002243
2244 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Hila Gonene35e4d22012-06-27 17:19:42 +03002245 return rdev_set_wds_peer(rdev, dev, bssid);
Bill Jordane8347eb2010-10-01 13:54:28 -04002246}
2247
Johannes Berg55682962007-09-20 13:09:35 -04002248static int nl80211_set_wiphy(struct sk_buff *skb, struct genl_info *info)
2249{
2250 struct cfg80211_registered_device *rdev;
Johannes Bergf444de02010-05-05 15:25:02 +02002251 struct net_device *netdev = NULL;
2252 struct wireless_dev *wdev;
Bill Jordana1e567c2010-09-10 11:22:32 -04002253 int result = 0, rem_txq_params = 0;
Jouni Malinen31888482008-10-30 16:59:24 +02002254 struct nlattr *nl_txq_params;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002255 u32 changed;
2256 u8 retry_short = 0, retry_long = 0;
2257 u32 frag_threshold = 0, rts_threshold = 0;
Lukáš Turek81077e82009-12-21 22:50:47 +01002258 u8 coverage_class = 0;
Johannes Berg55682962007-09-20 13:09:35 -04002259
Johannes Berg5fe231e2013-05-08 21:45:15 +02002260 ASSERT_RTNL();
2261
Johannes Bergf444de02010-05-05 15:25:02 +02002262 /*
2263 * Try to find the wiphy and netdev. Normally this
2264 * function shouldn't need the netdev, but this is
2265 * done for backward compatibility -- previously
2266 * setting the channel was done per wiphy, but now
2267 * it is per netdev. Previous userland like hostapd
2268 * also passed a netdev to set_wiphy, so that it is
2269 * possible to let that go to the right netdev!
2270 */
Johannes Berg4bbf4d52009-03-24 09:35:46 +01002271
Johannes Bergf444de02010-05-05 15:25:02 +02002272 if (info->attrs[NL80211_ATTR_IFINDEX]) {
2273 int ifindex = nla_get_u32(info->attrs[NL80211_ATTR_IFINDEX]);
2274
Ying Xue7f2b8562014-01-15 10:23:45 +08002275 netdev = __dev_get_by_index(genl_info_net(info), ifindex);
Johannes Berg5fe231e2013-05-08 21:45:15 +02002276 if (netdev && netdev->ieee80211_ptr)
Zhao, Gangf26cbf42014-04-21 12:53:03 +08002277 rdev = wiphy_to_rdev(netdev->ieee80211_ptr->wiphy);
Johannes Berg5fe231e2013-05-08 21:45:15 +02002278 else
Johannes Bergf444de02010-05-05 15:25:02 +02002279 netdev = NULL;
Johannes Berg4bbf4d52009-03-24 09:35:46 +01002280 }
2281
Johannes Bergf444de02010-05-05 15:25:02 +02002282 if (!netdev) {
Johannes Berg878d9ec2012-06-15 14:18:32 +02002283 rdev = __cfg80211_rdev_from_attrs(genl_info_net(info),
2284 info->attrs);
Johannes Berg5fe231e2013-05-08 21:45:15 +02002285 if (IS_ERR(rdev))
Johannes Berg4c476992010-10-04 21:36:35 +02002286 return PTR_ERR(rdev);
Johannes Bergf444de02010-05-05 15:25:02 +02002287 wdev = NULL;
2288 netdev = NULL;
2289 result = 0;
Johannes Berg71fe96b2012-10-24 10:04:58 +02002290 } else
Johannes Bergf444de02010-05-05 15:25:02 +02002291 wdev = netdev->ieee80211_ptr;
Johannes Bergf444de02010-05-05 15:25:02 +02002292
2293 /*
2294 * end workaround code, by now the rdev is available
2295 * and locked, and wdev may or may not be NULL.
2296 */
Johannes Berg4bbf4d52009-03-24 09:35:46 +01002297
2298 if (info->attrs[NL80211_ATTR_WIPHY_NAME])
Jouni Malinen31888482008-10-30 16:59:24 +02002299 result = cfg80211_dev_rename(
2300 rdev, nla_data(info->attrs[NL80211_ATTR_WIPHY_NAME]));
Johannes Berg4bbf4d52009-03-24 09:35:46 +01002301
Johannes Berg4bbf4d52009-03-24 09:35:46 +01002302 if (result)
Ying Xue7f2b8562014-01-15 10:23:45 +08002303 return result;
Johannes Berg55682962007-09-20 13:09:35 -04002304
Jouni Malinen31888482008-10-30 16:59:24 +02002305 if (info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS]) {
2306 struct ieee80211_txq_params txq_params;
2307 struct nlattr *tb[NL80211_TXQ_ATTR_MAX + 1];
2308
Ying Xue7f2b8562014-01-15 10:23:45 +08002309 if (!rdev->ops->set_txq_params)
2310 return -EOPNOTSUPP;
Jouni Malinen31888482008-10-30 16:59:24 +02002311
Ying Xue7f2b8562014-01-15 10:23:45 +08002312 if (!netdev)
2313 return -EINVAL;
Eliad Pellerf70f01c2011-09-25 20:06:53 +03002314
Johannes Berg133a3ff2011-11-03 14:50:13 +01002315 if (netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
Ying Xue7f2b8562014-01-15 10:23:45 +08002316 netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
2317 return -EINVAL;
Johannes Berg133a3ff2011-11-03 14:50:13 +01002318
Ying Xue7f2b8562014-01-15 10:23:45 +08002319 if (!netif_running(netdev))
2320 return -ENETDOWN;
Johannes Berg2b5f8b02012-04-02 10:51:55 +02002321
Jouni Malinen31888482008-10-30 16:59:24 +02002322 nla_for_each_nested(nl_txq_params,
2323 info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS],
2324 rem_txq_params) {
Johannes Bergbfe2c7b2016-10-26 14:42:21 +02002325 result = nla_parse_nested(tb, NL80211_TXQ_ATTR_MAX,
2326 nl_txq_params,
2327 txq_params_policy);
Johannes Bergae811e22014-01-24 10:17:47 +01002328 if (result)
2329 return result;
Jouni Malinen31888482008-10-30 16:59:24 +02002330 result = parse_txq_params(tb, &txq_params);
2331 if (result)
Ying Xue7f2b8562014-01-15 10:23:45 +08002332 return result;
Jouni Malinen31888482008-10-30 16:59:24 +02002333
Hila Gonene35e4d22012-06-27 17:19:42 +03002334 result = rdev_set_txq_params(rdev, netdev,
2335 &txq_params);
Jouni Malinen31888482008-10-30 16:59:24 +02002336 if (result)
Ying Xue7f2b8562014-01-15 10:23:45 +08002337 return result;
Jouni Malinen31888482008-10-30 16:59:24 +02002338 }
2339 }
2340
Jouni Malinen72bdcf32008-11-26 16:15:24 +02002341 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
Jouni Malinene16821b2014-04-28 11:22:08 +03002342 result = __nl80211_set_channel(
2343 rdev,
2344 nl80211_can_set_dev_channel(wdev) ? netdev : NULL,
2345 info);
Jouni Malinen72bdcf32008-11-26 16:15:24 +02002346 if (result)
Ying Xue7f2b8562014-01-15 10:23:45 +08002347 return result;
Jouni Malinen72bdcf32008-11-26 16:15:24 +02002348 }
2349
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03002350 if (info->attrs[NL80211_ATTR_WIPHY_TX_POWER_SETTING]) {
Johannes Bergc8442112012-10-24 10:17:18 +02002351 struct wireless_dev *txp_wdev = wdev;
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03002352 enum nl80211_tx_power_setting type;
2353 int idx, mbm = 0;
2354
Johannes Bergc8442112012-10-24 10:17:18 +02002355 if (!(rdev->wiphy.features & NL80211_FEATURE_VIF_TXPOWER))
2356 txp_wdev = NULL;
2357
Ying Xue7f2b8562014-01-15 10:23:45 +08002358 if (!rdev->ops->set_tx_power)
2359 return -EOPNOTSUPP;
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03002360
2361 idx = NL80211_ATTR_WIPHY_TX_POWER_SETTING;
2362 type = nla_get_u32(info->attrs[idx]);
2363
2364 if (!info->attrs[NL80211_ATTR_WIPHY_TX_POWER_LEVEL] &&
Ying Xue7f2b8562014-01-15 10:23:45 +08002365 (type != NL80211_TX_POWER_AUTOMATIC))
2366 return -EINVAL;
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03002367
2368 if (type != NL80211_TX_POWER_AUTOMATIC) {
2369 idx = NL80211_ATTR_WIPHY_TX_POWER_LEVEL;
2370 mbm = nla_get_u32(info->attrs[idx]);
2371 }
2372
Johannes Bergc8442112012-10-24 10:17:18 +02002373 result = rdev_set_tx_power(rdev, txp_wdev, type, mbm);
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03002374 if (result)
Ying Xue7f2b8562014-01-15 10:23:45 +08002375 return result;
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03002376 }
2377
Bruno Randolfafe0cbf2010-11-10 12:50:50 +09002378 if (info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX] &&
2379 info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]) {
2380 u32 tx_ant, rx_ant;
Kirtika Ruchandani7a087e72016-05-29 19:51:23 -07002381
Bruno Randolf7f531e02010-12-16 11:30:22 +09002382 if ((!rdev->wiphy.available_antennas_tx &&
2383 !rdev->wiphy.available_antennas_rx) ||
Ying Xue7f2b8562014-01-15 10:23:45 +08002384 !rdev->ops->set_antenna)
2385 return -EOPNOTSUPP;
Bruno Randolfafe0cbf2010-11-10 12:50:50 +09002386
2387 tx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX]);
2388 rx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]);
2389
Bruno Randolfa7ffac92010-12-08 13:59:24 +09002390 /* reject antenna configurations which don't match the
Bruno Randolf7f531e02010-12-16 11:30:22 +09002391 * available antenna masks, except for the "all" mask */
2392 if ((~tx_ant && (tx_ant & ~rdev->wiphy.available_antennas_tx)) ||
Ying Xue7f2b8562014-01-15 10:23:45 +08002393 (~rx_ant && (rx_ant & ~rdev->wiphy.available_antennas_rx)))
2394 return -EINVAL;
Bruno Randolfa7ffac92010-12-08 13:59:24 +09002395
Bruno Randolf7f531e02010-12-16 11:30:22 +09002396 tx_ant = tx_ant & rdev->wiphy.available_antennas_tx;
2397 rx_ant = rx_ant & rdev->wiphy.available_antennas_rx;
Bruno Randolfa7ffac92010-12-08 13:59:24 +09002398
Hila Gonene35e4d22012-06-27 17:19:42 +03002399 result = rdev_set_antenna(rdev, tx_ant, rx_ant);
Bruno Randolfafe0cbf2010-11-10 12:50:50 +09002400 if (result)
Ying Xue7f2b8562014-01-15 10:23:45 +08002401 return result;
Bruno Randolfafe0cbf2010-11-10 12:50:50 +09002402 }
2403
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002404 changed = 0;
2405
2406 if (info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]) {
2407 retry_short = nla_get_u8(
2408 info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]);
Ying Xue7f2b8562014-01-15 10:23:45 +08002409 if (retry_short == 0)
2410 return -EINVAL;
2411
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002412 changed |= WIPHY_PARAM_RETRY_SHORT;
2413 }
2414
2415 if (info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]) {
2416 retry_long = nla_get_u8(
2417 info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]);
Ying Xue7f2b8562014-01-15 10:23:45 +08002418 if (retry_long == 0)
2419 return -EINVAL;
2420
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002421 changed |= WIPHY_PARAM_RETRY_LONG;
2422 }
2423
2424 if (info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]) {
2425 frag_threshold = nla_get_u32(
2426 info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]);
Ying Xue7f2b8562014-01-15 10:23:45 +08002427 if (frag_threshold < 256)
2428 return -EINVAL;
2429
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002430 if (frag_threshold != (u32) -1) {
2431 /*
2432 * Fragments (apart from the last one) are required to
2433 * have even length. Make the fragmentation code
2434 * simpler by stripping LSB should someone try to use
2435 * odd threshold value.
2436 */
2437 frag_threshold &= ~0x1;
2438 }
2439 changed |= WIPHY_PARAM_FRAG_THRESHOLD;
2440 }
2441
2442 if (info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]) {
2443 rts_threshold = nla_get_u32(
2444 info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]);
2445 changed |= WIPHY_PARAM_RTS_THRESHOLD;
2446 }
2447
Lukáš Turek81077e82009-12-21 22:50:47 +01002448 if (info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]) {
Lorenzo Bianconi3057dbf2014-09-04 23:57:40 +02002449 if (info->attrs[NL80211_ATTR_WIPHY_DYN_ACK])
2450 return -EINVAL;
2451
Lukáš Turek81077e82009-12-21 22:50:47 +01002452 coverage_class = nla_get_u8(
2453 info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]);
2454 changed |= WIPHY_PARAM_COVERAGE_CLASS;
2455 }
2456
Lorenzo Bianconi3057dbf2014-09-04 23:57:40 +02002457 if (info->attrs[NL80211_ATTR_WIPHY_DYN_ACK]) {
2458 if (!(rdev->wiphy.features & NL80211_FEATURE_ACKTO_ESTIMATION))
2459 return -EOPNOTSUPP;
2460
2461 changed |= WIPHY_PARAM_DYN_ACK;
2462 }
2463
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002464 if (changed) {
2465 u8 old_retry_short, old_retry_long;
2466 u32 old_frag_threshold, old_rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01002467 u8 old_coverage_class;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002468
Ying Xue7f2b8562014-01-15 10:23:45 +08002469 if (!rdev->ops->set_wiphy_params)
2470 return -EOPNOTSUPP;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002471
2472 old_retry_short = rdev->wiphy.retry_short;
2473 old_retry_long = rdev->wiphy.retry_long;
2474 old_frag_threshold = rdev->wiphy.frag_threshold;
2475 old_rts_threshold = rdev->wiphy.rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01002476 old_coverage_class = rdev->wiphy.coverage_class;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002477
2478 if (changed & WIPHY_PARAM_RETRY_SHORT)
2479 rdev->wiphy.retry_short = retry_short;
2480 if (changed & WIPHY_PARAM_RETRY_LONG)
2481 rdev->wiphy.retry_long = retry_long;
2482 if (changed & WIPHY_PARAM_FRAG_THRESHOLD)
2483 rdev->wiphy.frag_threshold = frag_threshold;
2484 if (changed & WIPHY_PARAM_RTS_THRESHOLD)
2485 rdev->wiphy.rts_threshold = rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01002486 if (changed & WIPHY_PARAM_COVERAGE_CLASS)
2487 rdev->wiphy.coverage_class = coverage_class;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002488
Hila Gonene35e4d22012-06-27 17:19:42 +03002489 result = rdev_set_wiphy_params(rdev, changed);
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002490 if (result) {
2491 rdev->wiphy.retry_short = old_retry_short;
2492 rdev->wiphy.retry_long = old_retry_long;
2493 rdev->wiphy.frag_threshold = old_frag_threshold;
2494 rdev->wiphy.rts_threshold = old_rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01002495 rdev->wiphy.coverage_class = old_coverage_class;
Michal Kazior9189ee32015-08-03 10:55:24 +02002496 return result;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002497 }
2498 }
Ying Xue7f2b8562014-01-15 10:23:45 +08002499 return 0;
Johannes Berg55682962007-09-20 13:09:35 -04002500}
2501
Johannes Berg71bbc992012-06-15 15:30:18 +02002502static inline u64 wdev_id(struct wireless_dev *wdev)
2503{
2504 return (u64)wdev->identifier |
Zhao, Gangf26cbf42014-04-21 12:53:03 +08002505 ((u64)wiphy_to_rdev(wdev->wiphy)->wiphy_idx << 32);
Johannes Berg71bbc992012-06-15 15:30:18 +02002506}
Johannes Berg55682962007-09-20 13:09:35 -04002507
Johannes Berg683b6d32012-11-08 21:25:48 +01002508static int nl80211_send_chandef(struct sk_buff *msg,
Janusz Dziedzicd2859df2013-11-06 13:55:51 +01002509 const struct cfg80211_chan_def *chandef)
Johannes Berg683b6d32012-11-08 21:25:48 +01002510{
Johannes Berg601555c2014-11-27 17:26:56 +01002511 if (WARN_ON(!cfg80211_chandef_valid(chandef)))
2512 return -EINVAL;
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002513
Johannes Berg683b6d32012-11-08 21:25:48 +01002514 if (nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ,
2515 chandef->chan->center_freq))
2516 return -ENOBUFS;
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002517 switch (chandef->width) {
2518 case NL80211_CHAN_WIDTH_20_NOHT:
2519 case NL80211_CHAN_WIDTH_20:
2520 case NL80211_CHAN_WIDTH_40:
2521 if (nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE,
2522 cfg80211_get_chandef_type(chandef)))
2523 return -ENOBUFS;
2524 break;
2525 default:
2526 break;
2527 }
2528 if (nla_put_u32(msg, NL80211_ATTR_CHANNEL_WIDTH, chandef->width))
2529 return -ENOBUFS;
2530 if (nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ1, chandef->center_freq1))
2531 return -ENOBUFS;
2532 if (chandef->center_freq2 &&
2533 nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ2, chandef->center_freq2))
Johannes Berg683b6d32012-11-08 21:25:48 +01002534 return -ENOBUFS;
2535 return 0;
2536}
2537
Eric W. Biederman15e47302012-09-07 20:12:54 +00002538static int nl80211_send_iface(struct sk_buff *msg, u32 portid, u32 seq, int flags,
Johannes Bergd7264052009-04-19 16:23:20 +02002539 struct cfg80211_registered_device *rdev,
Tomasz Bursztyka8f894be2014-11-12 16:26:45 +02002540 struct wireless_dev *wdev, bool removal)
Johannes Berg55682962007-09-20 13:09:35 -04002541{
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002542 struct net_device *dev = wdev->netdev;
Tomasz Bursztyka8f894be2014-11-12 16:26:45 +02002543 u8 cmd = NL80211_CMD_NEW_INTERFACE;
Johannes Berg55682962007-09-20 13:09:35 -04002544 void *hdr;
2545
Tomasz Bursztyka8f894be2014-11-12 16:26:45 +02002546 if (removal)
2547 cmd = NL80211_CMD_DEL_INTERFACE;
2548
2549 hdr = nl80211hdr_put(msg, portid, seq, flags, cmd);
Johannes Berg55682962007-09-20 13:09:35 -04002550 if (!hdr)
2551 return -1;
2552
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002553 if (dev &&
2554 (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
Johannes Berg98104fde2012-06-16 00:19:54 +02002555 nla_put_string(msg, NL80211_ATTR_IFNAME, dev->name)))
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002556 goto nla_put_failure;
2557
2558 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
2559 nla_put_u32(msg, NL80211_ATTR_IFTYPE, wdev->iftype) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02002560 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
2561 NL80211_ATTR_PAD) ||
Johannes Berg98104fde2012-06-16 00:19:54 +02002562 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, wdev_address(wdev)) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04002563 nla_put_u32(msg, NL80211_ATTR_GENERATION,
2564 rdev->devlist_generation ^
2565 (cfg80211_rdev_list_generation << 2)))
2566 goto nla_put_failure;
Johannes Bergf5ea9122009-08-07 16:17:38 +02002567
Johannes Berg5b7ccaf2012-07-12 19:45:08 +02002568 if (rdev->ops->get_channel) {
Johannes Berg683b6d32012-11-08 21:25:48 +01002569 int ret;
2570 struct cfg80211_chan_def chandef;
Johannes Berg5b7ccaf2012-07-12 19:45:08 +02002571
Johannes Berg683b6d32012-11-08 21:25:48 +01002572 ret = rdev_get_channel(rdev, wdev, &chandef);
2573 if (ret == 0) {
2574 if (nl80211_send_chandef(msg, &chandef))
2575 goto nla_put_failure;
2576 }
Pontus Fuchsd91df0e2012-04-03 16:39:58 +02002577 }
2578
Rafał Miłeckid55d0d52015-08-31 22:59:38 +02002579 if (rdev->ops->get_tx_power) {
2580 int dbm, ret;
2581
2582 ret = rdev_get_tx_power(rdev, wdev, &dbm);
2583 if (ret == 0 &&
2584 nla_put_u32(msg, NL80211_ATTR_WIPHY_TX_POWER_LEVEL,
2585 DBM_TO_MBM(dbm)))
2586 goto nla_put_failure;
2587 }
2588
Antonio Quartullib84e7a02012-11-07 12:52:20 +01002589 if (wdev->ssid_len) {
2590 if (nla_put(msg, NL80211_ATTR_SSID, wdev->ssid_len, wdev->ssid))
2591 goto nla_put_failure;
2592 }
2593
Johannes Berg053c0952015-01-16 22:09:00 +01002594 genlmsg_end(msg, hdr);
2595 return 0;
Johannes Berg55682962007-09-20 13:09:35 -04002596
2597 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07002598 genlmsg_cancel(msg, hdr);
2599 return -EMSGSIZE;
Johannes Berg55682962007-09-20 13:09:35 -04002600}
2601
2602static int nl80211_dump_interface(struct sk_buff *skb, struct netlink_callback *cb)
2603{
2604 int wp_idx = 0;
2605 int if_idx = 0;
2606 int wp_start = cb->args[0];
2607 int if_start = cb->args[1];
Denis Kenziorb7fb44d2016-08-03 17:02:15 -05002608 int filter_wiphy = -1;
Johannes Bergf5ea9122009-08-07 16:17:38 +02002609 struct cfg80211_registered_device *rdev;
Johannes Berg55682962007-09-20 13:09:35 -04002610 struct wireless_dev *wdev;
2611
Johannes Berg5fe231e2013-05-08 21:45:15 +02002612 rtnl_lock();
Denis Kenziorb7fb44d2016-08-03 17:02:15 -05002613 if (!cb->args[2]) {
2614 struct nl80211_dump_wiphy_state state = {
2615 .filter_wiphy = -1,
2616 };
2617 int ret;
2618
2619 ret = nl80211_dump_wiphy_parse(skb, cb, &state);
2620 if (ret)
2621 return ret;
2622
2623 filter_wiphy = state.filter_wiphy;
2624
2625 /*
2626 * if filtering, set cb->args[2] to +1 since 0 is the default
2627 * value needed to determine that parsing is necessary.
2628 */
2629 if (filter_wiphy >= 0)
2630 cb->args[2] = filter_wiphy + 1;
2631 else
2632 cb->args[2] = -1;
2633 } else if (cb->args[2] > 0) {
2634 filter_wiphy = cb->args[2] - 1;
2635 }
2636
Johannes Bergf5ea9122009-08-07 16:17:38 +02002637 list_for_each_entry(rdev, &cfg80211_rdev_list, list) {
2638 if (!net_eq(wiphy_net(&rdev->wiphy), sock_net(skb->sk)))
Johannes Berg463d0182009-07-14 00:33:35 +02002639 continue;
Johannes Bergbba95fe2008-07-29 13:22:51 +02002640 if (wp_idx < wp_start) {
2641 wp_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04002642 continue;
Johannes Bergbba95fe2008-07-29 13:22:51 +02002643 }
Denis Kenziorb7fb44d2016-08-03 17:02:15 -05002644
2645 if (filter_wiphy >= 0 && filter_wiphy != rdev->wiphy_idx)
2646 continue;
2647
Johannes Berg55682962007-09-20 13:09:35 -04002648 if_idx = 0;
2649
Johannes Berg53873f12016-05-03 16:52:04 +03002650 list_for_each_entry(wdev, &rdev->wiphy.wdev_list, list) {
Johannes Bergbba95fe2008-07-29 13:22:51 +02002651 if (if_idx < if_start) {
2652 if_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04002653 continue;
Johannes Bergbba95fe2008-07-29 13:22:51 +02002654 }
Eric W. Biederman15e47302012-09-07 20:12:54 +00002655 if (nl80211_send_iface(skb, NETLINK_CB(cb->skb).portid,
Johannes Berg55682962007-09-20 13:09:35 -04002656 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Tomasz Bursztyka8f894be2014-11-12 16:26:45 +02002657 rdev, wdev, false) < 0) {
Johannes Bergbba95fe2008-07-29 13:22:51 +02002658 goto out;
2659 }
2660 if_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04002661 }
Johannes Bergbba95fe2008-07-29 13:22:51 +02002662
2663 wp_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04002664 }
Johannes Bergbba95fe2008-07-29 13:22:51 +02002665 out:
Johannes Berg5fe231e2013-05-08 21:45:15 +02002666 rtnl_unlock();
Johannes Berg55682962007-09-20 13:09:35 -04002667
2668 cb->args[0] = wp_idx;
2669 cb->args[1] = if_idx;
2670
2671 return skb->len;
2672}
2673
2674static int nl80211_get_interface(struct sk_buff *skb, struct genl_info *info)
2675{
2676 struct sk_buff *msg;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002677 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002678 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg55682962007-09-20 13:09:35 -04002679
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07002680 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -04002681 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02002682 return -ENOMEM;
Johannes Berg55682962007-09-20 13:09:35 -04002683
Eric W. Biederman15e47302012-09-07 20:12:54 +00002684 if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0,
Tomasz Bursztyka8f894be2014-11-12 16:26:45 +02002685 rdev, wdev, false) < 0) {
Johannes Berg4c476992010-10-04 21:36:35 +02002686 nlmsg_free(msg);
2687 return -ENOBUFS;
2688 }
Johannes Berg55682962007-09-20 13:09:35 -04002689
Johannes Berg134e6372009-07-10 09:51:34 +00002690 return genlmsg_reply(msg, info);
Johannes Berg55682962007-09-20 13:09:35 -04002691}
2692
Michael Wu66f7ac52008-01-31 19:48:22 +01002693static const struct nla_policy mntr_flags_policy[NL80211_MNTR_FLAG_MAX + 1] = {
2694 [NL80211_MNTR_FLAG_FCSFAIL] = { .type = NLA_FLAG },
2695 [NL80211_MNTR_FLAG_PLCPFAIL] = { .type = NLA_FLAG },
2696 [NL80211_MNTR_FLAG_CONTROL] = { .type = NLA_FLAG },
2697 [NL80211_MNTR_FLAG_OTHER_BSS] = { .type = NLA_FLAG },
2698 [NL80211_MNTR_FLAG_COOK_FRAMES] = { .type = NLA_FLAG },
Felix Fietkaue057d3c2013-05-28 13:01:52 +02002699 [NL80211_MNTR_FLAG_ACTIVE] = { .type = NLA_FLAG },
Michael Wu66f7ac52008-01-31 19:48:22 +01002700};
2701
2702static int parse_monitor_flags(struct nlattr *nla, u32 *mntrflags)
2703{
2704 struct nlattr *flags[NL80211_MNTR_FLAG_MAX + 1];
2705 int flag;
2706
2707 *mntrflags = 0;
2708
2709 if (!nla)
2710 return -EINVAL;
2711
2712 if (nla_parse_nested(flags, NL80211_MNTR_FLAG_MAX,
2713 nla, mntr_flags_policy))
2714 return -EINVAL;
2715
2716 for (flag = 1; flag <= NL80211_MNTR_FLAG_MAX; flag++)
2717 if (flags[flag])
2718 *mntrflags |= (1<<flag);
2719
2720 return 0;
2721}
2722
Johannes Berg9bc383d2009-11-19 11:55:19 +01002723static int nl80211_valid_4addr(struct cfg80211_registered_device *rdev,
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002724 struct net_device *netdev, u8 use_4addr,
2725 enum nl80211_iftype iftype)
Johannes Berg9bc383d2009-11-19 11:55:19 +01002726{
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002727 if (!use_4addr) {
Jiri Pirkof350a0a82010-06-15 06:50:45 +00002728 if (netdev && (netdev->priv_flags & IFF_BRIDGE_PORT))
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002729 return -EBUSY;
Johannes Berg9bc383d2009-11-19 11:55:19 +01002730 return 0;
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002731 }
Johannes Berg9bc383d2009-11-19 11:55:19 +01002732
2733 switch (iftype) {
2734 case NL80211_IFTYPE_AP_VLAN:
2735 if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_AP)
2736 return 0;
2737 break;
2738 case NL80211_IFTYPE_STATION:
2739 if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_STATION)
2740 return 0;
2741 break;
2742 default:
2743 break;
2744 }
2745
2746 return -EOPNOTSUPP;
2747}
2748
Johannes Berg55682962007-09-20 13:09:35 -04002749static int nl80211_set_interface(struct sk_buff *skb, struct genl_info *info)
2750{
Johannes Berg4c476992010-10-04 21:36:35 +02002751 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002752 struct vif_params params;
Johannes Berge36d56b2009-06-09 21:04:43 +02002753 int err;
Johannes Berg04a773a2009-04-19 21:24:32 +02002754 enum nl80211_iftype otype, ntype;
Johannes Berg4c476992010-10-04 21:36:35 +02002755 struct net_device *dev = info->user_ptr[1];
Johannes Berg92ffe052008-09-16 20:39:36 +02002756 u32 _flags, *flags = NULL;
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002757 bool change = false;
Johannes Berg55682962007-09-20 13:09:35 -04002758
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002759 memset(&params, 0, sizeof(params));
2760
Johannes Berg04a773a2009-04-19 21:24:32 +02002761 otype = ntype = dev->ieee80211_ptr->iftype;
Johannes Berg55682962007-09-20 13:09:35 -04002762
Johannes Berg723b0382008-09-16 20:22:09 +02002763 if (info->attrs[NL80211_ATTR_IFTYPE]) {
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002764 ntype = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]);
Johannes Berg04a773a2009-04-19 21:24:32 +02002765 if (otype != ntype)
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002766 change = true;
Johannes Berg4c476992010-10-04 21:36:35 +02002767 if (ntype > NL80211_IFTYPE_MAX)
2768 return -EINVAL;
Johannes Berg723b0382008-09-16 20:22:09 +02002769 }
2770
Johannes Berg92ffe052008-09-16 20:39:36 +02002771 if (info->attrs[NL80211_ATTR_MESH_ID]) {
Johannes Berg29cbe682010-12-03 09:20:44 +01002772 struct wireless_dev *wdev = dev->ieee80211_ptr;
2773
Johannes Berg4c476992010-10-04 21:36:35 +02002774 if (ntype != NL80211_IFTYPE_MESH_POINT)
2775 return -EINVAL;
Johannes Berg29cbe682010-12-03 09:20:44 +01002776 if (netif_running(dev))
2777 return -EBUSY;
2778
2779 wdev_lock(wdev);
2780 BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN !=
2781 IEEE80211_MAX_MESH_ID_LEN);
2782 wdev->mesh_id_up_len =
2783 nla_len(info->attrs[NL80211_ATTR_MESH_ID]);
2784 memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]),
2785 wdev->mesh_id_up_len);
2786 wdev_unlock(wdev);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002787 }
2788
Felix Fietkau8b787642009-11-10 18:53:10 +01002789 if (info->attrs[NL80211_ATTR_4ADDR]) {
2790 params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]);
2791 change = true;
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002792 err = nl80211_valid_4addr(rdev, dev, params.use_4addr, ntype);
Johannes Berg9bc383d2009-11-19 11:55:19 +01002793 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02002794 return err;
Felix Fietkau8b787642009-11-10 18:53:10 +01002795 } else {
2796 params.use_4addr = -1;
2797 }
2798
Johannes Berg92ffe052008-09-16 20:39:36 +02002799 if (info->attrs[NL80211_ATTR_MNTR_FLAGS]) {
Johannes Berg4c476992010-10-04 21:36:35 +02002800 if (ntype != NL80211_IFTYPE_MONITOR)
2801 return -EINVAL;
Johannes Berg92ffe052008-09-16 20:39:36 +02002802 err = parse_monitor_flags(info->attrs[NL80211_ATTR_MNTR_FLAGS],
2803 &_flags);
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002804 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02002805 return err;
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002806
2807 flags = &_flags;
2808 change = true;
Johannes Berg92ffe052008-09-16 20:39:36 +02002809 }
Johannes Berg3b858752009-03-12 09:55:09 +01002810
Aviya Erenfeldc6e6a0c2016-07-05 15:23:08 +03002811 if (info->attrs[NL80211_ATTR_MU_MIMO_GROUP_DATA]) {
2812 const u8 *mumimo_groups;
2813 u32 cap_flag = NL80211_EXT_FEATURE_MU_MIMO_AIR_SNIFFER;
2814
2815 if (!wiphy_ext_feature_isset(&rdev->wiphy, cap_flag))
2816 return -EOPNOTSUPP;
2817
2818 mumimo_groups =
2819 nla_data(info->attrs[NL80211_ATTR_MU_MIMO_GROUP_DATA]);
2820
2821 /* bits 0 and 63 are reserved and must be zero */
2822 if ((mumimo_groups[0] & BIT(7)) ||
2823 (mumimo_groups[VHT_MUMIMO_GROUPS_DATA_LEN - 1] & BIT(0)))
2824 return -EINVAL;
2825
2826 memcpy(params.vht_mumimo_groups, mumimo_groups,
2827 VHT_MUMIMO_GROUPS_DATA_LEN);
2828 change = true;
2829 }
2830
2831 if (info->attrs[NL80211_ATTR_MU_MIMO_FOLLOW_MAC_ADDR]) {
2832 u32 cap_flag = NL80211_EXT_FEATURE_MU_MIMO_AIR_SNIFFER;
2833
2834 if (!wiphy_ext_feature_isset(&rdev->wiphy, cap_flag))
2835 return -EOPNOTSUPP;
2836
2837 nla_memcpy(params.macaddr,
2838 info->attrs[NL80211_ATTR_MU_MIMO_FOLLOW_MAC_ADDR],
2839 ETH_ALEN);
2840 change = true;
2841 }
2842
Luciano Coelho18003292013-08-29 13:26:57 +03002843 if (flags && (*flags & MONITOR_FLAG_ACTIVE) &&
Felix Fietkaue057d3c2013-05-28 13:01:52 +02002844 !(rdev->wiphy.features & NL80211_FEATURE_ACTIVE_MONITOR))
2845 return -EOPNOTSUPP;
2846
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002847 if (change)
Johannes Berg3d54d252009-08-21 14:51:05 +02002848 err = cfg80211_change_iface(rdev, dev, ntype, flags, &params);
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002849 else
2850 err = 0;
Johannes Berg60719ff2008-09-16 14:55:09 +02002851
Johannes Berg9bc383d2009-11-19 11:55:19 +01002852 if (!err && params.use_4addr != -1)
2853 dev->ieee80211_ptr->use_4addr = params.use_4addr;
2854
Johannes Berg55682962007-09-20 13:09:35 -04002855 return err;
2856}
2857
2858static int nl80211_new_interface(struct sk_buff *skb, struct genl_info *info)
2859{
Johannes Berg4c476992010-10-04 21:36:35 +02002860 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002861 struct vif_params params;
Johannes Berg84efbb82012-06-16 00:00:26 +02002862 struct wireless_dev *wdev;
Denis Kenzior896ff062016-08-03 16:58:33 -05002863 struct sk_buff *msg;
Johannes Berg55682962007-09-20 13:09:35 -04002864 int err;
2865 enum nl80211_iftype type = NL80211_IFTYPE_UNSPECIFIED;
Michael Wu66f7ac52008-01-31 19:48:22 +01002866 u32 flags;
Johannes Berg55682962007-09-20 13:09:35 -04002867
Johannes Berg78f22b62014-03-24 17:57:27 +01002868 /* to avoid failing a new interface creation due to pending removal */
2869 cfg80211_destroy_ifaces(rdev);
2870
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002871 memset(&params, 0, sizeof(params));
2872
Johannes Berg55682962007-09-20 13:09:35 -04002873 if (!info->attrs[NL80211_ATTR_IFNAME])
2874 return -EINVAL;
2875
2876 if (info->attrs[NL80211_ATTR_IFTYPE]) {
2877 type = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]);
2878 if (type > NL80211_IFTYPE_MAX)
2879 return -EINVAL;
2880 }
2881
Johannes Berg79c97e92009-07-07 03:56:12 +02002882 if (!rdev->ops->add_virtual_intf ||
Johannes Berg4c476992010-10-04 21:36:35 +02002883 !(rdev->wiphy.interface_modes & (1 << type)))
2884 return -EOPNOTSUPP;
Johannes Berg55682962007-09-20 13:09:35 -04002885
Ayala Bekercb3b7d82016-09-20 17:31:13 +03002886 if ((type == NL80211_IFTYPE_P2P_DEVICE || type == NL80211_IFTYPE_NAN ||
Ben Greeare8f479b2014-10-22 12:23:05 -07002887 rdev->wiphy.features & NL80211_FEATURE_MAC_ON_CREATE) &&
2888 info->attrs[NL80211_ATTR_MAC]) {
Arend van Spriel1c18f142013-01-08 10:17:27 +01002889 nla_memcpy(params.macaddr, info->attrs[NL80211_ATTR_MAC],
2890 ETH_ALEN);
2891 if (!is_valid_ether_addr(params.macaddr))
2892 return -EADDRNOTAVAIL;
2893 }
2894
Johannes Berg9bc383d2009-11-19 11:55:19 +01002895 if (info->attrs[NL80211_ATTR_4ADDR]) {
Felix Fietkau8b787642009-11-10 18:53:10 +01002896 params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]);
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002897 err = nl80211_valid_4addr(rdev, NULL, params.use_4addr, type);
Johannes Berg9bc383d2009-11-19 11:55:19 +01002898 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02002899 return err;
Johannes Berg9bc383d2009-11-19 11:55:19 +01002900 }
Felix Fietkau8b787642009-11-10 18:53:10 +01002901
Michael Wu66f7ac52008-01-31 19:48:22 +01002902 err = parse_monitor_flags(type == NL80211_IFTYPE_MONITOR ?
2903 info->attrs[NL80211_ATTR_MNTR_FLAGS] : NULL,
2904 &flags);
Felix Fietkaue057d3c2013-05-28 13:01:52 +02002905
Luciano Coelho18003292013-08-29 13:26:57 +03002906 if (!err && (flags & MONITOR_FLAG_ACTIVE) &&
Felix Fietkaue057d3c2013-05-28 13:01:52 +02002907 !(rdev->wiphy.features & NL80211_FEATURE_ACTIVE_MONITOR))
2908 return -EOPNOTSUPP;
2909
Johannes Berga18c7192015-02-24 10:56:42 +01002910 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
2911 if (!msg)
2912 return -ENOMEM;
2913
Hila Gonene35e4d22012-06-27 17:19:42 +03002914 wdev = rdev_add_virtual_intf(rdev,
2915 nla_data(info->attrs[NL80211_ATTR_IFNAME]),
Tom Gundersen6bab2e192015-03-18 11:13:39 +01002916 NET_NAME_USER, type, err ? NULL : &flags,
2917 &params);
Rafał Miłeckid687cbb2014-11-14 18:43:28 +01002918 if (WARN_ON(!wdev)) {
2919 nlmsg_free(msg);
2920 return -EPROTO;
2921 } else if (IS_ERR(wdev)) {
Johannes Berg1c90f9d2012-06-16 00:05:37 +02002922 nlmsg_free(msg);
Johannes Berg84efbb82012-06-16 00:00:26 +02002923 return PTR_ERR(wdev);
Johannes Berg1c90f9d2012-06-16 00:05:37 +02002924 }
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002925
Jukka Rissanen18e5ca62014-11-13 17:25:14 +02002926 if (info->attrs[NL80211_ATTR_SOCKET_OWNER])
Johannes Berg78f22b62014-03-24 17:57:27 +01002927 wdev->owner_nlportid = info->snd_portid;
2928
Johannes Berg98104fde2012-06-16 00:19:54 +02002929 switch (type) {
2930 case NL80211_IFTYPE_MESH_POINT:
2931 if (!info->attrs[NL80211_ATTR_MESH_ID])
2932 break;
Johannes Berg29cbe682010-12-03 09:20:44 +01002933 wdev_lock(wdev);
2934 BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN !=
2935 IEEE80211_MAX_MESH_ID_LEN);
2936 wdev->mesh_id_up_len =
2937 nla_len(info->attrs[NL80211_ATTR_MESH_ID]);
2938 memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]),
2939 wdev->mesh_id_up_len);
2940 wdev_unlock(wdev);
Johannes Berg98104fde2012-06-16 00:19:54 +02002941 break;
Ayala Bekercb3b7d82016-09-20 17:31:13 +03002942 case NL80211_IFTYPE_NAN:
Johannes Berg98104fde2012-06-16 00:19:54 +02002943 case NL80211_IFTYPE_P2P_DEVICE:
2944 /*
Ayala Bekercb3b7d82016-09-20 17:31:13 +03002945 * P2P Device and NAN do not have a netdev, so don't go
Johannes Berg98104fde2012-06-16 00:19:54 +02002946 * through the netdev notifier and must be added here
2947 */
2948 mutex_init(&wdev->mtx);
2949 INIT_LIST_HEAD(&wdev->event_list);
2950 spin_lock_init(&wdev->event_lock);
2951 INIT_LIST_HEAD(&wdev->mgmt_registrations);
2952 spin_lock_init(&wdev->mgmt_registrations_lock);
2953
Johannes Berg98104fde2012-06-16 00:19:54 +02002954 wdev->identifier = ++rdev->wdev_id;
Johannes Berg53873f12016-05-03 16:52:04 +03002955 list_add_rcu(&wdev->list, &rdev->wiphy.wdev_list);
Johannes Berg98104fde2012-06-16 00:19:54 +02002956 rdev->devlist_generation++;
Johannes Berg98104fde2012-06-16 00:19:54 +02002957 break;
2958 default:
2959 break;
Johannes Berg29cbe682010-12-03 09:20:44 +01002960 }
2961
Eric W. Biederman15e47302012-09-07 20:12:54 +00002962 if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0,
Tomasz Bursztyka8f894be2014-11-12 16:26:45 +02002963 rdev, wdev, false) < 0) {
Johannes Berg1c90f9d2012-06-16 00:05:37 +02002964 nlmsg_free(msg);
2965 return -ENOBUFS;
2966 }
2967
Denis Kenzior896ff062016-08-03 16:58:33 -05002968 /*
2969 * For wdevs which have no associated netdev object (e.g. of type
2970 * NL80211_IFTYPE_P2P_DEVICE), emit the NEW_INTERFACE event here.
2971 * For all other types, the event will be generated from the
2972 * netdev notifier
2973 */
2974 if (!wdev->netdev)
2975 nl80211_notify_iface(rdev, wdev, NL80211_CMD_NEW_INTERFACE);
Tomasz Bursztyka8f894be2014-11-12 16:26:45 +02002976
Johannes Berg1c90f9d2012-06-16 00:05:37 +02002977 return genlmsg_reply(msg, info);
Johannes Berg55682962007-09-20 13:09:35 -04002978}
2979
2980static int nl80211_del_interface(struct sk_buff *skb, struct genl_info *info)
2981{
Johannes Berg4c476992010-10-04 21:36:35 +02002982 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg84efbb82012-06-16 00:00:26 +02002983 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg55682962007-09-20 13:09:35 -04002984
Johannes Berg4c476992010-10-04 21:36:35 +02002985 if (!rdev->ops->del_virtual_intf)
2986 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01002987
Johannes Berg84efbb82012-06-16 00:00:26 +02002988 /*
2989 * If we remove a wireless device without a netdev then clear
2990 * user_ptr[1] so that nl80211_post_doit won't dereference it
2991 * to check if it needs to do dev_put(). Otherwise it crashes
2992 * since the wdev has been freed, unlike with a netdev where
2993 * we need the dev_put() for the netdev to really be freed.
2994 */
2995 if (!wdev->netdev)
2996 info->user_ptr[1] = NULL;
2997
Denis Kenzior7f8ed012016-08-03 16:58:35 -05002998 return rdev_del_virtual_intf(rdev, wdev);
Johannes Berg55682962007-09-20 13:09:35 -04002999}
3000
Simon Wunderlich1d9d9212011-11-18 14:20:43 +01003001static int nl80211_set_noack_map(struct sk_buff *skb, struct genl_info *info)
3002{
3003 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3004 struct net_device *dev = info->user_ptr[1];
3005 u16 noack_map;
3006
3007 if (!info->attrs[NL80211_ATTR_NOACK_MAP])
3008 return -EINVAL;
3009
3010 if (!rdev->ops->set_noack_map)
3011 return -EOPNOTSUPP;
3012
3013 noack_map = nla_get_u16(info->attrs[NL80211_ATTR_NOACK_MAP]);
3014
Hila Gonene35e4d22012-06-27 17:19:42 +03003015 return rdev_set_noack_map(rdev, dev, noack_map);
Simon Wunderlich1d9d9212011-11-18 14:20:43 +01003016}
3017
Johannes Berg41ade002007-12-19 02:03:29 +01003018struct get_key_cookie {
3019 struct sk_buff *msg;
3020 int error;
Johannes Bergb9454e82009-07-08 13:29:08 +02003021 int idx;
Johannes Berg41ade002007-12-19 02:03:29 +01003022};
3023
3024static void get_key_callback(void *c, struct key_params *params)
3025{
Johannes Bergb9454e82009-07-08 13:29:08 +02003026 struct nlattr *key;
Johannes Berg41ade002007-12-19 02:03:29 +01003027 struct get_key_cookie *cookie = c;
3028
David S. Miller9360ffd2012-03-29 04:41:26 -04003029 if ((params->key &&
3030 nla_put(cookie->msg, NL80211_ATTR_KEY_DATA,
3031 params->key_len, params->key)) ||
3032 (params->seq &&
3033 nla_put(cookie->msg, NL80211_ATTR_KEY_SEQ,
3034 params->seq_len, params->seq)) ||
3035 (params->cipher &&
3036 nla_put_u32(cookie->msg, NL80211_ATTR_KEY_CIPHER,
3037 params->cipher)))
3038 goto nla_put_failure;
Johannes Berg41ade002007-12-19 02:03:29 +01003039
Johannes Bergb9454e82009-07-08 13:29:08 +02003040 key = nla_nest_start(cookie->msg, NL80211_ATTR_KEY);
3041 if (!key)
3042 goto nla_put_failure;
3043
David S. Miller9360ffd2012-03-29 04:41:26 -04003044 if ((params->key &&
3045 nla_put(cookie->msg, NL80211_KEY_DATA,
3046 params->key_len, params->key)) ||
3047 (params->seq &&
3048 nla_put(cookie->msg, NL80211_KEY_SEQ,
3049 params->seq_len, params->seq)) ||
3050 (params->cipher &&
3051 nla_put_u32(cookie->msg, NL80211_KEY_CIPHER,
3052 params->cipher)))
3053 goto nla_put_failure;
Johannes Bergb9454e82009-07-08 13:29:08 +02003054
David S. Miller9360ffd2012-03-29 04:41:26 -04003055 if (nla_put_u8(cookie->msg, NL80211_ATTR_KEY_IDX, cookie->idx))
3056 goto nla_put_failure;
Johannes Bergb9454e82009-07-08 13:29:08 +02003057
3058 nla_nest_end(cookie->msg, key);
3059
Johannes Berg41ade002007-12-19 02:03:29 +01003060 return;
3061 nla_put_failure:
3062 cookie->error = 1;
3063}
3064
3065static int nl80211_get_key(struct sk_buff *skb, struct genl_info *info)
3066{
Johannes Berg4c476992010-10-04 21:36:35 +02003067 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg41ade002007-12-19 02:03:29 +01003068 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02003069 struct net_device *dev = info->user_ptr[1];
Johannes Berg41ade002007-12-19 02:03:29 +01003070 u8 key_idx = 0;
Johannes Berge31b8212010-10-05 19:39:30 +02003071 const u8 *mac_addr = NULL;
3072 bool pairwise;
Johannes Berg41ade002007-12-19 02:03:29 +01003073 struct get_key_cookie cookie = {
3074 .error = 0,
3075 };
3076 void *hdr;
3077 struct sk_buff *msg;
3078
3079 if (info->attrs[NL80211_ATTR_KEY_IDX])
3080 key_idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]);
3081
Jouni Malinen3cfcf6ac2009-01-08 13:32:02 +02003082 if (key_idx > 5)
Johannes Berg41ade002007-12-19 02:03:29 +01003083 return -EINVAL;
3084
3085 if (info->attrs[NL80211_ATTR_MAC])
3086 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
3087
Johannes Berge31b8212010-10-05 19:39:30 +02003088 pairwise = !!mac_addr;
3089 if (info->attrs[NL80211_ATTR_KEY_TYPE]) {
3090 u32 kt = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]);
Kirtika Ruchandani7a087e72016-05-29 19:51:23 -07003091
Johannes Berge31b8212010-10-05 19:39:30 +02003092 if (kt >= NUM_NL80211_KEYTYPES)
3093 return -EINVAL;
3094 if (kt != NL80211_KEYTYPE_GROUP &&
3095 kt != NL80211_KEYTYPE_PAIRWISE)
3096 return -EINVAL;
3097 pairwise = kt == NL80211_KEYTYPE_PAIRWISE;
3098 }
3099
Johannes Berg4c476992010-10-04 21:36:35 +02003100 if (!rdev->ops->get_key)
3101 return -EOPNOTSUPP;
Johannes Berg41ade002007-12-19 02:03:29 +01003102
Johannes Berg0fa7b392015-01-23 11:10:12 +01003103 if (!pairwise && mac_addr && !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN))
3104 return -ENOENT;
3105
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07003106 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02003107 if (!msg)
3108 return -ENOMEM;
Johannes Berg41ade002007-12-19 02:03:29 +01003109
Eric W. Biederman15e47302012-09-07 20:12:54 +00003110 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berg41ade002007-12-19 02:03:29 +01003111 NL80211_CMD_NEW_KEY);
Dan Carpentercb35fba2013-08-14 14:50:01 +03003112 if (!hdr)
Johannes Berg9fe271a2013-10-25 11:15:12 +02003113 goto nla_put_failure;
Johannes Berg41ade002007-12-19 02:03:29 +01003114
3115 cookie.msg = msg;
Johannes Bergb9454e82009-07-08 13:29:08 +02003116 cookie.idx = key_idx;
Johannes Berg41ade002007-12-19 02:03:29 +01003117
David S. Miller9360ffd2012-03-29 04:41:26 -04003118 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
3119 nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_idx))
3120 goto nla_put_failure;
3121 if (mac_addr &&
3122 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr))
3123 goto nla_put_failure;
Johannes Berg41ade002007-12-19 02:03:29 +01003124
Hila Gonene35e4d22012-06-27 17:19:42 +03003125 err = rdev_get_key(rdev, dev, key_idx, pairwise, mac_addr, &cookie,
3126 get_key_callback);
Johannes Berg41ade002007-12-19 02:03:29 +01003127
3128 if (err)
Niko Jokinen6c95e2a2009-07-15 11:00:53 +03003129 goto free_msg;
Johannes Berg41ade002007-12-19 02:03:29 +01003130
3131 if (cookie.error)
3132 goto nla_put_failure;
3133
3134 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02003135 return genlmsg_reply(msg, info);
Johannes Berg41ade002007-12-19 02:03:29 +01003136
3137 nla_put_failure:
3138 err = -ENOBUFS;
Niko Jokinen6c95e2a2009-07-15 11:00:53 +03003139 free_msg:
Johannes Berg41ade002007-12-19 02:03:29 +01003140 nlmsg_free(msg);
Johannes Berg41ade002007-12-19 02:03:29 +01003141 return err;
3142}
3143
3144static int nl80211_set_key(struct sk_buff *skb, struct genl_info *info)
3145{
Johannes Berg4c476992010-10-04 21:36:35 +02003146 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Bergb9454e82009-07-08 13:29:08 +02003147 struct key_parse key;
Johannes Berg41ade002007-12-19 02:03:29 +01003148 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02003149 struct net_device *dev = info->user_ptr[1];
Johannes Berg41ade002007-12-19 02:03:29 +01003150
Johannes Bergb9454e82009-07-08 13:29:08 +02003151 err = nl80211_parse_key(info, &key);
3152 if (err)
3153 return err;
3154
3155 if (key.idx < 0)
Johannes Berg41ade002007-12-19 02:03:29 +01003156 return -EINVAL;
3157
Johannes Bergb9454e82009-07-08 13:29:08 +02003158 /* only support setting default key */
3159 if (!key.def && !key.defmgmt)
Johannes Berg41ade002007-12-19 02:03:29 +01003160 return -EINVAL;
3161
Johannes Bergfffd0932009-07-08 14:22:54 +02003162 wdev_lock(dev->ieee80211_ptr);
Johannes Bergdbd2fd62010-12-09 19:58:59 +01003163
3164 if (key.def) {
3165 if (!rdev->ops->set_default_key) {
3166 err = -EOPNOTSUPP;
3167 goto out;
3168 }
3169
3170 err = nl80211_key_allowed(dev->ieee80211_ptr);
3171 if (err)
3172 goto out;
3173
Hila Gonene35e4d22012-06-27 17:19:42 +03003174 err = rdev_set_default_key(rdev, dev, key.idx,
Johannes Bergdbd2fd62010-12-09 19:58:59 +01003175 key.def_uni, key.def_multi);
3176
3177 if (err)
3178 goto out;
Johannes Bergfffd0932009-07-08 14:22:54 +02003179
Johannes Berg3d23e342009-09-29 23:27:28 +02003180#ifdef CONFIG_CFG80211_WEXT
Johannes Bergdbd2fd62010-12-09 19:58:59 +01003181 dev->ieee80211_ptr->wext.default_key = key.idx;
Johannes Berg08645122009-05-11 13:54:58 +02003182#endif
Johannes Bergdbd2fd62010-12-09 19:58:59 +01003183 } else {
3184 if (key.def_uni || !key.def_multi) {
3185 err = -EINVAL;
3186 goto out;
3187 }
3188
3189 if (!rdev->ops->set_default_mgmt_key) {
3190 err = -EOPNOTSUPP;
3191 goto out;
3192 }
3193
3194 err = nl80211_key_allowed(dev->ieee80211_ptr);
3195 if (err)
3196 goto out;
3197
Hila Gonene35e4d22012-06-27 17:19:42 +03003198 err = rdev_set_default_mgmt_key(rdev, dev, key.idx);
Johannes Bergdbd2fd62010-12-09 19:58:59 +01003199 if (err)
3200 goto out;
3201
3202#ifdef CONFIG_CFG80211_WEXT
3203 dev->ieee80211_ptr->wext.default_mgmt_key = key.idx;
3204#endif
3205 }
3206
3207 out:
Johannes Bergfffd0932009-07-08 14:22:54 +02003208 wdev_unlock(dev->ieee80211_ptr);
Johannes Berg41ade002007-12-19 02:03:29 +01003209
Johannes Berg41ade002007-12-19 02:03:29 +01003210 return err;
3211}
3212
3213static int nl80211_new_key(struct sk_buff *skb, struct genl_info *info)
3214{
Johannes Berg4c476992010-10-04 21:36:35 +02003215 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Bergfffd0932009-07-08 14:22:54 +02003216 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02003217 struct net_device *dev = info->user_ptr[1];
Johannes Bergb9454e82009-07-08 13:29:08 +02003218 struct key_parse key;
Johannes Berge31b8212010-10-05 19:39:30 +02003219 const u8 *mac_addr = NULL;
Johannes Berg41ade002007-12-19 02:03:29 +01003220
Johannes Bergb9454e82009-07-08 13:29:08 +02003221 err = nl80211_parse_key(info, &key);
3222 if (err)
3223 return err;
Johannes Berg41ade002007-12-19 02:03:29 +01003224
Johannes Bergb9454e82009-07-08 13:29:08 +02003225 if (!key.p.key)
Johannes Berg41ade002007-12-19 02:03:29 +01003226 return -EINVAL;
3227
Johannes Berg41ade002007-12-19 02:03:29 +01003228 if (info->attrs[NL80211_ATTR_MAC])
3229 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
3230
Johannes Berge31b8212010-10-05 19:39:30 +02003231 if (key.type == -1) {
3232 if (mac_addr)
3233 key.type = NL80211_KEYTYPE_PAIRWISE;
3234 else
3235 key.type = NL80211_KEYTYPE_GROUP;
3236 }
3237
3238 /* for now */
3239 if (key.type != NL80211_KEYTYPE_PAIRWISE &&
3240 key.type != NL80211_KEYTYPE_GROUP)
3241 return -EINVAL;
3242
Johannes Berg4c476992010-10-04 21:36:35 +02003243 if (!rdev->ops->add_key)
3244 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01003245
Johannes Berge31b8212010-10-05 19:39:30 +02003246 if (cfg80211_validate_key_settings(rdev, &key.p, key.idx,
3247 key.type == NL80211_KEYTYPE_PAIRWISE,
3248 mac_addr))
Johannes Berg4c476992010-10-04 21:36:35 +02003249 return -EINVAL;
Johannes Bergfffd0932009-07-08 14:22:54 +02003250
3251 wdev_lock(dev->ieee80211_ptr);
3252 err = nl80211_key_allowed(dev->ieee80211_ptr);
3253 if (!err)
Hila Gonene35e4d22012-06-27 17:19:42 +03003254 err = rdev_add_key(rdev, dev, key.idx,
3255 key.type == NL80211_KEYTYPE_PAIRWISE,
3256 mac_addr, &key.p);
Johannes Bergfffd0932009-07-08 14:22:54 +02003257 wdev_unlock(dev->ieee80211_ptr);
Johannes Berg41ade002007-12-19 02:03:29 +01003258
Johannes Berg41ade002007-12-19 02:03:29 +01003259 return err;
3260}
3261
3262static int nl80211_del_key(struct sk_buff *skb, struct genl_info *info)
3263{
Johannes Berg4c476992010-10-04 21:36:35 +02003264 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg41ade002007-12-19 02:03:29 +01003265 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02003266 struct net_device *dev = info->user_ptr[1];
Johannes Berg41ade002007-12-19 02:03:29 +01003267 u8 *mac_addr = NULL;
Johannes Bergb9454e82009-07-08 13:29:08 +02003268 struct key_parse key;
Johannes Berg41ade002007-12-19 02:03:29 +01003269
Johannes Bergb9454e82009-07-08 13:29:08 +02003270 err = nl80211_parse_key(info, &key);
3271 if (err)
3272 return err;
Johannes Berg41ade002007-12-19 02:03:29 +01003273
3274 if (info->attrs[NL80211_ATTR_MAC])
3275 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
3276
Johannes Berge31b8212010-10-05 19:39:30 +02003277 if (key.type == -1) {
3278 if (mac_addr)
3279 key.type = NL80211_KEYTYPE_PAIRWISE;
3280 else
3281 key.type = NL80211_KEYTYPE_GROUP;
3282 }
3283
3284 /* for now */
3285 if (key.type != NL80211_KEYTYPE_PAIRWISE &&
3286 key.type != NL80211_KEYTYPE_GROUP)
3287 return -EINVAL;
3288
Johannes Berg4c476992010-10-04 21:36:35 +02003289 if (!rdev->ops->del_key)
3290 return -EOPNOTSUPP;
Johannes Berg41ade002007-12-19 02:03:29 +01003291
Johannes Bergfffd0932009-07-08 14:22:54 +02003292 wdev_lock(dev->ieee80211_ptr);
3293 err = nl80211_key_allowed(dev->ieee80211_ptr);
Johannes Berge31b8212010-10-05 19:39:30 +02003294
Johannes Berg0fa7b392015-01-23 11:10:12 +01003295 if (key.type == NL80211_KEYTYPE_GROUP && mac_addr &&
Johannes Berge31b8212010-10-05 19:39:30 +02003296 !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN))
3297 err = -ENOENT;
3298
Johannes Bergfffd0932009-07-08 14:22:54 +02003299 if (!err)
Hila Gonene35e4d22012-06-27 17:19:42 +03003300 err = rdev_del_key(rdev, dev, key.idx,
3301 key.type == NL80211_KEYTYPE_PAIRWISE,
3302 mac_addr);
Johannes Berg41ade002007-12-19 02:03:29 +01003303
Johannes Berg3d23e342009-09-29 23:27:28 +02003304#ifdef CONFIG_CFG80211_WEXT
Johannes Berg08645122009-05-11 13:54:58 +02003305 if (!err) {
Johannes Bergb9454e82009-07-08 13:29:08 +02003306 if (key.idx == dev->ieee80211_ptr->wext.default_key)
Johannes Berg08645122009-05-11 13:54:58 +02003307 dev->ieee80211_ptr->wext.default_key = -1;
Johannes Bergb9454e82009-07-08 13:29:08 +02003308 else if (key.idx == dev->ieee80211_ptr->wext.default_mgmt_key)
Johannes Berg08645122009-05-11 13:54:58 +02003309 dev->ieee80211_ptr->wext.default_mgmt_key = -1;
3310 }
3311#endif
Johannes Bergfffd0932009-07-08 14:22:54 +02003312 wdev_unlock(dev->ieee80211_ptr);
Johannes Berg08645122009-05-11 13:54:58 +02003313
Johannes Berg41ade002007-12-19 02:03:29 +01003314 return err;
3315}
3316
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +05303317/* This function returns an error or the number of nested attributes */
3318static int validate_acl_mac_addrs(struct nlattr *nl_attr)
3319{
3320 struct nlattr *attr;
3321 int n_entries = 0, tmp;
3322
3323 nla_for_each_nested(attr, nl_attr, tmp) {
3324 if (nla_len(attr) != ETH_ALEN)
3325 return -EINVAL;
3326
3327 n_entries++;
3328 }
3329
3330 return n_entries;
3331}
3332
3333/*
3334 * This function parses ACL information and allocates memory for ACL data.
3335 * On successful return, the calling function is responsible to free the
3336 * ACL buffer returned by this function.
3337 */
3338static struct cfg80211_acl_data *parse_acl_data(struct wiphy *wiphy,
3339 struct genl_info *info)
3340{
3341 enum nl80211_acl_policy acl_policy;
3342 struct nlattr *attr;
3343 struct cfg80211_acl_data *acl;
3344 int i = 0, n_entries, tmp;
3345
3346 if (!wiphy->max_acl_mac_addrs)
3347 return ERR_PTR(-EOPNOTSUPP);
3348
3349 if (!info->attrs[NL80211_ATTR_ACL_POLICY])
3350 return ERR_PTR(-EINVAL);
3351
3352 acl_policy = nla_get_u32(info->attrs[NL80211_ATTR_ACL_POLICY]);
3353 if (acl_policy != NL80211_ACL_POLICY_ACCEPT_UNLESS_LISTED &&
3354 acl_policy != NL80211_ACL_POLICY_DENY_UNLESS_LISTED)
3355 return ERR_PTR(-EINVAL);
3356
3357 if (!info->attrs[NL80211_ATTR_MAC_ADDRS])
3358 return ERR_PTR(-EINVAL);
3359
3360 n_entries = validate_acl_mac_addrs(info->attrs[NL80211_ATTR_MAC_ADDRS]);
3361 if (n_entries < 0)
3362 return ERR_PTR(n_entries);
3363
3364 if (n_entries > wiphy->max_acl_mac_addrs)
3365 return ERR_PTR(-ENOTSUPP);
3366
3367 acl = kzalloc(sizeof(*acl) + (sizeof(struct mac_address) * n_entries),
3368 GFP_KERNEL);
3369 if (!acl)
3370 return ERR_PTR(-ENOMEM);
3371
3372 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_MAC_ADDRS], tmp) {
3373 memcpy(acl->mac_addrs[i].addr, nla_data(attr), ETH_ALEN);
3374 i++;
3375 }
3376
3377 acl->n_acl_entries = n_entries;
3378 acl->acl_policy = acl_policy;
3379
3380 return acl;
3381}
3382
3383static int nl80211_set_mac_acl(struct sk_buff *skb, struct genl_info *info)
3384{
3385 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3386 struct net_device *dev = info->user_ptr[1];
3387 struct cfg80211_acl_data *acl;
3388 int err;
3389
3390 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
3391 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
3392 return -EOPNOTSUPP;
3393
3394 if (!dev->ieee80211_ptr->beacon_interval)
3395 return -EINVAL;
3396
3397 acl = parse_acl_data(&rdev->wiphy, info);
3398 if (IS_ERR(acl))
3399 return PTR_ERR(acl);
3400
3401 err = rdev_set_mac_acl(rdev, dev, acl);
3402
3403 kfree(acl);
3404
3405 return err;
3406}
3407
Purushottam Kushwahaa7c7fbf2016-09-14 17:38:44 +05303408static u32 rateset_to_mask(struct ieee80211_supported_band *sband,
3409 u8 *rates, u8 rates_len)
3410{
3411 u8 i;
3412 u32 mask = 0;
3413
3414 for (i = 0; i < rates_len; i++) {
3415 int rate = (rates[i] & 0x7f) * 5;
3416 int ridx;
3417
3418 for (ridx = 0; ridx < sband->n_bitrates; ridx++) {
3419 struct ieee80211_rate *srate =
3420 &sband->bitrates[ridx];
3421 if (rate == srate->bitrate) {
3422 mask |= 1 << ridx;
3423 break;
3424 }
3425 }
3426 if (ridx == sband->n_bitrates)
3427 return 0; /* rate not found */
3428 }
3429
3430 return mask;
3431}
3432
3433static bool ht_rateset_to_mask(struct ieee80211_supported_band *sband,
3434 u8 *rates, u8 rates_len,
3435 u8 mcs[IEEE80211_HT_MCS_MASK_LEN])
3436{
3437 u8 i;
3438
3439 memset(mcs, 0, IEEE80211_HT_MCS_MASK_LEN);
3440
3441 for (i = 0; i < rates_len; i++) {
3442 int ridx, rbit;
3443
3444 ridx = rates[i] / 8;
3445 rbit = BIT(rates[i] % 8);
3446
3447 /* check validity */
3448 if ((ridx < 0) || (ridx >= IEEE80211_HT_MCS_MASK_LEN))
3449 return false;
3450
3451 /* check availability */
3452 if (sband->ht_cap.mcs.rx_mask[ridx] & rbit)
3453 mcs[ridx] |= rbit;
3454 else
3455 return false;
3456 }
3457
3458 return true;
3459}
3460
3461static u16 vht_mcs_map_to_mcs_mask(u8 vht_mcs_map)
3462{
3463 u16 mcs_mask = 0;
3464
3465 switch (vht_mcs_map) {
3466 case IEEE80211_VHT_MCS_NOT_SUPPORTED:
3467 break;
3468 case IEEE80211_VHT_MCS_SUPPORT_0_7:
3469 mcs_mask = 0x00FF;
3470 break;
3471 case IEEE80211_VHT_MCS_SUPPORT_0_8:
3472 mcs_mask = 0x01FF;
3473 break;
3474 case IEEE80211_VHT_MCS_SUPPORT_0_9:
3475 mcs_mask = 0x03FF;
3476 break;
3477 default:
3478 break;
3479 }
3480
3481 return mcs_mask;
3482}
3483
3484static void vht_build_mcs_mask(u16 vht_mcs_map,
3485 u16 vht_mcs_mask[NL80211_VHT_NSS_MAX])
3486{
3487 u8 nss;
3488
3489 for (nss = 0; nss < NL80211_VHT_NSS_MAX; nss++) {
3490 vht_mcs_mask[nss] = vht_mcs_map_to_mcs_mask(vht_mcs_map & 0x03);
3491 vht_mcs_map >>= 2;
3492 }
3493}
3494
3495static bool vht_set_mcs_mask(struct ieee80211_supported_band *sband,
3496 struct nl80211_txrate_vht *txrate,
3497 u16 mcs[NL80211_VHT_NSS_MAX])
3498{
3499 u16 tx_mcs_map = le16_to_cpu(sband->vht_cap.vht_mcs.tx_mcs_map);
3500 u16 tx_mcs_mask[NL80211_VHT_NSS_MAX] = {};
3501 u8 i;
3502
3503 if (!sband->vht_cap.vht_supported)
3504 return false;
3505
3506 memset(mcs, 0, sizeof(u16) * NL80211_VHT_NSS_MAX);
3507
3508 /* Build vht_mcs_mask from VHT capabilities */
3509 vht_build_mcs_mask(tx_mcs_map, tx_mcs_mask);
3510
3511 for (i = 0; i < NL80211_VHT_NSS_MAX; i++) {
3512 if ((tx_mcs_mask[i] & txrate->mcs[i]) == txrate->mcs[i])
3513 mcs[i] = txrate->mcs[i];
3514 else
3515 return false;
3516 }
3517
3518 return true;
3519}
3520
3521static const struct nla_policy nl80211_txattr_policy[NL80211_TXRATE_MAX + 1] = {
3522 [NL80211_TXRATE_LEGACY] = { .type = NLA_BINARY,
3523 .len = NL80211_MAX_SUPP_RATES },
3524 [NL80211_TXRATE_HT] = { .type = NLA_BINARY,
3525 .len = NL80211_MAX_SUPP_HT_RATES },
3526 [NL80211_TXRATE_VHT] = { .len = sizeof(struct nl80211_txrate_vht)},
3527 [NL80211_TXRATE_GI] = { .type = NLA_U8 },
3528};
3529
3530static int nl80211_parse_tx_bitrate_mask(struct genl_info *info,
3531 struct cfg80211_bitrate_mask *mask)
3532{
3533 struct nlattr *tb[NL80211_TXRATE_MAX + 1];
3534 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3535 int rem, i;
3536 struct nlattr *tx_rates;
3537 struct ieee80211_supported_band *sband;
3538 u16 vht_tx_mcs_map;
3539
3540 memset(mask, 0, sizeof(*mask));
3541 /* Default to all rates enabled */
3542 for (i = 0; i < NUM_NL80211_BANDS; i++) {
3543 sband = rdev->wiphy.bands[i];
3544
3545 if (!sband)
3546 continue;
3547
3548 mask->control[i].legacy = (1 << sband->n_bitrates) - 1;
3549 memcpy(mask->control[i].ht_mcs,
3550 sband->ht_cap.mcs.rx_mask,
3551 sizeof(mask->control[i].ht_mcs));
3552
3553 if (!sband->vht_cap.vht_supported)
3554 continue;
3555
3556 vht_tx_mcs_map = le16_to_cpu(sband->vht_cap.vht_mcs.tx_mcs_map);
3557 vht_build_mcs_mask(vht_tx_mcs_map, mask->control[i].vht_mcs);
3558 }
3559
3560 /* if no rates are given set it back to the defaults */
3561 if (!info->attrs[NL80211_ATTR_TX_RATES])
3562 goto out;
3563
3564 /* The nested attribute uses enum nl80211_band as the index. This maps
3565 * directly to the enum nl80211_band values used in cfg80211.
3566 */
3567 BUILD_BUG_ON(NL80211_MAX_SUPP_HT_RATES > IEEE80211_HT_MCS_MASK_LEN * 8);
3568 nla_for_each_nested(tx_rates, info->attrs[NL80211_ATTR_TX_RATES], rem) {
3569 enum nl80211_band band = nla_type(tx_rates);
3570 int err;
3571
3572 if (band < 0 || band >= NUM_NL80211_BANDS)
3573 return -EINVAL;
3574 sband = rdev->wiphy.bands[band];
3575 if (sband == NULL)
3576 return -EINVAL;
Johannes Bergbfe2c7b2016-10-26 14:42:21 +02003577 err = nla_parse_nested(tb, NL80211_TXRATE_MAX, tx_rates,
3578 nl80211_txattr_policy);
Purushottam Kushwahaa7c7fbf2016-09-14 17:38:44 +05303579 if (err)
3580 return err;
3581 if (tb[NL80211_TXRATE_LEGACY]) {
3582 mask->control[band].legacy = rateset_to_mask(
3583 sband,
3584 nla_data(tb[NL80211_TXRATE_LEGACY]),
3585 nla_len(tb[NL80211_TXRATE_LEGACY]));
3586 if ((mask->control[band].legacy == 0) &&
3587 nla_len(tb[NL80211_TXRATE_LEGACY]))
3588 return -EINVAL;
3589 }
3590 if (tb[NL80211_TXRATE_HT]) {
3591 if (!ht_rateset_to_mask(
3592 sband,
3593 nla_data(tb[NL80211_TXRATE_HT]),
3594 nla_len(tb[NL80211_TXRATE_HT]),
3595 mask->control[band].ht_mcs))
3596 return -EINVAL;
3597 }
3598 if (tb[NL80211_TXRATE_VHT]) {
3599 if (!vht_set_mcs_mask(
3600 sband,
3601 nla_data(tb[NL80211_TXRATE_VHT]),
3602 mask->control[band].vht_mcs))
3603 return -EINVAL;
3604 }
3605 if (tb[NL80211_TXRATE_GI]) {
3606 mask->control[band].gi =
3607 nla_get_u8(tb[NL80211_TXRATE_GI]);
3608 if (mask->control[band].gi > NL80211_TXRATE_FORCE_LGI)
3609 return -EINVAL;
3610 }
3611
3612 if (mask->control[band].legacy == 0) {
3613 /* don't allow empty legacy rates if HT or VHT
3614 * are not even supported.
3615 */
3616 if (!(rdev->wiphy.bands[band]->ht_cap.ht_supported ||
3617 rdev->wiphy.bands[band]->vht_cap.vht_supported))
3618 return -EINVAL;
3619
3620 for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++)
3621 if (mask->control[band].ht_mcs[i])
3622 goto out;
3623
3624 for (i = 0; i < NL80211_VHT_NSS_MAX; i++)
3625 if (mask->control[band].vht_mcs[i])
3626 goto out;
3627
3628 /* legacy and mcs rates may not be both empty */
3629 return -EINVAL;
3630 }
3631 }
3632
3633out:
3634 return 0;
3635}
3636
Johannes Berg8564e382016-09-19 09:44:44 +02003637static int validate_beacon_tx_rate(struct cfg80211_registered_device *rdev,
3638 enum nl80211_band band,
3639 struct cfg80211_bitrate_mask *beacon_rate)
Purushottam Kushwahaa7c7fbf2016-09-14 17:38:44 +05303640{
Johannes Berg8564e382016-09-19 09:44:44 +02003641 u32 count_ht, count_vht, i;
3642 u32 rate = beacon_rate->control[band].legacy;
Purushottam Kushwahaa7c7fbf2016-09-14 17:38:44 +05303643
3644 /* Allow only one rate */
3645 if (hweight32(rate) > 1)
3646 return -EINVAL;
3647
3648 count_ht = 0;
3649 for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++) {
Johannes Berg8564e382016-09-19 09:44:44 +02003650 if (hweight8(beacon_rate->control[band].ht_mcs[i]) > 1) {
Purushottam Kushwahaa7c7fbf2016-09-14 17:38:44 +05303651 return -EINVAL;
Johannes Berg8564e382016-09-19 09:44:44 +02003652 } else if (beacon_rate->control[band].ht_mcs[i]) {
Purushottam Kushwahaa7c7fbf2016-09-14 17:38:44 +05303653 count_ht++;
3654 if (count_ht > 1)
3655 return -EINVAL;
3656 }
3657 if (count_ht && rate)
3658 return -EINVAL;
3659 }
3660
3661 count_vht = 0;
3662 for (i = 0; i < NL80211_VHT_NSS_MAX; i++) {
Johannes Berg8564e382016-09-19 09:44:44 +02003663 if (hweight16(beacon_rate->control[band].vht_mcs[i]) > 1) {
Purushottam Kushwahaa7c7fbf2016-09-14 17:38:44 +05303664 return -EINVAL;
Johannes Berg8564e382016-09-19 09:44:44 +02003665 } else if (beacon_rate->control[band].vht_mcs[i]) {
Purushottam Kushwahaa7c7fbf2016-09-14 17:38:44 +05303666 count_vht++;
3667 if (count_vht > 1)
3668 return -EINVAL;
3669 }
3670 if (count_vht && rate)
3671 return -EINVAL;
3672 }
3673
3674 if ((count_ht && count_vht) || (!rate && !count_ht && !count_vht))
3675 return -EINVAL;
3676
Johannes Berg8564e382016-09-19 09:44:44 +02003677 if (rate &&
3678 !wiphy_ext_feature_isset(&rdev->wiphy,
3679 NL80211_EXT_FEATURE_BEACON_RATE_LEGACY))
3680 return -EINVAL;
3681 if (count_ht &&
3682 !wiphy_ext_feature_isset(&rdev->wiphy,
3683 NL80211_EXT_FEATURE_BEACON_RATE_HT))
3684 return -EINVAL;
3685 if (count_vht &&
3686 !wiphy_ext_feature_isset(&rdev->wiphy,
3687 NL80211_EXT_FEATURE_BEACON_RATE_VHT))
3688 return -EINVAL;
3689
Purushottam Kushwahaa7c7fbf2016-09-14 17:38:44 +05303690 return 0;
3691}
3692
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003693static int nl80211_parse_beacon(struct nlattr *attrs[],
Johannes Berg88600202012-02-13 15:17:18 +01003694 struct cfg80211_beacon_data *bcn)
Johannes Berged1b6cc2007-12-19 02:03:32 +01003695{
Johannes Berg88600202012-02-13 15:17:18 +01003696 bool haveinfo = false;
Johannes Berged1b6cc2007-12-19 02:03:32 +01003697
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003698 if (!is_valid_ie_attr(attrs[NL80211_ATTR_BEACON_TAIL]) ||
3699 !is_valid_ie_attr(attrs[NL80211_ATTR_IE]) ||
3700 !is_valid_ie_attr(attrs[NL80211_ATTR_IE_PROBE_RESP]) ||
3701 !is_valid_ie_attr(attrs[NL80211_ATTR_IE_ASSOC_RESP]))
Johannes Bergf4a11bb2009-03-27 12:40:28 +01003702 return -EINVAL;
3703
Johannes Berg88600202012-02-13 15:17:18 +01003704 memset(bcn, 0, sizeof(*bcn));
Johannes Berged1b6cc2007-12-19 02:03:32 +01003705
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003706 if (attrs[NL80211_ATTR_BEACON_HEAD]) {
3707 bcn->head = nla_data(attrs[NL80211_ATTR_BEACON_HEAD]);
3708 bcn->head_len = nla_len(attrs[NL80211_ATTR_BEACON_HEAD]);
Johannes Berg88600202012-02-13 15:17:18 +01003709 if (!bcn->head_len)
3710 return -EINVAL;
3711 haveinfo = true;
Johannes Berged1b6cc2007-12-19 02:03:32 +01003712 }
3713
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003714 if (attrs[NL80211_ATTR_BEACON_TAIL]) {
3715 bcn->tail = nla_data(attrs[NL80211_ATTR_BEACON_TAIL]);
3716 bcn->tail_len = nla_len(attrs[NL80211_ATTR_BEACON_TAIL]);
Johannes Berg88600202012-02-13 15:17:18 +01003717 haveinfo = true;
Johannes Berged1b6cc2007-12-19 02:03:32 +01003718 }
3719
Johannes Berg4c476992010-10-04 21:36:35 +02003720 if (!haveinfo)
3721 return -EINVAL;
Johannes Berged1b6cc2007-12-19 02:03:32 +01003722
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003723 if (attrs[NL80211_ATTR_IE]) {
3724 bcn->beacon_ies = nla_data(attrs[NL80211_ATTR_IE]);
3725 bcn->beacon_ies_len = nla_len(attrs[NL80211_ATTR_IE]);
Jouni Malinen9946ecf2011-08-10 23:55:56 +03003726 }
3727
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003728 if (attrs[NL80211_ATTR_IE_PROBE_RESP]) {
Johannes Berg88600202012-02-13 15:17:18 +01003729 bcn->proberesp_ies =
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003730 nla_data(attrs[NL80211_ATTR_IE_PROBE_RESP]);
Johannes Berg88600202012-02-13 15:17:18 +01003731 bcn->proberesp_ies_len =
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003732 nla_len(attrs[NL80211_ATTR_IE_PROBE_RESP]);
Jouni Malinen9946ecf2011-08-10 23:55:56 +03003733 }
3734
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003735 if (attrs[NL80211_ATTR_IE_ASSOC_RESP]) {
Johannes Berg88600202012-02-13 15:17:18 +01003736 bcn->assocresp_ies =
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003737 nla_data(attrs[NL80211_ATTR_IE_ASSOC_RESP]);
Johannes Berg88600202012-02-13 15:17:18 +01003738 bcn->assocresp_ies_len =
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003739 nla_len(attrs[NL80211_ATTR_IE_ASSOC_RESP]);
Jouni Malinen9946ecf2011-08-10 23:55:56 +03003740 }
3741
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003742 if (attrs[NL80211_ATTR_PROBE_RESP]) {
3743 bcn->probe_resp = nla_data(attrs[NL80211_ATTR_PROBE_RESP]);
3744 bcn->probe_resp_len = nla_len(attrs[NL80211_ATTR_PROBE_RESP]);
Arik Nemtsov00f740e2011-11-10 11:28:56 +02003745 }
3746
Johannes Berg88600202012-02-13 15:17:18 +01003747 return 0;
3748}
3749
Johannes Berg66cd7942017-02-07 22:40:44 +02003750static void nl80211_check_ap_rate_selectors(struct cfg80211_ap_settings *params,
3751 const u8 *rates)
3752{
3753 int i;
3754
3755 if (!rates)
3756 return;
3757
3758 for (i = 0; i < rates[1]; i++) {
3759 if (rates[2 + i] == BSS_MEMBERSHIP_SELECTOR_HT_PHY)
3760 params->ht_required = true;
3761 if (rates[2 + i] == BSS_MEMBERSHIP_SELECTOR_VHT_PHY)
3762 params->vht_required = true;
3763 }
3764}
3765
3766/*
3767 * Since the nl80211 API didn't include, from the beginning, attributes about
3768 * HT/VHT requirements/capabilities, we parse them out of the IEs for the
3769 * benefit of drivers that rebuild IEs in the firmware.
3770 */
3771static void nl80211_calculate_ap_params(struct cfg80211_ap_settings *params)
3772{
3773 const struct cfg80211_beacon_data *bcn = &params->beacon;
3774 size_t ies_len = bcn->beacon_ies_len;
3775 const u8 *ies = bcn->beacon_ies;
3776 const u8 *rates;
3777 const u8 *cap;
3778
3779 rates = cfg80211_find_ie(WLAN_EID_SUPP_RATES, ies, ies_len);
3780 nl80211_check_ap_rate_selectors(params, rates);
3781
3782 rates = cfg80211_find_ie(WLAN_EID_EXT_SUPP_RATES, ies, ies_len);
3783 nl80211_check_ap_rate_selectors(params, rates);
3784
3785 cap = cfg80211_find_ie(WLAN_EID_HT_CAPABILITY, ies, ies_len);
3786 if (cap && cap[1] >= sizeof(*params->ht_cap))
3787 params->ht_cap = (void *)(cap + 2);
3788 cap = cfg80211_find_ie(WLAN_EID_VHT_CAPABILITY, ies, ies_len);
3789 if (cap && cap[1] >= sizeof(*params->vht_cap))
3790 params->vht_cap = (void *)(cap + 2);
3791}
3792
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003793static bool nl80211_get_ap_channel(struct cfg80211_registered_device *rdev,
3794 struct cfg80211_ap_settings *params)
3795{
3796 struct wireless_dev *wdev;
3797 bool ret = false;
3798
Johannes Berg53873f12016-05-03 16:52:04 +03003799 list_for_each_entry(wdev, &rdev->wiphy.wdev_list, list) {
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003800 if (wdev->iftype != NL80211_IFTYPE_AP &&
3801 wdev->iftype != NL80211_IFTYPE_P2P_GO)
3802 continue;
3803
Johannes Berg683b6d32012-11-08 21:25:48 +01003804 if (!wdev->preset_chandef.chan)
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003805 continue;
3806
Johannes Berg683b6d32012-11-08 21:25:48 +01003807 params->chandef = wdev->preset_chandef;
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003808 ret = true;
3809 break;
3810 }
3811
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003812 return ret;
3813}
3814
Jouni Malinene39e5b52012-09-30 19:29:39 +03003815static bool nl80211_valid_auth_type(struct cfg80211_registered_device *rdev,
3816 enum nl80211_auth_type auth_type,
3817 enum nl80211_commands cmd)
3818{
3819 if (auth_type > NL80211_AUTHTYPE_MAX)
3820 return false;
3821
3822 switch (cmd) {
3823 case NL80211_CMD_AUTHENTICATE:
3824 if (!(rdev->wiphy.features & NL80211_FEATURE_SAE) &&
3825 auth_type == NL80211_AUTHTYPE_SAE)
3826 return false;
Jouni Malinen63181062016-10-27 00:42:02 +03003827 if (!wiphy_ext_feature_isset(&rdev->wiphy,
3828 NL80211_EXT_FEATURE_FILS_STA) &&
3829 (auth_type == NL80211_AUTHTYPE_FILS_SK ||
3830 auth_type == NL80211_AUTHTYPE_FILS_SK_PFS ||
3831 auth_type == NL80211_AUTHTYPE_FILS_PK))
3832 return false;
Jouni Malinene39e5b52012-09-30 19:29:39 +03003833 return true;
3834 case NL80211_CMD_CONNECT:
3835 case NL80211_CMD_START_AP:
3836 /* SAE not supported yet */
3837 if (auth_type == NL80211_AUTHTYPE_SAE)
3838 return false;
Jouni Malinen63181062016-10-27 00:42:02 +03003839 /* FILS not supported yet */
3840 if (auth_type == NL80211_AUTHTYPE_FILS_SK ||
3841 auth_type == NL80211_AUTHTYPE_FILS_SK_PFS ||
3842 auth_type == NL80211_AUTHTYPE_FILS_PK)
3843 return false;
Jouni Malinene39e5b52012-09-30 19:29:39 +03003844 return true;
3845 default:
3846 return false;
3847 }
3848}
3849
Johannes Berg88600202012-02-13 15:17:18 +01003850static int nl80211_start_ap(struct sk_buff *skb, struct genl_info *info)
3851{
3852 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3853 struct net_device *dev = info->user_ptr[1];
3854 struct wireless_dev *wdev = dev->ieee80211_ptr;
3855 struct cfg80211_ap_settings params;
3856 int err;
3857
3858 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
3859 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
3860 return -EOPNOTSUPP;
3861
3862 if (!rdev->ops->start_ap)
3863 return -EOPNOTSUPP;
3864
3865 if (wdev->beacon_interval)
3866 return -EALREADY;
3867
3868 memset(&params, 0, sizeof(params));
3869
3870 /* these are required for START_AP */
3871 if (!info->attrs[NL80211_ATTR_BEACON_INTERVAL] ||
3872 !info->attrs[NL80211_ATTR_DTIM_PERIOD] ||
3873 !info->attrs[NL80211_ATTR_BEACON_HEAD])
3874 return -EINVAL;
3875
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003876 err = nl80211_parse_beacon(info->attrs, &params.beacon);
Johannes Berg88600202012-02-13 15:17:18 +01003877 if (err)
3878 return err;
3879
3880 params.beacon_interval =
3881 nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]);
3882 params.dtim_period =
3883 nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]);
3884
Purushottam Kushwaha0c317a02016-10-12 18:26:51 +05303885 err = cfg80211_validate_beacon_int(rdev, dev->ieee80211_ptr->iftype,
3886 params.beacon_interval);
Johannes Berg88600202012-02-13 15:17:18 +01003887 if (err)
3888 return err;
3889
3890 /*
3891 * In theory, some of these attributes should be required here
3892 * but since they were not used when the command was originally
3893 * added, keep them optional for old user space programs to let
3894 * them continue to work with drivers that do not need the
3895 * additional information -- drivers must check!
3896 */
3897 if (info->attrs[NL80211_ATTR_SSID]) {
3898 params.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
3899 params.ssid_len =
3900 nla_len(info->attrs[NL80211_ATTR_SSID]);
3901 if (params.ssid_len == 0 ||
3902 params.ssid_len > IEEE80211_MAX_SSID_LEN)
3903 return -EINVAL;
3904 }
3905
3906 if (info->attrs[NL80211_ATTR_HIDDEN_SSID]) {
3907 params.hidden_ssid = nla_get_u32(
3908 info->attrs[NL80211_ATTR_HIDDEN_SSID]);
3909 if (params.hidden_ssid != NL80211_HIDDEN_SSID_NOT_IN_USE &&
3910 params.hidden_ssid != NL80211_HIDDEN_SSID_ZERO_LEN &&
3911 params.hidden_ssid != NL80211_HIDDEN_SSID_ZERO_CONTENTS)
3912 return -EINVAL;
3913 }
3914
3915 params.privacy = !!info->attrs[NL80211_ATTR_PRIVACY];
3916
3917 if (info->attrs[NL80211_ATTR_AUTH_TYPE]) {
3918 params.auth_type = nla_get_u32(
3919 info->attrs[NL80211_ATTR_AUTH_TYPE]);
Jouni Malinene39e5b52012-09-30 19:29:39 +03003920 if (!nl80211_valid_auth_type(rdev, params.auth_type,
3921 NL80211_CMD_START_AP))
Johannes Berg88600202012-02-13 15:17:18 +01003922 return -EINVAL;
3923 } else
3924 params.auth_type = NL80211_AUTHTYPE_AUTOMATIC;
3925
3926 err = nl80211_crypto_settings(rdev, info, &params.crypto,
3927 NL80211_MAX_NR_CIPHER_SUITES);
3928 if (err)
3929 return err;
3930
Vasanthakumar Thiagarajan1b658f12012-03-02 15:50:02 +05303931 if (info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]) {
3932 if (!(rdev->wiphy.features & NL80211_FEATURE_INACTIVITY_TIMER))
3933 return -EOPNOTSUPP;
3934 params.inactivity_timeout = nla_get_u16(
3935 info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]);
3936 }
3937
Johannes Berg53cabad2012-11-14 15:17:28 +01003938 if (info->attrs[NL80211_ATTR_P2P_CTWINDOW]) {
3939 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
3940 return -EINVAL;
3941 params.p2p_ctwindow =
3942 nla_get_u8(info->attrs[NL80211_ATTR_P2P_CTWINDOW]);
3943 if (params.p2p_ctwindow > 127)
3944 return -EINVAL;
3945 if (params.p2p_ctwindow != 0 &&
3946 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_CTWIN))
3947 return -EINVAL;
3948 }
3949
3950 if (info->attrs[NL80211_ATTR_P2P_OPPPS]) {
3951 u8 tmp;
3952
3953 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
3954 return -EINVAL;
3955 tmp = nla_get_u8(info->attrs[NL80211_ATTR_P2P_OPPPS]);
3956 if (tmp > 1)
3957 return -EINVAL;
3958 params.p2p_opp_ps = tmp;
3959 if (params.p2p_opp_ps != 0 &&
3960 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_OPPPS))
3961 return -EINVAL;
3962 }
3963
Johannes Bergaa430da2012-05-16 23:50:18 +02003964 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
Johannes Berg683b6d32012-11-08 21:25:48 +01003965 err = nl80211_parse_chandef(rdev, info, &params.chandef);
3966 if (err)
3967 return err;
3968 } else if (wdev->preset_chandef.chan) {
3969 params.chandef = wdev->preset_chandef;
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003970 } else if (!nl80211_get_ap_channel(rdev, &params))
Johannes Bergaa430da2012-05-16 23:50:18 +02003971 return -EINVAL;
3972
Arik Nemtsov923b3522015-07-08 15:41:44 +03003973 if (!cfg80211_reg_can_beacon_relax(&rdev->wiphy, &params.chandef,
3974 wdev->iftype))
Johannes Bergaa430da2012-05-16 23:50:18 +02003975 return -EINVAL;
3976
Purushottam Kushwahaa7c7fbf2016-09-14 17:38:44 +05303977 if (info->attrs[NL80211_ATTR_TX_RATES]) {
3978 err = nl80211_parse_tx_bitrate_mask(info, &params.beacon_rate);
3979 if (err)
3980 return err;
3981
Johannes Berg8564e382016-09-19 09:44:44 +02003982 err = validate_beacon_tx_rate(rdev, params.chandef.chan->band,
3983 &params.beacon_rate);
Purushottam Kushwahaa7c7fbf2016-09-14 17:38:44 +05303984 if (err)
3985 return err;
3986 }
3987
Eliad Peller18998c32014-09-10 14:07:34 +03003988 if (info->attrs[NL80211_ATTR_SMPS_MODE]) {
3989 params.smps_mode =
3990 nla_get_u8(info->attrs[NL80211_ATTR_SMPS_MODE]);
3991 switch (params.smps_mode) {
3992 case NL80211_SMPS_OFF:
3993 break;
3994 case NL80211_SMPS_STATIC:
3995 if (!(rdev->wiphy.features &
3996 NL80211_FEATURE_STATIC_SMPS))
3997 return -EINVAL;
3998 break;
3999 case NL80211_SMPS_DYNAMIC:
4000 if (!(rdev->wiphy.features &
4001 NL80211_FEATURE_DYNAMIC_SMPS))
4002 return -EINVAL;
4003 break;
4004 default:
4005 return -EINVAL;
4006 }
4007 } else {
4008 params.smps_mode = NL80211_SMPS_OFF;
4009 }
4010
Purushottam Kushwaha6e8ef842016-07-05 13:44:51 +05304011 params.pbss = nla_get_flag(info->attrs[NL80211_ATTR_PBSS]);
4012 if (params.pbss && !rdev->wiphy.bands[NL80211_BAND_60GHZ])
4013 return -EOPNOTSUPP;
4014
Ola Olsson4baf6be2015-10-29 07:04:58 +01004015 if (info->attrs[NL80211_ATTR_ACL_POLICY]) {
4016 params.acl = parse_acl_data(&rdev->wiphy, info);
4017 if (IS_ERR(params.acl))
4018 return PTR_ERR(params.acl);
4019 }
4020
Johannes Berg66cd7942017-02-07 22:40:44 +02004021 nl80211_calculate_ap_params(&params);
4022
Simon Wunderlichc56589e2013-11-21 18:19:49 +01004023 wdev_lock(wdev);
Hila Gonene35e4d22012-06-27 17:19:42 +03004024 err = rdev_start_ap(rdev, dev, &params);
Felix Fietkau46c1dd02012-06-19 02:50:57 +02004025 if (!err) {
Johannes Berg683b6d32012-11-08 21:25:48 +01004026 wdev->preset_chandef = params.chandef;
Johannes Berg88600202012-02-13 15:17:18 +01004027 wdev->beacon_interval = params.beacon_interval;
Michal Kazior9e0e2962014-01-29 14:22:27 +01004028 wdev->chandef = params.chandef;
Antonio Quartulli06e191e2012-11-07 12:52:19 +01004029 wdev->ssid_len = params.ssid_len;
4030 memcpy(wdev->ssid, params.ssid, wdev->ssid_len);
Felix Fietkau46c1dd02012-06-19 02:50:57 +02004031 }
Simon Wunderlichc56589e2013-11-21 18:19:49 +01004032 wdev_unlock(wdev);
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +05304033
4034 kfree(params.acl);
4035
Johannes Berg56d18932011-05-09 18:41:15 +02004036 return err;
Johannes Berged1b6cc2007-12-19 02:03:32 +01004037}
4038
Johannes Berg88600202012-02-13 15:17:18 +01004039static int nl80211_set_beacon(struct sk_buff *skb, struct genl_info *info)
4040{
4041 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4042 struct net_device *dev = info->user_ptr[1];
4043 struct wireless_dev *wdev = dev->ieee80211_ptr;
4044 struct cfg80211_beacon_data params;
4045 int err;
4046
4047 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
4048 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
4049 return -EOPNOTSUPP;
4050
4051 if (!rdev->ops->change_beacon)
4052 return -EOPNOTSUPP;
4053
4054 if (!wdev->beacon_interval)
4055 return -EINVAL;
4056
Simon Wunderlicha1193be2013-06-14 14:15:19 +02004057 err = nl80211_parse_beacon(info->attrs, &params);
Johannes Berg88600202012-02-13 15:17:18 +01004058 if (err)
4059 return err;
4060
Simon Wunderlichc56589e2013-11-21 18:19:49 +01004061 wdev_lock(wdev);
4062 err = rdev_change_beacon(rdev, dev, &params);
4063 wdev_unlock(wdev);
4064
4065 return err;
Johannes Berg88600202012-02-13 15:17:18 +01004066}
4067
4068static int nl80211_stop_ap(struct sk_buff *skb, struct genl_info *info)
Johannes Berged1b6cc2007-12-19 02:03:32 +01004069{
Johannes Berg4c476992010-10-04 21:36:35 +02004070 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4071 struct net_device *dev = info->user_ptr[1];
Johannes Berged1b6cc2007-12-19 02:03:32 +01004072
Ilan Peer7c8d5e02014-02-25 15:33:38 +02004073 return cfg80211_stop_ap(rdev, dev, false);
Johannes Berged1b6cc2007-12-19 02:03:32 +01004074}
4075
Johannes Berg5727ef12007-12-19 02:03:34 +01004076static const struct nla_policy sta_flags_policy[NL80211_STA_FLAG_MAX + 1] = {
4077 [NL80211_STA_FLAG_AUTHORIZED] = { .type = NLA_FLAG },
4078 [NL80211_STA_FLAG_SHORT_PREAMBLE] = { .type = NLA_FLAG },
4079 [NL80211_STA_FLAG_WME] = { .type = NLA_FLAG },
Jouni Malinen0e467242009-05-11 21:57:55 +03004080 [NL80211_STA_FLAG_MFP] = { .type = NLA_FLAG },
Javier Cardonab39c48f2011-04-07 15:08:30 -07004081 [NL80211_STA_FLAG_AUTHENTICATED] = { .type = NLA_FLAG },
Johannes Bergd83023d2011-12-14 09:29:15 +01004082 [NL80211_STA_FLAG_TDLS_PEER] = { .type = NLA_FLAG },
Johannes Berg5727ef12007-12-19 02:03:34 +01004083};
4084
Johannes Bergeccb8e82009-05-11 21:57:56 +03004085static int parse_station_flags(struct genl_info *info,
Johannes Bergbdd3ae32012-01-02 13:30:03 +01004086 enum nl80211_iftype iftype,
Johannes Bergeccb8e82009-05-11 21:57:56 +03004087 struct station_parameters *params)
Johannes Berg5727ef12007-12-19 02:03:34 +01004088{
4089 struct nlattr *flags[NL80211_STA_FLAG_MAX + 1];
Johannes Bergeccb8e82009-05-11 21:57:56 +03004090 struct nlattr *nla;
Johannes Berg5727ef12007-12-19 02:03:34 +01004091 int flag;
4092
Johannes Bergeccb8e82009-05-11 21:57:56 +03004093 /*
4094 * Try parsing the new attribute first so userspace
4095 * can specify both for older kernels.
4096 */
4097 nla = info->attrs[NL80211_ATTR_STA_FLAGS2];
4098 if (nla) {
4099 struct nl80211_sta_flag_update *sta_flags;
Johannes Berg5727ef12007-12-19 02:03:34 +01004100
Johannes Bergeccb8e82009-05-11 21:57:56 +03004101 sta_flags = nla_data(nla);
4102 params->sta_flags_mask = sta_flags->mask;
4103 params->sta_flags_set = sta_flags->set;
Johannes Berg77ee7c82013-02-15 00:48:33 +01004104 params->sta_flags_set &= params->sta_flags_mask;
Johannes Bergeccb8e82009-05-11 21:57:56 +03004105 if ((params->sta_flags_mask |
4106 params->sta_flags_set) & BIT(__NL80211_STA_FLAG_INVALID))
4107 return -EINVAL;
4108 return 0;
4109 }
4110
4111 /* if present, parse the old attribute */
4112
4113 nla = info->attrs[NL80211_ATTR_STA_FLAGS];
Johannes Berg5727ef12007-12-19 02:03:34 +01004114 if (!nla)
4115 return 0;
4116
4117 if (nla_parse_nested(flags, NL80211_STA_FLAG_MAX,
4118 nla, sta_flags_policy))
4119 return -EINVAL;
4120
Johannes Bergbdd3ae32012-01-02 13:30:03 +01004121 /*
4122 * Only allow certain flags for interface types so that
4123 * other attributes are silently ignored. Remember that
4124 * this is backward compatibility code with old userspace
4125 * and shouldn't be hit in other cases anyway.
4126 */
4127 switch (iftype) {
4128 case NL80211_IFTYPE_AP:
4129 case NL80211_IFTYPE_AP_VLAN:
4130 case NL80211_IFTYPE_P2P_GO:
4131 params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) |
4132 BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) |
4133 BIT(NL80211_STA_FLAG_WME) |
4134 BIT(NL80211_STA_FLAG_MFP);
4135 break;
4136 case NL80211_IFTYPE_P2P_CLIENT:
4137 case NL80211_IFTYPE_STATION:
4138 params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) |
4139 BIT(NL80211_STA_FLAG_TDLS_PEER);
4140 break;
4141 case NL80211_IFTYPE_MESH_POINT:
4142 params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHENTICATED) |
4143 BIT(NL80211_STA_FLAG_MFP) |
4144 BIT(NL80211_STA_FLAG_AUTHORIZED);
4145 default:
4146 return -EINVAL;
4147 }
Johannes Berg5727ef12007-12-19 02:03:34 +01004148
Johannes Berg3383b5a2012-05-10 20:14:43 +02004149 for (flag = 1; flag <= NL80211_STA_FLAG_MAX; flag++) {
4150 if (flags[flag]) {
Johannes Bergeccb8e82009-05-11 21:57:56 +03004151 params->sta_flags_set |= (1<<flag);
Johannes Berg5727ef12007-12-19 02:03:34 +01004152
Johannes Berg3383b5a2012-05-10 20:14:43 +02004153 /* no longer support new API additions in old API */
4154 if (flag > NL80211_STA_FLAG_MAX_OLD_API)
4155 return -EINVAL;
4156 }
4157 }
4158
Johannes Berg5727ef12007-12-19 02:03:34 +01004159 return 0;
4160}
4161
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01004162static bool nl80211_put_sta_rate(struct sk_buff *msg, struct rate_info *info,
4163 int attr)
4164{
4165 struct nlattr *rate;
Vladimir Kondratiev8eb41c82012-07-05 14:25:49 +03004166 u32 bitrate;
4167 u16 bitrate_compat;
Johannes Bergb51f3be2015-01-15 16:14:02 +01004168 enum nl80211_attrs rate_flg;
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01004169
4170 rate = nla_nest_start(msg, attr);
4171 if (!rate)
Johannes Bergdb9c64c2012-11-09 14:56:41 +01004172 return false;
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01004173
4174 /* cfg80211_calculate_bitrate will return 0 for mcs >= 32 */
4175 bitrate = cfg80211_calculate_bitrate(info);
Vladimir Kondratiev8eb41c82012-07-05 14:25:49 +03004176 /* report 16-bit bitrate only if we can */
4177 bitrate_compat = bitrate < (1UL << 16) ? bitrate : 0;
Johannes Bergdb9c64c2012-11-09 14:56:41 +01004178 if (bitrate > 0 &&
4179 nla_put_u32(msg, NL80211_RATE_INFO_BITRATE32, bitrate))
4180 return false;
4181 if (bitrate_compat > 0 &&
4182 nla_put_u16(msg, NL80211_RATE_INFO_BITRATE, bitrate_compat))
4183 return false;
4184
Johannes Bergb51f3be2015-01-15 16:14:02 +01004185 switch (info->bw) {
4186 case RATE_INFO_BW_5:
4187 rate_flg = NL80211_RATE_INFO_5_MHZ_WIDTH;
4188 break;
4189 case RATE_INFO_BW_10:
4190 rate_flg = NL80211_RATE_INFO_10_MHZ_WIDTH;
4191 break;
4192 default:
4193 WARN_ON(1);
4194 /* fall through */
4195 case RATE_INFO_BW_20:
4196 rate_flg = 0;
4197 break;
4198 case RATE_INFO_BW_40:
4199 rate_flg = NL80211_RATE_INFO_40_MHZ_WIDTH;
4200 break;
4201 case RATE_INFO_BW_80:
4202 rate_flg = NL80211_RATE_INFO_80_MHZ_WIDTH;
4203 break;
4204 case RATE_INFO_BW_160:
4205 rate_flg = NL80211_RATE_INFO_160_MHZ_WIDTH;
4206 break;
4207 }
4208
4209 if (rate_flg && nla_put_flag(msg, rate_flg))
4210 return false;
4211
Johannes Bergdb9c64c2012-11-09 14:56:41 +01004212 if (info->flags & RATE_INFO_FLAGS_MCS) {
4213 if (nla_put_u8(msg, NL80211_RATE_INFO_MCS, info->mcs))
4214 return false;
Johannes Bergdb9c64c2012-11-09 14:56:41 +01004215 if (info->flags & RATE_INFO_FLAGS_SHORT_GI &&
4216 nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI))
4217 return false;
4218 } else if (info->flags & RATE_INFO_FLAGS_VHT_MCS) {
4219 if (nla_put_u8(msg, NL80211_RATE_INFO_VHT_MCS, info->mcs))
4220 return false;
4221 if (nla_put_u8(msg, NL80211_RATE_INFO_VHT_NSS, info->nss))
4222 return false;
Johannes Bergdb9c64c2012-11-09 14:56:41 +01004223 if (info->flags & RATE_INFO_FLAGS_SHORT_GI &&
4224 nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI))
4225 return false;
4226 }
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01004227
4228 nla_nest_end(msg, rate);
4229 return true;
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01004230}
4231
Felix Fietkau119363c2013-04-22 16:29:30 +02004232static bool nl80211_put_signal(struct sk_buff *msg, u8 mask, s8 *signal,
4233 int id)
4234{
4235 void *attr;
4236 int i = 0;
4237
4238 if (!mask)
4239 return true;
4240
4241 attr = nla_nest_start(msg, id);
4242 if (!attr)
4243 return false;
4244
4245 for (i = 0; i < IEEE80211_MAX_CHAINS; i++) {
4246 if (!(mask & BIT(i)))
4247 continue;
4248
4249 if (nla_put_u8(msg, i, signal[i]))
4250 return false;
4251 }
4252
4253 nla_nest_end(msg, attr);
4254
4255 return true;
4256}
4257
Johannes Bergcf5ead82014-11-14 17:14:00 +01004258static int nl80211_send_station(struct sk_buff *msg, u32 cmd, u32 portid,
4259 u32 seq, int flags,
John W. Linville66266b32012-03-15 13:25:41 -04004260 struct cfg80211_registered_device *rdev,
4261 struct net_device *dev,
Johannes Berg98b62182009-12-23 13:15:44 +01004262 const u8 *mac_addr, struct station_info *sinfo)
Johannes Bergfd5b74d2007-12-19 02:03:36 +01004263{
4264 void *hdr;
Paul Stewartf4263c92011-03-31 09:25:41 -07004265 struct nlattr *sinfoattr, *bss_param;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01004266
Johannes Bergcf5ead82014-11-14 17:14:00 +01004267 hdr = nl80211hdr_put(msg, portid, seq, flags, cmd);
Johannes Bergfd5b74d2007-12-19 02:03:36 +01004268 if (!hdr)
4269 return -1;
4270
David S. Miller9360ffd2012-03-29 04:41:26 -04004271 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
4272 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) ||
4273 nla_put_u32(msg, NL80211_ATTR_GENERATION, sinfo->generation))
4274 goto nla_put_failure;
Johannes Bergf5ea9122009-08-07 16:17:38 +02004275
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004276 sinfoattr = nla_nest_start(msg, NL80211_ATTR_STA_INFO);
4277 if (!sinfoattr)
Johannes Bergfd5b74d2007-12-19 02:03:36 +01004278 goto nla_put_failure;
Johannes Berg319090b2014-11-17 14:08:11 +01004279
4280#define PUT_SINFO(attr, memb, type) do { \
Johannes Bergd686b922016-04-26 09:54:11 +02004281 BUILD_BUG_ON(sizeof(type) == sizeof(u64)); \
Mohammed Shafi Shajakhan739960f2016-04-07 19:59:34 +05304282 if (sinfo->filled & (1ULL << NL80211_STA_INFO_ ## attr) && \
Johannes Berg319090b2014-11-17 14:08:11 +01004283 nla_put_ ## type(msg, NL80211_STA_INFO_ ## attr, \
4284 sinfo->memb)) \
4285 goto nla_put_failure; \
4286 } while (0)
Johannes Bergd686b922016-04-26 09:54:11 +02004287#define PUT_SINFO_U64(attr, memb) do { \
4288 if (sinfo->filled & (1ULL << NL80211_STA_INFO_ ## attr) && \
4289 nla_put_u64_64bit(msg, NL80211_STA_INFO_ ## attr, \
4290 sinfo->memb, NL80211_STA_INFO_PAD)) \
4291 goto nla_put_failure; \
4292 } while (0)
Johannes Berg319090b2014-11-17 14:08:11 +01004293
4294 PUT_SINFO(CONNECTED_TIME, connected_time, u32);
4295 PUT_SINFO(INACTIVE_TIME, inactive_time, u32);
4296
4297 if (sinfo->filled & (BIT(NL80211_STA_INFO_RX_BYTES) |
4298 BIT(NL80211_STA_INFO_RX_BYTES64)) &&
David S. Miller9360ffd2012-03-29 04:41:26 -04004299 nla_put_u32(msg, NL80211_STA_INFO_RX_BYTES,
Vladimir Kondratiev42745e02013-02-04 13:53:11 +02004300 (u32)sinfo->rx_bytes))
4301 goto nla_put_failure;
Johannes Berg319090b2014-11-17 14:08:11 +01004302
4303 if (sinfo->filled & (BIT(NL80211_STA_INFO_TX_BYTES) |
4304 BIT(NL80211_STA_INFO_TX_BYTES64)) &&
Vladimir Kondratiev42745e02013-02-04 13:53:11 +02004305 nla_put_u32(msg, NL80211_STA_INFO_TX_BYTES,
4306 (u32)sinfo->tx_bytes))
4307 goto nla_put_failure;
Johannes Berg319090b2014-11-17 14:08:11 +01004308
Johannes Bergd686b922016-04-26 09:54:11 +02004309 PUT_SINFO_U64(RX_BYTES64, rx_bytes);
4310 PUT_SINFO_U64(TX_BYTES64, tx_bytes);
Johannes Berg319090b2014-11-17 14:08:11 +01004311 PUT_SINFO(LLID, llid, u16);
4312 PUT_SINFO(PLID, plid, u16);
4313 PUT_SINFO(PLINK_STATE, plink_state, u8);
Johannes Bergd686b922016-04-26 09:54:11 +02004314 PUT_SINFO_U64(RX_DURATION, rx_duration);
Johannes Berg319090b2014-11-17 14:08:11 +01004315
John W. Linville66266b32012-03-15 13:25:41 -04004316 switch (rdev->wiphy.signal_type) {
4317 case CFG80211_SIGNAL_TYPE_MBM:
Johannes Berg319090b2014-11-17 14:08:11 +01004318 PUT_SINFO(SIGNAL, signal, u8);
4319 PUT_SINFO(SIGNAL_AVG, signal_avg, u8);
John W. Linville66266b32012-03-15 13:25:41 -04004320 break;
4321 default:
4322 break;
4323 }
Johannes Berg319090b2014-11-17 14:08:11 +01004324 if (sinfo->filled & BIT(NL80211_STA_INFO_CHAIN_SIGNAL)) {
Felix Fietkau119363c2013-04-22 16:29:30 +02004325 if (!nl80211_put_signal(msg, sinfo->chains,
4326 sinfo->chain_signal,
4327 NL80211_STA_INFO_CHAIN_SIGNAL))
4328 goto nla_put_failure;
4329 }
Johannes Berg319090b2014-11-17 14:08:11 +01004330 if (sinfo->filled & BIT(NL80211_STA_INFO_CHAIN_SIGNAL_AVG)) {
Felix Fietkau119363c2013-04-22 16:29:30 +02004331 if (!nl80211_put_signal(msg, sinfo->chains,
4332 sinfo->chain_signal_avg,
4333 NL80211_STA_INFO_CHAIN_SIGNAL_AVG))
4334 goto nla_put_failure;
4335 }
Johannes Berg319090b2014-11-17 14:08:11 +01004336 if (sinfo->filled & BIT(NL80211_STA_INFO_TX_BITRATE)) {
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01004337 if (!nl80211_put_sta_rate(msg, &sinfo->txrate,
4338 NL80211_STA_INFO_TX_BITRATE))
Henning Rogge420e7fa2008-12-11 22:04:19 +01004339 goto nla_put_failure;
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01004340 }
Johannes Berg319090b2014-11-17 14:08:11 +01004341 if (sinfo->filled & BIT(NL80211_STA_INFO_RX_BITRATE)) {
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01004342 if (!nl80211_put_sta_rate(msg, &sinfo->rxrate,
4343 NL80211_STA_INFO_RX_BITRATE))
4344 goto nla_put_failure;
Henning Rogge420e7fa2008-12-11 22:04:19 +01004345 }
Johannes Berg319090b2014-11-17 14:08:11 +01004346
4347 PUT_SINFO(RX_PACKETS, rx_packets, u32);
4348 PUT_SINFO(TX_PACKETS, tx_packets, u32);
4349 PUT_SINFO(TX_RETRIES, tx_retries, u32);
4350 PUT_SINFO(TX_FAILED, tx_failed, u32);
4351 PUT_SINFO(EXPECTED_THROUGHPUT, expected_throughput, u32);
4352 PUT_SINFO(BEACON_LOSS, beacon_loss_count, u32);
4353 PUT_SINFO(LOCAL_PM, local_pm, u32);
4354 PUT_SINFO(PEER_PM, peer_pm, u32);
4355 PUT_SINFO(NONPEER_PM, nonpeer_pm, u32);
4356
4357 if (sinfo->filled & BIT(NL80211_STA_INFO_BSS_PARAM)) {
Paul Stewartf4263c92011-03-31 09:25:41 -07004358 bss_param = nla_nest_start(msg, NL80211_STA_INFO_BSS_PARAM);
4359 if (!bss_param)
4360 goto nla_put_failure;
4361
David S. Miller9360ffd2012-03-29 04:41:26 -04004362 if (((sinfo->bss_param.flags & BSS_PARAM_FLAGS_CTS_PROT) &&
4363 nla_put_flag(msg, NL80211_STA_BSS_PARAM_CTS_PROT)) ||
4364 ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_PREAMBLE) &&
4365 nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_PREAMBLE)) ||
4366 ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_SLOT_TIME) &&
4367 nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_SLOT_TIME)) ||
4368 nla_put_u8(msg, NL80211_STA_BSS_PARAM_DTIM_PERIOD,
4369 sinfo->bss_param.dtim_period) ||
4370 nla_put_u16(msg, NL80211_STA_BSS_PARAM_BEACON_INTERVAL,
4371 sinfo->bss_param.beacon_interval))
4372 goto nla_put_failure;
Paul Stewartf4263c92011-03-31 09:25:41 -07004373
4374 nla_nest_end(msg, bss_param);
4375 }
Johannes Berg319090b2014-11-17 14:08:11 +01004376 if ((sinfo->filled & BIT(NL80211_STA_INFO_STA_FLAGS)) &&
David S. Miller9360ffd2012-03-29 04:41:26 -04004377 nla_put(msg, NL80211_STA_INFO_STA_FLAGS,
4378 sizeof(struct nl80211_sta_flag_update),
4379 &sinfo->sta_flags))
4380 goto nla_put_failure;
Johannes Berg319090b2014-11-17 14:08:11 +01004381
Johannes Bergd686b922016-04-26 09:54:11 +02004382 PUT_SINFO_U64(T_OFFSET, t_offset);
4383 PUT_SINFO_U64(RX_DROP_MISC, rx_dropped_misc);
4384 PUT_SINFO_U64(BEACON_RX, rx_beacon);
Johannes Berga76b1942014-11-17 14:12:22 +01004385 PUT_SINFO(BEACON_SIGNAL_AVG, rx_beacon_signal_avg, u8);
Johannes Berg319090b2014-11-17 14:08:11 +01004386
4387#undef PUT_SINFO
Johannes Bergd686b922016-04-26 09:54:11 +02004388#undef PUT_SINFO_U64
Johannes Berg6de39802014-12-19 12:34:00 +01004389
4390 if (sinfo->filled & BIT(NL80211_STA_INFO_TID_STATS)) {
4391 struct nlattr *tidsattr;
4392 int tid;
4393
4394 tidsattr = nla_nest_start(msg, NL80211_STA_INFO_TID_STATS);
4395 if (!tidsattr)
4396 goto nla_put_failure;
4397
4398 for (tid = 0; tid < IEEE80211_NUM_TIDS + 1; tid++) {
4399 struct cfg80211_tid_stats *tidstats;
4400 struct nlattr *tidattr;
4401
4402 tidstats = &sinfo->pertid[tid];
4403
4404 if (!tidstats->filled)
4405 continue;
4406
4407 tidattr = nla_nest_start(msg, tid + 1);
4408 if (!tidattr)
4409 goto nla_put_failure;
4410
Johannes Bergd686b922016-04-26 09:54:11 +02004411#define PUT_TIDVAL_U64(attr, memb) do { \
Johannes Berg6de39802014-12-19 12:34:00 +01004412 if (tidstats->filled & BIT(NL80211_TID_STATS_ ## attr) && \
Johannes Bergd686b922016-04-26 09:54:11 +02004413 nla_put_u64_64bit(msg, NL80211_TID_STATS_ ## attr, \
4414 tidstats->memb, NL80211_TID_STATS_PAD)) \
Johannes Berg6de39802014-12-19 12:34:00 +01004415 goto nla_put_failure; \
4416 } while (0)
4417
Johannes Bergd686b922016-04-26 09:54:11 +02004418 PUT_TIDVAL_U64(RX_MSDU, rx_msdu);
4419 PUT_TIDVAL_U64(TX_MSDU, tx_msdu);
4420 PUT_TIDVAL_U64(TX_MSDU_RETRIES, tx_msdu_retries);
4421 PUT_TIDVAL_U64(TX_MSDU_FAILED, tx_msdu_failed);
Johannes Berg6de39802014-12-19 12:34:00 +01004422
Johannes Bergd686b922016-04-26 09:54:11 +02004423#undef PUT_TIDVAL_U64
Johannes Berg6de39802014-12-19 12:34:00 +01004424 nla_nest_end(msg, tidattr);
4425 }
4426
4427 nla_nest_end(msg, tidsattr);
4428 }
4429
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004430 nla_nest_end(msg, sinfoattr);
Johannes Bergfd5b74d2007-12-19 02:03:36 +01004431
Johannes Berg319090b2014-11-17 14:08:11 +01004432 if (sinfo->assoc_req_ies_len &&
David S. Miller9360ffd2012-03-29 04:41:26 -04004433 nla_put(msg, NL80211_ATTR_IE, sinfo->assoc_req_ies_len,
4434 sinfo->assoc_req_ies))
4435 goto nla_put_failure;
Jouni Malinen50d3dfb2011-08-08 12:11:52 +03004436
Johannes Berg053c0952015-01-16 22:09:00 +01004437 genlmsg_end(msg, hdr);
4438 return 0;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01004439
4440 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07004441 genlmsg_cancel(msg, hdr);
4442 return -EMSGSIZE;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01004443}
4444
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004445static int nl80211_dump_station(struct sk_buff *skb,
Johannes Bergbba95fe2008-07-29 13:22:51 +02004446 struct netlink_callback *cb)
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004447{
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004448 struct station_info sinfo;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08004449 struct cfg80211_registered_device *rdev;
Johannes Berg97990a02013-04-19 01:02:55 +02004450 struct wireless_dev *wdev;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004451 u8 mac_addr[ETH_ALEN];
Johannes Berg97990a02013-04-19 01:02:55 +02004452 int sta_idx = cb->args[2];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004453 int err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004454
Zhao, Gang1b8ec872014-04-21 12:53:02 +08004455 err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev);
Johannes Berg67748892010-10-04 21:14:06 +02004456 if (err)
4457 return err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004458
Johannes Berg97990a02013-04-19 01:02:55 +02004459 if (!wdev->netdev) {
4460 err = -EINVAL;
4461 goto out_err;
4462 }
4463
Zhao, Gang1b8ec872014-04-21 12:53:02 +08004464 if (!rdev->ops->dump_station) {
Jouni Malineneec60b02009-03-20 21:21:19 +02004465 err = -EOPNOTSUPP;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004466 goto out_err;
4467 }
4468
Johannes Bergbba95fe2008-07-29 13:22:51 +02004469 while (1) {
Jouni Malinenf612ced2011-08-11 11:46:22 +03004470 memset(&sinfo, 0, sizeof(sinfo));
Zhao, Gang1b8ec872014-04-21 12:53:02 +08004471 err = rdev_dump_station(rdev, wdev->netdev, sta_idx,
Hila Gonene35e4d22012-06-27 17:19:42 +03004472 mac_addr, &sinfo);
Johannes Bergbba95fe2008-07-29 13:22:51 +02004473 if (err == -ENOENT)
4474 break;
4475 if (err)
Johannes Berg3b858752009-03-12 09:55:09 +01004476 goto out_err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004477
Johannes Bergcf5ead82014-11-14 17:14:00 +01004478 if (nl80211_send_station(skb, NL80211_CMD_NEW_STATION,
Eric W. Biederman15e47302012-09-07 20:12:54 +00004479 NETLINK_CB(cb->skb).portid,
Johannes Bergbba95fe2008-07-29 13:22:51 +02004480 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08004481 rdev, wdev->netdev, mac_addr,
Johannes Bergbba95fe2008-07-29 13:22:51 +02004482 &sinfo) < 0)
4483 goto out;
4484
4485 sta_idx++;
4486 }
4487
Johannes Bergbba95fe2008-07-29 13:22:51 +02004488 out:
Johannes Berg97990a02013-04-19 01:02:55 +02004489 cb->args[2] = sta_idx;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004490 err = skb->len;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004491 out_err:
Zhao, Gang1b8ec872014-04-21 12:53:02 +08004492 nl80211_finish_wdev_dump(rdev);
Johannes Bergbba95fe2008-07-29 13:22:51 +02004493
4494 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004495}
Johannes Bergfd5b74d2007-12-19 02:03:36 +01004496
Johannes Berg5727ef12007-12-19 02:03:34 +01004497static int nl80211_get_station(struct sk_buff *skb, struct genl_info *info)
4498{
Johannes Berg4c476992010-10-04 21:36:35 +02004499 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4500 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004501 struct station_info sinfo;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01004502 struct sk_buff *msg;
4503 u8 *mac_addr = NULL;
Johannes Berg4c476992010-10-04 21:36:35 +02004504 int err;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01004505
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004506 memset(&sinfo, 0, sizeof(sinfo));
Johannes Bergfd5b74d2007-12-19 02:03:36 +01004507
4508 if (!info->attrs[NL80211_ATTR_MAC])
4509 return -EINVAL;
4510
4511 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
4512
Johannes Berg4c476992010-10-04 21:36:35 +02004513 if (!rdev->ops->get_station)
4514 return -EOPNOTSUPP;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01004515
Hila Gonene35e4d22012-06-27 17:19:42 +03004516 err = rdev_get_station(rdev, dev, mac_addr, &sinfo);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004517 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02004518 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004519
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07004520 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Bergfd5b74d2007-12-19 02:03:36 +01004521 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02004522 return -ENOMEM;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01004523
Johannes Bergcf5ead82014-11-14 17:14:00 +01004524 if (nl80211_send_station(msg, NL80211_CMD_NEW_STATION,
4525 info->snd_portid, info->snd_seq, 0,
John W. Linville66266b32012-03-15 13:25:41 -04004526 rdev, dev, mac_addr, &sinfo) < 0) {
Johannes Berg4c476992010-10-04 21:36:35 +02004527 nlmsg_free(msg);
4528 return -ENOBUFS;
4529 }
Johannes Bergfd5b74d2007-12-19 02:03:36 +01004530
Johannes Berg4c476992010-10-04 21:36:35 +02004531 return genlmsg_reply(msg, info);
Johannes Berg5727ef12007-12-19 02:03:34 +01004532}
4533
Johannes Berg77ee7c82013-02-15 00:48:33 +01004534int cfg80211_check_station_change(struct wiphy *wiphy,
4535 struct station_parameters *params,
4536 enum cfg80211_station_type statype)
4537{
Ayala Bekere4208422015-10-23 11:20:06 +03004538 if (params->listen_interval != -1 &&
4539 statype != CFG80211_STA_AP_CLIENT_UNASSOC)
Johannes Berg77ee7c82013-02-15 00:48:33 +01004540 return -EINVAL;
Ayala Bekere4208422015-10-23 11:20:06 +03004541
Ayala Beker17b94242016-03-17 15:41:38 +02004542 if (params->support_p2p_ps != -1 &&
4543 statype != CFG80211_STA_AP_CLIENT_UNASSOC)
4544 return -EINVAL;
4545
Arik Nemtsovc72e1142014-07-17 17:14:29 +03004546 if (params->aid &&
Ayala Bekere4208422015-10-23 11:20:06 +03004547 !(params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) &&
4548 statype != CFG80211_STA_AP_CLIENT_UNASSOC)
Johannes Berg77ee7c82013-02-15 00:48:33 +01004549 return -EINVAL;
4550
4551 /* When you run into this, adjust the code below for the new flag */
4552 BUILD_BUG_ON(NL80211_STA_FLAG_MAX != 7);
4553
4554 switch (statype) {
Thomas Pederseneef941e2013-03-04 13:06:11 -08004555 case CFG80211_STA_MESH_PEER_KERNEL:
4556 case CFG80211_STA_MESH_PEER_USER:
Johannes Berg77ee7c82013-02-15 00:48:33 +01004557 /*
4558 * No ignoring the TDLS flag here -- the userspace mesh
4559 * code doesn't have the bug of including TDLS in the
4560 * mask everywhere.
4561 */
4562 if (params->sta_flags_mask &
4563 ~(BIT(NL80211_STA_FLAG_AUTHENTICATED) |
4564 BIT(NL80211_STA_FLAG_MFP) |
4565 BIT(NL80211_STA_FLAG_AUTHORIZED)))
4566 return -EINVAL;
4567 break;
4568 case CFG80211_STA_TDLS_PEER_SETUP:
4569 case CFG80211_STA_TDLS_PEER_ACTIVE:
4570 if (!(params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)))
4571 return -EINVAL;
4572 /* ignore since it can't change */
4573 params->sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER);
4574 break;
4575 default:
4576 /* disallow mesh-specific things */
4577 if (params->plink_action != NL80211_PLINK_ACTION_NO_ACTION)
4578 return -EINVAL;
4579 if (params->local_pm)
4580 return -EINVAL;
4581 if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE)
4582 return -EINVAL;
4583 }
4584
4585 if (statype != CFG80211_STA_TDLS_PEER_SETUP &&
4586 statype != CFG80211_STA_TDLS_PEER_ACTIVE) {
4587 /* TDLS can't be set, ... */
4588 if (params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))
4589 return -EINVAL;
4590 /*
4591 * ... but don't bother the driver with it. This works around
4592 * a hostapd/wpa_supplicant issue -- it always includes the
4593 * TLDS_PEER flag in the mask even for AP mode.
4594 */
4595 params->sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER);
4596 }
4597
Ayala Beker47edb112015-09-21 15:49:53 +03004598 if (statype != CFG80211_STA_TDLS_PEER_SETUP &&
4599 statype != CFG80211_STA_AP_CLIENT_UNASSOC) {
Johannes Berg77ee7c82013-02-15 00:48:33 +01004600 /* reject other things that can't change */
4601 if (params->sta_modify_mask & STATION_PARAM_APPLY_UAPSD)
4602 return -EINVAL;
4603 if (params->sta_modify_mask & STATION_PARAM_APPLY_CAPABILITY)
4604 return -EINVAL;
4605 if (params->supported_rates)
4606 return -EINVAL;
4607 if (params->ext_capab || params->ht_capa || params->vht_capa)
4608 return -EINVAL;
4609 }
4610
Ayala Beker47edb112015-09-21 15:49:53 +03004611 if (statype != CFG80211_STA_AP_CLIENT &&
4612 statype != CFG80211_STA_AP_CLIENT_UNASSOC) {
Johannes Berg77ee7c82013-02-15 00:48:33 +01004613 if (params->vlan)
4614 return -EINVAL;
4615 }
4616
4617 switch (statype) {
4618 case CFG80211_STA_AP_MLME_CLIENT:
4619 /* Use this only for authorizing/unauthorizing a station */
4620 if (!(params->sta_flags_mask & BIT(NL80211_STA_FLAG_AUTHORIZED)))
4621 return -EOPNOTSUPP;
4622 break;
4623 case CFG80211_STA_AP_CLIENT:
Ayala Beker47edb112015-09-21 15:49:53 +03004624 case CFG80211_STA_AP_CLIENT_UNASSOC:
Johannes Berg77ee7c82013-02-15 00:48:33 +01004625 /* accept only the listed bits */
4626 if (params->sta_flags_mask &
4627 ~(BIT(NL80211_STA_FLAG_AUTHORIZED) |
4628 BIT(NL80211_STA_FLAG_AUTHENTICATED) |
4629 BIT(NL80211_STA_FLAG_ASSOCIATED) |
4630 BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) |
4631 BIT(NL80211_STA_FLAG_WME) |
4632 BIT(NL80211_STA_FLAG_MFP)))
4633 return -EINVAL;
4634
4635 /* but authenticated/associated only if driver handles it */
4636 if (!(wiphy->features & NL80211_FEATURE_FULL_AP_CLIENT_STATE) &&
4637 params->sta_flags_mask &
4638 (BIT(NL80211_STA_FLAG_AUTHENTICATED) |
4639 BIT(NL80211_STA_FLAG_ASSOCIATED)))
4640 return -EINVAL;
4641 break;
4642 case CFG80211_STA_IBSS:
4643 case CFG80211_STA_AP_STA:
4644 /* reject any changes other than AUTHORIZED */
4645 if (params->sta_flags_mask & ~BIT(NL80211_STA_FLAG_AUTHORIZED))
4646 return -EINVAL;
4647 break;
4648 case CFG80211_STA_TDLS_PEER_SETUP:
4649 /* reject any changes other than AUTHORIZED or WME */
4650 if (params->sta_flags_mask & ~(BIT(NL80211_STA_FLAG_AUTHORIZED) |
4651 BIT(NL80211_STA_FLAG_WME)))
4652 return -EINVAL;
4653 /* force (at least) rates when authorizing */
4654 if (params->sta_flags_set & BIT(NL80211_STA_FLAG_AUTHORIZED) &&
4655 !params->supported_rates)
4656 return -EINVAL;
4657 break;
4658 case CFG80211_STA_TDLS_PEER_ACTIVE:
4659 /* reject any changes */
4660 return -EINVAL;
Thomas Pederseneef941e2013-03-04 13:06:11 -08004661 case CFG80211_STA_MESH_PEER_KERNEL:
Johannes Berg77ee7c82013-02-15 00:48:33 +01004662 if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE)
4663 return -EINVAL;
4664 break;
Thomas Pederseneef941e2013-03-04 13:06:11 -08004665 case CFG80211_STA_MESH_PEER_USER:
Chun-Yeow Yeoh42925042015-04-18 01:30:02 +08004666 if (params->plink_action != NL80211_PLINK_ACTION_NO_ACTION &&
4667 params->plink_action != NL80211_PLINK_ACTION_BLOCK)
Johannes Berg77ee7c82013-02-15 00:48:33 +01004668 return -EINVAL;
4669 break;
4670 }
4671
Beni Lev06f7c882016-07-19 19:28:56 +03004672 /*
4673 * Older kernel versions ignored this attribute entirely, so don't
4674 * reject attempts to update it but mark it as unused instead so the
4675 * driver won't look at the data.
4676 */
4677 if (statype != CFG80211_STA_AP_CLIENT_UNASSOC &&
4678 statype != CFG80211_STA_TDLS_PEER_SETUP)
4679 params->opmode_notif_used = false;
4680
Johannes Berg77ee7c82013-02-15 00:48:33 +01004681 return 0;
4682}
4683EXPORT_SYMBOL(cfg80211_check_station_change);
4684
Johannes Berg5727ef12007-12-19 02:03:34 +01004685/*
Felix Fietkauc258d2d2009-11-11 17:23:31 +01004686 * Get vlan interface making sure it is running and on the right wiphy.
Johannes Berg5727ef12007-12-19 02:03:34 +01004687 */
Johannes Berg80b99892011-11-18 16:23:01 +01004688static struct net_device *get_vlan(struct genl_info *info,
4689 struct cfg80211_registered_device *rdev)
Johannes Berg5727ef12007-12-19 02:03:34 +01004690{
Johannes Berg463d0182009-07-14 00:33:35 +02004691 struct nlattr *vlanattr = info->attrs[NL80211_ATTR_STA_VLAN];
Johannes Berg80b99892011-11-18 16:23:01 +01004692 struct net_device *v;
4693 int ret;
Johannes Berg5727ef12007-12-19 02:03:34 +01004694
Johannes Berg80b99892011-11-18 16:23:01 +01004695 if (!vlanattr)
4696 return NULL;
4697
4698 v = dev_get_by_index(genl_info_net(info), nla_get_u32(vlanattr));
4699 if (!v)
4700 return ERR_PTR(-ENODEV);
4701
4702 if (!v->ieee80211_ptr || v->ieee80211_ptr->wiphy != &rdev->wiphy) {
4703 ret = -EINVAL;
4704 goto error;
Johannes Berg5727ef12007-12-19 02:03:34 +01004705 }
Johannes Berg80b99892011-11-18 16:23:01 +01004706
Johannes Berg77ee7c82013-02-15 00:48:33 +01004707 if (v->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN &&
4708 v->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
4709 v->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) {
4710 ret = -EINVAL;
4711 goto error;
4712 }
4713
Johannes Berg80b99892011-11-18 16:23:01 +01004714 if (!netif_running(v)) {
4715 ret = -ENETDOWN;
4716 goto error;
4717 }
4718
4719 return v;
4720 error:
4721 dev_put(v);
4722 return ERR_PTR(ret);
Johannes Berg5727ef12007-12-19 02:03:34 +01004723}
4724
Johannes Berg94e860f2014-01-20 23:58:15 +01004725static const struct nla_policy
4726nl80211_sta_wme_policy[NL80211_STA_WME_MAX + 1] = {
Jouni Malinendf881292013-02-14 21:10:54 +02004727 [NL80211_STA_WME_UAPSD_QUEUES] = { .type = NLA_U8 },
4728 [NL80211_STA_WME_MAX_SP] = { .type = NLA_U8 },
4729};
4730
Johannes Bergff276692013-02-15 00:09:01 +01004731static int nl80211_parse_sta_wme(struct genl_info *info,
4732 struct station_parameters *params)
Jouni Malinendf881292013-02-14 21:10:54 +02004733{
Jouni Malinendf881292013-02-14 21:10:54 +02004734 struct nlattr *tb[NL80211_STA_WME_MAX + 1];
4735 struct nlattr *nla;
4736 int err;
4737
Jouni Malinendf881292013-02-14 21:10:54 +02004738 /* parse WME attributes if present */
4739 if (!info->attrs[NL80211_ATTR_STA_WME])
4740 return 0;
4741
4742 nla = info->attrs[NL80211_ATTR_STA_WME];
4743 err = nla_parse_nested(tb, NL80211_STA_WME_MAX, nla,
4744 nl80211_sta_wme_policy);
4745 if (err)
4746 return err;
4747
4748 if (tb[NL80211_STA_WME_UAPSD_QUEUES])
4749 params->uapsd_queues = nla_get_u8(
4750 tb[NL80211_STA_WME_UAPSD_QUEUES]);
4751 if (params->uapsd_queues & ~IEEE80211_WMM_IE_STA_QOSINFO_AC_MASK)
4752 return -EINVAL;
4753
4754 if (tb[NL80211_STA_WME_MAX_SP])
4755 params->max_sp = nla_get_u8(tb[NL80211_STA_WME_MAX_SP]);
4756
4757 if (params->max_sp & ~IEEE80211_WMM_IE_STA_QOSINFO_SP_MASK)
4758 return -EINVAL;
4759
4760 params->sta_modify_mask |= STATION_PARAM_APPLY_UAPSD;
4761
4762 return 0;
4763}
4764
Sunil Duttc01fc9a2013-10-09 20:45:21 +05304765static int nl80211_parse_sta_channel_info(struct genl_info *info,
4766 struct station_parameters *params)
4767{
4768 if (info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]) {
4769 params->supported_channels =
4770 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]);
4771 params->supported_channels_len =
4772 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]);
4773 /*
4774 * Need to include at least one (first channel, number of
4775 * channels) tuple for each subband, and must have proper
4776 * tuples for the rest of the data as well.
4777 */
4778 if (params->supported_channels_len < 2)
4779 return -EINVAL;
4780 if (params->supported_channels_len % 2)
4781 return -EINVAL;
4782 }
4783
4784 if (info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]) {
4785 params->supported_oper_classes =
4786 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]);
4787 params->supported_oper_classes_len =
4788 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]);
4789 /*
4790 * The value of the Length field of the Supported Operating
4791 * Classes element is between 2 and 253.
4792 */
4793 if (params->supported_oper_classes_len < 2 ||
4794 params->supported_oper_classes_len > 253)
4795 return -EINVAL;
4796 }
4797 return 0;
4798}
4799
Johannes Bergff276692013-02-15 00:09:01 +01004800static int nl80211_set_station_tdls(struct genl_info *info,
4801 struct station_parameters *params)
4802{
Sunil Duttc01fc9a2013-10-09 20:45:21 +05304803 int err;
Johannes Bergff276692013-02-15 00:09:01 +01004804 /* Dummy STA entry gets updated once the peer capabilities are known */
Jouni Malinen5e4b6f52013-05-16 20:11:08 +03004805 if (info->attrs[NL80211_ATTR_PEER_AID])
4806 params->aid = nla_get_u16(info->attrs[NL80211_ATTR_PEER_AID]);
Johannes Bergff276692013-02-15 00:09:01 +01004807 if (info->attrs[NL80211_ATTR_HT_CAPABILITY])
4808 params->ht_capa =
4809 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]);
4810 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY])
4811 params->vht_capa =
4812 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]);
4813
Sunil Duttc01fc9a2013-10-09 20:45:21 +05304814 err = nl80211_parse_sta_channel_info(info, params);
4815 if (err)
4816 return err;
4817
Johannes Bergff276692013-02-15 00:09:01 +01004818 return nl80211_parse_sta_wme(info, params);
4819}
4820
Johannes Berg5727ef12007-12-19 02:03:34 +01004821static int nl80211_set_station(struct sk_buff *skb, struct genl_info *info)
4822{
Johannes Berg4c476992010-10-04 21:36:35 +02004823 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg4c476992010-10-04 21:36:35 +02004824 struct net_device *dev = info->user_ptr[1];
Johannes Berg5727ef12007-12-19 02:03:34 +01004825 struct station_parameters params;
Johannes Berg77ee7c82013-02-15 00:48:33 +01004826 u8 *mac_addr;
4827 int err;
Johannes Berg5727ef12007-12-19 02:03:34 +01004828
4829 memset(&params, 0, sizeof(params));
4830
Johannes Berg77ee7c82013-02-15 00:48:33 +01004831 if (!rdev->ops->change_station)
4832 return -EOPNOTSUPP;
4833
Ayala Bekere4208422015-10-23 11:20:06 +03004834 /*
4835 * AID and listen_interval properties can be set only for unassociated
4836 * station. Include these parameters here and will check them in
4837 * cfg80211_check_station_change().
4838 */
Ayala Bekera9bc31e2015-11-26 16:26:12 +01004839 if (info->attrs[NL80211_ATTR_STA_AID])
4840 params.aid = nla_get_u16(info->attrs[NL80211_ATTR_STA_AID]);
Ayala Bekere4208422015-10-23 11:20:06 +03004841
4842 if (info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL])
4843 params.listen_interval =
4844 nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]);
4845 else
4846 params.listen_interval = -1;
Johannes Berg5727ef12007-12-19 02:03:34 +01004847
Ayala Beker17b94242016-03-17 15:41:38 +02004848 if (info->attrs[NL80211_ATTR_STA_SUPPORT_P2P_PS]) {
4849 u8 tmp;
4850
4851 tmp = nla_get_u8(info->attrs[NL80211_ATTR_STA_SUPPORT_P2P_PS]);
4852 if (tmp >= NUM_NL80211_P2P_PS_STATUS)
4853 return -EINVAL;
4854
4855 params.support_p2p_ps = tmp;
4856 } else {
4857 params.support_p2p_ps = -1;
4858 }
4859
Johannes Berg5727ef12007-12-19 02:03:34 +01004860 if (!info->attrs[NL80211_ATTR_MAC])
4861 return -EINVAL;
4862
4863 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
4864
4865 if (info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) {
4866 params.supported_rates =
4867 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
4868 params.supported_rates_len =
4869 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
4870 }
4871
Jouni Malinen9d62a982013-02-14 21:10:13 +02004872 if (info->attrs[NL80211_ATTR_STA_CAPABILITY]) {
4873 params.capability =
4874 nla_get_u16(info->attrs[NL80211_ATTR_STA_CAPABILITY]);
4875 params.sta_modify_mask |= STATION_PARAM_APPLY_CAPABILITY;
4876 }
4877
4878 if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]) {
4879 params.ext_capab =
4880 nla_data(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
4881 params.ext_capab_len =
4882 nla_len(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
4883 }
4884
Johannes Bergbdd3ae32012-01-02 13:30:03 +01004885 if (parse_station_flags(info, dev->ieee80211_ptr->iftype, &params))
Johannes Berg5727ef12007-12-19 02:03:34 +01004886 return -EINVAL;
4887
Johannes Bergf8bacc22013-02-14 23:27:01 +01004888 if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) {
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004889 params.plink_action =
Johannes Bergf8bacc22013-02-14 23:27:01 +01004890 nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]);
4891 if (params.plink_action >= NUM_NL80211_PLINK_ACTIONS)
4892 return -EINVAL;
4893 }
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004894
Johannes Bergf8bacc22013-02-14 23:27:01 +01004895 if (info->attrs[NL80211_ATTR_STA_PLINK_STATE]) {
Javier Cardona9c3990a2011-05-03 16:57:11 -07004896 params.plink_state =
Johannes Bergf8bacc22013-02-14 23:27:01 +01004897 nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_STATE]);
4898 if (params.plink_state >= NUM_NL80211_PLINK_STATES)
4899 return -EINVAL;
Masashi Honma7d27a0b2016-07-01 10:19:34 +09004900 if (info->attrs[NL80211_ATTR_MESH_PEER_AID]) {
4901 params.peer_aid = nla_get_u16(
4902 info->attrs[NL80211_ATTR_MESH_PEER_AID]);
4903 if (params.peer_aid > IEEE80211_MAX_AID)
4904 return -EINVAL;
4905 }
Johannes Bergf8bacc22013-02-14 23:27:01 +01004906 params.sta_modify_mask |= STATION_PARAM_APPLY_PLINK_STATE;
4907 }
Javier Cardona9c3990a2011-05-03 16:57:11 -07004908
Marco Porsch3b1c5a52013-01-07 16:04:52 +01004909 if (info->attrs[NL80211_ATTR_LOCAL_MESH_POWER_MODE]) {
4910 enum nl80211_mesh_power_mode pm = nla_get_u32(
4911 info->attrs[NL80211_ATTR_LOCAL_MESH_POWER_MODE]);
4912
4913 if (pm <= NL80211_MESH_POWER_UNKNOWN ||
4914 pm > NL80211_MESH_POWER_MAX)
4915 return -EINVAL;
4916
4917 params.local_pm = pm;
4918 }
4919
Beni Lev06f7c882016-07-19 19:28:56 +03004920 if (info->attrs[NL80211_ATTR_OPMODE_NOTIF]) {
4921 params.opmode_notif_used = true;
4922 params.opmode_notif =
4923 nla_get_u8(info->attrs[NL80211_ATTR_OPMODE_NOTIF]);
4924 }
4925
Johannes Berg77ee7c82013-02-15 00:48:33 +01004926 /* Include parameters for TDLS peer (will check later) */
4927 err = nl80211_set_station_tdls(info, &params);
4928 if (err)
4929 return err;
4930
4931 params.vlan = get_vlan(info, rdev);
4932 if (IS_ERR(params.vlan))
4933 return PTR_ERR(params.vlan);
4934
Johannes Berga97f4422009-06-18 17:23:43 +02004935 switch (dev->ieee80211_ptr->iftype) {
4936 case NL80211_IFTYPE_AP:
4937 case NL80211_IFTYPE_AP_VLAN:
Johannes Berg074ac8d2010-09-16 14:58:22 +02004938 case NL80211_IFTYPE_P2P_GO:
Johannes Berg074ac8d2010-09-16 14:58:22 +02004939 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Berga97f4422009-06-18 17:23:43 +02004940 case NL80211_IFTYPE_STATION:
Antonio Quartulli267335d2012-01-31 20:25:47 +01004941 case NL80211_IFTYPE_ADHOC:
Johannes Berga97f4422009-06-18 17:23:43 +02004942 case NL80211_IFTYPE_MESH_POINT:
Johannes Berga97f4422009-06-18 17:23:43 +02004943 break;
4944 default:
Johannes Berg77ee7c82013-02-15 00:48:33 +01004945 err = -EOPNOTSUPP;
4946 goto out_put_vlan;
Johannes Berg034d6552009-05-27 10:35:29 +02004947 }
4948
Johannes Berg77ee7c82013-02-15 00:48:33 +01004949 /* driver will call cfg80211_check_station_change() */
Hila Gonene35e4d22012-06-27 17:19:42 +03004950 err = rdev_change_station(rdev, dev, mac_addr, &params);
Johannes Berg5727ef12007-12-19 02:03:34 +01004951
Johannes Berg77ee7c82013-02-15 00:48:33 +01004952 out_put_vlan:
Johannes Berg5727ef12007-12-19 02:03:34 +01004953 if (params.vlan)
4954 dev_put(params.vlan);
Johannes Berg3b858752009-03-12 09:55:09 +01004955
Johannes Berg5727ef12007-12-19 02:03:34 +01004956 return err;
4957}
4958
4959static int nl80211_new_station(struct sk_buff *skb, struct genl_info *info)
4960{
Johannes Berg4c476992010-10-04 21:36:35 +02004961 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg5727ef12007-12-19 02:03:34 +01004962 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02004963 struct net_device *dev = info->user_ptr[1];
Johannes Berg5727ef12007-12-19 02:03:34 +01004964 struct station_parameters params;
4965 u8 *mac_addr = NULL;
Johannes Bergbda95eb2015-11-26 16:26:13 +01004966 u32 auth_assoc = BIT(NL80211_STA_FLAG_AUTHENTICATED) |
4967 BIT(NL80211_STA_FLAG_ASSOCIATED);
Johannes Berg5727ef12007-12-19 02:03:34 +01004968
4969 memset(&params, 0, sizeof(params));
4970
Johannes Berg984c3112013-02-14 23:43:25 +01004971 if (!rdev->ops->add_station)
4972 return -EOPNOTSUPP;
4973
Johannes Berg5727ef12007-12-19 02:03:34 +01004974 if (!info->attrs[NL80211_ATTR_MAC])
4975 return -EINVAL;
4976
Johannes Berg5727ef12007-12-19 02:03:34 +01004977 if (!info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL])
4978 return -EINVAL;
4979
4980 if (!info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES])
4981 return -EINVAL;
4982
Jouni Malinen5e4b6f52013-05-16 20:11:08 +03004983 if (!info->attrs[NL80211_ATTR_STA_AID] &&
4984 !info->attrs[NL80211_ATTR_PEER_AID])
Thadeu Lima de Souza Cascardo0e956c12010-02-12 12:34:50 -02004985 return -EINVAL;
4986
Johannes Berg5727ef12007-12-19 02:03:34 +01004987 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
4988 params.supported_rates =
4989 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
4990 params.supported_rates_len =
4991 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
4992 params.listen_interval =
4993 nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]);
Johannes Berg51b50fb2009-05-24 16:42:30 +02004994
Ayala Beker17b94242016-03-17 15:41:38 +02004995 if (info->attrs[NL80211_ATTR_STA_SUPPORT_P2P_PS]) {
4996 u8 tmp;
4997
4998 tmp = nla_get_u8(info->attrs[NL80211_ATTR_STA_SUPPORT_P2P_PS]);
4999 if (tmp >= NUM_NL80211_P2P_PS_STATUS)
5000 return -EINVAL;
5001
5002 params.support_p2p_ps = tmp;
5003 } else {
5004 /*
5005 * if not specified, assume it's supported for P2P GO interface,
5006 * and is NOT supported for AP interface
5007 */
5008 params.support_p2p_ps =
5009 dev->ieee80211_ptr->iftype == NL80211_IFTYPE_P2P_GO;
5010 }
5011
Jouni Malinen3d124ea2013-05-27 18:24:02 +03005012 if (info->attrs[NL80211_ATTR_PEER_AID])
Jouni Malinen5e4b6f52013-05-16 20:11:08 +03005013 params.aid = nla_get_u16(info->attrs[NL80211_ATTR_PEER_AID]);
Jouni Malinen3d124ea2013-05-27 18:24:02 +03005014 else
5015 params.aid = nla_get_u16(info->attrs[NL80211_ATTR_STA_AID]);
Thadeu Lima de Souza Cascardo0e956c12010-02-12 12:34:50 -02005016 if (!params.aid || params.aid > IEEE80211_MAX_AID)
5017 return -EINVAL;
Johannes Berg51b50fb2009-05-24 16:42:30 +02005018
Jouni Malinen9d62a982013-02-14 21:10:13 +02005019 if (info->attrs[NL80211_ATTR_STA_CAPABILITY]) {
5020 params.capability =
5021 nla_get_u16(info->attrs[NL80211_ATTR_STA_CAPABILITY]);
5022 params.sta_modify_mask |= STATION_PARAM_APPLY_CAPABILITY;
5023 }
5024
5025 if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]) {
5026 params.ext_capab =
5027 nla_data(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
5028 params.ext_capab_len =
5029 nla_len(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
5030 }
5031
Jouni Malinen36aedc92008-08-25 11:58:58 +03005032 if (info->attrs[NL80211_ATTR_HT_CAPABILITY])
5033 params.ht_capa =
5034 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]);
Johannes Berg5727ef12007-12-19 02:03:34 +01005035
Mahesh Palivelaf461be3e2012-10-11 08:04:52 +00005036 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY])
5037 params.vht_capa =
5038 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]);
5039
Marek Kwaczynski60f4a7b2013-12-03 10:04:59 +01005040 if (info->attrs[NL80211_ATTR_OPMODE_NOTIF]) {
5041 params.opmode_notif_used = true;
5042 params.opmode_notif =
5043 nla_get_u8(info->attrs[NL80211_ATTR_OPMODE_NOTIF]);
5044 }
5045
Johannes Bergf8bacc22013-02-14 23:27:01 +01005046 if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) {
Javier Cardona96b78df2011-04-07 15:08:33 -07005047 params.plink_action =
Johannes Bergf8bacc22013-02-14 23:27:01 +01005048 nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]);
5049 if (params.plink_action >= NUM_NL80211_PLINK_ACTIONS)
5050 return -EINVAL;
5051 }
Javier Cardona96b78df2011-04-07 15:08:33 -07005052
Sunil Duttc01fc9a2013-10-09 20:45:21 +05305053 err = nl80211_parse_sta_channel_info(info, &params);
5054 if (err)
5055 return err;
5056
Johannes Bergff276692013-02-15 00:09:01 +01005057 err = nl80211_parse_sta_wme(info, &params);
5058 if (err)
5059 return err;
Johannes Bergbdd90d52011-12-14 12:20:27 +01005060
Johannes Bergbdd3ae32012-01-02 13:30:03 +01005061 if (parse_station_flags(info, dev->ieee80211_ptr->iftype, &params))
Johannes Berg5727ef12007-12-19 02:03:34 +01005062 return -EINVAL;
5063
Johannes Berg496fcc22015-03-12 08:53:27 +02005064 /* HT/VHT requires QoS, but if we don't have that just ignore HT/VHT
5065 * as userspace might just pass through the capabilities from the IEs
5066 * directly, rather than enforcing this restriction and returning an
5067 * error in this case.
5068 */
5069 if (!(params.sta_flags_set & BIT(NL80211_STA_FLAG_WME))) {
5070 params.ht_capa = NULL;
5071 params.vht_capa = NULL;
5072 }
5073
Johannes Berg77ee7c82013-02-15 00:48:33 +01005074 /* When you run into this, adjust the code below for the new flag */
5075 BUILD_BUG_ON(NL80211_STA_FLAG_MAX != 7);
5076
Johannes Bergbdd90d52011-12-14 12:20:27 +01005077 switch (dev->ieee80211_ptr->iftype) {
5078 case NL80211_IFTYPE_AP:
5079 case NL80211_IFTYPE_AP_VLAN:
5080 case NL80211_IFTYPE_P2P_GO:
Johannes Berg984c3112013-02-14 23:43:25 +01005081 /* ignore WME attributes if iface/sta is not capable */
5082 if (!(rdev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) ||
5083 !(params.sta_flags_set & BIT(NL80211_STA_FLAG_WME)))
5084 params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD;
Eliad Pellerc75786c2011-08-23 14:37:46 +03005085
Johannes Bergbdd90d52011-12-14 12:20:27 +01005086 /* TDLS peers cannot be added */
Jouni Malinen3d124ea2013-05-27 18:24:02 +03005087 if ((params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) ||
5088 info->attrs[NL80211_ATTR_PEER_AID])
Johannes Berg4319e192011-09-07 11:50:48 +02005089 return -EINVAL;
Johannes Bergbdd90d52011-12-14 12:20:27 +01005090 /* but don't bother the driver with it */
5091 params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER);
Eliad Pellerc75786c2011-08-23 14:37:46 +03005092
Johannes Bergd582cff2012-10-26 17:53:44 +02005093 /* allow authenticated/associated only if driver handles it */
5094 if (!(rdev->wiphy.features &
5095 NL80211_FEATURE_FULL_AP_CLIENT_STATE) &&
Johannes Bergbda95eb2015-11-26 16:26:13 +01005096 params.sta_flags_mask & auth_assoc)
Johannes Bergd582cff2012-10-26 17:53:44 +02005097 return -EINVAL;
5098
Johannes Bergbda95eb2015-11-26 16:26:13 +01005099 /* Older userspace, or userspace wanting to be compatible with
5100 * !NL80211_FEATURE_FULL_AP_CLIENT_STATE, will not set the auth
5101 * and assoc flags in the mask, but assumes the station will be
5102 * added as associated anyway since this was the required driver
5103 * behaviour before NL80211_FEATURE_FULL_AP_CLIENT_STATE was
5104 * introduced.
5105 * In order to not bother drivers with this quirk in the API
5106 * set the flags in both the mask and set for new stations in
5107 * this case.
5108 */
5109 if (!(params.sta_flags_mask & auth_assoc)) {
5110 params.sta_flags_mask |= auth_assoc;
5111 params.sta_flags_set |= auth_assoc;
5112 }
5113
Johannes Bergbdd90d52011-12-14 12:20:27 +01005114 /* must be last in here for error handling */
5115 params.vlan = get_vlan(info, rdev);
5116 if (IS_ERR(params.vlan))
5117 return PTR_ERR(params.vlan);
5118 break;
5119 case NL80211_IFTYPE_MESH_POINT:
Johannes Berg984c3112013-02-14 23:43:25 +01005120 /* ignore uAPSD data */
5121 params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD;
5122
Johannes Bergd582cff2012-10-26 17:53:44 +02005123 /* associated is disallowed */
5124 if (params.sta_flags_mask & BIT(NL80211_STA_FLAG_ASSOCIATED))
5125 return -EINVAL;
Johannes Bergbdd90d52011-12-14 12:20:27 +01005126 /* TDLS peers cannot be added */
Jouni Malinen3d124ea2013-05-27 18:24:02 +03005127 if ((params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) ||
5128 info->attrs[NL80211_ATTR_PEER_AID])
Johannes Berg4319e192011-09-07 11:50:48 +02005129 return -EINVAL;
Johannes Bergbdd90d52011-12-14 12:20:27 +01005130 break;
5131 case NL80211_IFTYPE_STATION:
Johannes Berg93d08f02013-03-04 09:29:46 +01005132 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Berg984c3112013-02-14 23:43:25 +01005133 /* ignore uAPSD data */
5134 params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD;
5135
Johannes Berg77ee7c82013-02-15 00:48:33 +01005136 /* these are disallowed */
5137 if (params.sta_flags_mask &
5138 (BIT(NL80211_STA_FLAG_ASSOCIATED) |
5139 BIT(NL80211_STA_FLAG_AUTHENTICATED)))
Johannes Bergd582cff2012-10-26 17:53:44 +02005140 return -EINVAL;
Johannes Bergbdd90d52011-12-14 12:20:27 +01005141 /* Only TDLS peers can be added */
5142 if (!(params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)))
5143 return -EINVAL;
5144 /* Can only add if TDLS ... */
5145 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS))
5146 return -EOPNOTSUPP;
5147 /* ... with external setup is supported */
5148 if (!(rdev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP))
5149 return -EOPNOTSUPP;
Johannes Berg77ee7c82013-02-15 00:48:33 +01005150 /*
5151 * Older wpa_supplicant versions always mark the TDLS peer
5152 * as authorized, but it shouldn't yet be.
5153 */
5154 params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_AUTHORIZED);
Johannes Bergbdd90d52011-12-14 12:20:27 +01005155 break;
5156 default:
5157 return -EOPNOTSUPP;
Eliad Pellerc75786c2011-08-23 14:37:46 +03005158 }
5159
Johannes Bergbdd90d52011-12-14 12:20:27 +01005160 /* be aware of params.vlan when changing code here */
Johannes Berg5727ef12007-12-19 02:03:34 +01005161
Hila Gonene35e4d22012-06-27 17:19:42 +03005162 err = rdev_add_station(rdev, dev, mac_addr, &params);
Johannes Berg5727ef12007-12-19 02:03:34 +01005163
Johannes Berg5727ef12007-12-19 02:03:34 +01005164 if (params.vlan)
5165 dev_put(params.vlan);
Johannes Berg5727ef12007-12-19 02:03:34 +01005166 return err;
5167}
5168
5169static int nl80211_del_station(struct sk_buff *skb, struct genl_info *info)
5170{
Johannes Berg4c476992010-10-04 21:36:35 +02005171 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5172 struct net_device *dev = info->user_ptr[1];
Jouni Malinen89c771e2014-10-10 20:52:40 +03005173 struct station_del_parameters params;
5174
5175 memset(&params, 0, sizeof(params));
Johannes Berg5727ef12007-12-19 02:03:34 +01005176
5177 if (info->attrs[NL80211_ATTR_MAC])
Jouni Malinen89c771e2014-10-10 20:52:40 +03005178 params.mac = nla_data(info->attrs[NL80211_ATTR_MAC]);
Johannes Berg5727ef12007-12-19 02:03:34 +01005179
Johannes Berge80cf852009-05-11 14:43:13 +02005180 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
Marco Porschd5d9de02010-03-30 10:00:16 +02005181 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN &&
Johannes Berg074ac8d2010-09-16 14:58:22 +02005182 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT &&
Johannes Berg4c476992010-10-04 21:36:35 +02005183 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
5184 return -EINVAL;
Johannes Berge80cf852009-05-11 14:43:13 +02005185
Johannes Berg4c476992010-10-04 21:36:35 +02005186 if (!rdev->ops->del_station)
5187 return -EOPNOTSUPP;
Johannes Berg5727ef12007-12-19 02:03:34 +01005188
Jouni Malinen98856862014-10-20 13:20:45 +03005189 if (info->attrs[NL80211_ATTR_MGMT_SUBTYPE]) {
5190 params.subtype =
5191 nla_get_u8(info->attrs[NL80211_ATTR_MGMT_SUBTYPE]);
5192 if (params.subtype != IEEE80211_STYPE_DISASSOC >> 4 &&
5193 params.subtype != IEEE80211_STYPE_DEAUTH >> 4)
5194 return -EINVAL;
5195 } else {
5196 /* Default to Deauthentication frame */
5197 params.subtype = IEEE80211_STYPE_DEAUTH >> 4;
5198 }
5199
5200 if (info->attrs[NL80211_ATTR_REASON_CODE]) {
5201 params.reason_code =
5202 nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
5203 if (params.reason_code == 0)
5204 return -EINVAL; /* 0 is reserved */
5205 } else {
5206 /* Default to reason code 2 */
5207 params.reason_code = WLAN_REASON_PREV_AUTH_NOT_VALID;
5208 }
5209
Jouni Malinen89c771e2014-10-10 20:52:40 +03005210 return rdev_del_station(rdev, dev, &params);
Johannes Berg5727ef12007-12-19 02:03:34 +01005211}
5212
Eric W. Biederman15e47302012-09-07 20:12:54 +00005213static int nl80211_send_mpath(struct sk_buff *msg, u32 portid, u32 seq,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005214 int flags, struct net_device *dev,
5215 u8 *dst, u8 *next_hop,
5216 struct mpath_info *pinfo)
5217{
5218 void *hdr;
5219 struct nlattr *pinfoattr;
5220
Henning Rogge1ef4c852014-11-04 16:14:58 +01005221 hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_MPATH);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005222 if (!hdr)
5223 return -1;
5224
David S. Miller9360ffd2012-03-29 04:41:26 -04005225 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
5226 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, dst) ||
5227 nla_put(msg, NL80211_ATTR_MPATH_NEXT_HOP, ETH_ALEN, next_hop) ||
5228 nla_put_u32(msg, NL80211_ATTR_GENERATION, pinfo->generation))
5229 goto nla_put_failure;
Johannes Bergf5ea9122009-08-07 16:17:38 +02005230
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005231 pinfoattr = nla_nest_start(msg, NL80211_ATTR_MPATH_INFO);
5232 if (!pinfoattr)
5233 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04005234 if ((pinfo->filled & MPATH_INFO_FRAME_QLEN) &&
5235 nla_put_u32(msg, NL80211_MPATH_INFO_FRAME_QLEN,
5236 pinfo->frame_qlen))
5237 goto nla_put_failure;
5238 if (((pinfo->filled & MPATH_INFO_SN) &&
5239 nla_put_u32(msg, NL80211_MPATH_INFO_SN, pinfo->sn)) ||
5240 ((pinfo->filled & MPATH_INFO_METRIC) &&
5241 nla_put_u32(msg, NL80211_MPATH_INFO_METRIC,
5242 pinfo->metric)) ||
5243 ((pinfo->filled & MPATH_INFO_EXPTIME) &&
5244 nla_put_u32(msg, NL80211_MPATH_INFO_EXPTIME,
5245 pinfo->exptime)) ||
5246 ((pinfo->filled & MPATH_INFO_FLAGS) &&
5247 nla_put_u8(msg, NL80211_MPATH_INFO_FLAGS,
5248 pinfo->flags)) ||
5249 ((pinfo->filled & MPATH_INFO_DISCOVERY_TIMEOUT) &&
5250 nla_put_u32(msg, NL80211_MPATH_INFO_DISCOVERY_TIMEOUT,
5251 pinfo->discovery_timeout)) ||
5252 ((pinfo->filled & MPATH_INFO_DISCOVERY_RETRIES) &&
5253 nla_put_u8(msg, NL80211_MPATH_INFO_DISCOVERY_RETRIES,
5254 pinfo->discovery_retries)))
5255 goto nla_put_failure;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005256
5257 nla_nest_end(msg, pinfoattr);
5258
Johannes Berg053c0952015-01-16 22:09:00 +01005259 genlmsg_end(msg, hdr);
5260 return 0;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005261
5262 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07005263 genlmsg_cancel(msg, hdr);
5264 return -EMSGSIZE;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005265}
5266
5267static int nl80211_dump_mpath(struct sk_buff *skb,
Johannes Bergbba95fe2008-07-29 13:22:51 +02005268 struct netlink_callback *cb)
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005269{
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005270 struct mpath_info pinfo;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08005271 struct cfg80211_registered_device *rdev;
Johannes Berg97990a02013-04-19 01:02:55 +02005272 struct wireless_dev *wdev;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005273 u8 dst[ETH_ALEN];
5274 u8 next_hop[ETH_ALEN];
Johannes Berg97990a02013-04-19 01:02:55 +02005275 int path_idx = cb->args[2];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005276 int err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005277
Zhao, Gang1b8ec872014-04-21 12:53:02 +08005278 err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev);
Johannes Berg67748892010-10-04 21:14:06 +02005279 if (err)
5280 return err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02005281
Zhao, Gang1b8ec872014-04-21 12:53:02 +08005282 if (!rdev->ops->dump_mpath) {
Jouni Malineneec60b02009-03-20 21:21:19 +02005283 err = -EOPNOTSUPP;
Johannes Bergbba95fe2008-07-29 13:22:51 +02005284 goto out_err;
5285 }
5286
Johannes Berg97990a02013-04-19 01:02:55 +02005287 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) {
Jouni Malineneec60b02009-03-20 21:21:19 +02005288 err = -EOPNOTSUPP;
Roel Kluin0448b5f2009-08-22 21:15:49 +02005289 goto out_err;
Jouni Malineneec60b02009-03-20 21:21:19 +02005290 }
5291
Johannes Bergbba95fe2008-07-29 13:22:51 +02005292 while (1) {
Zhao, Gang1b8ec872014-04-21 12:53:02 +08005293 err = rdev_dump_mpath(rdev, wdev->netdev, path_idx, dst,
Johannes Berg97990a02013-04-19 01:02:55 +02005294 next_hop, &pinfo);
Johannes Bergbba95fe2008-07-29 13:22:51 +02005295 if (err == -ENOENT)
5296 break;
5297 if (err)
Johannes Berg3b858752009-03-12 09:55:09 +01005298 goto out_err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02005299
Eric W. Biederman15e47302012-09-07 20:12:54 +00005300 if (nl80211_send_mpath(skb, NETLINK_CB(cb->skb).portid,
Johannes Bergbba95fe2008-07-29 13:22:51 +02005301 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Johannes Berg97990a02013-04-19 01:02:55 +02005302 wdev->netdev, dst, next_hop,
Johannes Bergbba95fe2008-07-29 13:22:51 +02005303 &pinfo) < 0)
5304 goto out;
5305
5306 path_idx++;
5307 }
5308
Johannes Bergbba95fe2008-07-29 13:22:51 +02005309 out:
Johannes Berg97990a02013-04-19 01:02:55 +02005310 cb->args[2] = path_idx;
Johannes Bergbba95fe2008-07-29 13:22:51 +02005311 err = skb->len;
Johannes Bergbba95fe2008-07-29 13:22:51 +02005312 out_err:
Zhao, Gang1b8ec872014-04-21 12:53:02 +08005313 nl80211_finish_wdev_dump(rdev);
Johannes Bergbba95fe2008-07-29 13:22:51 +02005314 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005315}
5316
5317static int nl80211_get_mpath(struct sk_buff *skb, struct genl_info *info)
5318{
Johannes Berg4c476992010-10-04 21:36:35 +02005319 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005320 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02005321 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005322 struct mpath_info pinfo;
5323 struct sk_buff *msg;
5324 u8 *dst = NULL;
5325 u8 next_hop[ETH_ALEN];
5326
5327 memset(&pinfo, 0, sizeof(pinfo));
5328
5329 if (!info->attrs[NL80211_ATTR_MAC])
5330 return -EINVAL;
5331
5332 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
5333
Johannes Berg4c476992010-10-04 21:36:35 +02005334 if (!rdev->ops->get_mpath)
5335 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01005336
Johannes Berg4c476992010-10-04 21:36:35 +02005337 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
5338 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02005339
Hila Gonene35e4d22012-06-27 17:19:42 +03005340 err = rdev_get_mpath(rdev, dev, dst, next_hop, &pinfo);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005341 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02005342 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005343
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07005344 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005345 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02005346 return -ENOMEM;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005347
Eric W. Biederman15e47302012-09-07 20:12:54 +00005348 if (nl80211_send_mpath(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berg4c476992010-10-04 21:36:35 +02005349 dev, dst, next_hop, &pinfo) < 0) {
5350 nlmsg_free(msg);
5351 return -ENOBUFS;
5352 }
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005353
Johannes Berg4c476992010-10-04 21:36:35 +02005354 return genlmsg_reply(msg, info);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005355}
5356
5357static int nl80211_set_mpath(struct sk_buff *skb, struct genl_info *info)
5358{
Johannes Berg4c476992010-10-04 21:36:35 +02005359 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5360 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005361 u8 *dst = NULL;
5362 u8 *next_hop = NULL;
5363
5364 if (!info->attrs[NL80211_ATTR_MAC])
5365 return -EINVAL;
5366
5367 if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP])
5368 return -EINVAL;
5369
5370 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
5371 next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]);
5372
Johannes Berg4c476992010-10-04 21:36:35 +02005373 if (!rdev->ops->change_mpath)
5374 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01005375
Johannes Berg4c476992010-10-04 21:36:35 +02005376 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
5377 return -EOPNOTSUPP;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005378
Hila Gonene35e4d22012-06-27 17:19:42 +03005379 return rdev_change_mpath(rdev, dev, dst, next_hop);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005380}
Johannes Berg4c476992010-10-04 21:36:35 +02005381
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005382static int nl80211_new_mpath(struct sk_buff *skb, struct genl_info *info)
5383{
Johannes Berg4c476992010-10-04 21:36:35 +02005384 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5385 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005386 u8 *dst = NULL;
5387 u8 *next_hop = NULL;
5388
5389 if (!info->attrs[NL80211_ATTR_MAC])
5390 return -EINVAL;
5391
5392 if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP])
5393 return -EINVAL;
5394
5395 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
5396 next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]);
5397
Johannes Berg4c476992010-10-04 21:36:35 +02005398 if (!rdev->ops->add_mpath)
5399 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01005400
Johannes Berg4c476992010-10-04 21:36:35 +02005401 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
5402 return -EOPNOTSUPP;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005403
Hila Gonene35e4d22012-06-27 17:19:42 +03005404 return rdev_add_mpath(rdev, dev, dst, next_hop);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005405}
5406
5407static int nl80211_del_mpath(struct sk_buff *skb, struct genl_info *info)
5408{
Johannes Berg4c476992010-10-04 21:36:35 +02005409 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5410 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005411 u8 *dst = NULL;
5412
5413 if (info->attrs[NL80211_ATTR_MAC])
5414 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
5415
Johannes Berg4c476992010-10-04 21:36:35 +02005416 if (!rdev->ops->del_mpath)
5417 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01005418
Hila Gonene35e4d22012-06-27 17:19:42 +03005419 return rdev_del_mpath(rdev, dev, dst);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005420}
5421
Henning Rogge66be7d22014-09-12 08:58:49 +02005422static int nl80211_get_mpp(struct sk_buff *skb, struct genl_info *info)
5423{
5424 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5425 int err;
5426 struct net_device *dev = info->user_ptr[1];
5427 struct mpath_info pinfo;
5428 struct sk_buff *msg;
5429 u8 *dst = NULL;
5430 u8 mpp[ETH_ALEN];
5431
5432 memset(&pinfo, 0, sizeof(pinfo));
5433
5434 if (!info->attrs[NL80211_ATTR_MAC])
5435 return -EINVAL;
5436
5437 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
5438
5439 if (!rdev->ops->get_mpp)
5440 return -EOPNOTSUPP;
5441
5442 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
5443 return -EOPNOTSUPP;
5444
5445 err = rdev_get_mpp(rdev, dev, dst, mpp, &pinfo);
5446 if (err)
5447 return err;
5448
5449 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
5450 if (!msg)
5451 return -ENOMEM;
5452
5453 if (nl80211_send_mpath(msg, info->snd_portid, info->snd_seq, 0,
5454 dev, dst, mpp, &pinfo) < 0) {
5455 nlmsg_free(msg);
5456 return -ENOBUFS;
5457 }
5458
5459 return genlmsg_reply(msg, info);
5460}
5461
5462static int nl80211_dump_mpp(struct sk_buff *skb,
5463 struct netlink_callback *cb)
5464{
5465 struct mpath_info pinfo;
5466 struct cfg80211_registered_device *rdev;
5467 struct wireless_dev *wdev;
5468 u8 dst[ETH_ALEN];
5469 u8 mpp[ETH_ALEN];
5470 int path_idx = cb->args[2];
5471 int err;
5472
5473 err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev);
5474 if (err)
5475 return err;
5476
5477 if (!rdev->ops->dump_mpp) {
5478 err = -EOPNOTSUPP;
5479 goto out_err;
5480 }
5481
5482 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) {
5483 err = -EOPNOTSUPP;
5484 goto out_err;
5485 }
5486
5487 while (1) {
5488 err = rdev_dump_mpp(rdev, wdev->netdev, path_idx, dst,
5489 mpp, &pinfo);
5490 if (err == -ENOENT)
5491 break;
5492 if (err)
5493 goto out_err;
5494
5495 if (nl80211_send_mpath(skb, NETLINK_CB(cb->skb).portid,
5496 cb->nlh->nlmsg_seq, NLM_F_MULTI,
5497 wdev->netdev, dst, mpp,
5498 &pinfo) < 0)
5499 goto out;
5500
5501 path_idx++;
5502 }
5503
5504 out:
5505 cb->args[2] = path_idx;
5506 err = skb->len;
5507 out_err:
5508 nl80211_finish_wdev_dump(rdev);
5509 return err;
5510}
5511
Jouni Malinen9f1ba902008-08-07 20:07:01 +03005512static int nl80211_set_bss(struct sk_buff *skb, struct genl_info *info)
5513{
Johannes Berg4c476992010-10-04 21:36:35 +02005514 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5515 struct net_device *dev = info->user_ptr[1];
Simon Wunderlichc56589e2013-11-21 18:19:49 +01005516 struct wireless_dev *wdev = dev->ieee80211_ptr;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03005517 struct bss_parameters params;
Simon Wunderlichc56589e2013-11-21 18:19:49 +01005518 int err;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03005519
5520 memset(&params, 0, sizeof(params));
5521 /* default to not changing parameters */
5522 params.use_cts_prot = -1;
5523 params.use_short_preamble = -1;
5524 params.use_short_slot_time = -1;
Felix Fietkaufd8aaaf2010-04-27 01:23:35 +02005525 params.ap_isolate = -1;
Helmut Schaa50b12f52010-11-19 12:40:25 +01005526 params.ht_opmode = -1;
Johannes Berg53cabad2012-11-14 15:17:28 +01005527 params.p2p_ctwindow = -1;
5528 params.p2p_opp_ps = -1;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03005529
5530 if (info->attrs[NL80211_ATTR_BSS_CTS_PROT])
5531 params.use_cts_prot =
5532 nla_get_u8(info->attrs[NL80211_ATTR_BSS_CTS_PROT]);
5533 if (info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE])
5534 params.use_short_preamble =
5535 nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]);
5536 if (info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME])
5537 params.use_short_slot_time =
5538 nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]);
Jouni Malinen90c97a02008-10-30 16:59:22 +02005539 if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) {
5540 params.basic_rates =
5541 nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
5542 params.basic_rates_len =
5543 nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
5544 }
Felix Fietkaufd8aaaf2010-04-27 01:23:35 +02005545 if (info->attrs[NL80211_ATTR_AP_ISOLATE])
5546 params.ap_isolate = !!nla_get_u8(info->attrs[NL80211_ATTR_AP_ISOLATE]);
Helmut Schaa50b12f52010-11-19 12:40:25 +01005547 if (info->attrs[NL80211_ATTR_BSS_HT_OPMODE])
5548 params.ht_opmode =
5549 nla_get_u16(info->attrs[NL80211_ATTR_BSS_HT_OPMODE]);
Jouni Malinen9f1ba902008-08-07 20:07:01 +03005550
Johannes Berg53cabad2012-11-14 15:17:28 +01005551 if (info->attrs[NL80211_ATTR_P2P_CTWINDOW]) {
5552 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
5553 return -EINVAL;
5554 params.p2p_ctwindow =
5555 nla_get_s8(info->attrs[NL80211_ATTR_P2P_CTWINDOW]);
5556 if (params.p2p_ctwindow < 0)
5557 return -EINVAL;
5558 if (params.p2p_ctwindow != 0 &&
5559 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_CTWIN))
5560 return -EINVAL;
5561 }
5562
5563 if (info->attrs[NL80211_ATTR_P2P_OPPPS]) {
5564 u8 tmp;
5565
5566 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
5567 return -EINVAL;
5568 tmp = nla_get_u8(info->attrs[NL80211_ATTR_P2P_OPPPS]);
5569 if (tmp > 1)
5570 return -EINVAL;
5571 params.p2p_opp_ps = tmp;
5572 if (params.p2p_opp_ps &&
5573 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_OPPPS))
5574 return -EINVAL;
5575 }
5576
Johannes Berg4c476992010-10-04 21:36:35 +02005577 if (!rdev->ops->change_bss)
5578 return -EOPNOTSUPP;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03005579
Johannes Berg074ac8d2010-09-16 14:58:22 +02005580 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
Johannes Berg4c476992010-10-04 21:36:35 +02005581 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
5582 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02005583
Simon Wunderlichc56589e2013-11-21 18:19:49 +01005584 wdev_lock(wdev);
5585 err = rdev_change_bss(rdev, dev, &params);
5586 wdev_unlock(wdev);
5587
5588 return err;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03005589}
5590
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005591static int nl80211_req_set_reg(struct sk_buff *skb, struct genl_info *info)
5592{
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005593 char *data = NULL;
Ilan peer05050752015-03-04 00:32:06 -05005594 bool is_indoor;
Luis R. Rodriguez57b5ce02012-07-12 11:49:18 -07005595 enum nl80211_user_reg_hint_type user_reg_hint_type;
Ilan peer05050752015-03-04 00:32:06 -05005596 u32 owner_nlportid;
5597
Luis R. Rodriguez80778f12009-02-21 00:04:22 -05005598 /*
5599 * You should only get this when cfg80211 hasn't yet initialized
5600 * completely when built-in to the kernel right between the time
5601 * window between nl80211_init() and regulatory_init(), if that is
5602 * even possible.
5603 */
Johannes Berg458f4f92012-12-06 15:47:38 +01005604 if (unlikely(!rcu_access_pointer(cfg80211_regdomain)))
Luis R. Rodriguezfe33eb32009-02-21 00:04:30 -05005605 return -EINPROGRESS;
Luis R. Rodriguez80778f12009-02-21 00:04:22 -05005606
Luis R. Rodriguez57b5ce02012-07-12 11:49:18 -07005607 if (info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE])
5608 user_reg_hint_type =
5609 nla_get_u32(info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE]);
5610 else
5611 user_reg_hint_type = NL80211_USER_REG_HINT_USER;
5612
5613 switch (user_reg_hint_type) {
5614 case NL80211_USER_REG_HINT_USER:
5615 case NL80211_USER_REG_HINT_CELL_BASE:
Ilan Peer52616f22014-02-25 16:26:00 +02005616 if (!info->attrs[NL80211_ATTR_REG_ALPHA2])
5617 return -EINVAL;
5618
5619 data = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]);
5620 return regulatory_hint_user(data, user_reg_hint_type);
5621 case NL80211_USER_REG_HINT_INDOOR:
Ilan peer05050752015-03-04 00:32:06 -05005622 if (info->attrs[NL80211_ATTR_SOCKET_OWNER]) {
5623 owner_nlportid = info->snd_portid;
5624 is_indoor = !!info->attrs[NL80211_ATTR_REG_INDOOR];
5625 } else {
5626 owner_nlportid = 0;
5627 is_indoor = true;
5628 }
5629
5630 return regulatory_hint_indoor(is_indoor, owner_nlportid);
Luis R. Rodriguez57b5ce02012-07-12 11:49:18 -07005631 default:
5632 return -EINVAL;
5633 }
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005634}
5635
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005636static int nl80211_get_mesh_config(struct sk_buff *skb,
Johannes Berg29cbe682010-12-03 09:20:44 +01005637 struct genl_info *info)
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005638{
Johannes Berg4c476992010-10-04 21:36:35 +02005639 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg4c476992010-10-04 21:36:35 +02005640 struct net_device *dev = info->user_ptr[1];
Johannes Berg29cbe682010-12-03 09:20:44 +01005641 struct wireless_dev *wdev = dev->ieee80211_ptr;
5642 struct mesh_config cur_params;
5643 int err = 0;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005644 void *hdr;
5645 struct nlattr *pinfoattr;
5646 struct sk_buff *msg;
5647
Johannes Berg29cbe682010-12-03 09:20:44 +01005648 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT)
5649 return -EOPNOTSUPP;
5650
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005651 if (!rdev->ops->get_mesh_config)
Johannes Berg4c476992010-10-04 21:36:35 +02005652 return -EOPNOTSUPP;
Jouni Malinenf3f92582009-03-20 17:57:36 +02005653
Johannes Berg29cbe682010-12-03 09:20:44 +01005654 wdev_lock(wdev);
5655 /* If not connected, get default parameters */
5656 if (!wdev->mesh_id_len)
5657 memcpy(&cur_params, &default_mesh_config, sizeof(cur_params));
5658 else
Hila Gonene35e4d22012-06-27 17:19:42 +03005659 err = rdev_get_mesh_config(rdev, dev, &cur_params);
Johannes Berg29cbe682010-12-03 09:20:44 +01005660 wdev_unlock(wdev);
5661
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005662 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02005663 return err;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005664
5665 /* Draw up a netlink message to send back */
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07005666 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02005667 if (!msg)
5668 return -ENOMEM;
Eric W. Biederman15e47302012-09-07 20:12:54 +00005669 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005670 NL80211_CMD_GET_MESH_CONFIG);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005671 if (!hdr)
Julia Lawallefe1cf02011-01-28 15:17:11 +01005672 goto out;
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005673 pinfoattr = nla_nest_start(msg, NL80211_ATTR_MESH_CONFIG);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005674 if (!pinfoattr)
5675 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04005676 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
5677 nla_put_u16(msg, NL80211_MESHCONF_RETRY_TIMEOUT,
5678 cur_params.dot11MeshRetryTimeout) ||
5679 nla_put_u16(msg, NL80211_MESHCONF_CONFIRM_TIMEOUT,
5680 cur_params.dot11MeshConfirmTimeout) ||
5681 nla_put_u16(msg, NL80211_MESHCONF_HOLDING_TIMEOUT,
5682 cur_params.dot11MeshHoldingTimeout) ||
5683 nla_put_u16(msg, NL80211_MESHCONF_MAX_PEER_LINKS,
5684 cur_params.dot11MeshMaxPeerLinks) ||
5685 nla_put_u8(msg, NL80211_MESHCONF_MAX_RETRIES,
5686 cur_params.dot11MeshMaxRetries) ||
5687 nla_put_u8(msg, NL80211_MESHCONF_TTL,
5688 cur_params.dot11MeshTTL) ||
5689 nla_put_u8(msg, NL80211_MESHCONF_ELEMENT_TTL,
5690 cur_params.element_ttl) ||
5691 nla_put_u8(msg, NL80211_MESHCONF_AUTO_OPEN_PLINKS,
5692 cur_params.auto_open_plinks) ||
John W. Linville7eab0f62012-04-12 14:25:14 -04005693 nla_put_u32(msg, NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR,
5694 cur_params.dot11MeshNbrOffsetMaxNeighbor) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04005695 nla_put_u8(msg, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES,
5696 cur_params.dot11MeshHWMPmaxPREQretries) ||
5697 nla_put_u32(msg, NL80211_MESHCONF_PATH_REFRESH_TIME,
5698 cur_params.path_refresh_time) ||
5699 nla_put_u16(msg, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT,
5700 cur_params.min_discovery_timeout) ||
5701 nla_put_u32(msg, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT,
5702 cur_params.dot11MeshHWMPactivePathTimeout) ||
5703 nla_put_u16(msg, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL,
5704 cur_params.dot11MeshHWMPpreqMinInterval) ||
5705 nla_put_u16(msg, NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL,
5706 cur_params.dot11MeshHWMPperrMinInterval) ||
5707 nla_put_u16(msg, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME,
5708 cur_params.dot11MeshHWMPnetDiameterTraversalTime) ||
5709 nla_put_u8(msg, NL80211_MESHCONF_HWMP_ROOTMODE,
5710 cur_params.dot11MeshHWMPRootMode) ||
5711 nla_put_u16(msg, NL80211_MESHCONF_HWMP_RANN_INTERVAL,
5712 cur_params.dot11MeshHWMPRannInterval) ||
5713 nla_put_u8(msg, NL80211_MESHCONF_GATE_ANNOUNCEMENTS,
5714 cur_params.dot11MeshGateAnnouncementProtocol) ||
5715 nla_put_u8(msg, NL80211_MESHCONF_FORWARDING,
5716 cur_params.dot11MeshForwarding) ||
Masashi Honma335d5342017-03-16 10:57:17 +09005717 nla_put_s32(msg, NL80211_MESHCONF_RSSI_THRESHOLD,
Ashok Nagarajan70c33ea2012-04-30 14:20:32 -07005718 cur_params.rssi_threshold) ||
5719 nla_put_u32(msg, NL80211_MESHCONF_HT_OPMODE,
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08005720 cur_params.ht_opmode) ||
5721 nla_put_u32(msg, NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT,
5722 cur_params.dot11MeshHWMPactivePathToRootTimeout) ||
5723 nla_put_u16(msg, NL80211_MESHCONF_HWMP_ROOT_INTERVAL,
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +08005724 cur_params.dot11MeshHWMProotInterval) ||
5725 nla_put_u16(msg, NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL,
Marco Porsch3b1c5a52013-01-07 16:04:52 +01005726 cur_params.dot11MeshHWMPconfirmationInterval) ||
5727 nla_put_u32(msg, NL80211_MESHCONF_POWER_MODE,
5728 cur_params.power_mode) ||
5729 nla_put_u16(msg, NL80211_MESHCONF_AWAKE_WINDOW,
Colleen Twitty8e7c0532013-06-03 09:53:39 -07005730 cur_params.dot11MeshAwakeWindowDuration) ||
5731 nla_put_u32(msg, NL80211_MESHCONF_PLINK_TIMEOUT,
5732 cur_params.plink_timeout))
David S. Miller9360ffd2012-03-29 04:41:26 -04005733 goto nla_put_failure;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005734 nla_nest_end(msg, pinfoattr);
5735 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02005736 return genlmsg_reply(msg, info);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005737
Johannes Berg3b858752009-03-12 09:55:09 +01005738 nla_put_failure:
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005739 genlmsg_cancel(msg, hdr);
Julia Lawallefe1cf02011-01-28 15:17:11 +01005740 out:
Yuri Ershovd080e272010-06-29 15:08:07 +04005741 nlmsg_free(msg);
Johannes Berg4c476992010-10-04 21:36:35 +02005742 return -ENOBUFS;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005743}
5744
Alexey Dobriyanb54452b2010-02-18 08:14:31 +00005745static const struct nla_policy nl80211_meshconf_params_policy[NL80211_MESHCONF_ATTR_MAX+1] = {
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005746 [NL80211_MESHCONF_RETRY_TIMEOUT] = { .type = NLA_U16 },
5747 [NL80211_MESHCONF_CONFIRM_TIMEOUT] = { .type = NLA_U16 },
5748 [NL80211_MESHCONF_HOLDING_TIMEOUT] = { .type = NLA_U16 },
5749 [NL80211_MESHCONF_MAX_PEER_LINKS] = { .type = NLA_U16 },
5750 [NL80211_MESHCONF_MAX_RETRIES] = { .type = NLA_U8 },
5751 [NL80211_MESHCONF_TTL] = { .type = NLA_U8 },
Javier Cardona45904f22010-12-03 09:20:40 +01005752 [NL80211_MESHCONF_ELEMENT_TTL] = { .type = NLA_U8 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005753 [NL80211_MESHCONF_AUTO_OPEN_PLINKS] = { .type = NLA_U8 },
Javier Cardonad299a1f2012-03-31 11:31:33 -07005754 [NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR] = { .type = NLA_U32 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005755 [NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES] = { .type = NLA_U8 },
5756 [NL80211_MESHCONF_PATH_REFRESH_TIME] = { .type = NLA_U32 },
5757 [NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT] = { .type = NLA_U16 },
5758 [NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT] = { .type = NLA_U32 },
5759 [NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL] = { .type = NLA_U16 },
Thomas Pedersendca7e942011-11-24 17:15:24 -08005760 [NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL] = { .type = NLA_U16 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005761 [NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME] = { .type = NLA_U16 },
Javier Cardona699403d2011-08-09 16:45:09 -07005762 [NL80211_MESHCONF_HWMP_ROOTMODE] = { .type = NLA_U8 },
Javier Cardona0507e152011-08-09 16:45:10 -07005763 [NL80211_MESHCONF_HWMP_RANN_INTERVAL] = { .type = NLA_U16 },
Javier Cardona16dd7262011-08-09 16:45:11 -07005764 [NL80211_MESHCONF_GATE_ANNOUNCEMENTS] = { .type = NLA_U8 },
Chun-Yeow Yeoh94f90652012-01-21 01:02:16 +08005765 [NL80211_MESHCONF_FORWARDING] = { .type = NLA_U8 },
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005766 [NL80211_MESHCONF_RSSI_THRESHOLD] = { .type = NLA_U32 },
5767 [NL80211_MESHCONF_HT_OPMODE] = { .type = NLA_U16 },
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08005768 [NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT] = { .type = NLA_U32 },
5769 [NL80211_MESHCONF_HWMP_ROOT_INTERVAL] = { .type = NLA_U16 },
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +08005770 [NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL] = { .type = NLA_U16 },
Marco Porsch3b1c5a52013-01-07 16:04:52 +01005771 [NL80211_MESHCONF_POWER_MODE] = { .type = NLA_U32 },
5772 [NL80211_MESHCONF_AWAKE_WINDOW] = { .type = NLA_U16 },
Colleen Twitty8e7c0532013-06-03 09:53:39 -07005773 [NL80211_MESHCONF_PLINK_TIMEOUT] = { .type = NLA_U32 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005774};
5775
Javier Cardonac80d5452010-12-16 17:37:49 -08005776static const struct nla_policy
5777 nl80211_mesh_setup_params_policy[NL80211_MESH_SETUP_ATTR_MAX+1] = {
Javier Cardonad299a1f2012-03-31 11:31:33 -07005778 [NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC] = { .type = NLA_U8 },
Javier Cardonac80d5452010-12-16 17:37:49 -08005779 [NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL] = { .type = NLA_U8 },
5780 [NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC] = { .type = NLA_U8 },
Javier Cardona15d5dda2011-04-07 15:08:28 -07005781 [NL80211_MESH_SETUP_USERSPACE_AUTH] = { .type = NLA_FLAG },
Colleen Twitty6e16d902013-05-08 11:45:59 -07005782 [NL80211_MESH_SETUP_AUTH_PROTOCOL] = { .type = NLA_U8 },
Thomas Pedersenbb2798d2013-03-04 13:06:10 -08005783 [NL80211_MESH_SETUP_USERSPACE_MPM] = { .type = NLA_FLAG },
Javier Cardona581a8b02011-04-07 15:08:27 -07005784 [NL80211_MESH_SETUP_IE] = { .type = NLA_BINARY,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005785 .len = IEEE80211_MAX_DATA_LEN },
Javier Cardonab130e5c2011-05-03 16:57:07 -07005786 [NL80211_MESH_SETUP_USERSPACE_AMPE] = { .type = NLA_FLAG },
Javier Cardonac80d5452010-12-16 17:37:49 -08005787};
5788
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005789static int nl80211_check_bool(const struct nlattr *nla, u8 min, u8 max, bool *out)
5790{
5791 u8 val = nla_get_u8(nla);
5792 if (val < min || val > max)
5793 return -EINVAL;
5794 *out = val;
5795 return 0;
5796}
5797
5798static int nl80211_check_u8(const struct nlattr *nla, u8 min, u8 max, u8 *out)
5799{
5800 u8 val = nla_get_u8(nla);
5801 if (val < min || val > max)
5802 return -EINVAL;
5803 *out = val;
5804 return 0;
5805}
5806
5807static int nl80211_check_u16(const struct nlattr *nla, u16 min, u16 max, u16 *out)
5808{
5809 u16 val = nla_get_u16(nla);
5810 if (val < min || val > max)
5811 return -EINVAL;
5812 *out = val;
5813 return 0;
5814}
5815
5816static int nl80211_check_u32(const struct nlattr *nla, u32 min, u32 max, u32 *out)
5817{
5818 u32 val = nla_get_u32(nla);
5819 if (val < min || val > max)
5820 return -EINVAL;
5821 *out = val;
5822 return 0;
5823}
5824
5825static int nl80211_check_s32(const struct nlattr *nla, s32 min, s32 max, s32 *out)
5826{
5827 s32 val = nla_get_s32(nla);
5828 if (val < min || val > max)
5829 return -EINVAL;
5830 *out = val;
5831 return 0;
5832}
5833
Johannes Bergff9a71a2016-08-11 14:59:53 +02005834static int nl80211_check_power_mode(const struct nlattr *nla,
5835 enum nl80211_mesh_power_mode min,
5836 enum nl80211_mesh_power_mode max,
5837 enum nl80211_mesh_power_mode *out)
5838{
5839 u32 val = nla_get_u32(nla);
5840 if (val < min || val > max)
5841 return -EINVAL;
5842 *out = val;
5843 return 0;
5844}
5845
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005846static int nl80211_parse_mesh_config(struct genl_info *info,
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005847 struct mesh_config *cfg,
5848 u32 *mask_out)
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005849{
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005850 struct nlattr *tb[NL80211_MESHCONF_ATTR_MAX + 1];
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005851 u32 mask = 0;
Masashi Honma97572352016-08-03 10:07:44 +09005852 u16 ht_opmode;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005853
Marco Porschea54fba2013-01-07 16:04:48 +01005854#define FILL_IN_MESH_PARAM_IF_SET(tb, cfg, param, min, max, mask, attr, fn) \
5855do { \
5856 if (tb[attr]) { \
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005857 if (fn(tb[attr], min, max, &cfg->param)) \
Marco Porschea54fba2013-01-07 16:04:48 +01005858 return -EINVAL; \
Marco Porschea54fba2013-01-07 16:04:48 +01005859 mask |= (1 << (attr - 1)); \
5860 } \
5861} while (0)
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005862
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005863 if (!info->attrs[NL80211_ATTR_MESH_CONFIG])
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005864 return -EINVAL;
5865 if (nla_parse_nested(tb, NL80211_MESHCONF_ATTR_MAX,
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005866 info->attrs[NL80211_ATTR_MESH_CONFIG],
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005867 nl80211_meshconf_params_policy))
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005868 return -EINVAL;
5869
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005870 /* This makes sure that there aren't more than 32 mesh config
5871 * parameters (otherwise our bitfield scheme would not work.) */
5872 BUILD_BUG_ON(NL80211_MESHCONF_ATTR_MAX > 32);
5873
5874 /* Fill in the params struct */
Marco Porschea54fba2013-01-07 16:04:48 +01005875 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshRetryTimeout, 1, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005876 mask, NL80211_MESHCONF_RETRY_TIMEOUT,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005877 nl80211_check_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01005878 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshConfirmTimeout, 1, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005879 mask, NL80211_MESHCONF_CONFIRM_TIMEOUT,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005880 nl80211_check_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01005881 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHoldingTimeout, 1, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005882 mask, NL80211_MESHCONF_HOLDING_TIMEOUT,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005883 nl80211_check_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01005884 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxPeerLinks, 0, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005885 mask, NL80211_MESHCONF_MAX_PEER_LINKS,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005886 nl80211_check_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01005887 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxRetries, 0, 16,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005888 mask, NL80211_MESHCONF_MAX_RETRIES,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005889 nl80211_check_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01005890 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshTTL, 1, 255,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005891 mask, NL80211_MESHCONF_TTL, nl80211_check_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01005892 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, element_ttl, 1, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005893 mask, NL80211_MESHCONF_ELEMENT_TTL,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005894 nl80211_check_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01005895 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, auto_open_plinks, 0, 1,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005896 mask, NL80211_MESHCONF_AUTO_OPEN_PLINKS,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005897 nl80211_check_bool);
Marco Porschea54fba2013-01-07 16:04:48 +01005898 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshNbrOffsetMaxNeighbor,
5899 1, 255, mask,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005900 NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005901 nl80211_check_u32);
Marco Porschea54fba2013-01-07 16:04:48 +01005902 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPmaxPREQretries, 0, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005903 mask, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005904 nl80211_check_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01005905 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, path_refresh_time, 1, 65535,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005906 mask, NL80211_MESHCONF_PATH_REFRESH_TIME,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005907 nl80211_check_u32);
Marco Porschea54fba2013-01-07 16:04:48 +01005908 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, min_discovery_timeout, 1, 65535,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005909 mask, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005910 nl80211_check_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01005911 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathTimeout,
5912 1, 65535, mask,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005913 NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005914 nl80211_check_u32);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005915 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPpreqMinInterval,
Marco Porschea54fba2013-01-07 16:04:48 +01005916 1, 65535, mask,
5917 NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005918 nl80211_check_u16);
Thomas Pedersendca7e942011-11-24 17:15:24 -08005919 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPperrMinInterval,
Marco Porschea54fba2013-01-07 16:04:48 +01005920 1, 65535, mask,
5921 NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005922 nl80211_check_u16);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005923 FILL_IN_MESH_PARAM_IF_SET(tb, cfg,
Marco Porschea54fba2013-01-07 16:04:48 +01005924 dot11MeshHWMPnetDiameterTraversalTime,
5925 1, 65535, mask,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005926 NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005927 nl80211_check_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01005928 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRootMode, 0, 4,
5929 mask, NL80211_MESHCONF_HWMP_ROOTMODE,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005930 nl80211_check_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01005931 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRannInterval, 1, 65535,
5932 mask, NL80211_MESHCONF_HWMP_RANN_INTERVAL,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005933 nl80211_check_u16);
Rui Paulo63c57232009-11-09 23:46:57 +00005934 FILL_IN_MESH_PARAM_IF_SET(tb, cfg,
Marco Porschea54fba2013-01-07 16:04:48 +01005935 dot11MeshGateAnnouncementProtocol, 0, 1,
5936 mask, NL80211_MESHCONF_GATE_ANNOUNCEMENTS,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005937 nl80211_check_bool);
Marco Porschea54fba2013-01-07 16:04:48 +01005938 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshForwarding, 0, 1,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005939 mask, NL80211_MESHCONF_FORWARDING,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005940 nl80211_check_bool);
Chun-Yeow Yeoh83374fe2013-07-11 18:24:03 +08005941 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, rssi_threshold, -255, 0,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005942 mask, NL80211_MESHCONF_RSSI_THRESHOLD,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005943 nl80211_check_s32);
Masashi Honma97572352016-08-03 10:07:44 +09005944 /*
5945 * Check HT operation mode based on
5946 * IEEE 802.11 2012 8.4.2.59 HT Operation element.
5947 */
5948 if (tb[NL80211_MESHCONF_HT_OPMODE]) {
5949 ht_opmode = nla_get_u16(tb[NL80211_MESHCONF_HT_OPMODE]);
5950
5951 if (ht_opmode & ~(IEEE80211_HT_OP_MODE_PROTECTION |
5952 IEEE80211_HT_OP_MODE_NON_GF_STA_PRSNT |
5953 IEEE80211_HT_OP_MODE_NON_HT_STA_PRSNT))
5954 return -EINVAL;
5955
5956 if ((ht_opmode & IEEE80211_HT_OP_MODE_NON_GF_STA_PRSNT) &&
5957 (ht_opmode & IEEE80211_HT_OP_MODE_NON_HT_STA_PRSNT))
5958 return -EINVAL;
5959
5960 switch (ht_opmode & IEEE80211_HT_OP_MODE_PROTECTION) {
5961 case IEEE80211_HT_OP_MODE_PROTECTION_NONE:
5962 case IEEE80211_HT_OP_MODE_PROTECTION_20MHZ:
5963 if (ht_opmode & IEEE80211_HT_OP_MODE_NON_HT_STA_PRSNT)
5964 return -EINVAL;
5965 break;
5966 case IEEE80211_HT_OP_MODE_PROTECTION_NONMEMBER:
5967 case IEEE80211_HT_OP_MODE_PROTECTION_NONHT_MIXED:
5968 if (!(ht_opmode & IEEE80211_HT_OP_MODE_NON_HT_STA_PRSNT))
5969 return -EINVAL;
5970 break;
5971 }
5972 cfg->ht_opmode = ht_opmode;
Masashi Honmafd551ba2017-01-26 08:56:13 +09005973 mask |= (1 << (NL80211_MESHCONF_HT_OPMODE - 1));
Masashi Honma97572352016-08-03 10:07:44 +09005974 }
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08005975 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathToRootTimeout,
Marco Porschea54fba2013-01-07 16:04:48 +01005976 1, 65535, mask,
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08005977 NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005978 nl80211_check_u32);
Marco Porschea54fba2013-01-07 16:04:48 +01005979 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMProotInterval, 1, 65535,
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08005980 mask, NL80211_MESHCONF_HWMP_ROOT_INTERVAL,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005981 nl80211_check_u16);
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +08005982 FILL_IN_MESH_PARAM_IF_SET(tb, cfg,
Marco Porschea54fba2013-01-07 16:04:48 +01005983 dot11MeshHWMPconfirmationInterval,
5984 1, 65535, mask,
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +08005985 NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005986 nl80211_check_u16);
Marco Porsch3b1c5a52013-01-07 16:04:52 +01005987 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, power_mode,
5988 NL80211_MESH_POWER_ACTIVE,
5989 NL80211_MESH_POWER_MAX,
5990 mask, NL80211_MESHCONF_POWER_MODE,
Johannes Bergff9a71a2016-08-11 14:59:53 +02005991 nl80211_check_power_mode);
Marco Porsch3b1c5a52013-01-07 16:04:52 +01005992 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshAwakeWindowDuration,
5993 0, 65535, mask,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005994 NL80211_MESHCONF_AWAKE_WINDOW, nl80211_check_u16);
Masashi Honma31f909a2015-02-24 22:42:16 +09005995 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, plink_timeout, 0, 0xffffffff,
Colleen Twitty8e7c0532013-06-03 09:53:39 -07005996 mask, NL80211_MESHCONF_PLINK_TIMEOUT,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005997 nl80211_check_u32);
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005998 if (mask_out)
5999 *mask_out = mask;
Javier Cardonac80d5452010-12-16 17:37:49 -08006000
Johannes Bergbd90fdc2010-12-03 09:20:43 +01006001 return 0;
6002
6003#undef FILL_IN_MESH_PARAM_IF_SET
6004}
6005
Javier Cardonac80d5452010-12-16 17:37:49 -08006006static int nl80211_parse_mesh_setup(struct genl_info *info,
6007 struct mesh_setup *setup)
6008{
Thomas Pedersenbb2798d2013-03-04 13:06:10 -08006009 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Javier Cardonac80d5452010-12-16 17:37:49 -08006010 struct nlattr *tb[NL80211_MESH_SETUP_ATTR_MAX + 1];
6011
6012 if (!info->attrs[NL80211_ATTR_MESH_SETUP])
6013 return -EINVAL;
6014 if (nla_parse_nested(tb, NL80211_MESH_SETUP_ATTR_MAX,
6015 info->attrs[NL80211_ATTR_MESH_SETUP],
6016 nl80211_mesh_setup_params_policy))
6017 return -EINVAL;
6018
Javier Cardonad299a1f2012-03-31 11:31:33 -07006019 if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC])
6020 setup->sync_method =
6021 (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC])) ?
6022 IEEE80211_SYNC_METHOD_VENDOR :
6023 IEEE80211_SYNC_METHOD_NEIGHBOR_OFFSET;
6024
Javier Cardonac80d5452010-12-16 17:37:49 -08006025 if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL])
6026 setup->path_sel_proto =
6027 (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL])) ?
6028 IEEE80211_PATH_PROTOCOL_VENDOR :
6029 IEEE80211_PATH_PROTOCOL_HWMP;
6030
6031 if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC])
6032 setup->path_metric =
6033 (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC])) ?
6034 IEEE80211_PATH_METRIC_VENDOR :
6035 IEEE80211_PATH_METRIC_AIRTIME;
6036
Javier Cardona581a8b02011-04-07 15:08:27 -07006037 if (tb[NL80211_MESH_SETUP_IE]) {
Javier Cardonac80d5452010-12-16 17:37:49 -08006038 struct nlattr *ieattr =
Javier Cardona581a8b02011-04-07 15:08:27 -07006039 tb[NL80211_MESH_SETUP_IE];
Javier Cardonac80d5452010-12-16 17:37:49 -08006040 if (!is_valid_ie_attr(ieattr))
6041 return -EINVAL;
Javier Cardona581a8b02011-04-07 15:08:27 -07006042 setup->ie = nla_data(ieattr);
6043 setup->ie_len = nla_len(ieattr);
Javier Cardonac80d5452010-12-16 17:37:49 -08006044 }
Thomas Pedersenbb2798d2013-03-04 13:06:10 -08006045 if (tb[NL80211_MESH_SETUP_USERSPACE_MPM] &&
6046 !(rdev->wiphy.features & NL80211_FEATURE_USERSPACE_MPM))
6047 return -EINVAL;
6048 setup->user_mpm = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_MPM]);
Javier Cardonab130e5c2011-05-03 16:57:07 -07006049 setup->is_authenticated = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AUTH]);
6050 setup->is_secure = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AMPE]);
Thomas Pedersenbb2798d2013-03-04 13:06:10 -08006051 if (setup->is_secure)
6052 setup->user_mpm = true;
Javier Cardonac80d5452010-12-16 17:37:49 -08006053
Colleen Twitty6e16d902013-05-08 11:45:59 -07006054 if (tb[NL80211_MESH_SETUP_AUTH_PROTOCOL]) {
6055 if (!setup->user_mpm)
6056 return -EINVAL;
6057 setup->auth_id =
6058 nla_get_u8(tb[NL80211_MESH_SETUP_AUTH_PROTOCOL]);
6059 }
6060
Javier Cardonac80d5452010-12-16 17:37:49 -08006061 return 0;
6062}
6063
Javier Cardona24bdd9f2010-12-16 17:37:48 -08006064static int nl80211_update_mesh_config(struct sk_buff *skb,
Johannes Berg29cbe682010-12-03 09:20:44 +01006065 struct genl_info *info)
Johannes Bergbd90fdc2010-12-03 09:20:43 +01006066{
6067 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6068 struct net_device *dev = info->user_ptr[1];
Johannes Berg29cbe682010-12-03 09:20:44 +01006069 struct wireless_dev *wdev = dev->ieee80211_ptr;
Johannes Bergbd90fdc2010-12-03 09:20:43 +01006070 struct mesh_config cfg;
6071 u32 mask;
6072 int err;
6073
Johannes Berg29cbe682010-12-03 09:20:44 +01006074 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT)
6075 return -EOPNOTSUPP;
6076
Javier Cardona24bdd9f2010-12-16 17:37:48 -08006077 if (!rdev->ops->update_mesh_config)
Johannes Bergbd90fdc2010-12-03 09:20:43 +01006078 return -EOPNOTSUPP;
6079
Javier Cardona24bdd9f2010-12-16 17:37:48 -08006080 err = nl80211_parse_mesh_config(info, &cfg, &mask);
Johannes Bergbd90fdc2010-12-03 09:20:43 +01006081 if (err)
6082 return err;
6083
Johannes Berg29cbe682010-12-03 09:20:44 +01006084 wdev_lock(wdev);
6085 if (!wdev->mesh_id_len)
6086 err = -ENOLINK;
6087
6088 if (!err)
Hila Gonene35e4d22012-06-27 17:19:42 +03006089 err = rdev_update_mesh_config(rdev, dev, mask, &cfg);
Johannes Berg29cbe682010-12-03 09:20:44 +01006090
6091 wdev_unlock(wdev);
6092
6093 return err;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07006094}
6095
Arik Nemtsovad30ca22014-12-15 19:25:59 +02006096static int nl80211_put_regdom(const struct ieee80211_regdomain *regdom,
6097 struct sk_buff *msg)
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08006098{
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08006099 struct nlattr *nl_reg_rules;
6100 unsigned int i;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08006101
Johannes Berg458f4f92012-12-06 15:47:38 +01006102 if (nla_put_string(msg, NL80211_ATTR_REG_ALPHA2, regdom->alpha2) ||
6103 (regdom->dfs_region &&
6104 nla_put_u8(msg, NL80211_ATTR_DFS_REGION, regdom->dfs_region)))
Arik Nemtsovad30ca22014-12-15 19:25:59 +02006105 goto nla_put_failure;
Johannes Berg458f4f92012-12-06 15:47:38 +01006106
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08006107 nl_reg_rules = nla_nest_start(msg, NL80211_ATTR_REG_RULES);
6108 if (!nl_reg_rules)
Arik Nemtsovad30ca22014-12-15 19:25:59 +02006109 goto nla_put_failure;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08006110
Johannes Berg458f4f92012-12-06 15:47:38 +01006111 for (i = 0; i < regdom->n_reg_rules; i++) {
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08006112 struct nlattr *nl_reg_rule;
6113 const struct ieee80211_reg_rule *reg_rule;
6114 const struct ieee80211_freq_range *freq_range;
6115 const struct ieee80211_power_rule *power_rule;
Janusz Dziedzic97524822014-01-30 09:52:20 +01006116 unsigned int max_bandwidth_khz;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08006117
Johannes Berg458f4f92012-12-06 15:47:38 +01006118 reg_rule = &regdom->reg_rules[i];
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08006119 freq_range = &reg_rule->freq_range;
6120 power_rule = &reg_rule->power_rule;
6121
6122 nl_reg_rule = nla_nest_start(msg, i);
6123 if (!nl_reg_rule)
Arik Nemtsovad30ca22014-12-15 19:25:59 +02006124 goto nla_put_failure;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08006125
Janusz Dziedzic97524822014-01-30 09:52:20 +01006126 max_bandwidth_khz = freq_range->max_bandwidth_khz;
6127 if (!max_bandwidth_khz)
6128 max_bandwidth_khz = reg_get_max_bandwidth(regdom,
6129 reg_rule);
6130
David S. Miller9360ffd2012-03-29 04:41:26 -04006131 if (nla_put_u32(msg, NL80211_ATTR_REG_RULE_FLAGS,
6132 reg_rule->flags) ||
6133 nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_START,
6134 freq_range->start_freq_khz) ||
6135 nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_END,
6136 freq_range->end_freq_khz) ||
6137 nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_MAX_BW,
Janusz Dziedzic97524822014-01-30 09:52:20 +01006138 max_bandwidth_khz) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04006139 nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN,
6140 power_rule->max_antenna_gain) ||
6141 nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_EIRP,
Janusz Dziedzic089027e2014-02-21 19:46:12 +01006142 power_rule->max_eirp) ||
6143 nla_put_u32(msg, NL80211_ATTR_DFS_CAC_TIME,
6144 reg_rule->dfs_cac_ms))
Arik Nemtsovad30ca22014-12-15 19:25:59 +02006145 goto nla_put_failure;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08006146
6147 nla_nest_end(msg, nl_reg_rule);
6148 }
6149
6150 nla_nest_end(msg, nl_reg_rules);
Arik Nemtsovad30ca22014-12-15 19:25:59 +02006151 return 0;
6152
6153nla_put_failure:
6154 return -EMSGSIZE;
6155}
6156
6157static int nl80211_get_reg_do(struct sk_buff *skb, struct genl_info *info)
6158{
6159 const struct ieee80211_regdomain *regdom = NULL;
6160 struct cfg80211_registered_device *rdev;
6161 struct wiphy *wiphy = NULL;
6162 struct sk_buff *msg;
6163 void *hdr;
6164
6165 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
6166 if (!msg)
6167 return -ENOBUFS;
6168
6169 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
6170 NL80211_CMD_GET_REG);
6171 if (!hdr)
6172 goto put_failure;
6173
6174 if (info->attrs[NL80211_ATTR_WIPHY]) {
Arik Nemtsov1bdd7162014-12-15 19:26:01 +02006175 bool self_managed;
6176
Arik Nemtsovad30ca22014-12-15 19:25:59 +02006177 rdev = cfg80211_get_dev_from_info(genl_info_net(info), info);
6178 if (IS_ERR(rdev)) {
6179 nlmsg_free(msg);
6180 return PTR_ERR(rdev);
6181 }
6182
6183 wiphy = &rdev->wiphy;
Arik Nemtsov1bdd7162014-12-15 19:26:01 +02006184 self_managed = wiphy->regulatory_flags &
6185 REGULATORY_WIPHY_SELF_MANAGED;
Arik Nemtsovad30ca22014-12-15 19:25:59 +02006186 regdom = get_wiphy_regdom(wiphy);
6187
Arik Nemtsov1bdd7162014-12-15 19:26:01 +02006188 /* a self-managed-reg device must have a private regdom */
6189 if (WARN_ON(!regdom && self_managed)) {
6190 nlmsg_free(msg);
6191 return -EINVAL;
6192 }
6193
Arik Nemtsovad30ca22014-12-15 19:25:59 +02006194 if (regdom &&
6195 nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy)))
6196 goto nla_put_failure;
6197 }
6198
6199 if (!wiphy && reg_last_request_cell_base() &&
6200 nla_put_u32(msg, NL80211_ATTR_USER_REG_HINT_TYPE,
6201 NL80211_USER_REG_HINT_CELL_BASE))
6202 goto nla_put_failure;
6203
6204 rcu_read_lock();
6205
6206 if (!regdom)
6207 regdom = rcu_dereference(cfg80211_regdomain);
6208
6209 if (nl80211_put_regdom(regdom, msg))
6210 goto nla_put_failure_rcu;
6211
6212 rcu_read_unlock();
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08006213
6214 genlmsg_end(msg, hdr);
Johannes Berg5fe231e2013-05-08 21:45:15 +02006215 return genlmsg_reply(msg, info);
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08006216
Johannes Berg458f4f92012-12-06 15:47:38 +01006217nla_put_failure_rcu:
6218 rcu_read_unlock();
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08006219nla_put_failure:
6220 genlmsg_cancel(msg, hdr);
Julia Lawallefe1cf02011-01-28 15:17:11 +01006221put_failure:
Yuri Ershovd080e272010-06-29 15:08:07 +04006222 nlmsg_free(msg);
Johannes Berg5fe231e2013-05-08 21:45:15 +02006223 return -EMSGSIZE;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08006224}
6225
Arik Nemtsovad30ca22014-12-15 19:25:59 +02006226static int nl80211_send_regdom(struct sk_buff *msg, struct netlink_callback *cb,
6227 u32 seq, int flags, struct wiphy *wiphy,
6228 const struct ieee80211_regdomain *regdom)
6229{
6230 void *hdr = nl80211hdr_put(msg, NETLINK_CB(cb->skb).portid, seq, flags,
6231 NL80211_CMD_GET_REG);
6232
6233 if (!hdr)
6234 return -1;
6235
6236 genl_dump_check_consistent(cb, hdr, &nl80211_fam);
6237
6238 if (nl80211_put_regdom(regdom, msg))
6239 goto nla_put_failure;
6240
6241 if (!wiphy && reg_last_request_cell_base() &&
6242 nla_put_u32(msg, NL80211_ATTR_USER_REG_HINT_TYPE,
6243 NL80211_USER_REG_HINT_CELL_BASE))
6244 goto nla_put_failure;
6245
6246 if (wiphy &&
6247 nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy)))
6248 goto nla_put_failure;
6249
Arik Nemtsov1bdd7162014-12-15 19:26:01 +02006250 if (wiphy && wiphy->regulatory_flags & REGULATORY_WIPHY_SELF_MANAGED &&
6251 nla_put_flag(msg, NL80211_ATTR_WIPHY_SELF_MANAGED_REG))
6252 goto nla_put_failure;
6253
Johannes Berg053c0952015-01-16 22:09:00 +01006254 genlmsg_end(msg, hdr);
6255 return 0;
Arik Nemtsovad30ca22014-12-15 19:25:59 +02006256
6257nla_put_failure:
6258 genlmsg_cancel(msg, hdr);
6259 return -EMSGSIZE;
6260}
6261
6262static int nl80211_get_reg_dump(struct sk_buff *skb,
6263 struct netlink_callback *cb)
6264{
6265 const struct ieee80211_regdomain *regdom = NULL;
6266 struct cfg80211_registered_device *rdev;
6267 int err, reg_idx, start = cb->args[2];
6268
6269 rtnl_lock();
6270
6271 if (cfg80211_regdomain && start == 0) {
6272 err = nl80211_send_regdom(skb, cb, cb->nlh->nlmsg_seq,
6273 NLM_F_MULTI, NULL,
6274 rtnl_dereference(cfg80211_regdomain));
6275 if (err < 0)
6276 goto out_err;
6277 }
6278
6279 /* the global regdom is idx 0 */
6280 reg_idx = 1;
6281 list_for_each_entry(rdev, &cfg80211_rdev_list, list) {
6282 regdom = get_wiphy_regdom(&rdev->wiphy);
6283 if (!regdom)
6284 continue;
6285
6286 if (++reg_idx <= start)
6287 continue;
6288
6289 err = nl80211_send_regdom(skb, cb, cb->nlh->nlmsg_seq,
6290 NLM_F_MULTI, &rdev->wiphy, regdom);
6291 if (err < 0) {
6292 reg_idx--;
6293 break;
6294 }
6295 }
6296
6297 cb->args[2] = reg_idx;
6298 err = skb->len;
6299out_err:
6300 rtnl_unlock();
6301 return err;
6302}
6303
Johannes Bergb6863032015-10-15 09:25:18 +02006304#ifdef CONFIG_CFG80211_CRDA_SUPPORT
6305static const struct nla_policy reg_rule_policy[NL80211_REG_RULE_ATTR_MAX + 1] = {
6306 [NL80211_ATTR_REG_RULE_FLAGS] = { .type = NLA_U32 },
6307 [NL80211_ATTR_FREQ_RANGE_START] = { .type = NLA_U32 },
6308 [NL80211_ATTR_FREQ_RANGE_END] = { .type = NLA_U32 },
6309 [NL80211_ATTR_FREQ_RANGE_MAX_BW] = { .type = NLA_U32 },
6310 [NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN] = { .type = NLA_U32 },
6311 [NL80211_ATTR_POWER_RULE_MAX_EIRP] = { .type = NLA_U32 },
6312 [NL80211_ATTR_DFS_CAC_TIME] = { .type = NLA_U32 },
6313};
6314
6315static int parse_reg_rule(struct nlattr *tb[],
6316 struct ieee80211_reg_rule *reg_rule)
6317{
6318 struct ieee80211_freq_range *freq_range = &reg_rule->freq_range;
6319 struct ieee80211_power_rule *power_rule = &reg_rule->power_rule;
6320
6321 if (!tb[NL80211_ATTR_REG_RULE_FLAGS])
6322 return -EINVAL;
6323 if (!tb[NL80211_ATTR_FREQ_RANGE_START])
6324 return -EINVAL;
6325 if (!tb[NL80211_ATTR_FREQ_RANGE_END])
6326 return -EINVAL;
6327 if (!tb[NL80211_ATTR_FREQ_RANGE_MAX_BW])
6328 return -EINVAL;
6329 if (!tb[NL80211_ATTR_POWER_RULE_MAX_EIRP])
6330 return -EINVAL;
6331
6332 reg_rule->flags = nla_get_u32(tb[NL80211_ATTR_REG_RULE_FLAGS]);
6333
6334 freq_range->start_freq_khz =
6335 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_START]);
6336 freq_range->end_freq_khz =
6337 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_END]);
6338 freq_range->max_bandwidth_khz =
6339 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]);
6340
6341 power_rule->max_eirp =
6342 nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]);
6343
6344 if (tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN])
6345 power_rule->max_antenna_gain =
6346 nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]);
6347
6348 if (tb[NL80211_ATTR_DFS_CAC_TIME])
6349 reg_rule->dfs_cac_ms =
6350 nla_get_u32(tb[NL80211_ATTR_DFS_CAC_TIME]);
6351
6352 return 0;
6353}
6354
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07006355static int nl80211_set_reg(struct sk_buff *skb, struct genl_info *info)
6356{
6357 struct nlattr *tb[NL80211_REG_RULE_ATTR_MAX + 1];
6358 struct nlattr *nl_reg_rule;
Johannes Bergea372c52014-11-28 14:54:31 +01006359 char *alpha2;
6360 int rem_reg_rules, r;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07006361 u32 num_rules = 0, rule_idx = 0, size_of_regd;
Luis R. Rodriguez4c7d3982013-11-13 18:54:02 +01006362 enum nl80211_dfs_regions dfs_region = NL80211_DFS_UNSET;
Johannes Bergea372c52014-11-28 14:54:31 +01006363 struct ieee80211_regdomain *rd;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07006364
6365 if (!info->attrs[NL80211_ATTR_REG_ALPHA2])
6366 return -EINVAL;
6367
6368 if (!info->attrs[NL80211_ATTR_REG_RULES])
6369 return -EINVAL;
6370
6371 alpha2 = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]);
6372
Luis R. Rodriguez8b60b072011-10-11 10:59:02 -07006373 if (info->attrs[NL80211_ATTR_DFS_REGION])
6374 dfs_region = nla_get_u8(info->attrs[NL80211_ATTR_DFS_REGION]);
6375
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07006376 nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES],
Johannes Berg1a919312012-12-03 17:21:11 +01006377 rem_reg_rules) {
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07006378 num_rules++;
6379 if (num_rules > NL80211_MAX_SUPP_REG_RULES)
Luis R. Rodriguez4776c6e2009-05-13 17:04:39 -04006380 return -EINVAL;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07006381 }
6382
Luis R. Rodrigueze4387682013-11-05 09:18:01 -08006383 if (!reg_is_valid_request(alpha2))
6384 return -EINVAL;
6385
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07006386 size_of_regd = sizeof(struct ieee80211_regdomain) +
Johannes Berg1a919312012-12-03 17:21:11 +01006387 num_rules * sizeof(struct ieee80211_reg_rule);
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07006388
6389 rd = kzalloc(size_of_regd, GFP_KERNEL);
Johannes Berg6913b492012-12-04 00:48:59 +01006390 if (!rd)
6391 return -ENOMEM;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07006392
6393 rd->n_reg_rules = num_rules;
6394 rd->alpha2[0] = alpha2[0];
6395 rd->alpha2[1] = alpha2[1];
6396
Luis R. Rodriguez8b60b072011-10-11 10:59:02 -07006397 /*
6398 * Disable DFS master mode if the DFS region was
6399 * not supported or known on this kernel.
6400 */
6401 if (reg_supported_dfs_region(dfs_region))
6402 rd->dfs_region = dfs_region;
6403
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07006404 nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES],
Johannes Berg1a919312012-12-03 17:21:11 +01006405 rem_reg_rules) {
Johannes Bergbfe2c7b2016-10-26 14:42:21 +02006406 r = nla_parse_nested(tb, NL80211_REG_RULE_ATTR_MAX,
6407 nl_reg_rule, reg_rule_policy);
Johannes Bergae811e22014-01-24 10:17:47 +01006408 if (r)
6409 goto bad_reg;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07006410 r = parse_reg_rule(tb, &rd->reg_rules[rule_idx]);
6411 if (r)
6412 goto bad_reg;
6413
6414 rule_idx++;
6415
Luis R. Rodriguezd0e18f82009-05-13 17:04:40 -04006416 if (rule_idx > NL80211_MAX_SUPP_REG_RULES) {
6417 r = -EINVAL;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07006418 goto bad_reg;
Luis R. Rodriguezd0e18f82009-05-13 17:04:40 -04006419 }
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07006420 }
6421
Johannes Berg06627992016-06-09 10:40:09 +02006422 /* set_regdom takes ownership of rd */
6423 return set_regdom(rd, REGD_SOURCE_CRDA);
Johannes Bergd2372b32008-10-24 20:32:20 +02006424 bad_reg:
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07006425 kfree(rd);
Luis R. Rodriguezd0e18f82009-05-13 17:04:40 -04006426 return r;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07006427}
Johannes Bergb6863032015-10-15 09:25:18 +02006428#endif /* CONFIG_CFG80211_CRDA_SUPPORT */
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07006429
Johannes Berg83f5e2c2009-06-17 17:41:49 +02006430static int validate_scan_freqs(struct nlattr *freqs)
6431{
6432 struct nlattr *attr1, *attr2;
6433 int n_channels = 0, tmp1, tmp2;
6434
6435 nla_for_each_nested(attr1, freqs, tmp1) {
6436 n_channels++;
6437 /*
6438 * Some hardware has a limited channel list for
6439 * scanning, and it is pretty much nonsensical
6440 * to scan for a channel twice, so disallow that
6441 * and don't require drivers to check that the
6442 * channel list they get isn't longer than what
6443 * they can scan, as long as they can scan all
6444 * the channels they registered at once.
6445 */
6446 nla_for_each_nested(attr2, freqs, tmp2)
6447 if (attr1 != attr2 &&
6448 nla_get_u32(attr1) == nla_get_u32(attr2))
6449 return 0;
6450 }
6451
6452 return n_channels;
6453}
6454
Johannes Berg57fbcce2016-04-12 15:56:15 +02006455static bool is_band_valid(struct wiphy *wiphy, enum nl80211_band b)
Arend van Spriel38de03d2016-03-02 20:37:18 +01006456{
Johannes Berg57fbcce2016-04-12 15:56:15 +02006457 return b < NUM_NL80211_BANDS && wiphy->bands[b];
Arend van Spriel38de03d2016-03-02 20:37:18 +01006458}
6459
6460static int parse_bss_select(struct nlattr *nla, struct wiphy *wiphy,
6461 struct cfg80211_bss_selection *bss_select)
6462{
6463 struct nlattr *attr[NL80211_BSS_SELECT_ATTR_MAX + 1];
6464 struct nlattr *nest;
6465 int err;
6466 bool found = false;
6467 int i;
6468
6469 /* only process one nested attribute */
6470 nest = nla_data(nla);
6471 if (!nla_ok(nest, nla_len(nest)))
6472 return -EINVAL;
6473
Johannes Bergbfe2c7b2016-10-26 14:42:21 +02006474 err = nla_parse_nested(attr, NL80211_BSS_SELECT_ATTR_MAX, nest,
6475 nl80211_bss_select_policy);
Arend van Spriel38de03d2016-03-02 20:37:18 +01006476 if (err)
6477 return err;
6478
6479 /* only one attribute may be given */
6480 for (i = 0; i <= NL80211_BSS_SELECT_ATTR_MAX; i++) {
6481 if (attr[i]) {
6482 if (found)
6483 return -EINVAL;
6484 found = true;
6485 }
6486 }
6487
6488 bss_select->behaviour = __NL80211_BSS_SELECT_ATTR_INVALID;
6489
6490 if (attr[NL80211_BSS_SELECT_ATTR_RSSI])
6491 bss_select->behaviour = NL80211_BSS_SELECT_ATTR_RSSI;
6492
6493 if (attr[NL80211_BSS_SELECT_ATTR_BAND_PREF]) {
6494 bss_select->behaviour = NL80211_BSS_SELECT_ATTR_BAND_PREF;
6495 bss_select->param.band_pref =
6496 nla_get_u32(attr[NL80211_BSS_SELECT_ATTR_BAND_PREF]);
6497 if (!is_band_valid(wiphy, bss_select->param.band_pref))
6498 return -EINVAL;
6499 }
6500
6501 if (attr[NL80211_BSS_SELECT_ATTR_RSSI_ADJUST]) {
6502 struct nl80211_bss_select_rssi_adjust *adj_param;
6503
6504 adj_param = nla_data(attr[NL80211_BSS_SELECT_ATTR_RSSI_ADJUST]);
6505 bss_select->behaviour = NL80211_BSS_SELECT_ATTR_RSSI_ADJUST;
6506 bss_select->param.adjust.band = adj_param->band;
6507 bss_select->param.adjust.delta = adj_param->delta;
6508 if (!is_band_valid(wiphy, bss_select->param.adjust.band))
6509 return -EINVAL;
6510 }
6511
6512 /* user-space did not provide behaviour attribute */
6513 if (bss_select->behaviour == __NL80211_BSS_SELECT_ATTR_INVALID)
6514 return -EINVAL;
6515
6516 if (!(wiphy->bss_select_support & BIT(bss_select->behaviour)))
6517 return -EINVAL;
6518
6519 return 0;
6520}
6521
Johannes Bergad2b26a2014-06-12 21:39:05 +02006522static int nl80211_parse_random_mac(struct nlattr **attrs,
6523 u8 *mac_addr, u8 *mac_addr_mask)
6524{
6525 int i;
6526
6527 if (!attrs[NL80211_ATTR_MAC] && !attrs[NL80211_ATTR_MAC_MASK]) {
Joe Perchesd2beae12015-03-02 19:54:58 -08006528 eth_zero_addr(mac_addr);
6529 eth_zero_addr(mac_addr_mask);
Johannes Bergad2b26a2014-06-12 21:39:05 +02006530 mac_addr[0] = 0x2;
6531 mac_addr_mask[0] = 0x3;
6532
6533 return 0;
6534 }
6535
6536 /* need both or none */
6537 if (!attrs[NL80211_ATTR_MAC] || !attrs[NL80211_ATTR_MAC_MASK])
6538 return -EINVAL;
6539
6540 memcpy(mac_addr, nla_data(attrs[NL80211_ATTR_MAC]), ETH_ALEN);
6541 memcpy(mac_addr_mask, nla_data(attrs[NL80211_ATTR_MAC_MASK]), ETH_ALEN);
6542
6543 /* don't allow or configure an mcast address */
6544 if (!is_multicast_ether_addr(mac_addr_mask) ||
6545 is_multicast_ether_addr(mac_addr))
6546 return -EINVAL;
6547
6548 /*
6549 * allow users to pass a MAC address that has bits set outside
6550 * of the mask, but don't bother drivers with having to deal
6551 * with such bits
6552 */
6553 for (i = 0; i < ETH_ALEN; i++)
6554 mac_addr[i] &= mac_addr_mask[i];
6555
6556 return 0;
6557}
6558
Vasanthakumar Thiagarajan34373d12017-02-27 17:04:34 +05306559static bool cfg80211_off_channel_oper_allowed(struct wireless_dev *wdev)
6560{
6561 ASSERT_WDEV_LOCK(wdev);
6562
6563 if (!cfg80211_beaconing_iface_active(wdev))
6564 return true;
6565
6566 if (!(wdev->chandef.chan->flags & IEEE80211_CHAN_RADAR))
6567 return true;
6568
6569 return regulatory_pre_cac_allowed(wdev->wiphy);
6570}
6571
Johannes Berg2a519312009-02-10 21:25:55 +01006572static int nl80211_trigger_scan(struct sk_buff *skb, struct genl_info *info)
6573{
Johannes Berg4c476992010-10-04 21:36:35 +02006574 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Bergfd014282012-06-18 19:17:03 +02006575 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg2a519312009-02-10 21:25:55 +01006576 struct cfg80211_scan_request *request;
Johannes Berg2a519312009-02-10 21:25:55 +01006577 struct nlattr *attr;
6578 struct wiphy *wiphy;
Johannes Berg83f5e2c2009-06-17 17:41:49 +02006579 int err, tmp, n_ssids = 0, n_channels, i;
Jouni Malinen70692ad2009-02-16 19:39:13 +02006580 size_t ie_len;
Johannes Berg2a519312009-02-10 21:25:55 +01006581
Johannes Bergf4a11bb2009-03-27 12:40:28 +01006582 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
6583 return -EINVAL;
6584
Johannes Berg79c97e92009-07-07 03:56:12 +02006585 wiphy = &rdev->wiphy;
Johannes Berg2a519312009-02-10 21:25:55 +01006586
Ayala Bekercb3b7d82016-09-20 17:31:13 +03006587 if (wdev->iftype == NL80211_IFTYPE_NAN)
6588 return -EOPNOTSUPP;
6589
Johannes Berg4c476992010-10-04 21:36:35 +02006590 if (!rdev->ops->scan)
6591 return -EOPNOTSUPP;
Johannes Berg2a519312009-02-10 21:25:55 +01006592
Johannes Bergf9d15d12014-01-22 11:14:19 +02006593 if (rdev->scan_req || rdev->scan_msg) {
Johannes Bergf9f47522013-03-19 15:04:07 +01006594 err = -EBUSY;
6595 goto unlock;
6596 }
Johannes Berg2a519312009-02-10 21:25:55 +01006597
6598 if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
Johannes Berg83f5e2c2009-06-17 17:41:49 +02006599 n_channels = validate_scan_freqs(
6600 info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]);
Johannes Bergf9f47522013-03-19 15:04:07 +01006601 if (!n_channels) {
6602 err = -EINVAL;
6603 goto unlock;
6604 }
Johannes Berg2a519312009-02-10 21:25:55 +01006605 } else {
Ilan Peerbdfbec22014-01-09 11:37:23 +02006606 n_channels = ieee80211_get_num_supported_channels(wiphy);
Johannes Berg2a519312009-02-10 21:25:55 +01006607 }
6608
6609 if (info->attrs[NL80211_ATTR_SCAN_SSIDS])
6610 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp)
6611 n_ssids++;
6612
Johannes Bergf9f47522013-03-19 15:04:07 +01006613 if (n_ssids > wiphy->max_scan_ssids) {
6614 err = -EINVAL;
6615 goto unlock;
6616 }
Johannes Berg2a519312009-02-10 21:25:55 +01006617
Jouni Malinen70692ad2009-02-16 19:39:13 +02006618 if (info->attrs[NL80211_ATTR_IE])
6619 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
6620 else
6621 ie_len = 0;
6622
Johannes Bergf9f47522013-03-19 15:04:07 +01006623 if (ie_len > wiphy->max_scan_ie_len) {
6624 err = -EINVAL;
6625 goto unlock;
6626 }
Johannes Berg18a83652009-03-31 12:12:05 +02006627
Johannes Berg2a519312009-02-10 21:25:55 +01006628 request = kzalloc(sizeof(*request)
Luciano Coelhoa2cd43c2011-05-18 11:42:03 +03006629 + sizeof(*request->ssids) * n_ssids
6630 + sizeof(*request->channels) * n_channels
Jouni Malinen70692ad2009-02-16 19:39:13 +02006631 + ie_len, GFP_KERNEL);
Johannes Bergf9f47522013-03-19 15:04:07 +01006632 if (!request) {
6633 err = -ENOMEM;
6634 goto unlock;
6635 }
Johannes Berg2a519312009-02-10 21:25:55 +01006636
Johannes Berg2a519312009-02-10 21:25:55 +01006637 if (n_ssids)
Johannes Berg5ba63532009-08-07 17:54:07 +02006638 request->ssids = (void *)&request->channels[n_channels];
Johannes Berg2a519312009-02-10 21:25:55 +01006639 request->n_ssids = n_ssids;
Jouni Malinen70692ad2009-02-16 19:39:13 +02006640 if (ie_len) {
Johannes Berg13874e42015-01-23 11:25:20 +01006641 if (n_ssids)
Jouni Malinen70692ad2009-02-16 19:39:13 +02006642 request->ie = (void *)(request->ssids + n_ssids);
6643 else
6644 request->ie = (void *)(request->channels + n_channels);
6645 }
Johannes Berg2a519312009-02-10 21:25:55 +01006646
Johannes Berg584991d2009-11-02 13:32:03 +01006647 i = 0;
Johannes Berg2a519312009-02-10 21:25:55 +01006648 if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
6649 /* user specified, bail out if channel not found */
Johannes Berg2a519312009-02-10 21:25:55 +01006650 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_FREQUENCIES], tmp) {
Johannes Berg584991d2009-11-02 13:32:03 +01006651 struct ieee80211_channel *chan;
6652
6653 chan = ieee80211_get_channel(wiphy, nla_get_u32(attr));
6654
6655 if (!chan) {
Johannes Berg2a519312009-02-10 21:25:55 +01006656 err = -EINVAL;
6657 goto out_free;
6658 }
Johannes Berg584991d2009-11-02 13:32:03 +01006659
6660 /* ignore disabled channels */
6661 if (chan->flags & IEEE80211_CHAN_DISABLED)
6662 continue;
6663
6664 request->channels[i] = chan;
Johannes Berg2a519312009-02-10 21:25:55 +01006665 i++;
6666 }
6667 } else {
Johannes Berg57fbcce2016-04-12 15:56:15 +02006668 enum nl80211_band band;
Johannes Berg34850ab2011-07-18 18:08:35 +02006669
Johannes Berg2a519312009-02-10 21:25:55 +01006670 /* all channels */
Johannes Berg57fbcce2016-04-12 15:56:15 +02006671 for (band = 0; band < NUM_NL80211_BANDS; band++) {
Johannes Berg2a519312009-02-10 21:25:55 +01006672 int j;
Kirtika Ruchandani7a087e72016-05-29 19:51:23 -07006673
Johannes Berg2a519312009-02-10 21:25:55 +01006674 if (!wiphy->bands[band])
6675 continue;
6676 for (j = 0; j < wiphy->bands[band]->n_channels; j++) {
Johannes Berg584991d2009-11-02 13:32:03 +01006677 struct ieee80211_channel *chan;
6678
6679 chan = &wiphy->bands[band]->channels[j];
6680
6681 if (chan->flags & IEEE80211_CHAN_DISABLED)
6682 continue;
6683
6684 request->channels[i] = chan;
Johannes Berg2a519312009-02-10 21:25:55 +01006685 i++;
6686 }
6687 }
6688 }
6689
Johannes Berg584991d2009-11-02 13:32:03 +01006690 if (!i) {
6691 err = -EINVAL;
6692 goto out_free;
6693 }
6694
6695 request->n_channels = i;
6696
Vasanthakumar Thiagarajan34373d12017-02-27 17:04:34 +05306697 wdev_lock(wdev);
6698 if (!cfg80211_off_channel_oper_allowed(wdev)) {
6699 struct ieee80211_channel *chan;
6700
6701 if (request->n_channels != 1) {
6702 wdev_unlock(wdev);
6703 err = -EBUSY;
6704 goto out_free;
6705 }
6706
6707 chan = request->channels[0];
6708 if (chan->center_freq != wdev->chandef.chan->center_freq) {
6709 wdev_unlock(wdev);
6710 err = -EBUSY;
6711 goto out_free;
6712 }
6713 }
6714 wdev_unlock(wdev);
6715
Johannes Berg2a519312009-02-10 21:25:55 +01006716 i = 0;
Johannes Berg13874e42015-01-23 11:25:20 +01006717 if (n_ssids) {
Johannes Berg2a519312009-02-10 21:25:55 +01006718 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) {
Luciano Coelho57a27e12011-06-07 20:42:26 +03006719 if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) {
Johannes Berg2a519312009-02-10 21:25:55 +01006720 err = -EINVAL;
6721 goto out_free;
6722 }
Luciano Coelho57a27e12011-06-07 20:42:26 +03006723 request->ssids[i].ssid_len = nla_len(attr);
Johannes Berg2a519312009-02-10 21:25:55 +01006724 memcpy(request->ssids[i].ssid, nla_data(attr), nla_len(attr));
Johannes Berg2a519312009-02-10 21:25:55 +01006725 i++;
6726 }
6727 }
6728
Jouni Malinen70692ad2009-02-16 19:39:13 +02006729 if (info->attrs[NL80211_ATTR_IE]) {
6730 request->ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Johannes Bergde95a542009-04-01 11:58:36 +02006731 memcpy((void *)request->ie,
6732 nla_data(info->attrs[NL80211_ATTR_IE]),
Jouni Malinen70692ad2009-02-16 19:39:13 +02006733 request->ie_len);
6734 }
6735
Johannes Berg57fbcce2016-04-12 15:56:15 +02006736 for (i = 0; i < NUM_NL80211_BANDS; i++)
Johannes Berga401d2b2011-07-20 00:52:16 +02006737 if (wiphy->bands[i])
6738 request->rates[i] =
6739 (1 << wiphy->bands[i]->n_bitrates) - 1;
Johannes Berg34850ab2011-07-18 18:08:35 +02006740
6741 if (info->attrs[NL80211_ATTR_SCAN_SUPP_RATES]) {
6742 nla_for_each_nested(attr,
6743 info->attrs[NL80211_ATTR_SCAN_SUPP_RATES],
6744 tmp) {
Johannes Berg57fbcce2016-04-12 15:56:15 +02006745 enum nl80211_band band = nla_type(attr);
Johannes Berg34850ab2011-07-18 18:08:35 +02006746
Johannes Berg57fbcce2016-04-12 15:56:15 +02006747 if (band < 0 || band >= NUM_NL80211_BANDS) {
Johannes Berg34850ab2011-07-18 18:08:35 +02006748 err = -EINVAL;
6749 goto out_free;
6750 }
Felix Fietkau1b09cd82013-11-20 19:40:41 +01006751
6752 if (!wiphy->bands[band])
6753 continue;
6754
Johannes Berg34850ab2011-07-18 18:08:35 +02006755 err = ieee80211_get_ratemask(wiphy->bands[band],
6756 nla_data(attr),
6757 nla_len(attr),
6758 &request->rates[band]);
6759 if (err)
6760 goto out_free;
6761 }
6762 }
6763
Avraham Stern1d762502016-07-05 17:10:13 +03006764 if (info->attrs[NL80211_ATTR_MEASUREMENT_DURATION]) {
6765 if (!wiphy_ext_feature_isset(wiphy,
6766 NL80211_EXT_FEATURE_SET_SCAN_DWELL)) {
6767 err = -EOPNOTSUPP;
6768 goto out_free;
6769 }
6770
6771 request->duration =
6772 nla_get_u16(info->attrs[NL80211_ATTR_MEASUREMENT_DURATION]);
6773 request->duration_mandatory =
6774 nla_get_flag(info->attrs[NL80211_ATTR_MEASUREMENT_DURATION_MANDATORY]);
6775 }
6776
Sam Leffler46856bb2012-10-11 21:03:32 -07006777 if (info->attrs[NL80211_ATTR_SCAN_FLAGS]) {
Sam Lefflered4737712012-10-11 21:03:31 -07006778 request->flags = nla_get_u32(
6779 info->attrs[NL80211_ATTR_SCAN_FLAGS]);
Johannes Berg00c3a6e2013-10-26 17:14:38 +02006780 if ((request->flags & NL80211_SCAN_FLAG_LOW_PRIORITY) &&
6781 !(wiphy->features & NL80211_FEATURE_LOW_PRIORITY_SCAN)) {
Sam Leffler46856bb2012-10-11 21:03:32 -07006782 err = -EOPNOTSUPP;
6783 goto out_free;
6784 }
Johannes Bergad2b26a2014-06-12 21:39:05 +02006785
6786 if (request->flags & NL80211_SCAN_FLAG_RANDOM_ADDR) {
6787 if (!(wiphy->features &
6788 NL80211_FEATURE_SCAN_RANDOM_MAC_ADDR)) {
6789 err = -EOPNOTSUPP;
6790 goto out_free;
6791 }
6792
6793 if (wdev->current_bss) {
6794 err = -EOPNOTSUPP;
6795 goto out_free;
6796 }
6797
6798 err = nl80211_parse_random_mac(info->attrs,
6799 request->mac_addr,
6800 request->mac_addr_mask);
6801 if (err)
6802 goto out_free;
6803 }
Sam Leffler46856bb2012-10-11 21:03:32 -07006804 }
Sam Lefflered4737712012-10-11 21:03:31 -07006805
Rajkumar Manoharane9f935e2011-09-25 14:53:30 +05306806 request->no_cck =
6807 nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]);
6808
Vamsi Krishna2fa436b2016-12-02 23:59:08 +02006809 /* Initial implementation used NL80211_ATTR_MAC to set the specific
6810 * BSSID to scan for. This was problematic because that same attribute
6811 * was already used for another purpose (local random MAC address). The
6812 * NL80211_ATTR_BSSID attribute was added to fix this. For backwards
6813 * compatibility with older userspace components, also use the
6814 * NL80211_ATTR_MAC value here if it can be determined to be used for
6815 * the specific BSSID use case instead of the random MAC address
6816 * (NL80211_ATTR_SCAN_FLAGS is used to enable random MAC address use).
6817 */
6818 if (info->attrs[NL80211_ATTR_BSSID])
6819 memcpy(request->bssid,
6820 nla_data(info->attrs[NL80211_ATTR_BSSID]), ETH_ALEN);
6821 else if (!(request->flags & NL80211_SCAN_FLAG_RANDOM_ADDR) &&
6822 info->attrs[NL80211_ATTR_MAC])
Jouni Malinen818965d2016-02-26 22:12:47 +02006823 memcpy(request->bssid, nla_data(info->attrs[NL80211_ATTR_MAC]),
6824 ETH_ALEN);
6825 else
6826 eth_broadcast_addr(request->bssid);
6827
Johannes Bergfd014282012-06-18 19:17:03 +02006828 request->wdev = wdev;
Johannes Berg79c97e92009-07-07 03:56:12 +02006829 request->wiphy = &rdev->wiphy;
Sam Leffler15d60302012-10-11 21:03:34 -07006830 request->scan_start = jiffies;
Johannes Berg2a519312009-02-10 21:25:55 +01006831
Johannes Berg79c97e92009-07-07 03:56:12 +02006832 rdev->scan_req = request;
Hila Gonene35e4d22012-06-27 17:19:42 +03006833 err = rdev_scan(rdev, request);
Johannes Berg2a519312009-02-10 21:25:55 +01006834
Johannes Berg463d0182009-07-14 00:33:35 +02006835 if (!err) {
Johannes Bergfd014282012-06-18 19:17:03 +02006836 nl80211_send_scan_start(rdev, wdev);
6837 if (wdev->netdev)
6838 dev_hold(wdev->netdev);
Johannes Berg4c476992010-10-04 21:36:35 +02006839 } else {
Johannes Berg2a519312009-02-10 21:25:55 +01006840 out_free:
Johannes Berg79c97e92009-07-07 03:56:12 +02006841 rdev->scan_req = NULL;
Johannes Berg2a519312009-02-10 21:25:55 +01006842 kfree(request);
6843 }
Johannes Berg3b858752009-03-12 09:55:09 +01006844
Johannes Bergf9f47522013-03-19 15:04:07 +01006845 unlock:
Johannes Berg2a519312009-02-10 21:25:55 +01006846 return err;
6847}
6848
Vidyullatha Kanchanapally91d3ab42015-10-30 19:14:49 +05306849static int nl80211_abort_scan(struct sk_buff *skb, struct genl_info *info)
6850{
6851 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6852 struct wireless_dev *wdev = info->user_ptr[1];
6853
6854 if (!rdev->ops->abort_scan)
6855 return -EOPNOTSUPP;
6856
6857 if (rdev->scan_msg)
6858 return 0;
6859
6860 if (!rdev->scan_req)
6861 return -ENOENT;
6862
6863 rdev_abort_scan(rdev, wdev);
6864 return 0;
6865}
6866
Avraham Stern3b06d272015-10-12 09:51:34 +03006867static int
6868nl80211_parse_sched_scan_plans(struct wiphy *wiphy, int n_plans,
6869 struct cfg80211_sched_scan_request *request,
6870 struct nlattr **attrs)
6871{
6872 int tmp, err, i = 0;
6873 struct nlattr *attr;
6874
6875 if (!attrs[NL80211_ATTR_SCHED_SCAN_PLANS]) {
6876 u32 interval;
6877
6878 /*
6879 * If scan plans are not specified,
Arend Van Spriel5a88de52016-11-17 09:02:40 +00006880 * %NL80211_ATTR_SCHED_SCAN_INTERVAL will be specified. In this
Avraham Stern3b06d272015-10-12 09:51:34 +03006881 * case one scan plan will be set with the specified scan
6882 * interval and infinite number of iterations.
6883 */
Avraham Stern3b06d272015-10-12 09:51:34 +03006884 interval = nla_get_u32(attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]);
6885 if (!interval)
6886 return -EINVAL;
6887
6888 request->scan_plans[0].interval =
6889 DIV_ROUND_UP(interval, MSEC_PER_SEC);
6890 if (!request->scan_plans[0].interval)
6891 return -EINVAL;
6892
6893 if (request->scan_plans[0].interval >
6894 wiphy->max_sched_scan_plan_interval)
6895 request->scan_plans[0].interval =
6896 wiphy->max_sched_scan_plan_interval;
6897
6898 return 0;
6899 }
6900
6901 nla_for_each_nested(attr, attrs[NL80211_ATTR_SCHED_SCAN_PLANS], tmp) {
6902 struct nlattr *plan[NL80211_SCHED_SCAN_PLAN_MAX + 1];
6903
6904 if (WARN_ON(i >= n_plans))
6905 return -EINVAL;
6906
Johannes Bergbfe2c7b2016-10-26 14:42:21 +02006907 err = nla_parse_nested(plan, NL80211_SCHED_SCAN_PLAN_MAX,
6908 attr, nl80211_plan_policy);
Avraham Stern3b06d272015-10-12 09:51:34 +03006909 if (err)
6910 return err;
6911
6912 if (!plan[NL80211_SCHED_SCAN_PLAN_INTERVAL])
6913 return -EINVAL;
6914
6915 request->scan_plans[i].interval =
6916 nla_get_u32(plan[NL80211_SCHED_SCAN_PLAN_INTERVAL]);
6917 if (!request->scan_plans[i].interval ||
6918 request->scan_plans[i].interval >
6919 wiphy->max_sched_scan_plan_interval)
6920 return -EINVAL;
6921
6922 if (plan[NL80211_SCHED_SCAN_PLAN_ITERATIONS]) {
6923 request->scan_plans[i].iterations =
6924 nla_get_u32(plan[NL80211_SCHED_SCAN_PLAN_ITERATIONS]);
6925 if (!request->scan_plans[i].iterations ||
6926 (request->scan_plans[i].iterations >
6927 wiphy->max_sched_scan_plan_iterations))
6928 return -EINVAL;
6929 } else if (i < n_plans - 1) {
6930 /*
6931 * All scan plans but the last one must specify
6932 * a finite number of iterations
6933 */
6934 return -EINVAL;
6935 }
6936
6937 i++;
6938 }
6939
6940 /*
6941 * The last scan plan must not specify the number of
6942 * iterations, it is supposed to run infinitely
6943 */
6944 if (request->scan_plans[n_plans - 1].iterations)
6945 return -EINVAL;
6946
6947 return 0;
6948}
6949
Luciano Coelho256da022014-11-10 16:13:46 +02006950static struct cfg80211_sched_scan_request *
Johannes Bergad2b26a2014-06-12 21:39:05 +02006951nl80211_parse_sched_scan(struct wiphy *wiphy, struct wireless_dev *wdev,
Arend Van Sprielaad1e812017-01-27 12:27:44 +00006952 struct nlattr **attrs, int max_match_sets)
Luciano Coelho807f8a82011-05-11 17:09:35 +03006953{
6954 struct cfg80211_sched_scan_request *request;
Luciano Coelho807f8a82011-05-11 17:09:35 +03006955 struct nlattr *attr;
Avraham Stern3b06d272015-10-12 09:51:34 +03006956 int err, tmp, n_ssids = 0, n_match_sets = 0, n_channels, i, n_plans = 0;
Johannes Berg57fbcce2016-04-12 15:56:15 +02006957 enum nl80211_band band;
Luciano Coelho807f8a82011-05-11 17:09:35 +03006958 size_t ie_len;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03006959 struct nlattr *tb[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1];
Johannes Bergea73cbc2014-01-24 10:53:53 +01006960 s32 default_match_rssi = NL80211_SCAN_RSSI_THOLD_OFF;
Luciano Coelho807f8a82011-05-11 17:09:35 +03006961
Luciano Coelho256da022014-11-10 16:13:46 +02006962 if (!is_valid_ie_attr(attrs[NL80211_ATTR_IE]))
6963 return ERR_PTR(-EINVAL);
Luciano Coelho807f8a82011-05-11 17:09:35 +03006964
Luciano Coelho256da022014-11-10 16:13:46 +02006965 if (attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
Luciano Coelho807f8a82011-05-11 17:09:35 +03006966 n_channels = validate_scan_freqs(
Luciano Coelho256da022014-11-10 16:13:46 +02006967 attrs[NL80211_ATTR_SCAN_FREQUENCIES]);
Luciano Coelho807f8a82011-05-11 17:09:35 +03006968 if (!n_channels)
Luciano Coelho256da022014-11-10 16:13:46 +02006969 return ERR_PTR(-EINVAL);
Luciano Coelho807f8a82011-05-11 17:09:35 +03006970 } else {
Ilan Peerbdfbec22014-01-09 11:37:23 +02006971 n_channels = ieee80211_get_num_supported_channels(wiphy);
Luciano Coelho807f8a82011-05-11 17:09:35 +03006972 }
6973
Luciano Coelho256da022014-11-10 16:13:46 +02006974 if (attrs[NL80211_ATTR_SCAN_SSIDS])
6975 nla_for_each_nested(attr, attrs[NL80211_ATTR_SCAN_SSIDS],
Luciano Coelho807f8a82011-05-11 17:09:35 +03006976 tmp)
6977 n_ssids++;
6978
Luciano Coelho93b6aa62011-07-13 14:57:28 +03006979 if (n_ssids > wiphy->max_sched_scan_ssids)
Luciano Coelho256da022014-11-10 16:13:46 +02006980 return ERR_PTR(-EINVAL);
Luciano Coelho807f8a82011-05-11 17:09:35 +03006981
Johannes Bergea73cbc2014-01-24 10:53:53 +01006982 /*
6983 * First, count the number of 'real' matchsets. Due to an issue with
6984 * the old implementation, matchsets containing only the RSSI attribute
6985 * (NL80211_SCHED_SCAN_MATCH_ATTR_RSSI) are considered as the 'default'
6986 * RSSI for all matchsets, rather than their own matchset for reporting
6987 * all APs with a strong RSSI. This is needed to be compatible with
6988 * older userspace that treated a matchset with only the RSSI as the
6989 * global RSSI for all other matchsets - if there are other matchsets.
6990 */
Luciano Coelho256da022014-11-10 16:13:46 +02006991 if (attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) {
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03006992 nla_for_each_nested(attr,
Luciano Coelho256da022014-11-10 16:13:46 +02006993 attrs[NL80211_ATTR_SCHED_SCAN_MATCH],
Johannes Bergea73cbc2014-01-24 10:53:53 +01006994 tmp) {
6995 struct nlattr *rssi;
6996
Johannes Bergbfe2c7b2016-10-26 14:42:21 +02006997 err = nla_parse_nested(tb,
6998 NL80211_SCHED_SCAN_MATCH_ATTR_MAX,
6999 attr, nl80211_match_policy);
Johannes Bergea73cbc2014-01-24 10:53:53 +01007000 if (err)
Luciano Coelho256da022014-11-10 16:13:46 +02007001 return ERR_PTR(err);
Johannes Bergea73cbc2014-01-24 10:53:53 +01007002 /* add other standalone attributes here */
7003 if (tb[NL80211_SCHED_SCAN_MATCH_ATTR_SSID]) {
7004 n_match_sets++;
7005 continue;
7006 }
7007 rssi = tb[NL80211_SCHED_SCAN_MATCH_ATTR_RSSI];
7008 if (rssi)
7009 default_match_rssi = nla_get_s32(rssi);
7010 }
7011 }
7012
7013 /* However, if there's no other matchset, add the RSSI one */
7014 if (!n_match_sets && default_match_rssi != NL80211_SCAN_RSSI_THOLD_OFF)
7015 n_match_sets = 1;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03007016
Arend Van Sprielaad1e812017-01-27 12:27:44 +00007017 if (n_match_sets > max_match_sets)
Luciano Coelho256da022014-11-10 16:13:46 +02007018 return ERR_PTR(-EINVAL);
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03007019
Luciano Coelho256da022014-11-10 16:13:46 +02007020 if (attrs[NL80211_ATTR_IE])
7021 ie_len = nla_len(attrs[NL80211_ATTR_IE]);
Luciano Coelho807f8a82011-05-11 17:09:35 +03007022 else
7023 ie_len = 0;
7024
Luciano Coelho5a865ba2011-07-13 14:57:29 +03007025 if (ie_len > wiphy->max_sched_scan_ie_len)
Luciano Coelho256da022014-11-10 16:13:46 +02007026 return ERR_PTR(-EINVAL);
Luciano Coelhoc10841c2011-06-30 08:32:41 +03007027
Avraham Stern3b06d272015-10-12 09:51:34 +03007028 if (attrs[NL80211_ATTR_SCHED_SCAN_PLANS]) {
7029 /*
7030 * NL80211_ATTR_SCHED_SCAN_INTERVAL must not be specified since
7031 * each scan plan already specifies its own interval
7032 */
7033 if (attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL])
7034 return ERR_PTR(-EINVAL);
7035
7036 nla_for_each_nested(attr,
7037 attrs[NL80211_ATTR_SCHED_SCAN_PLANS], tmp)
7038 n_plans++;
7039 } else {
7040 /*
7041 * The scan interval attribute is kept for backward
7042 * compatibility. If no scan plans are specified and sched scan
7043 * interval is specified, one scan plan will be set with this
7044 * scan interval and infinite number of iterations.
7045 */
7046 if (!attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL])
7047 return ERR_PTR(-EINVAL);
7048
7049 n_plans = 1;
7050 }
7051
7052 if (!n_plans || n_plans > wiphy->max_sched_scan_plans)
7053 return ERR_PTR(-EINVAL);
7054
vamsi krishnabf95ecd2017-01-13 01:12:20 +02007055 if (!wiphy_ext_feature_isset(
7056 wiphy, NL80211_EXT_FEATURE_SCHED_SCAN_RELATIVE_RSSI) &&
7057 (attrs[NL80211_ATTR_SCHED_SCAN_RELATIVE_RSSI] ||
7058 attrs[NL80211_ATTR_SCHED_SCAN_RSSI_ADJUST]))
7059 return ERR_PTR(-EINVAL);
7060
Luciano Coelho807f8a82011-05-11 17:09:35 +03007061 request = kzalloc(sizeof(*request)
Luciano Coelhoa2cd43c2011-05-18 11:42:03 +03007062 + sizeof(*request->ssids) * n_ssids
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03007063 + sizeof(*request->match_sets) * n_match_sets
Avraham Stern3b06d272015-10-12 09:51:34 +03007064 + sizeof(*request->scan_plans) * n_plans
Luciano Coelhoa2cd43c2011-05-18 11:42:03 +03007065 + sizeof(*request->channels) * n_channels
Luciano Coelho807f8a82011-05-11 17:09:35 +03007066 + ie_len, GFP_KERNEL);
Luciano Coelho256da022014-11-10 16:13:46 +02007067 if (!request)
7068 return ERR_PTR(-ENOMEM);
Luciano Coelho807f8a82011-05-11 17:09:35 +03007069
7070 if (n_ssids)
7071 request->ssids = (void *)&request->channels[n_channels];
7072 request->n_ssids = n_ssids;
7073 if (ie_len) {
Johannes Berg13874e42015-01-23 11:25:20 +01007074 if (n_ssids)
Luciano Coelho807f8a82011-05-11 17:09:35 +03007075 request->ie = (void *)(request->ssids + n_ssids);
7076 else
7077 request->ie = (void *)(request->channels + n_channels);
7078 }
7079
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03007080 if (n_match_sets) {
7081 if (request->ie)
7082 request->match_sets = (void *)(request->ie + ie_len);
Johannes Berg13874e42015-01-23 11:25:20 +01007083 else if (n_ssids)
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03007084 request->match_sets =
7085 (void *)(request->ssids + n_ssids);
7086 else
7087 request->match_sets =
7088 (void *)(request->channels + n_channels);
7089 }
7090 request->n_match_sets = n_match_sets;
7091
Avraham Stern3b06d272015-10-12 09:51:34 +03007092 if (n_match_sets)
7093 request->scan_plans = (void *)(request->match_sets +
7094 n_match_sets);
7095 else if (request->ie)
7096 request->scan_plans = (void *)(request->ie + ie_len);
7097 else if (n_ssids)
7098 request->scan_plans = (void *)(request->ssids + n_ssids);
7099 else
7100 request->scan_plans = (void *)(request->channels + n_channels);
7101
7102 request->n_scan_plans = n_plans;
7103
Luciano Coelho807f8a82011-05-11 17:09:35 +03007104 i = 0;
Luciano Coelho256da022014-11-10 16:13:46 +02007105 if (attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
Luciano Coelho807f8a82011-05-11 17:09:35 +03007106 /* user specified, bail out if channel not found */
7107 nla_for_each_nested(attr,
Luciano Coelho256da022014-11-10 16:13:46 +02007108 attrs[NL80211_ATTR_SCAN_FREQUENCIES],
Luciano Coelho807f8a82011-05-11 17:09:35 +03007109 tmp) {
7110 struct ieee80211_channel *chan;
7111
7112 chan = ieee80211_get_channel(wiphy, nla_get_u32(attr));
7113
7114 if (!chan) {
7115 err = -EINVAL;
7116 goto out_free;
7117 }
7118
7119 /* ignore disabled channels */
7120 if (chan->flags & IEEE80211_CHAN_DISABLED)
7121 continue;
7122
7123 request->channels[i] = chan;
7124 i++;
7125 }
7126 } else {
7127 /* all channels */
Johannes Berg57fbcce2016-04-12 15:56:15 +02007128 for (band = 0; band < NUM_NL80211_BANDS; band++) {
Luciano Coelho807f8a82011-05-11 17:09:35 +03007129 int j;
Kirtika Ruchandani7a087e72016-05-29 19:51:23 -07007130
Luciano Coelho807f8a82011-05-11 17:09:35 +03007131 if (!wiphy->bands[band])
7132 continue;
7133 for (j = 0; j < wiphy->bands[band]->n_channels; j++) {
7134 struct ieee80211_channel *chan;
7135
7136 chan = &wiphy->bands[band]->channels[j];
7137
7138 if (chan->flags & IEEE80211_CHAN_DISABLED)
7139 continue;
7140
7141 request->channels[i] = chan;
7142 i++;
7143 }
7144 }
7145 }
7146
7147 if (!i) {
7148 err = -EINVAL;
7149 goto out_free;
7150 }
7151
7152 request->n_channels = i;
7153
7154 i = 0;
Johannes Berg13874e42015-01-23 11:25:20 +01007155 if (n_ssids) {
Luciano Coelho256da022014-11-10 16:13:46 +02007156 nla_for_each_nested(attr, attrs[NL80211_ATTR_SCAN_SSIDS],
Luciano Coelho807f8a82011-05-11 17:09:35 +03007157 tmp) {
Luciano Coelho57a27e12011-06-07 20:42:26 +03007158 if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) {
Luciano Coelho807f8a82011-05-11 17:09:35 +03007159 err = -EINVAL;
7160 goto out_free;
7161 }
Luciano Coelho57a27e12011-06-07 20:42:26 +03007162 request->ssids[i].ssid_len = nla_len(attr);
Luciano Coelho807f8a82011-05-11 17:09:35 +03007163 memcpy(request->ssids[i].ssid, nla_data(attr),
7164 nla_len(attr));
Luciano Coelho807f8a82011-05-11 17:09:35 +03007165 i++;
7166 }
7167 }
7168
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03007169 i = 0;
Luciano Coelho256da022014-11-10 16:13:46 +02007170 if (attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) {
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03007171 nla_for_each_nested(attr,
Luciano Coelho256da022014-11-10 16:13:46 +02007172 attrs[NL80211_ATTR_SCHED_SCAN_MATCH],
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03007173 tmp) {
Thomas Pedersen88e920b2012-06-21 11:09:54 -07007174 struct nlattr *ssid, *rssi;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03007175
Johannes Bergbfe2c7b2016-10-26 14:42:21 +02007176 err = nla_parse_nested(tb,
7177 NL80211_SCHED_SCAN_MATCH_ATTR_MAX,
7178 attr, nl80211_match_policy);
Johannes Bergae811e22014-01-24 10:17:47 +01007179 if (err)
7180 goto out_free;
Johannes Berg4a4ab0d2012-06-13 11:17:11 +02007181 ssid = tb[NL80211_SCHED_SCAN_MATCH_ATTR_SSID];
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03007182 if (ssid) {
Johannes Bergea73cbc2014-01-24 10:53:53 +01007183 if (WARN_ON(i >= n_match_sets)) {
7184 /* this indicates a programming error,
7185 * the loop above should have verified
7186 * things properly
7187 */
7188 err = -EINVAL;
7189 goto out_free;
7190 }
7191
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03007192 if (nla_len(ssid) > IEEE80211_MAX_SSID_LEN) {
7193 err = -EINVAL;
7194 goto out_free;
7195 }
7196 memcpy(request->match_sets[i].ssid.ssid,
7197 nla_data(ssid), nla_len(ssid));
7198 request->match_sets[i].ssid.ssid_len =
7199 nla_len(ssid);
Kirtika Ruchandani56ab3642016-05-29 19:54:10 -07007200 /* special attribute - old implementation w/a */
Johannes Bergea73cbc2014-01-24 10:53:53 +01007201 request->match_sets[i].rssi_thold =
7202 default_match_rssi;
7203 rssi = tb[NL80211_SCHED_SCAN_MATCH_ATTR_RSSI];
7204 if (rssi)
7205 request->match_sets[i].rssi_thold =
7206 nla_get_s32(rssi);
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03007207 }
7208 i++;
7209 }
Johannes Bergea73cbc2014-01-24 10:53:53 +01007210
7211 /* there was no other matchset, so the RSSI one is alone */
Luciano Coelhof89f46c2014-12-01 11:32:09 +02007212 if (i == 0 && n_match_sets)
Johannes Bergea73cbc2014-01-24 10:53:53 +01007213 request->match_sets[0].rssi_thold = default_match_rssi;
7214
7215 request->min_rssi_thold = INT_MAX;
7216 for (i = 0; i < n_match_sets; i++)
7217 request->min_rssi_thold =
7218 min(request->match_sets[i].rssi_thold,
7219 request->min_rssi_thold);
7220 } else {
7221 request->min_rssi_thold = NL80211_SCAN_RSSI_THOLD_OFF;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03007222 }
7223
Johannes Berg9900e482014-02-04 21:01:25 +01007224 if (ie_len) {
7225 request->ie_len = ie_len;
Luciano Coelho807f8a82011-05-11 17:09:35 +03007226 memcpy((void *)request->ie,
Luciano Coelho256da022014-11-10 16:13:46 +02007227 nla_data(attrs[NL80211_ATTR_IE]),
Luciano Coelho807f8a82011-05-11 17:09:35 +03007228 request->ie_len);
7229 }
7230
Luciano Coelho256da022014-11-10 16:13:46 +02007231 if (attrs[NL80211_ATTR_SCAN_FLAGS]) {
Sam Lefflered4737712012-10-11 21:03:31 -07007232 request->flags = nla_get_u32(
Luciano Coelho256da022014-11-10 16:13:46 +02007233 attrs[NL80211_ATTR_SCAN_FLAGS]);
Johannes Berg00c3a6e2013-10-26 17:14:38 +02007234 if ((request->flags & NL80211_SCAN_FLAG_LOW_PRIORITY) &&
7235 !(wiphy->features & NL80211_FEATURE_LOW_PRIORITY_SCAN)) {
Sam Leffler46856bb2012-10-11 21:03:32 -07007236 err = -EOPNOTSUPP;
7237 goto out_free;
7238 }
Johannes Bergad2b26a2014-06-12 21:39:05 +02007239
7240 if (request->flags & NL80211_SCAN_FLAG_RANDOM_ADDR) {
7241 u32 flg = NL80211_FEATURE_SCHED_SCAN_RANDOM_MAC_ADDR;
7242
7243 if (!wdev) /* must be net-detect */
7244 flg = NL80211_FEATURE_ND_RANDOM_MAC_ADDR;
7245
7246 if (!(wiphy->features & flg)) {
7247 err = -EOPNOTSUPP;
7248 goto out_free;
7249 }
7250
7251 if (wdev && wdev->current_bss) {
7252 err = -EOPNOTSUPP;
7253 goto out_free;
7254 }
7255
7256 err = nl80211_parse_random_mac(attrs, request->mac_addr,
7257 request->mac_addr_mask);
7258 if (err)
7259 goto out_free;
7260 }
Sam Leffler46856bb2012-10-11 21:03:32 -07007261 }
Sam Lefflered4737712012-10-11 21:03:31 -07007262
Luciano Coelho9c748932015-01-16 16:04:09 +02007263 if (attrs[NL80211_ATTR_SCHED_SCAN_DELAY])
7264 request->delay =
7265 nla_get_u32(attrs[NL80211_ATTR_SCHED_SCAN_DELAY]);
7266
vamsi krishnabf95ecd2017-01-13 01:12:20 +02007267 if (attrs[NL80211_ATTR_SCHED_SCAN_RELATIVE_RSSI]) {
7268 request->relative_rssi = nla_get_s8(
7269 attrs[NL80211_ATTR_SCHED_SCAN_RELATIVE_RSSI]);
7270 request->relative_rssi_set = true;
7271 }
7272
7273 if (request->relative_rssi_set &&
7274 attrs[NL80211_ATTR_SCHED_SCAN_RSSI_ADJUST]) {
7275 struct nl80211_bss_select_rssi_adjust *rssi_adjust;
7276
7277 rssi_adjust = nla_data(
7278 attrs[NL80211_ATTR_SCHED_SCAN_RSSI_ADJUST]);
7279 request->rssi_adjust.band = rssi_adjust->band;
7280 request->rssi_adjust.delta = rssi_adjust->delta;
7281 if (!is_band_valid(wiphy, request->rssi_adjust.band)) {
7282 err = -EINVAL;
7283 goto out_free;
7284 }
7285 }
7286
Avraham Stern3b06d272015-10-12 09:51:34 +03007287 err = nl80211_parse_sched_scan_plans(wiphy, n_plans, request, attrs);
7288 if (err)
7289 goto out_free;
7290
Sam Leffler15d60302012-10-11 21:03:34 -07007291 request->scan_start = jiffies;
Luciano Coelho807f8a82011-05-11 17:09:35 +03007292
Luciano Coelho256da022014-11-10 16:13:46 +02007293 return request;
Luciano Coelho807f8a82011-05-11 17:09:35 +03007294
7295out_free:
7296 kfree(request);
Luciano Coelho256da022014-11-10 16:13:46 +02007297 return ERR_PTR(err);
7298}
7299
7300static int nl80211_start_sched_scan(struct sk_buff *skb,
7301 struct genl_info *info)
7302{
7303 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7304 struct net_device *dev = info->user_ptr[1];
Johannes Bergad2b26a2014-06-12 21:39:05 +02007305 struct wireless_dev *wdev = dev->ieee80211_ptr;
Jukka Rissanen31a60ed2014-12-15 13:25:38 +02007306 struct cfg80211_sched_scan_request *sched_scan_req;
Luciano Coelho256da022014-11-10 16:13:46 +02007307 int err;
7308
7309 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) ||
7310 !rdev->ops->sched_scan_start)
7311 return -EOPNOTSUPP;
7312
7313 if (rdev->sched_scan_req)
7314 return -EINPROGRESS;
7315
Jukka Rissanen31a60ed2014-12-15 13:25:38 +02007316 sched_scan_req = nl80211_parse_sched_scan(&rdev->wiphy, wdev,
Arend Van Sprielaad1e812017-01-27 12:27:44 +00007317 info->attrs,
7318 rdev->wiphy.max_match_sets);
Jukka Rissanen31a60ed2014-12-15 13:25:38 +02007319
7320 err = PTR_ERR_OR_ZERO(sched_scan_req);
Luciano Coelho256da022014-11-10 16:13:46 +02007321 if (err)
7322 goto out_err;
7323
Jukka Rissanen31a60ed2014-12-15 13:25:38 +02007324 err = rdev_sched_scan_start(rdev, dev, sched_scan_req);
Luciano Coelho256da022014-11-10 16:13:46 +02007325 if (err)
7326 goto out_free;
7327
Jukka Rissanen31a60ed2014-12-15 13:25:38 +02007328 sched_scan_req->dev = dev;
7329 sched_scan_req->wiphy = &rdev->wiphy;
7330
Jukka Rissanen93a1e862014-12-15 13:25:39 +02007331 if (info->attrs[NL80211_ATTR_SOCKET_OWNER])
7332 sched_scan_req->owner_nlportid = info->snd_portid;
7333
Jukka Rissanen31a60ed2014-12-15 13:25:38 +02007334 rcu_assign_pointer(rdev->sched_scan_req, sched_scan_req);
Luciano Coelho256da022014-11-10 16:13:46 +02007335
7336 nl80211_send_sched_scan(rdev, dev,
7337 NL80211_CMD_START_SCHED_SCAN);
7338 return 0;
7339
7340out_free:
Jukka Rissanen31a60ed2014-12-15 13:25:38 +02007341 kfree(sched_scan_req);
Luciano Coelho256da022014-11-10 16:13:46 +02007342out_err:
Luciano Coelho807f8a82011-05-11 17:09:35 +03007343 return err;
7344}
7345
7346static int nl80211_stop_sched_scan(struct sk_buff *skb,
7347 struct genl_info *info)
7348{
7349 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7350
7351 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) ||
7352 !rdev->ops->sched_scan_stop)
7353 return -EOPNOTSUPP;
7354
Johannes Berg5fe231e2013-05-08 21:45:15 +02007355 return __cfg80211_stop_sched_scan(rdev, false);
Luciano Coelho807f8a82011-05-11 17:09:35 +03007356}
7357
Simon Wunderlich04f39042013-02-08 18:16:19 +01007358static int nl80211_start_radar_detection(struct sk_buff *skb,
7359 struct genl_info *info)
7360{
7361 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7362 struct net_device *dev = info->user_ptr[1];
7363 struct wireless_dev *wdev = dev->ieee80211_ptr;
7364 struct cfg80211_chan_def chandef;
Luis R. Rodriguez55f74352013-11-25 20:56:10 +01007365 enum nl80211_dfs_regions dfs_region;
Janusz Dziedzic31559f32014-02-21 19:46:13 +01007366 unsigned int cac_time_ms;
Simon Wunderlich04f39042013-02-08 18:16:19 +01007367 int err;
7368
Luis R. Rodriguez55f74352013-11-25 20:56:10 +01007369 dfs_region = reg_get_dfs_region(wdev->wiphy);
7370 if (dfs_region == NL80211_DFS_UNSET)
7371 return -EINVAL;
7372
Simon Wunderlich04f39042013-02-08 18:16:19 +01007373 err = nl80211_parse_chandef(rdev, info, &chandef);
7374 if (err)
7375 return err;
7376
Simon Wunderlichff311bc2013-09-03 19:43:18 +02007377 if (netif_carrier_ok(dev))
7378 return -EBUSY;
7379
Simon Wunderlich04f39042013-02-08 18:16:19 +01007380 if (wdev->cac_started)
7381 return -EBUSY;
7382
Luciano Coelho2beb6dab2014-02-18 11:40:36 +02007383 err = cfg80211_chandef_dfs_required(wdev->wiphy, &chandef,
Luciano Coelho00ec75f2014-05-15 13:05:39 +03007384 wdev->iftype);
Simon Wunderlich04f39042013-02-08 18:16:19 +01007385 if (err < 0)
7386 return err;
7387
7388 if (err == 0)
7389 return -EINVAL;
7390
Janusz Dziedzicfe7c3a12013-11-05 14:48:48 +01007391 if (!cfg80211_chandef_dfs_usable(wdev->wiphy, &chandef))
Simon Wunderlich04f39042013-02-08 18:16:19 +01007392 return -EINVAL;
7393
7394 if (!rdev->ops->start_radar_detection)
7395 return -EOPNOTSUPP;
7396
Janusz Dziedzic31559f32014-02-21 19:46:13 +01007397 cac_time_ms = cfg80211_chandef_dfs_cac_time(&rdev->wiphy, &chandef);
7398 if (WARN_ON(!cac_time_ms))
7399 cac_time_ms = IEEE80211_DFS_MIN_CAC_TIME_MS;
7400
Ilan Peera1056b1b2015-10-22 22:27:46 +03007401 err = rdev_start_radar_detection(rdev, dev, &chandef, cac_time_ms);
Simon Wunderlich04f39042013-02-08 18:16:19 +01007402 if (!err) {
Michal Kazior9e0e2962014-01-29 14:22:27 +01007403 wdev->chandef = chandef;
Simon Wunderlich04f39042013-02-08 18:16:19 +01007404 wdev->cac_started = true;
7405 wdev->cac_start_time = jiffies;
Janusz Dziedzic31559f32014-02-21 19:46:13 +01007406 wdev->cac_time_ms = cac_time_ms;
Simon Wunderlich04f39042013-02-08 18:16:19 +01007407 }
Simon Wunderlich04f39042013-02-08 18:16:19 +01007408 return err;
7409}
7410
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02007411static int nl80211_channel_switch(struct sk_buff *skb, struct genl_info *info)
7412{
7413 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7414 struct net_device *dev = info->user_ptr[1];
7415 struct wireless_dev *wdev = dev->ieee80211_ptr;
7416 struct cfg80211_csa_settings params;
7417 /* csa_attrs is defined static to avoid waste of stack size - this
7418 * function is called under RTNL lock, so this should not be a problem.
7419 */
7420 static struct nlattr *csa_attrs[NL80211_ATTR_MAX+1];
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02007421 int err;
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02007422 bool need_new_beacon = false;
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03007423 int len, i;
Luciano Coelho252e07c2014-10-08 09:48:34 +03007424 u32 cs_count;
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02007425
7426 if (!rdev->ops->channel_switch ||
7427 !(rdev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH))
7428 return -EOPNOTSUPP;
7429
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02007430 switch (dev->ieee80211_ptr->iftype) {
7431 case NL80211_IFTYPE_AP:
7432 case NL80211_IFTYPE_P2P_GO:
7433 need_new_beacon = true;
7434
7435 /* useless if AP is not running */
7436 if (!wdev->beacon_interval)
Johannes Berg1ff79df2014-01-22 10:05:27 +01007437 return -ENOTCONN;
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02007438 break;
7439 case NL80211_IFTYPE_ADHOC:
Johannes Berg1ff79df2014-01-22 10:05:27 +01007440 if (!wdev->ssid_len)
7441 return -ENOTCONN;
7442 break;
Chun-Yeow Yeohc6da6742013-10-14 19:08:28 -07007443 case NL80211_IFTYPE_MESH_POINT:
Johannes Berg1ff79df2014-01-22 10:05:27 +01007444 if (!wdev->mesh_id_len)
7445 return -ENOTCONN;
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02007446 break;
7447 default:
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02007448 return -EOPNOTSUPP;
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02007449 }
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02007450
7451 memset(&params, 0, sizeof(params));
7452
7453 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] ||
7454 !info->attrs[NL80211_ATTR_CH_SWITCH_COUNT])
7455 return -EINVAL;
7456
7457 /* only important for AP, IBSS and mesh create IEs internally */
Andrei Otcheretianskid0a361a2013-10-17 10:52:17 +02007458 if (need_new_beacon && !info->attrs[NL80211_ATTR_CSA_IES])
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02007459 return -EINVAL;
7460
Luciano Coelho252e07c2014-10-08 09:48:34 +03007461 /* Even though the attribute is u32, the specification says
7462 * u8, so let's make sure we don't overflow.
7463 */
7464 cs_count = nla_get_u32(info->attrs[NL80211_ATTR_CH_SWITCH_COUNT]);
7465 if (cs_count > 255)
7466 return -EINVAL;
7467
7468 params.count = cs_count;
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02007469
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02007470 if (!need_new_beacon)
7471 goto skip_beacons;
7472
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02007473 err = nl80211_parse_beacon(info->attrs, &params.beacon_after);
7474 if (err)
7475 return err;
7476
7477 err = nla_parse_nested(csa_attrs, NL80211_ATTR_MAX,
7478 info->attrs[NL80211_ATTR_CSA_IES],
7479 nl80211_policy);
7480 if (err)
7481 return err;
7482
7483 err = nl80211_parse_beacon(csa_attrs, &params.beacon_csa);
7484 if (err)
7485 return err;
7486
7487 if (!csa_attrs[NL80211_ATTR_CSA_C_OFF_BEACON])
7488 return -EINVAL;
7489
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03007490 len = nla_len(csa_attrs[NL80211_ATTR_CSA_C_OFF_BEACON]);
7491 if (!len || (len % sizeof(u16)))
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02007492 return -EINVAL;
7493
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03007494 params.n_counter_offsets_beacon = len / sizeof(u16);
7495 if (rdev->wiphy.max_num_csa_counters &&
7496 (params.n_counter_offsets_beacon >
7497 rdev->wiphy.max_num_csa_counters))
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02007498 return -EINVAL;
7499
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03007500 params.counter_offsets_beacon =
7501 nla_data(csa_attrs[NL80211_ATTR_CSA_C_OFF_BEACON]);
7502
7503 /* sanity checks - counters should fit and be the same */
7504 for (i = 0; i < params.n_counter_offsets_beacon; i++) {
7505 u16 offset = params.counter_offsets_beacon[i];
7506
7507 if (offset >= params.beacon_csa.tail_len)
7508 return -EINVAL;
7509
7510 if (params.beacon_csa.tail[offset] != params.count)
7511 return -EINVAL;
7512 }
7513
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02007514 if (csa_attrs[NL80211_ATTR_CSA_C_OFF_PRESP]) {
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03007515 len = nla_len(csa_attrs[NL80211_ATTR_CSA_C_OFF_PRESP]);
7516 if (!len || (len % sizeof(u16)))
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02007517 return -EINVAL;
7518
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03007519 params.n_counter_offsets_presp = len / sizeof(u16);
7520 if (rdev->wiphy.max_num_csa_counters &&
Johannes Bergad5987b2016-09-13 15:53:55 +02007521 (params.n_counter_offsets_presp >
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03007522 rdev->wiphy.max_num_csa_counters))
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02007523 return -EINVAL;
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03007524
7525 params.counter_offsets_presp =
7526 nla_data(csa_attrs[NL80211_ATTR_CSA_C_OFF_PRESP]);
7527
7528 /* sanity checks - counters should fit and be the same */
7529 for (i = 0; i < params.n_counter_offsets_presp; i++) {
7530 u16 offset = params.counter_offsets_presp[i];
7531
7532 if (offset >= params.beacon_csa.probe_resp_len)
7533 return -EINVAL;
7534
7535 if (params.beacon_csa.probe_resp[offset] !=
7536 params.count)
7537 return -EINVAL;
7538 }
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02007539 }
7540
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02007541skip_beacons:
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02007542 err = nl80211_parse_chandef(rdev, info, &params.chandef);
7543 if (err)
7544 return err;
7545
Arik Nemtsov923b3522015-07-08 15:41:44 +03007546 if (!cfg80211_reg_can_beacon_relax(&rdev->wiphy, &params.chandef,
7547 wdev->iftype))
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02007548 return -EINVAL;
7549
Luciano Coelho2beb6dab2014-02-18 11:40:36 +02007550 err = cfg80211_chandef_dfs_required(wdev->wiphy,
7551 &params.chandef,
7552 wdev->iftype);
7553 if (err < 0)
7554 return err;
7555
Fabian Frederickdcc6c2f2014-10-25 17:57:35 +02007556 if (err > 0)
Luciano Coelho2beb6dab2014-02-18 11:40:36 +02007557 params.radar_required = true;
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02007558
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02007559 if (info->attrs[NL80211_ATTR_CH_SWITCH_BLOCK_TX])
7560 params.block_tx = true;
7561
Simon Wunderlichc56589e2013-11-21 18:19:49 +01007562 wdev_lock(wdev);
7563 err = rdev_channel_switch(rdev, dev, &params);
7564 wdev_unlock(wdev);
7565
7566 return err;
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02007567}
7568
Johannes Berg9720bb32011-06-21 09:45:33 +02007569static int nl80211_send_bss(struct sk_buff *msg, struct netlink_callback *cb,
7570 u32 seq, int flags,
Johannes Berg2a519312009-02-10 21:25:55 +01007571 struct cfg80211_registered_device *rdev,
Johannes Berg48ab9052009-07-10 18:42:31 +02007572 struct wireless_dev *wdev,
7573 struct cfg80211_internal_bss *intbss)
Johannes Berg2a519312009-02-10 21:25:55 +01007574{
Johannes Berg48ab9052009-07-10 18:42:31 +02007575 struct cfg80211_bss *res = &intbss->pub;
Johannes Berg9caf0362012-11-29 01:25:20 +01007576 const struct cfg80211_bss_ies *ies;
Johannes Berg2a519312009-02-10 21:25:55 +01007577 void *hdr;
7578 struct nlattr *bss;
Johannes Berg48ab9052009-07-10 18:42:31 +02007579
7580 ASSERT_WDEV_LOCK(wdev);
Johannes Berg2a519312009-02-10 21:25:55 +01007581
Eric W. Biederman15e47302012-09-07 20:12:54 +00007582 hdr = nl80211hdr_put(msg, NETLINK_CB(cb->skb).portid, seq, flags,
Johannes Berg2a519312009-02-10 21:25:55 +01007583 NL80211_CMD_NEW_SCAN_RESULTS);
7584 if (!hdr)
7585 return -1;
7586
Johannes Berg9720bb32011-06-21 09:45:33 +02007587 genl_dump_check_consistent(cb, hdr, &nl80211_fam);
7588
Johannes Berg97990a02013-04-19 01:02:55 +02007589 if (nla_put_u32(msg, NL80211_ATTR_GENERATION, rdev->bss_generation))
7590 goto nla_put_failure;
7591 if (wdev->netdev &&
David S. Miller9360ffd2012-03-29 04:41:26 -04007592 nla_put_u32(msg, NL80211_ATTR_IFINDEX, wdev->netdev->ifindex))
7593 goto nla_put_failure;
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02007594 if (nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
7595 NL80211_ATTR_PAD))
Johannes Berg97990a02013-04-19 01:02:55 +02007596 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01007597
7598 bss = nla_nest_start(msg, NL80211_ATTR_BSS);
7599 if (!bss)
7600 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04007601 if ((!is_zero_ether_addr(res->bssid) &&
Johannes Berg9caf0362012-11-29 01:25:20 +01007602 nla_put(msg, NL80211_BSS_BSSID, ETH_ALEN, res->bssid)))
David S. Miller9360ffd2012-03-29 04:41:26 -04007603 goto nla_put_failure;
Johannes Berg9caf0362012-11-29 01:25:20 +01007604
7605 rcu_read_lock();
Johannes Berg0e227082014-08-12 20:34:30 +02007606 /* indicate whether we have probe response data or not */
7607 if (rcu_access_pointer(res->proberesp_ies) &&
7608 nla_put_flag(msg, NL80211_BSS_PRESP_DATA))
7609 goto fail_unlock_rcu;
7610
7611 /* this pointer prefers to be pointed to probe response data
7612 * but is always valid
7613 */
Johannes Berg9caf0362012-11-29 01:25:20 +01007614 ies = rcu_dereference(res->ies);
Johannes Berg8cef2c92013-02-05 16:54:31 +01007615 if (ies) {
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02007616 if (nla_put_u64_64bit(msg, NL80211_BSS_TSF, ies->tsf,
7617 NL80211_BSS_PAD))
Johannes Berg8cef2c92013-02-05 16:54:31 +01007618 goto fail_unlock_rcu;
Johannes Berg8cef2c92013-02-05 16:54:31 +01007619 if (ies->len && nla_put(msg, NL80211_BSS_INFORMATION_ELEMENTS,
7620 ies->len, ies->data))
7621 goto fail_unlock_rcu;
Johannes Berg9caf0362012-11-29 01:25:20 +01007622 }
Johannes Berg0e227082014-08-12 20:34:30 +02007623
7624 /* and this pointer is always (unless driver didn't know) beacon data */
Johannes Berg9caf0362012-11-29 01:25:20 +01007625 ies = rcu_dereference(res->beacon_ies);
Johannes Berg0e227082014-08-12 20:34:30 +02007626 if (ies && ies->from_beacon) {
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02007627 if (nla_put_u64_64bit(msg, NL80211_BSS_BEACON_TSF, ies->tsf,
7628 NL80211_BSS_PAD))
Johannes Berg8cef2c92013-02-05 16:54:31 +01007629 goto fail_unlock_rcu;
7630 if (ies->len && nla_put(msg, NL80211_BSS_BEACON_IES,
7631 ies->len, ies->data))
7632 goto fail_unlock_rcu;
Johannes Berg9caf0362012-11-29 01:25:20 +01007633 }
7634 rcu_read_unlock();
7635
David S. Miller9360ffd2012-03-29 04:41:26 -04007636 if (res->beacon_interval &&
7637 nla_put_u16(msg, NL80211_BSS_BEACON_INTERVAL, res->beacon_interval))
7638 goto nla_put_failure;
7639 if (nla_put_u16(msg, NL80211_BSS_CAPABILITY, res->capability) ||
7640 nla_put_u32(msg, NL80211_BSS_FREQUENCY, res->channel->center_freq) ||
Simon Wunderlichdcd6eac2013-07-08 16:55:49 +02007641 nla_put_u32(msg, NL80211_BSS_CHAN_WIDTH, res->scan_width) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04007642 nla_put_u32(msg, NL80211_BSS_SEEN_MS_AGO,
7643 jiffies_to_msecs(jiffies - intbss->ts)))
7644 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01007645
Avraham Stern1d762502016-07-05 17:10:13 +03007646 if (intbss->parent_tsf &&
7647 (nla_put_u64_64bit(msg, NL80211_BSS_PARENT_TSF,
7648 intbss->parent_tsf, NL80211_BSS_PAD) ||
7649 nla_put(msg, NL80211_BSS_PARENT_BSSID, ETH_ALEN,
7650 intbss->parent_bssid)))
7651 goto nla_put_failure;
7652
Dmitry Shmidt6e19bc42015-10-07 11:32:53 +02007653 if (intbss->ts_boottime &&
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02007654 nla_put_u64_64bit(msg, NL80211_BSS_LAST_SEEN_BOOTTIME,
7655 intbss->ts_boottime, NL80211_BSS_PAD))
Dmitry Shmidt6e19bc42015-10-07 11:32:53 +02007656 goto nla_put_failure;
7657
Johannes Berg77965c92009-02-18 18:45:06 +01007658 switch (rdev->wiphy.signal_type) {
Johannes Berg2a519312009-02-10 21:25:55 +01007659 case CFG80211_SIGNAL_TYPE_MBM:
David S. Miller9360ffd2012-03-29 04:41:26 -04007660 if (nla_put_u32(msg, NL80211_BSS_SIGNAL_MBM, res->signal))
7661 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01007662 break;
7663 case CFG80211_SIGNAL_TYPE_UNSPEC:
David S. Miller9360ffd2012-03-29 04:41:26 -04007664 if (nla_put_u8(msg, NL80211_BSS_SIGNAL_UNSPEC, res->signal))
7665 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01007666 break;
7667 default:
7668 break;
7669 }
7670
Johannes Berg48ab9052009-07-10 18:42:31 +02007671 switch (wdev->iftype) {
Johannes Berg074ac8d2010-09-16 14:58:22 +02007672 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Berg48ab9052009-07-10 18:42:31 +02007673 case NL80211_IFTYPE_STATION:
David S. Miller9360ffd2012-03-29 04:41:26 -04007674 if (intbss == wdev->current_bss &&
7675 nla_put_u32(msg, NL80211_BSS_STATUS,
7676 NL80211_BSS_STATUS_ASSOCIATED))
7677 goto nla_put_failure;
Johannes Berg48ab9052009-07-10 18:42:31 +02007678 break;
7679 case NL80211_IFTYPE_ADHOC:
David S. Miller9360ffd2012-03-29 04:41:26 -04007680 if (intbss == wdev->current_bss &&
7681 nla_put_u32(msg, NL80211_BSS_STATUS,
7682 NL80211_BSS_STATUS_IBSS_JOINED))
7683 goto nla_put_failure;
Johannes Berg48ab9052009-07-10 18:42:31 +02007684 break;
7685 default:
7686 break;
7687 }
7688
Johannes Berg2a519312009-02-10 21:25:55 +01007689 nla_nest_end(msg, bss);
7690
Johannes Berg053c0952015-01-16 22:09:00 +01007691 genlmsg_end(msg, hdr);
7692 return 0;
Johannes Berg2a519312009-02-10 21:25:55 +01007693
Johannes Berg8cef2c92013-02-05 16:54:31 +01007694 fail_unlock_rcu:
7695 rcu_read_unlock();
Johannes Berg2a519312009-02-10 21:25:55 +01007696 nla_put_failure:
7697 genlmsg_cancel(msg, hdr);
7698 return -EMSGSIZE;
7699}
7700
Johannes Berg97990a02013-04-19 01:02:55 +02007701static int nl80211_dump_scan(struct sk_buff *skb, struct netlink_callback *cb)
Johannes Berg2a519312009-02-10 21:25:55 +01007702{
Johannes Berg48ab9052009-07-10 18:42:31 +02007703 struct cfg80211_registered_device *rdev;
Johannes Berg2a519312009-02-10 21:25:55 +01007704 struct cfg80211_internal_bss *scan;
Johannes Berg48ab9052009-07-10 18:42:31 +02007705 struct wireless_dev *wdev;
Johannes Berg97990a02013-04-19 01:02:55 +02007706 int start = cb->args[2], idx = 0;
Johannes Berg2a519312009-02-10 21:25:55 +01007707 int err;
7708
Johannes Berg97990a02013-04-19 01:02:55 +02007709 err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev);
Johannes Berg67748892010-10-04 21:14:06 +02007710 if (err)
7711 return err;
Johannes Berg2a519312009-02-10 21:25:55 +01007712
Johannes Berg48ab9052009-07-10 18:42:31 +02007713 wdev_lock(wdev);
7714 spin_lock_bh(&rdev->bss_lock);
7715 cfg80211_bss_expire(rdev);
7716
Johannes Berg9720bb32011-06-21 09:45:33 +02007717 cb->seq = rdev->bss_generation;
7718
Johannes Berg48ab9052009-07-10 18:42:31 +02007719 list_for_each_entry(scan, &rdev->bss_list, list) {
Johannes Berg2a519312009-02-10 21:25:55 +01007720 if (++idx <= start)
7721 continue;
Johannes Berg9720bb32011-06-21 09:45:33 +02007722 if (nl80211_send_bss(skb, cb,
Johannes Berg2a519312009-02-10 21:25:55 +01007723 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Johannes Berg48ab9052009-07-10 18:42:31 +02007724 rdev, wdev, scan) < 0) {
Johannes Berg2a519312009-02-10 21:25:55 +01007725 idx--;
Johannes Berg67748892010-10-04 21:14:06 +02007726 break;
Johannes Berg2a519312009-02-10 21:25:55 +01007727 }
7728 }
7729
Johannes Berg48ab9052009-07-10 18:42:31 +02007730 spin_unlock_bh(&rdev->bss_lock);
7731 wdev_unlock(wdev);
Johannes Berg2a519312009-02-10 21:25:55 +01007732
Johannes Berg97990a02013-04-19 01:02:55 +02007733 cb->args[2] = idx;
7734 nl80211_finish_wdev_dump(rdev);
Johannes Berg2a519312009-02-10 21:25:55 +01007735
Johannes Berg67748892010-10-04 21:14:06 +02007736 return skb->len;
Johannes Berg2a519312009-02-10 21:25:55 +01007737}
7738
Eric W. Biederman15e47302012-09-07 20:12:54 +00007739static int nl80211_send_survey(struct sk_buff *msg, u32 portid, u32 seq,
Johannes Berg11f78ac2014-11-14 16:43:50 +01007740 int flags, struct net_device *dev,
7741 bool allow_radio_stats,
7742 struct survey_info *survey)
Holger Schurig61fa7132009-11-11 12:25:40 +01007743{
7744 void *hdr;
7745 struct nlattr *infoattr;
7746
Johannes Berg11f78ac2014-11-14 16:43:50 +01007747 /* skip radio stats if userspace didn't request them */
7748 if (!survey->channel && !allow_radio_stats)
7749 return 0;
7750
Eric W. Biederman15e47302012-09-07 20:12:54 +00007751 hdr = nl80211hdr_put(msg, portid, seq, flags,
Holger Schurig61fa7132009-11-11 12:25:40 +01007752 NL80211_CMD_NEW_SURVEY_RESULTS);
7753 if (!hdr)
7754 return -ENOMEM;
7755
David S. Miller9360ffd2012-03-29 04:41:26 -04007756 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex))
7757 goto nla_put_failure;
Holger Schurig61fa7132009-11-11 12:25:40 +01007758
7759 infoattr = nla_nest_start(msg, NL80211_ATTR_SURVEY_INFO);
7760 if (!infoattr)
7761 goto nla_put_failure;
7762
Johannes Berg11f78ac2014-11-14 16:43:50 +01007763 if (survey->channel &&
7764 nla_put_u32(msg, NL80211_SURVEY_INFO_FREQUENCY,
David S. Miller9360ffd2012-03-29 04:41:26 -04007765 survey->channel->center_freq))
7766 goto nla_put_failure;
7767
7768 if ((survey->filled & SURVEY_INFO_NOISE_DBM) &&
7769 nla_put_u8(msg, NL80211_SURVEY_INFO_NOISE, survey->noise))
7770 goto nla_put_failure;
7771 if ((survey->filled & SURVEY_INFO_IN_USE) &&
7772 nla_put_flag(msg, NL80211_SURVEY_INFO_IN_USE))
7773 goto nla_put_failure;
Johannes Berg4ed20be2014-11-14 16:35:34 +01007774 if ((survey->filled & SURVEY_INFO_TIME) &&
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02007775 nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME,
7776 survey->time, NL80211_SURVEY_INFO_PAD))
David S. Miller9360ffd2012-03-29 04:41:26 -04007777 goto nla_put_failure;
Johannes Berg4ed20be2014-11-14 16:35:34 +01007778 if ((survey->filled & SURVEY_INFO_TIME_BUSY) &&
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02007779 nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME_BUSY,
7780 survey->time_busy, NL80211_SURVEY_INFO_PAD))
David S. Miller9360ffd2012-03-29 04:41:26 -04007781 goto nla_put_failure;
Johannes Berg4ed20be2014-11-14 16:35:34 +01007782 if ((survey->filled & SURVEY_INFO_TIME_EXT_BUSY) &&
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02007783 nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME_EXT_BUSY,
7784 survey->time_ext_busy, NL80211_SURVEY_INFO_PAD))
David S. Miller9360ffd2012-03-29 04:41:26 -04007785 goto nla_put_failure;
Johannes Berg4ed20be2014-11-14 16:35:34 +01007786 if ((survey->filled & SURVEY_INFO_TIME_RX) &&
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02007787 nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME_RX,
7788 survey->time_rx, NL80211_SURVEY_INFO_PAD))
David S. Miller9360ffd2012-03-29 04:41:26 -04007789 goto nla_put_failure;
Johannes Berg4ed20be2014-11-14 16:35:34 +01007790 if ((survey->filled & SURVEY_INFO_TIME_TX) &&
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02007791 nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME_TX,
7792 survey->time_tx, NL80211_SURVEY_INFO_PAD))
David S. Miller9360ffd2012-03-29 04:41:26 -04007793 goto nla_put_failure;
Johannes Berg052536a2014-11-14 16:44:11 +01007794 if ((survey->filled & SURVEY_INFO_TIME_SCAN) &&
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02007795 nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME_SCAN,
7796 survey->time_scan, NL80211_SURVEY_INFO_PAD))
Johannes Berg052536a2014-11-14 16:44:11 +01007797 goto nla_put_failure;
Holger Schurig61fa7132009-11-11 12:25:40 +01007798
7799 nla_nest_end(msg, infoattr);
7800
Johannes Berg053c0952015-01-16 22:09:00 +01007801 genlmsg_end(msg, hdr);
7802 return 0;
Holger Schurig61fa7132009-11-11 12:25:40 +01007803
7804 nla_put_failure:
7805 genlmsg_cancel(msg, hdr);
7806 return -EMSGSIZE;
7807}
7808
Johannes Berg11f78ac2014-11-14 16:43:50 +01007809static int nl80211_dump_survey(struct sk_buff *skb, struct netlink_callback *cb)
Holger Schurig61fa7132009-11-11 12:25:40 +01007810{
Johannes Bergc90c39d2016-10-24 14:40:01 +02007811 struct nlattr **attrbuf = genl_family_attrbuf(&nl80211_fam);
Holger Schurig61fa7132009-11-11 12:25:40 +01007812 struct survey_info survey;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08007813 struct cfg80211_registered_device *rdev;
Johannes Berg97990a02013-04-19 01:02:55 +02007814 struct wireless_dev *wdev;
7815 int survey_idx = cb->args[2];
Holger Schurig61fa7132009-11-11 12:25:40 +01007816 int res;
Johannes Berg11f78ac2014-11-14 16:43:50 +01007817 bool radio_stats;
Holger Schurig61fa7132009-11-11 12:25:40 +01007818
Zhao, Gang1b8ec872014-04-21 12:53:02 +08007819 res = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev);
Johannes Berg67748892010-10-04 21:14:06 +02007820 if (res)
7821 return res;
Holger Schurig61fa7132009-11-11 12:25:40 +01007822
Johannes Berg11f78ac2014-11-14 16:43:50 +01007823 /* prepare_wdev_dump parsed the attributes */
Johannes Bergc90c39d2016-10-24 14:40:01 +02007824 radio_stats = attrbuf[NL80211_ATTR_SURVEY_RADIO_STATS];
Johannes Berg11f78ac2014-11-14 16:43:50 +01007825
Johannes Berg97990a02013-04-19 01:02:55 +02007826 if (!wdev->netdev) {
7827 res = -EINVAL;
7828 goto out_err;
7829 }
7830
Zhao, Gang1b8ec872014-04-21 12:53:02 +08007831 if (!rdev->ops->dump_survey) {
Holger Schurig61fa7132009-11-11 12:25:40 +01007832 res = -EOPNOTSUPP;
7833 goto out_err;
7834 }
7835
7836 while (1) {
Zhao, Gang1b8ec872014-04-21 12:53:02 +08007837 res = rdev_dump_survey(rdev, wdev->netdev, survey_idx, &survey);
Holger Schurig61fa7132009-11-11 12:25:40 +01007838 if (res == -ENOENT)
7839 break;
7840 if (res)
7841 goto out_err;
7842
Johannes Berg11f78ac2014-11-14 16:43:50 +01007843 /* don't send disabled channels, but do send non-channel data */
7844 if (survey.channel &&
7845 survey.channel->flags & IEEE80211_CHAN_DISABLED) {
Luis R. Rodriguez180cdc72011-05-27 07:24:02 -07007846 survey_idx++;
7847 continue;
7848 }
7849
Holger Schurig61fa7132009-11-11 12:25:40 +01007850 if (nl80211_send_survey(skb,
Eric W. Biederman15e47302012-09-07 20:12:54 +00007851 NETLINK_CB(cb->skb).portid,
Holger Schurig61fa7132009-11-11 12:25:40 +01007852 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Johannes Berg11f78ac2014-11-14 16:43:50 +01007853 wdev->netdev, radio_stats, &survey) < 0)
Holger Schurig61fa7132009-11-11 12:25:40 +01007854 goto out;
7855 survey_idx++;
7856 }
7857
7858 out:
Johannes Berg97990a02013-04-19 01:02:55 +02007859 cb->args[2] = survey_idx;
Holger Schurig61fa7132009-11-11 12:25:40 +01007860 res = skb->len;
7861 out_err:
Zhao, Gang1b8ec872014-04-21 12:53:02 +08007862 nl80211_finish_wdev_dump(rdev);
Holger Schurig61fa7132009-11-11 12:25:40 +01007863 return res;
7864}
7865
Samuel Ortizb23aa672009-07-01 21:26:54 +02007866static bool nl80211_valid_wpa_versions(u32 wpa_versions)
7867{
7868 return !(wpa_versions & ~(NL80211_WPA_VERSION_1 |
7869 NL80211_WPA_VERSION_2));
7870}
7871
Jouni Malinen636a5d32009-03-19 13:39:22 +02007872static int nl80211_authenticate(struct sk_buff *skb, struct genl_info *info)
7873{
Johannes Berg4c476992010-10-04 21:36:35 +02007874 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7875 struct net_device *dev = info->user_ptr[1];
Johannes Berg19957bb2009-07-02 17:20:43 +02007876 struct ieee80211_channel *chan;
Jouni Malinen11b6b5a2016-10-27 00:41:58 +03007877 const u8 *bssid, *ssid, *ie = NULL, *auth_data = NULL;
7878 int err, ssid_len, ie_len = 0, auth_data_len = 0;
Johannes Berg19957bb2009-07-02 17:20:43 +02007879 enum nl80211_auth_type auth_type;
Johannes Bergfffd0932009-07-08 14:22:54 +02007880 struct key_parse key;
Jouni Malinend5cdfac2010-04-04 09:37:19 +03007881 bool local_state_change;
Jouni Malinen636a5d32009-03-19 13:39:22 +02007882
Johannes Bergf4a11bb2009-03-27 12:40:28 +01007883 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
7884 return -EINVAL;
7885
7886 if (!info->attrs[NL80211_ATTR_MAC])
7887 return -EINVAL;
7888
Jouni Malinen17780922009-03-27 20:52:47 +02007889 if (!info->attrs[NL80211_ATTR_AUTH_TYPE])
7890 return -EINVAL;
7891
Johannes Berg19957bb2009-07-02 17:20:43 +02007892 if (!info->attrs[NL80211_ATTR_SSID])
7893 return -EINVAL;
7894
7895 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ])
7896 return -EINVAL;
7897
Johannes Bergfffd0932009-07-08 14:22:54 +02007898 err = nl80211_parse_key(info, &key);
7899 if (err)
7900 return err;
7901
7902 if (key.idx >= 0) {
Johannes Berge31b8212010-10-05 19:39:30 +02007903 if (key.type != -1 && key.type != NL80211_KEYTYPE_GROUP)
7904 return -EINVAL;
Johannes Bergfffd0932009-07-08 14:22:54 +02007905 if (!key.p.key || !key.p.key_len)
7906 return -EINVAL;
7907 if ((key.p.cipher != WLAN_CIPHER_SUITE_WEP40 ||
7908 key.p.key_len != WLAN_KEY_LEN_WEP40) &&
7909 (key.p.cipher != WLAN_CIPHER_SUITE_WEP104 ||
7910 key.p.key_len != WLAN_KEY_LEN_WEP104))
7911 return -EINVAL;
Johannes Bergb6b55552016-09-13 16:25:58 +02007912 if (key.idx > 3)
Johannes Bergfffd0932009-07-08 14:22:54 +02007913 return -EINVAL;
7914 } else {
7915 key.p.key_len = 0;
7916 key.p.key = NULL;
7917 }
7918
Johannes Bergafea0b72010-08-10 09:46:42 +02007919 if (key.idx >= 0) {
7920 int i;
7921 bool ok = false;
Kirtika Ruchandani7a087e72016-05-29 19:51:23 -07007922
Johannes Bergafea0b72010-08-10 09:46:42 +02007923 for (i = 0; i < rdev->wiphy.n_cipher_suites; i++) {
7924 if (key.p.cipher == rdev->wiphy.cipher_suites[i]) {
7925 ok = true;
7926 break;
7927 }
7928 }
Johannes Berg4c476992010-10-04 21:36:35 +02007929 if (!ok)
7930 return -EINVAL;
Johannes Bergafea0b72010-08-10 09:46:42 +02007931 }
7932
Johannes Berg4c476992010-10-04 21:36:35 +02007933 if (!rdev->ops->auth)
7934 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02007935
Johannes Berg074ac8d2010-09-16 14:58:22 +02007936 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02007937 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
7938 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02007939
Johannes Berg19957bb2009-07-02 17:20:43 +02007940 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen664834d2014-01-15 00:01:44 +02007941 chan = nl80211_get_valid_chan(&rdev->wiphy,
7942 info->attrs[NL80211_ATTR_WIPHY_FREQ]);
7943 if (!chan)
Johannes Berg4c476992010-10-04 21:36:35 +02007944 return -EINVAL;
Jouni Malinen636a5d32009-03-19 13:39:22 +02007945
Johannes Berg19957bb2009-07-02 17:20:43 +02007946 ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
7947 ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
7948
7949 if (info->attrs[NL80211_ATTR_IE]) {
7950 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
7951 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
7952 }
7953
7954 auth_type = nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]);
Jouni Malinene39e5b52012-09-30 19:29:39 +03007955 if (!nl80211_valid_auth_type(rdev, auth_type, NL80211_CMD_AUTHENTICATE))
Johannes Berg4c476992010-10-04 21:36:35 +02007956 return -EINVAL;
Johannes Berg19957bb2009-07-02 17:20:43 +02007957
Jouni Malinen63181062016-10-27 00:42:02 +03007958 if ((auth_type == NL80211_AUTHTYPE_SAE ||
7959 auth_type == NL80211_AUTHTYPE_FILS_SK ||
7960 auth_type == NL80211_AUTHTYPE_FILS_SK_PFS ||
7961 auth_type == NL80211_AUTHTYPE_FILS_PK) &&
Jouni Malinen11b6b5a2016-10-27 00:41:58 +03007962 !info->attrs[NL80211_ATTR_AUTH_DATA])
Jouni Malinene39e5b52012-09-30 19:29:39 +03007963 return -EINVAL;
7964
Jouni Malinen11b6b5a2016-10-27 00:41:58 +03007965 if (info->attrs[NL80211_ATTR_AUTH_DATA]) {
Jouni Malinen63181062016-10-27 00:42:02 +03007966 if (auth_type != NL80211_AUTHTYPE_SAE &&
7967 auth_type != NL80211_AUTHTYPE_FILS_SK &&
7968 auth_type != NL80211_AUTHTYPE_FILS_SK_PFS &&
7969 auth_type != NL80211_AUTHTYPE_FILS_PK)
Jouni Malinene39e5b52012-09-30 19:29:39 +03007970 return -EINVAL;
Jouni Malinen11b6b5a2016-10-27 00:41:58 +03007971 auth_data = nla_data(info->attrs[NL80211_ATTR_AUTH_DATA]);
7972 auth_data_len = nla_len(info->attrs[NL80211_ATTR_AUTH_DATA]);
Jouni Malinene39e5b52012-09-30 19:29:39 +03007973 /* need to include at least Auth Transaction and Status Code */
Jouni Malinen11b6b5a2016-10-27 00:41:58 +03007974 if (auth_data_len < 4)
Jouni Malinene39e5b52012-09-30 19:29:39 +03007975 return -EINVAL;
7976 }
7977
Jouni Malinend5cdfac2010-04-04 09:37:19 +03007978 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE];
7979
Johannes Berg95de8172012-01-20 13:55:25 +01007980 /*
7981 * Since we no longer track auth state, ignore
7982 * requests to only change local state.
7983 */
7984 if (local_state_change)
7985 return 0;
7986
Johannes Berg91bf9b22013-05-15 17:44:01 +02007987 wdev_lock(dev->ieee80211_ptr);
7988 err = cfg80211_mlme_auth(rdev, dev, chan, auth_type, bssid,
7989 ssid, ssid_len, ie, ie_len,
7990 key.p.key, key.p.key_len, key.idx,
Jouni Malinen11b6b5a2016-10-27 00:41:58 +03007991 auth_data, auth_data_len);
Johannes Berg91bf9b22013-05-15 17:44:01 +02007992 wdev_unlock(dev->ieee80211_ptr);
7993 return err;
Jouni Malinen636a5d32009-03-19 13:39:22 +02007994}
7995
Johannes Bergc0692b82010-08-27 14:26:53 +03007996static int nl80211_crypto_settings(struct cfg80211_registered_device *rdev,
7997 struct genl_info *info,
Johannes Berg3dc27d22009-07-02 21:36:37 +02007998 struct cfg80211_crypto_settings *settings,
7999 int cipher_limit)
Samuel Ortizb23aa672009-07-01 21:26:54 +02008000{
Johannes Bergc0b2bbd2009-07-25 16:54:36 +02008001 memset(settings, 0, sizeof(*settings));
8002
Samuel Ortizb23aa672009-07-01 21:26:54 +02008003 settings->control_port = info->attrs[NL80211_ATTR_CONTROL_PORT];
8004
Johannes Bergc0692b82010-08-27 14:26:53 +03008005 if (info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]) {
8006 u16 proto;
Kirtika Ruchandani7a087e72016-05-29 19:51:23 -07008007
Johannes Bergc0692b82010-08-27 14:26:53 +03008008 proto = nla_get_u16(
8009 info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]);
8010 settings->control_port_ethertype = cpu_to_be16(proto);
8011 if (!(rdev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) &&
8012 proto != ETH_P_PAE)
8013 return -EINVAL;
8014 if (info->attrs[NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT])
8015 settings->control_port_no_encrypt = true;
8016 } else
8017 settings->control_port_ethertype = cpu_to_be16(ETH_P_PAE);
8018
Samuel Ortizb23aa672009-07-01 21:26:54 +02008019 if (info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]) {
8020 void *data;
8021 int len, i;
8022
8023 data = nla_data(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]);
8024 len = nla_len(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]);
8025 settings->n_ciphers_pairwise = len / sizeof(u32);
8026
8027 if (len % sizeof(u32))
8028 return -EINVAL;
8029
Johannes Berg3dc27d22009-07-02 21:36:37 +02008030 if (settings->n_ciphers_pairwise > cipher_limit)
Samuel Ortizb23aa672009-07-01 21:26:54 +02008031 return -EINVAL;
8032
8033 memcpy(settings->ciphers_pairwise, data, len);
8034
8035 for (i = 0; i < settings->n_ciphers_pairwise; i++)
Jouni Malinen38ba3c52011-09-21 18:14:56 +03008036 if (!cfg80211_supported_cipher_suite(
8037 &rdev->wiphy,
Samuel Ortizb23aa672009-07-01 21:26:54 +02008038 settings->ciphers_pairwise[i]))
8039 return -EINVAL;
8040 }
8041
8042 if (info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]) {
8043 settings->cipher_group =
8044 nla_get_u32(info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]);
Jouni Malinen38ba3c52011-09-21 18:14:56 +03008045 if (!cfg80211_supported_cipher_suite(&rdev->wiphy,
8046 settings->cipher_group))
Samuel Ortizb23aa672009-07-01 21:26:54 +02008047 return -EINVAL;
8048 }
8049
8050 if (info->attrs[NL80211_ATTR_WPA_VERSIONS]) {
8051 settings->wpa_versions =
8052 nla_get_u32(info->attrs[NL80211_ATTR_WPA_VERSIONS]);
8053 if (!nl80211_valid_wpa_versions(settings->wpa_versions))
8054 return -EINVAL;
8055 }
8056
8057 if (info->attrs[NL80211_ATTR_AKM_SUITES]) {
8058 void *data;
Jouni Malinen6d302402011-09-21 18:11:33 +03008059 int len;
Samuel Ortizb23aa672009-07-01 21:26:54 +02008060
8061 data = nla_data(info->attrs[NL80211_ATTR_AKM_SUITES]);
8062 len = nla_len(info->attrs[NL80211_ATTR_AKM_SUITES]);
8063 settings->n_akm_suites = len / sizeof(u32);
8064
8065 if (len % sizeof(u32))
8066 return -EINVAL;
8067
Jouni Malinen1b9ca022011-09-21 16:13:07 +03008068 if (settings->n_akm_suites > NL80211_MAX_NR_AKM_SUITES)
8069 return -EINVAL;
8070
Samuel Ortizb23aa672009-07-01 21:26:54 +02008071 memcpy(settings->akm_suites, data, len);
Samuel Ortizb23aa672009-07-01 21:26:54 +02008072 }
8073
8074 return 0;
8075}
8076
Jouni Malinen636a5d32009-03-19 13:39:22 +02008077static int nl80211_associate(struct sk_buff *skb, struct genl_info *info)
8078{
Johannes Berg4c476992010-10-04 21:36:35 +02008079 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8080 struct net_device *dev = info->user_ptr[1];
Johannes Bergf444de02010-05-05 15:25:02 +02008081 struct ieee80211_channel *chan;
Johannes Bergf62fab72013-02-21 20:09:09 +01008082 struct cfg80211_assoc_request req = {};
8083 const u8 *bssid, *ssid;
8084 int err, ssid_len = 0;
Jouni Malinen636a5d32009-03-19 13:39:22 +02008085
Johannes Bergf4a11bb2009-03-27 12:40:28 +01008086 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
8087 return -EINVAL;
8088
8089 if (!info->attrs[NL80211_ATTR_MAC] ||
Johannes Berg19957bb2009-07-02 17:20:43 +02008090 !info->attrs[NL80211_ATTR_SSID] ||
8091 !info->attrs[NL80211_ATTR_WIPHY_FREQ])
Johannes Bergf4a11bb2009-03-27 12:40:28 +01008092 return -EINVAL;
8093
Johannes Berg4c476992010-10-04 21:36:35 +02008094 if (!rdev->ops->assoc)
8095 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02008096
Johannes Berg074ac8d2010-09-16 14:58:22 +02008097 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02008098 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
8099 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02008100
Johannes Berg19957bb2009-07-02 17:20:43 +02008101 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02008102
Jouni Malinen664834d2014-01-15 00:01:44 +02008103 chan = nl80211_get_valid_chan(&rdev->wiphy,
8104 info->attrs[NL80211_ATTR_WIPHY_FREQ]);
8105 if (!chan)
Johannes Berg4c476992010-10-04 21:36:35 +02008106 return -EINVAL;
Jouni Malinen636a5d32009-03-19 13:39:22 +02008107
Johannes Berg19957bb2009-07-02 17:20:43 +02008108 ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
8109 ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02008110
8111 if (info->attrs[NL80211_ATTR_IE]) {
Johannes Bergf62fab72013-02-21 20:09:09 +01008112 req.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
8113 req.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02008114 }
8115
Jouni Malinendc6382ce2009-05-06 22:09:37 +03008116 if (info->attrs[NL80211_ATTR_USE_MFP]) {
Johannes Berg4f5dadc2009-07-07 03:56:10 +02008117 enum nl80211_mfp mfp =
Jouni Malinendc6382ce2009-05-06 22:09:37 +03008118 nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]);
Johannes Berg4f5dadc2009-07-07 03:56:10 +02008119 if (mfp == NL80211_MFP_REQUIRED)
Johannes Bergf62fab72013-02-21 20:09:09 +01008120 req.use_mfp = true;
Johannes Berg4c476992010-10-04 21:36:35 +02008121 else if (mfp != NL80211_MFP_NO)
8122 return -EINVAL;
Jouni Malinendc6382ce2009-05-06 22:09:37 +03008123 }
8124
Johannes Berg3e5d7642009-07-07 14:37:26 +02008125 if (info->attrs[NL80211_ATTR_PREV_BSSID])
Johannes Bergf62fab72013-02-21 20:09:09 +01008126 req.prev_bssid = nla_data(info->attrs[NL80211_ATTR_PREV_BSSID]);
Johannes Berg3e5d7642009-07-07 14:37:26 +02008127
Ben Greear7e7c8922011-11-18 11:31:59 -08008128 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT]))
Johannes Bergf62fab72013-02-21 20:09:09 +01008129 req.flags |= ASSOC_REQ_DISABLE_HT;
Ben Greear7e7c8922011-11-18 11:31:59 -08008130
8131 if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
Johannes Bergf62fab72013-02-21 20:09:09 +01008132 memcpy(&req.ht_capa_mask,
8133 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]),
8134 sizeof(req.ht_capa_mask));
Ben Greear7e7c8922011-11-18 11:31:59 -08008135
8136 if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) {
Johannes Bergf62fab72013-02-21 20:09:09 +01008137 if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
Ben Greear7e7c8922011-11-18 11:31:59 -08008138 return -EINVAL;
Johannes Bergf62fab72013-02-21 20:09:09 +01008139 memcpy(&req.ht_capa,
8140 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]),
8141 sizeof(req.ht_capa));
Ben Greear7e7c8922011-11-18 11:31:59 -08008142 }
8143
Johannes Bergee2aca32013-02-21 17:36:01 +01008144 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_VHT]))
Johannes Bergf62fab72013-02-21 20:09:09 +01008145 req.flags |= ASSOC_REQ_DISABLE_VHT;
Johannes Bergee2aca32013-02-21 17:36:01 +01008146
8147 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK])
Johannes Bergf62fab72013-02-21 20:09:09 +01008148 memcpy(&req.vht_capa_mask,
8149 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]),
8150 sizeof(req.vht_capa_mask));
Johannes Bergee2aca32013-02-21 17:36:01 +01008151
8152 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) {
Johannes Bergf62fab72013-02-21 20:09:09 +01008153 if (!info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK])
Johannes Bergee2aca32013-02-21 17:36:01 +01008154 return -EINVAL;
Johannes Bergf62fab72013-02-21 20:09:09 +01008155 memcpy(&req.vht_capa,
8156 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]),
8157 sizeof(req.vht_capa));
Johannes Bergee2aca32013-02-21 17:36:01 +01008158 }
8159
Assaf Kraussbab5ab72014-09-03 15:25:01 +03008160 if (nla_get_flag(info->attrs[NL80211_ATTR_USE_RRM])) {
Beni Lev0c9ca112016-02-17 20:30:00 +02008161 if (!((rdev->wiphy.features &
8162 NL80211_FEATURE_DS_PARAM_SET_IE_IN_PROBES) &&
8163 (rdev->wiphy.features & NL80211_FEATURE_QUIET)) &&
8164 !wiphy_ext_feature_isset(&rdev->wiphy,
8165 NL80211_EXT_FEATURE_RRM))
Assaf Kraussbab5ab72014-09-03 15:25:01 +03008166 return -EINVAL;
8167 req.flags |= ASSOC_REQ_USE_RRM;
8168 }
8169
Jouni Malinen348bd452016-10-27 00:42:03 +03008170 if (info->attrs[NL80211_ATTR_FILS_KEK]) {
8171 req.fils_kek = nla_data(info->attrs[NL80211_ATTR_FILS_KEK]);
8172 req.fils_kek_len = nla_len(info->attrs[NL80211_ATTR_FILS_KEK]);
8173 if (!info->attrs[NL80211_ATTR_FILS_NONCES])
8174 return -EINVAL;
8175 req.fils_nonces =
8176 nla_data(info->attrs[NL80211_ATTR_FILS_NONCES]);
8177 }
8178
Johannes Bergf62fab72013-02-21 20:09:09 +01008179 err = nl80211_crypto_settings(rdev, info, &req.crypto, 1);
Johannes Berg91bf9b22013-05-15 17:44:01 +02008180 if (!err) {
8181 wdev_lock(dev->ieee80211_ptr);
Andrzej Zaborowskibd2522b2017-01-06 16:33:43 -05008182
Johannes Bergf62fab72013-02-21 20:09:09 +01008183 err = cfg80211_mlme_assoc(rdev, dev, chan, bssid,
8184 ssid, ssid_len, &req);
Andrzej Zaborowskibd2522b2017-01-06 16:33:43 -05008185
8186 if (!err && info->attrs[NL80211_ATTR_SOCKET_OWNER]) {
8187 dev->ieee80211_ptr->conn_owner_nlportid =
8188 info->snd_portid;
8189 memcpy(dev->ieee80211_ptr->disconnect_bssid,
8190 bssid, ETH_ALEN);
8191 }
8192
Johannes Berg91bf9b22013-05-15 17:44:01 +02008193 wdev_unlock(dev->ieee80211_ptr);
8194 }
Jouni Malinen636a5d32009-03-19 13:39:22 +02008195
Jouni Malinen636a5d32009-03-19 13:39:22 +02008196 return err;
8197}
8198
8199static int nl80211_deauthenticate(struct sk_buff *skb, struct genl_info *info)
8200{
Johannes Berg4c476992010-10-04 21:36:35 +02008201 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8202 struct net_device *dev = info->user_ptr[1];
Johannes Berg19957bb2009-07-02 17:20:43 +02008203 const u8 *ie = NULL, *bssid;
Johannes Berg91bf9b22013-05-15 17:44:01 +02008204 int ie_len = 0, err;
Johannes Berg19957bb2009-07-02 17:20:43 +02008205 u16 reason_code;
Jouni Malinend5cdfac2010-04-04 09:37:19 +03008206 bool local_state_change;
Jouni Malinen636a5d32009-03-19 13:39:22 +02008207
Johannes Bergf4a11bb2009-03-27 12:40:28 +01008208 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
8209 return -EINVAL;
8210
8211 if (!info->attrs[NL80211_ATTR_MAC])
8212 return -EINVAL;
8213
8214 if (!info->attrs[NL80211_ATTR_REASON_CODE])
8215 return -EINVAL;
8216
Johannes Berg4c476992010-10-04 21:36:35 +02008217 if (!rdev->ops->deauth)
8218 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02008219
Johannes Berg074ac8d2010-09-16 14:58:22 +02008220 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02008221 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
8222 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02008223
Johannes Berg19957bb2009-07-02 17:20:43 +02008224 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02008225
Johannes Berg19957bb2009-07-02 17:20:43 +02008226 reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
8227 if (reason_code == 0) {
Johannes Bergf4a11bb2009-03-27 12:40:28 +01008228 /* Reason Code 0 is reserved */
Johannes Berg4c476992010-10-04 21:36:35 +02008229 return -EINVAL;
Jouni Malinen255e7372009-03-20 21:21:17 +02008230 }
Jouni Malinen636a5d32009-03-19 13:39:22 +02008231
8232 if (info->attrs[NL80211_ATTR_IE]) {
Johannes Berg19957bb2009-07-02 17:20:43 +02008233 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
8234 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02008235 }
8236
Jouni Malinend5cdfac2010-04-04 09:37:19 +03008237 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE];
8238
Johannes Berg91bf9b22013-05-15 17:44:01 +02008239 wdev_lock(dev->ieee80211_ptr);
8240 err = cfg80211_mlme_deauth(rdev, dev, bssid, ie, ie_len, reason_code,
8241 local_state_change);
8242 wdev_unlock(dev->ieee80211_ptr);
8243 return err;
Jouni Malinen636a5d32009-03-19 13:39:22 +02008244}
8245
8246static int nl80211_disassociate(struct sk_buff *skb, struct genl_info *info)
8247{
Johannes Berg4c476992010-10-04 21:36:35 +02008248 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8249 struct net_device *dev = info->user_ptr[1];
Johannes Berg19957bb2009-07-02 17:20:43 +02008250 const u8 *ie = NULL, *bssid;
Johannes Berg91bf9b22013-05-15 17:44:01 +02008251 int ie_len = 0, err;
Johannes Berg19957bb2009-07-02 17:20:43 +02008252 u16 reason_code;
Jouni Malinend5cdfac2010-04-04 09:37:19 +03008253 bool local_state_change;
Jouni Malinen636a5d32009-03-19 13:39:22 +02008254
Johannes Bergf4a11bb2009-03-27 12:40:28 +01008255 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
8256 return -EINVAL;
8257
8258 if (!info->attrs[NL80211_ATTR_MAC])
8259 return -EINVAL;
8260
8261 if (!info->attrs[NL80211_ATTR_REASON_CODE])
8262 return -EINVAL;
8263
Johannes Berg4c476992010-10-04 21:36:35 +02008264 if (!rdev->ops->disassoc)
8265 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02008266
Johannes Berg074ac8d2010-09-16 14:58:22 +02008267 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02008268 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
8269 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02008270
Johannes Berg19957bb2009-07-02 17:20:43 +02008271 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02008272
Johannes Berg19957bb2009-07-02 17:20:43 +02008273 reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
8274 if (reason_code == 0) {
Johannes Bergf4a11bb2009-03-27 12:40:28 +01008275 /* Reason Code 0 is reserved */
Johannes Berg4c476992010-10-04 21:36:35 +02008276 return -EINVAL;
Jouni Malinen255e7372009-03-20 21:21:17 +02008277 }
Jouni Malinen636a5d32009-03-19 13:39:22 +02008278
8279 if (info->attrs[NL80211_ATTR_IE]) {
Johannes Berg19957bb2009-07-02 17:20:43 +02008280 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
8281 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02008282 }
8283
Jouni Malinend5cdfac2010-04-04 09:37:19 +03008284 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE];
8285
Johannes Berg91bf9b22013-05-15 17:44:01 +02008286 wdev_lock(dev->ieee80211_ptr);
8287 err = cfg80211_mlme_disassoc(rdev, dev, bssid, ie, ie_len, reason_code,
8288 local_state_change);
8289 wdev_unlock(dev->ieee80211_ptr);
8290 return err;
Jouni Malinen636a5d32009-03-19 13:39:22 +02008291}
8292
Felix Fietkaudd5b4cc2010-11-22 20:58:24 +01008293static bool
8294nl80211_parse_mcast_rate(struct cfg80211_registered_device *rdev,
Johannes Berg57fbcce2016-04-12 15:56:15 +02008295 int mcast_rate[NUM_NL80211_BANDS],
Felix Fietkaudd5b4cc2010-11-22 20:58:24 +01008296 int rateval)
8297{
8298 struct wiphy *wiphy = &rdev->wiphy;
8299 bool found = false;
8300 int band, i;
8301
Johannes Berg57fbcce2016-04-12 15:56:15 +02008302 for (band = 0; band < NUM_NL80211_BANDS; band++) {
Felix Fietkaudd5b4cc2010-11-22 20:58:24 +01008303 struct ieee80211_supported_band *sband;
8304
8305 sband = wiphy->bands[band];
8306 if (!sband)
8307 continue;
8308
8309 for (i = 0; i < sband->n_bitrates; i++) {
8310 if (sband->bitrates[i].bitrate == rateval) {
8311 mcast_rate[band] = i + 1;
8312 found = true;
8313 break;
8314 }
8315 }
8316 }
8317
8318 return found;
8319}
8320
Johannes Berg04a773a2009-04-19 21:24:32 +02008321static int nl80211_join_ibss(struct sk_buff *skb, struct genl_info *info)
8322{
Johannes Berg4c476992010-10-04 21:36:35 +02008323 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8324 struct net_device *dev = info->user_ptr[1];
Johannes Berg04a773a2009-04-19 21:24:32 +02008325 struct cfg80211_ibss_params ibss;
8326 struct wiphy *wiphy;
Johannes Bergfffd0932009-07-08 14:22:54 +02008327 struct cfg80211_cached_keys *connkeys = NULL;
Johannes Berg04a773a2009-04-19 21:24:32 +02008328 int err;
8329
Johannes Berg8e30bc52009-04-22 17:45:38 +02008330 memset(&ibss, 0, sizeof(ibss));
8331
Johannes Berg04a773a2009-04-19 21:24:32 +02008332 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
8333 return -EINVAL;
8334
Johannes Berg683b6d32012-11-08 21:25:48 +01008335 if (!info->attrs[NL80211_ATTR_SSID] ||
Johannes Berg04a773a2009-04-19 21:24:32 +02008336 !nla_len(info->attrs[NL80211_ATTR_SSID]))
8337 return -EINVAL;
8338
Johannes Berg8e30bc52009-04-22 17:45:38 +02008339 ibss.beacon_interval = 100;
8340
Purushottam Kushwaha12d20fc92016-08-11 15:14:02 +05308341 if (info->attrs[NL80211_ATTR_BEACON_INTERVAL])
Johannes Berg8e30bc52009-04-22 17:45:38 +02008342 ibss.beacon_interval =
8343 nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]);
Purushottam Kushwaha12d20fc92016-08-11 15:14:02 +05308344
Purushottam Kushwaha0c317a02016-10-12 18:26:51 +05308345 err = cfg80211_validate_beacon_int(rdev, NL80211_IFTYPE_ADHOC,
8346 ibss.beacon_interval);
Purushottam Kushwaha12d20fc92016-08-11 15:14:02 +05308347 if (err)
8348 return err;
Johannes Berg8e30bc52009-04-22 17:45:38 +02008349
Johannes Berg4c476992010-10-04 21:36:35 +02008350 if (!rdev->ops->join_ibss)
8351 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02008352
Johannes Berg4c476992010-10-04 21:36:35 +02008353 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC)
8354 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02008355
Johannes Berg79c97e92009-07-07 03:56:12 +02008356 wiphy = &rdev->wiphy;
Johannes Berg04a773a2009-04-19 21:24:32 +02008357
Johannes Berg39193492011-09-16 13:45:25 +02008358 if (info->attrs[NL80211_ATTR_MAC]) {
Johannes Berg04a773a2009-04-19 21:24:32 +02008359 ibss.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Johannes Berg39193492011-09-16 13:45:25 +02008360
8361 if (!is_valid_ether_addr(ibss.bssid))
8362 return -EINVAL;
8363 }
Johannes Berg04a773a2009-04-19 21:24:32 +02008364 ibss.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
8365 ibss.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
8366
8367 if (info->attrs[NL80211_ATTR_IE]) {
8368 ibss.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
8369 ibss.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
8370 }
8371
Johannes Berg683b6d32012-11-08 21:25:48 +01008372 err = nl80211_parse_chandef(rdev, info, &ibss.chandef);
8373 if (err)
8374 return err;
Alexander Simon54858ee5b2011-11-30 16:56:32 +01008375
Ilan Peer174e0cd2014-02-23 09:13:01 +02008376 if (!cfg80211_reg_can_beacon(&rdev->wiphy, &ibss.chandef,
8377 NL80211_IFTYPE_ADHOC))
Alexander Simon54858ee5b2011-11-30 16:56:32 +01008378 return -EINVAL;
8379
Simon Wunderlich2f301ab2013-05-16 13:00:28 +02008380 switch (ibss.chandef.width) {
Simon Wunderlichbf372642013-07-08 16:55:58 +02008381 case NL80211_CHAN_WIDTH_5:
8382 case NL80211_CHAN_WIDTH_10:
Simon Wunderlich2f301ab2013-05-16 13:00:28 +02008383 case NL80211_CHAN_WIDTH_20_NOHT:
8384 break;
8385 case NL80211_CHAN_WIDTH_20:
8386 case NL80211_CHAN_WIDTH_40:
Janusz.Dziedzic@tieto.comffc11992015-02-21 16:52:39 +01008387 if (!(rdev->wiphy.features & NL80211_FEATURE_HT_IBSS))
8388 return -EINVAL;
8389 break;
8390 case NL80211_CHAN_WIDTH_80:
8391 case NL80211_CHAN_WIDTH_80P80:
8392 case NL80211_CHAN_WIDTH_160:
8393 if (!(rdev->wiphy.features & NL80211_FEATURE_HT_IBSS))
8394 return -EINVAL;
8395 if (!wiphy_ext_feature_isset(&rdev->wiphy,
8396 NL80211_EXT_FEATURE_VHT_IBSS))
8397 return -EINVAL;
8398 break;
Simon Wunderlich2f301ab2013-05-16 13:00:28 +02008399 default:
Johannes Bergdb9c64c2012-11-09 14:56:41 +01008400 return -EINVAL;
Simon Wunderlich2f301ab2013-05-16 13:00:28 +02008401 }
Johannes Bergdb9c64c2012-11-09 14:56:41 +01008402
Johannes Berg04a773a2009-04-19 21:24:32 +02008403 ibss.channel_fixed = !!info->attrs[NL80211_ATTR_FREQ_FIXED];
Johannes Bergfffd0932009-07-08 14:22:54 +02008404 ibss.privacy = !!info->attrs[NL80211_ATTR_PRIVACY];
Johannes Berg04a773a2009-04-19 21:24:32 +02008405
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03008406 if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) {
8407 u8 *rates =
8408 nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
8409 int n_rates =
8410 nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
8411 struct ieee80211_supported_band *sband =
Johannes Berg683b6d32012-11-08 21:25:48 +01008412 wiphy->bands[ibss.chandef.chan->band];
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03008413
Johannes Berg34850ab2011-07-18 18:08:35 +02008414 err = ieee80211_get_ratemask(sband, rates, n_rates,
8415 &ibss.basic_rates);
8416 if (err)
8417 return err;
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03008418 }
Felix Fietkaudd5b4cc2010-11-22 20:58:24 +01008419
Simon Wunderlich803768f2013-06-28 10:39:58 +02008420 if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
8421 memcpy(&ibss.ht_capa_mask,
8422 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]),
8423 sizeof(ibss.ht_capa_mask));
8424
8425 if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) {
8426 if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
8427 return -EINVAL;
8428 memcpy(&ibss.ht_capa,
8429 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]),
8430 sizeof(ibss.ht_capa));
8431 }
8432
Felix Fietkaudd5b4cc2010-11-22 20:58:24 +01008433 if (info->attrs[NL80211_ATTR_MCAST_RATE] &&
8434 !nl80211_parse_mcast_rate(rdev, ibss.mcast_rate,
8435 nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE])))
8436 return -EINVAL;
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03008437
Johannes Berg4c476992010-10-04 21:36:35 +02008438 if (ibss.privacy && info->attrs[NL80211_ATTR_KEYS]) {
Sujith Manoharande7044e2012-10-18 10:19:28 +05308439 bool no_ht = false;
8440
Johannes Berg4c476992010-10-04 21:36:35 +02008441 connkeys = nl80211_parse_connkeys(rdev,
Sujith Manoharande7044e2012-10-18 10:19:28 +05308442 info->attrs[NL80211_ATTR_KEYS],
8443 &no_ht);
Johannes Berg4c476992010-10-04 21:36:35 +02008444 if (IS_ERR(connkeys))
8445 return PTR_ERR(connkeys);
Sujith Manoharande7044e2012-10-18 10:19:28 +05308446
Johannes Berg3d9d1d62012-11-08 23:14:50 +01008447 if ((ibss.chandef.width != NL80211_CHAN_WIDTH_20_NOHT) &&
8448 no_ht) {
Ola Olsson5e950a72016-02-11 01:00:22 +01008449 kzfree(connkeys);
Sujith Manoharande7044e2012-10-18 10:19:28 +05308450 return -EINVAL;
8451 }
Johannes Berg4c476992010-10-04 21:36:35 +02008452 }
Johannes Berg04a773a2009-04-19 21:24:32 +02008453
Antonio Quartulli267335d2012-01-31 20:25:47 +01008454 ibss.control_port =
8455 nla_get_flag(info->attrs[NL80211_ATTR_CONTROL_PORT]);
8456
Simon Wunderlich5336fa82013-10-07 18:41:05 +02008457 ibss.userspace_handles_dfs =
8458 nla_get_flag(info->attrs[NL80211_ATTR_HANDLE_DFS]);
8459
Johannes Berg4c476992010-10-04 21:36:35 +02008460 err = cfg80211_join_ibss(rdev, dev, &ibss, connkeys);
Johannes Bergfffd0932009-07-08 14:22:54 +02008461 if (err)
Johannes Bergb47f6102014-09-10 13:39:54 +03008462 kzfree(connkeys);
Johannes Berg04a773a2009-04-19 21:24:32 +02008463 return err;
8464}
8465
8466static int nl80211_leave_ibss(struct sk_buff *skb, struct genl_info *info)
8467{
Johannes Berg4c476992010-10-04 21:36:35 +02008468 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8469 struct net_device *dev = info->user_ptr[1];
Johannes Berg04a773a2009-04-19 21:24:32 +02008470
Johannes Berg4c476992010-10-04 21:36:35 +02008471 if (!rdev->ops->leave_ibss)
8472 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02008473
Johannes Berg4c476992010-10-04 21:36:35 +02008474 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC)
8475 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02008476
Johannes Berg4c476992010-10-04 21:36:35 +02008477 return cfg80211_leave_ibss(rdev, dev, false);
Johannes Berg04a773a2009-04-19 21:24:32 +02008478}
8479
Antonio Quartullif4e583c2012-11-02 13:27:48 +01008480static int nl80211_set_mcast_rate(struct sk_buff *skb, struct genl_info *info)
8481{
8482 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8483 struct net_device *dev = info->user_ptr[1];
Johannes Berg57fbcce2016-04-12 15:56:15 +02008484 int mcast_rate[NUM_NL80211_BANDS];
Antonio Quartullif4e583c2012-11-02 13:27:48 +01008485 u32 nla_rate;
8486 int err;
8487
8488 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC &&
Bertold Van den Bergh876dc932015-08-05 16:02:21 +02008489 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT &&
8490 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_OCB)
Antonio Quartullif4e583c2012-11-02 13:27:48 +01008491 return -EOPNOTSUPP;
8492
8493 if (!rdev->ops->set_mcast_rate)
8494 return -EOPNOTSUPP;
8495
8496 memset(mcast_rate, 0, sizeof(mcast_rate));
8497
8498 if (!info->attrs[NL80211_ATTR_MCAST_RATE])
8499 return -EINVAL;
8500
8501 nla_rate = nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]);
8502 if (!nl80211_parse_mcast_rate(rdev, mcast_rate, nla_rate))
8503 return -EINVAL;
8504
Ilan Peera1056b1b2015-10-22 22:27:46 +03008505 err = rdev_set_mcast_rate(rdev, dev, mcast_rate);
Antonio Quartullif4e583c2012-11-02 13:27:48 +01008506
8507 return err;
8508}
8509
Johannes Bergad7e7182013-11-13 13:37:47 +01008510static struct sk_buff *
8511__cfg80211_alloc_vendor_skb(struct cfg80211_registered_device *rdev,
Ahmad Kholaif6c09e792015-02-26 15:26:53 +02008512 struct wireless_dev *wdev, int approxlen,
8513 u32 portid, u32 seq, enum nl80211_commands cmd,
Johannes Berg567ffc32013-12-18 14:43:31 +01008514 enum nl80211_attrs attr,
8515 const struct nl80211_vendor_cmd_info *info,
8516 gfp_t gfp)
Johannes Bergad7e7182013-11-13 13:37:47 +01008517{
8518 struct sk_buff *skb;
8519 void *hdr;
8520 struct nlattr *data;
8521
8522 skb = nlmsg_new(approxlen + 100, gfp);
8523 if (!skb)
8524 return NULL;
8525
8526 hdr = nl80211hdr_put(skb, portid, seq, 0, cmd);
8527 if (!hdr) {
8528 kfree_skb(skb);
8529 return NULL;
8530 }
8531
8532 if (nla_put_u32(skb, NL80211_ATTR_WIPHY, rdev->wiphy_idx))
8533 goto nla_put_failure;
Johannes Berg567ffc32013-12-18 14:43:31 +01008534
8535 if (info) {
8536 if (nla_put_u32(skb, NL80211_ATTR_VENDOR_ID,
8537 info->vendor_id))
8538 goto nla_put_failure;
8539 if (nla_put_u32(skb, NL80211_ATTR_VENDOR_SUBCMD,
8540 info->subcmd))
8541 goto nla_put_failure;
8542 }
8543
Ahmad Kholaif6c09e792015-02-26 15:26:53 +02008544 if (wdev) {
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02008545 if (nla_put_u64_64bit(skb, NL80211_ATTR_WDEV,
8546 wdev_id(wdev), NL80211_ATTR_PAD))
Ahmad Kholaif6c09e792015-02-26 15:26:53 +02008547 goto nla_put_failure;
8548 if (wdev->netdev &&
8549 nla_put_u32(skb, NL80211_ATTR_IFINDEX,
8550 wdev->netdev->ifindex))
8551 goto nla_put_failure;
8552 }
8553
Johannes Bergad7e7182013-11-13 13:37:47 +01008554 data = nla_nest_start(skb, attr);
Johannes Berg76e1fb42016-09-14 09:55:57 +02008555 if (!data)
8556 goto nla_put_failure;
Johannes Bergad7e7182013-11-13 13:37:47 +01008557
8558 ((void **)skb->cb)[0] = rdev;
8559 ((void **)skb->cb)[1] = hdr;
8560 ((void **)skb->cb)[2] = data;
8561
8562 return skb;
8563
8564 nla_put_failure:
8565 kfree_skb(skb);
8566 return NULL;
8567}
Antonio Quartullif4e583c2012-11-02 13:27:48 +01008568
Johannes Berge03ad6e2014-01-01 17:22:30 +01008569struct sk_buff *__cfg80211_alloc_event_skb(struct wiphy *wiphy,
Ahmad Kholaif6c09e792015-02-26 15:26:53 +02008570 struct wireless_dev *wdev,
Johannes Berge03ad6e2014-01-01 17:22:30 +01008571 enum nl80211_commands cmd,
8572 enum nl80211_attrs attr,
8573 int vendor_event_idx,
8574 int approxlen, gfp_t gfp)
8575{
Zhao, Gangf26cbf42014-04-21 12:53:03 +08008576 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berge03ad6e2014-01-01 17:22:30 +01008577 const struct nl80211_vendor_cmd_info *info;
8578
8579 switch (cmd) {
8580 case NL80211_CMD_TESTMODE:
8581 if (WARN_ON(vendor_event_idx != -1))
8582 return NULL;
8583 info = NULL;
8584 break;
8585 case NL80211_CMD_VENDOR:
8586 if (WARN_ON(vendor_event_idx < 0 ||
8587 vendor_event_idx >= wiphy->n_vendor_events))
8588 return NULL;
8589 info = &wiphy->vendor_events[vendor_event_idx];
8590 break;
8591 default:
8592 WARN_ON(1);
8593 return NULL;
8594 }
8595
Ahmad Kholaif6c09e792015-02-26 15:26:53 +02008596 return __cfg80211_alloc_vendor_skb(rdev, wdev, approxlen, 0, 0,
Johannes Berge03ad6e2014-01-01 17:22:30 +01008597 cmd, attr, info, gfp);
8598}
8599EXPORT_SYMBOL(__cfg80211_alloc_event_skb);
8600
8601void __cfg80211_send_event_skb(struct sk_buff *skb, gfp_t gfp)
8602{
8603 struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0];
8604 void *hdr = ((void **)skb->cb)[1];
8605 struct nlattr *data = ((void **)skb->cb)[2];
8606 enum nl80211_multicast_groups mcgrp = NL80211_MCGRP_TESTMODE;
8607
Johannes Bergbd8c78e2014-07-30 14:55:26 +02008608 /* clear CB data for netlink core to own from now on */
8609 memset(skb->cb, 0, sizeof(skb->cb));
8610
Johannes Berge03ad6e2014-01-01 17:22:30 +01008611 nla_nest_end(skb, data);
8612 genlmsg_end(skb, hdr);
8613
8614 if (data->nla_type == NL80211_ATTR_VENDOR_DATA)
8615 mcgrp = NL80211_MCGRP_VENDOR;
8616
8617 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), skb, 0,
8618 mcgrp, gfp);
8619}
8620EXPORT_SYMBOL(__cfg80211_send_event_skb);
8621
Johannes Bergaff89a92009-07-01 21:26:51 +02008622#ifdef CONFIG_NL80211_TESTMODE
Johannes Bergaff89a92009-07-01 21:26:51 +02008623static int nl80211_testmode_do(struct sk_buff *skb, struct genl_info *info)
8624{
Johannes Berg4c476992010-10-04 21:36:35 +02008625 struct cfg80211_registered_device *rdev = info->user_ptr[0];
David Spinadelfc73f112013-07-31 18:04:15 +03008626 struct wireless_dev *wdev =
8627 __cfg80211_wdev_from_attrs(genl_info_net(info), info->attrs);
Johannes Bergaff89a92009-07-01 21:26:51 +02008628 int err;
8629
David Spinadelfc73f112013-07-31 18:04:15 +03008630 if (!rdev->ops->testmode_cmd)
8631 return -EOPNOTSUPP;
8632
8633 if (IS_ERR(wdev)) {
8634 err = PTR_ERR(wdev);
8635 if (err != -EINVAL)
8636 return err;
8637 wdev = NULL;
8638 } else if (wdev->wiphy != &rdev->wiphy) {
8639 return -EINVAL;
8640 }
8641
Johannes Bergaff89a92009-07-01 21:26:51 +02008642 if (!info->attrs[NL80211_ATTR_TESTDATA])
8643 return -EINVAL;
8644
Johannes Bergad7e7182013-11-13 13:37:47 +01008645 rdev->cur_cmd_info = info;
David Spinadelfc73f112013-07-31 18:04:15 +03008646 err = rdev_testmode_cmd(rdev, wdev,
Johannes Bergaff89a92009-07-01 21:26:51 +02008647 nla_data(info->attrs[NL80211_ATTR_TESTDATA]),
8648 nla_len(info->attrs[NL80211_ATTR_TESTDATA]));
Johannes Bergad7e7182013-11-13 13:37:47 +01008649 rdev->cur_cmd_info = NULL;
Johannes Bergaff89a92009-07-01 21:26:51 +02008650
Johannes Bergaff89a92009-07-01 21:26:51 +02008651 return err;
8652}
8653
Wey-Yi Guy71063f02011-05-20 09:05:54 -07008654static int nl80211_testmode_dump(struct sk_buff *skb,
8655 struct netlink_callback *cb)
8656{
Johannes Berg00918d32011-12-13 17:22:05 +01008657 struct cfg80211_registered_device *rdev;
Wey-Yi Guy71063f02011-05-20 09:05:54 -07008658 int err;
8659 long phy_idx;
8660 void *data = NULL;
8661 int data_len = 0;
8662
Johannes Berg5fe231e2013-05-08 21:45:15 +02008663 rtnl_lock();
8664
Wey-Yi Guy71063f02011-05-20 09:05:54 -07008665 if (cb->args[0]) {
8666 /*
8667 * 0 is a valid index, but not valid for args[0],
8668 * so we need to offset by 1.
8669 */
8670 phy_idx = cb->args[0] - 1;
Luca Coelhoa4956dc2017-02-07 22:13:56 +02008671
8672 rdev = cfg80211_rdev_by_wiphy_idx(phy_idx);
8673 if (!rdev) {
8674 err = -ENOENT;
8675 goto out_err;
8676 }
Wey-Yi Guy71063f02011-05-20 09:05:54 -07008677 } else {
Johannes Bergc90c39d2016-10-24 14:40:01 +02008678 struct nlattr **attrbuf = genl_family_attrbuf(&nl80211_fam);
8679
Wey-Yi Guy71063f02011-05-20 09:05:54 -07008680 err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize,
Johannes Bergc90c39d2016-10-24 14:40:01 +02008681 attrbuf, nl80211_fam.maxattr, nl80211_policy);
Wey-Yi Guy71063f02011-05-20 09:05:54 -07008682 if (err)
Johannes Berg5fe231e2013-05-08 21:45:15 +02008683 goto out_err;
Johannes Berg00918d32011-12-13 17:22:05 +01008684
Johannes Bergc90c39d2016-10-24 14:40:01 +02008685 rdev = __cfg80211_rdev_from_attrs(sock_net(skb->sk), attrbuf);
Johannes Berg2bd7e352012-06-15 14:23:16 +02008686 if (IS_ERR(rdev)) {
Johannes Berg5fe231e2013-05-08 21:45:15 +02008687 err = PTR_ERR(rdev);
8688 goto out_err;
Johannes Berg00918d32011-12-13 17:22:05 +01008689 }
Johannes Berg2bd7e352012-06-15 14:23:16 +02008690 phy_idx = rdev->wiphy_idx;
Johannes Berg2bd7e352012-06-15 14:23:16 +02008691
Johannes Bergc90c39d2016-10-24 14:40:01 +02008692 if (attrbuf[NL80211_ATTR_TESTDATA])
8693 cb->args[1] = (long)attrbuf[NL80211_ATTR_TESTDATA];
Wey-Yi Guy71063f02011-05-20 09:05:54 -07008694 }
8695
8696 if (cb->args[1]) {
8697 data = nla_data((void *)cb->args[1]);
8698 data_len = nla_len((void *)cb->args[1]);
8699 }
8700
Johannes Berg00918d32011-12-13 17:22:05 +01008701 if (!rdev->ops->testmode_dump) {
Wey-Yi Guy71063f02011-05-20 09:05:54 -07008702 err = -EOPNOTSUPP;
8703 goto out_err;
8704 }
8705
8706 while (1) {
Eric W. Biederman15e47302012-09-07 20:12:54 +00008707 void *hdr = nl80211hdr_put(skb, NETLINK_CB(cb->skb).portid,
Wey-Yi Guy71063f02011-05-20 09:05:54 -07008708 cb->nlh->nlmsg_seq, NLM_F_MULTI,
8709 NL80211_CMD_TESTMODE);
8710 struct nlattr *tmdata;
8711
Dan Carpentercb35fba2013-08-14 14:50:01 +03008712 if (!hdr)
8713 break;
8714
David S. Miller9360ffd2012-03-29 04:41:26 -04008715 if (nla_put_u32(skb, NL80211_ATTR_WIPHY, phy_idx)) {
Wey-Yi Guy71063f02011-05-20 09:05:54 -07008716 genlmsg_cancel(skb, hdr);
8717 break;
8718 }
8719
8720 tmdata = nla_nest_start(skb, NL80211_ATTR_TESTDATA);
8721 if (!tmdata) {
8722 genlmsg_cancel(skb, hdr);
8723 break;
8724 }
Hila Gonene35e4d22012-06-27 17:19:42 +03008725 err = rdev_testmode_dump(rdev, skb, cb, data, data_len);
Wey-Yi Guy71063f02011-05-20 09:05:54 -07008726 nla_nest_end(skb, tmdata);
8727
8728 if (err == -ENOBUFS || err == -ENOENT) {
8729 genlmsg_cancel(skb, hdr);
8730 break;
8731 } else if (err) {
8732 genlmsg_cancel(skb, hdr);
8733 goto out_err;
8734 }
8735
8736 genlmsg_end(skb, hdr);
8737 }
8738
8739 err = skb->len;
8740 /* see above */
8741 cb->args[0] = phy_idx + 1;
8742 out_err:
Johannes Berg5fe231e2013-05-08 21:45:15 +02008743 rtnl_unlock();
Wey-Yi Guy71063f02011-05-20 09:05:54 -07008744 return err;
8745}
Johannes Bergaff89a92009-07-01 21:26:51 +02008746#endif
8747
Samuel Ortizb23aa672009-07-01 21:26:54 +02008748static int nl80211_connect(struct sk_buff *skb, struct genl_info *info)
8749{
Johannes Berg4c476992010-10-04 21:36:35 +02008750 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8751 struct net_device *dev = info->user_ptr[1];
Samuel Ortizb23aa672009-07-01 21:26:54 +02008752 struct cfg80211_connect_params connect;
8753 struct wiphy *wiphy;
Johannes Bergfffd0932009-07-08 14:22:54 +02008754 struct cfg80211_cached_keys *connkeys = NULL;
Samuel Ortizb23aa672009-07-01 21:26:54 +02008755 int err;
8756
8757 memset(&connect, 0, sizeof(connect));
8758
8759 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
8760 return -EINVAL;
8761
8762 if (!info->attrs[NL80211_ATTR_SSID] ||
8763 !nla_len(info->attrs[NL80211_ATTR_SSID]))
8764 return -EINVAL;
8765
8766 if (info->attrs[NL80211_ATTR_AUTH_TYPE]) {
8767 connect.auth_type =
8768 nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]);
Jouni Malinene39e5b52012-09-30 19:29:39 +03008769 if (!nl80211_valid_auth_type(rdev, connect.auth_type,
8770 NL80211_CMD_CONNECT))
Samuel Ortizb23aa672009-07-01 21:26:54 +02008771 return -EINVAL;
8772 } else
8773 connect.auth_type = NL80211_AUTHTYPE_AUTOMATIC;
8774
8775 connect.privacy = info->attrs[NL80211_ATTR_PRIVACY];
8776
Johannes Bergc0692b82010-08-27 14:26:53 +03008777 err = nl80211_crypto_settings(rdev, info, &connect.crypto,
Johannes Berg3dc27d22009-07-02 21:36:37 +02008778 NL80211_MAX_NR_CIPHER_SUITES);
Samuel Ortizb23aa672009-07-01 21:26:54 +02008779 if (err)
8780 return err;
Samuel Ortizb23aa672009-07-01 21:26:54 +02008781
Johannes Berg074ac8d2010-09-16 14:58:22 +02008782 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02008783 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
8784 return -EOPNOTSUPP;
Samuel Ortizb23aa672009-07-01 21:26:54 +02008785
Johannes Berg79c97e92009-07-07 03:56:12 +02008786 wiphy = &rdev->wiphy;
Samuel Ortizb23aa672009-07-01 21:26:54 +02008787
Bala Shanmugam4486ea92012-03-07 17:27:12 +05308788 connect.bg_scan_period = -1;
8789 if (info->attrs[NL80211_ATTR_BG_SCAN_PERIOD] &&
8790 (wiphy->flags & WIPHY_FLAG_SUPPORTS_FW_ROAM)) {
8791 connect.bg_scan_period =
8792 nla_get_u16(info->attrs[NL80211_ATTR_BG_SCAN_PERIOD]);
8793 }
8794
Samuel Ortizb23aa672009-07-01 21:26:54 +02008795 if (info->attrs[NL80211_ATTR_MAC])
8796 connect.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen1df4a512014-01-15 00:00:47 +02008797 else if (info->attrs[NL80211_ATTR_MAC_HINT])
8798 connect.bssid_hint =
8799 nla_data(info->attrs[NL80211_ATTR_MAC_HINT]);
Samuel Ortizb23aa672009-07-01 21:26:54 +02008800 connect.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
8801 connect.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
8802
8803 if (info->attrs[NL80211_ATTR_IE]) {
8804 connect.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
8805 connect.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
8806 }
8807
Jouni Malinencee00a92013-01-15 17:15:57 +02008808 if (info->attrs[NL80211_ATTR_USE_MFP]) {
8809 connect.mfp = nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]);
8810 if (connect.mfp != NL80211_MFP_REQUIRED &&
8811 connect.mfp != NL80211_MFP_NO)
8812 return -EINVAL;
8813 } else {
8814 connect.mfp = NL80211_MFP_NO;
8815 }
8816
Jouni Malinenba6fbac2016-03-29 13:53:27 +03008817 if (info->attrs[NL80211_ATTR_PREV_BSSID])
8818 connect.prev_bssid =
8819 nla_data(info->attrs[NL80211_ATTR_PREV_BSSID]);
8820
Samuel Ortizb23aa672009-07-01 21:26:54 +02008821 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
Jouni Malinen664834d2014-01-15 00:01:44 +02008822 connect.channel = nl80211_get_valid_chan(
8823 wiphy, info->attrs[NL80211_ATTR_WIPHY_FREQ]);
8824 if (!connect.channel)
Johannes Berg4c476992010-10-04 21:36:35 +02008825 return -EINVAL;
Jouni Malinen1df4a512014-01-15 00:00:47 +02008826 } else if (info->attrs[NL80211_ATTR_WIPHY_FREQ_HINT]) {
Jouni Malinen664834d2014-01-15 00:01:44 +02008827 connect.channel_hint = nl80211_get_valid_chan(
8828 wiphy, info->attrs[NL80211_ATTR_WIPHY_FREQ_HINT]);
8829 if (!connect.channel_hint)
Jouni Malinen1df4a512014-01-15 00:00:47 +02008830 return -EINVAL;
Samuel Ortizb23aa672009-07-01 21:26:54 +02008831 }
8832
Johannes Bergfffd0932009-07-08 14:22:54 +02008833 if (connect.privacy && info->attrs[NL80211_ATTR_KEYS]) {
8834 connkeys = nl80211_parse_connkeys(rdev,
Sujith Manoharande7044e2012-10-18 10:19:28 +05308835 info->attrs[NL80211_ATTR_KEYS], NULL);
Johannes Berg4c476992010-10-04 21:36:35 +02008836 if (IS_ERR(connkeys))
8837 return PTR_ERR(connkeys);
Johannes Bergfffd0932009-07-08 14:22:54 +02008838 }
8839
Ben Greear7e7c8922011-11-18 11:31:59 -08008840 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT]))
8841 connect.flags |= ASSOC_REQ_DISABLE_HT;
8842
8843 if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
8844 memcpy(&connect.ht_capa_mask,
8845 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]),
8846 sizeof(connect.ht_capa_mask));
8847
8848 if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) {
Wei Yongjunb4e4f472012-09-02 21:41:04 +08008849 if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) {
Johannes Bergb47f6102014-09-10 13:39:54 +03008850 kzfree(connkeys);
Ben Greear7e7c8922011-11-18 11:31:59 -08008851 return -EINVAL;
Wei Yongjunb4e4f472012-09-02 21:41:04 +08008852 }
Ben Greear7e7c8922011-11-18 11:31:59 -08008853 memcpy(&connect.ht_capa,
8854 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]),
8855 sizeof(connect.ht_capa));
8856 }
8857
Johannes Bergee2aca32013-02-21 17:36:01 +01008858 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_VHT]))
8859 connect.flags |= ASSOC_REQ_DISABLE_VHT;
8860
8861 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK])
8862 memcpy(&connect.vht_capa_mask,
8863 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]),
8864 sizeof(connect.vht_capa_mask));
8865
8866 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) {
8867 if (!info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) {
Johannes Bergb47f6102014-09-10 13:39:54 +03008868 kzfree(connkeys);
Johannes Bergee2aca32013-02-21 17:36:01 +01008869 return -EINVAL;
8870 }
8871 memcpy(&connect.vht_capa,
8872 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]),
8873 sizeof(connect.vht_capa));
8874 }
8875
Assaf Kraussbab5ab72014-09-03 15:25:01 +03008876 if (nla_get_flag(info->attrs[NL80211_ATTR_USE_RRM])) {
Beni Lev0c9ca112016-02-17 20:30:00 +02008877 if (!((rdev->wiphy.features &
8878 NL80211_FEATURE_DS_PARAM_SET_IE_IN_PROBES) &&
8879 (rdev->wiphy.features & NL80211_FEATURE_QUIET)) &&
8880 !wiphy_ext_feature_isset(&rdev->wiphy,
8881 NL80211_EXT_FEATURE_RRM)) {
Ola Olsson707554b2015-12-11 21:04:52 +01008882 kzfree(connkeys);
Assaf Kraussbab5ab72014-09-03 15:25:01 +03008883 return -EINVAL;
Ola Olsson707554b2015-12-11 21:04:52 +01008884 }
Assaf Kraussbab5ab72014-09-03 15:25:01 +03008885 connect.flags |= ASSOC_REQ_USE_RRM;
8886 }
8887
Lior David34d50512016-01-28 10:58:25 +02008888 connect.pbss = nla_get_flag(info->attrs[NL80211_ATTR_PBSS]);
Johannes Berg57fbcce2016-04-12 15:56:15 +02008889 if (connect.pbss && !rdev->wiphy.bands[NL80211_BAND_60GHZ]) {
Lior David34d50512016-01-28 10:58:25 +02008890 kzfree(connkeys);
8891 return -EOPNOTSUPP;
8892 }
8893
Arend van Spriel38de03d2016-03-02 20:37:18 +01008894 if (info->attrs[NL80211_ATTR_BSS_SELECT]) {
8895 /* bss selection makes no sense if bssid is set */
8896 if (connect.bssid) {
8897 kzfree(connkeys);
8898 return -EINVAL;
8899 }
8900
8901 err = parse_bss_select(info->attrs[NL80211_ATTR_BSS_SELECT],
8902 wiphy, &connect.bss_select);
8903 if (err) {
8904 kzfree(connkeys);
8905 return err;
8906 }
8907 }
8908
Johannes Berg83739b02013-05-15 17:44:01 +02008909 wdev_lock(dev->ieee80211_ptr);
Andrzej Zaborowskibd2522b2017-01-06 16:33:43 -05008910
Jouni Malinen4ce2bd9c42016-03-29 13:53:28 +03008911 err = cfg80211_connect(rdev, dev, &connect, connkeys,
8912 connect.prev_bssid);
Johannes Bergfffd0932009-07-08 14:22:54 +02008913 if (err)
Johannes Bergb47f6102014-09-10 13:39:54 +03008914 kzfree(connkeys);
Andrzej Zaborowskibd2522b2017-01-06 16:33:43 -05008915
8916 if (!err && info->attrs[NL80211_ATTR_SOCKET_OWNER]) {
8917 dev->ieee80211_ptr->conn_owner_nlportid = info->snd_portid;
8918 if (connect.bssid)
8919 memcpy(dev->ieee80211_ptr->disconnect_bssid,
8920 connect.bssid, ETH_ALEN);
8921 else
8922 memset(dev->ieee80211_ptr->disconnect_bssid,
8923 0, ETH_ALEN);
8924 }
8925
8926 wdev_unlock(dev->ieee80211_ptr);
8927
Samuel Ortizb23aa672009-07-01 21:26:54 +02008928 return err;
8929}
8930
vamsi krishna088e8df2016-10-27 16:51:11 +03008931static int nl80211_update_connect_params(struct sk_buff *skb,
8932 struct genl_info *info)
8933{
8934 struct cfg80211_connect_params connect = {};
8935 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8936 struct net_device *dev = info->user_ptr[1];
8937 struct wireless_dev *wdev = dev->ieee80211_ptr;
8938 u32 changed = 0;
8939 int ret;
8940
8941 if (!rdev->ops->update_connect_params)
8942 return -EOPNOTSUPP;
8943
8944 if (info->attrs[NL80211_ATTR_IE]) {
8945 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
8946 return -EINVAL;
8947 connect.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
8948 connect.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
8949 changed |= UPDATE_ASSOC_IES;
8950 }
8951
8952 wdev_lock(dev->ieee80211_ptr);
8953 if (!wdev->current_bss)
8954 ret = -ENOLINK;
8955 else
8956 ret = rdev_update_connect_params(rdev, dev, &connect, changed);
8957 wdev_unlock(dev->ieee80211_ptr);
8958
8959 return ret;
8960}
8961
Samuel Ortizb23aa672009-07-01 21:26:54 +02008962static int nl80211_disconnect(struct sk_buff *skb, struct genl_info *info)
8963{
Johannes Berg4c476992010-10-04 21:36:35 +02008964 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8965 struct net_device *dev = info->user_ptr[1];
Samuel Ortizb23aa672009-07-01 21:26:54 +02008966 u16 reason;
Johannes Berg83739b02013-05-15 17:44:01 +02008967 int ret;
Samuel Ortizb23aa672009-07-01 21:26:54 +02008968
8969 if (!info->attrs[NL80211_ATTR_REASON_CODE])
8970 reason = WLAN_REASON_DEAUTH_LEAVING;
8971 else
8972 reason = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
8973
8974 if (reason == 0)
8975 return -EINVAL;
8976
Johannes Berg074ac8d2010-09-16 14:58:22 +02008977 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02008978 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
8979 return -EOPNOTSUPP;
Samuel Ortizb23aa672009-07-01 21:26:54 +02008980
Johannes Berg83739b02013-05-15 17:44:01 +02008981 wdev_lock(dev->ieee80211_ptr);
8982 ret = cfg80211_disconnect(rdev, dev, reason, true);
8983 wdev_unlock(dev->ieee80211_ptr);
8984 return ret;
Samuel Ortizb23aa672009-07-01 21:26:54 +02008985}
8986
Johannes Berg463d0182009-07-14 00:33:35 +02008987static int nl80211_wiphy_netns(struct sk_buff *skb, struct genl_info *info)
8988{
Johannes Berg4c476992010-10-04 21:36:35 +02008989 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg463d0182009-07-14 00:33:35 +02008990 struct net *net;
8991 int err;
Johannes Berg463d0182009-07-14 00:33:35 +02008992
Vadim Kochan4b681c82015-01-12 16:34:05 +02008993 if (info->attrs[NL80211_ATTR_PID]) {
8994 u32 pid = nla_get_u32(info->attrs[NL80211_ATTR_PID]);
8995
8996 net = get_net_ns_by_pid(pid);
8997 } else if (info->attrs[NL80211_ATTR_NETNS_FD]) {
8998 u32 fd = nla_get_u32(info->attrs[NL80211_ATTR_NETNS_FD]);
8999
9000 net = get_net_ns_by_fd(fd);
9001 } else {
Johannes Berg463d0182009-07-14 00:33:35 +02009002 return -EINVAL;
Vadim Kochan4b681c82015-01-12 16:34:05 +02009003 }
Johannes Berg463d0182009-07-14 00:33:35 +02009004
Johannes Berg4c476992010-10-04 21:36:35 +02009005 if (IS_ERR(net))
9006 return PTR_ERR(net);
Johannes Berg463d0182009-07-14 00:33:35 +02009007
9008 err = 0;
9009
9010 /* check if anything to do */
Johannes Berg4c476992010-10-04 21:36:35 +02009011 if (!net_eq(wiphy_net(&rdev->wiphy), net))
9012 err = cfg80211_switch_netns(rdev, net);
Johannes Berg463d0182009-07-14 00:33:35 +02009013
Johannes Berg463d0182009-07-14 00:33:35 +02009014 put_net(net);
Johannes Berg463d0182009-07-14 00:33:35 +02009015 return err;
9016}
9017
Samuel Ortiz67fbb162009-11-24 23:59:15 +01009018static int nl80211_setdel_pmksa(struct sk_buff *skb, struct genl_info *info)
9019{
Johannes Berg4c476992010-10-04 21:36:35 +02009020 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Samuel Ortiz67fbb162009-11-24 23:59:15 +01009021 int (*rdev_ops)(struct wiphy *wiphy, struct net_device *dev,
9022 struct cfg80211_pmksa *pmksa) = NULL;
Johannes Berg4c476992010-10-04 21:36:35 +02009023 struct net_device *dev = info->user_ptr[1];
Samuel Ortiz67fbb162009-11-24 23:59:15 +01009024 struct cfg80211_pmksa pmksa;
9025
9026 memset(&pmksa, 0, sizeof(struct cfg80211_pmksa));
9027
9028 if (!info->attrs[NL80211_ATTR_MAC])
9029 return -EINVAL;
9030
9031 if (!info->attrs[NL80211_ATTR_PMKID])
9032 return -EINVAL;
9033
Samuel Ortiz67fbb162009-11-24 23:59:15 +01009034 pmksa.pmkid = nla_data(info->attrs[NL80211_ATTR_PMKID]);
9035 pmksa.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
9036
Johannes Berg074ac8d2010-09-16 14:58:22 +02009037 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02009038 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
9039 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01009040
9041 switch (info->genlhdr->cmd) {
9042 case NL80211_CMD_SET_PMKSA:
9043 rdev_ops = rdev->ops->set_pmksa;
9044 break;
9045 case NL80211_CMD_DEL_PMKSA:
9046 rdev_ops = rdev->ops->del_pmksa;
9047 break;
9048 default:
9049 WARN_ON(1);
9050 break;
9051 }
9052
Johannes Berg4c476992010-10-04 21:36:35 +02009053 if (!rdev_ops)
9054 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01009055
Johannes Berg4c476992010-10-04 21:36:35 +02009056 return rdev_ops(&rdev->wiphy, dev, &pmksa);
Samuel Ortiz67fbb162009-11-24 23:59:15 +01009057}
9058
9059static int nl80211_flush_pmksa(struct sk_buff *skb, struct genl_info *info)
9060{
Johannes Berg4c476992010-10-04 21:36:35 +02009061 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9062 struct net_device *dev = info->user_ptr[1];
Samuel Ortiz67fbb162009-11-24 23:59:15 +01009063
Johannes Berg074ac8d2010-09-16 14:58:22 +02009064 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02009065 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
9066 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01009067
Johannes Berg4c476992010-10-04 21:36:35 +02009068 if (!rdev->ops->flush_pmksa)
9069 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01009070
Hila Gonene35e4d22012-06-27 17:19:42 +03009071 return rdev_flush_pmksa(rdev, dev);
Samuel Ortiz67fbb162009-11-24 23:59:15 +01009072}
9073
Arik Nemtsov109086c2011-09-28 14:12:50 +03009074static int nl80211_tdls_mgmt(struct sk_buff *skb, struct genl_info *info)
9075{
9076 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9077 struct net_device *dev = info->user_ptr[1];
9078 u8 action_code, dialog_token;
Sunil Dutt Undekaridf942e72014-02-20 16:22:09 +05309079 u32 peer_capability = 0;
Arik Nemtsov109086c2011-09-28 14:12:50 +03009080 u16 status_code;
9081 u8 *peer;
Arik Nemtsov31fa97c2014-06-11 17:18:21 +03009082 bool initiator;
Arik Nemtsov109086c2011-09-28 14:12:50 +03009083
9084 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) ||
9085 !rdev->ops->tdls_mgmt)
9086 return -EOPNOTSUPP;
9087
9088 if (!info->attrs[NL80211_ATTR_TDLS_ACTION] ||
9089 !info->attrs[NL80211_ATTR_STATUS_CODE] ||
9090 !info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN] ||
9091 !info->attrs[NL80211_ATTR_IE] ||
9092 !info->attrs[NL80211_ATTR_MAC])
9093 return -EINVAL;
9094
9095 peer = nla_data(info->attrs[NL80211_ATTR_MAC]);
9096 action_code = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_ACTION]);
9097 status_code = nla_get_u16(info->attrs[NL80211_ATTR_STATUS_CODE]);
9098 dialog_token = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN]);
Arik Nemtsov31fa97c2014-06-11 17:18:21 +03009099 initiator = nla_get_flag(info->attrs[NL80211_ATTR_TDLS_INITIATOR]);
Sunil Dutt Undekaridf942e72014-02-20 16:22:09 +05309100 if (info->attrs[NL80211_ATTR_TDLS_PEER_CAPABILITY])
9101 peer_capability =
9102 nla_get_u32(info->attrs[NL80211_ATTR_TDLS_PEER_CAPABILITY]);
Arik Nemtsov109086c2011-09-28 14:12:50 +03009103
Hila Gonene35e4d22012-06-27 17:19:42 +03009104 return rdev_tdls_mgmt(rdev, dev, peer, action_code,
Sunil Dutt Undekaridf942e72014-02-20 16:22:09 +05309105 dialog_token, status_code, peer_capability,
Arik Nemtsov31fa97c2014-06-11 17:18:21 +03009106 initiator,
Hila Gonene35e4d22012-06-27 17:19:42 +03009107 nla_data(info->attrs[NL80211_ATTR_IE]),
9108 nla_len(info->attrs[NL80211_ATTR_IE]));
Arik Nemtsov109086c2011-09-28 14:12:50 +03009109}
9110
9111static int nl80211_tdls_oper(struct sk_buff *skb, struct genl_info *info)
9112{
9113 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9114 struct net_device *dev = info->user_ptr[1];
9115 enum nl80211_tdls_operation operation;
9116 u8 *peer;
9117
9118 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) ||
9119 !rdev->ops->tdls_oper)
9120 return -EOPNOTSUPP;
9121
9122 if (!info->attrs[NL80211_ATTR_TDLS_OPERATION] ||
9123 !info->attrs[NL80211_ATTR_MAC])
9124 return -EINVAL;
9125
9126 operation = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_OPERATION]);
9127 peer = nla_data(info->attrs[NL80211_ATTR_MAC]);
9128
Hila Gonene35e4d22012-06-27 17:19:42 +03009129 return rdev_tdls_oper(rdev, dev, peer, operation);
Arik Nemtsov109086c2011-09-28 14:12:50 +03009130}
9131
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009132static int nl80211_remain_on_channel(struct sk_buff *skb,
9133 struct genl_info *info)
9134{
Johannes Berg4c476992010-10-04 21:36:35 +02009135 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02009136 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg683b6d32012-11-08 21:25:48 +01009137 struct cfg80211_chan_def chandef;
Vasanthakumar Thiagarajan34373d12017-02-27 17:04:34 +05309138 const struct cfg80211_chan_def *compat_chandef;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009139 struct sk_buff *msg;
9140 void *hdr;
9141 u64 cookie;
Johannes Berg683b6d32012-11-08 21:25:48 +01009142 u32 duration;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009143 int err;
9144
9145 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] ||
9146 !info->attrs[NL80211_ATTR_DURATION])
9147 return -EINVAL;
9148
9149 duration = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]);
9150
Johannes Berg7c4ef712011-11-18 15:33:48 +01009151 if (!rdev->ops->remain_on_channel ||
9152 !(rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL))
Johannes Berg4c476992010-10-04 21:36:35 +02009153 return -EOPNOTSUPP;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009154
Johannes Bergebf348f2012-06-01 12:50:54 +02009155 /*
9156 * We should be on that channel for at least a minimum amount of
9157 * time (10ms) but no longer than the driver supports.
9158 */
9159 if (duration < NL80211_MIN_REMAIN_ON_CHANNEL_TIME ||
9160 duration > rdev->wiphy.max_remain_on_channel_duration)
9161 return -EINVAL;
9162
Johannes Berg683b6d32012-11-08 21:25:48 +01009163 err = nl80211_parse_chandef(rdev, info, &chandef);
9164 if (err)
9165 return err;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009166
Vasanthakumar Thiagarajan34373d12017-02-27 17:04:34 +05309167 wdev_lock(wdev);
9168 if (!cfg80211_off_channel_oper_allowed(wdev) &&
9169 !cfg80211_chandef_identical(&wdev->chandef, &chandef)) {
9170 compat_chandef = cfg80211_chandef_compatible(&wdev->chandef,
9171 &chandef);
9172 if (compat_chandef != &chandef) {
9173 wdev_unlock(wdev);
9174 return -EBUSY;
9175 }
9176 }
9177 wdev_unlock(wdev);
9178
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009179 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02009180 if (!msg)
9181 return -ENOMEM;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009182
Eric W. Biederman15e47302012-09-07 20:12:54 +00009183 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009184 NL80211_CMD_REMAIN_ON_CHANNEL);
Dan Carpentercb35fba2013-08-14 14:50:01 +03009185 if (!hdr) {
9186 err = -ENOBUFS;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009187 goto free_msg;
9188 }
9189
Johannes Berg683b6d32012-11-08 21:25:48 +01009190 err = rdev_remain_on_channel(rdev, wdev, chandef.chan,
9191 duration, &cookie);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009192
9193 if (err)
9194 goto free_msg;
9195
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02009196 if (nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie,
9197 NL80211_ATTR_PAD))
David S. Miller9360ffd2012-03-29 04:41:26 -04009198 goto nla_put_failure;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009199
9200 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02009201
9202 return genlmsg_reply(msg, info);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009203
9204 nla_put_failure:
9205 err = -ENOBUFS;
9206 free_msg:
9207 nlmsg_free(msg);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009208 return err;
9209}
9210
9211static int nl80211_cancel_remain_on_channel(struct sk_buff *skb,
9212 struct genl_info *info)
9213{
Johannes Berg4c476992010-10-04 21:36:35 +02009214 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02009215 struct wireless_dev *wdev = info->user_ptr[1];
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009216 u64 cookie;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009217
9218 if (!info->attrs[NL80211_ATTR_COOKIE])
9219 return -EINVAL;
9220
Johannes Berg4c476992010-10-04 21:36:35 +02009221 if (!rdev->ops->cancel_remain_on_channel)
9222 return -EOPNOTSUPP;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009223
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009224 cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]);
9225
Hila Gonene35e4d22012-06-27 17:19:42 +03009226 return rdev_cancel_remain_on_channel(rdev, wdev, cookie);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009227}
9228
Jouni Malinen13ae75b2009-12-29 12:59:45 +02009229static int nl80211_set_tx_bitrate_mask(struct sk_buff *skb,
9230 struct genl_info *info)
9231{
Jouni Malinen13ae75b2009-12-29 12:59:45 +02009232 struct cfg80211_bitrate_mask mask;
Purushottam Kushwahaa7c7fbf2016-09-14 17:38:44 +05309233 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg4c476992010-10-04 21:36:35 +02009234 struct net_device *dev = info->user_ptr[1];
Purushottam Kushwahaa7c7fbf2016-09-14 17:38:44 +05309235 int err;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02009236
Johannes Berg4c476992010-10-04 21:36:35 +02009237 if (!rdev->ops->set_bitrate_mask)
9238 return -EOPNOTSUPP;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02009239
Purushottam Kushwahaa7c7fbf2016-09-14 17:38:44 +05309240 err = nl80211_parse_tx_bitrate_mask(info, &mask);
9241 if (err)
9242 return err;
Janusz Dziedzic78693032013-12-03 09:50:44 +01009243
Hila Gonene35e4d22012-06-27 17:19:42 +03009244 return rdev_set_bitrate_mask(rdev, dev, NULL, &mask);
Jouni Malinen13ae75b2009-12-29 12:59:45 +02009245}
9246
Johannes Berg2e161f72010-08-12 15:38:38 +02009247static int nl80211_register_mgmt(struct sk_buff *skb, struct genl_info *info)
Jouni Malinen026331c2010-02-15 12:53:10 +02009248{
Johannes Berg4c476992010-10-04 21:36:35 +02009249 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02009250 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg2e161f72010-08-12 15:38:38 +02009251 u16 frame_type = IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_ACTION;
Jouni Malinen026331c2010-02-15 12:53:10 +02009252
9253 if (!info->attrs[NL80211_ATTR_FRAME_MATCH])
9254 return -EINVAL;
9255
Johannes Berg2e161f72010-08-12 15:38:38 +02009256 if (info->attrs[NL80211_ATTR_FRAME_TYPE])
9257 frame_type = nla_get_u16(info->attrs[NL80211_ATTR_FRAME_TYPE]);
Jouni Malinen026331c2010-02-15 12:53:10 +02009258
Johannes Berg71bbc992012-06-15 15:30:18 +02009259 switch (wdev->iftype) {
9260 case NL80211_IFTYPE_STATION:
9261 case NL80211_IFTYPE_ADHOC:
9262 case NL80211_IFTYPE_P2P_CLIENT:
9263 case NL80211_IFTYPE_AP:
9264 case NL80211_IFTYPE_AP_VLAN:
9265 case NL80211_IFTYPE_MESH_POINT:
9266 case NL80211_IFTYPE_P2P_GO:
Johannes Berg98104fde2012-06-16 00:19:54 +02009267 case NL80211_IFTYPE_P2P_DEVICE:
Johannes Berg71bbc992012-06-15 15:30:18 +02009268 break;
Ayala Bekercb3b7d82016-09-20 17:31:13 +03009269 case NL80211_IFTYPE_NAN:
Johannes Berg71bbc992012-06-15 15:30:18 +02009270 default:
Johannes Berg4c476992010-10-04 21:36:35 +02009271 return -EOPNOTSUPP;
Johannes Berg71bbc992012-06-15 15:30:18 +02009272 }
Jouni Malinen026331c2010-02-15 12:53:10 +02009273
9274 /* not much point in registering if we can't reply */
Johannes Berg4c476992010-10-04 21:36:35 +02009275 if (!rdev->ops->mgmt_tx)
9276 return -EOPNOTSUPP;
Jouni Malinen026331c2010-02-15 12:53:10 +02009277
Eric W. Biederman15e47302012-09-07 20:12:54 +00009278 return cfg80211_mlme_register_mgmt(wdev, info->snd_portid, frame_type,
Jouni Malinen026331c2010-02-15 12:53:10 +02009279 nla_data(info->attrs[NL80211_ATTR_FRAME_MATCH]),
9280 nla_len(info->attrs[NL80211_ATTR_FRAME_MATCH]));
Jouni Malinen026331c2010-02-15 12:53:10 +02009281}
9282
Johannes Berg2e161f72010-08-12 15:38:38 +02009283static int nl80211_tx_mgmt(struct sk_buff *skb, struct genl_info *info)
Jouni Malinen026331c2010-02-15 12:53:10 +02009284{
Johannes Berg4c476992010-10-04 21:36:35 +02009285 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02009286 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg683b6d32012-11-08 21:25:48 +01009287 struct cfg80211_chan_def chandef;
Jouni Malinen026331c2010-02-15 12:53:10 +02009288 int err;
Johannes Bergd64d3732011-11-10 09:44:46 +01009289 void *hdr = NULL;
Jouni Malinen026331c2010-02-15 12:53:10 +02009290 u64 cookie;
Johannes Berge247bd902011-11-04 11:18:21 +01009291 struct sk_buff *msg = NULL;
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02009292 struct cfg80211_mgmt_tx_params params = {
9293 .dont_wait_for_ack =
9294 info->attrs[NL80211_ATTR_DONT_WAIT_FOR_ACK],
9295 };
Jouni Malinen026331c2010-02-15 12:53:10 +02009296
Johannes Berg683b6d32012-11-08 21:25:48 +01009297 if (!info->attrs[NL80211_ATTR_FRAME])
Jouni Malinen026331c2010-02-15 12:53:10 +02009298 return -EINVAL;
9299
Johannes Berg4c476992010-10-04 21:36:35 +02009300 if (!rdev->ops->mgmt_tx)
9301 return -EOPNOTSUPP;
Jouni Malinen026331c2010-02-15 12:53:10 +02009302
Johannes Berg71bbc992012-06-15 15:30:18 +02009303 switch (wdev->iftype) {
Antonio Quartulliea141b752013-06-11 14:20:03 +02009304 case NL80211_IFTYPE_P2P_DEVICE:
9305 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ])
9306 return -EINVAL;
Johannes Berg71bbc992012-06-15 15:30:18 +02009307 case NL80211_IFTYPE_STATION:
9308 case NL80211_IFTYPE_ADHOC:
9309 case NL80211_IFTYPE_P2P_CLIENT:
9310 case NL80211_IFTYPE_AP:
9311 case NL80211_IFTYPE_AP_VLAN:
9312 case NL80211_IFTYPE_MESH_POINT:
9313 case NL80211_IFTYPE_P2P_GO:
9314 break;
Ayala Bekercb3b7d82016-09-20 17:31:13 +03009315 case NL80211_IFTYPE_NAN:
Johannes Berg71bbc992012-06-15 15:30:18 +02009316 default:
Johannes Berg4c476992010-10-04 21:36:35 +02009317 return -EOPNOTSUPP;
Johannes Berg71bbc992012-06-15 15:30:18 +02009318 }
Jouni Malinen026331c2010-02-15 12:53:10 +02009319
Johannes Bergf7ca38d2010-11-25 10:02:29 +01009320 if (info->attrs[NL80211_ATTR_DURATION]) {
Johannes Berg7c4ef712011-11-18 15:33:48 +01009321 if (!(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX))
Johannes Bergf7ca38d2010-11-25 10:02:29 +01009322 return -EINVAL;
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02009323 params.wait = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]);
Johannes Bergebf348f2012-06-01 12:50:54 +02009324
9325 /*
9326 * We should wait on the channel for at least a minimum amount
9327 * of time (10ms) but no longer than the driver supports.
9328 */
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02009329 if (params.wait < NL80211_MIN_REMAIN_ON_CHANNEL_TIME ||
9330 params.wait > rdev->wiphy.max_remain_on_channel_duration)
Johannes Bergebf348f2012-06-01 12:50:54 +02009331 return -EINVAL;
Johannes Bergf7ca38d2010-11-25 10:02:29 +01009332 }
9333
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02009334 params.offchan = info->attrs[NL80211_ATTR_OFFCHANNEL_TX_OK];
Johannes Bergf7ca38d2010-11-25 10:02:29 +01009335
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02009336 if (params.offchan && !(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX))
Johannes Berg7c4ef712011-11-18 15:33:48 +01009337 return -EINVAL;
9338
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02009339 params.no_cck = nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]);
Rajkumar Manoharane9f935e2011-09-25 14:53:30 +05309340
Antonio Quartulliea141b752013-06-11 14:20:03 +02009341 /* get the channel if any has been specified, otherwise pass NULL to
9342 * the driver. The latter will use the current one
9343 */
9344 chandef.chan = NULL;
9345 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
9346 err = nl80211_parse_chandef(rdev, info, &chandef);
9347 if (err)
9348 return err;
9349 }
9350
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02009351 if (!chandef.chan && params.offchan)
Antonio Quartulliea141b752013-06-11 14:20:03 +02009352 return -EINVAL;
Jouni Malinen026331c2010-02-15 12:53:10 +02009353
Vasanthakumar Thiagarajan34373d12017-02-27 17:04:34 +05309354 wdev_lock(wdev);
9355 if (params.offchan && !cfg80211_off_channel_oper_allowed(wdev)) {
9356 wdev_unlock(wdev);
9357 return -EBUSY;
9358 }
9359 wdev_unlock(wdev);
9360
Andrei Otcheretianski34d22ce2014-05-09 14:11:44 +03009361 params.buf = nla_data(info->attrs[NL80211_ATTR_FRAME]);
9362 params.len = nla_len(info->attrs[NL80211_ATTR_FRAME]);
9363
9364 if (info->attrs[NL80211_ATTR_CSA_C_OFFSETS_TX]) {
9365 int len = nla_len(info->attrs[NL80211_ATTR_CSA_C_OFFSETS_TX]);
9366 int i;
9367
9368 if (len % sizeof(u16))
9369 return -EINVAL;
9370
9371 params.n_csa_offsets = len / sizeof(u16);
9372 params.csa_offsets =
9373 nla_data(info->attrs[NL80211_ATTR_CSA_C_OFFSETS_TX]);
9374
9375 /* check that all the offsets fit the frame */
9376 for (i = 0; i < params.n_csa_offsets; i++) {
9377 if (params.csa_offsets[i] >= params.len)
9378 return -EINVAL;
9379 }
9380 }
9381
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02009382 if (!params.dont_wait_for_ack) {
Johannes Berge247bd902011-11-04 11:18:21 +01009383 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
9384 if (!msg)
9385 return -ENOMEM;
Jouni Malinen026331c2010-02-15 12:53:10 +02009386
Eric W. Biederman15e47302012-09-07 20:12:54 +00009387 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berge247bd902011-11-04 11:18:21 +01009388 NL80211_CMD_FRAME);
Dan Carpentercb35fba2013-08-14 14:50:01 +03009389 if (!hdr) {
9390 err = -ENOBUFS;
Johannes Berge247bd902011-11-04 11:18:21 +01009391 goto free_msg;
9392 }
Jouni Malinen026331c2010-02-15 12:53:10 +02009393 }
Johannes Berge247bd902011-11-04 11:18:21 +01009394
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02009395 params.chan = chandef.chan;
9396 err = cfg80211_mlme_mgmt_tx(rdev, wdev, &params, &cookie);
Jouni Malinen026331c2010-02-15 12:53:10 +02009397 if (err)
9398 goto free_msg;
9399
Johannes Berge247bd902011-11-04 11:18:21 +01009400 if (msg) {
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02009401 if (nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie,
9402 NL80211_ATTR_PAD))
David S. Miller9360ffd2012-03-29 04:41:26 -04009403 goto nla_put_failure;
Jouni Malinen026331c2010-02-15 12:53:10 +02009404
Johannes Berge247bd902011-11-04 11:18:21 +01009405 genlmsg_end(msg, hdr);
9406 return genlmsg_reply(msg, info);
9407 }
9408
9409 return 0;
Jouni Malinen026331c2010-02-15 12:53:10 +02009410
9411 nla_put_failure:
9412 err = -ENOBUFS;
9413 free_msg:
9414 nlmsg_free(msg);
Jouni Malinen026331c2010-02-15 12:53:10 +02009415 return err;
9416}
9417
Johannes Bergf7ca38d2010-11-25 10:02:29 +01009418static int nl80211_tx_mgmt_cancel_wait(struct sk_buff *skb, struct genl_info *info)
9419{
9420 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02009421 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Bergf7ca38d2010-11-25 10:02:29 +01009422 u64 cookie;
9423
9424 if (!info->attrs[NL80211_ATTR_COOKIE])
9425 return -EINVAL;
9426
9427 if (!rdev->ops->mgmt_tx_cancel_wait)
9428 return -EOPNOTSUPP;
9429
Johannes Berg71bbc992012-06-15 15:30:18 +02009430 switch (wdev->iftype) {
9431 case NL80211_IFTYPE_STATION:
9432 case NL80211_IFTYPE_ADHOC:
9433 case NL80211_IFTYPE_P2P_CLIENT:
9434 case NL80211_IFTYPE_AP:
9435 case NL80211_IFTYPE_AP_VLAN:
9436 case NL80211_IFTYPE_P2P_GO:
Johannes Berg98104fde2012-06-16 00:19:54 +02009437 case NL80211_IFTYPE_P2P_DEVICE:
Johannes Berg71bbc992012-06-15 15:30:18 +02009438 break;
Ayala Bekercb3b7d82016-09-20 17:31:13 +03009439 case NL80211_IFTYPE_NAN:
Johannes Berg71bbc992012-06-15 15:30:18 +02009440 default:
Johannes Bergf7ca38d2010-11-25 10:02:29 +01009441 return -EOPNOTSUPP;
Johannes Berg71bbc992012-06-15 15:30:18 +02009442 }
Johannes Bergf7ca38d2010-11-25 10:02:29 +01009443
9444 cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]);
9445
Hila Gonene35e4d22012-06-27 17:19:42 +03009446 return rdev_mgmt_tx_cancel_wait(rdev, wdev, cookie);
Johannes Bergf7ca38d2010-11-25 10:02:29 +01009447}
9448
Kalle Valoffb9eb32010-02-17 17:58:10 +02009449static int nl80211_set_power_save(struct sk_buff *skb, struct genl_info *info)
9450{
Johannes Berg4c476992010-10-04 21:36:35 +02009451 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Kalle Valoffb9eb32010-02-17 17:58:10 +02009452 struct wireless_dev *wdev;
Johannes Berg4c476992010-10-04 21:36:35 +02009453 struct net_device *dev = info->user_ptr[1];
Kalle Valoffb9eb32010-02-17 17:58:10 +02009454 u8 ps_state;
9455 bool state;
9456 int err;
9457
Johannes Berg4c476992010-10-04 21:36:35 +02009458 if (!info->attrs[NL80211_ATTR_PS_STATE])
9459 return -EINVAL;
Kalle Valoffb9eb32010-02-17 17:58:10 +02009460
9461 ps_state = nla_get_u32(info->attrs[NL80211_ATTR_PS_STATE]);
9462
Johannes Berg4c476992010-10-04 21:36:35 +02009463 if (ps_state != NL80211_PS_DISABLED && ps_state != NL80211_PS_ENABLED)
9464 return -EINVAL;
Kalle Valoffb9eb32010-02-17 17:58:10 +02009465
9466 wdev = dev->ieee80211_ptr;
9467
Johannes Berg4c476992010-10-04 21:36:35 +02009468 if (!rdev->ops->set_power_mgmt)
9469 return -EOPNOTSUPP;
Kalle Valoffb9eb32010-02-17 17:58:10 +02009470
9471 state = (ps_state == NL80211_PS_ENABLED) ? true : false;
9472
9473 if (state == wdev->ps)
Johannes Berg4c476992010-10-04 21:36:35 +02009474 return 0;
Kalle Valoffb9eb32010-02-17 17:58:10 +02009475
Hila Gonene35e4d22012-06-27 17:19:42 +03009476 err = rdev_set_power_mgmt(rdev, dev, state, wdev->ps_timeout);
Johannes Berg4c476992010-10-04 21:36:35 +02009477 if (!err)
9478 wdev->ps = state;
Kalle Valoffb9eb32010-02-17 17:58:10 +02009479 return err;
9480}
9481
9482static int nl80211_get_power_save(struct sk_buff *skb, struct genl_info *info)
9483{
Johannes Berg4c476992010-10-04 21:36:35 +02009484 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Kalle Valoffb9eb32010-02-17 17:58:10 +02009485 enum nl80211_ps_state ps_state;
9486 struct wireless_dev *wdev;
Johannes Berg4c476992010-10-04 21:36:35 +02009487 struct net_device *dev = info->user_ptr[1];
Kalle Valoffb9eb32010-02-17 17:58:10 +02009488 struct sk_buff *msg;
9489 void *hdr;
9490 int err;
9491
Kalle Valoffb9eb32010-02-17 17:58:10 +02009492 wdev = dev->ieee80211_ptr;
9493
Johannes Berg4c476992010-10-04 21:36:35 +02009494 if (!rdev->ops->set_power_mgmt)
9495 return -EOPNOTSUPP;
Kalle Valoffb9eb32010-02-17 17:58:10 +02009496
9497 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02009498 if (!msg)
9499 return -ENOMEM;
Kalle Valoffb9eb32010-02-17 17:58:10 +02009500
Eric W. Biederman15e47302012-09-07 20:12:54 +00009501 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Kalle Valoffb9eb32010-02-17 17:58:10 +02009502 NL80211_CMD_GET_POWER_SAVE);
9503 if (!hdr) {
Johannes Berg4c476992010-10-04 21:36:35 +02009504 err = -ENOBUFS;
Kalle Valoffb9eb32010-02-17 17:58:10 +02009505 goto free_msg;
9506 }
9507
9508 if (wdev->ps)
9509 ps_state = NL80211_PS_ENABLED;
9510 else
9511 ps_state = NL80211_PS_DISABLED;
9512
David S. Miller9360ffd2012-03-29 04:41:26 -04009513 if (nla_put_u32(msg, NL80211_ATTR_PS_STATE, ps_state))
9514 goto nla_put_failure;
Kalle Valoffb9eb32010-02-17 17:58:10 +02009515
9516 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02009517 return genlmsg_reply(msg, info);
Kalle Valoffb9eb32010-02-17 17:58:10 +02009518
Johannes Berg4c476992010-10-04 21:36:35 +02009519 nla_put_failure:
Kalle Valoffb9eb32010-02-17 17:58:10 +02009520 err = -ENOBUFS;
Johannes Berg4c476992010-10-04 21:36:35 +02009521 free_msg:
Kalle Valoffb9eb32010-02-17 17:58:10 +02009522 nlmsg_free(msg);
Kalle Valoffb9eb32010-02-17 17:58:10 +02009523 return err;
9524}
9525
Johannes Berg94e860f2014-01-20 23:58:15 +01009526static const struct nla_policy
9527nl80211_attr_cqm_policy[NL80211_ATTR_CQM_MAX + 1] = {
Andrew Zaborowski4a4b8162017-02-10 10:02:31 +01009528 [NL80211_ATTR_CQM_RSSI_THOLD] = { .type = NLA_BINARY },
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02009529 [NL80211_ATTR_CQM_RSSI_HYST] = { .type = NLA_U32 },
9530 [NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT] = { .type = NLA_U32 },
Thomas Pedersen84f10702012-07-12 16:17:33 -07009531 [NL80211_ATTR_CQM_TXE_RATE] = { .type = NLA_U32 },
9532 [NL80211_ATTR_CQM_TXE_PKTS] = { .type = NLA_U32 },
9533 [NL80211_ATTR_CQM_TXE_INTVL] = { .type = NLA_U32 },
Andrzej Zaborowskibee427b2017-01-25 12:43:41 +01009534 [NL80211_ATTR_CQM_RSSI_LEVEL] = { .type = NLA_S32 },
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02009535};
9536
Thomas Pedersen84f10702012-07-12 16:17:33 -07009537static int nl80211_set_cqm_txe(struct genl_info *info,
Johannes Bergd9d8b012012-11-26 12:51:52 +01009538 u32 rate, u32 pkts, u32 intvl)
Thomas Pedersen84f10702012-07-12 16:17:33 -07009539{
9540 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Thomas Pedersen84f10702012-07-12 16:17:33 -07009541 struct net_device *dev = info->user_ptr[1];
Johannes Berg1da5fcc2013-08-06 14:10:48 +02009542 struct wireless_dev *wdev = dev->ieee80211_ptr;
Thomas Pedersen84f10702012-07-12 16:17:33 -07009543
Johannes Bergd9d8b012012-11-26 12:51:52 +01009544 if (rate > 100 || intvl > NL80211_CQM_TXE_MAX_INTVL)
Thomas Pedersen84f10702012-07-12 16:17:33 -07009545 return -EINVAL;
9546
Thomas Pedersen84f10702012-07-12 16:17:33 -07009547 if (!rdev->ops->set_cqm_txe_config)
9548 return -EOPNOTSUPP;
9549
9550 if (wdev->iftype != NL80211_IFTYPE_STATION &&
9551 wdev->iftype != NL80211_IFTYPE_P2P_CLIENT)
9552 return -EOPNOTSUPP;
9553
Hila Gonene35e4d22012-06-27 17:19:42 +03009554 return rdev_set_cqm_txe_config(rdev, dev, rate, pkts, intvl);
Thomas Pedersen84f10702012-07-12 16:17:33 -07009555}
9556
Andrew Zaborowski4a4b8162017-02-10 10:02:31 +01009557static int cfg80211_cqm_rssi_update(struct cfg80211_registered_device *rdev,
9558 struct net_device *dev)
9559{
9560 struct wireless_dev *wdev = dev->ieee80211_ptr;
9561 s32 last, low, high;
9562 u32 hyst;
9563 int i, n;
9564 int err;
9565
9566 /* RSSI reporting disabled? */
9567 if (!wdev->cqm_config)
9568 return rdev_set_cqm_rssi_range_config(rdev, dev, 0, 0);
9569
9570 /*
9571 * Obtain current RSSI value if possible, if not and no RSSI threshold
9572 * event has been received yet, we should receive an event after a
9573 * connection is established and enough beacons received to calculate
9574 * the average.
9575 */
9576 if (!wdev->cqm_config->last_rssi_event_value && wdev->current_bss &&
9577 rdev->ops->get_station) {
9578 struct station_info sinfo;
9579 u8 *mac_addr;
9580
9581 mac_addr = wdev->current_bss->pub.bssid;
9582
9583 err = rdev_get_station(rdev, dev, mac_addr, &sinfo);
9584 if (err)
9585 return err;
9586
9587 if (sinfo.filled & BIT(NL80211_STA_INFO_BEACON_SIGNAL_AVG))
9588 wdev->cqm_config->last_rssi_event_value =
9589 (s8) sinfo.rx_beacon_signal_avg;
9590 }
9591
9592 last = wdev->cqm_config->last_rssi_event_value;
9593 hyst = wdev->cqm_config->rssi_hyst;
9594 n = wdev->cqm_config->n_rssi_thresholds;
9595
9596 for (i = 0; i < n; i++)
9597 if (last < wdev->cqm_config->rssi_thresholds[i])
9598 break;
9599
9600 low = i > 0 ?
9601 (wdev->cqm_config->rssi_thresholds[i - 1] - hyst) : S32_MIN;
9602 high = i < n ?
9603 (wdev->cqm_config->rssi_thresholds[i] + hyst - 1) : S32_MAX;
9604
9605 return rdev_set_cqm_rssi_range_config(rdev, dev, low, high);
9606}
9607
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02009608static int nl80211_set_cqm_rssi(struct genl_info *info,
Andrew Zaborowski4a4b8162017-02-10 10:02:31 +01009609 const s32 *thresholds, int n_thresholds,
9610 u32 hysteresis)
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02009611{
Johannes Berg4c476992010-10-04 21:36:35 +02009612 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg4c476992010-10-04 21:36:35 +02009613 struct net_device *dev = info->user_ptr[1];
Johannes Berg1da5fcc2013-08-06 14:10:48 +02009614 struct wireless_dev *wdev = dev->ieee80211_ptr;
Andrew Zaborowski4a4b8162017-02-10 10:02:31 +01009615 int i, err;
9616 s32 prev = S32_MIN;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02009617
Andrew Zaborowski4a4b8162017-02-10 10:02:31 +01009618 /* Check all values negative and sorted */
9619 for (i = 0; i < n_thresholds; i++) {
9620 if (thresholds[i] > 0 || thresholds[i] <= prev)
9621 return -EINVAL;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02009622
Andrew Zaborowski4a4b8162017-02-10 10:02:31 +01009623 prev = thresholds[i];
9624 }
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02009625
Johannes Berg074ac8d2010-09-16 14:58:22 +02009626 if (wdev->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02009627 wdev->iftype != NL80211_IFTYPE_P2P_CLIENT)
9628 return -EOPNOTSUPP;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02009629
Andrew Zaborowski4a4b8162017-02-10 10:02:31 +01009630 wdev_lock(wdev);
9631 cfg80211_cqm_config_free(wdev);
9632 wdev_unlock(wdev);
9633
9634 if (n_thresholds <= 1 && rdev->ops->set_cqm_rssi_config) {
9635 if (n_thresholds == 0 || thresholds[0] == 0) /* Disabling */
9636 return rdev_set_cqm_rssi_config(rdev, dev, 0, 0);
9637
9638 return rdev_set_cqm_rssi_config(rdev, dev,
9639 thresholds[0], hysteresis);
9640 }
9641
9642 if (!wiphy_ext_feature_isset(&rdev->wiphy,
9643 NL80211_EXT_FEATURE_CQM_RSSI_LIST))
9644 return -EOPNOTSUPP;
9645
9646 if (n_thresholds == 1 && thresholds[0] == 0) /* Disabling */
9647 n_thresholds = 0;
9648
9649 wdev_lock(wdev);
9650 if (n_thresholds) {
9651 struct cfg80211_cqm_config *cqm_config;
9652
9653 cqm_config = kzalloc(sizeof(struct cfg80211_cqm_config) +
9654 n_thresholds * sizeof(s32), GFP_KERNEL);
9655 if (!cqm_config) {
9656 err = -ENOMEM;
9657 goto unlock;
9658 }
9659
9660 cqm_config->rssi_hyst = hysteresis;
9661 cqm_config->n_rssi_thresholds = n_thresholds;
9662 memcpy(cqm_config->rssi_thresholds, thresholds,
9663 n_thresholds * sizeof(s32));
9664
9665 wdev->cqm_config = cqm_config;
9666 }
9667
9668 err = cfg80211_cqm_rssi_update(rdev, dev);
9669
9670unlock:
9671 wdev_unlock(wdev);
9672
9673 return err;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02009674}
9675
9676static int nl80211_set_cqm(struct sk_buff *skb, struct genl_info *info)
9677{
9678 struct nlattr *attrs[NL80211_ATTR_CQM_MAX + 1];
9679 struct nlattr *cqm;
9680 int err;
9681
9682 cqm = info->attrs[NL80211_ATTR_CQM];
Johannes Berg1da5fcc2013-08-06 14:10:48 +02009683 if (!cqm)
9684 return -EINVAL;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02009685
9686 err = nla_parse_nested(attrs, NL80211_ATTR_CQM_MAX, cqm,
9687 nl80211_attr_cqm_policy);
9688 if (err)
Johannes Berg1da5fcc2013-08-06 14:10:48 +02009689 return err;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02009690
9691 if (attrs[NL80211_ATTR_CQM_RSSI_THOLD] &&
9692 attrs[NL80211_ATTR_CQM_RSSI_HYST]) {
Andrew Zaborowski4a4b8162017-02-10 10:02:31 +01009693 const s32 *thresholds =
9694 nla_data(attrs[NL80211_ATTR_CQM_RSSI_THOLD]);
9695 int len = nla_len(attrs[NL80211_ATTR_CQM_RSSI_THOLD]);
Johannes Berg1da5fcc2013-08-06 14:10:48 +02009696 u32 hysteresis = nla_get_u32(attrs[NL80211_ATTR_CQM_RSSI_HYST]);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02009697
Andrew Zaborowski4a4b8162017-02-10 10:02:31 +01009698 if (len % 4)
9699 return -EINVAL;
9700
9701 return nl80211_set_cqm_rssi(info, thresholds, len / 4,
9702 hysteresis);
Johannes Berg1da5fcc2013-08-06 14:10:48 +02009703 }
9704
9705 if (attrs[NL80211_ATTR_CQM_TXE_RATE] &&
9706 attrs[NL80211_ATTR_CQM_TXE_PKTS] &&
9707 attrs[NL80211_ATTR_CQM_TXE_INTVL]) {
9708 u32 rate = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_RATE]);
9709 u32 pkts = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_PKTS]);
9710 u32 intvl = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_INTVL]);
9711
9712 return nl80211_set_cqm_txe(info, rate, pkts, intvl);
9713 }
9714
9715 return -EINVAL;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02009716}
9717
Rostislav Lisovy6e0bd6c2014-11-03 10:33:18 +01009718static int nl80211_join_ocb(struct sk_buff *skb, struct genl_info *info)
9719{
9720 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9721 struct net_device *dev = info->user_ptr[1];
9722 struct ocb_setup setup = {};
9723 int err;
9724
9725 err = nl80211_parse_chandef(rdev, info, &setup.chandef);
9726 if (err)
9727 return err;
9728
9729 return cfg80211_join_ocb(rdev, dev, &setup);
9730}
9731
9732static int nl80211_leave_ocb(struct sk_buff *skb, struct genl_info *info)
9733{
9734 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9735 struct net_device *dev = info->user_ptr[1];
9736
9737 return cfg80211_leave_ocb(rdev, dev);
9738}
9739
Johannes Berg29cbe682010-12-03 09:20:44 +01009740static int nl80211_join_mesh(struct sk_buff *skb, struct genl_info *info)
9741{
9742 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9743 struct net_device *dev = info->user_ptr[1];
9744 struct mesh_config cfg;
Javier Cardonac80d5452010-12-16 17:37:49 -08009745 struct mesh_setup setup;
Johannes Berg29cbe682010-12-03 09:20:44 +01009746 int err;
9747
9748 /* start with default */
9749 memcpy(&cfg, &default_mesh_config, sizeof(cfg));
Javier Cardonac80d5452010-12-16 17:37:49 -08009750 memcpy(&setup, &default_mesh_setup, sizeof(setup));
Johannes Berg29cbe682010-12-03 09:20:44 +01009751
Javier Cardona24bdd9f2010-12-16 17:37:48 -08009752 if (info->attrs[NL80211_ATTR_MESH_CONFIG]) {
Johannes Berg29cbe682010-12-03 09:20:44 +01009753 /* and parse parameters if given */
Javier Cardona24bdd9f2010-12-16 17:37:48 -08009754 err = nl80211_parse_mesh_config(info, &cfg, NULL);
Johannes Berg29cbe682010-12-03 09:20:44 +01009755 if (err)
9756 return err;
9757 }
9758
9759 if (!info->attrs[NL80211_ATTR_MESH_ID] ||
9760 !nla_len(info->attrs[NL80211_ATTR_MESH_ID]))
9761 return -EINVAL;
9762
Javier Cardonac80d5452010-12-16 17:37:49 -08009763 setup.mesh_id = nla_data(info->attrs[NL80211_ATTR_MESH_ID]);
9764 setup.mesh_id_len = nla_len(info->attrs[NL80211_ATTR_MESH_ID]);
9765
Chun-Yeow Yeoh4bb62342011-11-24 17:15:20 -08009766 if (info->attrs[NL80211_ATTR_MCAST_RATE] &&
9767 !nl80211_parse_mcast_rate(rdev, setup.mcast_rate,
9768 nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE])))
9769 return -EINVAL;
9770
Marco Porsch9bdbf042013-01-07 16:04:51 +01009771 if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) {
9772 setup.beacon_interval =
9773 nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]);
Purushottam Kushwaha12d20fc92016-08-11 15:14:02 +05309774
Purushottam Kushwaha0c317a02016-10-12 18:26:51 +05309775 err = cfg80211_validate_beacon_int(rdev,
9776 NL80211_IFTYPE_MESH_POINT,
9777 setup.beacon_interval);
Purushottam Kushwaha12d20fc92016-08-11 15:14:02 +05309778 if (err)
9779 return err;
Marco Porsch9bdbf042013-01-07 16:04:51 +01009780 }
9781
9782 if (info->attrs[NL80211_ATTR_DTIM_PERIOD]) {
9783 setup.dtim_period =
9784 nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]);
9785 if (setup.dtim_period < 1 || setup.dtim_period > 100)
9786 return -EINVAL;
9787 }
9788
Javier Cardonac80d5452010-12-16 17:37:49 -08009789 if (info->attrs[NL80211_ATTR_MESH_SETUP]) {
9790 /* parse additional setup parameters if given */
9791 err = nl80211_parse_mesh_setup(info, &setup);
9792 if (err)
9793 return err;
9794 }
9795
Thomas Pedersend37bb182013-03-04 13:06:13 -08009796 if (setup.user_mpm)
9797 cfg.auto_open_plinks = false;
9798
Johannes Bergcc1d2802012-05-16 23:50:20 +02009799 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
Johannes Berg683b6d32012-11-08 21:25:48 +01009800 err = nl80211_parse_chandef(rdev, info, &setup.chandef);
9801 if (err)
9802 return err;
Johannes Bergcc1d2802012-05-16 23:50:20 +02009803 } else {
9804 /* cfg80211_join_mesh() will sort it out */
Johannes Berg683b6d32012-11-08 21:25:48 +01009805 setup.chandef.chan = NULL;
Johannes Bergcc1d2802012-05-16 23:50:20 +02009806 }
9807
Ashok Nagarajanffb3cf32013-06-03 10:33:36 -07009808 if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) {
9809 u8 *rates = nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
9810 int n_rates =
9811 nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
9812 struct ieee80211_supported_band *sband;
9813
9814 if (!setup.chandef.chan)
9815 return -EINVAL;
9816
9817 sband = rdev->wiphy.bands[setup.chandef.chan->band];
9818
9819 err = ieee80211_get_ratemask(sband, rates, n_rates,
9820 &setup.basic_rates);
9821 if (err)
9822 return err;
9823 }
9824
Johannes Berg8564e382016-09-19 09:44:44 +02009825 if (info->attrs[NL80211_ATTR_TX_RATES]) {
9826 err = nl80211_parse_tx_bitrate_mask(info, &setup.beacon_rate);
9827 if (err)
9828 return err;
9829
9830 err = validate_beacon_tx_rate(rdev, setup.chandef.chan->band,
9831 &setup.beacon_rate);
9832 if (err)
9833 return err;
9834 }
9835
Javier Cardonac80d5452010-12-16 17:37:49 -08009836 return cfg80211_join_mesh(rdev, dev, &setup, &cfg);
Johannes Berg29cbe682010-12-03 09:20:44 +01009837}
9838
9839static int nl80211_leave_mesh(struct sk_buff *skb, struct genl_info *info)
9840{
9841 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9842 struct net_device *dev = info->user_ptr[1];
9843
9844 return cfg80211_leave_mesh(rdev, dev);
9845}
9846
Johannes Bergdfb89c52012-06-27 09:23:48 +02009847#ifdef CONFIG_PM
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08009848static int nl80211_send_wowlan_patterns(struct sk_buff *msg,
9849 struct cfg80211_registered_device *rdev)
9850{
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009851 struct cfg80211_wowlan *wowlan = rdev->wiphy.wowlan_config;
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08009852 struct nlattr *nl_pats, *nl_pat;
9853 int i, pat_len;
9854
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009855 if (!wowlan->n_patterns)
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08009856 return 0;
9857
9858 nl_pats = nla_nest_start(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN);
9859 if (!nl_pats)
9860 return -ENOBUFS;
9861
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009862 for (i = 0; i < wowlan->n_patterns; i++) {
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08009863 nl_pat = nla_nest_start(msg, i + 1);
9864 if (!nl_pat)
9865 return -ENOBUFS;
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009866 pat_len = wowlan->patterns[i].pattern_len;
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07009867 if (nla_put(msg, NL80211_PKTPAT_MASK, DIV_ROUND_UP(pat_len, 8),
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009868 wowlan->patterns[i].mask) ||
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07009869 nla_put(msg, NL80211_PKTPAT_PATTERN, pat_len,
9870 wowlan->patterns[i].pattern) ||
9871 nla_put_u32(msg, NL80211_PKTPAT_OFFSET,
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009872 wowlan->patterns[i].pkt_offset))
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08009873 return -ENOBUFS;
9874 nla_nest_end(msg, nl_pat);
9875 }
9876 nla_nest_end(msg, nl_pats);
9877
9878 return 0;
9879}
9880
Johannes Berg2a0e0472013-01-23 22:57:40 +01009881static int nl80211_send_wowlan_tcp(struct sk_buff *msg,
9882 struct cfg80211_wowlan_tcp *tcp)
9883{
9884 struct nlattr *nl_tcp;
9885
9886 if (!tcp)
9887 return 0;
9888
9889 nl_tcp = nla_nest_start(msg, NL80211_WOWLAN_TRIG_TCP_CONNECTION);
9890 if (!nl_tcp)
9891 return -ENOBUFS;
9892
Jiri Benc930345e2015-03-29 16:59:25 +02009893 if (nla_put_in_addr(msg, NL80211_WOWLAN_TCP_SRC_IPV4, tcp->src) ||
9894 nla_put_in_addr(msg, NL80211_WOWLAN_TCP_DST_IPV4, tcp->dst) ||
Johannes Berg2a0e0472013-01-23 22:57:40 +01009895 nla_put(msg, NL80211_WOWLAN_TCP_DST_MAC, ETH_ALEN, tcp->dst_mac) ||
9896 nla_put_u16(msg, NL80211_WOWLAN_TCP_SRC_PORT, tcp->src_port) ||
9897 nla_put_u16(msg, NL80211_WOWLAN_TCP_DST_PORT, tcp->dst_port) ||
9898 nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD,
9899 tcp->payload_len, tcp->payload) ||
9900 nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_INTERVAL,
9901 tcp->data_interval) ||
9902 nla_put(msg, NL80211_WOWLAN_TCP_WAKE_PAYLOAD,
9903 tcp->wake_len, tcp->wake_data) ||
9904 nla_put(msg, NL80211_WOWLAN_TCP_WAKE_MASK,
9905 DIV_ROUND_UP(tcp->wake_len, 8), tcp->wake_mask))
9906 return -ENOBUFS;
9907
9908 if (tcp->payload_seq.len &&
9909 nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ,
9910 sizeof(tcp->payload_seq), &tcp->payload_seq))
9911 return -ENOBUFS;
9912
9913 if (tcp->payload_tok.len &&
9914 nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN,
9915 sizeof(tcp->payload_tok) + tcp->tokens_size,
9916 &tcp->payload_tok))
9917 return -ENOBUFS;
9918
Johannes Berge248ad32013-05-16 10:24:28 +02009919 nla_nest_end(msg, nl_tcp);
9920
Johannes Berg2a0e0472013-01-23 22:57:40 +01009921 return 0;
9922}
9923
Luciano Coelho75453cc2015-01-09 14:06:37 +02009924static int nl80211_send_wowlan_nd(struct sk_buff *msg,
9925 struct cfg80211_sched_scan_request *req)
9926{
Avraham Stern3b06d272015-10-12 09:51:34 +03009927 struct nlattr *nd, *freqs, *matches, *match, *scan_plans, *scan_plan;
Luciano Coelho75453cc2015-01-09 14:06:37 +02009928 int i;
9929
9930 if (!req)
9931 return 0;
9932
9933 nd = nla_nest_start(msg, NL80211_WOWLAN_TRIG_NET_DETECT);
9934 if (!nd)
9935 return -ENOBUFS;
9936
Avraham Stern3b06d272015-10-12 09:51:34 +03009937 if (req->n_scan_plans == 1 &&
9938 nla_put_u32(msg, NL80211_ATTR_SCHED_SCAN_INTERVAL,
9939 req->scan_plans[0].interval * 1000))
Luciano Coelho75453cc2015-01-09 14:06:37 +02009940 return -ENOBUFS;
9941
Luciano Coelho21fea562015-03-17 16:36:01 +02009942 if (nla_put_u32(msg, NL80211_ATTR_SCHED_SCAN_DELAY, req->delay))
9943 return -ENOBUFS;
9944
vamsi krishnabf95ecd2017-01-13 01:12:20 +02009945 if (req->relative_rssi_set) {
9946 struct nl80211_bss_select_rssi_adjust rssi_adjust;
9947
9948 if (nla_put_s8(msg, NL80211_ATTR_SCHED_SCAN_RELATIVE_RSSI,
9949 req->relative_rssi))
9950 return -ENOBUFS;
9951
9952 rssi_adjust.band = req->rssi_adjust.band;
9953 rssi_adjust.delta = req->rssi_adjust.delta;
9954 if (nla_put(msg, NL80211_ATTR_SCHED_SCAN_RSSI_ADJUST,
9955 sizeof(rssi_adjust), &rssi_adjust))
9956 return -ENOBUFS;
9957 }
9958
Luciano Coelho75453cc2015-01-09 14:06:37 +02009959 freqs = nla_nest_start(msg, NL80211_ATTR_SCAN_FREQUENCIES);
9960 if (!freqs)
9961 return -ENOBUFS;
9962
Johannes Berg53b18982016-09-14 09:59:21 +02009963 for (i = 0; i < req->n_channels; i++) {
9964 if (nla_put_u32(msg, i, req->channels[i]->center_freq))
9965 return -ENOBUFS;
9966 }
Luciano Coelho75453cc2015-01-09 14:06:37 +02009967
9968 nla_nest_end(msg, freqs);
9969
9970 if (req->n_match_sets) {
9971 matches = nla_nest_start(msg, NL80211_ATTR_SCHED_SCAN_MATCH);
Johannes Berg76e1fb42016-09-14 09:55:57 +02009972 if (!matches)
9973 return -ENOBUFS;
9974
Luciano Coelho75453cc2015-01-09 14:06:37 +02009975 for (i = 0; i < req->n_match_sets; i++) {
9976 match = nla_nest_start(msg, i);
Johannes Berg76e1fb42016-09-14 09:55:57 +02009977 if (!match)
9978 return -ENOBUFS;
9979
Johannes Berg53b18982016-09-14 09:59:21 +02009980 if (nla_put(msg, NL80211_SCHED_SCAN_MATCH_ATTR_SSID,
9981 req->match_sets[i].ssid.ssid_len,
9982 req->match_sets[i].ssid.ssid))
9983 return -ENOBUFS;
Luciano Coelho75453cc2015-01-09 14:06:37 +02009984 nla_nest_end(msg, match);
9985 }
9986 nla_nest_end(msg, matches);
9987 }
9988
Avraham Stern3b06d272015-10-12 09:51:34 +03009989 scan_plans = nla_nest_start(msg, NL80211_ATTR_SCHED_SCAN_PLANS);
9990 if (!scan_plans)
9991 return -ENOBUFS;
9992
9993 for (i = 0; i < req->n_scan_plans; i++) {
9994 scan_plan = nla_nest_start(msg, i + 1);
Johannes Berg76e1fb42016-09-14 09:55:57 +02009995 if (!scan_plan)
9996 return -ENOBUFS;
9997
Avraham Stern3b06d272015-10-12 09:51:34 +03009998 if (!scan_plan ||
9999 nla_put_u32(msg, NL80211_SCHED_SCAN_PLAN_INTERVAL,
10000 req->scan_plans[i].interval) ||
10001 (req->scan_plans[i].iterations &&
10002 nla_put_u32(msg, NL80211_SCHED_SCAN_PLAN_ITERATIONS,
10003 req->scan_plans[i].iterations)))
10004 return -ENOBUFS;
10005 nla_nest_end(msg, scan_plan);
10006 }
10007 nla_nest_end(msg, scan_plans);
10008
Luciano Coelho75453cc2015-01-09 14:06:37 +020010009 nla_nest_end(msg, nd);
10010
10011 return 0;
10012}
10013
Johannes Bergff1b6e62011-05-04 15:37:28 +020010014static int nl80211_get_wowlan(struct sk_buff *skb, struct genl_info *info)
10015{
10016 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10017 struct sk_buff *msg;
10018 void *hdr;
Johannes Berg2a0e0472013-01-23 22:57:40 +010010019 u32 size = NLMSG_DEFAULT_SIZE;
Johannes Bergff1b6e62011-05-04 15:37:28 +020010020
Johannes Berg964dc9e2013-06-03 17:25:34 +020010021 if (!rdev->wiphy.wowlan)
Johannes Bergff1b6e62011-05-04 15:37:28 +020010022 return -EOPNOTSUPP;
10023
Johannes Berg6abb9cb2013-05-15 09:30:07 +020010024 if (rdev->wiphy.wowlan_config && rdev->wiphy.wowlan_config->tcp) {
Johannes Berg2a0e0472013-01-23 22:57:40 +010010025 /* adjust size to have room for all the data */
Johannes Berg6abb9cb2013-05-15 09:30:07 +020010026 size += rdev->wiphy.wowlan_config->tcp->tokens_size +
10027 rdev->wiphy.wowlan_config->tcp->payload_len +
10028 rdev->wiphy.wowlan_config->tcp->wake_len +
10029 rdev->wiphy.wowlan_config->tcp->wake_len / 8;
Johannes Berg2a0e0472013-01-23 22:57:40 +010010030 }
10031
10032 msg = nlmsg_new(size, GFP_KERNEL);
Johannes Bergff1b6e62011-05-04 15:37:28 +020010033 if (!msg)
10034 return -ENOMEM;
10035
Eric W. Biederman15e47302012-09-07 20:12:54 +000010036 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Johannes Bergff1b6e62011-05-04 15:37:28 +020010037 NL80211_CMD_GET_WOWLAN);
10038 if (!hdr)
10039 goto nla_put_failure;
10040
Johannes Berg6abb9cb2013-05-15 09:30:07 +020010041 if (rdev->wiphy.wowlan_config) {
Johannes Bergff1b6e62011-05-04 15:37:28 +020010042 struct nlattr *nl_wowlan;
10043
10044 nl_wowlan = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS);
10045 if (!nl_wowlan)
10046 goto nla_put_failure;
10047
Johannes Berg6abb9cb2013-05-15 09:30:07 +020010048 if ((rdev->wiphy.wowlan_config->any &&
David S. Miller9360ffd2012-03-29 04:41:26 -040010049 nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +020010050 (rdev->wiphy.wowlan_config->disconnect &&
David S. Miller9360ffd2012-03-29 04:41:26 -040010051 nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +020010052 (rdev->wiphy.wowlan_config->magic_pkt &&
David S. Miller9360ffd2012-03-29 04:41:26 -040010053 nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +020010054 (rdev->wiphy.wowlan_config->gtk_rekey_failure &&
David S. Miller9360ffd2012-03-29 04:41:26 -040010055 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +020010056 (rdev->wiphy.wowlan_config->eap_identity_req &&
David S. Miller9360ffd2012-03-29 04:41:26 -040010057 nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +020010058 (rdev->wiphy.wowlan_config->four_way_handshake &&
David S. Miller9360ffd2012-03-29 04:41:26 -040010059 nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +020010060 (rdev->wiphy.wowlan_config->rfkill_release &&
David S. Miller9360ffd2012-03-29 04:41:26 -040010061 nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE)))
10062 goto nla_put_failure;
Johannes Berg2a0e0472013-01-23 22:57:40 +010010063
Amitkumar Karwarbb92d192013-02-12 12:16:26 -080010064 if (nl80211_send_wowlan_patterns(msg, rdev))
10065 goto nla_put_failure;
Johannes Berg2a0e0472013-01-23 22:57:40 +010010066
Johannes Berg6abb9cb2013-05-15 09:30:07 +020010067 if (nl80211_send_wowlan_tcp(msg,
10068 rdev->wiphy.wowlan_config->tcp))
Johannes Berg2a0e0472013-01-23 22:57:40 +010010069 goto nla_put_failure;
10070
Luciano Coelho75453cc2015-01-09 14:06:37 +020010071 if (nl80211_send_wowlan_nd(
10072 msg,
10073 rdev->wiphy.wowlan_config->nd_config))
10074 goto nla_put_failure;
10075
Johannes Bergff1b6e62011-05-04 15:37:28 +020010076 nla_nest_end(msg, nl_wowlan);
10077 }
10078
10079 genlmsg_end(msg, hdr);
10080 return genlmsg_reply(msg, info);
10081
10082nla_put_failure:
10083 nlmsg_free(msg);
10084 return -ENOBUFS;
10085}
10086
Johannes Berg2a0e0472013-01-23 22:57:40 +010010087static int nl80211_parse_wowlan_tcp(struct cfg80211_registered_device *rdev,
10088 struct nlattr *attr,
10089 struct cfg80211_wowlan *trig)
10090{
10091 struct nlattr *tb[NUM_NL80211_WOWLAN_TCP];
10092 struct cfg80211_wowlan_tcp *cfg;
10093 struct nl80211_wowlan_tcp_data_token *tok = NULL;
10094 struct nl80211_wowlan_tcp_data_seq *seq = NULL;
10095 u32 size;
10096 u32 data_size, wake_size, tokens_size = 0, wake_mask_size;
10097 int err, port;
10098
Johannes Berg964dc9e2013-06-03 17:25:34 +020010099 if (!rdev->wiphy.wowlan->tcp)
Johannes Berg2a0e0472013-01-23 22:57:40 +010010100 return -EINVAL;
10101
Johannes Bergbfe2c7b2016-10-26 14:42:21 +020010102 err = nla_parse_nested(tb, MAX_NL80211_WOWLAN_TCP, attr,
10103 nl80211_wowlan_tcp_policy);
Johannes Berg2a0e0472013-01-23 22:57:40 +010010104 if (err)
10105 return err;
10106
10107 if (!tb[NL80211_WOWLAN_TCP_SRC_IPV4] ||
10108 !tb[NL80211_WOWLAN_TCP_DST_IPV4] ||
10109 !tb[NL80211_WOWLAN_TCP_DST_MAC] ||
10110 !tb[NL80211_WOWLAN_TCP_DST_PORT] ||
10111 !tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD] ||
10112 !tb[NL80211_WOWLAN_TCP_DATA_INTERVAL] ||
10113 !tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD] ||
10114 !tb[NL80211_WOWLAN_TCP_WAKE_MASK])
10115 return -EINVAL;
10116
10117 data_size = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]);
Johannes Berg964dc9e2013-06-03 17:25:34 +020010118 if (data_size > rdev->wiphy.wowlan->tcp->data_payload_max)
Johannes Berg2a0e0472013-01-23 22:57:40 +010010119 return -EINVAL;
10120
10121 if (nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]) >
Johannes Berg964dc9e2013-06-03 17:25:34 +020010122 rdev->wiphy.wowlan->tcp->data_interval_max ||
Johannes Berg723d5682013-02-26 13:56:40 +010010123 nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]) == 0)
Johannes Berg2a0e0472013-01-23 22:57:40 +010010124 return -EINVAL;
10125
10126 wake_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]);
Johannes Berg964dc9e2013-06-03 17:25:34 +020010127 if (wake_size > rdev->wiphy.wowlan->tcp->wake_payload_max)
Johannes Berg2a0e0472013-01-23 22:57:40 +010010128 return -EINVAL;
10129
10130 wake_mask_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_MASK]);
10131 if (wake_mask_size != DIV_ROUND_UP(wake_size, 8))
10132 return -EINVAL;
10133
10134 if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]) {
10135 u32 tokln = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]);
10136
10137 tok = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]);
10138 tokens_size = tokln - sizeof(*tok);
10139
10140 if (!tok->len || tokens_size % tok->len)
10141 return -EINVAL;
Johannes Berg964dc9e2013-06-03 17:25:34 +020010142 if (!rdev->wiphy.wowlan->tcp->tok)
Johannes Berg2a0e0472013-01-23 22:57:40 +010010143 return -EINVAL;
Johannes Berg964dc9e2013-06-03 17:25:34 +020010144 if (tok->len > rdev->wiphy.wowlan->tcp->tok->max_len)
Johannes Berg2a0e0472013-01-23 22:57:40 +010010145 return -EINVAL;
Johannes Berg964dc9e2013-06-03 17:25:34 +020010146 if (tok->len < rdev->wiphy.wowlan->tcp->tok->min_len)
Johannes Berg2a0e0472013-01-23 22:57:40 +010010147 return -EINVAL;
Johannes Berg964dc9e2013-06-03 17:25:34 +020010148 if (tokens_size > rdev->wiphy.wowlan->tcp->tok->bufsize)
Johannes Berg2a0e0472013-01-23 22:57:40 +010010149 return -EINVAL;
10150 if (tok->offset + tok->len > data_size)
10151 return -EINVAL;
10152 }
10153
10154 if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]) {
10155 seq = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]);
Johannes Berg964dc9e2013-06-03 17:25:34 +020010156 if (!rdev->wiphy.wowlan->tcp->seq)
Johannes Berg2a0e0472013-01-23 22:57:40 +010010157 return -EINVAL;
10158 if (seq->len == 0 || seq->len > 4)
10159 return -EINVAL;
10160 if (seq->len + seq->offset > data_size)
10161 return -EINVAL;
10162 }
10163
10164 size = sizeof(*cfg);
10165 size += data_size;
10166 size += wake_size + wake_mask_size;
10167 size += tokens_size;
10168
10169 cfg = kzalloc(size, GFP_KERNEL);
10170 if (!cfg)
10171 return -ENOMEM;
Jiri Benc67b61f62015-03-29 16:59:26 +020010172 cfg->src = nla_get_in_addr(tb[NL80211_WOWLAN_TCP_SRC_IPV4]);
10173 cfg->dst = nla_get_in_addr(tb[NL80211_WOWLAN_TCP_DST_IPV4]);
Johannes Berg2a0e0472013-01-23 22:57:40 +010010174 memcpy(cfg->dst_mac, nla_data(tb[NL80211_WOWLAN_TCP_DST_MAC]),
10175 ETH_ALEN);
10176 if (tb[NL80211_WOWLAN_TCP_SRC_PORT])
10177 port = nla_get_u16(tb[NL80211_WOWLAN_TCP_SRC_PORT]);
10178 else
10179 port = 0;
10180#ifdef CONFIG_INET
10181 /* allocate a socket and port for it and use it */
10182 err = __sock_create(wiphy_net(&rdev->wiphy), PF_INET, SOCK_STREAM,
10183 IPPROTO_TCP, &cfg->sock, 1);
10184 if (err) {
10185 kfree(cfg);
10186 return err;
10187 }
10188 if (inet_csk_get_port(cfg->sock->sk, port)) {
10189 sock_release(cfg->sock);
10190 kfree(cfg);
10191 return -EADDRINUSE;
10192 }
10193 cfg->src_port = inet_sk(cfg->sock->sk)->inet_num;
10194#else
10195 if (!port) {
10196 kfree(cfg);
10197 return -EINVAL;
10198 }
10199 cfg->src_port = port;
10200#endif
10201
10202 cfg->dst_port = nla_get_u16(tb[NL80211_WOWLAN_TCP_DST_PORT]);
10203 cfg->payload_len = data_size;
10204 cfg->payload = (u8 *)cfg + sizeof(*cfg) + tokens_size;
10205 memcpy((void *)cfg->payload,
10206 nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]),
10207 data_size);
10208 if (seq)
10209 cfg->payload_seq = *seq;
10210 cfg->data_interval = nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]);
10211 cfg->wake_len = wake_size;
10212 cfg->wake_data = (u8 *)cfg + sizeof(*cfg) + tokens_size + data_size;
10213 memcpy((void *)cfg->wake_data,
10214 nla_data(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]),
10215 wake_size);
10216 cfg->wake_mask = (u8 *)cfg + sizeof(*cfg) + tokens_size +
10217 data_size + wake_size;
10218 memcpy((void *)cfg->wake_mask,
10219 nla_data(tb[NL80211_WOWLAN_TCP_WAKE_MASK]),
10220 wake_mask_size);
10221 if (tok) {
10222 cfg->tokens_size = tokens_size;
10223 memcpy(&cfg->payload_tok, tok, sizeof(*tok) + tokens_size);
10224 }
10225
10226 trig->tcp = cfg;
10227
10228 return 0;
10229}
10230
Luciano Coelho8cd4d452014-09-17 11:55:28 +030010231static int nl80211_parse_wowlan_nd(struct cfg80211_registered_device *rdev,
10232 const struct wiphy_wowlan_support *wowlan,
10233 struct nlattr *attr,
10234 struct cfg80211_wowlan *trig)
10235{
10236 struct nlattr **tb;
10237 int err;
10238
10239 tb = kzalloc(NUM_NL80211_ATTR * sizeof(*tb), GFP_KERNEL);
10240 if (!tb)
10241 return -ENOMEM;
10242
10243 if (!(wowlan->flags & WIPHY_WOWLAN_NET_DETECT)) {
10244 err = -EOPNOTSUPP;
10245 goto out;
10246 }
10247
Johannes Bergbfe2c7b2016-10-26 14:42:21 +020010248 err = nla_parse_nested(tb, NL80211_ATTR_MAX, attr, nl80211_policy);
Luciano Coelho8cd4d452014-09-17 11:55:28 +030010249 if (err)
10250 goto out;
10251
Arend Van Sprielaad1e812017-01-27 12:27:44 +000010252 trig->nd_config = nl80211_parse_sched_scan(&rdev->wiphy, NULL, tb,
10253 wowlan->max_nd_match_sets);
Luciano Coelho8cd4d452014-09-17 11:55:28 +030010254 err = PTR_ERR_OR_ZERO(trig->nd_config);
10255 if (err)
10256 trig->nd_config = NULL;
10257
10258out:
10259 kfree(tb);
10260 return err;
10261}
10262
Johannes Bergff1b6e62011-05-04 15:37:28 +020010263static int nl80211_set_wowlan(struct sk_buff *skb, struct genl_info *info)
10264{
10265 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10266 struct nlattr *tb[NUM_NL80211_WOWLAN_TRIG];
Johannes Bergff1b6e62011-05-04 15:37:28 +020010267 struct cfg80211_wowlan new_triggers = {};
Johannes Bergae33bd82012-07-12 16:25:02 +020010268 struct cfg80211_wowlan *ntrig;
Johannes Berg964dc9e2013-06-03 17:25:34 +020010269 const struct wiphy_wowlan_support *wowlan = rdev->wiphy.wowlan;
Johannes Bergff1b6e62011-05-04 15:37:28 +020010270 int err, i;
Johannes Berg6abb9cb2013-05-15 09:30:07 +020010271 bool prev_enabled = rdev->wiphy.wowlan_config;
Johannes Berg98fc4382015-03-01 09:10:13 +020010272 bool regular = false;
Johannes Bergff1b6e62011-05-04 15:37:28 +020010273
Johannes Berg964dc9e2013-06-03 17:25:34 +020010274 if (!wowlan)
Johannes Bergff1b6e62011-05-04 15:37:28 +020010275 return -EOPNOTSUPP;
10276
Johannes Bergae33bd82012-07-12 16:25:02 +020010277 if (!info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]) {
10278 cfg80211_rdev_free_wowlan(rdev);
Johannes Berg6abb9cb2013-05-15 09:30:07 +020010279 rdev->wiphy.wowlan_config = NULL;
Johannes Bergae33bd82012-07-12 16:25:02 +020010280 goto set_wakeup;
10281 }
Johannes Bergff1b6e62011-05-04 15:37:28 +020010282
Johannes Bergbfe2c7b2016-10-26 14:42:21 +020010283 err = nla_parse_nested(tb, MAX_NL80211_WOWLAN_TRIG,
10284 info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS],
10285 nl80211_wowlan_policy);
Johannes Bergff1b6e62011-05-04 15:37:28 +020010286 if (err)
10287 return err;
10288
10289 if (tb[NL80211_WOWLAN_TRIG_ANY]) {
10290 if (!(wowlan->flags & WIPHY_WOWLAN_ANY))
10291 return -EINVAL;
10292 new_triggers.any = true;
10293 }
10294
10295 if (tb[NL80211_WOWLAN_TRIG_DISCONNECT]) {
10296 if (!(wowlan->flags & WIPHY_WOWLAN_DISCONNECT))
10297 return -EINVAL;
10298 new_triggers.disconnect = true;
Johannes Berg98fc4382015-03-01 09:10:13 +020010299 regular = true;
Johannes Bergff1b6e62011-05-04 15:37:28 +020010300 }
10301
10302 if (tb[NL80211_WOWLAN_TRIG_MAGIC_PKT]) {
10303 if (!(wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT))
10304 return -EINVAL;
10305 new_triggers.magic_pkt = true;
Johannes Berg98fc4382015-03-01 09:10:13 +020010306 regular = true;
Johannes Bergff1b6e62011-05-04 15:37:28 +020010307 }
10308
Johannes Berg77dbbb12011-07-13 10:48:55 +020010309 if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED])
10310 return -EINVAL;
10311
10312 if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE]) {
10313 if (!(wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE))
10314 return -EINVAL;
10315 new_triggers.gtk_rekey_failure = true;
Johannes Berg98fc4382015-03-01 09:10:13 +020010316 regular = true;
Johannes Berg77dbbb12011-07-13 10:48:55 +020010317 }
10318
10319 if (tb[NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST]) {
10320 if (!(wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ))
10321 return -EINVAL;
10322 new_triggers.eap_identity_req = true;
Johannes Berg98fc4382015-03-01 09:10:13 +020010323 regular = true;
Johannes Berg77dbbb12011-07-13 10:48:55 +020010324 }
10325
10326 if (tb[NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE]) {
10327 if (!(wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE))
10328 return -EINVAL;
10329 new_triggers.four_way_handshake = true;
Johannes Berg98fc4382015-03-01 09:10:13 +020010330 regular = true;
Johannes Berg77dbbb12011-07-13 10:48:55 +020010331 }
10332
10333 if (tb[NL80211_WOWLAN_TRIG_RFKILL_RELEASE]) {
10334 if (!(wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE))
10335 return -EINVAL;
10336 new_triggers.rfkill_release = true;
Johannes Berg98fc4382015-03-01 09:10:13 +020010337 regular = true;
Johannes Berg77dbbb12011-07-13 10:48:55 +020010338 }
10339
Johannes Bergff1b6e62011-05-04 15:37:28 +020010340 if (tb[NL80211_WOWLAN_TRIG_PKT_PATTERN]) {
10341 struct nlattr *pat;
10342 int n_patterns = 0;
Amitkumar Karwarbb92d192013-02-12 12:16:26 -080010343 int rem, pat_len, mask_len, pkt_offset;
Amitkumar Karwar50ac6602013-06-25 19:03:56 -070010344 struct nlattr *pat_tb[NUM_NL80211_PKTPAT];
Johannes Bergff1b6e62011-05-04 15:37:28 +020010345
Johannes Berg98fc4382015-03-01 09:10:13 +020010346 regular = true;
10347
Johannes Bergff1b6e62011-05-04 15:37:28 +020010348 nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN],
10349 rem)
10350 n_patterns++;
10351 if (n_patterns > wowlan->n_patterns)
10352 return -EINVAL;
10353
10354 new_triggers.patterns = kcalloc(n_patterns,
10355 sizeof(new_triggers.patterns[0]),
10356 GFP_KERNEL);
10357 if (!new_triggers.patterns)
10358 return -ENOMEM;
10359
10360 new_triggers.n_patterns = n_patterns;
10361 i = 0;
10362
10363 nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN],
10364 rem) {
Johannes Berg922bd802014-05-19 17:59:50 +020010365 u8 *mask_pat;
10366
Johannes Bergbfe2c7b2016-10-26 14:42:21 +020010367 nla_parse_nested(pat_tb, MAX_NL80211_PKTPAT, pat,
10368 NULL);
Johannes Bergff1b6e62011-05-04 15:37:28 +020010369 err = -EINVAL;
Amitkumar Karwar50ac6602013-06-25 19:03:56 -070010370 if (!pat_tb[NL80211_PKTPAT_MASK] ||
10371 !pat_tb[NL80211_PKTPAT_PATTERN])
Johannes Bergff1b6e62011-05-04 15:37:28 +020010372 goto error;
Amitkumar Karwar50ac6602013-06-25 19:03:56 -070010373 pat_len = nla_len(pat_tb[NL80211_PKTPAT_PATTERN]);
Johannes Bergff1b6e62011-05-04 15:37:28 +020010374 mask_len = DIV_ROUND_UP(pat_len, 8);
Amitkumar Karwar50ac6602013-06-25 19:03:56 -070010375 if (nla_len(pat_tb[NL80211_PKTPAT_MASK]) != mask_len)
Johannes Bergff1b6e62011-05-04 15:37:28 +020010376 goto error;
10377 if (pat_len > wowlan->pattern_max_len ||
10378 pat_len < wowlan->pattern_min_len)
10379 goto error;
10380
Amitkumar Karwar50ac6602013-06-25 19:03:56 -070010381 if (!pat_tb[NL80211_PKTPAT_OFFSET])
Amitkumar Karwarbb92d192013-02-12 12:16:26 -080010382 pkt_offset = 0;
10383 else
10384 pkt_offset = nla_get_u32(
Amitkumar Karwar50ac6602013-06-25 19:03:56 -070010385 pat_tb[NL80211_PKTPAT_OFFSET]);
Amitkumar Karwarbb92d192013-02-12 12:16:26 -080010386 if (pkt_offset > wowlan->max_pkt_offset)
10387 goto error;
10388 new_triggers.patterns[i].pkt_offset = pkt_offset;
10389
Johannes Berg922bd802014-05-19 17:59:50 +020010390 mask_pat = kmalloc(mask_len + pat_len, GFP_KERNEL);
10391 if (!mask_pat) {
Johannes Bergff1b6e62011-05-04 15:37:28 +020010392 err = -ENOMEM;
10393 goto error;
10394 }
Johannes Berg922bd802014-05-19 17:59:50 +020010395 new_triggers.patterns[i].mask = mask_pat;
10396 memcpy(mask_pat, nla_data(pat_tb[NL80211_PKTPAT_MASK]),
Johannes Bergff1b6e62011-05-04 15:37:28 +020010397 mask_len);
Johannes Berg922bd802014-05-19 17:59:50 +020010398 mask_pat += mask_len;
10399 new_triggers.patterns[i].pattern = mask_pat;
Johannes Bergff1b6e62011-05-04 15:37:28 +020010400 new_triggers.patterns[i].pattern_len = pat_len;
Johannes Berg922bd802014-05-19 17:59:50 +020010401 memcpy(mask_pat,
Amitkumar Karwar50ac6602013-06-25 19:03:56 -070010402 nla_data(pat_tb[NL80211_PKTPAT_PATTERN]),
Johannes Bergff1b6e62011-05-04 15:37:28 +020010403 pat_len);
10404 i++;
10405 }
10406 }
10407
Johannes Berg2a0e0472013-01-23 22:57:40 +010010408 if (tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION]) {
Johannes Berg98fc4382015-03-01 09:10:13 +020010409 regular = true;
Johannes Berg2a0e0472013-01-23 22:57:40 +010010410 err = nl80211_parse_wowlan_tcp(
10411 rdev, tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION],
10412 &new_triggers);
10413 if (err)
10414 goto error;
10415 }
10416
Luciano Coelho8cd4d452014-09-17 11:55:28 +030010417 if (tb[NL80211_WOWLAN_TRIG_NET_DETECT]) {
Johannes Berg98fc4382015-03-01 09:10:13 +020010418 regular = true;
Luciano Coelho8cd4d452014-09-17 11:55:28 +030010419 err = nl80211_parse_wowlan_nd(
10420 rdev, wowlan, tb[NL80211_WOWLAN_TRIG_NET_DETECT],
10421 &new_triggers);
10422 if (err)
10423 goto error;
10424 }
10425
Johannes Berg98fc4382015-03-01 09:10:13 +020010426 /* The 'any' trigger means the device continues operating more or less
10427 * as in its normal operation mode and wakes up the host on most of the
10428 * normal interrupts (like packet RX, ...)
10429 * It therefore makes little sense to combine with the more constrained
10430 * wakeup trigger modes.
10431 */
10432 if (new_triggers.any && regular) {
10433 err = -EINVAL;
10434 goto error;
10435 }
10436
Johannes Bergae33bd82012-07-12 16:25:02 +020010437 ntrig = kmemdup(&new_triggers, sizeof(new_triggers), GFP_KERNEL);
10438 if (!ntrig) {
10439 err = -ENOMEM;
10440 goto error;
Johannes Bergff1b6e62011-05-04 15:37:28 +020010441 }
Johannes Bergae33bd82012-07-12 16:25:02 +020010442 cfg80211_rdev_free_wowlan(rdev);
Johannes Berg6abb9cb2013-05-15 09:30:07 +020010443 rdev->wiphy.wowlan_config = ntrig;
Johannes Bergff1b6e62011-05-04 15:37:28 +020010444
Johannes Bergae33bd82012-07-12 16:25:02 +020010445 set_wakeup:
Johannes Berg6abb9cb2013-05-15 09:30:07 +020010446 if (rdev->ops->set_wakeup &&
10447 prev_enabled != !!rdev->wiphy.wowlan_config)
10448 rdev_set_wakeup(rdev, rdev->wiphy.wowlan_config);
Johannes Berg6d525632012-04-04 15:05:25 +020010449
Johannes Bergff1b6e62011-05-04 15:37:28 +020010450 return 0;
10451 error:
10452 for (i = 0; i < new_triggers.n_patterns; i++)
10453 kfree(new_triggers.patterns[i].mask);
10454 kfree(new_triggers.patterns);
Johannes Berg2a0e0472013-01-23 22:57:40 +010010455 if (new_triggers.tcp && new_triggers.tcp->sock)
10456 sock_release(new_triggers.tcp->sock);
10457 kfree(new_triggers.tcp);
Ola Olssone5dbe072015-12-12 23:17:17 +010010458 kfree(new_triggers.nd_config);
Johannes Bergff1b6e62011-05-04 15:37:28 +020010459 return err;
10460}
Johannes Bergdfb89c52012-06-27 09:23:48 +020010461#endif
Johannes Bergff1b6e62011-05-04 15:37:28 +020010462
Amitkumar Karwarbe29b99a2013-06-28 11:51:26 -070010463static int nl80211_send_coalesce_rules(struct sk_buff *msg,
10464 struct cfg80211_registered_device *rdev)
10465{
10466 struct nlattr *nl_pats, *nl_pat, *nl_rule, *nl_rules;
10467 int i, j, pat_len;
10468 struct cfg80211_coalesce_rules *rule;
10469
10470 if (!rdev->coalesce->n_rules)
10471 return 0;
10472
10473 nl_rules = nla_nest_start(msg, NL80211_ATTR_COALESCE_RULE);
10474 if (!nl_rules)
10475 return -ENOBUFS;
10476
10477 for (i = 0; i < rdev->coalesce->n_rules; i++) {
10478 nl_rule = nla_nest_start(msg, i + 1);
10479 if (!nl_rule)
10480 return -ENOBUFS;
10481
10482 rule = &rdev->coalesce->rules[i];
10483 if (nla_put_u32(msg, NL80211_ATTR_COALESCE_RULE_DELAY,
10484 rule->delay))
10485 return -ENOBUFS;
10486
10487 if (nla_put_u32(msg, NL80211_ATTR_COALESCE_RULE_CONDITION,
10488 rule->condition))
10489 return -ENOBUFS;
10490
10491 nl_pats = nla_nest_start(msg,
10492 NL80211_ATTR_COALESCE_RULE_PKT_PATTERN);
10493 if (!nl_pats)
10494 return -ENOBUFS;
10495
10496 for (j = 0; j < rule->n_patterns; j++) {
10497 nl_pat = nla_nest_start(msg, j + 1);
10498 if (!nl_pat)
10499 return -ENOBUFS;
10500 pat_len = rule->patterns[j].pattern_len;
10501 if (nla_put(msg, NL80211_PKTPAT_MASK,
10502 DIV_ROUND_UP(pat_len, 8),
10503 rule->patterns[j].mask) ||
10504 nla_put(msg, NL80211_PKTPAT_PATTERN, pat_len,
10505 rule->patterns[j].pattern) ||
10506 nla_put_u32(msg, NL80211_PKTPAT_OFFSET,
10507 rule->patterns[j].pkt_offset))
10508 return -ENOBUFS;
10509 nla_nest_end(msg, nl_pat);
10510 }
10511 nla_nest_end(msg, nl_pats);
10512 nla_nest_end(msg, nl_rule);
10513 }
10514 nla_nest_end(msg, nl_rules);
10515
10516 return 0;
10517}
10518
10519static int nl80211_get_coalesce(struct sk_buff *skb, struct genl_info *info)
10520{
10521 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10522 struct sk_buff *msg;
10523 void *hdr;
10524
10525 if (!rdev->wiphy.coalesce)
10526 return -EOPNOTSUPP;
10527
10528 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
10529 if (!msg)
10530 return -ENOMEM;
10531
10532 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
10533 NL80211_CMD_GET_COALESCE);
10534 if (!hdr)
10535 goto nla_put_failure;
10536
10537 if (rdev->coalesce && nl80211_send_coalesce_rules(msg, rdev))
10538 goto nla_put_failure;
10539
10540 genlmsg_end(msg, hdr);
10541 return genlmsg_reply(msg, info);
10542
10543nla_put_failure:
10544 nlmsg_free(msg);
10545 return -ENOBUFS;
10546}
10547
10548void cfg80211_rdev_free_coalesce(struct cfg80211_registered_device *rdev)
10549{
10550 struct cfg80211_coalesce *coalesce = rdev->coalesce;
10551 int i, j;
10552 struct cfg80211_coalesce_rules *rule;
10553
10554 if (!coalesce)
10555 return;
10556
10557 for (i = 0; i < coalesce->n_rules; i++) {
10558 rule = &coalesce->rules[i];
10559 for (j = 0; j < rule->n_patterns; j++)
10560 kfree(rule->patterns[j].mask);
10561 kfree(rule->patterns);
10562 }
10563 kfree(coalesce->rules);
10564 kfree(coalesce);
10565 rdev->coalesce = NULL;
10566}
10567
10568static int nl80211_parse_coalesce_rule(struct cfg80211_registered_device *rdev,
10569 struct nlattr *rule,
10570 struct cfg80211_coalesce_rules *new_rule)
10571{
10572 int err, i;
10573 const struct wiphy_coalesce_support *coalesce = rdev->wiphy.coalesce;
10574 struct nlattr *tb[NUM_NL80211_ATTR_COALESCE_RULE], *pat;
10575 int rem, pat_len, mask_len, pkt_offset, n_patterns = 0;
10576 struct nlattr *pat_tb[NUM_NL80211_PKTPAT];
10577
Johannes Bergbfe2c7b2016-10-26 14:42:21 +020010578 err = nla_parse_nested(tb, NL80211_ATTR_COALESCE_RULE_MAX, rule,
10579 nl80211_coalesce_policy);
Amitkumar Karwarbe29b99a2013-06-28 11:51:26 -070010580 if (err)
10581 return err;
10582
10583 if (tb[NL80211_ATTR_COALESCE_RULE_DELAY])
10584 new_rule->delay =
10585 nla_get_u32(tb[NL80211_ATTR_COALESCE_RULE_DELAY]);
10586 if (new_rule->delay > coalesce->max_delay)
10587 return -EINVAL;
10588
10589 if (tb[NL80211_ATTR_COALESCE_RULE_CONDITION])
10590 new_rule->condition =
10591 nla_get_u32(tb[NL80211_ATTR_COALESCE_RULE_CONDITION]);
10592 if (new_rule->condition != NL80211_COALESCE_CONDITION_MATCH &&
10593 new_rule->condition != NL80211_COALESCE_CONDITION_NO_MATCH)
10594 return -EINVAL;
10595
10596 if (!tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN])
10597 return -EINVAL;
10598
10599 nla_for_each_nested(pat, tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN],
10600 rem)
10601 n_patterns++;
10602 if (n_patterns > coalesce->n_patterns)
10603 return -EINVAL;
10604
10605 new_rule->patterns = kcalloc(n_patterns, sizeof(new_rule->patterns[0]),
10606 GFP_KERNEL);
10607 if (!new_rule->patterns)
10608 return -ENOMEM;
10609
10610 new_rule->n_patterns = n_patterns;
10611 i = 0;
10612
10613 nla_for_each_nested(pat, tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN],
10614 rem) {
Johannes Berg922bd802014-05-19 17:59:50 +020010615 u8 *mask_pat;
10616
Johannes Bergbfe2c7b2016-10-26 14:42:21 +020010617 nla_parse_nested(pat_tb, MAX_NL80211_PKTPAT, pat, NULL);
Amitkumar Karwarbe29b99a2013-06-28 11:51:26 -070010618 if (!pat_tb[NL80211_PKTPAT_MASK] ||
10619 !pat_tb[NL80211_PKTPAT_PATTERN])
10620 return -EINVAL;
10621 pat_len = nla_len(pat_tb[NL80211_PKTPAT_PATTERN]);
10622 mask_len = DIV_ROUND_UP(pat_len, 8);
10623 if (nla_len(pat_tb[NL80211_PKTPAT_MASK]) != mask_len)
10624 return -EINVAL;
10625 if (pat_len > coalesce->pattern_max_len ||
10626 pat_len < coalesce->pattern_min_len)
10627 return -EINVAL;
10628
10629 if (!pat_tb[NL80211_PKTPAT_OFFSET])
10630 pkt_offset = 0;
10631 else
10632 pkt_offset = nla_get_u32(pat_tb[NL80211_PKTPAT_OFFSET]);
10633 if (pkt_offset > coalesce->max_pkt_offset)
10634 return -EINVAL;
10635 new_rule->patterns[i].pkt_offset = pkt_offset;
10636
Johannes Berg922bd802014-05-19 17:59:50 +020010637 mask_pat = kmalloc(mask_len + pat_len, GFP_KERNEL);
10638 if (!mask_pat)
Amitkumar Karwarbe29b99a2013-06-28 11:51:26 -070010639 return -ENOMEM;
Johannes Berg922bd802014-05-19 17:59:50 +020010640
10641 new_rule->patterns[i].mask = mask_pat;
10642 memcpy(mask_pat, nla_data(pat_tb[NL80211_PKTPAT_MASK]),
10643 mask_len);
10644
10645 mask_pat += mask_len;
10646 new_rule->patterns[i].pattern = mask_pat;
Amitkumar Karwarbe29b99a2013-06-28 11:51:26 -070010647 new_rule->patterns[i].pattern_len = pat_len;
Johannes Berg922bd802014-05-19 17:59:50 +020010648 memcpy(mask_pat, nla_data(pat_tb[NL80211_PKTPAT_PATTERN]),
10649 pat_len);
Amitkumar Karwarbe29b99a2013-06-28 11:51:26 -070010650 i++;
10651 }
10652
10653 return 0;
10654}
10655
10656static int nl80211_set_coalesce(struct sk_buff *skb, struct genl_info *info)
10657{
10658 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10659 const struct wiphy_coalesce_support *coalesce = rdev->wiphy.coalesce;
10660 struct cfg80211_coalesce new_coalesce = {};
10661 struct cfg80211_coalesce *n_coalesce;
10662 int err, rem_rule, n_rules = 0, i, j;
10663 struct nlattr *rule;
10664 struct cfg80211_coalesce_rules *tmp_rule;
10665
10666 if (!rdev->wiphy.coalesce || !rdev->ops->set_coalesce)
10667 return -EOPNOTSUPP;
10668
10669 if (!info->attrs[NL80211_ATTR_COALESCE_RULE]) {
10670 cfg80211_rdev_free_coalesce(rdev);
Ilan Peera1056b1b2015-10-22 22:27:46 +030010671 rdev_set_coalesce(rdev, NULL);
Amitkumar Karwarbe29b99a2013-06-28 11:51:26 -070010672 return 0;
10673 }
10674
10675 nla_for_each_nested(rule, info->attrs[NL80211_ATTR_COALESCE_RULE],
10676 rem_rule)
10677 n_rules++;
10678 if (n_rules > coalesce->n_rules)
10679 return -EINVAL;
10680
10681 new_coalesce.rules = kcalloc(n_rules, sizeof(new_coalesce.rules[0]),
10682 GFP_KERNEL);
10683 if (!new_coalesce.rules)
10684 return -ENOMEM;
10685
10686 new_coalesce.n_rules = n_rules;
10687 i = 0;
10688
10689 nla_for_each_nested(rule, info->attrs[NL80211_ATTR_COALESCE_RULE],
10690 rem_rule) {
10691 err = nl80211_parse_coalesce_rule(rdev, rule,
10692 &new_coalesce.rules[i]);
10693 if (err)
10694 goto error;
10695
10696 i++;
10697 }
10698
Ilan Peera1056b1b2015-10-22 22:27:46 +030010699 err = rdev_set_coalesce(rdev, &new_coalesce);
Amitkumar Karwarbe29b99a2013-06-28 11:51:26 -070010700 if (err)
10701 goto error;
10702
10703 n_coalesce = kmemdup(&new_coalesce, sizeof(new_coalesce), GFP_KERNEL);
10704 if (!n_coalesce) {
10705 err = -ENOMEM;
10706 goto error;
10707 }
10708 cfg80211_rdev_free_coalesce(rdev);
10709 rdev->coalesce = n_coalesce;
10710
10711 return 0;
10712error:
10713 for (i = 0; i < new_coalesce.n_rules; i++) {
10714 tmp_rule = &new_coalesce.rules[i];
10715 for (j = 0; j < tmp_rule->n_patterns; j++)
10716 kfree(tmp_rule->patterns[j].mask);
10717 kfree(tmp_rule->patterns);
10718 }
10719 kfree(new_coalesce.rules);
10720
10721 return err;
10722}
10723
Johannes Berge5497d72011-07-05 16:35:40 +020010724static int nl80211_set_rekey_data(struct sk_buff *skb, struct genl_info *info)
10725{
10726 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10727 struct net_device *dev = info->user_ptr[1];
10728 struct wireless_dev *wdev = dev->ieee80211_ptr;
10729 struct nlattr *tb[NUM_NL80211_REKEY_DATA];
10730 struct cfg80211_gtk_rekey_data rekey_data;
10731 int err;
10732
10733 if (!info->attrs[NL80211_ATTR_REKEY_DATA])
10734 return -EINVAL;
10735
Johannes Bergbfe2c7b2016-10-26 14:42:21 +020010736 err = nla_parse_nested(tb, MAX_NL80211_REKEY_DATA,
10737 info->attrs[NL80211_ATTR_REKEY_DATA],
10738 nl80211_rekey_policy);
Johannes Berge5497d72011-07-05 16:35:40 +020010739 if (err)
10740 return err;
10741
10742 if (nla_len(tb[NL80211_REKEY_DATA_REPLAY_CTR]) != NL80211_REPLAY_CTR_LEN)
10743 return -ERANGE;
10744 if (nla_len(tb[NL80211_REKEY_DATA_KEK]) != NL80211_KEK_LEN)
10745 return -ERANGE;
10746 if (nla_len(tb[NL80211_REKEY_DATA_KCK]) != NL80211_KCK_LEN)
10747 return -ERANGE;
10748
Johannes Berg78f686c2014-09-10 22:28:06 +030010749 rekey_data.kek = nla_data(tb[NL80211_REKEY_DATA_KEK]);
10750 rekey_data.kck = nla_data(tb[NL80211_REKEY_DATA_KCK]);
10751 rekey_data.replay_ctr = nla_data(tb[NL80211_REKEY_DATA_REPLAY_CTR]);
Johannes Berge5497d72011-07-05 16:35:40 +020010752
10753 wdev_lock(wdev);
10754 if (!wdev->current_bss) {
10755 err = -ENOTCONN;
10756 goto out;
10757 }
10758
10759 if (!rdev->ops->set_rekey_data) {
10760 err = -EOPNOTSUPP;
10761 goto out;
10762 }
10763
Hila Gonene35e4d22012-06-27 17:19:42 +030010764 err = rdev_set_rekey_data(rdev, dev, &rekey_data);
Johannes Berge5497d72011-07-05 16:35:40 +020010765 out:
10766 wdev_unlock(wdev);
10767 return err;
10768}
10769
Johannes Berg28946da2011-11-04 11:18:12 +010010770static int nl80211_register_unexpected_frame(struct sk_buff *skb,
10771 struct genl_info *info)
10772{
10773 struct net_device *dev = info->user_ptr[1];
10774 struct wireless_dev *wdev = dev->ieee80211_ptr;
10775
10776 if (wdev->iftype != NL80211_IFTYPE_AP &&
10777 wdev->iftype != NL80211_IFTYPE_P2P_GO)
10778 return -EINVAL;
10779
Eric W. Biederman15e47302012-09-07 20:12:54 +000010780 if (wdev->ap_unexpected_nlportid)
Johannes Berg28946da2011-11-04 11:18:12 +010010781 return -EBUSY;
10782
Eric W. Biederman15e47302012-09-07 20:12:54 +000010783 wdev->ap_unexpected_nlportid = info->snd_portid;
Johannes Berg28946da2011-11-04 11:18:12 +010010784 return 0;
10785}
10786
Johannes Berg7f6cf312011-11-04 11:18:15 +010010787static int nl80211_probe_client(struct sk_buff *skb,
10788 struct genl_info *info)
10789{
10790 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10791 struct net_device *dev = info->user_ptr[1];
10792 struct wireless_dev *wdev = dev->ieee80211_ptr;
10793 struct sk_buff *msg;
10794 void *hdr;
10795 const u8 *addr;
10796 u64 cookie;
10797 int err;
10798
10799 if (wdev->iftype != NL80211_IFTYPE_AP &&
10800 wdev->iftype != NL80211_IFTYPE_P2P_GO)
10801 return -EOPNOTSUPP;
10802
10803 if (!info->attrs[NL80211_ATTR_MAC])
10804 return -EINVAL;
10805
10806 if (!rdev->ops->probe_client)
10807 return -EOPNOTSUPP;
10808
10809 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
10810 if (!msg)
10811 return -ENOMEM;
10812
Eric W. Biederman15e47302012-09-07 20:12:54 +000010813 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berg7f6cf312011-11-04 11:18:15 +010010814 NL80211_CMD_PROBE_CLIENT);
Dan Carpentercb35fba2013-08-14 14:50:01 +030010815 if (!hdr) {
10816 err = -ENOBUFS;
Johannes Berg7f6cf312011-11-04 11:18:15 +010010817 goto free_msg;
10818 }
10819
10820 addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
10821
Hila Gonene35e4d22012-06-27 17:19:42 +030010822 err = rdev_probe_client(rdev, dev, addr, &cookie);
Johannes Berg7f6cf312011-11-04 11:18:15 +010010823 if (err)
10824 goto free_msg;
10825
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020010826 if (nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie,
10827 NL80211_ATTR_PAD))
David S. Miller9360ffd2012-03-29 04:41:26 -040010828 goto nla_put_failure;
Johannes Berg7f6cf312011-11-04 11:18:15 +010010829
10830 genlmsg_end(msg, hdr);
10831
10832 return genlmsg_reply(msg, info);
10833
10834 nla_put_failure:
10835 err = -ENOBUFS;
10836 free_msg:
10837 nlmsg_free(msg);
10838 return err;
10839}
10840
Johannes Berg5e760232011-11-04 11:18:17 +010010841static int nl80211_register_beacons(struct sk_buff *skb, struct genl_info *info)
10842{
10843 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Ben Greear37c73b52012-10-26 14:49:25 -070010844 struct cfg80211_beacon_registration *reg, *nreg;
10845 int rv;
Johannes Berg5e760232011-11-04 11:18:17 +010010846
10847 if (!(rdev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS))
10848 return -EOPNOTSUPP;
10849
Ben Greear37c73b52012-10-26 14:49:25 -070010850 nreg = kzalloc(sizeof(*nreg), GFP_KERNEL);
10851 if (!nreg)
10852 return -ENOMEM;
Johannes Berg5e760232011-11-04 11:18:17 +010010853
Ben Greear37c73b52012-10-26 14:49:25 -070010854 /* First, check if already registered. */
10855 spin_lock_bh(&rdev->beacon_registrations_lock);
10856 list_for_each_entry(reg, &rdev->beacon_registrations, list) {
10857 if (reg->nlportid == info->snd_portid) {
10858 rv = -EALREADY;
10859 goto out_err;
10860 }
10861 }
10862 /* Add it to the list */
10863 nreg->nlportid = info->snd_portid;
10864 list_add(&nreg->list, &rdev->beacon_registrations);
10865
10866 spin_unlock_bh(&rdev->beacon_registrations_lock);
Johannes Berg5e760232011-11-04 11:18:17 +010010867
10868 return 0;
Ben Greear37c73b52012-10-26 14:49:25 -070010869out_err:
10870 spin_unlock_bh(&rdev->beacon_registrations_lock);
10871 kfree(nreg);
10872 return rv;
Johannes Berg5e760232011-11-04 11:18:17 +010010873}
10874
Johannes Berg98104fde2012-06-16 00:19:54 +020010875static int nl80211_start_p2p_device(struct sk_buff *skb, struct genl_info *info)
10876{
10877 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10878 struct wireless_dev *wdev = info->user_ptr[1];
10879 int err;
10880
10881 if (!rdev->ops->start_p2p_device)
10882 return -EOPNOTSUPP;
10883
10884 if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE)
10885 return -EOPNOTSUPP;
10886
Arend Van Spriel73c7da32016-10-20 20:08:22 +010010887 if (wdev_running(wdev))
Johannes Berg98104fde2012-06-16 00:19:54 +020010888 return 0;
10889
Luciano Coelhob6a55012014-02-27 11:07:21 +020010890 if (rfkill_blocked(rdev->rfkill))
10891 return -ERFKILL;
Johannes Berg98104fde2012-06-16 00:19:54 +020010892
Johannes Bergeeb126e2012-10-23 15:16:50 +020010893 err = rdev_start_p2p_device(rdev, wdev);
Johannes Berg98104fde2012-06-16 00:19:54 +020010894 if (err)
10895 return err;
10896
Arend Van Spriel73c7da32016-10-20 20:08:22 +010010897 wdev->is_running = true;
Johannes Berg98104fde2012-06-16 00:19:54 +020010898 rdev->opencount++;
Johannes Berg98104fde2012-06-16 00:19:54 +020010899
10900 return 0;
10901}
10902
10903static int nl80211_stop_p2p_device(struct sk_buff *skb, struct genl_info *info)
10904{
10905 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10906 struct wireless_dev *wdev = info->user_ptr[1];
10907
10908 if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE)
10909 return -EOPNOTSUPP;
10910
10911 if (!rdev->ops->stop_p2p_device)
10912 return -EOPNOTSUPP;
10913
Johannes Bergf9f47522013-03-19 15:04:07 +010010914 cfg80211_stop_p2p_device(rdev, wdev);
Johannes Berg98104fde2012-06-16 00:19:54 +020010915
10916 return 0;
10917}
10918
Ayala Bekercb3b7d82016-09-20 17:31:13 +030010919static int nl80211_start_nan(struct sk_buff *skb, struct genl_info *info)
10920{
10921 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10922 struct wireless_dev *wdev = info->user_ptr[1];
10923 struct cfg80211_nan_conf conf = {};
10924 int err;
10925
10926 if (wdev->iftype != NL80211_IFTYPE_NAN)
10927 return -EOPNOTSUPP;
10928
Johannes Bergeeb04a92016-11-21 13:55:48 +010010929 if (wdev_running(wdev))
Ayala Bekercb3b7d82016-09-20 17:31:13 +030010930 return -EEXIST;
10931
10932 if (rfkill_blocked(rdev->rfkill))
10933 return -ERFKILL;
10934
10935 if (!info->attrs[NL80211_ATTR_NAN_MASTER_PREF])
10936 return -EINVAL;
10937
Ayala Bekercb3b7d82016-09-20 17:31:13 +030010938 conf.master_pref =
10939 nla_get_u8(info->attrs[NL80211_ATTR_NAN_MASTER_PREF]);
10940 if (!conf.master_pref)
10941 return -EINVAL;
10942
Luca Coelho85859892017-02-08 15:00:34 +020010943 if (info->attrs[NL80211_ATTR_BANDS]) {
10944 u32 bands = nla_get_u32(info->attrs[NL80211_ATTR_BANDS]);
10945
10946 if (bands & ~(u32)wdev->wiphy->nan_supported_bands)
10947 return -EOPNOTSUPP;
10948
10949 if (bands && !(bands & BIT(NL80211_BAND_2GHZ)))
10950 return -EINVAL;
10951
10952 conf.bands = bands;
10953 }
Ayala Bekercb3b7d82016-09-20 17:31:13 +030010954
10955 err = rdev_start_nan(rdev, wdev, &conf);
10956 if (err)
10957 return err;
10958
Arend Van Spriel73c7da32016-10-20 20:08:22 +010010959 wdev->is_running = true;
Ayala Bekercb3b7d82016-09-20 17:31:13 +030010960 rdev->opencount++;
10961
10962 return 0;
10963}
10964
10965static int nl80211_stop_nan(struct sk_buff *skb, struct genl_info *info)
10966{
10967 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10968 struct wireless_dev *wdev = info->user_ptr[1];
10969
10970 if (wdev->iftype != NL80211_IFTYPE_NAN)
10971 return -EOPNOTSUPP;
10972
10973 cfg80211_stop_nan(rdev, wdev);
10974
10975 return 0;
10976}
10977
Ayala Bekera442b762016-09-20 17:31:15 +030010978static int validate_nan_filter(struct nlattr *filter_attr)
10979{
10980 struct nlattr *attr;
10981 int len = 0, n_entries = 0, rem;
10982
10983 nla_for_each_nested(attr, filter_attr, rem) {
10984 len += nla_len(attr);
10985 n_entries++;
10986 }
10987
10988 if (len >= U8_MAX)
10989 return -EINVAL;
10990
10991 return n_entries;
10992}
10993
10994static int handle_nan_filter(struct nlattr *attr_filter,
10995 struct cfg80211_nan_func *func,
10996 bool tx)
10997{
10998 struct nlattr *attr;
10999 int n_entries, rem, i;
11000 struct cfg80211_nan_func_filter *filter;
11001
11002 n_entries = validate_nan_filter(attr_filter);
11003 if (n_entries < 0)
11004 return n_entries;
11005
11006 BUILD_BUG_ON(sizeof(*func->rx_filters) != sizeof(*func->tx_filters));
11007
11008 filter = kcalloc(n_entries, sizeof(*func->rx_filters), GFP_KERNEL);
11009 if (!filter)
11010 return -ENOMEM;
11011
11012 i = 0;
11013 nla_for_each_nested(attr, attr_filter, rem) {
Thomas Grafb15ca182016-10-26 10:53:16 +020011014 filter[i].filter = nla_memdup(attr, GFP_KERNEL);
Ayala Bekera442b762016-09-20 17:31:15 +030011015 filter[i].len = nla_len(attr);
11016 i++;
11017 }
11018 if (tx) {
11019 func->num_tx_filters = n_entries;
11020 func->tx_filters = filter;
11021 } else {
11022 func->num_rx_filters = n_entries;
11023 func->rx_filters = filter;
11024 }
11025
11026 return 0;
11027}
11028
11029static int nl80211_nan_add_func(struct sk_buff *skb,
11030 struct genl_info *info)
11031{
11032 struct cfg80211_registered_device *rdev = info->user_ptr[0];
11033 struct wireless_dev *wdev = info->user_ptr[1];
11034 struct nlattr *tb[NUM_NL80211_NAN_FUNC_ATTR], *func_attr;
11035 struct cfg80211_nan_func *func;
11036 struct sk_buff *msg = NULL;
11037 void *hdr = NULL;
11038 int err = 0;
11039
11040 if (wdev->iftype != NL80211_IFTYPE_NAN)
11041 return -EOPNOTSUPP;
11042
Arend Van Spriel73c7da32016-10-20 20:08:22 +010011043 if (!wdev_running(wdev))
Ayala Bekera442b762016-09-20 17:31:15 +030011044 return -ENOTCONN;
11045
11046 if (!info->attrs[NL80211_ATTR_NAN_FUNC])
11047 return -EINVAL;
11048
11049 if (wdev->owner_nlportid &&
11050 wdev->owner_nlportid != info->snd_portid)
11051 return -ENOTCONN;
11052
Johannes Bergbfe2c7b2016-10-26 14:42:21 +020011053 err = nla_parse_nested(tb, NL80211_NAN_FUNC_ATTR_MAX,
11054 info->attrs[NL80211_ATTR_NAN_FUNC],
11055 nl80211_nan_func_policy);
Ayala Bekera442b762016-09-20 17:31:15 +030011056 if (err)
11057 return err;
11058
11059 func = kzalloc(sizeof(*func), GFP_KERNEL);
11060 if (!func)
11061 return -ENOMEM;
11062
11063 func->cookie = wdev->wiphy->cookie_counter++;
11064
11065 if (!tb[NL80211_NAN_FUNC_TYPE] ||
11066 nla_get_u8(tb[NL80211_NAN_FUNC_TYPE]) > NL80211_NAN_FUNC_MAX_TYPE) {
11067 err = -EINVAL;
11068 goto out;
11069 }
11070
11071
11072 func->type = nla_get_u8(tb[NL80211_NAN_FUNC_TYPE]);
11073
11074 if (!tb[NL80211_NAN_FUNC_SERVICE_ID]) {
11075 err = -EINVAL;
11076 goto out;
11077 }
11078
11079 memcpy(func->service_id, nla_data(tb[NL80211_NAN_FUNC_SERVICE_ID]),
11080 sizeof(func->service_id));
11081
11082 func->close_range =
11083 nla_get_flag(tb[NL80211_NAN_FUNC_CLOSE_RANGE]);
11084
11085 if (tb[NL80211_NAN_FUNC_SERVICE_INFO]) {
11086 func->serv_spec_info_len =
11087 nla_len(tb[NL80211_NAN_FUNC_SERVICE_INFO]);
11088 func->serv_spec_info =
11089 kmemdup(nla_data(tb[NL80211_NAN_FUNC_SERVICE_INFO]),
11090 func->serv_spec_info_len,
11091 GFP_KERNEL);
11092 if (!func->serv_spec_info) {
11093 err = -ENOMEM;
11094 goto out;
11095 }
11096 }
11097
11098 if (tb[NL80211_NAN_FUNC_TTL])
11099 func->ttl = nla_get_u32(tb[NL80211_NAN_FUNC_TTL]);
11100
11101 switch (func->type) {
11102 case NL80211_NAN_FUNC_PUBLISH:
11103 if (!tb[NL80211_NAN_FUNC_PUBLISH_TYPE]) {
11104 err = -EINVAL;
11105 goto out;
11106 }
11107
11108 func->publish_type =
11109 nla_get_u8(tb[NL80211_NAN_FUNC_PUBLISH_TYPE]);
11110 func->publish_bcast =
11111 nla_get_flag(tb[NL80211_NAN_FUNC_PUBLISH_BCAST]);
11112
11113 if ((!(func->publish_type & NL80211_NAN_SOLICITED_PUBLISH)) &&
11114 func->publish_bcast) {
11115 err = -EINVAL;
11116 goto out;
11117 }
11118 break;
11119 case NL80211_NAN_FUNC_SUBSCRIBE:
11120 func->subscribe_active =
11121 nla_get_flag(tb[NL80211_NAN_FUNC_SUBSCRIBE_ACTIVE]);
11122 break;
11123 case NL80211_NAN_FUNC_FOLLOW_UP:
11124 if (!tb[NL80211_NAN_FUNC_FOLLOW_UP_ID] ||
11125 !tb[NL80211_NAN_FUNC_FOLLOW_UP_REQ_ID]) {
11126 err = -EINVAL;
11127 goto out;
11128 }
11129
11130 func->followup_id =
11131 nla_get_u8(tb[NL80211_NAN_FUNC_FOLLOW_UP_ID]);
11132 func->followup_reqid =
11133 nla_get_u8(tb[NL80211_NAN_FUNC_FOLLOW_UP_REQ_ID]);
11134 memcpy(func->followup_dest.addr,
11135 nla_data(tb[NL80211_NAN_FUNC_FOLLOW_UP_DEST]),
11136 sizeof(func->followup_dest.addr));
11137 if (func->ttl) {
11138 err = -EINVAL;
11139 goto out;
11140 }
11141 break;
11142 default:
11143 err = -EINVAL;
11144 goto out;
11145 }
11146
11147 if (tb[NL80211_NAN_FUNC_SRF]) {
11148 struct nlattr *srf_tb[NUM_NL80211_NAN_SRF_ATTR];
11149
Johannes Bergbfe2c7b2016-10-26 14:42:21 +020011150 err = nla_parse_nested(srf_tb, NL80211_NAN_SRF_ATTR_MAX,
11151 tb[NL80211_NAN_FUNC_SRF],
11152 nl80211_nan_srf_policy);
Ayala Bekera442b762016-09-20 17:31:15 +030011153 if (err)
11154 goto out;
11155
11156 func->srf_include =
11157 nla_get_flag(srf_tb[NL80211_NAN_SRF_INCLUDE]);
11158
11159 if (srf_tb[NL80211_NAN_SRF_BF]) {
11160 if (srf_tb[NL80211_NAN_SRF_MAC_ADDRS] ||
11161 !srf_tb[NL80211_NAN_SRF_BF_IDX]) {
11162 err = -EINVAL;
11163 goto out;
11164 }
11165
11166 func->srf_bf_len =
11167 nla_len(srf_tb[NL80211_NAN_SRF_BF]);
11168 func->srf_bf =
11169 kmemdup(nla_data(srf_tb[NL80211_NAN_SRF_BF]),
11170 func->srf_bf_len, GFP_KERNEL);
11171 if (!func->srf_bf) {
11172 err = -ENOMEM;
11173 goto out;
11174 }
11175
11176 func->srf_bf_idx =
11177 nla_get_u8(srf_tb[NL80211_NAN_SRF_BF_IDX]);
11178 } else {
11179 struct nlattr *attr, *mac_attr =
11180 srf_tb[NL80211_NAN_SRF_MAC_ADDRS];
11181 int n_entries, rem, i = 0;
11182
11183 if (!mac_attr) {
11184 err = -EINVAL;
11185 goto out;
11186 }
11187
11188 n_entries = validate_acl_mac_addrs(mac_attr);
11189 if (n_entries <= 0) {
11190 err = -EINVAL;
11191 goto out;
11192 }
11193
11194 func->srf_num_macs = n_entries;
11195 func->srf_macs =
11196 kzalloc(sizeof(*func->srf_macs) * n_entries,
11197 GFP_KERNEL);
11198 if (!func->srf_macs) {
11199 err = -ENOMEM;
11200 goto out;
11201 }
11202
11203 nla_for_each_nested(attr, mac_attr, rem)
11204 memcpy(func->srf_macs[i++].addr, nla_data(attr),
11205 sizeof(*func->srf_macs));
11206 }
11207 }
11208
11209 if (tb[NL80211_NAN_FUNC_TX_MATCH_FILTER]) {
11210 err = handle_nan_filter(tb[NL80211_NAN_FUNC_TX_MATCH_FILTER],
11211 func, true);
11212 if (err)
11213 goto out;
11214 }
11215
11216 if (tb[NL80211_NAN_FUNC_RX_MATCH_FILTER]) {
11217 err = handle_nan_filter(tb[NL80211_NAN_FUNC_RX_MATCH_FILTER],
11218 func, false);
11219 if (err)
11220 goto out;
11221 }
11222
11223 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
11224 if (!msg) {
11225 err = -ENOMEM;
11226 goto out;
11227 }
11228
11229 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
11230 NL80211_CMD_ADD_NAN_FUNCTION);
11231 /* This can't really happen - we just allocated 4KB */
11232 if (WARN_ON(!hdr)) {
11233 err = -ENOMEM;
11234 goto out;
11235 }
11236
11237 err = rdev_add_nan_func(rdev, wdev, func);
11238out:
11239 if (err < 0) {
11240 cfg80211_free_nan_func(func);
11241 nlmsg_free(msg);
11242 return err;
11243 }
11244
11245 /* propagate the instance id and cookie to userspace */
11246 if (nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, func->cookie,
11247 NL80211_ATTR_PAD))
11248 goto nla_put_failure;
11249
11250 func_attr = nla_nest_start(msg, NL80211_ATTR_NAN_FUNC);
11251 if (!func_attr)
11252 goto nla_put_failure;
11253
11254 if (nla_put_u8(msg, NL80211_NAN_FUNC_INSTANCE_ID,
11255 func->instance_id))
11256 goto nla_put_failure;
11257
11258 nla_nest_end(msg, func_attr);
11259
11260 genlmsg_end(msg, hdr);
11261 return genlmsg_reply(msg, info);
11262
11263nla_put_failure:
11264 nlmsg_free(msg);
11265 return -ENOBUFS;
11266}
11267
11268static int nl80211_nan_del_func(struct sk_buff *skb,
11269 struct genl_info *info)
11270{
11271 struct cfg80211_registered_device *rdev = info->user_ptr[0];
11272 struct wireless_dev *wdev = info->user_ptr[1];
11273 u64 cookie;
11274
11275 if (wdev->iftype != NL80211_IFTYPE_NAN)
11276 return -EOPNOTSUPP;
11277
Arend Van Spriel73c7da32016-10-20 20:08:22 +010011278 if (!wdev_running(wdev))
Ayala Bekera442b762016-09-20 17:31:15 +030011279 return -ENOTCONN;
11280
11281 if (!info->attrs[NL80211_ATTR_COOKIE])
11282 return -EINVAL;
11283
11284 if (wdev->owner_nlportid &&
11285 wdev->owner_nlportid != info->snd_portid)
11286 return -ENOTCONN;
11287
11288 cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]);
11289
11290 rdev_del_nan_func(rdev, wdev, cookie);
11291
11292 return 0;
11293}
11294
Ayala Bekera5a9dcf2016-09-20 17:31:16 +030011295static int nl80211_nan_change_config(struct sk_buff *skb,
11296 struct genl_info *info)
11297{
11298 struct cfg80211_registered_device *rdev = info->user_ptr[0];
11299 struct wireless_dev *wdev = info->user_ptr[1];
11300 struct cfg80211_nan_conf conf = {};
11301 u32 changed = 0;
11302
11303 if (wdev->iftype != NL80211_IFTYPE_NAN)
11304 return -EOPNOTSUPP;
11305
Arend Van Spriel73c7da32016-10-20 20:08:22 +010011306 if (!wdev_running(wdev))
Ayala Bekera5a9dcf2016-09-20 17:31:16 +030011307 return -ENOTCONN;
11308
11309 if (info->attrs[NL80211_ATTR_NAN_MASTER_PREF]) {
11310 conf.master_pref =
11311 nla_get_u8(info->attrs[NL80211_ATTR_NAN_MASTER_PREF]);
11312 if (conf.master_pref <= 1 || conf.master_pref == 255)
11313 return -EINVAL;
11314
11315 changed |= CFG80211_NAN_CONF_CHANGED_PREF;
11316 }
11317
Luca Coelho85859892017-02-08 15:00:34 +020011318 if (info->attrs[NL80211_ATTR_BANDS]) {
11319 u32 bands = nla_get_u32(info->attrs[NL80211_ATTR_BANDS]);
11320
11321 if (bands & ~(u32)wdev->wiphy->nan_supported_bands)
11322 return -EOPNOTSUPP;
11323
11324 if (bands && !(bands & BIT(NL80211_BAND_2GHZ)))
11325 return -EINVAL;
11326
11327 conf.bands = bands;
11328 changed |= CFG80211_NAN_CONF_CHANGED_BANDS;
Ayala Bekera5a9dcf2016-09-20 17:31:16 +030011329 }
11330
11331 if (!changed)
11332 return -EINVAL;
11333
11334 return rdev_nan_change_conf(rdev, wdev, &conf, changed);
11335}
11336
Ayala Beker50bcd312016-09-20 17:31:17 +030011337void cfg80211_nan_match(struct wireless_dev *wdev,
11338 struct cfg80211_nan_match_params *match, gfp_t gfp)
11339{
11340 struct wiphy *wiphy = wdev->wiphy;
11341 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
11342 struct nlattr *match_attr, *local_func_attr, *peer_func_attr;
11343 struct sk_buff *msg;
11344 void *hdr;
11345
11346 if (WARN_ON(!match->inst_id || !match->peer_inst_id || !match->addr))
11347 return;
11348
11349 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
11350 if (!msg)
11351 return;
11352
11353 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NAN_MATCH);
11354 if (!hdr) {
11355 nlmsg_free(msg);
11356 return;
11357 }
11358
11359 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
11360 (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
11361 wdev->netdev->ifindex)) ||
11362 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
11363 NL80211_ATTR_PAD))
11364 goto nla_put_failure;
11365
11366 if (nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, match->cookie,
11367 NL80211_ATTR_PAD) ||
11368 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, match->addr))
11369 goto nla_put_failure;
11370
11371 match_attr = nla_nest_start(msg, NL80211_ATTR_NAN_MATCH);
11372 if (!match_attr)
11373 goto nla_put_failure;
11374
11375 local_func_attr = nla_nest_start(msg, NL80211_NAN_MATCH_FUNC_LOCAL);
11376 if (!local_func_attr)
11377 goto nla_put_failure;
11378
11379 if (nla_put_u8(msg, NL80211_NAN_FUNC_INSTANCE_ID, match->inst_id))
11380 goto nla_put_failure;
11381
11382 nla_nest_end(msg, local_func_attr);
11383
11384 peer_func_attr = nla_nest_start(msg, NL80211_NAN_MATCH_FUNC_PEER);
11385 if (!peer_func_attr)
11386 goto nla_put_failure;
11387
11388 if (nla_put_u8(msg, NL80211_NAN_FUNC_TYPE, match->type) ||
11389 nla_put_u8(msg, NL80211_NAN_FUNC_INSTANCE_ID, match->peer_inst_id))
11390 goto nla_put_failure;
11391
11392 if (match->info && match->info_len &&
11393 nla_put(msg, NL80211_NAN_FUNC_SERVICE_INFO, match->info_len,
11394 match->info))
11395 goto nla_put_failure;
11396
11397 nla_nest_end(msg, peer_func_attr);
11398 nla_nest_end(msg, match_attr);
11399 genlmsg_end(msg, hdr);
11400
11401 if (!wdev->owner_nlportid)
11402 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy),
11403 msg, 0, NL80211_MCGRP_NAN, gfp);
11404 else
11405 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg,
11406 wdev->owner_nlportid);
11407
11408 return;
11409
11410nla_put_failure:
11411 nlmsg_free(msg);
11412}
11413EXPORT_SYMBOL(cfg80211_nan_match);
11414
Ayala Beker368e5a72016-09-20 17:31:18 +030011415void cfg80211_nan_func_terminated(struct wireless_dev *wdev,
11416 u8 inst_id,
11417 enum nl80211_nan_func_term_reason reason,
11418 u64 cookie, gfp_t gfp)
11419{
11420 struct wiphy *wiphy = wdev->wiphy;
11421 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
11422 struct sk_buff *msg;
11423 struct nlattr *func_attr;
11424 void *hdr;
11425
11426 if (WARN_ON(!inst_id))
11427 return;
11428
11429 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
11430 if (!msg)
11431 return;
11432
11433 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DEL_NAN_FUNCTION);
11434 if (!hdr) {
11435 nlmsg_free(msg);
11436 return;
11437 }
11438
11439 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
11440 (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
11441 wdev->netdev->ifindex)) ||
11442 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
11443 NL80211_ATTR_PAD))
11444 goto nla_put_failure;
11445
11446 if (nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie,
11447 NL80211_ATTR_PAD))
11448 goto nla_put_failure;
11449
11450 func_attr = nla_nest_start(msg, NL80211_ATTR_NAN_FUNC);
11451 if (!func_attr)
11452 goto nla_put_failure;
11453
11454 if (nla_put_u8(msg, NL80211_NAN_FUNC_INSTANCE_ID, inst_id) ||
11455 nla_put_u8(msg, NL80211_NAN_FUNC_TERM_REASON, reason))
11456 goto nla_put_failure;
11457
11458 nla_nest_end(msg, func_attr);
11459 genlmsg_end(msg, hdr);
11460
11461 if (!wdev->owner_nlportid)
11462 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy),
11463 msg, 0, NL80211_MCGRP_NAN, gfp);
11464 else
11465 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg,
11466 wdev->owner_nlportid);
11467
11468 return;
11469
11470nla_put_failure:
11471 nlmsg_free(msg);
11472}
11473EXPORT_SYMBOL(cfg80211_nan_func_terminated);
11474
Johannes Berg3713b4e2013-02-14 16:19:38 +010011475static int nl80211_get_protocol_features(struct sk_buff *skb,
11476 struct genl_info *info)
11477{
11478 void *hdr;
11479 struct sk_buff *msg;
11480
11481 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
11482 if (!msg)
11483 return -ENOMEM;
11484
11485 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
11486 NL80211_CMD_GET_PROTOCOL_FEATURES);
11487 if (!hdr)
11488 goto nla_put_failure;
11489
11490 if (nla_put_u32(msg, NL80211_ATTR_PROTOCOL_FEATURES,
11491 NL80211_PROTOCOL_FEATURE_SPLIT_WIPHY_DUMP))
11492 goto nla_put_failure;
11493
11494 genlmsg_end(msg, hdr);
11495 return genlmsg_reply(msg, info);
11496
11497 nla_put_failure:
11498 kfree_skb(msg);
11499 return -ENOBUFS;
11500}
11501
Jouni Malinen355199e2013-02-27 17:14:27 +020011502static int nl80211_update_ft_ies(struct sk_buff *skb, struct genl_info *info)
11503{
11504 struct cfg80211_registered_device *rdev = info->user_ptr[0];
11505 struct cfg80211_update_ft_ies_params ft_params;
11506 struct net_device *dev = info->user_ptr[1];
11507
11508 if (!rdev->ops->update_ft_ies)
11509 return -EOPNOTSUPP;
11510
11511 if (!info->attrs[NL80211_ATTR_MDID] ||
11512 !is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
11513 return -EINVAL;
11514
11515 memset(&ft_params, 0, sizeof(ft_params));
11516 ft_params.md = nla_get_u16(info->attrs[NL80211_ATTR_MDID]);
11517 ft_params.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
11518 ft_params.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
11519
11520 return rdev_update_ft_ies(rdev, dev, &ft_params);
11521}
11522
Arend van Spriel5de17982013-04-18 15:49:00 +020011523static int nl80211_crit_protocol_start(struct sk_buff *skb,
11524 struct genl_info *info)
11525{
11526 struct cfg80211_registered_device *rdev = info->user_ptr[0];
11527 struct wireless_dev *wdev = info->user_ptr[1];
11528 enum nl80211_crit_proto_id proto = NL80211_CRIT_PROTO_UNSPEC;
11529 u16 duration;
11530 int ret;
11531
11532 if (!rdev->ops->crit_proto_start)
11533 return -EOPNOTSUPP;
11534
11535 if (WARN_ON(!rdev->ops->crit_proto_stop))
11536 return -EINVAL;
11537
11538 if (rdev->crit_proto_nlportid)
11539 return -EBUSY;
11540
11541 /* determine protocol if provided */
11542 if (info->attrs[NL80211_ATTR_CRIT_PROT_ID])
11543 proto = nla_get_u16(info->attrs[NL80211_ATTR_CRIT_PROT_ID]);
11544
11545 if (proto >= NUM_NL80211_CRIT_PROTO)
11546 return -EINVAL;
11547
11548 /* timeout must be provided */
11549 if (!info->attrs[NL80211_ATTR_MAX_CRIT_PROT_DURATION])
11550 return -EINVAL;
11551
11552 duration =
11553 nla_get_u16(info->attrs[NL80211_ATTR_MAX_CRIT_PROT_DURATION]);
11554
11555 if (duration > NL80211_CRIT_PROTO_MAX_DURATION)
11556 return -ERANGE;
11557
11558 ret = rdev_crit_proto_start(rdev, wdev, proto, duration);
11559 if (!ret)
11560 rdev->crit_proto_nlportid = info->snd_portid;
11561
11562 return ret;
11563}
11564
11565static int nl80211_crit_protocol_stop(struct sk_buff *skb,
11566 struct genl_info *info)
11567{
11568 struct cfg80211_registered_device *rdev = info->user_ptr[0];
11569 struct wireless_dev *wdev = info->user_ptr[1];
11570
11571 if (!rdev->ops->crit_proto_stop)
11572 return -EOPNOTSUPP;
11573
11574 if (rdev->crit_proto_nlportid) {
11575 rdev->crit_proto_nlportid = 0;
11576 rdev_crit_proto_stop(rdev, wdev);
11577 }
11578 return 0;
11579}
11580
Johannes Bergad7e7182013-11-13 13:37:47 +010011581static int nl80211_vendor_cmd(struct sk_buff *skb, struct genl_info *info)
11582{
11583 struct cfg80211_registered_device *rdev = info->user_ptr[0];
11584 struct wireless_dev *wdev =
11585 __cfg80211_wdev_from_attrs(genl_info_net(info), info->attrs);
11586 int i, err;
11587 u32 vid, subcmd;
11588
11589 if (!rdev->wiphy.vendor_commands)
11590 return -EOPNOTSUPP;
11591
11592 if (IS_ERR(wdev)) {
11593 err = PTR_ERR(wdev);
11594 if (err != -EINVAL)
11595 return err;
11596 wdev = NULL;
11597 } else if (wdev->wiphy != &rdev->wiphy) {
11598 return -EINVAL;
11599 }
11600
11601 if (!info->attrs[NL80211_ATTR_VENDOR_ID] ||
11602 !info->attrs[NL80211_ATTR_VENDOR_SUBCMD])
11603 return -EINVAL;
11604
11605 vid = nla_get_u32(info->attrs[NL80211_ATTR_VENDOR_ID]);
11606 subcmd = nla_get_u32(info->attrs[NL80211_ATTR_VENDOR_SUBCMD]);
11607 for (i = 0; i < rdev->wiphy.n_vendor_commands; i++) {
11608 const struct wiphy_vendor_command *vcmd;
11609 void *data = NULL;
11610 int len = 0;
11611
11612 vcmd = &rdev->wiphy.vendor_commands[i];
11613
11614 if (vcmd->info.vendor_id != vid || vcmd->info.subcmd != subcmd)
11615 continue;
11616
11617 if (vcmd->flags & (WIPHY_VENDOR_CMD_NEED_WDEV |
11618 WIPHY_VENDOR_CMD_NEED_NETDEV)) {
11619 if (!wdev)
11620 return -EINVAL;
11621 if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_NETDEV &&
11622 !wdev->netdev)
11623 return -EINVAL;
11624
11625 if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_RUNNING) {
Arend Van Spriel73c7da32016-10-20 20:08:22 +010011626 if (!wdev_running(wdev))
Johannes Bergad7e7182013-11-13 13:37:47 +010011627 return -ENETDOWN;
11628 }
Johannes Berg7bdbe402015-08-15 22:39:49 +030011629
11630 if (!vcmd->doit)
11631 return -EOPNOTSUPP;
Johannes Bergad7e7182013-11-13 13:37:47 +010011632 } else {
11633 wdev = NULL;
11634 }
11635
11636 if (info->attrs[NL80211_ATTR_VENDOR_DATA]) {
11637 data = nla_data(info->attrs[NL80211_ATTR_VENDOR_DATA]);
11638 len = nla_len(info->attrs[NL80211_ATTR_VENDOR_DATA]);
11639 }
11640
11641 rdev->cur_cmd_info = info;
11642 err = rdev->wiphy.vendor_commands[i].doit(&rdev->wiphy, wdev,
11643 data, len);
11644 rdev->cur_cmd_info = NULL;
11645 return err;
11646 }
11647
11648 return -EOPNOTSUPP;
11649}
11650
Johannes Berg7bdbe402015-08-15 22:39:49 +030011651static int nl80211_prepare_vendor_dump(struct sk_buff *skb,
11652 struct netlink_callback *cb,
11653 struct cfg80211_registered_device **rdev,
11654 struct wireless_dev **wdev)
11655{
Johannes Bergc90c39d2016-10-24 14:40:01 +020011656 struct nlattr **attrbuf = genl_family_attrbuf(&nl80211_fam);
Johannes Berg7bdbe402015-08-15 22:39:49 +030011657 u32 vid, subcmd;
11658 unsigned int i;
11659 int vcmd_idx = -1;
11660 int err;
11661 void *data = NULL;
11662 unsigned int data_len = 0;
11663
11664 rtnl_lock();
11665
11666 if (cb->args[0]) {
11667 /* subtract the 1 again here */
11668 struct wiphy *wiphy = wiphy_idx_to_wiphy(cb->args[0] - 1);
11669 struct wireless_dev *tmp;
11670
11671 if (!wiphy) {
11672 err = -ENODEV;
11673 goto out_unlock;
11674 }
11675 *rdev = wiphy_to_rdev(wiphy);
11676 *wdev = NULL;
11677
11678 if (cb->args[1]) {
Johannes Berg53873f12016-05-03 16:52:04 +030011679 list_for_each_entry(tmp, &wiphy->wdev_list, list) {
Johannes Berg7bdbe402015-08-15 22:39:49 +030011680 if (tmp->identifier == cb->args[1] - 1) {
11681 *wdev = tmp;
11682 break;
11683 }
11684 }
11685 }
11686
11687 /* keep rtnl locked in successful case */
11688 return 0;
11689 }
11690
11691 err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize,
Johannes Bergc90c39d2016-10-24 14:40:01 +020011692 attrbuf, nl80211_fam.maxattr, nl80211_policy);
Johannes Berg7bdbe402015-08-15 22:39:49 +030011693 if (err)
11694 goto out_unlock;
11695
Johannes Bergc90c39d2016-10-24 14:40:01 +020011696 if (!attrbuf[NL80211_ATTR_VENDOR_ID] ||
11697 !attrbuf[NL80211_ATTR_VENDOR_SUBCMD]) {
Johannes Berg7bdbe402015-08-15 22:39:49 +030011698 err = -EINVAL;
11699 goto out_unlock;
11700 }
11701
Johannes Bergc90c39d2016-10-24 14:40:01 +020011702 *wdev = __cfg80211_wdev_from_attrs(sock_net(skb->sk), attrbuf);
Johannes Berg7bdbe402015-08-15 22:39:49 +030011703 if (IS_ERR(*wdev))
11704 *wdev = NULL;
11705
Johannes Bergc90c39d2016-10-24 14:40:01 +020011706 *rdev = __cfg80211_rdev_from_attrs(sock_net(skb->sk), attrbuf);
Johannes Berg7bdbe402015-08-15 22:39:49 +030011707 if (IS_ERR(*rdev)) {
11708 err = PTR_ERR(*rdev);
11709 goto out_unlock;
11710 }
11711
Johannes Bergc90c39d2016-10-24 14:40:01 +020011712 vid = nla_get_u32(attrbuf[NL80211_ATTR_VENDOR_ID]);
11713 subcmd = nla_get_u32(attrbuf[NL80211_ATTR_VENDOR_SUBCMD]);
Johannes Berg7bdbe402015-08-15 22:39:49 +030011714
11715 for (i = 0; i < (*rdev)->wiphy.n_vendor_commands; i++) {
11716 const struct wiphy_vendor_command *vcmd;
11717
11718 vcmd = &(*rdev)->wiphy.vendor_commands[i];
11719
11720 if (vcmd->info.vendor_id != vid || vcmd->info.subcmd != subcmd)
11721 continue;
11722
11723 if (!vcmd->dumpit) {
11724 err = -EOPNOTSUPP;
11725 goto out_unlock;
11726 }
11727
11728 vcmd_idx = i;
11729 break;
11730 }
11731
11732 if (vcmd_idx < 0) {
11733 err = -EOPNOTSUPP;
11734 goto out_unlock;
11735 }
11736
Johannes Bergc90c39d2016-10-24 14:40:01 +020011737 if (attrbuf[NL80211_ATTR_VENDOR_DATA]) {
11738 data = nla_data(attrbuf[NL80211_ATTR_VENDOR_DATA]);
11739 data_len = nla_len(attrbuf[NL80211_ATTR_VENDOR_DATA]);
Johannes Berg7bdbe402015-08-15 22:39:49 +030011740 }
11741
11742 /* 0 is the first index - add 1 to parse only once */
11743 cb->args[0] = (*rdev)->wiphy_idx + 1;
11744 /* add 1 to know if it was NULL */
11745 cb->args[1] = *wdev ? (*wdev)->identifier + 1 : 0;
11746 cb->args[2] = vcmd_idx;
11747 cb->args[3] = (unsigned long)data;
11748 cb->args[4] = data_len;
11749
11750 /* keep rtnl locked in successful case */
11751 return 0;
11752 out_unlock:
11753 rtnl_unlock();
11754 return err;
11755}
11756
11757static int nl80211_vendor_cmd_dump(struct sk_buff *skb,
11758 struct netlink_callback *cb)
11759{
11760 struct cfg80211_registered_device *rdev;
11761 struct wireless_dev *wdev;
11762 unsigned int vcmd_idx;
11763 const struct wiphy_vendor_command *vcmd;
11764 void *data;
11765 int data_len;
11766 int err;
11767 struct nlattr *vendor_data;
11768
11769 err = nl80211_prepare_vendor_dump(skb, cb, &rdev, &wdev);
11770 if (err)
11771 return err;
11772
11773 vcmd_idx = cb->args[2];
11774 data = (void *)cb->args[3];
11775 data_len = cb->args[4];
11776 vcmd = &rdev->wiphy.vendor_commands[vcmd_idx];
11777
11778 if (vcmd->flags & (WIPHY_VENDOR_CMD_NEED_WDEV |
11779 WIPHY_VENDOR_CMD_NEED_NETDEV)) {
11780 if (!wdev)
11781 return -EINVAL;
11782 if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_NETDEV &&
11783 !wdev->netdev)
11784 return -EINVAL;
11785
11786 if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_RUNNING) {
Arend Van Spriel73c7da32016-10-20 20:08:22 +010011787 if (!wdev_running(wdev))
Johannes Berg7bdbe402015-08-15 22:39:49 +030011788 return -ENETDOWN;
11789 }
11790 }
11791
11792 while (1) {
11793 void *hdr = nl80211hdr_put(skb, NETLINK_CB(cb->skb).portid,
11794 cb->nlh->nlmsg_seq, NLM_F_MULTI,
11795 NL80211_CMD_VENDOR);
11796 if (!hdr)
11797 break;
11798
11799 if (nla_put_u32(skb, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020011800 (wdev && nla_put_u64_64bit(skb, NL80211_ATTR_WDEV,
11801 wdev_id(wdev),
11802 NL80211_ATTR_PAD))) {
Johannes Berg7bdbe402015-08-15 22:39:49 +030011803 genlmsg_cancel(skb, hdr);
11804 break;
11805 }
11806
11807 vendor_data = nla_nest_start(skb, NL80211_ATTR_VENDOR_DATA);
11808 if (!vendor_data) {
11809 genlmsg_cancel(skb, hdr);
11810 break;
11811 }
11812
11813 err = vcmd->dumpit(&rdev->wiphy, wdev, skb, data, data_len,
11814 (unsigned long *)&cb->args[5]);
11815 nla_nest_end(skb, vendor_data);
11816
11817 if (err == -ENOBUFS || err == -ENOENT) {
11818 genlmsg_cancel(skb, hdr);
11819 break;
11820 } else if (err) {
11821 genlmsg_cancel(skb, hdr);
11822 goto out;
11823 }
11824
11825 genlmsg_end(skb, hdr);
11826 }
11827
11828 err = skb->len;
11829 out:
11830 rtnl_unlock();
11831 return err;
11832}
11833
Johannes Bergad7e7182013-11-13 13:37:47 +010011834struct sk_buff *__cfg80211_alloc_reply_skb(struct wiphy *wiphy,
11835 enum nl80211_commands cmd,
11836 enum nl80211_attrs attr,
11837 int approxlen)
11838{
Zhao, Gangf26cbf42014-04-21 12:53:03 +080011839 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Bergad7e7182013-11-13 13:37:47 +010011840
11841 if (WARN_ON(!rdev->cur_cmd_info))
11842 return NULL;
11843
Ahmad Kholaif6c09e792015-02-26 15:26:53 +020011844 return __cfg80211_alloc_vendor_skb(rdev, NULL, approxlen,
Johannes Bergad7e7182013-11-13 13:37:47 +010011845 rdev->cur_cmd_info->snd_portid,
11846 rdev->cur_cmd_info->snd_seq,
Johannes Berg567ffc32013-12-18 14:43:31 +010011847 cmd, attr, NULL, GFP_KERNEL);
Johannes Bergad7e7182013-11-13 13:37:47 +010011848}
11849EXPORT_SYMBOL(__cfg80211_alloc_reply_skb);
11850
11851int cfg80211_vendor_cmd_reply(struct sk_buff *skb)
11852{
11853 struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0];
11854 void *hdr = ((void **)skb->cb)[1];
11855 struct nlattr *data = ((void **)skb->cb)[2];
11856
Johannes Bergbd8c78e2014-07-30 14:55:26 +020011857 /* clear CB data for netlink core to own from now on */
11858 memset(skb->cb, 0, sizeof(skb->cb));
11859
Johannes Bergad7e7182013-11-13 13:37:47 +010011860 if (WARN_ON(!rdev->cur_cmd_info)) {
11861 kfree_skb(skb);
11862 return -EINVAL;
11863 }
11864
11865 nla_nest_end(skb, data);
11866 genlmsg_end(skb, hdr);
11867 return genlmsg_reply(skb, rdev->cur_cmd_info);
11868}
11869EXPORT_SYMBOL_GPL(cfg80211_vendor_cmd_reply);
11870
Kyeyoon Parkfa9ffc72013-12-16 23:01:30 -080011871static int nl80211_set_qos_map(struct sk_buff *skb,
11872 struct genl_info *info)
11873{
11874 struct cfg80211_registered_device *rdev = info->user_ptr[0];
11875 struct cfg80211_qos_map *qos_map = NULL;
11876 struct net_device *dev = info->user_ptr[1];
11877 u8 *pos, len, num_des, des_len, des;
11878 int ret;
11879
11880 if (!rdev->ops->set_qos_map)
11881 return -EOPNOTSUPP;
11882
11883 if (info->attrs[NL80211_ATTR_QOS_MAP]) {
11884 pos = nla_data(info->attrs[NL80211_ATTR_QOS_MAP]);
11885 len = nla_len(info->attrs[NL80211_ATTR_QOS_MAP]);
11886
11887 if (len % 2 || len < IEEE80211_QOS_MAP_LEN_MIN ||
11888 len > IEEE80211_QOS_MAP_LEN_MAX)
11889 return -EINVAL;
11890
11891 qos_map = kzalloc(sizeof(struct cfg80211_qos_map), GFP_KERNEL);
11892 if (!qos_map)
11893 return -ENOMEM;
11894
11895 num_des = (len - IEEE80211_QOS_MAP_LEN_MIN) >> 1;
11896 if (num_des) {
11897 des_len = num_des *
11898 sizeof(struct cfg80211_dscp_exception);
11899 memcpy(qos_map->dscp_exception, pos, des_len);
11900 qos_map->num_des = num_des;
11901 for (des = 0; des < num_des; des++) {
11902 if (qos_map->dscp_exception[des].up > 7) {
11903 kfree(qos_map);
11904 return -EINVAL;
11905 }
11906 }
11907 pos += des_len;
11908 }
11909 memcpy(qos_map->up, pos, IEEE80211_QOS_MAP_LEN_MIN);
11910 }
11911
11912 wdev_lock(dev->ieee80211_ptr);
11913 ret = nl80211_key_allowed(dev->ieee80211_ptr);
11914 if (!ret)
11915 ret = rdev_set_qos_map(rdev, dev, qos_map);
11916 wdev_unlock(dev->ieee80211_ptr);
11917
11918 kfree(qos_map);
11919 return ret;
11920}
11921
Johannes Berg960d01a2014-09-09 22:55:35 +030011922static int nl80211_add_tx_ts(struct sk_buff *skb, struct genl_info *info)
11923{
11924 struct cfg80211_registered_device *rdev = info->user_ptr[0];
11925 struct net_device *dev = info->user_ptr[1];
11926 struct wireless_dev *wdev = dev->ieee80211_ptr;
11927 const u8 *peer;
11928 u8 tsid, up;
11929 u16 admitted_time = 0;
11930 int err;
11931
Johannes Berg723e73a2014-10-22 09:25:06 +020011932 if (!(rdev->wiphy.features & NL80211_FEATURE_SUPPORTS_WMM_ADMISSION))
Johannes Berg960d01a2014-09-09 22:55:35 +030011933 return -EOPNOTSUPP;
11934
11935 if (!info->attrs[NL80211_ATTR_TSID] || !info->attrs[NL80211_ATTR_MAC] ||
11936 !info->attrs[NL80211_ATTR_USER_PRIO])
11937 return -EINVAL;
11938
11939 tsid = nla_get_u8(info->attrs[NL80211_ATTR_TSID]);
11940 if (tsid >= IEEE80211_NUM_TIDS)
11941 return -EINVAL;
11942
11943 up = nla_get_u8(info->attrs[NL80211_ATTR_USER_PRIO]);
11944 if (up >= IEEE80211_NUM_UPS)
11945 return -EINVAL;
11946
11947 /* WMM uses TIDs 0-7 even for TSPEC */
Johannes Berg723e73a2014-10-22 09:25:06 +020011948 if (tsid >= IEEE80211_FIRST_TSPEC_TSID) {
Johannes Berg960d01a2014-09-09 22:55:35 +030011949 /* TODO: handle 802.11 TSPEC/admission control
Johannes Berg723e73a2014-10-22 09:25:06 +020011950 * need more attributes for that (e.g. BA session requirement);
11951 * change the WMM adminssion test above to allow both then
Johannes Berg960d01a2014-09-09 22:55:35 +030011952 */
11953 return -EINVAL;
11954 }
11955
11956 peer = nla_data(info->attrs[NL80211_ATTR_MAC]);
11957
11958 if (info->attrs[NL80211_ATTR_ADMITTED_TIME]) {
11959 admitted_time =
11960 nla_get_u16(info->attrs[NL80211_ATTR_ADMITTED_TIME]);
11961 if (!admitted_time)
11962 return -EINVAL;
11963 }
11964
11965 wdev_lock(wdev);
11966 switch (wdev->iftype) {
11967 case NL80211_IFTYPE_STATION:
11968 case NL80211_IFTYPE_P2P_CLIENT:
11969 if (wdev->current_bss)
11970 break;
11971 err = -ENOTCONN;
11972 goto out;
11973 default:
11974 err = -EOPNOTSUPP;
11975 goto out;
11976 }
11977
11978 err = rdev_add_tx_ts(rdev, dev, tsid, peer, up, admitted_time);
11979
11980 out:
11981 wdev_unlock(wdev);
11982 return err;
11983}
11984
11985static int nl80211_del_tx_ts(struct sk_buff *skb, struct genl_info *info)
11986{
11987 struct cfg80211_registered_device *rdev = info->user_ptr[0];
11988 struct net_device *dev = info->user_ptr[1];
11989 struct wireless_dev *wdev = dev->ieee80211_ptr;
11990 const u8 *peer;
11991 u8 tsid;
11992 int err;
11993
11994 if (!info->attrs[NL80211_ATTR_TSID] || !info->attrs[NL80211_ATTR_MAC])
11995 return -EINVAL;
11996
11997 tsid = nla_get_u8(info->attrs[NL80211_ATTR_TSID]);
11998 peer = nla_data(info->attrs[NL80211_ATTR_MAC]);
11999
12000 wdev_lock(wdev);
12001 err = rdev_del_tx_ts(rdev, dev, tsid, peer);
12002 wdev_unlock(wdev);
12003
12004 return err;
12005}
12006
Arik Nemtsov1057d352014-11-19 12:54:26 +020012007static int nl80211_tdls_channel_switch(struct sk_buff *skb,
12008 struct genl_info *info)
12009{
12010 struct cfg80211_registered_device *rdev = info->user_ptr[0];
12011 struct net_device *dev = info->user_ptr[1];
12012 struct wireless_dev *wdev = dev->ieee80211_ptr;
12013 struct cfg80211_chan_def chandef = {};
12014 const u8 *addr;
12015 u8 oper_class;
12016 int err;
12017
12018 if (!rdev->ops->tdls_channel_switch ||
12019 !(rdev->wiphy.features & NL80211_FEATURE_TDLS_CHANNEL_SWITCH))
12020 return -EOPNOTSUPP;
12021
12022 switch (dev->ieee80211_ptr->iftype) {
12023 case NL80211_IFTYPE_STATION:
12024 case NL80211_IFTYPE_P2P_CLIENT:
12025 break;
12026 default:
12027 return -EOPNOTSUPP;
12028 }
12029
12030 if (!info->attrs[NL80211_ATTR_MAC] ||
12031 !info->attrs[NL80211_ATTR_OPER_CLASS])
12032 return -EINVAL;
12033
12034 err = nl80211_parse_chandef(rdev, info, &chandef);
12035 if (err)
12036 return err;
12037
12038 /*
12039 * Don't allow wide channels on the 2.4Ghz band, as per IEEE802.11-2012
12040 * section 10.22.6.2.1. Disallow 5/10Mhz channels as well for now, the
12041 * specification is not defined for them.
12042 */
Johannes Berg57fbcce2016-04-12 15:56:15 +020012043 if (chandef.chan->band == NL80211_BAND_2GHZ &&
Arik Nemtsov1057d352014-11-19 12:54:26 +020012044 chandef.width != NL80211_CHAN_WIDTH_20_NOHT &&
12045 chandef.width != NL80211_CHAN_WIDTH_20)
12046 return -EINVAL;
12047
12048 /* we will be active on the TDLS link */
Arik Nemtsov923b3522015-07-08 15:41:44 +030012049 if (!cfg80211_reg_can_beacon_relax(&rdev->wiphy, &chandef,
12050 wdev->iftype))
Arik Nemtsov1057d352014-11-19 12:54:26 +020012051 return -EINVAL;
12052
12053 /* don't allow switching to DFS channels */
12054 if (cfg80211_chandef_dfs_required(wdev->wiphy, &chandef, wdev->iftype))
12055 return -EINVAL;
12056
12057 addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
12058 oper_class = nla_get_u8(info->attrs[NL80211_ATTR_OPER_CLASS]);
12059
12060 wdev_lock(wdev);
12061 err = rdev_tdls_channel_switch(rdev, dev, addr, oper_class, &chandef);
12062 wdev_unlock(wdev);
12063
12064 return err;
12065}
12066
12067static int nl80211_tdls_cancel_channel_switch(struct sk_buff *skb,
12068 struct genl_info *info)
12069{
12070 struct cfg80211_registered_device *rdev = info->user_ptr[0];
12071 struct net_device *dev = info->user_ptr[1];
12072 struct wireless_dev *wdev = dev->ieee80211_ptr;
12073 const u8 *addr;
12074
12075 if (!rdev->ops->tdls_channel_switch ||
12076 !rdev->ops->tdls_cancel_channel_switch ||
12077 !(rdev->wiphy.features & NL80211_FEATURE_TDLS_CHANNEL_SWITCH))
12078 return -EOPNOTSUPP;
12079
12080 switch (dev->ieee80211_ptr->iftype) {
12081 case NL80211_IFTYPE_STATION:
12082 case NL80211_IFTYPE_P2P_CLIENT:
12083 break;
12084 default:
12085 return -EOPNOTSUPP;
12086 }
12087
12088 if (!info->attrs[NL80211_ATTR_MAC])
12089 return -EINVAL;
12090
12091 addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
12092
12093 wdev_lock(wdev);
12094 rdev_tdls_cancel_channel_switch(rdev, dev, addr);
12095 wdev_unlock(wdev);
12096
12097 return 0;
12098}
12099
Michael Braunce0ce132016-10-10 19:12:22 +020012100static int nl80211_set_multicast_to_unicast(struct sk_buff *skb,
12101 struct genl_info *info)
12102{
12103 struct cfg80211_registered_device *rdev = info->user_ptr[0];
12104 struct net_device *dev = info->user_ptr[1];
12105 struct wireless_dev *wdev = dev->ieee80211_ptr;
12106 const struct nlattr *nla;
12107 bool enabled;
12108
Michael Braunce0ce132016-10-10 19:12:22 +020012109 if (!rdev->ops->set_multicast_to_unicast)
12110 return -EOPNOTSUPP;
12111
12112 if (wdev->iftype != NL80211_IFTYPE_AP &&
12113 wdev->iftype != NL80211_IFTYPE_P2P_GO)
12114 return -EOPNOTSUPP;
12115
12116 nla = info->attrs[NL80211_ATTR_MULTICAST_TO_UNICAST_ENABLED];
12117 enabled = nla_get_flag(nla);
12118
12119 return rdev_set_multicast_to_unicast(rdev, dev, enabled);
12120}
12121
Johannes Berg4c476992010-10-04 21:36:35 +020012122#define NL80211_FLAG_NEED_WIPHY 0x01
12123#define NL80211_FLAG_NEED_NETDEV 0x02
12124#define NL80211_FLAG_NEED_RTNL 0x04
Johannes Berg41265712010-10-04 21:14:05 +020012125#define NL80211_FLAG_CHECK_NETDEV_UP 0x08
12126#define NL80211_FLAG_NEED_NETDEV_UP (NL80211_FLAG_NEED_NETDEV |\
12127 NL80211_FLAG_CHECK_NETDEV_UP)
Johannes Berg1bf614e2012-06-15 15:23:36 +020012128#define NL80211_FLAG_NEED_WDEV 0x10
Johannes Berg98104fde2012-06-16 00:19:54 +020012129/* If a netdev is associated, it must be UP, P2P must be started */
Johannes Berg1bf614e2012-06-15 15:23:36 +020012130#define NL80211_FLAG_NEED_WDEV_UP (NL80211_FLAG_NEED_WDEV |\
12131 NL80211_FLAG_CHECK_NETDEV_UP)
Johannes Berg5393b912014-09-10 15:00:16 +030012132#define NL80211_FLAG_CLEAR_SKB 0x20
Johannes Berg4c476992010-10-04 21:36:35 +020012133
Johannes Bergf84f7712013-11-14 17:14:45 +010012134static int nl80211_pre_doit(const struct genl_ops *ops, struct sk_buff *skb,
Johannes Berg4c476992010-10-04 21:36:35 +020012135 struct genl_info *info)
12136{
12137 struct cfg80211_registered_device *rdev;
Johannes Berg89a54e42012-06-15 14:33:17 +020012138 struct wireless_dev *wdev;
Johannes Berg4c476992010-10-04 21:36:35 +020012139 struct net_device *dev;
Johannes Berg4c476992010-10-04 21:36:35 +020012140 bool rtnl = ops->internal_flags & NL80211_FLAG_NEED_RTNL;
12141
12142 if (rtnl)
12143 rtnl_lock();
12144
12145 if (ops->internal_flags & NL80211_FLAG_NEED_WIPHY) {
Johannes Berg4f7eff12012-06-15 14:14:22 +020012146 rdev = cfg80211_get_dev_from_info(genl_info_net(info), info);
Johannes Berg4c476992010-10-04 21:36:35 +020012147 if (IS_ERR(rdev)) {
12148 if (rtnl)
12149 rtnl_unlock();
12150 return PTR_ERR(rdev);
12151 }
12152 info->user_ptr[0] = rdev;
Johannes Berg1bf614e2012-06-15 15:23:36 +020012153 } else if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV ||
12154 ops->internal_flags & NL80211_FLAG_NEED_WDEV) {
Johannes Berg5fe231e2013-05-08 21:45:15 +020012155 ASSERT_RTNL();
12156
Johannes Berg89a54e42012-06-15 14:33:17 +020012157 wdev = __cfg80211_wdev_from_attrs(genl_info_net(info),
12158 info->attrs);
12159 if (IS_ERR(wdev)) {
Johannes Berg4c476992010-10-04 21:36:35 +020012160 if (rtnl)
12161 rtnl_unlock();
Johannes Berg89a54e42012-06-15 14:33:17 +020012162 return PTR_ERR(wdev);
Johannes Berg4c476992010-10-04 21:36:35 +020012163 }
Johannes Berg89a54e42012-06-15 14:33:17 +020012164
Johannes Berg89a54e42012-06-15 14:33:17 +020012165 dev = wdev->netdev;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080012166 rdev = wiphy_to_rdev(wdev->wiphy);
Johannes Berg89a54e42012-06-15 14:33:17 +020012167
Johannes Berg1bf614e2012-06-15 15:23:36 +020012168 if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV) {
12169 if (!dev) {
Johannes Berg1bf614e2012-06-15 15:23:36 +020012170 if (rtnl)
12171 rtnl_unlock();
12172 return -EINVAL;
12173 }
12174
12175 info->user_ptr[1] = dev;
12176 } else {
12177 info->user_ptr[1] = wdev;
Johannes Berg41265712010-10-04 21:14:05 +020012178 }
Johannes Berg89a54e42012-06-15 14:33:17 +020012179
Arend Van Spriel73c7da32016-10-20 20:08:22 +010012180 if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP &&
12181 !wdev_running(wdev)) {
12182 if (rtnl)
12183 rtnl_unlock();
12184 return -ENETDOWN;
Johannes Berg1bf614e2012-06-15 15:23:36 +020012185 }
12186
Arend Van Spriel73c7da32016-10-20 20:08:22 +010012187 if (dev)
12188 dev_hold(dev);
12189
Johannes Berg4c476992010-10-04 21:36:35 +020012190 info->user_ptr[0] = rdev;
Johannes Berg4c476992010-10-04 21:36:35 +020012191 }
12192
12193 return 0;
12194}
12195
Johannes Bergf84f7712013-11-14 17:14:45 +010012196static void nl80211_post_doit(const struct genl_ops *ops, struct sk_buff *skb,
Johannes Berg4c476992010-10-04 21:36:35 +020012197 struct genl_info *info)
12198{
Johannes Berg1bf614e2012-06-15 15:23:36 +020012199 if (info->user_ptr[1]) {
12200 if (ops->internal_flags & NL80211_FLAG_NEED_WDEV) {
12201 struct wireless_dev *wdev = info->user_ptr[1];
12202
12203 if (wdev->netdev)
12204 dev_put(wdev->netdev);
12205 } else {
12206 dev_put(info->user_ptr[1]);
12207 }
12208 }
Johannes Berg5393b912014-09-10 15:00:16 +030012209
Johannes Berg4c476992010-10-04 21:36:35 +020012210 if (ops->internal_flags & NL80211_FLAG_NEED_RTNL)
12211 rtnl_unlock();
Johannes Berg5393b912014-09-10 15:00:16 +030012212
12213 /* If needed, clear the netlink message payload from the SKB
12214 * as it might contain key data that shouldn't stick around on
12215 * the heap after the SKB is freed. The netlink message header
12216 * is still needed for further processing, so leave it intact.
12217 */
12218 if (ops->internal_flags & NL80211_FLAG_CLEAR_SKB) {
12219 struct nlmsghdr *nlh = nlmsg_hdr(skb);
12220
12221 memset(nlmsg_data(nlh), 0, nlmsg_len(nlh));
12222 }
Johannes Berg4c476992010-10-04 21:36:35 +020012223}
12224
Johannes Berg4534de82013-11-14 17:14:46 +010012225static const struct genl_ops nl80211_ops[] = {
Johannes Berg55682962007-09-20 13:09:35 -040012226 {
12227 .cmd = NL80211_CMD_GET_WIPHY,
12228 .doit = nl80211_get_wiphy,
12229 .dumpit = nl80211_dump_wiphy,
Johannes Berg86e8cf92013-06-19 10:57:22 +020012230 .done = nl80211_dump_wiphy_done,
Johannes Berg55682962007-09-20 13:09:35 -040012231 .policy = nl80211_policy,
12232 /* can be retrieved by unprivileged users */
Johannes Berg5fe231e2013-05-08 21:45:15 +020012233 .internal_flags = NL80211_FLAG_NEED_WIPHY |
12234 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -040012235 },
12236 {
12237 .cmd = NL80211_CMD_SET_WIPHY,
12238 .doit = nl80211_set_wiphy,
12239 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012240 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020012241 .internal_flags = NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -040012242 },
12243 {
12244 .cmd = NL80211_CMD_GET_INTERFACE,
12245 .doit = nl80211_get_interface,
12246 .dumpit = nl80211_dump_interface,
12247 .policy = nl80211_policy,
12248 /* can be retrieved by unprivileged users */
Johannes Berg5fe231e2013-05-08 21:45:15 +020012249 .internal_flags = NL80211_FLAG_NEED_WDEV |
12250 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -040012251 },
12252 {
12253 .cmd = NL80211_CMD_SET_INTERFACE,
12254 .doit = nl80211_set_interface,
12255 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012256 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020012257 .internal_flags = NL80211_FLAG_NEED_NETDEV |
12258 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -040012259 },
12260 {
12261 .cmd = NL80211_CMD_NEW_INTERFACE,
12262 .doit = nl80211_new_interface,
12263 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012264 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020012265 .internal_flags = NL80211_FLAG_NEED_WIPHY |
12266 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -040012267 },
12268 {
12269 .cmd = NL80211_CMD_DEL_INTERFACE,
12270 .doit = nl80211_del_interface,
12271 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012272 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg84efbb82012-06-16 00:00:26 +020012273 .internal_flags = NL80211_FLAG_NEED_WDEV |
Johannes Berg4c476992010-10-04 21:36:35 +020012274 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -040012275 },
Johannes Berg41ade002007-12-19 02:03:29 +010012276 {
12277 .cmd = NL80211_CMD_GET_KEY,
12278 .doit = nl80211_get_key,
12279 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012280 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020012281 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020012282 NL80211_FLAG_NEED_RTNL,
Johannes Berg41ade002007-12-19 02:03:29 +010012283 },
12284 {
12285 .cmd = NL80211_CMD_SET_KEY,
12286 .doit = nl80211_set_key,
12287 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012288 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020012289 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg5393b912014-09-10 15:00:16 +030012290 NL80211_FLAG_NEED_RTNL |
12291 NL80211_FLAG_CLEAR_SKB,
Johannes Berg41ade002007-12-19 02:03:29 +010012292 },
12293 {
12294 .cmd = NL80211_CMD_NEW_KEY,
12295 .doit = nl80211_new_key,
12296 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012297 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020012298 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg5393b912014-09-10 15:00:16 +030012299 NL80211_FLAG_NEED_RTNL |
12300 NL80211_FLAG_CLEAR_SKB,
Johannes Berg41ade002007-12-19 02:03:29 +010012301 },
12302 {
12303 .cmd = NL80211_CMD_DEL_KEY,
12304 .doit = nl80211_del_key,
12305 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012306 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020012307 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020012308 NL80211_FLAG_NEED_RTNL,
Johannes Berg41ade002007-12-19 02:03:29 +010012309 },
Johannes Berged1b6cc2007-12-19 02:03:32 +010012310 {
12311 .cmd = NL80211_CMD_SET_BEACON,
12312 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012313 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg88600202012-02-13 15:17:18 +010012314 .doit = nl80211_set_beacon,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020012315 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020012316 NL80211_FLAG_NEED_RTNL,
Johannes Berged1b6cc2007-12-19 02:03:32 +010012317 },
12318 {
Johannes Berg88600202012-02-13 15:17:18 +010012319 .cmd = NL80211_CMD_START_AP,
Johannes Berged1b6cc2007-12-19 02:03:32 +010012320 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012321 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg88600202012-02-13 15:17:18 +010012322 .doit = nl80211_start_ap,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020012323 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020012324 NL80211_FLAG_NEED_RTNL,
Johannes Berged1b6cc2007-12-19 02:03:32 +010012325 },
12326 {
Johannes Berg88600202012-02-13 15:17:18 +010012327 .cmd = NL80211_CMD_STOP_AP,
Johannes Berged1b6cc2007-12-19 02:03:32 +010012328 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012329 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg88600202012-02-13 15:17:18 +010012330 .doit = nl80211_stop_ap,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020012331 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020012332 NL80211_FLAG_NEED_RTNL,
Johannes Berged1b6cc2007-12-19 02:03:32 +010012333 },
Johannes Berg5727ef12007-12-19 02:03:34 +010012334 {
12335 .cmd = NL80211_CMD_GET_STATION,
12336 .doit = nl80211_get_station,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010012337 .dumpit = nl80211_dump_station,
Johannes Berg5727ef12007-12-19 02:03:34 +010012338 .policy = nl80211_policy,
Johannes Berg4c476992010-10-04 21:36:35 +020012339 .internal_flags = NL80211_FLAG_NEED_NETDEV |
12340 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +010012341 },
12342 {
12343 .cmd = NL80211_CMD_SET_STATION,
12344 .doit = nl80211_set_station,
12345 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012346 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020012347 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020012348 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +010012349 },
12350 {
12351 .cmd = NL80211_CMD_NEW_STATION,
12352 .doit = nl80211_new_station,
12353 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012354 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020012355 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020012356 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +010012357 },
12358 {
12359 .cmd = NL80211_CMD_DEL_STATION,
12360 .doit = nl80211_del_station,
12361 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012362 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020012363 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020012364 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +010012365 },
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010012366 {
12367 .cmd = NL80211_CMD_GET_MPATH,
12368 .doit = nl80211_get_mpath,
12369 .dumpit = nl80211_dump_mpath,
12370 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012371 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020012372 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020012373 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010012374 },
12375 {
Henning Rogge66be7d22014-09-12 08:58:49 +020012376 .cmd = NL80211_CMD_GET_MPP,
12377 .doit = nl80211_get_mpp,
12378 .dumpit = nl80211_dump_mpp,
12379 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012380 .flags = GENL_UNS_ADMIN_PERM,
Henning Rogge66be7d22014-09-12 08:58:49 +020012381 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
12382 NL80211_FLAG_NEED_RTNL,
12383 },
12384 {
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010012385 .cmd = NL80211_CMD_SET_MPATH,
12386 .doit = nl80211_set_mpath,
12387 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012388 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020012389 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020012390 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010012391 },
12392 {
12393 .cmd = NL80211_CMD_NEW_MPATH,
12394 .doit = nl80211_new_mpath,
12395 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012396 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020012397 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020012398 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010012399 },
12400 {
12401 .cmd = NL80211_CMD_DEL_MPATH,
12402 .doit = nl80211_del_mpath,
12403 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012404 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020012405 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020012406 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010012407 },
Jouni Malinen9f1ba902008-08-07 20:07:01 +030012408 {
12409 .cmd = NL80211_CMD_SET_BSS,
12410 .doit = nl80211_set_bss,
12411 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012412 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020012413 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020012414 NL80211_FLAG_NEED_RTNL,
Jouni Malinen9f1ba902008-08-07 20:07:01 +030012415 },
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -070012416 {
Luis R. Rodriguezf1303472009-01-30 09:26:42 -080012417 .cmd = NL80211_CMD_GET_REG,
Arik Nemtsovad30ca22014-12-15 19:25:59 +020012418 .doit = nl80211_get_reg_do,
12419 .dumpit = nl80211_get_reg_dump,
Luis R. Rodriguezf1303472009-01-30 09:26:42 -080012420 .policy = nl80211_policy,
Johannes Berg5fe231e2013-05-08 21:45:15 +020012421 .internal_flags = NL80211_FLAG_NEED_RTNL,
Luis R. Rodriguezf1303472009-01-30 09:26:42 -080012422 /* can be retrieved by unprivileged users */
12423 },
Johannes Bergb6863032015-10-15 09:25:18 +020012424#ifdef CONFIG_CFG80211_CRDA_SUPPORT
Luis R. Rodriguezf1303472009-01-30 09:26:42 -080012425 {
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -070012426 .cmd = NL80211_CMD_SET_REG,
12427 .doit = nl80211_set_reg,
12428 .policy = nl80211_policy,
12429 .flags = GENL_ADMIN_PERM,
Johannes Berg5fe231e2013-05-08 21:45:15 +020012430 .internal_flags = NL80211_FLAG_NEED_RTNL,
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -070012431 },
Johannes Bergb6863032015-10-15 09:25:18 +020012432#endif
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -070012433 {
12434 .cmd = NL80211_CMD_REQ_SET_REG,
12435 .doit = nl80211_req_set_reg,
12436 .policy = nl80211_policy,
12437 .flags = GENL_ADMIN_PERM,
12438 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -070012439 {
Javier Cardona24bdd9f2010-12-16 17:37:48 -080012440 .cmd = NL80211_CMD_GET_MESH_CONFIG,
12441 .doit = nl80211_get_mesh_config,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -070012442 .policy = nl80211_policy,
12443 /* can be retrieved by unprivileged users */
Johannes Berg2b5f8b02012-04-02 10:51:55 +020012444 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020012445 NL80211_FLAG_NEED_RTNL,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -070012446 },
12447 {
Javier Cardona24bdd9f2010-12-16 17:37:48 -080012448 .cmd = NL80211_CMD_SET_MESH_CONFIG,
12449 .doit = nl80211_update_mesh_config,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -070012450 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012451 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg29cbe682010-12-03 09:20:44 +010012452 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020012453 NL80211_FLAG_NEED_RTNL,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -070012454 },
Jouni Malinen9aed3cc2009-01-13 16:03:29 +020012455 {
Johannes Berg2a519312009-02-10 21:25:55 +010012456 .cmd = NL80211_CMD_TRIGGER_SCAN,
12457 .doit = nl80211_trigger_scan,
12458 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012459 .flags = GENL_UNS_ADMIN_PERM,
Johannes Bergfd014282012-06-18 19:17:03 +020012460 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020012461 NL80211_FLAG_NEED_RTNL,
Johannes Berg2a519312009-02-10 21:25:55 +010012462 },
12463 {
Vidyullatha Kanchanapally91d3ab42015-10-30 19:14:49 +053012464 .cmd = NL80211_CMD_ABORT_SCAN,
12465 .doit = nl80211_abort_scan,
12466 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012467 .flags = GENL_UNS_ADMIN_PERM,
Vidyullatha Kanchanapally91d3ab42015-10-30 19:14:49 +053012468 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
12469 NL80211_FLAG_NEED_RTNL,
12470 },
12471 {
Johannes Berg2a519312009-02-10 21:25:55 +010012472 .cmd = NL80211_CMD_GET_SCAN,
12473 .policy = nl80211_policy,
12474 .dumpit = nl80211_dump_scan,
12475 },
Jouni Malinen636a5d32009-03-19 13:39:22 +020012476 {
Luciano Coelho807f8a82011-05-11 17:09:35 +030012477 .cmd = NL80211_CMD_START_SCHED_SCAN,
12478 .doit = nl80211_start_sched_scan,
12479 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012480 .flags = GENL_UNS_ADMIN_PERM,
Luciano Coelho807f8a82011-05-11 17:09:35 +030012481 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
12482 NL80211_FLAG_NEED_RTNL,
12483 },
12484 {
12485 .cmd = NL80211_CMD_STOP_SCHED_SCAN,
12486 .doit = nl80211_stop_sched_scan,
12487 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012488 .flags = GENL_UNS_ADMIN_PERM,
Luciano Coelho807f8a82011-05-11 17:09:35 +030012489 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
12490 NL80211_FLAG_NEED_RTNL,
12491 },
12492 {
Jouni Malinen636a5d32009-03-19 13:39:22 +020012493 .cmd = NL80211_CMD_AUTHENTICATE,
12494 .doit = nl80211_authenticate,
12495 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012496 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020012497 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg5393b912014-09-10 15:00:16 +030012498 NL80211_FLAG_NEED_RTNL |
12499 NL80211_FLAG_CLEAR_SKB,
Jouni Malinen636a5d32009-03-19 13:39:22 +020012500 },
12501 {
12502 .cmd = NL80211_CMD_ASSOCIATE,
12503 .doit = nl80211_associate,
12504 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012505 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020012506 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020012507 NL80211_FLAG_NEED_RTNL,
Jouni Malinen636a5d32009-03-19 13:39:22 +020012508 },
12509 {
12510 .cmd = NL80211_CMD_DEAUTHENTICATE,
12511 .doit = nl80211_deauthenticate,
12512 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012513 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020012514 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020012515 NL80211_FLAG_NEED_RTNL,
Jouni Malinen636a5d32009-03-19 13:39:22 +020012516 },
12517 {
12518 .cmd = NL80211_CMD_DISASSOCIATE,
12519 .doit = nl80211_disassociate,
12520 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012521 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020012522 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020012523 NL80211_FLAG_NEED_RTNL,
Jouni Malinen636a5d32009-03-19 13:39:22 +020012524 },
Johannes Berg04a773a2009-04-19 21:24:32 +020012525 {
12526 .cmd = NL80211_CMD_JOIN_IBSS,
12527 .doit = nl80211_join_ibss,
12528 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012529 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020012530 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020012531 NL80211_FLAG_NEED_RTNL,
Johannes Berg04a773a2009-04-19 21:24:32 +020012532 },
12533 {
12534 .cmd = NL80211_CMD_LEAVE_IBSS,
12535 .doit = nl80211_leave_ibss,
12536 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012537 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020012538 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020012539 NL80211_FLAG_NEED_RTNL,
Johannes Berg04a773a2009-04-19 21:24:32 +020012540 },
Johannes Bergaff89a92009-07-01 21:26:51 +020012541#ifdef CONFIG_NL80211_TESTMODE
12542 {
12543 .cmd = NL80211_CMD_TESTMODE,
12544 .doit = nl80211_testmode_do,
Wey-Yi Guy71063f02011-05-20 09:05:54 -070012545 .dumpit = nl80211_testmode_dump,
Johannes Bergaff89a92009-07-01 21:26:51 +020012546 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012547 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020012548 .internal_flags = NL80211_FLAG_NEED_WIPHY |
12549 NL80211_FLAG_NEED_RTNL,
Johannes Bergaff89a92009-07-01 21:26:51 +020012550 },
12551#endif
Samuel Ortizb23aa672009-07-01 21:26:54 +020012552 {
12553 .cmd = NL80211_CMD_CONNECT,
12554 .doit = nl80211_connect,
12555 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012556 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020012557 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020012558 NL80211_FLAG_NEED_RTNL,
Samuel Ortizb23aa672009-07-01 21:26:54 +020012559 },
12560 {
vamsi krishna088e8df2016-10-27 16:51:11 +030012561 .cmd = NL80211_CMD_UPDATE_CONNECT_PARAMS,
12562 .doit = nl80211_update_connect_params,
12563 .policy = nl80211_policy,
12564 .flags = GENL_ADMIN_PERM,
12565 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
12566 NL80211_FLAG_NEED_RTNL,
12567 },
12568 {
Samuel Ortizb23aa672009-07-01 21:26:54 +020012569 .cmd = NL80211_CMD_DISCONNECT,
12570 .doit = nl80211_disconnect,
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,
Samuel Ortizb23aa672009-07-01 21:26:54 +020012575 },
Johannes Berg463d0182009-07-14 00:33:35 +020012576 {
12577 .cmd = NL80211_CMD_SET_WIPHY_NETNS,
12578 .doit = nl80211_wiphy_netns,
12579 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012580 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020012581 .internal_flags = NL80211_FLAG_NEED_WIPHY |
12582 NL80211_FLAG_NEED_RTNL,
Johannes Berg463d0182009-07-14 00:33:35 +020012583 },
Holger Schurig61fa7132009-11-11 12:25:40 +010012584 {
12585 .cmd = NL80211_CMD_GET_SURVEY,
12586 .policy = nl80211_policy,
12587 .dumpit = nl80211_dump_survey,
12588 },
Samuel Ortiz67fbb162009-11-24 23:59:15 +010012589 {
12590 .cmd = NL80211_CMD_SET_PMKSA,
12591 .doit = nl80211_setdel_pmksa,
12592 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012593 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020012594 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020012595 NL80211_FLAG_NEED_RTNL,
Samuel Ortiz67fbb162009-11-24 23:59:15 +010012596 },
12597 {
12598 .cmd = NL80211_CMD_DEL_PMKSA,
12599 .doit = nl80211_setdel_pmksa,
12600 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012601 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020012602 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020012603 NL80211_FLAG_NEED_RTNL,
Samuel Ortiz67fbb162009-11-24 23:59:15 +010012604 },
12605 {
12606 .cmd = NL80211_CMD_FLUSH_PMKSA,
12607 .doit = nl80211_flush_pmksa,
12608 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012609 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020012610 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020012611 NL80211_FLAG_NEED_RTNL,
Samuel Ortiz67fbb162009-11-24 23:59:15 +010012612 },
Jouni Malinen9588bbd2009-12-23 13:15:41 +010012613 {
12614 .cmd = NL80211_CMD_REMAIN_ON_CHANNEL,
12615 .doit = nl80211_remain_on_channel,
12616 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012617 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +020012618 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020012619 NL80211_FLAG_NEED_RTNL,
Jouni Malinen9588bbd2009-12-23 13:15:41 +010012620 },
12621 {
12622 .cmd = NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL,
12623 .doit = nl80211_cancel_remain_on_channel,
12624 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012625 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +020012626 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020012627 NL80211_FLAG_NEED_RTNL,
Jouni Malinen9588bbd2009-12-23 13:15:41 +010012628 },
Jouni Malinen13ae75b2009-12-29 12:59:45 +020012629 {
12630 .cmd = NL80211_CMD_SET_TX_BITRATE_MASK,
12631 .doit = nl80211_set_tx_bitrate_mask,
12632 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012633 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020012634 .internal_flags = NL80211_FLAG_NEED_NETDEV |
12635 NL80211_FLAG_NEED_RTNL,
Jouni Malinen13ae75b2009-12-29 12:59:45 +020012636 },
Jouni Malinen026331c2010-02-15 12:53:10 +020012637 {
Johannes Berg2e161f72010-08-12 15:38:38 +020012638 .cmd = NL80211_CMD_REGISTER_FRAME,
12639 .doit = nl80211_register_mgmt,
Jouni Malinen026331c2010-02-15 12:53:10 +020012640 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012641 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +020012642 .internal_flags = NL80211_FLAG_NEED_WDEV |
Johannes Berg4c476992010-10-04 21:36:35 +020012643 NL80211_FLAG_NEED_RTNL,
Jouni Malinen026331c2010-02-15 12:53:10 +020012644 },
12645 {
Johannes Berg2e161f72010-08-12 15:38:38 +020012646 .cmd = NL80211_CMD_FRAME,
12647 .doit = nl80211_tx_mgmt,
Jouni Malinen026331c2010-02-15 12:53:10 +020012648 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012649 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +020012650 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020012651 NL80211_FLAG_NEED_RTNL,
Jouni Malinen026331c2010-02-15 12:53:10 +020012652 },
Kalle Valoffb9eb32010-02-17 17:58:10 +020012653 {
Johannes Bergf7ca38d2010-11-25 10:02:29 +010012654 .cmd = NL80211_CMD_FRAME_WAIT_CANCEL,
12655 .doit = nl80211_tx_mgmt_cancel_wait,
12656 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012657 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +020012658 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Bergf7ca38d2010-11-25 10:02:29 +010012659 NL80211_FLAG_NEED_RTNL,
12660 },
12661 {
Kalle Valoffb9eb32010-02-17 17:58:10 +020012662 .cmd = NL80211_CMD_SET_POWER_SAVE,
12663 .doit = nl80211_set_power_save,
12664 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012665 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020012666 .internal_flags = NL80211_FLAG_NEED_NETDEV |
12667 NL80211_FLAG_NEED_RTNL,
Kalle Valoffb9eb32010-02-17 17:58:10 +020012668 },
12669 {
12670 .cmd = NL80211_CMD_GET_POWER_SAVE,
12671 .doit = nl80211_get_power_save,
12672 .policy = nl80211_policy,
12673 /* can be retrieved by unprivileged users */
Johannes Berg4c476992010-10-04 21:36:35 +020012674 .internal_flags = NL80211_FLAG_NEED_NETDEV |
12675 NL80211_FLAG_NEED_RTNL,
Kalle Valoffb9eb32010-02-17 17:58:10 +020012676 },
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020012677 {
12678 .cmd = NL80211_CMD_SET_CQM,
12679 .doit = nl80211_set_cqm,
12680 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012681 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020012682 .internal_flags = NL80211_FLAG_NEED_NETDEV |
12683 NL80211_FLAG_NEED_RTNL,
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020012684 },
Johannes Bergf444de02010-05-05 15:25:02 +020012685 {
12686 .cmd = NL80211_CMD_SET_CHANNEL,
12687 .doit = nl80211_set_channel,
12688 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012689 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020012690 .internal_flags = NL80211_FLAG_NEED_NETDEV |
12691 NL80211_FLAG_NEED_RTNL,
Johannes Bergf444de02010-05-05 15:25:02 +020012692 },
Bill Jordane8347eb2010-10-01 13:54:28 -040012693 {
12694 .cmd = NL80211_CMD_SET_WDS_PEER,
12695 .doit = nl80211_set_wds_peer,
12696 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012697 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg43b19952010-10-07 13:10:30 +020012698 .internal_flags = NL80211_FLAG_NEED_NETDEV |
12699 NL80211_FLAG_NEED_RTNL,
Bill Jordane8347eb2010-10-01 13:54:28 -040012700 },
Johannes Berg29cbe682010-12-03 09:20:44 +010012701 {
12702 .cmd = NL80211_CMD_JOIN_MESH,
12703 .doit = nl80211_join_mesh,
12704 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012705 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg29cbe682010-12-03 09:20:44 +010012706 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
12707 NL80211_FLAG_NEED_RTNL,
12708 },
12709 {
12710 .cmd = NL80211_CMD_LEAVE_MESH,
12711 .doit = nl80211_leave_mesh,
12712 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012713 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg29cbe682010-12-03 09:20:44 +010012714 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
12715 NL80211_FLAG_NEED_RTNL,
12716 },
Rostislav Lisovy6e0bd6c2014-11-03 10:33:18 +010012717 {
12718 .cmd = NL80211_CMD_JOIN_OCB,
12719 .doit = nl80211_join_ocb,
12720 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012721 .flags = GENL_UNS_ADMIN_PERM,
Rostislav Lisovy6e0bd6c2014-11-03 10:33:18 +010012722 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
12723 NL80211_FLAG_NEED_RTNL,
12724 },
12725 {
12726 .cmd = NL80211_CMD_LEAVE_OCB,
12727 .doit = nl80211_leave_ocb,
12728 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012729 .flags = GENL_UNS_ADMIN_PERM,
Rostislav Lisovy6e0bd6c2014-11-03 10:33:18 +010012730 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
12731 NL80211_FLAG_NEED_RTNL,
12732 },
Johannes Bergdfb89c52012-06-27 09:23:48 +020012733#ifdef CONFIG_PM
Johannes Bergff1b6e62011-05-04 15:37:28 +020012734 {
12735 .cmd = NL80211_CMD_GET_WOWLAN,
12736 .doit = nl80211_get_wowlan,
12737 .policy = nl80211_policy,
12738 /* can be retrieved by unprivileged users */
12739 .internal_flags = NL80211_FLAG_NEED_WIPHY |
12740 NL80211_FLAG_NEED_RTNL,
12741 },
12742 {
12743 .cmd = NL80211_CMD_SET_WOWLAN,
12744 .doit = nl80211_set_wowlan,
12745 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012746 .flags = GENL_UNS_ADMIN_PERM,
Johannes Bergff1b6e62011-05-04 15:37:28 +020012747 .internal_flags = NL80211_FLAG_NEED_WIPHY |
12748 NL80211_FLAG_NEED_RTNL,
12749 },
Johannes Bergdfb89c52012-06-27 09:23:48 +020012750#endif
Johannes Berge5497d72011-07-05 16:35:40 +020012751 {
12752 .cmd = NL80211_CMD_SET_REKEY_OFFLOAD,
12753 .doit = nl80211_set_rekey_data,
12754 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012755 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berge5497d72011-07-05 16:35:40 +020012756 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg5393b912014-09-10 15:00:16 +030012757 NL80211_FLAG_NEED_RTNL |
12758 NL80211_FLAG_CLEAR_SKB,
Johannes Berge5497d72011-07-05 16:35:40 +020012759 },
Arik Nemtsov109086c2011-09-28 14:12:50 +030012760 {
12761 .cmd = NL80211_CMD_TDLS_MGMT,
12762 .doit = nl80211_tdls_mgmt,
12763 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012764 .flags = GENL_UNS_ADMIN_PERM,
Arik Nemtsov109086c2011-09-28 14:12:50 +030012765 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
12766 NL80211_FLAG_NEED_RTNL,
12767 },
12768 {
12769 .cmd = NL80211_CMD_TDLS_OPER,
12770 .doit = nl80211_tdls_oper,
12771 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012772 .flags = GENL_UNS_ADMIN_PERM,
Arik Nemtsov109086c2011-09-28 14:12:50 +030012773 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
12774 NL80211_FLAG_NEED_RTNL,
12775 },
Johannes Berg28946da2011-11-04 11:18:12 +010012776 {
12777 .cmd = NL80211_CMD_UNEXPECTED_FRAME,
12778 .doit = nl80211_register_unexpected_frame,
12779 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012780 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg28946da2011-11-04 11:18:12 +010012781 .internal_flags = NL80211_FLAG_NEED_NETDEV |
12782 NL80211_FLAG_NEED_RTNL,
12783 },
Johannes Berg7f6cf312011-11-04 11:18:15 +010012784 {
12785 .cmd = NL80211_CMD_PROBE_CLIENT,
12786 .doit = nl80211_probe_client,
12787 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012788 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020012789 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg7f6cf312011-11-04 11:18:15 +010012790 NL80211_FLAG_NEED_RTNL,
12791 },
Johannes Berg5e760232011-11-04 11:18:17 +010012792 {
12793 .cmd = NL80211_CMD_REGISTER_BEACONS,
12794 .doit = nl80211_register_beacons,
12795 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012796 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg5e760232011-11-04 11:18:17 +010012797 .internal_flags = NL80211_FLAG_NEED_WIPHY |
12798 NL80211_FLAG_NEED_RTNL,
12799 },
Simon Wunderlich1d9d9212011-11-18 14:20:43 +010012800 {
12801 .cmd = NL80211_CMD_SET_NOACK_MAP,
12802 .doit = nl80211_set_noack_map,
12803 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012804 .flags = GENL_UNS_ADMIN_PERM,
Simon Wunderlich1d9d9212011-11-18 14:20:43 +010012805 .internal_flags = NL80211_FLAG_NEED_NETDEV |
12806 NL80211_FLAG_NEED_RTNL,
12807 },
Johannes Berg98104fde2012-06-16 00:19:54 +020012808 {
12809 .cmd = NL80211_CMD_START_P2P_DEVICE,
12810 .doit = nl80211_start_p2p_device,
12811 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012812 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg98104fde2012-06-16 00:19:54 +020012813 .internal_flags = NL80211_FLAG_NEED_WDEV |
12814 NL80211_FLAG_NEED_RTNL,
12815 },
12816 {
12817 .cmd = NL80211_CMD_STOP_P2P_DEVICE,
12818 .doit = nl80211_stop_p2p_device,
12819 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012820 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg98104fde2012-06-16 00:19:54 +020012821 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
12822 NL80211_FLAG_NEED_RTNL,
12823 },
Antonio Quartullif4e583c2012-11-02 13:27:48 +010012824 {
Ayala Bekercb3b7d82016-09-20 17:31:13 +030012825 .cmd = NL80211_CMD_START_NAN,
12826 .doit = nl80211_start_nan,
12827 .policy = nl80211_policy,
12828 .flags = GENL_ADMIN_PERM,
12829 .internal_flags = NL80211_FLAG_NEED_WDEV |
12830 NL80211_FLAG_NEED_RTNL,
12831 },
12832 {
12833 .cmd = NL80211_CMD_STOP_NAN,
12834 .doit = nl80211_stop_nan,
12835 .policy = nl80211_policy,
12836 .flags = GENL_ADMIN_PERM,
12837 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
12838 NL80211_FLAG_NEED_RTNL,
12839 },
12840 {
Ayala Bekera442b762016-09-20 17:31:15 +030012841 .cmd = NL80211_CMD_ADD_NAN_FUNCTION,
12842 .doit = nl80211_nan_add_func,
12843 .policy = nl80211_policy,
12844 .flags = GENL_ADMIN_PERM,
12845 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
12846 NL80211_FLAG_NEED_RTNL,
12847 },
12848 {
12849 .cmd = NL80211_CMD_DEL_NAN_FUNCTION,
12850 .doit = nl80211_nan_del_func,
12851 .policy = nl80211_policy,
12852 .flags = GENL_ADMIN_PERM,
12853 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
12854 NL80211_FLAG_NEED_RTNL,
12855 },
12856 {
Ayala Bekera5a9dcf2016-09-20 17:31:16 +030012857 .cmd = NL80211_CMD_CHANGE_NAN_CONFIG,
12858 .doit = nl80211_nan_change_config,
12859 .policy = nl80211_policy,
12860 .flags = GENL_ADMIN_PERM,
12861 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
12862 NL80211_FLAG_NEED_RTNL,
12863 },
12864 {
Antonio Quartullif4e583c2012-11-02 13:27:48 +010012865 .cmd = NL80211_CMD_SET_MCAST_RATE,
12866 .doit = nl80211_set_mcast_rate,
12867 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012868 .flags = GENL_UNS_ADMIN_PERM,
Antonio Quartullif4e583c2012-11-02 13:27:48 +010012869 .internal_flags = NL80211_FLAG_NEED_NETDEV |
12870 NL80211_FLAG_NEED_RTNL,
12871 },
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +053012872 {
12873 .cmd = NL80211_CMD_SET_MAC_ACL,
12874 .doit = nl80211_set_mac_acl,
12875 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012876 .flags = GENL_UNS_ADMIN_PERM,
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +053012877 .internal_flags = NL80211_FLAG_NEED_NETDEV |
12878 NL80211_FLAG_NEED_RTNL,
12879 },
Simon Wunderlich04f39042013-02-08 18:16:19 +010012880 {
12881 .cmd = NL80211_CMD_RADAR_DETECT,
12882 .doit = nl80211_start_radar_detection,
12883 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012884 .flags = GENL_UNS_ADMIN_PERM,
Simon Wunderlich04f39042013-02-08 18:16:19 +010012885 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
12886 NL80211_FLAG_NEED_RTNL,
12887 },
Johannes Berg3713b4e2013-02-14 16:19:38 +010012888 {
12889 .cmd = NL80211_CMD_GET_PROTOCOL_FEATURES,
12890 .doit = nl80211_get_protocol_features,
12891 .policy = nl80211_policy,
12892 },
Jouni Malinen355199e2013-02-27 17:14:27 +020012893 {
12894 .cmd = NL80211_CMD_UPDATE_FT_IES,
12895 .doit = nl80211_update_ft_ies,
12896 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012897 .flags = GENL_UNS_ADMIN_PERM,
Jouni Malinen355199e2013-02-27 17:14:27 +020012898 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
12899 NL80211_FLAG_NEED_RTNL,
12900 },
Arend van Spriel5de17982013-04-18 15:49:00 +020012901 {
12902 .cmd = NL80211_CMD_CRIT_PROTOCOL_START,
12903 .doit = nl80211_crit_protocol_start,
12904 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012905 .flags = GENL_UNS_ADMIN_PERM,
Arend van Spriel5de17982013-04-18 15:49:00 +020012906 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
12907 NL80211_FLAG_NEED_RTNL,
12908 },
12909 {
12910 .cmd = NL80211_CMD_CRIT_PROTOCOL_STOP,
12911 .doit = nl80211_crit_protocol_stop,
12912 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012913 .flags = GENL_UNS_ADMIN_PERM,
Arend van Spriel5de17982013-04-18 15:49:00 +020012914 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
12915 NL80211_FLAG_NEED_RTNL,
Amitkumar Karwarbe29b99a2013-06-28 11:51:26 -070012916 },
12917 {
12918 .cmd = NL80211_CMD_GET_COALESCE,
12919 .doit = nl80211_get_coalesce,
12920 .policy = nl80211_policy,
12921 .internal_flags = NL80211_FLAG_NEED_WIPHY |
12922 NL80211_FLAG_NEED_RTNL,
12923 },
12924 {
12925 .cmd = NL80211_CMD_SET_COALESCE,
12926 .doit = nl80211_set_coalesce,
12927 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012928 .flags = GENL_UNS_ADMIN_PERM,
Amitkumar Karwarbe29b99a2013-06-28 11:51:26 -070012929 .internal_flags = NL80211_FLAG_NEED_WIPHY |
12930 NL80211_FLAG_NEED_RTNL,
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +020012931 },
12932 {
12933 .cmd = NL80211_CMD_CHANNEL_SWITCH,
12934 .doit = nl80211_channel_switch,
12935 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012936 .flags = GENL_UNS_ADMIN_PERM,
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +020012937 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
12938 NL80211_FLAG_NEED_RTNL,
12939 },
Johannes Bergad7e7182013-11-13 13:37:47 +010012940 {
12941 .cmd = NL80211_CMD_VENDOR,
12942 .doit = nl80211_vendor_cmd,
Johannes Berg7bdbe402015-08-15 22:39:49 +030012943 .dumpit = nl80211_vendor_cmd_dump,
Johannes Bergad7e7182013-11-13 13:37:47 +010012944 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012945 .flags = GENL_UNS_ADMIN_PERM,
Johannes Bergad7e7182013-11-13 13:37:47 +010012946 .internal_flags = NL80211_FLAG_NEED_WIPHY |
12947 NL80211_FLAG_NEED_RTNL,
12948 },
Kyeyoon Parkfa9ffc72013-12-16 23:01:30 -080012949 {
12950 .cmd = NL80211_CMD_SET_QOS_MAP,
12951 .doit = nl80211_set_qos_map,
12952 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012953 .flags = GENL_UNS_ADMIN_PERM,
Kyeyoon Parkfa9ffc72013-12-16 23:01:30 -080012954 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
12955 NL80211_FLAG_NEED_RTNL,
12956 },
Johannes Berg960d01a2014-09-09 22:55:35 +030012957 {
12958 .cmd = NL80211_CMD_ADD_TX_TS,
12959 .doit = nl80211_add_tx_ts,
12960 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012961 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg960d01a2014-09-09 22:55:35 +030012962 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
12963 NL80211_FLAG_NEED_RTNL,
12964 },
12965 {
12966 .cmd = NL80211_CMD_DEL_TX_TS,
12967 .doit = nl80211_del_tx_ts,
12968 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012969 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg960d01a2014-09-09 22:55:35 +030012970 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
12971 NL80211_FLAG_NEED_RTNL,
12972 },
Arik Nemtsov1057d352014-11-19 12:54:26 +020012973 {
12974 .cmd = NL80211_CMD_TDLS_CHANNEL_SWITCH,
12975 .doit = nl80211_tdls_channel_switch,
12976 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012977 .flags = GENL_UNS_ADMIN_PERM,
Arik Nemtsov1057d352014-11-19 12:54:26 +020012978 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
12979 NL80211_FLAG_NEED_RTNL,
12980 },
12981 {
12982 .cmd = NL80211_CMD_TDLS_CANCEL_CHANNEL_SWITCH,
12983 .doit = nl80211_tdls_cancel_channel_switch,
12984 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012985 .flags = GENL_UNS_ADMIN_PERM,
Arik Nemtsov1057d352014-11-19 12:54:26 +020012986 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
12987 NL80211_FLAG_NEED_RTNL,
12988 },
Michael Braunce0ce132016-10-10 19:12:22 +020012989 {
12990 .cmd = NL80211_CMD_SET_MULTICAST_TO_UNICAST,
12991 .doit = nl80211_set_multicast_to_unicast,
12992 .policy = nl80211_policy,
12993 .flags = GENL_UNS_ADMIN_PERM,
12994 .internal_flags = NL80211_FLAG_NEED_NETDEV |
12995 NL80211_FLAG_NEED_RTNL,
12996 },
Johannes Berg55682962007-09-20 13:09:35 -040012997};
Jouni Malinen9588bbd2009-12-23 13:15:41 +010012998
Johannes Berg56989f62016-10-24 14:40:05 +020012999static struct genl_family nl80211_fam __ro_after_init = {
Johannes Berg489111e2016-10-24 14:40:03 +020013000 .name = NL80211_GENL_NAME, /* have users key off the name instead */
13001 .hdrsize = 0, /* no private header */
13002 .version = 1, /* no particular meaning now */
13003 .maxattr = NL80211_ATTR_MAX,
13004 .netnsok = true,
13005 .pre_doit = nl80211_pre_doit,
13006 .post_doit = nl80211_post_doit,
13007 .module = THIS_MODULE,
13008 .ops = nl80211_ops,
13009 .n_ops = ARRAY_SIZE(nl80211_ops),
13010 .mcgrps = nl80211_mcgrps,
13011 .n_mcgrps = ARRAY_SIZE(nl80211_mcgrps),
13012};
13013
Johannes Berg55682962007-09-20 13:09:35 -040013014/* notification functions */
13015
Johannes Berg3bb20552014-05-26 13:52:25 +020013016void nl80211_notify_wiphy(struct cfg80211_registered_device *rdev,
13017 enum nl80211_commands cmd)
Johannes Berg55682962007-09-20 13:09:35 -040013018{
13019 struct sk_buff *msg;
Johannes Berg86e8cf92013-06-19 10:57:22 +020013020 struct nl80211_dump_wiphy_state state = {};
Johannes Berg55682962007-09-20 13:09:35 -040013021
Johannes Berg3bb20552014-05-26 13:52:25 +020013022 WARN_ON(cmd != NL80211_CMD_NEW_WIPHY &&
13023 cmd != NL80211_CMD_DEL_WIPHY);
13024
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -070013025 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -040013026 if (!msg)
13027 return;
13028
Johannes Berg3bb20552014-05-26 13:52:25 +020013029 if (nl80211_send_wiphy(rdev, cmd, msg, 0, 0, 0, &state) < 0) {
Johannes Berg55682962007-09-20 13:09:35 -040013030 nlmsg_free(msg);
13031 return;
13032 }
13033
Johannes Berg68eb5502013-11-19 15:19:38 +010013034 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010013035 NL80211_MCGRP_CONFIG, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -040013036}
13037
Denis Kenzior896ff062016-08-03 16:58:33 -050013038void nl80211_notify_iface(struct cfg80211_registered_device *rdev,
13039 struct wireless_dev *wdev,
13040 enum nl80211_commands cmd)
13041{
13042 struct sk_buff *msg;
13043
13044 WARN_ON(cmd != NL80211_CMD_NEW_INTERFACE &&
13045 cmd != NL80211_CMD_DEL_INTERFACE);
13046
13047 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
13048 if (!msg)
13049 return;
13050
13051 if (nl80211_send_iface(msg, 0, 0, 0, rdev, wdev,
13052 cmd == NL80211_CMD_DEL_INTERFACE) < 0) {
13053 nlmsg_free(msg);
13054 return;
13055 }
13056
13057 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
13058 NL80211_MCGRP_CONFIG, GFP_KERNEL);
13059}
13060
Johannes Berg362a4152009-05-24 16:43:15 +020013061static int nl80211_add_scan_req(struct sk_buff *msg,
13062 struct cfg80211_registered_device *rdev)
13063{
13064 struct cfg80211_scan_request *req = rdev->scan_req;
13065 struct nlattr *nest;
13066 int i;
13067
13068 if (WARN_ON(!req))
13069 return 0;
13070
13071 nest = nla_nest_start(msg, NL80211_ATTR_SCAN_SSIDS);
13072 if (!nest)
13073 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -040013074 for (i = 0; i < req->n_ssids; i++) {
13075 if (nla_put(msg, i, req->ssids[i].ssid_len, req->ssids[i].ssid))
13076 goto nla_put_failure;
13077 }
Johannes Berg362a4152009-05-24 16:43:15 +020013078 nla_nest_end(msg, nest);
13079
13080 nest = nla_nest_start(msg, NL80211_ATTR_SCAN_FREQUENCIES);
13081 if (!nest)
13082 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -040013083 for (i = 0; i < req->n_channels; i++) {
13084 if (nla_put_u32(msg, i, req->channels[i]->center_freq))
13085 goto nla_put_failure;
13086 }
Johannes Berg362a4152009-05-24 16:43:15 +020013087 nla_nest_end(msg, nest);
13088
David S. Miller9360ffd2012-03-29 04:41:26 -040013089 if (req->ie &&
13090 nla_put(msg, NL80211_ATTR_IE, req->ie_len, req->ie))
13091 goto nla_put_failure;
Johannes Berg362a4152009-05-24 16:43:15 +020013092
Johannes Bergae917c92013-10-25 11:05:22 +020013093 if (req->flags &&
13094 nla_put_u32(msg, NL80211_ATTR_SCAN_FLAGS, req->flags))
13095 goto nla_put_failure;
Sam Lefflered4737712012-10-11 21:03:31 -070013096
Avraham Stern1d762502016-07-05 17:10:13 +030013097 if (req->info.scan_start_tsf &&
13098 (nla_put_u64_64bit(msg, NL80211_ATTR_SCAN_START_TIME_TSF,
13099 req->info.scan_start_tsf, NL80211_BSS_PAD) ||
13100 nla_put(msg, NL80211_ATTR_SCAN_START_TIME_TSF_BSSID, ETH_ALEN,
13101 req->info.tsf_bssid)))
13102 goto nla_put_failure;
13103
Johannes Berg362a4152009-05-24 16:43:15 +020013104 return 0;
13105 nla_put_failure:
13106 return -ENOBUFS;
13107}
13108
Arend Van Spriel505a2e82016-12-16 11:21:54 +000013109static int nl80211_prep_scan_msg(struct sk_buff *msg,
Johannes Berga538e2d2009-06-16 19:56:42 +020013110 struct cfg80211_registered_device *rdev,
Johannes Bergfd014282012-06-18 19:17:03 +020013111 struct wireless_dev *wdev,
Eric W. Biederman15e47302012-09-07 20:12:54 +000013112 u32 portid, u32 seq, int flags,
Johannes Berga538e2d2009-06-16 19:56:42 +020013113 u32 cmd)
Johannes Berg2a519312009-02-10 21:25:55 +010013114{
13115 void *hdr;
13116
Eric W. Biederman15e47302012-09-07 20:12:54 +000013117 hdr = nl80211hdr_put(msg, portid, seq, flags, cmd);
Johannes Berg2a519312009-02-10 21:25:55 +010013118 if (!hdr)
13119 return -1;
13120
David S. Miller9360ffd2012-03-29 04:41:26 -040013121 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Bergfd014282012-06-18 19:17:03 +020013122 (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
13123 wdev->netdev->ifindex)) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020013124 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
13125 NL80211_ATTR_PAD))
David S. Miller9360ffd2012-03-29 04:41:26 -040013126 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +010013127
Johannes Berg362a4152009-05-24 16:43:15 +020013128 /* ignore errors and send incomplete event anyway */
13129 nl80211_add_scan_req(msg, rdev);
Johannes Berg2a519312009-02-10 21:25:55 +010013130
Johannes Berg053c0952015-01-16 22:09:00 +010013131 genlmsg_end(msg, hdr);
13132 return 0;
Johannes Berg2a519312009-02-10 21:25:55 +010013133
13134 nla_put_failure:
13135 genlmsg_cancel(msg, hdr);
13136 return -EMSGSIZE;
13137}
13138
Luciano Coelho807f8a82011-05-11 17:09:35 +030013139static int
Arend Van Spriel505a2e82016-12-16 11:21:54 +000013140nl80211_prep_sched_scan_msg(struct sk_buff *msg,
Luciano Coelho807f8a82011-05-11 17:09:35 +030013141 struct cfg80211_registered_device *rdev,
13142 struct net_device *netdev,
Eric W. Biederman15e47302012-09-07 20:12:54 +000013143 u32 portid, u32 seq, int flags, u32 cmd)
Luciano Coelho807f8a82011-05-11 17:09:35 +030013144{
13145 void *hdr;
13146
Eric W. Biederman15e47302012-09-07 20:12:54 +000013147 hdr = nl80211hdr_put(msg, portid, seq, flags, cmd);
Luciano Coelho807f8a82011-05-11 17:09:35 +030013148 if (!hdr)
13149 return -1;
13150
David S. Miller9360ffd2012-03-29 04:41:26 -040013151 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
13152 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex))
13153 goto nla_put_failure;
Luciano Coelho807f8a82011-05-11 17:09:35 +030013154
Johannes Berg053c0952015-01-16 22:09:00 +010013155 genlmsg_end(msg, hdr);
13156 return 0;
Luciano Coelho807f8a82011-05-11 17:09:35 +030013157
13158 nla_put_failure:
13159 genlmsg_cancel(msg, hdr);
13160 return -EMSGSIZE;
13161}
13162
Johannes Berga538e2d2009-06-16 19:56:42 +020013163void nl80211_send_scan_start(struct cfg80211_registered_device *rdev,
Johannes Bergfd014282012-06-18 19:17:03 +020013164 struct wireless_dev *wdev)
Johannes Berga538e2d2009-06-16 19:56:42 +020013165{
13166 struct sk_buff *msg;
13167
Thomas Graf58050fc2012-06-28 03:57:45 +000013168 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berga538e2d2009-06-16 19:56:42 +020013169 if (!msg)
13170 return;
13171
Arend Van Spriel505a2e82016-12-16 11:21:54 +000013172 if (nl80211_prep_scan_msg(msg, rdev, wdev, 0, 0, 0,
Johannes Berga538e2d2009-06-16 19:56:42 +020013173 NL80211_CMD_TRIGGER_SCAN) < 0) {
13174 nlmsg_free(msg);
13175 return;
13176 }
13177
Johannes Berg68eb5502013-11-19 15:19:38 +010013178 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010013179 NL80211_MCGRP_SCAN, GFP_KERNEL);
Johannes Berga538e2d2009-06-16 19:56:42 +020013180}
13181
Johannes Bergf9d15d12014-01-22 11:14:19 +020013182struct sk_buff *nl80211_build_scan_msg(struct cfg80211_registered_device *rdev,
13183 struct wireless_dev *wdev, bool aborted)
Johannes Berg2a519312009-02-10 21:25:55 +010013184{
13185 struct sk_buff *msg;
13186
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -070013187 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg2a519312009-02-10 21:25:55 +010013188 if (!msg)
Johannes Bergf9d15d12014-01-22 11:14:19 +020013189 return NULL;
Johannes Berg2a519312009-02-10 21:25:55 +010013190
Arend Van Spriel505a2e82016-12-16 11:21:54 +000013191 if (nl80211_prep_scan_msg(msg, rdev, wdev, 0, 0, 0,
Johannes Bergf9d15d12014-01-22 11:14:19 +020013192 aborted ? NL80211_CMD_SCAN_ABORTED :
13193 NL80211_CMD_NEW_SCAN_RESULTS) < 0) {
Johannes Berg2a519312009-02-10 21:25:55 +010013194 nlmsg_free(msg);
Johannes Bergf9d15d12014-01-22 11:14:19 +020013195 return NULL;
Johannes Berg2a519312009-02-10 21:25:55 +010013196 }
13197
Johannes Bergf9d15d12014-01-22 11:14:19 +020013198 return msg;
Johannes Berg2a519312009-02-10 21:25:55 +010013199}
13200
Arend Van Spriel505a2e82016-12-16 11:21:54 +000013201/* send message created by nl80211_build_scan_msg() */
13202void nl80211_send_scan_msg(struct cfg80211_registered_device *rdev,
13203 struct sk_buff *msg)
Johannes Berg2a519312009-02-10 21:25:55 +010013204{
Johannes Berg2a519312009-02-10 21:25:55 +010013205 if (!msg)
13206 return;
13207
Johannes Berg68eb5502013-11-19 15:19:38 +010013208 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010013209 NL80211_MCGRP_SCAN, GFP_KERNEL);
Johannes Berg2a519312009-02-10 21:25:55 +010013210}
13211
Luciano Coelho807f8a82011-05-11 17:09:35 +030013212void nl80211_send_sched_scan(struct cfg80211_registered_device *rdev,
13213 struct net_device *netdev, u32 cmd)
13214{
13215 struct sk_buff *msg;
13216
Thomas Graf58050fc2012-06-28 03:57:45 +000013217 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Luciano Coelho807f8a82011-05-11 17:09:35 +030013218 if (!msg)
13219 return;
13220
Arend Van Spriel505a2e82016-12-16 11:21:54 +000013221 if (nl80211_prep_sched_scan_msg(msg, rdev, netdev, 0, 0, 0, cmd) < 0) {
Luciano Coelho807f8a82011-05-11 17:09:35 +030013222 nlmsg_free(msg);
13223 return;
13224 }
13225
Johannes Berg68eb5502013-11-19 15:19:38 +010013226 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010013227 NL80211_MCGRP_SCAN, GFP_KERNEL);
Luciano Coelho807f8a82011-05-11 17:09:35 +030013228}
13229
Jonathan Doronb0d7aa52014-12-15 19:26:00 +020013230static bool nl80211_reg_change_event_fill(struct sk_buff *msg,
13231 struct regulatory_request *request)
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040013232{
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040013233 /* Userspace can always count this one always being set */
David S. Miller9360ffd2012-03-29 04:41:26 -040013234 if (nla_put_u8(msg, NL80211_ATTR_REG_INITIATOR, request->initiator))
13235 goto nla_put_failure;
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040013236
David S. Miller9360ffd2012-03-29 04:41:26 -040013237 if (request->alpha2[0] == '0' && request->alpha2[1] == '0') {
13238 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
13239 NL80211_REGDOM_TYPE_WORLD))
13240 goto nla_put_failure;
13241 } else if (request->alpha2[0] == '9' && request->alpha2[1] == '9') {
13242 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
13243 NL80211_REGDOM_TYPE_CUSTOM_WORLD))
13244 goto nla_put_failure;
13245 } else if ((request->alpha2[0] == '9' && request->alpha2[1] == '8') ||
13246 request->intersect) {
13247 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
13248 NL80211_REGDOM_TYPE_INTERSECTION))
13249 goto nla_put_failure;
13250 } else {
13251 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
13252 NL80211_REGDOM_TYPE_COUNTRY) ||
13253 nla_put_string(msg, NL80211_ATTR_REG_ALPHA2,
13254 request->alpha2))
13255 goto nla_put_failure;
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040013256 }
13257
Arik Nemtsovad30ca22014-12-15 19:25:59 +020013258 if (request->wiphy_idx != WIPHY_IDX_INVALID) {
13259 struct wiphy *wiphy = wiphy_idx_to_wiphy(request->wiphy_idx);
13260
13261 if (wiphy &&
13262 nla_put_u32(msg, NL80211_ATTR_WIPHY, request->wiphy_idx))
13263 goto nla_put_failure;
Arik Nemtsov1bdd7162014-12-15 19:26:01 +020013264
13265 if (wiphy &&
13266 wiphy->regulatory_flags & REGULATORY_WIPHY_SELF_MANAGED &&
13267 nla_put_flag(msg, NL80211_ATTR_WIPHY_SELF_MANAGED_REG))
13268 goto nla_put_failure;
Arik Nemtsovad30ca22014-12-15 19:25:59 +020013269 }
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040013270
Jonathan Doronb0d7aa52014-12-15 19:26:00 +020013271 return true;
13272
13273nla_put_failure:
13274 return false;
13275}
13276
13277/*
13278 * This can happen on global regulatory changes or device specific settings
13279 * based on custom regulatory domains.
13280 */
13281void nl80211_common_reg_change_event(enum nl80211_commands cmd_id,
13282 struct regulatory_request *request)
13283{
13284 struct sk_buff *msg;
13285 void *hdr;
13286
13287 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
13288 if (!msg)
13289 return;
13290
13291 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd_id);
13292 if (!hdr) {
13293 nlmsg_free(msg);
13294 return;
13295 }
13296
13297 if (nl80211_reg_change_event_fill(msg, request) == false)
13298 goto nla_put_failure;
13299
Johannes Berg3b7b72e2011-10-22 19:05:51 +020013300 genlmsg_end(msg, hdr);
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040013301
Johannes Bergbc43b282009-07-25 10:54:13 +020013302 rcu_read_lock();
Johannes Berg68eb5502013-11-19 15:19:38 +010013303 genlmsg_multicast_allns(&nl80211_fam, msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010013304 NL80211_MCGRP_REGULATORY, GFP_ATOMIC);
Johannes Bergbc43b282009-07-25 10:54:13 +020013305 rcu_read_unlock();
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040013306
13307 return;
13308
13309nla_put_failure:
13310 genlmsg_cancel(msg, hdr);
13311 nlmsg_free(msg);
13312}
13313
Jouni Malinen6039f6d2009-03-19 13:39:21 +020013314static void nl80211_send_mlme_event(struct cfg80211_registered_device *rdev,
13315 struct net_device *netdev,
13316 const u8 *buf, size_t len,
Eliad Pellerb0b6aa22014-09-09 17:09:45 +030013317 enum nl80211_commands cmd, gfp_t gfp,
13318 int uapsd_queues)
Jouni Malinen6039f6d2009-03-19 13:39:21 +020013319{
13320 struct sk_buff *msg;
13321 void *hdr;
13322
Johannes Berg4ef8c1c2017-01-09 11:10:42 +010013323 msg = nlmsg_new(100 + len, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020013324 if (!msg)
13325 return;
13326
13327 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
13328 if (!hdr) {
13329 nlmsg_free(msg);
13330 return;
13331 }
13332
David S. Miller9360ffd2012-03-29 04:41:26 -040013333 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
13334 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
13335 nla_put(msg, NL80211_ATTR_FRAME, len, buf))
13336 goto nla_put_failure;
Jouni Malinen6039f6d2009-03-19 13:39:21 +020013337
Eliad Pellerb0b6aa22014-09-09 17:09:45 +030013338 if (uapsd_queues >= 0) {
13339 struct nlattr *nla_wmm =
13340 nla_nest_start(msg, NL80211_ATTR_STA_WME);
13341 if (!nla_wmm)
13342 goto nla_put_failure;
13343
13344 if (nla_put_u8(msg, NL80211_STA_WME_UAPSD_QUEUES,
13345 uapsd_queues))
13346 goto nla_put_failure;
13347
13348 nla_nest_end(msg, nla_wmm);
13349 }
13350
Johannes Berg3b7b72e2011-10-22 19:05:51 +020013351 genlmsg_end(msg, hdr);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020013352
Johannes Berg68eb5502013-11-19 15:19:38 +010013353 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010013354 NL80211_MCGRP_MLME, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020013355 return;
13356
13357 nla_put_failure:
13358 genlmsg_cancel(msg, hdr);
13359 nlmsg_free(msg);
13360}
13361
13362void nl80211_send_rx_auth(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +020013363 struct net_device *netdev, const u8 *buf,
13364 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +020013365{
13366 nl80211_send_mlme_event(rdev, netdev, buf, len,
Eliad Pellerb0b6aa22014-09-09 17:09:45 +030013367 NL80211_CMD_AUTHENTICATE, gfp, -1);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020013368}
13369
13370void nl80211_send_rx_assoc(struct cfg80211_registered_device *rdev,
13371 struct net_device *netdev, const u8 *buf,
Eliad Pellerb0b6aa22014-09-09 17:09:45 +030013372 size_t len, gfp_t gfp, int uapsd_queues)
Jouni Malinen6039f6d2009-03-19 13:39:21 +020013373{
Johannes Berge6d6e342009-07-01 21:26:47 +020013374 nl80211_send_mlme_event(rdev, netdev, buf, len,
Eliad Pellerb0b6aa22014-09-09 17:09:45 +030013375 NL80211_CMD_ASSOCIATE, gfp, uapsd_queues);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020013376}
13377
Jouni Malinen53b46b82009-03-27 20:53:56 +020013378void nl80211_send_deauth(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +020013379 struct net_device *netdev, const u8 *buf,
13380 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +020013381{
13382 nl80211_send_mlme_event(rdev, netdev, buf, len,
Eliad Pellerb0b6aa22014-09-09 17:09:45 +030013383 NL80211_CMD_DEAUTHENTICATE, gfp, -1);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020013384}
13385
Jouni Malinen53b46b82009-03-27 20:53:56 +020013386void nl80211_send_disassoc(struct cfg80211_registered_device *rdev,
13387 struct net_device *netdev, const u8 *buf,
Johannes Berge6d6e342009-07-01 21:26:47 +020013388 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +020013389{
13390 nl80211_send_mlme_event(rdev, netdev, buf, len,
Eliad Pellerb0b6aa22014-09-09 17:09:45 +030013391 NL80211_CMD_DISASSOCIATE, gfp, -1);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020013392}
13393
Johannes Berg6ff57cf2013-05-16 00:55:00 +020013394void cfg80211_rx_unprot_mlme_mgmt(struct net_device *dev, const u8 *buf,
13395 size_t len)
Jouni Malinencf4e5942010-12-16 00:52:40 +020013396{
Johannes Berg947add32013-02-22 22:05:20 +010013397 struct wireless_dev *wdev = dev->ieee80211_ptr;
13398 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080013399 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg6ff57cf2013-05-16 00:55:00 +020013400 const struct ieee80211_mgmt *mgmt = (void *)buf;
13401 u32 cmd;
Jouni Malinencf4e5942010-12-16 00:52:40 +020013402
Johannes Berg6ff57cf2013-05-16 00:55:00 +020013403 if (WARN_ON(len < 2))
13404 return;
13405
13406 if (ieee80211_is_deauth(mgmt->frame_control))
13407 cmd = NL80211_CMD_UNPROT_DEAUTHENTICATE;
13408 else
13409 cmd = NL80211_CMD_UNPROT_DISASSOCIATE;
13410
13411 trace_cfg80211_rx_unprot_mlme_mgmt(dev, buf, len);
Eliad Pellerb0b6aa22014-09-09 17:09:45 +030013412 nl80211_send_mlme_event(rdev, dev, buf, len, cmd, GFP_ATOMIC, -1);
Jouni Malinencf4e5942010-12-16 00:52:40 +020013413}
Johannes Berg6ff57cf2013-05-16 00:55:00 +020013414EXPORT_SYMBOL(cfg80211_rx_unprot_mlme_mgmt);
Jouni Malinencf4e5942010-12-16 00:52:40 +020013415
Luis R. Rodriguez1b06bb42009-05-02 00:34:48 -040013416static void nl80211_send_mlme_timeout(struct cfg80211_registered_device *rdev,
13417 struct net_device *netdev, int cmd,
Johannes Berge6d6e342009-07-01 21:26:47 +020013418 const u8 *addr, gfp_t gfp)
Jouni Malinen1965c852009-04-22 21:38:25 +030013419{
13420 struct sk_buff *msg;
13421 void *hdr;
13422
Johannes Berge6d6e342009-07-01 21:26:47 +020013423 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +030013424 if (!msg)
13425 return;
13426
13427 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
13428 if (!hdr) {
13429 nlmsg_free(msg);
13430 return;
13431 }
13432
David S. Miller9360ffd2012-03-29 04:41:26 -040013433 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
13434 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
13435 nla_put_flag(msg, NL80211_ATTR_TIMED_OUT) ||
13436 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr))
13437 goto nla_put_failure;
Jouni Malinen1965c852009-04-22 21:38:25 +030013438
Johannes Berg3b7b72e2011-10-22 19:05:51 +020013439 genlmsg_end(msg, hdr);
Jouni Malinen1965c852009-04-22 21:38:25 +030013440
Johannes Berg68eb5502013-11-19 15:19:38 +010013441 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010013442 NL80211_MCGRP_MLME, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +030013443 return;
13444
13445 nla_put_failure:
13446 genlmsg_cancel(msg, hdr);
13447 nlmsg_free(msg);
13448}
13449
13450void nl80211_send_auth_timeout(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +020013451 struct net_device *netdev, const u8 *addr,
13452 gfp_t gfp)
Jouni Malinen1965c852009-04-22 21:38:25 +030013453{
13454 nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_AUTHENTICATE,
Johannes Berge6d6e342009-07-01 21:26:47 +020013455 addr, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +030013456}
13457
13458void nl80211_send_assoc_timeout(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +020013459 struct net_device *netdev, const u8 *addr,
13460 gfp_t gfp)
Jouni Malinen1965c852009-04-22 21:38:25 +030013461{
Johannes Berge6d6e342009-07-01 21:26:47 +020013462 nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_ASSOCIATE,
13463 addr, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +030013464}
13465
Samuel Ortizb23aa672009-07-01 21:26:54 +020013466void nl80211_send_connect_result(struct cfg80211_registered_device *rdev,
13467 struct net_device *netdev, const u8 *bssid,
13468 const u8 *req_ie, size_t req_ie_len,
13469 const u8 *resp_ie, size_t resp_ie_len,
Purushottam Kushwaha3093ebbeab2017-01-13 01:12:21 +020013470 int status,
13471 enum nl80211_timeout_reason timeout_reason,
13472 gfp_t gfp)
Samuel Ortizb23aa672009-07-01 21:26:54 +020013473{
13474 struct sk_buff *msg;
13475 void *hdr;
13476
Johannes Berg4ef8c1c2017-01-09 11:10:42 +010013477 msg = nlmsg_new(100 + req_ie_len + resp_ie_len, gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +020013478 if (!msg)
13479 return;
13480
13481 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONNECT);
13482 if (!hdr) {
13483 nlmsg_free(msg);
13484 return;
13485 }
13486
David S. Miller9360ffd2012-03-29 04:41:26 -040013487 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
13488 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
13489 (bssid && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) ||
Jouni Malinenbf1ecd22016-05-31 00:16:50 +030013490 nla_put_u16(msg, NL80211_ATTR_STATUS_CODE,
13491 status < 0 ? WLAN_STATUS_UNSPECIFIED_FAILURE :
13492 status) ||
Purushottam Kushwaha3093ebbeab2017-01-13 01:12:21 +020013493 (status < 0 &&
13494 (nla_put_flag(msg, NL80211_ATTR_TIMED_OUT) ||
13495 nla_put_u32(msg, NL80211_ATTR_TIMEOUT_REASON, timeout_reason))) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040013496 (req_ie &&
13497 nla_put(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie)) ||
13498 (resp_ie &&
13499 nla_put(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie)))
13500 goto nla_put_failure;
Samuel Ortizb23aa672009-07-01 21:26:54 +020013501
Johannes Berg3b7b72e2011-10-22 19:05:51 +020013502 genlmsg_end(msg, hdr);
Samuel Ortizb23aa672009-07-01 21:26:54 +020013503
Johannes Berg68eb5502013-11-19 15:19:38 +010013504 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010013505 NL80211_MCGRP_MLME, gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +020013506 return;
13507
13508 nla_put_failure:
13509 genlmsg_cancel(msg, hdr);
13510 nlmsg_free(msg);
Samuel Ortizb23aa672009-07-01 21:26:54 +020013511}
13512
13513void nl80211_send_roamed(struct cfg80211_registered_device *rdev,
13514 struct net_device *netdev, const u8 *bssid,
13515 const u8 *req_ie, size_t req_ie_len,
13516 const u8 *resp_ie, size_t resp_ie_len, gfp_t gfp)
13517{
13518 struct sk_buff *msg;
13519 void *hdr;
13520
Johannes Berg4ef8c1c2017-01-09 11:10:42 +010013521 msg = nlmsg_new(100 + req_ie_len + resp_ie_len, gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +020013522 if (!msg)
13523 return;
13524
13525 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_ROAM);
13526 if (!hdr) {
13527 nlmsg_free(msg);
13528 return;
13529 }
13530
David S. Miller9360ffd2012-03-29 04:41:26 -040013531 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
13532 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
13533 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid) ||
13534 (req_ie &&
13535 nla_put(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie)) ||
13536 (resp_ie &&
13537 nla_put(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie)))
13538 goto nla_put_failure;
Samuel Ortizb23aa672009-07-01 21:26:54 +020013539
Johannes Berg3b7b72e2011-10-22 19:05:51 +020013540 genlmsg_end(msg, hdr);
Samuel Ortizb23aa672009-07-01 21:26:54 +020013541
Johannes Berg68eb5502013-11-19 15:19:38 +010013542 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010013543 NL80211_MCGRP_MLME, gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +020013544 return;
13545
13546 nla_put_failure:
13547 genlmsg_cancel(msg, hdr);
13548 nlmsg_free(msg);
Samuel Ortizb23aa672009-07-01 21:26:54 +020013549}
13550
13551void nl80211_send_disconnected(struct cfg80211_registered_device *rdev,
13552 struct net_device *netdev, u16 reason,
Johannes Berg667503d2009-07-07 03:56:11 +020013553 const u8 *ie, size_t ie_len, bool from_ap)
Samuel Ortizb23aa672009-07-01 21:26:54 +020013554{
13555 struct sk_buff *msg;
13556 void *hdr;
13557
Johannes Berg4ef8c1c2017-01-09 11:10:42 +010013558 msg = nlmsg_new(100 + ie_len, GFP_KERNEL);
Samuel Ortizb23aa672009-07-01 21:26:54 +020013559 if (!msg)
13560 return;
13561
13562 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DISCONNECT);
13563 if (!hdr) {
13564 nlmsg_free(msg);
13565 return;
13566 }
13567
David S. Miller9360ffd2012-03-29 04:41:26 -040013568 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
13569 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
13570 (from_ap && reason &&
13571 nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason)) ||
13572 (from_ap &&
13573 nla_put_flag(msg, NL80211_ATTR_DISCONNECTED_BY_AP)) ||
13574 (ie && nla_put(msg, NL80211_ATTR_IE, ie_len, ie)))
13575 goto nla_put_failure;
Samuel Ortizb23aa672009-07-01 21:26:54 +020013576
Johannes Berg3b7b72e2011-10-22 19:05:51 +020013577 genlmsg_end(msg, hdr);
Samuel Ortizb23aa672009-07-01 21:26:54 +020013578
Johannes Berg68eb5502013-11-19 15:19:38 +010013579 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010013580 NL80211_MCGRP_MLME, GFP_KERNEL);
Samuel Ortizb23aa672009-07-01 21:26:54 +020013581 return;
13582
13583 nla_put_failure:
13584 genlmsg_cancel(msg, hdr);
13585 nlmsg_free(msg);
Samuel Ortizb23aa672009-07-01 21:26:54 +020013586}
13587
Johannes Berg04a773a2009-04-19 21:24:32 +020013588void nl80211_send_ibss_bssid(struct cfg80211_registered_device *rdev,
13589 struct net_device *netdev, const u8 *bssid,
13590 gfp_t gfp)
13591{
13592 struct sk_buff *msg;
13593 void *hdr;
13594
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -070013595 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Johannes Berg04a773a2009-04-19 21:24:32 +020013596 if (!msg)
13597 return;
13598
13599 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_JOIN_IBSS);
13600 if (!hdr) {
13601 nlmsg_free(msg);
13602 return;
13603 }
13604
David S. Miller9360ffd2012-03-29 04:41:26 -040013605 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
13606 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
13607 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid))
13608 goto nla_put_failure;
Johannes Berg04a773a2009-04-19 21:24:32 +020013609
Johannes Berg3b7b72e2011-10-22 19:05:51 +020013610 genlmsg_end(msg, hdr);
Johannes Berg04a773a2009-04-19 21:24:32 +020013611
Johannes Berg68eb5502013-11-19 15:19:38 +010013612 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010013613 NL80211_MCGRP_MLME, gfp);
Johannes Berg04a773a2009-04-19 21:24:32 +020013614 return;
13615
13616 nla_put_failure:
13617 genlmsg_cancel(msg, hdr);
13618 nlmsg_free(msg);
13619}
13620
Johannes Berg947add32013-02-22 22:05:20 +010013621void cfg80211_notify_new_peer_candidate(struct net_device *dev, const u8 *addr,
13622 const u8* ie, u8 ie_len, gfp_t gfp)
Javier Cardonac93b5e72011-04-07 15:08:34 -070013623{
Johannes Berg947add32013-02-22 22:05:20 +010013624 struct wireless_dev *wdev = dev->ieee80211_ptr;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080013625 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Javier Cardonac93b5e72011-04-07 15:08:34 -070013626 struct sk_buff *msg;
13627 void *hdr;
13628
Johannes Berg947add32013-02-22 22:05:20 +010013629 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_MESH_POINT))
13630 return;
13631
13632 trace_cfg80211_notify_new_peer_candidate(dev, addr);
13633
Johannes Berg4ef8c1c2017-01-09 11:10:42 +010013634 msg = nlmsg_new(100 + ie_len, gfp);
Javier Cardonac93b5e72011-04-07 15:08:34 -070013635 if (!msg)
13636 return;
13637
13638 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NEW_PEER_CANDIDATE);
13639 if (!hdr) {
13640 nlmsg_free(msg);
13641 return;
13642 }
13643
David S. Miller9360ffd2012-03-29 04:41:26 -040013644 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg947add32013-02-22 22:05:20 +010013645 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
13646 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040013647 (ie_len && ie &&
13648 nla_put(msg, NL80211_ATTR_IE, ie_len , ie)))
13649 goto nla_put_failure;
Javier Cardonac93b5e72011-04-07 15:08:34 -070013650
Johannes Berg3b7b72e2011-10-22 19:05:51 +020013651 genlmsg_end(msg, hdr);
Javier Cardonac93b5e72011-04-07 15:08:34 -070013652
Johannes Berg68eb5502013-11-19 15:19:38 +010013653 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010013654 NL80211_MCGRP_MLME, gfp);
Javier Cardonac93b5e72011-04-07 15:08:34 -070013655 return;
13656
13657 nla_put_failure:
13658 genlmsg_cancel(msg, hdr);
13659 nlmsg_free(msg);
13660}
Johannes Berg947add32013-02-22 22:05:20 +010013661EXPORT_SYMBOL(cfg80211_notify_new_peer_candidate);
Javier Cardonac93b5e72011-04-07 15:08:34 -070013662
Jouni Malinena3b8b052009-03-27 21:59:49 +020013663void nl80211_michael_mic_failure(struct cfg80211_registered_device *rdev,
13664 struct net_device *netdev, const u8 *addr,
13665 enum nl80211_key_type key_type, int key_id,
Johannes Berge6d6e342009-07-01 21:26:47 +020013666 const u8 *tsc, gfp_t gfp)
Jouni Malinena3b8b052009-03-27 21:59:49 +020013667{
13668 struct sk_buff *msg;
13669 void *hdr;
13670
Johannes Berge6d6e342009-07-01 21:26:47 +020013671 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinena3b8b052009-03-27 21:59:49 +020013672 if (!msg)
13673 return;
13674
13675 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_MICHAEL_MIC_FAILURE);
13676 if (!hdr) {
13677 nlmsg_free(msg);
13678 return;
13679 }
13680
David S. Miller9360ffd2012-03-29 04:41:26 -040013681 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
13682 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
13683 (addr && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) ||
13684 nla_put_u32(msg, NL80211_ATTR_KEY_TYPE, key_type) ||
13685 (key_id != -1 &&
13686 nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_id)) ||
13687 (tsc && nla_put(msg, NL80211_ATTR_KEY_SEQ, 6, tsc)))
13688 goto nla_put_failure;
Jouni Malinena3b8b052009-03-27 21:59:49 +020013689
Johannes Berg3b7b72e2011-10-22 19:05:51 +020013690 genlmsg_end(msg, hdr);
Jouni Malinena3b8b052009-03-27 21:59:49 +020013691
Johannes Berg68eb5502013-11-19 15:19:38 +010013692 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010013693 NL80211_MCGRP_MLME, gfp);
Jouni Malinena3b8b052009-03-27 21:59:49 +020013694 return;
13695
13696 nla_put_failure:
13697 genlmsg_cancel(msg, hdr);
13698 nlmsg_free(msg);
13699}
13700
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040013701void nl80211_send_beacon_hint_event(struct wiphy *wiphy,
13702 struct ieee80211_channel *channel_before,
13703 struct ieee80211_channel *channel_after)
13704{
13705 struct sk_buff *msg;
13706 void *hdr;
13707 struct nlattr *nl_freq;
13708
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -070013709 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_ATOMIC);
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040013710 if (!msg)
13711 return;
13712
13713 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_BEACON_HINT);
13714 if (!hdr) {
13715 nlmsg_free(msg);
13716 return;
13717 }
13718
13719 /*
13720 * Since we are applying the beacon hint to a wiphy we know its
13721 * wiphy_idx is valid
13722 */
David S. Miller9360ffd2012-03-29 04:41:26 -040013723 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy)))
13724 goto nla_put_failure;
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040013725
13726 /* Before */
13727 nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_BEFORE);
13728 if (!nl_freq)
13729 goto nla_put_failure;
Johannes Bergcdc89b92013-02-18 23:54:36 +010013730 if (nl80211_msg_put_channel(msg, channel_before, false))
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040013731 goto nla_put_failure;
13732 nla_nest_end(msg, nl_freq);
13733
13734 /* After */
13735 nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_AFTER);
13736 if (!nl_freq)
13737 goto nla_put_failure;
Johannes Bergcdc89b92013-02-18 23:54:36 +010013738 if (nl80211_msg_put_channel(msg, channel_after, false))
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040013739 goto nla_put_failure;
13740 nla_nest_end(msg, nl_freq);
13741
Johannes Berg3b7b72e2011-10-22 19:05:51 +020013742 genlmsg_end(msg, hdr);
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040013743
Johannes Berg463d0182009-07-14 00:33:35 +020013744 rcu_read_lock();
Johannes Berg68eb5502013-11-19 15:19:38 +010013745 genlmsg_multicast_allns(&nl80211_fam, msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010013746 NL80211_MCGRP_REGULATORY, GFP_ATOMIC);
Johannes Berg463d0182009-07-14 00:33:35 +020013747 rcu_read_unlock();
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040013748
13749 return;
13750
13751nla_put_failure:
13752 genlmsg_cancel(msg, hdr);
13753 nlmsg_free(msg);
13754}
13755
Jouni Malinen9588bbd2009-12-23 13:15:41 +010013756static void nl80211_send_remain_on_chan_event(
13757 int cmd, struct cfg80211_registered_device *rdev,
Johannes Berg71bbc992012-06-15 15:30:18 +020013758 struct wireless_dev *wdev, u64 cookie,
Jouni Malinen9588bbd2009-12-23 13:15:41 +010013759 struct ieee80211_channel *chan,
Jouni Malinen9588bbd2009-12-23 13:15:41 +010013760 unsigned int duration, gfp_t gfp)
13761{
13762 struct sk_buff *msg;
13763 void *hdr;
13764
13765 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
13766 if (!msg)
13767 return;
13768
13769 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
13770 if (!hdr) {
13771 nlmsg_free(msg);
13772 return;
13773 }
13774
David S. Miller9360ffd2012-03-29 04:41:26 -040013775 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg71bbc992012-06-15 15:30:18 +020013776 (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
13777 wdev->netdev->ifindex)) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020013778 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
13779 NL80211_ATTR_PAD) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040013780 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, chan->center_freq) ||
Johannes Berg42d97a52012-11-08 18:31:02 +010013781 nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE,
13782 NL80211_CHAN_NO_HT) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020013783 nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie,
13784 NL80211_ATTR_PAD))
David S. Miller9360ffd2012-03-29 04:41:26 -040013785 goto nla_put_failure;
Jouni Malinen9588bbd2009-12-23 13:15:41 +010013786
David S. Miller9360ffd2012-03-29 04:41:26 -040013787 if (cmd == NL80211_CMD_REMAIN_ON_CHANNEL &&
13788 nla_put_u32(msg, NL80211_ATTR_DURATION, duration))
13789 goto nla_put_failure;
Jouni Malinen9588bbd2009-12-23 13:15:41 +010013790
Johannes Berg3b7b72e2011-10-22 19:05:51 +020013791 genlmsg_end(msg, hdr);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010013792
Johannes Berg68eb5502013-11-19 15:19:38 +010013793 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010013794 NL80211_MCGRP_MLME, gfp);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010013795 return;
13796
13797 nla_put_failure:
13798 genlmsg_cancel(msg, hdr);
13799 nlmsg_free(msg);
13800}
13801
Johannes Berg947add32013-02-22 22:05:20 +010013802void cfg80211_ready_on_channel(struct wireless_dev *wdev, u64 cookie,
13803 struct ieee80211_channel *chan,
13804 unsigned int duration, gfp_t gfp)
Jouni Malinen9588bbd2009-12-23 13:15:41 +010013805{
Johannes Berg947add32013-02-22 22:05:20 +010013806 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080013807 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg947add32013-02-22 22:05:20 +010013808
13809 trace_cfg80211_ready_on_channel(wdev, cookie, chan, duration);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010013810 nl80211_send_remain_on_chan_event(NL80211_CMD_REMAIN_ON_CHANNEL,
Johannes Berg71bbc992012-06-15 15:30:18 +020013811 rdev, wdev, cookie, chan,
Johannes Berg42d97a52012-11-08 18:31:02 +010013812 duration, gfp);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010013813}
Johannes Berg947add32013-02-22 22:05:20 +010013814EXPORT_SYMBOL(cfg80211_ready_on_channel);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010013815
Johannes Berg947add32013-02-22 22:05:20 +010013816void cfg80211_remain_on_channel_expired(struct wireless_dev *wdev, u64 cookie,
13817 struct ieee80211_channel *chan,
13818 gfp_t gfp)
Jouni Malinen9588bbd2009-12-23 13:15:41 +010013819{
Johannes Berg947add32013-02-22 22:05:20 +010013820 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080013821 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg947add32013-02-22 22:05:20 +010013822
13823 trace_cfg80211_ready_on_channel_expired(wdev, cookie, chan);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010013824 nl80211_send_remain_on_chan_event(NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL,
Johannes Berg42d97a52012-11-08 18:31:02 +010013825 rdev, wdev, cookie, chan, 0, gfp);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010013826}
Johannes Berg947add32013-02-22 22:05:20 +010013827EXPORT_SYMBOL(cfg80211_remain_on_channel_expired);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010013828
Johannes Berg947add32013-02-22 22:05:20 +010013829void cfg80211_new_sta(struct net_device *dev, const u8 *mac_addr,
13830 struct station_info *sinfo, gfp_t gfp)
Johannes Berg98b62182009-12-23 13:15:44 +010013831{
Johannes Berg947add32013-02-22 22:05:20 +010013832 struct wiphy *wiphy = dev->ieee80211_ptr->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080013833 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg98b62182009-12-23 13:15:44 +010013834 struct sk_buff *msg;
13835
Johannes Berg947add32013-02-22 22:05:20 +010013836 trace_cfg80211_new_sta(dev, mac_addr, sinfo);
13837
Thomas Graf58050fc2012-06-28 03:57:45 +000013838 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Johannes Berg98b62182009-12-23 13:15:44 +010013839 if (!msg)
13840 return;
13841
Johannes Bergcf5ead82014-11-14 17:14:00 +010013842 if (nl80211_send_station(msg, NL80211_CMD_NEW_STATION, 0, 0, 0,
John W. Linville66266b32012-03-15 13:25:41 -040013843 rdev, dev, mac_addr, sinfo) < 0) {
Johannes Berg98b62182009-12-23 13:15:44 +010013844 nlmsg_free(msg);
13845 return;
13846 }
13847
Johannes Berg68eb5502013-11-19 15:19:38 +010013848 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010013849 NL80211_MCGRP_MLME, gfp);
Johannes Berg98b62182009-12-23 13:15:44 +010013850}
Johannes Berg947add32013-02-22 22:05:20 +010013851EXPORT_SYMBOL(cfg80211_new_sta);
Johannes Berg98b62182009-12-23 13:15:44 +010013852
Johannes Bergcf5ead82014-11-14 17:14:00 +010013853void cfg80211_del_sta_sinfo(struct net_device *dev, const u8 *mac_addr,
13854 struct station_info *sinfo, gfp_t gfp)
Jouni Malinenec15e682011-03-23 15:29:52 +020013855{
Johannes Berg947add32013-02-22 22:05:20 +010013856 struct wiphy *wiphy = dev->ieee80211_ptr->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080013857 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Jouni Malinenec15e682011-03-23 15:29:52 +020013858 struct sk_buff *msg;
Johannes Bergcf5ead82014-11-14 17:14:00 +010013859 struct station_info empty_sinfo = {};
13860
13861 if (!sinfo)
13862 sinfo = &empty_sinfo;
Jouni Malinenec15e682011-03-23 15:29:52 +020013863
Johannes Berg947add32013-02-22 22:05:20 +010013864 trace_cfg80211_del_sta(dev, mac_addr);
13865
Thomas Graf58050fc2012-06-28 03:57:45 +000013866 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinenec15e682011-03-23 15:29:52 +020013867 if (!msg)
13868 return;
13869
Johannes Bergcf5ead82014-11-14 17:14:00 +010013870 if (nl80211_send_station(msg, NL80211_CMD_DEL_STATION, 0, 0, 0,
Johannes Berg57007122015-01-16 21:05:02 +010013871 rdev, dev, mac_addr, sinfo) < 0) {
Jouni Malinenec15e682011-03-23 15:29:52 +020013872 nlmsg_free(msg);
13873 return;
13874 }
13875
Johannes Berg68eb5502013-11-19 15:19:38 +010013876 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010013877 NL80211_MCGRP_MLME, gfp);
Jouni Malinenec15e682011-03-23 15:29:52 +020013878}
Johannes Bergcf5ead82014-11-14 17:14:00 +010013879EXPORT_SYMBOL(cfg80211_del_sta_sinfo);
Jouni Malinenec15e682011-03-23 15:29:52 +020013880
Johannes Berg947add32013-02-22 22:05:20 +010013881void cfg80211_conn_failed(struct net_device *dev, const u8 *mac_addr,
13882 enum nl80211_connect_failed_reason reason,
13883 gfp_t gfp)
Pandiyarajan Pitchaimuthued44a952012-09-18 16:50:49 +053013884{
Johannes Berg947add32013-02-22 22:05:20 +010013885 struct wiphy *wiphy = dev->ieee80211_ptr->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080013886 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Pandiyarajan Pitchaimuthued44a952012-09-18 16:50:49 +053013887 struct sk_buff *msg;
13888 void *hdr;
13889
13890 msg = nlmsg_new(NLMSG_GOODSIZE, gfp);
13891 if (!msg)
13892 return;
13893
13894 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONN_FAILED);
13895 if (!hdr) {
13896 nlmsg_free(msg);
13897 return;
13898 }
13899
13900 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
13901 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) ||
13902 nla_put_u32(msg, NL80211_ATTR_CONN_FAILED_REASON, reason))
13903 goto nla_put_failure;
13904
13905 genlmsg_end(msg, hdr);
13906
Johannes Berg68eb5502013-11-19 15:19:38 +010013907 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010013908 NL80211_MCGRP_MLME, gfp);
Pandiyarajan Pitchaimuthued44a952012-09-18 16:50:49 +053013909 return;
13910
13911 nla_put_failure:
13912 genlmsg_cancel(msg, hdr);
13913 nlmsg_free(msg);
13914}
Johannes Berg947add32013-02-22 22:05:20 +010013915EXPORT_SYMBOL(cfg80211_conn_failed);
Pandiyarajan Pitchaimuthued44a952012-09-18 16:50:49 +053013916
Johannes Bergb92ab5d2011-11-04 11:18:19 +010013917static bool __nl80211_unexpected_frame(struct net_device *dev, u8 cmd,
13918 const u8 *addr, gfp_t gfp)
Johannes Berg28946da2011-11-04 11:18:12 +010013919{
13920 struct wireless_dev *wdev = dev->ieee80211_ptr;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080013921 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Johannes Berg28946da2011-11-04 11:18:12 +010013922 struct sk_buff *msg;
13923 void *hdr;
Eric W. Biederman15e47302012-09-07 20:12:54 +000013924 u32 nlportid = ACCESS_ONCE(wdev->ap_unexpected_nlportid);
Johannes Berg28946da2011-11-04 11:18:12 +010013925
Eric W. Biederman15e47302012-09-07 20:12:54 +000013926 if (!nlportid)
Johannes Berg28946da2011-11-04 11:18:12 +010013927 return false;
13928
13929 msg = nlmsg_new(100, gfp);
13930 if (!msg)
13931 return true;
13932
Johannes Bergb92ab5d2011-11-04 11:18:19 +010013933 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
Johannes Berg28946da2011-11-04 11:18:12 +010013934 if (!hdr) {
13935 nlmsg_free(msg);
13936 return true;
13937 }
13938
David S. Miller9360ffd2012-03-29 04:41:26 -040013939 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
13940 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
13941 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr))
13942 goto nla_put_failure;
Johannes Berg28946da2011-11-04 11:18:12 +010013943
Johannes Berg9c90a9f2013-06-04 12:46:03 +020013944 genlmsg_end(msg, hdr);
Eric W. Biederman15e47302012-09-07 20:12:54 +000013945 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid);
Johannes Berg28946da2011-11-04 11:18:12 +010013946 return true;
13947
13948 nla_put_failure:
13949 genlmsg_cancel(msg, hdr);
13950 nlmsg_free(msg);
13951 return true;
13952}
13953
Johannes Berg947add32013-02-22 22:05:20 +010013954bool cfg80211_rx_spurious_frame(struct net_device *dev,
13955 const u8 *addr, gfp_t gfp)
Johannes Bergb92ab5d2011-11-04 11:18:19 +010013956{
Johannes Berg947add32013-02-22 22:05:20 +010013957 struct wireless_dev *wdev = dev->ieee80211_ptr;
13958 bool ret;
Johannes Bergb92ab5d2011-11-04 11:18:19 +010013959
Johannes Berg947add32013-02-22 22:05:20 +010013960 trace_cfg80211_rx_spurious_frame(dev, addr);
13961
13962 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP &&
13963 wdev->iftype != NL80211_IFTYPE_P2P_GO)) {
13964 trace_cfg80211_return_bool(false);
13965 return false;
13966 }
13967 ret = __nl80211_unexpected_frame(dev, NL80211_CMD_UNEXPECTED_FRAME,
13968 addr, gfp);
13969 trace_cfg80211_return_bool(ret);
13970 return ret;
Johannes Bergb92ab5d2011-11-04 11:18:19 +010013971}
Johannes Berg947add32013-02-22 22:05:20 +010013972EXPORT_SYMBOL(cfg80211_rx_spurious_frame);
13973
13974bool cfg80211_rx_unexpected_4addr_frame(struct net_device *dev,
13975 const u8 *addr, gfp_t gfp)
13976{
13977 struct wireless_dev *wdev = dev->ieee80211_ptr;
13978 bool ret;
13979
13980 trace_cfg80211_rx_unexpected_4addr_frame(dev, addr);
13981
13982 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP &&
13983 wdev->iftype != NL80211_IFTYPE_P2P_GO &&
13984 wdev->iftype != NL80211_IFTYPE_AP_VLAN)) {
13985 trace_cfg80211_return_bool(false);
13986 return false;
13987 }
13988 ret = __nl80211_unexpected_frame(dev,
13989 NL80211_CMD_UNEXPECTED_4ADDR_FRAME,
13990 addr, gfp);
13991 trace_cfg80211_return_bool(ret);
13992 return ret;
13993}
13994EXPORT_SYMBOL(cfg80211_rx_unexpected_4addr_frame);
Johannes Bergb92ab5d2011-11-04 11:18:19 +010013995
Johannes Berg2e161f72010-08-12 15:38:38 +020013996int nl80211_send_mgmt(struct cfg80211_registered_device *rdev,
Eric W. Biederman15e47302012-09-07 20:12:54 +000013997 struct wireless_dev *wdev, u32 nlportid,
Johannes Berg804483e2012-03-05 22:18:41 +010013998 int freq, int sig_dbm,
Vladimir Kondratiev19504cf2013-08-15 14:51:28 +030013999 const u8 *buf, size_t len, u32 flags, gfp_t gfp)
Jouni Malinen026331c2010-02-15 12:53:10 +020014000{
Johannes Berg71bbc992012-06-15 15:30:18 +020014001 struct net_device *netdev = wdev->netdev;
Jouni Malinen026331c2010-02-15 12:53:10 +020014002 struct sk_buff *msg;
14003 void *hdr;
Jouni Malinen026331c2010-02-15 12:53:10 +020014004
Johannes Berg4ef8c1c2017-01-09 11:10:42 +010014005 msg = nlmsg_new(100 + len, gfp);
Jouni Malinen026331c2010-02-15 12:53:10 +020014006 if (!msg)
14007 return -ENOMEM;
14008
Johannes Berg2e161f72010-08-12 15:38:38 +020014009 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME);
Jouni Malinen026331c2010-02-15 12:53:10 +020014010 if (!hdr) {
14011 nlmsg_free(msg);
14012 return -ENOMEM;
14013 }
14014
David S. Miller9360ffd2012-03-29 04:41:26 -040014015 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg71bbc992012-06-15 15:30:18 +020014016 (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
14017 netdev->ifindex)) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020014018 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
14019 NL80211_ATTR_PAD) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040014020 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq) ||
14021 (sig_dbm &&
14022 nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) ||
Vladimir Kondratiev19504cf2013-08-15 14:51:28 +030014023 nla_put(msg, NL80211_ATTR_FRAME, len, buf) ||
14024 (flags &&
14025 nla_put_u32(msg, NL80211_ATTR_RXMGMT_FLAGS, flags)))
David S. Miller9360ffd2012-03-29 04:41:26 -040014026 goto nla_put_failure;
Jouni Malinen026331c2010-02-15 12:53:10 +020014027
Johannes Berg3b7b72e2011-10-22 19:05:51 +020014028 genlmsg_end(msg, hdr);
Jouni Malinen026331c2010-02-15 12:53:10 +020014029
Eric W. Biederman15e47302012-09-07 20:12:54 +000014030 return genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid);
Jouni Malinen026331c2010-02-15 12:53:10 +020014031
14032 nla_put_failure:
14033 genlmsg_cancel(msg, hdr);
14034 nlmsg_free(msg);
14035 return -ENOBUFS;
14036}
14037
Johannes Berg947add32013-02-22 22:05:20 +010014038void cfg80211_mgmt_tx_status(struct wireless_dev *wdev, u64 cookie,
14039 const u8 *buf, size_t len, bool ack, gfp_t gfp)
Jouni Malinen026331c2010-02-15 12:53:10 +020014040{
Johannes Berg947add32013-02-22 22:05:20 +010014041 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080014042 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg71bbc992012-06-15 15:30:18 +020014043 struct net_device *netdev = wdev->netdev;
Jouni Malinen026331c2010-02-15 12:53:10 +020014044 struct sk_buff *msg;
14045 void *hdr;
14046
Johannes Berg947add32013-02-22 22:05:20 +010014047 trace_cfg80211_mgmt_tx_status(wdev, cookie, ack);
14048
Johannes Berg4ef8c1c2017-01-09 11:10:42 +010014049 msg = nlmsg_new(100 + len, gfp);
Jouni Malinen026331c2010-02-15 12:53:10 +020014050 if (!msg)
14051 return;
14052
Johannes Berg2e161f72010-08-12 15:38:38 +020014053 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME_TX_STATUS);
Jouni Malinen026331c2010-02-15 12:53:10 +020014054 if (!hdr) {
14055 nlmsg_free(msg);
14056 return;
14057 }
14058
David S. Miller9360ffd2012-03-29 04:41:26 -040014059 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg71bbc992012-06-15 15:30:18 +020014060 (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
14061 netdev->ifindex)) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020014062 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
14063 NL80211_ATTR_PAD) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040014064 nla_put(msg, NL80211_ATTR_FRAME, len, buf) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020014065 nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie,
14066 NL80211_ATTR_PAD) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040014067 (ack && nla_put_flag(msg, NL80211_ATTR_ACK)))
14068 goto nla_put_failure;
Jouni Malinen026331c2010-02-15 12:53:10 +020014069
Johannes Berg3b7b72e2011-10-22 19:05:51 +020014070 genlmsg_end(msg, hdr);
Jouni Malinen026331c2010-02-15 12:53:10 +020014071
Johannes Berg68eb5502013-11-19 15:19:38 +010014072 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010014073 NL80211_MCGRP_MLME, gfp);
Jouni Malinen026331c2010-02-15 12:53:10 +020014074 return;
14075
14076 nla_put_failure:
14077 genlmsg_cancel(msg, hdr);
14078 nlmsg_free(msg);
14079}
Johannes Berg947add32013-02-22 22:05:20 +010014080EXPORT_SYMBOL(cfg80211_mgmt_tx_status);
Jouni Malinen026331c2010-02-15 12:53:10 +020014081
Johannes Berg5b97f492014-11-26 12:37:43 +010014082static struct sk_buff *cfg80211_prepare_cqm(struct net_device *dev,
14083 const char *mac, gfp_t gfp)
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020014084{
Johannes Berg947add32013-02-22 22:05:20 +010014085 struct wireless_dev *wdev = dev->ieee80211_ptr;
Johannes Berg5b97f492014-11-26 12:37:43 +010014086 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
14087 struct sk_buff *msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
14088 void **cb;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020014089
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020014090 if (!msg)
Johannes Berg5b97f492014-11-26 12:37:43 +010014091 return NULL;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020014092
Johannes Berg5b97f492014-11-26 12:37:43 +010014093 cb = (void **)msg->cb;
14094
14095 cb[0] = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM);
14096 if (!cb[0]) {
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020014097 nlmsg_free(msg);
Johannes Berg5b97f492014-11-26 12:37:43 +010014098 return NULL;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020014099 }
14100
David S. Miller9360ffd2012-03-29 04:41:26 -040014101 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg947add32013-02-22 22:05:20 +010014102 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex))
David S. Miller9360ffd2012-03-29 04:41:26 -040014103 goto nla_put_failure;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020014104
Johannes Berg5b97f492014-11-26 12:37:43 +010014105 if (mac && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac))
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020014106 goto nla_put_failure;
14107
Johannes Berg5b97f492014-11-26 12:37:43 +010014108 cb[1] = nla_nest_start(msg, NL80211_ATTR_CQM);
14109 if (!cb[1])
14110 goto nla_put_failure;
14111
14112 cb[2] = rdev;
14113
14114 return msg;
14115 nla_put_failure:
14116 nlmsg_free(msg);
14117 return NULL;
14118}
14119
14120static void cfg80211_send_cqm(struct sk_buff *msg, gfp_t gfp)
14121{
14122 void **cb = (void **)msg->cb;
14123 struct cfg80211_registered_device *rdev = cb[2];
14124
14125 nla_nest_end(msg, cb[1]);
14126 genlmsg_end(msg, cb[0]);
14127
14128 memset(msg->cb, 0, sizeof(msg->cb));
14129
14130 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
14131 NL80211_MCGRP_MLME, gfp);
14132}
14133
14134void cfg80211_cqm_rssi_notify(struct net_device *dev,
14135 enum nl80211_cqm_rssi_threshold_event rssi_event,
Andrzej Zaborowskibee427b2017-01-25 12:43:41 +010014136 s32 rssi_level, gfp_t gfp)
Johannes Berg5b97f492014-11-26 12:37:43 +010014137{
14138 struct sk_buff *msg;
Andrew Zaborowski4a4b8162017-02-10 10:02:31 +010014139 struct wireless_dev *wdev = dev->ieee80211_ptr;
14140 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Johannes Berg5b97f492014-11-26 12:37:43 +010014141
Andrzej Zaborowskibee427b2017-01-25 12:43:41 +010014142 trace_cfg80211_cqm_rssi_notify(dev, rssi_event, rssi_level);
Johannes Berg5b97f492014-11-26 12:37:43 +010014143
Johannes Berg98f03342014-11-26 12:42:02 +010014144 if (WARN_ON(rssi_event != NL80211_CQM_RSSI_THRESHOLD_EVENT_LOW &&
14145 rssi_event != NL80211_CQM_RSSI_THRESHOLD_EVENT_HIGH))
14146 return;
14147
Andrew Zaborowski4a4b8162017-02-10 10:02:31 +010014148 if (wdev->cqm_config) {
14149 wdev->cqm_config->last_rssi_event_value = rssi_level;
14150
14151 cfg80211_cqm_rssi_update(rdev, dev);
14152
14153 if (rssi_level == 0)
14154 rssi_level = wdev->cqm_config->last_rssi_event_value;
14155 }
14156
Johannes Berg5b97f492014-11-26 12:37:43 +010014157 msg = cfg80211_prepare_cqm(dev, NULL, gfp);
14158 if (!msg)
14159 return;
14160
David S. Miller9360ffd2012-03-29 04:41:26 -040014161 if (nla_put_u32(msg, NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT,
14162 rssi_event))
14163 goto nla_put_failure;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020014164
Andrzej Zaborowskibee427b2017-01-25 12:43:41 +010014165 if (rssi_level && nla_put_s32(msg, NL80211_ATTR_CQM_RSSI_LEVEL,
14166 rssi_level))
14167 goto nla_put_failure;
14168
Johannes Berg5b97f492014-11-26 12:37:43 +010014169 cfg80211_send_cqm(msg, gfp);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020014170
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020014171 return;
14172
14173 nla_put_failure:
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020014174 nlmsg_free(msg);
14175}
Johannes Berg947add32013-02-22 22:05:20 +010014176EXPORT_SYMBOL(cfg80211_cqm_rssi_notify);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020014177
Johannes Berg5b97f492014-11-26 12:37:43 +010014178void cfg80211_cqm_txe_notify(struct net_device *dev,
14179 const u8 *peer, u32 num_packets,
14180 u32 rate, u32 intvl, gfp_t gfp)
14181{
14182 struct sk_buff *msg;
14183
14184 msg = cfg80211_prepare_cqm(dev, peer, gfp);
14185 if (!msg)
14186 return;
14187
14188 if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_PKTS, num_packets))
14189 goto nla_put_failure;
14190
14191 if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_RATE, rate))
14192 goto nla_put_failure;
14193
14194 if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_INTVL, intvl))
14195 goto nla_put_failure;
14196
14197 cfg80211_send_cqm(msg, gfp);
14198 return;
14199
14200 nla_put_failure:
14201 nlmsg_free(msg);
14202}
14203EXPORT_SYMBOL(cfg80211_cqm_txe_notify);
14204
14205void cfg80211_cqm_pktloss_notify(struct net_device *dev,
14206 const u8 *peer, u32 num_packets, gfp_t gfp)
14207{
14208 struct sk_buff *msg;
14209
14210 trace_cfg80211_cqm_pktloss_notify(dev, peer, num_packets);
14211
14212 msg = cfg80211_prepare_cqm(dev, peer, gfp);
14213 if (!msg)
14214 return;
14215
14216 if (nla_put_u32(msg, NL80211_ATTR_CQM_PKT_LOSS_EVENT, num_packets))
14217 goto nla_put_failure;
14218
14219 cfg80211_send_cqm(msg, gfp);
14220 return;
14221
14222 nla_put_failure:
14223 nlmsg_free(msg);
14224}
14225EXPORT_SYMBOL(cfg80211_cqm_pktloss_notify);
14226
Johannes Berg98f03342014-11-26 12:42:02 +010014227void cfg80211_cqm_beacon_loss_notify(struct net_device *dev, gfp_t gfp)
14228{
14229 struct sk_buff *msg;
14230
14231 msg = cfg80211_prepare_cqm(dev, NULL, gfp);
14232 if (!msg)
14233 return;
14234
14235 if (nla_put_flag(msg, NL80211_ATTR_CQM_BEACON_LOSS_EVENT))
14236 goto nla_put_failure;
14237
14238 cfg80211_send_cqm(msg, gfp);
14239 return;
14240
14241 nla_put_failure:
14242 nlmsg_free(msg);
14243}
14244EXPORT_SYMBOL(cfg80211_cqm_beacon_loss_notify);
14245
Johannes Berg947add32013-02-22 22:05:20 +010014246static void nl80211_gtk_rekey_notify(struct cfg80211_registered_device *rdev,
14247 struct net_device *netdev, const u8 *bssid,
14248 const u8 *replay_ctr, gfp_t gfp)
Johannes Berge5497d72011-07-05 16:35:40 +020014249{
14250 struct sk_buff *msg;
14251 struct nlattr *rekey_attr;
14252 void *hdr;
14253
Thomas Graf58050fc2012-06-28 03:57:45 +000014254 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Johannes Berge5497d72011-07-05 16:35:40 +020014255 if (!msg)
14256 return;
14257
14258 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_REKEY_OFFLOAD);
14259 if (!hdr) {
14260 nlmsg_free(msg);
14261 return;
14262 }
14263
David S. Miller9360ffd2012-03-29 04:41:26 -040014264 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
14265 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
14266 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid))
14267 goto nla_put_failure;
Johannes Berge5497d72011-07-05 16:35:40 +020014268
14269 rekey_attr = nla_nest_start(msg, NL80211_ATTR_REKEY_DATA);
14270 if (!rekey_attr)
14271 goto nla_put_failure;
14272
David S. Miller9360ffd2012-03-29 04:41:26 -040014273 if (nla_put(msg, NL80211_REKEY_DATA_REPLAY_CTR,
14274 NL80211_REPLAY_CTR_LEN, replay_ctr))
14275 goto nla_put_failure;
Johannes Berge5497d72011-07-05 16:35:40 +020014276
14277 nla_nest_end(msg, rekey_attr);
14278
Johannes Berg3b7b72e2011-10-22 19:05:51 +020014279 genlmsg_end(msg, hdr);
Johannes Berge5497d72011-07-05 16:35:40 +020014280
Johannes Berg68eb5502013-11-19 15:19:38 +010014281 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010014282 NL80211_MCGRP_MLME, gfp);
Johannes Berge5497d72011-07-05 16:35:40 +020014283 return;
14284
14285 nla_put_failure:
14286 genlmsg_cancel(msg, hdr);
14287 nlmsg_free(msg);
14288}
14289
Johannes Berg947add32013-02-22 22:05:20 +010014290void cfg80211_gtk_rekey_notify(struct net_device *dev, const u8 *bssid,
14291 const u8 *replay_ctr, gfp_t gfp)
14292{
14293 struct wireless_dev *wdev = dev->ieee80211_ptr;
14294 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080014295 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg947add32013-02-22 22:05:20 +010014296
14297 trace_cfg80211_gtk_rekey_notify(dev, bssid);
14298 nl80211_gtk_rekey_notify(rdev, dev, bssid, replay_ctr, gfp);
14299}
14300EXPORT_SYMBOL(cfg80211_gtk_rekey_notify);
14301
14302static void
14303nl80211_pmksa_candidate_notify(struct cfg80211_registered_device *rdev,
14304 struct net_device *netdev, int index,
14305 const u8 *bssid, bool preauth, gfp_t gfp)
Jouni Malinenc9df56b2011-09-16 18:56:23 +030014306{
14307 struct sk_buff *msg;
14308 struct nlattr *attr;
14309 void *hdr;
14310
Thomas Graf58050fc2012-06-28 03:57:45 +000014311 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinenc9df56b2011-09-16 18:56:23 +030014312 if (!msg)
14313 return;
14314
14315 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PMKSA_CANDIDATE);
14316 if (!hdr) {
14317 nlmsg_free(msg);
14318 return;
14319 }
14320
David S. Miller9360ffd2012-03-29 04:41:26 -040014321 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
14322 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex))
14323 goto nla_put_failure;
Jouni Malinenc9df56b2011-09-16 18:56:23 +030014324
14325 attr = nla_nest_start(msg, NL80211_ATTR_PMKSA_CANDIDATE);
14326 if (!attr)
14327 goto nla_put_failure;
14328
David S. Miller9360ffd2012-03-29 04:41:26 -040014329 if (nla_put_u32(msg, NL80211_PMKSA_CANDIDATE_INDEX, index) ||
14330 nla_put(msg, NL80211_PMKSA_CANDIDATE_BSSID, ETH_ALEN, bssid) ||
14331 (preauth &&
14332 nla_put_flag(msg, NL80211_PMKSA_CANDIDATE_PREAUTH)))
14333 goto nla_put_failure;
Jouni Malinenc9df56b2011-09-16 18:56:23 +030014334
14335 nla_nest_end(msg, attr);
14336
Johannes Berg3b7b72e2011-10-22 19:05:51 +020014337 genlmsg_end(msg, hdr);
Jouni Malinenc9df56b2011-09-16 18:56:23 +030014338
Johannes Berg68eb5502013-11-19 15:19:38 +010014339 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010014340 NL80211_MCGRP_MLME, gfp);
Jouni Malinenc9df56b2011-09-16 18:56:23 +030014341 return;
14342
14343 nla_put_failure:
14344 genlmsg_cancel(msg, hdr);
14345 nlmsg_free(msg);
14346}
14347
Johannes Berg947add32013-02-22 22:05:20 +010014348void cfg80211_pmksa_candidate_notify(struct net_device *dev, int index,
14349 const u8 *bssid, bool preauth, gfp_t gfp)
14350{
14351 struct wireless_dev *wdev = dev->ieee80211_ptr;
14352 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080014353 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg947add32013-02-22 22:05:20 +010014354
14355 trace_cfg80211_pmksa_candidate_notify(dev, index, bssid, preauth);
14356 nl80211_pmksa_candidate_notify(rdev, dev, index, bssid, preauth, gfp);
14357}
14358EXPORT_SYMBOL(cfg80211_pmksa_candidate_notify);
14359
14360static void nl80211_ch_switch_notify(struct cfg80211_registered_device *rdev,
14361 struct net_device *netdev,
14362 struct cfg80211_chan_def *chandef,
Luciano Coelhof8d75522014-11-07 14:31:35 +020014363 gfp_t gfp,
14364 enum nl80211_commands notif,
14365 u8 count)
Thomas Pedersen53145262012-04-06 13:35:47 -070014366{
14367 struct sk_buff *msg;
14368 void *hdr;
14369
Thomas Graf58050fc2012-06-28 03:57:45 +000014370 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Thomas Pedersen53145262012-04-06 13:35:47 -070014371 if (!msg)
14372 return;
14373
Luciano Coelhof8d75522014-11-07 14:31:35 +020014374 hdr = nl80211hdr_put(msg, 0, 0, 0, notif);
Thomas Pedersen53145262012-04-06 13:35:47 -070014375 if (!hdr) {
14376 nlmsg_free(msg);
14377 return;
14378 }
14379
Johannes Berg683b6d32012-11-08 21:25:48 +010014380 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex))
14381 goto nla_put_failure;
14382
14383 if (nl80211_send_chandef(msg, chandef))
John W. Linville7eab0f62012-04-12 14:25:14 -040014384 goto nla_put_failure;
Thomas Pedersen53145262012-04-06 13:35:47 -070014385
Luciano Coelhof8d75522014-11-07 14:31:35 +020014386 if ((notif == NL80211_CMD_CH_SWITCH_STARTED_NOTIFY) &&
14387 (nla_put_u32(msg, NL80211_ATTR_CH_SWITCH_COUNT, count)))
14388 goto nla_put_failure;
14389
Thomas Pedersen53145262012-04-06 13:35:47 -070014390 genlmsg_end(msg, hdr);
14391
Johannes Berg68eb5502013-11-19 15:19:38 +010014392 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010014393 NL80211_MCGRP_MLME, gfp);
Thomas Pedersen53145262012-04-06 13:35:47 -070014394 return;
14395
14396 nla_put_failure:
14397 genlmsg_cancel(msg, hdr);
14398 nlmsg_free(msg);
14399}
14400
Johannes Berg947add32013-02-22 22:05:20 +010014401void cfg80211_ch_switch_notify(struct net_device *dev,
14402 struct cfg80211_chan_def *chandef)
Thomas Pedersen84f10702012-07-12 16:17:33 -070014403{
Johannes Berg947add32013-02-22 22:05:20 +010014404 struct wireless_dev *wdev = dev->ieee80211_ptr;
14405 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080014406 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg947add32013-02-22 22:05:20 +010014407
Simon Wunderliche487eae2013-11-21 18:19:51 +010014408 ASSERT_WDEV_LOCK(wdev);
Johannes Berg947add32013-02-22 22:05:20 +010014409
Simon Wunderliche487eae2013-11-21 18:19:51 +010014410 trace_cfg80211_ch_switch_notify(dev, chandef);
Johannes Berg947add32013-02-22 22:05:20 +010014411
Michal Kazior9e0e2962014-01-29 14:22:27 +010014412 wdev->chandef = *chandef;
Janusz Dziedzic96f55f12014-01-24 14:29:21 +010014413 wdev->preset_chandef = *chandef;
Luciano Coelhof8d75522014-11-07 14:31:35 +020014414 nl80211_ch_switch_notify(rdev, dev, chandef, GFP_KERNEL,
14415 NL80211_CMD_CH_SWITCH_NOTIFY, 0);
Johannes Berg947add32013-02-22 22:05:20 +010014416}
14417EXPORT_SYMBOL(cfg80211_ch_switch_notify);
14418
Luciano Coelhof8d75522014-11-07 14:31:35 +020014419void cfg80211_ch_switch_started_notify(struct net_device *dev,
14420 struct cfg80211_chan_def *chandef,
14421 u8 count)
14422{
14423 struct wireless_dev *wdev = dev->ieee80211_ptr;
14424 struct wiphy *wiphy = wdev->wiphy;
14425 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
14426
14427 trace_cfg80211_ch_switch_started_notify(dev, chandef);
14428
14429 nl80211_ch_switch_notify(rdev, dev, chandef, GFP_KERNEL,
14430 NL80211_CMD_CH_SWITCH_STARTED_NOTIFY, count);
14431}
14432EXPORT_SYMBOL(cfg80211_ch_switch_started_notify);
14433
Thomas Pedersen84f10702012-07-12 16:17:33 -070014434void
Simon Wunderlich04f39042013-02-08 18:16:19 +010014435nl80211_radar_notify(struct cfg80211_registered_device *rdev,
Janusz Dziedzicd2859df2013-11-06 13:55:51 +010014436 const struct cfg80211_chan_def *chandef,
Simon Wunderlich04f39042013-02-08 18:16:19 +010014437 enum nl80211_radar_event event,
14438 struct net_device *netdev, gfp_t gfp)
14439{
14440 struct sk_buff *msg;
14441 void *hdr;
14442
14443 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
14444 if (!msg)
14445 return;
14446
14447 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_RADAR_DETECT);
14448 if (!hdr) {
14449 nlmsg_free(msg);
14450 return;
14451 }
14452
14453 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx))
14454 goto nla_put_failure;
14455
14456 /* NOP and radar events don't need a netdev parameter */
14457 if (netdev) {
14458 struct wireless_dev *wdev = netdev->ieee80211_ptr;
14459
14460 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020014461 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
14462 NL80211_ATTR_PAD))
Simon Wunderlich04f39042013-02-08 18:16:19 +010014463 goto nla_put_failure;
14464 }
14465
14466 if (nla_put_u32(msg, NL80211_ATTR_RADAR_EVENT, event))
14467 goto nla_put_failure;
14468
14469 if (nl80211_send_chandef(msg, chandef))
14470 goto nla_put_failure;
14471
Johannes Berg9c90a9f2013-06-04 12:46:03 +020014472 genlmsg_end(msg, hdr);
Simon Wunderlich04f39042013-02-08 18:16:19 +010014473
Johannes Berg68eb5502013-11-19 15:19:38 +010014474 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010014475 NL80211_MCGRP_MLME, gfp);
Simon Wunderlich04f39042013-02-08 18:16:19 +010014476 return;
14477
14478 nla_put_failure:
14479 genlmsg_cancel(msg, hdr);
14480 nlmsg_free(msg);
14481}
14482
Johannes Berg7f6cf312011-11-04 11:18:15 +010014483void cfg80211_probe_status(struct net_device *dev, const u8 *addr,
14484 u64 cookie, bool acked, gfp_t gfp)
14485{
14486 struct wireless_dev *wdev = dev->ieee80211_ptr;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080014487 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Johannes Berg7f6cf312011-11-04 11:18:15 +010014488 struct sk_buff *msg;
14489 void *hdr;
Johannes Berg7f6cf312011-11-04 11:18:15 +010014490
Beni Lev4ee3e062012-08-27 12:49:39 +030014491 trace_cfg80211_probe_status(dev, addr, cookie, acked);
14492
Thomas Graf58050fc2012-06-28 03:57:45 +000014493 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Beni Lev4ee3e062012-08-27 12:49:39 +030014494
Johannes Berg7f6cf312011-11-04 11:18:15 +010014495 if (!msg)
14496 return;
14497
14498 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PROBE_CLIENT);
14499 if (!hdr) {
14500 nlmsg_free(msg);
14501 return;
14502 }
14503
David S. Miller9360ffd2012-03-29 04:41:26 -040014504 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
14505 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
14506 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020014507 nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie,
14508 NL80211_ATTR_PAD) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040014509 (acked && nla_put_flag(msg, NL80211_ATTR_ACK)))
14510 goto nla_put_failure;
Johannes Berg7f6cf312011-11-04 11:18:15 +010014511
Johannes Berg9c90a9f2013-06-04 12:46:03 +020014512 genlmsg_end(msg, hdr);
Johannes Berg7f6cf312011-11-04 11:18:15 +010014513
Johannes Berg68eb5502013-11-19 15:19:38 +010014514 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010014515 NL80211_MCGRP_MLME, gfp);
Johannes Berg7f6cf312011-11-04 11:18:15 +010014516 return;
14517
14518 nla_put_failure:
14519 genlmsg_cancel(msg, hdr);
14520 nlmsg_free(msg);
14521}
14522EXPORT_SYMBOL(cfg80211_probe_status);
14523
Johannes Berg5e760232011-11-04 11:18:17 +010014524void cfg80211_report_obss_beacon(struct wiphy *wiphy,
14525 const u8 *frame, size_t len,
Ben Greear37c73b52012-10-26 14:49:25 -070014526 int freq, int sig_dbm)
Johannes Berg5e760232011-11-04 11:18:17 +010014527{
Zhao, Gangf26cbf42014-04-21 12:53:03 +080014528 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg5e760232011-11-04 11:18:17 +010014529 struct sk_buff *msg;
14530 void *hdr;
Ben Greear37c73b52012-10-26 14:49:25 -070014531 struct cfg80211_beacon_registration *reg;
Johannes Berg5e760232011-11-04 11:18:17 +010014532
Beni Lev4ee3e062012-08-27 12:49:39 +030014533 trace_cfg80211_report_obss_beacon(wiphy, frame, len, freq, sig_dbm);
14534
Ben Greear37c73b52012-10-26 14:49:25 -070014535 spin_lock_bh(&rdev->beacon_registrations_lock);
14536 list_for_each_entry(reg, &rdev->beacon_registrations, list) {
14537 msg = nlmsg_new(len + 100, GFP_ATOMIC);
14538 if (!msg) {
14539 spin_unlock_bh(&rdev->beacon_registrations_lock);
14540 return;
14541 }
Johannes Berg5e760232011-11-04 11:18:17 +010014542
Ben Greear37c73b52012-10-26 14:49:25 -070014543 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME);
14544 if (!hdr)
14545 goto nla_put_failure;
Johannes Berg5e760232011-11-04 11:18:17 +010014546
Ben Greear37c73b52012-10-26 14:49:25 -070014547 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
14548 (freq &&
14549 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq)) ||
14550 (sig_dbm &&
14551 nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) ||
14552 nla_put(msg, NL80211_ATTR_FRAME, len, frame))
14553 goto nla_put_failure;
14554
14555 genlmsg_end(msg, hdr);
14556
14557 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, reg->nlportid);
Johannes Berg5e760232011-11-04 11:18:17 +010014558 }
Ben Greear37c73b52012-10-26 14:49:25 -070014559 spin_unlock_bh(&rdev->beacon_registrations_lock);
Johannes Berg5e760232011-11-04 11:18:17 +010014560 return;
14561
14562 nla_put_failure:
Ben Greear37c73b52012-10-26 14:49:25 -070014563 spin_unlock_bh(&rdev->beacon_registrations_lock);
14564 if (hdr)
14565 genlmsg_cancel(msg, hdr);
Johannes Berg5e760232011-11-04 11:18:17 +010014566 nlmsg_free(msg);
14567}
14568EXPORT_SYMBOL(cfg80211_report_obss_beacon);
14569
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010014570#ifdef CONFIG_PM
Luciano Coelho8cd4d452014-09-17 11:55:28 +030014571static int cfg80211_net_detect_results(struct sk_buff *msg,
14572 struct cfg80211_wowlan_wakeup *wakeup)
14573{
14574 struct cfg80211_wowlan_nd_info *nd = wakeup->net_detect;
14575 struct nlattr *nl_results, *nl_match, *nl_freqs;
14576 int i, j;
14577
14578 nl_results = nla_nest_start(
14579 msg, NL80211_WOWLAN_TRIG_NET_DETECT_RESULTS);
14580 if (!nl_results)
14581 return -EMSGSIZE;
14582
14583 for (i = 0; i < nd->n_matches; i++) {
14584 struct cfg80211_wowlan_nd_match *match = nd->matches[i];
14585
14586 nl_match = nla_nest_start(msg, i);
14587 if (!nl_match)
14588 break;
14589
14590 /* The SSID attribute is optional in nl80211, but for
14591 * simplicity reasons it's always present in the
14592 * cfg80211 structure. If a driver can't pass the
14593 * SSID, that needs to be changed. A zero length SSID
14594 * is still a valid SSID (wildcard), so it cannot be
14595 * used for this purpose.
14596 */
14597 if (nla_put(msg, NL80211_ATTR_SSID, match->ssid.ssid_len,
14598 match->ssid.ssid)) {
14599 nla_nest_cancel(msg, nl_match);
14600 goto out;
14601 }
14602
14603 if (match->n_channels) {
14604 nl_freqs = nla_nest_start(
14605 msg, NL80211_ATTR_SCAN_FREQUENCIES);
14606 if (!nl_freqs) {
14607 nla_nest_cancel(msg, nl_match);
14608 goto out;
14609 }
14610
14611 for (j = 0; j < match->n_channels; j++) {
Samuel Tan5528fae82015-02-09 21:29:15 +020014612 if (nla_put_u32(msg, j, match->channels[j])) {
Luciano Coelho8cd4d452014-09-17 11:55:28 +030014613 nla_nest_cancel(msg, nl_freqs);
14614 nla_nest_cancel(msg, nl_match);
14615 goto out;
14616 }
14617 }
14618
14619 nla_nest_end(msg, nl_freqs);
14620 }
14621
14622 nla_nest_end(msg, nl_match);
14623 }
14624
14625out:
14626 nla_nest_end(msg, nl_results);
14627 return 0;
14628}
14629
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010014630void cfg80211_report_wowlan_wakeup(struct wireless_dev *wdev,
14631 struct cfg80211_wowlan_wakeup *wakeup,
14632 gfp_t gfp)
14633{
Zhao, Gangf26cbf42014-04-21 12:53:03 +080014634 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010014635 struct sk_buff *msg;
14636 void *hdr;
Johannes Berg9c90a9f2013-06-04 12:46:03 +020014637 int size = 200;
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010014638
14639 trace_cfg80211_report_wowlan_wakeup(wdev->wiphy, wdev, wakeup);
14640
14641 if (wakeup)
14642 size += wakeup->packet_present_len;
14643
14644 msg = nlmsg_new(size, gfp);
14645 if (!msg)
14646 return;
14647
14648 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_WOWLAN);
14649 if (!hdr)
14650 goto free_msg;
14651
14652 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020014653 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
14654 NL80211_ATTR_PAD))
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010014655 goto free_msg;
14656
14657 if (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
14658 wdev->netdev->ifindex))
14659 goto free_msg;
14660
14661 if (wakeup) {
14662 struct nlattr *reasons;
14663
14664 reasons = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS);
Johannes Berg7fa322c2013-10-25 11:16:58 +020014665 if (!reasons)
14666 goto free_msg;
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010014667
14668 if (wakeup->disconnect &&
14669 nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT))
14670 goto free_msg;
14671 if (wakeup->magic_pkt &&
14672 nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT))
14673 goto free_msg;
14674 if (wakeup->gtk_rekey_failure &&
14675 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE))
14676 goto free_msg;
14677 if (wakeup->eap_identity_req &&
14678 nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST))
14679 goto free_msg;
14680 if (wakeup->four_way_handshake &&
14681 nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE))
14682 goto free_msg;
14683 if (wakeup->rfkill_release &&
14684 nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE))
14685 goto free_msg;
14686
14687 if (wakeup->pattern_idx >= 0 &&
14688 nla_put_u32(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN,
14689 wakeup->pattern_idx))
14690 goto free_msg;
14691
Johannes Bergae917c92013-10-25 11:05:22 +020014692 if (wakeup->tcp_match &&
14693 nla_put_flag(msg, NL80211_WOWLAN_TRIG_WAKEUP_TCP_MATCH))
14694 goto free_msg;
Johannes Berg2a0e0472013-01-23 22:57:40 +010014695
Johannes Bergae917c92013-10-25 11:05:22 +020014696 if (wakeup->tcp_connlost &&
14697 nla_put_flag(msg, NL80211_WOWLAN_TRIG_WAKEUP_TCP_CONNLOST))
14698 goto free_msg;
Johannes Berg2a0e0472013-01-23 22:57:40 +010014699
Johannes Bergae917c92013-10-25 11:05:22 +020014700 if (wakeup->tcp_nomoretokens &&
14701 nla_put_flag(msg,
14702 NL80211_WOWLAN_TRIG_WAKEUP_TCP_NOMORETOKENS))
14703 goto free_msg;
Johannes Berg2a0e0472013-01-23 22:57:40 +010014704
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010014705 if (wakeup->packet) {
14706 u32 pkt_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211;
14707 u32 len_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211_LEN;
14708
14709 if (!wakeup->packet_80211) {
14710 pkt_attr =
14711 NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023;
14712 len_attr =
14713 NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023_LEN;
14714 }
14715
14716 if (wakeup->packet_len &&
14717 nla_put_u32(msg, len_attr, wakeup->packet_len))
14718 goto free_msg;
14719
14720 if (nla_put(msg, pkt_attr, wakeup->packet_present_len,
14721 wakeup->packet))
14722 goto free_msg;
14723 }
14724
Luciano Coelho8cd4d452014-09-17 11:55:28 +030014725 if (wakeup->net_detect &&
14726 cfg80211_net_detect_results(msg, wakeup))
14727 goto free_msg;
14728
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010014729 nla_nest_end(msg, reasons);
14730 }
14731
Johannes Berg9c90a9f2013-06-04 12:46:03 +020014732 genlmsg_end(msg, hdr);
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010014733
Johannes Berg68eb5502013-11-19 15:19:38 +010014734 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010014735 NL80211_MCGRP_MLME, gfp);
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010014736 return;
14737
14738 free_msg:
14739 nlmsg_free(msg);
14740}
14741EXPORT_SYMBOL(cfg80211_report_wowlan_wakeup);
14742#endif
14743
Jouni Malinen3475b092012-11-16 22:49:57 +020014744void cfg80211_tdls_oper_request(struct net_device *dev, const u8 *peer,
14745 enum nl80211_tdls_operation oper,
14746 u16 reason_code, gfp_t gfp)
14747{
14748 struct wireless_dev *wdev = dev->ieee80211_ptr;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080014749 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Jouni Malinen3475b092012-11-16 22:49:57 +020014750 struct sk_buff *msg;
14751 void *hdr;
Jouni Malinen3475b092012-11-16 22:49:57 +020014752
14753 trace_cfg80211_tdls_oper_request(wdev->wiphy, dev, peer, oper,
14754 reason_code);
14755
14756 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
14757 if (!msg)
14758 return;
14759
14760 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_TDLS_OPER);
14761 if (!hdr) {
14762 nlmsg_free(msg);
14763 return;
14764 }
14765
14766 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
14767 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
14768 nla_put_u8(msg, NL80211_ATTR_TDLS_OPERATION, oper) ||
14769 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer) ||
14770 (reason_code > 0 &&
14771 nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason_code)))
14772 goto nla_put_failure;
14773
Johannes Berg9c90a9f2013-06-04 12:46:03 +020014774 genlmsg_end(msg, hdr);
Jouni Malinen3475b092012-11-16 22:49:57 +020014775
Johannes Berg68eb5502013-11-19 15:19:38 +010014776 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010014777 NL80211_MCGRP_MLME, gfp);
Jouni Malinen3475b092012-11-16 22:49:57 +020014778 return;
14779
14780 nla_put_failure:
14781 genlmsg_cancel(msg, hdr);
14782 nlmsg_free(msg);
14783}
14784EXPORT_SYMBOL(cfg80211_tdls_oper_request);
14785
Jouni Malinen026331c2010-02-15 12:53:10 +020014786static int nl80211_netlink_notify(struct notifier_block * nb,
14787 unsigned long state,
14788 void *_notify)
14789{
14790 struct netlink_notify *notify = _notify;
14791 struct cfg80211_registered_device *rdev;
14792 struct wireless_dev *wdev;
Ben Greear37c73b52012-10-26 14:49:25 -070014793 struct cfg80211_beacon_registration *reg, *tmp;
Jouni Malinen026331c2010-02-15 12:53:10 +020014794
Dmitry Ivanov8f815cd2016-04-06 17:23:18 +030014795 if (state != NETLINK_URELEASE || notify->protocol != NETLINK_GENERIC)
Jouni Malinen026331c2010-02-15 12:53:10 +020014796 return NOTIFY_DONE;
14797
14798 rcu_read_lock();
14799
Johannes Berg5e760232011-11-04 11:18:17 +010014800 list_for_each_entry_rcu(rdev, &cfg80211_rdev_list, list) {
Johannes Berg78f22b62014-03-24 17:57:27 +010014801 bool schedule_destroy_work = false;
Jukka Rissanen93a1e862014-12-15 13:25:39 +020014802 struct cfg80211_sched_scan_request *sched_scan_req =
14803 rcu_dereference(rdev->sched_scan_req);
14804
14805 if (sched_scan_req && notify->portid &&
Johannes Berg753aacf2017-01-05 10:57:14 +010014806 sched_scan_req->owner_nlportid == notify->portid) {
14807 sched_scan_req->owner_nlportid = 0;
14808
14809 if (rdev->ops->sched_scan_stop &&
14810 rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN)
14811 schedule_work(&rdev->sched_scan_stop_wk);
14812 }
Johannes Berg78f22b62014-03-24 17:57:27 +010014813
Johannes Berg53873f12016-05-03 16:52:04 +030014814 list_for_each_entry_rcu(wdev, &rdev->wiphy.wdev_list, list) {
Eric W. Biederman15e47302012-09-07 20:12:54 +000014815 cfg80211_mlme_unregister_socket(wdev, notify->portid);
Ben Greear37c73b52012-10-26 14:49:25 -070014816
Johannes Berg78f22b62014-03-24 17:57:27 +010014817 if (wdev->owner_nlportid == notify->portid)
14818 schedule_destroy_work = true;
Andrzej Zaborowskibd2522b2017-01-06 16:33:43 -050014819 else if (wdev->conn_owner_nlportid == notify->portid)
14820 schedule_work(&wdev->disconnect_wk);
Johannes Berg78f22b62014-03-24 17:57:27 +010014821 }
14822
Ben Greear37c73b52012-10-26 14:49:25 -070014823 spin_lock_bh(&rdev->beacon_registrations_lock);
14824 list_for_each_entry_safe(reg, tmp, &rdev->beacon_registrations,
14825 list) {
14826 if (reg->nlportid == notify->portid) {
14827 list_del(&reg->list);
14828 kfree(reg);
14829 break;
14830 }
14831 }
14832 spin_unlock_bh(&rdev->beacon_registrations_lock);
Johannes Berg78f22b62014-03-24 17:57:27 +010014833
14834 if (schedule_destroy_work) {
14835 struct cfg80211_iface_destroy *destroy;
14836
14837 destroy = kzalloc(sizeof(*destroy), GFP_ATOMIC);
14838 if (destroy) {
14839 destroy->nlportid = notify->portid;
14840 spin_lock(&rdev->destroy_list_lock);
14841 list_add(&destroy->list, &rdev->destroy_list);
14842 spin_unlock(&rdev->destroy_list_lock);
14843 schedule_work(&rdev->destroy_work);
14844 }
14845 }
Johannes Berg5e760232011-11-04 11:18:17 +010014846 }
Jouni Malinen026331c2010-02-15 12:53:10 +020014847
14848 rcu_read_unlock();
14849
Ilan peer05050752015-03-04 00:32:06 -050014850 /*
14851 * It is possible that the user space process that is controlling the
14852 * indoor setting disappeared, so notify the regulatory core.
14853 */
14854 regulatory_netlink_notify(notify->portid);
Zhao, Gang6784c7d2014-04-21 12:53:04 +080014855 return NOTIFY_OK;
Jouni Malinen026331c2010-02-15 12:53:10 +020014856}
14857
14858static struct notifier_block nl80211_netlink_notifier = {
14859 .notifier_call = nl80211_netlink_notify,
14860};
14861
Jouni Malinen355199e2013-02-27 17:14:27 +020014862void cfg80211_ft_event(struct net_device *netdev,
14863 struct cfg80211_ft_event_params *ft_event)
14864{
14865 struct wiphy *wiphy = netdev->ieee80211_ptr->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080014866 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Jouni Malinen355199e2013-02-27 17:14:27 +020014867 struct sk_buff *msg;
14868 void *hdr;
Jouni Malinen355199e2013-02-27 17:14:27 +020014869
14870 trace_cfg80211_ft_event(wiphy, netdev, ft_event);
14871
14872 if (!ft_event->target_ap)
14873 return;
14874
Johannes Berg4ef8c1c2017-01-09 11:10:42 +010014875 msg = nlmsg_new(100 + ft_event->ric_ies_len, GFP_KERNEL);
Jouni Malinen355199e2013-02-27 17:14:27 +020014876 if (!msg)
14877 return;
14878
14879 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FT_EVENT);
Johannes Bergae917c92013-10-25 11:05:22 +020014880 if (!hdr)
14881 goto out;
Jouni Malinen355199e2013-02-27 17:14:27 +020014882
Johannes Bergae917c92013-10-25 11:05:22 +020014883 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
14884 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
14885 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, ft_event->target_ap))
14886 goto out;
14887
14888 if (ft_event->ies &&
14889 nla_put(msg, NL80211_ATTR_IE, ft_event->ies_len, ft_event->ies))
14890 goto out;
14891 if (ft_event->ric_ies &&
14892 nla_put(msg, NL80211_ATTR_IE_RIC, ft_event->ric_ies_len,
14893 ft_event->ric_ies))
14894 goto out;
Jouni Malinen355199e2013-02-27 17:14:27 +020014895
Johannes Berg9c90a9f2013-06-04 12:46:03 +020014896 genlmsg_end(msg, hdr);
Jouni Malinen355199e2013-02-27 17:14:27 +020014897
Johannes Berg68eb5502013-11-19 15:19:38 +010014898 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010014899 NL80211_MCGRP_MLME, GFP_KERNEL);
Johannes Bergae917c92013-10-25 11:05:22 +020014900 return;
14901 out:
14902 nlmsg_free(msg);
Jouni Malinen355199e2013-02-27 17:14:27 +020014903}
14904EXPORT_SYMBOL(cfg80211_ft_event);
14905
Arend van Spriel5de17982013-04-18 15:49:00 +020014906void cfg80211_crit_proto_stopped(struct wireless_dev *wdev, gfp_t gfp)
14907{
14908 struct cfg80211_registered_device *rdev;
14909 struct sk_buff *msg;
14910 void *hdr;
14911 u32 nlportid;
14912
Zhao, Gangf26cbf42014-04-21 12:53:03 +080014913 rdev = wiphy_to_rdev(wdev->wiphy);
Arend van Spriel5de17982013-04-18 15:49:00 +020014914 if (!rdev->crit_proto_nlportid)
14915 return;
14916
14917 nlportid = rdev->crit_proto_nlportid;
14918 rdev->crit_proto_nlportid = 0;
14919
14920 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
14921 if (!msg)
14922 return;
14923
14924 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CRIT_PROTOCOL_STOP);
14925 if (!hdr)
14926 goto nla_put_failure;
14927
14928 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020014929 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
14930 NL80211_ATTR_PAD))
Arend van Spriel5de17982013-04-18 15:49:00 +020014931 goto nla_put_failure;
14932
14933 genlmsg_end(msg, hdr);
14934
14935 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid);
14936 return;
14937
14938 nla_put_failure:
14939 if (hdr)
14940 genlmsg_cancel(msg, hdr);
14941 nlmsg_free(msg);
Arend van Spriel5de17982013-04-18 15:49:00 +020014942}
14943EXPORT_SYMBOL(cfg80211_crit_proto_stopped);
14944
Johannes Berg348baf02014-01-24 14:06:29 +010014945void nl80211_send_ap_stopped(struct wireless_dev *wdev)
14946{
14947 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080014948 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg348baf02014-01-24 14:06:29 +010014949 struct sk_buff *msg;
14950 void *hdr;
14951
14952 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
14953 if (!msg)
14954 return;
14955
14956 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_STOP_AP);
14957 if (!hdr)
14958 goto out;
14959
14960 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
14961 nla_put_u32(msg, NL80211_ATTR_IFINDEX, wdev->netdev->ifindex) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020014962 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
14963 NL80211_ATTR_PAD))
Johannes Berg348baf02014-01-24 14:06:29 +010014964 goto out;
14965
14966 genlmsg_end(msg, hdr);
14967
14968 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(wiphy), msg, 0,
14969 NL80211_MCGRP_MLME, GFP_KERNEL);
14970 return;
14971 out:
14972 nlmsg_free(msg);
14973}
14974
Johannes Berg55682962007-09-20 13:09:35 -040014975/* initialisation/exit functions */
14976
Johannes Berg56989f62016-10-24 14:40:05 +020014977int __init nl80211_init(void)
Johannes Berg55682962007-09-20 13:09:35 -040014978{
Michał Mirosław0d63cbb2009-05-21 10:34:06 +000014979 int err;
Johannes Berg55682962007-09-20 13:09:35 -040014980
Johannes Berg489111e2016-10-24 14:40:03 +020014981 err = genl_register_family(&nl80211_fam);
Johannes Berg55682962007-09-20 13:09:35 -040014982 if (err)
14983 return err;
14984
Jouni Malinen026331c2010-02-15 12:53:10 +020014985 err = netlink_register_notifier(&nl80211_netlink_notifier);
14986 if (err)
14987 goto err_out;
14988
Johannes Berg55682962007-09-20 13:09:35 -040014989 return 0;
14990 err_out:
14991 genl_unregister_family(&nl80211_fam);
14992 return err;
14993}
14994
14995void nl80211_exit(void)
14996{
Jouni Malinen026331c2010-02-15 12:53:10 +020014997 netlink_unregister_notifier(&nl80211_netlink_notifier);
Johannes Berg55682962007-09-20 13:09:35 -040014998 genl_unregister_family(&nl80211_fam);
14999}