blob: 2312dc2ffdb98b37b2909274c57eed68935267d7 [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 Karwarbe29b992013-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 Berg97990a02013-04-19 01:02:55 +0200548 if (!cb->args[0]) {
549 err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize,
Johannes Bergc90c39d2016-10-24 14:40:01 +0200550 genl_family_attrbuf(&nl80211_fam),
551 nl80211_fam.maxattr, nl80211_policy);
Johannes Berg97990a02013-04-19 01:02:55 +0200552 if (err)
Johannes Bergea90e0d2017-03-15 14:26:04 +0100553 return err;
Johannes Berg97990a02013-04-19 01:02:55 +0200554
Johannes Bergc90c39d2016-10-24 14:40:01 +0200555 *wdev = __cfg80211_wdev_from_attrs(
556 sock_net(skb->sk),
557 genl_family_attrbuf(&nl80211_fam));
Johannes Bergea90e0d2017-03-15 14:26:04 +0100558 if (IS_ERR(*wdev))
559 return PTR_ERR(*wdev);
Zhao, Gangf26cbf42014-04-21 12:53:03 +0800560 *rdev = wiphy_to_rdev((*wdev)->wiphy);
Johannes Bergc319d502013-07-30 22:34:28 +0200561 /* 0 is the first index - add 1 to parse only once */
562 cb->args[0] = (*rdev)->wiphy_idx + 1;
Johannes Berg97990a02013-04-19 01:02:55 +0200563 cb->args[1] = (*wdev)->identifier;
564 } else {
Johannes Bergc319d502013-07-30 22:34:28 +0200565 /* subtract the 1 again here */
566 struct wiphy *wiphy = wiphy_idx_to_wiphy(cb->args[0] - 1);
Johannes Berg97990a02013-04-19 01:02:55 +0200567 struct wireless_dev *tmp;
568
Johannes Bergea90e0d2017-03-15 14:26:04 +0100569 if (!wiphy)
570 return -ENODEV;
Zhao, Gangf26cbf42014-04-21 12:53:03 +0800571 *rdev = wiphy_to_rdev(wiphy);
Johannes Berg97990a02013-04-19 01:02:55 +0200572 *wdev = NULL;
573
Johannes Berg53873f12016-05-03 16:52:04 +0300574 list_for_each_entry(tmp, &(*rdev)->wiphy.wdev_list, list) {
Johannes Berg97990a02013-04-19 01:02:55 +0200575 if (tmp->identifier == cb->args[1]) {
576 *wdev = tmp;
577 break;
578 }
579 }
Johannes Berg97990a02013-04-19 01:02:55 +0200580
Johannes Bergea90e0d2017-03-15 14:26:04 +0100581 if (!*wdev)
582 return -ENODEV;
Johannes Berg67748892010-10-04 21:14:06 +0200583 }
584
Johannes Berg67748892010-10-04 21:14:06 +0200585 return 0;
Johannes Berg67748892010-10-04 21:14:06 +0200586}
587
Johannes Bergf4a11bb2009-03-27 12:40:28 +0100588/* IE validation */
589static bool is_valid_ie_attr(const struct nlattr *attr)
590{
591 const u8 *pos;
592 int len;
593
594 if (!attr)
595 return true;
596
597 pos = nla_data(attr);
598 len = nla_len(attr);
599
600 while (len) {
601 u8 elemlen;
602
603 if (len < 2)
604 return false;
605 len -= 2;
606
607 elemlen = pos[1];
608 if (elemlen > len)
609 return false;
610
611 len -= elemlen;
612 pos += 2 + elemlen;
613 }
614
615 return true;
616}
617
Johannes Berg55682962007-09-20 13:09:35 -0400618/* message building helper */
Eric W. Biederman15e47302012-09-07 20:12:54 +0000619static inline void *nl80211hdr_put(struct sk_buff *skb, u32 portid, u32 seq,
Johannes Berg55682962007-09-20 13:09:35 -0400620 int flags, u8 cmd)
621{
622 /* since there is no private header just add the generic one */
Eric W. Biederman15e47302012-09-07 20:12:54 +0000623 return genlmsg_put(skb, portid, seq, &nl80211_fam, flags, cmd);
Johannes Berg55682962007-09-20 13:09:35 -0400624}
625
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400626static int nl80211_msg_put_channel(struct sk_buff *msg,
Johannes Bergcdc89b92013-02-18 23:54:36 +0100627 struct ieee80211_channel *chan,
628 bool large)
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400629{
Rostislav Lisovyea077c12014-04-15 14:37:55 +0200630 /* Some channels must be completely excluded from the
631 * list to protect old user-space tools from breaking
632 */
633 if (!large && chan->flags &
634 (IEEE80211_CHAN_NO_10MHZ | IEEE80211_CHAN_NO_20MHZ))
635 return 0;
636
David S. Miller9360ffd2012-03-29 04:41:26 -0400637 if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_FREQ,
638 chan->center_freq))
639 goto nla_put_failure;
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400640
David S. Miller9360ffd2012-03-29 04:41:26 -0400641 if ((chan->flags & IEEE80211_CHAN_DISABLED) &&
642 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_DISABLED))
643 goto nla_put_failure;
Luis R. Rodriguez8fe02e12013-10-21 19:22:25 +0200644 if (chan->flags & IEEE80211_CHAN_NO_IR) {
645 if (nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_IR))
646 goto nla_put_failure;
647 if (nla_put_flag(msg, __NL80211_FREQUENCY_ATTR_NO_IBSS))
648 goto nla_put_failure;
649 }
Johannes Bergcdc89b92013-02-18 23:54:36 +0100650 if (chan->flags & IEEE80211_CHAN_RADAR) {
651 if (nla_put_flag(msg, NL80211_FREQUENCY_ATTR_RADAR))
652 goto nla_put_failure;
653 if (large) {
654 u32 time;
655
656 time = elapsed_jiffies_msecs(chan->dfs_state_entered);
657
658 if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_DFS_STATE,
659 chan->dfs_state))
660 goto nla_put_failure;
661 if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_DFS_TIME,
662 time))
663 goto nla_put_failure;
Janusz Dziedzic089027e2014-02-21 19:46:12 +0100664 if (nla_put_u32(msg,
665 NL80211_FREQUENCY_ATTR_DFS_CAC_TIME,
666 chan->dfs_cac_ms))
667 goto nla_put_failure;
Johannes Bergcdc89b92013-02-18 23:54:36 +0100668 }
669 }
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400670
Johannes Bergfe1abaf2013-02-27 15:39:45 +0100671 if (large) {
672 if ((chan->flags & IEEE80211_CHAN_NO_HT40MINUS) &&
673 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_HT40_MINUS))
674 goto nla_put_failure;
675 if ((chan->flags & IEEE80211_CHAN_NO_HT40PLUS) &&
676 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_HT40_PLUS))
677 goto nla_put_failure;
678 if ((chan->flags & IEEE80211_CHAN_NO_80MHZ) &&
679 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_80MHZ))
680 goto nla_put_failure;
681 if ((chan->flags & IEEE80211_CHAN_NO_160MHZ) &&
682 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_160MHZ))
683 goto nla_put_failure;
David Spinadel570dbde2014-02-23 09:12:59 +0200684 if ((chan->flags & IEEE80211_CHAN_INDOOR_ONLY) &&
685 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_INDOOR_ONLY))
686 goto nla_put_failure;
Arik Nemtsov06f207f2015-05-06 16:28:31 +0300687 if ((chan->flags & IEEE80211_CHAN_IR_CONCURRENT) &&
688 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_IR_CONCURRENT))
David Spinadel570dbde2014-02-23 09:12:59 +0200689 goto nla_put_failure;
Rostislav Lisovyea077c12014-04-15 14:37:55 +0200690 if ((chan->flags & IEEE80211_CHAN_NO_20MHZ) &&
691 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_20MHZ))
692 goto nla_put_failure;
693 if ((chan->flags & IEEE80211_CHAN_NO_10MHZ) &&
694 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_10MHZ))
695 goto nla_put_failure;
Johannes Bergfe1abaf2013-02-27 15:39:45 +0100696 }
697
David S. Miller9360ffd2012-03-29 04:41:26 -0400698 if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_MAX_TX_POWER,
699 DBM_TO_MBM(chan->max_power)))
700 goto nla_put_failure;
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400701
702 return 0;
703
704 nla_put_failure:
705 return -ENOBUFS;
706}
707
Johannes Berg55682962007-09-20 13:09:35 -0400708/* netlink command implementations */
709
Johannes Bergb9454e82009-07-08 13:29:08 +0200710struct key_parse {
711 struct key_params p;
712 int idx;
Johannes Berge31b8212010-10-05 19:39:30 +0200713 int type;
Johannes Bergb9454e82009-07-08 13:29:08 +0200714 bool def, defmgmt;
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100715 bool def_uni, def_multi;
Johannes Bergb9454e82009-07-08 13:29:08 +0200716};
717
718static int nl80211_parse_key_new(struct nlattr *key, struct key_parse *k)
719{
720 struct nlattr *tb[NL80211_KEY_MAX + 1];
721 int err = nla_parse_nested(tb, NL80211_KEY_MAX, key,
722 nl80211_key_policy);
723 if (err)
724 return err;
725
726 k->def = !!tb[NL80211_KEY_DEFAULT];
727 k->defmgmt = !!tb[NL80211_KEY_DEFAULT_MGMT];
728
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100729 if (k->def) {
730 k->def_uni = true;
731 k->def_multi = true;
732 }
733 if (k->defmgmt)
734 k->def_multi = true;
735
Johannes Bergb9454e82009-07-08 13:29:08 +0200736 if (tb[NL80211_KEY_IDX])
737 k->idx = nla_get_u8(tb[NL80211_KEY_IDX]);
738
739 if (tb[NL80211_KEY_DATA]) {
740 k->p.key = nla_data(tb[NL80211_KEY_DATA]);
741 k->p.key_len = nla_len(tb[NL80211_KEY_DATA]);
742 }
743
744 if (tb[NL80211_KEY_SEQ]) {
745 k->p.seq = nla_data(tb[NL80211_KEY_SEQ]);
746 k->p.seq_len = nla_len(tb[NL80211_KEY_SEQ]);
747 }
748
749 if (tb[NL80211_KEY_CIPHER])
750 k->p.cipher = nla_get_u32(tb[NL80211_KEY_CIPHER]);
751
Johannes Berge31b8212010-10-05 19:39:30 +0200752 if (tb[NL80211_KEY_TYPE]) {
753 k->type = nla_get_u32(tb[NL80211_KEY_TYPE]);
754 if (k->type < 0 || k->type >= NUM_NL80211_KEYTYPES)
755 return -EINVAL;
756 }
757
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100758 if (tb[NL80211_KEY_DEFAULT_TYPES]) {
759 struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES];
Kirtika Ruchandani7a087e72016-05-29 19:51:23 -0700760
Johannes Berg2da8f412012-01-20 13:52:37 +0100761 err = nla_parse_nested(kdt, NUM_NL80211_KEY_DEFAULT_TYPES - 1,
762 tb[NL80211_KEY_DEFAULT_TYPES],
763 nl80211_key_default_policy);
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100764 if (err)
765 return err;
766
767 k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST];
768 k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST];
769 }
770
Johannes Bergb9454e82009-07-08 13:29:08 +0200771 return 0;
772}
773
774static int nl80211_parse_key_old(struct genl_info *info, struct key_parse *k)
775{
776 if (info->attrs[NL80211_ATTR_KEY_DATA]) {
777 k->p.key = nla_data(info->attrs[NL80211_ATTR_KEY_DATA]);
778 k->p.key_len = nla_len(info->attrs[NL80211_ATTR_KEY_DATA]);
779 }
780
781 if (info->attrs[NL80211_ATTR_KEY_SEQ]) {
782 k->p.seq = nla_data(info->attrs[NL80211_ATTR_KEY_SEQ]);
783 k->p.seq_len = nla_len(info->attrs[NL80211_ATTR_KEY_SEQ]);
784 }
785
786 if (info->attrs[NL80211_ATTR_KEY_IDX])
787 k->idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]);
788
789 if (info->attrs[NL80211_ATTR_KEY_CIPHER])
790 k->p.cipher = nla_get_u32(info->attrs[NL80211_ATTR_KEY_CIPHER]);
791
792 k->def = !!info->attrs[NL80211_ATTR_KEY_DEFAULT];
793 k->defmgmt = !!info->attrs[NL80211_ATTR_KEY_DEFAULT_MGMT];
794
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100795 if (k->def) {
796 k->def_uni = true;
797 k->def_multi = true;
798 }
799 if (k->defmgmt)
800 k->def_multi = true;
801
Johannes Berge31b8212010-10-05 19:39:30 +0200802 if (info->attrs[NL80211_ATTR_KEY_TYPE]) {
803 k->type = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]);
804 if (k->type < 0 || k->type >= NUM_NL80211_KEYTYPES)
805 return -EINVAL;
806 }
807
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100808 if (info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES]) {
809 struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES];
810 int err = nla_parse_nested(
811 kdt, NUM_NL80211_KEY_DEFAULT_TYPES - 1,
812 info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES],
813 nl80211_key_default_policy);
814 if (err)
815 return err;
816
817 k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST];
818 k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST];
819 }
820
Johannes Bergb9454e82009-07-08 13:29:08 +0200821 return 0;
822}
823
824static int nl80211_parse_key(struct genl_info *info, struct key_parse *k)
825{
826 int err;
827
828 memset(k, 0, sizeof(*k));
829 k->idx = -1;
Johannes Berge31b8212010-10-05 19:39:30 +0200830 k->type = -1;
Johannes Bergb9454e82009-07-08 13:29:08 +0200831
832 if (info->attrs[NL80211_ATTR_KEY])
833 err = nl80211_parse_key_new(info->attrs[NL80211_ATTR_KEY], k);
834 else
835 err = nl80211_parse_key_old(info, k);
836
837 if (err)
838 return err;
839
840 if (k->def && k->defmgmt)
841 return -EINVAL;
842
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100843 if (k->defmgmt) {
844 if (k->def_uni || !k->def_multi)
845 return -EINVAL;
846 }
847
Johannes Bergb9454e82009-07-08 13:29:08 +0200848 if (k->idx != -1) {
849 if (k->defmgmt) {
850 if (k->idx < 4 || k->idx > 5)
851 return -EINVAL;
852 } else if (k->def) {
853 if (k->idx < 0 || k->idx > 3)
854 return -EINVAL;
855 } else {
856 if (k->idx < 0 || k->idx > 5)
857 return -EINVAL;
858 }
859 }
860
861 return 0;
862}
863
Johannes Bergfffd0932009-07-08 14:22:54 +0200864static struct cfg80211_cached_keys *
865nl80211_parse_connkeys(struct cfg80211_registered_device *rdev,
Sujith Manoharande7044e2012-10-18 10:19:28 +0530866 struct nlattr *keys, bool *no_ht)
Johannes Bergfffd0932009-07-08 14:22:54 +0200867{
868 struct key_parse parse;
869 struct nlattr *key;
870 struct cfg80211_cached_keys *result;
871 int rem, err, def = 0;
Johannes Bergf1c1f172016-09-13 17:08:23 +0200872 bool have_key = false;
873
874 nla_for_each_nested(key, keys, rem) {
875 have_key = true;
876 break;
877 }
878
879 if (!have_key)
880 return NULL;
Johannes Bergfffd0932009-07-08 14:22:54 +0200881
882 result = kzalloc(sizeof(*result), GFP_KERNEL);
883 if (!result)
884 return ERR_PTR(-ENOMEM);
885
886 result->def = -1;
Johannes Bergfffd0932009-07-08 14:22:54 +0200887
888 nla_for_each_nested(key, keys, rem) {
889 memset(&parse, 0, sizeof(parse));
890 parse.idx = -1;
891
892 err = nl80211_parse_key_new(key, &parse);
893 if (err)
894 goto error;
895 err = -EINVAL;
896 if (!parse.p.key)
897 goto error;
Johannes Berg42ee2312016-09-13 15:51:03 +0200898 if (parse.idx < 0 || parse.idx > 3)
Johannes Bergfffd0932009-07-08 14:22:54 +0200899 goto error;
900 if (parse.def) {
901 if (def)
902 goto error;
903 def = 1;
904 result->def = parse.idx;
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100905 if (!parse.def_uni || !parse.def_multi)
906 goto error;
Johannes Bergfffd0932009-07-08 14:22:54 +0200907 } else if (parse.defmgmt)
908 goto error;
909 err = cfg80211_validate_key_settings(rdev, &parse.p,
Johannes Berge31b8212010-10-05 19:39:30 +0200910 parse.idx, false, NULL);
Johannes Bergfffd0932009-07-08 14:22:54 +0200911 if (err)
912 goto error;
Johannes Berg386b1f22016-09-13 16:10:02 +0200913 if (parse.p.cipher != WLAN_CIPHER_SUITE_WEP40 &&
914 parse.p.cipher != WLAN_CIPHER_SUITE_WEP104) {
915 err = -EINVAL;
916 goto error;
917 }
Johannes Bergfffd0932009-07-08 14:22:54 +0200918 result->params[parse.idx].cipher = parse.p.cipher;
919 result->params[parse.idx].key_len = parse.p.key_len;
920 result->params[parse.idx].key = result->data[parse.idx];
921 memcpy(result->data[parse.idx], parse.p.key, parse.p.key_len);
Sujith Manoharande7044e2012-10-18 10:19:28 +0530922
Johannes Berg386b1f22016-09-13 16:10:02 +0200923 /* must be WEP key if we got here */
924 if (no_ht)
925 *no_ht = true;
Johannes Bergfffd0932009-07-08 14:22:54 +0200926 }
927
Johannes Bergf1c1f172016-09-13 17:08:23 +0200928 if (result->def < 0) {
929 err = -EINVAL;
930 goto error;
931 }
932
Johannes Bergfffd0932009-07-08 14:22:54 +0200933 return result;
934 error:
935 kfree(result);
936 return ERR_PTR(err);
937}
938
939static int nl80211_key_allowed(struct wireless_dev *wdev)
940{
941 ASSERT_WDEV_LOCK(wdev);
942
Johannes Bergfffd0932009-07-08 14:22:54 +0200943 switch (wdev->iftype) {
944 case NL80211_IFTYPE_AP:
945 case NL80211_IFTYPE_AP_VLAN:
Johannes Berg074ac8d2010-09-16 14:58:22 +0200946 case NL80211_IFTYPE_P2P_GO:
Thomas Pedersenff973af2011-05-03 16:57:12 -0700947 case NL80211_IFTYPE_MESH_POINT:
Johannes Bergfffd0932009-07-08 14:22:54 +0200948 break;
949 case NL80211_IFTYPE_ADHOC:
Johannes Bergfffd0932009-07-08 14:22:54 +0200950 case NL80211_IFTYPE_STATION:
Johannes Berg074ac8d2010-09-16 14:58:22 +0200951 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Bergceca7b72013-05-16 00:55:45 +0200952 if (!wdev->current_bss)
Johannes Bergfffd0932009-07-08 14:22:54 +0200953 return -ENOLINK;
954 break;
Johannes Bergde4fcba2014-10-31 14:16:12 +0100955 case NL80211_IFTYPE_UNSPECIFIED:
Rostislav Lisovy6e0bd6c2014-11-03 10:33:18 +0100956 case NL80211_IFTYPE_OCB:
Johannes Bergde4fcba2014-10-31 14:16:12 +0100957 case NL80211_IFTYPE_MONITOR:
Ayala Bekercb3b7d82016-09-20 17:31:13 +0300958 case NL80211_IFTYPE_NAN:
Johannes Bergde4fcba2014-10-31 14:16:12 +0100959 case NL80211_IFTYPE_P2P_DEVICE:
960 case NL80211_IFTYPE_WDS:
961 case NUM_NL80211_IFTYPES:
Johannes Bergfffd0932009-07-08 14:22:54 +0200962 return -EINVAL;
963 }
964
965 return 0;
966}
967
Jouni Malinen664834d2014-01-15 00:01:44 +0200968static struct ieee80211_channel *nl80211_get_valid_chan(struct wiphy *wiphy,
969 struct nlattr *tb)
970{
971 struct ieee80211_channel *chan;
972
973 if (tb == NULL)
974 return NULL;
975 chan = ieee80211_get_channel(wiphy, nla_get_u32(tb));
976 if (!chan || chan->flags & IEEE80211_CHAN_DISABLED)
977 return NULL;
978 return chan;
979}
980
Johannes Berg7527a782011-05-13 10:58:57 +0200981static int nl80211_put_iftypes(struct sk_buff *msg, u32 attr, u16 ifmodes)
982{
983 struct nlattr *nl_modes = nla_nest_start(msg, attr);
984 int i;
985
986 if (!nl_modes)
987 goto nla_put_failure;
988
989 i = 0;
990 while (ifmodes) {
David S. Miller9360ffd2012-03-29 04:41:26 -0400991 if ((ifmodes & 1) && nla_put_flag(msg, i))
992 goto nla_put_failure;
Johannes Berg7527a782011-05-13 10:58:57 +0200993 ifmodes >>= 1;
994 i++;
995 }
996
997 nla_nest_end(msg, nl_modes);
998 return 0;
999
1000nla_put_failure:
1001 return -ENOBUFS;
1002}
1003
1004static int nl80211_put_iface_combinations(struct wiphy *wiphy,
Johannes Bergcdc89b92013-02-18 23:54:36 +01001005 struct sk_buff *msg,
1006 bool large)
Johannes Berg7527a782011-05-13 10:58:57 +02001007{
1008 struct nlattr *nl_combis;
1009 int i, j;
1010
1011 nl_combis = nla_nest_start(msg,
1012 NL80211_ATTR_INTERFACE_COMBINATIONS);
1013 if (!nl_combis)
1014 goto nla_put_failure;
1015
1016 for (i = 0; i < wiphy->n_iface_combinations; i++) {
1017 const struct ieee80211_iface_combination *c;
1018 struct nlattr *nl_combi, *nl_limits;
1019
1020 c = &wiphy->iface_combinations[i];
1021
1022 nl_combi = nla_nest_start(msg, i + 1);
1023 if (!nl_combi)
1024 goto nla_put_failure;
1025
1026 nl_limits = nla_nest_start(msg, NL80211_IFACE_COMB_LIMITS);
1027 if (!nl_limits)
1028 goto nla_put_failure;
1029
1030 for (j = 0; j < c->n_limits; j++) {
1031 struct nlattr *nl_limit;
1032
1033 nl_limit = nla_nest_start(msg, j + 1);
1034 if (!nl_limit)
1035 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04001036 if (nla_put_u32(msg, NL80211_IFACE_LIMIT_MAX,
1037 c->limits[j].max))
1038 goto nla_put_failure;
Johannes Berg7527a782011-05-13 10:58:57 +02001039 if (nl80211_put_iftypes(msg, NL80211_IFACE_LIMIT_TYPES,
1040 c->limits[j].types))
1041 goto nla_put_failure;
1042 nla_nest_end(msg, nl_limit);
1043 }
1044
1045 nla_nest_end(msg, nl_limits);
1046
David S. Miller9360ffd2012-03-29 04:41:26 -04001047 if (c->beacon_int_infra_match &&
1048 nla_put_flag(msg, NL80211_IFACE_COMB_STA_AP_BI_MATCH))
1049 goto nla_put_failure;
1050 if (nla_put_u32(msg, NL80211_IFACE_COMB_NUM_CHANNELS,
1051 c->num_different_channels) ||
1052 nla_put_u32(msg, NL80211_IFACE_COMB_MAXNUM,
1053 c->max_interfaces))
1054 goto nla_put_failure;
Johannes Bergcdc89b92013-02-18 23:54:36 +01001055 if (large &&
Felix Fietkau8c48b502014-05-05 11:48:40 +02001056 (nla_put_u32(msg, NL80211_IFACE_COMB_RADAR_DETECT_WIDTHS,
1057 c->radar_detect_widths) ||
1058 nla_put_u32(msg, NL80211_IFACE_COMB_RADAR_DETECT_REGIONS,
1059 c->radar_detect_regions)))
Johannes Bergcdc89b92013-02-18 23:54:36 +01001060 goto nla_put_failure;
Purushottam Kushwaha0c317a02016-10-12 18:26:51 +05301061 if (c->beacon_int_min_gcd &&
1062 nla_put_u32(msg, NL80211_IFACE_COMB_BI_MIN_GCD,
1063 c->beacon_int_min_gcd))
1064 goto nla_put_failure;
Johannes Berg7527a782011-05-13 10:58:57 +02001065
1066 nla_nest_end(msg, nl_combi);
1067 }
1068
1069 nla_nest_end(msg, nl_combis);
1070
1071 return 0;
1072nla_put_failure:
1073 return -ENOBUFS;
1074}
1075
Johannes Berg3713b4e2013-02-14 16:19:38 +01001076#ifdef CONFIG_PM
Johannes Bergb56cf722013-02-20 01:02:38 +01001077static int nl80211_send_wowlan_tcp_caps(struct cfg80211_registered_device *rdev,
1078 struct sk_buff *msg)
1079{
Johannes Berg964dc9e2013-06-03 17:25:34 +02001080 const struct wiphy_wowlan_tcp_support *tcp = rdev->wiphy.wowlan->tcp;
Johannes Bergb56cf722013-02-20 01:02:38 +01001081 struct nlattr *nl_tcp;
1082
1083 if (!tcp)
1084 return 0;
1085
1086 nl_tcp = nla_nest_start(msg, NL80211_WOWLAN_TRIG_TCP_CONNECTION);
1087 if (!nl_tcp)
1088 return -ENOBUFS;
1089
1090 if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD,
1091 tcp->data_payload_max))
1092 return -ENOBUFS;
1093
1094 if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD,
1095 tcp->data_payload_max))
1096 return -ENOBUFS;
1097
1098 if (tcp->seq && nla_put_flag(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ))
1099 return -ENOBUFS;
1100
1101 if (tcp->tok && nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN,
1102 sizeof(*tcp->tok), tcp->tok))
1103 return -ENOBUFS;
1104
1105 if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_INTERVAL,
1106 tcp->data_interval_max))
1107 return -ENOBUFS;
1108
1109 if (nla_put_u32(msg, NL80211_WOWLAN_TCP_WAKE_PAYLOAD,
1110 tcp->wake_payload_max))
1111 return -ENOBUFS;
1112
1113 nla_nest_end(msg, nl_tcp);
1114 return 0;
1115}
1116
Johannes Berg3713b4e2013-02-14 16:19:38 +01001117static int nl80211_send_wowlan(struct sk_buff *msg,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001118 struct cfg80211_registered_device *rdev,
Johannes Bergb56cf722013-02-20 01:02:38 +01001119 bool large)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001120{
1121 struct nlattr *nl_wowlan;
1122
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001123 if (!rdev->wiphy.wowlan)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001124 return 0;
1125
1126 nl_wowlan = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS_SUPPORTED);
1127 if (!nl_wowlan)
1128 return -ENOBUFS;
1129
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001130 if (((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_ANY) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001131 nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) ||
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001132 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_DISCONNECT) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001133 nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) ||
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001134 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001135 nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) ||
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001136 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_SUPPORTS_GTK_REKEY) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001137 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED)) ||
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001138 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001139 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) ||
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001140 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001141 nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) ||
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001142 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001143 nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) ||
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001144 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001145 nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE)))
1146 return -ENOBUFS;
1147
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001148 if (rdev->wiphy.wowlan->n_patterns) {
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07001149 struct nl80211_pattern_support pat = {
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001150 .max_patterns = rdev->wiphy.wowlan->n_patterns,
1151 .min_pattern_len = rdev->wiphy.wowlan->pattern_min_len,
1152 .max_pattern_len = rdev->wiphy.wowlan->pattern_max_len,
1153 .max_pkt_offset = rdev->wiphy.wowlan->max_pkt_offset,
Johannes Berg3713b4e2013-02-14 16:19:38 +01001154 };
1155
1156 if (nla_put(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN,
1157 sizeof(pat), &pat))
1158 return -ENOBUFS;
1159 }
1160
Luciano Coelho75453cc2015-01-09 14:06:37 +02001161 if ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_NET_DETECT) &&
1162 nla_put_u32(msg, NL80211_WOWLAN_TRIG_NET_DETECT,
1163 rdev->wiphy.wowlan->max_nd_match_sets))
1164 return -ENOBUFS;
1165
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001166 if (large && nl80211_send_wowlan_tcp_caps(rdev, msg))
Johannes Bergb56cf722013-02-20 01:02:38 +01001167 return -ENOBUFS;
1168
Johannes Berg3713b4e2013-02-14 16:19:38 +01001169 nla_nest_end(msg, nl_wowlan);
1170
1171 return 0;
1172}
1173#endif
1174
Amitkumar Karwarbe29b992013-06-28 11:51:26 -07001175static int nl80211_send_coalesce(struct sk_buff *msg,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001176 struct cfg80211_registered_device *rdev)
Amitkumar Karwarbe29b992013-06-28 11:51:26 -07001177{
1178 struct nl80211_coalesce_rule_support rule;
1179
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001180 if (!rdev->wiphy.coalesce)
Amitkumar Karwarbe29b992013-06-28 11:51:26 -07001181 return 0;
1182
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001183 rule.max_rules = rdev->wiphy.coalesce->n_rules;
1184 rule.max_delay = rdev->wiphy.coalesce->max_delay;
1185 rule.pat.max_patterns = rdev->wiphy.coalesce->n_patterns;
1186 rule.pat.min_pattern_len = rdev->wiphy.coalesce->pattern_min_len;
1187 rule.pat.max_pattern_len = rdev->wiphy.coalesce->pattern_max_len;
1188 rule.pat.max_pkt_offset = rdev->wiphy.coalesce->max_pkt_offset;
Amitkumar Karwarbe29b992013-06-28 11:51:26 -07001189
1190 if (nla_put(msg, NL80211_ATTR_COALESCE_RULE, sizeof(rule), &rule))
1191 return -ENOBUFS;
1192
1193 return 0;
1194}
1195
Johannes Berg3713b4e2013-02-14 16:19:38 +01001196static int nl80211_send_band_rateinfo(struct sk_buff *msg,
1197 struct ieee80211_supported_band *sband)
1198{
1199 struct nlattr *nl_rates, *nl_rate;
1200 struct ieee80211_rate *rate;
1201 int i;
1202
1203 /* add HT info */
1204 if (sband->ht_cap.ht_supported &&
1205 (nla_put(msg, NL80211_BAND_ATTR_HT_MCS_SET,
1206 sizeof(sband->ht_cap.mcs),
1207 &sband->ht_cap.mcs) ||
1208 nla_put_u16(msg, NL80211_BAND_ATTR_HT_CAPA,
1209 sband->ht_cap.cap) ||
1210 nla_put_u8(msg, NL80211_BAND_ATTR_HT_AMPDU_FACTOR,
1211 sband->ht_cap.ampdu_factor) ||
1212 nla_put_u8(msg, NL80211_BAND_ATTR_HT_AMPDU_DENSITY,
1213 sband->ht_cap.ampdu_density)))
1214 return -ENOBUFS;
1215
1216 /* add VHT info */
1217 if (sband->vht_cap.vht_supported &&
1218 (nla_put(msg, NL80211_BAND_ATTR_VHT_MCS_SET,
1219 sizeof(sband->vht_cap.vht_mcs),
1220 &sband->vht_cap.vht_mcs) ||
1221 nla_put_u32(msg, NL80211_BAND_ATTR_VHT_CAPA,
1222 sband->vht_cap.cap)))
1223 return -ENOBUFS;
1224
1225 /* add bitrates */
1226 nl_rates = nla_nest_start(msg, NL80211_BAND_ATTR_RATES);
1227 if (!nl_rates)
1228 return -ENOBUFS;
1229
1230 for (i = 0; i < sband->n_bitrates; i++) {
1231 nl_rate = nla_nest_start(msg, i);
1232 if (!nl_rate)
1233 return -ENOBUFS;
1234
1235 rate = &sband->bitrates[i];
1236 if (nla_put_u32(msg, NL80211_BITRATE_ATTR_RATE,
1237 rate->bitrate))
1238 return -ENOBUFS;
1239 if ((rate->flags & IEEE80211_RATE_SHORT_PREAMBLE) &&
1240 nla_put_flag(msg,
1241 NL80211_BITRATE_ATTR_2GHZ_SHORTPREAMBLE))
1242 return -ENOBUFS;
1243
1244 nla_nest_end(msg, nl_rate);
1245 }
1246
1247 nla_nest_end(msg, nl_rates);
1248
1249 return 0;
1250}
1251
1252static int
1253nl80211_send_mgmt_stypes(struct sk_buff *msg,
1254 const struct ieee80211_txrx_stypes *mgmt_stypes)
1255{
1256 u16 stypes;
1257 struct nlattr *nl_ftypes, *nl_ifs;
1258 enum nl80211_iftype ift;
1259 int i;
1260
1261 if (!mgmt_stypes)
1262 return 0;
1263
1264 nl_ifs = nla_nest_start(msg, NL80211_ATTR_TX_FRAME_TYPES);
1265 if (!nl_ifs)
1266 return -ENOBUFS;
1267
1268 for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) {
1269 nl_ftypes = nla_nest_start(msg, ift);
1270 if (!nl_ftypes)
1271 return -ENOBUFS;
1272 i = 0;
1273 stypes = mgmt_stypes[ift].tx;
1274 while (stypes) {
1275 if ((stypes & 1) &&
1276 nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE,
1277 (i << 4) | IEEE80211_FTYPE_MGMT))
1278 return -ENOBUFS;
1279 stypes >>= 1;
1280 i++;
1281 }
1282 nla_nest_end(msg, nl_ftypes);
1283 }
1284
1285 nla_nest_end(msg, nl_ifs);
1286
1287 nl_ifs = nla_nest_start(msg, NL80211_ATTR_RX_FRAME_TYPES);
1288 if (!nl_ifs)
1289 return -ENOBUFS;
1290
1291 for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) {
1292 nl_ftypes = nla_nest_start(msg, ift);
1293 if (!nl_ftypes)
1294 return -ENOBUFS;
1295 i = 0;
1296 stypes = mgmt_stypes[ift].rx;
1297 while (stypes) {
1298 if ((stypes & 1) &&
1299 nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE,
1300 (i << 4) | IEEE80211_FTYPE_MGMT))
1301 return -ENOBUFS;
1302 stypes >>= 1;
1303 i++;
1304 }
1305 nla_nest_end(msg, nl_ftypes);
1306 }
1307 nla_nest_end(msg, nl_ifs);
1308
1309 return 0;
1310}
1311
Johannes Berg17948992016-10-26 11:42:04 +02001312#define CMD(op, n) \
1313 do { \
1314 if (rdev->ops->op) { \
1315 i++; \
1316 if (nla_put_u32(msg, i, NL80211_CMD_ ## n)) \
1317 goto nla_put_failure; \
1318 } \
1319 } while (0)
1320
1321static int nl80211_add_commands_unsplit(struct cfg80211_registered_device *rdev,
1322 struct sk_buff *msg)
1323{
1324 int i = 0;
1325
1326 /*
1327 * do *NOT* add anything into this function, new things need to be
1328 * advertised only to new versions of userspace that can deal with
1329 * the split (and they can't possibly care about new features...
1330 */
1331 CMD(add_virtual_intf, NEW_INTERFACE);
1332 CMD(change_virtual_intf, SET_INTERFACE);
1333 CMD(add_key, NEW_KEY);
1334 CMD(start_ap, START_AP);
1335 CMD(add_station, NEW_STATION);
1336 CMD(add_mpath, NEW_MPATH);
1337 CMD(update_mesh_config, SET_MESH_CONFIG);
1338 CMD(change_bss, SET_BSS);
1339 CMD(auth, AUTHENTICATE);
1340 CMD(assoc, ASSOCIATE);
1341 CMD(deauth, DEAUTHENTICATE);
1342 CMD(disassoc, DISASSOCIATE);
1343 CMD(join_ibss, JOIN_IBSS);
1344 CMD(join_mesh, JOIN_MESH);
1345 CMD(set_pmksa, SET_PMKSA);
1346 CMD(del_pmksa, DEL_PMKSA);
1347 CMD(flush_pmksa, FLUSH_PMKSA);
1348 if (rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL)
1349 CMD(remain_on_channel, REMAIN_ON_CHANNEL);
1350 CMD(set_bitrate_mask, SET_TX_BITRATE_MASK);
1351 CMD(mgmt_tx, FRAME);
1352 CMD(mgmt_tx_cancel_wait, FRAME_WAIT_CANCEL);
1353 if (rdev->wiphy.flags & WIPHY_FLAG_NETNS_OK) {
1354 i++;
1355 if (nla_put_u32(msg, i, NL80211_CMD_SET_WIPHY_NETNS))
1356 goto nla_put_failure;
1357 }
1358 if (rdev->ops->set_monitor_channel || rdev->ops->start_ap ||
1359 rdev->ops->join_mesh) {
1360 i++;
1361 if (nla_put_u32(msg, i, NL80211_CMD_SET_CHANNEL))
1362 goto nla_put_failure;
1363 }
1364 CMD(set_wds_peer, SET_WDS_PEER);
1365 if (rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) {
1366 CMD(tdls_mgmt, TDLS_MGMT);
1367 CMD(tdls_oper, TDLS_OPER);
1368 }
1369 if (rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN)
1370 CMD(sched_scan_start, START_SCHED_SCAN);
1371 CMD(probe_client, PROBE_CLIENT);
1372 CMD(set_noack_map, SET_NOACK_MAP);
1373 if (rdev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS) {
1374 i++;
1375 if (nla_put_u32(msg, i, NL80211_CMD_REGISTER_BEACONS))
1376 goto nla_put_failure;
1377 }
1378 CMD(start_p2p_device, START_P2P_DEVICE);
1379 CMD(set_mcast_rate, SET_MCAST_RATE);
1380#ifdef CONFIG_NL80211_TESTMODE
1381 CMD(testmode_cmd, TESTMODE);
1382#endif
1383
1384 if (rdev->ops->connect || rdev->ops->auth) {
1385 i++;
1386 if (nla_put_u32(msg, i, NL80211_CMD_CONNECT))
1387 goto nla_put_failure;
1388 }
1389
1390 if (rdev->ops->disconnect || rdev->ops->deauth) {
1391 i++;
1392 if (nla_put_u32(msg, i, NL80211_CMD_DISCONNECT))
1393 goto nla_put_failure;
1394 }
1395
1396 return i;
1397 nla_put_failure:
1398 return -ENOBUFS;
1399}
1400
Johannes Berg86e8cf92013-06-19 10:57:22 +02001401struct nl80211_dump_wiphy_state {
1402 s64 filter_wiphy;
1403 long start;
Kanchanapally, Vidyullatha019ae3a2016-05-16 10:41:04 +05301404 long split_start, band_start, chan_start, capa_start;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001405 bool split;
1406};
1407
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001408static int nl80211_send_wiphy(struct cfg80211_registered_device *rdev,
Johannes Berg3bb20552014-05-26 13:52:25 +02001409 enum nl80211_commands cmd,
Johannes Berg3713b4e2013-02-14 16:19:38 +01001410 struct sk_buff *msg, u32 portid, u32 seq,
Johannes Berg86e8cf92013-06-19 10:57:22 +02001411 int flags, struct nl80211_dump_wiphy_state *state)
Johannes Berg55682962007-09-20 13:09:35 -04001412{
1413 void *hdr;
Johannes Bergee688b002008-01-24 19:38:39 +01001414 struct nlattr *nl_bands, *nl_band;
1415 struct nlattr *nl_freqs, *nl_freq;
Johannes Berg8fdc6212009-03-14 09:34:01 +01001416 struct nlattr *nl_cmds;
Johannes Berg57fbcce2016-04-12 15:56:15 +02001417 enum nl80211_band band;
Johannes Bergee688b002008-01-24 19:38:39 +01001418 struct ieee80211_channel *chan;
Johannes Bergee688b002008-01-24 19:38:39 +01001419 int i;
Johannes Berg2e161f72010-08-12 15:38:38 +02001420 const struct ieee80211_txrx_stypes *mgmt_stypes =
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001421 rdev->wiphy.mgmt_stypes;
Johannes Bergfe1abaf2013-02-27 15:39:45 +01001422 u32 features;
Johannes Berg55682962007-09-20 13:09:35 -04001423
Johannes Berg3bb20552014-05-26 13:52:25 +02001424 hdr = nl80211hdr_put(msg, portid, seq, flags, cmd);
Johannes Berg55682962007-09-20 13:09:35 -04001425 if (!hdr)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001426 return -ENOBUFS;
1427
Johannes Berg86e8cf92013-06-19 10:57:22 +02001428 if (WARN_ON(!state))
1429 return -EINVAL;
Johannes Berg55682962007-09-20 13:09:35 -04001430
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001431 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001432 nla_put_string(msg, NL80211_ATTR_WIPHY_NAME,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001433 wiphy_name(&rdev->wiphy)) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04001434 nla_put_u32(msg, NL80211_ATTR_GENERATION,
Johannes Berg3713b4e2013-02-14 16:19:38 +01001435 cfg80211_rdev_list_generation))
David S. Miller9360ffd2012-03-29 04:41:26 -04001436 goto nla_put_failure;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02001437
Johannes Berg3bb20552014-05-26 13:52:25 +02001438 if (cmd != NL80211_CMD_NEW_WIPHY)
1439 goto finish;
1440
Johannes Berg86e8cf92013-06-19 10:57:22 +02001441 switch (state->split_start) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001442 case 0:
1443 if (nla_put_u8(msg, NL80211_ATTR_WIPHY_RETRY_SHORT,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001444 rdev->wiphy.retry_short) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001445 nla_put_u8(msg, NL80211_ATTR_WIPHY_RETRY_LONG,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001446 rdev->wiphy.retry_long) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001447 nla_put_u32(msg, NL80211_ATTR_WIPHY_FRAG_THRESHOLD,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001448 rdev->wiphy.frag_threshold) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001449 nla_put_u32(msg, NL80211_ATTR_WIPHY_RTS_THRESHOLD,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001450 rdev->wiphy.rts_threshold) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001451 nla_put_u8(msg, NL80211_ATTR_WIPHY_COVERAGE_CLASS,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001452 rdev->wiphy.coverage_class) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001453 nla_put_u8(msg, NL80211_ATTR_MAX_NUM_SCAN_SSIDS,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001454 rdev->wiphy.max_scan_ssids) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001455 nla_put_u8(msg, NL80211_ATTR_MAX_NUM_SCHED_SCAN_SSIDS,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001456 rdev->wiphy.max_sched_scan_ssids) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001457 nla_put_u16(msg, NL80211_ATTR_MAX_SCAN_IE_LEN,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001458 rdev->wiphy.max_scan_ie_len) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001459 nla_put_u16(msg, NL80211_ATTR_MAX_SCHED_SCAN_IE_LEN,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001460 rdev->wiphy.max_sched_scan_ie_len) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001461 nla_put_u8(msg, NL80211_ATTR_MAX_MATCH_SETS,
Avraham Stern3b06d272015-10-12 09:51:34 +03001462 rdev->wiphy.max_match_sets) ||
1463 nla_put_u32(msg, NL80211_ATTR_MAX_NUM_SCHED_SCAN_PLANS,
1464 rdev->wiphy.max_sched_scan_plans) ||
1465 nla_put_u32(msg, NL80211_ATTR_MAX_SCAN_PLAN_INTERVAL,
1466 rdev->wiphy.max_sched_scan_plan_interval) ||
1467 nla_put_u32(msg, NL80211_ATTR_MAX_SCAN_PLAN_ITERATIONS,
1468 rdev->wiphy.max_sched_scan_plan_iterations))
Johannes Bergee688b002008-01-24 19:38:39 +01001469 goto nla_put_failure;
1470
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001471 if ((rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001472 nla_put_flag(msg, NL80211_ATTR_SUPPORT_IBSS_RSN))
1473 goto nla_put_failure;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001474 if ((rdev->wiphy.flags & WIPHY_FLAG_MESH_AUTH) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001475 nla_put_flag(msg, NL80211_ATTR_SUPPORT_MESH_AUTH))
1476 goto nla_put_failure;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001477 if ((rdev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001478 nla_put_flag(msg, NL80211_ATTR_SUPPORT_AP_UAPSD))
1479 goto nla_put_failure;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001480 if ((rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_FW_ROAM) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001481 nla_put_flag(msg, NL80211_ATTR_ROAM_SUPPORT))
1482 goto nla_put_failure;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001483 if ((rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001484 nla_put_flag(msg, NL80211_ATTR_TDLS_SUPPORT))
1485 goto nla_put_failure;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001486 if ((rdev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001487 nla_put_flag(msg, NL80211_ATTR_TDLS_EXTERNAL_SETUP))
David S. Miller9360ffd2012-03-29 04:41:26 -04001488 goto nla_put_failure;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001489 state->split_start++;
1490 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001491 break;
1492 case 1:
1493 if (nla_put(msg, NL80211_ATTR_CIPHER_SUITES,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001494 sizeof(u32) * rdev->wiphy.n_cipher_suites,
1495 rdev->wiphy.cipher_suites))
Mahesh Palivelabf0c111e2012-06-22 07:27:46 +00001496 goto nla_put_failure;
1497
Johannes Berg3713b4e2013-02-14 16:19:38 +01001498 if (nla_put_u8(msg, NL80211_ATTR_MAX_NUM_PMKIDS,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001499 rdev->wiphy.max_num_pmkids))
Johannes Bergee688b002008-01-24 19:38:39 +01001500 goto nla_put_failure;
1501
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001502 if ((rdev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001503 nla_put_flag(msg, NL80211_ATTR_CONTROL_PORT_ETHERTYPE))
1504 goto nla_put_failure;
Johannes Bergee688b002008-01-24 19:38:39 +01001505
Johannes Berg3713b4e2013-02-14 16:19:38 +01001506 if (nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_TX,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001507 rdev->wiphy.available_antennas_tx) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001508 nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_RX,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001509 rdev->wiphy.available_antennas_rx))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001510 goto nla_put_failure;
Johannes Bergee688b002008-01-24 19:38:39 +01001511
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001512 if ((rdev->wiphy.flags & WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001513 nla_put_u32(msg, NL80211_ATTR_PROBE_RESP_OFFLOAD,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001514 rdev->wiphy.probe_resp_offload))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001515 goto nla_put_failure;
Jouni Malinene2f367f262008-11-21 19:01:30 +02001516
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001517 if ((rdev->wiphy.available_antennas_tx ||
1518 rdev->wiphy.available_antennas_rx) &&
1519 rdev->ops->get_antenna) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001520 u32 tx_ant = 0, rx_ant = 0;
1521 int res;
Kirtika Ruchandani7a087e72016-05-29 19:51:23 -07001522
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001523 res = rdev_get_antenna(rdev, &tx_ant, &rx_ant);
Johannes Berg3713b4e2013-02-14 16:19:38 +01001524 if (!res) {
1525 if (nla_put_u32(msg,
1526 NL80211_ATTR_WIPHY_ANTENNA_TX,
1527 tx_ant) ||
1528 nla_put_u32(msg,
1529 NL80211_ATTR_WIPHY_ANTENNA_RX,
1530 rx_ant))
1531 goto nla_put_failure;
1532 }
Johannes Bergee688b002008-01-24 19:38:39 +01001533 }
1534
Johannes Berg86e8cf92013-06-19 10:57:22 +02001535 state->split_start++;
1536 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001537 break;
1538 case 2:
1539 if (nl80211_put_iftypes(msg, NL80211_ATTR_SUPPORTED_IFTYPES,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001540 rdev->wiphy.interface_modes))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001541 goto nla_put_failure;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001542 state->split_start++;
1543 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001544 break;
1545 case 3:
1546 nl_bands = nla_nest_start(msg, NL80211_ATTR_WIPHY_BANDS);
1547 if (!nl_bands)
Johannes Bergee688b002008-01-24 19:38:39 +01001548 goto nla_put_failure;
1549
Johannes Berg86e8cf92013-06-19 10:57:22 +02001550 for (band = state->band_start;
Johannes Berg57fbcce2016-04-12 15:56:15 +02001551 band < NUM_NL80211_BANDS; band++) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001552 struct ieee80211_supported_band *sband;
1553
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001554 sband = rdev->wiphy.bands[band];
Johannes Berg3713b4e2013-02-14 16:19:38 +01001555
1556 if (!sband)
1557 continue;
1558
1559 nl_band = nla_nest_start(msg, band);
1560 if (!nl_band)
Johannes Bergee688b002008-01-24 19:38:39 +01001561 goto nla_put_failure;
1562
Johannes Berg86e8cf92013-06-19 10:57:22 +02001563 switch (state->chan_start) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001564 case 0:
1565 if (nl80211_send_band_rateinfo(msg, sband))
1566 goto nla_put_failure;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001567 state->chan_start++;
1568 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001569 break;
1570 default:
1571 /* add frequencies */
1572 nl_freqs = nla_nest_start(
1573 msg, NL80211_BAND_ATTR_FREQS);
1574 if (!nl_freqs)
1575 goto nla_put_failure;
Johannes Bergee688b002008-01-24 19:38:39 +01001576
Johannes Berg86e8cf92013-06-19 10:57:22 +02001577 for (i = state->chan_start - 1;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001578 i < sband->n_channels;
1579 i++) {
1580 nl_freq = nla_nest_start(msg, i);
1581 if (!nl_freq)
1582 goto nla_put_failure;
1583
1584 chan = &sband->channels[i];
1585
Johannes Berg86e8cf92013-06-19 10:57:22 +02001586 if (nl80211_msg_put_channel(
1587 msg, chan,
1588 state->split))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001589 goto nla_put_failure;
1590
1591 nla_nest_end(msg, nl_freq);
Johannes Berg86e8cf92013-06-19 10:57:22 +02001592 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001593 break;
1594 }
1595 if (i < sband->n_channels)
Johannes Berg86e8cf92013-06-19 10:57:22 +02001596 state->chan_start = i + 2;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001597 else
Johannes Berg86e8cf92013-06-19 10:57:22 +02001598 state->chan_start = 0;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001599 nla_nest_end(msg, nl_freqs);
1600 }
1601
1602 nla_nest_end(msg, nl_band);
1603
Johannes Berg86e8cf92013-06-19 10:57:22 +02001604 if (state->split) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001605 /* start again here */
Johannes Berg86e8cf92013-06-19 10:57:22 +02001606 if (state->chan_start)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001607 band--;
1608 break;
1609 }
Johannes Bergee688b002008-01-24 19:38:39 +01001610 }
Johannes Berg3713b4e2013-02-14 16:19:38 +01001611 nla_nest_end(msg, nl_bands);
Johannes Bergee688b002008-01-24 19:38:39 +01001612
Johannes Berg57fbcce2016-04-12 15:56:15 +02001613 if (band < NUM_NL80211_BANDS)
Johannes Berg86e8cf92013-06-19 10:57:22 +02001614 state->band_start = band + 1;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001615 else
Johannes Berg86e8cf92013-06-19 10:57:22 +02001616 state->band_start = 0;
Johannes Bergee688b002008-01-24 19:38:39 +01001617
Johannes Berg3713b4e2013-02-14 16:19:38 +01001618 /* if bands & channels are done, continue outside */
Johannes Berg86e8cf92013-06-19 10:57:22 +02001619 if (state->band_start == 0 && state->chan_start == 0)
1620 state->split_start++;
1621 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001622 break;
1623 case 4:
1624 nl_cmds = nla_nest_start(msg, NL80211_ATTR_SUPPORTED_COMMANDS);
1625 if (!nl_cmds)
David S. Miller9360ffd2012-03-29 04:41:26 -04001626 goto nla_put_failure;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001627
Johannes Berg17948992016-10-26 11:42:04 +02001628 i = nl80211_add_commands_unsplit(rdev, msg);
1629 if (i < 0)
1630 goto nla_put_failure;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001631 if (state->split) {
Arend van Spriel5de17982013-04-18 15:49:00 +02001632 CMD(crit_proto_start, CRIT_PROTOCOL_START);
1633 CMD(crit_proto_stop, CRIT_PROTOCOL_STOP);
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001634 if (rdev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH)
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02001635 CMD(channel_switch, CHANNEL_SWITCH);
Johannes Berg02df00e2014-06-10 14:06:25 +02001636 CMD(set_qos_map, SET_QOS_MAP);
Johannes Berg723e73a2014-10-22 09:25:06 +02001637 if (rdev->wiphy.features &
1638 NL80211_FEATURE_SUPPORTS_WMM_ADMISSION)
Johannes Berg960d01a2014-09-09 22:55:35 +03001639 CMD(add_tx_ts, ADD_TX_TS);
Michael Braunce0ce132016-10-10 19:12:22 +02001640 CMD(set_multicast_to_unicast, SET_MULTICAST_TO_UNICAST);
vamsi krishna088e8df2016-10-27 16:51:11 +03001641 CMD(update_connect_params, UPDATE_CONNECT_PARAMS);
Arend van Spriel5de17982013-04-18 15:49:00 +02001642 }
Johannes Berg8fdc6212009-03-14 09:34:01 +01001643#undef CMD
Samuel Ortizb23aa672009-07-01 21:26:54 +02001644
Johannes Berg3713b4e2013-02-14 16:19:38 +01001645 nla_nest_end(msg, nl_cmds);
Johannes Berg86e8cf92013-06-19 10:57:22 +02001646 state->split_start++;
1647 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001648 break;
1649 case 5:
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001650 if (rdev->ops->remain_on_channel &&
1651 (rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001652 nla_put_u32(msg,
1653 NL80211_ATTR_MAX_REMAIN_ON_CHANNEL_DURATION,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001654 rdev->wiphy.max_remain_on_channel_duration))
Johannes Berg2e161f72010-08-12 15:38:38 +02001655 goto nla_put_failure;
1656
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001657 if ((rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001658 nla_put_flag(msg, NL80211_ATTR_OFFCHANNEL_TX_OK))
1659 goto nla_put_failure;
Johannes Berg2e161f72010-08-12 15:38:38 +02001660
Johannes Berg3713b4e2013-02-14 16:19:38 +01001661 if (nl80211_send_mgmt_stypes(msg, mgmt_stypes))
1662 goto nla_put_failure;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001663 state->split_start++;
1664 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001665 break;
1666 case 6:
Johannes Bergdfb89c52012-06-27 09:23:48 +02001667#ifdef CONFIG_PM
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001668 if (nl80211_send_wowlan(msg, rdev, state->split))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001669 goto nla_put_failure;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001670 state->split_start++;
1671 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001672 break;
1673#else
Johannes Berg86e8cf92013-06-19 10:57:22 +02001674 state->split_start++;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001675#endif
1676 case 7:
1677 if (nl80211_put_iftypes(msg, NL80211_ATTR_SOFTWARE_IFTYPES,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001678 rdev->wiphy.software_iftypes))
Johannes Bergff1b6e62011-05-04 15:37:28 +02001679 goto nla_put_failure;
1680
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001681 if (nl80211_put_iface_combinations(&rdev->wiphy, msg,
Johannes Berg86e8cf92013-06-19 10:57:22 +02001682 state->split))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001683 goto nla_put_failure;
Johannes Bergff1b6e62011-05-04 15:37:28 +02001684
Johannes Berg86e8cf92013-06-19 10:57:22 +02001685 state->split_start++;
1686 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001687 break;
1688 case 8:
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001689 if ((rdev->wiphy.flags & WIPHY_FLAG_HAVE_AP_SME) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001690 nla_put_u32(msg, NL80211_ATTR_DEVICE_AP_SME,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001691 rdev->wiphy.ap_sme_capa))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001692 goto nla_put_failure;
1693
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001694 features = rdev->wiphy.features;
Johannes Bergfe1abaf2013-02-27 15:39:45 +01001695 /*
1696 * We can only add the per-channel limit information if the
1697 * dump is split, otherwise it makes it too big. Therefore
1698 * only advertise it in that case.
1699 */
Johannes Berg86e8cf92013-06-19 10:57:22 +02001700 if (state->split)
Johannes Bergfe1abaf2013-02-27 15:39:45 +01001701 features |= NL80211_FEATURE_ADVERTISE_CHAN_LIMITS;
1702 if (nla_put_u32(msg, NL80211_ATTR_FEATURE_FLAGS, features))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001703 goto nla_put_failure;
1704
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001705 if (rdev->wiphy.ht_capa_mod_mask &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001706 nla_put(msg, NL80211_ATTR_HT_CAPABILITY_MASK,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001707 sizeof(*rdev->wiphy.ht_capa_mod_mask),
1708 rdev->wiphy.ht_capa_mod_mask))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001709 goto nla_put_failure;
1710
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001711 if (rdev->wiphy.flags & WIPHY_FLAG_HAVE_AP_SME &&
1712 rdev->wiphy.max_acl_mac_addrs &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001713 nla_put_u32(msg, NL80211_ATTR_MAC_ACL_MAX,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001714 rdev->wiphy.max_acl_mac_addrs))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001715 goto nla_put_failure;
1716
1717 /*
1718 * Any information below this point is only available to
1719 * applications that can deal with it being split. This
1720 * helps ensure that newly added capabilities don't break
1721 * older tools by overrunning their buffers.
1722 *
1723 * We still increment split_start so that in the split
1724 * case we'll continue with more data in the next round,
1725 * but break unconditionally so unsplit data stops here.
1726 */
Johannes Berg86e8cf92013-06-19 10:57:22 +02001727 state->split_start++;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001728 break;
1729 case 9:
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001730 if (rdev->wiphy.extended_capabilities &&
Johannes Bergfe1abaf2013-02-27 15:39:45 +01001731 (nla_put(msg, NL80211_ATTR_EXT_CAPA,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001732 rdev->wiphy.extended_capabilities_len,
1733 rdev->wiphy.extended_capabilities) ||
Johannes Bergfe1abaf2013-02-27 15:39:45 +01001734 nla_put(msg, NL80211_ATTR_EXT_CAPA_MASK,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001735 rdev->wiphy.extended_capabilities_len,
1736 rdev->wiphy.extended_capabilities_mask)))
Johannes Bergfe1abaf2013-02-27 15:39:45 +01001737 goto nla_put_failure;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001738
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001739 if (rdev->wiphy.vht_capa_mod_mask &&
Johannes Bergee2aca32013-02-21 17:36:01 +01001740 nla_put(msg, NL80211_ATTR_VHT_CAPABILITY_MASK,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001741 sizeof(*rdev->wiphy.vht_capa_mod_mask),
1742 rdev->wiphy.vht_capa_mod_mask))
Johannes Bergee2aca32013-02-21 17:36:01 +01001743 goto nla_put_failure;
1744
Amitkumar Karwarbe29b992013-06-28 11:51:26 -07001745 state->split_start++;
1746 break;
1747 case 10:
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001748 if (nl80211_send_coalesce(msg, rdev))
Amitkumar Karwarbe29b992013-06-28 11:51:26 -07001749 goto nla_put_failure;
1750
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001751 if ((rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_5_10_MHZ) &&
Felix Fietkau01e0daa2013-11-09 14:57:54 +01001752 (nla_put_flag(msg, NL80211_ATTR_SUPPORT_5_MHZ) ||
1753 nla_put_flag(msg, NL80211_ATTR_SUPPORT_10_MHZ)))
1754 goto nla_put_failure;
Jouni Malinenb43504c2014-01-15 00:01:08 +02001755
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001756 if (rdev->wiphy.max_ap_assoc_sta &&
Jouni Malinenb43504c2014-01-15 00:01:08 +02001757 nla_put_u32(msg, NL80211_ATTR_MAX_AP_ASSOC_STA,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001758 rdev->wiphy.max_ap_assoc_sta))
Jouni Malinenb43504c2014-01-15 00:01:08 +02001759 goto nla_put_failure;
1760
Johannes Bergad7e7182013-11-13 13:37:47 +01001761 state->split_start++;
1762 break;
1763 case 11:
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001764 if (rdev->wiphy.n_vendor_commands) {
Johannes Berg567ffc32013-12-18 14:43:31 +01001765 const struct nl80211_vendor_cmd_info *info;
1766 struct nlattr *nested;
Johannes Bergad7e7182013-11-13 13:37:47 +01001767
Johannes Berg567ffc32013-12-18 14:43:31 +01001768 nested = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA);
1769 if (!nested)
Johannes Bergad7e7182013-11-13 13:37:47 +01001770 goto nla_put_failure;
Johannes Berg567ffc32013-12-18 14:43:31 +01001771
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001772 for (i = 0; i < rdev->wiphy.n_vendor_commands; i++) {
1773 info = &rdev->wiphy.vendor_commands[i].info;
Johannes Berg567ffc32013-12-18 14:43:31 +01001774 if (nla_put(msg, i + 1, sizeof(*info), info))
1775 goto nla_put_failure;
1776 }
1777 nla_nest_end(msg, nested);
1778 }
1779
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001780 if (rdev->wiphy.n_vendor_events) {
Johannes Berg567ffc32013-12-18 14:43:31 +01001781 const struct nl80211_vendor_cmd_info *info;
1782 struct nlattr *nested;
1783
1784 nested = nla_nest_start(msg,
1785 NL80211_ATTR_VENDOR_EVENTS);
1786 if (!nested)
1787 goto nla_put_failure;
1788
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001789 for (i = 0; i < rdev->wiphy.n_vendor_events; i++) {
1790 info = &rdev->wiphy.vendor_events[i];
Johannes Berg567ffc32013-12-18 14:43:31 +01001791 if (nla_put(msg, i + 1, sizeof(*info), info))
1792 goto nla_put_failure;
1793 }
1794 nla_nest_end(msg, nested);
1795 }
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03001796 state->split_start++;
1797 break;
1798 case 12:
1799 if (rdev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH &&
1800 nla_put_u8(msg, NL80211_ATTR_MAX_CSA_COUNTERS,
1801 rdev->wiphy.max_num_csa_counters))
1802 goto nla_put_failure;
Felix Fietkau01e0daa2013-11-09 14:57:54 +01001803
Arik Nemtsov1bdd7162014-12-15 19:26:01 +02001804 if (rdev->wiphy.regulatory_flags & REGULATORY_WIPHY_SELF_MANAGED &&
1805 nla_put_flag(msg, NL80211_ATTR_WIPHY_SELF_MANAGED_REG))
1806 goto nla_put_failure;
1807
Gautam Kumar Shuklad75bb062014-12-23 16:55:19 +01001808 if (nla_put(msg, NL80211_ATTR_EXT_FEATURES,
1809 sizeof(rdev->wiphy.ext_features),
1810 rdev->wiphy.ext_features))
1811 goto nla_put_failure;
1812
Arend van Spriel38de03d2016-03-02 20:37:18 +01001813 if (rdev->wiphy.bss_select_support) {
1814 struct nlattr *nested;
1815 u32 bss_select_support = rdev->wiphy.bss_select_support;
1816
1817 nested = nla_nest_start(msg, NL80211_ATTR_BSS_SELECT);
1818 if (!nested)
1819 goto nla_put_failure;
1820
1821 i = 0;
1822 while (bss_select_support) {
1823 if ((bss_select_support & 1) &&
1824 nla_put_flag(msg, i))
1825 goto nla_put_failure;
1826 i++;
1827 bss_select_support >>= 1;
1828 }
1829 nla_nest_end(msg, nested);
1830 }
1831
Kanchanapally, Vidyullatha019ae3a2016-05-16 10:41:04 +05301832 state->split_start++;
1833 break;
1834 case 13:
1835 if (rdev->wiphy.num_iftype_ext_capab &&
1836 rdev->wiphy.iftype_ext_capab) {
1837 struct nlattr *nested_ext_capab, *nested;
1838
1839 nested = nla_nest_start(msg,
1840 NL80211_ATTR_IFTYPE_EXT_CAPA);
1841 if (!nested)
1842 goto nla_put_failure;
1843
1844 for (i = state->capa_start;
1845 i < rdev->wiphy.num_iftype_ext_capab; i++) {
1846 const struct wiphy_iftype_ext_capab *capab;
1847
1848 capab = &rdev->wiphy.iftype_ext_capab[i];
1849
1850 nested_ext_capab = nla_nest_start(msg, i);
1851 if (!nested_ext_capab ||
1852 nla_put_u32(msg, NL80211_ATTR_IFTYPE,
1853 capab->iftype) ||
1854 nla_put(msg, NL80211_ATTR_EXT_CAPA,
1855 capab->extended_capabilities_len,
1856 capab->extended_capabilities) ||
1857 nla_put(msg, NL80211_ATTR_EXT_CAPA_MASK,
1858 capab->extended_capabilities_len,
1859 capab->extended_capabilities_mask))
1860 goto nla_put_failure;
1861
1862 nla_nest_end(msg, nested_ext_capab);
1863 if (state->split)
1864 break;
1865 }
1866 nla_nest_end(msg, nested);
1867 if (i < rdev->wiphy.num_iftype_ext_capab) {
1868 state->capa_start = i + 1;
1869 break;
1870 }
1871 }
1872
Luca Coelho85859892017-02-08 15:00:34 +02001873 if (nla_put_u32(msg, NL80211_ATTR_BANDS,
1874 rdev->wiphy.nan_supported_bands))
1875 goto nla_put_failure;
1876
Johannes Berg3713b4e2013-02-14 16:19:38 +01001877 /* done */
Johannes Berg86e8cf92013-06-19 10:57:22 +02001878 state->split_start = 0;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001879 break;
Johannes Bergff1b6e62011-05-04 15:37:28 +02001880 }
Johannes Berg3bb20552014-05-26 13:52:25 +02001881 finish:
Johannes Berg053c0952015-01-16 22:09:00 +01001882 genlmsg_end(msg, hdr);
1883 return 0;
Johannes Berg55682962007-09-20 13:09:35 -04001884
1885 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07001886 genlmsg_cancel(msg, hdr);
1887 return -EMSGSIZE;
Johannes Berg55682962007-09-20 13:09:35 -04001888}
1889
Johannes Berg86e8cf92013-06-19 10:57:22 +02001890static int nl80211_dump_wiphy_parse(struct sk_buff *skb,
1891 struct netlink_callback *cb,
1892 struct nl80211_dump_wiphy_state *state)
1893{
Johannes Bergc90c39d2016-10-24 14:40:01 +02001894 struct nlattr **tb = genl_family_attrbuf(&nl80211_fam);
Johannes Berg86e8cf92013-06-19 10:57:22 +02001895 int ret = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize,
1896 tb, nl80211_fam.maxattr, nl80211_policy);
1897 /* ignore parse errors for backward compatibility */
1898 if (ret)
1899 return 0;
1900
1901 state->split = tb[NL80211_ATTR_SPLIT_WIPHY_DUMP];
1902 if (tb[NL80211_ATTR_WIPHY])
1903 state->filter_wiphy = nla_get_u32(tb[NL80211_ATTR_WIPHY]);
1904 if (tb[NL80211_ATTR_WDEV])
1905 state->filter_wiphy = nla_get_u64(tb[NL80211_ATTR_WDEV]) >> 32;
1906 if (tb[NL80211_ATTR_IFINDEX]) {
1907 struct net_device *netdev;
1908 struct cfg80211_registered_device *rdev;
1909 int ifidx = nla_get_u32(tb[NL80211_ATTR_IFINDEX]);
1910
Ying Xue7f2b8562014-01-15 10:23:45 +08001911 netdev = __dev_get_by_index(sock_net(skb->sk), ifidx);
Johannes Berg86e8cf92013-06-19 10:57:22 +02001912 if (!netdev)
1913 return -ENODEV;
1914 if (netdev->ieee80211_ptr) {
Zhao, Gangf26cbf42014-04-21 12:53:03 +08001915 rdev = wiphy_to_rdev(
Johannes Berg86e8cf92013-06-19 10:57:22 +02001916 netdev->ieee80211_ptr->wiphy);
1917 state->filter_wiphy = rdev->wiphy_idx;
1918 }
Johannes Berg86e8cf92013-06-19 10:57:22 +02001919 }
1920
1921 return 0;
1922}
1923
Johannes Berg55682962007-09-20 13:09:35 -04001924static int nl80211_dump_wiphy(struct sk_buff *skb, struct netlink_callback *cb)
1925{
Johannes Berg645e77d2013-03-01 14:03:49 +01001926 int idx = 0, ret;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001927 struct nl80211_dump_wiphy_state *state = (void *)cb->args[0];
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001928 struct cfg80211_registered_device *rdev;
Johannes Berg3a5a4232013-06-19 10:09:57 +02001929
Johannes Berg5fe231e2013-05-08 21:45:15 +02001930 rtnl_lock();
Johannes Berg86e8cf92013-06-19 10:57:22 +02001931 if (!state) {
1932 state = kzalloc(sizeof(*state), GFP_KERNEL);
John W. Linville57ed5cd2013-06-28 13:18:21 -04001933 if (!state) {
1934 rtnl_unlock();
Johannes Berg86e8cf92013-06-19 10:57:22 +02001935 return -ENOMEM;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001936 }
Johannes Berg86e8cf92013-06-19 10:57:22 +02001937 state->filter_wiphy = -1;
1938 ret = nl80211_dump_wiphy_parse(skb, cb, state);
1939 if (ret) {
1940 kfree(state);
1941 rtnl_unlock();
1942 return ret;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001943 }
Johannes Berg86e8cf92013-06-19 10:57:22 +02001944 cb->args[0] = (long)state;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001945 }
1946
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001947 list_for_each_entry(rdev, &cfg80211_rdev_list, list) {
1948 if (!net_eq(wiphy_net(&rdev->wiphy), sock_net(skb->sk)))
Johannes Berg463d0182009-07-14 00:33:35 +02001949 continue;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001950 if (++idx <= state->start)
Johannes Berg55682962007-09-20 13:09:35 -04001951 continue;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001952 if (state->filter_wiphy != -1 &&
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001953 state->filter_wiphy != rdev->wiphy_idx)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001954 continue;
1955 /* attempt to fit multiple wiphy data chunks into the skb */
1956 do {
Johannes Berg3bb20552014-05-26 13:52:25 +02001957 ret = nl80211_send_wiphy(rdev, NL80211_CMD_NEW_WIPHY,
1958 skb,
Johannes Berg3713b4e2013-02-14 16:19:38 +01001959 NETLINK_CB(cb->skb).portid,
1960 cb->nlh->nlmsg_seq,
Johannes Berg86e8cf92013-06-19 10:57:22 +02001961 NLM_F_MULTI, state);
Johannes Berg3713b4e2013-02-14 16:19:38 +01001962 if (ret < 0) {
1963 /*
1964 * If sending the wiphy data didn't fit (ENOBUFS
1965 * or EMSGSIZE returned), this SKB is still
1966 * empty (so it's not too big because another
1967 * wiphy dataset is already in the skb) and
1968 * we've not tried to adjust the dump allocation
1969 * yet ... then adjust the alloc size to be
1970 * bigger, and return 1 but with the empty skb.
1971 * This results in an empty message being RX'ed
1972 * in userspace, but that is ignored.
1973 *
1974 * We can then retry with the larger buffer.
1975 */
1976 if ((ret == -ENOBUFS || ret == -EMSGSIZE) &&
Pontus Fuchsf12cb282014-01-16 15:00:40 +01001977 !skb->len && !state->split &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001978 cb->min_dump_alloc < 4096) {
1979 cb->min_dump_alloc = 4096;
Pontus Fuchsf12cb282014-01-16 15:00:40 +01001980 state->split_start = 0;
David S. Millerd98cae64e2013-06-19 16:49:39 -07001981 rtnl_unlock();
Johannes Berg3713b4e2013-02-14 16:19:38 +01001982 return 1;
1983 }
1984 idx--;
1985 break;
Johannes Berg645e77d2013-03-01 14:03:49 +01001986 }
Johannes Berg86e8cf92013-06-19 10:57:22 +02001987 } while (state->split_start > 0);
Johannes Berg3713b4e2013-02-14 16:19:38 +01001988 break;
Johannes Berg55682962007-09-20 13:09:35 -04001989 }
Johannes Berg5fe231e2013-05-08 21:45:15 +02001990 rtnl_unlock();
Johannes Berg55682962007-09-20 13:09:35 -04001991
Johannes Berg86e8cf92013-06-19 10:57:22 +02001992 state->start = idx;
Johannes Berg55682962007-09-20 13:09:35 -04001993
1994 return skb->len;
1995}
1996
Johannes Berg86e8cf92013-06-19 10:57:22 +02001997static int nl80211_dump_wiphy_done(struct netlink_callback *cb)
1998{
1999 kfree((void *)cb->args[0]);
2000 return 0;
2001}
2002
Johannes Berg55682962007-09-20 13:09:35 -04002003static int nl80211_get_wiphy(struct sk_buff *skb, struct genl_info *info)
2004{
2005 struct sk_buff *msg;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002006 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg86e8cf92013-06-19 10:57:22 +02002007 struct nl80211_dump_wiphy_state state = {};
Johannes Berg55682962007-09-20 13:09:35 -04002008
Johannes Berg645e77d2013-03-01 14:03:49 +01002009 msg = nlmsg_new(4096, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -04002010 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02002011 return -ENOMEM;
Johannes Berg55682962007-09-20 13:09:35 -04002012
Johannes Berg3bb20552014-05-26 13:52:25 +02002013 if (nl80211_send_wiphy(rdev, NL80211_CMD_NEW_WIPHY, msg,
2014 info->snd_portid, info->snd_seq, 0,
Johannes Berg86e8cf92013-06-19 10:57:22 +02002015 &state) < 0) {
Johannes Berg4c476992010-10-04 21:36:35 +02002016 nlmsg_free(msg);
2017 return -ENOBUFS;
2018 }
Johannes Berg55682962007-09-20 13:09:35 -04002019
Johannes Berg134e6372009-07-10 09:51:34 +00002020 return genlmsg_reply(msg, info);
Johannes Berg55682962007-09-20 13:09:35 -04002021}
2022
Jouni Malinen31888482008-10-30 16:59:24 +02002023static const struct nla_policy txq_params_policy[NL80211_TXQ_ATTR_MAX + 1] = {
2024 [NL80211_TXQ_ATTR_QUEUE] = { .type = NLA_U8 },
2025 [NL80211_TXQ_ATTR_TXOP] = { .type = NLA_U16 },
2026 [NL80211_TXQ_ATTR_CWMIN] = { .type = NLA_U16 },
2027 [NL80211_TXQ_ATTR_CWMAX] = { .type = NLA_U16 },
2028 [NL80211_TXQ_ATTR_AIFS] = { .type = NLA_U8 },
2029};
2030
2031static int parse_txq_params(struct nlattr *tb[],
2032 struct ieee80211_txq_params *txq_params)
2033{
Johannes Berga3304b02012-03-28 11:04:24 +02002034 if (!tb[NL80211_TXQ_ATTR_AC] || !tb[NL80211_TXQ_ATTR_TXOP] ||
Jouni Malinen31888482008-10-30 16:59:24 +02002035 !tb[NL80211_TXQ_ATTR_CWMIN] || !tb[NL80211_TXQ_ATTR_CWMAX] ||
2036 !tb[NL80211_TXQ_ATTR_AIFS])
2037 return -EINVAL;
2038
Johannes Berga3304b02012-03-28 11:04:24 +02002039 txq_params->ac = nla_get_u8(tb[NL80211_TXQ_ATTR_AC]);
Jouni Malinen31888482008-10-30 16:59:24 +02002040 txq_params->txop = nla_get_u16(tb[NL80211_TXQ_ATTR_TXOP]);
2041 txq_params->cwmin = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMIN]);
2042 txq_params->cwmax = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMAX]);
2043 txq_params->aifs = nla_get_u8(tb[NL80211_TXQ_ATTR_AIFS]);
2044
Johannes Berga3304b02012-03-28 11:04:24 +02002045 if (txq_params->ac >= NL80211_NUM_ACS)
2046 return -EINVAL;
2047
Jouni Malinen31888482008-10-30 16:59:24 +02002048 return 0;
2049}
2050
Johannes Bergf444de02010-05-05 15:25:02 +02002051static bool nl80211_can_set_dev_channel(struct wireless_dev *wdev)
2052{
2053 /*
Johannes Bergcc1d2802012-05-16 23:50:20 +02002054 * You can only set the channel explicitly for WDS interfaces,
2055 * all others have their channel managed via their respective
2056 * "establish a connection" command (connect, join, ...)
2057 *
2058 * For AP/GO and mesh mode, the channel can be set with the
2059 * channel userspace API, but is only stored and passed to the
2060 * low-level driver when the AP starts or the mesh is joined.
2061 * This is for backward compatibility, userspace can also give
2062 * the channel in the start-ap or join-mesh commands instead.
Johannes Bergf444de02010-05-05 15:25:02 +02002063 *
2064 * Monitors are special as they are normally slaved to
Johannes Berge8c9bd52012-06-06 08:18:22 +02002065 * whatever else is going on, so they have their own special
2066 * operation to set the monitor channel if possible.
Johannes Bergf444de02010-05-05 15:25:02 +02002067 */
2068 return !wdev ||
2069 wdev->iftype == NL80211_IFTYPE_AP ||
Johannes Bergf444de02010-05-05 15:25:02 +02002070 wdev->iftype == NL80211_IFTYPE_MESH_POINT ||
Johannes Berg074ac8d2010-09-16 14:58:22 +02002071 wdev->iftype == NL80211_IFTYPE_MONITOR ||
2072 wdev->iftype == NL80211_IFTYPE_P2P_GO;
Johannes Bergf444de02010-05-05 15:25:02 +02002073}
2074
Johannes Berg683b6d32012-11-08 21:25:48 +01002075static int nl80211_parse_chandef(struct cfg80211_registered_device *rdev,
2076 struct genl_info *info,
2077 struct cfg80211_chan_def *chandef)
2078{
Mahesh Paliveladbeca2e2012-11-29 14:11:07 +05302079 u32 control_freq;
Johannes Berg683b6d32012-11-08 21:25:48 +01002080
2081 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ])
2082 return -EINVAL;
2083
2084 control_freq = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]);
2085
2086 chandef->chan = ieee80211_get_channel(&rdev->wiphy, control_freq);
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002087 chandef->width = NL80211_CHAN_WIDTH_20_NOHT;
2088 chandef->center_freq1 = control_freq;
2089 chandef->center_freq2 = 0;
Johannes Berg683b6d32012-11-08 21:25:48 +01002090
2091 /* Primary channel not allowed */
2092 if (!chandef->chan || chandef->chan->flags & IEEE80211_CHAN_DISABLED)
2093 return -EINVAL;
2094
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002095 if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]) {
2096 enum nl80211_channel_type chantype;
Johannes Berg683b6d32012-11-08 21:25:48 +01002097
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002098 chantype = nla_get_u32(
2099 info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]);
2100
2101 switch (chantype) {
2102 case NL80211_CHAN_NO_HT:
2103 case NL80211_CHAN_HT20:
2104 case NL80211_CHAN_HT40PLUS:
2105 case NL80211_CHAN_HT40MINUS:
2106 cfg80211_chandef_create(chandef, chandef->chan,
2107 chantype);
2108 break;
2109 default:
Johannes Berg683b6d32012-11-08 21:25:48 +01002110 return -EINVAL;
Johannes Berg683b6d32012-11-08 21:25:48 +01002111 }
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002112 } else if (info->attrs[NL80211_ATTR_CHANNEL_WIDTH]) {
2113 chandef->width =
2114 nla_get_u32(info->attrs[NL80211_ATTR_CHANNEL_WIDTH]);
2115 if (info->attrs[NL80211_ATTR_CENTER_FREQ1])
2116 chandef->center_freq1 =
2117 nla_get_u32(
2118 info->attrs[NL80211_ATTR_CENTER_FREQ1]);
2119 if (info->attrs[NL80211_ATTR_CENTER_FREQ2])
2120 chandef->center_freq2 =
2121 nla_get_u32(
2122 info->attrs[NL80211_ATTR_CENTER_FREQ2]);
2123 }
2124
Johannes Berg9f5e8f62012-11-22 16:59:45 +01002125 if (!cfg80211_chandef_valid(chandef))
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002126 return -EINVAL;
2127
Johannes Berg9f5e8f62012-11-22 16:59:45 +01002128 if (!cfg80211_chandef_usable(&rdev->wiphy, chandef,
2129 IEEE80211_CHAN_DISABLED))
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002130 return -EINVAL;
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002131
Simon Wunderlich2f301ab2013-05-16 13:00:28 +02002132 if ((chandef->width == NL80211_CHAN_WIDTH_5 ||
2133 chandef->width == NL80211_CHAN_WIDTH_10) &&
2134 !(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_5_10_MHZ))
2135 return -EINVAL;
2136
Johannes Berg683b6d32012-11-08 21:25:48 +01002137 return 0;
2138}
2139
Johannes Bergf444de02010-05-05 15:25:02 +02002140static int __nl80211_set_channel(struct cfg80211_registered_device *rdev,
Jouni Malinene16821b2014-04-28 11:22:08 +03002141 struct net_device *dev,
Johannes Bergf444de02010-05-05 15:25:02 +02002142 struct genl_info *info)
2143{
Johannes Berg683b6d32012-11-08 21:25:48 +01002144 struct cfg80211_chan_def chandef;
Johannes Bergf444de02010-05-05 15:25:02 +02002145 int result;
Johannes Berge8c9bd52012-06-06 08:18:22 +02002146 enum nl80211_iftype iftype = NL80211_IFTYPE_MONITOR;
Jouni Malinene16821b2014-04-28 11:22:08 +03002147 struct wireless_dev *wdev = NULL;
Johannes Berge8c9bd52012-06-06 08:18:22 +02002148
Jouni Malinene16821b2014-04-28 11:22:08 +03002149 if (dev)
2150 wdev = dev->ieee80211_ptr;
Johannes Bergf444de02010-05-05 15:25:02 +02002151 if (!nl80211_can_set_dev_channel(wdev))
2152 return -EOPNOTSUPP;
Jouni Malinene16821b2014-04-28 11:22:08 +03002153 if (wdev)
2154 iftype = wdev->iftype;
Johannes Bergf444de02010-05-05 15:25:02 +02002155
Johannes Berg683b6d32012-11-08 21:25:48 +01002156 result = nl80211_parse_chandef(rdev, info, &chandef);
2157 if (result)
2158 return result;
Johannes Bergf444de02010-05-05 15:25:02 +02002159
Johannes Berge8c9bd52012-06-06 08:18:22 +02002160 switch (iftype) {
Johannes Bergaa430da2012-05-16 23:50:18 +02002161 case NL80211_IFTYPE_AP:
2162 case NL80211_IFTYPE_P2P_GO:
Arik Nemtsov923b3522015-07-08 15:41:44 +03002163 if (!cfg80211_reg_can_beacon_relax(&rdev->wiphy, &chandef,
2164 iftype)) {
Johannes Bergaa430da2012-05-16 23:50:18 +02002165 result = -EINVAL;
2166 break;
2167 }
Jouni Malinene16821b2014-04-28 11:22:08 +03002168 if (wdev->beacon_interval) {
2169 if (!dev || !rdev->ops->set_ap_chanwidth ||
2170 !(rdev->wiphy.features &
2171 NL80211_FEATURE_AP_MODE_CHAN_WIDTH_CHANGE)) {
2172 result = -EBUSY;
2173 break;
2174 }
2175
2176 /* Only allow dynamic channel width changes */
2177 if (chandef.chan != wdev->preset_chandef.chan) {
2178 result = -EBUSY;
2179 break;
2180 }
2181 result = rdev_set_ap_chanwidth(rdev, dev, &chandef);
2182 if (result)
2183 break;
2184 }
Johannes Berg683b6d32012-11-08 21:25:48 +01002185 wdev->preset_chandef = chandef;
Johannes Bergaa430da2012-05-16 23:50:18 +02002186 result = 0;
2187 break;
Johannes Bergcc1d2802012-05-16 23:50:20 +02002188 case NL80211_IFTYPE_MESH_POINT:
Johannes Berg683b6d32012-11-08 21:25:48 +01002189 result = cfg80211_set_mesh_channel(rdev, wdev, &chandef);
Johannes Bergcc1d2802012-05-16 23:50:20 +02002190 break;
Johannes Berge8c9bd52012-06-06 08:18:22 +02002191 case NL80211_IFTYPE_MONITOR:
Johannes Berg683b6d32012-11-08 21:25:48 +01002192 result = cfg80211_set_monitor_channel(rdev, &chandef);
Johannes Berge8c9bd52012-06-06 08:18:22 +02002193 break;
Johannes Bergaa430da2012-05-16 23:50:18 +02002194 default:
Johannes Berge8c9bd52012-06-06 08:18:22 +02002195 result = -EINVAL;
Johannes Bergf444de02010-05-05 15:25:02 +02002196 }
Johannes Bergf444de02010-05-05 15:25:02 +02002197
2198 return result;
2199}
2200
2201static int nl80211_set_channel(struct sk_buff *skb, struct genl_info *info)
2202{
Johannes Berg4c476992010-10-04 21:36:35 +02002203 struct cfg80211_registered_device *rdev = info->user_ptr[0];
2204 struct net_device *netdev = info->user_ptr[1];
Johannes Bergf444de02010-05-05 15:25:02 +02002205
Jouni Malinene16821b2014-04-28 11:22:08 +03002206 return __nl80211_set_channel(rdev, netdev, info);
Johannes Bergf444de02010-05-05 15:25:02 +02002207}
2208
Bill Jordane8347eb2010-10-01 13:54:28 -04002209static int nl80211_set_wds_peer(struct sk_buff *skb, struct genl_info *info)
2210{
Johannes Berg43b19952010-10-07 13:10:30 +02002211 struct cfg80211_registered_device *rdev = info->user_ptr[0];
2212 struct net_device *dev = info->user_ptr[1];
2213 struct wireless_dev *wdev = dev->ieee80211_ptr;
Johannes Berg388ac772010-10-07 13:11:09 +02002214 const u8 *bssid;
Bill Jordane8347eb2010-10-01 13:54:28 -04002215
2216 if (!info->attrs[NL80211_ATTR_MAC])
2217 return -EINVAL;
2218
Johannes Berg43b19952010-10-07 13:10:30 +02002219 if (netif_running(dev))
2220 return -EBUSY;
Bill Jordane8347eb2010-10-01 13:54:28 -04002221
Johannes Berg43b19952010-10-07 13:10:30 +02002222 if (!rdev->ops->set_wds_peer)
2223 return -EOPNOTSUPP;
Bill Jordane8347eb2010-10-01 13:54:28 -04002224
Johannes Berg43b19952010-10-07 13:10:30 +02002225 if (wdev->iftype != NL80211_IFTYPE_WDS)
2226 return -EOPNOTSUPP;
Bill Jordane8347eb2010-10-01 13:54:28 -04002227
2228 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Hila Gonene35e4d22012-06-27 17:19:42 +03002229 return rdev_set_wds_peer(rdev, dev, bssid);
Bill Jordane8347eb2010-10-01 13:54:28 -04002230}
2231
Johannes Berg55682962007-09-20 13:09:35 -04002232static int nl80211_set_wiphy(struct sk_buff *skb, struct genl_info *info)
2233{
2234 struct cfg80211_registered_device *rdev;
Johannes Bergf444de02010-05-05 15:25:02 +02002235 struct net_device *netdev = NULL;
2236 struct wireless_dev *wdev;
Bill Jordana1e567c2010-09-10 11:22:32 -04002237 int result = 0, rem_txq_params = 0;
Jouni Malinen31888482008-10-30 16:59:24 +02002238 struct nlattr *nl_txq_params;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002239 u32 changed;
2240 u8 retry_short = 0, retry_long = 0;
2241 u32 frag_threshold = 0, rts_threshold = 0;
Lukáš Turek81077e82009-12-21 22:50:47 +01002242 u8 coverage_class = 0;
Johannes Berg55682962007-09-20 13:09:35 -04002243
Johannes Berg5fe231e2013-05-08 21:45:15 +02002244 ASSERT_RTNL();
2245
Johannes Bergf444de02010-05-05 15:25:02 +02002246 /*
2247 * Try to find the wiphy and netdev. Normally this
2248 * function shouldn't need the netdev, but this is
2249 * done for backward compatibility -- previously
2250 * setting the channel was done per wiphy, but now
2251 * it is per netdev. Previous userland like hostapd
2252 * also passed a netdev to set_wiphy, so that it is
2253 * possible to let that go to the right netdev!
2254 */
Johannes Berg4bbf4d52009-03-24 09:35:46 +01002255
Johannes Bergf444de02010-05-05 15:25:02 +02002256 if (info->attrs[NL80211_ATTR_IFINDEX]) {
2257 int ifindex = nla_get_u32(info->attrs[NL80211_ATTR_IFINDEX]);
2258
Ying Xue7f2b8562014-01-15 10:23:45 +08002259 netdev = __dev_get_by_index(genl_info_net(info), ifindex);
Johannes Berg5fe231e2013-05-08 21:45:15 +02002260 if (netdev && netdev->ieee80211_ptr)
Zhao, Gangf26cbf42014-04-21 12:53:03 +08002261 rdev = wiphy_to_rdev(netdev->ieee80211_ptr->wiphy);
Johannes Berg5fe231e2013-05-08 21:45:15 +02002262 else
Johannes Bergf444de02010-05-05 15:25:02 +02002263 netdev = NULL;
Johannes Berg4bbf4d52009-03-24 09:35:46 +01002264 }
2265
Johannes Bergf444de02010-05-05 15:25:02 +02002266 if (!netdev) {
Johannes Berg878d9ec2012-06-15 14:18:32 +02002267 rdev = __cfg80211_rdev_from_attrs(genl_info_net(info),
2268 info->attrs);
Johannes Berg5fe231e2013-05-08 21:45:15 +02002269 if (IS_ERR(rdev))
Johannes Berg4c476992010-10-04 21:36:35 +02002270 return PTR_ERR(rdev);
Johannes Bergf444de02010-05-05 15:25:02 +02002271 wdev = NULL;
2272 netdev = NULL;
2273 result = 0;
Johannes Berg71fe96b2012-10-24 10:04:58 +02002274 } else
Johannes Bergf444de02010-05-05 15:25:02 +02002275 wdev = netdev->ieee80211_ptr;
Johannes Bergf444de02010-05-05 15:25:02 +02002276
2277 /*
2278 * end workaround code, by now the rdev is available
2279 * and locked, and wdev may or may not be NULL.
2280 */
Johannes Berg4bbf4d52009-03-24 09:35:46 +01002281
2282 if (info->attrs[NL80211_ATTR_WIPHY_NAME])
Jouni Malinen31888482008-10-30 16:59:24 +02002283 result = cfg80211_dev_rename(
2284 rdev, nla_data(info->attrs[NL80211_ATTR_WIPHY_NAME]));
Johannes Berg4bbf4d52009-03-24 09:35:46 +01002285
Johannes Berg4bbf4d52009-03-24 09:35:46 +01002286 if (result)
Ying Xue7f2b8562014-01-15 10:23:45 +08002287 return result;
Johannes Berg55682962007-09-20 13:09:35 -04002288
Jouni Malinen31888482008-10-30 16:59:24 +02002289 if (info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS]) {
2290 struct ieee80211_txq_params txq_params;
2291 struct nlattr *tb[NL80211_TXQ_ATTR_MAX + 1];
2292
Ying Xue7f2b8562014-01-15 10:23:45 +08002293 if (!rdev->ops->set_txq_params)
2294 return -EOPNOTSUPP;
Jouni Malinen31888482008-10-30 16:59:24 +02002295
Ying Xue7f2b8562014-01-15 10:23:45 +08002296 if (!netdev)
2297 return -EINVAL;
Eliad Pellerf70f01c2011-09-25 20:06:53 +03002298
Johannes Berg133a3ff2011-11-03 14:50:13 +01002299 if (netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
Ying Xue7f2b8562014-01-15 10:23:45 +08002300 netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
2301 return -EINVAL;
Johannes Berg133a3ff2011-11-03 14:50:13 +01002302
Ying Xue7f2b8562014-01-15 10:23:45 +08002303 if (!netif_running(netdev))
2304 return -ENETDOWN;
Johannes Berg2b5f8b02012-04-02 10:51:55 +02002305
Jouni Malinen31888482008-10-30 16:59:24 +02002306 nla_for_each_nested(nl_txq_params,
2307 info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS],
2308 rem_txq_params) {
Johannes Bergbfe2c7b2016-10-26 14:42:21 +02002309 result = nla_parse_nested(tb, NL80211_TXQ_ATTR_MAX,
2310 nl_txq_params,
2311 txq_params_policy);
Johannes Bergae811e22014-01-24 10:17:47 +01002312 if (result)
2313 return result;
Jouni Malinen31888482008-10-30 16:59:24 +02002314 result = parse_txq_params(tb, &txq_params);
2315 if (result)
Ying Xue7f2b8562014-01-15 10:23:45 +08002316 return result;
Jouni Malinen31888482008-10-30 16:59:24 +02002317
Hila Gonene35e4d22012-06-27 17:19:42 +03002318 result = rdev_set_txq_params(rdev, netdev,
2319 &txq_params);
Jouni Malinen31888482008-10-30 16:59:24 +02002320 if (result)
Ying Xue7f2b8562014-01-15 10:23:45 +08002321 return result;
Jouni Malinen31888482008-10-30 16:59:24 +02002322 }
2323 }
2324
Jouni Malinen72bdcf32008-11-26 16:15:24 +02002325 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
Jouni Malinene16821b2014-04-28 11:22:08 +03002326 result = __nl80211_set_channel(
2327 rdev,
2328 nl80211_can_set_dev_channel(wdev) ? netdev : NULL,
2329 info);
Jouni Malinen72bdcf32008-11-26 16:15:24 +02002330 if (result)
Ying Xue7f2b8562014-01-15 10:23:45 +08002331 return result;
Jouni Malinen72bdcf32008-11-26 16:15:24 +02002332 }
2333
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03002334 if (info->attrs[NL80211_ATTR_WIPHY_TX_POWER_SETTING]) {
Johannes Bergc8442112012-10-24 10:17:18 +02002335 struct wireless_dev *txp_wdev = wdev;
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03002336 enum nl80211_tx_power_setting type;
2337 int idx, mbm = 0;
2338
Johannes Bergc8442112012-10-24 10:17:18 +02002339 if (!(rdev->wiphy.features & NL80211_FEATURE_VIF_TXPOWER))
2340 txp_wdev = NULL;
2341
Ying Xue7f2b8562014-01-15 10:23:45 +08002342 if (!rdev->ops->set_tx_power)
2343 return -EOPNOTSUPP;
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03002344
2345 idx = NL80211_ATTR_WIPHY_TX_POWER_SETTING;
2346 type = nla_get_u32(info->attrs[idx]);
2347
2348 if (!info->attrs[NL80211_ATTR_WIPHY_TX_POWER_LEVEL] &&
Ying Xue7f2b8562014-01-15 10:23:45 +08002349 (type != NL80211_TX_POWER_AUTOMATIC))
2350 return -EINVAL;
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03002351
2352 if (type != NL80211_TX_POWER_AUTOMATIC) {
2353 idx = NL80211_ATTR_WIPHY_TX_POWER_LEVEL;
2354 mbm = nla_get_u32(info->attrs[idx]);
2355 }
2356
Johannes Bergc8442112012-10-24 10:17:18 +02002357 result = rdev_set_tx_power(rdev, txp_wdev, type, mbm);
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03002358 if (result)
Ying Xue7f2b8562014-01-15 10:23:45 +08002359 return result;
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03002360 }
2361
Bruno Randolfafe0cbf2010-11-10 12:50:50 +09002362 if (info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX] &&
2363 info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]) {
2364 u32 tx_ant, rx_ant;
Kirtika Ruchandani7a087e72016-05-29 19:51:23 -07002365
Bruno Randolf7f531e02010-12-16 11:30:22 +09002366 if ((!rdev->wiphy.available_antennas_tx &&
2367 !rdev->wiphy.available_antennas_rx) ||
Ying Xue7f2b8562014-01-15 10:23:45 +08002368 !rdev->ops->set_antenna)
2369 return -EOPNOTSUPP;
Bruno Randolfafe0cbf2010-11-10 12:50:50 +09002370
2371 tx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX]);
2372 rx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]);
2373
Bruno Randolfa7ffac92010-12-08 13:59:24 +09002374 /* reject antenna configurations which don't match the
Bruno Randolf7f531e02010-12-16 11:30:22 +09002375 * available antenna masks, except for the "all" mask */
2376 if ((~tx_ant && (tx_ant & ~rdev->wiphy.available_antennas_tx)) ||
Ying Xue7f2b8562014-01-15 10:23:45 +08002377 (~rx_ant && (rx_ant & ~rdev->wiphy.available_antennas_rx)))
2378 return -EINVAL;
Bruno Randolfa7ffac92010-12-08 13:59:24 +09002379
Bruno Randolf7f531e02010-12-16 11:30:22 +09002380 tx_ant = tx_ant & rdev->wiphy.available_antennas_tx;
2381 rx_ant = rx_ant & rdev->wiphy.available_antennas_rx;
Bruno Randolfa7ffac92010-12-08 13:59:24 +09002382
Hila Gonene35e4d22012-06-27 17:19:42 +03002383 result = rdev_set_antenna(rdev, tx_ant, rx_ant);
Bruno Randolfafe0cbf2010-11-10 12:50:50 +09002384 if (result)
Ying Xue7f2b8562014-01-15 10:23:45 +08002385 return result;
Bruno Randolfafe0cbf2010-11-10 12:50:50 +09002386 }
2387
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002388 changed = 0;
2389
2390 if (info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]) {
2391 retry_short = nla_get_u8(
2392 info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]);
Ying Xue7f2b8562014-01-15 10:23:45 +08002393 if (retry_short == 0)
2394 return -EINVAL;
2395
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002396 changed |= WIPHY_PARAM_RETRY_SHORT;
2397 }
2398
2399 if (info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]) {
2400 retry_long = nla_get_u8(
2401 info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]);
Ying Xue7f2b8562014-01-15 10:23:45 +08002402 if (retry_long == 0)
2403 return -EINVAL;
2404
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002405 changed |= WIPHY_PARAM_RETRY_LONG;
2406 }
2407
2408 if (info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]) {
2409 frag_threshold = nla_get_u32(
2410 info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]);
Ying Xue7f2b8562014-01-15 10:23:45 +08002411 if (frag_threshold < 256)
2412 return -EINVAL;
2413
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002414 if (frag_threshold != (u32) -1) {
2415 /*
2416 * Fragments (apart from the last one) are required to
2417 * have even length. Make the fragmentation code
2418 * simpler by stripping LSB should someone try to use
2419 * odd threshold value.
2420 */
2421 frag_threshold &= ~0x1;
2422 }
2423 changed |= WIPHY_PARAM_FRAG_THRESHOLD;
2424 }
2425
2426 if (info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]) {
2427 rts_threshold = nla_get_u32(
2428 info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]);
2429 changed |= WIPHY_PARAM_RTS_THRESHOLD;
2430 }
2431
Lukáš Turek81077e82009-12-21 22:50:47 +01002432 if (info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]) {
Lorenzo Bianconi3057dbf2014-09-04 23:57:40 +02002433 if (info->attrs[NL80211_ATTR_WIPHY_DYN_ACK])
2434 return -EINVAL;
2435
Lukáš Turek81077e82009-12-21 22:50:47 +01002436 coverage_class = nla_get_u8(
2437 info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]);
2438 changed |= WIPHY_PARAM_COVERAGE_CLASS;
2439 }
2440
Lorenzo Bianconi3057dbf2014-09-04 23:57:40 +02002441 if (info->attrs[NL80211_ATTR_WIPHY_DYN_ACK]) {
2442 if (!(rdev->wiphy.features & NL80211_FEATURE_ACKTO_ESTIMATION))
2443 return -EOPNOTSUPP;
2444
2445 changed |= WIPHY_PARAM_DYN_ACK;
2446 }
2447
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002448 if (changed) {
2449 u8 old_retry_short, old_retry_long;
2450 u32 old_frag_threshold, old_rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01002451 u8 old_coverage_class;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002452
Ying Xue7f2b8562014-01-15 10:23:45 +08002453 if (!rdev->ops->set_wiphy_params)
2454 return -EOPNOTSUPP;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002455
2456 old_retry_short = rdev->wiphy.retry_short;
2457 old_retry_long = rdev->wiphy.retry_long;
2458 old_frag_threshold = rdev->wiphy.frag_threshold;
2459 old_rts_threshold = rdev->wiphy.rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01002460 old_coverage_class = rdev->wiphy.coverage_class;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002461
2462 if (changed & WIPHY_PARAM_RETRY_SHORT)
2463 rdev->wiphy.retry_short = retry_short;
2464 if (changed & WIPHY_PARAM_RETRY_LONG)
2465 rdev->wiphy.retry_long = retry_long;
2466 if (changed & WIPHY_PARAM_FRAG_THRESHOLD)
2467 rdev->wiphy.frag_threshold = frag_threshold;
2468 if (changed & WIPHY_PARAM_RTS_THRESHOLD)
2469 rdev->wiphy.rts_threshold = rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01002470 if (changed & WIPHY_PARAM_COVERAGE_CLASS)
2471 rdev->wiphy.coverage_class = coverage_class;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002472
Hila Gonene35e4d22012-06-27 17:19:42 +03002473 result = rdev_set_wiphy_params(rdev, changed);
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002474 if (result) {
2475 rdev->wiphy.retry_short = old_retry_short;
2476 rdev->wiphy.retry_long = old_retry_long;
2477 rdev->wiphy.frag_threshold = old_frag_threshold;
2478 rdev->wiphy.rts_threshold = old_rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01002479 rdev->wiphy.coverage_class = old_coverage_class;
Michal Kazior9189ee32015-08-03 10:55:24 +02002480 return result;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002481 }
2482 }
Ying Xue7f2b8562014-01-15 10:23:45 +08002483 return 0;
Johannes Berg55682962007-09-20 13:09:35 -04002484}
2485
Johannes Berg71bbc992012-06-15 15:30:18 +02002486static inline u64 wdev_id(struct wireless_dev *wdev)
2487{
2488 return (u64)wdev->identifier |
Zhao, Gangf26cbf42014-04-21 12:53:03 +08002489 ((u64)wiphy_to_rdev(wdev->wiphy)->wiphy_idx << 32);
Johannes Berg71bbc992012-06-15 15:30:18 +02002490}
Johannes Berg55682962007-09-20 13:09:35 -04002491
Johannes Berg683b6d32012-11-08 21:25:48 +01002492static int nl80211_send_chandef(struct sk_buff *msg,
Janusz Dziedzicd2859df2013-11-06 13:55:51 +01002493 const struct cfg80211_chan_def *chandef)
Johannes Berg683b6d32012-11-08 21:25:48 +01002494{
Johannes Berg601555c2014-11-27 17:26:56 +01002495 if (WARN_ON(!cfg80211_chandef_valid(chandef)))
2496 return -EINVAL;
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002497
Johannes Berg683b6d32012-11-08 21:25:48 +01002498 if (nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ,
2499 chandef->chan->center_freq))
2500 return -ENOBUFS;
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002501 switch (chandef->width) {
2502 case NL80211_CHAN_WIDTH_20_NOHT:
2503 case NL80211_CHAN_WIDTH_20:
2504 case NL80211_CHAN_WIDTH_40:
2505 if (nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE,
2506 cfg80211_get_chandef_type(chandef)))
2507 return -ENOBUFS;
2508 break;
2509 default:
2510 break;
2511 }
2512 if (nla_put_u32(msg, NL80211_ATTR_CHANNEL_WIDTH, chandef->width))
2513 return -ENOBUFS;
2514 if (nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ1, chandef->center_freq1))
2515 return -ENOBUFS;
2516 if (chandef->center_freq2 &&
2517 nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ2, chandef->center_freq2))
Johannes Berg683b6d32012-11-08 21:25:48 +01002518 return -ENOBUFS;
2519 return 0;
2520}
2521
Eric W. Biederman15e47302012-09-07 20:12:54 +00002522static int nl80211_send_iface(struct sk_buff *msg, u32 portid, u32 seq, int flags,
Johannes Bergd7264052009-04-19 16:23:20 +02002523 struct cfg80211_registered_device *rdev,
Tomasz Bursztyka8f894be2014-11-12 16:26:45 +02002524 struct wireless_dev *wdev, bool removal)
Johannes Berg55682962007-09-20 13:09:35 -04002525{
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002526 struct net_device *dev = wdev->netdev;
Tomasz Bursztyka8f894be2014-11-12 16:26:45 +02002527 u8 cmd = NL80211_CMD_NEW_INTERFACE;
Johannes Berg55682962007-09-20 13:09:35 -04002528 void *hdr;
2529
Tomasz Bursztyka8f894be2014-11-12 16:26:45 +02002530 if (removal)
2531 cmd = NL80211_CMD_DEL_INTERFACE;
2532
2533 hdr = nl80211hdr_put(msg, portid, seq, flags, cmd);
Johannes Berg55682962007-09-20 13:09:35 -04002534 if (!hdr)
2535 return -1;
2536
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002537 if (dev &&
2538 (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
Johannes Berg98104fde2012-06-16 00:19:54 +02002539 nla_put_string(msg, NL80211_ATTR_IFNAME, dev->name)))
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002540 goto nla_put_failure;
2541
2542 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
2543 nla_put_u32(msg, NL80211_ATTR_IFTYPE, wdev->iftype) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02002544 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
2545 NL80211_ATTR_PAD) ||
Johannes Berg98104fde2012-06-16 00:19:54 +02002546 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, wdev_address(wdev)) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04002547 nla_put_u32(msg, NL80211_ATTR_GENERATION,
2548 rdev->devlist_generation ^
2549 (cfg80211_rdev_list_generation << 2)))
2550 goto nla_put_failure;
Johannes Bergf5ea9122009-08-07 16:17:38 +02002551
Johannes Berg5b7ccaf2012-07-12 19:45:08 +02002552 if (rdev->ops->get_channel) {
Johannes Berg683b6d32012-11-08 21:25:48 +01002553 int ret;
2554 struct cfg80211_chan_def chandef;
Johannes Berg5b7ccaf2012-07-12 19:45:08 +02002555
Johannes Berg683b6d32012-11-08 21:25:48 +01002556 ret = rdev_get_channel(rdev, wdev, &chandef);
2557 if (ret == 0) {
2558 if (nl80211_send_chandef(msg, &chandef))
2559 goto nla_put_failure;
2560 }
Pontus Fuchsd91df0e2012-04-03 16:39:58 +02002561 }
2562
Rafał Miłeckid55d0d52015-08-31 22:59:38 +02002563 if (rdev->ops->get_tx_power) {
2564 int dbm, ret;
2565
2566 ret = rdev_get_tx_power(rdev, wdev, &dbm);
2567 if (ret == 0 &&
2568 nla_put_u32(msg, NL80211_ATTR_WIPHY_TX_POWER_LEVEL,
2569 DBM_TO_MBM(dbm)))
2570 goto nla_put_failure;
2571 }
2572
Antonio Quartullib84e7a02012-11-07 12:52:20 +01002573 if (wdev->ssid_len) {
2574 if (nla_put(msg, NL80211_ATTR_SSID, wdev->ssid_len, wdev->ssid))
2575 goto nla_put_failure;
2576 }
2577
Johannes Berg053c0952015-01-16 22:09:00 +01002578 genlmsg_end(msg, hdr);
2579 return 0;
Johannes Berg55682962007-09-20 13:09:35 -04002580
2581 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07002582 genlmsg_cancel(msg, hdr);
2583 return -EMSGSIZE;
Johannes Berg55682962007-09-20 13:09:35 -04002584}
2585
2586static int nl80211_dump_interface(struct sk_buff *skb, struct netlink_callback *cb)
2587{
2588 int wp_idx = 0;
2589 int if_idx = 0;
2590 int wp_start = cb->args[0];
2591 int if_start = cb->args[1];
Denis Kenziorb7fb44d2016-08-03 17:02:15 -05002592 int filter_wiphy = -1;
Johannes Bergf5ea9122009-08-07 16:17:38 +02002593 struct cfg80211_registered_device *rdev;
Johannes Berg55682962007-09-20 13:09:35 -04002594 struct wireless_dev *wdev;
Johannes Bergea90e0d2017-03-15 14:26:04 +01002595 int ret;
Johannes Berg55682962007-09-20 13:09:35 -04002596
Johannes Berg5fe231e2013-05-08 21:45:15 +02002597 rtnl_lock();
Denis Kenziorb7fb44d2016-08-03 17:02:15 -05002598 if (!cb->args[2]) {
2599 struct nl80211_dump_wiphy_state state = {
2600 .filter_wiphy = -1,
2601 };
Denis Kenziorb7fb44d2016-08-03 17:02:15 -05002602
2603 ret = nl80211_dump_wiphy_parse(skb, cb, &state);
2604 if (ret)
Johannes Bergea90e0d2017-03-15 14:26:04 +01002605 goto out_unlock;
Denis Kenziorb7fb44d2016-08-03 17:02:15 -05002606
2607 filter_wiphy = state.filter_wiphy;
2608
2609 /*
2610 * if filtering, set cb->args[2] to +1 since 0 is the default
2611 * value needed to determine that parsing is necessary.
2612 */
2613 if (filter_wiphy >= 0)
2614 cb->args[2] = filter_wiphy + 1;
2615 else
2616 cb->args[2] = -1;
2617 } else if (cb->args[2] > 0) {
2618 filter_wiphy = cb->args[2] - 1;
2619 }
2620
Johannes Bergf5ea9122009-08-07 16:17:38 +02002621 list_for_each_entry(rdev, &cfg80211_rdev_list, list) {
2622 if (!net_eq(wiphy_net(&rdev->wiphy), sock_net(skb->sk)))
Johannes Berg463d0182009-07-14 00:33:35 +02002623 continue;
Johannes Bergbba95fe2008-07-29 13:22:51 +02002624 if (wp_idx < wp_start) {
2625 wp_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04002626 continue;
Johannes Bergbba95fe2008-07-29 13:22:51 +02002627 }
Denis Kenziorb7fb44d2016-08-03 17:02:15 -05002628
2629 if (filter_wiphy >= 0 && filter_wiphy != rdev->wiphy_idx)
2630 continue;
2631
Johannes Berg55682962007-09-20 13:09:35 -04002632 if_idx = 0;
2633
Johannes Berg53873f12016-05-03 16:52:04 +03002634 list_for_each_entry(wdev, &rdev->wiphy.wdev_list, list) {
Johannes Bergbba95fe2008-07-29 13:22:51 +02002635 if (if_idx < if_start) {
2636 if_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04002637 continue;
Johannes Bergbba95fe2008-07-29 13:22:51 +02002638 }
Eric W. Biederman15e47302012-09-07 20:12:54 +00002639 if (nl80211_send_iface(skb, NETLINK_CB(cb->skb).portid,
Johannes Berg55682962007-09-20 13:09:35 -04002640 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Tomasz Bursztyka8f894be2014-11-12 16:26:45 +02002641 rdev, wdev, false) < 0) {
Johannes Bergbba95fe2008-07-29 13:22:51 +02002642 goto out;
2643 }
2644 if_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04002645 }
Johannes Bergbba95fe2008-07-29 13:22:51 +02002646
2647 wp_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04002648 }
Johannes Bergbba95fe2008-07-29 13:22:51 +02002649 out:
Johannes Berg55682962007-09-20 13:09:35 -04002650 cb->args[0] = wp_idx;
2651 cb->args[1] = if_idx;
2652
Johannes Bergea90e0d2017-03-15 14:26:04 +01002653 ret = skb->len;
2654 out_unlock:
2655 rtnl_unlock();
2656
2657 return ret;
Johannes Berg55682962007-09-20 13:09:35 -04002658}
2659
2660static int nl80211_get_interface(struct sk_buff *skb, struct genl_info *info)
2661{
2662 struct sk_buff *msg;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002663 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002664 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg55682962007-09-20 13:09:35 -04002665
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07002666 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -04002667 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02002668 return -ENOMEM;
Johannes Berg55682962007-09-20 13:09:35 -04002669
Eric W. Biederman15e47302012-09-07 20:12:54 +00002670 if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0,
Tomasz Bursztyka8f894be2014-11-12 16:26:45 +02002671 rdev, wdev, false) < 0) {
Johannes Berg4c476992010-10-04 21:36:35 +02002672 nlmsg_free(msg);
2673 return -ENOBUFS;
2674 }
Johannes Berg55682962007-09-20 13:09:35 -04002675
Johannes Berg134e6372009-07-10 09:51:34 +00002676 return genlmsg_reply(msg, info);
Johannes Berg55682962007-09-20 13:09:35 -04002677}
2678
Michael Wu66f7ac52008-01-31 19:48:22 +01002679static const struct nla_policy mntr_flags_policy[NL80211_MNTR_FLAG_MAX + 1] = {
2680 [NL80211_MNTR_FLAG_FCSFAIL] = { .type = NLA_FLAG },
2681 [NL80211_MNTR_FLAG_PLCPFAIL] = { .type = NLA_FLAG },
2682 [NL80211_MNTR_FLAG_CONTROL] = { .type = NLA_FLAG },
2683 [NL80211_MNTR_FLAG_OTHER_BSS] = { .type = NLA_FLAG },
2684 [NL80211_MNTR_FLAG_COOK_FRAMES] = { .type = NLA_FLAG },
Felix Fietkaue057d3c2013-05-28 13:01:52 +02002685 [NL80211_MNTR_FLAG_ACTIVE] = { .type = NLA_FLAG },
Michael Wu66f7ac52008-01-31 19:48:22 +01002686};
2687
2688static int parse_monitor_flags(struct nlattr *nla, u32 *mntrflags)
2689{
2690 struct nlattr *flags[NL80211_MNTR_FLAG_MAX + 1];
2691 int flag;
2692
2693 *mntrflags = 0;
2694
2695 if (!nla)
2696 return -EINVAL;
2697
2698 if (nla_parse_nested(flags, NL80211_MNTR_FLAG_MAX,
2699 nla, mntr_flags_policy))
2700 return -EINVAL;
2701
2702 for (flag = 1; flag <= NL80211_MNTR_FLAG_MAX; flag++)
2703 if (flags[flag])
2704 *mntrflags |= (1<<flag);
2705
2706 return 0;
2707}
2708
Johannes Berg9bc383d2009-11-19 11:55:19 +01002709static int nl80211_valid_4addr(struct cfg80211_registered_device *rdev,
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002710 struct net_device *netdev, u8 use_4addr,
2711 enum nl80211_iftype iftype)
Johannes Berg9bc383d2009-11-19 11:55:19 +01002712{
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002713 if (!use_4addr) {
Jiri Pirkof350a0a82010-06-15 06:50:45 +00002714 if (netdev && (netdev->priv_flags & IFF_BRIDGE_PORT))
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002715 return -EBUSY;
Johannes Berg9bc383d2009-11-19 11:55:19 +01002716 return 0;
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002717 }
Johannes Berg9bc383d2009-11-19 11:55:19 +01002718
2719 switch (iftype) {
2720 case NL80211_IFTYPE_AP_VLAN:
2721 if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_AP)
2722 return 0;
2723 break;
2724 case NL80211_IFTYPE_STATION:
2725 if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_STATION)
2726 return 0;
2727 break;
2728 default:
2729 break;
2730 }
2731
2732 return -EOPNOTSUPP;
2733}
2734
Johannes Berg55682962007-09-20 13:09:35 -04002735static int nl80211_set_interface(struct sk_buff *skb, struct genl_info *info)
2736{
Johannes Berg4c476992010-10-04 21:36:35 +02002737 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002738 struct vif_params params;
Johannes Berge36d56b2009-06-09 21:04:43 +02002739 int err;
Johannes Berg04a773a2009-04-19 21:24:32 +02002740 enum nl80211_iftype otype, ntype;
Johannes Berg4c476992010-10-04 21:36:35 +02002741 struct net_device *dev = info->user_ptr[1];
Johannes Berg92ffe052008-09-16 20:39:36 +02002742 u32 _flags, *flags = NULL;
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002743 bool change = false;
Johannes Berg55682962007-09-20 13:09:35 -04002744
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002745 memset(&params, 0, sizeof(params));
2746
Johannes Berg04a773a2009-04-19 21:24:32 +02002747 otype = ntype = dev->ieee80211_ptr->iftype;
Johannes Berg55682962007-09-20 13:09:35 -04002748
Johannes Berg723b0382008-09-16 20:22:09 +02002749 if (info->attrs[NL80211_ATTR_IFTYPE]) {
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002750 ntype = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]);
Johannes Berg04a773a2009-04-19 21:24:32 +02002751 if (otype != ntype)
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002752 change = true;
Johannes Berg4c476992010-10-04 21:36:35 +02002753 if (ntype > NL80211_IFTYPE_MAX)
2754 return -EINVAL;
Johannes Berg723b0382008-09-16 20:22:09 +02002755 }
2756
Johannes Berg92ffe052008-09-16 20:39:36 +02002757 if (info->attrs[NL80211_ATTR_MESH_ID]) {
Johannes Berg29cbe682010-12-03 09:20:44 +01002758 struct wireless_dev *wdev = dev->ieee80211_ptr;
2759
Johannes Berg4c476992010-10-04 21:36:35 +02002760 if (ntype != NL80211_IFTYPE_MESH_POINT)
2761 return -EINVAL;
Johannes Berg29cbe682010-12-03 09:20:44 +01002762 if (netif_running(dev))
2763 return -EBUSY;
2764
2765 wdev_lock(wdev);
2766 BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN !=
2767 IEEE80211_MAX_MESH_ID_LEN);
2768 wdev->mesh_id_up_len =
2769 nla_len(info->attrs[NL80211_ATTR_MESH_ID]);
2770 memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]),
2771 wdev->mesh_id_up_len);
2772 wdev_unlock(wdev);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002773 }
2774
Felix Fietkau8b787642009-11-10 18:53:10 +01002775 if (info->attrs[NL80211_ATTR_4ADDR]) {
2776 params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]);
2777 change = true;
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002778 err = nl80211_valid_4addr(rdev, dev, params.use_4addr, ntype);
Johannes Berg9bc383d2009-11-19 11:55:19 +01002779 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02002780 return err;
Felix Fietkau8b787642009-11-10 18:53:10 +01002781 } else {
2782 params.use_4addr = -1;
2783 }
2784
Johannes Berg92ffe052008-09-16 20:39:36 +02002785 if (info->attrs[NL80211_ATTR_MNTR_FLAGS]) {
Johannes Berg4c476992010-10-04 21:36:35 +02002786 if (ntype != NL80211_IFTYPE_MONITOR)
2787 return -EINVAL;
Johannes Berg92ffe052008-09-16 20:39:36 +02002788 err = parse_monitor_flags(info->attrs[NL80211_ATTR_MNTR_FLAGS],
2789 &_flags);
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002790 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02002791 return err;
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002792
2793 flags = &_flags;
2794 change = true;
Johannes Berg92ffe052008-09-16 20:39:36 +02002795 }
Johannes Berg3b858752009-03-12 09:55:09 +01002796
Aviya Erenfeldc6e6a0c2016-07-05 15:23:08 +03002797 if (info->attrs[NL80211_ATTR_MU_MIMO_GROUP_DATA]) {
2798 const u8 *mumimo_groups;
2799 u32 cap_flag = NL80211_EXT_FEATURE_MU_MIMO_AIR_SNIFFER;
2800
2801 if (!wiphy_ext_feature_isset(&rdev->wiphy, cap_flag))
2802 return -EOPNOTSUPP;
2803
2804 mumimo_groups =
2805 nla_data(info->attrs[NL80211_ATTR_MU_MIMO_GROUP_DATA]);
2806
2807 /* bits 0 and 63 are reserved and must be zero */
2808 if ((mumimo_groups[0] & BIT(7)) ||
2809 (mumimo_groups[VHT_MUMIMO_GROUPS_DATA_LEN - 1] & BIT(0)))
2810 return -EINVAL;
2811
2812 memcpy(params.vht_mumimo_groups, mumimo_groups,
2813 VHT_MUMIMO_GROUPS_DATA_LEN);
2814 change = true;
2815 }
2816
2817 if (info->attrs[NL80211_ATTR_MU_MIMO_FOLLOW_MAC_ADDR]) {
2818 u32 cap_flag = NL80211_EXT_FEATURE_MU_MIMO_AIR_SNIFFER;
2819
2820 if (!wiphy_ext_feature_isset(&rdev->wiphy, cap_flag))
2821 return -EOPNOTSUPP;
2822
2823 nla_memcpy(params.macaddr,
2824 info->attrs[NL80211_ATTR_MU_MIMO_FOLLOW_MAC_ADDR],
2825 ETH_ALEN);
2826 change = true;
2827 }
2828
Luciano Coelho18003292013-08-29 13:26:57 +03002829 if (flags && (*flags & MONITOR_FLAG_ACTIVE) &&
Felix Fietkaue057d3c2013-05-28 13:01:52 +02002830 !(rdev->wiphy.features & NL80211_FEATURE_ACTIVE_MONITOR))
2831 return -EOPNOTSUPP;
2832
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002833 if (change)
Johannes Berg3d54d252009-08-21 14:51:05 +02002834 err = cfg80211_change_iface(rdev, dev, ntype, flags, &params);
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002835 else
2836 err = 0;
Johannes Berg60719ff2008-09-16 14:55:09 +02002837
Johannes Berg9bc383d2009-11-19 11:55:19 +01002838 if (!err && params.use_4addr != -1)
2839 dev->ieee80211_ptr->use_4addr = params.use_4addr;
2840
Johannes Berg55682962007-09-20 13:09:35 -04002841 return err;
2842}
2843
2844static int nl80211_new_interface(struct sk_buff *skb, struct genl_info *info)
2845{
Johannes Berg4c476992010-10-04 21:36:35 +02002846 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002847 struct vif_params params;
Johannes Berg84efbb82012-06-16 00:00:26 +02002848 struct wireless_dev *wdev;
Denis Kenzior896ff062016-08-03 16:58:33 -05002849 struct sk_buff *msg;
Johannes Berg55682962007-09-20 13:09:35 -04002850 int err;
2851 enum nl80211_iftype type = NL80211_IFTYPE_UNSPECIFIED;
Michael Wu66f7ac52008-01-31 19:48:22 +01002852 u32 flags;
Johannes Berg55682962007-09-20 13:09:35 -04002853
Johannes Berg78f22b62014-03-24 17:57:27 +01002854 /* to avoid failing a new interface creation due to pending removal */
2855 cfg80211_destroy_ifaces(rdev);
2856
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002857 memset(&params, 0, sizeof(params));
2858
Johannes Berg55682962007-09-20 13:09:35 -04002859 if (!info->attrs[NL80211_ATTR_IFNAME])
2860 return -EINVAL;
2861
2862 if (info->attrs[NL80211_ATTR_IFTYPE]) {
2863 type = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]);
2864 if (type > NL80211_IFTYPE_MAX)
2865 return -EINVAL;
2866 }
2867
Johannes Berg79c97e92009-07-07 03:56:12 +02002868 if (!rdev->ops->add_virtual_intf ||
Johannes Berg4c476992010-10-04 21:36:35 +02002869 !(rdev->wiphy.interface_modes & (1 << type)))
2870 return -EOPNOTSUPP;
Johannes Berg55682962007-09-20 13:09:35 -04002871
Ayala Bekercb3b7d82016-09-20 17:31:13 +03002872 if ((type == NL80211_IFTYPE_P2P_DEVICE || type == NL80211_IFTYPE_NAN ||
Ben Greeare8f479b2014-10-22 12:23:05 -07002873 rdev->wiphy.features & NL80211_FEATURE_MAC_ON_CREATE) &&
2874 info->attrs[NL80211_ATTR_MAC]) {
Arend van Spriel1c18f142013-01-08 10:17:27 +01002875 nla_memcpy(params.macaddr, info->attrs[NL80211_ATTR_MAC],
2876 ETH_ALEN);
2877 if (!is_valid_ether_addr(params.macaddr))
2878 return -EADDRNOTAVAIL;
2879 }
2880
Johannes Berg9bc383d2009-11-19 11:55:19 +01002881 if (info->attrs[NL80211_ATTR_4ADDR]) {
Felix Fietkau8b787642009-11-10 18:53:10 +01002882 params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]);
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002883 err = nl80211_valid_4addr(rdev, NULL, params.use_4addr, type);
Johannes Berg9bc383d2009-11-19 11:55:19 +01002884 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02002885 return err;
Johannes Berg9bc383d2009-11-19 11:55:19 +01002886 }
Felix Fietkau8b787642009-11-10 18:53:10 +01002887
Michael Wu66f7ac52008-01-31 19:48:22 +01002888 err = parse_monitor_flags(type == NL80211_IFTYPE_MONITOR ?
2889 info->attrs[NL80211_ATTR_MNTR_FLAGS] : NULL,
2890 &flags);
Felix Fietkaue057d3c2013-05-28 13:01:52 +02002891
Luciano Coelho18003292013-08-29 13:26:57 +03002892 if (!err && (flags & MONITOR_FLAG_ACTIVE) &&
Felix Fietkaue057d3c2013-05-28 13:01:52 +02002893 !(rdev->wiphy.features & NL80211_FEATURE_ACTIVE_MONITOR))
2894 return -EOPNOTSUPP;
2895
Johannes Berga18c7192015-02-24 10:56:42 +01002896 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
2897 if (!msg)
2898 return -ENOMEM;
2899
Hila Gonene35e4d22012-06-27 17:19:42 +03002900 wdev = rdev_add_virtual_intf(rdev,
2901 nla_data(info->attrs[NL80211_ATTR_IFNAME]),
Tom Gundersen6bab2e192015-03-18 11:13:39 +01002902 NET_NAME_USER, type, err ? NULL : &flags,
2903 &params);
Rafał Miłeckid687cbb2014-11-14 18:43:28 +01002904 if (WARN_ON(!wdev)) {
2905 nlmsg_free(msg);
2906 return -EPROTO;
2907 } else if (IS_ERR(wdev)) {
Johannes Berg1c90f9d2012-06-16 00:05:37 +02002908 nlmsg_free(msg);
Johannes Berg84efbb82012-06-16 00:00:26 +02002909 return PTR_ERR(wdev);
Johannes Berg1c90f9d2012-06-16 00:05:37 +02002910 }
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002911
Jukka Rissanen18e5ca62014-11-13 17:25:14 +02002912 if (info->attrs[NL80211_ATTR_SOCKET_OWNER])
Johannes Berg78f22b62014-03-24 17:57:27 +01002913 wdev->owner_nlportid = info->snd_portid;
2914
Johannes Berg98104fde2012-06-16 00:19:54 +02002915 switch (type) {
2916 case NL80211_IFTYPE_MESH_POINT:
2917 if (!info->attrs[NL80211_ATTR_MESH_ID])
2918 break;
Johannes Berg29cbe682010-12-03 09:20:44 +01002919 wdev_lock(wdev);
2920 BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN !=
2921 IEEE80211_MAX_MESH_ID_LEN);
2922 wdev->mesh_id_up_len =
2923 nla_len(info->attrs[NL80211_ATTR_MESH_ID]);
2924 memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]),
2925 wdev->mesh_id_up_len);
2926 wdev_unlock(wdev);
Johannes Berg98104fde2012-06-16 00:19:54 +02002927 break;
Ayala Bekercb3b7d82016-09-20 17:31:13 +03002928 case NL80211_IFTYPE_NAN:
Johannes Berg98104fde2012-06-16 00:19:54 +02002929 case NL80211_IFTYPE_P2P_DEVICE:
2930 /*
Ayala Bekercb3b7d82016-09-20 17:31:13 +03002931 * P2P Device and NAN do not have a netdev, so don't go
Johannes Berg98104fde2012-06-16 00:19:54 +02002932 * through the netdev notifier and must be added here
2933 */
2934 mutex_init(&wdev->mtx);
2935 INIT_LIST_HEAD(&wdev->event_list);
2936 spin_lock_init(&wdev->event_lock);
2937 INIT_LIST_HEAD(&wdev->mgmt_registrations);
2938 spin_lock_init(&wdev->mgmt_registrations_lock);
2939
Johannes Berg98104fde2012-06-16 00:19:54 +02002940 wdev->identifier = ++rdev->wdev_id;
Johannes Berg53873f12016-05-03 16:52:04 +03002941 list_add_rcu(&wdev->list, &rdev->wiphy.wdev_list);
Johannes Berg98104fde2012-06-16 00:19:54 +02002942 rdev->devlist_generation++;
Johannes Berg98104fde2012-06-16 00:19:54 +02002943 break;
2944 default:
2945 break;
Johannes Berg29cbe682010-12-03 09:20:44 +01002946 }
2947
Eric W. Biederman15e47302012-09-07 20:12:54 +00002948 if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0,
Tomasz Bursztyka8f894be2014-11-12 16:26:45 +02002949 rdev, wdev, false) < 0) {
Johannes Berg1c90f9d2012-06-16 00:05:37 +02002950 nlmsg_free(msg);
2951 return -ENOBUFS;
2952 }
2953
Denis Kenzior896ff062016-08-03 16:58:33 -05002954 /*
2955 * For wdevs which have no associated netdev object (e.g. of type
2956 * NL80211_IFTYPE_P2P_DEVICE), emit the NEW_INTERFACE event here.
2957 * For all other types, the event will be generated from the
2958 * netdev notifier
2959 */
2960 if (!wdev->netdev)
2961 nl80211_notify_iface(rdev, wdev, NL80211_CMD_NEW_INTERFACE);
Tomasz Bursztyka8f894be2014-11-12 16:26:45 +02002962
Johannes Berg1c90f9d2012-06-16 00:05:37 +02002963 return genlmsg_reply(msg, info);
Johannes Berg55682962007-09-20 13:09:35 -04002964}
2965
2966static int nl80211_del_interface(struct sk_buff *skb, struct genl_info *info)
2967{
Johannes Berg4c476992010-10-04 21:36:35 +02002968 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg84efbb82012-06-16 00:00:26 +02002969 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg55682962007-09-20 13:09:35 -04002970
Johannes Berg4c476992010-10-04 21:36:35 +02002971 if (!rdev->ops->del_virtual_intf)
2972 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01002973
Johannes Berg84efbb82012-06-16 00:00:26 +02002974 /*
2975 * If we remove a wireless device without a netdev then clear
2976 * user_ptr[1] so that nl80211_post_doit won't dereference it
2977 * to check if it needs to do dev_put(). Otherwise it crashes
2978 * since the wdev has been freed, unlike with a netdev where
2979 * we need the dev_put() for the netdev to really be freed.
2980 */
2981 if (!wdev->netdev)
2982 info->user_ptr[1] = NULL;
2983
Denis Kenzior7f8ed012016-08-03 16:58:35 -05002984 return rdev_del_virtual_intf(rdev, wdev);
Johannes Berg55682962007-09-20 13:09:35 -04002985}
2986
Simon Wunderlich1d9d9212011-11-18 14:20:43 +01002987static int nl80211_set_noack_map(struct sk_buff *skb, struct genl_info *info)
2988{
2989 struct cfg80211_registered_device *rdev = info->user_ptr[0];
2990 struct net_device *dev = info->user_ptr[1];
2991 u16 noack_map;
2992
2993 if (!info->attrs[NL80211_ATTR_NOACK_MAP])
2994 return -EINVAL;
2995
2996 if (!rdev->ops->set_noack_map)
2997 return -EOPNOTSUPP;
2998
2999 noack_map = nla_get_u16(info->attrs[NL80211_ATTR_NOACK_MAP]);
3000
Hila Gonene35e4d22012-06-27 17:19:42 +03003001 return rdev_set_noack_map(rdev, dev, noack_map);
Simon Wunderlich1d9d9212011-11-18 14:20:43 +01003002}
3003
Johannes Berg41ade002007-12-19 02:03:29 +01003004struct get_key_cookie {
3005 struct sk_buff *msg;
3006 int error;
Johannes Bergb9454e82009-07-08 13:29:08 +02003007 int idx;
Johannes Berg41ade002007-12-19 02:03:29 +01003008};
3009
3010static void get_key_callback(void *c, struct key_params *params)
3011{
Johannes Bergb9454e82009-07-08 13:29:08 +02003012 struct nlattr *key;
Johannes Berg41ade002007-12-19 02:03:29 +01003013 struct get_key_cookie *cookie = c;
3014
David S. Miller9360ffd2012-03-29 04:41:26 -04003015 if ((params->key &&
3016 nla_put(cookie->msg, NL80211_ATTR_KEY_DATA,
3017 params->key_len, params->key)) ||
3018 (params->seq &&
3019 nla_put(cookie->msg, NL80211_ATTR_KEY_SEQ,
3020 params->seq_len, params->seq)) ||
3021 (params->cipher &&
3022 nla_put_u32(cookie->msg, NL80211_ATTR_KEY_CIPHER,
3023 params->cipher)))
3024 goto nla_put_failure;
Johannes Berg41ade002007-12-19 02:03:29 +01003025
Johannes Bergb9454e82009-07-08 13:29:08 +02003026 key = nla_nest_start(cookie->msg, NL80211_ATTR_KEY);
3027 if (!key)
3028 goto nla_put_failure;
3029
David S. Miller9360ffd2012-03-29 04:41:26 -04003030 if ((params->key &&
3031 nla_put(cookie->msg, NL80211_KEY_DATA,
3032 params->key_len, params->key)) ||
3033 (params->seq &&
3034 nla_put(cookie->msg, NL80211_KEY_SEQ,
3035 params->seq_len, params->seq)) ||
3036 (params->cipher &&
3037 nla_put_u32(cookie->msg, NL80211_KEY_CIPHER,
3038 params->cipher)))
3039 goto nla_put_failure;
Johannes Bergb9454e82009-07-08 13:29:08 +02003040
David S. Miller9360ffd2012-03-29 04:41:26 -04003041 if (nla_put_u8(cookie->msg, NL80211_ATTR_KEY_IDX, cookie->idx))
3042 goto nla_put_failure;
Johannes Bergb9454e82009-07-08 13:29:08 +02003043
3044 nla_nest_end(cookie->msg, key);
3045
Johannes Berg41ade002007-12-19 02:03:29 +01003046 return;
3047 nla_put_failure:
3048 cookie->error = 1;
3049}
3050
3051static int nl80211_get_key(struct sk_buff *skb, struct genl_info *info)
3052{
Johannes Berg4c476992010-10-04 21:36:35 +02003053 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg41ade002007-12-19 02:03:29 +01003054 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02003055 struct net_device *dev = info->user_ptr[1];
Johannes Berg41ade002007-12-19 02:03:29 +01003056 u8 key_idx = 0;
Johannes Berge31b8212010-10-05 19:39:30 +02003057 const u8 *mac_addr = NULL;
3058 bool pairwise;
Johannes Berg41ade002007-12-19 02:03:29 +01003059 struct get_key_cookie cookie = {
3060 .error = 0,
3061 };
3062 void *hdr;
3063 struct sk_buff *msg;
3064
3065 if (info->attrs[NL80211_ATTR_KEY_IDX])
3066 key_idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]);
3067
Jouni Malinen3cfcf6ac2009-01-08 13:32:02 +02003068 if (key_idx > 5)
Johannes Berg41ade002007-12-19 02:03:29 +01003069 return -EINVAL;
3070
3071 if (info->attrs[NL80211_ATTR_MAC])
3072 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
3073
Johannes Berge31b8212010-10-05 19:39:30 +02003074 pairwise = !!mac_addr;
3075 if (info->attrs[NL80211_ATTR_KEY_TYPE]) {
3076 u32 kt = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]);
Kirtika Ruchandani7a087e72016-05-29 19:51:23 -07003077
Johannes Berge31b8212010-10-05 19:39:30 +02003078 if (kt >= NUM_NL80211_KEYTYPES)
3079 return -EINVAL;
3080 if (kt != NL80211_KEYTYPE_GROUP &&
3081 kt != NL80211_KEYTYPE_PAIRWISE)
3082 return -EINVAL;
3083 pairwise = kt == NL80211_KEYTYPE_PAIRWISE;
3084 }
3085
Johannes Berg4c476992010-10-04 21:36:35 +02003086 if (!rdev->ops->get_key)
3087 return -EOPNOTSUPP;
Johannes Berg41ade002007-12-19 02:03:29 +01003088
Johannes Berg0fa7b392015-01-23 11:10:12 +01003089 if (!pairwise && mac_addr && !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN))
3090 return -ENOENT;
3091
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07003092 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02003093 if (!msg)
3094 return -ENOMEM;
Johannes Berg41ade002007-12-19 02:03:29 +01003095
Eric W. Biederman15e47302012-09-07 20:12:54 +00003096 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berg41ade002007-12-19 02:03:29 +01003097 NL80211_CMD_NEW_KEY);
Dan Carpentercb35fba2013-08-14 14:50:01 +03003098 if (!hdr)
Johannes Berg9fe271a2013-10-25 11:15:12 +02003099 goto nla_put_failure;
Johannes Berg41ade002007-12-19 02:03:29 +01003100
3101 cookie.msg = msg;
Johannes Bergb9454e82009-07-08 13:29:08 +02003102 cookie.idx = key_idx;
Johannes Berg41ade002007-12-19 02:03:29 +01003103
David S. Miller9360ffd2012-03-29 04:41:26 -04003104 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
3105 nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_idx))
3106 goto nla_put_failure;
3107 if (mac_addr &&
3108 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr))
3109 goto nla_put_failure;
Johannes Berg41ade002007-12-19 02:03:29 +01003110
Hila Gonene35e4d22012-06-27 17:19:42 +03003111 err = rdev_get_key(rdev, dev, key_idx, pairwise, mac_addr, &cookie,
3112 get_key_callback);
Johannes Berg41ade002007-12-19 02:03:29 +01003113
3114 if (err)
Niko Jokinen6c95e2a2009-07-15 11:00:53 +03003115 goto free_msg;
Johannes Berg41ade002007-12-19 02:03:29 +01003116
3117 if (cookie.error)
3118 goto nla_put_failure;
3119
3120 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02003121 return genlmsg_reply(msg, info);
Johannes Berg41ade002007-12-19 02:03:29 +01003122
3123 nla_put_failure:
3124 err = -ENOBUFS;
Niko Jokinen6c95e2a2009-07-15 11:00:53 +03003125 free_msg:
Johannes Berg41ade002007-12-19 02:03:29 +01003126 nlmsg_free(msg);
Johannes Berg41ade002007-12-19 02:03:29 +01003127 return err;
3128}
3129
3130static int nl80211_set_key(struct sk_buff *skb, struct genl_info *info)
3131{
Johannes Berg4c476992010-10-04 21:36:35 +02003132 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Bergb9454e82009-07-08 13:29:08 +02003133 struct key_parse key;
Johannes Berg41ade002007-12-19 02:03:29 +01003134 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02003135 struct net_device *dev = info->user_ptr[1];
Johannes Berg41ade002007-12-19 02:03:29 +01003136
Johannes Bergb9454e82009-07-08 13:29:08 +02003137 err = nl80211_parse_key(info, &key);
3138 if (err)
3139 return err;
3140
3141 if (key.idx < 0)
Johannes Berg41ade002007-12-19 02:03:29 +01003142 return -EINVAL;
3143
Johannes Bergb9454e82009-07-08 13:29:08 +02003144 /* only support setting default key */
3145 if (!key.def && !key.defmgmt)
Johannes Berg41ade002007-12-19 02:03:29 +01003146 return -EINVAL;
3147
Johannes Bergfffd0932009-07-08 14:22:54 +02003148 wdev_lock(dev->ieee80211_ptr);
Johannes Bergdbd2fd62010-12-09 19:58:59 +01003149
3150 if (key.def) {
3151 if (!rdev->ops->set_default_key) {
3152 err = -EOPNOTSUPP;
3153 goto out;
3154 }
3155
3156 err = nl80211_key_allowed(dev->ieee80211_ptr);
3157 if (err)
3158 goto out;
3159
Hila Gonene35e4d22012-06-27 17:19:42 +03003160 err = rdev_set_default_key(rdev, dev, key.idx,
Johannes Bergdbd2fd62010-12-09 19:58:59 +01003161 key.def_uni, key.def_multi);
3162
3163 if (err)
3164 goto out;
Johannes Bergfffd0932009-07-08 14:22:54 +02003165
Johannes Berg3d23e342009-09-29 23:27:28 +02003166#ifdef CONFIG_CFG80211_WEXT
Johannes Bergdbd2fd62010-12-09 19:58:59 +01003167 dev->ieee80211_ptr->wext.default_key = key.idx;
Johannes Berg08645122009-05-11 13:54:58 +02003168#endif
Johannes Bergdbd2fd62010-12-09 19:58:59 +01003169 } else {
3170 if (key.def_uni || !key.def_multi) {
3171 err = -EINVAL;
3172 goto out;
3173 }
3174
3175 if (!rdev->ops->set_default_mgmt_key) {
3176 err = -EOPNOTSUPP;
3177 goto out;
3178 }
3179
3180 err = nl80211_key_allowed(dev->ieee80211_ptr);
3181 if (err)
3182 goto out;
3183
Hila Gonene35e4d22012-06-27 17:19:42 +03003184 err = rdev_set_default_mgmt_key(rdev, dev, key.idx);
Johannes Bergdbd2fd62010-12-09 19:58:59 +01003185 if (err)
3186 goto out;
3187
3188#ifdef CONFIG_CFG80211_WEXT
3189 dev->ieee80211_ptr->wext.default_mgmt_key = key.idx;
3190#endif
3191 }
3192
3193 out:
Johannes Bergfffd0932009-07-08 14:22:54 +02003194 wdev_unlock(dev->ieee80211_ptr);
Johannes Berg41ade002007-12-19 02:03:29 +01003195
Johannes Berg41ade002007-12-19 02:03:29 +01003196 return err;
3197}
3198
3199static int nl80211_new_key(struct sk_buff *skb, struct genl_info *info)
3200{
Johannes Berg4c476992010-10-04 21:36:35 +02003201 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Bergfffd0932009-07-08 14:22:54 +02003202 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02003203 struct net_device *dev = info->user_ptr[1];
Johannes Bergb9454e82009-07-08 13:29:08 +02003204 struct key_parse key;
Johannes Berge31b8212010-10-05 19:39:30 +02003205 const u8 *mac_addr = NULL;
Johannes Berg41ade002007-12-19 02:03:29 +01003206
Johannes Bergb9454e82009-07-08 13:29:08 +02003207 err = nl80211_parse_key(info, &key);
3208 if (err)
3209 return err;
Johannes Berg41ade002007-12-19 02:03:29 +01003210
Johannes Bergb9454e82009-07-08 13:29:08 +02003211 if (!key.p.key)
Johannes Berg41ade002007-12-19 02:03:29 +01003212 return -EINVAL;
3213
Johannes Berg41ade002007-12-19 02:03:29 +01003214 if (info->attrs[NL80211_ATTR_MAC])
3215 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
3216
Johannes Berge31b8212010-10-05 19:39:30 +02003217 if (key.type == -1) {
3218 if (mac_addr)
3219 key.type = NL80211_KEYTYPE_PAIRWISE;
3220 else
3221 key.type = NL80211_KEYTYPE_GROUP;
3222 }
3223
3224 /* for now */
3225 if (key.type != NL80211_KEYTYPE_PAIRWISE &&
3226 key.type != NL80211_KEYTYPE_GROUP)
3227 return -EINVAL;
3228
Johannes Berg4c476992010-10-04 21:36:35 +02003229 if (!rdev->ops->add_key)
3230 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01003231
Johannes Berge31b8212010-10-05 19:39:30 +02003232 if (cfg80211_validate_key_settings(rdev, &key.p, key.idx,
3233 key.type == NL80211_KEYTYPE_PAIRWISE,
3234 mac_addr))
Johannes Berg4c476992010-10-04 21:36:35 +02003235 return -EINVAL;
Johannes Bergfffd0932009-07-08 14:22:54 +02003236
3237 wdev_lock(dev->ieee80211_ptr);
3238 err = nl80211_key_allowed(dev->ieee80211_ptr);
3239 if (!err)
Hila Gonene35e4d22012-06-27 17:19:42 +03003240 err = rdev_add_key(rdev, dev, key.idx,
3241 key.type == NL80211_KEYTYPE_PAIRWISE,
3242 mac_addr, &key.p);
Johannes Bergfffd0932009-07-08 14:22:54 +02003243 wdev_unlock(dev->ieee80211_ptr);
Johannes Berg41ade002007-12-19 02:03:29 +01003244
Johannes Berg41ade002007-12-19 02:03:29 +01003245 return err;
3246}
3247
3248static int nl80211_del_key(struct sk_buff *skb, struct genl_info *info)
3249{
Johannes Berg4c476992010-10-04 21:36:35 +02003250 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg41ade002007-12-19 02:03:29 +01003251 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02003252 struct net_device *dev = info->user_ptr[1];
Johannes Berg41ade002007-12-19 02:03:29 +01003253 u8 *mac_addr = NULL;
Johannes Bergb9454e82009-07-08 13:29:08 +02003254 struct key_parse key;
Johannes Berg41ade002007-12-19 02:03:29 +01003255
Johannes Bergb9454e82009-07-08 13:29:08 +02003256 err = nl80211_parse_key(info, &key);
3257 if (err)
3258 return err;
Johannes Berg41ade002007-12-19 02:03:29 +01003259
3260 if (info->attrs[NL80211_ATTR_MAC])
3261 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
3262
Johannes Berge31b8212010-10-05 19:39:30 +02003263 if (key.type == -1) {
3264 if (mac_addr)
3265 key.type = NL80211_KEYTYPE_PAIRWISE;
3266 else
3267 key.type = NL80211_KEYTYPE_GROUP;
3268 }
3269
3270 /* for now */
3271 if (key.type != NL80211_KEYTYPE_PAIRWISE &&
3272 key.type != NL80211_KEYTYPE_GROUP)
3273 return -EINVAL;
3274
Johannes Berg4c476992010-10-04 21:36:35 +02003275 if (!rdev->ops->del_key)
3276 return -EOPNOTSUPP;
Johannes Berg41ade002007-12-19 02:03:29 +01003277
Johannes Bergfffd0932009-07-08 14:22:54 +02003278 wdev_lock(dev->ieee80211_ptr);
3279 err = nl80211_key_allowed(dev->ieee80211_ptr);
Johannes Berge31b8212010-10-05 19:39:30 +02003280
Johannes Berg0fa7b392015-01-23 11:10:12 +01003281 if (key.type == NL80211_KEYTYPE_GROUP && mac_addr &&
Johannes Berge31b8212010-10-05 19:39:30 +02003282 !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN))
3283 err = -ENOENT;
3284
Johannes Bergfffd0932009-07-08 14:22:54 +02003285 if (!err)
Hila Gonene35e4d22012-06-27 17:19:42 +03003286 err = rdev_del_key(rdev, dev, key.idx,
3287 key.type == NL80211_KEYTYPE_PAIRWISE,
3288 mac_addr);
Johannes Berg41ade002007-12-19 02:03:29 +01003289
Johannes Berg3d23e342009-09-29 23:27:28 +02003290#ifdef CONFIG_CFG80211_WEXT
Johannes Berg08645122009-05-11 13:54:58 +02003291 if (!err) {
Johannes Bergb9454e82009-07-08 13:29:08 +02003292 if (key.idx == dev->ieee80211_ptr->wext.default_key)
Johannes Berg08645122009-05-11 13:54:58 +02003293 dev->ieee80211_ptr->wext.default_key = -1;
Johannes Bergb9454e82009-07-08 13:29:08 +02003294 else if (key.idx == dev->ieee80211_ptr->wext.default_mgmt_key)
Johannes Berg08645122009-05-11 13:54:58 +02003295 dev->ieee80211_ptr->wext.default_mgmt_key = -1;
3296 }
3297#endif
Johannes Bergfffd0932009-07-08 14:22:54 +02003298 wdev_unlock(dev->ieee80211_ptr);
Johannes Berg08645122009-05-11 13:54:58 +02003299
Johannes Berg41ade002007-12-19 02:03:29 +01003300 return err;
3301}
3302
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +05303303/* This function returns an error or the number of nested attributes */
3304static int validate_acl_mac_addrs(struct nlattr *nl_attr)
3305{
3306 struct nlattr *attr;
3307 int n_entries = 0, tmp;
3308
3309 nla_for_each_nested(attr, nl_attr, tmp) {
3310 if (nla_len(attr) != ETH_ALEN)
3311 return -EINVAL;
3312
3313 n_entries++;
3314 }
3315
3316 return n_entries;
3317}
3318
3319/*
3320 * This function parses ACL information and allocates memory for ACL data.
3321 * On successful return, the calling function is responsible to free the
3322 * ACL buffer returned by this function.
3323 */
3324static struct cfg80211_acl_data *parse_acl_data(struct wiphy *wiphy,
3325 struct genl_info *info)
3326{
3327 enum nl80211_acl_policy acl_policy;
3328 struct nlattr *attr;
3329 struct cfg80211_acl_data *acl;
3330 int i = 0, n_entries, tmp;
3331
3332 if (!wiphy->max_acl_mac_addrs)
3333 return ERR_PTR(-EOPNOTSUPP);
3334
3335 if (!info->attrs[NL80211_ATTR_ACL_POLICY])
3336 return ERR_PTR(-EINVAL);
3337
3338 acl_policy = nla_get_u32(info->attrs[NL80211_ATTR_ACL_POLICY]);
3339 if (acl_policy != NL80211_ACL_POLICY_ACCEPT_UNLESS_LISTED &&
3340 acl_policy != NL80211_ACL_POLICY_DENY_UNLESS_LISTED)
3341 return ERR_PTR(-EINVAL);
3342
3343 if (!info->attrs[NL80211_ATTR_MAC_ADDRS])
3344 return ERR_PTR(-EINVAL);
3345
3346 n_entries = validate_acl_mac_addrs(info->attrs[NL80211_ATTR_MAC_ADDRS]);
3347 if (n_entries < 0)
3348 return ERR_PTR(n_entries);
3349
3350 if (n_entries > wiphy->max_acl_mac_addrs)
3351 return ERR_PTR(-ENOTSUPP);
3352
3353 acl = kzalloc(sizeof(*acl) + (sizeof(struct mac_address) * n_entries),
3354 GFP_KERNEL);
3355 if (!acl)
3356 return ERR_PTR(-ENOMEM);
3357
3358 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_MAC_ADDRS], tmp) {
3359 memcpy(acl->mac_addrs[i].addr, nla_data(attr), ETH_ALEN);
3360 i++;
3361 }
3362
3363 acl->n_acl_entries = n_entries;
3364 acl->acl_policy = acl_policy;
3365
3366 return acl;
3367}
3368
3369static int nl80211_set_mac_acl(struct sk_buff *skb, struct genl_info *info)
3370{
3371 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3372 struct net_device *dev = info->user_ptr[1];
3373 struct cfg80211_acl_data *acl;
3374 int err;
3375
3376 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
3377 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
3378 return -EOPNOTSUPP;
3379
3380 if (!dev->ieee80211_ptr->beacon_interval)
3381 return -EINVAL;
3382
3383 acl = parse_acl_data(&rdev->wiphy, info);
3384 if (IS_ERR(acl))
3385 return PTR_ERR(acl);
3386
3387 err = rdev_set_mac_acl(rdev, dev, acl);
3388
3389 kfree(acl);
3390
3391 return err;
3392}
3393
Purushottam Kushwahaa7c7fbf2016-09-14 17:38:44 +05303394static u32 rateset_to_mask(struct ieee80211_supported_band *sband,
3395 u8 *rates, u8 rates_len)
3396{
3397 u8 i;
3398 u32 mask = 0;
3399
3400 for (i = 0; i < rates_len; i++) {
3401 int rate = (rates[i] & 0x7f) * 5;
3402 int ridx;
3403
3404 for (ridx = 0; ridx < sband->n_bitrates; ridx++) {
3405 struct ieee80211_rate *srate =
3406 &sband->bitrates[ridx];
3407 if (rate == srate->bitrate) {
3408 mask |= 1 << ridx;
3409 break;
3410 }
3411 }
3412 if (ridx == sband->n_bitrates)
3413 return 0; /* rate not found */
3414 }
3415
3416 return mask;
3417}
3418
3419static bool ht_rateset_to_mask(struct ieee80211_supported_band *sband,
3420 u8 *rates, u8 rates_len,
3421 u8 mcs[IEEE80211_HT_MCS_MASK_LEN])
3422{
3423 u8 i;
3424
3425 memset(mcs, 0, IEEE80211_HT_MCS_MASK_LEN);
3426
3427 for (i = 0; i < rates_len; i++) {
3428 int ridx, rbit;
3429
3430 ridx = rates[i] / 8;
3431 rbit = BIT(rates[i] % 8);
3432
3433 /* check validity */
3434 if ((ridx < 0) || (ridx >= IEEE80211_HT_MCS_MASK_LEN))
3435 return false;
3436
3437 /* check availability */
3438 if (sband->ht_cap.mcs.rx_mask[ridx] & rbit)
3439 mcs[ridx] |= rbit;
3440 else
3441 return false;
3442 }
3443
3444 return true;
3445}
3446
3447static u16 vht_mcs_map_to_mcs_mask(u8 vht_mcs_map)
3448{
3449 u16 mcs_mask = 0;
3450
3451 switch (vht_mcs_map) {
3452 case IEEE80211_VHT_MCS_NOT_SUPPORTED:
3453 break;
3454 case IEEE80211_VHT_MCS_SUPPORT_0_7:
3455 mcs_mask = 0x00FF;
3456 break;
3457 case IEEE80211_VHT_MCS_SUPPORT_0_8:
3458 mcs_mask = 0x01FF;
3459 break;
3460 case IEEE80211_VHT_MCS_SUPPORT_0_9:
3461 mcs_mask = 0x03FF;
3462 break;
3463 default:
3464 break;
3465 }
3466
3467 return mcs_mask;
3468}
3469
3470static void vht_build_mcs_mask(u16 vht_mcs_map,
3471 u16 vht_mcs_mask[NL80211_VHT_NSS_MAX])
3472{
3473 u8 nss;
3474
3475 for (nss = 0; nss < NL80211_VHT_NSS_MAX; nss++) {
3476 vht_mcs_mask[nss] = vht_mcs_map_to_mcs_mask(vht_mcs_map & 0x03);
3477 vht_mcs_map >>= 2;
3478 }
3479}
3480
3481static bool vht_set_mcs_mask(struct ieee80211_supported_band *sband,
3482 struct nl80211_txrate_vht *txrate,
3483 u16 mcs[NL80211_VHT_NSS_MAX])
3484{
3485 u16 tx_mcs_map = le16_to_cpu(sband->vht_cap.vht_mcs.tx_mcs_map);
3486 u16 tx_mcs_mask[NL80211_VHT_NSS_MAX] = {};
3487 u8 i;
3488
3489 if (!sband->vht_cap.vht_supported)
3490 return false;
3491
3492 memset(mcs, 0, sizeof(u16) * NL80211_VHT_NSS_MAX);
3493
3494 /* Build vht_mcs_mask from VHT capabilities */
3495 vht_build_mcs_mask(tx_mcs_map, tx_mcs_mask);
3496
3497 for (i = 0; i < NL80211_VHT_NSS_MAX; i++) {
3498 if ((tx_mcs_mask[i] & txrate->mcs[i]) == txrate->mcs[i])
3499 mcs[i] = txrate->mcs[i];
3500 else
3501 return false;
3502 }
3503
3504 return true;
3505}
3506
3507static const struct nla_policy nl80211_txattr_policy[NL80211_TXRATE_MAX + 1] = {
3508 [NL80211_TXRATE_LEGACY] = { .type = NLA_BINARY,
3509 .len = NL80211_MAX_SUPP_RATES },
3510 [NL80211_TXRATE_HT] = { .type = NLA_BINARY,
3511 .len = NL80211_MAX_SUPP_HT_RATES },
3512 [NL80211_TXRATE_VHT] = { .len = sizeof(struct nl80211_txrate_vht)},
3513 [NL80211_TXRATE_GI] = { .type = NLA_U8 },
3514};
3515
3516static int nl80211_parse_tx_bitrate_mask(struct genl_info *info,
3517 struct cfg80211_bitrate_mask *mask)
3518{
3519 struct nlattr *tb[NL80211_TXRATE_MAX + 1];
3520 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3521 int rem, i;
3522 struct nlattr *tx_rates;
3523 struct ieee80211_supported_band *sband;
3524 u16 vht_tx_mcs_map;
3525
3526 memset(mask, 0, sizeof(*mask));
3527 /* Default to all rates enabled */
3528 for (i = 0; i < NUM_NL80211_BANDS; i++) {
3529 sband = rdev->wiphy.bands[i];
3530
3531 if (!sband)
3532 continue;
3533
3534 mask->control[i].legacy = (1 << sband->n_bitrates) - 1;
3535 memcpy(mask->control[i].ht_mcs,
3536 sband->ht_cap.mcs.rx_mask,
3537 sizeof(mask->control[i].ht_mcs));
3538
3539 if (!sband->vht_cap.vht_supported)
3540 continue;
3541
3542 vht_tx_mcs_map = le16_to_cpu(sband->vht_cap.vht_mcs.tx_mcs_map);
3543 vht_build_mcs_mask(vht_tx_mcs_map, mask->control[i].vht_mcs);
3544 }
3545
3546 /* if no rates are given set it back to the defaults */
3547 if (!info->attrs[NL80211_ATTR_TX_RATES])
3548 goto out;
3549
3550 /* The nested attribute uses enum nl80211_band as the index. This maps
3551 * directly to the enum nl80211_band values used in cfg80211.
3552 */
3553 BUILD_BUG_ON(NL80211_MAX_SUPP_HT_RATES > IEEE80211_HT_MCS_MASK_LEN * 8);
3554 nla_for_each_nested(tx_rates, info->attrs[NL80211_ATTR_TX_RATES], rem) {
3555 enum nl80211_band band = nla_type(tx_rates);
3556 int err;
3557
3558 if (band < 0 || band >= NUM_NL80211_BANDS)
3559 return -EINVAL;
3560 sband = rdev->wiphy.bands[band];
3561 if (sband == NULL)
3562 return -EINVAL;
Johannes Bergbfe2c7b2016-10-26 14:42:21 +02003563 err = nla_parse_nested(tb, NL80211_TXRATE_MAX, tx_rates,
3564 nl80211_txattr_policy);
Purushottam Kushwahaa7c7fbf2016-09-14 17:38:44 +05303565 if (err)
3566 return err;
3567 if (tb[NL80211_TXRATE_LEGACY]) {
3568 mask->control[band].legacy = rateset_to_mask(
3569 sband,
3570 nla_data(tb[NL80211_TXRATE_LEGACY]),
3571 nla_len(tb[NL80211_TXRATE_LEGACY]));
3572 if ((mask->control[band].legacy == 0) &&
3573 nla_len(tb[NL80211_TXRATE_LEGACY]))
3574 return -EINVAL;
3575 }
3576 if (tb[NL80211_TXRATE_HT]) {
3577 if (!ht_rateset_to_mask(
3578 sband,
3579 nla_data(tb[NL80211_TXRATE_HT]),
3580 nla_len(tb[NL80211_TXRATE_HT]),
3581 mask->control[band].ht_mcs))
3582 return -EINVAL;
3583 }
3584 if (tb[NL80211_TXRATE_VHT]) {
3585 if (!vht_set_mcs_mask(
3586 sband,
3587 nla_data(tb[NL80211_TXRATE_VHT]),
3588 mask->control[band].vht_mcs))
3589 return -EINVAL;
3590 }
3591 if (tb[NL80211_TXRATE_GI]) {
3592 mask->control[band].gi =
3593 nla_get_u8(tb[NL80211_TXRATE_GI]);
3594 if (mask->control[band].gi > NL80211_TXRATE_FORCE_LGI)
3595 return -EINVAL;
3596 }
3597
3598 if (mask->control[band].legacy == 0) {
3599 /* don't allow empty legacy rates if HT or VHT
3600 * are not even supported.
3601 */
3602 if (!(rdev->wiphy.bands[band]->ht_cap.ht_supported ||
3603 rdev->wiphy.bands[band]->vht_cap.vht_supported))
3604 return -EINVAL;
3605
3606 for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++)
3607 if (mask->control[band].ht_mcs[i])
3608 goto out;
3609
3610 for (i = 0; i < NL80211_VHT_NSS_MAX; i++)
3611 if (mask->control[band].vht_mcs[i])
3612 goto out;
3613
3614 /* legacy and mcs rates may not be both empty */
3615 return -EINVAL;
3616 }
3617 }
3618
3619out:
3620 return 0;
3621}
3622
Johannes Berg8564e382016-09-19 09:44:44 +02003623static int validate_beacon_tx_rate(struct cfg80211_registered_device *rdev,
3624 enum nl80211_band band,
3625 struct cfg80211_bitrate_mask *beacon_rate)
Purushottam Kushwahaa7c7fbf2016-09-14 17:38:44 +05303626{
Johannes Berg8564e382016-09-19 09:44:44 +02003627 u32 count_ht, count_vht, i;
3628 u32 rate = beacon_rate->control[band].legacy;
Purushottam Kushwahaa7c7fbf2016-09-14 17:38:44 +05303629
3630 /* Allow only one rate */
3631 if (hweight32(rate) > 1)
3632 return -EINVAL;
3633
3634 count_ht = 0;
3635 for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++) {
Johannes Berg8564e382016-09-19 09:44:44 +02003636 if (hweight8(beacon_rate->control[band].ht_mcs[i]) > 1) {
Purushottam Kushwahaa7c7fbf2016-09-14 17:38:44 +05303637 return -EINVAL;
Johannes Berg8564e382016-09-19 09:44:44 +02003638 } else if (beacon_rate->control[band].ht_mcs[i]) {
Purushottam Kushwahaa7c7fbf2016-09-14 17:38:44 +05303639 count_ht++;
3640 if (count_ht > 1)
3641 return -EINVAL;
3642 }
3643 if (count_ht && rate)
3644 return -EINVAL;
3645 }
3646
3647 count_vht = 0;
3648 for (i = 0; i < NL80211_VHT_NSS_MAX; i++) {
Johannes Berg8564e382016-09-19 09:44:44 +02003649 if (hweight16(beacon_rate->control[band].vht_mcs[i]) > 1) {
Purushottam Kushwahaa7c7fbf2016-09-14 17:38:44 +05303650 return -EINVAL;
Johannes Berg8564e382016-09-19 09:44:44 +02003651 } else if (beacon_rate->control[band].vht_mcs[i]) {
Purushottam Kushwahaa7c7fbf2016-09-14 17:38:44 +05303652 count_vht++;
3653 if (count_vht > 1)
3654 return -EINVAL;
3655 }
3656 if (count_vht && rate)
3657 return -EINVAL;
3658 }
3659
3660 if ((count_ht && count_vht) || (!rate && !count_ht && !count_vht))
3661 return -EINVAL;
3662
Johannes Berg8564e382016-09-19 09:44:44 +02003663 if (rate &&
3664 !wiphy_ext_feature_isset(&rdev->wiphy,
3665 NL80211_EXT_FEATURE_BEACON_RATE_LEGACY))
3666 return -EINVAL;
3667 if (count_ht &&
3668 !wiphy_ext_feature_isset(&rdev->wiphy,
3669 NL80211_EXT_FEATURE_BEACON_RATE_HT))
3670 return -EINVAL;
3671 if (count_vht &&
3672 !wiphy_ext_feature_isset(&rdev->wiphy,
3673 NL80211_EXT_FEATURE_BEACON_RATE_VHT))
3674 return -EINVAL;
3675
Purushottam Kushwahaa7c7fbf2016-09-14 17:38:44 +05303676 return 0;
3677}
3678
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003679static int nl80211_parse_beacon(struct nlattr *attrs[],
Johannes Berg88600202012-02-13 15:17:18 +01003680 struct cfg80211_beacon_data *bcn)
Johannes Berged1b6cc2007-12-19 02:03:32 +01003681{
Johannes Berg88600202012-02-13 15:17:18 +01003682 bool haveinfo = false;
Johannes Berged1b6cc2007-12-19 02:03:32 +01003683
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003684 if (!is_valid_ie_attr(attrs[NL80211_ATTR_BEACON_TAIL]) ||
3685 !is_valid_ie_attr(attrs[NL80211_ATTR_IE]) ||
3686 !is_valid_ie_attr(attrs[NL80211_ATTR_IE_PROBE_RESP]) ||
3687 !is_valid_ie_attr(attrs[NL80211_ATTR_IE_ASSOC_RESP]))
Johannes Bergf4a11bb2009-03-27 12:40:28 +01003688 return -EINVAL;
3689
Johannes Berg88600202012-02-13 15:17:18 +01003690 memset(bcn, 0, sizeof(*bcn));
Johannes Berged1b6cc2007-12-19 02:03:32 +01003691
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003692 if (attrs[NL80211_ATTR_BEACON_HEAD]) {
3693 bcn->head = nla_data(attrs[NL80211_ATTR_BEACON_HEAD]);
3694 bcn->head_len = nla_len(attrs[NL80211_ATTR_BEACON_HEAD]);
Johannes Berg88600202012-02-13 15:17:18 +01003695 if (!bcn->head_len)
3696 return -EINVAL;
3697 haveinfo = true;
Johannes Berged1b6cc2007-12-19 02:03:32 +01003698 }
3699
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003700 if (attrs[NL80211_ATTR_BEACON_TAIL]) {
3701 bcn->tail = nla_data(attrs[NL80211_ATTR_BEACON_TAIL]);
3702 bcn->tail_len = nla_len(attrs[NL80211_ATTR_BEACON_TAIL]);
Johannes Berg88600202012-02-13 15:17:18 +01003703 haveinfo = true;
Johannes Berged1b6cc2007-12-19 02:03:32 +01003704 }
3705
Johannes Berg4c476992010-10-04 21:36:35 +02003706 if (!haveinfo)
3707 return -EINVAL;
Johannes Berged1b6cc2007-12-19 02:03:32 +01003708
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003709 if (attrs[NL80211_ATTR_IE]) {
3710 bcn->beacon_ies = nla_data(attrs[NL80211_ATTR_IE]);
3711 bcn->beacon_ies_len = nla_len(attrs[NL80211_ATTR_IE]);
Jouni Malinen9946ecf2011-08-10 23:55:56 +03003712 }
3713
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003714 if (attrs[NL80211_ATTR_IE_PROBE_RESP]) {
Johannes Berg88600202012-02-13 15:17:18 +01003715 bcn->proberesp_ies =
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003716 nla_data(attrs[NL80211_ATTR_IE_PROBE_RESP]);
Johannes Berg88600202012-02-13 15:17:18 +01003717 bcn->proberesp_ies_len =
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003718 nla_len(attrs[NL80211_ATTR_IE_PROBE_RESP]);
Jouni Malinen9946ecf2011-08-10 23:55:56 +03003719 }
3720
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003721 if (attrs[NL80211_ATTR_IE_ASSOC_RESP]) {
Johannes Berg88600202012-02-13 15:17:18 +01003722 bcn->assocresp_ies =
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003723 nla_data(attrs[NL80211_ATTR_IE_ASSOC_RESP]);
Johannes Berg88600202012-02-13 15:17:18 +01003724 bcn->assocresp_ies_len =
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003725 nla_len(attrs[NL80211_ATTR_IE_ASSOC_RESP]);
Jouni Malinen9946ecf2011-08-10 23:55:56 +03003726 }
3727
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003728 if (attrs[NL80211_ATTR_PROBE_RESP]) {
3729 bcn->probe_resp = nla_data(attrs[NL80211_ATTR_PROBE_RESP]);
3730 bcn->probe_resp_len = nla_len(attrs[NL80211_ATTR_PROBE_RESP]);
Arik Nemtsov00f740e2011-11-10 11:28:56 +02003731 }
3732
Johannes Berg88600202012-02-13 15:17:18 +01003733 return 0;
3734}
3735
Johannes Berg66cd7942017-02-07 22:40:44 +02003736static void nl80211_check_ap_rate_selectors(struct cfg80211_ap_settings *params,
3737 const u8 *rates)
3738{
3739 int i;
3740
3741 if (!rates)
3742 return;
3743
3744 for (i = 0; i < rates[1]; i++) {
3745 if (rates[2 + i] == BSS_MEMBERSHIP_SELECTOR_HT_PHY)
3746 params->ht_required = true;
3747 if (rates[2 + i] == BSS_MEMBERSHIP_SELECTOR_VHT_PHY)
3748 params->vht_required = true;
3749 }
3750}
3751
3752/*
3753 * Since the nl80211 API didn't include, from the beginning, attributes about
3754 * HT/VHT requirements/capabilities, we parse them out of the IEs for the
3755 * benefit of drivers that rebuild IEs in the firmware.
3756 */
3757static void nl80211_calculate_ap_params(struct cfg80211_ap_settings *params)
3758{
3759 const struct cfg80211_beacon_data *bcn = &params->beacon;
3760 size_t ies_len = bcn->beacon_ies_len;
3761 const u8 *ies = bcn->beacon_ies;
3762 const u8 *rates;
3763 const u8 *cap;
3764
3765 rates = cfg80211_find_ie(WLAN_EID_SUPP_RATES, ies, ies_len);
3766 nl80211_check_ap_rate_selectors(params, rates);
3767
3768 rates = cfg80211_find_ie(WLAN_EID_EXT_SUPP_RATES, ies, ies_len);
3769 nl80211_check_ap_rate_selectors(params, rates);
3770
3771 cap = cfg80211_find_ie(WLAN_EID_HT_CAPABILITY, ies, ies_len);
3772 if (cap && cap[1] >= sizeof(*params->ht_cap))
3773 params->ht_cap = (void *)(cap + 2);
3774 cap = cfg80211_find_ie(WLAN_EID_VHT_CAPABILITY, ies, ies_len);
3775 if (cap && cap[1] >= sizeof(*params->vht_cap))
3776 params->vht_cap = (void *)(cap + 2);
3777}
3778
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003779static bool nl80211_get_ap_channel(struct cfg80211_registered_device *rdev,
3780 struct cfg80211_ap_settings *params)
3781{
3782 struct wireless_dev *wdev;
3783 bool ret = false;
3784
Johannes Berg53873f12016-05-03 16:52:04 +03003785 list_for_each_entry(wdev, &rdev->wiphy.wdev_list, list) {
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003786 if (wdev->iftype != NL80211_IFTYPE_AP &&
3787 wdev->iftype != NL80211_IFTYPE_P2P_GO)
3788 continue;
3789
Johannes Berg683b6d32012-11-08 21:25:48 +01003790 if (!wdev->preset_chandef.chan)
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003791 continue;
3792
Johannes Berg683b6d32012-11-08 21:25:48 +01003793 params->chandef = wdev->preset_chandef;
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003794 ret = true;
3795 break;
3796 }
3797
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003798 return ret;
3799}
3800
Jouni Malinene39e5b52012-09-30 19:29:39 +03003801static bool nl80211_valid_auth_type(struct cfg80211_registered_device *rdev,
3802 enum nl80211_auth_type auth_type,
3803 enum nl80211_commands cmd)
3804{
3805 if (auth_type > NL80211_AUTHTYPE_MAX)
3806 return false;
3807
3808 switch (cmd) {
3809 case NL80211_CMD_AUTHENTICATE:
3810 if (!(rdev->wiphy.features & NL80211_FEATURE_SAE) &&
3811 auth_type == NL80211_AUTHTYPE_SAE)
3812 return false;
Jouni Malinen63181062016-10-27 00:42:02 +03003813 if (!wiphy_ext_feature_isset(&rdev->wiphy,
3814 NL80211_EXT_FEATURE_FILS_STA) &&
3815 (auth_type == NL80211_AUTHTYPE_FILS_SK ||
3816 auth_type == NL80211_AUTHTYPE_FILS_SK_PFS ||
3817 auth_type == NL80211_AUTHTYPE_FILS_PK))
3818 return false;
Jouni Malinene39e5b52012-09-30 19:29:39 +03003819 return true;
3820 case NL80211_CMD_CONNECT:
3821 case NL80211_CMD_START_AP:
3822 /* SAE not supported yet */
3823 if (auth_type == NL80211_AUTHTYPE_SAE)
3824 return false;
Jouni Malinen63181062016-10-27 00:42:02 +03003825 /* FILS not supported yet */
3826 if (auth_type == NL80211_AUTHTYPE_FILS_SK ||
3827 auth_type == NL80211_AUTHTYPE_FILS_SK_PFS ||
3828 auth_type == NL80211_AUTHTYPE_FILS_PK)
3829 return false;
Jouni Malinene39e5b52012-09-30 19:29:39 +03003830 return true;
3831 default:
3832 return false;
3833 }
3834}
3835
Johannes Berg88600202012-02-13 15:17:18 +01003836static int nl80211_start_ap(struct sk_buff *skb, struct genl_info *info)
3837{
3838 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3839 struct net_device *dev = info->user_ptr[1];
3840 struct wireless_dev *wdev = dev->ieee80211_ptr;
3841 struct cfg80211_ap_settings params;
3842 int err;
3843
3844 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
3845 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
3846 return -EOPNOTSUPP;
3847
3848 if (!rdev->ops->start_ap)
3849 return -EOPNOTSUPP;
3850
3851 if (wdev->beacon_interval)
3852 return -EALREADY;
3853
3854 memset(&params, 0, sizeof(params));
3855
3856 /* these are required for START_AP */
3857 if (!info->attrs[NL80211_ATTR_BEACON_INTERVAL] ||
3858 !info->attrs[NL80211_ATTR_DTIM_PERIOD] ||
3859 !info->attrs[NL80211_ATTR_BEACON_HEAD])
3860 return -EINVAL;
3861
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003862 err = nl80211_parse_beacon(info->attrs, &params.beacon);
Johannes Berg88600202012-02-13 15:17:18 +01003863 if (err)
3864 return err;
3865
3866 params.beacon_interval =
3867 nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]);
3868 params.dtim_period =
3869 nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]);
3870
Purushottam Kushwaha0c317a02016-10-12 18:26:51 +05303871 err = cfg80211_validate_beacon_int(rdev, dev->ieee80211_ptr->iftype,
3872 params.beacon_interval);
Johannes Berg88600202012-02-13 15:17:18 +01003873 if (err)
3874 return err;
3875
3876 /*
3877 * In theory, some of these attributes should be required here
3878 * but since they were not used when the command was originally
3879 * added, keep them optional for old user space programs to let
3880 * them continue to work with drivers that do not need the
3881 * additional information -- drivers must check!
3882 */
3883 if (info->attrs[NL80211_ATTR_SSID]) {
3884 params.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
3885 params.ssid_len =
3886 nla_len(info->attrs[NL80211_ATTR_SSID]);
3887 if (params.ssid_len == 0 ||
3888 params.ssid_len > IEEE80211_MAX_SSID_LEN)
3889 return -EINVAL;
3890 }
3891
3892 if (info->attrs[NL80211_ATTR_HIDDEN_SSID]) {
3893 params.hidden_ssid = nla_get_u32(
3894 info->attrs[NL80211_ATTR_HIDDEN_SSID]);
3895 if (params.hidden_ssid != NL80211_HIDDEN_SSID_NOT_IN_USE &&
3896 params.hidden_ssid != NL80211_HIDDEN_SSID_ZERO_LEN &&
3897 params.hidden_ssid != NL80211_HIDDEN_SSID_ZERO_CONTENTS)
3898 return -EINVAL;
3899 }
3900
3901 params.privacy = !!info->attrs[NL80211_ATTR_PRIVACY];
3902
3903 if (info->attrs[NL80211_ATTR_AUTH_TYPE]) {
3904 params.auth_type = nla_get_u32(
3905 info->attrs[NL80211_ATTR_AUTH_TYPE]);
Jouni Malinene39e5b52012-09-30 19:29:39 +03003906 if (!nl80211_valid_auth_type(rdev, params.auth_type,
3907 NL80211_CMD_START_AP))
Johannes Berg88600202012-02-13 15:17:18 +01003908 return -EINVAL;
3909 } else
3910 params.auth_type = NL80211_AUTHTYPE_AUTOMATIC;
3911
3912 err = nl80211_crypto_settings(rdev, info, &params.crypto,
3913 NL80211_MAX_NR_CIPHER_SUITES);
3914 if (err)
3915 return err;
3916
Vasanthakumar Thiagarajan1b658f12012-03-02 15:50:02 +05303917 if (info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]) {
3918 if (!(rdev->wiphy.features & NL80211_FEATURE_INACTIVITY_TIMER))
3919 return -EOPNOTSUPP;
3920 params.inactivity_timeout = nla_get_u16(
3921 info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]);
3922 }
3923
Johannes Berg53cabad2012-11-14 15:17:28 +01003924 if (info->attrs[NL80211_ATTR_P2P_CTWINDOW]) {
3925 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
3926 return -EINVAL;
3927 params.p2p_ctwindow =
3928 nla_get_u8(info->attrs[NL80211_ATTR_P2P_CTWINDOW]);
3929 if (params.p2p_ctwindow > 127)
3930 return -EINVAL;
3931 if (params.p2p_ctwindow != 0 &&
3932 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_CTWIN))
3933 return -EINVAL;
3934 }
3935
3936 if (info->attrs[NL80211_ATTR_P2P_OPPPS]) {
3937 u8 tmp;
3938
3939 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
3940 return -EINVAL;
3941 tmp = nla_get_u8(info->attrs[NL80211_ATTR_P2P_OPPPS]);
3942 if (tmp > 1)
3943 return -EINVAL;
3944 params.p2p_opp_ps = tmp;
3945 if (params.p2p_opp_ps != 0 &&
3946 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_OPPPS))
3947 return -EINVAL;
3948 }
3949
Johannes Bergaa430da2012-05-16 23:50:18 +02003950 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
Johannes Berg683b6d32012-11-08 21:25:48 +01003951 err = nl80211_parse_chandef(rdev, info, &params.chandef);
3952 if (err)
3953 return err;
3954 } else if (wdev->preset_chandef.chan) {
3955 params.chandef = wdev->preset_chandef;
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003956 } else if (!nl80211_get_ap_channel(rdev, &params))
Johannes Bergaa430da2012-05-16 23:50:18 +02003957 return -EINVAL;
3958
Arik Nemtsov923b3522015-07-08 15:41:44 +03003959 if (!cfg80211_reg_can_beacon_relax(&rdev->wiphy, &params.chandef,
3960 wdev->iftype))
Johannes Bergaa430da2012-05-16 23:50:18 +02003961 return -EINVAL;
3962
Purushottam Kushwahaa7c7fbf2016-09-14 17:38:44 +05303963 if (info->attrs[NL80211_ATTR_TX_RATES]) {
3964 err = nl80211_parse_tx_bitrate_mask(info, &params.beacon_rate);
3965 if (err)
3966 return err;
3967
Johannes Berg8564e382016-09-19 09:44:44 +02003968 err = validate_beacon_tx_rate(rdev, params.chandef.chan->band,
3969 &params.beacon_rate);
Purushottam Kushwahaa7c7fbf2016-09-14 17:38:44 +05303970 if (err)
3971 return err;
3972 }
3973
Eliad Peller18998c32014-09-10 14:07:34 +03003974 if (info->attrs[NL80211_ATTR_SMPS_MODE]) {
3975 params.smps_mode =
3976 nla_get_u8(info->attrs[NL80211_ATTR_SMPS_MODE]);
3977 switch (params.smps_mode) {
3978 case NL80211_SMPS_OFF:
3979 break;
3980 case NL80211_SMPS_STATIC:
3981 if (!(rdev->wiphy.features &
3982 NL80211_FEATURE_STATIC_SMPS))
3983 return -EINVAL;
3984 break;
3985 case NL80211_SMPS_DYNAMIC:
3986 if (!(rdev->wiphy.features &
3987 NL80211_FEATURE_DYNAMIC_SMPS))
3988 return -EINVAL;
3989 break;
3990 default:
3991 return -EINVAL;
3992 }
3993 } else {
3994 params.smps_mode = NL80211_SMPS_OFF;
3995 }
3996
Purushottam Kushwaha6e8ef842016-07-05 13:44:51 +05303997 params.pbss = nla_get_flag(info->attrs[NL80211_ATTR_PBSS]);
3998 if (params.pbss && !rdev->wiphy.bands[NL80211_BAND_60GHZ])
3999 return -EOPNOTSUPP;
4000
Ola Olsson4baf6be2015-10-29 07:04:58 +01004001 if (info->attrs[NL80211_ATTR_ACL_POLICY]) {
4002 params.acl = parse_acl_data(&rdev->wiphy, info);
4003 if (IS_ERR(params.acl))
4004 return PTR_ERR(params.acl);
4005 }
4006
Johannes Berg66cd7942017-02-07 22:40:44 +02004007 nl80211_calculate_ap_params(&params);
4008
Simon Wunderlichc56589e2013-11-21 18:19:49 +01004009 wdev_lock(wdev);
Hila Gonene35e4d22012-06-27 17:19:42 +03004010 err = rdev_start_ap(rdev, dev, &params);
Felix Fietkau46c1dd02012-06-19 02:50:57 +02004011 if (!err) {
Johannes Berg683b6d32012-11-08 21:25:48 +01004012 wdev->preset_chandef = params.chandef;
Johannes Berg88600202012-02-13 15:17:18 +01004013 wdev->beacon_interval = params.beacon_interval;
Michal Kazior9e0e2962014-01-29 14:22:27 +01004014 wdev->chandef = params.chandef;
Antonio Quartulli06e191e2012-11-07 12:52:19 +01004015 wdev->ssid_len = params.ssid_len;
4016 memcpy(wdev->ssid, params.ssid, wdev->ssid_len);
Felix Fietkau46c1dd02012-06-19 02:50:57 +02004017 }
Simon Wunderlichc56589e2013-11-21 18:19:49 +01004018 wdev_unlock(wdev);
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +05304019
4020 kfree(params.acl);
4021
Johannes Berg56d18932011-05-09 18:41:15 +02004022 return err;
Johannes Berged1b6cc2007-12-19 02:03:32 +01004023}
4024
Johannes Berg88600202012-02-13 15:17:18 +01004025static int nl80211_set_beacon(struct sk_buff *skb, struct genl_info *info)
4026{
4027 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4028 struct net_device *dev = info->user_ptr[1];
4029 struct wireless_dev *wdev = dev->ieee80211_ptr;
4030 struct cfg80211_beacon_data params;
4031 int err;
4032
4033 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
4034 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
4035 return -EOPNOTSUPP;
4036
4037 if (!rdev->ops->change_beacon)
4038 return -EOPNOTSUPP;
4039
4040 if (!wdev->beacon_interval)
4041 return -EINVAL;
4042
Simon Wunderlicha1193be2013-06-14 14:15:19 +02004043 err = nl80211_parse_beacon(info->attrs, &params);
Johannes Berg88600202012-02-13 15:17:18 +01004044 if (err)
4045 return err;
4046
Simon Wunderlichc56589e2013-11-21 18:19:49 +01004047 wdev_lock(wdev);
4048 err = rdev_change_beacon(rdev, dev, &params);
4049 wdev_unlock(wdev);
4050
4051 return err;
Johannes Berg88600202012-02-13 15:17:18 +01004052}
4053
4054static int nl80211_stop_ap(struct sk_buff *skb, struct genl_info *info)
Johannes Berged1b6cc2007-12-19 02:03:32 +01004055{
Johannes Berg4c476992010-10-04 21:36:35 +02004056 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4057 struct net_device *dev = info->user_ptr[1];
Johannes Berged1b6cc2007-12-19 02:03:32 +01004058
Ilan Peer7c8d5e02014-02-25 15:33:38 +02004059 return cfg80211_stop_ap(rdev, dev, false);
Johannes Berged1b6cc2007-12-19 02:03:32 +01004060}
4061
Johannes Berg5727ef12007-12-19 02:03:34 +01004062static const struct nla_policy sta_flags_policy[NL80211_STA_FLAG_MAX + 1] = {
4063 [NL80211_STA_FLAG_AUTHORIZED] = { .type = NLA_FLAG },
4064 [NL80211_STA_FLAG_SHORT_PREAMBLE] = { .type = NLA_FLAG },
4065 [NL80211_STA_FLAG_WME] = { .type = NLA_FLAG },
Jouni Malinen0e467242009-05-11 21:57:55 +03004066 [NL80211_STA_FLAG_MFP] = { .type = NLA_FLAG },
Javier Cardonab39c48f2011-04-07 15:08:30 -07004067 [NL80211_STA_FLAG_AUTHENTICATED] = { .type = NLA_FLAG },
Johannes Bergd83023d2011-12-14 09:29:15 +01004068 [NL80211_STA_FLAG_TDLS_PEER] = { .type = NLA_FLAG },
Johannes Berg5727ef12007-12-19 02:03:34 +01004069};
4070
Johannes Bergeccb8e82009-05-11 21:57:56 +03004071static int parse_station_flags(struct genl_info *info,
Johannes Bergbdd3ae32012-01-02 13:30:03 +01004072 enum nl80211_iftype iftype,
Johannes Bergeccb8e82009-05-11 21:57:56 +03004073 struct station_parameters *params)
Johannes Berg5727ef12007-12-19 02:03:34 +01004074{
4075 struct nlattr *flags[NL80211_STA_FLAG_MAX + 1];
Johannes Bergeccb8e82009-05-11 21:57:56 +03004076 struct nlattr *nla;
Johannes Berg5727ef12007-12-19 02:03:34 +01004077 int flag;
4078
Johannes Bergeccb8e82009-05-11 21:57:56 +03004079 /*
4080 * Try parsing the new attribute first so userspace
4081 * can specify both for older kernels.
4082 */
4083 nla = info->attrs[NL80211_ATTR_STA_FLAGS2];
4084 if (nla) {
4085 struct nl80211_sta_flag_update *sta_flags;
Johannes Berg5727ef12007-12-19 02:03:34 +01004086
Johannes Bergeccb8e82009-05-11 21:57:56 +03004087 sta_flags = nla_data(nla);
4088 params->sta_flags_mask = sta_flags->mask;
4089 params->sta_flags_set = sta_flags->set;
Johannes Berg77ee7c82013-02-15 00:48:33 +01004090 params->sta_flags_set &= params->sta_flags_mask;
Johannes Bergeccb8e82009-05-11 21:57:56 +03004091 if ((params->sta_flags_mask |
4092 params->sta_flags_set) & BIT(__NL80211_STA_FLAG_INVALID))
4093 return -EINVAL;
4094 return 0;
4095 }
4096
4097 /* if present, parse the old attribute */
4098
4099 nla = info->attrs[NL80211_ATTR_STA_FLAGS];
Johannes Berg5727ef12007-12-19 02:03:34 +01004100 if (!nla)
4101 return 0;
4102
4103 if (nla_parse_nested(flags, NL80211_STA_FLAG_MAX,
4104 nla, sta_flags_policy))
4105 return -EINVAL;
4106
Johannes Bergbdd3ae32012-01-02 13:30:03 +01004107 /*
4108 * Only allow certain flags for interface types so that
4109 * other attributes are silently ignored. Remember that
4110 * this is backward compatibility code with old userspace
4111 * and shouldn't be hit in other cases anyway.
4112 */
4113 switch (iftype) {
4114 case NL80211_IFTYPE_AP:
4115 case NL80211_IFTYPE_AP_VLAN:
4116 case NL80211_IFTYPE_P2P_GO:
4117 params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) |
4118 BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) |
4119 BIT(NL80211_STA_FLAG_WME) |
4120 BIT(NL80211_STA_FLAG_MFP);
4121 break;
4122 case NL80211_IFTYPE_P2P_CLIENT:
4123 case NL80211_IFTYPE_STATION:
4124 params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) |
4125 BIT(NL80211_STA_FLAG_TDLS_PEER);
4126 break;
4127 case NL80211_IFTYPE_MESH_POINT:
4128 params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHENTICATED) |
4129 BIT(NL80211_STA_FLAG_MFP) |
4130 BIT(NL80211_STA_FLAG_AUTHORIZED);
4131 default:
4132 return -EINVAL;
4133 }
Johannes Berg5727ef12007-12-19 02:03:34 +01004134
Johannes Berg3383b5a2012-05-10 20:14:43 +02004135 for (flag = 1; flag <= NL80211_STA_FLAG_MAX; flag++) {
4136 if (flags[flag]) {
Johannes Bergeccb8e82009-05-11 21:57:56 +03004137 params->sta_flags_set |= (1<<flag);
Johannes Berg5727ef12007-12-19 02:03:34 +01004138
Johannes Berg3383b5a2012-05-10 20:14:43 +02004139 /* no longer support new API additions in old API */
4140 if (flag > NL80211_STA_FLAG_MAX_OLD_API)
4141 return -EINVAL;
4142 }
4143 }
4144
Johannes Berg5727ef12007-12-19 02:03:34 +01004145 return 0;
4146}
4147
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01004148static bool nl80211_put_sta_rate(struct sk_buff *msg, struct rate_info *info,
4149 int attr)
4150{
4151 struct nlattr *rate;
Vladimir Kondratiev8eb41c82012-07-05 14:25:49 +03004152 u32 bitrate;
4153 u16 bitrate_compat;
Johannes Bergb51f3be2015-01-15 16:14:02 +01004154 enum nl80211_attrs rate_flg;
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01004155
4156 rate = nla_nest_start(msg, attr);
4157 if (!rate)
Johannes Bergdb9c64c2012-11-09 14:56:41 +01004158 return false;
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01004159
4160 /* cfg80211_calculate_bitrate will return 0 for mcs >= 32 */
4161 bitrate = cfg80211_calculate_bitrate(info);
Vladimir Kondratiev8eb41c82012-07-05 14:25:49 +03004162 /* report 16-bit bitrate only if we can */
4163 bitrate_compat = bitrate < (1UL << 16) ? bitrate : 0;
Johannes Bergdb9c64c2012-11-09 14:56:41 +01004164 if (bitrate > 0 &&
4165 nla_put_u32(msg, NL80211_RATE_INFO_BITRATE32, bitrate))
4166 return false;
4167 if (bitrate_compat > 0 &&
4168 nla_put_u16(msg, NL80211_RATE_INFO_BITRATE, bitrate_compat))
4169 return false;
4170
Johannes Bergb51f3be2015-01-15 16:14:02 +01004171 switch (info->bw) {
4172 case RATE_INFO_BW_5:
4173 rate_flg = NL80211_RATE_INFO_5_MHZ_WIDTH;
4174 break;
4175 case RATE_INFO_BW_10:
4176 rate_flg = NL80211_RATE_INFO_10_MHZ_WIDTH;
4177 break;
4178 default:
4179 WARN_ON(1);
4180 /* fall through */
4181 case RATE_INFO_BW_20:
4182 rate_flg = 0;
4183 break;
4184 case RATE_INFO_BW_40:
4185 rate_flg = NL80211_RATE_INFO_40_MHZ_WIDTH;
4186 break;
4187 case RATE_INFO_BW_80:
4188 rate_flg = NL80211_RATE_INFO_80_MHZ_WIDTH;
4189 break;
4190 case RATE_INFO_BW_160:
4191 rate_flg = NL80211_RATE_INFO_160_MHZ_WIDTH;
4192 break;
4193 }
4194
4195 if (rate_flg && nla_put_flag(msg, rate_flg))
4196 return false;
4197
Johannes Bergdb9c64c2012-11-09 14:56:41 +01004198 if (info->flags & RATE_INFO_FLAGS_MCS) {
4199 if (nla_put_u8(msg, NL80211_RATE_INFO_MCS, info->mcs))
4200 return false;
Johannes Bergdb9c64c2012-11-09 14:56:41 +01004201 if (info->flags & RATE_INFO_FLAGS_SHORT_GI &&
4202 nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI))
4203 return false;
4204 } else if (info->flags & RATE_INFO_FLAGS_VHT_MCS) {
4205 if (nla_put_u8(msg, NL80211_RATE_INFO_VHT_MCS, info->mcs))
4206 return false;
4207 if (nla_put_u8(msg, NL80211_RATE_INFO_VHT_NSS, info->nss))
4208 return false;
Johannes Bergdb9c64c2012-11-09 14:56:41 +01004209 if (info->flags & RATE_INFO_FLAGS_SHORT_GI &&
4210 nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI))
4211 return false;
4212 }
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01004213
4214 nla_nest_end(msg, rate);
4215 return true;
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01004216}
4217
Felix Fietkau119363c2013-04-22 16:29:30 +02004218static bool nl80211_put_signal(struct sk_buff *msg, u8 mask, s8 *signal,
4219 int id)
4220{
4221 void *attr;
4222 int i = 0;
4223
4224 if (!mask)
4225 return true;
4226
4227 attr = nla_nest_start(msg, id);
4228 if (!attr)
4229 return false;
4230
4231 for (i = 0; i < IEEE80211_MAX_CHAINS; i++) {
4232 if (!(mask & BIT(i)))
4233 continue;
4234
4235 if (nla_put_u8(msg, i, signal[i]))
4236 return false;
4237 }
4238
4239 nla_nest_end(msg, attr);
4240
4241 return true;
4242}
4243
Johannes Bergcf5ead82014-11-14 17:14:00 +01004244static int nl80211_send_station(struct sk_buff *msg, u32 cmd, u32 portid,
4245 u32 seq, int flags,
John W. Linville66266b32012-03-15 13:25:41 -04004246 struct cfg80211_registered_device *rdev,
4247 struct net_device *dev,
Johannes Berg98b62182009-12-23 13:15:44 +01004248 const u8 *mac_addr, struct station_info *sinfo)
Johannes Bergfd5b74d2007-12-19 02:03:36 +01004249{
4250 void *hdr;
Paul Stewartf4263c92011-03-31 09:25:41 -07004251 struct nlattr *sinfoattr, *bss_param;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01004252
Johannes Bergcf5ead82014-11-14 17:14:00 +01004253 hdr = nl80211hdr_put(msg, portid, seq, flags, cmd);
Johannes Bergfd5b74d2007-12-19 02:03:36 +01004254 if (!hdr)
4255 return -1;
4256
David S. Miller9360ffd2012-03-29 04:41:26 -04004257 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
4258 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) ||
4259 nla_put_u32(msg, NL80211_ATTR_GENERATION, sinfo->generation))
4260 goto nla_put_failure;
Johannes Bergf5ea9122009-08-07 16:17:38 +02004261
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004262 sinfoattr = nla_nest_start(msg, NL80211_ATTR_STA_INFO);
4263 if (!sinfoattr)
Johannes Bergfd5b74d2007-12-19 02:03:36 +01004264 goto nla_put_failure;
Johannes Berg319090b2014-11-17 14:08:11 +01004265
4266#define PUT_SINFO(attr, memb, type) do { \
Johannes Bergd686b922016-04-26 09:54:11 +02004267 BUILD_BUG_ON(sizeof(type) == sizeof(u64)); \
Mohammed Shafi Shajakhan739960f2016-04-07 19:59:34 +05304268 if (sinfo->filled & (1ULL << NL80211_STA_INFO_ ## attr) && \
Johannes Berg319090b2014-11-17 14:08:11 +01004269 nla_put_ ## type(msg, NL80211_STA_INFO_ ## attr, \
4270 sinfo->memb)) \
4271 goto nla_put_failure; \
4272 } while (0)
Johannes Bergd686b922016-04-26 09:54:11 +02004273#define PUT_SINFO_U64(attr, memb) do { \
4274 if (sinfo->filled & (1ULL << NL80211_STA_INFO_ ## attr) && \
4275 nla_put_u64_64bit(msg, NL80211_STA_INFO_ ## attr, \
4276 sinfo->memb, NL80211_STA_INFO_PAD)) \
4277 goto nla_put_failure; \
4278 } while (0)
Johannes Berg319090b2014-11-17 14:08:11 +01004279
4280 PUT_SINFO(CONNECTED_TIME, connected_time, u32);
4281 PUT_SINFO(INACTIVE_TIME, inactive_time, u32);
4282
4283 if (sinfo->filled & (BIT(NL80211_STA_INFO_RX_BYTES) |
4284 BIT(NL80211_STA_INFO_RX_BYTES64)) &&
David S. Miller9360ffd2012-03-29 04:41:26 -04004285 nla_put_u32(msg, NL80211_STA_INFO_RX_BYTES,
Vladimir Kondratiev42745e02013-02-04 13:53:11 +02004286 (u32)sinfo->rx_bytes))
4287 goto nla_put_failure;
Johannes Berg319090b2014-11-17 14:08:11 +01004288
4289 if (sinfo->filled & (BIT(NL80211_STA_INFO_TX_BYTES) |
4290 BIT(NL80211_STA_INFO_TX_BYTES64)) &&
Vladimir Kondratiev42745e02013-02-04 13:53:11 +02004291 nla_put_u32(msg, NL80211_STA_INFO_TX_BYTES,
4292 (u32)sinfo->tx_bytes))
4293 goto nla_put_failure;
Johannes Berg319090b2014-11-17 14:08:11 +01004294
Johannes Bergd686b922016-04-26 09:54:11 +02004295 PUT_SINFO_U64(RX_BYTES64, rx_bytes);
4296 PUT_SINFO_U64(TX_BYTES64, tx_bytes);
Johannes Berg319090b2014-11-17 14:08:11 +01004297 PUT_SINFO(LLID, llid, u16);
4298 PUT_SINFO(PLID, plid, u16);
4299 PUT_SINFO(PLINK_STATE, plink_state, u8);
Johannes Bergd686b922016-04-26 09:54:11 +02004300 PUT_SINFO_U64(RX_DURATION, rx_duration);
Johannes Berg319090b2014-11-17 14:08:11 +01004301
John W. Linville66266b32012-03-15 13:25:41 -04004302 switch (rdev->wiphy.signal_type) {
4303 case CFG80211_SIGNAL_TYPE_MBM:
Johannes Berg319090b2014-11-17 14:08:11 +01004304 PUT_SINFO(SIGNAL, signal, u8);
4305 PUT_SINFO(SIGNAL_AVG, signal_avg, u8);
John W. Linville66266b32012-03-15 13:25:41 -04004306 break;
4307 default:
4308 break;
4309 }
Johannes Berg319090b2014-11-17 14:08:11 +01004310 if (sinfo->filled & BIT(NL80211_STA_INFO_CHAIN_SIGNAL)) {
Felix Fietkau119363c2013-04-22 16:29:30 +02004311 if (!nl80211_put_signal(msg, sinfo->chains,
4312 sinfo->chain_signal,
4313 NL80211_STA_INFO_CHAIN_SIGNAL))
4314 goto nla_put_failure;
4315 }
Johannes Berg319090b2014-11-17 14:08:11 +01004316 if (sinfo->filled & BIT(NL80211_STA_INFO_CHAIN_SIGNAL_AVG)) {
Felix Fietkau119363c2013-04-22 16:29:30 +02004317 if (!nl80211_put_signal(msg, sinfo->chains,
4318 sinfo->chain_signal_avg,
4319 NL80211_STA_INFO_CHAIN_SIGNAL_AVG))
4320 goto nla_put_failure;
4321 }
Johannes Berg319090b2014-11-17 14:08:11 +01004322 if (sinfo->filled & BIT(NL80211_STA_INFO_TX_BITRATE)) {
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01004323 if (!nl80211_put_sta_rate(msg, &sinfo->txrate,
4324 NL80211_STA_INFO_TX_BITRATE))
Henning Rogge420e7fa2008-12-11 22:04:19 +01004325 goto nla_put_failure;
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01004326 }
Johannes Berg319090b2014-11-17 14:08:11 +01004327 if (sinfo->filled & BIT(NL80211_STA_INFO_RX_BITRATE)) {
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01004328 if (!nl80211_put_sta_rate(msg, &sinfo->rxrate,
4329 NL80211_STA_INFO_RX_BITRATE))
4330 goto nla_put_failure;
Henning Rogge420e7fa2008-12-11 22:04:19 +01004331 }
Johannes Berg319090b2014-11-17 14:08:11 +01004332
4333 PUT_SINFO(RX_PACKETS, rx_packets, u32);
4334 PUT_SINFO(TX_PACKETS, tx_packets, u32);
4335 PUT_SINFO(TX_RETRIES, tx_retries, u32);
4336 PUT_SINFO(TX_FAILED, tx_failed, u32);
4337 PUT_SINFO(EXPECTED_THROUGHPUT, expected_throughput, u32);
4338 PUT_SINFO(BEACON_LOSS, beacon_loss_count, u32);
4339 PUT_SINFO(LOCAL_PM, local_pm, u32);
4340 PUT_SINFO(PEER_PM, peer_pm, u32);
4341 PUT_SINFO(NONPEER_PM, nonpeer_pm, u32);
4342
4343 if (sinfo->filled & BIT(NL80211_STA_INFO_BSS_PARAM)) {
Paul Stewartf4263c92011-03-31 09:25:41 -07004344 bss_param = nla_nest_start(msg, NL80211_STA_INFO_BSS_PARAM);
4345 if (!bss_param)
4346 goto nla_put_failure;
4347
David S. Miller9360ffd2012-03-29 04:41:26 -04004348 if (((sinfo->bss_param.flags & BSS_PARAM_FLAGS_CTS_PROT) &&
4349 nla_put_flag(msg, NL80211_STA_BSS_PARAM_CTS_PROT)) ||
4350 ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_PREAMBLE) &&
4351 nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_PREAMBLE)) ||
4352 ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_SLOT_TIME) &&
4353 nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_SLOT_TIME)) ||
4354 nla_put_u8(msg, NL80211_STA_BSS_PARAM_DTIM_PERIOD,
4355 sinfo->bss_param.dtim_period) ||
4356 nla_put_u16(msg, NL80211_STA_BSS_PARAM_BEACON_INTERVAL,
4357 sinfo->bss_param.beacon_interval))
4358 goto nla_put_failure;
Paul Stewartf4263c92011-03-31 09:25:41 -07004359
4360 nla_nest_end(msg, bss_param);
4361 }
Johannes Berg319090b2014-11-17 14:08:11 +01004362 if ((sinfo->filled & BIT(NL80211_STA_INFO_STA_FLAGS)) &&
David S. Miller9360ffd2012-03-29 04:41:26 -04004363 nla_put(msg, NL80211_STA_INFO_STA_FLAGS,
4364 sizeof(struct nl80211_sta_flag_update),
4365 &sinfo->sta_flags))
4366 goto nla_put_failure;
Johannes Berg319090b2014-11-17 14:08:11 +01004367
Johannes Bergd686b922016-04-26 09:54:11 +02004368 PUT_SINFO_U64(T_OFFSET, t_offset);
4369 PUT_SINFO_U64(RX_DROP_MISC, rx_dropped_misc);
4370 PUT_SINFO_U64(BEACON_RX, rx_beacon);
Johannes Berga76b1942014-11-17 14:12:22 +01004371 PUT_SINFO(BEACON_SIGNAL_AVG, rx_beacon_signal_avg, u8);
Johannes Berg319090b2014-11-17 14:08:11 +01004372
4373#undef PUT_SINFO
Johannes Bergd686b922016-04-26 09:54:11 +02004374#undef PUT_SINFO_U64
Johannes Berg6de39802014-12-19 12:34:00 +01004375
4376 if (sinfo->filled & BIT(NL80211_STA_INFO_TID_STATS)) {
4377 struct nlattr *tidsattr;
4378 int tid;
4379
4380 tidsattr = nla_nest_start(msg, NL80211_STA_INFO_TID_STATS);
4381 if (!tidsattr)
4382 goto nla_put_failure;
4383
4384 for (tid = 0; tid < IEEE80211_NUM_TIDS + 1; tid++) {
4385 struct cfg80211_tid_stats *tidstats;
4386 struct nlattr *tidattr;
4387
4388 tidstats = &sinfo->pertid[tid];
4389
4390 if (!tidstats->filled)
4391 continue;
4392
4393 tidattr = nla_nest_start(msg, tid + 1);
4394 if (!tidattr)
4395 goto nla_put_failure;
4396
Johannes Bergd686b922016-04-26 09:54:11 +02004397#define PUT_TIDVAL_U64(attr, memb) do { \
Johannes Berg6de39802014-12-19 12:34:00 +01004398 if (tidstats->filled & BIT(NL80211_TID_STATS_ ## attr) && \
Johannes Bergd686b922016-04-26 09:54:11 +02004399 nla_put_u64_64bit(msg, NL80211_TID_STATS_ ## attr, \
4400 tidstats->memb, NL80211_TID_STATS_PAD)) \
Johannes Berg6de39802014-12-19 12:34:00 +01004401 goto nla_put_failure; \
4402 } while (0)
4403
Johannes Bergd686b922016-04-26 09:54:11 +02004404 PUT_TIDVAL_U64(RX_MSDU, rx_msdu);
4405 PUT_TIDVAL_U64(TX_MSDU, tx_msdu);
4406 PUT_TIDVAL_U64(TX_MSDU_RETRIES, tx_msdu_retries);
4407 PUT_TIDVAL_U64(TX_MSDU_FAILED, tx_msdu_failed);
Johannes Berg6de39802014-12-19 12:34:00 +01004408
Johannes Bergd686b922016-04-26 09:54:11 +02004409#undef PUT_TIDVAL_U64
Johannes Berg6de39802014-12-19 12:34:00 +01004410 nla_nest_end(msg, tidattr);
4411 }
4412
4413 nla_nest_end(msg, tidsattr);
4414 }
4415
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004416 nla_nest_end(msg, sinfoattr);
Johannes Bergfd5b74d2007-12-19 02:03:36 +01004417
Johannes Berg319090b2014-11-17 14:08:11 +01004418 if (sinfo->assoc_req_ies_len &&
David S. Miller9360ffd2012-03-29 04:41:26 -04004419 nla_put(msg, NL80211_ATTR_IE, sinfo->assoc_req_ies_len,
4420 sinfo->assoc_req_ies))
4421 goto nla_put_failure;
Jouni Malinen50d3dfb2011-08-08 12:11:52 +03004422
Johannes Berg053c0952015-01-16 22:09:00 +01004423 genlmsg_end(msg, hdr);
4424 return 0;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01004425
4426 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07004427 genlmsg_cancel(msg, hdr);
4428 return -EMSGSIZE;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01004429}
4430
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004431static int nl80211_dump_station(struct sk_buff *skb,
Johannes Bergbba95fe2008-07-29 13:22:51 +02004432 struct netlink_callback *cb)
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004433{
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004434 struct station_info sinfo;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08004435 struct cfg80211_registered_device *rdev;
Johannes Berg97990a02013-04-19 01:02:55 +02004436 struct wireless_dev *wdev;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004437 u8 mac_addr[ETH_ALEN];
Johannes Berg97990a02013-04-19 01:02:55 +02004438 int sta_idx = cb->args[2];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004439 int err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004440
Johannes Bergea90e0d2017-03-15 14:26:04 +01004441 rtnl_lock();
Zhao, Gang1b8ec872014-04-21 12:53:02 +08004442 err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev);
Johannes Berg67748892010-10-04 21:14:06 +02004443 if (err)
Johannes Bergea90e0d2017-03-15 14:26:04 +01004444 goto out_err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004445
Johannes Berg97990a02013-04-19 01:02:55 +02004446 if (!wdev->netdev) {
4447 err = -EINVAL;
4448 goto out_err;
4449 }
4450
Zhao, Gang1b8ec872014-04-21 12:53:02 +08004451 if (!rdev->ops->dump_station) {
Jouni Malineneec60b02009-03-20 21:21:19 +02004452 err = -EOPNOTSUPP;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004453 goto out_err;
4454 }
4455
Johannes Bergbba95fe2008-07-29 13:22:51 +02004456 while (1) {
Jouni Malinenf612ced2011-08-11 11:46:22 +03004457 memset(&sinfo, 0, sizeof(sinfo));
Zhao, Gang1b8ec872014-04-21 12:53:02 +08004458 err = rdev_dump_station(rdev, wdev->netdev, sta_idx,
Hila Gonene35e4d22012-06-27 17:19:42 +03004459 mac_addr, &sinfo);
Johannes Bergbba95fe2008-07-29 13:22:51 +02004460 if (err == -ENOENT)
4461 break;
4462 if (err)
Johannes Berg3b858752009-03-12 09:55:09 +01004463 goto out_err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004464
Johannes Bergcf5ead82014-11-14 17:14:00 +01004465 if (nl80211_send_station(skb, NL80211_CMD_NEW_STATION,
Eric W. Biederman15e47302012-09-07 20:12:54 +00004466 NETLINK_CB(cb->skb).portid,
Johannes Bergbba95fe2008-07-29 13:22:51 +02004467 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08004468 rdev, wdev->netdev, mac_addr,
Johannes Bergbba95fe2008-07-29 13:22:51 +02004469 &sinfo) < 0)
4470 goto out;
4471
4472 sta_idx++;
4473 }
4474
Johannes Bergbba95fe2008-07-29 13:22:51 +02004475 out:
Johannes Berg97990a02013-04-19 01:02:55 +02004476 cb->args[2] = sta_idx;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004477 err = skb->len;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004478 out_err:
Johannes Bergea90e0d2017-03-15 14:26:04 +01004479 rtnl_unlock();
Johannes Bergbba95fe2008-07-29 13:22:51 +02004480
4481 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004482}
Johannes Bergfd5b74d2007-12-19 02:03:36 +01004483
Johannes Berg5727ef12007-12-19 02:03:34 +01004484static int nl80211_get_station(struct sk_buff *skb, struct genl_info *info)
4485{
Johannes Berg4c476992010-10-04 21:36:35 +02004486 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4487 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004488 struct station_info sinfo;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01004489 struct sk_buff *msg;
4490 u8 *mac_addr = NULL;
Johannes Berg4c476992010-10-04 21:36:35 +02004491 int err;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01004492
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004493 memset(&sinfo, 0, sizeof(sinfo));
Johannes Bergfd5b74d2007-12-19 02:03:36 +01004494
4495 if (!info->attrs[NL80211_ATTR_MAC])
4496 return -EINVAL;
4497
4498 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
4499
Johannes Berg4c476992010-10-04 21:36:35 +02004500 if (!rdev->ops->get_station)
4501 return -EOPNOTSUPP;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01004502
Hila Gonene35e4d22012-06-27 17:19:42 +03004503 err = rdev_get_station(rdev, dev, mac_addr, &sinfo);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004504 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02004505 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004506
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07004507 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Bergfd5b74d2007-12-19 02:03:36 +01004508 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02004509 return -ENOMEM;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01004510
Johannes Bergcf5ead82014-11-14 17:14:00 +01004511 if (nl80211_send_station(msg, NL80211_CMD_NEW_STATION,
4512 info->snd_portid, info->snd_seq, 0,
John W. Linville66266b32012-03-15 13:25:41 -04004513 rdev, dev, mac_addr, &sinfo) < 0) {
Johannes Berg4c476992010-10-04 21:36:35 +02004514 nlmsg_free(msg);
4515 return -ENOBUFS;
4516 }
Johannes Bergfd5b74d2007-12-19 02:03:36 +01004517
Johannes Berg4c476992010-10-04 21:36:35 +02004518 return genlmsg_reply(msg, info);
Johannes Berg5727ef12007-12-19 02:03:34 +01004519}
4520
Johannes Berg77ee7c82013-02-15 00:48:33 +01004521int cfg80211_check_station_change(struct wiphy *wiphy,
4522 struct station_parameters *params,
4523 enum cfg80211_station_type statype)
4524{
Ayala Bekere4208422015-10-23 11:20:06 +03004525 if (params->listen_interval != -1 &&
4526 statype != CFG80211_STA_AP_CLIENT_UNASSOC)
Johannes Berg77ee7c82013-02-15 00:48:33 +01004527 return -EINVAL;
Ayala Bekere4208422015-10-23 11:20:06 +03004528
Ayala Beker17b94242016-03-17 15:41:38 +02004529 if (params->support_p2p_ps != -1 &&
4530 statype != CFG80211_STA_AP_CLIENT_UNASSOC)
4531 return -EINVAL;
4532
Arik Nemtsovc72e1142014-07-17 17:14:29 +03004533 if (params->aid &&
Ayala Bekere4208422015-10-23 11:20:06 +03004534 !(params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) &&
4535 statype != CFG80211_STA_AP_CLIENT_UNASSOC)
Johannes Berg77ee7c82013-02-15 00:48:33 +01004536 return -EINVAL;
4537
4538 /* When you run into this, adjust the code below for the new flag */
4539 BUILD_BUG_ON(NL80211_STA_FLAG_MAX != 7);
4540
4541 switch (statype) {
Thomas Pederseneef941e2013-03-04 13:06:11 -08004542 case CFG80211_STA_MESH_PEER_KERNEL:
4543 case CFG80211_STA_MESH_PEER_USER:
Johannes Berg77ee7c82013-02-15 00:48:33 +01004544 /*
4545 * No ignoring the TDLS flag here -- the userspace mesh
4546 * code doesn't have the bug of including TDLS in the
4547 * mask everywhere.
4548 */
4549 if (params->sta_flags_mask &
4550 ~(BIT(NL80211_STA_FLAG_AUTHENTICATED) |
4551 BIT(NL80211_STA_FLAG_MFP) |
4552 BIT(NL80211_STA_FLAG_AUTHORIZED)))
4553 return -EINVAL;
4554 break;
4555 case CFG80211_STA_TDLS_PEER_SETUP:
4556 case CFG80211_STA_TDLS_PEER_ACTIVE:
4557 if (!(params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)))
4558 return -EINVAL;
4559 /* ignore since it can't change */
4560 params->sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER);
4561 break;
4562 default:
4563 /* disallow mesh-specific things */
4564 if (params->plink_action != NL80211_PLINK_ACTION_NO_ACTION)
4565 return -EINVAL;
4566 if (params->local_pm)
4567 return -EINVAL;
4568 if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE)
4569 return -EINVAL;
4570 }
4571
4572 if (statype != CFG80211_STA_TDLS_PEER_SETUP &&
4573 statype != CFG80211_STA_TDLS_PEER_ACTIVE) {
4574 /* TDLS can't be set, ... */
4575 if (params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))
4576 return -EINVAL;
4577 /*
4578 * ... but don't bother the driver with it. This works around
4579 * a hostapd/wpa_supplicant issue -- it always includes the
4580 * TLDS_PEER flag in the mask even for AP mode.
4581 */
4582 params->sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER);
4583 }
4584
Ayala Beker47edb112015-09-21 15:49:53 +03004585 if (statype != CFG80211_STA_TDLS_PEER_SETUP &&
4586 statype != CFG80211_STA_AP_CLIENT_UNASSOC) {
Johannes Berg77ee7c82013-02-15 00:48:33 +01004587 /* reject other things that can't change */
4588 if (params->sta_modify_mask & STATION_PARAM_APPLY_UAPSD)
4589 return -EINVAL;
4590 if (params->sta_modify_mask & STATION_PARAM_APPLY_CAPABILITY)
4591 return -EINVAL;
4592 if (params->supported_rates)
4593 return -EINVAL;
4594 if (params->ext_capab || params->ht_capa || params->vht_capa)
4595 return -EINVAL;
4596 }
4597
Ayala Beker47edb112015-09-21 15:49:53 +03004598 if (statype != CFG80211_STA_AP_CLIENT &&
4599 statype != CFG80211_STA_AP_CLIENT_UNASSOC) {
Johannes Berg77ee7c82013-02-15 00:48:33 +01004600 if (params->vlan)
4601 return -EINVAL;
4602 }
4603
4604 switch (statype) {
4605 case CFG80211_STA_AP_MLME_CLIENT:
4606 /* Use this only for authorizing/unauthorizing a station */
4607 if (!(params->sta_flags_mask & BIT(NL80211_STA_FLAG_AUTHORIZED)))
4608 return -EOPNOTSUPP;
4609 break;
4610 case CFG80211_STA_AP_CLIENT:
Ayala Beker47edb112015-09-21 15:49:53 +03004611 case CFG80211_STA_AP_CLIENT_UNASSOC:
Johannes Berg77ee7c82013-02-15 00:48:33 +01004612 /* accept only the listed bits */
4613 if (params->sta_flags_mask &
4614 ~(BIT(NL80211_STA_FLAG_AUTHORIZED) |
4615 BIT(NL80211_STA_FLAG_AUTHENTICATED) |
4616 BIT(NL80211_STA_FLAG_ASSOCIATED) |
4617 BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) |
4618 BIT(NL80211_STA_FLAG_WME) |
4619 BIT(NL80211_STA_FLAG_MFP)))
4620 return -EINVAL;
4621
4622 /* but authenticated/associated only if driver handles it */
4623 if (!(wiphy->features & NL80211_FEATURE_FULL_AP_CLIENT_STATE) &&
4624 params->sta_flags_mask &
4625 (BIT(NL80211_STA_FLAG_AUTHENTICATED) |
4626 BIT(NL80211_STA_FLAG_ASSOCIATED)))
4627 return -EINVAL;
4628 break;
4629 case CFG80211_STA_IBSS:
4630 case CFG80211_STA_AP_STA:
4631 /* reject any changes other than AUTHORIZED */
4632 if (params->sta_flags_mask & ~BIT(NL80211_STA_FLAG_AUTHORIZED))
4633 return -EINVAL;
4634 break;
4635 case CFG80211_STA_TDLS_PEER_SETUP:
4636 /* reject any changes other than AUTHORIZED or WME */
4637 if (params->sta_flags_mask & ~(BIT(NL80211_STA_FLAG_AUTHORIZED) |
4638 BIT(NL80211_STA_FLAG_WME)))
4639 return -EINVAL;
4640 /* force (at least) rates when authorizing */
4641 if (params->sta_flags_set & BIT(NL80211_STA_FLAG_AUTHORIZED) &&
4642 !params->supported_rates)
4643 return -EINVAL;
4644 break;
4645 case CFG80211_STA_TDLS_PEER_ACTIVE:
4646 /* reject any changes */
4647 return -EINVAL;
Thomas Pederseneef941e2013-03-04 13:06:11 -08004648 case CFG80211_STA_MESH_PEER_KERNEL:
Johannes Berg77ee7c82013-02-15 00:48:33 +01004649 if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE)
4650 return -EINVAL;
4651 break;
Thomas Pederseneef941e2013-03-04 13:06:11 -08004652 case CFG80211_STA_MESH_PEER_USER:
Chun-Yeow Yeoh42925042015-04-18 01:30:02 +08004653 if (params->plink_action != NL80211_PLINK_ACTION_NO_ACTION &&
4654 params->plink_action != NL80211_PLINK_ACTION_BLOCK)
Johannes Berg77ee7c82013-02-15 00:48:33 +01004655 return -EINVAL;
4656 break;
4657 }
4658
Beni Lev06f7c882016-07-19 19:28:56 +03004659 /*
4660 * Older kernel versions ignored this attribute entirely, so don't
4661 * reject attempts to update it but mark it as unused instead so the
4662 * driver won't look at the data.
4663 */
4664 if (statype != CFG80211_STA_AP_CLIENT_UNASSOC &&
4665 statype != CFG80211_STA_TDLS_PEER_SETUP)
4666 params->opmode_notif_used = false;
4667
Johannes Berg77ee7c82013-02-15 00:48:33 +01004668 return 0;
4669}
4670EXPORT_SYMBOL(cfg80211_check_station_change);
4671
Johannes Berg5727ef12007-12-19 02:03:34 +01004672/*
Felix Fietkauc258d2d2009-11-11 17:23:31 +01004673 * Get vlan interface making sure it is running and on the right wiphy.
Johannes Berg5727ef12007-12-19 02:03:34 +01004674 */
Johannes Berg80b99892011-11-18 16:23:01 +01004675static struct net_device *get_vlan(struct genl_info *info,
4676 struct cfg80211_registered_device *rdev)
Johannes Berg5727ef12007-12-19 02:03:34 +01004677{
Johannes Berg463d0182009-07-14 00:33:35 +02004678 struct nlattr *vlanattr = info->attrs[NL80211_ATTR_STA_VLAN];
Johannes Berg80b99892011-11-18 16:23:01 +01004679 struct net_device *v;
4680 int ret;
Johannes Berg5727ef12007-12-19 02:03:34 +01004681
Johannes Berg80b99892011-11-18 16:23:01 +01004682 if (!vlanattr)
4683 return NULL;
4684
4685 v = dev_get_by_index(genl_info_net(info), nla_get_u32(vlanattr));
4686 if (!v)
4687 return ERR_PTR(-ENODEV);
4688
4689 if (!v->ieee80211_ptr || v->ieee80211_ptr->wiphy != &rdev->wiphy) {
4690 ret = -EINVAL;
4691 goto error;
Johannes Berg5727ef12007-12-19 02:03:34 +01004692 }
Johannes Berg80b99892011-11-18 16:23:01 +01004693
Johannes Berg77ee7c82013-02-15 00:48:33 +01004694 if (v->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN &&
4695 v->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
4696 v->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) {
4697 ret = -EINVAL;
4698 goto error;
4699 }
4700
Johannes Berg80b99892011-11-18 16:23:01 +01004701 if (!netif_running(v)) {
4702 ret = -ENETDOWN;
4703 goto error;
4704 }
4705
4706 return v;
4707 error:
4708 dev_put(v);
4709 return ERR_PTR(ret);
Johannes Berg5727ef12007-12-19 02:03:34 +01004710}
4711
Johannes Berg94e860f2014-01-20 23:58:15 +01004712static const struct nla_policy
4713nl80211_sta_wme_policy[NL80211_STA_WME_MAX + 1] = {
Jouni Malinendf881292013-02-14 21:10:54 +02004714 [NL80211_STA_WME_UAPSD_QUEUES] = { .type = NLA_U8 },
4715 [NL80211_STA_WME_MAX_SP] = { .type = NLA_U8 },
4716};
4717
Johannes Bergff276692013-02-15 00:09:01 +01004718static int nl80211_parse_sta_wme(struct genl_info *info,
4719 struct station_parameters *params)
Jouni Malinendf881292013-02-14 21:10:54 +02004720{
Jouni Malinendf881292013-02-14 21:10:54 +02004721 struct nlattr *tb[NL80211_STA_WME_MAX + 1];
4722 struct nlattr *nla;
4723 int err;
4724
Jouni Malinendf881292013-02-14 21:10:54 +02004725 /* parse WME attributes if present */
4726 if (!info->attrs[NL80211_ATTR_STA_WME])
4727 return 0;
4728
4729 nla = info->attrs[NL80211_ATTR_STA_WME];
4730 err = nla_parse_nested(tb, NL80211_STA_WME_MAX, nla,
4731 nl80211_sta_wme_policy);
4732 if (err)
4733 return err;
4734
4735 if (tb[NL80211_STA_WME_UAPSD_QUEUES])
4736 params->uapsd_queues = nla_get_u8(
4737 tb[NL80211_STA_WME_UAPSD_QUEUES]);
4738 if (params->uapsd_queues & ~IEEE80211_WMM_IE_STA_QOSINFO_AC_MASK)
4739 return -EINVAL;
4740
4741 if (tb[NL80211_STA_WME_MAX_SP])
4742 params->max_sp = nla_get_u8(tb[NL80211_STA_WME_MAX_SP]);
4743
4744 if (params->max_sp & ~IEEE80211_WMM_IE_STA_QOSINFO_SP_MASK)
4745 return -EINVAL;
4746
4747 params->sta_modify_mask |= STATION_PARAM_APPLY_UAPSD;
4748
4749 return 0;
4750}
4751
Sunil Duttc01fc9a2013-10-09 20:45:21 +05304752static int nl80211_parse_sta_channel_info(struct genl_info *info,
4753 struct station_parameters *params)
4754{
4755 if (info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]) {
4756 params->supported_channels =
4757 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]);
4758 params->supported_channels_len =
4759 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]);
4760 /*
4761 * Need to include at least one (first channel, number of
4762 * channels) tuple for each subband, and must have proper
4763 * tuples for the rest of the data as well.
4764 */
4765 if (params->supported_channels_len < 2)
4766 return -EINVAL;
4767 if (params->supported_channels_len % 2)
4768 return -EINVAL;
4769 }
4770
4771 if (info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]) {
4772 params->supported_oper_classes =
4773 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]);
4774 params->supported_oper_classes_len =
4775 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]);
4776 /*
4777 * The value of the Length field of the Supported Operating
4778 * Classes element is between 2 and 253.
4779 */
4780 if (params->supported_oper_classes_len < 2 ||
4781 params->supported_oper_classes_len > 253)
4782 return -EINVAL;
4783 }
4784 return 0;
4785}
4786
Johannes Bergff276692013-02-15 00:09:01 +01004787static int nl80211_set_station_tdls(struct genl_info *info,
4788 struct station_parameters *params)
4789{
Sunil Duttc01fc9a2013-10-09 20:45:21 +05304790 int err;
Johannes Bergff276692013-02-15 00:09:01 +01004791 /* Dummy STA entry gets updated once the peer capabilities are known */
Jouni Malinen5e4b6f52013-05-16 20:11:08 +03004792 if (info->attrs[NL80211_ATTR_PEER_AID])
4793 params->aid = nla_get_u16(info->attrs[NL80211_ATTR_PEER_AID]);
Johannes Bergff276692013-02-15 00:09:01 +01004794 if (info->attrs[NL80211_ATTR_HT_CAPABILITY])
4795 params->ht_capa =
4796 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]);
4797 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY])
4798 params->vht_capa =
4799 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]);
4800
Sunil Duttc01fc9a2013-10-09 20:45:21 +05304801 err = nl80211_parse_sta_channel_info(info, params);
4802 if (err)
4803 return err;
4804
Johannes Bergff276692013-02-15 00:09:01 +01004805 return nl80211_parse_sta_wme(info, params);
4806}
4807
Johannes Berg5727ef12007-12-19 02:03:34 +01004808static int nl80211_set_station(struct sk_buff *skb, struct genl_info *info)
4809{
Johannes Berg4c476992010-10-04 21:36:35 +02004810 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg4c476992010-10-04 21:36:35 +02004811 struct net_device *dev = info->user_ptr[1];
Johannes Berg5727ef12007-12-19 02:03:34 +01004812 struct station_parameters params;
Johannes Berg77ee7c82013-02-15 00:48:33 +01004813 u8 *mac_addr;
4814 int err;
Johannes Berg5727ef12007-12-19 02:03:34 +01004815
4816 memset(&params, 0, sizeof(params));
4817
Johannes Berg77ee7c82013-02-15 00:48:33 +01004818 if (!rdev->ops->change_station)
4819 return -EOPNOTSUPP;
4820
Ayala Bekere4208422015-10-23 11:20:06 +03004821 /*
4822 * AID and listen_interval properties can be set only for unassociated
4823 * station. Include these parameters here and will check them in
4824 * cfg80211_check_station_change().
4825 */
Ayala Bekera9bc31e2015-11-26 16:26:12 +01004826 if (info->attrs[NL80211_ATTR_STA_AID])
4827 params.aid = nla_get_u16(info->attrs[NL80211_ATTR_STA_AID]);
Ayala Bekere4208422015-10-23 11:20:06 +03004828
4829 if (info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL])
4830 params.listen_interval =
4831 nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]);
4832 else
4833 params.listen_interval = -1;
Johannes Berg5727ef12007-12-19 02:03:34 +01004834
Ayala Beker17b94242016-03-17 15:41:38 +02004835 if (info->attrs[NL80211_ATTR_STA_SUPPORT_P2P_PS]) {
4836 u8 tmp;
4837
4838 tmp = nla_get_u8(info->attrs[NL80211_ATTR_STA_SUPPORT_P2P_PS]);
4839 if (tmp >= NUM_NL80211_P2P_PS_STATUS)
4840 return -EINVAL;
4841
4842 params.support_p2p_ps = tmp;
4843 } else {
4844 params.support_p2p_ps = -1;
4845 }
4846
Johannes Berg5727ef12007-12-19 02:03:34 +01004847 if (!info->attrs[NL80211_ATTR_MAC])
4848 return -EINVAL;
4849
4850 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
4851
4852 if (info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) {
4853 params.supported_rates =
4854 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
4855 params.supported_rates_len =
4856 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
4857 }
4858
Jouni Malinen9d62a982013-02-14 21:10:13 +02004859 if (info->attrs[NL80211_ATTR_STA_CAPABILITY]) {
4860 params.capability =
4861 nla_get_u16(info->attrs[NL80211_ATTR_STA_CAPABILITY]);
4862 params.sta_modify_mask |= STATION_PARAM_APPLY_CAPABILITY;
4863 }
4864
4865 if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]) {
4866 params.ext_capab =
4867 nla_data(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
4868 params.ext_capab_len =
4869 nla_len(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
4870 }
4871
Johannes Bergbdd3ae32012-01-02 13:30:03 +01004872 if (parse_station_flags(info, dev->ieee80211_ptr->iftype, &params))
Johannes Berg5727ef12007-12-19 02:03:34 +01004873 return -EINVAL;
4874
Johannes Bergf8bacc22013-02-14 23:27:01 +01004875 if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) {
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004876 params.plink_action =
Johannes Bergf8bacc22013-02-14 23:27:01 +01004877 nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]);
4878 if (params.plink_action >= NUM_NL80211_PLINK_ACTIONS)
4879 return -EINVAL;
4880 }
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004881
Johannes Bergf8bacc22013-02-14 23:27:01 +01004882 if (info->attrs[NL80211_ATTR_STA_PLINK_STATE]) {
Javier Cardona9c3990a2011-05-03 16:57:11 -07004883 params.plink_state =
Johannes Bergf8bacc22013-02-14 23:27:01 +01004884 nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_STATE]);
4885 if (params.plink_state >= NUM_NL80211_PLINK_STATES)
4886 return -EINVAL;
Masashi Honma7d27a0b2016-07-01 10:19:34 +09004887 if (info->attrs[NL80211_ATTR_MESH_PEER_AID]) {
4888 params.peer_aid = nla_get_u16(
4889 info->attrs[NL80211_ATTR_MESH_PEER_AID]);
4890 if (params.peer_aid > IEEE80211_MAX_AID)
4891 return -EINVAL;
4892 }
Johannes Bergf8bacc22013-02-14 23:27:01 +01004893 params.sta_modify_mask |= STATION_PARAM_APPLY_PLINK_STATE;
4894 }
Javier Cardona9c3990a2011-05-03 16:57:11 -07004895
Marco Porsch3b1c5a52013-01-07 16:04:52 +01004896 if (info->attrs[NL80211_ATTR_LOCAL_MESH_POWER_MODE]) {
4897 enum nl80211_mesh_power_mode pm = nla_get_u32(
4898 info->attrs[NL80211_ATTR_LOCAL_MESH_POWER_MODE]);
4899
4900 if (pm <= NL80211_MESH_POWER_UNKNOWN ||
4901 pm > NL80211_MESH_POWER_MAX)
4902 return -EINVAL;
4903
4904 params.local_pm = pm;
4905 }
4906
Beni Lev06f7c882016-07-19 19:28:56 +03004907 if (info->attrs[NL80211_ATTR_OPMODE_NOTIF]) {
4908 params.opmode_notif_used = true;
4909 params.opmode_notif =
4910 nla_get_u8(info->attrs[NL80211_ATTR_OPMODE_NOTIF]);
4911 }
4912
Johannes Berg77ee7c82013-02-15 00:48:33 +01004913 /* Include parameters for TDLS peer (will check later) */
4914 err = nl80211_set_station_tdls(info, &params);
4915 if (err)
4916 return err;
4917
4918 params.vlan = get_vlan(info, rdev);
4919 if (IS_ERR(params.vlan))
4920 return PTR_ERR(params.vlan);
4921
Johannes Berga97f4422009-06-18 17:23:43 +02004922 switch (dev->ieee80211_ptr->iftype) {
4923 case NL80211_IFTYPE_AP:
4924 case NL80211_IFTYPE_AP_VLAN:
Johannes Berg074ac8d2010-09-16 14:58:22 +02004925 case NL80211_IFTYPE_P2P_GO:
Johannes Berg074ac8d2010-09-16 14:58:22 +02004926 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Berga97f4422009-06-18 17:23:43 +02004927 case NL80211_IFTYPE_STATION:
Antonio Quartulli267335d2012-01-31 20:25:47 +01004928 case NL80211_IFTYPE_ADHOC:
Johannes Berga97f4422009-06-18 17:23:43 +02004929 case NL80211_IFTYPE_MESH_POINT:
Johannes Berga97f4422009-06-18 17:23:43 +02004930 break;
4931 default:
Johannes Berg77ee7c82013-02-15 00:48:33 +01004932 err = -EOPNOTSUPP;
4933 goto out_put_vlan;
Johannes Berg034d6552009-05-27 10:35:29 +02004934 }
4935
Johannes Berg77ee7c82013-02-15 00:48:33 +01004936 /* driver will call cfg80211_check_station_change() */
Hila Gonene35e4d22012-06-27 17:19:42 +03004937 err = rdev_change_station(rdev, dev, mac_addr, &params);
Johannes Berg5727ef12007-12-19 02:03:34 +01004938
Johannes Berg77ee7c82013-02-15 00:48:33 +01004939 out_put_vlan:
Johannes Berg5727ef12007-12-19 02:03:34 +01004940 if (params.vlan)
4941 dev_put(params.vlan);
Johannes Berg3b858752009-03-12 09:55:09 +01004942
Johannes Berg5727ef12007-12-19 02:03:34 +01004943 return err;
4944}
4945
4946static int nl80211_new_station(struct sk_buff *skb, struct genl_info *info)
4947{
Johannes Berg4c476992010-10-04 21:36:35 +02004948 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg5727ef12007-12-19 02:03:34 +01004949 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02004950 struct net_device *dev = info->user_ptr[1];
Johannes Berg5727ef12007-12-19 02:03:34 +01004951 struct station_parameters params;
4952 u8 *mac_addr = NULL;
Johannes Bergbda95eb2015-11-26 16:26:13 +01004953 u32 auth_assoc = BIT(NL80211_STA_FLAG_AUTHENTICATED) |
4954 BIT(NL80211_STA_FLAG_ASSOCIATED);
Johannes Berg5727ef12007-12-19 02:03:34 +01004955
4956 memset(&params, 0, sizeof(params));
4957
Johannes Berg984c3112013-02-14 23:43:25 +01004958 if (!rdev->ops->add_station)
4959 return -EOPNOTSUPP;
4960
Johannes Berg5727ef12007-12-19 02:03:34 +01004961 if (!info->attrs[NL80211_ATTR_MAC])
4962 return -EINVAL;
4963
Johannes Berg5727ef12007-12-19 02:03:34 +01004964 if (!info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL])
4965 return -EINVAL;
4966
4967 if (!info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES])
4968 return -EINVAL;
4969
Jouni Malinen5e4b6f52013-05-16 20:11:08 +03004970 if (!info->attrs[NL80211_ATTR_STA_AID] &&
4971 !info->attrs[NL80211_ATTR_PEER_AID])
Thadeu Lima de Souza Cascardo0e956c12010-02-12 12:34:50 -02004972 return -EINVAL;
4973
Johannes Berg5727ef12007-12-19 02:03:34 +01004974 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
4975 params.supported_rates =
4976 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
4977 params.supported_rates_len =
4978 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
4979 params.listen_interval =
4980 nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]);
Johannes Berg51b50fb2009-05-24 16:42:30 +02004981
Ayala Beker17b94242016-03-17 15:41:38 +02004982 if (info->attrs[NL80211_ATTR_STA_SUPPORT_P2P_PS]) {
4983 u8 tmp;
4984
4985 tmp = nla_get_u8(info->attrs[NL80211_ATTR_STA_SUPPORT_P2P_PS]);
4986 if (tmp >= NUM_NL80211_P2P_PS_STATUS)
4987 return -EINVAL;
4988
4989 params.support_p2p_ps = tmp;
4990 } else {
4991 /*
4992 * if not specified, assume it's supported for P2P GO interface,
4993 * and is NOT supported for AP interface
4994 */
4995 params.support_p2p_ps =
4996 dev->ieee80211_ptr->iftype == NL80211_IFTYPE_P2P_GO;
4997 }
4998
Jouni Malinen3d124ea2013-05-27 18:24:02 +03004999 if (info->attrs[NL80211_ATTR_PEER_AID])
Jouni Malinen5e4b6f52013-05-16 20:11:08 +03005000 params.aid = nla_get_u16(info->attrs[NL80211_ATTR_PEER_AID]);
Jouni Malinen3d124ea2013-05-27 18:24:02 +03005001 else
5002 params.aid = nla_get_u16(info->attrs[NL80211_ATTR_STA_AID]);
Thadeu Lima de Souza Cascardo0e956c12010-02-12 12:34:50 -02005003 if (!params.aid || params.aid > IEEE80211_MAX_AID)
5004 return -EINVAL;
Johannes Berg51b50fb2009-05-24 16:42:30 +02005005
Jouni Malinen9d62a982013-02-14 21:10:13 +02005006 if (info->attrs[NL80211_ATTR_STA_CAPABILITY]) {
5007 params.capability =
5008 nla_get_u16(info->attrs[NL80211_ATTR_STA_CAPABILITY]);
5009 params.sta_modify_mask |= STATION_PARAM_APPLY_CAPABILITY;
5010 }
5011
5012 if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]) {
5013 params.ext_capab =
5014 nla_data(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
5015 params.ext_capab_len =
5016 nla_len(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
5017 }
5018
Jouni Malinen36aedc92008-08-25 11:58:58 +03005019 if (info->attrs[NL80211_ATTR_HT_CAPABILITY])
5020 params.ht_capa =
5021 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]);
Johannes Berg5727ef12007-12-19 02:03:34 +01005022
Mahesh Palivelaf461be3e2012-10-11 08:04:52 +00005023 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY])
5024 params.vht_capa =
5025 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]);
5026
Marek Kwaczynski60f4a7b2013-12-03 10:04:59 +01005027 if (info->attrs[NL80211_ATTR_OPMODE_NOTIF]) {
5028 params.opmode_notif_used = true;
5029 params.opmode_notif =
5030 nla_get_u8(info->attrs[NL80211_ATTR_OPMODE_NOTIF]);
5031 }
5032
Johannes Bergf8bacc22013-02-14 23:27:01 +01005033 if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) {
Javier Cardona96b78df2011-04-07 15:08:33 -07005034 params.plink_action =
Johannes Bergf8bacc22013-02-14 23:27:01 +01005035 nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]);
5036 if (params.plink_action >= NUM_NL80211_PLINK_ACTIONS)
5037 return -EINVAL;
5038 }
Javier Cardona96b78df2011-04-07 15:08:33 -07005039
Sunil Duttc01fc9a2013-10-09 20:45:21 +05305040 err = nl80211_parse_sta_channel_info(info, &params);
5041 if (err)
5042 return err;
5043
Johannes Bergff276692013-02-15 00:09:01 +01005044 err = nl80211_parse_sta_wme(info, &params);
5045 if (err)
5046 return err;
Johannes Bergbdd90d52011-12-14 12:20:27 +01005047
Johannes Bergbdd3ae32012-01-02 13:30:03 +01005048 if (parse_station_flags(info, dev->ieee80211_ptr->iftype, &params))
Johannes Berg5727ef12007-12-19 02:03:34 +01005049 return -EINVAL;
5050
Johannes Berg496fcc22015-03-12 08:53:27 +02005051 /* HT/VHT requires QoS, but if we don't have that just ignore HT/VHT
5052 * as userspace might just pass through the capabilities from the IEs
5053 * directly, rather than enforcing this restriction and returning an
5054 * error in this case.
5055 */
5056 if (!(params.sta_flags_set & BIT(NL80211_STA_FLAG_WME))) {
5057 params.ht_capa = NULL;
5058 params.vht_capa = NULL;
5059 }
5060
Johannes Berg77ee7c82013-02-15 00:48:33 +01005061 /* When you run into this, adjust the code below for the new flag */
5062 BUILD_BUG_ON(NL80211_STA_FLAG_MAX != 7);
5063
Johannes Bergbdd90d52011-12-14 12:20:27 +01005064 switch (dev->ieee80211_ptr->iftype) {
5065 case NL80211_IFTYPE_AP:
5066 case NL80211_IFTYPE_AP_VLAN:
5067 case NL80211_IFTYPE_P2P_GO:
Johannes Berg984c3112013-02-14 23:43:25 +01005068 /* ignore WME attributes if iface/sta is not capable */
5069 if (!(rdev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) ||
5070 !(params.sta_flags_set & BIT(NL80211_STA_FLAG_WME)))
5071 params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD;
Eliad Pellerc75786c2011-08-23 14:37:46 +03005072
Johannes Bergbdd90d52011-12-14 12:20:27 +01005073 /* TDLS peers cannot be added */
Jouni Malinen3d124ea2013-05-27 18:24:02 +03005074 if ((params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) ||
5075 info->attrs[NL80211_ATTR_PEER_AID])
Johannes Berg4319e192011-09-07 11:50:48 +02005076 return -EINVAL;
Johannes Bergbdd90d52011-12-14 12:20:27 +01005077 /* but don't bother the driver with it */
5078 params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER);
Eliad Pellerc75786c2011-08-23 14:37:46 +03005079
Johannes Bergd582cff2012-10-26 17:53:44 +02005080 /* allow authenticated/associated only if driver handles it */
5081 if (!(rdev->wiphy.features &
5082 NL80211_FEATURE_FULL_AP_CLIENT_STATE) &&
Johannes Bergbda95eb2015-11-26 16:26:13 +01005083 params.sta_flags_mask & auth_assoc)
Johannes Bergd582cff2012-10-26 17:53:44 +02005084 return -EINVAL;
5085
Johannes Bergbda95eb2015-11-26 16:26:13 +01005086 /* Older userspace, or userspace wanting to be compatible with
5087 * !NL80211_FEATURE_FULL_AP_CLIENT_STATE, will not set the auth
5088 * and assoc flags in the mask, but assumes the station will be
5089 * added as associated anyway since this was the required driver
5090 * behaviour before NL80211_FEATURE_FULL_AP_CLIENT_STATE was
5091 * introduced.
5092 * In order to not bother drivers with this quirk in the API
5093 * set the flags in both the mask and set for new stations in
5094 * this case.
5095 */
5096 if (!(params.sta_flags_mask & auth_assoc)) {
5097 params.sta_flags_mask |= auth_assoc;
5098 params.sta_flags_set |= auth_assoc;
5099 }
5100
Johannes Bergbdd90d52011-12-14 12:20:27 +01005101 /* must be last in here for error handling */
5102 params.vlan = get_vlan(info, rdev);
5103 if (IS_ERR(params.vlan))
5104 return PTR_ERR(params.vlan);
5105 break;
5106 case NL80211_IFTYPE_MESH_POINT:
Johannes Berg984c3112013-02-14 23:43:25 +01005107 /* ignore uAPSD data */
5108 params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD;
5109
Johannes Bergd582cff2012-10-26 17:53:44 +02005110 /* associated is disallowed */
5111 if (params.sta_flags_mask & BIT(NL80211_STA_FLAG_ASSOCIATED))
5112 return -EINVAL;
Johannes Bergbdd90d52011-12-14 12:20:27 +01005113 /* TDLS peers cannot be added */
Jouni Malinen3d124ea2013-05-27 18:24:02 +03005114 if ((params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) ||
5115 info->attrs[NL80211_ATTR_PEER_AID])
Johannes Berg4319e192011-09-07 11:50:48 +02005116 return -EINVAL;
Johannes Bergbdd90d52011-12-14 12:20:27 +01005117 break;
5118 case NL80211_IFTYPE_STATION:
Johannes Berg93d08f02013-03-04 09:29:46 +01005119 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Berg984c3112013-02-14 23:43:25 +01005120 /* ignore uAPSD data */
5121 params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD;
5122
Johannes Berg77ee7c82013-02-15 00:48:33 +01005123 /* these are disallowed */
5124 if (params.sta_flags_mask &
5125 (BIT(NL80211_STA_FLAG_ASSOCIATED) |
5126 BIT(NL80211_STA_FLAG_AUTHENTICATED)))
Johannes Bergd582cff2012-10-26 17:53:44 +02005127 return -EINVAL;
Johannes Bergbdd90d52011-12-14 12:20:27 +01005128 /* Only TDLS peers can be added */
5129 if (!(params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)))
5130 return -EINVAL;
5131 /* Can only add if TDLS ... */
5132 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS))
5133 return -EOPNOTSUPP;
5134 /* ... with external setup is supported */
5135 if (!(rdev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP))
5136 return -EOPNOTSUPP;
Johannes Berg77ee7c82013-02-15 00:48:33 +01005137 /*
5138 * Older wpa_supplicant versions always mark the TDLS peer
5139 * as authorized, but it shouldn't yet be.
5140 */
5141 params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_AUTHORIZED);
Johannes Bergbdd90d52011-12-14 12:20:27 +01005142 break;
5143 default:
5144 return -EOPNOTSUPP;
Eliad Pellerc75786c2011-08-23 14:37:46 +03005145 }
5146
Johannes Bergbdd90d52011-12-14 12:20:27 +01005147 /* be aware of params.vlan when changing code here */
Johannes Berg5727ef12007-12-19 02:03:34 +01005148
Hila Gonene35e4d22012-06-27 17:19:42 +03005149 err = rdev_add_station(rdev, dev, mac_addr, &params);
Johannes Berg5727ef12007-12-19 02:03:34 +01005150
Johannes Berg5727ef12007-12-19 02:03:34 +01005151 if (params.vlan)
5152 dev_put(params.vlan);
Johannes Berg5727ef12007-12-19 02:03:34 +01005153 return err;
5154}
5155
5156static int nl80211_del_station(struct sk_buff *skb, struct genl_info *info)
5157{
Johannes Berg4c476992010-10-04 21:36:35 +02005158 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5159 struct net_device *dev = info->user_ptr[1];
Jouni Malinen89c771e2014-10-10 20:52:40 +03005160 struct station_del_parameters params;
5161
5162 memset(&params, 0, sizeof(params));
Johannes Berg5727ef12007-12-19 02:03:34 +01005163
5164 if (info->attrs[NL80211_ATTR_MAC])
Jouni Malinen89c771e2014-10-10 20:52:40 +03005165 params.mac = nla_data(info->attrs[NL80211_ATTR_MAC]);
Johannes Berg5727ef12007-12-19 02:03:34 +01005166
Johannes Berge80cf852009-05-11 14:43:13 +02005167 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
Marco Porschd5d9de02010-03-30 10:00:16 +02005168 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN &&
Johannes Berg074ac8d2010-09-16 14:58:22 +02005169 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT &&
Johannes Berg4c476992010-10-04 21:36:35 +02005170 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
5171 return -EINVAL;
Johannes Berge80cf852009-05-11 14:43:13 +02005172
Johannes Berg4c476992010-10-04 21:36:35 +02005173 if (!rdev->ops->del_station)
5174 return -EOPNOTSUPP;
Johannes Berg5727ef12007-12-19 02:03:34 +01005175
Jouni Malinen98856862014-10-20 13:20:45 +03005176 if (info->attrs[NL80211_ATTR_MGMT_SUBTYPE]) {
5177 params.subtype =
5178 nla_get_u8(info->attrs[NL80211_ATTR_MGMT_SUBTYPE]);
5179 if (params.subtype != IEEE80211_STYPE_DISASSOC >> 4 &&
5180 params.subtype != IEEE80211_STYPE_DEAUTH >> 4)
5181 return -EINVAL;
5182 } else {
5183 /* Default to Deauthentication frame */
5184 params.subtype = IEEE80211_STYPE_DEAUTH >> 4;
5185 }
5186
5187 if (info->attrs[NL80211_ATTR_REASON_CODE]) {
5188 params.reason_code =
5189 nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
5190 if (params.reason_code == 0)
5191 return -EINVAL; /* 0 is reserved */
5192 } else {
5193 /* Default to reason code 2 */
5194 params.reason_code = WLAN_REASON_PREV_AUTH_NOT_VALID;
5195 }
5196
Jouni Malinen89c771e2014-10-10 20:52:40 +03005197 return rdev_del_station(rdev, dev, &params);
Johannes Berg5727ef12007-12-19 02:03:34 +01005198}
5199
Eric W. Biederman15e47302012-09-07 20:12:54 +00005200static int nl80211_send_mpath(struct sk_buff *msg, u32 portid, u32 seq,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005201 int flags, struct net_device *dev,
5202 u8 *dst, u8 *next_hop,
5203 struct mpath_info *pinfo)
5204{
5205 void *hdr;
5206 struct nlattr *pinfoattr;
5207
Henning Rogge1ef4c852014-11-04 16:14:58 +01005208 hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_MPATH);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005209 if (!hdr)
5210 return -1;
5211
David S. Miller9360ffd2012-03-29 04:41:26 -04005212 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
5213 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, dst) ||
5214 nla_put(msg, NL80211_ATTR_MPATH_NEXT_HOP, ETH_ALEN, next_hop) ||
5215 nla_put_u32(msg, NL80211_ATTR_GENERATION, pinfo->generation))
5216 goto nla_put_failure;
Johannes Bergf5ea9122009-08-07 16:17:38 +02005217
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005218 pinfoattr = nla_nest_start(msg, NL80211_ATTR_MPATH_INFO);
5219 if (!pinfoattr)
5220 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04005221 if ((pinfo->filled & MPATH_INFO_FRAME_QLEN) &&
5222 nla_put_u32(msg, NL80211_MPATH_INFO_FRAME_QLEN,
5223 pinfo->frame_qlen))
5224 goto nla_put_failure;
5225 if (((pinfo->filled & MPATH_INFO_SN) &&
5226 nla_put_u32(msg, NL80211_MPATH_INFO_SN, pinfo->sn)) ||
5227 ((pinfo->filled & MPATH_INFO_METRIC) &&
5228 nla_put_u32(msg, NL80211_MPATH_INFO_METRIC,
5229 pinfo->metric)) ||
5230 ((pinfo->filled & MPATH_INFO_EXPTIME) &&
5231 nla_put_u32(msg, NL80211_MPATH_INFO_EXPTIME,
5232 pinfo->exptime)) ||
5233 ((pinfo->filled & MPATH_INFO_FLAGS) &&
5234 nla_put_u8(msg, NL80211_MPATH_INFO_FLAGS,
5235 pinfo->flags)) ||
5236 ((pinfo->filled & MPATH_INFO_DISCOVERY_TIMEOUT) &&
5237 nla_put_u32(msg, NL80211_MPATH_INFO_DISCOVERY_TIMEOUT,
5238 pinfo->discovery_timeout)) ||
5239 ((pinfo->filled & MPATH_INFO_DISCOVERY_RETRIES) &&
5240 nla_put_u8(msg, NL80211_MPATH_INFO_DISCOVERY_RETRIES,
5241 pinfo->discovery_retries)))
5242 goto nla_put_failure;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005243
5244 nla_nest_end(msg, pinfoattr);
5245
Johannes Berg053c0952015-01-16 22:09:00 +01005246 genlmsg_end(msg, hdr);
5247 return 0;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005248
5249 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07005250 genlmsg_cancel(msg, hdr);
5251 return -EMSGSIZE;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005252}
5253
5254static int nl80211_dump_mpath(struct sk_buff *skb,
Johannes Bergbba95fe2008-07-29 13:22:51 +02005255 struct netlink_callback *cb)
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005256{
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005257 struct mpath_info pinfo;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08005258 struct cfg80211_registered_device *rdev;
Johannes Berg97990a02013-04-19 01:02:55 +02005259 struct wireless_dev *wdev;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005260 u8 dst[ETH_ALEN];
5261 u8 next_hop[ETH_ALEN];
Johannes Berg97990a02013-04-19 01:02:55 +02005262 int path_idx = cb->args[2];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005263 int err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005264
Johannes Bergea90e0d2017-03-15 14:26:04 +01005265 rtnl_lock();
Zhao, Gang1b8ec872014-04-21 12:53:02 +08005266 err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev);
Johannes Berg67748892010-10-04 21:14:06 +02005267 if (err)
Johannes Bergea90e0d2017-03-15 14:26:04 +01005268 goto out_err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02005269
Zhao, Gang1b8ec872014-04-21 12:53:02 +08005270 if (!rdev->ops->dump_mpath) {
Jouni Malineneec60b02009-03-20 21:21:19 +02005271 err = -EOPNOTSUPP;
Johannes Bergbba95fe2008-07-29 13:22:51 +02005272 goto out_err;
5273 }
5274
Johannes Berg97990a02013-04-19 01:02:55 +02005275 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) {
Jouni Malineneec60b02009-03-20 21:21:19 +02005276 err = -EOPNOTSUPP;
Roel Kluin0448b5f2009-08-22 21:15:49 +02005277 goto out_err;
Jouni Malineneec60b02009-03-20 21:21:19 +02005278 }
5279
Johannes Bergbba95fe2008-07-29 13:22:51 +02005280 while (1) {
Zhao, Gang1b8ec872014-04-21 12:53:02 +08005281 err = rdev_dump_mpath(rdev, wdev->netdev, path_idx, dst,
Johannes Berg97990a02013-04-19 01:02:55 +02005282 next_hop, &pinfo);
Johannes Bergbba95fe2008-07-29 13:22:51 +02005283 if (err == -ENOENT)
5284 break;
5285 if (err)
Johannes Berg3b858752009-03-12 09:55:09 +01005286 goto out_err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02005287
Eric W. Biederman15e47302012-09-07 20:12:54 +00005288 if (nl80211_send_mpath(skb, NETLINK_CB(cb->skb).portid,
Johannes Bergbba95fe2008-07-29 13:22:51 +02005289 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Johannes Berg97990a02013-04-19 01:02:55 +02005290 wdev->netdev, dst, next_hop,
Johannes Bergbba95fe2008-07-29 13:22:51 +02005291 &pinfo) < 0)
5292 goto out;
5293
5294 path_idx++;
5295 }
5296
Johannes Bergbba95fe2008-07-29 13:22:51 +02005297 out:
Johannes Berg97990a02013-04-19 01:02:55 +02005298 cb->args[2] = path_idx;
Johannes Bergbba95fe2008-07-29 13:22:51 +02005299 err = skb->len;
Johannes Bergbba95fe2008-07-29 13:22:51 +02005300 out_err:
Johannes Bergea90e0d2017-03-15 14:26:04 +01005301 rtnl_unlock();
Johannes Bergbba95fe2008-07-29 13:22:51 +02005302 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005303}
5304
5305static int nl80211_get_mpath(struct sk_buff *skb, struct genl_info *info)
5306{
Johannes Berg4c476992010-10-04 21:36:35 +02005307 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005308 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02005309 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005310 struct mpath_info pinfo;
5311 struct sk_buff *msg;
5312 u8 *dst = NULL;
5313 u8 next_hop[ETH_ALEN];
5314
5315 memset(&pinfo, 0, sizeof(pinfo));
5316
5317 if (!info->attrs[NL80211_ATTR_MAC])
5318 return -EINVAL;
5319
5320 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
5321
Johannes Berg4c476992010-10-04 21:36:35 +02005322 if (!rdev->ops->get_mpath)
5323 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01005324
Johannes Berg4c476992010-10-04 21:36:35 +02005325 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
5326 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02005327
Hila Gonene35e4d22012-06-27 17:19:42 +03005328 err = rdev_get_mpath(rdev, dev, dst, next_hop, &pinfo);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005329 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02005330 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005331
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07005332 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005333 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02005334 return -ENOMEM;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005335
Eric W. Biederman15e47302012-09-07 20:12:54 +00005336 if (nl80211_send_mpath(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berg4c476992010-10-04 21:36:35 +02005337 dev, dst, next_hop, &pinfo) < 0) {
5338 nlmsg_free(msg);
5339 return -ENOBUFS;
5340 }
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005341
Johannes Berg4c476992010-10-04 21:36:35 +02005342 return genlmsg_reply(msg, info);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005343}
5344
5345static int nl80211_set_mpath(struct sk_buff *skb, struct genl_info *info)
5346{
Johannes Berg4c476992010-10-04 21:36:35 +02005347 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5348 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005349 u8 *dst = NULL;
5350 u8 *next_hop = NULL;
5351
5352 if (!info->attrs[NL80211_ATTR_MAC])
5353 return -EINVAL;
5354
5355 if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP])
5356 return -EINVAL;
5357
5358 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
5359 next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]);
5360
Johannes Berg4c476992010-10-04 21:36:35 +02005361 if (!rdev->ops->change_mpath)
5362 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01005363
Johannes Berg4c476992010-10-04 21:36:35 +02005364 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
5365 return -EOPNOTSUPP;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005366
Hila Gonene35e4d22012-06-27 17:19:42 +03005367 return rdev_change_mpath(rdev, dev, dst, next_hop);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005368}
Johannes Berg4c476992010-10-04 21:36:35 +02005369
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005370static int nl80211_new_mpath(struct sk_buff *skb, struct genl_info *info)
5371{
Johannes Berg4c476992010-10-04 21:36:35 +02005372 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5373 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005374 u8 *dst = NULL;
5375 u8 *next_hop = NULL;
5376
5377 if (!info->attrs[NL80211_ATTR_MAC])
5378 return -EINVAL;
5379
5380 if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP])
5381 return -EINVAL;
5382
5383 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
5384 next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]);
5385
Johannes Berg4c476992010-10-04 21:36:35 +02005386 if (!rdev->ops->add_mpath)
5387 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01005388
Johannes Berg4c476992010-10-04 21:36:35 +02005389 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
5390 return -EOPNOTSUPP;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005391
Hila Gonene35e4d22012-06-27 17:19:42 +03005392 return rdev_add_mpath(rdev, dev, dst, next_hop);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005393}
5394
5395static int nl80211_del_mpath(struct sk_buff *skb, struct genl_info *info)
5396{
Johannes Berg4c476992010-10-04 21:36:35 +02005397 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5398 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005399 u8 *dst = NULL;
5400
5401 if (info->attrs[NL80211_ATTR_MAC])
5402 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
5403
Johannes Berg4c476992010-10-04 21:36:35 +02005404 if (!rdev->ops->del_mpath)
5405 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01005406
Hila Gonene35e4d22012-06-27 17:19:42 +03005407 return rdev_del_mpath(rdev, dev, dst);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005408}
5409
Henning Rogge66be7d22014-09-12 08:58:49 +02005410static int nl80211_get_mpp(struct sk_buff *skb, struct genl_info *info)
5411{
5412 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5413 int err;
5414 struct net_device *dev = info->user_ptr[1];
5415 struct mpath_info pinfo;
5416 struct sk_buff *msg;
5417 u8 *dst = NULL;
5418 u8 mpp[ETH_ALEN];
5419
5420 memset(&pinfo, 0, sizeof(pinfo));
5421
5422 if (!info->attrs[NL80211_ATTR_MAC])
5423 return -EINVAL;
5424
5425 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
5426
5427 if (!rdev->ops->get_mpp)
5428 return -EOPNOTSUPP;
5429
5430 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
5431 return -EOPNOTSUPP;
5432
5433 err = rdev_get_mpp(rdev, dev, dst, mpp, &pinfo);
5434 if (err)
5435 return err;
5436
5437 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
5438 if (!msg)
5439 return -ENOMEM;
5440
5441 if (nl80211_send_mpath(msg, info->snd_portid, info->snd_seq, 0,
5442 dev, dst, mpp, &pinfo) < 0) {
5443 nlmsg_free(msg);
5444 return -ENOBUFS;
5445 }
5446
5447 return genlmsg_reply(msg, info);
5448}
5449
5450static int nl80211_dump_mpp(struct sk_buff *skb,
5451 struct netlink_callback *cb)
5452{
5453 struct mpath_info pinfo;
5454 struct cfg80211_registered_device *rdev;
5455 struct wireless_dev *wdev;
5456 u8 dst[ETH_ALEN];
5457 u8 mpp[ETH_ALEN];
5458 int path_idx = cb->args[2];
5459 int err;
5460
Johannes Bergea90e0d2017-03-15 14:26:04 +01005461 rtnl_lock();
Henning Rogge66be7d22014-09-12 08:58:49 +02005462 err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev);
5463 if (err)
Johannes Bergea90e0d2017-03-15 14:26:04 +01005464 goto out_err;
Henning Rogge66be7d22014-09-12 08:58:49 +02005465
5466 if (!rdev->ops->dump_mpp) {
5467 err = -EOPNOTSUPP;
5468 goto out_err;
5469 }
5470
5471 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) {
5472 err = -EOPNOTSUPP;
5473 goto out_err;
5474 }
5475
5476 while (1) {
5477 err = rdev_dump_mpp(rdev, wdev->netdev, path_idx, dst,
5478 mpp, &pinfo);
5479 if (err == -ENOENT)
5480 break;
5481 if (err)
5482 goto out_err;
5483
5484 if (nl80211_send_mpath(skb, NETLINK_CB(cb->skb).portid,
5485 cb->nlh->nlmsg_seq, NLM_F_MULTI,
5486 wdev->netdev, dst, mpp,
5487 &pinfo) < 0)
5488 goto out;
5489
5490 path_idx++;
5491 }
5492
5493 out:
5494 cb->args[2] = path_idx;
5495 err = skb->len;
5496 out_err:
Johannes Bergea90e0d2017-03-15 14:26:04 +01005497 rtnl_unlock();
Henning Rogge66be7d22014-09-12 08:58:49 +02005498 return err;
5499}
5500
Jouni Malinen9f1ba902008-08-07 20:07:01 +03005501static int nl80211_set_bss(struct sk_buff *skb, struct genl_info *info)
5502{
Johannes Berg4c476992010-10-04 21:36:35 +02005503 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5504 struct net_device *dev = info->user_ptr[1];
Simon Wunderlichc56589e2013-11-21 18:19:49 +01005505 struct wireless_dev *wdev = dev->ieee80211_ptr;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03005506 struct bss_parameters params;
Simon Wunderlichc56589e2013-11-21 18:19:49 +01005507 int err;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03005508
5509 memset(&params, 0, sizeof(params));
5510 /* default to not changing parameters */
5511 params.use_cts_prot = -1;
5512 params.use_short_preamble = -1;
5513 params.use_short_slot_time = -1;
Felix Fietkaufd8aaaf2010-04-27 01:23:35 +02005514 params.ap_isolate = -1;
Helmut Schaa50b12f52010-11-19 12:40:25 +01005515 params.ht_opmode = -1;
Johannes Berg53cabad2012-11-14 15:17:28 +01005516 params.p2p_ctwindow = -1;
5517 params.p2p_opp_ps = -1;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03005518
5519 if (info->attrs[NL80211_ATTR_BSS_CTS_PROT])
5520 params.use_cts_prot =
5521 nla_get_u8(info->attrs[NL80211_ATTR_BSS_CTS_PROT]);
5522 if (info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE])
5523 params.use_short_preamble =
5524 nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]);
5525 if (info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME])
5526 params.use_short_slot_time =
5527 nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]);
Jouni Malinen90c97a02008-10-30 16:59:22 +02005528 if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) {
5529 params.basic_rates =
5530 nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
5531 params.basic_rates_len =
5532 nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
5533 }
Felix Fietkaufd8aaaf2010-04-27 01:23:35 +02005534 if (info->attrs[NL80211_ATTR_AP_ISOLATE])
5535 params.ap_isolate = !!nla_get_u8(info->attrs[NL80211_ATTR_AP_ISOLATE]);
Helmut Schaa50b12f52010-11-19 12:40:25 +01005536 if (info->attrs[NL80211_ATTR_BSS_HT_OPMODE])
5537 params.ht_opmode =
5538 nla_get_u16(info->attrs[NL80211_ATTR_BSS_HT_OPMODE]);
Jouni Malinen9f1ba902008-08-07 20:07:01 +03005539
Johannes Berg53cabad2012-11-14 15:17:28 +01005540 if (info->attrs[NL80211_ATTR_P2P_CTWINDOW]) {
5541 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
5542 return -EINVAL;
5543 params.p2p_ctwindow =
5544 nla_get_s8(info->attrs[NL80211_ATTR_P2P_CTWINDOW]);
5545 if (params.p2p_ctwindow < 0)
5546 return -EINVAL;
5547 if (params.p2p_ctwindow != 0 &&
5548 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_CTWIN))
5549 return -EINVAL;
5550 }
5551
5552 if (info->attrs[NL80211_ATTR_P2P_OPPPS]) {
5553 u8 tmp;
5554
5555 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
5556 return -EINVAL;
5557 tmp = nla_get_u8(info->attrs[NL80211_ATTR_P2P_OPPPS]);
5558 if (tmp > 1)
5559 return -EINVAL;
5560 params.p2p_opp_ps = tmp;
5561 if (params.p2p_opp_ps &&
5562 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_OPPPS))
5563 return -EINVAL;
5564 }
5565
Johannes Berg4c476992010-10-04 21:36:35 +02005566 if (!rdev->ops->change_bss)
5567 return -EOPNOTSUPP;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03005568
Johannes Berg074ac8d2010-09-16 14:58:22 +02005569 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
Johannes Berg4c476992010-10-04 21:36:35 +02005570 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
5571 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02005572
Simon Wunderlichc56589e2013-11-21 18:19:49 +01005573 wdev_lock(wdev);
5574 err = rdev_change_bss(rdev, dev, &params);
5575 wdev_unlock(wdev);
5576
5577 return err;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03005578}
5579
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005580static int nl80211_req_set_reg(struct sk_buff *skb, struct genl_info *info)
5581{
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005582 char *data = NULL;
Ilan peer05050752015-03-04 00:32:06 -05005583 bool is_indoor;
Luis R. Rodriguez57b5ce02012-07-12 11:49:18 -07005584 enum nl80211_user_reg_hint_type user_reg_hint_type;
Ilan peer05050752015-03-04 00:32:06 -05005585 u32 owner_nlportid;
5586
Luis R. Rodriguez80778f12009-02-21 00:04:22 -05005587 /*
5588 * You should only get this when cfg80211 hasn't yet initialized
5589 * completely when built-in to the kernel right between the time
5590 * window between nl80211_init() and regulatory_init(), if that is
5591 * even possible.
5592 */
Johannes Berg458f4f92012-12-06 15:47:38 +01005593 if (unlikely(!rcu_access_pointer(cfg80211_regdomain)))
Luis R. Rodriguezfe33eb32009-02-21 00:04:30 -05005594 return -EINPROGRESS;
Luis R. Rodriguez80778f12009-02-21 00:04:22 -05005595
Luis R. Rodriguez57b5ce02012-07-12 11:49:18 -07005596 if (info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE])
5597 user_reg_hint_type =
5598 nla_get_u32(info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE]);
5599 else
5600 user_reg_hint_type = NL80211_USER_REG_HINT_USER;
5601
5602 switch (user_reg_hint_type) {
5603 case NL80211_USER_REG_HINT_USER:
5604 case NL80211_USER_REG_HINT_CELL_BASE:
Ilan Peer52616f22014-02-25 16:26:00 +02005605 if (!info->attrs[NL80211_ATTR_REG_ALPHA2])
5606 return -EINVAL;
5607
5608 data = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]);
5609 return regulatory_hint_user(data, user_reg_hint_type);
5610 case NL80211_USER_REG_HINT_INDOOR:
Ilan peer05050752015-03-04 00:32:06 -05005611 if (info->attrs[NL80211_ATTR_SOCKET_OWNER]) {
5612 owner_nlportid = info->snd_portid;
5613 is_indoor = !!info->attrs[NL80211_ATTR_REG_INDOOR];
5614 } else {
5615 owner_nlportid = 0;
5616 is_indoor = true;
5617 }
5618
5619 return regulatory_hint_indoor(is_indoor, owner_nlportid);
Luis R. Rodriguez57b5ce02012-07-12 11:49:18 -07005620 default:
5621 return -EINVAL;
5622 }
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005623}
5624
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005625static int nl80211_get_mesh_config(struct sk_buff *skb,
Johannes Berg29cbe682010-12-03 09:20:44 +01005626 struct genl_info *info)
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005627{
Johannes Berg4c476992010-10-04 21:36:35 +02005628 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg4c476992010-10-04 21:36:35 +02005629 struct net_device *dev = info->user_ptr[1];
Johannes Berg29cbe682010-12-03 09:20:44 +01005630 struct wireless_dev *wdev = dev->ieee80211_ptr;
5631 struct mesh_config cur_params;
5632 int err = 0;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005633 void *hdr;
5634 struct nlattr *pinfoattr;
5635 struct sk_buff *msg;
5636
Johannes Berg29cbe682010-12-03 09:20:44 +01005637 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT)
5638 return -EOPNOTSUPP;
5639
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005640 if (!rdev->ops->get_mesh_config)
Johannes Berg4c476992010-10-04 21:36:35 +02005641 return -EOPNOTSUPP;
Jouni Malinenf3f92582009-03-20 17:57:36 +02005642
Johannes Berg29cbe682010-12-03 09:20:44 +01005643 wdev_lock(wdev);
5644 /* If not connected, get default parameters */
5645 if (!wdev->mesh_id_len)
5646 memcpy(&cur_params, &default_mesh_config, sizeof(cur_params));
5647 else
Hila Gonene35e4d22012-06-27 17:19:42 +03005648 err = rdev_get_mesh_config(rdev, dev, &cur_params);
Johannes Berg29cbe682010-12-03 09:20:44 +01005649 wdev_unlock(wdev);
5650
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005651 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02005652 return err;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005653
5654 /* Draw up a netlink message to send back */
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07005655 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02005656 if (!msg)
5657 return -ENOMEM;
Eric W. Biederman15e47302012-09-07 20:12:54 +00005658 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005659 NL80211_CMD_GET_MESH_CONFIG);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005660 if (!hdr)
Julia Lawallefe1cf02011-01-28 15:17:11 +01005661 goto out;
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005662 pinfoattr = nla_nest_start(msg, NL80211_ATTR_MESH_CONFIG);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005663 if (!pinfoattr)
5664 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04005665 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
5666 nla_put_u16(msg, NL80211_MESHCONF_RETRY_TIMEOUT,
5667 cur_params.dot11MeshRetryTimeout) ||
5668 nla_put_u16(msg, NL80211_MESHCONF_CONFIRM_TIMEOUT,
5669 cur_params.dot11MeshConfirmTimeout) ||
5670 nla_put_u16(msg, NL80211_MESHCONF_HOLDING_TIMEOUT,
5671 cur_params.dot11MeshHoldingTimeout) ||
5672 nla_put_u16(msg, NL80211_MESHCONF_MAX_PEER_LINKS,
5673 cur_params.dot11MeshMaxPeerLinks) ||
5674 nla_put_u8(msg, NL80211_MESHCONF_MAX_RETRIES,
5675 cur_params.dot11MeshMaxRetries) ||
5676 nla_put_u8(msg, NL80211_MESHCONF_TTL,
5677 cur_params.dot11MeshTTL) ||
5678 nla_put_u8(msg, NL80211_MESHCONF_ELEMENT_TTL,
5679 cur_params.element_ttl) ||
5680 nla_put_u8(msg, NL80211_MESHCONF_AUTO_OPEN_PLINKS,
5681 cur_params.auto_open_plinks) ||
John W. Linville7eab0f62012-04-12 14:25:14 -04005682 nla_put_u32(msg, NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR,
5683 cur_params.dot11MeshNbrOffsetMaxNeighbor) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04005684 nla_put_u8(msg, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES,
5685 cur_params.dot11MeshHWMPmaxPREQretries) ||
5686 nla_put_u32(msg, NL80211_MESHCONF_PATH_REFRESH_TIME,
5687 cur_params.path_refresh_time) ||
5688 nla_put_u16(msg, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT,
5689 cur_params.min_discovery_timeout) ||
5690 nla_put_u32(msg, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT,
5691 cur_params.dot11MeshHWMPactivePathTimeout) ||
5692 nla_put_u16(msg, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL,
5693 cur_params.dot11MeshHWMPpreqMinInterval) ||
5694 nla_put_u16(msg, NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL,
5695 cur_params.dot11MeshHWMPperrMinInterval) ||
5696 nla_put_u16(msg, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME,
5697 cur_params.dot11MeshHWMPnetDiameterTraversalTime) ||
5698 nla_put_u8(msg, NL80211_MESHCONF_HWMP_ROOTMODE,
5699 cur_params.dot11MeshHWMPRootMode) ||
5700 nla_put_u16(msg, NL80211_MESHCONF_HWMP_RANN_INTERVAL,
5701 cur_params.dot11MeshHWMPRannInterval) ||
5702 nla_put_u8(msg, NL80211_MESHCONF_GATE_ANNOUNCEMENTS,
5703 cur_params.dot11MeshGateAnnouncementProtocol) ||
5704 nla_put_u8(msg, NL80211_MESHCONF_FORWARDING,
5705 cur_params.dot11MeshForwarding) ||
5706 nla_put_u32(msg, NL80211_MESHCONF_RSSI_THRESHOLD,
Ashok Nagarajan70c33ea2012-04-30 14:20:32 -07005707 cur_params.rssi_threshold) ||
5708 nla_put_u32(msg, NL80211_MESHCONF_HT_OPMODE,
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08005709 cur_params.ht_opmode) ||
5710 nla_put_u32(msg, NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT,
5711 cur_params.dot11MeshHWMPactivePathToRootTimeout) ||
5712 nla_put_u16(msg, NL80211_MESHCONF_HWMP_ROOT_INTERVAL,
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +08005713 cur_params.dot11MeshHWMProotInterval) ||
5714 nla_put_u16(msg, NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL,
Marco Porsch3b1c5a52013-01-07 16:04:52 +01005715 cur_params.dot11MeshHWMPconfirmationInterval) ||
5716 nla_put_u32(msg, NL80211_MESHCONF_POWER_MODE,
5717 cur_params.power_mode) ||
5718 nla_put_u16(msg, NL80211_MESHCONF_AWAKE_WINDOW,
Colleen Twitty8e7c0532013-06-03 09:53:39 -07005719 cur_params.dot11MeshAwakeWindowDuration) ||
5720 nla_put_u32(msg, NL80211_MESHCONF_PLINK_TIMEOUT,
5721 cur_params.plink_timeout))
David S. Miller9360ffd2012-03-29 04:41:26 -04005722 goto nla_put_failure;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005723 nla_nest_end(msg, pinfoattr);
5724 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02005725 return genlmsg_reply(msg, info);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005726
Johannes Berg3b858752009-03-12 09:55:09 +01005727 nla_put_failure:
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005728 genlmsg_cancel(msg, hdr);
Julia Lawallefe1cf02011-01-28 15:17:11 +01005729 out:
Yuri Ershovd080e272010-06-29 15:08:07 +04005730 nlmsg_free(msg);
Johannes Berg4c476992010-10-04 21:36:35 +02005731 return -ENOBUFS;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005732}
5733
Alexey Dobriyanb54452b2010-02-18 08:14:31 +00005734static const struct nla_policy nl80211_meshconf_params_policy[NL80211_MESHCONF_ATTR_MAX+1] = {
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005735 [NL80211_MESHCONF_RETRY_TIMEOUT] = { .type = NLA_U16 },
5736 [NL80211_MESHCONF_CONFIRM_TIMEOUT] = { .type = NLA_U16 },
5737 [NL80211_MESHCONF_HOLDING_TIMEOUT] = { .type = NLA_U16 },
5738 [NL80211_MESHCONF_MAX_PEER_LINKS] = { .type = NLA_U16 },
5739 [NL80211_MESHCONF_MAX_RETRIES] = { .type = NLA_U8 },
5740 [NL80211_MESHCONF_TTL] = { .type = NLA_U8 },
Javier Cardona45904f22010-12-03 09:20:40 +01005741 [NL80211_MESHCONF_ELEMENT_TTL] = { .type = NLA_U8 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005742 [NL80211_MESHCONF_AUTO_OPEN_PLINKS] = { .type = NLA_U8 },
Javier Cardonad299a1f2012-03-31 11:31:33 -07005743 [NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR] = { .type = NLA_U32 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005744 [NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES] = { .type = NLA_U8 },
5745 [NL80211_MESHCONF_PATH_REFRESH_TIME] = { .type = NLA_U32 },
5746 [NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT] = { .type = NLA_U16 },
5747 [NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT] = { .type = NLA_U32 },
5748 [NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL] = { .type = NLA_U16 },
Thomas Pedersendca7e942011-11-24 17:15:24 -08005749 [NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL] = { .type = NLA_U16 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005750 [NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME] = { .type = NLA_U16 },
Javier Cardona699403d2011-08-09 16:45:09 -07005751 [NL80211_MESHCONF_HWMP_ROOTMODE] = { .type = NLA_U8 },
Javier Cardona0507e152011-08-09 16:45:10 -07005752 [NL80211_MESHCONF_HWMP_RANN_INTERVAL] = { .type = NLA_U16 },
Javier Cardona16dd7262011-08-09 16:45:11 -07005753 [NL80211_MESHCONF_GATE_ANNOUNCEMENTS] = { .type = NLA_U8 },
Chun-Yeow Yeoh94f90652012-01-21 01:02:16 +08005754 [NL80211_MESHCONF_FORWARDING] = { .type = NLA_U8 },
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005755 [NL80211_MESHCONF_RSSI_THRESHOLD] = { .type = NLA_U32 },
5756 [NL80211_MESHCONF_HT_OPMODE] = { .type = NLA_U16 },
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08005757 [NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT] = { .type = NLA_U32 },
5758 [NL80211_MESHCONF_HWMP_ROOT_INTERVAL] = { .type = NLA_U16 },
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +08005759 [NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL] = { .type = NLA_U16 },
Marco Porsch3b1c5a52013-01-07 16:04:52 +01005760 [NL80211_MESHCONF_POWER_MODE] = { .type = NLA_U32 },
5761 [NL80211_MESHCONF_AWAKE_WINDOW] = { .type = NLA_U16 },
Colleen Twitty8e7c0532013-06-03 09:53:39 -07005762 [NL80211_MESHCONF_PLINK_TIMEOUT] = { .type = NLA_U32 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005763};
5764
Javier Cardonac80d5452010-12-16 17:37:49 -08005765static const struct nla_policy
5766 nl80211_mesh_setup_params_policy[NL80211_MESH_SETUP_ATTR_MAX+1] = {
Javier Cardonad299a1f2012-03-31 11:31:33 -07005767 [NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC] = { .type = NLA_U8 },
Javier Cardonac80d5452010-12-16 17:37:49 -08005768 [NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL] = { .type = NLA_U8 },
5769 [NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC] = { .type = NLA_U8 },
Javier Cardona15d5dda2011-04-07 15:08:28 -07005770 [NL80211_MESH_SETUP_USERSPACE_AUTH] = { .type = NLA_FLAG },
Colleen Twitty6e16d902013-05-08 11:45:59 -07005771 [NL80211_MESH_SETUP_AUTH_PROTOCOL] = { .type = NLA_U8 },
Thomas Pedersenbb2798d2013-03-04 13:06:10 -08005772 [NL80211_MESH_SETUP_USERSPACE_MPM] = { .type = NLA_FLAG },
Javier Cardona581a8b02011-04-07 15:08:27 -07005773 [NL80211_MESH_SETUP_IE] = { .type = NLA_BINARY,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005774 .len = IEEE80211_MAX_DATA_LEN },
Javier Cardonab130e5c2011-05-03 16:57:07 -07005775 [NL80211_MESH_SETUP_USERSPACE_AMPE] = { .type = NLA_FLAG },
Javier Cardonac80d5452010-12-16 17:37:49 -08005776};
5777
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005778static int nl80211_check_bool(const struct nlattr *nla, u8 min, u8 max, bool *out)
5779{
5780 u8 val = nla_get_u8(nla);
5781 if (val < min || val > max)
5782 return -EINVAL;
5783 *out = val;
5784 return 0;
5785}
5786
5787static int nl80211_check_u8(const struct nlattr *nla, u8 min, u8 max, u8 *out)
5788{
5789 u8 val = nla_get_u8(nla);
5790 if (val < min || val > max)
5791 return -EINVAL;
5792 *out = val;
5793 return 0;
5794}
5795
5796static int nl80211_check_u16(const struct nlattr *nla, u16 min, u16 max, u16 *out)
5797{
5798 u16 val = nla_get_u16(nla);
5799 if (val < min || val > max)
5800 return -EINVAL;
5801 *out = val;
5802 return 0;
5803}
5804
5805static int nl80211_check_u32(const struct nlattr *nla, u32 min, u32 max, u32 *out)
5806{
5807 u32 val = nla_get_u32(nla);
5808 if (val < min || val > max)
5809 return -EINVAL;
5810 *out = val;
5811 return 0;
5812}
5813
5814static int nl80211_check_s32(const struct nlattr *nla, s32 min, s32 max, s32 *out)
5815{
5816 s32 val = nla_get_s32(nla);
5817 if (val < min || val > max)
5818 return -EINVAL;
5819 *out = val;
5820 return 0;
5821}
5822
Johannes Bergff9a71a2016-08-11 14:59:53 +02005823static int nl80211_check_power_mode(const struct nlattr *nla,
5824 enum nl80211_mesh_power_mode min,
5825 enum nl80211_mesh_power_mode max,
5826 enum nl80211_mesh_power_mode *out)
5827{
5828 u32 val = nla_get_u32(nla);
5829 if (val < min || val > max)
5830 return -EINVAL;
5831 *out = val;
5832 return 0;
5833}
5834
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005835static int nl80211_parse_mesh_config(struct genl_info *info,
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005836 struct mesh_config *cfg,
5837 u32 *mask_out)
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005838{
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005839 struct nlattr *tb[NL80211_MESHCONF_ATTR_MAX + 1];
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005840 u32 mask = 0;
Masashi Honma97572352016-08-03 10:07:44 +09005841 u16 ht_opmode;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005842
Marco Porschea54fba2013-01-07 16:04:48 +01005843#define FILL_IN_MESH_PARAM_IF_SET(tb, cfg, param, min, max, mask, attr, fn) \
5844do { \
5845 if (tb[attr]) { \
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005846 if (fn(tb[attr], min, max, &cfg->param)) \
Marco Porschea54fba2013-01-07 16:04:48 +01005847 return -EINVAL; \
Marco Porschea54fba2013-01-07 16:04:48 +01005848 mask |= (1 << (attr - 1)); \
5849 } \
5850} while (0)
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005851
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005852 if (!info->attrs[NL80211_ATTR_MESH_CONFIG])
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005853 return -EINVAL;
5854 if (nla_parse_nested(tb, NL80211_MESHCONF_ATTR_MAX,
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005855 info->attrs[NL80211_ATTR_MESH_CONFIG],
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005856 nl80211_meshconf_params_policy))
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005857 return -EINVAL;
5858
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005859 /* This makes sure that there aren't more than 32 mesh config
5860 * parameters (otherwise our bitfield scheme would not work.) */
5861 BUILD_BUG_ON(NL80211_MESHCONF_ATTR_MAX > 32);
5862
5863 /* Fill in the params struct */
Marco Porschea54fba2013-01-07 16:04:48 +01005864 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshRetryTimeout, 1, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005865 mask, NL80211_MESHCONF_RETRY_TIMEOUT,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005866 nl80211_check_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01005867 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshConfirmTimeout, 1, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005868 mask, NL80211_MESHCONF_CONFIRM_TIMEOUT,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005869 nl80211_check_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01005870 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHoldingTimeout, 1, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005871 mask, NL80211_MESHCONF_HOLDING_TIMEOUT,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005872 nl80211_check_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01005873 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxPeerLinks, 0, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005874 mask, NL80211_MESHCONF_MAX_PEER_LINKS,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005875 nl80211_check_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01005876 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxRetries, 0, 16,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005877 mask, NL80211_MESHCONF_MAX_RETRIES,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005878 nl80211_check_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01005879 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshTTL, 1, 255,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005880 mask, NL80211_MESHCONF_TTL, nl80211_check_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01005881 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, element_ttl, 1, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005882 mask, NL80211_MESHCONF_ELEMENT_TTL,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005883 nl80211_check_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01005884 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, auto_open_plinks, 0, 1,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005885 mask, NL80211_MESHCONF_AUTO_OPEN_PLINKS,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005886 nl80211_check_bool);
Marco Porschea54fba2013-01-07 16:04:48 +01005887 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshNbrOffsetMaxNeighbor,
5888 1, 255, mask,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005889 NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005890 nl80211_check_u32);
Marco Porschea54fba2013-01-07 16:04:48 +01005891 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPmaxPREQretries, 0, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005892 mask, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005893 nl80211_check_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01005894 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, path_refresh_time, 1, 65535,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005895 mask, NL80211_MESHCONF_PATH_REFRESH_TIME,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005896 nl80211_check_u32);
Marco Porschea54fba2013-01-07 16:04:48 +01005897 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, min_discovery_timeout, 1, 65535,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005898 mask, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005899 nl80211_check_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01005900 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathTimeout,
5901 1, 65535, mask,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005902 NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005903 nl80211_check_u32);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005904 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPpreqMinInterval,
Marco Porschea54fba2013-01-07 16:04:48 +01005905 1, 65535, mask,
5906 NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005907 nl80211_check_u16);
Thomas Pedersendca7e942011-11-24 17:15:24 -08005908 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPperrMinInterval,
Marco Porschea54fba2013-01-07 16:04:48 +01005909 1, 65535, mask,
5910 NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005911 nl80211_check_u16);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005912 FILL_IN_MESH_PARAM_IF_SET(tb, cfg,
Marco Porschea54fba2013-01-07 16:04:48 +01005913 dot11MeshHWMPnetDiameterTraversalTime,
5914 1, 65535, mask,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005915 NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005916 nl80211_check_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01005917 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRootMode, 0, 4,
5918 mask, NL80211_MESHCONF_HWMP_ROOTMODE,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005919 nl80211_check_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01005920 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRannInterval, 1, 65535,
5921 mask, NL80211_MESHCONF_HWMP_RANN_INTERVAL,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005922 nl80211_check_u16);
Rui Paulo63c57232009-11-09 23:46:57 +00005923 FILL_IN_MESH_PARAM_IF_SET(tb, cfg,
Marco Porschea54fba2013-01-07 16:04:48 +01005924 dot11MeshGateAnnouncementProtocol, 0, 1,
5925 mask, NL80211_MESHCONF_GATE_ANNOUNCEMENTS,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005926 nl80211_check_bool);
Marco Porschea54fba2013-01-07 16:04:48 +01005927 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshForwarding, 0, 1,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005928 mask, NL80211_MESHCONF_FORWARDING,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005929 nl80211_check_bool);
Chun-Yeow Yeoh83374fe2013-07-11 18:24:03 +08005930 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, rssi_threshold, -255, 0,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005931 mask, NL80211_MESHCONF_RSSI_THRESHOLD,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005932 nl80211_check_s32);
Masashi Honma97572352016-08-03 10:07:44 +09005933 /*
5934 * Check HT operation mode based on
5935 * IEEE 802.11 2012 8.4.2.59 HT Operation element.
5936 */
5937 if (tb[NL80211_MESHCONF_HT_OPMODE]) {
5938 ht_opmode = nla_get_u16(tb[NL80211_MESHCONF_HT_OPMODE]);
5939
5940 if (ht_opmode & ~(IEEE80211_HT_OP_MODE_PROTECTION |
5941 IEEE80211_HT_OP_MODE_NON_GF_STA_PRSNT |
5942 IEEE80211_HT_OP_MODE_NON_HT_STA_PRSNT))
5943 return -EINVAL;
5944
5945 if ((ht_opmode & IEEE80211_HT_OP_MODE_NON_GF_STA_PRSNT) &&
5946 (ht_opmode & IEEE80211_HT_OP_MODE_NON_HT_STA_PRSNT))
5947 return -EINVAL;
5948
5949 switch (ht_opmode & IEEE80211_HT_OP_MODE_PROTECTION) {
5950 case IEEE80211_HT_OP_MODE_PROTECTION_NONE:
5951 case IEEE80211_HT_OP_MODE_PROTECTION_20MHZ:
5952 if (ht_opmode & IEEE80211_HT_OP_MODE_NON_HT_STA_PRSNT)
5953 return -EINVAL;
5954 break;
5955 case IEEE80211_HT_OP_MODE_PROTECTION_NONMEMBER:
5956 case IEEE80211_HT_OP_MODE_PROTECTION_NONHT_MIXED:
5957 if (!(ht_opmode & IEEE80211_HT_OP_MODE_NON_HT_STA_PRSNT))
5958 return -EINVAL;
5959 break;
5960 }
5961 cfg->ht_opmode = ht_opmode;
Masashi Honmafd551ba2017-01-26 08:56:13 +09005962 mask |= (1 << (NL80211_MESHCONF_HT_OPMODE - 1));
Masashi Honma97572352016-08-03 10:07:44 +09005963 }
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08005964 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathToRootTimeout,
Marco Porschea54fba2013-01-07 16:04:48 +01005965 1, 65535, mask,
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08005966 NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005967 nl80211_check_u32);
Marco Porschea54fba2013-01-07 16:04:48 +01005968 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMProotInterval, 1, 65535,
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08005969 mask, NL80211_MESHCONF_HWMP_ROOT_INTERVAL,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005970 nl80211_check_u16);
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +08005971 FILL_IN_MESH_PARAM_IF_SET(tb, cfg,
Marco Porschea54fba2013-01-07 16:04:48 +01005972 dot11MeshHWMPconfirmationInterval,
5973 1, 65535, mask,
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +08005974 NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005975 nl80211_check_u16);
Marco Porsch3b1c5a52013-01-07 16:04:52 +01005976 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, power_mode,
5977 NL80211_MESH_POWER_ACTIVE,
5978 NL80211_MESH_POWER_MAX,
5979 mask, NL80211_MESHCONF_POWER_MODE,
Johannes Bergff9a71a2016-08-11 14:59:53 +02005980 nl80211_check_power_mode);
Marco Porsch3b1c5a52013-01-07 16:04:52 +01005981 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshAwakeWindowDuration,
5982 0, 65535, mask,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005983 NL80211_MESHCONF_AWAKE_WINDOW, nl80211_check_u16);
Masashi Honma31f909a2015-02-24 22:42:16 +09005984 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, plink_timeout, 0, 0xffffffff,
Colleen Twitty8e7c0532013-06-03 09:53:39 -07005985 mask, NL80211_MESHCONF_PLINK_TIMEOUT,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005986 nl80211_check_u32);
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005987 if (mask_out)
5988 *mask_out = mask;
Javier Cardonac80d5452010-12-16 17:37:49 -08005989
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005990 return 0;
5991
5992#undef FILL_IN_MESH_PARAM_IF_SET
5993}
5994
Javier Cardonac80d5452010-12-16 17:37:49 -08005995static int nl80211_parse_mesh_setup(struct genl_info *info,
5996 struct mesh_setup *setup)
5997{
Thomas Pedersenbb2798d2013-03-04 13:06:10 -08005998 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Javier Cardonac80d5452010-12-16 17:37:49 -08005999 struct nlattr *tb[NL80211_MESH_SETUP_ATTR_MAX + 1];
6000
6001 if (!info->attrs[NL80211_ATTR_MESH_SETUP])
6002 return -EINVAL;
6003 if (nla_parse_nested(tb, NL80211_MESH_SETUP_ATTR_MAX,
6004 info->attrs[NL80211_ATTR_MESH_SETUP],
6005 nl80211_mesh_setup_params_policy))
6006 return -EINVAL;
6007
Javier Cardonad299a1f2012-03-31 11:31:33 -07006008 if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC])
6009 setup->sync_method =
6010 (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC])) ?
6011 IEEE80211_SYNC_METHOD_VENDOR :
6012 IEEE80211_SYNC_METHOD_NEIGHBOR_OFFSET;
6013
Javier Cardonac80d5452010-12-16 17:37:49 -08006014 if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL])
6015 setup->path_sel_proto =
6016 (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL])) ?
6017 IEEE80211_PATH_PROTOCOL_VENDOR :
6018 IEEE80211_PATH_PROTOCOL_HWMP;
6019
6020 if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC])
6021 setup->path_metric =
6022 (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC])) ?
6023 IEEE80211_PATH_METRIC_VENDOR :
6024 IEEE80211_PATH_METRIC_AIRTIME;
6025
Javier Cardona581a8b02011-04-07 15:08:27 -07006026 if (tb[NL80211_MESH_SETUP_IE]) {
Javier Cardonac80d5452010-12-16 17:37:49 -08006027 struct nlattr *ieattr =
Javier Cardona581a8b02011-04-07 15:08:27 -07006028 tb[NL80211_MESH_SETUP_IE];
Javier Cardonac80d5452010-12-16 17:37:49 -08006029 if (!is_valid_ie_attr(ieattr))
6030 return -EINVAL;
Javier Cardona581a8b02011-04-07 15:08:27 -07006031 setup->ie = nla_data(ieattr);
6032 setup->ie_len = nla_len(ieattr);
Javier Cardonac80d5452010-12-16 17:37:49 -08006033 }
Thomas Pedersenbb2798d2013-03-04 13:06:10 -08006034 if (tb[NL80211_MESH_SETUP_USERSPACE_MPM] &&
6035 !(rdev->wiphy.features & NL80211_FEATURE_USERSPACE_MPM))
6036 return -EINVAL;
6037 setup->user_mpm = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_MPM]);
Javier Cardonab130e5c2011-05-03 16:57:07 -07006038 setup->is_authenticated = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AUTH]);
6039 setup->is_secure = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AMPE]);
Thomas Pedersenbb2798d2013-03-04 13:06:10 -08006040 if (setup->is_secure)
6041 setup->user_mpm = true;
Javier Cardonac80d5452010-12-16 17:37:49 -08006042
Colleen Twitty6e16d902013-05-08 11:45:59 -07006043 if (tb[NL80211_MESH_SETUP_AUTH_PROTOCOL]) {
6044 if (!setup->user_mpm)
6045 return -EINVAL;
6046 setup->auth_id =
6047 nla_get_u8(tb[NL80211_MESH_SETUP_AUTH_PROTOCOL]);
6048 }
6049
Javier Cardonac80d5452010-12-16 17:37:49 -08006050 return 0;
6051}
6052
Javier Cardona24bdd9f2010-12-16 17:37:48 -08006053static int nl80211_update_mesh_config(struct sk_buff *skb,
Johannes Berg29cbe682010-12-03 09:20:44 +01006054 struct genl_info *info)
Johannes Bergbd90fdc2010-12-03 09:20:43 +01006055{
6056 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6057 struct net_device *dev = info->user_ptr[1];
Johannes Berg29cbe682010-12-03 09:20:44 +01006058 struct wireless_dev *wdev = dev->ieee80211_ptr;
Johannes Bergbd90fdc2010-12-03 09:20:43 +01006059 struct mesh_config cfg;
6060 u32 mask;
6061 int err;
6062
Johannes Berg29cbe682010-12-03 09:20:44 +01006063 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT)
6064 return -EOPNOTSUPP;
6065
Javier Cardona24bdd9f2010-12-16 17:37:48 -08006066 if (!rdev->ops->update_mesh_config)
Johannes Bergbd90fdc2010-12-03 09:20:43 +01006067 return -EOPNOTSUPP;
6068
Javier Cardona24bdd9f2010-12-16 17:37:48 -08006069 err = nl80211_parse_mesh_config(info, &cfg, &mask);
Johannes Bergbd90fdc2010-12-03 09:20:43 +01006070 if (err)
6071 return err;
6072
Johannes Berg29cbe682010-12-03 09:20:44 +01006073 wdev_lock(wdev);
6074 if (!wdev->mesh_id_len)
6075 err = -ENOLINK;
6076
6077 if (!err)
Hila Gonene35e4d22012-06-27 17:19:42 +03006078 err = rdev_update_mesh_config(rdev, dev, mask, &cfg);
Johannes Berg29cbe682010-12-03 09:20:44 +01006079
6080 wdev_unlock(wdev);
6081
6082 return err;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07006083}
6084
Arik Nemtsovad30ca22014-12-15 19:25:59 +02006085static int nl80211_put_regdom(const struct ieee80211_regdomain *regdom,
6086 struct sk_buff *msg)
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08006087{
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08006088 struct nlattr *nl_reg_rules;
6089 unsigned int i;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08006090
Johannes Berg458f4f92012-12-06 15:47:38 +01006091 if (nla_put_string(msg, NL80211_ATTR_REG_ALPHA2, regdom->alpha2) ||
6092 (regdom->dfs_region &&
6093 nla_put_u8(msg, NL80211_ATTR_DFS_REGION, regdom->dfs_region)))
Arik Nemtsovad30ca22014-12-15 19:25:59 +02006094 goto nla_put_failure;
Johannes Berg458f4f92012-12-06 15:47:38 +01006095
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08006096 nl_reg_rules = nla_nest_start(msg, NL80211_ATTR_REG_RULES);
6097 if (!nl_reg_rules)
Arik Nemtsovad30ca22014-12-15 19:25:59 +02006098 goto nla_put_failure;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08006099
Johannes Berg458f4f92012-12-06 15:47:38 +01006100 for (i = 0; i < regdom->n_reg_rules; i++) {
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08006101 struct nlattr *nl_reg_rule;
6102 const struct ieee80211_reg_rule *reg_rule;
6103 const struct ieee80211_freq_range *freq_range;
6104 const struct ieee80211_power_rule *power_rule;
Janusz Dziedzic97524822014-01-30 09:52:20 +01006105 unsigned int max_bandwidth_khz;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08006106
Johannes Berg458f4f92012-12-06 15:47:38 +01006107 reg_rule = &regdom->reg_rules[i];
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08006108 freq_range = &reg_rule->freq_range;
6109 power_rule = &reg_rule->power_rule;
6110
6111 nl_reg_rule = nla_nest_start(msg, i);
6112 if (!nl_reg_rule)
Arik Nemtsovad30ca22014-12-15 19:25:59 +02006113 goto nla_put_failure;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08006114
Janusz Dziedzic97524822014-01-30 09:52:20 +01006115 max_bandwidth_khz = freq_range->max_bandwidth_khz;
6116 if (!max_bandwidth_khz)
6117 max_bandwidth_khz = reg_get_max_bandwidth(regdom,
6118 reg_rule);
6119
David S. Miller9360ffd2012-03-29 04:41:26 -04006120 if (nla_put_u32(msg, NL80211_ATTR_REG_RULE_FLAGS,
6121 reg_rule->flags) ||
6122 nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_START,
6123 freq_range->start_freq_khz) ||
6124 nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_END,
6125 freq_range->end_freq_khz) ||
6126 nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_MAX_BW,
Janusz Dziedzic97524822014-01-30 09:52:20 +01006127 max_bandwidth_khz) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04006128 nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN,
6129 power_rule->max_antenna_gain) ||
6130 nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_EIRP,
Janusz Dziedzic089027e2014-02-21 19:46:12 +01006131 power_rule->max_eirp) ||
6132 nla_put_u32(msg, NL80211_ATTR_DFS_CAC_TIME,
6133 reg_rule->dfs_cac_ms))
Arik Nemtsovad30ca22014-12-15 19:25:59 +02006134 goto nla_put_failure;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08006135
6136 nla_nest_end(msg, nl_reg_rule);
6137 }
6138
6139 nla_nest_end(msg, nl_reg_rules);
Arik Nemtsovad30ca22014-12-15 19:25:59 +02006140 return 0;
6141
6142nla_put_failure:
6143 return -EMSGSIZE;
6144}
6145
6146static int nl80211_get_reg_do(struct sk_buff *skb, struct genl_info *info)
6147{
6148 const struct ieee80211_regdomain *regdom = NULL;
6149 struct cfg80211_registered_device *rdev;
6150 struct wiphy *wiphy = NULL;
6151 struct sk_buff *msg;
6152 void *hdr;
6153
6154 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
6155 if (!msg)
6156 return -ENOBUFS;
6157
6158 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
6159 NL80211_CMD_GET_REG);
6160 if (!hdr)
6161 goto put_failure;
6162
6163 if (info->attrs[NL80211_ATTR_WIPHY]) {
Arik Nemtsov1bdd7162014-12-15 19:26:01 +02006164 bool self_managed;
6165
Arik Nemtsovad30ca22014-12-15 19:25:59 +02006166 rdev = cfg80211_get_dev_from_info(genl_info_net(info), info);
6167 if (IS_ERR(rdev)) {
6168 nlmsg_free(msg);
6169 return PTR_ERR(rdev);
6170 }
6171
6172 wiphy = &rdev->wiphy;
Arik Nemtsov1bdd7162014-12-15 19:26:01 +02006173 self_managed = wiphy->regulatory_flags &
6174 REGULATORY_WIPHY_SELF_MANAGED;
Arik Nemtsovad30ca22014-12-15 19:25:59 +02006175 regdom = get_wiphy_regdom(wiphy);
6176
Arik Nemtsov1bdd7162014-12-15 19:26:01 +02006177 /* a self-managed-reg device must have a private regdom */
6178 if (WARN_ON(!regdom && self_managed)) {
6179 nlmsg_free(msg);
6180 return -EINVAL;
6181 }
6182
Arik Nemtsovad30ca22014-12-15 19:25:59 +02006183 if (regdom &&
6184 nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy)))
6185 goto nla_put_failure;
6186 }
6187
6188 if (!wiphy && reg_last_request_cell_base() &&
6189 nla_put_u32(msg, NL80211_ATTR_USER_REG_HINT_TYPE,
6190 NL80211_USER_REG_HINT_CELL_BASE))
6191 goto nla_put_failure;
6192
6193 rcu_read_lock();
6194
6195 if (!regdom)
6196 regdom = rcu_dereference(cfg80211_regdomain);
6197
6198 if (nl80211_put_regdom(regdom, msg))
6199 goto nla_put_failure_rcu;
6200
6201 rcu_read_unlock();
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08006202
6203 genlmsg_end(msg, hdr);
Johannes Berg5fe231e2013-05-08 21:45:15 +02006204 return genlmsg_reply(msg, info);
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08006205
Johannes Berg458f4f92012-12-06 15:47:38 +01006206nla_put_failure_rcu:
6207 rcu_read_unlock();
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08006208nla_put_failure:
6209 genlmsg_cancel(msg, hdr);
Julia Lawallefe1cf02011-01-28 15:17:11 +01006210put_failure:
Yuri Ershovd080e272010-06-29 15:08:07 +04006211 nlmsg_free(msg);
Johannes Berg5fe231e2013-05-08 21:45:15 +02006212 return -EMSGSIZE;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08006213}
6214
Arik Nemtsovad30ca22014-12-15 19:25:59 +02006215static int nl80211_send_regdom(struct sk_buff *msg, struct netlink_callback *cb,
6216 u32 seq, int flags, struct wiphy *wiphy,
6217 const struct ieee80211_regdomain *regdom)
6218{
6219 void *hdr = nl80211hdr_put(msg, NETLINK_CB(cb->skb).portid, seq, flags,
6220 NL80211_CMD_GET_REG);
6221
6222 if (!hdr)
6223 return -1;
6224
6225 genl_dump_check_consistent(cb, hdr, &nl80211_fam);
6226
6227 if (nl80211_put_regdom(regdom, msg))
6228 goto nla_put_failure;
6229
6230 if (!wiphy && reg_last_request_cell_base() &&
6231 nla_put_u32(msg, NL80211_ATTR_USER_REG_HINT_TYPE,
6232 NL80211_USER_REG_HINT_CELL_BASE))
6233 goto nla_put_failure;
6234
6235 if (wiphy &&
6236 nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy)))
6237 goto nla_put_failure;
6238
Arik Nemtsov1bdd7162014-12-15 19:26:01 +02006239 if (wiphy && wiphy->regulatory_flags & REGULATORY_WIPHY_SELF_MANAGED &&
6240 nla_put_flag(msg, NL80211_ATTR_WIPHY_SELF_MANAGED_REG))
6241 goto nla_put_failure;
6242
Johannes Berg053c0952015-01-16 22:09:00 +01006243 genlmsg_end(msg, hdr);
6244 return 0;
Arik Nemtsovad30ca22014-12-15 19:25:59 +02006245
6246nla_put_failure:
6247 genlmsg_cancel(msg, hdr);
6248 return -EMSGSIZE;
6249}
6250
6251static int nl80211_get_reg_dump(struct sk_buff *skb,
6252 struct netlink_callback *cb)
6253{
6254 const struct ieee80211_regdomain *regdom = NULL;
6255 struct cfg80211_registered_device *rdev;
6256 int err, reg_idx, start = cb->args[2];
6257
6258 rtnl_lock();
6259
6260 if (cfg80211_regdomain && start == 0) {
6261 err = nl80211_send_regdom(skb, cb, cb->nlh->nlmsg_seq,
6262 NLM_F_MULTI, NULL,
6263 rtnl_dereference(cfg80211_regdomain));
6264 if (err < 0)
6265 goto out_err;
6266 }
6267
6268 /* the global regdom is idx 0 */
6269 reg_idx = 1;
6270 list_for_each_entry(rdev, &cfg80211_rdev_list, list) {
6271 regdom = get_wiphy_regdom(&rdev->wiphy);
6272 if (!regdom)
6273 continue;
6274
6275 if (++reg_idx <= start)
6276 continue;
6277
6278 err = nl80211_send_regdom(skb, cb, cb->nlh->nlmsg_seq,
6279 NLM_F_MULTI, &rdev->wiphy, regdom);
6280 if (err < 0) {
6281 reg_idx--;
6282 break;
6283 }
6284 }
6285
6286 cb->args[2] = reg_idx;
6287 err = skb->len;
6288out_err:
6289 rtnl_unlock();
6290 return err;
6291}
6292
Johannes Bergb6863032015-10-15 09:25:18 +02006293#ifdef CONFIG_CFG80211_CRDA_SUPPORT
6294static const struct nla_policy reg_rule_policy[NL80211_REG_RULE_ATTR_MAX + 1] = {
6295 [NL80211_ATTR_REG_RULE_FLAGS] = { .type = NLA_U32 },
6296 [NL80211_ATTR_FREQ_RANGE_START] = { .type = NLA_U32 },
6297 [NL80211_ATTR_FREQ_RANGE_END] = { .type = NLA_U32 },
6298 [NL80211_ATTR_FREQ_RANGE_MAX_BW] = { .type = NLA_U32 },
6299 [NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN] = { .type = NLA_U32 },
6300 [NL80211_ATTR_POWER_RULE_MAX_EIRP] = { .type = NLA_U32 },
6301 [NL80211_ATTR_DFS_CAC_TIME] = { .type = NLA_U32 },
6302};
6303
6304static int parse_reg_rule(struct nlattr *tb[],
6305 struct ieee80211_reg_rule *reg_rule)
6306{
6307 struct ieee80211_freq_range *freq_range = &reg_rule->freq_range;
6308 struct ieee80211_power_rule *power_rule = &reg_rule->power_rule;
6309
6310 if (!tb[NL80211_ATTR_REG_RULE_FLAGS])
6311 return -EINVAL;
6312 if (!tb[NL80211_ATTR_FREQ_RANGE_START])
6313 return -EINVAL;
6314 if (!tb[NL80211_ATTR_FREQ_RANGE_END])
6315 return -EINVAL;
6316 if (!tb[NL80211_ATTR_FREQ_RANGE_MAX_BW])
6317 return -EINVAL;
6318 if (!tb[NL80211_ATTR_POWER_RULE_MAX_EIRP])
6319 return -EINVAL;
6320
6321 reg_rule->flags = nla_get_u32(tb[NL80211_ATTR_REG_RULE_FLAGS]);
6322
6323 freq_range->start_freq_khz =
6324 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_START]);
6325 freq_range->end_freq_khz =
6326 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_END]);
6327 freq_range->max_bandwidth_khz =
6328 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]);
6329
6330 power_rule->max_eirp =
6331 nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]);
6332
6333 if (tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN])
6334 power_rule->max_antenna_gain =
6335 nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]);
6336
6337 if (tb[NL80211_ATTR_DFS_CAC_TIME])
6338 reg_rule->dfs_cac_ms =
6339 nla_get_u32(tb[NL80211_ATTR_DFS_CAC_TIME]);
6340
6341 return 0;
6342}
6343
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07006344static int nl80211_set_reg(struct sk_buff *skb, struct genl_info *info)
6345{
6346 struct nlattr *tb[NL80211_REG_RULE_ATTR_MAX + 1];
6347 struct nlattr *nl_reg_rule;
Johannes Bergea372c52014-11-28 14:54:31 +01006348 char *alpha2;
6349 int rem_reg_rules, r;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07006350 u32 num_rules = 0, rule_idx = 0, size_of_regd;
Luis R. Rodriguez4c7d3982013-11-13 18:54:02 +01006351 enum nl80211_dfs_regions dfs_region = NL80211_DFS_UNSET;
Johannes Bergea372c52014-11-28 14:54:31 +01006352 struct ieee80211_regdomain *rd;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07006353
6354 if (!info->attrs[NL80211_ATTR_REG_ALPHA2])
6355 return -EINVAL;
6356
6357 if (!info->attrs[NL80211_ATTR_REG_RULES])
6358 return -EINVAL;
6359
6360 alpha2 = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]);
6361
Luis R. Rodriguez8b60b072011-10-11 10:59:02 -07006362 if (info->attrs[NL80211_ATTR_DFS_REGION])
6363 dfs_region = nla_get_u8(info->attrs[NL80211_ATTR_DFS_REGION]);
6364
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07006365 nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES],
Johannes Berg1a919312012-12-03 17:21:11 +01006366 rem_reg_rules) {
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07006367 num_rules++;
6368 if (num_rules > NL80211_MAX_SUPP_REG_RULES)
Luis R. Rodriguez4776c6e2009-05-13 17:04:39 -04006369 return -EINVAL;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07006370 }
6371
Luis R. Rodrigueze4387682013-11-05 09:18:01 -08006372 if (!reg_is_valid_request(alpha2))
6373 return -EINVAL;
6374
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07006375 size_of_regd = sizeof(struct ieee80211_regdomain) +
Johannes Berg1a919312012-12-03 17:21:11 +01006376 num_rules * sizeof(struct ieee80211_reg_rule);
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07006377
6378 rd = kzalloc(size_of_regd, GFP_KERNEL);
Johannes Berg6913b492012-12-04 00:48:59 +01006379 if (!rd)
6380 return -ENOMEM;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07006381
6382 rd->n_reg_rules = num_rules;
6383 rd->alpha2[0] = alpha2[0];
6384 rd->alpha2[1] = alpha2[1];
6385
Luis R. Rodriguez8b60b072011-10-11 10:59:02 -07006386 /*
6387 * Disable DFS master mode if the DFS region was
6388 * not supported or known on this kernel.
6389 */
6390 if (reg_supported_dfs_region(dfs_region))
6391 rd->dfs_region = dfs_region;
6392
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07006393 nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES],
Johannes Berg1a919312012-12-03 17:21:11 +01006394 rem_reg_rules) {
Johannes Bergbfe2c7b2016-10-26 14:42:21 +02006395 r = nla_parse_nested(tb, NL80211_REG_RULE_ATTR_MAX,
6396 nl_reg_rule, reg_rule_policy);
Johannes Bergae811e22014-01-24 10:17:47 +01006397 if (r)
6398 goto bad_reg;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07006399 r = parse_reg_rule(tb, &rd->reg_rules[rule_idx]);
6400 if (r)
6401 goto bad_reg;
6402
6403 rule_idx++;
6404
Luis R. Rodriguezd0e18f82009-05-13 17:04:40 -04006405 if (rule_idx > NL80211_MAX_SUPP_REG_RULES) {
6406 r = -EINVAL;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07006407 goto bad_reg;
Luis R. Rodriguezd0e18f82009-05-13 17:04:40 -04006408 }
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07006409 }
6410
Johannes Berg06627992016-06-09 10:40:09 +02006411 /* set_regdom takes ownership of rd */
6412 return set_regdom(rd, REGD_SOURCE_CRDA);
Johannes Bergd2372b32008-10-24 20:32:20 +02006413 bad_reg:
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07006414 kfree(rd);
Luis R. Rodriguezd0e18f82009-05-13 17:04:40 -04006415 return r;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07006416}
Johannes Bergb6863032015-10-15 09:25:18 +02006417#endif /* CONFIG_CFG80211_CRDA_SUPPORT */
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07006418
Johannes Berg83f5e2c2009-06-17 17:41:49 +02006419static int validate_scan_freqs(struct nlattr *freqs)
6420{
6421 struct nlattr *attr1, *attr2;
6422 int n_channels = 0, tmp1, tmp2;
6423
6424 nla_for_each_nested(attr1, freqs, tmp1) {
6425 n_channels++;
6426 /*
6427 * Some hardware has a limited channel list for
6428 * scanning, and it is pretty much nonsensical
6429 * to scan for a channel twice, so disallow that
6430 * and don't require drivers to check that the
6431 * channel list they get isn't longer than what
6432 * they can scan, as long as they can scan all
6433 * the channels they registered at once.
6434 */
6435 nla_for_each_nested(attr2, freqs, tmp2)
6436 if (attr1 != attr2 &&
6437 nla_get_u32(attr1) == nla_get_u32(attr2))
6438 return 0;
6439 }
6440
6441 return n_channels;
6442}
6443
Johannes Berg57fbcce2016-04-12 15:56:15 +02006444static bool is_band_valid(struct wiphy *wiphy, enum nl80211_band b)
Arend van Spriel38de03d2016-03-02 20:37:18 +01006445{
Johannes Berg57fbcce2016-04-12 15:56:15 +02006446 return b < NUM_NL80211_BANDS && wiphy->bands[b];
Arend van Spriel38de03d2016-03-02 20:37:18 +01006447}
6448
6449static int parse_bss_select(struct nlattr *nla, struct wiphy *wiphy,
6450 struct cfg80211_bss_selection *bss_select)
6451{
6452 struct nlattr *attr[NL80211_BSS_SELECT_ATTR_MAX + 1];
6453 struct nlattr *nest;
6454 int err;
6455 bool found = false;
6456 int i;
6457
6458 /* only process one nested attribute */
6459 nest = nla_data(nla);
6460 if (!nla_ok(nest, nla_len(nest)))
6461 return -EINVAL;
6462
Johannes Bergbfe2c7b2016-10-26 14:42:21 +02006463 err = nla_parse_nested(attr, NL80211_BSS_SELECT_ATTR_MAX, nest,
6464 nl80211_bss_select_policy);
Arend van Spriel38de03d2016-03-02 20:37:18 +01006465 if (err)
6466 return err;
6467
6468 /* only one attribute may be given */
6469 for (i = 0; i <= NL80211_BSS_SELECT_ATTR_MAX; i++) {
6470 if (attr[i]) {
6471 if (found)
6472 return -EINVAL;
6473 found = true;
6474 }
6475 }
6476
6477 bss_select->behaviour = __NL80211_BSS_SELECT_ATTR_INVALID;
6478
6479 if (attr[NL80211_BSS_SELECT_ATTR_RSSI])
6480 bss_select->behaviour = NL80211_BSS_SELECT_ATTR_RSSI;
6481
6482 if (attr[NL80211_BSS_SELECT_ATTR_BAND_PREF]) {
6483 bss_select->behaviour = NL80211_BSS_SELECT_ATTR_BAND_PREF;
6484 bss_select->param.band_pref =
6485 nla_get_u32(attr[NL80211_BSS_SELECT_ATTR_BAND_PREF]);
6486 if (!is_band_valid(wiphy, bss_select->param.band_pref))
6487 return -EINVAL;
6488 }
6489
6490 if (attr[NL80211_BSS_SELECT_ATTR_RSSI_ADJUST]) {
6491 struct nl80211_bss_select_rssi_adjust *adj_param;
6492
6493 adj_param = nla_data(attr[NL80211_BSS_SELECT_ATTR_RSSI_ADJUST]);
6494 bss_select->behaviour = NL80211_BSS_SELECT_ATTR_RSSI_ADJUST;
6495 bss_select->param.adjust.band = adj_param->band;
6496 bss_select->param.adjust.delta = adj_param->delta;
6497 if (!is_band_valid(wiphy, bss_select->param.adjust.band))
6498 return -EINVAL;
6499 }
6500
6501 /* user-space did not provide behaviour attribute */
6502 if (bss_select->behaviour == __NL80211_BSS_SELECT_ATTR_INVALID)
6503 return -EINVAL;
6504
6505 if (!(wiphy->bss_select_support & BIT(bss_select->behaviour)))
6506 return -EINVAL;
6507
6508 return 0;
6509}
6510
Johannes Bergad2b26a2014-06-12 21:39:05 +02006511static int nl80211_parse_random_mac(struct nlattr **attrs,
6512 u8 *mac_addr, u8 *mac_addr_mask)
6513{
6514 int i;
6515
6516 if (!attrs[NL80211_ATTR_MAC] && !attrs[NL80211_ATTR_MAC_MASK]) {
Joe Perchesd2beae12015-03-02 19:54:58 -08006517 eth_zero_addr(mac_addr);
6518 eth_zero_addr(mac_addr_mask);
Johannes Bergad2b26a2014-06-12 21:39:05 +02006519 mac_addr[0] = 0x2;
6520 mac_addr_mask[0] = 0x3;
6521
6522 return 0;
6523 }
6524
6525 /* need both or none */
6526 if (!attrs[NL80211_ATTR_MAC] || !attrs[NL80211_ATTR_MAC_MASK])
6527 return -EINVAL;
6528
6529 memcpy(mac_addr, nla_data(attrs[NL80211_ATTR_MAC]), ETH_ALEN);
6530 memcpy(mac_addr_mask, nla_data(attrs[NL80211_ATTR_MAC_MASK]), ETH_ALEN);
6531
6532 /* don't allow or configure an mcast address */
6533 if (!is_multicast_ether_addr(mac_addr_mask) ||
6534 is_multicast_ether_addr(mac_addr))
6535 return -EINVAL;
6536
6537 /*
6538 * allow users to pass a MAC address that has bits set outside
6539 * of the mask, but don't bother drivers with having to deal
6540 * with such bits
6541 */
6542 for (i = 0; i < ETH_ALEN; i++)
6543 mac_addr[i] &= mac_addr_mask[i];
6544
6545 return 0;
6546}
6547
Johannes Berg2a519312009-02-10 21:25:55 +01006548static int nl80211_trigger_scan(struct sk_buff *skb, struct genl_info *info)
6549{
Johannes Berg4c476992010-10-04 21:36:35 +02006550 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Bergfd014282012-06-18 19:17:03 +02006551 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg2a519312009-02-10 21:25:55 +01006552 struct cfg80211_scan_request *request;
Johannes Berg2a519312009-02-10 21:25:55 +01006553 struct nlattr *attr;
6554 struct wiphy *wiphy;
Johannes Berg83f5e2c2009-06-17 17:41:49 +02006555 int err, tmp, n_ssids = 0, n_channels, i;
Jouni Malinen70692ad2009-02-16 19:39:13 +02006556 size_t ie_len;
Johannes Berg2a519312009-02-10 21:25:55 +01006557
Johannes Bergf4a11bb2009-03-27 12:40:28 +01006558 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
6559 return -EINVAL;
6560
Johannes Berg79c97e92009-07-07 03:56:12 +02006561 wiphy = &rdev->wiphy;
Johannes Berg2a519312009-02-10 21:25:55 +01006562
Ayala Bekercb3b7d82016-09-20 17:31:13 +03006563 if (wdev->iftype == NL80211_IFTYPE_NAN)
6564 return -EOPNOTSUPP;
6565
Johannes Berg4c476992010-10-04 21:36:35 +02006566 if (!rdev->ops->scan)
6567 return -EOPNOTSUPP;
Johannes Berg2a519312009-02-10 21:25:55 +01006568
Johannes Bergf9d15d12014-01-22 11:14:19 +02006569 if (rdev->scan_req || rdev->scan_msg) {
Johannes Bergf9f47522013-03-19 15:04:07 +01006570 err = -EBUSY;
6571 goto unlock;
6572 }
Johannes Berg2a519312009-02-10 21:25:55 +01006573
6574 if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
Johannes Berg83f5e2c2009-06-17 17:41:49 +02006575 n_channels = validate_scan_freqs(
6576 info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]);
Johannes Bergf9f47522013-03-19 15:04:07 +01006577 if (!n_channels) {
6578 err = -EINVAL;
6579 goto unlock;
6580 }
Johannes Berg2a519312009-02-10 21:25:55 +01006581 } else {
Ilan Peerbdfbec22014-01-09 11:37:23 +02006582 n_channels = ieee80211_get_num_supported_channels(wiphy);
Johannes Berg2a519312009-02-10 21:25:55 +01006583 }
6584
6585 if (info->attrs[NL80211_ATTR_SCAN_SSIDS])
6586 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp)
6587 n_ssids++;
6588
Johannes Bergf9f47522013-03-19 15:04:07 +01006589 if (n_ssids > wiphy->max_scan_ssids) {
6590 err = -EINVAL;
6591 goto unlock;
6592 }
Johannes Berg2a519312009-02-10 21:25:55 +01006593
Jouni Malinen70692ad2009-02-16 19:39:13 +02006594 if (info->attrs[NL80211_ATTR_IE])
6595 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
6596 else
6597 ie_len = 0;
6598
Johannes Bergf9f47522013-03-19 15:04:07 +01006599 if (ie_len > wiphy->max_scan_ie_len) {
6600 err = -EINVAL;
6601 goto unlock;
6602 }
Johannes Berg18a83652009-03-31 12:12:05 +02006603
Johannes Berg2a519312009-02-10 21:25:55 +01006604 request = kzalloc(sizeof(*request)
Luciano Coelhoa2cd43c2011-05-18 11:42:03 +03006605 + sizeof(*request->ssids) * n_ssids
6606 + sizeof(*request->channels) * n_channels
Jouni Malinen70692ad2009-02-16 19:39:13 +02006607 + ie_len, GFP_KERNEL);
Johannes Bergf9f47522013-03-19 15:04:07 +01006608 if (!request) {
6609 err = -ENOMEM;
6610 goto unlock;
6611 }
Johannes Berg2a519312009-02-10 21:25:55 +01006612
Johannes Berg2a519312009-02-10 21:25:55 +01006613 if (n_ssids)
Johannes Berg5ba63532009-08-07 17:54:07 +02006614 request->ssids = (void *)&request->channels[n_channels];
Johannes Berg2a519312009-02-10 21:25:55 +01006615 request->n_ssids = n_ssids;
Jouni Malinen70692ad2009-02-16 19:39:13 +02006616 if (ie_len) {
Johannes Berg13874e42015-01-23 11:25:20 +01006617 if (n_ssids)
Jouni Malinen70692ad2009-02-16 19:39:13 +02006618 request->ie = (void *)(request->ssids + n_ssids);
6619 else
6620 request->ie = (void *)(request->channels + n_channels);
6621 }
Johannes Berg2a519312009-02-10 21:25:55 +01006622
Johannes Berg584991d2009-11-02 13:32:03 +01006623 i = 0;
Johannes Berg2a519312009-02-10 21:25:55 +01006624 if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
6625 /* user specified, bail out if channel not found */
Johannes Berg2a519312009-02-10 21:25:55 +01006626 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_FREQUENCIES], tmp) {
Johannes Berg584991d2009-11-02 13:32:03 +01006627 struct ieee80211_channel *chan;
6628
6629 chan = ieee80211_get_channel(wiphy, nla_get_u32(attr));
6630
6631 if (!chan) {
Johannes Berg2a519312009-02-10 21:25:55 +01006632 err = -EINVAL;
6633 goto out_free;
6634 }
Johannes Berg584991d2009-11-02 13:32:03 +01006635
6636 /* ignore disabled channels */
6637 if (chan->flags & IEEE80211_CHAN_DISABLED)
6638 continue;
6639
6640 request->channels[i] = chan;
Johannes Berg2a519312009-02-10 21:25:55 +01006641 i++;
6642 }
6643 } else {
Johannes Berg57fbcce2016-04-12 15:56:15 +02006644 enum nl80211_band band;
Johannes Berg34850ab2011-07-18 18:08:35 +02006645
Johannes Berg2a519312009-02-10 21:25:55 +01006646 /* all channels */
Johannes Berg57fbcce2016-04-12 15:56:15 +02006647 for (band = 0; band < NUM_NL80211_BANDS; band++) {
Johannes Berg2a519312009-02-10 21:25:55 +01006648 int j;
Kirtika Ruchandani7a087e72016-05-29 19:51:23 -07006649
Johannes Berg2a519312009-02-10 21:25:55 +01006650 if (!wiphy->bands[band])
6651 continue;
6652 for (j = 0; j < wiphy->bands[band]->n_channels; j++) {
Johannes Berg584991d2009-11-02 13:32:03 +01006653 struct ieee80211_channel *chan;
6654
6655 chan = &wiphy->bands[band]->channels[j];
6656
6657 if (chan->flags & IEEE80211_CHAN_DISABLED)
6658 continue;
6659
6660 request->channels[i] = chan;
Johannes Berg2a519312009-02-10 21:25:55 +01006661 i++;
6662 }
6663 }
6664 }
6665
Johannes Berg584991d2009-11-02 13:32:03 +01006666 if (!i) {
6667 err = -EINVAL;
6668 goto out_free;
6669 }
6670
6671 request->n_channels = i;
6672
Johannes Berg2a519312009-02-10 21:25:55 +01006673 i = 0;
Johannes Berg13874e42015-01-23 11:25:20 +01006674 if (n_ssids) {
Johannes Berg2a519312009-02-10 21:25:55 +01006675 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) {
Luciano Coelho57a27e12011-06-07 20:42:26 +03006676 if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) {
Johannes Berg2a519312009-02-10 21:25:55 +01006677 err = -EINVAL;
6678 goto out_free;
6679 }
Luciano Coelho57a27e12011-06-07 20:42:26 +03006680 request->ssids[i].ssid_len = nla_len(attr);
Johannes Berg2a519312009-02-10 21:25:55 +01006681 memcpy(request->ssids[i].ssid, nla_data(attr), nla_len(attr));
Johannes Berg2a519312009-02-10 21:25:55 +01006682 i++;
6683 }
6684 }
6685
Jouni Malinen70692ad2009-02-16 19:39:13 +02006686 if (info->attrs[NL80211_ATTR_IE]) {
6687 request->ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Johannes Bergde95a542009-04-01 11:58:36 +02006688 memcpy((void *)request->ie,
6689 nla_data(info->attrs[NL80211_ATTR_IE]),
Jouni Malinen70692ad2009-02-16 19:39:13 +02006690 request->ie_len);
6691 }
6692
Johannes Berg57fbcce2016-04-12 15:56:15 +02006693 for (i = 0; i < NUM_NL80211_BANDS; i++)
Johannes Berga401d2b2011-07-20 00:52:16 +02006694 if (wiphy->bands[i])
6695 request->rates[i] =
6696 (1 << wiphy->bands[i]->n_bitrates) - 1;
Johannes Berg34850ab2011-07-18 18:08:35 +02006697
6698 if (info->attrs[NL80211_ATTR_SCAN_SUPP_RATES]) {
6699 nla_for_each_nested(attr,
6700 info->attrs[NL80211_ATTR_SCAN_SUPP_RATES],
6701 tmp) {
Johannes Berg57fbcce2016-04-12 15:56:15 +02006702 enum nl80211_band band = nla_type(attr);
Johannes Berg34850ab2011-07-18 18:08:35 +02006703
Johannes Berg57fbcce2016-04-12 15:56:15 +02006704 if (band < 0 || band >= NUM_NL80211_BANDS) {
Johannes Berg34850ab2011-07-18 18:08:35 +02006705 err = -EINVAL;
6706 goto out_free;
6707 }
Felix Fietkau1b09cd82013-11-20 19:40:41 +01006708
6709 if (!wiphy->bands[band])
6710 continue;
6711
Johannes Berg34850ab2011-07-18 18:08:35 +02006712 err = ieee80211_get_ratemask(wiphy->bands[band],
6713 nla_data(attr),
6714 nla_len(attr),
6715 &request->rates[band]);
6716 if (err)
6717 goto out_free;
6718 }
6719 }
6720
Avraham Stern1d762502016-07-05 17:10:13 +03006721 if (info->attrs[NL80211_ATTR_MEASUREMENT_DURATION]) {
6722 if (!wiphy_ext_feature_isset(wiphy,
6723 NL80211_EXT_FEATURE_SET_SCAN_DWELL)) {
6724 err = -EOPNOTSUPP;
6725 goto out_free;
6726 }
6727
6728 request->duration =
6729 nla_get_u16(info->attrs[NL80211_ATTR_MEASUREMENT_DURATION]);
6730 request->duration_mandatory =
6731 nla_get_flag(info->attrs[NL80211_ATTR_MEASUREMENT_DURATION_MANDATORY]);
6732 }
6733
Sam Leffler46856bb2012-10-11 21:03:32 -07006734 if (info->attrs[NL80211_ATTR_SCAN_FLAGS]) {
Sam Lefflered4737712012-10-11 21:03:31 -07006735 request->flags = nla_get_u32(
6736 info->attrs[NL80211_ATTR_SCAN_FLAGS]);
Johannes Berg00c3a6e2013-10-26 17:14:38 +02006737 if ((request->flags & NL80211_SCAN_FLAG_LOW_PRIORITY) &&
6738 !(wiphy->features & NL80211_FEATURE_LOW_PRIORITY_SCAN)) {
Sam Leffler46856bb2012-10-11 21:03:32 -07006739 err = -EOPNOTSUPP;
6740 goto out_free;
6741 }
Johannes Bergad2b26a2014-06-12 21:39:05 +02006742
6743 if (request->flags & NL80211_SCAN_FLAG_RANDOM_ADDR) {
6744 if (!(wiphy->features &
6745 NL80211_FEATURE_SCAN_RANDOM_MAC_ADDR)) {
6746 err = -EOPNOTSUPP;
6747 goto out_free;
6748 }
6749
6750 if (wdev->current_bss) {
6751 err = -EOPNOTSUPP;
6752 goto out_free;
6753 }
6754
6755 err = nl80211_parse_random_mac(info->attrs,
6756 request->mac_addr,
6757 request->mac_addr_mask);
6758 if (err)
6759 goto out_free;
6760 }
Sam Leffler46856bb2012-10-11 21:03:32 -07006761 }
Sam Lefflered4737712012-10-11 21:03:31 -07006762
Rajkumar Manoharane9f935e2011-09-25 14:53:30 +05306763 request->no_cck =
6764 nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]);
6765
Vamsi Krishna2fa436b2016-12-02 23:59:08 +02006766 /* Initial implementation used NL80211_ATTR_MAC to set the specific
6767 * BSSID to scan for. This was problematic because that same attribute
6768 * was already used for another purpose (local random MAC address). The
6769 * NL80211_ATTR_BSSID attribute was added to fix this. For backwards
6770 * compatibility with older userspace components, also use the
6771 * NL80211_ATTR_MAC value here if it can be determined to be used for
6772 * the specific BSSID use case instead of the random MAC address
6773 * (NL80211_ATTR_SCAN_FLAGS is used to enable random MAC address use).
6774 */
6775 if (info->attrs[NL80211_ATTR_BSSID])
6776 memcpy(request->bssid,
6777 nla_data(info->attrs[NL80211_ATTR_BSSID]), ETH_ALEN);
6778 else if (!(request->flags & NL80211_SCAN_FLAG_RANDOM_ADDR) &&
6779 info->attrs[NL80211_ATTR_MAC])
Jouni Malinen818965d2016-02-26 22:12:47 +02006780 memcpy(request->bssid, nla_data(info->attrs[NL80211_ATTR_MAC]),
6781 ETH_ALEN);
6782 else
6783 eth_broadcast_addr(request->bssid);
6784
Johannes Bergfd014282012-06-18 19:17:03 +02006785 request->wdev = wdev;
Johannes Berg79c97e92009-07-07 03:56:12 +02006786 request->wiphy = &rdev->wiphy;
Sam Leffler15d60302012-10-11 21:03:34 -07006787 request->scan_start = jiffies;
Johannes Berg2a519312009-02-10 21:25:55 +01006788
Johannes Berg79c97e92009-07-07 03:56:12 +02006789 rdev->scan_req = request;
Hila Gonene35e4d22012-06-27 17:19:42 +03006790 err = rdev_scan(rdev, request);
Johannes Berg2a519312009-02-10 21:25:55 +01006791
Johannes Berg463d0182009-07-14 00:33:35 +02006792 if (!err) {
Johannes Bergfd014282012-06-18 19:17:03 +02006793 nl80211_send_scan_start(rdev, wdev);
6794 if (wdev->netdev)
6795 dev_hold(wdev->netdev);
Johannes Berg4c476992010-10-04 21:36:35 +02006796 } else {
Johannes Berg2a519312009-02-10 21:25:55 +01006797 out_free:
Johannes Berg79c97e92009-07-07 03:56:12 +02006798 rdev->scan_req = NULL;
Johannes Berg2a519312009-02-10 21:25:55 +01006799 kfree(request);
6800 }
Johannes Berg3b858752009-03-12 09:55:09 +01006801
Johannes Bergf9f47522013-03-19 15:04:07 +01006802 unlock:
Johannes Berg2a519312009-02-10 21:25:55 +01006803 return err;
6804}
6805
Vidyullatha Kanchanapally91d3ab42015-10-30 19:14:49 +05306806static int nl80211_abort_scan(struct sk_buff *skb, struct genl_info *info)
6807{
6808 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6809 struct wireless_dev *wdev = info->user_ptr[1];
6810
6811 if (!rdev->ops->abort_scan)
6812 return -EOPNOTSUPP;
6813
6814 if (rdev->scan_msg)
6815 return 0;
6816
6817 if (!rdev->scan_req)
6818 return -ENOENT;
6819
6820 rdev_abort_scan(rdev, wdev);
6821 return 0;
6822}
6823
Avraham Stern3b06d272015-10-12 09:51:34 +03006824static int
6825nl80211_parse_sched_scan_plans(struct wiphy *wiphy, int n_plans,
6826 struct cfg80211_sched_scan_request *request,
6827 struct nlattr **attrs)
6828{
6829 int tmp, err, i = 0;
6830 struct nlattr *attr;
6831
6832 if (!attrs[NL80211_ATTR_SCHED_SCAN_PLANS]) {
6833 u32 interval;
6834
6835 /*
6836 * If scan plans are not specified,
Arend Van Spriel5a88de52016-11-17 09:02:40 +00006837 * %NL80211_ATTR_SCHED_SCAN_INTERVAL will be specified. In this
Avraham Stern3b06d272015-10-12 09:51:34 +03006838 * case one scan plan will be set with the specified scan
6839 * interval and infinite number of iterations.
6840 */
Avraham Stern3b06d272015-10-12 09:51:34 +03006841 interval = nla_get_u32(attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]);
6842 if (!interval)
6843 return -EINVAL;
6844
6845 request->scan_plans[0].interval =
6846 DIV_ROUND_UP(interval, MSEC_PER_SEC);
6847 if (!request->scan_plans[0].interval)
6848 return -EINVAL;
6849
6850 if (request->scan_plans[0].interval >
6851 wiphy->max_sched_scan_plan_interval)
6852 request->scan_plans[0].interval =
6853 wiphy->max_sched_scan_plan_interval;
6854
6855 return 0;
6856 }
6857
6858 nla_for_each_nested(attr, attrs[NL80211_ATTR_SCHED_SCAN_PLANS], tmp) {
6859 struct nlattr *plan[NL80211_SCHED_SCAN_PLAN_MAX + 1];
6860
6861 if (WARN_ON(i >= n_plans))
6862 return -EINVAL;
6863
Johannes Bergbfe2c7b2016-10-26 14:42:21 +02006864 err = nla_parse_nested(plan, NL80211_SCHED_SCAN_PLAN_MAX,
6865 attr, nl80211_plan_policy);
Avraham Stern3b06d272015-10-12 09:51:34 +03006866 if (err)
6867 return err;
6868
6869 if (!plan[NL80211_SCHED_SCAN_PLAN_INTERVAL])
6870 return -EINVAL;
6871
6872 request->scan_plans[i].interval =
6873 nla_get_u32(plan[NL80211_SCHED_SCAN_PLAN_INTERVAL]);
6874 if (!request->scan_plans[i].interval ||
6875 request->scan_plans[i].interval >
6876 wiphy->max_sched_scan_plan_interval)
6877 return -EINVAL;
6878
6879 if (plan[NL80211_SCHED_SCAN_PLAN_ITERATIONS]) {
6880 request->scan_plans[i].iterations =
6881 nla_get_u32(plan[NL80211_SCHED_SCAN_PLAN_ITERATIONS]);
6882 if (!request->scan_plans[i].iterations ||
6883 (request->scan_plans[i].iterations >
6884 wiphy->max_sched_scan_plan_iterations))
6885 return -EINVAL;
6886 } else if (i < n_plans - 1) {
6887 /*
6888 * All scan plans but the last one must specify
6889 * a finite number of iterations
6890 */
6891 return -EINVAL;
6892 }
6893
6894 i++;
6895 }
6896
6897 /*
6898 * The last scan plan must not specify the number of
6899 * iterations, it is supposed to run infinitely
6900 */
6901 if (request->scan_plans[n_plans - 1].iterations)
6902 return -EINVAL;
6903
6904 return 0;
6905}
6906
Luciano Coelho256da022014-11-10 16:13:46 +02006907static struct cfg80211_sched_scan_request *
Johannes Bergad2b26a2014-06-12 21:39:05 +02006908nl80211_parse_sched_scan(struct wiphy *wiphy, struct wireless_dev *wdev,
Arend Van Sprielaad1e812017-01-27 12:27:44 +00006909 struct nlattr **attrs, int max_match_sets)
Luciano Coelho807f8a82011-05-11 17:09:35 +03006910{
6911 struct cfg80211_sched_scan_request *request;
Luciano Coelho807f8a82011-05-11 17:09:35 +03006912 struct nlattr *attr;
Avraham Stern3b06d272015-10-12 09:51:34 +03006913 int err, tmp, n_ssids = 0, n_match_sets = 0, n_channels, i, n_plans = 0;
Johannes Berg57fbcce2016-04-12 15:56:15 +02006914 enum nl80211_band band;
Luciano Coelho807f8a82011-05-11 17:09:35 +03006915 size_t ie_len;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03006916 struct nlattr *tb[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1];
Johannes Bergea73cbc2014-01-24 10:53:53 +01006917 s32 default_match_rssi = NL80211_SCAN_RSSI_THOLD_OFF;
Luciano Coelho807f8a82011-05-11 17:09:35 +03006918
Luciano Coelho256da022014-11-10 16:13:46 +02006919 if (!is_valid_ie_attr(attrs[NL80211_ATTR_IE]))
6920 return ERR_PTR(-EINVAL);
Luciano Coelho807f8a82011-05-11 17:09:35 +03006921
Luciano Coelho256da022014-11-10 16:13:46 +02006922 if (attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
Luciano Coelho807f8a82011-05-11 17:09:35 +03006923 n_channels = validate_scan_freqs(
Luciano Coelho256da022014-11-10 16:13:46 +02006924 attrs[NL80211_ATTR_SCAN_FREQUENCIES]);
Luciano Coelho807f8a82011-05-11 17:09:35 +03006925 if (!n_channels)
Luciano Coelho256da022014-11-10 16:13:46 +02006926 return ERR_PTR(-EINVAL);
Luciano Coelho807f8a82011-05-11 17:09:35 +03006927 } else {
Ilan Peerbdfbec22014-01-09 11:37:23 +02006928 n_channels = ieee80211_get_num_supported_channels(wiphy);
Luciano Coelho807f8a82011-05-11 17:09:35 +03006929 }
6930
Luciano Coelho256da022014-11-10 16:13:46 +02006931 if (attrs[NL80211_ATTR_SCAN_SSIDS])
6932 nla_for_each_nested(attr, attrs[NL80211_ATTR_SCAN_SSIDS],
Luciano Coelho807f8a82011-05-11 17:09:35 +03006933 tmp)
6934 n_ssids++;
6935
Luciano Coelho93b6aa62011-07-13 14:57:28 +03006936 if (n_ssids > wiphy->max_sched_scan_ssids)
Luciano Coelho256da022014-11-10 16:13:46 +02006937 return ERR_PTR(-EINVAL);
Luciano Coelho807f8a82011-05-11 17:09:35 +03006938
Johannes Bergea73cbc2014-01-24 10:53:53 +01006939 /*
6940 * First, count the number of 'real' matchsets. Due to an issue with
6941 * the old implementation, matchsets containing only the RSSI attribute
6942 * (NL80211_SCHED_SCAN_MATCH_ATTR_RSSI) are considered as the 'default'
6943 * RSSI for all matchsets, rather than their own matchset for reporting
6944 * all APs with a strong RSSI. This is needed to be compatible with
6945 * older userspace that treated a matchset with only the RSSI as the
6946 * global RSSI for all other matchsets - if there are other matchsets.
6947 */
Luciano Coelho256da022014-11-10 16:13:46 +02006948 if (attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) {
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03006949 nla_for_each_nested(attr,
Luciano Coelho256da022014-11-10 16:13:46 +02006950 attrs[NL80211_ATTR_SCHED_SCAN_MATCH],
Johannes Bergea73cbc2014-01-24 10:53:53 +01006951 tmp) {
6952 struct nlattr *rssi;
6953
Johannes Bergbfe2c7b2016-10-26 14:42:21 +02006954 err = nla_parse_nested(tb,
6955 NL80211_SCHED_SCAN_MATCH_ATTR_MAX,
6956 attr, nl80211_match_policy);
Johannes Bergea73cbc2014-01-24 10:53:53 +01006957 if (err)
Luciano Coelho256da022014-11-10 16:13:46 +02006958 return ERR_PTR(err);
Johannes Bergea73cbc2014-01-24 10:53:53 +01006959 /* add other standalone attributes here */
6960 if (tb[NL80211_SCHED_SCAN_MATCH_ATTR_SSID]) {
6961 n_match_sets++;
6962 continue;
6963 }
6964 rssi = tb[NL80211_SCHED_SCAN_MATCH_ATTR_RSSI];
6965 if (rssi)
6966 default_match_rssi = nla_get_s32(rssi);
6967 }
6968 }
6969
6970 /* However, if there's no other matchset, add the RSSI one */
6971 if (!n_match_sets && default_match_rssi != NL80211_SCAN_RSSI_THOLD_OFF)
6972 n_match_sets = 1;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03006973
Arend Van Sprielaad1e812017-01-27 12:27:44 +00006974 if (n_match_sets > max_match_sets)
Luciano Coelho256da022014-11-10 16:13:46 +02006975 return ERR_PTR(-EINVAL);
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03006976
Luciano Coelho256da022014-11-10 16:13:46 +02006977 if (attrs[NL80211_ATTR_IE])
6978 ie_len = nla_len(attrs[NL80211_ATTR_IE]);
Luciano Coelho807f8a82011-05-11 17:09:35 +03006979 else
6980 ie_len = 0;
6981
Luciano Coelho5a865ba2011-07-13 14:57:29 +03006982 if (ie_len > wiphy->max_sched_scan_ie_len)
Luciano Coelho256da022014-11-10 16:13:46 +02006983 return ERR_PTR(-EINVAL);
Luciano Coelhoc10841c2011-06-30 08:32:41 +03006984
Avraham Stern3b06d272015-10-12 09:51:34 +03006985 if (attrs[NL80211_ATTR_SCHED_SCAN_PLANS]) {
6986 /*
6987 * NL80211_ATTR_SCHED_SCAN_INTERVAL must not be specified since
6988 * each scan plan already specifies its own interval
6989 */
6990 if (attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL])
6991 return ERR_PTR(-EINVAL);
6992
6993 nla_for_each_nested(attr,
6994 attrs[NL80211_ATTR_SCHED_SCAN_PLANS], tmp)
6995 n_plans++;
6996 } else {
6997 /*
6998 * The scan interval attribute is kept for backward
6999 * compatibility. If no scan plans are specified and sched scan
7000 * interval is specified, one scan plan will be set with this
7001 * scan interval and infinite number of iterations.
7002 */
7003 if (!attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL])
7004 return ERR_PTR(-EINVAL);
7005
7006 n_plans = 1;
7007 }
7008
7009 if (!n_plans || n_plans > wiphy->max_sched_scan_plans)
7010 return ERR_PTR(-EINVAL);
7011
vamsi krishnabf95ecd2017-01-13 01:12:20 +02007012 if (!wiphy_ext_feature_isset(
7013 wiphy, NL80211_EXT_FEATURE_SCHED_SCAN_RELATIVE_RSSI) &&
7014 (attrs[NL80211_ATTR_SCHED_SCAN_RELATIVE_RSSI] ||
7015 attrs[NL80211_ATTR_SCHED_SCAN_RSSI_ADJUST]))
7016 return ERR_PTR(-EINVAL);
7017
Luciano Coelho807f8a82011-05-11 17:09:35 +03007018 request = kzalloc(sizeof(*request)
Luciano Coelhoa2cd43c2011-05-18 11:42:03 +03007019 + sizeof(*request->ssids) * n_ssids
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03007020 + sizeof(*request->match_sets) * n_match_sets
Avraham Stern3b06d272015-10-12 09:51:34 +03007021 + sizeof(*request->scan_plans) * n_plans
Luciano Coelhoa2cd43c2011-05-18 11:42:03 +03007022 + sizeof(*request->channels) * n_channels
Luciano Coelho807f8a82011-05-11 17:09:35 +03007023 + ie_len, GFP_KERNEL);
Luciano Coelho256da022014-11-10 16:13:46 +02007024 if (!request)
7025 return ERR_PTR(-ENOMEM);
Luciano Coelho807f8a82011-05-11 17:09:35 +03007026
7027 if (n_ssids)
7028 request->ssids = (void *)&request->channels[n_channels];
7029 request->n_ssids = n_ssids;
7030 if (ie_len) {
Johannes Berg13874e42015-01-23 11:25:20 +01007031 if (n_ssids)
Luciano Coelho807f8a82011-05-11 17:09:35 +03007032 request->ie = (void *)(request->ssids + n_ssids);
7033 else
7034 request->ie = (void *)(request->channels + n_channels);
7035 }
7036
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03007037 if (n_match_sets) {
7038 if (request->ie)
7039 request->match_sets = (void *)(request->ie + ie_len);
Johannes Berg13874e42015-01-23 11:25:20 +01007040 else if (n_ssids)
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03007041 request->match_sets =
7042 (void *)(request->ssids + n_ssids);
7043 else
7044 request->match_sets =
7045 (void *)(request->channels + n_channels);
7046 }
7047 request->n_match_sets = n_match_sets;
7048
Avraham Stern3b06d272015-10-12 09:51:34 +03007049 if (n_match_sets)
7050 request->scan_plans = (void *)(request->match_sets +
7051 n_match_sets);
7052 else if (request->ie)
7053 request->scan_plans = (void *)(request->ie + ie_len);
7054 else if (n_ssids)
7055 request->scan_plans = (void *)(request->ssids + n_ssids);
7056 else
7057 request->scan_plans = (void *)(request->channels + n_channels);
7058
7059 request->n_scan_plans = n_plans;
7060
Luciano Coelho807f8a82011-05-11 17:09:35 +03007061 i = 0;
Luciano Coelho256da022014-11-10 16:13:46 +02007062 if (attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
Luciano Coelho807f8a82011-05-11 17:09:35 +03007063 /* user specified, bail out if channel not found */
7064 nla_for_each_nested(attr,
Luciano Coelho256da022014-11-10 16:13:46 +02007065 attrs[NL80211_ATTR_SCAN_FREQUENCIES],
Luciano Coelho807f8a82011-05-11 17:09:35 +03007066 tmp) {
7067 struct ieee80211_channel *chan;
7068
7069 chan = ieee80211_get_channel(wiphy, nla_get_u32(attr));
7070
7071 if (!chan) {
7072 err = -EINVAL;
7073 goto out_free;
7074 }
7075
7076 /* ignore disabled channels */
7077 if (chan->flags & IEEE80211_CHAN_DISABLED)
7078 continue;
7079
7080 request->channels[i] = chan;
7081 i++;
7082 }
7083 } else {
7084 /* all channels */
Johannes Berg57fbcce2016-04-12 15:56:15 +02007085 for (band = 0; band < NUM_NL80211_BANDS; band++) {
Luciano Coelho807f8a82011-05-11 17:09:35 +03007086 int j;
Kirtika Ruchandani7a087e72016-05-29 19:51:23 -07007087
Luciano Coelho807f8a82011-05-11 17:09:35 +03007088 if (!wiphy->bands[band])
7089 continue;
7090 for (j = 0; j < wiphy->bands[band]->n_channels; j++) {
7091 struct ieee80211_channel *chan;
7092
7093 chan = &wiphy->bands[band]->channels[j];
7094
7095 if (chan->flags & IEEE80211_CHAN_DISABLED)
7096 continue;
7097
7098 request->channels[i] = chan;
7099 i++;
7100 }
7101 }
7102 }
7103
7104 if (!i) {
7105 err = -EINVAL;
7106 goto out_free;
7107 }
7108
7109 request->n_channels = i;
7110
7111 i = 0;
Johannes Berg13874e42015-01-23 11:25:20 +01007112 if (n_ssids) {
Luciano Coelho256da022014-11-10 16:13:46 +02007113 nla_for_each_nested(attr, attrs[NL80211_ATTR_SCAN_SSIDS],
Luciano Coelho807f8a82011-05-11 17:09:35 +03007114 tmp) {
Luciano Coelho57a27e12011-06-07 20:42:26 +03007115 if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) {
Luciano Coelho807f8a82011-05-11 17:09:35 +03007116 err = -EINVAL;
7117 goto out_free;
7118 }
Luciano Coelho57a27e12011-06-07 20:42:26 +03007119 request->ssids[i].ssid_len = nla_len(attr);
Luciano Coelho807f8a82011-05-11 17:09:35 +03007120 memcpy(request->ssids[i].ssid, nla_data(attr),
7121 nla_len(attr));
Luciano Coelho807f8a82011-05-11 17:09:35 +03007122 i++;
7123 }
7124 }
7125
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03007126 i = 0;
Luciano Coelho256da022014-11-10 16:13:46 +02007127 if (attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) {
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03007128 nla_for_each_nested(attr,
Luciano Coelho256da022014-11-10 16:13:46 +02007129 attrs[NL80211_ATTR_SCHED_SCAN_MATCH],
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03007130 tmp) {
Thomas Pedersen88e920b2012-06-21 11:09:54 -07007131 struct nlattr *ssid, *rssi;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03007132
Johannes Bergbfe2c7b2016-10-26 14:42:21 +02007133 err = nla_parse_nested(tb,
7134 NL80211_SCHED_SCAN_MATCH_ATTR_MAX,
7135 attr, nl80211_match_policy);
Johannes Bergae811e22014-01-24 10:17:47 +01007136 if (err)
7137 goto out_free;
Johannes Berg4a4ab0d2012-06-13 11:17:11 +02007138 ssid = tb[NL80211_SCHED_SCAN_MATCH_ATTR_SSID];
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03007139 if (ssid) {
Johannes Bergea73cbc2014-01-24 10:53:53 +01007140 if (WARN_ON(i >= n_match_sets)) {
7141 /* this indicates a programming error,
7142 * the loop above should have verified
7143 * things properly
7144 */
7145 err = -EINVAL;
7146 goto out_free;
7147 }
7148
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03007149 if (nla_len(ssid) > IEEE80211_MAX_SSID_LEN) {
7150 err = -EINVAL;
7151 goto out_free;
7152 }
7153 memcpy(request->match_sets[i].ssid.ssid,
7154 nla_data(ssid), nla_len(ssid));
7155 request->match_sets[i].ssid.ssid_len =
7156 nla_len(ssid);
Kirtika Ruchandani56ab3642016-05-29 19:54:10 -07007157 /* special attribute - old implementation w/a */
Johannes Bergea73cbc2014-01-24 10:53:53 +01007158 request->match_sets[i].rssi_thold =
7159 default_match_rssi;
7160 rssi = tb[NL80211_SCHED_SCAN_MATCH_ATTR_RSSI];
7161 if (rssi)
7162 request->match_sets[i].rssi_thold =
7163 nla_get_s32(rssi);
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03007164 }
7165 i++;
7166 }
Johannes Bergea73cbc2014-01-24 10:53:53 +01007167
7168 /* there was no other matchset, so the RSSI one is alone */
Luciano Coelhof89f46c2014-12-01 11:32:09 +02007169 if (i == 0 && n_match_sets)
Johannes Bergea73cbc2014-01-24 10:53:53 +01007170 request->match_sets[0].rssi_thold = default_match_rssi;
7171
7172 request->min_rssi_thold = INT_MAX;
7173 for (i = 0; i < n_match_sets; i++)
7174 request->min_rssi_thold =
7175 min(request->match_sets[i].rssi_thold,
7176 request->min_rssi_thold);
7177 } else {
7178 request->min_rssi_thold = NL80211_SCAN_RSSI_THOLD_OFF;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03007179 }
7180
Johannes Berg9900e482014-02-04 21:01:25 +01007181 if (ie_len) {
7182 request->ie_len = ie_len;
Luciano Coelho807f8a82011-05-11 17:09:35 +03007183 memcpy((void *)request->ie,
Luciano Coelho256da022014-11-10 16:13:46 +02007184 nla_data(attrs[NL80211_ATTR_IE]),
Luciano Coelho807f8a82011-05-11 17:09:35 +03007185 request->ie_len);
7186 }
7187
Luciano Coelho256da022014-11-10 16:13:46 +02007188 if (attrs[NL80211_ATTR_SCAN_FLAGS]) {
Sam Lefflered4737712012-10-11 21:03:31 -07007189 request->flags = nla_get_u32(
Luciano Coelho256da022014-11-10 16:13:46 +02007190 attrs[NL80211_ATTR_SCAN_FLAGS]);
Johannes Berg00c3a6e2013-10-26 17:14:38 +02007191 if ((request->flags & NL80211_SCAN_FLAG_LOW_PRIORITY) &&
7192 !(wiphy->features & NL80211_FEATURE_LOW_PRIORITY_SCAN)) {
Sam Leffler46856bb2012-10-11 21:03:32 -07007193 err = -EOPNOTSUPP;
7194 goto out_free;
7195 }
Johannes Bergad2b26a2014-06-12 21:39:05 +02007196
7197 if (request->flags & NL80211_SCAN_FLAG_RANDOM_ADDR) {
7198 u32 flg = NL80211_FEATURE_SCHED_SCAN_RANDOM_MAC_ADDR;
7199
7200 if (!wdev) /* must be net-detect */
7201 flg = NL80211_FEATURE_ND_RANDOM_MAC_ADDR;
7202
7203 if (!(wiphy->features & flg)) {
7204 err = -EOPNOTSUPP;
7205 goto out_free;
7206 }
7207
7208 if (wdev && wdev->current_bss) {
7209 err = -EOPNOTSUPP;
7210 goto out_free;
7211 }
7212
7213 err = nl80211_parse_random_mac(attrs, request->mac_addr,
7214 request->mac_addr_mask);
7215 if (err)
7216 goto out_free;
7217 }
Sam Leffler46856bb2012-10-11 21:03:32 -07007218 }
Sam Lefflered4737712012-10-11 21:03:31 -07007219
Luciano Coelho9c748932015-01-16 16:04:09 +02007220 if (attrs[NL80211_ATTR_SCHED_SCAN_DELAY])
7221 request->delay =
7222 nla_get_u32(attrs[NL80211_ATTR_SCHED_SCAN_DELAY]);
7223
vamsi krishnabf95ecd2017-01-13 01:12:20 +02007224 if (attrs[NL80211_ATTR_SCHED_SCAN_RELATIVE_RSSI]) {
7225 request->relative_rssi = nla_get_s8(
7226 attrs[NL80211_ATTR_SCHED_SCAN_RELATIVE_RSSI]);
7227 request->relative_rssi_set = true;
7228 }
7229
7230 if (request->relative_rssi_set &&
7231 attrs[NL80211_ATTR_SCHED_SCAN_RSSI_ADJUST]) {
7232 struct nl80211_bss_select_rssi_adjust *rssi_adjust;
7233
7234 rssi_adjust = nla_data(
7235 attrs[NL80211_ATTR_SCHED_SCAN_RSSI_ADJUST]);
7236 request->rssi_adjust.band = rssi_adjust->band;
7237 request->rssi_adjust.delta = rssi_adjust->delta;
7238 if (!is_band_valid(wiphy, request->rssi_adjust.band)) {
7239 err = -EINVAL;
7240 goto out_free;
7241 }
7242 }
7243
Avraham Stern3b06d272015-10-12 09:51:34 +03007244 err = nl80211_parse_sched_scan_plans(wiphy, n_plans, request, attrs);
7245 if (err)
7246 goto out_free;
7247
Sam Leffler15d60302012-10-11 21:03:34 -07007248 request->scan_start = jiffies;
Luciano Coelho807f8a82011-05-11 17:09:35 +03007249
Luciano Coelho256da022014-11-10 16:13:46 +02007250 return request;
Luciano Coelho807f8a82011-05-11 17:09:35 +03007251
7252out_free:
7253 kfree(request);
Luciano Coelho256da022014-11-10 16:13:46 +02007254 return ERR_PTR(err);
7255}
7256
7257static int nl80211_start_sched_scan(struct sk_buff *skb,
7258 struct genl_info *info)
7259{
7260 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7261 struct net_device *dev = info->user_ptr[1];
Johannes Bergad2b26a2014-06-12 21:39:05 +02007262 struct wireless_dev *wdev = dev->ieee80211_ptr;
Jukka Rissanen31a60ed2014-12-15 13:25:38 +02007263 struct cfg80211_sched_scan_request *sched_scan_req;
Luciano Coelho256da022014-11-10 16:13:46 +02007264 int err;
7265
7266 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) ||
7267 !rdev->ops->sched_scan_start)
7268 return -EOPNOTSUPP;
7269
7270 if (rdev->sched_scan_req)
7271 return -EINPROGRESS;
7272
Jukka Rissanen31a60ed2014-12-15 13:25:38 +02007273 sched_scan_req = nl80211_parse_sched_scan(&rdev->wiphy, wdev,
Arend Van Sprielaad1e812017-01-27 12:27:44 +00007274 info->attrs,
7275 rdev->wiphy.max_match_sets);
Jukka Rissanen31a60ed2014-12-15 13:25:38 +02007276
7277 err = PTR_ERR_OR_ZERO(sched_scan_req);
Luciano Coelho256da022014-11-10 16:13:46 +02007278 if (err)
7279 goto out_err;
7280
Jukka Rissanen31a60ed2014-12-15 13:25:38 +02007281 err = rdev_sched_scan_start(rdev, dev, sched_scan_req);
Luciano Coelho256da022014-11-10 16:13:46 +02007282 if (err)
7283 goto out_free;
7284
Jukka Rissanen31a60ed2014-12-15 13:25:38 +02007285 sched_scan_req->dev = dev;
7286 sched_scan_req->wiphy = &rdev->wiphy;
7287
Jukka Rissanen93a1e862014-12-15 13:25:39 +02007288 if (info->attrs[NL80211_ATTR_SOCKET_OWNER])
7289 sched_scan_req->owner_nlportid = info->snd_portid;
7290
Jukka Rissanen31a60ed2014-12-15 13:25:38 +02007291 rcu_assign_pointer(rdev->sched_scan_req, sched_scan_req);
Luciano Coelho256da022014-11-10 16:13:46 +02007292
7293 nl80211_send_sched_scan(rdev, dev,
7294 NL80211_CMD_START_SCHED_SCAN);
7295 return 0;
7296
7297out_free:
Jukka Rissanen31a60ed2014-12-15 13:25:38 +02007298 kfree(sched_scan_req);
Luciano Coelho256da022014-11-10 16:13:46 +02007299out_err:
Luciano Coelho807f8a82011-05-11 17:09:35 +03007300 return err;
7301}
7302
7303static int nl80211_stop_sched_scan(struct sk_buff *skb,
7304 struct genl_info *info)
7305{
7306 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7307
7308 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) ||
7309 !rdev->ops->sched_scan_stop)
7310 return -EOPNOTSUPP;
7311
Johannes Berg5fe231e2013-05-08 21:45:15 +02007312 return __cfg80211_stop_sched_scan(rdev, false);
Luciano Coelho807f8a82011-05-11 17:09:35 +03007313}
7314
Simon Wunderlich04f39042013-02-08 18:16:19 +01007315static int nl80211_start_radar_detection(struct sk_buff *skb,
7316 struct genl_info *info)
7317{
7318 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7319 struct net_device *dev = info->user_ptr[1];
7320 struct wireless_dev *wdev = dev->ieee80211_ptr;
7321 struct cfg80211_chan_def chandef;
Luis R. Rodriguez55f74352013-11-25 20:56:10 +01007322 enum nl80211_dfs_regions dfs_region;
Janusz Dziedzic31559f32014-02-21 19:46:13 +01007323 unsigned int cac_time_ms;
Simon Wunderlich04f39042013-02-08 18:16:19 +01007324 int err;
7325
Luis R. Rodriguez55f74352013-11-25 20:56:10 +01007326 dfs_region = reg_get_dfs_region(wdev->wiphy);
7327 if (dfs_region == NL80211_DFS_UNSET)
7328 return -EINVAL;
7329
Simon Wunderlich04f39042013-02-08 18:16:19 +01007330 err = nl80211_parse_chandef(rdev, info, &chandef);
7331 if (err)
7332 return err;
7333
Simon Wunderlichff311bc2013-09-03 19:43:18 +02007334 if (netif_carrier_ok(dev))
7335 return -EBUSY;
7336
Simon Wunderlich04f39042013-02-08 18:16:19 +01007337 if (wdev->cac_started)
7338 return -EBUSY;
7339
Luciano Coelho2beb6dab2014-02-18 11:40:36 +02007340 err = cfg80211_chandef_dfs_required(wdev->wiphy, &chandef,
Luciano Coelho00ec75f2014-05-15 13:05:39 +03007341 wdev->iftype);
Simon Wunderlich04f39042013-02-08 18:16:19 +01007342 if (err < 0)
7343 return err;
7344
7345 if (err == 0)
7346 return -EINVAL;
7347
Janusz Dziedzicfe7c3a12013-11-05 14:48:48 +01007348 if (!cfg80211_chandef_dfs_usable(wdev->wiphy, &chandef))
Simon Wunderlich04f39042013-02-08 18:16:19 +01007349 return -EINVAL;
7350
7351 if (!rdev->ops->start_radar_detection)
7352 return -EOPNOTSUPP;
7353
Janusz Dziedzic31559f32014-02-21 19:46:13 +01007354 cac_time_ms = cfg80211_chandef_dfs_cac_time(&rdev->wiphy, &chandef);
7355 if (WARN_ON(!cac_time_ms))
7356 cac_time_ms = IEEE80211_DFS_MIN_CAC_TIME_MS;
7357
Ilan Peera1056b12015-10-22 22:27:46 +03007358 err = rdev_start_radar_detection(rdev, dev, &chandef, cac_time_ms);
Simon Wunderlich04f39042013-02-08 18:16:19 +01007359 if (!err) {
Michal Kazior9e0e2962014-01-29 14:22:27 +01007360 wdev->chandef = chandef;
Simon Wunderlich04f39042013-02-08 18:16:19 +01007361 wdev->cac_started = true;
7362 wdev->cac_start_time = jiffies;
Janusz Dziedzic31559f32014-02-21 19:46:13 +01007363 wdev->cac_time_ms = cac_time_ms;
Simon Wunderlich04f39042013-02-08 18:16:19 +01007364 }
Simon Wunderlich04f39042013-02-08 18:16:19 +01007365 return err;
7366}
7367
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02007368static int nl80211_channel_switch(struct sk_buff *skb, struct genl_info *info)
7369{
7370 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7371 struct net_device *dev = info->user_ptr[1];
7372 struct wireless_dev *wdev = dev->ieee80211_ptr;
7373 struct cfg80211_csa_settings params;
7374 /* csa_attrs is defined static to avoid waste of stack size - this
7375 * function is called under RTNL lock, so this should not be a problem.
7376 */
7377 static struct nlattr *csa_attrs[NL80211_ATTR_MAX+1];
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02007378 int err;
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02007379 bool need_new_beacon = false;
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03007380 int len, i;
Luciano Coelho252e07c2014-10-08 09:48:34 +03007381 u32 cs_count;
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02007382
7383 if (!rdev->ops->channel_switch ||
7384 !(rdev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH))
7385 return -EOPNOTSUPP;
7386
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02007387 switch (dev->ieee80211_ptr->iftype) {
7388 case NL80211_IFTYPE_AP:
7389 case NL80211_IFTYPE_P2P_GO:
7390 need_new_beacon = true;
7391
7392 /* useless if AP is not running */
7393 if (!wdev->beacon_interval)
Johannes Berg1ff79df2014-01-22 10:05:27 +01007394 return -ENOTCONN;
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02007395 break;
7396 case NL80211_IFTYPE_ADHOC:
Johannes Berg1ff79df2014-01-22 10:05:27 +01007397 if (!wdev->ssid_len)
7398 return -ENOTCONN;
7399 break;
Chun-Yeow Yeohc6da6742013-10-14 19:08:28 -07007400 case NL80211_IFTYPE_MESH_POINT:
Johannes Berg1ff79df2014-01-22 10:05:27 +01007401 if (!wdev->mesh_id_len)
7402 return -ENOTCONN;
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02007403 break;
7404 default:
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02007405 return -EOPNOTSUPP;
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02007406 }
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02007407
7408 memset(&params, 0, sizeof(params));
7409
7410 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] ||
7411 !info->attrs[NL80211_ATTR_CH_SWITCH_COUNT])
7412 return -EINVAL;
7413
7414 /* only important for AP, IBSS and mesh create IEs internally */
Andrei Otcheretianskid0a361a2013-10-17 10:52:17 +02007415 if (need_new_beacon && !info->attrs[NL80211_ATTR_CSA_IES])
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02007416 return -EINVAL;
7417
Luciano Coelho252e07c2014-10-08 09:48:34 +03007418 /* Even though the attribute is u32, the specification says
7419 * u8, so let's make sure we don't overflow.
7420 */
7421 cs_count = nla_get_u32(info->attrs[NL80211_ATTR_CH_SWITCH_COUNT]);
7422 if (cs_count > 255)
7423 return -EINVAL;
7424
7425 params.count = cs_count;
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02007426
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02007427 if (!need_new_beacon)
7428 goto skip_beacons;
7429
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02007430 err = nl80211_parse_beacon(info->attrs, &params.beacon_after);
7431 if (err)
7432 return err;
7433
7434 err = nla_parse_nested(csa_attrs, NL80211_ATTR_MAX,
7435 info->attrs[NL80211_ATTR_CSA_IES],
7436 nl80211_policy);
7437 if (err)
7438 return err;
7439
7440 err = nl80211_parse_beacon(csa_attrs, &params.beacon_csa);
7441 if (err)
7442 return err;
7443
7444 if (!csa_attrs[NL80211_ATTR_CSA_C_OFF_BEACON])
7445 return -EINVAL;
7446
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03007447 len = nla_len(csa_attrs[NL80211_ATTR_CSA_C_OFF_BEACON]);
7448 if (!len || (len % sizeof(u16)))
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02007449 return -EINVAL;
7450
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03007451 params.n_counter_offsets_beacon = len / sizeof(u16);
7452 if (rdev->wiphy.max_num_csa_counters &&
7453 (params.n_counter_offsets_beacon >
7454 rdev->wiphy.max_num_csa_counters))
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02007455 return -EINVAL;
7456
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03007457 params.counter_offsets_beacon =
7458 nla_data(csa_attrs[NL80211_ATTR_CSA_C_OFF_BEACON]);
7459
7460 /* sanity checks - counters should fit and be the same */
7461 for (i = 0; i < params.n_counter_offsets_beacon; i++) {
7462 u16 offset = params.counter_offsets_beacon[i];
7463
7464 if (offset >= params.beacon_csa.tail_len)
7465 return -EINVAL;
7466
7467 if (params.beacon_csa.tail[offset] != params.count)
7468 return -EINVAL;
7469 }
7470
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02007471 if (csa_attrs[NL80211_ATTR_CSA_C_OFF_PRESP]) {
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03007472 len = nla_len(csa_attrs[NL80211_ATTR_CSA_C_OFF_PRESP]);
7473 if (!len || (len % sizeof(u16)))
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02007474 return -EINVAL;
7475
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03007476 params.n_counter_offsets_presp = len / sizeof(u16);
7477 if (rdev->wiphy.max_num_csa_counters &&
Johannes Bergad5987b2016-09-13 15:53:55 +02007478 (params.n_counter_offsets_presp >
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03007479 rdev->wiphy.max_num_csa_counters))
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02007480 return -EINVAL;
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03007481
7482 params.counter_offsets_presp =
7483 nla_data(csa_attrs[NL80211_ATTR_CSA_C_OFF_PRESP]);
7484
7485 /* sanity checks - counters should fit and be the same */
7486 for (i = 0; i < params.n_counter_offsets_presp; i++) {
7487 u16 offset = params.counter_offsets_presp[i];
7488
7489 if (offset >= params.beacon_csa.probe_resp_len)
7490 return -EINVAL;
7491
7492 if (params.beacon_csa.probe_resp[offset] !=
7493 params.count)
7494 return -EINVAL;
7495 }
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02007496 }
7497
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02007498skip_beacons:
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02007499 err = nl80211_parse_chandef(rdev, info, &params.chandef);
7500 if (err)
7501 return err;
7502
Arik Nemtsov923b3522015-07-08 15:41:44 +03007503 if (!cfg80211_reg_can_beacon_relax(&rdev->wiphy, &params.chandef,
7504 wdev->iftype))
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02007505 return -EINVAL;
7506
Luciano Coelho2beb6dab2014-02-18 11:40:36 +02007507 err = cfg80211_chandef_dfs_required(wdev->wiphy,
7508 &params.chandef,
7509 wdev->iftype);
7510 if (err < 0)
7511 return err;
7512
Fabian Frederickdcc6c2f2014-10-25 17:57:35 +02007513 if (err > 0)
Luciano Coelho2beb6dab2014-02-18 11:40:36 +02007514 params.radar_required = true;
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02007515
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02007516 if (info->attrs[NL80211_ATTR_CH_SWITCH_BLOCK_TX])
7517 params.block_tx = true;
7518
Simon Wunderlichc56589e2013-11-21 18:19:49 +01007519 wdev_lock(wdev);
7520 err = rdev_channel_switch(rdev, dev, &params);
7521 wdev_unlock(wdev);
7522
7523 return err;
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02007524}
7525
Johannes Berg9720bb32011-06-21 09:45:33 +02007526static int nl80211_send_bss(struct sk_buff *msg, struct netlink_callback *cb,
7527 u32 seq, int flags,
Johannes Berg2a519312009-02-10 21:25:55 +01007528 struct cfg80211_registered_device *rdev,
Johannes Berg48ab9052009-07-10 18:42:31 +02007529 struct wireless_dev *wdev,
7530 struct cfg80211_internal_bss *intbss)
Johannes Berg2a519312009-02-10 21:25:55 +01007531{
Johannes Berg48ab9052009-07-10 18:42:31 +02007532 struct cfg80211_bss *res = &intbss->pub;
Johannes Berg9caf0362012-11-29 01:25:20 +01007533 const struct cfg80211_bss_ies *ies;
Johannes Berg2a519312009-02-10 21:25:55 +01007534 void *hdr;
7535 struct nlattr *bss;
Johannes Berg48ab9052009-07-10 18:42:31 +02007536
7537 ASSERT_WDEV_LOCK(wdev);
Johannes Berg2a519312009-02-10 21:25:55 +01007538
Eric W. Biederman15e47302012-09-07 20:12:54 +00007539 hdr = nl80211hdr_put(msg, NETLINK_CB(cb->skb).portid, seq, flags,
Johannes Berg2a519312009-02-10 21:25:55 +01007540 NL80211_CMD_NEW_SCAN_RESULTS);
7541 if (!hdr)
7542 return -1;
7543
Johannes Berg9720bb32011-06-21 09:45:33 +02007544 genl_dump_check_consistent(cb, hdr, &nl80211_fam);
7545
Johannes Berg97990a02013-04-19 01:02:55 +02007546 if (nla_put_u32(msg, NL80211_ATTR_GENERATION, rdev->bss_generation))
7547 goto nla_put_failure;
7548 if (wdev->netdev &&
David S. Miller9360ffd2012-03-29 04:41:26 -04007549 nla_put_u32(msg, NL80211_ATTR_IFINDEX, wdev->netdev->ifindex))
7550 goto nla_put_failure;
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02007551 if (nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
7552 NL80211_ATTR_PAD))
Johannes Berg97990a02013-04-19 01:02:55 +02007553 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01007554
7555 bss = nla_nest_start(msg, NL80211_ATTR_BSS);
7556 if (!bss)
7557 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04007558 if ((!is_zero_ether_addr(res->bssid) &&
Johannes Berg9caf0362012-11-29 01:25:20 +01007559 nla_put(msg, NL80211_BSS_BSSID, ETH_ALEN, res->bssid)))
David S. Miller9360ffd2012-03-29 04:41:26 -04007560 goto nla_put_failure;
Johannes Berg9caf0362012-11-29 01:25:20 +01007561
7562 rcu_read_lock();
Johannes Berg0e227082014-08-12 20:34:30 +02007563 /* indicate whether we have probe response data or not */
7564 if (rcu_access_pointer(res->proberesp_ies) &&
7565 nla_put_flag(msg, NL80211_BSS_PRESP_DATA))
7566 goto fail_unlock_rcu;
7567
7568 /* this pointer prefers to be pointed to probe response data
7569 * but is always valid
7570 */
Johannes Berg9caf0362012-11-29 01:25:20 +01007571 ies = rcu_dereference(res->ies);
Johannes Berg8cef2c92013-02-05 16:54:31 +01007572 if (ies) {
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02007573 if (nla_put_u64_64bit(msg, NL80211_BSS_TSF, ies->tsf,
7574 NL80211_BSS_PAD))
Johannes Berg8cef2c92013-02-05 16:54:31 +01007575 goto fail_unlock_rcu;
Johannes Berg8cef2c92013-02-05 16:54:31 +01007576 if (ies->len && nla_put(msg, NL80211_BSS_INFORMATION_ELEMENTS,
7577 ies->len, ies->data))
7578 goto fail_unlock_rcu;
Johannes Berg9caf0362012-11-29 01:25:20 +01007579 }
Johannes Berg0e227082014-08-12 20:34:30 +02007580
7581 /* and this pointer is always (unless driver didn't know) beacon data */
Johannes Berg9caf0362012-11-29 01:25:20 +01007582 ies = rcu_dereference(res->beacon_ies);
Johannes Berg0e227082014-08-12 20:34:30 +02007583 if (ies && ies->from_beacon) {
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02007584 if (nla_put_u64_64bit(msg, NL80211_BSS_BEACON_TSF, ies->tsf,
7585 NL80211_BSS_PAD))
Johannes Berg8cef2c92013-02-05 16:54:31 +01007586 goto fail_unlock_rcu;
7587 if (ies->len && nla_put(msg, NL80211_BSS_BEACON_IES,
7588 ies->len, ies->data))
7589 goto fail_unlock_rcu;
Johannes Berg9caf0362012-11-29 01:25:20 +01007590 }
7591 rcu_read_unlock();
7592
David S. Miller9360ffd2012-03-29 04:41:26 -04007593 if (res->beacon_interval &&
7594 nla_put_u16(msg, NL80211_BSS_BEACON_INTERVAL, res->beacon_interval))
7595 goto nla_put_failure;
7596 if (nla_put_u16(msg, NL80211_BSS_CAPABILITY, res->capability) ||
7597 nla_put_u32(msg, NL80211_BSS_FREQUENCY, res->channel->center_freq) ||
Simon Wunderlichdcd6eac2013-07-08 16:55:49 +02007598 nla_put_u32(msg, NL80211_BSS_CHAN_WIDTH, res->scan_width) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04007599 nla_put_u32(msg, NL80211_BSS_SEEN_MS_AGO,
7600 jiffies_to_msecs(jiffies - intbss->ts)))
7601 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01007602
Avraham Stern1d762502016-07-05 17:10:13 +03007603 if (intbss->parent_tsf &&
7604 (nla_put_u64_64bit(msg, NL80211_BSS_PARENT_TSF,
7605 intbss->parent_tsf, NL80211_BSS_PAD) ||
7606 nla_put(msg, NL80211_BSS_PARENT_BSSID, ETH_ALEN,
7607 intbss->parent_bssid)))
7608 goto nla_put_failure;
7609
Dmitry Shmidt6e19bc42015-10-07 11:32:53 +02007610 if (intbss->ts_boottime &&
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02007611 nla_put_u64_64bit(msg, NL80211_BSS_LAST_SEEN_BOOTTIME,
7612 intbss->ts_boottime, NL80211_BSS_PAD))
Dmitry Shmidt6e19bc42015-10-07 11:32:53 +02007613 goto nla_put_failure;
7614
Johannes Berg77965c92009-02-18 18:45:06 +01007615 switch (rdev->wiphy.signal_type) {
Johannes Berg2a519312009-02-10 21:25:55 +01007616 case CFG80211_SIGNAL_TYPE_MBM:
David S. Miller9360ffd2012-03-29 04:41:26 -04007617 if (nla_put_u32(msg, NL80211_BSS_SIGNAL_MBM, res->signal))
7618 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01007619 break;
7620 case CFG80211_SIGNAL_TYPE_UNSPEC:
David S. Miller9360ffd2012-03-29 04:41:26 -04007621 if (nla_put_u8(msg, NL80211_BSS_SIGNAL_UNSPEC, res->signal))
7622 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01007623 break;
7624 default:
7625 break;
7626 }
7627
Johannes Berg48ab9052009-07-10 18:42:31 +02007628 switch (wdev->iftype) {
Johannes Berg074ac8d2010-09-16 14:58:22 +02007629 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Berg48ab9052009-07-10 18:42:31 +02007630 case NL80211_IFTYPE_STATION:
David S. Miller9360ffd2012-03-29 04:41:26 -04007631 if (intbss == wdev->current_bss &&
7632 nla_put_u32(msg, NL80211_BSS_STATUS,
7633 NL80211_BSS_STATUS_ASSOCIATED))
7634 goto nla_put_failure;
Johannes Berg48ab9052009-07-10 18:42:31 +02007635 break;
7636 case NL80211_IFTYPE_ADHOC:
David S. Miller9360ffd2012-03-29 04:41:26 -04007637 if (intbss == wdev->current_bss &&
7638 nla_put_u32(msg, NL80211_BSS_STATUS,
7639 NL80211_BSS_STATUS_IBSS_JOINED))
7640 goto nla_put_failure;
Johannes Berg48ab9052009-07-10 18:42:31 +02007641 break;
7642 default:
7643 break;
7644 }
7645
Johannes Berg2a519312009-02-10 21:25:55 +01007646 nla_nest_end(msg, bss);
7647
Johannes Berg053c0952015-01-16 22:09:00 +01007648 genlmsg_end(msg, hdr);
7649 return 0;
Johannes Berg2a519312009-02-10 21:25:55 +01007650
Johannes Berg8cef2c92013-02-05 16:54:31 +01007651 fail_unlock_rcu:
7652 rcu_read_unlock();
Johannes Berg2a519312009-02-10 21:25:55 +01007653 nla_put_failure:
7654 genlmsg_cancel(msg, hdr);
7655 return -EMSGSIZE;
7656}
7657
Johannes Berg97990a02013-04-19 01:02:55 +02007658static int nl80211_dump_scan(struct sk_buff *skb, struct netlink_callback *cb)
Johannes Berg2a519312009-02-10 21:25:55 +01007659{
Johannes Berg48ab9052009-07-10 18:42:31 +02007660 struct cfg80211_registered_device *rdev;
Johannes Berg2a519312009-02-10 21:25:55 +01007661 struct cfg80211_internal_bss *scan;
Johannes Berg48ab9052009-07-10 18:42:31 +02007662 struct wireless_dev *wdev;
Johannes Berg97990a02013-04-19 01:02:55 +02007663 int start = cb->args[2], idx = 0;
Johannes Berg2a519312009-02-10 21:25:55 +01007664 int err;
7665
Johannes Bergea90e0d2017-03-15 14:26:04 +01007666 rtnl_lock();
Johannes Berg97990a02013-04-19 01:02:55 +02007667 err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev);
Johannes Bergea90e0d2017-03-15 14:26:04 +01007668 if (err) {
7669 rtnl_unlock();
Johannes Berg67748892010-10-04 21:14:06 +02007670 return err;
Johannes Bergea90e0d2017-03-15 14:26:04 +01007671 }
Johannes Berg2a519312009-02-10 21:25:55 +01007672
Johannes Berg48ab9052009-07-10 18:42:31 +02007673 wdev_lock(wdev);
7674 spin_lock_bh(&rdev->bss_lock);
7675 cfg80211_bss_expire(rdev);
7676
Johannes Berg9720bb32011-06-21 09:45:33 +02007677 cb->seq = rdev->bss_generation;
7678
Johannes Berg48ab9052009-07-10 18:42:31 +02007679 list_for_each_entry(scan, &rdev->bss_list, list) {
Johannes Berg2a519312009-02-10 21:25:55 +01007680 if (++idx <= start)
7681 continue;
Johannes Berg9720bb32011-06-21 09:45:33 +02007682 if (nl80211_send_bss(skb, cb,
Johannes Berg2a519312009-02-10 21:25:55 +01007683 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Johannes Berg48ab9052009-07-10 18:42:31 +02007684 rdev, wdev, scan) < 0) {
Johannes Berg2a519312009-02-10 21:25:55 +01007685 idx--;
Johannes Berg67748892010-10-04 21:14:06 +02007686 break;
Johannes Berg2a519312009-02-10 21:25:55 +01007687 }
7688 }
7689
Johannes Berg48ab9052009-07-10 18:42:31 +02007690 spin_unlock_bh(&rdev->bss_lock);
7691 wdev_unlock(wdev);
Johannes Berg2a519312009-02-10 21:25:55 +01007692
Johannes Berg97990a02013-04-19 01:02:55 +02007693 cb->args[2] = idx;
Johannes Bergea90e0d2017-03-15 14:26:04 +01007694 rtnl_unlock();
Johannes Berg2a519312009-02-10 21:25:55 +01007695
Johannes Berg67748892010-10-04 21:14:06 +02007696 return skb->len;
Johannes Berg2a519312009-02-10 21:25:55 +01007697}
7698
Eric W. Biederman15e47302012-09-07 20:12:54 +00007699static int nl80211_send_survey(struct sk_buff *msg, u32 portid, u32 seq,
Johannes Berg11f78ac2014-11-14 16:43:50 +01007700 int flags, struct net_device *dev,
7701 bool allow_radio_stats,
7702 struct survey_info *survey)
Holger Schurig61fa7132009-11-11 12:25:40 +01007703{
7704 void *hdr;
7705 struct nlattr *infoattr;
7706
Johannes Berg11f78ac2014-11-14 16:43:50 +01007707 /* skip radio stats if userspace didn't request them */
7708 if (!survey->channel && !allow_radio_stats)
7709 return 0;
7710
Eric W. Biederman15e47302012-09-07 20:12:54 +00007711 hdr = nl80211hdr_put(msg, portid, seq, flags,
Holger Schurig61fa7132009-11-11 12:25:40 +01007712 NL80211_CMD_NEW_SURVEY_RESULTS);
7713 if (!hdr)
7714 return -ENOMEM;
7715
David S. Miller9360ffd2012-03-29 04:41:26 -04007716 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex))
7717 goto nla_put_failure;
Holger Schurig61fa7132009-11-11 12:25:40 +01007718
7719 infoattr = nla_nest_start(msg, NL80211_ATTR_SURVEY_INFO);
7720 if (!infoattr)
7721 goto nla_put_failure;
7722
Johannes Berg11f78ac2014-11-14 16:43:50 +01007723 if (survey->channel &&
7724 nla_put_u32(msg, NL80211_SURVEY_INFO_FREQUENCY,
David S. Miller9360ffd2012-03-29 04:41:26 -04007725 survey->channel->center_freq))
7726 goto nla_put_failure;
7727
7728 if ((survey->filled & SURVEY_INFO_NOISE_DBM) &&
7729 nla_put_u8(msg, NL80211_SURVEY_INFO_NOISE, survey->noise))
7730 goto nla_put_failure;
7731 if ((survey->filled & SURVEY_INFO_IN_USE) &&
7732 nla_put_flag(msg, NL80211_SURVEY_INFO_IN_USE))
7733 goto nla_put_failure;
Johannes Berg4ed20be2014-11-14 16:35:34 +01007734 if ((survey->filled & SURVEY_INFO_TIME) &&
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02007735 nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME,
7736 survey->time, NL80211_SURVEY_INFO_PAD))
David S. Miller9360ffd2012-03-29 04:41:26 -04007737 goto nla_put_failure;
Johannes Berg4ed20be2014-11-14 16:35:34 +01007738 if ((survey->filled & SURVEY_INFO_TIME_BUSY) &&
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02007739 nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME_BUSY,
7740 survey->time_busy, NL80211_SURVEY_INFO_PAD))
David S. Miller9360ffd2012-03-29 04:41:26 -04007741 goto nla_put_failure;
Johannes Berg4ed20be2014-11-14 16:35:34 +01007742 if ((survey->filled & SURVEY_INFO_TIME_EXT_BUSY) &&
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02007743 nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME_EXT_BUSY,
7744 survey->time_ext_busy, NL80211_SURVEY_INFO_PAD))
David S. Miller9360ffd2012-03-29 04:41:26 -04007745 goto nla_put_failure;
Johannes Berg4ed20be2014-11-14 16:35:34 +01007746 if ((survey->filled & SURVEY_INFO_TIME_RX) &&
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02007747 nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME_RX,
7748 survey->time_rx, NL80211_SURVEY_INFO_PAD))
David S. Miller9360ffd2012-03-29 04:41:26 -04007749 goto nla_put_failure;
Johannes Berg4ed20be2014-11-14 16:35:34 +01007750 if ((survey->filled & SURVEY_INFO_TIME_TX) &&
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02007751 nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME_TX,
7752 survey->time_tx, NL80211_SURVEY_INFO_PAD))
David S. Miller9360ffd2012-03-29 04:41:26 -04007753 goto nla_put_failure;
Johannes Berg052536a2014-11-14 16:44:11 +01007754 if ((survey->filled & SURVEY_INFO_TIME_SCAN) &&
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02007755 nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME_SCAN,
7756 survey->time_scan, NL80211_SURVEY_INFO_PAD))
Johannes Berg052536a2014-11-14 16:44:11 +01007757 goto nla_put_failure;
Holger Schurig61fa7132009-11-11 12:25:40 +01007758
7759 nla_nest_end(msg, infoattr);
7760
Johannes Berg053c0952015-01-16 22:09:00 +01007761 genlmsg_end(msg, hdr);
7762 return 0;
Holger Schurig61fa7132009-11-11 12:25:40 +01007763
7764 nla_put_failure:
7765 genlmsg_cancel(msg, hdr);
7766 return -EMSGSIZE;
7767}
7768
Johannes Berg11f78ac2014-11-14 16:43:50 +01007769static int nl80211_dump_survey(struct sk_buff *skb, struct netlink_callback *cb)
Holger Schurig61fa7132009-11-11 12:25:40 +01007770{
Johannes Bergc90c39d2016-10-24 14:40:01 +02007771 struct nlattr **attrbuf = genl_family_attrbuf(&nl80211_fam);
Holger Schurig61fa7132009-11-11 12:25:40 +01007772 struct survey_info survey;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08007773 struct cfg80211_registered_device *rdev;
Johannes Berg97990a02013-04-19 01:02:55 +02007774 struct wireless_dev *wdev;
7775 int survey_idx = cb->args[2];
Holger Schurig61fa7132009-11-11 12:25:40 +01007776 int res;
Johannes Berg11f78ac2014-11-14 16:43:50 +01007777 bool radio_stats;
Holger Schurig61fa7132009-11-11 12:25:40 +01007778
Johannes Bergea90e0d2017-03-15 14:26:04 +01007779 rtnl_lock();
Zhao, Gang1b8ec872014-04-21 12:53:02 +08007780 res = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev);
Johannes Berg67748892010-10-04 21:14:06 +02007781 if (res)
Johannes Bergea90e0d2017-03-15 14:26:04 +01007782 goto out_err;
Holger Schurig61fa7132009-11-11 12:25:40 +01007783
Johannes Berg11f78ac2014-11-14 16:43:50 +01007784 /* prepare_wdev_dump parsed the attributes */
Johannes Bergc90c39d2016-10-24 14:40:01 +02007785 radio_stats = attrbuf[NL80211_ATTR_SURVEY_RADIO_STATS];
Johannes Berg11f78ac2014-11-14 16:43:50 +01007786
Johannes Berg97990a02013-04-19 01:02:55 +02007787 if (!wdev->netdev) {
7788 res = -EINVAL;
7789 goto out_err;
7790 }
7791
Zhao, Gang1b8ec872014-04-21 12:53:02 +08007792 if (!rdev->ops->dump_survey) {
Holger Schurig61fa7132009-11-11 12:25:40 +01007793 res = -EOPNOTSUPP;
7794 goto out_err;
7795 }
7796
7797 while (1) {
Zhao, Gang1b8ec872014-04-21 12:53:02 +08007798 res = rdev_dump_survey(rdev, wdev->netdev, survey_idx, &survey);
Holger Schurig61fa7132009-11-11 12:25:40 +01007799 if (res == -ENOENT)
7800 break;
7801 if (res)
7802 goto out_err;
7803
Johannes Berg11f78ac2014-11-14 16:43:50 +01007804 /* don't send disabled channels, but do send non-channel data */
7805 if (survey.channel &&
7806 survey.channel->flags & IEEE80211_CHAN_DISABLED) {
Luis R. Rodriguez180cdc72011-05-27 07:24:02 -07007807 survey_idx++;
7808 continue;
7809 }
7810
Holger Schurig61fa7132009-11-11 12:25:40 +01007811 if (nl80211_send_survey(skb,
Eric W. Biederman15e47302012-09-07 20:12:54 +00007812 NETLINK_CB(cb->skb).portid,
Holger Schurig61fa7132009-11-11 12:25:40 +01007813 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Johannes Berg11f78ac2014-11-14 16:43:50 +01007814 wdev->netdev, radio_stats, &survey) < 0)
Holger Schurig61fa7132009-11-11 12:25:40 +01007815 goto out;
7816 survey_idx++;
7817 }
7818
7819 out:
Johannes Berg97990a02013-04-19 01:02:55 +02007820 cb->args[2] = survey_idx;
Holger Schurig61fa7132009-11-11 12:25:40 +01007821 res = skb->len;
7822 out_err:
Johannes Bergea90e0d2017-03-15 14:26:04 +01007823 rtnl_unlock();
Holger Schurig61fa7132009-11-11 12:25:40 +01007824 return res;
7825}
7826
Samuel Ortizb23aa672009-07-01 21:26:54 +02007827static bool nl80211_valid_wpa_versions(u32 wpa_versions)
7828{
7829 return !(wpa_versions & ~(NL80211_WPA_VERSION_1 |
7830 NL80211_WPA_VERSION_2));
7831}
7832
Jouni Malinen636a5d32009-03-19 13:39:22 +02007833static int nl80211_authenticate(struct sk_buff *skb, struct genl_info *info)
7834{
Johannes Berg4c476992010-10-04 21:36:35 +02007835 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7836 struct net_device *dev = info->user_ptr[1];
Johannes Berg19957bb2009-07-02 17:20:43 +02007837 struct ieee80211_channel *chan;
Jouni Malinen11b6b5a2016-10-27 00:41:58 +03007838 const u8 *bssid, *ssid, *ie = NULL, *auth_data = NULL;
7839 int err, ssid_len, ie_len = 0, auth_data_len = 0;
Johannes Berg19957bb2009-07-02 17:20:43 +02007840 enum nl80211_auth_type auth_type;
Johannes Bergfffd0932009-07-08 14:22:54 +02007841 struct key_parse key;
Jouni Malinend5cdfac2010-04-04 09:37:19 +03007842 bool local_state_change;
Jouni Malinen636a5d32009-03-19 13:39:22 +02007843
Johannes Bergf4a11bb2009-03-27 12:40:28 +01007844 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
7845 return -EINVAL;
7846
7847 if (!info->attrs[NL80211_ATTR_MAC])
7848 return -EINVAL;
7849
Jouni Malinen17780922009-03-27 20:52:47 +02007850 if (!info->attrs[NL80211_ATTR_AUTH_TYPE])
7851 return -EINVAL;
7852
Johannes Berg19957bb2009-07-02 17:20:43 +02007853 if (!info->attrs[NL80211_ATTR_SSID])
7854 return -EINVAL;
7855
7856 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ])
7857 return -EINVAL;
7858
Johannes Bergfffd0932009-07-08 14:22:54 +02007859 err = nl80211_parse_key(info, &key);
7860 if (err)
7861 return err;
7862
7863 if (key.idx >= 0) {
Johannes Berge31b8212010-10-05 19:39:30 +02007864 if (key.type != -1 && key.type != NL80211_KEYTYPE_GROUP)
7865 return -EINVAL;
Johannes Bergfffd0932009-07-08 14:22:54 +02007866 if (!key.p.key || !key.p.key_len)
7867 return -EINVAL;
7868 if ((key.p.cipher != WLAN_CIPHER_SUITE_WEP40 ||
7869 key.p.key_len != WLAN_KEY_LEN_WEP40) &&
7870 (key.p.cipher != WLAN_CIPHER_SUITE_WEP104 ||
7871 key.p.key_len != WLAN_KEY_LEN_WEP104))
7872 return -EINVAL;
Johannes Bergb6b55552016-09-13 16:25:58 +02007873 if (key.idx > 3)
Johannes Bergfffd0932009-07-08 14:22:54 +02007874 return -EINVAL;
7875 } else {
7876 key.p.key_len = 0;
7877 key.p.key = NULL;
7878 }
7879
Johannes Bergafea0b72010-08-10 09:46:42 +02007880 if (key.idx >= 0) {
7881 int i;
7882 bool ok = false;
Kirtika Ruchandani7a087e72016-05-29 19:51:23 -07007883
Johannes Bergafea0b72010-08-10 09:46:42 +02007884 for (i = 0; i < rdev->wiphy.n_cipher_suites; i++) {
7885 if (key.p.cipher == rdev->wiphy.cipher_suites[i]) {
7886 ok = true;
7887 break;
7888 }
7889 }
Johannes Berg4c476992010-10-04 21:36:35 +02007890 if (!ok)
7891 return -EINVAL;
Johannes Bergafea0b72010-08-10 09:46:42 +02007892 }
7893
Johannes Berg4c476992010-10-04 21:36:35 +02007894 if (!rdev->ops->auth)
7895 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02007896
Johannes Berg074ac8d2010-09-16 14:58:22 +02007897 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02007898 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
7899 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02007900
Johannes Berg19957bb2009-07-02 17:20:43 +02007901 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen664834d2014-01-15 00:01:44 +02007902 chan = nl80211_get_valid_chan(&rdev->wiphy,
7903 info->attrs[NL80211_ATTR_WIPHY_FREQ]);
7904 if (!chan)
Johannes Berg4c476992010-10-04 21:36:35 +02007905 return -EINVAL;
Jouni Malinen636a5d32009-03-19 13:39:22 +02007906
Johannes Berg19957bb2009-07-02 17:20:43 +02007907 ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
7908 ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
7909
7910 if (info->attrs[NL80211_ATTR_IE]) {
7911 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
7912 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
7913 }
7914
7915 auth_type = nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]);
Jouni Malinene39e5b52012-09-30 19:29:39 +03007916 if (!nl80211_valid_auth_type(rdev, auth_type, NL80211_CMD_AUTHENTICATE))
Johannes Berg4c476992010-10-04 21:36:35 +02007917 return -EINVAL;
Johannes Berg19957bb2009-07-02 17:20:43 +02007918
Jouni Malinen63181062016-10-27 00:42:02 +03007919 if ((auth_type == NL80211_AUTHTYPE_SAE ||
7920 auth_type == NL80211_AUTHTYPE_FILS_SK ||
7921 auth_type == NL80211_AUTHTYPE_FILS_SK_PFS ||
7922 auth_type == NL80211_AUTHTYPE_FILS_PK) &&
Jouni Malinen11b6b5a2016-10-27 00:41:58 +03007923 !info->attrs[NL80211_ATTR_AUTH_DATA])
Jouni Malinene39e5b52012-09-30 19:29:39 +03007924 return -EINVAL;
7925
Jouni Malinen11b6b5a2016-10-27 00:41:58 +03007926 if (info->attrs[NL80211_ATTR_AUTH_DATA]) {
Jouni Malinen63181062016-10-27 00:42:02 +03007927 if (auth_type != NL80211_AUTHTYPE_SAE &&
7928 auth_type != NL80211_AUTHTYPE_FILS_SK &&
7929 auth_type != NL80211_AUTHTYPE_FILS_SK_PFS &&
7930 auth_type != NL80211_AUTHTYPE_FILS_PK)
Jouni Malinene39e5b52012-09-30 19:29:39 +03007931 return -EINVAL;
Jouni Malinen11b6b5a2016-10-27 00:41:58 +03007932 auth_data = nla_data(info->attrs[NL80211_ATTR_AUTH_DATA]);
7933 auth_data_len = nla_len(info->attrs[NL80211_ATTR_AUTH_DATA]);
Jouni Malinene39e5b52012-09-30 19:29:39 +03007934 /* need to include at least Auth Transaction and Status Code */
Jouni Malinen11b6b5a2016-10-27 00:41:58 +03007935 if (auth_data_len < 4)
Jouni Malinene39e5b52012-09-30 19:29:39 +03007936 return -EINVAL;
7937 }
7938
Jouni Malinend5cdfac2010-04-04 09:37:19 +03007939 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE];
7940
Johannes Berg95de8172012-01-20 13:55:25 +01007941 /*
7942 * Since we no longer track auth state, ignore
7943 * requests to only change local state.
7944 */
7945 if (local_state_change)
7946 return 0;
7947
Johannes Berg91bf9b22013-05-15 17:44:01 +02007948 wdev_lock(dev->ieee80211_ptr);
7949 err = cfg80211_mlme_auth(rdev, dev, chan, auth_type, bssid,
7950 ssid, ssid_len, ie, ie_len,
7951 key.p.key, key.p.key_len, key.idx,
Jouni Malinen11b6b5a2016-10-27 00:41:58 +03007952 auth_data, auth_data_len);
Johannes Berg91bf9b22013-05-15 17:44:01 +02007953 wdev_unlock(dev->ieee80211_ptr);
7954 return err;
Jouni Malinen636a5d32009-03-19 13:39:22 +02007955}
7956
Johannes Bergc0692b82010-08-27 14:26:53 +03007957static int nl80211_crypto_settings(struct cfg80211_registered_device *rdev,
7958 struct genl_info *info,
Johannes Berg3dc27d22009-07-02 21:36:37 +02007959 struct cfg80211_crypto_settings *settings,
7960 int cipher_limit)
Samuel Ortizb23aa672009-07-01 21:26:54 +02007961{
Johannes Bergc0b2bbd2009-07-25 16:54:36 +02007962 memset(settings, 0, sizeof(*settings));
7963
Samuel Ortizb23aa672009-07-01 21:26:54 +02007964 settings->control_port = info->attrs[NL80211_ATTR_CONTROL_PORT];
7965
Johannes Bergc0692b82010-08-27 14:26:53 +03007966 if (info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]) {
7967 u16 proto;
Kirtika Ruchandani7a087e72016-05-29 19:51:23 -07007968
Johannes Bergc0692b82010-08-27 14:26:53 +03007969 proto = nla_get_u16(
7970 info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]);
7971 settings->control_port_ethertype = cpu_to_be16(proto);
7972 if (!(rdev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) &&
7973 proto != ETH_P_PAE)
7974 return -EINVAL;
7975 if (info->attrs[NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT])
7976 settings->control_port_no_encrypt = true;
7977 } else
7978 settings->control_port_ethertype = cpu_to_be16(ETH_P_PAE);
7979
Samuel Ortizb23aa672009-07-01 21:26:54 +02007980 if (info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]) {
7981 void *data;
7982 int len, i;
7983
7984 data = nla_data(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]);
7985 len = nla_len(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]);
7986 settings->n_ciphers_pairwise = len / sizeof(u32);
7987
7988 if (len % sizeof(u32))
7989 return -EINVAL;
7990
Johannes Berg3dc27d22009-07-02 21:36:37 +02007991 if (settings->n_ciphers_pairwise > cipher_limit)
Samuel Ortizb23aa672009-07-01 21:26:54 +02007992 return -EINVAL;
7993
7994 memcpy(settings->ciphers_pairwise, data, len);
7995
7996 for (i = 0; i < settings->n_ciphers_pairwise; i++)
Jouni Malinen38ba3c52011-09-21 18:14:56 +03007997 if (!cfg80211_supported_cipher_suite(
7998 &rdev->wiphy,
Samuel Ortizb23aa672009-07-01 21:26:54 +02007999 settings->ciphers_pairwise[i]))
8000 return -EINVAL;
8001 }
8002
8003 if (info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]) {
8004 settings->cipher_group =
8005 nla_get_u32(info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]);
Jouni Malinen38ba3c52011-09-21 18:14:56 +03008006 if (!cfg80211_supported_cipher_suite(&rdev->wiphy,
8007 settings->cipher_group))
Samuel Ortizb23aa672009-07-01 21:26:54 +02008008 return -EINVAL;
8009 }
8010
8011 if (info->attrs[NL80211_ATTR_WPA_VERSIONS]) {
8012 settings->wpa_versions =
8013 nla_get_u32(info->attrs[NL80211_ATTR_WPA_VERSIONS]);
8014 if (!nl80211_valid_wpa_versions(settings->wpa_versions))
8015 return -EINVAL;
8016 }
8017
8018 if (info->attrs[NL80211_ATTR_AKM_SUITES]) {
8019 void *data;
Jouni Malinen6d302402011-09-21 18:11:33 +03008020 int len;
Samuel Ortizb23aa672009-07-01 21:26:54 +02008021
8022 data = nla_data(info->attrs[NL80211_ATTR_AKM_SUITES]);
8023 len = nla_len(info->attrs[NL80211_ATTR_AKM_SUITES]);
8024 settings->n_akm_suites = len / sizeof(u32);
8025
8026 if (len % sizeof(u32))
8027 return -EINVAL;
8028
Jouni Malinen1b9ca022011-09-21 16:13:07 +03008029 if (settings->n_akm_suites > NL80211_MAX_NR_AKM_SUITES)
8030 return -EINVAL;
8031
Samuel Ortizb23aa672009-07-01 21:26:54 +02008032 memcpy(settings->akm_suites, data, len);
Samuel Ortizb23aa672009-07-01 21:26:54 +02008033 }
8034
8035 return 0;
8036}
8037
Jouni Malinen636a5d32009-03-19 13:39:22 +02008038static int nl80211_associate(struct sk_buff *skb, struct genl_info *info)
8039{
Johannes Berg4c476992010-10-04 21:36:35 +02008040 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8041 struct net_device *dev = info->user_ptr[1];
Johannes Bergf444de02010-05-05 15:25:02 +02008042 struct ieee80211_channel *chan;
Johannes Bergf62fab72013-02-21 20:09:09 +01008043 struct cfg80211_assoc_request req = {};
8044 const u8 *bssid, *ssid;
8045 int err, ssid_len = 0;
Jouni Malinen636a5d32009-03-19 13:39:22 +02008046
Johannes Bergf4a11bb2009-03-27 12:40:28 +01008047 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
8048 return -EINVAL;
8049
8050 if (!info->attrs[NL80211_ATTR_MAC] ||
Johannes Berg19957bb2009-07-02 17:20:43 +02008051 !info->attrs[NL80211_ATTR_SSID] ||
8052 !info->attrs[NL80211_ATTR_WIPHY_FREQ])
Johannes Bergf4a11bb2009-03-27 12:40:28 +01008053 return -EINVAL;
8054
Johannes Berg4c476992010-10-04 21:36:35 +02008055 if (!rdev->ops->assoc)
8056 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02008057
Johannes Berg074ac8d2010-09-16 14:58:22 +02008058 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02008059 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
8060 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02008061
Johannes Berg19957bb2009-07-02 17:20:43 +02008062 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02008063
Jouni Malinen664834d2014-01-15 00:01:44 +02008064 chan = nl80211_get_valid_chan(&rdev->wiphy,
8065 info->attrs[NL80211_ATTR_WIPHY_FREQ]);
8066 if (!chan)
Johannes Berg4c476992010-10-04 21:36:35 +02008067 return -EINVAL;
Jouni Malinen636a5d32009-03-19 13:39:22 +02008068
Johannes Berg19957bb2009-07-02 17:20:43 +02008069 ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
8070 ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02008071
8072 if (info->attrs[NL80211_ATTR_IE]) {
Johannes Bergf62fab72013-02-21 20:09:09 +01008073 req.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
8074 req.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02008075 }
8076
Jouni Malinendc6382ce2009-05-06 22:09:37 +03008077 if (info->attrs[NL80211_ATTR_USE_MFP]) {
Johannes Berg4f5dadc2009-07-07 03:56:10 +02008078 enum nl80211_mfp mfp =
Jouni Malinendc6382ce2009-05-06 22:09:37 +03008079 nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]);
Johannes Berg4f5dadc2009-07-07 03:56:10 +02008080 if (mfp == NL80211_MFP_REQUIRED)
Johannes Bergf62fab72013-02-21 20:09:09 +01008081 req.use_mfp = true;
Johannes Berg4c476992010-10-04 21:36:35 +02008082 else if (mfp != NL80211_MFP_NO)
8083 return -EINVAL;
Jouni Malinendc6382ce2009-05-06 22:09:37 +03008084 }
8085
Johannes Berg3e5d7642009-07-07 14:37:26 +02008086 if (info->attrs[NL80211_ATTR_PREV_BSSID])
Johannes Bergf62fab72013-02-21 20:09:09 +01008087 req.prev_bssid = nla_data(info->attrs[NL80211_ATTR_PREV_BSSID]);
Johannes Berg3e5d7642009-07-07 14:37:26 +02008088
Ben Greear7e7c8922011-11-18 11:31:59 -08008089 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT]))
Johannes Bergf62fab72013-02-21 20:09:09 +01008090 req.flags |= ASSOC_REQ_DISABLE_HT;
Ben Greear7e7c8922011-11-18 11:31:59 -08008091
8092 if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
Johannes Bergf62fab72013-02-21 20:09:09 +01008093 memcpy(&req.ht_capa_mask,
8094 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]),
8095 sizeof(req.ht_capa_mask));
Ben Greear7e7c8922011-11-18 11:31:59 -08008096
8097 if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) {
Johannes Bergf62fab72013-02-21 20:09:09 +01008098 if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
Ben Greear7e7c8922011-11-18 11:31:59 -08008099 return -EINVAL;
Johannes Bergf62fab72013-02-21 20:09:09 +01008100 memcpy(&req.ht_capa,
8101 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]),
8102 sizeof(req.ht_capa));
Ben Greear7e7c8922011-11-18 11:31:59 -08008103 }
8104
Johannes Bergee2aca32013-02-21 17:36:01 +01008105 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_VHT]))
Johannes Bergf62fab72013-02-21 20:09:09 +01008106 req.flags |= ASSOC_REQ_DISABLE_VHT;
Johannes Bergee2aca32013-02-21 17:36:01 +01008107
8108 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK])
Johannes Bergf62fab72013-02-21 20:09:09 +01008109 memcpy(&req.vht_capa_mask,
8110 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]),
8111 sizeof(req.vht_capa_mask));
Johannes Bergee2aca32013-02-21 17:36:01 +01008112
8113 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) {
Johannes Bergf62fab72013-02-21 20:09:09 +01008114 if (!info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK])
Johannes Bergee2aca32013-02-21 17:36:01 +01008115 return -EINVAL;
Johannes Bergf62fab72013-02-21 20:09:09 +01008116 memcpy(&req.vht_capa,
8117 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]),
8118 sizeof(req.vht_capa));
Johannes Bergee2aca32013-02-21 17:36:01 +01008119 }
8120
Assaf Kraussbab5ab72014-09-03 15:25:01 +03008121 if (nla_get_flag(info->attrs[NL80211_ATTR_USE_RRM])) {
Beni Lev0c9ca112016-02-17 20:30:00 +02008122 if (!((rdev->wiphy.features &
8123 NL80211_FEATURE_DS_PARAM_SET_IE_IN_PROBES) &&
8124 (rdev->wiphy.features & NL80211_FEATURE_QUIET)) &&
8125 !wiphy_ext_feature_isset(&rdev->wiphy,
8126 NL80211_EXT_FEATURE_RRM))
Assaf Kraussbab5ab72014-09-03 15:25:01 +03008127 return -EINVAL;
8128 req.flags |= ASSOC_REQ_USE_RRM;
8129 }
8130
Jouni Malinen348bd452016-10-27 00:42:03 +03008131 if (info->attrs[NL80211_ATTR_FILS_KEK]) {
8132 req.fils_kek = nla_data(info->attrs[NL80211_ATTR_FILS_KEK]);
8133 req.fils_kek_len = nla_len(info->attrs[NL80211_ATTR_FILS_KEK]);
8134 if (!info->attrs[NL80211_ATTR_FILS_NONCES])
8135 return -EINVAL;
8136 req.fils_nonces =
8137 nla_data(info->attrs[NL80211_ATTR_FILS_NONCES]);
8138 }
8139
Johannes Bergf62fab72013-02-21 20:09:09 +01008140 err = nl80211_crypto_settings(rdev, info, &req.crypto, 1);
Johannes Berg91bf9b22013-05-15 17:44:01 +02008141 if (!err) {
8142 wdev_lock(dev->ieee80211_ptr);
Andrzej Zaborowskibd2522b2017-01-06 16:33:43 -05008143
Johannes Bergf62fab72013-02-21 20:09:09 +01008144 err = cfg80211_mlme_assoc(rdev, dev, chan, bssid,
8145 ssid, ssid_len, &req);
Andrzej Zaborowskibd2522b2017-01-06 16:33:43 -05008146
8147 if (!err && info->attrs[NL80211_ATTR_SOCKET_OWNER]) {
8148 dev->ieee80211_ptr->conn_owner_nlportid =
8149 info->snd_portid;
8150 memcpy(dev->ieee80211_ptr->disconnect_bssid,
8151 bssid, ETH_ALEN);
8152 }
8153
Johannes Berg91bf9b22013-05-15 17:44:01 +02008154 wdev_unlock(dev->ieee80211_ptr);
8155 }
Jouni Malinen636a5d32009-03-19 13:39:22 +02008156
Jouni Malinen636a5d32009-03-19 13:39:22 +02008157 return err;
8158}
8159
8160static int nl80211_deauthenticate(struct sk_buff *skb, struct genl_info *info)
8161{
Johannes Berg4c476992010-10-04 21:36:35 +02008162 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8163 struct net_device *dev = info->user_ptr[1];
Johannes Berg19957bb2009-07-02 17:20:43 +02008164 const u8 *ie = NULL, *bssid;
Johannes Berg91bf9b22013-05-15 17:44:01 +02008165 int ie_len = 0, err;
Johannes Berg19957bb2009-07-02 17:20:43 +02008166 u16 reason_code;
Jouni Malinend5cdfac2010-04-04 09:37:19 +03008167 bool local_state_change;
Jouni Malinen636a5d32009-03-19 13:39:22 +02008168
Johannes Bergf4a11bb2009-03-27 12:40:28 +01008169 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
8170 return -EINVAL;
8171
8172 if (!info->attrs[NL80211_ATTR_MAC])
8173 return -EINVAL;
8174
8175 if (!info->attrs[NL80211_ATTR_REASON_CODE])
8176 return -EINVAL;
8177
Johannes Berg4c476992010-10-04 21:36:35 +02008178 if (!rdev->ops->deauth)
8179 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02008180
Johannes Berg074ac8d2010-09-16 14:58:22 +02008181 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02008182 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
8183 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02008184
Johannes Berg19957bb2009-07-02 17:20:43 +02008185 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02008186
Johannes Berg19957bb2009-07-02 17:20:43 +02008187 reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
8188 if (reason_code == 0) {
Johannes Bergf4a11bb2009-03-27 12:40:28 +01008189 /* Reason Code 0 is reserved */
Johannes Berg4c476992010-10-04 21:36:35 +02008190 return -EINVAL;
Jouni Malinen255e7372009-03-20 21:21:17 +02008191 }
Jouni Malinen636a5d32009-03-19 13:39:22 +02008192
8193 if (info->attrs[NL80211_ATTR_IE]) {
Johannes Berg19957bb2009-07-02 17:20:43 +02008194 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
8195 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02008196 }
8197
Jouni Malinend5cdfac2010-04-04 09:37:19 +03008198 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE];
8199
Johannes Berg91bf9b22013-05-15 17:44:01 +02008200 wdev_lock(dev->ieee80211_ptr);
8201 err = cfg80211_mlme_deauth(rdev, dev, bssid, ie, ie_len, reason_code,
8202 local_state_change);
8203 wdev_unlock(dev->ieee80211_ptr);
8204 return err;
Jouni Malinen636a5d32009-03-19 13:39:22 +02008205}
8206
8207static int nl80211_disassociate(struct sk_buff *skb, struct genl_info *info)
8208{
Johannes Berg4c476992010-10-04 21:36:35 +02008209 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8210 struct net_device *dev = info->user_ptr[1];
Johannes Berg19957bb2009-07-02 17:20:43 +02008211 const u8 *ie = NULL, *bssid;
Johannes Berg91bf9b22013-05-15 17:44:01 +02008212 int ie_len = 0, err;
Johannes Berg19957bb2009-07-02 17:20:43 +02008213 u16 reason_code;
Jouni Malinend5cdfac2010-04-04 09:37:19 +03008214 bool local_state_change;
Jouni Malinen636a5d32009-03-19 13:39:22 +02008215
Johannes Bergf4a11bb2009-03-27 12:40:28 +01008216 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
8217 return -EINVAL;
8218
8219 if (!info->attrs[NL80211_ATTR_MAC])
8220 return -EINVAL;
8221
8222 if (!info->attrs[NL80211_ATTR_REASON_CODE])
8223 return -EINVAL;
8224
Johannes Berg4c476992010-10-04 21:36:35 +02008225 if (!rdev->ops->disassoc)
8226 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02008227
Johannes Berg074ac8d2010-09-16 14:58:22 +02008228 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02008229 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
8230 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02008231
Johannes Berg19957bb2009-07-02 17:20:43 +02008232 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02008233
Johannes Berg19957bb2009-07-02 17:20:43 +02008234 reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
8235 if (reason_code == 0) {
Johannes Bergf4a11bb2009-03-27 12:40:28 +01008236 /* Reason Code 0 is reserved */
Johannes Berg4c476992010-10-04 21:36:35 +02008237 return -EINVAL;
Jouni Malinen255e7372009-03-20 21:21:17 +02008238 }
Jouni Malinen636a5d32009-03-19 13:39:22 +02008239
8240 if (info->attrs[NL80211_ATTR_IE]) {
Johannes Berg19957bb2009-07-02 17:20:43 +02008241 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
8242 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02008243 }
8244
Jouni Malinend5cdfac2010-04-04 09:37:19 +03008245 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE];
8246
Johannes Berg91bf9b22013-05-15 17:44:01 +02008247 wdev_lock(dev->ieee80211_ptr);
8248 err = cfg80211_mlme_disassoc(rdev, dev, bssid, ie, ie_len, reason_code,
8249 local_state_change);
8250 wdev_unlock(dev->ieee80211_ptr);
8251 return err;
Jouni Malinen636a5d32009-03-19 13:39:22 +02008252}
8253
Felix Fietkaudd5b4cc2010-11-22 20:58:24 +01008254static bool
8255nl80211_parse_mcast_rate(struct cfg80211_registered_device *rdev,
Johannes Berg57fbcce2016-04-12 15:56:15 +02008256 int mcast_rate[NUM_NL80211_BANDS],
Felix Fietkaudd5b4cc2010-11-22 20:58:24 +01008257 int rateval)
8258{
8259 struct wiphy *wiphy = &rdev->wiphy;
8260 bool found = false;
8261 int band, i;
8262
Johannes Berg57fbcce2016-04-12 15:56:15 +02008263 for (band = 0; band < NUM_NL80211_BANDS; band++) {
Felix Fietkaudd5b4cc2010-11-22 20:58:24 +01008264 struct ieee80211_supported_band *sband;
8265
8266 sband = wiphy->bands[band];
8267 if (!sband)
8268 continue;
8269
8270 for (i = 0; i < sband->n_bitrates; i++) {
8271 if (sband->bitrates[i].bitrate == rateval) {
8272 mcast_rate[band] = i + 1;
8273 found = true;
8274 break;
8275 }
8276 }
8277 }
8278
8279 return found;
8280}
8281
Johannes Berg04a773a2009-04-19 21:24:32 +02008282static int nl80211_join_ibss(struct sk_buff *skb, struct genl_info *info)
8283{
Johannes Berg4c476992010-10-04 21:36:35 +02008284 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8285 struct net_device *dev = info->user_ptr[1];
Johannes Berg04a773a2009-04-19 21:24:32 +02008286 struct cfg80211_ibss_params ibss;
8287 struct wiphy *wiphy;
Johannes Bergfffd0932009-07-08 14:22:54 +02008288 struct cfg80211_cached_keys *connkeys = NULL;
Johannes Berg04a773a2009-04-19 21:24:32 +02008289 int err;
8290
Johannes Berg8e30bc52009-04-22 17:45:38 +02008291 memset(&ibss, 0, sizeof(ibss));
8292
Johannes Berg04a773a2009-04-19 21:24:32 +02008293 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
8294 return -EINVAL;
8295
Johannes Berg683b6d32012-11-08 21:25:48 +01008296 if (!info->attrs[NL80211_ATTR_SSID] ||
Johannes Berg04a773a2009-04-19 21:24:32 +02008297 !nla_len(info->attrs[NL80211_ATTR_SSID]))
8298 return -EINVAL;
8299
Johannes Berg8e30bc52009-04-22 17:45:38 +02008300 ibss.beacon_interval = 100;
8301
Purushottam Kushwaha12d20fc92016-08-11 15:14:02 +05308302 if (info->attrs[NL80211_ATTR_BEACON_INTERVAL])
Johannes Berg8e30bc52009-04-22 17:45:38 +02008303 ibss.beacon_interval =
8304 nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]);
Purushottam Kushwaha12d20fc92016-08-11 15:14:02 +05308305
Purushottam Kushwaha0c317a02016-10-12 18:26:51 +05308306 err = cfg80211_validate_beacon_int(rdev, NL80211_IFTYPE_ADHOC,
8307 ibss.beacon_interval);
Purushottam Kushwaha12d20fc92016-08-11 15:14:02 +05308308 if (err)
8309 return err;
Johannes Berg8e30bc52009-04-22 17:45:38 +02008310
Johannes Berg4c476992010-10-04 21:36:35 +02008311 if (!rdev->ops->join_ibss)
8312 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02008313
Johannes Berg4c476992010-10-04 21:36:35 +02008314 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC)
8315 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02008316
Johannes Berg79c97e92009-07-07 03:56:12 +02008317 wiphy = &rdev->wiphy;
Johannes Berg04a773a2009-04-19 21:24:32 +02008318
Johannes Berg39193492011-09-16 13:45:25 +02008319 if (info->attrs[NL80211_ATTR_MAC]) {
Johannes Berg04a773a2009-04-19 21:24:32 +02008320 ibss.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Johannes Berg39193492011-09-16 13:45:25 +02008321
8322 if (!is_valid_ether_addr(ibss.bssid))
8323 return -EINVAL;
8324 }
Johannes Berg04a773a2009-04-19 21:24:32 +02008325 ibss.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
8326 ibss.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
8327
8328 if (info->attrs[NL80211_ATTR_IE]) {
8329 ibss.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
8330 ibss.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
8331 }
8332
Johannes Berg683b6d32012-11-08 21:25:48 +01008333 err = nl80211_parse_chandef(rdev, info, &ibss.chandef);
8334 if (err)
8335 return err;
Alexander Simon54858ee5b2011-11-30 16:56:32 +01008336
Ilan Peer174e0cd2014-02-23 09:13:01 +02008337 if (!cfg80211_reg_can_beacon(&rdev->wiphy, &ibss.chandef,
8338 NL80211_IFTYPE_ADHOC))
Alexander Simon54858ee5b2011-11-30 16:56:32 +01008339 return -EINVAL;
8340
Simon Wunderlich2f301ab2013-05-16 13:00:28 +02008341 switch (ibss.chandef.width) {
Simon Wunderlichbf372642013-07-08 16:55:58 +02008342 case NL80211_CHAN_WIDTH_5:
8343 case NL80211_CHAN_WIDTH_10:
Simon Wunderlich2f301ab2013-05-16 13:00:28 +02008344 case NL80211_CHAN_WIDTH_20_NOHT:
8345 break;
8346 case NL80211_CHAN_WIDTH_20:
8347 case NL80211_CHAN_WIDTH_40:
Janusz.Dziedzic@tieto.comffc11992015-02-21 16:52:39 +01008348 if (!(rdev->wiphy.features & NL80211_FEATURE_HT_IBSS))
8349 return -EINVAL;
8350 break;
8351 case NL80211_CHAN_WIDTH_80:
8352 case NL80211_CHAN_WIDTH_80P80:
8353 case NL80211_CHAN_WIDTH_160:
8354 if (!(rdev->wiphy.features & NL80211_FEATURE_HT_IBSS))
8355 return -EINVAL;
8356 if (!wiphy_ext_feature_isset(&rdev->wiphy,
8357 NL80211_EXT_FEATURE_VHT_IBSS))
8358 return -EINVAL;
8359 break;
Simon Wunderlich2f301ab2013-05-16 13:00:28 +02008360 default:
Johannes Bergdb9c64c2012-11-09 14:56:41 +01008361 return -EINVAL;
Simon Wunderlich2f301ab2013-05-16 13:00:28 +02008362 }
Johannes Bergdb9c64c2012-11-09 14:56:41 +01008363
Johannes Berg04a773a2009-04-19 21:24:32 +02008364 ibss.channel_fixed = !!info->attrs[NL80211_ATTR_FREQ_FIXED];
Johannes Bergfffd0932009-07-08 14:22:54 +02008365 ibss.privacy = !!info->attrs[NL80211_ATTR_PRIVACY];
Johannes Berg04a773a2009-04-19 21:24:32 +02008366
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03008367 if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) {
8368 u8 *rates =
8369 nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
8370 int n_rates =
8371 nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
8372 struct ieee80211_supported_band *sband =
Johannes Berg683b6d32012-11-08 21:25:48 +01008373 wiphy->bands[ibss.chandef.chan->band];
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03008374
Johannes Berg34850ab2011-07-18 18:08:35 +02008375 err = ieee80211_get_ratemask(sband, rates, n_rates,
8376 &ibss.basic_rates);
8377 if (err)
8378 return err;
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03008379 }
Felix Fietkaudd5b4cc2010-11-22 20:58:24 +01008380
Simon Wunderlich803768f2013-06-28 10:39:58 +02008381 if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
8382 memcpy(&ibss.ht_capa_mask,
8383 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]),
8384 sizeof(ibss.ht_capa_mask));
8385
8386 if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) {
8387 if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
8388 return -EINVAL;
8389 memcpy(&ibss.ht_capa,
8390 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]),
8391 sizeof(ibss.ht_capa));
8392 }
8393
Felix Fietkaudd5b4cc2010-11-22 20:58:24 +01008394 if (info->attrs[NL80211_ATTR_MCAST_RATE] &&
8395 !nl80211_parse_mcast_rate(rdev, ibss.mcast_rate,
8396 nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE])))
8397 return -EINVAL;
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03008398
Johannes Berg4c476992010-10-04 21:36:35 +02008399 if (ibss.privacy && info->attrs[NL80211_ATTR_KEYS]) {
Sujith Manoharande7044e2012-10-18 10:19:28 +05308400 bool no_ht = false;
8401
Johannes Berg4c476992010-10-04 21:36:35 +02008402 connkeys = nl80211_parse_connkeys(rdev,
Sujith Manoharande7044e2012-10-18 10:19:28 +05308403 info->attrs[NL80211_ATTR_KEYS],
8404 &no_ht);
Johannes Berg4c476992010-10-04 21:36:35 +02008405 if (IS_ERR(connkeys))
8406 return PTR_ERR(connkeys);
Sujith Manoharande7044e2012-10-18 10:19:28 +05308407
Johannes Berg3d9d1d62012-11-08 23:14:50 +01008408 if ((ibss.chandef.width != NL80211_CHAN_WIDTH_20_NOHT) &&
8409 no_ht) {
Ola Olsson5e950a72016-02-11 01:00:22 +01008410 kzfree(connkeys);
Sujith Manoharande7044e2012-10-18 10:19:28 +05308411 return -EINVAL;
8412 }
Johannes Berg4c476992010-10-04 21:36:35 +02008413 }
Johannes Berg04a773a2009-04-19 21:24:32 +02008414
Antonio Quartulli267335d2012-01-31 20:25:47 +01008415 ibss.control_port =
8416 nla_get_flag(info->attrs[NL80211_ATTR_CONTROL_PORT]);
8417
Simon Wunderlich5336fa82013-10-07 18:41:05 +02008418 ibss.userspace_handles_dfs =
8419 nla_get_flag(info->attrs[NL80211_ATTR_HANDLE_DFS]);
8420
Johannes Berg4c476992010-10-04 21:36:35 +02008421 err = cfg80211_join_ibss(rdev, dev, &ibss, connkeys);
Johannes Bergfffd0932009-07-08 14:22:54 +02008422 if (err)
Johannes Bergb47f6102014-09-10 13:39:54 +03008423 kzfree(connkeys);
Johannes Berg04a773a2009-04-19 21:24:32 +02008424 return err;
8425}
8426
8427static int nl80211_leave_ibss(struct sk_buff *skb, struct genl_info *info)
8428{
Johannes Berg4c476992010-10-04 21:36:35 +02008429 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8430 struct net_device *dev = info->user_ptr[1];
Johannes Berg04a773a2009-04-19 21:24:32 +02008431
Johannes Berg4c476992010-10-04 21:36:35 +02008432 if (!rdev->ops->leave_ibss)
8433 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02008434
Johannes Berg4c476992010-10-04 21:36:35 +02008435 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC)
8436 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02008437
Johannes Berg4c476992010-10-04 21:36:35 +02008438 return cfg80211_leave_ibss(rdev, dev, false);
Johannes Berg04a773a2009-04-19 21:24:32 +02008439}
8440
Antonio Quartullif4e583c2012-11-02 13:27:48 +01008441static int nl80211_set_mcast_rate(struct sk_buff *skb, struct genl_info *info)
8442{
8443 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8444 struct net_device *dev = info->user_ptr[1];
Johannes Berg57fbcce2016-04-12 15:56:15 +02008445 int mcast_rate[NUM_NL80211_BANDS];
Antonio Quartullif4e583c2012-11-02 13:27:48 +01008446 u32 nla_rate;
8447 int err;
8448
8449 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC &&
Bertold Van den Bergh876dc932015-08-05 16:02:21 +02008450 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT &&
8451 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_OCB)
Antonio Quartullif4e583c2012-11-02 13:27:48 +01008452 return -EOPNOTSUPP;
8453
8454 if (!rdev->ops->set_mcast_rate)
8455 return -EOPNOTSUPP;
8456
8457 memset(mcast_rate, 0, sizeof(mcast_rate));
8458
8459 if (!info->attrs[NL80211_ATTR_MCAST_RATE])
8460 return -EINVAL;
8461
8462 nla_rate = nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]);
8463 if (!nl80211_parse_mcast_rate(rdev, mcast_rate, nla_rate))
8464 return -EINVAL;
8465
Ilan Peera1056b12015-10-22 22:27:46 +03008466 err = rdev_set_mcast_rate(rdev, dev, mcast_rate);
Antonio Quartullif4e583c2012-11-02 13:27:48 +01008467
8468 return err;
8469}
8470
Johannes Bergad7e7182013-11-13 13:37:47 +01008471static struct sk_buff *
8472__cfg80211_alloc_vendor_skb(struct cfg80211_registered_device *rdev,
Ahmad Kholaif6c09e792015-02-26 15:26:53 +02008473 struct wireless_dev *wdev, int approxlen,
8474 u32 portid, u32 seq, enum nl80211_commands cmd,
Johannes Berg567ffc32013-12-18 14:43:31 +01008475 enum nl80211_attrs attr,
8476 const struct nl80211_vendor_cmd_info *info,
8477 gfp_t gfp)
Johannes Bergad7e7182013-11-13 13:37:47 +01008478{
8479 struct sk_buff *skb;
8480 void *hdr;
8481 struct nlattr *data;
8482
8483 skb = nlmsg_new(approxlen + 100, gfp);
8484 if (!skb)
8485 return NULL;
8486
8487 hdr = nl80211hdr_put(skb, portid, seq, 0, cmd);
8488 if (!hdr) {
8489 kfree_skb(skb);
8490 return NULL;
8491 }
8492
8493 if (nla_put_u32(skb, NL80211_ATTR_WIPHY, rdev->wiphy_idx))
8494 goto nla_put_failure;
Johannes Berg567ffc32013-12-18 14:43:31 +01008495
8496 if (info) {
8497 if (nla_put_u32(skb, NL80211_ATTR_VENDOR_ID,
8498 info->vendor_id))
8499 goto nla_put_failure;
8500 if (nla_put_u32(skb, NL80211_ATTR_VENDOR_SUBCMD,
8501 info->subcmd))
8502 goto nla_put_failure;
8503 }
8504
Ahmad Kholaif6c09e792015-02-26 15:26:53 +02008505 if (wdev) {
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02008506 if (nla_put_u64_64bit(skb, NL80211_ATTR_WDEV,
8507 wdev_id(wdev), NL80211_ATTR_PAD))
Ahmad Kholaif6c09e792015-02-26 15:26:53 +02008508 goto nla_put_failure;
8509 if (wdev->netdev &&
8510 nla_put_u32(skb, NL80211_ATTR_IFINDEX,
8511 wdev->netdev->ifindex))
8512 goto nla_put_failure;
8513 }
8514
Johannes Bergad7e7182013-11-13 13:37:47 +01008515 data = nla_nest_start(skb, attr);
Johannes Berg76e1fb42016-09-14 09:55:57 +02008516 if (!data)
8517 goto nla_put_failure;
Johannes Bergad7e7182013-11-13 13:37:47 +01008518
8519 ((void **)skb->cb)[0] = rdev;
8520 ((void **)skb->cb)[1] = hdr;
8521 ((void **)skb->cb)[2] = data;
8522
8523 return skb;
8524
8525 nla_put_failure:
8526 kfree_skb(skb);
8527 return NULL;
8528}
Antonio Quartullif4e583c2012-11-02 13:27:48 +01008529
Johannes Berge03ad6e2014-01-01 17:22:30 +01008530struct sk_buff *__cfg80211_alloc_event_skb(struct wiphy *wiphy,
Ahmad Kholaif6c09e792015-02-26 15:26:53 +02008531 struct wireless_dev *wdev,
Johannes Berge03ad6e2014-01-01 17:22:30 +01008532 enum nl80211_commands cmd,
8533 enum nl80211_attrs attr,
8534 int vendor_event_idx,
8535 int approxlen, gfp_t gfp)
8536{
Zhao, Gangf26cbf42014-04-21 12:53:03 +08008537 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berge03ad6e2014-01-01 17:22:30 +01008538 const struct nl80211_vendor_cmd_info *info;
8539
8540 switch (cmd) {
8541 case NL80211_CMD_TESTMODE:
8542 if (WARN_ON(vendor_event_idx != -1))
8543 return NULL;
8544 info = NULL;
8545 break;
8546 case NL80211_CMD_VENDOR:
8547 if (WARN_ON(vendor_event_idx < 0 ||
8548 vendor_event_idx >= wiphy->n_vendor_events))
8549 return NULL;
8550 info = &wiphy->vendor_events[vendor_event_idx];
8551 break;
8552 default:
8553 WARN_ON(1);
8554 return NULL;
8555 }
8556
Ahmad Kholaif6c09e792015-02-26 15:26:53 +02008557 return __cfg80211_alloc_vendor_skb(rdev, wdev, approxlen, 0, 0,
Johannes Berge03ad6e2014-01-01 17:22:30 +01008558 cmd, attr, info, gfp);
8559}
8560EXPORT_SYMBOL(__cfg80211_alloc_event_skb);
8561
8562void __cfg80211_send_event_skb(struct sk_buff *skb, gfp_t gfp)
8563{
8564 struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0];
8565 void *hdr = ((void **)skb->cb)[1];
8566 struct nlattr *data = ((void **)skb->cb)[2];
8567 enum nl80211_multicast_groups mcgrp = NL80211_MCGRP_TESTMODE;
8568
Johannes Bergbd8c78e2014-07-30 14:55:26 +02008569 /* clear CB data for netlink core to own from now on */
8570 memset(skb->cb, 0, sizeof(skb->cb));
8571
Johannes Berge03ad6e2014-01-01 17:22:30 +01008572 nla_nest_end(skb, data);
8573 genlmsg_end(skb, hdr);
8574
8575 if (data->nla_type == NL80211_ATTR_VENDOR_DATA)
8576 mcgrp = NL80211_MCGRP_VENDOR;
8577
8578 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), skb, 0,
8579 mcgrp, gfp);
8580}
8581EXPORT_SYMBOL(__cfg80211_send_event_skb);
8582
Johannes Bergaff89a92009-07-01 21:26:51 +02008583#ifdef CONFIG_NL80211_TESTMODE
Johannes Bergaff89a92009-07-01 21:26:51 +02008584static int nl80211_testmode_do(struct sk_buff *skb, struct genl_info *info)
8585{
Johannes Berg4c476992010-10-04 21:36:35 +02008586 struct cfg80211_registered_device *rdev = info->user_ptr[0];
David Spinadelfc73f112013-07-31 18:04:15 +03008587 struct wireless_dev *wdev =
8588 __cfg80211_wdev_from_attrs(genl_info_net(info), info->attrs);
Johannes Bergaff89a92009-07-01 21:26:51 +02008589 int err;
8590
David Spinadelfc73f112013-07-31 18:04:15 +03008591 if (!rdev->ops->testmode_cmd)
8592 return -EOPNOTSUPP;
8593
8594 if (IS_ERR(wdev)) {
8595 err = PTR_ERR(wdev);
8596 if (err != -EINVAL)
8597 return err;
8598 wdev = NULL;
8599 } else if (wdev->wiphy != &rdev->wiphy) {
8600 return -EINVAL;
8601 }
8602
Johannes Bergaff89a92009-07-01 21:26:51 +02008603 if (!info->attrs[NL80211_ATTR_TESTDATA])
8604 return -EINVAL;
8605
Johannes Bergad7e7182013-11-13 13:37:47 +01008606 rdev->cur_cmd_info = info;
David Spinadelfc73f112013-07-31 18:04:15 +03008607 err = rdev_testmode_cmd(rdev, wdev,
Johannes Bergaff89a92009-07-01 21:26:51 +02008608 nla_data(info->attrs[NL80211_ATTR_TESTDATA]),
8609 nla_len(info->attrs[NL80211_ATTR_TESTDATA]));
Johannes Bergad7e7182013-11-13 13:37:47 +01008610 rdev->cur_cmd_info = NULL;
Johannes Bergaff89a92009-07-01 21:26:51 +02008611
Johannes Bergaff89a92009-07-01 21:26:51 +02008612 return err;
8613}
8614
Wey-Yi Guy71063f02011-05-20 09:05:54 -07008615static int nl80211_testmode_dump(struct sk_buff *skb,
8616 struct netlink_callback *cb)
8617{
Johannes Berg00918d32011-12-13 17:22:05 +01008618 struct cfg80211_registered_device *rdev;
Wey-Yi Guy71063f02011-05-20 09:05:54 -07008619 int err;
8620 long phy_idx;
8621 void *data = NULL;
8622 int data_len = 0;
8623
Johannes Berg5fe231e2013-05-08 21:45:15 +02008624 rtnl_lock();
8625
Wey-Yi Guy71063f02011-05-20 09:05:54 -07008626 if (cb->args[0]) {
8627 /*
8628 * 0 is a valid index, but not valid for args[0],
8629 * so we need to offset by 1.
8630 */
8631 phy_idx = cb->args[0] - 1;
Luca Coelhoa4956dc2017-02-07 22:13:56 +02008632
8633 rdev = cfg80211_rdev_by_wiphy_idx(phy_idx);
8634 if (!rdev) {
8635 err = -ENOENT;
8636 goto out_err;
8637 }
Wey-Yi Guy71063f02011-05-20 09:05:54 -07008638 } else {
Johannes Bergc90c39d2016-10-24 14:40:01 +02008639 struct nlattr **attrbuf = genl_family_attrbuf(&nl80211_fam);
8640
Wey-Yi Guy71063f02011-05-20 09:05:54 -07008641 err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize,
Johannes Bergc90c39d2016-10-24 14:40:01 +02008642 attrbuf, nl80211_fam.maxattr, nl80211_policy);
Wey-Yi Guy71063f02011-05-20 09:05:54 -07008643 if (err)
Johannes Berg5fe231e2013-05-08 21:45:15 +02008644 goto out_err;
Johannes Berg00918d32011-12-13 17:22:05 +01008645
Johannes Bergc90c39d2016-10-24 14:40:01 +02008646 rdev = __cfg80211_rdev_from_attrs(sock_net(skb->sk), attrbuf);
Johannes Berg2bd7e352012-06-15 14:23:16 +02008647 if (IS_ERR(rdev)) {
Johannes Berg5fe231e2013-05-08 21:45:15 +02008648 err = PTR_ERR(rdev);
8649 goto out_err;
Johannes Berg00918d32011-12-13 17:22:05 +01008650 }
Johannes Berg2bd7e352012-06-15 14:23:16 +02008651 phy_idx = rdev->wiphy_idx;
Johannes Berg2bd7e352012-06-15 14:23:16 +02008652
Johannes Bergc90c39d2016-10-24 14:40:01 +02008653 if (attrbuf[NL80211_ATTR_TESTDATA])
8654 cb->args[1] = (long)attrbuf[NL80211_ATTR_TESTDATA];
Wey-Yi Guy71063f02011-05-20 09:05:54 -07008655 }
8656
8657 if (cb->args[1]) {
8658 data = nla_data((void *)cb->args[1]);
8659 data_len = nla_len((void *)cb->args[1]);
8660 }
8661
Johannes Berg00918d32011-12-13 17:22:05 +01008662 if (!rdev->ops->testmode_dump) {
Wey-Yi Guy71063f02011-05-20 09:05:54 -07008663 err = -EOPNOTSUPP;
8664 goto out_err;
8665 }
8666
8667 while (1) {
Eric W. Biederman15e47302012-09-07 20:12:54 +00008668 void *hdr = nl80211hdr_put(skb, NETLINK_CB(cb->skb).portid,
Wey-Yi Guy71063f02011-05-20 09:05:54 -07008669 cb->nlh->nlmsg_seq, NLM_F_MULTI,
8670 NL80211_CMD_TESTMODE);
8671 struct nlattr *tmdata;
8672
Dan Carpentercb35fba2013-08-14 14:50:01 +03008673 if (!hdr)
8674 break;
8675
David S. Miller9360ffd2012-03-29 04:41:26 -04008676 if (nla_put_u32(skb, NL80211_ATTR_WIPHY, phy_idx)) {
Wey-Yi Guy71063f02011-05-20 09:05:54 -07008677 genlmsg_cancel(skb, hdr);
8678 break;
8679 }
8680
8681 tmdata = nla_nest_start(skb, NL80211_ATTR_TESTDATA);
8682 if (!tmdata) {
8683 genlmsg_cancel(skb, hdr);
8684 break;
8685 }
Hila Gonene35e4d22012-06-27 17:19:42 +03008686 err = rdev_testmode_dump(rdev, skb, cb, data, data_len);
Wey-Yi Guy71063f02011-05-20 09:05:54 -07008687 nla_nest_end(skb, tmdata);
8688
8689 if (err == -ENOBUFS || err == -ENOENT) {
8690 genlmsg_cancel(skb, hdr);
8691 break;
8692 } else if (err) {
8693 genlmsg_cancel(skb, hdr);
8694 goto out_err;
8695 }
8696
8697 genlmsg_end(skb, hdr);
8698 }
8699
8700 err = skb->len;
8701 /* see above */
8702 cb->args[0] = phy_idx + 1;
8703 out_err:
Johannes Berg5fe231e2013-05-08 21:45:15 +02008704 rtnl_unlock();
Wey-Yi Guy71063f02011-05-20 09:05:54 -07008705 return err;
8706}
Johannes Bergaff89a92009-07-01 21:26:51 +02008707#endif
8708
Samuel Ortizb23aa672009-07-01 21:26:54 +02008709static int nl80211_connect(struct sk_buff *skb, struct genl_info *info)
8710{
Johannes Berg4c476992010-10-04 21:36:35 +02008711 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8712 struct net_device *dev = info->user_ptr[1];
Samuel Ortizb23aa672009-07-01 21:26:54 +02008713 struct cfg80211_connect_params connect;
8714 struct wiphy *wiphy;
Johannes Bergfffd0932009-07-08 14:22:54 +02008715 struct cfg80211_cached_keys *connkeys = NULL;
Samuel Ortizb23aa672009-07-01 21:26:54 +02008716 int err;
8717
8718 memset(&connect, 0, sizeof(connect));
8719
8720 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
8721 return -EINVAL;
8722
8723 if (!info->attrs[NL80211_ATTR_SSID] ||
8724 !nla_len(info->attrs[NL80211_ATTR_SSID]))
8725 return -EINVAL;
8726
8727 if (info->attrs[NL80211_ATTR_AUTH_TYPE]) {
8728 connect.auth_type =
8729 nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]);
Jouni Malinene39e5b52012-09-30 19:29:39 +03008730 if (!nl80211_valid_auth_type(rdev, connect.auth_type,
8731 NL80211_CMD_CONNECT))
Samuel Ortizb23aa672009-07-01 21:26:54 +02008732 return -EINVAL;
8733 } else
8734 connect.auth_type = NL80211_AUTHTYPE_AUTOMATIC;
8735
8736 connect.privacy = info->attrs[NL80211_ATTR_PRIVACY];
8737
Johannes Bergc0692b82010-08-27 14:26:53 +03008738 err = nl80211_crypto_settings(rdev, info, &connect.crypto,
Johannes Berg3dc27d22009-07-02 21:36:37 +02008739 NL80211_MAX_NR_CIPHER_SUITES);
Samuel Ortizb23aa672009-07-01 21:26:54 +02008740 if (err)
8741 return err;
Samuel Ortizb23aa672009-07-01 21:26:54 +02008742
Johannes Berg074ac8d2010-09-16 14:58:22 +02008743 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02008744 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
8745 return -EOPNOTSUPP;
Samuel Ortizb23aa672009-07-01 21:26:54 +02008746
Johannes Berg79c97e92009-07-07 03:56:12 +02008747 wiphy = &rdev->wiphy;
Samuel Ortizb23aa672009-07-01 21:26:54 +02008748
Bala Shanmugam4486ea92012-03-07 17:27:12 +05308749 connect.bg_scan_period = -1;
8750 if (info->attrs[NL80211_ATTR_BG_SCAN_PERIOD] &&
8751 (wiphy->flags & WIPHY_FLAG_SUPPORTS_FW_ROAM)) {
8752 connect.bg_scan_period =
8753 nla_get_u16(info->attrs[NL80211_ATTR_BG_SCAN_PERIOD]);
8754 }
8755
Samuel Ortizb23aa672009-07-01 21:26:54 +02008756 if (info->attrs[NL80211_ATTR_MAC])
8757 connect.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen1df4a512014-01-15 00:00:47 +02008758 else if (info->attrs[NL80211_ATTR_MAC_HINT])
8759 connect.bssid_hint =
8760 nla_data(info->attrs[NL80211_ATTR_MAC_HINT]);
Samuel Ortizb23aa672009-07-01 21:26:54 +02008761 connect.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
8762 connect.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
8763
8764 if (info->attrs[NL80211_ATTR_IE]) {
8765 connect.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
8766 connect.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
8767 }
8768
Jouni Malinencee00a92013-01-15 17:15:57 +02008769 if (info->attrs[NL80211_ATTR_USE_MFP]) {
8770 connect.mfp = nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]);
8771 if (connect.mfp != NL80211_MFP_REQUIRED &&
8772 connect.mfp != NL80211_MFP_NO)
8773 return -EINVAL;
8774 } else {
8775 connect.mfp = NL80211_MFP_NO;
8776 }
8777
Jouni Malinenba6fbac2016-03-29 13:53:27 +03008778 if (info->attrs[NL80211_ATTR_PREV_BSSID])
8779 connect.prev_bssid =
8780 nla_data(info->attrs[NL80211_ATTR_PREV_BSSID]);
8781
Samuel Ortizb23aa672009-07-01 21:26:54 +02008782 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
Jouni Malinen664834d2014-01-15 00:01:44 +02008783 connect.channel = nl80211_get_valid_chan(
8784 wiphy, info->attrs[NL80211_ATTR_WIPHY_FREQ]);
8785 if (!connect.channel)
Johannes Berg4c476992010-10-04 21:36:35 +02008786 return -EINVAL;
Jouni Malinen1df4a512014-01-15 00:00:47 +02008787 } else if (info->attrs[NL80211_ATTR_WIPHY_FREQ_HINT]) {
Jouni Malinen664834d2014-01-15 00:01:44 +02008788 connect.channel_hint = nl80211_get_valid_chan(
8789 wiphy, info->attrs[NL80211_ATTR_WIPHY_FREQ_HINT]);
8790 if (!connect.channel_hint)
Jouni Malinen1df4a512014-01-15 00:00:47 +02008791 return -EINVAL;
Samuel Ortizb23aa672009-07-01 21:26:54 +02008792 }
8793
Johannes Bergfffd0932009-07-08 14:22:54 +02008794 if (connect.privacy && info->attrs[NL80211_ATTR_KEYS]) {
8795 connkeys = nl80211_parse_connkeys(rdev,
Sujith Manoharande7044e2012-10-18 10:19:28 +05308796 info->attrs[NL80211_ATTR_KEYS], NULL);
Johannes Berg4c476992010-10-04 21:36:35 +02008797 if (IS_ERR(connkeys))
8798 return PTR_ERR(connkeys);
Johannes Bergfffd0932009-07-08 14:22:54 +02008799 }
8800
Ben Greear7e7c8922011-11-18 11:31:59 -08008801 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT]))
8802 connect.flags |= ASSOC_REQ_DISABLE_HT;
8803
8804 if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
8805 memcpy(&connect.ht_capa_mask,
8806 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]),
8807 sizeof(connect.ht_capa_mask));
8808
8809 if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) {
Wei Yongjunb4e4f472012-09-02 21:41:04 +08008810 if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) {
Johannes Bergb47f6102014-09-10 13:39:54 +03008811 kzfree(connkeys);
Ben Greear7e7c8922011-11-18 11:31:59 -08008812 return -EINVAL;
Wei Yongjunb4e4f472012-09-02 21:41:04 +08008813 }
Ben Greear7e7c8922011-11-18 11:31:59 -08008814 memcpy(&connect.ht_capa,
8815 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]),
8816 sizeof(connect.ht_capa));
8817 }
8818
Johannes Bergee2aca32013-02-21 17:36:01 +01008819 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_VHT]))
8820 connect.flags |= ASSOC_REQ_DISABLE_VHT;
8821
8822 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK])
8823 memcpy(&connect.vht_capa_mask,
8824 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]),
8825 sizeof(connect.vht_capa_mask));
8826
8827 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) {
8828 if (!info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) {
Johannes Bergb47f6102014-09-10 13:39:54 +03008829 kzfree(connkeys);
Johannes Bergee2aca32013-02-21 17:36:01 +01008830 return -EINVAL;
8831 }
8832 memcpy(&connect.vht_capa,
8833 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]),
8834 sizeof(connect.vht_capa));
8835 }
8836
Assaf Kraussbab5ab72014-09-03 15:25:01 +03008837 if (nla_get_flag(info->attrs[NL80211_ATTR_USE_RRM])) {
Beni Lev0c9ca112016-02-17 20:30:00 +02008838 if (!((rdev->wiphy.features &
8839 NL80211_FEATURE_DS_PARAM_SET_IE_IN_PROBES) &&
8840 (rdev->wiphy.features & NL80211_FEATURE_QUIET)) &&
8841 !wiphy_ext_feature_isset(&rdev->wiphy,
8842 NL80211_EXT_FEATURE_RRM)) {
Ola Olsson707554b2015-12-11 21:04:52 +01008843 kzfree(connkeys);
Assaf Kraussbab5ab72014-09-03 15:25:01 +03008844 return -EINVAL;
Ola Olsson707554b2015-12-11 21:04:52 +01008845 }
Assaf Kraussbab5ab72014-09-03 15:25:01 +03008846 connect.flags |= ASSOC_REQ_USE_RRM;
8847 }
8848
Lior David34d50512016-01-28 10:58:25 +02008849 connect.pbss = nla_get_flag(info->attrs[NL80211_ATTR_PBSS]);
Johannes Berg57fbcce2016-04-12 15:56:15 +02008850 if (connect.pbss && !rdev->wiphy.bands[NL80211_BAND_60GHZ]) {
Lior David34d50512016-01-28 10:58:25 +02008851 kzfree(connkeys);
8852 return -EOPNOTSUPP;
8853 }
8854
Arend van Spriel38de03d2016-03-02 20:37:18 +01008855 if (info->attrs[NL80211_ATTR_BSS_SELECT]) {
8856 /* bss selection makes no sense if bssid is set */
8857 if (connect.bssid) {
8858 kzfree(connkeys);
8859 return -EINVAL;
8860 }
8861
8862 err = parse_bss_select(info->attrs[NL80211_ATTR_BSS_SELECT],
8863 wiphy, &connect.bss_select);
8864 if (err) {
8865 kzfree(connkeys);
8866 return err;
8867 }
8868 }
8869
Johannes Berg83739b02013-05-15 17:44:01 +02008870 wdev_lock(dev->ieee80211_ptr);
Andrzej Zaborowskibd2522b2017-01-06 16:33:43 -05008871
Jouni Malinen4ce2bd92016-03-29 13:53:28 +03008872 err = cfg80211_connect(rdev, dev, &connect, connkeys,
8873 connect.prev_bssid);
Johannes Bergfffd0932009-07-08 14:22:54 +02008874 if (err)
Johannes Bergb47f6102014-09-10 13:39:54 +03008875 kzfree(connkeys);
Andrzej Zaborowskibd2522b2017-01-06 16:33:43 -05008876
8877 if (!err && info->attrs[NL80211_ATTR_SOCKET_OWNER]) {
8878 dev->ieee80211_ptr->conn_owner_nlportid = info->snd_portid;
8879 if (connect.bssid)
8880 memcpy(dev->ieee80211_ptr->disconnect_bssid,
8881 connect.bssid, ETH_ALEN);
8882 else
8883 memset(dev->ieee80211_ptr->disconnect_bssid,
8884 0, ETH_ALEN);
8885 }
8886
8887 wdev_unlock(dev->ieee80211_ptr);
8888
Samuel Ortizb23aa672009-07-01 21:26:54 +02008889 return err;
8890}
8891
vamsi krishna088e8df2016-10-27 16:51:11 +03008892static int nl80211_update_connect_params(struct sk_buff *skb,
8893 struct genl_info *info)
8894{
8895 struct cfg80211_connect_params connect = {};
8896 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8897 struct net_device *dev = info->user_ptr[1];
8898 struct wireless_dev *wdev = dev->ieee80211_ptr;
8899 u32 changed = 0;
8900 int ret;
8901
8902 if (!rdev->ops->update_connect_params)
8903 return -EOPNOTSUPP;
8904
8905 if (info->attrs[NL80211_ATTR_IE]) {
8906 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
8907 return -EINVAL;
8908 connect.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
8909 connect.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
8910 changed |= UPDATE_ASSOC_IES;
8911 }
8912
8913 wdev_lock(dev->ieee80211_ptr);
8914 if (!wdev->current_bss)
8915 ret = -ENOLINK;
8916 else
8917 ret = rdev_update_connect_params(rdev, dev, &connect, changed);
8918 wdev_unlock(dev->ieee80211_ptr);
8919
8920 return ret;
8921}
8922
Samuel Ortizb23aa672009-07-01 21:26:54 +02008923static int nl80211_disconnect(struct sk_buff *skb, struct genl_info *info)
8924{
Johannes Berg4c476992010-10-04 21:36:35 +02008925 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8926 struct net_device *dev = info->user_ptr[1];
Samuel Ortizb23aa672009-07-01 21:26:54 +02008927 u16 reason;
Johannes Berg83739b02013-05-15 17:44:01 +02008928 int ret;
Samuel Ortizb23aa672009-07-01 21:26:54 +02008929
8930 if (!info->attrs[NL80211_ATTR_REASON_CODE])
8931 reason = WLAN_REASON_DEAUTH_LEAVING;
8932 else
8933 reason = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
8934
8935 if (reason == 0)
8936 return -EINVAL;
8937
Johannes Berg074ac8d2010-09-16 14:58:22 +02008938 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02008939 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
8940 return -EOPNOTSUPP;
Samuel Ortizb23aa672009-07-01 21:26:54 +02008941
Johannes Berg83739b02013-05-15 17:44:01 +02008942 wdev_lock(dev->ieee80211_ptr);
8943 ret = cfg80211_disconnect(rdev, dev, reason, true);
8944 wdev_unlock(dev->ieee80211_ptr);
8945 return ret;
Samuel Ortizb23aa672009-07-01 21:26:54 +02008946}
8947
Johannes Berg463d0182009-07-14 00:33:35 +02008948static int nl80211_wiphy_netns(struct sk_buff *skb, struct genl_info *info)
8949{
Johannes Berg4c476992010-10-04 21:36:35 +02008950 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg463d0182009-07-14 00:33:35 +02008951 struct net *net;
8952 int err;
Johannes Berg463d0182009-07-14 00:33:35 +02008953
Vadim Kochan4b681c82015-01-12 16:34:05 +02008954 if (info->attrs[NL80211_ATTR_PID]) {
8955 u32 pid = nla_get_u32(info->attrs[NL80211_ATTR_PID]);
8956
8957 net = get_net_ns_by_pid(pid);
8958 } else if (info->attrs[NL80211_ATTR_NETNS_FD]) {
8959 u32 fd = nla_get_u32(info->attrs[NL80211_ATTR_NETNS_FD]);
8960
8961 net = get_net_ns_by_fd(fd);
8962 } else {
Johannes Berg463d0182009-07-14 00:33:35 +02008963 return -EINVAL;
Vadim Kochan4b681c82015-01-12 16:34:05 +02008964 }
Johannes Berg463d0182009-07-14 00:33:35 +02008965
Johannes Berg4c476992010-10-04 21:36:35 +02008966 if (IS_ERR(net))
8967 return PTR_ERR(net);
Johannes Berg463d0182009-07-14 00:33:35 +02008968
8969 err = 0;
8970
8971 /* check if anything to do */
Johannes Berg4c476992010-10-04 21:36:35 +02008972 if (!net_eq(wiphy_net(&rdev->wiphy), net))
8973 err = cfg80211_switch_netns(rdev, net);
Johannes Berg463d0182009-07-14 00:33:35 +02008974
Johannes Berg463d0182009-07-14 00:33:35 +02008975 put_net(net);
Johannes Berg463d0182009-07-14 00:33:35 +02008976 return err;
8977}
8978
Samuel Ortiz67fbb162009-11-24 23:59:15 +01008979static int nl80211_setdel_pmksa(struct sk_buff *skb, struct genl_info *info)
8980{
Johannes Berg4c476992010-10-04 21:36:35 +02008981 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Samuel Ortiz67fbb162009-11-24 23:59:15 +01008982 int (*rdev_ops)(struct wiphy *wiphy, struct net_device *dev,
8983 struct cfg80211_pmksa *pmksa) = NULL;
Johannes Berg4c476992010-10-04 21:36:35 +02008984 struct net_device *dev = info->user_ptr[1];
Samuel Ortiz67fbb162009-11-24 23:59:15 +01008985 struct cfg80211_pmksa pmksa;
8986
8987 memset(&pmksa, 0, sizeof(struct cfg80211_pmksa));
8988
8989 if (!info->attrs[NL80211_ATTR_MAC])
8990 return -EINVAL;
8991
8992 if (!info->attrs[NL80211_ATTR_PMKID])
8993 return -EINVAL;
8994
Samuel Ortiz67fbb162009-11-24 23:59:15 +01008995 pmksa.pmkid = nla_data(info->attrs[NL80211_ATTR_PMKID]);
8996 pmksa.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
8997
Johannes Berg074ac8d2010-09-16 14:58:22 +02008998 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02008999 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
9000 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01009001
9002 switch (info->genlhdr->cmd) {
9003 case NL80211_CMD_SET_PMKSA:
9004 rdev_ops = rdev->ops->set_pmksa;
9005 break;
9006 case NL80211_CMD_DEL_PMKSA:
9007 rdev_ops = rdev->ops->del_pmksa;
9008 break;
9009 default:
9010 WARN_ON(1);
9011 break;
9012 }
9013
Johannes Berg4c476992010-10-04 21:36:35 +02009014 if (!rdev_ops)
9015 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01009016
Johannes Berg4c476992010-10-04 21:36:35 +02009017 return rdev_ops(&rdev->wiphy, dev, &pmksa);
Samuel Ortiz67fbb162009-11-24 23:59:15 +01009018}
9019
9020static int nl80211_flush_pmksa(struct sk_buff *skb, struct genl_info *info)
9021{
Johannes Berg4c476992010-10-04 21:36:35 +02009022 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9023 struct net_device *dev = info->user_ptr[1];
Samuel Ortiz67fbb162009-11-24 23:59:15 +01009024
Johannes Berg074ac8d2010-09-16 14:58:22 +02009025 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02009026 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
9027 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01009028
Johannes Berg4c476992010-10-04 21:36:35 +02009029 if (!rdev->ops->flush_pmksa)
9030 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01009031
Hila Gonene35e4d22012-06-27 17:19:42 +03009032 return rdev_flush_pmksa(rdev, dev);
Samuel Ortiz67fbb162009-11-24 23:59:15 +01009033}
9034
Arik Nemtsov109086c2011-09-28 14:12:50 +03009035static int nl80211_tdls_mgmt(struct sk_buff *skb, struct genl_info *info)
9036{
9037 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9038 struct net_device *dev = info->user_ptr[1];
9039 u8 action_code, dialog_token;
Sunil Dutt Undekaridf942e72014-02-20 16:22:09 +05309040 u32 peer_capability = 0;
Arik Nemtsov109086c2011-09-28 14:12:50 +03009041 u16 status_code;
9042 u8 *peer;
Arik Nemtsov31fa97c2014-06-11 17:18:21 +03009043 bool initiator;
Arik Nemtsov109086c2011-09-28 14:12:50 +03009044
9045 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) ||
9046 !rdev->ops->tdls_mgmt)
9047 return -EOPNOTSUPP;
9048
9049 if (!info->attrs[NL80211_ATTR_TDLS_ACTION] ||
9050 !info->attrs[NL80211_ATTR_STATUS_CODE] ||
9051 !info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN] ||
9052 !info->attrs[NL80211_ATTR_IE] ||
9053 !info->attrs[NL80211_ATTR_MAC])
9054 return -EINVAL;
9055
9056 peer = nla_data(info->attrs[NL80211_ATTR_MAC]);
9057 action_code = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_ACTION]);
9058 status_code = nla_get_u16(info->attrs[NL80211_ATTR_STATUS_CODE]);
9059 dialog_token = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN]);
Arik Nemtsov31fa97c2014-06-11 17:18:21 +03009060 initiator = nla_get_flag(info->attrs[NL80211_ATTR_TDLS_INITIATOR]);
Sunil Dutt Undekaridf942e72014-02-20 16:22:09 +05309061 if (info->attrs[NL80211_ATTR_TDLS_PEER_CAPABILITY])
9062 peer_capability =
9063 nla_get_u32(info->attrs[NL80211_ATTR_TDLS_PEER_CAPABILITY]);
Arik Nemtsov109086c2011-09-28 14:12:50 +03009064
Hila Gonene35e4d22012-06-27 17:19:42 +03009065 return rdev_tdls_mgmt(rdev, dev, peer, action_code,
Sunil Dutt Undekaridf942e72014-02-20 16:22:09 +05309066 dialog_token, status_code, peer_capability,
Arik Nemtsov31fa97c2014-06-11 17:18:21 +03009067 initiator,
Hila Gonene35e4d22012-06-27 17:19:42 +03009068 nla_data(info->attrs[NL80211_ATTR_IE]),
9069 nla_len(info->attrs[NL80211_ATTR_IE]));
Arik Nemtsov109086c2011-09-28 14:12:50 +03009070}
9071
9072static int nl80211_tdls_oper(struct sk_buff *skb, struct genl_info *info)
9073{
9074 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9075 struct net_device *dev = info->user_ptr[1];
9076 enum nl80211_tdls_operation operation;
9077 u8 *peer;
9078
9079 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) ||
9080 !rdev->ops->tdls_oper)
9081 return -EOPNOTSUPP;
9082
9083 if (!info->attrs[NL80211_ATTR_TDLS_OPERATION] ||
9084 !info->attrs[NL80211_ATTR_MAC])
9085 return -EINVAL;
9086
9087 operation = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_OPERATION]);
9088 peer = nla_data(info->attrs[NL80211_ATTR_MAC]);
9089
Hila Gonene35e4d22012-06-27 17:19:42 +03009090 return rdev_tdls_oper(rdev, dev, peer, operation);
Arik Nemtsov109086c2011-09-28 14:12:50 +03009091}
9092
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009093static int nl80211_remain_on_channel(struct sk_buff *skb,
9094 struct genl_info *info)
9095{
Johannes Berg4c476992010-10-04 21:36:35 +02009096 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02009097 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg683b6d32012-11-08 21:25:48 +01009098 struct cfg80211_chan_def chandef;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009099 struct sk_buff *msg;
9100 void *hdr;
9101 u64 cookie;
Johannes Berg683b6d32012-11-08 21:25:48 +01009102 u32 duration;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009103 int err;
9104
9105 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] ||
9106 !info->attrs[NL80211_ATTR_DURATION])
9107 return -EINVAL;
9108
9109 duration = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]);
9110
Johannes Berg7c4ef712011-11-18 15:33:48 +01009111 if (!rdev->ops->remain_on_channel ||
9112 !(rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL))
Johannes Berg4c476992010-10-04 21:36:35 +02009113 return -EOPNOTSUPP;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009114
Johannes Bergebf348f2012-06-01 12:50:54 +02009115 /*
9116 * We should be on that channel for at least a minimum amount of
9117 * time (10ms) but no longer than the driver supports.
9118 */
9119 if (duration < NL80211_MIN_REMAIN_ON_CHANNEL_TIME ||
9120 duration > rdev->wiphy.max_remain_on_channel_duration)
9121 return -EINVAL;
9122
Johannes Berg683b6d32012-11-08 21:25:48 +01009123 err = nl80211_parse_chandef(rdev, info, &chandef);
9124 if (err)
9125 return err;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009126
9127 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02009128 if (!msg)
9129 return -ENOMEM;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009130
Eric W. Biederman15e47302012-09-07 20:12:54 +00009131 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009132 NL80211_CMD_REMAIN_ON_CHANNEL);
Dan Carpentercb35fba2013-08-14 14:50:01 +03009133 if (!hdr) {
9134 err = -ENOBUFS;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009135 goto free_msg;
9136 }
9137
Johannes Berg683b6d32012-11-08 21:25:48 +01009138 err = rdev_remain_on_channel(rdev, wdev, chandef.chan,
9139 duration, &cookie);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009140
9141 if (err)
9142 goto free_msg;
9143
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02009144 if (nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie,
9145 NL80211_ATTR_PAD))
David S. Miller9360ffd2012-03-29 04:41:26 -04009146 goto nla_put_failure;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009147
9148 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02009149
9150 return genlmsg_reply(msg, info);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009151
9152 nla_put_failure:
9153 err = -ENOBUFS;
9154 free_msg:
9155 nlmsg_free(msg);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009156 return err;
9157}
9158
9159static int nl80211_cancel_remain_on_channel(struct sk_buff *skb,
9160 struct genl_info *info)
9161{
Johannes Berg4c476992010-10-04 21:36:35 +02009162 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02009163 struct wireless_dev *wdev = info->user_ptr[1];
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009164 u64 cookie;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009165
9166 if (!info->attrs[NL80211_ATTR_COOKIE])
9167 return -EINVAL;
9168
Johannes Berg4c476992010-10-04 21:36:35 +02009169 if (!rdev->ops->cancel_remain_on_channel)
9170 return -EOPNOTSUPP;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009171
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009172 cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]);
9173
Hila Gonene35e4d22012-06-27 17:19:42 +03009174 return rdev_cancel_remain_on_channel(rdev, wdev, cookie);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009175}
9176
Jouni Malinen13ae75b2009-12-29 12:59:45 +02009177static int nl80211_set_tx_bitrate_mask(struct sk_buff *skb,
9178 struct genl_info *info)
9179{
Jouni Malinen13ae75b2009-12-29 12:59:45 +02009180 struct cfg80211_bitrate_mask mask;
Purushottam Kushwahaa7c7fbf2016-09-14 17:38:44 +05309181 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg4c476992010-10-04 21:36:35 +02009182 struct net_device *dev = info->user_ptr[1];
Purushottam Kushwahaa7c7fbf2016-09-14 17:38:44 +05309183 int err;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02009184
Johannes Berg4c476992010-10-04 21:36:35 +02009185 if (!rdev->ops->set_bitrate_mask)
9186 return -EOPNOTSUPP;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02009187
Purushottam Kushwahaa7c7fbf2016-09-14 17:38:44 +05309188 err = nl80211_parse_tx_bitrate_mask(info, &mask);
9189 if (err)
9190 return err;
Janusz Dziedzic78693032013-12-03 09:50:44 +01009191
Hila Gonene35e4d22012-06-27 17:19:42 +03009192 return rdev_set_bitrate_mask(rdev, dev, NULL, &mask);
Jouni Malinen13ae75b2009-12-29 12:59:45 +02009193}
9194
Johannes Berg2e161f72010-08-12 15:38:38 +02009195static int nl80211_register_mgmt(struct sk_buff *skb, struct genl_info *info)
Jouni Malinen026331c2010-02-15 12:53:10 +02009196{
Johannes Berg4c476992010-10-04 21:36:35 +02009197 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02009198 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg2e161f72010-08-12 15:38:38 +02009199 u16 frame_type = IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_ACTION;
Jouni Malinen026331c2010-02-15 12:53:10 +02009200
9201 if (!info->attrs[NL80211_ATTR_FRAME_MATCH])
9202 return -EINVAL;
9203
Johannes Berg2e161f72010-08-12 15:38:38 +02009204 if (info->attrs[NL80211_ATTR_FRAME_TYPE])
9205 frame_type = nla_get_u16(info->attrs[NL80211_ATTR_FRAME_TYPE]);
Jouni Malinen026331c2010-02-15 12:53:10 +02009206
Johannes Berg71bbc992012-06-15 15:30:18 +02009207 switch (wdev->iftype) {
9208 case NL80211_IFTYPE_STATION:
9209 case NL80211_IFTYPE_ADHOC:
9210 case NL80211_IFTYPE_P2P_CLIENT:
9211 case NL80211_IFTYPE_AP:
9212 case NL80211_IFTYPE_AP_VLAN:
9213 case NL80211_IFTYPE_MESH_POINT:
9214 case NL80211_IFTYPE_P2P_GO:
Johannes Berg98104fde2012-06-16 00:19:54 +02009215 case NL80211_IFTYPE_P2P_DEVICE:
Johannes Berg71bbc992012-06-15 15:30:18 +02009216 break;
Ayala Bekercb3b7d82016-09-20 17:31:13 +03009217 case NL80211_IFTYPE_NAN:
Johannes Berg71bbc992012-06-15 15:30:18 +02009218 default:
Johannes Berg4c476992010-10-04 21:36:35 +02009219 return -EOPNOTSUPP;
Johannes Berg71bbc992012-06-15 15:30:18 +02009220 }
Jouni Malinen026331c2010-02-15 12:53:10 +02009221
9222 /* not much point in registering if we can't reply */
Johannes Berg4c476992010-10-04 21:36:35 +02009223 if (!rdev->ops->mgmt_tx)
9224 return -EOPNOTSUPP;
Jouni Malinen026331c2010-02-15 12:53:10 +02009225
Eric W. Biederman15e47302012-09-07 20:12:54 +00009226 return cfg80211_mlme_register_mgmt(wdev, info->snd_portid, frame_type,
Jouni Malinen026331c2010-02-15 12:53:10 +02009227 nla_data(info->attrs[NL80211_ATTR_FRAME_MATCH]),
9228 nla_len(info->attrs[NL80211_ATTR_FRAME_MATCH]));
Jouni Malinen026331c2010-02-15 12:53:10 +02009229}
9230
Johannes Berg2e161f72010-08-12 15:38:38 +02009231static int nl80211_tx_mgmt(struct sk_buff *skb, struct genl_info *info)
Jouni Malinen026331c2010-02-15 12:53:10 +02009232{
Johannes Berg4c476992010-10-04 21:36:35 +02009233 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02009234 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg683b6d32012-11-08 21:25:48 +01009235 struct cfg80211_chan_def chandef;
Jouni Malinen026331c2010-02-15 12:53:10 +02009236 int err;
Johannes Bergd64d3732011-11-10 09:44:46 +01009237 void *hdr = NULL;
Jouni Malinen026331c2010-02-15 12:53:10 +02009238 u64 cookie;
Johannes Berge247bd902011-11-04 11:18:21 +01009239 struct sk_buff *msg = NULL;
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02009240 struct cfg80211_mgmt_tx_params params = {
9241 .dont_wait_for_ack =
9242 info->attrs[NL80211_ATTR_DONT_WAIT_FOR_ACK],
9243 };
Jouni Malinen026331c2010-02-15 12:53:10 +02009244
Johannes Berg683b6d32012-11-08 21:25:48 +01009245 if (!info->attrs[NL80211_ATTR_FRAME])
Jouni Malinen026331c2010-02-15 12:53:10 +02009246 return -EINVAL;
9247
Johannes Berg4c476992010-10-04 21:36:35 +02009248 if (!rdev->ops->mgmt_tx)
9249 return -EOPNOTSUPP;
Jouni Malinen026331c2010-02-15 12:53:10 +02009250
Johannes Berg71bbc992012-06-15 15:30:18 +02009251 switch (wdev->iftype) {
Antonio Quartulliea141b752013-06-11 14:20:03 +02009252 case NL80211_IFTYPE_P2P_DEVICE:
9253 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ])
9254 return -EINVAL;
Johannes Berg71bbc992012-06-15 15:30:18 +02009255 case NL80211_IFTYPE_STATION:
9256 case NL80211_IFTYPE_ADHOC:
9257 case NL80211_IFTYPE_P2P_CLIENT:
9258 case NL80211_IFTYPE_AP:
9259 case NL80211_IFTYPE_AP_VLAN:
9260 case NL80211_IFTYPE_MESH_POINT:
9261 case NL80211_IFTYPE_P2P_GO:
9262 break;
Ayala Bekercb3b7d82016-09-20 17:31:13 +03009263 case NL80211_IFTYPE_NAN:
Johannes Berg71bbc992012-06-15 15:30:18 +02009264 default:
Johannes Berg4c476992010-10-04 21:36:35 +02009265 return -EOPNOTSUPP;
Johannes Berg71bbc992012-06-15 15:30:18 +02009266 }
Jouni Malinen026331c2010-02-15 12:53:10 +02009267
Johannes Bergf7ca38d2010-11-25 10:02:29 +01009268 if (info->attrs[NL80211_ATTR_DURATION]) {
Johannes Berg7c4ef712011-11-18 15:33:48 +01009269 if (!(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX))
Johannes Bergf7ca38d2010-11-25 10:02:29 +01009270 return -EINVAL;
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02009271 params.wait = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]);
Johannes Bergebf348f2012-06-01 12:50:54 +02009272
9273 /*
9274 * We should wait on the channel for at least a minimum amount
9275 * of time (10ms) but no longer than the driver supports.
9276 */
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02009277 if (params.wait < NL80211_MIN_REMAIN_ON_CHANNEL_TIME ||
9278 params.wait > rdev->wiphy.max_remain_on_channel_duration)
Johannes Bergebf348f2012-06-01 12:50:54 +02009279 return -EINVAL;
Johannes Bergf7ca38d2010-11-25 10:02:29 +01009280 }
9281
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02009282 params.offchan = info->attrs[NL80211_ATTR_OFFCHANNEL_TX_OK];
Johannes Bergf7ca38d2010-11-25 10:02:29 +01009283
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02009284 if (params.offchan && !(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX))
Johannes Berg7c4ef712011-11-18 15:33:48 +01009285 return -EINVAL;
9286
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02009287 params.no_cck = nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]);
Rajkumar Manoharane9f935e2011-09-25 14:53:30 +05309288
Antonio Quartulliea141b752013-06-11 14:20:03 +02009289 /* get the channel if any has been specified, otherwise pass NULL to
9290 * the driver. The latter will use the current one
9291 */
9292 chandef.chan = NULL;
9293 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
9294 err = nl80211_parse_chandef(rdev, info, &chandef);
9295 if (err)
9296 return err;
9297 }
9298
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02009299 if (!chandef.chan && params.offchan)
Antonio Quartulliea141b752013-06-11 14:20:03 +02009300 return -EINVAL;
Jouni Malinen026331c2010-02-15 12:53:10 +02009301
Andrei Otcheretianski34d22ce2014-05-09 14:11:44 +03009302 params.buf = nla_data(info->attrs[NL80211_ATTR_FRAME]);
9303 params.len = nla_len(info->attrs[NL80211_ATTR_FRAME]);
9304
9305 if (info->attrs[NL80211_ATTR_CSA_C_OFFSETS_TX]) {
9306 int len = nla_len(info->attrs[NL80211_ATTR_CSA_C_OFFSETS_TX]);
9307 int i;
9308
9309 if (len % sizeof(u16))
9310 return -EINVAL;
9311
9312 params.n_csa_offsets = len / sizeof(u16);
9313 params.csa_offsets =
9314 nla_data(info->attrs[NL80211_ATTR_CSA_C_OFFSETS_TX]);
9315
9316 /* check that all the offsets fit the frame */
9317 for (i = 0; i < params.n_csa_offsets; i++) {
9318 if (params.csa_offsets[i] >= params.len)
9319 return -EINVAL;
9320 }
9321 }
9322
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02009323 if (!params.dont_wait_for_ack) {
Johannes Berge247bd902011-11-04 11:18:21 +01009324 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
9325 if (!msg)
9326 return -ENOMEM;
Jouni Malinen026331c2010-02-15 12:53:10 +02009327
Eric W. Biederman15e47302012-09-07 20:12:54 +00009328 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berge247bd902011-11-04 11:18:21 +01009329 NL80211_CMD_FRAME);
Dan Carpentercb35fba2013-08-14 14:50:01 +03009330 if (!hdr) {
9331 err = -ENOBUFS;
Johannes Berge247bd902011-11-04 11:18:21 +01009332 goto free_msg;
9333 }
Jouni Malinen026331c2010-02-15 12:53:10 +02009334 }
Johannes Berge247bd902011-11-04 11:18:21 +01009335
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02009336 params.chan = chandef.chan;
9337 err = cfg80211_mlme_mgmt_tx(rdev, wdev, &params, &cookie);
Jouni Malinen026331c2010-02-15 12:53:10 +02009338 if (err)
9339 goto free_msg;
9340
Johannes Berge247bd902011-11-04 11:18:21 +01009341 if (msg) {
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02009342 if (nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie,
9343 NL80211_ATTR_PAD))
David S. Miller9360ffd2012-03-29 04:41:26 -04009344 goto nla_put_failure;
Jouni Malinen026331c2010-02-15 12:53:10 +02009345
Johannes Berge247bd902011-11-04 11:18:21 +01009346 genlmsg_end(msg, hdr);
9347 return genlmsg_reply(msg, info);
9348 }
9349
9350 return 0;
Jouni Malinen026331c2010-02-15 12:53:10 +02009351
9352 nla_put_failure:
9353 err = -ENOBUFS;
9354 free_msg:
9355 nlmsg_free(msg);
Jouni Malinen026331c2010-02-15 12:53:10 +02009356 return err;
9357}
9358
Johannes Bergf7ca38d2010-11-25 10:02:29 +01009359static int nl80211_tx_mgmt_cancel_wait(struct sk_buff *skb, struct genl_info *info)
9360{
9361 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02009362 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Bergf7ca38d2010-11-25 10:02:29 +01009363 u64 cookie;
9364
9365 if (!info->attrs[NL80211_ATTR_COOKIE])
9366 return -EINVAL;
9367
9368 if (!rdev->ops->mgmt_tx_cancel_wait)
9369 return -EOPNOTSUPP;
9370
Johannes Berg71bbc992012-06-15 15:30:18 +02009371 switch (wdev->iftype) {
9372 case NL80211_IFTYPE_STATION:
9373 case NL80211_IFTYPE_ADHOC:
9374 case NL80211_IFTYPE_P2P_CLIENT:
9375 case NL80211_IFTYPE_AP:
9376 case NL80211_IFTYPE_AP_VLAN:
9377 case NL80211_IFTYPE_P2P_GO:
Johannes Berg98104fde2012-06-16 00:19:54 +02009378 case NL80211_IFTYPE_P2P_DEVICE:
Johannes Berg71bbc992012-06-15 15:30:18 +02009379 break;
Ayala Bekercb3b7d82016-09-20 17:31:13 +03009380 case NL80211_IFTYPE_NAN:
Johannes Berg71bbc992012-06-15 15:30:18 +02009381 default:
Johannes Bergf7ca38d2010-11-25 10:02:29 +01009382 return -EOPNOTSUPP;
Johannes Berg71bbc992012-06-15 15:30:18 +02009383 }
Johannes Bergf7ca38d2010-11-25 10:02:29 +01009384
9385 cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]);
9386
Hila Gonene35e4d22012-06-27 17:19:42 +03009387 return rdev_mgmt_tx_cancel_wait(rdev, wdev, cookie);
Johannes Bergf7ca38d2010-11-25 10:02:29 +01009388}
9389
Kalle Valoffb9eb32010-02-17 17:58:10 +02009390static int nl80211_set_power_save(struct sk_buff *skb, struct genl_info *info)
9391{
Johannes Berg4c476992010-10-04 21:36:35 +02009392 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Kalle Valoffb9eb32010-02-17 17:58:10 +02009393 struct wireless_dev *wdev;
Johannes Berg4c476992010-10-04 21:36:35 +02009394 struct net_device *dev = info->user_ptr[1];
Kalle Valoffb9eb32010-02-17 17:58:10 +02009395 u8 ps_state;
9396 bool state;
9397 int err;
9398
Johannes Berg4c476992010-10-04 21:36:35 +02009399 if (!info->attrs[NL80211_ATTR_PS_STATE])
9400 return -EINVAL;
Kalle Valoffb9eb32010-02-17 17:58:10 +02009401
9402 ps_state = nla_get_u32(info->attrs[NL80211_ATTR_PS_STATE]);
9403
Johannes Berg4c476992010-10-04 21:36:35 +02009404 if (ps_state != NL80211_PS_DISABLED && ps_state != NL80211_PS_ENABLED)
9405 return -EINVAL;
Kalle Valoffb9eb32010-02-17 17:58:10 +02009406
9407 wdev = dev->ieee80211_ptr;
9408
Johannes Berg4c476992010-10-04 21:36:35 +02009409 if (!rdev->ops->set_power_mgmt)
9410 return -EOPNOTSUPP;
Kalle Valoffb9eb32010-02-17 17:58:10 +02009411
9412 state = (ps_state == NL80211_PS_ENABLED) ? true : false;
9413
9414 if (state == wdev->ps)
Johannes Berg4c476992010-10-04 21:36:35 +02009415 return 0;
Kalle Valoffb9eb32010-02-17 17:58:10 +02009416
Hila Gonene35e4d22012-06-27 17:19:42 +03009417 err = rdev_set_power_mgmt(rdev, dev, state, wdev->ps_timeout);
Johannes Berg4c476992010-10-04 21:36:35 +02009418 if (!err)
9419 wdev->ps = state;
Kalle Valoffb9eb32010-02-17 17:58:10 +02009420 return err;
9421}
9422
9423static int nl80211_get_power_save(struct sk_buff *skb, struct genl_info *info)
9424{
Johannes Berg4c476992010-10-04 21:36:35 +02009425 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Kalle Valoffb9eb32010-02-17 17:58:10 +02009426 enum nl80211_ps_state ps_state;
9427 struct wireless_dev *wdev;
Johannes Berg4c476992010-10-04 21:36:35 +02009428 struct net_device *dev = info->user_ptr[1];
Kalle Valoffb9eb32010-02-17 17:58:10 +02009429 struct sk_buff *msg;
9430 void *hdr;
9431 int err;
9432
Kalle Valoffb9eb32010-02-17 17:58:10 +02009433 wdev = dev->ieee80211_ptr;
9434
Johannes Berg4c476992010-10-04 21:36:35 +02009435 if (!rdev->ops->set_power_mgmt)
9436 return -EOPNOTSUPP;
Kalle Valoffb9eb32010-02-17 17:58:10 +02009437
9438 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02009439 if (!msg)
9440 return -ENOMEM;
Kalle Valoffb9eb32010-02-17 17:58:10 +02009441
Eric W. Biederman15e47302012-09-07 20:12:54 +00009442 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Kalle Valoffb9eb32010-02-17 17:58:10 +02009443 NL80211_CMD_GET_POWER_SAVE);
9444 if (!hdr) {
Johannes Berg4c476992010-10-04 21:36:35 +02009445 err = -ENOBUFS;
Kalle Valoffb9eb32010-02-17 17:58:10 +02009446 goto free_msg;
9447 }
9448
9449 if (wdev->ps)
9450 ps_state = NL80211_PS_ENABLED;
9451 else
9452 ps_state = NL80211_PS_DISABLED;
9453
David S. Miller9360ffd2012-03-29 04:41:26 -04009454 if (nla_put_u32(msg, NL80211_ATTR_PS_STATE, ps_state))
9455 goto nla_put_failure;
Kalle Valoffb9eb32010-02-17 17:58:10 +02009456
9457 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02009458 return genlmsg_reply(msg, info);
Kalle Valoffb9eb32010-02-17 17:58:10 +02009459
Johannes Berg4c476992010-10-04 21:36:35 +02009460 nla_put_failure:
Kalle Valoffb9eb32010-02-17 17:58:10 +02009461 err = -ENOBUFS;
Johannes Berg4c476992010-10-04 21:36:35 +02009462 free_msg:
Kalle Valoffb9eb32010-02-17 17:58:10 +02009463 nlmsg_free(msg);
Kalle Valoffb9eb32010-02-17 17:58:10 +02009464 return err;
9465}
9466
Johannes Berg94e860f2014-01-20 23:58:15 +01009467static const struct nla_policy
9468nl80211_attr_cqm_policy[NL80211_ATTR_CQM_MAX + 1] = {
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02009469 [NL80211_ATTR_CQM_RSSI_THOLD] = { .type = NLA_U32 },
9470 [NL80211_ATTR_CQM_RSSI_HYST] = { .type = NLA_U32 },
9471 [NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT] = { .type = NLA_U32 },
Thomas Pedersen84f10702012-07-12 16:17:33 -07009472 [NL80211_ATTR_CQM_TXE_RATE] = { .type = NLA_U32 },
9473 [NL80211_ATTR_CQM_TXE_PKTS] = { .type = NLA_U32 },
9474 [NL80211_ATTR_CQM_TXE_INTVL] = { .type = NLA_U32 },
Andrzej Zaborowskibee427b2017-01-25 12:43:41 +01009475 [NL80211_ATTR_CQM_RSSI_LEVEL] = { .type = NLA_S32 },
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02009476};
9477
Thomas Pedersen84f10702012-07-12 16:17:33 -07009478static int nl80211_set_cqm_txe(struct genl_info *info,
Johannes Bergd9d8b012012-11-26 12:51:52 +01009479 u32 rate, u32 pkts, u32 intvl)
Thomas Pedersen84f10702012-07-12 16:17:33 -07009480{
9481 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Thomas Pedersen84f10702012-07-12 16:17:33 -07009482 struct net_device *dev = info->user_ptr[1];
Johannes Berg1da5fcc2013-08-06 14:10:48 +02009483 struct wireless_dev *wdev = dev->ieee80211_ptr;
Thomas Pedersen84f10702012-07-12 16:17:33 -07009484
Johannes Bergd9d8b012012-11-26 12:51:52 +01009485 if (rate > 100 || intvl > NL80211_CQM_TXE_MAX_INTVL)
Thomas Pedersen84f10702012-07-12 16:17:33 -07009486 return -EINVAL;
9487
Thomas Pedersen84f10702012-07-12 16:17:33 -07009488 if (!rdev->ops->set_cqm_txe_config)
9489 return -EOPNOTSUPP;
9490
9491 if (wdev->iftype != NL80211_IFTYPE_STATION &&
9492 wdev->iftype != NL80211_IFTYPE_P2P_CLIENT)
9493 return -EOPNOTSUPP;
9494
Hila Gonene35e4d22012-06-27 17:19:42 +03009495 return rdev_set_cqm_txe_config(rdev, dev, rate, pkts, intvl);
Thomas Pedersen84f10702012-07-12 16:17:33 -07009496}
9497
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02009498static int nl80211_set_cqm_rssi(struct genl_info *info,
9499 s32 threshold, u32 hysteresis)
9500{
Johannes Berg4c476992010-10-04 21:36:35 +02009501 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg4c476992010-10-04 21:36:35 +02009502 struct net_device *dev = info->user_ptr[1];
Johannes Berg1da5fcc2013-08-06 14:10:48 +02009503 struct wireless_dev *wdev = dev->ieee80211_ptr;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02009504
9505 if (threshold > 0)
9506 return -EINVAL;
9507
Johannes Berg1da5fcc2013-08-06 14:10:48 +02009508 /* disabling - hysteresis should also be zero then */
9509 if (threshold == 0)
9510 hysteresis = 0;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02009511
Johannes Berg4c476992010-10-04 21:36:35 +02009512 if (!rdev->ops->set_cqm_rssi_config)
9513 return -EOPNOTSUPP;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02009514
Johannes Berg074ac8d2010-09-16 14:58:22 +02009515 if (wdev->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02009516 wdev->iftype != NL80211_IFTYPE_P2P_CLIENT)
9517 return -EOPNOTSUPP;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02009518
Hila Gonene35e4d22012-06-27 17:19:42 +03009519 return rdev_set_cqm_rssi_config(rdev, dev, threshold, hysteresis);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02009520}
9521
9522static int nl80211_set_cqm(struct sk_buff *skb, struct genl_info *info)
9523{
9524 struct nlattr *attrs[NL80211_ATTR_CQM_MAX + 1];
9525 struct nlattr *cqm;
9526 int err;
9527
9528 cqm = info->attrs[NL80211_ATTR_CQM];
Johannes Berg1da5fcc2013-08-06 14:10:48 +02009529 if (!cqm)
9530 return -EINVAL;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02009531
9532 err = nla_parse_nested(attrs, NL80211_ATTR_CQM_MAX, cqm,
9533 nl80211_attr_cqm_policy);
9534 if (err)
Johannes Berg1da5fcc2013-08-06 14:10:48 +02009535 return err;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02009536
9537 if (attrs[NL80211_ATTR_CQM_RSSI_THOLD] &&
9538 attrs[NL80211_ATTR_CQM_RSSI_HYST]) {
Johannes Berg1da5fcc2013-08-06 14:10:48 +02009539 s32 threshold = nla_get_s32(attrs[NL80211_ATTR_CQM_RSSI_THOLD]);
9540 u32 hysteresis = nla_get_u32(attrs[NL80211_ATTR_CQM_RSSI_HYST]);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02009541
Johannes Berg1da5fcc2013-08-06 14:10:48 +02009542 return nl80211_set_cqm_rssi(info, threshold, hysteresis);
9543 }
9544
9545 if (attrs[NL80211_ATTR_CQM_TXE_RATE] &&
9546 attrs[NL80211_ATTR_CQM_TXE_PKTS] &&
9547 attrs[NL80211_ATTR_CQM_TXE_INTVL]) {
9548 u32 rate = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_RATE]);
9549 u32 pkts = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_PKTS]);
9550 u32 intvl = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_INTVL]);
9551
9552 return nl80211_set_cqm_txe(info, rate, pkts, intvl);
9553 }
9554
9555 return -EINVAL;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02009556}
9557
Rostislav Lisovy6e0bd6c2014-11-03 10:33:18 +01009558static int nl80211_join_ocb(struct sk_buff *skb, struct genl_info *info)
9559{
9560 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9561 struct net_device *dev = info->user_ptr[1];
9562 struct ocb_setup setup = {};
9563 int err;
9564
9565 err = nl80211_parse_chandef(rdev, info, &setup.chandef);
9566 if (err)
9567 return err;
9568
9569 return cfg80211_join_ocb(rdev, dev, &setup);
9570}
9571
9572static int nl80211_leave_ocb(struct sk_buff *skb, struct genl_info *info)
9573{
9574 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9575 struct net_device *dev = info->user_ptr[1];
9576
9577 return cfg80211_leave_ocb(rdev, dev);
9578}
9579
Johannes Berg29cbe682010-12-03 09:20:44 +01009580static int nl80211_join_mesh(struct sk_buff *skb, struct genl_info *info)
9581{
9582 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9583 struct net_device *dev = info->user_ptr[1];
9584 struct mesh_config cfg;
Javier Cardonac80d5452010-12-16 17:37:49 -08009585 struct mesh_setup setup;
Johannes Berg29cbe682010-12-03 09:20:44 +01009586 int err;
9587
9588 /* start with default */
9589 memcpy(&cfg, &default_mesh_config, sizeof(cfg));
Javier Cardonac80d5452010-12-16 17:37:49 -08009590 memcpy(&setup, &default_mesh_setup, sizeof(setup));
Johannes Berg29cbe682010-12-03 09:20:44 +01009591
Javier Cardona24bdd9f2010-12-16 17:37:48 -08009592 if (info->attrs[NL80211_ATTR_MESH_CONFIG]) {
Johannes Berg29cbe682010-12-03 09:20:44 +01009593 /* and parse parameters if given */
Javier Cardona24bdd9f2010-12-16 17:37:48 -08009594 err = nl80211_parse_mesh_config(info, &cfg, NULL);
Johannes Berg29cbe682010-12-03 09:20:44 +01009595 if (err)
9596 return err;
9597 }
9598
9599 if (!info->attrs[NL80211_ATTR_MESH_ID] ||
9600 !nla_len(info->attrs[NL80211_ATTR_MESH_ID]))
9601 return -EINVAL;
9602
Javier Cardonac80d5452010-12-16 17:37:49 -08009603 setup.mesh_id = nla_data(info->attrs[NL80211_ATTR_MESH_ID]);
9604 setup.mesh_id_len = nla_len(info->attrs[NL80211_ATTR_MESH_ID]);
9605
Chun-Yeow Yeoh4bb62342011-11-24 17:15:20 -08009606 if (info->attrs[NL80211_ATTR_MCAST_RATE] &&
9607 !nl80211_parse_mcast_rate(rdev, setup.mcast_rate,
9608 nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE])))
9609 return -EINVAL;
9610
Marco Porsch9bdbf042013-01-07 16:04:51 +01009611 if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) {
9612 setup.beacon_interval =
9613 nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]);
Purushottam Kushwaha12d20fc92016-08-11 15:14:02 +05309614
Purushottam Kushwaha0c317a02016-10-12 18:26:51 +05309615 err = cfg80211_validate_beacon_int(rdev,
9616 NL80211_IFTYPE_MESH_POINT,
9617 setup.beacon_interval);
Purushottam Kushwaha12d20fc92016-08-11 15:14:02 +05309618 if (err)
9619 return err;
Marco Porsch9bdbf042013-01-07 16:04:51 +01009620 }
9621
9622 if (info->attrs[NL80211_ATTR_DTIM_PERIOD]) {
9623 setup.dtim_period =
9624 nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]);
9625 if (setup.dtim_period < 1 || setup.dtim_period > 100)
9626 return -EINVAL;
9627 }
9628
Javier Cardonac80d5452010-12-16 17:37:49 -08009629 if (info->attrs[NL80211_ATTR_MESH_SETUP]) {
9630 /* parse additional setup parameters if given */
9631 err = nl80211_parse_mesh_setup(info, &setup);
9632 if (err)
9633 return err;
9634 }
9635
Thomas Pedersend37bb182013-03-04 13:06:13 -08009636 if (setup.user_mpm)
9637 cfg.auto_open_plinks = false;
9638
Johannes Bergcc1d2802012-05-16 23:50:20 +02009639 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
Johannes Berg683b6d32012-11-08 21:25:48 +01009640 err = nl80211_parse_chandef(rdev, info, &setup.chandef);
9641 if (err)
9642 return err;
Johannes Bergcc1d2802012-05-16 23:50:20 +02009643 } else {
9644 /* cfg80211_join_mesh() will sort it out */
Johannes Berg683b6d32012-11-08 21:25:48 +01009645 setup.chandef.chan = NULL;
Johannes Bergcc1d2802012-05-16 23:50:20 +02009646 }
9647
Ashok Nagarajanffb3cf32013-06-03 10:33:36 -07009648 if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) {
9649 u8 *rates = nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
9650 int n_rates =
9651 nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
9652 struct ieee80211_supported_band *sband;
9653
9654 if (!setup.chandef.chan)
9655 return -EINVAL;
9656
9657 sband = rdev->wiphy.bands[setup.chandef.chan->band];
9658
9659 err = ieee80211_get_ratemask(sband, rates, n_rates,
9660 &setup.basic_rates);
9661 if (err)
9662 return err;
9663 }
9664
Johannes Berg8564e382016-09-19 09:44:44 +02009665 if (info->attrs[NL80211_ATTR_TX_RATES]) {
9666 err = nl80211_parse_tx_bitrate_mask(info, &setup.beacon_rate);
9667 if (err)
9668 return err;
9669
9670 err = validate_beacon_tx_rate(rdev, setup.chandef.chan->band,
9671 &setup.beacon_rate);
9672 if (err)
9673 return err;
9674 }
9675
Javier Cardonac80d5452010-12-16 17:37:49 -08009676 return cfg80211_join_mesh(rdev, dev, &setup, &cfg);
Johannes Berg29cbe682010-12-03 09:20:44 +01009677}
9678
9679static int nl80211_leave_mesh(struct sk_buff *skb, struct genl_info *info)
9680{
9681 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9682 struct net_device *dev = info->user_ptr[1];
9683
9684 return cfg80211_leave_mesh(rdev, dev);
9685}
9686
Johannes Bergdfb89c52012-06-27 09:23:48 +02009687#ifdef CONFIG_PM
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08009688static int nl80211_send_wowlan_patterns(struct sk_buff *msg,
9689 struct cfg80211_registered_device *rdev)
9690{
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009691 struct cfg80211_wowlan *wowlan = rdev->wiphy.wowlan_config;
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08009692 struct nlattr *nl_pats, *nl_pat;
9693 int i, pat_len;
9694
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009695 if (!wowlan->n_patterns)
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08009696 return 0;
9697
9698 nl_pats = nla_nest_start(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN);
9699 if (!nl_pats)
9700 return -ENOBUFS;
9701
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009702 for (i = 0; i < wowlan->n_patterns; i++) {
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08009703 nl_pat = nla_nest_start(msg, i + 1);
9704 if (!nl_pat)
9705 return -ENOBUFS;
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009706 pat_len = wowlan->patterns[i].pattern_len;
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07009707 if (nla_put(msg, NL80211_PKTPAT_MASK, DIV_ROUND_UP(pat_len, 8),
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009708 wowlan->patterns[i].mask) ||
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07009709 nla_put(msg, NL80211_PKTPAT_PATTERN, pat_len,
9710 wowlan->patterns[i].pattern) ||
9711 nla_put_u32(msg, NL80211_PKTPAT_OFFSET,
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009712 wowlan->patterns[i].pkt_offset))
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08009713 return -ENOBUFS;
9714 nla_nest_end(msg, nl_pat);
9715 }
9716 nla_nest_end(msg, nl_pats);
9717
9718 return 0;
9719}
9720
Johannes Berg2a0e0472013-01-23 22:57:40 +01009721static int nl80211_send_wowlan_tcp(struct sk_buff *msg,
9722 struct cfg80211_wowlan_tcp *tcp)
9723{
9724 struct nlattr *nl_tcp;
9725
9726 if (!tcp)
9727 return 0;
9728
9729 nl_tcp = nla_nest_start(msg, NL80211_WOWLAN_TRIG_TCP_CONNECTION);
9730 if (!nl_tcp)
9731 return -ENOBUFS;
9732
Jiri Benc930345e2015-03-29 16:59:25 +02009733 if (nla_put_in_addr(msg, NL80211_WOWLAN_TCP_SRC_IPV4, tcp->src) ||
9734 nla_put_in_addr(msg, NL80211_WOWLAN_TCP_DST_IPV4, tcp->dst) ||
Johannes Berg2a0e0472013-01-23 22:57:40 +01009735 nla_put(msg, NL80211_WOWLAN_TCP_DST_MAC, ETH_ALEN, tcp->dst_mac) ||
9736 nla_put_u16(msg, NL80211_WOWLAN_TCP_SRC_PORT, tcp->src_port) ||
9737 nla_put_u16(msg, NL80211_WOWLAN_TCP_DST_PORT, tcp->dst_port) ||
9738 nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD,
9739 tcp->payload_len, tcp->payload) ||
9740 nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_INTERVAL,
9741 tcp->data_interval) ||
9742 nla_put(msg, NL80211_WOWLAN_TCP_WAKE_PAYLOAD,
9743 tcp->wake_len, tcp->wake_data) ||
9744 nla_put(msg, NL80211_WOWLAN_TCP_WAKE_MASK,
9745 DIV_ROUND_UP(tcp->wake_len, 8), tcp->wake_mask))
9746 return -ENOBUFS;
9747
9748 if (tcp->payload_seq.len &&
9749 nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ,
9750 sizeof(tcp->payload_seq), &tcp->payload_seq))
9751 return -ENOBUFS;
9752
9753 if (tcp->payload_tok.len &&
9754 nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN,
9755 sizeof(tcp->payload_tok) + tcp->tokens_size,
9756 &tcp->payload_tok))
9757 return -ENOBUFS;
9758
Johannes Berge248ad32013-05-16 10:24:28 +02009759 nla_nest_end(msg, nl_tcp);
9760
Johannes Berg2a0e0472013-01-23 22:57:40 +01009761 return 0;
9762}
9763
Luciano Coelho75453cc2015-01-09 14:06:37 +02009764static int nl80211_send_wowlan_nd(struct sk_buff *msg,
9765 struct cfg80211_sched_scan_request *req)
9766{
Avraham Stern3b06d272015-10-12 09:51:34 +03009767 struct nlattr *nd, *freqs, *matches, *match, *scan_plans, *scan_plan;
Luciano Coelho75453cc2015-01-09 14:06:37 +02009768 int i;
9769
9770 if (!req)
9771 return 0;
9772
9773 nd = nla_nest_start(msg, NL80211_WOWLAN_TRIG_NET_DETECT);
9774 if (!nd)
9775 return -ENOBUFS;
9776
Avraham Stern3b06d272015-10-12 09:51:34 +03009777 if (req->n_scan_plans == 1 &&
9778 nla_put_u32(msg, NL80211_ATTR_SCHED_SCAN_INTERVAL,
9779 req->scan_plans[0].interval * 1000))
Luciano Coelho75453cc2015-01-09 14:06:37 +02009780 return -ENOBUFS;
9781
Luciano Coelho21fea562015-03-17 16:36:01 +02009782 if (nla_put_u32(msg, NL80211_ATTR_SCHED_SCAN_DELAY, req->delay))
9783 return -ENOBUFS;
9784
vamsi krishnabf95ecd2017-01-13 01:12:20 +02009785 if (req->relative_rssi_set) {
9786 struct nl80211_bss_select_rssi_adjust rssi_adjust;
9787
9788 if (nla_put_s8(msg, NL80211_ATTR_SCHED_SCAN_RELATIVE_RSSI,
9789 req->relative_rssi))
9790 return -ENOBUFS;
9791
9792 rssi_adjust.band = req->rssi_adjust.band;
9793 rssi_adjust.delta = req->rssi_adjust.delta;
9794 if (nla_put(msg, NL80211_ATTR_SCHED_SCAN_RSSI_ADJUST,
9795 sizeof(rssi_adjust), &rssi_adjust))
9796 return -ENOBUFS;
9797 }
9798
Luciano Coelho75453cc2015-01-09 14:06:37 +02009799 freqs = nla_nest_start(msg, NL80211_ATTR_SCAN_FREQUENCIES);
9800 if (!freqs)
9801 return -ENOBUFS;
9802
Johannes Berg53b18982016-09-14 09:59:21 +02009803 for (i = 0; i < req->n_channels; i++) {
9804 if (nla_put_u32(msg, i, req->channels[i]->center_freq))
9805 return -ENOBUFS;
9806 }
Luciano Coelho75453cc2015-01-09 14:06:37 +02009807
9808 nla_nest_end(msg, freqs);
9809
9810 if (req->n_match_sets) {
9811 matches = nla_nest_start(msg, NL80211_ATTR_SCHED_SCAN_MATCH);
Johannes Berg76e1fb42016-09-14 09:55:57 +02009812 if (!matches)
9813 return -ENOBUFS;
9814
Luciano Coelho75453cc2015-01-09 14:06:37 +02009815 for (i = 0; i < req->n_match_sets; i++) {
9816 match = nla_nest_start(msg, i);
Johannes Berg76e1fb42016-09-14 09:55:57 +02009817 if (!match)
9818 return -ENOBUFS;
9819
Johannes Berg53b18982016-09-14 09:59:21 +02009820 if (nla_put(msg, NL80211_SCHED_SCAN_MATCH_ATTR_SSID,
9821 req->match_sets[i].ssid.ssid_len,
9822 req->match_sets[i].ssid.ssid))
9823 return -ENOBUFS;
Luciano Coelho75453cc2015-01-09 14:06:37 +02009824 nla_nest_end(msg, match);
9825 }
9826 nla_nest_end(msg, matches);
9827 }
9828
Avraham Stern3b06d272015-10-12 09:51:34 +03009829 scan_plans = nla_nest_start(msg, NL80211_ATTR_SCHED_SCAN_PLANS);
9830 if (!scan_plans)
9831 return -ENOBUFS;
9832
9833 for (i = 0; i < req->n_scan_plans; i++) {
9834 scan_plan = nla_nest_start(msg, i + 1);
Johannes Berg76e1fb42016-09-14 09:55:57 +02009835 if (!scan_plan)
9836 return -ENOBUFS;
9837
Avraham Stern3b06d272015-10-12 09:51:34 +03009838 if (!scan_plan ||
9839 nla_put_u32(msg, NL80211_SCHED_SCAN_PLAN_INTERVAL,
9840 req->scan_plans[i].interval) ||
9841 (req->scan_plans[i].iterations &&
9842 nla_put_u32(msg, NL80211_SCHED_SCAN_PLAN_ITERATIONS,
9843 req->scan_plans[i].iterations)))
9844 return -ENOBUFS;
9845 nla_nest_end(msg, scan_plan);
9846 }
9847 nla_nest_end(msg, scan_plans);
9848
Luciano Coelho75453cc2015-01-09 14:06:37 +02009849 nla_nest_end(msg, nd);
9850
9851 return 0;
9852}
9853
Johannes Bergff1b6e62011-05-04 15:37:28 +02009854static int nl80211_get_wowlan(struct sk_buff *skb, struct genl_info *info)
9855{
9856 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9857 struct sk_buff *msg;
9858 void *hdr;
Johannes Berg2a0e0472013-01-23 22:57:40 +01009859 u32 size = NLMSG_DEFAULT_SIZE;
Johannes Bergff1b6e62011-05-04 15:37:28 +02009860
Johannes Berg964dc9e2013-06-03 17:25:34 +02009861 if (!rdev->wiphy.wowlan)
Johannes Bergff1b6e62011-05-04 15:37:28 +02009862 return -EOPNOTSUPP;
9863
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009864 if (rdev->wiphy.wowlan_config && rdev->wiphy.wowlan_config->tcp) {
Johannes Berg2a0e0472013-01-23 22:57:40 +01009865 /* adjust size to have room for all the data */
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009866 size += rdev->wiphy.wowlan_config->tcp->tokens_size +
9867 rdev->wiphy.wowlan_config->tcp->payload_len +
9868 rdev->wiphy.wowlan_config->tcp->wake_len +
9869 rdev->wiphy.wowlan_config->tcp->wake_len / 8;
Johannes Berg2a0e0472013-01-23 22:57:40 +01009870 }
9871
9872 msg = nlmsg_new(size, GFP_KERNEL);
Johannes Bergff1b6e62011-05-04 15:37:28 +02009873 if (!msg)
9874 return -ENOMEM;
9875
Eric W. Biederman15e47302012-09-07 20:12:54 +00009876 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Johannes Bergff1b6e62011-05-04 15:37:28 +02009877 NL80211_CMD_GET_WOWLAN);
9878 if (!hdr)
9879 goto nla_put_failure;
9880
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009881 if (rdev->wiphy.wowlan_config) {
Johannes Bergff1b6e62011-05-04 15:37:28 +02009882 struct nlattr *nl_wowlan;
9883
9884 nl_wowlan = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS);
9885 if (!nl_wowlan)
9886 goto nla_put_failure;
9887
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009888 if ((rdev->wiphy.wowlan_config->any &&
David S. Miller9360ffd2012-03-29 04:41:26 -04009889 nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009890 (rdev->wiphy.wowlan_config->disconnect &&
David S. Miller9360ffd2012-03-29 04:41:26 -04009891 nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009892 (rdev->wiphy.wowlan_config->magic_pkt &&
David S. Miller9360ffd2012-03-29 04:41:26 -04009893 nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009894 (rdev->wiphy.wowlan_config->gtk_rekey_failure &&
David S. Miller9360ffd2012-03-29 04:41:26 -04009895 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009896 (rdev->wiphy.wowlan_config->eap_identity_req &&
David S. Miller9360ffd2012-03-29 04:41:26 -04009897 nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009898 (rdev->wiphy.wowlan_config->four_way_handshake &&
David S. Miller9360ffd2012-03-29 04:41:26 -04009899 nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009900 (rdev->wiphy.wowlan_config->rfkill_release &&
David S. Miller9360ffd2012-03-29 04:41:26 -04009901 nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE)))
9902 goto nla_put_failure;
Johannes Berg2a0e0472013-01-23 22:57:40 +01009903
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08009904 if (nl80211_send_wowlan_patterns(msg, rdev))
9905 goto nla_put_failure;
Johannes Berg2a0e0472013-01-23 22:57:40 +01009906
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009907 if (nl80211_send_wowlan_tcp(msg,
9908 rdev->wiphy.wowlan_config->tcp))
Johannes Berg2a0e0472013-01-23 22:57:40 +01009909 goto nla_put_failure;
9910
Luciano Coelho75453cc2015-01-09 14:06:37 +02009911 if (nl80211_send_wowlan_nd(
9912 msg,
9913 rdev->wiphy.wowlan_config->nd_config))
9914 goto nla_put_failure;
9915
Johannes Bergff1b6e62011-05-04 15:37:28 +02009916 nla_nest_end(msg, nl_wowlan);
9917 }
9918
9919 genlmsg_end(msg, hdr);
9920 return genlmsg_reply(msg, info);
9921
9922nla_put_failure:
9923 nlmsg_free(msg);
9924 return -ENOBUFS;
9925}
9926
Johannes Berg2a0e0472013-01-23 22:57:40 +01009927static int nl80211_parse_wowlan_tcp(struct cfg80211_registered_device *rdev,
9928 struct nlattr *attr,
9929 struct cfg80211_wowlan *trig)
9930{
9931 struct nlattr *tb[NUM_NL80211_WOWLAN_TCP];
9932 struct cfg80211_wowlan_tcp *cfg;
9933 struct nl80211_wowlan_tcp_data_token *tok = NULL;
9934 struct nl80211_wowlan_tcp_data_seq *seq = NULL;
9935 u32 size;
9936 u32 data_size, wake_size, tokens_size = 0, wake_mask_size;
9937 int err, port;
9938
Johannes Berg964dc9e2013-06-03 17:25:34 +02009939 if (!rdev->wiphy.wowlan->tcp)
Johannes Berg2a0e0472013-01-23 22:57:40 +01009940 return -EINVAL;
9941
Johannes Bergbfe2c7b2016-10-26 14:42:21 +02009942 err = nla_parse_nested(tb, MAX_NL80211_WOWLAN_TCP, attr,
9943 nl80211_wowlan_tcp_policy);
Johannes Berg2a0e0472013-01-23 22:57:40 +01009944 if (err)
9945 return err;
9946
9947 if (!tb[NL80211_WOWLAN_TCP_SRC_IPV4] ||
9948 !tb[NL80211_WOWLAN_TCP_DST_IPV4] ||
9949 !tb[NL80211_WOWLAN_TCP_DST_MAC] ||
9950 !tb[NL80211_WOWLAN_TCP_DST_PORT] ||
9951 !tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD] ||
9952 !tb[NL80211_WOWLAN_TCP_DATA_INTERVAL] ||
9953 !tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD] ||
9954 !tb[NL80211_WOWLAN_TCP_WAKE_MASK])
9955 return -EINVAL;
9956
9957 data_size = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]);
Johannes Berg964dc9e2013-06-03 17:25:34 +02009958 if (data_size > rdev->wiphy.wowlan->tcp->data_payload_max)
Johannes Berg2a0e0472013-01-23 22:57:40 +01009959 return -EINVAL;
9960
9961 if (nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]) >
Johannes Berg964dc9e2013-06-03 17:25:34 +02009962 rdev->wiphy.wowlan->tcp->data_interval_max ||
Johannes Berg723d5682013-02-26 13:56:40 +01009963 nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]) == 0)
Johannes Berg2a0e0472013-01-23 22:57:40 +01009964 return -EINVAL;
9965
9966 wake_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]);
Johannes Berg964dc9e2013-06-03 17:25:34 +02009967 if (wake_size > rdev->wiphy.wowlan->tcp->wake_payload_max)
Johannes Berg2a0e0472013-01-23 22:57:40 +01009968 return -EINVAL;
9969
9970 wake_mask_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_MASK]);
9971 if (wake_mask_size != DIV_ROUND_UP(wake_size, 8))
9972 return -EINVAL;
9973
9974 if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]) {
9975 u32 tokln = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]);
9976
9977 tok = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]);
9978 tokens_size = tokln - sizeof(*tok);
9979
9980 if (!tok->len || tokens_size % tok->len)
9981 return -EINVAL;
Johannes Berg964dc9e2013-06-03 17:25:34 +02009982 if (!rdev->wiphy.wowlan->tcp->tok)
Johannes Berg2a0e0472013-01-23 22:57:40 +01009983 return -EINVAL;
Johannes Berg964dc9e2013-06-03 17:25:34 +02009984 if (tok->len > rdev->wiphy.wowlan->tcp->tok->max_len)
Johannes Berg2a0e0472013-01-23 22:57:40 +01009985 return -EINVAL;
Johannes Berg964dc9e2013-06-03 17:25:34 +02009986 if (tok->len < rdev->wiphy.wowlan->tcp->tok->min_len)
Johannes Berg2a0e0472013-01-23 22:57:40 +01009987 return -EINVAL;
Johannes Berg964dc9e2013-06-03 17:25:34 +02009988 if (tokens_size > rdev->wiphy.wowlan->tcp->tok->bufsize)
Johannes Berg2a0e0472013-01-23 22:57:40 +01009989 return -EINVAL;
9990 if (tok->offset + tok->len > data_size)
9991 return -EINVAL;
9992 }
9993
9994 if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]) {
9995 seq = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]);
Johannes Berg964dc9e2013-06-03 17:25:34 +02009996 if (!rdev->wiphy.wowlan->tcp->seq)
Johannes Berg2a0e0472013-01-23 22:57:40 +01009997 return -EINVAL;
9998 if (seq->len == 0 || seq->len > 4)
9999 return -EINVAL;
10000 if (seq->len + seq->offset > data_size)
10001 return -EINVAL;
10002 }
10003
10004 size = sizeof(*cfg);
10005 size += data_size;
10006 size += wake_size + wake_mask_size;
10007 size += tokens_size;
10008
10009 cfg = kzalloc(size, GFP_KERNEL);
10010 if (!cfg)
10011 return -ENOMEM;
Jiri Benc67b61f62015-03-29 16:59:26 +020010012 cfg->src = nla_get_in_addr(tb[NL80211_WOWLAN_TCP_SRC_IPV4]);
10013 cfg->dst = nla_get_in_addr(tb[NL80211_WOWLAN_TCP_DST_IPV4]);
Johannes Berg2a0e0472013-01-23 22:57:40 +010010014 memcpy(cfg->dst_mac, nla_data(tb[NL80211_WOWLAN_TCP_DST_MAC]),
10015 ETH_ALEN);
10016 if (tb[NL80211_WOWLAN_TCP_SRC_PORT])
10017 port = nla_get_u16(tb[NL80211_WOWLAN_TCP_SRC_PORT]);
10018 else
10019 port = 0;
10020#ifdef CONFIG_INET
10021 /* allocate a socket and port for it and use it */
10022 err = __sock_create(wiphy_net(&rdev->wiphy), PF_INET, SOCK_STREAM,
10023 IPPROTO_TCP, &cfg->sock, 1);
10024 if (err) {
10025 kfree(cfg);
10026 return err;
10027 }
10028 if (inet_csk_get_port(cfg->sock->sk, port)) {
10029 sock_release(cfg->sock);
10030 kfree(cfg);
10031 return -EADDRINUSE;
10032 }
10033 cfg->src_port = inet_sk(cfg->sock->sk)->inet_num;
10034#else
10035 if (!port) {
10036 kfree(cfg);
10037 return -EINVAL;
10038 }
10039 cfg->src_port = port;
10040#endif
10041
10042 cfg->dst_port = nla_get_u16(tb[NL80211_WOWLAN_TCP_DST_PORT]);
10043 cfg->payload_len = data_size;
10044 cfg->payload = (u8 *)cfg + sizeof(*cfg) + tokens_size;
10045 memcpy((void *)cfg->payload,
10046 nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]),
10047 data_size);
10048 if (seq)
10049 cfg->payload_seq = *seq;
10050 cfg->data_interval = nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]);
10051 cfg->wake_len = wake_size;
10052 cfg->wake_data = (u8 *)cfg + sizeof(*cfg) + tokens_size + data_size;
10053 memcpy((void *)cfg->wake_data,
10054 nla_data(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]),
10055 wake_size);
10056 cfg->wake_mask = (u8 *)cfg + sizeof(*cfg) + tokens_size +
10057 data_size + wake_size;
10058 memcpy((void *)cfg->wake_mask,
10059 nla_data(tb[NL80211_WOWLAN_TCP_WAKE_MASK]),
10060 wake_mask_size);
10061 if (tok) {
10062 cfg->tokens_size = tokens_size;
10063 memcpy(&cfg->payload_tok, tok, sizeof(*tok) + tokens_size);
10064 }
10065
10066 trig->tcp = cfg;
10067
10068 return 0;
10069}
10070
Luciano Coelho8cd4d452014-09-17 11:55:28 +030010071static int nl80211_parse_wowlan_nd(struct cfg80211_registered_device *rdev,
10072 const struct wiphy_wowlan_support *wowlan,
10073 struct nlattr *attr,
10074 struct cfg80211_wowlan *trig)
10075{
10076 struct nlattr **tb;
10077 int err;
10078
10079 tb = kzalloc(NUM_NL80211_ATTR * sizeof(*tb), GFP_KERNEL);
10080 if (!tb)
10081 return -ENOMEM;
10082
10083 if (!(wowlan->flags & WIPHY_WOWLAN_NET_DETECT)) {
10084 err = -EOPNOTSUPP;
10085 goto out;
10086 }
10087
Johannes Bergbfe2c7b2016-10-26 14:42:21 +020010088 err = nla_parse_nested(tb, NL80211_ATTR_MAX, attr, nl80211_policy);
Luciano Coelho8cd4d452014-09-17 11:55:28 +030010089 if (err)
10090 goto out;
10091
Arend Van Sprielaad1e812017-01-27 12:27:44 +000010092 trig->nd_config = nl80211_parse_sched_scan(&rdev->wiphy, NULL, tb,
10093 wowlan->max_nd_match_sets);
Luciano Coelho8cd4d452014-09-17 11:55:28 +030010094 err = PTR_ERR_OR_ZERO(trig->nd_config);
10095 if (err)
10096 trig->nd_config = NULL;
10097
10098out:
10099 kfree(tb);
10100 return err;
10101}
10102
Johannes Bergff1b6e62011-05-04 15:37:28 +020010103static int nl80211_set_wowlan(struct sk_buff *skb, struct genl_info *info)
10104{
10105 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10106 struct nlattr *tb[NUM_NL80211_WOWLAN_TRIG];
Johannes Bergff1b6e62011-05-04 15:37:28 +020010107 struct cfg80211_wowlan new_triggers = {};
Johannes Bergae33bd82012-07-12 16:25:02 +020010108 struct cfg80211_wowlan *ntrig;
Johannes Berg964dc9e2013-06-03 17:25:34 +020010109 const struct wiphy_wowlan_support *wowlan = rdev->wiphy.wowlan;
Johannes Bergff1b6e62011-05-04 15:37:28 +020010110 int err, i;
Johannes Berg6abb9cb2013-05-15 09:30:07 +020010111 bool prev_enabled = rdev->wiphy.wowlan_config;
Johannes Berg98fc4382015-03-01 09:10:13 +020010112 bool regular = false;
Johannes Bergff1b6e62011-05-04 15:37:28 +020010113
Johannes Berg964dc9e2013-06-03 17:25:34 +020010114 if (!wowlan)
Johannes Bergff1b6e62011-05-04 15:37:28 +020010115 return -EOPNOTSUPP;
10116
Johannes Bergae33bd82012-07-12 16:25:02 +020010117 if (!info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]) {
10118 cfg80211_rdev_free_wowlan(rdev);
Johannes Berg6abb9cb2013-05-15 09:30:07 +020010119 rdev->wiphy.wowlan_config = NULL;
Johannes Bergae33bd82012-07-12 16:25:02 +020010120 goto set_wakeup;
10121 }
Johannes Bergff1b6e62011-05-04 15:37:28 +020010122
Johannes Bergbfe2c7b2016-10-26 14:42:21 +020010123 err = nla_parse_nested(tb, MAX_NL80211_WOWLAN_TRIG,
10124 info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS],
10125 nl80211_wowlan_policy);
Johannes Bergff1b6e62011-05-04 15:37:28 +020010126 if (err)
10127 return err;
10128
10129 if (tb[NL80211_WOWLAN_TRIG_ANY]) {
10130 if (!(wowlan->flags & WIPHY_WOWLAN_ANY))
10131 return -EINVAL;
10132 new_triggers.any = true;
10133 }
10134
10135 if (tb[NL80211_WOWLAN_TRIG_DISCONNECT]) {
10136 if (!(wowlan->flags & WIPHY_WOWLAN_DISCONNECT))
10137 return -EINVAL;
10138 new_triggers.disconnect = true;
Johannes Berg98fc4382015-03-01 09:10:13 +020010139 regular = true;
Johannes Bergff1b6e62011-05-04 15:37:28 +020010140 }
10141
10142 if (tb[NL80211_WOWLAN_TRIG_MAGIC_PKT]) {
10143 if (!(wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT))
10144 return -EINVAL;
10145 new_triggers.magic_pkt = true;
Johannes Berg98fc4382015-03-01 09:10:13 +020010146 regular = true;
Johannes Bergff1b6e62011-05-04 15:37:28 +020010147 }
10148
Johannes Berg77dbbb12011-07-13 10:48:55 +020010149 if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED])
10150 return -EINVAL;
10151
10152 if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE]) {
10153 if (!(wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE))
10154 return -EINVAL;
10155 new_triggers.gtk_rekey_failure = true;
Johannes Berg98fc4382015-03-01 09:10:13 +020010156 regular = true;
Johannes Berg77dbbb12011-07-13 10:48:55 +020010157 }
10158
10159 if (tb[NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST]) {
10160 if (!(wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ))
10161 return -EINVAL;
10162 new_triggers.eap_identity_req = true;
Johannes Berg98fc4382015-03-01 09:10:13 +020010163 regular = true;
Johannes Berg77dbbb12011-07-13 10:48:55 +020010164 }
10165
10166 if (tb[NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE]) {
10167 if (!(wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE))
10168 return -EINVAL;
10169 new_triggers.four_way_handshake = true;
Johannes Berg98fc4382015-03-01 09:10:13 +020010170 regular = true;
Johannes Berg77dbbb12011-07-13 10:48:55 +020010171 }
10172
10173 if (tb[NL80211_WOWLAN_TRIG_RFKILL_RELEASE]) {
10174 if (!(wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE))
10175 return -EINVAL;
10176 new_triggers.rfkill_release = true;
Johannes Berg98fc4382015-03-01 09:10:13 +020010177 regular = true;
Johannes Berg77dbbb12011-07-13 10:48:55 +020010178 }
10179
Johannes Bergff1b6e62011-05-04 15:37:28 +020010180 if (tb[NL80211_WOWLAN_TRIG_PKT_PATTERN]) {
10181 struct nlattr *pat;
10182 int n_patterns = 0;
Amitkumar Karwarbb92d192013-02-12 12:16:26 -080010183 int rem, pat_len, mask_len, pkt_offset;
Amitkumar Karwar50ac6602013-06-25 19:03:56 -070010184 struct nlattr *pat_tb[NUM_NL80211_PKTPAT];
Johannes Bergff1b6e62011-05-04 15:37:28 +020010185
Johannes Berg98fc4382015-03-01 09:10:13 +020010186 regular = true;
10187
Johannes Bergff1b6e62011-05-04 15:37:28 +020010188 nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN],
10189 rem)
10190 n_patterns++;
10191 if (n_patterns > wowlan->n_patterns)
10192 return -EINVAL;
10193
10194 new_triggers.patterns = kcalloc(n_patterns,
10195 sizeof(new_triggers.patterns[0]),
10196 GFP_KERNEL);
10197 if (!new_triggers.patterns)
10198 return -ENOMEM;
10199
10200 new_triggers.n_patterns = n_patterns;
10201 i = 0;
10202
10203 nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN],
10204 rem) {
Johannes Berg922bd802014-05-19 17:59:50 +020010205 u8 *mask_pat;
10206
Johannes Bergbfe2c7b2016-10-26 14:42:21 +020010207 nla_parse_nested(pat_tb, MAX_NL80211_PKTPAT, pat,
10208 NULL);
Johannes Bergff1b6e62011-05-04 15:37:28 +020010209 err = -EINVAL;
Amitkumar Karwar50ac6602013-06-25 19:03:56 -070010210 if (!pat_tb[NL80211_PKTPAT_MASK] ||
10211 !pat_tb[NL80211_PKTPAT_PATTERN])
Johannes Bergff1b6e62011-05-04 15:37:28 +020010212 goto error;
Amitkumar Karwar50ac6602013-06-25 19:03:56 -070010213 pat_len = nla_len(pat_tb[NL80211_PKTPAT_PATTERN]);
Johannes Bergff1b6e62011-05-04 15:37:28 +020010214 mask_len = DIV_ROUND_UP(pat_len, 8);
Amitkumar Karwar50ac6602013-06-25 19:03:56 -070010215 if (nla_len(pat_tb[NL80211_PKTPAT_MASK]) != mask_len)
Johannes Bergff1b6e62011-05-04 15:37:28 +020010216 goto error;
10217 if (pat_len > wowlan->pattern_max_len ||
10218 pat_len < wowlan->pattern_min_len)
10219 goto error;
10220
Amitkumar Karwar50ac6602013-06-25 19:03:56 -070010221 if (!pat_tb[NL80211_PKTPAT_OFFSET])
Amitkumar Karwarbb92d192013-02-12 12:16:26 -080010222 pkt_offset = 0;
10223 else
10224 pkt_offset = nla_get_u32(
Amitkumar Karwar50ac6602013-06-25 19:03:56 -070010225 pat_tb[NL80211_PKTPAT_OFFSET]);
Amitkumar Karwarbb92d192013-02-12 12:16:26 -080010226 if (pkt_offset > wowlan->max_pkt_offset)
10227 goto error;
10228 new_triggers.patterns[i].pkt_offset = pkt_offset;
10229
Johannes Berg922bd802014-05-19 17:59:50 +020010230 mask_pat = kmalloc(mask_len + pat_len, GFP_KERNEL);
10231 if (!mask_pat) {
Johannes Bergff1b6e62011-05-04 15:37:28 +020010232 err = -ENOMEM;
10233 goto error;
10234 }
Johannes Berg922bd802014-05-19 17:59:50 +020010235 new_triggers.patterns[i].mask = mask_pat;
10236 memcpy(mask_pat, nla_data(pat_tb[NL80211_PKTPAT_MASK]),
Johannes Bergff1b6e62011-05-04 15:37:28 +020010237 mask_len);
Johannes Berg922bd802014-05-19 17:59:50 +020010238 mask_pat += mask_len;
10239 new_triggers.patterns[i].pattern = mask_pat;
Johannes Bergff1b6e62011-05-04 15:37:28 +020010240 new_triggers.patterns[i].pattern_len = pat_len;
Johannes Berg922bd802014-05-19 17:59:50 +020010241 memcpy(mask_pat,
Amitkumar Karwar50ac6602013-06-25 19:03:56 -070010242 nla_data(pat_tb[NL80211_PKTPAT_PATTERN]),
Johannes Bergff1b6e62011-05-04 15:37:28 +020010243 pat_len);
10244 i++;
10245 }
10246 }
10247
Johannes Berg2a0e0472013-01-23 22:57:40 +010010248 if (tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION]) {
Johannes Berg98fc4382015-03-01 09:10:13 +020010249 regular = true;
Johannes Berg2a0e0472013-01-23 22:57:40 +010010250 err = nl80211_parse_wowlan_tcp(
10251 rdev, tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION],
10252 &new_triggers);
10253 if (err)
10254 goto error;
10255 }
10256
Luciano Coelho8cd4d452014-09-17 11:55:28 +030010257 if (tb[NL80211_WOWLAN_TRIG_NET_DETECT]) {
Johannes Berg98fc4382015-03-01 09:10:13 +020010258 regular = true;
Luciano Coelho8cd4d452014-09-17 11:55:28 +030010259 err = nl80211_parse_wowlan_nd(
10260 rdev, wowlan, tb[NL80211_WOWLAN_TRIG_NET_DETECT],
10261 &new_triggers);
10262 if (err)
10263 goto error;
10264 }
10265
Johannes Berg98fc4382015-03-01 09:10:13 +020010266 /* The 'any' trigger means the device continues operating more or less
10267 * as in its normal operation mode and wakes up the host on most of the
10268 * normal interrupts (like packet RX, ...)
10269 * It therefore makes little sense to combine with the more constrained
10270 * wakeup trigger modes.
10271 */
10272 if (new_triggers.any && regular) {
10273 err = -EINVAL;
10274 goto error;
10275 }
10276
Johannes Bergae33bd82012-07-12 16:25:02 +020010277 ntrig = kmemdup(&new_triggers, sizeof(new_triggers), GFP_KERNEL);
10278 if (!ntrig) {
10279 err = -ENOMEM;
10280 goto error;
Johannes Bergff1b6e62011-05-04 15:37:28 +020010281 }
Johannes Bergae33bd82012-07-12 16:25:02 +020010282 cfg80211_rdev_free_wowlan(rdev);
Johannes Berg6abb9cb2013-05-15 09:30:07 +020010283 rdev->wiphy.wowlan_config = ntrig;
Johannes Bergff1b6e62011-05-04 15:37:28 +020010284
Johannes Bergae33bd82012-07-12 16:25:02 +020010285 set_wakeup:
Johannes Berg6abb9cb2013-05-15 09:30:07 +020010286 if (rdev->ops->set_wakeup &&
10287 prev_enabled != !!rdev->wiphy.wowlan_config)
10288 rdev_set_wakeup(rdev, rdev->wiphy.wowlan_config);
Johannes Berg6d525632012-04-04 15:05:25 +020010289
Johannes Bergff1b6e62011-05-04 15:37:28 +020010290 return 0;
10291 error:
10292 for (i = 0; i < new_triggers.n_patterns; i++)
10293 kfree(new_triggers.patterns[i].mask);
10294 kfree(new_triggers.patterns);
Johannes Berg2a0e0472013-01-23 22:57:40 +010010295 if (new_triggers.tcp && new_triggers.tcp->sock)
10296 sock_release(new_triggers.tcp->sock);
10297 kfree(new_triggers.tcp);
Ola Olssone5dbe072015-12-12 23:17:17 +010010298 kfree(new_triggers.nd_config);
Johannes Bergff1b6e62011-05-04 15:37:28 +020010299 return err;
10300}
Johannes Bergdfb89c52012-06-27 09:23:48 +020010301#endif
Johannes Bergff1b6e62011-05-04 15:37:28 +020010302
Amitkumar Karwarbe29b992013-06-28 11:51:26 -070010303static int nl80211_send_coalesce_rules(struct sk_buff *msg,
10304 struct cfg80211_registered_device *rdev)
10305{
10306 struct nlattr *nl_pats, *nl_pat, *nl_rule, *nl_rules;
10307 int i, j, pat_len;
10308 struct cfg80211_coalesce_rules *rule;
10309
10310 if (!rdev->coalesce->n_rules)
10311 return 0;
10312
10313 nl_rules = nla_nest_start(msg, NL80211_ATTR_COALESCE_RULE);
10314 if (!nl_rules)
10315 return -ENOBUFS;
10316
10317 for (i = 0; i < rdev->coalesce->n_rules; i++) {
10318 nl_rule = nla_nest_start(msg, i + 1);
10319 if (!nl_rule)
10320 return -ENOBUFS;
10321
10322 rule = &rdev->coalesce->rules[i];
10323 if (nla_put_u32(msg, NL80211_ATTR_COALESCE_RULE_DELAY,
10324 rule->delay))
10325 return -ENOBUFS;
10326
10327 if (nla_put_u32(msg, NL80211_ATTR_COALESCE_RULE_CONDITION,
10328 rule->condition))
10329 return -ENOBUFS;
10330
10331 nl_pats = nla_nest_start(msg,
10332 NL80211_ATTR_COALESCE_RULE_PKT_PATTERN);
10333 if (!nl_pats)
10334 return -ENOBUFS;
10335
10336 for (j = 0; j < rule->n_patterns; j++) {
10337 nl_pat = nla_nest_start(msg, j + 1);
10338 if (!nl_pat)
10339 return -ENOBUFS;
10340 pat_len = rule->patterns[j].pattern_len;
10341 if (nla_put(msg, NL80211_PKTPAT_MASK,
10342 DIV_ROUND_UP(pat_len, 8),
10343 rule->patterns[j].mask) ||
10344 nla_put(msg, NL80211_PKTPAT_PATTERN, pat_len,
10345 rule->patterns[j].pattern) ||
10346 nla_put_u32(msg, NL80211_PKTPAT_OFFSET,
10347 rule->patterns[j].pkt_offset))
10348 return -ENOBUFS;
10349 nla_nest_end(msg, nl_pat);
10350 }
10351 nla_nest_end(msg, nl_pats);
10352 nla_nest_end(msg, nl_rule);
10353 }
10354 nla_nest_end(msg, nl_rules);
10355
10356 return 0;
10357}
10358
10359static int nl80211_get_coalesce(struct sk_buff *skb, struct genl_info *info)
10360{
10361 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10362 struct sk_buff *msg;
10363 void *hdr;
10364
10365 if (!rdev->wiphy.coalesce)
10366 return -EOPNOTSUPP;
10367
10368 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
10369 if (!msg)
10370 return -ENOMEM;
10371
10372 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
10373 NL80211_CMD_GET_COALESCE);
10374 if (!hdr)
10375 goto nla_put_failure;
10376
10377 if (rdev->coalesce && nl80211_send_coalesce_rules(msg, rdev))
10378 goto nla_put_failure;
10379
10380 genlmsg_end(msg, hdr);
10381 return genlmsg_reply(msg, info);
10382
10383nla_put_failure:
10384 nlmsg_free(msg);
10385 return -ENOBUFS;
10386}
10387
10388void cfg80211_rdev_free_coalesce(struct cfg80211_registered_device *rdev)
10389{
10390 struct cfg80211_coalesce *coalesce = rdev->coalesce;
10391 int i, j;
10392 struct cfg80211_coalesce_rules *rule;
10393
10394 if (!coalesce)
10395 return;
10396
10397 for (i = 0; i < coalesce->n_rules; i++) {
10398 rule = &coalesce->rules[i];
10399 for (j = 0; j < rule->n_patterns; j++)
10400 kfree(rule->patterns[j].mask);
10401 kfree(rule->patterns);
10402 }
10403 kfree(coalesce->rules);
10404 kfree(coalesce);
10405 rdev->coalesce = NULL;
10406}
10407
10408static int nl80211_parse_coalesce_rule(struct cfg80211_registered_device *rdev,
10409 struct nlattr *rule,
10410 struct cfg80211_coalesce_rules *new_rule)
10411{
10412 int err, i;
10413 const struct wiphy_coalesce_support *coalesce = rdev->wiphy.coalesce;
10414 struct nlattr *tb[NUM_NL80211_ATTR_COALESCE_RULE], *pat;
10415 int rem, pat_len, mask_len, pkt_offset, n_patterns = 0;
10416 struct nlattr *pat_tb[NUM_NL80211_PKTPAT];
10417
Johannes Bergbfe2c7b2016-10-26 14:42:21 +020010418 err = nla_parse_nested(tb, NL80211_ATTR_COALESCE_RULE_MAX, rule,
10419 nl80211_coalesce_policy);
Amitkumar Karwarbe29b992013-06-28 11:51:26 -070010420 if (err)
10421 return err;
10422
10423 if (tb[NL80211_ATTR_COALESCE_RULE_DELAY])
10424 new_rule->delay =
10425 nla_get_u32(tb[NL80211_ATTR_COALESCE_RULE_DELAY]);
10426 if (new_rule->delay > coalesce->max_delay)
10427 return -EINVAL;
10428
10429 if (tb[NL80211_ATTR_COALESCE_RULE_CONDITION])
10430 new_rule->condition =
10431 nla_get_u32(tb[NL80211_ATTR_COALESCE_RULE_CONDITION]);
10432 if (new_rule->condition != NL80211_COALESCE_CONDITION_MATCH &&
10433 new_rule->condition != NL80211_COALESCE_CONDITION_NO_MATCH)
10434 return -EINVAL;
10435
10436 if (!tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN])
10437 return -EINVAL;
10438
10439 nla_for_each_nested(pat, tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN],
10440 rem)
10441 n_patterns++;
10442 if (n_patterns > coalesce->n_patterns)
10443 return -EINVAL;
10444
10445 new_rule->patterns = kcalloc(n_patterns, sizeof(new_rule->patterns[0]),
10446 GFP_KERNEL);
10447 if (!new_rule->patterns)
10448 return -ENOMEM;
10449
10450 new_rule->n_patterns = n_patterns;
10451 i = 0;
10452
10453 nla_for_each_nested(pat, tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN],
10454 rem) {
Johannes Berg922bd802014-05-19 17:59:50 +020010455 u8 *mask_pat;
10456
Johannes Bergbfe2c7b2016-10-26 14:42:21 +020010457 nla_parse_nested(pat_tb, MAX_NL80211_PKTPAT, pat, NULL);
Amitkumar Karwarbe29b992013-06-28 11:51:26 -070010458 if (!pat_tb[NL80211_PKTPAT_MASK] ||
10459 !pat_tb[NL80211_PKTPAT_PATTERN])
10460 return -EINVAL;
10461 pat_len = nla_len(pat_tb[NL80211_PKTPAT_PATTERN]);
10462 mask_len = DIV_ROUND_UP(pat_len, 8);
10463 if (nla_len(pat_tb[NL80211_PKTPAT_MASK]) != mask_len)
10464 return -EINVAL;
10465 if (pat_len > coalesce->pattern_max_len ||
10466 pat_len < coalesce->pattern_min_len)
10467 return -EINVAL;
10468
10469 if (!pat_tb[NL80211_PKTPAT_OFFSET])
10470 pkt_offset = 0;
10471 else
10472 pkt_offset = nla_get_u32(pat_tb[NL80211_PKTPAT_OFFSET]);
10473 if (pkt_offset > coalesce->max_pkt_offset)
10474 return -EINVAL;
10475 new_rule->patterns[i].pkt_offset = pkt_offset;
10476
Johannes Berg922bd802014-05-19 17:59:50 +020010477 mask_pat = kmalloc(mask_len + pat_len, GFP_KERNEL);
10478 if (!mask_pat)
Amitkumar Karwarbe29b992013-06-28 11:51:26 -070010479 return -ENOMEM;
Johannes Berg922bd802014-05-19 17:59:50 +020010480
10481 new_rule->patterns[i].mask = mask_pat;
10482 memcpy(mask_pat, nla_data(pat_tb[NL80211_PKTPAT_MASK]),
10483 mask_len);
10484
10485 mask_pat += mask_len;
10486 new_rule->patterns[i].pattern = mask_pat;
Amitkumar Karwarbe29b992013-06-28 11:51:26 -070010487 new_rule->patterns[i].pattern_len = pat_len;
Johannes Berg922bd802014-05-19 17:59:50 +020010488 memcpy(mask_pat, nla_data(pat_tb[NL80211_PKTPAT_PATTERN]),
10489 pat_len);
Amitkumar Karwarbe29b992013-06-28 11:51:26 -070010490 i++;
10491 }
10492
10493 return 0;
10494}
10495
10496static int nl80211_set_coalesce(struct sk_buff *skb, struct genl_info *info)
10497{
10498 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10499 const struct wiphy_coalesce_support *coalesce = rdev->wiphy.coalesce;
10500 struct cfg80211_coalesce new_coalesce = {};
10501 struct cfg80211_coalesce *n_coalesce;
10502 int err, rem_rule, n_rules = 0, i, j;
10503 struct nlattr *rule;
10504 struct cfg80211_coalesce_rules *tmp_rule;
10505
10506 if (!rdev->wiphy.coalesce || !rdev->ops->set_coalesce)
10507 return -EOPNOTSUPP;
10508
10509 if (!info->attrs[NL80211_ATTR_COALESCE_RULE]) {
10510 cfg80211_rdev_free_coalesce(rdev);
Ilan Peera1056b12015-10-22 22:27:46 +030010511 rdev_set_coalesce(rdev, NULL);
Amitkumar Karwarbe29b992013-06-28 11:51:26 -070010512 return 0;
10513 }
10514
10515 nla_for_each_nested(rule, info->attrs[NL80211_ATTR_COALESCE_RULE],
10516 rem_rule)
10517 n_rules++;
10518 if (n_rules > coalesce->n_rules)
10519 return -EINVAL;
10520
10521 new_coalesce.rules = kcalloc(n_rules, sizeof(new_coalesce.rules[0]),
10522 GFP_KERNEL);
10523 if (!new_coalesce.rules)
10524 return -ENOMEM;
10525
10526 new_coalesce.n_rules = n_rules;
10527 i = 0;
10528
10529 nla_for_each_nested(rule, info->attrs[NL80211_ATTR_COALESCE_RULE],
10530 rem_rule) {
10531 err = nl80211_parse_coalesce_rule(rdev, rule,
10532 &new_coalesce.rules[i]);
10533 if (err)
10534 goto error;
10535
10536 i++;
10537 }
10538
Ilan Peera1056b12015-10-22 22:27:46 +030010539 err = rdev_set_coalesce(rdev, &new_coalesce);
Amitkumar Karwarbe29b992013-06-28 11:51:26 -070010540 if (err)
10541 goto error;
10542
10543 n_coalesce = kmemdup(&new_coalesce, sizeof(new_coalesce), GFP_KERNEL);
10544 if (!n_coalesce) {
10545 err = -ENOMEM;
10546 goto error;
10547 }
10548 cfg80211_rdev_free_coalesce(rdev);
10549 rdev->coalesce = n_coalesce;
10550
10551 return 0;
10552error:
10553 for (i = 0; i < new_coalesce.n_rules; i++) {
10554 tmp_rule = &new_coalesce.rules[i];
10555 for (j = 0; j < tmp_rule->n_patterns; j++)
10556 kfree(tmp_rule->patterns[j].mask);
10557 kfree(tmp_rule->patterns);
10558 }
10559 kfree(new_coalesce.rules);
10560
10561 return err;
10562}
10563
Johannes Berge5497d72011-07-05 16:35:40 +020010564static int nl80211_set_rekey_data(struct sk_buff *skb, struct genl_info *info)
10565{
10566 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10567 struct net_device *dev = info->user_ptr[1];
10568 struct wireless_dev *wdev = dev->ieee80211_ptr;
10569 struct nlattr *tb[NUM_NL80211_REKEY_DATA];
10570 struct cfg80211_gtk_rekey_data rekey_data;
10571 int err;
10572
10573 if (!info->attrs[NL80211_ATTR_REKEY_DATA])
10574 return -EINVAL;
10575
Johannes Bergbfe2c7b2016-10-26 14:42:21 +020010576 err = nla_parse_nested(tb, MAX_NL80211_REKEY_DATA,
10577 info->attrs[NL80211_ATTR_REKEY_DATA],
10578 nl80211_rekey_policy);
Johannes Berge5497d72011-07-05 16:35:40 +020010579 if (err)
10580 return err;
10581
10582 if (nla_len(tb[NL80211_REKEY_DATA_REPLAY_CTR]) != NL80211_REPLAY_CTR_LEN)
10583 return -ERANGE;
10584 if (nla_len(tb[NL80211_REKEY_DATA_KEK]) != NL80211_KEK_LEN)
10585 return -ERANGE;
10586 if (nla_len(tb[NL80211_REKEY_DATA_KCK]) != NL80211_KCK_LEN)
10587 return -ERANGE;
10588
Johannes Berg78f686c2014-09-10 22:28:06 +030010589 rekey_data.kek = nla_data(tb[NL80211_REKEY_DATA_KEK]);
10590 rekey_data.kck = nla_data(tb[NL80211_REKEY_DATA_KCK]);
10591 rekey_data.replay_ctr = nla_data(tb[NL80211_REKEY_DATA_REPLAY_CTR]);
Johannes Berge5497d72011-07-05 16:35:40 +020010592
10593 wdev_lock(wdev);
10594 if (!wdev->current_bss) {
10595 err = -ENOTCONN;
10596 goto out;
10597 }
10598
10599 if (!rdev->ops->set_rekey_data) {
10600 err = -EOPNOTSUPP;
10601 goto out;
10602 }
10603
Hila Gonene35e4d22012-06-27 17:19:42 +030010604 err = rdev_set_rekey_data(rdev, dev, &rekey_data);
Johannes Berge5497d72011-07-05 16:35:40 +020010605 out:
10606 wdev_unlock(wdev);
10607 return err;
10608}
10609
Johannes Berg28946da2011-11-04 11:18:12 +010010610static int nl80211_register_unexpected_frame(struct sk_buff *skb,
10611 struct genl_info *info)
10612{
10613 struct net_device *dev = info->user_ptr[1];
10614 struct wireless_dev *wdev = dev->ieee80211_ptr;
10615
10616 if (wdev->iftype != NL80211_IFTYPE_AP &&
10617 wdev->iftype != NL80211_IFTYPE_P2P_GO)
10618 return -EINVAL;
10619
Eric W. Biederman15e47302012-09-07 20:12:54 +000010620 if (wdev->ap_unexpected_nlportid)
Johannes Berg28946da2011-11-04 11:18:12 +010010621 return -EBUSY;
10622
Eric W. Biederman15e47302012-09-07 20:12:54 +000010623 wdev->ap_unexpected_nlportid = info->snd_portid;
Johannes Berg28946da2011-11-04 11:18:12 +010010624 return 0;
10625}
10626
Johannes Berg7f6cf312011-11-04 11:18:15 +010010627static int nl80211_probe_client(struct sk_buff *skb,
10628 struct genl_info *info)
10629{
10630 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10631 struct net_device *dev = info->user_ptr[1];
10632 struct wireless_dev *wdev = dev->ieee80211_ptr;
10633 struct sk_buff *msg;
10634 void *hdr;
10635 const u8 *addr;
10636 u64 cookie;
10637 int err;
10638
10639 if (wdev->iftype != NL80211_IFTYPE_AP &&
10640 wdev->iftype != NL80211_IFTYPE_P2P_GO)
10641 return -EOPNOTSUPP;
10642
10643 if (!info->attrs[NL80211_ATTR_MAC])
10644 return -EINVAL;
10645
10646 if (!rdev->ops->probe_client)
10647 return -EOPNOTSUPP;
10648
10649 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
10650 if (!msg)
10651 return -ENOMEM;
10652
Eric W. Biederman15e47302012-09-07 20:12:54 +000010653 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berg7f6cf312011-11-04 11:18:15 +010010654 NL80211_CMD_PROBE_CLIENT);
Dan Carpentercb35fba2013-08-14 14:50:01 +030010655 if (!hdr) {
10656 err = -ENOBUFS;
Johannes Berg7f6cf312011-11-04 11:18:15 +010010657 goto free_msg;
10658 }
10659
10660 addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
10661
Hila Gonene35e4d22012-06-27 17:19:42 +030010662 err = rdev_probe_client(rdev, dev, addr, &cookie);
Johannes Berg7f6cf312011-11-04 11:18:15 +010010663 if (err)
10664 goto free_msg;
10665
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020010666 if (nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie,
10667 NL80211_ATTR_PAD))
David S. Miller9360ffd2012-03-29 04:41:26 -040010668 goto nla_put_failure;
Johannes Berg7f6cf312011-11-04 11:18:15 +010010669
10670 genlmsg_end(msg, hdr);
10671
10672 return genlmsg_reply(msg, info);
10673
10674 nla_put_failure:
10675 err = -ENOBUFS;
10676 free_msg:
10677 nlmsg_free(msg);
10678 return err;
10679}
10680
Johannes Berg5e760232011-11-04 11:18:17 +010010681static int nl80211_register_beacons(struct sk_buff *skb, struct genl_info *info)
10682{
10683 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Ben Greear37c73b52012-10-26 14:49:25 -070010684 struct cfg80211_beacon_registration *reg, *nreg;
10685 int rv;
Johannes Berg5e760232011-11-04 11:18:17 +010010686
10687 if (!(rdev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS))
10688 return -EOPNOTSUPP;
10689
Ben Greear37c73b52012-10-26 14:49:25 -070010690 nreg = kzalloc(sizeof(*nreg), GFP_KERNEL);
10691 if (!nreg)
10692 return -ENOMEM;
Johannes Berg5e760232011-11-04 11:18:17 +010010693
Ben Greear37c73b52012-10-26 14:49:25 -070010694 /* First, check if already registered. */
10695 spin_lock_bh(&rdev->beacon_registrations_lock);
10696 list_for_each_entry(reg, &rdev->beacon_registrations, list) {
10697 if (reg->nlportid == info->snd_portid) {
10698 rv = -EALREADY;
10699 goto out_err;
10700 }
10701 }
10702 /* Add it to the list */
10703 nreg->nlportid = info->snd_portid;
10704 list_add(&nreg->list, &rdev->beacon_registrations);
10705
10706 spin_unlock_bh(&rdev->beacon_registrations_lock);
Johannes Berg5e760232011-11-04 11:18:17 +010010707
10708 return 0;
Ben Greear37c73b52012-10-26 14:49:25 -070010709out_err:
10710 spin_unlock_bh(&rdev->beacon_registrations_lock);
10711 kfree(nreg);
10712 return rv;
Johannes Berg5e760232011-11-04 11:18:17 +010010713}
10714
Johannes Berg98104fde2012-06-16 00:19:54 +020010715static int nl80211_start_p2p_device(struct sk_buff *skb, struct genl_info *info)
10716{
10717 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10718 struct wireless_dev *wdev = info->user_ptr[1];
10719 int err;
10720
10721 if (!rdev->ops->start_p2p_device)
10722 return -EOPNOTSUPP;
10723
10724 if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE)
10725 return -EOPNOTSUPP;
10726
Arend Van Spriel73c7da32016-10-20 20:08:22 +010010727 if (wdev_running(wdev))
Johannes Berg98104fde2012-06-16 00:19:54 +020010728 return 0;
10729
Luciano Coelhob6a55012014-02-27 11:07:21 +020010730 if (rfkill_blocked(rdev->rfkill))
10731 return -ERFKILL;
Johannes Berg98104fde2012-06-16 00:19:54 +020010732
Johannes Bergeeb126e2012-10-23 15:16:50 +020010733 err = rdev_start_p2p_device(rdev, wdev);
Johannes Berg98104fde2012-06-16 00:19:54 +020010734 if (err)
10735 return err;
10736
Arend Van Spriel73c7da32016-10-20 20:08:22 +010010737 wdev->is_running = true;
Johannes Berg98104fde2012-06-16 00:19:54 +020010738 rdev->opencount++;
Johannes Berg98104fde2012-06-16 00:19:54 +020010739
10740 return 0;
10741}
10742
10743static int nl80211_stop_p2p_device(struct sk_buff *skb, struct genl_info *info)
10744{
10745 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10746 struct wireless_dev *wdev = info->user_ptr[1];
10747
10748 if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE)
10749 return -EOPNOTSUPP;
10750
10751 if (!rdev->ops->stop_p2p_device)
10752 return -EOPNOTSUPP;
10753
Johannes Bergf9f47522013-03-19 15:04:07 +010010754 cfg80211_stop_p2p_device(rdev, wdev);
Johannes Berg98104fde2012-06-16 00:19:54 +020010755
10756 return 0;
10757}
10758
Ayala Bekercb3b7d82016-09-20 17:31:13 +030010759static int nl80211_start_nan(struct sk_buff *skb, struct genl_info *info)
10760{
10761 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10762 struct wireless_dev *wdev = info->user_ptr[1];
10763 struct cfg80211_nan_conf conf = {};
10764 int err;
10765
10766 if (wdev->iftype != NL80211_IFTYPE_NAN)
10767 return -EOPNOTSUPP;
10768
Johannes Bergeeb04a92016-11-21 13:55:48 +010010769 if (wdev_running(wdev))
Ayala Bekercb3b7d82016-09-20 17:31:13 +030010770 return -EEXIST;
10771
10772 if (rfkill_blocked(rdev->rfkill))
10773 return -ERFKILL;
10774
10775 if (!info->attrs[NL80211_ATTR_NAN_MASTER_PREF])
10776 return -EINVAL;
10777
Ayala Bekercb3b7d82016-09-20 17:31:13 +030010778 conf.master_pref =
10779 nla_get_u8(info->attrs[NL80211_ATTR_NAN_MASTER_PREF]);
10780 if (!conf.master_pref)
10781 return -EINVAL;
10782
Luca Coelho85859892017-02-08 15:00:34 +020010783 if (info->attrs[NL80211_ATTR_BANDS]) {
10784 u32 bands = nla_get_u32(info->attrs[NL80211_ATTR_BANDS]);
10785
10786 if (bands & ~(u32)wdev->wiphy->nan_supported_bands)
10787 return -EOPNOTSUPP;
10788
10789 if (bands && !(bands & BIT(NL80211_BAND_2GHZ)))
10790 return -EINVAL;
10791
10792 conf.bands = bands;
10793 }
Ayala Bekercb3b7d82016-09-20 17:31:13 +030010794
10795 err = rdev_start_nan(rdev, wdev, &conf);
10796 if (err)
10797 return err;
10798
Arend Van Spriel73c7da32016-10-20 20:08:22 +010010799 wdev->is_running = true;
Ayala Bekercb3b7d82016-09-20 17:31:13 +030010800 rdev->opencount++;
10801
10802 return 0;
10803}
10804
10805static int nl80211_stop_nan(struct sk_buff *skb, struct genl_info *info)
10806{
10807 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10808 struct wireless_dev *wdev = info->user_ptr[1];
10809
10810 if (wdev->iftype != NL80211_IFTYPE_NAN)
10811 return -EOPNOTSUPP;
10812
10813 cfg80211_stop_nan(rdev, wdev);
10814
10815 return 0;
10816}
10817
Ayala Bekera442b762016-09-20 17:31:15 +030010818static int validate_nan_filter(struct nlattr *filter_attr)
10819{
10820 struct nlattr *attr;
10821 int len = 0, n_entries = 0, rem;
10822
10823 nla_for_each_nested(attr, filter_attr, rem) {
10824 len += nla_len(attr);
10825 n_entries++;
10826 }
10827
10828 if (len >= U8_MAX)
10829 return -EINVAL;
10830
10831 return n_entries;
10832}
10833
10834static int handle_nan_filter(struct nlattr *attr_filter,
10835 struct cfg80211_nan_func *func,
10836 bool tx)
10837{
10838 struct nlattr *attr;
10839 int n_entries, rem, i;
10840 struct cfg80211_nan_func_filter *filter;
10841
10842 n_entries = validate_nan_filter(attr_filter);
10843 if (n_entries < 0)
10844 return n_entries;
10845
10846 BUILD_BUG_ON(sizeof(*func->rx_filters) != sizeof(*func->tx_filters));
10847
10848 filter = kcalloc(n_entries, sizeof(*func->rx_filters), GFP_KERNEL);
10849 if (!filter)
10850 return -ENOMEM;
10851
10852 i = 0;
10853 nla_for_each_nested(attr, attr_filter, rem) {
Thomas Grafb15ca182016-10-26 10:53:16 +020010854 filter[i].filter = nla_memdup(attr, GFP_KERNEL);
Ayala Bekera442b762016-09-20 17:31:15 +030010855 filter[i].len = nla_len(attr);
10856 i++;
10857 }
10858 if (tx) {
10859 func->num_tx_filters = n_entries;
10860 func->tx_filters = filter;
10861 } else {
10862 func->num_rx_filters = n_entries;
10863 func->rx_filters = filter;
10864 }
10865
10866 return 0;
10867}
10868
10869static int nl80211_nan_add_func(struct sk_buff *skb,
10870 struct genl_info *info)
10871{
10872 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10873 struct wireless_dev *wdev = info->user_ptr[1];
10874 struct nlattr *tb[NUM_NL80211_NAN_FUNC_ATTR], *func_attr;
10875 struct cfg80211_nan_func *func;
10876 struct sk_buff *msg = NULL;
10877 void *hdr = NULL;
10878 int err = 0;
10879
10880 if (wdev->iftype != NL80211_IFTYPE_NAN)
10881 return -EOPNOTSUPP;
10882
Arend Van Spriel73c7da32016-10-20 20:08:22 +010010883 if (!wdev_running(wdev))
Ayala Bekera442b762016-09-20 17:31:15 +030010884 return -ENOTCONN;
10885
10886 if (!info->attrs[NL80211_ATTR_NAN_FUNC])
10887 return -EINVAL;
10888
10889 if (wdev->owner_nlportid &&
10890 wdev->owner_nlportid != info->snd_portid)
10891 return -ENOTCONN;
10892
Johannes Bergbfe2c7b2016-10-26 14:42:21 +020010893 err = nla_parse_nested(tb, NL80211_NAN_FUNC_ATTR_MAX,
10894 info->attrs[NL80211_ATTR_NAN_FUNC],
10895 nl80211_nan_func_policy);
Ayala Bekera442b762016-09-20 17:31:15 +030010896 if (err)
10897 return err;
10898
10899 func = kzalloc(sizeof(*func), GFP_KERNEL);
10900 if (!func)
10901 return -ENOMEM;
10902
10903 func->cookie = wdev->wiphy->cookie_counter++;
10904
10905 if (!tb[NL80211_NAN_FUNC_TYPE] ||
10906 nla_get_u8(tb[NL80211_NAN_FUNC_TYPE]) > NL80211_NAN_FUNC_MAX_TYPE) {
10907 err = -EINVAL;
10908 goto out;
10909 }
10910
10911
10912 func->type = nla_get_u8(tb[NL80211_NAN_FUNC_TYPE]);
10913
10914 if (!tb[NL80211_NAN_FUNC_SERVICE_ID]) {
10915 err = -EINVAL;
10916 goto out;
10917 }
10918
10919 memcpy(func->service_id, nla_data(tb[NL80211_NAN_FUNC_SERVICE_ID]),
10920 sizeof(func->service_id));
10921
10922 func->close_range =
10923 nla_get_flag(tb[NL80211_NAN_FUNC_CLOSE_RANGE]);
10924
10925 if (tb[NL80211_NAN_FUNC_SERVICE_INFO]) {
10926 func->serv_spec_info_len =
10927 nla_len(tb[NL80211_NAN_FUNC_SERVICE_INFO]);
10928 func->serv_spec_info =
10929 kmemdup(nla_data(tb[NL80211_NAN_FUNC_SERVICE_INFO]),
10930 func->serv_spec_info_len,
10931 GFP_KERNEL);
10932 if (!func->serv_spec_info) {
10933 err = -ENOMEM;
10934 goto out;
10935 }
10936 }
10937
10938 if (tb[NL80211_NAN_FUNC_TTL])
10939 func->ttl = nla_get_u32(tb[NL80211_NAN_FUNC_TTL]);
10940
10941 switch (func->type) {
10942 case NL80211_NAN_FUNC_PUBLISH:
10943 if (!tb[NL80211_NAN_FUNC_PUBLISH_TYPE]) {
10944 err = -EINVAL;
10945 goto out;
10946 }
10947
10948 func->publish_type =
10949 nla_get_u8(tb[NL80211_NAN_FUNC_PUBLISH_TYPE]);
10950 func->publish_bcast =
10951 nla_get_flag(tb[NL80211_NAN_FUNC_PUBLISH_BCAST]);
10952
10953 if ((!(func->publish_type & NL80211_NAN_SOLICITED_PUBLISH)) &&
10954 func->publish_bcast) {
10955 err = -EINVAL;
10956 goto out;
10957 }
10958 break;
10959 case NL80211_NAN_FUNC_SUBSCRIBE:
10960 func->subscribe_active =
10961 nla_get_flag(tb[NL80211_NAN_FUNC_SUBSCRIBE_ACTIVE]);
10962 break;
10963 case NL80211_NAN_FUNC_FOLLOW_UP:
10964 if (!tb[NL80211_NAN_FUNC_FOLLOW_UP_ID] ||
10965 !tb[NL80211_NAN_FUNC_FOLLOW_UP_REQ_ID]) {
10966 err = -EINVAL;
10967 goto out;
10968 }
10969
10970 func->followup_id =
10971 nla_get_u8(tb[NL80211_NAN_FUNC_FOLLOW_UP_ID]);
10972 func->followup_reqid =
10973 nla_get_u8(tb[NL80211_NAN_FUNC_FOLLOW_UP_REQ_ID]);
10974 memcpy(func->followup_dest.addr,
10975 nla_data(tb[NL80211_NAN_FUNC_FOLLOW_UP_DEST]),
10976 sizeof(func->followup_dest.addr));
10977 if (func->ttl) {
10978 err = -EINVAL;
10979 goto out;
10980 }
10981 break;
10982 default:
10983 err = -EINVAL;
10984 goto out;
10985 }
10986
10987 if (tb[NL80211_NAN_FUNC_SRF]) {
10988 struct nlattr *srf_tb[NUM_NL80211_NAN_SRF_ATTR];
10989
Johannes Bergbfe2c7b2016-10-26 14:42:21 +020010990 err = nla_parse_nested(srf_tb, NL80211_NAN_SRF_ATTR_MAX,
10991 tb[NL80211_NAN_FUNC_SRF],
10992 nl80211_nan_srf_policy);
Ayala Bekera442b762016-09-20 17:31:15 +030010993 if (err)
10994 goto out;
10995
10996 func->srf_include =
10997 nla_get_flag(srf_tb[NL80211_NAN_SRF_INCLUDE]);
10998
10999 if (srf_tb[NL80211_NAN_SRF_BF]) {
11000 if (srf_tb[NL80211_NAN_SRF_MAC_ADDRS] ||
11001 !srf_tb[NL80211_NAN_SRF_BF_IDX]) {
11002 err = -EINVAL;
11003 goto out;
11004 }
11005
11006 func->srf_bf_len =
11007 nla_len(srf_tb[NL80211_NAN_SRF_BF]);
11008 func->srf_bf =
11009 kmemdup(nla_data(srf_tb[NL80211_NAN_SRF_BF]),
11010 func->srf_bf_len, GFP_KERNEL);
11011 if (!func->srf_bf) {
11012 err = -ENOMEM;
11013 goto out;
11014 }
11015
11016 func->srf_bf_idx =
11017 nla_get_u8(srf_tb[NL80211_NAN_SRF_BF_IDX]);
11018 } else {
11019 struct nlattr *attr, *mac_attr =
11020 srf_tb[NL80211_NAN_SRF_MAC_ADDRS];
11021 int n_entries, rem, i = 0;
11022
11023 if (!mac_attr) {
11024 err = -EINVAL;
11025 goto out;
11026 }
11027
11028 n_entries = validate_acl_mac_addrs(mac_attr);
11029 if (n_entries <= 0) {
11030 err = -EINVAL;
11031 goto out;
11032 }
11033
11034 func->srf_num_macs = n_entries;
11035 func->srf_macs =
11036 kzalloc(sizeof(*func->srf_macs) * n_entries,
11037 GFP_KERNEL);
11038 if (!func->srf_macs) {
11039 err = -ENOMEM;
11040 goto out;
11041 }
11042
11043 nla_for_each_nested(attr, mac_attr, rem)
11044 memcpy(func->srf_macs[i++].addr, nla_data(attr),
11045 sizeof(*func->srf_macs));
11046 }
11047 }
11048
11049 if (tb[NL80211_NAN_FUNC_TX_MATCH_FILTER]) {
11050 err = handle_nan_filter(tb[NL80211_NAN_FUNC_TX_MATCH_FILTER],
11051 func, true);
11052 if (err)
11053 goto out;
11054 }
11055
11056 if (tb[NL80211_NAN_FUNC_RX_MATCH_FILTER]) {
11057 err = handle_nan_filter(tb[NL80211_NAN_FUNC_RX_MATCH_FILTER],
11058 func, false);
11059 if (err)
11060 goto out;
11061 }
11062
11063 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
11064 if (!msg) {
11065 err = -ENOMEM;
11066 goto out;
11067 }
11068
11069 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
11070 NL80211_CMD_ADD_NAN_FUNCTION);
11071 /* This can't really happen - we just allocated 4KB */
11072 if (WARN_ON(!hdr)) {
11073 err = -ENOMEM;
11074 goto out;
11075 }
11076
11077 err = rdev_add_nan_func(rdev, wdev, func);
11078out:
11079 if (err < 0) {
11080 cfg80211_free_nan_func(func);
11081 nlmsg_free(msg);
11082 return err;
11083 }
11084
11085 /* propagate the instance id and cookie to userspace */
11086 if (nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, func->cookie,
11087 NL80211_ATTR_PAD))
11088 goto nla_put_failure;
11089
11090 func_attr = nla_nest_start(msg, NL80211_ATTR_NAN_FUNC);
11091 if (!func_attr)
11092 goto nla_put_failure;
11093
11094 if (nla_put_u8(msg, NL80211_NAN_FUNC_INSTANCE_ID,
11095 func->instance_id))
11096 goto nla_put_failure;
11097
11098 nla_nest_end(msg, func_attr);
11099
11100 genlmsg_end(msg, hdr);
11101 return genlmsg_reply(msg, info);
11102
11103nla_put_failure:
11104 nlmsg_free(msg);
11105 return -ENOBUFS;
11106}
11107
11108static int nl80211_nan_del_func(struct sk_buff *skb,
11109 struct genl_info *info)
11110{
11111 struct cfg80211_registered_device *rdev = info->user_ptr[0];
11112 struct wireless_dev *wdev = info->user_ptr[1];
11113 u64 cookie;
11114
11115 if (wdev->iftype != NL80211_IFTYPE_NAN)
11116 return -EOPNOTSUPP;
11117
Arend Van Spriel73c7da32016-10-20 20:08:22 +010011118 if (!wdev_running(wdev))
Ayala Bekera442b762016-09-20 17:31:15 +030011119 return -ENOTCONN;
11120
11121 if (!info->attrs[NL80211_ATTR_COOKIE])
11122 return -EINVAL;
11123
11124 if (wdev->owner_nlportid &&
11125 wdev->owner_nlportid != info->snd_portid)
11126 return -ENOTCONN;
11127
11128 cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]);
11129
11130 rdev_del_nan_func(rdev, wdev, cookie);
11131
11132 return 0;
11133}
11134
Ayala Bekera5a9dcf2016-09-20 17:31:16 +030011135static int nl80211_nan_change_config(struct sk_buff *skb,
11136 struct genl_info *info)
11137{
11138 struct cfg80211_registered_device *rdev = info->user_ptr[0];
11139 struct wireless_dev *wdev = info->user_ptr[1];
11140 struct cfg80211_nan_conf conf = {};
11141 u32 changed = 0;
11142
11143 if (wdev->iftype != NL80211_IFTYPE_NAN)
11144 return -EOPNOTSUPP;
11145
Arend Van Spriel73c7da32016-10-20 20:08:22 +010011146 if (!wdev_running(wdev))
Ayala Bekera5a9dcf2016-09-20 17:31:16 +030011147 return -ENOTCONN;
11148
11149 if (info->attrs[NL80211_ATTR_NAN_MASTER_PREF]) {
11150 conf.master_pref =
11151 nla_get_u8(info->attrs[NL80211_ATTR_NAN_MASTER_PREF]);
11152 if (conf.master_pref <= 1 || conf.master_pref == 255)
11153 return -EINVAL;
11154
11155 changed |= CFG80211_NAN_CONF_CHANGED_PREF;
11156 }
11157
Luca Coelho85859892017-02-08 15:00:34 +020011158 if (info->attrs[NL80211_ATTR_BANDS]) {
11159 u32 bands = nla_get_u32(info->attrs[NL80211_ATTR_BANDS]);
11160
11161 if (bands & ~(u32)wdev->wiphy->nan_supported_bands)
11162 return -EOPNOTSUPP;
11163
11164 if (bands && !(bands & BIT(NL80211_BAND_2GHZ)))
11165 return -EINVAL;
11166
11167 conf.bands = bands;
11168 changed |= CFG80211_NAN_CONF_CHANGED_BANDS;
Ayala Bekera5a9dcf2016-09-20 17:31:16 +030011169 }
11170
11171 if (!changed)
11172 return -EINVAL;
11173
11174 return rdev_nan_change_conf(rdev, wdev, &conf, changed);
11175}
11176
Ayala Beker50bcd312016-09-20 17:31:17 +030011177void cfg80211_nan_match(struct wireless_dev *wdev,
11178 struct cfg80211_nan_match_params *match, gfp_t gfp)
11179{
11180 struct wiphy *wiphy = wdev->wiphy;
11181 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
11182 struct nlattr *match_attr, *local_func_attr, *peer_func_attr;
11183 struct sk_buff *msg;
11184 void *hdr;
11185
11186 if (WARN_ON(!match->inst_id || !match->peer_inst_id || !match->addr))
11187 return;
11188
11189 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
11190 if (!msg)
11191 return;
11192
11193 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NAN_MATCH);
11194 if (!hdr) {
11195 nlmsg_free(msg);
11196 return;
11197 }
11198
11199 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
11200 (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
11201 wdev->netdev->ifindex)) ||
11202 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
11203 NL80211_ATTR_PAD))
11204 goto nla_put_failure;
11205
11206 if (nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, match->cookie,
11207 NL80211_ATTR_PAD) ||
11208 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, match->addr))
11209 goto nla_put_failure;
11210
11211 match_attr = nla_nest_start(msg, NL80211_ATTR_NAN_MATCH);
11212 if (!match_attr)
11213 goto nla_put_failure;
11214
11215 local_func_attr = nla_nest_start(msg, NL80211_NAN_MATCH_FUNC_LOCAL);
11216 if (!local_func_attr)
11217 goto nla_put_failure;
11218
11219 if (nla_put_u8(msg, NL80211_NAN_FUNC_INSTANCE_ID, match->inst_id))
11220 goto nla_put_failure;
11221
11222 nla_nest_end(msg, local_func_attr);
11223
11224 peer_func_attr = nla_nest_start(msg, NL80211_NAN_MATCH_FUNC_PEER);
11225 if (!peer_func_attr)
11226 goto nla_put_failure;
11227
11228 if (nla_put_u8(msg, NL80211_NAN_FUNC_TYPE, match->type) ||
11229 nla_put_u8(msg, NL80211_NAN_FUNC_INSTANCE_ID, match->peer_inst_id))
11230 goto nla_put_failure;
11231
11232 if (match->info && match->info_len &&
11233 nla_put(msg, NL80211_NAN_FUNC_SERVICE_INFO, match->info_len,
11234 match->info))
11235 goto nla_put_failure;
11236
11237 nla_nest_end(msg, peer_func_attr);
11238 nla_nest_end(msg, match_attr);
11239 genlmsg_end(msg, hdr);
11240
11241 if (!wdev->owner_nlportid)
11242 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy),
11243 msg, 0, NL80211_MCGRP_NAN, gfp);
11244 else
11245 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg,
11246 wdev->owner_nlportid);
11247
11248 return;
11249
11250nla_put_failure:
11251 nlmsg_free(msg);
11252}
11253EXPORT_SYMBOL(cfg80211_nan_match);
11254
Ayala Beker368e5a72016-09-20 17:31:18 +030011255void cfg80211_nan_func_terminated(struct wireless_dev *wdev,
11256 u8 inst_id,
11257 enum nl80211_nan_func_term_reason reason,
11258 u64 cookie, gfp_t gfp)
11259{
11260 struct wiphy *wiphy = wdev->wiphy;
11261 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
11262 struct sk_buff *msg;
11263 struct nlattr *func_attr;
11264 void *hdr;
11265
11266 if (WARN_ON(!inst_id))
11267 return;
11268
11269 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
11270 if (!msg)
11271 return;
11272
11273 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DEL_NAN_FUNCTION);
11274 if (!hdr) {
11275 nlmsg_free(msg);
11276 return;
11277 }
11278
11279 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
11280 (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
11281 wdev->netdev->ifindex)) ||
11282 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
11283 NL80211_ATTR_PAD))
11284 goto nla_put_failure;
11285
11286 if (nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie,
11287 NL80211_ATTR_PAD))
11288 goto nla_put_failure;
11289
11290 func_attr = nla_nest_start(msg, NL80211_ATTR_NAN_FUNC);
11291 if (!func_attr)
11292 goto nla_put_failure;
11293
11294 if (nla_put_u8(msg, NL80211_NAN_FUNC_INSTANCE_ID, inst_id) ||
11295 nla_put_u8(msg, NL80211_NAN_FUNC_TERM_REASON, reason))
11296 goto nla_put_failure;
11297
11298 nla_nest_end(msg, func_attr);
11299 genlmsg_end(msg, hdr);
11300
11301 if (!wdev->owner_nlportid)
11302 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy),
11303 msg, 0, NL80211_MCGRP_NAN, gfp);
11304 else
11305 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg,
11306 wdev->owner_nlportid);
11307
11308 return;
11309
11310nla_put_failure:
11311 nlmsg_free(msg);
11312}
11313EXPORT_SYMBOL(cfg80211_nan_func_terminated);
11314
Johannes Berg3713b4e2013-02-14 16:19:38 +010011315static int nl80211_get_protocol_features(struct sk_buff *skb,
11316 struct genl_info *info)
11317{
11318 void *hdr;
11319 struct sk_buff *msg;
11320
11321 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
11322 if (!msg)
11323 return -ENOMEM;
11324
11325 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
11326 NL80211_CMD_GET_PROTOCOL_FEATURES);
11327 if (!hdr)
11328 goto nla_put_failure;
11329
11330 if (nla_put_u32(msg, NL80211_ATTR_PROTOCOL_FEATURES,
11331 NL80211_PROTOCOL_FEATURE_SPLIT_WIPHY_DUMP))
11332 goto nla_put_failure;
11333
11334 genlmsg_end(msg, hdr);
11335 return genlmsg_reply(msg, info);
11336
11337 nla_put_failure:
11338 kfree_skb(msg);
11339 return -ENOBUFS;
11340}
11341
Jouni Malinen355199e2013-02-27 17:14:27 +020011342static int nl80211_update_ft_ies(struct sk_buff *skb, struct genl_info *info)
11343{
11344 struct cfg80211_registered_device *rdev = info->user_ptr[0];
11345 struct cfg80211_update_ft_ies_params ft_params;
11346 struct net_device *dev = info->user_ptr[1];
11347
11348 if (!rdev->ops->update_ft_ies)
11349 return -EOPNOTSUPP;
11350
11351 if (!info->attrs[NL80211_ATTR_MDID] ||
11352 !is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
11353 return -EINVAL;
11354
11355 memset(&ft_params, 0, sizeof(ft_params));
11356 ft_params.md = nla_get_u16(info->attrs[NL80211_ATTR_MDID]);
11357 ft_params.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
11358 ft_params.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
11359
11360 return rdev_update_ft_ies(rdev, dev, &ft_params);
11361}
11362
Arend van Spriel5de17982013-04-18 15:49:00 +020011363static int nl80211_crit_protocol_start(struct sk_buff *skb,
11364 struct genl_info *info)
11365{
11366 struct cfg80211_registered_device *rdev = info->user_ptr[0];
11367 struct wireless_dev *wdev = info->user_ptr[1];
11368 enum nl80211_crit_proto_id proto = NL80211_CRIT_PROTO_UNSPEC;
11369 u16 duration;
11370 int ret;
11371
11372 if (!rdev->ops->crit_proto_start)
11373 return -EOPNOTSUPP;
11374
11375 if (WARN_ON(!rdev->ops->crit_proto_stop))
11376 return -EINVAL;
11377
11378 if (rdev->crit_proto_nlportid)
11379 return -EBUSY;
11380
11381 /* determine protocol if provided */
11382 if (info->attrs[NL80211_ATTR_CRIT_PROT_ID])
11383 proto = nla_get_u16(info->attrs[NL80211_ATTR_CRIT_PROT_ID]);
11384
11385 if (proto >= NUM_NL80211_CRIT_PROTO)
11386 return -EINVAL;
11387
11388 /* timeout must be provided */
11389 if (!info->attrs[NL80211_ATTR_MAX_CRIT_PROT_DURATION])
11390 return -EINVAL;
11391
11392 duration =
11393 nla_get_u16(info->attrs[NL80211_ATTR_MAX_CRIT_PROT_DURATION]);
11394
11395 if (duration > NL80211_CRIT_PROTO_MAX_DURATION)
11396 return -ERANGE;
11397
11398 ret = rdev_crit_proto_start(rdev, wdev, proto, duration);
11399 if (!ret)
11400 rdev->crit_proto_nlportid = info->snd_portid;
11401
11402 return ret;
11403}
11404
11405static int nl80211_crit_protocol_stop(struct sk_buff *skb,
11406 struct genl_info *info)
11407{
11408 struct cfg80211_registered_device *rdev = info->user_ptr[0];
11409 struct wireless_dev *wdev = info->user_ptr[1];
11410
11411 if (!rdev->ops->crit_proto_stop)
11412 return -EOPNOTSUPP;
11413
11414 if (rdev->crit_proto_nlportid) {
11415 rdev->crit_proto_nlportid = 0;
11416 rdev_crit_proto_stop(rdev, wdev);
11417 }
11418 return 0;
11419}
11420
Johannes Bergad7e7182013-11-13 13:37:47 +010011421static int nl80211_vendor_cmd(struct sk_buff *skb, struct genl_info *info)
11422{
11423 struct cfg80211_registered_device *rdev = info->user_ptr[0];
11424 struct wireless_dev *wdev =
11425 __cfg80211_wdev_from_attrs(genl_info_net(info), info->attrs);
11426 int i, err;
11427 u32 vid, subcmd;
11428
11429 if (!rdev->wiphy.vendor_commands)
11430 return -EOPNOTSUPP;
11431
11432 if (IS_ERR(wdev)) {
11433 err = PTR_ERR(wdev);
11434 if (err != -EINVAL)
11435 return err;
11436 wdev = NULL;
11437 } else if (wdev->wiphy != &rdev->wiphy) {
11438 return -EINVAL;
11439 }
11440
11441 if (!info->attrs[NL80211_ATTR_VENDOR_ID] ||
11442 !info->attrs[NL80211_ATTR_VENDOR_SUBCMD])
11443 return -EINVAL;
11444
11445 vid = nla_get_u32(info->attrs[NL80211_ATTR_VENDOR_ID]);
11446 subcmd = nla_get_u32(info->attrs[NL80211_ATTR_VENDOR_SUBCMD]);
11447 for (i = 0; i < rdev->wiphy.n_vendor_commands; i++) {
11448 const struct wiphy_vendor_command *vcmd;
11449 void *data = NULL;
11450 int len = 0;
11451
11452 vcmd = &rdev->wiphy.vendor_commands[i];
11453
11454 if (vcmd->info.vendor_id != vid || vcmd->info.subcmd != subcmd)
11455 continue;
11456
11457 if (vcmd->flags & (WIPHY_VENDOR_CMD_NEED_WDEV |
11458 WIPHY_VENDOR_CMD_NEED_NETDEV)) {
11459 if (!wdev)
11460 return -EINVAL;
11461 if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_NETDEV &&
11462 !wdev->netdev)
11463 return -EINVAL;
11464
11465 if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_RUNNING) {
Arend Van Spriel73c7da32016-10-20 20:08:22 +010011466 if (!wdev_running(wdev))
Johannes Bergad7e7182013-11-13 13:37:47 +010011467 return -ENETDOWN;
11468 }
Johannes Berg7bdbe402015-08-15 22:39:49 +030011469
11470 if (!vcmd->doit)
11471 return -EOPNOTSUPP;
Johannes Bergad7e7182013-11-13 13:37:47 +010011472 } else {
11473 wdev = NULL;
11474 }
11475
11476 if (info->attrs[NL80211_ATTR_VENDOR_DATA]) {
11477 data = nla_data(info->attrs[NL80211_ATTR_VENDOR_DATA]);
11478 len = nla_len(info->attrs[NL80211_ATTR_VENDOR_DATA]);
11479 }
11480
11481 rdev->cur_cmd_info = info;
11482 err = rdev->wiphy.vendor_commands[i].doit(&rdev->wiphy, wdev,
11483 data, len);
11484 rdev->cur_cmd_info = NULL;
11485 return err;
11486 }
11487
11488 return -EOPNOTSUPP;
11489}
11490
Johannes Berg7bdbe402015-08-15 22:39:49 +030011491static int nl80211_prepare_vendor_dump(struct sk_buff *skb,
11492 struct netlink_callback *cb,
11493 struct cfg80211_registered_device **rdev,
11494 struct wireless_dev **wdev)
11495{
Johannes Bergc90c39d2016-10-24 14:40:01 +020011496 struct nlattr **attrbuf = genl_family_attrbuf(&nl80211_fam);
Johannes Berg7bdbe402015-08-15 22:39:49 +030011497 u32 vid, subcmd;
11498 unsigned int i;
11499 int vcmd_idx = -1;
11500 int err;
11501 void *data = NULL;
11502 unsigned int data_len = 0;
11503
Johannes Berg7bdbe402015-08-15 22:39:49 +030011504 if (cb->args[0]) {
11505 /* subtract the 1 again here */
11506 struct wiphy *wiphy = wiphy_idx_to_wiphy(cb->args[0] - 1);
11507 struct wireless_dev *tmp;
11508
Johannes Bergea90e0d2017-03-15 14:26:04 +010011509 if (!wiphy)
11510 return -ENODEV;
Johannes Berg7bdbe402015-08-15 22:39:49 +030011511 *rdev = wiphy_to_rdev(wiphy);
11512 *wdev = NULL;
11513
11514 if (cb->args[1]) {
Johannes Berg53873f12016-05-03 16:52:04 +030011515 list_for_each_entry(tmp, &wiphy->wdev_list, list) {
Johannes Berg7bdbe402015-08-15 22:39:49 +030011516 if (tmp->identifier == cb->args[1] - 1) {
11517 *wdev = tmp;
11518 break;
11519 }
11520 }
11521 }
11522
11523 /* keep rtnl locked in successful case */
11524 return 0;
11525 }
11526
11527 err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize,
Johannes Bergc90c39d2016-10-24 14:40:01 +020011528 attrbuf, nl80211_fam.maxattr, nl80211_policy);
Johannes Berg7bdbe402015-08-15 22:39:49 +030011529 if (err)
Johannes Bergea90e0d2017-03-15 14:26:04 +010011530 return err;
Johannes Berg7bdbe402015-08-15 22:39:49 +030011531
Johannes Bergc90c39d2016-10-24 14:40:01 +020011532 if (!attrbuf[NL80211_ATTR_VENDOR_ID] ||
Johannes Bergea90e0d2017-03-15 14:26:04 +010011533 !attrbuf[NL80211_ATTR_VENDOR_SUBCMD])
11534 return -EINVAL;
Johannes Berg7bdbe402015-08-15 22:39:49 +030011535
Johannes Bergc90c39d2016-10-24 14:40:01 +020011536 *wdev = __cfg80211_wdev_from_attrs(sock_net(skb->sk), attrbuf);
Johannes Berg7bdbe402015-08-15 22:39:49 +030011537 if (IS_ERR(*wdev))
11538 *wdev = NULL;
11539
Johannes Bergc90c39d2016-10-24 14:40:01 +020011540 *rdev = __cfg80211_rdev_from_attrs(sock_net(skb->sk), attrbuf);
Johannes Bergea90e0d2017-03-15 14:26:04 +010011541 if (IS_ERR(*rdev))
11542 return PTR_ERR(*rdev);
Johannes Berg7bdbe402015-08-15 22:39:49 +030011543
Johannes Bergc90c39d2016-10-24 14:40:01 +020011544 vid = nla_get_u32(attrbuf[NL80211_ATTR_VENDOR_ID]);
11545 subcmd = nla_get_u32(attrbuf[NL80211_ATTR_VENDOR_SUBCMD]);
Johannes Berg7bdbe402015-08-15 22:39:49 +030011546
11547 for (i = 0; i < (*rdev)->wiphy.n_vendor_commands; i++) {
11548 const struct wiphy_vendor_command *vcmd;
11549
11550 vcmd = &(*rdev)->wiphy.vendor_commands[i];
11551
11552 if (vcmd->info.vendor_id != vid || vcmd->info.subcmd != subcmd)
11553 continue;
11554
Johannes Bergea90e0d2017-03-15 14:26:04 +010011555 if (!vcmd->dumpit)
11556 return -EOPNOTSUPP;
Johannes Berg7bdbe402015-08-15 22:39:49 +030011557
11558 vcmd_idx = i;
11559 break;
11560 }
11561
Johannes Bergea90e0d2017-03-15 14:26:04 +010011562 if (vcmd_idx < 0)
11563 return -EOPNOTSUPP;
Johannes Berg7bdbe402015-08-15 22:39:49 +030011564
Johannes Bergc90c39d2016-10-24 14:40:01 +020011565 if (attrbuf[NL80211_ATTR_VENDOR_DATA]) {
11566 data = nla_data(attrbuf[NL80211_ATTR_VENDOR_DATA]);
11567 data_len = nla_len(attrbuf[NL80211_ATTR_VENDOR_DATA]);
Johannes Berg7bdbe402015-08-15 22:39:49 +030011568 }
11569
11570 /* 0 is the first index - add 1 to parse only once */
11571 cb->args[0] = (*rdev)->wiphy_idx + 1;
11572 /* add 1 to know if it was NULL */
11573 cb->args[1] = *wdev ? (*wdev)->identifier + 1 : 0;
11574 cb->args[2] = vcmd_idx;
11575 cb->args[3] = (unsigned long)data;
11576 cb->args[4] = data_len;
11577
11578 /* keep rtnl locked in successful case */
11579 return 0;
Johannes Berg7bdbe402015-08-15 22:39:49 +030011580}
11581
11582static int nl80211_vendor_cmd_dump(struct sk_buff *skb,
11583 struct netlink_callback *cb)
11584{
11585 struct cfg80211_registered_device *rdev;
11586 struct wireless_dev *wdev;
11587 unsigned int vcmd_idx;
11588 const struct wiphy_vendor_command *vcmd;
11589 void *data;
11590 int data_len;
11591 int err;
11592 struct nlattr *vendor_data;
11593
Johannes Bergea90e0d2017-03-15 14:26:04 +010011594 rtnl_lock();
Johannes Berg7bdbe402015-08-15 22:39:49 +030011595 err = nl80211_prepare_vendor_dump(skb, cb, &rdev, &wdev);
11596 if (err)
Johannes Bergea90e0d2017-03-15 14:26:04 +010011597 goto out;
Johannes Berg7bdbe402015-08-15 22:39:49 +030011598
11599 vcmd_idx = cb->args[2];
11600 data = (void *)cb->args[3];
11601 data_len = cb->args[4];
11602 vcmd = &rdev->wiphy.vendor_commands[vcmd_idx];
11603
11604 if (vcmd->flags & (WIPHY_VENDOR_CMD_NEED_WDEV |
11605 WIPHY_VENDOR_CMD_NEED_NETDEV)) {
Johannes Bergea90e0d2017-03-15 14:26:04 +010011606 if (!wdev) {
11607 err = -EINVAL;
11608 goto out;
11609 }
Johannes Berg7bdbe402015-08-15 22:39:49 +030011610 if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_NETDEV &&
Johannes Bergea90e0d2017-03-15 14:26:04 +010011611 !wdev->netdev) {
11612 err = -EINVAL;
11613 goto out;
11614 }
Johannes Berg7bdbe402015-08-15 22:39:49 +030011615
11616 if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_RUNNING) {
Johannes Bergea90e0d2017-03-15 14:26:04 +010011617 if (!wdev_running(wdev)) {
11618 err = -ENETDOWN;
11619 goto out;
11620 }
Johannes Berg7bdbe402015-08-15 22:39:49 +030011621 }
11622 }
11623
11624 while (1) {
11625 void *hdr = nl80211hdr_put(skb, NETLINK_CB(cb->skb).portid,
11626 cb->nlh->nlmsg_seq, NLM_F_MULTI,
11627 NL80211_CMD_VENDOR);
11628 if (!hdr)
11629 break;
11630
11631 if (nla_put_u32(skb, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020011632 (wdev && nla_put_u64_64bit(skb, NL80211_ATTR_WDEV,
11633 wdev_id(wdev),
11634 NL80211_ATTR_PAD))) {
Johannes Berg7bdbe402015-08-15 22:39:49 +030011635 genlmsg_cancel(skb, hdr);
11636 break;
11637 }
11638
11639 vendor_data = nla_nest_start(skb, NL80211_ATTR_VENDOR_DATA);
11640 if (!vendor_data) {
11641 genlmsg_cancel(skb, hdr);
11642 break;
11643 }
11644
11645 err = vcmd->dumpit(&rdev->wiphy, wdev, skb, data, data_len,
11646 (unsigned long *)&cb->args[5]);
11647 nla_nest_end(skb, vendor_data);
11648
11649 if (err == -ENOBUFS || err == -ENOENT) {
11650 genlmsg_cancel(skb, hdr);
11651 break;
11652 } else if (err) {
11653 genlmsg_cancel(skb, hdr);
11654 goto out;
11655 }
11656
11657 genlmsg_end(skb, hdr);
11658 }
11659
11660 err = skb->len;
11661 out:
11662 rtnl_unlock();
11663 return err;
11664}
11665
Johannes Bergad7e7182013-11-13 13:37:47 +010011666struct sk_buff *__cfg80211_alloc_reply_skb(struct wiphy *wiphy,
11667 enum nl80211_commands cmd,
11668 enum nl80211_attrs attr,
11669 int approxlen)
11670{
Zhao, Gangf26cbf42014-04-21 12:53:03 +080011671 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Bergad7e7182013-11-13 13:37:47 +010011672
11673 if (WARN_ON(!rdev->cur_cmd_info))
11674 return NULL;
11675
Ahmad Kholaif6c09e792015-02-26 15:26:53 +020011676 return __cfg80211_alloc_vendor_skb(rdev, NULL, approxlen,
Johannes Bergad7e7182013-11-13 13:37:47 +010011677 rdev->cur_cmd_info->snd_portid,
11678 rdev->cur_cmd_info->snd_seq,
Johannes Berg567ffc32013-12-18 14:43:31 +010011679 cmd, attr, NULL, GFP_KERNEL);
Johannes Bergad7e7182013-11-13 13:37:47 +010011680}
11681EXPORT_SYMBOL(__cfg80211_alloc_reply_skb);
11682
11683int cfg80211_vendor_cmd_reply(struct sk_buff *skb)
11684{
11685 struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0];
11686 void *hdr = ((void **)skb->cb)[1];
11687 struct nlattr *data = ((void **)skb->cb)[2];
11688
Johannes Bergbd8c78e2014-07-30 14:55:26 +020011689 /* clear CB data for netlink core to own from now on */
11690 memset(skb->cb, 0, sizeof(skb->cb));
11691
Johannes Bergad7e7182013-11-13 13:37:47 +010011692 if (WARN_ON(!rdev->cur_cmd_info)) {
11693 kfree_skb(skb);
11694 return -EINVAL;
11695 }
11696
11697 nla_nest_end(skb, data);
11698 genlmsg_end(skb, hdr);
11699 return genlmsg_reply(skb, rdev->cur_cmd_info);
11700}
11701EXPORT_SYMBOL_GPL(cfg80211_vendor_cmd_reply);
11702
Kyeyoon Parkfa9ffc72013-12-16 23:01:30 -080011703static int nl80211_set_qos_map(struct sk_buff *skb,
11704 struct genl_info *info)
11705{
11706 struct cfg80211_registered_device *rdev = info->user_ptr[0];
11707 struct cfg80211_qos_map *qos_map = NULL;
11708 struct net_device *dev = info->user_ptr[1];
11709 u8 *pos, len, num_des, des_len, des;
11710 int ret;
11711
11712 if (!rdev->ops->set_qos_map)
11713 return -EOPNOTSUPP;
11714
11715 if (info->attrs[NL80211_ATTR_QOS_MAP]) {
11716 pos = nla_data(info->attrs[NL80211_ATTR_QOS_MAP]);
11717 len = nla_len(info->attrs[NL80211_ATTR_QOS_MAP]);
11718
11719 if (len % 2 || len < IEEE80211_QOS_MAP_LEN_MIN ||
11720 len > IEEE80211_QOS_MAP_LEN_MAX)
11721 return -EINVAL;
11722
11723 qos_map = kzalloc(sizeof(struct cfg80211_qos_map), GFP_KERNEL);
11724 if (!qos_map)
11725 return -ENOMEM;
11726
11727 num_des = (len - IEEE80211_QOS_MAP_LEN_MIN) >> 1;
11728 if (num_des) {
11729 des_len = num_des *
11730 sizeof(struct cfg80211_dscp_exception);
11731 memcpy(qos_map->dscp_exception, pos, des_len);
11732 qos_map->num_des = num_des;
11733 for (des = 0; des < num_des; des++) {
11734 if (qos_map->dscp_exception[des].up > 7) {
11735 kfree(qos_map);
11736 return -EINVAL;
11737 }
11738 }
11739 pos += des_len;
11740 }
11741 memcpy(qos_map->up, pos, IEEE80211_QOS_MAP_LEN_MIN);
11742 }
11743
11744 wdev_lock(dev->ieee80211_ptr);
11745 ret = nl80211_key_allowed(dev->ieee80211_ptr);
11746 if (!ret)
11747 ret = rdev_set_qos_map(rdev, dev, qos_map);
11748 wdev_unlock(dev->ieee80211_ptr);
11749
11750 kfree(qos_map);
11751 return ret;
11752}
11753
Johannes Berg960d01a2014-09-09 22:55:35 +030011754static int nl80211_add_tx_ts(struct sk_buff *skb, struct genl_info *info)
11755{
11756 struct cfg80211_registered_device *rdev = info->user_ptr[0];
11757 struct net_device *dev = info->user_ptr[1];
11758 struct wireless_dev *wdev = dev->ieee80211_ptr;
11759 const u8 *peer;
11760 u8 tsid, up;
11761 u16 admitted_time = 0;
11762 int err;
11763
Johannes Berg723e73a2014-10-22 09:25:06 +020011764 if (!(rdev->wiphy.features & NL80211_FEATURE_SUPPORTS_WMM_ADMISSION))
Johannes Berg960d01a2014-09-09 22:55:35 +030011765 return -EOPNOTSUPP;
11766
11767 if (!info->attrs[NL80211_ATTR_TSID] || !info->attrs[NL80211_ATTR_MAC] ||
11768 !info->attrs[NL80211_ATTR_USER_PRIO])
11769 return -EINVAL;
11770
11771 tsid = nla_get_u8(info->attrs[NL80211_ATTR_TSID]);
11772 if (tsid >= IEEE80211_NUM_TIDS)
11773 return -EINVAL;
11774
11775 up = nla_get_u8(info->attrs[NL80211_ATTR_USER_PRIO]);
11776 if (up >= IEEE80211_NUM_UPS)
11777 return -EINVAL;
11778
11779 /* WMM uses TIDs 0-7 even for TSPEC */
Johannes Berg723e73a2014-10-22 09:25:06 +020011780 if (tsid >= IEEE80211_FIRST_TSPEC_TSID) {
Johannes Berg960d01a2014-09-09 22:55:35 +030011781 /* TODO: handle 802.11 TSPEC/admission control
Johannes Berg723e73a2014-10-22 09:25:06 +020011782 * need more attributes for that (e.g. BA session requirement);
11783 * change the WMM adminssion test above to allow both then
Johannes Berg960d01a2014-09-09 22:55:35 +030011784 */
11785 return -EINVAL;
11786 }
11787
11788 peer = nla_data(info->attrs[NL80211_ATTR_MAC]);
11789
11790 if (info->attrs[NL80211_ATTR_ADMITTED_TIME]) {
11791 admitted_time =
11792 nla_get_u16(info->attrs[NL80211_ATTR_ADMITTED_TIME]);
11793 if (!admitted_time)
11794 return -EINVAL;
11795 }
11796
11797 wdev_lock(wdev);
11798 switch (wdev->iftype) {
11799 case NL80211_IFTYPE_STATION:
11800 case NL80211_IFTYPE_P2P_CLIENT:
11801 if (wdev->current_bss)
11802 break;
11803 err = -ENOTCONN;
11804 goto out;
11805 default:
11806 err = -EOPNOTSUPP;
11807 goto out;
11808 }
11809
11810 err = rdev_add_tx_ts(rdev, dev, tsid, peer, up, admitted_time);
11811
11812 out:
11813 wdev_unlock(wdev);
11814 return err;
11815}
11816
11817static int nl80211_del_tx_ts(struct sk_buff *skb, struct genl_info *info)
11818{
11819 struct cfg80211_registered_device *rdev = info->user_ptr[0];
11820 struct net_device *dev = info->user_ptr[1];
11821 struct wireless_dev *wdev = dev->ieee80211_ptr;
11822 const u8 *peer;
11823 u8 tsid;
11824 int err;
11825
11826 if (!info->attrs[NL80211_ATTR_TSID] || !info->attrs[NL80211_ATTR_MAC])
11827 return -EINVAL;
11828
11829 tsid = nla_get_u8(info->attrs[NL80211_ATTR_TSID]);
11830 peer = nla_data(info->attrs[NL80211_ATTR_MAC]);
11831
11832 wdev_lock(wdev);
11833 err = rdev_del_tx_ts(rdev, dev, tsid, peer);
11834 wdev_unlock(wdev);
11835
11836 return err;
11837}
11838
Arik Nemtsov1057d352014-11-19 12:54:26 +020011839static int nl80211_tdls_channel_switch(struct sk_buff *skb,
11840 struct genl_info *info)
11841{
11842 struct cfg80211_registered_device *rdev = info->user_ptr[0];
11843 struct net_device *dev = info->user_ptr[1];
11844 struct wireless_dev *wdev = dev->ieee80211_ptr;
11845 struct cfg80211_chan_def chandef = {};
11846 const u8 *addr;
11847 u8 oper_class;
11848 int err;
11849
11850 if (!rdev->ops->tdls_channel_switch ||
11851 !(rdev->wiphy.features & NL80211_FEATURE_TDLS_CHANNEL_SWITCH))
11852 return -EOPNOTSUPP;
11853
11854 switch (dev->ieee80211_ptr->iftype) {
11855 case NL80211_IFTYPE_STATION:
11856 case NL80211_IFTYPE_P2P_CLIENT:
11857 break;
11858 default:
11859 return -EOPNOTSUPP;
11860 }
11861
11862 if (!info->attrs[NL80211_ATTR_MAC] ||
11863 !info->attrs[NL80211_ATTR_OPER_CLASS])
11864 return -EINVAL;
11865
11866 err = nl80211_parse_chandef(rdev, info, &chandef);
11867 if (err)
11868 return err;
11869
11870 /*
11871 * Don't allow wide channels on the 2.4Ghz band, as per IEEE802.11-2012
11872 * section 10.22.6.2.1. Disallow 5/10Mhz channels as well for now, the
11873 * specification is not defined for them.
11874 */
Johannes Berg57fbcce2016-04-12 15:56:15 +020011875 if (chandef.chan->band == NL80211_BAND_2GHZ &&
Arik Nemtsov1057d352014-11-19 12:54:26 +020011876 chandef.width != NL80211_CHAN_WIDTH_20_NOHT &&
11877 chandef.width != NL80211_CHAN_WIDTH_20)
11878 return -EINVAL;
11879
11880 /* we will be active on the TDLS link */
Arik Nemtsov923b3522015-07-08 15:41:44 +030011881 if (!cfg80211_reg_can_beacon_relax(&rdev->wiphy, &chandef,
11882 wdev->iftype))
Arik Nemtsov1057d352014-11-19 12:54:26 +020011883 return -EINVAL;
11884
11885 /* don't allow switching to DFS channels */
11886 if (cfg80211_chandef_dfs_required(wdev->wiphy, &chandef, wdev->iftype))
11887 return -EINVAL;
11888
11889 addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
11890 oper_class = nla_get_u8(info->attrs[NL80211_ATTR_OPER_CLASS]);
11891
11892 wdev_lock(wdev);
11893 err = rdev_tdls_channel_switch(rdev, dev, addr, oper_class, &chandef);
11894 wdev_unlock(wdev);
11895
11896 return err;
11897}
11898
11899static int nl80211_tdls_cancel_channel_switch(struct sk_buff *skb,
11900 struct genl_info *info)
11901{
11902 struct cfg80211_registered_device *rdev = info->user_ptr[0];
11903 struct net_device *dev = info->user_ptr[1];
11904 struct wireless_dev *wdev = dev->ieee80211_ptr;
11905 const u8 *addr;
11906
11907 if (!rdev->ops->tdls_channel_switch ||
11908 !rdev->ops->tdls_cancel_channel_switch ||
11909 !(rdev->wiphy.features & NL80211_FEATURE_TDLS_CHANNEL_SWITCH))
11910 return -EOPNOTSUPP;
11911
11912 switch (dev->ieee80211_ptr->iftype) {
11913 case NL80211_IFTYPE_STATION:
11914 case NL80211_IFTYPE_P2P_CLIENT:
11915 break;
11916 default:
11917 return -EOPNOTSUPP;
11918 }
11919
11920 if (!info->attrs[NL80211_ATTR_MAC])
11921 return -EINVAL;
11922
11923 addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
11924
11925 wdev_lock(wdev);
11926 rdev_tdls_cancel_channel_switch(rdev, dev, addr);
11927 wdev_unlock(wdev);
11928
11929 return 0;
11930}
11931
Michael Braunce0ce132016-10-10 19:12:22 +020011932static int nl80211_set_multicast_to_unicast(struct sk_buff *skb,
11933 struct genl_info *info)
11934{
11935 struct cfg80211_registered_device *rdev = info->user_ptr[0];
11936 struct net_device *dev = info->user_ptr[1];
11937 struct wireless_dev *wdev = dev->ieee80211_ptr;
11938 const struct nlattr *nla;
11939 bool enabled;
11940
Michael Braunce0ce132016-10-10 19:12:22 +020011941 if (!rdev->ops->set_multicast_to_unicast)
11942 return -EOPNOTSUPP;
11943
11944 if (wdev->iftype != NL80211_IFTYPE_AP &&
11945 wdev->iftype != NL80211_IFTYPE_P2P_GO)
11946 return -EOPNOTSUPP;
11947
11948 nla = info->attrs[NL80211_ATTR_MULTICAST_TO_UNICAST_ENABLED];
11949 enabled = nla_get_flag(nla);
11950
11951 return rdev_set_multicast_to_unicast(rdev, dev, enabled);
11952}
11953
Johannes Berg4c476992010-10-04 21:36:35 +020011954#define NL80211_FLAG_NEED_WIPHY 0x01
11955#define NL80211_FLAG_NEED_NETDEV 0x02
11956#define NL80211_FLAG_NEED_RTNL 0x04
Johannes Berg41265712010-10-04 21:14:05 +020011957#define NL80211_FLAG_CHECK_NETDEV_UP 0x08
11958#define NL80211_FLAG_NEED_NETDEV_UP (NL80211_FLAG_NEED_NETDEV |\
11959 NL80211_FLAG_CHECK_NETDEV_UP)
Johannes Berg1bf614e2012-06-15 15:23:36 +020011960#define NL80211_FLAG_NEED_WDEV 0x10
Johannes Berg98104fde2012-06-16 00:19:54 +020011961/* If a netdev is associated, it must be UP, P2P must be started */
Johannes Berg1bf614e2012-06-15 15:23:36 +020011962#define NL80211_FLAG_NEED_WDEV_UP (NL80211_FLAG_NEED_WDEV |\
11963 NL80211_FLAG_CHECK_NETDEV_UP)
Johannes Berg5393b912014-09-10 15:00:16 +030011964#define NL80211_FLAG_CLEAR_SKB 0x20
Johannes Berg4c476992010-10-04 21:36:35 +020011965
Johannes Bergf84f7712013-11-14 17:14:45 +010011966static int nl80211_pre_doit(const struct genl_ops *ops, struct sk_buff *skb,
Johannes Berg4c476992010-10-04 21:36:35 +020011967 struct genl_info *info)
11968{
11969 struct cfg80211_registered_device *rdev;
Johannes Berg89a54e42012-06-15 14:33:17 +020011970 struct wireless_dev *wdev;
Johannes Berg4c476992010-10-04 21:36:35 +020011971 struct net_device *dev;
Johannes Berg4c476992010-10-04 21:36:35 +020011972 bool rtnl = ops->internal_flags & NL80211_FLAG_NEED_RTNL;
11973
11974 if (rtnl)
11975 rtnl_lock();
11976
11977 if (ops->internal_flags & NL80211_FLAG_NEED_WIPHY) {
Johannes Berg4f7eff12012-06-15 14:14:22 +020011978 rdev = cfg80211_get_dev_from_info(genl_info_net(info), info);
Johannes Berg4c476992010-10-04 21:36:35 +020011979 if (IS_ERR(rdev)) {
11980 if (rtnl)
11981 rtnl_unlock();
11982 return PTR_ERR(rdev);
11983 }
11984 info->user_ptr[0] = rdev;
Johannes Berg1bf614e2012-06-15 15:23:36 +020011985 } else if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV ||
11986 ops->internal_flags & NL80211_FLAG_NEED_WDEV) {
Johannes Berg5fe231e2013-05-08 21:45:15 +020011987 ASSERT_RTNL();
11988
Johannes Berg89a54e42012-06-15 14:33:17 +020011989 wdev = __cfg80211_wdev_from_attrs(genl_info_net(info),
11990 info->attrs);
11991 if (IS_ERR(wdev)) {
Johannes Berg4c476992010-10-04 21:36:35 +020011992 if (rtnl)
11993 rtnl_unlock();
Johannes Berg89a54e42012-06-15 14:33:17 +020011994 return PTR_ERR(wdev);
Johannes Berg4c476992010-10-04 21:36:35 +020011995 }
Johannes Berg89a54e42012-06-15 14:33:17 +020011996
Johannes Berg89a54e42012-06-15 14:33:17 +020011997 dev = wdev->netdev;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080011998 rdev = wiphy_to_rdev(wdev->wiphy);
Johannes Berg89a54e42012-06-15 14:33:17 +020011999
Johannes Berg1bf614e2012-06-15 15:23:36 +020012000 if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV) {
12001 if (!dev) {
Johannes Berg1bf614e2012-06-15 15:23:36 +020012002 if (rtnl)
12003 rtnl_unlock();
12004 return -EINVAL;
12005 }
12006
12007 info->user_ptr[1] = dev;
12008 } else {
12009 info->user_ptr[1] = wdev;
Johannes Berg41265712010-10-04 21:14:05 +020012010 }
Johannes Berg89a54e42012-06-15 14:33:17 +020012011
Arend Van Spriel73c7da32016-10-20 20:08:22 +010012012 if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP &&
12013 !wdev_running(wdev)) {
12014 if (rtnl)
12015 rtnl_unlock();
12016 return -ENETDOWN;
Johannes Berg1bf614e2012-06-15 15:23:36 +020012017 }
12018
Arend Van Spriel73c7da32016-10-20 20:08:22 +010012019 if (dev)
12020 dev_hold(dev);
12021
Johannes Berg4c476992010-10-04 21:36:35 +020012022 info->user_ptr[0] = rdev;
Johannes Berg4c476992010-10-04 21:36:35 +020012023 }
12024
12025 return 0;
12026}
12027
Johannes Bergf84f7712013-11-14 17:14:45 +010012028static void nl80211_post_doit(const struct genl_ops *ops, struct sk_buff *skb,
Johannes Berg4c476992010-10-04 21:36:35 +020012029 struct genl_info *info)
12030{
Johannes Berg1bf614e2012-06-15 15:23:36 +020012031 if (info->user_ptr[1]) {
12032 if (ops->internal_flags & NL80211_FLAG_NEED_WDEV) {
12033 struct wireless_dev *wdev = info->user_ptr[1];
12034
12035 if (wdev->netdev)
12036 dev_put(wdev->netdev);
12037 } else {
12038 dev_put(info->user_ptr[1]);
12039 }
12040 }
Johannes Berg5393b912014-09-10 15:00:16 +030012041
Johannes Berg4c476992010-10-04 21:36:35 +020012042 if (ops->internal_flags & NL80211_FLAG_NEED_RTNL)
12043 rtnl_unlock();
Johannes Berg5393b912014-09-10 15:00:16 +030012044
12045 /* If needed, clear the netlink message payload from the SKB
12046 * as it might contain key data that shouldn't stick around on
12047 * the heap after the SKB is freed. The netlink message header
12048 * is still needed for further processing, so leave it intact.
12049 */
12050 if (ops->internal_flags & NL80211_FLAG_CLEAR_SKB) {
12051 struct nlmsghdr *nlh = nlmsg_hdr(skb);
12052
12053 memset(nlmsg_data(nlh), 0, nlmsg_len(nlh));
12054 }
Johannes Berg4c476992010-10-04 21:36:35 +020012055}
12056
Johannes Berg4534de82013-11-14 17:14:46 +010012057static const struct genl_ops nl80211_ops[] = {
Johannes Berg55682962007-09-20 13:09:35 -040012058 {
12059 .cmd = NL80211_CMD_GET_WIPHY,
12060 .doit = nl80211_get_wiphy,
12061 .dumpit = nl80211_dump_wiphy,
Johannes Berg86e8cf92013-06-19 10:57:22 +020012062 .done = nl80211_dump_wiphy_done,
Johannes Berg55682962007-09-20 13:09:35 -040012063 .policy = nl80211_policy,
12064 /* can be retrieved by unprivileged users */
Johannes Berg5fe231e2013-05-08 21:45:15 +020012065 .internal_flags = NL80211_FLAG_NEED_WIPHY |
12066 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -040012067 },
12068 {
12069 .cmd = NL80211_CMD_SET_WIPHY,
12070 .doit = nl80211_set_wiphy,
12071 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012072 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020012073 .internal_flags = NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -040012074 },
12075 {
12076 .cmd = NL80211_CMD_GET_INTERFACE,
12077 .doit = nl80211_get_interface,
12078 .dumpit = nl80211_dump_interface,
12079 .policy = nl80211_policy,
12080 /* can be retrieved by unprivileged users */
Johannes Berg5fe231e2013-05-08 21:45:15 +020012081 .internal_flags = NL80211_FLAG_NEED_WDEV |
12082 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -040012083 },
12084 {
12085 .cmd = NL80211_CMD_SET_INTERFACE,
12086 .doit = nl80211_set_interface,
12087 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012088 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020012089 .internal_flags = NL80211_FLAG_NEED_NETDEV |
12090 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -040012091 },
12092 {
12093 .cmd = NL80211_CMD_NEW_INTERFACE,
12094 .doit = nl80211_new_interface,
12095 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012096 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020012097 .internal_flags = NL80211_FLAG_NEED_WIPHY |
12098 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -040012099 },
12100 {
12101 .cmd = NL80211_CMD_DEL_INTERFACE,
12102 .doit = nl80211_del_interface,
12103 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012104 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg84efbb82012-06-16 00:00:26 +020012105 .internal_flags = NL80211_FLAG_NEED_WDEV |
Johannes Berg4c476992010-10-04 21:36:35 +020012106 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -040012107 },
Johannes Berg41ade002007-12-19 02:03:29 +010012108 {
12109 .cmd = NL80211_CMD_GET_KEY,
12110 .doit = nl80211_get_key,
12111 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012112 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020012113 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020012114 NL80211_FLAG_NEED_RTNL,
Johannes Berg41ade002007-12-19 02:03:29 +010012115 },
12116 {
12117 .cmd = NL80211_CMD_SET_KEY,
12118 .doit = nl80211_set_key,
12119 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012120 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020012121 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg5393b912014-09-10 15:00:16 +030012122 NL80211_FLAG_NEED_RTNL |
12123 NL80211_FLAG_CLEAR_SKB,
Johannes Berg41ade002007-12-19 02:03:29 +010012124 },
12125 {
12126 .cmd = NL80211_CMD_NEW_KEY,
12127 .doit = nl80211_new_key,
12128 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012129 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020012130 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg5393b912014-09-10 15:00:16 +030012131 NL80211_FLAG_NEED_RTNL |
12132 NL80211_FLAG_CLEAR_SKB,
Johannes Berg41ade002007-12-19 02:03:29 +010012133 },
12134 {
12135 .cmd = NL80211_CMD_DEL_KEY,
12136 .doit = nl80211_del_key,
12137 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012138 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020012139 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020012140 NL80211_FLAG_NEED_RTNL,
Johannes Berg41ade002007-12-19 02:03:29 +010012141 },
Johannes Berged1b6cc2007-12-19 02:03:32 +010012142 {
12143 .cmd = NL80211_CMD_SET_BEACON,
12144 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012145 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg88600202012-02-13 15:17:18 +010012146 .doit = nl80211_set_beacon,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020012147 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020012148 NL80211_FLAG_NEED_RTNL,
Johannes Berged1b6cc2007-12-19 02:03:32 +010012149 },
12150 {
Johannes Berg88600202012-02-13 15:17:18 +010012151 .cmd = NL80211_CMD_START_AP,
Johannes Berged1b6cc2007-12-19 02:03:32 +010012152 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012153 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg88600202012-02-13 15:17:18 +010012154 .doit = nl80211_start_ap,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020012155 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020012156 NL80211_FLAG_NEED_RTNL,
Johannes Berged1b6cc2007-12-19 02:03:32 +010012157 },
12158 {
Johannes Berg88600202012-02-13 15:17:18 +010012159 .cmd = NL80211_CMD_STOP_AP,
Johannes Berged1b6cc2007-12-19 02:03:32 +010012160 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012161 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg88600202012-02-13 15:17:18 +010012162 .doit = nl80211_stop_ap,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020012163 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020012164 NL80211_FLAG_NEED_RTNL,
Johannes Berged1b6cc2007-12-19 02:03:32 +010012165 },
Johannes Berg5727ef12007-12-19 02:03:34 +010012166 {
12167 .cmd = NL80211_CMD_GET_STATION,
12168 .doit = nl80211_get_station,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010012169 .dumpit = nl80211_dump_station,
Johannes Berg5727ef12007-12-19 02:03:34 +010012170 .policy = nl80211_policy,
Johannes Berg4c476992010-10-04 21:36:35 +020012171 .internal_flags = NL80211_FLAG_NEED_NETDEV |
12172 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +010012173 },
12174 {
12175 .cmd = NL80211_CMD_SET_STATION,
12176 .doit = nl80211_set_station,
12177 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012178 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020012179 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020012180 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +010012181 },
12182 {
12183 .cmd = NL80211_CMD_NEW_STATION,
12184 .doit = nl80211_new_station,
12185 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012186 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020012187 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020012188 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +010012189 },
12190 {
12191 .cmd = NL80211_CMD_DEL_STATION,
12192 .doit = nl80211_del_station,
12193 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012194 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020012195 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020012196 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +010012197 },
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010012198 {
12199 .cmd = NL80211_CMD_GET_MPATH,
12200 .doit = nl80211_get_mpath,
12201 .dumpit = nl80211_dump_mpath,
12202 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012203 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020012204 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020012205 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010012206 },
12207 {
Henning Rogge66be7d22014-09-12 08:58:49 +020012208 .cmd = NL80211_CMD_GET_MPP,
12209 .doit = nl80211_get_mpp,
12210 .dumpit = nl80211_dump_mpp,
12211 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012212 .flags = GENL_UNS_ADMIN_PERM,
Henning Rogge66be7d22014-09-12 08:58:49 +020012213 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
12214 NL80211_FLAG_NEED_RTNL,
12215 },
12216 {
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010012217 .cmd = NL80211_CMD_SET_MPATH,
12218 .doit = nl80211_set_mpath,
12219 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012220 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020012221 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020012222 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010012223 },
12224 {
12225 .cmd = NL80211_CMD_NEW_MPATH,
12226 .doit = nl80211_new_mpath,
12227 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012228 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020012229 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020012230 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010012231 },
12232 {
12233 .cmd = NL80211_CMD_DEL_MPATH,
12234 .doit = nl80211_del_mpath,
12235 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012236 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020012237 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020012238 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010012239 },
Jouni Malinen9f1ba902008-08-07 20:07:01 +030012240 {
12241 .cmd = NL80211_CMD_SET_BSS,
12242 .doit = nl80211_set_bss,
12243 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012244 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020012245 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020012246 NL80211_FLAG_NEED_RTNL,
Jouni Malinen9f1ba902008-08-07 20:07:01 +030012247 },
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -070012248 {
Luis R. Rodriguezf1303472009-01-30 09:26:42 -080012249 .cmd = NL80211_CMD_GET_REG,
Arik Nemtsovad30ca22014-12-15 19:25:59 +020012250 .doit = nl80211_get_reg_do,
12251 .dumpit = nl80211_get_reg_dump,
Luis R. Rodriguezf1303472009-01-30 09:26:42 -080012252 .policy = nl80211_policy,
Johannes Berg5fe231e2013-05-08 21:45:15 +020012253 .internal_flags = NL80211_FLAG_NEED_RTNL,
Luis R. Rodriguezf1303472009-01-30 09:26:42 -080012254 /* can be retrieved by unprivileged users */
12255 },
Johannes Bergb6863032015-10-15 09:25:18 +020012256#ifdef CONFIG_CFG80211_CRDA_SUPPORT
Luis R. Rodriguezf1303472009-01-30 09:26:42 -080012257 {
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -070012258 .cmd = NL80211_CMD_SET_REG,
12259 .doit = nl80211_set_reg,
12260 .policy = nl80211_policy,
12261 .flags = GENL_ADMIN_PERM,
Johannes Berg5fe231e2013-05-08 21:45:15 +020012262 .internal_flags = NL80211_FLAG_NEED_RTNL,
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -070012263 },
Johannes Bergb6863032015-10-15 09:25:18 +020012264#endif
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -070012265 {
12266 .cmd = NL80211_CMD_REQ_SET_REG,
12267 .doit = nl80211_req_set_reg,
12268 .policy = nl80211_policy,
12269 .flags = GENL_ADMIN_PERM,
12270 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -070012271 {
Javier Cardona24bdd9f2010-12-16 17:37:48 -080012272 .cmd = NL80211_CMD_GET_MESH_CONFIG,
12273 .doit = nl80211_get_mesh_config,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -070012274 .policy = nl80211_policy,
12275 /* can be retrieved by unprivileged users */
Johannes Berg2b5f8b02012-04-02 10:51:55 +020012276 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020012277 NL80211_FLAG_NEED_RTNL,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -070012278 },
12279 {
Javier Cardona24bdd9f2010-12-16 17:37:48 -080012280 .cmd = NL80211_CMD_SET_MESH_CONFIG,
12281 .doit = nl80211_update_mesh_config,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -070012282 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012283 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg29cbe682010-12-03 09:20:44 +010012284 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020012285 NL80211_FLAG_NEED_RTNL,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -070012286 },
Jouni Malinen9aed3cc2009-01-13 16:03:29 +020012287 {
Johannes Berg2a519312009-02-10 21:25:55 +010012288 .cmd = NL80211_CMD_TRIGGER_SCAN,
12289 .doit = nl80211_trigger_scan,
12290 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012291 .flags = GENL_UNS_ADMIN_PERM,
Johannes Bergfd014282012-06-18 19:17:03 +020012292 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020012293 NL80211_FLAG_NEED_RTNL,
Johannes Berg2a519312009-02-10 21:25:55 +010012294 },
12295 {
Vidyullatha Kanchanapally91d3ab42015-10-30 19:14:49 +053012296 .cmd = NL80211_CMD_ABORT_SCAN,
12297 .doit = nl80211_abort_scan,
12298 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012299 .flags = GENL_UNS_ADMIN_PERM,
Vidyullatha Kanchanapally91d3ab42015-10-30 19:14:49 +053012300 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
12301 NL80211_FLAG_NEED_RTNL,
12302 },
12303 {
Johannes Berg2a519312009-02-10 21:25:55 +010012304 .cmd = NL80211_CMD_GET_SCAN,
12305 .policy = nl80211_policy,
12306 .dumpit = nl80211_dump_scan,
12307 },
Jouni Malinen636a5d32009-03-19 13:39:22 +020012308 {
Luciano Coelho807f8a82011-05-11 17:09:35 +030012309 .cmd = NL80211_CMD_START_SCHED_SCAN,
12310 .doit = nl80211_start_sched_scan,
12311 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012312 .flags = GENL_UNS_ADMIN_PERM,
Luciano Coelho807f8a82011-05-11 17:09:35 +030012313 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
12314 NL80211_FLAG_NEED_RTNL,
12315 },
12316 {
12317 .cmd = NL80211_CMD_STOP_SCHED_SCAN,
12318 .doit = nl80211_stop_sched_scan,
12319 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012320 .flags = GENL_UNS_ADMIN_PERM,
Luciano Coelho807f8a82011-05-11 17:09:35 +030012321 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
12322 NL80211_FLAG_NEED_RTNL,
12323 },
12324 {
Jouni Malinen636a5d32009-03-19 13:39:22 +020012325 .cmd = NL80211_CMD_AUTHENTICATE,
12326 .doit = nl80211_authenticate,
12327 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012328 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020012329 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg5393b912014-09-10 15:00:16 +030012330 NL80211_FLAG_NEED_RTNL |
12331 NL80211_FLAG_CLEAR_SKB,
Jouni Malinen636a5d32009-03-19 13:39:22 +020012332 },
12333 {
12334 .cmd = NL80211_CMD_ASSOCIATE,
12335 .doit = nl80211_associate,
12336 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012337 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020012338 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020012339 NL80211_FLAG_NEED_RTNL,
Jouni Malinen636a5d32009-03-19 13:39:22 +020012340 },
12341 {
12342 .cmd = NL80211_CMD_DEAUTHENTICATE,
12343 .doit = nl80211_deauthenticate,
12344 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012345 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020012346 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020012347 NL80211_FLAG_NEED_RTNL,
Jouni Malinen636a5d32009-03-19 13:39:22 +020012348 },
12349 {
12350 .cmd = NL80211_CMD_DISASSOCIATE,
12351 .doit = nl80211_disassociate,
12352 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012353 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020012354 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020012355 NL80211_FLAG_NEED_RTNL,
Jouni Malinen636a5d32009-03-19 13:39:22 +020012356 },
Johannes Berg04a773a2009-04-19 21:24:32 +020012357 {
12358 .cmd = NL80211_CMD_JOIN_IBSS,
12359 .doit = nl80211_join_ibss,
12360 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012361 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020012362 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020012363 NL80211_FLAG_NEED_RTNL,
Johannes Berg04a773a2009-04-19 21:24:32 +020012364 },
12365 {
12366 .cmd = NL80211_CMD_LEAVE_IBSS,
12367 .doit = nl80211_leave_ibss,
12368 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012369 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020012370 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020012371 NL80211_FLAG_NEED_RTNL,
Johannes Berg04a773a2009-04-19 21:24:32 +020012372 },
Johannes Bergaff89a92009-07-01 21:26:51 +020012373#ifdef CONFIG_NL80211_TESTMODE
12374 {
12375 .cmd = NL80211_CMD_TESTMODE,
12376 .doit = nl80211_testmode_do,
Wey-Yi Guy71063f02011-05-20 09:05:54 -070012377 .dumpit = nl80211_testmode_dump,
Johannes Bergaff89a92009-07-01 21:26:51 +020012378 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012379 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020012380 .internal_flags = NL80211_FLAG_NEED_WIPHY |
12381 NL80211_FLAG_NEED_RTNL,
Johannes Bergaff89a92009-07-01 21:26:51 +020012382 },
12383#endif
Samuel Ortizb23aa672009-07-01 21:26:54 +020012384 {
12385 .cmd = NL80211_CMD_CONNECT,
12386 .doit = nl80211_connect,
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,
Samuel Ortizb23aa672009-07-01 21:26:54 +020012391 },
12392 {
vamsi krishna088e8df2016-10-27 16:51:11 +030012393 .cmd = NL80211_CMD_UPDATE_CONNECT_PARAMS,
12394 .doit = nl80211_update_connect_params,
12395 .policy = nl80211_policy,
12396 .flags = GENL_ADMIN_PERM,
12397 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
12398 NL80211_FLAG_NEED_RTNL,
12399 },
12400 {
Samuel Ortizb23aa672009-07-01 21:26:54 +020012401 .cmd = NL80211_CMD_DISCONNECT,
12402 .doit = nl80211_disconnect,
12403 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012404 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020012405 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020012406 NL80211_FLAG_NEED_RTNL,
Samuel Ortizb23aa672009-07-01 21:26:54 +020012407 },
Johannes Berg463d0182009-07-14 00:33:35 +020012408 {
12409 .cmd = NL80211_CMD_SET_WIPHY_NETNS,
12410 .doit = nl80211_wiphy_netns,
12411 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012412 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020012413 .internal_flags = NL80211_FLAG_NEED_WIPHY |
12414 NL80211_FLAG_NEED_RTNL,
Johannes Berg463d0182009-07-14 00:33:35 +020012415 },
Holger Schurig61fa7132009-11-11 12:25:40 +010012416 {
12417 .cmd = NL80211_CMD_GET_SURVEY,
12418 .policy = nl80211_policy,
12419 .dumpit = nl80211_dump_survey,
12420 },
Samuel Ortiz67fbb162009-11-24 23:59:15 +010012421 {
12422 .cmd = NL80211_CMD_SET_PMKSA,
12423 .doit = nl80211_setdel_pmksa,
12424 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012425 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020012426 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020012427 NL80211_FLAG_NEED_RTNL,
Samuel Ortiz67fbb162009-11-24 23:59:15 +010012428 },
12429 {
12430 .cmd = NL80211_CMD_DEL_PMKSA,
12431 .doit = nl80211_setdel_pmksa,
12432 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012433 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020012434 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020012435 NL80211_FLAG_NEED_RTNL,
Samuel Ortiz67fbb162009-11-24 23:59:15 +010012436 },
12437 {
12438 .cmd = NL80211_CMD_FLUSH_PMKSA,
12439 .doit = nl80211_flush_pmksa,
12440 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012441 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020012442 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020012443 NL80211_FLAG_NEED_RTNL,
Samuel Ortiz67fbb162009-11-24 23:59:15 +010012444 },
Jouni Malinen9588bbd2009-12-23 13:15:41 +010012445 {
12446 .cmd = NL80211_CMD_REMAIN_ON_CHANNEL,
12447 .doit = nl80211_remain_on_channel,
12448 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012449 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +020012450 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020012451 NL80211_FLAG_NEED_RTNL,
Jouni Malinen9588bbd2009-12-23 13:15:41 +010012452 },
12453 {
12454 .cmd = NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL,
12455 .doit = nl80211_cancel_remain_on_channel,
12456 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012457 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +020012458 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020012459 NL80211_FLAG_NEED_RTNL,
Jouni Malinen9588bbd2009-12-23 13:15:41 +010012460 },
Jouni Malinen13ae75b2009-12-29 12:59:45 +020012461 {
12462 .cmd = NL80211_CMD_SET_TX_BITRATE_MASK,
12463 .doit = nl80211_set_tx_bitrate_mask,
12464 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012465 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020012466 .internal_flags = NL80211_FLAG_NEED_NETDEV |
12467 NL80211_FLAG_NEED_RTNL,
Jouni Malinen13ae75b2009-12-29 12:59:45 +020012468 },
Jouni Malinen026331c2010-02-15 12:53:10 +020012469 {
Johannes Berg2e161f72010-08-12 15:38:38 +020012470 .cmd = NL80211_CMD_REGISTER_FRAME,
12471 .doit = nl80211_register_mgmt,
Jouni Malinen026331c2010-02-15 12:53:10 +020012472 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012473 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +020012474 .internal_flags = NL80211_FLAG_NEED_WDEV |
Johannes Berg4c476992010-10-04 21:36:35 +020012475 NL80211_FLAG_NEED_RTNL,
Jouni Malinen026331c2010-02-15 12:53:10 +020012476 },
12477 {
Johannes Berg2e161f72010-08-12 15:38:38 +020012478 .cmd = NL80211_CMD_FRAME,
12479 .doit = nl80211_tx_mgmt,
Jouni Malinen026331c2010-02-15 12:53:10 +020012480 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012481 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +020012482 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020012483 NL80211_FLAG_NEED_RTNL,
Jouni Malinen026331c2010-02-15 12:53:10 +020012484 },
Kalle Valoffb9eb32010-02-17 17:58:10 +020012485 {
Johannes Bergf7ca38d2010-11-25 10:02:29 +010012486 .cmd = NL80211_CMD_FRAME_WAIT_CANCEL,
12487 .doit = nl80211_tx_mgmt_cancel_wait,
12488 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012489 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +020012490 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Bergf7ca38d2010-11-25 10:02:29 +010012491 NL80211_FLAG_NEED_RTNL,
12492 },
12493 {
Kalle Valoffb9eb32010-02-17 17:58:10 +020012494 .cmd = NL80211_CMD_SET_POWER_SAVE,
12495 .doit = nl80211_set_power_save,
12496 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012497 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020012498 .internal_flags = NL80211_FLAG_NEED_NETDEV |
12499 NL80211_FLAG_NEED_RTNL,
Kalle Valoffb9eb32010-02-17 17:58:10 +020012500 },
12501 {
12502 .cmd = NL80211_CMD_GET_POWER_SAVE,
12503 .doit = nl80211_get_power_save,
12504 .policy = nl80211_policy,
12505 /* can be retrieved by unprivileged users */
Johannes Berg4c476992010-10-04 21:36:35 +020012506 .internal_flags = NL80211_FLAG_NEED_NETDEV |
12507 NL80211_FLAG_NEED_RTNL,
Kalle Valoffb9eb32010-02-17 17:58:10 +020012508 },
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020012509 {
12510 .cmd = NL80211_CMD_SET_CQM,
12511 .doit = nl80211_set_cqm,
12512 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012513 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020012514 .internal_flags = NL80211_FLAG_NEED_NETDEV |
12515 NL80211_FLAG_NEED_RTNL,
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020012516 },
Johannes Bergf444de02010-05-05 15:25:02 +020012517 {
12518 .cmd = NL80211_CMD_SET_CHANNEL,
12519 .doit = nl80211_set_channel,
12520 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012521 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020012522 .internal_flags = NL80211_FLAG_NEED_NETDEV |
12523 NL80211_FLAG_NEED_RTNL,
Johannes Bergf444de02010-05-05 15:25:02 +020012524 },
Bill Jordane8347eb2010-10-01 13:54:28 -040012525 {
12526 .cmd = NL80211_CMD_SET_WDS_PEER,
12527 .doit = nl80211_set_wds_peer,
12528 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012529 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg43b19952010-10-07 13:10:30 +020012530 .internal_flags = NL80211_FLAG_NEED_NETDEV |
12531 NL80211_FLAG_NEED_RTNL,
Bill Jordane8347eb2010-10-01 13:54:28 -040012532 },
Johannes Berg29cbe682010-12-03 09:20:44 +010012533 {
12534 .cmd = NL80211_CMD_JOIN_MESH,
12535 .doit = nl80211_join_mesh,
12536 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012537 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg29cbe682010-12-03 09:20:44 +010012538 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
12539 NL80211_FLAG_NEED_RTNL,
12540 },
12541 {
12542 .cmd = NL80211_CMD_LEAVE_MESH,
12543 .doit = nl80211_leave_mesh,
12544 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012545 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg29cbe682010-12-03 09:20:44 +010012546 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
12547 NL80211_FLAG_NEED_RTNL,
12548 },
Rostislav Lisovy6e0bd6c2014-11-03 10:33:18 +010012549 {
12550 .cmd = NL80211_CMD_JOIN_OCB,
12551 .doit = nl80211_join_ocb,
12552 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012553 .flags = GENL_UNS_ADMIN_PERM,
Rostislav Lisovy6e0bd6c2014-11-03 10:33:18 +010012554 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
12555 NL80211_FLAG_NEED_RTNL,
12556 },
12557 {
12558 .cmd = NL80211_CMD_LEAVE_OCB,
12559 .doit = nl80211_leave_ocb,
12560 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012561 .flags = GENL_UNS_ADMIN_PERM,
Rostislav Lisovy6e0bd6c2014-11-03 10:33:18 +010012562 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
12563 NL80211_FLAG_NEED_RTNL,
12564 },
Johannes Bergdfb89c52012-06-27 09:23:48 +020012565#ifdef CONFIG_PM
Johannes Bergff1b6e62011-05-04 15:37:28 +020012566 {
12567 .cmd = NL80211_CMD_GET_WOWLAN,
12568 .doit = nl80211_get_wowlan,
12569 .policy = nl80211_policy,
12570 /* can be retrieved by unprivileged users */
12571 .internal_flags = NL80211_FLAG_NEED_WIPHY |
12572 NL80211_FLAG_NEED_RTNL,
12573 },
12574 {
12575 .cmd = NL80211_CMD_SET_WOWLAN,
12576 .doit = nl80211_set_wowlan,
12577 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012578 .flags = GENL_UNS_ADMIN_PERM,
Johannes Bergff1b6e62011-05-04 15:37:28 +020012579 .internal_flags = NL80211_FLAG_NEED_WIPHY |
12580 NL80211_FLAG_NEED_RTNL,
12581 },
Johannes Bergdfb89c52012-06-27 09:23:48 +020012582#endif
Johannes Berge5497d72011-07-05 16:35:40 +020012583 {
12584 .cmd = NL80211_CMD_SET_REKEY_OFFLOAD,
12585 .doit = nl80211_set_rekey_data,
12586 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012587 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berge5497d72011-07-05 16:35:40 +020012588 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg5393b912014-09-10 15:00:16 +030012589 NL80211_FLAG_NEED_RTNL |
12590 NL80211_FLAG_CLEAR_SKB,
Johannes Berge5497d72011-07-05 16:35:40 +020012591 },
Arik Nemtsov109086c2011-09-28 14:12:50 +030012592 {
12593 .cmd = NL80211_CMD_TDLS_MGMT,
12594 .doit = nl80211_tdls_mgmt,
12595 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012596 .flags = GENL_UNS_ADMIN_PERM,
Arik Nemtsov109086c2011-09-28 14:12:50 +030012597 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
12598 NL80211_FLAG_NEED_RTNL,
12599 },
12600 {
12601 .cmd = NL80211_CMD_TDLS_OPER,
12602 .doit = nl80211_tdls_oper,
12603 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012604 .flags = GENL_UNS_ADMIN_PERM,
Arik Nemtsov109086c2011-09-28 14:12:50 +030012605 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
12606 NL80211_FLAG_NEED_RTNL,
12607 },
Johannes Berg28946da2011-11-04 11:18:12 +010012608 {
12609 .cmd = NL80211_CMD_UNEXPECTED_FRAME,
12610 .doit = nl80211_register_unexpected_frame,
12611 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012612 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg28946da2011-11-04 11:18:12 +010012613 .internal_flags = NL80211_FLAG_NEED_NETDEV |
12614 NL80211_FLAG_NEED_RTNL,
12615 },
Johannes Berg7f6cf312011-11-04 11:18:15 +010012616 {
12617 .cmd = NL80211_CMD_PROBE_CLIENT,
12618 .doit = nl80211_probe_client,
12619 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012620 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020012621 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg7f6cf312011-11-04 11:18:15 +010012622 NL80211_FLAG_NEED_RTNL,
12623 },
Johannes Berg5e760232011-11-04 11:18:17 +010012624 {
12625 .cmd = NL80211_CMD_REGISTER_BEACONS,
12626 .doit = nl80211_register_beacons,
12627 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012628 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg5e760232011-11-04 11:18:17 +010012629 .internal_flags = NL80211_FLAG_NEED_WIPHY |
12630 NL80211_FLAG_NEED_RTNL,
12631 },
Simon Wunderlich1d9d9212011-11-18 14:20:43 +010012632 {
12633 .cmd = NL80211_CMD_SET_NOACK_MAP,
12634 .doit = nl80211_set_noack_map,
12635 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012636 .flags = GENL_UNS_ADMIN_PERM,
Simon Wunderlich1d9d9212011-11-18 14:20:43 +010012637 .internal_flags = NL80211_FLAG_NEED_NETDEV |
12638 NL80211_FLAG_NEED_RTNL,
12639 },
Johannes Berg98104fde2012-06-16 00:19:54 +020012640 {
12641 .cmd = NL80211_CMD_START_P2P_DEVICE,
12642 .doit = nl80211_start_p2p_device,
12643 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012644 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg98104fde2012-06-16 00:19:54 +020012645 .internal_flags = NL80211_FLAG_NEED_WDEV |
12646 NL80211_FLAG_NEED_RTNL,
12647 },
12648 {
12649 .cmd = NL80211_CMD_STOP_P2P_DEVICE,
12650 .doit = nl80211_stop_p2p_device,
12651 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012652 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg98104fde2012-06-16 00:19:54 +020012653 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
12654 NL80211_FLAG_NEED_RTNL,
12655 },
Antonio Quartullif4e583c2012-11-02 13:27:48 +010012656 {
Ayala Bekercb3b7d82016-09-20 17:31:13 +030012657 .cmd = NL80211_CMD_START_NAN,
12658 .doit = nl80211_start_nan,
12659 .policy = nl80211_policy,
12660 .flags = GENL_ADMIN_PERM,
12661 .internal_flags = NL80211_FLAG_NEED_WDEV |
12662 NL80211_FLAG_NEED_RTNL,
12663 },
12664 {
12665 .cmd = NL80211_CMD_STOP_NAN,
12666 .doit = nl80211_stop_nan,
12667 .policy = nl80211_policy,
12668 .flags = GENL_ADMIN_PERM,
12669 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
12670 NL80211_FLAG_NEED_RTNL,
12671 },
12672 {
Ayala Bekera442b762016-09-20 17:31:15 +030012673 .cmd = NL80211_CMD_ADD_NAN_FUNCTION,
12674 .doit = nl80211_nan_add_func,
12675 .policy = nl80211_policy,
12676 .flags = GENL_ADMIN_PERM,
12677 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
12678 NL80211_FLAG_NEED_RTNL,
12679 },
12680 {
12681 .cmd = NL80211_CMD_DEL_NAN_FUNCTION,
12682 .doit = nl80211_nan_del_func,
12683 .policy = nl80211_policy,
12684 .flags = GENL_ADMIN_PERM,
12685 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
12686 NL80211_FLAG_NEED_RTNL,
12687 },
12688 {
Ayala Bekera5a9dcf2016-09-20 17:31:16 +030012689 .cmd = NL80211_CMD_CHANGE_NAN_CONFIG,
12690 .doit = nl80211_nan_change_config,
12691 .policy = nl80211_policy,
12692 .flags = GENL_ADMIN_PERM,
12693 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
12694 NL80211_FLAG_NEED_RTNL,
12695 },
12696 {
Antonio Quartullif4e583c2012-11-02 13:27:48 +010012697 .cmd = NL80211_CMD_SET_MCAST_RATE,
12698 .doit = nl80211_set_mcast_rate,
12699 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012700 .flags = GENL_UNS_ADMIN_PERM,
Antonio Quartullif4e583c2012-11-02 13:27:48 +010012701 .internal_flags = NL80211_FLAG_NEED_NETDEV |
12702 NL80211_FLAG_NEED_RTNL,
12703 },
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +053012704 {
12705 .cmd = NL80211_CMD_SET_MAC_ACL,
12706 .doit = nl80211_set_mac_acl,
12707 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012708 .flags = GENL_UNS_ADMIN_PERM,
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +053012709 .internal_flags = NL80211_FLAG_NEED_NETDEV |
12710 NL80211_FLAG_NEED_RTNL,
12711 },
Simon Wunderlich04f39042013-02-08 18:16:19 +010012712 {
12713 .cmd = NL80211_CMD_RADAR_DETECT,
12714 .doit = nl80211_start_radar_detection,
12715 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012716 .flags = GENL_UNS_ADMIN_PERM,
Simon Wunderlich04f39042013-02-08 18:16:19 +010012717 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
12718 NL80211_FLAG_NEED_RTNL,
12719 },
Johannes Berg3713b4e2013-02-14 16:19:38 +010012720 {
12721 .cmd = NL80211_CMD_GET_PROTOCOL_FEATURES,
12722 .doit = nl80211_get_protocol_features,
12723 .policy = nl80211_policy,
12724 },
Jouni Malinen355199e2013-02-27 17:14:27 +020012725 {
12726 .cmd = NL80211_CMD_UPDATE_FT_IES,
12727 .doit = nl80211_update_ft_ies,
12728 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012729 .flags = GENL_UNS_ADMIN_PERM,
Jouni Malinen355199e2013-02-27 17:14:27 +020012730 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
12731 NL80211_FLAG_NEED_RTNL,
12732 },
Arend van Spriel5de17982013-04-18 15:49:00 +020012733 {
12734 .cmd = NL80211_CMD_CRIT_PROTOCOL_START,
12735 .doit = nl80211_crit_protocol_start,
12736 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012737 .flags = GENL_UNS_ADMIN_PERM,
Arend van Spriel5de17982013-04-18 15:49:00 +020012738 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
12739 NL80211_FLAG_NEED_RTNL,
12740 },
12741 {
12742 .cmd = NL80211_CMD_CRIT_PROTOCOL_STOP,
12743 .doit = nl80211_crit_protocol_stop,
12744 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012745 .flags = GENL_UNS_ADMIN_PERM,
Arend van Spriel5de17982013-04-18 15:49:00 +020012746 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
12747 NL80211_FLAG_NEED_RTNL,
Amitkumar Karwarbe29b992013-06-28 11:51:26 -070012748 },
12749 {
12750 .cmd = NL80211_CMD_GET_COALESCE,
12751 .doit = nl80211_get_coalesce,
12752 .policy = nl80211_policy,
12753 .internal_flags = NL80211_FLAG_NEED_WIPHY |
12754 NL80211_FLAG_NEED_RTNL,
12755 },
12756 {
12757 .cmd = NL80211_CMD_SET_COALESCE,
12758 .doit = nl80211_set_coalesce,
12759 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012760 .flags = GENL_UNS_ADMIN_PERM,
Amitkumar Karwarbe29b992013-06-28 11:51:26 -070012761 .internal_flags = NL80211_FLAG_NEED_WIPHY |
12762 NL80211_FLAG_NEED_RTNL,
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +020012763 },
12764 {
12765 .cmd = NL80211_CMD_CHANNEL_SWITCH,
12766 .doit = nl80211_channel_switch,
12767 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012768 .flags = GENL_UNS_ADMIN_PERM,
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +020012769 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
12770 NL80211_FLAG_NEED_RTNL,
12771 },
Johannes Bergad7e7182013-11-13 13:37:47 +010012772 {
12773 .cmd = NL80211_CMD_VENDOR,
12774 .doit = nl80211_vendor_cmd,
Johannes Berg7bdbe402015-08-15 22:39:49 +030012775 .dumpit = nl80211_vendor_cmd_dump,
Johannes Bergad7e7182013-11-13 13:37:47 +010012776 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012777 .flags = GENL_UNS_ADMIN_PERM,
Johannes Bergad7e7182013-11-13 13:37:47 +010012778 .internal_flags = NL80211_FLAG_NEED_WIPHY |
12779 NL80211_FLAG_NEED_RTNL,
12780 },
Kyeyoon Parkfa9ffc72013-12-16 23:01:30 -080012781 {
12782 .cmd = NL80211_CMD_SET_QOS_MAP,
12783 .doit = nl80211_set_qos_map,
12784 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012785 .flags = GENL_UNS_ADMIN_PERM,
Kyeyoon Parkfa9ffc72013-12-16 23:01:30 -080012786 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
12787 NL80211_FLAG_NEED_RTNL,
12788 },
Johannes Berg960d01a2014-09-09 22:55:35 +030012789 {
12790 .cmd = NL80211_CMD_ADD_TX_TS,
12791 .doit = nl80211_add_tx_ts,
12792 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012793 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg960d01a2014-09-09 22:55:35 +030012794 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
12795 NL80211_FLAG_NEED_RTNL,
12796 },
12797 {
12798 .cmd = NL80211_CMD_DEL_TX_TS,
12799 .doit = nl80211_del_tx_ts,
12800 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012801 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg960d01a2014-09-09 22:55:35 +030012802 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
12803 NL80211_FLAG_NEED_RTNL,
12804 },
Arik Nemtsov1057d352014-11-19 12:54:26 +020012805 {
12806 .cmd = NL80211_CMD_TDLS_CHANNEL_SWITCH,
12807 .doit = nl80211_tdls_channel_switch,
12808 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012809 .flags = GENL_UNS_ADMIN_PERM,
Arik Nemtsov1057d352014-11-19 12:54:26 +020012810 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
12811 NL80211_FLAG_NEED_RTNL,
12812 },
12813 {
12814 .cmd = NL80211_CMD_TDLS_CANCEL_CHANNEL_SWITCH,
12815 .doit = nl80211_tdls_cancel_channel_switch,
12816 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012817 .flags = GENL_UNS_ADMIN_PERM,
Arik Nemtsov1057d352014-11-19 12:54:26 +020012818 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
12819 NL80211_FLAG_NEED_RTNL,
12820 },
Michael Braunce0ce132016-10-10 19:12:22 +020012821 {
12822 .cmd = NL80211_CMD_SET_MULTICAST_TO_UNICAST,
12823 .doit = nl80211_set_multicast_to_unicast,
12824 .policy = nl80211_policy,
12825 .flags = GENL_UNS_ADMIN_PERM,
12826 .internal_flags = NL80211_FLAG_NEED_NETDEV |
12827 NL80211_FLAG_NEED_RTNL,
12828 },
Johannes Berg55682962007-09-20 13:09:35 -040012829};
Jouni Malinen9588bbd2009-12-23 13:15:41 +010012830
Johannes Berg56989f62016-10-24 14:40:05 +020012831static struct genl_family nl80211_fam __ro_after_init = {
Johannes Berg489111e2016-10-24 14:40:03 +020012832 .name = NL80211_GENL_NAME, /* have users key off the name instead */
12833 .hdrsize = 0, /* no private header */
12834 .version = 1, /* no particular meaning now */
12835 .maxattr = NL80211_ATTR_MAX,
12836 .netnsok = true,
12837 .pre_doit = nl80211_pre_doit,
12838 .post_doit = nl80211_post_doit,
12839 .module = THIS_MODULE,
12840 .ops = nl80211_ops,
12841 .n_ops = ARRAY_SIZE(nl80211_ops),
12842 .mcgrps = nl80211_mcgrps,
12843 .n_mcgrps = ARRAY_SIZE(nl80211_mcgrps),
12844};
12845
Johannes Berg55682962007-09-20 13:09:35 -040012846/* notification functions */
12847
Johannes Berg3bb20552014-05-26 13:52:25 +020012848void nl80211_notify_wiphy(struct cfg80211_registered_device *rdev,
12849 enum nl80211_commands cmd)
Johannes Berg55682962007-09-20 13:09:35 -040012850{
12851 struct sk_buff *msg;
Johannes Berg86e8cf92013-06-19 10:57:22 +020012852 struct nl80211_dump_wiphy_state state = {};
Johannes Berg55682962007-09-20 13:09:35 -040012853
Johannes Berg3bb20552014-05-26 13:52:25 +020012854 WARN_ON(cmd != NL80211_CMD_NEW_WIPHY &&
12855 cmd != NL80211_CMD_DEL_WIPHY);
12856
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -070012857 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -040012858 if (!msg)
12859 return;
12860
Johannes Berg3bb20552014-05-26 13:52:25 +020012861 if (nl80211_send_wiphy(rdev, cmd, msg, 0, 0, 0, &state) < 0) {
Johannes Berg55682962007-09-20 13:09:35 -040012862 nlmsg_free(msg);
12863 return;
12864 }
12865
Johannes Berg68eb5502013-11-19 15:19:38 +010012866 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010012867 NL80211_MCGRP_CONFIG, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -040012868}
12869
Denis Kenzior896ff062016-08-03 16:58:33 -050012870void nl80211_notify_iface(struct cfg80211_registered_device *rdev,
12871 struct wireless_dev *wdev,
12872 enum nl80211_commands cmd)
12873{
12874 struct sk_buff *msg;
12875
12876 WARN_ON(cmd != NL80211_CMD_NEW_INTERFACE &&
12877 cmd != NL80211_CMD_DEL_INTERFACE);
12878
12879 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
12880 if (!msg)
12881 return;
12882
12883 if (nl80211_send_iface(msg, 0, 0, 0, rdev, wdev,
12884 cmd == NL80211_CMD_DEL_INTERFACE) < 0) {
12885 nlmsg_free(msg);
12886 return;
12887 }
12888
12889 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
12890 NL80211_MCGRP_CONFIG, GFP_KERNEL);
12891}
12892
Johannes Berg362a4152009-05-24 16:43:15 +020012893static int nl80211_add_scan_req(struct sk_buff *msg,
12894 struct cfg80211_registered_device *rdev)
12895{
12896 struct cfg80211_scan_request *req = rdev->scan_req;
12897 struct nlattr *nest;
12898 int i;
12899
12900 if (WARN_ON(!req))
12901 return 0;
12902
12903 nest = nla_nest_start(msg, NL80211_ATTR_SCAN_SSIDS);
12904 if (!nest)
12905 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -040012906 for (i = 0; i < req->n_ssids; i++) {
12907 if (nla_put(msg, i, req->ssids[i].ssid_len, req->ssids[i].ssid))
12908 goto nla_put_failure;
12909 }
Johannes Berg362a4152009-05-24 16:43:15 +020012910 nla_nest_end(msg, nest);
12911
12912 nest = nla_nest_start(msg, NL80211_ATTR_SCAN_FREQUENCIES);
12913 if (!nest)
12914 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -040012915 for (i = 0; i < req->n_channels; i++) {
12916 if (nla_put_u32(msg, i, req->channels[i]->center_freq))
12917 goto nla_put_failure;
12918 }
Johannes Berg362a4152009-05-24 16:43:15 +020012919 nla_nest_end(msg, nest);
12920
David S. Miller9360ffd2012-03-29 04:41:26 -040012921 if (req->ie &&
12922 nla_put(msg, NL80211_ATTR_IE, req->ie_len, req->ie))
12923 goto nla_put_failure;
Johannes Berg362a4152009-05-24 16:43:15 +020012924
Johannes Bergae917c92013-10-25 11:05:22 +020012925 if (req->flags &&
12926 nla_put_u32(msg, NL80211_ATTR_SCAN_FLAGS, req->flags))
12927 goto nla_put_failure;
Sam Lefflered4737712012-10-11 21:03:31 -070012928
Avraham Stern1d762502016-07-05 17:10:13 +030012929 if (req->info.scan_start_tsf &&
12930 (nla_put_u64_64bit(msg, NL80211_ATTR_SCAN_START_TIME_TSF,
12931 req->info.scan_start_tsf, NL80211_BSS_PAD) ||
12932 nla_put(msg, NL80211_ATTR_SCAN_START_TIME_TSF_BSSID, ETH_ALEN,
12933 req->info.tsf_bssid)))
12934 goto nla_put_failure;
12935
Johannes Berg362a4152009-05-24 16:43:15 +020012936 return 0;
12937 nla_put_failure:
12938 return -ENOBUFS;
12939}
12940
Arend Van Spriel505a2e82016-12-16 11:21:54 +000012941static int nl80211_prep_scan_msg(struct sk_buff *msg,
Johannes Berga538e2d2009-06-16 19:56:42 +020012942 struct cfg80211_registered_device *rdev,
Johannes Bergfd014282012-06-18 19:17:03 +020012943 struct wireless_dev *wdev,
Eric W. Biederman15e47302012-09-07 20:12:54 +000012944 u32 portid, u32 seq, int flags,
Johannes Berga538e2d2009-06-16 19:56:42 +020012945 u32 cmd)
Johannes Berg2a519312009-02-10 21:25:55 +010012946{
12947 void *hdr;
12948
Eric W. Biederman15e47302012-09-07 20:12:54 +000012949 hdr = nl80211hdr_put(msg, portid, seq, flags, cmd);
Johannes Berg2a519312009-02-10 21:25:55 +010012950 if (!hdr)
12951 return -1;
12952
David S. Miller9360ffd2012-03-29 04:41:26 -040012953 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Bergfd014282012-06-18 19:17:03 +020012954 (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
12955 wdev->netdev->ifindex)) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020012956 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
12957 NL80211_ATTR_PAD))
David S. Miller9360ffd2012-03-29 04:41:26 -040012958 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +010012959
Johannes Berg362a4152009-05-24 16:43:15 +020012960 /* ignore errors and send incomplete event anyway */
12961 nl80211_add_scan_req(msg, rdev);
Johannes Berg2a519312009-02-10 21:25:55 +010012962
Johannes Berg053c0952015-01-16 22:09:00 +010012963 genlmsg_end(msg, hdr);
12964 return 0;
Johannes Berg2a519312009-02-10 21:25:55 +010012965
12966 nla_put_failure:
12967 genlmsg_cancel(msg, hdr);
12968 return -EMSGSIZE;
12969}
12970
Luciano Coelho807f8a82011-05-11 17:09:35 +030012971static int
Arend Van Spriel505a2e82016-12-16 11:21:54 +000012972nl80211_prep_sched_scan_msg(struct sk_buff *msg,
Luciano Coelho807f8a82011-05-11 17:09:35 +030012973 struct cfg80211_registered_device *rdev,
12974 struct net_device *netdev,
Eric W. Biederman15e47302012-09-07 20:12:54 +000012975 u32 portid, u32 seq, int flags, u32 cmd)
Luciano Coelho807f8a82011-05-11 17:09:35 +030012976{
12977 void *hdr;
12978
Eric W. Biederman15e47302012-09-07 20:12:54 +000012979 hdr = nl80211hdr_put(msg, portid, seq, flags, cmd);
Luciano Coelho807f8a82011-05-11 17:09:35 +030012980 if (!hdr)
12981 return -1;
12982
David S. Miller9360ffd2012-03-29 04:41:26 -040012983 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
12984 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex))
12985 goto nla_put_failure;
Luciano Coelho807f8a82011-05-11 17:09:35 +030012986
Johannes Berg053c0952015-01-16 22:09:00 +010012987 genlmsg_end(msg, hdr);
12988 return 0;
Luciano Coelho807f8a82011-05-11 17:09:35 +030012989
12990 nla_put_failure:
12991 genlmsg_cancel(msg, hdr);
12992 return -EMSGSIZE;
12993}
12994
Johannes Berga538e2d2009-06-16 19:56:42 +020012995void nl80211_send_scan_start(struct cfg80211_registered_device *rdev,
Johannes Bergfd014282012-06-18 19:17:03 +020012996 struct wireless_dev *wdev)
Johannes Berga538e2d2009-06-16 19:56:42 +020012997{
12998 struct sk_buff *msg;
12999
Thomas Graf58050fc2012-06-28 03:57:45 +000013000 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berga538e2d2009-06-16 19:56:42 +020013001 if (!msg)
13002 return;
13003
Arend Van Spriel505a2e82016-12-16 11:21:54 +000013004 if (nl80211_prep_scan_msg(msg, rdev, wdev, 0, 0, 0,
Johannes Berga538e2d2009-06-16 19:56:42 +020013005 NL80211_CMD_TRIGGER_SCAN) < 0) {
13006 nlmsg_free(msg);
13007 return;
13008 }
13009
Johannes Berg68eb5502013-11-19 15:19:38 +010013010 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010013011 NL80211_MCGRP_SCAN, GFP_KERNEL);
Johannes Berga538e2d2009-06-16 19:56:42 +020013012}
13013
Johannes Bergf9d15d12014-01-22 11:14:19 +020013014struct sk_buff *nl80211_build_scan_msg(struct cfg80211_registered_device *rdev,
13015 struct wireless_dev *wdev, bool aborted)
Johannes Berg2a519312009-02-10 21:25:55 +010013016{
13017 struct sk_buff *msg;
13018
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -070013019 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg2a519312009-02-10 21:25:55 +010013020 if (!msg)
Johannes Bergf9d15d12014-01-22 11:14:19 +020013021 return NULL;
Johannes Berg2a519312009-02-10 21:25:55 +010013022
Arend Van Spriel505a2e82016-12-16 11:21:54 +000013023 if (nl80211_prep_scan_msg(msg, rdev, wdev, 0, 0, 0,
Johannes Bergf9d15d12014-01-22 11:14:19 +020013024 aborted ? NL80211_CMD_SCAN_ABORTED :
13025 NL80211_CMD_NEW_SCAN_RESULTS) < 0) {
Johannes Berg2a519312009-02-10 21:25:55 +010013026 nlmsg_free(msg);
Johannes Bergf9d15d12014-01-22 11:14:19 +020013027 return NULL;
Johannes Berg2a519312009-02-10 21:25:55 +010013028 }
13029
Johannes Bergf9d15d12014-01-22 11:14:19 +020013030 return msg;
Johannes Berg2a519312009-02-10 21:25:55 +010013031}
13032
Arend Van Spriel505a2e82016-12-16 11:21:54 +000013033/* send message created by nl80211_build_scan_msg() */
13034void nl80211_send_scan_msg(struct cfg80211_registered_device *rdev,
13035 struct sk_buff *msg)
Johannes Berg2a519312009-02-10 21:25:55 +010013036{
Johannes Berg2a519312009-02-10 21:25:55 +010013037 if (!msg)
13038 return;
13039
Johannes Berg68eb5502013-11-19 15:19:38 +010013040 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010013041 NL80211_MCGRP_SCAN, GFP_KERNEL);
Johannes Berg2a519312009-02-10 21:25:55 +010013042}
13043
Luciano Coelho807f8a82011-05-11 17:09:35 +030013044void nl80211_send_sched_scan(struct cfg80211_registered_device *rdev,
13045 struct net_device *netdev, u32 cmd)
13046{
13047 struct sk_buff *msg;
13048
Thomas Graf58050fc2012-06-28 03:57:45 +000013049 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Luciano Coelho807f8a82011-05-11 17:09:35 +030013050 if (!msg)
13051 return;
13052
Arend Van Spriel505a2e82016-12-16 11:21:54 +000013053 if (nl80211_prep_sched_scan_msg(msg, rdev, netdev, 0, 0, 0, cmd) < 0) {
Luciano Coelho807f8a82011-05-11 17:09:35 +030013054 nlmsg_free(msg);
13055 return;
13056 }
13057
Johannes Berg68eb5502013-11-19 15:19:38 +010013058 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010013059 NL80211_MCGRP_SCAN, GFP_KERNEL);
Luciano Coelho807f8a82011-05-11 17:09:35 +030013060}
13061
Jonathan Doronb0d7aa52014-12-15 19:26:00 +020013062static bool nl80211_reg_change_event_fill(struct sk_buff *msg,
13063 struct regulatory_request *request)
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040013064{
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040013065 /* Userspace can always count this one always being set */
David S. Miller9360ffd2012-03-29 04:41:26 -040013066 if (nla_put_u8(msg, NL80211_ATTR_REG_INITIATOR, request->initiator))
13067 goto nla_put_failure;
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040013068
David S. Miller9360ffd2012-03-29 04:41:26 -040013069 if (request->alpha2[0] == '0' && request->alpha2[1] == '0') {
13070 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
13071 NL80211_REGDOM_TYPE_WORLD))
13072 goto nla_put_failure;
13073 } else if (request->alpha2[0] == '9' && request->alpha2[1] == '9') {
13074 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
13075 NL80211_REGDOM_TYPE_CUSTOM_WORLD))
13076 goto nla_put_failure;
13077 } else if ((request->alpha2[0] == '9' && request->alpha2[1] == '8') ||
13078 request->intersect) {
13079 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
13080 NL80211_REGDOM_TYPE_INTERSECTION))
13081 goto nla_put_failure;
13082 } else {
13083 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
13084 NL80211_REGDOM_TYPE_COUNTRY) ||
13085 nla_put_string(msg, NL80211_ATTR_REG_ALPHA2,
13086 request->alpha2))
13087 goto nla_put_failure;
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040013088 }
13089
Arik Nemtsovad30ca22014-12-15 19:25:59 +020013090 if (request->wiphy_idx != WIPHY_IDX_INVALID) {
13091 struct wiphy *wiphy = wiphy_idx_to_wiphy(request->wiphy_idx);
13092
13093 if (wiphy &&
13094 nla_put_u32(msg, NL80211_ATTR_WIPHY, request->wiphy_idx))
13095 goto nla_put_failure;
Arik Nemtsov1bdd7162014-12-15 19:26:01 +020013096
13097 if (wiphy &&
13098 wiphy->regulatory_flags & REGULATORY_WIPHY_SELF_MANAGED &&
13099 nla_put_flag(msg, NL80211_ATTR_WIPHY_SELF_MANAGED_REG))
13100 goto nla_put_failure;
Arik Nemtsovad30ca22014-12-15 19:25:59 +020013101 }
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040013102
Jonathan Doronb0d7aa52014-12-15 19:26:00 +020013103 return true;
13104
13105nla_put_failure:
13106 return false;
13107}
13108
13109/*
13110 * This can happen on global regulatory changes or device specific settings
13111 * based on custom regulatory domains.
13112 */
13113void nl80211_common_reg_change_event(enum nl80211_commands cmd_id,
13114 struct regulatory_request *request)
13115{
13116 struct sk_buff *msg;
13117 void *hdr;
13118
13119 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
13120 if (!msg)
13121 return;
13122
13123 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd_id);
13124 if (!hdr) {
13125 nlmsg_free(msg);
13126 return;
13127 }
13128
13129 if (nl80211_reg_change_event_fill(msg, request) == false)
13130 goto nla_put_failure;
13131
Johannes Berg3b7b72e2011-10-22 19:05:51 +020013132 genlmsg_end(msg, hdr);
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040013133
Johannes Bergbc43b282009-07-25 10:54:13 +020013134 rcu_read_lock();
Johannes Berg68eb5502013-11-19 15:19:38 +010013135 genlmsg_multicast_allns(&nl80211_fam, msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010013136 NL80211_MCGRP_REGULATORY, GFP_ATOMIC);
Johannes Bergbc43b282009-07-25 10:54:13 +020013137 rcu_read_unlock();
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040013138
13139 return;
13140
13141nla_put_failure:
13142 genlmsg_cancel(msg, hdr);
13143 nlmsg_free(msg);
13144}
13145
Jouni Malinen6039f6d2009-03-19 13:39:21 +020013146static void nl80211_send_mlme_event(struct cfg80211_registered_device *rdev,
13147 struct net_device *netdev,
13148 const u8 *buf, size_t len,
Eliad Pellerb0b6aa22014-09-09 17:09:45 +030013149 enum nl80211_commands cmd, gfp_t gfp,
13150 int uapsd_queues)
Jouni Malinen6039f6d2009-03-19 13:39:21 +020013151{
13152 struct sk_buff *msg;
13153 void *hdr;
13154
Johannes Berg4ef8c1c2017-01-09 11:10:42 +010013155 msg = nlmsg_new(100 + len, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020013156 if (!msg)
13157 return;
13158
13159 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
13160 if (!hdr) {
13161 nlmsg_free(msg);
13162 return;
13163 }
13164
David S. Miller9360ffd2012-03-29 04:41:26 -040013165 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
13166 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
13167 nla_put(msg, NL80211_ATTR_FRAME, len, buf))
13168 goto nla_put_failure;
Jouni Malinen6039f6d2009-03-19 13:39:21 +020013169
Eliad Pellerb0b6aa22014-09-09 17:09:45 +030013170 if (uapsd_queues >= 0) {
13171 struct nlattr *nla_wmm =
13172 nla_nest_start(msg, NL80211_ATTR_STA_WME);
13173 if (!nla_wmm)
13174 goto nla_put_failure;
13175
13176 if (nla_put_u8(msg, NL80211_STA_WME_UAPSD_QUEUES,
13177 uapsd_queues))
13178 goto nla_put_failure;
13179
13180 nla_nest_end(msg, nla_wmm);
13181 }
13182
Johannes Berg3b7b72e2011-10-22 19:05:51 +020013183 genlmsg_end(msg, hdr);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020013184
Johannes Berg68eb5502013-11-19 15:19:38 +010013185 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010013186 NL80211_MCGRP_MLME, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020013187 return;
13188
13189 nla_put_failure:
13190 genlmsg_cancel(msg, hdr);
13191 nlmsg_free(msg);
13192}
13193
13194void nl80211_send_rx_auth(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +020013195 struct net_device *netdev, const u8 *buf,
13196 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +020013197{
13198 nl80211_send_mlme_event(rdev, netdev, buf, len,
Eliad Pellerb0b6aa22014-09-09 17:09:45 +030013199 NL80211_CMD_AUTHENTICATE, gfp, -1);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020013200}
13201
13202void nl80211_send_rx_assoc(struct cfg80211_registered_device *rdev,
13203 struct net_device *netdev, const u8 *buf,
Eliad Pellerb0b6aa22014-09-09 17:09:45 +030013204 size_t len, gfp_t gfp, int uapsd_queues)
Jouni Malinen6039f6d2009-03-19 13:39:21 +020013205{
Johannes Berge6d6e342009-07-01 21:26:47 +020013206 nl80211_send_mlme_event(rdev, netdev, buf, len,
Eliad Pellerb0b6aa22014-09-09 17:09:45 +030013207 NL80211_CMD_ASSOCIATE, gfp, uapsd_queues);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020013208}
13209
Jouni Malinen53b46b82009-03-27 20:53:56 +020013210void nl80211_send_deauth(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +020013211 struct net_device *netdev, const u8 *buf,
13212 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +020013213{
13214 nl80211_send_mlme_event(rdev, netdev, buf, len,
Eliad Pellerb0b6aa22014-09-09 17:09:45 +030013215 NL80211_CMD_DEAUTHENTICATE, gfp, -1);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020013216}
13217
Jouni Malinen53b46b82009-03-27 20:53:56 +020013218void nl80211_send_disassoc(struct cfg80211_registered_device *rdev,
13219 struct net_device *netdev, const u8 *buf,
Johannes Berge6d6e342009-07-01 21:26:47 +020013220 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +020013221{
13222 nl80211_send_mlme_event(rdev, netdev, buf, len,
Eliad Pellerb0b6aa22014-09-09 17:09:45 +030013223 NL80211_CMD_DISASSOCIATE, gfp, -1);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020013224}
13225
Johannes Berg6ff57cf2013-05-16 00:55:00 +020013226void cfg80211_rx_unprot_mlme_mgmt(struct net_device *dev, const u8 *buf,
13227 size_t len)
Jouni Malinencf4e5942010-12-16 00:52:40 +020013228{
Johannes Berg947add32013-02-22 22:05:20 +010013229 struct wireless_dev *wdev = dev->ieee80211_ptr;
13230 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080013231 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg6ff57cf2013-05-16 00:55:00 +020013232 const struct ieee80211_mgmt *mgmt = (void *)buf;
13233 u32 cmd;
Jouni Malinencf4e5942010-12-16 00:52:40 +020013234
Johannes Berg6ff57cf2013-05-16 00:55:00 +020013235 if (WARN_ON(len < 2))
13236 return;
13237
13238 if (ieee80211_is_deauth(mgmt->frame_control))
13239 cmd = NL80211_CMD_UNPROT_DEAUTHENTICATE;
13240 else
13241 cmd = NL80211_CMD_UNPROT_DISASSOCIATE;
13242
13243 trace_cfg80211_rx_unprot_mlme_mgmt(dev, buf, len);
Eliad Pellerb0b6aa22014-09-09 17:09:45 +030013244 nl80211_send_mlme_event(rdev, dev, buf, len, cmd, GFP_ATOMIC, -1);
Jouni Malinencf4e5942010-12-16 00:52:40 +020013245}
Johannes Berg6ff57cf2013-05-16 00:55:00 +020013246EXPORT_SYMBOL(cfg80211_rx_unprot_mlme_mgmt);
Jouni Malinencf4e5942010-12-16 00:52:40 +020013247
Luis R. Rodriguez1b06bb42009-05-02 00:34:48 -040013248static void nl80211_send_mlme_timeout(struct cfg80211_registered_device *rdev,
13249 struct net_device *netdev, int cmd,
Johannes Berge6d6e342009-07-01 21:26:47 +020013250 const u8 *addr, gfp_t gfp)
Jouni Malinen1965c852009-04-22 21:38:25 +030013251{
13252 struct sk_buff *msg;
13253 void *hdr;
13254
Johannes Berge6d6e342009-07-01 21:26:47 +020013255 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +030013256 if (!msg)
13257 return;
13258
13259 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
13260 if (!hdr) {
13261 nlmsg_free(msg);
13262 return;
13263 }
13264
David S. Miller9360ffd2012-03-29 04:41:26 -040013265 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
13266 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
13267 nla_put_flag(msg, NL80211_ATTR_TIMED_OUT) ||
13268 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr))
13269 goto nla_put_failure;
Jouni Malinen1965c852009-04-22 21:38:25 +030013270
Johannes Berg3b7b72e2011-10-22 19:05:51 +020013271 genlmsg_end(msg, hdr);
Jouni Malinen1965c852009-04-22 21:38:25 +030013272
Johannes Berg68eb5502013-11-19 15:19:38 +010013273 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010013274 NL80211_MCGRP_MLME, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +030013275 return;
13276
13277 nla_put_failure:
13278 genlmsg_cancel(msg, hdr);
13279 nlmsg_free(msg);
13280}
13281
13282void nl80211_send_auth_timeout(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +020013283 struct net_device *netdev, const u8 *addr,
13284 gfp_t gfp)
Jouni Malinen1965c852009-04-22 21:38:25 +030013285{
13286 nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_AUTHENTICATE,
Johannes Berge6d6e342009-07-01 21:26:47 +020013287 addr, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +030013288}
13289
13290void nl80211_send_assoc_timeout(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +020013291 struct net_device *netdev, const u8 *addr,
13292 gfp_t gfp)
Jouni Malinen1965c852009-04-22 21:38:25 +030013293{
Johannes Berge6d6e342009-07-01 21:26:47 +020013294 nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_ASSOCIATE,
13295 addr, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +030013296}
13297
Samuel Ortizb23aa672009-07-01 21:26:54 +020013298void nl80211_send_connect_result(struct cfg80211_registered_device *rdev,
13299 struct net_device *netdev, const u8 *bssid,
13300 const u8 *req_ie, size_t req_ie_len,
13301 const u8 *resp_ie, size_t resp_ie_len,
Purushottam Kushwaha3093ebbeab2017-01-13 01:12:21 +020013302 int status,
13303 enum nl80211_timeout_reason timeout_reason,
13304 gfp_t gfp)
Samuel Ortizb23aa672009-07-01 21:26:54 +020013305{
13306 struct sk_buff *msg;
13307 void *hdr;
13308
Johannes Berg4ef8c1c2017-01-09 11:10:42 +010013309 msg = nlmsg_new(100 + req_ie_len + resp_ie_len, gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +020013310 if (!msg)
13311 return;
13312
13313 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONNECT);
13314 if (!hdr) {
13315 nlmsg_free(msg);
13316 return;
13317 }
13318
David S. Miller9360ffd2012-03-29 04:41:26 -040013319 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
13320 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
13321 (bssid && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) ||
Jouni Malinenbf1ecd22016-05-31 00:16:50 +030013322 nla_put_u16(msg, NL80211_ATTR_STATUS_CODE,
13323 status < 0 ? WLAN_STATUS_UNSPECIFIED_FAILURE :
13324 status) ||
Purushottam Kushwaha3093ebbeab2017-01-13 01:12:21 +020013325 (status < 0 &&
13326 (nla_put_flag(msg, NL80211_ATTR_TIMED_OUT) ||
13327 nla_put_u32(msg, NL80211_ATTR_TIMEOUT_REASON, timeout_reason))) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040013328 (req_ie &&
13329 nla_put(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie)) ||
13330 (resp_ie &&
13331 nla_put(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie)))
13332 goto nla_put_failure;
Samuel Ortizb23aa672009-07-01 21:26:54 +020013333
Johannes Berg3b7b72e2011-10-22 19:05:51 +020013334 genlmsg_end(msg, hdr);
Samuel Ortizb23aa672009-07-01 21:26:54 +020013335
Johannes Berg68eb5502013-11-19 15:19:38 +010013336 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010013337 NL80211_MCGRP_MLME, gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +020013338 return;
13339
13340 nla_put_failure:
13341 genlmsg_cancel(msg, hdr);
13342 nlmsg_free(msg);
Samuel Ortizb23aa672009-07-01 21:26:54 +020013343}
13344
13345void nl80211_send_roamed(struct cfg80211_registered_device *rdev,
13346 struct net_device *netdev, const u8 *bssid,
13347 const u8 *req_ie, size_t req_ie_len,
13348 const u8 *resp_ie, size_t resp_ie_len, gfp_t gfp)
13349{
13350 struct sk_buff *msg;
13351 void *hdr;
13352
Johannes Berg4ef8c1c2017-01-09 11:10:42 +010013353 msg = nlmsg_new(100 + req_ie_len + resp_ie_len, gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +020013354 if (!msg)
13355 return;
13356
13357 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_ROAM);
13358 if (!hdr) {
13359 nlmsg_free(msg);
13360 return;
13361 }
13362
David S. Miller9360ffd2012-03-29 04:41:26 -040013363 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
13364 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
13365 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid) ||
13366 (req_ie &&
13367 nla_put(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie)) ||
13368 (resp_ie &&
13369 nla_put(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie)))
13370 goto nla_put_failure;
Samuel Ortizb23aa672009-07-01 21:26:54 +020013371
Johannes Berg3b7b72e2011-10-22 19:05:51 +020013372 genlmsg_end(msg, hdr);
Samuel Ortizb23aa672009-07-01 21:26:54 +020013373
Johannes Berg68eb5502013-11-19 15:19:38 +010013374 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010013375 NL80211_MCGRP_MLME, gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +020013376 return;
13377
13378 nla_put_failure:
13379 genlmsg_cancel(msg, hdr);
13380 nlmsg_free(msg);
Samuel Ortizb23aa672009-07-01 21:26:54 +020013381}
13382
13383void nl80211_send_disconnected(struct cfg80211_registered_device *rdev,
13384 struct net_device *netdev, u16 reason,
Johannes Berg667503d2009-07-07 03:56:11 +020013385 const u8 *ie, size_t ie_len, bool from_ap)
Samuel Ortizb23aa672009-07-01 21:26:54 +020013386{
13387 struct sk_buff *msg;
13388 void *hdr;
13389
Johannes Berg4ef8c1c2017-01-09 11:10:42 +010013390 msg = nlmsg_new(100 + ie_len, GFP_KERNEL);
Samuel Ortizb23aa672009-07-01 21:26:54 +020013391 if (!msg)
13392 return;
13393
13394 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DISCONNECT);
13395 if (!hdr) {
13396 nlmsg_free(msg);
13397 return;
13398 }
13399
David S. Miller9360ffd2012-03-29 04:41:26 -040013400 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
13401 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
13402 (from_ap && reason &&
13403 nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason)) ||
13404 (from_ap &&
13405 nla_put_flag(msg, NL80211_ATTR_DISCONNECTED_BY_AP)) ||
13406 (ie && nla_put(msg, NL80211_ATTR_IE, ie_len, ie)))
13407 goto nla_put_failure;
Samuel Ortizb23aa672009-07-01 21:26:54 +020013408
Johannes Berg3b7b72e2011-10-22 19:05:51 +020013409 genlmsg_end(msg, hdr);
Samuel Ortizb23aa672009-07-01 21:26:54 +020013410
Johannes Berg68eb5502013-11-19 15:19:38 +010013411 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010013412 NL80211_MCGRP_MLME, GFP_KERNEL);
Samuel Ortizb23aa672009-07-01 21:26:54 +020013413 return;
13414
13415 nla_put_failure:
13416 genlmsg_cancel(msg, hdr);
13417 nlmsg_free(msg);
Samuel Ortizb23aa672009-07-01 21:26:54 +020013418}
13419
Johannes Berg04a773a2009-04-19 21:24:32 +020013420void nl80211_send_ibss_bssid(struct cfg80211_registered_device *rdev,
13421 struct net_device *netdev, const u8 *bssid,
13422 gfp_t gfp)
13423{
13424 struct sk_buff *msg;
13425 void *hdr;
13426
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -070013427 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Johannes Berg04a773a2009-04-19 21:24:32 +020013428 if (!msg)
13429 return;
13430
13431 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_JOIN_IBSS);
13432 if (!hdr) {
13433 nlmsg_free(msg);
13434 return;
13435 }
13436
David S. Miller9360ffd2012-03-29 04:41:26 -040013437 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
13438 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
13439 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid))
13440 goto nla_put_failure;
Johannes Berg04a773a2009-04-19 21:24:32 +020013441
Johannes Berg3b7b72e2011-10-22 19:05:51 +020013442 genlmsg_end(msg, hdr);
Johannes Berg04a773a2009-04-19 21:24:32 +020013443
Johannes Berg68eb5502013-11-19 15:19:38 +010013444 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010013445 NL80211_MCGRP_MLME, gfp);
Johannes Berg04a773a2009-04-19 21:24:32 +020013446 return;
13447
13448 nla_put_failure:
13449 genlmsg_cancel(msg, hdr);
13450 nlmsg_free(msg);
13451}
13452
Johannes Berg947add32013-02-22 22:05:20 +010013453void cfg80211_notify_new_peer_candidate(struct net_device *dev, const u8 *addr,
13454 const u8* ie, u8 ie_len, gfp_t gfp)
Javier Cardonac93b5e72011-04-07 15:08:34 -070013455{
Johannes Berg947add32013-02-22 22:05:20 +010013456 struct wireless_dev *wdev = dev->ieee80211_ptr;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080013457 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Javier Cardonac93b5e72011-04-07 15:08:34 -070013458 struct sk_buff *msg;
13459 void *hdr;
13460
Johannes Berg947add32013-02-22 22:05:20 +010013461 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_MESH_POINT))
13462 return;
13463
13464 trace_cfg80211_notify_new_peer_candidate(dev, addr);
13465
Johannes Berg4ef8c1c2017-01-09 11:10:42 +010013466 msg = nlmsg_new(100 + ie_len, gfp);
Javier Cardonac93b5e72011-04-07 15:08:34 -070013467 if (!msg)
13468 return;
13469
13470 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NEW_PEER_CANDIDATE);
13471 if (!hdr) {
13472 nlmsg_free(msg);
13473 return;
13474 }
13475
David S. Miller9360ffd2012-03-29 04:41:26 -040013476 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg947add32013-02-22 22:05:20 +010013477 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
13478 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040013479 (ie_len && ie &&
13480 nla_put(msg, NL80211_ATTR_IE, ie_len , ie)))
13481 goto nla_put_failure;
Javier Cardonac93b5e72011-04-07 15:08:34 -070013482
Johannes Berg3b7b72e2011-10-22 19:05:51 +020013483 genlmsg_end(msg, hdr);
Javier Cardonac93b5e72011-04-07 15:08:34 -070013484
Johannes Berg68eb5502013-11-19 15:19:38 +010013485 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010013486 NL80211_MCGRP_MLME, gfp);
Javier Cardonac93b5e72011-04-07 15:08:34 -070013487 return;
13488
13489 nla_put_failure:
13490 genlmsg_cancel(msg, hdr);
13491 nlmsg_free(msg);
13492}
Johannes Berg947add32013-02-22 22:05:20 +010013493EXPORT_SYMBOL(cfg80211_notify_new_peer_candidate);
Javier Cardonac93b5e72011-04-07 15:08:34 -070013494
Jouni Malinena3b8b052009-03-27 21:59:49 +020013495void nl80211_michael_mic_failure(struct cfg80211_registered_device *rdev,
13496 struct net_device *netdev, const u8 *addr,
13497 enum nl80211_key_type key_type, int key_id,
Johannes Berge6d6e342009-07-01 21:26:47 +020013498 const u8 *tsc, gfp_t gfp)
Jouni Malinena3b8b052009-03-27 21:59:49 +020013499{
13500 struct sk_buff *msg;
13501 void *hdr;
13502
Johannes Berge6d6e342009-07-01 21:26:47 +020013503 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinena3b8b052009-03-27 21:59:49 +020013504 if (!msg)
13505 return;
13506
13507 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_MICHAEL_MIC_FAILURE);
13508 if (!hdr) {
13509 nlmsg_free(msg);
13510 return;
13511 }
13512
David S. Miller9360ffd2012-03-29 04:41:26 -040013513 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
13514 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
13515 (addr && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) ||
13516 nla_put_u32(msg, NL80211_ATTR_KEY_TYPE, key_type) ||
13517 (key_id != -1 &&
13518 nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_id)) ||
13519 (tsc && nla_put(msg, NL80211_ATTR_KEY_SEQ, 6, tsc)))
13520 goto nla_put_failure;
Jouni Malinena3b8b052009-03-27 21:59:49 +020013521
Johannes Berg3b7b72e2011-10-22 19:05:51 +020013522 genlmsg_end(msg, hdr);
Jouni Malinena3b8b052009-03-27 21:59:49 +020013523
Johannes Berg68eb5502013-11-19 15:19:38 +010013524 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010013525 NL80211_MCGRP_MLME, gfp);
Jouni Malinena3b8b052009-03-27 21:59:49 +020013526 return;
13527
13528 nla_put_failure:
13529 genlmsg_cancel(msg, hdr);
13530 nlmsg_free(msg);
13531}
13532
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040013533void nl80211_send_beacon_hint_event(struct wiphy *wiphy,
13534 struct ieee80211_channel *channel_before,
13535 struct ieee80211_channel *channel_after)
13536{
13537 struct sk_buff *msg;
13538 void *hdr;
13539 struct nlattr *nl_freq;
13540
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -070013541 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_ATOMIC);
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040013542 if (!msg)
13543 return;
13544
13545 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_BEACON_HINT);
13546 if (!hdr) {
13547 nlmsg_free(msg);
13548 return;
13549 }
13550
13551 /*
13552 * Since we are applying the beacon hint to a wiphy we know its
13553 * wiphy_idx is valid
13554 */
David S. Miller9360ffd2012-03-29 04:41:26 -040013555 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy)))
13556 goto nla_put_failure;
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040013557
13558 /* Before */
13559 nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_BEFORE);
13560 if (!nl_freq)
13561 goto nla_put_failure;
Johannes Bergcdc89b92013-02-18 23:54:36 +010013562 if (nl80211_msg_put_channel(msg, channel_before, false))
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040013563 goto nla_put_failure;
13564 nla_nest_end(msg, nl_freq);
13565
13566 /* After */
13567 nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_AFTER);
13568 if (!nl_freq)
13569 goto nla_put_failure;
Johannes Bergcdc89b92013-02-18 23:54:36 +010013570 if (nl80211_msg_put_channel(msg, channel_after, false))
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040013571 goto nla_put_failure;
13572 nla_nest_end(msg, nl_freq);
13573
Johannes Berg3b7b72e2011-10-22 19:05:51 +020013574 genlmsg_end(msg, hdr);
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040013575
Johannes Berg463d0182009-07-14 00:33:35 +020013576 rcu_read_lock();
Johannes Berg68eb5502013-11-19 15:19:38 +010013577 genlmsg_multicast_allns(&nl80211_fam, msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010013578 NL80211_MCGRP_REGULATORY, GFP_ATOMIC);
Johannes Berg463d0182009-07-14 00:33:35 +020013579 rcu_read_unlock();
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040013580
13581 return;
13582
13583nla_put_failure:
13584 genlmsg_cancel(msg, hdr);
13585 nlmsg_free(msg);
13586}
13587
Jouni Malinen9588bbd2009-12-23 13:15:41 +010013588static void nl80211_send_remain_on_chan_event(
13589 int cmd, struct cfg80211_registered_device *rdev,
Johannes Berg71bbc992012-06-15 15:30:18 +020013590 struct wireless_dev *wdev, u64 cookie,
Jouni Malinen9588bbd2009-12-23 13:15:41 +010013591 struct ieee80211_channel *chan,
Jouni Malinen9588bbd2009-12-23 13:15:41 +010013592 unsigned int duration, gfp_t gfp)
13593{
13594 struct sk_buff *msg;
13595 void *hdr;
13596
13597 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
13598 if (!msg)
13599 return;
13600
13601 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
13602 if (!hdr) {
13603 nlmsg_free(msg);
13604 return;
13605 }
13606
David S. Miller9360ffd2012-03-29 04:41:26 -040013607 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg71bbc992012-06-15 15:30:18 +020013608 (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
13609 wdev->netdev->ifindex)) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020013610 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
13611 NL80211_ATTR_PAD) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040013612 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, chan->center_freq) ||
Johannes Berg42d97a52012-11-08 18:31:02 +010013613 nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE,
13614 NL80211_CHAN_NO_HT) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020013615 nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie,
13616 NL80211_ATTR_PAD))
David S. Miller9360ffd2012-03-29 04:41:26 -040013617 goto nla_put_failure;
Jouni Malinen9588bbd2009-12-23 13:15:41 +010013618
David S. Miller9360ffd2012-03-29 04:41:26 -040013619 if (cmd == NL80211_CMD_REMAIN_ON_CHANNEL &&
13620 nla_put_u32(msg, NL80211_ATTR_DURATION, duration))
13621 goto nla_put_failure;
Jouni Malinen9588bbd2009-12-23 13:15:41 +010013622
Johannes Berg3b7b72e2011-10-22 19:05:51 +020013623 genlmsg_end(msg, hdr);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010013624
Johannes Berg68eb5502013-11-19 15:19:38 +010013625 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010013626 NL80211_MCGRP_MLME, gfp);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010013627 return;
13628
13629 nla_put_failure:
13630 genlmsg_cancel(msg, hdr);
13631 nlmsg_free(msg);
13632}
13633
Johannes Berg947add32013-02-22 22:05:20 +010013634void cfg80211_ready_on_channel(struct wireless_dev *wdev, u64 cookie,
13635 struct ieee80211_channel *chan,
13636 unsigned int duration, gfp_t gfp)
Jouni Malinen9588bbd2009-12-23 13:15:41 +010013637{
Johannes Berg947add32013-02-22 22:05:20 +010013638 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080013639 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg947add32013-02-22 22:05:20 +010013640
13641 trace_cfg80211_ready_on_channel(wdev, cookie, chan, duration);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010013642 nl80211_send_remain_on_chan_event(NL80211_CMD_REMAIN_ON_CHANNEL,
Johannes Berg71bbc992012-06-15 15:30:18 +020013643 rdev, wdev, cookie, chan,
Johannes Berg42d97a52012-11-08 18:31:02 +010013644 duration, gfp);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010013645}
Johannes Berg947add32013-02-22 22:05:20 +010013646EXPORT_SYMBOL(cfg80211_ready_on_channel);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010013647
Johannes Berg947add32013-02-22 22:05:20 +010013648void cfg80211_remain_on_channel_expired(struct wireless_dev *wdev, u64 cookie,
13649 struct ieee80211_channel *chan,
13650 gfp_t gfp)
Jouni Malinen9588bbd2009-12-23 13:15:41 +010013651{
Johannes Berg947add32013-02-22 22:05:20 +010013652 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080013653 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg947add32013-02-22 22:05:20 +010013654
13655 trace_cfg80211_ready_on_channel_expired(wdev, cookie, chan);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010013656 nl80211_send_remain_on_chan_event(NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL,
Johannes Berg42d97a52012-11-08 18:31:02 +010013657 rdev, wdev, cookie, chan, 0, gfp);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010013658}
Johannes Berg947add32013-02-22 22:05:20 +010013659EXPORT_SYMBOL(cfg80211_remain_on_channel_expired);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010013660
Johannes Berg947add32013-02-22 22:05:20 +010013661void cfg80211_new_sta(struct net_device *dev, const u8 *mac_addr,
13662 struct station_info *sinfo, gfp_t gfp)
Johannes Berg98b62182009-12-23 13:15:44 +010013663{
Johannes Berg947add32013-02-22 22:05:20 +010013664 struct wiphy *wiphy = dev->ieee80211_ptr->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080013665 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg98b62182009-12-23 13:15:44 +010013666 struct sk_buff *msg;
13667
Johannes Berg947add32013-02-22 22:05:20 +010013668 trace_cfg80211_new_sta(dev, mac_addr, sinfo);
13669
Thomas Graf58050fc2012-06-28 03:57:45 +000013670 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Johannes Berg98b62182009-12-23 13:15:44 +010013671 if (!msg)
13672 return;
13673
Johannes Bergcf5ead82014-11-14 17:14:00 +010013674 if (nl80211_send_station(msg, NL80211_CMD_NEW_STATION, 0, 0, 0,
John W. Linville66266b32012-03-15 13:25:41 -040013675 rdev, dev, mac_addr, sinfo) < 0) {
Johannes Berg98b62182009-12-23 13:15:44 +010013676 nlmsg_free(msg);
13677 return;
13678 }
13679
Johannes Berg68eb5502013-11-19 15:19:38 +010013680 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010013681 NL80211_MCGRP_MLME, gfp);
Johannes Berg98b62182009-12-23 13:15:44 +010013682}
Johannes Berg947add32013-02-22 22:05:20 +010013683EXPORT_SYMBOL(cfg80211_new_sta);
Johannes Berg98b62182009-12-23 13:15:44 +010013684
Johannes Bergcf5ead82014-11-14 17:14:00 +010013685void cfg80211_del_sta_sinfo(struct net_device *dev, const u8 *mac_addr,
13686 struct station_info *sinfo, gfp_t gfp)
Jouni Malinenec15e682011-03-23 15:29:52 +020013687{
Johannes Berg947add32013-02-22 22:05:20 +010013688 struct wiphy *wiphy = dev->ieee80211_ptr->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080013689 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Jouni Malinenec15e682011-03-23 15:29:52 +020013690 struct sk_buff *msg;
Johannes Bergcf5ead82014-11-14 17:14:00 +010013691 struct station_info empty_sinfo = {};
13692
13693 if (!sinfo)
13694 sinfo = &empty_sinfo;
Jouni Malinenec15e682011-03-23 15:29:52 +020013695
Johannes Berg947add32013-02-22 22:05:20 +010013696 trace_cfg80211_del_sta(dev, mac_addr);
13697
Thomas Graf58050fc2012-06-28 03:57:45 +000013698 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinenec15e682011-03-23 15:29:52 +020013699 if (!msg)
13700 return;
13701
Johannes Bergcf5ead82014-11-14 17:14:00 +010013702 if (nl80211_send_station(msg, NL80211_CMD_DEL_STATION, 0, 0, 0,
Johannes Berg57007122015-01-16 21:05:02 +010013703 rdev, dev, mac_addr, sinfo) < 0) {
Jouni Malinenec15e682011-03-23 15:29:52 +020013704 nlmsg_free(msg);
13705 return;
13706 }
13707
Johannes Berg68eb5502013-11-19 15:19:38 +010013708 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010013709 NL80211_MCGRP_MLME, gfp);
Jouni Malinenec15e682011-03-23 15:29:52 +020013710}
Johannes Bergcf5ead82014-11-14 17:14:00 +010013711EXPORT_SYMBOL(cfg80211_del_sta_sinfo);
Jouni Malinenec15e682011-03-23 15:29:52 +020013712
Johannes Berg947add32013-02-22 22:05:20 +010013713void cfg80211_conn_failed(struct net_device *dev, const u8 *mac_addr,
13714 enum nl80211_connect_failed_reason reason,
13715 gfp_t gfp)
Pandiyarajan Pitchaimuthued44a952012-09-18 16:50:49 +053013716{
Johannes Berg947add32013-02-22 22:05:20 +010013717 struct wiphy *wiphy = dev->ieee80211_ptr->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080013718 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Pandiyarajan Pitchaimuthued44a952012-09-18 16:50:49 +053013719 struct sk_buff *msg;
13720 void *hdr;
13721
13722 msg = nlmsg_new(NLMSG_GOODSIZE, gfp);
13723 if (!msg)
13724 return;
13725
13726 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONN_FAILED);
13727 if (!hdr) {
13728 nlmsg_free(msg);
13729 return;
13730 }
13731
13732 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
13733 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) ||
13734 nla_put_u32(msg, NL80211_ATTR_CONN_FAILED_REASON, reason))
13735 goto nla_put_failure;
13736
13737 genlmsg_end(msg, hdr);
13738
Johannes Berg68eb5502013-11-19 15:19:38 +010013739 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010013740 NL80211_MCGRP_MLME, gfp);
Pandiyarajan Pitchaimuthued44a952012-09-18 16:50:49 +053013741 return;
13742
13743 nla_put_failure:
13744 genlmsg_cancel(msg, hdr);
13745 nlmsg_free(msg);
13746}
Johannes Berg947add32013-02-22 22:05:20 +010013747EXPORT_SYMBOL(cfg80211_conn_failed);
Pandiyarajan Pitchaimuthued44a952012-09-18 16:50:49 +053013748
Johannes Bergb92ab5d2011-11-04 11:18:19 +010013749static bool __nl80211_unexpected_frame(struct net_device *dev, u8 cmd,
13750 const u8 *addr, gfp_t gfp)
Johannes Berg28946da2011-11-04 11:18:12 +010013751{
13752 struct wireless_dev *wdev = dev->ieee80211_ptr;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080013753 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Johannes Berg28946da2011-11-04 11:18:12 +010013754 struct sk_buff *msg;
13755 void *hdr;
Eric W. Biederman15e47302012-09-07 20:12:54 +000013756 u32 nlportid = ACCESS_ONCE(wdev->ap_unexpected_nlportid);
Johannes Berg28946da2011-11-04 11:18:12 +010013757
Eric W. Biederman15e47302012-09-07 20:12:54 +000013758 if (!nlportid)
Johannes Berg28946da2011-11-04 11:18:12 +010013759 return false;
13760
13761 msg = nlmsg_new(100, gfp);
13762 if (!msg)
13763 return true;
13764
Johannes Bergb92ab5d2011-11-04 11:18:19 +010013765 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
Johannes Berg28946da2011-11-04 11:18:12 +010013766 if (!hdr) {
13767 nlmsg_free(msg);
13768 return true;
13769 }
13770
David S. Miller9360ffd2012-03-29 04:41:26 -040013771 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
13772 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
13773 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr))
13774 goto nla_put_failure;
Johannes Berg28946da2011-11-04 11:18:12 +010013775
Johannes Berg9c90a9f2013-06-04 12:46:03 +020013776 genlmsg_end(msg, hdr);
Eric W. Biederman15e47302012-09-07 20:12:54 +000013777 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid);
Johannes Berg28946da2011-11-04 11:18:12 +010013778 return true;
13779
13780 nla_put_failure:
13781 genlmsg_cancel(msg, hdr);
13782 nlmsg_free(msg);
13783 return true;
13784}
13785
Johannes Berg947add32013-02-22 22:05:20 +010013786bool cfg80211_rx_spurious_frame(struct net_device *dev,
13787 const u8 *addr, gfp_t gfp)
Johannes Bergb92ab5d2011-11-04 11:18:19 +010013788{
Johannes Berg947add32013-02-22 22:05:20 +010013789 struct wireless_dev *wdev = dev->ieee80211_ptr;
13790 bool ret;
Johannes Bergb92ab5d2011-11-04 11:18:19 +010013791
Johannes Berg947add32013-02-22 22:05:20 +010013792 trace_cfg80211_rx_spurious_frame(dev, addr);
13793
13794 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP &&
13795 wdev->iftype != NL80211_IFTYPE_P2P_GO)) {
13796 trace_cfg80211_return_bool(false);
13797 return false;
13798 }
13799 ret = __nl80211_unexpected_frame(dev, NL80211_CMD_UNEXPECTED_FRAME,
13800 addr, gfp);
13801 trace_cfg80211_return_bool(ret);
13802 return ret;
Johannes Bergb92ab5d2011-11-04 11:18:19 +010013803}
Johannes Berg947add32013-02-22 22:05:20 +010013804EXPORT_SYMBOL(cfg80211_rx_spurious_frame);
13805
13806bool cfg80211_rx_unexpected_4addr_frame(struct net_device *dev,
13807 const u8 *addr, gfp_t gfp)
13808{
13809 struct wireless_dev *wdev = dev->ieee80211_ptr;
13810 bool ret;
13811
13812 trace_cfg80211_rx_unexpected_4addr_frame(dev, addr);
13813
13814 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP &&
13815 wdev->iftype != NL80211_IFTYPE_P2P_GO &&
13816 wdev->iftype != NL80211_IFTYPE_AP_VLAN)) {
13817 trace_cfg80211_return_bool(false);
13818 return false;
13819 }
13820 ret = __nl80211_unexpected_frame(dev,
13821 NL80211_CMD_UNEXPECTED_4ADDR_FRAME,
13822 addr, gfp);
13823 trace_cfg80211_return_bool(ret);
13824 return ret;
13825}
13826EXPORT_SYMBOL(cfg80211_rx_unexpected_4addr_frame);
Johannes Bergb92ab5d2011-11-04 11:18:19 +010013827
Johannes Berg2e161f72010-08-12 15:38:38 +020013828int nl80211_send_mgmt(struct cfg80211_registered_device *rdev,
Eric W. Biederman15e47302012-09-07 20:12:54 +000013829 struct wireless_dev *wdev, u32 nlportid,
Johannes Berg804483e2012-03-05 22:18:41 +010013830 int freq, int sig_dbm,
Vladimir Kondratiev19504cf2013-08-15 14:51:28 +030013831 const u8 *buf, size_t len, u32 flags, gfp_t gfp)
Jouni Malinen026331c2010-02-15 12:53:10 +020013832{
Johannes Berg71bbc992012-06-15 15:30:18 +020013833 struct net_device *netdev = wdev->netdev;
Jouni Malinen026331c2010-02-15 12:53:10 +020013834 struct sk_buff *msg;
13835 void *hdr;
Jouni Malinen026331c2010-02-15 12:53:10 +020013836
Johannes Berg4ef8c1c2017-01-09 11:10:42 +010013837 msg = nlmsg_new(100 + len, gfp);
Jouni Malinen026331c2010-02-15 12:53:10 +020013838 if (!msg)
13839 return -ENOMEM;
13840
Johannes Berg2e161f72010-08-12 15:38:38 +020013841 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME);
Jouni Malinen026331c2010-02-15 12:53:10 +020013842 if (!hdr) {
13843 nlmsg_free(msg);
13844 return -ENOMEM;
13845 }
13846
David S. Miller9360ffd2012-03-29 04:41:26 -040013847 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg71bbc992012-06-15 15:30:18 +020013848 (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
13849 netdev->ifindex)) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020013850 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
13851 NL80211_ATTR_PAD) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040013852 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq) ||
13853 (sig_dbm &&
13854 nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) ||
Vladimir Kondratiev19504cf2013-08-15 14:51:28 +030013855 nla_put(msg, NL80211_ATTR_FRAME, len, buf) ||
13856 (flags &&
13857 nla_put_u32(msg, NL80211_ATTR_RXMGMT_FLAGS, flags)))
David S. Miller9360ffd2012-03-29 04:41:26 -040013858 goto nla_put_failure;
Jouni Malinen026331c2010-02-15 12:53:10 +020013859
Johannes Berg3b7b72e2011-10-22 19:05:51 +020013860 genlmsg_end(msg, hdr);
Jouni Malinen026331c2010-02-15 12:53:10 +020013861
Eric W. Biederman15e47302012-09-07 20:12:54 +000013862 return genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid);
Jouni Malinen026331c2010-02-15 12:53:10 +020013863
13864 nla_put_failure:
13865 genlmsg_cancel(msg, hdr);
13866 nlmsg_free(msg);
13867 return -ENOBUFS;
13868}
13869
Johannes Berg947add32013-02-22 22:05:20 +010013870void cfg80211_mgmt_tx_status(struct wireless_dev *wdev, u64 cookie,
13871 const u8 *buf, size_t len, bool ack, gfp_t gfp)
Jouni Malinen026331c2010-02-15 12:53:10 +020013872{
Johannes Berg947add32013-02-22 22:05:20 +010013873 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080013874 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg71bbc992012-06-15 15:30:18 +020013875 struct net_device *netdev = wdev->netdev;
Jouni Malinen026331c2010-02-15 12:53:10 +020013876 struct sk_buff *msg;
13877 void *hdr;
13878
Johannes Berg947add32013-02-22 22:05:20 +010013879 trace_cfg80211_mgmt_tx_status(wdev, cookie, ack);
13880
Johannes Berg4ef8c1c2017-01-09 11:10:42 +010013881 msg = nlmsg_new(100 + len, gfp);
Jouni Malinen026331c2010-02-15 12:53:10 +020013882 if (!msg)
13883 return;
13884
Johannes Berg2e161f72010-08-12 15:38:38 +020013885 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME_TX_STATUS);
Jouni Malinen026331c2010-02-15 12:53:10 +020013886 if (!hdr) {
13887 nlmsg_free(msg);
13888 return;
13889 }
13890
David S. Miller9360ffd2012-03-29 04:41:26 -040013891 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg71bbc992012-06-15 15:30:18 +020013892 (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
13893 netdev->ifindex)) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020013894 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
13895 NL80211_ATTR_PAD) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040013896 nla_put(msg, NL80211_ATTR_FRAME, len, buf) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020013897 nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie,
13898 NL80211_ATTR_PAD) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040013899 (ack && nla_put_flag(msg, NL80211_ATTR_ACK)))
13900 goto nla_put_failure;
Jouni Malinen026331c2010-02-15 12:53:10 +020013901
Johannes Berg3b7b72e2011-10-22 19:05:51 +020013902 genlmsg_end(msg, hdr);
Jouni Malinen026331c2010-02-15 12:53:10 +020013903
Johannes Berg68eb5502013-11-19 15:19:38 +010013904 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010013905 NL80211_MCGRP_MLME, gfp);
Jouni Malinen026331c2010-02-15 12:53:10 +020013906 return;
13907
13908 nla_put_failure:
13909 genlmsg_cancel(msg, hdr);
13910 nlmsg_free(msg);
13911}
Johannes Berg947add32013-02-22 22:05:20 +010013912EXPORT_SYMBOL(cfg80211_mgmt_tx_status);
Jouni Malinen026331c2010-02-15 12:53:10 +020013913
Johannes Berg5b97f492014-11-26 12:37:43 +010013914static struct sk_buff *cfg80211_prepare_cqm(struct net_device *dev,
13915 const char *mac, gfp_t gfp)
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020013916{
Johannes Berg947add32013-02-22 22:05:20 +010013917 struct wireless_dev *wdev = dev->ieee80211_ptr;
Johannes Berg5b97f492014-11-26 12:37:43 +010013918 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
13919 struct sk_buff *msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
13920 void **cb;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020013921
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020013922 if (!msg)
Johannes Berg5b97f492014-11-26 12:37:43 +010013923 return NULL;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020013924
Johannes Berg5b97f492014-11-26 12:37:43 +010013925 cb = (void **)msg->cb;
13926
13927 cb[0] = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM);
13928 if (!cb[0]) {
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020013929 nlmsg_free(msg);
Johannes Berg5b97f492014-11-26 12:37:43 +010013930 return NULL;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020013931 }
13932
David S. Miller9360ffd2012-03-29 04:41:26 -040013933 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg947add32013-02-22 22:05:20 +010013934 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex))
David S. Miller9360ffd2012-03-29 04:41:26 -040013935 goto nla_put_failure;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020013936
Johannes Berg5b97f492014-11-26 12:37:43 +010013937 if (mac && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac))
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020013938 goto nla_put_failure;
13939
Johannes Berg5b97f492014-11-26 12:37:43 +010013940 cb[1] = nla_nest_start(msg, NL80211_ATTR_CQM);
13941 if (!cb[1])
13942 goto nla_put_failure;
13943
13944 cb[2] = rdev;
13945
13946 return msg;
13947 nla_put_failure:
13948 nlmsg_free(msg);
13949 return NULL;
13950}
13951
13952static void cfg80211_send_cqm(struct sk_buff *msg, gfp_t gfp)
13953{
13954 void **cb = (void **)msg->cb;
13955 struct cfg80211_registered_device *rdev = cb[2];
13956
13957 nla_nest_end(msg, cb[1]);
13958 genlmsg_end(msg, cb[0]);
13959
13960 memset(msg->cb, 0, sizeof(msg->cb));
13961
13962 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
13963 NL80211_MCGRP_MLME, gfp);
13964}
13965
13966void cfg80211_cqm_rssi_notify(struct net_device *dev,
13967 enum nl80211_cqm_rssi_threshold_event rssi_event,
Andrzej Zaborowskibee427b2017-01-25 12:43:41 +010013968 s32 rssi_level, gfp_t gfp)
Johannes Berg5b97f492014-11-26 12:37:43 +010013969{
13970 struct sk_buff *msg;
13971
Andrzej Zaborowskibee427b2017-01-25 12:43:41 +010013972 trace_cfg80211_cqm_rssi_notify(dev, rssi_event, rssi_level);
Johannes Berg5b97f492014-11-26 12:37:43 +010013973
Johannes Berg98f03342014-11-26 12:42:02 +010013974 if (WARN_ON(rssi_event != NL80211_CQM_RSSI_THRESHOLD_EVENT_LOW &&
13975 rssi_event != NL80211_CQM_RSSI_THRESHOLD_EVENT_HIGH))
13976 return;
13977
Johannes Berg5b97f492014-11-26 12:37:43 +010013978 msg = cfg80211_prepare_cqm(dev, NULL, gfp);
13979 if (!msg)
13980 return;
13981
David S. Miller9360ffd2012-03-29 04:41:26 -040013982 if (nla_put_u32(msg, NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT,
13983 rssi_event))
13984 goto nla_put_failure;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020013985
Andrzej Zaborowskibee427b2017-01-25 12:43:41 +010013986 if (rssi_level && nla_put_s32(msg, NL80211_ATTR_CQM_RSSI_LEVEL,
13987 rssi_level))
13988 goto nla_put_failure;
13989
Johannes Berg5b97f492014-11-26 12:37:43 +010013990 cfg80211_send_cqm(msg, gfp);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020013991
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020013992 return;
13993
13994 nla_put_failure:
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020013995 nlmsg_free(msg);
13996}
Johannes Berg947add32013-02-22 22:05:20 +010013997EXPORT_SYMBOL(cfg80211_cqm_rssi_notify);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020013998
Johannes Berg5b97f492014-11-26 12:37:43 +010013999void cfg80211_cqm_txe_notify(struct net_device *dev,
14000 const u8 *peer, u32 num_packets,
14001 u32 rate, u32 intvl, gfp_t gfp)
14002{
14003 struct sk_buff *msg;
14004
14005 msg = cfg80211_prepare_cqm(dev, peer, gfp);
14006 if (!msg)
14007 return;
14008
14009 if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_PKTS, num_packets))
14010 goto nla_put_failure;
14011
14012 if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_RATE, rate))
14013 goto nla_put_failure;
14014
14015 if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_INTVL, intvl))
14016 goto nla_put_failure;
14017
14018 cfg80211_send_cqm(msg, gfp);
14019 return;
14020
14021 nla_put_failure:
14022 nlmsg_free(msg);
14023}
14024EXPORT_SYMBOL(cfg80211_cqm_txe_notify);
14025
14026void cfg80211_cqm_pktloss_notify(struct net_device *dev,
14027 const u8 *peer, u32 num_packets, gfp_t gfp)
14028{
14029 struct sk_buff *msg;
14030
14031 trace_cfg80211_cqm_pktloss_notify(dev, peer, num_packets);
14032
14033 msg = cfg80211_prepare_cqm(dev, peer, gfp);
14034 if (!msg)
14035 return;
14036
14037 if (nla_put_u32(msg, NL80211_ATTR_CQM_PKT_LOSS_EVENT, num_packets))
14038 goto nla_put_failure;
14039
14040 cfg80211_send_cqm(msg, gfp);
14041 return;
14042
14043 nla_put_failure:
14044 nlmsg_free(msg);
14045}
14046EXPORT_SYMBOL(cfg80211_cqm_pktloss_notify);
14047
Johannes Berg98f03342014-11-26 12:42:02 +010014048void cfg80211_cqm_beacon_loss_notify(struct net_device *dev, gfp_t gfp)
14049{
14050 struct sk_buff *msg;
14051
14052 msg = cfg80211_prepare_cqm(dev, NULL, gfp);
14053 if (!msg)
14054 return;
14055
14056 if (nla_put_flag(msg, NL80211_ATTR_CQM_BEACON_LOSS_EVENT))
14057 goto nla_put_failure;
14058
14059 cfg80211_send_cqm(msg, gfp);
14060 return;
14061
14062 nla_put_failure:
14063 nlmsg_free(msg);
14064}
14065EXPORT_SYMBOL(cfg80211_cqm_beacon_loss_notify);
14066
Johannes Berg947add32013-02-22 22:05:20 +010014067static void nl80211_gtk_rekey_notify(struct cfg80211_registered_device *rdev,
14068 struct net_device *netdev, const u8 *bssid,
14069 const u8 *replay_ctr, gfp_t gfp)
Johannes Berge5497d72011-07-05 16:35:40 +020014070{
14071 struct sk_buff *msg;
14072 struct nlattr *rekey_attr;
14073 void *hdr;
14074
Thomas Graf58050fc2012-06-28 03:57:45 +000014075 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Johannes Berge5497d72011-07-05 16:35:40 +020014076 if (!msg)
14077 return;
14078
14079 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_REKEY_OFFLOAD);
14080 if (!hdr) {
14081 nlmsg_free(msg);
14082 return;
14083 }
14084
David S. Miller9360ffd2012-03-29 04:41:26 -040014085 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
14086 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
14087 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid))
14088 goto nla_put_failure;
Johannes Berge5497d72011-07-05 16:35:40 +020014089
14090 rekey_attr = nla_nest_start(msg, NL80211_ATTR_REKEY_DATA);
14091 if (!rekey_attr)
14092 goto nla_put_failure;
14093
David S. Miller9360ffd2012-03-29 04:41:26 -040014094 if (nla_put(msg, NL80211_REKEY_DATA_REPLAY_CTR,
14095 NL80211_REPLAY_CTR_LEN, replay_ctr))
14096 goto nla_put_failure;
Johannes Berge5497d72011-07-05 16:35:40 +020014097
14098 nla_nest_end(msg, rekey_attr);
14099
Johannes Berg3b7b72e2011-10-22 19:05:51 +020014100 genlmsg_end(msg, hdr);
Johannes Berge5497d72011-07-05 16:35:40 +020014101
Johannes Berg68eb5502013-11-19 15:19:38 +010014102 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010014103 NL80211_MCGRP_MLME, gfp);
Johannes Berge5497d72011-07-05 16:35:40 +020014104 return;
14105
14106 nla_put_failure:
14107 genlmsg_cancel(msg, hdr);
14108 nlmsg_free(msg);
14109}
14110
Johannes Berg947add32013-02-22 22:05:20 +010014111void cfg80211_gtk_rekey_notify(struct net_device *dev, const u8 *bssid,
14112 const u8 *replay_ctr, gfp_t gfp)
14113{
14114 struct wireless_dev *wdev = dev->ieee80211_ptr;
14115 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080014116 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg947add32013-02-22 22:05:20 +010014117
14118 trace_cfg80211_gtk_rekey_notify(dev, bssid);
14119 nl80211_gtk_rekey_notify(rdev, dev, bssid, replay_ctr, gfp);
14120}
14121EXPORT_SYMBOL(cfg80211_gtk_rekey_notify);
14122
14123static void
14124nl80211_pmksa_candidate_notify(struct cfg80211_registered_device *rdev,
14125 struct net_device *netdev, int index,
14126 const u8 *bssid, bool preauth, gfp_t gfp)
Jouni Malinenc9df56b2011-09-16 18:56:23 +030014127{
14128 struct sk_buff *msg;
14129 struct nlattr *attr;
14130 void *hdr;
14131
Thomas Graf58050fc2012-06-28 03:57:45 +000014132 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinenc9df56b2011-09-16 18:56:23 +030014133 if (!msg)
14134 return;
14135
14136 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PMKSA_CANDIDATE);
14137 if (!hdr) {
14138 nlmsg_free(msg);
14139 return;
14140 }
14141
David S. Miller9360ffd2012-03-29 04:41:26 -040014142 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
14143 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex))
14144 goto nla_put_failure;
Jouni Malinenc9df56b2011-09-16 18:56:23 +030014145
14146 attr = nla_nest_start(msg, NL80211_ATTR_PMKSA_CANDIDATE);
14147 if (!attr)
14148 goto nla_put_failure;
14149
David S. Miller9360ffd2012-03-29 04:41:26 -040014150 if (nla_put_u32(msg, NL80211_PMKSA_CANDIDATE_INDEX, index) ||
14151 nla_put(msg, NL80211_PMKSA_CANDIDATE_BSSID, ETH_ALEN, bssid) ||
14152 (preauth &&
14153 nla_put_flag(msg, NL80211_PMKSA_CANDIDATE_PREAUTH)))
14154 goto nla_put_failure;
Jouni Malinenc9df56b2011-09-16 18:56:23 +030014155
14156 nla_nest_end(msg, attr);
14157
Johannes Berg3b7b72e2011-10-22 19:05:51 +020014158 genlmsg_end(msg, hdr);
Jouni Malinenc9df56b2011-09-16 18:56:23 +030014159
Johannes Berg68eb5502013-11-19 15:19:38 +010014160 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010014161 NL80211_MCGRP_MLME, gfp);
Jouni Malinenc9df56b2011-09-16 18:56:23 +030014162 return;
14163
14164 nla_put_failure:
14165 genlmsg_cancel(msg, hdr);
14166 nlmsg_free(msg);
14167}
14168
Johannes Berg947add32013-02-22 22:05:20 +010014169void cfg80211_pmksa_candidate_notify(struct net_device *dev, int index,
14170 const u8 *bssid, bool preauth, gfp_t gfp)
14171{
14172 struct wireless_dev *wdev = dev->ieee80211_ptr;
14173 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080014174 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg947add32013-02-22 22:05:20 +010014175
14176 trace_cfg80211_pmksa_candidate_notify(dev, index, bssid, preauth);
14177 nl80211_pmksa_candidate_notify(rdev, dev, index, bssid, preauth, gfp);
14178}
14179EXPORT_SYMBOL(cfg80211_pmksa_candidate_notify);
14180
14181static void nl80211_ch_switch_notify(struct cfg80211_registered_device *rdev,
14182 struct net_device *netdev,
14183 struct cfg80211_chan_def *chandef,
Luciano Coelhof8d75522014-11-07 14:31:35 +020014184 gfp_t gfp,
14185 enum nl80211_commands notif,
14186 u8 count)
Thomas Pedersen53145262012-04-06 13:35:47 -070014187{
14188 struct sk_buff *msg;
14189 void *hdr;
14190
Thomas Graf58050fc2012-06-28 03:57:45 +000014191 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Thomas Pedersen53145262012-04-06 13:35:47 -070014192 if (!msg)
14193 return;
14194
Luciano Coelhof8d75522014-11-07 14:31:35 +020014195 hdr = nl80211hdr_put(msg, 0, 0, 0, notif);
Thomas Pedersen53145262012-04-06 13:35:47 -070014196 if (!hdr) {
14197 nlmsg_free(msg);
14198 return;
14199 }
14200
Johannes Berg683b6d32012-11-08 21:25:48 +010014201 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex))
14202 goto nla_put_failure;
14203
14204 if (nl80211_send_chandef(msg, chandef))
John W. Linville7eab0f62012-04-12 14:25:14 -040014205 goto nla_put_failure;
Thomas Pedersen53145262012-04-06 13:35:47 -070014206
Luciano Coelhof8d75522014-11-07 14:31:35 +020014207 if ((notif == NL80211_CMD_CH_SWITCH_STARTED_NOTIFY) &&
14208 (nla_put_u32(msg, NL80211_ATTR_CH_SWITCH_COUNT, count)))
14209 goto nla_put_failure;
14210
Thomas Pedersen53145262012-04-06 13:35:47 -070014211 genlmsg_end(msg, hdr);
14212
Johannes Berg68eb5502013-11-19 15:19:38 +010014213 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010014214 NL80211_MCGRP_MLME, gfp);
Thomas Pedersen53145262012-04-06 13:35:47 -070014215 return;
14216
14217 nla_put_failure:
14218 genlmsg_cancel(msg, hdr);
14219 nlmsg_free(msg);
14220}
14221
Johannes Berg947add32013-02-22 22:05:20 +010014222void cfg80211_ch_switch_notify(struct net_device *dev,
14223 struct cfg80211_chan_def *chandef)
Thomas Pedersen84f10702012-07-12 16:17:33 -070014224{
Johannes Berg947add32013-02-22 22:05:20 +010014225 struct wireless_dev *wdev = dev->ieee80211_ptr;
14226 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080014227 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg947add32013-02-22 22:05:20 +010014228
Simon Wunderliche487eae2013-11-21 18:19:51 +010014229 ASSERT_WDEV_LOCK(wdev);
Johannes Berg947add32013-02-22 22:05:20 +010014230
Simon Wunderliche487eae2013-11-21 18:19:51 +010014231 trace_cfg80211_ch_switch_notify(dev, chandef);
Johannes Berg947add32013-02-22 22:05:20 +010014232
Michal Kazior9e0e2962014-01-29 14:22:27 +010014233 wdev->chandef = *chandef;
Janusz Dziedzic96f55f12014-01-24 14:29:21 +010014234 wdev->preset_chandef = *chandef;
Luciano Coelhof8d75522014-11-07 14:31:35 +020014235 nl80211_ch_switch_notify(rdev, dev, chandef, GFP_KERNEL,
14236 NL80211_CMD_CH_SWITCH_NOTIFY, 0);
Johannes Berg947add32013-02-22 22:05:20 +010014237}
14238EXPORT_SYMBOL(cfg80211_ch_switch_notify);
14239
Luciano Coelhof8d75522014-11-07 14:31:35 +020014240void cfg80211_ch_switch_started_notify(struct net_device *dev,
14241 struct cfg80211_chan_def *chandef,
14242 u8 count)
14243{
14244 struct wireless_dev *wdev = dev->ieee80211_ptr;
14245 struct wiphy *wiphy = wdev->wiphy;
14246 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
14247
14248 trace_cfg80211_ch_switch_started_notify(dev, chandef);
14249
14250 nl80211_ch_switch_notify(rdev, dev, chandef, GFP_KERNEL,
14251 NL80211_CMD_CH_SWITCH_STARTED_NOTIFY, count);
14252}
14253EXPORT_SYMBOL(cfg80211_ch_switch_started_notify);
14254
Thomas Pedersen84f10702012-07-12 16:17:33 -070014255void
Simon Wunderlich04f39042013-02-08 18:16:19 +010014256nl80211_radar_notify(struct cfg80211_registered_device *rdev,
Janusz Dziedzicd2859df2013-11-06 13:55:51 +010014257 const struct cfg80211_chan_def *chandef,
Simon Wunderlich04f39042013-02-08 18:16:19 +010014258 enum nl80211_radar_event event,
14259 struct net_device *netdev, gfp_t gfp)
14260{
14261 struct sk_buff *msg;
14262 void *hdr;
14263
14264 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
14265 if (!msg)
14266 return;
14267
14268 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_RADAR_DETECT);
14269 if (!hdr) {
14270 nlmsg_free(msg);
14271 return;
14272 }
14273
14274 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx))
14275 goto nla_put_failure;
14276
14277 /* NOP and radar events don't need a netdev parameter */
14278 if (netdev) {
14279 struct wireless_dev *wdev = netdev->ieee80211_ptr;
14280
14281 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020014282 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
14283 NL80211_ATTR_PAD))
Simon Wunderlich04f39042013-02-08 18:16:19 +010014284 goto nla_put_failure;
14285 }
14286
14287 if (nla_put_u32(msg, NL80211_ATTR_RADAR_EVENT, event))
14288 goto nla_put_failure;
14289
14290 if (nl80211_send_chandef(msg, chandef))
14291 goto nla_put_failure;
14292
Johannes Berg9c90a9f2013-06-04 12:46:03 +020014293 genlmsg_end(msg, hdr);
Simon Wunderlich04f39042013-02-08 18:16:19 +010014294
Johannes Berg68eb5502013-11-19 15:19:38 +010014295 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010014296 NL80211_MCGRP_MLME, gfp);
Simon Wunderlich04f39042013-02-08 18:16:19 +010014297 return;
14298
14299 nla_put_failure:
14300 genlmsg_cancel(msg, hdr);
14301 nlmsg_free(msg);
14302}
14303
Johannes Berg7f6cf312011-11-04 11:18:15 +010014304void cfg80211_probe_status(struct net_device *dev, const u8 *addr,
14305 u64 cookie, bool acked, gfp_t gfp)
14306{
14307 struct wireless_dev *wdev = dev->ieee80211_ptr;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080014308 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Johannes Berg7f6cf312011-11-04 11:18:15 +010014309 struct sk_buff *msg;
14310 void *hdr;
Johannes Berg7f6cf312011-11-04 11:18:15 +010014311
Beni Lev4ee3e062012-08-27 12:49:39 +030014312 trace_cfg80211_probe_status(dev, addr, cookie, acked);
14313
Thomas Graf58050fc2012-06-28 03:57:45 +000014314 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Beni Lev4ee3e062012-08-27 12:49:39 +030014315
Johannes Berg7f6cf312011-11-04 11:18:15 +010014316 if (!msg)
14317 return;
14318
14319 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PROBE_CLIENT);
14320 if (!hdr) {
14321 nlmsg_free(msg);
14322 return;
14323 }
14324
David S. Miller9360ffd2012-03-29 04:41:26 -040014325 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
14326 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
14327 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020014328 nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie,
14329 NL80211_ATTR_PAD) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040014330 (acked && nla_put_flag(msg, NL80211_ATTR_ACK)))
14331 goto nla_put_failure;
Johannes Berg7f6cf312011-11-04 11:18:15 +010014332
Johannes Berg9c90a9f2013-06-04 12:46:03 +020014333 genlmsg_end(msg, hdr);
Johannes Berg7f6cf312011-11-04 11:18:15 +010014334
Johannes Berg68eb5502013-11-19 15:19:38 +010014335 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010014336 NL80211_MCGRP_MLME, gfp);
Johannes Berg7f6cf312011-11-04 11:18:15 +010014337 return;
14338
14339 nla_put_failure:
14340 genlmsg_cancel(msg, hdr);
14341 nlmsg_free(msg);
14342}
14343EXPORT_SYMBOL(cfg80211_probe_status);
14344
Johannes Berg5e760232011-11-04 11:18:17 +010014345void cfg80211_report_obss_beacon(struct wiphy *wiphy,
14346 const u8 *frame, size_t len,
Ben Greear37c73b52012-10-26 14:49:25 -070014347 int freq, int sig_dbm)
Johannes Berg5e760232011-11-04 11:18:17 +010014348{
Zhao, Gangf26cbf42014-04-21 12:53:03 +080014349 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg5e760232011-11-04 11:18:17 +010014350 struct sk_buff *msg;
14351 void *hdr;
Ben Greear37c73b52012-10-26 14:49:25 -070014352 struct cfg80211_beacon_registration *reg;
Johannes Berg5e760232011-11-04 11:18:17 +010014353
Beni Lev4ee3e062012-08-27 12:49:39 +030014354 trace_cfg80211_report_obss_beacon(wiphy, frame, len, freq, sig_dbm);
14355
Ben Greear37c73b52012-10-26 14:49:25 -070014356 spin_lock_bh(&rdev->beacon_registrations_lock);
14357 list_for_each_entry(reg, &rdev->beacon_registrations, list) {
14358 msg = nlmsg_new(len + 100, GFP_ATOMIC);
14359 if (!msg) {
14360 spin_unlock_bh(&rdev->beacon_registrations_lock);
14361 return;
14362 }
Johannes Berg5e760232011-11-04 11:18:17 +010014363
Ben Greear37c73b52012-10-26 14:49:25 -070014364 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME);
14365 if (!hdr)
14366 goto nla_put_failure;
Johannes Berg5e760232011-11-04 11:18:17 +010014367
Ben Greear37c73b52012-10-26 14:49:25 -070014368 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
14369 (freq &&
14370 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq)) ||
14371 (sig_dbm &&
14372 nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) ||
14373 nla_put(msg, NL80211_ATTR_FRAME, len, frame))
14374 goto nla_put_failure;
14375
14376 genlmsg_end(msg, hdr);
14377
14378 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, reg->nlportid);
Johannes Berg5e760232011-11-04 11:18:17 +010014379 }
Ben Greear37c73b52012-10-26 14:49:25 -070014380 spin_unlock_bh(&rdev->beacon_registrations_lock);
Johannes Berg5e760232011-11-04 11:18:17 +010014381 return;
14382
14383 nla_put_failure:
Ben Greear37c73b52012-10-26 14:49:25 -070014384 spin_unlock_bh(&rdev->beacon_registrations_lock);
14385 if (hdr)
14386 genlmsg_cancel(msg, hdr);
Johannes Berg5e760232011-11-04 11:18:17 +010014387 nlmsg_free(msg);
14388}
14389EXPORT_SYMBOL(cfg80211_report_obss_beacon);
14390
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010014391#ifdef CONFIG_PM
Luciano Coelho8cd4d452014-09-17 11:55:28 +030014392static int cfg80211_net_detect_results(struct sk_buff *msg,
14393 struct cfg80211_wowlan_wakeup *wakeup)
14394{
14395 struct cfg80211_wowlan_nd_info *nd = wakeup->net_detect;
14396 struct nlattr *nl_results, *nl_match, *nl_freqs;
14397 int i, j;
14398
14399 nl_results = nla_nest_start(
14400 msg, NL80211_WOWLAN_TRIG_NET_DETECT_RESULTS);
14401 if (!nl_results)
14402 return -EMSGSIZE;
14403
14404 for (i = 0; i < nd->n_matches; i++) {
14405 struct cfg80211_wowlan_nd_match *match = nd->matches[i];
14406
14407 nl_match = nla_nest_start(msg, i);
14408 if (!nl_match)
14409 break;
14410
14411 /* The SSID attribute is optional in nl80211, but for
14412 * simplicity reasons it's always present in the
14413 * cfg80211 structure. If a driver can't pass the
14414 * SSID, that needs to be changed. A zero length SSID
14415 * is still a valid SSID (wildcard), so it cannot be
14416 * used for this purpose.
14417 */
14418 if (nla_put(msg, NL80211_ATTR_SSID, match->ssid.ssid_len,
14419 match->ssid.ssid)) {
14420 nla_nest_cancel(msg, nl_match);
14421 goto out;
14422 }
14423
14424 if (match->n_channels) {
14425 nl_freqs = nla_nest_start(
14426 msg, NL80211_ATTR_SCAN_FREQUENCIES);
14427 if (!nl_freqs) {
14428 nla_nest_cancel(msg, nl_match);
14429 goto out;
14430 }
14431
14432 for (j = 0; j < match->n_channels; j++) {
Samuel Tan5528fae82015-02-09 21:29:15 +020014433 if (nla_put_u32(msg, j, match->channels[j])) {
Luciano Coelho8cd4d452014-09-17 11:55:28 +030014434 nla_nest_cancel(msg, nl_freqs);
14435 nla_nest_cancel(msg, nl_match);
14436 goto out;
14437 }
14438 }
14439
14440 nla_nest_end(msg, nl_freqs);
14441 }
14442
14443 nla_nest_end(msg, nl_match);
14444 }
14445
14446out:
14447 nla_nest_end(msg, nl_results);
14448 return 0;
14449}
14450
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010014451void cfg80211_report_wowlan_wakeup(struct wireless_dev *wdev,
14452 struct cfg80211_wowlan_wakeup *wakeup,
14453 gfp_t gfp)
14454{
Zhao, Gangf26cbf42014-04-21 12:53:03 +080014455 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010014456 struct sk_buff *msg;
14457 void *hdr;
Johannes Berg9c90a9f2013-06-04 12:46:03 +020014458 int size = 200;
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010014459
14460 trace_cfg80211_report_wowlan_wakeup(wdev->wiphy, wdev, wakeup);
14461
14462 if (wakeup)
14463 size += wakeup->packet_present_len;
14464
14465 msg = nlmsg_new(size, gfp);
14466 if (!msg)
14467 return;
14468
14469 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_WOWLAN);
14470 if (!hdr)
14471 goto free_msg;
14472
14473 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020014474 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
14475 NL80211_ATTR_PAD))
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010014476 goto free_msg;
14477
14478 if (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
14479 wdev->netdev->ifindex))
14480 goto free_msg;
14481
14482 if (wakeup) {
14483 struct nlattr *reasons;
14484
14485 reasons = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS);
Johannes Berg7fa322c2013-10-25 11:16:58 +020014486 if (!reasons)
14487 goto free_msg;
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010014488
14489 if (wakeup->disconnect &&
14490 nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT))
14491 goto free_msg;
14492 if (wakeup->magic_pkt &&
14493 nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT))
14494 goto free_msg;
14495 if (wakeup->gtk_rekey_failure &&
14496 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE))
14497 goto free_msg;
14498 if (wakeup->eap_identity_req &&
14499 nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST))
14500 goto free_msg;
14501 if (wakeup->four_way_handshake &&
14502 nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE))
14503 goto free_msg;
14504 if (wakeup->rfkill_release &&
14505 nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE))
14506 goto free_msg;
14507
14508 if (wakeup->pattern_idx >= 0 &&
14509 nla_put_u32(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN,
14510 wakeup->pattern_idx))
14511 goto free_msg;
14512
Johannes Bergae917c92013-10-25 11:05:22 +020014513 if (wakeup->tcp_match &&
14514 nla_put_flag(msg, NL80211_WOWLAN_TRIG_WAKEUP_TCP_MATCH))
14515 goto free_msg;
Johannes Berg2a0e0472013-01-23 22:57:40 +010014516
Johannes Bergae917c92013-10-25 11:05:22 +020014517 if (wakeup->tcp_connlost &&
14518 nla_put_flag(msg, NL80211_WOWLAN_TRIG_WAKEUP_TCP_CONNLOST))
14519 goto free_msg;
Johannes Berg2a0e0472013-01-23 22:57:40 +010014520
Johannes Bergae917c92013-10-25 11:05:22 +020014521 if (wakeup->tcp_nomoretokens &&
14522 nla_put_flag(msg,
14523 NL80211_WOWLAN_TRIG_WAKEUP_TCP_NOMORETOKENS))
14524 goto free_msg;
Johannes Berg2a0e0472013-01-23 22:57:40 +010014525
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010014526 if (wakeup->packet) {
14527 u32 pkt_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211;
14528 u32 len_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211_LEN;
14529
14530 if (!wakeup->packet_80211) {
14531 pkt_attr =
14532 NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023;
14533 len_attr =
14534 NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023_LEN;
14535 }
14536
14537 if (wakeup->packet_len &&
14538 nla_put_u32(msg, len_attr, wakeup->packet_len))
14539 goto free_msg;
14540
14541 if (nla_put(msg, pkt_attr, wakeup->packet_present_len,
14542 wakeup->packet))
14543 goto free_msg;
14544 }
14545
Luciano Coelho8cd4d452014-09-17 11:55:28 +030014546 if (wakeup->net_detect &&
14547 cfg80211_net_detect_results(msg, wakeup))
14548 goto free_msg;
14549
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010014550 nla_nest_end(msg, reasons);
14551 }
14552
Johannes Berg9c90a9f2013-06-04 12:46:03 +020014553 genlmsg_end(msg, hdr);
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010014554
Johannes Berg68eb5502013-11-19 15:19:38 +010014555 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010014556 NL80211_MCGRP_MLME, gfp);
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010014557 return;
14558
14559 free_msg:
14560 nlmsg_free(msg);
14561}
14562EXPORT_SYMBOL(cfg80211_report_wowlan_wakeup);
14563#endif
14564
Jouni Malinen3475b092012-11-16 22:49:57 +020014565void cfg80211_tdls_oper_request(struct net_device *dev, const u8 *peer,
14566 enum nl80211_tdls_operation oper,
14567 u16 reason_code, gfp_t gfp)
14568{
14569 struct wireless_dev *wdev = dev->ieee80211_ptr;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080014570 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Jouni Malinen3475b092012-11-16 22:49:57 +020014571 struct sk_buff *msg;
14572 void *hdr;
Jouni Malinen3475b092012-11-16 22:49:57 +020014573
14574 trace_cfg80211_tdls_oper_request(wdev->wiphy, dev, peer, oper,
14575 reason_code);
14576
14577 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
14578 if (!msg)
14579 return;
14580
14581 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_TDLS_OPER);
14582 if (!hdr) {
14583 nlmsg_free(msg);
14584 return;
14585 }
14586
14587 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
14588 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
14589 nla_put_u8(msg, NL80211_ATTR_TDLS_OPERATION, oper) ||
14590 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer) ||
14591 (reason_code > 0 &&
14592 nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason_code)))
14593 goto nla_put_failure;
14594
Johannes Berg9c90a9f2013-06-04 12:46:03 +020014595 genlmsg_end(msg, hdr);
Jouni Malinen3475b092012-11-16 22:49:57 +020014596
Johannes Berg68eb5502013-11-19 15:19:38 +010014597 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010014598 NL80211_MCGRP_MLME, gfp);
Jouni Malinen3475b092012-11-16 22:49:57 +020014599 return;
14600
14601 nla_put_failure:
14602 genlmsg_cancel(msg, hdr);
14603 nlmsg_free(msg);
14604}
14605EXPORT_SYMBOL(cfg80211_tdls_oper_request);
14606
Jouni Malinen026331c2010-02-15 12:53:10 +020014607static int nl80211_netlink_notify(struct notifier_block * nb,
14608 unsigned long state,
14609 void *_notify)
14610{
14611 struct netlink_notify *notify = _notify;
14612 struct cfg80211_registered_device *rdev;
14613 struct wireless_dev *wdev;
Ben Greear37c73b52012-10-26 14:49:25 -070014614 struct cfg80211_beacon_registration *reg, *tmp;
Jouni Malinen026331c2010-02-15 12:53:10 +020014615
Dmitry Ivanov8f815cd2016-04-06 17:23:18 +030014616 if (state != NETLINK_URELEASE || notify->protocol != NETLINK_GENERIC)
Jouni Malinen026331c2010-02-15 12:53:10 +020014617 return NOTIFY_DONE;
14618
14619 rcu_read_lock();
14620
Johannes Berg5e760232011-11-04 11:18:17 +010014621 list_for_each_entry_rcu(rdev, &cfg80211_rdev_list, list) {
Johannes Berg78f22b62014-03-24 17:57:27 +010014622 bool schedule_destroy_work = false;
Jukka Rissanen93a1e862014-12-15 13:25:39 +020014623 struct cfg80211_sched_scan_request *sched_scan_req =
14624 rcu_dereference(rdev->sched_scan_req);
14625
14626 if (sched_scan_req && notify->portid &&
Johannes Berg753aacf2017-01-05 10:57:14 +010014627 sched_scan_req->owner_nlportid == notify->portid) {
14628 sched_scan_req->owner_nlportid = 0;
14629
14630 if (rdev->ops->sched_scan_stop &&
14631 rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN)
14632 schedule_work(&rdev->sched_scan_stop_wk);
14633 }
Johannes Berg78f22b62014-03-24 17:57:27 +010014634
Johannes Berg53873f12016-05-03 16:52:04 +030014635 list_for_each_entry_rcu(wdev, &rdev->wiphy.wdev_list, list) {
Eric W. Biederman15e47302012-09-07 20:12:54 +000014636 cfg80211_mlme_unregister_socket(wdev, notify->portid);
Ben Greear37c73b52012-10-26 14:49:25 -070014637
Johannes Berg78f22b62014-03-24 17:57:27 +010014638 if (wdev->owner_nlportid == notify->portid)
14639 schedule_destroy_work = true;
Andrzej Zaborowskibd2522b2017-01-06 16:33:43 -050014640 else if (wdev->conn_owner_nlportid == notify->portid)
14641 schedule_work(&wdev->disconnect_wk);
Johannes Berg78f22b62014-03-24 17:57:27 +010014642 }
14643
Ben Greear37c73b52012-10-26 14:49:25 -070014644 spin_lock_bh(&rdev->beacon_registrations_lock);
14645 list_for_each_entry_safe(reg, tmp, &rdev->beacon_registrations,
14646 list) {
14647 if (reg->nlportid == notify->portid) {
14648 list_del(&reg->list);
14649 kfree(reg);
14650 break;
14651 }
14652 }
14653 spin_unlock_bh(&rdev->beacon_registrations_lock);
Johannes Berg78f22b62014-03-24 17:57:27 +010014654
14655 if (schedule_destroy_work) {
14656 struct cfg80211_iface_destroy *destroy;
14657
14658 destroy = kzalloc(sizeof(*destroy), GFP_ATOMIC);
14659 if (destroy) {
14660 destroy->nlportid = notify->portid;
14661 spin_lock(&rdev->destroy_list_lock);
14662 list_add(&destroy->list, &rdev->destroy_list);
14663 spin_unlock(&rdev->destroy_list_lock);
14664 schedule_work(&rdev->destroy_work);
14665 }
14666 }
Johannes Berg5e760232011-11-04 11:18:17 +010014667 }
Jouni Malinen026331c2010-02-15 12:53:10 +020014668
14669 rcu_read_unlock();
14670
Ilan peer05050752015-03-04 00:32:06 -050014671 /*
14672 * It is possible that the user space process that is controlling the
14673 * indoor setting disappeared, so notify the regulatory core.
14674 */
14675 regulatory_netlink_notify(notify->portid);
Zhao, Gang6784c7d2014-04-21 12:53:04 +080014676 return NOTIFY_OK;
Jouni Malinen026331c2010-02-15 12:53:10 +020014677}
14678
14679static struct notifier_block nl80211_netlink_notifier = {
14680 .notifier_call = nl80211_netlink_notify,
14681};
14682
Jouni Malinen355199e2013-02-27 17:14:27 +020014683void cfg80211_ft_event(struct net_device *netdev,
14684 struct cfg80211_ft_event_params *ft_event)
14685{
14686 struct wiphy *wiphy = netdev->ieee80211_ptr->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080014687 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Jouni Malinen355199e2013-02-27 17:14:27 +020014688 struct sk_buff *msg;
14689 void *hdr;
Jouni Malinen355199e2013-02-27 17:14:27 +020014690
14691 trace_cfg80211_ft_event(wiphy, netdev, ft_event);
14692
14693 if (!ft_event->target_ap)
14694 return;
14695
Johannes Berg4ef8c1c2017-01-09 11:10:42 +010014696 msg = nlmsg_new(100 + ft_event->ric_ies_len, GFP_KERNEL);
Jouni Malinen355199e2013-02-27 17:14:27 +020014697 if (!msg)
14698 return;
14699
14700 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FT_EVENT);
Johannes Bergae917c92013-10-25 11:05:22 +020014701 if (!hdr)
14702 goto out;
Jouni Malinen355199e2013-02-27 17:14:27 +020014703
Johannes Bergae917c92013-10-25 11:05:22 +020014704 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
14705 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
14706 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, ft_event->target_ap))
14707 goto out;
14708
14709 if (ft_event->ies &&
14710 nla_put(msg, NL80211_ATTR_IE, ft_event->ies_len, ft_event->ies))
14711 goto out;
14712 if (ft_event->ric_ies &&
14713 nla_put(msg, NL80211_ATTR_IE_RIC, ft_event->ric_ies_len,
14714 ft_event->ric_ies))
14715 goto out;
Jouni Malinen355199e2013-02-27 17:14:27 +020014716
Johannes Berg9c90a9f2013-06-04 12:46:03 +020014717 genlmsg_end(msg, hdr);
Jouni Malinen355199e2013-02-27 17:14:27 +020014718
Johannes Berg68eb5502013-11-19 15:19:38 +010014719 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010014720 NL80211_MCGRP_MLME, GFP_KERNEL);
Johannes Bergae917c92013-10-25 11:05:22 +020014721 return;
14722 out:
14723 nlmsg_free(msg);
Jouni Malinen355199e2013-02-27 17:14:27 +020014724}
14725EXPORT_SYMBOL(cfg80211_ft_event);
14726
Arend van Spriel5de17982013-04-18 15:49:00 +020014727void cfg80211_crit_proto_stopped(struct wireless_dev *wdev, gfp_t gfp)
14728{
14729 struct cfg80211_registered_device *rdev;
14730 struct sk_buff *msg;
14731 void *hdr;
14732 u32 nlportid;
14733
Zhao, Gangf26cbf42014-04-21 12:53:03 +080014734 rdev = wiphy_to_rdev(wdev->wiphy);
Arend van Spriel5de17982013-04-18 15:49:00 +020014735 if (!rdev->crit_proto_nlportid)
14736 return;
14737
14738 nlportid = rdev->crit_proto_nlportid;
14739 rdev->crit_proto_nlportid = 0;
14740
14741 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
14742 if (!msg)
14743 return;
14744
14745 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CRIT_PROTOCOL_STOP);
14746 if (!hdr)
14747 goto nla_put_failure;
14748
14749 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020014750 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
14751 NL80211_ATTR_PAD))
Arend van Spriel5de17982013-04-18 15:49:00 +020014752 goto nla_put_failure;
14753
14754 genlmsg_end(msg, hdr);
14755
14756 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid);
14757 return;
14758
14759 nla_put_failure:
14760 if (hdr)
14761 genlmsg_cancel(msg, hdr);
14762 nlmsg_free(msg);
Arend van Spriel5de17982013-04-18 15:49:00 +020014763}
14764EXPORT_SYMBOL(cfg80211_crit_proto_stopped);
14765
Johannes Berg348baf02014-01-24 14:06:29 +010014766void nl80211_send_ap_stopped(struct wireless_dev *wdev)
14767{
14768 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080014769 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg348baf02014-01-24 14:06:29 +010014770 struct sk_buff *msg;
14771 void *hdr;
14772
14773 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
14774 if (!msg)
14775 return;
14776
14777 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_STOP_AP);
14778 if (!hdr)
14779 goto out;
14780
14781 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
14782 nla_put_u32(msg, NL80211_ATTR_IFINDEX, wdev->netdev->ifindex) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020014783 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
14784 NL80211_ATTR_PAD))
Johannes Berg348baf02014-01-24 14:06:29 +010014785 goto out;
14786
14787 genlmsg_end(msg, hdr);
14788
14789 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(wiphy), msg, 0,
14790 NL80211_MCGRP_MLME, GFP_KERNEL);
14791 return;
14792 out:
14793 nlmsg_free(msg);
14794}
14795
Johannes Berg55682962007-09-20 13:09:35 -040014796/* initialisation/exit functions */
14797
Johannes Berg56989f62016-10-24 14:40:05 +020014798int __init nl80211_init(void)
Johannes Berg55682962007-09-20 13:09:35 -040014799{
Michał Mirosław0d63cbb2009-05-21 10:34:06 +000014800 int err;
Johannes Berg55682962007-09-20 13:09:35 -040014801
Johannes Berg489111e2016-10-24 14:40:03 +020014802 err = genl_register_family(&nl80211_fam);
Johannes Berg55682962007-09-20 13:09:35 -040014803 if (err)
14804 return err;
14805
Jouni Malinen026331c2010-02-15 12:53:10 +020014806 err = netlink_register_notifier(&nl80211_netlink_notifier);
14807 if (err)
14808 goto err_out;
14809
Johannes Berg55682962007-09-20 13:09:35 -040014810 return 0;
14811 err_out:
14812 genl_unregister_family(&nl80211_fam);
14813 return err;
14814}
14815
14816void nl80211_exit(void)
14817{
Jouni Malinen026331c2010-02-15 12:53:10 +020014818 netlink_unregister_notifier(&nl80211_netlink_notifier);
Johannes Berg55682962007-09-20 13:09:35 -040014819 genl_unregister_family(&nl80211_fam);
14820}