blob: c11c1ef6daa720175eb697afce401ba01370ea7c [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 Berg7fee4772012-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 Berg7fee4772012-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 Berg7fee4772012-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 Berg7fee4772012-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 Berg7fee4772012-06-15 14:09:58 +0200176 else
177 tmp = NULL;
178
Johannes Berg7fee4772012-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 Malinen36aedc902008-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 Malinendc6382c2009-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 Berg2e161f72010-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 },
Johannes Berg55682962007-09-20 13:09:35 -0400412};
413
Johannes Berge31b8212010-10-05 19:39:30 +0200414/* policy for the key attributes */
Alexey Dobriyanb54452b2010-02-18 08:14:31 +0000415static const struct nla_policy nl80211_key_policy[NL80211_KEY_MAX + 1] = {
Johannes Bergfffd0932009-07-08 14:22:54 +0200416 [NL80211_KEY_DATA] = { .type = NLA_BINARY, .len = WLAN_MAX_KEY_LEN },
Johannes Bergb9454e82009-07-08 13:29:08 +0200417 [NL80211_KEY_IDX] = { .type = NLA_U8 },
418 [NL80211_KEY_CIPHER] = { .type = NLA_U32 },
Jouni Malinen81962262011-11-02 23:36:31 +0200419 [NL80211_KEY_SEQ] = { .type = NLA_BINARY, .len = 16 },
Johannes Bergb9454e82009-07-08 13:29:08 +0200420 [NL80211_KEY_DEFAULT] = { .type = NLA_FLAG },
421 [NL80211_KEY_DEFAULT_MGMT] = { .type = NLA_FLAG },
Johannes Berge31b8212010-10-05 19:39:30 +0200422 [NL80211_KEY_TYPE] = { .type = NLA_U32 },
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100423 [NL80211_KEY_DEFAULT_TYPES] = { .type = NLA_NESTED },
424};
425
426/* policy for the key default flags */
427static const struct nla_policy
428nl80211_key_default_policy[NUM_NL80211_KEY_DEFAULT_TYPES] = {
429 [NL80211_KEY_DEFAULT_TYPE_UNICAST] = { .type = NLA_FLAG },
430 [NL80211_KEY_DEFAULT_TYPE_MULTICAST] = { .type = NLA_FLAG },
Johannes Bergb9454e82009-07-08 13:29:08 +0200431};
432
Johannes Bergff1b6e62011-05-04 15:37:28 +0200433/* policy for WoWLAN attributes */
434static const struct nla_policy
435nl80211_wowlan_policy[NUM_NL80211_WOWLAN_TRIG] = {
436 [NL80211_WOWLAN_TRIG_ANY] = { .type = NLA_FLAG },
437 [NL80211_WOWLAN_TRIG_DISCONNECT] = { .type = NLA_FLAG },
438 [NL80211_WOWLAN_TRIG_MAGIC_PKT] = { .type = NLA_FLAG },
439 [NL80211_WOWLAN_TRIG_PKT_PATTERN] = { .type = NLA_NESTED },
Johannes Berg77dbbb12011-07-13 10:48:55 +0200440 [NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE] = { .type = NLA_FLAG },
441 [NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST] = { .type = NLA_FLAG },
442 [NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE] = { .type = NLA_FLAG },
443 [NL80211_WOWLAN_TRIG_RFKILL_RELEASE] = { .type = NLA_FLAG },
Johannes Berg2a0e0472013-01-23 22:57:40 +0100444 [NL80211_WOWLAN_TRIG_TCP_CONNECTION] = { .type = NLA_NESTED },
Luciano Coelho8cd4d452014-09-17 11:55:28 +0300445 [NL80211_WOWLAN_TRIG_NET_DETECT] = { .type = NLA_NESTED },
Johannes Berg2a0e0472013-01-23 22:57:40 +0100446};
447
448static const struct nla_policy
449nl80211_wowlan_tcp_policy[NUM_NL80211_WOWLAN_TCP] = {
450 [NL80211_WOWLAN_TCP_SRC_IPV4] = { .type = NLA_U32 },
451 [NL80211_WOWLAN_TCP_DST_IPV4] = { .type = NLA_U32 },
452 [NL80211_WOWLAN_TCP_DST_MAC] = { .len = ETH_ALEN },
453 [NL80211_WOWLAN_TCP_SRC_PORT] = { .type = NLA_U16 },
454 [NL80211_WOWLAN_TCP_DST_PORT] = { .type = NLA_U16 },
455 [NL80211_WOWLAN_TCP_DATA_PAYLOAD] = { .len = 1 },
456 [NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ] = {
457 .len = sizeof(struct nl80211_wowlan_tcp_data_seq)
458 },
459 [NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN] = {
460 .len = sizeof(struct nl80211_wowlan_tcp_data_token)
461 },
462 [NL80211_WOWLAN_TCP_DATA_INTERVAL] = { .type = NLA_U32 },
463 [NL80211_WOWLAN_TCP_WAKE_PAYLOAD] = { .len = 1 },
464 [NL80211_WOWLAN_TCP_WAKE_MASK] = { .len = 1 },
Johannes Bergff1b6e62011-05-04 15:37:28 +0200465};
466
Amitkumar Karwarbe29b992013-06-28 11:51:26 -0700467/* policy for coalesce rule attributes */
468static const struct nla_policy
469nl80211_coalesce_policy[NUM_NL80211_ATTR_COALESCE_RULE] = {
470 [NL80211_ATTR_COALESCE_RULE_DELAY] = { .type = NLA_U32 },
471 [NL80211_ATTR_COALESCE_RULE_CONDITION] = { .type = NLA_U32 },
472 [NL80211_ATTR_COALESCE_RULE_PKT_PATTERN] = { .type = NLA_NESTED },
473};
474
Johannes Berge5497d72011-07-05 16:35:40 +0200475/* policy for GTK rekey offload attributes */
476static const struct nla_policy
477nl80211_rekey_policy[NUM_NL80211_REKEY_DATA] = {
478 [NL80211_REKEY_DATA_KEK] = { .len = NL80211_KEK_LEN },
479 [NL80211_REKEY_DATA_KCK] = { .len = NL80211_KCK_LEN },
480 [NL80211_REKEY_DATA_REPLAY_CTR] = { .len = NL80211_REPLAY_CTR_LEN },
481};
482
Luciano Coelhoa1f1c212011-08-31 16:01:48 +0300483static const struct nla_policy
484nl80211_match_policy[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1] = {
Johannes Berg4a4ab0d2012-06-13 11:17:11 +0200485 [NL80211_SCHED_SCAN_MATCH_ATTR_SSID] = { .type = NLA_BINARY,
Luciano Coelhoa1f1c212011-08-31 16:01:48 +0300486 .len = IEEE80211_MAX_SSID_LEN },
Thomas Pedersen88e920b2012-06-21 11:09:54 -0700487 [NL80211_SCHED_SCAN_MATCH_ATTR_RSSI] = { .type = NLA_U32 },
Luciano Coelhoa1f1c212011-08-31 16:01:48 +0300488};
489
Avraham Stern3b06d272015-10-12 09:51:34 +0300490static const struct nla_policy
491nl80211_plan_policy[NL80211_SCHED_SCAN_PLAN_MAX + 1] = {
492 [NL80211_SCHED_SCAN_PLAN_INTERVAL] = { .type = NLA_U32 },
493 [NL80211_SCHED_SCAN_PLAN_ITERATIONS] = { .type = NLA_U32 },
494};
495
Arend van Spriel38de03d2016-03-02 20:37:18 +0100496static const struct nla_policy
497nl80211_bss_select_policy[NL80211_BSS_SELECT_ATTR_MAX + 1] = {
498 [NL80211_BSS_SELECT_ATTR_RSSI] = { .type = NLA_FLAG },
499 [NL80211_BSS_SELECT_ATTR_BAND_PREF] = { .type = NLA_U32 },
500 [NL80211_BSS_SELECT_ATTR_RSSI_ADJUST] = {
501 .len = sizeof(struct nl80211_bss_select_rssi_adjust)
502 },
503};
504
Johannes Berg97990a02013-04-19 01:02:55 +0200505static int nl80211_prepare_wdev_dump(struct sk_buff *skb,
506 struct netlink_callback *cb,
507 struct cfg80211_registered_device **rdev,
508 struct wireless_dev **wdev)
Holger Schuriga0438972009-11-11 11:30:02 +0100509{
Johannes Berg67748892010-10-04 21:14:06 +0200510 int err;
511
Johannes Berg67748892010-10-04 21:14:06 +0200512 rtnl_lock();
513
Johannes Berg97990a02013-04-19 01:02:55 +0200514 if (!cb->args[0]) {
515 err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize,
516 nl80211_fam.attrbuf, nl80211_fam.maxattr,
517 nl80211_policy);
518 if (err)
519 goto out_unlock;
520
521 *wdev = __cfg80211_wdev_from_attrs(sock_net(skb->sk),
522 nl80211_fam.attrbuf);
523 if (IS_ERR(*wdev)) {
524 err = PTR_ERR(*wdev);
525 goto out_unlock;
526 }
Zhao, Gangf26cbf42014-04-21 12:53:03 +0800527 *rdev = wiphy_to_rdev((*wdev)->wiphy);
Johannes Bergc319d502013-07-30 22:34:28 +0200528 /* 0 is the first index - add 1 to parse only once */
529 cb->args[0] = (*rdev)->wiphy_idx + 1;
Johannes Berg97990a02013-04-19 01:02:55 +0200530 cb->args[1] = (*wdev)->identifier;
531 } else {
Johannes Bergc319d502013-07-30 22:34:28 +0200532 /* subtract the 1 again here */
533 struct wiphy *wiphy = wiphy_idx_to_wiphy(cb->args[0] - 1);
Johannes Berg97990a02013-04-19 01:02:55 +0200534 struct wireless_dev *tmp;
535
536 if (!wiphy) {
537 err = -ENODEV;
538 goto out_unlock;
539 }
Zhao, Gangf26cbf42014-04-21 12:53:03 +0800540 *rdev = wiphy_to_rdev(wiphy);
Johannes Berg97990a02013-04-19 01:02:55 +0200541 *wdev = NULL;
542
Johannes Berg53873f12016-05-03 16:52:04 +0300543 list_for_each_entry(tmp, &(*rdev)->wiphy.wdev_list, list) {
Johannes Berg97990a02013-04-19 01:02:55 +0200544 if (tmp->identifier == cb->args[1]) {
545 *wdev = tmp;
546 break;
547 }
548 }
Johannes Berg97990a02013-04-19 01:02:55 +0200549
550 if (!*wdev) {
551 err = -ENODEV;
552 goto out_unlock;
553 }
Johannes Berg67748892010-10-04 21:14:06 +0200554 }
555
Johannes Berg67748892010-10-04 21:14:06 +0200556 return 0;
Johannes Berg97990a02013-04-19 01:02:55 +0200557 out_unlock:
Johannes Berg67748892010-10-04 21:14:06 +0200558 rtnl_unlock();
559 return err;
560}
561
Johannes Berg97990a02013-04-19 01:02:55 +0200562static void nl80211_finish_wdev_dump(struct cfg80211_registered_device *rdev)
Johannes Berg67748892010-10-04 21:14:06 +0200563{
Johannes Berg67748892010-10-04 21:14:06 +0200564 rtnl_unlock();
565}
566
Johannes Bergf4a11bb2009-03-27 12:40:28 +0100567/* IE validation */
568static bool is_valid_ie_attr(const struct nlattr *attr)
569{
570 const u8 *pos;
571 int len;
572
573 if (!attr)
574 return true;
575
576 pos = nla_data(attr);
577 len = nla_len(attr);
578
579 while (len) {
580 u8 elemlen;
581
582 if (len < 2)
583 return false;
584 len -= 2;
585
586 elemlen = pos[1];
587 if (elemlen > len)
588 return false;
589
590 len -= elemlen;
591 pos += 2 + elemlen;
592 }
593
594 return true;
595}
596
Johannes Berg55682962007-09-20 13:09:35 -0400597/* message building helper */
Eric W. Biederman15e47302012-09-07 20:12:54 +0000598static inline void *nl80211hdr_put(struct sk_buff *skb, u32 portid, u32 seq,
Johannes Berg55682962007-09-20 13:09:35 -0400599 int flags, u8 cmd)
600{
601 /* since there is no private header just add the generic one */
Eric W. Biederman15e47302012-09-07 20:12:54 +0000602 return genlmsg_put(skb, portid, seq, &nl80211_fam, flags, cmd);
Johannes Berg55682962007-09-20 13:09:35 -0400603}
604
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400605static int nl80211_msg_put_channel(struct sk_buff *msg,
Johannes Bergcdc89b92013-02-18 23:54:36 +0100606 struct ieee80211_channel *chan,
607 bool large)
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400608{
Rostislav Lisovyea077c12014-04-15 14:37:55 +0200609 /* Some channels must be completely excluded from the
610 * list to protect old user-space tools from breaking
611 */
612 if (!large && chan->flags &
613 (IEEE80211_CHAN_NO_10MHZ | IEEE80211_CHAN_NO_20MHZ))
614 return 0;
615
David S. Miller9360ffd2012-03-29 04:41:26 -0400616 if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_FREQ,
617 chan->center_freq))
618 goto nla_put_failure;
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400619
David S. Miller9360ffd2012-03-29 04:41:26 -0400620 if ((chan->flags & IEEE80211_CHAN_DISABLED) &&
621 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_DISABLED))
622 goto nla_put_failure;
Luis R. Rodriguez8fe02e12013-10-21 19:22:25 +0200623 if (chan->flags & IEEE80211_CHAN_NO_IR) {
624 if (nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_IR))
625 goto nla_put_failure;
626 if (nla_put_flag(msg, __NL80211_FREQUENCY_ATTR_NO_IBSS))
627 goto nla_put_failure;
628 }
Johannes Bergcdc89b92013-02-18 23:54:36 +0100629 if (chan->flags & IEEE80211_CHAN_RADAR) {
630 if (nla_put_flag(msg, NL80211_FREQUENCY_ATTR_RADAR))
631 goto nla_put_failure;
632 if (large) {
633 u32 time;
634
635 time = elapsed_jiffies_msecs(chan->dfs_state_entered);
636
637 if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_DFS_STATE,
638 chan->dfs_state))
639 goto nla_put_failure;
640 if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_DFS_TIME,
641 time))
642 goto nla_put_failure;
Janusz Dziedzic089027e2014-02-21 19:46:12 +0100643 if (nla_put_u32(msg,
644 NL80211_FREQUENCY_ATTR_DFS_CAC_TIME,
645 chan->dfs_cac_ms))
646 goto nla_put_failure;
Johannes Bergcdc89b92013-02-18 23:54:36 +0100647 }
648 }
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400649
Johannes Bergfe1abaf2013-02-27 15:39:45 +0100650 if (large) {
651 if ((chan->flags & IEEE80211_CHAN_NO_HT40MINUS) &&
652 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_HT40_MINUS))
653 goto nla_put_failure;
654 if ((chan->flags & IEEE80211_CHAN_NO_HT40PLUS) &&
655 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_HT40_PLUS))
656 goto nla_put_failure;
657 if ((chan->flags & IEEE80211_CHAN_NO_80MHZ) &&
658 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_80MHZ))
659 goto nla_put_failure;
660 if ((chan->flags & IEEE80211_CHAN_NO_160MHZ) &&
661 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_160MHZ))
662 goto nla_put_failure;
David Spinadel570dbde2014-02-23 09:12:59 +0200663 if ((chan->flags & IEEE80211_CHAN_INDOOR_ONLY) &&
664 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_INDOOR_ONLY))
665 goto nla_put_failure;
Arik Nemtsov06f207f2015-05-06 16:28:31 +0300666 if ((chan->flags & IEEE80211_CHAN_IR_CONCURRENT) &&
667 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_IR_CONCURRENT))
David Spinadel570dbde2014-02-23 09:12:59 +0200668 goto nla_put_failure;
Rostislav Lisovyea077c12014-04-15 14:37:55 +0200669 if ((chan->flags & IEEE80211_CHAN_NO_20MHZ) &&
670 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_20MHZ))
671 goto nla_put_failure;
672 if ((chan->flags & IEEE80211_CHAN_NO_10MHZ) &&
673 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_10MHZ))
674 goto nla_put_failure;
Johannes Bergfe1abaf2013-02-27 15:39:45 +0100675 }
676
David S. Miller9360ffd2012-03-29 04:41:26 -0400677 if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_MAX_TX_POWER,
678 DBM_TO_MBM(chan->max_power)))
679 goto nla_put_failure;
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400680
681 return 0;
682
683 nla_put_failure:
684 return -ENOBUFS;
685}
686
Johannes Berg55682962007-09-20 13:09:35 -0400687/* netlink command implementations */
688
Johannes Bergb9454e82009-07-08 13:29:08 +0200689struct key_parse {
690 struct key_params p;
691 int idx;
Johannes Berge31b8212010-10-05 19:39:30 +0200692 int type;
Johannes Bergb9454e82009-07-08 13:29:08 +0200693 bool def, defmgmt;
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100694 bool def_uni, def_multi;
Johannes Bergb9454e82009-07-08 13:29:08 +0200695};
696
697static int nl80211_parse_key_new(struct nlattr *key, struct key_parse *k)
698{
699 struct nlattr *tb[NL80211_KEY_MAX + 1];
700 int err = nla_parse_nested(tb, NL80211_KEY_MAX, key,
701 nl80211_key_policy);
702 if (err)
703 return err;
704
705 k->def = !!tb[NL80211_KEY_DEFAULT];
706 k->defmgmt = !!tb[NL80211_KEY_DEFAULT_MGMT];
707
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100708 if (k->def) {
709 k->def_uni = true;
710 k->def_multi = true;
711 }
712 if (k->defmgmt)
713 k->def_multi = true;
714
Johannes Bergb9454e82009-07-08 13:29:08 +0200715 if (tb[NL80211_KEY_IDX])
716 k->idx = nla_get_u8(tb[NL80211_KEY_IDX]);
717
718 if (tb[NL80211_KEY_DATA]) {
719 k->p.key = nla_data(tb[NL80211_KEY_DATA]);
720 k->p.key_len = nla_len(tb[NL80211_KEY_DATA]);
721 }
722
723 if (tb[NL80211_KEY_SEQ]) {
724 k->p.seq = nla_data(tb[NL80211_KEY_SEQ]);
725 k->p.seq_len = nla_len(tb[NL80211_KEY_SEQ]);
726 }
727
728 if (tb[NL80211_KEY_CIPHER])
729 k->p.cipher = nla_get_u32(tb[NL80211_KEY_CIPHER]);
730
Johannes Berge31b8212010-10-05 19:39:30 +0200731 if (tb[NL80211_KEY_TYPE]) {
732 k->type = nla_get_u32(tb[NL80211_KEY_TYPE]);
733 if (k->type < 0 || k->type >= NUM_NL80211_KEYTYPES)
734 return -EINVAL;
735 }
736
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100737 if (tb[NL80211_KEY_DEFAULT_TYPES]) {
738 struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES];
Kirtika Ruchandani7a087e72016-05-29 19:51:23 -0700739
Johannes Berg2da8f412012-01-20 13:52:37 +0100740 err = nla_parse_nested(kdt, NUM_NL80211_KEY_DEFAULT_TYPES - 1,
741 tb[NL80211_KEY_DEFAULT_TYPES],
742 nl80211_key_default_policy);
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100743 if (err)
744 return err;
745
746 k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST];
747 k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST];
748 }
749
Johannes Bergb9454e82009-07-08 13:29:08 +0200750 return 0;
751}
752
753static int nl80211_parse_key_old(struct genl_info *info, struct key_parse *k)
754{
755 if (info->attrs[NL80211_ATTR_KEY_DATA]) {
756 k->p.key = nla_data(info->attrs[NL80211_ATTR_KEY_DATA]);
757 k->p.key_len = nla_len(info->attrs[NL80211_ATTR_KEY_DATA]);
758 }
759
760 if (info->attrs[NL80211_ATTR_KEY_SEQ]) {
761 k->p.seq = nla_data(info->attrs[NL80211_ATTR_KEY_SEQ]);
762 k->p.seq_len = nla_len(info->attrs[NL80211_ATTR_KEY_SEQ]);
763 }
764
765 if (info->attrs[NL80211_ATTR_KEY_IDX])
766 k->idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]);
767
768 if (info->attrs[NL80211_ATTR_KEY_CIPHER])
769 k->p.cipher = nla_get_u32(info->attrs[NL80211_ATTR_KEY_CIPHER]);
770
771 k->def = !!info->attrs[NL80211_ATTR_KEY_DEFAULT];
772 k->defmgmt = !!info->attrs[NL80211_ATTR_KEY_DEFAULT_MGMT];
773
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100774 if (k->def) {
775 k->def_uni = true;
776 k->def_multi = true;
777 }
778 if (k->defmgmt)
779 k->def_multi = true;
780
Johannes Berge31b8212010-10-05 19:39:30 +0200781 if (info->attrs[NL80211_ATTR_KEY_TYPE]) {
782 k->type = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]);
783 if (k->type < 0 || k->type >= NUM_NL80211_KEYTYPES)
784 return -EINVAL;
785 }
786
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100787 if (info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES]) {
788 struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES];
789 int err = nla_parse_nested(
790 kdt, NUM_NL80211_KEY_DEFAULT_TYPES - 1,
791 info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES],
792 nl80211_key_default_policy);
793 if (err)
794 return err;
795
796 k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST];
797 k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST];
798 }
799
Johannes Bergb9454e82009-07-08 13:29:08 +0200800 return 0;
801}
802
803static int nl80211_parse_key(struct genl_info *info, struct key_parse *k)
804{
805 int err;
806
807 memset(k, 0, sizeof(*k));
808 k->idx = -1;
Johannes Berge31b8212010-10-05 19:39:30 +0200809 k->type = -1;
Johannes Bergb9454e82009-07-08 13:29:08 +0200810
811 if (info->attrs[NL80211_ATTR_KEY])
812 err = nl80211_parse_key_new(info->attrs[NL80211_ATTR_KEY], k);
813 else
814 err = nl80211_parse_key_old(info, k);
815
816 if (err)
817 return err;
818
819 if (k->def && k->defmgmt)
820 return -EINVAL;
821
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100822 if (k->defmgmt) {
823 if (k->def_uni || !k->def_multi)
824 return -EINVAL;
825 }
826
Johannes Bergb9454e82009-07-08 13:29:08 +0200827 if (k->idx != -1) {
828 if (k->defmgmt) {
829 if (k->idx < 4 || k->idx > 5)
830 return -EINVAL;
831 } else if (k->def) {
832 if (k->idx < 0 || k->idx > 3)
833 return -EINVAL;
834 } else {
835 if (k->idx < 0 || k->idx > 5)
836 return -EINVAL;
837 }
838 }
839
840 return 0;
841}
842
Johannes Bergfffd0932009-07-08 14:22:54 +0200843static struct cfg80211_cached_keys *
844nl80211_parse_connkeys(struct cfg80211_registered_device *rdev,
Sujith Manoharande7044e2012-10-18 10:19:28 +0530845 struct nlattr *keys, bool *no_ht)
Johannes Bergfffd0932009-07-08 14:22:54 +0200846{
847 struct key_parse parse;
848 struct nlattr *key;
849 struct cfg80211_cached_keys *result;
850 int rem, err, def = 0;
851
852 result = kzalloc(sizeof(*result), GFP_KERNEL);
853 if (!result)
854 return ERR_PTR(-ENOMEM);
855
856 result->def = -1;
857 result->defmgmt = -1;
858
859 nla_for_each_nested(key, keys, rem) {
860 memset(&parse, 0, sizeof(parse));
861 parse.idx = -1;
862
863 err = nl80211_parse_key_new(key, &parse);
864 if (err)
865 goto error;
866 err = -EINVAL;
867 if (!parse.p.key)
868 goto error;
869 if (parse.idx < 0 || parse.idx > 4)
870 goto error;
871 if (parse.def) {
872 if (def)
873 goto error;
874 def = 1;
875 result->def = parse.idx;
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100876 if (!parse.def_uni || !parse.def_multi)
877 goto error;
Johannes Bergfffd0932009-07-08 14:22:54 +0200878 } else if (parse.defmgmt)
879 goto error;
880 err = cfg80211_validate_key_settings(rdev, &parse.p,
Johannes Berge31b8212010-10-05 19:39:30 +0200881 parse.idx, false, NULL);
Johannes Bergfffd0932009-07-08 14:22:54 +0200882 if (err)
883 goto error;
884 result->params[parse.idx].cipher = parse.p.cipher;
885 result->params[parse.idx].key_len = parse.p.key_len;
886 result->params[parse.idx].key = result->data[parse.idx];
887 memcpy(result->data[parse.idx], parse.p.key, parse.p.key_len);
Sujith Manoharande7044e2012-10-18 10:19:28 +0530888
889 if (parse.p.cipher == WLAN_CIPHER_SUITE_WEP40 ||
890 parse.p.cipher == WLAN_CIPHER_SUITE_WEP104) {
891 if (no_ht)
892 *no_ht = true;
893 }
Johannes Bergfffd0932009-07-08 14:22:54 +0200894 }
895
896 return result;
897 error:
898 kfree(result);
899 return ERR_PTR(err);
900}
901
902static int nl80211_key_allowed(struct wireless_dev *wdev)
903{
904 ASSERT_WDEV_LOCK(wdev);
905
Johannes Bergfffd0932009-07-08 14:22:54 +0200906 switch (wdev->iftype) {
907 case NL80211_IFTYPE_AP:
908 case NL80211_IFTYPE_AP_VLAN:
Johannes Berg074ac8d2010-09-16 14:58:22 +0200909 case NL80211_IFTYPE_P2P_GO:
Thomas Pedersenff973af2011-05-03 16:57:12 -0700910 case NL80211_IFTYPE_MESH_POINT:
Johannes Bergfffd0932009-07-08 14:22:54 +0200911 break;
912 case NL80211_IFTYPE_ADHOC:
Johannes Bergfffd0932009-07-08 14:22:54 +0200913 case NL80211_IFTYPE_STATION:
Johannes Berg074ac8d2010-09-16 14:58:22 +0200914 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Bergceca7b72013-05-16 00:55:45 +0200915 if (!wdev->current_bss)
Johannes Bergfffd0932009-07-08 14:22:54 +0200916 return -ENOLINK;
917 break;
Johannes Bergde4fcba2014-10-31 14:16:12 +0100918 case NL80211_IFTYPE_UNSPECIFIED:
Rostislav Lisovy6e0bd6c2014-11-03 10:33:18 +0100919 case NL80211_IFTYPE_OCB:
Johannes Bergde4fcba2014-10-31 14:16:12 +0100920 case NL80211_IFTYPE_MONITOR:
921 case NL80211_IFTYPE_P2P_DEVICE:
922 case NL80211_IFTYPE_WDS:
923 case NUM_NL80211_IFTYPES:
Johannes Bergfffd0932009-07-08 14:22:54 +0200924 return -EINVAL;
925 }
926
927 return 0;
928}
929
Jouni Malinen664834d2014-01-15 00:01:44 +0200930static struct ieee80211_channel *nl80211_get_valid_chan(struct wiphy *wiphy,
931 struct nlattr *tb)
932{
933 struct ieee80211_channel *chan;
934
935 if (tb == NULL)
936 return NULL;
937 chan = ieee80211_get_channel(wiphy, nla_get_u32(tb));
938 if (!chan || chan->flags & IEEE80211_CHAN_DISABLED)
939 return NULL;
940 return chan;
941}
942
Johannes Berg7527a782011-05-13 10:58:57 +0200943static int nl80211_put_iftypes(struct sk_buff *msg, u32 attr, u16 ifmodes)
944{
945 struct nlattr *nl_modes = nla_nest_start(msg, attr);
946 int i;
947
948 if (!nl_modes)
949 goto nla_put_failure;
950
951 i = 0;
952 while (ifmodes) {
David S. Miller9360ffd2012-03-29 04:41:26 -0400953 if ((ifmodes & 1) && nla_put_flag(msg, i))
954 goto nla_put_failure;
Johannes Berg7527a782011-05-13 10:58:57 +0200955 ifmodes >>= 1;
956 i++;
957 }
958
959 nla_nest_end(msg, nl_modes);
960 return 0;
961
962nla_put_failure:
963 return -ENOBUFS;
964}
965
966static int nl80211_put_iface_combinations(struct wiphy *wiphy,
Johannes Bergcdc89b92013-02-18 23:54:36 +0100967 struct sk_buff *msg,
968 bool large)
Johannes Berg7527a782011-05-13 10:58:57 +0200969{
970 struct nlattr *nl_combis;
971 int i, j;
972
973 nl_combis = nla_nest_start(msg,
974 NL80211_ATTR_INTERFACE_COMBINATIONS);
975 if (!nl_combis)
976 goto nla_put_failure;
977
978 for (i = 0; i < wiphy->n_iface_combinations; i++) {
979 const struct ieee80211_iface_combination *c;
980 struct nlattr *nl_combi, *nl_limits;
981
982 c = &wiphy->iface_combinations[i];
983
984 nl_combi = nla_nest_start(msg, i + 1);
985 if (!nl_combi)
986 goto nla_put_failure;
987
988 nl_limits = nla_nest_start(msg, NL80211_IFACE_COMB_LIMITS);
989 if (!nl_limits)
990 goto nla_put_failure;
991
992 for (j = 0; j < c->n_limits; j++) {
993 struct nlattr *nl_limit;
994
995 nl_limit = nla_nest_start(msg, j + 1);
996 if (!nl_limit)
997 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -0400998 if (nla_put_u32(msg, NL80211_IFACE_LIMIT_MAX,
999 c->limits[j].max))
1000 goto nla_put_failure;
Johannes Berg7527a782011-05-13 10:58:57 +02001001 if (nl80211_put_iftypes(msg, NL80211_IFACE_LIMIT_TYPES,
1002 c->limits[j].types))
1003 goto nla_put_failure;
1004 nla_nest_end(msg, nl_limit);
1005 }
1006
1007 nla_nest_end(msg, nl_limits);
1008
David S. Miller9360ffd2012-03-29 04:41:26 -04001009 if (c->beacon_int_infra_match &&
1010 nla_put_flag(msg, NL80211_IFACE_COMB_STA_AP_BI_MATCH))
1011 goto nla_put_failure;
1012 if (nla_put_u32(msg, NL80211_IFACE_COMB_NUM_CHANNELS,
1013 c->num_different_channels) ||
1014 nla_put_u32(msg, NL80211_IFACE_COMB_MAXNUM,
1015 c->max_interfaces))
1016 goto nla_put_failure;
Johannes Bergcdc89b92013-02-18 23:54:36 +01001017 if (large &&
Felix Fietkau8c48b502014-05-05 11:48:40 +02001018 (nla_put_u32(msg, NL80211_IFACE_COMB_RADAR_DETECT_WIDTHS,
1019 c->radar_detect_widths) ||
1020 nla_put_u32(msg, NL80211_IFACE_COMB_RADAR_DETECT_REGIONS,
1021 c->radar_detect_regions)))
Johannes Bergcdc89b92013-02-18 23:54:36 +01001022 goto nla_put_failure;
Johannes Berg7527a782011-05-13 10:58:57 +02001023
1024 nla_nest_end(msg, nl_combi);
1025 }
1026
1027 nla_nest_end(msg, nl_combis);
1028
1029 return 0;
1030nla_put_failure:
1031 return -ENOBUFS;
1032}
1033
Johannes Berg3713b4e2013-02-14 16:19:38 +01001034#ifdef CONFIG_PM
Johannes Bergb56cf722013-02-20 01:02:38 +01001035static int nl80211_send_wowlan_tcp_caps(struct cfg80211_registered_device *rdev,
1036 struct sk_buff *msg)
1037{
Johannes Berg964dc9e2013-06-03 17:25:34 +02001038 const struct wiphy_wowlan_tcp_support *tcp = rdev->wiphy.wowlan->tcp;
Johannes Bergb56cf722013-02-20 01:02:38 +01001039 struct nlattr *nl_tcp;
1040
1041 if (!tcp)
1042 return 0;
1043
1044 nl_tcp = nla_nest_start(msg, NL80211_WOWLAN_TRIG_TCP_CONNECTION);
1045 if (!nl_tcp)
1046 return -ENOBUFS;
1047
1048 if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD,
1049 tcp->data_payload_max))
1050 return -ENOBUFS;
1051
1052 if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD,
1053 tcp->data_payload_max))
1054 return -ENOBUFS;
1055
1056 if (tcp->seq && nla_put_flag(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ))
1057 return -ENOBUFS;
1058
1059 if (tcp->tok && nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN,
1060 sizeof(*tcp->tok), tcp->tok))
1061 return -ENOBUFS;
1062
1063 if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_INTERVAL,
1064 tcp->data_interval_max))
1065 return -ENOBUFS;
1066
1067 if (nla_put_u32(msg, NL80211_WOWLAN_TCP_WAKE_PAYLOAD,
1068 tcp->wake_payload_max))
1069 return -ENOBUFS;
1070
1071 nla_nest_end(msg, nl_tcp);
1072 return 0;
1073}
1074
Johannes Berg3713b4e2013-02-14 16:19:38 +01001075static int nl80211_send_wowlan(struct sk_buff *msg,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001076 struct cfg80211_registered_device *rdev,
Johannes Bergb56cf722013-02-20 01:02:38 +01001077 bool large)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001078{
1079 struct nlattr *nl_wowlan;
1080
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001081 if (!rdev->wiphy.wowlan)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001082 return 0;
1083
1084 nl_wowlan = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS_SUPPORTED);
1085 if (!nl_wowlan)
1086 return -ENOBUFS;
1087
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001088 if (((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_ANY) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001089 nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) ||
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001090 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_DISCONNECT) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001091 nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) ||
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001092 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001093 nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) ||
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001094 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_SUPPORTS_GTK_REKEY) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001095 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED)) ||
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001096 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001097 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) ||
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001098 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001099 nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) ||
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001100 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001101 nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) ||
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001102 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001103 nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE)))
1104 return -ENOBUFS;
1105
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001106 if (rdev->wiphy.wowlan->n_patterns) {
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07001107 struct nl80211_pattern_support pat = {
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001108 .max_patterns = rdev->wiphy.wowlan->n_patterns,
1109 .min_pattern_len = rdev->wiphy.wowlan->pattern_min_len,
1110 .max_pattern_len = rdev->wiphy.wowlan->pattern_max_len,
1111 .max_pkt_offset = rdev->wiphy.wowlan->max_pkt_offset,
Johannes Berg3713b4e2013-02-14 16:19:38 +01001112 };
1113
1114 if (nla_put(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN,
1115 sizeof(pat), &pat))
1116 return -ENOBUFS;
1117 }
1118
Luciano Coelho75453cc2015-01-09 14:06:37 +02001119 if ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_NET_DETECT) &&
1120 nla_put_u32(msg, NL80211_WOWLAN_TRIG_NET_DETECT,
1121 rdev->wiphy.wowlan->max_nd_match_sets))
1122 return -ENOBUFS;
1123
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001124 if (large && nl80211_send_wowlan_tcp_caps(rdev, msg))
Johannes Bergb56cf722013-02-20 01:02:38 +01001125 return -ENOBUFS;
1126
Johannes Berg3713b4e2013-02-14 16:19:38 +01001127 nla_nest_end(msg, nl_wowlan);
1128
1129 return 0;
1130}
1131#endif
1132
Amitkumar Karwarbe29b992013-06-28 11:51:26 -07001133static int nl80211_send_coalesce(struct sk_buff *msg,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001134 struct cfg80211_registered_device *rdev)
Amitkumar Karwarbe29b992013-06-28 11:51:26 -07001135{
1136 struct nl80211_coalesce_rule_support rule;
1137
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001138 if (!rdev->wiphy.coalesce)
Amitkumar Karwarbe29b992013-06-28 11:51:26 -07001139 return 0;
1140
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001141 rule.max_rules = rdev->wiphy.coalesce->n_rules;
1142 rule.max_delay = rdev->wiphy.coalesce->max_delay;
1143 rule.pat.max_patterns = rdev->wiphy.coalesce->n_patterns;
1144 rule.pat.min_pattern_len = rdev->wiphy.coalesce->pattern_min_len;
1145 rule.pat.max_pattern_len = rdev->wiphy.coalesce->pattern_max_len;
1146 rule.pat.max_pkt_offset = rdev->wiphy.coalesce->max_pkt_offset;
Amitkumar Karwarbe29b992013-06-28 11:51:26 -07001147
1148 if (nla_put(msg, NL80211_ATTR_COALESCE_RULE, sizeof(rule), &rule))
1149 return -ENOBUFS;
1150
1151 return 0;
1152}
1153
Johannes Berg3713b4e2013-02-14 16:19:38 +01001154static int nl80211_send_band_rateinfo(struct sk_buff *msg,
1155 struct ieee80211_supported_band *sband)
1156{
1157 struct nlattr *nl_rates, *nl_rate;
1158 struct ieee80211_rate *rate;
1159 int i;
1160
1161 /* add HT info */
1162 if (sband->ht_cap.ht_supported &&
1163 (nla_put(msg, NL80211_BAND_ATTR_HT_MCS_SET,
1164 sizeof(sband->ht_cap.mcs),
1165 &sband->ht_cap.mcs) ||
1166 nla_put_u16(msg, NL80211_BAND_ATTR_HT_CAPA,
1167 sband->ht_cap.cap) ||
1168 nla_put_u8(msg, NL80211_BAND_ATTR_HT_AMPDU_FACTOR,
1169 sband->ht_cap.ampdu_factor) ||
1170 nla_put_u8(msg, NL80211_BAND_ATTR_HT_AMPDU_DENSITY,
1171 sband->ht_cap.ampdu_density)))
1172 return -ENOBUFS;
1173
1174 /* add VHT info */
1175 if (sband->vht_cap.vht_supported &&
1176 (nla_put(msg, NL80211_BAND_ATTR_VHT_MCS_SET,
1177 sizeof(sband->vht_cap.vht_mcs),
1178 &sband->vht_cap.vht_mcs) ||
1179 nla_put_u32(msg, NL80211_BAND_ATTR_VHT_CAPA,
1180 sband->vht_cap.cap)))
1181 return -ENOBUFS;
1182
1183 /* add bitrates */
1184 nl_rates = nla_nest_start(msg, NL80211_BAND_ATTR_RATES);
1185 if (!nl_rates)
1186 return -ENOBUFS;
1187
1188 for (i = 0; i < sband->n_bitrates; i++) {
1189 nl_rate = nla_nest_start(msg, i);
1190 if (!nl_rate)
1191 return -ENOBUFS;
1192
1193 rate = &sband->bitrates[i];
1194 if (nla_put_u32(msg, NL80211_BITRATE_ATTR_RATE,
1195 rate->bitrate))
1196 return -ENOBUFS;
1197 if ((rate->flags & IEEE80211_RATE_SHORT_PREAMBLE) &&
1198 nla_put_flag(msg,
1199 NL80211_BITRATE_ATTR_2GHZ_SHORTPREAMBLE))
1200 return -ENOBUFS;
1201
1202 nla_nest_end(msg, nl_rate);
1203 }
1204
1205 nla_nest_end(msg, nl_rates);
1206
1207 return 0;
1208}
1209
1210static int
1211nl80211_send_mgmt_stypes(struct sk_buff *msg,
1212 const struct ieee80211_txrx_stypes *mgmt_stypes)
1213{
1214 u16 stypes;
1215 struct nlattr *nl_ftypes, *nl_ifs;
1216 enum nl80211_iftype ift;
1217 int i;
1218
1219 if (!mgmt_stypes)
1220 return 0;
1221
1222 nl_ifs = nla_nest_start(msg, NL80211_ATTR_TX_FRAME_TYPES);
1223 if (!nl_ifs)
1224 return -ENOBUFS;
1225
1226 for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) {
1227 nl_ftypes = nla_nest_start(msg, ift);
1228 if (!nl_ftypes)
1229 return -ENOBUFS;
1230 i = 0;
1231 stypes = mgmt_stypes[ift].tx;
1232 while (stypes) {
1233 if ((stypes & 1) &&
1234 nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE,
1235 (i << 4) | IEEE80211_FTYPE_MGMT))
1236 return -ENOBUFS;
1237 stypes >>= 1;
1238 i++;
1239 }
1240 nla_nest_end(msg, nl_ftypes);
1241 }
1242
1243 nla_nest_end(msg, nl_ifs);
1244
1245 nl_ifs = nla_nest_start(msg, NL80211_ATTR_RX_FRAME_TYPES);
1246 if (!nl_ifs)
1247 return -ENOBUFS;
1248
1249 for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) {
1250 nl_ftypes = nla_nest_start(msg, ift);
1251 if (!nl_ftypes)
1252 return -ENOBUFS;
1253 i = 0;
1254 stypes = mgmt_stypes[ift].rx;
1255 while (stypes) {
1256 if ((stypes & 1) &&
1257 nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE,
1258 (i << 4) | IEEE80211_FTYPE_MGMT))
1259 return -ENOBUFS;
1260 stypes >>= 1;
1261 i++;
1262 }
1263 nla_nest_end(msg, nl_ftypes);
1264 }
1265 nla_nest_end(msg, nl_ifs);
1266
1267 return 0;
1268}
1269
Johannes Berg86e8cf92013-06-19 10:57:22 +02001270struct nl80211_dump_wiphy_state {
1271 s64 filter_wiphy;
1272 long start;
Kanchanapally, Vidyullatha019ae3a2016-05-16 10:41:04 +05301273 long split_start, band_start, chan_start, capa_start;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001274 bool split;
1275};
1276
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001277static int nl80211_send_wiphy(struct cfg80211_registered_device *rdev,
Johannes Berg3bb20552014-05-26 13:52:25 +02001278 enum nl80211_commands cmd,
Johannes Berg3713b4e2013-02-14 16:19:38 +01001279 struct sk_buff *msg, u32 portid, u32 seq,
Johannes Berg86e8cf92013-06-19 10:57:22 +02001280 int flags, struct nl80211_dump_wiphy_state *state)
Johannes Berg55682962007-09-20 13:09:35 -04001281{
1282 void *hdr;
Johannes Bergee688b002008-01-24 19:38:39 +01001283 struct nlattr *nl_bands, *nl_band;
1284 struct nlattr *nl_freqs, *nl_freq;
Johannes Berg8fdc6212009-03-14 09:34:01 +01001285 struct nlattr *nl_cmds;
Johannes Berg57fbcce2016-04-12 15:56:15 +02001286 enum nl80211_band band;
Johannes Bergee688b002008-01-24 19:38:39 +01001287 struct ieee80211_channel *chan;
Johannes Bergee688b002008-01-24 19:38:39 +01001288 int i;
Johannes Berg2e161f72010-08-12 15:38:38 +02001289 const struct ieee80211_txrx_stypes *mgmt_stypes =
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001290 rdev->wiphy.mgmt_stypes;
Johannes Bergfe1abaf2013-02-27 15:39:45 +01001291 u32 features;
Johannes Berg55682962007-09-20 13:09:35 -04001292
Johannes Berg3bb20552014-05-26 13:52:25 +02001293 hdr = nl80211hdr_put(msg, portid, seq, flags, cmd);
Johannes Berg55682962007-09-20 13:09:35 -04001294 if (!hdr)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001295 return -ENOBUFS;
1296
Johannes Berg86e8cf92013-06-19 10:57:22 +02001297 if (WARN_ON(!state))
1298 return -EINVAL;
Johannes Berg55682962007-09-20 13:09:35 -04001299
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001300 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001301 nla_put_string(msg, NL80211_ATTR_WIPHY_NAME,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001302 wiphy_name(&rdev->wiphy)) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04001303 nla_put_u32(msg, NL80211_ATTR_GENERATION,
Johannes Berg3713b4e2013-02-14 16:19:38 +01001304 cfg80211_rdev_list_generation))
David S. Miller9360ffd2012-03-29 04:41:26 -04001305 goto nla_put_failure;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02001306
Johannes Berg3bb20552014-05-26 13:52:25 +02001307 if (cmd != NL80211_CMD_NEW_WIPHY)
1308 goto finish;
1309
Johannes Berg86e8cf92013-06-19 10:57:22 +02001310 switch (state->split_start) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001311 case 0:
1312 if (nla_put_u8(msg, NL80211_ATTR_WIPHY_RETRY_SHORT,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001313 rdev->wiphy.retry_short) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001314 nla_put_u8(msg, NL80211_ATTR_WIPHY_RETRY_LONG,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001315 rdev->wiphy.retry_long) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001316 nla_put_u32(msg, NL80211_ATTR_WIPHY_FRAG_THRESHOLD,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001317 rdev->wiphy.frag_threshold) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001318 nla_put_u32(msg, NL80211_ATTR_WIPHY_RTS_THRESHOLD,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001319 rdev->wiphy.rts_threshold) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001320 nla_put_u8(msg, NL80211_ATTR_WIPHY_COVERAGE_CLASS,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001321 rdev->wiphy.coverage_class) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001322 nla_put_u8(msg, NL80211_ATTR_MAX_NUM_SCAN_SSIDS,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001323 rdev->wiphy.max_scan_ssids) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001324 nla_put_u8(msg, NL80211_ATTR_MAX_NUM_SCHED_SCAN_SSIDS,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001325 rdev->wiphy.max_sched_scan_ssids) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001326 nla_put_u16(msg, NL80211_ATTR_MAX_SCAN_IE_LEN,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001327 rdev->wiphy.max_scan_ie_len) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001328 nla_put_u16(msg, NL80211_ATTR_MAX_SCHED_SCAN_IE_LEN,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001329 rdev->wiphy.max_sched_scan_ie_len) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001330 nla_put_u8(msg, NL80211_ATTR_MAX_MATCH_SETS,
Avraham Stern3b06d272015-10-12 09:51:34 +03001331 rdev->wiphy.max_match_sets) ||
1332 nla_put_u32(msg, NL80211_ATTR_MAX_NUM_SCHED_SCAN_PLANS,
1333 rdev->wiphy.max_sched_scan_plans) ||
1334 nla_put_u32(msg, NL80211_ATTR_MAX_SCAN_PLAN_INTERVAL,
1335 rdev->wiphy.max_sched_scan_plan_interval) ||
1336 nla_put_u32(msg, NL80211_ATTR_MAX_SCAN_PLAN_ITERATIONS,
1337 rdev->wiphy.max_sched_scan_plan_iterations))
Johannes Bergee688b002008-01-24 19:38:39 +01001338 goto nla_put_failure;
1339
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001340 if ((rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001341 nla_put_flag(msg, NL80211_ATTR_SUPPORT_IBSS_RSN))
1342 goto nla_put_failure;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001343 if ((rdev->wiphy.flags & WIPHY_FLAG_MESH_AUTH) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001344 nla_put_flag(msg, NL80211_ATTR_SUPPORT_MESH_AUTH))
1345 goto nla_put_failure;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001346 if ((rdev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001347 nla_put_flag(msg, NL80211_ATTR_SUPPORT_AP_UAPSD))
1348 goto nla_put_failure;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001349 if ((rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_FW_ROAM) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001350 nla_put_flag(msg, NL80211_ATTR_ROAM_SUPPORT))
1351 goto nla_put_failure;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001352 if ((rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001353 nla_put_flag(msg, NL80211_ATTR_TDLS_SUPPORT))
1354 goto nla_put_failure;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001355 if ((rdev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001356 nla_put_flag(msg, NL80211_ATTR_TDLS_EXTERNAL_SETUP))
David S. Miller9360ffd2012-03-29 04:41:26 -04001357 goto nla_put_failure;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001358 state->split_start++;
1359 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001360 break;
1361 case 1:
1362 if (nla_put(msg, NL80211_ATTR_CIPHER_SUITES,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001363 sizeof(u32) * rdev->wiphy.n_cipher_suites,
1364 rdev->wiphy.cipher_suites))
Mahesh Palivelabf0c111e2012-06-22 07:27:46 +00001365 goto nla_put_failure;
1366
Johannes Berg3713b4e2013-02-14 16:19:38 +01001367 if (nla_put_u8(msg, NL80211_ATTR_MAX_NUM_PMKIDS,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001368 rdev->wiphy.max_num_pmkids))
Johannes Bergee688b002008-01-24 19:38:39 +01001369 goto nla_put_failure;
1370
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001371 if ((rdev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001372 nla_put_flag(msg, NL80211_ATTR_CONTROL_PORT_ETHERTYPE))
1373 goto nla_put_failure;
Johannes Bergee688b002008-01-24 19:38:39 +01001374
Johannes Berg3713b4e2013-02-14 16:19:38 +01001375 if (nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_TX,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001376 rdev->wiphy.available_antennas_tx) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001377 nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_RX,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001378 rdev->wiphy.available_antennas_rx))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001379 goto nla_put_failure;
Johannes Bergee688b002008-01-24 19:38:39 +01001380
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001381 if ((rdev->wiphy.flags & WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001382 nla_put_u32(msg, NL80211_ATTR_PROBE_RESP_OFFLOAD,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001383 rdev->wiphy.probe_resp_offload))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001384 goto nla_put_failure;
Jouni Malinene2f367f262008-11-21 19:01:30 +02001385
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001386 if ((rdev->wiphy.available_antennas_tx ||
1387 rdev->wiphy.available_antennas_rx) &&
1388 rdev->ops->get_antenna) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001389 u32 tx_ant = 0, rx_ant = 0;
1390 int res;
Kirtika Ruchandani7a087e72016-05-29 19:51:23 -07001391
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001392 res = rdev_get_antenna(rdev, &tx_ant, &rx_ant);
Johannes Berg3713b4e2013-02-14 16:19:38 +01001393 if (!res) {
1394 if (nla_put_u32(msg,
1395 NL80211_ATTR_WIPHY_ANTENNA_TX,
1396 tx_ant) ||
1397 nla_put_u32(msg,
1398 NL80211_ATTR_WIPHY_ANTENNA_RX,
1399 rx_ant))
1400 goto nla_put_failure;
1401 }
Johannes Bergee688b002008-01-24 19:38:39 +01001402 }
1403
Johannes Berg86e8cf92013-06-19 10:57:22 +02001404 state->split_start++;
1405 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001406 break;
1407 case 2:
1408 if (nl80211_put_iftypes(msg, NL80211_ATTR_SUPPORTED_IFTYPES,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001409 rdev->wiphy.interface_modes))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001410 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 3:
1415 nl_bands = nla_nest_start(msg, NL80211_ATTR_WIPHY_BANDS);
1416 if (!nl_bands)
Johannes Bergee688b002008-01-24 19:38:39 +01001417 goto nla_put_failure;
1418
Johannes Berg86e8cf92013-06-19 10:57:22 +02001419 for (band = state->band_start;
Johannes Berg57fbcce2016-04-12 15:56:15 +02001420 band < NUM_NL80211_BANDS; band++) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001421 struct ieee80211_supported_band *sband;
1422
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001423 sband = rdev->wiphy.bands[band];
Johannes Berg3713b4e2013-02-14 16:19:38 +01001424
1425 if (!sband)
1426 continue;
1427
1428 nl_band = nla_nest_start(msg, band);
1429 if (!nl_band)
Johannes Bergee688b002008-01-24 19:38:39 +01001430 goto nla_put_failure;
1431
Johannes Berg86e8cf92013-06-19 10:57:22 +02001432 switch (state->chan_start) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001433 case 0:
1434 if (nl80211_send_band_rateinfo(msg, sband))
1435 goto nla_put_failure;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001436 state->chan_start++;
1437 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001438 break;
1439 default:
1440 /* add frequencies */
1441 nl_freqs = nla_nest_start(
1442 msg, NL80211_BAND_ATTR_FREQS);
1443 if (!nl_freqs)
1444 goto nla_put_failure;
Johannes Bergee688b002008-01-24 19:38:39 +01001445
Johannes Berg86e8cf92013-06-19 10:57:22 +02001446 for (i = state->chan_start - 1;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001447 i < sband->n_channels;
1448 i++) {
1449 nl_freq = nla_nest_start(msg, i);
1450 if (!nl_freq)
1451 goto nla_put_failure;
1452
1453 chan = &sband->channels[i];
1454
Johannes Berg86e8cf92013-06-19 10:57:22 +02001455 if (nl80211_msg_put_channel(
1456 msg, chan,
1457 state->split))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001458 goto nla_put_failure;
1459
1460 nla_nest_end(msg, nl_freq);
Johannes Berg86e8cf92013-06-19 10:57:22 +02001461 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001462 break;
1463 }
1464 if (i < sband->n_channels)
Johannes Berg86e8cf92013-06-19 10:57:22 +02001465 state->chan_start = i + 2;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001466 else
Johannes Berg86e8cf92013-06-19 10:57:22 +02001467 state->chan_start = 0;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001468 nla_nest_end(msg, nl_freqs);
1469 }
1470
1471 nla_nest_end(msg, nl_band);
1472
Johannes Berg86e8cf92013-06-19 10:57:22 +02001473 if (state->split) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001474 /* start again here */
Johannes Berg86e8cf92013-06-19 10:57:22 +02001475 if (state->chan_start)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001476 band--;
1477 break;
1478 }
Johannes Bergee688b002008-01-24 19:38:39 +01001479 }
Johannes Berg3713b4e2013-02-14 16:19:38 +01001480 nla_nest_end(msg, nl_bands);
Johannes Bergee688b002008-01-24 19:38:39 +01001481
Johannes Berg57fbcce2016-04-12 15:56:15 +02001482 if (band < NUM_NL80211_BANDS)
Johannes Berg86e8cf92013-06-19 10:57:22 +02001483 state->band_start = band + 1;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001484 else
Johannes Berg86e8cf92013-06-19 10:57:22 +02001485 state->band_start = 0;
Johannes Bergee688b002008-01-24 19:38:39 +01001486
Johannes Berg3713b4e2013-02-14 16:19:38 +01001487 /* if bands & channels are done, continue outside */
Johannes Berg86e8cf92013-06-19 10:57:22 +02001488 if (state->band_start == 0 && state->chan_start == 0)
1489 state->split_start++;
1490 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001491 break;
1492 case 4:
1493 nl_cmds = nla_nest_start(msg, NL80211_ATTR_SUPPORTED_COMMANDS);
1494 if (!nl_cmds)
David S. Miller9360ffd2012-03-29 04:41:26 -04001495 goto nla_put_failure;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001496
1497 i = 0;
1498#define CMD(op, n) \
1499 do { \
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001500 if (rdev->ops->op) { \
Johannes Berg3713b4e2013-02-14 16:19:38 +01001501 i++; \
1502 if (nla_put_u32(msg, i, NL80211_CMD_ ## n)) \
1503 goto nla_put_failure; \
1504 } \
1505 } while (0)
1506
1507 CMD(add_virtual_intf, NEW_INTERFACE);
1508 CMD(change_virtual_intf, SET_INTERFACE);
1509 CMD(add_key, NEW_KEY);
1510 CMD(start_ap, START_AP);
1511 CMD(add_station, NEW_STATION);
1512 CMD(add_mpath, NEW_MPATH);
1513 CMD(update_mesh_config, SET_MESH_CONFIG);
1514 CMD(change_bss, SET_BSS);
1515 CMD(auth, AUTHENTICATE);
1516 CMD(assoc, ASSOCIATE);
1517 CMD(deauth, DEAUTHENTICATE);
1518 CMD(disassoc, DISASSOCIATE);
1519 CMD(join_ibss, JOIN_IBSS);
1520 CMD(join_mesh, JOIN_MESH);
1521 CMD(set_pmksa, SET_PMKSA);
1522 CMD(del_pmksa, DEL_PMKSA);
1523 CMD(flush_pmksa, FLUSH_PMKSA);
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001524 if (rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001525 CMD(remain_on_channel, REMAIN_ON_CHANNEL);
1526 CMD(set_bitrate_mask, SET_TX_BITRATE_MASK);
1527 CMD(mgmt_tx, FRAME);
1528 CMD(mgmt_tx_cancel_wait, FRAME_WAIT_CANCEL);
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001529 if (rdev->wiphy.flags & WIPHY_FLAG_NETNS_OK) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001530 i++;
1531 if (nla_put_u32(msg, i, NL80211_CMD_SET_WIPHY_NETNS))
1532 goto nla_put_failure;
1533 }
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001534 if (rdev->ops->set_monitor_channel || rdev->ops->start_ap ||
1535 rdev->ops->join_mesh) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001536 i++;
1537 if (nla_put_u32(msg, i, NL80211_CMD_SET_CHANNEL))
1538 goto nla_put_failure;
1539 }
1540 CMD(set_wds_peer, SET_WDS_PEER);
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001541 if (rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001542 CMD(tdls_mgmt, TDLS_MGMT);
1543 CMD(tdls_oper, TDLS_OPER);
1544 }
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001545 if (rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001546 CMD(sched_scan_start, START_SCHED_SCAN);
1547 CMD(probe_client, PROBE_CLIENT);
1548 CMD(set_noack_map, SET_NOACK_MAP);
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001549 if (rdev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001550 i++;
1551 if (nla_put_u32(msg, i, NL80211_CMD_REGISTER_BEACONS))
1552 goto nla_put_failure;
1553 }
1554 CMD(start_p2p_device, START_P2P_DEVICE);
1555 CMD(set_mcast_rate, SET_MCAST_RATE);
Johannes Berg02df00e2014-06-10 14:06:25 +02001556#ifdef CONFIG_NL80211_TESTMODE
1557 CMD(testmode_cmd, TESTMODE);
1558#endif
Johannes Berg86e8cf92013-06-19 10:57:22 +02001559 if (state->split) {
Arend van Spriel5de17982013-04-18 15:49:00 +02001560 CMD(crit_proto_start, CRIT_PROTOCOL_START);
1561 CMD(crit_proto_stop, CRIT_PROTOCOL_STOP);
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001562 if (rdev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH)
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02001563 CMD(channel_switch, CHANNEL_SWITCH);
Johannes Berg02df00e2014-06-10 14:06:25 +02001564 CMD(set_qos_map, SET_QOS_MAP);
Johannes Berg723e73a2014-10-22 09:25:06 +02001565 if (rdev->wiphy.features &
1566 NL80211_FEATURE_SUPPORTS_WMM_ADMISSION)
Johannes Berg960d01a2014-09-09 22:55:35 +03001567 CMD(add_tx_ts, ADD_TX_TS);
Arend van Spriel5de17982013-04-18 15:49:00 +02001568 }
Johannes Berg02df00e2014-06-10 14:06:25 +02001569 /* add into the if now */
Johannes Berg8fdc6212009-03-14 09:34:01 +01001570#undef CMD
Samuel Ortizb23aa672009-07-01 21:26:54 +02001571
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001572 if (rdev->ops->connect || rdev->ops->auth) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001573 i++;
1574 if (nla_put_u32(msg, i, NL80211_CMD_CONNECT))
Johannes Berg2e161f72010-08-12 15:38:38 +02001575 goto nla_put_failure;
Johannes Berg2e161f72010-08-12 15:38:38 +02001576 }
1577
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001578 if (rdev->ops->disconnect || rdev->ops->deauth) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001579 i++;
1580 if (nla_put_u32(msg, i, NL80211_CMD_DISCONNECT))
1581 goto nla_put_failure;
1582 }
Johannes Berg74b70a42010-08-24 12:15:53 +02001583
Johannes Berg3713b4e2013-02-14 16:19:38 +01001584 nla_nest_end(msg, nl_cmds);
Johannes Berg86e8cf92013-06-19 10:57:22 +02001585 state->split_start++;
1586 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001587 break;
1588 case 5:
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001589 if (rdev->ops->remain_on_channel &&
1590 (rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001591 nla_put_u32(msg,
1592 NL80211_ATTR_MAX_REMAIN_ON_CHANNEL_DURATION,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001593 rdev->wiphy.max_remain_on_channel_duration))
Johannes Berg2e161f72010-08-12 15:38:38 +02001594 goto nla_put_failure;
1595
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001596 if ((rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001597 nla_put_flag(msg, NL80211_ATTR_OFFCHANNEL_TX_OK))
1598 goto nla_put_failure;
Johannes Berg2e161f72010-08-12 15:38:38 +02001599
Johannes Berg3713b4e2013-02-14 16:19:38 +01001600 if (nl80211_send_mgmt_stypes(msg, mgmt_stypes))
1601 goto nla_put_failure;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001602 state->split_start++;
1603 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001604 break;
1605 case 6:
Johannes Bergdfb89c52012-06-27 09:23:48 +02001606#ifdef CONFIG_PM
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001607 if (nl80211_send_wowlan(msg, rdev, state->split))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001608 goto nla_put_failure;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001609 state->split_start++;
1610 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001611 break;
1612#else
Johannes Berg86e8cf92013-06-19 10:57:22 +02001613 state->split_start++;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001614#endif
1615 case 7:
1616 if (nl80211_put_iftypes(msg, NL80211_ATTR_SOFTWARE_IFTYPES,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001617 rdev->wiphy.software_iftypes))
Johannes Bergff1b6e62011-05-04 15:37:28 +02001618 goto nla_put_failure;
1619
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001620 if (nl80211_put_iface_combinations(&rdev->wiphy, msg,
Johannes Berg86e8cf92013-06-19 10:57:22 +02001621 state->split))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001622 goto nla_put_failure;
Johannes Bergff1b6e62011-05-04 15:37:28 +02001623
Johannes Berg86e8cf92013-06-19 10:57:22 +02001624 state->split_start++;
1625 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001626 break;
1627 case 8:
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001628 if ((rdev->wiphy.flags & WIPHY_FLAG_HAVE_AP_SME) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001629 nla_put_u32(msg, NL80211_ATTR_DEVICE_AP_SME,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001630 rdev->wiphy.ap_sme_capa))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001631 goto nla_put_failure;
1632
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001633 features = rdev->wiphy.features;
Johannes Bergfe1abaf2013-02-27 15:39:45 +01001634 /*
1635 * We can only add the per-channel limit information if the
1636 * dump is split, otherwise it makes it too big. Therefore
1637 * only advertise it in that case.
1638 */
Johannes Berg86e8cf92013-06-19 10:57:22 +02001639 if (state->split)
Johannes Bergfe1abaf2013-02-27 15:39:45 +01001640 features |= NL80211_FEATURE_ADVERTISE_CHAN_LIMITS;
1641 if (nla_put_u32(msg, NL80211_ATTR_FEATURE_FLAGS, features))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001642 goto nla_put_failure;
1643
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001644 if (rdev->wiphy.ht_capa_mod_mask &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001645 nla_put(msg, NL80211_ATTR_HT_CAPABILITY_MASK,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001646 sizeof(*rdev->wiphy.ht_capa_mod_mask),
1647 rdev->wiphy.ht_capa_mod_mask))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001648 goto nla_put_failure;
1649
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001650 if (rdev->wiphy.flags & WIPHY_FLAG_HAVE_AP_SME &&
1651 rdev->wiphy.max_acl_mac_addrs &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001652 nla_put_u32(msg, NL80211_ATTR_MAC_ACL_MAX,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001653 rdev->wiphy.max_acl_mac_addrs))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001654 goto nla_put_failure;
1655
1656 /*
1657 * Any information below this point is only available to
1658 * applications that can deal with it being split. This
1659 * helps ensure that newly added capabilities don't break
1660 * older tools by overrunning their buffers.
1661 *
1662 * We still increment split_start so that in the split
1663 * case we'll continue with more data in the next round,
1664 * but break unconditionally so unsplit data stops here.
1665 */
Johannes Berg86e8cf92013-06-19 10:57:22 +02001666 state->split_start++;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001667 break;
1668 case 9:
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001669 if (rdev->wiphy.extended_capabilities &&
Johannes Bergfe1abaf2013-02-27 15:39:45 +01001670 (nla_put(msg, NL80211_ATTR_EXT_CAPA,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001671 rdev->wiphy.extended_capabilities_len,
1672 rdev->wiphy.extended_capabilities) ||
Johannes Bergfe1abaf2013-02-27 15:39:45 +01001673 nla_put(msg, NL80211_ATTR_EXT_CAPA_MASK,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001674 rdev->wiphy.extended_capabilities_len,
1675 rdev->wiphy.extended_capabilities_mask)))
Johannes Bergfe1abaf2013-02-27 15:39:45 +01001676 goto nla_put_failure;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001677
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001678 if (rdev->wiphy.vht_capa_mod_mask &&
Johannes Bergee2aca32013-02-21 17:36:01 +01001679 nla_put(msg, NL80211_ATTR_VHT_CAPABILITY_MASK,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001680 sizeof(*rdev->wiphy.vht_capa_mod_mask),
1681 rdev->wiphy.vht_capa_mod_mask))
Johannes Bergee2aca32013-02-21 17:36:01 +01001682 goto nla_put_failure;
1683
Amitkumar Karwarbe29b992013-06-28 11:51:26 -07001684 state->split_start++;
1685 break;
1686 case 10:
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001687 if (nl80211_send_coalesce(msg, rdev))
Amitkumar Karwarbe29b992013-06-28 11:51:26 -07001688 goto nla_put_failure;
1689
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001690 if ((rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_5_10_MHZ) &&
Felix Fietkau01e0daa2013-11-09 14:57:54 +01001691 (nla_put_flag(msg, NL80211_ATTR_SUPPORT_5_MHZ) ||
1692 nla_put_flag(msg, NL80211_ATTR_SUPPORT_10_MHZ)))
1693 goto nla_put_failure;
Jouni Malinenb43504c2014-01-15 00:01:08 +02001694
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001695 if (rdev->wiphy.max_ap_assoc_sta &&
Jouni Malinenb43504c2014-01-15 00:01:08 +02001696 nla_put_u32(msg, NL80211_ATTR_MAX_AP_ASSOC_STA,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001697 rdev->wiphy.max_ap_assoc_sta))
Jouni Malinenb43504c2014-01-15 00:01:08 +02001698 goto nla_put_failure;
1699
Johannes Bergad7e7182013-11-13 13:37:47 +01001700 state->split_start++;
1701 break;
1702 case 11:
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001703 if (rdev->wiphy.n_vendor_commands) {
Johannes Berg567ffc32013-12-18 14:43:31 +01001704 const struct nl80211_vendor_cmd_info *info;
1705 struct nlattr *nested;
Johannes Bergad7e7182013-11-13 13:37:47 +01001706
Johannes Berg567ffc32013-12-18 14:43:31 +01001707 nested = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA);
1708 if (!nested)
Johannes Bergad7e7182013-11-13 13:37:47 +01001709 goto nla_put_failure;
Johannes Berg567ffc32013-12-18 14:43:31 +01001710
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001711 for (i = 0; i < rdev->wiphy.n_vendor_commands; i++) {
1712 info = &rdev->wiphy.vendor_commands[i].info;
Johannes Berg567ffc32013-12-18 14:43:31 +01001713 if (nla_put(msg, i + 1, sizeof(*info), info))
1714 goto nla_put_failure;
1715 }
1716 nla_nest_end(msg, nested);
1717 }
1718
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001719 if (rdev->wiphy.n_vendor_events) {
Johannes Berg567ffc32013-12-18 14:43:31 +01001720 const struct nl80211_vendor_cmd_info *info;
1721 struct nlattr *nested;
1722
1723 nested = nla_nest_start(msg,
1724 NL80211_ATTR_VENDOR_EVENTS);
1725 if (!nested)
1726 goto nla_put_failure;
1727
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001728 for (i = 0; i < rdev->wiphy.n_vendor_events; i++) {
1729 info = &rdev->wiphy.vendor_events[i];
Johannes Berg567ffc32013-12-18 14:43:31 +01001730 if (nla_put(msg, i + 1, sizeof(*info), info))
1731 goto nla_put_failure;
1732 }
1733 nla_nest_end(msg, nested);
1734 }
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03001735 state->split_start++;
1736 break;
1737 case 12:
1738 if (rdev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH &&
1739 nla_put_u8(msg, NL80211_ATTR_MAX_CSA_COUNTERS,
1740 rdev->wiphy.max_num_csa_counters))
1741 goto nla_put_failure;
Felix Fietkau01e0daa2013-11-09 14:57:54 +01001742
Arik Nemtsov1bdd7162014-12-15 19:26:01 +02001743 if (rdev->wiphy.regulatory_flags & REGULATORY_WIPHY_SELF_MANAGED &&
1744 nla_put_flag(msg, NL80211_ATTR_WIPHY_SELF_MANAGED_REG))
1745 goto nla_put_failure;
1746
Gautam Kumar Shuklad75bb062014-12-23 16:55:19 +01001747 if (nla_put(msg, NL80211_ATTR_EXT_FEATURES,
1748 sizeof(rdev->wiphy.ext_features),
1749 rdev->wiphy.ext_features))
1750 goto nla_put_failure;
1751
Arend van Spriel38de03d2016-03-02 20:37:18 +01001752 if (rdev->wiphy.bss_select_support) {
1753 struct nlattr *nested;
1754 u32 bss_select_support = rdev->wiphy.bss_select_support;
1755
1756 nested = nla_nest_start(msg, NL80211_ATTR_BSS_SELECT);
1757 if (!nested)
1758 goto nla_put_failure;
1759
1760 i = 0;
1761 while (bss_select_support) {
1762 if ((bss_select_support & 1) &&
1763 nla_put_flag(msg, i))
1764 goto nla_put_failure;
1765 i++;
1766 bss_select_support >>= 1;
1767 }
1768 nla_nest_end(msg, nested);
1769 }
1770
Kanchanapally, Vidyullatha019ae3a2016-05-16 10:41:04 +05301771 state->split_start++;
1772 break;
1773 case 13:
1774 if (rdev->wiphy.num_iftype_ext_capab &&
1775 rdev->wiphy.iftype_ext_capab) {
1776 struct nlattr *nested_ext_capab, *nested;
1777
1778 nested = nla_nest_start(msg,
1779 NL80211_ATTR_IFTYPE_EXT_CAPA);
1780 if (!nested)
1781 goto nla_put_failure;
1782
1783 for (i = state->capa_start;
1784 i < rdev->wiphy.num_iftype_ext_capab; i++) {
1785 const struct wiphy_iftype_ext_capab *capab;
1786
1787 capab = &rdev->wiphy.iftype_ext_capab[i];
1788
1789 nested_ext_capab = nla_nest_start(msg, i);
1790 if (!nested_ext_capab ||
1791 nla_put_u32(msg, NL80211_ATTR_IFTYPE,
1792 capab->iftype) ||
1793 nla_put(msg, NL80211_ATTR_EXT_CAPA,
1794 capab->extended_capabilities_len,
1795 capab->extended_capabilities) ||
1796 nla_put(msg, NL80211_ATTR_EXT_CAPA_MASK,
1797 capab->extended_capabilities_len,
1798 capab->extended_capabilities_mask))
1799 goto nla_put_failure;
1800
1801 nla_nest_end(msg, nested_ext_capab);
1802 if (state->split)
1803 break;
1804 }
1805 nla_nest_end(msg, nested);
1806 if (i < rdev->wiphy.num_iftype_ext_capab) {
1807 state->capa_start = i + 1;
1808 break;
1809 }
1810 }
1811
Johannes Berg3713b4e2013-02-14 16:19:38 +01001812 /* done */
Johannes Berg86e8cf92013-06-19 10:57:22 +02001813 state->split_start = 0;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001814 break;
Johannes Bergff1b6e62011-05-04 15:37:28 +02001815 }
Johannes Berg3bb20552014-05-26 13:52:25 +02001816 finish:
Johannes Berg053c0952015-01-16 22:09:00 +01001817 genlmsg_end(msg, hdr);
1818 return 0;
Johannes Berg55682962007-09-20 13:09:35 -04001819
1820 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07001821 genlmsg_cancel(msg, hdr);
1822 return -EMSGSIZE;
Johannes Berg55682962007-09-20 13:09:35 -04001823}
1824
Johannes Berg86e8cf92013-06-19 10:57:22 +02001825static int nl80211_dump_wiphy_parse(struct sk_buff *skb,
1826 struct netlink_callback *cb,
1827 struct nl80211_dump_wiphy_state *state)
1828{
1829 struct nlattr **tb = nl80211_fam.attrbuf;
1830 int ret = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize,
1831 tb, nl80211_fam.maxattr, nl80211_policy);
1832 /* ignore parse errors for backward compatibility */
1833 if (ret)
1834 return 0;
1835
1836 state->split = tb[NL80211_ATTR_SPLIT_WIPHY_DUMP];
1837 if (tb[NL80211_ATTR_WIPHY])
1838 state->filter_wiphy = nla_get_u32(tb[NL80211_ATTR_WIPHY]);
1839 if (tb[NL80211_ATTR_WDEV])
1840 state->filter_wiphy = nla_get_u64(tb[NL80211_ATTR_WDEV]) >> 32;
1841 if (tb[NL80211_ATTR_IFINDEX]) {
1842 struct net_device *netdev;
1843 struct cfg80211_registered_device *rdev;
1844 int ifidx = nla_get_u32(tb[NL80211_ATTR_IFINDEX]);
1845
Ying Xue7f2b8562014-01-15 10:23:45 +08001846 netdev = __dev_get_by_index(sock_net(skb->sk), ifidx);
Johannes Berg86e8cf92013-06-19 10:57:22 +02001847 if (!netdev)
1848 return -ENODEV;
1849 if (netdev->ieee80211_ptr) {
Zhao, Gangf26cbf42014-04-21 12:53:03 +08001850 rdev = wiphy_to_rdev(
Johannes Berg86e8cf92013-06-19 10:57:22 +02001851 netdev->ieee80211_ptr->wiphy);
1852 state->filter_wiphy = rdev->wiphy_idx;
1853 }
Johannes Berg86e8cf92013-06-19 10:57:22 +02001854 }
1855
1856 return 0;
1857}
1858
Johannes Berg55682962007-09-20 13:09:35 -04001859static int nl80211_dump_wiphy(struct sk_buff *skb, struct netlink_callback *cb)
1860{
Johannes Berg645e77d2013-03-01 14:03:49 +01001861 int idx = 0, ret;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001862 struct nl80211_dump_wiphy_state *state = (void *)cb->args[0];
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001863 struct cfg80211_registered_device *rdev;
Johannes Berg3a5a4232013-06-19 10:09:57 +02001864
Johannes Berg5fe231e2013-05-08 21:45:15 +02001865 rtnl_lock();
Johannes Berg86e8cf92013-06-19 10:57:22 +02001866 if (!state) {
1867 state = kzalloc(sizeof(*state), GFP_KERNEL);
John W. Linville57ed5cd2013-06-28 13:18:21 -04001868 if (!state) {
1869 rtnl_unlock();
Johannes Berg86e8cf92013-06-19 10:57:22 +02001870 return -ENOMEM;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001871 }
Johannes Berg86e8cf92013-06-19 10:57:22 +02001872 state->filter_wiphy = -1;
1873 ret = nl80211_dump_wiphy_parse(skb, cb, state);
1874 if (ret) {
1875 kfree(state);
1876 rtnl_unlock();
1877 return ret;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001878 }
Johannes Berg86e8cf92013-06-19 10:57:22 +02001879 cb->args[0] = (long)state;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001880 }
1881
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001882 list_for_each_entry(rdev, &cfg80211_rdev_list, list) {
1883 if (!net_eq(wiphy_net(&rdev->wiphy), sock_net(skb->sk)))
Johannes Berg463d0182009-07-14 00:33:35 +02001884 continue;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001885 if (++idx <= state->start)
Johannes Berg55682962007-09-20 13:09:35 -04001886 continue;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001887 if (state->filter_wiphy != -1 &&
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001888 state->filter_wiphy != rdev->wiphy_idx)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001889 continue;
1890 /* attempt to fit multiple wiphy data chunks into the skb */
1891 do {
Johannes Berg3bb20552014-05-26 13:52:25 +02001892 ret = nl80211_send_wiphy(rdev, NL80211_CMD_NEW_WIPHY,
1893 skb,
Johannes Berg3713b4e2013-02-14 16:19:38 +01001894 NETLINK_CB(cb->skb).portid,
1895 cb->nlh->nlmsg_seq,
Johannes Berg86e8cf92013-06-19 10:57:22 +02001896 NLM_F_MULTI, state);
Johannes Berg3713b4e2013-02-14 16:19:38 +01001897 if (ret < 0) {
1898 /*
1899 * If sending the wiphy data didn't fit (ENOBUFS
1900 * or EMSGSIZE returned), this SKB is still
1901 * empty (so it's not too big because another
1902 * wiphy dataset is already in the skb) and
1903 * we've not tried to adjust the dump allocation
1904 * yet ... then adjust the alloc size to be
1905 * bigger, and return 1 but with the empty skb.
1906 * This results in an empty message being RX'ed
1907 * in userspace, but that is ignored.
1908 *
1909 * We can then retry with the larger buffer.
1910 */
1911 if ((ret == -ENOBUFS || ret == -EMSGSIZE) &&
Pontus Fuchsf12cb282014-01-16 15:00:40 +01001912 !skb->len && !state->split &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001913 cb->min_dump_alloc < 4096) {
1914 cb->min_dump_alloc = 4096;
Pontus Fuchsf12cb282014-01-16 15:00:40 +01001915 state->split_start = 0;
David S. Millerd98cae64e2013-06-19 16:49:39 -07001916 rtnl_unlock();
Johannes Berg3713b4e2013-02-14 16:19:38 +01001917 return 1;
1918 }
1919 idx--;
1920 break;
Johannes Berg645e77d2013-03-01 14:03:49 +01001921 }
Johannes Berg86e8cf92013-06-19 10:57:22 +02001922 } while (state->split_start > 0);
Johannes Berg3713b4e2013-02-14 16:19:38 +01001923 break;
Johannes Berg55682962007-09-20 13:09:35 -04001924 }
Johannes Berg5fe231e2013-05-08 21:45:15 +02001925 rtnl_unlock();
Johannes Berg55682962007-09-20 13:09:35 -04001926
Johannes Berg86e8cf92013-06-19 10:57:22 +02001927 state->start = idx;
Johannes Berg55682962007-09-20 13:09:35 -04001928
1929 return skb->len;
1930}
1931
Johannes Berg86e8cf92013-06-19 10:57:22 +02001932static int nl80211_dump_wiphy_done(struct netlink_callback *cb)
1933{
1934 kfree((void *)cb->args[0]);
1935 return 0;
1936}
1937
Johannes Berg55682962007-09-20 13:09:35 -04001938static int nl80211_get_wiphy(struct sk_buff *skb, struct genl_info *info)
1939{
1940 struct sk_buff *msg;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001941 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg86e8cf92013-06-19 10:57:22 +02001942 struct nl80211_dump_wiphy_state state = {};
Johannes Berg55682962007-09-20 13:09:35 -04001943
Johannes Berg645e77d2013-03-01 14:03:49 +01001944 msg = nlmsg_new(4096, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -04001945 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02001946 return -ENOMEM;
Johannes Berg55682962007-09-20 13:09:35 -04001947
Johannes Berg3bb20552014-05-26 13:52:25 +02001948 if (nl80211_send_wiphy(rdev, NL80211_CMD_NEW_WIPHY, msg,
1949 info->snd_portid, info->snd_seq, 0,
Johannes Berg86e8cf92013-06-19 10:57:22 +02001950 &state) < 0) {
Johannes Berg4c476992010-10-04 21:36:35 +02001951 nlmsg_free(msg);
1952 return -ENOBUFS;
1953 }
Johannes Berg55682962007-09-20 13:09:35 -04001954
Johannes Berg134e6372009-07-10 09:51:34 +00001955 return genlmsg_reply(msg, info);
Johannes Berg55682962007-09-20 13:09:35 -04001956}
1957
Jouni Malinen31888482008-10-30 16:59:24 +02001958static const struct nla_policy txq_params_policy[NL80211_TXQ_ATTR_MAX + 1] = {
1959 [NL80211_TXQ_ATTR_QUEUE] = { .type = NLA_U8 },
1960 [NL80211_TXQ_ATTR_TXOP] = { .type = NLA_U16 },
1961 [NL80211_TXQ_ATTR_CWMIN] = { .type = NLA_U16 },
1962 [NL80211_TXQ_ATTR_CWMAX] = { .type = NLA_U16 },
1963 [NL80211_TXQ_ATTR_AIFS] = { .type = NLA_U8 },
1964};
1965
1966static int parse_txq_params(struct nlattr *tb[],
1967 struct ieee80211_txq_params *txq_params)
1968{
Johannes Berga3304b02012-03-28 11:04:24 +02001969 if (!tb[NL80211_TXQ_ATTR_AC] || !tb[NL80211_TXQ_ATTR_TXOP] ||
Jouni Malinen31888482008-10-30 16:59:24 +02001970 !tb[NL80211_TXQ_ATTR_CWMIN] || !tb[NL80211_TXQ_ATTR_CWMAX] ||
1971 !tb[NL80211_TXQ_ATTR_AIFS])
1972 return -EINVAL;
1973
Johannes Berga3304b02012-03-28 11:04:24 +02001974 txq_params->ac = nla_get_u8(tb[NL80211_TXQ_ATTR_AC]);
Jouni Malinen31888482008-10-30 16:59:24 +02001975 txq_params->txop = nla_get_u16(tb[NL80211_TXQ_ATTR_TXOP]);
1976 txq_params->cwmin = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMIN]);
1977 txq_params->cwmax = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMAX]);
1978 txq_params->aifs = nla_get_u8(tb[NL80211_TXQ_ATTR_AIFS]);
1979
Johannes Berga3304b02012-03-28 11:04:24 +02001980 if (txq_params->ac >= NL80211_NUM_ACS)
1981 return -EINVAL;
1982
Jouni Malinen31888482008-10-30 16:59:24 +02001983 return 0;
1984}
1985
Johannes Bergf444de02010-05-05 15:25:02 +02001986static bool nl80211_can_set_dev_channel(struct wireless_dev *wdev)
1987{
1988 /*
Johannes Bergcc1d2802012-05-16 23:50:20 +02001989 * You can only set the channel explicitly for WDS interfaces,
1990 * all others have their channel managed via their respective
1991 * "establish a connection" command (connect, join, ...)
1992 *
1993 * For AP/GO and mesh mode, the channel can be set with the
1994 * channel userspace API, but is only stored and passed to the
1995 * low-level driver when the AP starts or the mesh is joined.
1996 * This is for backward compatibility, userspace can also give
1997 * the channel in the start-ap or join-mesh commands instead.
Johannes Bergf444de02010-05-05 15:25:02 +02001998 *
1999 * Monitors are special as they are normally slaved to
Johannes Berge8c9bd52012-06-06 08:18:22 +02002000 * whatever else is going on, so they have their own special
2001 * operation to set the monitor channel if possible.
Johannes Bergf444de02010-05-05 15:25:02 +02002002 */
2003 return !wdev ||
2004 wdev->iftype == NL80211_IFTYPE_AP ||
Johannes Bergf444de02010-05-05 15:25:02 +02002005 wdev->iftype == NL80211_IFTYPE_MESH_POINT ||
Johannes Berg074ac8d2010-09-16 14:58:22 +02002006 wdev->iftype == NL80211_IFTYPE_MONITOR ||
2007 wdev->iftype == NL80211_IFTYPE_P2P_GO;
Johannes Bergf444de02010-05-05 15:25:02 +02002008}
2009
Johannes Berg683b6d32012-11-08 21:25:48 +01002010static int nl80211_parse_chandef(struct cfg80211_registered_device *rdev,
2011 struct genl_info *info,
2012 struct cfg80211_chan_def *chandef)
2013{
Mahesh Paliveladbeca2e2012-11-29 14:11:07 +05302014 u32 control_freq;
Johannes Berg683b6d32012-11-08 21:25:48 +01002015
2016 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ])
2017 return -EINVAL;
2018
2019 control_freq = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]);
2020
2021 chandef->chan = ieee80211_get_channel(&rdev->wiphy, control_freq);
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002022 chandef->width = NL80211_CHAN_WIDTH_20_NOHT;
2023 chandef->center_freq1 = control_freq;
2024 chandef->center_freq2 = 0;
Johannes Berg683b6d32012-11-08 21:25:48 +01002025
2026 /* Primary channel not allowed */
2027 if (!chandef->chan || chandef->chan->flags & IEEE80211_CHAN_DISABLED)
2028 return -EINVAL;
2029
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002030 if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]) {
2031 enum nl80211_channel_type chantype;
Johannes Berg683b6d32012-11-08 21:25:48 +01002032
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002033 chantype = nla_get_u32(
2034 info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]);
2035
2036 switch (chantype) {
2037 case NL80211_CHAN_NO_HT:
2038 case NL80211_CHAN_HT20:
2039 case NL80211_CHAN_HT40PLUS:
2040 case NL80211_CHAN_HT40MINUS:
2041 cfg80211_chandef_create(chandef, chandef->chan,
2042 chantype);
2043 break;
2044 default:
Johannes Berg683b6d32012-11-08 21:25:48 +01002045 return -EINVAL;
Johannes Berg683b6d32012-11-08 21:25:48 +01002046 }
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002047 } else if (info->attrs[NL80211_ATTR_CHANNEL_WIDTH]) {
2048 chandef->width =
2049 nla_get_u32(info->attrs[NL80211_ATTR_CHANNEL_WIDTH]);
2050 if (info->attrs[NL80211_ATTR_CENTER_FREQ1])
2051 chandef->center_freq1 =
2052 nla_get_u32(
2053 info->attrs[NL80211_ATTR_CENTER_FREQ1]);
2054 if (info->attrs[NL80211_ATTR_CENTER_FREQ2])
2055 chandef->center_freq2 =
2056 nla_get_u32(
2057 info->attrs[NL80211_ATTR_CENTER_FREQ2]);
2058 }
2059
Johannes Berg9f5e8f62012-11-22 16:59:45 +01002060 if (!cfg80211_chandef_valid(chandef))
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002061 return -EINVAL;
2062
Johannes Berg9f5e8f62012-11-22 16:59:45 +01002063 if (!cfg80211_chandef_usable(&rdev->wiphy, chandef,
2064 IEEE80211_CHAN_DISABLED))
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002065 return -EINVAL;
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002066
Simon Wunderlich2f301ab2013-05-16 13:00:28 +02002067 if ((chandef->width == NL80211_CHAN_WIDTH_5 ||
2068 chandef->width == NL80211_CHAN_WIDTH_10) &&
2069 !(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_5_10_MHZ))
2070 return -EINVAL;
2071
Johannes Berg683b6d32012-11-08 21:25:48 +01002072 return 0;
2073}
2074
Johannes Bergf444de02010-05-05 15:25:02 +02002075static int __nl80211_set_channel(struct cfg80211_registered_device *rdev,
Jouni Malinene16821b2014-04-28 11:22:08 +03002076 struct net_device *dev,
Johannes Bergf444de02010-05-05 15:25:02 +02002077 struct genl_info *info)
2078{
Johannes Berg683b6d32012-11-08 21:25:48 +01002079 struct cfg80211_chan_def chandef;
Johannes Bergf444de02010-05-05 15:25:02 +02002080 int result;
Johannes Berge8c9bd52012-06-06 08:18:22 +02002081 enum nl80211_iftype iftype = NL80211_IFTYPE_MONITOR;
Jouni Malinene16821b2014-04-28 11:22:08 +03002082 struct wireless_dev *wdev = NULL;
Johannes Berge8c9bd52012-06-06 08:18:22 +02002083
Jouni Malinene16821b2014-04-28 11:22:08 +03002084 if (dev)
2085 wdev = dev->ieee80211_ptr;
Johannes Bergf444de02010-05-05 15:25:02 +02002086 if (!nl80211_can_set_dev_channel(wdev))
2087 return -EOPNOTSUPP;
Jouni Malinene16821b2014-04-28 11:22:08 +03002088 if (wdev)
2089 iftype = wdev->iftype;
Johannes Bergf444de02010-05-05 15:25:02 +02002090
Johannes Berg683b6d32012-11-08 21:25:48 +01002091 result = nl80211_parse_chandef(rdev, info, &chandef);
2092 if (result)
2093 return result;
Johannes Bergf444de02010-05-05 15:25:02 +02002094
Johannes Berge8c9bd52012-06-06 08:18:22 +02002095 switch (iftype) {
Johannes Bergaa430da2012-05-16 23:50:18 +02002096 case NL80211_IFTYPE_AP:
2097 case NL80211_IFTYPE_P2P_GO:
Arik Nemtsov923b3522015-07-08 15:41:44 +03002098 if (!cfg80211_reg_can_beacon_relax(&rdev->wiphy, &chandef,
2099 iftype)) {
Johannes Bergaa430da2012-05-16 23:50:18 +02002100 result = -EINVAL;
2101 break;
2102 }
Jouni Malinene16821b2014-04-28 11:22:08 +03002103 if (wdev->beacon_interval) {
2104 if (!dev || !rdev->ops->set_ap_chanwidth ||
2105 !(rdev->wiphy.features &
2106 NL80211_FEATURE_AP_MODE_CHAN_WIDTH_CHANGE)) {
2107 result = -EBUSY;
2108 break;
2109 }
2110
2111 /* Only allow dynamic channel width changes */
2112 if (chandef.chan != wdev->preset_chandef.chan) {
2113 result = -EBUSY;
2114 break;
2115 }
2116 result = rdev_set_ap_chanwidth(rdev, dev, &chandef);
2117 if (result)
2118 break;
2119 }
Johannes Berg683b6d32012-11-08 21:25:48 +01002120 wdev->preset_chandef = chandef;
Johannes Bergaa430da2012-05-16 23:50:18 +02002121 result = 0;
2122 break;
Johannes Bergcc1d2802012-05-16 23:50:20 +02002123 case NL80211_IFTYPE_MESH_POINT:
Johannes Berg683b6d32012-11-08 21:25:48 +01002124 result = cfg80211_set_mesh_channel(rdev, wdev, &chandef);
Johannes Bergcc1d2802012-05-16 23:50:20 +02002125 break;
Johannes Berge8c9bd52012-06-06 08:18:22 +02002126 case NL80211_IFTYPE_MONITOR:
Johannes Berg683b6d32012-11-08 21:25:48 +01002127 result = cfg80211_set_monitor_channel(rdev, &chandef);
Johannes Berge8c9bd52012-06-06 08:18:22 +02002128 break;
Johannes Bergaa430da2012-05-16 23:50:18 +02002129 default:
Johannes Berge8c9bd52012-06-06 08:18:22 +02002130 result = -EINVAL;
Johannes Bergf444de02010-05-05 15:25:02 +02002131 }
Johannes Bergf444de02010-05-05 15:25:02 +02002132
2133 return result;
2134}
2135
2136static int nl80211_set_channel(struct sk_buff *skb, struct genl_info *info)
2137{
Johannes Berg4c476992010-10-04 21:36:35 +02002138 struct cfg80211_registered_device *rdev = info->user_ptr[0];
2139 struct net_device *netdev = info->user_ptr[1];
Johannes Bergf444de02010-05-05 15:25:02 +02002140
Jouni Malinene16821b2014-04-28 11:22:08 +03002141 return __nl80211_set_channel(rdev, netdev, info);
Johannes Bergf444de02010-05-05 15:25:02 +02002142}
2143
Bill Jordane8347eb2010-10-01 13:54:28 -04002144static int nl80211_set_wds_peer(struct sk_buff *skb, struct genl_info *info)
2145{
Johannes Berg43b19952010-10-07 13:10:30 +02002146 struct cfg80211_registered_device *rdev = info->user_ptr[0];
2147 struct net_device *dev = info->user_ptr[1];
2148 struct wireless_dev *wdev = dev->ieee80211_ptr;
Johannes Berg388ac772010-10-07 13:11:09 +02002149 const u8 *bssid;
Bill Jordane8347eb2010-10-01 13:54:28 -04002150
2151 if (!info->attrs[NL80211_ATTR_MAC])
2152 return -EINVAL;
2153
Johannes Berg43b19952010-10-07 13:10:30 +02002154 if (netif_running(dev))
2155 return -EBUSY;
Bill Jordane8347eb2010-10-01 13:54:28 -04002156
Johannes Berg43b19952010-10-07 13:10:30 +02002157 if (!rdev->ops->set_wds_peer)
2158 return -EOPNOTSUPP;
Bill Jordane8347eb2010-10-01 13:54:28 -04002159
Johannes Berg43b19952010-10-07 13:10:30 +02002160 if (wdev->iftype != NL80211_IFTYPE_WDS)
2161 return -EOPNOTSUPP;
Bill Jordane8347eb2010-10-01 13:54:28 -04002162
2163 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Hila Gonene35e4d22012-06-27 17:19:42 +03002164 return rdev_set_wds_peer(rdev, dev, bssid);
Bill Jordane8347eb2010-10-01 13:54:28 -04002165}
2166
Johannes Berg55682962007-09-20 13:09:35 -04002167static int nl80211_set_wiphy(struct sk_buff *skb, struct genl_info *info)
2168{
2169 struct cfg80211_registered_device *rdev;
Johannes Bergf444de02010-05-05 15:25:02 +02002170 struct net_device *netdev = NULL;
2171 struct wireless_dev *wdev;
Bill Jordana1e567c2010-09-10 11:22:32 -04002172 int result = 0, rem_txq_params = 0;
Jouni Malinen31888482008-10-30 16:59:24 +02002173 struct nlattr *nl_txq_params;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002174 u32 changed;
2175 u8 retry_short = 0, retry_long = 0;
2176 u32 frag_threshold = 0, rts_threshold = 0;
Lukáš Turek81077e82009-12-21 22:50:47 +01002177 u8 coverage_class = 0;
Johannes Berg55682962007-09-20 13:09:35 -04002178
Johannes Berg5fe231e2013-05-08 21:45:15 +02002179 ASSERT_RTNL();
2180
Johannes Bergf444de02010-05-05 15:25:02 +02002181 /*
2182 * Try to find the wiphy and netdev. Normally this
2183 * function shouldn't need the netdev, but this is
2184 * done for backward compatibility -- previously
2185 * setting the channel was done per wiphy, but now
2186 * it is per netdev. Previous userland like hostapd
2187 * also passed a netdev to set_wiphy, so that it is
2188 * possible to let that go to the right netdev!
2189 */
Johannes Berg4bbf4d52009-03-24 09:35:46 +01002190
Johannes Bergf444de02010-05-05 15:25:02 +02002191 if (info->attrs[NL80211_ATTR_IFINDEX]) {
2192 int ifindex = nla_get_u32(info->attrs[NL80211_ATTR_IFINDEX]);
2193
Ying Xue7f2b8562014-01-15 10:23:45 +08002194 netdev = __dev_get_by_index(genl_info_net(info), ifindex);
Johannes Berg5fe231e2013-05-08 21:45:15 +02002195 if (netdev && netdev->ieee80211_ptr)
Zhao, Gangf26cbf42014-04-21 12:53:03 +08002196 rdev = wiphy_to_rdev(netdev->ieee80211_ptr->wiphy);
Johannes Berg5fe231e2013-05-08 21:45:15 +02002197 else
Johannes Bergf444de02010-05-05 15:25:02 +02002198 netdev = NULL;
Johannes Berg4bbf4d52009-03-24 09:35:46 +01002199 }
2200
Johannes Bergf444de02010-05-05 15:25:02 +02002201 if (!netdev) {
Johannes Berg878d9ec2012-06-15 14:18:32 +02002202 rdev = __cfg80211_rdev_from_attrs(genl_info_net(info),
2203 info->attrs);
Johannes Berg5fe231e2013-05-08 21:45:15 +02002204 if (IS_ERR(rdev))
Johannes Berg4c476992010-10-04 21:36:35 +02002205 return PTR_ERR(rdev);
Johannes Bergf444de02010-05-05 15:25:02 +02002206 wdev = NULL;
2207 netdev = NULL;
2208 result = 0;
Johannes Berg71fe96b2012-10-24 10:04:58 +02002209 } else
Johannes Bergf444de02010-05-05 15:25:02 +02002210 wdev = netdev->ieee80211_ptr;
Johannes Bergf444de02010-05-05 15:25:02 +02002211
2212 /*
2213 * end workaround code, by now the rdev is available
2214 * and locked, and wdev may or may not be NULL.
2215 */
Johannes Berg4bbf4d52009-03-24 09:35:46 +01002216
2217 if (info->attrs[NL80211_ATTR_WIPHY_NAME])
Jouni Malinen31888482008-10-30 16:59:24 +02002218 result = cfg80211_dev_rename(
2219 rdev, nla_data(info->attrs[NL80211_ATTR_WIPHY_NAME]));
Johannes Berg4bbf4d52009-03-24 09:35:46 +01002220
Johannes Berg4bbf4d52009-03-24 09:35:46 +01002221 if (result)
Ying Xue7f2b8562014-01-15 10:23:45 +08002222 return result;
Johannes Berg55682962007-09-20 13:09:35 -04002223
Jouni Malinen31888482008-10-30 16:59:24 +02002224 if (info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS]) {
2225 struct ieee80211_txq_params txq_params;
2226 struct nlattr *tb[NL80211_TXQ_ATTR_MAX + 1];
2227
Ying Xue7f2b8562014-01-15 10:23:45 +08002228 if (!rdev->ops->set_txq_params)
2229 return -EOPNOTSUPP;
Jouni Malinen31888482008-10-30 16:59:24 +02002230
Ying Xue7f2b8562014-01-15 10:23:45 +08002231 if (!netdev)
2232 return -EINVAL;
Eliad Pellerf70f01c2011-09-25 20:06:53 +03002233
Johannes Berg133a3ff2011-11-03 14:50:13 +01002234 if (netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
Ying Xue7f2b8562014-01-15 10:23:45 +08002235 netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
2236 return -EINVAL;
Johannes Berg133a3ff2011-11-03 14:50:13 +01002237
Ying Xue7f2b8562014-01-15 10:23:45 +08002238 if (!netif_running(netdev))
2239 return -ENETDOWN;
Johannes Berg2b5f8b02012-04-02 10:51:55 +02002240
Jouni Malinen31888482008-10-30 16:59:24 +02002241 nla_for_each_nested(nl_txq_params,
2242 info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS],
2243 rem_txq_params) {
Johannes Bergae811e22014-01-24 10:17:47 +01002244 result = nla_parse(tb, NL80211_TXQ_ATTR_MAX,
2245 nla_data(nl_txq_params),
2246 nla_len(nl_txq_params),
2247 txq_params_policy);
2248 if (result)
2249 return result;
Jouni Malinen31888482008-10-30 16:59:24 +02002250 result = parse_txq_params(tb, &txq_params);
2251 if (result)
Ying Xue7f2b8562014-01-15 10:23:45 +08002252 return result;
Jouni Malinen31888482008-10-30 16:59:24 +02002253
Hila Gonene35e4d22012-06-27 17:19:42 +03002254 result = rdev_set_txq_params(rdev, netdev,
2255 &txq_params);
Jouni Malinen31888482008-10-30 16:59:24 +02002256 if (result)
Ying Xue7f2b8562014-01-15 10:23:45 +08002257 return result;
Jouni Malinen31888482008-10-30 16:59:24 +02002258 }
2259 }
2260
Jouni Malinen72bdcf32008-11-26 16:15:24 +02002261 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
Jouni Malinene16821b2014-04-28 11:22:08 +03002262 result = __nl80211_set_channel(
2263 rdev,
2264 nl80211_can_set_dev_channel(wdev) ? netdev : NULL,
2265 info);
Jouni Malinen72bdcf32008-11-26 16:15:24 +02002266 if (result)
Ying Xue7f2b8562014-01-15 10:23:45 +08002267 return result;
Jouni Malinen72bdcf32008-11-26 16:15:24 +02002268 }
2269
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03002270 if (info->attrs[NL80211_ATTR_WIPHY_TX_POWER_SETTING]) {
Johannes Bergc8442112012-10-24 10:17:18 +02002271 struct wireless_dev *txp_wdev = wdev;
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03002272 enum nl80211_tx_power_setting type;
2273 int idx, mbm = 0;
2274
Johannes Bergc8442112012-10-24 10:17:18 +02002275 if (!(rdev->wiphy.features & NL80211_FEATURE_VIF_TXPOWER))
2276 txp_wdev = NULL;
2277
Ying Xue7f2b8562014-01-15 10:23:45 +08002278 if (!rdev->ops->set_tx_power)
2279 return -EOPNOTSUPP;
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03002280
2281 idx = NL80211_ATTR_WIPHY_TX_POWER_SETTING;
2282 type = nla_get_u32(info->attrs[idx]);
2283
2284 if (!info->attrs[NL80211_ATTR_WIPHY_TX_POWER_LEVEL] &&
Ying Xue7f2b8562014-01-15 10:23:45 +08002285 (type != NL80211_TX_POWER_AUTOMATIC))
2286 return -EINVAL;
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03002287
2288 if (type != NL80211_TX_POWER_AUTOMATIC) {
2289 idx = NL80211_ATTR_WIPHY_TX_POWER_LEVEL;
2290 mbm = nla_get_u32(info->attrs[idx]);
2291 }
2292
Johannes Bergc8442112012-10-24 10:17:18 +02002293 result = rdev_set_tx_power(rdev, txp_wdev, type, mbm);
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03002294 if (result)
Ying Xue7f2b8562014-01-15 10:23:45 +08002295 return result;
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03002296 }
2297
Bruno Randolfafe0cbf2010-11-10 12:50:50 +09002298 if (info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX] &&
2299 info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]) {
2300 u32 tx_ant, rx_ant;
Kirtika Ruchandani7a087e72016-05-29 19:51:23 -07002301
Bruno Randolf7f531e02010-12-16 11:30:22 +09002302 if ((!rdev->wiphy.available_antennas_tx &&
2303 !rdev->wiphy.available_antennas_rx) ||
Ying Xue7f2b8562014-01-15 10:23:45 +08002304 !rdev->ops->set_antenna)
2305 return -EOPNOTSUPP;
Bruno Randolfafe0cbf2010-11-10 12:50:50 +09002306
2307 tx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX]);
2308 rx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]);
2309
Bruno Randolfa7ffac92010-12-08 13:59:24 +09002310 /* reject antenna configurations which don't match the
Bruno Randolf7f531e02010-12-16 11:30:22 +09002311 * available antenna masks, except for the "all" mask */
2312 if ((~tx_ant && (tx_ant & ~rdev->wiphy.available_antennas_tx)) ||
Ying Xue7f2b8562014-01-15 10:23:45 +08002313 (~rx_ant && (rx_ant & ~rdev->wiphy.available_antennas_rx)))
2314 return -EINVAL;
Bruno Randolfa7ffac92010-12-08 13:59:24 +09002315
Bruno Randolf7f531e02010-12-16 11:30:22 +09002316 tx_ant = tx_ant & rdev->wiphy.available_antennas_tx;
2317 rx_ant = rx_ant & rdev->wiphy.available_antennas_rx;
Bruno Randolfa7ffac92010-12-08 13:59:24 +09002318
Hila Gonene35e4d22012-06-27 17:19:42 +03002319 result = rdev_set_antenna(rdev, tx_ant, rx_ant);
Bruno Randolfafe0cbf2010-11-10 12:50:50 +09002320 if (result)
Ying Xue7f2b8562014-01-15 10:23:45 +08002321 return result;
Bruno Randolfafe0cbf2010-11-10 12:50:50 +09002322 }
2323
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002324 changed = 0;
2325
2326 if (info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]) {
2327 retry_short = nla_get_u8(
2328 info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]);
Ying Xue7f2b8562014-01-15 10:23:45 +08002329 if (retry_short == 0)
2330 return -EINVAL;
2331
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002332 changed |= WIPHY_PARAM_RETRY_SHORT;
2333 }
2334
2335 if (info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]) {
2336 retry_long = nla_get_u8(
2337 info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]);
Ying Xue7f2b8562014-01-15 10:23:45 +08002338 if (retry_long == 0)
2339 return -EINVAL;
2340
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002341 changed |= WIPHY_PARAM_RETRY_LONG;
2342 }
2343
2344 if (info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]) {
2345 frag_threshold = nla_get_u32(
2346 info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]);
Ying Xue7f2b8562014-01-15 10:23:45 +08002347 if (frag_threshold < 256)
2348 return -EINVAL;
2349
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002350 if (frag_threshold != (u32) -1) {
2351 /*
2352 * Fragments (apart from the last one) are required to
2353 * have even length. Make the fragmentation code
2354 * simpler by stripping LSB should someone try to use
2355 * odd threshold value.
2356 */
2357 frag_threshold &= ~0x1;
2358 }
2359 changed |= WIPHY_PARAM_FRAG_THRESHOLD;
2360 }
2361
2362 if (info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]) {
2363 rts_threshold = nla_get_u32(
2364 info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]);
2365 changed |= WIPHY_PARAM_RTS_THRESHOLD;
2366 }
2367
Lukáš Turek81077e82009-12-21 22:50:47 +01002368 if (info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]) {
Lorenzo Bianconi3057dbf2014-09-04 23:57:40 +02002369 if (info->attrs[NL80211_ATTR_WIPHY_DYN_ACK])
2370 return -EINVAL;
2371
Lukáš Turek81077e82009-12-21 22:50:47 +01002372 coverage_class = nla_get_u8(
2373 info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]);
2374 changed |= WIPHY_PARAM_COVERAGE_CLASS;
2375 }
2376
Lorenzo Bianconi3057dbf2014-09-04 23:57:40 +02002377 if (info->attrs[NL80211_ATTR_WIPHY_DYN_ACK]) {
2378 if (!(rdev->wiphy.features & NL80211_FEATURE_ACKTO_ESTIMATION))
2379 return -EOPNOTSUPP;
2380
2381 changed |= WIPHY_PARAM_DYN_ACK;
2382 }
2383
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002384 if (changed) {
2385 u8 old_retry_short, old_retry_long;
2386 u32 old_frag_threshold, old_rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01002387 u8 old_coverage_class;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002388
Ying Xue7f2b8562014-01-15 10:23:45 +08002389 if (!rdev->ops->set_wiphy_params)
2390 return -EOPNOTSUPP;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002391
2392 old_retry_short = rdev->wiphy.retry_short;
2393 old_retry_long = rdev->wiphy.retry_long;
2394 old_frag_threshold = rdev->wiphy.frag_threshold;
2395 old_rts_threshold = rdev->wiphy.rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01002396 old_coverage_class = rdev->wiphy.coverage_class;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002397
2398 if (changed & WIPHY_PARAM_RETRY_SHORT)
2399 rdev->wiphy.retry_short = retry_short;
2400 if (changed & WIPHY_PARAM_RETRY_LONG)
2401 rdev->wiphy.retry_long = retry_long;
2402 if (changed & WIPHY_PARAM_FRAG_THRESHOLD)
2403 rdev->wiphy.frag_threshold = frag_threshold;
2404 if (changed & WIPHY_PARAM_RTS_THRESHOLD)
2405 rdev->wiphy.rts_threshold = rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01002406 if (changed & WIPHY_PARAM_COVERAGE_CLASS)
2407 rdev->wiphy.coverage_class = coverage_class;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002408
Hila Gonene35e4d22012-06-27 17:19:42 +03002409 result = rdev_set_wiphy_params(rdev, changed);
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002410 if (result) {
2411 rdev->wiphy.retry_short = old_retry_short;
2412 rdev->wiphy.retry_long = old_retry_long;
2413 rdev->wiphy.frag_threshold = old_frag_threshold;
2414 rdev->wiphy.rts_threshold = old_rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01002415 rdev->wiphy.coverage_class = old_coverage_class;
Michal Kazior9189ee32015-08-03 10:55:24 +02002416 return result;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002417 }
2418 }
Ying Xue7f2b8562014-01-15 10:23:45 +08002419 return 0;
Johannes Berg55682962007-09-20 13:09:35 -04002420}
2421
Johannes Berg71bbc992012-06-15 15:30:18 +02002422static inline u64 wdev_id(struct wireless_dev *wdev)
2423{
2424 return (u64)wdev->identifier |
Zhao, Gangf26cbf42014-04-21 12:53:03 +08002425 ((u64)wiphy_to_rdev(wdev->wiphy)->wiphy_idx << 32);
Johannes Berg71bbc992012-06-15 15:30:18 +02002426}
Johannes Berg55682962007-09-20 13:09:35 -04002427
Johannes Berg683b6d32012-11-08 21:25:48 +01002428static int nl80211_send_chandef(struct sk_buff *msg,
Janusz Dziedzicd2859df2013-11-06 13:55:51 +01002429 const struct cfg80211_chan_def *chandef)
Johannes Berg683b6d32012-11-08 21:25:48 +01002430{
Johannes Berg601555c2014-11-27 17:26:56 +01002431 if (WARN_ON(!cfg80211_chandef_valid(chandef)))
2432 return -EINVAL;
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002433
Johannes Berg683b6d32012-11-08 21:25:48 +01002434 if (nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ,
2435 chandef->chan->center_freq))
2436 return -ENOBUFS;
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002437 switch (chandef->width) {
2438 case NL80211_CHAN_WIDTH_20_NOHT:
2439 case NL80211_CHAN_WIDTH_20:
2440 case NL80211_CHAN_WIDTH_40:
2441 if (nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE,
2442 cfg80211_get_chandef_type(chandef)))
2443 return -ENOBUFS;
2444 break;
2445 default:
2446 break;
2447 }
2448 if (nla_put_u32(msg, NL80211_ATTR_CHANNEL_WIDTH, chandef->width))
2449 return -ENOBUFS;
2450 if (nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ1, chandef->center_freq1))
2451 return -ENOBUFS;
2452 if (chandef->center_freq2 &&
2453 nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ2, chandef->center_freq2))
Johannes Berg683b6d32012-11-08 21:25:48 +01002454 return -ENOBUFS;
2455 return 0;
2456}
2457
Eric W. Biederman15e47302012-09-07 20:12:54 +00002458static int nl80211_send_iface(struct sk_buff *msg, u32 portid, u32 seq, int flags,
Johannes Bergd7264052009-04-19 16:23:20 +02002459 struct cfg80211_registered_device *rdev,
Tomasz Bursztyka8f894be2014-11-12 16:26:45 +02002460 struct wireless_dev *wdev, bool removal)
Johannes Berg55682962007-09-20 13:09:35 -04002461{
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002462 struct net_device *dev = wdev->netdev;
Tomasz Bursztyka8f894be2014-11-12 16:26:45 +02002463 u8 cmd = NL80211_CMD_NEW_INTERFACE;
Johannes Berg55682962007-09-20 13:09:35 -04002464 void *hdr;
2465
Tomasz Bursztyka8f894be2014-11-12 16:26:45 +02002466 if (removal)
2467 cmd = NL80211_CMD_DEL_INTERFACE;
2468
2469 hdr = nl80211hdr_put(msg, portid, seq, flags, cmd);
Johannes Berg55682962007-09-20 13:09:35 -04002470 if (!hdr)
2471 return -1;
2472
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002473 if (dev &&
2474 (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
Johannes Berg98104fde2012-06-16 00:19:54 +02002475 nla_put_string(msg, NL80211_ATTR_IFNAME, dev->name)))
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002476 goto nla_put_failure;
2477
2478 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
2479 nla_put_u32(msg, NL80211_ATTR_IFTYPE, wdev->iftype) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02002480 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
2481 NL80211_ATTR_PAD) ||
Johannes Berg98104fde2012-06-16 00:19:54 +02002482 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, wdev_address(wdev)) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04002483 nla_put_u32(msg, NL80211_ATTR_GENERATION,
2484 rdev->devlist_generation ^
2485 (cfg80211_rdev_list_generation << 2)))
2486 goto nla_put_failure;
Johannes Bergf5ea9122009-08-07 16:17:38 +02002487
Johannes Berg5b7ccaf2012-07-12 19:45:08 +02002488 if (rdev->ops->get_channel) {
Johannes Berg683b6d32012-11-08 21:25:48 +01002489 int ret;
2490 struct cfg80211_chan_def chandef;
Johannes Berg5b7ccaf2012-07-12 19:45:08 +02002491
Johannes Berg683b6d32012-11-08 21:25:48 +01002492 ret = rdev_get_channel(rdev, wdev, &chandef);
2493 if (ret == 0) {
2494 if (nl80211_send_chandef(msg, &chandef))
2495 goto nla_put_failure;
2496 }
Pontus Fuchsd91df0e2012-04-03 16:39:58 +02002497 }
2498
Rafał Miłeckid55d0d52015-08-31 22:59:38 +02002499 if (rdev->ops->get_tx_power) {
2500 int dbm, ret;
2501
2502 ret = rdev_get_tx_power(rdev, wdev, &dbm);
2503 if (ret == 0 &&
2504 nla_put_u32(msg, NL80211_ATTR_WIPHY_TX_POWER_LEVEL,
2505 DBM_TO_MBM(dbm)))
2506 goto nla_put_failure;
2507 }
2508
Antonio Quartullib84e7a02012-11-07 12:52:20 +01002509 if (wdev->ssid_len) {
2510 if (nla_put(msg, NL80211_ATTR_SSID, wdev->ssid_len, wdev->ssid))
2511 goto nla_put_failure;
2512 }
2513
Johannes Berg053c0952015-01-16 22:09:00 +01002514 genlmsg_end(msg, hdr);
2515 return 0;
Johannes Berg55682962007-09-20 13:09:35 -04002516
2517 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07002518 genlmsg_cancel(msg, hdr);
2519 return -EMSGSIZE;
Johannes Berg55682962007-09-20 13:09:35 -04002520}
2521
2522static int nl80211_dump_interface(struct sk_buff *skb, struct netlink_callback *cb)
2523{
2524 int wp_idx = 0;
2525 int if_idx = 0;
2526 int wp_start = cb->args[0];
2527 int if_start = cb->args[1];
Denis Kenziorb7fb44d2016-08-03 17:02:15 -05002528 int filter_wiphy = -1;
Johannes Bergf5ea9122009-08-07 16:17:38 +02002529 struct cfg80211_registered_device *rdev;
Johannes Berg55682962007-09-20 13:09:35 -04002530 struct wireless_dev *wdev;
2531
Johannes Berg5fe231e2013-05-08 21:45:15 +02002532 rtnl_lock();
Denis Kenziorb7fb44d2016-08-03 17:02:15 -05002533 if (!cb->args[2]) {
2534 struct nl80211_dump_wiphy_state state = {
2535 .filter_wiphy = -1,
2536 };
2537 int ret;
2538
2539 ret = nl80211_dump_wiphy_parse(skb, cb, &state);
2540 if (ret)
2541 return ret;
2542
2543 filter_wiphy = state.filter_wiphy;
2544
2545 /*
2546 * if filtering, set cb->args[2] to +1 since 0 is the default
2547 * value needed to determine that parsing is necessary.
2548 */
2549 if (filter_wiphy >= 0)
2550 cb->args[2] = filter_wiphy + 1;
2551 else
2552 cb->args[2] = -1;
2553 } else if (cb->args[2] > 0) {
2554 filter_wiphy = cb->args[2] - 1;
2555 }
2556
Johannes Bergf5ea9122009-08-07 16:17:38 +02002557 list_for_each_entry(rdev, &cfg80211_rdev_list, list) {
2558 if (!net_eq(wiphy_net(&rdev->wiphy), sock_net(skb->sk)))
Johannes Berg463d0182009-07-14 00:33:35 +02002559 continue;
Johannes Bergbba95fe2008-07-29 13:22:51 +02002560 if (wp_idx < wp_start) {
2561 wp_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04002562 continue;
Johannes Bergbba95fe2008-07-29 13:22:51 +02002563 }
Denis Kenziorb7fb44d2016-08-03 17:02:15 -05002564
2565 if (filter_wiphy >= 0 && filter_wiphy != rdev->wiphy_idx)
2566 continue;
2567
Johannes Berg55682962007-09-20 13:09:35 -04002568 if_idx = 0;
2569
Johannes Berg53873f12016-05-03 16:52:04 +03002570 list_for_each_entry(wdev, &rdev->wiphy.wdev_list, list) {
Johannes Bergbba95fe2008-07-29 13:22:51 +02002571 if (if_idx < if_start) {
2572 if_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04002573 continue;
Johannes Bergbba95fe2008-07-29 13:22:51 +02002574 }
Eric W. Biederman15e47302012-09-07 20:12:54 +00002575 if (nl80211_send_iface(skb, NETLINK_CB(cb->skb).portid,
Johannes Berg55682962007-09-20 13:09:35 -04002576 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Tomasz Bursztyka8f894be2014-11-12 16:26:45 +02002577 rdev, wdev, false) < 0) {
Johannes Bergbba95fe2008-07-29 13:22:51 +02002578 goto out;
2579 }
2580 if_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04002581 }
Johannes Bergbba95fe2008-07-29 13:22:51 +02002582
2583 wp_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04002584 }
Johannes Bergbba95fe2008-07-29 13:22:51 +02002585 out:
Johannes Berg5fe231e2013-05-08 21:45:15 +02002586 rtnl_unlock();
Johannes Berg55682962007-09-20 13:09:35 -04002587
2588 cb->args[0] = wp_idx;
2589 cb->args[1] = if_idx;
2590
2591 return skb->len;
2592}
2593
2594static int nl80211_get_interface(struct sk_buff *skb, struct genl_info *info)
2595{
2596 struct sk_buff *msg;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002597 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002598 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg55682962007-09-20 13:09:35 -04002599
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07002600 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -04002601 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02002602 return -ENOMEM;
Johannes Berg55682962007-09-20 13:09:35 -04002603
Eric W. Biederman15e47302012-09-07 20:12:54 +00002604 if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0,
Tomasz Bursztyka8f894be2014-11-12 16:26:45 +02002605 rdev, wdev, false) < 0) {
Johannes Berg4c476992010-10-04 21:36:35 +02002606 nlmsg_free(msg);
2607 return -ENOBUFS;
2608 }
Johannes Berg55682962007-09-20 13:09:35 -04002609
Johannes Berg134e6372009-07-10 09:51:34 +00002610 return genlmsg_reply(msg, info);
Johannes Berg55682962007-09-20 13:09:35 -04002611}
2612
Michael Wu66f7ac52008-01-31 19:48:22 +01002613static const struct nla_policy mntr_flags_policy[NL80211_MNTR_FLAG_MAX + 1] = {
2614 [NL80211_MNTR_FLAG_FCSFAIL] = { .type = NLA_FLAG },
2615 [NL80211_MNTR_FLAG_PLCPFAIL] = { .type = NLA_FLAG },
2616 [NL80211_MNTR_FLAG_CONTROL] = { .type = NLA_FLAG },
2617 [NL80211_MNTR_FLAG_OTHER_BSS] = { .type = NLA_FLAG },
2618 [NL80211_MNTR_FLAG_COOK_FRAMES] = { .type = NLA_FLAG },
Felix Fietkaue057d3c2013-05-28 13:01:52 +02002619 [NL80211_MNTR_FLAG_ACTIVE] = { .type = NLA_FLAG },
Michael Wu66f7ac52008-01-31 19:48:22 +01002620};
2621
2622static int parse_monitor_flags(struct nlattr *nla, u32 *mntrflags)
2623{
2624 struct nlattr *flags[NL80211_MNTR_FLAG_MAX + 1];
2625 int flag;
2626
2627 *mntrflags = 0;
2628
2629 if (!nla)
2630 return -EINVAL;
2631
2632 if (nla_parse_nested(flags, NL80211_MNTR_FLAG_MAX,
2633 nla, mntr_flags_policy))
2634 return -EINVAL;
2635
2636 for (flag = 1; flag <= NL80211_MNTR_FLAG_MAX; flag++)
2637 if (flags[flag])
2638 *mntrflags |= (1<<flag);
2639
2640 return 0;
2641}
2642
Johannes Berg9bc383d2009-11-19 11:55:19 +01002643static int nl80211_valid_4addr(struct cfg80211_registered_device *rdev,
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002644 struct net_device *netdev, u8 use_4addr,
2645 enum nl80211_iftype iftype)
Johannes Berg9bc383d2009-11-19 11:55:19 +01002646{
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002647 if (!use_4addr) {
Jiri Pirkof350a0a82010-06-15 06:50:45 +00002648 if (netdev && (netdev->priv_flags & IFF_BRIDGE_PORT))
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002649 return -EBUSY;
Johannes Berg9bc383d2009-11-19 11:55:19 +01002650 return 0;
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002651 }
Johannes Berg9bc383d2009-11-19 11:55:19 +01002652
2653 switch (iftype) {
2654 case NL80211_IFTYPE_AP_VLAN:
2655 if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_AP)
2656 return 0;
2657 break;
2658 case NL80211_IFTYPE_STATION:
2659 if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_STATION)
2660 return 0;
2661 break;
2662 default:
2663 break;
2664 }
2665
2666 return -EOPNOTSUPP;
2667}
2668
Johannes Berg55682962007-09-20 13:09:35 -04002669static int nl80211_set_interface(struct sk_buff *skb, struct genl_info *info)
2670{
Johannes Berg4c476992010-10-04 21:36:35 +02002671 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002672 struct vif_params params;
Johannes Berge36d56b2009-06-09 21:04:43 +02002673 int err;
Johannes Berg04a773a2009-04-19 21:24:32 +02002674 enum nl80211_iftype otype, ntype;
Johannes Berg4c476992010-10-04 21:36:35 +02002675 struct net_device *dev = info->user_ptr[1];
Johannes Berg92ffe052008-09-16 20:39:36 +02002676 u32 _flags, *flags = NULL;
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002677 bool change = false;
Johannes Berg55682962007-09-20 13:09:35 -04002678
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002679 memset(&params, 0, sizeof(params));
2680
Johannes Berg04a773a2009-04-19 21:24:32 +02002681 otype = ntype = dev->ieee80211_ptr->iftype;
Johannes Berg55682962007-09-20 13:09:35 -04002682
Johannes Berg723b0382008-09-16 20:22:09 +02002683 if (info->attrs[NL80211_ATTR_IFTYPE]) {
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002684 ntype = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]);
Johannes Berg04a773a2009-04-19 21:24:32 +02002685 if (otype != ntype)
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002686 change = true;
Johannes Berg4c476992010-10-04 21:36:35 +02002687 if (ntype > NL80211_IFTYPE_MAX)
2688 return -EINVAL;
Johannes Berg723b0382008-09-16 20:22:09 +02002689 }
2690
Johannes Berg92ffe052008-09-16 20:39:36 +02002691 if (info->attrs[NL80211_ATTR_MESH_ID]) {
Johannes Berg29cbe682010-12-03 09:20:44 +01002692 struct wireless_dev *wdev = dev->ieee80211_ptr;
2693
Johannes Berg4c476992010-10-04 21:36:35 +02002694 if (ntype != NL80211_IFTYPE_MESH_POINT)
2695 return -EINVAL;
Johannes Berg29cbe682010-12-03 09:20:44 +01002696 if (netif_running(dev))
2697 return -EBUSY;
2698
2699 wdev_lock(wdev);
2700 BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN !=
2701 IEEE80211_MAX_MESH_ID_LEN);
2702 wdev->mesh_id_up_len =
2703 nla_len(info->attrs[NL80211_ATTR_MESH_ID]);
2704 memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]),
2705 wdev->mesh_id_up_len);
2706 wdev_unlock(wdev);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002707 }
2708
Felix Fietkau8b787642009-11-10 18:53:10 +01002709 if (info->attrs[NL80211_ATTR_4ADDR]) {
2710 params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]);
2711 change = true;
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002712 err = nl80211_valid_4addr(rdev, dev, params.use_4addr, ntype);
Johannes Berg9bc383d2009-11-19 11:55:19 +01002713 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02002714 return err;
Felix Fietkau8b787642009-11-10 18:53:10 +01002715 } else {
2716 params.use_4addr = -1;
2717 }
2718
Johannes Berg92ffe052008-09-16 20:39:36 +02002719 if (info->attrs[NL80211_ATTR_MNTR_FLAGS]) {
Johannes Berg4c476992010-10-04 21:36:35 +02002720 if (ntype != NL80211_IFTYPE_MONITOR)
2721 return -EINVAL;
Johannes Berg92ffe052008-09-16 20:39:36 +02002722 err = parse_monitor_flags(info->attrs[NL80211_ATTR_MNTR_FLAGS],
2723 &_flags);
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002724 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02002725 return err;
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002726
2727 flags = &_flags;
2728 change = true;
Johannes Berg92ffe052008-09-16 20:39:36 +02002729 }
Johannes Berg3b858752009-03-12 09:55:09 +01002730
Aviya Erenfeldc6e6a0c2016-07-05 15:23:08 +03002731 if (info->attrs[NL80211_ATTR_MU_MIMO_GROUP_DATA]) {
2732 const u8 *mumimo_groups;
2733 u32 cap_flag = NL80211_EXT_FEATURE_MU_MIMO_AIR_SNIFFER;
2734
2735 if (!wiphy_ext_feature_isset(&rdev->wiphy, cap_flag))
2736 return -EOPNOTSUPP;
2737
2738 mumimo_groups =
2739 nla_data(info->attrs[NL80211_ATTR_MU_MIMO_GROUP_DATA]);
2740
2741 /* bits 0 and 63 are reserved and must be zero */
2742 if ((mumimo_groups[0] & BIT(7)) ||
2743 (mumimo_groups[VHT_MUMIMO_GROUPS_DATA_LEN - 1] & BIT(0)))
2744 return -EINVAL;
2745
2746 memcpy(params.vht_mumimo_groups, mumimo_groups,
2747 VHT_MUMIMO_GROUPS_DATA_LEN);
2748 change = true;
2749 }
2750
2751 if (info->attrs[NL80211_ATTR_MU_MIMO_FOLLOW_MAC_ADDR]) {
2752 u32 cap_flag = NL80211_EXT_FEATURE_MU_MIMO_AIR_SNIFFER;
2753
2754 if (!wiphy_ext_feature_isset(&rdev->wiphy, cap_flag))
2755 return -EOPNOTSUPP;
2756
2757 nla_memcpy(params.macaddr,
2758 info->attrs[NL80211_ATTR_MU_MIMO_FOLLOW_MAC_ADDR],
2759 ETH_ALEN);
2760 change = true;
2761 }
2762
Luciano Coelho18003292013-08-29 13:26:57 +03002763 if (flags && (*flags & MONITOR_FLAG_ACTIVE) &&
Felix Fietkaue057d3c2013-05-28 13:01:52 +02002764 !(rdev->wiphy.features & NL80211_FEATURE_ACTIVE_MONITOR))
2765 return -EOPNOTSUPP;
2766
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002767 if (change)
Johannes Berg3d54d252009-08-21 14:51:05 +02002768 err = cfg80211_change_iface(rdev, dev, ntype, flags, &params);
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002769 else
2770 err = 0;
Johannes Berg60719ff2008-09-16 14:55:09 +02002771
Johannes Berg9bc383d2009-11-19 11:55:19 +01002772 if (!err && params.use_4addr != -1)
2773 dev->ieee80211_ptr->use_4addr = params.use_4addr;
2774
Johannes Berg55682962007-09-20 13:09:35 -04002775 return err;
2776}
2777
2778static int nl80211_new_interface(struct sk_buff *skb, struct genl_info *info)
2779{
Johannes Berg4c476992010-10-04 21:36:35 +02002780 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002781 struct vif_params params;
Johannes Berg84efbb82012-06-16 00:00:26 +02002782 struct wireless_dev *wdev;
Denis Kenzior896ff062016-08-03 16:58:33 -05002783 struct sk_buff *msg;
Johannes Berg55682962007-09-20 13:09:35 -04002784 int err;
2785 enum nl80211_iftype type = NL80211_IFTYPE_UNSPECIFIED;
Michael Wu66f7ac52008-01-31 19:48:22 +01002786 u32 flags;
Johannes Berg55682962007-09-20 13:09:35 -04002787
Johannes Berg78f22b62014-03-24 17:57:27 +01002788 /* to avoid failing a new interface creation due to pending removal */
2789 cfg80211_destroy_ifaces(rdev);
2790
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002791 memset(&params, 0, sizeof(params));
2792
Johannes Berg55682962007-09-20 13:09:35 -04002793 if (!info->attrs[NL80211_ATTR_IFNAME])
2794 return -EINVAL;
2795
2796 if (info->attrs[NL80211_ATTR_IFTYPE]) {
2797 type = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]);
2798 if (type > NL80211_IFTYPE_MAX)
2799 return -EINVAL;
2800 }
2801
Johannes Berg79c97e92009-07-07 03:56:12 +02002802 if (!rdev->ops->add_virtual_intf ||
Johannes Berg4c476992010-10-04 21:36:35 +02002803 !(rdev->wiphy.interface_modes & (1 << type)))
2804 return -EOPNOTSUPP;
Johannes Berg55682962007-09-20 13:09:35 -04002805
Ben Greeare8f479b2014-10-22 12:23:05 -07002806 if ((type == NL80211_IFTYPE_P2P_DEVICE ||
2807 rdev->wiphy.features & NL80211_FEATURE_MAC_ON_CREATE) &&
2808 info->attrs[NL80211_ATTR_MAC]) {
Arend van Spriel1c18f142013-01-08 10:17:27 +01002809 nla_memcpy(params.macaddr, info->attrs[NL80211_ATTR_MAC],
2810 ETH_ALEN);
2811 if (!is_valid_ether_addr(params.macaddr))
2812 return -EADDRNOTAVAIL;
2813 }
2814
Johannes Berg9bc383d2009-11-19 11:55:19 +01002815 if (info->attrs[NL80211_ATTR_4ADDR]) {
Felix Fietkau8b787642009-11-10 18:53:10 +01002816 params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]);
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002817 err = nl80211_valid_4addr(rdev, NULL, params.use_4addr, type);
Johannes Berg9bc383d2009-11-19 11:55:19 +01002818 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02002819 return err;
Johannes Berg9bc383d2009-11-19 11:55:19 +01002820 }
Felix Fietkau8b787642009-11-10 18:53:10 +01002821
Michael Wu66f7ac52008-01-31 19:48:22 +01002822 err = parse_monitor_flags(type == NL80211_IFTYPE_MONITOR ?
2823 info->attrs[NL80211_ATTR_MNTR_FLAGS] : NULL,
2824 &flags);
Felix Fietkaue057d3c2013-05-28 13:01:52 +02002825
Luciano Coelho18003292013-08-29 13:26:57 +03002826 if (!err && (flags & MONITOR_FLAG_ACTIVE) &&
Felix Fietkaue057d3c2013-05-28 13:01:52 +02002827 !(rdev->wiphy.features & NL80211_FEATURE_ACTIVE_MONITOR))
2828 return -EOPNOTSUPP;
2829
Johannes Berga18c7192015-02-24 10:56:42 +01002830 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
2831 if (!msg)
2832 return -ENOMEM;
2833
Hila Gonene35e4d22012-06-27 17:19:42 +03002834 wdev = rdev_add_virtual_intf(rdev,
2835 nla_data(info->attrs[NL80211_ATTR_IFNAME]),
Tom Gundersen6bab2e192015-03-18 11:13:39 +01002836 NET_NAME_USER, type, err ? NULL : &flags,
2837 &params);
Rafał Miłeckid687cbb2014-11-14 18:43:28 +01002838 if (WARN_ON(!wdev)) {
2839 nlmsg_free(msg);
2840 return -EPROTO;
2841 } else if (IS_ERR(wdev)) {
Johannes Berg1c90f9d2012-06-16 00:05:37 +02002842 nlmsg_free(msg);
Johannes Berg84efbb82012-06-16 00:00:26 +02002843 return PTR_ERR(wdev);
Johannes Berg1c90f9d2012-06-16 00:05:37 +02002844 }
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002845
Jukka Rissanen18e5ca62014-11-13 17:25:14 +02002846 if (info->attrs[NL80211_ATTR_SOCKET_OWNER])
Johannes Berg78f22b62014-03-24 17:57:27 +01002847 wdev->owner_nlportid = info->snd_portid;
2848
Johannes Berg98104fde2012-06-16 00:19:54 +02002849 switch (type) {
2850 case NL80211_IFTYPE_MESH_POINT:
2851 if (!info->attrs[NL80211_ATTR_MESH_ID])
2852 break;
Johannes Berg29cbe682010-12-03 09:20:44 +01002853 wdev_lock(wdev);
2854 BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN !=
2855 IEEE80211_MAX_MESH_ID_LEN);
2856 wdev->mesh_id_up_len =
2857 nla_len(info->attrs[NL80211_ATTR_MESH_ID]);
2858 memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]),
2859 wdev->mesh_id_up_len);
2860 wdev_unlock(wdev);
Johannes Berg98104fde2012-06-16 00:19:54 +02002861 break;
2862 case NL80211_IFTYPE_P2P_DEVICE:
2863 /*
2864 * P2P Device doesn't have a netdev, so doesn't go
2865 * through the netdev notifier and must be added here
2866 */
2867 mutex_init(&wdev->mtx);
2868 INIT_LIST_HEAD(&wdev->event_list);
2869 spin_lock_init(&wdev->event_lock);
2870 INIT_LIST_HEAD(&wdev->mgmt_registrations);
2871 spin_lock_init(&wdev->mgmt_registrations_lock);
2872
Johannes Berg98104fde2012-06-16 00:19:54 +02002873 wdev->identifier = ++rdev->wdev_id;
Johannes Berg53873f12016-05-03 16:52:04 +03002874 list_add_rcu(&wdev->list, &rdev->wiphy.wdev_list);
Johannes Berg98104fde2012-06-16 00:19:54 +02002875 rdev->devlist_generation++;
Johannes Berg98104fde2012-06-16 00:19:54 +02002876 break;
2877 default:
2878 break;
Johannes Berg29cbe682010-12-03 09:20:44 +01002879 }
2880
Eric W. Biederman15e47302012-09-07 20:12:54 +00002881 if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0,
Tomasz Bursztyka8f894be2014-11-12 16:26:45 +02002882 rdev, wdev, false) < 0) {
Johannes Berg1c90f9d2012-06-16 00:05:37 +02002883 nlmsg_free(msg);
2884 return -ENOBUFS;
2885 }
2886
Denis Kenzior896ff062016-08-03 16:58:33 -05002887 /*
2888 * For wdevs which have no associated netdev object (e.g. of type
2889 * NL80211_IFTYPE_P2P_DEVICE), emit the NEW_INTERFACE event here.
2890 * For all other types, the event will be generated from the
2891 * netdev notifier
2892 */
2893 if (!wdev->netdev)
2894 nl80211_notify_iface(rdev, wdev, NL80211_CMD_NEW_INTERFACE);
Tomasz Bursztyka8f894be2014-11-12 16:26:45 +02002895
Johannes Berg1c90f9d2012-06-16 00:05:37 +02002896 return genlmsg_reply(msg, info);
Johannes Berg55682962007-09-20 13:09:35 -04002897}
2898
2899static int nl80211_del_interface(struct sk_buff *skb, struct genl_info *info)
2900{
Johannes Berg4c476992010-10-04 21:36:35 +02002901 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg84efbb82012-06-16 00:00:26 +02002902 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg55682962007-09-20 13:09:35 -04002903
Johannes Berg4c476992010-10-04 21:36:35 +02002904 if (!rdev->ops->del_virtual_intf)
2905 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01002906
Johannes Berg84efbb82012-06-16 00:00:26 +02002907 /*
2908 * If we remove a wireless device without a netdev then clear
2909 * user_ptr[1] so that nl80211_post_doit won't dereference it
2910 * to check if it needs to do dev_put(). Otherwise it crashes
2911 * since the wdev has been freed, unlike with a netdev where
2912 * we need the dev_put() for the netdev to really be freed.
2913 */
2914 if (!wdev->netdev)
2915 info->user_ptr[1] = NULL;
2916
Denis Kenzior7f8ed012016-08-03 16:58:35 -05002917 return rdev_del_virtual_intf(rdev, wdev);
Johannes Berg55682962007-09-20 13:09:35 -04002918}
2919
Simon Wunderlich1d9d9212011-11-18 14:20:43 +01002920static int nl80211_set_noack_map(struct sk_buff *skb, struct genl_info *info)
2921{
2922 struct cfg80211_registered_device *rdev = info->user_ptr[0];
2923 struct net_device *dev = info->user_ptr[1];
2924 u16 noack_map;
2925
2926 if (!info->attrs[NL80211_ATTR_NOACK_MAP])
2927 return -EINVAL;
2928
2929 if (!rdev->ops->set_noack_map)
2930 return -EOPNOTSUPP;
2931
2932 noack_map = nla_get_u16(info->attrs[NL80211_ATTR_NOACK_MAP]);
2933
Hila Gonene35e4d22012-06-27 17:19:42 +03002934 return rdev_set_noack_map(rdev, dev, noack_map);
Simon Wunderlich1d9d9212011-11-18 14:20:43 +01002935}
2936
Johannes Berg41ade002007-12-19 02:03:29 +01002937struct get_key_cookie {
2938 struct sk_buff *msg;
2939 int error;
Johannes Bergb9454e82009-07-08 13:29:08 +02002940 int idx;
Johannes Berg41ade002007-12-19 02:03:29 +01002941};
2942
2943static void get_key_callback(void *c, struct key_params *params)
2944{
Johannes Bergb9454e82009-07-08 13:29:08 +02002945 struct nlattr *key;
Johannes Berg41ade002007-12-19 02:03:29 +01002946 struct get_key_cookie *cookie = c;
2947
David S. Miller9360ffd2012-03-29 04:41:26 -04002948 if ((params->key &&
2949 nla_put(cookie->msg, NL80211_ATTR_KEY_DATA,
2950 params->key_len, params->key)) ||
2951 (params->seq &&
2952 nla_put(cookie->msg, NL80211_ATTR_KEY_SEQ,
2953 params->seq_len, params->seq)) ||
2954 (params->cipher &&
2955 nla_put_u32(cookie->msg, NL80211_ATTR_KEY_CIPHER,
2956 params->cipher)))
2957 goto nla_put_failure;
Johannes Berg41ade002007-12-19 02:03:29 +01002958
Johannes Bergb9454e82009-07-08 13:29:08 +02002959 key = nla_nest_start(cookie->msg, NL80211_ATTR_KEY);
2960 if (!key)
2961 goto nla_put_failure;
2962
David S. Miller9360ffd2012-03-29 04:41:26 -04002963 if ((params->key &&
2964 nla_put(cookie->msg, NL80211_KEY_DATA,
2965 params->key_len, params->key)) ||
2966 (params->seq &&
2967 nla_put(cookie->msg, NL80211_KEY_SEQ,
2968 params->seq_len, params->seq)) ||
2969 (params->cipher &&
2970 nla_put_u32(cookie->msg, NL80211_KEY_CIPHER,
2971 params->cipher)))
2972 goto nla_put_failure;
Johannes Bergb9454e82009-07-08 13:29:08 +02002973
David S. Miller9360ffd2012-03-29 04:41:26 -04002974 if (nla_put_u8(cookie->msg, NL80211_ATTR_KEY_IDX, cookie->idx))
2975 goto nla_put_failure;
Johannes Bergb9454e82009-07-08 13:29:08 +02002976
2977 nla_nest_end(cookie->msg, key);
2978
Johannes Berg41ade002007-12-19 02:03:29 +01002979 return;
2980 nla_put_failure:
2981 cookie->error = 1;
2982}
2983
2984static int nl80211_get_key(struct sk_buff *skb, struct genl_info *info)
2985{
Johannes Berg4c476992010-10-04 21:36:35 +02002986 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg41ade002007-12-19 02:03:29 +01002987 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02002988 struct net_device *dev = info->user_ptr[1];
Johannes Berg41ade002007-12-19 02:03:29 +01002989 u8 key_idx = 0;
Johannes Berge31b8212010-10-05 19:39:30 +02002990 const u8 *mac_addr = NULL;
2991 bool pairwise;
Johannes Berg41ade002007-12-19 02:03:29 +01002992 struct get_key_cookie cookie = {
2993 .error = 0,
2994 };
2995 void *hdr;
2996 struct sk_buff *msg;
2997
2998 if (info->attrs[NL80211_ATTR_KEY_IDX])
2999 key_idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]);
3000
Jouni Malinen3cfcf6ac2009-01-08 13:32:02 +02003001 if (key_idx > 5)
Johannes Berg41ade002007-12-19 02:03:29 +01003002 return -EINVAL;
3003
3004 if (info->attrs[NL80211_ATTR_MAC])
3005 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
3006
Johannes Berge31b8212010-10-05 19:39:30 +02003007 pairwise = !!mac_addr;
3008 if (info->attrs[NL80211_ATTR_KEY_TYPE]) {
3009 u32 kt = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]);
Kirtika Ruchandani7a087e72016-05-29 19:51:23 -07003010
Johannes Berge31b8212010-10-05 19:39:30 +02003011 if (kt >= NUM_NL80211_KEYTYPES)
3012 return -EINVAL;
3013 if (kt != NL80211_KEYTYPE_GROUP &&
3014 kt != NL80211_KEYTYPE_PAIRWISE)
3015 return -EINVAL;
3016 pairwise = kt == NL80211_KEYTYPE_PAIRWISE;
3017 }
3018
Johannes Berg4c476992010-10-04 21:36:35 +02003019 if (!rdev->ops->get_key)
3020 return -EOPNOTSUPP;
Johannes Berg41ade002007-12-19 02:03:29 +01003021
Johannes Berg0fa7b392015-01-23 11:10:12 +01003022 if (!pairwise && mac_addr && !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN))
3023 return -ENOENT;
3024
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07003025 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02003026 if (!msg)
3027 return -ENOMEM;
Johannes Berg41ade002007-12-19 02:03:29 +01003028
Eric W. Biederman15e47302012-09-07 20:12:54 +00003029 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berg41ade002007-12-19 02:03:29 +01003030 NL80211_CMD_NEW_KEY);
Dan Carpentercb35fba2013-08-14 14:50:01 +03003031 if (!hdr)
Johannes Berg9fe271a2013-10-25 11:15:12 +02003032 goto nla_put_failure;
Johannes Berg41ade002007-12-19 02:03:29 +01003033
3034 cookie.msg = msg;
Johannes Bergb9454e82009-07-08 13:29:08 +02003035 cookie.idx = key_idx;
Johannes Berg41ade002007-12-19 02:03:29 +01003036
David S. Miller9360ffd2012-03-29 04:41:26 -04003037 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
3038 nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_idx))
3039 goto nla_put_failure;
3040 if (mac_addr &&
3041 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr))
3042 goto nla_put_failure;
Johannes Berg41ade002007-12-19 02:03:29 +01003043
Hila Gonene35e4d22012-06-27 17:19:42 +03003044 err = rdev_get_key(rdev, dev, key_idx, pairwise, mac_addr, &cookie,
3045 get_key_callback);
Johannes Berg41ade002007-12-19 02:03:29 +01003046
3047 if (err)
Niko Jokinen6c95e2a2009-07-15 11:00:53 +03003048 goto free_msg;
Johannes Berg41ade002007-12-19 02:03:29 +01003049
3050 if (cookie.error)
3051 goto nla_put_failure;
3052
3053 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02003054 return genlmsg_reply(msg, info);
Johannes Berg41ade002007-12-19 02:03:29 +01003055
3056 nla_put_failure:
3057 err = -ENOBUFS;
Niko Jokinen6c95e2a2009-07-15 11:00:53 +03003058 free_msg:
Johannes Berg41ade002007-12-19 02:03:29 +01003059 nlmsg_free(msg);
Johannes Berg41ade002007-12-19 02:03:29 +01003060 return err;
3061}
3062
3063static int nl80211_set_key(struct sk_buff *skb, struct genl_info *info)
3064{
Johannes Berg4c476992010-10-04 21:36:35 +02003065 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Bergb9454e82009-07-08 13:29:08 +02003066 struct key_parse key;
Johannes Berg41ade002007-12-19 02:03:29 +01003067 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02003068 struct net_device *dev = info->user_ptr[1];
Johannes Berg41ade002007-12-19 02:03:29 +01003069
Johannes Bergb9454e82009-07-08 13:29:08 +02003070 err = nl80211_parse_key(info, &key);
3071 if (err)
3072 return err;
3073
3074 if (key.idx < 0)
Johannes Berg41ade002007-12-19 02:03:29 +01003075 return -EINVAL;
3076
Johannes Bergb9454e82009-07-08 13:29:08 +02003077 /* only support setting default key */
3078 if (!key.def && !key.defmgmt)
Johannes Berg41ade002007-12-19 02:03:29 +01003079 return -EINVAL;
3080
Johannes Bergfffd0932009-07-08 14:22:54 +02003081 wdev_lock(dev->ieee80211_ptr);
Johannes Bergdbd2fd62010-12-09 19:58:59 +01003082
3083 if (key.def) {
3084 if (!rdev->ops->set_default_key) {
3085 err = -EOPNOTSUPP;
3086 goto out;
3087 }
3088
3089 err = nl80211_key_allowed(dev->ieee80211_ptr);
3090 if (err)
3091 goto out;
3092
Hila Gonene35e4d22012-06-27 17:19:42 +03003093 err = rdev_set_default_key(rdev, dev, key.idx,
Johannes Bergdbd2fd62010-12-09 19:58:59 +01003094 key.def_uni, key.def_multi);
3095
3096 if (err)
3097 goto out;
Johannes Bergfffd0932009-07-08 14:22:54 +02003098
Johannes Berg3d23e342009-09-29 23:27:28 +02003099#ifdef CONFIG_CFG80211_WEXT
Johannes Bergdbd2fd62010-12-09 19:58:59 +01003100 dev->ieee80211_ptr->wext.default_key = key.idx;
Johannes Berg08645122009-05-11 13:54:58 +02003101#endif
Johannes Bergdbd2fd62010-12-09 19:58:59 +01003102 } else {
3103 if (key.def_uni || !key.def_multi) {
3104 err = -EINVAL;
3105 goto out;
3106 }
3107
3108 if (!rdev->ops->set_default_mgmt_key) {
3109 err = -EOPNOTSUPP;
3110 goto out;
3111 }
3112
3113 err = nl80211_key_allowed(dev->ieee80211_ptr);
3114 if (err)
3115 goto out;
3116
Hila Gonene35e4d22012-06-27 17:19:42 +03003117 err = rdev_set_default_mgmt_key(rdev, dev, key.idx);
Johannes Bergdbd2fd62010-12-09 19:58:59 +01003118 if (err)
3119 goto out;
3120
3121#ifdef CONFIG_CFG80211_WEXT
3122 dev->ieee80211_ptr->wext.default_mgmt_key = key.idx;
3123#endif
3124 }
3125
3126 out:
Johannes Bergfffd0932009-07-08 14:22:54 +02003127 wdev_unlock(dev->ieee80211_ptr);
Johannes Berg41ade002007-12-19 02:03:29 +01003128
Johannes Berg41ade002007-12-19 02:03:29 +01003129 return err;
3130}
3131
3132static int nl80211_new_key(struct sk_buff *skb, struct genl_info *info)
3133{
Johannes Berg4c476992010-10-04 21:36:35 +02003134 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Bergfffd0932009-07-08 14:22:54 +02003135 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02003136 struct net_device *dev = info->user_ptr[1];
Johannes Bergb9454e82009-07-08 13:29:08 +02003137 struct key_parse key;
Johannes Berge31b8212010-10-05 19:39:30 +02003138 const u8 *mac_addr = NULL;
Johannes Berg41ade002007-12-19 02:03:29 +01003139
Johannes Bergb9454e82009-07-08 13:29:08 +02003140 err = nl80211_parse_key(info, &key);
3141 if (err)
3142 return err;
Johannes Berg41ade002007-12-19 02:03:29 +01003143
Johannes Bergb9454e82009-07-08 13:29:08 +02003144 if (!key.p.key)
Johannes Berg41ade002007-12-19 02:03:29 +01003145 return -EINVAL;
3146
Johannes Berg41ade002007-12-19 02:03:29 +01003147 if (info->attrs[NL80211_ATTR_MAC])
3148 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
3149
Johannes Berge31b8212010-10-05 19:39:30 +02003150 if (key.type == -1) {
3151 if (mac_addr)
3152 key.type = NL80211_KEYTYPE_PAIRWISE;
3153 else
3154 key.type = NL80211_KEYTYPE_GROUP;
3155 }
3156
3157 /* for now */
3158 if (key.type != NL80211_KEYTYPE_PAIRWISE &&
3159 key.type != NL80211_KEYTYPE_GROUP)
3160 return -EINVAL;
3161
Johannes Berg4c476992010-10-04 21:36:35 +02003162 if (!rdev->ops->add_key)
3163 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01003164
Johannes Berge31b8212010-10-05 19:39:30 +02003165 if (cfg80211_validate_key_settings(rdev, &key.p, key.idx,
3166 key.type == NL80211_KEYTYPE_PAIRWISE,
3167 mac_addr))
Johannes Berg4c476992010-10-04 21:36:35 +02003168 return -EINVAL;
Johannes Bergfffd0932009-07-08 14:22:54 +02003169
3170 wdev_lock(dev->ieee80211_ptr);
3171 err = nl80211_key_allowed(dev->ieee80211_ptr);
3172 if (!err)
Hila Gonene35e4d22012-06-27 17:19:42 +03003173 err = rdev_add_key(rdev, dev, key.idx,
3174 key.type == NL80211_KEYTYPE_PAIRWISE,
3175 mac_addr, &key.p);
Johannes Bergfffd0932009-07-08 14:22:54 +02003176 wdev_unlock(dev->ieee80211_ptr);
Johannes Berg41ade002007-12-19 02:03:29 +01003177
Johannes Berg41ade002007-12-19 02:03:29 +01003178 return err;
3179}
3180
3181static int nl80211_del_key(struct sk_buff *skb, struct genl_info *info)
3182{
Johannes Berg4c476992010-10-04 21:36:35 +02003183 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg41ade002007-12-19 02:03:29 +01003184 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02003185 struct net_device *dev = info->user_ptr[1];
Johannes Berg41ade002007-12-19 02:03:29 +01003186 u8 *mac_addr = NULL;
Johannes Bergb9454e82009-07-08 13:29:08 +02003187 struct key_parse key;
Johannes Berg41ade002007-12-19 02:03:29 +01003188
Johannes Bergb9454e82009-07-08 13:29:08 +02003189 err = nl80211_parse_key(info, &key);
3190 if (err)
3191 return err;
Johannes Berg41ade002007-12-19 02:03:29 +01003192
3193 if (info->attrs[NL80211_ATTR_MAC])
3194 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
3195
Johannes Berge31b8212010-10-05 19:39:30 +02003196 if (key.type == -1) {
3197 if (mac_addr)
3198 key.type = NL80211_KEYTYPE_PAIRWISE;
3199 else
3200 key.type = NL80211_KEYTYPE_GROUP;
3201 }
3202
3203 /* for now */
3204 if (key.type != NL80211_KEYTYPE_PAIRWISE &&
3205 key.type != NL80211_KEYTYPE_GROUP)
3206 return -EINVAL;
3207
Johannes Berg4c476992010-10-04 21:36:35 +02003208 if (!rdev->ops->del_key)
3209 return -EOPNOTSUPP;
Johannes Berg41ade002007-12-19 02:03:29 +01003210
Johannes Bergfffd0932009-07-08 14:22:54 +02003211 wdev_lock(dev->ieee80211_ptr);
3212 err = nl80211_key_allowed(dev->ieee80211_ptr);
Johannes Berge31b8212010-10-05 19:39:30 +02003213
Johannes Berg0fa7b392015-01-23 11:10:12 +01003214 if (key.type == NL80211_KEYTYPE_GROUP && mac_addr &&
Johannes Berge31b8212010-10-05 19:39:30 +02003215 !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN))
3216 err = -ENOENT;
3217
Johannes Bergfffd0932009-07-08 14:22:54 +02003218 if (!err)
Hila Gonene35e4d22012-06-27 17:19:42 +03003219 err = rdev_del_key(rdev, dev, key.idx,
3220 key.type == NL80211_KEYTYPE_PAIRWISE,
3221 mac_addr);
Johannes Berg41ade002007-12-19 02:03:29 +01003222
Johannes Berg3d23e342009-09-29 23:27:28 +02003223#ifdef CONFIG_CFG80211_WEXT
Johannes Berg08645122009-05-11 13:54:58 +02003224 if (!err) {
Johannes Bergb9454e82009-07-08 13:29:08 +02003225 if (key.idx == dev->ieee80211_ptr->wext.default_key)
Johannes Berg08645122009-05-11 13:54:58 +02003226 dev->ieee80211_ptr->wext.default_key = -1;
Johannes Bergb9454e82009-07-08 13:29:08 +02003227 else if (key.idx == dev->ieee80211_ptr->wext.default_mgmt_key)
Johannes Berg08645122009-05-11 13:54:58 +02003228 dev->ieee80211_ptr->wext.default_mgmt_key = -1;
3229 }
3230#endif
Johannes Bergfffd0932009-07-08 14:22:54 +02003231 wdev_unlock(dev->ieee80211_ptr);
Johannes Berg08645122009-05-11 13:54:58 +02003232
Johannes Berg41ade002007-12-19 02:03:29 +01003233 return err;
3234}
3235
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +05303236/* This function returns an error or the number of nested attributes */
3237static int validate_acl_mac_addrs(struct nlattr *nl_attr)
3238{
3239 struct nlattr *attr;
3240 int n_entries = 0, tmp;
3241
3242 nla_for_each_nested(attr, nl_attr, tmp) {
3243 if (nla_len(attr) != ETH_ALEN)
3244 return -EINVAL;
3245
3246 n_entries++;
3247 }
3248
3249 return n_entries;
3250}
3251
3252/*
3253 * This function parses ACL information and allocates memory for ACL data.
3254 * On successful return, the calling function is responsible to free the
3255 * ACL buffer returned by this function.
3256 */
3257static struct cfg80211_acl_data *parse_acl_data(struct wiphy *wiphy,
3258 struct genl_info *info)
3259{
3260 enum nl80211_acl_policy acl_policy;
3261 struct nlattr *attr;
3262 struct cfg80211_acl_data *acl;
3263 int i = 0, n_entries, tmp;
3264
3265 if (!wiphy->max_acl_mac_addrs)
3266 return ERR_PTR(-EOPNOTSUPP);
3267
3268 if (!info->attrs[NL80211_ATTR_ACL_POLICY])
3269 return ERR_PTR(-EINVAL);
3270
3271 acl_policy = nla_get_u32(info->attrs[NL80211_ATTR_ACL_POLICY]);
3272 if (acl_policy != NL80211_ACL_POLICY_ACCEPT_UNLESS_LISTED &&
3273 acl_policy != NL80211_ACL_POLICY_DENY_UNLESS_LISTED)
3274 return ERR_PTR(-EINVAL);
3275
3276 if (!info->attrs[NL80211_ATTR_MAC_ADDRS])
3277 return ERR_PTR(-EINVAL);
3278
3279 n_entries = validate_acl_mac_addrs(info->attrs[NL80211_ATTR_MAC_ADDRS]);
3280 if (n_entries < 0)
3281 return ERR_PTR(n_entries);
3282
3283 if (n_entries > wiphy->max_acl_mac_addrs)
3284 return ERR_PTR(-ENOTSUPP);
3285
3286 acl = kzalloc(sizeof(*acl) + (sizeof(struct mac_address) * n_entries),
3287 GFP_KERNEL);
3288 if (!acl)
3289 return ERR_PTR(-ENOMEM);
3290
3291 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_MAC_ADDRS], tmp) {
3292 memcpy(acl->mac_addrs[i].addr, nla_data(attr), ETH_ALEN);
3293 i++;
3294 }
3295
3296 acl->n_acl_entries = n_entries;
3297 acl->acl_policy = acl_policy;
3298
3299 return acl;
3300}
3301
3302static int nl80211_set_mac_acl(struct sk_buff *skb, struct genl_info *info)
3303{
3304 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3305 struct net_device *dev = info->user_ptr[1];
3306 struct cfg80211_acl_data *acl;
3307 int err;
3308
3309 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
3310 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
3311 return -EOPNOTSUPP;
3312
3313 if (!dev->ieee80211_ptr->beacon_interval)
3314 return -EINVAL;
3315
3316 acl = parse_acl_data(&rdev->wiphy, info);
3317 if (IS_ERR(acl))
3318 return PTR_ERR(acl);
3319
3320 err = rdev_set_mac_acl(rdev, dev, acl);
3321
3322 kfree(acl);
3323
3324 return err;
3325}
3326
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003327static int nl80211_parse_beacon(struct nlattr *attrs[],
Johannes Berg88600202012-02-13 15:17:18 +01003328 struct cfg80211_beacon_data *bcn)
Johannes Berged1b6cc2007-12-19 02:03:32 +01003329{
Johannes Berg88600202012-02-13 15:17:18 +01003330 bool haveinfo = false;
Johannes Berged1b6cc2007-12-19 02:03:32 +01003331
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003332 if (!is_valid_ie_attr(attrs[NL80211_ATTR_BEACON_TAIL]) ||
3333 !is_valid_ie_attr(attrs[NL80211_ATTR_IE]) ||
3334 !is_valid_ie_attr(attrs[NL80211_ATTR_IE_PROBE_RESP]) ||
3335 !is_valid_ie_attr(attrs[NL80211_ATTR_IE_ASSOC_RESP]))
Johannes Bergf4a11bb2009-03-27 12:40:28 +01003336 return -EINVAL;
3337
Johannes Berg88600202012-02-13 15:17:18 +01003338 memset(bcn, 0, sizeof(*bcn));
Johannes Berged1b6cc2007-12-19 02:03:32 +01003339
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003340 if (attrs[NL80211_ATTR_BEACON_HEAD]) {
3341 bcn->head = nla_data(attrs[NL80211_ATTR_BEACON_HEAD]);
3342 bcn->head_len = nla_len(attrs[NL80211_ATTR_BEACON_HEAD]);
Johannes Berg88600202012-02-13 15:17:18 +01003343 if (!bcn->head_len)
3344 return -EINVAL;
3345 haveinfo = true;
Johannes Berged1b6cc2007-12-19 02:03:32 +01003346 }
3347
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003348 if (attrs[NL80211_ATTR_BEACON_TAIL]) {
3349 bcn->tail = nla_data(attrs[NL80211_ATTR_BEACON_TAIL]);
3350 bcn->tail_len = nla_len(attrs[NL80211_ATTR_BEACON_TAIL]);
Johannes Berg88600202012-02-13 15:17:18 +01003351 haveinfo = true;
Johannes Berged1b6cc2007-12-19 02:03:32 +01003352 }
3353
Johannes Berg4c476992010-10-04 21:36:35 +02003354 if (!haveinfo)
3355 return -EINVAL;
Johannes Berged1b6cc2007-12-19 02:03:32 +01003356
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003357 if (attrs[NL80211_ATTR_IE]) {
3358 bcn->beacon_ies = nla_data(attrs[NL80211_ATTR_IE]);
3359 bcn->beacon_ies_len = nla_len(attrs[NL80211_ATTR_IE]);
Jouni Malinen9946ecf2011-08-10 23:55:56 +03003360 }
3361
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003362 if (attrs[NL80211_ATTR_IE_PROBE_RESP]) {
Johannes Berg88600202012-02-13 15:17:18 +01003363 bcn->proberesp_ies =
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003364 nla_data(attrs[NL80211_ATTR_IE_PROBE_RESP]);
Johannes Berg88600202012-02-13 15:17:18 +01003365 bcn->proberesp_ies_len =
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003366 nla_len(attrs[NL80211_ATTR_IE_PROBE_RESP]);
Jouni Malinen9946ecf2011-08-10 23:55:56 +03003367 }
3368
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003369 if (attrs[NL80211_ATTR_IE_ASSOC_RESP]) {
Johannes Berg88600202012-02-13 15:17:18 +01003370 bcn->assocresp_ies =
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003371 nla_data(attrs[NL80211_ATTR_IE_ASSOC_RESP]);
Johannes Berg88600202012-02-13 15:17:18 +01003372 bcn->assocresp_ies_len =
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003373 nla_len(attrs[NL80211_ATTR_IE_ASSOC_RESP]);
Jouni Malinen9946ecf2011-08-10 23:55:56 +03003374 }
3375
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003376 if (attrs[NL80211_ATTR_PROBE_RESP]) {
3377 bcn->probe_resp = nla_data(attrs[NL80211_ATTR_PROBE_RESP]);
3378 bcn->probe_resp_len = nla_len(attrs[NL80211_ATTR_PROBE_RESP]);
Arik Nemtsov00f740e2011-11-10 11:28:56 +02003379 }
3380
Johannes Berg88600202012-02-13 15:17:18 +01003381 return 0;
3382}
3383
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003384static bool nl80211_get_ap_channel(struct cfg80211_registered_device *rdev,
3385 struct cfg80211_ap_settings *params)
3386{
3387 struct wireless_dev *wdev;
3388 bool ret = false;
3389
Johannes Berg53873f12016-05-03 16:52:04 +03003390 list_for_each_entry(wdev, &rdev->wiphy.wdev_list, list) {
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003391 if (wdev->iftype != NL80211_IFTYPE_AP &&
3392 wdev->iftype != NL80211_IFTYPE_P2P_GO)
3393 continue;
3394
Johannes Berg683b6d32012-11-08 21:25:48 +01003395 if (!wdev->preset_chandef.chan)
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003396 continue;
3397
Johannes Berg683b6d32012-11-08 21:25:48 +01003398 params->chandef = wdev->preset_chandef;
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003399 ret = true;
3400 break;
3401 }
3402
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003403 return ret;
3404}
3405
Jouni Malinene39e5b52012-09-30 19:29:39 +03003406static bool nl80211_valid_auth_type(struct cfg80211_registered_device *rdev,
3407 enum nl80211_auth_type auth_type,
3408 enum nl80211_commands cmd)
3409{
3410 if (auth_type > NL80211_AUTHTYPE_MAX)
3411 return false;
3412
3413 switch (cmd) {
3414 case NL80211_CMD_AUTHENTICATE:
3415 if (!(rdev->wiphy.features & NL80211_FEATURE_SAE) &&
3416 auth_type == NL80211_AUTHTYPE_SAE)
3417 return false;
3418 return true;
3419 case NL80211_CMD_CONNECT:
3420 case NL80211_CMD_START_AP:
3421 /* SAE not supported yet */
3422 if (auth_type == NL80211_AUTHTYPE_SAE)
3423 return false;
3424 return true;
3425 default:
3426 return false;
3427 }
3428}
3429
Johannes Berg88600202012-02-13 15:17:18 +01003430static int nl80211_start_ap(struct sk_buff *skb, struct genl_info *info)
3431{
3432 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3433 struct net_device *dev = info->user_ptr[1];
3434 struct wireless_dev *wdev = dev->ieee80211_ptr;
3435 struct cfg80211_ap_settings params;
3436 int err;
3437
3438 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
3439 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
3440 return -EOPNOTSUPP;
3441
3442 if (!rdev->ops->start_ap)
3443 return -EOPNOTSUPP;
3444
3445 if (wdev->beacon_interval)
3446 return -EALREADY;
3447
3448 memset(&params, 0, sizeof(params));
3449
3450 /* these are required for START_AP */
3451 if (!info->attrs[NL80211_ATTR_BEACON_INTERVAL] ||
3452 !info->attrs[NL80211_ATTR_DTIM_PERIOD] ||
3453 !info->attrs[NL80211_ATTR_BEACON_HEAD])
3454 return -EINVAL;
3455
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003456 err = nl80211_parse_beacon(info->attrs, &params.beacon);
Johannes Berg88600202012-02-13 15:17:18 +01003457 if (err)
3458 return err;
3459
3460 params.beacon_interval =
3461 nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]);
3462 params.dtim_period =
3463 nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]);
3464
3465 err = cfg80211_validate_beacon_int(rdev, params.beacon_interval);
3466 if (err)
3467 return err;
3468
3469 /*
3470 * In theory, some of these attributes should be required here
3471 * but since they were not used when the command was originally
3472 * added, keep them optional for old user space programs to let
3473 * them continue to work with drivers that do not need the
3474 * additional information -- drivers must check!
3475 */
3476 if (info->attrs[NL80211_ATTR_SSID]) {
3477 params.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
3478 params.ssid_len =
3479 nla_len(info->attrs[NL80211_ATTR_SSID]);
3480 if (params.ssid_len == 0 ||
3481 params.ssid_len > IEEE80211_MAX_SSID_LEN)
3482 return -EINVAL;
3483 }
3484
3485 if (info->attrs[NL80211_ATTR_HIDDEN_SSID]) {
3486 params.hidden_ssid = nla_get_u32(
3487 info->attrs[NL80211_ATTR_HIDDEN_SSID]);
3488 if (params.hidden_ssid != NL80211_HIDDEN_SSID_NOT_IN_USE &&
3489 params.hidden_ssid != NL80211_HIDDEN_SSID_ZERO_LEN &&
3490 params.hidden_ssid != NL80211_HIDDEN_SSID_ZERO_CONTENTS)
3491 return -EINVAL;
3492 }
3493
3494 params.privacy = !!info->attrs[NL80211_ATTR_PRIVACY];
3495
3496 if (info->attrs[NL80211_ATTR_AUTH_TYPE]) {
3497 params.auth_type = nla_get_u32(
3498 info->attrs[NL80211_ATTR_AUTH_TYPE]);
Jouni Malinene39e5b52012-09-30 19:29:39 +03003499 if (!nl80211_valid_auth_type(rdev, params.auth_type,
3500 NL80211_CMD_START_AP))
Johannes Berg88600202012-02-13 15:17:18 +01003501 return -EINVAL;
3502 } else
3503 params.auth_type = NL80211_AUTHTYPE_AUTOMATIC;
3504
3505 err = nl80211_crypto_settings(rdev, info, &params.crypto,
3506 NL80211_MAX_NR_CIPHER_SUITES);
3507 if (err)
3508 return err;
3509
Vasanthakumar Thiagarajan1b658f12012-03-02 15:50:02 +05303510 if (info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]) {
3511 if (!(rdev->wiphy.features & NL80211_FEATURE_INACTIVITY_TIMER))
3512 return -EOPNOTSUPP;
3513 params.inactivity_timeout = nla_get_u16(
3514 info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]);
3515 }
3516
Johannes Berg53cabad2012-11-14 15:17:28 +01003517 if (info->attrs[NL80211_ATTR_P2P_CTWINDOW]) {
3518 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
3519 return -EINVAL;
3520 params.p2p_ctwindow =
3521 nla_get_u8(info->attrs[NL80211_ATTR_P2P_CTWINDOW]);
3522 if (params.p2p_ctwindow > 127)
3523 return -EINVAL;
3524 if (params.p2p_ctwindow != 0 &&
3525 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_CTWIN))
3526 return -EINVAL;
3527 }
3528
3529 if (info->attrs[NL80211_ATTR_P2P_OPPPS]) {
3530 u8 tmp;
3531
3532 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
3533 return -EINVAL;
3534 tmp = nla_get_u8(info->attrs[NL80211_ATTR_P2P_OPPPS]);
3535 if (tmp > 1)
3536 return -EINVAL;
3537 params.p2p_opp_ps = tmp;
3538 if (params.p2p_opp_ps != 0 &&
3539 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_OPPPS))
3540 return -EINVAL;
3541 }
3542
Johannes Bergaa430da2012-05-16 23:50:18 +02003543 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
Johannes Berg683b6d32012-11-08 21:25:48 +01003544 err = nl80211_parse_chandef(rdev, info, &params.chandef);
3545 if (err)
3546 return err;
3547 } else if (wdev->preset_chandef.chan) {
3548 params.chandef = wdev->preset_chandef;
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003549 } else if (!nl80211_get_ap_channel(rdev, &params))
Johannes Bergaa430da2012-05-16 23:50:18 +02003550 return -EINVAL;
3551
Arik Nemtsov923b3522015-07-08 15:41:44 +03003552 if (!cfg80211_reg_can_beacon_relax(&rdev->wiphy, &params.chandef,
3553 wdev->iftype))
Johannes Bergaa430da2012-05-16 23:50:18 +02003554 return -EINVAL;
3555
Eliad Peller18998c32014-09-10 14:07:34 +03003556 if (info->attrs[NL80211_ATTR_SMPS_MODE]) {
3557 params.smps_mode =
3558 nla_get_u8(info->attrs[NL80211_ATTR_SMPS_MODE]);
3559 switch (params.smps_mode) {
3560 case NL80211_SMPS_OFF:
3561 break;
3562 case NL80211_SMPS_STATIC:
3563 if (!(rdev->wiphy.features &
3564 NL80211_FEATURE_STATIC_SMPS))
3565 return -EINVAL;
3566 break;
3567 case NL80211_SMPS_DYNAMIC:
3568 if (!(rdev->wiphy.features &
3569 NL80211_FEATURE_DYNAMIC_SMPS))
3570 return -EINVAL;
3571 break;
3572 default:
3573 return -EINVAL;
3574 }
3575 } else {
3576 params.smps_mode = NL80211_SMPS_OFF;
3577 }
3578
Purushottam Kushwaha6e8ef842016-07-05 13:44:51 +05303579 params.pbss = nla_get_flag(info->attrs[NL80211_ATTR_PBSS]);
3580 if (params.pbss && !rdev->wiphy.bands[NL80211_BAND_60GHZ])
3581 return -EOPNOTSUPP;
3582
Ola Olsson4baf6be2015-10-29 07:04:58 +01003583 if (info->attrs[NL80211_ATTR_ACL_POLICY]) {
3584 params.acl = parse_acl_data(&rdev->wiphy, info);
3585 if (IS_ERR(params.acl))
3586 return PTR_ERR(params.acl);
3587 }
3588
Simon Wunderlichc56589e2013-11-21 18:19:49 +01003589 wdev_lock(wdev);
Hila Gonene35e4d22012-06-27 17:19:42 +03003590 err = rdev_start_ap(rdev, dev, &params);
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003591 if (!err) {
Johannes Berg683b6d32012-11-08 21:25:48 +01003592 wdev->preset_chandef = params.chandef;
Johannes Berg88600202012-02-13 15:17:18 +01003593 wdev->beacon_interval = params.beacon_interval;
Michal Kazior9e0e2962014-01-29 14:22:27 +01003594 wdev->chandef = params.chandef;
Antonio Quartulli06e191e2012-11-07 12:52:19 +01003595 wdev->ssid_len = params.ssid_len;
3596 memcpy(wdev->ssid, params.ssid, wdev->ssid_len);
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003597 }
Simon Wunderlichc56589e2013-11-21 18:19:49 +01003598 wdev_unlock(wdev);
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +05303599
3600 kfree(params.acl);
3601
Johannes Berg56d18932011-05-09 18:41:15 +02003602 return err;
Johannes Berged1b6cc2007-12-19 02:03:32 +01003603}
3604
Johannes Berg88600202012-02-13 15:17:18 +01003605static int nl80211_set_beacon(struct sk_buff *skb, struct genl_info *info)
3606{
3607 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3608 struct net_device *dev = info->user_ptr[1];
3609 struct wireless_dev *wdev = dev->ieee80211_ptr;
3610 struct cfg80211_beacon_data params;
3611 int err;
3612
3613 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
3614 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
3615 return -EOPNOTSUPP;
3616
3617 if (!rdev->ops->change_beacon)
3618 return -EOPNOTSUPP;
3619
3620 if (!wdev->beacon_interval)
3621 return -EINVAL;
3622
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003623 err = nl80211_parse_beacon(info->attrs, &params);
Johannes Berg88600202012-02-13 15:17:18 +01003624 if (err)
3625 return err;
3626
Simon Wunderlichc56589e2013-11-21 18:19:49 +01003627 wdev_lock(wdev);
3628 err = rdev_change_beacon(rdev, dev, &params);
3629 wdev_unlock(wdev);
3630
3631 return err;
Johannes Berg88600202012-02-13 15:17:18 +01003632}
3633
3634static int nl80211_stop_ap(struct sk_buff *skb, struct genl_info *info)
Johannes Berged1b6cc2007-12-19 02:03:32 +01003635{
Johannes Berg4c476992010-10-04 21:36:35 +02003636 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3637 struct net_device *dev = info->user_ptr[1];
Johannes Berged1b6cc2007-12-19 02:03:32 +01003638
Ilan Peer7c8d5e02014-02-25 15:33:38 +02003639 return cfg80211_stop_ap(rdev, dev, false);
Johannes Berged1b6cc2007-12-19 02:03:32 +01003640}
3641
Johannes Berg5727ef12007-12-19 02:03:34 +01003642static const struct nla_policy sta_flags_policy[NL80211_STA_FLAG_MAX + 1] = {
3643 [NL80211_STA_FLAG_AUTHORIZED] = { .type = NLA_FLAG },
3644 [NL80211_STA_FLAG_SHORT_PREAMBLE] = { .type = NLA_FLAG },
3645 [NL80211_STA_FLAG_WME] = { .type = NLA_FLAG },
Jouni Malinen0e467242009-05-11 21:57:55 +03003646 [NL80211_STA_FLAG_MFP] = { .type = NLA_FLAG },
Javier Cardonab39c48f2011-04-07 15:08:30 -07003647 [NL80211_STA_FLAG_AUTHENTICATED] = { .type = NLA_FLAG },
Johannes Bergd83023d2011-12-14 09:29:15 +01003648 [NL80211_STA_FLAG_TDLS_PEER] = { .type = NLA_FLAG },
Johannes Berg5727ef12007-12-19 02:03:34 +01003649};
3650
Johannes Bergeccb8e82009-05-11 21:57:56 +03003651static int parse_station_flags(struct genl_info *info,
Johannes Bergbdd3ae32012-01-02 13:30:03 +01003652 enum nl80211_iftype iftype,
Johannes Bergeccb8e82009-05-11 21:57:56 +03003653 struct station_parameters *params)
Johannes Berg5727ef12007-12-19 02:03:34 +01003654{
3655 struct nlattr *flags[NL80211_STA_FLAG_MAX + 1];
Johannes Bergeccb8e82009-05-11 21:57:56 +03003656 struct nlattr *nla;
Johannes Berg5727ef12007-12-19 02:03:34 +01003657 int flag;
3658
Johannes Bergeccb8e82009-05-11 21:57:56 +03003659 /*
3660 * Try parsing the new attribute first so userspace
3661 * can specify both for older kernels.
3662 */
3663 nla = info->attrs[NL80211_ATTR_STA_FLAGS2];
3664 if (nla) {
3665 struct nl80211_sta_flag_update *sta_flags;
Johannes Berg5727ef12007-12-19 02:03:34 +01003666
Johannes Bergeccb8e82009-05-11 21:57:56 +03003667 sta_flags = nla_data(nla);
3668 params->sta_flags_mask = sta_flags->mask;
3669 params->sta_flags_set = sta_flags->set;
Johannes Berg77ee7c82013-02-15 00:48:33 +01003670 params->sta_flags_set &= params->sta_flags_mask;
Johannes Bergeccb8e82009-05-11 21:57:56 +03003671 if ((params->sta_flags_mask |
3672 params->sta_flags_set) & BIT(__NL80211_STA_FLAG_INVALID))
3673 return -EINVAL;
3674 return 0;
3675 }
3676
3677 /* if present, parse the old attribute */
3678
3679 nla = info->attrs[NL80211_ATTR_STA_FLAGS];
Johannes Berg5727ef12007-12-19 02:03:34 +01003680 if (!nla)
3681 return 0;
3682
3683 if (nla_parse_nested(flags, NL80211_STA_FLAG_MAX,
3684 nla, sta_flags_policy))
3685 return -EINVAL;
3686
Johannes Bergbdd3ae32012-01-02 13:30:03 +01003687 /*
3688 * Only allow certain flags for interface types so that
3689 * other attributes are silently ignored. Remember that
3690 * this is backward compatibility code with old userspace
3691 * and shouldn't be hit in other cases anyway.
3692 */
3693 switch (iftype) {
3694 case NL80211_IFTYPE_AP:
3695 case NL80211_IFTYPE_AP_VLAN:
3696 case NL80211_IFTYPE_P2P_GO:
3697 params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) |
3698 BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) |
3699 BIT(NL80211_STA_FLAG_WME) |
3700 BIT(NL80211_STA_FLAG_MFP);
3701 break;
3702 case NL80211_IFTYPE_P2P_CLIENT:
3703 case NL80211_IFTYPE_STATION:
3704 params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) |
3705 BIT(NL80211_STA_FLAG_TDLS_PEER);
3706 break;
3707 case NL80211_IFTYPE_MESH_POINT:
3708 params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHENTICATED) |
3709 BIT(NL80211_STA_FLAG_MFP) |
3710 BIT(NL80211_STA_FLAG_AUTHORIZED);
3711 default:
3712 return -EINVAL;
3713 }
Johannes Berg5727ef12007-12-19 02:03:34 +01003714
Johannes Berg3383b5a2012-05-10 20:14:43 +02003715 for (flag = 1; flag <= NL80211_STA_FLAG_MAX; flag++) {
3716 if (flags[flag]) {
Johannes Bergeccb8e82009-05-11 21:57:56 +03003717 params->sta_flags_set |= (1<<flag);
Johannes Berg5727ef12007-12-19 02:03:34 +01003718
Johannes Berg3383b5a2012-05-10 20:14:43 +02003719 /* no longer support new API additions in old API */
3720 if (flag > NL80211_STA_FLAG_MAX_OLD_API)
3721 return -EINVAL;
3722 }
3723 }
3724
Johannes Berg5727ef12007-12-19 02:03:34 +01003725 return 0;
3726}
3727
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003728static bool nl80211_put_sta_rate(struct sk_buff *msg, struct rate_info *info,
3729 int attr)
3730{
3731 struct nlattr *rate;
Vladimir Kondratiev8eb41c82012-07-05 14:25:49 +03003732 u32 bitrate;
3733 u16 bitrate_compat;
Johannes Bergb51f3be2015-01-15 16:14:02 +01003734 enum nl80211_attrs rate_flg;
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003735
3736 rate = nla_nest_start(msg, attr);
3737 if (!rate)
Johannes Bergdb9c64c2012-11-09 14:56:41 +01003738 return false;
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003739
3740 /* cfg80211_calculate_bitrate will return 0 for mcs >= 32 */
3741 bitrate = cfg80211_calculate_bitrate(info);
Vladimir Kondratiev8eb41c82012-07-05 14:25:49 +03003742 /* report 16-bit bitrate only if we can */
3743 bitrate_compat = bitrate < (1UL << 16) ? bitrate : 0;
Johannes Bergdb9c64c2012-11-09 14:56:41 +01003744 if (bitrate > 0 &&
3745 nla_put_u32(msg, NL80211_RATE_INFO_BITRATE32, bitrate))
3746 return false;
3747 if (bitrate_compat > 0 &&
3748 nla_put_u16(msg, NL80211_RATE_INFO_BITRATE, bitrate_compat))
3749 return false;
3750
Johannes Bergb51f3be2015-01-15 16:14:02 +01003751 switch (info->bw) {
3752 case RATE_INFO_BW_5:
3753 rate_flg = NL80211_RATE_INFO_5_MHZ_WIDTH;
3754 break;
3755 case RATE_INFO_BW_10:
3756 rate_flg = NL80211_RATE_INFO_10_MHZ_WIDTH;
3757 break;
3758 default:
3759 WARN_ON(1);
3760 /* fall through */
3761 case RATE_INFO_BW_20:
3762 rate_flg = 0;
3763 break;
3764 case RATE_INFO_BW_40:
3765 rate_flg = NL80211_RATE_INFO_40_MHZ_WIDTH;
3766 break;
3767 case RATE_INFO_BW_80:
3768 rate_flg = NL80211_RATE_INFO_80_MHZ_WIDTH;
3769 break;
3770 case RATE_INFO_BW_160:
3771 rate_flg = NL80211_RATE_INFO_160_MHZ_WIDTH;
3772 break;
3773 }
3774
3775 if (rate_flg && nla_put_flag(msg, rate_flg))
3776 return false;
3777
Johannes Bergdb9c64c2012-11-09 14:56:41 +01003778 if (info->flags & RATE_INFO_FLAGS_MCS) {
3779 if (nla_put_u8(msg, NL80211_RATE_INFO_MCS, info->mcs))
3780 return false;
Johannes Bergdb9c64c2012-11-09 14:56:41 +01003781 if (info->flags & RATE_INFO_FLAGS_SHORT_GI &&
3782 nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI))
3783 return false;
3784 } else if (info->flags & RATE_INFO_FLAGS_VHT_MCS) {
3785 if (nla_put_u8(msg, NL80211_RATE_INFO_VHT_MCS, info->mcs))
3786 return false;
3787 if (nla_put_u8(msg, NL80211_RATE_INFO_VHT_NSS, info->nss))
3788 return false;
Johannes Bergdb9c64c2012-11-09 14:56:41 +01003789 if (info->flags & RATE_INFO_FLAGS_SHORT_GI &&
3790 nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI))
3791 return false;
3792 }
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003793
3794 nla_nest_end(msg, rate);
3795 return true;
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003796}
3797
Felix Fietkau119363c2013-04-22 16:29:30 +02003798static bool nl80211_put_signal(struct sk_buff *msg, u8 mask, s8 *signal,
3799 int id)
3800{
3801 void *attr;
3802 int i = 0;
3803
3804 if (!mask)
3805 return true;
3806
3807 attr = nla_nest_start(msg, id);
3808 if (!attr)
3809 return false;
3810
3811 for (i = 0; i < IEEE80211_MAX_CHAINS; i++) {
3812 if (!(mask & BIT(i)))
3813 continue;
3814
3815 if (nla_put_u8(msg, i, signal[i]))
3816 return false;
3817 }
3818
3819 nla_nest_end(msg, attr);
3820
3821 return true;
3822}
3823
Johannes Bergcf5ead82014-11-14 17:14:00 +01003824static int nl80211_send_station(struct sk_buff *msg, u32 cmd, u32 portid,
3825 u32 seq, int flags,
John W. Linville66266b32012-03-15 13:25:41 -04003826 struct cfg80211_registered_device *rdev,
3827 struct net_device *dev,
Johannes Berg98b62182009-12-23 13:15:44 +01003828 const u8 *mac_addr, struct station_info *sinfo)
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003829{
3830 void *hdr;
Paul Stewartf4263c92011-03-31 09:25:41 -07003831 struct nlattr *sinfoattr, *bss_param;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003832
Johannes Bergcf5ead82014-11-14 17:14:00 +01003833 hdr = nl80211hdr_put(msg, portid, seq, flags, cmd);
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003834 if (!hdr)
3835 return -1;
3836
David S. Miller9360ffd2012-03-29 04:41:26 -04003837 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
3838 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) ||
3839 nla_put_u32(msg, NL80211_ATTR_GENERATION, sinfo->generation))
3840 goto nla_put_failure;
Johannes Bergf5ea9122009-08-07 16:17:38 +02003841
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003842 sinfoattr = nla_nest_start(msg, NL80211_ATTR_STA_INFO);
3843 if (!sinfoattr)
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003844 goto nla_put_failure;
Johannes Berg319090b2014-11-17 14:08:11 +01003845
3846#define PUT_SINFO(attr, memb, type) do { \
Johannes Bergd686b922016-04-26 09:54:11 +02003847 BUILD_BUG_ON(sizeof(type) == sizeof(u64)); \
Mohammed Shafi Shajakhan739960f2016-04-07 19:59:34 +05303848 if (sinfo->filled & (1ULL << NL80211_STA_INFO_ ## attr) && \
Johannes Berg319090b2014-11-17 14:08:11 +01003849 nla_put_ ## type(msg, NL80211_STA_INFO_ ## attr, \
3850 sinfo->memb)) \
3851 goto nla_put_failure; \
3852 } while (0)
Johannes Bergd686b922016-04-26 09:54:11 +02003853#define PUT_SINFO_U64(attr, memb) do { \
3854 if (sinfo->filled & (1ULL << NL80211_STA_INFO_ ## attr) && \
3855 nla_put_u64_64bit(msg, NL80211_STA_INFO_ ## attr, \
3856 sinfo->memb, NL80211_STA_INFO_PAD)) \
3857 goto nla_put_failure; \
3858 } while (0)
Johannes Berg319090b2014-11-17 14:08:11 +01003859
3860 PUT_SINFO(CONNECTED_TIME, connected_time, u32);
3861 PUT_SINFO(INACTIVE_TIME, inactive_time, u32);
3862
3863 if (sinfo->filled & (BIT(NL80211_STA_INFO_RX_BYTES) |
3864 BIT(NL80211_STA_INFO_RX_BYTES64)) &&
David S. Miller9360ffd2012-03-29 04:41:26 -04003865 nla_put_u32(msg, NL80211_STA_INFO_RX_BYTES,
Vladimir Kondratiev42745e02013-02-04 13:53:11 +02003866 (u32)sinfo->rx_bytes))
3867 goto nla_put_failure;
Johannes Berg319090b2014-11-17 14:08:11 +01003868
3869 if (sinfo->filled & (BIT(NL80211_STA_INFO_TX_BYTES) |
3870 BIT(NL80211_STA_INFO_TX_BYTES64)) &&
Vladimir Kondratiev42745e02013-02-04 13:53:11 +02003871 nla_put_u32(msg, NL80211_STA_INFO_TX_BYTES,
3872 (u32)sinfo->tx_bytes))
3873 goto nla_put_failure;
Johannes Berg319090b2014-11-17 14:08:11 +01003874
Johannes Bergd686b922016-04-26 09:54:11 +02003875 PUT_SINFO_U64(RX_BYTES64, rx_bytes);
3876 PUT_SINFO_U64(TX_BYTES64, tx_bytes);
Johannes Berg319090b2014-11-17 14:08:11 +01003877 PUT_SINFO(LLID, llid, u16);
3878 PUT_SINFO(PLID, plid, u16);
3879 PUT_SINFO(PLINK_STATE, plink_state, u8);
Johannes Bergd686b922016-04-26 09:54:11 +02003880 PUT_SINFO_U64(RX_DURATION, rx_duration);
Johannes Berg319090b2014-11-17 14:08:11 +01003881
John W. Linville66266b32012-03-15 13:25:41 -04003882 switch (rdev->wiphy.signal_type) {
3883 case CFG80211_SIGNAL_TYPE_MBM:
Johannes Berg319090b2014-11-17 14:08:11 +01003884 PUT_SINFO(SIGNAL, signal, u8);
3885 PUT_SINFO(SIGNAL_AVG, signal_avg, u8);
John W. Linville66266b32012-03-15 13:25:41 -04003886 break;
3887 default:
3888 break;
3889 }
Johannes Berg319090b2014-11-17 14:08:11 +01003890 if (sinfo->filled & BIT(NL80211_STA_INFO_CHAIN_SIGNAL)) {
Felix Fietkau119363c2013-04-22 16:29:30 +02003891 if (!nl80211_put_signal(msg, sinfo->chains,
3892 sinfo->chain_signal,
3893 NL80211_STA_INFO_CHAIN_SIGNAL))
3894 goto nla_put_failure;
3895 }
Johannes Berg319090b2014-11-17 14:08:11 +01003896 if (sinfo->filled & BIT(NL80211_STA_INFO_CHAIN_SIGNAL_AVG)) {
Felix Fietkau119363c2013-04-22 16:29:30 +02003897 if (!nl80211_put_signal(msg, sinfo->chains,
3898 sinfo->chain_signal_avg,
3899 NL80211_STA_INFO_CHAIN_SIGNAL_AVG))
3900 goto nla_put_failure;
3901 }
Johannes Berg319090b2014-11-17 14:08:11 +01003902 if (sinfo->filled & BIT(NL80211_STA_INFO_TX_BITRATE)) {
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003903 if (!nl80211_put_sta_rate(msg, &sinfo->txrate,
3904 NL80211_STA_INFO_TX_BITRATE))
Henning Rogge420e7fa2008-12-11 22:04:19 +01003905 goto nla_put_failure;
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003906 }
Johannes Berg319090b2014-11-17 14:08:11 +01003907 if (sinfo->filled & BIT(NL80211_STA_INFO_RX_BITRATE)) {
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003908 if (!nl80211_put_sta_rate(msg, &sinfo->rxrate,
3909 NL80211_STA_INFO_RX_BITRATE))
3910 goto nla_put_failure;
Henning Rogge420e7fa2008-12-11 22:04:19 +01003911 }
Johannes Berg319090b2014-11-17 14:08:11 +01003912
3913 PUT_SINFO(RX_PACKETS, rx_packets, u32);
3914 PUT_SINFO(TX_PACKETS, tx_packets, u32);
3915 PUT_SINFO(TX_RETRIES, tx_retries, u32);
3916 PUT_SINFO(TX_FAILED, tx_failed, u32);
3917 PUT_SINFO(EXPECTED_THROUGHPUT, expected_throughput, u32);
3918 PUT_SINFO(BEACON_LOSS, beacon_loss_count, u32);
3919 PUT_SINFO(LOCAL_PM, local_pm, u32);
3920 PUT_SINFO(PEER_PM, peer_pm, u32);
3921 PUT_SINFO(NONPEER_PM, nonpeer_pm, u32);
3922
3923 if (sinfo->filled & BIT(NL80211_STA_INFO_BSS_PARAM)) {
Paul Stewartf4263c92011-03-31 09:25:41 -07003924 bss_param = nla_nest_start(msg, NL80211_STA_INFO_BSS_PARAM);
3925 if (!bss_param)
3926 goto nla_put_failure;
3927
David S. Miller9360ffd2012-03-29 04:41:26 -04003928 if (((sinfo->bss_param.flags & BSS_PARAM_FLAGS_CTS_PROT) &&
3929 nla_put_flag(msg, NL80211_STA_BSS_PARAM_CTS_PROT)) ||
3930 ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_PREAMBLE) &&
3931 nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_PREAMBLE)) ||
3932 ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_SLOT_TIME) &&
3933 nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_SLOT_TIME)) ||
3934 nla_put_u8(msg, NL80211_STA_BSS_PARAM_DTIM_PERIOD,
3935 sinfo->bss_param.dtim_period) ||
3936 nla_put_u16(msg, NL80211_STA_BSS_PARAM_BEACON_INTERVAL,
3937 sinfo->bss_param.beacon_interval))
3938 goto nla_put_failure;
Paul Stewartf4263c92011-03-31 09:25:41 -07003939
3940 nla_nest_end(msg, bss_param);
3941 }
Johannes Berg319090b2014-11-17 14:08:11 +01003942 if ((sinfo->filled & BIT(NL80211_STA_INFO_STA_FLAGS)) &&
David S. Miller9360ffd2012-03-29 04:41:26 -04003943 nla_put(msg, NL80211_STA_INFO_STA_FLAGS,
3944 sizeof(struct nl80211_sta_flag_update),
3945 &sinfo->sta_flags))
3946 goto nla_put_failure;
Johannes Berg319090b2014-11-17 14:08:11 +01003947
Johannes Bergd686b922016-04-26 09:54:11 +02003948 PUT_SINFO_U64(T_OFFSET, t_offset);
3949 PUT_SINFO_U64(RX_DROP_MISC, rx_dropped_misc);
3950 PUT_SINFO_U64(BEACON_RX, rx_beacon);
Johannes Berga76b1942014-11-17 14:12:22 +01003951 PUT_SINFO(BEACON_SIGNAL_AVG, rx_beacon_signal_avg, u8);
Johannes Berg319090b2014-11-17 14:08:11 +01003952
3953#undef PUT_SINFO
Johannes Bergd686b922016-04-26 09:54:11 +02003954#undef PUT_SINFO_U64
Johannes Berg6de39802014-12-19 12:34:00 +01003955
3956 if (sinfo->filled & BIT(NL80211_STA_INFO_TID_STATS)) {
3957 struct nlattr *tidsattr;
3958 int tid;
3959
3960 tidsattr = nla_nest_start(msg, NL80211_STA_INFO_TID_STATS);
3961 if (!tidsattr)
3962 goto nla_put_failure;
3963
3964 for (tid = 0; tid < IEEE80211_NUM_TIDS + 1; tid++) {
3965 struct cfg80211_tid_stats *tidstats;
3966 struct nlattr *tidattr;
3967
3968 tidstats = &sinfo->pertid[tid];
3969
3970 if (!tidstats->filled)
3971 continue;
3972
3973 tidattr = nla_nest_start(msg, tid + 1);
3974 if (!tidattr)
3975 goto nla_put_failure;
3976
Johannes Bergd686b922016-04-26 09:54:11 +02003977#define PUT_TIDVAL_U64(attr, memb) do { \
Johannes Berg6de39802014-12-19 12:34:00 +01003978 if (tidstats->filled & BIT(NL80211_TID_STATS_ ## attr) && \
Johannes Bergd686b922016-04-26 09:54:11 +02003979 nla_put_u64_64bit(msg, NL80211_TID_STATS_ ## attr, \
3980 tidstats->memb, NL80211_TID_STATS_PAD)) \
Johannes Berg6de39802014-12-19 12:34:00 +01003981 goto nla_put_failure; \
3982 } while (0)
3983
Johannes Bergd686b922016-04-26 09:54:11 +02003984 PUT_TIDVAL_U64(RX_MSDU, rx_msdu);
3985 PUT_TIDVAL_U64(TX_MSDU, tx_msdu);
3986 PUT_TIDVAL_U64(TX_MSDU_RETRIES, tx_msdu_retries);
3987 PUT_TIDVAL_U64(TX_MSDU_FAILED, tx_msdu_failed);
Johannes Berg6de39802014-12-19 12:34:00 +01003988
Johannes Bergd686b922016-04-26 09:54:11 +02003989#undef PUT_TIDVAL_U64
Johannes Berg6de39802014-12-19 12:34:00 +01003990 nla_nest_end(msg, tidattr);
3991 }
3992
3993 nla_nest_end(msg, tidsattr);
3994 }
3995
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003996 nla_nest_end(msg, sinfoattr);
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003997
Johannes Berg319090b2014-11-17 14:08:11 +01003998 if (sinfo->assoc_req_ies_len &&
David S. Miller9360ffd2012-03-29 04:41:26 -04003999 nla_put(msg, NL80211_ATTR_IE, sinfo->assoc_req_ies_len,
4000 sinfo->assoc_req_ies))
4001 goto nla_put_failure;
Jouni Malinen50d3dfb2011-08-08 12:11:52 +03004002
Johannes Berg053c0952015-01-16 22:09:00 +01004003 genlmsg_end(msg, hdr);
4004 return 0;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01004005
4006 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07004007 genlmsg_cancel(msg, hdr);
4008 return -EMSGSIZE;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01004009}
4010
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004011static int nl80211_dump_station(struct sk_buff *skb,
Johannes Bergbba95fe2008-07-29 13:22:51 +02004012 struct netlink_callback *cb)
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004013{
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004014 struct station_info sinfo;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08004015 struct cfg80211_registered_device *rdev;
Johannes Berg97990a02013-04-19 01:02:55 +02004016 struct wireless_dev *wdev;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004017 u8 mac_addr[ETH_ALEN];
Johannes Berg97990a02013-04-19 01:02:55 +02004018 int sta_idx = cb->args[2];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004019 int err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004020
Zhao, Gang1b8ec872014-04-21 12:53:02 +08004021 err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev);
Johannes Berg67748892010-10-04 21:14:06 +02004022 if (err)
4023 return err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004024
Johannes Berg97990a02013-04-19 01:02:55 +02004025 if (!wdev->netdev) {
4026 err = -EINVAL;
4027 goto out_err;
4028 }
4029
Zhao, Gang1b8ec872014-04-21 12:53:02 +08004030 if (!rdev->ops->dump_station) {
Jouni Malineneec60b02009-03-20 21:21:19 +02004031 err = -EOPNOTSUPP;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004032 goto out_err;
4033 }
4034
Johannes Bergbba95fe2008-07-29 13:22:51 +02004035 while (1) {
Jouni Malinenf612ced2011-08-11 11:46:22 +03004036 memset(&sinfo, 0, sizeof(sinfo));
Zhao, Gang1b8ec872014-04-21 12:53:02 +08004037 err = rdev_dump_station(rdev, wdev->netdev, sta_idx,
Hila Gonene35e4d22012-06-27 17:19:42 +03004038 mac_addr, &sinfo);
Johannes Bergbba95fe2008-07-29 13:22:51 +02004039 if (err == -ENOENT)
4040 break;
4041 if (err)
Johannes Berg3b858752009-03-12 09:55:09 +01004042 goto out_err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004043
Johannes Bergcf5ead82014-11-14 17:14:00 +01004044 if (nl80211_send_station(skb, NL80211_CMD_NEW_STATION,
Eric W. Biederman15e47302012-09-07 20:12:54 +00004045 NETLINK_CB(cb->skb).portid,
Johannes Bergbba95fe2008-07-29 13:22:51 +02004046 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08004047 rdev, wdev->netdev, mac_addr,
Johannes Bergbba95fe2008-07-29 13:22:51 +02004048 &sinfo) < 0)
4049 goto out;
4050
4051 sta_idx++;
4052 }
4053
Johannes Bergbba95fe2008-07-29 13:22:51 +02004054 out:
Johannes Berg97990a02013-04-19 01:02:55 +02004055 cb->args[2] = sta_idx;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004056 err = skb->len;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004057 out_err:
Zhao, Gang1b8ec872014-04-21 12:53:02 +08004058 nl80211_finish_wdev_dump(rdev);
Johannes Bergbba95fe2008-07-29 13:22:51 +02004059
4060 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004061}
Johannes Bergfd5b74d2007-12-19 02:03:36 +01004062
Johannes Berg5727ef12007-12-19 02:03:34 +01004063static int nl80211_get_station(struct sk_buff *skb, struct genl_info *info)
4064{
Johannes Berg4c476992010-10-04 21:36:35 +02004065 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4066 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004067 struct station_info sinfo;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01004068 struct sk_buff *msg;
4069 u8 *mac_addr = NULL;
Johannes Berg4c476992010-10-04 21:36:35 +02004070 int err;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01004071
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004072 memset(&sinfo, 0, sizeof(sinfo));
Johannes Bergfd5b74d2007-12-19 02:03:36 +01004073
4074 if (!info->attrs[NL80211_ATTR_MAC])
4075 return -EINVAL;
4076
4077 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
4078
Johannes Berg4c476992010-10-04 21:36:35 +02004079 if (!rdev->ops->get_station)
4080 return -EOPNOTSUPP;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01004081
Hila Gonene35e4d22012-06-27 17:19:42 +03004082 err = rdev_get_station(rdev, dev, mac_addr, &sinfo);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004083 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02004084 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004085
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07004086 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Bergfd5b74d2007-12-19 02:03:36 +01004087 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02004088 return -ENOMEM;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01004089
Johannes Bergcf5ead82014-11-14 17:14:00 +01004090 if (nl80211_send_station(msg, NL80211_CMD_NEW_STATION,
4091 info->snd_portid, info->snd_seq, 0,
John W. Linville66266b32012-03-15 13:25:41 -04004092 rdev, dev, mac_addr, &sinfo) < 0) {
Johannes Berg4c476992010-10-04 21:36:35 +02004093 nlmsg_free(msg);
4094 return -ENOBUFS;
4095 }
Johannes Bergfd5b74d2007-12-19 02:03:36 +01004096
Johannes Berg4c476992010-10-04 21:36:35 +02004097 return genlmsg_reply(msg, info);
Johannes Berg5727ef12007-12-19 02:03:34 +01004098}
4099
Johannes Berg77ee7c82013-02-15 00:48:33 +01004100int cfg80211_check_station_change(struct wiphy *wiphy,
4101 struct station_parameters *params,
4102 enum cfg80211_station_type statype)
4103{
Ayala Bekere4208422015-10-23 11:20:06 +03004104 if (params->listen_interval != -1 &&
4105 statype != CFG80211_STA_AP_CLIENT_UNASSOC)
Johannes Berg77ee7c82013-02-15 00:48:33 +01004106 return -EINVAL;
Ayala Bekere4208422015-10-23 11:20:06 +03004107
Ayala Beker17b94242016-03-17 15:41:38 +02004108 if (params->support_p2p_ps != -1 &&
4109 statype != CFG80211_STA_AP_CLIENT_UNASSOC)
4110 return -EINVAL;
4111
Arik Nemtsovc72e1142014-07-17 17:14:29 +03004112 if (params->aid &&
Ayala Bekere4208422015-10-23 11:20:06 +03004113 !(params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) &&
4114 statype != CFG80211_STA_AP_CLIENT_UNASSOC)
Johannes Berg77ee7c82013-02-15 00:48:33 +01004115 return -EINVAL;
4116
4117 /* When you run into this, adjust the code below for the new flag */
4118 BUILD_BUG_ON(NL80211_STA_FLAG_MAX != 7);
4119
4120 switch (statype) {
Thomas Pederseneef941e2013-03-04 13:06:11 -08004121 case CFG80211_STA_MESH_PEER_KERNEL:
4122 case CFG80211_STA_MESH_PEER_USER:
Johannes Berg77ee7c82013-02-15 00:48:33 +01004123 /*
4124 * No ignoring the TDLS flag here -- the userspace mesh
4125 * code doesn't have the bug of including TDLS in the
4126 * mask everywhere.
4127 */
4128 if (params->sta_flags_mask &
4129 ~(BIT(NL80211_STA_FLAG_AUTHENTICATED) |
4130 BIT(NL80211_STA_FLAG_MFP) |
4131 BIT(NL80211_STA_FLAG_AUTHORIZED)))
4132 return -EINVAL;
4133 break;
4134 case CFG80211_STA_TDLS_PEER_SETUP:
4135 case CFG80211_STA_TDLS_PEER_ACTIVE:
4136 if (!(params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)))
4137 return -EINVAL;
4138 /* ignore since it can't change */
4139 params->sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER);
4140 break;
4141 default:
4142 /* disallow mesh-specific things */
4143 if (params->plink_action != NL80211_PLINK_ACTION_NO_ACTION)
4144 return -EINVAL;
4145 if (params->local_pm)
4146 return -EINVAL;
4147 if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE)
4148 return -EINVAL;
4149 }
4150
4151 if (statype != CFG80211_STA_TDLS_PEER_SETUP &&
4152 statype != CFG80211_STA_TDLS_PEER_ACTIVE) {
4153 /* TDLS can't be set, ... */
4154 if (params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))
4155 return -EINVAL;
4156 /*
4157 * ... but don't bother the driver with it. This works around
4158 * a hostapd/wpa_supplicant issue -- it always includes the
4159 * TLDS_PEER flag in the mask even for AP mode.
4160 */
4161 params->sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER);
4162 }
4163
Ayala Beker47edb112015-09-21 15:49:53 +03004164 if (statype != CFG80211_STA_TDLS_PEER_SETUP &&
4165 statype != CFG80211_STA_AP_CLIENT_UNASSOC) {
Johannes Berg77ee7c82013-02-15 00:48:33 +01004166 /* reject other things that can't change */
4167 if (params->sta_modify_mask & STATION_PARAM_APPLY_UAPSD)
4168 return -EINVAL;
4169 if (params->sta_modify_mask & STATION_PARAM_APPLY_CAPABILITY)
4170 return -EINVAL;
4171 if (params->supported_rates)
4172 return -EINVAL;
4173 if (params->ext_capab || params->ht_capa || params->vht_capa)
4174 return -EINVAL;
4175 }
4176
Ayala Beker47edb112015-09-21 15:49:53 +03004177 if (statype != CFG80211_STA_AP_CLIENT &&
4178 statype != CFG80211_STA_AP_CLIENT_UNASSOC) {
Johannes Berg77ee7c82013-02-15 00:48:33 +01004179 if (params->vlan)
4180 return -EINVAL;
4181 }
4182
4183 switch (statype) {
4184 case CFG80211_STA_AP_MLME_CLIENT:
4185 /* Use this only for authorizing/unauthorizing a station */
4186 if (!(params->sta_flags_mask & BIT(NL80211_STA_FLAG_AUTHORIZED)))
4187 return -EOPNOTSUPP;
4188 break;
4189 case CFG80211_STA_AP_CLIENT:
Ayala Beker47edb112015-09-21 15:49:53 +03004190 case CFG80211_STA_AP_CLIENT_UNASSOC:
Johannes Berg77ee7c82013-02-15 00:48:33 +01004191 /* accept only the listed bits */
4192 if (params->sta_flags_mask &
4193 ~(BIT(NL80211_STA_FLAG_AUTHORIZED) |
4194 BIT(NL80211_STA_FLAG_AUTHENTICATED) |
4195 BIT(NL80211_STA_FLAG_ASSOCIATED) |
4196 BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) |
4197 BIT(NL80211_STA_FLAG_WME) |
4198 BIT(NL80211_STA_FLAG_MFP)))
4199 return -EINVAL;
4200
4201 /* but authenticated/associated only if driver handles it */
4202 if (!(wiphy->features & NL80211_FEATURE_FULL_AP_CLIENT_STATE) &&
4203 params->sta_flags_mask &
4204 (BIT(NL80211_STA_FLAG_AUTHENTICATED) |
4205 BIT(NL80211_STA_FLAG_ASSOCIATED)))
4206 return -EINVAL;
4207 break;
4208 case CFG80211_STA_IBSS:
4209 case CFG80211_STA_AP_STA:
4210 /* reject any changes other than AUTHORIZED */
4211 if (params->sta_flags_mask & ~BIT(NL80211_STA_FLAG_AUTHORIZED))
4212 return -EINVAL;
4213 break;
4214 case CFG80211_STA_TDLS_PEER_SETUP:
4215 /* reject any changes other than AUTHORIZED or WME */
4216 if (params->sta_flags_mask & ~(BIT(NL80211_STA_FLAG_AUTHORIZED) |
4217 BIT(NL80211_STA_FLAG_WME)))
4218 return -EINVAL;
4219 /* force (at least) rates when authorizing */
4220 if (params->sta_flags_set & BIT(NL80211_STA_FLAG_AUTHORIZED) &&
4221 !params->supported_rates)
4222 return -EINVAL;
4223 break;
4224 case CFG80211_STA_TDLS_PEER_ACTIVE:
4225 /* reject any changes */
4226 return -EINVAL;
Thomas Pederseneef941e2013-03-04 13:06:11 -08004227 case CFG80211_STA_MESH_PEER_KERNEL:
Johannes Berg77ee7c82013-02-15 00:48:33 +01004228 if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE)
4229 return -EINVAL;
4230 break;
Thomas Pederseneef941e2013-03-04 13:06:11 -08004231 case CFG80211_STA_MESH_PEER_USER:
Chun-Yeow Yeoh42925042015-04-18 01:30:02 +08004232 if (params->plink_action != NL80211_PLINK_ACTION_NO_ACTION &&
4233 params->plink_action != NL80211_PLINK_ACTION_BLOCK)
Johannes Berg77ee7c82013-02-15 00:48:33 +01004234 return -EINVAL;
4235 break;
4236 }
4237
4238 return 0;
4239}
4240EXPORT_SYMBOL(cfg80211_check_station_change);
4241
Johannes Berg5727ef12007-12-19 02:03:34 +01004242/*
Felix Fietkauc258d2d2009-11-11 17:23:31 +01004243 * Get vlan interface making sure it is running and on the right wiphy.
Johannes Berg5727ef12007-12-19 02:03:34 +01004244 */
Johannes Berg80b99892011-11-18 16:23:01 +01004245static struct net_device *get_vlan(struct genl_info *info,
4246 struct cfg80211_registered_device *rdev)
Johannes Berg5727ef12007-12-19 02:03:34 +01004247{
Johannes Berg463d0182009-07-14 00:33:35 +02004248 struct nlattr *vlanattr = info->attrs[NL80211_ATTR_STA_VLAN];
Johannes Berg80b99892011-11-18 16:23:01 +01004249 struct net_device *v;
4250 int ret;
Johannes Berg5727ef12007-12-19 02:03:34 +01004251
Johannes Berg80b99892011-11-18 16:23:01 +01004252 if (!vlanattr)
4253 return NULL;
4254
4255 v = dev_get_by_index(genl_info_net(info), nla_get_u32(vlanattr));
4256 if (!v)
4257 return ERR_PTR(-ENODEV);
4258
4259 if (!v->ieee80211_ptr || v->ieee80211_ptr->wiphy != &rdev->wiphy) {
4260 ret = -EINVAL;
4261 goto error;
Johannes Berg5727ef12007-12-19 02:03:34 +01004262 }
Johannes Berg80b99892011-11-18 16:23:01 +01004263
Johannes Berg77ee7c82013-02-15 00:48:33 +01004264 if (v->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN &&
4265 v->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
4266 v->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) {
4267 ret = -EINVAL;
4268 goto error;
4269 }
4270
Johannes Berg80b99892011-11-18 16:23:01 +01004271 if (!netif_running(v)) {
4272 ret = -ENETDOWN;
4273 goto error;
4274 }
4275
4276 return v;
4277 error:
4278 dev_put(v);
4279 return ERR_PTR(ret);
Johannes Berg5727ef12007-12-19 02:03:34 +01004280}
4281
Johannes Berg94e860f2014-01-20 23:58:15 +01004282static const struct nla_policy
4283nl80211_sta_wme_policy[NL80211_STA_WME_MAX + 1] = {
Jouni Malinendf881292013-02-14 21:10:54 +02004284 [NL80211_STA_WME_UAPSD_QUEUES] = { .type = NLA_U8 },
4285 [NL80211_STA_WME_MAX_SP] = { .type = NLA_U8 },
4286};
4287
Johannes Bergff276692013-02-15 00:09:01 +01004288static int nl80211_parse_sta_wme(struct genl_info *info,
4289 struct station_parameters *params)
Jouni Malinendf881292013-02-14 21:10:54 +02004290{
Jouni Malinendf881292013-02-14 21:10:54 +02004291 struct nlattr *tb[NL80211_STA_WME_MAX + 1];
4292 struct nlattr *nla;
4293 int err;
4294
Jouni Malinendf881292013-02-14 21:10:54 +02004295 /* parse WME attributes if present */
4296 if (!info->attrs[NL80211_ATTR_STA_WME])
4297 return 0;
4298
4299 nla = info->attrs[NL80211_ATTR_STA_WME];
4300 err = nla_parse_nested(tb, NL80211_STA_WME_MAX, nla,
4301 nl80211_sta_wme_policy);
4302 if (err)
4303 return err;
4304
4305 if (tb[NL80211_STA_WME_UAPSD_QUEUES])
4306 params->uapsd_queues = nla_get_u8(
4307 tb[NL80211_STA_WME_UAPSD_QUEUES]);
4308 if (params->uapsd_queues & ~IEEE80211_WMM_IE_STA_QOSINFO_AC_MASK)
4309 return -EINVAL;
4310
4311 if (tb[NL80211_STA_WME_MAX_SP])
4312 params->max_sp = nla_get_u8(tb[NL80211_STA_WME_MAX_SP]);
4313
4314 if (params->max_sp & ~IEEE80211_WMM_IE_STA_QOSINFO_SP_MASK)
4315 return -EINVAL;
4316
4317 params->sta_modify_mask |= STATION_PARAM_APPLY_UAPSD;
4318
4319 return 0;
4320}
4321
Sunil Duttc01fc9a2013-10-09 20:45:21 +05304322static int nl80211_parse_sta_channel_info(struct genl_info *info,
4323 struct station_parameters *params)
4324{
4325 if (info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]) {
4326 params->supported_channels =
4327 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]);
4328 params->supported_channels_len =
4329 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]);
4330 /*
4331 * Need to include at least one (first channel, number of
4332 * channels) tuple for each subband, and must have proper
4333 * tuples for the rest of the data as well.
4334 */
4335 if (params->supported_channels_len < 2)
4336 return -EINVAL;
4337 if (params->supported_channels_len % 2)
4338 return -EINVAL;
4339 }
4340
4341 if (info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]) {
4342 params->supported_oper_classes =
4343 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]);
4344 params->supported_oper_classes_len =
4345 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]);
4346 /*
4347 * The value of the Length field of the Supported Operating
4348 * Classes element is between 2 and 253.
4349 */
4350 if (params->supported_oper_classes_len < 2 ||
4351 params->supported_oper_classes_len > 253)
4352 return -EINVAL;
4353 }
4354 return 0;
4355}
4356
Johannes Bergff276692013-02-15 00:09:01 +01004357static int nl80211_set_station_tdls(struct genl_info *info,
4358 struct station_parameters *params)
4359{
Sunil Duttc01fc9a2013-10-09 20:45:21 +05304360 int err;
Johannes Bergff276692013-02-15 00:09:01 +01004361 /* Dummy STA entry gets updated once the peer capabilities are known */
Jouni Malinen5e4b6f52013-05-16 20:11:08 +03004362 if (info->attrs[NL80211_ATTR_PEER_AID])
4363 params->aid = nla_get_u16(info->attrs[NL80211_ATTR_PEER_AID]);
Johannes Bergff276692013-02-15 00:09:01 +01004364 if (info->attrs[NL80211_ATTR_HT_CAPABILITY])
4365 params->ht_capa =
4366 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]);
4367 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY])
4368 params->vht_capa =
4369 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]);
4370
Sunil Duttc01fc9a2013-10-09 20:45:21 +05304371 err = nl80211_parse_sta_channel_info(info, params);
4372 if (err)
4373 return err;
4374
Johannes Bergff276692013-02-15 00:09:01 +01004375 return nl80211_parse_sta_wme(info, params);
4376}
4377
Johannes Berg5727ef12007-12-19 02:03:34 +01004378static int nl80211_set_station(struct sk_buff *skb, struct genl_info *info)
4379{
Johannes Berg4c476992010-10-04 21:36:35 +02004380 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg4c476992010-10-04 21:36:35 +02004381 struct net_device *dev = info->user_ptr[1];
Johannes Berg5727ef12007-12-19 02:03:34 +01004382 struct station_parameters params;
Johannes Berg77ee7c82013-02-15 00:48:33 +01004383 u8 *mac_addr;
4384 int err;
Johannes Berg5727ef12007-12-19 02:03:34 +01004385
4386 memset(&params, 0, sizeof(params));
4387
Johannes Berg77ee7c82013-02-15 00:48:33 +01004388 if (!rdev->ops->change_station)
4389 return -EOPNOTSUPP;
4390
Ayala Bekere4208422015-10-23 11:20:06 +03004391 /*
4392 * AID and listen_interval properties can be set only for unassociated
4393 * station. Include these parameters here and will check them in
4394 * cfg80211_check_station_change().
4395 */
Ayala Bekera9bc31e2015-11-26 16:26:12 +01004396 if (info->attrs[NL80211_ATTR_STA_AID])
4397 params.aid = nla_get_u16(info->attrs[NL80211_ATTR_STA_AID]);
Ayala Bekere4208422015-10-23 11:20:06 +03004398
4399 if (info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL])
4400 params.listen_interval =
4401 nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]);
4402 else
4403 params.listen_interval = -1;
Johannes Berg5727ef12007-12-19 02:03:34 +01004404
Ayala Beker17b94242016-03-17 15:41:38 +02004405 if (info->attrs[NL80211_ATTR_STA_SUPPORT_P2P_PS]) {
4406 u8 tmp;
4407
4408 tmp = nla_get_u8(info->attrs[NL80211_ATTR_STA_SUPPORT_P2P_PS]);
4409 if (tmp >= NUM_NL80211_P2P_PS_STATUS)
4410 return -EINVAL;
4411
4412 params.support_p2p_ps = tmp;
4413 } else {
4414 params.support_p2p_ps = -1;
4415 }
4416
Johannes Berg5727ef12007-12-19 02:03:34 +01004417 if (!info->attrs[NL80211_ATTR_MAC])
4418 return -EINVAL;
4419
4420 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
4421
4422 if (info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) {
4423 params.supported_rates =
4424 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
4425 params.supported_rates_len =
4426 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
4427 }
4428
Jouni Malinen9d62a982013-02-14 21:10:13 +02004429 if (info->attrs[NL80211_ATTR_STA_CAPABILITY]) {
4430 params.capability =
4431 nla_get_u16(info->attrs[NL80211_ATTR_STA_CAPABILITY]);
4432 params.sta_modify_mask |= STATION_PARAM_APPLY_CAPABILITY;
4433 }
4434
4435 if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]) {
4436 params.ext_capab =
4437 nla_data(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
4438 params.ext_capab_len =
4439 nla_len(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
4440 }
4441
Johannes Bergbdd3ae32012-01-02 13:30:03 +01004442 if (parse_station_flags(info, dev->ieee80211_ptr->iftype, &params))
Johannes Berg5727ef12007-12-19 02:03:34 +01004443 return -EINVAL;
4444
Johannes Bergf8bacc22013-02-14 23:27:01 +01004445 if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) {
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004446 params.plink_action =
Johannes Bergf8bacc22013-02-14 23:27:01 +01004447 nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]);
4448 if (params.plink_action >= NUM_NL80211_PLINK_ACTIONS)
4449 return -EINVAL;
4450 }
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004451
Johannes Bergf8bacc22013-02-14 23:27:01 +01004452 if (info->attrs[NL80211_ATTR_STA_PLINK_STATE]) {
Javier Cardona9c3990a2011-05-03 16:57:11 -07004453 params.plink_state =
Johannes Bergf8bacc22013-02-14 23:27:01 +01004454 nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_STATE]);
4455 if (params.plink_state >= NUM_NL80211_PLINK_STATES)
4456 return -EINVAL;
Masashi Honma7d27a0b2016-07-01 10:19:34 +09004457 if (info->attrs[NL80211_ATTR_MESH_PEER_AID]) {
4458 params.peer_aid = nla_get_u16(
4459 info->attrs[NL80211_ATTR_MESH_PEER_AID]);
4460 if (params.peer_aid > IEEE80211_MAX_AID)
4461 return -EINVAL;
4462 }
Johannes Bergf8bacc22013-02-14 23:27:01 +01004463 params.sta_modify_mask |= STATION_PARAM_APPLY_PLINK_STATE;
4464 }
Javier Cardona9c3990a2011-05-03 16:57:11 -07004465
Marco Porsch3b1c5a52013-01-07 16:04:52 +01004466 if (info->attrs[NL80211_ATTR_LOCAL_MESH_POWER_MODE]) {
4467 enum nl80211_mesh_power_mode pm = nla_get_u32(
4468 info->attrs[NL80211_ATTR_LOCAL_MESH_POWER_MODE]);
4469
4470 if (pm <= NL80211_MESH_POWER_UNKNOWN ||
4471 pm > NL80211_MESH_POWER_MAX)
4472 return -EINVAL;
4473
4474 params.local_pm = pm;
4475 }
4476
Johannes Berg77ee7c82013-02-15 00:48:33 +01004477 /* Include parameters for TDLS peer (will check later) */
4478 err = nl80211_set_station_tdls(info, &params);
4479 if (err)
4480 return err;
4481
4482 params.vlan = get_vlan(info, rdev);
4483 if (IS_ERR(params.vlan))
4484 return PTR_ERR(params.vlan);
4485
Johannes Berga97f4422009-06-18 17:23:43 +02004486 switch (dev->ieee80211_ptr->iftype) {
4487 case NL80211_IFTYPE_AP:
4488 case NL80211_IFTYPE_AP_VLAN:
Johannes Berg074ac8d2010-09-16 14:58:22 +02004489 case NL80211_IFTYPE_P2P_GO:
Johannes Berg074ac8d2010-09-16 14:58:22 +02004490 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Berga97f4422009-06-18 17:23:43 +02004491 case NL80211_IFTYPE_STATION:
Antonio Quartulli267335d2012-01-31 20:25:47 +01004492 case NL80211_IFTYPE_ADHOC:
Johannes Berga97f4422009-06-18 17:23:43 +02004493 case NL80211_IFTYPE_MESH_POINT:
Johannes Berga97f4422009-06-18 17:23:43 +02004494 break;
4495 default:
Johannes Berg77ee7c82013-02-15 00:48:33 +01004496 err = -EOPNOTSUPP;
4497 goto out_put_vlan;
Johannes Berg034d6552009-05-27 10:35:29 +02004498 }
4499
Johannes Berg77ee7c82013-02-15 00:48:33 +01004500 /* driver will call cfg80211_check_station_change() */
Hila Gonene35e4d22012-06-27 17:19:42 +03004501 err = rdev_change_station(rdev, dev, mac_addr, &params);
Johannes Berg5727ef12007-12-19 02:03:34 +01004502
Johannes Berg77ee7c82013-02-15 00:48:33 +01004503 out_put_vlan:
Johannes Berg5727ef12007-12-19 02:03:34 +01004504 if (params.vlan)
4505 dev_put(params.vlan);
Johannes Berg3b858752009-03-12 09:55:09 +01004506
Johannes Berg5727ef12007-12-19 02:03:34 +01004507 return err;
4508}
4509
4510static int nl80211_new_station(struct sk_buff *skb, struct genl_info *info)
4511{
Johannes Berg4c476992010-10-04 21:36:35 +02004512 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg5727ef12007-12-19 02:03:34 +01004513 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02004514 struct net_device *dev = info->user_ptr[1];
Johannes Berg5727ef12007-12-19 02:03:34 +01004515 struct station_parameters params;
4516 u8 *mac_addr = NULL;
Johannes Bergbda95eb2015-11-26 16:26:13 +01004517 u32 auth_assoc = BIT(NL80211_STA_FLAG_AUTHENTICATED) |
4518 BIT(NL80211_STA_FLAG_ASSOCIATED);
Johannes Berg5727ef12007-12-19 02:03:34 +01004519
4520 memset(&params, 0, sizeof(params));
4521
Johannes Berg984c3112013-02-14 23:43:25 +01004522 if (!rdev->ops->add_station)
4523 return -EOPNOTSUPP;
4524
Johannes Berg5727ef12007-12-19 02:03:34 +01004525 if (!info->attrs[NL80211_ATTR_MAC])
4526 return -EINVAL;
4527
Johannes Berg5727ef12007-12-19 02:03:34 +01004528 if (!info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL])
4529 return -EINVAL;
4530
4531 if (!info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES])
4532 return -EINVAL;
4533
Jouni Malinen5e4b6f52013-05-16 20:11:08 +03004534 if (!info->attrs[NL80211_ATTR_STA_AID] &&
4535 !info->attrs[NL80211_ATTR_PEER_AID])
Thadeu Lima de Souza Cascardo0e956c12010-02-12 12:34:50 -02004536 return -EINVAL;
4537
Johannes Berg5727ef12007-12-19 02:03:34 +01004538 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
4539 params.supported_rates =
4540 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
4541 params.supported_rates_len =
4542 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
4543 params.listen_interval =
4544 nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]);
Johannes Berg51b50fb2009-05-24 16:42:30 +02004545
Ayala Beker17b94242016-03-17 15:41:38 +02004546 if (info->attrs[NL80211_ATTR_STA_SUPPORT_P2P_PS]) {
4547 u8 tmp;
4548
4549 tmp = nla_get_u8(info->attrs[NL80211_ATTR_STA_SUPPORT_P2P_PS]);
4550 if (tmp >= NUM_NL80211_P2P_PS_STATUS)
4551 return -EINVAL;
4552
4553 params.support_p2p_ps = tmp;
4554 } else {
4555 /*
4556 * if not specified, assume it's supported for P2P GO interface,
4557 * and is NOT supported for AP interface
4558 */
4559 params.support_p2p_ps =
4560 dev->ieee80211_ptr->iftype == NL80211_IFTYPE_P2P_GO;
4561 }
4562
Jouni Malinen3d124ea2013-05-27 18:24:02 +03004563 if (info->attrs[NL80211_ATTR_PEER_AID])
Jouni Malinen5e4b6f52013-05-16 20:11:08 +03004564 params.aid = nla_get_u16(info->attrs[NL80211_ATTR_PEER_AID]);
Jouni Malinen3d124ea2013-05-27 18:24:02 +03004565 else
4566 params.aid = nla_get_u16(info->attrs[NL80211_ATTR_STA_AID]);
Thadeu Lima de Souza Cascardo0e956c12010-02-12 12:34:50 -02004567 if (!params.aid || params.aid > IEEE80211_MAX_AID)
4568 return -EINVAL;
Johannes Berg51b50fb2009-05-24 16:42:30 +02004569
Jouni Malinen9d62a982013-02-14 21:10:13 +02004570 if (info->attrs[NL80211_ATTR_STA_CAPABILITY]) {
4571 params.capability =
4572 nla_get_u16(info->attrs[NL80211_ATTR_STA_CAPABILITY]);
4573 params.sta_modify_mask |= STATION_PARAM_APPLY_CAPABILITY;
4574 }
4575
4576 if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]) {
4577 params.ext_capab =
4578 nla_data(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
4579 params.ext_capab_len =
4580 nla_len(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
4581 }
4582
Jouni Malinen36aedc902008-08-25 11:58:58 +03004583 if (info->attrs[NL80211_ATTR_HT_CAPABILITY])
4584 params.ht_capa =
4585 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]);
Johannes Berg5727ef12007-12-19 02:03:34 +01004586
Mahesh Palivelaf461be3e2012-10-11 08:04:52 +00004587 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY])
4588 params.vht_capa =
4589 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]);
4590
Marek Kwaczynski60f4a7b2013-12-03 10:04:59 +01004591 if (info->attrs[NL80211_ATTR_OPMODE_NOTIF]) {
4592 params.opmode_notif_used = true;
4593 params.opmode_notif =
4594 nla_get_u8(info->attrs[NL80211_ATTR_OPMODE_NOTIF]);
4595 }
4596
Johannes Bergf8bacc22013-02-14 23:27:01 +01004597 if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) {
Javier Cardona96b78df2011-04-07 15:08:33 -07004598 params.plink_action =
Johannes Bergf8bacc22013-02-14 23:27:01 +01004599 nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]);
4600 if (params.plink_action >= NUM_NL80211_PLINK_ACTIONS)
4601 return -EINVAL;
4602 }
Javier Cardona96b78df2011-04-07 15:08:33 -07004603
Sunil Duttc01fc9a2013-10-09 20:45:21 +05304604 err = nl80211_parse_sta_channel_info(info, &params);
4605 if (err)
4606 return err;
4607
Johannes Bergff276692013-02-15 00:09:01 +01004608 err = nl80211_parse_sta_wme(info, &params);
4609 if (err)
4610 return err;
Johannes Bergbdd90d52011-12-14 12:20:27 +01004611
Johannes Bergbdd3ae32012-01-02 13:30:03 +01004612 if (parse_station_flags(info, dev->ieee80211_ptr->iftype, &params))
Johannes Berg5727ef12007-12-19 02:03:34 +01004613 return -EINVAL;
4614
Johannes Berg496fcc22015-03-12 08:53:27 +02004615 /* HT/VHT requires QoS, but if we don't have that just ignore HT/VHT
4616 * as userspace might just pass through the capabilities from the IEs
4617 * directly, rather than enforcing this restriction and returning an
4618 * error in this case.
4619 */
4620 if (!(params.sta_flags_set & BIT(NL80211_STA_FLAG_WME))) {
4621 params.ht_capa = NULL;
4622 params.vht_capa = NULL;
4623 }
4624
Johannes Berg77ee7c82013-02-15 00:48:33 +01004625 /* When you run into this, adjust the code below for the new flag */
4626 BUILD_BUG_ON(NL80211_STA_FLAG_MAX != 7);
4627
Johannes Bergbdd90d52011-12-14 12:20:27 +01004628 switch (dev->ieee80211_ptr->iftype) {
4629 case NL80211_IFTYPE_AP:
4630 case NL80211_IFTYPE_AP_VLAN:
4631 case NL80211_IFTYPE_P2P_GO:
Johannes Berg984c3112013-02-14 23:43:25 +01004632 /* ignore WME attributes if iface/sta is not capable */
4633 if (!(rdev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) ||
4634 !(params.sta_flags_set & BIT(NL80211_STA_FLAG_WME)))
4635 params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD;
Eliad Pellerc75786c2011-08-23 14:37:46 +03004636
Johannes Bergbdd90d52011-12-14 12:20:27 +01004637 /* TDLS peers cannot be added */
Jouni Malinen3d124ea2013-05-27 18:24:02 +03004638 if ((params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) ||
4639 info->attrs[NL80211_ATTR_PEER_AID])
Johannes Berg4319e192011-09-07 11:50:48 +02004640 return -EINVAL;
Johannes Bergbdd90d52011-12-14 12:20:27 +01004641 /* but don't bother the driver with it */
4642 params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER);
Eliad Pellerc75786c2011-08-23 14:37:46 +03004643
Johannes Bergd582cff2012-10-26 17:53:44 +02004644 /* allow authenticated/associated only if driver handles it */
4645 if (!(rdev->wiphy.features &
4646 NL80211_FEATURE_FULL_AP_CLIENT_STATE) &&
Johannes Bergbda95eb2015-11-26 16:26:13 +01004647 params.sta_flags_mask & auth_assoc)
Johannes Bergd582cff2012-10-26 17:53:44 +02004648 return -EINVAL;
4649
Johannes Bergbda95eb2015-11-26 16:26:13 +01004650 /* Older userspace, or userspace wanting to be compatible with
4651 * !NL80211_FEATURE_FULL_AP_CLIENT_STATE, will not set the auth
4652 * and assoc flags in the mask, but assumes the station will be
4653 * added as associated anyway since this was the required driver
4654 * behaviour before NL80211_FEATURE_FULL_AP_CLIENT_STATE was
4655 * introduced.
4656 * In order to not bother drivers with this quirk in the API
4657 * set the flags in both the mask and set for new stations in
4658 * this case.
4659 */
4660 if (!(params.sta_flags_mask & auth_assoc)) {
4661 params.sta_flags_mask |= auth_assoc;
4662 params.sta_flags_set |= auth_assoc;
4663 }
4664
Johannes Bergbdd90d52011-12-14 12:20:27 +01004665 /* must be last in here for error handling */
4666 params.vlan = get_vlan(info, rdev);
4667 if (IS_ERR(params.vlan))
4668 return PTR_ERR(params.vlan);
4669 break;
4670 case NL80211_IFTYPE_MESH_POINT:
Johannes Berg984c3112013-02-14 23:43:25 +01004671 /* ignore uAPSD data */
4672 params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD;
4673
Johannes Bergd582cff2012-10-26 17:53:44 +02004674 /* associated is disallowed */
4675 if (params.sta_flags_mask & BIT(NL80211_STA_FLAG_ASSOCIATED))
4676 return -EINVAL;
Johannes Bergbdd90d52011-12-14 12:20:27 +01004677 /* TDLS peers cannot be added */
Jouni Malinen3d124ea2013-05-27 18:24:02 +03004678 if ((params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) ||
4679 info->attrs[NL80211_ATTR_PEER_AID])
Johannes Berg4319e192011-09-07 11:50:48 +02004680 return -EINVAL;
Johannes Bergbdd90d52011-12-14 12:20:27 +01004681 break;
4682 case NL80211_IFTYPE_STATION:
Johannes Berg93d08f02013-03-04 09:29:46 +01004683 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Berg984c3112013-02-14 23:43:25 +01004684 /* ignore uAPSD data */
4685 params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD;
4686
Johannes Berg77ee7c82013-02-15 00:48:33 +01004687 /* these are disallowed */
4688 if (params.sta_flags_mask &
4689 (BIT(NL80211_STA_FLAG_ASSOCIATED) |
4690 BIT(NL80211_STA_FLAG_AUTHENTICATED)))
Johannes Bergd582cff2012-10-26 17:53:44 +02004691 return -EINVAL;
Johannes Bergbdd90d52011-12-14 12:20:27 +01004692 /* Only TDLS peers can be added */
4693 if (!(params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)))
4694 return -EINVAL;
4695 /* Can only add if TDLS ... */
4696 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS))
4697 return -EOPNOTSUPP;
4698 /* ... with external setup is supported */
4699 if (!(rdev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP))
4700 return -EOPNOTSUPP;
Johannes Berg77ee7c82013-02-15 00:48:33 +01004701 /*
4702 * Older wpa_supplicant versions always mark the TDLS peer
4703 * as authorized, but it shouldn't yet be.
4704 */
4705 params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_AUTHORIZED);
Johannes Bergbdd90d52011-12-14 12:20:27 +01004706 break;
4707 default:
4708 return -EOPNOTSUPP;
Eliad Pellerc75786c2011-08-23 14:37:46 +03004709 }
4710
Johannes Bergbdd90d52011-12-14 12:20:27 +01004711 /* be aware of params.vlan when changing code here */
Johannes Berg5727ef12007-12-19 02:03:34 +01004712
Hila Gonene35e4d22012-06-27 17:19:42 +03004713 err = rdev_add_station(rdev, dev, mac_addr, &params);
Johannes Berg5727ef12007-12-19 02:03:34 +01004714
Johannes Berg5727ef12007-12-19 02:03:34 +01004715 if (params.vlan)
4716 dev_put(params.vlan);
Johannes Berg5727ef12007-12-19 02:03:34 +01004717 return err;
4718}
4719
4720static int nl80211_del_station(struct sk_buff *skb, struct genl_info *info)
4721{
Johannes Berg4c476992010-10-04 21:36:35 +02004722 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4723 struct net_device *dev = info->user_ptr[1];
Jouni Malinen89c771e2014-10-10 20:52:40 +03004724 struct station_del_parameters params;
4725
4726 memset(&params, 0, sizeof(params));
Johannes Berg5727ef12007-12-19 02:03:34 +01004727
4728 if (info->attrs[NL80211_ATTR_MAC])
Jouni Malinen89c771e2014-10-10 20:52:40 +03004729 params.mac = nla_data(info->attrs[NL80211_ATTR_MAC]);
Johannes Berg5727ef12007-12-19 02:03:34 +01004730
Johannes Berge80cf852009-05-11 14:43:13 +02004731 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
Marco Porschd5d9de02010-03-30 10:00:16 +02004732 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN &&
Johannes Berg074ac8d2010-09-16 14:58:22 +02004733 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT &&
Johannes Berg4c476992010-10-04 21:36:35 +02004734 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
4735 return -EINVAL;
Johannes Berge80cf852009-05-11 14:43:13 +02004736
Johannes Berg4c476992010-10-04 21:36:35 +02004737 if (!rdev->ops->del_station)
4738 return -EOPNOTSUPP;
Johannes Berg5727ef12007-12-19 02:03:34 +01004739
Jouni Malinen98856862014-10-20 13:20:45 +03004740 if (info->attrs[NL80211_ATTR_MGMT_SUBTYPE]) {
4741 params.subtype =
4742 nla_get_u8(info->attrs[NL80211_ATTR_MGMT_SUBTYPE]);
4743 if (params.subtype != IEEE80211_STYPE_DISASSOC >> 4 &&
4744 params.subtype != IEEE80211_STYPE_DEAUTH >> 4)
4745 return -EINVAL;
4746 } else {
4747 /* Default to Deauthentication frame */
4748 params.subtype = IEEE80211_STYPE_DEAUTH >> 4;
4749 }
4750
4751 if (info->attrs[NL80211_ATTR_REASON_CODE]) {
4752 params.reason_code =
4753 nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
4754 if (params.reason_code == 0)
4755 return -EINVAL; /* 0 is reserved */
4756 } else {
4757 /* Default to reason code 2 */
4758 params.reason_code = WLAN_REASON_PREV_AUTH_NOT_VALID;
4759 }
4760
Jouni Malinen89c771e2014-10-10 20:52:40 +03004761 return rdev_del_station(rdev, dev, &params);
Johannes Berg5727ef12007-12-19 02:03:34 +01004762}
4763
Eric W. Biederman15e47302012-09-07 20:12:54 +00004764static int nl80211_send_mpath(struct sk_buff *msg, u32 portid, u32 seq,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004765 int flags, struct net_device *dev,
4766 u8 *dst, u8 *next_hop,
4767 struct mpath_info *pinfo)
4768{
4769 void *hdr;
4770 struct nlattr *pinfoattr;
4771
Henning Rogge1ef4c852014-11-04 16:14:58 +01004772 hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_MPATH);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004773 if (!hdr)
4774 return -1;
4775
David S. Miller9360ffd2012-03-29 04:41:26 -04004776 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
4777 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, dst) ||
4778 nla_put(msg, NL80211_ATTR_MPATH_NEXT_HOP, ETH_ALEN, next_hop) ||
4779 nla_put_u32(msg, NL80211_ATTR_GENERATION, pinfo->generation))
4780 goto nla_put_failure;
Johannes Bergf5ea9122009-08-07 16:17:38 +02004781
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004782 pinfoattr = nla_nest_start(msg, NL80211_ATTR_MPATH_INFO);
4783 if (!pinfoattr)
4784 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04004785 if ((pinfo->filled & MPATH_INFO_FRAME_QLEN) &&
4786 nla_put_u32(msg, NL80211_MPATH_INFO_FRAME_QLEN,
4787 pinfo->frame_qlen))
4788 goto nla_put_failure;
4789 if (((pinfo->filled & MPATH_INFO_SN) &&
4790 nla_put_u32(msg, NL80211_MPATH_INFO_SN, pinfo->sn)) ||
4791 ((pinfo->filled & MPATH_INFO_METRIC) &&
4792 nla_put_u32(msg, NL80211_MPATH_INFO_METRIC,
4793 pinfo->metric)) ||
4794 ((pinfo->filled & MPATH_INFO_EXPTIME) &&
4795 nla_put_u32(msg, NL80211_MPATH_INFO_EXPTIME,
4796 pinfo->exptime)) ||
4797 ((pinfo->filled & MPATH_INFO_FLAGS) &&
4798 nla_put_u8(msg, NL80211_MPATH_INFO_FLAGS,
4799 pinfo->flags)) ||
4800 ((pinfo->filled & MPATH_INFO_DISCOVERY_TIMEOUT) &&
4801 nla_put_u32(msg, NL80211_MPATH_INFO_DISCOVERY_TIMEOUT,
4802 pinfo->discovery_timeout)) ||
4803 ((pinfo->filled & MPATH_INFO_DISCOVERY_RETRIES) &&
4804 nla_put_u8(msg, NL80211_MPATH_INFO_DISCOVERY_RETRIES,
4805 pinfo->discovery_retries)))
4806 goto nla_put_failure;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004807
4808 nla_nest_end(msg, pinfoattr);
4809
Johannes Berg053c0952015-01-16 22:09:00 +01004810 genlmsg_end(msg, hdr);
4811 return 0;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004812
4813 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07004814 genlmsg_cancel(msg, hdr);
4815 return -EMSGSIZE;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004816}
4817
4818static int nl80211_dump_mpath(struct sk_buff *skb,
Johannes Bergbba95fe2008-07-29 13:22:51 +02004819 struct netlink_callback *cb)
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004820{
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004821 struct mpath_info pinfo;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08004822 struct cfg80211_registered_device *rdev;
Johannes Berg97990a02013-04-19 01:02:55 +02004823 struct wireless_dev *wdev;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004824 u8 dst[ETH_ALEN];
4825 u8 next_hop[ETH_ALEN];
Johannes Berg97990a02013-04-19 01:02:55 +02004826 int path_idx = cb->args[2];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004827 int err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004828
Zhao, Gang1b8ec872014-04-21 12:53:02 +08004829 err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev);
Johannes Berg67748892010-10-04 21:14:06 +02004830 if (err)
4831 return err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004832
Zhao, Gang1b8ec872014-04-21 12:53:02 +08004833 if (!rdev->ops->dump_mpath) {
Jouni Malineneec60b02009-03-20 21:21:19 +02004834 err = -EOPNOTSUPP;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004835 goto out_err;
4836 }
4837
Johannes Berg97990a02013-04-19 01:02:55 +02004838 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) {
Jouni Malineneec60b02009-03-20 21:21:19 +02004839 err = -EOPNOTSUPP;
Roel Kluin0448b5f2009-08-22 21:15:49 +02004840 goto out_err;
Jouni Malineneec60b02009-03-20 21:21:19 +02004841 }
4842
Johannes Bergbba95fe2008-07-29 13:22:51 +02004843 while (1) {
Zhao, Gang1b8ec872014-04-21 12:53:02 +08004844 err = rdev_dump_mpath(rdev, wdev->netdev, path_idx, dst,
Johannes Berg97990a02013-04-19 01:02:55 +02004845 next_hop, &pinfo);
Johannes Bergbba95fe2008-07-29 13:22:51 +02004846 if (err == -ENOENT)
4847 break;
4848 if (err)
Johannes Berg3b858752009-03-12 09:55:09 +01004849 goto out_err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004850
Eric W. Biederman15e47302012-09-07 20:12:54 +00004851 if (nl80211_send_mpath(skb, NETLINK_CB(cb->skb).portid,
Johannes Bergbba95fe2008-07-29 13:22:51 +02004852 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Johannes Berg97990a02013-04-19 01:02:55 +02004853 wdev->netdev, dst, next_hop,
Johannes Bergbba95fe2008-07-29 13:22:51 +02004854 &pinfo) < 0)
4855 goto out;
4856
4857 path_idx++;
4858 }
4859
Johannes Bergbba95fe2008-07-29 13:22:51 +02004860 out:
Johannes Berg97990a02013-04-19 01:02:55 +02004861 cb->args[2] = path_idx;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004862 err = skb->len;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004863 out_err:
Zhao, Gang1b8ec872014-04-21 12:53:02 +08004864 nl80211_finish_wdev_dump(rdev);
Johannes Bergbba95fe2008-07-29 13:22:51 +02004865 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004866}
4867
4868static int nl80211_get_mpath(struct sk_buff *skb, struct genl_info *info)
4869{
Johannes Berg4c476992010-10-04 21:36:35 +02004870 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004871 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02004872 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004873 struct mpath_info pinfo;
4874 struct sk_buff *msg;
4875 u8 *dst = NULL;
4876 u8 next_hop[ETH_ALEN];
4877
4878 memset(&pinfo, 0, sizeof(pinfo));
4879
4880 if (!info->attrs[NL80211_ATTR_MAC])
4881 return -EINVAL;
4882
4883 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
4884
Johannes Berg4c476992010-10-04 21:36:35 +02004885 if (!rdev->ops->get_mpath)
4886 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01004887
Johannes Berg4c476992010-10-04 21:36:35 +02004888 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
4889 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02004890
Hila Gonene35e4d22012-06-27 17:19:42 +03004891 err = rdev_get_mpath(rdev, dev, dst, next_hop, &pinfo);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004892 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02004893 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004894
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07004895 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004896 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02004897 return -ENOMEM;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004898
Eric W. Biederman15e47302012-09-07 20:12:54 +00004899 if (nl80211_send_mpath(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berg4c476992010-10-04 21:36:35 +02004900 dev, dst, next_hop, &pinfo) < 0) {
4901 nlmsg_free(msg);
4902 return -ENOBUFS;
4903 }
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004904
Johannes Berg4c476992010-10-04 21:36:35 +02004905 return genlmsg_reply(msg, info);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004906}
4907
4908static int nl80211_set_mpath(struct sk_buff *skb, struct genl_info *info)
4909{
Johannes Berg4c476992010-10-04 21:36:35 +02004910 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4911 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004912 u8 *dst = NULL;
4913 u8 *next_hop = NULL;
4914
4915 if (!info->attrs[NL80211_ATTR_MAC])
4916 return -EINVAL;
4917
4918 if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP])
4919 return -EINVAL;
4920
4921 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
4922 next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]);
4923
Johannes Berg4c476992010-10-04 21:36:35 +02004924 if (!rdev->ops->change_mpath)
4925 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01004926
Johannes Berg4c476992010-10-04 21:36:35 +02004927 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
4928 return -EOPNOTSUPP;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004929
Hila Gonene35e4d22012-06-27 17:19:42 +03004930 return rdev_change_mpath(rdev, dev, dst, next_hop);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004931}
Johannes Berg4c476992010-10-04 21:36:35 +02004932
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004933static int nl80211_new_mpath(struct sk_buff *skb, struct genl_info *info)
4934{
Johannes Berg4c476992010-10-04 21:36:35 +02004935 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4936 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004937 u8 *dst = NULL;
4938 u8 *next_hop = NULL;
4939
4940 if (!info->attrs[NL80211_ATTR_MAC])
4941 return -EINVAL;
4942
4943 if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP])
4944 return -EINVAL;
4945
4946 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
4947 next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]);
4948
Johannes Berg4c476992010-10-04 21:36:35 +02004949 if (!rdev->ops->add_mpath)
4950 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01004951
Johannes Berg4c476992010-10-04 21:36:35 +02004952 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
4953 return -EOPNOTSUPP;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004954
Hila Gonene35e4d22012-06-27 17:19:42 +03004955 return rdev_add_mpath(rdev, dev, dst, next_hop);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004956}
4957
4958static int nl80211_del_mpath(struct sk_buff *skb, struct genl_info *info)
4959{
Johannes Berg4c476992010-10-04 21:36:35 +02004960 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4961 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004962 u8 *dst = NULL;
4963
4964 if (info->attrs[NL80211_ATTR_MAC])
4965 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
4966
Johannes Berg4c476992010-10-04 21:36:35 +02004967 if (!rdev->ops->del_mpath)
4968 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01004969
Hila Gonene35e4d22012-06-27 17:19:42 +03004970 return rdev_del_mpath(rdev, dev, dst);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004971}
4972
Henning Rogge66be7d22014-09-12 08:58:49 +02004973static int nl80211_get_mpp(struct sk_buff *skb, struct genl_info *info)
4974{
4975 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4976 int err;
4977 struct net_device *dev = info->user_ptr[1];
4978 struct mpath_info pinfo;
4979 struct sk_buff *msg;
4980 u8 *dst = NULL;
4981 u8 mpp[ETH_ALEN];
4982
4983 memset(&pinfo, 0, sizeof(pinfo));
4984
4985 if (!info->attrs[NL80211_ATTR_MAC])
4986 return -EINVAL;
4987
4988 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
4989
4990 if (!rdev->ops->get_mpp)
4991 return -EOPNOTSUPP;
4992
4993 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
4994 return -EOPNOTSUPP;
4995
4996 err = rdev_get_mpp(rdev, dev, dst, mpp, &pinfo);
4997 if (err)
4998 return err;
4999
5000 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
5001 if (!msg)
5002 return -ENOMEM;
5003
5004 if (nl80211_send_mpath(msg, info->snd_portid, info->snd_seq, 0,
5005 dev, dst, mpp, &pinfo) < 0) {
5006 nlmsg_free(msg);
5007 return -ENOBUFS;
5008 }
5009
5010 return genlmsg_reply(msg, info);
5011}
5012
5013static int nl80211_dump_mpp(struct sk_buff *skb,
5014 struct netlink_callback *cb)
5015{
5016 struct mpath_info pinfo;
5017 struct cfg80211_registered_device *rdev;
5018 struct wireless_dev *wdev;
5019 u8 dst[ETH_ALEN];
5020 u8 mpp[ETH_ALEN];
5021 int path_idx = cb->args[2];
5022 int err;
5023
5024 err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev);
5025 if (err)
5026 return err;
5027
5028 if (!rdev->ops->dump_mpp) {
5029 err = -EOPNOTSUPP;
5030 goto out_err;
5031 }
5032
5033 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) {
5034 err = -EOPNOTSUPP;
5035 goto out_err;
5036 }
5037
5038 while (1) {
5039 err = rdev_dump_mpp(rdev, wdev->netdev, path_idx, dst,
5040 mpp, &pinfo);
5041 if (err == -ENOENT)
5042 break;
5043 if (err)
5044 goto out_err;
5045
5046 if (nl80211_send_mpath(skb, NETLINK_CB(cb->skb).portid,
5047 cb->nlh->nlmsg_seq, NLM_F_MULTI,
5048 wdev->netdev, dst, mpp,
5049 &pinfo) < 0)
5050 goto out;
5051
5052 path_idx++;
5053 }
5054
5055 out:
5056 cb->args[2] = path_idx;
5057 err = skb->len;
5058 out_err:
5059 nl80211_finish_wdev_dump(rdev);
5060 return err;
5061}
5062
Jouni Malinen9f1ba902008-08-07 20:07:01 +03005063static int nl80211_set_bss(struct sk_buff *skb, struct genl_info *info)
5064{
Johannes Berg4c476992010-10-04 21:36:35 +02005065 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5066 struct net_device *dev = info->user_ptr[1];
Simon Wunderlichc56589e2013-11-21 18:19:49 +01005067 struct wireless_dev *wdev = dev->ieee80211_ptr;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03005068 struct bss_parameters params;
Simon Wunderlichc56589e2013-11-21 18:19:49 +01005069 int err;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03005070
5071 memset(&params, 0, sizeof(params));
5072 /* default to not changing parameters */
5073 params.use_cts_prot = -1;
5074 params.use_short_preamble = -1;
5075 params.use_short_slot_time = -1;
Felix Fietkaufd8aaaf2010-04-27 01:23:35 +02005076 params.ap_isolate = -1;
Helmut Schaa50b12f52010-11-19 12:40:25 +01005077 params.ht_opmode = -1;
Johannes Berg53cabad2012-11-14 15:17:28 +01005078 params.p2p_ctwindow = -1;
5079 params.p2p_opp_ps = -1;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03005080
5081 if (info->attrs[NL80211_ATTR_BSS_CTS_PROT])
5082 params.use_cts_prot =
5083 nla_get_u8(info->attrs[NL80211_ATTR_BSS_CTS_PROT]);
5084 if (info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE])
5085 params.use_short_preamble =
5086 nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]);
5087 if (info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME])
5088 params.use_short_slot_time =
5089 nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]);
Jouni Malinen90c97a02008-10-30 16:59:22 +02005090 if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) {
5091 params.basic_rates =
5092 nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
5093 params.basic_rates_len =
5094 nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
5095 }
Felix Fietkaufd8aaaf2010-04-27 01:23:35 +02005096 if (info->attrs[NL80211_ATTR_AP_ISOLATE])
5097 params.ap_isolate = !!nla_get_u8(info->attrs[NL80211_ATTR_AP_ISOLATE]);
Helmut Schaa50b12f52010-11-19 12:40:25 +01005098 if (info->attrs[NL80211_ATTR_BSS_HT_OPMODE])
5099 params.ht_opmode =
5100 nla_get_u16(info->attrs[NL80211_ATTR_BSS_HT_OPMODE]);
Jouni Malinen9f1ba902008-08-07 20:07:01 +03005101
Johannes Berg53cabad2012-11-14 15:17:28 +01005102 if (info->attrs[NL80211_ATTR_P2P_CTWINDOW]) {
5103 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
5104 return -EINVAL;
5105 params.p2p_ctwindow =
5106 nla_get_s8(info->attrs[NL80211_ATTR_P2P_CTWINDOW]);
5107 if (params.p2p_ctwindow < 0)
5108 return -EINVAL;
5109 if (params.p2p_ctwindow != 0 &&
5110 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_CTWIN))
5111 return -EINVAL;
5112 }
5113
5114 if (info->attrs[NL80211_ATTR_P2P_OPPPS]) {
5115 u8 tmp;
5116
5117 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
5118 return -EINVAL;
5119 tmp = nla_get_u8(info->attrs[NL80211_ATTR_P2P_OPPPS]);
5120 if (tmp > 1)
5121 return -EINVAL;
5122 params.p2p_opp_ps = tmp;
5123 if (params.p2p_opp_ps &&
5124 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_OPPPS))
5125 return -EINVAL;
5126 }
5127
Johannes Berg4c476992010-10-04 21:36:35 +02005128 if (!rdev->ops->change_bss)
5129 return -EOPNOTSUPP;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03005130
Johannes Berg074ac8d2010-09-16 14:58:22 +02005131 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
Johannes Berg4c476992010-10-04 21:36:35 +02005132 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
5133 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02005134
Simon Wunderlichc56589e2013-11-21 18:19:49 +01005135 wdev_lock(wdev);
5136 err = rdev_change_bss(rdev, dev, &params);
5137 wdev_unlock(wdev);
5138
5139 return err;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03005140}
5141
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005142static int nl80211_req_set_reg(struct sk_buff *skb, struct genl_info *info)
5143{
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005144 char *data = NULL;
Ilan peer05050752015-03-04 00:32:06 -05005145 bool is_indoor;
Luis R. Rodriguez57b5ce02012-07-12 11:49:18 -07005146 enum nl80211_user_reg_hint_type user_reg_hint_type;
Ilan peer05050752015-03-04 00:32:06 -05005147 u32 owner_nlportid;
5148
Luis R. Rodriguez80778f12009-02-21 00:04:22 -05005149 /*
5150 * You should only get this when cfg80211 hasn't yet initialized
5151 * completely when built-in to the kernel right between the time
5152 * window between nl80211_init() and regulatory_init(), if that is
5153 * even possible.
5154 */
Johannes Berg458f4f92012-12-06 15:47:38 +01005155 if (unlikely(!rcu_access_pointer(cfg80211_regdomain)))
Luis R. Rodriguezfe33eb32009-02-21 00:04:30 -05005156 return -EINPROGRESS;
Luis R. Rodriguez80778f12009-02-21 00:04:22 -05005157
Luis R. Rodriguez57b5ce02012-07-12 11:49:18 -07005158 if (info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE])
5159 user_reg_hint_type =
5160 nla_get_u32(info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE]);
5161 else
5162 user_reg_hint_type = NL80211_USER_REG_HINT_USER;
5163
5164 switch (user_reg_hint_type) {
5165 case NL80211_USER_REG_HINT_USER:
5166 case NL80211_USER_REG_HINT_CELL_BASE:
Ilan Peer52616f22014-02-25 16:26:00 +02005167 if (!info->attrs[NL80211_ATTR_REG_ALPHA2])
5168 return -EINVAL;
5169
5170 data = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]);
5171 return regulatory_hint_user(data, user_reg_hint_type);
5172 case NL80211_USER_REG_HINT_INDOOR:
Ilan peer05050752015-03-04 00:32:06 -05005173 if (info->attrs[NL80211_ATTR_SOCKET_OWNER]) {
5174 owner_nlportid = info->snd_portid;
5175 is_indoor = !!info->attrs[NL80211_ATTR_REG_INDOOR];
5176 } else {
5177 owner_nlportid = 0;
5178 is_indoor = true;
5179 }
5180
5181 return regulatory_hint_indoor(is_indoor, owner_nlportid);
Luis R. Rodriguez57b5ce02012-07-12 11:49:18 -07005182 default:
5183 return -EINVAL;
5184 }
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005185}
5186
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005187static int nl80211_get_mesh_config(struct sk_buff *skb,
Johannes Berg29cbe682010-12-03 09:20:44 +01005188 struct genl_info *info)
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005189{
Johannes Berg4c476992010-10-04 21:36:35 +02005190 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg4c476992010-10-04 21:36:35 +02005191 struct net_device *dev = info->user_ptr[1];
Johannes Berg29cbe682010-12-03 09:20:44 +01005192 struct wireless_dev *wdev = dev->ieee80211_ptr;
5193 struct mesh_config cur_params;
5194 int err = 0;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005195 void *hdr;
5196 struct nlattr *pinfoattr;
5197 struct sk_buff *msg;
5198
Johannes Berg29cbe682010-12-03 09:20:44 +01005199 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT)
5200 return -EOPNOTSUPP;
5201
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005202 if (!rdev->ops->get_mesh_config)
Johannes Berg4c476992010-10-04 21:36:35 +02005203 return -EOPNOTSUPP;
Jouni Malinenf3f92582009-03-20 17:57:36 +02005204
Johannes Berg29cbe682010-12-03 09:20:44 +01005205 wdev_lock(wdev);
5206 /* If not connected, get default parameters */
5207 if (!wdev->mesh_id_len)
5208 memcpy(&cur_params, &default_mesh_config, sizeof(cur_params));
5209 else
Hila Gonene35e4d22012-06-27 17:19:42 +03005210 err = rdev_get_mesh_config(rdev, dev, &cur_params);
Johannes Berg29cbe682010-12-03 09:20:44 +01005211 wdev_unlock(wdev);
5212
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005213 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02005214 return err;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005215
5216 /* Draw up a netlink message to send back */
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07005217 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02005218 if (!msg)
5219 return -ENOMEM;
Eric W. Biederman15e47302012-09-07 20:12:54 +00005220 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005221 NL80211_CMD_GET_MESH_CONFIG);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005222 if (!hdr)
Julia Lawallefe1cf02011-01-28 15:17:11 +01005223 goto out;
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005224 pinfoattr = nla_nest_start(msg, NL80211_ATTR_MESH_CONFIG);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005225 if (!pinfoattr)
5226 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04005227 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
5228 nla_put_u16(msg, NL80211_MESHCONF_RETRY_TIMEOUT,
5229 cur_params.dot11MeshRetryTimeout) ||
5230 nla_put_u16(msg, NL80211_MESHCONF_CONFIRM_TIMEOUT,
5231 cur_params.dot11MeshConfirmTimeout) ||
5232 nla_put_u16(msg, NL80211_MESHCONF_HOLDING_TIMEOUT,
5233 cur_params.dot11MeshHoldingTimeout) ||
5234 nla_put_u16(msg, NL80211_MESHCONF_MAX_PEER_LINKS,
5235 cur_params.dot11MeshMaxPeerLinks) ||
5236 nla_put_u8(msg, NL80211_MESHCONF_MAX_RETRIES,
5237 cur_params.dot11MeshMaxRetries) ||
5238 nla_put_u8(msg, NL80211_MESHCONF_TTL,
5239 cur_params.dot11MeshTTL) ||
5240 nla_put_u8(msg, NL80211_MESHCONF_ELEMENT_TTL,
5241 cur_params.element_ttl) ||
5242 nla_put_u8(msg, NL80211_MESHCONF_AUTO_OPEN_PLINKS,
5243 cur_params.auto_open_plinks) ||
John W. Linville7eab0f62012-04-12 14:25:14 -04005244 nla_put_u32(msg, NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR,
5245 cur_params.dot11MeshNbrOffsetMaxNeighbor) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04005246 nla_put_u8(msg, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES,
5247 cur_params.dot11MeshHWMPmaxPREQretries) ||
5248 nla_put_u32(msg, NL80211_MESHCONF_PATH_REFRESH_TIME,
5249 cur_params.path_refresh_time) ||
5250 nla_put_u16(msg, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT,
5251 cur_params.min_discovery_timeout) ||
5252 nla_put_u32(msg, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT,
5253 cur_params.dot11MeshHWMPactivePathTimeout) ||
5254 nla_put_u16(msg, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL,
5255 cur_params.dot11MeshHWMPpreqMinInterval) ||
5256 nla_put_u16(msg, NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL,
5257 cur_params.dot11MeshHWMPperrMinInterval) ||
5258 nla_put_u16(msg, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME,
5259 cur_params.dot11MeshHWMPnetDiameterTraversalTime) ||
5260 nla_put_u8(msg, NL80211_MESHCONF_HWMP_ROOTMODE,
5261 cur_params.dot11MeshHWMPRootMode) ||
5262 nla_put_u16(msg, NL80211_MESHCONF_HWMP_RANN_INTERVAL,
5263 cur_params.dot11MeshHWMPRannInterval) ||
5264 nla_put_u8(msg, NL80211_MESHCONF_GATE_ANNOUNCEMENTS,
5265 cur_params.dot11MeshGateAnnouncementProtocol) ||
5266 nla_put_u8(msg, NL80211_MESHCONF_FORWARDING,
5267 cur_params.dot11MeshForwarding) ||
5268 nla_put_u32(msg, NL80211_MESHCONF_RSSI_THRESHOLD,
Ashok Nagarajan70c33ea2012-04-30 14:20:32 -07005269 cur_params.rssi_threshold) ||
5270 nla_put_u32(msg, NL80211_MESHCONF_HT_OPMODE,
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08005271 cur_params.ht_opmode) ||
5272 nla_put_u32(msg, NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT,
5273 cur_params.dot11MeshHWMPactivePathToRootTimeout) ||
5274 nla_put_u16(msg, NL80211_MESHCONF_HWMP_ROOT_INTERVAL,
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +08005275 cur_params.dot11MeshHWMProotInterval) ||
5276 nla_put_u16(msg, NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL,
Marco Porsch3b1c5a52013-01-07 16:04:52 +01005277 cur_params.dot11MeshHWMPconfirmationInterval) ||
5278 nla_put_u32(msg, NL80211_MESHCONF_POWER_MODE,
5279 cur_params.power_mode) ||
5280 nla_put_u16(msg, NL80211_MESHCONF_AWAKE_WINDOW,
Colleen Twitty8e7c0532013-06-03 09:53:39 -07005281 cur_params.dot11MeshAwakeWindowDuration) ||
5282 nla_put_u32(msg, NL80211_MESHCONF_PLINK_TIMEOUT,
5283 cur_params.plink_timeout))
David S. Miller9360ffd2012-03-29 04:41:26 -04005284 goto nla_put_failure;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005285 nla_nest_end(msg, pinfoattr);
5286 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02005287 return genlmsg_reply(msg, info);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005288
Johannes Berg3b858752009-03-12 09:55:09 +01005289 nla_put_failure:
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005290 genlmsg_cancel(msg, hdr);
Julia Lawallefe1cf02011-01-28 15:17:11 +01005291 out:
Yuri Ershovd080e272010-06-29 15:08:07 +04005292 nlmsg_free(msg);
Johannes Berg4c476992010-10-04 21:36:35 +02005293 return -ENOBUFS;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005294}
5295
Alexey Dobriyanb54452b2010-02-18 08:14:31 +00005296static const struct nla_policy nl80211_meshconf_params_policy[NL80211_MESHCONF_ATTR_MAX+1] = {
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005297 [NL80211_MESHCONF_RETRY_TIMEOUT] = { .type = NLA_U16 },
5298 [NL80211_MESHCONF_CONFIRM_TIMEOUT] = { .type = NLA_U16 },
5299 [NL80211_MESHCONF_HOLDING_TIMEOUT] = { .type = NLA_U16 },
5300 [NL80211_MESHCONF_MAX_PEER_LINKS] = { .type = NLA_U16 },
5301 [NL80211_MESHCONF_MAX_RETRIES] = { .type = NLA_U8 },
5302 [NL80211_MESHCONF_TTL] = { .type = NLA_U8 },
Javier Cardona45904f22010-12-03 09:20:40 +01005303 [NL80211_MESHCONF_ELEMENT_TTL] = { .type = NLA_U8 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005304 [NL80211_MESHCONF_AUTO_OPEN_PLINKS] = { .type = NLA_U8 },
Javier Cardonad299a1f2012-03-31 11:31:33 -07005305 [NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR] = { .type = NLA_U32 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005306 [NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES] = { .type = NLA_U8 },
5307 [NL80211_MESHCONF_PATH_REFRESH_TIME] = { .type = NLA_U32 },
5308 [NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT] = { .type = NLA_U16 },
5309 [NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT] = { .type = NLA_U32 },
5310 [NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL] = { .type = NLA_U16 },
Thomas Pedersendca7e942011-11-24 17:15:24 -08005311 [NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL] = { .type = NLA_U16 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005312 [NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME] = { .type = NLA_U16 },
Javier Cardona699403d2011-08-09 16:45:09 -07005313 [NL80211_MESHCONF_HWMP_ROOTMODE] = { .type = NLA_U8 },
Javier Cardona0507e152011-08-09 16:45:10 -07005314 [NL80211_MESHCONF_HWMP_RANN_INTERVAL] = { .type = NLA_U16 },
Javier Cardona16dd7262011-08-09 16:45:11 -07005315 [NL80211_MESHCONF_GATE_ANNOUNCEMENTS] = { .type = NLA_U8 },
Chun-Yeow Yeoh94f90652012-01-21 01:02:16 +08005316 [NL80211_MESHCONF_FORWARDING] = { .type = NLA_U8 },
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005317 [NL80211_MESHCONF_RSSI_THRESHOLD] = { .type = NLA_U32 },
5318 [NL80211_MESHCONF_HT_OPMODE] = { .type = NLA_U16 },
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08005319 [NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT] = { .type = NLA_U32 },
5320 [NL80211_MESHCONF_HWMP_ROOT_INTERVAL] = { .type = NLA_U16 },
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +08005321 [NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL] = { .type = NLA_U16 },
Marco Porsch3b1c5a52013-01-07 16:04:52 +01005322 [NL80211_MESHCONF_POWER_MODE] = { .type = NLA_U32 },
5323 [NL80211_MESHCONF_AWAKE_WINDOW] = { .type = NLA_U16 },
Colleen Twitty8e7c0532013-06-03 09:53:39 -07005324 [NL80211_MESHCONF_PLINK_TIMEOUT] = { .type = NLA_U32 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005325};
5326
Javier Cardonac80d5452010-12-16 17:37:49 -08005327static const struct nla_policy
5328 nl80211_mesh_setup_params_policy[NL80211_MESH_SETUP_ATTR_MAX+1] = {
Javier Cardonad299a1f2012-03-31 11:31:33 -07005329 [NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC] = { .type = NLA_U8 },
Javier Cardonac80d5452010-12-16 17:37:49 -08005330 [NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL] = { .type = NLA_U8 },
5331 [NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC] = { .type = NLA_U8 },
Javier Cardona15d5dda2011-04-07 15:08:28 -07005332 [NL80211_MESH_SETUP_USERSPACE_AUTH] = { .type = NLA_FLAG },
Colleen Twitty6e16d902013-05-08 11:45:59 -07005333 [NL80211_MESH_SETUP_AUTH_PROTOCOL] = { .type = NLA_U8 },
Thomas Pedersenbb2798d2013-03-04 13:06:10 -08005334 [NL80211_MESH_SETUP_USERSPACE_MPM] = { .type = NLA_FLAG },
Javier Cardona581a8b02011-04-07 15:08:27 -07005335 [NL80211_MESH_SETUP_IE] = { .type = NLA_BINARY,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005336 .len = IEEE80211_MAX_DATA_LEN },
Javier Cardonab130e5c2011-05-03 16:57:07 -07005337 [NL80211_MESH_SETUP_USERSPACE_AMPE] = { .type = NLA_FLAG },
Javier Cardonac80d5452010-12-16 17:37:49 -08005338};
5339
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005340static int nl80211_check_bool(const struct nlattr *nla, u8 min, u8 max, bool *out)
5341{
5342 u8 val = nla_get_u8(nla);
5343 if (val < min || val > max)
5344 return -EINVAL;
5345 *out = val;
5346 return 0;
5347}
5348
5349static int nl80211_check_u8(const struct nlattr *nla, u8 min, u8 max, u8 *out)
5350{
5351 u8 val = nla_get_u8(nla);
5352 if (val < min || val > max)
5353 return -EINVAL;
5354 *out = val;
5355 return 0;
5356}
5357
5358static int nl80211_check_u16(const struct nlattr *nla, u16 min, u16 max, u16 *out)
5359{
5360 u16 val = nla_get_u16(nla);
5361 if (val < min || val > max)
5362 return -EINVAL;
5363 *out = val;
5364 return 0;
5365}
5366
5367static int nl80211_check_u32(const struct nlattr *nla, u32 min, u32 max, u32 *out)
5368{
5369 u32 val = nla_get_u32(nla);
5370 if (val < min || val > max)
5371 return -EINVAL;
5372 *out = val;
5373 return 0;
5374}
5375
5376static int nl80211_check_s32(const struct nlattr *nla, s32 min, s32 max, s32 *out)
5377{
5378 s32 val = nla_get_s32(nla);
5379 if (val < min || val > max)
5380 return -EINVAL;
5381 *out = val;
5382 return 0;
5383}
5384
Johannes Bergff9a71a2016-08-11 14:59:53 +02005385static int nl80211_check_power_mode(const struct nlattr *nla,
5386 enum nl80211_mesh_power_mode min,
5387 enum nl80211_mesh_power_mode max,
5388 enum nl80211_mesh_power_mode *out)
5389{
5390 u32 val = nla_get_u32(nla);
5391 if (val < min || val > max)
5392 return -EINVAL;
5393 *out = val;
5394 return 0;
5395}
5396
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005397static int nl80211_parse_mesh_config(struct genl_info *info,
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005398 struct mesh_config *cfg,
5399 u32 *mask_out)
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005400{
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005401 struct nlattr *tb[NL80211_MESHCONF_ATTR_MAX + 1];
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005402 u32 mask = 0;
Masashi Honma97572352016-08-03 10:07:44 +09005403 u16 ht_opmode;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005404
Marco Porschea54fba2013-01-07 16:04:48 +01005405#define FILL_IN_MESH_PARAM_IF_SET(tb, cfg, param, min, max, mask, attr, fn) \
5406do { \
5407 if (tb[attr]) { \
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005408 if (fn(tb[attr], min, max, &cfg->param)) \
Marco Porschea54fba2013-01-07 16:04:48 +01005409 return -EINVAL; \
Marco Porschea54fba2013-01-07 16:04:48 +01005410 mask |= (1 << (attr - 1)); \
5411 } \
5412} while (0)
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005413
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005414 if (!info->attrs[NL80211_ATTR_MESH_CONFIG])
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005415 return -EINVAL;
5416 if (nla_parse_nested(tb, NL80211_MESHCONF_ATTR_MAX,
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005417 info->attrs[NL80211_ATTR_MESH_CONFIG],
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005418 nl80211_meshconf_params_policy))
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005419 return -EINVAL;
5420
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005421 /* This makes sure that there aren't more than 32 mesh config
5422 * parameters (otherwise our bitfield scheme would not work.) */
5423 BUILD_BUG_ON(NL80211_MESHCONF_ATTR_MAX > 32);
5424
5425 /* Fill in the params struct */
Marco Porschea54fba2013-01-07 16:04:48 +01005426 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshRetryTimeout, 1, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005427 mask, NL80211_MESHCONF_RETRY_TIMEOUT,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005428 nl80211_check_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01005429 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshConfirmTimeout, 1, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005430 mask, NL80211_MESHCONF_CONFIRM_TIMEOUT,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005431 nl80211_check_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01005432 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHoldingTimeout, 1, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005433 mask, NL80211_MESHCONF_HOLDING_TIMEOUT,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005434 nl80211_check_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01005435 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxPeerLinks, 0, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005436 mask, NL80211_MESHCONF_MAX_PEER_LINKS,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005437 nl80211_check_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01005438 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxRetries, 0, 16,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005439 mask, NL80211_MESHCONF_MAX_RETRIES,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005440 nl80211_check_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01005441 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshTTL, 1, 255,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005442 mask, NL80211_MESHCONF_TTL, nl80211_check_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01005443 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, element_ttl, 1, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005444 mask, NL80211_MESHCONF_ELEMENT_TTL,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005445 nl80211_check_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01005446 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, auto_open_plinks, 0, 1,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005447 mask, NL80211_MESHCONF_AUTO_OPEN_PLINKS,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005448 nl80211_check_bool);
Marco Porschea54fba2013-01-07 16:04:48 +01005449 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshNbrOffsetMaxNeighbor,
5450 1, 255, mask,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005451 NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005452 nl80211_check_u32);
Marco Porschea54fba2013-01-07 16:04:48 +01005453 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPmaxPREQretries, 0, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005454 mask, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005455 nl80211_check_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01005456 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, path_refresh_time, 1, 65535,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005457 mask, NL80211_MESHCONF_PATH_REFRESH_TIME,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005458 nl80211_check_u32);
Marco Porschea54fba2013-01-07 16:04:48 +01005459 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, min_discovery_timeout, 1, 65535,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005460 mask, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005461 nl80211_check_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01005462 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathTimeout,
5463 1, 65535, mask,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005464 NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005465 nl80211_check_u32);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005466 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPpreqMinInterval,
Marco Porschea54fba2013-01-07 16:04:48 +01005467 1, 65535, mask,
5468 NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005469 nl80211_check_u16);
Thomas Pedersendca7e942011-11-24 17:15:24 -08005470 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPperrMinInterval,
Marco Porschea54fba2013-01-07 16:04:48 +01005471 1, 65535, mask,
5472 NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005473 nl80211_check_u16);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005474 FILL_IN_MESH_PARAM_IF_SET(tb, cfg,
Marco Porschea54fba2013-01-07 16:04:48 +01005475 dot11MeshHWMPnetDiameterTraversalTime,
5476 1, 65535, mask,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005477 NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005478 nl80211_check_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01005479 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRootMode, 0, 4,
5480 mask, NL80211_MESHCONF_HWMP_ROOTMODE,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005481 nl80211_check_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01005482 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRannInterval, 1, 65535,
5483 mask, NL80211_MESHCONF_HWMP_RANN_INTERVAL,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005484 nl80211_check_u16);
Rui Paulo63c57232009-11-09 23:46:57 +00005485 FILL_IN_MESH_PARAM_IF_SET(tb, cfg,
Marco Porschea54fba2013-01-07 16:04:48 +01005486 dot11MeshGateAnnouncementProtocol, 0, 1,
5487 mask, NL80211_MESHCONF_GATE_ANNOUNCEMENTS,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005488 nl80211_check_bool);
Marco Porschea54fba2013-01-07 16:04:48 +01005489 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshForwarding, 0, 1,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005490 mask, NL80211_MESHCONF_FORWARDING,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005491 nl80211_check_bool);
Chun-Yeow Yeoh83374fe2013-07-11 18:24:03 +08005492 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, rssi_threshold, -255, 0,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005493 mask, NL80211_MESHCONF_RSSI_THRESHOLD,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005494 nl80211_check_s32);
Masashi Honma97572352016-08-03 10:07:44 +09005495 /*
5496 * Check HT operation mode based on
5497 * IEEE 802.11 2012 8.4.2.59 HT Operation element.
5498 */
5499 if (tb[NL80211_MESHCONF_HT_OPMODE]) {
5500 ht_opmode = nla_get_u16(tb[NL80211_MESHCONF_HT_OPMODE]);
5501
5502 if (ht_opmode & ~(IEEE80211_HT_OP_MODE_PROTECTION |
5503 IEEE80211_HT_OP_MODE_NON_GF_STA_PRSNT |
5504 IEEE80211_HT_OP_MODE_NON_HT_STA_PRSNT))
5505 return -EINVAL;
5506
5507 if ((ht_opmode & IEEE80211_HT_OP_MODE_NON_GF_STA_PRSNT) &&
5508 (ht_opmode & IEEE80211_HT_OP_MODE_NON_HT_STA_PRSNT))
5509 return -EINVAL;
5510
5511 switch (ht_opmode & IEEE80211_HT_OP_MODE_PROTECTION) {
5512 case IEEE80211_HT_OP_MODE_PROTECTION_NONE:
5513 case IEEE80211_HT_OP_MODE_PROTECTION_20MHZ:
5514 if (ht_opmode & IEEE80211_HT_OP_MODE_NON_HT_STA_PRSNT)
5515 return -EINVAL;
5516 break;
5517 case IEEE80211_HT_OP_MODE_PROTECTION_NONMEMBER:
5518 case IEEE80211_HT_OP_MODE_PROTECTION_NONHT_MIXED:
5519 if (!(ht_opmode & IEEE80211_HT_OP_MODE_NON_HT_STA_PRSNT))
5520 return -EINVAL;
5521 break;
5522 }
5523 cfg->ht_opmode = ht_opmode;
5524 }
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08005525 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathToRootTimeout,
Marco Porschea54fba2013-01-07 16:04:48 +01005526 1, 65535, mask,
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08005527 NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005528 nl80211_check_u32);
Marco Porschea54fba2013-01-07 16:04:48 +01005529 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMProotInterval, 1, 65535,
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08005530 mask, NL80211_MESHCONF_HWMP_ROOT_INTERVAL,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005531 nl80211_check_u16);
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +08005532 FILL_IN_MESH_PARAM_IF_SET(tb, cfg,
Marco Porschea54fba2013-01-07 16:04:48 +01005533 dot11MeshHWMPconfirmationInterval,
5534 1, 65535, mask,
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +08005535 NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005536 nl80211_check_u16);
Marco Porsch3b1c5a52013-01-07 16:04:52 +01005537 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, power_mode,
5538 NL80211_MESH_POWER_ACTIVE,
5539 NL80211_MESH_POWER_MAX,
5540 mask, NL80211_MESHCONF_POWER_MODE,
Johannes Bergff9a71a2016-08-11 14:59:53 +02005541 nl80211_check_power_mode);
Marco Porsch3b1c5a52013-01-07 16:04:52 +01005542 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshAwakeWindowDuration,
5543 0, 65535, mask,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005544 NL80211_MESHCONF_AWAKE_WINDOW, nl80211_check_u16);
Masashi Honma31f909a2015-02-24 22:42:16 +09005545 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, plink_timeout, 0, 0xffffffff,
Colleen Twitty8e7c0532013-06-03 09:53:39 -07005546 mask, NL80211_MESHCONF_PLINK_TIMEOUT,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005547 nl80211_check_u32);
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005548 if (mask_out)
5549 *mask_out = mask;
Javier Cardonac80d5452010-12-16 17:37:49 -08005550
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005551 return 0;
5552
5553#undef FILL_IN_MESH_PARAM_IF_SET
5554}
5555
Javier Cardonac80d5452010-12-16 17:37:49 -08005556static int nl80211_parse_mesh_setup(struct genl_info *info,
5557 struct mesh_setup *setup)
5558{
Thomas Pedersenbb2798d2013-03-04 13:06:10 -08005559 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Javier Cardonac80d5452010-12-16 17:37:49 -08005560 struct nlattr *tb[NL80211_MESH_SETUP_ATTR_MAX + 1];
5561
5562 if (!info->attrs[NL80211_ATTR_MESH_SETUP])
5563 return -EINVAL;
5564 if (nla_parse_nested(tb, NL80211_MESH_SETUP_ATTR_MAX,
5565 info->attrs[NL80211_ATTR_MESH_SETUP],
5566 nl80211_mesh_setup_params_policy))
5567 return -EINVAL;
5568
Javier Cardonad299a1f2012-03-31 11:31:33 -07005569 if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC])
5570 setup->sync_method =
5571 (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC])) ?
5572 IEEE80211_SYNC_METHOD_VENDOR :
5573 IEEE80211_SYNC_METHOD_NEIGHBOR_OFFSET;
5574
Javier Cardonac80d5452010-12-16 17:37:49 -08005575 if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL])
5576 setup->path_sel_proto =
5577 (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL])) ?
5578 IEEE80211_PATH_PROTOCOL_VENDOR :
5579 IEEE80211_PATH_PROTOCOL_HWMP;
5580
5581 if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC])
5582 setup->path_metric =
5583 (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC])) ?
5584 IEEE80211_PATH_METRIC_VENDOR :
5585 IEEE80211_PATH_METRIC_AIRTIME;
5586
Javier Cardona581a8b02011-04-07 15:08:27 -07005587 if (tb[NL80211_MESH_SETUP_IE]) {
Javier Cardonac80d5452010-12-16 17:37:49 -08005588 struct nlattr *ieattr =
Javier Cardona581a8b02011-04-07 15:08:27 -07005589 tb[NL80211_MESH_SETUP_IE];
Javier Cardonac80d5452010-12-16 17:37:49 -08005590 if (!is_valid_ie_attr(ieattr))
5591 return -EINVAL;
Javier Cardona581a8b02011-04-07 15:08:27 -07005592 setup->ie = nla_data(ieattr);
5593 setup->ie_len = nla_len(ieattr);
Javier Cardonac80d5452010-12-16 17:37:49 -08005594 }
Thomas Pedersenbb2798d2013-03-04 13:06:10 -08005595 if (tb[NL80211_MESH_SETUP_USERSPACE_MPM] &&
5596 !(rdev->wiphy.features & NL80211_FEATURE_USERSPACE_MPM))
5597 return -EINVAL;
5598 setup->user_mpm = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_MPM]);
Javier Cardonab130e5c2011-05-03 16:57:07 -07005599 setup->is_authenticated = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AUTH]);
5600 setup->is_secure = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AMPE]);
Thomas Pedersenbb2798d2013-03-04 13:06:10 -08005601 if (setup->is_secure)
5602 setup->user_mpm = true;
Javier Cardonac80d5452010-12-16 17:37:49 -08005603
Colleen Twitty6e16d902013-05-08 11:45:59 -07005604 if (tb[NL80211_MESH_SETUP_AUTH_PROTOCOL]) {
5605 if (!setup->user_mpm)
5606 return -EINVAL;
5607 setup->auth_id =
5608 nla_get_u8(tb[NL80211_MESH_SETUP_AUTH_PROTOCOL]);
5609 }
5610
Javier Cardonac80d5452010-12-16 17:37:49 -08005611 return 0;
5612}
5613
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005614static int nl80211_update_mesh_config(struct sk_buff *skb,
Johannes Berg29cbe682010-12-03 09:20:44 +01005615 struct genl_info *info)
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005616{
5617 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5618 struct net_device *dev = info->user_ptr[1];
Johannes Berg29cbe682010-12-03 09:20:44 +01005619 struct wireless_dev *wdev = dev->ieee80211_ptr;
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005620 struct mesh_config cfg;
5621 u32 mask;
5622 int err;
5623
Johannes Berg29cbe682010-12-03 09:20:44 +01005624 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT)
5625 return -EOPNOTSUPP;
5626
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005627 if (!rdev->ops->update_mesh_config)
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005628 return -EOPNOTSUPP;
5629
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005630 err = nl80211_parse_mesh_config(info, &cfg, &mask);
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005631 if (err)
5632 return err;
5633
Johannes Berg29cbe682010-12-03 09:20:44 +01005634 wdev_lock(wdev);
5635 if (!wdev->mesh_id_len)
5636 err = -ENOLINK;
5637
5638 if (!err)
Hila Gonene35e4d22012-06-27 17:19:42 +03005639 err = rdev_update_mesh_config(rdev, dev, mask, &cfg);
Johannes Berg29cbe682010-12-03 09:20:44 +01005640
5641 wdev_unlock(wdev);
5642
5643 return err;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005644}
5645
Arik Nemtsovad30ca22014-12-15 19:25:59 +02005646static int nl80211_put_regdom(const struct ieee80211_regdomain *regdom,
5647 struct sk_buff *msg)
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005648{
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005649 struct nlattr *nl_reg_rules;
5650 unsigned int i;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005651
Johannes Berg458f4f92012-12-06 15:47:38 +01005652 if (nla_put_string(msg, NL80211_ATTR_REG_ALPHA2, regdom->alpha2) ||
5653 (regdom->dfs_region &&
5654 nla_put_u8(msg, NL80211_ATTR_DFS_REGION, regdom->dfs_region)))
Arik Nemtsovad30ca22014-12-15 19:25:59 +02005655 goto nla_put_failure;
Johannes Berg458f4f92012-12-06 15:47:38 +01005656
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005657 nl_reg_rules = nla_nest_start(msg, NL80211_ATTR_REG_RULES);
5658 if (!nl_reg_rules)
Arik Nemtsovad30ca22014-12-15 19:25:59 +02005659 goto nla_put_failure;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005660
Johannes Berg458f4f92012-12-06 15:47:38 +01005661 for (i = 0; i < regdom->n_reg_rules; i++) {
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005662 struct nlattr *nl_reg_rule;
5663 const struct ieee80211_reg_rule *reg_rule;
5664 const struct ieee80211_freq_range *freq_range;
5665 const struct ieee80211_power_rule *power_rule;
Janusz Dziedzic97524822014-01-30 09:52:20 +01005666 unsigned int max_bandwidth_khz;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005667
Johannes Berg458f4f92012-12-06 15:47:38 +01005668 reg_rule = &regdom->reg_rules[i];
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005669 freq_range = &reg_rule->freq_range;
5670 power_rule = &reg_rule->power_rule;
5671
5672 nl_reg_rule = nla_nest_start(msg, i);
5673 if (!nl_reg_rule)
Arik Nemtsovad30ca22014-12-15 19:25:59 +02005674 goto nla_put_failure;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005675
Janusz Dziedzic97524822014-01-30 09:52:20 +01005676 max_bandwidth_khz = freq_range->max_bandwidth_khz;
5677 if (!max_bandwidth_khz)
5678 max_bandwidth_khz = reg_get_max_bandwidth(regdom,
5679 reg_rule);
5680
David S. Miller9360ffd2012-03-29 04:41:26 -04005681 if (nla_put_u32(msg, NL80211_ATTR_REG_RULE_FLAGS,
5682 reg_rule->flags) ||
5683 nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_START,
5684 freq_range->start_freq_khz) ||
5685 nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_END,
5686 freq_range->end_freq_khz) ||
5687 nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_MAX_BW,
Janusz Dziedzic97524822014-01-30 09:52:20 +01005688 max_bandwidth_khz) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04005689 nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN,
5690 power_rule->max_antenna_gain) ||
5691 nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_EIRP,
Janusz Dziedzic089027e2014-02-21 19:46:12 +01005692 power_rule->max_eirp) ||
5693 nla_put_u32(msg, NL80211_ATTR_DFS_CAC_TIME,
5694 reg_rule->dfs_cac_ms))
Arik Nemtsovad30ca22014-12-15 19:25:59 +02005695 goto nla_put_failure;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005696
5697 nla_nest_end(msg, nl_reg_rule);
5698 }
5699
5700 nla_nest_end(msg, nl_reg_rules);
Arik Nemtsovad30ca22014-12-15 19:25:59 +02005701 return 0;
5702
5703nla_put_failure:
5704 return -EMSGSIZE;
5705}
5706
5707static int nl80211_get_reg_do(struct sk_buff *skb, struct genl_info *info)
5708{
5709 const struct ieee80211_regdomain *regdom = NULL;
5710 struct cfg80211_registered_device *rdev;
5711 struct wiphy *wiphy = NULL;
5712 struct sk_buff *msg;
5713 void *hdr;
5714
5715 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
5716 if (!msg)
5717 return -ENOBUFS;
5718
5719 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
5720 NL80211_CMD_GET_REG);
5721 if (!hdr)
5722 goto put_failure;
5723
5724 if (info->attrs[NL80211_ATTR_WIPHY]) {
Arik Nemtsov1bdd7162014-12-15 19:26:01 +02005725 bool self_managed;
5726
Arik Nemtsovad30ca22014-12-15 19:25:59 +02005727 rdev = cfg80211_get_dev_from_info(genl_info_net(info), info);
5728 if (IS_ERR(rdev)) {
5729 nlmsg_free(msg);
5730 return PTR_ERR(rdev);
5731 }
5732
5733 wiphy = &rdev->wiphy;
Arik Nemtsov1bdd7162014-12-15 19:26:01 +02005734 self_managed = wiphy->regulatory_flags &
5735 REGULATORY_WIPHY_SELF_MANAGED;
Arik Nemtsovad30ca22014-12-15 19:25:59 +02005736 regdom = get_wiphy_regdom(wiphy);
5737
Arik Nemtsov1bdd7162014-12-15 19:26:01 +02005738 /* a self-managed-reg device must have a private regdom */
5739 if (WARN_ON(!regdom && self_managed)) {
5740 nlmsg_free(msg);
5741 return -EINVAL;
5742 }
5743
Arik Nemtsovad30ca22014-12-15 19:25:59 +02005744 if (regdom &&
5745 nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy)))
5746 goto nla_put_failure;
5747 }
5748
5749 if (!wiphy && reg_last_request_cell_base() &&
5750 nla_put_u32(msg, NL80211_ATTR_USER_REG_HINT_TYPE,
5751 NL80211_USER_REG_HINT_CELL_BASE))
5752 goto nla_put_failure;
5753
5754 rcu_read_lock();
5755
5756 if (!regdom)
5757 regdom = rcu_dereference(cfg80211_regdomain);
5758
5759 if (nl80211_put_regdom(regdom, msg))
5760 goto nla_put_failure_rcu;
5761
5762 rcu_read_unlock();
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005763
5764 genlmsg_end(msg, hdr);
Johannes Berg5fe231e2013-05-08 21:45:15 +02005765 return genlmsg_reply(msg, info);
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005766
Johannes Berg458f4f92012-12-06 15:47:38 +01005767nla_put_failure_rcu:
5768 rcu_read_unlock();
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005769nla_put_failure:
5770 genlmsg_cancel(msg, hdr);
Julia Lawallefe1cf02011-01-28 15:17:11 +01005771put_failure:
Yuri Ershovd080e272010-06-29 15:08:07 +04005772 nlmsg_free(msg);
Johannes Berg5fe231e2013-05-08 21:45:15 +02005773 return -EMSGSIZE;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005774}
5775
Arik Nemtsovad30ca22014-12-15 19:25:59 +02005776static int nl80211_send_regdom(struct sk_buff *msg, struct netlink_callback *cb,
5777 u32 seq, int flags, struct wiphy *wiphy,
5778 const struct ieee80211_regdomain *regdom)
5779{
5780 void *hdr = nl80211hdr_put(msg, NETLINK_CB(cb->skb).portid, seq, flags,
5781 NL80211_CMD_GET_REG);
5782
5783 if (!hdr)
5784 return -1;
5785
5786 genl_dump_check_consistent(cb, hdr, &nl80211_fam);
5787
5788 if (nl80211_put_regdom(regdom, msg))
5789 goto nla_put_failure;
5790
5791 if (!wiphy && reg_last_request_cell_base() &&
5792 nla_put_u32(msg, NL80211_ATTR_USER_REG_HINT_TYPE,
5793 NL80211_USER_REG_HINT_CELL_BASE))
5794 goto nla_put_failure;
5795
5796 if (wiphy &&
5797 nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy)))
5798 goto nla_put_failure;
5799
Arik Nemtsov1bdd7162014-12-15 19:26:01 +02005800 if (wiphy && wiphy->regulatory_flags & REGULATORY_WIPHY_SELF_MANAGED &&
5801 nla_put_flag(msg, NL80211_ATTR_WIPHY_SELF_MANAGED_REG))
5802 goto nla_put_failure;
5803
Johannes Berg053c0952015-01-16 22:09:00 +01005804 genlmsg_end(msg, hdr);
5805 return 0;
Arik Nemtsovad30ca22014-12-15 19:25:59 +02005806
5807nla_put_failure:
5808 genlmsg_cancel(msg, hdr);
5809 return -EMSGSIZE;
5810}
5811
5812static int nl80211_get_reg_dump(struct sk_buff *skb,
5813 struct netlink_callback *cb)
5814{
5815 const struct ieee80211_regdomain *regdom = NULL;
5816 struct cfg80211_registered_device *rdev;
5817 int err, reg_idx, start = cb->args[2];
5818
5819 rtnl_lock();
5820
5821 if (cfg80211_regdomain && start == 0) {
5822 err = nl80211_send_regdom(skb, cb, cb->nlh->nlmsg_seq,
5823 NLM_F_MULTI, NULL,
5824 rtnl_dereference(cfg80211_regdomain));
5825 if (err < 0)
5826 goto out_err;
5827 }
5828
5829 /* the global regdom is idx 0 */
5830 reg_idx = 1;
5831 list_for_each_entry(rdev, &cfg80211_rdev_list, list) {
5832 regdom = get_wiphy_regdom(&rdev->wiphy);
5833 if (!regdom)
5834 continue;
5835
5836 if (++reg_idx <= start)
5837 continue;
5838
5839 err = nl80211_send_regdom(skb, cb, cb->nlh->nlmsg_seq,
5840 NLM_F_MULTI, &rdev->wiphy, regdom);
5841 if (err < 0) {
5842 reg_idx--;
5843 break;
5844 }
5845 }
5846
5847 cb->args[2] = reg_idx;
5848 err = skb->len;
5849out_err:
5850 rtnl_unlock();
5851 return err;
5852}
5853
Johannes Bergb6863032015-10-15 09:25:18 +02005854#ifdef CONFIG_CFG80211_CRDA_SUPPORT
5855static const struct nla_policy reg_rule_policy[NL80211_REG_RULE_ATTR_MAX + 1] = {
5856 [NL80211_ATTR_REG_RULE_FLAGS] = { .type = NLA_U32 },
5857 [NL80211_ATTR_FREQ_RANGE_START] = { .type = NLA_U32 },
5858 [NL80211_ATTR_FREQ_RANGE_END] = { .type = NLA_U32 },
5859 [NL80211_ATTR_FREQ_RANGE_MAX_BW] = { .type = NLA_U32 },
5860 [NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN] = { .type = NLA_U32 },
5861 [NL80211_ATTR_POWER_RULE_MAX_EIRP] = { .type = NLA_U32 },
5862 [NL80211_ATTR_DFS_CAC_TIME] = { .type = NLA_U32 },
5863};
5864
5865static int parse_reg_rule(struct nlattr *tb[],
5866 struct ieee80211_reg_rule *reg_rule)
5867{
5868 struct ieee80211_freq_range *freq_range = &reg_rule->freq_range;
5869 struct ieee80211_power_rule *power_rule = &reg_rule->power_rule;
5870
5871 if (!tb[NL80211_ATTR_REG_RULE_FLAGS])
5872 return -EINVAL;
5873 if (!tb[NL80211_ATTR_FREQ_RANGE_START])
5874 return -EINVAL;
5875 if (!tb[NL80211_ATTR_FREQ_RANGE_END])
5876 return -EINVAL;
5877 if (!tb[NL80211_ATTR_FREQ_RANGE_MAX_BW])
5878 return -EINVAL;
5879 if (!tb[NL80211_ATTR_POWER_RULE_MAX_EIRP])
5880 return -EINVAL;
5881
5882 reg_rule->flags = nla_get_u32(tb[NL80211_ATTR_REG_RULE_FLAGS]);
5883
5884 freq_range->start_freq_khz =
5885 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_START]);
5886 freq_range->end_freq_khz =
5887 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_END]);
5888 freq_range->max_bandwidth_khz =
5889 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]);
5890
5891 power_rule->max_eirp =
5892 nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]);
5893
5894 if (tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN])
5895 power_rule->max_antenna_gain =
5896 nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]);
5897
5898 if (tb[NL80211_ATTR_DFS_CAC_TIME])
5899 reg_rule->dfs_cac_ms =
5900 nla_get_u32(tb[NL80211_ATTR_DFS_CAC_TIME]);
5901
5902 return 0;
5903}
5904
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005905static int nl80211_set_reg(struct sk_buff *skb, struct genl_info *info)
5906{
5907 struct nlattr *tb[NL80211_REG_RULE_ATTR_MAX + 1];
5908 struct nlattr *nl_reg_rule;
Johannes Bergea372c52014-11-28 14:54:31 +01005909 char *alpha2;
5910 int rem_reg_rules, r;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005911 u32 num_rules = 0, rule_idx = 0, size_of_regd;
Luis R. Rodriguez4c7d3982013-11-13 18:54:02 +01005912 enum nl80211_dfs_regions dfs_region = NL80211_DFS_UNSET;
Johannes Bergea372c52014-11-28 14:54:31 +01005913 struct ieee80211_regdomain *rd;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005914
5915 if (!info->attrs[NL80211_ATTR_REG_ALPHA2])
5916 return -EINVAL;
5917
5918 if (!info->attrs[NL80211_ATTR_REG_RULES])
5919 return -EINVAL;
5920
5921 alpha2 = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]);
5922
Luis R. Rodriguez8b60b072011-10-11 10:59:02 -07005923 if (info->attrs[NL80211_ATTR_DFS_REGION])
5924 dfs_region = nla_get_u8(info->attrs[NL80211_ATTR_DFS_REGION]);
5925
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005926 nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES],
Johannes Berg1a919312012-12-03 17:21:11 +01005927 rem_reg_rules) {
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005928 num_rules++;
5929 if (num_rules > NL80211_MAX_SUPP_REG_RULES)
Luis R. Rodriguez4776c6e2009-05-13 17:04:39 -04005930 return -EINVAL;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005931 }
5932
Luis R. Rodrigueze4387682013-11-05 09:18:01 -08005933 if (!reg_is_valid_request(alpha2))
5934 return -EINVAL;
5935
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005936 size_of_regd = sizeof(struct ieee80211_regdomain) +
Johannes Berg1a919312012-12-03 17:21:11 +01005937 num_rules * sizeof(struct ieee80211_reg_rule);
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005938
5939 rd = kzalloc(size_of_regd, GFP_KERNEL);
Johannes Berg6913b492012-12-04 00:48:59 +01005940 if (!rd)
5941 return -ENOMEM;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005942
5943 rd->n_reg_rules = num_rules;
5944 rd->alpha2[0] = alpha2[0];
5945 rd->alpha2[1] = alpha2[1];
5946
Luis R. Rodriguez8b60b072011-10-11 10:59:02 -07005947 /*
5948 * Disable DFS master mode if the DFS region was
5949 * not supported or known on this kernel.
5950 */
5951 if (reg_supported_dfs_region(dfs_region))
5952 rd->dfs_region = dfs_region;
5953
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005954 nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES],
Johannes Berg1a919312012-12-03 17:21:11 +01005955 rem_reg_rules) {
Johannes Bergae811e22014-01-24 10:17:47 +01005956 r = nla_parse(tb, NL80211_REG_RULE_ATTR_MAX,
5957 nla_data(nl_reg_rule), nla_len(nl_reg_rule),
5958 reg_rule_policy);
5959 if (r)
5960 goto bad_reg;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005961 r = parse_reg_rule(tb, &rd->reg_rules[rule_idx]);
5962 if (r)
5963 goto bad_reg;
5964
5965 rule_idx++;
5966
Luis R. Rodriguezd0e18f82009-05-13 17:04:40 -04005967 if (rule_idx > NL80211_MAX_SUPP_REG_RULES) {
5968 r = -EINVAL;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005969 goto bad_reg;
Luis R. Rodriguezd0e18f82009-05-13 17:04:40 -04005970 }
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005971 }
5972
Johannes Berg06627992016-06-09 10:40:09 +02005973 /* set_regdom takes ownership of rd */
5974 return set_regdom(rd, REGD_SOURCE_CRDA);
Johannes Bergd2372b32008-10-24 20:32:20 +02005975 bad_reg:
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005976 kfree(rd);
Luis R. Rodriguezd0e18f82009-05-13 17:04:40 -04005977 return r;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005978}
Johannes Bergb6863032015-10-15 09:25:18 +02005979#endif /* CONFIG_CFG80211_CRDA_SUPPORT */
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005980
Johannes Berg83f5e2c2009-06-17 17:41:49 +02005981static int validate_scan_freqs(struct nlattr *freqs)
5982{
5983 struct nlattr *attr1, *attr2;
5984 int n_channels = 0, tmp1, tmp2;
5985
5986 nla_for_each_nested(attr1, freqs, tmp1) {
5987 n_channels++;
5988 /*
5989 * Some hardware has a limited channel list for
5990 * scanning, and it is pretty much nonsensical
5991 * to scan for a channel twice, so disallow that
5992 * and don't require drivers to check that the
5993 * channel list they get isn't longer than what
5994 * they can scan, as long as they can scan all
5995 * the channels they registered at once.
5996 */
5997 nla_for_each_nested(attr2, freqs, tmp2)
5998 if (attr1 != attr2 &&
5999 nla_get_u32(attr1) == nla_get_u32(attr2))
6000 return 0;
6001 }
6002
6003 return n_channels;
6004}
6005
Johannes Berg57fbcce2016-04-12 15:56:15 +02006006static bool is_band_valid(struct wiphy *wiphy, enum nl80211_band b)
Arend van Spriel38de03d2016-03-02 20:37:18 +01006007{
Johannes Berg57fbcce2016-04-12 15:56:15 +02006008 return b < NUM_NL80211_BANDS && wiphy->bands[b];
Arend van Spriel38de03d2016-03-02 20:37:18 +01006009}
6010
6011static int parse_bss_select(struct nlattr *nla, struct wiphy *wiphy,
6012 struct cfg80211_bss_selection *bss_select)
6013{
6014 struct nlattr *attr[NL80211_BSS_SELECT_ATTR_MAX + 1];
6015 struct nlattr *nest;
6016 int err;
6017 bool found = false;
6018 int i;
6019
6020 /* only process one nested attribute */
6021 nest = nla_data(nla);
6022 if (!nla_ok(nest, nla_len(nest)))
6023 return -EINVAL;
6024
6025 err = nla_parse(attr, NL80211_BSS_SELECT_ATTR_MAX, nla_data(nest),
6026 nla_len(nest), nl80211_bss_select_policy);
6027 if (err)
6028 return err;
6029
6030 /* only one attribute may be given */
6031 for (i = 0; i <= NL80211_BSS_SELECT_ATTR_MAX; i++) {
6032 if (attr[i]) {
6033 if (found)
6034 return -EINVAL;
6035 found = true;
6036 }
6037 }
6038
6039 bss_select->behaviour = __NL80211_BSS_SELECT_ATTR_INVALID;
6040
6041 if (attr[NL80211_BSS_SELECT_ATTR_RSSI])
6042 bss_select->behaviour = NL80211_BSS_SELECT_ATTR_RSSI;
6043
6044 if (attr[NL80211_BSS_SELECT_ATTR_BAND_PREF]) {
6045 bss_select->behaviour = NL80211_BSS_SELECT_ATTR_BAND_PREF;
6046 bss_select->param.band_pref =
6047 nla_get_u32(attr[NL80211_BSS_SELECT_ATTR_BAND_PREF]);
6048 if (!is_band_valid(wiphy, bss_select->param.band_pref))
6049 return -EINVAL;
6050 }
6051
6052 if (attr[NL80211_BSS_SELECT_ATTR_RSSI_ADJUST]) {
6053 struct nl80211_bss_select_rssi_adjust *adj_param;
6054
6055 adj_param = nla_data(attr[NL80211_BSS_SELECT_ATTR_RSSI_ADJUST]);
6056 bss_select->behaviour = NL80211_BSS_SELECT_ATTR_RSSI_ADJUST;
6057 bss_select->param.adjust.band = adj_param->band;
6058 bss_select->param.adjust.delta = adj_param->delta;
6059 if (!is_band_valid(wiphy, bss_select->param.adjust.band))
6060 return -EINVAL;
6061 }
6062
6063 /* user-space did not provide behaviour attribute */
6064 if (bss_select->behaviour == __NL80211_BSS_SELECT_ATTR_INVALID)
6065 return -EINVAL;
6066
6067 if (!(wiphy->bss_select_support & BIT(bss_select->behaviour)))
6068 return -EINVAL;
6069
6070 return 0;
6071}
6072
Johannes Bergad2b26a2014-06-12 21:39:05 +02006073static int nl80211_parse_random_mac(struct nlattr **attrs,
6074 u8 *mac_addr, u8 *mac_addr_mask)
6075{
6076 int i;
6077
6078 if (!attrs[NL80211_ATTR_MAC] && !attrs[NL80211_ATTR_MAC_MASK]) {
Joe Perchesd2beae12015-03-02 19:54:58 -08006079 eth_zero_addr(mac_addr);
6080 eth_zero_addr(mac_addr_mask);
Johannes Bergad2b26a2014-06-12 21:39:05 +02006081 mac_addr[0] = 0x2;
6082 mac_addr_mask[0] = 0x3;
6083
6084 return 0;
6085 }
6086
6087 /* need both or none */
6088 if (!attrs[NL80211_ATTR_MAC] || !attrs[NL80211_ATTR_MAC_MASK])
6089 return -EINVAL;
6090
6091 memcpy(mac_addr, nla_data(attrs[NL80211_ATTR_MAC]), ETH_ALEN);
6092 memcpy(mac_addr_mask, nla_data(attrs[NL80211_ATTR_MAC_MASK]), ETH_ALEN);
6093
6094 /* don't allow or configure an mcast address */
6095 if (!is_multicast_ether_addr(mac_addr_mask) ||
6096 is_multicast_ether_addr(mac_addr))
6097 return -EINVAL;
6098
6099 /*
6100 * allow users to pass a MAC address that has bits set outside
6101 * of the mask, but don't bother drivers with having to deal
6102 * with such bits
6103 */
6104 for (i = 0; i < ETH_ALEN; i++)
6105 mac_addr[i] &= mac_addr_mask[i];
6106
6107 return 0;
6108}
6109
Johannes Berg2a519312009-02-10 21:25:55 +01006110static int nl80211_trigger_scan(struct sk_buff *skb, struct genl_info *info)
6111{
Johannes Berg4c476992010-10-04 21:36:35 +02006112 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Bergfd014282012-06-18 19:17:03 +02006113 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg2a519312009-02-10 21:25:55 +01006114 struct cfg80211_scan_request *request;
Johannes Berg2a519312009-02-10 21:25:55 +01006115 struct nlattr *attr;
6116 struct wiphy *wiphy;
Johannes Berg83f5e2c2009-06-17 17:41:49 +02006117 int err, tmp, n_ssids = 0, n_channels, i;
Jouni Malinen70692ad2009-02-16 19:39:13 +02006118 size_t ie_len;
Johannes Berg2a519312009-02-10 21:25:55 +01006119
Johannes Bergf4a11bb2009-03-27 12:40:28 +01006120 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
6121 return -EINVAL;
6122
Johannes Berg79c97e92009-07-07 03:56:12 +02006123 wiphy = &rdev->wiphy;
Johannes Berg2a519312009-02-10 21:25:55 +01006124
Johannes Berg4c476992010-10-04 21:36:35 +02006125 if (!rdev->ops->scan)
6126 return -EOPNOTSUPP;
Johannes Berg2a519312009-02-10 21:25:55 +01006127
Johannes Bergf9d15d12014-01-22 11:14:19 +02006128 if (rdev->scan_req || rdev->scan_msg) {
Johannes Bergf9f47522013-03-19 15:04:07 +01006129 err = -EBUSY;
6130 goto unlock;
6131 }
Johannes Berg2a519312009-02-10 21:25:55 +01006132
6133 if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
Johannes Berg83f5e2c2009-06-17 17:41:49 +02006134 n_channels = validate_scan_freqs(
6135 info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]);
Johannes Bergf9f47522013-03-19 15:04:07 +01006136 if (!n_channels) {
6137 err = -EINVAL;
6138 goto unlock;
6139 }
Johannes Berg2a519312009-02-10 21:25:55 +01006140 } else {
Ilan Peerbdfbec22014-01-09 11:37:23 +02006141 n_channels = ieee80211_get_num_supported_channels(wiphy);
Johannes Berg2a519312009-02-10 21:25:55 +01006142 }
6143
6144 if (info->attrs[NL80211_ATTR_SCAN_SSIDS])
6145 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp)
6146 n_ssids++;
6147
Johannes Bergf9f47522013-03-19 15:04:07 +01006148 if (n_ssids > wiphy->max_scan_ssids) {
6149 err = -EINVAL;
6150 goto unlock;
6151 }
Johannes Berg2a519312009-02-10 21:25:55 +01006152
Jouni Malinen70692ad2009-02-16 19:39:13 +02006153 if (info->attrs[NL80211_ATTR_IE])
6154 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
6155 else
6156 ie_len = 0;
6157
Johannes Bergf9f47522013-03-19 15:04:07 +01006158 if (ie_len > wiphy->max_scan_ie_len) {
6159 err = -EINVAL;
6160 goto unlock;
6161 }
Johannes Berg18a83652009-03-31 12:12:05 +02006162
Johannes Berg2a519312009-02-10 21:25:55 +01006163 request = kzalloc(sizeof(*request)
Luciano Coelhoa2cd43c2011-05-18 11:42:03 +03006164 + sizeof(*request->ssids) * n_ssids
6165 + sizeof(*request->channels) * n_channels
Jouni Malinen70692ad2009-02-16 19:39:13 +02006166 + ie_len, GFP_KERNEL);
Johannes Bergf9f47522013-03-19 15:04:07 +01006167 if (!request) {
6168 err = -ENOMEM;
6169 goto unlock;
6170 }
Johannes Berg2a519312009-02-10 21:25:55 +01006171
Johannes Berg2a519312009-02-10 21:25:55 +01006172 if (n_ssids)
Johannes Berg5ba63532009-08-07 17:54:07 +02006173 request->ssids = (void *)&request->channels[n_channels];
Johannes Berg2a519312009-02-10 21:25:55 +01006174 request->n_ssids = n_ssids;
Jouni Malinen70692ad2009-02-16 19:39:13 +02006175 if (ie_len) {
Johannes Berg13874e42015-01-23 11:25:20 +01006176 if (n_ssids)
Jouni Malinen70692ad2009-02-16 19:39:13 +02006177 request->ie = (void *)(request->ssids + n_ssids);
6178 else
6179 request->ie = (void *)(request->channels + n_channels);
6180 }
Johannes Berg2a519312009-02-10 21:25:55 +01006181
Johannes Berg584991d2009-11-02 13:32:03 +01006182 i = 0;
Johannes Berg2a519312009-02-10 21:25:55 +01006183 if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
6184 /* user specified, bail out if channel not found */
Johannes Berg2a519312009-02-10 21:25:55 +01006185 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_FREQUENCIES], tmp) {
Johannes Berg584991d2009-11-02 13:32:03 +01006186 struct ieee80211_channel *chan;
6187
6188 chan = ieee80211_get_channel(wiphy, nla_get_u32(attr));
6189
6190 if (!chan) {
Johannes Berg2a519312009-02-10 21:25:55 +01006191 err = -EINVAL;
6192 goto out_free;
6193 }
Johannes Berg584991d2009-11-02 13:32:03 +01006194
6195 /* ignore disabled channels */
6196 if (chan->flags & IEEE80211_CHAN_DISABLED)
6197 continue;
6198
6199 request->channels[i] = chan;
Johannes Berg2a519312009-02-10 21:25:55 +01006200 i++;
6201 }
6202 } else {
Johannes Berg57fbcce2016-04-12 15:56:15 +02006203 enum nl80211_band band;
Johannes Berg34850ab2011-07-18 18:08:35 +02006204
Johannes Berg2a519312009-02-10 21:25:55 +01006205 /* all channels */
Johannes Berg57fbcce2016-04-12 15:56:15 +02006206 for (band = 0; band < NUM_NL80211_BANDS; band++) {
Johannes Berg2a519312009-02-10 21:25:55 +01006207 int j;
Kirtika Ruchandani7a087e72016-05-29 19:51:23 -07006208
Johannes Berg2a519312009-02-10 21:25:55 +01006209 if (!wiphy->bands[band])
6210 continue;
6211 for (j = 0; j < wiphy->bands[band]->n_channels; j++) {
Johannes Berg584991d2009-11-02 13:32:03 +01006212 struct ieee80211_channel *chan;
6213
6214 chan = &wiphy->bands[band]->channels[j];
6215
6216 if (chan->flags & IEEE80211_CHAN_DISABLED)
6217 continue;
6218
6219 request->channels[i] = chan;
Johannes Berg2a519312009-02-10 21:25:55 +01006220 i++;
6221 }
6222 }
6223 }
6224
Johannes Berg584991d2009-11-02 13:32:03 +01006225 if (!i) {
6226 err = -EINVAL;
6227 goto out_free;
6228 }
6229
6230 request->n_channels = i;
6231
Johannes Berg2a519312009-02-10 21:25:55 +01006232 i = 0;
Johannes Berg13874e42015-01-23 11:25:20 +01006233 if (n_ssids) {
Johannes Berg2a519312009-02-10 21:25:55 +01006234 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) {
Luciano Coelho57a27e12011-06-07 20:42:26 +03006235 if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) {
Johannes Berg2a519312009-02-10 21:25:55 +01006236 err = -EINVAL;
6237 goto out_free;
6238 }
Luciano Coelho57a27e12011-06-07 20:42:26 +03006239 request->ssids[i].ssid_len = nla_len(attr);
Johannes Berg2a519312009-02-10 21:25:55 +01006240 memcpy(request->ssids[i].ssid, nla_data(attr), nla_len(attr));
Johannes Berg2a519312009-02-10 21:25:55 +01006241 i++;
6242 }
6243 }
6244
Jouni Malinen70692ad2009-02-16 19:39:13 +02006245 if (info->attrs[NL80211_ATTR_IE]) {
6246 request->ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Johannes Bergde95a542009-04-01 11:58:36 +02006247 memcpy((void *)request->ie,
6248 nla_data(info->attrs[NL80211_ATTR_IE]),
Jouni Malinen70692ad2009-02-16 19:39:13 +02006249 request->ie_len);
6250 }
6251
Johannes Berg57fbcce2016-04-12 15:56:15 +02006252 for (i = 0; i < NUM_NL80211_BANDS; i++)
Johannes Berga401d2b2011-07-20 00:52:16 +02006253 if (wiphy->bands[i])
6254 request->rates[i] =
6255 (1 << wiphy->bands[i]->n_bitrates) - 1;
Johannes Berg34850ab2011-07-18 18:08:35 +02006256
6257 if (info->attrs[NL80211_ATTR_SCAN_SUPP_RATES]) {
6258 nla_for_each_nested(attr,
6259 info->attrs[NL80211_ATTR_SCAN_SUPP_RATES],
6260 tmp) {
Johannes Berg57fbcce2016-04-12 15:56:15 +02006261 enum nl80211_band band = nla_type(attr);
Johannes Berg34850ab2011-07-18 18:08:35 +02006262
Johannes Berg57fbcce2016-04-12 15:56:15 +02006263 if (band < 0 || band >= NUM_NL80211_BANDS) {
Johannes Berg34850ab2011-07-18 18:08:35 +02006264 err = -EINVAL;
6265 goto out_free;
6266 }
Felix Fietkau1b09cd82013-11-20 19:40:41 +01006267
6268 if (!wiphy->bands[band])
6269 continue;
6270
Johannes Berg34850ab2011-07-18 18:08:35 +02006271 err = ieee80211_get_ratemask(wiphy->bands[band],
6272 nla_data(attr),
6273 nla_len(attr),
6274 &request->rates[band]);
6275 if (err)
6276 goto out_free;
6277 }
6278 }
6279
Avraham Stern1d762502016-07-05 17:10:13 +03006280 if (info->attrs[NL80211_ATTR_MEASUREMENT_DURATION]) {
6281 if (!wiphy_ext_feature_isset(wiphy,
6282 NL80211_EXT_FEATURE_SET_SCAN_DWELL)) {
6283 err = -EOPNOTSUPP;
6284 goto out_free;
6285 }
6286
6287 request->duration =
6288 nla_get_u16(info->attrs[NL80211_ATTR_MEASUREMENT_DURATION]);
6289 request->duration_mandatory =
6290 nla_get_flag(info->attrs[NL80211_ATTR_MEASUREMENT_DURATION_MANDATORY]);
6291 }
6292
Sam Leffler46856bb2012-10-11 21:03:32 -07006293 if (info->attrs[NL80211_ATTR_SCAN_FLAGS]) {
Sam Lefflered4737712012-10-11 21:03:31 -07006294 request->flags = nla_get_u32(
6295 info->attrs[NL80211_ATTR_SCAN_FLAGS]);
Johannes Berg00c3a6e2013-10-26 17:14:38 +02006296 if ((request->flags & NL80211_SCAN_FLAG_LOW_PRIORITY) &&
6297 !(wiphy->features & NL80211_FEATURE_LOW_PRIORITY_SCAN)) {
Sam Leffler46856bb2012-10-11 21:03:32 -07006298 err = -EOPNOTSUPP;
6299 goto out_free;
6300 }
Johannes Bergad2b26a2014-06-12 21:39:05 +02006301
6302 if (request->flags & NL80211_SCAN_FLAG_RANDOM_ADDR) {
6303 if (!(wiphy->features &
6304 NL80211_FEATURE_SCAN_RANDOM_MAC_ADDR)) {
6305 err = -EOPNOTSUPP;
6306 goto out_free;
6307 }
6308
6309 if (wdev->current_bss) {
6310 err = -EOPNOTSUPP;
6311 goto out_free;
6312 }
6313
6314 err = nl80211_parse_random_mac(info->attrs,
6315 request->mac_addr,
6316 request->mac_addr_mask);
6317 if (err)
6318 goto out_free;
6319 }
Sam Leffler46856bb2012-10-11 21:03:32 -07006320 }
Sam Lefflered4737712012-10-11 21:03:31 -07006321
Rajkumar Manoharane9f935e2011-09-25 14:53:30 +05306322 request->no_cck =
6323 nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]);
6324
Jouni Malinen818965d2016-02-26 22:12:47 +02006325 if (info->attrs[NL80211_ATTR_MAC])
6326 memcpy(request->bssid, nla_data(info->attrs[NL80211_ATTR_MAC]),
6327 ETH_ALEN);
6328 else
6329 eth_broadcast_addr(request->bssid);
6330
Johannes Bergfd014282012-06-18 19:17:03 +02006331 request->wdev = wdev;
Johannes Berg79c97e92009-07-07 03:56:12 +02006332 request->wiphy = &rdev->wiphy;
Sam Leffler15d60302012-10-11 21:03:34 -07006333 request->scan_start = jiffies;
Johannes Berg2a519312009-02-10 21:25:55 +01006334
Johannes Berg79c97e92009-07-07 03:56:12 +02006335 rdev->scan_req = request;
Hila Gonene35e4d22012-06-27 17:19:42 +03006336 err = rdev_scan(rdev, request);
Johannes Berg2a519312009-02-10 21:25:55 +01006337
Johannes Berg463d0182009-07-14 00:33:35 +02006338 if (!err) {
Johannes Bergfd014282012-06-18 19:17:03 +02006339 nl80211_send_scan_start(rdev, wdev);
6340 if (wdev->netdev)
6341 dev_hold(wdev->netdev);
Johannes Berg4c476992010-10-04 21:36:35 +02006342 } else {
Johannes Berg2a519312009-02-10 21:25:55 +01006343 out_free:
Johannes Berg79c97e92009-07-07 03:56:12 +02006344 rdev->scan_req = NULL;
Johannes Berg2a519312009-02-10 21:25:55 +01006345 kfree(request);
6346 }
Johannes Berg3b858752009-03-12 09:55:09 +01006347
Johannes Bergf9f47522013-03-19 15:04:07 +01006348 unlock:
Johannes Berg2a519312009-02-10 21:25:55 +01006349 return err;
6350}
6351
Vidyullatha Kanchanapally91d3ab42015-10-30 19:14:49 +05306352static int nl80211_abort_scan(struct sk_buff *skb, struct genl_info *info)
6353{
6354 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6355 struct wireless_dev *wdev = info->user_ptr[1];
6356
6357 if (!rdev->ops->abort_scan)
6358 return -EOPNOTSUPP;
6359
6360 if (rdev->scan_msg)
6361 return 0;
6362
6363 if (!rdev->scan_req)
6364 return -ENOENT;
6365
6366 rdev_abort_scan(rdev, wdev);
6367 return 0;
6368}
6369
Avraham Stern3b06d272015-10-12 09:51:34 +03006370static int
6371nl80211_parse_sched_scan_plans(struct wiphy *wiphy, int n_plans,
6372 struct cfg80211_sched_scan_request *request,
6373 struct nlattr **attrs)
6374{
6375 int tmp, err, i = 0;
6376 struct nlattr *attr;
6377
6378 if (!attrs[NL80211_ATTR_SCHED_SCAN_PLANS]) {
6379 u32 interval;
6380
6381 /*
6382 * If scan plans are not specified,
6383 * %NL80211_ATTR_SCHED_SCAN_INTERVAL must be specified. In this
6384 * case one scan plan will be set with the specified scan
6385 * interval and infinite number of iterations.
6386 */
6387 if (!attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL])
6388 return -EINVAL;
6389
6390 interval = nla_get_u32(attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]);
6391 if (!interval)
6392 return -EINVAL;
6393
6394 request->scan_plans[0].interval =
6395 DIV_ROUND_UP(interval, MSEC_PER_SEC);
6396 if (!request->scan_plans[0].interval)
6397 return -EINVAL;
6398
6399 if (request->scan_plans[0].interval >
6400 wiphy->max_sched_scan_plan_interval)
6401 request->scan_plans[0].interval =
6402 wiphy->max_sched_scan_plan_interval;
6403
6404 return 0;
6405 }
6406
6407 nla_for_each_nested(attr, attrs[NL80211_ATTR_SCHED_SCAN_PLANS], tmp) {
6408 struct nlattr *plan[NL80211_SCHED_SCAN_PLAN_MAX + 1];
6409
6410 if (WARN_ON(i >= n_plans))
6411 return -EINVAL;
6412
6413 err = nla_parse(plan, NL80211_SCHED_SCAN_PLAN_MAX,
6414 nla_data(attr), nla_len(attr),
6415 nl80211_plan_policy);
6416 if (err)
6417 return err;
6418
6419 if (!plan[NL80211_SCHED_SCAN_PLAN_INTERVAL])
6420 return -EINVAL;
6421
6422 request->scan_plans[i].interval =
6423 nla_get_u32(plan[NL80211_SCHED_SCAN_PLAN_INTERVAL]);
6424 if (!request->scan_plans[i].interval ||
6425 request->scan_plans[i].interval >
6426 wiphy->max_sched_scan_plan_interval)
6427 return -EINVAL;
6428
6429 if (plan[NL80211_SCHED_SCAN_PLAN_ITERATIONS]) {
6430 request->scan_plans[i].iterations =
6431 nla_get_u32(plan[NL80211_SCHED_SCAN_PLAN_ITERATIONS]);
6432 if (!request->scan_plans[i].iterations ||
6433 (request->scan_plans[i].iterations >
6434 wiphy->max_sched_scan_plan_iterations))
6435 return -EINVAL;
6436 } else if (i < n_plans - 1) {
6437 /*
6438 * All scan plans but the last one must specify
6439 * a finite number of iterations
6440 */
6441 return -EINVAL;
6442 }
6443
6444 i++;
6445 }
6446
6447 /*
6448 * The last scan plan must not specify the number of
6449 * iterations, it is supposed to run infinitely
6450 */
6451 if (request->scan_plans[n_plans - 1].iterations)
6452 return -EINVAL;
6453
6454 return 0;
6455}
6456
Luciano Coelho256da022014-11-10 16:13:46 +02006457static struct cfg80211_sched_scan_request *
Johannes Bergad2b26a2014-06-12 21:39:05 +02006458nl80211_parse_sched_scan(struct wiphy *wiphy, struct wireless_dev *wdev,
Luciano Coelho256da022014-11-10 16:13:46 +02006459 struct nlattr **attrs)
Luciano Coelho807f8a82011-05-11 17:09:35 +03006460{
6461 struct cfg80211_sched_scan_request *request;
Luciano Coelho807f8a82011-05-11 17:09:35 +03006462 struct nlattr *attr;
Avraham Stern3b06d272015-10-12 09:51:34 +03006463 int err, tmp, n_ssids = 0, n_match_sets = 0, n_channels, i, n_plans = 0;
Johannes Berg57fbcce2016-04-12 15:56:15 +02006464 enum nl80211_band band;
Luciano Coelho807f8a82011-05-11 17:09:35 +03006465 size_t ie_len;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03006466 struct nlattr *tb[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1];
Johannes Bergea73cbc2014-01-24 10:53:53 +01006467 s32 default_match_rssi = NL80211_SCAN_RSSI_THOLD_OFF;
Luciano Coelho807f8a82011-05-11 17:09:35 +03006468
Luciano Coelho256da022014-11-10 16:13:46 +02006469 if (!is_valid_ie_attr(attrs[NL80211_ATTR_IE]))
6470 return ERR_PTR(-EINVAL);
Luciano Coelho807f8a82011-05-11 17:09:35 +03006471
Luciano Coelho256da022014-11-10 16:13:46 +02006472 if (attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
Luciano Coelho807f8a82011-05-11 17:09:35 +03006473 n_channels = validate_scan_freqs(
Luciano Coelho256da022014-11-10 16:13:46 +02006474 attrs[NL80211_ATTR_SCAN_FREQUENCIES]);
Luciano Coelho807f8a82011-05-11 17:09:35 +03006475 if (!n_channels)
Luciano Coelho256da022014-11-10 16:13:46 +02006476 return ERR_PTR(-EINVAL);
Luciano Coelho807f8a82011-05-11 17:09:35 +03006477 } else {
Ilan Peerbdfbec22014-01-09 11:37:23 +02006478 n_channels = ieee80211_get_num_supported_channels(wiphy);
Luciano Coelho807f8a82011-05-11 17:09:35 +03006479 }
6480
Luciano Coelho256da022014-11-10 16:13:46 +02006481 if (attrs[NL80211_ATTR_SCAN_SSIDS])
6482 nla_for_each_nested(attr, attrs[NL80211_ATTR_SCAN_SSIDS],
Luciano Coelho807f8a82011-05-11 17:09:35 +03006483 tmp)
6484 n_ssids++;
6485
Luciano Coelho93b6aa62011-07-13 14:57:28 +03006486 if (n_ssids > wiphy->max_sched_scan_ssids)
Luciano Coelho256da022014-11-10 16:13:46 +02006487 return ERR_PTR(-EINVAL);
Luciano Coelho807f8a82011-05-11 17:09:35 +03006488
Johannes Bergea73cbc2014-01-24 10:53:53 +01006489 /*
6490 * First, count the number of 'real' matchsets. Due to an issue with
6491 * the old implementation, matchsets containing only the RSSI attribute
6492 * (NL80211_SCHED_SCAN_MATCH_ATTR_RSSI) are considered as the 'default'
6493 * RSSI for all matchsets, rather than their own matchset for reporting
6494 * all APs with a strong RSSI. This is needed to be compatible with
6495 * older userspace that treated a matchset with only the RSSI as the
6496 * global RSSI for all other matchsets - if there are other matchsets.
6497 */
Luciano Coelho256da022014-11-10 16:13:46 +02006498 if (attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) {
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03006499 nla_for_each_nested(attr,
Luciano Coelho256da022014-11-10 16:13:46 +02006500 attrs[NL80211_ATTR_SCHED_SCAN_MATCH],
Johannes Bergea73cbc2014-01-24 10:53:53 +01006501 tmp) {
6502 struct nlattr *rssi;
6503
6504 err = nla_parse(tb, NL80211_SCHED_SCAN_MATCH_ATTR_MAX,
6505 nla_data(attr), nla_len(attr),
6506 nl80211_match_policy);
6507 if (err)
Luciano Coelho256da022014-11-10 16:13:46 +02006508 return ERR_PTR(err);
Johannes Bergea73cbc2014-01-24 10:53:53 +01006509 /* add other standalone attributes here */
6510 if (tb[NL80211_SCHED_SCAN_MATCH_ATTR_SSID]) {
6511 n_match_sets++;
6512 continue;
6513 }
6514 rssi = tb[NL80211_SCHED_SCAN_MATCH_ATTR_RSSI];
6515 if (rssi)
6516 default_match_rssi = nla_get_s32(rssi);
6517 }
6518 }
6519
6520 /* However, if there's no other matchset, add the RSSI one */
6521 if (!n_match_sets && default_match_rssi != NL80211_SCAN_RSSI_THOLD_OFF)
6522 n_match_sets = 1;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03006523
6524 if (n_match_sets > wiphy->max_match_sets)
Luciano Coelho256da022014-11-10 16:13:46 +02006525 return ERR_PTR(-EINVAL);
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03006526
Luciano Coelho256da022014-11-10 16:13:46 +02006527 if (attrs[NL80211_ATTR_IE])
6528 ie_len = nla_len(attrs[NL80211_ATTR_IE]);
Luciano Coelho807f8a82011-05-11 17:09:35 +03006529 else
6530 ie_len = 0;
6531
Luciano Coelho5a865ba2011-07-13 14:57:29 +03006532 if (ie_len > wiphy->max_sched_scan_ie_len)
Luciano Coelho256da022014-11-10 16:13:46 +02006533 return ERR_PTR(-EINVAL);
Luciano Coelhoc10841c2011-06-30 08:32:41 +03006534
Avraham Stern3b06d272015-10-12 09:51:34 +03006535 if (attrs[NL80211_ATTR_SCHED_SCAN_PLANS]) {
6536 /*
6537 * NL80211_ATTR_SCHED_SCAN_INTERVAL must not be specified since
6538 * each scan plan already specifies its own interval
6539 */
6540 if (attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL])
6541 return ERR_PTR(-EINVAL);
6542
6543 nla_for_each_nested(attr,
6544 attrs[NL80211_ATTR_SCHED_SCAN_PLANS], tmp)
6545 n_plans++;
6546 } else {
6547 /*
6548 * The scan interval attribute is kept for backward
6549 * compatibility. If no scan plans are specified and sched scan
6550 * interval is specified, one scan plan will be set with this
6551 * scan interval and infinite number of iterations.
6552 */
6553 if (!attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL])
6554 return ERR_PTR(-EINVAL);
6555
6556 n_plans = 1;
6557 }
6558
6559 if (!n_plans || n_plans > wiphy->max_sched_scan_plans)
6560 return ERR_PTR(-EINVAL);
6561
Luciano Coelho807f8a82011-05-11 17:09:35 +03006562 request = kzalloc(sizeof(*request)
Luciano Coelhoa2cd43c2011-05-18 11:42:03 +03006563 + sizeof(*request->ssids) * n_ssids
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03006564 + sizeof(*request->match_sets) * n_match_sets
Avraham Stern3b06d272015-10-12 09:51:34 +03006565 + sizeof(*request->scan_plans) * n_plans
Luciano Coelhoa2cd43c2011-05-18 11:42:03 +03006566 + sizeof(*request->channels) * n_channels
Luciano Coelho807f8a82011-05-11 17:09:35 +03006567 + ie_len, GFP_KERNEL);
Luciano Coelho256da022014-11-10 16:13:46 +02006568 if (!request)
6569 return ERR_PTR(-ENOMEM);
Luciano Coelho807f8a82011-05-11 17:09:35 +03006570
6571 if (n_ssids)
6572 request->ssids = (void *)&request->channels[n_channels];
6573 request->n_ssids = n_ssids;
6574 if (ie_len) {
Johannes Berg13874e42015-01-23 11:25:20 +01006575 if (n_ssids)
Luciano Coelho807f8a82011-05-11 17:09:35 +03006576 request->ie = (void *)(request->ssids + n_ssids);
6577 else
6578 request->ie = (void *)(request->channels + n_channels);
6579 }
6580
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03006581 if (n_match_sets) {
6582 if (request->ie)
6583 request->match_sets = (void *)(request->ie + ie_len);
Johannes Berg13874e42015-01-23 11:25:20 +01006584 else if (n_ssids)
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03006585 request->match_sets =
6586 (void *)(request->ssids + n_ssids);
6587 else
6588 request->match_sets =
6589 (void *)(request->channels + n_channels);
6590 }
6591 request->n_match_sets = n_match_sets;
6592
Avraham Stern3b06d272015-10-12 09:51:34 +03006593 if (n_match_sets)
6594 request->scan_plans = (void *)(request->match_sets +
6595 n_match_sets);
6596 else if (request->ie)
6597 request->scan_plans = (void *)(request->ie + ie_len);
6598 else if (n_ssids)
6599 request->scan_plans = (void *)(request->ssids + n_ssids);
6600 else
6601 request->scan_plans = (void *)(request->channels + n_channels);
6602
6603 request->n_scan_plans = n_plans;
6604
Luciano Coelho807f8a82011-05-11 17:09:35 +03006605 i = 0;
Luciano Coelho256da022014-11-10 16:13:46 +02006606 if (attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
Luciano Coelho807f8a82011-05-11 17:09:35 +03006607 /* user specified, bail out if channel not found */
6608 nla_for_each_nested(attr,
Luciano Coelho256da022014-11-10 16:13:46 +02006609 attrs[NL80211_ATTR_SCAN_FREQUENCIES],
Luciano Coelho807f8a82011-05-11 17:09:35 +03006610 tmp) {
6611 struct ieee80211_channel *chan;
6612
6613 chan = ieee80211_get_channel(wiphy, nla_get_u32(attr));
6614
6615 if (!chan) {
6616 err = -EINVAL;
6617 goto out_free;
6618 }
6619
6620 /* ignore disabled channels */
6621 if (chan->flags & IEEE80211_CHAN_DISABLED)
6622 continue;
6623
6624 request->channels[i] = chan;
6625 i++;
6626 }
6627 } else {
6628 /* all channels */
Johannes Berg57fbcce2016-04-12 15:56:15 +02006629 for (band = 0; band < NUM_NL80211_BANDS; band++) {
Luciano Coelho807f8a82011-05-11 17:09:35 +03006630 int j;
Kirtika Ruchandani7a087e72016-05-29 19:51:23 -07006631
Luciano Coelho807f8a82011-05-11 17:09:35 +03006632 if (!wiphy->bands[band])
6633 continue;
6634 for (j = 0; j < wiphy->bands[band]->n_channels; j++) {
6635 struct ieee80211_channel *chan;
6636
6637 chan = &wiphy->bands[band]->channels[j];
6638
6639 if (chan->flags & IEEE80211_CHAN_DISABLED)
6640 continue;
6641
6642 request->channels[i] = chan;
6643 i++;
6644 }
6645 }
6646 }
6647
6648 if (!i) {
6649 err = -EINVAL;
6650 goto out_free;
6651 }
6652
6653 request->n_channels = i;
6654
6655 i = 0;
Johannes Berg13874e42015-01-23 11:25:20 +01006656 if (n_ssids) {
Luciano Coelho256da022014-11-10 16:13:46 +02006657 nla_for_each_nested(attr, attrs[NL80211_ATTR_SCAN_SSIDS],
Luciano Coelho807f8a82011-05-11 17:09:35 +03006658 tmp) {
Luciano Coelho57a27e12011-06-07 20:42:26 +03006659 if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) {
Luciano Coelho807f8a82011-05-11 17:09:35 +03006660 err = -EINVAL;
6661 goto out_free;
6662 }
Luciano Coelho57a27e12011-06-07 20:42:26 +03006663 request->ssids[i].ssid_len = nla_len(attr);
Luciano Coelho807f8a82011-05-11 17:09:35 +03006664 memcpy(request->ssids[i].ssid, nla_data(attr),
6665 nla_len(attr));
Luciano Coelho807f8a82011-05-11 17:09:35 +03006666 i++;
6667 }
6668 }
6669
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03006670 i = 0;
Luciano Coelho256da022014-11-10 16:13:46 +02006671 if (attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) {
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03006672 nla_for_each_nested(attr,
Luciano Coelho256da022014-11-10 16:13:46 +02006673 attrs[NL80211_ATTR_SCHED_SCAN_MATCH],
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03006674 tmp) {
Thomas Pedersen88e920b2012-06-21 11:09:54 -07006675 struct nlattr *ssid, *rssi;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03006676
Johannes Bergae811e22014-01-24 10:17:47 +01006677 err = nla_parse(tb, NL80211_SCHED_SCAN_MATCH_ATTR_MAX,
6678 nla_data(attr), nla_len(attr),
6679 nl80211_match_policy);
6680 if (err)
6681 goto out_free;
Johannes Berg4a4ab0d2012-06-13 11:17:11 +02006682 ssid = tb[NL80211_SCHED_SCAN_MATCH_ATTR_SSID];
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03006683 if (ssid) {
Johannes Bergea73cbc2014-01-24 10:53:53 +01006684 if (WARN_ON(i >= n_match_sets)) {
6685 /* this indicates a programming error,
6686 * the loop above should have verified
6687 * things properly
6688 */
6689 err = -EINVAL;
6690 goto out_free;
6691 }
6692
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03006693 if (nla_len(ssid) > IEEE80211_MAX_SSID_LEN) {
6694 err = -EINVAL;
6695 goto out_free;
6696 }
6697 memcpy(request->match_sets[i].ssid.ssid,
6698 nla_data(ssid), nla_len(ssid));
6699 request->match_sets[i].ssid.ssid_len =
6700 nla_len(ssid);
Kirtika Ruchandani56ab3642016-05-29 19:54:10 -07006701 /* special attribute - old implementation w/a */
Johannes Bergea73cbc2014-01-24 10:53:53 +01006702 request->match_sets[i].rssi_thold =
6703 default_match_rssi;
6704 rssi = tb[NL80211_SCHED_SCAN_MATCH_ATTR_RSSI];
6705 if (rssi)
6706 request->match_sets[i].rssi_thold =
6707 nla_get_s32(rssi);
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03006708 }
6709 i++;
6710 }
Johannes Bergea73cbc2014-01-24 10:53:53 +01006711
6712 /* there was no other matchset, so the RSSI one is alone */
Luciano Coelhof89f46c2014-12-01 11:32:09 +02006713 if (i == 0 && n_match_sets)
Johannes Bergea73cbc2014-01-24 10:53:53 +01006714 request->match_sets[0].rssi_thold = default_match_rssi;
6715
6716 request->min_rssi_thold = INT_MAX;
6717 for (i = 0; i < n_match_sets; i++)
6718 request->min_rssi_thold =
6719 min(request->match_sets[i].rssi_thold,
6720 request->min_rssi_thold);
6721 } else {
6722 request->min_rssi_thold = NL80211_SCAN_RSSI_THOLD_OFF;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03006723 }
6724
Johannes Berg9900e482014-02-04 21:01:25 +01006725 if (ie_len) {
6726 request->ie_len = ie_len;
Luciano Coelho807f8a82011-05-11 17:09:35 +03006727 memcpy((void *)request->ie,
Luciano Coelho256da022014-11-10 16:13:46 +02006728 nla_data(attrs[NL80211_ATTR_IE]),
Luciano Coelho807f8a82011-05-11 17:09:35 +03006729 request->ie_len);
6730 }
6731
Luciano Coelho256da022014-11-10 16:13:46 +02006732 if (attrs[NL80211_ATTR_SCAN_FLAGS]) {
Sam Lefflered4737712012-10-11 21:03:31 -07006733 request->flags = nla_get_u32(
Luciano Coelho256da022014-11-10 16:13:46 +02006734 attrs[NL80211_ATTR_SCAN_FLAGS]);
Johannes Berg00c3a6e2013-10-26 17:14:38 +02006735 if ((request->flags & NL80211_SCAN_FLAG_LOW_PRIORITY) &&
6736 !(wiphy->features & NL80211_FEATURE_LOW_PRIORITY_SCAN)) {
Sam Leffler46856bb2012-10-11 21:03:32 -07006737 err = -EOPNOTSUPP;
6738 goto out_free;
6739 }
Johannes Bergad2b26a2014-06-12 21:39:05 +02006740
6741 if (request->flags & NL80211_SCAN_FLAG_RANDOM_ADDR) {
6742 u32 flg = NL80211_FEATURE_SCHED_SCAN_RANDOM_MAC_ADDR;
6743
6744 if (!wdev) /* must be net-detect */
6745 flg = NL80211_FEATURE_ND_RANDOM_MAC_ADDR;
6746
6747 if (!(wiphy->features & flg)) {
6748 err = -EOPNOTSUPP;
6749 goto out_free;
6750 }
6751
6752 if (wdev && wdev->current_bss) {
6753 err = -EOPNOTSUPP;
6754 goto out_free;
6755 }
6756
6757 err = nl80211_parse_random_mac(attrs, request->mac_addr,
6758 request->mac_addr_mask);
6759 if (err)
6760 goto out_free;
6761 }
Sam Leffler46856bb2012-10-11 21:03:32 -07006762 }
Sam Lefflered4737712012-10-11 21:03:31 -07006763
Luciano Coelho9c748932015-01-16 16:04:09 +02006764 if (attrs[NL80211_ATTR_SCHED_SCAN_DELAY])
6765 request->delay =
6766 nla_get_u32(attrs[NL80211_ATTR_SCHED_SCAN_DELAY]);
6767
Avraham Stern3b06d272015-10-12 09:51:34 +03006768 err = nl80211_parse_sched_scan_plans(wiphy, n_plans, request, attrs);
6769 if (err)
6770 goto out_free;
6771
Sam Leffler15d60302012-10-11 21:03:34 -07006772 request->scan_start = jiffies;
Luciano Coelho807f8a82011-05-11 17:09:35 +03006773
Luciano Coelho256da022014-11-10 16:13:46 +02006774 return request;
Luciano Coelho807f8a82011-05-11 17:09:35 +03006775
6776out_free:
6777 kfree(request);
Luciano Coelho256da022014-11-10 16:13:46 +02006778 return ERR_PTR(err);
6779}
6780
6781static int nl80211_start_sched_scan(struct sk_buff *skb,
6782 struct genl_info *info)
6783{
6784 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6785 struct net_device *dev = info->user_ptr[1];
Johannes Bergad2b26a2014-06-12 21:39:05 +02006786 struct wireless_dev *wdev = dev->ieee80211_ptr;
Jukka Rissanen31a60ed2014-12-15 13:25:38 +02006787 struct cfg80211_sched_scan_request *sched_scan_req;
Luciano Coelho256da022014-11-10 16:13:46 +02006788 int err;
6789
6790 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) ||
6791 !rdev->ops->sched_scan_start)
6792 return -EOPNOTSUPP;
6793
6794 if (rdev->sched_scan_req)
6795 return -EINPROGRESS;
6796
Jukka Rissanen31a60ed2014-12-15 13:25:38 +02006797 sched_scan_req = nl80211_parse_sched_scan(&rdev->wiphy, wdev,
6798 info->attrs);
6799
6800 err = PTR_ERR_OR_ZERO(sched_scan_req);
Luciano Coelho256da022014-11-10 16:13:46 +02006801 if (err)
6802 goto out_err;
6803
Jukka Rissanen31a60ed2014-12-15 13:25:38 +02006804 err = rdev_sched_scan_start(rdev, dev, sched_scan_req);
Luciano Coelho256da022014-11-10 16:13:46 +02006805 if (err)
6806 goto out_free;
6807
Jukka Rissanen31a60ed2014-12-15 13:25:38 +02006808 sched_scan_req->dev = dev;
6809 sched_scan_req->wiphy = &rdev->wiphy;
6810
Jukka Rissanen93a1e862014-12-15 13:25:39 +02006811 if (info->attrs[NL80211_ATTR_SOCKET_OWNER])
6812 sched_scan_req->owner_nlportid = info->snd_portid;
6813
Jukka Rissanen31a60ed2014-12-15 13:25:38 +02006814 rcu_assign_pointer(rdev->sched_scan_req, sched_scan_req);
Luciano Coelho256da022014-11-10 16:13:46 +02006815
6816 nl80211_send_sched_scan(rdev, dev,
6817 NL80211_CMD_START_SCHED_SCAN);
6818 return 0;
6819
6820out_free:
Jukka Rissanen31a60ed2014-12-15 13:25:38 +02006821 kfree(sched_scan_req);
Luciano Coelho256da022014-11-10 16:13:46 +02006822out_err:
Luciano Coelho807f8a82011-05-11 17:09:35 +03006823 return err;
6824}
6825
6826static int nl80211_stop_sched_scan(struct sk_buff *skb,
6827 struct genl_info *info)
6828{
6829 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6830
6831 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) ||
6832 !rdev->ops->sched_scan_stop)
6833 return -EOPNOTSUPP;
6834
Johannes Berg5fe231e2013-05-08 21:45:15 +02006835 return __cfg80211_stop_sched_scan(rdev, false);
Luciano Coelho807f8a82011-05-11 17:09:35 +03006836}
6837
Simon Wunderlich04f39042013-02-08 18:16:19 +01006838static int nl80211_start_radar_detection(struct sk_buff *skb,
6839 struct genl_info *info)
6840{
6841 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6842 struct net_device *dev = info->user_ptr[1];
6843 struct wireless_dev *wdev = dev->ieee80211_ptr;
6844 struct cfg80211_chan_def chandef;
Luis R. Rodriguez55f74352013-11-25 20:56:10 +01006845 enum nl80211_dfs_regions dfs_region;
Janusz Dziedzic31559f32014-02-21 19:46:13 +01006846 unsigned int cac_time_ms;
Simon Wunderlich04f39042013-02-08 18:16:19 +01006847 int err;
6848
Luis R. Rodriguez55f74352013-11-25 20:56:10 +01006849 dfs_region = reg_get_dfs_region(wdev->wiphy);
6850 if (dfs_region == NL80211_DFS_UNSET)
6851 return -EINVAL;
6852
Simon Wunderlich04f39042013-02-08 18:16:19 +01006853 err = nl80211_parse_chandef(rdev, info, &chandef);
6854 if (err)
6855 return err;
6856
Simon Wunderlichff311bc2013-09-03 19:43:18 +02006857 if (netif_carrier_ok(dev))
6858 return -EBUSY;
6859
Simon Wunderlich04f39042013-02-08 18:16:19 +01006860 if (wdev->cac_started)
6861 return -EBUSY;
6862
Luciano Coelho2beb6dab2014-02-18 11:40:36 +02006863 err = cfg80211_chandef_dfs_required(wdev->wiphy, &chandef,
Luciano Coelho00ec75f2014-05-15 13:05:39 +03006864 wdev->iftype);
Simon Wunderlich04f39042013-02-08 18:16:19 +01006865 if (err < 0)
6866 return err;
6867
6868 if (err == 0)
6869 return -EINVAL;
6870
Janusz Dziedzicfe7c3a12013-11-05 14:48:48 +01006871 if (!cfg80211_chandef_dfs_usable(wdev->wiphy, &chandef))
Simon Wunderlich04f39042013-02-08 18:16:19 +01006872 return -EINVAL;
6873
6874 if (!rdev->ops->start_radar_detection)
6875 return -EOPNOTSUPP;
6876
Janusz Dziedzic31559f32014-02-21 19:46:13 +01006877 cac_time_ms = cfg80211_chandef_dfs_cac_time(&rdev->wiphy, &chandef);
6878 if (WARN_ON(!cac_time_ms))
6879 cac_time_ms = IEEE80211_DFS_MIN_CAC_TIME_MS;
6880
Ilan Peera1056b12015-10-22 22:27:46 +03006881 err = rdev_start_radar_detection(rdev, dev, &chandef, cac_time_ms);
Simon Wunderlich04f39042013-02-08 18:16:19 +01006882 if (!err) {
Michal Kazior9e0e2962014-01-29 14:22:27 +01006883 wdev->chandef = chandef;
Simon Wunderlich04f39042013-02-08 18:16:19 +01006884 wdev->cac_started = true;
6885 wdev->cac_start_time = jiffies;
Janusz Dziedzic31559f32014-02-21 19:46:13 +01006886 wdev->cac_time_ms = cac_time_ms;
Simon Wunderlich04f39042013-02-08 18:16:19 +01006887 }
Simon Wunderlich04f39042013-02-08 18:16:19 +01006888 return err;
6889}
6890
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006891static int nl80211_channel_switch(struct sk_buff *skb, struct genl_info *info)
6892{
6893 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6894 struct net_device *dev = info->user_ptr[1];
6895 struct wireless_dev *wdev = dev->ieee80211_ptr;
6896 struct cfg80211_csa_settings params;
6897 /* csa_attrs is defined static to avoid waste of stack size - this
6898 * function is called under RTNL lock, so this should not be a problem.
6899 */
6900 static struct nlattr *csa_attrs[NL80211_ATTR_MAX+1];
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006901 int err;
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02006902 bool need_new_beacon = false;
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03006903 int len, i;
Luciano Coelho252e07c2014-10-08 09:48:34 +03006904 u32 cs_count;
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006905
6906 if (!rdev->ops->channel_switch ||
6907 !(rdev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH))
6908 return -EOPNOTSUPP;
6909
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02006910 switch (dev->ieee80211_ptr->iftype) {
6911 case NL80211_IFTYPE_AP:
6912 case NL80211_IFTYPE_P2P_GO:
6913 need_new_beacon = true;
6914
6915 /* useless if AP is not running */
6916 if (!wdev->beacon_interval)
Johannes Berg1ff79df2014-01-22 10:05:27 +01006917 return -ENOTCONN;
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02006918 break;
6919 case NL80211_IFTYPE_ADHOC:
Johannes Berg1ff79df2014-01-22 10:05:27 +01006920 if (!wdev->ssid_len)
6921 return -ENOTCONN;
6922 break;
Chun-Yeow Yeohc6da6742013-10-14 19:08:28 -07006923 case NL80211_IFTYPE_MESH_POINT:
Johannes Berg1ff79df2014-01-22 10:05:27 +01006924 if (!wdev->mesh_id_len)
6925 return -ENOTCONN;
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02006926 break;
6927 default:
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006928 return -EOPNOTSUPP;
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02006929 }
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006930
6931 memset(&params, 0, sizeof(params));
6932
6933 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] ||
6934 !info->attrs[NL80211_ATTR_CH_SWITCH_COUNT])
6935 return -EINVAL;
6936
6937 /* only important for AP, IBSS and mesh create IEs internally */
Andrei Otcheretianskid0a361a2013-10-17 10:52:17 +02006938 if (need_new_beacon && !info->attrs[NL80211_ATTR_CSA_IES])
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006939 return -EINVAL;
6940
Luciano Coelho252e07c2014-10-08 09:48:34 +03006941 /* Even though the attribute is u32, the specification says
6942 * u8, so let's make sure we don't overflow.
6943 */
6944 cs_count = nla_get_u32(info->attrs[NL80211_ATTR_CH_SWITCH_COUNT]);
6945 if (cs_count > 255)
6946 return -EINVAL;
6947
6948 params.count = cs_count;
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006949
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02006950 if (!need_new_beacon)
6951 goto skip_beacons;
6952
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006953 err = nl80211_parse_beacon(info->attrs, &params.beacon_after);
6954 if (err)
6955 return err;
6956
6957 err = nla_parse_nested(csa_attrs, NL80211_ATTR_MAX,
6958 info->attrs[NL80211_ATTR_CSA_IES],
6959 nl80211_policy);
6960 if (err)
6961 return err;
6962
6963 err = nl80211_parse_beacon(csa_attrs, &params.beacon_csa);
6964 if (err)
6965 return err;
6966
6967 if (!csa_attrs[NL80211_ATTR_CSA_C_OFF_BEACON])
6968 return -EINVAL;
6969
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03006970 len = nla_len(csa_attrs[NL80211_ATTR_CSA_C_OFF_BEACON]);
6971 if (!len || (len % sizeof(u16)))
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006972 return -EINVAL;
6973
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03006974 params.n_counter_offsets_beacon = len / sizeof(u16);
6975 if (rdev->wiphy.max_num_csa_counters &&
6976 (params.n_counter_offsets_beacon >
6977 rdev->wiphy.max_num_csa_counters))
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006978 return -EINVAL;
6979
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03006980 params.counter_offsets_beacon =
6981 nla_data(csa_attrs[NL80211_ATTR_CSA_C_OFF_BEACON]);
6982
6983 /* sanity checks - counters should fit and be the same */
6984 for (i = 0; i < params.n_counter_offsets_beacon; i++) {
6985 u16 offset = params.counter_offsets_beacon[i];
6986
6987 if (offset >= params.beacon_csa.tail_len)
6988 return -EINVAL;
6989
6990 if (params.beacon_csa.tail[offset] != params.count)
6991 return -EINVAL;
6992 }
6993
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006994 if (csa_attrs[NL80211_ATTR_CSA_C_OFF_PRESP]) {
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03006995 len = nla_len(csa_attrs[NL80211_ATTR_CSA_C_OFF_PRESP]);
6996 if (!len || (len % sizeof(u16)))
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006997 return -EINVAL;
6998
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03006999 params.n_counter_offsets_presp = len / sizeof(u16);
7000 if (rdev->wiphy.max_num_csa_counters &&
7001 (params.n_counter_offsets_beacon >
7002 rdev->wiphy.max_num_csa_counters))
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02007003 return -EINVAL;
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03007004
7005 params.counter_offsets_presp =
7006 nla_data(csa_attrs[NL80211_ATTR_CSA_C_OFF_PRESP]);
7007
7008 /* sanity checks - counters should fit and be the same */
7009 for (i = 0; i < params.n_counter_offsets_presp; i++) {
7010 u16 offset = params.counter_offsets_presp[i];
7011
7012 if (offset >= params.beacon_csa.probe_resp_len)
7013 return -EINVAL;
7014
7015 if (params.beacon_csa.probe_resp[offset] !=
7016 params.count)
7017 return -EINVAL;
7018 }
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02007019 }
7020
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02007021skip_beacons:
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02007022 err = nl80211_parse_chandef(rdev, info, &params.chandef);
7023 if (err)
7024 return err;
7025
Arik Nemtsov923b3522015-07-08 15:41:44 +03007026 if (!cfg80211_reg_can_beacon_relax(&rdev->wiphy, &params.chandef,
7027 wdev->iftype))
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02007028 return -EINVAL;
7029
Luciano Coelho2beb6dab2014-02-18 11:40:36 +02007030 err = cfg80211_chandef_dfs_required(wdev->wiphy,
7031 &params.chandef,
7032 wdev->iftype);
7033 if (err < 0)
7034 return err;
7035
Fabian Frederickdcc6c2f2014-10-25 17:57:35 +02007036 if (err > 0)
Luciano Coelho2beb6dab2014-02-18 11:40:36 +02007037 params.radar_required = true;
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02007038
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02007039 if (info->attrs[NL80211_ATTR_CH_SWITCH_BLOCK_TX])
7040 params.block_tx = true;
7041
Simon Wunderlichc56589e2013-11-21 18:19:49 +01007042 wdev_lock(wdev);
7043 err = rdev_channel_switch(rdev, dev, &params);
7044 wdev_unlock(wdev);
7045
7046 return err;
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02007047}
7048
Johannes Berg9720bb32011-06-21 09:45:33 +02007049static int nl80211_send_bss(struct sk_buff *msg, struct netlink_callback *cb,
7050 u32 seq, int flags,
Johannes Berg2a519312009-02-10 21:25:55 +01007051 struct cfg80211_registered_device *rdev,
Johannes Berg48ab9052009-07-10 18:42:31 +02007052 struct wireless_dev *wdev,
7053 struct cfg80211_internal_bss *intbss)
Johannes Berg2a519312009-02-10 21:25:55 +01007054{
Johannes Berg48ab9052009-07-10 18:42:31 +02007055 struct cfg80211_bss *res = &intbss->pub;
Johannes Berg9caf0362012-11-29 01:25:20 +01007056 const struct cfg80211_bss_ies *ies;
Johannes Berg2a519312009-02-10 21:25:55 +01007057 void *hdr;
7058 struct nlattr *bss;
Johannes Berg48ab9052009-07-10 18:42:31 +02007059
7060 ASSERT_WDEV_LOCK(wdev);
Johannes Berg2a519312009-02-10 21:25:55 +01007061
Eric W. Biederman15e47302012-09-07 20:12:54 +00007062 hdr = nl80211hdr_put(msg, NETLINK_CB(cb->skb).portid, seq, flags,
Johannes Berg2a519312009-02-10 21:25:55 +01007063 NL80211_CMD_NEW_SCAN_RESULTS);
7064 if (!hdr)
7065 return -1;
7066
Johannes Berg9720bb32011-06-21 09:45:33 +02007067 genl_dump_check_consistent(cb, hdr, &nl80211_fam);
7068
Johannes Berg97990a02013-04-19 01:02:55 +02007069 if (nla_put_u32(msg, NL80211_ATTR_GENERATION, rdev->bss_generation))
7070 goto nla_put_failure;
7071 if (wdev->netdev &&
David S. Miller9360ffd2012-03-29 04:41:26 -04007072 nla_put_u32(msg, NL80211_ATTR_IFINDEX, wdev->netdev->ifindex))
7073 goto nla_put_failure;
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02007074 if (nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
7075 NL80211_ATTR_PAD))
Johannes Berg97990a02013-04-19 01:02:55 +02007076 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01007077
7078 bss = nla_nest_start(msg, NL80211_ATTR_BSS);
7079 if (!bss)
7080 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04007081 if ((!is_zero_ether_addr(res->bssid) &&
Johannes Berg9caf0362012-11-29 01:25:20 +01007082 nla_put(msg, NL80211_BSS_BSSID, ETH_ALEN, res->bssid)))
David S. Miller9360ffd2012-03-29 04:41:26 -04007083 goto nla_put_failure;
Johannes Berg9caf0362012-11-29 01:25:20 +01007084
7085 rcu_read_lock();
Johannes Berg0e227082014-08-12 20:34:30 +02007086 /* indicate whether we have probe response data or not */
7087 if (rcu_access_pointer(res->proberesp_ies) &&
7088 nla_put_flag(msg, NL80211_BSS_PRESP_DATA))
7089 goto fail_unlock_rcu;
7090
7091 /* this pointer prefers to be pointed to probe response data
7092 * but is always valid
7093 */
Johannes Berg9caf0362012-11-29 01:25:20 +01007094 ies = rcu_dereference(res->ies);
Johannes Berg8cef2c92013-02-05 16:54:31 +01007095 if (ies) {
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02007096 if (nla_put_u64_64bit(msg, NL80211_BSS_TSF, ies->tsf,
7097 NL80211_BSS_PAD))
Johannes Berg8cef2c92013-02-05 16:54:31 +01007098 goto fail_unlock_rcu;
Johannes Berg8cef2c92013-02-05 16:54:31 +01007099 if (ies->len && nla_put(msg, NL80211_BSS_INFORMATION_ELEMENTS,
7100 ies->len, ies->data))
7101 goto fail_unlock_rcu;
Johannes Berg9caf0362012-11-29 01:25:20 +01007102 }
Johannes Berg0e227082014-08-12 20:34:30 +02007103
7104 /* and this pointer is always (unless driver didn't know) beacon data */
Johannes Berg9caf0362012-11-29 01:25:20 +01007105 ies = rcu_dereference(res->beacon_ies);
Johannes Berg0e227082014-08-12 20:34:30 +02007106 if (ies && ies->from_beacon) {
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02007107 if (nla_put_u64_64bit(msg, NL80211_BSS_BEACON_TSF, ies->tsf,
7108 NL80211_BSS_PAD))
Johannes Berg8cef2c92013-02-05 16:54:31 +01007109 goto fail_unlock_rcu;
7110 if (ies->len && nla_put(msg, NL80211_BSS_BEACON_IES,
7111 ies->len, ies->data))
7112 goto fail_unlock_rcu;
Johannes Berg9caf0362012-11-29 01:25:20 +01007113 }
7114 rcu_read_unlock();
7115
David S. Miller9360ffd2012-03-29 04:41:26 -04007116 if (res->beacon_interval &&
7117 nla_put_u16(msg, NL80211_BSS_BEACON_INTERVAL, res->beacon_interval))
7118 goto nla_put_failure;
7119 if (nla_put_u16(msg, NL80211_BSS_CAPABILITY, res->capability) ||
7120 nla_put_u32(msg, NL80211_BSS_FREQUENCY, res->channel->center_freq) ||
Simon Wunderlichdcd6eac2013-07-08 16:55:49 +02007121 nla_put_u32(msg, NL80211_BSS_CHAN_WIDTH, res->scan_width) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04007122 nla_put_u32(msg, NL80211_BSS_SEEN_MS_AGO,
7123 jiffies_to_msecs(jiffies - intbss->ts)))
7124 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01007125
Avraham Stern1d762502016-07-05 17:10:13 +03007126 if (intbss->parent_tsf &&
7127 (nla_put_u64_64bit(msg, NL80211_BSS_PARENT_TSF,
7128 intbss->parent_tsf, NL80211_BSS_PAD) ||
7129 nla_put(msg, NL80211_BSS_PARENT_BSSID, ETH_ALEN,
7130 intbss->parent_bssid)))
7131 goto nla_put_failure;
7132
Dmitry Shmidt6e19bc42015-10-07 11:32:53 +02007133 if (intbss->ts_boottime &&
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02007134 nla_put_u64_64bit(msg, NL80211_BSS_LAST_SEEN_BOOTTIME,
7135 intbss->ts_boottime, NL80211_BSS_PAD))
Dmitry Shmidt6e19bc42015-10-07 11:32:53 +02007136 goto nla_put_failure;
7137
Johannes Berg77965c92009-02-18 18:45:06 +01007138 switch (rdev->wiphy.signal_type) {
Johannes Berg2a519312009-02-10 21:25:55 +01007139 case CFG80211_SIGNAL_TYPE_MBM:
David S. Miller9360ffd2012-03-29 04:41:26 -04007140 if (nla_put_u32(msg, NL80211_BSS_SIGNAL_MBM, res->signal))
7141 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01007142 break;
7143 case CFG80211_SIGNAL_TYPE_UNSPEC:
David S. Miller9360ffd2012-03-29 04:41:26 -04007144 if (nla_put_u8(msg, NL80211_BSS_SIGNAL_UNSPEC, res->signal))
7145 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01007146 break;
7147 default:
7148 break;
7149 }
7150
Johannes Berg48ab9052009-07-10 18:42:31 +02007151 switch (wdev->iftype) {
Johannes Berg074ac8d2010-09-16 14:58:22 +02007152 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Berg48ab9052009-07-10 18:42:31 +02007153 case NL80211_IFTYPE_STATION:
David S. Miller9360ffd2012-03-29 04:41:26 -04007154 if (intbss == wdev->current_bss &&
7155 nla_put_u32(msg, NL80211_BSS_STATUS,
7156 NL80211_BSS_STATUS_ASSOCIATED))
7157 goto nla_put_failure;
Johannes Berg48ab9052009-07-10 18:42:31 +02007158 break;
7159 case NL80211_IFTYPE_ADHOC:
David S. Miller9360ffd2012-03-29 04:41:26 -04007160 if (intbss == wdev->current_bss &&
7161 nla_put_u32(msg, NL80211_BSS_STATUS,
7162 NL80211_BSS_STATUS_IBSS_JOINED))
7163 goto nla_put_failure;
Johannes Berg48ab9052009-07-10 18:42:31 +02007164 break;
7165 default:
7166 break;
7167 }
7168
Johannes Berg2a519312009-02-10 21:25:55 +01007169 nla_nest_end(msg, bss);
7170
Johannes Berg053c0952015-01-16 22:09:00 +01007171 genlmsg_end(msg, hdr);
7172 return 0;
Johannes Berg2a519312009-02-10 21:25:55 +01007173
Johannes Berg8cef2c92013-02-05 16:54:31 +01007174 fail_unlock_rcu:
7175 rcu_read_unlock();
Johannes Berg2a519312009-02-10 21:25:55 +01007176 nla_put_failure:
7177 genlmsg_cancel(msg, hdr);
7178 return -EMSGSIZE;
7179}
7180
Johannes Berg97990a02013-04-19 01:02:55 +02007181static int nl80211_dump_scan(struct sk_buff *skb, struct netlink_callback *cb)
Johannes Berg2a519312009-02-10 21:25:55 +01007182{
Johannes Berg48ab9052009-07-10 18:42:31 +02007183 struct cfg80211_registered_device *rdev;
Johannes Berg2a519312009-02-10 21:25:55 +01007184 struct cfg80211_internal_bss *scan;
Johannes Berg48ab9052009-07-10 18:42:31 +02007185 struct wireless_dev *wdev;
Johannes Berg97990a02013-04-19 01:02:55 +02007186 int start = cb->args[2], idx = 0;
Johannes Berg2a519312009-02-10 21:25:55 +01007187 int err;
7188
Johannes Berg97990a02013-04-19 01:02:55 +02007189 err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev);
Johannes Berg67748892010-10-04 21:14:06 +02007190 if (err)
7191 return err;
Johannes Berg2a519312009-02-10 21:25:55 +01007192
Johannes Berg48ab9052009-07-10 18:42:31 +02007193 wdev_lock(wdev);
7194 spin_lock_bh(&rdev->bss_lock);
7195 cfg80211_bss_expire(rdev);
7196
Johannes Berg9720bb32011-06-21 09:45:33 +02007197 cb->seq = rdev->bss_generation;
7198
Johannes Berg48ab9052009-07-10 18:42:31 +02007199 list_for_each_entry(scan, &rdev->bss_list, list) {
Johannes Berg2a519312009-02-10 21:25:55 +01007200 if (++idx <= start)
7201 continue;
Johannes Berg9720bb32011-06-21 09:45:33 +02007202 if (nl80211_send_bss(skb, cb,
Johannes Berg2a519312009-02-10 21:25:55 +01007203 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Johannes Berg48ab9052009-07-10 18:42:31 +02007204 rdev, wdev, scan) < 0) {
Johannes Berg2a519312009-02-10 21:25:55 +01007205 idx--;
Johannes Berg67748892010-10-04 21:14:06 +02007206 break;
Johannes Berg2a519312009-02-10 21:25:55 +01007207 }
7208 }
7209
Johannes Berg48ab9052009-07-10 18:42:31 +02007210 spin_unlock_bh(&rdev->bss_lock);
7211 wdev_unlock(wdev);
Johannes Berg2a519312009-02-10 21:25:55 +01007212
Johannes Berg97990a02013-04-19 01:02:55 +02007213 cb->args[2] = idx;
7214 nl80211_finish_wdev_dump(rdev);
Johannes Berg2a519312009-02-10 21:25:55 +01007215
Johannes Berg67748892010-10-04 21:14:06 +02007216 return skb->len;
Johannes Berg2a519312009-02-10 21:25:55 +01007217}
7218
Eric W. Biederman15e47302012-09-07 20:12:54 +00007219static int nl80211_send_survey(struct sk_buff *msg, u32 portid, u32 seq,
Johannes Berg11f78ac2014-11-14 16:43:50 +01007220 int flags, struct net_device *dev,
7221 bool allow_radio_stats,
7222 struct survey_info *survey)
Holger Schurig61fa7132009-11-11 12:25:40 +01007223{
7224 void *hdr;
7225 struct nlattr *infoattr;
7226
Johannes Berg11f78ac2014-11-14 16:43:50 +01007227 /* skip radio stats if userspace didn't request them */
7228 if (!survey->channel && !allow_radio_stats)
7229 return 0;
7230
Eric W. Biederman15e47302012-09-07 20:12:54 +00007231 hdr = nl80211hdr_put(msg, portid, seq, flags,
Holger Schurig61fa7132009-11-11 12:25:40 +01007232 NL80211_CMD_NEW_SURVEY_RESULTS);
7233 if (!hdr)
7234 return -ENOMEM;
7235
David S. Miller9360ffd2012-03-29 04:41:26 -04007236 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex))
7237 goto nla_put_failure;
Holger Schurig61fa7132009-11-11 12:25:40 +01007238
7239 infoattr = nla_nest_start(msg, NL80211_ATTR_SURVEY_INFO);
7240 if (!infoattr)
7241 goto nla_put_failure;
7242
Johannes Berg11f78ac2014-11-14 16:43:50 +01007243 if (survey->channel &&
7244 nla_put_u32(msg, NL80211_SURVEY_INFO_FREQUENCY,
David S. Miller9360ffd2012-03-29 04:41:26 -04007245 survey->channel->center_freq))
7246 goto nla_put_failure;
7247
7248 if ((survey->filled & SURVEY_INFO_NOISE_DBM) &&
7249 nla_put_u8(msg, NL80211_SURVEY_INFO_NOISE, survey->noise))
7250 goto nla_put_failure;
7251 if ((survey->filled & SURVEY_INFO_IN_USE) &&
7252 nla_put_flag(msg, NL80211_SURVEY_INFO_IN_USE))
7253 goto nla_put_failure;
Johannes Berg4ed20be2014-11-14 16:35:34 +01007254 if ((survey->filled & SURVEY_INFO_TIME) &&
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02007255 nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME,
7256 survey->time, NL80211_SURVEY_INFO_PAD))
David S. Miller9360ffd2012-03-29 04:41:26 -04007257 goto nla_put_failure;
Johannes Berg4ed20be2014-11-14 16:35:34 +01007258 if ((survey->filled & SURVEY_INFO_TIME_BUSY) &&
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02007259 nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME_BUSY,
7260 survey->time_busy, NL80211_SURVEY_INFO_PAD))
David S. Miller9360ffd2012-03-29 04:41:26 -04007261 goto nla_put_failure;
Johannes Berg4ed20be2014-11-14 16:35:34 +01007262 if ((survey->filled & SURVEY_INFO_TIME_EXT_BUSY) &&
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02007263 nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME_EXT_BUSY,
7264 survey->time_ext_busy, NL80211_SURVEY_INFO_PAD))
David S. Miller9360ffd2012-03-29 04:41:26 -04007265 goto nla_put_failure;
Johannes Berg4ed20be2014-11-14 16:35:34 +01007266 if ((survey->filled & SURVEY_INFO_TIME_RX) &&
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02007267 nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME_RX,
7268 survey->time_rx, NL80211_SURVEY_INFO_PAD))
David S. Miller9360ffd2012-03-29 04:41:26 -04007269 goto nla_put_failure;
Johannes Berg4ed20be2014-11-14 16:35:34 +01007270 if ((survey->filled & SURVEY_INFO_TIME_TX) &&
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02007271 nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME_TX,
7272 survey->time_tx, NL80211_SURVEY_INFO_PAD))
David S. Miller9360ffd2012-03-29 04:41:26 -04007273 goto nla_put_failure;
Johannes Berg052536a2014-11-14 16:44:11 +01007274 if ((survey->filled & SURVEY_INFO_TIME_SCAN) &&
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02007275 nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME_SCAN,
7276 survey->time_scan, NL80211_SURVEY_INFO_PAD))
Johannes Berg052536a2014-11-14 16:44:11 +01007277 goto nla_put_failure;
Holger Schurig61fa7132009-11-11 12:25:40 +01007278
7279 nla_nest_end(msg, infoattr);
7280
Johannes Berg053c0952015-01-16 22:09:00 +01007281 genlmsg_end(msg, hdr);
7282 return 0;
Holger Schurig61fa7132009-11-11 12:25:40 +01007283
7284 nla_put_failure:
7285 genlmsg_cancel(msg, hdr);
7286 return -EMSGSIZE;
7287}
7288
Johannes Berg11f78ac2014-11-14 16:43:50 +01007289static int nl80211_dump_survey(struct sk_buff *skb, struct netlink_callback *cb)
Holger Schurig61fa7132009-11-11 12:25:40 +01007290{
7291 struct survey_info survey;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08007292 struct cfg80211_registered_device *rdev;
Johannes Berg97990a02013-04-19 01:02:55 +02007293 struct wireless_dev *wdev;
7294 int survey_idx = cb->args[2];
Holger Schurig61fa7132009-11-11 12:25:40 +01007295 int res;
Johannes Berg11f78ac2014-11-14 16:43:50 +01007296 bool radio_stats;
Holger Schurig61fa7132009-11-11 12:25:40 +01007297
Zhao, Gang1b8ec872014-04-21 12:53:02 +08007298 res = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev);
Johannes Berg67748892010-10-04 21:14:06 +02007299 if (res)
7300 return res;
Holger Schurig61fa7132009-11-11 12:25:40 +01007301
Johannes Berg11f78ac2014-11-14 16:43:50 +01007302 /* prepare_wdev_dump parsed the attributes */
7303 radio_stats = nl80211_fam.attrbuf[NL80211_ATTR_SURVEY_RADIO_STATS];
7304
Johannes Berg97990a02013-04-19 01:02:55 +02007305 if (!wdev->netdev) {
7306 res = -EINVAL;
7307 goto out_err;
7308 }
7309
Zhao, Gang1b8ec872014-04-21 12:53:02 +08007310 if (!rdev->ops->dump_survey) {
Holger Schurig61fa7132009-11-11 12:25:40 +01007311 res = -EOPNOTSUPP;
7312 goto out_err;
7313 }
7314
7315 while (1) {
Zhao, Gang1b8ec872014-04-21 12:53:02 +08007316 res = rdev_dump_survey(rdev, wdev->netdev, survey_idx, &survey);
Holger Schurig61fa7132009-11-11 12:25:40 +01007317 if (res == -ENOENT)
7318 break;
7319 if (res)
7320 goto out_err;
7321
Johannes Berg11f78ac2014-11-14 16:43:50 +01007322 /* don't send disabled channels, but do send non-channel data */
7323 if (survey.channel &&
7324 survey.channel->flags & IEEE80211_CHAN_DISABLED) {
Luis R. Rodriguez180cdc72011-05-27 07:24:02 -07007325 survey_idx++;
7326 continue;
7327 }
7328
Holger Schurig61fa7132009-11-11 12:25:40 +01007329 if (nl80211_send_survey(skb,
Eric W. Biederman15e47302012-09-07 20:12:54 +00007330 NETLINK_CB(cb->skb).portid,
Holger Schurig61fa7132009-11-11 12:25:40 +01007331 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Johannes Berg11f78ac2014-11-14 16:43:50 +01007332 wdev->netdev, radio_stats, &survey) < 0)
Holger Schurig61fa7132009-11-11 12:25:40 +01007333 goto out;
7334 survey_idx++;
7335 }
7336
7337 out:
Johannes Berg97990a02013-04-19 01:02:55 +02007338 cb->args[2] = survey_idx;
Holger Schurig61fa7132009-11-11 12:25:40 +01007339 res = skb->len;
7340 out_err:
Zhao, Gang1b8ec872014-04-21 12:53:02 +08007341 nl80211_finish_wdev_dump(rdev);
Holger Schurig61fa7132009-11-11 12:25:40 +01007342 return res;
7343}
7344
Samuel Ortizb23aa672009-07-01 21:26:54 +02007345static bool nl80211_valid_wpa_versions(u32 wpa_versions)
7346{
7347 return !(wpa_versions & ~(NL80211_WPA_VERSION_1 |
7348 NL80211_WPA_VERSION_2));
7349}
7350
Jouni Malinen636a5d32009-03-19 13:39:22 +02007351static int nl80211_authenticate(struct sk_buff *skb, struct genl_info *info)
7352{
Johannes Berg4c476992010-10-04 21:36:35 +02007353 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7354 struct net_device *dev = info->user_ptr[1];
Johannes Berg19957bb2009-07-02 17:20:43 +02007355 struct ieee80211_channel *chan;
Jouni Malinene39e5b52012-09-30 19:29:39 +03007356 const u8 *bssid, *ssid, *ie = NULL, *sae_data = NULL;
7357 int err, ssid_len, ie_len = 0, sae_data_len = 0;
Johannes Berg19957bb2009-07-02 17:20:43 +02007358 enum nl80211_auth_type auth_type;
Johannes Bergfffd0932009-07-08 14:22:54 +02007359 struct key_parse key;
Jouni Malinend5cdfac2010-04-04 09:37:19 +03007360 bool local_state_change;
Jouni Malinen636a5d32009-03-19 13:39:22 +02007361
Johannes Bergf4a11bb2009-03-27 12:40:28 +01007362 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
7363 return -EINVAL;
7364
7365 if (!info->attrs[NL80211_ATTR_MAC])
7366 return -EINVAL;
7367
Jouni Malinen17780922009-03-27 20:52:47 +02007368 if (!info->attrs[NL80211_ATTR_AUTH_TYPE])
7369 return -EINVAL;
7370
Johannes Berg19957bb2009-07-02 17:20:43 +02007371 if (!info->attrs[NL80211_ATTR_SSID])
7372 return -EINVAL;
7373
7374 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ])
7375 return -EINVAL;
7376
Johannes Bergfffd0932009-07-08 14:22:54 +02007377 err = nl80211_parse_key(info, &key);
7378 if (err)
7379 return err;
7380
7381 if (key.idx >= 0) {
Johannes Berge31b8212010-10-05 19:39:30 +02007382 if (key.type != -1 && key.type != NL80211_KEYTYPE_GROUP)
7383 return -EINVAL;
Johannes Bergfffd0932009-07-08 14:22:54 +02007384 if (!key.p.key || !key.p.key_len)
7385 return -EINVAL;
7386 if ((key.p.cipher != WLAN_CIPHER_SUITE_WEP40 ||
7387 key.p.key_len != WLAN_KEY_LEN_WEP40) &&
7388 (key.p.cipher != WLAN_CIPHER_SUITE_WEP104 ||
7389 key.p.key_len != WLAN_KEY_LEN_WEP104))
7390 return -EINVAL;
Johannes Bergb6b55552016-09-13 16:25:58 +02007391 if (key.idx > 3)
Johannes Bergfffd0932009-07-08 14:22:54 +02007392 return -EINVAL;
7393 } else {
7394 key.p.key_len = 0;
7395 key.p.key = NULL;
7396 }
7397
Johannes Bergafea0b72010-08-10 09:46:42 +02007398 if (key.idx >= 0) {
7399 int i;
7400 bool ok = false;
Kirtika Ruchandani7a087e72016-05-29 19:51:23 -07007401
Johannes Bergafea0b72010-08-10 09:46:42 +02007402 for (i = 0; i < rdev->wiphy.n_cipher_suites; i++) {
7403 if (key.p.cipher == rdev->wiphy.cipher_suites[i]) {
7404 ok = true;
7405 break;
7406 }
7407 }
Johannes Berg4c476992010-10-04 21:36:35 +02007408 if (!ok)
7409 return -EINVAL;
Johannes Bergafea0b72010-08-10 09:46:42 +02007410 }
7411
Johannes Berg4c476992010-10-04 21:36:35 +02007412 if (!rdev->ops->auth)
7413 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02007414
Johannes Berg074ac8d2010-09-16 14:58:22 +02007415 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02007416 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
7417 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02007418
Johannes Berg19957bb2009-07-02 17:20:43 +02007419 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen664834d2014-01-15 00:01:44 +02007420 chan = nl80211_get_valid_chan(&rdev->wiphy,
7421 info->attrs[NL80211_ATTR_WIPHY_FREQ]);
7422 if (!chan)
Johannes Berg4c476992010-10-04 21:36:35 +02007423 return -EINVAL;
Jouni Malinen636a5d32009-03-19 13:39:22 +02007424
Johannes Berg19957bb2009-07-02 17:20:43 +02007425 ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
7426 ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
7427
7428 if (info->attrs[NL80211_ATTR_IE]) {
7429 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
7430 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
7431 }
7432
7433 auth_type = nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]);
Jouni Malinene39e5b52012-09-30 19:29:39 +03007434 if (!nl80211_valid_auth_type(rdev, auth_type, NL80211_CMD_AUTHENTICATE))
Johannes Berg4c476992010-10-04 21:36:35 +02007435 return -EINVAL;
Johannes Berg19957bb2009-07-02 17:20:43 +02007436
Jouni Malinene39e5b52012-09-30 19:29:39 +03007437 if (auth_type == NL80211_AUTHTYPE_SAE &&
7438 !info->attrs[NL80211_ATTR_SAE_DATA])
7439 return -EINVAL;
7440
7441 if (info->attrs[NL80211_ATTR_SAE_DATA]) {
7442 if (auth_type != NL80211_AUTHTYPE_SAE)
7443 return -EINVAL;
7444 sae_data = nla_data(info->attrs[NL80211_ATTR_SAE_DATA]);
7445 sae_data_len = nla_len(info->attrs[NL80211_ATTR_SAE_DATA]);
7446 /* need to include at least Auth Transaction and Status Code */
7447 if (sae_data_len < 4)
7448 return -EINVAL;
7449 }
7450
Jouni Malinend5cdfac2010-04-04 09:37:19 +03007451 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE];
7452
Johannes Berg95de8172012-01-20 13:55:25 +01007453 /*
7454 * Since we no longer track auth state, ignore
7455 * requests to only change local state.
7456 */
7457 if (local_state_change)
7458 return 0;
7459
Johannes Berg91bf9b22013-05-15 17:44:01 +02007460 wdev_lock(dev->ieee80211_ptr);
7461 err = cfg80211_mlme_auth(rdev, dev, chan, auth_type, bssid,
7462 ssid, ssid_len, ie, ie_len,
7463 key.p.key, key.p.key_len, key.idx,
7464 sae_data, sae_data_len);
7465 wdev_unlock(dev->ieee80211_ptr);
7466 return err;
Jouni Malinen636a5d32009-03-19 13:39:22 +02007467}
7468
Johannes Bergc0692b82010-08-27 14:26:53 +03007469static int nl80211_crypto_settings(struct cfg80211_registered_device *rdev,
7470 struct genl_info *info,
Johannes Berg3dc27d22009-07-02 21:36:37 +02007471 struct cfg80211_crypto_settings *settings,
7472 int cipher_limit)
Samuel Ortizb23aa672009-07-01 21:26:54 +02007473{
Johannes Bergc0b2bbd2009-07-25 16:54:36 +02007474 memset(settings, 0, sizeof(*settings));
7475
Samuel Ortizb23aa672009-07-01 21:26:54 +02007476 settings->control_port = info->attrs[NL80211_ATTR_CONTROL_PORT];
7477
Johannes Bergc0692b82010-08-27 14:26:53 +03007478 if (info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]) {
7479 u16 proto;
Kirtika Ruchandani7a087e72016-05-29 19:51:23 -07007480
Johannes Bergc0692b82010-08-27 14:26:53 +03007481 proto = nla_get_u16(
7482 info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]);
7483 settings->control_port_ethertype = cpu_to_be16(proto);
7484 if (!(rdev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) &&
7485 proto != ETH_P_PAE)
7486 return -EINVAL;
7487 if (info->attrs[NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT])
7488 settings->control_port_no_encrypt = true;
7489 } else
7490 settings->control_port_ethertype = cpu_to_be16(ETH_P_PAE);
7491
Samuel Ortizb23aa672009-07-01 21:26:54 +02007492 if (info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]) {
7493 void *data;
7494 int len, i;
7495
7496 data = nla_data(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]);
7497 len = nla_len(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]);
7498 settings->n_ciphers_pairwise = len / sizeof(u32);
7499
7500 if (len % sizeof(u32))
7501 return -EINVAL;
7502
Johannes Berg3dc27d22009-07-02 21:36:37 +02007503 if (settings->n_ciphers_pairwise > cipher_limit)
Samuel Ortizb23aa672009-07-01 21:26:54 +02007504 return -EINVAL;
7505
7506 memcpy(settings->ciphers_pairwise, data, len);
7507
7508 for (i = 0; i < settings->n_ciphers_pairwise; i++)
Jouni Malinen38ba3c52011-09-21 18:14:56 +03007509 if (!cfg80211_supported_cipher_suite(
7510 &rdev->wiphy,
Samuel Ortizb23aa672009-07-01 21:26:54 +02007511 settings->ciphers_pairwise[i]))
7512 return -EINVAL;
7513 }
7514
7515 if (info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]) {
7516 settings->cipher_group =
7517 nla_get_u32(info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]);
Jouni Malinen38ba3c52011-09-21 18:14:56 +03007518 if (!cfg80211_supported_cipher_suite(&rdev->wiphy,
7519 settings->cipher_group))
Samuel Ortizb23aa672009-07-01 21:26:54 +02007520 return -EINVAL;
7521 }
7522
7523 if (info->attrs[NL80211_ATTR_WPA_VERSIONS]) {
7524 settings->wpa_versions =
7525 nla_get_u32(info->attrs[NL80211_ATTR_WPA_VERSIONS]);
7526 if (!nl80211_valid_wpa_versions(settings->wpa_versions))
7527 return -EINVAL;
7528 }
7529
7530 if (info->attrs[NL80211_ATTR_AKM_SUITES]) {
7531 void *data;
Jouni Malinen6d302402011-09-21 18:11:33 +03007532 int len;
Samuel Ortizb23aa672009-07-01 21:26:54 +02007533
7534 data = nla_data(info->attrs[NL80211_ATTR_AKM_SUITES]);
7535 len = nla_len(info->attrs[NL80211_ATTR_AKM_SUITES]);
7536 settings->n_akm_suites = len / sizeof(u32);
7537
7538 if (len % sizeof(u32))
7539 return -EINVAL;
7540
Jouni Malinen1b9ca022011-09-21 16:13:07 +03007541 if (settings->n_akm_suites > NL80211_MAX_NR_AKM_SUITES)
7542 return -EINVAL;
7543
Samuel Ortizb23aa672009-07-01 21:26:54 +02007544 memcpy(settings->akm_suites, data, len);
Samuel Ortizb23aa672009-07-01 21:26:54 +02007545 }
7546
7547 return 0;
7548}
7549
Jouni Malinen636a5d32009-03-19 13:39:22 +02007550static int nl80211_associate(struct sk_buff *skb, struct genl_info *info)
7551{
Johannes Berg4c476992010-10-04 21:36:35 +02007552 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7553 struct net_device *dev = info->user_ptr[1];
Johannes Bergf444de02010-05-05 15:25:02 +02007554 struct ieee80211_channel *chan;
Johannes Bergf62fab72013-02-21 20:09:09 +01007555 struct cfg80211_assoc_request req = {};
7556 const u8 *bssid, *ssid;
7557 int err, ssid_len = 0;
Jouni Malinen636a5d32009-03-19 13:39:22 +02007558
Johannes Bergf4a11bb2009-03-27 12:40:28 +01007559 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
7560 return -EINVAL;
7561
7562 if (!info->attrs[NL80211_ATTR_MAC] ||
Johannes Berg19957bb2009-07-02 17:20:43 +02007563 !info->attrs[NL80211_ATTR_SSID] ||
7564 !info->attrs[NL80211_ATTR_WIPHY_FREQ])
Johannes Bergf4a11bb2009-03-27 12:40:28 +01007565 return -EINVAL;
7566
Johannes Berg4c476992010-10-04 21:36:35 +02007567 if (!rdev->ops->assoc)
7568 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02007569
Johannes Berg074ac8d2010-09-16 14:58:22 +02007570 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02007571 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
7572 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02007573
Johannes Berg19957bb2009-07-02 17:20:43 +02007574 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02007575
Jouni Malinen664834d2014-01-15 00:01:44 +02007576 chan = nl80211_get_valid_chan(&rdev->wiphy,
7577 info->attrs[NL80211_ATTR_WIPHY_FREQ]);
7578 if (!chan)
Johannes Berg4c476992010-10-04 21:36:35 +02007579 return -EINVAL;
Jouni Malinen636a5d32009-03-19 13:39:22 +02007580
Johannes Berg19957bb2009-07-02 17:20:43 +02007581 ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
7582 ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02007583
7584 if (info->attrs[NL80211_ATTR_IE]) {
Johannes Bergf62fab72013-02-21 20:09:09 +01007585 req.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
7586 req.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02007587 }
7588
Jouni Malinendc6382c2009-05-06 22:09:37 +03007589 if (info->attrs[NL80211_ATTR_USE_MFP]) {
Johannes Berg4f5dadc2009-07-07 03:56:10 +02007590 enum nl80211_mfp mfp =
Jouni Malinendc6382c2009-05-06 22:09:37 +03007591 nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]);
Johannes Berg4f5dadc2009-07-07 03:56:10 +02007592 if (mfp == NL80211_MFP_REQUIRED)
Johannes Bergf62fab72013-02-21 20:09:09 +01007593 req.use_mfp = true;
Johannes Berg4c476992010-10-04 21:36:35 +02007594 else if (mfp != NL80211_MFP_NO)
7595 return -EINVAL;
Jouni Malinendc6382c2009-05-06 22:09:37 +03007596 }
7597
Johannes Berg3e5d7642009-07-07 14:37:26 +02007598 if (info->attrs[NL80211_ATTR_PREV_BSSID])
Johannes Bergf62fab72013-02-21 20:09:09 +01007599 req.prev_bssid = nla_data(info->attrs[NL80211_ATTR_PREV_BSSID]);
Johannes Berg3e5d7642009-07-07 14:37:26 +02007600
Ben Greear7e7c8922011-11-18 11:31:59 -08007601 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT]))
Johannes Bergf62fab72013-02-21 20:09:09 +01007602 req.flags |= ASSOC_REQ_DISABLE_HT;
Ben Greear7e7c8922011-11-18 11:31:59 -08007603
7604 if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
Johannes Bergf62fab72013-02-21 20:09:09 +01007605 memcpy(&req.ht_capa_mask,
7606 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]),
7607 sizeof(req.ht_capa_mask));
Ben Greear7e7c8922011-11-18 11:31:59 -08007608
7609 if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) {
Johannes Bergf62fab72013-02-21 20:09:09 +01007610 if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
Ben Greear7e7c8922011-11-18 11:31:59 -08007611 return -EINVAL;
Johannes Bergf62fab72013-02-21 20:09:09 +01007612 memcpy(&req.ht_capa,
7613 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]),
7614 sizeof(req.ht_capa));
Ben Greear7e7c8922011-11-18 11:31:59 -08007615 }
7616
Johannes Bergee2aca32013-02-21 17:36:01 +01007617 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_VHT]))
Johannes Bergf62fab72013-02-21 20:09:09 +01007618 req.flags |= ASSOC_REQ_DISABLE_VHT;
Johannes Bergee2aca32013-02-21 17:36:01 +01007619
7620 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK])
Johannes Bergf62fab72013-02-21 20:09:09 +01007621 memcpy(&req.vht_capa_mask,
7622 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]),
7623 sizeof(req.vht_capa_mask));
Johannes Bergee2aca32013-02-21 17:36:01 +01007624
7625 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) {
Johannes Bergf62fab72013-02-21 20:09:09 +01007626 if (!info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK])
Johannes Bergee2aca32013-02-21 17:36:01 +01007627 return -EINVAL;
Johannes Bergf62fab72013-02-21 20:09:09 +01007628 memcpy(&req.vht_capa,
7629 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]),
7630 sizeof(req.vht_capa));
Johannes Bergee2aca32013-02-21 17:36:01 +01007631 }
7632
Assaf Kraussbab5ab72014-09-03 15:25:01 +03007633 if (nla_get_flag(info->attrs[NL80211_ATTR_USE_RRM])) {
Beni Lev0c9ca112016-02-17 20:30:00 +02007634 if (!((rdev->wiphy.features &
7635 NL80211_FEATURE_DS_PARAM_SET_IE_IN_PROBES) &&
7636 (rdev->wiphy.features & NL80211_FEATURE_QUIET)) &&
7637 !wiphy_ext_feature_isset(&rdev->wiphy,
7638 NL80211_EXT_FEATURE_RRM))
Assaf Kraussbab5ab72014-09-03 15:25:01 +03007639 return -EINVAL;
7640 req.flags |= ASSOC_REQ_USE_RRM;
7641 }
7642
Johannes Bergf62fab72013-02-21 20:09:09 +01007643 err = nl80211_crypto_settings(rdev, info, &req.crypto, 1);
Johannes Berg91bf9b22013-05-15 17:44:01 +02007644 if (!err) {
7645 wdev_lock(dev->ieee80211_ptr);
Johannes Bergf62fab72013-02-21 20:09:09 +01007646 err = cfg80211_mlme_assoc(rdev, dev, chan, bssid,
7647 ssid, ssid_len, &req);
Johannes Berg91bf9b22013-05-15 17:44:01 +02007648 wdev_unlock(dev->ieee80211_ptr);
7649 }
Jouni Malinen636a5d32009-03-19 13:39:22 +02007650
Jouni Malinen636a5d32009-03-19 13:39:22 +02007651 return err;
7652}
7653
7654static int nl80211_deauthenticate(struct sk_buff *skb, struct genl_info *info)
7655{
Johannes Berg4c476992010-10-04 21:36:35 +02007656 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7657 struct net_device *dev = info->user_ptr[1];
Johannes Berg19957bb2009-07-02 17:20:43 +02007658 const u8 *ie = NULL, *bssid;
Johannes Berg91bf9b22013-05-15 17:44:01 +02007659 int ie_len = 0, err;
Johannes Berg19957bb2009-07-02 17:20:43 +02007660 u16 reason_code;
Jouni Malinend5cdfac2010-04-04 09:37:19 +03007661 bool local_state_change;
Jouni Malinen636a5d32009-03-19 13:39:22 +02007662
Johannes Bergf4a11bb2009-03-27 12:40:28 +01007663 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
7664 return -EINVAL;
7665
7666 if (!info->attrs[NL80211_ATTR_MAC])
7667 return -EINVAL;
7668
7669 if (!info->attrs[NL80211_ATTR_REASON_CODE])
7670 return -EINVAL;
7671
Johannes Berg4c476992010-10-04 21:36:35 +02007672 if (!rdev->ops->deauth)
7673 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02007674
Johannes Berg074ac8d2010-09-16 14:58:22 +02007675 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02007676 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
7677 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02007678
Johannes Berg19957bb2009-07-02 17:20:43 +02007679 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02007680
Johannes Berg19957bb2009-07-02 17:20:43 +02007681 reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
7682 if (reason_code == 0) {
Johannes Bergf4a11bb2009-03-27 12:40:28 +01007683 /* Reason Code 0 is reserved */
Johannes Berg4c476992010-10-04 21:36:35 +02007684 return -EINVAL;
Jouni Malinen255e7372009-03-20 21:21:17 +02007685 }
Jouni Malinen636a5d32009-03-19 13:39:22 +02007686
7687 if (info->attrs[NL80211_ATTR_IE]) {
Johannes Berg19957bb2009-07-02 17:20:43 +02007688 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
7689 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02007690 }
7691
Jouni Malinend5cdfac2010-04-04 09:37:19 +03007692 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE];
7693
Johannes Berg91bf9b22013-05-15 17:44:01 +02007694 wdev_lock(dev->ieee80211_ptr);
7695 err = cfg80211_mlme_deauth(rdev, dev, bssid, ie, ie_len, reason_code,
7696 local_state_change);
7697 wdev_unlock(dev->ieee80211_ptr);
7698 return err;
Jouni Malinen636a5d32009-03-19 13:39:22 +02007699}
7700
7701static int nl80211_disassociate(struct sk_buff *skb, struct genl_info *info)
7702{
Johannes Berg4c476992010-10-04 21:36:35 +02007703 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7704 struct net_device *dev = info->user_ptr[1];
Johannes Berg19957bb2009-07-02 17:20:43 +02007705 const u8 *ie = NULL, *bssid;
Johannes Berg91bf9b22013-05-15 17:44:01 +02007706 int ie_len = 0, err;
Johannes Berg19957bb2009-07-02 17:20:43 +02007707 u16 reason_code;
Jouni Malinend5cdfac2010-04-04 09:37:19 +03007708 bool local_state_change;
Jouni Malinen636a5d32009-03-19 13:39:22 +02007709
Johannes Bergf4a11bb2009-03-27 12:40:28 +01007710 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
7711 return -EINVAL;
7712
7713 if (!info->attrs[NL80211_ATTR_MAC])
7714 return -EINVAL;
7715
7716 if (!info->attrs[NL80211_ATTR_REASON_CODE])
7717 return -EINVAL;
7718
Johannes Berg4c476992010-10-04 21:36:35 +02007719 if (!rdev->ops->disassoc)
7720 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02007721
Johannes Berg074ac8d2010-09-16 14:58:22 +02007722 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02007723 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
7724 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02007725
Johannes Berg19957bb2009-07-02 17:20:43 +02007726 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02007727
Johannes Berg19957bb2009-07-02 17:20:43 +02007728 reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
7729 if (reason_code == 0) {
Johannes Bergf4a11bb2009-03-27 12:40:28 +01007730 /* Reason Code 0 is reserved */
Johannes Berg4c476992010-10-04 21:36:35 +02007731 return -EINVAL;
Jouni Malinen255e7372009-03-20 21:21:17 +02007732 }
Jouni Malinen636a5d32009-03-19 13:39:22 +02007733
7734 if (info->attrs[NL80211_ATTR_IE]) {
Johannes Berg19957bb2009-07-02 17:20:43 +02007735 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
7736 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02007737 }
7738
Jouni Malinend5cdfac2010-04-04 09:37:19 +03007739 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE];
7740
Johannes Berg91bf9b22013-05-15 17:44:01 +02007741 wdev_lock(dev->ieee80211_ptr);
7742 err = cfg80211_mlme_disassoc(rdev, dev, bssid, ie, ie_len, reason_code,
7743 local_state_change);
7744 wdev_unlock(dev->ieee80211_ptr);
7745 return err;
Jouni Malinen636a5d32009-03-19 13:39:22 +02007746}
7747
Felix Fietkaudd5b4cc2010-11-22 20:58:24 +01007748static bool
7749nl80211_parse_mcast_rate(struct cfg80211_registered_device *rdev,
Johannes Berg57fbcce2016-04-12 15:56:15 +02007750 int mcast_rate[NUM_NL80211_BANDS],
Felix Fietkaudd5b4cc2010-11-22 20:58:24 +01007751 int rateval)
7752{
7753 struct wiphy *wiphy = &rdev->wiphy;
7754 bool found = false;
7755 int band, i;
7756
Johannes Berg57fbcce2016-04-12 15:56:15 +02007757 for (band = 0; band < NUM_NL80211_BANDS; band++) {
Felix Fietkaudd5b4cc2010-11-22 20:58:24 +01007758 struct ieee80211_supported_band *sband;
7759
7760 sband = wiphy->bands[band];
7761 if (!sband)
7762 continue;
7763
7764 for (i = 0; i < sband->n_bitrates; i++) {
7765 if (sband->bitrates[i].bitrate == rateval) {
7766 mcast_rate[band] = i + 1;
7767 found = true;
7768 break;
7769 }
7770 }
7771 }
7772
7773 return found;
7774}
7775
Johannes Berg04a773a2009-04-19 21:24:32 +02007776static int nl80211_join_ibss(struct sk_buff *skb, struct genl_info *info)
7777{
Johannes Berg4c476992010-10-04 21:36:35 +02007778 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7779 struct net_device *dev = info->user_ptr[1];
Johannes Berg04a773a2009-04-19 21:24:32 +02007780 struct cfg80211_ibss_params ibss;
7781 struct wiphy *wiphy;
Johannes Bergfffd0932009-07-08 14:22:54 +02007782 struct cfg80211_cached_keys *connkeys = NULL;
Johannes Berg04a773a2009-04-19 21:24:32 +02007783 int err;
7784
Johannes Berg8e30bc52009-04-22 17:45:38 +02007785 memset(&ibss, 0, sizeof(ibss));
7786
Johannes Berg04a773a2009-04-19 21:24:32 +02007787 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
7788 return -EINVAL;
7789
Johannes Berg683b6d32012-11-08 21:25:48 +01007790 if (!info->attrs[NL80211_ATTR_SSID] ||
Johannes Berg04a773a2009-04-19 21:24:32 +02007791 !nla_len(info->attrs[NL80211_ATTR_SSID]))
7792 return -EINVAL;
7793
Johannes Berg8e30bc52009-04-22 17:45:38 +02007794 ibss.beacon_interval = 100;
7795
Purushottam Kushwaha12d20fc92016-08-11 15:14:02 +05307796 if (info->attrs[NL80211_ATTR_BEACON_INTERVAL])
Johannes Berg8e30bc52009-04-22 17:45:38 +02007797 ibss.beacon_interval =
7798 nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]);
Purushottam Kushwaha12d20fc92016-08-11 15:14:02 +05307799
7800 err = cfg80211_validate_beacon_int(rdev, ibss.beacon_interval);
7801 if (err)
7802 return err;
Johannes Berg8e30bc52009-04-22 17:45:38 +02007803
Johannes Berg4c476992010-10-04 21:36:35 +02007804 if (!rdev->ops->join_ibss)
7805 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02007806
Johannes Berg4c476992010-10-04 21:36:35 +02007807 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC)
7808 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02007809
Johannes Berg79c97e92009-07-07 03:56:12 +02007810 wiphy = &rdev->wiphy;
Johannes Berg04a773a2009-04-19 21:24:32 +02007811
Johannes Berg39193492011-09-16 13:45:25 +02007812 if (info->attrs[NL80211_ATTR_MAC]) {
Johannes Berg04a773a2009-04-19 21:24:32 +02007813 ibss.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Johannes Berg39193492011-09-16 13:45:25 +02007814
7815 if (!is_valid_ether_addr(ibss.bssid))
7816 return -EINVAL;
7817 }
Johannes Berg04a773a2009-04-19 21:24:32 +02007818 ibss.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
7819 ibss.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
7820
7821 if (info->attrs[NL80211_ATTR_IE]) {
7822 ibss.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
7823 ibss.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
7824 }
7825
Johannes Berg683b6d32012-11-08 21:25:48 +01007826 err = nl80211_parse_chandef(rdev, info, &ibss.chandef);
7827 if (err)
7828 return err;
Alexander Simon54858ee5b2011-11-30 16:56:32 +01007829
Ilan Peer174e0cd2014-02-23 09:13:01 +02007830 if (!cfg80211_reg_can_beacon(&rdev->wiphy, &ibss.chandef,
7831 NL80211_IFTYPE_ADHOC))
Alexander Simon54858ee5b2011-11-30 16:56:32 +01007832 return -EINVAL;
7833
Simon Wunderlich2f301ab2013-05-16 13:00:28 +02007834 switch (ibss.chandef.width) {
Simon Wunderlichbf372642013-07-08 16:55:58 +02007835 case NL80211_CHAN_WIDTH_5:
7836 case NL80211_CHAN_WIDTH_10:
Simon Wunderlich2f301ab2013-05-16 13:00:28 +02007837 case NL80211_CHAN_WIDTH_20_NOHT:
7838 break;
7839 case NL80211_CHAN_WIDTH_20:
7840 case NL80211_CHAN_WIDTH_40:
Janusz.Dziedzic@tieto.comffc11992015-02-21 16:52:39 +01007841 if (!(rdev->wiphy.features & NL80211_FEATURE_HT_IBSS))
7842 return -EINVAL;
7843 break;
7844 case NL80211_CHAN_WIDTH_80:
7845 case NL80211_CHAN_WIDTH_80P80:
7846 case NL80211_CHAN_WIDTH_160:
7847 if (!(rdev->wiphy.features & NL80211_FEATURE_HT_IBSS))
7848 return -EINVAL;
7849 if (!wiphy_ext_feature_isset(&rdev->wiphy,
7850 NL80211_EXT_FEATURE_VHT_IBSS))
7851 return -EINVAL;
7852 break;
Simon Wunderlich2f301ab2013-05-16 13:00:28 +02007853 default:
Johannes Bergdb9c64c2012-11-09 14:56:41 +01007854 return -EINVAL;
Simon Wunderlich2f301ab2013-05-16 13:00:28 +02007855 }
Johannes Bergdb9c64c2012-11-09 14:56:41 +01007856
Johannes Berg04a773a2009-04-19 21:24:32 +02007857 ibss.channel_fixed = !!info->attrs[NL80211_ATTR_FREQ_FIXED];
Johannes Bergfffd0932009-07-08 14:22:54 +02007858 ibss.privacy = !!info->attrs[NL80211_ATTR_PRIVACY];
Johannes Berg04a773a2009-04-19 21:24:32 +02007859
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03007860 if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) {
7861 u8 *rates =
7862 nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
7863 int n_rates =
7864 nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
7865 struct ieee80211_supported_band *sband =
Johannes Berg683b6d32012-11-08 21:25:48 +01007866 wiphy->bands[ibss.chandef.chan->band];
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03007867
Johannes Berg34850ab2011-07-18 18:08:35 +02007868 err = ieee80211_get_ratemask(sband, rates, n_rates,
7869 &ibss.basic_rates);
7870 if (err)
7871 return err;
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03007872 }
Felix Fietkaudd5b4cc2010-11-22 20:58:24 +01007873
Simon Wunderlich803768f2013-06-28 10:39:58 +02007874 if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
7875 memcpy(&ibss.ht_capa_mask,
7876 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]),
7877 sizeof(ibss.ht_capa_mask));
7878
7879 if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) {
7880 if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
7881 return -EINVAL;
7882 memcpy(&ibss.ht_capa,
7883 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]),
7884 sizeof(ibss.ht_capa));
7885 }
7886
Felix Fietkaudd5b4cc2010-11-22 20:58:24 +01007887 if (info->attrs[NL80211_ATTR_MCAST_RATE] &&
7888 !nl80211_parse_mcast_rate(rdev, ibss.mcast_rate,
7889 nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE])))
7890 return -EINVAL;
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03007891
Johannes Berg4c476992010-10-04 21:36:35 +02007892 if (ibss.privacy && info->attrs[NL80211_ATTR_KEYS]) {
Sujith Manoharande7044e2012-10-18 10:19:28 +05307893 bool no_ht = false;
7894
Johannes Berg4c476992010-10-04 21:36:35 +02007895 connkeys = nl80211_parse_connkeys(rdev,
Sujith Manoharande7044e2012-10-18 10:19:28 +05307896 info->attrs[NL80211_ATTR_KEYS],
7897 &no_ht);
Johannes Berg4c476992010-10-04 21:36:35 +02007898 if (IS_ERR(connkeys))
7899 return PTR_ERR(connkeys);
Sujith Manoharande7044e2012-10-18 10:19:28 +05307900
Johannes Berg3d9d1d62012-11-08 23:14:50 +01007901 if ((ibss.chandef.width != NL80211_CHAN_WIDTH_20_NOHT) &&
7902 no_ht) {
Ola Olsson5e950a72016-02-11 01:00:22 +01007903 kzfree(connkeys);
Sujith Manoharande7044e2012-10-18 10:19:28 +05307904 return -EINVAL;
7905 }
Johannes Berg4c476992010-10-04 21:36:35 +02007906 }
Johannes Berg04a773a2009-04-19 21:24:32 +02007907
Antonio Quartulli267335d2012-01-31 20:25:47 +01007908 ibss.control_port =
7909 nla_get_flag(info->attrs[NL80211_ATTR_CONTROL_PORT]);
7910
Simon Wunderlich5336fa82013-10-07 18:41:05 +02007911 ibss.userspace_handles_dfs =
7912 nla_get_flag(info->attrs[NL80211_ATTR_HANDLE_DFS]);
7913
Johannes Berg4c476992010-10-04 21:36:35 +02007914 err = cfg80211_join_ibss(rdev, dev, &ibss, connkeys);
Johannes Bergfffd0932009-07-08 14:22:54 +02007915 if (err)
Johannes Bergb47f6102014-09-10 13:39:54 +03007916 kzfree(connkeys);
Johannes Berg04a773a2009-04-19 21:24:32 +02007917 return err;
7918}
7919
7920static int nl80211_leave_ibss(struct sk_buff *skb, struct genl_info *info)
7921{
Johannes Berg4c476992010-10-04 21:36:35 +02007922 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7923 struct net_device *dev = info->user_ptr[1];
Johannes Berg04a773a2009-04-19 21:24:32 +02007924
Johannes Berg4c476992010-10-04 21:36:35 +02007925 if (!rdev->ops->leave_ibss)
7926 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02007927
Johannes Berg4c476992010-10-04 21:36:35 +02007928 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC)
7929 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02007930
Johannes Berg4c476992010-10-04 21:36:35 +02007931 return cfg80211_leave_ibss(rdev, dev, false);
Johannes Berg04a773a2009-04-19 21:24:32 +02007932}
7933
Antonio Quartullif4e583c2012-11-02 13:27:48 +01007934static int nl80211_set_mcast_rate(struct sk_buff *skb, struct genl_info *info)
7935{
7936 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7937 struct net_device *dev = info->user_ptr[1];
Johannes Berg57fbcce2016-04-12 15:56:15 +02007938 int mcast_rate[NUM_NL80211_BANDS];
Antonio Quartullif4e583c2012-11-02 13:27:48 +01007939 u32 nla_rate;
7940 int err;
7941
7942 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC &&
Bertold Van den Bergh876dc932015-08-05 16:02:21 +02007943 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT &&
7944 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_OCB)
Antonio Quartullif4e583c2012-11-02 13:27:48 +01007945 return -EOPNOTSUPP;
7946
7947 if (!rdev->ops->set_mcast_rate)
7948 return -EOPNOTSUPP;
7949
7950 memset(mcast_rate, 0, sizeof(mcast_rate));
7951
7952 if (!info->attrs[NL80211_ATTR_MCAST_RATE])
7953 return -EINVAL;
7954
7955 nla_rate = nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]);
7956 if (!nl80211_parse_mcast_rate(rdev, mcast_rate, nla_rate))
7957 return -EINVAL;
7958
Ilan Peera1056b12015-10-22 22:27:46 +03007959 err = rdev_set_mcast_rate(rdev, dev, mcast_rate);
Antonio Quartullif4e583c2012-11-02 13:27:48 +01007960
7961 return err;
7962}
7963
Johannes Bergad7e7182013-11-13 13:37:47 +01007964static struct sk_buff *
7965__cfg80211_alloc_vendor_skb(struct cfg80211_registered_device *rdev,
Ahmad Kholaif6c09e792015-02-26 15:26:53 +02007966 struct wireless_dev *wdev, int approxlen,
7967 u32 portid, u32 seq, enum nl80211_commands cmd,
Johannes Berg567ffc32013-12-18 14:43:31 +01007968 enum nl80211_attrs attr,
7969 const struct nl80211_vendor_cmd_info *info,
7970 gfp_t gfp)
Johannes Bergad7e7182013-11-13 13:37:47 +01007971{
7972 struct sk_buff *skb;
7973 void *hdr;
7974 struct nlattr *data;
7975
7976 skb = nlmsg_new(approxlen + 100, gfp);
7977 if (!skb)
7978 return NULL;
7979
7980 hdr = nl80211hdr_put(skb, portid, seq, 0, cmd);
7981 if (!hdr) {
7982 kfree_skb(skb);
7983 return NULL;
7984 }
7985
7986 if (nla_put_u32(skb, NL80211_ATTR_WIPHY, rdev->wiphy_idx))
7987 goto nla_put_failure;
Johannes Berg567ffc32013-12-18 14:43:31 +01007988
7989 if (info) {
7990 if (nla_put_u32(skb, NL80211_ATTR_VENDOR_ID,
7991 info->vendor_id))
7992 goto nla_put_failure;
7993 if (nla_put_u32(skb, NL80211_ATTR_VENDOR_SUBCMD,
7994 info->subcmd))
7995 goto nla_put_failure;
7996 }
7997
Ahmad Kholaif6c09e792015-02-26 15:26:53 +02007998 if (wdev) {
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02007999 if (nla_put_u64_64bit(skb, NL80211_ATTR_WDEV,
8000 wdev_id(wdev), NL80211_ATTR_PAD))
Ahmad Kholaif6c09e792015-02-26 15:26:53 +02008001 goto nla_put_failure;
8002 if (wdev->netdev &&
8003 nla_put_u32(skb, NL80211_ATTR_IFINDEX,
8004 wdev->netdev->ifindex))
8005 goto nla_put_failure;
8006 }
8007
Johannes Bergad7e7182013-11-13 13:37:47 +01008008 data = nla_nest_start(skb, attr);
8009
8010 ((void **)skb->cb)[0] = rdev;
8011 ((void **)skb->cb)[1] = hdr;
8012 ((void **)skb->cb)[2] = data;
8013
8014 return skb;
8015
8016 nla_put_failure:
8017 kfree_skb(skb);
8018 return NULL;
8019}
Antonio Quartullif4e583c2012-11-02 13:27:48 +01008020
Johannes Berge03ad6e2014-01-01 17:22:30 +01008021struct sk_buff *__cfg80211_alloc_event_skb(struct wiphy *wiphy,
Ahmad Kholaif6c09e792015-02-26 15:26:53 +02008022 struct wireless_dev *wdev,
Johannes Berge03ad6e2014-01-01 17:22:30 +01008023 enum nl80211_commands cmd,
8024 enum nl80211_attrs attr,
8025 int vendor_event_idx,
8026 int approxlen, gfp_t gfp)
8027{
Zhao, Gangf26cbf42014-04-21 12:53:03 +08008028 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berge03ad6e2014-01-01 17:22:30 +01008029 const struct nl80211_vendor_cmd_info *info;
8030
8031 switch (cmd) {
8032 case NL80211_CMD_TESTMODE:
8033 if (WARN_ON(vendor_event_idx != -1))
8034 return NULL;
8035 info = NULL;
8036 break;
8037 case NL80211_CMD_VENDOR:
8038 if (WARN_ON(vendor_event_idx < 0 ||
8039 vendor_event_idx >= wiphy->n_vendor_events))
8040 return NULL;
8041 info = &wiphy->vendor_events[vendor_event_idx];
8042 break;
8043 default:
8044 WARN_ON(1);
8045 return NULL;
8046 }
8047
Ahmad Kholaif6c09e792015-02-26 15:26:53 +02008048 return __cfg80211_alloc_vendor_skb(rdev, wdev, approxlen, 0, 0,
Johannes Berge03ad6e2014-01-01 17:22:30 +01008049 cmd, attr, info, gfp);
8050}
8051EXPORT_SYMBOL(__cfg80211_alloc_event_skb);
8052
8053void __cfg80211_send_event_skb(struct sk_buff *skb, gfp_t gfp)
8054{
8055 struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0];
8056 void *hdr = ((void **)skb->cb)[1];
8057 struct nlattr *data = ((void **)skb->cb)[2];
8058 enum nl80211_multicast_groups mcgrp = NL80211_MCGRP_TESTMODE;
8059
Johannes Bergbd8c78e2014-07-30 14:55:26 +02008060 /* clear CB data for netlink core to own from now on */
8061 memset(skb->cb, 0, sizeof(skb->cb));
8062
Johannes Berge03ad6e2014-01-01 17:22:30 +01008063 nla_nest_end(skb, data);
8064 genlmsg_end(skb, hdr);
8065
8066 if (data->nla_type == NL80211_ATTR_VENDOR_DATA)
8067 mcgrp = NL80211_MCGRP_VENDOR;
8068
8069 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), skb, 0,
8070 mcgrp, gfp);
8071}
8072EXPORT_SYMBOL(__cfg80211_send_event_skb);
8073
Johannes Bergaff89a92009-07-01 21:26:51 +02008074#ifdef CONFIG_NL80211_TESTMODE
Johannes Bergaff89a92009-07-01 21:26:51 +02008075static int nl80211_testmode_do(struct sk_buff *skb, struct genl_info *info)
8076{
Johannes Berg4c476992010-10-04 21:36:35 +02008077 struct cfg80211_registered_device *rdev = info->user_ptr[0];
David Spinadelfc73f112013-07-31 18:04:15 +03008078 struct wireless_dev *wdev =
8079 __cfg80211_wdev_from_attrs(genl_info_net(info), info->attrs);
Johannes Bergaff89a92009-07-01 21:26:51 +02008080 int err;
8081
David Spinadelfc73f112013-07-31 18:04:15 +03008082 if (!rdev->ops->testmode_cmd)
8083 return -EOPNOTSUPP;
8084
8085 if (IS_ERR(wdev)) {
8086 err = PTR_ERR(wdev);
8087 if (err != -EINVAL)
8088 return err;
8089 wdev = NULL;
8090 } else if (wdev->wiphy != &rdev->wiphy) {
8091 return -EINVAL;
8092 }
8093
Johannes Bergaff89a92009-07-01 21:26:51 +02008094 if (!info->attrs[NL80211_ATTR_TESTDATA])
8095 return -EINVAL;
8096
Johannes Bergad7e7182013-11-13 13:37:47 +01008097 rdev->cur_cmd_info = info;
David Spinadelfc73f112013-07-31 18:04:15 +03008098 err = rdev_testmode_cmd(rdev, wdev,
Johannes Bergaff89a92009-07-01 21:26:51 +02008099 nla_data(info->attrs[NL80211_ATTR_TESTDATA]),
8100 nla_len(info->attrs[NL80211_ATTR_TESTDATA]));
Johannes Bergad7e7182013-11-13 13:37:47 +01008101 rdev->cur_cmd_info = NULL;
Johannes Bergaff89a92009-07-01 21:26:51 +02008102
Johannes Bergaff89a92009-07-01 21:26:51 +02008103 return err;
8104}
8105
Wey-Yi Guy71063f02011-05-20 09:05:54 -07008106static int nl80211_testmode_dump(struct sk_buff *skb,
8107 struct netlink_callback *cb)
8108{
Johannes Berg00918d32011-12-13 17:22:05 +01008109 struct cfg80211_registered_device *rdev;
Wey-Yi Guy71063f02011-05-20 09:05:54 -07008110 int err;
8111 long phy_idx;
8112 void *data = NULL;
8113 int data_len = 0;
8114
Johannes Berg5fe231e2013-05-08 21:45:15 +02008115 rtnl_lock();
8116
Wey-Yi Guy71063f02011-05-20 09:05:54 -07008117 if (cb->args[0]) {
8118 /*
8119 * 0 is a valid index, but not valid for args[0],
8120 * so we need to offset by 1.
8121 */
8122 phy_idx = cb->args[0] - 1;
8123 } else {
8124 err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize,
8125 nl80211_fam.attrbuf, nl80211_fam.maxattr,
8126 nl80211_policy);
8127 if (err)
Johannes Berg5fe231e2013-05-08 21:45:15 +02008128 goto out_err;
Johannes Berg00918d32011-12-13 17:22:05 +01008129
Johannes Berg2bd7e352012-06-15 14:23:16 +02008130 rdev = __cfg80211_rdev_from_attrs(sock_net(skb->sk),
8131 nl80211_fam.attrbuf);
8132 if (IS_ERR(rdev)) {
Johannes Berg5fe231e2013-05-08 21:45:15 +02008133 err = PTR_ERR(rdev);
8134 goto out_err;
Johannes Berg00918d32011-12-13 17:22:05 +01008135 }
Johannes Berg2bd7e352012-06-15 14:23:16 +02008136 phy_idx = rdev->wiphy_idx;
8137 rdev = NULL;
Johannes Berg2bd7e352012-06-15 14:23:16 +02008138
Wey-Yi Guy71063f02011-05-20 09:05:54 -07008139 if (nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA])
8140 cb->args[1] =
8141 (long)nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA];
8142 }
8143
8144 if (cb->args[1]) {
8145 data = nla_data((void *)cb->args[1]);
8146 data_len = nla_len((void *)cb->args[1]);
8147 }
8148
Johannes Berg00918d32011-12-13 17:22:05 +01008149 rdev = cfg80211_rdev_by_wiphy_idx(phy_idx);
8150 if (!rdev) {
Johannes Berg5fe231e2013-05-08 21:45:15 +02008151 err = -ENOENT;
8152 goto out_err;
Wey-Yi Guy71063f02011-05-20 09:05:54 -07008153 }
Wey-Yi Guy71063f02011-05-20 09:05:54 -07008154
Johannes Berg00918d32011-12-13 17:22:05 +01008155 if (!rdev->ops->testmode_dump) {
Wey-Yi Guy71063f02011-05-20 09:05:54 -07008156 err = -EOPNOTSUPP;
8157 goto out_err;
8158 }
8159
8160 while (1) {
Eric W. Biederman15e47302012-09-07 20:12:54 +00008161 void *hdr = nl80211hdr_put(skb, NETLINK_CB(cb->skb).portid,
Wey-Yi Guy71063f02011-05-20 09:05:54 -07008162 cb->nlh->nlmsg_seq, NLM_F_MULTI,
8163 NL80211_CMD_TESTMODE);
8164 struct nlattr *tmdata;
8165
Dan Carpentercb35fba2013-08-14 14:50:01 +03008166 if (!hdr)
8167 break;
8168
David S. Miller9360ffd2012-03-29 04:41:26 -04008169 if (nla_put_u32(skb, NL80211_ATTR_WIPHY, phy_idx)) {
Wey-Yi Guy71063f02011-05-20 09:05:54 -07008170 genlmsg_cancel(skb, hdr);
8171 break;
8172 }
8173
8174 tmdata = nla_nest_start(skb, NL80211_ATTR_TESTDATA);
8175 if (!tmdata) {
8176 genlmsg_cancel(skb, hdr);
8177 break;
8178 }
Hila Gonene35e4d22012-06-27 17:19:42 +03008179 err = rdev_testmode_dump(rdev, skb, cb, data, data_len);
Wey-Yi Guy71063f02011-05-20 09:05:54 -07008180 nla_nest_end(skb, tmdata);
8181
8182 if (err == -ENOBUFS || err == -ENOENT) {
8183 genlmsg_cancel(skb, hdr);
8184 break;
8185 } else if (err) {
8186 genlmsg_cancel(skb, hdr);
8187 goto out_err;
8188 }
8189
8190 genlmsg_end(skb, hdr);
8191 }
8192
8193 err = skb->len;
8194 /* see above */
8195 cb->args[0] = phy_idx + 1;
8196 out_err:
Johannes Berg5fe231e2013-05-08 21:45:15 +02008197 rtnl_unlock();
Wey-Yi Guy71063f02011-05-20 09:05:54 -07008198 return err;
8199}
Johannes Bergaff89a92009-07-01 21:26:51 +02008200#endif
8201
Samuel Ortizb23aa672009-07-01 21:26:54 +02008202static int nl80211_connect(struct sk_buff *skb, struct genl_info *info)
8203{
Johannes Berg4c476992010-10-04 21:36:35 +02008204 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8205 struct net_device *dev = info->user_ptr[1];
Samuel Ortizb23aa672009-07-01 21:26:54 +02008206 struct cfg80211_connect_params connect;
8207 struct wiphy *wiphy;
Johannes Bergfffd0932009-07-08 14:22:54 +02008208 struct cfg80211_cached_keys *connkeys = NULL;
Samuel Ortizb23aa672009-07-01 21:26:54 +02008209 int err;
8210
8211 memset(&connect, 0, sizeof(connect));
8212
8213 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
8214 return -EINVAL;
8215
8216 if (!info->attrs[NL80211_ATTR_SSID] ||
8217 !nla_len(info->attrs[NL80211_ATTR_SSID]))
8218 return -EINVAL;
8219
8220 if (info->attrs[NL80211_ATTR_AUTH_TYPE]) {
8221 connect.auth_type =
8222 nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]);
Jouni Malinene39e5b52012-09-30 19:29:39 +03008223 if (!nl80211_valid_auth_type(rdev, connect.auth_type,
8224 NL80211_CMD_CONNECT))
Samuel Ortizb23aa672009-07-01 21:26:54 +02008225 return -EINVAL;
8226 } else
8227 connect.auth_type = NL80211_AUTHTYPE_AUTOMATIC;
8228
8229 connect.privacy = info->attrs[NL80211_ATTR_PRIVACY];
8230
Johannes Bergc0692b82010-08-27 14:26:53 +03008231 err = nl80211_crypto_settings(rdev, info, &connect.crypto,
Johannes Berg3dc27d22009-07-02 21:36:37 +02008232 NL80211_MAX_NR_CIPHER_SUITES);
Samuel Ortizb23aa672009-07-01 21:26:54 +02008233 if (err)
8234 return err;
Samuel Ortizb23aa672009-07-01 21:26:54 +02008235
Johannes Berg074ac8d2010-09-16 14:58:22 +02008236 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02008237 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
8238 return -EOPNOTSUPP;
Samuel Ortizb23aa672009-07-01 21:26:54 +02008239
Johannes Berg79c97e92009-07-07 03:56:12 +02008240 wiphy = &rdev->wiphy;
Samuel Ortizb23aa672009-07-01 21:26:54 +02008241
Bala Shanmugam4486ea92012-03-07 17:27:12 +05308242 connect.bg_scan_period = -1;
8243 if (info->attrs[NL80211_ATTR_BG_SCAN_PERIOD] &&
8244 (wiphy->flags & WIPHY_FLAG_SUPPORTS_FW_ROAM)) {
8245 connect.bg_scan_period =
8246 nla_get_u16(info->attrs[NL80211_ATTR_BG_SCAN_PERIOD]);
8247 }
8248
Samuel Ortizb23aa672009-07-01 21:26:54 +02008249 if (info->attrs[NL80211_ATTR_MAC])
8250 connect.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen1df4a512014-01-15 00:00:47 +02008251 else if (info->attrs[NL80211_ATTR_MAC_HINT])
8252 connect.bssid_hint =
8253 nla_data(info->attrs[NL80211_ATTR_MAC_HINT]);
Samuel Ortizb23aa672009-07-01 21:26:54 +02008254 connect.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
8255 connect.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
8256
8257 if (info->attrs[NL80211_ATTR_IE]) {
8258 connect.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
8259 connect.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
8260 }
8261
Jouni Malinencee00a92013-01-15 17:15:57 +02008262 if (info->attrs[NL80211_ATTR_USE_MFP]) {
8263 connect.mfp = nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]);
8264 if (connect.mfp != NL80211_MFP_REQUIRED &&
8265 connect.mfp != NL80211_MFP_NO)
8266 return -EINVAL;
8267 } else {
8268 connect.mfp = NL80211_MFP_NO;
8269 }
8270
Jouni Malinenba6fbac2016-03-29 13:53:27 +03008271 if (info->attrs[NL80211_ATTR_PREV_BSSID])
8272 connect.prev_bssid =
8273 nla_data(info->attrs[NL80211_ATTR_PREV_BSSID]);
8274
Samuel Ortizb23aa672009-07-01 21:26:54 +02008275 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
Jouni Malinen664834d2014-01-15 00:01:44 +02008276 connect.channel = nl80211_get_valid_chan(
8277 wiphy, info->attrs[NL80211_ATTR_WIPHY_FREQ]);
8278 if (!connect.channel)
Johannes Berg4c476992010-10-04 21:36:35 +02008279 return -EINVAL;
Jouni Malinen1df4a512014-01-15 00:00:47 +02008280 } else if (info->attrs[NL80211_ATTR_WIPHY_FREQ_HINT]) {
Jouni Malinen664834d2014-01-15 00:01:44 +02008281 connect.channel_hint = nl80211_get_valid_chan(
8282 wiphy, info->attrs[NL80211_ATTR_WIPHY_FREQ_HINT]);
8283 if (!connect.channel_hint)
Jouni Malinen1df4a512014-01-15 00:00:47 +02008284 return -EINVAL;
Samuel Ortizb23aa672009-07-01 21:26:54 +02008285 }
8286
Johannes Bergfffd0932009-07-08 14:22:54 +02008287 if (connect.privacy && info->attrs[NL80211_ATTR_KEYS]) {
8288 connkeys = nl80211_parse_connkeys(rdev,
Sujith Manoharande7044e2012-10-18 10:19:28 +05308289 info->attrs[NL80211_ATTR_KEYS], NULL);
Johannes Berg4c476992010-10-04 21:36:35 +02008290 if (IS_ERR(connkeys))
8291 return PTR_ERR(connkeys);
Johannes Bergfffd0932009-07-08 14:22:54 +02008292 }
8293
Ben Greear7e7c8922011-11-18 11:31:59 -08008294 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT]))
8295 connect.flags |= ASSOC_REQ_DISABLE_HT;
8296
8297 if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
8298 memcpy(&connect.ht_capa_mask,
8299 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]),
8300 sizeof(connect.ht_capa_mask));
8301
8302 if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) {
Wei Yongjunb4e4f472012-09-02 21:41:04 +08008303 if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) {
Johannes Bergb47f6102014-09-10 13:39:54 +03008304 kzfree(connkeys);
Ben Greear7e7c8922011-11-18 11:31:59 -08008305 return -EINVAL;
Wei Yongjunb4e4f472012-09-02 21:41:04 +08008306 }
Ben Greear7e7c8922011-11-18 11:31:59 -08008307 memcpy(&connect.ht_capa,
8308 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]),
8309 sizeof(connect.ht_capa));
8310 }
8311
Johannes Bergee2aca32013-02-21 17:36:01 +01008312 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_VHT]))
8313 connect.flags |= ASSOC_REQ_DISABLE_VHT;
8314
8315 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK])
8316 memcpy(&connect.vht_capa_mask,
8317 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]),
8318 sizeof(connect.vht_capa_mask));
8319
8320 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) {
8321 if (!info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) {
Johannes Bergb47f6102014-09-10 13:39:54 +03008322 kzfree(connkeys);
Johannes Bergee2aca32013-02-21 17:36:01 +01008323 return -EINVAL;
8324 }
8325 memcpy(&connect.vht_capa,
8326 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]),
8327 sizeof(connect.vht_capa));
8328 }
8329
Assaf Kraussbab5ab72014-09-03 15:25:01 +03008330 if (nla_get_flag(info->attrs[NL80211_ATTR_USE_RRM])) {
Beni Lev0c9ca112016-02-17 20:30:00 +02008331 if (!((rdev->wiphy.features &
8332 NL80211_FEATURE_DS_PARAM_SET_IE_IN_PROBES) &&
8333 (rdev->wiphy.features & NL80211_FEATURE_QUIET)) &&
8334 !wiphy_ext_feature_isset(&rdev->wiphy,
8335 NL80211_EXT_FEATURE_RRM)) {
Ola Olsson707554b2015-12-11 21:04:52 +01008336 kzfree(connkeys);
Assaf Kraussbab5ab72014-09-03 15:25:01 +03008337 return -EINVAL;
Ola Olsson707554b2015-12-11 21:04:52 +01008338 }
Assaf Kraussbab5ab72014-09-03 15:25:01 +03008339 connect.flags |= ASSOC_REQ_USE_RRM;
8340 }
8341
Lior David34d50512016-01-28 10:58:25 +02008342 connect.pbss = nla_get_flag(info->attrs[NL80211_ATTR_PBSS]);
Johannes Berg57fbcce2016-04-12 15:56:15 +02008343 if (connect.pbss && !rdev->wiphy.bands[NL80211_BAND_60GHZ]) {
Lior David34d50512016-01-28 10:58:25 +02008344 kzfree(connkeys);
8345 return -EOPNOTSUPP;
8346 }
8347
Arend van Spriel38de03d2016-03-02 20:37:18 +01008348 if (info->attrs[NL80211_ATTR_BSS_SELECT]) {
8349 /* bss selection makes no sense if bssid is set */
8350 if (connect.bssid) {
8351 kzfree(connkeys);
8352 return -EINVAL;
8353 }
8354
8355 err = parse_bss_select(info->attrs[NL80211_ATTR_BSS_SELECT],
8356 wiphy, &connect.bss_select);
8357 if (err) {
8358 kzfree(connkeys);
8359 return err;
8360 }
8361 }
8362
Johannes Berg83739b02013-05-15 17:44:01 +02008363 wdev_lock(dev->ieee80211_ptr);
Jouni Malinen4ce2bd92016-03-29 13:53:28 +03008364 err = cfg80211_connect(rdev, dev, &connect, connkeys,
8365 connect.prev_bssid);
Johannes Berg83739b02013-05-15 17:44:01 +02008366 wdev_unlock(dev->ieee80211_ptr);
Johannes Bergfffd0932009-07-08 14:22:54 +02008367 if (err)
Johannes Bergb47f6102014-09-10 13:39:54 +03008368 kzfree(connkeys);
Samuel Ortizb23aa672009-07-01 21:26:54 +02008369 return err;
8370}
8371
8372static int nl80211_disconnect(struct sk_buff *skb, struct genl_info *info)
8373{
Johannes Berg4c476992010-10-04 21:36:35 +02008374 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8375 struct net_device *dev = info->user_ptr[1];
Samuel Ortizb23aa672009-07-01 21:26:54 +02008376 u16 reason;
Johannes Berg83739b02013-05-15 17:44:01 +02008377 int ret;
Samuel Ortizb23aa672009-07-01 21:26:54 +02008378
8379 if (!info->attrs[NL80211_ATTR_REASON_CODE])
8380 reason = WLAN_REASON_DEAUTH_LEAVING;
8381 else
8382 reason = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
8383
8384 if (reason == 0)
8385 return -EINVAL;
8386
Johannes Berg074ac8d2010-09-16 14:58:22 +02008387 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02008388 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
8389 return -EOPNOTSUPP;
Samuel Ortizb23aa672009-07-01 21:26:54 +02008390
Johannes Berg83739b02013-05-15 17:44:01 +02008391 wdev_lock(dev->ieee80211_ptr);
8392 ret = cfg80211_disconnect(rdev, dev, reason, true);
8393 wdev_unlock(dev->ieee80211_ptr);
8394 return ret;
Samuel Ortizb23aa672009-07-01 21:26:54 +02008395}
8396
Johannes Berg463d0182009-07-14 00:33:35 +02008397static int nl80211_wiphy_netns(struct sk_buff *skb, struct genl_info *info)
8398{
Johannes Berg4c476992010-10-04 21:36:35 +02008399 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg463d0182009-07-14 00:33:35 +02008400 struct net *net;
8401 int err;
Johannes Berg463d0182009-07-14 00:33:35 +02008402
Vadim Kochan4b681c82015-01-12 16:34:05 +02008403 if (info->attrs[NL80211_ATTR_PID]) {
8404 u32 pid = nla_get_u32(info->attrs[NL80211_ATTR_PID]);
8405
8406 net = get_net_ns_by_pid(pid);
8407 } else if (info->attrs[NL80211_ATTR_NETNS_FD]) {
8408 u32 fd = nla_get_u32(info->attrs[NL80211_ATTR_NETNS_FD]);
8409
8410 net = get_net_ns_by_fd(fd);
8411 } else {
Johannes Berg463d0182009-07-14 00:33:35 +02008412 return -EINVAL;
Vadim Kochan4b681c82015-01-12 16:34:05 +02008413 }
Johannes Berg463d0182009-07-14 00:33:35 +02008414
Johannes Berg4c476992010-10-04 21:36:35 +02008415 if (IS_ERR(net))
8416 return PTR_ERR(net);
Johannes Berg463d0182009-07-14 00:33:35 +02008417
8418 err = 0;
8419
8420 /* check if anything to do */
Johannes Berg4c476992010-10-04 21:36:35 +02008421 if (!net_eq(wiphy_net(&rdev->wiphy), net))
8422 err = cfg80211_switch_netns(rdev, net);
Johannes Berg463d0182009-07-14 00:33:35 +02008423
Johannes Berg463d0182009-07-14 00:33:35 +02008424 put_net(net);
Johannes Berg463d0182009-07-14 00:33:35 +02008425 return err;
8426}
8427
Samuel Ortiz67fbb162009-11-24 23:59:15 +01008428static int nl80211_setdel_pmksa(struct sk_buff *skb, struct genl_info *info)
8429{
Johannes Berg4c476992010-10-04 21:36:35 +02008430 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Samuel Ortiz67fbb162009-11-24 23:59:15 +01008431 int (*rdev_ops)(struct wiphy *wiphy, struct net_device *dev,
8432 struct cfg80211_pmksa *pmksa) = NULL;
Johannes Berg4c476992010-10-04 21:36:35 +02008433 struct net_device *dev = info->user_ptr[1];
Samuel Ortiz67fbb162009-11-24 23:59:15 +01008434 struct cfg80211_pmksa pmksa;
8435
8436 memset(&pmksa, 0, sizeof(struct cfg80211_pmksa));
8437
8438 if (!info->attrs[NL80211_ATTR_MAC])
8439 return -EINVAL;
8440
8441 if (!info->attrs[NL80211_ATTR_PMKID])
8442 return -EINVAL;
8443
Samuel Ortiz67fbb162009-11-24 23:59:15 +01008444 pmksa.pmkid = nla_data(info->attrs[NL80211_ATTR_PMKID]);
8445 pmksa.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
8446
Johannes Berg074ac8d2010-09-16 14:58:22 +02008447 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02008448 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
8449 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01008450
8451 switch (info->genlhdr->cmd) {
8452 case NL80211_CMD_SET_PMKSA:
8453 rdev_ops = rdev->ops->set_pmksa;
8454 break;
8455 case NL80211_CMD_DEL_PMKSA:
8456 rdev_ops = rdev->ops->del_pmksa;
8457 break;
8458 default:
8459 WARN_ON(1);
8460 break;
8461 }
8462
Johannes Berg4c476992010-10-04 21:36:35 +02008463 if (!rdev_ops)
8464 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01008465
Johannes Berg4c476992010-10-04 21:36:35 +02008466 return rdev_ops(&rdev->wiphy, dev, &pmksa);
Samuel Ortiz67fbb162009-11-24 23:59:15 +01008467}
8468
8469static int nl80211_flush_pmksa(struct sk_buff *skb, struct genl_info *info)
8470{
Johannes Berg4c476992010-10-04 21:36:35 +02008471 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8472 struct net_device *dev = info->user_ptr[1];
Samuel Ortiz67fbb162009-11-24 23:59:15 +01008473
Johannes Berg074ac8d2010-09-16 14:58:22 +02008474 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02008475 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
8476 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01008477
Johannes Berg4c476992010-10-04 21:36:35 +02008478 if (!rdev->ops->flush_pmksa)
8479 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01008480
Hila Gonene35e4d22012-06-27 17:19:42 +03008481 return rdev_flush_pmksa(rdev, dev);
Samuel Ortiz67fbb162009-11-24 23:59:15 +01008482}
8483
Arik Nemtsov109086c2011-09-28 14:12:50 +03008484static int nl80211_tdls_mgmt(struct sk_buff *skb, struct genl_info *info)
8485{
8486 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8487 struct net_device *dev = info->user_ptr[1];
8488 u8 action_code, dialog_token;
Sunil Dutt Undekaridf942e72014-02-20 16:22:09 +05308489 u32 peer_capability = 0;
Arik Nemtsov109086c2011-09-28 14:12:50 +03008490 u16 status_code;
8491 u8 *peer;
Arik Nemtsov31fa97c2014-06-11 17:18:21 +03008492 bool initiator;
Arik Nemtsov109086c2011-09-28 14:12:50 +03008493
8494 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) ||
8495 !rdev->ops->tdls_mgmt)
8496 return -EOPNOTSUPP;
8497
8498 if (!info->attrs[NL80211_ATTR_TDLS_ACTION] ||
8499 !info->attrs[NL80211_ATTR_STATUS_CODE] ||
8500 !info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN] ||
8501 !info->attrs[NL80211_ATTR_IE] ||
8502 !info->attrs[NL80211_ATTR_MAC])
8503 return -EINVAL;
8504
8505 peer = nla_data(info->attrs[NL80211_ATTR_MAC]);
8506 action_code = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_ACTION]);
8507 status_code = nla_get_u16(info->attrs[NL80211_ATTR_STATUS_CODE]);
8508 dialog_token = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN]);
Arik Nemtsov31fa97c2014-06-11 17:18:21 +03008509 initiator = nla_get_flag(info->attrs[NL80211_ATTR_TDLS_INITIATOR]);
Sunil Dutt Undekaridf942e72014-02-20 16:22:09 +05308510 if (info->attrs[NL80211_ATTR_TDLS_PEER_CAPABILITY])
8511 peer_capability =
8512 nla_get_u32(info->attrs[NL80211_ATTR_TDLS_PEER_CAPABILITY]);
Arik Nemtsov109086c2011-09-28 14:12:50 +03008513
Hila Gonene35e4d22012-06-27 17:19:42 +03008514 return rdev_tdls_mgmt(rdev, dev, peer, action_code,
Sunil Dutt Undekaridf942e72014-02-20 16:22:09 +05308515 dialog_token, status_code, peer_capability,
Arik Nemtsov31fa97c2014-06-11 17:18:21 +03008516 initiator,
Hila Gonene35e4d22012-06-27 17:19:42 +03008517 nla_data(info->attrs[NL80211_ATTR_IE]),
8518 nla_len(info->attrs[NL80211_ATTR_IE]));
Arik Nemtsov109086c2011-09-28 14:12:50 +03008519}
8520
8521static int nl80211_tdls_oper(struct sk_buff *skb, struct genl_info *info)
8522{
8523 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8524 struct net_device *dev = info->user_ptr[1];
8525 enum nl80211_tdls_operation operation;
8526 u8 *peer;
8527
8528 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) ||
8529 !rdev->ops->tdls_oper)
8530 return -EOPNOTSUPP;
8531
8532 if (!info->attrs[NL80211_ATTR_TDLS_OPERATION] ||
8533 !info->attrs[NL80211_ATTR_MAC])
8534 return -EINVAL;
8535
8536 operation = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_OPERATION]);
8537 peer = nla_data(info->attrs[NL80211_ATTR_MAC]);
8538
Hila Gonene35e4d22012-06-27 17:19:42 +03008539 return rdev_tdls_oper(rdev, dev, peer, operation);
Arik Nemtsov109086c2011-09-28 14:12:50 +03008540}
8541
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008542static int nl80211_remain_on_channel(struct sk_buff *skb,
8543 struct genl_info *info)
8544{
Johannes Berg4c476992010-10-04 21:36:35 +02008545 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02008546 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg683b6d32012-11-08 21:25:48 +01008547 struct cfg80211_chan_def chandef;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008548 struct sk_buff *msg;
8549 void *hdr;
8550 u64 cookie;
Johannes Berg683b6d32012-11-08 21:25:48 +01008551 u32 duration;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008552 int err;
8553
8554 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] ||
8555 !info->attrs[NL80211_ATTR_DURATION])
8556 return -EINVAL;
8557
8558 duration = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]);
8559
Johannes Berg7c4ef712011-11-18 15:33:48 +01008560 if (!rdev->ops->remain_on_channel ||
8561 !(rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL))
Johannes Berg4c476992010-10-04 21:36:35 +02008562 return -EOPNOTSUPP;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008563
Johannes Bergebf348f2012-06-01 12:50:54 +02008564 /*
8565 * We should be on that channel for at least a minimum amount of
8566 * time (10ms) but no longer than the driver supports.
8567 */
8568 if (duration < NL80211_MIN_REMAIN_ON_CHANNEL_TIME ||
8569 duration > rdev->wiphy.max_remain_on_channel_duration)
8570 return -EINVAL;
8571
Johannes Berg683b6d32012-11-08 21:25:48 +01008572 err = nl80211_parse_chandef(rdev, info, &chandef);
8573 if (err)
8574 return err;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008575
8576 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02008577 if (!msg)
8578 return -ENOMEM;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008579
Eric W. Biederman15e47302012-09-07 20:12:54 +00008580 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008581 NL80211_CMD_REMAIN_ON_CHANNEL);
Dan Carpentercb35fba2013-08-14 14:50:01 +03008582 if (!hdr) {
8583 err = -ENOBUFS;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008584 goto free_msg;
8585 }
8586
Johannes Berg683b6d32012-11-08 21:25:48 +01008587 err = rdev_remain_on_channel(rdev, wdev, chandef.chan,
8588 duration, &cookie);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008589
8590 if (err)
8591 goto free_msg;
8592
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02008593 if (nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie,
8594 NL80211_ATTR_PAD))
David S. Miller9360ffd2012-03-29 04:41:26 -04008595 goto nla_put_failure;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008596
8597 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02008598
8599 return genlmsg_reply(msg, info);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008600
8601 nla_put_failure:
8602 err = -ENOBUFS;
8603 free_msg:
8604 nlmsg_free(msg);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008605 return err;
8606}
8607
8608static int nl80211_cancel_remain_on_channel(struct sk_buff *skb,
8609 struct genl_info *info)
8610{
Johannes Berg4c476992010-10-04 21:36:35 +02008611 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02008612 struct wireless_dev *wdev = info->user_ptr[1];
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008613 u64 cookie;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008614
8615 if (!info->attrs[NL80211_ATTR_COOKIE])
8616 return -EINVAL;
8617
Johannes Berg4c476992010-10-04 21:36:35 +02008618 if (!rdev->ops->cancel_remain_on_channel)
8619 return -EOPNOTSUPP;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008620
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008621 cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]);
8622
Hila Gonene35e4d22012-06-27 17:19:42 +03008623 return rdev_cancel_remain_on_channel(rdev, wdev, cookie);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008624}
8625
Jouni Malinen13ae75b2009-12-29 12:59:45 +02008626static u32 rateset_to_mask(struct ieee80211_supported_band *sband,
8627 u8 *rates, u8 rates_len)
8628{
8629 u8 i;
8630 u32 mask = 0;
8631
8632 for (i = 0; i < rates_len; i++) {
8633 int rate = (rates[i] & 0x7f) * 5;
8634 int ridx;
Kirtika Ruchandani7a087e72016-05-29 19:51:23 -07008635
Jouni Malinen13ae75b2009-12-29 12:59:45 +02008636 for (ridx = 0; ridx < sband->n_bitrates; ridx++) {
8637 struct ieee80211_rate *srate =
8638 &sband->bitrates[ridx];
8639 if (rate == srate->bitrate) {
8640 mask |= 1 << ridx;
8641 break;
8642 }
8643 }
8644 if (ridx == sband->n_bitrates)
8645 return 0; /* rate not found */
8646 }
8647
8648 return mask;
8649}
8650
Simon Wunderlich24db78c2012-01-28 17:25:32 +01008651static bool ht_rateset_to_mask(struct ieee80211_supported_band *sband,
8652 u8 *rates, u8 rates_len,
8653 u8 mcs[IEEE80211_HT_MCS_MASK_LEN])
8654{
8655 u8 i;
8656
8657 memset(mcs, 0, IEEE80211_HT_MCS_MASK_LEN);
8658
8659 for (i = 0; i < rates_len; i++) {
8660 int ridx, rbit;
8661
8662 ridx = rates[i] / 8;
8663 rbit = BIT(rates[i] % 8);
8664
8665 /* check validity */
Dan Carpenter910570b52012-02-01 10:42:11 +03008666 if ((ridx < 0) || (ridx >= IEEE80211_HT_MCS_MASK_LEN))
Simon Wunderlich24db78c2012-01-28 17:25:32 +01008667 return false;
8668
8669 /* check availability */
8670 if (sband->ht_cap.mcs.rx_mask[ridx] & rbit)
8671 mcs[ridx] |= rbit;
8672 else
8673 return false;
8674 }
8675
8676 return true;
8677}
8678
Janusz Dziedzic204e35a2013-12-05 20:42:58 +01008679static u16 vht_mcs_map_to_mcs_mask(u8 vht_mcs_map)
8680{
8681 u16 mcs_mask = 0;
8682
8683 switch (vht_mcs_map) {
8684 case IEEE80211_VHT_MCS_NOT_SUPPORTED:
8685 break;
8686 case IEEE80211_VHT_MCS_SUPPORT_0_7:
8687 mcs_mask = 0x00FF;
8688 break;
8689 case IEEE80211_VHT_MCS_SUPPORT_0_8:
8690 mcs_mask = 0x01FF;
8691 break;
8692 case IEEE80211_VHT_MCS_SUPPORT_0_9:
8693 mcs_mask = 0x03FF;
8694 break;
8695 default:
8696 break;
8697 }
8698
8699 return mcs_mask;
8700}
8701
8702static void vht_build_mcs_mask(u16 vht_mcs_map,
8703 u16 vht_mcs_mask[NL80211_VHT_NSS_MAX])
8704{
8705 u8 nss;
8706
8707 for (nss = 0; nss < NL80211_VHT_NSS_MAX; nss++) {
8708 vht_mcs_mask[nss] = vht_mcs_map_to_mcs_mask(vht_mcs_map & 0x03);
8709 vht_mcs_map >>= 2;
8710 }
8711}
8712
8713static bool vht_set_mcs_mask(struct ieee80211_supported_band *sband,
8714 struct nl80211_txrate_vht *txrate,
8715 u16 mcs[NL80211_VHT_NSS_MAX])
8716{
8717 u16 tx_mcs_map = le16_to_cpu(sband->vht_cap.vht_mcs.tx_mcs_map);
8718 u16 tx_mcs_mask[NL80211_VHT_NSS_MAX] = {};
8719 u8 i;
8720
8721 if (!sband->vht_cap.vht_supported)
8722 return false;
8723
8724 memset(mcs, 0, sizeof(u16) * NL80211_VHT_NSS_MAX);
8725
8726 /* Build vht_mcs_mask from VHT capabilities */
8727 vht_build_mcs_mask(tx_mcs_map, tx_mcs_mask);
8728
8729 for (i = 0; i < NL80211_VHT_NSS_MAX; i++) {
8730 if ((tx_mcs_mask[i] & txrate->mcs[i]) == txrate->mcs[i])
8731 mcs[i] = txrate->mcs[i];
8732 else
8733 return false;
8734 }
8735
8736 return true;
8737}
8738
Alexey Dobriyanb54452b2010-02-18 08:14:31 +00008739static const struct nla_policy nl80211_txattr_policy[NL80211_TXRATE_MAX + 1] = {
Jouni Malinen13ae75b2009-12-29 12:59:45 +02008740 [NL80211_TXRATE_LEGACY] = { .type = NLA_BINARY,
8741 .len = NL80211_MAX_SUPP_RATES },
Janusz Dziedzicd1e33e62013-12-05 10:02:15 +01008742 [NL80211_TXRATE_HT] = { .type = NLA_BINARY,
8743 .len = NL80211_MAX_SUPP_HT_RATES },
Janusz Dziedzic204e35a2013-12-05 20:42:58 +01008744 [NL80211_TXRATE_VHT] = { .len = sizeof(struct nl80211_txrate_vht)},
Janusz Dziedzic0b9323f2014-01-08 08:46:02 +01008745 [NL80211_TXRATE_GI] = { .type = NLA_U8 },
Jouni Malinen13ae75b2009-12-29 12:59:45 +02008746};
8747
8748static int nl80211_set_tx_bitrate_mask(struct sk_buff *skb,
8749 struct genl_info *info)
8750{
8751 struct nlattr *tb[NL80211_TXRATE_MAX + 1];
Johannes Berg4c476992010-10-04 21:36:35 +02008752 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Jouni Malinen13ae75b2009-12-29 12:59:45 +02008753 struct cfg80211_bitrate_mask mask;
Johannes Berg4c476992010-10-04 21:36:35 +02008754 int rem, i;
8755 struct net_device *dev = info->user_ptr[1];
Jouni Malinen13ae75b2009-12-29 12:59:45 +02008756 struct nlattr *tx_rates;
8757 struct ieee80211_supported_band *sband;
Janusz Dziedzic204e35a2013-12-05 20:42:58 +01008758 u16 vht_tx_mcs_map;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02008759
Johannes Berg4c476992010-10-04 21:36:35 +02008760 if (!rdev->ops->set_bitrate_mask)
8761 return -EOPNOTSUPP;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02008762
8763 memset(&mask, 0, sizeof(mask));
8764 /* Default to all rates enabled */
Johannes Berg57fbcce2016-04-12 15:56:15 +02008765 for (i = 0; i < NUM_NL80211_BANDS; i++) {
Jouni Malinen13ae75b2009-12-29 12:59:45 +02008766 sband = rdev->wiphy.bands[i];
Janusz Dziedzic78693032013-12-03 09:50:44 +01008767
8768 if (!sband)
8769 continue;
8770
8771 mask.control[i].legacy = (1 << sband->n_bitrates) - 1;
Janusz Dziedzicd1e33e62013-12-05 10:02:15 +01008772 memcpy(mask.control[i].ht_mcs,
Janusz Dziedzic78693032013-12-03 09:50:44 +01008773 sband->ht_cap.mcs.rx_mask,
Janusz Dziedzicd1e33e62013-12-05 10:02:15 +01008774 sizeof(mask.control[i].ht_mcs));
Janusz Dziedzic204e35a2013-12-05 20:42:58 +01008775
8776 if (!sband->vht_cap.vht_supported)
8777 continue;
8778
8779 vht_tx_mcs_map = le16_to_cpu(sband->vht_cap.vht_mcs.tx_mcs_map);
8780 vht_build_mcs_mask(vht_tx_mcs_map, mask.control[i].vht_mcs);
Jouni Malinen13ae75b2009-12-29 12:59:45 +02008781 }
8782
Janusz Dziedzicb9243ab2013-12-05 10:02:14 +01008783 /* if no rates are given set it back to the defaults */
8784 if (!info->attrs[NL80211_ATTR_TX_RATES])
8785 goto out;
8786
Jouni Malinen13ae75b2009-12-29 12:59:45 +02008787 /*
8788 * The nested attribute uses enum nl80211_band as the index. This maps
Johannes Berg57fbcce2016-04-12 15:56:15 +02008789 * directly to the enum nl80211_band values used in cfg80211.
Jouni Malinen13ae75b2009-12-29 12:59:45 +02008790 */
Simon Wunderlich24db78c2012-01-28 17:25:32 +01008791 BUILD_BUG_ON(NL80211_MAX_SUPP_HT_RATES > IEEE80211_HT_MCS_MASK_LEN * 8);
Johannes Bergae811e22014-01-24 10:17:47 +01008792 nla_for_each_nested(tx_rates, info->attrs[NL80211_ATTR_TX_RATES], rem) {
Johannes Berg57fbcce2016-04-12 15:56:15 +02008793 enum nl80211_band band = nla_type(tx_rates);
Johannes Bergae811e22014-01-24 10:17:47 +01008794 int err;
8795
Johannes Berg57fbcce2016-04-12 15:56:15 +02008796 if (band < 0 || band >= NUM_NL80211_BANDS)
Johannes Berg4c476992010-10-04 21:36:35 +02008797 return -EINVAL;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02008798 sband = rdev->wiphy.bands[band];
Johannes Berg4c476992010-10-04 21:36:35 +02008799 if (sband == NULL)
8800 return -EINVAL;
Johannes Bergae811e22014-01-24 10:17:47 +01008801 err = nla_parse(tb, NL80211_TXRATE_MAX, nla_data(tx_rates),
8802 nla_len(tx_rates), nl80211_txattr_policy);
8803 if (err)
8804 return err;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02008805 if (tb[NL80211_TXRATE_LEGACY]) {
8806 mask.control[band].legacy = rateset_to_mask(
8807 sband,
8808 nla_data(tb[NL80211_TXRATE_LEGACY]),
8809 nla_len(tb[NL80211_TXRATE_LEGACY]));
Bala Shanmugam218d2e22012-04-20 19:12:58 +05308810 if ((mask.control[band].legacy == 0) &&
8811 nla_len(tb[NL80211_TXRATE_LEGACY]))
8812 return -EINVAL;
Simon Wunderlich24db78c2012-01-28 17:25:32 +01008813 }
Janusz Dziedzicd1e33e62013-12-05 10:02:15 +01008814 if (tb[NL80211_TXRATE_HT]) {
Simon Wunderlich24db78c2012-01-28 17:25:32 +01008815 if (!ht_rateset_to_mask(
8816 sband,
Janusz Dziedzicd1e33e62013-12-05 10:02:15 +01008817 nla_data(tb[NL80211_TXRATE_HT]),
8818 nla_len(tb[NL80211_TXRATE_HT]),
8819 mask.control[band].ht_mcs))
Simon Wunderlich24db78c2012-01-28 17:25:32 +01008820 return -EINVAL;
8821 }
Janusz Dziedzic204e35a2013-12-05 20:42:58 +01008822 if (tb[NL80211_TXRATE_VHT]) {
8823 if (!vht_set_mcs_mask(
8824 sband,
8825 nla_data(tb[NL80211_TXRATE_VHT]),
8826 mask.control[band].vht_mcs))
8827 return -EINVAL;
8828 }
Janusz Dziedzic0b9323f2014-01-08 08:46:02 +01008829 if (tb[NL80211_TXRATE_GI]) {
8830 mask.control[band].gi =
8831 nla_get_u8(tb[NL80211_TXRATE_GI]);
8832 if (mask.control[band].gi > NL80211_TXRATE_FORCE_LGI)
8833 return -EINVAL;
8834 }
Simon Wunderlich24db78c2012-01-28 17:25:32 +01008835
8836 if (mask.control[band].legacy == 0) {
Janusz Dziedzic204e35a2013-12-05 20:42:58 +01008837 /* don't allow empty legacy rates if HT or VHT
8838 * are not even supported.
8839 */
8840 if (!(rdev->wiphy.bands[band]->ht_cap.ht_supported ||
8841 rdev->wiphy.bands[band]->vht_cap.vht_supported))
Simon Wunderlich24db78c2012-01-28 17:25:32 +01008842 return -EINVAL;
8843
8844 for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++)
Janusz Dziedzicd1e33e62013-12-05 10:02:15 +01008845 if (mask.control[band].ht_mcs[i])
Janusz Dziedzic204e35a2013-12-05 20:42:58 +01008846 goto out;
8847
8848 for (i = 0; i < NL80211_VHT_NSS_MAX; i++)
8849 if (mask.control[band].vht_mcs[i])
8850 goto out;
Simon Wunderlich24db78c2012-01-28 17:25:32 +01008851
8852 /* legacy and mcs rates may not be both empty */
Janusz Dziedzic204e35a2013-12-05 20:42:58 +01008853 return -EINVAL;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02008854 }
8855 }
8856
Janusz Dziedzicb9243ab2013-12-05 10:02:14 +01008857out:
Hila Gonene35e4d22012-06-27 17:19:42 +03008858 return rdev_set_bitrate_mask(rdev, dev, NULL, &mask);
Jouni Malinen13ae75b2009-12-29 12:59:45 +02008859}
8860
Johannes Berg2e161f72010-08-12 15:38:38 +02008861static int nl80211_register_mgmt(struct sk_buff *skb, struct genl_info *info)
Jouni Malinen026331c2010-02-15 12:53:10 +02008862{
Johannes Berg4c476992010-10-04 21:36:35 +02008863 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02008864 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg2e161f72010-08-12 15:38:38 +02008865 u16 frame_type = IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_ACTION;
Jouni Malinen026331c2010-02-15 12:53:10 +02008866
8867 if (!info->attrs[NL80211_ATTR_FRAME_MATCH])
8868 return -EINVAL;
8869
Johannes Berg2e161f72010-08-12 15:38:38 +02008870 if (info->attrs[NL80211_ATTR_FRAME_TYPE])
8871 frame_type = nla_get_u16(info->attrs[NL80211_ATTR_FRAME_TYPE]);
Jouni Malinen026331c2010-02-15 12:53:10 +02008872
Johannes Berg71bbc992012-06-15 15:30:18 +02008873 switch (wdev->iftype) {
8874 case NL80211_IFTYPE_STATION:
8875 case NL80211_IFTYPE_ADHOC:
8876 case NL80211_IFTYPE_P2P_CLIENT:
8877 case NL80211_IFTYPE_AP:
8878 case NL80211_IFTYPE_AP_VLAN:
8879 case NL80211_IFTYPE_MESH_POINT:
8880 case NL80211_IFTYPE_P2P_GO:
Johannes Berg98104fde2012-06-16 00:19:54 +02008881 case NL80211_IFTYPE_P2P_DEVICE:
Johannes Berg71bbc992012-06-15 15:30:18 +02008882 break;
8883 default:
Johannes Berg4c476992010-10-04 21:36:35 +02008884 return -EOPNOTSUPP;
Johannes Berg71bbc992012-06-15 15:30:18 +02008885 }
Jouni Malinen026331c2010-02-15 12:53:10 +02008886
8887 /* not much point in registering if we can't reply */
Johannes Berg4c476992010-10-04 21:36:35 +02008888 if (!rdev->ops->mgmt_tx)
8889 return -EOPNOTSUPP;
Jouni Malinen026331c2010-02-15 12:53:10 +02008890
Eric W. Biederman15e47302012-09-07 20:12:54 +00008891 return cfg80211_mlme_register_mgmt(wdev, info->snd_portid, frame_type,
Jouni Malinen026331c2010-02-15 12:53:10 +02008892 nla_data(info->attrs[NL80211_ATTR_FRAME_MATCH]),
8893 nla_len(info->attrs[NL80211_ATTR_FRAME_MATCH]));
Jouni Malinen026331c2010-02-15 12:53:10 +02008894}
8895
Johannes Berg2e161f72010-08-12 15:38:38 +02008896static int nl80211_tx_mgmt(struct sk_buff *skb, struct genl_info *info)
Jouni Malinen026331c2010-02-15 12:53:10 +02008897{
Johannes Berg4c476992010-10-04 21:36:35 +02008898 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02008899 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg683b6d32012-11-08 21:25:48 +01008900 struct cfg80211_chan_def chandef;
Jouni Malinen026331c2010-02-15 12:53:10 +02008901 int err;
Johannes Bergd64d3732011-11-10 09:44:46 +01008902 void *hdr = NULL;
Jouni Malinen026331c2010-02-15 12:53:10 +02008903 u64 cookie;
Johannes Berge247bd902011-11-04 11:18:21 +01008904 struct sk_buff *msg = NULL;
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02008905 struct cfg80211_mgmt_tx_params params = {
8906 .dont_wait_for_ack =
8907 info->attrs[NL80211_ATTR_DONT_WAIT_FOR_ACK],
8908 };
Jouni Malinen026331c2010-02-15 12:53:10 +02008909
Johannes Berg683b6d32012-11-08 21:25:48 +01008910 if (!info->attrs[NL80211_ATTR_FRAME])
Jouni Malinen026331c2010-02-15 12:53:10 +02008911 return -EINVAL;
8912
Johannes Berg4c476992010-10-04 21:36:35 +02008913 if (!rdev->ops->mgmt_tx)
8914 return -EOPNOTSUPP;
Jouni Malinen026331c2010-02-15 12:53:10 +02008915
Johannes Berg71bbc992012-06-15 15:30:18 +02008916 switch (wdev->iftype) {
Antonio Quartulliea141b752013-06-11 14:20:03 +02008917 case NL80211_IFTYPE_P2P_DEVICE:
8918 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ])
8919 return -EINVAL;
Johannes Berg71bbc992012-06-15 15:30:18 +02008920 case NL80211_IFTYPE_STATION:
8921 case NL80211_IFTYPE_ADHOC:
8922 case NL80211_IFTYPE_P2P_CLIENT:
8923 case NL80211_IFTYPE_AP:
8924 case NL80211_IFTYPE_AP_VLAN:
8925 case NL80211_IFTYPE_MESH_POINT:
8926 case NL80211_IFTYPE_P2P_GO:
8927 break;
8928 default:
Johannes Berg4c476992010-10-04 21:36:35 +02008929 return -EOPNOTSUPP;
Johannes Berg71bbc992012-06-15 15:30:18 +02008930 }
Jouni Malinen026331c2010-02-15 12:53:10 +02008931
Johannes Bergf7ca38d2010-11-25 10:02:29 +01008932 if (info->attrs[NL80211_ATTR_DURATION]) {
Johannes Berg7c4ef712011-11-18 15:33:48 +01008933 if (!(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX))
Johannes Bergf7ca38d2010-11-25 10:02:29 +01008934 return -EINVAL;
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02008935 params.wait = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]);
Johannes Bergebf348f2012-06-01 12:50:54 +02008936
8937 /*
8938 * We should wait on the channel for at least a minimum amount
8939 * of time (10ms) but no longer than the driver supports.
8940 */
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02008941 if (params.wait < NL80211_MIN_REMAIN_ON_CHANNEL_TIME ||
8942 params.wait > rdev->wiphy.max_remain_on_channel_duration)
Johannes Bergebf348f2012-06-01 12:50:54 +02008943 return -EINVAL;
Johannes Bergf7ca38d2010-11-25 10:02:29 +01008944 }
8945
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02008946 params.offchan = info->attrs[NL80211_ATTR_OFFCHANNEL_TX_OK];
Johannes Bergf7ca38d2010-11-25 10:02:29 +01008947
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02008948 if (params.offchan && !(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX))
Johannes Berg7c4ef712011-11-18 15:33:48 +01008949 return -EINVAL;
8950
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02008951 params.no_cck = nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]);
Rajkumar Manoharane9f935e2011-09-25 14:53:30 +05308952
Antonio Quartulliea141b752013-06-11 14:20:03 +02008953 /* get the channel if any has been specified, otherwise pass NULL to
8954 * the driver. The latter will use the current one
8955 */
8956 chandef.chan = NULL;
8957 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
8958 err = nl80211_parse_chandef(rdev, info, &chandef);
8959 if (err)
8960 return err;
8961 }
8962
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02008963 if (!chandef.chan && params.offchan)
Antonio Quartulliea141b752013-06-11 14:20:03 +02008964 return -EINVAL;
Jouni Malinen026331c2010-02-15 12:53:10 +02008965
Andrei Otcheretianski34d22ce2014-05-09 14:11:44 +03008966 params.buf = nla_data(info->attrs[NL80211_ATTR_FRAME]);
8967 params.len = nla_len(info->attrs[NL80211_ATTR_FRAME]);
8968
8969 if (info->attrs[NL80211_ATTR_CSA_C_OFFSETS_TX]) {
8970 int len = nla_len(info->attrs[NL80211_ATTR_CSA_C_OFFSETS_TX]);
8971 int i;
8972
8973 if (len % sizeof(u16))
8974 return -EINVAL;
8975
8976 params.n_csa_offsets = len / sizeof(u16);
8977 params.csa_offsets =
8978 nla_data(info->attrs[NL80211_ATTR_CSA_C_OFFSETS_TX]);
8979
8980 /* check that all the offsets fit the frame */
8981 for (i = 0; i < params.n_csa_offsets; i++) {
8982 if (params.csa_offsets[i] >= params.len)
8983 return -EINVAL;
8984 }
8985 }
8986
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02008987 if (!params.dont_wait_for_ack) {
Johannes Berge247bd902011-11-04 11:18:21 +01008988 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
8989 if (!msg)
8990 return -ENOMEM;
Jouni Malinen026331c2010-02-15 12:53:10 +02008991
Eric W. Biederman15e47302012-09-07 20:12:54 +00008992 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berge247bd902011-11-04 11:18:21 +01008993 NL80211_CMD_FRAME);
Dan Carpentercb35fba2013-08-14 14:50:01 +03008994 if (!hdr) {
8995 err = -ENOBUFS;
Johannes Berge247bd902011-11-04 11:18:21 +01008996 goto free_msg;
8997 }
Jouni Malinen026331c2010-02-15 12:53:10 +02008998 }
Johannes Berge247bd902011-11-04 11:18:21 +01008999
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02009000 params.chan = chandef.chan;
9001 err = cfg80211_mlme_mgmt_tx(rdev, wdev, &params, &cookie);
Jouni Malinen026331c2010-02-15 12:53:10 +02009002 if (err)
9003 goto free_msg;
9004
Johannes Berge247bd902011-11-04 11:18:21 +01009005 if (msg) {
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02009006 if (nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie,
9007 NL80211_ATTR_PAD))
David S. Miller9360ffd2012-03-29 04:41:26 -04009008 goto nla_put_failure;
Jouni Malinen026331c2010-02-15 12:53:10 +02009009
Johannes Berge247bd902011-11-04 11:18:21 +01009010 genlmsg_end(msg, hdr);
9011 return genlmsg_reply(msg, info);
9012 }
9013
9014 return 0;
Jouni Malinen026331c2010-02-15 12:53:10 +02009015
9016 nla_put_failure:
9017 err = -ENOBUFS;
9018 free_msg:
9019 nlmsg_free(msg);
Jouni Malinen026331c2010-02-15 12:53:10 +02009020 return err;
9021}
9022
Johannes Bergf7ca38d2010-11-25 10:02:29 +01009023static int nl80211_tx_mgmt_cancel_wait(struct sk_buff *skb, struct genl_info *info)
9024{
9025 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02009026 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Bergf7ca38d2010-11-25 10:02:29 +01009027 u64 cookie;
9028
9029 if (!info->attrs[NL80211_ATTR_COOKIE])
9030 return -EINVAL;
9031
9032 if (!rdev->ops->mgmt_tx_cancel_wait)
9033 return -EOPNOTSUPP;
9034
Johannes Berg71bbc992012-06-15 15:30:18 +02009035 switch (wdev->iftype) {
9036 case NL80211_IFTYPE_STATION:
9037 case NL80211_IFTYPE_ADHOC:
9038 case NL80211_IFTYPE_P2P_CLIENT:
9039 case NL80211_IFTYPE_AP:
9040 case NL80211_IFTYPE_AP_VLAN:
9041 case NL80211_IFTYPE_P2P_GO:
Johannes Berg98104fde2012-06-16 00:19:54 +02009042 case NL80211_IFTYPE_P2P_DEVICE:
Johannes Berg71bbc992012-06-15 15:30:18 +02009043 break;
9044 default:
Johannes Bergf7ca38d2010-11-25 10:02:29 +01009045 return -EOPNOTSUPP;
Johannes Berg71bbc992012-06-15 15:30:18 +02009046 }
Johannes Bergf7ca38d2010-11-25 10:02:29 +01009047
9048 cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]);
9049
Hila Gonene35e4d22012-06-27 17:19:42 +03009050 return rdev_mgmt_tx_cancel_wait(rdev, wdev, cookie);
Johannes Bergf7ca38d2010-11-25 10:02:29 +01009051}
9052
Kalle Valoffb9eb32010-02-17 17:58:10 +02009053static int nl80211_set_power_save(struct sk_buff *skb, struct genl_info *info)
9054{
Johannes Berg4c476992010-10-04 21:36:35 +02009055 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Kalle Valoffb9eb32010-02-17 17:58:10 +02009056 struct wireless_dev *wdev;
Johannes Berg4c476992010-10-04 21:36:35 +02009057 struct net_device *dev = info->user_ptr[1];
Kalle Valoffb9eb32010-02-17 17:58:10 +02009058 u8 ps_state;
9059 bool state;
9060 int err;
9061
Johannes Berg4c476992010-10-04 21:36:35 +02009062 if (!info->attrs[NL80211_ATTR_PS_STATE])
9063 return -EINVAL;
Kalle Valoffb9eb32010-02-17 17:58:10 +02009064
9065 ps_state = nla_get_u32(info->attrs[NL80211_ATTR_PS_STATE]);
9066
Johannes Berg4c476992010-10-04 21:36:35 +02009067 if (ps_state != NL80211_PS_DISABLED && ps_state != NL80211_PS_ENABLED)
9068 return -EINVAL;
Kalle Valoffb9eb32010-02-17 17:58:10 +02009069
9070 wdev = dev->ieee80211_ptr;
9071
Johannes Berg4c476992010-10-04 21:36:35 +02009072 if (!rdev->ops->set_power_mgmt)
9073 return -EOPNOTSUPP;
Kalle Valoffb9eb32010-02-17 17:58:10 +02009074
9075 state = (ps_state == NL80211_PS_ENABLED) ? true : false;
9076
9077 if (state == wdev->ps)
Johannes Berg4c476992010-10-04 21:36:35 +02009078 return 0;
Kalle Valoffb9eb32010-02-17 17:58:10 +02009079
Hila Gonene35e4d22012-06-27 17:19:42 +03009080 err = rdev_set_power_mgmt(rdev, dev, state, wdev->ps_timeout);
Johannes Berg4c476992010-10-04 21:36:35 +02009081 if (!err)
9082 wdev->ps = state;
Kalle Valoffb9eb32010-02-17 17:58:10 +02009083 return err;
9084}
9085
9086static int nl80211_get_power_save(struct sk_buff *skb, struct genl_info *info)
9087{
Johannes Berg4c476992010-10-04 21:36:35 +02009088 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Kalle Valoffb9eb32010-02-17 17:58:10 +02009089 enum nl80211_ps_state ps_state;
9090 struct wireless_dev *wdev;
Johannes Berg4c476992010-10-04 21:36:35 +02009091 struct net_device *dev = info->user_ptr[1];
Kalle Valoffb9eb32010-02-17 17:58:10 +02009092 struct sk_buff *msg;
9093 void *hdr;
9094 int err;
9095
Kalle Valoffb9eb32010-02-17 17:58:10 +02009096 wdev = dev->ieee80211_ptr;
9097
Johannes Berg4c476992010-10-04 21:36:35 +02009098 if (!rdev->ops->set_power_mgmt)
9099 return -EOPNOTSUPP;
Kalle Valoffb9eb32010-02-17 17:58:10 +02009100
9101 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02009102 if (!msg)
9103 return -ENOMEM;
Kalle Valoffb9eb32010-02-17 17:58:10 +02009104
Eric W. Biederman15e47302012-09-07 20:12:54 +00009105 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Kalle Valoffb9eb32010-02-17 17:58:10 +02009106 NL80211_CMD_GET_POWER_SAVE);
9107 if (!hdr) {
Johannes Berg4c476992010-10-04 21:36:35 +02009108 err = -ENOBUFS;
Kalle Valoffb9eb32010-02-17 17:58:10 +02009109 goto free_msg;
9110 }
9111
9112 if (wdev->ps)
9113 ps_state = NL80211_PS_ENABLED;
9114 else
9115 ps_state = NL80211_PS_DISABLED;
9116
David S. Miller9360ffd2012-03-29 04:41:26 -04009117 if (nla_put_u32(msg, NL80211_ATTR_PS_STATE, ps_state))
9118 goto nla_put_failure;
Kalle Valoffb9eb32010-02-17 17:58:10 +02009119
9120 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02009121 return genlmsg_reply(msg, info);
Kalle Valoffb9eb32010-02-17 17:58:10 +02009122
Johannes Berg4c476992010-10-04 21:36:35 +02009123 nla_put_failure:
Kalle Valoffb9eb32010-02-17 17:58:10 +02009124 err = -ENOBUFS;
Johannes Berg4c476992010-10-04 21:36:35 +02009125 free_msg:
Kalle Valoffb9eb32010-02-17 17:58:10 +02009126 nlmsg_free(msg);
Kalle Valoffb9eb32010-02-17 17:58:10 +02009127 return err;
9128}
9129
Johannes Berg94e860f2014-01-20 23:58:15 +01009130static const struct nla_policy
9131nl80211_attr_cqm_policy[NL80211_ATTR_CQM_MAX + 1] = {
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02009132 [NL80211_ATTR_CQM_RSSI_THOLD] = { .type = NLA_U32 },
9133 [NL80211_ATTR_CQM_RSSI_HYST] = { .type = NLA_U32 },
9134 [NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT] = { .type = NLA_U32 },
Thomas Pedersen84f10702012-07-12 16:17:33 -07009135 [NL80211_ATTR_CQM_TXE_RATE] = { .type = NLA_U32 },
9136 [NL80211_ATTR_CQM_TXE_PKTS] = { .type = NLA_U32 },
9137 [NL80211_ATTR_CQM_TXE_INTVL] = { .type = NLA_U32 },
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02009138};
9139
Thomas Pedersen84f10702012-07-12 16:17:33 -07009140static int nl80211_set_cqm_txe(struct genl_info *info,
Johannes Bergd9d8b012012-11-26 12:51:52 +01009141 u32 rate, u32 pkts, u32 intvl)
Thomas Pedersen84f10702012-07-12 16:17:33 -07009142{
9143 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Thomas Pedersen84f10702012-07-12 16:17:33 -07009144 struct net_device *dev = info->user_ptr[1];
Johannes Berg1da5fcc2013-08-06 14:10:48 +02009145 struct wireless_dev *wdev = dev->ieee80211_ptr;
Thomas Pedersen84f10702012-07-12 16:17:33 -07009146
Johannes Bergd9d8b012012-11-26 12:51:52 +01009147 if (rate > 100 || intvl > NL80211_CQM_TXE_MAX_INTVL)
Thomas Pedersen84f10702012-07-12 16:17:33 -07009148 return -EINVAL;
9149
Thomas Pedersen84f10702012-07-12 16:17:33 -07009150 if (!rdev->ops->set_cqm_txe_config)
9151 return -EOPNOTSUPP;
9152
9153 if (wdev->iftype != NL80211_IFTYPE_STATION &&
9154 wdev->iftype != NL80211_IFTYPE_P2P_CLIENT)
9155 return -EOPNOTSUPP;
9156
Hila Gonene35e4d22012-06-27 17:19:42 +03009157 return rdev_set_cqm_txe_config(rdev, dev, rate, pkts, intvl);
Thomas Pedersen84f10702012-07-12 16:17:33 -07009158}
9159
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02009160static int nl80211_set_cqm_rssi(struct genl_info *info,
9161 s32 threshold, u32 hysteresis)
9162{
Johannes Berg4c476992010-10-04 21:36:35 +02009163 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg4c476992010-10-04 21:36:35 +02009164 struct net_device *dev = info->user_ptr[1];
Johannes Berg1da5fcc2013-08-06 14:10:48 +02009165 struct wireless_dev *wdev = dev->ieee80211_ptr;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02009166
9167 if (threshold > 0)
9168 return -EINVAL;
9169
Johannes Berg1da5fcc2013-08-06 14:10:48 +02009170 /* disabling - hysteresis should also be zero then */
9171 if (threshold == 0)
9172 hysteresis = 0;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02009173
Johannes Berg4c476992010-10-04 21:36:35 +02009174 if (!rdev->ops->set_cqm_rssi_config)
9175 return -EOPNOTSUPP;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02009176
Johannes Berg074ac8d2010-09-16 14:58:22 +02009177 if (wdev->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02009178 wdev->iftype != NL80211_IFTYPE_P2P_CLIENT)
9179 return -EOPNOTSUPP;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02009180
Hila Gonene35e4d22012-06-27 17:19:42 +03009181 return rdev_set_cqm_rssi_config(rdev, dev, threshold, hysteresis);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02009182}
9183
9184static int nl80211_set_cqm(struct sk_buff *skb, struct genl_info *info)
9185{
9186 struct nlattr *attrs[NL80211_ATTR_CQM_MAX + 1];
9187 struct nlattr *cqm;
9188 int err;
9189
9190 cqm = info->attrs[NL80211_ATTR_CQM];
Johannes Berg1da5fcc2013-08-06 14:10:48 +02009191 if (!cqm)
9192 return -EINVAL;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02009193
9194 err = nla_parse_nested(attrs, NL80211_ATTR_CQM_MAX, cqm,
9195 nl80211_attr_cqm_policy);
9196 if (err)
Johannes Berg1da5fcc2013-08-06 14:10:48 +02009197 return err;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02009198
9199 if (attrs[NL80211_ATTR_CQM_RSSI_THOLD] &&
9200 attrs[NL80211_ATTR_CQM_RSSI_HYST]) {
Johannes Berg1da5fcc2013-08-06 14:10:48 +02009201 s32 threshold = nla_get_s32(attrs[NL80211_ATTR_CQM_RSSI_THOLD]);
9202 u32 hysteresis = nla_get_u32(attrs[NL80211_ATTR_CQM_RSSI_HYST]);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02009203
Johannes Berg1da5fcc2013-08-06 14:10:48 +02009204 return nl80211_set_cqm_rssi(info, threshold, hysteresis);
9205 }
9206
9207 if (attrs[NL80211_ATTR_CQM_TXE_RATE] &&
9208 attrs[NL80211_ATTR_CQM_TXE_PKTS] &&
9209 attrs[NL80211_ATTR_CQM_TXE_INTVL]) {
9210 u32 rate = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_RATE]);
9211 u32 pkts = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_PKTS]);
9212 u32 intvl = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_INTVL]);
9213
9214 return nl80211_set_cqm_txe(info, rate, pkts, intvl);
9215 }
9216
9217 return -EINVAL;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02009218}
9219
Rostislav Lisovy6e0bd6c2014-11-03 10:33:18 +01009220static int nl80211_join_ocb(struct sk_buff *skb, struct genl_info *info)
9221{
9222 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9223 struct net_device *dev = info->user_ptr[1];
9224 struct ocb_setup setup = {};
9225 int err;
9226
9227 err = nl80211_parse_chandef(rdev, info, &setup.chandef);
9228 if (err)
9229 return err;
9230
9231 return cfg80211_join_ocb(rdev, dev, &setup);
9232}
9233
9234static int nl80211_leave_ocb(struct sk_buff *skb, struct genl_info *info)
9235{
9236 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9237 struct net_device *dev = info->user_ptr[1];
9238
9239 return cfg80211_leave_ocb(rdev, dev);
9240}
9241
Johannes Berg29cbe682010-12-03 09:20:44 +01009242static int nl80211_join_mesh(struct sk_buff *skb, struct genl_info *info)
9243{
9244 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9245 struct net_device *dev = info->user_ptr[1];
9246 struct mesh_config cfg;
Javier Cardonac80d5452010-12-16 17:37:49 -08009247 struct mesh_setup setup;
Johannes Berg29cbe682010-12-03 09:20:44 +01009248 int err;
9249
9250 /* start with default */
9251 memcpy(&cfg, &default_mesh_config, sizeof(cfg));
Javier Cardonac80d5452010-12-16 17:37:49 -08009252 memcpy(&setup, &default_mesh_setup, sizeof(setup));
Johannes Berg29cbe682010-12-03 09:20:44 +01009253
Javier Cardona24bdd9f2010-12-16 17:37:48 -08009254 if (info->attrs[NL80211_ATTR_MESH_CONFIG]) {
Johannes Berg29cbe682010-12-03 09:20:44 +01009255 /* and parse parameters if given */
Javier Cardona24bdd9f2010-12-16 17:37:48 -08009256 err = nl80211_parse_mesh_config(info, &cfg, NULL);
Johannes Berg29cbe682010-12-03 09:20:44 +01009257 if (err)
9258 return err;
9259 }
9260
9261 if (!info->attrs[NL80211_ATTR_MESH_ID] ||
9262 !nla_len(info->attrs[NL80211_ATTR_MESH_ID]))
9263 return -EINVAL;
9264
Javier Cardonac80d5452010-12-16 17:37:49 -08009265 setup.mesh_id = nla_data(info->attrs[NL80211_ATTR_MESH_ID]);
9266 setup.mesh_id_len = nla_len(info->attrs[NL80211_ATTR_MESH_ID]);
9267
Chun-Yeow Yeoh4bb62342011-11-24 17:15:20 -08009268 if (info->attrs[NL80211_ATTR_MCAST_RATE] &&
9269 !nl80211_parse_mcast_rate(rdev, setup.mcast_rate,
9270 nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE])))
9271 return -EINVAL;
9272
Marco Porsch9bdbf042013-01-07 16:04:51 +01009273 if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) {
9274 setup.beacon_interval =
9275 nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]);
Purushottam Kushwaha12d20fc92016-08-11 15:14:02 +05309276
9277 err = cfg80211_validate_beacon_int(rdev, setup.beacon_interval);
9278 if (err)
9279 return err;
Marco Porsch9bdbf042013-01-07 16:04:51 +01009280 }
9281
9282 if (info->attrs[NL80211_ATTR_DTIM_PERIOD]) {
9283 setup.dtim_period =
9284 nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]);
9285 if (setup.dtim_period < 1 || setup.dtim_period > 100)
9286 return -EINVAL;
9287 }
9288
Javier Cardonac80d5452010-12-16 17:37:49 -08009289 if (info->attrs[NL80211_ATTR_MESH_SETUP]) {
9290 /* parse additional setup parameters if given */
9291 err = nl80211_parse_mesh_setup(info, &setup);
9292 if (err)
9293 return err;
9294 }
9295
Thomas Pedersend37bb182013-03-04 13:06:13 -08009296 if (setup.user_mpm)
9297 cfg.auto_open_plinks = false;
9298
Johannes Bergcc1d2802012-05-16 23:50:20 +02009299 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
Johannes Berg683b6d32012-11-08 21:25:48 +01009300 err = nl80211_parse_chandef(rdev, info, &setup.chandef);
9301 if (err)
9302 return err;
Johannes Bergcc1d2802012-05-16 23:50:20 +02009303 } else {
9304 /* cfg80211_join_mesh() will sort it out */
Johannes Berg683b6d32012-11-08 21:25:48 +01009305 setup.chandef.chan = NULL;
Johannes Bergcc1d2802012-05-16 23:50:20 +02009306 }
9307
Ashok Nagarajanffb3cf32013-06-03 10:33:36 -07009308 if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) {
9309 u8 *rates = nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
9310 int n_rates =
9311 nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
9312 struct ieee80211_supported_band *sband;
9313
9314 if (!setup.chandef.chan)
9315 return -EINVAL;
9316
9317 sband = rdev->wiphy.bands[setup.chandef.chan->band];
9318
9319 err = ieee80211_get_ratemask(sband, rates, n_rates,
9320 &setup.basic_rates);
9321 if (err)
9322 return err;
9323 }
9324
Javier Cardonac80d5452010-12-16 17:37:49 -08009325 return cfg80211_join_mesh(rdev, dev, &setup, &cfg);
Johannes Berg29cbe682010-12-03 09:20:44 +01009326}
9327
9328static int nl80211_leave_mesh(struct sk_buff *skb, struct genl_info *info)
9329{
9330 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9331 struct net_device *dev = info->user_ptr[1];
9332
9333 return cfg80211_leave_mesh(rdev, dev);
9334}
9335
Johannes Bergdfb89c52012-06-27 09:23:48 +02009336#ifdef CONFIG_PM
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08009337static int nl80211_send_wowlan_patterns(struct sk_buff *msg,
9338 struct cfg80211_registered_device *rdev)
9339{
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009340 struct cfg80211_wowlan *wowlan = rdev->wiphy.wowlan_config;
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08009341 struct nlattr *nl_pats, *nl_pat;
9342 int i, pat_len;
9343
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009344 if (!wowlan->n_patterns)
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08009345 return 0;
9346
9347 nl_pats = nla_nest_start(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN);
9348 if (!nl_pats)
9349 return -ENOBUFS;
9350
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009351 for (i = 0; i < wowlan->n_patterns; i++) {
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08009352 nl_pat = nla_nest_start(msg, i + 1);
9353 if (!nl_pat)
9354 return -ENOBUFS;
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009355 pat_len = wowlan->patterns[i].pattern_len;
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07009356 if (nla_put(msg, NL80211_PKTPAT_MASK, DIV_ROUND_UP(pat_len, 8),
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009357 wowlan->patterns[i].mask) ||
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07009358 nla_put(msg, NL80211_PKTPAT_PATTERN, pat_len,
9359 wowlan->patterns[i].pattern) ||
9360 nla_put_u32(msg, NL80211_PKTPAT_OFFSET,
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009361 wowlan->patterns[i].pkt_offset))
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08009362 return -ENOBUFS;
9363 nla_nest_end(msg, nl_pat);
9364 }
9365 nla_nest_end(msg, nl_pats);
9366
9367 return 0;
9368}
9369
Johannes Berg2a0e0472013-01-23 22:57:40 +01009370static int nl80211_send_wowlan_tcp(struct sk_buff *msg,
9371 struct cfg80211_wowlan_tcp *tcp)
9372{
9373 struct nlattr *nl_tcp;
9374
9375 if (!tcp)
9376 return 0;
9377
9378 nl_tcp = nla_nest_start(msg, NL80211_WOWLAN_TRIG_TCP_CONNECTION);
9379 if (!nl_tcp)
9380 return -ENOBUFS;
9381
Jiri Benc930345e2015-03-29 16:59:25 +02009382 if (nla_put_in_addr(msg, NL80211_WOWLAN_TCP_SRC_IPV4, tcp->src) ||
9383 nla_put_in_addr(msg, NL80211_WOWLAN_TCP_DST_IPV4, tcp->dst) ||
Johannes Berg2a0e0472013-01-23 22:57:40 +01009384 nla_put(msg, NL80211_WOWLAN_TCP_DST_MAC, ETH_ALEN, tcp->dst_mac) ||
9385 nla_put_u16(msg, NL80211_WOWLAN_TCP_SRC_PORT, tcp->src_port) ||
9386 nla_put_u16(msg, NL80211_WOWLAN_TCP_DST_PORT, tcp->dst_port) ||
9387 nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD,
9388 tcp->payload_len, tcp->payload) ||
9389 nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_INTERVAL,
9390 tcp->data_interval) ||
9391 nla_put(msg, NL80211_WOWLAN_TCP_WAKE_PAYLOAD,
9392 tcp->wake_len, tcp->wake_data) ||
9393 nla_put(msg, NL80211_WOWLAN_TCP_WAKE_MASK,
9394 DIV_ROUND_UP(tcp->wake_len, 8), tcp->wake_mask))
9395 return -ENOBUFS;
9396
9397 if (tcp->payload_seq.len &&
9398 nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ,
9399 sizeof(tcp->payload_seq), &tcp->payload_seq))
9400 return -ENOBUFS;
9401
9402 if (tcp->payload_tok.len &&
9403 nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN,
9404 sizeof(tcp->payload_tok) + tcp->tokens_size,
9405 &tcp->payload_tok))
9406 return -ENOBUFS;
9407
Johannes Berge248ad32013-05-16 10:24:28 +02009408 nla_nest_end(msg, nl_tcp);
9409
Johannes Berg2a0e0472013-01-23 22:57:40 +01009410 return 0;
9411}
9412
Luciano Coelho75453cc2015-01-09 14:06:37 +02009413static int nl80211_send_wowlan_nd(struct sk_buff *msg,
9414 struct cfg80211_sched_scan_request *req)
9415{
Avraham Stern3b06d272015-10-12 09:51:34 +03009416 struct nlattr *nd, *freqs, *matches, *match, *scan_plans, *scan_plan;
Luciano Coelho75453cc2015-01-09 14:06:37 +02009417 int i;
9418
9419 if (!req)
9420 return 0;
9421
9422 nd = nla_nest_start(msg, NL80211_WOWLAN_TRIG_NET_DETECT);
9423 if (!nd)
9424 return -ENOBUFS;
9425
Avraham Stern3b06d272015-10-12 09:51:34 +03009426 if (req->n_scan_plans == 1 &&
9427 nla_put_u32(msg, NL80211_ATTR_SCHED_SCAN_INTERVAL,
9428 req->scan_plans[0].interval * 1000))
Luciano Coelho75453cc2015-01-09 14:06:37 +02009429 return -ENOBUFS;
9430
Luciano Coelho21fea562015-03-17 16:36:01 +02009431 if (nla_put_u32(msg, NL80211_ATTR_SCHED_SCAN_DELAY, req->delay))
9432 return -ENOBUFS;
9433
Luciano Coelho75453cc2015-01-09 14:06:37 +02009434 freqs = nla_nest_start(msg, NL80211_ATTR_SCAN_FREQUENCIES);
9435 if (!freqs)
9436 return -ENOBUFS;
9437
9438 for (i = 0; i < req->n_channels; i++)
9439 nla_put_u32(msg, i, req->channels[i]->center_freq);
9440
9441 nla_nest_end(msg, freqs);
9442
9443 if (req->n_match_sets) {
9444 matches = nla_nest_start(msg, NL80211_ATTR_SCHED_SCAN_MATCH);
9445 for (i = 0; i < req->n_match_sets; i++) {
9446 match = nla_nest_start(msg, i);
9447 nla_put(msg, NL80211_SCHED_SCAN_MATCH_ATTR_SSID,
9448 req->match_sets[i].ssid.ssid_len,
9449 req->match_sets[i].ssid.ssid);
9450 nla_nest_end(msg, match);
9451 }
9452 nla_nest_end(msg, matches);
9453 }
9454
Avraham Stern3b06d272015-10-12 09:51:34 +03009455 scan_plans = nla_nest_start(msg, NL80211_ATTR_SCHED_SCAN_PLANS);
9456 if (!scan_plans)
9457 return -ENOBUFS;
9458
9459 for (i = 0; i < req->n_scan_plans; i++) {
9460 scan_plan = nla_nest_start(msg, i + 1);
9461 if (!scan_plan ||
9462 nla_put_u32(msg, NL80211_SCHED_SCAN_PLAN_INTERVAL,
9463 req->scan_plans[i].interval) ||
9464 (req->scan_plans[i].iterations &&
9465 nla_put_u32(msg, NL80211_SCHED_SCAN_PLAN_ITERATIONS,
9466 req->scan_plans[i].iterations)))
9467 return -ENOBUFS;
9468 nla_nest_end(msg, scan_plan);
9469 }
9470 nla_nest_end(msg, scan_plans);
9471
Luciano Coelho75453cc2015-01-09 14:06:37 +02009472 nla_nest_end(msg, nd);
9473
9474 return 0;
9475}
9476
Johannes Bergff1b6e62011-05-04 15:37:28 +02009477static int nl80211_get_wowlan(struct sk_buff *skb, struct genl_info *info)
9478{
9479 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9480 struct sk_buff *msg;
9481 void *hdr;
Johannes Berg2a0e0472013-01-23 22:57:40 +01009482 u32 size = NLMSG_DEFAULT_SIZE;
Johannes Bergff1b6e62011-05-04 15:37:28 +02009483
Johannes Berg964dc9e2013-06-03 17:25:34 +02009484 if (!rdev->wiphy.wowlan)
Johannes Bergff1b6e62011-05-04 15:37:28 +02009485 return -EOPNOTSUPP;
9486
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009487 if (rdev->wiphy.wowlan_config && rdev->wiphy.wowlan_config->tcp) {
Johannes Berg2a0e0472013-01-23 22:57:40 +01009488 /* adjust size to have room for all the data */
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009489 size += rdev->wiphy.wowlan_config->tcp->tokens_size +
9490 rdev->wiphy.wowlan_config->tcp->payload_len +
9491 rdev->wiphy.wowlan_config->tcp->wake_len +
9492 rdev->wiphy.wowlan_config->tcp->wake_len / 8;
Johannes Berg2a0e0472013-01-23 22:57:40 +01009493 }
9494
9495 msg = nlmsg_new(size, GFP_KERNEL);
Johannes Bergff1b6e62011-05-04 15:37:28 +02009496 if (!msg)
9497 return -ENOMEM;
9498
Eric W. Biederman15e47302012-09-07 20:12:54 +00009499 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Johannes Bergff1b6e62011-05-04 15:37:28 +02009500 NL80211_CMD_GET_WOWLAN);
9501 if (!hdr)
9502 goto nla_put_failure;
9503
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009504 if (rdev->wiphy.wowlan_config) {
Johannes Bergff1b6e62011-05-04 15:37:28 +02009505 struct nlattr *nl_wowlan;
9506
9507 nl_wowlan = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS);
9508 if (!nl_wowlan)
9509 goto nla_put_failure;
9510
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009511 if ((rdev->wiphy.wowlan_config->any &&
David S. Miller9360ffd2012-03-29 04:41:26 -04009512 nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009513 (rdev->wiphy.wowlan_config->disconnect &&
David S. Miller9360ffd2012-03-29 04:41:26 -04009514 nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009515 (rdev->wiphy.wowlan_config->magic_pkt &&
David S. Miller9360ffd2012-03-29 04:41:26 -04009516 nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009517 (rdev->wiphy.wowlan_config->gtk_rekey_failure &&
David S. Miller9360ffd2012-03-29 04:41:26 -04009518 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009519 (rdev->wiphy.wowlan_config->eap_identity_req &&
David S. Miller9360ffd2012-03-29 04:41:26 -04009520 nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009521 (rdev->wiphy.wowlan_config->four_way_handshake &&
David S. Miller9360ffd2012-03-29 04:41:26 -04009522 nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009523 (rdev->wiphy.wowlan_config->rfkill_release &&
David S. Miller9360ffd2012-03-29 04:41:26 -04009524 nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE)))
9525 goto nla_put_failure;
Johannes Berg2a0e0472013-01-23 22:57:40 +01009526
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08009527 if (nl80211_send_wowlan_patterns(msg, rdev))
9528 goto nla_put_failure;
Johannes Berg2a0e0472013-01-23 22:57:40 +01009529
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009530 if (nl80211_send_wowlan_tcp(msg,
9531 rdev->wiphy.wowlan_config->tcp))
Johannes Berg2a0e0472013-01-23 22:57:40 +01009532 goto nla_put_failure;
9533
Luciano Coelho75453cc2015-01-09 14:06:37 +02009534 if (nl80211_send_wowlan_nd(
9535 msg,
9536 rdev->wiphy.wowlan_config->nd_config))
9537 goto nla_put_failure;
9538
Johannes Bergff1b6e62011-05-04 15:37:28 +02009539 nla_nest_end(msg, nl_wowlan);
9540 }
9541
9542 genlmsg_end(msg, hdr);
9543 return genlmsg_reply(msg, info);
9544
9545nla_put_failure:
9546 nlmsg_free(msg);
9547 return -ENOBUFS;
9548}
9549
Johannes Berg2a0e0472013-01-23 22:57:40 +01009550static int nl80211_parse_wowlan_tcp(struct cfg80211_registered_device *rdev,
9551 struct nlattr *attr,
9552 struct cfg80211_wowlan *trig)
9553{
9554 struct nlattr *tb[NUM_NL80211_WOWLAN_TCP];
9555 struct cfg80211_wowlan_tcp *cfg;
9556 struct nl80211_wowlan_tcp_data_token *tok = NULL;
9557 struct nl80211_wowlan_tcp_data_seq *seq = NULL;
9558 u32 size;
9559 u32 data_size, wake_size, tokens_size = 0, wake_mask_size;
9560 int err, port;
9561
Johannes Berg964dc9e2013-06-03 17:25:34 +02009562 if (!rdev->wiphy.wowlan->tcp)
Johannes Berg2a0e0472013-01-23 22:57:40 +01009563 return -EINVAL;
9564
9565 err = nla_parse(tb, MAX_NL80211_WOWLAN_TCP,
9566 nla_data(attr), nla_len(attr),
9567 nl80211_wowlan_tcp_policy);
9568 if (err)
9569 return err;
9570
9571 if (!tb[NL80211_WOWLAN_TCP_SRC_IPV4] ||
9572 !tb[NL80211_WOWLAN_TCP_DST_IPV4] ||
9573 !tb[NL80211_WOWLAN_TCP_DST_MAC] ||
9574 !tb[NL80211_WOWLAN_TCP_DST_PORT] ||
9575 !tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD] ||
9576 !tb[NL80211_WOWLAN_TCP_DATA_INTERVAL] ||
9577 !tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD] ||
9578 !tb[NL80211_WOWLAN_TCP_WAKE_MASK])
9579 return -EINVAL;
9580
9581 data_size = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]);
Johannes Berg964dc9e2013-06-03 17:25:34 +02009582 if (data_size > rdev->wiphy.wowlan->tcp->data_payload_max)
Johannes Berg2a0e0472013-01-23 22:57:40 +01009583 return -EINVAL;
9584
9585 if (nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]) >
Johannes Berg964dc9e2013-06-03 17:25:34 +02009586 rdev->wiphy.wowlan->tcp->data_interval_max ||
Johannes Berg723d5682013-02-26 13:56:40 +01009587 nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]) == 0)
Johannes Berg2a0e0472013-01-23 22:57:40 +01009588 return -EINVAL;
9589
9590 wake_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]);
Johannes Berg964dc9e2013-06-03 17:25:34 +02009591 if (wake_size > rdev->wiphy.wowlan->tcp->wake_payload_max)
Johannes Berg2a0e0472013-01-23 22:57:40 +01009592 return -EINVAL;
9593
9594 wake_mask_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_MASK]);
9595 if (wake_mask_size != DIV_ROUND_UP(wake_size, 8))
9596 return -EINVAL;
9597
9598 if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]) {
9599 u32 tokln = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]);
9600
9601 tok = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]);
9602 tokens_size = tokln - sizeof(*tok);
9603
9604 if (!tok->len || tokens_size % tok->len)
9605 return -EINVAL;
Johannes Berg964dc9e2013-06-03 17:25:34 +02009606 if (!rdev->wiphy.wowlan->tcp->tok)
Johannes Berg2a0e0472013-01-23 22:57:40 +01009607 return -EINVAL;
Johannes Berg964dc9e2013-06-03 17:25:34 +02009608 if (tok->len > rdev->wiphy.wowlan->tcp->tok->max_len)
Johannes Berg2a0e0472013-01-23 22:57:40 +01009609 return -EINVAL;
Johannes Berg964dc9e2013-06-03 17:25:34 +02009610 if (tok->len < rdev->wiphy.wowlan->tcp->tok->min_len)
Johannes Berg2a0e0472013-01-23 22:57:40 +01009611 return -EINVAL;
Johannes Berg964dc9e2013-06-03 17:25:34 +02009612 if (tokens_size > rdev->wiphy.wowlan->tcp->tok->bufsize)
Johannes Berg2a0e0472013-01-23 22:57:40 +01009613 return -EINVAL;
9614 if (tok->offset + tok->len > data_size)
9615 return -EINVAL;
9616 }
9617
9618 if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]) {
9619 seq = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]);
Johannes Berg964dc9e2013-06-03 17:25:34 +02009620 if (!rdev->wiphy.wowlan->tcp->seq)
Johannes Berg2a0e0472013-01-23 22:57:40 +01009621 return -EINVAL;
9622 if (seq->len == 0 || seq->len > 4)
9623 return -EINVAL;
9624 if (seq->len + seq->offset > data_size)
9625 return -EINVAL;
9626 }
9627
9628 size = sizeof(*cfg);
9629 size += data_size;
9630 size += wake_size + wake_mask_size;
9631 size += tokens_size;
9632
9633 cfg = kzalloc(size, GFP_KERNEL);
9634 if (!cfg)
9635 return -ENOMEM;
Jiri Benc67b61f62015-03-29 16:59:26 +02009636 cfg->src = nla_get_in_addr(tb[NL80211_WOWLAN_TCP_SRC_IPV4]);
9637 cfg->dst = nla_get_in_addr(tb[NL80211_WOWLAN_TCP_DST_IPV4]);
Johannes Berg2a0e0472013-01-23 22:57:40 +01009638 memcpy(cfg->dst_mac, nla_data(tb[NL80211_WOWLAN_TCP_DST_MAC]),
9639 ETH_ALEN);
9640 if (tb[NL80211_WOWLAN_TCP_SRC_PORT])
9641 port = nla_get_u16(tb[NL80211_WOWLAN_TCP_SRC_PORT]);
9642 else
9643 port = 0;
9644#ifdef CONFIG_INET
9645 /* allocate a socket and port for it and use it */
9646 err = __sock_create(wiphy_net(&rdev->wiphy), PF_INET, SOCK_STREAM,
9647 IPPROTO_TCP, &cfg->sock, 1);
9648 if (err) {
9649 kfree(cfg);
9650 return err;
9651 }
9652 if (inet_csk_get_port(cfg->sock->sk, port)) {
9653 sock_release(cfg->sock);
9654 kfree(cfg);
9655 return -EADDRINUSE;
9656 }
9657 cfg->src_port = inet_sk(cfg->sock->sk)->inet_num;
9658#else
9659 if (!port) {
9660 kfree(cfg);
9661 return -EINVAL;
9662 }
9663 cfg->src_port = port;
9664#endif
9665
9666 cfg->dst_port = nla_get_u16(tb[NL80211_WOWLAN_TCP_DST_PORT]);
9667 cfg->payload_len = data_size;
9668 cfg->payload = (u8 *)cfg + sizeof(*cfg) + tokens_size;
9669 memcpy((void *)cfg->payload,
9670 nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]),
9671 data_size);
9672 if (seq)
9673 cfg->payload_seq = *seq;
9674 cfg->data_interval = nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]);
9675 cfg->wake_len = wake_size;
9676 cfg->wake_data = (u8 *)cfg + sizeof(*cfg) + tokens_size + data_size;
9677 memcpy((void *)cfg->wake_data,
9678 nla_data(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]),
9679 wake_size);
9680 cfg->wake_mask = (u8 *)cfg + sizeof(*cfg) + tokens_size +
9681 data_size + wake_size;
9682 memcpy((void *)cfg->wake_mask,
9683 nla_data(tb[NL80211_WOWLAN_TCP_WAKE_MASK]),
9684 wake_mask_size);
9685 if (tok) {
9686 cfg->tokens_size = tokens_size;
9687 memcpy(&cfg->payload_tok, tok, sizeof(*tok) + tokens_size);
9688 }
9689
9690 trig->tcp = cfg;
9691
9692 return 0;
9693}
9694
Luciano Coelho8cd4d452014-09-17 11:55:28 +03009695static int nl80211_parse_wowlan_nd(struct cfg80211_registered_device *rdev,
9696 const struct wiphy_wowlan_support *wowlan,
9697 struct nlattr *attr,
9698 struct cfg80211_wowlan *trig)
9699{
9700 struct nlattr **tb;
9701 int err;
9702
9703 tb = kzalloc(NUM_NL80211_ATTR * sizeof(*tb), GFP_KERNEL);
9704 if (!tb)
9705 return -ENOMEM;
9706
9707 if (!(wowlan->flags & WIPHY_WOWLAN_NET_DETECT)) {
9708 err = -EOPNOTSUPP;
9709 goto out;
9710 }
9711
9712 err = nla_parse(tb, NL80211_ATTR_MAX,
9713 nla_data(attr), nla_len(attr),
9714 nl80211_policy);
9715 if (err)
9716 goto out;
9717
Johannes Bergad2b26a2014-06-12 21:39:05 +02009718 trig->nd_config = nl80211_parse_sched_scan(&rdev->wiphy, NULL, tb);
Luciano Coelho8cd4d452014-09-17 11:55:28 +03009719 err = PTR_ERR_OR_ZERO(trig->nd_config);
9720 if (err)
9721 trig->nd_config = NULL;
9722
9723out:
9724 kfree(tb);
9725 return err;
9726}
9727
Johannes Bergff1b6e62011-05-04 15:37:28 +02009728static int nl80211_set_wowlan(struct sk_buff *skb, struct genl_info *info)
9729{
9730 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9731 struct nlattr *tb[NUM_NL80211_WOWLAN_TRIG];
Johannes Bergff1b6e62011-05-04 15:37:28 +02009732 struct cfg80211_wowlan new_triggers = {};
Johannes Bergae33bd82012-07-12 16:25:02 +02009733 struct cfg80211_wowlan *ntrig;
Johannes Berg964dc9e2013-06-03 17:25:34 +02009734 const struct wiphy_wowlan_support *wowlan = rdev->wiphy.wowlan;
Johannes Bergff1b6e62011-05-04 15:37:28 +02009735 int err, i;
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009736 bool prev_enabled = rdev->wiphy.wowlan_config;
Johannes Berg98fc4382015-03-01 09:10:13 +02009737 bool regular = false;
Johannes Bergff1b6e62011-05-04 15:37:28 +02009738
Johannes Berg964dc9e2013-06-03 17:25:34 +02009739 if (!wowlan)
Johannes Bergff1b6e62011-05-04 15:37:28 +02009740 return -EOPNOTSUPP;
9741
Johannes Bergae33bd82012-07-12 16:25:02 +02009742 if (!info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]) {
9743 cfg80211_rdev_free_wowlan(rdev);
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009744 rdev->wiphy.wowlan_config = NULL;
Johannes Bergae33bd82012-07-12 16:25:02 +02009745 goto set_wakeup;
9746 }
Johannes Bergff1b6e62011-05-04 15:37:28 +02009747
9748 err = nla_parse(tb, MAX_NL80211_WOWLAN_TRIG,
9749 nla_data(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]),
9750 nla_len(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]),
9751 nl80211_wowlan_policy);
9752 if (err)
9753 return err;
9754
9755 if (tb[NL80211_WOWLAN_TRIG_ANY]) {
9756 if (!(wowlan->flags & WIPHY_WOWLAN_ANY))
9757 return -EINVAL;
9758 new_triggers.any = true;
9759 }
9760
9761 if (tb[NL80211_WOWLAN_TRIG_DISCONNECT]) {
9762 if (!(wowlan->flags & WIPHY_WOWLAN_DISCONNECT))
9763 return -EINVAL;
9764 new_triggers.disconnect = true;
Johannes Berg98fc4382015-03-01 09:10:13 +02009765 regular = true;
Johannes Bergff1b6e62011-05-04 15:37:28 +02009766 }
9767
9768 if (tb[NL80211_WOWLAN_TRIG_MAGIC_PKT]) {
9769 if (!(wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT))
9770 return -EINVAL;
9771 new_triggers.magic_pkt = true;
Johannes Berg98fc4382015-03-01 09:10:13 +02009772 regular = true;
Johannes Bergff1b6e62011-05-04 15:37:28 +02009773 }
9774
Johannes Berg77dbbb12011-07-13 10:48:55 +02009775 if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED])
9776 return -EINVAL;
9777
9778 if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE]) {
9779 if (!(wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE))
9780 return -EINVAL;
9781 new_triggers.gtk_rekey_failure = true;
Johannes Berg98fc4382015-03-01 09:10:13 +02009782 regular = true;
Johannes Berg77dbbb12011-07-13 10:48:55 +02009783 }
9784
9785 if (tb[NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST]) {
9786 if (!(wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ))
9787 return -EINVAL;
9788 new_triggers.eap_identity_req = true;
Johannes Berg98fc4382015-03-01 09:10:13 +02009789 regular = true;
Johannes Berg77dbbb12011-07-13 10:48:55 +02009790 }
9791
9792 if (tb[NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE]) {
9793 if (!(wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE))
9794 return -EINVAL;
9795 new_triggers.four_way_handshake = true;
Johannes Berg98fc4382015-03-01 09:10:13 +02009796 regular = true;
Johannes Berg77dbbb12011-07-13 10:48:55 +02009797 }
9798
9799 if (tb[NL80211_WOWLAN_TRIG_RFKILL_RELEASE]) {
9800 if (!(wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE))
9801 return -EINVAL;
9802 new_triggers.rfkill_release = true;
Johannes Berg98fc4382015-03-01 09:10:13 +02009803 regular = true;
Johannes Berg77dbbb12011-07-13 10:48:55 +02009804 }
9805
Johannes Bergff1b6e62011-05-04 15:37:28 +02009806 if (tb[NL80211_WOWLAN_TRIG_PKT_PATTERN]) {
9807 struct nlattr *pat;
9808 int n_patterns = 0;
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08009809 int rem, pat_len, mask_len, pkt_offset;
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07009810 struct nlattr *pat_tb[NUM_NL80211_PKTPAT];
Johannes Bergff1b6e62011-05-04 15:37:28 +02009811
Johannes Berg98fc4382015-03-01 09:10:13 +02009812 regular = true;
9813
Johannes Bergff1b6e62011-05-04 15:37:28 +02009814 nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN],
9815 rem)
9816 n_patterns++;
9817 if (n_patterns > wowlan->n_patterns)
9818 return -EINVAL;
9819
9820 new_triggers.patterns = kcalloc(n_patterns,
9821 sizeof(new_triggers.patterns[0]),
9822 GFP_KERNEL);
9823 if (!new_triggers.patterns)
9824 return -ENOMEM;
9825
9826 new_triggers.n_patterns = n_patterns;
9827 i = 0;
9828
9829 nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN],
9830 rem) {
Johannes Berg922bd802014-05-19 17:59:50 +02009831 u8 *mask_pat;
9832
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07009833 nla_parse(pat_tb, MAX_NL80211_PKTPAT, nla_data(pat),
9834 nla_len(pat), NULL);
Johannes Bergff1b6e62011-05-04 15:37:28 +02009835 err = -EINVAL;
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07009836 if (!pat_tb[NL80211_PKTPAT_MASK] ||
9837 !pat_tb[NL80211_PKTPAT_PATTERN])
Johannes Bergff1b6e62011-05-04 15:37:28 +02009838 goto error;
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07009839 pat_len = nla_len(pat_tb[NL80211_PKTPAT_PATTERN]);
Johannes Bergff1b6e62011-05-04 15:37:28 +02009840 mask_len = DIV_ROUND_UP(pat_len, 8);
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07009841 if (nla_len(pat_tb[NL80211_PKTPAT_MASK]) != mask_len)
Johannes Bergff1b6e62011-05-04 15:37:28 +02009842 goto error;
9843 if (pat_len > wowlan->pattern_max_len ||
9844 pat_len < wowlan->pattern_min_len)
9845 goto error;
9846
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07009847 if (!pat_tb[NL80211_PKTPAT_OFFSET])
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08009848 pkt_offset = 0;
9849 else
9850 pkt_offset = nla_get_u32(
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07009851 pat_tb[NL80211_PKTPAT_OFFSET]);
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08009852 if (pkt_offset > wowlan->max_pkt_offset)
9853 goto error;
9854 new_triggers.patterns[i].pkt_offset = pkt_offset;
9855
Johannes Berg922bd802014-05-19 17:59:50 +02009856 mask_pat = kmalloc(mask_len + pat_len, GFP_KERNEL);
9857 if (!mask_pat) {
Johannes Bergff1b6e62011-05-04 15:37:28 +02009858 err = -ENOMEM;
9859 goto error;
9860 }
Johannes Berg922bd802014-05-19 17:59:50 +02009861 new_triggers.patterns[i].mask = mask_pat;
9862 memcpy(mask_pat, nla_data(pat_tb[NL80211_PKTPAT_MASK]),
Johannes Bergff1b6e62011-05-04 15:37:28 +02009863 mask_len);
Johannes Berg922bd802014-05-19 17:59:50 +02009864 mask_pat += mask_len;
9865 new_triggers.patterns[i].pattern = mask_pat;
Johannes Bergff1b6e62011-05-04 15:37:28 +02009866 new_triggers.patterns[i].pattern_len = pat_len;
Johannes Berg922bd802014-05-19 17:59:50 +02009867 memcpy(mask_pat,
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07009868 nla_data(pat_tb[NL80211_PKTPAT_PATTERN]),
Johannes Bergff1b6e62011-05-04 15:37:28 +02009869 pat_len);
9870 i++;
9871 }
9872 }
9873
Johannes Berg2a0e0472013-01-23 22:57:40 +01009874 if (tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION]) {
Johannes Berg98fc4382015-03-01 09:10:13 +02009875 regular = true;
Johannes Berg2a0e0472013-01-23 22:57:40 +01009876 err = nl80211_parse_wowlan_tcp(
9877 rdev, tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION],
9878 &new_triggers);
9879 if (err)
9880 goto error;
9881 }
9882
Luciano Coelho8cd4d452014-09-17 11:55:28 +03009883 if (tb[NL80211_WOWLAN_TRIG_NET_DETECT]) {
Johannes Berg98fc4382015-03-01 09:10:13 +02009884 regular = true;
Luciano Coelho8cd4d452014-09-17 11:55:28 +03009885 err = nl80211_parse_wowlan_nd(
9886 rdev, wowlan, tb[NL80211_WOWLAN_TRIG_NET_DETECT],
9887 &new_triggers);
9888 if (err)
9889 goto error;
9890 }
9891
Johannes Berg98fc4382015-03-01 09:10:13 +02009892 /* The 'any' trigger means the device continues operating more or less
9893 * as in its normal operation mode and wakes up the host on most of the
9894 * normal interrupts (like packet RX, ...)
9895 * It therefore makes little sense to combine with the more constrained
9896 * wakeup trigger modes.
9897 */
9898 if (new_triggers.any && regular) {
9899 err = -EINVAL;
9900 goto error;
9901 }
9902
Johannes Bergae33bd82012-07-12 16:25:02 +02009903 ntrig = kmemdup(&new_triggers, sizeof(new_triggers), GFP_KERNEL);
9904 if (!ntrig) {
9905 err = -ENOMEM;
9906 goto error;
Johannes Bergff1b6e62011-05-04 15:37:28 +02009907 }
Johannes Bergae33bd82012-07-12 16:25:02 +02009908 cfg80211_rdev_free_wowlan(rdev);
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009909 rdev->wiphy.wowlan_config = ntrig;
Johannes Bergff1b6e62011-05-04 15:37:28 +02009910
Johannes Bergae33bd82012-07-12 16:25:02 +02009911 set_wakeup:
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009912 if (rdev->ops->set_wakeup &&
9913 prev_enabled != !!rdev->wiphy.wowlan_config)
9914 rdev_set_wakeup(rdev, rdev->wiphy.wowlan_config);
Johannes Berg6d525632012-04-04 15:05:25 +02009915
Johannes Bergff1b6e62011-05-04 15:37:28 +02009916 return 0;
9917 error:
9918 for (i = 0; i < new_triggers.n_patterns; i++)
9919 kfree(new_triggers.patterns[i].mask);
9920 kfree(new_triggers.patterns);
Johannes Berg2a0e0472013-01-23 22:57:40 +01009921 if (new_triggers.tcp && new_triggers.tcp->sock)
9922 sock_release(new_triggers.tcp->sock);
9923 kfree(new_triggers.tcp);
Ola Olssone5dbe072015-12-12 23:17:17 +01009924 kfree(new_triggers.nd_config);
Johannes Bergff1b6e62011-05-04 15:37:28 +02009925 return err;
9926}
Johannes Bergdfb89c52012-06-27 09:23:48 +02009927#endif
Johannes Bergff1b6e62011-05-04 15:37:28 +02009928
Amitkumar Karwarbe29b992013-06-28 11:51:26 -07009929static int nl80211_send_coalesce_rules(struct sk_buff *msg,
9930 struct cfg80211_registered_device *rdev)
9931{
9932 struct nlattr *nl_pats, *nl_pat, *nl_rule, *nl_rules;
9933 int i, j, pat_len;
9934 struct cfg80211_coalesce_rules *rule;
9935
9936 if (!rdev->coalesce->n_rules)
9937 return 0;
9938
9939 nl_rules = nla_nest_start(msg, NL80211_ATTR_COALESCE_RULE);
9940 if (!nl_rules)
9941 return -ENOBUFS;
9942
9943 for (i = 0; i < rdev->coalesce->n_rules; i++) {
9944 nl_rule = nla_nest_start(msg, i + 1);
9945 if (!nl_rule)
9946 return -ENOBUFS;
9947
9948 rule = &rdev->coalesce->rules[i];
9949 if (nla_put_u32(msg, NL80211_ATTR_COALESCE_RULE_DELAY,
9950 rule->delay))
9951 return -ENOBUFS;
9952
9953 if (nla_put_u32(msg, NL80211_ATTR_COALESCE_RULE_CONDITION,
9954 rule->condition))
9955 return -ENOBUFS;
9956
9957 nl_pats = nla_nest_start(msg,
9958 NL80211_ATTR_COALESCE_RULE_PKT_PATTERN);
9959 if (!nl_pats)
9960 return -ENOBUFS;
9961
9962 for (j = 0; j < rule->n_patterns; j++) {
9963 nl_pat = nla_nest_start(msg, j + 1);
9964 if (!nl_pat)
9965 return -ENOBUFS;
9966 pat_len = rule->patterns[j].pattern_len;
9967 if (nla_put(msg, NL80211_PKTPAT_MASK,
9968 DIV_ROUND_UP(pat_len, 8),
9969 rule->patterns[j].mask) ||
9970 nla_put(msg, NL80211_PKTPAT_PATTERN, pat_len,
9971 rule->patterns[j].pattern) ||
9972 nla_put_u32(msg, NL80211_PKTPAT_OFFSET,
9973 rule->patterns[j].pkt_offset))
9974 return -ENOBUFS;
9975 nla_nest_end(msg, nl_pat);
9976 }
9977 nla_nest_end(msg, nl_pats);
9978 nla_nest_end(msg, nl_rule);
9979 }
9980 nla_nest_end(msg, nl_rules);
9981
9982 return 0;
9983}
9984
9985static int nl80211_get_coalesce(struct sk_buff *skb, struct genl_info *info)
9986{
9987 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9988 struct sk_buff *msg;
9989 void *hdr;
9990
9991 if (!rdev->wiphy.coalesce)
9992 return -EOPNOTSUPP;
9993
9994 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
9995 if (!msg)
9996 return -ENOMEM;
9997
9998 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
9999 NL80211_CMD_GET_COALESCE);
10000 if (!hdr)
10001 goto nla_put_failure;
10002
10003 if (rdev->coalesce && nl80211_send_coalesce_rules(msg, rdev))
10004 goto nla_put_failure;
10005
10006 genlmsg_end(msg, hdr);
10007 return genlmsg_reply(msg, info);
10008
10009nla_put_failure:
10010 nlmsg_free(msg);
10011 return -ENOBUFS;
10012}
10013
10014void cfg80211_rdev_free_coalesce(struct cfg80211_registered_device *rdev)
10015{
10016 struct cfg80211_coalesce *coalesce = rdev->coalesce;
10017 int i, j;
10018 struct cfg80211_coalesce_rules *rule;
10019
10020 if (!coalesce)
10021 return;
10022
10023 for (i = 0; i < coalesce->n_rules; i++) {
10024 rule = &coalesce->rules[i];
10025 for (j = 0; j < rule->n_patterns; j++)
10026 kfree(rule->patterns[j].mask);
10027 kfree(rule->patterns);
10028 }
10029 kfree(coalesce->rules);
10030 kfree(coalesce);
10031 rdev->coalesce = NULL;
10032}
10033
10034static int nl80211_parse_coalesce_rule(struct cfg80211_registered_device *rdev,
10035 struct nlattr *rule,
10036 struct cfg80211_coalesce_rules *new_rule)
10037{
10038 int err, i;
10039 const struct wiphy_coalesce_support *coalesce = rdev->wiphy.coalesce;
10040 struct nlattr *tb[NUM_NL80211_ATTR_COALESCE_RULE], *pat;
10041 int rem, pat_len, mask_len, pkt_offset, n_patterns = 0;
10042 struct nlattr *pat_tb[NUM_NL80211_PKTPAT];
10043
10044 err = nla_parse(tb, NL80211_ATTR_COALESCE_RULE_MAX, nla_data(rule),
10045 nla_len(rule), nl80211_coalesce_policy);
10046 if (err)
10047 return err;
10048
10049 if (tb[NL80211_ATTR_COALESCE_RULE_DELAY])
10050 new_rule->delay =
10051 nla_get_u32(tb[NL80211_ATTR_COALESCE_RULE_DELAY]);
10052 if (new_rule->delay > coalesce->max_delay)
10053 return -EINVAL;
10054
10055 if (tb[NL80211_ATTR_COALESCE_RULE_CONDITION])
10056 new_rule->condition =
10057 nla_get_u32(tb[NL80211_ATTR_COALESCE_RULE_CONDITION]);
10058 if (new_rule->condition != NL80211_COALESCE_CONDITION_MATCH &&
10059 new_rule->condition != NL80211_COALESCE_CONDITION_NO_MATCH)
10060 return -EINVAL;
10061
10062 if (!tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN])
10063 return -EINVAL;
10064
10065 nla_for_each_nested(pat, tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN],
10066 rem)
10067 n_patterns++;
10068 if (n_patterns > coalesce->n_patterns)
10069 return -EINVAL;
10070
10071 new_rule->patterns = kcalloc(n_patterns, sizeof(new_rule->patterns[0]),
10072 GFP_KERNEL);
10073 if (!new_rule->patterns)
10074 return -ENOMEM;
10075
10076 new_rule->n_patterns = n_patterns;
10077 i = 0;
10078
10079 nla_for_each_nested(pat, tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN],
10080 rem) {
Johannes Berg922bd802014-05-19 17:59:50 +020010081 u8 *mask_pat;
10082
Amitkumar Karwarbe29b992013-06-28 11:51:26 -070010083 nla_parse(pat_tb, MAX_NL80211_PKTPAT, nla_data(pat),
10084 nla_len(pat), NULL);
10085 if (!pat_tb[NL80211_PKTPAT_MASK] ||
10086 !pat_tb[NL80211_PKTPAT_PATTERN])
10087 return -EINVAL;
10088 pat_len = nla_len(pat_tb[NL80211_PKTPAT_PATTERN]);
10089 mask_len = DIV_ROUND_UP(pat_len, 8);
10090 if (nla_len(pat_tb[NL80211_PKTPAT_MASK]) != mask_len)
10091 return -EINVAL;
10092 if (pat_len > coalesce->pattern_max_len ||
10093 pat_len < coalesce->pattern_min_len)
10094 return -EINVAL;
10095
10096 if (!pat_tb[NL80211_PKTPAT_OFFSET])
10097 pkt_offset = 0;
10098 else
10099 pkt_offset = nla_get_u32(pat_tb[NL80211_PKTPAT_OFFSET]);
10100 if (pkt_offset > coalesce->max_pkt_offset)
10101 return -EINVAL;
10102 new_rule->patterns[i].pkt_offset = pkt_offset;
10103
Johannes Berg922bd802014-05-19 17:59:50 +020010104 mask_pat = kmalloc(mask_len + pat_len, GFP_KERNEL);
10105 if (!mask_pat)
Amitkumar Karwarbe29b992013-06-28 11:51:26 -070010106 return -ENOMEM;
Johannes Berg922bd802014-05-19 17:59:50 +020010107
10108 new_rule->patterns[i].mask = mask_pat;
10109 memcpy(mask_pat, nla_data(pat_tb[NL80211_PKTPAT_MASK]),
10110 mask_len);
10111
10112 mask_pat += mask_len;
10113 new_rule->patterns[i].pattern = mask_pat;
Amitkumar Karwarbe29b992013-06-28 11:51:26 -070010114 new_rule->patterns[i].pattern_len = pat_len;
Johannes Berg922bd802014-05-19 17:59:50 +020010115 memcpy(mask_pat, nla_data(pat_tb[NL80211_PKTPAT_PATTERN]),
10116 pat_len);
Amitkumar Karwarbe29b992013-06-28 11:51:26 -070010117 i++;
10118 }
10119
10120 return 0;
10121}
10122
10123static int nl80211_set_coalesce(struct sk_buff *skb, struct genl_info *info)
10124{
10125 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10126 const struct wiphy_coalesce_support *coalesce = rdev->wiphy.coalesce;
10127 struct cfg80211_coalesce new_coalesce = {};
10128 struct cfg80211_coalesce *n_coalesce;
10129 int err, rem_rule, n_rules = 0, i, j;
10130 struct nlattr *rule;
10131 struct cfg80211_coalesce_rules *tmp_rule;
10132
10133 if (!rdev->wiphy.coalesce || !rdev->ops->set_coalesce)
10134 return -EOPNOTSUPP;
10135
10136 if (!info->attrs[NL80211_ATTR_COALESCE_RULE]) {
10137 cfg80211_rdev_free_coalesce(rdev);
Ilan Peera1056b12015-10-22 22:27:46 +030010138 rdev_set_coalesce(rdev, NULL);
Amitkumar Karwarbe29b992013-06-28 11:51:26 -070010139 return 0;
10140 }
10141
10142 nla_for_each_nested(rule, info->attrs[NL80211_ATTR_COALESCE_RULE],
10143 rem_rule)
10144 n_rules++;
10145 if (n_rules > coalesce->n_rules)
10146 return -EINVAL;
10147
10148 new_coalesce.rules = kcalloc(n_rules, sizeof(new_coalesce.rules[0]),
10149 GFP_KERNEL);
10150 if (!new_coalesce.rules)
10151 return -ENOMEM;
10152
10153 new_coalesce.n_rules = n_rules;
10154 i = 0;
10155
10156 nla_for_each_nested(rule, info->attrs[NL80211_ATTR_COALESCE_RULE],
10157 rem_rule) {
10158 err = nl80211_parse_coalesce_rule(rdev, rule,
10159 &new_coalesce.rules[i]);
10160 if (err)
10161 goto error;
10162
10163 i++;
10164 }
10165
Ilan Peera1056b12015-10-22 22:27:46 +030010166 err = rdev_set_coalesce(rdev, &new_coalesce);
Amitkumar Karwarbe29b992013-06-28 11:51:26 -070010167 if (err)
10168 goto error;
10169
10170 n_coalesce = kmemdup(&new_coalesce, sizeof(new_coalesce), GFP_KERNEL);
10171 if (!n_coalesce) {
10172 err = -ENOMEM;
10173 goto error;
10174 }
10175 cfg80211_rdev_free_coalesce(rdev);
10176 rdev->coalesce = n_coalesce;
10177
10178 return 0;
10179error:
10180 for (i = 0; i < new_coalesce.n_rules; i++) {
10181 tmp_rule = &new_coalesce.rules[i];
10182 for (j = 0; j < tmp_rule->n_patterns; j++)
10183 kfree(tmp_rule->patterns[j].mask);
10184 kfree(tmp_rule->patterns);
10185 }
10186 kfree(new_coalesce.rules);
10187
10188 return err;
10189}
10190
Johannes Berge5497d72011-07-05 16:35:40 +020010191static int nl80211_set_rekey_data(struct sk_buff *skb, struct genl_info *info)
10192{
10193 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10194 struct net_device *dev = info->user_ptr[1];
10195 struct wireless_dev *wdev = dev->ieee80211_ptr;
10196 struct nlattr *tb[NUM_NL80211_REKEY_DATA];
10197 struct cfg80211_gtk_rekey_data rekey_data;
10198 int err;
10199
10200 if (!info->attrs[NL80211_ATTR_REKEY_DATA])
10201 return -EINVAL;
10202
10203 err = nla_parse(tb, MAX_NL80211_REKEY_DATA,
10204 nla_data(info->attrs[NL80211_ATTR_REKEY_DATA]),
10205 nla_len(info->attrs[NL80211_ATTR_REKEY_DATA]),
10206 nl80211_rekey_policy);
10207 if (err)
10208 return err;
10209
10210 if (nla_len(tb[NL80211_REKEY_DATA_REPLAY_CTR]) != NL80211_REPLAY_CTR_LEN)
10211 return -ERANGE;
10212 if (nla_len(tb[NL80211_REKEY_DATA_KEK]) != NL80211_KEK_LEN)
10213 return -ERANGE;
10214 if (nla_len(tb[NL80211_REKEY_DATA_KCK]) != NL80211_KCK_LEN)
10215 return -ERANGE;
10216
Johannes Berg78f686c2014-09-10 22:28:06 +030010217 rekey_data.kek = nla_data(tb[NL80211_REKEY_DATA_KEK]);
10218 rekey_data.kck = nla_data(tb[NL80211_REKEY_DATA_KCK]);
10219 rekey_data.replay_ctr = nla_data(tb[NL80211_REKEY_DATA_REPLAY_CTR]);
Johannes Berge5497d72011-07-05 16:35:40 +020010220
10221 wdev_lock(wdev);
10222 if (!wdev->current_bss) {
10223 err = -ENOTCONN;
10224 goto out;
10225 }
10226
10227 if (!rdev->ops->set_rekey_data) {
10228 err = -EOPNOTSUPP;
10229 goto out;
10230 }
10231
Hila Gonene35e4d22012-06-27 17:19:42 +030010232 err = rdev_set_rekey_data(rdev, dev, &rekey_data);
Johannes Berge5497d72011-07-05 16:35:40 +020010233 out:
10234 wdev_unlock(wdev);
10235 return err;
10236}
10237
Johannes Berg28946da2011-11-04 11:18:12 +010010238static int nl80211_register_unexpected_frame(struct sk_buff *skb,
10239 struct genl_info *info)
10240{
10241 struct net_device *dev = info->user_ptr[1];
10242 struct wireless_dev *wdev = dev->ieee80211_ptr;
10243
10244 if (wdev->iftype != NL80211_IFTYPE_AP &&
10245 wdev->iftype != NL80211_IFTYPE_P2P_GO)
10246 return -EINVAL;
10247
Eric W. Biederman15e47302012-09-07 20:12:54 +000010248 if (wdev->ap_unexpected_nlportid)
Johannes Berg28946da2011-11-04 11:18:12 +010010249 return -EBUSY;
10250
Eric W. Biederman15e47302012-09-07 20:12:54 +000010251 wdev->ap_unexpected_nlportid = info->snd_portid;
Johannes Berg28946da2011-11-04 11:18:12 +010010252 return 0;
10253}
10254
Johannes Berg7f6cf312011-11-04 11:18:15 +010010255static int nl80211_probe_client(struct sk_buff *skb,
10256 struct genl_info *info)
10257{
10258 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10259 struct net_device *dev = info->user_ptr[1];
10260 struct wireless_dev *wdev = dev->ieee80211_ptr;
10261 struct sk_buff *msg;
10262 void *hdr;
10263 const u8 *addr;
10264 u64 cookie;
10265 int err;
10266
10267 if (wdev->iftype != NL80211_IFTYPE_AP &&
10268 wdev->iftype != NL80211_IFTYPE_P2P_GO)
10269 return -EOPNOTSUPP;
10270
10271 if (!info->attrs[NL80211_ATTR_MAC])
10272 return -EINVAL;
10273
10274 if (!rdev->ops->probe_client)
10275 return -EOPNOTSUPP;
10276
10277 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
10278 if (!msg)
10279 return -ENOMEM;
10280
Eric W. Biederman15e47302012-09-07 20:12:54 +000010281 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berg7f6cf312011-11-04 11:18:15 +010010282 NL80211_CMD_PROBE_CLIENT);
Dan Carpentercb35fba2013-08-14 14:50:01 +030010283 if (!hdr) {
10284 err = -ENOBUFS;
Johannes Berg7f6cf312011-11-04 11:18:15 +010010285 goto free_msg;
10286 }
10287
10288 addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
10289
Hila Gonene35e4d22012-06-27 17:19:42 +030010290 err = rdev_probe_client(rdev, dev, addr, &cookie);
Johannes Berg7f6cf312011-11-04 11:18:15 +010010291 if (err)
10292 goto free_msg;
10293
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020010294 if (nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie,
10295 NL80211_ATTR_PAD))
David S. Miller9360ffd2012-03-29 04:41:26 -040010296 goto nla_put_failure;
Johannes Berg7f6cf312011-11-04 11:18:15 +010010297
10298 genlmsg_end(msg, hdr);
10299
10300 return genlmsg_reply(msg, info);
10301
10302 nla_put_failure:
10303 err = -ENOBUFS;
10304 free_msg:
10305 nlmsg_free(msg);
10306 return err;
10307}
10308
Johannes Berg5e7602302011-11-04 11:18:17 +010010309static int nl80211_register_beacons(struct sk_buff *skb, struct genl_info *info)
10310{
10311 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Ben Greear37c73b52012-10-26 14:49:25 -070010312 struct cfg80211_beacon_registration *reg, *nreg;
10313 int rv;
Johannes Berg5e7602302011-11-04 11:18:17 +010010314
10315 if (!(rdev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS))
10316 return -EOPNOTSUPP;
10317
Ben Greear37c73b52012-10-26 14:49:25 -070010318 nreg = kzalloc(sizeof(*nreg), GFP_KERNEL);
10319 if (!nreg)
10320 return -ENOMEM;
Johannes Berg5e7602302011-11-04 11:18:17 +010010321
Ben Greear37c73b52012-10-26 14:49:25 -070010322 /* First, check if already registered. */
10323 spin_lock_bh(&rdev->beacon_registrations_lock);
10324 list_for_each_entry(reg, &rdev->beacon_registrations, list) {
10325 if (reg->nlportid == info->snd_portid) {
10326 rv = -EALREADY;
10327 goto out_err;
10328 }
10329 }
10330 /* Add it to the list */
10331 nreg->nlportid = info->snd_portid;
10332 list_add(&nreg->list, &rdev->beacon_registrations);
10333
10334 spin_unlock_bh(&rdev->beacon_registrations_lock);
Johannes Berg5e7602302011-11-04 11:18:17 +010010335
10336 return 0;
Ben Greear37c73b52012-10-26 14:49:25 -070010337out_err:
10338 spin_unlock_bh(&rdev->beacon_registrations_lock);
10339 kfree(nreg);
10340 return rv;
Johannes Berg5e7602302011-11-04 11:18:17 +010010341}
10342
Johannes Berg98104fde2012-06-16 00:19:54 +020010343static int nl80211_start_p2p_device(struct sk_buff *skb, struct genl_info *info)
10344{
10345 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10346 struct wireless_dev *wdev = info->user_ptr[1];
10347 int err;
10348
10349 if (!rdev->ops->start_p2p_device)
10350 return -EOPNOTSUPP;
10351
10352 if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE)
10353 return -EOPNOTSUPP;
10354
10355 if (wdev->p2p_started)
10356 return 0;
10357
Luciano Coelhob6a55012014-02-27 11:07:21 +020010358 if (rfkill_blocked(rdev->rfkill))
10359 return -ERFKILL;
Johannes Berg98104fde2012-06-16 00:19:54 +020010360
Johannes Bergeeb126e2012-10-23 15:16:50 +020010361 err = rdev_start_p2p_device(rdev, wdev);
Johannes Berg98104fde2012-06-16 00:19:54 +020010362 if (err)
10363 return err;
10364
10365 wdev->p2p_started = true;
Johannes Berg98104fde2012-06-16 00:19:54 +020010366 rdev->opencount++;
Johannes Berg98104fde2012-06-16 00:19:54 +020010367
10368 return 0;
10369}
10370
10371static int nl80211_stop_p2p_device(struct sk_buff *skb, struct genl_info *info)
10372{
10373 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10374 struct wireless_dev *wdev = info->user_ptr[1];
10375
10376 if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE)
10377 return -EOPNOTSUPP;
10378
10379 if (!rdev->ops->stop_p2p_device)
10380 return -EOPNOTSUPP;
10381
Johannes Bergf9f47522013-03-19 15:04:07 +010010382 cfg80211_stop_p2p_device(rdev, wdev);
Johannes Berg98104fde2012-06-16 00:19:54 +020010383
10384 return 0;
10385}
10386
Johannes Berg3713b4e2013-02-14 16:19:38 +010010387static int nl80211_get_protocol_features(struct sk_buff *skb,
10388 struct genl_info *info)
10389{
10390 void *hdr;
10391 struct sk_buff *msg;
10392
10393 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
10394 if (!msg)
10395 return -ENOMEM;
10396
10397 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
10398 NL80211_CMD_GET_PROTOCOL_FEATURES);
10399 if (!hdr)
10400 goto nla_put_failure;
10401
10402 if (nla_put_u32(msg, NL80211_ATTR_PROTOCOL_FEATURES,
10403 NL80211_PROTOCOL_FEATURE_SPLIT_WIPHY_DUMP))
10404 goto nla_put_failure;
10405
10406 genlmsg_end(msg, hdr);
10407 return genlmsg_reply(msg, info);
10408
10409 nla_put_failure:
10410 kfree_skb(msg);
10411 return -ENOBUFS;
10412}
10413
Jouni Malinen355199e2013-02-27 17:14:27 +020010414static int nl80211_update_ft_ies(struct sk_buff *skb, struct genl_info *info)
10415{
10416 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10417 struct cfg80211_update_ft_ies_params ft_params;
10418 struct net_device *dev = info->user_ptr[1];
10419
10420 if (!rdev->ops->update_ft_ies)
10421 return -EOPNOTSUPP;
10422
10423 if (!info->attrs[NL80211_ATTR_MDID] ||
10424 !is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
10425 return -EINVAL;
10426
10427 memset(&ft_params, 0, sizeof(ft_params));
10428 ft_params.md = nla_get_u16(info->attrs[NL80211_ATTR_MDID]);
10429 ft_params.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
10430 ft_params.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
10431
10432 return rdev_update_ft_ies(rdev, dev, &ft_params);
10433}
10434
Arend van Spriel5de17982013-04-18 15:49:00 +020010435static int nl80211_crit_protocol_start(struct sk_buff *skb,
10436 struct genl_info *info)
10437{
10438 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10439 struct wireless_dev *wdev = info->user_ptr[1];
10440 enum nl80211_crit_proto_id proto = NL80211_CRIT_PROTO_UNSPEC;
10441 u16 duration;
10442 int ret;
10443
10444 if (!rdev->ops->crit_proto_start)
10445 return -EOPNOTSUPP;
10446
10447 if (WARN_ON(!rdev->ops->crit_proto_stop))
10448 return -EINVAL;
10449
10450 if (rdev->crit_proto_nlportid)
10451 return -EBUSY;
10452
10453 /* determine protocol if provided */
10454 if (info->attrs[NL80211_ATTR_CRIT_PROT_ID])
10455 proto = nla_get_u16(info->attrs[NL80211_ATTR_CRIT_PROT_ID]);
10456
10457 if (proto >= NUM_NL80211_CRIT_PROTO)
10458 return -EINVAL;
10459
10460 /* timeout must be provided */
10461 if (!info->attrs[NL80211_ATTR_MAX_CRIT_PROT_DURATION])
10462 return -EINVAL;
10463
10464 duration =
10465 nla_get_u16(info->attrs[NL80211_ATTR_MAX_CRIT_PROT_DURATION]);
10466
10467 if (duration > NL80211_CRIT_PROTO_MAX_DURATION)
10468 return -ERANGE;
10469
10470 ret = rdev_crit_proto_start(rdev, wdev, proto, duration);
10471 if (!ret)
10472 rdev->crit_proto_nlportid = info->snd_portid;
10473
10474 return ret;
10475}
10476
10477static int nl80211_crit_protocol_stop(struct sk_buff *skb,
10478 struct genl_info *info)
10479{
10480 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10481 struct wireless_dev *wdev = info->user_ptr[1];
10482
10483 if (!rdev->ops->crit_proto_stop)
10484 return -EOPNOTSUPP;
10485
10486 if (rdev->crit_proto_nlportid) {
10487 rdev->crit_proto_nlportid = 0;
10488 rdev_crit_proto_stop(rdev, wdev);
10489 }
10490 return 0;
10491}
10492
Johannes Bergad7e7182013-11-13 13:37:47 +010010493static int nl80211_vendor_cmd(struct sk_buff *skb, struct genl_info *info)
10494{
10495 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10496 struct wireless_dev *wdev =
10497 __cfg80211_wdev_from_attrs(genl_info_net(info), info->attrs);
10498 int i, err;
10499 u32 vid, subcmd;
10500
10501 if (!rdev->wiphy.vendor_commands)
10502 return -EOPNOTSUPP;
10503
10504 if (IS_ERR(wdev)) {
10505 err = PTR_ERR(wdev);
10506 if (err != -EINVAL)
10507 return err;
10508 wdev = NULL;
10509 } else if (wdev->wiphy != &rdev->wiphy) {
10510 return -EINVAL;
10511 }
10512
10513 if (!info->attrs[NL80211_ATTR_VENDOR_ID] ||
10514 !info->attrs[NL80211_ATTR_VENDOR_SUBCMD])
10515 return -EINVAL;
10516
10517 vid = nla_get_u32(info->attrs[NL80211_ATTR_VENDOR_ID]);
10518 subcmd = nla_get_u32(info->attrs[NL80211_ATTR_VENDOR_SUBCMD]);
10519 for (i = 0; i < rdev->wiphy.n_vendor_commands; i++) {
10520 const struct wiphy_vendor_command *vcmd;
10521 void *data = NULL;
10522 int len = 0;
10523
10524 vcmd = &rdev->wiphy.vendor_commands[i];
10525
10526 if (vcmd->info.vendor_id != vid || vcmd->info.subcmd != subcmd)
10527 continue;
10528
10529 if (vcmd->flags & (WIPHY_VENDOR_CMD_NEED_WDEV |
10530 WIPHY_VENDOR_CMD_NEED_NETDEV)) {
10531 if (!wdev)
10532 return -EINVAL;
10533 if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_NETDEV &&
10534 !wdev->netdev)
10535 return -EINVAL;
10536
10537 if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_RUNNING) {
10538 if (wdev->netdev &&
10539 !netif_running(wdev->netdev))
10540 return -ENETDOWN;
10541 if (!wdev->netdev && !wdev->p2p_started)
10542 return -ENETDOWN;
10543 }
Johannes Berg7bdbe402015-08-15 22:39:49 +030010544
10545 if (!vcmd->doit)
10546 return -EOPNOTSUPP;
Johannes Bergad7e7182013-11-13 13:37:47 +010010547 } else {
10548 wdev = NULL;
10549 }
10550
10551 if (info->attrs[NL80211_ATTR_VENDOR_DATA]) {
10552 data = nla_data(info->attrs[NL80211_ATTR_VENDOR_DATA]);
10553 len = nla_len(info->attrs[NL80211_ATTR_VENDOR_DATA]);
10554 }
10555
10556 rdev->cur_cmd_info = info;
10557 err = rdev->wiphy.vendor_commands[i].doit(&rdev->wiphy, wdev,
10558 data, len);
10559 rdev->cur_cmd_info = NULL;
10560 return err;
10561 }
10562
10563 return -EOPNOTSUPP;
10564}
10565
Johannes Berg7bdbe402015-08-15 22:39:49 +030010566static int nl80211_prepare_vendor_dump(struct sk_buff *skb,
10567 struct netlink_callback *cb,
10568 struct cfg80211_registered_device **rdev,
10569 struct wireless_dev **wdev)
10570{
10571 u32 vid, subcmd;
10572 unsigned int i;
10573 int vcmd_idx = -1;
10574 int err;
10575 void *data = NULL;
10576 unsigned int data_len = 0;
10577
10578 rtnl_lock();
10579
10580 if (cb->args[0]) {
10581 /* subtract the 1 again here */
10582 struct wiphy *wiphy = wiphy_idx_to_wiphy(cb->args[0] - 1);
10583 struct wireless_dev *tmp;
10584
10585 if (!wiphy) {
10586 err = -ENODEV;
10587 goto out_unlock;
10588 }
10589 *rdev = wiphy_to_rdev(wiphy);
10590 *wdev = NULL;
10591
10592 if (cb->args[1]) {
Johannes Berg53873f12016-05-03 16:52:04 +030010593 list_for_each_entry(tmp, &wiphy->wdev_list, list) {
Johannes Berg7bdbe402015-08-15 22:39:49 +030010594 if (tmp->identifier == cb->args[1] - 1) {
10595 *wdev = tmp;
10596 break;
10597 }
10598 }
10599 }
10600
10601 /* keep rtnl locked in successful case */
10602 return 0;
10603 }
10604
10605 err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize,
10606 nl80211_fam.attrbuf, nl80211_fam.maxattr,
10607 nl80211_policy);
10608 if (err)
10609 goto out_unlock;
10610
10611 if (!nl80211_fam.attrbuf[NL80211_ATTR_VENDOR_ID] ||
10612 !nl80211_fam.attrbuf[NL80211_ATTR_VENDOR_SUBCMD]) {
10613 err = -EINVAL;
10614 goto out_unlock;
10615 }
10616
10617 *wdev = __cfg80211_wdev_from_attrs(sock_net(skb->sk),
10618 nl80211_fam.attrbuf);
10619 if (IS_ERR(*wdev))
10620 *wdev = NULL;
10621
10622 *rdev = __cfg80211_rdev_from_attrs(sock_net(skb->sk),
10623 nl80211_fam.attrbuf);
10624 if (IS_ERR(*rdev)) {
10625 err = PTR_ERR(*rdev);
10626 goto out_unlock;
10627 }
10628
10629 vid = nla_get_u32(nl80211_fam.attrbuf[NL80211_ATTR_VENDOR_ID]);
10630 subcmd = nla_get_u32(nl80211_fam.attrbuf[NL80211_ATTR_VENDOR_SUBCMD]);
10631
10632 for (i = 0; i < (*rdev)->wiphy.n_vendor_commands; i++) {
10633 const struct wiphy_vendor_command *vcmd;
10634
10635 vcmd = &(*rdev)->wiphy.vendor_commands[i];
10636
10637 if (vcmd->info.vendor_id != vid || vcmd->info.subcmd != subcmd)
10638 continue;
10639
10640 if (!vcmd->dumpit) {
10641 err = -EOPNOTSUPP;
10642 goto out_unlock;
10643 }
10644
10645 vcmd_idx = i;
10646 break;
10647 }
10648
10649 if (vcmd_idx < 0) {
10650 err = -EOPNOTSUPP;
10651 goto out_unlock;
10652 }
10653
10654 if (nl80211_fam.attrbuf[NL80211_ATTR_VENDOR_DATA]) {
10655 data = nla_data(nl80211_fam.attrbuf[NL80211_ATTR_VENDOR_DATA]);
10656 data_len = nla_len(nl80211_fam.attrbuf[NL80211_ATTR_VENDOR_DATA]);
10657 }
10658
10659 /* 0 is the first index - add 1 to parse only once */
10660 cb->args[0] = (*rdev)->wiphy_idx + 1;
10661 /* add 1 to know if it was NULL */
10662 cb->args[1] = *wdev ? (*wdev)->identifier + 1 : 0;
10663 cb->args[2] = vcmd_idx;
10664 cb->args[3] = (unsigned long)data;
10665 cb->args[4] = data_len;
10666
10667 /* keep rtnl locked in successful case */
10668 return 0;
10669 out_unlock:
10670 rtnl_unlock();
10671 return err;
10672}
10673
10674static int nl80211_vendor_cmd_dump(struct sk_buff *skb,
10675 struct netlink_callback *cb)
10676{
10677 struct cfg80211_registered_device *rdev;
10678 struct wireless_dev *wdev;
10679 unsigned int vcmd_idx;
10680 const struct wiphy_vendor_command *vcmd;
10681 void *data;
10682 int data_len;
10683 int err;
10684 struct nlattr *vendor_data;
10685
10686 err = nl80211_prepare_vendor_dump(skb, cb, &rdev, &wdev);
10687 if (err)
10688 return err;
10689
10690 vcmd_idx = cb->args[2];
10691 data = (void *)cb->args[3];
10692 data_len = cb->args[4];
10693 vcmd = &rdev->wiphy.vendor_commands[vcmd_idx];
10694
10695 if (vcmd->flags & (WIPHY_VENDOR_CMD_NEED_WDEV |
10696 WIPHY_VENDOR_CMD_NEED_NETDEV)) {
10697 if (!wdev)
10698 return -EINVAL;
10699 if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_NETDEV &&
10700 !wdev->netdev)
10701 return -EINVAL;
10702
10703 if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_RUNNING) {
10704 if (wdev->netdev &&
10705 !netif_running(wdev->netdev))
10706 return -ENETDOWN;
10707 if (!wdev->netdev && !wdev->p2p_started)
10708 return -ENETDOWN;
10709 }
10710 }
10711
10712 while (1) {
10713 void *hdr = nl80211hdr_put(skb, NETLINK_CB(cb->skb).portid,
10714 cb->nlh->nlmsg_seq, NLM_F_MULTI,
10715 NL80211_CMD_VENDOR);
10716 if (!hdr)
10717 break;
10718
10719 if (nla_put_u32(skb, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020010720 (wdev && nla_put_u64_64bit(skb, NL80211_ATTR_WDEV,
10721 wdev_id(wdev),
10722 NL80211_ATTR_PAD))) {
Johannes Berg7bdbe402015-08-15 22:39:49 +030010723 genlmsg_cancel(skb, hdr);
10724 break;
10725 }
10726
10727 vendor_data = nla_nest_start(skb, NL80211_ATTR_VENDOR_DATA);
10728 if (!vendor_data) {
10729 genlmsg_cancel(skb, hdr);
10730 break;
10731 }
10732
10733 err = vcmd->dumpit(&rdev->wiphy, wdev, skb, data, data_len,
10734 (unsigned long *)&cb->args[5]);
10735 nla_nest_end(skb, vendor_data);
10736
10737 if (err == -ENOBUFS || err == -ENOENT) {
10738 genlmsg_cancel(skb, hdr);
10739 break;
10740 } else if (err) {
10741 genlmsg_cancel(skb, hdr);
10742 goto out;
10743 }
10744
10745 genlmsg_end(skb, hdr);
10746 }
10747
10748 err = skb->len;
10749 out:
10750 rtnl_unlock();
10751 return err;
10752}
10753
Johannes Bergad7e7182013-11-13 13:37:47 +010010754struct sk_buff *__cfg80211_alloc_reply_skb(struct wiphy *wiphy,
10755 enum nl80211_commands cmd,
10756 enum nl80211_attrs attr,
10757 int approxlen)
10758{
Zhao, Gangf26cbf42014-04-21 12:53:03 +080010759 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Bergad7e7182013-11-13 13:37:47 +010010760
10761 if (WARN_ON(!rdev->cur_cmd_info))
10762 return NULL;
10763
Ahmad Kholaif6c09e792015-02-26 15:26:53 +020010764 return __cfg80211_alloc_vendor_skb(rdev, NULL, approxlen,
Johannes Bergad7e7182013-11-13 13:37:47 +010010765 rdev->cur_cmd_info->snd_portid,
10766 rdev->cur_cmd_info->snd_seq,
Johannes Berg567ffc32013-12-18 14:43:31 +010010767 cmd, attr, NULL, GFP_KERNEL);
Johannes Bergad7e7182013-11-13 13:37:47 +010010768}
10769EXPORT_SYMBOL(__cfg80211_alloc_reply_skb);
10770
10771int cfg80211_vendor_cmd_reply(struct sk_buff *skb)
10772{
10773 struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0];
10774 void *hdr = ((void **)skb->cb)[1];
10775 struct nlattr *data = ((void **)skb->cb)[2];
10776
Johannes Bergbd8c78e2014-07-30 14:55:26 +020010777 /* clear CB data for netlink core to own from now on */
10778 memset(skb->cb, 0, sizeof(skb->cb));
10779
Johannes Bergad7e7182013-11-13 13:37:47 +010010780 if (WARN_ON(!rdev->cur_cmd_info)) {
10781 kfree_skb(skb);
10782 return -EINVAL;
10783 }
10784
10785 nla_nest_end(skb, data);
10786 genlmsg_end(skb, hdr);
10787 return genlmsg_reply(skb, rdev->cur_cmd_info);
10788}
10789EXPORT_SYMBOL_GPL(cfg80211_vendor_cmd_reply);
10790
Kyeyoon Parkfa9ffc72013-12-16 23:01:30 -080010791static int nl80211_set_qos_map(struct sk_buff *skb,
10792 struct genl_info *info)
10793{
10794 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10795 struct cfg80211_qos_map *qos_map = NULL;
10796 struct net_device *dev = info->user_ptr[1];
10797 u8 *pos, len, num_des, des_len, des;
10798 int ret;
10799
10800 if (!rdev->ops->set_qos_map)
10801 return -EOPNOTSUPP;
10802
10803 if (info->attrs[NL80211_ATTR_QOS_MAP]) {
10804 pos = nla_data(info->attrs[NL80211_ATTR_QOS_MAP]);
10805 len = nla_len(info->attrs[NL80211_ATTR_QOS_MAP]);
10806
10807 if (len % 2 || len < IEEE80211_QOS_MAP_LEN_MIN ||
10808 len > IEEE80211_QOS_MAP_LEN_MAX)
10809 return -EINVAL;
10810
10811 qos_map = kzalloc(sizeof(struct cfg80211_qos_map), GFP_KERNEL);
10812 if (!qos_map)
10813 return -ENOMEM;
10814
10815 num_des = (len - IEEE80211_QOS_MAP_LEN_MIN) >> 1;
10816 if (num_des) {
10817 des_len = num_des *
10818 sizeof(struct cfg80211_dscp_exception);
10819 memcpy(qos_map->dscp_exception, pos, des_len);
10820 qos_map->num_des = num_des;
10821 for (des = 0; des < num_des; des++) {
10822 if (qos_map->dscp_exception[des].up > 7) {
10823 kfree(qos_map);
10824 return -EINVAL;
10825 }
10826 }
10827 pos += des_len;
10828 }
10829 memcpy(qos_map->up, pos, IEEE80211_QOS_MAP_LEN_MIN);
10830 }
10831
10832 wdev_lock(dev->ieee80211_ptr);
10833 ret = nl80211_key_allowed(dev->ieee80211_ptr);
10834 if (!ret)
10835 ret = rdev_set_qos_map(rdev, dev, qos_map);
10836 wdev_unlock(dev->ieee80211_ptr);
10837
10838 kfree(qos_map);
10839 return ret;
10840}
10841
Johannes Berg960d01a2014-09-09 22:55:35 +030010842static int nl80211_add_tx_ts(struct sk_buff *skb, struct genl_info *info)
10843{
10844 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10845 struct net_device *dev = info->user_ptr[1];
10846 struct wireless_dev *wdev = dev->ieee80211_ptr;
10847 const u8 *peer;
10848 u8 tsid, up;
10849 u16 admitted_time = 0;
10850 int err;
10851
Johannes Berg723e73a2014-10-22 09:25:06 +020010852 if (!(rdev->wiphy.features & NL80211_FEATURE_SUPPORTS_WMM_ADMISSION))
Johannes Berg960d01a2014-09-09 22:55:35 +030010853 return -EOPNOTSUPP;
10854
10855 if (!info->attrs[NL80211_ATTR_TSID] || !info->attrs[NL80211_ATTR_MAC] ||
10856 !info->attrs[NL80211_ATTR_USER_PRIO])
10857 return -EINVAL;
10858
10859 tsid = nla_get_u8(info->attrs[NL80211_ATTR_TSID]);
10860 if (tsid >= IEEE80211_NUM_TIDS)
10861 return -EINVAL;
10862
10863 up = nla_get_u8(info->attrs[NL80211_ATTR_USER_PRIO]);
10864 if (up >= IEEE80211_NUM_UPS)
10865 return -EINVAL;
10866
10867 /* WMM uses TIDs 0-7 even for TSPEC */
Johannes Berg723e73a2014-10-22 09:25:06 +020010868 if (tsid >= IEEE80211_FIRST_TSPEC_TSID) {
Johannes Berg960d01a2014-09-09 22:55:35 +030010869 /* TODO: handle 802.11 TSPEC/admission control
Johannes Berg723e73a2014-10-22 09:25:06 +020010870 * need more attributes for that (e.g. BA session requirement);
10871 * change the WMM adminssion test above to allow both then
Johannes Berg960d01a2014-09-09 22:55:35 +030010872 */
10873 return -EINVAL;
10874 }
10875
10876 peer = nla_data(info->attrs[NL80211_ATTR_MAC]);
10877
10878 if (info->attrs[NL80211_ATTR_ADMITTED_TIME]) {
10879 admitted_time =
10880 nla_get_u16(info->attrs[NL80211_ATTR_ADMITTED_TIME]);
10881 if (!admitted_time)
10882 return -EINVAL;
10883 }
10884
10885 wdev_lock(wdev);
10886 switch (wdev->iftype) {
10887 case NL80211_IFTYPE_STATION:
10888 case NL80211_IFTYPE_P2P_CLIENT:
10889 if (wdev->current_bss)
10890 break;
10891 err = -ENOTCONN;
10892 goto out;
10893 default:
10894 err = -EOPNOTSUPP;
10895 goto out;
10896 }
10897
10898 err = rdev_add_tx_ts(rdev, dev, tsid, peer, up, admitted_time);
10899
10900 out:
10901 wdev_unlock(wdev);
10902 return err;
10903}
10904
10905static int nl80211_del_tx_ts(struct sk_buff *skb, struct genl_info *info)
10906{
10907 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10908 struct net_device *dev = info->user_ptr[1];
10909 struct wireless_dev *wdev = dev->ieee80211_ptr;
10910 const u8 *peer;
10911 u8 tsid;
10912 int err;
10913
10914 if (!info->attrs[NL80211_ATTR_TSID] || !info->attrs[NL80211_ATTR_MAC])
10915 return -EINVAL;
10916
10917 tsid = nla_get_u8(info->attrs[NL80211_ATTR_TSID]);
10918 peer = nla_data(info->attrs[NL80211_ATTR_MAC]);
10919
10920 wdev_lock(wdev);
10921 err = rdev_del_tx_ts(rdev, dev, tsid, peer);
10922 wdev_unlock(wdev);
10923
10924 return err;
10925}
10926
Arik Nemtsov1057d352014-11-19 12:54:26 +020010927static int nl80211_tdls_channel_switch(struct sk_buff *skb,
10928 struct genl_info *info)
10929{
10930 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10931 struct net_device *dev = info->user_ptr[1];
10932 struct wireless_dev *wdev = dev->ieee80211_ptr;
10933 struct cfg80211_chan_def chandef = {};
10934 const u8 *addr;
10935 u8 oper_class;
10936 int err;
10937
10938 if (!rdev->ops->tdls_channel_switch ||
10939 !(rdev->wiphy.features & NL80211_FEATURE_TDLS_CHANNEL_SWITCH))
10940 return -EOPNOTSUPP;
10941
10942 switch (dev->ieee80211_ptr->iftype) {
10943 case NL80211_IFTYPE_STATION:
10944 case NL80211_IFTYPE_P2P_CLIENT:
10945 break;
10946 default:
10947 return -EOPNOTSUPP;
10948 }
10949
10950 if (!info->attrs[NL80211_ATTR_MAC] ||
10951 !info->attrs[NL80211_ATTR_OPER_CLASS])
10952 return -EINVAL;
10953
10954 err = nl80211_parse_chandef(rdev, info, &chandef);
10955 if (err)
10956 return err;
10957
10958 /*
10959 * Don't allow wide channels on the 2.4Ghz band, as per IEEE802.11-2012
10960 * section 10.22.6.2.1. Disallow 5/10Mhz channels as well for now, the
10961 * specification is not defined for them.
10962 */
Johannes Berg57fbcce2016-04-12 15:56:15 +020010963 if (chandef.chan->band == NL80211_BAND_2GHZ &&
Arik Nemtsov1057d352014-11-19 12:54:26 +020010964 chandef.width != NL80211_CHAN_WIDTH_20_NOHT &&
10965 chandef.width != NL80211_CHAN_WIDTH_20)
10966 return -EINVAL;
10967
10968 /* we will be active on the TDLS link */
Arik Nemtsov923b3522015-07-08 15:41:44 +030010969 if (!cfg80211_reg_can_beacon_relax(&rdev->wiphy, &chandef,
10970 wdev->iftype))
Arik Nemtsov1057d352014-11-19 12:54:26 +020010971 return -EINVAL;
10972
10973 /* don't allow switching to DFS channels */
10974 if (cfg80211_chandef_dfs_required(wdev->wiphy, &chandef, wdev->iftype))
10975 return -EINVAL;
10976
10977 addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
10978 oper_class = nla_get_u8(info->attrs[NL80211_ATTR_OPER_CLASS]);
10979
10980 wdev_lock(wdev);
10981 err = rdev_tdls_channel_switch(rdev, dev, addr, oper_class, &chandef);
10982 wdev_unlock(wdev);
10983
10984 return err;
10985}
10986
10987static int nl80211_tdls_cancel_channel_switch(struct sk_buff *skb,
10988 struct genl_info *info)
10989{
10990 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10991 struct net_device *dev = info->user_ptr[1];
10992 struct wireless_dev *wdev = dev->ieee80211_ptr;
10993 const u8 *addr;
10994
10995 if (!rdev->ops->tdls_channel_switch ||
10996 !rdev->ops->tdls_cancel_channel_switch ||
10997 !(rdev->wiphy.features & NL80211_FEATURE_TDLS_CHANNEL_SWITCH))
10998 return -EOPNOTSUPP;
10999
11000 switch (dev->ieee80211_ptr->iftype) {
11001 case NL80211_IFTYPE_STATION:
11002 case NL80211_IFTYPE_P2P_CLIENT:
11003 break;
11004 default:
11005 return -EOPNOTSUPP;
11006 }
11007
11008 if (!info->attrs[NL80211_ATTR_MAC])
11009 return -EINVAL;
11010
11011 addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
11012
11013 wdev_lock(wdev);
11014 rdev_tdls_cancel_channel_switch(rdev, dev, addr);
11015 wdev_unlock(wdev);
11016
11017 return 0;
11018}
11019
Johannes Berg4c476992010-10-04 21:36:35 +020011020#define NL80211_FLAG_NEED_WIPHY 0x01
11021#define NL80211_FLAG_NEED_NETDEV 0x02
11022#define NL80211_FLAG_NEED_RTNL 0x04
Johannes Berg41265712010-10-04 21:14:05 +020011023#define NL80211_FLAG_CHECK_NETDEV_UP 0x08
11024#define NL80211_FLAG_NEED_NETDEV_UP (NL80211_FLAG_NEED_NETDEV |\
11025 NL80211_FLAG_CHECK_NETDEV_UP)
Johannes Berg1bf614e2012-06-15 15:23:36 +020011026#define NL80211_FLAG_NEED_WDEV 0x10
Johannes Berg98104fde2012-06-16 00:19:54 +020011027/* If a netdev is associated, it must be UP, P2P must be started */
Johannes Berg1bf614e2012-06-15 15:23:36 +020011028#define NL80211_FLAG_NEED_WDEV_UP (NL80211_FLAG_NEED_WDEV |\
11029 NL80211_FLAG_CHECK_NETDEV_UP)
Johannes Berg5393b912014-09-10 15:00:16 +030011030#define NL80211_FLAG_CLEAR_SKB 0x20
Johannes Berg4c476992010-10-04 21:36:35 +020011031
Johannes Bergf84f7712013-11-14 17:14:45 +010011032static int nl80211_pre_doit(const struct genl_ops *ops, struct sk_buff *skb,
Johannes Berg4c476992010-10-04 21:36:35 +020011033 struct genl_info *info)
11034{
11035 struct cfg80211_registered_device *rdev;
Johannes Berg89a54e42012-06-15 14:33:17 +020011036 struct wireless_dev *wdev;
Johannes Berg4c476992010-10-04 21:36:35 +020011037 struct net_device *dev;
Johannes Berg4c476992010-10-04 21:36:35 +020011038 bool rtnl = ops->internal_flags & NL80211_FLAG_NEED_RTNL;
11039
11040 if (rtnl)
11041 rtnl_lock();
11042
11043 if (ops->internal_flags & NL80211_FLAG_NEED_WIPHY) {
Johannes Berg4f7eff12012-06-15 14:14:22 +020011044 rdev = cfg80211_get_dev_from_info(genl_info_net(info), info);
Johannes Berg4c476992010-10-04 21:36:35 +020011045 if (IS_ERR(rdev)) {
11046 if (rtnl)
11047 rtnl_unlock();
11048 return PTR_ERR(rdev);
11049 }
11050 info->user_ptr[0] = rdev;
Johannes Berg1bf614e2012-06-15 15:23:36 +020011051 } else if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV ||
11052 ops->internal_flags & NL80211_FLAG_NEED_WDEV) {
Johannes Berg5fe231e2013-05-08 21:45:15 +020011053 ASSERT_RTNL();
11054
Johannes Berg89a54e42012-06-15 14:33:17 +020011055 wdev = __cfg80211_wdev_from_attrs(genl_info_net(info),
11056 info->attrs);
11057 if (IS_ERR(wdev)) {
Johannes Berg4c476992010-10-04 21:36:35 +020011058 if (rtnl)
11059 rtnl_unlock();
Johannes Berg89a54e42012-06-15 14:33:17 +020011060 return PTR_ERR(wdev);
Johannes Berg4c476992010-10-04 21:36:35 +020011061 }
Johannes Berg89a54e42012-06-15 14:33:17 +020011062
Johannes Berg89a54e42012-06-15 14:33:17 +020011063 dev = wdev->netdev;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080011064 rdev = wiphy_to_rdev(wdev->wiphy);
Johannes Berg89a54e42012-06-15 14:33:17 +020011065
Johannes Berg1bf614e2012-06-15 15:23:36 +020011066 if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV) {
11067 if (!dev) {
Johannes Berg1bf614e2012-06-15 15:23:36 +020011068 if (rtnl)
11069 rtnl_unlock();
11070 return -EINVAL;
11071 }
11072
11073 info->user_ptr[1] = dev;
11074 } else {
11075 info->user_ptr[1] = wdev;
Johannes Berg41265712010-10-04 21:14:05 +020011076 }
Johannes Berg89a54e42012-06-15 14:33:17 +020011077
Johannes Berg1bf614e2012-06-15 15:23:36 +020011078 if (dev) {
11079 if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP &&
11080 !netif_running(dev)) {
Johannes Berg1bf614e2012-06-15 15:23:36 +020011081 if (rtnl)
11082 rtnl_unlock();
11083 return -ENETDOWN;
11084 }
11085
11086 dev_hold(dev);
Johannes Berg98104fde2012-06-16 00:19:54 +020011087 } else if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP) {
11088 if (!wdev->p2p_started) {
Johannes Berg98104fde2012-06-16 00:19:54 +020011089 if (rtnl)
11090 rtnl_unlock();
11091 return -ENETDOWN;
11092 }
Johannes Berg1bf614e2012-06-15 15:23:36 +020011093 }
11094
Johannes Berg4c476992010-10-04 21:36:35 +020011095 info->user_ptr[0] = rdev;
Johannes Berg4c476992010-10-04 21:36:35 +020011096 }
11097
11098 return 0;
11099}
11100
Johannes Bergf84f7712013-11-14 17:14:45 +010011101static void nl80211_post_doit(const struct genl_ops *ops, struct sk_buff *skb,
Johannes Berg4c476992010-10-04 21:36:35 +020011102 struct genl_info *info)
11103{
Johannes Berg1bf614e2012-06-15 15:23:36 +020011104 if (info->user_ptr[1]) {
11105 if (ops->internal_flags & NL80211_FLAG_NEED_WDEV) {
11106 struct wireless_dev *wdev = info->user_ptr[1];
11107
11108 if (wdev->netdev)
11109 dev_put(wdev->netdev);
11110 } else {
11111 dev_put(info->user_ptr[1]);
11112 }
11113 }
Johannes Berg5393b912014-09-10 15:00:16 +030011114
Johannes Berg4c476992010-10-04 21:36:35 +020011115 if (ops->internal_flags & NL80211_FLAG_NEED_RTNL)
11116 rtnl_unlock();
Johannes Berg5393b912014-09-10 15:00:16 +030011117
11118 /* If needed, clear the netlink message payload from the SKB
11119 * as it might contain key data that shouldn't stick around on
11120 * the heap after the SKB is freed. The netlink message header
11121 * is still needed for further processing, so leave it intact.
11122 */
11123 if (ops->internal_flags & NL80211_FLAG_CLEAR_SKB) {
11124 struct nlmsghdr *nlh = nlmsg_hdr(skb);
11125
11126 memset(nlmsg_data(nlh), 0, nlmsg_len(nlh));
11127 }
Johannes Berg4c476992010-10-04 21:36:35 +020011128}
11129
Johannes Berg4534de82013-11-14 17:14:46 +010011130static const struct genl_ops nl80211_ops[] = {
Johannes Berg55682962007-09-20 13:09:35 -040011131 {
11132 .cmd = NL80211_CMD_GET_WIPHY,
11133 .doit = nl80211_get_wiphy,
11134 .dumpit = nl80211_dump_wiphy,
Johannes Berg86e8cf92013-06-19 10:57:22 +020011135 .done = nl80211_dump_wiphy_done,
Johannes Berg55682962007-09-20 13:09:35 -040011136 .policy = nl80211_policy,
11137 /* can be retrieved by unprivileged users */
Johannes Berg5fe231e2013-05-08 21:45:15 +020011138 .internal_flags = NL80211_FLAG_NEED_WIPHY |
11139 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -040011140 },
11141 {
11142 .cmd = NL80211_CMD_SET_WIPHY,
11143 .doit = nl80211_set_wiphy,
11144 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011145 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020011146 .internal_flags = NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -040011147 },
11148 {
11149 .cmd = NL80211_CMD_GET_INTERFACE,
11150 .doit = nl80211_get_interface,
11151 .dumpit = nl80211_dump_interface,
11152 .policy = nl80211_policy,
11153 /* can be retrieved by unprivileged users */
Johannes Berg5fe231e2013-05-08 21:45:15 +020011154 .internal_flags = NL80211_FLAG_NEED_WDEV |
11155 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -040011156 },
11157 {
11158 .cmd = NL80211_CMD_SET_INTERFACE,
11159 .doit = nl80211_set_interface,
11160 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011161 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020011162 .internal_flags = NL80211_FLAG_NEED_NETDEV |
11163 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -040011164 },
11165 {
11166 .cmd = NL80211_CMD_NEW_INTERFACE,
11167 .doit = nl80211_new_interface,
11168 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011169 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020011170 .internal_flags = NL80211_FLAG_NEED_WIPHY |
11171 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -040011172 },
11173 {
11174 .cmd = NL80211_CMD_DEL_INTERFACE,
11175 .doit = nl80211_del_interface,
11176 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011177 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg84efbb82012-06-16 00:00:26 +020011178 .internal_flags = NL80211_FLAG_NEED_WDEV |
Johannes Berg4c476992010-10-04 21:36:35 +020011179 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -040011180 },
Johannes Berg41ade002007-12-19 02:03:29 +010011181 {
11182 .cmd = NL80211_CMD_GET_KEY,
11183 .doit = nl80211_get_key,
11184 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011185 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020011186 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020011187 NL80211_FLAG_NEED_RTNL,
Johannes Berg41ade002007-12-19 02:03:29 +010011188 },
11189 {
11190 .cmd = NL80211_CMD_SET_KEY,
11191 .doit = nl80211_set_key,
11192 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011193 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020011194 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg5393b912014-09-10 15:00:16 +030011195 NL80211_FLAG_NEED_RTNL |
11196 NL80211_FLAG_CLEAR_SKB,
Johannes Berg41ade002007-12-19 02:03:29 +010011197 },
11198 {
11199 .cmd = NL80211_CMD_NEW_KEY,
11200 .doit = nl80211_new_key,
11201 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011202 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020011203 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg5393b912014-09-10 15:00:16 +030011204 NL80211_FLAG_NEED_RTNL |
11205 NL80211_FLAG_CLEAR_SKB,
Johannes Berg41ade002007-12-19 02:03:29 +010011206 },
11207 {
11208 .cmd = NL80211_CMD_DEL_KEY,
11209 .doit = nl80211_del_key,
11210 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011211 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020011212 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020011213 NL80211_FLAG_NEED_RTNL,
Johannes Berg41ade002007-12-19 02:03:29 +010011214 },
Johannes Berged1b6cc2007-12-19 02:03:32 +010011215 {
11216 .cmd = NL80211_CMD_SET_BEACON,
11217 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011218 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg88600202012-02-13 15:17:18 +010011219 .doit = nl80211_set_beacon,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020011220 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020011221 NL80211_FLAG_NEED_RTNL,
Johannes Berged1b6cc2007-12-19 02:03:32 +010011222 },
11223 {
Johannes Berg88600202012-02-13 15:17:18 +010011224 .cmd = NL80211_CMD_START_AP,
Johannes Berged1b6cc2007-12-19 02:03:32 +010011225 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011226 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg88600202012-02-13 15:17:18 +010011227 .doit = nl80211_start_ap,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020011228 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020011229 NL80211_FLAG_NEED_RTNL,
Johannes Berged1b6cc2007-12-19 02:03:32 +010011230 },
11231 {
Johannes Berg88600202012-02-13 15:17:18 +010011232 .cmd = NL80211_CMD_STOP_AP,
Johannes Berged1b6cc2007-12-19 02:03:32 +010011233 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011234 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg88600202012-02-13 15:17:18 +010011235 .doit = nl80211_stop_ap,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020011236 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020011237 NL80211_FLAG_NEED_RTNL,
Johannes Berged1b6cc2007-12-19 02:03:32 +010011238 },
Johannes Berg5727ef12007-12-19 02:03:34 +010011239 {
11240 .cmd = NL80211_CMD_GET_STATION,
11241 .doit = nl80211_get_station,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010011242 .dumpit = nl80211_dump_station,
Johannes Berg5727ef12007-12-19 02:03:34 +010011243 .policy = nl80211_policy,
Johannes Berg4c476992010-10-04 21:36:35 +020011244 .internal_flags = NL80211_FLAG_NEED_NETDEV |
11245 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +010011246 },
11247 {
11248 .cmd = NL80211_CMD_SET_STATION,
11249 .doit = nl80211_set_station,
11250 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011251 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020011252 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020011253 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +010011254 },
11255 {
11256 .cmd = NL80211_CMD_NEW_STATION,
11257 .doit = nl80211_new_station,
11258 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011259 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020011260 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020011261 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +010011262 },
11263 {
11264 .cmd = NL80211_CMD_DEL_STATION,
11265 .doit = nl80211_del_station,
11266 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011267 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020011268 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020011269 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +010011270 },
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010011271 {
11272 .cmd = NL80211_CMD_GET_MPATH,
11273 .doit = nl80211_get_mpath,
11274 .dumpit = nl80211_dump_mpath,
11275 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011276 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020011277 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020011278 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010011279 },
11280 {
Henning Rogge66be7d22014-09-12 08:58:49 +020011281 .cmd = NL80211_CMD_GET_MPP,
11282 .doit = nl80211_get_mpp,
11283 .dumpit = nl80211_dump_mpp,
11284 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011285 .flags = GENL_UNS_ADMIN_PERM,
Henning Rogge66be7d22014-09-12 08:58:49 +020011286 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
11287 NL80211_FLAG_NEED_RTNL,
11288 },
11289 {
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010011290 .cmd = NL80211_CMD_SET_MPATH,
11291 .doit = nl80211_set_mpath,
11292 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011293 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020011294 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020011295 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010011296 },
11297 {
11298 .cmd = NL80211_CMD_NEW_MPATH,
11299 .doit = nl80211_new_mpath,
11300 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011301 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020011302 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020011303 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010011304 },
11305 {
11306 .cmd = NL80211_CMD_DEL_MPATH,
11307 .doit = nl80211_del_mpath,
11308 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011309 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020011310 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020011311 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010011312 },
Jouni Malinen9f1ba902008-08-07 20:07:01 +030011313 {
11314 .cmd = NL80211_CMD_SET_BSS,
11315 .doit = nl80211_set_bss,
11316 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011317 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020011318 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020011319 NL80211_FLAG_NEED_RTNL,
Jouni Malinen9f1ba902008-08-07 20:07:01 +030011320 },
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -070011321 {
Luis R. Rodriguezf1303472009-01-30 09:26:42 -080011322 .cmd = NL80211_CMD_GET_REG,
Arik Nemtsovad30ca22014-12-15 19:25:59 +020011323 .doit = nl80211_get_reg_do,
11324 .dumpit = nl80211_get_reg_dump,
Luis R. Rodriguezf1303472009-01-30 09:26:42 -080011325 .policy = nl80211_policy,
Johannes Berg5fe231e2013-05-08 21:45:15 +020011326 .internal_flags = NL80211_FLAG_NEED_RTNL,
Luis R. Rodriguezf1303472009-01-30 09:26:42 -080011327 /* can be retrieved by unprivileged users */
11328 },
Johannes Bergb6863032015-10-15 09:25:18 +020011329#ifdef CONFIG_CFG80211_CRDA_SUPPORT
Luis R. Rodriguezf1303472009-01-30 09:26:42 -080011330 {
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -070011331 .cmd = NL80211_CMD_SET_REG,
11332 .doit = nl80211_set_reg,
11333 .policy = nl80211_policy,
11334 .flags = GENL_ADMIN_PERM,
Johannes Berg5fe231e2013-05-08 21:45:15 +020011335 .internal_flags = NL80211_FLAG_NEED_RTNL,
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -070011336 },
Johannes Bergb6863032015-10-15 09:25:18 +020011337#endif
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -070011338 {
11339 .cmd = NL80211_CMD_REQ_SET_REG,
11340 .doit = nl80211_req_set_reg,
11341 .policy = nl80211_policy,
11342 .flags = GENL_ADMIN_PERM,
11343 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -070011344 {
Javier Cardona24bdd9f2010-12-16 17:37:48 -080011345 .cmd = NL80211_CMD_GET_MESH_CONFIG,
11346 .doit = nl80211_get_mesh_config,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -070011347 .policy = nl80211_policy,
11348 /* can be retrieved by unprivileged users */
Johannes Berg2b5f8b02012-04-02 10:51:55 +020011349 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020011350 NL80211_FLAG_NEED_RTNL,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -070011351 },
11352 {
Javier Cardona24bdd9f2010-12-16 17:37:48 -080011353 .cmd = NL80211_CMD_SET_MESH_CONFIG,
11354 .doit = nl80211_update_mesh_config,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -070011355 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011356 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg29cbe682010-12-03 09:20:44 +010011357 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020011358 NL80211_FLAG_NEED_RTNL,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -070011359 },
Jouni Malinen9aed3cc2009-01-13 16:03:29 +020011360 {
Johannes Berg2a519312009-02-10 21:25:55 +010011361 .cmd = NL80211_CMD_TRIGGER_SCAN,
11362 .doit = nl80211_trigger_scan,
11363 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011364 .flags = GENL_UNS_ADMIN_PERM,
Johannes Bergfd014282012-06-18 19:17:03 +020011365 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020011366 NL80211_FLAG_NEED_RTNL,
Johannes Berg2a519312009-02-10 21:25:55 +010011367 },
11368 {
Vidyullatha Kanchanapally91d3ab42015-10-30 19:14:49 +053011369 .cmd = NL80211_CMD_ABORT_SCAN,
11370 .doit = nl80211_abort_scan,
11371 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011372 .flags = GENL_UNS_ADMIN_PERM,
Vidyullatha Kanchanapally91d3ab42015-10-30 19:14:49 +053011373 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
11374 NL80211_FLAG_NEED_RTNL,
11375 },
11376 {
Johannes Berg2a519312009-02-10 21:25:55 +010011377 .cmd = NL80211_CMD_GET_SCAN,
11378 .policy = nl80211_policy,
11379 .dumpit = nl80211_dump_scan,
11380 },
Jouni Malinen636a5d32009-03-19 13:39:22 +020011381 {
Luciano Coelho807f8a82011-05-11 17:09:35 +030011382 .cmd = NL80211_CMD_START_SCHED_SCAN,
11383 .doit = nl80211_start_sched_scan,
11384 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011385 .flags = GENL_UNS_ADMIN_PERM,
Luciano Coelho807f8a82011-05-11 17:09:35 +030011386 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
11387 NL80211_FLAG_NEED_RTNL,
11388 },
11389 {
11390 .cmd = NL80211_CMD_STOP_SCHED_SCAN,
11391 .doit = nl80211_stop_sched_scan,
11392 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011393 .flags = GENL_UNS_ADMIN_PERM,
Luciano Coelho807f8a82011-05-11 17:09:35 +030011394 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
11395 NL80211_FLAG_NEED_RTNL,
11396 },
11397 {
Jouni Malinen636a5d32009-03-19 13:39:22 +020011398 .cmd = NL80211_CMD_AUTHENTICATE,
11399 .doit = nl80211_authenticate,
11400 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011401 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020011402 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg5393b912014-09-10 15:00:16 +030011403 NL80211_FLAG_NEED_RTNL |
11404 NL80211_FLAG_CLEAR_SKB,
Jouni Malinen636a5d32009-03-19 13:39:22 +020011405 },
11406 {
11407 .cmd = NL80211_CMD_ASSOCIATE,
11408 .doit = nl80211_associate,
11409 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011410 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020011411 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020011412 NL80211_FLAG_NEED_RTNL,
Jouni Malinen636a5d32009-03-19 13:39:22 +020011413 },
11414 {
11415 .cmd = NL80211_CMD_DEAUTHENTICATE,
11416 .doit = nl80211_deauthenticate,
11417 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011418 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020011419 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020011420 NL80211_FLAG_NEED_RTNL,
Jouni Malinen636a5d32009-03-19 13:39:22 +020011421 },
11422 {
11423 .cmd = NL80211_CMD_DISASSOCIATE,
11424 .doit = nl80211_disassociate,
11425 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011426 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020011427 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020011428 NL80211_FLAG_NEED_RTNL,
Jouni Malinen636a5d32009-03-19 13:39:22 +020011429 },
Johannes Berg04a773a2009-04-19 21:24:32 +020011430 {
11431 .cmd = NL80211_CMD_JOIN_IBSS,
11432 .doit = nl80211_join_ibss,
11433 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011434 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020011435 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020011436 NL80211_FLAG_NEED_RTNL,
Johannes Berg04a773a2009-04-19 21:24:32 +020011437 },
11438 {
11439 .cmd = NL80211_CMD_LEAVE_IBSS,
11440 .doit = nl80211_leave_ibss,
11441 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011442 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020011443 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020011444 NL80211_FLAG_NEED_RTNL,
Johannes Berg04a773a2009-04-19 21:24:32 +020011445 },
Johannes Bergaff89a92009-07-01 21:26:51 +020011446#ifdef CONFIG_NL80211_TESTMODE
11447 {
11448 .cmd = NL80211_CMD_TESTMODE,
11449 .doit = nl80211_testmode_do,
Wey-Yi Guy71063f02011-05-20 09:05:54 -070011450 .dumpit = nl80211_testmode_dump,
Johannes Bergaff89a92009-07-01 21:26:51 +020011451 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011452 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020011453 .internal_flags = NL80211_FLAG_NEED_WIPHY |
11454 NL80211_FLAG_NEED_RTNL,
Johannes Bergaff89a92009-07-01 21:26:51 +020011455 },
11456#endif
Samuel Ortizb23aa672009-07-01 21:26:54 +020011457 {
11458 .cmd = NL80211_CMD_CONNECT,
11459 .doit = nl80211_connect,
11460 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011461 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020011462 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020011463 NL80211_FLAG_NEED_RTNL,
Samuel Ortizb23aa672009-07-01 21:26:54 +020011464 },
11465 {
11466 .cmd = NL80211_CMD_DISCONNECT,
11467 .doit = nl80211_disconnect,
11468 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011469 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020011470 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020011471 NL80211_FLAG_NEED_RTNL,
Samuel Ortizb23aa672009-07-01 21:26:54 +020011472 },
Johannes Berg463d0182009-07-14 00:33:35 +020011473 {
11474 .cmd = NL80211_CMD_SET_WIPHY_NETNS,
11475 .doit = nl80211_wiphy_netns,
11476 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011477 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020011478 .internal_flags = NL80211_FLAG_NEED_WIPHY |
11479 NL80211_FLAG_NEED_RTNL,
Johannes Berg463d0182009-07-14 00:33:35 +020011480 },
Holger Schurig61fa7132009-11-11 12:25:40 +010011481 {
11482 .cmd = NL80211_CMD_GET_SURVEY,
11483 .policy = nl80211_policy,
11484 .dumpit = nl80211_dump_survey,
11485 },
Samuel Ortiz67fbb162009-11-24 23:59:15 +010011486 {
11487 .cmd = NL80211_CMD_SET_PMKSA,
11488 .doit = nl80211_setdel_pmksa,
11489 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011490 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020011491 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020011492 NL80211_FLAG_NEED_RTNL,
Samuel Ortiz67fbb162009-11-24 23:59:15 +010011493 },
11494 {
11495 .cmd = NL80211_CMD_DEL_PMKSA,
11496 .doit = nl80211_setdel_pmksa,
11497 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011498 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020011499 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020011500 NL80211_FLAG_NEED_RTNL,
Samuel Ortiz67fbb162009-11-24 23:59:15 +010011501 },
11502 {
11503 .cmd = NL80211_CMD_FLUSH_PMKSA,
11504 .doit = nl80211_flush_pmksa,
11505 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011506 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020011507 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020011508 NL80211_FLAG_NEED_RTNL,
Samuel Ortiz67fbb162009-11-24 23:59:15 +010011509 },
Jouni Malinen9588bbd2009-12-23 13:15:41 +010011510 {
11511 .cmd = NL80211_CMD_REMAIN_ON_CHANNEL,
11512 .doit = nl80211_remain_on_channel,
11513 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011514 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +020011515 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020011516 NL80211_FLAG_NEED_RTNL,
Jouni Malinen9588bbd2009-12-23 13:15:41 +010011517 },
11518 {
11519 .cmd = NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL,
11520 .doit = nl80211_cancel_remain_on_channel,
11521 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011522 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +020011523 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020011524 NL80211_FLAG_NEED_RTNL,
Jouni Malinen9588bbd2009-12-23 13:15:41 +010011525 },
Jouni Malinen13ae75b2009-12-29 12:59:45 +020011526 {
11527 .cmd = NL80211_CMD_SET_TX_BITRATE_MASK,
11528 .doit = nl80211_set_tx_bitrate_mask,
11529 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011530 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020011531 .internal_flags = NL80211_FLAG_NEED_NETDEV |
11532 NL80211_FLAG_NEED_RTNL,
Jouni Malinen13ae75b2009-12-29 12:59:45 +020011533 },
Jouni Malinen026331c2010-02-15 12:53:10 +020011534 {
Johannes Berg2e161f72010-08-12 15:38:38 +020011535 .cmd = NL80211_CMD_REGISTER_FRAME,
11536 .doit = nl80211_register_mgmt,
Jouni Malinen026331c2010-02-15 12:53:10 +020011537 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011538 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +020011539 .internal_flags = NL80211_FLAG_NEED_WDEV |
Johannes Berg4c476992010-10-04 21:36:35 +020011540 NL80211_FLAG_NEED_RTNL,
Jouni Malinen026331c2010-02-15 12:53:10 +020011541 },
11542 {
Johannes Berg2e161f72010-08-12 15:38:38 +020011543 .cmd = NL80211_CMD_FRAME,
11544 .doit = nl80211_tx_mgmt,
Jouni Malinen026331c2010-02-15 12:53:10 +020011545 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011546 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +020011547 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020011548 NL80211_FLAG_NEED_RTNL,
Jouni Malinen026331c2010-02-15 12:53:10 +020011549 },
Kalle Valoffb9eb32010-02-17 17:58:10 +020011550 {
Johannes Bergf7ca38d2010-11-25 10:02:29 +010011551 .cmd = NL80211_CMD_FRAME_WAIT_CANCEL,
11552 .doit = nl80211_tx_mgmt_cancel_wait,
11553 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011554 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +020011555 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Bergf7ca38d2010-11-25 10:02:29 +010011556 NL80211_FLAG_NEED_RTNL,
11557 },
11558 {
Kalle Valoffb9eb32010-02-17 17:58:10 +020011559 .cmd = NL80211_CMD_SET_POWER_SAVE,
11560 .doit = nl80211_set_power_save,
11561 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011562 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020011563 .internal_flags = NL80211_FLAG_NEED_NETDEV |
11564 NL80211_FLAG_NEED_RTNL,
Kalle Valoffb9eb32010-02-17 17:58:10 +020011565 },
11566 {
11567 .cmd = NL80211_CMD_GET_POWER_SAVE,
11568 .doit = nl80211_get_power_save,
11569 .policy = nl80211_policy,
11570 /* can be retrieved by unprivileged users */
Johannes Berg4c476992010-10-04 21:36:35 +020011571 .internal_flags = NL80211_FLAG_NEED_NETDEV |
11572 NL80211_FLAG_NEED_RTNL,
Kalle Valoffb9eb32010-02-17 17:58:10 +020011573 },
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020011574 {
11575 .cmd = NL80211_CMD_SET_CQM,
11576 .doit = nl80211_set_cqm,
11577 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011578 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020011579 .internal_flags = NL80211_FLAG_NEED_NETDEV |
11580 NL80211_FLAG_NEED_RTNL,
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020011581 },
Johannes Bergf444de02010-05-05 15:25:02 +020011582 {
11583 .cmd = NL80211_CMD_SET_CHANNEL,
11584 .doit = nl80211_set_channel,
11585 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011586 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020011587 .internal_flags = NL80211_FLAG_NEED_NETDEV |
11588 NL80211_FLAG_NEED_RTNL,
Johannes Bergf444de02010-05-05 15:25:02 +020011589 },
Bill Jordane8347eb2010-10-01 13:54:28 -040011590 {
11591 .cmd = NL80211_CMD_SET_WDS_PEER,
11592 .doit = nl80211_set_wds_peer,
11593 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011594 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg43b19952010-10-07 13:10:30 +020011595 .internal_flags = NL80211_FLAG_NEED_NETDEV |
11596 NL80211_FLAG_NEED_RTNL,
Bill Jordane8347eb2010-10-01 13:54:28 -040011597 },
Johannes Berg29cbe682010-12-03 09:20:44 +010011598 {
11599 .cmd = NL80211_CMD_JOIN_MESH,
11600 .doit = nl80211_join_mesh,
11601 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011602 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg29cbe682010-12-03 09:20:44 +010011603 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
11604 NL80211_FLAG_NEED_RTNL,
11605 },
11606 {
11607 .cmd = NL80211_CMD_LEAVE_MESH,
11608 .doit = nl80211_leave_mesh,
11609 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011610 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg29cbe682010-12-03 09:20:44 +010011611 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
11612 NL80211_FLAG_NEED_RTNL,
11613 },
Rostislav Lisovy6e0bd6c2014-11-03 10:33:18 +010011614 {
11615 .cmd = NL80211_CMD_JOIN_OCB,
11616 .doit = nl80211_join_ocb,
11617 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011618 .flags = GENL_UNS_ADMIN_PERM,
Rostislav Lisovy6e0bd6c2014-11-03 10:33:18 +010011619 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
11620 NL80211_FLAG_NEED_RTNL,
11621 },
11622 {
11623 .cmd = NL80211_CMD_LEAVE_OCB,
11624 .doit = nl80211_leave_ocb,
11625 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011626 .flags = GENL_UNS_ADMIN_PERM,
Rostislav Lisovy6e0bd6c2014-11-03 10:33:18 +010011627 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
11628 NL80211_FLAG_NEED_RTNL,
11629 },
Johannes Bergdfb89c52012-06-27 09:23:48 +020011630#ifdef CONFIG_PM
Johannes Bergff1b6e62011-05-04 15:37:28 +020011631 {
11632 .cmd = NL80211_CMD_GET_WOWLAN,
11633 .doit = nl80211_get_wowlan,
11634 .policy = nl80211_policy,
11635 /* can be retrieved by unprivileged users */
11636 .internal_flags = NL80211_FLAG_NEED_WIPHY |
11637 NL80211_FLAG_NEED_RTNL,
11638 },
11639 {
11640 .cmd = NL80211_CMD_SET_WOWLAN,
11641 .doit = nl80211_set_wowlan,
11642 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011643 .flags = GENL_UNS_ADMIN_PERM,
Johannes Bergff1b6e62011-05-04 15:37:28 +020011644 .internal_flags = NL80211_FLAG_NEED_WIPHY |
11645 NL80211_FLAG_NEED_RTNL,
11646 },
Johannes Bergdfb89c52012-06-27 09:23:48 +020011647#endif
Johannes Berge5497d72011-07-05 16:35:40 +020011648 {
11649 .cmd = NL80211_CMD_SET_REKEY_OFFLOAD,
11650 .doit = nl80211_set_rekey_data,
11651 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011652 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berge5497d72011-07-05 16:35:40 +020011653 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg5393b912014-09-10 15:00:16 +030011654 NL80211_FLAG_NEED_RTNL |
11655 NL80211_FLAG_CLEAR_SKB,
Johannes Berge5497d72011-07-05 16:35:40 +020011656 },
Arik Nemtsov109086c2011-09-28 14:12:50 +030011657 {
11658 .cmd = NL80211_CMD_TDLS_MGMT,
11659 .doit = nl80211_tdls_mgmt,
11660 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011661 .flags = GENL_UNS_ADMIN_PERM,
Arik Nemtsov109086c2011-09-28 14:12:50 +030011662 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
11663 NL80211_FLAG_NEED_RTNL,
11664 },
11665 {
11666 .cmd = NL80211_CMD_TDLS_OPER,
11667 .doit = nl80211_tdls_oper,
11668 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011669 .flags = GENL_UNS_ADMIN_PERM,
Arik Nemtsov109086c2011-09-28 14:12:50 +030011670 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
11671 NL80211_FLAG_NEED_RTNL,
11672 },
Johannes Berg28946da2011-11-04 11:18:12 +010011673 {
11674 .cmd = NL80211_CMD_UNEXPECTED_FRAME,
11675 .doit = nl80211_register_unexpected_frame,
11676 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011677 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg28946da2011-11-04 11:18:12 +010011678 .internal_flags = NL80211_FLAG_NEED_NETDEV |
11679 NL80211_FLAG_NEED_RTNL,
11680 },
Johannes Berg7f6cf312011-11-04 11:18:15 +010011681 {
11682 .cmd = NL80211_CMD_PROBE_CLIENT,
11683 .doit = nl80211_probe_client,
11684 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011685 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020011686 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg7f6cf312011-11-04 11:18:15 +010011687 NL80211_FLAG_NEED_RTNL,
11688 },
Johannes Berg5e7602302011-11-04 11:18:17 +010011689 {
11690 .cmd = NL80211_CMD_REGISTER_BEACONS,
11691 .doit = nl80211_register_beacons,
11692 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011693 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg5e7602302011-11-04 11:18:17 +010011694 .internal_flags = NL80211_FLAG_NEED_WIPHY |
11695 NL80211_FLAG_NEED_RTNL,
11696 },
Simon Wunderlich1d9d9212011-11-18 14:20:43 +010011697 {
11698 .cmd = NL80211_CMD_SET_NOACK_MAP,
11699 .doit = nl80211_set_noack_map,
11700 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011701 .flags = GENL_UNS_ADMIN_PERM,
Simon Wunderlich1d9d9212011-11-18 14:20:43 +010011702 .internal_flags = NL80211_FLAG_NEED_NETDEV |
11703 NL80211_FLAG_NEED_RTNL,
11704 },
Johannes Berg98104fde2012-06-16 00:19:54 +020011705 {
11706 .cmd = NL80211_CMD_START_P2P_DEVICE,
11707 .doit = nl80211_start_p2p_device,
11708 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011709 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg98104fde2012-06-16 00:19:54 +020011710 .internal_flags = NL80211_FLAG_NEED_WDEV |
11711 NL80211_FLAG_NEED_RTNL,
11712 },
11713 {
11714 .cmd = NL80211_CMD_STOP_P2P_DEVICE,
11715 .doit = nl80211_stop_p2p_device,
11716 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011717 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg98104fde2012-06-16 00:19:54 +020011718 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
11719 NL80211_FLAG_NEED_RTNL,
11720 },
Antonio Quartullif4e583c2012-11-02 13:27:48 +010011721 {
11722 .cmd = NL80211_CMD_SET_MCAST_RATE,
11723 .doit = nl80211_set_mcast_rate,
11724 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011725 .flags = GENL_UNS_ADMIN_PERM,
Antonio Quartullif4e583c2012-11-02 13:27:48 +010011726 .internal_flags = NL80211_FLAG_NEED_NETDEV |
11727 NL80211_FLAG_NEED_RTNL,
11728 },
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +053011729 {
11730 .cmd = NL80211_CMD_SET_MAC_ACL,
11731 .doit = nl80211_set_mac_acl,
11732 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011733 .flags = GENL_UNS_ADMIN_PERM,
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +053011734 .internal_flags = NL80211_FLAG_NEED_NETDEV |
11735 NL80211_FLAG_NEED_RTNL,
11736 },
Simon Wunderlich04f39042013-02-08 18:16:19 +010011737 {
11738 .cmd = NL80211_CMD_RADAR_DETECT,
11739 .doit = nl80211_start_radar_detection,
11740 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011741 .flags = GENL_UNS_ADMIN_PERM,
Simon Wunderlich04f39042013-02-08 18:16:19 +010011742 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
11743 NL80211_FLAG_NEED_RTNL,
11744 },
Johannes Berg3713b4e2013-02-14 16:19:38 +010011745 {
11746 .cmd = NL80211_CMD_GET_PROTOCOL_FEATURES,
11747 .doit = nl80211_get_protocol_features,
11748 .policy = nl80211_policy,
11749 },
Jouni Malinen355199e2013-02-27 17:14:27 +020011750 {
11751 .cmd = NL80211_CMD_UPDATE_FT_IES,
11752 .doit = nl80211_update_ft_ies,
11753 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011754 .flags = GENL_UNS_ADMIN_PERM,
Jouni Malinen355199e2013-02-27 17:14:27 +020011755 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
11756 NL80211_FLAG_NEED_RTNL,
11757 },
Arend van Spriel5de17982013-04-18 15:49:00 +020011758 {
11759 .cmd = NL80211_CMD_CRIT_PROTOCOL_START,
11760 .doit = nl80211_crit_protocol_start,
11761 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011762 .flags = GENL_UNS_ADMIN_PERM,
Arend van Spriel5de17982013-04-18 15:49:00 +020011763 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
11764 NL80211_FLAG_NEED_RTNL,
11765 },
11766 {
11767 .cmd = NL80211_CMD_CRIT_PROTOCOL_STOP,
11768 .doit = nl80211_crit_protocol_stop,
11769 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011770 .flags = GENL_UNS_ADMIN_PERM,
Arend van Spriel5de17982013-04-18 15:49:00 +020011771 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
11772 NL80211_FLAG_NEED_RTNL,
Amitkumar Karwarbe29b992013-06-28 11:51:26 -070011773 },
11774 {
11775 .cmd = NL80211_CMD_GET_COALESCE,
11776 .doit = nl80211_get_coalesce,
11777 .policy = nl80211_policy,
11778 .internal_flags = NL80211_FLAG_NEED_WIPHY |
11779 NL80211_FLAG_NEED_RTNL,
11780 },
11781 {
11782 .cmd = NL80211_CMD_SET_COALESCE,
11783 .doit = nl80211_set_coalesce,
11784 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011785 .flags = GENL_UNS_ADMIN_PERM,
Amitkumar Karwarbe29b992013-06-28 11:51:26 -070011786 .internal_flags = NL80211_FLAG_NEED_WIPHY |
11787 NL80211_FLAG_NEED_RTNL,
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +020011788 },
11789 {
11790 .cmd = NL80211_CMD_CHANNEL_SWITCH,
11791 .doit = nl80211_channel_switch,
11792 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011793 .flags = GENL_UNS_ADMIN_PERM,
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +020011794 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
11795 NL80211_FLAG_NEED_RTNL,
11796 },
Johannes Bergad7e7182013-11-13 13:37:47 +010011797 {
11798 .cmd = NL80211_CMD_VENDOR,
11799 .doit = nl80211_vendor_cmd,
Johannes Berg7bdbe402015-08-15 22:39:49 +030011800 .dumpit = nl80211_vendor_cmd_dump,
Johannes Bergad7e7182013-11-13 13:37:47 +010011801 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011802 .flags = GENL_UNS_ADMIN_PERM,
Johannes Bergad7e7182013-11-13 13:37:47 +010011803 .internal_flags = NL80211_FLAG_NEED_WIPHY |
11804 NL80211_FLAG_NEED_RTNL,
11805 },
Kyeyoon Parkfa9ffc72013-12-16 23:01:30 -080011806 {
11807 .cmd = NL80211_CMD_SET_QOS_MAP,
11808 .doit = nl80211_set_qos_map,
11809 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011810 .flags = GENL_UNS_ADMIN_PERM,
Kyeyoon Parkfa9ffc72013-12-16 23:01:30 -080011811 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
11812 NL80211_FLAG_NEED_RTNL,
11813 },
Johannes Berg960d01a2014-09-09 22:55:35 +030011814 {
11815 .cmd = NL80211_CMD_ADD_TX_TS,
11816 .doit = nl80211_add_tx_ts,
11817 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011818 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg960d01a2014-09-09 22:55:35 +030011819 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
11820 NL80211_FLAG_NEED_RTNL,
11821 },
11822 {
11823 .cmd = NL80211_CMD_DEL_TX_TS,
11824 .doit = nl80211_del_tx_ts,
11825 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011826 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg960d01a2014-09-09 22:55:35 +030011827 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
11828 NL80211_FLAG_NEED_RTNL,
11829 },
Arik Nemtsov1057d352014-11-19 12:54:26 +020011830 {
11831 .cmd = NL80211_CMD_TDLS_CHANNEL_SWITCH,
11832 .doit = nl80211_tdls_channel_switch,
11833 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011834 .flags = GENL_UNS_ADMIN_PERM,
Arik Nemtsov1057d352014-11-19 12:54:26 +020011835 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
11836 NL80211_FLAG_NEED_RTNL,
11837 },
11838 {
11839 .cmd = NL80211_CMD_TDLS_CANCEL_CHANNEL_SWITCH,
11840 .doit = nl80211_tdls_cancel_channel_switch,
11841 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011842 .flags = GENL_UNS_ADMIN_PERM,
Arik Nemtsov1057d352014-11-19 12:54:26 +020011843 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
11844 NL80211_FLAG_NEED_RTNL,
11845 },
Johannes Berg55682962007-09-20 13:09:35 -040011846};
Jouni Malinen9588bbd2009-12-23 13:15:41 +010011847
Johannes Berg55682962007-09-20 13:09:35 -040011848/* notification functions */
11849
Johannes Berg3bb20552014-05-26 13:52:25 +020011850void nl80211_notify_wiphy(struct cfg80211_registered_device *rdev,
11851 enum nl80211_commands cmd)
Johannes Berg55682962007-09-20 13:09:35 -040011852{
11853 struct sk_buff *msg;
Johannes Berg86e8cf92013-06-19 10:57:22 +020011854 struct nl80211_dump_wiphy_state state = {};
Johannes Berg55682962007-09-20 13:09:35 -040011855
Johannes Berg3bb20552014-05-26 13:52:25 +020011856 WARN_ON(cmd != NL80211_CMD_NEW_WIPHY &&
11857 cmd != NL80211_CMD_DEL_WIPHY);
11858
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -070011859 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -040011860 if (!msg)
11861 return;
11862
Johannes Berg3bb20552014-05-26 13:52:25 +020011863 if (nl80211_send_wiphy(rdev, cmd, msg, 0, 0, 0, &state) < 0) {
Johannes Berg55682962007-09-20 13:09:35 -040011864 nlmsg_free(msg);
11865 return;
11866 }
11867
Johannes Berg68eb5502013-11-19 15:19:38 +010011868 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011869 NL80211_MCGRP_CONFIG, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -040011870}
11871
Denis Kenzior896ff062016-08-03 16:58:33 -050011872void nl80211_notify_iface(struct cfg80211_registered_device *rdev,
11873 struct wireless_dev *wdev,
11874 enum nl80211_commands cmd)
11875{
11876 struct sk_buff *msg;
11877
11878 WARN_ON(cmd != NL80211_CMD_NEW_INTERFACE &&
11879 cmd != NL80211_CMD_DEL_INTERFACE);
11880
11881 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
11882 if (!msg)
11883 return;
11884
11885 if (nl80211_send_iface(msg, 0, 0, 0, rdev, wdev,
11886 cmd == NL80211_CMD_DEL_INTERFACE) < 0) {
11887 nlmsg_free(msg);
11888 return;
11889 }
11890
11891 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
11892 NL80211_MCGRP_CONFIG, GFP_KERNEL);
11893}
11894
Johannes Berg362a4152009-05-24 16:43:15 +020011895static int nl80211_add_scan_req(struct sk_buff *msg,
11896 struct cfg80211_registered_device *rdev)
11897{
11898 struct cfg80211_scan_request *req = rdev->scan_req;
11899 struct nlattr *nest;
11900 int i;
11901
11902 if (WARN_ON(!req))
11903 return 0;
11904
11905 nest = nla_nest_start(msg, NL80211_ATTR_SCAN_SSIDS);
11906 if (!nest)
11907 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -040011908 for (i = 0; i < req->n_ssids; i++) {
11909 if (nla_put(msg, i, req->ssids[i].ssid_len, req->ssids[i].ssid))
11910 goto nla_put_failure;
11911 }
Johannes Berg362a4152009-05-24 16:43:15 +020011912 nla_nest_end(msg, nest);
11913
11914 nest = nla_nest_start(msg, NL80211_ATTR_SCAN_FREQUENCIES);
11915 if (!nest)
11916 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -040011917 for (i = 0; i < req->n_channels; i++) {
11918 if (nla_put_u32(msg, i, req->channels[i]->center_freq))
11919 goto nla_put_failure;
11920 }
Johannes Berg362a4152009-05-24 16:43:15 +020011921 nla_nest_end(msg, nest);
11922
David S. Miller9360ffd2012-03-29 04:41:26 -040011923 if (req->ie &&
11924 nla_put(msg, NL80211_ATTR_IE, req->ie_len, req->ie))
11925 goto nla_put_failure;
Johannes Berg362a4152009-05-24 16:43:15 +020011926
Johannes Bergae917c92013-10-25 11:05:22 +020011927 if (req->flags &&
11928 nla_put_u32(msg, NL80211_ATTR_SCAN_FLAGS, req->flags))
11929 goto nla_put_failure;
Sam Lefflered4737712012-10-11 21:03:31 -070011930
Avraham Stern1d762502016-07-05 17:10:13 +030011931 if (req->info.scan_start_tsf &&
11932 (nla_put_u64_64bit(msg, NL80211_ATTR_SCAN_START_TIME_TSF,
11933 req->info.scan_start_tsf, NL80211_BSS_PAD) ||
11934 nla_put(msg, NL80211_ATTR_SCAN_START_TIME_TSF_BSSID, ETH_ALEN,
11935 req->info.tsf_bssid)))
11936 goto nla_put_failure;
11937
Johannes Berg362a4152009-05-24 16:43:15 +020011938 return 0;
11939 nla_put_failure:
11940 return -ENOBUFS;
11941}
11942
Johannes Berga538e2d2009-06-16 19:56:42 +020011943static int nl80211_send_scan_msg(struct sk_buff *msg,
11944 struct cfg80211_registered_device *rdev,
Johannes Bergfd014282012-06-18 19:17:03 +020011945 struct wireless_dev *wdev,
Eric W. Biederman15e47302012-09-07 20:12:54 +000011946 u32 portid, u32 seq, int flags,
Johannes Berga538e2d2009-06-16 19:56:42 +020011947 u32 cmd)
Johannes Berg2a519312009-02-10 21:25:55 +010011948{
11949 void *hdr;
11950
Eric W. Biederman15e47302012-09-07 20:12:54 +000011951 hdr = nl80211hdr_put(msg, portid, seq, flags, cmd);
Johannes Berg2a519312009-02-10 21:25:55 +010011952 if (!hdr)
11953 return -1;
11954
David S. Miller9360ffd2012-03-29 04:41:26 -040011955 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Bergfd014282012-06-18 19:17:03 +020011956 (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
11957 wdev->netdev->ifindex)) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020011958 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
11959 NL80211_ATTR_PAD))
David S. Miller9360ffd2012-03-29 04:41:26 -040011960 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +010011961
Johannes Berg362a4152009-05-24 16:43:15 +020011962 /* ignore errors and send incomplete event anyway */
11963 nl80211_add_scan_req(msg, rdev);
Johannes Berg2a519312009-02-10 21:25:55 +010011964
Johannes Berg053c0952015-01-16 22:09:00 +010011965 genlmsg_end(msg, hdr);
11966 return 0;
Johannes Berg2a519312009-02-10 21:25:55 +010011967
11968 nla_put_failure:
11969 genlmsg_cancel(msg, hdr);
11970 return -EMSGSIZE;
11971}
11972
Luciano Coelho807f8a82011-05-11 17:09:35 +030011973static int
11974nl80211_send_sched_scan_msg(struct sk_buff *msg,
11975 struct cfg80211_registered_device *rdev,
11976 struct net_device *netdev,
Eric W. Biederman15e47302012-09-07 20:12:54 +000011977 u32 portid, u32 seq, int flags, u32 cmd)
Luciano Coelho807f8a82011-05-11 17:09:35 +030011978{
11979 void *hdr;
11980
Eric W. Biederman15e47302012-09-07 20:12:54 +000011981 hdr = nl80211hdr_put(msg, portid, seq, flags, cmd);
Luciano Coelho807f8a82011-05-11 17:09:35 +030011982 if (!hdr)
11983 return -1;
11984
David S. Miller9360ffd2012-03-29 04:41:26 -040011985 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
11986 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex))
11987 goto nla_put_failure;
Luciano Coelho807f8a82011-05-11 17:09:35 +030011988
Johannes Berg053c0952015-01-16 22:09:00 +010011989 genlmsg_end(msg, hdr);
11990 return 0;
Luciano Coelho807f8a82011-05-11 17:09:35 +030011991
11992 nla_put_failure:
11993 genlmsg_cancel(msg, hdr);
11994 return -EMSGSIZE;
11995}
11996
Johannes Berga538e2d2009-06-16 19:56:42 +020011997void nl80211_send_scan_start(struct cfg80211_registered_device *rdev,
Johannes Bergfd014282012-06-18 19:17:03 +020011998 struct wireless_dev *wdev)
Johannes Berga538e2d2009-06-16 19:56:42 +020011999{
12000 struct sk_buff *msg;
12001
Thomas Graf58050fc2012-06-28 03:57:45 +000012002 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berga538e2d2009-06-16 19:56:42 +020012003 if (!msg)
12004 return;
12005
Johannes Bergfd014282012-06-18 19:17:03 +020012006 if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0,
Johannes Berga538e2d2009-06-16 19:56:42 +020012007 NL80211_CMD_TRIGGER_SCAN) < 0) {
12008 nlmsg_free(msg);
12009 return;
12010 }
12011
Johannes Berg68eb5502013-11-19 15:19:38 +010012012 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010012013 NL80211_MCGRP_SCAN, GFP_KERNEL);
Johannes Berga538e2d2009-06-16 19:56:42 +020012014}
12015
Johannes Bergf9d15d12014-01-22 11:14:19 +020012016struct sk_buff *nl80211_build_scan_msg(struct cfg80211_registered_device *rdev,
12017 struct wireless_dev *wdev, bool aborted)
Johannes Berg2a519312009-02-10 21:25:55 +010012018{
12019 struct sk_buff *msg;
12020
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -070012021 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg2a519312009-02-10 21:25:55 +010012022 if (!msg)
Johannes Bergf9d15d12014-01-22 11:14:19 +020012023 return NULL;
Johannes Berg2a519312009-02-10 21:25:55 +010012024
Johannes Bergfd014282012-06-18 19:17:03 +020012025 if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0,
Johannes Bergf9d15d12014-01-22 11:14:19 +020012026 aborted ? NL80211_CMD_SCAN_ABORTED :
12027 NL80211_CMD_NEW_SCAN_RESULTS) < 0) {
Johannes Berg2a519312009-02-10 21:25:55 +010012028 nlmsg_free(msg);
Johannes Bergf9d15d12014-01-22 11:14:19 +020012029 return NULL;
Johannes Berg2a519312009-02-10 21:25:55 +010012030 }
12031
Johannes Bergf9d15d12014-01-22 11:14:19 +020012032 return msg;
Johannes Berg2a519312009-02-10 21:25:55 +010012033}
12034
Johannes Bergf9d15d12014-01-22 11:14:19 +020012035void nl80211_send_scan_result(struct cfg80211_registered_device *rdev,
12036 struct sk_buff *msg)
Johannes Berg2a519312009-02-10 21:25:55 +010012037{
Johannes Berg2a519312009-02-10 21:25:55 +010012038 if (!msg)
12039 return;
12040
Johannes Berg68eb5502013-11-19 15:19:38 +010012041 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010012042 NL80211_MCGRP_SCAN, GFP_KERNEL);
Johannes Berg2a519312009-02-10 21:25:55 +010012043}
12044
Luciano Coelho807f8a82011-05-11 17:09:35 +030012045void nl80211_send_sched_scan_results(struct cfg80211_registered_device *rdev,
12046 struct net_device *netdev)
12047{
12048 struct sk_buff *msg;
12049
12050 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
12051 if (!msg)
12052 return;
12053
12054 if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0,
12055 NL80211_CMD_SCHED_SCAN_RESULTS) < 0) {
12056 nlmsg_free(msg);
12057 return;
12058 }
12059
Johannes Berg68eb5502013-11-19 15:19:38 +010012060 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010012061 NL80211_MCGRP_SCAN, GFP_KERNEL);
Luciano Coelho807f8a82011-05-11 17:09:35 +030012062}
12063
12064void nl80211_send_sched_scan(struct cfg80211_registered_device *rdev,
12065 struct net_device *netdev, u32 cmd)
12066{
12067 struct sk_buff *msg;
12068
Thomas Graf58050fc2012-06-28 03:57:45 +000012069 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Luciano Coelho807f8a82011-05-11 17:09:35 +030012070 if (!msg)
12071 return;
12072
12073 if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0, cmd) < 0) {
12074 nlmsg_free(msg);
12075 return;
12076 }
12077
Johannes Berg68eb5502013-11-19 15:19:38 +010012078 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010012079 NL80211_MCGRP_SCAN, GFP_KERNEL);
Luciano Coelho807f8a82011-05-11 17:09:35 +030012080}
12081
Jonathan Doronb0d7aa52014-12-15 19:26:00 +020012082static bool nl80211_reg_change_event_fill(struct sk_buff *msg,
12083 struct regulatory_request *request)
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040012084{
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040012085 /* Userspace can always count this one always being set */
David S. Miller9360ffd2012-03-29 04:41:26 -040012086 if (nla_put_u8(msg, NL80211_ATTR_REG_INITIATOR, request->initiator))
12087 goto nla_put_failure;
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040012088
David S. Miller9360ffd2012-03-29 04:41:26 -040012089 if (request->alpha2[0] == '0' && request->alpha2[1] == '0') {
12090 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
12091 NL80211_REGDOM_TYPE_WORLD))
12092 goto nla_put_failure;
12093 } else if (request->alpha2[0] == '9' && request->alpha2[1] == '9') {
12094 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
12095 NL80211_REGDOM_TYPE_CUSTOM_WORLD))
12096 goto nla_put_failure;
12097 } else if ((request->alpha2[0] == '9' && request->alpha2[1] == '8') ||
12098 request->intersect) {
12099 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
12100 NL80211_REGDOM_TYPE_INTERSECTION))
12101 goto nla_put_failure;
12102 } else {
12103 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
12104 NL80211_REGDOM_TYPE_COUNTRY) ||
12105 nla_put_string(msg, NL80211_ATTR_REG_ALPHA2,
12106 request->alpha2))
12107 goto nla_put_failure;
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040012108 }
12109
Arik Nemtsovad30ca22014-12-15 19:25:59 +020012110 if (request->wiphy_idx != WIPHY_IDX_INVALID) {
12111 struct wiphy *wiphy = wiphy_idx_to_wiphy(request->wiphy_idx);
12112
12113 if (wiphy &&
12114 nla_put_u32(msg, NL80211_ATTR_WIPHY, request->wiphy_idx))
12115 goto nla_put_failure;
Arik Nemtsov1bdd7162014-12-15 19:26:01 +020012116
12117 if (wiphy &&
12118 wiphy->regulatory_flags & REGULATORY_WIPHY_SELF_MANAGED &&
12119 nla_put_flag(msg, NL80211_ATTR_WIPHY_SELF_MANAGED_REG))
12120 goto nla_put_failure;
Arik Nemtsovad30ca22014-12-15 19:25:59 +020012121 }
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040012122
Jonathan Doronb0d7aa52014-12-15 19:26:00 +020012123 return true;
12124
12125nla_put_failure:
12126 return false;
12127}
12128
12129/*
12130 * This can happen on global regulatory changes or device specific settings
12131 * based on custom regulatory domains.
12132 */
12133void nl80211_common_reg_change_event(enum nl80211_commands cmd_id,
12134 struct regulatory_request *request)
12135{
12136 struct sk_buff *msg;
12137 void *hdr;
12138
12139 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
12140 if (!msg)
12141 return;
12142
12143 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd_id);
12144 if (!hdr) {
12145 nlmsg_free(msg);
12146 return;
12147 }
12148
12149 if (nl80211_reg_change_event_fill(msg, request) == false)
12150 goto nla_put_failure;
12151
Johannes Berg3b7b72e2011-10-22 19:05:51 +020012152 genlmsg_end(msg, hdr);
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040012153
Johannes Bergbc43b282009-07-25 10:54:13 +020012154 rcu_read_lock();
Johannes Berg68eb5502013-11-19 15:19:38 +010012155 genlmsg_multicast_allns(&nl80211_fam, msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010012156 NL80211_MCGRP_REGULATORY, GFP_ATOMIC);
Johannes Bergbc43b282009-07-25 10:54:13 +020012157 rcu_read_unlock();
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040012158
12159 return;
12160
12161nla_put_failure:
12162 genlmsg_cancel(msg, hdr);
12163 nlmsg_free(msg);
12164}
12165
Jouni Malinen6039f6d2009-03-19 13:39:21 +020012166static void nl80211_send_mlme_event(struct cfg80211_registered_device *rdev,
12167 struct net_device *netdev,
12168 const u8 *buf, size_t len,
Eliad Pellerb0b6aa22014-09-09 17:09:45 +030012169 enum nl80211_commands cmd, gfp_t gfp,
12170 int uapsd_queues)
Jouni Malinen6039f6d2009-03-19 13:39:21 +020012171{
12172 struct sk_buff *msg;
12173 void *hdr;
12174
Johannes Berge6d6e342009-07-01 21:26:47 +020012175 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020012176 if (!msg)
12177 return;
12178
12179 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
12180 if (!hdr) {
12181 nlmsg_free(msg);
12182 return;
12183 }
12184
David S. Miller9360ffd2012-03-29 04:41:26 -040012185 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
12186 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
12187 nla_put(msg, NL80211_ATTR_FRAME, len, buf))
12188 goto nla_put_failure;
Jouni Malinen6039f6d2009-03-19 13:39:21 +020012189
Eliad Pellerb0b6aa22014-09-09 17:09:45 +030012190 if (uapsd_queues >= 0) {
12191 struct nlattr *nla_wmm =
12192 nla_nest_start(msg, NL80211_ATTR_STA_WME);
12193 if (!nla_wmm)
12194 goto nla_put_failure;
12195
12196 if (nla_put_u8(msg, NL80211_STA_WME_UAPSD_QUEUES,
12197 uapsd_queues))
12198 goto nla_put_failure;
12199
12200 nla_nest_end(msg, nla_wmm);
12201 }
12202
Johannes Berg3b7b72e2011-10-22 19:05:51 +020012203 genlmsg_end(msg, hdr);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020012204
Johannes Berg68eb5502013-11-19 15:19:38 +010012205 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010012206 NL80211_MCGRP_MLME, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020012207 return;
12208
12209 nla_put_failure:
12210 genlmsg_cancel(msg, hdr);
12211 nlmsg_free(msg);
12212}
12213
12214void nl80211_send_rx_auth(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +020012215 struct net_device *netdev, const u8 *buf,
12216 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +020012217{
12218 nl80211_send_mlme_event(rdev, netdev, buf, len,
Eliad Pellerb0b6aa22014-09-09 17:09:45 +030012219 NL80211_CMD_AUTHENTICATE, gfp, -1);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020012220}
12221
12222void nl80211_send_rx_assoc(struct cfg80211_registered_device *rdev,
12223 struct net_device *netdev, const u8 *buf,
Eliad Pellerb0b6aa22014-09-09 17:09:45 +030012224 size_t len, gfp_t gfp, int uapsd_queues)
Jouni Malinen6039f6d2009-03-19 13:39:21 +020012225{
Johannes Berge6d6e342009-07-01 21:26:47 +020012226 nl80211_send_mlme_event(rdev, netdev, buf, len,
Eliad Pellerb0b6aa22014-09-09 17:09:45 +030012227 NL80211_CMD_ASSOCIATE, gfp, uapsd_queues);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020012228}
12229
Jouni Malinen53b46b82009-03-27 20:53:56 +020012230void nl80211_send_deauth(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +020012231 struct net_device *netdev, const u8 *buf,
12232 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +020012233{
12234 nl80211_send_mlme_event(rdev, netdev, buf, len,
Eliad Pellerb0b6aa22014-09-09 17:09:45 +030012235 NL80211_CMD_DEAUTHENTICATE, gfp, -1);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020012236}
12237
Jouni Malinen53b46b82009-03-27 20:53:56 +020012238void nl80211_send_disassoc(struct cfg80211_registered_device *rdev,
12239 struct net_device *netdev, const u8 *buf,
Johannes Berge6d6e342009-07-01 21:26:47 +020012240 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +020012241{
12242 nl80211_send_mlme_event(rdev, netdev, buf, len,
Eliad Pellerb0b6aa22014-09-09 17:09:45 +030012243 NL80211_CMD_DISASSOCIATE, gfp, -1);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020012244}
12245
Johannes Berg6ff57cf2013-05-16 00:55:00 +020012246void cfg80211_rx_unprot_mlme_mgmt(struct net_device *dev, const u8 *buf,
12247 size_t len)
Jouni Malinencf4e5942010-12-16 00:52:40 +020012248{
Johannes Berg947add32013-02-22 22:05:20 +010012249 struct wireless_dev *wdev = dev->ieee80211_ptr;
12250 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080012251 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg6ff57cf2013-05-16 00:55:00 +020012252 const struct ieee80211_mgmt *mgmt = (void *)buf;
12253 u32 cmd;
Jouni Malinencf4e5942010-12-16 00:52:40 +020012254
Johannes Berg6ff57cf2013-05-16 00:55:00 +020012255 if (WARN_ON(len < 2))
12256 return;
12257
12258 if (ieee80211_is_deauth(mgmt->frame_control))
12259 cmd = NL80211_CMD_UNPROT_DEAUTHENTICATE;
12260 else
12261 cmd = NL80211_CMD_UNPROT_DISASSOCIATE;
12262
12263 trace_cfg80211_rx_unprot_mlme_mgmt(dev, buf, len);
Eliad Pellerb0b6aa22014-09-09 17:09:45 +030012264 nl80211_send_mlme_event(rdev, dev, buf, len, cmd, GFP_ATOMIC, -1);
Jouni Malinencf4e5942010-12-16 00:52:40 +020012265}
Johannes Berg6ff57cf2013-05-16 00:55:00 +020012266EXPORT_SYMBOL(cfg80211_rx_unprot_mlme_mgmt);
Jouni Malinencf4e5942010-12-16 00:52:40 +020012267
Luis R. Rodriguez1b06bb42009-05-02 00:34:48 -040012268static void nl80211_send_mlme_timeout(struct cfg80211_registered_device *rdev,
12269 struct net_device *netdev, int cmd,
Johannes Berge6d6e342009-07-01 21:26:47 +020012270 const u8 *addr, gfp_t gfp)
Jouni Malinen1965c852009-04-22 21:38:25 +030012271{
12272 struct sk_buff *msg;
12273 void *hdr;
12274
Johannes Berge6d6e342009-07-01 21:26:47 +020012275 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +030012276 if (!msg)
12277 return;
12278
12279 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
12280 if (!hdr) {
12281 nlmsg_free(msg);
12282 return;
12283 }
12284
David S. Miller9360ffd2012-03-29 04:41:26 -040012285 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
12286 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
12287 nla_put_flag(msg, NL80211_ATTR_TIMED_OUT) ||
12288 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr))
12289 goto nla_put_failure;
Jouni Malinen1965c852009-04-22 21:38:25 +030012290
Johannes Berg3b7b72e2011-10-22 19:05:51 +020012291 genlmsg_end(msg, hdr);
Jouni Malinen1965c852009-04-22 21:38:25 +030012292
Johannes Berg68eb5502013-11-19 15:19:38 +010012293 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010012294 NL80211_MCGRP_MLME, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +030012295 return;
12296
12297 nla_put_failure:
12298 genlmsg_cancel(msg, hdr);
12299 nlmsg_free(msg);
12300}
12301
12302void nl80211_send_auth_timeout(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +020012303 struct net_device *netdev, const u8 *addr,
12304 gfp_t gfp)
Jouni Malinen1965c852009-04-22 21:38:25 +030012305{
12306 nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_AUTHENTICATE,
Johannes Berge6d6e342009-07-01 21:26:47 +020012307 addr, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +030012308}
12309
12310void nl80211_send_assoc_timeout(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +020012311 struct net_device *netdev, const u8 *addr,
12312 gfp_t gfp)
Jouni Malinen1965c852009-04-22 21:38:25 +030012313{
Johannes Berge6d6e342009-07-01 21:26:47 +020012314 nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_ASSOCIATE,
12315 addr, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +030012316}
12317
Samuel Ortizb23aa672009-07-01 21:26:54 +020012318void nl80211_send_connect_result(struct cfg80211_registered_device *rdev,
12319 struct net_device *netdev, const u8 *bssid,
12320 const u8 *req_ie, size_t req_ie_len,
12321 const u8 *resp_ie, size_t resp_ie_len,
Jouni Malinenbf1ecd22016-05-31 00:16:50 +030012322 int status, gfp_t gfp)
Samuel Ortizb23aa672009-07-01 21:26:54 +020012323{
12324 struct sk_buff *msg;
12325 void *hdr;
12326
Thomas Graf58050fc2012-06-28 03:57:45 +000012327 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +020012328 if (!msg)
12329 return;
12330
12331 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONNECT);
12332 if (!hdr) {
12333 nlmsg_free(msg);
12334 return;
12335 }
12336
David S. Miller9360ffd2012-03-29 04:41:26 -040012337 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
12338 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
12339 (bssid && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) ||
Jouni Malinenbf1ecd22016-05-31 00:16:50 +030012340 nla_put_u16(msg, NL80211_ATTR_STATUS_CODE,
12341 status < 0 ? WLAN_STATUS_UNSPECIFIED_FAILURE :
12342 status) ||
12343 (status < 0 && nla_put_flag(msg, NL80211_ATTR_TIMED_OUT)) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040012344 (req_ie &&
12345 nla_put(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie)) ||
12346 (resp_ie &&
12347 nla_put(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie)))
12348 goto nla_put_failure;
Samuel Ortizb23aa672009-07-01 21:26:54 +020012349
Johannes Berg3b7b72e2011-10-22 19:05:51 +020012350 genlmsg_end(msg, hdr);
Samuel Ortizb23aa672009-07-01 21:26:54 +020012351
Johannes Berg68eb5502013-11-19 15:19:38 +010012352 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010012353 NL80211_MCGRP_MLME, gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +020012354 return;
12355
12356 nla_put_failure:
12357 genlmsg_cancel(msg, hdr);
12358 nlmsg_free(msg);
Samuel Ortizb23aa672009-07-01 21:26:54 +020012359}
12360
12361void nl80211_send_roamed(struct cfg80211_registered_device *rdev,
12362 struct net_device *netdev, const u8 *bssid,
12363 const u8 *req_ie, size_t req_ie_len,
12364 const u8 *resp_ie, size_t resp_ie_len, gfp_t gfp)
12365{
12366 struct sk_buff *msg;
12367 void *hdr;
12368
Thomas Graf58050fc2012-06-28 03:57:45 +000012369 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +020012370 if (!msg)
12371 return;
12372
12373 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_ROAM);
12374 if (!hdr) {
12375 nlmsg_free(msg);
12376 return;
12377 }
12378
David S. Miller9360ffd2012-03-29 04:41:26 -040012379 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
12380 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
12381 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid) ||
12382 (req_ie &&
12383 nla_put(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie)) ||
12384 (resp_ie &&
12385 nla_put(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie)))
12386 goto nla_put_failure;
Samuel Ortizb23aa672009-07-01 21:26:54 +020012387
Johannes Berg3b7b72e2011-10-22 19:05:51 +020012388 genlmsg_end(msg, hdr);
Samuel Ortizb23aa672009-07-01 21:26:54 +020012389
Johannes Berg68eb5502013-11-19 15:19:38 +010012390 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010012391 NL80211_MCGRP_MLME, gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +020012392 return;
12393
12394 nla_put_failure:
12395 genlmsg_cancel(msg, hdr);
12396 nlmsg_free(msg);
Samuel Ortizb23aa672009-07-01 21:26:54 +020012397}
12398
12399void nl80211_send_disconnected(struct cfg80211_registered_device *rdev,
12400 struct net_device *netdev, u16 reason,
Johannes Berg667503dd2009-07-07 03:56:11 +020012401 const u8 *ie, size_t ie_len, bool from_ap)
Samuel Ortizb23aa672009-07-01 21:26:54 +020012402{
12403 struct sk_buff *msg;
12404 void *hdr;
12405
Thomas Graf58050fc2012-06-28 03:57:45 +000012406 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Samuel Ortizb23aa672009-07-01 21:26:54 +020012407 if (!msg)
12408 return;
12409
12410 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DISCONNECT);
12411 if (!hdr) {
12412 nlmsg_free(msg);
12413 return;
12414 }
12415
David S. Miller9360ffd2012-03-29 04:41:26 -040012416 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
12417 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
12418 (from_ap && reason &&
12419 nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason)) ||
12420 (from_ap &&
12421 nla_put_flag(msg, NL80211_ATTR_DISCONNECTED_BY_AP)) ||
12422 (ie && nla_put(msg, NL80211_ATTR_IE, ie_len, ie)))
12423 goto nla_put_failure;
Samuel Ortizb23aa672009-07-01 21:26:54 +020012424
Johannes Berg3b7b72e2011-10-22 19:05:51 +020012425 genlmsg_end(msg, hdr);
Samuel Ortizb23aa672009-07-01 21:26:54 +020012426
Johannes Berg68eb5502013-11-19 15:19:38 +010012427 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010012428 NL80211_MCGRP_MLME, GFP_KERNEL);
Samuel Ortizb23aa672009-07-01 21:26:54 +020012429 return;
12430
12431 nla_put_failure:
12432 genlmsg_cancel(msg, hdr);
12433 nlmsg_free(msg);
Samuel Ortizb23aa672009-07-01 21:26:54 +020012434}
12435
Johannes Berg04a773a2009-04-19 21:24:32 +020012436void nl80211_send_ibss_bssid(struct cfg80211_registered_device *rdev,
12437 struct net_device *netdev, const u8 *bssid,
12438 gfp_t gfp)
12439{
12440 struct sk_buff *msg;
12441 void *hdr;
12442
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -070012443 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Johannes Berg04a773a2009-04-19 21:24:32 +020012444 if (!msg)
12445 return;
12446
12447 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_JOIN_IBSS);
12448 if (!hdr) {
12449 nlmsg_free(msg);
12450 return;
12451 }
12452
David S. Miller9360ffd2012-03-29 04:41:26 -040012453 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
12454 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
12455 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid))
12456 goto nla_put_failure;
Johannes Berg04a773a2009-04-19 21:24:32 +020012457
Johannes Berg3b7b72e2011-10-22 19:05:51 +020012458 genlmsg_end(msg, hdr);
Johannes Berg04a773a2009-04-19 21:24:32 +020012459
Johannes Berg68eb5502013-11-19 15:19:38 +010012460 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010012461 NL80211_MCGRP_MLME, gfp);
Johannes Berg04a773a2009-04-19 21:24:32 +020012462 return;
12463
12464 nla_put_failure:
12465 genlmsg_cancel(msg, hdr);
12466 nlmsg_free(msg);
12467}
12468
Johannes Berg947add32013-02-22 22:05:20 +010012469void cfg80211_notify_new_peer_candidate(struct net_device *dev, const u8 *addr,
12470 const u8* ie, u8 ie_len, gfp_t gfp)
Javier Cardonac93b5e72011-04-07 15:08:34 -070012471{
Johannes Berg947add32013-02-22 22:05:20 +010012472 struct wireless_dev *wdev = dev->ieee80211_ptr;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080012473 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Javier Cardonac93b5e72011-04-07 15:08:34 -070012474 struct sk_buff *msg;
12475 void *hdr;
12476
Johannes Berg947add32013-02-22 22:05:20 +010012477 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_MESH_POINT))
12478 return;
12479
12480 trace_cfg80211_notify_new_peer_candidate(dev, addr);
12481
Javier Cardonac93b5e72011-04-07 15:08:34 -070012482 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
12483 if (!msg)
12484 return;
12485
12486 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NEW_PEER_CANDIDATE);
12487 if (!hdr) {
12488 nlmsg_free(msg);
12489 return;
12490 }
12491
David S. Miller9360ffd2012-03-29 04:41:26 -040012492 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg947add32013-02-22 22:05:20 +010012493 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
12494 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040012495 (ie_len && ie &&
12496 nla_put(msg, NL80211_ATTR_IE, ie_len , ie)))
12497 goto nla_put_failure;
Javier Cardonac93b5e72011-04-07 15:08:34 -070012498
Johannes Berg3b7b72e2011-10-22 19:05:51 +020012499 genlmsg_end(msg, hdr);
Javier Cardonac93b5e72011-04-07 15:08:34 -070012500
Johannes Berg68eb5502013-11-19 15:19:38 +010012501 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010012502 NL80211_MCGRP_MLME, gfp);
Javier Cardonac93b5e72011-04-07 15:08:34 -070012503 return;
12504
12505 nla_put_failure:
12506 genlmsg_cancel(msg, hdr);
12507 nlmsg_free(msg);
12508}
Johannes Berg947add32013-02-22 22:05:20 +010012509EXPORT_SYMBOL(cfg80211_notify_new_peer_candidate);
Javier Cardonac93b5e72011-04-07 15:08:34 -070012510
Jouni Malinena3b8b052009-03-27 21:59:49 +020012511void nl80211_michael_mic_failure(struct cfg80211_registered_device *rdev,
12512 struct net_device *netdev, const u8 *addr,
12513 enum nl80211_key_type key_type, int key_id,
Johannes Berge6d6e342009-07-01 21:26:47 +020012514 const u8 *tsc, gfp_t gfp)
Jouni Malinena3b8b052009-03-27 21:59:49 +020012515{
12516 struct sk_buff *msg;
12517 void *hdr;
12518
Johannes Berge6d6e342009-07-01 21:26:47 +020012519 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinena3b8b052009-03-27 21:59:49 +020012520 if (!msg)
12521 return;
12522
12523 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_MICHAEL_MIC_FAILURE);
12524 if (!hdr) {
12525 nlmsg_free(msg);
12526 return;
12527 }
12528
David S. Miller9360ffd2012-03-29 04:41:26 -040012529 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
12530 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
12531 (addr && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) ||
12532 nla_put_u32(msg, NL80211_ATTR_KEY_TYPE, key_type) ||
12533 (key_id != -1 &&
12534 nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_id)) ||
12535 (tsc && nla_put(msg, NL80211_ATTR_KEY_SEQ, 6, tsc)))
12536 goto nla_put_failure;
Jouni Malinena3b8b052009-03-27 21:59:49 +020012537
Johannes Berg3b7b72e2011-10-22 19:05:51 +020012538 genlmsg_end(msg, hdr);
Jouni Malinena3b8b052009-03-27 21:59:49 +020012539
Johannes Berg68eb5502013-11-19 15:19:38 +010012540 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010012541 NL80211_MCGRP_MLME, gfp);
Jouni Malinena3b8b052009-03-27 21:59:49 +020012542 return;
12543
12544 nla_put_failure:
12545 genlmsg_cancel(msg, hdr);
12546 nlmsg_free(msg);
12547}
12548
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040012549void nl80211_send_beacon_hint_event(struct wiphy *wiphy,
12550 struct ieee80211_channel *channel_before,
12551 struct ieee80211_channel *channel_after)
12552{
12553 struct sk_buff *msg;
12554 void *hdr;
12555 struct nlattr *nl_freq;
12556
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -070012557 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_ATOMIC);
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040012558 if (!msg)
12559 return;
12560
12561 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_BEACON_HINT);
12562 if (!hdr) {
12563 nlmsg_free(msg);
12564 return;
12565 }
12566
12567 /*
12568 * Since we are applying the beacon hint to a wiphy we know its
12569 * wiphy_idx is valid
12570 */
David S. Miller9360ffd2012-03-29 04:41:26 -040012571 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy)))
12572 goto nla_put_failure;
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040012573
12574 /* Before */
12575 nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_BEFORE);
12576 if (!nl_freq)
12577 goto nla_put_failure;
Johannes Bergcdc89b92013-02-18 23:54:36 +010012578 if (nl80211_msg_put_channel(msg, channel_before, false))
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040012579 goto nla_put_failure;
12580 nla_nest_end(msg, nl_freq);
12581
12582 /* After */
12583 nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_AFTER);
12584 if (!nl_freq)
12585 goto nla_put_failure;
Johannes Bergcdc89b92013-02-18 23:54:36 +010012586 if (nl80211_msg_put_channel(msg, channel_after, false))
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040012587 goto nla_put_failure;
12588 nla_nest_end(msg, nl_freq);
12589
Johannes Berg3b7b72e2011-10-22 19:05:51 +020012590 genlmsg_end(msg, hdr);
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040012591
Johannes Berg463d0182009-07-14 00:33:35 +020012592 rcu_read_lock();
Johannes Berg68eb5502013-11-19 15:19:38 +010012593 genlmsg_multicast_allns(&nl80211_fam, msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010012594 NL80211_MCGRP_REGULATORY, GFP_ATOMIC);
Johannes Berg463d0182009-07-14 00:33:35 +020012595 rcu_read_unlock();
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040012596
12597 return;
12598
12599nla_put_failure:
12600 genlmsg_cancel(msg, hdr);
12601 nlmsg_free(msg);
12602}
12603
Jouni Malinen9588bbd2009-12-23 13:15:41 +010012604static void nl80211_send_remain_on_chan_event(
12605 int cmd, struct cfg80211_registered_device *rdev,
Johannes Berg71bbc992012-06-15 15:30:18 +020012606 struct wireless_dev *wdev, u64 cookie,
Jouni Malinen9588bbd2009-12-23 13:15:41 +010012607 struct ieee80211_channel *chan,
Jouni Malinen9588bbd2009-12-23 13:15:41 +010012608 unsigned int duration, gfp_t gfp)
12609{
12610 struct sk_buff *msg;
12611 void *hdr;
12612
12613 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
12614 if (!msg)
12615 return;
12616
12617 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
12618 if (!hdr) {
12619 nlmsg_free(msg);
12620 return;
12621 }
12622
David S. Miller9360ffd2012-03-29 04:41:26 -040012623 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg71bbc992012-06-15 15:30:18 +020012624 (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
12625 wdev->netdev->ifindex)) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020012626 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
12627 NL80211_ATTR_PAD) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040012628 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, chan->center_freq) ||
Johannes Berg42d97a52012-11-08 18:31:02 +010012629 nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE,
12630 NL80211_CHAN_NO_HT) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020012631 nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie,
12632 NL80211_ATTR_PAD))
David S. Miller9360ffd2012-03-29 04:41:26 -040012633 goto nla_put_failure;
Jouni Malinen9588bbd2009-12-23 13:15:41 +010012634
David S. Miller9360ffd2012-03-29 04:41:26 -040012635 if (cmd == NL80211_CMD_REMAIN_ON_CHANNEL &&
12636 nla_put_u32(msg, NL80211_ATTR_DURATION, duration))
12637 goto nla_put_failure;
Jouni Malinen9588bbd2009-12-23 13:15:41 +010012638
Johannes Berg3b7b72e2011-10-22 19:05:51 +020012639 genlmsg_end(msg, hdr);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010012640
Johannes Berg68eb5502013-11-19 15:19:38 +010012641 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010012642 NL80211_MCGRP_MLME, gfp);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010012643 return;
12644
12645 nla_put_failure:
12646 genlmsg_cancel(msg, hdr);
12647 nlmsg_free(msg);
12648}
12649
Johannes Berg947add32013-02-22 22:05:20 +010012650void cfg80211_ready_on_channel(struct wireless_dev *wdev, u64 cookie,
12651 struct ieee80211_channel *chan,
12652 unsigned int duration, gfp_t gfp)
Jouni Malinen9588bbd2009-12-23 13:15:41 +010012653{
Johannes Berg947add32013-02-22 22:05:20 +010012654 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080012655 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg947add32013-02-22 22:05:20 +010012656
12657 trace_cfg80211_ready_on_channel(wdev, cookie, chan, duration);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010012658 nl80211_send_remain_on_chan_event(NL80211_CMD_REMAIN_ON_CHANNEL,
Johannes Berg71bbc992012-06-15 15:30:18 +020012659 rdev, wdev, cookie, chan,
Johannes Berg42d97a52012-11-08 18:31:02 +010012660 duration, gfp);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010012661}
Johannes Berg947add32013-02-22 22:05:20 +010012662EXPORT_SYMBOL(cfg80211_ready_on_channel);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010012663
Johannes Berg947add32013-02-22 22:05:20 +010012664void cfg80211_remain_on_channel_expired(struct wireless_dev *wdev, u64 cookie,
12665 struct ieee80211_channel *chan,
12666 gfp_t gfp)
Jouni Malinen9588bbd2009-12-23 13:15:41 +010012667{
Johannes Berg947add32013-02-22 22:05:20 +010012668 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080012669 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg947add32013-02-22 22:05:20 +010012670
12671 trace_cfg80211_ready_on_channel_expired(wdev, cookie, chan);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010012672 nl80211_send_remain_on_chan_event(NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL,
Johannes Berg42d97a52012-11-08 18:31:02 +010012673 rdev, wdev, cookie, chan, 0, gfp);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010012674}
Johannes Berg947add32013-02-22 22:05:20 +010012675EXPORT_SYMBOL(cfg80211_remain_on_channel_expired);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010012676
Johannes Berg947add32013-02-22 22:05:20 +010012677void cfg80211_new_sta(struct net_device *dev, const u8 *mac_addr,
12678 struct station_info *sinfo, gfp_t gfp)
Johannes Berg98b62182009-12-23 13:15:44 +010012679{
Johannes Berg947add32013-02-22 22:05:20 +010012680 struct wiphy *wiphy = dev->ieee80211_ptr->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080012681 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg98b62182009-12-23 13:15:44 +010012682 struct sk_buff *msg;
12683
Johannes Berg947add32013-02-22 22:05:20 +010012684 trace_cfg80211_new_sta(dev, mac_addr, sinfo);
12685
Thomas Graf58050fc2012-06-28 03:57:45 +000012686 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Johannes Berg98b62182009-12-23 13:15:44 +010012687 if (!msg)
12688 return;
12689
Johannes Bergcf5ead82014-11-14 17:14:00 +010012690 if (nl80211_send_station(msg, NL80211_CMD_NEW_STATION, 0, 0, 0,
John W. Linville66266b32012-03-15 13:25:41 -040012691 rdev, dev, mac_addr, sinfo) < 0) {
Johannes Berg98b62182009-12-23 13:15:44 +010012692 nlmsg_free(msg);
12693 return;
12694 }
12695
Johannes Berg68eb5502013-11-19 15:19:38 +010012696 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010012697 NL80211_MCGRP_MLME, gfp);
Johannes Berg98b62182009-12-23 13:15:44 +010012698}
Johannes Berg947add32013-02-22 22:05:20 +010012699EXPORT_SYMBOL(cfg80211_new_sta);
Johannes Berg98b62182009-12-23 13:15:44 +010012700
Johannes Bergcf5ead82014-11-14 17:14:00 +010012701void cfg80211_del_sta_sinfo(struct net_device *dev, const u8 *mac_addr,
12702 struct station_info *sinfo, gfp_t gfp)
Jouni Malinenec15e682011-03-23 15:29:52 +020012703{
Johannes Berg947add32013-02-22 22:05:20 +010012704 struct wiphy *wiphy = dev->ieee80211_ptr->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080012705 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Jouni Malinenec15e682011-03-23 15:29:52 +020012706 struct sk_buff *msg;
Johannes Bergcf5ead82014-11-14 17:14:00 +010012707 struct station_info empty_sinfo = {};
12708
12709 if (!sinfo)
12710 sinfo = &empty_sinfo;
Jouni Malinenec15e682011-03-23 15:29:52 +020012711
Johannes Berg947add32013-02-22 22:05:20 +010012712 trace_cfg80211_del_sta(dev, mac_addr);
12713
Thomas Graf58050fc2012-06-28 03:57:45 +000012714 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinenec15e682011-03-23 15:29:52 +020012715 if (!msg)
12716 return;
12717
Johannes Bergcf5ead82014-11-14 17:14:00 +010012718 if (nl80211_send_station(msg, NL80211_CMD_DEL_STATION, 0, 0, 0,
Johannes Berg57007122015-01-16 21:05:02 +010012719 rdev, dev, mac_addr, sinfo) < 0) {
Jouni Malinenec15e682011-03-23 15:29:52 +020012720 nlmsg_free(msg);
12721 return;
12722 }
12723
Johannes Berg68eb5502013-11-19 15:19:38 +010012724 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010012725 NL80211_MCGRP_MLME, gfp);
Jouni Malinenec15e682011-03-23 15:29:52 +020012726}
Johannes Bergcf5ead82014-11-14 17:14:00 +010012727EXPORT_SYMBOL(cfg80211_del_sta_sinfo);
Jouni Malinenec15e682011-03-23 15:29:52 +020012728
Johannes Berg947add32013-02-22 22:05:20 +010012729void cfg80211_conn_failed(struct net_device *dev, const u8 *mac_addr,
12730 enum nl80211_connect_failed_reason reason,
12731 gfp_t gfp)
Pandiyarajan Pitchaimuthued44a952012-09-18 16:50:49 +053012732{
Johannes Berg947add32013-02-22 22:05:20 +010012733 struct wiphy *wiphy = dev->ieee80211_ptr->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080012734 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Pandiyarajan Pitchaimuthued44a952012-09-18 16:50:49 +053012735 struct sk_buff *msg;
12736 void *hdr;
12737
12738 msg = nlmsg_new(NLMSG_GOODSIZE, gfp);
12739 if (!msg)
12740 return;
12741
12742 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONN_FAILED);
12743 if (!hdr) {
12744 nlmsg_free(msg);
12745 return;
12746 }
12747
12748 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
12749 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) ||
12750 nla_put_u32(msg, NL80211_ATTR_CONN_FAILED_REASON, reason))
12751 goto nla_put_failure;
12752
12753 genlmsg_end(msg, hdr);
12754
Johannes Berg68eb5502013-11-19 15:19:38 +010012755 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010012756 NL80211_MCGRP_MLME, gfp);
Pandiyarajan Pitchaimuthued44a952012-09-18 16:50:49 +053012757 return;
12758
12759 nla_put_failure:
12760 genlmsg_cancel(msg, hdr);
12761 nlmsg_free(msg);
12762}
Johannes Berg947add32013-02-22 22:05:20 +010012763EXPORT_SYMBOL(cfg80211_conn_failed);
Pandiyarajan Pitchaimuthued44a952012-09-18 16:50:49 +053012764
Johannes Bergb92ab5d2011-11-04 11:18:19 +010012765static bool __nl80211_unexpected_frame(struct net_device *dev, u8 cmd,
12766 const u8 *addr, gfp_t gfp)
Johannes Berg28946da2011-11-04 11:18:12 +010012767{
12768 struct wireless_dev *wdev = dev->ieee80211_ptr;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080012769 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Johannes Berg28946da2011-11-04 11:18:12 +010012770 struct sk_buff *msg;
12771 void *hdr;
Eric W. Biederman15e47302012-09-07 20:12:54 +000012772 u32 nlportid = ACCESS_ONCE(wdev->ap_unexpected_nlportid);
Johannes Berg28946da2011-11-04 11:18:12 +010012773
Eric W. Biederman15e47302012-09-07 20:12:54 +000012774 if (!nlportid)
Johannes Berg28946da2011-11-04 11:18:12 +010012775 return false;
12776
12777 msg = nlmsg_new(100, gfp);
12778 if (!msg)
12779 return true;
12780
Johannes Bergb92ab5d2011-11-04 11:18:19 +010012781 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
Johannes Berg28946da2011-11-04 11:18:12 +010012782 if (!hdr) {
12783 nlmsg_free(msg);
12784 return true;
12785 }
12786
David S. Miller9360ffd2012-03-29 04:41:26 -040012787 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
12788 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
12789 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr))
12790 goto nla_put_failure;
Johannes Berg28946da2011-11-04 11:18:12 +010012791
Johannes Berg9c90a9f2013-06-04 12:46:03 +020012792 genlmsg_end(msg, hdr);
Eric W. Biederman15e47302012-09-07 20:12:54 +000012793 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid);
Johannes Berg28946da2011-11-04 11:18:12 +010012794 return true;
12795
12796 nla_put_failure:
12797 genlmsg_cancel(msg, hdr);
12798 nlmsg_free(msg);
12799 return true;
12800}
12801
Johannes Berg947add32013-02-22 22:05:20 +010012802bool cfg80211_rx_spurious_frame(struct net_device *dev,
12803 const u8 *addr, gfp_t gfp)
Johannes Bergb92ab5d2011-11-04 11:18:19 +010012804{
Johannes Berg947add32013-02-22 22:05:20 +010012805 struct wireless_dev *wdev = dev->ieee80211_ptr;
12806 bool ret;
Johannes Bergb92ab5d2011-11-04 11:18:19 +010012807
Johannes Berg947add32013-02-22 22:05:20 +010012808 trace_cfg80211_rx_spurious_frame(dev, addr);
12809
12810 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP &&
12811 wdev->iftype != NL80211_IFTYPE_P2P_GO)) {
12812 trace_cfg80211_return_bool(false);
12813 return false;
12814 }
12815 ret = __nl80211_unexpected_frame(dev, NL80211_CMD_UNEXPECTED_FRAME,
12816 addr, gfp);
12817 trace_cfg80211_return_bool(ret);
12818 return ret;
Johannes Bergb92ab5d2011-11-04 11:18:19 +010012819}
Johannes Berg947add32013-02-22 22:05:20 +010012820EXPORT_SYMBOL(cfg80211_rx_spurious_frame);
12821
12822bool cfg80211_rx_unexpected_4addr_frame(struct net_device *dev,
12823 const u8 *addr, gfp_t gfp)
12824{
12825 struct wireless_dev *wdev = dev->ieee80211_ptr;
12826 bool ret;
12827
12828 trace_cfg80211_rx_unexpected_4addr_frame(dev, addr);
12829
12830 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP &&
12831 wdev->iftype != NL80211_IFTYPE_P2P_GO &&
12832 wdev->iftype != NL80211_IFTYPE_AP_VLAN)) {
12833 trace_cfg80211_return_bool(false);
12834 return false;
12835 }
12836 ret = __nl80211_unexpected_frame(dev,
12837 NL80211_CMD_UNEXPECTED_4ADDR_FRAME,
12838 addr, gfp);
12839 trace_cfg80211_return_bool(ret);
12840 return ret;
12841}
12842EXPORT_SYMBOL(cfg80211_rx_unexpected_4addr_frame);
Johannes Bergb92ab5d2011-11-04 11:18:19 +010012843
Johannes Berg2e161f72010-08-12 15:38:38 +020012844int nl80211_send_mgmt(struct cfg80211_registered_device *rdev,
Eric W. Biederman15e47302012-09-07 20:12:54 +000012845 struct wireless_dev *wdev, u32 nlportid,
Johannes Berg804483e2012-03-05 22:18:41 +010012846 int freq, int sig_dbm,
Vladimir Kondratiev19504cf2013-08-15 14:51:28 +030012847 const u8 *buf, size_t len, u32 flags, gfp_t gfp)
Jouni Malinen026331c2010-02-15 12:53:10 +020012848{
Johannes Berg71bbc992012-06-15 15:30:18 +020012849 struct net_device *netdev = wdev->netdev;
Jouni Malinen026331c2010-02-15 12:53:10 +020012850 struct sk_buff *msg;
12851 void *hdr;
Jouni Malinen026331c2010-02-15 12:53:10 +020012852
12853 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
12854 if (!msg)
12855 return -ENOMEM;
12856
Johannes Berg2e161f72010-08-12 15:38:38 +020012857 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME);
Jouni Malinen026331c2010-02-15 12:53:10 +020012858 if (!hdr) {
12859 nlmsg_free(msg);
12860 return -ENOMEM;
12861 }
12862
David S. Miller9360ffd2012-03-29 04:41:26 -040012863 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg71bbc992012-06-15 15:30:18 +020012864 (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
12865 netdev->ifindex)) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020012866 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
12867 NL80211_ATTR_PAD) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040012868 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq) ||
12869 (sig_dbm &&
12870 nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) ||
Vladimir Kondratiev19504cf2013-08-15 14:51:28 +030012871 nla_put(msg, NL80211_ATTR_FRAME, len, buf) ||
12872 (flags &&
12873 nla_put_u32(msg, NL80211_ATTR_RXMGMT_FLAGS, flags)))
David S. Miller9360ffd2012-03-29 04:41:26 -040012874 goto nla_put_failure;
Jouni Malinen026331c2010-02-15 12:53:10 +020012875
Johannes Berg3b7b72e2011-10-22 19:05:51 +020012876 genlmsg_end(msg, hdr);
Jouni Malinen026331c2010-02-15 12:53:10 +020012877
Eric W. Biederman15e47302012-09-07 20:12:54 +000012878 return genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid);
Jouni Malinen026331c2010-02-15 12:53:10 +020012879
12880 nla_put_failure:
12881 genlmsg_cancel(msg, hdr);
12882 nlmsg_free(msg);
12883 return -ENOBUFS;
12884}
12885
Johannes Berg947add32013-02-22 22:05:20 +010012886void cfg80211_mgmt_tx_status(struct wireless_dev *wdev, u64 cookie,
12887 const u8 *buf, size_t len, bool ack, gfp_t gfp)
Jouni Malinen026331c2010-02-15 12:53:10 +020012888{
Johannes Berg947add32013-02-22 22:05:20 +010012889 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080012890 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg71bbc992012-06-15 15:30:18 +020012891 struct net_device *netdev = wdev->netdev;
Jouni Malinen026331c2010-02-15 12:53:10 +020012892 struct sk_buff *msg;
12893 void *hdr;
12894
Johannes Berg947add32013-02-22 22:05:20 +010012895 trace_cfg80211_mgmt_tx_status(wdev, cookie, ack);
12896
Jouni Malinen026331c2010-02-15 12:53:10 +020012897 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
12898 if (!msg)
12899 return;
12900
Johannes Berg2e161f72010-08-12 15:38:38 +020012901 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME_TX_STATUS);
Jouni Malinen026331c2010-02-15 12:53:10 +020012902 if (!hdr) {
12903 nlmsg_free(msg);
12904 return;
12905 }
12906
David S. Miller9360ffd2012-03-29 04:41:26 -040012907 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg71bbc992012-06-15 15:30:18 +020012908 (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
12909 netdev->ifindex)) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020012910 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
12911 NL80211_ATTR_PAD) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040012912 nla_put(msg, NL80211_ATTR_FRAME, len, buf) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020012913 nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie,
12914 NL80211_ATTR_PAD) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040012915 (ack && nla_put_flag(msg, NL80211_ATTR_ACK)))
12916 goto nla_put_failure;
Jouni Malinen026331c2010-02-15 12:53:10 +020012917
Johannes Berg3b7b72e2011-10-22 19:05:51 +020012918 genlmsg_end(msg, hdr);
Jouni Malinen026331c2010-02-15 12:53:10 +020012919
Johannes Berg68eb5502013-11-19 15:19:38 +010012920 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010012921 NL80211_MCGRP_MLME, gfp);
Jouni Malinen026331c2010-02-15 12:53:10 +020012922 return;
12923
12924 nla_put_failure:
12925 genlmsg_cancel(msg, hdr);
12926 nlmsg_free(msg);
12927}
Johannes Berg947add32013-02-22 22:05:20 +010012928EXPORT_SYMBOL(cfg80211_mgmt_tx_status);
Jouni Malinen026331c2010-02-15 12:53:10 +020012929
Johannes Berg5b97f492014-11-26 12:37:43 +010012930static struct sk_buff *cfg80211_prepare_cqm(struct net_device *dev,
12931 const char *mac, gfp_t gfp)
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020012932{
Johannes Berg947add32013-02-22 22:05:20 +010012933 struct wireless_dev *wdev = dev->ieee80211_ptr;
Johannes Berg5b97f492014-11-26 12:37:43 +010012934 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
12935 struct sk_buff *msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
12936 void **cb;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020012937
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020012938 if (!msg)
Johannes Berg5b97f492014-11-26 12:37:43 +010012939 return NULL;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020012940
Johannes Berg5b97f492014-11-26 12:37:43 +010012941 cb = (void **)msg->cb;
12942
12943 cb[0] = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM);
12944 if (!cb[0]) {
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020012945 nlmsg_free(msg);
Johannes Berg5b97f492014-11-26 12:37:43 +010012946 return NULL;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020012947 }
12948
David S. Miller9360ffd2012-03-29 04:41:26 -040012949 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg947add32013-02-22 22:05:20 +010012950 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex))
David S. Miller9360ffd2012-03-29 04:41:26 -040012951 goto nla_put_failure;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020012952
Johannes Berg5b97f492014-11-26 12:37:43 +010012953 if (mac && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac))
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020012954 goto nla_put_failure;
12955
Johannes Berg5b97f492014-11-26 12:37:43 +010012956 cb[1] = nla_nest_start(msg, NL80211_ATTR_CQM);
12957 if (!cb[1])
12958 goto nla_put_failure;
12959
12960 cb[2] = rdev;
12961
12962 return msg;
12963 nla_put_failure:
12964 nlmsg_free(msg);
12965 return NULL;
12966}
12967
12968static void cfg80211_send_cqm(struct sk_buff *msg, gfp_t gfp)
12969{
12970 void **cb = (void **)msg->cb;
12971 struct cfg80211_registered_device *rdev = cb[2];
12972
12973 nla_nest_end(msg, cb[1]);
12974 genlmsg_end(msg, cb[0]);
12975
12976 memset(msg->cb, 0, sizeof(msg->cb));
12977
12978 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
12979 NL80211_MCGRP_MLME, gfp);
12980}
12981
12982void cfg80211_cqm_rssi_notify(struct net_device *dev,
12983 enum nl80211_cqm_rssi_threshold_event rssi_event,
12984 gfp_t gfp)
12985{
12986 struct sk_buff *msg;
12987
12988 trace_cfg80211_cqm_rssi_notify(dev, rssi_event);
12989
Johannes Berg98f03342014-11-26 12:42:02 +010012990 if (WARN_ON(rssi_event != NL80211_CQM_RSSI_THRESHOLD_EVENT_LOW &&
12991 rssi_event != NL80211_CQM_RSSI_THRESHOLD_EVENT_HIGH))
12992 return;
12993
Johannes Berg5b97f492014-11-26 12:37:43 +010012994 msg = cfg80211_prepare_cqm(dev, NULL, gfp);
12995 if (!msg)
12996 return;
12997
David S. Miller9360ffd2012-03-29 04:41:26 -040012998 if (nla_put_u32(msg, NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT,
12999 rssi_event))
13000 goto nla_put_failure;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020013001
Johannes Berg5b97f492014-11-26 12:37:43 +010013002 cfg80211_send_cqm(msg, gfp);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020013003
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020013004 return;
13005
13006 nla_put_failure:
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020013007 nlmsg_free(msg);
13008}
Johannes Berg947add32013-02-22 22:05:20 +010013009EXPORT_SYMBOL(cfg80211_cqm_rssi_notify);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020013010
Johannes Berg5b97f492014-11-26 12:37:43 +010013011void cfg80211_cqm_txe_notify(struct net_device *dev,
13012 const u8 *peer, u32 num_packets,
13013 u32 rate, u32 intvl, gfp_t gfp)
13014{
13015 struct sk_buff *msg;
13016
13017 msg = cfg80211_prepare_cqm(dev, peer, gfp);
13018 if (!msg)
13019 return;
13020
13021 if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_PKTS, num_packets))
13022 goto nla_put_failure;
13023
13024 if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_RATE, rate))
13025 goto nla_put_failure;
13026
13027 if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_INTVL, intvl))
13028 goto nla_put_failure;
13029
13030 cfg80211_send_cqm(msg, gfp);
13031 return;
13032
13033 nla_put_failure:
13034 nlmsg_free(msg);
13035}
13036EXPORT_SYMBOL(cfg80211_cqm_txe_notify);
13037
13038void cfg80211_cqm_pktloss_notify(struct net_device *dev,
13039 const u8 *peer, u32 num_packets, gfp_t gfp)
13040{
13041 struct sk_buff *msg;
13042
13043 trace_cfg80211_cqm_pktloss_notify(dev, peer, num_packets);
13044
13045 msg = cfg80211_prepare_cqm(dev, peer, gfp);
13046 if (!msg)
13047 return;
13048
13049 if (nla_put_u32(msg, NL80211_ATTR_CQM_PKT_LOSS_EVENT, num_packets))
13050 goto nla_put_failure;
13051
13052 cfg80211_send_cqm(msg, gfp);
13053 return;
13054
13055 nla_put_failure:
13056 nlmsg_free(msg);
13057}
13058EXPORT_SYMBOL(cfg80211_cqm_pktloss_notify);
13059
Johannes Berg98f03342014-11-26 12:42:02 +010013060void cfg80211_cqm_beacon_loss_notify(struct net_device *dev, gfp_t gfp)
13061{
13062 struct sk_buff *msg;
13063
13064 msg = cfg80211_prepare_cqm(dev, NULL, gfp);
13065 if (!msg)
13066 return;
13067
13068 if (nla_put_flag(msg, NL80211_ATTR_CQM_BEACON_LOSS_EVENT))
13069 goto nla_put_failure;
13070
13071 cfg80211_send_cqm(msg, gfp);
13072 return;
13073
13074 nla_put_failure:
13075 nlmsg_free(msg);
13076}
13077EXPORT_SYMBOL(cfg80211_cqm_beacon_loss_notify);
13078
Johannes Berg947add32013-02-22 22:05:20 +010013079static void nl80211_gtk_rekey_notify(struct cfg80211_registered_device *rdev,
13080 struct net_device *netdev, const u8 *bssid,
13081 const u8 *replay_ctr, gfp_t gfp)
Johannes Berge5497d72011-07-05 16:35:40 +020013082{
13083 struct sk_buff *msg;
13084 struct nlattr *rekey_attr;
13085 void *hdr;
13086
Thomas Graf58050fc2012-06-28 03:57:45 +000013087 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Johannes Berge5497d72011-07-05 16:35:40 +020013088 if (!msg)
13089 return;
13090
13091 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_REKEY_OFFLOAD);
13092 if (!hdr) {
13093 nlmsg_free(msg);
13094 return;
13095 }
13096
David S. Miller9360ffd2012-03-29 04:41:26 -040013097 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
13098 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
13099 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid))
13100 goto nla_put_failure;
Johannes Berge5497d72011-07-05 16:35:40 +020013101
13102 rekey_attr = nla_nest_start(msg, NL80211_ATTR_REKEY_DATA);
13103 if (!rekey_attr)
13104 goto nla_put_failure;
13105
David S. Miller9360ffd2012-03-29 04:41:26 -040013106 if (nla_put(msg, NL80211_REKEY_DATA_REPLAY_CTR,
13107 NL80211_REPLAY_CTR_LEN, replay_ctr))
13108 goto nla_put_failure;
Johannes Berge5497d72011-07-05 16:35:40 +020013109
13110 nla_nest_end(msg, rekey_attr);
13111
Johannes Berg3b7b72e2011-10-22 19:05:51 +020013112 genlmsg_end(msg, hdr);
Johannes Berge5497d72011-07-05 16:35:40 +020013113
Johannes Berg68eb5502013-11-19 15:19:38 +010013114 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010013115 NL80211_MCGRP_MLME, gfp);
Johannes Berge5497d72011-07-05 16:35:40 +020013116 return;
13117
13118 nla_put_failure:
13119 genlmsg_cancel(msg, hdr);
13120 nlmsg_free(msg);
13121}
13122
Johannes Berg947add32013-02-22 22:05:20 +010013123void cfg80211_gtk_rekey_notify(struct net_device *dev, const u8 *bssid,
13124 const u8 *replay_ctr, gfp_t gfp)
13125{
13126 struct wireless_dev *wdev = dev->ieee80211_ptr;
13127 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080013128 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg947add32013-02-22 22:05:20 +010013129
13130 trace_cfg80211_gtk_rekey_notify(dev, bssid);
13131 nl80211_gtk_rekey_notify(rdev, dev, bssid, replay_ctr, gfp);
13132}
13133EXPORT_SYMBOL(cfg80211_gtk_rekey_notify);
13134
13135static void
13136nl80211_pmksa_candidate_notify(struct cfg80211_registered_device *rdev,
13137 struct net_device *netdev, int index,
13138 const u8 *bssid, bool preauth, gfp_t gfp)
Jouni Malinenc9df56b2011-09-16 18:56:23 +030013139{
13140 struct sk_buff *msg;
13141 struct nlattr *attr;
13142 void *hdr;
13143
Thomas Graf58050fc2012-06-28 03:57:45 +000013144 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinenc9df56b2011-09-16 18:56:23 +030013145 if (!msg)
13146 return;
13147
13148 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PMKSA_CANDIDATE);
13149 if (!hdr) {
13150 nlmsg_free(msg);
13151 return;
13152 }
13153
David S. Miller9360ffd2012-03-29 04:41:26 -040013154 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
13155 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex))
13156 goto nla_put_failure;
Jouni Malinenc9df56b2011-09-16 18:56:23 +030013157
13158 attr = nla_nest_start(msg, NL80211_ATTR_PMKSA_CANDIDATE);
13159 if (!attr)
13160 goto nla_put_failure;
13161
David S. Miller9360ffd2012-03-29 04:41:26 -040013162 if (nla_put_u32(msg, NL80211_PMKSA_CANDIDATE_INDEX, index) ||
13163 nla_put(msg, NL80211_PMKSA_CANDIDATE_BSSID, ETH_ALEN, bssid) ||
13164 (preauth &&
13165 nla_put_flag(msg, NL80211_PMKSA_CANDIDATE_PREAUTH)))
13166 goto nla_put_failure;
Jouni Malinenc9df56b2011-09-16 18:56:23 +030013167
13168 nla_nest_end(msg, attr);
13169
Johannes Berg3b7b72e2011-10-22 19:05:51 +020013170 genlmsg_end(msg, hdr);
Jouni Malinenc9df56b2011-09-16 18:56:23 +030013171
Johannes Berg68eb5502013-11-19 15:19:38 +010013172 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010013173 NL80211_MCGRP_MLME, gfp);
Jouni Malinenc9df56b2011-09-16 18:56:23 +030013174 return;
13175
13176 nla_put_failure:
13177 genlmsg_cancel(msg, hdr);
13178 nlmsg_free(msg);
13179}
13180
Johannes Berg947add32013-02-22 22:05:20 +010013181void cfg80211_pmksa_candidate_notify(struct net_device *dev, int index,
13182 const u8 *bssid, bool preauth, gfp_t gfp)
13183{
13184 struct wireless_dev *wdev = dev->ieee80211_ptr;
13185 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080013186 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg947add32013-02-22 22:05:20 +010013187
13188 trace_cfg80211_pmksa_candidate_notify(dev, index, bssid, preauth);
13189 nl80211_pmksa_candidate_notify(rdev, dev, index, bssid, preauth, gfp);
13190}
13191EXPORT_SYMBOL(cfg80211_pmksa_candidate_notify);
13192
13193static void nl80211_ch_switch_notify(struct cfg80211_registered_device *rdev,
13194 struct net_device *netdev,
13195 struct cfg80211_chan_def *chandef,
Luciano Coelhof8d75522014-11-07 14:31:35 +020013196 gfp_t gfp,
13197 enum nl80211_commands notif,
13198 u8 count)
Thomas Pedersen53145262012-04-06 13:35:47 -070013199{
13200 struct sk_buff *msg;
13201 void *hdr;
13202
Thomas Graf58050fc2012-06-28 03:57:45 +000013203 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Thomas Pedersen53145262012-04-06 13:35:47 -070013204 if (!msg)
13205 return;
13206
Luciano Coelhof8d75522014-11-07 14:31:35 +020013207 hdr = nl80211hdr_put(msg, 0, 0, 0, notif);
Thomas Pedersen53145262012-04-06 13:35:47 -070013208 if (!hdr) {
13209 nlmsg_free(msg);
13210 return;
13211 }
13212
Johannes Berg683b6d32012-11-08 21:25:48 +010013213 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex))
13214 goto nla_put_failure;
13215
13216 if (nl80211_send_chandef(msg, chandef))
John W. Linville7eab0f62012-04-12 14:25:14 -040013217 goto nla_put_failure;
Thomas Pedersen53145262012-04-06 13:35:47 -070013218
Luciano Coelhof8d75522014-11-07 14:31:35 +020013219 if ((notif == NL80211_CMD_CH_SWITCH_STARTED_NOTIFY) &&
13220 (nla_put_u32(msg, NL80211_ATTR_CH_SWITCH_COUNT, count)))
13221 goto nla_put_failure;
13222
Thomas Pedersen53145262012-04-06 13:35:47 -070013223 genlmsg_end(msg, hdr);
13224
Johannes Berg68eb5502013-11-19 15:19:38 +010013225 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010013226 NL80211_MCGRP_MLME, gfp);
Thomas Pedersen53145262012-04-06 13:35:47 -070013227 return;
13228
13229 nla_put_failure:
13230 genlmsg_cancel(msg, hdr);
13231 nlmsg_free(msg);
13232}
13233
Johannes Berg947add32013-02-22 22:05:20 +010013234void cfg80211_ch_switch_notify(struct net_device *dev,
13235 struct cfg80211_chan_def *chandef)
Thomas Pedersen84f10702012-07-12 16:17:33 -070013236{
Johannes Berg947add32013-02-22 22:05:20 +010013237 struct wireless_dev *wdev = dev->ieee80211_ptr;
13238 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080013239 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg947add32013-02-22 22:05:20 +010013240
Simon Wunderliche487eae2013-11-21 18:19:51 +010013241 ASSERT_WDEV_LOCK(wdev);
Johannes Berg947add32013-02-22 22:05:20 +010013242
Simon Wunderliche487eae2013-11-21 18:19:51 +010013243 trace_cfg80211_ch_switch_notify(dev, chandef);
Johannes Berg947add32013-02-22 22:05:20 +010013244
Michal Kazior9e0e2962014-01-29 14:22:27 +010013245 wdev->chandef = *chandef;
Janusz Dziedzic96f55f12014-01-24 14:29:21 +010013246 wdev->preset_chandef = *chandef;
Luciano Coelhof8d75522014-11-07 14:31:35 +020013247 nl80211_ch_switch_notify(rdev, dev, chandef, GFP_KERNEL,
13248 NL80211_CMD_CH_SWITCH_NOTIFY, 0);
Johannes Berg947add32013-02-22 22:05:20 +010013249}
13250EXPORT_SYMBOL(cfg80211_ch_switch_notify);
13251
Luciano Coelhof8d75522014-11-07 14:31:35 +020013252void cfg80211_ch_switch_started_notify(struct net_device *dev,
13253 struct cfg80211_chan_def *chandef,
13254 u8 count)
13255{
13256 struct wireless_dev *wdev = dev->ieee80211_ptr;
13257 struct wiphy *wiphy = wdev->wiphy;
13258 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
13259
13260 trace_cfg80211_ch_switch_started_notify(dev, chandef);
13261
13262 nl80211_ch_switch_notify(rdev, dev, chandef, GFP_KERNEL,
13263 NL80211_CMD_CH_SWITCH_STARTED_NOTIFY, count);
13264}
13265EXPORT_SYMBOL(cfg80211_ch_switch_started_notify);
13266
Thomas Pedersen84f10702012-07-12 16:17:33 -070013267void
Simon Wunderlich04f39042013-02-08 18:16:19 +010013268nl80211_radar_notify(struct cfg80211_registered_device *rdev,
Janusz Dziedzicd2859df2013-11-06 13:55:51 +010013269 const struct cfg80211_chan_def *chandef,
Simon Wunderlich04f39042013-02-08 18:16:19 +010013270 enum nl80211_radar_event event,
13271 struct net_device *netdev, gfp_t gfp)
13272{
13273 struct sk_buff *msg;
13274 void *hdr;
13275
13276 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
13277 if (!msg)
13278 return;
13279
13280 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_RADAR_DETECT);
13281 if (!hdr) {
13282 nlmsg_free(msg);
13283 return;
13284 }
13285
13286 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx))
13287 goto nla_put_failure;
13288
13289 /* NOP and radar events don't need a netdev parameter */
13290 if (netdev) {
13291 struct wireless_dev *wdev = netdev->ieee80211_ptr;
13292
13293 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020013294 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
13295 NL80211_ATTR_PAD))
Simon Wunderlich04f39042013-02-08 18:16:19 +010013296 goto nla_put_failure;
13297 }
13298
13299 if (nla_put_u32(msg, NL80211_ATTR_RADAR_EVENT, event))
13300 goto nla_put_failure;
13301
13302 if (nl80211_send_chandef(msg, chandef))
13303 goto nla_put_failure;
13304
Johannes Berg9c90a9f2013-06-04 12:46:03 +020013305 genlmsg_end(msg, hdr);
Simon Wunderlich04f39042013-02-08 18:16:19 +010013306
Johannes Berg68eb5502013-11-19 15:19:38 +010013307 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010013308 NL80211_MCGRP_MLME, gfp);
Simon Wunderlich04f39042013-02-08 18:16:19 +010013309 return;
13310
13311 nla_put_failure:
13312 genlmsg_cancel(msg, hdr);
13313 nlmsg_free(msg);
13314}
13315
Johannes Berg7f6cf312011-11-04 11:18:15 +010013316void cfg80211_probe_status(struct net_device *dev, const u8 *addr,
13317 u64 cookie, bool acked, gfp_t gfp)
13318{
13319 struct wireless_dev *wdev = dev->ieee80211_ptr;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080013320 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Johannes Berg7f6cf312011-11-04 11:18:15 +010013321 struct sk_buff *msg;
13322 void *hdr;
Johannes Berg7f6cf312011-11-04 11:18:15 +010013323
Beni Lev4ee3e062012-08-27 12:49:39 +030013324 trace_cfg80211_probe_status(dev, addr, cookie, acked);
13325
Thomas Graf58050fc2012-06-28 03:57:45 +000013326 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Beni Lev4ee3e062012-08-27 12:49:39 +030013327
Johannes Berg7f6cf312011-11-04 11:18:15 +010013328 if (!msg)
13329 return;
13330
13331 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PROBE_CLIENT);
13332 if (!hdr) {
13333 nlmsg_free(msg);
13334 return;
13335 }
13336
David S. Miller9360ffd2012-03-29 04:41:26 -040013337 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
13338 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
13339 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020013340 nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie,
13341 NL80211_ATTR_PAD) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040013342 (acked && nla_put_flag(msg, NL80211_ATTR_ACK)))
13343 goto nla_put_failure;
Johannes Berg7f6cf312011-11-04 11:18:15 +010013344
Johannes Berg9c90a9f2013-06-04 12:46:03 +020013345 genlmsg_end(msg, hdr);
Johannes Berg7f6cf312011-11-04 11:18:15 +010013346
Johannes Berg68eb5502013-11-19 15:19:38 +010013347 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010013348 NL80211_MCGRP_MLME, gfp);
Johannes Berg7f6cf312011-11-04 11:18:15 +010013349 return;
13350
13351 nla_put_failure:
13352 genlmsg_cancel(msg, hdr);
13353 nlmsg_free(msg);
13354}
13355EXPORT_SYMBOL(cfg80211_probe_status);
13356
Johannes Berg5e7602302011-11-04 11:18:17 +010013357void cfg80211_report_obss_beacon(struct wiphy *wiphy,
13358 const u8 *frame, size_t len,
Ben Greear37c73b52012-10-26 14:49:25 -070013359 int freq, int sig_dbm)
Johannes Berg5e7602302011-11-04 11:18:17 +010013360{
Zhao, Gangf26cbf42014-04-21 12:53:03 +080013361 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg5e7602302011-11-04 11:18:17 +010013362 struct sk_buff *msg;
13363 void *hdr;
Ben Greear37c73b52012-10-26 14:49:25 -070013364 struct cfg80211_beacon_registration *reg;
Johannes Berg5e7602302011-11-04 11:18:17 +010013365
Beni Lev4ee3e062012-08-27 12:49:39 +030013366 trace_cfg80211_report_obss_beacon(wiphy, frame, len, freq, sig_dbm);
13367
Ben Greear37c73b52012-10-26 14:49:25 -070013368 spin_lock_bh(&rdev->beacon_registrations_lock);
13369 list_for_each_entry(reg, &rdev->beacon_registrations, list) {
13370 msg = nlmsg_new(len + 100, GFP_ATOMIC);
13371 if (!msg) {
13372 spin_unlock_bh(&rdev->beacon_registrations_lock);
13373 return;
13374 }
Johannes Berg5e7602302011-11-04 11:18:17 +010013375
Ben Greear37c73b52012-10-26 14:49:25 -070013376 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME);
13377 if (!hdr)
13378 goto nla_put_failure;
Johannes Berg5e7602302011-11-04 11:18:17 +010013379
Ben Greear37c73b52012-10-26 14:49:25 -070013380 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
13381 (freq &&
13382 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq)) ||
13383 (sig_dbm &&
13384 nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) ||
13385 nla_put(msg, NL80211_ATTR_FRAME, len, frame))
13386 goto nla_put_failure;
13387
13388 genlmsg_end(msg, hdr);
13389
13390 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, reg->nlportid);
Johannes Berg5e7602302011-11-04 11:18:17 +010013391 }
Ben Greear37c73b52012-10-26 14:49:25 -070013392 spin_unlock_bh(&rdev->beacon_registrations_lock);
Johannes Berg5e7602302011-11-04 11:18:17 +010013393 return;
13394
13395 nla_put_failure:
Ben Greear37c73b52012-10-26 14:49:25 -070013396 spin_unlock_bh(&rdev->beacon_registrations_lock);
13397 if (hdr)
13398 genlmsg_cancel(msg, hdr);
Johannes Berg5e7602302011-11-04 11:18:17 +010013399 nlmsg_free(msg);
13400}
13401EXPORT_SYMBOL(cfg80211_report_obss_beacon);
13402
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010013403#ifdef CONFIG_PM
Luciano Coelho8cd4d452014-09-17 11:55:28 +030013404static int cfg80211_net_detect_results(struct sk_buff *msg,
13405 struct cfg80211_wowlan_wakeup *wakeup)
13406{
13407 struct cfg80211_wowlan_nd_info *nd = wakeup->net_detect;
13408 struct nlattr *nl_results, *nl_match, *nl_freqs;
13409 int i, j;
13410
13411 nl_results = nla_nest_start(
13412 msg, NL80211_WOWLAN_TRIG_NET_DETECT_RESULTS);
13413 if (!nl_results)
13414 return -EMSGSIZE;
13415
13416 for (i = 0; i < nd->n_matches; i++) {
13417 struct cfg80211_wowlan_nd_match *match = nd->matches[i];
13418
13419 nl_match = nla_nest_start(msg, i);
13420 if (!nl_match)
13421 break;
13422
13423 /* The SSID attribute is optional in nl80211, but for
13424 * simplicity reasons it's always present in the
13425 * cfg80211 structure. If a driver can't pass the
13426 * SSID, that needs to be changed. A zero length SSID
13427 * is still a valid SSID (wildcard), so it cannot be
13428 * used for this purpose.
13429 */
13430 if (nla_put(msg, NL80211_ATTR_SSID, match->ssid.ssid_len,
13431 match->ssid.ssid)) {
13432 nla_nest_cancel(msg, nl_match);
13433 goto out;
13434 }
13435
13436 if (match->n_channels) {
13437 nl_freqs = nla_nest_start(
13438 msg, NL80211_ATTR_SCAN_FREQUENCIES);
13439 if (!nl_freqs) {
13440 nla_nest_cancel(msg, nl_match);
13441 goto out;
13442 }
13443
13444 for (j = 0; j < match->n_channels; j++) {
Samuel Tan5528fae82015-02-09 21:29:15 +020013445 if (nla_put_u32(msg, j, match->channels[j])) {
Luciano Coelho8cd4d452014-09-17 11:55:28 +030013446 nla_nest_cancel(msg, nl_freqs);
13447 nla_nest_cancel(msg, nl_match);
13448 goto out;
13449 }
13450 }
13451
13452 nla_nest_end(msg, nl_freqs);
13453 }
13454
13455 nla_nest_end(msg, nl_match);
13456 }
13457
13458out:
13459 nla_nest_end(msg, nl_results);
13460 return 0;
13461}
13462
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010013463void cfg80211_report_wowlan_wakeup(struct wireless_dev *wdev,
13464 struct cfg80211_wowlan_wakeup *wakeup,
13465 gfp_t gfp)
13466{
Zhao, Gangf26cbf42014-04-21 12:53:03 +080013467 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010013468 struct sk_buff *msg;
13469 void *hdr;
Johannes Berg9c90a9f2013-06-04 12:46:03 +020013470 int size = 200;
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010013471
13472 trace_cfg80211_report_wowlan_wakeup(wdev->wiphy, wdev, wakeup);
13473
13474 if (wakeup)
13475 size += wakeup->packet_present_len;
13476
13477 msg = nlmsg_new(size, gfp);
13478 if (!msg)
13479 return;
13480
13481 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_WOWLAN);
13482 if (!hdr)
13483 goto free_msg;
13484
13485 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020013486 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
13487 NL80211_ATTR_PAD))
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010013488 goto free_msg;
13489
13490 if (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
13491 wdev->netdev->ifindex))
13492 goto free_msg;
13493
13494 if (wakeup) {
13495 struct nlattr *reasons;
13496
13497 reasons = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS);
Johannes Berg7fa322c2013-10-25 11:16:58 +020013498 if (!reasons)
13499 goto free_msg;
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010013500
13501 if (wakeup->disconnect &&
13502 nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT))
13503 goto free_msg;
13504 if (wakeup->magic_pkt &&
13505 nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT))
13506 goto free_msg;
13507 if (wakeup->gtk_rekey_failure &&
13508 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE))
13509 goto free_msg;
13510 if (wakeup->eap_identity_req &&
13511 nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST))
13512 goto free_msg;
13513 if (wakeup->four_way_handshake &&
13514 nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE))
13515 goto free_msg;
13516 if (wakeup->rfkill_release &&
13517 nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE))
13518 goto free_msg;
13519
13520 if (wakeup->pattern_idx >= 0 &&
13521 nla_put_u32(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN,
13522 wakeup->pattern_idx))
13523 goto free_msg;
13524
Johannes Bergae917c92013-10-25 11:05:22 +020013525 if (wakeup->tcp_match &&
13526 nla_put_flag(msg, NL80211_WOWLAN_TRIG_WAKEUP_TCP_MATCH))
13527 goto free_msg;
Johannes Berg2a0e0472013-01-23 22:57:40 +010013528
Johannes Bergae917c92013-10-25 11:05:22 +020013529 if (wakeup->tcp_connlost &&
13530 nla_put_flag(msg, NL80211_WOWLAN_TRIG_WAKEUP_TCP_CONNLOST))
13531 goto free_msg;
Johannes Berg2a0e0472013-01-23 22:57:40 +010013532
Johannes Bergae917c92013-10-25 11:05:22 +020013533 if (wakeup->tcp_nomoretokens &&
13534 nla_put_flag(msg,
13535 NL80211_WOWLAN_TRIG_WAKEUP_TCP_NOMORETOKENS))
13536 goto free_msg;
Johannes Berg2a0e0472013-01-23 22:57:40 +010013537
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010013538 if (wakeup->packet) {
13539 u32 pkt_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211;
13540 u32 len_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211_LEN;
13541
13542 if (!wakeup->packet_80211) {
13543 pkt_attr =
13544 NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023;
13545 len_attr =
13546 NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023_LEN;
13547 }
13548
13549 if (wakeup->packet_len &&
13550 nla_put_u32(msg, len_attr, wakeup->packet_len))
13551 goto free_msg;
13552
13553 if (nla_put(msg, pkt_attr, wakeup->packet_present_len,
13554 wakeup->packet))
13555 goto free_msg;
13556 }
13557
Luciano Coelho8cd4d452014-09-17 11:55:28 +030013558 if (wakeup->net_detect &&
13559 cfg80211_net_detect_results(msg, wakeup))
13560 goto free_msg;
13561
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010013562 nla_nest_end(msg, reasons);
13563 }
13564
Johannes Berg9c90a9f2013-06-04 12:46:03 +020013565 genlmsg_end(msg, hdr);
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010013566
Johannes Berg68eb5502013-11-19 15:19:38 +010013567 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010013568 NL80211_MCGRP_MLME, gfp);
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010013569 return;
13570
13571 free_msg:
13572 nlmsg_free(msg);
13573}
13574EXPORT_SYMBOL(cfg80211_report_wowlan_wakeup);
13575#endif
13576
Jouni Malinen3475b092012-11-16 22:49:57 +020013577void cfg80211_tdls_oper_request(struct net_device *dev, const u8 *peer,
13578 enum nl80211_tdls_operation oper,
13579 u16 reason_code, gfp_t gfp)
13580{
13581 struct wireless_dev *wdev = dev->ieee80211_ptr;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080013582 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Jouni Malinen3475b092012-11-16 22:49:57 +020013583 struct sk_buff *msg;
13584 void *hdr;
Jouni Malinen3475b092012-11-16 22:49:57 +020013585
13586 trace_cfg80211_tdls_oper_request(wdev->wiphy, dev, peer, oper,
13587 reason_code);
13588
13589 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
13590 if (!msg)
13591 return;
13592
13593 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_TDLS_OPER);
13594 if (!hdr) {
13595 nlmsg_free(msg);
13596 return;
13597 }
13598
13599 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
13600 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
13601 nla_put_u8(msg, NL80211_ATTR_TDLS_OPERATION, oper) ||
13602 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer) ||
13603 (reason_code > 0 &&
13604 nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason_code)))
13605 goto nla_put_failure;
13606
Johannes Berg9c90a9f2013-06-04 12:46:03 +020013607 genlmsg_end(msg, hdr);
Jouni Malinen3475b092012-11-16 22:49:57 +020013608
Johannes Berg68eb5502013-11-19 15:19:38 +010013609 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010013610 NL80211_MCGRP_MLME, gfp);
Jouni Malinen3475b092012-11-16 22:49:57 +020013611 return;
13612
13613 nla_put_failure:
13614 genlmsg_cancel(msg, hdr);
13615 nlmsg_free(msg);
13616}
13617EXPORT_SYMBOL(cfg80211_tdls_oper_request);
13618
Jouni Malinen026331c2010-02-15 12:53:10 +020013619static int nl80211_netlink_notify(struct notifier_block * nb,
13620 unsigned long state,
13621 void *_notify)
13622{
13623 struct netlink_notify *notify = _notify;
13624 struct cfg80211_registered_device *rdev;
13625 struct wireless_dev *wdev;
Ben Greear37c73b52012-10-26 14:49:25 -070013626 struct cfg80211_beacon_registration *reg, *tmp;
Jouni Malinen026331c2010-02-15 12:53:10 +020013627
Dmitry Ivanov8f815cd2016-04-06 17:23:18 +030013628 if (state != NETLINK_URELEASE || notify->protocol != NETLINK_GENERIC)
Jouni Malinen026331c2010-02-15 12:53:10 +020013629 return NOTIFY_DONE;
13630
13631 rcu_read_lock();
13632
Johannes Berg5e7602302011-11-04 11:18:17 +010013633 list_for_each_entry_rcu(rdev, &cfg80211_rdev_list, list) {
Johannes Berg78f22b62014-03-24 17:57:27 +010013634 bool schedule_destroy_work = false;
Jukka Rissanen93a1e862014-12-15 13:25:39 +020013635 bool schedule_scan_stop = false;
13636 struct cfg80211_sched_scan_request *sched_scan_req =
13637 rcu_dereference(rdev->sched_scan_req);
13638
13639 if (sched_scan_req && notify->portid &&
13640 sched_scan_req->owner_nlportid == notify->portid)
13641 schedule_scan_stop = true;
Johannes Berg78f22b62014-03-24 17:57:27 +010013642
Johannes Berg53873f12016-05-03 16:52:04 +030013643 list_for_each_entry_rcu(wdev, &rdev->wiphy.wdev_list, list) {
Eric W. Biederman15e47302012-09-07 20:12:54 +000013644 cfg80211_mlme_unregister_socket(wdev, notify->portid);
Ben Greear37c73b52012-10-26 14:49:25 -070013645
Johannes Berg78f22b62014-03-24 17:57:27 +010013646 if (wdev->owner_nlportid == notify->portid)
13647 schedule_destroy_work = true;
13648 }
13649
Ben Greear37c73b52012-10-26 14:49:25 -070013650 spin_lock_bh(&rdev->beacon_registrations_lock);
13651 list_for_each_entry_safe(reg, tmp, &rdev->beacon_registrations,
13652 list) {
13653 if (reg->nlportid == notify->portid) {
13654 list_del(&reg->list);
13655 kfree(reg);
13656 break;
13657 }
13658 }
13659 spin_unlock_bh(&rdev->beacon_registrations_lock);
Johannes Berg78f22b62014-03-24 17:57:27 +010013660
13661 if (schedule_destroy_work) {
13662 struct cfg80211_iface_destroy *destroy;
13663
13664 destroy = kzalloc(sizeof(*destroy), GFP_ATOMIC);
13665 if (destroy) {
13666 destroy->nlportid = notify->portid;
13667 spin_lock(&rdev->destroy_list_lock);
13668 list_add(&destroy->list, &rdev->destroy_list);
13669 spin_unlock(&rdev->destroy_list_lock);
13670 schedule_work(&rdev->destroy_work);
13671 }
Jukka Rissanen93a1e862014-12-15 13:25:39 +020013672 } else if (schedule_scan_stop) {
13673 sched_scan_req->owner_nlportid = 0;
13674
13675 if (rdev->ops->sched_scan_stop &&
13676 rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN)
13677 schedule_work(&rdev->sched_scan_stop_wk);
Johannes Berg78f22b62014-03-24 17:57:27 +010013678 }
Johannes Berg5e7602302011-11-04 11:18:17 +010013679 }
Jouni Malinen026331c2010-02-15 12:53:10 +020013680
13681 rcu_read_unlock();
13682
Ilan peer05050752015-03-04 00:32:06 -050013683 /*
13684 * It is possible that the user space process that is controlling the
13685 * indoor setting disappeared, so notify the regulatory core.
13686 */
13687 regulatory_netlink_notify(notify->portid);
Zhao, Gang6784c7d2014-04-21 12:53:04 +080013688 return NOTIFY_OK;
Jouni Malinen026331c2010-02-15 12:53:10 +020013689}
13690
13691static struct notifier_block nl80211_netlink_notifier = {
13692 .notifier_call = nl80211_netlink_notify,
13693};
13694
Jouni Malinen355199e2013-02-27 17:14:27 +020013695void cfg80211_ft_event(struct net_device *netdev,
13696 struct cfg80211_ft_event_params *ft_event)
13697{
13698 struct wiphy *wiphy = netdev->ieee80211_ptr->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080013699 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Jouni Malinen355199e2013-02-27 17:14:27 +020013700 struct sk_buff *msg;
13701 void *hdr;
Jouni Malinen355199e2013-02-27 17:14:27 +020013702
13703 trace_cfg80211_ft_event(wiphy, netdev, ft_event);
13704
13705 if (!ft_event->target_ap)
13706 return;
13707
13708 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
13709 if (!msg)
13710 return;
13711
13712 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FT_EVENT);
Johannes Bergae917c92013-10-25 11:05:22 +020013713 if (!hdr)
13714 goto out;
Jouni Malinen355199e2013-02-27 17:14:27 +020013715
Johannes Bergae917c92013-10-25 11:05:22 +020013716 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
13717 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
13718 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, ft_event->target_ap))
13719 goto out;
13720
13721 if (ft_event->ies &&
13722 nla_put(msg, NL80211_ATTR_IE, ft_event->ies_len, ft_event->ies))
13723 goto out;
13724 if (ft_event->ric_ies &&
13725 nla_put(msg, NL80211_ATTR_IE_RIC, ft_event->ric_ies_len,
13726 ft_event->ric_ies))
13727 goto out;
Jouni Malinen355199e2013-02-27 17:14:27 +020013728
Johannes Berg9c90a9f2013-06-04 12:46:03 +020013729 genlmsg_end(msg, hdr);
Jouni Malinen355199e2013-02-27 17:14:27 +020013730
Johannes Berg68eb5502013-11-19 15:19:38 +010013731 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010013732 NL80211_MCGRP_MLME, GFP_KERNEL);
Johannes Bergae917c92013-10-25 11:05:22 +020013733 return;
13734 out:
13735 nlmsg_free(msg);
Jouni Malinen355199e2013-02-27 17:14:27 +020013736}
13737EXPORT_SYMBOL(cfg80211_ft_event);
13738
Arend van Spriel5de17982013-04-18 15:49:00 +020013739void cfg80211_crit_proto_stopped(struct wireless_dev *wdev, gfp_t gfp)
13740{
13741 struct cfg80211_registered_device *rdev;
13742 struct sk_buff *msg;
13743 void *hdr;
13744 u32 nlportid;
13745
Zhao, Gangf26cbf42014-04-21 12:53:03 +080013746 rdev = wiphy_to_rdev(wdev->wiphy);
Arend van Spriel5de17982013-04-18 15:49:00 +020013747 if (!rdev->crit_proto_nlportid)
13748 return;
13749
13750 nlportid = rdev->crit_proto_nlportid;
13751 rdev->crit_proto_nlportid = 0;
13752
13753 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
13754 if (!msg)
13755 return;
13756
13757 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CRIT_PROTOCOL_STOP);
13758 if (!hdr)
13759 goto nla_put_failure;
13760
13761 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020013762 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
13763 NL80211_ATTR_PAD))
Arend van Spriel5de17982013-04-18 15:49:00 +020013764 goto nla_put_failure;
13765
13766 genlmsg_end(msg, hdr);
13767
13768 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid);
13769 return;
13770
13771 nla_put_failure:
13772 if (hdr)
13773 genlmsg_cancel(msg, hdr);
13774 nlmsg_free(msg);
Arend van Spriel5de17982013-04-18 15:49:00 +020013775}
13776EXPORT_SYMBOL(cfg80211_crit_proto_stopped);
13777
Johannes Berg348baf02014-01-24 14:06:29 +010013778void nl80211_send_ap_stopped(struct wireless_dev *wdev)
13779{
13780 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080013781 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg348baf02014-01-24 14:06:29 +010013782 struct sk_buff *msg;
13783 void *hdr;
13784
13785 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
13786 if (!msg)
13787 return;
13788
13789 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_STOP_AP);
13790 if (!hdr)
13791 goto out;
13792
13793 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
13794 nla_put_u32(msg, NL80211_ATTR_IFINDEX, wdev->netdev->ifindex) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020013795 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
13796 NL80211_ATTR_PAD))
Johannes Berg348baf02014-01-24 14:06:29 +010013797 goto out;
13798
13799 genlmsg_end(msg, hdr);
13800
13801 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(wiphy), msg, 0,
13802 NL80211_MCGRP_MLME, GFP_KERNEL);
13803 return;
13804 out:
13805 nlmsg_free(msg);
13806}
13807
Johannes Berg55682962007-09-20 13:09:35 -040013808/* initialisation/exit functions */
13809
13810int nl80211_init(void)
13811{
Michał Mirosław0d63cbb2009-05-21 10:34:06 +000013812 int err;
Johannes Berg55682962007-09-20 13:09:35 -040013813
Johannes Berg2a94fe42013-11-19 15:19:39 +010013814 err = genl_register_family_with_ops_groups(&nl80211_fam, nl80211_ops,
13815 nl80211_mcgrps);
Johannes Berg55682962007-09-20 13:09:35 -040013816 if (err)
13817 return err;
13818
Jouni Malinen026331c2010-02-15 12:53:10 +020013819 err = netlink_register_notifier(&nl80211_netlink_notifier);
13820 if (err)
13821 goto err_out;
13822
Johannes Berg55682962007-09-20 13:09:35 -040013823 return 0;
13824 err_out:
13825 genl_unregister_family(&nl80211_fam);
13826 return err;
13827}
13828
13829void nl80211_exit(void)
13830{
Jouni Malinen026331c2010-02-15 12:53:10 +020013831 netlink_unregister_notifier(&nl80211_netlink_notifier);
Johannes Berg55682962007-09-20 13:09:35 -040013832 genl_unregister_family(&nl80211_fam);
13833}