blob: c0b5ae4af2d80dd2512965235851c6544e7e38b1 [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
Beni Lev0c9ca112016-02-17 20:30:00 +02006 * Copyright 2015-2016 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 Bergf84f7712013-11-14 17:14:45 +010035static int nl80211_pre_doit(const struct genl_ops *ops, struct sk_buff *skb,
Johannes Berg4c476992010-10-04 21:36:35 +020036 struct genl_info *info);
Johannes Bergf84f7712013-11-14 17:14:45 +010037static void nl80211_post_doit(const struct genl_ops *ops, struct sk_buff *skb,
Johannes Berg4c476992010-10-04 21:36:35 +020038 struct genl_info *info);
39
Johannes Berg55682962007-09-20 13:09:35 -040040/* the netlink family */
41static struct genl_family nl80211_fam = {
Marcel Holtmannfb4e1562013-04-28 16:22:06 -070042 .id = GENL_ID_GENERATE, /* don't bother with a hardcoded ID */
43 .name = NL80211_GENL_NAME, /* have users key off the name instead */
44 .hdrsize = 0, /* no private header */
45 .version = 1, /* no particular meaning now */
Johannes Berg55682962007-09-20 13:09:35 -040046 .maxattr = NL80211_ATTR_MAX,
Johannes Berg463d0182009-07-14 00:33:35 +020047 .netnsok = true,
Johannes Berg4c476992010-10-04 21:36:35 +020048 .pre_doit = nl80211_pre_doit,
49 .post_doit = nl80211_post_doit,
Johannes Berg55682962007-09-20 13:09:35 -040050};
51
Johannes Berg2a94fe42013-11-19 15:19:39 +010052/* multicast groups */
53enum nl80211_multicast_groups {
54 NL80211_MCGRP_CONFIG,
55 NL80211_MCGRP_SCAN,
56 NL80211_MCGRP_REGULATORY,
57 NL80211_MCGRP_MLME,
Johannes Berg567ffc32013-12-18 14:43:31 +010058 NL80211_MCGRP_VENDOR,
Johannes Berg2a94fe42013-11-19 15:19:39 +010059 NL80211_MCGRP_TESTMODE /* keep last - ifdef! */
60};
61
62static const struct genl_multicast_group nl80211_mcgrps[] = {
Johannes Berg71b836e2014-12-23 17:17:38 +010063 [NL80211_MCGRP_CONFIG] = { .name = NL80211_MULTICAST_GROUP_CONFIG },
64 [NL80211_MCGRP_SCAN] = { .name = NL80211_MULTICAST_GROUP_SCAN },
65 [NL80211_MCGRP_REGULATORY] = { .name = NL80211_MULTICAST_GROUP_REG },
66 [NL80211_MCGRP_MLME] = { .name = NL80211_MULTICAST_GROUP_MLME },
67 [NL80211_MCGRP_VENDOR] = { .name = NL80211_MULTICAST_GROUP_VENDOR },
Johannes Berg2a94fe42013-11-19 15:19:39 +010068#ifdef CONFIG_NL80211_TESTMODE
Johannes Berg71b836e2014-12-23 17:17:38 +010069 [NL80211_MCGRP_TESTMODE] = { .name = NL80211_MULTICAST_GROUP_TESTMODE }
Johannes Berg2a94fe42013-11-19 15:19:39 +010070#endif
71};
72
Johannes Berg89a54e42012-06-15 14:33:17 +020073/* returns ERR_PTR values */
74static struct wireless_dev *
75__cfg80211_wdev_from_attrs(struct net *netns, struct nlattr **attrs)
Johannes Berg55682962007-09-20 13:09:35 -040076{
Johannes Berg89a54e42012-06-15 14:33:17 +020077 struct cfg80211_registered_device *rdev;
78 struct wireless_dev *result = NULL;
79 bool have_ifidx = attrs[NL80211_ATTR_IFINDEX];
80 bool have_wdev_id = attrs[NL80211_ATTR_WDEV];
81 u64 wdev_id;
82 int wiphy_idx = -1;
83 int ifidx = -1;
Johannes Berg55682962007-09-20 13:09:35 -040084
Johannes Berg5fe231e2013-05-08 21:45:15 +020085 ASSERT_RTNL();
Johannes Berg55682962007-09-20 13:09:35 -040086
Johannes Berg89a54e42012-06-15 14:33:17 +020087 if (!have_ifidx && !have_wdev_id)
88 return ERR_PTR(-EINVAL);
Johannes Berg55682962007-09-20 13:09:35 -040089
Johannes Berg89a54e42012-06-15 14:33:17 +020090 if (have_ifidx)
91 ifidx = nla_get_u32(attrs[NL80211_ATTR_IFINDEX]);
92 if (have_wdev_id) {
93 wdev_id = nla_get_u64(attrs[NL80211_ATTR_WDEV]);
94 wiphy_idx = wdev_id >> 32;
Johannes Berg55682962007-09-20 13:09:35 -040095 }
96
Johannes Berg89a54e42012-06-15 14:33:17 +020097 list_for_each_entry(rdev, &cfg80211_rdev_list, list) {
98 struct wireless_dev *wdev;
99
100 if (wiphy_net(&rdev->wiphy) != netns)
101 continue;
102
103 if (have_wdev_id && rdev->wiphy_idx != wiphy_idx)
104 continue;
105
Johannes Berg53873f12016-05-03 16:52:04 +0300106 list_for_each_entry(wdev, &rdev->wiphy.wdev_list, list) {
Johannes Berg89a54e42012-06-15 14:33:17 +0200107 if (have_ifidx && wdev->netdev &&
108 wdev->netdev->ifindex == ifidx) {
109 result = wdev;
110 break;
111 }
112 if (have_wdev_id && wdev->identifier == (u32)wdev_id) {
113 result = wdev;
114 break;
115 }
116 }
Johannes Berg89a54e42012-06-15 14:33:17 +0200117
118 if (result)
119 break;
120 }
121
122 if (result)
123 return result;
124 return ERR_PTR(-ENODEV);
Johannes Berg55682962007-09-20 13:09:35 -0400125}
126
Johannes Berga9455402012-06-15 13:32:49 +0200127static struct cfg80211_registered_device *
Johannes Berg878d9ec2012-06-15 14:18:32 +0200128__cfg80211_rdev_from_attrs(struct net *netns, struct nlattr **attrs)
Johannes Berga9455402012-06-15 13:32:49 +0200129{
Johannes Berg7fee47782012-06-15 14:09:58 +0200130 struct cfg80211_registered_device *rdev = NULL, *tmp;
131 struct net_device *netdev;
Johannes Berga9455402012-06-15 13:32:49 +0200132
Johannes Berg5fe231e2013-05-08 21:45:15 +0200133 ASSERT_RTNL();
Johannes Berga9455402012-06-15 13:32:49 +0200134
Johannes Berg878d9ec2012-06-15 14:18:32 +0200135 if (!attrs[NL80211_ATTR_WIPHY] &&
Johannes Berg89a54e42012-06-15 14:33:17 +0200136 !attrs[NL80211_ATTR_IFINDEX] &&
137 !attrs[NL80211_ATTR_WDEV])
Johannes Berg7fee47782012-06-15 14:09:58 +0200138 return ERR_PTR(-EINVAL);
139
Johannes Berg878d9ec2012-06-15 14:18:32 +0200140 if (attrs[NL80211_ATTR_WIPHY])
Johannes Berg7fee47782012-06-15 14:09:58 +0200141 rdev = cfg80211_rdev_by_wiphy_idx(
Johannes Berg878d9ec2012-06-15 14:18:32 +0200142 nla_get_u32(attrs[NL80211_ATTR_WIPHY]));
Johannes Berga9455402012-06-15 13:32:49 +0200143
Johannes Berg89a54e42012-06-15 14:33:17 +0200144 if (attrs[NL80211_ATTR_WDEV]) {
145 u64 wdev_id = nla_get_u64(attrs[NL80211_ATTR_WDEV]);
146 struct wireless_dev *wdev;
147 bool found = false;
148
149 tmp = cfg80211_rdev_by_wiphy_idx(wdev_id >> 32);
150 if (tmp) {
151 /* make sure wdev exists */
Johannes Berg53873f12016-05-03 16:52:04 +0300152 list_for_each_entry(wdev, &tmp->wiphy.wdev_list, list) {
Johannes Berg89a54e42012-06-15 14:33:17 +0200153 if (wdev->identifier != (u32)wdev_id)
154 continue;
155 found = true;
156 break;
157 }
Johannes Berg89a54e42012-06-15 14:33:17 +0200158
159 if (!found)
160 tmp = NULL;
161
162 if (rdev && tmp != rdev)
163 return ERR_PTR(-EINVAL);
164 rdev = tmp;
165 }
166 }
167
Johannes Berg878d9ec2012-06-15 14:18:32 +0200168 if (attrs[NL80211_ATTR_IFINDEX]) {
169 int ifindex = nla_get_u32(attrs[NL80211_ATTR_IFINDEX]);
Kirtika Ruchandani7a087e72016-05-29 19:51:23 -0700170
Ying Xue7f2b8562014-01-15 10:23:45 +0800171 netdev = __dev_get_by_index(netns, ifindex);
Johannes Berg7fee47782012-06-15 14:09:58 +0200172 if (netdev) {
173 if (netdev->ieee80211_ptr)
Zhao, Gangf26cbf42014-04-21 12:53:03 +0800174 tmp = wiphy_to_rdev(
175 netdev->ieee80211_ptr->wiphy);
Johannes Berg7fee47782012-06-15 14:09:58 +0200176 else
177 tmp = NULL;
178
Johannes Berg7fee47782012-06-15 14:09:58 +0200179 /* not wireless device -- return error */
180 if (!tmp)
181 return ERR_PTR(-EINVAL);
182
183 /* mismatch -- return error */
184 if (rdev && tmp != rdev)
185 return ERR_PTR(-EINVAL);
186
187 rdev = tmp;
Johannes Berga9455402012-06-15 13:32:49 +0200188 }
Johannes Berga9455402012-06-15 13:32:49 +0200189 }
190
Johannes Berg4f7eff12012-06-15 14:14:22 +0200191 if (!rdev)
192 return ERR_PTR(-ENODEV);
Johannes Berga9455402012-06-15 13:32:49 +0200193
Johannes Berg4f7eff12012-06-15 14:14:22 +0200194 if (netns != wiphy_net(&rdev->wiphy))
195 return ERR_PTR(-ENODEV);
196
197 return rdev;
Johannes Berga9455402012-06-15 13:32:49 +0200198}
199
200/*
201 * This function returns a pointer to the driver
202 * that the genl_info item that is passed refers to.
Johannes Berga9455402012-06-15 13:32:49 +0200203 *
204 * The result of this can be a PTR_ERR and hence must
205 * be checked with IS_ERR() for errors.
206 */
207static struct cfg80211_registered_device *
Johannes Berg4f7eff12012-06-15 14:14:22 +0200208cfg80211_get_dev_from_info(struct net *netns, struct genl_info *info)
Johannes Berga9455402012-06-15 13:32:49 +0200209{
Johannes Berg5fe231e2013-05-08 21:45:15 +0200210 return __cfg80211_rdev_from_attrs(netns, info->attrs);
Johannes Berga9455402012-06-15 13:32:49 +0200211}
212
Johannes Berg55682962007-09-20 13:09:35 -0400213/* policy for the attributes */
Luciano Coelho8cd4d452014-09-17 11:55:28 +0300214static const struct nla_policy nl80211_policy[NUM_NL80211_ATTR] = {
Johannes Berg55682962007-09-20 13:09:35 -0400215 [NL80211_ATTR_WIPHY] = { .type = NLA_U32 },
216 [NL80211_ATTR_WIPHY_NAME] = { .type = NLA_NUL_STRING,
David S. Miller079e24e2009-05-26 21:15:00 -0700217 .len = 20-1 },
Jouni Malinen31888482008-10-30 16:59:24 +0200218 [NL80211_ATTR_WIPHY_TXQ_PARAMS] = { .type = NLA_NESTED },
Johannes Berg3d9d1d62012-11-08 23:14:50 +0100219
Jouni Malinen72bdcf32008-11-26 16:15:24 +0200220 [NL80211_ATTR_WIPHY_FREQ] = { .type = NLA_U32 },
Sujith094d05d2008-12-12 11:57:43 +0530221 [NL80211_ATTR_WIPHY_CHANNEL_TYPE] = { .type = NLA_U32 },
Johannes Berg3d9d1d62012-11-08 23:14:50 +0100222 [NL80211_ATTR_CHANNEL_WIDTH] = { .type = NLA_U32 },
223 [NL80211_ATTR_CENTER_FREQ1] = { .type = NLA_U32 },
224 [NL80211_ATTR_CENTER_FREQ2] = { .type = NLA_U32 },
225
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +0200226 [NL80211_ATTR_WIPHY_RETRY_SHORT] = { .type = NLA_U8 },
227 [NL80211_ATTR_WIPHY_RETRY_LONG] = { .type = NLA_U8 },
228 [NL80211_ATTR_WIPHY_FRAG_THRESHOLD] = { .type = NLA_U32 },
229 [NL80211_ATTR_WIPHY_RTS_THRESHOLD] = { .type = NLA_U32 },
Lukáš Turek81077e82009-12-21 22:50:47 +0100230 [NL80211_ATTR_WIPHY_COVERAGE_CLASS] = { .type = NLA_U8 },
Lorenzo Bianconi3057dbf2014-09-04 23:57:40 +0200231 [NL80211_ATTR_WIPHY_DYN_ACK] = { .type = NLA_FLAG },
Johannes Berg55682962007-09-20 13:09:35 -0400232
233 [NL80211_ATTR_IFTYPE] = { .type = NLA_U32 },
234 [NL80211_ATTR_IFINDEX] = { .type = NLA_U32 },
235 [NL80211_ATTR_IFNAME] = { .type = NLA_NUL_STRING, .len = IFNAMSIZ-1 },
Johannes Berg41ade002007-12-19 02:03:29 +0100236
Eliad Pellere007b852011-11-24 18:13:56 +0200237 [NL80211_ATTR_MAC] = { .len = ETH_ALEN },
238 [NL80211_ATTR_PREV_BSSID] = { .len = ETH_ALEN },
Johannes Berg41ade002007-12-19 02:03:29 +0100239
Johannes Bergb9454e82009-07-08 13:29:08 +0200240 [NL80211_ATTR_KEY] = { .type = NLA_NESTED, },
Johannes Berg41ade002007-12-19 02:03:29 +0100241 [NL80211_ATTR_KEY_DATA] = { .type = NLA_BINARY,
242 .len = WLAN_MAX_KEY_LEN },
243 [NL80211_ATTR_KEY_IDX] = { .type = NLA_U8 },
244 [NL80211_ATTR_KEY_CIPHER] = { .type = NLA_U32 },
245 [NL80211_ATTR_KEY_DEFAULT] = { .type = NLA_FLAG },
Jouni Malinen81962262011-11-02 23:36:31 +0200246 [NL80211_ATTR_KEY_SEQ] = { .type = NLA_BINARY, .len = 16 },
Johannes Berge31b8212010-10-05 19:39:30 +0200247 [NL80211_ATTR_KEY_TYPE] = { .type = NLA_U32 },
Johannes Berged1b6cc2007-12-19 02:03:32 +0100248
249 [NL80211_ATTR_BEACON_INTERVAL] = { .type = NLA_U32 },
250 [NL80211_ATTR_DTIM_PERIOD] = { .type = NLA_U32 },
251 [NL80211_ATTR_BEACON_HEAD] = { .type = NLA_BINARY,
252 .len = IEEE80211_MAX_DATA_LEN },
253 [NL80211_ATTR_BEACON_TAIL] = { .type = NLA_BINARY,
254 .len = IEEE80211_MAX_DATA_LEN },
Johannes Berg5727ef12007-12-19 02:03:34 +0100255 [NL80211_ATTR_STA_AID] = { .type = NLA_U16 },
256 [NL80211_ATTR_STA_FLAGS] = { .type = NLA_NESTED },
257 [NL80211_ATTR_STA_LISTEN_INTERVAL] = { .type = NLA_U16 },
258 [NL80211_ATTR_STA_SUPPORTED_RATES] = { .type = NLA_BINARY,
259 .len = NL80211_MAX_SUPP_RATES },
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +0100260 [NL80211_ATTR_STA_PLINK_ACTION] = { .type = NLA_U8 },
Johannes Berg5727ef12007-12-19 02:03:34 +0100261 [NL80211_ATTR_STA_VLAN] = { .type = NLA_U32 },
Johannes Berg0a9542e2008-10-15 11:54:04 +0200262 [NL80211_ATTR_MNTR_FLAGS] = { /* NLA_NESTED can't be empty */ },
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +0100263 [NL80211_ATTR_MESH_ID] = { .type = NLA_BINARY,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +0800264 .len = IEEE80211_MAX_MESH_ID_LEN },
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +0100265 [NL80211_ATTR_MPATH_NEXT_HOP] = { .type = NLA_U32 },
Jouni Malinen9f1ba902008-08-07 20:07:01 +0300266
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -0700267 [NL80211_ATTR_REG_ALPHA2] = { .type = NLA_STRING, .len = 2 },
268 [NL80211_ATTR_REG_RULES] = { .type = NLA_NESTED },
269
Jouni Malinen9f1ba902008-08-07 20:07:01 +0300270 [NL80211_ATTR_BSS_CTS_PROT] = { .type = NLA_U8 },
271 [NL80211_ATTR_BSS_SHORT_PREAMBLE] = { .type = NLA_U8 },
272 [NL80211_ATTR_BSS_SHORT_SLOT_TIME] = { .type = NLA_U8 },
Jouni Malinen90c97a02008-10-30 16:59:22 +0200273 [NL80211_ATTR_BSS_BASIC_RATES] = { .type = NLA_BINARY,
274 .len = NL80211_MAX_SUPP_RATES },
Helmut Schaa50b12f52010-11-19 12:40:25 +0100275 [NL80211_ATTR_BSS_HT_OPMODE] = { .type = NLA_U16 },
Jouni Malinen36aedc92008-08-25 11:58:58 +0300276
Javier Cardona24bdd9f2010-12-16 17:37:48 -0800277 [NL80211_ATTR_MESH_CONFIG] = { .type = NLA_NESTED },
Javier Cardona15d5dda2011-04-07 15:08:28 -0700278 [NL80211_ATTR_SUPPORT_MESH_AUTH] = { .type = NLA_FLAG },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -0700279
Johannes Berg6c739412011-11-03 09:27:01 +0100280 [NL80211_ATTR_HT_CAPABILITY] = { .len = NL80211_HT_CAPABILITY_LEN },
Jouni Malinen9aed3cc2009-01-13 16:03:29 +0200281
282 [NL80211_ATTR_MGMT_SUBTYPE] = { .type = NLA_U8 },
283 [NL80211_ATTR_IE] = { .type = NLA_BINARY,
284 .len = IEEE80211_MAX_DATA_LEN },
Johannes Berg2a519312009-02-10 21:25:55 +0100285 [NL80211_ATTR_SCAN_FREQUENCIES] = { .type = NLA_NESTED },
286 [NL80211_ATTR_SCAN_SSIDS] = { .type = NLA_NESTED },
Jouni Malinen636a5d32009-03-19 13:39:22 +0200287
288 [NL80211_ATTR_SSID] = { .type = NLA_BINARY,
289 .len = IEEE80211_MAX_SSID_LEN },
290 [NL80211_ATTR_AUTH_TYPE] = { .type = NLA_U32 },
291 [NL80211_ATTR_REASON_CODE] = { .type = NLA_U16 },
Johannes Berg04a773a2009-04-19 21:24:32 +0200292 [NL80211_ATTR_FREQ_FIXED] = { .type = NLA_FLAG },
Jouni Malinen1965c852009-04-22 21:38:25 +0300293 [NL80211_ATTR_TIMED_OUT] = { .type = NLA_FLAG },
Jouni Malinendc6382ce2009-05-06 22:09:37 +0300294 [NL80211_ATTR_USE_MFP] = { .type = NLA_U32 },
Johannes Bergeccb8e82009-05-11 21:57:56 +0300295 [NL80211_ATTR_STA_FLAGS2] = {
296 .len = sizeof(struct nl80211_sta_flag_update),
297 },
Jouni Malinen3f77316c2009-05-11 21:57:57 +0300298 [NL80211_ATTR_CONTROL_PORT] = { .type = NLA_FLAG },
Johannes Bergc0692b82010-08-27 14:26:53 +0300299 [NL80211_ATTR_CONTROL_PORT_ETHERTYPE] = { .type = NLA_U16 },
300 [NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT] = { .type = NLA_FLAG },
Samuel Ortizb23aa672009-07-01 21:26:54 +0200301 [NL80211_ATTR_PRIVACY] = { .type = NLA_FLAG },
302 [NL80211_ATTR_CIPHER_SUITE_GROUP] = { .type = NLA_U32 },
303 [NL80211_ATTR_WPA_VERSIONS] = { .type = NLA_U32 },
Johannes Berg463d0182009-07-14 00:33:35 +0200304 [NL80211_ATTR_PID] = { .type = NLA_U32 },
Felix Fietkau8b787642009-11-10 18:53:10 +0100305 [NL80211_ATTR_4ADDR] = { .type = NLA_U8 },
Samuel Ortiz67fbb162009-11-24 23:59:15 +0100306 [NL80211_ATTR_PMKID] = { .type = NLA_BINARY,
307 .len = WLAN_PMKID_LEN },
Jouni Malinen9588bbd2009-12-23 13:15:41 +0100308 [NL80211_ATTR_DURATION] = { .type = NLA_U32 },
309 [NL80211_ATTR_COOKIE] = { .type = NLA_U64 },
Jouni Malinen13ae75b2009-12-29 12:59:45 +0200310 [NL80211_ATTR_TX_RATES] = { .type = NLA_NESTED },
Jouni Malinen026331c2010-02-15 12:53:10 +0200311 [NL80211_ATTR_FRAME] = { .type = NLA_BINARY,
312 .len = IEEE80211_MAX_DATA_LEN },
313 [NL80211_ATTR_FRAME_MATCH] = { .type = NLA_BINARY, },
Kalle Valoffb9eb32010-02-17 17:58:10 +0200314 [NL80211_ATTR_PS_STATE] = { .type = NLA_U32 },
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +0200315 [NL80211_ATTR_CQM] = { .type = NLA_NESTED, },
Jouni Malinend5cdfac2010-04-04 09:37:19 +0300316 [NL80211_ATTR_LOCAL_STATE_CHANGE] = { .type = NLA_FLAG },
Felix Fietkaufd8aaaf2010-04-27 01:23:35 +0200317 [NL80211_ATTR_AP_ISOLATE] = { .type = NLA_U8 },
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +0300318 [NL80211_ATTR_WIPHY_TX_POWER_SETTING] = { .type = NLA_U32 },
319 [NL80211_ATTR_WIPHY_TX_POWER_LEVEL] = { .type = NLA_U32 },
Johannes Berg2e161f782010-08-12 15:38:38 +0200320 [NL80211_ATTR_FRAME_TYPE] = { .type = NLA_U16 },
Bruno Randolfafe0cbf2010-11-10 12:50:50 +0900321 [NL80211_ATTR_WIPHY_ANTENNA_TX] = { .type = NLA_U32 },
322 [NL80211_ATTR_WIPHY_ANTENNA_RX] = { .type = NLA_U32 },
Felix Fietkau885a46d2010-11-11 15:07:22 +0100323 [NL80211_ATTR_MCAST_RATE] = { .type = NLA_U32 },
Johannes Bergf7ca38d2010-11-25 10:02:29 +0100324 [NL80211_ATTR_OFFCHANNEL_TX_OK] = { .type = NLA_FLAG },
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100325 [NL80211_ATTR_KEY_DEFAULT_TYPES] = { .type = NLA_NESTED },
Johannes Bergff1b6e62011-05-04 15:37:28 +0200326 [NL80211_ATTR_WOWLAN_TRIGGERS] = { .type = NLA_NESTED },
Javier Cardona9c3990a2011-05-03 16:57:11 -0700327 [NL80211_ATTR_STA_PLINK_STATE] = { .type = NLA_U8 },
Luciano Coelhobbe6ad62011-05-11 17:09:37 +0300328 [NL80211_ATTR_SCHED_SCAN_INTERVAL] = { .type = NLA_U32 },
Johannes Berge5497d72011-07-05 16:35:40 +0200329 [NL80211_ATTR_REKEY_DATA] = { .type = NLA_NESTED },
Johannes Berg34850ab2011-07-18 18:08:35 +0200330 [NL80211_ATTR_SCAN_SUPP_RATES] = { .type = NLA_NESTED },
Jouni Malinen32e9de82011-08-10 23:53:31 +0300331 [NL80211_ATTR_HIDDEN_SSID] = { .type = NLA_U32 },
Jouni Malinen9946ecf2011-08-10 23:55:56 +0300332 [NL80211_ATTR_IE_PROBE_RESP] = { .type = NLA_BINARY,
333 .len = IEEE80211_MAX_DATA_LEN },
334 [NL80211_ATTR_IE_ASSOC_RESP] = { .type = NLA_BINARY,
335 .len = IEEE80211_MAX_DATA_LEN },
Vivek Natarajanf4b34b52011-08-29 14:23:03 +0530336 [NL80211_ATTR_ROAM_SUPPORT] = { .type = NLA_FLAG },
Luciano Coelhoa1f1c212011-08-31 16:01:48 +0300337 [NL80211_ATTR_SCHED_SCAN_MATCH] = { .type = NLA_NESTED },
Rajkumar Manoharane9f935e2011-09-25 14:53:30 +0530338 [NL80211_ATTR_TX_NO_CCK_RATE] = { .type = NLA_FLAG },
Arik Nemtsov109086c2011-09-28 14:12:50 +0300339 [NL80211_ATTR_TDLS_ACTION] = { .type = NLA_U8 },
340 [NL80211_ATTR_TDLS_DIALOG_TOKEN] = { .type = NLA_U8 },
341 [NL80211_ATTR_TDLS_OPERATION] = { .type = NLA_U8 },
342 [NL80211_ATTR_TDLS_SUPPORT] = { .type = NLA_FLAG },
343 [NL80211_ATTR_TDLS_EXTERNAL_SETUP] = { .type = NLA_FLAG },
Arik Nemtsov31fa97c2014-06-11 17:18:21 +0300344 [NL80211_ATTR_TDLS_INITIATOR] = { .type = NLA_FLAG },
Johannes Berge247bd902011-11-04 11:18:21 +0100345 [NL80211_ATTR_DONT_WAIT_FOR_ACK] = { .type = NLA_FLAG },
Arik Nemtsov00f740e2011-11-10 11:28:56 +0200346 [NL80211_ATTR_PROBE_RESP] = { .type = NLA_BINARY,
347 .len = IEEE80211_MAX_DATA_LEN },
Luis R. Rodriguez8b60b072011-10-11 10:59:02 -0700348 [NL80211_ATTR_DFS_REGION] = { .type = NLA_U8 },
Ben Greear7e7c8922011-11-18 11:31:59 -0800349 [NL80211_ATTR_DISABLE_HT] = { .type = NLA_FLAG },
350 [NL80211_ATTR_HT_CAPABILITY_MASK] = {
351 .len = NL80211_HT_CAPABILITY_LEN
352 },
Simon Wunderlich1d9d9212011-11-18 14:20:43 +0100353 [NL80211_ATTR_NOACK_MAP] = { .type = NLA_U16 },
Vasanthakumar Thiagarajan1b658f12012-03-02 15:50:02 +0530354 [NL80211_ATTR_INACTIVITY_TIMEOUT] = { .type = NLA_U16 },
Bala Shanmugam4486ea92012-03-07 17:27:12 +0530355 [NL80211_ATTR_BG_SCAN_PERIOD] = { .type = NLA_U16 },
Johannes Berg89a54e42012-06-15 14:33:17 +0200356 [NL80211_ATTR_WDEV] = { .type = NLA_U64 },
Luis R. Rodriguez57b5ce02012-07-12 11:49:18 -0700357 [NL80211_ATTR_USER_REG_HINT_TYPE] = { .type = NLA_U32 },
Jouni Malinene39e5b52012-09-30 19:29:39 +0300358 [NL80211_ATTR_SAE_DATA] = { .type = NLA_BINARY, },
Mahesh Palivelaf461be3e2012-10-11 08:04:52 +0000359 [NL80211_ATTR_VHT_CAPABILITY] = { .len = NL80211_VHT_CAPABILITY_LEN },
Sam Lefflered4737712012-10-11 21:03:31 -0700360 [NL80211_ATTR_SCAN_FLAGS] = { .type = NLA_U32 },
Johannes Berg53cabad2012-11-14 15:17:28 +0100361 [NL80211_ATTR_P2P_CTWINDOW] = { .type = NLA_U8 },
362 [NL80211_ATTR_P2P_OPPPS] = { .type = NLA_U8 },
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +0530363 [NL80211_ATTR_ACL_POLICY] = {. type = NLA_U32 },
364 [NL80211_ATTR_MAC_ADDRS] = { .type = NLA_NESTED },
Jouni Malinen9d62a982013-02-14 21:10:13 +0200365 [NL80211_ATTR_STA_CAPABILITY] = { .type = NLA_U16 },
366 [NL80211_ATTR_STA_EXT_CAPABILITY] = { .type = NLA_BINARY, },
Johannes Berg3713b4e2013-02-14 16:19:38 +0100367 [NL80211_ATTR_SPLIT_WIPHY_DUMP] = { .type = NLA_FLAG, },
Johannes Bergee2aca32013-02-21 17:36:01 +0100368 [NL80211_ATTR_DISABLE_VHT] = { .type = NLA_FLAG },
369 [NL80211_ATTR_VHT_CAPABILITY_MASK] = {
370 .len = NL80211_VHT_CAPABILITY_LEN,
371 },
Jouni Malinen355199e2013-02-27 17:14:27 +0200372 [NL80211_ATTR_MDID] = { .type = NLA_U16 },
373 [NL80211_ATTR_IE_RIC] = { .type = NLA_BINARY,
374 .len = IEEE80211_MAX_DATA_LEN },
Jouni Malinen5e4b6f52013-05-16 20:11:08 +0300375 [NL80211_ATTR_PEER_AID] = { .type = NLA_U16 },
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +0200376 [NL80211_ATTR_CH_SWITCH_COUNT] = { .type = NLA_U32 },
377 [NL80211_ATTR_CH_SWITCH_BLOCK_TX] = { .type = NLA_FLAG },
378 [NL80211_ATTR_CSA_IES] = { .type = NLA_NESTED },
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +0300379 [NL80211_ATTR_CSA_C_OFF_BEACON] = { .type = NLA_BINARY },
380 [NL80211_ATTR_CSA_C_OFF_PRESP] = { .type = NLA_BINARY },
Sunil Duttc01fc9a2013-10-09 20:45:21 +0530381 [NL80211_ATTR_STA_SUPPORTED_CHANNELS] = { .type = NLA_BINARY },
382 [NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES] = { .type = NLA_BINARY },
Simon Wunderlich5336fa82013-10-07 18:41:05 +0200383 [NL80211_ATTR_HANDLE_DFS] = { .type = NLA_FLAG },
Marek Kwaczynski60f4a7b2013-12-03 10:04:59 +0100384 [NL80211_ATTR_OPMODE_NOTIF] = { .type = NLA_U8 },
Johannes Bergad7e7182013-11-13 13:37:47 +0100385 [NL80211_ATTR_VENDOR_ID] = { .type = NLA_U32 },
386 [NL80211_ATTR_VENDOR_SUBCMD] = { .type = NLA_U32 },
387 [NL80211_ATTR_VENDOR_DATA] = { .type = NLA_BINARY },
Kyeyoon Parkfa9ffc72013-12-16 23:01:30 -0800388 [NL80211_ATTR_QOS_MAP] = { .type = NLA_BINARY,
389 .len = IEEE80211_QOS_MAP_LEN_MAX },
Jouni Malinen1df4a512014-01-15 00:00:47 +0200390 [NL80211_ATTR_MAC_HINT] = { .len = ETH_ALEN },
391 [NL80211_ATTR_WIPHY_FREQ_HINT] = { .type = NLA_U32 },
Sunil Dutt Undekaridf942e72014-02-20 16:22:09 +0530392 [NL80211_ATTR_TDLS_PEER_CAPABILITY] = { .type = NLA_U32 },
Jukka Rissanen18e5ca62014-11-13 17:25:14 +0200393 [NL80211_ATTR_SOCKET_OWNER] = { .type = NLA_FLAG },
Andrei Otcheretianski34d22ce2014-05-09 14:11:44 +0300394 [NL80211_ATTR_CSA_C_OFFSETS_TX] = { .type = NLA_BINARY },
Assaf Kraussbab5ab72014-09-03 15:25:01 +0300395 [NL80211_ATTR_USE_RRM] = { .type = NLA_FLAG },
Johannes Berg960d01a2014-09-09 22:55:35 +0300396 [NL80211_ATTR_TSID] = { .type = NLA_U8 },
397 [NL80211_ATTR_USER_PRIO] = { .type = NLA_U8 },
398 [NL80211_ATTR_ADMITTED_TIME] = { .type = NLA_U16 },
Eliad Peller18998c32014-09-10 14:07:34 +0300399 [NL80211_ATTR_SMPS_MODE] = { .type = NLA_U8 },
Johannes Bergad2b26a2014-06-12 21:39:05 +0200400 [NL80211_ATTR_MAC_MASK] = { .len = ETH_ALEN },
Arik Nemtsov1bdd7162014-12-15 19:26:01 +0200401 [NL80211_ATTR_WIPHY_SELF_MANAGED_REG] = { .type = NLA_FLAG },
Vadim Kochan4b681c82015-01-12 16:34:05 +0200402 [NL80211_ATTR_NETNS_FD] = { .type = NLA_U32 },
Luciano Coelho9c748932015-01-16 16:04:09 +0200403 [NL80211_ATTR_SCHED_SCAN_DELAY] = { .type = NLA_U32 },
Ilan peer05050752015-03-04 00:32:06 -0500404 [NL80211_ATTR_REG_INDOOR] = { .type = NLA_FLAG },
Lior David34d50512016-01-28 10:58:25 +0200405 [NL80211_ATTR_PBSS] = { .type = NLA_FLAG },
Arend van Spriel38de03d2016-03-02 20:37:18 +0100406 [NL80211_ATTR_BSS_SELECT] = { .type = NLA_NESTED },
Ayala Beker17b94242016-03-17 15:41:38 +0200407 [NL80211_ATTR_STA_SUPPORT_P2P_PS] = { .type = NLA_U8 },
Aviya Erenfeldc6e6a0c2016-07-05 15:23:08 +0300408 [NL80211_ATTR_MU_MIMO_GROUP_DATA] = {
409 .len = VHT_MUMIMO_GROUPS_DATA_LEN
410 },
411 [NL80211_ATTR_MU_MIMO_FOLLOW_MAC_ADDR] = { .len = ETH_ALEN },
Ayala Bekercb3b7d82016-09-20 17:31:13 +0300412 [NL80211_ATTR_NAN_MASTER_PREF] = { .type = NLA_U8 },
413 [NL80211_ATTR_NAN_DUAL] = { .type = NLA_U8 },
Ayala Bekera442b762016-09-20 17:31:15 +0300414 [NL80211_ATTR_NAN_FUNC] = { .type = NLA_NESTED },
Johannes Berg55682962007-09-20 13:09:35 -0400415};
416
Johannes Berge31b8212010-10-05 19:39:30 +0200417/* policy for the key attributes */
Alexey Dobriyanb54452b2010-02-18 08:14:31 +0000418static const struct nla_policy nl80211_key_policy[NL80211_KEY_MAX + 1] = {
Johannes Bergfffd0932009-07-08 14:22:54 +0200419 [NL80211_KEY_DATA] = { .type = NLA_BINARY, .len = WLAN_MAX_KEY_LEN },
Johannes Bergb9454e82009-07-08 13:29:08 +0200420 [NL80211_KEY_IDX] = { .type = NLA_U8 },
421 [NL80211_KEY_CIPHER] = { .type = NLA_U32 },
Jouni Malinen81962262011-11-02 23:36:31 +0200422 [NL80211_KEY_SEQ] = { .type = NLA_BINARY, .len = 16 },
Johannes Bergb9454e82009-07-08 13:29:08 +0200423 [NL80211_KEY_DEFAULT] = { .type = NLA_FLAG },
424 [NL80211_KEY_DEFAULT_MGMT] = { .type = NLA_FLAG },
Johannes Berge31b8212010-10-05 19:39:30 +0200425 [NL80211_KEY_TYPE] = { .type = NLA_U32 },
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100426 [NL80211_KEY_DEFAULT_TYPES] = { .type = NLA_NESTED },
427};
428
429/* policy for the key default flags */
430static const struct nla_policy
431nl80211_key_default_policy[NUM_NL80211_KEY_DEFAULT_TYPES] = {
432 [NL80211_KEY_DEFAULT_TYPE_UNICAST] = { .type = NLA_FLAG },
433 [NL80211_KEY_DEFAULT_TYPE_MULTICAST] = { .type = NLA_FLAG },
Johannes Bergb9454e82009-07-08 13:29:08 +0200434};
435
Johannes Bergff1b6e62011-05-04 15:37:28 +0200436/* policy for WoWLAN attributes */
437static const struct nla_policy
438nl80211_wowlan_policy[NUM_NL80211_WOWLAN_TRIG] = {
439 [NL80211_WOWLAN_TRIG_ANY] = { .type = NLA_FLAG },
440 [NL80211_WOWLAN_TRIG_DISCONNECT] = { .type = NLA_FLAG },
441 [NL80211_WOWLAN_TRIG_MAGIC_PKT] = { .type = NLA_FLAG },
442 [NL80211_WOWLAN_TRIG_PKT_PATTERN] = { .type = NLA_NESTED },
Johannes Berg77dbbb12011-07-13 10:48:55 +0200443 [NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE] = { .type = NLA_FLAG },
444 [NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST] = { .type = NLA_FLAG },
445 [NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE] = { .type = NLA_FLAG },
446 [NL80211_WOWLAN_TRIG_RFKILL_RELEASE] = { .type = NLA_FLAG },
Johannes Berg2a0e0472013-01-23 22:57:40 +0100447 [NL80211_WOWLAN_TRIG_TCP_CONNECTION] = { .type = NLA_NESTED },
Luciano Coelho8cd4d452014-09-17 11:55:28 +0300448 [NL80211_WOWLAN_TRIG_NET_DETECT] = { .type = NLA_NESTED },
Johannes Berg2a0e0472013-01-23 22:57:40 +0100449};
450
451static const struct nla_policy
452nl80211_wowlan_tcp_policy[NUM_NL80211_WOWLAN_TCP] = {
453 [NL80211_WOWLAN_TCP_SRC_IPV4] = { .type = NLA_U32 },
454 [NL80211_WOWLAN_TCP_DST_IPV4] = { .type = NLA_U32 },
455 [NL80211_WOWLAN_TCP_DST_MAC] = { .len = ETH_ALEN },
456 [NL80211_WOWLAN_TCP_SRC_PORT] = { .type = NLA_U16 },
457 [NL80211_WOWLAN_TCP_DST_PORT] = { .type = NLA_U16 },
458 [NL80211_WOWLAN_TCP_DATA_PAYLOAD] = { .len = 1 },
459 [NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ] = {
460 .len = sizeof(struct nl80211_wowlan_tcp_data_seq)
461 },
462 [NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN] = {
463 .len = sizeof(struct nl80211_wowlan_tcp_data_token)
464 },
465 [NL80211_WOWLAN_TCP_DATA_INTERVAL] = { .type = NLA_U32 },
466 [NL80211_WOWLAN_TCP_WAKE_PAYLOAD] = { .len = 1 },
467 [NL80211_WOWLAN_TCP_WAKE_MASK] = { .len = 1 },
Johannes Bergff1b6e62011-05-04 15:37:28 +0200468};
469
Amitkumar Karwarbe29b99a2013-06-28 11:51:26 -0700470/* policy for coalesce rule attributes */
471static const struct nla_policy
472nl80211_coalesce_policy[NUM_NL80211_ATTR_COALESCE_RULE] = {
473 [NL80211_ATTR_COALESCE_RULE_DELAY] = { .type = NLA_U32 },
474 [NL80211_ATTR_COALESCE_RULE_CONDITION] = { .type = NLA_U32 },
475 [NL80211_ATTR_COALESCE_RULE_PKT_PATTERN] = { .type = NLA_NESTED },
476};
477
Johannes Berge5497d72011-07-05 16:35:40 +0200478/* policy for GTK rekey offload attributes */
479static const struct nla_policy
480nl80211_rekey_policy[NUM_NL80211_REKEY_DATA] = {
481 [NL80211_REKEY_DATA_KEK] = { .len = NL80211_KEK_LEN },
482 [NL80211_REKEY_DATA_KCK] = { .len = NL80211_KCK_LEN },
483 [NL80211_REKEY_DATA_REPLAY_CTR] = { .len = NL80211_REPLAY_CTR_LEN },
484};
485
Luciano Coelhoa1f1c212011-08-31 16:01:48 +0300486static const struct nla_policy
487nl80211_match_policy[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1] = {
Johannes Berg4a4ab0d2012-06-13 11:17:11 +0200488 [NL80211_SCHED_SCAN_MATCH_ATTR_SSID] = { .type = NLA_BINARY,
Luciano Coelhoa1f1c212011-08-31 16:01:48 +0300489 .len = IEEE80211_MAX_SSID_LEN },
Thomas Pedersen88e920b2012-06-21 11:09:54 -0700490 [NL80211_SCHED_SCAN_MATCH_ATTR_RSSI] = { .type = NLA_U32 },
Luciano Coelhoa1f1c212011-08-31 16:01:48 +0300491};
492
Avraham Stern3b06d272015-10-12 09:51:34 +0300493static const struct nla_policy
494nl80211_plan_policy[NL80211_SCHED_SCAN_PLAN_MAX + 1] = {
495 [NL80211_SCHED_SCAN_PLAN_INTERVAL] = { .type = NLA_U32 },
496 [NL80211_SCHED_SCAN_PLAN_ITERATIONS] = { .type = NLA_U32 },
497};
498
Arend van Spriel38de03d2016-03-02 20:37:18 +0100499static const struct nla_policy
500nl80211_bss_select_policy[NL80211_BSS_SELECT_ATTR_MAX + 1] = {
501 [NL80211_BSS_SELECT_ATTR_RSSI] = { .type = NLA_FLAG },
502 [NL80211_BSS_SELECT_ATTR_BAND_PREF] = { .type = NLA_U32 },
503 [NL80211_BSS_SELECT_ATTR_RSSI_ADJUST] = {
504 .len = sizeof(struct nl80211_bss_select_rssi_adjust)
505 },
506};
507
Ayala Bekera442b762016-09-20 17:31:15 +0300508/* policy for NAN function attributes */
509static const struct nla_policy
510nl80211_nan_func_policy[NL80211_NAN_FUNC_ATTR_MAX + 1] = {
511 [NL80211_NAN_FUNC_TYPE] = { .type = NLA_U8 },
512 [NL80211_NAN_FUNC_SERVICE_ID] = { .type = NLA_BINARY,
513 .len = NL80211_NAN_FUNC_SERVICE_ID_LEN },
514 [NL80211_NAN_FUNC_PUBLISH_TYPE] = { .type = NLA_U8 },
515 [NL80211_NAN_FUNC_PUBLISH_BCAST] = { .type = NLA_FLAG },
516 [NL80211_NAN_FUNC_SUBSCRIBE_ACTIVE] = { .type = NLA_FLAG },
517 [NL80211_NAN_FUNC_FOLLOW_UP_ID] = { .type = NLA_U8 },
518 [NL80211_NAN_FUNC_FOLLOW_UP_REQ_ID] = { .type = NLA_U8 },
519 [NL80211_NAN_FUNC_FOLLOW_UP_DEST] = { .len = ETH_ALEN },
520 [NL80211_NAN_FUNC_CLOSE_RANGE] = { .type = NLA_FLAG },
521 [NL80211_NAN_FUNC_TTL] = { .type = NLA_U32 },
522 [NL80211_NAN_FUNC_SERVICE_INFO] = { .type = NLA_BINARY,
523 .len = NL80211_NAN_FUNC_SERVICE_SPEC_INFO_MAX_LEN },
524 [NL80211_NAN_FUNC_SRF] = { .type = NLA_NESTED },
525 [NL80211_NAN_FUNC_RX_MATCH_FILTER] = { .type = NLA_NESTED },
526 [NL80211_NAN_FUNC_TX_MATCH_FILTER] = { .type = NLA_NESTED },
527 [NL80211_NAN_FUNC_INSTANCE_ID] = { .type = NLA_U8 },
528 [NL80211_NAN_FUNC_TERM_REASON] = { .type = NLA_U8 },
529};
530
531/* policy for Service Response Filter attributes */
532static const struct nla_policy
533nl80211_nan_srf_policy[NL80211_NAN_SRF_ATTR_MAX + 1] = {
534 [NL80211_NAN_SRF_INCLUDE] = { .type = NLA_FLAG },
535 [NL80211_NAN_SRF_BF] = { .type = NLA_BINARY,
536 .len = NL80211_NAN_FUNC_SRF_MAX_LEN },
537 [NL80211_NAN_SRF_BF_IDX] = { .type = NLA_U8 },
538 [NL80211_NAN_SRF_MAC_ADDRS] = { .type = NLA_NESTED },
539};
540
Johannes Berg97990a02013-04-19 01:02:55 +0200541static int nl80211_prepare_wdev_dump(struct sk_buff *skb,
542 struct netlink_callback *cb,
543 struct cfg80211_registered_device **rdev,
544 struct wireless_dev **wdev)
Holger Schuriga0438972009-11-11 11:30:02 +0100545{
Johannes Berg67748892010-10-04 21:14:06 +0200546 int err;
547
Johannes Berg67748892010-10-04 21:14:06 +0200548 rtnl_lock();
549
Johannes Berg97990a02013-04-19 01:02:55 +0200550 if (!cb->args[0]) {
551 err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize,
552 nl80211_fam.attrbuf, nl80211_fam.maxattr,
553 nl80211_policy);
554 if (err)
555 goto out_unlock;
556
557 *wdev = __cfg80211_wdev_from_attrs(sock_net(skb->sk),
558 nl80211_fam.attrbuf);
559 if (IS_ERR(*wdev)) {
560 err = PTR_ERR(*wdev);
561 goto out_unlock;
562 }
Zhao, Gangf26cbf42014-04-21 12:53:03 +0800563 *rdev = wiphy_to_rdev((*wdev)->wiphy);
Johannes Bergc319d502013-07-30 22:34:28 +0200564 /* 0 is the first index - add 1 to parse only once */
565 cb->args[0] = (*rdev)->wiphy_idx + 1;
Johannes Berg97990a02013-04-19 01:02:55 +0200566 cb->args[1] = (*wdev)->identifier;
567 } else {
Johannes Bergc319d502013-07-30 22:34:28 +0200568 /* subtract the 1 again here */
569 struct wiphy *wiphy = wiphy_idx_to_wiphy(cb->args[0] - 1);
Johannes Berg97990a02013-04-19 01:02:55 +0200570 struct wireless_dev *tmp;
571
572 if (!wiphy) {
573 err = -ENODEV;
574 goto out_unlock;
575 }
Zhao, Gangf26cbf42014-04-21 12:53:03 +0800576 *rdev = wiphy_to_rdev(wiphy);
Johannes Berg97990a02013-04-19 01:02:55 +0200577 *wdev = NULL;
578
Johannes Berg53873f12016-05-03 16:52:04 +0300579 list_for_each_entry(tmp, &(*rdev)->wiphy.wdev_list, list) {
Johannes Berg97990a02013-04-19 01:02:55 +0200580 if (tmp->identifier == cb->args[1]) {
581 *wdev = tmp;
582 break;
583 }
584 }
Johannes Berg97990a02013-04-19 01:02:55 +0200585
586 if (!*wdev) {
587 err = -ENODEV;
588 goto out_unlock;
589 }
Johannes Berg67748892010-10-04 21:14:06 +0200590 }
591
Johannes Berg67748892010-10-04 21:14:06 +0200592 return 0;
Johannes Berg97990a02013-04-19 01:02:55 +0200593 out_unlock:
Johannes Berg67748892010-10-04 21:14:06 +0200594 rtnl_unlock();
595 return err;
596}
597
Johannes Berg97990a02013-04-19 01:02:55 +0200598static void nl80211_finish_wdev_dump(struct cfg80211_registered_device *rdev)
Johannes Berg67748892010-10-04 21:14:06 +0200599{
Johannes Berg67748892010-10-04 21:14:06 +0200600 rtnl_unlock();
601}
602
Johannes Bergf4a11bb2009-03-27 12:40:28 +0100603/* IE validation */
604static bool is_valid_ie_attr(const struct nlattr *attr)
605{
606 const u8 *pos;
607 int len;
608
609 if (!attr)
610 return true;
611
612 pos = nla_data(attr);
613 len = nla_len(attr);
614
615 while (len) {
616 u8 elemlen;
617
618 if (len < 2)
619 return false;
620 len -= 2;
621
622 elemlen = pos[1];
623 if (elemlen > len)
624 return false;
625
626 len -= elemlen;
627 pos += 2 + elemlen;
628 }
629
630 return true;
631}
632
Johannes Berg55682962007-09-20 13:09:35 -0400633/* message building helper */
Eric W. Biederman15e47302012-09-07 20:12:54 +0000634static inline void *nl80211hdr_put(struct sk_buff *skb, u32 portid, u32 seq,
Johannes Berg55682962007-09-20 13:09:35 -0400635 int flags, u8 cmd)
636{
637 /* since there is no private header just add the generic one */
Eric W. Biederman15e47302012-09-07 20:12:54 +0000638 return genlmsg_put(skb, portid, seq, &nl80211_fam, flags, cmd);
Johannes Berg55682962007-09-20 13:09:35 -0400639}
640
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400641static int nl80211_msg_put_channel(struct sk_buff *msg,
Johannes Bergcdc89b92013-02-18 23:54:36 +0100642 struct ieee80211_channel *chan,
643 bool large)
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400644{
Rostislav Lisovyea077c12014-04-15 14:37:55 +0200645 /* Some channels must be completely excluded from the
646 * list to protect old user-space tools from breaking
647 */
648 if (!large && chan->flags &
649 (IEEE80211_CHAN_NO_10MHZ | IEEE80211_CHAN_NO_20MHZ))
650 return 0;
651
David S. Miller9360ffd2012-03-29 04:41:26 -0400652 if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_FREQ,
653 chan->center_freq))
654 goto nla_put_failure;
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400655
David S. Miller9360ffd2012-03-29 04:41:26 -0400656 if ((chan->flags & IEEE80211_CHAN_DISABLED) &&
657 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_DISABLED))
658 goto nla_put_failure;
Luis R. Rodriguez8fe02e12013-10-21 19:22:25 +0200659 if (chan->flags & IEEE80211_CHAN_NO_IR) {
660 if (nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_IR))
661 goto nla_put_failure;
662 if (nla_put_flag(msg, __NL80211_FREQUENCY_ATTR_NO_IBSS))
663 goto nla_put_failure;
664 }
Johannes Bergcdc89b92013-02-18 23:54:36 +0100665 if (chan->flags & IEEE80211_CHAN_RADAR) {
666 if (nla_put_flag(msg, NL80211_FREQUENCY_ATTR_RADAR))
667 goto nla_put_failure;
668 if (large) {
669 u32 time;
670
671 time = elapsed_jiffies_msecs(chan->dfs_state_entered);
672
673 if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_DFS_STATE,
674 chan->dfs_state))
675 goto nla_put_failure;
676 if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_DFS_TIME,
677 time))
678 goto nla_put_failure;
Janusz Dziedzic089027e2014-02-21 19:46:12 +0100679 if (nla_put_u32(msg,
680 NL80211_FREQUENCY_ATTR_DFS_CAC_TIME,
681 chan->dfs_cac_ms))
682 goto nla_put_failure;
Johannes Bergcdc89b92013-02-18 23:54:36 +0100683 }
684 }
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400685
Johannes Bergfe1abaf2013-02-27 15:39:45 +0100686 if (large) {
687 if ((chan->flags & IEEE80211_CHAN_NO_HT40MINUS) &&
688 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_HT40_MINUS))
689 goto nla_put_failure;
690 if ((chan->flags & IEEE80211_CHAN_NO_HT40PLUS) &&
691 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_HT40_PLUS))
692 goto nla_put_failure;
693 if ((chan->flags & IEEE80211_CHAN_NO_80MHZ) &&
694 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_80MHZ))
695 goto nla_put_failure;
696 if ((chan->flags & IEEE80211_CHAN_NO_160MHZ) &&
697 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_160MHZ))
698 goto nla_put_failure;
David Spinadel570dbde2014-02-23 09:12:59 +0200699 if ((chan->flags & IEEE80211_CHAN_INDOOR_ONLY) &&
700 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_INDOOR_ONLY))
701 goto nla_put_failure;
Arik Nemtsov06f207f2015-05-06 16:28:31 +0300702 if ((chan->flags & IEEE80211_CHAN_IR_CONCURRENT) &&
703 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_IR_CONCURRENT))
David Spinadel570dbde2014-02-23 09:12:59 +0200704 goto nla_put_failure;
Rostislav Lisovyea077c12014-04-15 14:37:55 +0200705 if ((chan->flags & IEEE80211_CHAN_NO_20MHZ) &&
706 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_20MHZ))
707 goto nla_put_failure;
708 if ((chan->flags & IEEE80211_CHAN_NO_10MHZ) &&
709 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_10MHZ))
710 goto nla_put_failure;
Johannes Bergfe1abaf2013-02-27 15:39:45 +0100711 }
712
David S. Miller9360ffd2012-03-29 04:41:26 -0400713 if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_MAX_TX_POWER,
714 DBM_TO_MBM(chan->max_power)))
715 goto nla_put_failure;
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400716
717 return 0;
718
719 nla_put_failure:
720 return -ENOBUFS;
721}
722
Johannes Berg55682962007-09-20 13:09:35 -0400723/* netlink command implementations */
724
Johannes Bergb9454e82009-07-08 13:29:08 +0200725struct key_parse {
726 struct key_params p;
727 int idx;
Johannes Berge31b8212010-10-05 19:39:30 +0200728 int type;
Johannes Bergb9454e82009-07-08 13:29:08 +0200729 bool def, defmgmt;
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100730 bool def_uni, def_multi;
Johannes Bergb9454e82009-07-08 13:29:08 +0200731};
732
733static int nl80211_parse_key_new(struct nlattr *key, struct key_parse *k)
734{
735 struct nlattr *tb[NL80211_KEY_MAX + 1];
736 int err = nla_parse_nested(tb, NL80211_KEY_MAX, key,
737 nl80211_key_policy);
738 if (err)
739 return err;
740
741 k->def = !!tb[NL80211_KEY_DEFAULT];
742 k->defmgmt = !!tb[NL80211_KEY_DEFAULT_MGMT];
743
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100744 if (k->def) {
745 k->def_uni = true;
746 k->def_multi = true;
747 }
748 if (k->defmgmt)
749 k->def_multi = true;
750
Johannes Bergb9454e82009-07-08 13:29:08 +0200751 if (tb[NL80211_KEY_IDX])
752 k->idx = nla_get_u8(tb[NL80211_KEY_IDX]);
753
754 if (tb[NL80211_KEY_DATA]) {
755 k->p.key = nla_data(tb[NL80211_KEY_DATA]);
756 k->p.key_len = nla_len(tb[NL80211_KEY_DATA]);
757 }
758
759 if (tb[NL80211_KEY_SEQ]) {
760 k->p.seq = nla_data(tb[NL80211_KEY_SEQ]);
761 k->p.seq_len = nla_len(tb[NL80211_KEY_SEQ]);
762 }
763
764 if (tb[NL80211_KEY_CIPHER])
765 k->p.cipher = nla_get_u32(tb[NL80211_KEY_CIPHER]);
766
Johannes Berge31b8212010-10-05 19:39:30 +0200767 if (tb[NL80211_KEY_TYPE]) {
768 k->type = nla_get_u32(tb[NL80211_KEY_TYPE]);
769 if (k->type < 0 || k->type >= NUM_NL80211_KEYTYPES)
770 return -EINVAL;
771 }
772
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100773 if (tb[NL80211_KEY_DEFAULT_TYPES]) {
774 struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES];
Kirtika Ruchandani7a087e72016-05-29 19:51:23 -0700775
Johannes Berg2da8f412012-01-20 13:52:37 +0100776 err = nla_parse_nested(kdt, NUM_NL80211_KEY_DEFAULT_TYPES - 1,
777 tb[NL80211_KEY_DEFAULT_TYPES],
778 nl80211_key_default_policy);
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100779 if (err)
780 return err;
781
782 k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST];
783 k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST];
784 }
785
Johannes Bergb9454e82009-07-08 13:29:08 +0200786 return 0;
787}
788
789static int nl80211_parse_key_old(struct genl_info *info, struct key_parse *k)
790{
791 if (info->attrs[NL80211_ATTR_KEY_DATA]) {
792 k->p.key = nla_data(info->attrs[NL80211_ATTR_KEY_DATA]);
793 k->p.key_len = nla_len(info->attrs[NL80211_ATTR_KEY_DATA]);
794 }
795
796 if (info->attrs[NL80211_ATTR_KEY_SEQ]) {
797 k->p.seq = nla_data(info->attrs[NL80211_ATTR_KEY_SEQ]);
798 k->p.seq_len = nla_len(info->attrs[NL80211_ATTR_KEY_SEQ]);
799 }
800
801 if (info->attrs[NL80211_ATTR_KEY_IDX])
802 k->idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]);
803
804 if (info->attrs[NL80211_ATTR_KEY_CIPHER])
805 k->p.cipher = nla_get_u32(info->attrs[NL80211_ATTR_KEY_CIPHER]);
806
807 k->def = !!info->attrs[NL80211_ATTR_KEY_DEFAULT];
808 k->defmgmt = !!info->attrs[NL80211_ATTR_KEY_DEFAULT_MGMT];
809
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100810 if (k->def) {
811 k->def_uni = true;
812 k->def_multi = true;
813 }
814 if (k->defmgmt)
815 k->def_multi = true;
816
Johannes Berge31b8212010-10-05 19:39:30 +0200817 if (info->attrs[NL80211_ATTR_KEY_TYPE]) {
818 k->type = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]);
819 if (k->type < 0 || k->type >= NUM_NL80211_KEYTYPES)
820 return -EINVAL;
821 }
822
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100823 if (info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES]) {
824 struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES];
825 int err = nla_parse_nested(
826 kdt, NUM_NL80211_KEY_DEFAULT_TYPES - 1,
827 info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES],
828 nl80211_key_default_policy);
829 if (err)
830 return err;
831
832 k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST];
833 k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST];
834 }
835
Johannes Bergb9454e82009-07-08 13:29:08 +0200836 return 0;
837}
838
839static int nl80211_parse_key(struct genl_info *info, struct key_parse *k)
840{
841 int err;
842
843 memset(k, 0, sizeof(*k));
844 k->idx = -1;
Johannes Berge31b8212010-10-05 19:39:30 +0200845 k->type = -1;
Johannes Bergb9454e82009-07-08 13:29:08 +0200846
847 if (info->attrs[NL80211_ATTR_KEY])
848 err = nl80211_parse_key_new(info->attrs[NL80211_ATTR_KEY], k);
849 else
850 err = nl80211_parse_key_old(info, k);
851
852 if (err)
853 return err;
854
855 if (k->def && k->defmgmt)
856 return -EINVAL;
857
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100858 if (k->defmgmt) {
859 if (k->def_uni || !k->def_multi)
860 return -EINVAL;
861 }
862
Johannes Bergb9454e82009-07-08 13:29:08 +0200863 if (k->idx != -1) {
864 if (k->defmgmt) {
865 if (k->idx < 4 || k->idx > 5)
866 return -EINVAL;
867 } else if (k->def) {
868 if (k->idx < 0 || k->idx > 3)
869 return -EINVAL;
870 } else {
871 if (k->idx < 0 || k->idx > 5)
872 return -EINVAL;
873 }
874 }
875
876 return 0;
877}
878
Johannes Bergfffd0932009-07-08 14:22:54 +0200879static struct cfg80211_cached_keys *
880nl80211_parse_connkeys(struct cfg80211_registered_device *rdev,
Sujith Manoharande7044e2012-10-18 10:19:28 +0530881 struct nlattr *keys, bool *no_ht)
Johannes Bergfffd0932009-07-08 14:22:54 +0200882{
883 struct key_parse parse;
884 struct nlattr *key;
885 struct cfg80211_cached_keys *result;
886 int rem, err, def = 0;
Johannes Bergf1c1f172016-09-13 17:08:23 +0200887 bool have_key = false;
888
889 nla_for_each_nested(key, keys, rem) {
890 have_key = true;
891 break;
892 }
893
894 if (!have_key)
895 return NULL;
Johannes Bergfffd0932009-07-08 14:22:54 +0200896
897 result = kzalloc(sizeof(*result), GFP_KERNEL);
898 if (!result)
899 return ERR_PTR(-ENOMEM);
900
901 result->def = -1;
Johannes Bergfffd0932009-07-08 14:22:54 +0200902
903 nla_for_each_nested(key, keys, rem) {
904 memset(&parse, 0, sizeof(parse));
905 parse.idx = -1;
906
907 err = nl80211_parse_key_new(key, &parse);
908 if (err)
909 goto error;
910 err = -EINVAL;
911 if (!parse.p.key)
912 goto error;
Johannes Berg42ee2312016-09-13 15:51:03 +0200913 if (parse.idx < 0 || parse.idx > 3)
Johannes Bergfffd0932009-07-08 14:22:54 +0200914 goto error;
915 if (parse.def) {
916 if (def)
917 goto error;
918 def = 1;
919 result->def = parse.idx;
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100920 if (!parse.def_uni || !parse.def_multi)
921 goto error;
Johannes Bergfffd0932009-07-08 14:22:54 +0200922 } else if (parse.defmgmt)
923 goto error;
924 err = cfg80211_validate_key_settings(rdev, &parse.p,
Johannes Berge31b8212010-10-05 19:39:30 +0200925 parse.idx, false, NULL);
Johannes Bergfffd0932009-07-08 14:22:54 +0200926 if (err)
927 goto error;
Johannes Berg386b1f22016-09-13 16:10:02 +0200928 if (parse.p.cipher != WLAN_CIPHER_SUITE_WEP40 &&
929 parse.p.cipher != WLAN_CIPHER_SUITE_WEP104) {
930 err = -EINVAL;
931 goto error;
932 }
Johannes Bergfffd0932009-07-08 14:22:54 +0200933 result->params[parse.idx].cipher = parse.p.cipher;
934 result->params[parse.idx].key_len = parse.p.key_len;
935 result->params[parse.idx].key = result->data[parse.idx];
936 memcpy(result->data[parse.idx], parse.p.key, parse.p.key_len);
Sujith Manoharande7044e2012-10-18 10:19:28 +0530937
Johannes Berg386b1f22016-09-13 16:10:02 +0200938 /* must be WEP key if we got here */
939 if (no_ht)
940 *no_ht = true;
Johannes Bergfffd0932009-07-08 14:22:54 +0200941 }
942
Johannes Bergf1c1f172016-09-13 17:08:23 +0200943 if (result->def < 0) {
944 err = -EINVAL;
945 goto error;
946 }
947
Johannes Bergfffd0932009-07-08 14:22:54 +0200948 return result;
949 error:
950 kfree(result);
951 return ERR_PTR(err);
952}
953
954static int nl80211_key_allowed(struct wireless_dev *wdev)
955{
956 ASSERT_WDEV_LOCK(wdev);
957
Johannes Bergfffd0932009-07-08 14:22:54 +0200958 switch (wdev->iftype) {
959 case NL80211_IFTYPE_AP:
960 case NL80211_IFTYPE_AP_VLAN:
Johannes Berg074ac8d2010-09-16 14:58:22 +0200961 case NL80211_IFTYPE_P2P_GO:
Thomas Pedersenff973af2011-05-03 16:57:12 -0700962 case NL80211_IFTYPE_MESH_POINT:
Johannes Bergfffd0932009-07-08 14:22:54 +0200963 break;
964 case NL80211_IFTYPE_ADHOC:
Johannes Bergfffd0932009-07-08 14:22:54 +0200965 case NL80211_IFTYPE_STATION:
Johannes Berg074ac8d2010-09-16 14:58:22 +0200966 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Bergceca7b72013-05-16 00:55:45 +0200967 if (!wdev->current_bss)
Johannes Bergfffd0932009-07-08 14:22:54 +0200968 return -ENOLINK;
969 break;
Johannes Bergde4fcba2014-10-31 14:16:12 +0100970 case NL80211_IFTYPE_UNSPECIFIED:
Rostislav Lisovy6e0bd6c2014-11-03 10:33:18 +0100971 case NL80211_IFTYPE_OCB:
Johannes Bergde4fcba2014-10-31 14:16:12 +0100972 case NL80211_IFTYPE_MONITOR:
Ayala Bekercb3b7d82016-09-20 17:31:13 +0300973 case NL80211_IFTYPE_NAN:
Johannes Bergde4fcba2014-10-31 14:16:12 +0100974 case NL80211_IFTYPE_P2P_DEVICE:
975 case NL80211_IFTYPE_WDS:
976 case NUM_NL80211_IFTYPES:
Johannes Bergfffd0932009-07-08 14:22:54 +0200977 return -EINVAL;
978 }
979
980 return 0;
981}
982
Jouni Malinen664834d2014-01-15 00:01:44 +0200983static struct ieee80211_channel *nl80211_get_valid_chan(struct wiphy *wiphy,
984 struct nlattr *tb)
985{
986 struct ieee80211_channel *chan;
987
988 if (tb == NULL)
989 return NULL;
990 chan = ieee80211_get_channel(wiphy, nla_get_u32(tb));
991 if (!chan || chan->flags & IEEE80211_CHAN_DISABLED)
992 return NULL;
993 return chan;
994}
995
Johannes Berg7527a782011-05-13 10:58:57 +0200996static int nl80211_put_iftypes(struct sk_buff *msg, u32 attr, u16 ifmodes)
997{
998 struct nlattr *nl_modes = nla_nest_start(msg, attr);
999 int i;
1000
1001 if (!nl_modes)
1002 goto nla_put_failure;
1003
1004 i = 0;
1005 while (ifmodes) {
David S. Miller9360ffd2012-03-29 04:41:26 -04001006 if ((ifmodes & 1) && nla_put_flag(msg, i))
1007 goto nla_put_failure;
Johannes Berg7527a782011-05-13 10:58:57 +02001008 ifmodes >>= 1;
1009 i++;
1010 }
1011
1012 nla_nest_end(msg, nl_modes);
1013 return 0;
1014
1015nla_put_failure:
1016 return -ENOBUFS;
1017}
1018
1019static int nl80211_put_iface_combinations(struct wiphy *wiphy,
Johannes Bergcdc89b92013-02-18 23:54:36 +01001020 struct sk_buff *msg,
1021 bool large)
Johannes Berg7527a782011-05-13 10:58:57 +02001022{
1023 struct nlattr *nl_combis;
1024 int i, j;
1025
1026 nl_combis = nla_nest_start(msg,
1027 NL80211_ATTR_INTERFACE_COMBINATIONS);
1028 if (!nl_combis)
1029 goto nla_put_failure;
1030
1031 for (i = 0; i < wiphy->n_iface_combinations; i++) {
1032 const struct ieee80211_iface_combination *c;
1033 struct nlattr *nl_combi, *nl_limits;
1034
1035 c = &wiphy->iface_combinations[i];
1036
1037 nl_combi = nla_nest_start(msg, i + 1);
1038 if (!nl_combi)
1039 goto nla_put_failure;
1040
1041 nl_limits = nla_nest_start(msg, NL80211_IFACE_COMB_LIMITS);
1042 if (!nl_limits)
1043 goto nla_put_failure;
1044
1045 for (j = 0; j < c->n_limits; j++) {
1046 struct nlattr *nl_limit;
1047
1048 nl_limit = nla_nest_start(msg, j + 1);
1049 if (!nl_limit)
1050 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04001051 if (nla_put_u32(msg, NL80211_IFACE_LIMIT_MAX,
1052 c->limits[j].max))
1053 goto nla_put_failure;
Johannes Berg7527a782011-05-13 10:58:57 +02001054 if (nl80211_put_iftypes(msg, NL80211_IFACE_LIMIT_TYPES,
1055 c->limits[j].types))
1056 goto nla_put_failure;
1057 nla_nest_end(msg, nl_limit);
1058 }
1059
1060 nla_nest_end(msg, nl_limits);
1061
David S. Miller9360ffd2012-03-29 04:41:26 -04001062 if (c->beacon_int_infra_match &&
1063 nla_put_flag(msg, NL80211_IFACE_COMB_STA_AP_BI_MATCH))
1064 goto nla_put_failure;
1065 if (nla_put_u32(msg, NL80211_IFACE_COMB_NUM_CHANNELS,
1066 c->num_different_channels) ||
1067 nla_put_u32(msg, NL80211_IFACE_COMB_MAXNUM,
1068 c->max_interfaces))
1069 goto nla_put_failure;
Johannes Bergcdc89b92013-02-18 23:54:36 +01001070 if (large &&
Felix Fietkau8c48b502014-05-05 11:48:40 +02001071 (nla_put_u32(msg, NL80211_IFACE_COMB_RADAR_DETECT_WIDTHS,
1072 c->radar_detect_widths) ||
1073 nla_put_u32(msg, NL80211_IFACE_COMB_RADAR_DETECT_REGIONS,
1074 c->radar_detect_regions)))
Johannes Bergcdc89b92013-02-18 23:54:36 +01001075 goto nla_put_failure;
Johannes Berg7527a782011-05-13 10:58:57 +02001076
1077 nla_nest_end(msg, nl_combi);
1078 }
1079
1080 nla_nest_end(msg, nl_combis);
1081
1082 return 0;
1083nla_put_failure:
1084 return -ENOBUFS;
1085}
1086
Johannes Berg3713b4e2013-02-14 16:19:38 +01001087#ifdef CONFIG_PM
Johannes Bergb56cf722013-02-20 01:02:38 +01001088static int nl80211_send_wowlan_tcp_caps(struct cfg80211_registered_device *rdev,
1089 struct sk_buff *msg)
1090{
Johannes Berg964dc9e2013-06-03 17:25:34 +02001091 const struct wiphy_wowlan_tcp_support *tcp = rdev->wiphy.wowlan->tcp;
Johannes Bergb56cf722013-02-20 01:02:38 +01001092 struct nlattr *nl_tcp;
1093
1094 if (!tcp)
1095 return 0;
1096
1097 nl_tcp = nla_nest_start(msg, NL80211_WOWLAN_TRIG_TCP_CONNECTION);
1098 if (!nl_tcp)
1099 return -ENOBUFS;
1100
1101 if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD,
1102 tcp->data_payload_max))
1103 return -ENOBUFS;
1104
1105 if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD,
1106 tcp->data_payload_max))
1107 return -ENOBUFS;
1108
1109 if (tcp->seq && nla_put_flag(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ))
1110 return -ENOBUFS;
1111
1112 if (tcp->tok && nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN,
1113 sizeof(*tcp->tok), tcp->tok))
1114 return -ENOBUFS;
1115
1116 if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_INTERVAL,
1117 tcp->data_interval_max))
1118 return -ENOBUFS;
1119
1120 if (nla_put_u32(msg, NL80211_WOWLAN_TCP_WAKE_PAYLOAD,
1121 tcp->wake_payload_max))
1122 return -ENOBUFS;
1123
1124 nla_nest_end(msg, nl_tcp);
1125 return 0;
1126}
1127
Johannes Berg3713b4e2013-02-14 16:19:38 +01001128static int nl80211_send_wowlan(struct sk_buff *msg,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001129 struct cfg80211_registered_device *rdev,
Johannes Bergb56cf722013-02-20 01:02:38 +01001130 bool large)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001131{
1132 struct nlattr *nl_wowlan;
1133
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001134 if (!rdev->wiphy.wowlan)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001135 return 0;
1136
1137 nl_wowlan = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS_SUPPORTED);
1138 if (!nl_wowlan)
1139 return -ENOBUFS;
1140
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001141 if (((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_ANY) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001142 nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) ||
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001143 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_DISCONNECT) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001144 nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) ||
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001145 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001146 nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) ||
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001147 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_SUPPORTS_GTK_REKEY) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001148 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED)) ||
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001149 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001150 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) ||
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001151 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001152 nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) ||
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001153 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001154 nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) ||
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001155 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001156 nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE)))
1157 return -ENOBUFS;
1158
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001159 if (rdev->wiphy.wowlan->n_patterns) {
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07001160 struct nl80211_pattern_support pat = {
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001161 .max_patterns = rdev->wiphy.wowlan->n_patterns,
1162 .min_pattern_len = rdev->wiphy.wowlan->pattern_min_len,
1163 .max_pattern_len = rdev->wiphy.wowlan->pattern_max_len,
1164 .max_pkt_offset = rdev->wiphy.wowlan->max_pkt_offset,
Johannes Berg3713b4e2013-02-14 16:19:38 +01001165 };
1166
1167 if (nla_put(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN,
1168 sizeof(pat), &pat))
1169 return -ENOBUFS;
1170 }
1171
Luciano Coelho75453cc2015-01-09 14:06:37 +02001172 if ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_NET_DETECT) &&
1173 nla_put_u32(msg, NL80211_WOWLAN_TRIG_NET_DETECT,
1174 rdev->wiphy.wowlan->max_nd_match_sets))
1175 return -ENOBUFS;
1176
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001177 if (large && nl80211_send_wowlan_tcp_caps(rdev, msg))
Johannes Bergb56cf722013-02-20 01:02:38 +01001178 return -ENOBUFS;
1179
Johannes Berg3713b4e2013-02-14 16:19:38 +01001180 nla_nest_end(msg, nl_wowlan);
1181
1182 return 0;
1183}
1184#endif
1185
Amitkumar Karwarbe29b99a2013-06-28 11:51:26 -07001186static int nl80211_send_coalesce(struct sk_buff *msg,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001187 struct cfg80211_registered_device *rdev)
Amitkumar Karwarbe29b99a2013-06-28 11:51:26 -07001188{
1189 struct nl80211_coalesce_rule_support rule;
1190
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001191 if (!rdev->wiphy.coalesce)
Amitkumar Karwarbe29b99a2013-06-28 11:51:26 -07001192 return 0;
1193
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001194 rule.max_rules = rdev->wiphy.coalesce->n_rules;
1195 rule.max_delay = rdev->wiphy.coalesce->max_delay;
1196 rule.pat.max_patterns = rdev->wiphy.coalesce->n_patterns;
1197 rule.pat.min_pattern_len = rdev->wiphy.coalesce->pattern_min_len;
1198 rule.pat.max_pattern_len = rdev->wiphy.coalesce->pattern_max_len;
1199 rule.pat.max_pkt_offset = rdev->wiphy.coalesce->max_pkt_offset;
Amitkumar Karwarbe29b99a2013-06-28 11:51:26 -07001200
1201 if (nla_put(msg, NL80211_ATTR_COALESCE_RULE, sizeof(rule), &rule))
1202 return -ENOBUFS;
1203
1204 return 0;
1205}
1206
Johannes Berg3713b4e2013-02-14 16:19:38 +01001207static int nl80211_send_band_rateinfo(struct sk_buff *msg,
1208 struct ieee80211_supported_band *sband)
1209{
1210 struct nlattr *nl_rates, *nl_rate;
1211 struct ieee80211_rate *rate;
1212 int i;
1213
1214 /* add HT info */
1215 if (sband->ht_cap.ht_supported &&
1216 (nla_put(msg, NL80211_BAND_ATTR_HT_MCS_SET,
1217 sizeof(sband->ht_cap.mcs),
1218 &sband->ht_cap.mcs) ||
1219 nla_put_u16(msg, NL80211_BAND_ATTR_HT_CAPA,
1220 sband->ht_cap.cap) ||
1221 nla_put_u8(msg, NL80211_BAND_ATTR_HT_AMPDU_FACTOR,
1222 sband->ht_cap.ampdu_factor) ||
1223 nla_put_u8(msg, NL80211_BAND_ATTR_HT_AMPDU_DENSITY,
1224 sband->ht_cap.ampdu_density)))
1225 return -ENOBUFS;
1226
1227 /* add VHT info */
1228 if (sband->vht_cap.vht_supported &&
1229 (nla_put(msg, NL80211_BAND_ATTR_VHT_MCS_SET,
1230 sizeof(sband->vht_cap.vht_mcs),
1231 &sband->vht_cap.vht_mcs) ||
1232 nla_put_u32(msg, NL80211_BAND_ATTR_VHT_CAPA,
1233 sband->vht_cap.cap)))
1234 return -ENOBUFS;
1235
1236 /* add bitrates */
1237 nl_rates = nla_nest_start(msg, NL80211_BAND_ATTR_RATES);
1238 if (!nl_rates)
1239 return -ENOBUFS;
1240
1241 for (i = 0; i < sband->n_bitrates; i++) {
1242 nl_rate = nla_nest_start(msg, i);
1243 if (!nl_rate)
1244 return -ENOBUFS;
1245
1246 rate = &sband->bitrates[i];
1247 if (nla_put_u32(msg, NL80211_BITRATE_ATTR_RATE,
1248 rate->bitrate))
1249 return -ENOBUFS;
1250 if ((rate->flags & IEEE80211_RATE_SHORT_PREAMBLE) &&
1251 nla_put_flag(msg,
1252 NL80211_BITRATE_ATTR_2GHZ_SHORTPREAMBLE))
1253 return -ENOBUFS;
1254
1255 nla_nest_end(msg, nl_rate);
1256 }
1257
1258 nla_nest_end(msg, nl_rates);
1259
1260 return 0;
1261}
1262
1263static int
1264nl80211_send_mgmt_stypes(struct sk_buff *msg,
1265 const struct ieee80211_txrx_stypes *mgmt_stypes)
1266{
1267 u16 stypes;
1268 struct nlattr *nl_ftypes, *nl_ifs;
1269 enum nl80211_iftype ift;
1270 int i;
1271
1272 if (!mgmt_stypes)
1273 return 0;
1274
1275 nl_ifs = nla_nest_start(msg, NL80211_ATTR_TX_FRAME_TYPES);
1276 if (!nl_ifs)
1277 return -ENOBUFS;
1278
1279 for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) {
1280 nl_ftypes = nla_nest_start(msg, ift);
1281 if (!nl_ftypes)
1282 return -ENOBUFS;
1283 i = 0;
1284 stypes = mgmt_stypes[ift].tx;
1285 while (stypes) {
1286 if ((stypes & 1) &&
1287 nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE,
1288 (i << 4) | IEEE80211_FTYPE_MGMT))
1289 return -ENOBUFS;
1290 stypes >>= 1;
1291 i++;
1292 }
1293 nla_nest_end(msg, nl_ftypes);
1294 }
1295
1296 nla_nest_end(msg, nl_ifs);
1297
1298 nl_ifs = nla_nest_start(msg, NL80211_ATTR_RX_FRAME_TYPES);
1299 if (!nl_ifs)
1300 return -ENOBUFS;
1301
1302 for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) {
1303 nl_ftypes = nla_nest_start(msg, ift);
1304 if (!nl_ftypes)
1305 return -ENOBUFS;
1306 i = 0;
1307 stypes = mgmt_stypes[ift].rx;
1308 while (stypes) {
1309 if ((stypes & 1) &&
1310 nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE,
1311 (i << 4) | IEEE80211_FTYPE_MGMT))
1312 return -ENOBUFS;
1313 stypes >>= 1;
1314 i++;
1315 }
1316 nla_nest_end(msg, nl_ftypes);
1317 }
1318 nla_nest_end(msg, nl_ifs);
1319
1320 return 0;
1321}
1322
Johannes Berg86e8cf92013-06-19 10:57:22 +02001323struct nl80211_dump_wiphy_state {
1324 s64 filter_wiphy;
1325 long start;
Kanchanapally, Vidyullatha019ae3a2016-05-16 10:41:04 +05301326 long split_start, band_start, chan_start, capa_start;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001327 bool split;
1328};
1329
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001330static int nl80211_send_wiphy(struct cfg80211_registered_device *rdev,
Johannes Berg3bb20552014-05-26 13:52:25 +02001331 enum nl80211_commands cmd,
Johannes Berg3713b4e2013-02-14 16:19:38 +01001332 struct sk_buff *msg, u32 portid, u32 seq,
Johannes Berg86e8cf92013-06-19 10:57:22 +02001333 int flags, struct nl80211_dump_wiphy_state *state)
Johannes Berg55682962007-09-20 13:09:35 -04001334{
1335 void *hdr;
Johannes Bergee688b002008-01-24 19:38:39 +01001336 struct nlattr *nl_bands, *nl_band;
1337 struct nlattr *nl_freqs, *nl_freq;
Johannes Berg8fdc6212009-03-14 09:34:01 +01001338 struct nlattr *nl_cmds;
Johannes Berg57fbcce2016-04-12 15:56:15 +02001339 enum nl80211_band band;
Johannes Bergee688b002008-01-24 19:38:39 +01001340 struct ieee80211_channel *chan;
Johannes Bergee688b002008-01-24 19:38:39 +01001341 int i;
Johannes Berg2e161f782010-08-12 15:38:38 +02001342 const struct ieee80211_txrx_stypes *mgmt_stypes =
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001343 rdev->wiphy.mgmt_stypes;
Johannes Bergfe1abaf2013-02-27 15:39:45 +01001344 u32 features;
Johannes Berg55682962007-09-20 13:09:35 -04001345
Johannes Berg3bb20552014-05-26 13:52:25 +02001346 hdr = nl80211hdr_put(msg, portid, seq, flags, cmd);
Johannes Berg55682962007-09-20 13:09:35 -04001347 if (!hdr)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001348 return -ENOBUFS;
1349
Johannes Berg86e8cf92013-06-19 10:57:22 +02001350 if (WARN_ON(!state))
1351 return -EINVAL;
Johannes Berg55682962007-09-20 13:09:35 -04001352
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001353 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001354 nla_put_string(msg, NL80211_ATTR_WIPHY_NAME,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001355 wiphy_name(&rdev->wiphy)) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04001356 nla_put_u32(msg, NL80211_ATTR_GENERATION,
Johannes Berg3713b4e2013-02-14 16:19:38 +01001357 cfg80211_rdev_list_generation))
David S. Miller9360ffd2012-03-29 04:41:26 -04001358 goto nla_put_failure;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02001359
Johannes Berg3bb20552014-05-26 13:52:25 +02001360 if (cmd != NL80211_CMD_NEW_WIPHY)
1361 goto finish;
1362
Johannes Berg86e8cf92013-06-19 10:57:22 +02001363 switch (state->split_start) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001364 case 0:
1365 if (nla_put_u8(msg, NL80211_ATTR_WIPHY_RETRY_SHORT,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001366 rdev->wiphy.retry_short) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001367 nla_put_u8(msg, NL80211_ATTR_WIPHY_RETRY_LONG,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001368 rdev->wiphy.retry_long) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001369 nla_put_u32(msg, NL80211_ATTR_WIPHY_FRAG_THRESHOLD,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001370 rdev->wiphy.frag_threshold) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001371 nla_put_u32(msg, NL80211_ATTR_WIPHY_RTS_THRESHOLD,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001372 rdev->wiphy.rts_threshold) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001373 nla_put_u8(msg, NL80211_ATTR_WIPHY_COVERAGE_CLASS,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001374 rdev->wiphy.coverage_class) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001375 nla_put_u8(msg, NL80211_ATTR_MAX_NUM_SCAN_SSIDS,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001376 rdev->wiphy.max_scan_ssids) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001377 nla_put_u8(msg, NL80211_ATTR_MAX_NUM_SCHED_SCAN_SSIDS,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001378 rdev->wiphy.max_sched_scan_ssids) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001379 nla_put_u16(msg, NL80211_ATTR_MAX_SCAN_IE_LEN,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001380 rdev->wiphy.max_scan_ie_len) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001381 nla_put_u16(msg, NL80211_ATTR_MAX_SCHED_SCAN_IE_LEN,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001382 rdev->wiphy.max_sched_scan_ie_len) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001383 nla_put_u8(msg, NL80211_ATTR_MAX_MATCH_SETS,
Avraham Stern3b06d272015-10-12 09:51:34 +03001384 rdev->wiphy.max_match_sets) ||
1385 nla_put_u32(msg, NL80211_ATTR_MAX_NUM_SCHED_SCAN_PLANS,
1386 rdev->wiphy.max_sched_scan_plans) ||
1387 nla_put_u32(msg, NL80211_ATTR_MAX_SCAN_PLAN_INTERVAL,
1388 rdev->wiphy.max_sched_scan_plan_interval) ||
1389 nla_put_u32(msg, NL80211_ATTR_MAX_SCAN_PLAN_ITERATIONS,
1390 rdev->wiphy.max_sched_scan_plan_iterations))
Johannes Bergee688b002008-01-24 19:38:39 +01001391 goto nla_put_failure;
1392
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001393 if ((rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001394 nla_put_flag(msg, NL80211_ATTR_SUPPORT_IBSS_RSN))
1395 goto nla_put_failure;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001396 if ((rdev->wiphy.flags & WIPHY_FLAG_MESH_AUTH) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001397 nla_put_flag(msg, NL80211_ATTR_SUPPORT_MESH_AUTH))
1398 goto nla_put_failure;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001399 if ((rdev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001400 nla_put_flag(msg, NL80211_ATTR_SUPPORT_AP_UAPSD))
1401 goto nla_put_failure;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001402 if ((rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_FW_ROAM) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001403 nla_put_flag(msg, NL80211_ATTR_ROAM_SUPPORT))
1404 goto nla_put_failure;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001405 if ((rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001406 nla_put_flag(msg, NL80211_ATTR_TDLS_SUPPORT))
1407 goto nla_put_failure;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001408 if ((rdev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001409 nla_put_flag(msg, NL80211_ATTR_TDLS_EXTERNAL_SETUP))
David S. Miller9360ffd2012-03-29 04:41:26 -04001410 goto nla_put_failure;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001411 state->split_start++;
1412 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001413 break;
1414 case 1:
1415 if (nla_put(msg, NL80211_ATTR_CIPHER_SUITES,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001416 sizeof(u32) * rdev->wiphy.n_cipher_suites,
1417 rdev->wiphy.cipher_suites))
Mahesh Palivelabf0c111e2012-06-22 07:27:46 +00001418 goto nla_put_failure;
1419
Johannes Berg3713b4e2013-02-14 16:19:38 +01001420 if (nla_put_u8(msg, NL80211_ATTR_MAX_NUM_PMKIDS,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001421 rdev->wiphy.max_num_pmkids))
Johannes Bergee688b002008-01-24 19:38:39 +01001422 goto nla_put_failure;
1423
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001424 if ((rdev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001425 nla_put_flag(msg, NL80211_ATTR_CONTROL_PORT_ETHERTYPE))
1426 goto nla_put_failure;
Johannes Bergee688b002008-01-24 19:38:39 +01001427
Johannes Berg3713b4e2013-02-14 16:19:38 +01001428 if (nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_TX,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001429 rdev->wiphy.available_antennas_tx) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001430 nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_RX,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001431 rdev->wiphy.available_antennas_rx))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001432 goto nla_put_failure;
Johannes Bergee688b002008-01-24 19:38:39 +01001433
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001434 if ((rdev->wiphy.flags & WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001435 nla_put_u32(msg, NL80211_ATTR_PROBE_RESP_OFFLOAD,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001436 rdev->wiphy.probe_resp_offload))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001437 goto nla_put_failure;
Jouni Malinene2f367f262008-11-21 19:01:30 +02001438
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001439 if ((rdev->wiphy.available_antennas_tx ||
1440 rdev->wiphy.available_antennas_rx) &&
1441 rdev->ops->get_antenna) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001442 u32 tx_ant = 0, rx_ant = 0;
1443 int res;
Kirtika Ruchandani7a087e72016-05-29 19:51:23 -07001444
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001445 res = rdev_get_antenna(rdev, &tx_ant, &rx_ant);
Johannes Berg3713b4e2013-02-14 16:19:38 +01001446 if (!res) {
1447 if (nla_put_u32(msg,
1448 NL80211_ATTR_WIPHY_ANTENNA_TX,
1449 tx_ant) ||
1450 nla_put_u32(msg,
1451 NL80211_ATTR_WIPHY_ANTENNA_RX,
1452 rx_ant))
1453 goto nla_put_failure;
1454 }
Johannes Bergee688b002008-01-24 19:38:39 +01001455 }
1456
Johannes Berg86e8cf92013-06-19 10:57:22 +02001457 state->split_start++;
1458 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001459 break;
1460 case 2:
1461 if (nl80211_put_iftypes(msg, NL80211_ATTR_SUPPORTED_IFTYPES,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001462 rdev->wiphy.interface_modes))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001463 goto nla_put_failure;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001464 state->split_start++;
1465 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001466 break;
1467 case 3:
1468 nl_bands = nla_nest_start(msg, NL80211_ATTR_WIPHY_BANDS);
1469 if (!nl_bands)
Johannes Bergee688b002008-01-24 19:38:39 +01001470 goto nla_put_failure;
1471
Johannes Berg86e8cf92013-06-19 10:57:22 +02001472 for (band = state->band_start;
Johannes Berg57fbcce2016-04-12 15:56:15 +02001473 band < NUM_NL80211_BANDS; band++) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001474 struct ieee80211_supported_band *sband;
1475
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001476 sband = rdev->wiphy.bands[band];
Johannes Berg3713b4e2013-02-14 16:19:38 +01001477
1478 if (!sband)
1479 continue;
1480
1481 nl_band = nla_nest_start(msg, band);
1482 if (!nl_band)
Johannes Bergee688b002008-01-24 19:38:39 +01001483 goto nla_put_failure;
1484
Johannes Berg86e8cf92013-06-19 10:57:22 +02001485 switch (state->chan_start) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001486 case 0:
1487 if (nl80211_send_band_rateinfo(msg, sband))
1488 goto nla_put_failure;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001489 state->chan_start++;
1490 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001491 break;
1492 default:
1493 /* add frequencies */
1494 nl_freqs = nla_nest_start(
1495 msg, NL80211_BAND_ATTR_FREQS);
1496 if (!nl_freqs)
1497 goto nla_put_failure;
Johannes Bergee688b002008-01-24 19:38:39 +01001498
Johannes Berg86e8cf92013-06-19 10:57:22 +02001499 for (i = state->chan_start - 1;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001500 i < sband->n_channels;
1501 i++) {
1502 nl_freq = nla_nest_start(msg, i);
1503 if (!nl_freq)
1504 goto nla_put_failure;
1505
1506 chan = &sband->channels[i];
1507
Johannes Berg86e8cf92013-06-19 10:57:22 +02001508 if (nl80211_msg_put_channel(
1509 msg, chan,
1510 state->split))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001511 goto nla_put_failure;
1512
1513 nla_nest_end(msg, nl_freq);
Johannes Berg86e8cf92013-06-19 10:57:22 +02001514 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001515 break;
1516 }
1517 if (i < sband->n_channels)
Johannes Berg86e8cf92013-06-19 10:57:22 +02001518 state->chan_start = i + 2;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001519 else
Johannes Berg86e8cf92013-06-19 10:57:22 +02001520 state->chan_start = 0;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001521 nla_nest_end(msg, nl_freqs);
1522 }
1523
1524 nla_nest_end(msg, nl_band);
1525
Johannes Berg86e8cf92013-06-19 10:57:22 +02001526 if (state->split) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001527 /* start again here */
Johannes Berg86e8cf92013-06-19 10:57:22 +02001528 if (state->chan_start)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001529 band--;
1530 break;
1531 }
Johannes Bergee688b002008-01-24 19:38:39 +01001532 }
Johannes Berg3713b4e2013-02-14 16:19:38 +01001533 nla_nest_end(msg, nl_bands);
Johannes Bergee688b002008-01-24 19:38:39 +01001534
Johannes Berg57fbcce2016-04-12 15:56:15 +02001535 if (band < NUM_NL80211_BANDS)
Johannes Berg86e8cf92013-06-19 10:57:22 +02001536 state->band_start = band + 1;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001537 else
Johannes Berg86e8cf92013-06-19 10:57:22 +02001538 state->band_start = 0;
Johannes Bergee688b002008-01-24 19:38:39 +01001539
Johannes Berg3713b4e2013-02-14 16:19:38 +01001540 /* if bands & channels are done, continue outside */
Johannes Berg86e8cf92013-06-19 10:57:22 +02001541 if (state->band_start == 0 && state->chan_start == 0)
1542 state->split_start++;
1543 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001544 break;
1545 case 4:
1546 nl_cmds = nla_nest_start(msg, NL80211_ATTR_SUPPORTED_COMMANDS);
1547 if (!nl_cmds)
David S. Miller9360ffd2012-03-29 04:41:26 -04001548 goto nla_put_failure;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001549
1550 i = 0;
1551#define CMD(op, n) \
1552 do { \
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001553 if (rdev->ops->op) { \
Johannes Berg3713b4e2013-02-14 16:19:38 +01001554 i++; \
1555 if (nla_put_u32(msg, i, NL80211_CMD_ ## n)) \
1556 goto nla_put_failure; \
1557 } \
1558 } while (0)
1559
1560 CMD(add_virtual_intf, NEW_INTERFACE);
1561 CMD(change_virtual_intf, SET_INTERFACE);
1562 CMD(add_key, NEW_KEY);
1563 CMD(start_ap, START_AP);
1564 CMD(add_station, NEW_STATION);
1565 CMD(add_mpath, NEW_MPATH);
1566 CMD(update_mesh_config, SET_MESH_CONFIG);
1567 CMD(change_bss, SET_BSS);
1568 CMD(auth, AUTHENTICATE);
1569 CMD(assoc, ASSOCIATE);
1570 CMD(deauth, DEAUTHENTICATE);
1571 CMD(disassoc, DISASSOCIATE);
1572 CMD(join_ibss, JOIN_IBSS);
1573 CMD(join_mesh, JOIN_MESH);
1574 CMD(set_pmksa, SET_PMKSA);
1575 CMD(del_pmksa, DEL_PMKSA);
1576 CMD(flush_pmksa, FLUSH_PMKSA);
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001577 if (rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001578 CMD(remain_on_channel, REMAIN_ON_CHANNEL);
1579 CMD(set_bitrate_mask, SET_TX_BITRATE_MASK);
1580 CMD(mgmt_tx, FRAME);
1581 CMD(mgmt_tx_cancel_wait, FRAME_WAIT_CANCEL);
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001582 if (rdev->wiphy.flags & WIPHY_FLAG_NETNS_OK) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001583 i++;
1584 if (nla_put_u32(msg, i, NL80211_CMD_SET_WIPHY_NETNS))
1585 goto nla_put_failure;
1586 }
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001587 if (rdev->ops->set_monitor_channel || rdev->ops->start_ap ||
1588 rdev->ops->join_mesh) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001589 i++;
1590 if (nla_put_u32(msg, i, NL80211_CMD_SET_CHANNEL))
1591 goto nla_put_failure;
1592 }
1593 CMD(set_wds_peer, SET_WDS_PEER);
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001594 if (rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001595 CMD(tdls_mgmt, TDLS_MGMT);
1596 CMD(tdls_oper, TDLS_OPER);
1597 }
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001598 if (rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001599 CMD(sched_scan_start, START_SCHED_SCAN);
1600 CMD(probe_client, PROBE_CLIENT);
1601 CMD(set_noack_map, SET_NOACK_MAP);
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001602 if (rdev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001603 i++;
1604 if (nla_put_u32(msg, i, NL80211_CMD_REGISTER_BEACONS))
1605 goto nla_put_failure;
1606 }
1607 CMD(start_p2p_device, START_P2P_DEVICE);
1608 CMD(set_mcast_rate, SET_MCAST_RATE);
Johannes Berg02df00e2014-06-10 14:06:25 +02001609#ifdef CONFIG_NL80211_TESTMODE
1610 CMD(testmode_cmd, TESTMODE);
1611#endif
Johannes Berg86e8cf92013-06-19 10:57:22 +02001612 if (state->split) {
Arend van Spriel5de17982013-04-18 15:49:00 +02001613 CMD(crit_proto_start, CRIT_PROTOCOL_START);
1614 CMD(crit_proto_stop, CRIT_PROTOCOL_STOP);
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001615 if (rdev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH)
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02001616 CMD(channel_switch, CHANNEL_SWITCH);
Johannes Berg02df00e2014-06-10 14:06:25 +02001617 CMD(set_qos_map, SET_QOS_MAP);
Johannes Berg723e73a2014-10-22 09:25:06 +02001618 if (rdev->wiphy.features &
1619 NL80211_FEATURE_SUPPORTS_WMM_ADMISSION)
Johannes Berg960d01a2014-09-09 22:55:35 +03001620 CMD(add_tx_ts, ADD_TX_TS);
Arend van Spriel5de17982013-04-18 15:49:00 +02001621 }
Johannes Berg02df00e2014-06-10 14:06:25 +02001622 /* add into the if now */
Johannes Berg8fdc6212009-03-14 09:34:01 +01001623#undef CMD
Samuel Ortizb23aa672009-07-01 21:26:54 +02001624
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001625 if (rdev->ops->connect || rdev->ops->auth) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001626 i++;
1627 if (nla_put_u32(msg, i, NL80211_CMD_CONNECT))
Johannes Berg2e161f782010-08-12 15:38:38 +02001628 goto nla_put_failure;
Johannes Berg2e161f782010-08-12 15:38:38 +02001629 }
1630
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001631 if (rdev->ops->disconnect || rdev->ops->deauth) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001632 i++;
1633 if (nla_put_u32(msg, i, NL80211_CMD_DISCONNECT))
1634 goto nla_put_failure;
1635 }
Johannes Berg74b70a42010-08-24 12:15:53 +02001636
Johannes Berg3713b4e2013-02-14 16:19:38 +01001637 nla_nest_end(msg, nl_cmds);
Johannes Berg86e8cf92013-06-19 10:57:22 +02001638 state->split_start++;
1639 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001640 break;
1641 case 5:
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001642 if (rdev->ops->remain_on_channel &&
1643 (rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001644 nla_put_u32(msg,
1645 NL80211_ATTR_MAX_REMAIN_ON_CHANNEL_DURATION,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001646 rdev->wiphy.max_remain_on_channel_duration))
Johannes Berg2e161f782010-08-12 15:38:38 +02001647 goto nla_put_failure;
1648
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001649 if ((rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001650 nla_put_flag(msg, NL80211_ATTR_OFFCHANNEL_TX_OK))
1651 goto nla_put_failure;
Johannes Berg2e161f782010-08-12 15:38:38 +02001652
Johannes Berg3713b4e2013-02-14 16:19:38 +01001653 if (nl80211_send_mgmt_stypes(msg, mgmt_stypes))
1654 goto nla_put_failure;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001655 state->split_start++;
1656 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001657 break;
1658 case 6:
Johannes Bergdfb89c52012-06-27 09:23:48 +02001659#ifdef CONFIG_PM
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001660 if (nl80211_send_wowlan(msg, rdev, state->split))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001661 goto nla_put_failure;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001662 state->split_start++;
1663 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001664 break;
1665#else
Johannes Berg86e8cf92013-06-19 10:57:22 +02001666 state->split_start++;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001667#endif
1668 case 7:
1669 if (nl80211_put_iftypes(msg, NL80211_ATTR_SOFTWARE_IFTYPES,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001670 rdev->wiphy.software_iftypes))
Johannes Bergff1b6e62011-05-04 15:37:28 +02001671 goto nla_put_failure;
1672
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001673 if (nl80211_put_iface_combinations(&rdev->wiphy, msg,
Johannes Berg86e8cf92013-06-19 10:57:22 +02001674 state->split))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001675 goto nla_put_failure;
Johannes Bergff1b6e62011-05-04 15:37:28 +02001676
Johannes Berg86e8cf92013-06-19 10:57:22 +02001677 state->split_start++;
1678 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001679 break;
1680 case 8:
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001681 if ((rdev->wiphy.flags & WIPHY_FLAG_HAVE_AP_SME) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001682 nla_put_u32(msg, NL80211_ATTR_DEVICE_AP_SME,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001683 rdev->wiphy.ap_sme_capa))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001684 goto nla_put_failure;
1685
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001686 features = rdev->wiphy.features;
Johannes Bergfe1abaf2013-02-27 15:39:45 +01001687 /*
1688 * We can only add the per-channel limit information if the
1689 * dump is split, otherwise it makes it too big. Therefore
1690 * only advertise it in that case.
1691 */
Johannes Berg86e8cf92013-06-19 10:57:22 +02001692 if (state->split)
Johannes Bergfe1abaf2013-02-27 15:39:45 +01001693 features |= NL80211_FEATURE_ADVERTISE_CHAN_LIMITS;
1694 if (nla_put_u32(msg, NL80211_ATTR_FEATURE_FLAGS, features))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001695 goto nla_put_failure;
1696
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001697 if (rdev->wiphy.ht_capa_mod_mask &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001698 nla_put(msg, NL80211_ATTR_HT_CAPABILITY_MASK,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001699 sizeof(*rdev->wiphy.ht_capa_mod_mask),
1700 rdev->wiphy.ht_capa_mod_mask))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001701 goto nla_put_failure;
1702
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001703 if (rdev->wiphy.flags & WIPHY_FLAG_HAVE_AP_SME &&
1704 rdev->wiphy.max_acl_mac_addrs &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001705 nla_put_u32(msg, NL80211_ATTR_MAC_ACL_MAX,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001706 rdev->wiphy.max_acl_mac_addrs))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001707 goto nla_put_failure;
1708
1709 /*
1710 * Any information below this point is only available to
1711 * applications that can deal with it being split. This
1712 * helps ensure that newly added capabilities don't break
1713 * older tools by overrunning their buffers.
1714 *
1715 * We still increment split_start so that in the split
1716 * case we'll continue with more data in the next round,
1717 * but break unconditionally so unsplit data stops here.
1718 */
Johannes Berg86e8cf92013-06-19 10:57:22 +02001719 state->split_start++;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001720 break;
1721 case 9:
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001722 if (rdev->wiphy.extended_capabilities &&
Johannes Bergfe1abaf2013-02-27 15:39:45 +01001723 (nla_put(msg, NL80211_ATTR_EXT_CAPA,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001724 rdev->wiphy.extended_capabilities_len,
1725 rdev->wiphy.extended_capabilities) ||
Johannes Bergfe1abaf2013-02-27 15:39:45 +01001726 nla_put(msg, NL80211_ATTR_EXT_CAPA_MASK,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001727 rdev->wiphy.extended_capabilities_len,
1728 rdev->wiphy.extended_capabilities_mask)))
Johannes Bergfe1abaf2013-02-27 15:39:45 +01001729 goto nla_put_failure;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001730
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001731 if (rdev->wiphy.vht_capa_mod_mask &&
Johannes Bergee2aca32013-02-21 17:36:01 +01001732 nla_put(msg, NL80211_ATTR_VHT_CAPABILITY_MASK,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001733 sizeof(*rdev->wiphy.vht_capa_mod_mask),
1734 rdev->wiphy.vht_capa_mod_mask))
Johannes Bergee2aca32013-02-21 17:36:01 +01001735 goto nla_put_failure;
1736
Amitkumar Karwarbe29b99a2013-06-28 11:51:26 -07001737 state->split_start++;
1738 break;
1739 case 10:
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001740 if (nl80211_send_coalesce(msg, rdev))
Amitkumar Karwarbe29b99a2013-06-28 11:51:26 -07001741 goto nla_put_failure;
1742
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001743 if ((rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_5_10_MHZ) &&
Felix Fietkau01e0daa2013-11-09 14:57:54 +01001744 (nla_put_flag(msg, NL80211_ATTR_SUPPORT_5_MHZ) ||
1745 nla_put_flag(msg, NL80211_ATTR_SUPPORT_10_MHZ)))
1746 goto nla_put_failure;
Jouni Malinenb43504c2014-01-15 00:01:08 +02001747
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001748 if (rdev->wiphy.max_ap_assoc_sta &&
Jouni Malinenb43504c2014-01-15 00:01:08 +02001749 nla_put_u32(msg, NL80211_ATTR_MAX_AP_ASSOC_STA,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001750 rdev->wiphy.max_ap_assoc_sta))
Jouni Malinenb43504c2014-01-15 00:01:08 +02001751 goto nla_put_failure;
1752
Johannes Bergad7e7182013-11-13 13:37:47 +01001753 state->split_start++;
1754 break;
1755 case 11:
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001756 if (rdev->wiphy.n_vendor_commands) {
Johannes Berg567ffc32013-12-18 14:43:31 +01001757 const struct nl80211_vendor_cmd_info *info;
1758 struct nlattr *nested;
Johannes Bergad7e7182013-11-13 13:37:47 +01001759
Johannes Berg567ffc32013-12-18 14:43:31 +01001760 nested = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA);
1761 if (!nested)
Johannes Bergad7e7182013-11-13 13:37:47 +01001762 goto nla_put_failure;
Johannes Berg567ffc32013-12-18 14:43:31 +01001763
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001764 for (i = 0; i < rdev->wiphy.n_vendor_commands; i++) {
1765 info = &rdev->wiphy.vendor_commands[i].info;
Johannes Berg567ffc32013-12-18 14:43:31 +01001766 if (nla_put(msg, i + 1, sizeof(*info), info))
1767 goto nla_put_failure;
1768 }
1769 nla_nest_end(msg, nested);
1770 }
1771
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001772 if (rdev->wiphy.n_vendor_events) {
Johannes Berg567ffc32013-12-18 14:43:31 +01001773 const struct nl80211_vendor_cmd_info *info;
1774 struct nlattr *nested;
1775
1776 nested = nla_nest_start(msg,
1777 NL80211_ATTR_VENDOR_EVENTS);
1778 if (!nested)
1779 goto nla_put_failure;
1780
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001781 for (i = 0; i < rdev->wiphy.n_vendor_events; i++) {
1782 info = &rdev->wiphy.vendor_events[i];
Johannes Berg567ffc32013-12-18 14:43:31 +01001783 if (nla_put(msg, i + 1, sizeof(*info), info))
1784 goto nla_put_failure;
1785 }
1786 nla_nest_end(msg, nested);
1787 }
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03001788 state->split_start++;
1789 break;
1790 case 12:
1791 if (rdev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH &&
1792 nla_put_u8(msg, NL80211_ATTR_MAX_CSA_COUNTERS,
1793 rdev->wiphy.max_num_csa_counters))
1794 goto nla_put_failure;
Felix Fietkau01e0daa2013-11-09 14:57:54 +01001795
Arik Nemtsov1bdd7162014-12-15 19:26:01 +02001796 if (rdev->wiphy.regulatory_flags & REGULATORY_WIPHY_SELF_MANAGED &&
1797 nla_put_flag(msg, NL80211_ATTR_WIPHY_SELF_MANAGED_REG))
1798 goto nla_put_failure;
1799
Gautam Kumar Shuklad75bb062014-12-23 16:55:19 +01001800 if (nla_put(msg, NL80211_ATTR_EXT_FEATURES,
1801 sizeof(rdev->wiphy.ext_features),
1802 rdev->wiphy.ext_features))
1803 goto nla_put_failure;
1804
Arend van Spriel38de03d2016-03-02 20:37:18 +01001805 if (rdev->wiphy.bss_select_support) {
1806 struct nlattr *nested;
1807 u32 bss_select_support = rdev->wiphy.bss_select_support;
1808
1809 nested = nla_nest_start(msg, NL80211_ATTR_BSS_SELECT);
1810 if (!nested)
1811 goto nla_put_failure;
1812
1813 i = 0;
1814 while (bss_select_support) {
1815 if ((bss_select_support & 1) &&
1816 nla_put_flag(msg, i))
1817 goto nla_put_failure;
1818 i++;
1819 bss_select_support >>= 1;
1820 }
1821 nla_nest_end(msg, nested);
1822 }
1823
Kanchanapally, Vidyullatha019ae3a2016-05-16 10:41:04 +05301824 state->split_start++;
1825 break;
1826 case 13:
1827 if (rdev->wiphy.num_iftype_ext_capab &&
1828 rdev->wiphy.iftype_ext_capab) {
1829 struct nlattr *nested_ext_capab, *nested;
1830
1831 nested = nla_nest_start(msg,
1832 NL80211_ATTR_IFTYPE_EXT_CAPA);
1833 if (!nested)
1834 goto nla_put_failure;
1835
1836 for (i = state->capa_start;
1837 i < rdev->wiphy.num_iftype_ext_capab; i++) {
1838 const struct wiphy_iftype_ext_capab *capab;
1839
1840 capab = &rdev->wiphy.iftype_ext_capab[i];
1841
1842 nested_ext_capab = nla_nest_start(msg, i);
1843 if (!nested_ext_capab ||
1844 nla_put_u32(msg, NL80211_ATTR_IFTYPE,
1845 capab->iftype) ||
1846 nla_put(msg, NL80211_ATTR_EXT_CAPA,
1847 capab->extended_capabilities_len,
1848 capab->extended_capabilities) ||
1849 nla_put(msg, NL80211_ATTR_EXT_CAPA_MASK,
1850 capab->extended_capabilities_len,
1851 capab->extended_capabilities_mask))
1852 goto nla_put_failure;
1853
1854 nla_nest_end(msg, nested_ext_capab);
1855 if (state->split)
1856 break;
1857 }
1858 nla_nest_end(msg, nested);
1859 if (i < rdev->wiphy.num_iftype_ext_capab) {
1860 state->capa_start = i + 1;
1861 break;
1862 }
1863 }
1864
Johannes Berg3713b4e2013-02-14 16:19:38 +01001865 /* done */
Johannes Berg86e8cf92013-06-19 10:57:22 +02001866 state->split_start = 0;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001867 break;
Johannes Bergff1b6e62011-05-04 15:37:28 +02001868 }
Johannes Berg3bb20552014-05-26 13:52:25 +02001869 finish:
Johannes Berg053c0952015-01-16 22:09:00 +01001870 genlmsg_end(msg, hdr);
1871 return 0;
Johannes Berg55682962007-09-20 13:09:35 -04001872
1873 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07001874 genlmsg_cancel(msg, hdr);
1875 return -EMSGSIZE;
Johannes Berg55682962007-09-20 13:09:35 -04001876}
1877
Johannes Berg86e8cf92013-06-19 10:57:22 +02001878static int nl80211_dump_wiphy_parse(struct sk_buff *skb,
1879 struct netlink_callback *cb,
1880 struct nl80211_dump_wiphy_state *state)
1881{
1882 struct nlattr **tb = nl80211_fam.attrbuf;
1883 int ret = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize,
1884 tb, nl80211_fam.maxattr, nl80211_policy);
1885 /* ignore parse errors for backward compatibility */
1886 if (ret)
1887 return 0;
1888
1889 state->split = tb[NL80211_ATTR_SPLIT_WIPHY_DUMP];
1890 if (tb[NL80211_ATTR_WIPHY])
1891 state->filter_wiphy = nla_get_u32(tb[NL80211_ATTR_WIPHY]);
1892 if (tb[NL80211_ATTR_WDEV])
1893 state->filter_wiphy = nla_get_u64(tb[NL80211_ATTR_WDEV]) >> 32;
1894 if (tb[NL80211_ATTR_IFINDEX]) {
1895 struct net_device *netdev;
1896 struct cfg80211_registered_device *rdev;
1897 int ifidx = nla_get_u32(tb[NL80211_ATTR_IFINDEX]);
1898
Ying Xue7f2b8562014-01-15 10:23:45 +08001899 netdev = __dev_get_by_index(sock_net(skb->sk), ifidx);
Johannes Berg86e8cf92013-06-19 10:57:22 +02001900 if (!netdev)
1901 return -ENODEV;
1902 if (netdev->ieee80211_ptr) {
Zhao, Gangf26cbf42014-04-21 12:53:03 +08001903 rdev = wiphy_to_rdev(
Johannes Berg86e8cf92013-06-19 10:57:22 +02001904 netdev->ieee80211_ptr->wiphy);
1905 state->filter_wiphy = rdev->wiphy_idx;
1906 }
Johannes Berg86e8cf92013-06-19 10:57:22 +02001907 }
1908
1909 return 0;
1910}
1911
Johannes Berg55682962007-09-20 13:09:35 -04001912static int nl80211_dump_wiphy(struct sk_buff *skb, struct netlink_callback *cb)
1913{
Johannes Berg645e77d2013-03-01 14:03:49 +01001914 int idx = 0, ret;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001915 struct nl80211_dump_wiphy_state *state = (void *)cb->args[0];
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001916 struct cfg80211_registered_device *rdev;
Johannes Berg3a5a4232013-06-19 10:09:57 +02001917
Johannes Berg5fe231e2013-05-08 21:45:15 +02001918 rtnl_lock();
Johannes Berg86e8cf92013-06-19 10:57:22 +02001919 if (!state) {
1920 state = kzalloc(sizeof(*state), GFP_KERNEL);
John W. Linville57ed5cd2013-06-28 13:18:21 -04001921 if (!state) {
1922 rtnl_unlock();
Johannes Berg86e8cf92013-06-19 10:57:22 +02001923 return -ENOMEM;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001924 }
Johannes Berg86e8cf92013-06-19 10:57:22 +02001925 state->filter_wiphy = -1;
1926 ret = nl80211_dump_wiphy_parse(skb, cb, state);
1927 if (ret) {
1928 kfree(state);
1929 rtnl_unlock();
1930 return ret;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001931 }
Johannes Berg86e8cf92013-06-19 10:57:22 +02001932 cb->args[0] = (long)state;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001933 }
1934
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001935 list_for_each_entry(rdev, &cfg80211_rdev_list, list) {
1936 if (!net_eq(wiphy_net(&rdev->wiphy), sock_net(skb->sk)))
Johannes Berg463d0182009-07-14 00:33:35 +02001937 continue;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001938 if (++idx <= state->start)
Johannes Berg55682962007-09-20 13:09:35 -04001939 continue;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001940 if (state->filter_wiphy != -1 &&
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001941 state->filter_wiphy != rdev->wiphy_idx)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001942 continue;
1943 /* attempt to fit multiple wiphy data chunks into the skb */
1944 do {
Johannes Berg3bb20552014-05-26 13:52:25 +02001945 ret = nl80211_send_wiphy(rdev, NL80211_CMD_NEW_WIPHY,
1946 skb,
Johannes Berg3713b4e2013-02-14 16:19:38 +01001947 NETLINK_CB(cb->skb).portid,
1948 cb->nlh->nlmsg_seq,
Johannes Berg86e8cf92013-06-19 10:57:22 +02001949 NLM_F_MULTI, state);
Johannes Berg3713b4e2013-02-14 16:19:38 +01001950 if (ret < 0) {
1951 /*
1952 * If sending the wiphy data didn't fit (ENOBUFS
1953 * or EMSGSIZE returned), this SKB is still
1954 * empty (so it's not too big because another
1955 * wiphy dataset is already in the skb) and
1956 * we've not tried to adjust the dump allocation
1957 * yet ... then adjust the alloc size to be
1958 * bigger, and return 1 but with the empty skb.
1959 * This results in an empty message being RX'ed
1960 * in userspace, but that is ignored.
1961 *
1962 * We can then retry with the larger buffer.
1963 */
1964 if ((ret == -ENOBUFS || ret == -EMSGSIZE) &&
Pontus Fuchsf12cb282014-01-16 15:00:40 +01001965 !skb->len && !state->split &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001966 cb->min_dump_alloc < 4096) {
1967 cb->min_dump_alloc = 4096;
Pontus Fuchsf12cb282014-01-16 15:00:40 +01001968 state->split_start = 0;
David S. Millerd98cae64e2013-06-19 16:49:39 -07001969 rtnl_unlock();
Johannes Berg3713b4e2013-02-14 16:19:38 +01001970 return 1;
1971 }
1972 idx--;
1973 break;
Johannes Berg645e77d2013-03-01 14:03:49 +01001974 }
Johannes Berg86e8cf92013-06-19 10:57:22 +02001975 } while (state->split_start > 0);
Johannes Berg3713b4e2013-02-14 16:19:38 +01001976 break;
Johannes Berg55682962007-09-20 13:09:35 -04001977 }
Johannes Berg5fe231e2013-05-08 21:45:15 +02001978 rtnl_unlock();
Johannes Berg55682962007-09-20 13:09:35 -04001979
Johannes Berg86e8cf92013-06-19 10:57:22 +02001980 state->start = idx;
Johannes Berg55682962007-09-20 13:09:35 -04001981
1982 return skb->len;
1983}
1984
Johannes Berg86e8cf92013-06-19 10:57:22 +02001985static int nl80211_dump_wiphy_done(struct netlink_callback *cb)
1986{
1987 kfree((void *)cb->args[0]);
1988 return 0;
1989}
1990
Johannes Berg55682962007-09-20 13:09:35 -04001991static int nl80211_get_wiphy(struct sk_buff *skb, struct genl_info *info)
1992{
1993 struct sk_buff *msg;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001994 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg86e8cf92013-06-19 10:57:22 +02001995 struct nl80211_dump_wiphy_state state = {};
Johannes Berg55682962007-09-20 13:09:35 -04001996
Johannes Berg645e77d2013-03-01 14:03:49 +01001997 msg = nlmsg_new(4096, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -04001998 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02001999 return -ENOMEM;
Johannes Berg55682962007-09-20 13:09:35 -04002000
Johannes Berg3bb20552014-05-26 13:52:25 +02002001 if (nl80211_send_wiphy(rdev, NL80211_CMD_NEW_WIPHY, msg,
2002 info->snd_portid, info->snd_seq, 0,
Johannes Berg86e8cf92013-06-19 10:57:22 +02002003 &state) < 0) {
Johannes Berg4c476992010-10-04 21:36:35 +02002004 nlmsg_free(msg);
2005 return -ENOBUFS;
2006 }
Johannes Berg55682962007-09-20 13:09:35 -04002007
Johannes Berg134e6372009-07-10 09:51:34 +00002008 return genlmsg_reply(msg, info);
Johannes Berg55682962007-09-20 13:09:35 -04002009}
2010
Jouni Malinen31888482008-10-30 16:59:24 +02002011static const struct nla_policy txq_params_policy[NL80211_TXQ_ATTR_MAX + 1] = {
2012 [NL80211_TXQ_ATTR_QUEUE] = { .type = NLA_U8 },
2013 [NL80211_TXQ_ATTR_TXOP] = { .type = NLA_U16 },
2014 [NL80211_TXQ_ATTR_CWMIN] = { .type = NLA_U16 },
2015 [NL80211_TXQ_ATTR_CWMAX] = { .type = NLA_U16 },
2016 [NL80211_TXQ_ATTR_AIFS] = { .type = NLA_U8 },
2017};
2018
2019static int parse_txq_params(struct nlattr *tb[],
2020 struct ieee80211_txq_params *txq_params)
2021{
Johannes Berga3304b02012-03-28 11:04:24 +02002022 if (!tb[NL80211_TXQ_ATTR_AC] || !tb[NL80211_TXQ_ATTR_TXOP] ||
Jouni Malinen31888482008-10-30 16:59:24 +02002023 !tb[NL80211_TXQ_ATTR_CWMIN] || !tb[NL80211_TXQ_ATTR_CWMAX] ||
2024 !tb[NL80211_TXQ_ATTR_AIFS])
2025 return -EINVAL;
2026
Johannes Berga3304b02012-03-28 11:04:24 +02002027 txq_params->ac = nla_get_u8(tb[NL80211_TXQ_ATTR_AC]);
Jouni Malinen31888482008-10-30 16:59:24 +02002028 txq_params->txop = nla_get_u16(tb[NL80211_TXQ_ATTR_TXOP]);
2029 txq_params->cwmin = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMIN]);
2030 txq_params->cwmax = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMAX]);
2031 txq_params->aifs = nla_get_u8(tb[NL80211_TXQ_ATTR_AIFS]);
2032
Johannes Berga3304b02012-03-28 11:04:24 +02002033 if (txq_params->ac >= NL80211_NUM_ACS)
2034 return -EINVAL;
2035
Jouni Malinen31888482008-10-30 16:59:24 +02002036 return 0;
2037}
2038
Johannes Bergf444de02010-05-05 15:25:02 +02002039static bool nl80211_can_set_dev_channel(struct wireless_dev *wdev)
2040{
2041 /*
Johannes Bergcc1d2802012-05-16 23:50:20 +02002042 * You can only set the channel explicitly for WDS interfaces,
2043 * all others have their channel managed via their respective
2044 * "establish a connection" command (connect, join, ...)
2045 *
2046 * For AP/GO and mesh mode, the channel can be set with the
2047 * channel userspace API, but is only stored and passed to the
2048 * low-level driver when the AP starts or the mesh is joined.
2049 * This is for backward compatibility, userspace can also give
2050 * the channel in the start-ap or join-mesh commands instead.
Johannes Bergf444de02010-05-05 15:25:02 +02002051 *
2052 * Monitors are special as they are normally slaved to
Johannes Berge8c9bd52012-06-06 08:18:22 +02002053 * whatever else is going on, so they have their own special
2054 * operation to set the monitor channel if possible.
Johannes Bergf444de02010-05-05 15:25:02 +02002055 */
2056 return !wdev ||
2057 wdev->iftype == NL80211_IFTYPE_AP ||
Johannes Bergf444de02010-05-05 15:25:02 +02002058 wdev->iftype == NL80211_IFTYPE_MESH_POINT ||
Johannes Berg074ac8d2010-09-16 14:58:22 +02002059 wdev->iftype == NL80211_IFTYPE_MONITOR ||
2060 wdev->iftype == NL80211_IFTYPE_P2P_GO;
Johannes Bergf444de02010-05-05 15:25:02 +02002061}
2062
Johannes Berg683b6d32012-11-08 21:25:48 +01002063static int nl80211_parse_chandef(struct cfg80211_registered_device *rdev,
2064 struct genl_info *info,
2065 struct cfg80211_chan_def *chandef)
2066{
Mahesh Paliveladbeca2e2012-11-29 14:11:07 +05302067 u32 control_freq;
Johannes Berg683b6d32012-11-08 21:25:48 +01002068
2069 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ])
2070 return -EINVAL;
2071
2072 control_freq = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]);
2073
2074 chandef->chan = ieee80211_get_channel(&rdev->wiphy, control_freq);
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002075 chandef->width = NL80211_CHAN_WIDTH_20_NOHT;
2076 chandef->center_freq1 = control_freq;
2077 chandef->center_freq2 = 0;
Johannes Berg683b6d32012-11-08 21:25:48 +01002078
2079 /* Primary channel not allowed */
2080 if (!chandef->chan || chandef->chan->flags & IEEE80211_CHAN_DISABLED)
2081 return -EINVAL;
2082
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002083 if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]) {
2084 enum nl80211_channel_type chantype;
Johannes Berg683b6d32012-11-08 21:25:48 +01002085
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002086 chantype = nla_get_u32(
2087 info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]);
2088
2089 switch (chantype) {
2090 case NL80211_CHAN_NO_HT:
2091 case NL80211_CHAN_HT20:
2092 case NL80211_CHAN_HT40PLUS:
2093 case NL80211_CHAN_HT40MINUS:
2094 cfg80211_chandef_create(chandef, chandef->chan,
2095 chantype);
2096 break;
2097 default:
Johannes Berg683b6d32012-11-08 21:25:48 +01002098 return -EINVAL;
Johannes Berg683b6d32012-11-08 21:25:48 +01002099 }
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002100 } else if (info->attrs[NL80211_ATTR_CHANNEL_WIDTH]) {
2101 chandef->width =
2102 nla_get_u32(info->attrs[NL80211_ATTR_CHANNEL_WIDTH]);
2103 if (info->attrs[NL80211_ATTR_CENTER_FREQ1])
2104 chandef->center_freq1 =
2105 nla_get_u32(
2106 info->attrs[NL80211_ATTR_CENTER_FREQ1]);
2107 if (info->attrs[NL80211_ATTR_CENTER_FREQ2])
2108 chandef->center_freq2 =
2109 nla_get_u32(
2110 info->attrs[NL80211_ATTR_CENTER_FREQ2]);
2111 }
2112
Johannes Berg9f5e8f62012-11-22 16:59:45 +01002113 if (!cfg80211_chandef_valid(chandef))
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002114 return -EINVAL;
2115
Johannes Berg9f5e8f62012-11-22 16:59:45 +01002116 if (!cfg80211_chandef_usable(&rdev->wiphy, chandef,
2117 IEEE80211_CHAN_DISABLED))
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002118 return -EINVAL;
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002119
Simon Wunderlich2f301ab2013-05-16 13:00:28 +02002120 if ((chandef->width == NL80211_CHAN_WIDTH_5 ||
2121 chandef->width == NL80211_CHAN_WIDTH_10) &&
2122 !(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_5_10_MHZ))
2123 return -EINVAL;
2124
Johannes Berg683b6d32012-11-08 21:25:48 +01002125 return 0;
2126}
2127
Johannes Bergf444de02010-05-05 15:25:02 +02002128static int __nl80211_set_channel(struct cfg80211_registered_device *rdev,
Jouni Malinene16821b2014-04-28 11:22:08 +03002129 struct net_device *dev,
Johannes Bergf444de02010-05-05 15:25:02 +02002130 struct genl_info *info)
2131{
Johannes Berg683b6d32012-11-08 21:25:48 +01002132 struct cfg80211_chan_def chandef;
Johannes Bergf444de02010-05-05 15:25:02 +02002133 int result;
Johannes Berge8c9bd52012-06-06 08:18:22 +02002134 enum nl80211_iftype iftype = NL80211_IFTYPE_MONITOR;
Jouni Malinene16821b2014-04-28 11:22:08 +03002135 struct wireless_dev *wdev = NULL;
Johannes Berge8c9bd52012-06-06 08:18:22 +02002136
Jouni Malinene16821b2014-04-28 11:22:08 +03002137 if (dev)
2138 wdev = dev->ieee80211_ptr;
Johannes Bergf444de02010-05-05 15:25:02 +02002139 if (!nl80211_can_set_dev_channel(wdev))
2140 return -EOPNOTSUPP;
Jouni Malinene16821b2014-04-28 11:22:08 +03002141 if (wdev)
2142 iftype = wdev->iftype;
Johannes Bergf444de02010-05-05 15:25:02 +02002143
Johannes Berg683b6d32012-11-08 21:25:48 +01002144 result = nl80211_parse_chandef(rdev, info, &chandef);
2145 if (result)
2146 return result;
Johannes Bergf444de02010-05-05 15:25:02 +02002147
Johannes Berge8c9bd52012-06-06 08:18:22 +02002148 switch (iftype) {
Johannes Bergaa430da2012-05-16 23:50:18 +02002149 case NL80211_IFTYPE_AP:
2150 case NL80211_IFTYPE_P2P_GO:
Arik Nemtsov923b3522015-07-08 15:41:44 +03002151 if (!cfg80211_reg_can_beacon_relax(&rdev->wiphy, &chandef,
2152 iftype)) {
Johannes Bergaa430da2012-05-16 23:50:18 +02002153 result = -EINVAL;
2154 break;
2155 }
Jouni Malinene16821b2014-04-28 11:22:08 +03002156 if (wdev->beacon_interval) {
2157 if (!dev || !rdev->ops->set_ap_chanwidth ||
2158 !(rdev->wiphy.features &
2159 NL80211_FEATURE_AP_MODE_CHAN_WIDTH_CHANGE)) {
2160 result = -EBUSY;
2161 break;
2162 }
2163
2164 /* Only allow dynamic channel width changes */
2165 if (chandef.chan != wdev->preset_chandef.chan) {
2166 result = -EBUSY;
2167 break;
2168 }
2169 result = rdev_set_ap_chanwidth(rdev, dev, &chandef);
2170 if (result)
2171 break;
2172 }
Johannes Berg683b6d32012-11-08 21:25:48 +01002173 wdev->preset_chandef = chandef;
Johannes Bergaa430da2012-05-16 23:50:18 +02002174 result = 0;
2175 break;
Johannes Bergcc1d2802012-05-16 23:50:20 +02002176 case NL80211_IFTYPE_MESH_POINT:
Johannes Berg683b6d32012-11-08 21:25:48 +01002177 result = cfg80211_set_mesh_channel(rdev, wdev, &chandef);
Johannes Bergcc1d2802012-05-16 23:50:20 +02002178 break;
Johannes Berge8c9bd52012-06-06 08:18:22 +02002179 case NL80211_IFTYPE_MONITOR:
Johannes Berg683b6d32012-11-08 21:25:48 +01002180 result = cfg80211_set_monitor_channel(rdev, &chandef);
Johannes Berge8c9bd52012-06-06 08:18:22 +02002181 break;
Johannes Bergaa430da2012-05-16 23:50:18 +02002182 default:
Johannes Berge8c9bd52012-06-06 08:18:22 +02002183 result = -EINVAL;
Johannes Bergf444de02010-05-05 15:25:02 +02002184 }
Johannes Bergf444de02010-05-05 15:25:02 +02002185
2186 return result;
2187}
2188
2189static int nl80211_set_channel(struct sk_buff *skb, struct genl_info *info)
2190{
Johannes Berg4c476992010-10-04 21:36:35 +02002191 struct cfg80211_registered_device *rdev = info->user_ptr[0];
2192 struct net_device *netdev = info->user_ptr[1];
Johannes Bergf444de02010-05-05 15:25:02 +02002193
Jouni Malinene16821b2014-04-28 11:22:08 +03002194 return __nl80211_set_channel(rdev, netdev, info);
Johannes Bergf444de02010-05-05 15:25:02 +02002195}
2196
Bill Jordane8347eb2010-10-01 13:54:28 -04002197static int nl80211_set_wds_peer(struct sk_buff *skb, struct genl_info *info)
2198{
Johannes Berg43b19952010-10-07 13:10:30 +02002199 struct cfg80211_registered_device *rdev = info->user_ptr[0];
2200 struct net_device *dev = info->user_ptr[1];
2201 struct wireless_dev *wdev = dev->ieee80211_ptr;
Johannes Berg388ac772010-10-07 13:11:09 +02002202 const u8 *bssid;
Bill Jordane8347eb2010-10-01 13:54:28 -04002203
2204 if (!info->attrs[NL80211_ATTR_MAC])
2205 return -EINVAL;
2206
Johannes Berg43b19952010-10-07 13:10:30 +02002207 if (netif_running(dev))
2208 return -EBUSY;
Bill Jordane8347eb2010-10-01 13:54:28 -04002209
Johannes Berg43b19952010-10-07 13:10:30 +02002210 if (!rdev->ops->set_wds_peer)
2211 return -EOPNOTSUPP;
Bill Jordane8347eb2010-10-01 13:54:28 -04002212
Johannes Berg43b19952010-10-07 13:10:30 +02002213 if (wdev->iftype != NL80211_IFTYPE_WDS)
2214 return -EOPNOTSUPP;
Bill Jordane8347eb2010-10-01 13:54:28 -04002215
2216 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Hila Gonene35e4d22012-06-27 17:19:42 +03002217 return rdev_set_wds_peer(rdev, dev, bssid);
Bill Jordane8347eb2010-10-01 13:54:28 -04002218}
2219
Johannes Berg55682962007-09-20 13:09:35 -04002220static int nl80211_set_wiphy(struct sk_buff *skb, struct genl_info *info)
2221{
2222 struct cfg80211_registered_device *rdev;
Johannes Bergf444de02010-05-05 15:25:02 +02002223 struct net_device *netdev = NULL;
2224 struct wireless_dev *wdev;
Bill Jordana1e567c2010-09-10 11:22:32 -04002225 int result = 0, rem_txq_params = 0;
Jouni Malinen31888482008-10-30 16:59:24 +02002226 struct nlattr *nl_txq_params;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002227 u32 changed;
2228 u8 retry_short = 0, retry_long = 0;
2229 u32 frag_threshold = 0, rts_threshold = 0;
Lukáš Turek81077e82009-12-21 22:50:47 +01002230 u8 coverage_class = 0;
Johannes Berg55682962007-09-20 13:09:35 -04002231
Johannes Berg5fe231e2013-05-08 21:45:15 +02002232 ASSERT_RTNL();
2233
Johannes Bergf444de02010-05-05 15:25:02 +02002234 /*
2235 * Try to find the wiphy and netdev. Normally this
2236 * function shouldn't need the netdev, but this is
2237 * done for backward compatibility -- previously
2238 * setting the channel was done per wiphy, but now
2239 * it is per netdev. Previous userland like hostapd
2240 * also passed a netdev to set_wiphy, so that it is
2241 * possible to let that go to the right netdev!
2242 */
Johannes Berg4bbf4d52009-03-24 09:35:46 +01002243
Johannes Bergf444de02010-05-05 15:25:02 +02002244 if (info->attrs[NL80211_ATTR_IFINDEX]) {
2245 int ifindex = nla_get_u32(info->attrs[NL80211_ATTR_IFINDEX]);
2246
Ying Xue7f2b8562014-01-15 10:23:45 +08002247 netdev = __dev_get_by_index(genl_info_net(info), ifindex);
Johannes Berg5fe231e2013-05-08 21:45:15 +02002248 if (netdev && netdev->ieee80211_ptr)
Zhao, Gangf26cbf42014-04-21 12:53:03 +08002249 rdev = wiphy_to_rdev(netdev->ieee80211_ptr->wiphy);
Johannes Berg5fe231e2013-05-08 21:45:15 +02002250 else
Johannes Bergf444de02010-05-05 15:25:02 +02002251 netdev = NULL;
Johannes Berg4bbf4d52009-03-24 09:35:46 +01002252 }
2253
Johannes Bergf444de02010-05-05 15:25:02 +02002254 if (!netdev) {
Johannes Berg878d9ec2012-06-15 14:18:32 +02002255 rdev = __cfg80211_rdev_from_attrs(genl_info_net(info),
2256 info->attrs);
Johannes Berg5fe231e2013-05-08 21:45:15 +02002257 if (IS_ERR(rdev))
Johannes Berg4c476992010-10-04 21:36:35 +02002258 return PTR_ERR(rdev);
Johannes Bergf444de02010-05-05 15:25:02 +02002259 wdev = NULL;
2260 netdev = NULL;
2261 result = 0;
Johannes Berg71fe96b2012-10-24 10:04:58 +02002262 } else
Johannes Bergf444de02010-05-05 15:25:02 +02002263 wdev = netdev->ieee80211_ptr;
Johannes Bergf444de02010-05-05 15:25:02 +02002264
2265 /*
2266 * end workaround code, by now the rdev is available
2267 * and locked, and wdev may or may not be NULL.
2268 */
Johannes Berg4bbf4d52009-03-24 09:35:46 +01002269
2270 if (info->attrs[NL80211_ATTR_WIPHY_NAME])
Jouni Malinen31888482008-10-30 16:59:24 +02002271 result = cfg80211_dev_rename(
2272 rdev, nla_data(info->attrs[NL80211_ATTR_WIPHY_NAME]));
Johannes Berg4bbf4d52009-03-24 09:35:46 +01002273
Johannes Berg4bbf4d52009-03-24 09:35:46 +01002274 if (result)
Ying Xue7f2b8562014-01-15 10:23:45 +08002275 return result;
Johannes Berg55682962007-09-20 13:09:35 -04002276
Jouni Malinen31888482008-10-30 16:59:24 +02002277 if (info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS]) {
2278 struct ieee80211_txq_params txq_params;
2279 struct nlattr *tb[NL80211_TXQ_ATTR_MAX + 1];
2280
Ying Xue7f2b8562014-01-15 10:23:45 +08002281 if (!rdev->ops->set_txq_params)
2282 return -EOPNOTSUPP;
Jouni Malinen31888482008-10-30 16:59:24 +02002283
Ying Xue7f2b8562014-01-15 10:23:45 +08002284 if (!netdev)
2285 return -EINVAL;
Eliad Pellerf70f01c2011-09-25 20:06:53 +03002286
Johannes Berg133a3ff2011-11-03 14:50:13 +01002287 if (netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
Ying Xue7f2b8562014-01-15 10:23:45 +08002288 netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
2289 return -EINVAL;
Johannes Berg133a3ff2011-11-03 14:50:13 +01002290
Ying Xue7f2b8562014-01-15 10:23:45 +08002291 if (!netif_running(netdev))
2292 return -ENETDOWN;
Johannes Berg2b5f8b02012-04-02 10:51:55 +02002293
Jouni Malinen31888482008-10-30 16:59:24 +02002294 nla_for_each_nested(nl_txq_params,
2295 info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS],
2296 rem_txq_params) {
Johannes Bergae811e22014-01-24 10:17:47 +01002297 result = nla_parse(tb, NL80211_TXQ_ATTR_MAX,
2298 nla_data(nl_txq_params),
2299 nla_len(nl_txq_params),
2300 txq_params_policy);
2301 if (result)
2302 return result;
Jouni Malinen31888482008-10-30 16:59:24 +02002303 result = parse_txq_params(tb, &txq_params);
2304 if (result)
Ying Xue7f2b8562014-01-15 10:23:45 +08002305 return result;
Jouni Malinen31888482008-10-30 16:59:24 +02002306
Hila Gonene35e4d22012-06-27 17:19:42 +03002307 result = rdev_set_txq_params(rdev, netdev,
2308 &txq_params);
Jouni Malinen31888482008-10-30 16:59:24 +02002309 if (result)
Ying Xue7f2b8562014-01-15 10:23:45 +08002310 return result;
Jouni Malinen31888482008-10-30 16:59:24 +02002311 }
2312 }
2313
Jouni Malinen72bdcf32008-11-26 16:15:24 +02002314 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
Jouni Malinene16821b2014-04-28 11:22:08 +03002315 result = __nl80211_set_channel(
2316 rdev,
2317 nl80211_can_set_dev_channel(wdev) ? netdev : NULL,
2318 info);
Jouni Malinen72bdcf32008-11-26 16:15:24 +02002319 if (result)
Ying Xue7f2b8562014-01-15 10:23:45 +08002320 return result;
Jouni Malinen72bdcf32008-11-26 16:15:24 +02002321 }
2322
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03002323 if (info->attrs[NL80211_ATTR_WIPHY_TX_POWER_SETTING]) {
Johannes Bergc8442112012-10-24 10:17:18 +02002324 struct wireless_dev *txp_wdev = wdev;
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03002325 enum nl80211_tx_power_setting type;
2326 int idx, mbm = 0;
2327
Johannes Bergc8442112012-10-24 10:17:18 +02002328 if (!(rdev->wiphy.features & NL80211_FEATURE_VIF_TXPOWER))
2329 txp_wdev = NULL;
2330
Ying Xue7f2b8562014-01-15 10:23:45 +08002331 if (!rdev->ops->set_tx_power)
2332 return -EOPNOTSUPP;
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03002333
2334 idx = NL80211_ATTR_WIPHY_TX_POWER_SETTING;
2335 type = nla_get_u32(info->attrs[idx]);
2336
2337 if (!info->attrs[NL80211_ATTR_WIPHY_TX_POWER_LEVEL] &&
Ying Xue7f2b8562014-01-15 10:23:45 +08002338 (type != NL80211_TX_POWER_AUTOMATIC))
2339 return -EINVAL;
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03002340
2341 if (type != NL80211_TX_POWER_AUTOMATIC) {
2342 idx = NL80211_ATTR_WIPHY_TX_POWER_LEVEL;
2343 mbm = nla_get_u32(info->attrs[idx]);
2344 }
2345
Johannes Bergc8442112012-10-24 10:17:18 +02002346 result = rdev_set_tx_power(rdev, txp_wdev, type, mbm);
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03002347 if (result)
Ying Xue7f2b8562014-01-15 10:23:45 +08002348 return result;
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03002349 }
2350
Bruno Randolfafe0cbf2010-11-10 12:50:50 +09002351 if (info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX] &&
2352 info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]) {
2353 u32 tx_ant, rx_ant;
Kirtika Ruchandani7a087e72016-05-29 19:51:23 -07002354
Bruno Randolf7f531e02010-12-16 11:30:22 +09002355 if ((!rdev->wiphy.available_antennas_tx &&
2356 !rdev->wiphy.available_antennas_rx) ||
Ying Xue7f2b8562014-01-15 10:23:45 +08002357 !rdev->ops->set_antenna)
2358 return -EOPNOTSUPP;
Bruno Randolfafe0cbf2010-11-10 12:50:50 +09002359
2360 tx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX]);
2361 rx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]);
2362
Bruno Randolfa7ffac92010-12-08 13:59:24 +09002363 /* reject antenna configurations which don't match the
Bruno Randolf7f531e02010-12-16 11:30:22 +09002364 * available antenna masks, except for the "all" mask */
2365 if ((~tx_ant && (tx_ant & ~rdev->wiphy.available_antennas_tx)) ||
Ying Xue7f2b8562014-01-15 10:23:45 +08002366 (~rx_ant && (rx_ant & ~rdev->wiphy.available_antennas_rx)))
2367 return -EINVAL;
Bruno Randolfa7ffac92010-12-08 13:59:24 +09002368
Bruno Randolf7f531e02010-12-16 11:30:22 +09002369 tx_ant = tx_ant & rdev->wiphy.available_antennas_tx;
2370 rx_ant = rx_ant & rdev->wiphy.available_antennas_rx;
Bruno Randolfa7ffac92010-12-08 13:59:24 +09002371
Hila Gonene35e4d22012-06-27 17:19:42 +03002372 result = rdev_set_antenna(rdev, tx_ant, rx_ant);
Bruno Randolfafe0cbf2010-11-10 12:50:50 +09002373 if (result)
Ying Xue7f2b8562014-01-15 10:23:45 +08002374 return result;
Bruno Randolfafe0cbf2010-11-10 12:50:50 +09002375 }
2376
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002377 changed = 0;
2378
2379 if (info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]) {
2380 retry_short = nla_get_u8(
2381 info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]);
Ying Xue7f2b8562014-01-15 10:23:45 +08002382 if (retry_short == 0)
2383 return -EINVAL;
2384
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002385 changed |= WIPHY_PARAM_RETRY_SHORT;
2386 }
2387
2388 if (info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]) {
2389 retry_long = nla_get_u8(
2390 info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]);
Ying Xue7f2b8562014-01-15 10:23:45 +08002391 if (retry_long == 0)
2392 return -EINVAL;
2393
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002394 changed |= WIPHY_PARAM_RETRY_LONG;
2395 }
2396
2397 if (info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]) {
2398 frag_threshold = nla_get_u32(
2399 info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]);
Ying Xue7f2b8562014-01-15 10:23:45 +08002400 if (frag_threshold < 256)
2401 return -EINVAL;
2402
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002403 if (frag_threshold != (u32) -1) {
2404 /*
2405 * Fragments (apart from the last one) are required to
2406 * have even length. Make the fragmentation code
2407 * simpler by stripping LSB should someone try to use
2408 * odd threshold value.
2409 */
2410 frag_threshold &= ~0x1;
2411 }
2412 changed |= WIPHY_PARAM_FRAG_THRESHOLD;
2413 }
2414
2415 if (info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]) {
2416 rts_threshold = nla_get_u32(
2417 info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]);
2418 changed |= WIPHY_PARAM_RTS_THRESHOLD;
2419 }
2420
Lukáš Turek81077e82009-12-21 22:50:47 +01002421 if (info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]) {
Lorenzo Bianconi3057dbf2014-09-04 23:57:40 +02002422 if (info->attrs[NL80211_ATTR_WIPHY_DYN_ACK])
2423 return -EINVAL;
2424
Lukáš Turek81077e82009-12-21 22:50:47 +01002425 coverage_class = nla_get_u8(
2426 info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]);
2427 changed |= WIPHY_PARAM_COVERAGE_CLASS;
2428 }
2429
Lorenzo Bianconi3057dbf2014-09-04 23:57:40 +02002430 if (info->attrs[NL80211_ATTR_WIPHY_DYN_ACK]) {
2431 if (!(rdev->wiphy.features & NL80211_FEATURE_ACKTO_ESTIMATION))
2432 return -EOPNOTSUPP;
2433
2434 changed |= WIPHY_PARAM_DYN_ACK;
2435 }
2436
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002437 if (changed) {
2438 u8 old_retry_short, old_retry_long;
2439 u32 old_frag_threshold, old_rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01002440 u8 old_coverage_class;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002441
Ying Xue7f2b8562014-01-15 10:23:45 +08002442 if (!rdev->ops->set_wiphy_params)
2443 return -EOPNOTSUPP;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002444
2445 old_retry_short = rdev->wiphy.retry_short;
2446 old_retry_long = rdev->wiphy.retry_long;
2447 old_frag_threshold = rdev->wiphy.frag_threshold;
2448 old_rts_threshold = rdev->wiphy.rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01002449 old_coverage_class = rdev->wiphy.coverage_class;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002450
2451 if (changed & WIPHY_PARAM_RETRY_SHORT)
2452 rdev->wiphy.retry_short = retry_short;
2453 if (changed & WIPHY_PARAM_RETRY_LONG)
2454 rdev->wiphy.retry_long = retry_long;
2455 if (changed & WIPHY_PARAM_FRAG_THRESHOLD)
2456 rdev->wiphy.frag_threshold = frag_threshold;
2457 if (changed & WIPHY_PARAM_RTS_THRESHOLD)
2458 rdev->wiphy.rts_threshold = rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01002459 if (changed & WIPHY_PARAM_COVERAGE_CLASS)
2460 rdev->wiphy.coverage_class = coverage_class;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002461
Hila Gonene35e4d22012-06-27 17:19:42 +03002462 result = rdev_set_wiphy_params(rdev, changed);
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002463 if (result) {
2464 rdev->wiphy.retry_short = old_retry_short;
2465 rdev->wiphy.retry_long = old_retry_long;
2466 rdev->wiphy.frag_threshold = old_frag_threshold;
2467 rdev->wiphy.rts_threshold = old_rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01002468 rdev->wiphy.coverage_class = old_coverage_class;
Michal Kazior9189ee32015-08-03 10:55:24 +02002469 return result;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002470 }
2471 }
Ying Xue7f2b8562014-01-15 10:23:45 +08002472 return 0;
Johannes Berg55682962007-09-20 13:09:35 -04002473}
2474
Johannes Berg71bbc992012-06-15 15:30:18 +02002475static inline u64 wdev_id(struct wireless_dev *wdev)
2476{
2477 return (u64)wdev->identifier |
Zhao, Gangf26cbf42014-04-21 12:53:03 +08002478 ((u64)wiphy_to_rdev(wdev->wiphy)->wiphy_idx << 32);
Johannes Berg71bbc992012-06-15 15:30:18 +02002479}
Johannes Berg55682962007-09-20 13:09:35 -04002480
Johannes Berg683b6d32012-11-08 21:25:48 +01002481static int nl80211_send_chandef(struct sk_buff *msg,
Janusz Dziedzicd2859df2013-11-06 13:55:51 +01002482 const struct cfg80211_chan_def *chandef)
Johannes Berg683b6d32012-11-08 21:25:48 +01002483{
Johannes Berg601555c2014-11-27 17:26:56 +01002484 if (WARN_ON(!cfg80211_chandef_valid(chandef)))
2485 return -EINVAL;
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002486
Johannes Berg683b6d32012-11-08 21:25:48 +01002487 if (nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ,
2488 chandef->chan->center_freq))
2489 return -ENOBUFS;
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002490 switch (chandef->width) {
2491 case NL80211_CHAN_WIDTH_20_NOHT:
2492 case NL80211_CHAN_WIDTH_20:
2493 case NL80211_CHAN_WIDTH_40:
2494 if (nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE,
2495 cfg80211_get_chandef_type(chandef)))
2496 return -ENOBUFS;
2497 break;
2498 default:
2499 break;
2500 }
2501 if (nla_put_u32(msg, NL80211_ATTR_CHANNEL_WIDTH, chandef->width))
2502 return -ENOBUFS;
2503 if (nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ1, chandef->center_freq1))
2504 return -ENOBUFS;
2505 if (chandef->center_freq2 &&
2506 nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ2, chandef->center_freq2))
Johannes Berg683b6d32012-11-08 21:25:48 +01002507 return -ENOBUFS;
2508 return 0;
2509}
2510
Eric W. Biederman15e47302012-09-07 20:12:54 +00002511static int nl80211_send_iface(struct sk_buff *msg, u32 portid, u32 seq, int flags,
Johannes Bergd7264052009-04-19 16:23:20 +02002512 struct cfg80211_registered_device *rdev,
Tomasz Bursztyka8f894be2014-11-12 16:26:45 +02002513 struct wireless_dev *wdev, bool removal)
Johannes Berg55682962007-09-20 13:09:35 -04002514{
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002515 struct net_device *dev = wdev->netdev;
Tomasz Bursztyka8f894be2014-11-12 16:26:45 +02002516 u8 cmd = NL80211_CMD_NEW_INTERFACE;
Johannes Berg55682962007-09-20 13:09:35 -04002517 void *hdr;
2518
Tomasz Bursztyka8f894be2014-11-12 16:26:45 +02002519 if (removal)
2520 cmd = NL80211_CMD_DEL_INTERFACE;
2521
2522 hdr = nl80211hdr_put(msg, portid, seq, flags, cmd);
Johannes Berg55682962007-09-20 13:09:35 -04002523 if (!hdr)
2524 return -1;
2525
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002526 if (dev &&
2527 (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
Johannes Berg98104fde2012-06-16 00:19:54 +02002528 nla_put_string(msg, NL80211_ATTR_IFNAME, dev->name)))
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002529 goto nla_put_failure;
2530
2531 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
2532 nla_put_u32(msg, NL80211_ATTR_IFTYPE, wdev->iftype) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02002533 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
2534 NL80211_ATTR_PAD) ||
Johannes Berg98104fde2012-06-16 00:19:54 +02002535 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, wdev_address(wdev)) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04002536 nla_put_u32(msg, NL80211_ATTR_GENERATION,
2537 rdev->devlist_generation ^
2538 (cfg80211_rdev_list_generation << 2)))
2539 goto nla_put_failure;
Johannes Bergf5ea9122009-08-07 16:17:38 +02002540
Johannes Berg5b7ccaf2012-07-12 19:45:08 +02002541 if (rdev->ops->get_channel) {
Johannes Berg683b6d32012-11-08 21:25:48 +01002542 int ret;
2543 struct cfg80211_chan_def chandef;
Johannes Berg5b7ccaf2012-07-12 19:45:08 +02002544
Johannes Berg683b6d32012-11-08 21:25:48 +01002545 ret = rdev_get_channel(rdev, wdev, &chandef);
2546 if (ret == 0) {
2547 if (nl80211_send_chandef(msg, &chandef))
2548 goto nla_put_failure;
2549 }
Pontus Fuchsd91df0e2012-04-03 16:39:58 +02002550 }
2551
Rafał Miłeckid55d0d52015-08-31 22:59:38 +02002552 if (rdev->ops->get_tx_power) {
2553 int dbm, ret;
2554
2555 ret = rdev_get_tx_power(rdev, wdev, &dbm);
2556 if (ret == 0 &&
2557 nla_put_u32(msg, NL80211_ATTR_WIPHY_TX_POWER_LEVEL,
2558 DBM_TO_MBM(dbm)))
2559 goto nla_put_failure;
2560 }
2561
Antonio Quartullib84e7a02012-11-07 12:52:20 +01002562 if (wdev->ssid_len) {
2563 if (nla_put(msg, NL80211_ATTR_SSID, wdev->ssid_len, wdev->ssid))
2564 goto nla_put_failure;
2565 }
2566
Johannes Berg053c0952015-01-16 22:09:00 +01002567 genlmsg_end(msg, hdr);
2568 return 0;
Johannes Berg55682962007-09-20 13:09:35 -04002569
2570 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07002571 genlmsg_cancel(msg, hdr);
2572 return -EMSGSIZE;
Johannes Berg55682962007-09-20 13:09:35 -04002573}
2574
2575static int nl80211_dump_interface(struct sk_buff *skb, struct netlink_callback *cb)
2576{
2577 int wp_idx = 0;
2578 int if_idx = 0;
2579 int wp_start = cb->args[0];
2580 int if_start = cb->args[1];
Denis Kenziorb7fb44d2016-08-03 17:02:15 -05002581 int filter_wiphy = -1;
Johannes Bergf5ea9122009-08-07 16:17:38 +02002582 struct cfg80211_registered_device *rdev;
Johannes Berg55682962007-09-20 13:09:35 -04002583 struct wireless_dev *wdev;
2584
Johannes Berg5fe231e2013-05-08 21:45:15 +02002585 rtnl_lock();
Denis Kenziorb7fb44d2016-08-03 17:02:15 -05002586 if (!cb->args[2]) {
2587 struct nl80211_dump_wiphy_state state = {
2588 .filter_wiphy = -1,
2589 };
2590 int ret;
2591
2592 ret = nl80211_dump_wiphy_parse(skb, cb, &state);
2593 if (ret)
2594 return ret;
2595
2596 filter_wiphy = state.filter_wiphy;
2597
2598 /*
2599 * if filtering, set cb->args[2] to +1 since 0 is the default
2600 * value needed to determine that parsing is necessary.
2601 */
2602 if (filter_wiphy >= 0)
2603 cb->args[2] = filter_wiphy + 1;
2604 else
2605 cb->args[2] = -1;
2606 } else if (cb->args[2] > 0) {
2607 filter_wiphy = cb->args[2] - 1;
2608 }
2609
Johannes Bergf5ea9122009-08-07 16:17:38 +02002610 list_for_each_entry(rdev, &cfg80211_rdev_list, list) {
2611 if (!net_eq(wiphy_net(&rdev->wiphy), sock_net(skb->sk)))
Johannes Berg463d0182009-07-14 00:33:35 +02002612 continue;
Johannes Bergbba95fe2008-07-29 13:22:51 +02002613 if (wp_idx < wp_start) {
2614 wp_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04002615 continue;
Johannes Bergbba95fe2008-07-29 13:22:51 +02002616 }
Denis Kenziorb7fb44d2016-08-03 17:02:15 -05002617
2618 if (filter_wiphy >= 0 && filter_wiphy != rdev->wiphy_idx)
2619 continue;
2620
Johannes Berg55682962007-09-20 13:09:35 -04002621 if_idx = 0;
2622
Johannes Berg53873f12016-05-03 16:52:04 +03002623 list_for_each_entry(wdev, &rdev->wiphy.wdev_list, list) {
Johannes Bergbba95fe2008-07-29 13:22:51 +02002624 if (if_idx < if_start) {
2625 if_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04002626 continue;
Johannes Bergbba95fe2008-07-29 13:22:51 +02002627 }
Eric W. Biederman15e47302012-09-07 20:12:54 +00002628 if (nl80211_send_iface(skb, NETLINK_CB(cb->skb).portid,
Johannes Berg55682962007-09-20 13:09:35 -04002629 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Tomasz Bursztyka8f894be2014-11-12 16:26:45 +02002630 rdev, wdev, false) < 0) {
Johannes Bergbba95fe2008-07-29 13:22:51 +02002631 goto out;
2632 }
2633 if_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04002634 }
Johannes Bergbba95fe2008-07-29 13:22:51 +02002635
2636 wp_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04002637 }
Johannes Bergbba95fe2008-07-29 13:22:51 +02002638 out:
Johannes Berg5fe231e2013-05-08 21:45:15 +02002639 rtnl_unlock();
Johannes Berg55682962007-09-20 13:09:35 -04002640
2641 cb->args[0] = wp_idx;
2642 cb->args[1] = if_idx;
2643
2644 return skb->len;
2645}
2646
2647static int nl80211_get_interface(struct sk_buff *skb, struct genl_info *info)
2648{
2649 struct sk_buff *msg;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002650 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002651 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg55682962007-09-20 13:09:35 -04002652
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07002653 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -04002654 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02002655 return -ENOMEM;
Johannes Berg55682962007-09-20 13:09:35 -04002656
Eric W. Biederman15e47302012-09-07 20:12:54 +00002657 if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0,
Tomasz Bursztyka8f894be2014-11-12 16:26:45 +02002658 rdev, wdev, false) < 0) {
Johannes Berg4c476992010-10-04 21:36:35 +02002659 nlmsg_free(msg);
2660 return -ENOBUFS;
2661 }
Johannes Berg55682962007-09-20 13:09:35 -04002662
Johannes Berg134e6372009-07-10 09:51:34 +00002663 return genlmsg_reply(msg, info);
Johannes Berg55682962007-09-20 13:09:35 -04002664}
2665
Michael Wu66f7ac52008-01-31 19:48:22 +01002666static const struct nla_policy mntr_flags_policy[NL80211_MNTR_FLAG_MAX + 1] = {
2667 [NL80211_MNTR_FLAG_FCSFAIL] = { .type = NLA_FLAG },
2668 [NL80211_MNTR_FLAG_PLCPFAIL] = { .type = NLA_FLAG },
2669 [NL80211_MNTR_FLAG_CONTROL] = { .type = NLA_FLAG },
2670 [NL80211_MNTR_FLAG_OTHER_BSS] = { .type = NLA_FLAG },
2671 [NL80211_MNTR_FLAG_COOK_FRAMES] = { .type = NLA_FLAG },
Felix Fietkaue057d3c2013-05-28 13:01:52 +02002672 [NL80211_MNTR_FLAG_ACTIVE] = { .type = NLA_FLAG },
Michael Wu66f7ac52008-01-31 19:48:22 +01002673};
2674
2675static int parse_monitor_flags(struct nlattr *nla, u32 *mntrflags)
2676{
2677 struct nlattr *flags[NL80211_MNTR_FLAG_MAX + 1];
2678 int flag;
2679
2680 *mntrflags = 0;
2681
2682 if (!nla)
2683 return -EINVAL;
2684
2685 if (nla_parse_nested(flags, NL80211_MNTR_FLAG_MAX,
2686 nla, mntr_flags_policy))
2687 return -EINVAL;
2688
2689 for (flag = 1; flag <= NL80211_MNTR_FLAG_MAX; flag++)
2690 if (flags[flag])
2691 *mntrflags |= (1<<flag);
2692
2693 return 0;
2694}
2695
Johannes Berg9bc383d2009-11-19 11:55:19 +01002696static int nl80211_valid_4addr(struct cfg80211_registered_device *rdev,
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002697 struct net_device *netdev, u8 use_4addr,
2698 enum nl80211_iftype iftype)
Johannes Berg9bc383d2009-11-19 11:55:19 +01002699{
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002700 if (!use_4addr) {
Jiri Pirkof350a0a82010-06-15 06:50:45 +00002701 if (netdev && (netdev->priv_flags & IFF_BRIDGE_PORT))
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002702 return -EBUSY;
Johannes Berg9bc383d2009-11-19 11:55:19 +01002703 return 0;
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002704 }
Johannes Berg9bc383d2009-11-19 11:55:19 +01002705
2706 switch (iftype) {
2707 case NL80211_IFTYPE_AP_VLAN:
2708 if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_AP)
2709 return 0;
2710 break;
2711 case NL80211_IFTYPE_STATION:
2712 if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_STATION)
2713 return 0;
2714 break;
2715 default:
2716 break;
2717 }
2718
2719 return -EOPNOTSUPP;
2720}
2721
Johannes Berg55682962007-09-20 13:09:35 -04002722static int nl80211_set_interface(struct sk_buff *skb, struct genl_info *info)
2723{
Johannes Berg4c476992010-10-04 21:36:35 +02002724 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002725 struct vif_params params;
Johannes Berge36d56b2009-06-09 21:04:43 +02002726 int err;
Johannes Berg04a773a2009-04-19 21:24:32 +02002727 enum nl80211_iftype otype, ntype;
Johannes Berg4c476992010-10-04 21:36:35 +02002728 struct net_device *dev = info->user_ptr[1];
Johannes Berg92ffe052008-09-16 20:39:36 +02002729 u32 _flags, *flags = NULL;
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002730 bool change = false;
Johannes Berg55682962007-09-20 13:09:35 -04002731
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002732 memset(&params, 0, sizeof(params));
2733
Johannes Berg04a773a2009-04-19 21:24:32 +02002734 otype = ntype = dev->ieee80211_ptr->iftype;
Johannes Berg55682962007-09-20 13:09:35 -04002735
Johannes Berg723b0382008-09-16 20:22:09 +02002736 if (info->attrs[NL80211_ATTR_IFTYPE]) {
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002737 ntype = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]);
Johannes Berg04a773a2009-04-19 21:24:32 +02002738 if (otype != ntype)
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002739 change = true;
Johannes Berg4c476992010-10-04 21:36:35 +02002740 if (ntype > NL80211_IFTYPE_MAX)
2741 return -EINVAL;
Johannes Berg723b0382008-09-16 20:22:09 +02002742 }
2743
Johannes Berg92ffe052008-09-16 20:39:36 +02002744 if (info->attrs[NL80211_ATTR_MESH_ID]) {
Johannes Berg29cbe682010-12-03 09:20:44 +01002745 struct wireless_dev *wdev = dev->ieee80211_ptr;
2746
Johannes Berg4c476992010-10-04 21:36:35 +02002747 if (ntype != NL80211_IFTYPE_MESH_POINT)
2748 return -EINVAL;
Johannes Berg29cbe682010-12-03 09:20:44 +01002749 if (netif_running(dev))
2750 return -EBUSY;
2751
2752 wdev_lock(wdev);
2753 BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN !=
2754 IEEE80211_MAX_MESH_ID_LEN);
2755 wdev->mesh_id_up_len =
2756 nla_len(info->attrs[NL80211_ATTR_MESH_ID]);
2757 memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]),
2758 wdev->mesh_id_up_len);
2759 wdev_unlock(wdev);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002760 }
2761
Felix Fietkau8b787642009-11-10 18:53:10 +01002762 if (info->attrs[NL80211_ATTR_4ADDR]) {
2763 params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]);
2764 change = true;
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002765 err = nl80211_valid_4addr(rdev, dev, params.use_4addr, ntype);
Johannes Berg9bc383d2009-11-19 11:55:19 +01002766 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02002767 return err;
Felix Fietkau8b787642009-11-10 18:53:10 +01002768 } else {
2769 params.use_4addr = -1;
2770 }
2771
Johannes Berg92ffe052008-09-16 20:39:36 +02002772 if (info->attrs[NL80211_ATTR_MNTR_FLAGS]) {
Johannes Berg4c476992010-10-04 21:36:35 +02002773 if (ntype != NL80211_IFTYPE_MONITOR)
2774 return -EINVAL;
Johannes Berg92ffe052008-09-16 20:39:36 +02002775 err = parse_monitor_flags(info->attrs[NL80211_ATTR_MNTR_FLAGS],
2776 &_flags);
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002777 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02002778 return err;
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002779
2780 flags = &_flags;
2781 change = true;
Johannes Berg92ffe052008-09-16 20:39:36 +02002782 }
Johannes Berg3b858752009-03-12 09:55:09 +01002783
Aviya Erenfeldc6e6a0c2016-07-05 15:23:08 +03002784 if (info->attrs[NL80211_ATTR_MU_MIMO_GROUP_DATA]) {
2785 const u8 *mumimo_groups;
2786 u32 cap_flag = NL80211_EXT_FEATURE_MU_MIMO_AIR_SNIFFER;
2787
2788 if (!wiphy_ext_feature_isset(&rdev->wiphy, cap_flag))
2789 return -EOPNOTSUPP;
2790
2791 mumimo_groups =
2792 nla_data(info->attrs[NL80211_ATTR_MU_MIMO_GROUP_DATA]);
2793
2794 /* bits 0 and 63 are reserved and must be zero */
2795 if ((mumimo_groups[0] & BIT(7)) ||
2796 (mumimo_groups[VHT_MUMIMO_GROUPS_DATA_LEN - 1] & BIT(0)))
2797 return -EINVAL;
2798
2799 memcpy(params.vht_mumimo_groups, mumimo_groups,
2800 VHT_MUMIMO_GROUPS_DATA_LEN);
2801 change = true;
2802 }
2803
2804 if (info->attrs[NL80211_ATTR_MU_MIMO_FOLLOW_MAC_ADDR]) {
2805 u32 cap_flag = NL80211_EXT_FEATURE_MU_MIMO_AIR_SNIFFER;
2806
2807 if (!wiphy_ext_feature_isset(&rdev->wiphy, cap_flag))
2808 return -EOPNOTSUPP;
2809
2810 nla_memcpy(params.macaddr,
2811 info->attrs[NL80211_ATTR_MU_MIMO_FOLLOW_MAC_ADDR],
2812 ETH_ALEN);
2813 change = true;
2814 }
2815
Luciano Coelho18003292013-08-29 13:26:57 +03002816 if (flags && (*flags & MONITOR_FLAG_ACTIVE) &&
Felix Fietkaue057d3c2013-05-28 13:01:52 +02002817 !(rdev->wiphy.features & NL80211_FEATURE_ACTIVE_MONITOR))
2818 return -EOPNOTSUPP;
2819
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002820 if (change)
Johannes Berg3d54d252009-08-21 14:51:05 +02002821 err = cfg80211_change_iface(rdev, dev, ntype, flags, &params);
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002822 else
2823 err = 0;
Johannes Berg60719ff2008-09-16 14:55:09 +02002824
Johannes Berg9bc383d2009-11-19 11:55:19 +01002825 if (!err && params.use_4addr != -1)
2826 dev->ieee80211_ptr->use_4addr = params.use_4addr;
2827
Johannes Berg55682962007-09-20 13:09:35 -04002828 return err;
2829}
2830
2831static int nl80211_new_interface(struct sk_buff *skb, struct genl_info *info)
2832{
Johannes Berg4c476992010-10-04 21:36:35 +02002833 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002834 struct vif_params params;
Johannes Berg84efbb82012-06-16 00:00:26 +02002835 struct wireless_dev *wdev;
Denis Kenzior896ff062016-08-03 16:58:33 -05002836 struct sk_buff *msg;
Johannes Berg55682962007-09-20 13:09:35 -04002837 int err;
2838 enum nl80211_iftype type = NL80211_IFTYPE_UNSPECIFIED;
Michael Wu66f7ac52008-01-31 19:48:22 +01002839 u32 flags;
Johannes Berg55682962007-09-20 13:09:35 -04002840
Johannes Berg78f22b62014-03-24 17:57:27 +01002841 /* to avoid failing a new interface creation due to pending removal */
2842 cfg80211_destroy_ifaces(rdev);
2843
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002844 memset(&params, 0, sizeof(params));
2845
Johannes Berg55682962007-09-20 13:09:35 -04002846 if (!info->attrs[NL80211_ATTR_IFNAME])
2847 return -EINVAL;
2848
2849 if (info->attrs[NL80211_ATTR_IFTYPE]) {
2850 type = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]);
2851 if (type > NL80211_IFTYPE_MAX)
2852 return -EINVAL;
2853 }
2854
Johannes Berg79c97e92009-07-07 03:56:12 +02002855 if (!rdev->ops->add_virtual_intf ||
Johannes Berg4c476992010-10-04 21:36:35 +02002856 !(rdev->wiphy.interface_modes & (1 << type)))
2857 return -EOPNOTSUPP;
Johannes Berg55682962007-09-20 13:09:35 -04002858
Ayala Bekercb3b7d82016-09-20 17:31:13 +03002859 if ((type == NL80211_IFTYPE_P2P_DEVICE || type == NL80211_IFTYPE_NAN ||
Ben Greeare8f479b2014-10-22 12:23:05 -07002860 rdev->wiphy.features & NL80211_FEATURE_MAC_ON_CREATE) &&
2861 info->attrs[NL80211_ATTR_MAC]) {
Arend van Spriel1c18f142013-01-08 10:17:27 +01002862 nla_memcpy(params.macaddr, info->attrs[NL80211_ATTR_MAC],
2863 ETH_ALEN);
2864 if (!is_valid_ether_addr(params.macaddr))
2865 return -EADDRNOTAVAIL;
2866 }
2867
Johannes Berg9bc383d2009-11-19 11:55:19 +01002868 if (info->attrs[NL80211_ATTR_4ADDR]) {
Felix Fietkau8b787642009-11-10 18:53:10 +01002869 params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]);
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002870 err = nl80211_valid_4addr(rdev, NULL, params.use_4addr, type);
Johannes Berg9bc383d2009-11-19 11:55:19 +01002871 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02002872 return err;
Johannes Berg9bc383d2009-11-19 11:55:19 +01002873 }
Felix Fietkau8b787642009-11-10 18:53:10 +01002874
Michael Wu66f7ac52008-01-31 19:48:22 +01002875 err = parse_monitor_flags(type == NL80211_IFTYPE_MONITOR ?
2876 info->attrs[NL80211_ATTR_MNTR_FLAGS] : NULL,
2877 &flags);
Felix Fietkaue057d3c2013-05-28 13:01:52 +02002878
Luciano Coelho18003292013-08-29 13:26:57 +03002879 if (!err && (flags & MONITOR_FLAG_ACTIVE) &&
Felix Fietkaue057d3c2013-05-28 13:01:52 +02002880 !(rdev->wiphy.features & NL80211_FEATURE_ACTIVE_MONITOR))
2881 return -EOPNOTSUPP;
2882
Johannes Berga18c7192015-02-24 10:56:42 +01002883 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
2884 if (!msg)
2885 return -ENOMEM;
2886
Hila Gonene35e4d22012-06-27 17:19:42 +03002887 wdev = rdev_add_virtual_intf(rdev,
2888 nla_data(info->attrs[NL80211_ATTR_IFNAME]),
Tom Gundersen6bab2e192015-03-18 11:13:39 +01002889 NET_NAME_USER, type, err ? NULL : &flags,
2890 &params);
Rafał Miłeckid687cbb2014-11-14 18:43:28 +01002891 if (WARN_ON(!wdev)) {
2892 nlmsg_free(msg);
2893 return -EPROTO;
2894 } else if (IS_ERR(wdev)) {
Johannes Berg1c90f9d2012-06-16 00:05:37 +02002895 nlmsg_free(msg);
Johannes Berg84efbb82012-06-16 00:00:26 +02002896 return PTR_ERR(wdev);
Johannes Berg1c90f9d2012-06-16 00:05:37 +02002897 }
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002898
Jukka Rissanen18e5ca62014-11-13 17:25:14 +02002899 if (info->attrs[NL80211_ATTR_SOCKET_OWNER])
Johannes Berg78f22b62014-03-24 17:57:27 +01002900 wdev->owner_nlportid = info->snd_portid;
2901
Johannes Berg98104fde2012-06-16 00:19:54 +02002902 switch (type) {
2903 case NL80211_IFTYPE_MESH_POINT:
2904 if (!info->attrs[NL80211_ATTR_MESH_ID])
2905 break;
Johannes Berg29cbe682010-12-03 09:20:44 +01002906 wdev_lock(wdev);
2907 BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN !=
2908 IEEE80211_MAX_MESH_ID_LEN);
2909 wdev->mesh_id_up_len =
2910 nla_len(info->attrs[NL80211_ATTR_MESH_ID]);
2911 memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]),
2912 wdev->mesh_id_up_len);
2913 wdev_unlock(wdev);
Johannes Berg98104fde2012-06-16 00:19:54 +02002914 break;
Ayala Bekercb3b7d82016-09-20 17:31:13 +03002915 case NL80211_IFTYPE_NAN:
Johannes Berg98104fde2012-06-16 00:19:54 +02002916 case NL80211_IFTYPE_P2P_DEVICE:
2917 /*
Ayala Bekercb3b7d82016-09-20 17:31:13 +03002918 * P2P Device and NAN do not have a netdev, so don't go
Johannes Berg98104fde2012-06-16 00:19:54 +02002919 * through the netdev notifier and must be added here
2920 */
2921 mutex_init(&wdev->mtx);
2922 INIT_LIST_HEAD(&wdev->event_list);
2923 spin_lock_init(&wdev->event_lock);
2924 INIT_LIST_HEAD(&wdev->mgmt_registrations);
2925 spin_lock_init(&wdev->mgmt_registrations_lock);
2926
Johannes Berg98104fde2012-06-16 00:19:54 +02002927 wdev->identifier = ++rdev->wdev_id;
Johannes Berg53873f12016-05-03 16:52:04 +03002928 list_add_rcu(&wdev->list, &rdev->wiphy.wdev_list);
Johannes Berg98104fde2012-06-16 00:19:54 +02002929 rdev->devlist_generation++;
Johannes Berg98104fde2012-06-16 00:19:54 +02002930 break;
2931 default:
2932 break;
Johannes Berg29cbe682010-12-03 09:20:44 +01002933 }
2934
Eric W. Biederman15e47302012-09-07 20:12:54 +00002935 if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0,
Tomasz Bursztyka8f894be2014-11-12 16:26:45 +02002936 rdev, wdev, false) < 0) {
Johannes Berg1c90f9d2012-06-16 00:05:37 +02002937 nlmsg_free(msg);
2938 return -ENOBUFS;
2939 }
2940
Denis Kenzior896ff062016-08-03 16:58:33 -05002941 /*
2942 * For wdevs which have no associated netdev object (e.g. of type
2943 * NL80211_IFTYPE_P2P_DEVICE), emit the NEW_INTERFACE event here.
2944 * For all other types, the event will be generated from the
2945 * netdev notifier
2946 */
2947 if (!wdev->netdev)
2948 nl80211_notify_iface(rdev, wdev, NL80211_CMD_NEW_INTERFACE);
Tomasz Bursztyka8f894be2014-11-12 16:26:45 +02002949
Johannes Berg1c90f9d2012-06-16 00:05:37 +02002950 return genlmsg_reply(msg, info);
Johannes Berg55682962007-09-20 13:09:35 -04002951}
2952
2953static int nl80211_del_interface(struct sk_buff *skb, struct genl_info *info)
2954{
Johannes Berg4c476992010-10-04 21:36:35 +02002955 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg84efbb82012-06-16 00:00:26 +02002956 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg55682962007-09-20 13:09:35 -04002957
Johannes Berg4c476992010-10-04 21:36:35 +02002958 if (!rdev->ops->del_virtual_intf)
2959 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01002960
Johannes Berg84efbb82012-06-16 00:00:26 +02002961 /*
2962 * If we remove a wireless device without a netdev then clear
2963 * user_ptr[1] so that nl80211_post_doit won't dereference it
2964 * to check if it needs to do dev_put(). Otherwise it crashes
2965 * since the wdev has been freed, unlike with a netdev where
2966 * we need the dev_put() for the netdev to really be freed.
2967 */
2968 if (!wdev->netdev)
2969 info->user_ptr[1] = NULL;
2970
Denis Kenzior7f8ed012016-08-03 16:58:35 -05002971 return rdev_del_virtual_intf(rdev, wdev);
Johannes Berg55682962007-09-20 13:09:35 -04002972}
2973
Simon Wunderlich1d9d9212011-11-18 14:20:43 +01002974static int nl80211_set_noack_map(struct sk_buff *skb, struct genl_info *info)
2975{
2976 struct cfg80211_registered_device *rdev = info->user_ptr[0];
2977 struct net_device *dev = info->user_ptr[1];
2978 u16 noack_map;
2979
2980 if (!info->attrs[NL80211_ATTR_NOACK_MAP])
2981 return -EINVAL;
2982
2983 if (!rdev->ops->set_noack_map)
2984 return -EOPNOTSUPP;
2985
2986 noack_map = nla_get_u16(info->attrs[NL80211_ATTR_NOACK_MAP]);
2987
Hila Gonene35e4d22012-06-27 17:19:42 +03002988 return rdev_set_noack_map(rdev, dev, noack_map);
Simon Wunderlich1d9d9212011-11-18 14:20:43 +01002989}
2990
Johannes Berg41ade002007-12-19 02:03:29 +01002991struct get_key_cookie {
2992 struct sk_buff *msg;
2993 int error;
Johannes Bergb9454e82009-07-08 13:29:08 +02002994 int idx;
Johannes Berg41ade002007-12-19 02:03:29 +01002995};
2996
2997static void get_key_callback(void *c, struct key_params *params)
2998{
Johannes Bergb9454e82009-07-08 13:29:08 +02002999 struct nlattr *key;
Johannes Berg41ade002007-12-19 02:03:29 +01003000 struct get_key_cookie *cookie = c;
3001
David S. Miller9360ffd2012-03-29 04:41:26 -04003002 if ((params->key &&
3003 nla_put(cookie->msg, NL80211_ATTR_KEY_DATA,
3004 params->key_len, params->key)) ||
3005 (params->seq &&
3006 nla_put(cookie->msg, NL80211_ATTR_KEY_SEQ,
3007 params->seq_len, params->seq)) ||
3008 (params->cipher &&
3009 nla_put_u32(cookie->msg, NL80211_ATTR_KEY_CIPHER,
3010 params->cipher)))
3011 goto nla_put_failure;
Johannes Berg41ade002007-12-19 02:03:29 +01003012
Johannes Bergb9454e82009-07-08 13:29:08 +02003013 key = nla_nest_start(cookie->msg, NL80211_ATTR_KEY);
3014 if (!key)
3015 goto nla_put_failure;
3016
David S. Miller9360ffd2012-03-29 04:41:26 -04003017 if ((params->key &&
3018 nla_put(cookie->msg, NL80211_KEY_DATA,
3019 params->key_len, params->key)) ||
3020 (params->seq &&
3021 nla_put(cookie->msg, NL80211_KEY_SEQ,
3022 params->seq_len, params->seq)) ||
3023 (params->cipher &&
3024 nla_put_u32(cookie->msg, NL80211_KEY_CIPHER,
3025 params->cipher)))
3026 goto nla_put_failure;
Johannes Bergb9454e82009-07-08 13:29:08 +02003027
David S. Miller9360ffd2012-03-29 04:41:26 -04003028 if (nla_put_u8(cookie->msg, NL80211_ATTR_KEY_IDX, cookie->idx))
3029 goto nla_put_failure;
Johannes Bergb9454e82009-07-08 13:29:08 +02003030
3031 nla_nest_end(cookie->msg, key);
3032
Johannes Berg41ade002007-12-19 02:03:29 +01003033 return;
3034 nla_put_failure:
3035 cookie->error = 1;
3036}
3037
3038static int nl80211_get_key(struct sk_buff *skb, struct genl_info *info)
3039{
Johannes Berg4c476992010-10-04 21:36:35 +02003040 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg41ade002007-12-19 02:03:29 +01003041 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02003042 struct net_device *dev = info->user_ptr[1];
Johannes Berg41ade002007-12-19 02:03:29 +01003043 u8 key_idx = 0;
Johannes Berge31b8212010-10-05 19:39:30 +02003044 const u8 *mac_addr = NULL;
3045 bool pairwise;
Johannes Berg41ade002007-12-19 02:03:29 +01003046 struct get_key_cookie cookie = {
3047 .error = 0,
3048 };
3049 void *hdr;
3050 struct sk_buff *msg;
3051
3052 if (info->attrs[NL80211_ATTR_KEY_IDX])
3053 key_idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]);
3054
Jouni Malinen3cfcf6ac2009-01-08 13:32:02 +02003055 if (key_idx > 5)
Johannes Berg41ade002007-12-19 02:03:29 +01003056 return -EINVAL;
3057
3058 if (info->attrs[NL80211_ATTR_MAC])
3059 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
3060
Johannes Berge31b8212010-10-05 19:39:30 +02003061 pairwise = !!mac_addr;
3062 if (info->attrs[NL80211_ATTR_KEY_TYPE]) {
3063 u32 kt = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]);
Kirtika Ruchandani7a087e72016-05-29 19:51:23 -07003064
Johannes Berge31b8212010-10-05 19:39:30 +02003065 if (kt >= NUM_NL80211_KEYTYPES)
3066 return -EINVAL;
3067 if (kt != NL80211_KEYTYPE_GROUP &&
3068 kt != NL80211_KEYTYPE_PAIRWISE)
3069 return -EINVAL;
3070 pairwise = kt == NL80211_KEYTYPE_PAIRWISE;
3071 }
3072
Johannes Berg4c476992010-10-04 21:36:35 +02003073 if (!rdev->ops->get_key)
3074 return -EOPNOTSUPP;
Johannes Berg41ade002007-12-19 02:03:29 +01003075
Johannes Berg0fa7b392015-01-23 11:10:12 +01003076 if (!pairwise && mac_addr && !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN))
3077 return -ENOENT;
3078
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07003079 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02003080 if (!msg)
3081 return -ENOMEM;
Johannes Berg41ade002007-12-19 02:03:29 +01003082
Eric W. Biederman15e47302012-09-07 20:12:54 +00003083 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berg41ade002007-12-19 02:03:29 +01003084 NL80211_CMD_NEW_KEY);
Dan Carpentercb35fba2013-08-14 14:50:01 +03003085 if (!hdr)
Johannes Berg9fe271a2013-10-25 11:15:12 +02003086 goto nla_put_failure;
Johannes Berg41ade002007-12-19 02:03:29 +01003087
3088 cookie.msg = msg;
Johannes Bergb9454e82009-07-08 13:29:08 +02003089 cookie.idx = key_idx;
Johannes Berg41ade002007-12-19 02:03:29 +01003090
David S. Miller9360ffd2012-03-29 04:41:26 -04003091 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
3092 nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_idx))
3093 goto nla_put_failure;
3094 if (mac_addr &&
3095 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr))
3096 goto nla_put_failure;
Johannes Berg41ade002007-12-19 02:03:29 +01003097
Hila Gonene35e4d22012-06-27 17:19:42 +03003098 err = rdev_get_key(rdev, dev, key_idx, pairwise, mac_addr, &cookie,
3099 get_key_callback);
Johannes Berg41ade002007-12-19 02:03:29 +01003100
3101 if (err)
Niko Jokinen6c95e2a2009-07-15 11:00:53 +03003102 goto free_msg;
Johannes Berg41ade002007-12-19 02:03:29 +01003103
3104 if (cookie.error)
3105 goto nla_put_failure;
3106
3107 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02003108 return genlmsg_reply(msg, info);
Johannes Berg41ade002007-12-19 02:03:29 +01003109
3110 nla_put_failure:
3111 err = -ENOBUFS;
Niko Jokinen6c95e2a2009-07-15 11:00:53 +03003112 free_msg:
Johannes Berg41ade002007-12-19 02:03:29 +01003113 nlmsg_free(msg);
Johannes Berg41ade002007-12-19 02:03:29 +01003114 return err;
3115}
3116
3117static int nl80211_set_key(struct sk_buff *skb, struct genl_info *info)
3118{
Johannes Berg4c476992010-10-04 21:36:35 +02003119 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Bergb9454e82009-07-08 13:29:08 +02003120 struct key_parse key;
Johannes Berg41ade002007-12-19 02:03:29 +01003121 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02003122 struct net_device *dev = info->user_ptr[1];
Johannes Berg41ade002007-12-19 02:03:29 +01003123
Johannes Bergb9454e82009-07-08 13:29:08 +02003124 err = nl80211_parse_key(info, &key);
3125 if (err)
3126 return err;
3127
3128 if (key.idx < 0)
Johannes Berg41ade002007-12-19 02:03:29 +01003129 return -EINVAL;
3130
Johannes Bergb9454e82009-07-08 13:29:08 +02003131 /* only support setting default key */
3132 if (!key.def && !key.defmgmt)
Johannes Berg41ade002007-12-19 02:03:29 +01003133 return -EINVAL;
3134
Johannes Bergfffd0932009-07-08 14:22:54 +02003135 wdev_lock(dev->ieee80211_ptr);
Johannes Bergdbd2fd62010-12-09 19:58:59 +01003136
3137 if (key.def) {
3138 if (!rdev->ops->set_default_key) {
3139 err = -EOPNOTSUPP;
3140 goto out;
3141 }
3142
3143 err = nl80211_key_allowed(dev->ieee80211_ptr);
3144 if (err)
3145 goto out;
3146
Hila Gonene35e4d22012-06-27 17:19:42 +03003147 err = rdev_set_default_key(rdev, dev, key.idx,
Johannes Bergdbd2fd62010-12-09 19:58:59 +01003148 key.def_uni, key.def_multi);
3149
3150 if (err)
3151 goto out;
Johannes Bergfffd0932009-07-08 14:22:54 +02003152
Johannes Berg3d23e342009-09-29 23:27:28 +02003153#ifdef CONFIG_CFG80211_WEXT
Johannes Bergdbd2fd62010-12-09 19:58:59 +01003154 dev->ieee80211_ptr->wext.default_key = key.idx;
Johannes Berg08645122009-05-11 13:54:58 +02003155#endif
Johannes Bergdbd2fd62010-12-09 19:58:59 +01003156 } else {
3157 if (key.def_uni || !key.def_multi) {
3158 err = -EINVAL;
3159 goto out;
3160 }
3161
3162 if (!rdev->ops->set_default_mgmt_key) {
3163 err = -EOPNOTSUPP;
3164 goto out;
3165 }
3166
3167 err = nl80211_key_allowed(dev->ieee80211_ptr);
3168 if (err)
3169 goto out;
3170
Hila Gonene35e4d22012-06-27 17:19:42 +03003171 err = rdev_set_default_mgmt_key(rdev, dev, key.idx);
Johannes Bergdbd2fd62010-12-09 19:58:59 +01003172 if (err)
3173 goto out;
3174
3175#ifdef CONFIG_CFG80211_WEXT
3176 dev->ieee80211_ptr->wext.default_mgmt_key = key.idx;
3177#endif
3178 }
3179
3180 out:
Johannes Bergfffd0932009-07-08 14:22:54 +02003181 wdev_unlock(dev->ieee80211_ptr);
Johannes Berg41ade002007-12-19 02:03:29 +01003182
Johannes Berg41ade002007-12-19 02:03:29 +01003183 return err;
3184}
3185
3186static int nl80211_new_key(struct sk_buff *skb, struct genl_info *info)
3187{
Johannes Berg4c476992010-10-04 21:36:35 +02003188 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Bergfffd0932009-07-08 14:22:54 +02003189 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02003190 struct net_device *dev = info->user_ptr[1];
Johannes Bergb9454e82009-07-08 13:29:08 +02003191 struct key_parse key;
Johannes Berge31b8212010-10-05 19:39:30 +02003192 const u8 *mac_addr = NULL;
Johannes Berg41ade002007-12-19 02:03:29 +01003193
Johannes Bergb9454e82009-07-08 13:29:08 +02003194 err = nl80211_parse_key(info, &key);
3195 if (err)
3196 return err;
Johannes Berg41ade002007-12-19 02:03:29 +01003197
Johannes Bergb9454e82009-07-08 13:29:08 +02003198 if (!key.p.key)
Johannes Berg41ade002007-12-19 02:03:29 +01003199 return -EINVAL;
3200
Johannes Berg41ade002007-12-19 02:03:29 +01003201 if (info->attrs[NL80211_ATTR_MAC])
3202 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
3203
Johannes Berge31b8212010-10-05 19:39:30 +02003204 if (key.type == -1) {
3205 if (mac_addr)
3206 key.type = NL80211_KEYTYPE_PAIRWISE;
3207 else
3208 key.type = NL80211_KEYTYPE_GROUP;
3209 }
3210
3211 /* for now */
3212 if (key.type != NL80211_KEYTYPE_PAIRWISE &&
3213 key.type != NL80211_KEYTYPE_GROUP)
3214 return -EINVAL;
3215
Johannes Berg4c476992010-10-04 21:36:35 +02003216 if (!rdev->ops->add_key)
3217 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01003218
Johannes Berge31b8212010-10-05 19:39:30 +02003219 if (cfg80211_validate_key_settings(rdev, &key.p, key.idx,
3220 key.type == NL80211_KEYTYPE_PAIRWISE,
3221 mac_addr))
Johannes Berg4c476992010-10-04 21:36:35 +02003222 return -EINVAL;
Johannes Bergfffd0932009-07-08 14:22:54 +02003223
3224 wdev_lock(dev->ieee80211_ptr);
3225 err = nl80211_key_allowed(dev->ieee80211_ptr);
3226 if (!err)
Hila Gonene35e4d22012-06-27 17:19:42 +03003227 err = rdev_add_key(rdev, dev, key.idx,
3228 key.type == NL80211_KEYTYPE_PAIRWISE,
3229 mac_addr, &key.p);
Johannes Bergfffd0932009-07-08 14:22:54 +02003230 wdev_unlock(dev->ieee80211_ptr);
Johannes Berg41ade002007-12-19 02:03:29 +01003231
Johannes Berg41ade002007-12-19 02:03:29 +01003232 return err;
3233}
3234
3235static int nl80211_del_key(struct sk_buff *skb, struct genl_info *info)
3236{
Johannes Berg4c476992010-10-04 21:36:35 +02003237 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg41ade002007-12-19 02:03:29 +01003238 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02003239 struct net_device *dev = info->user_ptr[1];
Johannes Berg41ade002007-12-19 02:03:29 +01003240 u8 *mac_addr = NULL;
Johannes Bergb9454e82009-07-08 13:29:08 +02003241 struct key_parse key;
Johannes Berg41ade002007-12-19 02:03:29 +01003242
Johannes Bergb9454e82009-07-08 13:29:08 +02003243 err = nl80211_parse_key(info, &key);
3244 if (err)
3245 return err;
Johannes Berg41ade002007-12-19 02:03:29 +01003246
3247 if (info->attrs[NL80211_ATTR_MAC])
3248 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
3249
Johannes Berge31b8212010-10-05 19:39:30 +02003250 if (key.type == -1) {
3251 if (mac_addr)
3252 key.type = NL80211_KEYTYPE_PAIRWISE;
3253 else
3254 key.type = NL80211_KEYTYPE_GROUP;
3255 }
3256
3257 /* for now */
3258 if (key.type != NL80211_KEYTYPE_PAIRWISE &&
3259 key.type != NL80211_KEYTYPE_GROUP)
3260 return -EINVAL;
3261
Johannes Berg4c476992010-10-04 21:36:35 +02003262 if (!rdev->ops->del_key)
3263 return -EOPNOTSUPP;
Johannes Berg41ade002007-12-19 02:03:29 +01003264
Johannes Bergfffd0932009-07-08 14:22:54 +02003265 wdev_lock(dev->ieee80211_ptr);
3266 err = nl80211_key_allowed(dev->ieee80211_ptr);
Johannes Berge31b8212010-10-05 19:39:30 +02003267
Johannes Berg0fa7b392015-01-23 11:10:12 +01003268 if (key.type == NL80211_KEYTYPE_GROUP && mac_addr &&
Johannes Berge31b8212010-10-05 19:39:30 +02003269 !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN))
3270 err = -ENOENT;
3271
Johannes Bergfffd0932009-07-08 14:22:54 +02003272 if (!err)
Hila Gonene35e4d22012-06-27 17:19:42 +03003273 err = rdev_del_key(rdev, dev, key.idx,
3274 key.type == NL80211_KEYTYPE_PAIRWISE,
3275 mac_addr);
Johannes Berg41ade002007-12-19 02:03:29 +01003276
Johannes Berg3d23e342009-09-29 23:27:28 +02003277#ifdef CONFIG_CFG80211_WEXT
Johannes Berg08645122009-05-11 13:54:58 +02003278 if (!err) {
Johannes Bergb9454e82009-07-08 13:29:08 +02003279 if (key.idx == dev->ieee80211_ptr->wext.default_key)
Johannes Berg08645122009-05-11 13:54:58 +02003280 dev->ieee80211_ptr->wext.default_key = -1;
Johannes Bergb9454e82009-07-08 13:29:08 +02003281 else if (key.idx == dev->ieee80211_ptr->wext.default_mgmt_key)
Johannes Berg08645122009-05-11 13:54:58 +02003282 dev->ieee80211_ptr->wext.default_mgmt_key = -1;
3283 }
3284#endif
Johannes Bergfffd0932009-07-08 14:22:54 +02003285 wdev_unlock(dev->ieee80211_ptr);
Johannes Berg08645122009-05-11 13:54:58 +02003286
Johannes Berg41ade002007-12-19 02:03:29 +01003287 return err;
3288}
3289
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +05303290/* This function returns an error or the number of nested attributes */
3291static int validate_acl_mac_addrs(struct nlattr *nl_attr)
3292{
3293 struct nlattr *attr;
3294 int n_entries = 0, tmp;
3295
3296 nla_for_each_nested(attr, nl_attr, tmp) {
3297 if (nla_len(attr) != ETH_ALEN)
3298 return -EINVAL;
3299
3300 n_entries++;
3301 }
3302
3303 return n_entries;
3304}
3305
3306/*
3307 * This function parses ACL information and allocates memory for ACL data.
3308 * On successful return, the calling function is responsible to free the
3309 * ACL buffer returned by this function.
3310 */
3311static struct cfg80211_acl_data *parse_acl_data(struct wiphy *wiphy,
3312 struct genl_info *info)
3313{
3314 enum nl80211_acl_policy acl_policy;
3315 struct nlattr *attr;
3316 struct cfg80211_acl_data *acl;
3317 int i = 0, n_entries, tmp;
3318
3319 if (!wiphy->max_acl_mac_addrs)
3320 return ERR_PTR(-EOPNOTSUPP);
3321
3322 if (!info->attrs[NL80211_ATTR_ACL_POLICY])
3323 return ERR_PTR(-EINVAL);
3324
3325 acl_policy = nla_get_u32(info->attrs[NL80211_ATTR_ACL_POLICY]);
3326 if (acl_policy != NL80211_ACL_POLICY_ACCEPT_UNLESS_LISTED &&
3327 acl_policy != NL80211_ACL_POLICY_DENY_UNLESS_LISTED)
3328 return ERR_PTR(-EINVAL);
3329
3330 if (!info->attrs[NL80211_ATTR_MAC_ADDRS])
3331 return ERR_PTR(-EINVAL);
3332
3333 n_entries = validate_acl_mac_addrs(info->attrs[NL80211_ATTR_MAC_ADDRS]);
3334 if (n_entries < 0)
3335 return ERR_PTR(n_entries);
3336
3337 if (n_entries > wiphy->max_acl_mac_addrs)
3338 return ERR_PTR(-ENOTSUPP);
3339
3340 acl = kzalloc(sizeof(*acl) + (sizeof(struct mac_address) * n_entries),
3341 GFP_KERNEL);
3342 if (!acl)
3343 return ERR_PTR(-ENOMEM);
3344
3345 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_MAC_ADDRS], tmp) {
3346 memcpy(acl->mac_addrs[i].addr, nla_data(attr), ETH_ALEN);
3347 i++;
3348 }
3349
3350 acl->n_acl_entries = n_entries;
3351 acl->acl_policy = acl_policy;
3352
3353 return acl;
3354}
3355
3356static int nl80211_set_mac_acl(struct sk_buff *skb, struct genl_info *info)
3357{
3358 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3359 struct net_device *dev = info->user_ptr[1];
3360 struct cfg80211_acl_data *acl;
3361 int err;
3362
3363 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
3364 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
3365 return -EOPNOTSUPP;
3366
3367 if (!dev->ieee80211_ptr->beacon_interval)
3368 return -EINVAL;
3369
3370 acl = parse_acl_data(&rdev->wiphy, info);
3371 if (IS_ERR(acl))
3372 return PTR_ERR(acl);
3373
3374 err = rdev_set_mac_acl(rdev, dev, acl);
3375
3376 kfree(acl);
3377
3378 return err;
3379}
3380
Purushottam Kushwahaa7c7fbf2016-09-14 17:38:44 +05303381static u32 rateset_to_mask(struct ieee80211_supported_band *sband,
3382 u8 *rates, u8 rates_len)
3383{
3384 u8 i;
3385 u32 mask = 0;
3386
3387 for (i = 0; i < rates_len; i++) {
3388 int rate = (rates[i] & 0x7f) * 5;
3389 int ridx;
3390
3391 for (ridx = 0; ridx < sband->n_bitrates; ridx++) {
3392 struct ieee80211_rate *srate =
3393 &sband->bitrates[ridx];
3394 if (rate == srate->bitrate) {
3395 mask |= 1 << ridx;
3396 break;
3397 }
3398 }
3399 if (ridx == sband->n_bitrates)
3400 return 0; /* rate not found */
3401 }
3402
3403 return mask;
3404}
3405
3406static bool ht_rateset_to_mask(struct ieee80211_supported_band *sband,
3407 u8 *rates, u8 rates_len,
3408 u8 mcs[IEEE80211_HT_MCS_MASK_LEN])
3409{
3410 u8 i;
3411
3412 memset(mcs, 0, IEEE80211_HT_MCS_MASK_LEN);
3413
3414 for (i = 0; i < rates_len; i++) {
3415 int ridx, rbit;
3416
3417 ridx = rates[i] / 8;
3418 rbit = BIT(rates[i] % 8);
3419
3420 /* check validity */
3421 if ((ridx < 0) || (ridx >= IEEE80211_HT_MCS_MASK_LEN))
3422 return false;
3423
3424 /* check availability */
3425 if (sband->ht_cap.mcs.rx_mask[ridx] & rbit)
3426 mcs[ridx] |= rbit;
3427 else
3428 return false;
3429 }
3430
3431 return true;
3432}
3433
3434static u16 vht_mcs_map_to_mcs_mask(u8 vht_mcs_map)
3435{
3436 u16 mcs_mask = 0;
3437
3438 switch (vht_mcs_map) {
3439 case IEEE80211_VHT_MCS_NOT_SUPPORTED:
3440 break;
3441 case IEEE80211_VHT_MCS_SUPPORT_0_7:
3442 mcs_mask = 0x00FF;
3443 break;
3444 case IEEE80211_VHT_MCS_SUPPORT_0_8:
3445 mcs_mask = 0x01FF;
3446 break;
3447 case IEEE80211_VHT_MCS_SUPPORT_0_9:
3448 mcs_mask = 0x03FF;
3449 break;
3450 default:
3451 break;
3452 }
3453
3454 return mcs_mask;
3455}
3456
3457static void vht_build_mcs_mask(u16 vht_mcs_map,
3458 u16 vht_mcs_mask[NL80211_VHT_NSS_MAX])
3459{
3460 u8 nss;
3461
3462 for (nss = 0; nss < NL80211_VHT_NSS_MAX; nss++) {
3463 vht_mcs_mask[nss] = vht_mcs_map_to_mcs_mask(vht_mcs_map & 0x03);
3464 vht_mcs_map >>= 2;
3465 }
3466}
3467
3468static bool vht_set_mcs_mask(struct ieee80211_supported_band *sband,
3469 struct nl80211_txrate_vht *txrate,
3470 u16 mcs[NL80211_VHT_NSS_MAX])
3471{
3472 u16 tx_mcs_map = le16_to_cpu(sband->vht_cap.vht_mcs.tx_mcs_map);
3473 u16 tx_mcs_mask[NL80211_VHT_NSS_MAX] = {};
3474 u8 i;
3475
3476 if (!sband->vht_cap.vht_supported)
3477 return false;
3478
3479 memset(mcs, 0, sizeof(u16) * NL80211_VHT_NSS_MAX);
3480
3481 /* Build vht_mcs_mask from VHT capabilities */
3482 vht_build_mcs_mask(tx_mcs_map, tx_mcs_mask);
3483
3484 for (i = 0; i < NL80211_VHT_NSS_MAX; i++) {
3485 if ((tx_mcs_mask[i] & txrate->mcs[i]) == txrate->mcs[i])
3486 mcs[i] = txrate->mcs[i];
3487 else
3488 return false;
3489 }
3490
3491 return true;
3492}
3493
3494static const struct nla_policy nl80211_txattr_policy[NL80211_TXRATE_MAX + 1] = {
3495 [NL80211_TXRATE_LEGACY] = { .type = NLA_BINARY,
3496 .len = NL80211_MAX_SUPP_RATES },
3497 [NL80211_TXRATE_HT] = { .type = NLA_BINARY,
3498 .len = NL80211_MAX_SUPP_HT_RATES },
3499 [NL80211_TXRATE_VHT] = { .len = sizeof(struct nl80211_txrate_vht)},
3500 [NL80211_TXRATE_GI] = { .type = NLA_U8 },
3501};
3502
3503static int nl80211_parse_tx_bitrate_mask(struct genl_info *info,
3504 struct cfg80211_bitrate_mask *mask)
3505{
3506 struct nlattr *tb[NL80211_TXRATE_MAX + 1];
3507 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3508 int rem, i;
3509 struct nlattr *tx_rates;
3510 struct ieee80211_supported_band *sband;
3511 u16 vht_tx_mcs_map;
3512
3513 memset(mask, 0, sizeof(*mask));
3514 /* Default to all rates enabled */
3515 for (i = 0; i < NUM_NL80211_BANDS; i++) {
3516 sband = rdev->wiphy.bands[i];
3517
3518 if (!sband)
3519 continue;
3520
3521 mask->control[i].legacy = (1 << sband->n_bitrates) - 1;
3522 memcpy(mask->control[i].ht_mcs,
3523 sband->ht_cap.mcs.rx_mask,
3524 sizeof(mask->control[i].ht_mcs));
3525
3526 if (!sband->vht_cap.vht_supported)
3527 continue;
3528
3529 vht_tx_mcs_map = le16_to_cpu(sband->vht_cap.vht_mcs.tx_mcs_map);
3530 vht_build_mcs_mask(vht_tx_mcs_map, mask->control[i].vht_mcs);
3531 }
3532
3533 /* if no rates are given set it back to the defaults */
3534 if (!info->attrs[NL80211_ATTR_TX_RATES])
3535 goto out;
3536
3537 /* The nested attribute uses enum nl80211_band as the index. This maps
3538 * directly to the enum nl80211_band values used in cfg80211.
3539 */
3540 BUILD_BUG_ON(NL80211_MAX_SUPP_HT_RATES > IEEE80211_HT_MCS_MASK_LEN * 8);
3541 nla_for_each_nested(tx_rates, info->attrs[NL80211_ATTR_TX_RATES], rem) {
3542 enum nl80211_band band = nla_type(tx_rates);
3543 int err;
3544
3545 if (band < 0 || band >= NUM_NL80211_BANDS)
3546 return -EINVAL;
3547 sband = rdev->wiphy.bands[band];
3548 if (sband == NULL)
3549 return -EINVAL;
3550 err = nla_parse(tb, NL80211_TXRATE_MAX, nla_data(tx_rates),
3551 nla_len(tx_rates), nl80211_txattr_policy);
3552 if (err)
3553 return err;
3554 if (tb[NL80211_TXRATE_LEGACY]) {
3555 mask->control[band].legacy = rateset_to_mask(
3556 sband,
3557 nla_data(tb[NL80211_TXRATE_LEGACY]),
3558 nla_len(tb[NL80211_TXRATE_LEGACY]));
3559 if ((mask->control[band].legacy == 0) &&
3560 nla_len(tb[NL80211_TXRATE_LEGACY]))
3561 return -EINVAL;
3562 }
3563 if (tb[NL80211_TXRATE_HT]) {
3564 if (!ht_rateset_to_mask(
3565 sband,
3566 nla_data(tb[NL80211_TXRATE_HT]),
3567 nla_len(tb[NL80211_TXRATE_HT]),
3568 mask->control[band].ht_mcs))
3569 return -EINVAL;
3570 }
3571 if (tb[NL80211_TXRATE_VHT]) {
3572 if (!vht_set_mcs_mask(
3573 sband,
3574 nla_data(tb[NL80211_TXRATE_VHT]),
3575 mask->control[band].vht_mcs))
3576 return -EINVAL;
3577 }
3578 if (tb[NL80211_TXRATE_GI]) {
3579 mask->control[band].gi =
3580 nla_get_u8(tb[NL80211_TXRATE_GI]);
3581 if (mask->control[band].gi > NL80211_TXRATE_FORCE_LGI)
3582 return -EINVAL;
3583 }
3584
3585 if (mask->control[band].legacy == 0) {
3586 /* don't allow empty legacy rates if HT or VHT
3587 * are not even supported.
3588 */
3589 if (!(rdev->wiphy.bands[band]->ht_cap.ht_supported ||
3590 rdev->wiphy.bands[band]->vht_cap.vht_supported))
3591 return -EINVAL;
3592
3593 for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++)
3594 if (mask->control[band].ht_mcs[i])
3595 goto out;
3596
3597 for (i = 0; i < NL80211_VHT_NSS_MAX; i++)
3598 if (mask->control[band].vht_mcs[i])
3599 goto out;
3600
3601 /* legacy and mcs rates may not be both empty */
3602 return -EINVAL;
3603 }
3604 }
3605
3606out:
3607 return 0;
3608}
3609
Johannes Berg8564e382016-09-19 09:44:44 +02003610static int validate_beacon_tx_rate(struct cfg80211_registered_device *rdev,
3611 enum nl80211_band band,
3612 struct cfg80211_bitrate_mask *beacon_rate)
Purushottam Kushwahaa7c7fbf2016-09-14 17:38:44 +05303613{
Johannes Berg8564e382016-09-19 09:44:44 +02003614 u32 count_ht, count_vht, i;
3615 u32 rate = beacon_rate->control[band].legacy;
Purushottam Kushwahaa7c7fbf2016-09-14 17:38:44 +05303616
3617 /* Allow only one rate */
3618 if (hweight32(rate) > 1)
3619 return -EINVAL;
3620
3621 count_ht = 0;
3622 for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++) {
Johannes Berg8564e382016-09-19 09:44:44 +02003623 if (hweight8(beacon_rate->control[band].ht_mcs[i]) > 1) {
Purushottam Kushwahaa7c7fbf2016-09-14 17:38:44 +05303624 return -EINVAL;
Johannes Berg8564e382016-09-19 09:44:44 +02003625 } else if (beacon_rate->control[band].ht_mcs[i]) {
Purushottam Kushwahaa7c7fbf2016-09-14 17:38:44 +05303626 count_ht++;
3627 if (count_ht > 1)
3628 return -EINVAL;
3629 }
3630 if (count_ht && rate)
3631 return -EINVAL;
3632 }
3633
3634 count_vht = 0;
3635 for (i = 0; i < NL80211_VHT_NSS_MAX; i++) {
Johannes Berg8564e382016-09-19 09:44:44 +02003636 if (hweight16(beacon_rate->control[band].vht_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].vht_mcs[i]) {
Purushottam Kushwahaa7c7fbf2016-09-14 17:38:44 +05303639 count_vht++;
3640 if (count_vht > 1)
3641 return -EINVAL;
3642 }
3643 if (count_vht && rate)
3644 return -EINVAL;
3645 }
3646
3647 if ((count_ht && count_vht) || (!rate && !count_ht && !count_vht))
3648 return -EINVAL;
3649
Johannes Berg8564e382016-09-19 09:44:44 +02003650 if (rate &&
3651 !wiphy_ext_feature_isset(&rdev->wiphy,
3652 NL80211_EXT_FEATURE_BEACON_RATE_LEGACY))
3653 return -EINVAL;
3654 if (count_ht &&
3655 !wiphy_ext_feature_isset(&rdev->wiphy,
3656 NL80211_EXT_FEATURE_BEACON_RATE_HT))
3657 return -EINVAL;
3658 if (count_vht &&
3659 !wiphy_ext_feature_isset(&rdev->wiphy,
3660 NL80211_EXT_FEATURE_BEACON_RATE_VHT))
3661 return -EINVAL;
3662
Purushottam Kushwahaa7c7fbf2016-09-14 17:38:44 +05303663 return 0;
3664}
3665
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003666static int nl80211_parse_beacon(struct nlattr *attrs[],
Johannes Berg88600202012-02-13 15:17:18 +01003667 struct cfg80211_beacon_data *bcn)
Johannes Berged1b6cc2007-12-19 02:03:32 +01003668{
Johannes Berg88600202012-02-13 15:17:18 +01003669 bool haveinfo = false;
Johannes Berged1b6cc2007-12-19 02:03:32 +01003670
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003671 if (!is_valid_ie_attr(attrs[NL80211_ATTR_BEACON_TAIL]) ||
3672 !is_valid_ie_attr(attrs[NL80211_ATTR_IE]) ||
3673 !is_valid_ie_attr(attrs[NL80211_ATTR_IE_PROBE_RESP]) ||
3674 !is_valid_ie_attr(attrs[NL80211_ATTR_IE_ASSOC_RESP]))
Johannes Bergf4a11bb2009-03-27 12:40:28 +01003675 return -EINVAL;
3676
Johannes Berg88600202012-02-13 15:17:18 +01003677 memset(bcn, 0, sizeof(*bcn));
Johannes Berged1b6cc2007-12-19 02:03:32 +01003678
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003679 if (attrs[NL80211_ATTR_BEACON_HEAD]) {
3680 bcn->head = nla_data(attrs[NL80211_ATTR_BEACON_HEAD]);
3681 bcn->head_len = nla_len(attrs[NL80211_ATTR_BEACON_HEAD]);
Johannes Berg88600202012-02-13 15:17:18 +01003682 if (!bcn->head_len)
3683 return -EINVAL;
3684 haveinfo = true;
Johannes Berged1b6cc2007-12-19 02:03:32 +01003685 }
3686
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003687 if (attrs[NL80211_ATTR_BEACON_TAIL]) {
3688 bcn->tail = nla_data(attrs[NL80211_ATTR_BEACON_TAIL]);
3689 bcn->tail_len = nla_len(attrs[NL80211_ATTR_BEACON_TAIL]);
Johannes Berg88600202012-02-13 15:17:18 +01003690 haveinfo = true;
Johannes Berged1b6cc2007-12-19 02:03:32 +01003691 }
3692
Johannes Berg4c476992010-10-04 21:36:35 +02003693 if (!haveinfo)
3694 return -EINVAL;
Johannes Berged1b6cc2007-12-19 02:03:32 +01003695
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003696 if (attrs[NL80211_ATTR_IE]) {
3697 bcn->beacon_ies = nla_data(attrs[NL80211_ATTR_IE]);
3698 bcn->beacon_ies_len = nla_len(attrs[NL80211_ATTR_IE]);
Jouni Malinen9946ecf2011-08-10 23:55:56 +03003699 }
3700
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003701 if (attrs[NL80211_ATTR_IE_PROBE_RESP]) {
Johannes Berg88600202012-02-13 15:17:18 +01003702 bcn->proberesp_ies =
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003703 nla_data(attrs[NL80211_ATTR_IE_PROBE_RESP]);
Johannes Berg88600202012-02-13 15:17:18 +01003704 bcn->proberesp_ies_len =
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003705 nla_len(attrs[NL80211_ATTR_IE_PROBE_RESP]);
Jouni Malinen9946ecf2011-08-10 23:55:56 +03003706 }
3707
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003708 if (attrs[NL80211_ATTR_IE_ASSOC_RESP]) {
Johannes Berg88600202012-02-13 15:17:18 +01003709 bcn->assocresp_ies =
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003710 nla_data(attrs[NL80211_ATTR_IE_ASSOC_RESP]);
Johannes Berg88600202012-02-13 15:17:18 +01003711 bcn->assocresp_ies_len =
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003712 nla_len(attrs[NL80211_ATTR_IE_ASSOC_RESP]);
Jouni Malinen9946ecf2011-08-10 23:55:56 +03003713 }
3714
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003715 if (attrs[NL80211_ATTR_PROBE_RESP]) {
3716 bcn->probe_resp = nla_data(attrs[NL80211_ATTR_PROBE_RESP]);
3717 bcn->probe_resp_len = nla_len(attrs[NL80211_ATTR_PROBE_RESP]);
Arik Nemtsov00f740e2011-11-10 11:28:56 +02003718 }
3719
Johannes Berg88600202012-02-13 15:17:18 +01003720 return 0;
3721}
3722
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003723static bool nl80211_get_ap_channel(struct cfg80211_registered_device *rdev,
3724 struct cfg80211_ap_settings *params)
3725{
3726 struct wireless_dev *wdev;
3727 bool ret = false;
3728
Johannes Berg53873f12016-05-03 16:52:04 +03003729 list_for_each_entry(wdev, &rdev->wiphy.wdev_list, list) {
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003730 if (wdev->iftype != NL80211_IFTYPE_AP &&
3731 wdev->iftype != NL80211_IFTYPE_P2P_GO)
3732 continue;
3733
Johannes Berg683b6d32012-11-08 21:25:48 +01003734 if (!wdev->preset_chandef.chan)
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003735 continue;
3736
Johannes Berg683b6d32012-11-08 21:25:48 +01003737 params->chandef = wdev->preset_chandef;
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003738 ret = true;
3739 break;
3740 }
3741
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003742 return ret;
3743}
3744
Jouni Malinene39e5b52012-09-30 19:29:39 +03003745static bool nl80211_valid_auth_type(struct cfg80211_registered_device *rdev,
3746 enum nl80211_auth_type auth_type,
3747 enum nl80211_commands cmd)
3748{
3749 if (auth_type > NL80211_AUTHTYPE_MAX)
3750 return false;
3751
3752 switch (cmd) {
3753 case NL80211_CMD_AUTHENTICATE:
3754 if (!(rdev->wiphy.features & NL80211_FEATURE_SAE) &&
3755 auth_type == NL80211_AUTHTYPE_SAE)
3756 return false;
3757 return true;
3758 case NL80211_CMD_CONNECT:
3759 case NL80211_CMD_START_AP:
3760 /* SAE not supported yet */
3761 if (auth_type == NL80211_AUTHTYPE_SAE)
3762 return false;
3763 return true;
3764 default:
3765 return false;
3766 }
3767}
3768
Johannes Berg88600202012-02-13 15:17:18 +01003769static int nl80211_start_ap(struct sk_buff *skb, struct genl_info *info)
3770{
3771 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3772 struct net_device *dev = info->user_ptr[1];
3773 struct wireless_dev *wdev = dev->ieee80211_ptr;
3774 struct cfg80211_ap_settings params;
3775 int err;
3776
3777 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
3778 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
3779 return -EOPNOTSUPP;
3780
3781 if (!rdev->ops->start_ap)
3782 return -EOPNOTSUPP;
3783
3784 if (wdev->beacon_interval)
3785 return -EALREADY;
3786
3787 memset(&params, 0, sizeof(params));
3788
3789 /* these are required for START_AP */
3790 if (!info->attrs[NL80211_ATTR_BEACON_INTERVAL] ||
3791 !info->attrs[NL80211_ATTR_DTIM_PERIOD] ||
3792 !info->attrs[NL80211_ATTR_BEACON_HEAD])
3793 return -EINVAL;
3794
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003795 err = nl80211_parse_beacon(info->attrs, &params.beacon);
Johannes Berg88600202012-02-13 15:17:18 +01003796 if (err)
3797 return err;
3798
3799 params.beacon_interval =
3800 nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]);
3801 params.dtim_period =
3802 nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]);
3803
3804 err = cfg80211_validate_beacon_int(rdev, params.beacon_interval);
3805 if (err)
3806 return err;
3807
3808 /*
3809 * In theory, some of these attributes should be required here
3810 * but since they were not used when the command was originally
3811 * added, keep them optional for old user space programs to let
3812 * them continue to work with drivers that do not need the
3813 * additional information -- drivers must check!
3814 */
3815 if (info->attrs[NL80211_ATTR_SSID]) {
3816 params.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
3817 params.ssid_len =
3818 nla_len(info->attrs[NL80211_ATTR_SSID]);
3819 if (params.ssid_len == 0 ||
3820 params.ssid_len > IEEE80211_MAX_SSID_LEN)
3821 return -EINVAL;
3822 }
3823
3824 if (info->attrs[NL80211_ATTR_HIDDEN_SSID]) {
3825 params.hidden_ssid = nla_get_u32(
3826 info->attrs[NL80211_ATTR_HIDDEN_SSID]);
3827 if (params.hidden_ssid != NL80211_HIDDEN_SSID_NOT_IN_USE &&
3828 params.hidden_ssid != NL80211_HIDDEN_SSID_ZERO_LEN &&
3829 params.hidden_ssid != NL80211_HIDDEN_SSID_ZERO_CONTENTS)
3830 return -EINVAL;
3831 }
3832
3833 params.privacy = !!info->attrs[NL80211_ATTR_PRIVACY];
3834
3835 if (info->attrs[NL80211_ATTR_AUTH_TYPE]) {
3836 params.auth_type = nla_get_u32(
3837 info->attrs[NL80211_ATTR_AUTH_TYPE]);
Jouni Malinene39e5b52012-09-30 19:29:39 +03003838 if (!nl80211_valid_auth_type(rdev, params.auth_type,
3839 NL80211_CMD_START_AP))
Johannes Berg88600202012-02-13 15:17:18 +01003840 return -EINVAL;
3841 } else
3842 params.auth_type = NL80211_AUTHTYPE_AUTOMATIC;
3843
3844 err = nl80211_crypto_settings(rdev, info, &params.crypto,
3845 NL80211_MAX_NR_CIPHER_SUITES);
3846 if (err)
3847 return err;
3848
Vasanthakumar Thiagarajan1b658f12012-03-02 15:50:02 +05303849 if (info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]) {
3850 if (!(rdev->wiphy.features & NL80211_FEATURE_INACTIVITY_TIMER))
3851 return -EOPNOTSUPP;
3852 params.inactivity_timeout = nla_get_u16(
3853 info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]);
3854 }
3855
Johannes Berg53cabad2012-11-14 15:17:28 +01003856 if (info->attrs[NL80211_ATTR_P2P_CTWINDOW]) {
3857 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
3858 return -EINVAL;
3859 params.p2p_ctwindow =
3860 nla_get_u8(info->attrs[NL80211_ATTR_P2P_CTWINDOW]);
3861 if (params.p2p_ctwindow > 127)
3862 return -EINVAL;
3863 if (params.p2p_ctwindow != 0 &&
3864 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_CTWIN))
3865 return -EINVAL;
3866 }
3867
3868 if (info->attrs[NL80211_ATTR_P2P_OPPPS]) {
3869 u8 tmp;
3870
3871 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
3872 return -EINVAL;
3873 tmp = nla_get_u8(info->attrs[NL80211_ATTR_P2P_OPPPS]);
3874 if (tmp > 1)
3875 return -EINVAL;
3876 params.p2p_opp_ps = tmp;
3877 if (params.p2p_opp_ps != 0 &&
3878 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_OPPPS))
3879 return -EINVAL;
3880 }
3881
Johannes Bergaa430da2012-05-16 23:50:18 +02003882 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
Johannes Berg683b6d32012-11-08 21:25:48 +01003883 err = nl80211_parse_chandef(rdev, info, &params.chandef);
3884 if (err)
3885 return err;
3886 } else if (wdev->preset_chandef.chan) {
3887 params.chandef = wdev->preset_chandef;
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003888 } else if (!nl80211_get_ap_channel(rdev, &params))
Johannes Bergaa430da2012-05-16 23:50:18 +02003889 return -EINVAL;
3890
Arik Nemtsov923b3522015-07-08 15:41:44 +03003891 if (!cfg80211_reg_can_beacon_relax(&rdev->wiphy, &params.chandef,
3892 wdev->iftype))
Johannes Bergaa430da2012-05-16 23:50:18 +02003893 return -EINVAL;
3894
Purushottam Kushwahaa7c7fbf2016-09-14 17:38:44 +05303895 if (info->attrs[NL80211_ATTR_TX_RATES]) {
3896 err = nl80211_parse_tx_bitrate_mask(info, &params.beacon_rate);
3897 if (err)
3898 return err;
3899
Johannes Berg8564e382016-09-19 09:44:44 +02003900 err = validate_beacon_tx_rate(rdev, params.chandef.chan->band,
3901 &params.beacon_rate);
Purushottam Kushwahaa7c7fbf2016-09-14 17:38:44 +05303902 if (err)
3903 return err;
3904 }
3905
Eliad Peller18998c32014-09-10 14:07:34 +03003906 if (info->attrs[NL80211_ATTR_SMPS_MODE]) {
3907 params.smps_mode =
3908 nla_get_u8(info->attrs[NL80211_ATTR_SMPS_MODE]);
3909 switch (params.smps_mode) {
3910 case NL80211_SMPS_OFF:
3911 break;
3912 case NL80211_SMPS_STATIC:
3913 if (!(rdev->wiphy.features &
3914 NL80211_FEATURE_STATIC_SMPS))
3915 return -EINVAL;
3916 break;
3917 case NL80211_SMPS_DYNAMIC:
3918 if (!(rdev->wiphy.features &
3919 NL80211_FEATURE_DYNAMIC_SMPS))
3920 return -EINVAL;
3921 break;
3922 default:
3923 return -EINVAL;
3924 }
3925 } else {
3926 params.smps_mode = NL80211_SMPS_OFF;
3927 }
3928
Purushottam Kushwaha6e8ef842016-07-05 13:44:51 +05303929 params.pbss = nla_get_flag(info->attrs[NL80211_ATTR_PBSS]);
3930 if (params.pbss && !rdev->wiphy.bands[NL80211_BAND_60GHZ])
3931 return -EOPNOTSUPP;
3932
Ola Olsson4baf6be2015-10-29 07:04:58 +01003933 if (info->attrs[NL80211_ATTR_ACL_POLICY]) {
3934 params.acl = parse_acl_data(&rdev->wiphy, info);
3935 if (IS_ERR(params.acl))
3936 return PTR_ERR(params.acl);
3937 }
3938
Simon Wunderlichc56589e2013-11-21 18:19:49 +01003939 wdev_lock(wdev);
Hila Gonene35e4d22012-06-27 17:19:42 +03003940 err = rdev_start_ap(rdev, dev, &params);
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003941 if (!err) {
Johannes Berg683b6d32012-11-08 21:25:48 +01003942 wdev->preset_chandef = params.chandef;
Johannes Berg88600202012-02-13 15:17:18 +01003943 wdev->beacon_interval = params.beacon_interval;
Michal Kazior9e0e2962014-01-29 14:22:27 +01003944 wdev->chandef = params.chandef;
Antonio Quartulli06e191e2012-11-07 12:52:19 +01003945 wdev->ssid_len = params.ssid_len;
3946 memcpy(wdev->ssid, params.ssid, wdev->ssid_len);
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003947 }
Simon Wunderlichc56589e2013-11-21 18:19:49 +01003948 wdev_unlock(wdev);
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +05303949
3950 kfree(params.acl);
3951
Johannes Berg56d18932011-05-09 18:41:15 +02003952 return err;
Johannes Berged1b6cc2007-12-19 02:03:32 +01003953}
3954
Johannes Berg88600202012-02-13 15:17:18 +01003955static int nl80211_set_beacon(struct sk_buff *skb, struct genl_info *info)
3956{
3957 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3958 struct net_device *dev = info->user_ptr[1];
3959 struct wireless_dev *wdev = dev->ieee80211_ptr;
3960 struct cfg80211_beacon_data params;
3961 int err;
3962
3963 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
3964 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
3965 return -EOPNOTSUPP;
3966
3967 if (!rdev->ops->change_beacon)
3968 return -EOPNOTSUPP;
3969
3970 if (!wdev->beacon_interval)
3971 return -EINVAL;
3972
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003973 err = nl80211_parse_beacon(info->attrs, &params);
Johannes Berg88600202012-02-13 15:17:18 +01003974 if (err)
3975 return err;
3976
Simon Wunderlichc56589e2013-11-21 18:19:49 +01003977 wdev_lock(wdev);
3978 err = rdev_change_beacon(rdev, dev, &params);
3979 wdev_unlock(wdev);
3980
3981 return err;
Johannes Berg88600202012-02-13 15:17:18 +01003982}
3983
3984static int nl80211_stop_ap(struct sk_buff *skb, struct genl_info *info)
Johannes Berged1b6cc2007-12-19 02:03:32 +01003985{
Johannes Berg4c476992010-10-04 21:36:35 +02003986 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3987 struct net_device *dev = info->user_ptr[1];
Johannes Berged1b6cc2007-12-19 02:03:32 +01003988
Ilan Peer7c8d5e02014-02-25 15:33:38 +02003989 return cfg80211_stop_ap(rdev, dev, false);
Johannes Berged1b6cc2007-12-19 02:03:32 +01003990}
3991
Johannes Berg5727ef12007-12-19 02:03:34 +01003992static const struct nla_policy sta_flags_policy[NL80211_STA_FLAG_MAX + 1] = {
3993 [NL80211_STA_FLAG_AUTHORIZED] = { .type = NLA_FLAG },
3994 [NL80211_STA_FLAG_SHORT_PREAMBLE] = { .type = NLA_FLAG },
3995 [NL80211_STA_FLAG_WME] = { .type = NLA_FLAG },
Jouni Malinen0e467242009-05-11 21:57:55 +03003996 [NL80211_STA_FLAG_MFP] = { .type = NLA_FLAG },
Javier Cardonab39c48f2011-04-07 15:08:30 -07003997 [NL80211_STA_FLAG_AUTHENTICATED] = { .type = NLA_FLAG },
Johannes Bergd83023d2011-12-14 09:29:15 +01003998 [NL80211_STA_FLAG_TDLS_PEER] = { .type = NLA_FLAG },
Johannes Berg5727ef12007-12-19 02:03:34 +01003999};
4000
Johannes Bergeccb8e82009-05-11 21:57:56 +03004001static int parse_station_flags(struct genl_info *info,
Johannes Bergbdd3ae32012-01-02 13:30:03 +01004002 enum nl80211_iftype iftype,
Johannes Bergeccb8e82009-05-11 21:57:56 +03004003 struct station_parameters *params)
Johannes Berg5727ef12007-12-19 02:03:34 +01004004{
4005 struct nlattr *flags[NL80211_STA_FLAG_MAX + 1];
Johannes Bergeccb8e82009-05-11 21:57:56 +03004006 struct nlattr *nla;
Johannes Berg5727ef12007-12-19 02:03:34 +01004007 int flag;
4008
Johannes Bergeccb8e82009-05-11 21:57:56 +03004009 /*
4010 * Try parsing the new attribute first so userspace
4011 * can specify both for older kernels.
4012 */
4013 nla = info->attrs[NL80211_ATTR_STA_FLAGS2];
4014 if (nla) {
4015 struct nl80211_sta_flag_update *sta_flags;
Johannes Berg5727ef12007-12-19 02:03:34 +01004016
Johannes Bergeccb8e82009-05-11 21:57:56 +03004017 sta_flags = nla_data(nla);
4018 params->sta_flags_mask = sta_flags->mask;
4019 params->sta_flags_set = sta_flags->set;
Johannes Berg77ee7c82013-02-15 00:48:33 +01004020 params->sta_flags_set &= params->sta_flags_mask;
Johannes Bergeccb8e82009-05-11 21:57:56 +03004021 if ((params->sta_flags_mask |
4022 params->sta_flags_set) & BIT(__NL80211_STA_FLAG_INVALID))
4023 return -EINVAL;
4024 return 0;
4025 }
4026
4027 /* if present, parse the old attribute */
4028
4029 nla = info->attrs[NL80211_ATTR_STA_FLAGS];
Johannes Berg5727ef12007-12-19 02:03:34 +01004030 if (!nla)
4031 return 0;
4032
4033 if (nla_parse_nested(flags, NL80211_STA_FLAG_MAX,
4034 nla, sta_flags_policy))
4035 return -EINVAL;
4036
Johannes Bergbdd3ae32012-01-02 13:30:03 +01004037 /*
4038 * Only allow certain flags for interface types so that
4039 * other attributes are silently ignored. Remember that
4040 * this is backward compatibility code with old userspace
4041 * and shouldn't be hit in other cases anyway.
4042 */
4043 switch (iftype) {
4044 case NL80211_IFTYPE_AP:
4045 case NL80211_IFTYPE_AP_VLAN:
4046 case NL80211_IFTYPE_P2P_GO:
4047 params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) |
4048 BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) |
4049 BIT(NL80211_STA_FLAG_WME) |
4050 BIT(NL80211_STA_FLAG_MFP);
4051 break;
4052 case NL80211_IFTYPE_P2P_CLIENT:
4053 case NL80211_IFTYPE_STATION:
4054 params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) |
4055 BIT(NL80211_STA_FLAG_TDLS_PEER);
4056 break;
4057 case NL80211_IFTYPE_MESH_POINT:
4058 params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHENTICATED) |
4059 BIT(NL80211_STA_FLAG_MFP) |
4060 BIT(NL80211_STA_FLAG_AUTHORIZED);
4061 default:
4062 return -EINVAL;
4063 }
Johannes Berg5727ef12007-12-19 02:03:34 +01004064
Johannes Berg3383b5a2012-05-10 20:14:43 +02004065 for (flag = 1; flag <= NL80211_STA_FLAG_MAX; flag++) {
4066 if (flags[flag]) {
Johannes Bergeccb8e82009-05-11 21:57:56 +03004067 params->sta_flags_set |= (1<<flag);
Johannes Berg5727ef12007-12-19 02:03:34 +01004068
Johannes Berg3383b5a2012-05-10 20:14:43 +02004069 /* no longer support new API additions in old API */
4070 if (flag > NL80211_STA_FLAG_MAX_OLD_API)
4071 return -EINVAL;
4072 }
4073 }
4074
Johannes Berg5727ef12007-12-19 02:03:34 +01004075 return 0;
4076}
4077
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01004078static bool nl80211_put_sta_rate(struct sk_buff *msg, struct rate_info *info,
4079 int attr)
4080{
4081 struct nlattr *rate;
Vladimir Kondratiev8eb41c82012-07-05 14:25:49 +03004082 u32 bitrate;
4083 u16 bitrate_compat;
Johannes Bergb51f3be2015-01-15 16:14:02 +01004084 enum nl80211_attrs rate_flg;
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01004085
4086 rate = nla_nest_start(msg, attr);
4087 if (!rate)
Johannes Bergdb9c64c2012-11-09 14:56:41 +01004088 return false;
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01004089
4090 /* cfg80211_calculate_bitrate will return 0 for mcs >= 32 */
4091 bitrate = cfg80211_calculate_bitrate(info);
Vladimir Kondratiev8eb41c82012-07-05 14:25:49 +03004092 /* report 16-bit bitrate only if we can */
4093 bitrate_compat = bitrate < (1UL << 16) ? bitrate : 0;
Johannes Bergdb9c64c2012-11-09 14:56:41 +01004094 if (bitrate > 0 &&
4095 nla_put_u32(msg, NL80211_RATE_INFO_BITRATE32, bitrate))
4096 return false;
4097 if (bitrate_compat > 0 &&
4098 nla_put_u16(msg, NL80211_RATE_INFO_BITRATE, bitrate_compat))
4099 return false;
4100
Johannes Bergb51f3be2015-01-15 16:14:02 +01004101 switch (info->bw) {
4102 case RATE_INFO_BW_5:
4103 rate_flg = NL80211_RATE_INFO_5_MHZ_WIDTH;
4104 break;
4105 case RATE_INFO_BW_10:
4106 rate_flg = NL80211_RATE_INFO_10_MHZ_WIDTH;
4107 break;
4108 default:
4109 WARN_ON(1);
4110 /* fall through */
4111 case RATE_INFO_BW_20:
4112 rate_flg = 0;
4113 break;
4114 case RATE_INFO_BW_40:
4115 rate_flg = NL80211_RATE_INFO_40_MHZ_WIDTH;
4116 break;
4117 case RATE_INFO_BW_80:
4118 rate_flg = NL80211_RATE_INFO_80_MHZ_WIDTH;
4119 break;
4120 case RATE_INFO_BW_160:
4121 rate_flg = NL80211_RATE_INFO_160_MHZ_WIDTH;
4122 break;
4123 }
4124
4125 if (rate_flg && nla_put_flag(msg, rate_flg))
4126 return false;
4127
Johannes Bergdb9c64c2012-11-09 14:56:41 +01004128 if (info->flags & RATE_INFO_FLAGS_MCS) {
4129 if (nla_put_u8(msg, NL80211_RATE_INFO_MCS, info->mcs))
4130 return false;
Johannes Bergdb9c64c2012-11-09 14:56:41 +01004131 if (info->flags & RATE_INFO_FLAGS_SHORT_GI &&
4132 nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI))
4133 return false;
4134 } else if (info->flags & RATE_INFO_FLAGS_VHT_MCS) {
4135 if (nla_put_u8(msg, NL80211_RATE_INFO_VHT_MCS, info->mcs))
4136 return false;
4137 if (nla_put_u8(msg, NL80211_RATE_INFO_VHT_NSS, info->nss))
4138 return false;
Johannes Bergdb9c64c2012-11-09 14:56:41 +01004139 if (info->flags & RATE_INFO_FLAGS_SHORT_GI &&
4140 nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI))
4141 return false;
4142 }
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01004143
4144 nla_nest_end(msg, rate);
4145 return true;
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01004146}
4147
Felix Fietkau119363c2013-04-22 16:29:30 +02004148static bool nl80211_put_signal(struct sk_buff *msg, u8 mask, s8 *signal,
4149 int id)
4150{
4151 void *attr;
4152 int i = 0;
4153
4154 if (!mask)
4155 return true;
4156
4157 attr = nla_nest_start(msg, id);
4158 if (!attr)
4159 return false;
4160
4161 for (i = 0; i < IEEE80211_MAX_CHAINS; i++) {
4162 if (!(mask & BIT(i)))
4163 continue;
4164
4165 if (nla_put_u8(msg, i, signal[i]))
4166 return false;
4167 }
4168
4169 nla_nest_end(msg, attr);
4170
4171 return true;
4172}
4173
Johannes Bergcf5ead82014-11-14 17:14:00 +01004174static int nl80211_send_station(struct sk_buff *msg, u32 cmd, u32 portid,
4175 u32 seq, int flags,
John W. Linville66266b32012-03-15 13:25:41 -04004176 struct cfg80211_registered_device *rdev,
4177 struct net_device *dev,
Johannes Berg98b62182009-12-23 13:15:44 +01004178 const u8 *mac_addr, struct station_info *sinfo)
Johannes Bergfd5b74d2007-12-19 02:03:36 +01004179{
4180 void *hdr;
Paul Stewartf4263c92011-03-31 09:25:41 -07004181 struct nlattr *sinfoattr, *bss_param;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01004182
Johannes Bergcf5ead82014-11-14 17:14:00 +01004183 hdr = nl80211hdr_put(msg, portid, seq, flags, cmd);
Johannes Bergfd5b74d2007-12-19 02:03:36 +01004184 if (!hdr)
4185 return -1;
4186
David S. Miller9360ffd2012-03-29 04:41:26 -04004187 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
4188 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) ||
4189 nla_put_u32(msg, NL80211_ATTR_GENERATION, sinfo->generation))
4190 goto nla_put_failure;
Johannes Bergf5ea9122009-08-07 16:17:38 +02004191
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004192 sinfoattr = nla_nest_start(msg, NL80211_ATTR_STA_INFO);
4193 if (!sinfoattr)
Johannes Bergfd5b74d2007-12-19 02:03:36 +01004194 goto nla_put_failure;
Johannes Berg319090b2014-11-17 14:08:11 +01004195
4196#define PUT_SINFO(attr, memb, type) do { \
Johannes Bergd686b922016-04-26 09:54:11 +02004197 BUILD_BUG_ON(sizeof(type) == sizeof(u64)); \
Mohammed Shafi Shajakhan739960f2016-04-07 19:59:34 +05304198 if (sinfo->filled & (1ULL << NL80211_STA_INFO_ ## attr) && \
Johannes Berg319090b2014-11-17 14:08:11 +01004199 nla_put_ ## type(msg, NL80211_STA_INFO_ ## attr, \
4200 sinfo->memb)) \
4201 goto nla_put_failure; \
4202 } while (0)
Johannes Bergd686b922016-04-26 09:54:11 +02004203#define PUT_SINFO_U64(attr, memb) do { \
4204 if (sinfo->filled & (1ULL << NL80211_STA_INFO_ ## attr) && \
4205 nla_put_u64_64bit(msg, NL80211_STA_INFO_ ## attr, \
4206 sinfo->memb, NL80211_STA_INFO_PAD)) \
4207 goto nla_put_failure; \
4208 } while (0)
Johannes Berg319090b2014-11-17 14:08:11 +01004209
4210 PUT_SINFO(CONNECTED_TIME, connected_time, u32);
4211 PUT_SINFO(INACTIVE_TIME, inactive_time, u32);
4212
4213 if (sinfo->filled & (BIT(NL80211_STA_INFO_RX_BYTES) |
4214 BIT(NL80211_STA_INFO_RX_BYTES64)) &&
David S. Miller9360ffd2012-03-29 04:41:26 -04004215 nla_put_u32(msg, NL80211_STA_INFO_RX_BYTES,
Vladimir Kondratiev42745e02013-02-04 13:53:11 +02004216 (u32)sinfo->rx_bytes))
4217 goto nla_put_failure;
Johannes Berg319090b2014-11-17 14:08:11 +01004218
4219 if (sinfo->filled & (BIT(NL80211_STA_INFO_TX_BYTES) |
4220 BIT(NL80211_STA_INFO_TX_BYTES64)) &&
Vladimir Kondratiev42745e02013-02-04 13:53:11 +02004221 nla_put_u32(msg, NL80211_STA_INFO_TX_BYTES,
4222 (u32)sinfo->tx_bytes))
4223 goto nla_put_failure;
Johannes Berg319090b2014-11-17 14:08:11 +01004224
Johannes Bergd686b922016-04-26 09:54:11 +02004225 PUT_SINFO_U64(RX_BYTES64, rx_bytes);
4226 PUT_SINFO_U64(TX_BYTES64, tx_bytes);
Johannes Berg319090b2014-11-17 14:08:11 +01004227 PUT_SINFO(LLID, llid, u16);
4228 PUT_SINFO(PLID, plid, u16);
4229 PUT_SINFO(PLINK_STATE, plink_state, u8);
Johannes Bergd686b922016-04-26 09:54:11 +02004230 PUT_SINFO_U64(RX_DURATION, rx_duration);
Johannes Berg319090b2014-11-17 14:08:11 +01004231
John W. Linville66266b32012-03-15 13:25:41 -04004232 switch (rdev->wiphy.signal_type) {
4233 case CFG80211_SIGNAL_TYPE_MBM:
Johannes Berg319090b2014-11-17 14:08:11 +01004234 PUT_SINFO(SIGNAL, signal, u8);
4235 PUT_SINFO(SIGNAL_AVG, signal_avg, u8);
John W. Linville66266b32012-03-15 13:25:41 -04004236 break;
4237 default:
4238 break;
4239 }
Johannes Berg319090b2014-11-17 14:08:11 +01004240 if (sinfo->filled & BIT(NL80211_STA_INFO_CHAIN_SIGNAL)) {
Felix Fietkau119363c2013-04-22 16:29:30 +02004241 if (!nl80211_put_signal(msg, sinfo->chains,
4242 sinfo->chain_signal,
4243 NL80211_STA_INFO_CHAIN_SIGNAL))
4244 goto nla_put_failure;
4245 }
Johannes Berg319090b2014-11-17 14:08:11 +01004246 if (sinfo->filled & BIT(NL80211_STA_INFO_CHAIN_SIGNAL_AVG)) {
Felix Fietkau119363c2013-04-22 16:29:30 +02004247 if (!nl80211_put_signal(msg, sinfo->chains,
4248 sinfo->chain_signal_avg,
4249 NL80211_STA_INFO_CHAIN_SIGNAL_AVG))
4250 goto nla_put_failure;
4251 }
Johannes Berg319090b2014-11-17 14:08:11 +01004252 if (sinfo->filled & BIT(NL80211_STA_INFO_TX_BITRATE)) {
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01004253 if (!nl80211_put_sta_rate(msg, &sinfo->txrate,
4254 NL80211_STA_INFO_TX_BITRATE))
Henning Rogge420e7fa2008-12-11 22:04:19 +01004255 goto nla_put_failure;
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01004256 }
Johannes Berg319090b2014-11-17 14:08:11 +01004257 if (sinfo->filled & BIT(NL80211_STA_INFO_RX_BITRATE)) {
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01004258 if (!nl80211_put_sta_rate(msg, &sinfo->rxrate,
4259 NL80211_STA_INFO_RX_BITRATE))
4260 goto nla_put_failure;
Henning Rogge420e7fa2008-12-11 22:04:19 +01004261 }
Johannes Berg319090b2014-11-17 14:08:11 +01004262
4263 PUT_SINFO(RX_PACKETS, rx_packets, u32);
4264 PUT_SINFO(TX_PACKETS, tx_packets, u32);
4265 PUT_SINFO(TX_RETRIES, tx_retries, u32);
4266 PUT_SINFO(TX_FAILED, tx_failed, u32);
4267 PUT_SINFO(EXPECTED_THROUGHPUT, expected_throughput, u32);
4268 PUT_SINFO(BEACON_LOSS, beacon_loss_count, u32);
4269 PUT_SINFO(LOCAL_PM, local_pm, u32);
4270 PUT_SINFO(PEER_PM, peer_pm, u32);
4271 PUT_SINFO(NONPEER_PM, nonpeer_pm, u32);
4272
4273 if (sinfo->filled & BIT(NL80211_STA_INFO_BSS_PARAM)) {
Paul Stewartf4263c92011-03-31 09:25:41 -07004274 bss_param = nla_nest_start(msg, NL80211_STA_INFO_BSS_PARAM);
4275 if (!bss_param)
4276 goto nla_put_failure;
4277
David S. Miller9360ffd2012-03-29 04:41:26 -04004278 if (((sinfo->bss_param.flags & BSS_PARAM_FLAGS_CTS_PROT) &&
4279 nla_put_flag(msg, NL80211_STA_BSS_PARAM_CTS_PROT)) ||
4280 ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_PREAMBLE) &&
4281 nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_PREAMBLE)) ||
4282 ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_SLOT_TIME) &&
4283 nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_SLOT_TIME)) ||
4284 nla_put_u8(msg, NL80211_STA_BSS_PARAM_DTIM_PERIOD,
4285 sinfo->bss_param.dtim_period) ||
4286 nla_put_u16(msg, NL80211_STA_BSS_PARAM_BEACON_INTERVAL,
4287 sinfo->bss_param.beacon_interval))
4288 goto nla_put_failure;
Paul Stewartf4263c92011-03-31 09:25:41 -07004289
4290 nla_nest_end(msg, bss_param);
4291 }
Johannes Berg319090b2014-11-17 14:08:11 +01004292 if ((sinfo->filled & BIT(NL80211_STA_INFO_STA_FLAGS)) &&
David S. Miller9360ffd2012-03-29 04:41:26 -04004293 nla_put(msg, NL80211_STA_INFO_STA_FLAGS,
4294 sizeof(struct nl80211_sta_flag_update),
4295 &sinfo->sta_flags))
4296 goto nla_put_failure;
Johannes Berg319090b2014-11-17 14:08:11 +01004297
Johannes Bergd686b922016-04-26 09:54:11 +02004298 PUT_SINFO_U64(T_OFFSET, t_offset);
4299 PUT_SINFO_U64(RX_DROP_MISC, rx_dropped_misc);
4300 PUT_SINFO_U64(BEACON_RX, rx_beacon);
Johannes Berga76b1942014-11-17 14:12:22 +01004301 PUT_SINFO(BEACON_SIGNAL_AVG, rx_beacon_signal_avg, u8);
Johannes Berg319090b2014-11-17 14:08:11 +01004302
4303#undef PUT_SINFO
Johannes Bergd686b922016-04-26 09:54:11 +02004304#undef PUT_SINFO_U64
Johannes Berg6de39802014-12-19 12:34:00 +01004305
4306 if (sinfo->filled & BIT(NL80211_STA_INFO_TID_STATS)) {
4307 struct nlattr *tidsattr;
4308 int tid;
4309
4310 tidsattr = nla_nest_start(msg, NL80211_STA_INFO_TID_STATS);
4311 if (!tidsattr)
4312 goto nla_put_failure;
4313
4314 for (tid = 0; tid < IEEE80211_NUM_TIDS + 1; tid++) {
4315 struct cfg80211_tid_stats *tidstats;
4316 struct nlattr *tidattr;
4317
4318 tidstats = &sinfo->pertid[tid];
4319
4320 if (!tidstats->filled)
4321 continue;
4322
4323 tidattr = nla_nest_start(msg, tid + 1);
4324 if (!tidattr)
4325 goto nla_put_failure;
4326
Johannes Bergd686b922016-04-26 09:54:11 +02004327#define PUT_TIDVAL_U64(attr, memb) do { \
Johannes Berg6de39802014-12-19 12:34:00 +01004328 if (tidstats->filled & BIT(NL80211_TID_STATS_ ## attr) && \
Johannes Bergd686b922016-04-26 09:54:11 +02004329 nla_put_u64_64bit(msg, NL80211_TID_STATS_ ## attr, \
4330 tidstats->memb, NL80211_TID_STATS_PAD)) \
Johannes Berg6de39802014-12-19 12:34:00 +01004331 goto nla_put_failure; \
4332 } while (0)
4333
Johannes Bergd686b922016-04-26 09:54:11 +02004334 PUT_TIDVAL_U64(RX_MSDU, rx_msdu);
4335 PUT_TIDVAL_U64(TX_MSDU, tx_msdu);
4336 PUT_TIDVAL_U64(TX_MSDU_RETRIES, tx_msdu_retries);
4337 PUT_TIDVAL_U64(TX_MSDU_FAILED, tx_msdu_failed);
Johannes Berg6de39802014-12-19 12:34:00 +01004338
Johannes Bergd686b922016-04-26 09:54:11 +02004339#undef PUT_TIDVAL_U64
Johannes Berg6de39802014-12-19 12:34:00 +01004340 nla_nest_end(msg, tidattr);
4341 }
4342
4343 nla_nest_end(msg, tidsattr);
4344 }
4345
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004346 nla_nest_end(msg, sinfoattr);
Johannes Bergfd5b74d2007-12-19 02:03:36 +01004347
Johannes Berg319090b2014-11-17 14:08:11 +01004348 if (sinfo->assoc_req_ies_len &&
David S. Miller9360ffd2012-03-29 04:41:26 -04004349 nla_put(msg, NL80211_ATTR_IE, sinfo->assoc_req_ies_len,
4350 sinfo->assoc_req_ies))
4351 goto nla_put_failure;
Jouni Malinen50d3dfb2011-08-08 12:11:52 +03004352
Johannes Berg053c0952015-01-16 22:09:00 +01004353 genlmsg_end(msg, hdr);
4354 return 0;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01004355
4356 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07004357 genlmsg_cancel(msg, hdr);
4358 return -EMSGSIZE;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01004359}
4360
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004361static int nl80211_dump_station(struct sk_buff *skb,
Johannes Bergbba95fe2008-07-29 13:22:51 +02004362 struct netlink_callback *cb)
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004363{
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004364 struct station_info sinfo;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08004365 struct cfg80211_registered_device *rdev;
Johannes Berg97990a02013-04-19 01:02:55 +02004366 struct wireless_dev *wdev;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004367 u8 mac_addr[ETH_ALEN];
Johannes Berg97990a02013-04-19 01:02:55 +02004368 int sta_idx = cb->args[2];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004369 int err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004370
Zhao, Gang1b8ec872014-04-21 12:53:02 +08004371 err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev);
Johannes Berg67748892010-10-04 21:14:06 +02004372 if (err)
4373 return err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004374
Johannes Berg97990a02013-04-19 01:02:55 +02004375 if (!wdev->netdev) {
4376 err = -EINVAL;
4377 goto out_err;
4378 }
4379
Zhao, Gang1b8ec872014-04-21 12:53:02 +08004380 if (!rdev->ops->dump_station) {
Jouni Malineneec60b02009-03-20 21:21:19 +02004381 err = -EOPNOTSUPP;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004382 goto out_err;
4383 }
4384
Johannes Bergbba95fe2008-07-29 13:22:51 +02004385 while (1) {
Jouni Malinenf612ced2011-08-11 11:46:22 +03004386 memset(&sinfo, 0, sizeof(sinfo));
Zhao, Gang1b8ec872014-04-21 12:53:02 +08004387 err = rdev_dump_station(rdev, wdev->netdev, sta_idx,
Hila Gonene35e4d22012-06-27 17:19:42 +03004388 mac_addr, &sinfo);
Johannes Bergbba95fe2008-07-29 13:22:51 +02004389 if (err == -ENOENT)
4390 break;
4391 if (err)
Johannes Berg3b858752009-03-12 09:55:09 +01004392 goto out_err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004393
Johannes Bergcf5ead82014-11-14 17:14:00 +01004394 if (nl80211_send_station(skb, NL80211_CMD_NEW_STATION,
Eric W. Biederman15e47302012-09-07 20:12:54 +00004395 NETLINK_CB(cb->skb).portid,
Johannes Bergbba95fe2008-07-29 13:22:51 +02004396 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08004397 rdev, wdev->netdev, mac_addr,
Johannes Bergbba95fe2008-07-29 13:22:51 +02004398 &sinfo) < 0)
4399 goto out;
4400
4401 sta_idx++;
4402 }
4403
Johannes Bergbba95fe2008-07-29 13:22:51 +02004404 out:
Johannes Berg97990a02013-04-19 01:02:55 +02004405 cb->args[2] = sta_idx;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004406 err = skb->len;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004407 out_err:
Zhao, Gang1b8ec872014-04-21 12:53:02 +08004408 nl80211_finish_wdev_dump(rdev);
Johannes Bergbba95fe2008-07-29 13:22:51 +02004409
4410 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004411}
Johannes Bergfd5b74d2007-12-19 02:03:36 +01004412
Johannes Berg5727ef12007-12-19 02:03:34 +01004413static int nl80211_get_station(struct sk_buff *skb, struct genl_info *info)
4414{
Johannes Berg4c476992010-10-04 21:36:35 +02004415 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4416 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004417 struct station_info sinfo;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01004418 struct sk_buff *msg;
4419 u8 *mac_addr = NULL;
Johannes Berg4c476992010-10-04 21:36:35 +02004420 int err;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01004421
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004422 memset(&sinfo, 0, sizeof(sinfo));
Johannes Bergfd5b74d2007-12-19 02:03:36 +01004423
4424 if (!info->attrs[NL80211_ATTR_MAC])
4425 return -EINVAL;
4426
4427 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
4428
Johannes Berg4c476992010-10-04 21:36:35 +02004429 if (!rdev->ops->get_station)
4430 return -EOPNOTSUPP;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01004431
Hila Gonene35e4d22012-06-27 17:19:42 +03004432 err = rdev_get_station(rdev, dev, mac_addr, &sinfo);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004433 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02004434 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004435
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07004436 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Bergfd5b74d2007-12-19 02:03:36 +01004437 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02004438 return -ENOMEM;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01004439
Johannes Bergcf5ead82014-11-14 17:14:00 +01004440 if (nl80211_send_station(msg, NL80211_CMD_NEW_STATION,
4441 info->snd_portid, info->snd_seq, 0,
John W. Linville66266b32012-03-15 13:25:41 -04004442 rdev, dev, mac_addr, &sinfo) < 0) {
Johannes Berg4c476992010-10-04 21:36:35 +02004443 nlmsg_free(msg);
4444 return -ENOBUFS;
4445 }
Johannes Bergfd5b74d2007-12-19 02:03:36 +01004446
Johannes Berg4c476992010-10-04 21:36:35 +02004447 return genlmsg_reply(msg, info);
Johannes Berg5727ef12007-12-19 02:03:34 +01004448}
4449
Johannes Berg77ee7c82013-02-15 00:48:33 +01004450int cfg80211_check_station_change(struct wiphy *wiphy,
4451 struct station_parameters *params,
4452 enum cfg80211_station_type statype)
4453{
Ayala Bekere4208422015-10-23 11:20:06 +03004454 if (params->listen_interval != -1 &&
4455 statype != CFG80211_STA_AP_CLIENT_UNASSOC)
Johannes Berg77ee7c82013-02-15 00:48:33 +01004456 return -EINVAL;
Ayala Bekere4208422015-10-23 11:20:06 +03004457
Ayala Beker17b94242016-03-17 15:41:38 +02004458 if (params->support_p2p_ps != -1 &&
4459 statype != CFG80211_STA_AP_CLIENT_UNASSOC)
4460 return -EINVAL;
4461
Arik Nemtsovc72e1142014-07-17 17:14:29 +03004462 if (params->aid &&
Ayala Bekere4208422015-10-23 11:20:06 +03004463 !(params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) &&
4464 statype != CFG80211_STA_AP_CLIENT_UNASSOC)
Johannes Berg77ee7c82013-02-15 00:48:33 +01004465 return -EINVAL;
4466
4467 /* When you run into this, adjust the code below for the new flag */
4468 BUILD_BUG_ON(NL80211_STA_FLAG_MAX != 7);
4469
4470 switch (statype) {
Thomas Pederseneef941e2013-03-04 13:06:11 -08004471 case CFG80211_STA_MESH_PEER_KERNEL:
4472 case CFG80211_STA_MESH_PEER_USER:
Johannes Berg77ee7c82013-02-15 00:48:33 +01004473 /*
4474 * No ignoring the TDLS flag here -- the userspace mesh
4475 * code doesn't have the bug of including TDLS in the
4476 * mask everywhere.
4477 */
4478 if (params->sta_flags_mask &
4479 ~(BIT(NL80211_STA_FLAG_AUTHENTICATED) |
4480 BIT(NL80211_STA_FLAG_MFP) |
4481 BIT(NL80211_STA_FLAG_AUTHORIZED)))
4482 return -EINVAL;
4483 break;
4484 case CFG80211_STA_TDLS_PEER_SETUP:
4485 case CFG80211_STA_TDLS_PEER_ACTIVE:
4486 if (!(params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)))
4487 return -EINVAL;
4488 /* ignore since it can't change */
4489 params->sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER);
4490 break;
4491 default:
4492 /* disallow mesh-specific things */
4493 if (params->plink_action != NL80211_PLINK_ACTION_NO_ACTION)
4494 return -EINVAL;
4495 if (params->local_pm)
4496 return -EINVAL;
4497 if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE)
4498 return -EINVAL;
4499 }
4500
4501 if (statype != CFG80211_STA_TDLS_PEER_SETUP &&
4502 statype != CFG80211_STA_TDLS_PEER_ACTIVE) {
4503 /* TDLS can't be set, ... */
4504 if (params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))
4505 return -EINVAL;
4506 /*
4507 * ... but don't bother the driver with it. This works around
4508 * a hostapd/wpa_supplicant issue -- it always includes the
4509 * TLDS_PEER flag in the mask even for AP mode.
4510 */
4511 params->sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER);
4512 }
4513
Ayala Beker47edb112015-09-21 15:49:53 +03004514 if (statype != CFG80211_STA_TDLS_PEER_SETUP &&
4515 statype != CFG80211_STA_AP_CLIENT_UNASSOC) {
Johannes Berg77ee7c82013-02-15 00:48:33 +01004516 /* reject other things that can't change */
4517 if (params->sta_modify_mask & STATION_PARAM_APPLY_UAPSD)
4518 return -EINVAL;
4519 if (params->sta_modify_mask & STATION_PARAM_APPLY_CAPABILITY)
4520 return -EINVAL;
4521 if (params->supported_rates)
4522 return -EINVAL;
4523 if (params->ext_capab || params->ht_capa || params->vht_capa)
4524 return -EINVAL;
4525 }
4526
Ayala Beker47edb112015-09-21 15:49:53 +03004527 if (statype != CFG80211_STA_AP_CLIENT &&
4528 statype != CFG80211_STA_AP_CLIENT_UNASSOC) {
Johannes Berg77ee7c82013-02-15 00:48:33 +01004529 if (params->vlan)
4530 return -EINVAL;
4531 }
4532
4533 switch (statype) {
4534 case CFG80211_STA_AP_MLME_CLIENT:
4535 /* Use this only for authorizing/unauthorizing a station */
4536 if (!(params->sta_flags_mask & BIT(NL80211_STA_FLAG_AUTHORIZED)))
4537 return -EOPNOTSUPP;
4538 break;
4539 case CFG80211_STA_AP_CLIENT:
Ayala Beker47edb112015-09-21 15:49:53 +03004540 case CFG80211_STA_AP_CLIENT_UNASSOC:
Johannes Berg77ee7c82013-02-15 00:48:33 +01004541 /* accept only the listed bits */
4542 if (params->sta_flags_mask &
4543 ~(BIT(NL80211_STA_FLAG_AUTHORIZED) |
4544 BIT(NL80211_STA_FLAG_AUTHENTICATED) |
4545 BIT(NL80211_STA_FLAG_ASSOCIATED) |
4546 BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) |
4547 BIT(NL80211_STA_FLAG_WME) |
4548 BIT(NL80211_STA_FLAG_MFP)))
4549 return -EINVAL;
4550
4551 /* but authenticated/associated only if driver handles it */
4552 if (!(wiphy->features & NL80211_FEATURE_FULL_AP_CLIENT_STATE) &&
4553 params->sta_flags_mask &
4554 (BIT(NL80211_STA_FLAG_AUTHENTICATED) |
4555 BIT(NL80211_STA_FLAG_ASSOCIATED)))
4556 return -EINVAL;
4557 break;
4558 case CFG80211_STA_IBSS:
4559 case CFG80211_STA_AP_STA:
4560 /* reject any changes other than AUTHORIZED */
4561 if (params->sta_flags_mask & ~BIT(NL80211_STA_FLAG_AUTHORIZED))
4562 return -EINVAL;
4563 break;
4564 case CFG80211_STA_TDLS_PEER_SETUP:
4565 /* reject any changes other than AUTHORIZED or WME */
4566 if (params->sta_flags_mask & ~(BIT(NL80211_STA_FLAG_AUTHORIZED) |
4567 BIT(NL80211_STA_FLAG_WME)))
4568 return -EINVAL;
4569 /* force (at least) rates when authorizing */
4570 if (params->sta_flags_set & BIT(NL80211_STA_FLAG_AUTHORIZED) &&
4571 !params->supported_rates)
4572 return -EINVAL;
4573 break;
4574 case CFG80211_STA_TDLS_PEER_ACTIVE:
4575 /* reject any changes */
4576 return -EINVAL;
Thomas Pederseneef941e2013-03-04 13:06:11 -08004577 case CFG80211_STA_MESH_PEER_KERNEL:
Johannes Berg77ee7c82013-02-15 00:48:33 +01004578 if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE)
4579 return -EINVAL;
4580 break;
Thomas Pederseneef941e2013-03-04 13:06:11 -08004581 case CFG80211_STA_MESH_PEER_USER:
Chun-Yeow Yeoh42925042015-04-18 01:30:02 +08004582 if (params->plink_action != NL80211_PLINK_ACTION_NO_ACTION &&
4583 params->plink_action != NL80211_PLINK_ACTION_BLOCK)
Johannes Berg77ee7c82013-02-15 00:48:33 +01004584 return -EINVAL;
4585 break;
4586 }
4587
4588 return 0;
4589}
4590EXPORT_SYMBOL(cfg80211_check_station_change);
4591
Johannes Berg5727ef12007-12-19 02:03:34 +01004592/*
Felix Fietkauc258d2d2009-11-11 17:23:31 +01004593 * Get vlan interface making sure it is running and on the right wiphy.
Johannes Berg5727ef12007-12-19 02:03:34 +01004594 */
Johannes Berg80b99892011-11-18 16:23:01 +01004595static struct net_device *get_vlan(struct genl_info *info,
4596 struct cfg80211_registered_device *rdev)
Johannes Berg5727ef12007-12-19 02:03:34 +01004597{
Johannes Berg463d0182009-07-14 00:33:35 +02004598 struct nlattr *vlanattr = info->attrs[NL80211_ATTR_STA_VLAN];
Johannes Berg80b99892011-11-18 16:23:01 +01004599 struct net_device *v;
4600 int ret;
Johannes Berg5727ef12007-12-19 02:03:34 +01004601
Johannes Berg80b99892011-11-18 16:23:01 +01004602 if (!vlanattr)
4603 return NULL;
4604
4605 v = dev_get_by_index(genl_info_net(info), nla_get_u32(vlanattr));
4606 if (!v)
4607 return ERR_PTR(-ENODEV);
4608
4609 if (!v->ieee80211_ptr || v->ieee80211_ptr->wiphy != &rdev->wiphy) {
4610 ret = -EINVAL;
4611 goto error;
Johannes Berg5727ef12007-12-19 02:03:34 +01004612 }
Johannes Berg80b99892011-11-18 16:23:01 +01004613
Johannes Berg77ee7c82013-02-15 00:48:33 +01004614 if (v->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN &&
4615 v->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
4616 v->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) {
4617 ret = -EINVAL;
4618 goto error;
4619 }
4620
Johannes Berg80b99892011-11-18 16:23:01 +01004621 if (!netif_running(v)) {
4622 ret = -ENETDOWN;
4623 goto error;
4624 }
4625
4626 return v;
4627 error:
4628 dev_put(v);
4629 return ERR_PTR(ret);
Johannes Berg5727ef12007-12-19 02:03:34 +01004630}
4631
Johannes Berg94e860f2014-01-20 23:58:15 +01004632static const struct nla_policy
4633nl80211_sta_wme_policy[NL80211_STA_WME_MAX + 1] = {
Jouni Malinendf881292013-02-14 21:10:54 +02004634 [NL80211_STA_WME_UAPSD_QUEUES] = { .type = NLA_U8 },
4635 [NL80211_STA_WME_MAX_SP] = { .type = NLA_U8 },
4636};
4637
Johannes Bergff276692013-02-15 00:09:01 +01004638static int nl80211_parse_sta_wme(struct genl_info *info,
4639 struct station_parameters *params)
Jouni Malinendf881292013-02-14 21:10:54 +02004640{
Jouni Malinendf881292013-02-14 21:10:54 +02004641 struct nlattr *tb[NL80211_STA_WME_MAX + 1];
4642 struct nlattr *nla;
4643 int err;
4644
Jouni Malinendf881292013-02-14 21:10:54 +02004645 /* parse WME attributes if present */
4646 if (!info->attrs[NL80211_ATTR_STA_WME])
4647 return 0;
4648
4649 nla = info->attrs[NL80211_ATTR_STA_WME];
4650 err = nla_parse_nested(tb, NL80211_STA_WME_MAX, nla,
4651 nl80211_sta_wme_policy);
4652 if (err)
4653 return err;
4654
4655 if (tb[NL80211_STA_WME_UAPSD_QUEUES])
4656 params->uapsd_queues = nla_get_u8(
4657 tb[NL80211_STA_WME_UAPSD_QUEUES]);
4658 if (params->uapsd_queues & ~IEEE80211_WMM_IE_STA_QOSINFO_AC_MASK)
4659 return -EINVAL;
4660
4661 if (tb[NL80211_STA_WME_MAX_SP])
4662 params->max_sp = nla_get_u8(tb[NL80211_STA_WME_MAX_SP]);
4663
4664 if (params->max_sp & ~IEEE80211_WMM_IE_STA_QOSINFO_SP_MASK)
4665 return -EINVAL;
4666
4667 params->sta_modify_mask |= STATION_PARAM_APPLY_UAPSD;
4668
4669 return 0;
4670}
4671
Sunil Duttc01fc9a2013-10-09 20:45:21 +05304672static int nl80211_parse_sta_channel_info(struct genl_info *info,
4673 struct station_parameters *params)
4674{
4675 if (info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]) {
4676 params->supported_channels =
4677 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]);
4678 params->supported_channels_len =
4679 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]);
4680 /*
4681 * Need to include at least one (first channel, number of
4682 * channels) tuple for each subband, and must have proper
4683 * tuples for the rest of the data as well.
4684 */
4685 if (params->supported_channels_len < 2)
4686 return -EINVAL;
4687 if (params->supported_channels_len % 2)
4688 return -EINVAL;
4689 }
4690
4691 if (info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]) {
4692 params->supported_oper_classes =
4693 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]);
4694 params->supported_oper_classes_len =
4695 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]);
4696 /*
4697 * The value of the Length field of the Supported Operating
4698 * Classes element is between 2 and 253.
4699 */
4700 if (params->supported_oper_classes_len < 2 ||
4701 params->supported_oper_classes_len > 253)
4702 return -EINVAL;
4703 }
4704 return 0;
4705}
4706
Johannes Bergff276692013-02-15 00:09:01 +01004707static int nl80211_set_station_tdls(struct genl_info *info,
4708 struct station_parameters *params)
4709{
Sunil Duttc01fc9a2013-10-09 20:45:21 +05304710 int err;
Johannes Bergff276692013-02-15 00:09:01 +01004711 /* Dummy STA entry gets updated once the peer capabilities are known */
Jouni Malinen5e4b6f52013-05-16 20:11:08 +03004712 if (info->attrs[NL80211_ATTR_PEER_AID])
4713 params->aid = nla_get_u16(info->attrs[NL80211_ATTR_PEER_AID]);
Johannes Bergff276692013-02-15 00:09:01 +01004714 if (info->attrs[NL80211_ATTR_HT_CAPABILITY])
4715 params->ht_capa =
4716 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]);
4717 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY])
4718 params->vht_capa =
4719 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]);
4720
Sunil Duttc01fc9a2013-10-09 20:45:21 +05304721 err = nl80211_parse_sta_channel_info(info, params);
4722 if (err)
4723 return err;
4724
Johannes Bergff276692013-02-15 00:09:01 +01004725 return nl80211_parse_sta_wme(info, params);
4726}
4727
Johannes Berg5727ef12007-12-19 02:03:34 +01004728static int nl80211_set_station(struct sk_buff *skb, struct genl_info *info)
4729{
Johannes Berg4c476992010-10-04 21:36:35 +02004730 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg4c476992010-10-04 21:36:35 +02004731 struct net_device *dev = info->user_ptr[1];
Johannes Berg5727ef12007-12-19 02:03:34 +01004732 struct station_parameters params;
Johannes Berg77ee7c82013-02-15 00:48:33 +01004733 u8 *mac_addr;
4734 int err;
Johannes Berg5727ef12007-12-19 02:03:34 +01004735
4736 memset(&params, 0, sizeof(params));
4737
Johannes Berg77ee7c82013-02-15 00:48:33 +01004738 if (!rdev->ops->change_station)
4739 return -EOPNOTSUPP;
4740
Ayala Bekere4208422015-10-23 11:20:06 +03004741 /*
4742 * AID and listen_interval properties can be set only for unassociated
4743 * station. Include these parameters here and will check them in
4744 * cfg80211_check_station_change().
4745 */
Ayala Bekera9bc31e2015-11-26 16:26:12 +01004746 if (info->attrs[NL80211_ATTR_STA_AID])
4747 params.aid = nla_get_u16(info->attrs[NL80211_ATTR_STA_AID]);
Ayala Bekere4208422015-10-23 11:20:06 +03004748
4749 if (info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL])
4750 params.listen_interval =
4751 nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]);
4752 else
4753 params.listen_interval = -1;
Johannes Berg5727ef12007-12-19 02:03:34 +01004754
Ayala Beker17b94242016-03-17 15:41:38 +02004755 if (info->attrs[NL80211_ATTR_STA_SUPPORT_P2P_PS]) {
4756 u8 tmp;
4757
4758 tmp = nla_get_u8(info->attrs[NL80211_ATTR_STA_SUPPORT_P2P_PS]);
4759 if (tmp >= NUM_NL80211_P2P_PS_STATUS)
4760 return -EINVAL;
4761
4762 params.support_p2p_ps = tmp;
4763 } else {
4764 params.support_p2p_ps = -1;
4765 }
4766
Johannes Berg5727ef12007-12-19 02:03:34 +01004767 if (!info->attrs[NL80211_ATTR_MAC])
4768 return -EINVAL;
4769
4770 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
4771
4772 if (info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) {
4773 params.supported_rates =
4774 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
4775 params.supported_rates_len =
4776 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
4777 }
4778
Jouni Malinen9d62a982013-02-14 21:10:13 +02004779 if (info->attrs[NL80211_ATTR_STA_CAPABILITY]) {
4780 params.capability =
4781 nla_get_u16(info->attrs[NL80211_ATTR_STA_CAPABILITY]);
4782 params.sta_modify_mask |= STATION_PARAM_APPLY_CAPABILITY;
4783 }
4784
4785 if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]) {
4786 params.ext_capab =
4787 nla_data(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
4788 params.ext_capab_len =
4789 nla_len(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
4790 }
4791
Johannes Bergbdd3ae32012-01-02 13:30:03 +01004792 if (parse_station_flags(info, dev->ieee80211_ptr->iftype, &params))
Johannes Berg5727ef12007-12-19 02:03:34 +01004793 return -EINVAL;
4794
Johannes Bergf8bacc22013-02-14 23:27:01 +01004795 if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) {
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004796 params.plink_action =
Johannes Bergf8bacc22013-02-14 23:27:01 +01004797 nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]);
4798 if (params.plink_action >= NUM_NL80211_PLINK_ACTIONS)
4799 return -EINVAL;
4800 }
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004801
Johannes Bergf8bacc22013-02-14 23:27:01 +01004802 if (info->attrs[NL80211_ATTR_STA_PLINK_STATE]) {
Javier Cardona9c3990a2011-05-03 16:57:11 -07004803 params.plink_state =
Johannes Bergf8bacc22013-02-14 23:27:01 +01004804 nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_STATE]);
4805 if (params.plink_state >= NUM_NL80211_PLINK_STATES)
4806 return -EINVAL;
Masashi Honma7d27a0b2016-07-01 10:19:34 +09004807 if (info->attrs[NL80211_ATTR_MESH_PEER_AID]) {
4808 params.peer_aid = nla_get_u16(
4809 info->attrs[NL80211_ATTR_MESH_PEER_AID]);
4810 if (params.peer_aid > IEEE80211_MAX_AID)
4811 return -EINVAL;
4812 }
Johannes Bergf8bacc22013-02-14 23:27:01 +01004813 params.sta_modify_mask |= STATION_PARAM_APPLY_PLINK_STATE;
4814 }
Javier Cardona9c3990a2011-05-03 16:57:11 -07004815
Marco Porsch3b1c5a52013-01-07 16:04:52 +01004816 if (info->attrs[NL80211_ATTR_LOCAL_MESH_POWER_MODE]) {
4817 enum nl80211_mesh_power_mode pm = nla_get_u32(
4818 info->attrs[NL80211_ATTR_LOCAL_MESH_POWER_MODE]);
4819
4820 if (pm <= NL80211_MESH_POWER_UNKNOWN ||
4821 pm > NL80211_MESH_POWER_MAX)
4822 return -EINVAL;
4823
4824 params.local_pm = pm;
4825 }
4826
Johannes Berg77ee7c82013-02-15 00:48:33 +01004827 /* Include parameters for TDLS peer (will check later) */
4828 err = nl80211_set_station_tdls(info, &params);
4829 if (err)
4830 return err;
4831
4832 params.vlan = get_vlan(info, rdev);
4833 if (IS_ERR(params.vlan))
4834 return PTR_ERR(params.vlan);
4835
Johannes Berga97f4422009-06-18 17:23:43 +02004836 switch (dev->ieee80211_ptr->iftype) {
4837 case NL80211_IFTYPE_AP:
4838 case NL80211_IFTYPE_AP_VLAN:
Johannes Berg074ac8d2010-09-16 14:58:22 +02004839 case NL80211_IFTYPE_P2P_GO:
Johannes Berg074ac8d2010-09-16 14:58:22 +02004840 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Berga97f4422009-06-18 17:23:43 +02004841 case NL80211_IFTYPE_STATION:
Antonio Quartulli267335d2012-01-31 20:25:47 +01004842 case NL80211_IFTYPE_ADHOC:
Johannes Berga97f4422009-06-18 17:23:43 +02004843 case NL80211_IFTYPE_MESH_POINT:
Johannes Berga97f4422009-06-18 17:23:43 +02004844 break;
4845 default:
Johannes Berg77ee7c82013-02-15 00:48:33 +01004846 err = -EOPNOTSUPP;
4847 goto out_put_vlan;
Johannes Berg034d6552009-05-27 10:35:29 +02004848 }
4849
Johannes Berg77ee7c82013-02-15 00:48:33 +01004850 /* driver will call cfg80211_check_station_change() */
Hila Gonene35e4d22012-06-27 17:19:42 +03004851 err = rdev_change_station(rdev, dev, mac_addr, &params);
Johannes Berg5727ef12007-12-19 02:03:34 +01004852
Johannes Berg77ee7c82013-02-15 00:48:33 +01004853 out_put_vlan:
Johannes Berg5727ef12007-12-19 02:03:34 +01004854 if (params.vlan)
4855 dev_put(params.vlan);
Johannes Berg3b858752009-03-12 09:55:09 +01004856
Johannes Berg5727ef12007-12-19 02:03:34 +01004857 return err;
4858}
4859
4860static int nl80211_new_station(struct sk_buff *skb, struct genl_info *info)
4861{
Johannes Berg4c476992010-10-04 21:36:35 +02004862 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg5727ef12007-12-19 02:03:34 +01004863 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02004864 struct net_device *dev = info->user_ptr[1];
Johannes Berg5727ef12007-12-19 02:03:34 +01004865 struct station_parameters params;
4866 u8 *mac_addr = NULL;
Johannes Bergbda95eb2015-11-26 16:26:13 +01004867 u32 auth_assoc = BIT(NL80211_STA_FLAG_AUTHENTICATED) |
4868 BIT(NL80211_STA_FLAG_ASSOCIATED);
Johannes Berg5727ef12007-12-19 02:03:34 +01004869
4870 memset(&params, 0, sizeof(params));
4871
Johannes Berg984c3112013-02-14 23:43:25 +01004872 if (!rdev->ops->add_station)
4873 return -EOPNOTSUPP;
4874
Johannes Berg5727ef12007-12-19 02:03:34 +01004875 if (!info->attrs[NL80211_ATTR_MAC])
4876 return -EINVAL;
4877
Johannes Berg5727ef12007-12-19 02:03:34 +01004878 if (!info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL])
4879 return -EINVAL;
4880
4881 if (!info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES])
4882 return -EINVAL;
4883
Jouni Malinen5e4b6f52013-05-16 20:11:08 +03004884 if (!info->attrs[NL80211_ATTR_STA_AID] &&
4885 !info->attrs[NL80211_ATTR_PEER_AID])
Thadeu Lima de Souza Cascardo0e956c12010-02-12 12:34:50 -02004886 return -EINVAL;
4887
Johannes Berg5727ef12007-12-19 02:03:34 +01004888 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
4889 params.supported_rates =
4890 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
4891 params.supported_rates_len =
4892 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
4893 params.listen_interval =
4894 nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]);
Johannes Berg51b50fb2009-05-24 16:42:30 +02004895
Ayala Beker17b94242016-03-17 15:41:38 +02004896 if (info->attrs[NL80211_ATTR_STA_SUPPORT_P2P_PS]) {
4897 u8 tmp;
4898
4899 tmp = nla_get_u8(info->attrs[NL80211_ATTR_STA_SUPPORT_P2P_PS]);
4900 if (tmp >= NUM_NL80211_P2P_PS_STATUS)
4901 return -EINVAL;
4902
4903 params.support_p2p_ps = tmp;
4904 } else {
4905 /*
4906 * if not specified, assume it's supported for P2P GO interface,
4907 * and is NOT supported for AP interface
4908 */
4909 params.support_p2p_ps =
4910 dev->ieee80211_ptr->iftype == NL80211_IFTYPE_P2P_GO;
4911 }
4912
Jouni Malinen3d124ea2013-05-27 18:24:02 +03004913 if (info->attrs[NL80211_ATTR_PEER_AID])
Jouni Malinen5e4b6f52013-05-16 20:11:08 +03004914 params.aid = nla_get_u16(info->attrs[NL80211_ATTR_PEER_AID]);
Jouni Malinen3d124ea2013-05-27 18:24:02 +03004915 else
4916 params.aid = nla_get_u16(info->attrs[NL80211_ATTR_STA_AID]);
Thadeu Lima de Souza Cascardo0e956c12010-02-12 12:34:50 -02004917 if (!params.aid || params.aid > IEEE80211_MAX_AID)
4918 return -EINVAL;
Johannes Berg51b50fb2009-05-24 16:42:30 +02004919
Jouni Malinen9d62a982013-02-14 21:10:13 +02004920 if (info->attrs[NL80211_ATTR_STA_CAPABILITY]) {
4921 params.capability =
4922 nla_get_u16(info->attrs[NL80211_ATTR_STA_CAPABILITY]);
4923 params.sta_modify_mask |= STATION_PARAM_APPLY_CAPABILITY;
4924 }
4925
4926 if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]) {
4927 params.ext_capab =
4928 nla_data(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
4929 params.ext_capab_len =
4930 nla_len(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
4931 }
4932
Jouni Malinen36aedc92008-08-25 11:58:58 +03004933 if (info->attrs[NL80211_ATTR_HT_CAPABILITY])
4934 params.ht_capa =
4935 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]);
Johannes Berg5727ef12007-12-19 02:03:34 +01004936
Mahesh Palivelaf461be3e2012-10-11 08:04:52 +00004937 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY])
4938 params.vht_capa =
4939 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]);
4940
Marek Kwaczynski60f4a7b2013-12-03 10:04:59 +01004941 if (info->attrs[NL80211_ATTR_OPMODE_NOTIF]) {
4942 params.opmode_notif_used = true;
4943 params.opmode_notif =
4944 nla_get_u8(info->attrs[NL80211_ATTR_OPMODE_NOTIF]);
4945 }
4946
Johannes Bergf8bacc22013-02-14 23:27:01 +01004947 if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) {
Javier Cardona96b78df2011-04-07 15:08:33 -07004948 params.plink_action =
Johannes Bergf8bacc22013-02-14 23:27:01 +01004949 nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]);
4950 if (params.plink_action >= NUM_NL80211_PLINK_ACTIONS)
4951 return -EINVAL;
4952 }
Javier Cardona96b78df2011-04-07 15:08:33 -07004953
Sunil Duttc01fc9a2013-10-09 20:45:21 +05304954 err = nl80211_parse_sta_channel_info(info, &params);
4955 if (err)
4956 return err;
4957
Johannes Bergff276692013-02-15 00:09:01 +01004958 err = nl80211_parse_sta_wme(info, &params);
4959 if (err)
4960 return err;
Johannes Bergbdd90d52011-12-14 12:20:27 +01004961
Johannes Bergbdd3ae32012-01-02 13:30:03 +01004962 if (parse_station_flags(info, dev->ieee80211_ptr->iftype, &params))
Johannes Berg5727ef12007-12-19 02:03:34 +01004963 return -EINVAL;
4964
Johannes Berg496fcc22015-03-12 08:53:27 +02004965 /* HT/VHT requires QoS, but if we don't have that just ignore HT/VHT
4966 * as userspace might just pass through the capabilities from the IEs
4967 * directly, rather than enforcing this restriction and returning an
4968 * error in this case.
4969 */
4970 if (!(params.sta_flags_set & BIT(NL80211_STA_FLAG_WME))) {
4971 params.ht_capa = NULL;
4972 params.vht_capa = NULL;
4973 }
4974
Johannes Berg77ee7c82013-02-15 00:48:33 +01004975 /* When you run into this, adjust the code below for the new flag */
4976 BUILD_BUG_ON(NL80211_STA_FLAG_MAX != 7);
4977
Johannes Bergbdd90d52011-12-14 12:20:27 +01004978 switch (dev->ieee80211_ptr->iftype) {
4979 case NL80211_IFTYPE_AP:
4980 case NL80211_IFTYPE_AP_VLAN:
4981 case NL80211_IFTYPE_P2P_GO:
Johannes Berg984c3112013-02-14 23:43:25 +01004982 /* ignore WME attributes if iface/sta is not capable */
4983 if (!(rdev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) ||
4984 !(params.sta_flags_set & BIT(NL80211_STA_FLAG_WME)))
4985 params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD;
Eliad Pellerc75786c2011-08-23 14:37:46 +03004986
Johannes Bergbdd90d52011-12-14 12:20:27 +01004987 /* TDLS peers cannot be added */
Jouni Malinen3d124ea2013-05-27 18:24:02 +03004988 if ((params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) ||
4989 info->attrs[NL80211_ATTR_PEER_AID])
Johannes Berg4319e192011-09-07 11:50:48 +02004990 return -EINVAL;
Johannes Bergbdd90d52011-12-14 12:20:27 +01004991 /* but don't bother the driver with it */
4992 params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER);
Eliad Pellerc75786c2011-08-23 14:37:46 +03004993
Johannes Bergd582cff2012-10-26 17:53:44 +02004994 /* allow authenticated/associated only if driver handles it */
4995 if (!(rdev->wiphy.features &
4996 NL80211_FEATURE_FULL_AP_CLIENT_STATE) &&
Johannes Bergbda95eb2015-11-26 16:26:13 +01004997 params.sta_flags_mask & auth_assoc)
Johannes Bergd582cff2012-10-26 17:53:44 +02004998 return -EINVAL;
4999
Johannes Bergbda95eb2015-11-26 16:26:13 +01005000 /* Older userspace, or userspace wanting to be compatible with
5001 * !NL80211_FEATURE_FULL_AP_CLIENT_STATE, will not set the auth
5002 * and assoc flags in the mask, but assumes the station will be
5003 * added as associated anyway since this was the required driver
5004 * behaviour before NL80211_FEATURE_FULL_AP_CLIENT_STATE was
5005 * introduced.
5006 * In order to not bother drivers with this quirk in the API
5007 * set the flags in both the mask and set for new stations in
5008 * this case.
5009 */
5010 if (!(params.sta_flags_mask & auth_assoc)) {
5011 params.sta_flags_mask |= auth_assoc;
5012 params.sta_flags_set |= auth_assoc;
5013 }
5014
Johannes Bergbdd90d52011-12-14 12:20:27 +01005015 /* must be last in here for error handling */
5016 params.vlan = get_vlan(info, rdev);
5017 if (IS_ERR(params.vlan))
5018 return PTR_ERR(params.vlan);
5019 break;
5020 case NL80211_IFTYPE_MESH_POINT:
Johannes Berg984c3112013-02-14 23:43:25 +01005021 /* ignore uAPSD data */
5022 params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD;
5023
Johannes Bergd582cff2012-10-26 17:53:44 +02005024 /* associated is disallowed */
5025 if (params.sta_flags_mask & BIT(NL80211_STA_FLAG_ASSOCIATED))
5026 return -EINVAL;
Johannes Bergbdd90d52011-12-14 12:20:27 +01005027 /* TDLS peers cannot be added */
Jouni Malinen3d124ea2013-05-27 18:24:02 +03005028 if ((params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) ||
5029 info->attrs[NL80211_ATTR_PEER_AID])
Johannes Berg4319e192011-09-07 11:50:48 +02005030 return -EINVAL;
Johannes Bergbdd90d52011-12-14 12:20:27 +01005031 break;
5032 case NL80211_IFTYPE_STATION:
Johannes Berg93d08f02013-03-04 09:29:46 +01005033 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Berg984c3112013-02-14 23:43:25 +01005034 /* ignore uAPSD data */
5035 params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD;
5036
Johannes Berg77ee7c82013-02-15 00:48:33 +01005037 /* these are disallowed */
5038 if (params.sta_flags_mask &
5039 (BIT(NL80211_STA_FLAG_ASSOCIATED) |
5040 BIT(NL80211_STA_FLAG_AUTHENTICATED)))
Johannes Bergd582cff2012-10-26 17:53:44 +02005041 return -EINVAL;
Johannes Bergbdd90d52011-12-14 12:20:27 +01005042 /* Only TDLS peers can be added */
5043 if (!(params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)))
5044 return -EINVAL;
5045 /* Can only add if TDLS ... */
5046 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS))
5047 return -EOPNOTSUPP;
5048 /* ... with external setup is supported */
5049 if (!(rdev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP))
5050 return -EOPNOTSUPP;
Johannes Berg77ee7c82013-02-15 00:48:33 +01005051 /*
5052 * Older wpa_supplicant versions always mark the TDLS peer
5053 * as authorized, but it shouldn't yet be.
5054 */
5055 params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_AUTHORIZED);
Johannes Bergbdd90d52011-12-14 12:20:27 +01005056 break;
5057 default:
5058 return -EOPNOTSUPP;
Eliad Pellerc75786c2011-08-23 14:37:46 +03005059 }
5060
Johannes Bergbdd90d52011-12-14 12:20:27 +01005061 /* be aware of params.vlan when changing code here */
Johannes Berg5727ef12007-12-19 02:03:34 +01005062
Hila Gonene35e4d22012-06-27 17:19:42 +03005063 err = rdev_add_station(rdev, dev, mac_addr, &params);
Johannes Berg5727ef12007-12-19 02:03:34 +01005064
Johannes Berg5727ef12007-12-19 02:03:34 +01005065 if (params.vlan)
5066 dev_put(params.vlan);
Johannes Berg5727ef12007-12-19 02:03:34 +01005067 return err;
5068}
5069
5070static int nl80211_del_station(struct sk_buff *skb, struct genl_info *info)
5071{
Johannes Berg4c476992010-10-04 21:36:35 +02005072 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5073 struct net_device *dev = info->user_ptr[1];
Jouni Malinen89c771e2014-10-10 20:52:40 +03005074 struct station_del_parameters params;
5075
5076 memset(&params, 0, sizeof(params));
Johannes Berg5727ef12007-12-19 02:03:34 +01005077
5078 if (info->attrs[NL80211_ATTR_MAC])
Jouni Malinen89c771e2014-10-10 20:52:40 +03005079 params.mac = nla_data(info->attrs[NL80211_ATTR_MAC]);
Johannes Berg5727ef12007-12-19 02:03:34 +01005080
Johannes Berge80cf852009-05-11 14:43:13 +02005081 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
Marco Porschd5d9de02010-03-30 10:00:16 +02005082 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN &&
Johannes Berg074ac8d2010-09-16 14:58:22 +02005083 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT &&
Johannes Berg4c476992010-10-04 21:36:35 +02005084 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
5085 return -EINVAL;
Johannes Berge80cf852009-05-11 14:43:13 +02005086
Johannes Berg4c476992010-10-04 21:36:35 +02005087 if (!rdev->ops->del_station)
5088 return -EOPNOTSUPP;
Johannes Berg5727ef12007-12-19 02:03:34 +01005089
Jouni Malinen98856862014-10-20 13:20:45 +03005090 if (info->attrs[NL80211_ATTR_MGMT_SUBTYPE]) {
5091 params.subtype =
5092 nla_get_u8(info->attrs[NL80211_ATTR_MGMT_SUBTYPE]);
5093 if (params.subtype != IEEE80211_STYPE_DISASSOC >> 4 &&
5094 params.subtype != IEEE80211_STYPE_DEAUTH >> 4)
5095 return -EINVAL;
5096 } else {
5097 /* Default to Deauthentication frame */
5098 params.subtype = IEEE80211_STYPE_DEAUTH >> 4;
5099 }
5100
5101 if (info->attrs[NL80211_ATTR_REASON_CODE]) {
5102 params.reason_code =
5103 nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
5104 if (params.reason_code == 0)
5105 return -EINVAL; /* 0 is reserved */
5106 } else {
5107 /* Default to reason code 2 */
5108 params.reason_code = WLAN_REASON_PREV_AUTH_NOT_VALID;
5109 }
5110
Jouni Malinen89c771e2014-10-10 20:52:40 +03005111 return rdev_del_station(rdev, dev, &params);
Johannes Berg5727ef12007-12-19 02:03:34 +01005112}
5113
Eric W. Biederman15e47302012-09-07 20:12:54 +00005114static int nl80211_send_mpath(struct sk_buff *msg, u32 portid, u32 seq,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005115 int flags, struct net_device *dev,
5116 u8 *dst, u8 *next_hop,
5117 struct mpath_info *pinfo)
5118{
5119 void *hdr;
5120 struct nlattr *pinfoattr;
5121
Henning Rogge1ef4c852014-11-04 16:14:58 +01005122 hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_MPATH);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005123 if (!hdr)
5124 return -1;
5125
David S. Miller9360ffd2012-03-29 04:41:26 -04005126 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
5127 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, dst) ||
5128 nla_put(msg, NL80211_ATTR_MPATH_NEXT_HOP, ETH_ALEN, next_hop) ||
5129 nla_put_u32(msg, NL80211_ATTR_GENERATION, pinfo->generation))
5130 goto nla_put_failure;
Johannes Bergf5ea9122009-08-07 16:17:38 +02005131
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005132 pinfoattr = nla_nest_start(msg, NL80211_ATTR_MPATH_INFO);
5133 if (!pinfoattr)
5134 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04005135 if ((pinfo->filled & MPATH_INFO_FRAME_QLEN) &&
5136 nla_put_u32(msg, NL80211_MPATH_INFO_FRAME_QLEN,
5137 pinfo->frame_qlen))
5138 goto nla_put_failure;
5139 if (((pinfo->filled & MPATH_INFO_SN) &&
5140 nla_put_u32(msg, NL80211_MPATH_INFO_SN, pinfo->sn)) ||
5141 ((pinfo->filled & MPATH_INFO_METRIC) &&
5142 nla_put_u32(msg, NL80211_MPATH_INFO_METRIC,
5143 pinfo->metric)) ||
5144 ((pinfo->filled & MPATH_INFO_EXPTIME) &&
5145 nla_put_u32(msg, NL80211_MPATH_INFO_EXPTIME,
5146 pinfo->exptime)) ||
5147 ((pinfo->filled & MPATH_INFO_FLAGS) &&
5148 nla_put_u8(msg, NL80211_MPATH_INFO_FLAGS,
5149 pinfo->flags)) ||
5150 ((pinfo->filled & MPATH_INFO_DISCOVERY_TIMEOUT) &&
5151 nla_put_u32(msg, NL80211_MPATH_INFO_DISCOVERY_TIMEOUT,
5152 pinfo->discovery_timeout)) ||
5153 ((pinfo->filled & MPATH_INFO_DISCOVERY_RETRIES) &&
5154 nla_put_u8(msg, NL80211_MPATH_INFO_DISCOVERY_RETRIES,
5155 pinfo->discovery_retries)))
5156 goto nla_put_failure;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005157
5158 nla_nest_end(msg, pinfoattr);
5159
Johannes Berg053c0952015-01-16 22:09:00 +01005160 genlmsg_end(msg, hdr);
5161 return 0;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005162
5163 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07005164 genlmsg_cancel(msg, hdr);
5165 return -EMSGSIZE;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005166}
5167
5168static int nl80211_dump_mpath(struct sk_buff *skb,
Johannes Bergbba95fe2008-07-29 13:22:51 +02005169 struct netlink_callback *cb)
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005170{
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005171 struct mpath_info pinfo;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08005172 struct cfg80211_registered_device *rdev;
Johannes Berg97990a02013-04-19 01:02:55 +02005173 struct wireless_dev *wdev;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005174 u8 dst[ETH_ALEN];
5175 u8 next_hop[ETH_ALEN];
Johannes Berg97990a02013-04-19 01:02:55 +02005176 int path_idx = cb->args[2];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005177 int err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005178
Zhao, Gang1b8ec872014-04-21 12:53:02 +08005179 err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev);
Johannes Berg67748892010-10-04 21:14:06 +02005180 if (err)
5181 return err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02005182
Zhao, Gang1b8ec872014-04-21 12:53:02 +08005183 if (!rdev->ops->dump_mpath) {
Jouni Malineneec60b02009-03-20 21:21:19 +02005184 err = -EOPNOTSUPP;
Johannes Bergbba95fe2008-07-29 13:22:51 +02005185 goto out_err;
5186 }
5187
Johannes Berg97990a02013-04-19 01:02:55 +02005188 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) {
Jouni Malineneec60b02009-03-20 21:21:19 +02005189 err = -EOPNOTSUPP;
Roel Kluin0448b5f2009-08-22 21:15:49 +02005190 goto out_err;
Jouni Malineneec60b02009-03-20 21:21:19 +02005191 }
5192
Johannes Bergbba95fe2008-07-29 13:22:51 +02005193 while (1) {
Zhao, Gang1b8ec872014-04-21 12:53:02 +08005194 err = rdev_dump_mpath(rdev, wdev->netdev, path_idx, dst,
Johannes Berg97990a02013-04-19 01:02:55 +02005195 next_hop, &pinfo);
Johannes Bergbba95fe2008-07-29 13:22:51 +02005196 if (err == -ENOENT)
5197 break;
5198 if (err)
Johannes Berg3b858752009-03-12 09:55:09 +01005199 goto out_err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02005200
Eric W. Biederman15e47302012-09-07 20:12:54 +00005201 if (nl80211_send_mpath(skb, NETLINK_CB(cb->skb).portid,
Johannes Bergbba95fe2008-07-29 13:22:51 +02005202 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Johannes Berg97990a02013-04-19 01:02:55 +02005203 wdev->netdev, dst, next_hop,
Johannes Bergbba95fe2008-07-29 13:22:51 +02005204 &pinfo) < 0)
5205 goto out;
5206
5207 path_idx++;
5208 }
5209
Johannes Bergbba95fe2008-07-29 13:22:51 +02005210 out:
Johannes Berg97990a02013-04-19 01:02:55 +02005211 cb->args[2] = path_idx;
Johannes Bergbba95fe2008-07-29 13:22:51 +02005212 err = skb->len;
Johannes Bergbba95fe2008-07-29 13:22:51 +02005213 out_err:
Zhao, Gang1b8ec872014-04-21 12:53:02 +08005214 nl80211_finish_wdev_dump(rdev);
Johannes Bergbba95fe2008-07-29 13:22:51 +02005215 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005216}
5217
5218static int nl80211_get_mpath(struct sk_buff *skb, struct genl_info *info)
5219{
Johannes Berg4c476992010-10-04 21:36:35 +02005220 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005221 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02005222 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005223 struct mpath_info pinfo;
5224 struct sk_buff *msg;
5225 u8 *dst = NULL;
5226 u8 next_hop[ETH_ALEN];
5227
5228 memset(&pinfo, 0, sizeof(pinfo));
5229
5230 if (!info->attrs[NL80211_ATTR_MAC])
5231 return -EINVAL;
5232
5233 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
5234
Johannes Berg4c476992010-10-04 21:36:35 +02005235 if (!rdev->ops->get_mpath)
5236 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01005237
Johannes Berg4c476992010-10-04 21:36:35 +02005238 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
5239 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02005240
Hila Gonene35e4d22012-06-27 17:19:42 +03005241 err = rdev_get_mpath(rdev, dev, dst, next_hop, &pinfo);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005242 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02005243 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005244
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07005245 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005246 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02005247 return -ENOMEM;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005248
Eric W. Biederman15e47302012-09-07 20:12:54 +00005249 if (nl80211_send_mpath(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berg4c476992010-10-04 21:36:35 +02005250 dev, dst, next_hop, &pinfo) < 0) {
5251 nlmsg_free(msg);
5252 return -ENOBUFS;
5253 }
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005254
Johannes Berg4c476992010-10-04 21:36:35 +02005255 return genlmsg_reply(msg, info);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005256}
5257
5258static int nl80211_set_mpath(struct sk_buff *skb, struct genl_info *info)
5259{
Johannes Berg4c476992010-10-04 21:36:35 +02005260 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5261 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005262 u8 *dst = NULL;
5263 u8 *next_hop = NULL;
5264
5265 if (!info->attrs[NL80211_ATTR_MAC])
5266 return -EINVAL;
5267
5268 if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP])
5269 return -EINVAL;
5270
5271 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
5272 next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]);
5273
Johannes Berg4c476992010-10-04 21:36:35 +02005274 if (!rdev->ops->change_mpath)
5275 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01005276
Johannes Berg4c476992010-10-04 21:36:35 +02005277 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
5278 return -EOPNOTSUPP;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005279
Hila Gonene35e4d22012-06-27 17:19:42 +03005280 return rdev_change_mpath(rdev, dev, dst, next_hop);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005281}
Johannes Berg4c476992010-10-04 21:36:35 +02005282
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005283static int nl80211_new_mpath(struct sk_buff *skb, struct genl_info *info)
5284{
Johannes Berg4c476992010-10-04 21:36:35 +02005285 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5286 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005287 u8 *dst = NULL;
5288 u8 *next_hop = NULL;
5289
5290 if (!info->attrs[NL80211_ATTR_MAC])
5291 return -EINVAL;
5292
5293 if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP])
5294 return -EINVAL;
5295
5296 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
5297 next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]);
5298
Johannes Berg4c476992010-10-04 21:36:35 +02005299 if (!rdev->ops->add_mpath)
5300 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01005301
Johannes Berg4c476992010-10-04 21:36:35 +02005302 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
5303 return -EOPNOTSUPP;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005304
Hila Gonene35e4d22012-06-27 17:19:42 +03005305 return rdev_add_mpath(rdev, dev, dst, next_hop);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005306}
5307
5308static int nl80211_del_mpath(struct sk_buff *skb, struct genl_info *info)
5309{
Johannes Berg4c476992010-10-04 21:36:35 +02005310 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5311 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005312 u8 *dst = NULL;
5313
5314 if (info->attrs[NL80211_ATTR_MAC])
5315 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
5316
Johannes Berg4c476992010-10-04 21:36:35 +02005317 if (!rdev->ops->del_mpath)
5318 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01005319
Hila Gonene35e4d22012-06-27 17:19:42 +03005320 return rdev_del_mpath(rdev, dev, dst);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005321}
5322
Henning Rogge66be7d22014-09-12 08:58:49 +02005323static int nl80211_get_mpp(struct sk_buff *skb, struct genl_info *info)
5324{
5325 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5326 int err;
5327 struct net_device *dev = info->user_ptr[1];
5328 struct mpath_info pinfo;
5329 struct sk_buff *msg;
5330 u8 *dst = NULL;
5331 u8 mpp[ETH_ALEN];
5332
5333 memset(&pinfo, 0, sizeof(pinfo));
5334
5335 if (!info->attrs[NL80211_ATTR_MAC])
5336 return -EINVAL;
5337
5338 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
5339
5340 if (!rdev->ops->get_mpp)
5341 return -EOPNOTSUPP;
5342
5343 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
5344 return -EOPNOTSUPP;
5345
5346 err = rdev_get_mpp(rdev, dev, dst, mpp, &pinfo);
5347 if (err)
5348 return err;
5349
5350 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
5351 if (!msg)
5352 return -ENOMEM;
5353
5354 if (nl80211_send_mpath(msg, info->snd_portid, info->snd_seq, 0,
5355 dev, dst, mpp, &pinfo) < 0) {
5356 nlmsg_free(msg);
5357 return -ENOBUFS;
5358 }
5359
5360 return genlmsg_reply(msg, info);
5361}
5362
5363static int nl80211_dump_mpp(struct sk_buff *skb,
5364 struct netlink_callback *cb)
5365{
5366 struct mpath_info pinfo;
5367 struct cfg80211_registered_device *rdev;
5368 struct wireless_dev *wdev;
5369 u8 dst[ETH_ALEN];
5370 u8 mpp[ETH_ALEN];
5371 int path_idx = cb->args[2];
5372 int err;
5373
5374 err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev);
5375 if (err)
5376 return err;
5377
5378 if (!rdev->ops->dump_mpp) {
5379 err = -EOPNOTSUPP;
5380 goto out_err;
5381 }
5382
5383 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) {
5384 err = -EOPNOTSUPP;
5385 goto out_err;
5386 }
5387
5388 while (1) {
5389 err = rdev_dump_mpp(rdev, wdev->netdev, path_idx, dst,
5390 mpp, &pinfo);
5391 if (err == -ENOENT)
5392 break;
5393 if (err)
5394 goto out_err;
5395
5396 if (nl80211_send_mpath(skb, NETLINK_CB(cb->skb).portid,
5397 cb->nlh->nlmsg_seq, NLM_F_MULTI,
5398 wdev->netdev, dst, mpp,
5399 &pinfo) < 0)
5400 goto out;
5401
5402 path_idx++;
5403 }
5404
5405 out:
5406 cb->args[2] = path_idx;
5407 err = skb->len;
5408 out_err:
5409 nl80211_finish_wdev_dump(rdev);
5410 return err;
5411}
5412
Jouni Malinen9f1ba902008-08-07 20:07:01 +03005413static int nl80211_set_bss(struct sk_buff *skb, struct genl_info *info)
5414{
Johannes Berg4c476992010-10-04 21:36:35 +02005415 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5416 struct net_device *dev = info->user_ptr[1];
Simon Wunderlichc56589e2013-11-21 18:19:49 +01005417 struct wireless_dev *wdev = dev->ieee80211_ptr;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03005418 struct bss_parameters params;
Simon Wunderlichc56589e2013-11-21 18:19:49 +01005419 int err;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03005420
5421 memset(&params, 0, sizeof(params));
5422 /* default to not changing parameters */
5423 params.use_cts_prot = -1;
5424 params.use_short_preamble = -1;
5425 params.use_short_slot_time = -1;
Felix Fietkaufd8aaaf2010-04-27 01:23:35 +02005426 params.ap_isolate = -1;
Helmut Schaa50b12f52010-11-19 12:40:25 +01005427 params.ht_opmode = -1;
Johannes Berg53cabad2012-11-14 15:17:28 +01005428 params.p2p_ctwindow = -1;
5429 params.p2p_opp_ps = -1;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03005430
5431 if (info->attrs[NL80211_ATTR_BSS_CTS_PROT])
5432 params.use_cts_prot =
5433 nla_get_u8(info->attrs[NL80211_ATTR_BSS_CTS_PROT]);
5434 if (info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE])
5435 params.use_short_preamble =
5436 nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]);
5437 if (info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME])
5438 params.use_short_slot_time =
5439 nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]);
Jouni Malinen90c97a02008-10-30 16:59:22 +02005440 if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) {
5441 params.basic_rates =
5442 nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
5443 params.basic_rates_len =
5444 nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
5445 }
Felix Fietkaufd8aaaf2010-04-27 01:23:35 +02005446 if (info->attrs[NL80211_ATTR_AP_ISOLATE])
5447 params.ap_isolate = !!nla_get_u8(info->attrs[NL80211_ATTR_AP_ISOLATE]);
Helmut Schaa50b12f52010-11-19 12:40:25 +01005448 if (info->attrs[NL80211_ATTR_BSS_HT_OPMODE])
5449 params.ht_opmode =
5450 nla_get_u16(info->attrs[NL80211_ATTR_BSS_HT_OPMODE]);
Jouni Malinen9f1ba902008-08-07 20:07:01 +03005451
Johannes Berg53cabad2012-11-14 15:17:28 +01005452 if (info->attrs[NL80211_ATTR_P2P_CTWINDOW]) {
5453 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
5454 return -EINVAL;
5455 params.p2p_ctwindow =
5456 nla_get_s8(info->attrs[NL80211_ATTR_P2P_CTWINDOW]);
5457 if (params.p2p_ctwindow < 0)
5458 return -EINVAL;
5459 if (params.p2p_ctwindow != 0 &&
5460 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_CTWIN))
5461 return -EINVAL;
5462 }
5463
5464 if (info->attrs[NL80211_ATTR_P2P_OPPPS]) {
5465 u8 tmp;
5466
5467 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
5468 return -EINVAL;
5469 tmp = nla_get_u8(info->attrs[NL80211_ATTR_P2P_OPPPS]);
5470 if (tmp > 1)
5471 return -EINVAL;
5472 params.p2p_opp_ps = tmp;
5473 if (params.p2p_opp_ps &&
5474 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_OPPPS))
5475 return -EINVAL;
5476 }
5477
Johannes Berg4c476992010-10-04 21:36:35 +02005478 if (!rdev->ops->change_bss)
5479 return -EOPNOTSUPP;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03005480
Johannes Berg074ac8d2010-09-16 14:58:22 +02005481 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
Johannes Berg4c476992010-10-04 21:36:35 +02005482 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
5483 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02005484
Simon Wunderlichc56589e2013-11-21 18:19:49 +01005485 wdev_lock(wdev);
5486 err = rdev_change_bss(rdev, dev, &params);
5487 wdev_unlock(wdev);
5488
5489 return err;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03005490}
5491
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005492static int nl80211_req_set_reg(struct sk_buff *skb, struct genl_info *info)
5493{
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005494 char *data = NULL;
Ilan peer05050752015-03-04 00:32:06 -05005495 bool is_indoor;
Luis R. Rodriguez57b5ce02012-07-12 11:49:18 -07005496 enum nl80211_user_reg_hint_type user_reg_hint_type;
Ilan peer05050752015-03-04 00:32:06 -05005497 u32 owner_nlportid;
5498
Luis R. Rodriguez80778f12009-02-21 00:04:22 -05005499 /*
5500 * You should only get this when cfg80211 hasn't yet initialized
5501 * completely when built-in to the kernel right between the time
5502 * window between nl80211_init() and regulatory_init(), if that is
5503 * even possible.
5504 */
Johannes Berg458f4f92012-12-06 15:47:38 +01005505 if (unlikely(!rcu_access_pointer(cfg80211_regdomain)))
Luis R. Rodriguezfe33eb32009-02-21 00:04:30 -05005506 return -EINPROGRESS;
Luis R. Rodriguez80778f12009-02-21 00:04:22 -05005507
Luis R. Rodriguez57b5ce02012-07-12 11:49:18 -07005508 if (info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE])
5509 user_reg_hint_type =
5510 nla_get_u32(info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE]);
5511 else
5512 user_reg_hint_type = NL80211_USER_REG_HINT_USER;
5513
5514 switch (user_reg_hint_type) {
5515 case NL80211_USER_REG_HINT_USER:
5516 case NL80211_USER_REG_HINT_CELL_BASE:
Ilan Peer52616f22014-02-25 16:26:00 +02005517 if (!info->attrs[NL80211_ATTR_REG_ALPHA2])
5518 return -EINVAL;
5519
5520 data = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]);
5521 return regulatory_hint_user(data, user_reg_hint_type);
5522 case NL80211_USER_REG_HINT_INDOOR:
Ilan peer05050752015-03-04 00:32:06 -05005523 if (info->attrs[NL80211_ATTR_SOCKET_OWNER]) {
5524 owner_nlportid = info->snd_portid;
5525 is_indoor = !!info->attrs[NL80211_ATTR_REG_INDOOR];
5526 } else {
5527 owner_nlportid = 0;
5528 is_indoor = true;
5529 }
5530
5531 return regulatory_hint_indoor(is_indoor, owner_nlportid);
Luis R. Rodriguez57b5ce02012-07-12 11:49:18 -07005532 default:
5533 return -EINVAL;
5534 }
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005535}
5536
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005537static int nl80211_get_mesh_config(struct sk_buff *skb,
Johannes Berg29cbe682010-12-03 09:20:44 +01005538 struct genl_info *info)
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005539{
Johannes Berg4c476992010-10-04 21:36:35 +02005540 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg4c476992010-10-04 21:36:35 +02005541 struct net_device *dev = info->user_ptr[1];
Johannes Berg29cbe682010-12-03 09:20:44 +01005542 struct wireless_dev *wdev = dev->ieee80211_ptr;
5543 struct mesh_config cur_params;
5544 int err = 0;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005545 void *hdr;
5546 struct nlattr *pinfoattr;
5547 struct sk_buff *msg;
5548
Johannes Berg29cbe682010-12-03 09:20:44 +01005549 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT)
5550 return -EOPNOTSUPP;
5551
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005552 if (!rdev->ops->get_mesh_config)
Johannes Berg4c476992010-10-04 21:36:35 +02005553 return -EOPNOTSUPP;
Jouni Malinenf3f92582009-03-20 17:57:36 +02005554
Johannes Berg29cbe682010-12-03 09:20:44 +01005555 wdev_lock(wdev);
5556 /* If not connected, get default parameters */
5557 if (!wdev->mesh_id_len)
5558 memcpy(&cur_params, &default_mesh_config, sizeof(cur_params));
5559 else
Hila Gonene35e4d22012-06-27 17:19:42 +03005560 err = rdev_get_mesh_config(rdev, dev, &cur_params);
Johannes Berg29cbe682010-12-03 09:20:44 +01005561 wdev_unlock(wdev);
5562
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005563 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02005564 return err;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005565
5566 /* Draw up a netlink message to send back */
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07005567 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02005568 if (!msg)
5569 return -ENOMEM;
Eric W. Biederman15e47302012-09-07 20:12:54 +00005570 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005571 NL80211_CMD_GET_MESH_CONFIG);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005572 if (!hdr)
Julia Lawallefe1cf02011-01-28 15:17:11 +01005573 goto out;
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005574 pinfoattr = nla_nest_start(msg, NL80211_ATTR_MESH_CONFIG);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005575 if (!pinfoattr)
5576 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04005577 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
5578 nla_put_u16(msg, NL80211_MESHCONF_RETRY_TIMEOUT,
5579 cur_params.dot11MeshRetryTimeout) ||
5580 nla_put_u16(msg, NL80211_MESHCONF_CONFIRM_TIMEOUT,
5581 cur_params.dot11MeshConfirmTimeout) ||
5582 nla_put_u16(msg, NL80211_MESHCONF_HOLDING_TIMEOUT,
5583 cur_params.dot11MeshHoldingTimeout) ||
5584 nla_put_u16(msg, NL80211_MESHCONF_MAX_PEER_LINKS,
5585 cur_params.dot11MeshMaxPeerLinks) ||
5586 nla_put_u8(msg, NL80211_MESHCONF_MAX_RETRIES,
5587 cur_params.dot11MeshMaxRetries) ||
5588 nla_put_u8(msg, NL80211_MESHCONF_TTL,
5589 cur_params.dot11MeshTTL) ||
5590 nla_put_u8(msg, NL80211_MESHCONF_ELEMENT_TTL,
5591 cur_params.element_ttl) ||
5592 nla_put_u8(msg, NL80211_MESHCONF_AUTO_OPEN_PLINKS,
5593 cur_params.auto_open_plinks) ||
John W. Linville7eab0f62012-04-12 14:25:14 -04005594 nla_put_u32(msg, NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR,
5595 cur_params.dot11MeshNbrOffsetMaxNeighbor) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04005596 nla_put_u8(msg, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES,
5597 cur_params.dot11MeshHWMPmaxPREQretries) ||
5598 nla_put_u32(msg, NL80211_MESHCONF_PATH_REFRESH_TIME,
5599 cur_params.path_refresh_time) ||
5600 nla_put_u16(msg, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT,
5601 cur_params.min_discovery_timeout) ||
5602 nla_put_u32(msg, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT,
5603 cur_params.dot11MeshHWMPactivePathTimeout) ||
5604 nla_put_u16(msg, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL,
5605 cur_params.dot11MeshHWMPpreqMinInterval) ||
5606 nla_put_u16(msg, NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL,
5607 cur_params.dot11MeshHWMPperrMinInterval) ||
5608 nla_put_u16(msg, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME,
5609 cur_params.dot11MeshHWMPnetDiameterTraversalTime) ||
5610 nla_put_u8(msg, NL80211_MESHCONF_HWMP_ROOTMODE,
5611 cur_params.dot11MeshHWMPRootMode) ||
5612 nla_put_u16(msg, NL80211_MESHCONF_HWMP_RANN_INTERVAL,
5613 cur_params.dot11MeshHWMPRannInterval) ||
5614 nla_put_u8(msg, NL80211_MESHCONF_GATE_ANNOUNCEMENTS,
5615 cur_params.dot11MeshGateAnnouncementProtocol) ||
5616 nla_put_u8(msg, NL80211_MESHCONF_FORWARDING,
5617 cur_params.dot11MeshForwarding) ||
5618 nla_put_u32(msg, NL80211_MESHCONF_RSSI_THRESHOLD,
Ashok Nagarajan70c33ea2012-04-30 14:20:32 -07005619 cur_params.rssi_threshold) ||
5620 nla_put_u32(msg, NL80211_MESHCONF_HT_OPMODE,
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08005621 cur_params.ht_opmode) ||
5622 nla_put_u32(msg, NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT,
5623 cur_params.dot11MeshHWMPactivePathToRootTimeout) ||
5624 nla_put_u16(msg, NL80211_MESHCONF_HWMP_ROOT_INTERVAL,
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +08005625 cur_params.dot11MeshHWMProotInterval) ||
5626 nla_put_u16(msg, NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL,
Marco Porsch3b1c5a52013-01-07 16:04:52 +01005627 cur_params.dot11MeshHWMPconfirmationInterval) ||
5628 nla_put_u32(msg, NL80211_MESHCONF_POWER_MODE,
5629 cur_params.power_mode) ||
5630 nla_put_u16(msg, NL80211_MESHCONF_AWAKE_WINDOW,
Colleen Twitty8e7c0532013-06-03 09:53:39 -07005631 cur_params.dot11MeshAwakeWindowDuration) ||
5632 nla_put_u32(msg, NL80211_MESHCONF_PLINK_TIMEOUT,
5633 cur_params.plink_timeout))
David S. Miller9360ffd2012-03-29 04:41:26 -04005634 goto nla_put_failure;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005635 nla_nest_end(msg, pinfoattr);
5636 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02005637 return genlmsg_reply(msg, info);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005638
Johannes Berg3b858752009-03-12 09:55:09 +01005639 nla_put_failure:
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005640 genlmsg_cancel(msg, hdr);
Julia Lawallefe1cf02011-01-28 15:17:11 +01005641 out:
Yuri Ershovd080e272010-06-29 15:08:07 +04005642 nlmsg_free(msg);
Johannes Berg4c476992010-10-04 21:36:35 +02005643 return -ENOBUFS;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005644}
5645
Alexey Dobriyanb54452b2010-02-18 08:14:31 +00005646static const struct nla_policy nl80211_meshconf_params_policy[NL80211_MESHCONF_ATTR_MAX+1] = {
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005647 [NL80211_MESHCONF_RETRY_TIMEOUT] = { .type = NLA_U16 },
5648 [NL80211_MESHCONF_CONFIRM_TIMEOUT] = { .type = NLA_U16 },
5649 [NL80211_MESHCONF_HOLDING_TIMEOUT] = { .type = NLA_U16 },
5650 [NL80211_MESHCONF_MAX_PEER_LINKS] = { .type = NLA_U16 },
5651 [NL80211_MESHCONF_MAX_RETRIES] = { .type = NLA_U8 },
5652 [NL80211_MESHCONF_TTL] = { .type = NLA_U8 },
Javier Cardona45904f22010-12-03 09:20:40 +01005653 [NL80211_MESHCONF_ELEMENT_TTL] = { .type = NLA_U8 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005654 [NL80211_MESHCONF_AUTO_OPEN_PLINKS] = { .type = NLA_U8 },
Javier Cardonad299a1f2012-03-31 11:31:33 -07005655 [NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR] = { .type = NLA_U32 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005656 [NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES] = { .type = NLA_U8 },
5657 [NL80211_MESHCONF_PATH_REFRESH_TIME] = { .type = NLA_U32 },
5658 [NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT] = { .type = NLA_U16 },
5659 [NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT] = { .type = NLA_U32 },
5660 [NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL] = { .type = NLA_U16 },
Thomas Pedersendca7e942011-11-24 17:15:24 -08005661 [NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL] = { .type = NLA_U16 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005662 [NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME] = { .type = NLA_U16 },
Javier Cardona699403d2011-08-09 16:45:09 -07005663 [NL80211_MESHCONF_HWMP_ROOTMODE] = { .type = NLA_U8 },
Javier Cardona0507e152011-08-09 16:45:10 -07005664 [NL80211_MESHCONF_HWMP_RANN_INTERVAL] = { .type = NLA_U16 },
Javier Cardona16dd7262011-08-09 16:45:11 -07005665 [NL80211_MESHCONF_GATE_ANNOUNCEMENTS] = { .type = NLA_U8 },
Chun-Yeow Yeoh94f90652012-01-21 01:02:16 +08005666 [NL80211_MESHCONF_FORWARDING] = { .type = NLA_U8 },
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005667 [NL80211_MESHCONF_RSSI_THRESHOLD] = { .type = NLA_U32 },
5668 [NL80211_MESHCONF_HT_OPMODE] = { .type = NLA_U16 },
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08005669 [NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT] = { .type = NLA_U32 },
5670 [NL80211_MESHCONF_HWMP_ROOT_INTERVAL] = { .type = NLA_U16 },
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +08005671 [NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL] = { .type = NLA_U16 },
Marco Porsch3b1c5a52013-01-07 16:04:52 +01005672 [NL80211_MESHCONF_POWER_MODE] = { .type = NLA_U32 },
5673 [NL80211_MESHCONF_AWAKE_WINDOW] = { .type = NLA_U16 },
Colleen Twitty8e7c0532013-06-03 09:53:39 -07005674 [NL80211_MESHCONF_PLINK_TIMEOUT] = { .type = NLA_U32 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005675};
5676
Javier Cardonac80d5452010-12-16 17:37:49 -08005677static const struct nla_policy
5678 nl80211_mesh_setup_params_policy[NL80211_MESH_SETUP_ATTR_MAX+1] = {
Javier Cardonad299a1f2012-03-31 11:31:33 -07005679 [NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC] = { .type = NLA_U8 },
Javier Cardonac80d5452010-12-16 17:37:49 -08005680 [NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL] = { .type = NLA_U8 },
5681 [NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC] = { .type = NLA_U8 },
Javier Cardona15d5dda2011-04-07 15:08:28 -07005682 [NL80211_MESH_SETUP_USERSPACE_AUTH] = { .type = NLA_FLAG },
Colleen Twitty6e16d902013-05-08 11:45:59 -07005683 [NL80211_MESH_SETUP_AUTH_PROTOCOL] = { .type = NLA_U8 },
Thomas Pedersenbb2798d2013-03-04 13:06:10 -08005684 [NL80211_MESH_SETUP_USERSPACE_MPM] = { .type = NLA_FLAG },
Javier Cardona581a8b02011-04-07 15:08:27 -07005685 [NL80211_MESH_SETUP_IE] = { .type = NLA_BINARY,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005686 .len = IEEE80211_MAX_DATA_LEN },
Javier Cardonab130e5c2011-05-03 16:57:07 -07005687 [NL80211_MESH_SETUP_USERSPACE_AMPE] = { .type = NLA_FLAG },
Javier Cardonac80d5452010-12-16 17:37:49 -08005688};
5689
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005690static int nl80211_check_bool(const struct nlattr *nla, u8 min, u8 max, bool *out)
5691{
5692 u8 val = nla_get_u8(nla);
5693 if (val < min || val > max)
5694 return -EINVAL;
5695 *out = val;
5696 return 0;
5697}
5698
5699static int nl80211_check_u8(const struct nlattr *nla, u8 min, u8 max, u8 *out)
5700{
5701 u8 val = nla_get_u8(nla);
5702 if (val < min || val > max)
5703 return -EINVAL;
5704 *out = val;
5705 return 0;
5706}
5707
5708static int nl80211_check_u16(const struct nlattr *nla, u16 min, u16 max, u16 *out)
5709{
5710 u16 val = nla_get_u16(nla);
5711 if (val < min || val > max)
5712 return -EINVAL;
5713 *out = val;
5714 return 0;
5715}
5716
5717static int nl80211_check_u32(const struct nlattr *nla, u32 min, u32 max, u32 *out)
5718{
5719 u32 val = nla_get_u32(nla);
5720 if (val < min || val > max)
5721 return -EINVAL;
5722 *out = val;
5723 return 0;
5724}
5725
5726static int nl80211_check_s32(const struct nlattr *nla, s32 min, s32 max, s32 *out)
5727{
5728 s32 val = nla_get_s32(nla);
5729 if (val < min || val > max)
5730 return -EINVAL;
5731 *out = val;
5732 return 0;
5733}
5734
Johannes Bergff9a71a2016-08-11 14:59:53 +02005735static int nl80211_check_power_mode(const struct nlattr *nla,
5736 enum nl80211_mesh_power_mode min,
5737 enum nl80211_mesh_power_mode max,
5738 enum nl80211_mesh_power_mode *out)
5739{
5740 u32 val = nla_get_u32(nla);
5741 if (val < min || val > max)
5742 return -EINVAL;
5743 *out = val;
5744 return 0;
5745}
5746
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005747static int nl80211_parse_mesh_config(struct genl_info *info,
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005748 struct mesh_config *cfg,
5749 u32 *mask_out)
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005750{
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005751 struct nlattr *tb[NL80211_MESHCONF_ATTR_MAX + 1];
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005752 u32 mask = 0;
Masashi Honma97572352016-08-03 10:07:44 +09005753 u16 ht_opmode;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005754
Marco Porschea54fba2013-01-07 16:04:48 +01005755#define FILL_IN_MESH_PARAM_IF_SET(tb, cfg, param, min, max, mask, attr, fn) \
5756do { \
5757 if (tb[attr]) { \
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005758 if (fn(tb[attr], min, max, &cfg->param)) \
Marco Porschea54fba2013-01-07 16:04:48 +01005759 return -EINVAL; \
Marco Porschea54fba2013-01-07 16:04:48 +01005760 mask |= (1 << (attr - 1)); \
5761 } \
5762} while (0)
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005763
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005764 if (!info->attrs[NL80211_ATTR_MESH_CONFIG])
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005765 return -EINVAL;
5766 if (nla_parse_nested(tb, NL80211_MESHCONF_ATTR_MAX,
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005767 info->attrs[NL80211_ATTR_MESH_CONFIG],
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005768 nl80211_meshconf_params_policy))
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005769 return -EINVAL;
5770
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005771 /* This makes sure that there aren't more than 32 mesh config
5772 * parameters (otherwise our bitfield scheme would not work.) */
5773 BUILD_BUG_ON(NL80211_MESHCONF_ATTR_MAX > 32);
5774
5775 /* Fill in the params struct */
Marco Porschea54fba2013-01-07 16:04:48 +01005776 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshRetryTimeout, 1, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005777 mask, NL80211_MESHCONF_RETRY_TIMEOUT,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005778 nl80211_check_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01005779 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshConfirmTimeout, 1, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005780 mask, NL80211_MESHCONF_CONFIRM_TIMEOUT,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005781 nl80211_check_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01005782 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHoldingTimeout, 1, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005783 mask, NL80211_MESHCONF_HOLDING_TIMEOUT,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005784 nl80211_check_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01005785 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxPeerLinks, 0, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005786 mask, NL80211_MESHCONF_MAX_PEER_LINKS,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005787 nl80211_check_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01005788 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxRetries, 0, 16,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005789 mask, NL80211_MESHCONF_MAX_RETRIES,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005790 nl80211_check_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01005791 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshTTL, 1, 255,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005792 mask, NL80211_MESHCONF_TTL, nl80211_check_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01005793 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, element_ttl, 1, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005794 mask, NL80211_MESHCONF_ELEMENT_TTL,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005795 nl80211_check_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01005796 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, auto_open_plinks, 0, 1,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005797 mask, NL80211_MESHCONF_AUTO_OPEN_PLINKS,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005798 nl80211_check_bool);
Marco Porschea54fba2013-01-07 16:04:48 +01005799 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshNbrOffsetMaxNeighbor,
5800 1, 255, mask,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005801 NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005802 nl80211_check_u32);
Marco Porschea54fba2013-01-07 16:04:48 +01005803 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPmaxPREQretries, 0, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005804 mask, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005805 nl80211_check_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01005806 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, path_refresh_time, 1, 65535,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005807 mask, NL80211_MESHCONF_PATH_REFRESH_TIME,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005808 nl80211_check_u32);
Marco Porschea54fba2013-01-07 16:04:48 +01005809 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, min_discovery_timeout, 1, 65535,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005810 mask, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005811 nl80211_check_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01005812 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathTimeout,
5813 1, 65535, mask,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005814 NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005815 nl80211_check_u32);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005816 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPpreqMinInterval,
Marco Porschea54fba2013-01-07 16:04:48 +01005817 1, 65535, mask,
5818 NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005819 nl80211_check_u16);
Thomas Pedersendca7e942011-11-24 17:15:24 -08005820 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPperrMinInterval,
Marco Porschea54fba2013-01-07 16:04:48 +01005821 1, 65535, mask,
5822 NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005823 nl80211_check_u16);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005824 FILL_IN_MESH_PARAM_IF_SET(tb, cfg,
Marco Porschea54fba2013-01-07 16:04:48 +01005825 dot11MeshHWMPnetDiameterTraversalTime,
5826 1, 65535, mask,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005827 NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005828 nl80211_check_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01005829 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRootMode, 0, 4,
5830 mask, NL80211_MESHCONF_HWMP_ROOTMODE,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005831 nl80211_check_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01005832 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRannInterval, 1, 65535,
5833 mask, NL80211_MESHCONF_HWMP_RANN_INTERVAL,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005834 nl80211_check_u16);
Rui Paulo63c57232009-11-09 23:46:57 +00005835 FILL_IN_MESH_PARAM_IF_SET(tb, cfg,
Marco Porschea54fba2013-01-07 16:04:48 +01005836 dot11MeshGateAnnouncementProtocol, 0, 1,
5837 mask, NL80211_MESHCONF_GATE_ANNOUNCEMENTS,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005838 nl80211_check_bool);
Marco Porschea54fba2013-01-07 16:04:48 +01005839 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshForwarding, 0, 1,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005840 mask, NL80211_MESHCONF_FORWARDING,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005841 nl80211_check_bool);
Chun-Yeow Yeoh83374fe2013-07-11 18:24:03 +08005842 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, rssi_threshold, -255, 0,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005843 mask, NL80211_MESHCONF_RSSI_THRESHOLD,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005844 nl80211_check_s32);
Masashi Honma97572352016-08-03 10:07:44 +09005845 /*
5846 * Check HT operation mode based on
5847 * IEEE 802.11 2012 8.4.2.59 HT Operation element.
5848 */
5849 if (tb[NL80211_MESHCONF_HT_OPMODE]) {
5850 ht_opmode = nla_get_u16(tb[NL80211_MESHCONF_HT_OPMODE]);
5851
5852 if (ht_opmode & ~(IEEE80211_HT_OP_MODE_PROTECTION |
5853 IEEE80211_HT_OP_MODE_NON_GF_STA_PRSNT |
5854 IEEE80211_HT_OP_MODE_NON_HT_STA_PRSNT))
5855 return -EINVAL;
5856
5857 if ((ht_opmode & IEEE80211_HT_OP_MODE_NON_GF_STA_PRSNT) &&
5858 (ht_opmode & IEEE80211_HT_OP_MODE_NON_HT_STA_PRSNT))
5859 return -EINVAL;
5860
5861 switch (ht_opmode & IEEE80211_HT_OP_MODE_PROTECTION) {
5862 case IEEE80211_HT_OP_MODE_PROTECTION_NONE:
5863 case IEEE80211_HT_OP_MODE_PROTECTION_20MHZ:
5864 if (ht_opmode & IEEE80211_HT_OP_MODE_NON_HT_STA_PRSNT)
5865 return -EINVAL;
5866 break;
5867 case IEEE80211_HT_OP_MODE_PROTECTION_NONMEMBER:
5868 case IEEE80211_HT_OP_MODE_PROTECTION_NONHT_MIXED:
5869 if (!(ht_opmode & IEEE80211_HT_OP_MODE_NON_HT_STA_PRSNT))
5870 return -EINVAL;
5871 break;
5872 }
5873 cfg->ht_opmode = ht_opmode;
5874 }
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08005875 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathToRootTimeout,
Marco Porschea54fba2013-01-07 16:04:48 +01005876 1, 65535, mask,
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08005877 NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005878 nl80211_check_u32);
Marco Porschea54fba2013-01-07 16:04:48 +01005879 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMProotInterval, 1, 65535,
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08005880 mask, NL80211_MESHCONF_HWMP_ROOT_INTERVAL,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005881 nl80211_check_u16);
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +08005882 FILL_IN_MESH_PARAM_IF_SET(tb, cfg,
Marco Porschea54fba2013-01-07 16:04:48 +01005883 dot11MeshHWMPconfirmationInterval,
5884 1, 65535, mask,
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +08005885 NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005886 nl80211_check_u16);
Marco Porsch3b1c5a52013-01-07 16:04:52 +01005887 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, power_mode,
5888 NL80211_MESH_POWER_ACTIVE,
5889 NL80211_MESH_POWER_MAX,
5890 mask, NL80211_MESHCONF_POWER_MODE,
Johannes Bergff9a71a2016-08-11 14:59:53 +02005891 nl80211_check_power_mode);
Marco Porsch3b1c5a52013-01-07 16:04:52 +01005892 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshAwakeWindowDuration,
5893 0, 65535, mask,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005894 NL80211_MESHCONF_AWAKE_WINDOW, nl80211_check_u16);
Masashi Honma31f909a2015-02-24 22:42:16 +09005895 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, plink_timeout, 0, 0xffffffff,
Colleen Twitty8e7c0532013-06-03 09:53:39 -07005896 mask, NL80211_MESHCONF_PLINK_TIMEOUT,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005897 nl80211_check_u32);
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005898 if (mask_out)
5899 *mask_out = mask;
Javier Cardonac80d5452010-12-16 17:37:49 -08005900
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005901 return 0;
5902
5903#undef FILL_IN_MESH_PARAM_IF_SET
5904}
5905
Javier Cardonac80d5452010-12-16 17:37:49 -08005906static int nl80211_parse_mesh_setup(struct genl_info *info,
5907 struct mesh_setup *setup)
5908{
Thomas Pedersenbb2798d2013-03-04 13:06:10 -08005909 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Javier Cardonac80d5452010-12-16 17:37:49 -08005910 struct nlattr *tb[NL80211_MESH_SETUP_ATTR_MAX + 1];
5911
5912 if (!info->attrs[NL80211_ATTR_MESH_SETUP])
5913 return -EINVAL;
5914 if (nla_parse_nested(tb, NL80211_MESH_SETUP_ATTR_MAX,
5915 info->attrs[NL80211_ATTR_MESH_SETUP],
5916 nl80211_mesh_setup_params_policy))
5917 return -EINVAL;
5918
Javier Cardonad299a1f2012-03-31 11:31:33 -07005919 if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC])
5920 setup->sync_method =
5921 (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC])) ?
5922 IEEE80211_SYNC_METHOD_VENDOR :
5923 IEEE80211_SYNC_METHOD_NEIGHBOR_OFFSET;
5924
Javier Cardonac80d5452010-12-16 17:37:49 -08005925 if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL])
5926 setup->path_sel_proto =
5927 (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL])) ?
5928 IEEE80211_PATH_PROTOCOL_VENDOR :
5929 IEEE80211_PATH_PROTOCOL_HWMP;
5930
5931 if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC])
5932 setup->path_metric =
5933 (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC])) ?
5934 IEEE80211_PATH_METRIC_VENDOR :
5935 IEEE80211_PATH_METRIC_AIRTIME;
5936
Javier Cardona581a8b02011-04-07 15:08:27 -07005937 if (tb[NL80211_MESH_SETUP_IE]) {
Javier Cardonac80d5452010-12-16 17:37:49 -08005938 struct nlattr *ieattr =
Javier Cardona581a8b02011-04-07 15:08:27 -07005939 tb[NL80211_MESH_SETUP_IE];
Javier Cardonac80d5452010-12-16 17:37:49 -08005940 if (!is_valid_ie_attr(ieattr))
5941 return -EINVAL;
Javier Cardona581a8b02011-04-07 15:08:27 -07005942 setup->ie = nla_data(ieattr);
5943 setup->ie_len = nla_len(ieattr);
Javier Cardonac80d5452010-12-16 17:37:49 -08005944 }
Thomas Pedersenbb2798d2013-03-04 13:06:10 -08005945 if (tb[NL80211_MESH_SETUP_USERSPACE_MPM] &&
5946 !(rdev->wiphy.features & NL80211_FEATURE_USERSPACE_MPM))
5947 return -EINVAL;
5948 setup->user_mpm = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_MPM]);
Javier Cardonab130e5c2011-05-03 16:57:07 -07005949 setup->is_authenticated = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AUTH]);
5950 setup->is_secure = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AMPE]);
Thomas Pedersenbb2798d2013-03-04 13:06:10 -08005951 if (setup->is_secure)
5952 setup->user_mpm = true;
Javier Cardonac80d5452010-12-16 17:37:49 -08005953
Colleen Twitty6e16d902013-05-08 11:45:59 -07005954 if (tb[NL80211_MESH_SETUP_AUTH_PROTOCOL]) {
5955 if (!setup->user_mpm)
5956 return -EINVAL;
5957 setup->auth_id =
5958 nla_get_u8(tb[NL80211_MESH_SETUP_AUTH_PROTOCOL]);
5959 }
5960
Javier Cardonac80d5452010-12-16 17:37:49 -08005961 return 0;
5962}
5963
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005964static int nl80211_update_mesh_config(struct sk_buff *skb,
Johannes Berg29cbe682010-12-03 09:20:44 +01005965 struct genl_info *info)
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005966{
5967 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5968 struct net_device *dev = info->user_ptr[1];
Johannes Berg29cbe682010-12-03 09:20:44 +01005969 struct wireless_dev *wdev = dev->ieee80211_ptr;
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005970 struct mesh_config cfg;
5971 u32 mask;
5972 int err;
5973
Johannes Berg29cbe682010-12-03 09:20:44 +01005974 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT)
5975 return -EOPNOTSUPP;
5976
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005977 if (!rdev->ops->update_mesh_config)
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005978 return -EOPNOTSUPP;
5979
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005980 err = nl80211_parse_mesh_config(info, &cfg, &mask);
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005981 if (err)
5982 return err;
5983
Johannes Berg29cbe682010-12-03 09:20:44 +01005984 wdev_lock(wdev);
5985 if (!wdev->mesh_id_len)
5986 err = -ENOLINK;
5987
5988 if (!err)
Hila Gonene35e4d22012-06-27 17:19:42 +03005989 err = rdev_update_mesh_config(rdev, dev, mask, &cfg);
Johannes Berg29cbe682010-12-03 09:20:44 +01005990
5991 wdev_unlock(wdev);
5992
5993 return err;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005994}
5995
Arik Nemtsovad30ca22014-12-15 19:25:59 +02005996static int nl80211_put_regdom(const struct ieee80211_regdomain *regdom,
5997 struct sk_buff *msg)
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005998{
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005999 struct nlattr *nl_reg_rules;
6000 unsigned int i;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08006001
Johannes Berg458f4f92012-12-06 15:47:38 +01006002 if (nla_put_string(msg, NL80211_ATTR_REG_ALPHA2, regdom->alpha2) ||
6003 (regdom->dfs_region &&
6004 nla_put_u8(msg, NL80211_ATTR_DFS_REGION, regdom->dfs_region)))
Arik Nemtsovad30ca22014-12-15 19:25:59 +02006005 goto nla_put_failure;
Johannes Berg458f4f92012-12-06 15:47:38 +01006006
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08006007 nl_reg_rules = nla_nest_start(msg, NL80211_ATTR_REG_RULES);
6008 if (!nl_reg_rules)
Arik Nemtsovad30ca22014-12-15 19:25:59 +02006009 goto nla_put_failure;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08006010
Johannes Berg458f4f92012-12-06 15:47:38 +01006011 for (i = 0; i < regdom->n_reg_rules; i++) {
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08006012 struct nlattr *nl_reg_rule;
6013 const struct ieee80211_reg_rule *reg_rule;
6014 const struct ieee80211_freq_range *freq_range;
6015 const struct ieee80211_power_rule *power_rule;
Janusz Dziedzic97524822014-01-30 09:52:20 +01006016 unsigned int max_bandwidth_khz;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08006017
Johannes Berg458f4f92012-12-06 15:47:38 +01006018 reg_rule = &regdom->reg_rules[i];
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08006019 freq_range = &reg_rule->freq_range;
6020 power_rule = &reg_rule->power_rule;
6021
6022 nl_reg_rule = nla_nest_start(msg, i);
6023 if (!nl_reg_rule)
Arik Nemtsovad30ca22014-12-15 19:25:59 +02006024 goto nla_put_failure;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08006025
Janusz Dziedzic97524822014-01-30 09:52:20 +01006026 max_bandwidth_khz = freq_range->max_bandwidth_khz;
6027 if (!max_bandwidth_khz)
6028 max_bandwidth_khz = reg_get_max_bandwidth(regdom,
6029 reg_rule);
6030
David S. Miller9360ffd2012-03-29 04:41:26 -04006031 if (nla_put_u32(msg, NL80211_ATTR_REG_RULE_FLAGS,
6032 reg_rule->flags) ||
6033 nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_START,
6034 freq_range->start_freq_khz) ||
6035 nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_END,
6036 freq_range->end_freq_khz) ||
6037 nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_MAX_BW,
Janusz Dziedzic97524822014-01-30 09:52:20 +01006038 max_bandwidth_khz) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04006039 nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN,
6040 power_rule->max_antenna_gain) ||
6041 nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_EIRP,
Janusz Dziedzic089027e2014-02-21 19:46:12 +01006042 power_rule->max_eirp) ||
6043 nla_put_u32(msg, NL80211_ATTR_DFS_CAC_TIME,
6044 reg_rule->dfs_cac_ms))
Arik Nemtsovad30ca22014-12-15 19:25:59 +02006045 goto nla_put_failure;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08006046
6047 nla_nest_end(msg, nl_reg_rule);
6048 }
6049
6050 nla_nest_end(msg, nl_reg_rules);
Arik Nemtsovad30ca22014-12-15 19:25:59 +02006051 return 0;
6052
6053nla_put_failure:
6054 return -EMSGSIZE;
6055}
6056
6057static int nl80211_get_reg_do(struct sk_buff *skb, struct genl_info *info)
6058{
6059 const struct ieee80211_regdomain *regdom = NULL;
6060 struct cfg80211_registered_device *rdev;
6061 struct wiphy *wiphy = NULL;
6062 struct sk_buff *msg;
6063 void *hdr;
6064
6065 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
6066 if (!msg)
6067 return -ENOBUFS;
6068
6069 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
6070 NL80211_CMD_GET_REG);
6071 if (!hdr)
6072 goto put_failure;
6073
6074 if (info->attrs[NL80211_ATTR_WIPHY]) {
Arik Nemtsov1bdd7162014-12-15 19:26:01 +02006075 bool self_managed;
6076
Arik Nemtsovad30ca22014-12-15 19:25:59 +02006077 rdev = cfg80211_get_dev_from_info(genl_info_net(info), info);
6078 if (IS_ERR(rdev)) {
6079 nlmsg_free(msg);
6080 return PTR_ERR(rdev);
6081 }
6082
6083 wiphy = &rdev->wiphy;
Arik Nemtsov1bdd7162014-12-15 19:26:01 +02006084 self_managed = wiphy->regulatory_flags &
6085 REGULATORY_WIPHY_SELF_MANAGED;
Arik Nemtsovad30ca22014-12-15 19:25:59 +02006086 regdom = get_wiphy_regdom(wiphy);
6087
Arik Nemtsov1bdd7162014-12-15 19:26:01 +02006088 /* a self-managed-reg device must have a private regdom */
6089 if (WARN_ON(!regdom && self_managed)) {
6090 nlmsg_free(msg);
6091 return -EINVAL;
6092 }
6093
Arik Nemtsovad30ca22014-12-15 19:25:59 +02006094 if (regdom &&
6095 nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy)))
6096 goto nla_put_failure;
6097 }
6098
6099 if (!wiphy && reg_last_request_cell_base() &&
6100 nla_put_u32(msg, NL80211_ATTR_USER_REG_HINT_TYPE,
6101 NL80211_USER_REG_HINT_CELL_BASE))
6102 goto nla_put_failure;
6103
6104 rcu_read_lock();
6105
6106 if (!regdom)
6107 regdom = rcu_dereference(cfg80211_regdomain);
6108
6109 if (nl80211_put_regdom(regdom, msg))
6110 goto nla_put_failure_rcu;
6111
6112 rcu_read_unlock();
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08006113
6114 genlmsg_end(msg, hdr);
Johannes Berg5fe231e2013-05-08 21:45:15 +02006115 return genlmsg_reply(msg, info);
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08006116
Johannes Berg458f4f92012-12-06 15:47:38 +01006117nla_put_failure_rcu:
6118 rcu_read_unlock();
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08006119nla_put_failure:
6120 genlmsg_cancel(msg, hdr);
Julia Lawallefe1cf02011-01-28 15:17:11 +01006121put_failure:
Yuri Ershovd080e272010-06-29 15:08:07 +04006122 nlmsg_free(msg);
Johannes Berg5fe231e2013-05-08 21:45:15 +02006123 return -EMSGSIZE;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08006124}
6125
Arik Nemtsovad30ca22014-12-15 19:25:59 +02006126static int nl80211_send_regdom(struct sk_buff *msg, struct netlink_callback *cb,
6127 u32 seq, int flags, struct wiphy *wiphy,
6128 const struct ieee80211_regdomain *regdom)
6129{
6130 void *hdr = nl80211hdr_put(msg, NETLINK_CB(cb->skb).portid, seq, flags,
6131 NL80211_CMD_GET_REG);
6132
6133 if (!hdr)
6134 return -1;
6135
6136 genl_dump_check_consistent(cb, hdr, &nl80211_fam);
6137
6138 if (nl80211_put_regdom(regdom, msg))
6139 goto nla_put_failure;
6140
6141 if (!wiphy && reg_last_request_cell_base() &&
6142 nla_put_u32(msg, NL80211_ATTR_USER_REG_HINT_TYPE,
6143 NL80211_USER_REG_HINT_CELL_BASE))
6144 goto nla_put_failure;
6145
6146 if (wiphy &&
6147 nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy)))
6148 goto nla_put_failure;
6149
Arik Nemtsov1bdd7162014-12-15 19:26:01 +02006150 if (wiphy && wiphy->regulatory_flags & REGULATORY_WIPHY_SELF_MANAGED &&
6151 nla_put_flag(msg, NL80211_ATTR_WIPHY_SELF_MANAGED_REG))
6152 goto nla_put_failure;
6153
Johannes Berg053c0952015-01-16 22:09:00 +01006154 genlmsg_end(msg, hdr);
6155 return 0;
Arik Nemtsovad30ca22014-12-15 19:25:59 +02006156
6157nla_put_failure:
6158 genlmsg_cancel(msg, hdr);
6159 return -EMSGSIZE;
6160}
6161
6162static int nl80211_get_reg_dump(struct sk_buff *skb,
6163 struct netlink_callback *cb)
6164{
6165 const struct ieee80211_regdomain *regdom = NULL;
6166 struct cfg80211_registered_device *rdev;
6167 int err, reg_idx, start = cb->args[2];
6168
6169 rtnl_lock();
6170
6171 if (cfg80211_regdomain && start == 0) {
6172 err = nl80211_send_regdom(skb, cb, cb->nlh->nlmsg_seq,
6173 NLM_F_MULTI, NULL,
6174 rtnl_dereference(cfg80211_regdomain));
6175 if (err < 0)
6176 goto out_err;
6177 }
6178
6179 /* the global regdom is idx 0 */
6180 reg_idx = 1;
6181 list_for_each_entry(rdev, &cfg80211_rdev_list, list) {
6182 regdom = get_wiphy_regdom(&rdev->wiphy);
6183 if (!regdom)
6184 continue;
6185
6186 if (++reg_idx <= start)
6187 continue;
6188
6189 err = nl80211_send_regdom(skb, cb, cb->nlh->nlmsg_seq,
6190 NLM_F_MULTI, &rdev->wiphy, regdom);
6191 if (err < 0) {
6192 reg_idx--;
6193 break;
6194 }
6195 }
6196
6197 cb->args[2] = reg_idx;
6198 err = skb->len;
6199out_err:
6200 rtnl_unlock();
6201 return err;
6202}
6203
Johannes Bergb6863032015-10-15 09:25:18 +02006204#ifdef CONFIG_CFG80211_CRDA_SUPPORT
6205static const struct nla_policy reg_rule_policy[NL80211_REG_RULE_ATTR_MAX + 1] = {
6206 [NL80211_ATTR_REG_RULE_FLAGS] = { .type = NLA_U32 },
6207 [NL80211_ATTR_FREQ_RANGE_START] = { .type = NLA_U32 },
6208 [NL80211_ATTR_FREQ_RANGE_END] = { .type = NLA_U32 },
6209 [NL80211_ATTR_FREQ_RANGE_MAX_BW] = { .type = NLA_U32 },
6210 [NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN] = { .type = NLA_U32 },
6211 [NL80211_ATTR_POWER_RULE_MAX_EIRP] = { .type = NLA_U32 },
6212 [NL80211_ATTR_DFS_CAC_TIME] = { .type = NLA_U32 },
6213};
6214
6215static int parse_reg_rule(struct nlattr *tb[],
6216 struct ieee80211_reg_rule *reg_rule)
6217{
6218 struct ieee80211_freq_range *freq_range = &reg_rule->freq_range;
6219 struct ieee80211_power_rule *power_rule = &reg_rule->power_rule;
6220
6221 if (!tb[NL80211_ATTR_REG_RULE_FLAGS])
6222 return -EINVAL;
6223 if (!tb[NL80211_ATTR_FREQ_RANGE_START])
6224 return -EINVAL;
6225 if (!tb[NL80211_ATTR_FREQ_RANGE_END])
6226 return -EINVAL;
6227 if (!tb[NL80211_ATTR_FREQ_RANGE_MAX_BW])
6228 return -EINVAL;
6229 if (!tb[NL80211_ATTR_POWER_RULE_MAX_EIRP])
6230 return -EINVAL;
6231
6232 reg_rule->flags = nla_get_u32(tb[NL80211_ATTR_REG_RULE_FLAGS]);
6233
6234 freq_range->start_freq_khz =
6235 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_START]);
6236 freq_range->end_freq_khz =
6237 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_END]);
6238 freq_range->max_bandwidth_khz =
6239 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]);
6240
6241 power_rule->max_eirp =
6242 nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]);
6243
6244 if (tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN])
6245 power_rule->max_antenna_gain =
6246 nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]);
6247
6248 if (tb[NL80211_ATTR_DFS_CAC_TIME])
6249 reg_rule->dfs_cac_ms =
6250 nla_get_u32(tb[NL80211_ATTR_DFS_CAC_TIME]);
6251
6252 return 0;
6253}
6254
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07006255static int nl80211_set_reg(struct sk_buff *skb, struct genl_info *info)
6256{
6257 struct nlattr *tb[NL80211_REG_RULE_ATTR_MAX + 1];
6258 struct nlattr *nl_reg_rule;
Johannes Bergea372c52014-11-28 14:54:31 +01006259 char *alpha2;
6260 int rem_reg_rules, r;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07006261 u32 num_rules = 0, rule_idx = 0, size_of_regd;
Luis R. Rodriguez4c7d3982013-11-13 18:54:02 +01006262 enum nl80211_dfs_regions dfs_region = NL80211_DFS_UNSET;
Johannes Bergea372c52014-11-28 14:54:31 +01006263 struct ieee80211_regdomain *rd;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07006264
6265 if (!info->attrs[NL80211_ATTR_REG_ALPHA2])
6266 return -EINVAL;
6267
6268 if (!info->attrs[NL80211_ATTR_REG_RULES])
6269 return -EINVAL;
6270
6271 alpha2 = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]);
6272
Luis R. Rodriguez8b60b072011-10-11 10:59:02 -07006273 if (info->attrs[NL80211_ATTR_DFS_REGION])
6274 dfs_region = nla_get_u8(info->attrs[NL80211_ATTR_DFS_REGION]);
6275
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07006276 nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES],
Johannes Berg1a919312012-12-03 17:21:11 +01006277 rem_reg_rules) {
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07006278 num_rules++;
6279 if (num_rules > NL80211_MAX_SUPP_REG_RULES)
Luis R. Rodriguez4776c6e2009-05-13 17:04:39 -04006280 return -EINVAL;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07006281 }
6282
Luis R. Rodrigueze4387682013-11-05 09:18:01 -08006283 if (!reg_is_valid_request(alpha2))
6284 return -EINVAL;
6285
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07006286 size_of_regd = sizeof(struct ieee80211_regdomain) +
Johannes Berg1a919312012-12-03 17:21:11 +01006287 num_rules * sizeof(struct ieee80211_reg_rule);
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07006288
6289 rd = kzalloc(size_of_regd, GFP_KERNEL);
Johannes Berg6913b492012-12-04 00:48:59 +01006290 if (!rd)
6291 return -ENOMEM;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07006292
6293 rd->n_reg_rules = num_rules;
6294 rd->alpha2[0] = alpha2[0];
6295 rd->alpha2[1] = alpha2[1];
6296
Luis R. Rodriguez8b60b072011-10-11 10:59:02 -07006297 /*
6298 * Disable DFS master mode if the DFS region was
6299 * not supported or known on this kernel.
6300 */
6301 if (reg_supported_dfs_region(dfs_region))
6302 rd->dfs_region = dfs_region;
6303
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07006304 nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES],
Johannes Berg1a919312012-12-03 17:21:11 +01006305 rem_reg_rules) {
Johannes Bergae811e22014-01-24 10:17:47 +01006306 r = nla_parse(tb, NL80211_REG_RULE_ATTR_MAX,
6307 nla_data(nl_reg_rule), nla_len(nl_reg_rule),
6308 reg_rule_policy);
6309 if (r)
6310 goto bad_reg;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07006311 r = parse_reg_rule(tb, &rd->reg_rules[rule_idx]);
6312 if (r)
6313 goto bad_reg;
6314
6315 rule_idx++;
6316
Luis R. Rodriguezd0e18f82009-05-13 17:04:40 -04006317 if (rule_idx > NL80211_MAX_SUPP_REG_RULES) {
6318 r = -EINVAL;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07006319 goto bad_reg;
Luis R. Rodriguezd0e18f82009-05-13 17:04:40 -04006320 }
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07006321 }
6322
Johannes Berg06627992016-06-09 10:40:09 +02006323 /* set_regdom takes ownership of rd */
6324 return set_regdom(rd, REGD_SOURCE_CRDA);
Johannes Bergd2372b32008-10-24 20:32:20 +02006325 bad_reg:
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07006326 kfree(rd);
Luis R. Rodriguezd0e18f82009-05-13 17:04:40 -04006327 return r;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07006328}
Johannes Bergb6863032015-10-15 09:25:18 +02006329#endif /* CONFIG_CFG80211_CRDA_SUPPORT */
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07006330
Johannes Berg83f5e2c2009-06-17 17:41:49 +02006331static int validate_scan_freqs(struct nlattr *freqs)
6332{
6333 struct nlattr *attr1, *attr2;
6334 int n_channels = 0, tmp1, tmp2;
6335
6336 nla_for_each_nested(attr1, freqs, tmp1) {
6337 n_channels++;
6338 /*
6339 * Some hardware has a limited channel list for
6340 * scanning, and it is pretty much nonsensical
6341 * to scan for a channel twice, so disallow that
6342 * and don't require drivers to check that the
6343 * channel list they get isn't longer than what
6344 * they can scan, as long as they can scan all
6345 * the channels they registered at once.
6346 */
6347 nla_for_each_nested(attr2, freqs, tmp2)
6348 if (attr1 != attr2 &&
6349 nla_get_u32(attr1) == nla_get_u32(attr2))
6350 return 0;
6351 }
6352
6353 return n_channels;
6354}
6355
Johannes Berg57fbcce2016-04-12 15:56:15 +02006356static bool is_band_valid(struct wiphy *wiphy, enum nl80211_band b)
Arend van Spriel38de03d2016-03-02 20:37:18 +01006357{
Johannes Berg57fbcce2016-04-12 15:56:15 +02006358 return b < NUM_NL80211_BANDS && wiphy->bands[b];
Arend van Spriel38de03d2016-03-02 20:37:18 +01006359}
6360
6361static int parse_bss_select(struct nlattr *nla, struct wiphy *wiphy,
6362 struct cfg80211_bss_selection *bss_select)
6363{
6364 struct nlattr *attr[NL80211_BSS_SELECT_ATTR_MAX + 1];
6365 struct nlattr *nest;
6366 int err;
6367 bool found = false;
6368 int i;
6369
6370 /* only process one nested attribute */
6371 nest = nla_data(nla);
6372 if (!nla_ok(nest, nla_len(nest)))
6373 return -EINVAL;
6374
6375 err = nla_parse(attr, NL80211_BSS_SELECT_ATTR_MAX, nla_data(nest),
6376 nla_len(nest), nl80211_bss_select_policy);
6377 if (err)
6378 return err;
6379
6380 /* only one attribute may be given */
6381 for (i = 0; i <= NL80211_BSS_SELECT_ATTR_MAX; i++) {
6382 if (attr[i]) {
6383 if (found)
6384 return -EINVAL;
6385 found = true;
6386 }
6387 }
6388
6389 bss_select->behaviour = __NL80211_BSS_SELECT_ATTR_INVALID;
6390
6391 if (attr[NL80211_BSS_SELECT_ATTR_RSSI])
6392 bss_select->behaviour = NL80211_BSS_SELECT_ATTR_RSSI;
6393
6394 if (attr[NL80211_BSS_SELECT_ATTR_BAND_PREF]) {
6395 bss_select->behaviour = NL80211_BSS_SELECT_ATTR_BAND_PREF;
6396 bss_select->param.band_pref =
6397 nla_get_u32(attr[NL80211_BSS_SELECT_ATTR_BAND_PREF]);
6398 if (!is_band_valid(wiphy, bss_select->param.band_pref))
6399 return -EINVAL;
6400 }
6401
6402 if (attr[NL80211_BSS_SELECT_ATTR_RSSI_ADJUST]) {
6403 struct nl80211_bss_select_rssi_adjust *adj_param;
6404
6405 adj_param = nla_data(attr[NL80211_BSS_SELECT_ATTR_RSSI_ADJUST]);
6406 bss_select->behaviour = NL80211_BSS_SELECT_ATTR_RSSI_ADJUST;
6407 bss_select->param.adjust.band = adj_param->band;
6408 bss_select->param.adjust.delta = adj_param->delta;
6409 if (!is_band_valid(wiphy, bss_select->param.adjust.band))
6410 return -EINVAL;
6411 }
6412
6413 /* user-space did not provide behaviour attribute */
6414 if (bss_select->behaviour == __NL80211_BSS_SELECT_ATTR_INVALID)
6415 return -EINVAL;
6416
6417 if (!(wiphy->bss_select_support & BIT(bss_select->behaviour)))
6418 return -EINVAL;
6419
6420 return 0;
6421}
6422
Johannes Bergad2b26a2014-06-12 21:39:05 +02006423static int nl80211_parse_random_mac(struct nlattr **attrs,
6424 u8 *mac_addr, u8 *mac_addr_mask)
6425{
6426 int i;
6427
6428 if (!attrs[NL80211_ATTR_MAC] && !attrs[NL80211_ATTR_MAC_MASK]) {
Joe Perchesd2beae12015-03-02 19:54:58 -08006429 eth_zero_addr(mac_addr);
6430 eth_zero_addr(mac_addr_mask);
Johannes Bergad2b26a2014-06-12 21:39:05 +02006431 mac_addr[0] = 0x2;
6432 mac_addr_mask[0] = 0x3;
6433
6434 return 0;
6435 }
6436
6437 /* need both or none */
6438 if (!attrs[NL80211_ATTR_MAC] || !attrs[NL80211_ATTR_MAC_MASK])
6439 return -EINVAL;
6440
6441 memcpy(mac_addr, nla_data(attrs[NL80211_ATTR_MAC]), ETH_ALEN);
6442 memcpy(mac_addr_mask, nla_data(attrs[NL80211_ATTR_MAC_MASK]), ETH_ALEN);
6443
6444 /* don't allow or configure an mcast address */
6445 if (!is_multicast_ether_addr(mac_addr_mask) ||
6446 is_multicast_ether_addr(mac_addr))
6447 return -EINVAL;
6448
6449 /*
6450 * allow users to pass a MAC address that has bits set outside
6451 * of the mask, but don't bother drivers with having to deal
6452 * with such bits
6453 */
6454 for (i = 0; i < ETH_ALEN; i++)
6455 mac_addr[i] &= mac_addr_mask[i];
6456
6457 return 0;
6458}
6459
Johannes Berg2a519312009-02-10 21:25:55 +01006460static int nl80211_trigger_scan(struct sk_buff *skb, struct genl_info *info)
6461{
Johannes Berg4c476992010-10-04 21:36:35 +02006462 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Bergfd014282012-06-18 19:17:03 +02006463 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg2a519312009-02-10 21:25:55 +01006464 struct cfg80211_scan_request *request;
Johannes Berg2a519312009-02-10 21:25:55 +01006465 struct nlattr *attr;
6466 struct wiphy *wiphy;
Johannes Berg83f5e2c2009-06-17 17:41:49 +02006467 int err, tmp, n_ssids = 0, n_channels, i;
Jouni Malinen70692ad2009-02-16 19:39:13 +02006468 size_t ie_len;
Johannes Berg2a519312009-02-10 21:25:55 +01006469
Johannes Bergf4a11bb2009-03-27 12:40:28 +01006470 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
6471 return -EINVAL;
6472
Johannes Berg79c97e92009-07-07 03:56:12 +02006473 wiphy = &rdev->wiphy;
Johannes Berg2a519312009-02-10 21:25:55 +01006474
Ayala Bekercb3b7d82016-09-20 17:31:13 +03006475 if (wdev->iftype == NL80211_IFTYPE_NAN)
6476 return -EOPNOTSUPP;
6477
Johannes Berg4c476992010-10-04 21:36:35 +02006478 if (!rdev->ops->scan)
6479 return -EOPNOTSUPP;
Johannes Berg2a519312009-02-10 21:25:55 +01006480
Johannes Bergf9d15d12014-01-22 11:14:19 +02006481 if (rdev->scan_req || rdev->scan_msg) {
Johannes Bergf9f47522013-03-19 15:04:07 +01006482 err = -EBUSY;
6483 goto unlock;
6484 }
Johannes Berg2a519312009-02-10 21:25:55 +01006485
6486 if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
Johannes Berg83f5e2c2009-06-17 17:41:49 +02006487 n_channels = validate_scan_freqs(
6488 info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]);
Johannes Bergf9f47522013-03-19 15:04:07 +01006489 if (!n_channels) {
6490 err = -EINVAL;
6491 goto unlock;
6492 }
Johannes Berg2a519312009-02-10 21:25:55 +01006493 } else {
Ilan Peerbdfbec22014-01-09 11:37:23 +02006494 n_channels = ieee80211_get_num_supported_channels(wiphy);
Johannes Berg2a519312009-02-10 21:25:55 +01006495 }
6496
6497 if (info->attrs[NL80211_ATTR_SCAN_SSIDS])
6498 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp)
6499 n_ssids++;
6500
Johannes Bergf9f47522013-03-19 15:04:07 +01006501 if (n_ssids > wiphy->max_scan_ssids) {
6502 err = -EINVAL;
6503 goto unlock;
6504 }
Johannes Berg2a519312009-02-10 21:25:55 +01006505
Jouni Malinen70692ad2009-02-16 19:39:13 +02006506 if (info->attrs[NL80211_ATTR_IE])
6507 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
6508 else
6509 ie_len = 0;
6510
Johannes Bergf9f47522013-03-19 15:04:07 +01006511 if (ie_len > wiphy->max_scan_ie_len) {
6512 err = -EINVAL;
6513 goto unlock;
6514 }
Johannes Berg18a83652009-03-31 12:12:05 +02006515
Johannes Berg2a519312009-02-10 21:25:55 +01006516 request = kzalloc(sizeof(*request)
Luciano Coelhoa2cd43c2011-05-18 11:42:03 +03006517 + sizeof(*request->ssids) * n_ssids
6518 + sizeof(*request->channels) * n_channels
Jouni Malinen70692ad2009-02-16 19:39:13 +02006519 + ie_len, GFP_KERNEL);
Johannes Bergf9f47522013-03-19 15:04:07 +01006520 if (!request) {
6521 err = -ENOMEM;
6522 goto unlock;
6523 }
Johannes Berg2a519312009-02-10 21:25:55 +01006524
Johannes Berg2a519312009-02-10 21:25:55 +01006525 if (n_ssids)
Johannes Berg5ba63532009-08-07 17:54:07 +02006526 request->ssids = (void *)&request->channels[n_channels];
Johannes Berg2a519312009-02-10 21:25:55 +01006527 request->n_ssids = n_ssids;
Jouni Malinen70692ad2009-02-16 19:39:13 +02006528 if (ie_len) {
Johannes Berg13874e42015-01-23 11:25:20 +01006529 if (n_ssids)
Jouni Malinen70692ad2009-02-16 19:39:13 +02006530 request->ie = (void *)(request->ssids + n_ssids);
6531 else
6532 request->ie = (void *)(request->channels + n_channels);
6533 }
Johannes Berg2a519312009-02-10 21:25:55 +01006534
Johannes Berg584991d2009-11-02 13:32:03 +01006535 i = 0;
Johannes Berg2a519312009-02-10 21:25:55 +01006536 if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
6537 /* user specified, bail out if channel not found */
Johannes Berg2a519312009-02-10 21:25:55 +01006538 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_FREQUENCIES], tmp) {
Johannes Berg584991d2009-11-02 13:32:03 +01006539 struct ieee80211_channel *chan;
6540
6541 chan = ieee80211_get_channel(wiphy, nla_get_u32(attr));
6542
6543 if (!chan) {
Johannes Berg2a519312009-02-10 21:25:55 +01006544 err = -EINVAL;
6545 goto out_free;
6546 }
Johannes Berg584991d2009-11-02 13:32:03 +01006547
6548 /* ignore disabled channels */
6549 if (chan->flags & IEEE80211_CHAN_DISABLED)
6550 continue;
6551
6552 request->channels[i] = chan;
Johannes Berg2a519312009-02-10 21:25:55 +01006553 i++;
6554 }
6555 } else {
Johannes Berg57fbcce2016-04-12 15:56:15 +02006556 enum nl80211_band band;
Johannes Berg34850ab2011-07-18 18:08:35 +02006557
Johannes Berg2a519312009-02-10 21:25:55 +01006558 /* all channels */
Johannes Berg57fbcce2016-04-12 15:56:15 +02006559 for (band = 0; band < NUM_NL80211_BANDS; band++) {
Johannes Berg2a519312009-02-10 21:25:55 +01006560 int j;
Kirtika Ruchandani7a087e72016-05-29 19:51:23 -07006561
Johannes Berg2a519312009-02-10 21:25:55 +01006562 if (!wiphy->bands[band])
6563 continue;
6564 for (j = 0; j < wiphy->bands[band]->n_channels; j++) {
Johannes Berg584991d2009-11-02 13:32:03 +01006565 struct ieee80211_channel *chan;
6566
6567 chan = &wiphy->bands[band]->channels[j];
6568
6569 if (chan->flags & IEEE80211_CHAN_DISABLED)
6570 continue;
6571
6572 request->channels[i] = chan;
Johannes Berg2a519312009-02-10 21:25:55 +01006573 i++;
6574 }
6575 }
6576 }
6577
Johannes Berg584991d2009-11-02 13:32:03 +01006578 if (!i) {
6579 err = -EINVAL;
6580 goto out_free;
6581 }
6582
6583 request->n_channels = i;
6584
Johannes Berg2a519312009-02-10 21:25:55 +01006585 i = 0;
Johannes Berg13874e42015-01-23 11:25:20 +01006586 if (n_ssids) {
Johannes Berg2a519312009-02-10 21:25:55 +01006587 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) {
Luciano Coelho57a27e12011-06-07 20:42:26 +03006588 if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) {
Johannes Berg2a519312009-02-10 21:25:55 +01006589 err = -EINVAL;
6590 goto out_free;
6591 }
Luciano Coelho57a27e12011-06-07 20:42:26 +03006592 request->ssids[i].ssid_len = nla_len(attr);
Johannes Berg2a519312009-02-10 21:25:55 +01006593 memcpy(request->ssids[i].ssid, nla_data(attr), nla_len(attr));
Johannes Berg2a519312009-02-10 21:25:55 +01006594 i++;
6595 }
6596 }
6597
Jouni Malinen70692ad2009-02-16 19:39:13 +02006598 if (info->attrs[NL80211_ATTR_IE]) {
6599 request->ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Johannes Bergde95a54b2009-04-01 11:58:36 +02006600 memcpy((void *)request->ie,
6601 nla_data(info->attrs[NL80211_ATTR_IE]),
Jouni Malinen70692ad2009-02-16 19:39:13 +02006602 request->ie_len);
6603 }
6604
Johannes Berg57fbcce2016-04-12 15:56:15 +02006605 for (i = 0; i < NUM_NL80211_BANDS; i++)
Johannes Berga401d2b2011-07-20 00:52:16 +02006606 if (wiphy->bands[i])
6607 request->rates[i] =
6608 (1 << wiphy->bands[i]->n_bitrates) - 1;
Johannes Berg34850ab2011-07-18 18:08:35 +02006609
6610 if (info->attrs[NL80211_ATTR_SCAN_SUPP_RATES]) {
6611 nla_for_each_nested(attr,
6612 info->attrs[NL80211_ATTR_SCAN_SUPP_RATES],
6613 tmp) {
Johannes Berg57fbcce2016-04-12 15:56:15 +02006614 enum nl80211_band band = nla_type(attr);
Johannes Berg34850ab2011-07-18 18:08:35 +02006615
Johannes Berg57fbcce2016-04-12 15:56:15 +02006616 if (band < 0 || band >= NUM_NL80211_BANDS) {
Johannes Berg34850ab2011-07-18 18:08:35 +02006617 err = -EINVAL;
6618 goto out_free;
6619 }
Felix Fietkau1b09cd82013-11-20 19:40:41 +01006620
6621 if (!wiphy->bands[band])
6622 continue;
6623
Johannes Berg34850ab2011-07-18 18:08:35 +02006624 err = ieee80211_get_ratemask(wiphy->bands[band],
6625 nla_data(attr),
6626 nla_len(attr),
6627 &request->rates[band]);
6628 if (err)
6629 goto out_free;
6630 }
6631 }
6632
Avraham Stern1d762502016-07-05 17:10:13 +03006633 if (info->attrs[NL80211_ATTR_MEASUREMENT_DURATION]) {
6634 if (!wiphy_ext_feature_isset(wiphy,
6635 NL80211_EXT_FEATURE_SET_SCAN_DWELL)) {
6636 err = -EOPNOTSUPP;
6637 goto out_free;
6638 }
6639
6640 request->duration =
6641 nla_get_u16(info->attrs[NL80211_ATTR_MEASUREMENT_DURATION]);
6642 request->duration_mandatory =
6643 nla_get_flag(info->attrs[NL80211_ATTR_MEASUREMENT_DURATION_MANDATORY]);
6644 }
6645
Sam Leffler46856bb2012-10-11 21:03:32 -07006646 if (info->attrs[NL80211_ATTR_SCAN_FLAGS]) {
Sam Lefflered4737712012-10-11 21:03:31 -07006647 request->flags = nla_get_u32(
6648 info->attrs[NL80211_ATTR_SCAN_FLAGS]);
Johannes Berg00c3a6e2013-10-26 17:14:38 +02006649 if ((request->flags & NL80211_SCAN_FLAG_LOW_PRIORITY) &&
6650 !(wiphy->features & NL80211_FEATURE_LOW_PRIORITY_SCAN)) {
Sam Leffler46856bb2012-10-11 21:03:32 -07006651 err = -EOPNOTSUPP;
6652 goto out_free;
6653 }
Johannes Bergad2b26a2014-06-12 21:39:05 +02006654
6655 if (request->flags & NL80211_SCAN_FLAG_RANDOM_ADDR) {
6656 if (!(wiphy->features &
6657 NL80211_FEATURE_SCAN_RANDOM_MAC_ADDR)) {
6658 err = -EOPNOTSUPP;
6659 goto out_free;
6660 }
6661
6662 if (wdev->current_bss) {
6663 err = -EOPNOTSUPP;
6664 goto out_free;
6665 }
6666
6667 err = nl80211_parse_random_mac(info->attrs,
6668 request->mac_addr,
6669 request->mac_addr_mask);
6670 if (err)
6671 goto out_free;
6672 }
Sam Leffler46856bb2012-10-11 21:03:32 -07006673 }
Sam Lefflered4737712012-10-11 21:03:31 -07006674
Rajkumar Manoharane9f935e2011-09-25 14:53:30 +05306675 request->no_cck =
6676 nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]);
6677
Jouni Malinen818965d2016-02-26 22:12:47 +02006678 if (info->attrs[NL80211_ATTR_MAC])
6679 memcpy(request->bssid, nla_data(info->attrs[NL80211_ATTR_MAC]),
6680 ETH_ALEN);
6681 else
6682 eth_broadcast_addr(request->bssid);
6683
Johannes Bergfd014282012-06-18 19:17:03 +02006684 request->wdev = wdev;
Johannes Berg79c97e92009-07-07 03:56:12 +02006685 request->wiphy = &rdev->wiphy;
Sam Leffler15d60302012-10-11 21:03:34 -07006686 request->scan_start = jiffies;
Johannes Berg2a519312009-02-10 21:25:55 +01006687
Johannes Berg79c97e92009-07-07 03:56:12 +02006688 rdev->scan_req = request;
Hila Gonene35e4d22012-06-27 17:19:42 +03006689 err = rdev_scan(rdev, request);
Johannes Berg2a519312009-02-10 21:25:55 +01006690
Johannes Berg463d0182009-07-14 00:33:35 +02006691 if (!err) {
Johannes Bergfd014282012-06-18 19:17:03 +02006692 nl80211_send_scan_start(rdev, wdev);
6693 if (wdev->netdev)
6694 dev_hold(wdev->netdev);
Johannes Berg4c476992010-10-04 21:36:35 +02006695 } else {
Johannes Berg2a519312009-02-10 21:25:55 +01006696 out_free:
Johannes Berg79c97e92009-07-07 03:56:12 +02006697 rdev->scan_req = NULL;
Johannes Berg2a519312009-02-10 21:25:55 +01006698 kfree(request);
6699 }
Johannes Berg3b858752009-03-12 09:55:09 +01006700
Johannes Bergf9f47522013-03-19 15:04:07 +01006701 unlock:
Johannes Berg2a519312009-02-10 21:25:55 +01006702 return err;
6703}
6704
Vidyullatha Kanchanapally91d3ab42015-10-30 19:14:49 +05306705static int nl80211_abort_scan(struct sk_buff *skb, struct genl_info *info)
6706{
6707 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6708 struct wireless_dev *wdev = info->user_ptr[1];
6709
6710 if (!rdev->ops->abort_scan)
6711 return -EOPNOTSUPP;
6712
6713 if (rdev->scan_msg)
6714 return 0;
6715
6716 if (!rdev->scan_req)
6717 return -ENOENT;
6718
6719 rdev_abort_scan(rdev, wdev);
6720 return 0;
6721}
6722
Avraham Stern3b06d272015-10-12 09:51:34 +03006723static int
6724nl80211_parse_sched_scan_plans(struct wiphy *wiphy, int n_plans,
6725 struct cfg80211_sched_scan_request *request,
6726 struct nlattr **attrs)
6727{
6728 int tmp, err, i = 0;
6729 struct nlattr *attr;
6730
6731 if (!attrs[NL80211_ATTR_SCHED_SCAN_PLANS]) {
6732 u32 interval;
6733
6734 /*
6735 * If scan plans are not specified,
6736 * %NL80211_ATTR_SCHED_SCAN_INTERVAL must be specified. In this
6737 * case one scan plan will be set with the specified scan
6738 * interval and infinite number of iterations.
6739 */
6740 if (!attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL])
6741 return -EINVAL;
6742
6743 interval = nla_get_u32(attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]);
6744 if (!interval)
6745 return -EINVAL;
6746
6747 request->scan_plans[0].interval =
6748 DIV_ROUND_UP(interval, MSEC_PER_SEC);
6749 if (!request->scan_plans[0].interval)
6750 return -EINVAL;
6751
6752 if (request->scan_plans[0].interval >
6753 wiphy->max_sched_scan_plan_interval)
6754 request->scan_plans[0].interval =
6755 wiphy->max_sched_scan_plan_interval;
6756
6757 return 0;
6758 }
6759
6760 nla_for_each_nested(attr, attrs[NL80211_ATTR_SCHED_SCAN_PLANS], tmp) {
6761 struct nlattr *plan[NL80211_SCHED_SCAN_PLAN_MAX + 1];
6762
6763 if (WARN_ON(i >= n_plans))
6764 return -EINVAL;
6765
6766 err = nla_parse(plan, NL80211_SCHED_SCAN_PLAN_MAX,
6767 nla_data(attr), nla_len(attr),
6768 nl80211_plan_policy);
6769 if (err)
6770 return err;
6771
6772 if (!plan[NL80211_SCHED_SCAN_PLAN_INTERVAL])
6773 return -EINVAL;
6774
6775 request->scan_plans[i].interval =
6776 nla_get_u32(plan[NL80211_SCHED_SCAN_PLAN_INTERVAL]);
6777 if (!request->scan_plans[i].interval ||
6778 request->scan_plans[i].interval >
6779 wiphy->max_sched_scan_plan_interval)
6780 return -EINVAL;
6781
6782 if (plan[NL80211_SCHED_SCAN_PLAN_ITERATIONS]) {
6783 request->scan_plans[i].iterations =
6784 nla_get_u32(plan[NL80211_SCHED_SCAN_PLAN_ITERATIONS]);
6785 if (!request->scan_plans[i].iterations ||
6786 (request->scan_plans[i].iterations >
6787 wiphy->max_sched_scan_plan_iterations))
6788 return -EINVAL;
6789 } else if (i < n_plans - 1) {
6790 /*
6791 * All scan plans but the last one must specify
6792 * a finite number of iterations
6793 */
6794 return -EINVAL;
6795 }
6796
6797 i++;
6798 }
6799
6800 /*
6801 * The last scan plan must not specify the number of
6802 * iterations, it is supposed to run infinitely
6803 */
6804 if (request->scan_plans[n_plans - 1].iterations)
6805 return -EINVAL;
6806
6807 return 0;
6808}
6809
Luciano Coelho256da022014-11-10 16:13:46 +02006810static struct cfg80211_sched_scan_request *
Johannes Bergad2b26a2014-06-12 21:39:05 +02006811nl80211_parse_sched_scan(struct wiphy *wiphy, struct wireless_dev *wdev,
Luciano Coelho256da022014-11-10 16:13:46 +02006812 struct nlattr **attrs)
Luciano Coelho807f8a82011-05-11 17:09:35 +03006813{
6814 struct cfg80211_sched_scan_request *request;
Luciano Coelho807f8a82011-05-11 17:09:35 +03006815 struct nlattr *attr;
Avraham Stern3b06d272015-10-12 09:51:34 +03006816 int err, tmp, n_ssids = 0, n_match_sets = 0, n_channels, i, n_plans = 0;
Johannes Berg57fbcce2016-04-12 15:56:15 +02006817 enum nl80211_band band;
Luciano Coelho807f8a82011-05-11 17:09:35 +03006818 size_t ie_len;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03006819 struct nlattr *tb[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1];
Johannes Bergea73cbc2014-01-24 10:53:53 +01006820 s32 default_match_rssi = NL80211_SCAN_RSSI_THOLD_OFF;
Luciano Coelho807f8a82011-05-11 17:09:35 +03006821
Luciano Coelho256da022014-11-10 16:13:46 +02006822 if (!is_valid_ie_attr(attrs[NL80211_ATTR_IE]))
6823 return ERR_PTR(-EINVAL);
Luciano Coelho807f8a82011-05-11 17:09:35 +03006824
Luciano Coelho256da022014-11-10 16:13:46 +02006825 if (attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
Luciano Coelho807f8a82011-05-11 17:09:35 +03006826 n_channels = validate_scan_freqs(
Luciano Coelho256da022014-11-10 16:13:46 +02006827 attrs[NL80211_ATTR_SCAN_FREQUENCIES]);
Luciano Coelho807f8a82011-05-11 17:09:35 +03006828 if (!n_channels)
Luciano Coelho256da022014-11-10 16:13:46 +02006829 return ERR_PTR(-EINVAL);
Luciano Coelho807f8a82011-05-11 17:09:35 +03006830 } else {
Ilan Peerbdfbec22014-01-09 11:37:23 +02006831 n_channels = ieee80211_get_num_supported_channels(wiphy);
Luciano Coelho807f8a82011-05-11 17:09:35 +03006832 }
6833
Luciano Coelho256da022014-11-10 16:13:46 +02006834 if (attrs[NL80211_ATTR_SCAN_SSIDS])
6835 nla_for_each_nested(attr, attrs[NL80211_ATTR_SCAN_SSIDS],
Luciano Coelho807f8a82011-05-11 17:09:35 +03006836 tmp)
6837 n_ssids++;
6838
Luciano Coelho93b6aa62011-07-13 14:57:28 +03006839 if (n_ssids > wiphy->max_sched_scan_ssids)
Luciano Coelho256da022014-11-10 16:13:46 +02006840 return ERR_PTR(-EINVAL);
Luciano Coelho807f8a82011-05-11 17:09:35 +03006841
Johannes Bergea73cbc2014-01-24 10:53:53 +01006842 /*
6843 * First, count the number of 'real' matchsets. Due to an issue with
6844 * the old implementation, matchsets containing only the RSSI attribute
6845 * (NL80211_SCHED_SCAN_MATCH_ATTR_RSSI) are considered as the 'default'
6846 * RSSI for all matchsets, rather than their own matchset for reporting
6847 * all APs with a strong RSSI. This is needed to be compatible with
6848 * older userspace that treated a matchset with only the RSSI as the
6849 * global RSSI for all other matchsets - if there are other matchsets.
6850 */
Luciano Coelho256da022014-11-10 16:13:46 +02006851 if (attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) {
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03006852 nla_for_each_nested(attr,
Luciano Coelho256da022014-11-10 16:13:46 +02006853 attrs[NL80211_ATTR_SCHED_SCAN_MATCH],
Johannes Bergea73cbc2014-01-24 10:53:53 +01006854 tmp) {
6855 struct nlattr *rssi;
6856
6857 err = nla_parse(tb, NL80211_SCHED_SCAN_MATCH_ATTR_MAX,
6858 nla_data(attr), nla_len(attr),
6859 nl80211_match_policy);
6860 if (err)
Luciano Coelho256da022014-11-10 16:13:46 +02006861 return ERR_PTR(err);
Johannes Bergea73cbc2014-01-24 10:53:53 +01006862 /* add other standalone attributes here */
6863 if (tb[NL80211_SCHED_SCAN_MATCH_ATTR_SSID]) {
6864 n_match_sets++;
6865 continue;
6866 }
6867 rssi = tb[NL80211_SCHED_SCAN_MATCH_ATTR_RSSI];
6868 if (rssi)
6869 default_match_rssi = nla_get_s32(rssi);
6870 }
6871 }
6872
6873 /* However, if there's no other matchset, add the RSSI one */
6874 if (!n_match_sets && default_match_rssi != NL80211_SCAN_RSSI_THOLD_OFF)
6875 n_match_sets = 1;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03006876
6877 if (n_match_sets > wiphy->max_match_sets)
Luciano Coelho256da022014-11-10 16:13:46 +02006878 return ERR_PTR(-EINVAL);
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03006879
Luciano Coelho256da022014-11-10 16:13:46 +02006880 if (attrs[NL80211_ATTR_IE])
6881 ie_len = nla_len(attrs[NL80211_ATTR_IE]);
Luciano Coelho807f8a82011-05-11 17:09:35 +03006882 else
6883 ie_len = 0;
6884
Luciano Coelho5a865ba2011-07-13 14:57:29 +03006885 if (ie_len > wiphy->max_sched_scan_ie_len)
Luciano Coelho256da022014-11-10 16:13:46 +02006886 return ERR_PTR(-EINVAL);
Luciano Coelhoc10841c2011-06-30 08:32:41 +03006887
Avraham Stern3b06d272015-10-12 09:51:34 +03006888 if (attrs[NL80211_ATTR_SCHED_SCAN_PLANS]) {
6889 /*
6890 * NL80211_ATTR_SCHED_SCAN_INTERVAL must not be specified since
6891 * each scan plan already specifies its own interval
6892 */
6893 if (attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL])
6894 return ERR_PTR(-EINVAL);
6895
6896 nla_for_each_nested(attr,
6897 attrs[NL80211_ATTR_SCHED_SCAN_PLANS], tmp)
6898 n_plans++;
6899 } else {
6900 /*
6901 * The scan interval attribute is kept for backward
6902 * compatibility. If no scan plans are specified and sched scan
6903 * interval is specified, one scan plan will be set with this
6904 * scan interval and infinite number of iterations.
6905 */
6906 if (!attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL])
6907 return ERR_PTR(-EINVAL);
6908
6909 n_plans = 1;
6910 }
6911
6912 if (!n_plans || n_plans > wiphy->max_sched_scan_plans)
6913 return ERR_PTR(-EINVAL);
6914
Luciano Coelho807f8a82011-05-11 17:09:35 +03006915 request = kzalloc(sizeof(*request)
Luciano Coelhoa2cd43c2011-05-18 11:42:03 +03006916 + sizeof(*request->ssids) * n_ssids
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03006917 + sizeof(*request->match_sets) * n_match_sets
Avraham Stern3b06d272015-10-12 09:51:34 +03006918 + sizeof(*request->scan_plans) * n_plans
Luciano Coelhoa2cd43c2011-05-18 11:42:03 +03006919 + sizeof(*request->channels) * n_channels
Luciano Coelho807f8a82011-05-11 17:09:35 +03006920 + ie_len, GFP_KERNEL);
Luciano Coelho256da022014-11-10 16:13:46 +02006921 if (!request)
6922 return ERR_PTR(-ENOMEM);
Luciano Coelho807f8a82011-05-11 17:09:35 +03006923
6924 if (n_ssids)
6925 request->ssids = (void *)&request->channels[n_channels];
6926 request->n_ssids = n_ssids;
6927 if (ie_len) {
Johannes Berg13874e42015-01-23 11:25:20 +01006928 if (n_ssids)
Luciano Coelho807f8a82011-05-11 17:09:35 +03006929 request->ie = (void *)(request->ssids + n_ssids);
6930 else
6931 request->ie = (void *)(request->channels + n_channels);
6932 }
6933
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03006934 if (n_match_sets) {
6935 if (request->ie)
6936 request->match_sets = (void *)(request->ie + ie_len);
Johannes Berg13874e42015-01-23 11:25:20 +01006937 else if (n_ssids)
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03006938 request->match_sets =
6939 (void *)(request->ssids + n_ssids);
6940 else
6941 request->match_sets =
6942 (void *)(request->channels + n_channels);
6943 }
6944 request->n_match_sets = n_match_sets;
6945
Avraham Stern3b06d272015-10-12 09:51:34 +03006946 if (n_match_sets)
6947 request->scan_plans = (void *)(request->match_sets +
6948 n_match_sets);
6949 else if (request->ie)
6950 request->scan_plans = (void *)(request->ie + ie_len);
6951 else if (n_ssids)
6952 request->scan_plans = (void *)(request->ssids + n_ssids);
6953 else
6954 request->scan_plans = (void *)(request->channels + n_channels);
6955
6956 request->n_scan_plans = n_plans;
6957
Luciano Coelho807f8a82011-05-11 17:09:35 +03006958 i = 0;
Luciano Coelho256da022014-11-10 16:13:46 +02006959 if (attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
Luciano Coelho807f8a82011-05-11 17:09:35 +03006960 /* user specified, bail out if channel not found */
6961 nla_for_each_nested(attr,
Luciano Coelho256da022014-11-10 16:13:46 +02006962 attrs[NL80211_ATTR_SCAN_FREQUENCIES],
Luciano Coelho807f8a82011-05-11 17:09:35 +03006963 tmp) {
6964 struct ieee80211_channel *chan;
6965
6966 chan = ieee80211_get_channel(wiphy, nla_get_u32(attr));
6967
6968 if (!chan) {
6969 err = -EINVAL;
6970 goto out_free;
6971 }
6972
6973 /* ignore disabled channels */
6974 if (chan->flags & IEEE80211_CHAN_DISABLED)
6975 continue;
6976
6977 request->channels[i] = chan;
6978 i++;
6979 }
6980 } else {
6981 /* all channels */
Johannes Berg57fbcce2016-04-12 15:56:15 +02006982 for (band = 0; band < NUM_NL80211_BANDS; band++) {
Luciano Coelho807f8a82011-05-11 17:09:35 +03006983 int j;
Kirtika Ruchandani7a087e72016-05-29 19:51:23 -07006984
Luciano Coelho807f8a82011-05-11 17:09:35 +03006985 if (!wiphy->bands[band])
6986 continue;
6987 for (j = 0; j < wiphy->bands[band]->n_channels; j++) {
6988 struct ieee80211_channel *chan;
6989
6990 chan = &wiphy->bands[band]->channels[j];
6991
6992 if (chan->flags & IEEE80211_CHAN_DISABLED)
6993 continue;
6994
6995 request->channels[i] = chan;
6996 i++;
6997 }
6998 }
6999 }
7000
7001 if (!i) {
7002 err = -EINVAL;
7003 goto out_free;
7004 }
7005
7006 request->n_channels = i;
7007
7008 i = 0;
Johannes Berg13874e42015-01-23 11:25:20 +01007009 if (n_ssids) {
Luciano Coelho256da022014-11-10 16:13:46 +02007010 nla_for_each_nested(attr, attrs[NL80211_ATTR_SCAN_SSIDS],
Luciano Coelho807f8a82011-05-11 17:09:35 +03007011 tmp) {
Luciano Coelho57a27e12011-06-07 20:42:26 +03007012 if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) {
Luciano Coelho807f8a82011-05-11 17:09:35 +03007013 err = -EINVAL;
7014 goto out_free;
7015 }
Luciano Coelho57a27e12011-06-07 20:42:26 +03007016 request->ssids[i].ssid_len = nla_len(attr);
Luciano Coelho807f8a82011-05-11 17:09:35 +03007017 memcpy(request->ssids[i].ssid, nla_data(attr),
7018 nla_len(attr));
Luciano Coelho807f8a82011-05-11 17:09:35 +03007019 i++;
7020 }
7021 }
7022
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03007023 i = 0;
Luciano Coelho256da022014-11-10 16:13:46 +02007024 if (attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) {
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03007025 nla_for_each_nested(attr,
Luciano Coelho256da022014-11-10 16:13:46 +02007026 attrs[NL80211_ATTR_SCHED_SCAN_MATCH],
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03007027 tmp) {
Thomas Pedersen88e920b2012-06-21 11:09:54 -07007028 struct nlattr *ssid, *rssi;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03007029
Johannes Bergae811e22014-01-24 10:17:47 +01007030 err = nla_parse(tb, NL80211_SCHED_SCAN_MATCH_ATTR_MAX,
7031 nla_data(attr), nla_len(attr),
7032 nl80211_match_policy);
7033 if (err)
7034 goto out_free;
Johannes Berg4a4ab0d2012-06-13 11:17:11 +02007035 ssid = tb[NL80211_SCHED_SCAN_MATCH_ATTR_SSID];
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03007036 if (ssid) {
Johannes Bergea73cbc2014-01-24 10:53:53 +01007037 if (WARN_ON(i >= n_match_sets)) {
7038 /* this indicates a programming error,
7039 * the loop above should have verified
7040 * things properly
7041 */
7042 err = -EINVAL;
7043 goto out_free;
7044 }
7045
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03007046 if (nla_len(ssid) > IEEE80211_MAX_SSID_LEN) {
7047 err = -EINVAL;
7048 goto out_free;
7049 }
7050 memcpy(request->match_sets[i].ssid.ssid,
7051 nla_data(ssid), nla_len(ssid));
7052 request->match_sets[i].ssid.ssid_len =
7053 nla_len(ssid);
Kirtika Ruchandani56ab3642016-05-29 19:54:10 -07007054 /* special attribute - old implementation w/a */
Johannes Bergea73cbc2014-01-24 10:53:53 +01007055 request->match_sets[i].rssi_thold =
7056 default_match_rssi;
7057 rssi = tb[NL80211_SCHED_SCAN_MATCH_ATTR_RSSI];
7058 if (rssi)
7059 request->match_sets[i].rssi_thold =
7060 nla_get_s32(rssi);
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03007061 }
7062 i++;
7063 }
Johannes Bergea73cbc2014-01-24 10:53:53 +01007064
7065 /* there was no other matchset, so the RSSI one is alone */
Luciano Coelhof89f46c2014-12-01 11:32:09 +02007066 if (i == 0 && n_match_sets)
Johannes Bergea73cbc2014-01-24 10:53:53 +01007067 request->match_sets[0].rssi_thold = default_match_rssi;
7068
7069 request->min_rssi_thold = INT_MAX;
7070 for (i = 0; i < n_match_sets; i++)
7071 request->min_rssi_thold =
7072 min(request->match_sets[i].rssi_thold,
7073 request->min_rssi_thold);
7074 } else {
7075 request->min_rssi_thold = NL80211_SCAN_RSSI_THOLD_OFF;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03007076 }
7077
Johannes Berg9900e482014-02-04 21:01:25 +01007078 if (ie_len) {
7079 request->ie_len = ie_len;
Luciano Coelho807f8a82011-05-11 17:09:35 +03007080 memcpy((void *)request->ie,
Luciano Coelho256da022014-11-10 16:13:46 +02007081 nla_data(attrs[NL80211_ATTR_IE]),
Luciano Coelho807f8a82011-05-11 17:09:35 +03007082 request->ie_len);
7083 }
7084
Luciano Coelho256da022014-11-10 16:13:46 +02007085 if (attrs[NL80211_ATTR_SCAN_FLAGS]) {
Sam Lefflered4737712012-10-11 21:03:31 -07007086 request->flags = nla_get_u32(
Luciano Coelho256da022014-11-10 16:13:46 +02007087 attrs[NL80211_ATTR_SCAN_FLAGS]);
Johannes Berg00c3a6e2013-10-26 17:14:38 +02007088 if ((request->flags & NL80211_SCAN_FLAG_LOW_PRIORITY) &&
7089 !(wiphy->features & NL80211_FEATURE_LOW_PRIORITY_SCAN)) {
Sam Leffler46856bb2012-10-11 21:03:32 -07007090 err = -EOPNOTSUPP;
7091 goto out_free;
7092 }
Johannes Bergad2b26a2014-06-12 21:39:05 +02007093
7094 if (request->flags & NL80211_SCAN_FLAG_RANDOM_ADDR) {
7095 u32 flg = NL80211_FEATURE_SCHED_SCAN_RANDOM_MAC_ADDR;
7096
7097 if (!wdev) /* must be net-detect */
7098 flg = NL80211_FEATURE_ND_RANDOM_MAC_ADDR;
7099
7100 if (!(wiphy->features & flg)) {
7101 err = -EOPNOTSUPP;
7102 goto out_free;
7103 }
7104
7105 if (wdev && wdev->current_bss) {
7106 err = -EOPNOTSUPP;
7107 goto out_free;
7108 }
7109
7110 err = nl80211_parse_random_mac(attrs, request->mac_addr,
7111 request->mac_addr_mask);
7112 if (err)
7113 goto out_free;
7114 }
Sam Leffler46856bb2012-10-11 21:03:32 -07007115 }
Sam Lefflered4737712012-10-11 21:03:31 -07007116
Luciano Coelho9c748932015-01-16 16:04:09 +02007117 if (attrs[NL80211_ATTR_SCHED_SCAN_DELAY])
7118 request->delay =
7119 nla_get_u32(attrs[NL80211_ATTR_SCHED_SCAN_DELAY]);
7120
Avraham Stern3b06d272015-10-12 09:51:34 +03007121 err = nl80211_parse_sched_scan_plans(wiphy, n_plans, request, attrs);
7122 if (err)
7123 goto out_free;
7124
Sam Leffler15d60302012-10-11 21:03:34 -07007125 request->scan_start = jiffies;
Luciano Coelho807f8a82011-05-11 17:09:35 +03007126
Luciano Coelho256da022014-11-10 16:13:46 +02007127 return request;
Luciano Coelho807f8a82011-05-11 17:09:35 +03007128
7129out_free:
7130 kfree(request);
Luciano Coelho256da022014-11-10 16:13:46 +02007131 return ERR_PTR(err);
7132}
7133
7134static int nl80211_start_sched_scan(struct sk_buff *skb,
7135 struct genl_info *info)
7136{
7137 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7138 struct net_device *dev = info->user_ptr[1];
Johannes Bergad2b26a2014-06-12 21:39:05 +02007139 struct wireless_dev *wdev = dev->ieee80211_ptr;
Jukka Rissanen31a60ed2014-12-15 13:25:38 +02007140 struct cfg80211_sched_scan_request *sched_scan_req;
Luciano Coelho256da022014-11-10 16:13:46 +02007141 int err;
7142
7143 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) ||
7144 !rdev->ops->sched_scan_start)
7145 return -EOPNOTSUPP;
7146
7147 if (rdev->sched_scan_req)
7148 return -EINPROGRESS;
7149
Jukka Rissanen31a60ed2014-12-15 13:25:38 +02007150 sched_scan_req = nl80211_parse_sched_scan(&rdev->wiphy, wdev,
7151 info->attrs);
7152
7153 err = PTR_ERR_OR_ZERO(sched_scan_req);
Luciano Coelho256da022014-11-10 16:13:46 +02007154 if (err)
7155 goto out_err;
7156
Jukka Rissanen31a60ed2014-12-15 13:25:38 +02007157 err = rdev_sched_scan_start(rdev, dev, sched_scan_req);
Luciano Coelho256da022014-11-10 16:13:46 +02007158 if (err)
7159 goto out_free;
7160
Jukka Rissanen31a60ed2014-12-15 13:25:38 +02007161 sched_scan_req->dev = dev;
7162 sched_scan_req->wiphy = &rdev->wiphy;
7163
Jukka Rissanen93a1e862014-12-15 13:25:39 +02007164 if (info->attrs[NL80211_ATTR_SOCKET_OWNER])
7165 sched_scan_req->owner_nlportid = info->snd_portid;
7166
Jukka Rissanen31a60ed2014-12-15 13:25:38 +02007167 rcu_assign_pointer(rdev->sched_scan_req, sched_scan_req);
Luciano Coelho256da022014-11-10 16:13:46 +02007168
7169 nl80211_send_sched_scan(rdev, dev,
7170 NL80211_CMD_START_SCHED_SCAN);
7171 return 0;
7172
7173out_free:
Jukka Rissanen31a60ed2014-12-15 13:25:38 +02007174 kfree(sched_scan_req);
Luciano Coelho256da022014-11-10 16:13:46 +02007175out_err:
Luciano Coelho807f8a82011-05-11 17:09:35 +03007176 return err;
7177}
7178
7179static int nl80211_stop_sched_scan(struct sk_buff *skb,
7180 struct genl_info *info)
7181{
7182 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7183
7184 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) ||
7185 !rdev->ops->sched_scan_stop)
7186 return -EOPNOTSUPP;
7187
Johannes Berg5fe231e2013-05-08 21:45:15 +02007188 return __cfg80211_stop_sched_scan(rdev, false);
Luciano Coelho807f8a82011-05-11 17:09:35 +03007189}
7190
Simon Wunderlich04f39042013-02-08 18:16:19 +01007191static int nl80211_start_radar_detection(struct sk_buff *skb,
7192 struct genl_info *info)
7193{
7194 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7195 struct net_device *dev = info->user_ptr[1];
7196 struct wireless_dev *wdev = dev->ieee80211_ptr;
7197 struct cfg80211_chan_def chandef;
Luis R. Rodriguez55f74352013-11-25 20:56:10 +01007198 enum nl80211_dfs_regions dfs_region;
Janusz Dziedzic31559f32014-02-21 19:46:13 +01007199 unsigned int cac_time_ms;
Simon Wunderlich04f39042013-02-08 18:16:19 +01007200 int err;
7201
Luis R. Rodriguez55f74352013-11-25 20:56:10 +01007202 dfs_region = reg_get_dfs_region(wdev->wiphy);
7203 if (dfs_region == NL80211_DFS_UNSET)
7204 return -EINVAL;
7205
Simon Wunderlich04f39042013-02-08 18:16:19 +01007206 err = nl80211_parse_chandef(rdev, info, &chandef);
7207 if (err)
7208 return err;
7209
Simon Wunderlichff311bc2013-09-03 19:43:18 +02007210 if (netif_carrier_ok(dev))
7211 return -EBUSY;
7212
Simon Wunderlich04f39042013-02-08 18:16:19 +01007213 if (wdev->cac_started)
7214 return -EBUSY;
7215
Luciano Coelho2beb6dab2014-02-18 11:40:36 +02007216 err = cfg80211_chandef_dfs_required(wdev->wiphy, &chandef,
Luciano Coelho00ec75f2014-05-15 13:05:39 +03007217 wdev->iftype);
Simon Wunderlich04f39042013-02-08 18:16:19 +01007218 if (err < 0)
7219 return err;
7220
7221 if (err == 0)
7222 return -EINVAL;
7223
Janusz Dziedzicfe7c3a12013-11-05 14:48:48 +01007224 if (!cfg80211_chandef_dfs_usable(wdev->wiphy, &chandef))
Simon Wunderlich04f39042013-02-08 18:16:19 +01007225 return -EINVAL;
7226
7227 if (!rdev->ops->start_radar_detection)
7228 return -EOPNOTSUPP;
7229
Janusz Dziedzic31559f32014-02-21 19:46:13 +01007230 cac_time_ms = cfg80211_chandef_dfs_cac_time(&rdev->wiphy, &chandef);
7231 if (WARN_ON(!cac_time_ms))
7232 cac_time_ms = IEEE80211_DFS_MIN_CAC_TIME_MS;
7233
Ilan Peera1056b1b2015-10-22 22:27:46 +03007234 err = rdev_start_radar_detection(rdev, dev, &chandef, cac_time_ms);
Simon Wunderlich04f39042013-02-08 18:16:19 +01007235 if (!err) {
Michal Kazior9e0e2962014-01-29 14:22:27 +01007236 wdev->chandef = chandef;
Simon Wunderlich04f39042013-02-08 18:16:19 +01007237 wdev->cac_started = true;
7238 wdev->cac_start_time = jiffies;
Janusz Dziedzic31559f32014-02-21 19:46:13 +01007239 wdev->cac_time_ms = cac_time_ms;
Simon Wunderlich04f39042013-02-08 18:16:19 +01007240 }
Simon Wunderlich04f39042013-02-08 18:16:19 +01007241 return err;
7242}
7243
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02007244static int nl80211_channel_switch(struct sk_buff *skb, struct genl_info *info)
7245{
7246 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7247 struct net_device *dev = info->user_ptr[1];
7248 struct wireless_dev *wdev = dev->ieee80211_ptr;
7249 struct cfg80211_csa_settings params;
7250 /* csa_attrs is defined static to avoid waste of stack size - this
7251 * function is called under RTNL lock, so this should not be a problem.
7252 */
7253 static struct nlattr *csa_attrs[NL80211_ATTR_MAX+1];
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02007254 int err;
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02007255 bool need_new_beacon = false;
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03007256 int len, i;
Luciano Coelho252e07c2014-10-08 09:48:34 +03007257 u32 cs_count;
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02007258
7259 if (!rdev->ops->channel_switch ||
7260 !(rdev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH))
7261 return -EOPNOTSUPP;
7262
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02007263 switch (dev->ieee80211_ptr->iftype) {
7264 case NL80211_IFTYPE_AP:
7265 case NL80211_IFTYPE_P2P_GO:
7266 need_new_beacon = true;
7267
7268 /* useless if AP is not running */
7269 if (!wdev->beacon_interval)
Johannes Berg1ff79df2014-01-22 10:05:27 +01007270 return -ENOTCONN;
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02007271 break;
7272 case NL80211_IFTYPE_ADHOC:
Johannes Berg1ff79df2014-01-22 10:05:27 +01007273 if (!wdev->ssid_len)
7274 return -ENOTCONN;
7275 break;
Chun-Yeow Yeohc6da6742013-10-14 19:08:28 -07007276 case NL80211_IFTYPE_MESH_POINT:
Johannes Berg1ff79df2014-01-22 10:05:27 +01007277 if (!wdev->mesh_id_len)
7278 return -ENOTCONN;
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02007279 break;
7280 default:
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02007281 return -EOPNOTSUPP;
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02007282 }
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02007283
7284 memset(&params, 0, sizeof(params));
7285
7286 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] ||
7287 !info->attrs[NL80211_ATTR_CH_SWITCH_COUNT])
7288 return -EINVAL;
7289
7290 /* only important for AP, IBSS and mesh create IEs internally */
Andrei Otcheretianskid0a361a2013-10-17 10:52:17 +02007291 if (need_new_beacon && !info->attrs[NL80211_ATTR_CSA_IES])
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02007292 return -EINVAL;
7293
Luciano Coelho252e07c2014-10-08 09:48:34 +03007294 /* Even though the attribute is u32, the specification says
7295 * u8, so let's make sure we don't overflow.
7296 */
7297 cs_count = nla_get_u32(info->attrs[NL80211_ATTR_CH_SWITCH_COUNT]);
7298 if (cs_count > 255)
7299 return -EINVAL;
7300
7301 params.count = cs_count;
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02007302
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02007303 if (!need_new_beacon)
7304 goto skip_beacons;
7305
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02007306 err = nl80211_parse_beacon(info->attrs, &params.beacon_after);
7307 if (err)
7308 return err;
7309
7310 err = nla_parse_nested(csa_attrs, NL80211_ATTR_MAX,
7311 info->attrs[NL80211_ATTR_CSA_IES],
7312 nl80211_policy);
7313 if (err)
7314 return err;
7315
7316 err = nl80211_parse_beacon(csa_attrs, &params.beacon_csa);
7317 if (err)
7318 return err;
7319
7320 if (!csa_attrs[NL80211_ATTR_CSA_C_OFF_BEACON])
7321 return -EINVAL;
7322
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03007323 len = nla_len(csa_attrs[NL80211_ATTR_CSA_C_OFF_BEACON]);
7324 if (!len || (len % sizeof(u16)))
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02007325 return -EINVAL;
7326
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03007327 params.n_counter_offsets_beacon = len / sizeof(u16);
7328 if (rdev->wiphy.max_num_csa_counters &&
7329 (params.n_counter_offsets_beacon >
7330 rdev->wiphy.max_num_csa_counters))
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02007331 return -EINVAL;
7332
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03007333 params.counter_offsets_beacon =
7334 nla_data(csa_attrs[NL80211_ATTR_CSA_C_OFF_BEACON]);
7335
7336 /* sanity checks - counters should fit and be the same */
7337 for (i = 0; i < params.n_counter_offsets_beacon; i++) {
7338 u16 offset = params.counter_offsets_beacon[i];
7339
7340 if (offset >= params.beacon_csa.tail_len)
7341 return -EINVAL;
7342
7343 if (params.beacon_csa.tail[offset] != params.count)
7344 return -EINVAL;
7345 }
7346
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02007347 if (csa_attrs[NL80211_ATTR_CSA_C_OFF_PRESP]) {
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03007348 len = nla_len(csa_attrs[NL80211_ATTR_CSA_C_OFF_PRESP]);
7349 if (!len || (len % sizeof(u16)))
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02007350 return -EINVAL;
7351
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03007352 params.n_counter_offsets_presp = len / sizeof(u16);
7353 if (rdev->wiphy.max_num_csa_counters &&
7354 (params.n_counter_offsets_beacon >
7355 rdev->wiphy.max_num_csa_counters))
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02007356 return -EINVAL;
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03007357
7358 params.counter_offsets_presp =
7359 nla_data(csa_attrs[NL80211_ATTR_CSA_C_OFF_PRESP]);
7360
7361 /* sanity checks - counters should fit and be the same */
7362 for (i = 0; i < params.n_counter_offsets_presp; i++) {
7363 u16 offset = params.counter_offsets_presp[i];
7364
7365 if (offset >= params.beacon_csa.probe_resp_len)
7366 return -EINVAL;
7367
7368 if (params.beacon_csa.probe_resp[offset] !=
7369 params.count)
7370 return -EINVAL;
7371 }
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02007372 }
7373
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02007374skip_beacons:
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02007375 err = nl80211_parse_chandef(rdev, info, &params.chandef);
7376 if (err)
7377 return err;
7378
Arik Nemtsov923b3522015-07-08 15:41:44 +03007379 if (!cfg80211_reg_can_beacon_relax(&rdev->wiphy, &params.chandef,
7380 wdev->iftype))
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02007381 return -EINVAL;
7382
Luciano Coelho2beb6dab2014-02-18 11:40:36 +02007383 err = cfg80211_chandef_dfs_required(wdev->wiphy,
7384 &params.chandef,
7385 wdev->iftype);
7386 if (err < 0)
7387 return err;
7388
Fabian Frederickdcc6c2f2014-10-25 17:57:35 +02007389 if (err > 0)
Luciano Coelho2beb6dab2014-02-18 11:40:36 +02007390 params.radar_required = true;
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02007391
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02007392 if (info->attrs[NL80211_ATTR_CH_SWITCH_BLOCK_TX])
7393 params.block_tx = true;
7394
Simon Wunderlichc56589e2013-11-21 18:19:49 +01007395 wdev_lock(wdev);
7396 err = rdev_channel_switch(rdev, dev, &params);
7397 wdev_unlock(wdev);
7398
7399 return err;
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02007400}
7401
Johannes Berg9720bb32011-06-21 09:45:33 +02007402static int nl80211_send_bss(struct sk_buff *msg, struct netlink_callback *cb,
7403 u32 seq, int flags,
Johannes Berg2a519312009-02-10 21:25:55 +01007404 struct cfg80211_registered_device *rdev,
Johannes Berg48ab9052009-07-10 18:42:31 +02007405 struct wireless_dev *wdev,
7406 struct cfg80211_internal_bss *intbss)
Johannes Berg2a519312009-02-10 21:25:55 +01007407{
Johannes Berg48ab9052009-07-10 18:42:31 +02007408 struct cfg80211_bss *res = &intbss->pub;
Johannes Berg9caf0362012-11-29 01:25:20 +01007409 const struct cfg80211_bss_ies *ies;
Johannes Berg2a519312009-02-10 21:25:55 +01007410 void *hdr;
7411 struct nlattr *bss;
Johannes Berg48ab9052009-07-10 18:42:31 +02007412
7413 ASSERT_WDEV_LOCK(wdev);
Johannes Berg2a519312009-02-10 21:25:55 +01007414
Eric W. Biederman15e47302012-09-07 20:12:54 +00007415 hdr = nl80211hdr_put(msg, NETLINK_CB(cb->skb).portid, seq, flags,
Johannes Berg2a519312009-02-10 21:25:55 +01007416 NL80211_CMD_NEW_SCAN_RESULTS);
7417 if (!hdr)
7418 return -1;
7419
Johannes Berg9720bb32011-06-21 09:45:33 +02007420 genl_dump_check_consistent(cb, hdr, &nl80211_fam);
7421
Johannes Berg97990a02013-04-19 01:02:55 +02007422 if (nla_put_u32(msg, NL80211_ATTR_GENERATION, rdev->bss_generation))
7423 goto nla_put_failure;
7424 if (wdev->netdev &&
David S. Miller9360ffd2012-03-29 04:41:26 -04007425 nla_put_u32(msg, NL80211_ATTR_IFINDEX, wdev->netdev->ifindex))
7426 goto nla_put_failure;
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02007427 if (nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
7428 NL80211_ATTR_PAD))
Johannes Berg97990a02013-04-19 01:02:55 +02007429 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01007430
7431 bss = nla_nest_start(msg, NL80211_ATTR_BSS);
7432 if (!bss)
7433 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04007434 if ((!is_zero_ether_addr(res->bssid) &&
Johannes Berg9caf0362012-11-29 01:25:20 +01007435 nla_put(msg, NL80211_BSS_BSSID, ETH_ALEN, res->bssid)))
David S. Miller9360ffd2012-03-29 04:41:26 -04007436 goto nla_put_failure;
Johannes Berg9caf0362012-11-29 01:25:20 +01007437
7438 rcu_read_lock();
Johannes Berg0e227082014-08-12 20:34:30 +02007439 /* indicate whether we have probe response data or not */
7440 if (rcu_access_pointer(res->proberesp_ies) &&
7441 nla_put_flag(msg, NL80211_BSS_PRESP_DATA))
7442 goto fail_unlock_rcu;
7443
7444 /* this pointer prefers to be pointed to probe response data
7445 * but is always valid
7446 */
Johannes Berg9caf0362012-11-29 01:25:20 +01007447 ies = rcu_dereference(res->ies);
Johannes Berg8cef2c92013-02-05 16:54:31 +01007448 if (ies) {
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02007449 if (nla_put_u64_64bit(msg, NL80211_BSS_TSF, ies->tsf,
7450 NL80211_BSS_PAD))
Johannes Berg8cef2c92013-02-05 16:54:31 +01007451 goto fail_unlock_rcu;
Johannes Berg8cef2c92013-02-05 16:54:31 +01007452 if (ies->len && nla_put(msg, NL80211_BSS_INFORMATION_ELEMENTS,
7453 ies->len, ies->data))
7454 goto fail_unlock_rcu;
Johannes Berg9caf0362012-11-29 01:25:20 +01007455 }
Johannes Berg0e227082014-08-12 20:34:30 +02007456
7457 /* and this pointer is always (unless driver didn't know) beacon data */
Johannes Berg9caf0362012-11-29 01:25:20 +01007458 ies = rcu_dereference(res->beacon_ies);
Johannes Berg0e227082014-08-12 20:34:30 +02007459 if (ies && ies->from_beacon) {
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02007460 if (nla_put_u64_64bit(msg, NL80211_BSS_BEACON_TSF, ies->tsf,
7461 NL80211_BSS_PAD))
Johannes Berg8cef2c92013-02-05 16:54:31 +01007462 goto fail_unlock_rcu;
7463 if (ies->len && nla_put(msg, NL80211_BSS_BEACON_IES,
7464 ies->len, ies->data))
7465 goto fail_unlock_rcu;
Johannes Berg9caf0362012-11-29 01:25:20 +01007466 }
7467 rcu_read_unlock();
7468
David S. Miller9360ffd2012-03-29 04:41:26 -04007469 if (res->beacon_interval &&
7470 nla_put_u16(msg, NL80211_BSS_BEACON_INTERVAL, res->beacon_interval))
7471 goto nla_put_failure;
7472 if (nla_put_u16(msg, NL80211_BSS_CAPABILITY, res->capability) ||
7473 nla_put_u32(msg, NL80211_BSS_FREQUENCY, res->channel->center_freq) ||
Simon Wunderlichdcd6eac2013-07-08 16:55:49 +02007474 nla_put_u32(msg, NL80211_BSS_CHAN_WIDTH, res->scan_width) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04007475 nla_put_u32(msg, NL80211_BSS_SEEN_MS_AGO,
7476 jiffies_to_msecs(jiffies - intbss->ts)))
7477 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01007478
Avraham Stern1d762502016-07-05 17:10:13 +03007479 if (intbss->parent_tsf &&
7480 (nla_put_u64_64bit(msg, NL80211_BSS_PARENT_TSF,
7481 intbss->parent_tsf, NL80211_BSS_PAD) ||
7482 nla_put(msg, NL80211_BSS_PARENT_BSSID, ETH_ALEN,
7483 intbss->parent_bssid)))
7484 goto nla_put_failure;
7485
Dmitry Shmidt6e19bc42015-10-07 11:32:53 +02007486 if (intbss->ts_boottime &&
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02007487 nla_put_u64_64bit(msg, NL80211_BSS_LAST_SEEN_BOOTTIME,
7488 intbss->ts_boottime, NL80211_BSS_PAD))
Dmitry Shmidt6e19bc42015-10-07 11:32:53 +02007489 goto nla_put_failure;
7490
Johannes Berg77965c972009-02-18 18:45:06 +01007491 switch (rdev->wiphy.signal_type) {
Johannes Berg2a519312009-02-10 21:25:55 +01007492 case CFG80211_SIGNAL_TYPE_MBM:
David S. Miller9360ffd2012-03-29 04:41:26 -04007493 if (nla_put_u32(msg, NL80211_BSS_SIGNAL_MBM, res->signal))
7494 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01007495 break;
7496 case CFG80211_SIGNAL_TYPE_UNSPEC:
David S. Miller9360ffd2012-03-29 04:41:26 -04007497 if (nla_put_u8(msg, NL80211_BSS_SIGNAL_UNSPEC, res->signal))
7498 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01007499 break;
7500 default:
7501 break;
7502 }
7503
Johannes Berg48ab9052009-07-10 18:42:31 +02007504 switch (wdev->iftype) {
Johannes Berg074ac8d2010-09-16 14:58:22 +02007505 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Berg48ab9052009-07-10 18:42:31 +02007506 case NL80211_IFTYPE_STATION:
David S. Miller9360ffd2012-03-29 04:41:26 -04007507 if (intbss == wdev->current_bss &&
7508 nla_put_u32(msg, NL80211_BSS_STATUS,
7509 NL80211_BSS_STATUS_ASSOCIATED))
7510 goto nla_put_failure;
Johannes Berg48ab9052009-07-10 18:42:31 +02007511 break;
7512 case NL80211_IFTYPE_ADHOC:
David S. Miller9360ffd2012-03-29 04:41:26 -04007513 if (intbss == wdev->current_bss &&
7514 nla_put_u32(msg, NL80211_BSS_STATUS,
7515 NL80211_BSS_STATUS_IBSS_JOINED))
7516 goto nla_put_failure;
Johannes Berg48ab9052009-07-10 18:42:31 +02007517 break;
7518 default:
7519 break;
7520 }
7521
Johannes Berg2a519312009-02-10 21:25:55 +01007522 nla_nest_end(msg, bss);
7523
Johannes Berg053c0952015-01-16 22:09:00 +01007524 genlmsg_end(msg, hdr);
7525 return 0;
Johannes Berg2a519312009-02-10 21:25:55 +01007526
Johannes Berg8cef2c92013-02-05 16:54:31 +01007527 fail_unlock_rcu:
7528 rcu_read_unlock();
Johannes Berg2a519312009-02-10 21:25:55 +01007529 nla_put_failure:
7530 genlmsg_cancel(msg, hdr);
7531 return -EMSGSIZE;
7532}
7533
Johannes Berg97990a02013-04-19 01:02:55 +02007534static int nl80211_dump_scan(struct sk_buff *skb, struct netlink_callback *cb)
Johannes Berg2a519312009-02-10 21:25:55 +01007535{
Johannes Berg48ab9052009-07-10 18:42:31 +02007536 struct cfg80211_registered_device *rdev;
Johannes Berg2a519312009-02-10 21:25:55 +01007537 struct cfg80211_internal_bss *scan;
Johannes Berg48ab9052009-07-10 18:42:31 +02007538 struct wireless_dev *wdev;
Johannes Berg97990a02013-04-19 01:02:55 +02007539 int start = cb->args[2], idx = 0;
Johannes Berg2a519312009-02-10 21:25:55 +01007540 int err;
7541
Johannes Berg97990a02013-04-19 01:02:55 +02007542 err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev);
Johannes Berg67748892010-10-04 21:14:06 +02007543 if (err)
7544 return err;
Johannes Berg2a519312009-02-10 21:25:55 +01007545
Johannes Berg48ab9052009-07-10 18:42:31 +02007546 wdev_lock(wdev);
7547 spin_lock_bh(&rdev->bss_lock);
7548 cfg80211_bss_expire(rdev);
7549
Johannes Berg9720bb32011-06-21 09:45:33 +02007550 cb->seq = rdev->bss_generation;
7551
Johannes Berg48ab9052009-07-10 18:42:31 +02007552 list_for_each_entry(scan, &rdev->bss_list, list) {
Johannes Berg2a519312009-02-10 21:25:55 +01007553 if (++idx <= start)
7554 continue;
Johannes Berg9720bb32011-06-21 09:45:33 +02007555 if (nl80211_send_bss(skb, cb,
Johannes Berg2a519312009-02-10 21:25:55 +01007556 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Johannes Berg48ab9052009-07-10 18:42:31 +02007557 rdev, wdev, scan) < 0) {
Johannes Berg2a519312009-02-10 21:25:55 +01007558 idx--;
Johannes Berg67748892010-10-04 21:14:06 +02007559 break;
Johannes Berg2a519312009-02-10 21:25:55 +01007560 }
7561 }
7562
Johannes Berg48ab9052009-07-10 18:42:31 +02007563 spin_unlock_bh(&rdev->bss_lock);
7564 wdev_unlock(wdev);
Johannes Berg2a519312009-02-10 21:25:55 +01007565
Johannes Berg97990a02013-04-19 01:02:55 +02007566 cb->args[2] = idx;
7567 nl80211_finish_wdev_dump(rdev);
Johannes Berg2a519312009-02-10 21:25:55 +01007568
Johannes Berg67748892010-10-04 21:14:06 +02007569 return skb->len;
Johannes Berg2a519312009-02-10 21:25:55 +01007570}
7571
Eric W. Biederman15e47302012-09-07 20:12:54 +00007572static int nl80211_send_survey(struct sk_buff *msg, u32 portid, u32 seq,
Johannes Berg11f78ac2014-11-14 16:43:50 +01007573 int flags, struct net_device *dev,
7574 bool allow_radio_stats,
7575 struct survey_info *survey)
Holger Schurig61fa7132009-11-11 12:25:40 +01007576{
7577 void *hdr;
7578 struct nlattr *infoattr;
7579
Johannes Berg11f78ac2014-11-14 16:43:50 +01007580 /* skip radio stats if userspace didn't request them */
7581 if (!survey->channel && !allow_radio_stats)
7582 return 0;
7583
Eric W. Biederman15e47302012-09-07 20:12:54 +00007584 hdr = nl80211hdr_put(msg, portid, seq, flags,
Holger Schurig61fa7132009-11-11 12:25:40 +01007585 NL80211_CMD_NEW_SURVEY_RESULTS);
7586 if (!hdr)
7587 return -ENOMEM;
7588
David S. Miller9360ffd2012-03-29 04:41:26 -04007589 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex))
7590 goto nla_put_failure;
Holger Schurig61fa7132009-11-11 12:25:40 +01007591
7592 infoattr = nla_nest_start(msg, NL80211_ATTR_SURVEY_INFO);
7593 if (!infoattr)
7594 goto nla_put_failure;
7595
Johannes Berg11f78ac2014-11-14 16:43:50 +01007596 if (survey->channel &&
7597 nla_put_u32(msg, NL80211_SURVEY_INFO_FREQUENCY,
David S. Miller9360ffd2012-03-29 04:41:26 -04007598 survey->channel->center_freq))
7599 goto nla_put_failure;
7600
7601 if ((survey->filled & SURVEY_INFO_NOISE_DBM) &&
7602 nla_put_u8(msg, NL80211_SURVEY_INFO_NOISE, survey->noise))
7603 goto nla_put_failure;
7604 if ((survey->filled & SURVEY_INFO_IN_USE) &&
7605 nla_put_flag(msg, NL80211_SURVEY_INFO_IN_USE))
7606 goto nla_put_failure;
Johannes Berg4ed20be2014-11-14 16:35:34 +01007607 if ((survey->filled & SURVEY_INFO_TIME) &&
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02007608 nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME,
7609 survey->time, NL80211_SURVEY_INFO_PAD))
David S. Miller9360ffd2012-03-29 04:41:26 -04007610 goto nla_put_failure;
Johannes Berg4ed20be2014-11-14 16:35:34 +01007611 if ((survey->filled & SURVEY_INFO_TIME_BUSY) &&
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02007612 nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME_BUSY,
7613 survey->time_busy, NL80211_SURVEY_INFO_PAD))
David S. Miller9360ffd2012-03-29 04:41:26 -04007614 goto nla_put_failure;
Johannes Berg4ed20be2014-11-14 16:35:34 +01007615 if ((survey->filled & SURVEY_INFO_TIME_EXT_BUSY) &&
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02007616 nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME_EXT_BUSY,
7617 survey->time_ext_busy, NL80211_SURVEY_INFO_PAD))
David S. Miller9360ffd2012-03-29 04:41:26 -04007618 goto nla_put_failure;
Johannes Berg4ed20be2014-11-14 16:35:34 +01007619 if ((survey->filled & SURVEY_INFO_TIME_RX) &&
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02007620 nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME_RX,
7621 survey->time_rx, NL80211_SURVEY_INFO_PAD))
David S. Miller9360ffd2012-03-29 04:41:26 -04007622 goto nla_put_failure;
Johannes Berg4ed20be2014-11-14 16:35:34 +01007623 if ((survey->filled & SURVEY_INFO_TIME_TX) &&
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02007624 nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME_TX,
7625 survey->time_tx, NL80211_SURVEY_INFO_PAD))
David S. Miller9360ffd2012-03-29 04:41:26 -04007626 goto nla_put_failure;
Johannes Berg052536a2014-11-14 16:44:11 +01007627 if ((survey->filled & SURVEY_INFO_TIME_SCAN) &&
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02007628 nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME_SCAN,
7629 survey->time_scan, NL80211_SURVEY_INFO_PAD))
Johannes Berg052536a2014-11-14 16:44:11 +01007630 goto nla_put_failure;
Holger Schurig61fa7132009-11-11 12:25:40 +01007631
7632 nla_nest_end(msg, infoattr);
7633
Johannes Berg053c0952015-01-16 22:09:00 +01007634 genlmsg_end(msg, hdr);
7635 return 0;
Holger Schurig61fa7132009-11-11 12:25:40 +01007636
7637 nla_put_failure:
7638 genlmsg_cancel(msg, hdr);
7639 return -EMSGSIZE;
7640}
7641
Johannes Berg11f78ac2014-11-14 16:43:50 +01007642static int nl80211_dump_survey(struct sk_buff *skb, struct netlink_callback *cb)
Holger Schurig61fa7132009-11-11 12:25:40 +01007643{
7644 struct survey_info survey;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08007645 struct cfg80211_registered_device *rdev;
Johannes Berg97990a02013-04-19 01:02:55 +02007646 struct wireless_dev *wdev;
7647 int survey_idx = cb->args[2];
Holger Schurig61fa7132009-11-11 12:25:40 +01007648 int res;
Johannes Berg11f78ac2014-11-14 16:43:50 +01007649 bool radio_stats;
Holger Schurig61fa7132009-11-11 12:25:40 +01007650
Zhao, Gang1b8ec872014-04-21 12:53:02 +08007651 res = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev);
Johannes Berg67748892010-10-04 21:14:06 +02007652 if (res)
7653 return res;
Holger Schurig61fa7132009-11-11 12:25:40 +01007654
Johannes Berg11f78ac2014-11-14 16:43:50 +01007655 /* prepare_wdev_dump parsed the attributes */
7656 radio_stats = nl80211_fam.attrbuf[NL80211_ATTR_SURVEY_RADIO_STATS];
7657
Johannes Berg97990a02013-04-19 01:02:55 +02007658 if (!wdev->netdev) {
7659 res = -EINVAL;
7660 goto out_err;
7661 }
7662
Zhao, Gang1b8ec872014-04-21 12:53:02 +08007663 if (!rdev->ops->dump_survey) {
Holger Schurig61fa7132009-11-11 12:25:40 +01007664 res = -EOPNOTSUPP;
7665 goto out_err;
7666 }
7667
7668 while (1) {
Zhao, Gang1b8ec872014-04-21 12:53:02 +08007669 res = rdev_dump_survey(rdev, wdev->netdev, survey_idx, &survey);
Holger Schurig61fa7132009-11-11 12:25:40 +01007670 if (res == -ENOENT)
7671 break;
7672 if (res)
7673 goto out_err;
7674
Johannes Berg11f78ac2014-11-14 16:43:50 +01007675 /* don't send disabled channels, but do send non-channel data */
7676 if (survey.channel &&
7677 survey.channel->flags & IEEE80211_CHAN_DISABLED) {
Luis R. Rodriguez180cdc72011-05-27 07:24:02 -07007678 survey_idx++;
7679 continue;
7680 }
7681
Holger Schurig61fa7132009-11-11 12:25:40 +01007682 if (nl80211_send_survey(skb,
Eric W. Biederman15e47302012-09-07 20:12:54 +00007683 NETLINK_CB(cb->skb).portid,
Holger Schurig61fa7132009-11-11 12:25:40 +01007684 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Johannes Berg11f78ac2014-11-14 16:43:50 +01007685 wdev->netdev, radio_stats, &survey) < 0)
Holger Schurig61fa7132009-11-11 12:25:40 +01007686 goto out;
7687 survey_idx++;
7688 }
7689
7690 out:
Johannes Berg97990a02013-04-19 01:02:55 +02007691 cb->args[2] = survey_idx;
Holger Schurig61fa7132009-11-11 12:25:40 +01007692 res = skb->len;
7693 out_err:
Zhao, Gang1b8ec872014-04-21 12:53:02 +08007694 nl80211_finish_wdev_dump(rdev);
Holger Schurig61fa7132009-11-11 12:25:40 +01007695 return res;
7696}
7697
Samuel Ortizb23aa672009-07-01 21:26:54 +02007698static bool nl80211_valid_wpa_versions(u32 wpa_versions)
7699{
7700 return !(wpa_versions & ~(NL80211_WPA_VERSION_1 |
7701 NL80211_WPA_VERSION_2));
7702}
7703
Jouni Malinen636a5d32009-03-19 13:39:22 +02007704static int nl80211_authenticate(struct sk_buff *skb, struct genl_info *info)
7705{
Johannes Berg4c476992010-10-04 21:36:35 +02007706 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7707 struct net_device *dev = info->user_ptr[1];
Johannes Berg19957bb2009-07-02 17:20:43 +02007708 struct ieee80211_channel *chan;
Jouni Malinene39e5b52012-09-30 19:29:39 +03007709 const u8 *bssid, *ssid, *ie = NULL, *sae_data = NULL;
7710 int err, ssid_len, ie_len = 0, sae_data_len = 0;
Johannes Berg19957bb2009-07-02 17:20:43 +02007711 enum nl80211_auth_type auth_type;
Johannes Bergfffd0932009-07-08 14:22:54 +02007712 struct key_parse key;
Jouni Malinend5cdfac2010-04-04 09:37:19 +03007713 bool local_state_change;
Jouni Malinen636a5d32009-03-19 13:39:22 +02007714
Johannes Bergf4a11bb2009-03-27 12:40:28 +01007715 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
7716 return -EINVAL;
7717
7718 if (!info->attrs[NL80211_ATTR_MAC])
7719 return -EINVAL;
7720
Jouni Malinen17780922009-03-27 20:52:47 +02007721 if (!info->attrs[NL80211_ATTR_AUTH_TYPE])
7722 return -EINVAL;
7723
Johannes Berg19957bb2009-07-02 17:20:43 +02007724 if (!info->attrs[NL80211_ATTR_SSID])
7725 return -EINVAL;
7726
7727 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ])
7728 return -EINVAL;
7729
Johannes Bergfffd0932009-07-08 14:22:54 +02007730 err = nl80211_parse_key(info, &key);
7731 if (err)
7732 return err;
7733
7734 if (key.idx >= 0) {
Johannes Berge31b8212010-10-05 19:39:30 +02007735 if (key.type != -1 && key.type != NL80211_KEYTYPE_GROUP)
7736 return -EINVAL;
Johannes Bergfffd0932009-07-08 14:22:54 +02007737 if (!key.p.key || !key.p.key_len)
7738 return -EINVAL;
7739 if ((key.p.cipher != WLAN_CIPHER_SUITE_WEP40 ||
7740 key.p.key_len != WLAN_KEY_LEN_WEP40) &&
7741 (key.p.cipher != WLAN_CIPHER_SUITE_WEP104 ||
7742 key.p.key_len != WLAN_KEY_LEN_WEP104))
7743 return -EINVAL;
Johannes Bergb6b55552016-09-13 16:25:58 +02007744 if (key.idx > 3)
Johannes Bergfffd0932009-07-08 14:22:54 +02007745 return -EINVAL;
7746 } else {
7747 key.p.key_len = 0;
7748 key.p.key = NULL;
7749 }
7750
Johannes Bergafea0b72010-08-10 09:46:42 +02007751 if (key.idx >= 0) {
7752 int i;
7753 bool ok = false;
Kirtika Ruchandani7a087e72016-05-29 19:51:23 -07007754
Johannes Bergafea0b72010-08-10 09:46:42 +02007755 for (i = 0; i < rdev->wiphy.n_cipher_suites; i++) {
7756 if (key.p.cipher == rdev->wiphy.cipher_suites[i]) {
7757 ok = true;
7758 break;
7759 }
7760 }
Johannes Berg4c476992010-10-04 21:36:35 +02007761 if (!ok)
7762 return -EINVAL;
Johannes Bergafea0b72010-08-10 09:46:42 +02007763 }
7764
Johannes Berg4c476992010-10-04 21:36:35 +02007765 if (!rdev->ops->auth)
7766 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02007767
Johannes Berg074ac8d2010-09-16 14:58:22 +02007768 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02007769 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
7770 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02007771
Johannes Berg19957bb2009-07-02 17:20:43 +02007772 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen664834d2014-01-15 00:01:44 +02007773 chan = nl80211_get_valid_chan(&rdev->wiphy,
7774 info->attrs[NL80211_ATTR_WIPHY_FREQ]);
7775 if (!chan)
Johannes Berg4c476992010-10-04 21:36:35 +02007776 return -EINVAL;
Jouni Malinen636a5d32009-03-19 13:39:22 +02007777
Johannes Berg19957bb2009-07-02 17:20:43 +02007778 ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
7779 ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
7780
7781 if (info->attrs[NL80211_ATTR_IE]) {
7782 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
7783 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
7784 }
7785
7786 auth_type = nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]);
Jouni Malinene39e5b52012-09-30 19:29:39 +03007787 if (!nl80211_valid_auth_type(rdev, auth_type, NL80211_CMD_AUTHENTICATE))
Johannes Berg4c476992010-10-04 21:36:35 +02007788 return -EINVAL;
Johannes Berg19957bb2009-07-02 17:20:43 +02007789
Jouni Malinene39e5b52012-09-30 19:29:39 +03007790 if (auth_type == NL80211_AUTHTYPE_SAE &&
7791 !info->attrs[NL80211_ATTR_SAE_DATA])
7792 return -EINVAL;
7793
7794 if (info->attrs[NL80211_ATTR_SAE_DATA]) {
7795 if (auth_type != NL80211_AUTHTYPE_SAE)
7796 return -EINVAL;
7797 sae_data = nla_data(info->attrs[NL80211_ATTR_SAE_DATA]);
7798 sae_data_len = nla_len(info->attrs[NL80211_ATTR_SAE_DATA]);
7799 /* need to include at least Auth Transaction and Status Code */
7800 if (sae_data_len < 4)
7801 return -EINVAL;
7802 }
7803
Jouni Malinend5cdfac2010-04-04 09:37:19 +03007804 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE];
7805
Johannes Berg95de8172012-01-20 13:55:25 +01007806 /*
7807 * Since we no longer track auth state, ignore
7808 * requests to only change local state.
7809 */
7810 if (local_state_change)
7811 return 0;
7812
Johannes Berg91bf9b22013-05-15 17:44:01 +02007813 wdev_lock(dev->ieee80211_ptr);
7814 err = cfg80211_mlme_auth(rdev, dev, chan, auth_type, bssid,
7815 ssid, ssid_len, ie, ie_len,
7816 key.p.key, key.p.key_len, key.idx,
7817 sae_data, sae_data_len);
7818 wdev_unlock(dev->ieee80211_ptr);
7819 return err;
Jouni Malinen636a5d32009-03-19 13:39:22 +02007820}
7821
Johannes Bergc0692b82010-08-27 14:26:53 +03007822static int nl80211_crypto_settings(struct cfg80211_registered_device *rdev,
7823 struct genl_info *info,
Johannes Berg3dc27d22009-07-02 21:36:37 +02007824 struct cfg80211_crypto_settings *settings,
7825 int cipher_limit)
Samuel Ortizb23aa672009-07-01 21:26:54 +02007826{
Johannes Bergc0b2bbd2009-07-25 16:54:36 +02007827 memset(settings, 0, sizeof(*settings));
7828
Samuel Ortizb23aa672009-07-01 21:26:54 +02007829 settings->control_port = info->attrs[NL80211_ATTR_CONTROL_PORT];
7830
Johannes Bergc0692b82010-08-27 14:26:53 +03007831 if (info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]) {
7832 u16 proto;
Kirtika Ruchandani7a087e72016-05-29 19:51:23 -07007833
Johannes Bergc0692b82010-08-27 14:26:53 +03007834 proto = nla_get_u16(
7835 info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]);
7836 settings->control_port_ethertype = cpu_to_be16(proto);
7837 if (!(rdev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) &&
7838 proto != ETH_P_PAE)
7839 return -EINVAL;
7840 if (info->attrs[NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT])
7841 settings->control_port_no_encrypt = true;
7842 } else
7843 settings->control_port_ethertype = cpu_to_be16(ETH_P_PAE);
7844
Samuel Ortizb23aa672009-07-01 21:26:54 +02007845 if (info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]) {
7846 void *data;
7847 int len, i;
7848
7849 data = nla_data(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]);
7850 len = nla_len(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]);
7851 settings->n_ciphers_pairwise = len / sizeof(u32);
7852
7853 if (len % sizeof(u32))
7854 return -EINVAL;
7855
Johannes Berg3dc27d22009-07-02 21:36:37 +02007856 if (settings->n_ciphers_pairwise > cipher_limit)
Samuel Ortizb23aa672009-07-01 21:26:54 +02007857 return -EINVAL;
7858
7859 memcpy(settings->ciphers_pairwise, data, len);
7860
7861 for (i = 0; i < settings->n_ciphers_pairwise; i++)
Jouni Malinen38ba3c52011-09-21 18:14:56 +03007862 if (!cfg80211_supported_cipher_suite(
7863 &rdev->wiphy,
Samuel Ortizb23aa672009-07-01 21:26:54 +02007864 settings->ciphers_pairwise[i]))
7865 return -EINVAL;
7866 }
7867
7868 if (info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]) {
7869 settings->cipher_group =
7870 nla_get_u32(info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]);
Jouni Malinen38ba3c52011-09-21 18:14:56 +03007871 if (!cfg80211_supported_cipher_suite(&rdev->wiphy,
7872 settings->cipher_group))
Samuel Ortizb23aa672009-07-01 21:26:54 +02007873 return -EINVAL;
7874 }
7875
7876 if (info->attrs[NL80211_ATTR_WPA_VERSIONS]) {
7877 settings->wpa_versions =
7878 nla_get_u32(info->attrs[NL80211_ATTR_WPA_VERSIONS]);
7879 if (!nl80211_valid_wpa_versions(settings->wpa_versions))
7880 return -EINVAL;
7881 }
7882
7883 if (info->attrs[NL80211_ATTR_AKM_SUITES]) {
7884 void *data;
Jouni Malinen6d302402011-09-21 18:11:33 +03007885 int len;
Samuel Ortizb23aa672009-07-01 21:26:54 +02007886
7887 data = nla_data(info->attrs[NL80211_ATTR_AKM_SUITES]);
7888 len = nla_len(info->attrs[NL80211_ATTR_AKM_SUITES]);
7889 settings->n_akm_suites = len / sizeof(u32);
7890
7891 if (len % sizeof(u32))
7892 return -EINVAL;
7893
Jouni Malinen1b9ca022011-09-21 16:13:07 +03007894 if (settings->n_akm_suites > NL80211_MAX_NR_AKM_SUITES)
7895 return -EINVAL;
7896
Samuel Ortizb23aa672009-07-01 21:26:54 +02007897 memcpy(settings->akm_suites, data, len);
Samuel Ortizb23aa672009-07-01 21:26:54 +02007898 }
7899
7900 return 0;
7901}
7902
Jouni Malinen636a5d32009-03-19 13:39:22 +02007903static int nl80211_associate(struct sk_buff *skb, struct genl_info *info)
7904{
Johannes Berg4c476992010-10-04 21:36:35 +02007905 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7906 struct net_device *dev = info->user_ptr[1];
Johannes Bergf444de02010-05-05 15:25:02 +02007907 struct ieee80211_channel *chan;
Johannes Bergf62fab72013-02-21 20:09:09 +01007908 struct cfg80211_assoc_request req = {};
7909 const u8 *bssid, *ssid;
7910 int err, ssid_len = 0;
Jouni Malinen636a5d32009-03-19 13:39:22 +02007911
Johannes Bergf4a11bb2009-03-27 12:40:28 +01007912 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
7913 return -EINVAL;
7914
7915 if (!info->attrs[NL80211_ATTR_MAC] ||
Johannes Berg19957bb2009-07-02 17:20:43 +02007916 !info->attrs[NL80211_ATTR_SSID] ||
7917 !info->attrs[NL80211_ATTR_WIPHY_FREQ])
Johannes Bergf4a11bb2009-03-27 12:40:28 +01007918 return -EINVAL;
7919
Johannes Berg4c476992010-10-04 21:36:35 +02007920 if (!rdev->ops->assoc)
7921 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02007922
Johannes Berg074ac8d2010-09-16 14:58:22 +02007923 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02007924 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
7925 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02007926
Johannes Berg19957bb2009-07-02 17:20:43 +02007927 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02007928
Jouni Malinen664834d2014-01-15 00:01:44 +02007929 chan = nl80211_get_valid_chan(&rdev->wiphy,
7930 info->attrs[NL80211_ATTR_WIPHY_FREQ]);
7931 if (!chan)
Johannes Berg4c476992010-10-04 21:36:35 +02007932 return -EINVAL;
Jouni Malinen636a5d32009-03-19 13:39:22 +02007933
Johannes Berg19957bb2009-07-02 17:20:43 +02007934 ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
7935 ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02007936
7937 if (info->attrs[NL80211_ATTR_IE]) {
Johannes Bergf62fab72013-02-21 20:09:09 +01007938 req.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
7939 req.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02007940 }
7941
Jouni Malinendc6382ce2009-05-06 22:09:37 +03007942 if (info->attrs[NL80211_ATTR_USE_MFP]) {
Johannes Berg4f5dadc2009-07-07 03:56:10 +02007943 enum nl80211_mfp mfp =
Jouni Malinendc6382ce2009-05-06 22:09:37 +03007944 nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]);
Johannes Berg4f5dadc2009-07-07 03:56:10 +02007945 if (mfp == NL80211_MFP_REQUIRED)
Johannes Bergf62fab72013-02-21 20:09:09 +01007946 req.use_mfp = true;
Johannes Berg4c476992010-10-04 21:36:35 +02007947 else if (mfp != NL80211_MFP_NO)
7948 return -EINVAL;
Jouni Malinendc6382ce2009-05-06 22:09:37 +03007949 }
7950
Johannes Berg3e5d7642009-07-07 14:37:26 +02007951 if (info->attrs[NL80211_ATTR_PREV_BSSID])
Johannes Bergf62fab72013-02-21 20:09:09 +01007952 req.prev_bssid = nla_data(info->attrs[NL80211_ATTR_PREV_BSSID]);
Johannes Berg3e5d7642009-07-07 14:37:26 +02007953
Ben Greear7e7c8922011-11-18 11:31:59 -08007954 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT]))
Johannes Bergf62fab72013-02-21 20:09:09 +01007955 req.flags |= ASSOC_REQ_DISABLE_HT;
Ben Greear7e7c8922011-11-18 11:31:59 -08007956
7957 if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
Johannes Bergf62fab72013-02-21 20:09:09 +01007958 memcpy(&req.ht_capa_mask,
7959 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]),
7960 sizeof(req.ht_capa_mask));
Ben Greear7e7c8922011-11-18 11:31:59 -08007961
7962 if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) {
Johannes Bergf62fab72013-02-21 20:09:09 +01007963 if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
Ben Greear7e7c8922011-11-18 11:31:59 -08007964 return -EINVAL;
Johannes Bergf62fab72013-02-21 20:09:09 +01007965 memcpy(&req.ht_capa,
7966 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]),
7967 sizeof(req.ht_capa));
Ben Greear7e7c8922011-11-18 11:31:59 -08007968 }
7969
Johannes Bergee2aca32013-02-21 17:36:01 +01007970 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_VHT]))
Johannes Bergf62fab72013-02-21 20:09:09 +01007971 req.flags |= ASSOC_REQ_DISABLE_VHT;
Johannes Bergee2aca32013-02-21 17:36:01 +01007972
7973 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK])
Johannes Bergf62fab72013-02-21 20:09:09 +01007974 memcpy(&req.vht_capa_mask,
7975 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]),
7976 sizeof(req.vht_capa_mask));
Johannes Bergee2aca32013-02-21 17:36:01 +01007977
7978 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) {
Johannes Bergf62fab72013-02-21 20:09:09 +01007979 if (!info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK])
Johannes Bergee2aca32013-02-21 17:36:01 +01007980 return -EINVAL;
Johannes Bergf62fab72013-02-21 20:09:09 +01007981 memcpy(&req.vht_capa,
7982 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]),
7983 sizeof(req.vht_capa));
Johannes Bergee2aca32013-02-21 17:36:01 +01007984 }
7985
Assaf Kraussbab5ab72014-09-03 15:25:01 +03007986 if (nla_get_flag(info->attrs[NL80211_ATTR_USE_RRM])) {
Beni Lev0c9ca112016-02-17 20:30:00 +02007987 if (!((rdev->wiphy.features &
7988 NL80211_FEATURE_DS_PARAM_SET_IE_IN_PROBES) &&
7989 (rdev->wiphy.features & NL80211_FEATURE_QUIET)) &&
7990 !wiphy_ext_feature_isset(&rdev->wiphy,
7991 NL80211_EXT_FEATURE_RRM))
Assaf Kraussbab5ab72014-09-03 15:25:01 +03007992 return -EINVAL;
7993 req.flags |= ASSOC_REQ_USE_RRM;
7994 }
7995
Johannes Bergf62fab72013-02-21 20:09:09 +01007996 err = nl80211_crypto_settings(rdev, info, &req.crypto, 1);
Johannes Berg91bf9b22013-05-15 17:44:01 +02007997 if (!err) {
7998 wdev_lock(dev->ieee80211_ptr);
Johannes Bergf62fab72013-02-21 20:09:09 +01007999 err = cfg80211_mlme_assoc(rdev, dev, chan, bssid,
8000 ssid, ssid_len, &req);
Johannes Berg91bf9b22013-05-15 17:44:01 +02008001 wdev_unlock(dev->ieee80211_ptr);
8002 }
Jouni Malinen636a5d32009-03-19 13:39:22 +02008003
Jouni Malinen636a5d32009-03-19 13:39:22 +02008004 return err;
8005}
8006
8007static int nl80211_deauthenticate(struct sk_buff *skb, struct genl_info *info)
8008{
Johannes Berg4c476992010-10-04 21:36:35 +02008009 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8010 struct net_device *dev = info->user_ptr[1];
Johannes Berg19957bb2009-07-02 17:20:43 +02008011 const u8 *ie = NULL, *bssid;
Johannes Berg91bf9b22013-05-15 17:44:01 +02008012 int ie_len = 0, err;
Johannes Berg19957bb2009-07-02 17:20:43 +02008013 u16 reason_code;
Jouni Malinend5cdfac2010-04-04 09:37:19 +03008014 bool local_state_change;
Jouni Malinen636a5d32009-03-19 13:39:22 +02008015
Johannes Bergf4a11bb2009-03-27 12:40:28 +01008016 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
8017 return -EINVAL;
8018
8019 if (!info->attrs[NL80211_ATTR_MAC])
8020 return -EINVAL;
8021
8022 if (!info->attrs[NL80211_ATTR_REASON_CODE])
8023 return -EINVAL;
8024
Johannes Berg4c476992010-10-04 21:36:35 +02008025 if (!rdev->ops->deauth)
8026 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02008027
Johannes Berg074ac8d2010-09-16 14:58:22 +02008028 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02008029 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
8030 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02008031
Johannes Berg19957bb2009-07-02 17:20:43 +02008032 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02008033
Johannes Berg19957bb2009-07-02 17:20:43 +02008034 reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
8035 if (reason_code == 0) {
Johannes Bergf4a11bb2009-03-27 12:40:28 +01008036 /* Reason Code 0 is reserved */
Johannes Berg4c476992010-10-04 21:36:35 +02008037 return -EINVAL;
Jouni Malinen255e7372009-03-20 21:21:17 +02008038 }
Jouni Malinen636a5d32009-03-19 13:39:22 +02008039
8040 if (info->attrs[NL80211_ATTR_IE]) {
Johannes Berg19957bb2009-07-02 17:20:43 +02008041 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
8042 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02008043 }
8044
Jouni Malinend5cdfac2010-04-04 09:37:19 +03008045 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE];
8046
Johannes Berg91bf9b22013-05-15 17:44:01 +02008047 wdev_lock(dev->ieee80211_ptr);
8048 err = cfg80211_mlme_deauth(rdev, dev, bssid, ie, ie_len, reason_code,
8049 local_state_change);
8050 wdev_unlock(dev->ieee80211_ptr);
8051 return err;
Jouni Malinen636a5d32009-03-19 13:39:22 +02008052}
8053
8054static int nl80211_disassociate(struct sk_buff *skb, struct genl_info *info)
8055{
Johannes Berg4c476992010-10-04 21:36:35 +02008056 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8057 struct net_device *dev = info->user_ptr[1];
Johannes Berg19957bb2009-07-02 17:20:43 +02008058 const u8 *ie = NULL, *bssid;
Johannes Berg91bf9b22013-05-15 17:44:01 +02008059 int ie_len = 0, err;
Johannes Berg19957bb2009-07-02 17:20:43 +02008060 u16 reason_code;
Jouni Malinend5cdfac2010-04-04 09:37:19 +03008061 bool local_state_change;
Jouni Malinen636a5d32009-03-19 13:39:22 +02008062
Johannes Bergf4a11bb2009-03-27 12:40:28 +01008063 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
8064 return -EINVAL;
8065
8066 if (!info->attrs[NL80211_ATTR_MAC])
8067 return -EINVAL;
8068
8069 if (!info->attrs[NL80211_ATTR_REASON_CODE])
8070 return -EINVAL;
8071
Johannes Berg4c476992010-10-04 21:36:35 +02008072 if (!rdev->ops->disassoc)
8073 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02008074
Johannes Berg074ac8d2010-09-16 14:58:22 +02008075 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02008076 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
8077 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02008078
Johannes Berg19957bb2009-07-02 17:20:43 +02008079 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02008080
Johannes Berg19957bb2009-07-02 17:20:43 +02008081 reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
8082 if (reason_code == 0) {
Johannes Bergf4a11bb2009-03-27 12:40:28 +01008083 /* Reason Code 0 is reserved */
Johannes Berg4c476992010-10-04 21:36:35 +02008084 return -EINVAL;
Jouni Malinen255e7372009-03-20 21:21:17 +02008085 }
Jouni Malinen636a5d32009-03-19 13:39:22 +02008086
8087 if (info->attrs[NL80211_ATTR_IE]) {
Johannes Berg19957bb2009-07-02 17:20:43 +02008088 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
8089 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02008090 }
8091
Jouni Malinend5cdfac2010-04-04 09:37:19 +03008092 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE];
8093
Johannes Berg91bf9b22013-05-15 17:44:01 +02008094 wdev_lock(dev->ieee80211_ptr);
8095 err = cfg80211_mlme_disassoc(rdev, dev, bssid, ie, ie_len, reason_code,
8096 local_state_change);
8097 wdev_unlock(dev->ieee80211_ptr);
8098 return err;
Jouni Malinen636a5d32009-03-19 13:39:22 +02008099}
8100
Felix Fietkaudd5b4cc2010-11-22 20:58:24 +01008101static bool
8102nl80211_parse_mcast_rate(struct cfg80211_registered_device *rdev,
Johannes Berg57fbcce2016-04-12 15:56:15 +02008103 int mcast_rate[NUM_NL80211_BANDS],
Felix Fietkaudd5b4cc2010-11-22 20:58:24 +01008104 int rateval)
8105{
8106 struct wiphy *wiphy = &rdev->wiphy;
8107 bool found = false;
8108 int band, i;
8109
Johannes Berg57fbcce2016-04-12 15:56:15 +02008110 for (band = 0; band < NUM_NL80211_BANDS; band++) {
Felix Fietkaudd5b4cc2010-11-22 20:58:24 +01008111 struct ieee80211_supported_band *sband;
8112
8113 sband = wiphy->bands[band];
8114 if (!sband)
8115 continue;
8116
8117 for (i = 0; i < sband->n_bitrates; i++) {
8118 if (sband->bitrates[i].bitrate == rateval) {
8119 mcast_rate[band] = i + 1;
8120 found = true;
8121 break;
8122 }
8123 }
8124 }
8125
8126 return found;
8127}
8128
Johannes Berg04a773a2009-04-19 21:24:32 +02008129static int nl80211_join_ibss(struct sk_buff *skb, struct genl_info *info)
8130{
Johannes Berg4c476992010-10-04 21:36:35 +02008131 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8132 struct net_device *dev = info->user_ptr[1];
Johannes Berg04a773a2009-04-19 21:24:32 +02008133 struct cfg80211_ibss_params ibss;
8134 struct wiphy *wiphy;
Johannes Bergfffd0932009-07-08 14:22:54 +02008135 struct cfg80211_cached_keys *connkeys = NULL;
Johannes Berg04a773a2009-04-19 21:24:32 +02008136 int err;
8137
Johannes Berg8e30bc52009-04-22 17:45:38 +02008138 memset(&ibss, 0, sizeof(ibss));
8139
Johannes Berg04a773a2009-04-19 21:24:32 +02008140 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
8141 return -EINVAL;
8142
Johannes Berg683b6d32012-11-08 21:25:48 +01008143 if (!info->attrs[NL80211_ATTR_SSID] ||
Johannes Berg04a773a2009-04-19 21:24:32 +02008144 !nla_len(info->attrs[NL80211_ATTR_SSID]))
8145 return -EINVAL;
8146
Johannes Berg8e30bc52009-04-22 17:45:38 +02008147 ibss.beacon_interval = 100;
8148
Purushottam Kushwaha12d20fc92016-08-11 15:14:02 +05308149 if (info->attrs[NL80211_ATTR_BEACON_INTERVAL])
Johannes Berg8e30bc52009-04-22 17:45:38 +02008150 ibss.beacon_interval =
8151 nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]);
Purushottam Kushwaha12d20fc92016-08-11 15:14:02 +05308152
8153 err = cfg80211_validate_beacon_int(rdev, ibss.beacon_interval);
8154 if (err)
8155 return err;
Johannes Berg8e30bc52009-04-22 17:45:38 +02008156
Johannes Berg4c476992010-10-04 21:36:35 +02008157 if (!rdev->ops->join_ibss)
8158 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02008159
Johannes Berg4c476992010-10-04 21:36:35 +02008160 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC)
8161 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02008162
Johannes Berg79c97e92009-07-07 03:56:12 +02008163 wiphy = &rdev->wiphy;
Johannes Berg04a773a2009-04-19 21:24:32 +02008164
Johannes Berg39193492011-09-16 13:45:25 +02008165 if (info->attrs[NL80211_ATTR_MAC]) {
Johannes Berg04a773a2009-04-19 21:24:32 +02008166 ibss.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Johannes Berg39193492011-09-16 13:45:25 +02008167
8168 if (!is_valid_ether_addr(ibss.bssid))
8169 return -EINVAL;
8170 }
Johannes Berg04a773a2009-04-19 21:24:32 +02008171 ibss.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
8172 ibss.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
8173
8174 if (info->attrs[NL80211_ATTR_IE]) {
8175 ibss.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
8176 ibss.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
8177 }
8178
Johannes Berg683b6d32012-11-08 21:25:48 +01008179 err = nl80211_parse_chandef(rdev, info, &ibss.chandef);
8180 if (err)
8181 return err;
Alexander Simon54858ee5b2011-11-30 16:56:32 +01008182
Ilan Peer174e0cd2014-02-23 09:13:01 +02008183 if (!cfg80211_reg_can_beacon(&rdev->wiphy, &ibss.chandef,
8184 NL80211_IFTYPE_ADHOC))
Alexander Simon54858ee5b2011-11-30 16:56:32 +01008185 return -EINVAL;
8186
Simon Wunderlich2f301ab2013-05-16 13:00:28 +02008187 switch (ibss.chandef.width) {
Simon Wunderlichbf372642013-07-08 16:55:58 +02008188 case NL80211_CHAN_WIDTH_5:
8189 case NL80211_CHAN_WIDTH_10:
Simon Wunderlich2f301ab2013-05-16 13:00:28 +02008190 case NL80211_CHAN_WIDTH_20_NOHT:
8191 break;
8192 case NL80211_CHAN_WIDTH_20:
8193 case NL80211_CHAN_WIDTH_40:
Janusz.Dziedzic@tieto.comffc11992015-02-21 16:52:39 +01008194 if (!(rdev->wiphy.features & NL80211_FEATURE_HT_IBSS))
8195 return -EINVAL;
8196 break;
8197 case NL80211_CHAN_WIDTH_80:
8198 case NL80211_CHAN_WIDTH_80P80:
8199 case NL80211_CHAN_WIDTH_160:
8200 if (!(rdev->wiphy.features & NL80211_FEATURE_HT_IBSS))
8201 return -EINVAL;
8202 if (!wiphy_ext_feature_isset(&rdev->wiphy,
8203 NL80211_EXT_FEATURE_VHT_IBSS))
8204 return -EINVAL;
8205 break;
Simon Wunderlich2f301ab2013-05-16 13:00:28 +02008206 default:
Johannes Bergdb9c64c2012-11-09 14:56:41 +01008207 return -EINVAL;
Simon Wunderlich2f301ab2013-05-16 13:00:28 +02008208 }
Johannes Bergdb9c64c2012-11-09 14:56:41 +01008209
Johannes Berg04a773a2009-04-19 21:24:32 +02008210 ibss.channel_fixed = !!info->attrs[NL80211_ATTR_FREQ_FIXED];
Johannes Bergfffd0932009-07-08 14:22:54 +02008211 ibss.privacy = !!info->attrs[NL80211_ATTR_PRIVACY];
Johannes Berg04a773a2009-04-19 21:24:32 +02008212
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03008213 if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) {
8214 u8 *rates =
8215 nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
8216 int n_rates =
8217 nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
8218 struct ieee80211_supported_band *sband =
Johannes Berg683b6d32012-11-08 21:25:48 +01008219 wiphy->bands[ibss.chandef.chan->band];
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03008220
Johannes Berg34850ab2011-07-18 18:08:35 +02008221 err = ieee80211_get_ratemask(sband, rates, n_rates,
8222 &ibss.basic_rates);
8223 if (err)
8224 return err;
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03008225 }
Felix Fietkaudd5b4cc2010-11-22 20:58:24 +01008226
Simon Wunderlich803768f2013-06-28 10:39:58 +02008227 if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
8228 memcpy(&ibss.ht_capa_mask,
8229 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]),
8230 sizeof(ibss.ht_capa_mask));
8231
8232 if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) {
8233 if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
8234 return -EINVAL;
8235 memcpy(&ibss.ht_capa,
8236 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]),
8237 sizeof(ibss.ht_capa));
8238 }
8239
Felix Fietkaudd5b4cc2010-11-22 20:58:24 +01008240 if (info->attrs[NL80211_ATTR_MCAST_RATE] &&
8241 !nl80211_parse_mcast_rate(rdev, ibss.mcast_rate,
8242 nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE])))
8243 return -EINVAL;
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03008244
Johannes Berg4c476992010-10-04 21:36:35 +02008245 if (ibss.privacy && info->attrs[NL80211_ATTR_KEYS]) {
Sujith Manoharande7044e2012-10-18 10:19:28 +05308246 bool no_ht = false;
8247
Johannes Berg4c476992010-10-04 21:36:35 +02008248 connkeys = nl80211_parse_connkeys(rdev,
Sujith Manoharande7044e2012-10-18 10:19:28 +05308249 info->attrs[NL80211_ATTR_KEYS],
8250 &no_ht);
Johannes Berg4c476992010-10-04 21:36:35 +02008251 if (IS_ERR(connkeys))
8252 return PTR_ERR(connkeys);
Sujith Manoharande7044e2012-10-18 10:19:28 +05308253
Johannes Berg3d9d1d62012-11-08 23:14:50 +01008254 if ((ibss.chandef.width != NL80211_CHAN_WIDTH_20_NOHT) &&
8255 no_ht) {
Ola Olsson5e950a72016-02-11 01:00:22 +01008256 kzfree(connkeys);
Sujith Manoharande7044e2012-10-18 10:19:28 +05308257 return -EINVAL;
8258 }
Johannes Berg4c476992010-10-04 21:36:35 +02008259 }
Johannes Berg04a773a2009-04-19 21:24:32 +02008260
Antonio Quartulli267335d2012-01-31 20:25:47 +01008261 ibss.control_port =
8262 nla_get_flag(info->attrs[NL80211_ATTR_CONTROL_PORT]);
8263
Simon Wunderlich5336fa82013-10-07 18:41:05 +02008264 ibss.userspace_handles_dfs =
8265 nla_get_flag(info->attrs[NL80211_ATTR_HANDLE_DFS]);
8266
Johannes Berg4c476992010-10-04 21:36:35 +02008267 err = cfg80211_join_ibss(rdev, dev, &ibss, connkeys);
Johannes Bergfffd0932009-07-08 14:22:54 +02008268 if (err)
Johannes Bergb47f6102014-09-10 13:39:54 +03008269 kzfree(connkeys);
Johannes Berg04a773a2009-04-19 21:24:32 +02008270 return err;
8271}
8272
8273static int nl80211_leave_ibss(struct sk_buff *skb, struct genl_info *info)
8274{
Johannes Berg4c476992010-10-04 21:36:35 +02008275 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8276 struct net_device *dev = info->user_ptr[1];
Johannes Berg04a773a2009-04-19 21:24:32 +02008277
Johannes Berg4c476992010-10-04 21:36:35 +02008278 if (!rdev->ops->leave_ibss)
8279 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02008280
Johannes Berg4c476992010-10-04 21:36:35 +02008281 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC)
8282 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02008283
Johannes Berg4c476992010-10-04 21:36:35 +02008284 return cfg80211_leave_ibss(rdev, dev, false);
Johannes Berg04a773a2009-04-19 21:24:32 +02008285}
8286
Antonio Quartullif4e583c2012-11-02 13:27:48 +01008287static int nl80211_set_mcast_rate(struct sk_buff *skb, struct genl_info *info)
8288{
8289 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8290 struct net_device *dev = info->user_ptr[1];
Johannes Berg57fbcce2016-04-12 15:56:15 +02008291 int mcast_rate[NUM_NL80211_BANDS];
Antonio Quartullif4e583c2012-11-02 13:27:48 +01008292 u32 nla_rate;
8293 int err;
8294
8295 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC &&
Bertold Van den Bergh876dc932015-08-05 16:02:21 +02008296 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT &&
8297 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_OCB)
Antonio Quartullif4e583c2012-11-02 13:27:48 +01008298 return -EOPNOTSUPP;
8299
8300 if (!rdev->ops->set_mcast_rate)
8301 return -EOPNOTSUPP;
8302
8303 memset(mcast_rate, 0, sizeof(mcast_rate));
8304
8305 if (!info->attrs[NL80211_ATTR_MCAST_RATE])
8306 return -EINVAL;
8307
8308 nla_rate = nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]);
8309 if (!nl80211_parse_mcast_rate(rdev, mcast_rate, nla_rate))
8310 return -EINVAL;
8311
Ilan Peera1056b1b2015-10-22 22:27:46 +03008312 err = rdev_set_mcast_rate(rdev, dev, mcast_rate);
Antonio Quartullif4e583c2012-11-02 13:27:48 +01008313
8314 return err;
8315}
8316
Johannes Bergad7e7182013-11-13 13:37:47 +01008317static struct sk_buff *
8318__cfg80211_alloc_vendor_skb(struct cfg80211_registered_device *rdev,
Ahmad Kholaif6c09e792015-02-26 15:26:53 +02008319 struct wireless_dev *wdev, int approxlen,
8320 u32 portid, u32 seq, enum nl80211_commands cmd,
Johannes Berg567ffc32013-12-18 14:43:31 +01008321 enum nl80211_attrs attr,
8322 const struct nl80211_vendor_cmd_info *info,
8323 gfp_t gfp)
Johannes Bergad7e7182013-11-13 13:37:47 +01008324{
8325 struct sk_buff *skb;
8326 void *hdr;
8327 struct nlattr *data;
8328
8329 skb = nlmsg_new(approxlen + 100, gfp);
8330 if (!skb)
8331 return NULL;
8332
8333 hdr = nl80211hdr_put(skb, portid, seq, 0, cmd);
8334 if (!hdr) {
8335 kfree_skb(skb);
8336 return NULL;
8337 }
8338
8339 if (nla_put_u32(skb, NL80211_ATTR_WIPHY, rdev->wiphy_idx))
8340 goto nla_put_failure;
Johannes Berg567ffc32013-12-18 14:43:31 +01008341
8342 if (info) {
8343 if (nla_put_u32(skb, NL80211_ATTR_VENDOR_ID,
8344 info->vendor_id))
8345 goto nla_put_failure;
8346 if (nla_put_u32(skb, NL80211_ATTR_VENDOR_SUBCMD,
8347 info->subcmd))
8348 goto nla_put_failure;
8349 }
8350
Ahmad Kholaif6c09e792015-02-26 15:26:53 +02008351 if (wdev) {
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02008352 if (nla_put_u64_64bit(skb, NL80211_ATTR_WDEV,
8353 wdev_id(wdev), NL80211_ATTR_PAD))
Ahmad Kholaif6c09e792015-02-26 15:26:53 +02008354 goto nla_put_failure;
8355 if (wdev->netdev &&
8356 nla_put_u32(skb, NL80211_ATTR_IFINDEX,
8357 wdev->netdev->ifindex))
8358 goto nla_put_failure;
8359 }
8360
Johannes Bergad7e7182013-11-13 13:37:47 +01008361 data = nla_nest_start(skb, attr);
Johannes Berg76e1fb42016-09-14 09:55:57 +02008362 if (!data)
8363 goto nla_put_failure;
Johannes Bergad7e7182013-11-13 13:37:47 +01008364
8365 ((void **)skb->cb)[0] = rdev;
8366 ((void **)skb->cb)[1] = hdr;
8367 ((void **)skb->cb)[2] = data;
8368
8369 return skb;
8370
8371 nla_put_failure:
8372 kfree_skb(skb);
8373 return NULL;
8374}
Antonio Quartullif4e583c2012-11-02 13:27:48 +01008375
Johannes Berge03ad6e2014-01-01 17:22:30 +01008376struct sk_buff *__cfg80211_alloc_event_skb(struct wiphy *wiphy,
Ahmad Kholaif6c09e792015-02-26 15:26:53 +02008377 struct wireless_dev *wdev,
Johannes Berge03ad6e2014-01-01 17:22:30 +01008378 enum nl80211_commands cmd,
8379 enum nl80211_attrs attr,
8380 int vendor_event_idx,
8381 int approxlen, gfp_t gfp)
8382{
Zhao, Gangf26cbf42014-04-21 12:53:03 +08008383 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berge03ad6e2014-01-01 17:22:30 +01008384 const struct nl80211_vendor_cmd_info *info;
8385
8386 switch (cmd) {
8387 case NL80211_CMD_TESTMODE:
8388 if (WARN_ON(vendor_event_idx != -1))
8389 return NULL;
8390 info = NULL;
8391 break;
8392 case NL80211_CMD_VENDOR:
8393 if (WARN_ON(vendor_event_idx < 0 ||
8394 vendor_event_idx >= wiphy->n_vendor_events))
8395 return NULL;
8396 info = &wiphy->vendor_events[vendor_event_idx];
8397 break;
8398 default:
8399 WARN_ON(1);
8400 return NULL;
8401 }
8402
Ahmad Kholaif6c09e792015-02-26 15:26:53 +02008403 return __cfg80211_alloc_vendor_skb(rdev, wdev, approxlen, 0, 0,
Johannes Berge03ad6e2014-01-01 17:22:30 +01008404 cmd, attr, info, gfp);
8405}
8406EXPORT_SYMBOL(__cfg80211_alloc_event_skb);
8407
8408void __cfg80211_send_event_skb(struct sk_buff *skb, gfp_t gfp)
8409{
8410 struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0];
8411 void *hdr = ((void **)skb->cb)[1];
8412 struct nlattr *data = ((void **)skb->cb)[2];
8413 enum nl80211_multicast_groups mcgrp = NL80211_MCGRP_TESTMODE;
8414
Johannes Bergbd8c78e2014-07-30 14:55:26 +02008415 /* clear CB data for netlink core to own from now on */
8416 memset(skb->cb, 0, sizeof(skb->cb));
8417
Johannes Berge03ad6e2014-01-01 17:22:30 +01008418 nla_nest_end(skb, data);
8419 genlmsg_end(skb, hdr);
8420
8421 if (data->nla_type == NL80211_ATTR_VENDOR_DATA)
8422 mcgrp = NL80211_MCGRP_VENDOR;
8423
8424 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), skb, 0,
8425 mcgrp, gfp);
8426}
8427EXPORT_SYMBOL(__cfg80211_send_event_skb);
8428
Johannes Bergaff89a92009-07-01 21:26:51 +02008429#ifdef CONFIG_NL80211_TESTMODE
Johannes Bergaff89a92009-07-01 21:26:51 +02008430static int nl80211_testmode_do(struct sk_buff *skb, struct genl_info *info)
8431{
Johannes Berg4c476992010-10-04 21:36:35 +02008432 struct cfg80211_registered_device *rdev = info->user_ptr[0];
David Spinadelfc73f112013-07-31 18:04:15 +03008433 struct wireless_dev *wdev =
8434 __cfg80211_wdev_from_attrs(genl_info_net(info), info->attrs);
Johannes Bergaff89a92009-07-01 21:26:51 +02008435 int err;
8436
David Spinadelfc73f112013-07-31 18:04:15 +03008437 if (!rdev->ops->testmode_cmd)
8438 return -EOPNOTSUPP;
8439
8440 if (IS_ERR(wdev)) {
8441 err = PTR_ERR(wdev);
8442 if (err != -EINVAL)
8443 return err;
8444 wdev = NULL;
8445 } else if (wdev->wiphy != &rdev->wiphy) {
8446 return -EINVAL;
8447 }
8448
Johannes Bergaff89a92009-07-01 21:26:51 +02008449 if (!info->attrs[NL80211_ATTR_TESTDATA])
8450 return -EINVAL;
8451
Johannes Bergad7e7182013-11-13 13:37:47 +01008452 rdev->cur_cmd_info = info;
David Spinadelfc73f112013-07-31 18:04:15 +03008453 err = rdev_testmode_cmd(rdev, wdev,
Johannes Bergaff89a92009-07-01 21:26:51 +02008454 nla_data(info->attrs[NL80211_ATTR_TESTDATA]),
8455 nla_len(info->attrs[NL80211_ATTR_TESTDATA]));
Johannes Bergad7e7182013-11-13 13:37:47 +01008456 rdev->cur_cmd_info = NULL;
Johannes Bergaff89a92009-07-01 21:26:51 +02008457
Johannes Bergaff89a92009-07-01 21:26:51 +02008458 return err;
8459}
8460
Wey-Yi Guy71063f02011-05-20 09:05:54 -07008461static int nl80211_testmode_dump(struct sk_buff *skb,
8462 struct netlink_callback *cb)
8463{
Johannes Berg00918d32011-12-13 17:22:05 +01008464 struct cfg80211_registered_device *rdev;
Wey-Yi Guy71063f02011-05-20 09:05:54 -07008465 int err;
8466 long phy_idx;
8467 void *data = NULL;
8468 int data_len = 0;
8469
Johannes Berg5fe231e2013-05-08 21:45:15 +02008470 rtnl_lock();
8471
Wey-Yi Guy71063f02011-05-20 09:05:54 -07008472 if (cb->args[0]) {
8473 /*
8474 * 0 is a valid index, but not valid for args[0],
8475 * so we need to offset by 1.
8476 */
8477 phy_idx = cb->args[0] - 1;
8478 } else {
8479 err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize,
8480 nl80211_fam.attrbuf, nl80211_fam.maxattr,
8481 nl80211_policy);
8482 if (err)
Johannes Berg5fe231e2013-05-08 21:45:15 +02008483 goto out_err;
Johannes Berg00918d32011-12-13 17:22:05 +01008484
Johannes Berg2bd7e352012-06-15 14:23:16 +02008485 rdev = __cfg80211_rdev_from_attrs(sock_net(skb->sk),
8486 nl80211_fam.attrbuf);
8487 if (IS_ERR(rdev)) {
Johannes Berg5fe231e2013-05-08 21:45:15 +02008488 err = PTR_ERR(rdev);
8489 goto out_err;
Johannes Berg00918d32011-12-13 17:22:05 +01008490 }
Johannes Berg2bd7e352012-06-15 14:23:16 +02008491 phy_idx = rdev->wiphy_idx;
8492 rdev = NULL;
Johannes Berg2bd7e352012-06-15 14:23:16 +02008493
Wey-Yi Guy71063f02011-05-20 09:05:54 -07008494 if (nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA])
8495 cb->args[1] =
8496 (long)nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA];
8497 }
8498
8499 if (cb->args[1]) {
8500 data = nla_data((void *)cb->args[1]);
8501 data_len = nla_len((void *)cb->args[1]);
8502 }
8503
Johannes Berg00918d32011-12-13 17:22:05 +01008504 rdev = cfg80211_rdev_by_wiphy_idx(phy_idx);
8505 if (!rdev) {
Johannes Berg5fe231e2013-05-08 21:45:15 +02008506 err = -ENOENT;
8507 goto out_err;
Wey-Yi Guy71063f02011-05-20 09:05:54 -07008508 }
Wey-Yi Guy71063f02011-05-20 09:05:54 -07008509
Johannes Berg00918d32011-12-13 17:22:05 +01008510 if (!rdev->ops->testmode_dump) {
Wey-Yi Guy71063f02011-05-20 09:05:54 -07008511 err = -EOPNOTSUPP;
8512 goto out_err;
8513 }
8514
8515 while (1) {
Eric W. Biederman15e47302012-09-07 20:12:54 +00008516 void *hdr = nl80211hdr_put(skb, NETLINK_CB(cb->skb).portid,
Wey-Yi Guy71063f02011-05-20 09:05:54 -07008517 cb->nlh->nlmsg_seq, NLM_F_MULTI,
8518 NL80211_CMD_TESTMODE);
8519 struct nlattr *tmdata;
8520
Dan Carpentercb35fba2013-08-14 14:50:01 +03008521 if (!hdr)
8522 break;
8523
David S. Miller9360ffd2012-03-29 04:41:26 -04008524 if (nla_put_u32(skb, NL80211_ATTR_WIPHY, phy_idx)) {
Wey-Yi Guy71063f02011-05-20 09:05:54 -07008525 genlmsg_cancel(skb, hdr);
8526 break;
8527 }
8528
8529 tmdata = nla_nest_start(skb, NL80211_ATTR_TESTDATA);
8530 if (!tmdata) {
8531 genlmsg_cancel(skb, hdr);
8532 break;
8533 }
Hila Gonene35e4d22012-06-27 17:19:42 +03008534 err = rdev_testmode_dump(rdev, skb, cb, data, data_len);
Wey-Yi Guy71063f02011-05-20 09:05:54 -07008535 nla_nest_end(skb, tmdata);
8536
8537 if (err == -ENOBUFS || err == -ENOENT) {
8538 genlmsg_cancel(skb, hdr);
8539 break;
8540 } else if (err) {
8541 genlmsg_cancel(skb, hdr);
8542 goto out_err;
8543 }
8544
8545 genlmsg_end(skb, hdr);
8546 }
8547
8548 err = skb->len;
8549 /* see above */
8550 cb->args[0] = phy_idx + 1;
8551 out_err:
Johannes Berg5fe231e2013-05-08 21:45:15 +02008552 rtnl_unlock();
Wey-Yi Guy71063f02011-05-20 09:05:54 -07008553 return err;
8554}
Johannes Bergaff89a92009-07-01 21:26:51 +02008555#endif
8556
Samuel Ortizb23aa672009-07-01 21:26:54 +02008557static int nl80211_connect(struct sk_buff *skb, struct genl_info *info)
8558{
Johannes Berg4c476992010-10-04 21:36:35 +02008559 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8560 struct net_device *dev = info->user_ptr[1];
Samuel Ortizb23aa672009-07-01 21:26:54 +02008561 struct cfg80211_connect_params connect;
8562 struct wiphy *wiphy;
Johannes Bergfffd0932009-07-08 14:22:54 +02008563 struct cfg80211_cached_keys *connkeys = NULL;
Samuel Ortizb23aa672009-07-01 21:26:54 +02008564 int err;
8565
8566 memset(&connect, 0, sizeof(connect));
8567
8568 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
8569 return -EINVAL;
8570
8571 if (!info->attrs[NL80211_ATTR_SSID] ||
8572 !nla_len(info->attrs[NL80211_ATTR_SSID]))
8573 return -EINVAL;
8574
8575 if (info->attrs[NL80211_ATTR_AUTH_TYPE]) {
8576 connect.auth_type =
8577 nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]);
Jouni Malinene39e5b52012-09-30 19:29:39 +03008578 if (!nl80211_valid_auth_type(rdev, connect.auth_type,
8579 NL80211_CMD_CONNECT))
Samuel Ortizb23aa672009-07-01 21:26:54 +02008580 return -EINVAL;
8581 } else
8582 connect.auth_type = NL80211_AUTHTYPE_AUTOMATIC;
8583
8584 connect.privacy = info->attrs[NL80211_ATTR_PRIVACY];
8585
Johannes Bergc0692b82010-08-27 14:26:53 +03008586 err = nl80211_crypto_settings(rdev, info, &connect.crypto,
Johannes Berg3dc27d22009-07-02 21:36:37 +02008587 NL80211_MAX_NR_CIPHER_SUITES);
Samuel Ortizb23aa672009-07-01 21:26:54 +02008588 if (err)
8589 return err;
Samuel Ortizb23aa672009-07-01 21:26:54 +02008590
Johannes Berg074ac8d2010-09-16 14:58:22 +02008591 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02008592 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
8593 return -EOPNOTSUPP;
Samuel Ortizb23aa672009-07-01 21:26:54 +02008594
Johannes Berg79c97e92009-07-07 03:56:12 +02008595 wiphy = &rdev->wiphy;
Samuel Ortizb23aa672009-07-01 21:26:54 +02008596
Bala Shanmugam4486ea92012-03-07 17:27:12 +05308597 connect.bg_scan_period = -1;
8598 if (info->attrs[NL80211_ATTR_BG_SCAN_PERIOD] &&
8599 (wiphy->flags & WIPHY_FLAG_SUPPORTS_FW_ROAM)) {
8600 connect.bg_scan_period =
8601 nla_get_u16(info->attrs[NL80211_ATTR_BG_SCAN_PERIOD]);
8602 }
8603
Samuel Ortizb23aa672009-07-01 21:26:54 +02008604 if (info->attrs[NL80211_ATTR_MAC])
8605 connect.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen1df4a512014-01-15 00:00:47 +02008606 else if (info->attrs[NL80211_ATTR_MAC_HINT])
8607 connect.bssid_hint =
8608 nla_data(info->attrs[NL80211_ATTR_MAC_HINT]);
Samuel Ortizb23aa672009-07-01 21:26:54 +02008609 connect.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
8610 connect.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
8611
8612 if (info->attrs[NL80211_ATTR_IE]) {
8613 connect.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
8614 connect.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
8615 }
8616
Jouni Malinencee00a92013-01-15 17:15:57 +02008617 if (info->attrs[NL80211_ATTR_USE_MFP]) {
8618 connect.mfp = nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]);
8619 if (connect.mfp != NL80211_MFP_REQUIRED &&
8620 connect.mfp != NL80211_MFP_NO)
8621 return -EINVAL;
8622 } else {
8623 connect.mfp = NL80211_MFP_NO;
8624 }
8625
Jouni Malinenba6fbac2016-03-29 13:53:27 +03008626 if (info->attrs[NL80211_ATTR_PREV_BSSID])
8627 connect.prev_bssid =
8628 nla_data(info->attrs[NL80211_ATTR_PREV_BSSID]);
8629
Samuel Ortizb23aa672009-07-01 21:26:54 +02008630 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
Jouni Malinen664834d2014-01-15 00:01:44 +02008631 connect.channel = nl80211_get_valid_chan(
8632 wiphy, info->attrs[NL80211_ATTR_WIPHY_FREQ]);
8633 if (!connect.channel)
Johannes Berg4c476992010-10-04 21:36:35 +02008634 return -EINVAL;
Jouni Malinen1df4a512014-01-15 00:00:47 +02008635 } else if (info->attrs[NL80211_ATTR_WIPHY_FREQ_HINT]) {
Jouni Malinen664834d2014-01-15 00:01:44 +02008636 connect.channel_hint = nl80211_get_valid_chan(
8637 wiphy, info->attrs[NL80211_ATTR_WIPHY_FREQ_HINT]);
8638 if (!connect.channel_hint)
Jouni Malinen1df4a512014-01-15 00:00:47 +02008639 return -EINVAL;
Samuel Ortizb23aa672009-07-01 21:26:54 +02008640 }
8641
Johannes Bergfffd0932009-07-08 14:22:54 +02008642 if (connect.privacy && info->attrs[NL80211_ATTR_KEYS]) {
8643 connkeys = nl80211_parse_connkeys(rdev,
Sujith Manoharande7044e2012-10-18 10:19:28 +05308644 info->attrs[NL80211_ATTR_KEYS], NULL);
Johannes Berg4c476992010-10-04 21:36:35 +02008645 if (IS_ERR(connkeys))
8646 return PTR_ERR(connkeys);
Johannes Bergfffd0932009-07-08 14:22:54 +02008647 }
8648
Ben Greear7e7c8922011-11-18 11:31:59 -08008649 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT]))
8650 connect.flags |= ASSOC_REQ_DISABLE_HT;
8651
8652 if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
8653 memcpy(&connect.ht_capa_mask,
8654 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]),
8655 sizeof(connect.ht_capa_mask));
8656
8657 if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) {
Wei Yongjunb4e4f472012-09-02 21:41:04 +08008658 if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) {
Johannes Bergb47f6102014-09-10 13:39:54 +03008659 kzfree(connkeys);
Ben Greear7e7c8922011-11-18 11:31:59 -08008660 return -EINVAL;
Wei Yongjunb4e4f472012-09-02 21:41:04 +08008661 }
Ben Greear7e7c8922011-11-18 11:31:59 -08008662 memcpy(&connect.ht_capa,
8663 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]),
8664 sizeof(connect.ht_capa));
8665 }
8666
Johannes Bergee2aca32013-02-21 17:36:01 +01008667 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_VHT]))
8668 connect.flags |= ASSOC_REQ_DISABLE_VHT;
8669
8670 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK])
8671 memcpy(&connect.vht_capa_mask,
8672 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]),
8673 sizeof(connect.vht_capa_mask));
8674
8675 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) {
8676 if (!info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) {
Johannes Bergb47f6102014-09-10 13:39:54 +03008677 kzfree(connkeys);
Johannes Bergee2aca32013-02-21 17:36:01 +01008678 return -EINVAL;
8679 }
8680 memcpy(&connect.vht_capa,
8681 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]),
8682 sizeof(connect.vht_capa));
8683 }
8684
Assaf Kraussbab5ab72014-09-03 15:25:01 +03008685 if (nla_get_flag(info->attrs[NL80211_ATTR_USE_RRM])) {
Beni Lev0c9ca112016-02-17 20:30:00 +02008686 if (!((rdev->wiphy.features &
8687 NL80211_FEATURE_DS_PARAM_SET_IE_IN_PROBES) &&
8688 (rdev->wiphy.features & NL80211_FEATURE_QUIET)) &&
8689 !wiphy_ext_feature_isset(&rdev->wiphy,
8690 NL80211_EXT_FEATURE_RRM)) {
Ola Olsson707554b2015-12-11 21:04:52 +01008691 kzfree(connkeys);
Assaf Kraussbab5ab72014-09-03 15:25:01 +03008692 return -EINVAL;
Ola Olsson707554b2015-12-11 21:04:52 +01008693 }
Assaf Kraussbab5ab72014-09-03 15:25:01 +03008694 connect.flags |= ASSOC_REQ_USE_RRM;
8695 }
8696
Lior David34d50512016-01-28 10:58:25 +02008697 connect.pbss = nla_get_flag(info->attrs[NL80211_ATTR_PBSS]);
Johannes Berg57fbcce2016-04-12 15:56:15 +02008698 if (connect.pbss && !rdev->wiphy.bands[NL80211_BAND_60GHZ]) {
Lior David34d50512016-01-28 10:58:25 +02008699 kzfree(connkeys);
8700 return -EOPNOTSUPP;
8701 }
8702
Arend van Spriel38de03d2016-03-02 20:37:18 +01008703 if (info->attrs[NL80211_ATTR_BSS_SELECT]) {
8704 /* bss selection makes no sense if bssid is set */
8705 if (connect.bssid) {
8706 kzfree(connkeys);
8707 return -EINVAL;
8708 }
8709
8710 err = parse_bss_select(info->attrs[NL80211_ATTR_BSS_SELECT],
8711 wiphy, &connect.bss_select);
8712 if (err) {
8713 kzfree(connkeys);
8714 return err;
8715 }
8716 }
8717
Johannes Berg83739b02013-05-15 17:44:01 +02008718 wdev_lock(dev->ieee80211_ptr);
Jouni Malinen4ce2bd92016-03-29 13:53:28 +03008719 err = cfg80211_connect(rdev, dev, &connect, connkeys,
8720 connect.prev_bssid);
Johannes Berg83739b02013-05-15 17:44:01 +02008721 wdev_unlock(dev->ieee80211_ptr);
Johannes Bergfffd0932009-07-08 14:22:54 +02008722 if (err)
Johannes Bergb47f6102014-09-10 13:39:54 +03008723 kzfree(connkeys);
Samuel Ortizb23aa672009-07-01 21:26:54 +02008724 return err;
8725}
8726
8727static int nl80211_disconnect(struct sk_buff *skb, struct genl_info *info)
8728{
Johannes Berg4c476992010-10-04 21:36:35 +02008729 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8730 struct net_device *dev = info->user_ptr[1];
Samuel Ortizb23aa672009-07-01 21:26:54 +02008731 u16 reason;
Johannes Berg83739b02013-05-15 17:44:01 +02008732 int ret;
Samuel Ortizb23aa672009-07-01 21:26:54 +02008733
8734 if (!info->attrs[NL80211_ATTR_REASON_CODE])
8735 reason = WLAN_REASON_DEAUTH_LEAVING;
8736 else
8737 reason = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
8738
8739 if (reason == 0)
8740 return -EINVAL;
8741
Johannes Berg074ac8d2010-09-16 14:58:22 +02008742 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02008743 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
8744 return -EOPNOTSUPP;
Samuel Ortizb23aa672009-07-01 21:26:54 +02008745
Johannes Berg83739b02013-05-15 17:44:01 +02008746 wdev_lock(dev->ieee80211_ptr);
8747 ret = cfg80211_disconnect(rdev, dev, reason, true);
8748 wdev_unlock(dev->ieee80211_ptr);
8749 return ret;
Samuel Ortizb23aa672009-07-01 21:26:54 +02008750}
8751
Johannes Berg463d0182009-07-14 00:33:35 +02008752static int nl80211_wiphy_netns(struct sk_buff *skb, struct genl_info *info)
8753{
Johannes Berg4c476992010-10-04 21:36:35 +02008754 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg463d0182009-07-14 00:33:35 +02008755 struct net *net;
8756 int err;
Johannes Berg463d0182009-07-14 00:33:35 +02008757
Vadim Kochan4b681c82015-01-12 16:34:05 +02008758 if (info->attrs[NL80211_ATTR_PID]) {
8759 u32 pid = nla_get_u32(info->attrs[NL80211_ATTR_PID]);
8760
8761 net = get_net_ns_by_pid(pid);
8762 } else if (info->attrs[NL80211_ATTR_NETNS_FD]) {
8763 u32 fd = nla_get_u32(info->attrs[NL80211_ATTR_NETNS_FD]);
8764
8765 net = get_net_ns_by_fd(fd);
8766 } else {
Johannes Berg463d0182009-07-14 00:33:35 +02008767 return -EINVAL;
Vadim Kochan4b681c82015-01-12 16:34:05 +02008768 }
Johannes Berg463d0182009-07-14 00:33:35 +02008769
Johannes Berg4c476992010-10-04 21:36:35 +02008770 if (IS_ERR(net))
8771 return PTR_ERR(net);
Johannes Berg463d0182009-07-14 00:33:35 +02008772
8773 err = 0;
8774
8775 /* check if anything to do */
Johannes Berg4c476992010-10-04 21:36:35 +02008776 if (!net_eq(wiphy_net(&rdev->wiphy), net))
8777 err = cfg80211_switch_netns(rdev, net);
Johannes Berg463d0182009-07-14 00:33:35 +02008778
Johannes Berg463d0182009-07-14 00:33:35 +02008779 put_net(net);
Johannes Berg463d0182009-07-14 00:33:35 +02008780 return err;
8781}
8782
Samuel Ortiz67fbb162009-11-24 23:59:15 +01008783static int nl80211_setdel_pmksa(struct sk_buff *skb, struct genl_info *info)
8784{
Johannes Berg4c476992010-10-04 21:36:35 +02008785 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Samuel Ortiz67fbb162009-11-24 23:59:15 +01008786 int (*rdev_ops)(struct wiphy *wiphy, struct net_device *dev,
8787 struct cfg80211_pmksa *pmksa) = NULL;
Johannes Berg4c476992010-10-04 21:36:35 +02008788 struct net_device *dev = info->user_ptr[1];
Samuel Ortiz67fbb162009-11-24 23:59:15 +01008789 struct cfg80211_pmksa pmksa;
8790
8791 memset(&pmksa, 0, sizeof(struct cfg80211_pmksa));
8792
8793 if (!info->attrs[NL80211_ATTR_MAC])
8794 return -EINVAL;
8795
8796 if (!info->attrs[NL80211_ATTR_PMKID])
8797 return -EINVAL;
8798
Samuel Ortiz67fbb162009-11-24 23:59:15 +01008799 pmksa.pmkid = nla_data(info->attrs[NL80211_ATTR_PMKID]);
8800 pmksa.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
8801
Johannes Berg074ac8d2010-09-16 14:58:22 +02008802 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02008803 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
8804 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01008805
8806 switch (info->genlhdr->cmd) {
8807 case NL80211_CMD_SET_PMKSA:
8808 rdev_ops = rdev->ops->set_pmksa;
8809 break;
8810 case NL80211_CMD_DEL_PMKSA:
8811 rdev_ops = rdev->ops->del_pmksa;
8812 break;
8813 default:
8814 WARN_ON(1);
8815 break;
8816 }
8817
Johannes Berg4c476992010-10-04 21:36:35 +02008818 if (!rdev_ops)
8819 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01008820
Johannes Berg4c476992010-10-04 21:36:35 +02008821 return rdev_ops(&rdev->wiphy, dev, &pmksa);
Samuel Ortiz67fbb162009-11-24 23:59:15 +01008822}
8823
8824static int nl80211_flush_pmksa(struct sk_buff *skb, struct genl_info *info)
8825{
Johannes Berg4c476992010-10-04 21:36:35 +02008826 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8827 struct net_device *dev = info->user_ptr[1];
Samuel Ortiz67fbb162009-11-24 23:59:15 +01008828
Johannes Berg074ac8d2010-09-16 14:58:22 +02008829 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02008830 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
8831 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01008832
Johannes Berg4c476992010-10-04 21:36:35 +02008833 if (!rdev->ops->flush_pmksa)
8834 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01008835
Hila Gonene35e4d22012-06-27 17:19:42 +03008836 return rdev_flush_pmksa(rdev, dev);
Samuel Ortiz67fbb162009-11-24 23:59:15 +01008837}
8838
Arik Nemtsov109086c2011-09-28 14:12:50 +03008839static int nl80211_tdls_mgmt(struct sk_buff *skb, struct genl_info *info)
8840{
8841 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8842 struct net_device *dev = info->user_ptr[1];
8843 u8 action_code, dialog_token;
Sunil Dutt Undekaridf942e72014-02-20 16:22:09 +05308844 u32 peer_capability = 0;
Arik Nemtsov109086c2011-09-28 14:12:50 +03008845 u16 status_code;
8846 u8 *peer;
Arik Nemtsov31fa97c2014-06-11 17:18:21 +03008847 bool initiator;
Arik Nemtsov109086c2011-09-28 14:12:50 +03008848
8849 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) ||
8850 !rdev->ops->tdls_mgmt)
8851 return -EOPNOTSUPP;
8852
8853 if (!info->attrs[NL80211_ATTR_TDLS_ACTION] ||
8854 !info->attrs[NL80211_ATTR_STATUS_CODE] ||
8855 !info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN] ||
8856 !info->attrs[NL80211_ATTR_IE] ||
8857 !info->attrs[NL80211_ATTR_MAC])
8858 return -EINVAL;
8859
8860 peer = nla_data(info->attrs[NL80211_ATTR_MAC]);
8861 action_code = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_ACTION]);
8862 status_code = nla_get_u16(info->attrs[NL80211_ATTR_STATUS_CODE]);
8863 dialog_token = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN]);
Arik Nemtsov31fa97c2014-06-11 17:18:21 +03008864 initiator = nla_get_flag(info->attrs[NL80211_ATTR_TDLS_INITIATOR]);
Sunil Dutt Undekaridf942e72014-02-20 16:22:09 +05308865 if (info->attrs[NL80211_ATTR_TDLS_PEER_CAPABILITY])
8866 peer_capability =
8867 nla_get_u32(info->attrs[NL80211_ATTR_TDLS_PEER_CAPABILITY]);
Arik Nemtsov109086c2011-09-28 14:12:50 +03008868
Hila Gonene35e4d22012-06-27 17:19:42 +03008869 return rdev_tdls_mgmt(rdev, dev, peer, action_code,
Sunil Dutt Undekaridf942e72014-02-20 16:22:09 +05308870 dialog_token, status_code, peer_capability,
Arik Nemtsov31fa97c2014-06-11 17:18:21 +03008871 initiator,
Hila Gonene35e4d22012-06-27 17:19:42 +03008872 nla_data(info->attrs[NL80211_ATTR_IE]),
8873 nla_len(info->attrs[NL80211_ATTR_IE]));
Arik Nemtsov109086c2011-09-28 14:12:50 +03008874}
8875
8876static int nl80211_tdls_oper(struct sk_buff *skb, struct genl_info *info)
8877{
8878 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8879 struct net_device *dev = info->user_ptr[1];
8880 enum nl80211_tdls_operation operation;
8881 u8 *peer;
8882
8883 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) ||
8884 !rdev->ops->tdls_oper)
8885 return -EOPNOTSUPP;
8886
8887 if (!info->attrs[NL80211_ATTR_TDLS_OPERATION] ||
8888 !info->attrs[NL80211_ATTR_MAC])
8889 return -EINVAL;
8890
8891 operation = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_OPERATION]);
8892 peer = nla_data(info->attrs[NL80211_ATTR_MAC]);
8893
Hila Gonene35e4d22012-06-27 17:19:42 +03008894 return rdev_tdls_oper(rdev, dev, peer, operation);
Arik Nemtsov109086c2011-09-28 14:12:50 +03008895}
8896
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008897static int nl80211_remain_on_channel(struct sk_buff *skb,
8898 struct genl_info *info)
8899{
Johannes Berg4c476992010-10-04 21:36:35 +02008900 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02008901 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg683b6d32012-11-08 21:25:48 +01008902 struct cfg80211_chan_def chandef;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008903 struct sk_buff *msg;
8904 void *hdr;
8905 u64 cookie;
Johannes Berg683b6d32012-11-08 21:25:48 +01008906 u32 duration;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008907 int err;
8908
8909 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] ||
8910 !info->attrs[NL80211_ATTR_DURATION])
8911 return -EINVAL;
8912
8913 duration = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]);
8914
Johannes Berg7c4ef712011-11-18 15:33:48 +01008915 if (!rdev->ops->remain_on_channel ||
8916 !(rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL))
Johannes Berg4c476992010-10-04 21:36:35 +02008917 return -EOPNOTSUPP;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008918
Johannes Bergebf348f2012-06-01 12:50:54 +02008919 /*
8920 * We should be on that channel for at least a minimum amount of
8921 * time (10ms) but no longer than the driver supports.
8922 */
8923 if (duration < NL80211_MIN_REMAIN_ON_CHANNEL_TIME ||
8924 duration > rdev->wiphy.max_remain_on_channel_duration)
8925 return -EINVAL;
8926
Johannes Berg683b6d32012-11-08 21:25:48 +01008927 err = nl80211_parse_chandef(rdev, info, &chandef);
8928 if (err)
8929 return err;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008930
8931 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02008932 if (!msg)
8933 return -ENOMEM;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008934
Eric W. Biederman15e47302012-09-07 20:12:54 +00008935 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008936 NL80211_CMD_REMAIN_ON_CHANNEL);
Dan Carpentercb35fba2013-08-14 14:50:01 +03008937 if (!hdr) {
8938 err = -ENOBUFS;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008939 goto free_msg;
8940 }
8941
Johannes Berg683b6d32012-11-08 21:25:48 +01008942 err = rdev_remain_on_channel(rdev, wdev, chandef.chan,
8943 duration, &cookie);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008944
8945 if (err)
8946 goto free_msg;
8947
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02008948 if (nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie,
8949 NL80211_ATTR_PAD))
David S. Miller9360ffd2012-03-29 04:41:26 -04008950 goto nla_put_failure;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008951
8952 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02008953
8954 return genlmsg_reply(msg, info);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008955
8956 nla_put_failure:
8957 err = -ENOBUFS;
8958 free_msg:
8959 nlmsg_free(msg);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008960 return err;
8961}
8962
8963static int nl80211_cancel_remain_on_channel(struct sk_buff *skb,
8964 struct genl_info *info)
8965{
Johannes Berg4c476992010-10-04 21:36:35 +02008966 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02008967 struct wireless_dev *wdev = info->user_ptr[1];
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008968 u64 cookie;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008969
8970 if (!info->attrs[NL80211_ATTR_COOKIE])
8971 return -EINVAL;
8972
Johannes Berg4c476992010-10-04 21:36:35 +02008973 if (!rdev->ops->cancel_remain_on_channel)
8974 return -EOPNOTSUPP;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008975
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008976 cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]);
8977
Hila Gonene35e4d22012-06-27 17:19:42 +03008978 return rdev_cancel_remain_on_channel(rdev, wdev, cookie);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008979}
8980
Jouni Malinen13ae75b2009-12-29 12:59:45 +02008981static int nl80211_set_tx_bitrate_mask(struct sk_buff *skb,
8982 struct genl_info *info)
8983{
Jouni Malinen13ae75b2009-12-29 12:59:45 +02008984 struct cfg80211_bitrate_mask mask;
Purushottam Kushwahaa7c7fbf2016-09-14 17:38:44 +05308985 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg4c476992010-10-04 21:36:35 +02008986 struct net_device *dev = info->user_ptr[1];
Purushottam Kushwahaa7c7fbf2016-09-14 17:38:44 +05308987 int err;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02008988
Johannes Berg4c476992010-10-04 21:36:35 +02008989 if (!rdev->ops->set_bitrate_mask)
8990 return -EOPNOTSUPP;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02008991
Purushottam Kushwahaa7c7fbf2016-09-14 17:38:44 +05308992 err = nl80211_parse_tx_bitrate_mask(info, &mask);
8993 if (err)
8994 return err;
Janusz Dziedzic78693032013-12-03 09:50:44 +01008995
Hila Gonene35e4d22012-06-27 17:19:42 +03008996 return rdev_set_bitrate_mask(rdev, dev, NULL, &mask);
Jouni Malinen13ae75b2009-12-29 12:59:45 +02008997}
8998
Johannes Berg2e161f782010-08-12 15:38:38 +02008999static int nl80211_register_mgmt(struct sk_buff *skb, struct genl_info *info)
Jouni Malinen026331c2010-02-15 12:53:10 +02009000{
Johannes Berg4c476992010-10-04 21:36:35 +02009001 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02009002 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg2e161f782010-08-12 15:38:38 +02009003 u16 frame_type = IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_ACTION;
Jouni Malinen026331c2010-02-15 12:53:10 +02009004
9005 if (!info->attrs[NL80211_ATTR_FRAME_MATCH])
9006 return -EINVAL;
9007
Johannes Berg2e161f782010-08-12 15:38:38 +02009008 if (info->attrs[NL80211_ATTR_FRAME_TYPE])
9009 frame_type = nla_get_u16(info->attrs[NL80211_ATTR_FRAME_TYPE]);
Jouni Malinen026331c2010-02-15 12:53:10 +02009010
Johannes Berg71bbc992012-06-15 15:30:18 +02009011 switch (wdev->iftype) {
9012 case NL80211_IFTYPE_STATION:
9013 case NL80211_IFTYPE_ADHOC:
9014 case NL80211_IFTYPE_P2P_CLIENT:
9015 case NL80211_IFTYPE_AP:
9016 case NL80211_IFTYPE_AP_VLAN:
9017 case NL80211_IFTYPE_MESH_POINT:
9018 case NL80211_IFTYPE_P2P_GO:
Johannes Berg98104fde2012-06-16 00:19:54 +02009019 case NL80211_IFTYPE_P2P_DEVICE:
Johannes Berg71bbc992012-06-15 15:30:18 +02009020 break;
Ayala Bekercb3b7d82016-09-20 17:31:13 +03009021 case NL80211_IFTYPE_NAN:
Johannes Berg71bbc992012-06-15 15:30:18 +02009022 default:
Johannes Berg4c476992010-10-04 21:36:35 +02009023 return -EOPNOTSUPP;
Johannes Berg71bbc992012-06-15 15:30:18 +02009024 }
Jouni Malinen026331c2010-02-15 12:53:10 +02009025
9026 /* not much point in registering if we can't reply */
Johannes Berg4c476992010-10-04 21:36:35 +02009027 if (!rdev->ops->mgmt_tx)
9028 return -EOPNOTSUPP;
Jouni Malinen026331c2010-02-15 12:53:10 +02009029
Eric W. Biederman15e47302012-09-07 20:12:54 +00009030 return cfg80211_mlme_register_mgmt(wdev, info->snd_portid, frame_type,
Jouni Malinen026331c2010-02-15 12:53:10 +02009031 nla_data(info->attrs[NL80211_ATTR_FRAME_MATCH]),
9032 nla_len(info->attrs[NL80211_ATTR_FRAME_MATCH]));
Jouni Malinen026331c2010-02-15 12:53:10 +02009033}
9034
Johannes Berg2e161f782010-08-12 15:38:38 +02009035static int nl80211_tx_mgmt(struct sk_buff *skb, struct genl_info *info)
Jouni Malinen026331c2010-02-15 12:53:10 +02009036{
Johannes Berg4c476992010-10-04 21:36:35 +02009037 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02009038 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg683b6d32012-11-08 21:25:48 +01009039 struct cfg80211_chan_def chandef;
Jouni Malinen026331c2010-02-15 12:53:10 +02009040 int err;
Johannes Bergd64d3732011-11-10 09:44:46 +01009041 void *hdr = NULL;
Jouni Malinen026331c2010-02-15 12:53:10 +02009042 u64 cookie;
Johannes Berge247bd902011-11-04 11:18:21 +01009043 struct sk_buff *msg = NULL;
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02009044 struct cfg80211_mgmt_tx_params params = {
9045 .dont_wait_for_ack =
9046 info->attrs[NL80211_ATTR_DONT_WAIT_FOR_ACK],
9047 };
Jouni Malinen026331c2010-02-15 12:53:10 +02009048
Johannes Berg683b6d32012-11-08 21:25:48 +01009049 if (!info->attrs[NL80211_ATTR_FRAME])
Jouni Malinen026331c2010-02-15 12:53:10 +02009050 return -EINVAL;
9051
Johannes Berg4c476992010-10-04 21:36:35 +02009052 if (!rdev->ops->mgmt_tx)
9053 return -EOPNOTSUPP;
Jouni Malinen026331c2010-02-15 12:53:10 +02009054
Johannes Berg71bbc992012-06-15 15:30:18 +02009055 switch (wdev->iftype) {
Antonio Quartulliea141b752013-06-11 14:20:03 +02009056 case NL80211_IFTYPE_P2P_DEVICE:
9057 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ])
9058 return -EINVAL;
Johannes Berg71bbc992012-06-15 15:30:18 +02009059 case NL80211_IFTYPE_STATION:
9060 case NL80211_IFTYPE_ADHOC:
9061 case NL80211_IFTYPE_P2P_CLIENT:
9062 case NL80211_IFTYPE_AP:
9063 case NL80211_IFTYPE_AP_VLAN:
9064 case NL80211_IFTYPE_MESH_POINT:
9065 case NL80211_IFTYPE_P2P_GO:
9066 break;
Ayala Bekercb3b7d82016-09-20 17:31:13 +03009067 case NL80211_IFTYPE_NAN:
Johannes Berg71bbc992012-06-15 15:30:18 +02009068 default:
Johannes Berg4c476992010-10-04 21:36:35 +02009069 return -EOPNOTSUPP;
Johannes Berg71bbc992012-06-15 15:30:18 +02009070 }
Jouni Malinen026331c2010-02-15 12:53:10 +02009071
Johannes Bergf7ca38d2010-11-25 10:02:29 +01009072 if (info->attrs[NL80211_ATTR_DURATION]) {
Johannes Berg7c4ef712011-11-18 15:33:48 +01009073 if (!(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX))
Johannes Bergf7ca38d2010-11-25 10:02:29 +01009074 return -EINVAL;
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02009075 params.wait = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]);
Johannes Bergebf348f2012-06-01 12:50:54 +02009076
9077 /*
9078 * We should wait on the channel for at least a minimum amount
9079 * of time (10ms) but no longer than the driver supports.
9080 */
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02009081 if (params.wait < NL80211_MIN_REMAIN_ON_CHANNEL_TIME ||
9082 params.wait > rdev->wiphy.max_remain_on_channel_duration)
Johannes Bergebf348f2012-06-01 12:50:54 +02009083 return -EINVAL;
Johannes Bergf7ca38d2010-11-25 10:02:29 +01009084 }
9085
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02009086 params.offchan = info->attrs[NL80211_ATTR_OFFCHANNEL_TX_OK];
Johannes Bergf7ca38d2010-11-25 10:02:29 +01009087
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02009088 if (params.offchan && !(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX))
Johannes Berg7c4ef712011-11-18 15:33:48 +01009089 return -EINVAL;
9090
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02009091 params.no_cck = nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]);
Rajkumar Manoharane9f935e2011-09-25 14:53:30 +05309092
Antonio Quartulliea141b752013-06-11 14:20:03 +02009093 /* get the channel if any has been specified, otherwise pass NULL to
9094 * the driver. The latter will use the current one
9095 */
9096 chandef.chan = NULL;
9097 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
9098 err = nl80211_parse_chandef(rdev, info, &chandef);
9099 if (err)
9100 return err;
9101 }
9102
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02009103 if (!chandef.chan && params.offchan)
Antonio Quartulliea141b752013-06-11 14:20:03 +02009104 return -EINVAL;
Jouni Malinen026331c2010-02-15 12:53:10 +02009105
Andrei Otcheretianski34d22ce2014-05-09 14:11:44 +03009106 params.buf = nla_data(info->attrs[NL80211_ATTR_FRAME]);
9107 params.len = nla_len(info->attrs[NL80211_ATTR_FRAME]);
9108
9109 if (info->attrs[NL80211_ATTR_CSA_C_OFFSETS_TX]) {
9110 int len = nla_len(info->attrs[NL80211_ATTR_CSA_C_OFFSETS_TX]);
9111 int i;
9112
9113 if (len % sizeof(u16))
9114 return -EINVAL;
9115
9116 params.n_csa_offsets = len / sizeof(u16);
9117 params.csa_offsets =
9118 nla_data(info->attrs[NL80211_ATTR_CSA_C_OFFSETS_TX]);
9119
9120 /* check that all the offsets fit the frame */
9121 for (i = 0; i < params.n_csa_offsets; i++) {
9122 if (params.csa_offsets[i] >= params.len)
9123 return -EINVAL;
9124 }
9125 }
9126
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02009127 if (!params.dont_wait_for_ack) {
Johannes Berge247bd902011-11-04 11:18:21 +01009128 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
9129 if (!msg)
9130 return -ENOMEM;
Jouni Malinen026331c2010-02-15 12:53:10 +02009131
Eric W. Biederman15e47302012-09-07 20:12:54 +00009132 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berge247bd902011-11-04 11:18:21 +01009133 NL80211_CMD_FRAME);
Dan Carpentercb35fba2013-08-14 14:50:01 +03009134 if (!hdr) {
9135 err = -ENOBUFS;
Johannes Berge247bd902011-11-04 11:18:21 +01009136 goto free_msg;
9137 }
Jouni Malinen026331c2010-02-15 12:53:10 +02009138 }
Johannes Berge247bd902011-11-04 11:18:21 +01009139
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02009140 params.chan = chandef.chan;
9141 err = cfg80211_mlme_mgmt_tx(rdev, wdev, &params, &cookie);
Jouni Malinen026331c2010-02-15 12:53:10 +02009142 if (err)
9143 goto free_msg;
9144
Johannes Berge247bd902011-11-04 11:18:21 +01009145 if (msg) {
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02009146 if (nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie,
9147 NL80211_ATTR_PAD))
David S. Miller9360ffd2012-03-29 04:41:26 -04009148 goto nla_put_failure;
Jouni Malinen026331c2010-02-15 12:53:10 +02009149
Johannes Berge247bd902011-11-04 11:18:21 +01009150 genlmsg_end(msg, hdr);
9151 return genlmsg_reply(msg, info);
9152 }
9153
9154 return 0;
Jouni Malinen026331c2010-02-15 12:53:10 +02009155
9156 nla_put_failure:
9157 err = -ENOBUFS;
9158 free_msg:
9159 nlmsg_free(msg);
Jouni Malinen026331c2010-02-15 12:53:10 +02009160 return err;
9161}
9162
Johannes Bergf7ca38d2010-11-25 10:02:29 +01009163static int nl80211_tx_mgmt_cancel_wait(struct sk_buff *skb, struct genl_info *info)
9164{
9165 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02009166 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Bergf7ca38d2010-11-25 10:02:29 +01009167 u64 cookie;
9168
9169 if (!info->attrs[NL80211_ATTR_COOKIE])
9170 return -EINVAL;
9171
9172 if (!rdev->ops->mgmt_tx_cancel_wait)
9173 return -EOPNOTSUPP;
9174
Johannes Berg71bbc992012-06-15 15:30:18 +02009175 switch (wdev->iftype) {
9176 case NL80211_IFTYPE_STATION:
9177 case NL80211_IFTYPE_ADHOC:
9178 case NL80211_IFTYPE_P2P_CLIENT:
9179 case NL80211_IFTYPE_AP:
9180 case NL80211_IFTYPE_AP_VLAN:
9181 case NL80211_IFTYPE_P2P_GO:
Johannes Berg98104fde2012-06-16 00:19:54 +02009182 case NL80211_IFTYPE_P2P_DEVICE:
Johannes Berg71bbc992012-06-15 15:30:18 +02009183 break;
Ayala Bekercb3b7d82016-09-20 17:31:13 +03009184 case NL80211_IFTYPE_NAN:
Johannes Berg71bbc992012-06-15 15:30:18 +02009185 default:
Johannes Bergf7ca38d2010-11-25 10:02:29 +01009186 return -EOPNOTSUPP;
Johannes Berg71bbc992012-06-15 15:30:18 +02009187 }
Johannes Bergf7ca38d2010-11-25 10:02:29 +01009188
9189 cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]);
9190
Hila Gonene35e4d22012-06-27 17:19:42 +03009191 return rdev_mgmt_tx_cancel_wait(rdev, wdev, cookie);
Johannes Bergf7ca38d2010-11-25 10:02:29 +01009192}
9193
Kalle Valoffb9eb32010-02-17 17:58:10 +02009194static int nl80211_set_power_save(struct sk_buff *skb, struct genl_info *info)
9195{
Johannes Berg4c476992010-10-04 21:36:35 +02009196 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Kalle Valoffb9eb32010-02-17 17:58:10 +02009197 struct wireless_dev *wdev;
Johannes Berg4c476992010-10-04 21:36:35 +02009198 struct net_device *dev = info->user_ptr[1];
Kalle Valoffb9eb32010-02-17 17:58:10 +02009199 u8 ps_state;
9200 bool state;
9201 int err;
9202
Johannes Berg4c476992010-10-04 21:36:35 +02009203 if (!info->attrs[NL80211_ATTR_PS_STATE])
9204 return -EINVAL;
Kalle Valoffb9eb32010-02-17 17:58:10 +02009205
9206 ps_state = nla_get_u32(info->attrs[NL80211_ATTR_PS_STATE]);
9207
Johannes Berg4c476992010-10-04 21:36:35 +02009208 if (ps_state != NL80211_PS_DISABLED && ps_state != NL80211_PS_ENABLED)
9209 return -EINVAL;
Kalle Valoffb9eb32010-02-17 17:58:10 +02009210
9211 wdev = dev->ieee80211_ptr;
9212
Johannes Berg4c476992010-10-04 21:36:35 +02009213 if (!rdev->ops->set_power_mgmt)
9214 return -EOPNOTSUPP;
Kalle Valoffb9eb32010-02-17 17:58:10 +02009215
9216 state = (ps_state == NL80211_PS_ENABLED) ? true : false;
9217
9218 if (state == wdev->ps)
Johannes Berg4c476992010-10-04 21:36:35 +02009219 return 0;
Kalle Valoffb9eb32010-02-17 17:58:10 +02009220
Hila Gonene35e4d22012-06-27 17:19:42 +03009221 err = rdev_set_power_mgmt(rdev, dev, state, wdev->ps_timeout);
Johannes Berg4c476992010-10-04 21:36:35 +02009222 if (!err)
9223 wdev->ps = state;
Kalle Valoffb9eb32010-02-17 17:58:10 +02009224 return err;
9225}
9226
9227static int nl80211_get_power_save(struct sk_buff *skb, struct genl_info *info)
9228{
Johannes Berg4c476992010-10-04 21:36:35 +02009229 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Kalle Valoffb9eb32010-02-17 17:58:10 +02009230 enum nl80211_ps_state ps_state;
9231 struct wireless_dev *wdev;
Johannes Berg4c476992010-10-04 21:36:35 +02009232 struct net_device *dev = info->user_ptr[1];
Kalle Valoffb9eb32010-02-17 17:58:10 +02009233 struct sk_buff *msg;
9234 void *hdr;
9235 int err;
9236
Kalle Valoffb9eb32010-02-17 17:58:10 +02009237 wdev = dev->ieee80211_ptr;
9238
Johannes Berg4c476992010-10-04 21:36:35 +02009239 if (!rdev->ops->set_power_mgmt)
9240 return -EOPNOTSUPP;
Kalle Valoffb9eb32010-02-17 17:58:10 +02009241
9242 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02009243 if (!msg)
9244 return -ENOMEM;
Kalle Valoffb9eb32010-02-17 17:58:10 +02009245
Eric W. Biederman15e47302012-09-07 20:12:54 +00009246 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Kalle Valoffb9eb32010-02-17 17:58:10 +02009247 NL80211_CMD_GET_POWER_SAVE);
9248 if (!hdr) {
Johannes Berg4c476992010-10-04 21:36:35 +02009249 err = -ENOBUFS;
Kalle Valoffb9eb32010-02-17 17:58:10 +02009250 goto free_msg;
9251 }
9252
9253 if (wdev->ps)
9254 ps_state = NL80211_PS_ENABLED;
9255 else
9256 ps_state = NL80211_PS_DISABLED;
9257
David S. Miller9360ffd2012-03-29 04:41:26 -04009258 if (nla_put_u32(msg, NL80211_ATTR_PS_STATE, ps_state))
9259 goto nla_put_failure;
Kalle Valoffb9eb32010-02-17 17:58:10 +02009260
9261 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02009262 return genlmsg_reply(msg, info);
Kalle Valoffb9eb32010-02-17 17:58:10 +02009263
Johannes Berg4c476992010-10-04 21:36:35 +02009264 nla_put_failure:
Kalle Valoffb9eb32010-02-17 17:58:10 +02009265 err = -ENOBUFS;
Johannes Berg4c476992010-10-04 21:36:35 +02009266 free_msg:
Kalle Valoffb9eb32010-02-17 17:58:10 +02009267 nlmsg_free(msg);
Kalle Valoffb9eb32010-02-17 17:58:10 +02009268 return err;
9269}
9270
Johannes Berg94e860f2014-01-20 23:58:15 +01009271static const struct nla_policy
9272nl80211_attr_cqm_policy[NL80211_ATTR_CQM_MAX + 1] = {
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02009273 [NL80211_ATTR_CQM_RSSI_THOLD] = { .type = NLA_U32 },
9274 [NL80211_ATTR_CQM_RSSI_HYST] = { .type = NLA_U32 },
9275 [NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT] = { .type = NLA_U32 },
Thomas Pedersen84f10702012-07-12 16:17:33 -07009276 [NL80211_ATTR_CQM_TXE_RATE] = { .type = NLA_U32 },
9277 [NL80211_ATTR_CQM_TXE_PKTS] = { .type = NLA_U32 },
9278 [NL80211_ATTR_CQM_TXE_INTVL] = { .type = NLA_U32 },
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02009279};
9280
Thomas Pedersen84f10702012-07-12 16:17:33 -07009281static int nl80211_set_cqm_txe(struct genl_info *info,
Johannes Bergd9d8b012012-11-26 12:51:52 +01009282 u32 rate, u32 pkts, u32 intvl)
Thomas Pedersen84f10702012-07-12 16:17:33 -07009283{
9284 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Thomas Pedersen84f10702012-07-12 16:17:33 -07009285 struct net_device *dev = info->user_ptr[1];
Johannes Berg1da5fcc2013-08-06 14:10:48 +02009286 struct wireless_dev *wdev = dev->ieee80211_ptr;
Thomas Pedersen84f10702012-07-12 16:17:33 -07009287
Johannes Bergd9d8b012012-11-26 12:51:52 +01009288 if (rate > 100 || intvl > NL80211_CQM_TXE_MAX_INTVL)
Thomas Pedersen84f10702012-07-12 16:17:33 -07009289 return -EINVAL;
9290
Thomas Pedersen84f10702012-07-12 16:17:33 -07009291 if (!rdev->ops->set_cqm_txe_config)
9292 return -EOPNOTSUPP;
9293
9294 if (wdev->iftype != NL80211_IFTYPE_STATION &&
9295 wdev->iftype != NL80211_IFTYPE_P2P_CLIENT)
9296 return -EOPNOTSUPP;
9297
Hila Gonene35e4d22012-06-27 17:19:42 +03009298 return rdev_set_cqm_txe_config(rdev, dev, rate, pkts, intvl);
Thomas Pedersen84f10702012-07-12 16:17:33 -07009299}
9300
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02009301static int nl80211_set_cqm_rssi(struct genl_info *info,
9302 s32 threshold, u32 hysteresis)
9303{
Johannes Berg4c476992010-10-04 21:36:35 +02009304 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg4c476992010-10-04 21:36:35 +02009305 struct net_device *dev = info->user_ptr[1];
Johannes Berg1da5fcc2013-08-06 14:10:48 +02009306 struct wireless_dev *wdev = dev->ieee80211_ptr;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02009307
9308 if (threshold > 0)
9309 return -EINVAL;
9310
Johannes Berg1da5fcc2013-08-06 14:10:48 +02009311 /* disabling - hysteresis should also be zero then */
9312 if (threshold == 0)
9313 hysteresis = 0;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02009314
Johannes Berg4c476992010-10-04 21:36:35 +02009315 if (!rdev->ops->set_cqm_rssi_config)
9316 return -EOPNOTSUPP;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02009317
Johannes Berg074ac8d2010-09-16 14:58:22 +02009318 if (wdev->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02009319 wdev->iftype != NL80211_IFTYPE_P2P_CLIENT)
9320 return -EOPNOTSUPP;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02009321
Hila Gonene35e4d22012-06-27 17:19:42 +03009322 return rdev_set_cqm_rssi_config(rdev, dev, threshold, hysteresis);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02009323}
9324
9325static int nl80211_set_cqm(struct sk_buff *skb, struct genl_info *info)
9326{
9327 struct nlattr *attrs[NL80211_ATTR_CQM_MAX + 1];
9328 struct nlattr *cqm;
9329 int err;
9330
9331 cqm = info->attrs[NL80211_ATTR_CQM];
Johannes Berg1da5fcc2013-08-06 14:10:48 +02009332 if (!cqm)
9333 return -EINVAL;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02009334
9335 err = nla_parse_nested(attrs, NL80211_ATTR_CQM_MAX, cqm,
9336 nl80211_attr_cqm_policy);
9337 if (err)
Johannes Berg1da5fcc2013-08-06 14:10:48 +02009338 return err;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02009339
9340 if (attrs[NL80211_ATTR_CQM_RSSI_THOLD] &&
9341 attrs[NL80211_ATTR_CQM_RSSI_HYST]) {
Johannes Berg1da5fcc2013-08-06 14:10:48 +02009342 s32 threshold = nla_get_s32(attrs[NL80211_ATTR_CQM_RSSI_THOLD]);
9343 u32 hysteresis = nla_get_u32(attrs[NL80211_ATTR_CQM_RSSI_HYST]);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02009344
Johannes Berg1da5fcc2013-08-06 14:10:48 +02009345 return nl80211_set_cqm_rssi(info, threshold, hysteresis);
9346 }
9347
9348 if (attrs[NL80211_ATTR_CQM_TXE_RATE] &&
9349 attrs[NL80211_ATTR_CQM_TXE_PKTS] &&
9350 attrs[NL80211_ATTR_CQM_TXE_INTVL]) {
9351 u32 rate = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_RATE]);
9352 u32 pkts = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_PKTS]);
9353 u32 intvl = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_INTVL]);
9354
9355 return nl80211_set_cqm_txe(info, rate, pkts, intvl);
9356 }
9357
9358 return -EINVAL;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02009359}
9360
Rostislav Lisovy6e0bd6c2014-11-03 10:33:18 +01009361static int nl80211_join_ocb(struct sk_buff *skb, struct genl_info *info)
9362{
9363 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9364 struct net_device *dev = info->user_ptr[1];
9365 struct ocb_setup setup = {};
9366 int err;
9367
9368 err = nl80211_parse_chandef(rdev, info, &setup.chandef);
9369 if (err)
9370 return err;
9371
9372 return cfg80211_join_ocb(rdev, dev, &setup);
9373}
9374
9375static int nl80211_leave_ocb(struct sk_buff *skb, struct genl_info *info)
9376{
9377 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9378 struct net_device *dev = info->user_ptr[1];
9379
9380 return cfg80211_leave_ocb(rdev, dev);
9381}
9382
Johannes Berg29cbe682010-12-03 09:20:44 +01009383static int nl80211_join_mesh(struct sk_buff *skb, struct genl_info *info)
9384{
9385 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9386 struct net_device *dev = info->user_ptr[1];
9387 struct mesh_config cfg;
Javier Cardonac80d5452010-12-16 17:37:49 -08009388 struct mesh_setup setup;
Johannes Berg29cbe682010-12-03 09:20:44 +01009389 int err;
9390
9391 /* start with default */
9392 memcpy(&cfg, &default_mesh_config, sizeof(cfg));
Javier Cardonac80d5452010-12-16 17:37:49 -08009393 memcpy(&setup, &default_mesh_setup, sizeof(setup));
Johannes Berg29cbe682010-12-03 09:20:44 +01009394
Javier Cardona24bdd9f2010-12-16 17:37:48 -08009395 if (info->attrs[NL80211_ATTR_MESH_CONFIG]) {
Johannes Berg29cbe682010-12-03 09:20:44 +01009396 /* and parse parameters if given */
Javier Cardona24bdd9f2010-12-16 17:37:48 -08009397 err = nl80211_parse_mesh_config(info, &cfg, NULL);
Johannes Berg29cbe682010-12-03 09:20:44 +01009398 if (err)
9399 return err;
9400 }
9401
9402 if (!info->attrs[NL80211_ATTR_MESH_ID] ||
9403 !nla_len(info->attrs[NL80211_ATTR_MESH_ID]))
9404 return -EINVAL;
9405
Javier Cardonac80d5452010-12-16 17:37:49 -08009406 setup.mesh_id = nla_data(info->attrs[NL80211_ATTR_MESH_ID]);
9407 setup.mesh_id_len = nla_len(info->attrs[NL80211_ATTR_MESH_ID]);
9408
Chun-Yeow Yeoh4bb62342011-11-24 17:15:20 -08009409 if (info->attrs[NL80211_ATTR_MCAST_RATE] &&
9410 !nl80211_parse_mcast_rate(rdev, setup.mcast_rate,
9411 nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE])))
9412 return -EINVAL;
9413
Marco Porsch9bdbf042013-01-07 16:04:51 +01009414 if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) {
9415 setup.beacon_interval =
9416 nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]);
Purushottam Kushwaha12d20fc92016-08-11 15:14:02 +05309417
9418 err = cfg80211_validate_beacon_int(rdev, setup.beacon_interval);
9419 if (err)
9420 return err;
Marco Porsch9bdbf042013-01-07 16:04:51 +01009421 }
9422
9423 if (info->attrs[NL80211_ATTR_DTIM_PERIOD]) {
9424 setup.dtim_period =
9425 nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]);
9426 if (setup.dtim_period < 1 || setup.dtim_period > 100)
9427 return -EINVAL;
9428 }
9429
Javier Cardonac80d5452010-12-16 17:37:49 -08009430 if (info->attrs[NL80211_ATTR_MESH_SETUP]) {
9431 /* parse additional setup parameters if given */
9432 err = nl80211_parse_mesh_setup(info, &setup);
9433 if (err)
9434 return err;
9435 }
9436
Thomas Pedersend37bb182013-03-04 13:06:13 -08009437 if (setup.user_mpm)
9438 cfg.auto_open_plinks = false;
9439
Johannes Bergcc1d2802012-05-16 23:50:20 +02009440 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
Johannes Berg683b6d32012-11-08 21:25:48 +01009441 err = nl80211_parse_chandef(rdev, info, &setup.chandef);
9442 if (err)
9443 return err;
Johannes Bergcc1d2802012-05-16 23:50:20 +02009444 } else {
9445 /* cfg80211_join_mesh() will sort it out */
Johannes Berg683b6d32012-11-08 21:25:48 +01009446 setup.chandef.chan = NULL;
Johannes Bergcc1d2802012-05-16 23:50:20 +02009447 }
9448
Ashok Nagarajanffb3cf32013-06-03 10:33:36 -07009449 if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) {
9450 u8 *rates = nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
9451 int n_rates =
9452 nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
9453 struct ieee80211_supported_band *sband;
9454
9455 if (!setup.chandef.chan)
9456 return -EINVAL;
9457
9458 sband = rdev->wiphy.bands[setup.chandef.chan->band];
9459
9460 err = ieee80211_get_ratemask(sband, rates, n_rates,
9461 &setup.basic_rates);
9462 if (err)
9463 return err;
9464 }
9465
Johannes Berg8564e382016-09-19 09:44:44 +02009466 if (info->attrs[NL80211_ATTR_TX_RATES]) {
9467 err = nl80211_parse_tx_bitrate_mask(info, &setup.beacon_rate);
9468 if (err)
9469 return err;
9470
9471 err = validate_beacon_tx_rate(rdev, setup.chandef.chan->band,
9472 &setup.beacon_rate);
9473 if (err)
9474 return err;
9475 }
9476
Javier Cardonac80d5452010-12-16 17:37:49 -08009477 return cfg80211_join_mesh(rdev, dev, &setup, &cfg);
Johannes Berg29cbe682010-12-03 09:20:44 +01009478}
9479
9480static int nl80211_leave_mesh(struct sk_buff *skb, struct genl_info *info)
9481{
9482 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9483 struct net_device *dev = info->user_ptr[1];
9484
9485 return cfg80211_leave_mesh(rdev, dev);
9486}
9487
Johannes Bergdfb89c52012-06-27 09:23:48 +02009488#ifdef CONFIG_PM
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08009489static int nl80211_send_wowlan_patterns(struct sk_buff *msg,
9490 struct cfg80211_registered_device *rdev)
9491{
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009492 struct cfg80211_wowlan *wowlan = rdev->wiphy.wowlan_config;
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08009493 struct nlattr *nl_pats, *nl_pat;
9494 int i, pat_len;
9495
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009496 if (!wowlan->n_patterns)
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08009497 return 0;
9498
9499 nl_pats = nla_nest_start(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN);
9500 if (!nl_pats)
9501 return -ENOBUFS;
9502
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009503 for (i = 0; i < wowlan->n_patterns; i++) {
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08009504 nl_pat = nla_nest_start(msg, i + 1);
9505 if (!nl_pat)
9506 return -ENOBUFS;
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009507 pat_len = wowlan->patterns[i].pattern_len;
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07009508 if (nla_put(msg, NL80211_PKTPAT_MASK, DIV_ROUND_UP(pat_len, 8),
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009509 wowlan->patterns[i].mask) ||
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07009510 nla_put(msg, NL80211_PKTPAT_PATTERN, pat_len,
9511 wowlan->patterns[i].pattern) ||
9512 nla_put_u32(msg, NL80211_PKTPAT_OFFSET,
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009513 wowlan->patterns[i].pkt_offset))
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08009514 return -ENOBUFS;
9515 nla_nest_end(msg, nl_pat);
9516 }
9517 nla_nest_end(msg, nl_pats);
9518
9519 return 0;
9520}
9521
Johannes Berg2a0e0472013-01-23 22:57:40 +01009522static int nl80211_send_wowlan_tcp(struct sk_buff *msg,
9523 struct cfg80211_wowlan_tcp *tcp)
9524{
9525 struct nlattr *nl_tcp;
9526
9527 if (!tcp)
9528 return 0;
9529
9530 nl_tcp = nla_nest_start(msg, NL80211_WOWLAN_TRIG_TCP_CONNECTION);
9531 if (!nl_tcp)
9532 return -ENOBUFS;
9533
Jiri Benc930345e2015-03-29 16:59:25 +02009534 if (nla_put_in_addr(msg, NL80211_WOWLAN_TCP_SRC_IPV4, tcp->src) ||
9535 nla_put_in_addr(msg, NL80211_WOWLAN_TCP_DST_IPV4, tcp->dst) ||
Johannes Berg2a0e0472013-01-23 22:57:40 +01009536 nla_put(msg, NL80211_WOWLAN_TCP_DST_MAC, ETH_ALEN, tcp->dst_mac) ||
9537 nla_put_u16(msg, NL80211_WOWLAN_TCP_SRC_PORT, tcp->src_port) ||
9538 nla_put_u16(msg, NL80211_WOWLAN_TCP_DST_PORT, tcp->dst_port) ||
9539 nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD,
9540 tcp->payload_len, tcp->payload) ||
9541 nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_INTERVAL,
9542 tcp->data_interval) ||
9543 nla_put(msg, NL80211_WOWLAN_TCP_WAKE_PAYLOAD,
9544 tcp->wake_len, tcp->wake_data) ||
9545 nla_put(msg, NL80211_WOWLAN_TCP_WAKE_MASK,
9546 DIV_ROUND_UP(tcp->wake_len, 8), tcp->wake_mask))
9547 return -ENOBUFS;
9548
9549 if (tcp->payload_seq.len &&
9550 nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ,
9551 sizeof(tcp->payload_seq), &tcp->payload_seq))
9552 return -ENOBUFS;
9553
9554 if (tcp->payload_tok.len &&
9555 nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN,
9556 sizeof(tcp->payload_tok) + tcp->tokens_size,
9557 &tcp->payload_tok))
9558 return -ENOBUFS;
9559
Johannes Berge248ad32013-05-16 10:24:28 +02009560 nla_nest_end(msg, nl_tcp);
9561
Johannes Berg2a0e0472013-01-23 22:57:40 +01009562 return 0;
9563}
9564
Luciano Coelho75453cc2015-01-09 14:06:37 +02009565static int nl80211_send_wowlan_nd(struct sk_buff *msg,
9566 struct cfg80211_sched_scan_request *req)
9567{
Avraham Stern3b06d272015-10-12 09:51:34 +03009568 struct nlattr *nd, *freqs, *matches, *match, *scan_plans, *scan_plan;
Luciano Coelho75453cc2015-01-09 14:06:37 +02009569 int i;
9570
9571 if (!req)
9572 return 0;
9573
9574 nd = nla_nest_start(msg, NL80211_WOWLAN_TRIG_NET_DETECT);
9575 if (!nd)
9576 return -ENOBUFS;
9577
Avraham Stern3b06d272015-10-12 09:51:34 +03009578 if (req->n_scan_plans == 1 &&
9579 nla_put_u32(msg, NL80211_ATTR_SCHED_SCAN_INTERVAL,
9580 req->scan_plans[0].interval * 1000))
Luciano Coelho75453cc2015-01-09 14:06:37 +02009581 return -ENOBUFS;
9582
Luciano Coelho21fea562015-03-17 16:36:01 +02009583 if (nla_put_u32(msg, NL80211_ATTR_SCHED_SCAN_DELAY, req->delay))
9584 return -ENOBUFS;
9585
Luciano Coelho75453cc2015-01-09 14:06:37 +02009586 freqs = nla_nest_start(msg, NL80211_ATTR_SCAN_FREQUENCIES);
9587 if (!freqs)
9588 return -ENOBUFS;
9589
Johannes Berg53b18982016-09-14 09:59:21 +02009590 for (i = 0; i < req->n_channels; i++) {
9591 if (nla_put_u32(msg, i, req->channels[i]->center_freq))
9592 return -ENOBUFS;
9593 }
Luciano Coelho75453cc2015-01-09 14:06:37 +02009594
9595 nla_nest_end(msg, freqs);
9596
9597 if (req->n_match_sets) {
9598 matches = nla_nest_start(msg, NL80211_ATTR_SCHED_SCAN_MATCH);
Johannes Berg76e1fb42016-09-14 09:55:57 +02009599 if (!matches)
9600 return -ENOBUFS;
9601
Luciano Coelho75453cc2015-01-09 14:06:37 +02009602 for (i = 0; i < req->n_match_sets; i++) {
9603 match = nla_nest_start(msg, i);
Johannes Berg76e1fb42016-09-14 09:55:57 +02009604 if (!match)
9605 return -ENOBUFS;
9606
Johannes Berg53b18982016-09-14 09:59:21 +02009607 if (nla_put(msg, NL80211_SCHED_SCAN_MATCH_ATTR_SSID,
9608 req->match_sets[i].ssid.ssid_len,
9609 req->match_sets[i].ssid.ssid))
9610 return -ENOBUFS;
Luciano Coelho75453cc2015-01-09 14:06:37 +02009611 nla_nest_end(msg, match);
9612 }
9613 nla_nest_end(msg, matches);
9614 }
9615
Avraham Stern3b06d272015-10-12 09:51:34 +03009616 scan_plans = nla_nest_start(msg, NL80211_ATTR_SCHED_SCAN_PLANS);
9617 if (!scan_plans)
9618 return -ENOBUFS;
9619
9620 for (i = 0; i < req->n_scan_plans; i++) {
9621 scan_plan = nla_nest_start(msg, i + 1);
Johannes Berg76e1fb42016-09-14 09:55:57 +02009622 if (!scan_plan)
9623 return -ENOBUFS;
9624
Avraham Stern3b06d272015-10-12 09:51:34 +03009625 if (!scan_plan ||
9626 nla_put_u32(msg, NL80211_SCHED_SCAN_PLAN_INTERVAL,
9627 req->scan_plans[i].interval) ||
9628 (req->scan_plans[i].iterations &&
9629 nla_put_u32(msg, NL80211_SCHED_SCAN_PLAN_ITERATIONS,
9630 req->scan_plans[i].iterations)))
9631 return -ENOBUFS;
9632 nla_nest_end(msg, scan_plan);
9633 }
9634 nla_nest_end(msg, scan_plans);
9635
Luciano Coelho75453cc2015-01-09 14:06:37 +02009636 nla_nest_end(msg, nd);
9637
9638 return 0;
9639}
9640
Johannes Bergff1b6e62011-05-04 15:37:28 +02009641static int nl80211_get_wowlan(struct sk_buff *skb, struct genl_info *info)
9642{
9643 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9644 struct sk_buff *msg;
9645 void *hdr;
Johannes Berg2a0e0472013-01-23 22:57:40 +01009646 u32 size = NLMSG_DEFAULT_SIZE;
Johannes Bergff1b6e62011-05-04 15:37:28 +02009647
Johannes Berg964dc9e2013-06-03 17:25:34 +02009648 if (!rdev->wiphy.wowlan)
Johannes Bergff1b6e62011-05-04 15:37:28 +02009649 return -EOPNOTSUPP;
9650
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009651 if (rdev->wiphy.wowlan_config && rdev->wiphy.wowlan_config->tcp) {
Johannes Berg2a0e0472013-01-23 22:57:40 +01009652 /* adjust size to have room for all the data */
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009653 size += rdev->wiphy.wowlan_config->tcp->tokens_size +
9654 rdev->wiphy.wowlan_config->tcp->payload_len +
9655 rdev->wiphy.wowlan_config->tcp->wake_len +
9656 rdev->wiphy.wowlan_config->tcp->wake_len / 8;
Johannes Berg2a0e0472013-01-23 22:57:40 +01009657 }
9658
9659 msg = nlmsg_new(size, GFP_KERNEL);
Johannes Bergff1b6e62011-05-04 15:37:28 +02009660 if (!msg)
9661 return -ENOMEM;
9662
Eric W. Biederman15e47302012-09-07 20:12:54 +00009663 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Johannes Bergff1b6e62011-05-04 15:37:28 +02009664 NL80211_CMD_GET_WOWLAN);
9665 if (!hdr)
9666 goto nla_put_failure;
9667
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009668 if (rdev->wiphy.wowlan_config) {
Johannes Bergff1b6e62011-05-04 15:37:28 +02009669 struct nlattr *nl_wowlan;
9670
9671 nl_wowlan = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS);
9672 if (!nl_wowlan)
9673 goto nla_put_failure;
9674
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009675 if ((rdev->wiphy.wowlan_config->any &&
David S. Miller9360ffd2012-03-29 04:41:26 -04009676 nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009677 (rdev->wiphy.wowlan_config->disconnect &&
David S. Miller9360ffd2012-03-29 04:41:26 -04009678 nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009679 (rdev->wiphy.wowlan_config->magic_pkt &&
David S. Miller9360ffd2012-03-29 04:41:26 -04009680 nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009681 (rdev->wiphy.wowlan_config->gtk_rekey_failure &&
David S. Miller9360ffd2012-03-29 04:41:26 -04009682 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009683 (rdev->wiphy.wowlan_config->eap_identity_req &&
David S. Miller9360ffd2012-03-29 04:41:26 -04009684 nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009685 (rdev->wiphy.wowlan_config->four_way_handshake &&
David S. Miller9360ffd2012-03-29 04:41:26 -04009686 nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009687 (rdev->wiphy.wowlan_config->rfkill_release &&
David S. Miller9360ffd2012-03-29 04:41:26 -04009688 nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE)))
9689 goto nla_put_failure;
Johannes Berg2a0e0472013-01-23 22:57:40 +01009690
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08009691 if (nl80211_send_wowlan_patterns(msg, rdev))
9692 goto nla_put_failure;
Johannes Berg2a0e0472013-01-23 22:57:40 +01009693
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009694 if (nl80211_send_wowlan_tcp(msg,
9695 rdev->wiphy.wowlan_config->tcp))
Johannes Berg2a0e0472013-01-23 22:57:40 +01009696 goto nla_put_failure;
9697
Luciano Coelho75453cc2015-01-09 14:06:37 +02009698 if (nl80211_send_wowlan_nd(
9699 msg,
9700 rdev->wiphy.wowlan_config->nd_config))
9701 goto nla_put_failure;
9702
Johannes Bergff1b6e62011-05-04 15:37:28 +02009703 nla_nest_end(msg, nl_wowlan);
9704 }
9705
9706 genlmsg_end(msg, hdr);
9707 return genlmsg_reply(msg, info);
9708
9709nla_put_failure:
9710 nlmsg_free(msg);
9711 return -ENOBUFS;
9712}
9713
Johannes Berg2a0e0472013-01-23 22:57:40 +01009714static int nl80211_parse_wowlan_tcp(struct cfg80211_registered_device *rdev,
9715 struct nlattr *attr,
9716 struct cfg80211_wowlan *trig)
9717{
9718 struct nlattr *tb[NUM_NL80211_WOWLAN_TCP];
9719 struct cfg80211_wowlan_tcp *cfg;
9720 struct nl80211_wowlan_tcp_data_token *tok = NULL;
9721 struct nl80211_wowlan_tcp_data_seq *seq = NULL;
9722 u32 size;
9723 u32 data_size, wake_size, tokens_size = 0, wake_mask_size;
9724 int err, port;
9725
Johannes Berg964dc9e2013-06-03 17:25:34 +02009726 if (!rdev->wiphy.wowlan->tcp)
Johannes Berg2a0e0472013-01-23 22:57:40 +01009727 return -EINVAL;
9728
9729 err = nla_parse(tb, MAX_NL80211_WOWLAN_TCP,
9730 nla_data(attr), nla_len(attr),
9731 nl80211_wowlan_tcp_policy);
9732 if (err)
9733 return err;
9734
9735 if (!tb[NL80211_WOWLAN_TCP_SRC_IPV4] ||
9736 !tb[NL80211_WOWLAN_TCP_DST_IPV4] ||
9737 !tb[NL80211_WOWLAN_TCP_DST_MAC] ||
9738 !tb[NL80211_WOWLAN_TCP_DST_PORT] ||
9739 !tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD] ||
9740 !tb[NL80211_WOWLAN_TCP_DATA_INTERVAL] ||
9741 !tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD] ||
9742 !tb[NL80211_WOWLAN_TCP_WAKE_MASK])
9743 return -EINVAL;
9744
9745 data_size = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]);
Johannes Berg964dc9e2013-06-03 17:25:34 +02009746 if (data_size > rdev->wiphy.wowlan->tcp->data_payload_max)
Johannes Berg2a0e0472013-01-23 22:57:40 +01009747 return -EINVAL;
9748
9749 if (nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]) >
Johannes Berg964dc9e2013-06-03 17:25:34 +02009750 rdev->wiphy.wowlan->tcp->data_interval_max ||
Johannes Berg723d5682013-02-26 13:56:40 +01009751 nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]) == 0)
Johannes Berg2a0e0472013-01-23 22:57:40 +01009752 return -EINVAL;
9753
9754 wake_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]);
Johannes Berg964dc9e2013-06-03 17:25:34 +02009755 if (wake_size > rdev->wiphy.wowlan->tcp->wake_payload_max)
Johannes Berg2a0e0472013-01-23 22:57:40 +01009756 return -EINVAL;
9757
9758 wake_mask_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_MASK]);
9759 if (wake_mask_size != DIV_ROUND_UP(wake_size, 8))
9760 return -EINVAL;
9761
9762 if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]) {
9763 u32 tokln = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]);
9764
9765 tok = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]);
9766 tokens_size = tokln - sizeof(*tok);
9767
9768 if (!tok->len || tokens_size % tok->len)
9769 return -EINVAL;
Johannes Berg964dc9e2013-06-03 17:25:34 +02009770 if (!rdev->wiphy.wowlan->tcp->tok)
Johannes Berg2a0e0472013-01-23 22:57:40 +01009771 return -EINVAL;
Johannes Berg964dc9e2013-06-03 17:25:34 +02009772 if (tok->len > rdev->wiphy.wowlan->tcp->tok->max_len)
Johannes Berg2a0e0472013-01-23 22:57:40 +01009773 return -EINVAL;
Johannes Berg964dc9e2013-06-03 17:25:34 +02009774 if (tok->len < rdev->wiphy.wowlan->tcp->tok->min_len)
Johannes Berg2a0e0472013-01-23 22:57:40 +01009775 return -EINVAL;
Johannes Berg964dc9e2013-06-03 17:25:34 +02009776 if (tokens_size > rdev->wiphy.wowlan->tcp->tok->bufsize)
Johannes Berg2a0e0472013-01-23 22:57:40 +01009777 return -EINVAL;
9778 if (tok->offset + tok->len > data_size)
9779 return -EINVAL;
9780 }
9781
9782 if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]) {
9783 seq = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]);
Johannes Berg964dc9e2013-06-03 17:25:34 +02009784 if (!rdev->wiphy.wowlan->tcp->seq)
Johannes Berg2a0e0472013-01-23 22:57:40 +01009785 return -EINVAL;
9786 if (seq->len == 0 || seq->len > 4)
9787 return -EINVAL;
9788 if (seq->len + seq->offset > data_size)
9789 return -EINVAL;
9790 }
9791
9792 size = sizeof(*cfg);
9793 size += data_size;
9794 size += wake_size + wake_mask_size;
9795 size += tokens_size;
9796
9797 cfg = kzalloc(size, GFP_KERNEL);
9798 if (!cfg)
9799 return -ENOMEM;
Jiri Benc67b61f62015-03-29 16:59:26 +02009800 cfg->src = nla_get_in_addr(tb[NL80211_WOWLAN_TCP_SRC_IPV4]);
9801 cfg->dst = nla_get_in_addr(tb[NL80211_WOWLAN_TCP_DST_IPV4]);
Johannes Berg2a0e0472013-01-23 22:57:40 +01009802 memcpy(cfg->dst_mac, nla_data(tb[NL80211_WOWLAN_TCP_DST_MAC]),
9803 ETH_ALEN);
9804 if (tb[NL80211_WOWLAN_TCP_SRC_PORT])
9805 port = nla_get_u16(tb[NL80211_WOWLAN_TCP_SRC_PORT]);
9806 else
9807 port = 0;
9808#ifdef CONFIG_INET
9809 /* allocate a socket and port for it and use it */
9810 err = __sock_create(wiphy_net(&rdev->wiphy), PF_INET, SOCK_STREAM,
9811 IPPROTO_TCP, &cfg->sock, 1);
9812 if (err) {
9813 kfree(cfg);
9814 return err;
9815 }
9816 if (inet_csk_get_port(cfg->sock->sk, port)) {
9817 sock_release(cfg->sock);
9818 kfree(cfg);
9819 return -EADDRINUSE;
9820 }
9821 cfg->src_port = inet_sk(cfg->sock->sk)->inet_num;
9822#else
9823 if (!port) {
9824 kfree(cfg);
9825 return -EINVAL;
9826 }
9827 cfg->src_port = port;
9828#endif
9829
9830 cfg->dst_port = nla_get_u16(tb[NL80211_WOWLAN_TCP_DST_PORT]);
9831 cfg->payload_len = data_size;
9832 cfg->payload = (u8 *)cfg + sizeof(*cfg) + tokens_size;
9833 memcpy((void *)cfg->payload,
9834 nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]),
9835 data_size);
9836 if (seq)
9837 cfg->payload_seq = *seq;
9838 cfg->data_interval = nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]);
9839 cfg->wake_len = wake_size;
9840 cfg->wake_data = (u8 *)cfg + sizeof(*cfg) + tokens_size + data_size;
9841 memcpy((void *)cfg->wake_data,
9842 nla_data(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]),
9843 wake_size);
9844 cfg->wake_mask = (u8 *)cfg + sizeof(*cfg) + tokens_size +
9845 data_size + wake_size;
9846 memcpy((void *)cfg->wake_mask,
9847 nla_data(tb[NL80211_WOWLAN_TCP_WAKE_MASK]),
9848 wake_mask_size);
9849 if (tok) {
9850 cfg->tokens_size = tokens_size;
9851 memcpy(&cfg->payload_tok, tok, sizeof(*tok) + tokens_size);
9852 }
9853
9854 trig->tcp = cfg;
9855
9856 return 0;
9857}
9858
Luciano Coelho8cd4d452014-09-17 11:55:28 +03009859static int nl80211_parse_wowlan_nd(struct cfg80211_registered_device *rdev,
9860 const struct wiphy_wowlan_support *wowlan,
9861 struct nlattr *attr,
9862 struct cfg80211_wowlan *trig)
9863{
9864 struct nlattr **tb;
9865 int err;
9866
9867 tb = kzalloc(NUM_NL80211_ATTR * sizeof(*tb), GFP_KERNEL);
9868 if (!tb)
9869 return -ENOMEM;
9870
9871 if (!(wowlan->flags & WIPHY_WOWLAN_NET_DETECT)) {
9872 err = -EOPNOTSUPP;
9873 goto out;
9874 }
9875
9876 err = nla_parse(tb, NL80211_ATTR_MAX,
9877 nla_data(attr), nla_len(attr),
9878 nl80211_policy);
9879 if (err)
9880 goto out;
9881
Johannes Bergad2b26a2014-06-12 21:39:05 +02009882 trig->nd_config = nl80211_parse_sched_scan(&rdev->wiphy, NULL, tb);
Luciano Coelho8cd4d452014-09-17 11:55:28 +03009883 err = PTR_ERR_OR_ZERO(trig->nd_config);
9884 if (err)
9885 trig->nd_config = NULL;
9886
9887out:
9888 kfree(tb);
9889 return err;
9890}
9891
Johannes Bergff1b6e62011-05-04 15:37:28 +02009892static int nl80211_set_wowlan(struct sk_buff *skb, struct genl_info *info)
9893{
9894 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9895 struct nlattr *tb[NUM_NL80211_WOWLAN_TRIG];
Johannes Bergff1b6e62011-05-04 15:37:28 +02009896 struct cfg80211_wowlan new_triggers = {};
Johannes Bergae33bd82012-07-12 16:25:02 +02009897 struct cfg80211_wowlan *ntrig;
Johannes Berg964dc9e2013-06-03 17:25:34 +02009898 const struct wiphy_wowlan_support *wowlan = rdev->wiphy.wowlan;
Johannes Bergff1b6e62011-05-04 15:37:28 +02009899 int err, i;
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009900 bool prev_enabled = rdev->wiphy.wowlan_config;
Johannes Berg98fc4382015-03-01 09:10:13 +02009901 bool regular = false;
Johannes Bergff1b6e62011-05-04 15:37:28 +02009902
Johannes Berg964dc9e2013-06-03 17:25:34 +02009903 if (!wowlan)
Johannes Bergff1b6e62011-05-04 15:37:28 +02009904 return -EOPNOTSUPP;
9905
Johannes Bergae33bd82012-07-12 16:25:02 +02009906 if (!info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]) {
9907 cfg80211_rdev_free_wowlan(rdev);
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009908 rdev->wiphy.wowlan_config = NULL;
Johannes Bergae33bd82012-07-12 16:25:02 +02009909 goto set_wakeup;
9910 }
Johannes Bergff1b6e62011-05-04 15:37:28 +02009911
9912 err = nla_parse(tb, MAX_NL80211_WOWLAN_TRIG,
9913 nla_data(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]),
9914 nla_len(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]),
9915 nl80211_wowlan_policy);
9916 if (err)
9917 return err;
9918
9919 if (tb[NL80211_WOWLAN_TRIG_ANY]) {
9920 if (!(wowlan->flags & WIPHY_WOWLAN_ANY))
9921 return -EINVAL;
9922 new_triggers.any = true;
9923 }
9924
9925 if (tb[NL80211_WOWLAN_TRIG_DISCONNECT]) {
9926 if (!(wowlan->flags & WIPHY_WOWLAN_DISCONNECT))
9927 return -EINVAL;
9928 new_triggers.disconnect = true;
Johannes Berg98fc4382015-03-01 09:10:13 +02009929 regular = true;
Johannes Bergff1b6e62011-05-04 15:37:28 +02009930 }
9931
9932 if (tb[NL80211_WOWLAN_TRIG_MAGIC_PKT]) {
9933 if (!(wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT))
9934 return -EINVAL;
9935 new_triggers.magic_pkt = true;
Johannes Berg98fc4382015-03-01 09:10:13 +02009936 regular = true;
Johannes Bergff1b6e62011-05-04 15:37:28 +02009937 }
9938
Johannes Berg77dbbb12011-07-13 10:48:55 +02009939 if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED])
9940 return -EINVAL;
9941
9942 if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE]) {
9943 if (!(wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE))
9944 return -EINVAL;
9945 new_triggers.gtk_rekey_failure = true;
Johannes Berg98fc4382015-03-01 09:10:13 +02009946 regular = true;
Johannes Berg77dbbb12011-07-13 10:48:55 +02009947 }
9948
9949 if (tb[NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST]) {
9950 if (!(wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ))
9951 return -EINVAL;
9952 new_triggers.eap_identity_req = true;
Johannes Berg98fc4382015-03-01 09:10:13 +02009953 regular = true;
Johannes Berg77dbbb12011-07-13 10:48:55 +02009954 }
9955
9956 if (tb[NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE]) {
9957 if (!(wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE))
9958 return -EINVAL;
9959 new_triggers.four_way_handshake = true;
Johannes Berg98fc4382015-03-01 09:10:13 +02009960 regular = true;
Johannes Berg77dbbb12011-07-13 10:48:55 +02009961 }
9962
9963 if (tb[NL80211_WOWLAN_TRIG_RFKILL_RELEASE]) {
9964 if (!(wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE))
9965 return -EINVAL;
9966 new_triggers.rfkill_release = true;
Johannes Berg98fc4382015-03-01 09:10:13 +02009967 regular = true;
Johannes Berg77dbbb12011-07-13 10:48:55 +02009968 }
9969
Johannes Bergff1b6e62011-05-04 15:37:28 +02009970 if (tb[NL80211_WOWLAN_TRIG_PKT_PATTERN]) {
9971 struct nlattr *pat;
9972 int n_patterns = 0;
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08009973 int rem, pat_len, mask_len, pkt_offset;
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07009974 struct nlattr *pat_tb[NUM_NL80211_PKTPAT];
Johannes Bergff1b6e62011-05-04 15:37:28 +02009975
Johannes Berg98fc4382015-03-01 09:10:13 +02009976 regular = true;
9977
Johannes Bergff1b6e62011-05-04 15:37:28 +02009978 nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN],
9979 rem)
9980 n_patterns++;
9981 if (n_patterns > wowlan->n_patterns)
9982 return -EINVAL;
9983
9984 new_triggers.patterns = kcalloc(n_patterns,
9985 sizeof(new_triggers.patterns[0]),
9986 GFP_KERNEL);
9987 if (!new_triggers.patterns)
9988 return -ENOMEM;
9989
9990 new_triggers.n_patterns = n_patterns;
9991 i = 0;
9992
9993 nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN],
9994 rem) {
Johannes Berg922bd802014-05-19 17:59:50 +02009995 u8 *mask_pat;
9996
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07009997 nla_parse(pat_tb, MAX_NL80211_PKTPAT, nla_data(pat),
9998 nla_len(pat), NULL);
Johannes Bergff1b6e62011-05-04 15:37:28 +02009999 err = -EINVAL;
Amitkumar Karwar50ac6602013-06-25 19:03:56 -070010000 if (!pat_tb[NL80211_PKTPAT_MASK] ||
10001 !pat_tb[NL80211_PKTPAT_PATTERN])
Johannes Bergff1b6e62011-05-04 15:37:28 +020010002 goto error;
Amitkumar Karwar50ac6602013-06-25 19:03:56 -070010003 pat_len = nla_len(pat_tb[NL80211_PKTPAT_PATTERN]);
Johannes Bergff1b6e62011-05-04 15:37:28 +020010004 mask_len = DIV_ROUND_UP(pat_len, 8);
Amitkumar Karwar50ac6602013-06-25 19:03:56 -070010005 if (nla_len(pat_tb[NL80211_PKTPAT_MASK]) != mask_len)
Johannes Bergff1b6e62011-05-04 15:37:28 +020010006 goto error;
10007 if (pat_len > wowlan->pattern_max_len ||
10008 pat_len < wowlan->pattern_min_len)
10009 goto error;
10010
Amitkumar Karwar50ac6602013-06-25 19:03:56 -070010011 if (!pat_tb[NL80211_PKTPAT_OFFSET])
Amitkumar Karwarbb92d192013-02-12 12:16:26 -080010012 pkt_offset = 0;
10013 else
10014 pkt_offset = nla_get_u32(
Amitkumar Karwar50ac6602013-06-25 19:03:56 -070010015 pat_tb[NL80211_PKTPAT_OFFSET]);
Amitkumar Karwarbb92d192013-02-12 12:16:26 -080010016 if (pkt_offset > wowlan->max_pkt_offset)
10017 goto error;
10018 new_triggers.patterns[i].pkt_offset = pkt_offset;
10019
Johannes Berg922bd802014-05-19 17:59:50 +020010020 mask_pat = kmalloc(mask_len + pat_len, GFP_KERNEL);
10021 if (!mask_pat) {
Johannes Bergff1b6e62011-05-04 15:37:28 +020010022 err = -ENOMEM;
10023 goto error;
10024 }
Johannes Berg922bd802014-05-19 17:59:50 +020010025 new_triggers.patterns[i].mask = mask_pat;
10026 memcpy(mask_pat, nla_data(pat_tb[NL80211_PKTPAT_MASK]),
Johannes Bergff1b6e62011-05-04 15:37:28 +020010027 mask_len);
Johannes Berg922bd802014-05-19 17:59:50 +020010028 mask_pat += mask_len;
10029 new_triggers.patterns[i].pattern = mask_pat;
Johannes Bergff1b6e62011-05-04 15:37:28 +020010030 new_triggers.patterns[i].pattern_len = pat_len;
Johannes Berg922bd802014-05-19 17:59:50 +020010031 memcpy(mask_pat,
Amitkumar Karwar50ac6602013-06-25 19:03:56 -070010032 nla_data(pat_tb[NL80211_PKTPAT_PATTERN]),
Johannes Bergff1b6e62011-05-04 15:37:28 +020010033 pat_len);
10034 i++;
10035 }
10036 }
10037
Johannes Berg2a0e0472013-01-23 22:57:40 +010010038 if (tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION]) {
Johannes Berg98fc4382015-03-01 09:10:13 +020010039 regular = true;
Johannes Berg2a0e0472013-01-23 22:57:40 +010010040 err = nl80211_parse_wowlan_tcp(
10041 rdev, tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION],
10042 &new_triggers);
10043 if (err)
10044 goto error;
10045 }
10046
Luciano Coelho8cd4d452014-09-17 11:55:28 +030010047 if (tb[NL80211_WOWLAN_TRIG_NET_DETECT]) {
Johannes Berg98fc4382015-03-01 09:10:13 +020010048 regular = true;
Luciano Coelho8cd4d452014-09-17 11:55:28 +030010049 err = nl80211_parse_wowlan_nd(
10050 rdev, wowlan, tb[NL80211_WOWLAN_TRIG_NET_DETECT],
10051 &new_triggers);
10052 if (err)
10053 goto error;
10054 }
10055
Johannes Berg98fc4382015-03-01 09:10:13 +020010056 /* The 'any' trigger means the device continues operating more or less
10057 * as in its normal operation mode and wakes up the host on most of the
10058 * normal interrupts (like packet RX, ...)
10059 * It therefore makes little sense to combine with the more constrained
10060 * wakeup trigger modes.
10061 */
10062 if (new_triggers.any && regular) {
10063 err = -EINVAL;
10064 goto error;
10065 }
10066
Johannes Bergae33bd82012-07-12 16:25:02 +020010067 ntrig = kmemdup(&new_triggers, sizeof(new_triggers), GFP_KERNEL);
10068 if (!ntrig) {
10069 err = -ENOMEM;
10070 goto error;
Johannes Bergff1b6e62011-05-04 15:37:28 +020010071 }
Johannes Bergae33bd82012-07-12 16:25:02 +020010072 cfg80211_rdev_free_wowlan(rdev);
Johannes Berg6abb9cb2013-05-15 09:30:07 +020010073 rdev->wiphy.wowlan_config = ntrig;
Johannes Bergff1b6e62011-05-04 15:37:28 +020010074
Johannes Bergae33bd82012-07-12 16:25:02 +020010075 set_wakeup:
Johannes Berg6abb9cb2013-05-15 09:30:07 +020010076 if (rdev->ops->set_wakeup &&
10077 prev_enabled != !!rdev->wiphy.wowlan_config)
10078 rdev_set_wakeup(rdev, rdev->wiphy.wowlan_config);
Johannes Berg6d525632012-04-04 15:05:25 +020010079
Johannes Bergff1b6e62011-05-04 15:37:28 +020010080 return 0;
10081 error:
10082 for (i = 0; i < new_triggers.n_patterns; i++)
10083 kfree(new_triggers.patterns[i].mask);
10084 kfree(new_triggers.patterns);
Johannes Berg2a0e0472013-01-23 22:57:40 +010010085 if (new_triggers.tcp && new_triggers.tcp->sock)
10086 sock_release(new_triggers.tcp->sock);
10087 kfree(new_triggers.tcp);
Ola Olssone5dbe072015-12-12 23:17:17 +010010088 kfree(new_triggers.nd_config);
Johannes Bergff1b6e62011-05-04 15:37:28 +020010089 return err;
10090}
Johannes Bergdfb89c52012-06-27 09:23:48 +020010091#endif
Johannes Bergff1b6e62011-05-04 15:37:28 +020010092
Amitkumar Karwarbe29b99a2013-06-28 11:51:26 -070010093static int nl80211_send_coalesce_rules(struct sk_buff *msg,
10094 struct cfg80211_registered_device *rdev)
10095{
10096 struct nlattr *nl_pats, *nl_pat, *nl_rule, *nl_rules;
10097 int i, j, pat_len;
10098 struct cfg80211_coalesce_rules *rule;
10099
10100 if (!rdev->coalesce->n_rules)
10101 return 0;
10102
10103 nl_rules = nla_nest_start(msg, NL80211_ATTR_COALESCE_RULE);
10104 if (!nl_rules)
10105 return -ENOBUFS;
10106
10107 for (i = 0; i < rdev->coalesce->n_rules; i++) {
10108 nl_rule = nla_nest_start(msg, i + 1);
10109 if (!nl_rule)
10110 return -ENOBUFS;
10111
10112 rule = &rdev->coalesce->rules[i];
10113 if (nla_put_u32(msg, NL80211_ATTR_COALESCE_RULE_DELAY,
10114 rule->delay))
10115 return -ENOBUFS;
10116
10117 if (nla_put_u32(msg, NL80211_ATTR_COALESCE_RULE_CONDITION,
10118 rule->condition))
10119 return -ENOBUFS;
10120
10121 nl_pats = nla_nest_start(msg,
10122 NL80211_ATTR_COALESCE_RULE_PKT_PATTERN);
10123 if (!nl_pats)
10124 return -ENOBUFS;
10125
10126 for (j = 0; j < rule->n_patterns; j++) {
10127 nl_pat = nla_nest_start(msg, j + 1);
10128 if (!nl_pat)
10129 return -ENOBUFS;
10130 pat_len = rule->patterns[j].pattern_len;
10131 if (nla_put(msg, NL80211_PKTPAT_MASK,
10132 DIV_ROUND_UP(pat_len, 8),
10133 rule->patterns[j].mask) ||
10134 nla_put(msg, NL80211_PKTPAT_PATTERN, pat_len,
10135 rule->patterns[j].pattern) ||
10136 nla_put_u32(msg, NL80211_PKTPAT_OFFSET,
10137 rule->patterns[j].pkt_offset))
10138 return -ENOBUFS;
10139 nla_nest_end(msg, nl_pat);
10140 }
10141 nla_nest_end(msg, nl_pats);
10142 nla_nest_end(msg, nl_rule);
10143 }
10144 nla_nest_end(msg, nl_rules);
10145
10146 return 0;
10147}
10148
10149static int nl80211_get_coalesce(struct sk_buff *skb, struct genl_info *info)
10150{
10151 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10152 struct sk_buff *msg;
10153 void *hdr;
10154
10155 if (!rdev->wiphy.coalesce)
10156 return -EOPNOTSUPP;
10157
10158 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
10159 if (!msg)
10160 return -ENOMEM;
10161
10162 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
10163 NL80211_CMD_GET_COALESCE);
10164 if (!hdr)
10165 goto nla_put_failure;
10166
10167 if (rdev->coalesce && nl80211_send_coalesce_rules(msg, rdev))
10168 goto nla_put_failure;
10169
10170 genlmsg_end(msg, hdr);
10171 return genlmsg_reply(msg, info);
10172
10173nla_put_failure:
10174 nlmsg_free(msg);
10175 return -ENOBUFS;
10176}
10177
10178void cfg80211_rdev_free_coalesce(struct cfg80211_registered_device *rdev)
10179{
10180 struct cfg80211_coalesce *coalesce = rdev->coalesce;
10181 int i, j;
10182 struct cfg80211_coalesce_rules *rule;
10183
10184 if (!coalesce)
10185 return;
10186
10187 for (i = 0; i < coalesce->n_rules; i++) {
10188 rule = &coalesce->rules[i];
10189 for (j = 0; j < rule->n_patterns; j++)
10190 kfree(rule->patterns[j].mask);
10191 kfree(rule->patterns);
10192 }
10193 kfree(coalesce->rules);
10194 kfree(coalesce);
10195 rdev->coalesce = NULL;
10196}
10197
10198static int nl80211_parse_coalesce_rule(struct cfg80211_registered_device *rdev,
10199 struct nlattr *rule,
10200 struct cfg80211_coalesce_rules *new_rule)
10201{
10202 int err, i;
10203 const struct wiphy_coalesce_support *coalesce = rdev->wiphy.coalesce;
10204 struct nlattr *tb[NUM_NL80211_ATTR_COALESCE_RULE], *pat;
10205 int rem, pat_len, mask_len, pkt_offset, n_patterns = 0;
10206 struct nlattr *pat_tb[NUM_NL80211_PKTPAT];
10207
10208 err = nla_parse(tb, NL80211_ATTR_COALESCE_RULE_MAX, nla_data(rule),
10209 nla_len(rule), nl80211_coalesce_policy);
10210 if (err)
10211 return err;
10212
10213 if (tb[NL80211_ATTR_COALESCE_RULE_DELAY])
10214 new_rule->delay =
10215 nla_get_u32(tb[NL80211_ATTR_COALESCE_RULE_DELAY]);
10216 if (new_rule->delay > coalesce->max_delay)
10217 return -EINVAL;
10218
10219 if (tb[NL80211_ATTR_COALESCE_RULE_CONDITION])
10220 new_rule->condition =
10221 nla_get_u32(tb[NL80211_ATTR_COALESCE_RULE_CONDITION]);
10222 if (new_rule->condition != NL80211_COALESCE_CONDITION_MATCH &&
10223 new_rule->condition != NL80211_COALESCE_CONDITION_NO_MATCH)
10224 return -EINVAL;
10225
10226 if (!tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN])
10227 return -EINVAL;
10228
10229 nla_for_each_nested(pat, tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN],
10230 rem)
10231 n_patterns++;
10232 if (n_patterns > coalesce->n_patterns)
10233 return -EINVAL;
10234
10235 new_rule->patterns = kcalloc(n_patterns, sizeof(new_rule->patterns[0]),
10236 GFP_KERNEL);
10237 if (!new_rule->patterns)
10238 return -ENOMEM;
10239
10240 new_rule->n_patterns = n_patterns;
10241 i = 0;
10242
10243 nla_for_each_nested(pat, tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN],
10244 rem) {
Johannes Berg922bd802014-05-19 17:59:50 +020010245 u8 *mask_pat;
10246
Amitkumar Karwarbe29b99a2013-06-28 11:51:26 -070010247 nla_parse(pat_tb, MAX_NL80211_PKTPAT, nla_data(pat),
10248 nla_len(pat), NULL);
10249 if (!pat_tb[NL80211_PKTPAT_MASK] ||
10250 !pat_tb[NL80211_PKTPAT_PATTERN])
10251 return -EINVAL;
10252 pat_len = nla_len(pat_tb[NL80211_PKTPAT_PATTERN]);
10253 mask_len = DIV_ROUND_UP(pat_len, 8);
10254 if (nla_len(pat_tb[NL80211_PKTPAT_MASK]) != mask_len)
10255 return -EINVAL;
10256 if (pat_len > coalesce->pattern_max_len ||
10257 pat_len < coalesce->pattern_min_len)
10258 return -EINVAL;
10259
10260 if (!pat_tb[NL80211_PKTPAT_OFFSET])
10261 pkt_offset = 0;
10262 else
10263 pkt_offset = nla_get_u32(pat_tb[NL80211_PKTPAT_OFFSET]);
10264 if (pkt_offset > coalesce->max_pkt_offset)
10265 return -EINVAL;
10266 new_rule->patterns[i].pkt_offset = pkt_offset;
10267
Johannes Berg922bd802014-05-19 17:59:50 +020010268 mask_pat = kmalloc(mask_len + pat_len, GFP_KERNEL);
10269 if (!mask_pat)
Amitkumar Karwarbe29b99a2013-06-28 11:51:26 -070010270 return -ENOMEM;
Johannes Berg922bd802014-05-19 17:59:50 +020010271
10272 new_rule->patterns[i].mask = mask_pat;
10273 memcpy(mask_pat, nla_data(pat_tb[NL80211_PKTPAT_MASK]),
10274 mask_len);
10275
10276 mask_pat += mask_len;
10277 new_rule->patterns[i].pattern = mask_pat;
Amitkumar Karwarbe29b99a2013-06-28 11:51:26 -070010278 new_rule->patterns[i].pattern_len = pat_len;
Johannes Berg922bd802014-05-19 17:59:50 +020010279 memcpy(mask_pat, nla_data(pat_tb[NL80211_PKTPAT_PATTERN]),
10280 pat_len);
Amitkumar Karwarbe29b99a2013-06-28 11:51:26 -070010281 i++;
10282 }
10283
10284 return 0;
10285}
10286
10287static int nl80211_set_coalesce(struct sk_buff *skb, struct genl_info *info)
10288{
10289 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10290 const struct wiphy_coalesce_support *coalesce = rdev->wiphy.coalesce;
10291 struct cfg80211_coalesce new_coalesce = {};
10292 struct cfg80211_coalesce *n_coalesce;
10293 int err, rem_rule, n_rules = 0, i, j;
10294 struct nlattr *rule;
10295 struct cfg80211_coalesce_rules *tmp_rule;
10296
10297 if (!rdev->wiphy.coalesce || !rdev->ops->set_coalesce)
10298 return -EOPNOTSUPP;
10299
10300 if (!info->attrs[NL80211_ATTR_COALESCE_RULE]) {
10301 cfg80211_rdev_free_coalesce(rdev);
Ilan Peera1056b1b2015-10-22 22:27:46 +030010302 rdev_set_coalesce(rdev, NULL);
Amitkumar Karwarbe29b99a2013-06-28 11:51:26 -070010303 return 0;
10304 }
10305
10306 nla_for_each_nested(rule, info->attrs[NL80211_ATTR_COALESCE_RULE],
10307 rem_rule)
10308 n_rules++;
10309 if (n_rules > coalesce->n_rules)
10310 return -EINVAL;
10311
10312 new_coalesce.rules = kcalloc(n_rules, sizeof(new_coalesce.rules[0]),
10313 GFP_KERNEL);
10314 if (!new_coalesce.rules)
10315 return -ENOMEM;
10316
10317 new_coalesce.n_rules = n_rules;
10318 i = 0;
10319
10320 nla_for_each_nested(rule, info->attrs[NL80211_ATTR_COALESCE_RULE],
10321 rem_rule) {
10322 err = nl80211_parse_coalesce_rule(rdev, rule,
10323 &new_coalesce.rules[i]);
10324 if (err)
10325 goto error;
10326
10327 i++;
10328 }
10329
Ilan Peera1056b1b2015-10-22 22:27:46 +030010330 err = rdev_set_coalesce(rdev, &new_coalesce);
Amitkumar Karwarbe29b99a2013-06-28 11:51:26 -070010331 if (err)
10332 goto error;
10333
10334 n_coalesce = kmemdup(&new_coalesce, sizeof(new_coalesce), GFP_KERNEL);
10335 if (!n_coalesce) {
10336 err = -ENOMEM;
10337 goto error;
10338 }
10339 cfg80211_rdev_free_coalesce(rdev);
10340 rdev->coalesce = n_coalesce;
10341
10342 return 0;
10343error:
10344 for (i = 0; i < new_coalesce.n_rules; i++) {
10345 tmp_rule = &new_coalesce.rules[i];
10346 for (j = 0; j < tmp_rule->n_patterns; j++)
10347 kfree(tmp_rule->patterns[j].mask);
10348 kfree(tmp_rule->patterns);
10349 }
10350 kfree(new_coalesce.rules);
10351
10352 return err;
10353}
10354
Johannes Berge5497d72011-07-05 16:35:40 +020010355static int nl80211_set_rekey_data(struct sk_buff *skb, struct genl_info *info)
10356{
10357 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10358 struct net_device *dev = info->user_ptr[1];
10359 struct wireless_dev *wdev = dev->ieee80211_ptr;
10360 struct nlattr *tb[NUM_NL80211_REKEY_DATA];
10361 struct cfg80211_gtk_rekey_data rekey_data;
10362 int err;
10363
10364 if (!info->attrs[NL80211_ATTR_REKEY_DATA])
10365 return -EINVAL;
10366
10367 err = nla_parse(tb, MAX_NL80211_REKEY_DATA,
10368 nla_data(info->attrs[NL80211_ATTR_REKEY_DATA]),
10369 nla_len(info->attrs[NL80211_ATTR_REKEY_DATA]),
10370 nl80211_rekey_policy);
10371 if (err)
10372 return err;
10373
10374 if (nla_len(tb[NL80211_REKEY_DATA_REPLAY_CTR]) != NL80211_REPLAY_CTR_LEN)
10375 return -ERANGE;
10376 if (nla_len(tb[NL80211_REKEY_DATA_KEK]) != NL80211_KEK_LEN)
10377 return -ERANGE;
10378 if (nla_len(tb[NL80211_REKEY_DATA_KCK]) != NL80211_KCK_LEN)
10379 return -ERANGE;
10380
Johannes Berg78f686c2014-09-10 22:28:06 +030010381 rekey_data.kek = nla_data(tb[NL80211_REKEY_DATA_KEK]);
10382 rekey_data.kck = nla_data(tb[NL80211_REKEY_DATA_KCK]);
10383 rekey_data.replay_ctr = nla_data(tb[NL80211_REKEY_DATA_REPLAY_CTR]);
Johannes Berge5497d72011-07-05 16:35:40 +020010384
10385 wdev_lock(wdev);
10386 if (!wdev->current_bss) {
10387 err = -ENOTCONN;
10388 goto out;
10389 }
10390
10391 if (!rdev->ops->set_rekey_data) {
10392 err = -EOPNOTSUPP;
10393 goto out;
10394 }
10395
Hila Gonene35e4d22012-06-27 17:19:42 +030010396 err = rdev_set_rekey_data(rdev, dev, &rekey_data);
Johannes Berge5497d72011-07-05 16:35:40 +020010397 out:
10398 wdev_unlock(wdev);
10399 return err;
10400}
10401
Johannes Berg28946da2011-11-04 11:18:12 +010010402static int nl80211_register_unexpected_frame(struct sk_buff *skb,
10403 struct genl_info *info)
10404{
10405 struct net_device *dev = info->user_ptr[1];
10406 struct wireless_dev *wdev = dev->ieee80211_ptr;
10407
10408 if (wdev->iftype != NL80211_IFTYPE_AP &&
10409 wdev->iftype != NL80211_IFTYPE_P2P_GO)
10410 return -EINVAL;
10411
Eric W. Biederman15e47302012-09-07 20:12:54 +000010412 if (wdev->ap_unexpected_nlportid)
Johannes Berg28946da2011-11-04 11:18:12 +010010413 return -EBUSY;
10414
Eric W. Biederman15e47302012-09-07 20:12:54 +000010415 wdev->ap_unexpected_nlportid = info->snd_portid;
Johannes Berg28946da2011-11-04 11:18:12 +010010416 return 0;
10417}
10418
Johannes Berg7f6cf312011-11-04 11:18:15 +010010419static int nl80211_probe_client(struct sk_buff *skb,
10420 struct genl_info *info)
10421{
10422 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10423 struct net_device *dev = info->user_ptr[1];
10424 struct wireless_dev *wdev = dev->ieee80211_ptr;
10425 struct sk_buff *msg;
10426 void *hdr;
10427 const u8 *addr;
10428 u64 cookie;
10429 int err;
10430
10431 if (wdev->iftype != NL80211_IFTYPE_AP &&
10432 wdev->iftype != NL80211_IFTYPE_P2P_GO)
10433 return -EOPNOTSUPP;
10434
10435 if (!info->attrs[NL80211_ATTR_MAC])
10436 return -EINVAL;
10437
10438 if (!rdev->ops->probe_client)
10439 return -EOPNOTSUPP;
10440
10441 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
10442 if (!msg)
10443 return -ENOMEM;
10444
Eric W. Biederman15e47302012-09-07 20:12:54 +000010445 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berg7f6cf312011-11-04 11:18:15 +010010446 NL80211_CMD_PROBE_CLIENT);
Dan Carpentercb35fba2013-08-14 14:50:01 +030010447 if (!hdr) {
10448 err = -ENOBUFS;
Johannes Berg7f6cf312011-11-04 11:18:15 +010010449 goto free_msg;
10450 }
10451
10452 addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
10453
Hila Gonene35e4d22012-06-27 17:19:42 +030010454 err = rdev_probe_client(rdev, dev, addr, &cookie);
Johannes Berg7f6cf312011-11-04 11:18:15 +010010455 if (err)
10456 goto free_msg;
10457
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020010458 if (nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie,
10459 NL80211_ATTR_PAD))
David S. Miller9360ffd2012-03-29 04:41:26 -040010460 goto nla_put_failure;
Johannes Berg7f6cf312011-11-04 11:18:15 +010010461
10462 genlmsg_end(msg, hdr);
10463
10464 return genlmsg_reply(msg, info);
10465
10466 nla_put_failure:
10467 err = -ENOBUFS;
10468 free_msg:
10469 nlmsg_free(msg);
10470 return err;
10471}
10472
Johannes Berg5e760232011-11-04 11:18:17 +010010473static int nl80211_register_beacons(struct sk_buff *skb, struct genl_info *info)
10474{
10475 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Ben Greear37c73b52012-10-26 14:49:25 -070010476 struct cfg80211_beacon_registration *reg, *nreg;
10477 int rv;
Johannes Berg5e760232011-11-04 11:18:17 +010010478
10479 if (!(rdev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS))
10480 return -EOPNOTSUPP;
10481
Ben Greear37c73b52012-10-26 14:49:25 -070010482 nreg = kzalloc(sizeof(*nreg), GFP_KERNEL);
10483 if (!nreg)
10484 return -ENOMEM;
Johannes Berg5e760232011-11-04 11:18:17 +010010485
Ben Greear37c73b52012-10-26 14:49:25 -070010486 /* First, check if already registered. */
10487 spin_lock_bh(&rdev->beacon_registrations_lock);
10488 list_for_each_entry(reg, &rdev->beacon_registrations, list) {
10489 if (reg->nlportid == info->snd_portid) {
10490 rv = -EALREADY;
10491 goto out_err;
10492 }
10493 }
10494 /* Add it to the list */
10495 nreg->nlportid = info->snd_portid;
10496 list_add(&nreg->list, &rdev->beacon_registrations);
10497
10498 spin_unlock_bh(&rdev->beacon_registrations_lock);
Johannes Berg5e760232011-11-04 11:18:17 +010010499
10500 return 0;
Ben Greear37c73b52012-10-26 14:49:25 -070010501out_err:
10502 spin_unlock_bh(&rdev->beacon_registrations_lock);
10503 kfree(nreg);
10504 return rv;
Johannes Berg5e760232011-11-04 11:18:17 +010010505}
10506
Johannes Berg98104fde2012-06-16 00:19:54 +020010507static int nl80211_start_p2p_device(struct sk_buff *skb, struct genl_info *info)
10508{
10509 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10510 struct wireless_dev *wdev = info->user_ptr[1];
10511 int err;
10512
10513 if (!rdev->ops->start_p2p_device)
10514 return -EOPNOTSUPP;
10515
10516 if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE)
10517 return -EOPNOTSUPP;
10518
10519 if (wdev->p2p_started)
10520 return 0;
10521
Luciano Coelhob6a55012014-02-27 11:07:21 +020010522 if (rfkill_blocked(rdev->rfkill))
10523 return -ERFKILL;
Johannes Berg98104fde2012-06-16 00:19:54 +020010524
Johannes Bergeeb126e2012-10-23 15:16:50 +020010525 err = rdev_start_p2p_device(rdev, wdev);
Johannes Berg98104fde2012-06-16 00:19:54 +020010526 if (err)
10527 return err;
10528
10529 wdev->p2p_started = true;
Johannes Berg98104fde2012-06-16 00:19:54 +020010530 rdev->opencount++;
Johannes Berg98104fde2012-06-16 00:19:54 +020010531
10532 return 0;
10533}
10534
10535static int nl80211_stop_p2p_device(struct sk_buff *skb, struct genl_info *info)
10536{
10537 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10538 struct wireless_dev *wdev = info->user_ptr[1];
10539
10540 if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE)
10541 return -EOPNOTSUPP;
10542
10543 if (!rdev->ops->stop_p2p_device)
10544 return -EOPNOTSUPP;
10545
Johannes Bergf9f47522013-03-19 15:04:07 +010010546 cfg80211_stop_p2p_device(rdev, wdev);
Johannes Berg98104fde2012-06-16 00:19:54 +020010547
10548 return 0;
10549}
10550
Ayala Bekercb3b7d82016-09-20 17:31:13 +030010551static int nl80211_start_nan(struct sk_buff *skb, struct genl_info *info)
10552{
10553 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10554 struct wireless_dev *wdev = info->user_ptr[1];
10555 struct cfg80211_nan_conf conf = {};
10556 int err;
10557
10558 if (wdev->iftype != NL80211_IFTYPE_NAN)
10559 return -EOPNOTSUPP;
10560
10561 if (wdev->nan_started)
10562 return -EEXIST;
10563
10564 if (rfkill_blocked(rdev->rfkill))
10565 return -ERFKILL;
10566
10567 if (!info->attrs[NL80211_ATTR_NAN_MASTER_PREF])
10568 return -EINVAL;
10569
10570 if (!info->attrs[NL80211_ATTR_NAN_DUAL])
10571 return -EINVAL;
10572
10573 conf.master_pref =
10574 nla_get_u8(info->attrs[NL80211_ATTR_NAN_MASTER_PREF]);
10575 if (!conf.master_pref)
10576 return -EINVAL;
10577
10578 conf.dual = nla_get_u8(info->attrs[NL80211_ATTR_NAN_DUAL]);
10579
10580 err = rdev_start_nan(rdev, wdev, &conf);
10581 if (err)
10582 return err;
10583
10584 wdev->nan_started = true;
10585 rdev->opencount++;
10586
10587 return 0;
10588}
10589
10590static int nl80211_stop_nan(struct sk_buff *skb, struct genl_info *info)
10591{
10592 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10593 struct wireless_dev *wdev = info->user_ptr[1];
10594
10595 if (wdev->iftype != NL80211_IFTYPE_NAN)
10596 return -EOPNOTSUPP;
10597
10598 cfg80211_stop_nan(rdev, wdev);
10599
10600 return 0;
10601}
10602
Ayala Bekera442b762016-09-20 17:31:15 +030010603static int validate_nan_filter(struct nlattr *filter_attr)
10604{
10605 struct nlattr *attr;
10606 int len = 0, n_entries = 0, rem;
10607
10608 nla_for_each_nested(attr, filter_attr, rem) {
10609 len += nla_len(attr);
10610 n_entries++;
10611 }
10612
10613 if (len >= U8_MAX)
10614 return -EINVAL;
10615
10616 return n_entries;
10617}
10618
10619static int handle_nan_filter(struct nlattr *attr_filter,
10620 struct cfg80211_nan_func *func,
10621 bool tx)
10622{
10623 struct nlattr *attr;
10624 int n_entries, rem, i;
10625 struct cfg80211_nan_func_filter *filter;
10626
10627 n_entries = validate_nan_filter(attr_filter);
10628 if (n_entries < 0)
10629 return n_entries;
10630
10631 BUILD_BUG_ON(sizeof(*func->rx_filters) != sizeof(*func->tx_filters));
10632
10633 filter = kcalloc(n_entries, sizeof(*func->rx_filters), GFP_KERNEL);
10634 if (!filter)
10635 return -ENOMEM;
10636
10637 i = 0;
10638 nla_for_each_nested(attr, attr_filter, rem) {
10639 filter[i].filter = kmemdup(nla_data(attr), nla_len(attr),
10640 GFP_KERNEL);
10641 filter[i].len = nla_len(attr);
10642 i++;
10643 }
10644 if (tx) {
10645 func->num_tx_filters = n_entries;
10646 func->tx_filters = filter;
10647 } else {
10648 func->num_rx_filters = n_entries;
10649 func->rx_filters = filter;
10650 }
10651
10652 return 0;
10653}
10654
10655static int nl80211_nan_add_func(struct sk_buff *skb,
10656 struct genl_info *info)
10657{
10658 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10659 struct wireless_dev *wdev = info->user_ptr[1];
10660 struct nlattr *tb[NUM_NL80211_NAN_FUNC_ATTR], *func_attr;
10661 struct cfg80211_nan_func *func;
10662 struct sk_buff *msg = NULL;
10663 void *hdr = NULL;
10664 int err = 0;
10665
10666 if (wdev->iftype != NL80211_IFTYPE_NAN)
10667 return -EOPNOTSUPP;
10668
10669 if (!wdev->nan_started)
10670 return -ENOTCONN;
10671
10672 if (!info->attrs[NL80211_ATTR_NAN_FUNC])
10673 return -EINVAL;
10674
10675 if (wdev->owner_nlportid &&
10676 wdev->owner_nlportid != info->snd_portid)
10677 return -ENOTCONN;
10678
10679 err = nla_parse(tb, NL80211_NAN_FUNC_ATTR_MAX,
10680 nla_data(info->attrs[NL80211_ATTR_NAN_FUNC]),
10681 nla_len(info->attrs[NL80211_ATTR_NAN_FUNC]),
10682 nl80211_nan_func_policy);
10683 if (err)
10684 return err;
10685
10686 func = kzalloc(sizeof(*func), GFP_KERNEL);
10687 if (!func)
10688 return -ENOMEM;
10689
10690 func->cookie = wdev->wiphy->cookie_counter++;
10691
10692 if (!tb[NL80211_NAN_FUNC_TYPE] ||
10693 nla_get_u8(tb[NL80211_NAN_FUNC_TYPE]) > NL80211_NAN_FUNC_MAX_TYPE) {
10694 err = -EINVAL;
10695 goto out;
10696 }
10697
10698
10699 func->type = nla_get_u8(tb[NL80211_NAN_FUNC_TYPE]);
10700
10701 if (!tb[NL80211_NAN_FUNC_SERVICE_ID]) {
10702 err = -EINVAL;
10703 goto out;
10704 }
10705
10706 memcpy(func->service_id, nla_data(tb[NL80211_NAN_FUNC_SERVICE_ID]),
10707 sizeof(func->service_id));
10708
10709 func->close_range =
10710 nla_get_flag(tb[NL80211_NAN_FUNC_CLOSE_RANGE]);
10711
10712 if (tb[NL80211_NAN_FUNC_SERVICE_INFO]) {
10713 func->serv_spec_info_len =
10714 nla_len(tb[NL80211_NAN_FUNC_SERVICE_INFO]);
10715 func->serv_spec_info =
10716 kmemdup(nla_data(tb[NL80211_NAN_FUNC_SERVICE_INFO]),
10717 func->serv_spec_info_len,
10718 GFP_KERNEL);
10719 if (!func->serv_spec_info) {
10720 err = -ENOMEM;
10721 goto out;
10722 }
10723 }
10724
10725 if (tb[NL80211_NAN_FUNC_TTL])
10726 func->ttl = nla_get_u32(tb[NL80211_NAN_FUNC_TTL]);
10727
10728 switch (func->type) {
10729 case NL80211_NAN_FUNC_PUBLISH:
10730 if (!tb[NL80211_NAN_FUNC_PUBLISH_TYPE]) {
10731 err = -EINVAL;
10732 goto out;
10733 }
10734
10735 func->publish_type =
10736 nla_get_u8(tb[NL80211_NAN_FUNC_PUBLISH_TYPE]);
10737 func->publish_bcast =
10738 nla_get_flag(tb[NL80211_NAN_FUNC_PUBLISH_BCAST]);
10739
10740 if ((!(func->publish_type & NL80211_NAN_SOLICITED_PUBLISH)) &&
10741 func->publish_bcast) {
10742 err = -EINVAL;
10743 goto out;
10744 }
10745 break;
10746 case NL80211_NAN_FUNC_SUBSCRIBE:
10747 func->subscribe_active =
10748 nla_get_flag(tb[NL80211_NAN_FUNC_SUBSCRIBE_ACTIVE]);
10749 break;
10750 case NL80211_NAN_FUNC_FOLLOW_UP:
10751 if (!tb[NL80211_NAN_FUNC_FOLLOW_UP_ID] ||
10752 !tb[NL80211_NAN_FUNC_FOLLOW_UP_REQ_ID]) {
10753 err = -EINVAL;
10754 goto out;
10755 }
10756
10757 func->followup_id =
10758 nla_get_u8(tb[NL80211_NAN_FUNC_FOLLOW_UP_ID]);
10759 func->followup_reqid =
10760 nla_get_u8(tb[NL80211_NAN_FUNC_FOLLOW_UP_REQ_ID]);
10761 memcpy(func->followup_dest.addr,
10762 nla_data(tb[NL80211_NAN_FUNC_FOLLOW_UP_DEST]),
10763 sizeof(func->followup_dest.addr));
10764 if (func->ttl) {
10765 err = -EINVAL;
10766 goto out;
10767 }
10768 break;
10769 default:
10770 err = -EINVAL;
10771 goto out;
10772 }
10773
10774 if (tb[NL80211_NAN_FUNC_SRF]) {
10775 struct nlattr *srf_tb[NUM_NL80211_NAN_SRF_ATTR];
10776
10777 err = nla_parse(srf_tb, NL80211_NAN_SRF_ATTR_MAX,
10778 nla_data(tb[NL80211_NAN_FUNC_SRF]),
10779 nla_len(tb[NL80211_NAN_FUNC_SRF]), NULL);
10780 if (err)
10781 goto out;
10782
10783 func->srf_include =
10784 nla_get_flag(srf_tb[NL80211_NAN_SRF_INCLUDE]);
10785
10786 if (srf_tb[NL80211_NAN_SRF_BF]) {
10787 if (srf_tb[NL80211_NAN_SRF_MAC_ADDRS] ||
10788 !srf_tb[NL80211_NAN_SRF_BF_IDX]) {
10789 err = -EINVAL;
10790 goto out;
10791 }
10792
10793 func->srf_bf_len =
10794 nla_len(srf_tb[NL80211_NAN_SRF_BF]);
10795 func->srf_bf =
10796 kmemdup(nla_data(srf_tb[NL80211_NAN_SRF_BF]),
10797 func->srf_bf_len, GFP_KERNEL);
10798 if (!func->srf_bf) {
10799 err = -ENOMEM;
10800 goto out;
10801 }
10802
10803 func->srf_bf_idx =
10804 nla_get_u8(srf_tb[NL80211_NAN_SRF_BF_IDX]);
10805 } else {
10806 struct nlattr *attr, *mac_attr =
10807 srf_tb[NL80211_NAN_SRF_MAC_ADDRS];
10808 int n_entries, rem, i = 0;
10809
10810 if (!mac_attr) {
10811 err = -EINVAL;
10812 goto out;
10813 }
10814
10815 n_entries = validate_acl_mac_addrs(mac_attr);
10816 if (n_entries <= 0) {
10817 err = -EINVAL;
10818 goto out;
10819 }
10820
10821 func->srf_num_macs = n_entries;
10822 func->srf_macs =
10823 kzalloc(sizeof(*func->srf_macs) * n_entries,
10824 GFP_KERNEL);
10825 if (!func->srf_macs) {
10826 err = -ENOMEM;
10827 goto out;
10828 }
10829
10830 nla_for_each_nested(attr, mac_attr, rem)
10831 memcpy(func->srf_macs[i++].addr, nla_data(attr),
10832 sizeof(*func->srf_macs));
10833 }
10834 }
10835
10836 if (tb[NL80211_NAN_FUNC_TX_MATCH_FILTER]) {
10837 err = handle_nan_filter(tb[NL80211_NAN_FUNC_TX_MATCH_FILTER],
10838 func, true);
10839 if (err)
10840 goto out;
10841 }
10842
10843 if (tb[NL80211_NAN_FUNC_RX_MATCH_FILTER]) {
10844 err = handle_nan_filter(tb[NL80211_NAN_FUNC_RX_MATCH_FILTER],
10845 func, false);
10846 if (err)
10847 goto out;
10848 }
10849
10850 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
10851 if (!msg) {
10852 err = -ENOMEM;
10853 goto out;
10854 }
10855
10856 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
10857 NL80211_CMD_ADD_NAN_FUNCTION);
10858 /* This can't really happen - we just allocated 4KB */
10859 if (WARN_ON(!hdr)) {
10860 err = -ENOMEM;
10861 goto out;
10862 }
10863
10864 err = rdev_add_nan_func(rdev, wdev, func);
10865out:
10866 if (err < 0) {
10867 cfg80211_free_nan_func(func);
10868 nlmsg_free(msg);
10869 return err;
10870 }
10871
10872 /* propagate the instance id and cookie to userspace */
10873 if (nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, func->cookie,
10874 NL80211_ATTR_PAD))
10875 goto nla_put_failure;
10876
10877 func_attr = nla_nest_start(msg, NL80211_ATTR_NAN_FUNC);
10878 if (!func_attr)
10879 goto nla_put_failure;
10880
10881 if (nla_put_u8(msg, NL80211_NAN_FUNC_INSTANCE_ID,
10882 func->instance_id))
10883 goto nla_put_failure;
10884
10885 nla_nest_end(msg, func_attr);
10886
10887 genlmsg_end(msg, hdr);
10888 return genlmsg_reply(msg, info);
10889
10890nla_put_failure:
10891 nlmsg_free(msg);
10892 return -ENOBUFS;
10893}
10894
10895static int nl80211_nan_del_func(struct sk_buff *skb,
10896 struct genl_info *info)
10897{
10898 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10899 struct wireless_dev *wdev = info->user_ptr[1];
10900 u64 cookie;
10901
10902 if (wdev->iftype != NL80211_IFTYPE_NAN)
10903 return -EOPNOTSUPP;
10904
10905 if (!wdev->nan_started)
10906 return -ENOTCONN;
10907
10908 if (!info->attrs[NL80211_ATTR_COOKIE])
10909 return -EINVAL;
10910
10911 if (wdev->owner_nlportid &&
10912 wdev->owner_nlportid != info->snd_portid)
10913 return -ENOTCONN;
10914
10915 cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]);
10916
10917 rdev_del_nan_func(rdev, wdev, cookie);
10918
10919 return 0;
10920}
10921
Ayala Bekera5a9dcf2016-09-20 17:31:16 +030010922static int nl80211_nan_change_config(struct sk_buff *skb,
10923 struct genl_info *info)
10924{
10925 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10926 struct wireless_dev *wdev = info->user_ptr[1];
10927 struct cfg80211_nan_conf conf = {};
10928 u32 changed = 0;
10929
10930 if (wdev->iftype != NL80211_IFTYPE_NAN)
10931 return -EOPNOTSUPP;
10932
10933 if (!wdev->nan_started)
10934 return -ENOTCONN;
10935
10936 if (info->attrs[NL80211_ATTR_NAN_MASTER_PREF]) {
10937 conf.master_pref =
10938 nla_get_u8(info->attrs[NL80211_ATTR_NAN_MASTER_PREF]);
10939 if (conf.master_pref <= 1 || conf.master_pref == 255)
10940 return -EINVAL;
10941
10942 changed |= CFG80211_NAN_CONF_CHANGED_PREF;
10943 }
10944
10945 if (info->attrs[NL80211_ATTR_NAN_DUAL]) {
10946 conf.dual = nla_get_u8(info->attrs[NL80211_ATTR_NAN_DUAL]);
10947 changed |= CFG80211_NAN_CONF_CHANGED_DUAL;
10948 }
10949
10950 if (!changed)
10951 return -EINVAL;
10952
10953 return rdev_nan_change_conf(rdev, wdev, &conf, changed);
10954}
10955
Johannes Berg3713b4e2013-02-14 16:19:38 +010010956static int nl80211_get_protocol_features(struct sk_buff *skb,
10957 struct genl_info *info)
10958{
10959 void *hdr;
10960 struct sk_buff *msg;
10961
10962 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
10963 if (!msg)
10964 return -ENOMEM;
10965
10966 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
10967 NL80211_CMD_GET_PROTOCOL_FEATURES);
10968 if (!hdr)
10969 goto nla_put_failure;
10970
10971 if (nla_put_u32(msg, NL80211_ATTR_PROTOCOL_FEATURES,
10972 NL80211_PROTOCOL_FEATURE_SPLIT_WIPHY_DUMP))
10973 goto nla_put_failure;
10974
10975 genlmsg_end(msg, hdr);
10976 return genlmsg_reply(msg, info);
10977
10978 nla_put_failure:
10979 kfree_skb(msg);
10980 return -ENOBUFS;
10981}
10982
Jouni Malinen355199e2013-02-27 17:14:27 +020010983static int nl80211_update_ft_ies(struct sk_buff *skb, struct genl_info *info)
10984{
10985 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10986 struct cfg80211_update_ft_ies_params ft_params;
10987 struct net_device *dev = info->user_ptr[1];
10988
10989 if (!rdev->ops->update_ft_ies)
10990 return -EOPNOTSUPP;
10991
10992 if (!info->attrs[NL80211_ATTR_MDID] ||
10993 !is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
10994 return -EINVAL;
10995
10996 memset(&ft_params, 0, sizeof(ft_params));
10997 ft_params.md = nla_get_u16(info->attrs[NL80211_ATTR_MDID]);
10998 ft_params.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
10999 ft_params.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
11000
11001 return rdev_update_ft_ies(rdev, dev, &ft_params);
11002}
11003
Arend van Spriel5de17982013-04-18 15:49:00 +020011004static int nl80211_crit_protocol_start(struct sk_buff *skb,
11005 struct genl_info *info)
11006{
11007 struct cfg80211_registered_device *rdev = info->user_ptr[0];
11008 struct wireless_dev *wdev = info->user_ptr[1];
11009 enum nl80211_crit_proto_id proto = NL80211_CRIT_PROTO_UNSPEC;
11010 u16 duration;
11011 int ret;
11012
11013 if (!rdev->ops->crit_proto_start)
11014 return -EOPNOTSUPP;
11015
11016 if (WARN_ON(!rdev->ops->crit_proto_stop))
11017 return -EINVAL;
11018
11019 if (rdev->crit_proto_nlportid)
11020 return -EBUSY;
11021
11022 /* determine protocol if provided */
11023 if (info->attrs[NL80211_ATTR_CRIT_PROT_ID])
11024 proto = nla_get_u16(info->attrs[NL80211_ATTR_CRIT_PROT_ID]);
11025
11026 if (proto >= NUM_NL80211_CRIT_PROTO)
11027 return -EINVAL;
11028
11029 /* timeout must be provided */
11030 if (!info->attrs[NL80211_ATTR_MAX_CRIT_PROT_DURATION])
11031 return -EINVAL;
11032
11033 duration =
11034 nla_get_u16(info->attrs[NL80211_ATTR_MAX_CRIT_PROT_DURATION]);
11035
11036 if (duration > NL80211_CRIT_PROTO_MAX_DURATION)
11037 return -ERANGE;
11038
11039 ret = rdev_crit_proto_start(rdev, wdev, proto, duration);
11040 if (!ret)
11041 rdev->crit_proto_nlportid = info->snd_portid;
11042
11043 return ret;
11044}
11045
11046static int nl80211_crit_protocol_stop(struct sk_buff *skb,
11047 struct genl_info *info)
11048{
11049 struct cfg80211_registered_device *rdev = info->user_ptr[0];
11050 struct wireless_dev *wdev = info->user_ptr[1];
11051
11052 if (!rdev->ops->crit_proto_stop)
11053 return -EOPNOTSUPP;
11054
11055 if (rdev->crit_proto_nlportid) {
11056 rdev->crit_proto_nlportid = 0;
11057 rdev_crit_proto_stop(rdev, wdev);
11058 }
11059 return 0;
11060}
11061
Johannes Bergad7e7182013-11-13 13:37:47 +010011062static int nl80211_vendor_cmd(struct sk_buff *skb, struct genl_info *info)
11063{
11064 struct cfg80211_registered_device *rdev = info->user_ptr[0];
11065 struct wireless_dev *wdev =
11066 __cfg80211_wdev_from_attrs(genl_info_net(info), info->attrs);
11067 int i, err;
11068 u32 vid, subcmd;
11069
11070 if (!rdev->wiphy.vendor_commands)
11071 return -EOPNOTSUPP;
11072
11073 if (IS_ERR(wdev)) {
11074 err = PTR_ERR(wdev);
11075 if (err != -EINVAL)
11076 return err;
11077 wdev = NULL;
11078 } else if (wdev->wiphy != &rdev->wiphy) {
11079 return -EINVAL;
11080 }
11081
11082 if (!info->attrs[NL80211_ATTR_VENDOR_ID] ||
11083 !info->attrs[NL80211_ATTR_VENDOR_SUBCMD])
11084 return -EINVAL;
11085
11086 vid = nla_get_u32(info->attrs[NL80211_ATTR_VENDOR_ID]);
11087 subcmd = nla_get_u32(info->attrs[NL80211_ATTR_VENDOR_SUBCMD]);
11088 for (i = 0; i < rdev->wiphy.n_vendor_commands; i++) {
11089 const struct wiphy_vendor_command *vcmd;
11090 void *data = NULL;
11091 int len = 0;
11092
11093 vcmd = &rdev->wiphy.vendor_commands[i];
11094
11095 if (vcmd->info.vendor_id != vid || vcmd->info.subcmd != subcmd)
11096 continue;
11097
11098 if (vcmd->flags & (WIPHY_VENDOR_CMD_NEED_WDEV |
11099 WIPHY_VENDOR_CMD_NEED_NETDEV)) {
11100 if (!wdev)
11101 return -EINVAL;
11102 if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_NETDEV &&
11103 !wdev->netdev)
11104 return -EINVAL;
11105
11106 if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_RUNNING) {
11107 if (wdev->netdev &&
11108 !netif_running(wdev->netdev))
11109 return -ENETDOWN;
11110 if (!wdev->netdev && !wdev->p2p_started)
11111 return -ENETDOWN;
11112 }
Johannes Berg7bdbe402015-08-15 22:39:49 +030011113
11114 if (!vcmd->doit)
11115 return -EOPNOTSUPP;
Johannes Bergad7e7182013-11-13 13:37:47 +010011116 } else {
11117 wdev = NULL;
11118 }
11119
11120 if (info->attrs[NL80211_ATTR_VENDOR_DATA]) {
11121 data = nla_data(info->attrs[NL80211_ATTR_VENDOR_DATA]);
11122 len = nla_len(info->attrs[NL80211_ATTR_VENDOR_DATA]);
11123 }
11124
11125 rdev->cur_cmd_info = info;
11126 err = rdev->wiphy.vendor_commands[i].doit(&rdev->wiphy, wdev,
11127 data, len);
11128 rdev->cur_cmd_info = NULL;
11129 return err;
11130 }
11131
11132 return -EOPNOTSUPP;
11133}
11134
Johannes Berg7bdbe402015-08-15 22:39:49 +030011135static int nl80211_prepare_vendor_dump(struct sk_buff *skb,
11136 struct netlink_callback *cb,
11137 struct cfg80211_registered_device **rdev,
11138 struct wireless_dev **wdev)
11139{
11140 u32 vid, subcmd;
11141 unsigned int i;
11142 int vcmd_idx = -1;
11143 int err;
11144 void *data = NULL;
11145 unsigned int data_len = 0;
11146
11147 rtnl_lock();
11148
11149 if (cb->args[0]) {
11150 /* subtract the 1 again here */
11151 struct wiphy *wiphy = wiphy_idx_to_wiphy(cb->args[0] - 1);
11152 struct wireless_dev *tmp;
11153
11154 if (!wiphy) {
11155 err = -ENODEV;
11156 goto out_unlock;
11157 }
11158 *rdev = wiphy_to_rdev(wiphy);
11159 *wdev = NULL;
11160
11161 if (cb->args[1]) {
Johannes Berg53873f12016-05-03 16:52:04 +030011162 list_for_each_entry(tmp, &wiphy->wdev_list, list) {
Johannes Berg7bdbe402015-08-15 22:39:49 +030011163 if (tmp->identifier == cb->args[1] - 1) {
11164 *wdev = tmp;
11165 break;
11166 }
11167 }
11168 }
11169
11170 /* keep rtnl locked in successful case */
11171 return 0;
11172 }
11173
11174 err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize,
11175 nl80211_fam.attrbuf, nl80211_fam.maxattr,
11176 nl80211_policy);
11177 if (err)
11178 goto out_unlock;
11179
11180 if (!nl80211_fam.attrbuf[NL80211_ATTR_VENDOR_ID] ||
11181 !nl80211_fam.attrbuf[NL80211_ATTR_VENDOR_SUBCMD]) {
11182 err = -EINVAL;
11183 goto out_unlock;
11184 }
11185
11186 *wdev = __cfg80211_wdev_from_attrs(sock_net(skb->sk),
11187 nl80211_fam.attrbuf);
11188 if (IS_ERR(*wdev))
11189 *wdev = NULL;
11190
11191 *rdev = __cfg80211_rdev_from_attrs(sock_net(skb->sk),
11192 nl80211_fam.attrbuf);
11193 if (IS_ERR(*rdev)) {
11194 err = PTR_ERR(*rdev);
11195 goto out_unlock;
11196 }
11197
11198 vid = nla_get_u32(nl80211_fam.attrbuf[NL80211_ATTR_VENDOR_ID]);
11199 subcmd = nla_get_u32(nl80211_fam.attrbuf[NL80211_ATTR_VENDOR_SUBCMD]);
11200
11201 for (i = 0; i < (*rdev)->wiphy.n_vendor_commands; i++) {
11202 const struct wiphy_vendor_command *vcmd;
11203
11204 vcmd = &(*rdev)->wiphy.vendor_commands[i];
11205
11206 if (vcmd->info.vendor_id != vid || vcmd->info.subcmd != subcmd)
11207 continue;
11208
11209 if (!vcmd->dumpit) {
11210 err = -EOPNOTSUPP;
11211 goto out_unlock;
11212 }
11213
11214 vcmd_idx = i;
11215 break;
11216 }
11217
11218 if (vcmd_idx < 0) {
11219 err = -EOPNOTSUPP;
11220 goto out_unlock;
11221 }
11222
11223 if (nl80211_fam.attrbuf[NL80211_ATTR_VENDOR_DATA]) {
11224 data = nla_data(nl80211_fam.attrbuf[NL80211_ATTR_VENDOR_DATA]);
11225 data_len = nla_len(nl80211_fam.attrbuf[NL80211_ATTR_VENDOR_DATA]);
11226 }
11227
11228 /* 0 is the first index - add 1 to parse only once */
11229 cb->args[0] = (*rdev)->wiphy_idx + 1;
11230 /* add 1 to know if it was NULL */
11231 cb->args[1] = *wdev ? (*wdev)->identifier + 1 : 0;
11232 cb->args[2] = vcmd_idx;
11233 cb->args[3] = (unsigned long)data;
11234 cb->args[4] = data_len;
11235
11236 /* keep rtnl locked in successful case */
11237 return 0;
11238 out_unlock:
11239 rtnl_unlock();
11240 return err;
11241}
11242
11243static int nl80211_vendor_cmd_dump(struct sk_buff *skb,
11244 struct netlink_callback *cb)
11245{
11246 struct cfg80211_registered_device *rdev;
11247 struct wireless_dev *wdev;
11248 unsigned int vcmd_idx;
11249 const struct wiphy_vendor_command *vcmd;
11250 void *data;
11251 int data_len;
11252 int err;
11253 struct nlattr *vendor_data;
11254
11255 err = nl80211_prepare_vendor_dump(skb, cb, &rdev, &wdev);
11256 if (err)
11257 return err;
11258
11259 vcmd_idx = cb->args[2];
11260 data = (void *)cb->args[3];
11261 data_len = cb->args[4];
11262 vcmd = &rdev->wiphy.vendor_commands[vcmd_idx];
11263
11264 if (vcmd->flags & (WIPHY_VENDOR_CMD_NEED_WDEV |
11265 WIPHY_VENDOR_CMD_NEED_NETDEV)) {
11266 if (!wdev)
11267 return -EINVAL;
11268 if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_NETDEV &&
11269 !wdev->netdev)
11270 return -EINVAL;
11271
11272 if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_RUNNING) {
11273 if (wdev->netdev &&
11274 !netif_running(wdev->netdev))
11275 return -ENETDOWN;
11276 if (!wdev->netdev && !wdev->p2p_started)
11277 return -ENETDOWN;
11278 }
11279 }
11280
11281 while (1) {
11282 void *hdr = nl80211hdr_put(skb, NETLINK_CB(cb->skb).portid,
11283 cb->nlh->nlmsg_seq, NLM_F_MULTI,
11284 NL80211_CMD_VENDOR);
11285 if (!hdr)
11286 break;
11287
11288 if (nla_put_u32(skb, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020011289 (wdev && nla_put_u64_64bit(skb, NL80211_ATTR_WDEV,
11290 wdev_id(wdev),
11291 NL80211_ATTR_PAD))) {
Johannes Berg7bdbe402015-08-15 22:39:49 +030011292 genlmsg_cancel(skb, hdr);
11293 break;
11294 }
11295
11296 vendor_data = nla_nest_start(skb, NL80211_ATTR_VENDOR_DATA);
11297 if (!vendor_data) {
11298 genlmsg_cancel(skb, hdr);
11299 break;
11300 }
11301
11302 err = vcmd->dumpit(&rdev->wiphy, wdev, skb, data, data_len,
11303 (unsigned long *)&cb->args[5]);
11304 nla_nest_end(skb, vendor_data);
11305
11306 if (err == -ENOBUFS || err == -ENOENT) {
11307 genlmsg_cancel(skb, hdr);
11308 break;
11309 } else if (err) {
11310 genlmsg_cancel(skb, hdr);
11311 goto out;
11312 }
11313
11314 genlmsg_end(skb, hdr);
11315 }
11316
11317 err = skb->len;
11318 out:
11319 rtnl_unlock();
11320 return err;
11321}
11322
Johannes Bergad7e7182013-11-13 13:37:47 +010011323struct sk_buff *__cfg80211_alloc_reply_skb(struct wiphy *wiphy,
11324 enum nl80211_commands cmd,
11325 enum nl80211_attrs attr,
11326 int approxlen)
11327{
Zhao, Gangf26cbf42014-04-21 12:53:03 +080011328 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Bergad7e7182013-11-13 13:37:47 +010011329
11330 if (WARN_ON(!rdev->cur_cmd_info))
11331 return NULL;
11332
Ahmad Kholaif6c09e792015-02-26 15:26:53 +020011333 return __cfg80211_alloc_vendor_skb(rdev, NULL, approxlen,
Johannes Bergad7e7182013-11-13 13:37:47 +010011334 rdev->cur_cmd_info->snd_portid,
11335 rdev->cur_cmd_info->snd_seq,
Johannes Berg567ffc32013-12-18 14:43:31 +010011336 cmd, attr, NULL, GFP_KERNEL);
Johannes Bergad7e7182013-11-13 13:37:47 +010011337}
11338EXPORT_SYMBOL(__cfg80211_alloc_reply_skb);
11339
11340int cfg80211_vendor_cmd_reply(struct sk_buff *skb)
11341{
11342 struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0];
11343 void *hdr = ((void **)skb->cb)[1];
11344 struct nlattr *data = ((void **)skb->cb)[2];
11345
Johannes Bergbd8c78e2014-07-30 14:55:26 +020011346 /* clear CB data for netlink core to own from now on */
11347 memset(skb->cb, 0, sizeof(skb->cb));
11348
Johannes Bergad7e7182013-11-13 13:37:47 +010011349 if (WARN_ON(!rdev->cur_cmd_info)) {
11350 kfree_skb(skb);
11351 return -EINVAL;
11352 }
11353
11354 nla_nest_end(skb, data);
11355 genlmsg_end(skb, hdr);
11356 return genlmsg_reply(skb, rdev->cur_cmd_info);
11357}
11358EXPORT_SYMBOL_GPL(cfg80211_vendor_cmd_reply);
11359
Kyeyoon Parkfa9ffc72013-12-16 23:01:30 -080011360static int nl80211_set_qos_map(struct sk_buff *skb,
11361 struct genl_info *info)
11362{
11363 struct cfg80211_registered_device *rdev = info->user_ptr[0];
11364 struct cfg80211_qos_map *qos_map = NULL;
11365 struct net_device *dev = info->user_ptr[1];
11366 u8 *pos, len, num_des, des_len, des;
11367 int ret;
11368
11369 if (!rdev->ops->set_qos_map)
11370 return -EOPNOTSUPP;
11371
11372 if (info->attrs[NL80211_ATTR_QOS_MAP]) {
11373 pos = nla_data(info->attrs[NL80211_ATTR_QOS_MAP]);
11374 len = nla_len(info->attrs[NL80211_ATTR_QOS_MAP]);
11375
11376 if (len % 2 || len < IEEE80211_QOS_MAP_LEN_MIN ||
11377 len > IEEE80211_QOS_MAP_LEN_MAX)
11378 return -EINVAL;
11379
11380 qos_map = kzalloc(sizeof(struct cfg80211_qos_map), GFP_KERNEL);
11381 if (!qos_map)
11382 return -ENOMEM;
11383
11384 num_des = (len - IEEE80211_QOS_MAP_LEN_MIN) >> 1;
11385 if (num_des) {
11386 des_len = num_des *
11387 sizeof(struct cfg80211_dscp_exception);
11388 memcpy(qos_map->dscp_exception, pos, des_len);
11389 qos_map->num_des = num_des;
11390 for (des = 0; des < num_des; des++) {
11391 if (qos_map->dscp_exception[des].up > 7) {
11392 kfree(qos_map);
11393 return -EINVAL;
11394 }
11395 }
11396 pos += des_len;
11397 }
11398 memcpy(qos_map->up, pos, IEEE80211_QOS_MAP_LEN_MIN);
11399 }
11400
11401 wdev_lock(dev->ieee80211_ptr);
11402 ret = nl80211_key_allowed(dev->ieee80211_ptr);
11403 if (!ret)
11404 ret = rdev_set_qos_map(rdev, dev, qos_map);
11405 wdev_unlock(dev->ieee80211_ptr);
11406
11407 kfree(qos_map);
11408 return ret;
11409}
11410
Johannes Berg960d01a2014-09-09 22:55:35 +030011411static int nl80211_add_tx_ts(struct sk_buff *skb, struct genl_info *info)
11412{
11413 struct cfg80211_registered_device *rdev = info->user_ptr[0];
11414 struct net_device *dev = info->user_ptr[1];
11415 struct wireless_dev *wdev = dev->ieee80211_ptr;
11416 const u8 *peer;
11417 u8 tsid, up;
11418 u16 admitted_time = 0;
11419 int err;
11420
Johannes Berg723e73a2014-10-22 09:25:06 +020011421 if (!(rdev->wiphy.features & NL80211_FEATURE_SUPPORTS_WMM_ADMISSION))
Johannes Berg960d01a2014-09-09 22:55:35 +030011422 return -EOPNOTSUPP;
11423
11424 if (!info->attrs[NL80211_ATTR_TSID] || !info->attrs[NL80211_ATTR_MAC] ||
11425 !info->attrs[NL80211_ATTR_USER_PRIO])
11426 return -EINVAL;
11427
11428 tsid = nla_get_u8(info->attrs[NL80211_ATTR_TSID]);
11429 if (tsid >= IEEE80211_NUM_TIDS)
11430 return -EINVAL;
11431
11432 up = nla_get_u8(info->attrs[NL80211_ATTR_USER_PRIO]);
11433 if (up >= IEEE80211_NUM_UPS)
11434 return -EINVAL;
11435
11436 /* WMM uses TIDs 0-7 even for TSPEC */
Johannes Berg723e73a2014-10-22 09:25:06 +020011437 if (tsid >= IEEE80211_FIRST_TSPEC_TSID) {
Johannes Berg960d01a2014-09-09 22:55:35 +030011438 /* TODO: handle 802.11 TSPEC/admission control
Johannes Berg723e73a2014-10-22 09:25:06 +020011439 * need more attributes for that (e.g. BA session requirement);
11440 * change the WMM adminssion test above to allow both then
Johannes Berg960d01a2014-09-09 22:55:35 +030011441 */
11442 return -EINVAL;
11443 }
11444
11445 peer = nla_data(info->attrs[NL80211_ATTR_MAC]);
11446
11447 if (info->attrs[NL80211_ATTR_ADMITTED_TIME]) {
11448 admitted_time =
11449 nla_get_u16(info->attrs[NL80211_ATTR_ADMITTED_TIME]);
11450 if (!admitted_time)
11451 return -EINVAL;
11452 }
11453
11454 wdev_lock(wdev);
11455 switch (wdev->iftype) {
11456 case NL80211_IFTYPE_STATION:
11457 case NL80211_IFTYPE_P2P_CLIENT:
11458 if (wdev->current_bss)
11459 break;
11460 err = -ENOTCONN;
11461 goto out;
11462 default:
11463 err = -EOPNOTSUPP;
11464 goto out;
11465 }
11466
11467 err = rdev_add_tx_ts(rdev, dev, tsid, peer, up, admitted_time);
11468
11469 out:
11470 wdev_unlock(wdev);
11471 return err;
11472}
11473
11474static int nl80211_del_tx_ts(struct sk_buff *skb, struct genl_info *info)
11475{
11476 struct cfg80211_registered_device *rdev = info->user_ptr[0];
11477 struct net_device *dev = info->user_ptr[1];
11478 struct wireless_dev *wdev = dev->ieee80211_ptr;
11479 const u8 *peer;
11480 u8 tsid;
11481 int err;
11482
11483 if (!info->attrs[NL80211_ATTR_TSID] || !info->attrs[NL80211_ATTR_MAC])
11484 return -EINVAL;
11485
11486 tsid = nla_get_u8(info->attrs[NL80211_ATTR_TSID]);
11487 peer = nla_data(info->attrs[NL80211_ATTR_MAC]);
11488
11489 wdev_lock(wdev);
11490 err = rdev_del_tx_ts(rdev, dev, tsid, peer);
11491 wdev_unlock(wdev);
11492
11493 return err;
11494}
11495
Arik Nemtsov1057d352014-11-19 12:54:26 +020011496static int nl80211_tdls_channel_switch(struct sk_buff *skb,
11497 struct genl_info *info)
11498{
11499 struct cfg80211_registered_device *rdev = info->user_ptr[0];
11500 struct net_device *dev = info->user_ptr[1];
11501 struct wireless_dev *wdev = dev->ieee80211_ptr;
11502 struct cfg80211_chan_def chandef = {};
11503 const u8 *addr;
11504 u8 oper_class;
11505 int err;
11506
11507 if (!rdev->ops->tdls_channel_switch ||
11508 !(rdev->wiphy.features & NL80211_FEATURE_TDLS_CHANNEL_SWITCH))
11509 return -EOPNOTSUPP;
11510
11511 switch (dev->ieee80211_ptr->iftype) {
11512 case NL80211_IFTYPE_STATION:
11513 case NL80211_IFTYPE_P2P_CLIENT:
11514 break;
11515 default:
11516 return -EOPNOTSUPP;
11517 }
11518
11519 if (!info->attrs[NL80211_ATTR_MAC] ||
11520 !info->attrs[NL80211_ATTR_OPER_CLASS])
11521 return -EINVAL;
11522
11523 err = nl80211_parse_chandef(rdev, info, &chandef);
11524 if (err)
11525 return err;
11526
11527 /*
11528 * Don't allow wide channels on the 2.4Ghz band, as per IEEE802.11-2012
11529 * section 10.22.6.2.1. Disallow 5/10Mhz channels as well for now, the
11530 * specification is not defined for them.
11531 */
Johannes Berg57fbcce2016-04-12 15:56:15 +020011532 if (chandef.chan->band == NL80211_BAND_2GHZ &&
Arik Nemtsov1057d352014-11-19 12:54:26 +020011533 chandef.width != NL80211_CHAN_WIDTH_20_NOHT &&
11534 chandef.width != NL80211_CHAN_WIDTH_20)
11535 return -EINVAL;
11536
11537 /* we will be active on the TDLS link */
Arik Nemtsov923b3522015-07-08 15:41:44 +030011538 if (!cfg80211_reg_can_beacon_relax(&rdev->wiphy, &chandef,
11539 wdev->iftype))
Arik Nemtsov1057d352014-11-19 12:54:26 +020011540 return -EINVAL;
11541
11542 /* don't allow switching to DFS channels */
11543 if (cfg80211_chandef_dfs_required(wdev->wiphy, &chandef, wdev->iftype))
11544 return -EINVAL;
11545
11546 addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
11547 oper_class = nla_get_u8(info->attrs[NL80211_ATTR_OPER_CLASS]);
11548
11549 wdev_lock(wdev);
11550 err = rdev_tdls_channel_switch(rdev, dev, addr, oper_class, &chandef);
11551 wdev_unlock(wdev);
11552
11553 return err;
11554}
11555
11556static int nl80211_tdls_cancel_channel_switch(struct sk_buff *skb,
11557 struct genl_info *info)
11558{
11559 struct cfg80211_registered_device *rdev = info->user_ptr[0];
11560 struct net_device *dev = info->user_ptr[1];
11561 struct wireless_dev *wdev = dev->ieee80211_ptr;
11562 const u8 *addr;
11563
11564 if (!rdev->ops->tdls_channel_switch ||
11565 !rdev->ops->tdls_cancel_channel_switch ||
11566 !(rdev->wiphy.features & NL80211_FEATURE_TDLS_CHANNEL_SWITCH))
11567 return -EOPNOTSUPP;
11568
11569 switch (dev->ieee80211_ptr->iftype) {
11570 case NL80211_IFTYPE_STATION:
11571 case NL80211_IFTYPE_P2P_CLIENT:
11572 break;
11573 default:
11574 return -EOPNOTSUPP;
11575 }
11576
11577 if (!info->attrs[NL80211_ATTR_MAC])
11578 return -EINVAL;
11579
11580 addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
11581
11582 wdev_lock(wdev);
11583 rdev_tdls_cancel_channel_switch(rdev, dev, addr);
11584 wdev_unlock(wdev);
11585
11586 return 0;
11587}
11588
Johannes Berg4c476992010-10-04 21:36:35 +020011589#define NL80211_FLAG_NEED_WIPHY 0x01
11590#define NL80211_FLAG_NEED_NETDEV 0x02
11591#define NL80211_FLAG_NEED_RTNL 0x04
Johannes Berg41265712010-10-04 21:14:05 +020011592#define NL80211_FLAG_CHECK_NETDEV_UP 0x08
11593#define NL80211_FLAG_NEED_NETDEV_UP (NL80211_FLAG_NEED_NETDEV |\
11594 NL80211_FLAG_CHECK_NETDEV_UP)
Johannes Berg1bf614e2012-06-15 15:23:36 +020011595#define NL80211_FLAG_NEED_WDEV 0x10
Johannes Berg98104fde2012-06-16 00:19:54 +020011596/* If a netdev is associated, it must be UP, P2P must be started */
Johannes Berg1bf614e2012-06-15 15:23:36 +020011597#define NL80211_FLAG_NEED_WDEV_UP (NL80211_FLAG_NEED_WDEV |\
11598 NL80211_FLAG_CHECK_NETDEV_UP)
Johannes Berg5393b912014-09-10 15:00:16 +030011599#define NL80211_FLAG_CLEAR_SKB 0x20
Johannes Berg4c476992010-10-04 21:36:35 +020011600
Johannes Bergf84f7712013-11-14 17:14:45 +010011601static int nl80211_pre_doit(const struct genl_ops *ops, struct sk_buff *skb,
Johannes Berg4c476992010-10-04 21:36:35 +020011602 struct genl_info *info)
11603{
11604 struct cfg80211_registered_device *rdev;
Johannes Berg89a54e42012-06-15 14:33:17 +020011605 struct wireless_dev *wdev;
Johannes Berg4c476992010-10-04 21:36:35 +020011606 struct net_device *dev;
Johannes Berg4c476992010-10-04 21:36:35 +020011607 bool rtnl = ops->internal_flags & NL80211_FLAG_NEED_RTNL;
11608
11609 if (rtnl)
11610 rtnl_lock();
11611
11612 if (ops->internal_flags & NL80211_FLAG_NEED_WIPHY) {
Johannes Berg4f7eff12012-06-15 14:14:22 +020011613 rdev = cfg80211_get_dev_from_info(genl_info_net(info), info);
Johannes Berg4c476992010-10-04 21:36:35 +020011614 if (IS_ERR(rdev)) {
11615 if (rtnl)
11616 rtnl_unlock();
11617 return PTR_ERR(rdev);
11618 }
11619 info->user_ptr[0] = rdev;
Johannes Berg1bf614e2012-06-15 15:23:36 +020011620 } else if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV ||
11621 ops->internal_flags & NL80211_FLAG_NEED_WDEV) {
Johannes Berg5fe231e2013-05-08 21:45:15 +020011622 ASSERT_RTNL();
11623
Johannes Berg89a54e42012-06-15 14:33:17 +020011624 wdev = __cfg80211_wdev_from_attrs(genl_info_net(info),
11625 info->attrs);
11626 if (IS_ERR(wdev)) {
Johannes Berg4c476992010-10-04 21:36:35 +020011627 if (rtnl)
11628 rtnl_unlock();
Johannes Berg89a54e42012-06-15 14:33:17 +020011629 return PTR_ERR(wdev);
Johannes Berg4c476992010-10-04 21:36:35 +020011630 }
Johannes Berg89a54e42012-06-15 14:33:17 +020011631
Johannes Berg89a54e42012-06-15 14:33:17 +020011632 dev = wdev->netdev;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080011633 rdev = wiphy_to_rdev(wdev->wiphy);
Johannes Berg89a54e42012-06-15 14:33:17 +020011634
Johannes Berg1bf614e2012-06-15 15:23:36 +020011635 if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV) {
11636 if (!dev) {
Johannes Berg1bf614e2012-06-15 15:23:36 +020011637 if (rtnl)
11638 rtnl_unlock();
11639 return -EINVAL;
11640 }
11641
11642 info->user_ptr[1] = dev;
11643 } else {
11644 info->user_ptr[1] = wdev;
Johannes Berg41265712010-10-04 21:14:05 +020011645 }
Johannes Berg89a54e42012-06-15 14:33:17 +020011646
Johannes Berg1bf614e2012-06-15 15:23:36 +020011647 if (dev) {
11648 if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP &&
11649 !netif_running(dev)) {
Johannes Berg1bf614e2012-06-15 15:23:36 +020011650 if (rtnl)
11651 rtnl_unlock();
11652 return -ENETDOWN;
11653 }
11654
11655 dev_hold(dev);
Johannes Berg98104fde2012-06-16 00:19:54 +020011656 } else if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP) {
Ayala Bekercb3b7d82016-09-20 17:31:13 +030011657 if (wdev->iftype == NL80211_IFTYPE_P2P_DEVICE &&
11658 !wdev->p2p_started) {
11659 if (rtnl)
11660 rtnl_unlock();
11661 return -ENETDOWN;
11662 }
11663 if (wdev->iftype == NL80211_IFTYPE_NAN &&
11664 !wdev->nan_started) {
Johannes Berg98104fde2012-06-16 00:19:54 +020011665 if (rtnl)
11666 rtnl_unlock();
11667 return -ENETDOWN;
11668 }
Johannes Berg1bf614e2012-06-15 15:23:36 +020011669 }
11670
Johannes Berg4c476992010-10-04 21:36:35 +020011671 info->user_ptr[0] = rdev;
Johannes Berg4c476992010-10-04 21:36:35 +020011672 }
11673
11674 return 0;
11675}
11676
Johannes Bergf84f7712013-11-14 17:14:45 +010011677static void nl80211_post_doit(const struct genl_ops *ops, struct sk_buff *skb,
Johannes Berg4c476992010-10-04 21:36:35 +020011678 struct genl_info *info)
11679{
Johannes Berg1bf614e2012-06-15 15:23:36 +020011680 if (info->user_ptr[1]) {
11681 if (ops->internal_flags & NL80211_FLAG_NEED_WDEV) {
11682 struct wireless_dev *wdev = info->user_ptr[1];
11683
11684 if (wdev->netdev)
11685 dev_put(wdev->netdev);
11686 } else {
11687 dev_put(info->user_ptr[1]);
11688 }
11689 }
Johannes Berg5393b912014-09-10 15:00:16 +030011690
Johannes Berg4c476992010-10-04 21:36:35 +020011691 if (ops->internal_flags & NL80211_FLAG_NEED_RTNL)
11692 rtnl_unlock();
Johannes Berg5393b912014-09-10 15:00:16 +030011693
11694 /* If needed, clear the netlink message payload from the SKB
11695 * as it might contain key data that shouldn't stick around on
11696 * the heap after the SKB is freed. The netlink message header
11697 * is still needed for further processing, so leave it intact.
11698 */
11699 if (ops->internal_flags & NL80211_FLAG_CLEAR_SKB) {
11700 struct nlmsghdr *nlh = nlmsg_hdr(skb);
11701
11702 memset(nlmsg_data(nlh), 0, nlmsg_len(nlh));
11703 }
Johannes Berg4c476992010-10-04 21:36:35 +020011704}
11705
Johannes Berg4534de82013-11-14 17:14:46 +010011706static const struct genl_ops nl80211_ops[] = {
Johannes Berg55682962007-09-20 13:09:35 -040011707 {
11708 .cmd = NL80211_CMD_GET_WIPHY,
11709 .doit = nl80211_get_wiphy,
11710 .dumpit = nl80211_dump_wiphy,
Johannes Berg86e8cf92013-06-19 10:57:22 +020011711 .done = nl80211_dump_wiphy_done,
Johannes Berg55682962007-09-20 13:09:35 -040011712 .policy = nl80211_policy,
11713 /* can be retrieved by unprivileged users */
Johannes Berg5fe231e2013-05-08 21:45:15 +020011714 .internal_flags = NL80211_FLAG_NEED_WIPHY |
11715 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -040011716 },
11717 {
11718 .cmd = NL80211_CMD_SET_WIPHY,
11719 .doit = nl80211_set_wiphy,
11720 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011721 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020011722 .internal_flags = NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -040011723 },
11724 {
11725 .cmd = NL80211_CMD_GET_INTERFACE,
11726 .doit = nl80211_get_interface,
11727 .dumpit = nl80211_dump_interface,
11728 .policy = nl80211_policy,
11729 /* can be retrieved by unprivileged users */
Johannes Berg5fe231e2013-05-08 21:45:15 +020011730 .internal_flags = NL80211_FLAG_NEED_WDEV |
11731 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -040011732 },
11733 {
11734 .cmd = NL80211_CMD_SET_INTERFACE,
11735 .doit = nl80211_set_interface,
11736 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011737 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020011738 .internal_flags = NL80211_FLAG_NEED_NETDEV |
11739 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -040011740 },
11741 {
11742 .cmd = NL80211_CMD_NEW_INTERFACE,
11743 .doit = nl80211_new_interface,
11744 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011745 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020011746 .internal_flags = NL80211_FLAG_NEED_WIPHY |
11747 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -040011748 },
11749 {
11750 .cmd = NL80211_CMD_DEL_INTERFACE,
11751 .doit = nl80211_del_interface,
11752 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011753 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg84efbb82012-06-16 00:00:26 +020011754 .internal_flags = NL80211_FLAG_NEED_WDEV |
Johannes Berg4c476992010-10-04 21:36:35 +020011755 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -040011756 },
Johannes Berg41ade002007-12-19 02:03:29 +010011757 {
11758 .cmd = NL80211_CMD_GET_KEY,
11759 .doit = nl80211_get_key,
11760 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011761 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020011762 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020011763 NL80211_FLAG_NEED_RTNL,
Johannes Berg41ade002007-12-19 02:03:29 +010011764 },
11765 {
11766 .cmd = NL80211_CMD_SET_KEY,
11767 .doit = nl80211_set_key,
11768 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011769 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020011770 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg5393b912014-09-10 15:00:16 +030011771 NL80211_FLAG_NEED_RTNL |
11772 NL80211_FLAG_CLEAR_SKB,
Johannes Berg41ade002007-12-19 02:03:29 +010011773 },
11774 {
11775 .cmd = NL80211_CMD_NEW_KEY,
11776 .doit = nl80211_new_key,
11777 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011778 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020011779 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg5393b912014-09-10 15:00:16 +030011780 NL80211_FLAG_NEED_RTNL |
11781 NL80211_FLAG_CLEAR_SKB,
Johannes Berg41ade002007-12-19 02:03:29 +010011782 },
11783 {
11784 .cmd = NL80211_CMD_DEL_KEY,
11785 .doit = nl80211_del_key,
11786 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011787 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020011788 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020011789 NL80211_FLAG_NEED_RTNL,
Johannes Berg41ade002007-12-19 02:03:29 +010011790 },
Johannes Berged1b6cc2007-12-19 02:03:32 +010011791 {
11792 .cmd = NL80211_CMD_SET_BEACON,
11793 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011794 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg88600202012-02-13 15:17:18 +010011795 .doit = nl80211_set_beacon,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020011796 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020011797 NL80211_FLAG_NEED_RTNL,
Johannes Berged1b6cc2007-12-19 02:03:32 +010011798 },
11799 {
Johannes Berg88600202012-02-13 15:17:18 +010011800 .cmd = NL80211_CMD_START_AP,
Johannes Berged1b6cc2007-12-19 02:03:32 +010011801 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011802 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg88600202012-02-13 15:17:18 +010011803 .doit = nl80211_start_ap,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020011804 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020011805 NL80211_FLAG_NEED_RTNL,
Johannes Berged1b6cc2007-12-19 02:03:32 +010011806 },
11807 {
Johannes Berg88600202012-02-13 15:17:18 +010011808 .cmd = NL80211_CMD_STOP_AP,
Johannes Berged1b6cc2007-12-19 02:03:32 +010011809 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011810 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg88600202012-02-13 15:17:18 +010011811 .doit = nl80211_stop_ap,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020011812 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020011813 NL80211_FLAG_NEED_RTNL,
Johannes Berged1b6cc2007-12-19 02:03:32 +010011814 },
Johannes Berg5727ef12007-12-19 02:03:34 +010011815 {
11816 .cmd = NL80211_CMD_GET_STATION,
11817 .doit = nl80211_get_station,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010011818 .dumpit = nl80211_dump_station,
Johannes Berg5727ef12007-12-19 02:03:34 +010011819 .policy = nl80211_policy,
Johannes Berg4c476992010-10-04 21:36:35 +020011820 .internal_flags = NL80211_FLAG_NEED_NETDEV |
11821 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +010011822 },
11823 {
11824 .cmd = NL80211_CMD_SET_STATION,
11825 .doit = nl80211_set_station,
11826 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011827 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020011828 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020011829 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +010011830 },
11831 {
11832 .cmd = NL80211_CMD_NEW_STATION,
11833 .doit = nl80211_new_station,
11834 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011835 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020011836 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020011837 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +010011838 },
11839 {
11840 .cmd = NL80211_CMD_DEL_STATION,
11841 .doit = nl80211_del_station,
11842 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011843 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020011844 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020011845 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +010011846 },
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010011847 {
11848 .cmd = NL80211_CMD_GET_MPATH,
11849 .doit = nl80211_get_mpath,
11850 .dumpit = nl80211_dump_mpath,
11851 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011852 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020011853 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020011854 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010011855 },
11856 {
Henning Rogge66be7d22014-09-12 08:58:49 +020011857 .cmd = NL80211_CMD_GET_MPP,
11858 .doit = nl80211_get_mpp,
11859 .dumpit = nl80211_dump_mpp,
11860 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011861 .flags = GENL_UNS_ADMIN_PERM,
Henning Rogge66be7d22014-09-12 08:58:49 +020011862 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
11863 NL80211_FLAG_NEED_RTNL,
11864 },
11865 {
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010011866 .cmd = NL80211_CMD_SET_MPATH,
11867 .doit = nl80211_set_mpath,
11868 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011869 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020011870 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020011871 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010011872 },
11873 {
11874 .cmd = NL80211_CMD_NEW_MPATH,
11875 .doit = nl80211_new_mpath,
11876 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011877 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020011878 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020011879 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010011880 },
11881 {
11882 .cmd = NL80211_CMD_DEL_MPATH,
11883 .doit = nl80211_del_mpath,
11884 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011885 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020011886 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020011887 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010011888 },
Jouni Malinen9f1ba902008-08-07 20:07:01 +030011889 {
11890 .cmd = NL80211_CMD_SET_BSS,
11891 .doit = nl80211_set_bss,
11892 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011893 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020011894 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020011895 NL80211_FLAG_NEED_RTNL,
Jouni Malinen9f1ba902008-08-07 20:07:01 +030011896 },
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -070011897 {
Luis R. Rodriguezf1303472009-01-30 09:26:42 -080011898 .cmd = NL80211_CMD_GET_REG,
Arik Nemtsovad30ca22014-12-15 19:25:59 +020011899 .doit = nl80211_get_reg_do,
11900 .dumpit = nl80211_get_reg_dump,
Luis R. Rodriguezf1303472009-01-30 09:26:42 -080011901 .policy = nl80211_policy,
Johannes Berg5fe231e2013-05-08 21:45:15 +020011902 .internal_flags = NL80211_FLAG_NEED_RTNL,
Luis R. Rodriguezf1303472009-01-30 09:26:42 -080011903 /* can be retrieved by unprivileged users */
11904 },
Johannes Bergb6863032015-10-15 09:25:18 +020011905#ifdef CONFIG_CFG80211_CRDA_SUPPORT
Luis R. Rodriguezf1303472009-01-30 09:26:42 -080011906 {
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -070011907 .cmd = NL80211_CMD_SET_REG,
11908 .doit = nl80211_set_reg,
11909 .policy = nl80211_policy,
11910 .flags = GENL_ADMIN_PERM,
Johannes Berg5fe231e2013-05-08 21:45:15 +020011911 .internal_flags = NL80211_FLAG_NEED_RTNL,
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -070011912 },
Johannes Bergb6863032015-10-15 09:25:18 +020011913#endif
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -070011914 {
11915 .cmd = NL80211_CMD_REQ_SET_REG,
11916 .doit = nl80211_req_set_reg,
11917 .policy = nl80211_policy,
11918 .flags = GENL_ADMIN_PERM,
11919 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -070011920 {
Javier Cardona24bdd9f2010-12-16 17:37:48 -080011921 .cmd = NL80211_CMD_GET_MESH_CONFIG,
11922 .doit = nl80211_get_mesh_config,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -070011923 .policy = nl80211_policy,
11924 /* can be retrieved by unprivileged users */
Johannes Berg2b5f8b02012-04-02 10:51:55 +020011925 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020011926 NL80211_FLAG_NEED_RTNL,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -070011927 },
11928 {
Javier Cardona24bdd9f2010-12-16 17:37:48 -080011929 .cmd = NL80211_CMD_SET_MESH_CONFIG,
11930 .doit = nl80211_update_mesh_config,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -070011931 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011932 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg29cbe682010-12-03 09:20:44 +010011933 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020011934 NL80211_FLAG_NEED_RTNL,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -070011935 },
Jouni Malinen9aed3cc2009-01-13 16:03:29 +020011936 {
Johannes Berg2a519312009-02-10 21:25:55 +010011937 .cmd = NL80211_CMD_TRIGGER_SCAN,
11938 .doit = nl80211_trigger_scan,
11939 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011940 .flags = GENL_UNS_ADMIN_PERM,
Johannes Bergfd014282012-06-18 19:17:03 +020011941 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020011942 NL80211_FLAG_NEED_RTNL,
Johannes Berg2a519312009-02-10 21:25:55 +010011943 },
11944 {
Vidyullatha Kanchanapally91d3ab42015-10-30 19:14:49 +053011945 .cmd = NL80211_CMD_ABORT_SCAN,
11946 .doit = nl80211_abort_scan,
11947 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011948 .flags = GENL_UNS_ADMIN_PERM,
Vidyullatha Kanchanapally91d3ab42015-10-30 19:14:49 +053011949 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
11950 NL80211_FLAG_NEED_RTNL,
11951 },
11952 {
Johannes Berg2a519312009-02-10 21:25:55 +010011953 .cmd = NL80211_CMD_GET_SCAN,
11954 .policy = nl80211_policy,
11955 .dumpit = nl80211_dump_scan,
11956 },
Jouni Malinen636a5d32009-03-19 13:39:22 +020011957 {
Luciano Coelho807f8a82011-05-11 17:09:35 +030011958 .cmd = NL80211_CMD_START_SCHED_SCAN,
11959 .doit = nl80211_start_sched_scan,
11960 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011961 .flags = GENL_UNS_ADMIN_PERM,
Luciano Coelho807f8a82011-05-11 17:09:35 +030011962 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
11963 NL80211_FLAG_NEED_RTNL,
11964 },
11965 {
11966 .cmd = NL80211_CMD_STOP_SCHED_SCAN,
11967 .doit = nl80211_stop_sched_scan,
11968 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011969 .flags = GENL_UNS_ADMIN_PERM,
Luciano Coelho807f8a82011-05-11 17:09:35 +030011970 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
11971 NL80211_FLAG_NEED_RTNL,
11972 },
11973 {
Jouni Malinen636a5d32009-03-19 13:39:22 +020011974 .cmd = NL80211_CMD_AUTHENTICATE,
11975 .doit = nl80211_authenticate,
11976 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011977 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020011978 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg5393b912014-09-10 15:00:16 +030011979 NL80211_FLAG_NEED_RTNL |
11980 NL80211_FLAG_CLEAR_SKB,
Jouni Malinen636a5d32009-03-19 13:39:22 +020011981 },
11982 {
11983 .cmd = NL80211_CMD_ASSOCIATE,
11984 .doit = nl80211_associate,
11985 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011986 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020011987 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020011988 NL80211_FLAG_NEED_RTNL,
Jouni Malinen636a5d32009-03-19 13:39:22 +020011989 },
11990 {
11991 .cmd = NL80211_CMD_DEAUTHENTICATE,
11992 .doit = nl80211_deauthenticate,
11993 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011994 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020011995 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020011996 NL80211_FLAG_NEED_RTNL,
Jouni Malinen636a5d32009-03-19 13:39:22 +020011997 },
11998 {
11999 .cmd = NL80211_CMD_DISASSOCIATE,
12000 .doit = nl80211_disassociate,
12001 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012002 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020012003 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020012004 NL80211_FLAG_NEED_RTNL,
Jouni Malinen636a5d32009-03-19 13:39:22 +020012005 },
Johannes Berg04a773a2009-04-19 21:24:32 +020012006 {
12007 .cmd = NL80211_CMD_JOIN_IBSS,
12008 .doit = nl80211_join_ibss,
12009 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012010 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020012011 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020012012 NL80211_FLAG_NEED_RTNL,
Johannes Berg04a773a2009-04-19 21:24:32 +020012013 },
12014 {
12015 .cmd = NL80211_CMD_LEAVE_IBSS,
12016 .doit = nl80211_leave_ibss,
12017 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012018 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020012019 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020012020 NL80211_FLAG_NEED_RTNL,
Johannes Berg04a773a2009-04-19 21:24:32 +020012021 },
Johannes Bergaff89a92009-07-01 21:26:51 +020012022#ifdef CONFIG_NL80211_TESTMODE
12023 {
12024 .cmd = NL80211_CMD_TESTMODE,
12025 .doit = nl80211_testmode_do,
Wey-Yi Guy71063f02011-05-20 09:05:54 -070012026 .dumpit = nl80211_testmode_dump,
Johannes Bergaff89a92009-07-01 21:26:51 +020012027 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012028 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020012029 .internal_flags = NL80211_FLAG_NEED_WIPHY |
12030 NL80211_FLAG_NEED_RTNL,
Johannes Bergaff89a92009-07-01 21:26:51 +020012031 },
12032#endif
Samuel Ortizb23aa672009-07-01 21:26:54 +020012033 {
12034 .cmd = NL80211_CMD_CONNECT,
12035 .doit = nl80211_connect,
12036 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012037 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020012038 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020012039 NL80211_FLAG_NEED_RTNL,
Samuel Ortizb23aa672009-07-01 21:26:54 +020012040 },
12041 {
12042 .cmd = NL80211_CMD_DISCONNECT,
12043 .doit = nl80211_disconnect,
12044 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012045 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020012046 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020012047 NL80211_FLAG_NEED_RTNL,
Samuel Ortizb23aa672009-07-01 21:26:54 +020012048 },
Johannes Berg463d0182009-07-14 00:33:35 +020012049 {
12050 .cmd = NL80211_CMD_SET_WIPHY_NETNS,
12051 .doit = nl80211_wiphy_netns,
12052 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012053 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020012054 .internal_flags = NL80211_FLAG_NEED_WIPHY |
12055 NL80211_FLAG_NEED_RTNL,
Johannes Berg463d0182009-07-14 00:33:35 +020012056 },
Holger Schurig61fa7132009-11-11 12:25:40 +010012057 {
12058 .cmd = NL80211_CMD_GET_SURVEY,
12059 .policy = nl80211_policy,
12060 .dumpit = nl80211_dump_survey,
12061 },
Samuel Ortiz67fbb162009-11-24 23:59:15 +010012062 {
12063 .cmd = NL80211_CMD_SET_PMKSA,
12064 .doit = nl80211_setdel_pmksa,
12065 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012066 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020012067 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020012068 NL80211_FLAG_NEED_RTNL,
Samuel Ortiz67fbb162009-11-24 23:59:15 +010012069 },
12070 {
12071 .cmd = NL80211_CMD_DEL_PMKSA,
12072 .doit = nl80211_setdel_pmksa,
12073 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012074 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020012075 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020012076 NL80211_FLAG_NEED_RTNL,
Samuel Ortiz67fbb162009-11-24 23:59:15 +010012077 },
12078 {
12079 .cmd = NL80211_CMD_FLUSH_PMKSA,
12080 .doit = nl80211_flush_pmksa,
12081 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012082 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020012083 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020012084 NL80211_FLAG_NEED_RTNL,
Samuel Ortiz67fbb162009-11-24 23:59:15 +010012085 },
Jouni Malinen9588bbd2009-12-23 13:15:41 +010012086 {
12087 .cmd = NL80211_CMD_REMAIN_ON_CHANNEL,
12088 .doit = nl80211_remain_on_channel,
12089 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012090 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +020012091 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020012092 NL80211_FLAG_NEED_RTNL,
Jouni Malinen9588bbd2009-12-23 13:15:41 +010012093 },
12094 {
12095 .cmd = NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL,
12096 .doit = nl80211_cancel_remain_on_channel,
12097 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012098 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +020012099 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020012100 NL80211_FLAG_NEED_RTNL,
Jouni Malinen9588bbd2009-12-23 13:15:41 +010012101 },
Jouni Malinen13ae75b2009-12-29 12:59:45 +020012102 {
12103 .cmd = NL80211_CMD_SET_TX_BITRATE_MASK,
12104 .doit = nl80211_set_tx_bitrate_mask,
12105 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012106 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020012107 .internal_flags = NL80211_FLAG_NEED_NETDEV |
12108 NL80211_FLAG_NEED_RTNL,
Jouni Malinen13ae75b2009-12-29 12:59:45 +020012109 },
Jouni Malinen026331c2010-02-15 12:53:10 +020012110 {
Johannes Berg2e161f782010-08-12 15:38:38 +020012111 .cmd = NL80211_CMD_REGISTER_FRAME,
12112 .doit = nl80211_register_mgmt,
Jouni Malinen026331c2010-02-15 12:53:10 +020012113 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012114 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +020012115 .internal_flags = NL80211_FLAG_NEED_WDEV |
Johannes Berg4c476992010-10-04 21:36:35 +020012116 NL80211_FLAG_NEED_RTNL,
Jouni Malinen026331c2010-02-15 12:53:10 +020012117 },
12118 {
Johannes Berg2e161f782010-08-12 15:38:38 +020012119 .cmd = NL80211_CMD_FRAME,
12120 .doit = nl80211_tx_mgmt,
Jouni Malinen026331c2010-02-15 12:53:10 +020012121 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012122 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +020012123 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020012124 NL80211_FLAG_NEED_RTNL,
Jouni Malinen026331c2010-02-15 12:53:10 +020012125 },
Kalle Valoffb9eb32010-02-17 17:58:10 +020012126 {
Johannes Bergf7ca38d2010-11-25 10:02:29 +010012127 .cmd = NL80211_CMD_FRAME_WAIT_CANCEL,
12128 .doit = nl80211_tx_mgmt_cancel_wait,
12129 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012130 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +020012131 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Bergf7ca38d2010-11-25 10:02:29 +010012132 NL80211_FLAG_NEED_RTNL,
12133 },
12134 {
Kalle Valoffb9eb32010-02-17 17:58:10 +020012135 .cmd = NL80211_CMD_SET_POWER_SAVE,
12136 .doit = nl80211_set_power_save,
12137 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012138 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020012139 .internal_flags = NL80211_FLAG_NEED_NETDEV |
12140 NL80211_FLAG_NEED_RTNL,
Kalle Valoffb9eb32010-02-17 17:58:10 +020012141 },
12142 {
12143 .cmd = NL80211_CMD_GET_POWER_SAVE,
12144 .doit = nl80211_get_power_save,
12145 .policy = nl80211_policy,
12146 /* can be retrieved by unprivileged users */
Johannes Berg4c476992010-10-04 21:36:35 +020012147 .internal_flags = NL80211_FLAG_NEED_NETDEV |
12148 NL80211_FLAG_NEED_RTNL,
Kalle Valoffb9eb32010-02-17 17:58:10 +020012149 },
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020012150 {
12151 .cmd = NL80211_CMD_SET_CQM,
12152 .doit = nl80211_set_cqm,
12153 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012154 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020012155 .internal_flags = NL80211_FLAG_NEED_NETDEV |
12156 NL80211_FLAG_NEED_RTNL,
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020012157 },
Johannes Bergf444de02010-05-05 15:25:02 +020012158 {
12159 .cmd = NL80211_CMD_SET_CHANNEL,
12160 .doit = nl80211_set_channel,
12161 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012162 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020012163 .internal_flags = NL80211_FLAG_NEED_NETDEV |
12164 NL80211_FLAG_NEED_RTNL,
Johannes Bergf444de02010-05-05 15:25:02 +020012165 },
Bill Jordane8347eb2010-10-01 13:54:28 -040012166 {
12167 .cmd = NL80211_CMD_SET_WDS_PEER,
12168 .doit = nl80211_set_wds_peer,
12169 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012170 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg43b19952010-10-07 13:10:30 +020012171 .internal_flags = NL80211_FLAG_NEED_NETDEV |
12172 NL80211_FLAG_NEED_RTNL,
Bill Jordane8347eb2010-10-01 13:54:28 -040012173 },
Johannes Berg29cbe682010-12-03 09:20:44 +010012174 {
12175 .cmd = NL80211_CMD_JOIN_MESH,
12176 .doit = nl80211_join_mesh,
12177 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012178 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg29cbe682010-12-03 09:20:44 +010012179 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
12180 NL80211_FLAG_NEED_RTNL,
12181 },
12182 {
12183 .cmd = NL80211_CMD_LEAVE_MESH,
12184 .doit = nl80211_leave_mesh,
12185 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012186 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg29cbe682010-12-03 09:20:44 +010012187 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
12188 NL80211_FLAG_NEED_RTNL,
12189 },
Rostislav Lisovy6e0bd6c2014-11-03 10:33:18 +010012190 {
12191 .cmd = NL80211_CMD_JOIN_OCB,
12192 .doit = nl80211_join_ocb,
12193 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012194 .flags = GENL_UNS_ADMIN_PERM,
Rostislav Lisovy6e0bd6c2014-11-03 10:33:18 +010012195 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
12196 NL80211_FLAG_NEED_RTNL,
12197 },
12198 {
12199 .cmd = NL80211_CMD_LEAVE_OCB,
12200 .doit = nl80211_leave_ocb,
12201 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012202 .flags = GENL_UNS_ADMIN_PERM,
Rostislav Lisovy6e0bd6c2014-11-03 10:33:18 +010012203 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
12204 NL80211_FLAG_NEED_RTNL,
12205 },
Johannes Bergdfb89c52012-06-27 09:23:48 +020012206#ifdef CONFIG_PM
Johannes Bergff1b6e62011-05-04 15:37:28 +020012207 {
12208 .cmd = NL80211_CMD_GET_WOWLAN,
12209 .doit = nl80211_get_wowlan,
12210 .policy = nl80211_policy,
12211 /* can be retrieved by unprivileged users */
12212 .internal_flags = NL80211_FLAG_NEED_WIPHY |
12213 NL80211_FLAG_NEED_RTNL,
12214 },
12215 {
12216 .cmd = NL80211_CMD_SET_WOWLAN,
12217 .doit = nl80211_set_wowlan,
12218 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012219 .flags = GENL_UNS_ADMIN_PERM,
Johannes Bergff1b6e62011-05-04 15:37:28 +020012220 .internal_flags = NL80211_FLAG_NEED_WIPHY |
12221 NL80211_FLAG_NEED_RTNL,
12222 },
Johannes Bergdfb89c52012-06-27 09:23:48 +020012223#endif
Johannes Berge5497d72011-07-05 16:35:40 +020012224 {
12225 .cmd = NL80211_CMD_SET_REKEY_OFFLOAD,
12226 .doit = nl80211_set_rekey_data,
12227 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012228 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berge5497d72011-07-05 16:35:40 +020012229 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg5393b912014-09-10 15:00:16 +030012230 NL80211_FLAG_NEED_RTNL |
12231 NL80211_FLAG_CLEAR_SKB,
Johannes Berge5497d72011-07-05 16:35:40 +020012232 },
Arik Nemtsov109086c2011-09-28 14:12:50 +030012233 {
12234 .cmd = NL80211_CMD_TDLS_MGMT,
12235 .doit = nl80211_tdls_mgmt,
12236 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012237 .flags = GENL_UNS_ADMIN_PERM,
Arik Nemtsov109086c2011-09-28 14:12:50 +030012238 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
12239 NL80211_FLAG_NEED_RTNL,
12240 },
12241 {
12242 .cmd = NL80211_CMD_TDLS_OPER,
12243 .doit = nl80211_tdls_oper,
12244 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012245 .flags = GENL_UNS_ADMIN_PERM,
Arik Nemtsov109086c2011-09-28 14:12:50 +030012246 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
12247 NL80211_FLAG_NEED_RTNL,
12248 },
Johannes Berg28946da2011-11-04 11:18:12 +010012249 {
12250 .cmd = NL80211_CMD_UNEXPECTED_FRAME,
12251 .doit = nl80211_register_unexpected_frame,
12252 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012253 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg28946da2011-11-04 11:18:12 +010012254 .internal_flags = NL80211_FLAG_NEED_NETDEV |
12255 NL80211_FLAG_NEED_RTNL,
12256 },
Johannes Berg7f6cf312011-11-04 11:18:15 +010012257 {
12258 .cmd = NL80211_CMD_PROBE_CLIENT,
12259 .doit = nl80211_probe_client,
12260 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012261 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020012262 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg7f6cf312011-11-04 11:18:15 +010012263 NL80211_FLAG_NEED_RTNL,
12264 },
Johannes Berg5e760232011-11-04 11:18:17 +010012265 {
12266 .cmd = NL80211_CMD_REGISTER_BEACONS,
12267 .doit = nl80211_register_beacons,
12268 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012269 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg5e760232011-11-04 11:18:17 +010012270 .internal_flags = NL80211_FLAG_NEED_WIPHY |
12271 NL80211_FLAG_NEED_RTNL,
12272 },
Simon Wunderlich1d9d9212011-11-18 14:20:43 +010012273 {
12274 .cmd = NL80211_CMD_SET_NOACK_MAP,
12275 .doit = nl80211_set_noack_map,
12276 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012277 .flags = GENL_UNS_ADMIN_PERM,
Simon Wunderlich1d9d9212011-11-18 14:20:43 +010012278 .internal_flags = NL80211_FLAG_NEED_NETDEV |
12279 NL80211_FLAG_NEED_RTNL,
12280 },
Johannes Berg98104fde2012-06-16 00:19:54 +020012281 {
12282 .cmd = NL80211_CMD_START_P2P_DEVICE,
12283 .doit = nl80211_start_p2p_device,
12284 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012285 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg98104fde2012-06-16 00:19:54 +020012286 .internal_flags = NL80211_FLAG_NEED_WDEV |
12287 NL80211_FLAG_NEED_RTNL,
12288 },
12289 {
12290 .cmd = NL80211_CMD_STOP_P2P_DEVICE,
12291 .doit = nl80211_stop_p2p_device,
12292 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012293 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg98104fde2012-06-16 00:19:54 +020012294 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
12295 NL80211_FLAG_NEED_RTNL,
12296 },
Antonio Quartullif4e583c2012-11-02 13:27:48 +010012297 {
Ayala Bekercb3b7d82016-09-20 17:31:13 +030012298 .cmd = NL80211_CMD_START_NAN,
12299 .doit = nl80211_start_nan,
12300 .policy = nl80211_policy,
12301 .flags = GENL_ADMIN_PERM,
12302 .internal_flags = NL80211_FLAG_NEED_WDEV |
12303 NL80211_FLAG_NEED_RTNL,
12304 },
12305 {
12306 .cmd = NL80211_CMD_STOP_NAN,
12307 .doit = nl80211_stop_nan,
12308 .policy = nl80211_policy,
12309 .flags = GENL_ADMIN_PERM,
12310 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
12311 NL80211_FLAG_NEED_RTNL,
12312 },
12313 {
Ayala Bekera442b762016-09-20 17:31:15 +030012314 .cmd = NL80211_CMD_ADD_NAN_FUNCTION,
12315 .doit = nl80211_nan_add_func,
12316 .policy = nl80211_policy,
12317 .flags = GENL_ADMIN_PERM,
12318 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
12319 NL80211_FLAG_NEED_RTNL,
12320 },
12321 {
12322 .cmd = NL80211_CMD_DEL_NAN_FUNCTION,
12323 .doit = nl80211_nan_del_func,
12324 .policy = nl80211_policy,
12325 .flags = GENL_ADMIN_PERM,
12326 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
12327 NL80211_FLAG_NEED_RTNL,
12328 },
12329 {
Ayala Bekera5a9dcf2016-09-20 17:31:16 +030012330 .cmd = NL80211_CMD_CHANGE_NAN_CONFIG,
12331 .doit = nl80211_nan_change_config,
12332 .policy = nl80211_policy,
12333 .flags = GENL_ADMIN_PERM,
12334 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
12335 NL80211_FLAG_NEED_RTNL,
12336 },
12337 {
Antonio Quartullif4e583c2012-11-02 13:27:48 +010012338 .cmd = NL80211_CMD_SET_MCAST_RATE,
12339 .doit = nl80211_set_mcast_rate,
12340 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012341 .flags = GENL_UNS_ADMIN_PERM,
Antonio Quartullif4e583c2012-11-02 13:27:48 +010012342 .internal_flags = NL80211_FLAG_NEED_NETDEV |
12343 NL80211_FLAG_NEED_RTNL,
12344 },
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +053012345 {
12346 .cmd = NL80211_CMD_SET_MAC_ACL,
12347 .doit = nl80211_set_mac_acl,
12348 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012349 .flags = GENL_UNS_ADMIN_PERM,
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +053012350 .internal_flags = NL80211_FLAG_NEED_NETDEV |
12351 NL80211_FLAG_NEED_RTNL,
12352 },
Simon Wunderlich04f39042013-02-08 18:16:19 +010012353 {
12354 .cmd = NL80211_CMD_RADAR_DETECT,
12355 .doit = nl80211_start_radar_detection,
12356 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012357 .flags = GENL_UNS_ADMIN_PERM,
Simon Wunderlich04f39042013-02-08 18:16:19 +010012358 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
12359 NL80211_FLAG_NEED_RTNL,
12360 },
Johannes Berg3713b4e2013-02-14 16:19:38 +010012361 {
12362 .cmd = NL80211_CMD_GET_PROTOCOL_FEATURES,
12363 .doit = nl80211_get_protocol_features,
12364 .policy = nl80211_policy,
12365 },
Jouni Malinen355199e2013-02-27 17:14:27 +020012366 {
12367 .cmd = NL80211_CMD_UPDATE_FT_IES,
12368 .doit = nl80211_update_ft_ies,
12369 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012370 .flags = GENL_UNS_ADMIN_PERM,
Jouni Malinen355199e2013-02-27 17:14:27 +020012371 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
12372 NL80211_FLAG_NEED_RTNL,
12373 },
Arend van Spriel5de17982013-04-18 15:49:00 +020012374 {
12375 .cmd = NL80211_CMD_CRIT_PROTOCOL_START,
12376 .doit = nl80211_crit_protocol_start,
12377 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012378 .flags = GENL_UNS_ADMIN_PERM,
Arend van Spriel5de17982013-04-18 15:49:00 +020012379 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
12380 NL80211_FLAG_NEED_RTNL,
12381 },
12382 {
12383 .cmd = NL80211_CMD_CRIT_PROTOCOL_STOP,
12384 .doit = nl80211_crit_protocol_stop,
12385 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012386 .flags = GENL_UNS_ADMIN_PERM,
Arend van Spriel5de17982013-04-18 15:49:00 +020012387 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
12388 NL80211_FLAG_NEED_RTNL,
Amitkumar Karwarbe29b99a2013-06-28 11:51:26 -070012389 },
12390 {
12391 .cmd = NL80211_CMD_GET_COALESCE,
12392 .doit = nl80211_get_coalesce,
12393 .policy = nl80211_policy,
12394 .internal_flags = NL80211_FLAG_NEED_WIPHY |
12395 NL80211_FLAG_NEED_RTNL,
12396 },
12397 {
12398 .cmd = NL80211_CMD_SET_COALESCE,
12399 .doit = nl80211_set_coalesce,
12400 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012401 .flags = GENL_UNS_ADMIN_PERM,
Amitkumar Karwarbe29b99a2013-06-28 11:51:26 -070012402 .internal_flags = NL80211_FLAG_NEED_WIPHY |
12403 NL80211_FLAG_NEED_RTNL,
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +020012404 },
12405 {
12406 .cmd = NL80211_CMD_CHANNEL_SWITCH,
12407 .doit = nl80211_channel_switch,
12408 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012409 .flags = GENL_UNS_ADMIN_PERM,
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +020012410 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
12411 NL80211_FLAG_NEED_RTNL,
12412 },
Johannes Bergad7e7182013-11-13 13:37:47 +010012413 {
12414 .cmd = NL80211_CMD_VENDOR,
12415 .doit = nl80211_vendor_cmd,
Johannes Berg7bdbe402015-08-15 22:39:49 +030012416 .dumpit = nl80211_vendor_cmd_dump,
Johannes Bergad7e7182013-11-13 13:37:47 +010012417 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012418 .flags = GENL_UNS_ADMIN_PERM,
Johannes Bergad7e7182013-11-13 13:37:47 +010012419 .internal_flags = NL80211_FLAG_NEED_WIPHY |
12420 NL80211_FLAG_NEED_RTNL,
12421 },
Kyeyoon Parkfa9ffc72013-12-16 23:01:30 -080012422 {
12423 .cmd = NL80211_CMD_SET_QOS_MAP,
12424 .doit = nl80211_set_qos_map,
12425 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012426 .flags = GENL_UNS_ADMIN_PERM,
Kyeyoon Parkfa9ffc72013-12-16 23:01:30 -080012427 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
12428 NL80211_FLAG_NEED_RTNL,
12429 },
Johannes Berg960d01a2014-09-09 22:55:35 +030012430 {
12431 .cmd = NL80211_CMD_ADD_TX_TS,
12432 .doit = nl80211_add_tx_ts,
12433 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012434 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg960d01a2014-09-09 22:55:35 +030012435 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
12436 NL80211_FLAG_NEED_RTNL,
12437 },
12438 {
12439 .cmd = NL80211_CMD_DEL_TX_TS,
12440 .doit = nl80211_del_tx_ts,
12441 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012442 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg960d01a2014-09-09 22:55:35 +030012443 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
12444 NL80211_FLAG_NEED_RTNL,
12445 },
Arik Nemtsov1057d352014-11-19 12:54:26 +020012446 {
12447 .cmd = NL80211_CMD_TDLS_CHANNEL_SWITCH,
12448 .doit = nl80211_tdls_channel_switch,
12449 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012450 .flags = GENL_UNS_ADMIN_PERM,
Arik Nemtsov1057d352014-11-19 12:54:26 +020012451 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
12452 NL80211_FLAG_NEED_RTNL,
12453 },
12454 {
12455 .cmd = NL80211_CMD_TDLS_CANCEL_CHANNEL_SWITCH,
12456 .doit = nl80211_tdls_cancel_channel_switch,
12457 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012458 .flags = GENL_UNS_ADMIN_PERM,
Arik Nemtsov1057d352014-11-19 12:54:26 +020012459 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
12460 NL80211_FLAG_NEED_RTNL,
12461 },
Johannes Berg55682962007-09-20 13:09:35 -040012462};
Jouni Malinen9588bbd2009-12-23 13:15:41 +010012463
Johannes Berg55682962007-09-20 13:09:35 -040012464/* notification functions */
12465
Johannes Berg3bb20552014-05-26 13:52:25 +020012466void nl80211_notify_wiphy(struct cfg80211_registered_device *rdev,
12467 enum nl80211_commands cmd)
Johannes Berg55682962007-09-20 13:09:35 -040012468{
12469 struct sk_buff *msg;
Johannes Berg86e8cf92013-06-19 10:57:22 +020012470 struct nl80211_dump_wiphy_state state = {};
Johannes Berg55682962007-09-20 13:09:35 -040012471
Johannes Berg3bb20552014-05-26 13:52:25 +020012472 WARN_ON(cmd != NL80211_CMD_NEW_WIPHY &&
12473 cmd != NL80211_CMD_DEL_WIPHY);
12474
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -070012475 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -040012476 if (!msg)
12477 return;
12478
Johannes Berg3bb20552014-05-26 13:52:25 +020012479 if (nl80211_send_wiphy(rdev, cmd, msg, 0, 0, 0, &state) < 0) {
Johannes Berg55682962007-09-20 13:09:35 -040012480 nlmsg_free(msg);
12481 return;
12482 }
12483
Johannes Berg68eb5502013-11-19 15:19:38 +010012484 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010012485 NL80211_MCGRP_CONFIG, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -040012486}
12487
Denis Kenzior896ff062016-08-03 16:58:33 -050012488void nl80211_notify_iface(struct cfg80211_registered_device *rdev,
12489 struct wireless_dev *wdev,
12490 enum nl80211_commands cmd)
12491{
12492 struct sk_buff *msg;
12493
12494 WARN_ON(cmd != NL80211_CMD_NEW_INTERFACE &&
12495 cmd != NL80211_CMD_DEL_INTERFACE);
12496
12497 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
12498 if (!msg)
12499 return;
12500
12501 if (nl80211_send_iface(msg, 0, 0, 0, rdev, wdev,
12502 cmd == NL80211_CMD_DEL_INTERFACE) < 0) {
12503 nlmsg_free(msg);
12504 return;
12505 }
12506
12507 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
12508 NL80211_MCGRP_CONFIG, GFP_KERNEL);
12509}
12510
Johannes Berg362a4152009-05-24 16:43:15 +020012511static int nl80211_add_scan_req(struct sk_buff *msg,
12512 struct cfg80211_registered_device *rdev)
12513{
12514 struct cfg80211_scan_request *req = rdev->scan_req;
12515 struct nlattr *nest;
12516 int i;
12517
12518 if (WARN_ON(!req))
12519 return 0;
12520
12521 nest = nla_nest_start(msg, NL80211_ATTR_SCAN_SSIDS);
12522 if (!nest)
12523 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -040012524 for (i = 0; i < req->n_ssids; i++) {
12525 if (nla_put(msg, i, req->ssids[i].ssid_len, req->ssids[i].ssid))
12526 goto nla_put_failure;
12527 }
Johannes Berg362a4152009-05-24 16:43:15 +020012528 nla_nest_end(msg, nest);
12529
12530 nest = nla_nest_start(msg, NL80211_ATTR_SCAN_FREQUENCIES);
12531 if (!nest)
12532 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -040012533 for (i = 0; i < req->n_channels; i++) {
12534 if (nla_put_u32(msg, i, req->channels[i]->center_freq))
12535 goto nla_put_failure;
12536 }
Johannes Berg362a4152009-05-24 16:43:15 +020012537 nla_nest_end(msg, nest);
12538
David S. Miller9360ffd2012-03-29 04:41:26 -040012539 if (req->ie &&
12540 nla_put(msg, NL80211_ATTR_IE, req->ie_len, req->ie))
12541 goto nla_put_failure;
Johannes Berg362a4152009-05-24 16:43:15 +020012542
Johannes Bergae917c92013-10-25 11:05:22 +020012543 if (req->flags &&
12544 nla_put_u32(msg, NL80211_ATTR_SCAN_FLAGS, req->flags))
12545 goto nla_put_failure;
Sam Lefflered4737712012-10-11 21:03:31 -070012546
Avraham Stern1d762502016-07-05 17:10:13 +030012547 if (req->info.scan_start_tsf &&
12548 (nla_put_u64_64bit(msg, NL80211_ATTR_SCAN_START_TIME_TSF,
12549 req->info.scan_start_tsf, NL80211_BSS_PAD) ||
12550 nla_put(msg, NL80211_ATTR_SCAN_START_TIME_TSF_BSSID, ETH_ALEN,
12551 req->info.tsf_bssid)))
12552 goto nla_put_failure;
12553
Johannes Berg362a4152009-05-24 16:43:15 +020012554 return 0;
12555 nla_put_failure:
12556 return -ENOBUFS;
12557}
12558
Johannes Berga538e2d2009-06-16 19:56:42 +020012559static int nl80211_send_scan_msg(struct sk_buff *msg,
12560 struct cfg80211_registered_device *rdev,
Johannes Bergfd014282012-06-18 19:17:03 +020012561 struct wireless_dev *wdev,
Eric W. Biederman15e47302012-09-07 20:12:54 +000012562 u32 portid, u32 seq, int flags,
Johannes Berga538e2d2009-06-16 19:56:42 +020012563 u32 cmd)
Johannes Berg2a519312009-02-10 21:25:55 +010012564{
12565 void *hdr;
12566
Eric W. Biederman15e47302012-09-07 20:12:54 +000012567 hdr = nl80211hdr_put(msg, portid, seq, flags, cmd);
Johannes Berg2a519312009-02-10 21:25:55 +010012568 if (!hdr)
12569 return -1;
12570
David S. Miller9360ffd2012-03-29 04:41:26 -040012571 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Bergfd014282012-06-18 19:17:03 +020012572 (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
12573 wdev->netdev->ifindex)) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020012574 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
12575 NL80211_ATTR_PAD))
David S. Miller9360ffd2012-03-29 04:41:26 -040012576 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +010012577
Johannes Berg362a4152009-05-24 16:43:15 +020012578 /* ignore errors and send incomplete event anyway */
12579 nl80211_add_scan_req(msg, rdev);
Johannes Berg2a519312009-02-10 21:25:55 +010012580
Johannes Berg053c0952015-01-16 22:09:00 +010012581 genlmsg_end(msg, hdr);
12582 return 0;
Johannes Berg2a519312009-02-10 21:25:55 +010012583
12584 nla_put_failure:
12585 genlmsg_cancel(msg, hdr);
12586 return -EMSGSIZE;
12587}
12588
Luciano Coelho807f8a82011-05-11 17:09:35 +030012589static int
12590nl80211_send_sched_scan_msg(struct sk_buff *msg,
12591 struct cfg80211_registered_device *rdev,
12592 struct net_device *netdev,
Eric W. Biederman15e47302012-09-07 20:12:54 +000012593 u32 portid, u32 seq, int flags, u32 cmd)
Luciano Coelho807f8a82011-05-11 17:09:35 +030012594{
12595 void *hdr;
12596
Eric W. Biederman15e47302012-09-07 20:12:54 +000012597 hdr = nl80211hdr_put(msg, portid, seq, flags, cmd);
Luciano Coelho807f8a82011-05-11 17:09:35 +030012598 if (!hdr)
12599 return -1;
12600
David S. Miller9360ffd2012-03-29 04:41:26 -040012601 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
12602 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex))
12603 goto nla_put_failure;
Luciano Coelho807f8a82011-05-11 17:09:35 +030012604
Johannes Berg053c0952015-01-16 22:09:00 +010012605 genlmsg_end(msg, hdr);
12606 return 0;
Luciano Coelho807f8a82011-05-11 17:09:35 +030012607
12608 nla_put_failure:
12609 genlmsg_cancel(msg, hdr);
12610 return -EMSGSIZE;
12611}
12612
Johannes Berga538e2d2009-06-16 19:56:42 +020012613void nl80211_send_scan_start(struct cfg80211_registered_device *rdev,
Johannes Bergfd014282012-06-18 19:17:03 +020012614 struct wireless_dev *wdev)
Johannes Berga538e2d2009-06-16 19:56:42 +020012615{
12616 struct sk_buff *msg;
12617
Thomas Graf58050fc2012-06-28 03:57:45 +000012618 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berga538e2d2009-06-16 19:56:42 +020012619 if (!msg)
12620 return;
12621
Johannes Bergfd014282012-06-18 19:17:03 +020012622 if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0,
Johannes Berga538e2d2009-06-16 19:56:42 +020012623 NL80211_CMD_TRIGGER_SCAN) < 0) {
12624 nlmsg_free(msg);
12625 return;
12626 }
12627
Johannes Berg68eb5502013-11-19 15:19:38 +010012628 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010012629 NL80211_MCGRP_SCAN, GFP_KERNEL);
Johannes Berga538e2d2009-06-16 19:56:42 +020012630}
12631
Johannes Bergf9d15d12014-01-22 11:14:19 +020012632struct sk_buff *nl80211_build_scan_msg(struct cfg80211_registered_device *rdev,
12633 struct wireless_dev *wdev, bool aborted)
Johannes Berg2a519312009-02-10 21:25:55 +010012634{
12635 struct sk_buff *msg;
12636
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -070012637 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg2a519312009-02-10 21:25:55 +010012638 if (!msg)
Johannes Bergf9d15d12014-01-22 11:14:19 +020012639 return NULL;
Johannes Berg2a519312009-02-10 21:25:55 +010012640
Johannes Bergfd014282012-06-18 19:17:03 +020012641 if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0,
Johannes Bergf9d15d12014-01-22 11:14:19 +020012642 aborted ? NL80211_CMD_SCAN_ABORTED :
12643 NL80211_CMD_NEW_SCAN_RESULTS) < 0) {
Johannes Berg2a519312009-02-10 21:25:55 +010012644 nlmsg_free(msg);
Johannes Bergf9d15d12014-01-22 11:14:19 +020012645 return NULL;
Johannes Berg2a519312009-02-10 21:25:55 +010012646 }
12647
Johannes Bergf9d15d12014-01-22 11:14:19 +020012648 return msg;
Johannes Berg2a519312009-02-10 21:25:55 +010012649}
12650
Johannes Bergf9d15d12014-01-22 11:14:19 +020012651void nl80211_send_scan_result(struct cfg80211_registered_device *rdev,
12652 struct sk_buff *msg)
Johannes Berg2a519312009-02-10 21:25:55 +010012653{
Johannes Berg2a519312009-02-10 21:25:55 +010012654 if (!msg)
12655 return;
12656
Johannes Berg68eb5502013-11-19 15:19:38 +010012657 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010012658 NL80211_MCGRP_SCAN, GFP_KERNEL);
Johannes Berg2a519312009-02-10 21:25:55 +010012659}
12660
Luciano Coelho807f8a82011-05-11 17:09:35 +030012661void nl80211_send_sched_scan_results(struct cfg80211_registered_device *rdev,
12662 struct net_device *netdev)
12663{
12664 struct sk_buff *msg;
12665
12666 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
12667 if (!msg)
12668 return;
12669
12670 if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0,
12671 NL80211_CMD_SCHED_SCAN_RESULTS) < 0) {
12672 nlmsg_free(msg);
12673 return;
12674 }
12675
Johannes Berg68eb5502013-11-19 15:19:38 +010012676 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010012677 NL80211_MCGRP_SCAN, GFP_KERNEL);
Luciano Coelho807f8a82011-05-11 17:09:35 +030012678}
12679
12680void nl80211_send_sched_scan(struct cfg80211_registered_device *rdev,
12681 struct net_device *netdev, u32 cmd)
12682{
12683 struct sk_buff *msg;
12684
Thomas Graf58050fc2012-06-28 03:57:45 +000012685 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Luciano Coelho807f8a82011-05-11 17:09:35 +030012686 if (!msg)
12687 return;
12688
12689 if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0, cmd) < 0) {
12690 nlmsg_free(msg);
12691 return;
12692 }
12693
Johannes Berg68eb5502013-11-19 15:19:38 +010012694 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010012695 NL80211_MCGRP_SCAN, GFP_KERNEL);
Luciano Coelho807f8a82011-05-11 17:09:35 +030012696}
12697
Jonathan Doronb0d7aa52014-12-15 19:26:00 +020012698static bool nl80211_reg_change_event_fill(struct sk_buff *msg,
12699 struct regulatory_request *request)
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040012700{
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040012701 /* Userspace can always count this one always being set */
David S. Miller9360ffd2012-03-29 04:41:26 -040012702 if (nla_put_u8(msg, NL80211_ATTR_REG_INITIATOR, request->initiator))
12703 goto nla_put_failure;
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040012704
David S. Miller9360ffd2012-03-29 04:41:26 -040012705 if (request->alpha2[0] == '0' && request->alpha2[1] == '0') {
12706 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
12707 NL80211_REGDOM_TYPE_WORLD))
12708 goto nla_put_failure;
12709 } else if (request->alpha2[0] == '9' && request->alpha2[1] == '9') {
12710 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
12711 NL80211_REGDOM_TYPE_CUSTOM_WORLD))
12712 goto nla_put_failure;
12713 } else if ((request->alpha2[0] == '9' && request->alpha2[1] == '8') ||
12714 request->intersect) {
12715 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
12716 NL80211_REGDOM_TYPE_INTERSECTION))
12717 goto nla_put_failure;
12718 } else {
12719 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
12720 NL80211_REGDOM_TYPE_COUNTRY) ||
12721 nla_put_string(msg, NL80211_ATTR_REG_ALPHA2,
12722 request->alpha2))
12723 goto nla_put_failure;
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040012724 }
12725
Arik Nemtsovad30ca22014-12-15 19:25:59 +020012726 if (request->wiphy_idx != WIPHY_IDX_INVALID) {
12727 struct wiphy *wiphy = wiphy_idx_to_wiphy(request->wiphy_idx);
12728
12729 if (wiphy &&
12730 nla_put_u32(msg, NL80211_ATTR_WIPHY, request->wiphy_idx))
12731 goto nla_put_failure;
Arik Nemtsov1bdd7162014-12-15 19:26:01 +020012732
12733 if (wiphy &&
12734 wiphy->regulatory_flags & REGULATORY_WIPHY_SELF_MANAGED &&
12735 nla_put_flag(msg, NL80211_ATTR_WIPHY_SELF_MANAGED_REG))
12736 goto nla_put_failure;
Arik Nemtsovad30ca22014-12-15 19:25:59 +020012737 }
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040012738
Jonathan Doronb0d7aa52014-12-15 19:26:00 +020012739 return true;
12740
12741nla_put_failure:
12742 return false;
12743}
12744
12745/*
12746 * This can happen on global regulatory changes or device specific settings
12747 * based on custom regulatory domains.
12748 */
12749void nl80211_common_reg_change_event(enum nl80211_commands cmd_id,
12750 struct regulatory_request *request)
12751{
12752 struct sk_buff *msg;
12753 void *hdr;
12754
12755 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
12756 if (!msg)
12757 return;
12758
12759 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd_id);
12760 if (!hdr) {
12761 nlmsg_free(msg);
12762 return;
12763 }
12764
12765 if (nl80211_reg_change_event_fill(msg, request) == false)
12766 goto nla_put_failure;
12767
Johannes Berg3b7b72e2011-10-22 19:05:51 +020012768 genlmsg_end(msg, hdr);
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040012769
Johannes Bergbc43b282009-07-25 10:54:13 +020012770 rcu_read_lock();
Johannes Berg68eb5502013-11-19 15:19:38 +010012771 genlmsg_multicast_allns(&nl80211_fam, msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010012772 NL80211_MCGRP_REGULATORY, GFP_ATOMIC);
Johannes Bergbc43b282009-07-25 10:54:13 +020012773 rcu_read_unlock();
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040012774
12775 return;
12776
12777nla_put_failure:
12778 genlmsg_cancel(msg, hdr);
12779 nlmsg_free(msg);
12780}
12781
Jouni Malinen6039f6d2009-03-19 13:39:21 +020012782static void nl80211_send_mlme_event(struct cfg80211_registered_device *rdev,
12783 struct net_device *netdev,
12784 const u8 *buf, size_t len,
Eliad Pellerb0b6aa22014-09-09 17:09:45 +030012785 enum nl80211_commands cmd, gfp_t gfp,
12786 int uapsd_queues)
Jouni Malinen6039f6d2009-03-19 13:39:21 +020012787{
12788 struct sk_buff *msg;
12789 void *hdr;
12790
Johannes Berge6d6e342009-07-01 21:26:47 +020012791 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020012792 if (!msg)
12793 return;
12794
12795 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
12796 if (!hdr) {
12797 nlmsg_free(msg);
12798 return;
12799 }
12800
David S. Miller9360ffd2012-03-29 04:41:26 -040012801 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
12802 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
12803 nla_put(msg, NL80211_ATTR_FRAME, len, buf))
12804 goto nla_put_failure;
Jouni Malinen6039f6d2009-03-19 13:39:21 +020012805
Eliad Pellerb0b6aa22014-09-09 17:09:45 +030012806 if (uapsd_queues >= 0) {
12807 struct nlattr *nla_wmm =
12808 nla_nest_start(msg, NL80211_ATTR_STA_WME);
12809 if (!nla_wmm)
12810 goto nla_put_failure;
12811
12812 if (nla_put_u8(msg, NL80211_STA_WME_UAPSD_QUEUES,
12813 uapsd_queues))
12814 goto nla_put_failure;
12815
12816 nla_nest_end(msg, nla_wmm);
12817 }
12818
Johannes Berg3b7b72e2011-10-22 19:05:51 +020012819 genlmsg_end(msg, hdr);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020012820
Johannes Berg68eb5502013-11-19 15:19:38 +010012821 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010012822 NL80211_MCGRP_MLME, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020012823 return;
12824
12825 nla_put_failure:
12826 genlmsg_cancel(msg, hdr);
12827 nlmsg_free(msg);
12828}
12829
12830void nl80211_send_rx_auth(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +020012831 struct net_device *netdev, const u8 *buf,
12832 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +020012833{
12834 nl80211_send_mlme_event(rdev, netdev, buf, len,
Eliad Pellerb0b6aa22014-09-09 17:09:45 +030012835 NL80211_CMD_AUTHENTICATE, gfp, -1);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020012836}
12837
12838void nl80211_send_rx_assoc(struct cfg80211_registered_device *rdev,
12839 struct net_device *netdev, const u8 *buf,
Eliad Pellerb0b6aa22014-09-09 17:09:45 +030012840 size_t len, gfp_t gfp, int uapsd_queues)
Jouni Malinen6039f6d2009-03-19 13:39:21 +020012841{
Johannes Berge6d6e342009-07-01 21:26:47 +020012842 nl80211_send_mlme_event(rdev, netdev, buf, len,
Eliad Pellerb0b6aa22014-09-09 17:09:45 +030012843 NL80211_CMD_ASSOCIATE, gfp, uapsd_queues);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020012844}
12845
Jouni Malinen53b46b82009-03-27 20:53:56 +020012846void nl80211_send_deauth(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +020012847 struct net_device *netdev, const u8 *buf,
12848 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +020012849{
12850 nl80211_send_mlme_event(rdev, netdev, buf, len,
Eliad Pellerb0b6aa22014-09-09 17:09:45 +030012851 NL80211_CMD_DEAUTHENTICATE, gfp, -1);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020012852}
12853
Jouni Malinen53b46b82009-03-27 20:53:56 +020012854void nl80211_send_disassoc(struct cfg80211_registered_device *rdev,
12855 struct net_device *netdev, const u8 *buf,
Johannes Berge6d6e342009-07-01 21:26:47 +020012856 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +020012857{
12858 nl80211_send_mlme_event(rdev, netdev, buf, len,
Eliad Pellerb0b6aa22014-09-09 17:09:45 +030012859 NL80211_CMD_DISASSOCIATE, gfp, -1);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020012860}
12861
Johannes Berg6ff57cf2013-05-16 00:55:00 +020012862void cfg80211_rx_unprot_mlme_mgmt(struct net_device *dev, const u8 *buf,
12863 size_t len)
Jouni Malinencf4e5942010-12-16 00:52:40 +020012864{
Johannes Berg947add32013-02-22 22:05:20 +010012865 struct wireless_dev *wdev = dev->ieee80211_ptr;
12866 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080012867 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg6ff57cf2013-05-16 00:55:00 +020012868 const struct ieee80211_mgmt *mgmt = (void *)buf;
12869 u32 cmd;
Jouni Malinencf4e5942010-12-16 00:52:40 +020012870
Johannes Berg6ff57cf2013-05-16 00:55:00 +020012871 if (WARN_ON(len < 2))
12872 return;
12873
12874 if (ieee80211_is_deauth(mgmt->frame_control))
12875 cmd = NL80211_CMD_UNPROT_DEAUTHENTICATE;
12876 else
12877 cmd = NL80211_CMD_UNPROT_DISASSOCIATE;
12878
12879 trace_cfg80211_rx_unprot_mlme_mgmt(dev, buf, len);
Eliad Pellerb0b6aa22014-09-09 17:09:45 +030012880 nl80211_send_mlme_event(rdev, dev, buf, len, cmd, GFP_ATOMIC, -1);
Jouni Malinencf4e5942010-12-16 00:52:40 +020012881}
Johannes Berg6ff57cf2013-05-16 00:55:00 +020012882EXPORT_SYMBOL(cfg80211_rx_unprot_mlme_mgmt);
Jouni Malinencf4e5942010-12-16 00:52:40 +020012883
Luis R. Rodriguez1b06bb42009-05-02 00:34:48 -040012884static void nl80211_send_mlme_timeout(struct cfg80211_registered_device *rdev,
12885 struct net_device *netdev, int cmd,
Johannes Berge6d6e342009-07-01 21:26:47 +020012886 const u8 *addr, gfp_t gfp)
Jouni Malinen1965c852009-04-22 21:38:25 +030012887{
12888 struct sk_buff *msg;
12889 void *hdr;
12890
Johannes Berge6d6e342009-07-01 21:26:47 +020012891 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +030012892 if (!msg)
12893 return;
12894
12895 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
12896 if (!hdr) {
12897 nlmsg_free(msg);
12898 return;
12899 }
12900
David S. Miller9360ffd2012-03-29 04:41:26 -040012901 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
12902 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
12903 nla_put_flag(msg, NL80211_ATTR_TIMED_OUT) ||
12904 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr))
12905 goto nla_put_failure;
Jouni Malinen1965c852009-04-22 21:38:25 +030012906
Johannes Berg3b7b72e2011-10-22 19:05:51 +020012907 genlmsg_end(msg, hdr);
Jouni Malinen1965c852009-04-22 21:38:25 +030012908
Johannes Berg68eb5502013-11-19 15:19:38 +010012909 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010012910 NL80211_MCGRP_MLME, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +030012911 return;
12912
12913 nla_put_failure:
12914 genlmsg_cancel(msg, hdr);
12915 nlmsg_free(msg);
12916}
12917
12918void nl80211_send_auth_timeout(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +020012919 struct net_device *netdev, const u8 *addr,
12920 gfp_t gfp)
Jouni Malinen1965c852009-04-22 21:38:25 +030012921{
12922 nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_AUTHENTICATE,
Johannes Berge6d6e342009-07-01 21:26:47 +020012923 addr, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +030012924}
12925
12926void nl80211_send_assoc_timeout(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +020012927 struct net_device *netdev, const u8 *addr,
12928 gfp_t gfp)
Jouni Malinen1965c852009-04-22 21:38:25 +030012929{
Johannes Berge6d6e342009-07-01 21:26:47 +020012930 nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_ASSOCIATE,
12931 addr, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +030012932}
12933
Samuel Ortizb23aa672009-07-01 21:26:54 +020012934void nl80211_send_connect_result(struct cfg80211_registered_device *rdev,
12935 struct net_device *netdev, const u8 *bssid,
12936 const u8 *req_ie, size_t req_ie_len,
12937 const u8 *resp_ie, size_t resp_ie_len,
Jouni Malinenbf1ecd22016-05-31 00:16:50 +030012938 int status, gfp_t gfp)
Samuel Ortizb23aa672009-07-01 21:26:54 +020012939{
12940 struct sk_buff *msg;
12941 void *hdr;
12942
Thomas Graf58050fc2012-06-28 03:57:45 +000012943 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +020012944 if (!msg)
12945 return;
12946
12947 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONNECT);
12948 if (!hdr) {
12949 nlmsg_free(msg);
12950 return;
12951 }
12952
David S. Miller9360ffd2012-03-29 04:41:26 -040012953 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
12954 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
12955 (bssid && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) ||
Jouni Malinenbf1ecd22016-05-31 00:16:50 +030012956 nla_put_u16(msg, NL80211_ATTR_STATUS_CODE,
12957 status < 0 ? WLAN_STATUS_UNSPECIFIED_FAILURE :
12958 status) ||
12959 (status < 0 && nla_put_flag(msg, NL80211_ATTR_TIMED_OUT)) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040012960 (req_ie &&
12961 nla_put(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie)) ||
12962 (resp_ie &&
12963 nla_put(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie)))
12964 goto nla_put_failure;
Samuel Ortizb23aa672009-07-01 21:26:54 +020012965
Johannes Berg3b7b72e2011-10-22 19:05:51 +020012966 genlmsg_end(msg, hdr);
Samuel Ortizb23aa672009-07-01 21:26:54 +020012967
Johannes Berg68eb5502013-11-19 15:19:38 +010012968 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010012969 NL80211_MCGRP_MLME, gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +020012970 return;
12971
12972 nla_put_failure:
12973 genlmsg_cancel(msg, hdr);
12974 nlmsg_free(msg);
Samuel Ortizb23aa672009-07-01 21:26:54 +020012975}
12976
12977void nl80211_send_roamed(struct cfg80211_registered_device *rdev,
12978 struct net_device *netdev, const u8 *bssid,
12979 const u8 *req_ie, size_t req_ie_len,
12980 const u8 *resp_ie, size_t resp_ie_len, gfp_t gfp)
12981{
12982 struct sk_buff *msg;
12983 void *hdr;
12984
Thomas Graf58050fc2012-06-28 03:57:45 +000012985 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +020012986 if (!msg)
12987 return;
12988
12989 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_ROAM);
12990 if (!hdr) {
12991 nlmsg_free(msg);
12992 return;
12993 }
12994
David S. Miller9360ffd2012-03-29 04:41:26 -040012995 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
12996 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
12997 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid) ||
12998 (req_ie &&
12999 nla_put(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie)) ||
13000 (resp_ie &&
13001 nla_put(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie)))
13002 goto nla_put_failure;
Samuel Ortizb23aa672009-07-01 21:26:54 +020013003
Johannes Berg3b7b72e2011-10-22 19:05:51 +020013004 genlmsg_end(msg, hdr);
Samuel Ortizb23aa672009-07-01 21:26:54 +020013005
Johannes Berg68eb5502013-11-19 15:19:38 +010013006 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010013007 NL80211_MCGRP_MLME, gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +020013008 return;
13009
13010 nla_put_failure:
13011 genlmsg_cancel(msg, hdr);
13012 nlmsg_free(msg);
Samuel Ortizb23aa672009-07-01 21:26:54 +020013013}
13014
13015void nl80211_send_disconnected(struct cfg80211_registered_device *rdev,
13016 struct net_device *netdev, u16 reason,
Johannes Berg667503d2009-07-07 03:56:11 +020013017 const u8 *ie, size_t ie_len, bool from_ap)
Samuel Ortizb23aa672009-07-01 21:26:54 +020013018{
13019 struct sk_buff *msg;
13020 void *hdr;
13021
Thomas Graf58050fc2012-06-28 03:57:45 +000013022 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Samuel Ortizb23aa672009-07-01 21:26:54 +020013023 if (!msg)
13024 return;
13025
13026 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DISCONNECT);
13027 if (!hdr) {
13028 nlmsg_free(msg);
13029 return;
13030 }
13031
David S. Miller9360ffd2012-03-29 04:41:26 -040013032 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
13033 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
13034 (from_ap && reason &&
13035 nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason)) ||
13036 (from_ap &&
13037 nla_put_flag(msg, NL80211_ATTR_DISCONNECTED_BY_AP)) ||
13038 (ie && nla_put(msg, NL80211_ATTR_IE, ie_len, ie)))
13039 goto nla_put_failure;
Samuel Ortizb23aa672009-07-01 21:26:54 +020013040
Johannes Berg3b7b72e2011-10-22 19:05:51 +020013041 genlmsg_end(msg, hdr);
Samuel Ortizb23aa672009-07-01 21:26:54 +020013042
Johannes Berg68eb5502013-11-19 15:19:38 +010013043 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010013044 NL80211_MCGRP_MLME, GFP_KERNEL);
Samuel Ortizb23aa672009-07-01 21:26:54 +020013045 return;
13046
13047 nla_put_failure:
13048 genlmsg_cancel(msg, hdr);
13049 nlmsg_free(msg);
Samuel Ortizb23aa672009-07-01 21:26:54 +020013050}
13051
Johannes Berg04a773a2009-04-19 21:24:32 +020013052void nl80211_send_ibss_bssid(struct cfg80211_registered_device *rdev,
13053 struct net_device *netdev, const u8 *bssid,
13054 gfp_t gfp)
13055{
13056 struct sk_buff *msg;
13057 void *hdr;
13058
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -070013059 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Johannes Berg04a773a2009-04-19 21:24:32 +020013060 if (!msg)
13061 return;
13062
13063 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_JOIN_IBSS);
13064 if (!hdr) {
13065 nlmsg_free(msg);
13066 return;
13067 }
13068
David S. Miller9360ffd2012-03-29 04:41:26 -040013069 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
13070 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
13071 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid))
13072 goto nla_put_failure;
Johannes Berg04a773a2009-04-19 21:24:32 +020013073
Johannes Berg3b7b72e2011-10-22 19:05:51 +020013074 genlmsg_end(msg, hdr);
Johannes Berg04a773a2009-04-19 21:24:32 +020013075
Johannes Berg68eb5502013-11-19 15:19:38 +010013076 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010013077 NL80211_MCGRP_MLME, gfp);
Johannes Berg04a773a2009-04-19 21:24:32 +020013078 return;
13079
13080 nla_put_failure:
13081 genlmsg_cancel(msg, hdr);
13082 nlmsg_free(msg);
13083}
13084
Johannes Berg947add32013-02-22 22:05:20 +010013085void cfg80211_notify_new_peer_candidate(struct net_device *dev, const u8 *addr,
13086 const u8* ie, u8 ie_len, gfp_t gfp)
Javier Cardonac93b5e72011-04-07 15:08:34 -070013087{
Johannes Berg947add32013-02-22 22:05:20 +010013088 struct wireless_dev *wdev = dev->ieee80211_ptr;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080013089 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Javier Cardonac93b5e72011-04-07 15:08:34 -070013090 struct sk_buff *msg;
13091 void *hdr;
13092
Johannes Berg947add32013-02-22 22:05:20 +010013093 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_MESH_POINT))
13094 return;
13095
13096 trace_cfg80211_notify_new_peer_candidate(dev, addr);
13097
Javier Cardonac93b5e72011-04-07 15:08:34 -070013098 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
13099 if (!msg)
13100 return;
13101
13102 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NEW_PEER_CANDIDATE);
13103 if (!hdr) {
13104 nlmsg_free(msg);
13105 return;
13106 }
13107
David S. Miller9360ffd2012-03-29 04:41:26 -040013108 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg947add32013-02-22 22:05:20 +010013109 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
13110 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040013111 (ie_len && ie &&
13112 nla_put(msg, NL80211_ATTR_IE, ie_len , ie)))
13113 goto nla_put_failure;
Javier Cardonac93b5e72011-04-07 15:08:34 -070013114
Johannes Berg3b7b72e2011-10-22 19:05:51 +020013115 genlmsg_end(msg, hdr);
Javier Cardonac93b5e72011-04-07 15:08:34 -070013116
Johannes Berg68eb5502013-11-19 15:19:38 +010013117 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010013118 NL80211_MCGRP_MLME, gfp);
Javier Cardonac93b5e72011-04-07 15:08:34 -070013119 return;
13120
13121 nla_put_failure:
13122 genlmsg_cancel(msg, hdr);
13123 nlmsg_free(msg);
13124}
Johannes Berg947add32013-02-22 22:05:20 +010013125EXPORT_SYMBOL(cfg80211_notify_new_peer_candidate);
Javier Cardonac93b5e72011-04-07 15:08:34 -070013126
Jouni Malinena3b8b052009-03-27 21:59:49 +020013127void nl80211_michael_mic_failure(struct cfg80211_registered_device *rdev,
13128 struct net_device *netdev, const u8 *addr,
13129 enum nl80211_key_type key_type, int key_id,
Johannes Berge6d6e342009-07-01 21:26:47 +020013130 const u8 *tsc, gfp_t gfp)
Jouni Malinena3b8b052009-03-27 21:59:49 +020013131{
13132 struct sk_buff *msg;
13133 void *hdr;
13134
Johannes Berge6d6e342009-07-01 21:26:47 +020013135 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinena3b8b052009-03-27 21:59:49 +020013136 if (!msg)
13137 return;
13138
13139 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_MICHAEL_MIC_FAILURE);
13140 if (!hdr) {
13141 nlmsg_free(msg);
13142 return;
13143 }
13144
David S. Miller9360ffd2012-03-29 04:41:26 -040013145 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
13146 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
13147 (addr && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) ||
13148 nla_put_u32(msg, NL80211_ATTR_KEY_TYPE, key_type) ||
13149 (key_id != -1 &&
13150 nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_id)) ||
13151 (tsc && nla_put(msg, NL80211_ATTR_KEY_SEQ, 6, tsc)))
13152 goto nla_put_failure;
Jouni Malinena3b8b052009-03-27 21:59:49 +020013153
Johannes Berg3b7b72e2011-10-22 19:05:51 +020013154 genlmsg_end(msg, hdr);
Jouni Malinena3b8b052009-03-27 21:59:49 +020013155
Johannes Berg68eb5502013-11-19 15:19:38 +010013156 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010013157 NL80211_MCGRP_MLME, gfp);
Jouni Malinena3b8b052009-03-27 21:59:49 +020013158 return;
13159
13160 nla_put_failure:
13161 genlmsg_cancel(msg, hdr);
13162 nlmsg_free(msg);
13163}
13164
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040013165void nl80211_send_beacon_hint_event(struct wiphy *wiphy,
13166 struct ieee80211_channel *channel_before,
13167 struct ieee80211_channel *channel_after)
13168{
13169 struct sk_buff *msg;
13170 void *hdr;
13171 struct nlattr *nl_freq;
13172
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -070013173 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_ATOMIC);
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040013174 if (!msg)
13175 return;
13176
13177 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_BEACON_HINT);
13178 if (!hdr) {
13179 nlmsg_free(msg);
13180 return;
13181 }
13182
13183 /*
13184 * Since we are applying the beacon hint to a wiphy we know its
13185 * wiphy_idx is valid
13186 */
David S. Miller9360ffd2012-03-29 04:41:26 -040013187 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy)))
13188 goto nla_put_failure;
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040013189
13190 /* Before */
13191 nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_BEFORE);
13192 if (!nl_freq)
13193 goto nla_put_failure;
Johannes Bergcdc89b92013-02-18 23:54:36 +010013194 if (nl80211_msg_put_channel(msg, channel_before, false))
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040013195 goto nla_put_failure;
13196 nla_nest_end(msg, nl_freq);
13197
13198 /* After */
13199 nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_AFTER);
13200 if (!nl_freq)
13201 goto nla_put_failure;
Johannes Bergcdc89b92013-02-18 23:54:36 +010013202 if (nl80211_msg_put_channel(msg, channel_after, false))
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040013203 goto nla_put_failure;
13204 nla_nest_end(msg, nl_freq);
13205
Johannes Berg3b7b72e2011-10-22 19:05:51 +020013206 genlmsg_end(msg, hdr);
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040013207
Johannes Berg463d0182009-07-14 00:33:35 +020013208 rcu_read_lock();
Johannes Berg68eb5502013-11-19 15:19:38 +010013209 genlmsg_multicast_allns(&nl80211_fam, msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010013210 NL80211_MCGRP_REGULATORY, GFP_ATOMIC);
Johannes Berg463d0182009-07-14 00:33:35 +020013211 rcu_read_unlock();
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040013212
13213 return;
13214
13215nla_put_failure:
13216 genlmsg_cancel(msg, hdr);
13217 nlmsg_free(msg);
13218}
13219
Jouni Malinen9588bbd2009-12-23 13:15:41 +010013220static void nl80211_send_remain_on_chan_event(
13221 int cmd, struct cfg80211_registered_device *rdev,
Johannes Berg71bbc992012-06-15 15:30:18 +020013222 struct wireless_dev *wdev, u64 cookie,
Jouni Malinen9588bbd2009-12-23 13:15:41 +010013223 struct ieee80211_channel *chan,
Jouni Malinen9588bbd2009-12-23 13:15:41 +010013224 unsigned int duration, gfp_t gfp)
13225{
13226 struct sk_buff *msg;
13227 void *hdr;
13228
13229 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
13230 if (!msg)
13231 return;
13232
13233 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
13234 if (!hdr) {
13235 nlmsg_free(msg);
13236 return;
13237 }
13238
David S. Miller9360ffd2012-03-29 04:41:26 -040013239 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg71bbc992012-06-15 15:30:18 +020013240 (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
13241 wdev->netdev->ifindex)) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020013242 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
13243 NL80211_ATTR_PAD) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040013244 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, chan->center_freq) ||
Johannes Berg42d97a52012-11-08 18:31:02 +010013245 nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE,
13246 NL80211_CHAN_NO_HT) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020013247 nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie,
13248 NL80211_ATTR_PAD))
David S. Miller9360ffd2012-03-29 04:41:26 -040013249 goto nla_put_failure;
Jouni Malinen9588bbd2009-12-23 13:15:41 +010013250
David S. Miller9360ffd2012-03-29 04:41:26 -040013251 if (cmd == NL80211_CMD_REMAIN_ON_CHANNEL &&
13252 nla_put_u32(msg, NL80211_ATTR_DURATION, duration))
13253 goto nla_put_failure;
Jouni Malinen9588bbd2009-12-23 13:15:41 +010013254
Johannes Berg3b7b72e2011-10-22 19:05:51 +020013255 genlmsg_end(msg, hdr);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010013256
Johannes Berg68eb5502013-11-19 15:19:38 +010013257 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010013258 NL80211_MCGRP_MLME, gfp);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010013259 return;
13260
13261 nla_put_failure:
13262 genlmsg_cancel(msg, hdr);
13263 nlmsg_free(msg);
13264}
13265
Johannes Berg947add32013-02-22 22:05:20 +010013266void cfg80211_ready_on_channel(struct wireless_dev *wdev, u64 cookie,
13267 struct ieee80211_channel *chan,
13268 unsigned int duration, gfp_t gfp)
Jouni Malinen9588bbd2009-12-23 13:15:41 +010013269{
Johannes Berg947add32013-02-22 22:05:20 +010013270 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080013271 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg947add32013-02-22 22:05:20 +010013272
13273 trace_cfg80211_ready_on_channel(wdev, cookie, chan, duration);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010013274 nl80211_send_remain_on_chan_event(NL80211_CMD_REMAIN_ON_CHANNEL,
Johannes Berg71bbc992012-06-15 15:30:18 +020013275 rdev, wdev, cookie, chan,
Johannes Berg42d97a52012-11-08 18:31:02 +010013276 duration, gfp);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010013277}
Johannes Berg947add32013-02-22 22:05:20 +010013278EXPORT_SYMBOL(cfg80211_ready_on_channel);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010013279
Johannes Berg947add32013-02-22 22:05:20 +010013280void cfg80211_remain_on_channel_expired(struct wireless_dev *wdev, u64 cookie,
13281 struct ieee80211_channel *chan,
13282 gfp_t gfp)
Jouni Malinen9588bbd2009-12-23 13:15:41 +010013283{
Johannes Berg947add32013-02-22 22:05:20 +010013284 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080013285 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg947add32013-02-22 22:05:20 +010013286
13287 trace_cfg80211_ready_on_channel_expired(wdev, cookie, chan);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010013288 nl80211_send_remain_on_chan_event(NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL,
Johannes Berg42d97a52012-11-08 18:31:02 +010013289 rdev, wdev, cookie, chan, 0, gfp);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010013290}
Johannes Berg947add32013-02-22 22:05:20 +010013291EXPORT_SYMBOL(cfg80211_remain_on_channel_expired);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010013292
Johannes Berg947add32013-02-22 22:05:20 +010013293void cfg80211_new_sta(struct net_device *dev, const u8 *mac_addr,
13294 struct station_info *sinfo, gfp_t gfp)
Johannes Berg98b62182009-12-23 13:15:44 +010013295{
Johannes Berg947add32013-02-22 22:05:20 +010013296 struct wiphy *wiphy = dev->ieee80211_ptr->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080013297 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg98b62182009-12-23 13:15:44 +010013298 struct sk_buff *msg;
13299
Johannes Berg947add32013-02-22 22:05:20 +010013300 trace_cfg80211_new_sta(dev, mac_addr, sinfo);
13301
Thomas Graf58050fc2012-06-28 03:57:45 +000013302 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Johannes Berg98b62182009-12-23 13:15:44 +010013303 if (!msg)
13304 return;
13305
Johannes Bergcf5ead82014-11-14 17:14:00 +010013306 if (nl80211_send_station(msg, NL80211_CMD_NEW_STATION, 0, 0, 0,
John W. Linville66266b32012-03-15 13:25:41 -040013307 rdev, dev, mac_addr, sinfo) < 0) {
Johannes Berg98b62182009-12-23 13:15:44 +010013308 nlmsg_free(msg);
13309 return;
13310 }
13311
Johannes Berg68eb5502013-11-19 15:19:38 +010013312 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010013313 NL80211_MCGRP_MLME, gfp);
Johannes Berg98b62182009-12-23 13:15:44 +010013314}
Johannes Berg947add32013-02-22 22:05:20 +010013315EXPORT_SYMBOL(cfg80211_new_sta);
Johannes Berg98b62182009-12-23 13:15:44 +010013316
Johannes Bergcf5ead82014-11-14 17:14:00 +010013317void cfg80211_del_sta_sinfo(struct net_device *dev, const u8 *mac_addr,
13318 struct station_info *sinfo, gfp_t gfp)
Jouni Malinenec15e682011-03-23 15:29:52 +020013319{
Johannes Berg947add32013-02-22 22:05:20 +010013320 struct wiphy *wiphy = dev->ieee80211_ptr->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080013321 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Jouni Malinenec15e682011-03-23 15:29:52 +020013322 struct sk_buff *msg;
Johannes Bergcf5ead82014-11-14 17:14:00 +010013323 struct station_info empty_sinfo = {};
13324
13325 if (!sinfo)
13326 sinfo = &empty_sinfo;
Jouni Malinenec15e682011-03-23 15:29:52 +020013327
Johannes Berg947add32013-02-22 22:05:20 +010013328 trace_cfg80211_del_sta(dev, mac_addr);
13329
Thomas Graf58050fc2012-06-28 03:57:45 +000013330 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinenec15e682011-03-23 15:29:52 +020013331 if (!msg)
13332 return;
13333
Johannes Bergcf5ead82014-11-14 17:14:00 +010013334 if (nl80211_send_station(msg, NL80211_CMD_DEL_STATION, 0, 0, 0,
Johannes Berg57007122015-01-16 21:05:02 +010013335 rdev, dev, mac_addr, sinfo) < 0) {
Jouni Malinenec15e682011-03-23 15:29:52 +020013336 nlmsg_free(msg);
13337 return;
13338 }
13339
Johannes Berg68eb5502013-11-19 15:19:38 +010013340 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010013341 NL80211_MCGRP_MLME, gfp);
Jouni Malinenec15e682011-03-23 15:29:52 +020013342}
Johannes Bergcf5ead82014-11-14 17:14:00 +010013343EXPORT_SYMBOL(cfg80211_del_sta_sinfo);
Jouni Malinenec15e682011-03-23 15:29:52 +020013344
Johannes Berg947add32013-02-22 22:05:20 +010013345void cfg80211_conn_failed(struct net_device *dev, const u8 *mac_addr,
13346 enum nl80211_connect_failed_reason reason,
13347 gfp_t gfp)
Pandiyarajan Pitchaimuthued44a952012-09-18 16:50:49 +053013348{
Johannes Berg947add32013-02-22 22:05:20 +010013349 struct wiphy *wiphy = dev->ieee80211_ptr->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080013350 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Pandiyarajan Pitchaimuthued44a952012-09-18 16:50:49 +053013351 struct sk_buff *msg;
13352 void *hdr;
13353
13354 msg = nlmsg_new(NLMSG_GOODSIZE, gfp);
13355 if (!msg)
13356 return;
13357
13358 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONN_FAILED);
13359 if (!hdr) {
13360 nlmsg_free(msg);
13361 return;
13362 }
13363
13364 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
13365 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) ||
13366 nla_put_u32(msg, NL80211_ATTR_CONN_FAILED_REASON, reason))
13367 goto nla_put_failure;
13368
13369 genlmsg_end(msg, hdr);
13370
Johannes Berg68eb5502013-11-19 15:19:38 +010013371 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010013372 NL80211_MCGRP_MLME, gfp);
Pandiyarajan Pitchaimuthued44a952012-09-18 16:50:49 +053013373 return;
13374
13375 nla_put_failure:
13376 genlmsg_cancel(msg, hdr);
13377 nlmsg_free(msg);
13378}
Johannes Berg947add32013-02-22 22:05:20 +010013379EXPORT_SYMBOL(cfg80211_conn_failed);
Pandiyarajan Pitchaimuthued44a952012-09-18 16:50:49 +053013380
Johannes Bergb92ab5d2011-11-04 11:18:19 +010013381static bool __nl80211_unexpected_frame(struct net_device *dev, u8 cmd,
13382 const u8 *addr, gfp_t gfp)
Johannes Berg28946da2011-11-04 11:18:12 +010013383{
13384 struct wireless_dev *wdev = dev->ieee80211_ptr;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080013385 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Johannes Berg28946da2011-11-04 11:18:12 +010013386 struct sk_buff *msg;
13387 void *hdr;
Eric W. Biederman15e47302012-09-07 20:12:54 +000013388 u32 nlportid = ACCESS_ONCE(wdev->ap_unexpected_nlportid);
Johannes Berg28946da2011-11-04 11:18:12 +010013389
Eric W. Biederman15e47302012-09-07 20:12:54 +000013390 if (!nlportid)
Johannes Berg28946da2011-11-04 11:18:12 +010013391 return false;
13392
13393 msg = nlmsg_new(100, gfp);
13394 if (!msg)
13395 return true;
13396
Johannes Bergb92ab5d2011-11-04 11:18:19 +010013397 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
Johannes Berg28946da2011-11-04 11:18:12 +010013398 if (!hdr) {
13399 nlmsg_free(msg);
13400 return true;
13401 }
13402
David S. Miller9360ffd2012-03-29 04:41:26 -040013403 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
13404 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
13405 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr))
13406 goto nla_put_failure;
Johannes Berg28946da2011-11-04 11:18:12 +010013407
Johannes Berg9c90a9f2013-06-04 12:46:03 +020013408 genlmsg_end(msg, hdr);
Eric W. Biederman15e47302012-09-07 20:12:54 +000013409 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid);
Johannes Berg28946da2011-11-04 11:18:12 +010013410 return true;
13411
13412 nla_put_failure:
13413 genlmsg_cancel(msg, hdr);
13414 nlmsg_free(msg);
13415 return true;
13416}
13417
Johannes Berg947add32013-02-22 22:05:20 +010013418bool cfg80211_rx_spurious_frame(struct net_device *dev,
13419 const u8 *addr, gfp_t gfp)
Johannes Bergb92ab5d2011-11-04 11:18:19 +010013420{
Johannes Berg947add32013-02-22 22:05:20 +010013421 struct wireless_dev *wdev = dev->ieee80211_ptr;
13422 bool ret;
Johannes Bergb92ab5d2011-11-04 11:18:19 +010013423
Johannes Berg947add32013-02-22 22:05:20 +010013424 trace_cfg80211_rx_spurious_frame(dev, addr);
13425
13426 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP &&
13427 wdev->iftype != NL80211_IFTYPE_P2P_GO)) {
13428 trace_cfg80211_return_bool(false);
13429 return false;
13430 }
13431 ret = __nl80211_unexpected_frame(dev, NL80211_CMD_UNEXPECTED_FRAME,
13432 addr, gfp);
13433 trace_cfg80211_return_bool(ret);
13434 return ret;
Johannes Bergb92ab5d2011-11-04 11:18:19 +010013435}
Johannes Berg947add32013-02-22 22:05:20 +010013436EXPORT_SYMBOL(cfg80211_rx_spurious_frame);
13437
13438bool cfg80211_rx_unexpected_4addr_frame(struct net_device *dev,
13439 const u8 *addr, gfp_t gfp)
13440{
13441 struct wireless_dev *wdev = dev->ieee80211_ptr;
13442 bool ret;
13443
13444 trace_cfg80211_rx_unexpected_4addr_frame(dev, addr);
13445
13446 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP &&
13447 wdev->iftype != NL80211_IFTYPE_P2P_GO &&
13448 wdev->iftype != NL80211_IFTYPE_AP_VLAN)) {
13449 trace_cfg80211_return_bool(false);
13450 return false;
13451 }
13452 ret = __nl80211_unexpected_frame(dev,
13453 NL80211_CMD_UNEXPECTED_4ADDR_FRAME,
13454 addr, gfp);
13455 trace_cfg80211_return_bool(ret);
13456 return ret;
13457}
13458EXPORT_SYMBOL(cfg80211_rx_unexpected_4addr_frame);
Johannes Bergb92ab5d2011-11-04 11:18:19 +010013459
Johannes Berg2e161f782010-08-12 15:38:38 +020013460int nl80211_send_mgmt(struct cfg80211_registered_device *rdev,
Eric W. Biederman15e47302012-09-07 20:12:54 +000013461 struct wireless_dev *wdev, u32 nlportid,
Johannes Berg804483e2012-03-05 22:18:41 +010013462 int freq, int sig_dbm,
Vladimir Kondratiev19504cf2013-08-15 14:51:28 +030013463 const u8 *buf, size_t len, u32 flags, gfp_t gfp)
Jouni Malinen026331c2010-02-15 12:53:10 +020013464{
Johannes Berg71bbc992012-06-15 15:30:18 +020013465 struct net_device *netdev = wdev->netdev;
Jouni Malinen026331c2010-02-15 12:53:10 +020013466 struct sk_buff *msg;
13467 void *hdr;
Jouni Malinen026331c2010-02-15 12:53:10 +020013468
13469 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
13470 if (!msg)
13471 return -ENOMEM;
13472
Johannes Berg2e161f782010-08-12 15:38:38 +020013473 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME);
Jouni Malinen026331c2010-02-15 12:53:10 +020013474 if (!hdr) {
13475 nlmsg_free(msg);
13476 return -ENOMEM;
13477 }
13478
David S. Miller9360ffd2012-03-29 04:41:26 -040013479 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg71bbc992012-06-15 15:30:18 +020013480 (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
13481 netdev->ifindex)) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020013482 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
13483 NL80211_ATTR_PAD) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040013484 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq) ||
13485 (sig_dbm &&
13486 nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) ||
Vladimir Kondratiev19504cf2013-08-15 14:51:28 +030013487 nla_put(msg, NL80211_ATTR_FRAME, len, buf) ||
13488 (flags &&
13489 nla_put_u32(msg, NL80211_ATTR_RXMGMT_FLAGS, flags)))
David S. Miller9360ffd2012-03-29 04:41:26 -040013490 goto nla_put_failure;
Jouni Malinen026331c2010-02-15 12:53:10 +020013491
Johannes Berg3b7b72e2011-10-22 19:05:51 +020013492 genlmsg_end(msg, hdr);
Jouni Malinen026331c2010-02-15 12:53:10 +020013493
Eric W. Biederman15e47302012-09-07 20:12:54 +000013494 return genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid);
Jouni Malinen026331c2010-02-15 12:53:10 +020013495
13496 nla_put_failure:
13497 genlmsg_cancel(msg, hdr);
13498 nlmsg_free(msg);
13499 return -ENOBUFS;
13500}
13501
Johannes Berg947add32013-02-22 22:05:20 +010013502void cfg80211_mgmt_tx_status(struct wireless_dev *wdev, u64 cookie,
13503 const u8 *buf, size_t len, bool ack, gfp_t gfp)
Jouni Malinen026331c2010-02-15 12:53:10 +020013504{
Johannes Berg947add32013-02-22 22:05:20 +010013505 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080013506 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg71bbc992012-06-15 15:30:18 +020013507 struct net_device *netdev = wdev->netdev;
Jouni Malinen026331c2010-02-15 12:53:10 +020013508 struct sk_buff *msg;
13509 void *hdr;
13510
Johannes Berg947add32013-02-22 22:05:20 +010013511 trace_cfg80211_mgmt_tx_status(wdev, cookie, ack);
13512
Jouni Malinen026331c2010-02-15 12:53:10 +020013513 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
13514 if (!msg)
13515 return;
13516
Johannes Berg2e161f782010-08-12 15:38:38 +020013517 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME_TX_STATUS);
Jouni Malinen026331c2010-02-15 12:53:10 +020013518 if (!hdr) {
13519 nlmsg_free(msg);
13520 return;
13521 }
13522
David S. Miller9360ffd2012-03-29 04:41:26 -040013523 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg71bbc992012-06-15 15:30:18 +020013524 (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
13525 netdev->ifindex)) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020013526 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
13527 NL80211_ATTR_PAD) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040013528 nla_put(msg, NL80211_ATTR_FRAME, len, buf) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020013529 nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie,
13530 NL80211_ATTR_PAD) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040013531 (ack && nla_put_flag(msg, NL80211_ATTR_ACK)))
13532 goto nla_put_failure;
Jouni Malinen026331c2010-02-15 12:53:10 +020013533
Johannes Berg3b7b72e2011-10-22 19:05:51 +020013534 genlmsg_end(msg, hdr);
Jouni Malinen026331c2010-02-15 12:53:10 +020013535
Johannes Berg68eb5502013-11-19 15:19:38 +010013536 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010013537 NL80211_MCGRP_MLME, gfp);
Jouni Malinen026331c2010-02-15 12:53:10 +020013538 return;
13539
13540 nla_put_failure:
13541 genlmsg_cancel(msg, hdr);
13542 nlmsg_free(msg);
13543}
Johannes Berg947add32013-02-22 22:05:20 +010013544EXPORT_SYMBOL(cfg80211_mgmt_tx_status);
Jouni Malinen026331c2010-02-15 12:53:10 +020013545
Johannes Berg5b97f492014-11-26 12:37:43 +010013546static struct sk_buff *cfg80211_prepare_cqm(struct net_device *dev,
13547 const char *mac, gfp_t gfp)
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020013548{
Johannes Berg947add32013-02-22 22:05:20 +010013549 struct wireless_dev *wdev = dev->ieee80211_ptr;
Johannes Berg5b97f492014-11-26 12:37:43 +010013550 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
13551 struct sk_buff *msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
13552 void **cb;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020013553
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020013554 if (!msg)
Johannes Berg5b97f492014-11-26 12:37:43 +010013555 return NULL;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020013556
Johannes Berg5b97f492014-11-26 12:37:43 +010013557 cb = (void **)msg->cb;
13558
13559 cb[0] = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM);
13560 if (!cb[0]) {
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020013561 nlmsg_free(msg);
Johannes Berg5b97f492014-11-26 12:37:43 +010013562 return NULL;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020013563 }
13564
David S. Miller9360ffd2012-03-29 04:41:26 -040013565 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg947add32013-02-22 22:05:20 +010013566 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex))
David S. Miller9360ffd2012-03-29 04:41:26 -040013567 goto nla_put_failure;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020013568
Johannes Berg5b97f492014-11-26 12:37:43 +010013569 if (mac && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac))
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020013570 goto nla_put_failure;
13571
Johannes Berg5b97f492014-11-26 12:37:43 +010013572 cb[1] = nla_nest_start(msg, NL80211_ATTR_CQM);
13573 if (!cb[1])
13574 goto nla_put_failure;
13575
13576 cb[2] = rdev;
13577
13578 return msg;
13579 nla_put_failure:
13580 nlmsg_free(msg);
13581 return NULL;
13582}
13583
13584static void cfg80211_send_cqm(struct sk_buff *msg, gfp_t gfp)
13585{
13586 void **cb = (void **)msg->cb;
13587 struct cfg80211_registered_device *rdev = cb[2];
13588
13589 nla_nest_end(msg, cb[1]);
13590 genlmsg_end(msg, cb[0]);
13591
13592 memset(msg->cb, 0, sizeof(msg->cb));
13593
13594 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
13595 NL80211_MCGRP_MLME, gfp);
13596}
13597
13598void cfg80211_cqm_rssi_notify(struct net_device *dev,
13599 enum nl80211_cqm_rssi_threshold_event rssi_event,
13600 gfp_t gfp)
13601{
13602 struct sk_buff *msg;
13603
13604 trace_cfg80211_cqm_rssi_notify(dev, rssi_event);
13605
Johannes Berg98f03342014-11-26 12:42:02 +010013606 if (WARN_ON(rssi_event != NL80211_CQM_RSSI_THRESHOLD_EVENT_LOW &&
13607 rssi_event != NL80211_CQM_RSSI_THRESHOLD_EVENT_HIGH))
13608 return;
13609
Johannes Berg5b97f492014-11-26 12:37:43 +010013610 msg = cfg80211_prepare_cqm(dev, NULL, gfp);
13611 if (!msg)
13612 return;
13613
David S. Miller9360ffd2012-03-29 04:41:26 -040013614 if (nla_put_u32(msg, NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT,
13615 rssi_event))
13616 goto nla_put_failure;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020013617
Johannes Berg5b97f492014-11-26 12:37:43 +010013618 cfg80211_send_cqm(msg, gfp);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020013619
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020013620 return;
13621
13622 nla_put_failure:
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020013623 nlmsg_free(msg);
13624}
Johannes Berg947add32013-02-22 22:05:20 +010013625EXPORT_SYMBOL(cfg80211_cqm_rssi_notify);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020013626
Johannes Berg5b97f492014-11-26 12:37:43 +010013627void cfg80211_cqm_txe_notify(struct net_device *dev,
13628 const u8 *peer, u32 num_packets,
13629 u32 rate, u32 intvl, gfp_t gfp)
13630{
13631 struct sk_buff *msg;
13632
13633 msg = cfg80211_prepare_cqm(dev, peer, gfp);
13634 if (!msg)
13635 return;
13636
13637 if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_PKTS, num_packets))
13638 goto nla_put_failure;
13639
13640 if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_RATE, rate))
13641 goto nla_put_failure;
13642
13643 if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_INTVL, intvl))
13644 goto nla_put_failure;
13645
13646 cfg80211_send_cqm(msg, gfp);
13647 return;
13648
13649 nla_put_failure:
13650 nlmsg_free(msg);
13651}
13652EXPORT_SYMBOL(cfg80211_cqm_txe_notify);
13653
13654void cfg80211_cqm_pktloss_notify(struct net_device *dev,
13655 const u8 *peer, u32 num_packets, gfp_t gfp)
13656{
13657 struct sk_buff *msg;
13658
13659 trace_cfg80211_cqm_pktloss_notify(dev, peer, num_packets);
13660
13661 msg = cfg80211_prepare_cqm(dev, peer, gfp);
13662 if (!msg)
13663 return;
13664
13665 if (nla_put_u32(msg, NL80211_ATTR_CQM_PKT_LOSS_EVENT, num_packets))
13666 goto nla_put_failure;
13667
13668 cfg80211_send_cqm(msg, gfp);
13669 return;
13670
13671 nla_put_failure:
13672 nlmsg_free(msg);
13673}
13674EXPORT_SYMBOL(cfg80211_cqm_pktloss_notify);
13675
Johannes Berg98f03342014-11-26 12:42:02 +010013676void cfg80211_cqm_beacon_loss_notify(struct net_device *dev, gfp_t gfp)
13677{
13678 struct sk_buff *msg;
13679
13680 msg = cfg80211_prepare_cqm(dev, NULL, gfp);
13681 if (!msg)
13682 return;
13683
13684 if (nla_put_flag(msg, NL80211_ATTR_CQM_BEACON_LOSS_EVENT))
13685 goto nla_put_failure;
13686
13687 cfg80211_send_cqm(msg, gfp);
13688 return;
13689
13690 nla_put_failure:
13691 nlmsg_free(msg);
13692}
13693EXPORT_SYMBOL(cfg80211_cqm_beacon_loss_notify);
13694
Johannes Berg947add32013-02-22 22:05:20 +010013695static void nl80211_gtk_rekey_notify(struct cfg80211_registered_device *rdev,
13696 struct net_device *netdev, const u8 *bssid,
13697 const u8 *replay_ctr, gfp_t gfp)
Johannes Berge5497d72011-07-05 16:35:40 +020013698{
13699 struct sk_buff *msg;
13700 struct nlattr *rekey_attr;
13701 void *hdr;
13702
Thomas Graf58050fc2012-06-28 03:57:45 +000013703 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Johannes Berge5497d72011-07-05 16:35:40 +020013704 if (!msg)
13705 return;
13706
13707 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_REKEY_OFFLOAD);
13708 if (!hdr) {
13709 nlmsg_free(msg);
13710 return;
13711 }
13712
David S. Miller9360ffd2012-03-29 04:41:26 -040013713 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
13714 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
13715 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid))
13716 goto nla_put_failure;
Johannes Berge5497d72011-07-05 16:35:40 +020013717
13718 rekey_attr = nla_nest_start(msg, NL80211_ATTR_REKEY_DATA);
13719 if (!rekey_attr)
13720 goto nla_put_failure;
13721
David S. Miller9360ffd2012-03-29 04:41:26 -040013722 if (nla_put(msg, NL80211_REKEY_DATA_REPLAY_CTR,
13723 NL80211_REPLAY_CTR_LEN, replay_ctr))
13724 goto nla_put_failure;
Johannes Berge5497d72011-07-05 16:35:40 +020013725
13726 nla_nest_end(msg, rekey_attr);
13727
Johannes Berg3b7b72e2011-10-22 19:05:51 +020013728 genlmsg_end(msg, hdr);
Johannes Berge5497d72011-07-05 16:35:40 +020013729
Johannes Berg68eb5502013-11-19 15:19:38 +010013730 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010013731 NL80211_MCGRP_MLME, gfp);
Johannes Berge5497d72011-07-05 16:35:40 +020013732 return;
13733
13734 nla_put_failure:
13735 genlmsg_cancel(msg, hdr);
13736 nlmsg_free(msg);
13737}
13738
Johannes Berg947add32013-02-22 22:05:20 +010013739void cfg80211_gtk_rekey_notify(struct net_device *dev, const u8 *bssid,
13740 const u8 *replay_ctr, gfp_t gfp)
13741{
13742 struct wireless_dev *wdev = dev->ieee80211_ptr;
13743 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080013744 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg947add32013-02-22 22:05:20 +010013745
13746 trace_cfg80211_gtk_rekey_notify(dev, bssid);
13747 nl80211_gtk_rekey_notify(rdev, dev, bssid, replay_ctr, gfp);
13748}
13749EXPORT_SYMBOL(cfg80211_gtk_rekey_notify);
13750
13751static void
13752nl80211_pmksa_candidate_notify(struct cfg80211_registered_device *rdev,
13753 struct net_device *netdev, int index,
13754 const u8 *bssid, bool preauth, gfp_t gfp)
Jouni Malinenc9df56b2011-09-16 18:56:23 +030013755{
13756 struct sk_buff *msg;
13757 struct nlattr *attr;
13758 void *hdr;
13759
Thomas Graf58050fc2012-06-28 03:57:45 +000013760 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinenc9df56b2011-09-16 18:56:23 +030013761 if (!msg)
13762 return;
13763
13764 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PMKSA_CANDIDATE);
13765 if (!hdr) {
13766 nlmsg_free(msg);
13767 return;
13768 }
13769
David S. Miller9360ffd2012-03-29 04:41:26 -040013770 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
13771 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex))
13772 goto nla_put_failure;
Jouni Malinenc9df56b2011-09-16 18:56:23 +030013773
13774 attr = nla_nest_start(msg, NL80211_ATTR_PMKSA_CANDIDATE);
13775 if (!attr)
13776 goto nla_put_failure;
13777
David S. Miller9360ffd2012-03-29 04:41:26 -040013778 if (nla_put_u32(msg, NL80211_PMKSA_CANDIDATE_INDEX, index) ||
13779 nla_put(msg, NL80211_PMKSA_CANDIDATE_BSSID, ETH_ALEN, bssid) ||
13780 (preauth &&
13781 nla_put_flag(msg, NL80211_PMKSA_CANDIDATE_PREAUTH)))
13782 goto nla_put_failure;
Jouni Malinenc9df56b2011-09-16 18:56:23 +030013783
13784 nla_nest_end(msg, attr);
13785
Johannes Berg3b7b72e2011-10-22 19:05:51 +020013786 genlmsg_end(msg, hdr);
Jouni Malinenc9df56b2011-09-16 18:56:23 +030013787
Johannes Berg68eb5502013-11-19 15:19:38 +010013788 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010013789 NL80211_MCGRP_MLME, gfp);
Jouni Malinenc9df56b2011-09-16 18:56:23 +030013790 return;
13791
13792 nla_put_failure:
13793 genlmsg_cancel(msg, hdr);
13794 nlmsg_free(msg);
13795}
13796
Johannes Berg947add32013-02-22 22:05:20 +010013797void cfg80211_pmksa_candidate_notify(struct net_device *dev, int index,
13798 const u8 *bssid, bool preauth, gfp_t gfp)
13799{
13800 struct wireless_dev *wdev = dev->ieee80211_ptr;
13801 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080013802 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg947add32013-02-22 22:05:20 +010013803
13804 trace_cfg80211_pmksa_candidate_notify(dev, index, bssid, preauth);
13805 nl80211_pmksa_candidate_notify(rdev, dev, index, bssid, preauth, gfp);
13806}
13807EXPORT_SYMBOL(cfg80211_pmksa_candidate_notify);
13808
13809static void nl80211_ch_switch_notify(struct cfg80211_registered_device *rdev,
13810 struct net_device *netdev,
13811 struct cfg80211_chan_def *chandef,
Luciano Coelhof8d75522014-11-07 14:31:35 +020013812 gfp_t gfp,
13813 enum nl80211_commands notif,
13814 u8 count)
Thomas Pedersen53145262012-04-06 13:35:47 -070013815{
13816 struct sk_buff *msg;
13817 void *hdr;
13818
Thomas Graf58050fc2012-06-28 03:57:45 +000013819 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Thomas Pedersen53145262012-04-06 13:35:47 -070013820 if (!msg)
13821 return;
13822
Luciano Coelhof8d75522014-11-07 14:31:35 +020013823 hdr = nl80211hdr_put(msg, 0, 0, 0, notif);
Thomas Pedersen53145262012-04-06 13:35:47 -070013824 if (!hdr) {
13825 nlmsg_free(msg);
13826 return;
13827 }
13828
Johannes Berg683b6d32012-11-08 21:25:48 +010013829 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex))
13830 goto nla_put_failure;
13831
13832 if (nl80211_send_chandef(msg, chandef))
John W. Linville7eab0f62012-04-12 14:25:14 -040013833 goto nla_put_failure;
Thomas Pedersen53145262012-04-06 13:35:47 -070013834
Luciano Coelhof8d75522014-11-07 14:31:35 +020013835 if ((notif == NL80211_CMD_CH_SWITCH_STARTED_NOTIFY) &&
13836 (nla_put_u32(msg, NL80211_ATTR_CH_SWITCH_COUNT, count)))
13837 goto nla_put_failure;
13838
Thomas Pedersen53145262012-04-06 13:35:47 -070013839 genlmsg_end(msg, hdr);
13840
Johannes Berg68eb5502013-11-19 15:19:38 +010013841 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010013842 NL80211_MCGRP_MLME, gfp);
Thomas Pedersen53145262012-04-06 13:35:47 -070013843 return;
13844
13845 nla_put_failure:
13846 genlmsg_cancel(msg, hdr);
13847 nlmsg_free(msg);
13848}
13849
Johannes Berg947add32013-02-22 22:05:20 +010013850void cfg80211_ch_switch_notify(struct net_device *dev,
13851 struct cfg80211_chan_def *chandef)
Thomas Pedersen84f10702012-07-12 16:17:33 -070013852{
Johannes Berg947add32013-02-22 22:05:20 +010013853 struct wireless_dev *wdev = dev->ieee80211_ptr;
13854 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080013855 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg947add32013-02-22 22:05:20 +010013856
Simon Wunderliche487eae2013-11-21 18:19:51 +010013857 ASSERT_WDEV_LOCK(wdev);
Johannes Berg947add32013-02-22 22:05:20 +010013858
Simon Wunderliche487eae2013-11-21 18:19:51 +010013859 trace_cfg80211_ch_switch_notify(dev, chandef);
Johannes Berg947add32013-02-22 22:05:20 +010013860
Michal Kazior9e0e2962014-01-29 14:22:27 +010013861 wdev->chandef = *chandef;
Janusz Dziedzic96f55f12014-01-24 14:29:21 +010013862 wdev->preset_chandef = *chandef;
Luciano Coelhof8d75522014-11-07 14:31:35 +020013863 nl80211_ch_switch_notify(rdev, dev, chandef, GFP_KERNEL,
13864 NL80211_CMD_CH_SWITCH_NOTIFY, 0);
Johannes Berg947add32013-02-22 22:05:20 +010013865}
13866EXPORT_SYMBOL(cfg80211_ch_switch_notify);
13867
Luciano Coelhof8d75522014-11-07 14:31:35 +020013868void cfg80211_ch_switch_started_notify(struct net_device *dev,
13869 struct cfg80211_chan_def *chandef,
13870 u8 count)
13871{
13872 struct wireless_dev *wdev = dev->ieee80211_ptr;
13873 struct wiphy *wiphy = wdev->wiphy;
13874 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
13875
13876 trace_cfg80211_ch_switch_started_notify(dev, chandef);
13877
13878 nl80211_ch_switch_notify(rdev, dev, chandef, GFP_KERNEL,
13879 NL80211_CMD_CH_SWITCH_STARTED_NOTIFY, count);
13880}
13881EXPORT_SYMBOL(cfg80211_ch_switch_started_notify);
13882
Thomas Pedersen84f10702012-07-12 16:17:33 -070013883void
Simon Wunderlich04f39042013-02-08 18:16:19 +010013884nl80211_radar_notify(struct cfg80211_registered_device *rdev,
Janusz Dziedzicd2859df2013-11-06 13:55:51 +010013885 const struct cfg80211_chan_def *chandef,
Simon Wunderlich04f39042013-02-08 18:16:19 +010013886 enum nl80211_radar_event event,
13887 struct net_device *netdev, gfp_t gfp)
13888{
13889 struct sk_buff *msg;
13890 void *hdr;
13891
13892 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
13893 if (!msg)
13894 return;
13895
13896 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_RADAR_DETECT);
13897 if (!hdr) {
13898 nlmsg_free(msg);
13899 return;
13900 }
13901
13902 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx))
13903 goto nla_put_failure;
13904
13905 /* NOP and radar events don't need a netdev parameter */
13906 if (netdev) {
13907 struct wireless_dev *wdev = netdev->ieee80211_ptr;
13908
13909 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020013910 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
13911 NL80211_ATTR_PAD))
Simon Wunderlich04f39042013-02-08 18:16:19 +010013912 goto nla_put_failure;
13913 }
13914
13915 if (nla_put_u32(msg, NL80211_ATTR_RADAR_EVENT, event))
13916 goto nla_put_failure;
13917
13918 if (nl80211_send_chandef(msg, chandef))
13919 goto nla_put_failure;
13920
Johannes Berg9c90a9f2013-06-04 12:46:03 +020013921 genlmsg_end(msg, hdr);
Simon Wunderlich04f39042013-02-08 18:16:19 +010013922
Johannes Berg68eb5502013-11-19 15:19:38 +010013923 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010013924 NL80211_MCGRP_MLME, gfp);
Simon Wunderlich04f39042013-02-08 18:16:19 +010013925 return;
13926
13927 nla_put_failure:
13928 genlmsg_cancel(msg, hdr);
13929 nlmsg_free(msg);
13930}
13931
Johannes Berg7f6cf312011-11-04 11:18:15 +010013932void cfg80211_probe_status(struct net_device *dev, const u8 *addr,
13933 u64 cookie, bool acked, gfp_t gfp)
13934{
13935 struct wireless_dev *wdev = dev->ieee80211_ptr;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080013936 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Johannes Berg7f6cf312011-11-04 11:18:15 +010013937 struct sk_buff *msg;
13938 void *hdr;
Johannes Berg7f6cf312011-11-04 11:18:15 +010013939
Beni Lev4ee3e062012-08-27 12:49:39 +030013940 trace_cfg80211_probe_status(dev, addr, cookie, acked);
13941
Thomas Graf58050fc2012-06-28 03:57:45 +000013942 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Beni Lev4ee3e062012-08-27 12:49:39 +030013943
Johannes Berg7f6cf312011-11-04 11:18:15 +010013944 if (!msg)
13945 return;
13946
13947 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PROBE_CLIENT);
13948 if (!hdr) {
13949 nlmsg_free(msg);
13950 return;
13951 }
13952
David S. Miller9360ffd2012-03-29 04:41:26 -040013953 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
13954 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
13955 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020013956 nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie,
13957 NL80211_ATTR_PAD) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040013958 (acked && nla_put_flag(msg, NL80211_ATTR_ACK)))
13959 goto nla_put_failure;
Johannes Berg7f6cf312011-11-04 11:18:15 +010013960
Johannes Berg9c90a9f2013-06-04 12:46:03 +020013961 genlmsg_end(msg, hdr);
Johannes Berg7f6cf312011-11-04 11:18:15 +010013962
Johannes Berg68eb5502013-11-19 15:19:38 +010013963 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010013964 NL80211_MCGRP_MLME, gfp);
Johannes Berg7f6cf312011-11-04 11:18:15 +010013965 return;
13966
13967 nla_put_failure:
13968 genlmsg_cancel(msg, hdr);
13969 nlmsg_free(msg);
13970}
13971EXPORT_SYMBOL(cfg80211_probe_status);
13972
Johannes Berg5e760232011-11-04 11:18:17 +010013973void cfg80211_report_obss_beacon(struct wiphy *wiphy,
13974 const u8 *frame, size_t len,
Ben Greear37c73b52012-10-26 14:49:25 -070013975 int freq, int sig_dbm)
Johannes Berg5e760232011-11-04 11:18:17 +010013976{
Zhao, Gangf26cbf42014-04-21 12:53:03 +080013977 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg5e760232011-11-04 11:18:17 +010013978 struct sk_buff *msg;
13979 void *hdr;
Ben Greear37c73b52012-10-26 14:49:25 -070013980 struct cfg80211_beacon_registration *reg;
Johannes Berg5e760232011-11-04 11:18:17 +010013981
Beni Lev4ee3e062012-08-27 12:49:39 +030013982 trace_cfg80211_report_obss_beacon(wiphy, frame, len, freq, sig_dbm);
13983
Ben Greear37c73b52012-10-26 14:49:25 -070013984 spin_lock_bh(&rdev->beacon_registrations_lock);
13985 list_for_each_entry(reg, &rdev->beacon_registrations, list) {
13986 msg = nlmsg_new(len + 100, GFP_ATOMIC);
13987 if (!msg) {
13988 spin_unlock_bh(&rdev->beacon_registrations_lock);
13989 return;
13990 }
Johannes Berg5e760232011-11-04 11:18:17 +010013991
Ben Greear37c73b52012-10-26 14:49:25 -070013992 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME);
13993 if (!hdr)
13994 goto nla_put_failure;
Johannes Berg5e760232011-11-04 11:18:17 +010013995
Ben Greear37c73b52012-10-26 14:49:25 -070013996 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
13997 (freq &&
13998 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq)) ||
13999 (sig_dbm &&
14000 nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) ||
14001 nla_put(msg, NL80211_ATTR_FRAME, len, frame))
14002 goto nla_put_failure;
14003
14004 genlmsg_end(msg, hdr);
14005
14006 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, reg->nlportid);
Johannes Berg5e760232011-11-04 11:18:17 +010014007 }
Ben Greear37c73b52012-10-26 14:49:25 -070014008 spin_unlock_bh(&rdev->beacon_registrations_lock);
Johannes Berg5e760232011-11-04 11:18:17 +010014009 return;
14010
14011 nla_put_failure:
Ben Greear37c73b52012-10-26 14:49:25 -070014012 spin_unlock_bh(&rdev->beacon_registrations_lock);
14013 if (hdr)
14014 genlmsg_cancel(msg, hdr);
Johannes Berg5e760232011-11-04 11:18:17 +010014015 nlmsg_free(msg);
14016}
14017EXPORT_SYMBOL(cfg80211_report_obss_beacon);
14018
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010014019#ifdef CONFIG_PM
Luciano Coelho8cd4d452014-09-17 11:55:28 +030014020static int cfg80211_net_detect_results(struct sk_buff *msg,
14021 struct cfg80211_wowlan_wakeup *wakeup)
14022{
14023 struct cfg80211_wowlan_nd_info *nd = wakeup->net_detect;
14024 struct nlattr *nl_results, *nl_match, *nl_freqs;
14025 int i, j;
14026
14027 nl_results = nla_nest_start(
14028 msg, NL80211_WOWLAN_TRIG_NET_DETECT_RESULTS);
14029 if (!nl_results)
14030 return -EMSGSIZE;
14031
14032 for (i = 0; i < nd->n_matches; i++) {
14033 struct cfg80211_wowlan_nd_match *match = nd->matches[i];
14034
14035 nl_match = nla_nest_start(msg, i);
14036 if (!nl_match)
14037 break;
14038
14039 /* The SSID attribute is optional in nl80211, but for
14040 * simplicity reasons it's always present in the
14041 * cfg80211 structure. If a driver can't pass the
14042 * SSID, that needs to be changed. A zero length SSID
14043 * is still a valid SSID (wildcard), so it cannot be
14044 * used for this purpose.
14045 */
14046 if (nla_put(msg, NL80211_ATTR_SSID, match->ssid.ssid_len,
14047 match->ssid.ssid)) {
14048 nla_nest_cancel(msg, nl_match);
14049 goto out;
14050 }
14051
14052 if (match->n_channels) {
14053 nl_freqs = nla_nest_start(
14054 msg, NL80211_ATTR_SCAN_FREQUENCIES);
14055 if (!nl_freqs) {
14056 nla_nest_cancel(msg, nl_match);
14057 goto out;
14058 }
14059
14060 for (j = 0; j < match->n_channels; j++) {
Samuel Tan5528fae82015-02-09 21:29:15 +020014061 if (nla_put_u32(msg, j, match->channels[j])) {
Luciano Coelho8cd4d452014-09-17 11:55:28 +030014062 nla_nest_cancel(msg, nl_freqs);
14063 nla_nest_cancel(msg, nl_match);
14064 goto out;
14065 }
14066 }
14067
14068 nla_nest_end(msg, nl_freqs);
14069 }
14070
14071 nla_nest_end(msg, nl_match);
14072 }
14073
14074out:
14075 nla_nest_end(msg, nl_results);
14076 return 0;
14077}
14078
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010014079void cfg80211_report_wowlan_wakeup(struct wireless_dev *wdev,
14080 struct cfg80211_wowlan_wakeup *wakeup,
14081 gfp_t gfp)
14082{
Zhao, Gangf26cbf42014-04-21 12:53:03 +080014083 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010014084 struct sk_buff *msg;
14085 void *hdr;
Johannes Berg9c90a9f2013-06-04 12:46:03 +020014086 int size = 200;
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010014087
14088 trace_cfg80211_report_wowlan_wakeup(wdev->wiphy, wdev, wakeup);
14089
14090 if (wakeup)
14091 size += wakeup->packet_present_len;
14092
14093 msg = nlmsg_new(size, gfp);
14094 if (!msg)
14095 return;
14096
14097 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_WOWLAN);
14098 if (!hdr)
14099 goto free_msg;
14100
14101 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020014102 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
14103 NL80211_ATTR_PAD))
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010014104 goto free_msg;
14105
14106 if (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
14107 wdev->netdev->ifindex))
14108 goto free_msg;
14109
14110 if (wakeup) {
14111 struct nlattr *reasons;
14112
14113 reasons = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS);
Johannes Berg7fa322c2013-10-25 11:16:58 +020014114 if (!reasons)
14115 goto free_msg;
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010014116
14117 if (wakeup->disconnect &&
14118 nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT))
14119 goto free_msg;
14120 if (wakeup->magic_pkt &&
14121 nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT))
14122 goto free_msg;
14123 if (wakeup->gtk_rekey_failure &&
14124 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE))
14125 goto free_msg;
14126 if (wakeup->eap_identity_req &&
14127 nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST))
14128 goto free_msg;
14129 if (wakeup->four_way_handshake &&
14130 nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE))
14131 goto free_msg;
14132 if (wakeup->rfkill_release &&
14133 nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE))
14134 goto free_msg;
14135
14136 if (wakeup->pattern_idx >= 0 &&
14137 nla_put_u32(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN,
14138 wakeup->pattern_idx))
14139 goto free_msg;
14140
Johannes Bergae917c92013-10-25 11:05:22 +020014141 if (wakeup->tcp_match &&
14142 nla_put_flag(msg, NL80211_WOWLAN_TRIG_WAKEUP_TCP_MATCH))
14143 goto free_msg;
Johannes Berg2a0e0472013-01-23 22:57:40 +010014144
Johannes Bergae917c92013-10-25 11:05:22 +020014145 if (wakeup->tcp_connlost &&
14146 nla_put_flag(msg, NL80211_WOWLAN_TRIG_WAKEUP_TCP_CONNLOST))
14147 goto free_msg;
Johannes Berg2a0e0472013-01-23 22:57:40 +010014148
Johannes Bergae917c92013-10-25 11:05:22 +020014149 if (wakeup->tcp_nomoretokens &&
14150 nla_put_flag(msg,
14151 NL80211_WOWLAN_TRIG_WAKEUP_TCP_NOMORETOKENS))
14152 goto free_msg;
Johannes Berg2a0e0472013-01-23 22:57:40 +010014153
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010014154 if (wakeup->packet) {
14155 u32 pkt_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211;
14156 u32 len_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211_LEN;
14157
14158 if (!wakeup->packet_80211) {
14159 pkt_attr =
14160 NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023;
14161 len_attr =
14162 NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023_LEN;
14163 }
14164
14165 if (wakeup->packet_len &&
14166 nla_put_u32(msg, len_attr, wakeup->packet_len))
14167 goto free_msg;
14168
14169 if (nla_put(msg, pkt_attr, wakeup->packet_present_len,
14170 wakeup->packet))
14171 goto free_msg;
14172 }
14173
Luciano Coelho8cd4d452014-09-17 11:55:28 +030014174 if (wakeup->net_detect &&
14175 cfg80211_net_detect_results(msg, wakeup))
14176 goto free_msg;
14177
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010014178 nla_nest_end(msg, reasons);
14179 }
14180
Johannes Berg9c90a9f2013-06-04 12:46:03 +020014181 genlmsg_end(msg, hdr);
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010014182
Johannes Berg68eb5502013-11-19 15:19:38 +010014183 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010014184 NL80211_MCGRP_MLME, gfp);
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010014185 return;
14186
14187 free_msg:
14188 nlmsg_free(msg);
14189}
14190EXPORT_SYMBOL(cfg80211_report_wowlan_wakeup);
14191#endif
14192
Jouni Malinen3475b092012-11-16 22:49:57 +020014193void cfg80211_tdls_oper_request(struct net_device *dev, const u8 *peer,
14194 enum nl80211_tdls_operation oper,
14195 u16 reason_code, gfp_t gfp)
14196{
14197 struct wireless_dev *wdev = dev->ieee80211_ptr;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080014198 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Jouni Malinen3475b092012-11-16 22:49:57 +020014199 struct sk_buff *msg;
14200 void *hdr;
Jouni Malinen3475b092012-11-16 22:49:57 +020014201
14202 trace_cfg80211_tdls_oper_request(wdev->wiphy, dev, peer, oper,
14203 reason_code);
14204
14205 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
14206 if (!msg)
14207 return;
14208
14209 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_TDLS_OPER);
14210 if (!hdr) {
14211 nlmsg_free(msg);
14212 return;
14213 }
14214
14215 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
14216 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
14217 nla_put_u8(msg, NL80211_ATTR_TDLS_OPERATION, oper) ||
14218 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer) ||
14219 (reason_code > 0 &&
14220 nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason_code)))
14221 goto nla_put_failure;
14222
Johannes Berg9c90a9f2013-06-04 12:46:03 +020014223 genlmsg_end(msg, hdr);
Jouni Malinen3475b092012-11-16 22:49:57 +020014224
Johannes Berg68eb5502013-11-19 15:19:38 +010014225 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010014226 NL80211_MCGRP_MLME, gfp);
Jouni Malinen3475b092012-11-16 22:49:57 +020014227 return;
14228
14229 nla_put_failure:
14230 genlmsg_cancel(msg, hdr);
14231 nlmsg_free(msg);
14232}
14233EXPORT_SYMBOL(cfg80211_tdls_oper_request);
14234
Jouni Malinen026331c2010-02-15 12:53:10 +020014235static int nl80211_netlink_notify(struct notifier_block * nb,
14236 unsigned long state,
14237 void *_notify)
14238{
14239 struct netlink_notify *notify = _notify;
14240 struct cfg80211_registered_device *rdev;
14241 struct wireless_dev *wdev;
Ben Greear37c73b52012-10-26 14:49:25 -070014242 struct cfg80211_beacon_registration *reg, *tmp;
Jouni Malinen026331c2010-02-15 12:53:10 +020014243
Dmitry Ivanov8f815cd2016-04-06 17:23:18 +030014244 if (state != NETLINK_URELEASE || notify->protocol != NETLINK_GENERIC)
Jouni Malinen026331c2010-02-15 12:53:10 +020014245 return NOTIFY_DONE;
14246
14247 rcu_read_lock();
14248
Johannes Berg5e760232011-11-04 11:18:17 +010014249 list_for_each_entry_rcu(rdev, &cfg80211_rdev_list, list) {
Johannes Berg78f22b62014-03-24 17:57:27 +010014250 bool schedule_destroy_work = false;
Jukka Rissanen93a1e862014-12-15 13:25:39 +020014251 bool schedule_scan_stop = false;
14252 struct cfg80211_sched_scan_request *sched_scan_req =
14253 rcu_dereference(rdev->sched_scan_req);
14254
14255 if (sched_scan_req && notify->portid &&
14256 sched_scan_req->owner_nlportid == notify->portid)
14257 schedule_scan_stop = true;
Johannes Berg78f22b62014-03-24 17:57:27 +010014258
Johannes Berg53873f12016-05-03 16:52:04 +030014259 list_for_each_entry_rcu(wdev, &rdev->wiphy.wdev_list, list) {
Eric W. Biederman15e47302012-09-07 20:12:54 +000014260 cfg80211_mlme_unregister_socket(wdev, notify->portid);
Ben Greear37c73b52012-10-26 14:49:25 -070014261
Johannes Berg78f22b62014-03-24 17:57:27 +010014262 if (wdev->owner_nlportid == notify->portid)
14263 schedule_destroy_work = true;
14264 }
14265
Ben Greear37c73b52012-10-26 14:49:25 -070014266 spin_lock_bh(&rdev->beacon_registrations_lock);
14267 list_for_each_entry_safe(reg, tmp, &rdev->beacon_registrations,
14268 list) {
14269 if (reg->nlportid == notify->portid) {
14270 list_del(&reg->list);
14271 kfree(reg);
14272 break;
14273 }
14274 }
14275 spin_unlock_bh(&rdev->beacon_registrations_lock);
Johannes Berg78f22b62014-03-24 17:57:27 +010014276
14277 if (schedule_destroy_work) {
14278 struct cfg80211_iface_destroy *destroy;
14279
14280 destroy = kzalloc(sizeof(*destroy), GFP_ATOMIC);
14281 if (destroy) {
14282 destroy->nlportid = notify->portid;
14283 spin_lock(&rdev->destroy_list_lock);
14284 list_add(&destroy->list, &rdev->destroy_list);
14285 spin_unlock(&rdev->destroy_list_lock);
14286 schedule_work(&rdev->destroy_work);
14287 }
Jukka Rissanen93a1e862014-12-15 13:25:39 +020014288 } else if (schedule_scan_stop) {
14289 sched_scan_req->owner_nlportid = 0;
14290
14291 if (rdev->ops->sched_scan_stop &&
14292 rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN)
14293 schedule_work(&rdev->sched_scan_stop_wk);
Johannes Berg78f22b62014-03-24 17:57:27 +010014294 }
Johannes Berg5e760232011-11-04 11:18:17 +010014295 }
Jouni Malinen026331c2010-02-15 12:53:10 +020014296
14297 rcu_read_unlock();
14298
Ilan peer05050752015-03-04 00:32:06 -050014299 /*
14300 * It is possible that the user space process that is controlling the
14301 * indoor setting disappeared, so notify the regulatory core.
14302 */
14303 regulatory_netlink_notify(notify->portid);
Zhao, Gang6784c7d2014-04-21 12:53:04 +080014304 return NOTIFY_OK;
Jouni Malinen026331c2010-02-15 12:53:10 +020014305}
14306
14307static struct notifier_block nl80211_netlink_notifier = {
14308 .notifier_call = nl80211_netlink_notify,
14309};
14310
Jouni Malinen355199e2013-02-27 17:14:27 +020014311void cfg80211_ft_event(struct net_device *netdev,
14312 struct cfg80211_ft_event_params *ft_event)
14313{
14314 struct wiphy *wiphy = netdev->ieee80211_ptr->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080014315 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Jouni Malinen355199e2013-02-27 17:14:27 +020014316 struct sk_buff *msg;
14317 void *hdr;
Jouni Malinen355199e2013-02-27 17:14:27 +020014318
14319 trace_cfg80211_ft_event(wiphy, netdev, ft_event);
14320
14321 if (!ft_event->target_ap)
14322 return;
14323
14324 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
14325 if (!msg)
14326 return;
14327
14328 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FT_EVENT);
Johannes Bergae917c92013-10-25 11:05:22 +020014329 if (!hdr)
14330 goto out;
Jouni Malinen355199e2013-02-27 17:14:27 +020014331
Johannes Bergae917c92013-10-25 11:05:22 +020014332 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
14333 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
14334 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, ft_event->target_ap))
14335 goto out;
14336
14337 if (ft_event->ies &&
14338 nla_put(msg, NL80211_ATTR_IE, ft_event->ies_len, ft_event->ies))
14339 goto out;
14340 if (ft_event->ric_ies &&
14341 nla_put(msg, NL80211_ATTR_IE_RIC, ft_event->ric_ies_len,
14342 ft_event->ric_ies))
14343 goto out;
Jouni Malinen355199e2013-02-27 17:14:27 +020014344
Johannes Berg9c90a9f2013-06-04 12:46:03 +020014345 genlmsg_end(msg, hdr);
Jouni Malinen355199e2013-02-27 17:14:27 +020014346
Johannes Berg68eb5502013-11-19 15:19:38 +010014347 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010014348 NL80211_MCGRP_MLME, GFP_KERNEL);
Johannes Bergae917c92013-10-25 11:05:22 +020014349 return;
14350 out:
14351 nlmsg_free(msg);
Jouni Malinen355199e2013-02-27 17:14:27 +020014352}
14353EXPORT_SYMBOL(cfg80211_ft_event);
14354
Arend van Spriel5de17982013-04-18 15:49:00 +020014355void cfg80211_crit_proto_stopped(struct wireless_dev *wdev, gfp_t gfp)
14356{
14357 struct cfg80211_registered_device *rdev;
14358 struct sk_buff *msg;
14359 void *hdr;
14360 u32 nlportid;
14361
Zhao, Gangf26cbf42014-04-21 12:53:03 +080014362 rdev = wiphy_to_rdev(wdev->wiphy);
Arend van Spriel5de17982013-04-18 15:49:00 +020014363 if (!rdev->crit_proto_nlportid)
14364 return;
14365
14366 nlportid = rdev->crit_proto_nlportid;
14367 rdev->crit_proto_nlportid = 0;
14368
14369 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
14370 if (!msg)
14371 return;
14372
14373 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CRIT_PROTOCOL_STOP);
14374 if (!hdr)
14375 goto nla_put_failure;
14376
14377 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020014378 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
14379 NL80211_ATTR_PAD))
Arend van Spriel5de17982013-04-18 15:49:00 +020014380 goto nla_put_failure;
14381
14382 genlmsg_end(msg, hdr);
14383
14384 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid);
14385 return;
14386
14387 nla_put_failure:
14388 if (hdr)
14389 genlmsg_cancel(msg, hdr);
14390 nlmsg_free(msg);
Arend van Spriel5de17982013-04-18 15:49:00 +020014391}
14392EXPORT_SYMBOL(cfg80211_crit_proto_stopped);
14393
Johannes Berg348baf02014-01-24 14:06:29 +010014394void nl80211_send_ap_stopped(struct wireless_dev *wdev)
14395{
14396 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080014397 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg348baf02014-01-24 14:06:29 +010014398 struct sk_buff *msg;
14399 void *hdr;
14400
14401 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
14402 if (!msg)
14403 return;
14404
14405 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_STOP_AP);
14406 if (!hdr)
14407 goto out;
14408
14409 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
14410 nla_put_u32(msg, NL80211_ATTR_IFINDEX, wdev->netdev->ifindex) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020014411 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
14412 NL80211_ATTR_PAD))
Johannes Berg348baf02014-01-24 14:06:29 +010014413 goto out;
14414
14415 genlmsg_end(msg, hdr);
14416
14417 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(wiphy), msg, 0,
14418 NL80211_MCGRP_MLME, GFP_KERNEL);
14419 return;
14420 out:
14421 nlmsg_free(msg);
14422}
14423
Johannes Berg55682962007-09-20 13:09:35 -040014424/* initialisation/exit functions */
14425
14426int nl80211_init(void)
14427{
Michał Mirosław0d63cbb2009-05-21 10:34:06 +000014428 int err;
Johannes Berg55682962007-09-20 13:09:35 -040014429
Johannes Berg2a94fe42013-11-19 15:19:39 +010014430 err = genl_register_family_with_ops_groups(&nl80211_fam, nl80211_ops,
14431 nl80211_mcgrps);
Johannes Berg55682962007-09-20 13:09:35 -040014432 if (err)
14433 return err;
14434
Jouni Malinen026331c2010-02-15 12:53:10 +020014435 err = netlink_register_notifier(&nl80211_netlink_notifier);
14436 if (err)
14437 goto err_out;
14438
Johannes Berg55682962007-09-20 13:09:35 -040014439 return 0;
14440 err_out:
14441 genl_unregister_family(&nl80211_fam);
14442 return err;
14443}
14444
14445void nl80211_exit(void)
14446{
Jouni Malinen026331c2010-02-15 12:53:10 +020014447 netlink_unregister_notifier(&nl80211_netlink_notifier);
Johannes Berg55682962007-09-20 13:09:35 -040014448 genl_unregister_family(&nl80211_fam);
14449}