blob: 499785778983d89baa1b99459971588ce10a23bb [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];
Johannes Bergf5ea9122009-08-07 16:17:38 +02002528 struct cfg80211_registered_device *rdev;
Johannes Berg55682962007-09-20 13:09:35 -04002529 struct wireless_dev *wdev;
2530
Johannes Berg5fe231e2013-05-08 21:45:15 +02002531 rtnl_lock();
Johannes Bergf5ea9122009-08-07 16:17:38 +02002532 list_for_each_entry(rdev, &cfg80211_rdev_list, list) {
2533 if (!net_eq(wiphy_net(&rdev->wiphy), sock_net(skb->sk)))
Johannes Berg463d0182009-07-14 00:33:35 +02002534 continue;
Johannes Bergbba95fe2008-07-29 13:22:51 +02002535 if (wp_idx < wp_start) {
2536 wp_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04002537 continue;
Johannes Bergbba95fe2008-07-29 13:22:51 +02002538 }
Johannes Berg55682962007-09-20 13:09:35 -04002539 if_idx = 0;
2540
Johannes Berg53873f12016-05-03 16:52:04 +03002541 list_for_each_entry(wdev, &rdev->wiphy.wdev_list, list) {
Johannes Bergbba95fe2008-07-29 13:22:51 +02002542 if (if_idx < if_start) {
2543 if_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04002544 continue;
Johannes Bergbba95fe2008-07-29 13:22:51 +02002545 }
Eric W. Biederman15e47302012-09-07 20:12:54 +00002546 if (nl80211_send_iface(skb, NETLINK_CB(cb->skb).portid,
Johannes Berg55682962007-09-20 13:09:35 -04002547 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Tomasz Bursztyka8f894be2014-11-12 16:26:45 +02002548 rdev, wdev, false) < 0) {
Johannes Bergbba95fe2008-07-29 13:22:51 +02002549 goto out;
2550 }
2551 if_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04002552 }
Johannes Bergbba95fe2008-07-29 13:22:51 +02002553
2554 wp_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04002555 }
Johannes Bergbba95fe2008-07-29 13:22:51 +02002556 out:
Johannes Berg5fe231e2013-05-08 21:45:15 +02002557 rtnl_unlock();
Johannes Berg55682962007-09-20 13:09:35 -04002558
2559 cb->args[0] = wp_idx;
2560 cb->args[1] = if_idx;
2561
2562 return skb->len;
2563}
2564
2565static int nl80211_get_interface(struct sk_buff *skb, struct genl_info *info)
2566{
2567 struct sk_buff *msg;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002568 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002569 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg55682962007-09-20 13:09:35 -04002570
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07002571 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -04002572 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02002573 return -ENOMEM;
Johannes Berg55682962007-09-20 13:09:35 -04002574
Eric W. Biederman15e47302012-09-07 20:12:54 +00002575 if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0,
Tomasz Bursztyka8f894be2014-11-12 16:26:45 +02002576 rdev, wdev, false) < 0) {
Johannes Berg4c476992010-10-04 21:36:35 +02002577 nlmsg_free(msg);
2578 return -ENOBUFS;
2579 }
Johannes Berg55682962007-09-20 13:09:35 -04002580
Johannes Berg134e6372009-07-10 09:51:34 +00002581 return genlmsg_reply(msg, info);
Johannes Berg55682962007-09-20 13:09:35 -04002582}
2583
Michael Wu66f7ac52008-01-31 19:48:22 +01002584static const struct nla_policy mntr_flags_policy[NL80211_MNTR_FLAG_MAX + 1] = {
2585 [NL80211_MNTR_FLAG_FCSFAIL] = { .type = NLA_FLAG },
2586 [NL80211_MNTR_FLAG_PLCPFAIL] = { .type = NLA_FLAG },
2587 [NL80211_MNTR_FLAG_CONTROL] = { .type = NLA_FLAG },
2588 [NL80211_MNTR_FLAG_OTHER_BSS] = { .type = NLA_FLAG },
2589 [NL80211_MNTR_FLAG_COOK_FRAMES] = { .type = NLA_FLAG },
Felix Fietkaue057d3c2013-05-28 13:01:52 +02002590 [NL80211_MNTR_FLAG_ACTIVE] = { .type = NLA_FLAG },
Michael Wu66f7ac52008-01-31 19:48:22 +01002591};
2592
2593static int parse_monitor_flags(struct nlattr *nla, u32 *mntrflags)
2594{
2595 struct nlattr *flags[NL80211_MNTR_FLAG_MAX + 1];
2596 int flag;
2597
2598 *mntrflags = 0;
2599
2600 if (!nla)
2601 return -EINVAL;
2602
2603 if (nla_parse_nested(flags, NL80211_MNTR_FLAG_MAX,
2604 nla, mntr_flags_policy))
2605 return -EINVAL;
2606
2607 for (flag = 1; flag <= NL80211_MNTR_FLAG_MAX; flag++)
2608 if (flags[flag])
2609 *mntrflags |= (1<<flag);
2610
2611 return 0;
2612}
2613
Johannes Berg9bc383d2009-11-19 11:55:19 +01002614static int nl80211_valid_4addr(struct cfg80211_registered_device *rdev,
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002615 struct net_device *netdev, u8 use_4addr,
2616 enum nl80211_iftype iftype)
Johannes Berg9bc383d2009-11-19 11:55:19 +01002617{
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002618 if (!use_4addr) {
Jiri Pirkof350a0a82010-06-15 06:50:45 +00002619 if (netdev && (netdev->priv_flags & IFF_BRIDGE_PORT))
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002620 return -EBUSY;
Johannes Berg9bc383d2009-11-19 11:55:19 +01002621 return 0;
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002622 }
Johannes Berg9bc383d2009-11-19 11:55:19 +01002623
2624 switch (iftype) {
2625 case NL80211_IFTYPE_AP_VLAN:
2626 if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_AP)
2627 return 0;
2628 break;
2629 case NL80211_IFTYPE_STATION:
2630 if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_STATION)
2631 return 0;
2632 break;
2633 default:
2634 break;
2635 }
2636
2637 return -EOPNOTSUPP;
2638}
2639
Johannes Berg55682962007-09-20 13:09:35 -04002640static int nl80211_set_interface(struct sk_buff *skb, struct genl_info *info)
2641{
Johannes Berg4c476992010-10-04 21:36:35 +02002642 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002643 struct vif_params params;
Johannes Berge36d56b2009-06-09 21:04:43 +02002644 int err;
Johannes Berg04a773a2009-04-19 21:24:32 +02002645 enum nl80211_iftype otype, ntype;
Johannes Berg4c476992010-10-04 21:36:35 +02002646 struct net_device *dev = info->user_ptr[1];
Johannes Berg92ffe052008-09-16 20:39:36 +02002647 u32 _flags, *flags = NULL;
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002648 bool change = false;
Johannes Berg55682962007-09-20 13:09:35 -04002649
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002650 memset(&params, 0, sizeof(params));
2651
Johannes Berg04a773a2009-04-19 21:24:32 +02002652 otype = ntype = dev->ieee80211_ptr->iftype;
Johannes Berg55682962007-09-20 13:09:35 -04002653
Johannes Berg723b0382008-09-16 20:22:09 +02002654 if (info->attrs[NL80211_ATTR_IFTYPE]) {
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002655 ntype = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]);
Johannes Berg04a773a2009-04-19 21:24:32 +02002656 if (otype != ntype)
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002657 change = true;
Johannes Berg4c476992010-10-04 21:36:35 +02002658 if (ntype > NL80211_IFTYPE_MAX)
2659 return -EINVAL;
Johannes Berg723b0382008-09-16 20:22:09 +02002660 }
2661
Johannes Berg92ffe052008-09-16 20:39:36 +02002662 if (info->attrs[NL80211_ATTR_MESH_ID]) {
Johannes Berg29cbe682010-12-03 09:20:44 +01002663 struct wireless_dev *wdev = dev->ieee80211_ptr;
2664
Johannes Berg4c476992010-10-04 21:36:35 +02002665 if (ntype != NL80211_IFTYPE_MESH_POINT)
2666 return -EINVAL;
Johannes Berg29cbe682010-12-03 09:20:44 +01002667 if (netif_running(dev))
2668 return -EBUSY;
2669
2670 wdev_lock(wdev);
2671 BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN !=
2672 IEEE80211_MAX_MESH_ID_LEN);
2673 wdev->mesh_id_up_len =
2674 nla_len(info->attrs[NL80211_ATTR_MESH_ID]);
2675 memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]),
2676 wdev->mesh_id_up_len);
2677 wdev_unlock(wdev);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002678 }
2679
Felix Fietkau8b787642009-11-10 18:53:10 +01002680 if (info->attrs[NL80211_ATTR_4ADDR]) {
2681 params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]);
2682 change = true;
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002683 err = nl80211_valid_4addr(rdev, dev, params.use_4addr, ntype);
Johannes Berg9bc383d2009-11-19 11:55:19 +01002684 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02002685 return err;
Felix Fietkau8b787642009-11-10 18:53:10 +01002686 } else {
2687 params.use_4addr = -1;
2688 }
2689
Johannes Berg92ffe052008-09-16 20:39:36 +02002690 if (info->attrs[NL80211_ATTR_MNTR_FLAGS]) {
Johannes Berg4c476992010-10-04 21:36:35 +02002691 if (ntype != NL80211_IFTYPE_MONITOR)
2692 return -EINVAL;
Johannes Berg92ffe052008-09-16 20:39:36 +02002693 err = parse_monitor_flags(info->attrs[NL80211_ATTR_MNTR_FLAGS],
2694 &_flags);
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002695 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02002696 return err;
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002697
2698 flags = &_flags;
2699 change = true;
Johannes Berg92ffe052008-09-16 20:39:36 +02002700 }
Johannes Berg3b858752009-03-12 09:55:09 +01002701
Aviya Erenfeldc6e6a0c2016-07-05 15:23:08 +03002702 if (info->attrs[NL80211_ATTR_MU_MIMO_GROUP_DATA]) {
2703 const u8 *mumimo_groups;
2704 u32 cap_flag = NL80211_EXT_FEATURE_MU_MIMO_AIR_SNIFFER;
2705
2706 if (!wiphy_ext_feature_isset(&rdev->wiphy, cap_flag))
2707 return -EOPNOTSUPP;
2708
2709 mumimo_groups =
2710 nla_data(info->attrs[NL80211_ATTR_MU_MIMO_GROUP_DATA]);
2711
2712 /* bits 0 and 63 are reserved and must be zero */
2713 if ((mumimo_groups[0] & BIT(7)) ||
2714 (mumimo_groups[VHT_MUMIMO_GROUPS_DATA_LEN - 1] & BIT(0)))
2715 return -EINVAL;
2716
2717 memcpy(params.vht_mumimo_groups, mumimo_groups,
2718 VHT_MUMIMO_GROUPS_DATA_LEN);
2719 change = true;
2720 }
2721
2722 if (info->attrs[NL80211_ATTR_MU_MIMO_FOLLOW_MAC_ADDR]) {
2723 u32 cap_flag = NL80211_EXT_FEATURE_MU_MIMO_AIR_SNIFFER;
2724
2725 if (!wiphy_ext_feature_isset(&rdev->wiphy, cap_flag))
2726 return -EOPNOTSUPP;
2727
2728 nla_memcpy(params.macaddr,
2729 info->attrs[NL80211_ATTR_MU_MIMO_FOLLOW_MAC_ADDR],
2730 ETH_ALEN);
2731 change = true;
2732 }
2733
Luciano Coelho18003292013-08-29 13:26:57 +03002734 if (flags && (*flags & MONITOR_FLAG_ACTIVE) &&
Felix Fietkaue057d3c2013-05-28 13:01:52 +02002735 !(rdev->wiphy.features & NL80211_FEATURE_ACTIVE_MONITOR))
2736 return -EOPNOTSUPP;
2737
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002738 if (change)
Johannes Berg3d54d252009-08-21 14:51:05 +02002739 err = cfg80211_change_iface(rdev, dev, ntype, flags, &params);
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002740 else
2741 err = 0;
Johannes Berg60719ff2008-09-16 14:55:09 +02002742
Johannes Berg9bc383d2009-11-19 11:55:19 +01002743 if (!err && params.use_4addr != -1)
2744 dev->ieee80211_ptr->use_4addr = params.use_4addr;
2745
Johannes Berg55682962007-09-20 13:09:35 -04002746 return err;
2747}
2748
2749static int nl80211_new_interface(struct sk_buff *skb, struct genl_info *info)
2750{
Johannes Berg4c476992010-10-04 21:36:35 +02002751 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002752 struct vif_params params;
Johannes Berg84efbb82012-06-16 00:00:26 +02002753 struct wireless_dev *wdev;
Denis Kenzior896ff062016-08-03 16:58:33 -05002754 struct sk_buff *msg;
Johannes Berg55682962007-09-20 13:09:35 -04002755 int err;
2756 enum nl80211_iftype type = NL80211_IFTYPE_UNSPECIFIED;
Michael Wu66f7ac52008-01-31 19:48:22 +01002757 u32 flags;
Johannes Berg55682962007-09-20 13:09:35 -04002758
Johannes Berg78f22b62014-03-24 17:57:27 +01002759 /* to avoid failing a new interface creation due to pending removal */
2760 cfg80211_destroy_ifaces(rdev);
2761
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002762 memset(&params, 0, sizeof(params));
2763
Johannes Berg55682962007-09-20 13:09:35 -04002764 if (!info->attrs[NL80211_ATTR_IFNAME])
2765 return -EINVAL;
2766
2767 if (info->attrs[NL80211_ATTR_IFTYPE]) {
2768 type = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]);
2769 if (type > NL80211_IFTYPE_MAX)
2770 return -EINVAL;
2771 }
2772
Johannes Berg79c97e92009-07-07 03:56:12 +02002773 if (!rdev->ops->add_virtual_intf ||
Johannes Berg4c476992010-10-04 21:36:35 +02002774 !(rdev->wiphy.interface_modes & (1 << type)))
2775 return -EOPNOTSUPP;
Johannes Berg55682962007-09-20 13:09:35 -04002776
Ben Greeare8f479b2014-10-22 12:23:05 -07002777 if ((type == NL80211_IFTYPE_P2P_DEVICE ||
2778 rdev->wiphy.features & NL80211_FEATURE_MAC_ON_CREATE) &&
2779 info->attrs[NL80211_ATTR_MAC]) {
Arend van Spriel1c18f142013-01-08 10:17:27 +01002780 nla_memcpy(params.macaddr, info->attrs[NL80211_ATTR_MAC],
2781 ETH_ALEN);
2782 if (!is_valid_ether_addr(params.macaddr))
2783 return -EADDRNOTAVAIL;
2784 }
2785
Johannes Berg9bc383d2009-11-19 11:55:19 +01002786 if (info->attrs[NL80211_ATTR_4ADDR]) {
Felix Fietkau8b787642009-11-10 18:53:10 +01002787 params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]);
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002788 err = nl80211_valid_4addr(rdev, NULL, params.use_4addr, type);
Johannes Berg9bc383d2009-11-19 11:55:19 +01002789 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02002790 return err;
Johannes Berg9bc383d2009-11-19 11:55:19 +01002791 }
Felix Fietkau8b787642009-11-10 18:53:10 +01002792
Michael Wu66f7ac52008-01-31 19:48:22 +01002793 err = parse_monitor_flags(type == NL80211_IFTYPE_MONITOR ?
2794 info->attrs[NL80211_ATTR_MNTR_FLAGS] : NULL,
2795 &flags);
Felix Fietkaue057d3c2013-05-28 13:01:52 +02002796
Luciano Coelho18003292013-08-29 13:26:57 +03002797 if (!err && (flags & MONITOR_FLAG_ACTIVE) &&
Felix Fietkaue057d3c2013-05-28 13:01:52 +02002798 !(rdev->wiphy.features & NL80211_FEATURE_ACTIVE_MONITOR))
2799 return -EOPNOTSUPP;
2800
Johannes Berga18c7192015-02-24 10:56:42 +01002801 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
2802 if (!msg)
2803 return -ENOMEM;
2804
Hila Gonene35e4d22012-06-27 17:19:42 +03002805 wdev = rdev_add_virtual_intf(rdev,
2806 nla_data(info->attrs[NL80211_ATTR_IFNAME]),
Tom Gundersen6bab2e192015-03-18 11:13:39 +01002807 NET_NAME_USER, type, err ? NULL : &flags,
2808 &params);
Rafał Miłeckid687cbb2014-11-14 18:43:28 +01002809 if (WARN_ON(!wdev)) {
2810 nlmsg_free(msg);
2811 return -EPROTO;
2812 } else if (IS_ERR(wdev)) {
Johannes Berg1c90f9d2012-06-16 00:05:37 +02002813 nlmsg_free(msg);
Johannes Berg84efbb82012-06-16 00:00:26 +02002814 return PTR_ERR(wdev);
Johannes Berg1c90f9d2012-06-16 00:05:37 +02002815 }
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002816
Jukka Rissanen18e5ca62014-11-13 17:25:14 +02002817 if (info->attrs[NL80211_ATTR_SOCKET_OWNER])
Johannes Berg78f22b62014-03-24 17:57:27 +01002818 wdev->owner_nlportid = info->snd_portid;
2819
Johannes Berg98104fde2012-06-16 00:19:54 +02002820 switch (type) {
2821 case NL80211_IFTYPE_MESH_POINT:
2822 if (!info->attrs[NL80211_ATTR_MESH_ID])
2823 break;
Johannes Berg29cbe682010-12-03 09:20:44 +01002824 wdev_lock(wdev);
2825 BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN !=
2826 IEEE80211_MAX_MESH_ID_LEN);
2827 wdev->mesh_id_up_len =
2828 nla_len(info->attrs[NL80211_ATTR_MESH_ID]);
2829 memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]),
2830 wdev->mesh_id_up_len);
2831 wdev_unlock(wdev);
Johannes Berg98104fde2012-06-16 00:19:54 +02002832 break;
2833 case NL80211_IFTYPE_P2P_DEVICE:
2834 /*
2835 * P2P Device doesn't have a netdev, so doesn't go
2836 * through the netdev notifier and must be added here
2837 */
2838 mutex_init(&wdev->mtx);
2839 INIT_LIST_HEAD(&wdev->event_list);
2840 spin_lock_init(&wdev->event_lock);
2841 INIT_LIST_HEAD(&wdev->mgmt_registrations);
2842 spin_lock_init(&wdev->mgmt_registrations_lock);
2843
Johannes Berg98104fde2012-06-16 00:19:54 +02002844 wdev->identifier = ++rdev->wdev_id;
Johannes Berg53873f12016-05-03 16:52:04 +03002845 list_add_rcu(&wdev->list, &rdev->wiphy.wdev_list);
Johannes Berg98104fde2012-06-16 00:19:54 +02002846 rdev->devlist_generation++;
Johannes Berg98104fde2012-06-16 00:19:54 +02002847 break;
2848 default:
2849 break;
Johannes Berg29cbe682010-12-03 09:20:44 +01002850 }
2851
Eric W. Biederman15e47302012-09-07 20:12:54 +00002852 if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0,
Tomasz Bursztyka8f894be2014-11-12 16:26:45 +02002853 rdev, wdev, false) < 0) {
Johannes Berg1c90f9d2012-06-16 00:05:37 +02002854 nlmsg_free(msg);
2855 return -ENOBUFS;
2856 }
2857
Denis Kenzior896ff062016-08-03 16:58:33 -05002858 /*
2859 * For wdevs which have no associated netdev object (e.g. of type
2860 * NL80211_IFTYPE_P2P_DEVICE), emit the NEW_INTERFACE event here.
2861 * For all other types, the event will be generated from the
2862 * netdev notifier
2863 */
2864 if (!wdev->netdev)
2865 nl80211_notify_iface(rdev, wdev, NL80211_CMD_NEW_INTERFACE);
Tomasz Bursztyka8f894be2014-11-12 16:26:45 +02002866
Johannes Berg1c90f9d2012-06-16 00:05:37 +02002867 return genlmsg_reply(msg, info);
Johannes Berg55682962007-09-20 13:09:35 -04002868}
2869
2870static int nl80211_del_interface(struct sk_buff *skb, struct genl_info *info)
2871{
Johannes Berg4c476992010-10-04 21:36:35 +02002872 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg84efbb82012-06-16 00:00:26 +02002873 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg55682962007-09-20 13:09:35 -04002874
Johannes Berg4c476992010-10-04 21:36:35 +02002875 if (!rdev->ops->del_virtual_intf)
2876 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01002877
Johannes Berg84efbb82012-06-16 00:00:26 +02002878 /*
2879 * If we remove a wireless device without a netdev then clear
2880 * user_ptr[1] so that nl80211_post_doit won't dereference it
2881 * to check if it needs to do dev_put(). Otherwise it crashes
2882 * since the wdev has been freed, unlike with a netdev where
2883 * we need the dev_put() for the netdev to really be freed.
2884 */
2885 if (!wdev->netdev)
2886 info->user_ptr[1] = NULL;
2887
Denis Kenzior7f8ed012016-08-03 16:58:35 -05002888 return rdev_del_virtual_intf(rdev, wdev);
Johannes Berg55682962007-09-20 13:09:35 -04002889}
2890
Simon Wunderlich1d9d9212011-11-18 14:20:43 +01002891static int nl80211_set_noack_map(struct sk_buff *skb, struct genl_info *info)
2892{
2893 struct cfg80211_registered_device *rdev = info->user_ptr[0];
2894 struct net_device *dev = info->user_ptr[1];
2895 u16 noack_map;
2896
2897 if (!info->attrs[NL80211_ATTR_NOACK_MAP])
2898 return -EINVAL;
2899
2900 if (!rdev->ops->set_noack_map)
2901 return -EOPNOTSUPP;
2902
2903 noack_map = nla_get_u16(info->attrs[NL80211_ATTR_NOACK_MAP]);
2904
Hila Gonene35e4d22012-06-27 17:19:42 +03002905 return rdev_set_noack_map(rdev, dev, noack_map);
Simon Wunderlich1d9d9212011-11-18 14:20:43 +01002906}
2907
Johannes Berg41ade002007-12-19 02:03:29 +01002908struct get_key_cookie {
2909 struct sk_buff *msg;
2910 int error;
Johannes Bergb9454e82009-07-08 13:29:08 +02002911 int idx;
Johannes Berg41ade002007-12-19 02:03:29 +01002912};
2913
2914static void get_key_callback(void *c, struct key_params *params)
2915{
Johannes Bergb9454e82009-07-08 13:29:08 +02002916 struct nlattr *key;
Johannes Berg41ade002007-12-19 02:03:29 +01002917 struct get_key_cookie *cookie = c;
2918
David S. Miller9360ffd2012-03-29 04:41:26 -04002919 if ((params->key &&
2920 nla_put(cookie->msg, NL80211_ATTR_KEY_DATA,
2921 params->key_len, params->key)) ||
2922 (params->seq &&
2923 nla_put(cookie->msg, NL80211_ATTR_KEY_SEQ,
2924 params->seq_len, params->seq)) ||
2925 (params->cipher &&
2926 nla_put_u32(cookie->msg, NL80211_ATTR_KEY_CIPHER,
2927 params->cipher)))
2928 goto nla_put_failure;
Johannes Berg41ade002007-12-19 02:03:29 +01002929
Johannes Bergb9454e82009-07-08 13:29:08 +02002930 key = nla_nest_start(cookie->msg, NL80211_ATTR_KEY);
2931 if (!key)
2932 goto nla_put_failure;
2933
David S. Miller9360ffd2012-03-29 04:41:26 -04002934 if ((params->key &&
2935 nla_put(cookie->msg, NL80211_KEY_DATA,
2936 params->key_len, params->key)) ||
2937 (params->seq &&
2938 nla_put(cookie->msg, NL80211_KEY_SEQ,
2939 params->seq_len, params->seq)) ||
2940 (params->cipher &&
2941 nla_put_u32(cookie->msg, NL80211_KEY_CIPHER,
2942 params->cipher)))
2943 goto nla_put_failure;
Johannes Bergb9454e82009-07-08 13:29:08 +02002944
David S. Miller9360ffd2012-03-29 04:41:26 -04002945 if (nla_put_u8(cookie->msg, NL80211_ATTR_KEY_IDX, cookie->idx))
2946 goto nla_put_failure;
Johannes Bergb9454e82009-07-08 13:29:08 +02002947
2948 nla_nest_end(cookie->msg, key);
2949
Johannes Berg41ade002007-12-19 02:03:29 +01002950 return;
2951 nla_put_failure:
2952 cookie->error = 1;
2953}
2954
2955static int nl80211_get_key(struct sk_buff *skb, struct genl_info *info)
2956{
Johannes Berg4c476992010-10-04 21:36:35 +02002957 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg41ade002007-12-19 02:03:29 +01002958 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02002959 struct net_device *dev = info->user_ptr[1];
Johannes Berg41ade002007-12-19 02:03:29 +01002960 u8 key_idx = 0;
Johannes Berge31b8212010-10-05 19:39:30 +02002961 const u8 *mac_addr = NULL;
2962 bool pairwise;
Johannes Berg41ade002007-12-19 02:03:29 +01002963 struct get_key_cookie cookie = {
2964 .error = 0,
2965 };
2966 void *hdr;
2967 struct sk_buff *msg;
2968
2969 if (info->attrs[NL80211_ATTR_KEY_IDX])
2970 key_idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]);
2971
Jouni Malinen3cfcf6ac2009-01-08 13:32:02 +02002972 if (key_idx > 5)
Johannes Berg41ade002007-12-19 02:03:29 +01002973 return -EINVAL;
2974
2975 if (info->attrs[NL80211_ATTR_MAC])
2976 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
2977
Johannes Berge31b8212010-10-05 19:39:30 +02002978 pairwise = !!mac_addr;
2979 if (info->attrs[NL80211_ATTR_KEY_TYPE]) {
2980 u32 kt = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]);
Kirtika Ruchandani7a087e72016-05-29 19:51:23 -07002981
Johannes Berge31b8212010-10-05 19:39:30 +02002982 if (kt >= NUM_NL80211_KEYTYPES)
2983 return -EINVAL;
2984 if (kt != NL80211_KEYTYPE_GROUP &&
2985 kt != NL80211_KEYTYPE_PAIRWISE)
2986 return -EINVAL;
2987 pairwise = kt == NL80211_KEYTYPE_PAIRWISE;
2988 }
2989
Johannes Berg4c476992010-10-04 21:36:35 +02002990 if (!rdev->ops->get_key)
2991 return -EOPNOTSUPP;
Johannes Berg41ade002007-12-19 02:03:29 +01002992
Johannes Berg0fa7b392015-01-23 11:10:12 +01002993 if (!pairwise && mac_addr && !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN))
2994 return -ENOENT;
2995
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07002996 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02002997 if (!msg)
2998 return -ENOMEM;
Johannes Berg41ade002007-12-19 02:03:29 +01002999
Eric W. Biederman15e47302012-09-07 20:12:54 +00003000 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berg41ade002007-12-19 02:03:29 +01003001 NL80211_CMD_NEW_KEY);
Dan Carpentercb35fba2013-08-14 14:50:01 +03003002 if (!hdr)
Johannes Berg9fe271a2013-10-25 11:15:12 +02003003 goto nla_put_failure;
Johannes Berg41ade002007-12-19 02:03:29 +01003004
3005 cookie.msg = msg;
Johannes Bergb9454e82009-07-08 13:29:08 +02003006 cookie.idx = key_idx;
Johannes Berg41ade002007-12-19 02:03:29 +01003007
David S. Miller9360ffd2012-03-29 04:41:26 -04003008 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
3009 nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_idx))
3010 goto nla_put_failure;
3011 if (mac_addr &&
3012 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr))
3013 goto nla_put_failure;
Johannes Berg41ade002007-12-19 02:03:29 +01003014
Hila Gonene35e4d22012-06-27 17:19:42 +03003015 err = rdev_get_key(rdev, dev, key_idx, pairwise, mac_addr, &cookie,
3016 get_key_callback);
Johannes Berg41ade002007-12-19 02:03:29 +01003017
3018 if (err)
Niko Jokinen6c95e2a2009-07-15 11:00:53 +03003019 goto free_msg;
Johannes Berg41ade002007-12-19 02:03:29 +01003020
3021 if (cookie.error)
3022 goto nla_put_failure;
3023
3024 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02003025 return genlmsg_reply(msg, info);
Johannes Berg41ade002007-12-19 02:03:29 +01003026
3027 nla_put_failure:
3028 err = -ENOBUFS;
Niko Jokinen6c95e2a2009-07-15 11:00:53 +03003029 free_msg:
Johannes Berg41ade002007-12-19 02:03:29 +01003030 nlmsg_free(msg);
Johannes Berg41ade002007-12-19 02:03:29 +01003031 return err;
3032}
3033
3034static int nl80211_set_key(struct sk_buff *skb, struct genl_info *info)
3035{
Johannes Berg4c476992010-10-04 21:36:35 +02003036 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Bergb9454e82009-07-08 13:29:08 +02003037 struct key_parse key;
Johannes Berg41ade002007-12-19 02:03:29 +01003038 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02003039 struct net_device *dev = info->user_ptr[1];
Johannes Berg41ade002007-12-19 02:03:29 +01003040
Johannes Bergb9454e82009-07-08 13:29:08 +02003041 err = nl80211_parse_key(info, &key);
3042 if (err)
3043 return err;
3044
3045 if (key.idx < 0)
Johannes Berg41ade002007-12-19 02:03:29 +01003046 return -EINVAL;
3047
Johannes Bergb9454e82009-07-08 13:29:08 +02003048 /* only support setting default key */
3049 if (!key.def && !key.defmgmt)
Johannes Berg41ade002007-12-19 02:03:29 +01003050 return -EINVAL;
3051
Johannes Bergfffd0932009-07-08 14:22:54 +02003052 wdev_lock(dev->ieee80211_ptr);
Johannes Bergdbd2fd62010-12-09 19:58:59 +01003053
3054 if (key.def) {
3055 if (!rdev->ops->set_default_key) {
3056 err = -EOPNOTSUPP;
3057 goto out;
3058 }
3059
3060 err = nl80211_key_allowed(dev->ieee80211_ptr);
3061 if (err)
3062 goto out;
3063
Hila Gonene35e4d22012-06-27 17:19:42 +03003064 err = rdev_set_default_key(rdev, dev, key.idx,
Johannes Bergdbd2fd62010-12-09 19:58:59 +01003065 key.def_uni, key.def_multi);
3066
3067 if (err)
3068 goto out;
Johannes Bergfffd0932009-07-08 14:22:54 +02003069
Johannes Berg3d23e342009-09-29 23:27:28 +02003070#ifdef CONFIG_CFG80211_WEXT
Johannes Bergdbd2fd62010-12-09 19:58:59 +01003071 dev->ieee80211_ptr->wext.default_key = key.idx;
Johannes Berg08645122009-05-11 13:54:58 +02003072#endif
Johannes Bergdbd2fd62010-12-09 19:58:59 +01003073 } else {
3074 if (key.def_uni || !key.def_multi) {
3075 err = -EINVAL;
3076 goto out;
3077 }
3078
3079 if (!rdev->ops->set_default_mgmt_key) {
3080 err = -EOPNOTSUPP;
3081 goto out;
3082 }
3083
3084 err = nl80211_key_allowed(dev->ieee80211_ptr);
3085 if (err)
3086 goto out;
3087
Hila Gonene35e4d22012-06-27 17:19:42 +03003088 err = rdev_set_default_mgmt_key(rdev, dev, key.idx);
Johannes Bergdbd2fd62010-12-09 19:58:59 +01003089 if (err)
3090 goto out;
3091
3092#ifdef CONFIG_CFG80211_WEXT
3093 dev->ieee80211_ptr->wext.default_mgmt_key = key.idx;
3094#endif
3095 }
3096
3097 out:
Johannes Bergfffd0932009-07-08 14:22:54 +02003098 wdev_unlock(dev->ieee80211_ptr);
Johannes Berg41ade002007-12-19 02:03:29 +01003099
Johannes Berg41ade002007-12-19 02:03:29 +01003100 return err;
3101}
3102
3103static int nl80211_new_key(struct sk_buff *skb, struct genl_info *info)
3104{
Johannes Berg4c476992010-10-04 21:36:35 +02003105 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Bergfffd0932009-07-08 14:22:54 +02003106 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02003107 struct net_device *dev = info->user_ptr[1];
Johannes Bergb9454e82009-07-08 13:29:08 +02003108 struct key_parse key;
Johannes Berge31b8212010-10-05 19:39:30 +02003109 const u8 *mac_addr = NULL;
Johannes Berg41ade002007-12-19 02:03:29 +01003110
Johannes Bergb9454e82009-07-08 13:29:08 +02003111 err = nl80211_parse_key(info, &key);
3112 if (err)
3113 return err;
Johannes Berg41ade002007-12-19 02:03:29 +01003114
Johannes Bergb9454e82009-07-08 13:29:08 +02003115 if (!key.p.key)
Johannes Berg41ade002007-12-19 02:03:29 +01003116 return -EINVAL;
3117
Johannes Berg41ade002007-12-19 02:03:29 +01003118 if (info->attrs[NL80211_ATTR_MAC])
3119 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
3120
Johannes Berge31b8212010-10-05 19:39:30 +02003121 if (key.type == -1) {
3122 if (mac_addr)
3123 key.type = NL80211_KEYTYPE_PAIRWISE;
3124 else
3125 key.type = NL80211_KEYTYPE_GROUP;
3126 }
3127
3128 /* for now */
3129 if (key.type != NL80211_KEYTYPE_PAIRWISE &&
3130 key.type != NL80211_KEYTYPE_GROUP)
3131 return -EINVAL;
3132
Johannes Berg4c476992010-10-04 21:36:35 +02003133 if (!rdev->ops->add_key)
3134 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01003135
Johannes Berge31b8212010-10-05 19:39:30 +02003136 if (cfg80211_validate_key_settings(rdev, &key.p, key.idx,
3137 key.type == NL80211_KEYTYPE_PAIRWISE,
3138 mac_addr))
Johannes Berg4c476992010-10-04 21:36:35 +02003139 return -EINVAL;
Johannes Bergfffd0932009-07-08 14:22:54 +02003140
3141 wdev_lock(dev->ieee80211_ptr);
3142 err = nl80211_key_allowed(dev->ieee80211_ptr);
3143 if (!err)
Hila Gonene35e4d22012-06-27 17:19:42 +03003144 err = rdev_add_key(rdev, dev, key.idx,
3145 key.type == NL80211_KEYTYPE_PAIRWISE,
3146 mac_addr, &key.p);
Johannes Bergfffd0932009-07-08 14:22:54 +02003147 wdev_unlock(dev->ieee80211_ptr);
Johannes Berg41ade002007-12-19 02:03:29 +01003148
Johannes Berg41ade002007-12-19 02:03:29 +01003149 return err;
3150}
3151
3152static int nl80211_del_key(struct sk_buff *skb, struct genl_info *info)
3153{
Johannes Berg4c476992010-10-04 21:36:35 +02003154 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg41ade002007-12-19 02:03:29 +01003155 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02003156 struct net_device *dev = info->user_ptr[1];
Johannes Berg41ade002007-12-19 02:03:29 +01003157 u8 *mac_addr = NULL;
Johannes Bergb9454e82009-07-08 13:29:08 +02003158 struct key_parse key;
Johannes Berg41ade002007-12-19 02:03:29 +01003159
Johannes Bergb9454e82009-07-08 13:29:08 +02003160 err = nl80211_parse_key(info, &key);
3161 if (err)
3162 return err;
Johannes Berg41ade002007-12-19 02:03:29 +01003163
3164 if (info->attrs[NL80211_ATTR_MAC])
3165 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
3166
Johannes Berge31b8212010-10-05 19:39:30 +02003167 if (key.type == -1) {
3168 if (mac_addr)
3169 key.type = NL80211_KEYTYPE_PAIRWISE;
3170 else
3171 key.type = NL80211_KEYTYPE_GROUP;
3172 }
3173
3174 /* for now */
3175 if (key.type != NL80211_KEYTYPE_PAIRWISE &&
3176 key.type != NL80211_KEYTYPE_GROUP)
3177 return -EINVAL;
3178
Johannes Berg4c476992010-10-04 21:36:35 +02003179 if (!rdev->ops->del_key)
3180 return -EOPNOTSUPP;
Johannes Berg41ade002007-12-19 02:03:29 +01003181
Johannes Bergfffd0932009-07-08 14:22:54 +02003182 wdev_lock(dev->ieee80211_ptr);
3183 err = nl80211_key_allowed(dev->ieee80211_ptr);
Johannes Berge31b8212010-10-05 19:39:30 +02003184
Johannes Berg0fa7b392015-01-23 11:10:12 +01003185 if (key.type == NL80211_KEYTYPE_GROUP && mac_addr &&
Johannes Berge31b8212010-10-05 19:39:30 +02003186 !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN))
3187 err = -ENOENT;
3188
Johannes Bergfffd0932009-07-08 14:22:54 +02003189 if (!err)
Hila Gonene35e4d22012-06-27 17:19:42 +03003190 err = rdev_del_key(rdev, dev, key.idx,
3191 key.type == NL80211_KEYTYPE_PAIRWISE,
3192 mac_addr);
Johannes Berg41ade002007-12-19 02:03:29 +01003193
Johannes Berg3d23e342009-09-29 23:27:28 +02003194#ifdef CONFIG_CFG80211_WEXT
Johannes Berg08645122009-05-11 13:54:58 +02003195 if (!err) {
Johannes Bergb9454e82009-07-08 13:29:08 +02003196 if (key.idx == dev->ieee80211_ptr->wext.default_key)
Johannes Berg08645122009-05-11 13:54:58 +02003197 dev->ieee80211_ptr->wext.default_key = -1;
Johannes Bergb9454e82009-07-08 13:29:08 +02003198 else if (key.idx == dev->ieee80211_ptr->wext.default_mgmt_key)
Johannes Berg08645122009-05-11 13:54:58 +02003199 dev->ieee80211_ptr->wext.default_mgmt_key = -1;
3200 }
3201#endif
Johannes Bergfffd0932009-07-08 14:22:54 +02003202 wdev_unlock(dev->ieee80211_ptr);
Johannes Berg08645122009-05-11 13:54:58 +02003203
Johannes Berg41ade002007-12-19 02:03:29 +01003204 return err;
3205}
3206
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +05303207/* This function returns an error or the number of nested attributes */
3208static int validate_acl_mac_addrs(struct nlattr *nl_attr)
3209{
3210 struct nlattr *attr;
3211 int n_entries = 0, tmp;
3212
3213 nla_for_each_nested(attr, nl_attr, tmp) {
3214 if (nla_len(attr) != ETH_ALEN)
3215 return -EINVAL;
3216
3217 n_entries++;
3218 }
3219
3220 return n_entries;
3221}
3222
3223/*
3224 * This function parses ACL information and allocates memory for ACL data.
3225 * On successful return, the calling function is responsible to free the
3226 * ACL buffer returned by this function.
3227 */
3228static struct cfg80211_acl_data *parse_acl_data(struct wiphy *wiphy,
3229 struct genl_info *info)
3230{
3231 enum nl80211_acl_policy acl_policy;
3232 struct nlattr *attr;
3233 struct cfg80211_acl_data *acl;
3234 int i = 0, n_entries, tmp;
3235
3236 if (!wiphy->max_acl_mac_addrs)
3237 return ERR_PTR(-EOPNOTSUPP);
3238
3239 if (!info->attrs[NL80211_ATTR_ACL_POLICY])
3240 return ERR_PTR(-EINVAL);
3241
3242 acl_policy = nla_get_u32(info->attrs[NL80211_ATTR_ACL_POLICY]);
3243 if (acl_policy != NL80211_ACL_POLICY_ACCEPT_UNLESS_LISTED &&
3244 acl_policy != NL80211_ACL_POLICY_DENY_UNLESS_LISTED)
3245 return ERR_PTR(-EINVAL);
3246
3247 if (!info->attrs[NL80211_ATTR_MAC_ADDRS])
3248 return ERR_PTR(-EINVAL);
3249
3250 n_entries = validate_acl_mac_addrs(info->attrs[NL80211_ATTR_MAC_ADDRS]);
3251 if (n_entries < 0)
3252 return ERR_PTR(n_entries);
3253
3254 if (n_entries > wiphy->max_acl_mac_addrs)
3255 return ERR_PTR(-ENOTSUPP);
3256
3257 acl = kzalloc(sizeof(*acl) + (sizeof(struct mac_address) * n_entries),
3258 GFP_KERNEL);
3259 if (!acl)
3260 return ERR_PTR(-ENOMEM);
3261
3262 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_MAC_ADDRS], tmp) {
3263 memcpy(acl->mac_addrs[i].addr, nla_data(attr), ETH_ALEN);
3264 i++;
3265 }
3266
3267 acl->n_acl_entries = n_entries;
3268 acl->acl_policy = acl_policy;
3269
3270 return acl;
3271}
3272
3273static int nl80211_set_mac_acl(struct sk_buff *skb, struct genl_info *info)
3274{
3275 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3276 struct net_device *dev = info->user_ptr[1];
3277 struct cfg80211_acl_data *acl;
3278 int err;
3279
3280 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
3281 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
3282 return -EOPNOTSUPP;
3283
3284 if (!dev->ieee80211_ptr->beacon_interval)
3285 return -EINVAL;
3286
3287 acl = parse_acl_data(&rdev->wiphy, info);
3288 if (IS_ERR(acl))
3289 return PTR_ERR(acl);
3290
3291 err = rdev_set_mac_acl(rdev, dev, acl);
3292
3293 kfree(acl);
3294
3295 return err;
3296}
3297
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003298static int nl80211_parse_beacon(struct nlattr *attrs[],
Johannes Berg88600202012-02-13 15:17:18 +01003299 struct cfg80211_beacon_data *bcn)
Johannes Berged1b6cc2007-12-19 02:03:32 +01003300{
Johannes Berg88600202012-02-13 15:17:18 +01003301 bool haveinfo = false;
Johannes Berged1b6cc2007-12-19 02:03:32 +01003302
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003303 if (!is_valid_ie_attr(attrs[NL80211_ATTR_BEACON_TAIL]) ||
3304 !is_valid_ie_attr(attrs[NL80211_ATTR_IE]) ||
3305 !is_valid_ie_attr(attrs[NL80211_ATTR_IE_PROBE_RESP]) ||
3306 !is_valid_ie_attr(attrs[NL80211_ATTR_IE_ASSOC_RESP]))
Johannes Bergf4a11bb2009-03-27 12:40:28 +01003307 return -EINVAL;
3308
Johannes Berg88600202012-02-13 15:17:18 +01003309 memset(bcn, 0, sizeof(*bcn));
Johannes Berged1b6cc2007-12-19 02:03:32 +01003310
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003311 if (attrs[NL80211_ATTR_BEACON_HEAD]) {
3312 bcn->head = nla_data(attrs[NL80211_ATTR_BEACON_HEAD]);
3313 bcn->head_len = nla_len(attrs[NL80211_ATTR_BEACON_HEAD]);
Johannes Berg88600202012-02-13 15:17:18 +01003314 if (!bcn->head_len)
3315 return -EINVAL;
3316 haveinfo = true;
Johannes Berged1b6cc2007-12-19 02:03:32 +01003317 }
3318
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003319 if (attrs[NL80211_ATTR_BEACON_TAIL]) {
3320 bcn->tail = nla_data(attrs[NL80211_ATTR_BEACON_TAIL]);
3321 bcn->tail_len = nla_len(attrs[NL80211_ATTR_BEACON_TAIL]);
Johannes Berg88600202012-02-13 15:17:18 +01003322 haveinfo = true;
Johannes Berged1b6cc2007-12-19 02:03:32 +01003323 }
3324
Johannes Berg4c476992010-10-04 21:36:35 +02003325 if (!haveinfo)
3326 return -EINVAL;
Johannes Berged1b6cc2007-12-19 02:03:32 +01003327
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003328 if (attrs[NL80211_ATTR_IE]) {
3329 bcn->beacon_ies = nla_data(attrs[NL80211_ATTR_IE]);
3330 bcn->beacon_ies_len = nla_len(attrs[NL80211_ATTR_IE]);
Jouni Malinen9946ecf2011-08-10 23:55:56 +03003331 }
3332
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003333 if (attrs[NL80211_ATTR_IE_PROBE_RESP]) {
Johannes Berg88600202012-02-13 15:17:18 +01003334 bcn->proberesp_ies =
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003335 nla_data(attrs[NL80211_ATTR_IE_PROBE_RESP]);
Johannes Berg88600202012-02-13 15:17:18 +01003336 bcn->proberesp_ies_len =
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003337 nla_len(attrs[NL80211_ATTR_IE_PROBE_RESP]);
Jouni Malinen9946ecf2011-08-10 23:55:56 +03003338 }
3339
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003340 if (attrs[NL80211_ATTR_IE_ASSOC_RESP]) {
Johannes Berg88600202012-02-13 15:17:18 +01003341 bcn->assocresp_ies =
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003342 nla_data(attrs[NL80211_ATTR_IE_ASSOC_RESP]);
Johannes Berg88600202012-02-13 15:17:18 +01003343 bcn->assocresp_ies_len =
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003344 nla_len(attrs[NL80211_ATTR_IE_ASSOC_RESP]);
Jouni Malinen9946ecf2011-08-10 23:55:56 +03003345 }
3346
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003347 if (attrs[NL80211_ATTR_PROBE_RESP]) {
3348 bcn->probe_resp = nla_data(attrs[NL80211_ATTR_PROBE_RESP]);
3349 bcn->probe_resp_len = nla_len(attrs[NL80211_ATTR_PROBE_RESP]);
Arik Nemtsov00f740e2011-11-10 11:28:56 +02003350 }
3351
Johannes Berg88600202012-02-13 15:17:18 +01003352 return 0;
3353}
3354
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003355static bool nl80211_get_ap_channel(struct cfg80211_registered_device *rdev,
3356 struct cfg80211_ap_settings *params)
3357{
3358 struct wireless_dev *wdev;
3359 bool ret = false;
3360
Johannes Berg53873f12016-05-03 16:52:04 +03003361 list_for_each_entry(wdev, &rdev->wiphy.wdev_list, list) {
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003362 if (wdev->iftype != NL80211_IFTYPE_AP &&
3363 wdev->iftype != NL80211_IFTYPE_P2P_GO)
3364 continue;
3365
Johannes Berg683b6d32012-11-08 21:25:48 +01003366 if (!wdev->preset_chandef.chan)
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003367 continue;
3368
Johannes Berg683b6d32012-11-08 21:25:48 +01003369 params->chandef = wdev->preset_chandef;
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003370 ret = true;
3371 break;
3372 }
3373
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003374 return ret;
3375}
3376
Jouni Malinene39e5b52012-09-30 19:29:39 +03003377static bool nl80211_valid_auth_type(struct cfg80211_registered_device *rdev,
3378 enum nl80211_auth_type auth_type,
3379 enum nl80211_commands cmd)
3380{
3381 if (auth_type > NL80211_AUTHTYPE_MAX)
3382 return false;
3383
3384 switch (cmd) {
3385 case NL80211_CMD_AUTHENTICATE:
3386 if (!(rdev->wiphy.features & NL80211_FEATURE_SAE) &&
3387 auth_type == NL80211_AUTHTYPE_SAE)
3388 return false;
3389 return true;
3390 case NL80211_CMD_CONNECT:
3391 case NL80211_CMD_START_AP:
3392 /* SAE not supported yet */
3393 if (auth_type == NL80211_AUTHTYPE_SAE)
3394 return false;
3395 return true;
3396 default:
3397 return false;
3398 }
3399}
3400
Johannes Berg88600202012-02-13 15:17:18 +01003401static int nl80211_start_ap(struct sk_buff *skb, struct genl_info *info)
3402{
3403 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3404 struct net_device *dev = info->user_ptr[1];
3405 struct wireless_dev *wdev = dev->ieee80211_ptr;
3406 struct cfg80211_ap_settings params;
3407 int err;
3408
3409 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
3410 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
3411 return -EOPNOTSUPP;
3412
3413 if (!rdev->ops->start_ap)
3414 return -EOPNOTSUPP;
3415
3416 if (wdev->beacon_interval)
3417 return -EALREADY;
3418
3419 memset(&params, 0, sizeof(params));
3420
3421 /* these are required for START_AP */
3422 if (!info->attrs[NL80211_ATTR_BEACON_INTERVAL] ||
3423 !info->attrs[NL80211_ATTR_DTIM_PERIOD] ||
3424 !info->attrs[NL80211_ATTR_BEACON_HEAD])
3425 return -EINVAL;
3426
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003427 err = nl80211_parse_beacon(info->attrs, &params.beacon);
Johannes Berg88600202012-02-13 15:17:18 +01003428 if (err)
3429 return err;
3430
3431 params.beacon_interval =
3432 nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]);
3433 params.dtim_period =
3434 nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]);
3435
3436 err = cfg80211_validate_beacon_int(rdev, params.beacon_interval);
3437 if (err)
3438 return err;
3439
3440 /*
3441 * In theory, some of these attributes should be required here
3442 * but since they were not used when the command was originally
3443 * added, keep them optional for old user space programs to let
3444 * them continue to work with drivers that do not need the
3445 * additional information -- drivers must check!
3446 */
3447 if (info->attrs[NL80211_ATTR_SSID]) {
3448 params.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
3449 params.ssid_len =
3450 nla_len(info->attrs[NL80211_ATTR_SSID]);
3451 if (params.ssid_len == 0 ||
3452 params.ssid_len > IEEE80211_MAX_SSID_LEN)
3453 return -EINVAL;
3454 }
3455
3456 if (info->attrs[NL80211_ATTR_HIDDEN_SSID]) {
3457 params.hidden_ssid = nla_get_u32(
3458 info->attrs[NL80211_ATTR_HIDDEN_SSID]);
3459 if (params.hidden_ssid != NL80211_HIDDEN_SSID_NOT_IN_USE &&
3460 params.hidden_ssid != NL80211_HIDDEN_SSID_ZERO_LEN &&
3461 params.hidden_ssid != NL80211_HIDDEN_SSID_ZERO_CONTENTS)
3462 return -EINVAL;
3463 }
3464
3465 params.privacy = !!info->attrs[NL80211_ATTR_PRIVACY];
3466
3467 if (info->attrs[NL80211_ATTR_AUTH_TYPE]) {
3468 params.auth_type = nla_get_u32(
3469 info->attrs[NL80211_ATTR_AUTH_TYPE]);
Jouni Malinene39e5b52012-09-30 19:29:39 +03003470 if (!nl80211_valid_auth_type(rdev, params.auth_type,
3471 NL80211_CMD_START_AP))
Johannes Berg88600202012-02-13 15:17:18 +01003472 return -EINVAL;
3473 } else
3474 params.auth_type = NL80211_AUTHTYPE_AUTOMATIC;
3475
3476 err = nl80211_crypto_settings(rdev, info, &params.crypto,
3477 NL80211_MAX_NR_CIPHER_SUITES);
3478 if (err)
3479 return err;
3480
Vasanthakumar Thiagarajan1b658f12012-03-02 15:50:02 +05303481 if (info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]) {
3482 if (!(rdev->wiphy.features & NL80211_FEATURE_INACTIVITY_TIMER))
3483 return -EOPNOTSUPP;
3484 params.inactivity_timeout = nla_get_u16(
3485 info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]);
3486 }
3487
Johannes Berg53cabad2012-11-14 15:17:28 +01003488 if (info->attrs[NL80211_ATTR_P2P_CTWINDOW]) {
3489 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
3490 return -EINVAL;
3491 params.p2p_ctwindow =
3492 nla_get_u8(info->attrs[NL80211_ATTR_P2P_CTWINDOW]);
3493 if (params.p2p_ctwindow > 127)
3494 return -EINVAL;
3495 if (params.p2p_ctwindow != 0 &&
3496 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_CTWIN))
3497 return -EINVAL;
3498 }
3499
3500 if (info->attrs[NL80211_ATTR_P2P_OPPPS]) {
3501 u8 tmp;
3502
3503 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
3504 return -EINVAL;
3505 tmp = nla_get_u8(info->attrs[NL80211_ATTR_P2P_OPPPS]);
3506 if (tmp > 1)
3507 return -EINVAL;
3508 params.p2p_opp_ps = tmp;
3509 if (params.p2p_opp_ps != 0 &&
3510 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_OPPPS))
3511 return -EINVAL;
3512 }
3513
Johannes Bergaa430da2012-05-16 23:50:18 +02003514 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
Johannes Berg683b6d32012-11-08 21:25:48 +01003515 err = nl80211_parse_chandef(rdev, info, &params.chandef);
3516 if (err)
3517 return err;
3518 } else if (wdev->preset_chandef.chan) {
3519 params.chandef = wdev->preset_chandef;
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003520 } else if (!nl80211_get_ap_channel(rdev, &params))
Johannes Bergaa430da2012-05-16 23:50:18 +02003521 return -EINVAL;
3522
Arik Nemtsov923b3522015-07-08 15:41:44 +03003523 if (!cfg80211_reg_can_beacon_relax(&rdev->wiphy, &params.chandef,
3524 wdev->iftype))
Johannes Bergaa430da2012-05-16 23:50:18 +02003525 return -EINVAL;
3526
Eliad Peller18998c32014-09-10 14:07:34 +03003527 if (info->attrs[NL80211_ATTR_SMPS_MODE]) {
3528 params.smps_mode =
3529 nla_get_u8(info->attrs[NL80211_ATTR_SMPS_MODE]);
3530 switch (params.smps_mode) {
3531 case NL80211_SMPS_OFF:
3532 break;
3533 case NL80211_SMPS_STATIC:
3534 if (!(rdev->wiphy.features &
3535 NL80211_FEATURE_STATIC_SMPS))
3536 return -EINVAL;
3537 break;
3538 case NL80211_SMPS_DYNAMIC:
3539 if (!(rdev->wiphy.features &
3540 NL80211_FEATURE_DYNAMIC_SMPS))
3541 return -EINVAL;
3542 break;
3543 default:
3544 return -EINVAL;
3545 }
3546 } else {
3547 params.smps_mode = NL80211_SMPS_OFF;
3548 }
3549
Purushottam Kushwaha6e8ef842016-07-05 13:44:51 +05303550 params.pbss = nla_get_flag(info->attrs[NL80211_ATTR_PBSS]);
3551 if (params.pbss && !rdev->wiphy.bands[NL80211_BAND_60GHZ])
3552 return -EOPNOTSUPP;
3553
Ola Olsson4baf6be2015-10-29 07:04:58 +01003554 if (info->attrs[NL80211_ATTR_ACL_POLICY]) {
3555 params.acl = parse_acl_data(&rdev->wiphy, info);
3556 if (IS_ERR(params.acl))
3557 return PTR_ERR(params.acl);
3558 }
3559
Simon Wunderlichc56589e2013-11-21 18:19:49 +01003560 wdev_lock(wdev);
Hila Gonene35e4d22012-06-27 17:19:42 +03003561 err = rdev_start_ap(rdev, dev, &params);
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003562 if (!err) {
Johannes Berg683b6d32012-11-08 21:25:48 +01003563 wdev->preset_chandef = params.chandef;
Johannes Berg88600202012-02-13 15:17:18 +01003564 wdev->beacon_interval = params.beacon_interval;
Michal Kazior9e0e2962014-01-29 14:22:27 +01003565 wdev->chandef = params.chandef;
Antonio Quartulli06e191e2012-11-07 12:52:19 +01003566 wdev->ssid_len = params.ssid_len;
3567 memcpy(wdev->ssid, params.ssid, wdev->ssid_len);
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003568 }
Simon Wunderlichc56589e2013-11-21 18:19:49 +01003569 wdev_unlock(wdev);
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +05303570
3571 kfree(params.acl);
3572
Johannes Berg56d18932011-05-09 18:41:15 +02003573 return err;
Johannes Berged1b6cc2007-12-19 02:03:32 +01003574}
3575
Johannes Berg88600202012-02-13 15:17:18 +01003576static int nl80211_set_beacon(struct sk_buff *skb, struct genl_info *info)
3577{
3578 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3579 struct net_device *dev = info->user_ptr[1];
3580 struct wireless_dev *wdev = dev->ieee80211_ptr;
3581 struct cfg80211_beacon_data params;
3582 int err;
3583
3584 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
3585 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
3586 return -EOPNOTSUPP;
3587
3588 if (!rdev->ops->change_beacon)
3589 return -EOPNOTSUPP;
3590
3591 if (!wdev->beacon_interval)
3592 return -EINVAL;
3593
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003594 err = nl80211_parse_beacon(info->attrs, &params);
Johannes Berg88600202012-02-13 15:17:18 +01003595 if (err)
3596 return err;
3597
Simon Wunderlichc56589e2013-11-21 18:19:49 +01003598 wdev_lock(wdev);
3599 err = rdev_change_beacon(rdev, dev, &params);
3600 wdev_unlock(wdev);
3601
3602 return err;
Johannes Berg88600202012-02-13 15:17:18 +01003603}
3604
3605static int nl80211_stop_ap(struct sk_buff *skb, struct genl_info *info)
Johannes Berged1b6cc2007-12-19 02:03:32 +01003606{
Johannes Berg4c476992010-10-04 21:36:35 +02003607 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3608 struct net_device *dev = info->user_ptr[1];
Johannes Berged1b6cc2007-12-19 02:03:32 +01003609
Ilan Peer7c8d5e02014-02-25 15:33:38 +02003610 return cfg80211_stop_ap(rdev, dev, false);
Johannes Berged1b6cc2007-12-19 02:03:32 +01003611}
3612
Johannes Berg5727ef12007-12-19 02:03:34 +01003613static const struct nla_policy sta_flags_policy[NL80211_STA_FLAG_MAX + 1] = {
3614 [NL80211_STA_FLAG_AUTHORIZED] = { .type = NLA_FLAG },
3615 [NL80211_STA_FLAG_SHORT_PREAMBLE] = { .type = NLA_FLAG },
3616 [NL80211_STA_FLAG_WME] = { .type = NLA_FLAG },
Jouni Malinen0e467242009-05-11 21:57:55 +03003617 [NL80211_STA_FLAG_MFP] = { .type = NLA_FLAG },
Javier Cardonab39c48f2011-04-07 15:08:30 -07003618 [NL80211_STA_FLAG_AUTHENTICATED] = { .type = NLA_FLAG },
Johannes Bergd83023d2011-12-14 09:29:15 +01003619 [NL80211_STA_FLAG_TDLS_PEER] = { .type = NLA_FLAG },
Johannes Berg5727ef12007-12-19 02:03:34 +01003620};
3621
Johannes Bergeccb8e82009-05-11 21:57:56 +03003622static int parse_station_flags(struct genl_info *info,
Johannes Bergbdd3ae32012-01-02 13:30:03 +01003623 enum nl80211_iftype iftype,
Johannes Bergeccb8e82009-05-11 21:57:56 +03003624 struct station_parameters *params)
Johannes Berg5727ef12007-12-19 02:03:34 +01003625{
3626 struct nlattr *flags[NL80211_STA_FLAG_MAX + 1];
Johannes Bergeccb8e82009-05-11 21:57:56 +03003627 struct nlattr *nla;
Johannes Berg5727ef12007-12-19 02:03:34 +01003628 int flag;
3629
Johannes Bergeccb8e82009-05-11 21:57:56 +03003630 /*
3631 * Try parsing the new attribute first so userspace
3632 * can specify both for older kernels.
3633 */
3634 nla = info->attrs[NL80211_ATTR_STA_FLAGS2];
3635 if (nla) {
3636 struct nl80211_sta_flag_update *sta_flags;
Johannes Berg5727ef12007-12-19 02:03:34 +01003637
Johannes Bergeccb8e82009-05-11 21:57:56 +03003638 sta_flags = nla_data(nla);
3639 params->sta_flags_mask = sta_flags->mask;
3640 params->sta_flags_set = sta_flags->set;
Johannes Berg77ee7c82013-02-15 00:48:33 +01003641 params->sta_flags_set &= params->sta_flags_mask;
Johannes Bergeccb8e82009-05-11 21:57:56 +03003642 if ((params->sta_flags_mask |
3643 params->sta_flags_set) & BIT(__NL80211_STA_FLAG_INVALID))
3644 return -EINVAL;
3645 return 0;
3646 }
3647
3648 /* if present, parse the old attribute */
3649
3650 nla = info->attrs[NL80211_ATTR_STA_FLAGS];
Johannes Berg5727ef12007-12-19 02:03:34 +01003651 if (!nla)
3652 return 0;
3653
3654 if (nla_parse_nested(flags, NL80211_STA_FLAG_MAX,
3655 nla, sta_flags_policy))
3656 return -EINVAL;
3657
Johannes Bergbdd3ae32012-01-02 13:30:03 +01003658 /*
3659 * Only allow certain flags for interface types so that
3660 * other attributes are silently ignored. Remember that
3661 * this is backward compatibility code with old userspace
3662 * and shouldn't be hit in other cases anyway.
3663 */
3664 switch (iftype) {
3665 case NL80211_IFTYPE_AP:
3666 case NL80211_IFTYPE_AP_VLAN:
3667 case NL80211_IFTYPE_P2P_GO:
3668 params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) |
3669 BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) |
3670 BIT(NL80211_STA_FLAG_WME) |
3671 BIT(NL80211_STA_FLAG_MFP);
3672 break;
3673 case NL80211_IFTYPE_P2P_CLIENT:
3674 case NL80211_IFTYPE_STATION:
3675 params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) |
3676 BIT(NL80211_STA_FLAG_TDLS_PEER);
3677 break;
3678 case NL80211_IFTYPE_MESH_POINT:
3679 params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHENTICATED) |
3680 BIT(NL80211_STA_FLAG_MFP) |
3681 BIT(NL80211_STA_FLAG_AUTHORIZED);
3682 default:
3683 return -EINVAL;
3684 }
Johannes Berg5727ef12007-12-19 02:03:34 +01003685
Johannes Berg3383b5a2012-05-10 20:14:43 +02003686 for (flag = 1; flag <= NL80211_STA_FLAG_MAX; flag++) {
3687 if (flags[flag]) {
Johannes Bergeccb8e82009-05-11 21:57:56 +03003688 params->sta_flags_set |= (1<<flag);
Johannes Berg5727ef12007-12-19 02:03:34 +01003689
Johannes Berg3383b5a2012-05-10 20:14:43 +02003690 /* no longer support new API additions in old API */
3691 if (flag > NL80211_STA_FLAG_MAX_OLD_API)
3692 return -EINVAL;
3693 }
3694 }
3695
Johannes Berg5727ef12007-12-19 02:03:34 +01003696 return 0;
3697}
3698
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003699static bool nl80211_put_sta_rate(struct sk_buff *msg, struct rate_info *info,
3700 int attr)
3701{
3702 struct nlattr *rate;
Vladimir Kondratiev8eb41c82012-07-05 14:25:49 +03003703 u32 bitrate;
3704 u16 bitrate_compat;
Johannes Bergb51f3be2015-01-15 16:14:02 +01003705 enum nl80211_attrs rate_flg;
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003706
3707 rate = nla_nest_start(msg, attr);
3708 if (!rate)
Johannes Bergdb9c64c2012-11-09 14:56:41 +01003709 return false;
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003710
3711 /* cfg80211_calculate_bitrate will return 0 for mcs >= 32 */
3712 bitrate = cfg80211_calculate_bitrate(info);
Vladimir Kondratiev8eb41c82012-07-05 14:25:49 +03003713 /* report 16-bit bitrate only if we can */
3714 bitrate_compat = bitrate < (1UL << 16) ? bitrate : 0;
Johannes Bergdb9c64c2012-11-09 14:56:41 +01003715 if (bitrate > 0 &&
3716 nla_put_u32(msg, NL80211_RATE_INFO_BITRATE32, bitrate))
3717 return false;
3718 if (bitrate_compat > 0 &&
3719 nla_put_u16(msg, NL80211_RATE_INFO_BITRATE, bitrate_compat))
3720 return false;
3721
Johannes Bergb51f3be2015-01-15 16:14:02 +01003722 switch (info->bw) {
3723 case RATE_INFO_BW_5:
3724 rate_flg = NL80211_RATE_INFO_5_MHZ_WIDTH;
3725 break;
3726 case RATE_INFO_BW_10:
3727 rate_flg = NL80211_RATE_INFO_10_MHZ_WIDTH;
3728 break;
3729 default:
3730 WARN_ON(1);
3731 /* fall through */
3732 case RATE_INFO_BW_20:
3733 rate_flg = 0;
3734 break;
3735 case RATE_INFO_BW_40:
3736 rate_flg = NL80211_RATE_INFO_40_MHZ_WIDTH;
3737 break;
3738 case RATE_INFO_BW_80:
3739 rate_flg = NL80211_RATE_INFO_80_MHZ_WIDTH;
3740 break;
3741 case RATE_INFO_BW_160:
3742 rate_flg = NL80211_RATE_INFO_160_MHZ_WIDTH;
3743 break;
3744 }
3745
3746 if (rate_flg && nla_put_flag(msg, rate_flg))
3747 return false;
3748
Johannes Bergdb9c64c2012-11-09 14:56:41 +01003749 if (info->flags & RATE_INFO_FLAGS_MCS) {
3750 if (nla_put_u8(msg, NL80211_RATE_INFO_MCS, info->mcs))
3751 return false;
Johannes Bergdb9c64c2012-11-09 14:56:41 +01003752 if (info->flags & RATE_INFO_FLAGS_SHORT_GI &&
3753 nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI))
3754 return false;
3755 } else if (info->flags & RATE_INFO_FLAGS_VHT_MCS) {
3756 if (nla_put_u8(msg, NL80211_RATE_INFO_VHT_MCS, info->mcs))
3757 return false;
3758 if (nla_put_u8(msg, NL80211_RATE_INFO_VHT_NSS, info->nss))
3759 return false;
Johannes Bergdb9c64c2012-11-09 14:56:41 +01003760 if (info->flags & RATE_INFO_FLAGS_SHORT_GI &&
3761 nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI))
3762 return false;
3763 }
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003764
3765 nla_nest_end(msg, rate);
3766 return true;
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003767}
3768
Felix Fietkau119363c2013-04-22 16:29:30 +02003769static bool nl80211_put_signal(struct sk_buff *msg, u8 mask, s8 *signal,
3770 int id)
3771{
3772 void *attr;
3773 int i = 0;
3774
3775 if (!mask)
3776 return true;
3777
3778 attr = nla_nest_start(msg, id);
3779 if (!attr)
3780 return false;
3781
3782 for (i = 0; i < IEEE80211_MAX_CHAINS; i++) {
3783 if (!(mask & BIT(i)))
3784 continue;
3785
3786 if (nla_put_u8(msg, i, signal[i]))
3787 return false;
3788 }
3789
3790 nla_nest_end(msg, attr);
3791
3792 return true;
3793}
3794
Johannes Bergcf5ead82014-11-14 17:14:00 +01003795static int nl80211_send_station(struct sk_buff *msg, u32 cmd, u32 portid,
3796 u32 seq, int flags,
John W. Linville66266b32012-03-15 13:25:41 -04003797 struct cfg80211_registered_device *rdev,
3798 struct net_device *dev,
Johannes Berg98b62182009-12-23 13:15:44 +01003799 const u8 *mac_addr, struct station_info *sinfo)
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003800{
3801 void *hdr;
Paul Stewartf4263c92011-03-31 09:25:41 -07003802 struct nlattr *sinfoattr, *bss_param;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003803
Johannes Bergcf5ead82014-11-14 17:14:00 +01003804 hdr = nl80211hdr_put(msg, portid, seq, flags, cmd);
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003805 if (!hdr)
3806 return -1;
3807
David S. Miller9360ffd2012-03-29 04:41:26 -04003808 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
3809 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) ||
3810 nla_put_u32(msg, NL80211_ATTR_GENERATION, sinfo->generation))
3811 goto nla_put_failure;
Johannes Bergf5ea9122009-08-07 16:17:38 +02003812
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003813 sinfoattr = nla_nest_start(msg, NL80211_ATTR_STA_INFO);
3814 if (!sinfoattr)
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003815 goto nla_put_failure;
Johannes Berg319090b2014-11-17 14:08:11 +01003816
3817#define PUT_SINFO(attr, memb, type) do { \
Johannes Bergd686b922016-04-26 09:54:11 +02003818 BUILD_BUG_ON(sizeof(type) == sizeof(u64)); \
Mohammed Shafi Shajakhan739960f2016-04-07 19:59:34 +05303819 if (sinfo->filled & (1ULL << NL80211_STA_INFO_ ## attr) && \
Johannes Berg319090b2014-11-17 14:08:11 +01003820 nla_put_ ## type(msg, NL80211_STA_INFO_ ## attr, \
3821 sinfo->memb)) \
3822 goto nla_put_failure; \
3823 } while (0)
Johannes Bergd686b922016-04-26 09:54:11 +02003824#define PUT_SINFO_U64(attr, memb) do { \
3825 if (sinfo->filled & (1ULL << NL80211_STA_INFO_ ## attr) && \
3826 nla_put_u64_64bit(msg, NL80211_STA_INFO_ ## attr, \
3827 sinfo->memb, NL80211_STA_INFO_PAD)) \
3828 goto nla_put_failure; \
3829 } while (0)
Johannes Berg319090b2014-11-17 14:08:11 +01003830
3831 PUT_SINFO(CONNECTED_TIME, connected_time, u32);
3832 PUT_SINFO(INACTIVE_TIME, inactive_time, u32);
3833
3834 if (sinfo->filled & (BIT(NL80211_STA_INFO_RX_BYTES) |
3835 BIT(NL80211_STA_INFO_RX_BYTES64)) &&
David S. Miller9360ffd2012-03-29 04:41:26 -04003836 nla_put_u32(msg, NL80211_STA_INFO_RX_BYTES,
Vladimir Kondratiev42745e02013-02-04 13:53:11 +02003837 (u32)sinfo->rx_bytes))
3838 goto nla_put_failure;
Johannes Berg319090b2014-11-17 14:08:11 +01003839
3840 if (sinfo->filled & (BIT(NL80211_STA_INFO_TX_BYTES) |
3841 BIT(NL80211_STA_INFO_TX_BYTES64)) &&
Vladimir Kondratiev42745e02013-02-04 13:53:11 +02003842 nla_put_u32(msg, NL80211_STA_INFO_TX_BYTES,
3843 (u32)sinfo->tx_bytes))
3844 goto nla_put_failure;
Johannes Berg319090b2014-11-17 14:08:11 +01003845
Johannes Bergd686b922016-04-26 09:54:11 +02003846 PUT_SINFO_U64(RX_BYTES64, rx_bytes);
3847 PUT_SINFO_U64(TX_BYTES64, tx_bytes);
Johannes Berg319090b2014-11-17 14:08:11 +01003848 PUT_SINFO(LLID, llid, u16);
3849 PUT_SINFO(PLID, plid, u16);
3850 PUT_SINFO(PLINK_STATE, plink_state, u8);
Johannes Bergd686b922016-04-26 09:54:11 +02003851 PUT_SINFO_U64(RX_DURATION, rx_duration);
Johannes Berg319090b2014-11-17 14:08:11 +01003852
John W. Linville66266b32012-03-15 13:25:41 -04003853 switch (rdev->wiphy.signal_type) {
3854 case CFG80211_SIGNAL_TYPE_MBM:
Johannes Berg319090b2014-11-17 14:08:11 +01003855 PUT_SINFO(SIGNAL, signal, u8);
3856 PUT_SINFO(SIGNAL_AVG, signal_avg, u8);
John W. Linville66266b32012-03-15 13:25:41 -04003857 break;
3858 default:
3859 break;
3860 }
Johannes Berg319090b2014-11-17 14:08:11 +01003861 if (sinfo->filled & BIT(NL80211_STA_INFO_CHAIN_SIGNAL)) {
Felix Fietkau119363c2013-04-22 16:29:30 +02003862 if (!nl80211_put_signal(msg, sinfo->chains,
3863 sinfo->chain_signal,
3864 NL80211_STA_INFO_CHAIN_SIGNAL))
3865 goto nla_put_failure;
3866 }
Johannes Berg319090b2014-11-17 14:08:11 +01003867 if (sinfo->filled & BIT(NL80211_STA_INFO_CHAIN_SIGNAL_AVG)) {
Felix Fietkau119363c2013-04-22 16:29:30 +02003868 if (!nl80211_put_signal(msg, sinfo->chains,
3869 sinfo->chain_signal_avg,
3870 NL80211_STA_INFO_CHAIN_SIGNAL_AVG))
3871 goto nla_put_failure;
3872 }
Johannes Berg319090b2014-11-17 14:08:11 +01003873 if (sinfo->filled & BIT(NL80211_STA_INFO_TX_BITRATE)) {
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003874 if (!nl80211_put_sta_rate(msg, &sinfo->txrate,
3875 NL80211_STA_INFO_TX_BITRATE))
Henning Rogge420e7fa2008-12-11 22:04:19 +01003876 goto nla_put_failure;
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003877 }
Johannes Berg319090b2014-11-17 14:08:11 +01003878 if (sinfo->filled & BIT(NL80211_STA_INFO_RX_BITRATE)) {
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003879 if (!nl80211_put_sta_rate(msg, &sinfo->rxrate,
3880 NL80211_STA_INFO_RX_BITRATE))
3881 goto nla_put_failure;
Henning Rogge420e7fa2008-12-11 22:04:19 +01003882 }
Johannes Berg319090b2014-11-17 14:08:11 +01003883
3884 PUT_SINFO(RX_PACKETS, rx_packets, u32);
3885 PUT_SINFO(TX_PACKETS, tx_packets, u32);
3886 PUT_SINFO(TX_RETRIES, tx_retries, u32);
3887 PUT_SINFO(TX_FAILED, tx_failed, u32);
3888 PUT_SINFO(EXPECTED_THROUGHPUT, expected_throughput, u32);
3889 PUT_SINFO(BEACON_LOSS, beacon_loss_count, u32);
3890 PUT_SINFO(LOCAL_PM, local_pm, u32);
3891 PUT_SINFO(PEER_PM, peer_pm, u32);
3892 PUT_SINFO(NONPEER_PM, nonpeer_pm, u32);
3893
3894 if (sinfo->filled & BIT(NL80211_STA_INFO_BSS_PARAM)) {
Paul Stewartf4263c92011-03-31 09:25:41 -07003895 bss_param = nla_nest_start(msg, NL80211_STA_INFO_BSS_PARAM);
3896 if (!bss_param)
3897 goto nla_put_failure;
3898
David S. Miller9360ffd2012-03-29 04:41:26 -04003899 if (((sinfo->bss_param.flags & BSS_PARAM_FLAGS_CTS_PROT) &&
3900 nla_put_flag(msg, NL80211_STA_BSS_PARAM_CTS_PROT)) ||
3901 ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_PREAMBLE) &&
3902 nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_PREAMBLE)) ||
3903 ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_SLOT_TIME) &&
3904 nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_SLOT_TIME)) ||
3905 nla_put_u8(msg, NL80211_STA_BSS_PARAM_DTIM_PERIOD,
3906 sinfo->bss_param.dtim_period) ||
3907 nla_put_u16(msg, NL80211_STA_BSS_PARAM_BEACON_INTERVAL,
3908 sinfo->bss_param.beacon_interval))
3909 goto nla_put_failure;
Paul Stewartf4263c92011-03-31 09:25:41 -07003910
3911 nla_nest_end(msg, bss_param);
3912 }
Johannes Berg319090b2014-11-17 14:08:11 +01003913 if ((sinfo->filled & BIT(NL80211_STA_INFO_STA_FLAGS)) &&
David S. Miller9360ffd2012-03-29 04:41:26 -04003914 nla_put(msg, NL80211_STA_INFO_STA_FLAGS,
3915 sizeof(struct nl80211_sta_flag_update),
3916 &sinfo->sta_flags))
3917 goto nla_put_failure;
Johannes Berg319090b2014-11-17 14:08:11 +01003918
Johannes Bergd686b922016-04-26 09:54:11 +02003919 PUT_SINFO_U64(T_OFFSET, t_offset);
3920 PUT_SINFO_U64(RX_DROP_MISC, rx_dropped_misc);
3921 PUT_SINFO_U64(BEACON_RX, rx_beacon);
Johannes Berga76b1942014-11-17 14:12:22 +01003922 PUT_SINFO(BEACON_SIGNAL_AVG, rx_beacon_signal_avg, u8);
Johannes Berg319090b2014-11-17 14:08:11 +01003923
3924#undef PUT_SINFO
Johannes Bergd686b922016-04-26 09:54:11 +02003925#undef PUT_SINFO_U64
Johannes Berg6de39802014-12-19 12:34:00 +01003926
3927 if (sinfo->filled & BIT(NL80211_STA_INFO_TID_STATS)) {
3928 struct nlattr *tidsattr;
3929 int tid;
3930
3931 tidsattr = nla_nest_start(msg, NL80211_STA_INFO_TID_STATS);
3932 if (!tidsattr)
3933 goto nla_put_failure;
3934
3935 for (tid = 0; tid < IEEE80211_NUM_TIDS + 1; tid++) {
3936 struct cfg80211_tid_stats *tidstats;
3937 struct nlattr *tidattr;
3938
3939 tidstats = &sinfo->pertid[tid];
3940
3941 if (!tidstats->filled)
3942 continue;
3943
3944 tidattr = nla_nest_start(msg, tid + 1);
3945 if (!tidattr)
3946 goto nla_put_failure;
3947
Johannes Bergd686b922016-04-26 09:54:11 +02003948#define PUT_TIDVAL_U64(attr, memb) do { \
Johannes Berg6de39802014-12-19 12:34:00 +01003949 if (tidstats->filled & BIT(NL80211_TID_STATS_ ## attr) && \
Johannes Bergd686b922016-04-26 09:54:11 +02003950 nla_put_u64_64bit(msg, NL80211_TID_STATS_ ## attr, \
3951 tidstats->memb, NL80211_TID_STATS_PAD)) \
Johannes Berg6de39802014-12-19 12:34:00 +01003952 goto nla_put_failure; \
3953 } while (0)
3954
Johannes Bergd686b922016-04-26 09:54:11 +02003955 PUT_TIDVAL_U64(RX_MSDU, rx_msdu);
3956 PUT_TIDVAL_U64(TX_MSDU, tx_msdu);
3957 PUT_TIDVAL_U64(TX_MSDU_RETRIES, tx_msdu_retries);
3958 PUT_TIDVAL_U64(TX_MSDU_FAILED, tx_msdu_failed);
Johannes Berg6de39802014-12-19 12:34:00 +01003959
Johannes Bergd686b922016-04-26 09:54:11 +02003960#undef PUT_TIDVAL_U64
Johannes Berg6de39802014-12-19 12:34:00 +01003961 nla_nest_end(msg, tidattr);
3962 }
3963
3964 nla_nest_end(msg, tidsattr);
3965 }
3966
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003967 nla_nest_end(msg, sinfoattr);
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003968
Johannes Berg319090b2014-11-17 14:08:11 +01003969 if (sinfo->assoc_req_ies_len &&
David S. Miller9360ffd2012-03-29 04:41:26 -04003970 nla_put(msg, NL80211_ATTR_IE, sinfo->assoc_req_ies_len,
3971 sinfo->assoc_req_ies))
3972 goto nla_put_failure;
Jouni Malinen50d3dfb2011-08-08 12:11:52 +03003973
Johannes Berg053c0952015-01-16 22:09:00 +01003974 genlmsg_end(msg, hdr);
3975 return 0;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003976
3977 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07003978 genlmsg_cancel(msg, hdr);
3979 return -EMSGSIZE;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003980}
3981
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003982static int nl80211_dump_station(struct sk_buff *skb,
Johannes Bergbba95fe2008-07-29 13:22:51 +02003983 struct netlink_callback *cb)
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003984{
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003985 struct station_info sinfo;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08003986 struct cfg80211_registered_device *rdev;
Johannes Berg97990a02013-04-19 01:02:55 +02003987 struct wireless_dev *wdev;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003988 u8 mac_addr[ETH_ALEN];
Johannes Berg97990a02013-04-19 01:02:55 +02003989 int sta_idx = cb->args[2];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003990 int err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003991
Zhao, Gang1b8ec872014-04-21 12:53:02 +08003992 err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev);
Johannes Berg67748892010-10-04 21:14:06 +02003993 if (err)
3994 return err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02003995
Johannes Berg97990a02013-04-19 01:02:55 +02003996 if (!wdev->netdev) {
3997 err = -EINVAL;
3998 goto out_err;
3999 }
4000
Zhao, Gang1b8ec872014-04-21 12:53:02 +08004001 if (!rdev->ops->dump_station) {
Jouni Malineneec60b02009-03-20 21:21:19 +02004002 err = -EOPNOTSUPP;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004003 goto out_err;
4004 }
4005
Johannes Bergbba95fe2008-07-29 13:22:51 +02004006 while (1) {
Jouni Malinenf612ced2011-08-11 11:46:22 +03004007 memset(&sinfo, 0, sizeof(sinfo));
Zhao, Gang1b8ec872014-04-21 12:53:02 +08004008 err = rdev_dump_station(rdev, wdev->netdev, sta_idx,
Hila Gonene35e4d22012-06-27 17:19:42 +03004009 mac_addr, &sinfo);
Johannes Bergbba95fe2008-07-29 13:22:51 +02004010 if (err == -ENOENT)
4011 break;
4012 if (err)
Johannes Berg3b858752009-03-12 09:55:09 +01004013 goto out_err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004014
Johannes Bergcf5ead82014-11-14 17:14:00 +01004015 if (nl80211_send_station(skb, NL80211_CMD_NEW_STATION,
Eric W. Biederman15e47302012-09-07 20:12:54 +00004016 NETLINK_CB(cb->skb).portid,
Johannes Bergbba95fe2008-07-29 13:22:51 +02004017 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08004018 rdev, wdev->netdev, mac_addr,
Johannes Bergbba95fe2008-07-29 13:22:51 +02004019 &sinfo) < 0)
4020 goto out;
4021
4022 sta_idx++;
4023 }
4024
Johannes Bergbba95fe2008-07-29 13:22:51 +02004025 out:
Johannes Berg97990a02013-04-19 01:02:55 +02004026 cb->args[2] = sta_idx;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004027 err = skb->len;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004028 out_err:
Zhao, Gang1b8ec872014-04-21 12:53:02 +08004029 nl80211_finish_wdev_dump(rdev);
Johannes Bergbba95fe2008-07-29 13:22:51 +02004030
4031 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004032}
Johannes Bergfd5b74d2007-12-19 02:03:36 +01004033
Johannes Berg5727ef12007-12-19 02:03:34 +01004034static int nl80211_get_station(struct sk_buff *skb, struct genl_info *info)
4035{
Johannes Berg4c476992010-10-04 21:36:35 +02004036 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4037 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004038 struct station_info sinfo;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01004039 struct sk_buff *msg;
4040 u8 *mac_addr = NULL;
Johannes Berg4c476992010-10-04 21:36:35 +02004041 int err;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01004042
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004043 memset(&sinfo, 0, sizeof(sinfo));
Johannes Bergfd5b74d2007-12-19 02:03:36 +01004044
4045 if (!info->attrs[NL80211_ATTR_MAC])
4046 return -EINVAL;
4047
4048 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
4049
Johannes Berg4c476992010-10-04 21:36:35 +02004050 if (!rdev->ops->get_station)
4051 return -EOPNOTSUPP;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01004052
Hila Gonene35e4d22012-06-27 17:19:42 +03004053 err = rdev_get_station(rdev, dev, mac_addr, &sinfo);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004054 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02004055 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004056
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07004057 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Bergfd5b74d2007-12-19 02:03:36 +01004058 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02004059 return -ENOMEM;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01004060
Johannes Bergcf5ead82014-11-14 17:14:00 +01004061 if (nl80211_send_station(msg, NL80211_CMD_NEW_STATION,
4062 info->snd_portid, info->snd_seq, 0,
John W. Linville66266b32012-03-15 13:25:41 -04004063 rdev, dev, mac_addr, &sinfo) < 0) {
Johannes Berg4c476992010-10-04 21:36:35 +02004064 nlmsg_free(msg);
4065 return -ENOBUFS;
4066 }
Johannes Bergfd5b74d2007-12-19 02:03:36 +01004067
Johannes Berg4c476992010-10-04 21:36:35 +02004068 return genlmsg_reply(msg, info);
Johannes Berg5727ef12007-12-19 02:03:34 +01004069}
4070
Johannes Berg77ee7c82013-02-15 00:48:33 +01004071int cfg80211_check_station_change(struct wiphy *wiphy,
4072 struct station_parameters *params,
4073 enum cfg80211_station_type statype)
4074{
Ayala Bekere4208422015-10-23 11:20:06 +03004075 if (params->listen_interval != -1 &&
4076 statype != CFG80211_STA_AP_CLIENT_UNASSOC)
Johannes Berg77ee7c82013-02-15 00:48:33 +01004077 return -EINVAL;
Ayala Bekere4208422015-10-23 11:20:06 +03004078
Ayala Beker17b94242016-03-17 15:41:38 +02004079 if (params->support_p2p_ps != -1 &&
4080 statype != CFG80211_STA_AP_CLIENT_UNASSOC)
4081 return -EINVAL;
4082
Arik Nemtsovc72e1142014-07-17 17:14:29 +03004083 if (params->aid &&
Ayala Bekere4208422015-10-23 11:20:06 +03004084 !(params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) &&
4085 statype != CFG80211_STA_AP_CLIENT_UNASSOC)
Johannes Berg77ee7c82013-02-15 00:48:33 +01004086 return -EINVAL;
4087
4088 /* When you run into this, adjust the code below for the new flag */
4089 BUILD_BUG_ON(NL80211_STA_FLAG_MAX != 7);
4090
4091 switch (statype) {
Thomas Pederseneef941e2013-03-04 13:06:11 -08004092 case CFG80211_STA_MESH_PEER_KERNEL:
4093 case CFG80211_STA_MESH_PEER_USER:
Johannes Berg77ee7c82013-02-15 00:48:33 +01004094 /*
4095 * No ignoring the TDLS flag here -- the userspace mesh
4096 * code doesn't have the bug of including TDLS in the
4097 * mask everywhere.
4098 */
4099 if (params->sta_flags_mask &
4100 ~(BIT(NL80211_STA_FLAG_AUTHENTICATED) |
4101 BIT(NL80211_STA_FLAG_MFP) |
4102 BIT(NL80211_STA_FLAG_AUTHORIZED)))
4103 return -EINVAL;
4104 break;
4105 case CFG80211_STA_TDLS_PEER_SETUP:
4106 case CFG80211_STA_TDLS_PEER_ACTIVE:
4107 if (!(params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)))
4108 return -EINVAL;
4109 /* ignore since it can't change */
4110 params->sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER);
4111 break;
4112 default:
4113 /* disallow mesh-specific things */
4114 if (params->plink_action != NL80211_PLINK_ACTION_NO_ACTION)
4115 return -EINVAL;
4116 if (params->local_pm)
4117 return -EINVAL;
4118 if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE)
4119 return -EINVAL;
4120 }
4121
4122 if (statype != CFG80211_STA_TDLS_PEER_SETUP &&
4123 statype != CFG80211_STA_TDLS_PEER_ACTIVE) {
4124 /* TDLS can't be set, ... */
4125 if (params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))
4126 return -EINVAL;
4127 /*
4128 * ... but don't bother the driver with it. This works around
4129 * a hostapd/wpa_supplicant issue -- it always includes the
4130 * TLDS_PEER flag in the mask even for AP mode.
4131 */
4132 params->sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER);
4133 }
4134
Ayala Beker47edb112015-09-21 15:49:53 +03004135 if (statype != CFG80211_STA_TDLS_PEER_SETUP &&
4136 statype != CFG80211_STA_AP_CLIENT_UNASSOC) {
Johannes Berg77ee7c82013-02-15 00:48:33 +01004137 /* reject other things that can't change */
4138 if (params->sta_modify_mask & STATION_PARAM_APPLY_UAPSD)
4139 return -EINVAL;
4140 if (params->sta_modify_mask & STATION_PARAM_APPLY_CAPABILITY)
4141 return -EINVAL;
4142 if (params->supported_rates)
4143 return -EINVAL;
4144 if (params->ext_capab || params->ht_capa || params->vht_capa)
4145 return -EINVAL;
4146 }
4147
Ayala Beker47edb112015-09-21 15:49:53 +03004148 if (statype != CFG80211_STA_AP_CLIENT &&
4149 statype != CFG80211_STA_AP_CLIENT_UNASSOC) {
Johannes Berg77ee7c82013-02-15 00:48:33 +01004150 if (params->vlan)
4151 return -EINVAL;
4152 }
4153
4154 switch (statype) {
4155 case CFG80211_STA_AP_MLME_CLIENT:
4156 /* Use this only for authorizing/unauthorizing a station */
4157 if (!(params->sta_flags_mask & BIT(NL80211_STA_FLAG_AUTHORIZED)))
4158 return -EOPNOTSUPP;
4159 break;
4160 case CFG80211_STA_AP_CLIENT:
Ayala Beker47edb112015-09-21 15:49:53 +03004161 case CFG80211_STA_AP_CLIENT_UNASSOC:
Johannes Berg77ee7c82013-02-15 00:48:33 +01004162 /* accept only the listed bits */
4163 if (params->sta_flags_mask &
4164 ~(BIT(NL80211_STA_FLAG_AUTHORIZED) |
4165 BIT(NL80211_STA_FLAG_AUTHENTICATED) |
4166 BIT(NL80211_STA_FLAG_ASSOCIATED) |
4167 BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) |
4168 BIT(NL80211_STA_FLAG_WME) |
4169 BIT(NL80211_STA_FLAG_MFP)))
4170 return -EINVAL;
4171
4172 /* but authenticated/associated only if driver handles it */
4173 if (!(wiphy->features & NL80211_FEATURE_FULL_AP_CLIENT_STATE) &&
4174 params->sta_flags_mask &
4175 (BIT(NL80211_STA_FLAG_AUTHENTICATED) |
4176 BIT(NL80211_STA_FLAG_ASSOCIATED)))
4177 return -EINVAL;
4178 break;
4179 case CFG80211_STA_IBSS:
4180 case CFG80211_STA_AP_STA:
4181 /* reject any changes other than AUTHORIZED */
4182 if (params->sta_flags_mask & ~BIT(NL80211_STA_FLAG_AUTHORIZED))
4183 return -EINVAL;
4184 break;
4185 case CFG80211_STA_TDLS_PEER_SETUP:
4186 /* reject any changes other than AUTHORIZED or WME */
4187 if (params->sta_flags_mask & ~(BIT(NL80211_STA_FLAG_AUTHORIZED) |
4188 BIT(NL80211_STA_FLAG_WME)))
4189 return -EINVAL;
4190 /* force (at least) rates when authorizing */
4191 if (params->sta_flags_set & BIT(NL80211_STA_FLAG_AUTHORIZED) &&
4192 !params->supported_rates)
4193 return -EINVAL;
4194 break;
4195 case CFG80211_STA_TDLS_PEER_ACTIVE:
4196 /* reject any changes */
4197 return -EINVAL;
Thomas Pederseneef941e2013-03-04 13:06:11 -08004198 case CFG80211_STA_MESH_PEER_KERNEL:
Johannes Berg77ee7c82013-02-15 00:48:33 +01004199 if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE)
4200 return -EINVAL;
4201 break;
Thomas Pederseneef941e2013-03-04 13:06:11 -08004202 case CFG80211_STA_MESH_PEER_USER:
Chun-Yeow Yeoh42925042015-04-18 01:30:02 +08004203 if (params->plink_action != NL80211_PLINK_ACTION_NO_ACTION &&
4204 params->plink_action != NL80211_PLINK_ACTION_BLOCK)
Johannes Berg77ee7c82013-02-15 00:48:33 +01004205 return -EINVAL;
4206 break;
4207 }
4208
4209 return 0;
4210}
4211EXPORT_SYMBOL(cfg80211_check_station_change);
4212
Johannes Berg5727ef12007-12-19 02:03:34 +01004213/*
Felix Fietkauc258d2d2009-11-11 17:23:31 +01004214 * Get vlan interface making sure it is running and on the right wiphy.
Johannes Berg5727ef12007-12-19 02:03:34 +01004215 */
Johannes Berg80b99892011-11-18 16:23:01 +01004216static struct net_device *get_vlan(struct genl_info *info,
4217 struct cfg80211_registered_device *rdev)
Johannes Berg5727ef12007-12-19 02:03:34 +01004218{
Johannes Berg463d0182009-07-14 00:33:35 +02004219 struct nlattr *vlanattr = info->attrs[NL80211_ATTR_STA_VLAN];
Johannes Berg80b99892011-11-18 16:23:01 +01004220 struct net_device *v;
4221 int ret;
Johannes Berg5727ef12007-12-19 02:03:34 +01004222
Johannes Berg80b99892011-11-18 16:23:01 +01004223 if (!vlanattr)
4224 return NULL;
4225
4226 v = dev_get_by_index(genl_info_net(info), nla_get_u32(vlanattr));
4227 if (!v)
4228 return ERR_PTR(-ENODEV);
4229
4230 if (!v->ieee80211_ptr || v->ieee80211_ptr->wiphy != &rdev->wiphy) {
4231 ret = -EINVAL;
4232 goto error;
Johannes Berg5727ef12007-12-19 02:03:34 +01004233 }
Johannes Berg80b99892011-11-18 16:23:01 +01004234
Johannes Berg77ee7c82013-02-15 00:48:33 +01004235 if (v->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN &&
4236 v->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
4237 v->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) {
4238 ret = -EINVAL;
4239 goto error;
4240 }
4241
Johannes Berg80b99892011-11-18 16:23:01 +01004242 if (!netif_running(v)) {
4243 ret = -ENETDOWN;
4244 goto error;
4245 }
4246
4247 return v;
4248 error:
4249 dev_put(v);
4250 return ERR_PTR(ret);
Johannes Berg5727ef12007-12-19 02:03:34 +01004251}
4252
Johannes Berg94e860f2014-01-20 23:58:15 +01004253static const struct nla_policy
4254nl80211_sta_wme_policy[NL80211_STA_WME_MAX + 1] = {
Jouni Malinendf881292013-02-14 21:10:54 +02004255 [NL80211_STA_WME_UAPSD_QUEUES] = { .type = NLA_U8 },
4256 [NL80211_STA_WME_MAX_SP] = { .type = NLA_U8 },
4257};
4258
Johannes Bergff276692013-02-15 00:09:01 +01004259static int nl80211_parse_sta_wme(struct genl_info *info,
4260 struct station_parameters *params)
Jouni Malinendf881292013-02-14 21:10:54 +02004261{
Jouni Malinendf881292013-02-14 21:10:54 +02004262 struct nlattr *tb[NL80211_STA_WME_MAX + 1];
4263 struct nlattr *nla;
4264 int err;
4265
Jouni Malinendf881292013-02-14 21:10:54 +02004266 /* parse WME attributes if present */
4267 if (!info->attrs[NL80211_ATTR_STA_WME])
4268 return 0;
4269
4270 nla = info->attrs[NL80211_ATTR_STA_WME];
4271 err = nla_parse_nested(tb, NL80211_STA_WME_MAX, nla,
4272 nl80211_sta_wme_policy);
4273 if (err)
4274 return err;
4275
4276 if (tb[NL80211_STA_WME_UAPSD_QUEUES])
4277 params->uapsd_queues = nla_get_u8(
4278 tb[NL80211_STA_WME_UAPSD_QUEUES]);
4279 if (params->uapsd_queues & ~IEEE80211_WMM_IE_STA_QOSINFO_AC_MASK)
4280 return -EINVAL;
4281
4282 if (tb[NL80211_STA_WME_MAX_SP])
4283 params->max_sp = nla_get_u8(tb[NL80211_STA_WME_MAX_SP]);
4284
4285 if (params->max_sp & ~IEEE80211_WMM_IE_STA_QOSINFO_SP_MASK)
4286 return -EINVAL;
4287
4288 params->sta_modify_mask |= STATION_PARAM_APPLY_UAPSD;
4289
4290 return 0;
4291}
4292
Sunil Duttc01fc9a2013-10-09 20:45:21 +05304293static int nl80211_parse_sta_channel_info(struct genl_info *info,
4294 struct station_parameters *params)
4295{
4296 if (info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]) {
4297 params->supported_channels =
4298 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]);
4299 params->supported_channels_len =
4300 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]);
4301 /*
4302 * Need to include at least one (first channel, number of
4303 * channels) tuple for each subband, and must have proper
4304 * tuples for the rest of the data as well.
4305 */
4306 if (params->supported_channels_len < 2)
4307 return -EINVAL;
4308 if (params->supported_channels_len % 2)
4309 return -EINVAL;
4310 }
4311
4312 if (info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]) {
4313 params->supported_oper_classes =
4314 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]);
4315 params->supported_oper_classes_len =
4316 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]);
4317 /*
4318 * The value of the Length field of the Supported Operating
4319 * Classes element is between 2 and 253.
4320 */
4321 if (params->supported_oper_classes_len < 2 ||
4322 params->supported_oper_classes_len > 253)
4323 return -EINVAL;
4324 }
4325 return 0;
4326}
4327
Johannes Bergff276692013-02-15 00:09:01 +01004328static int nl80211_set_station_tdls(struct genl_info *info,
4329 struct station_parameters *params)
4330{
Sunil Duttc01fc9a2013-10-09 20:45:21 +05304331 int err;
Johannes Bergff276692013-02-15 00:09:01 +01004332 /* Dummy STA entry gets updated once the peer capabilities are known */
Jouni Malinen5e4b6f52013-05-16 20:11:08 +03004333 if (info->attrs[NL80211_ATTR_PEER_AID])
4334 params->aid = nla_get_u16(info->attrs[NL80211_ATTR_PEER_AID]);
Johannes Bergff276692013-02-15 00:09:01 +01004335 if (info->attrs[NL80211_ATTR_HT_CAPABILITY])
4336 params->ht_capa =
4337 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]);
4338 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY])
4339 params->vht_capa =
4340 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]);
4341
Sunil Duttc01fc9a2013-10-09 20:45:21 +05304342 err = nl80211_parse_sta_channel_info(info, params);
4343 if (err)
4344 return err;
4345
Johannes Bergff276692013-02-15 00:09:01 +01004346 return nl80211_parse_sta_wme(info, params);
4347}
4348
Johannes Berg5727ef12007-12-19 02:03:34 +01004349static int nl80211_set_station(struct sk_buff *skb, struct genl_info *info)
4350{
Johannes Berg4c476992010-10-04 21:36:35 +02004351 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg4c476992010-10-04 21:36:35 +02004352 struct net_device *dev = info->user_ptr[1];
Johannes Berg5727ef12007-12-19 02:03:34 +01004353 struct station_parameters params;
Johannes Berg77ee7c82013-02-15 00:48:33 +01004354 u8 *mac_addr;
4355 int err;
Johannes Berg5727ef12007-12-19 02:03:34 +01004356
4357 memset(&params, 0, sizeof(params));
4358
Johannes Berg77ee7c82013-02-15 00:48:33 +01004359 if (!rdev->ops->change_station)
4360 return -EOPNOTSUPP;
4361
Ayala Bekere4208422015-10-23 11:20:06 +03004362 /*
4363 * AID and listen_interval properties can be set only for unassociated
4364 * station. Include these parameters here and will check them in
4365 * cfg80211_check_station_change().
4366 */
Ayala Bekera9bc31e2015-11-26 16:26:12 +01004367 if (info->attrs[NL80211_ATTR_STA_AID])
4368 params.aid = nla_get_u16(info->attrs[NL80211_ATTR_STA_AID]);
Ayala Bekere4208422015-10-23 11:20:06 +03004369
4370 if (info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL])
4371 params.listen_interval =
4372 nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]);
4373 else
4374 params.listen_interval = -1;
Johannes Berg5727ef12007-12-19 02:03:34 +01004375
Ayala Beker17b94242016-03-17 15:41:38 +02004376 if (info->attrs[NL80211_ATTR_STA_SUPPORT_P2P_PS]) {
4377 u8 tmp;
4378
4379 tmp = nla_get_u8(info->attrs[NL80211_ATTR_STA_SUPPORT_P2P_PS]);
4380 if (tmp >= NUM_NL80211_P2P_PS_STATUS)
4381 return -EINVAL;
4382
4383 params.support_p2p_ps = tmp;
4384 } else {
4385 params.support_p2p_ps = -1;
4386 }
4387
Johannes Berg5727ef12007-12-19 02:03:34 +01004388 if (!info->attrs[NL80211_ATTR_MAC])
4389 return -EINVAL;
4390
4391 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
4392
4393 if (info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) {
4394 params.supported_rates =
4395 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
4396 params.supported_rates_len =
4397 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
4398 }
4399
Jouni Malinen9d62a982013-02-14 21:10:13 +02004400 if (info->attrs[NL80211_ATTR_STA_CAPABILITY]) {
4401 params.capability =
4402 nla_get_u16(info->attrs[NL80211_ATTR_STA_CAPABILITY]);
4403 params.sta_modify_mask |= STATION_PARAM_APPLY_CAPABILITY;
4404 }
4405
4406 if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]) {
4407 params.ext_capab =
4408 nla_data(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
4409 params.ext_capab_len =
4410 nla_len(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
4411 }
4412
Johannes Bergbdd3ae32012-01-02 13:30:03 +01004413 if (parse_station_flags(info, dev->ieee80211_ptr->iftype, &params))
Johannes Berg5727ef12007-12-19 02:03:34 +01004414 return -EINVAL;
4415
Johannes Bergf8bacc22013-02-14 23:27:01 +01004416 if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) {
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004417 params.plink_action =
Johannes Bergf8bacc22013-02-14 23:27:01 +01004418 nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]);
4419 if (params.plink_action >= NUM_NL80211_PLINK_ACTIONS)
4420 return -EINVAL;
4421 }
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004422
Johannes Bergf8bacc22013-02-14 23:27:01 +01004423 if (info->attrs[NL80211_ATTR_STA_PLINK_STATE]) {
Javier Cardona9c3990a2011-05-03 16:57:11 -07004424 params.plink_state =
Johannes Bergf8bacc22013-02-14 23:27:01 +01004425 nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_STATE]);
4426 if (params.plink_state >= NUM_NL80211_PLINK_STATES)
4427 return -EINVAL;
Masashi Honma7d27a0b2016-07-01 10:19:34 +09004428 if (info->attrs[NL80211_ATTR_MESH_PEER_AID]) {
4429 params.peer_aid = nla_get_u16(
4430 info->attrs[NL80211_ATTR_MESH_PEER_AID]);
4431 if (params.peer_aid > IEEE80211_MAX_AID)
4432 return -EINVAL;
4433 }
Johannes Bergf8bacc22013-02-14 23:27:01 +01004434 params.sta_modify_mask |= STATION_PARAM_APPLY_PLINK_STATE;
4435 }
Javier Cardona9c3990a2011-05-03 16:57:11 -07004436
Marco Porsch3b1c5a52013-01-07 16:04:52 +01004437 if (info->attrs[NL80211_ATTR_LOCAL_MESH_POWER_MODE]) {
4438 enum nl80211_mesh_power_mode pm = nla_get_u32(
4439 info->attrs[NL80211_ATTR_LOCAL_MESH_POWER_MODE]);
4440
4441 if (pm <= NL80211_MESH_POWER_UNKNOWN ||
4442 pm > NL80211_MESH_POWER_MAX)
4443 return -EINVAL;
4444
4445 params.local_pm = pm;
4446 }
4447
Johannes Berg77ee7c82013-02-15 00:48:33 +01004448 /* Include parameters for TDLS peer (will check later) */
4449 err = nl80211_set_station_tdls(info, &params);
4450 if (err)
4451 return err;
4452
4453 params.vlan = get_vlan(info, rdev);
4454 if (IS_ERR(params.vlan))
4455 return PTR_ERR(params.vlan);
4456
Johannes Berga97f4422009-06-18 17:23:43 +02004457 switch (dev->ieee80211_ptr->iftype) {
4458 case NL80211_IFTYPE_AP:
4459 case NL80211_IFTYPE_AP_VLAN:
Johannes Berg074ac8d2010-09-16 14:58:22 +02004460 case NL80211_IFTYPE_P2P_GO:
Johannes Berg074ac8d2010-09-16 14:58:22 +02004461 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Berga97f4422009-06-18 17:23:43 +02004462 case NL80211_IFTYPE_STATION:
Antonio Quartulli267335d2012-01-31 20:25:47 +01004463 case NL80211_IFTYPE_ADHOC:
Johannes Berga97f4422009-06-18 17:23:43 +02004464 case NL80211_IFTYPE_MESH_POINT:
Johannes Berga97f4422009-06-18 17:23:43 +02004465 break;
4466 default:
Johannes Berg77ee7c82013-02-15 00:48:33 +01004467 err = -EOPNOTSUPP;
4468 goto out_put_vlan;
Johannes Berg034d6552009-05-27 10:35:29 +02004469 }
4470
Johannes Berg77ee7c82013-02-15 00:48:33 +01004471 /* driver will call cfg80211_check_station_change() */
Hila Gonene35e4d22012-06-27 17:19:42 +03004472 err = rdev_change_station(rdev, dev, mac_addr, &params);
Johannes Berg5727ef12007-12-19 02:03:34 +01004473
Johannes Berg77ee7c82013-02-15 00:48:33 +01004474 out_put_vlan:
Johannes Berg5727ef12007-12-19 02:03:34 +01004475 if (params.vlan)
4476 dev_put(params.vlan);
Johannes Berg3b858752009-03-12 09:55:09 +01004477
Johannes Berg5727ef12007-12-19 02:03:34 +01004478 return err;
4479}
4480
4481static int nl80211_new_station(struct sk_buff *skb, struct genl_info *info)
4482{
Johannes Berg4c476992010-10-04 21:36:35 +02004483 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg5727ef12007-12-19 02:03:34 +01004484 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02004485 struct net_device *dev = info->user_ptr[1];
Johannes Berg5727ef12007-12-19 02:03:34 +01004486 struct station_parameters params;
4487 u8 *mac_addr = NULL;
Johannes Bergbda95eb2015-11-26 16:26:13 +01004488 u32 auth_assoc = BIT(NL80211_STA_FLAG_AUTHENTICATED) |
4489 BIT(NL80211_STA_FLAG_ASSOCIATED);
Johannes Berg5727ef12007-12-19 02:03:34 +01004490
4491 memset(&params, 0, sizeof(params));
4492
Johannes Berg984c3112013-02-14 23:43:25 +01004493 if (!rdev->ops->add_station)
4494 return -EOPNOTSUPP;
4495
Johannes Berg5727ef12007-12-19 02:03:34 +01004496 if (!info->attrs[NL80211_ATTR_MAC])
4497 return -EINVAL;
4498
Johannes Berg5727ef12007-12-19 02:03:34 +01004499 if (!info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL])
4500 return -EINVAL;
4501
4502 if (!info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES])
4503 return -EINVAL;
4504
Jouni Malinen5e4b6f52013-05-16 20:11:08 +03004505 if (!info->attrs[NL80211_ATTR_STA_AID] &&
4506 !info->attrs[NL80211_ATTR_PEER_AID])
Thadeu Lima de Souza Cascardo0e956c12010-02-12 12:34:50 -02004507 return -EINVAL;
4508
Johannes Berg5727ef12007-12-19 02:03:34 +01004509 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
4510 params.supported_rates =
4511 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
4512 params.supported_rates_len =
4513 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
4514 params.listen_interval =
4515 nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]);
Johannes Berg51b50fb2009-05-24 16:42:30 +02004516
Ayala Beker17b94242016-03-17 15:41:38 +02004517 if (info->attrs[NL80211_ATTR_STA_SUPPORT_P2P_PS]) {
4518 u8 tmp;
4519
4520 tmp = nla_get_u8(info->attrs[NL80211_ATTR_STA_SUPPORT_P2P_PS]);
4521 if (tmp >= NUM_NL80211_P2P_PS_STATUS)
4522 return -EINVAL;
4523
4524 params.support_p2p_ps = tmp;
4525 } else {
4526 /*
4527 * if not specified, assume it's supported for P2P GO interface,
4528 * and is NOT supported for AP interface
4529 */
4530 params.support_p2p_ps =
4531 dev->ieee80211_ptr->iftype == NL80211_IFTYPE_P2P_GO;
4532 }
4533
Jouni Malinen3d124ea2013-05-27 18:24:02 +03004534 if (info->attrs[NL80211_ATTR_PEER_AID])
Jouni Malinen5e4b6f52013-05-16 20:11:08 +03004535 params.aid = nla_get_u16(info->attrs[NL80211_ATTR_PEER_AID]);
Jouni Malinen3d124ea2013-05-27 18:24:02 +03004536 else
4537 params.aid = nla_get_u16(info->attrs[NL80211_ATTR_STA_AID]);
Thadeu Lima de Souza Cascardo0e956c12010-02-12 12:34:50 -02004538 if (!params.aid || params.aid > IEEE80211_MAX_AID)
4539 return -EINVAL;
Johannes Berg51b50fb2009-05-24 16:42:30 +02004540
Jouni Malinen9d62a982013-02-14 21:10:13 +02004541 if (info->attrs[NL80211_ATTR_STA_CAPABILITY]) {
4542 params.capability =
4543 nla_get_u16(info->attrs[NL80211_ATTR_STA_CAPABILITY]);
4544 params.sta_modify_mask |= STATION_PARAM_APPLY_CAPABILITY;
4545 }
4546
4547 if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]) {
4548 params.ext_capab =
4549 nla_data(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
4550 params.ext_capab_len =
4551 nla_len(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
4552 }
4553
Jouni Malinen36aedc902008-08-25 11:58:58 +03004554 if (info->attrs[NL80211_ATTR_HT_CAPABILITY])
4555 params.ht_capa =
4556 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]);
Johannes Berg5727ef12007-12-19 02:03:34 +01004557
Mahesh Palivelaf461be3e2012-10-11 08:04:52 +00004558 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY])
4559 params.vht_capa =
4560 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]);
4561
Marek Kwaczynski60f4a7b2013-12-03 10:04:59 +01004562 if (info->attrs[NL80211_ATTR_OPMODE_NOTIF]) {
4563 params.opmode_notif_used = true;
4564 params.opmode_notif =
4565 nla_get_u8(info->attrs[NL80211_ATTR_OPMODE_NOTIF]);
4566 }
4567
Johannes Bergf8bacc22013-02-14 23:27:01 +01004568 if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) {
Javier Cardona96b78df2011-04-07 15:08:33 -07004569 params.plink_action =
Johannes Bergf8bacc22013-02-14 23:27:01 +01004570 nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]);
4571 if (params.plink_action >= NUM_NL80211_PLINK_ACTIONS)
4572 return -EINVAL;
4573 }
Javier Cardona96b78df2011-04-07 15:08:33 -07004574
Sunil Duttc01fc9a2013-10-09 20:45:21 +05304575 err = nl80211_parse_sta_channel_info(info, &params);
4576 if (err)
4577 return err;
4578
Johannes Bergff276692013-02-15 00:09:01 +01004579 err = nl80211_parse_sta_wme(info, &params);
4580 if (err)
4581 return err;
Johannes Bergbdd90d52011-12-14 12:20:27 +01004582
Johannes Bergbdd3ae32012-01-02 13:30:03 +01004583 if (parse_station_flags(info, dev->ieee80211_ptr->iftype, &params))
Johannes Berg5727ef12007-12-19 02:03:34 +01004584 return -EINVAL;
4585
Johannes Berg496fcc22015-03-12 08:53:27 +02004586 /* HT/VHT requires QoS, but if we don't have that just ignore HT/VHT
4587 * as userspace might just pass through the capabilities from the IEs
4588 * directly, rather than enforcing this restriction and returning an
4589 * error in this case.
4590 */
4591 if (!(params.sta_flags_set & BIT(NL80211_STA_FLAG_WME))) {
4592 params.ht_capa = NULL;
4593 params.vht_capa = NULL;
4594 }
4595
Johannes Berg77ee7c82013-02-15 00:48:33 +01004596 /* When you run into this, adjust the code below for the new flag */
4597 BUILD_BUG_ON(NL80211_STA_FLAG_MAX != 7);
4598
Johannes Bergbdd90d52011-12-14 12:20:27 +01004599 switch (dev->ieee80211_ptr->iftype) {
4600 case NL80211_IFTYPE_AP:
4601 case NL80211_IFTYPE_AP_VLAN:
4602 case NL80211_IFTYPE_P2P_GO:
Johannes Berg984c3112013-02-14 23:43:25 +01004603 /* ignore WME attributes if iface/sta is not capable */
4604 if (!(rdev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) ||
4605 !(params.sta_flags_set & BIT(NL80211_STA_FLAG_WME)))
4606 params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD;
Eliad Pellerc75786c2011-08-23 14:37:46 +03004607
Johannes Bergbdd90d52011-12-14 12:20:27 +01004608 /* TDLS peers cannot be added */
Jouni Malinen3d124ea2013-05-27 18:24:02 +03004609 if ((params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) ||
4610 info->attrs[NL80211_ATTR_PEER_AID])
Johannes Berg4319e192011-09-07 11:50:48 +02004611 return -EINVAL;
Johannes Bergbdd90d52011-12-14 12:20:27 +01004612 /* but don't bother the driver with it */
4613 params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER);
Eliad Pellerc75786c2011-08-23 14:37:46 +03004614
Johannes Bergd582cff2012-10-26 17:53:44 +02004615 /* allow authenticated/associated only if driver handles it */
4616 if (!(rdev->wiphy.features &
4617 NL80211_FEATURE_FULL_AP_CLIENT_STATE) &&
Johannes Bergbda95eb2015-11-26 16:26:13 +01004618 params.sta_flags_mask & auth_assoc)
Johannes Bergd582cff2012-10-26 17:53:44 +02004619 return -EINVAL;
4620
Johannes Bergbda95eb2015-11-26 16:26:13 +01004621 /* Older userspace, or userspace wanting to be compatible with
4622 * !NL80211_FEATURE_FULL_AP_CLIENT_STATE, will not set the auth
4623 * and assoc flags in the mask, but assumes the station will be
4624 * added as associated anyway since this was the required driver
4625 * behaviour before NL80211_FEATURE_FULL_AP_CLIENT_STATE was
4626 * introduced.
4627 * In order to not bother drivers with this quirk in the API
4628 * set the flags in both the mask and set for new stations in
4629 * this case.
4630 */
4631 if (!(params.sta_flags_mask & auth_assoc)) {
4632 params.sta_flags_mask |= auth_assoc;
4633 params.sta_flags_set |= auth_assoc;
4634 }
4635
Johannes Bergbdd90d52011-12-14 12:20:27 +01004636 /* must be last in here for error handling */
4637 params.vlan = get_vlan(info, rdev);
4638 if (IS_ERR(params.vlan))
4639 return PTR_ERR(params.vlan);
4640 break;
4641 case NL80211_IFTYPE_MESH_POINT:
Johannes Berg984c3112013-02-14 23:43:25 +01004642 /* ignore uAPSD data */
4643 params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD;
4644
Johannes Bergd582cff2012-10-26 17:53:44 +02004645 /* associated is disallowed */
4646 if (params.sta_flags_mask & BIT(NL80211_STA_FLAG_ASSOCIATED))
4647 return -EINVAL;
Johannes Bergbdd90d52011-12-14 12:20:27 +01004648 /* TDLS peers cannot be added */
Jouni Malinen3d124ea2013-05-27 18:24:02 +03004649 if ((params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) ||
4650 info->attrs[NL80211_ATTR_PEER_AID])
Johannes Berg4319e192011-09-07 11:50:48 +02004651 return -EINVAL;
Johannes Bergbdd90d52011-12-14 12:20:27 +01004652 break;
4653 case NL80211_IFTYPE_STATION:
Johannes Berg93d08f02013-03-04 09:29:46 +01004654 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Berg984c3112013-02-14 23:43:25 +01004655 /* ignore uAPSD data */
4656 params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD;
4657
Johannes Berg77ee7c82013-02-15 00:48:33 +01004658 /* these are disallowed */
4659 if (params.sta_flags_mask &
4660 (BIT(NL80211_STA_FLAG_ASSOCIATED) |
4661 BIT(NL80211_STA_FLAG_AUTHENTICATED)))
Johannes Bergd582cff2012-10-26 17:53:44 +02004662 return -EINVAL;
Johannes Bergbdd90d52011-12-14 12:20:27 +01004663 /* Only TDLS peers can be added */
4664 if (!(params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)))
4665 return -EINVAL;
4666 /* Can only add if TDLS ... */
4667 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS))
4668 return -EOPNOTSUPP;
4669 /* ... with external setup is supported */
4670 if (!(rdev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP))
4671 return -EOPNOTSUPP;
Johannes Berg77ee7c82013-02-15 00:48:33 +01004672 /*
4673 * Older wpa_supplicant versions always mark the TDLS peer
4674 * as authorized, but it shouldn't yet be.
4675 */
4676 params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_AUTHORIZED);
Johannes Bergbdd90d52011-12-14 12:20:27 +01004677 break;
4678 default:
4679 return -EOPNOTSUPP;
Eliad Pellerc75786c2011-08-23 14:37:46 +03004680 }
4681
Johannes Bergbdd90d52011-12-14 12:20:27 +01004682 /* be aware of params.vlan when changing code here */
Johannes Berg5727ef12007-12-19 02:03:34 +01004683
Hila Gonene35e4d22012-06-27 17:19:42 +03004684 err = rdev_add_station(rdev, dev, mac_addr, &params);
Johannes Berg5727ef12007-12-19 02:03:34 +01004685
Johannes Berg5727ef12007-12-19 02:03:34 +01004686 if (params.vlan)
4687 dev_put(params.vlan);
Johannes Berg5727ef12007-12-19 02:03:34 +01004688 return err;
4689}
4690
4691static int nl80211_del_station(struct sk_buff *skb, struct genl_info *info)
4692{
Johannes Berg4c476992010-10-04 21:36:35 +02004693 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4694 struct net_device *dev = info->user_ptr[1];
Jouni Malinen89c771e2014-10-10 20:52:40 +03004695 struct station_del_parameters params;
4696
4697 memset(&params, 0, sizeof(params));
Johannes Berg5727ef12007-12-19 02:03:34 +01004698
4699 if (info->attrs[NL80211_ATTR_MAC])
Jouni Malinen89c771e2014-10-10 20:52:40 +03004700 params.mac = nla_data(info->attrs[NL80211_ATTR_MAC]);
Johannes Berg5727ef12007-12-19 02:03:34 +01004701
Johannes Berge80cf852009-05-11 14:43:13 +02004702 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
Marco Porschd5d9de02010-03-30 10:00:16 +02004703 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN &&
Johannes Berg074ac8d2010-09-16 14:58:22 +02004704 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT &&
Johannes Berg4c476992010-10-04 21:36:35 +02004705 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
4706 return -EINVAL;
Johannes Berge80cf852009-05-11 14:43:13 +02004707
Johannes Berg4c476992010-10-04 21:36:35 +02004708 if (!rdev->ops->del_station)
4709 return -EOPNOTSUPP;
Johannes Berg5727ef12007-12-19 02:03:34 +01004710
Jouni Malinen98856862014-10-20 13:20:45 +03004711 if (info->attrs[NL80211_ATTR_MGMT_SUBTYPE]) {
4712 params.subtype =
4713 nla_get_u8(info->attrs[NL80211_ATTR_MGMT_SUBTYPE]);
4714 if (params.subtype != IEEE80211_STYPE_DISASSOC >> 4 &&
4715 params.subtype != IEEE80211_STYPE_DEAUTH >> 4)
4716 return -EINVAL;
4717 } else {
4718 /* Default to Deauthentication frame */
4719 params.subtype = IEEE80211_STYPE_DEAUTH >> 4;
4720 }
4721
4722 if (info->attrs[NL80211_ATTR_REASON_CODE]) {
4723 params.reason_code =
4724 nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
4725 if (params.reason_code == 0)
4726 return -EINVAL; /* 0 is reserved */
4727 } else {
4728 /* Default to reason code 2 */
4729 params.reason_code = WLAN_REASON_PREV_AUTH_NOT_VALID;
4730 }
4731
Jouni Malinen89c771e2014-10-10 20:52:40 +03004732 return rdev_del_station(rdev, dev, &params);
Johannes Berg5727ef12007-12-19 02:03:34 +01004733}
4734
Eric W. Biederman15e47302012-09-07 20:12:54 +00004735static int nl80211_send_mpath(struct sk_buff *msg, u32 portid, u32 seq,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004736 int flags, struct net_device *dev,
4737 u8 *dst, u8 *next_hop,
4738 struct mpath_info *pinfo)
4739{
4740 void *hdr;
4741 struct nlattr *pinfoattr;
4742
Henning Rogge1ef4c852014-11-04 16:14:58 +01004743 hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_MPATH);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004744 if (!hdr)
4745 return -1;
4746
David S. Miller9360ffd2012-03-29 04:41:26 -04004747 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
4748 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, dst) ||
4749 nla_put(msg, NL80211_ATTR_MPATH_NEXT_HOP, ETH_ALEN, next_hop) ||
4750 nla_put_u32(msg, NL80211_ATTR_GENERATION, pinfo->generation))
4751 goto nla_put_failure;
Johannes Bergf5ea9122009-08-07 16:17:38 +02004752
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004753 pinfoattr = nla_nest_start(msg, NL80211_ATTR_MPATH_INFO);
4754 if (!pinfoattr)
4755 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04004756 if ((pinfo->filled & MPATH_INFO_FRAME_QLEN) &&
4757 nla_put_u32(msg, NL80211_MPATH_INFO_FRAME_QLEN,
4758 pinfo->frame_qlen))
4759 goto nla_put_failure;
4760 if (((pinfo->filled & MPATH_INFO_SN) &&
4761 nla_put_u32(msg, NL80211_MPATH_INFO_SN, pinfo->sn)) ||
4762 ((pinfo->filled & MPATH_INFO_METRIC) &&
4763 nla_put_u32(msg, NL80211_MPATH_INFO_METRIC,
4764 pinfo->metric)) ||
4765 ((pinfo->filled & MPATH_INFO_EXPTIME) &&
4766 nla_put_u32(msg, NL80211_MPATH_INFO_EXPTIME,
4767 pinfo->exptime)) ||
4768 ((pinfo->filled & MPATH_INFO_FLAGS) &&
4769 nla_put_u8(msg, NL80211_MPATH_INFO_FLAGS,
4770 pinfo->flags)) ||
4771 ((pinfo->filled & MPATH_INFO_DISCOVERY_TIMEOUT) &&
4772 nla_put_u32(msg, NL80211_MPATH_INFO_DISCOVERY_TIMEOUT,
4773 pinfo->discovery_timeout)) ||
4774 ((pinfo->filled & MPATH_INFO_DISCOVERY_RETRIES) &&
4775 nla_put_u8(msg, NL80211_MPATH_INFO_DISCOVERY_RETRIES,
4776 pinfo->discovery_retries)))
4777 goto nla_put_failure;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004778
4779 nla_nest_end(msg, pinfoattr);
4780
Johannes Berg053c0952015-01-16 22:09:00 +01004781 genlmsg_end(msg, hdr);
4782 return 0;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004783
4784 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07004785 genlmsg_cancel(msg, hdr);
4786 return -EMSGSIZE;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004787}
4788
4789static int nl80211_dump_mpath(struct sk_buff *skb,
Johannes Bergbba95fe2008-07-29 13:22:51 +02004790 struct netlink_callback *cb)
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004791{
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004792 struct mpath_info pinfo;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08004793 struct cfg80211_registered_device *rdev;
Johannes Berg97990a02013-04-19 01:02:55 +02004794 struct wireless_dev *wdev;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004795 u8 dst[ETH_ALEN];
4796 u8 next_hop[ETH_ALEN];
Johannes Berg97990a02013-04-19 01:02:55 +02004797 int path_idx = cb->args[2];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004798 int err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004799
Zhao, Gang1b8ec872014-04-21 12:53:02 +08004800 err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev);
Johannes Berg67748892010-10-04 21:14:06 +02004801 if (err)
4802 return err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004803
Zhao, Gang1b8ec872014-04-21 12:53:02 +08004804 if (!rdev->ops->dump_mpath) {
Jouni Malineneec60b02009-03-20 21:21:19 +02004805 err = -EOPNOTSUPP;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004806 goto out_err;
4807 }
4808
Johannes Berg97990a02013-04-19 01:02:55 +02004809 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) {
Jouni Malineneec60b02009-03-20 21:21:19 +02004810 err = -EOPNOTSUPP;
Roel Kluin0448b5f2009-08-22 21:15:49 +02004811 goto out_err;
Jouni Malineneec60b02009-03-20 21:21:19 +02004812 }
4813
Johannes Bergbba95fe2008-07-29 13:22:51 +02004814 while (1) {
Zhao, Gang1b8ec872014-04-21 12:53:02 +08004815 err = rdev_dump_mpath(rdev, wdev->netdev, path_idx, dst,
Johannes Berg97990a02013-04-19 01:02:55 +02004816 next_hop, &pinfo);
Johannes Bergbba95fe2008-07-29 13:22:51 +02004817 if (err == -ENOENT)
4818 break;
4819 if (err)
Johannes Berg3b858752009-03-12 09:55:09 +01004820 goto out_err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004821
Eric W. Biederman15e47302012-09-07 20:12:54 +00004822 if (nl80211_send_mpath(skb, NETLINK_CB(cb->skb).portid,
Johannes Bergbba95fe2008-07-29 13:22:51 +02004823 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Johannes Berg97990a02013-04-19 01:02:55 +02004824 wdev->netdev, dst, next_hop,
Johannes Bergbba95fe2008-07-29 13:22:51 +02004825 &pinfo) < 0)
4826 goto out;
4827
4828 path_idx++;
4829 }
4830
Johannes Bergbba95fe2008-07-29 13:22:51 +02004831 out:
Johannes Berg97990a02013-04-19 01:02:55 +02004832 cb->args[2] = path_idx;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004833 err = skb->len;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004834 out_err:
Zhao, Gang1b8ec872014-04-21 12:53:02 +08004835 nl80211_finish_wdev_dump(rdev);
Johannes Bergbba95fe2008-07-29 13:22:51 +02004836 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004837}
4838
4839static int nl80211_get_mpath(struct sk_buff *skb, struct genl_info *info)
4840{
Johannes Berg4c476992010-10-04 21:36:35 +02004841 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004842 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02004843 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004844 struct mpath_info pinfo;
4845 struct sk_buff *msg;
4846 u8 *dst = NULL;
4847 u8 next_hop[ETH_ALEN];
4848
4849 memset(&pinfo, 0, sizeof(pinfo));
4850
4851 if (!info->attrs[NL80211_ATTR_MAC])
4852 return -EINVAL;
4853
4854 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
4855
Johannes Berg4c476992010-10-04 21:36:35 +02004856 if (!rdev->ops->get_mpath)
4857 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01004858
Johannes Berg4c476992010-10-04 21:36:35 +02004859 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
4860 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02004861
Hila Gonene35e4d22012-06-27 17:19:42 +03004862 err = rdev_get_mpath(rdev, dev, dst, next_hop, &pinfo);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004863 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02004864 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004865
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07004866 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004867 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02004868 return -ENOMEM;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004869
Eric W. Biederman15e47302012-09-07 20:12:54 +00004870 if (nl80211_send_mpath(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berg4c476992010-10-04 21:36:35 +02004871 dev, dst, next_hop, &pinfo) < 0) {
4872 nlmsg_free(msg);
4873 return -ENOBUFS;
4874 }
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004875
Johannes Berg4c476992010-10-04 21:36:35 +02004876 return genlmsg_reply(msg, info);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004877}
4878
4879static int nl80211_set_mpath(struct sk_buff *skb, struct genl_info *info)
4880{
Johannes Berg4c476992010-10-04 21:36:35 +02004881 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4882 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004883 u8 *dst = NULL;
4884 u8 *next_hop = NULL;
4885
4886 if (!info->attrs[NL80211_ATTR_MAC])
4887 return -EINVAL;
4888
4889 if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP])
4890 return -EINVAL;
4891
4892 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
4893 next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]);
4894
Johannes Berg4c476992010-10-04 21:36:35 +02004895 if (!rdev->ops->change_mpath)
4896 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01004897
Johannes Berg4c476992010-10-04 21:36:35 +02004898 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
4899 return -EOPNOTSUPP;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004900
Hila Gonene35e4d22012-06-27 17:19:42 +03004901 return rdev_change_mpath(rdev, dev, dst, next_hop);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004902}
Johannes Berg4c476992010-10-04 21:36:35 +02004903
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004904static int nl80211_new_mpath(struct sk_buff *skb, struct genl_info *info)
4905{
Johannes Berg4c476992010-10-04 21:36:35 +02004906 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4907 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004908 u8 *dst = NULL;
4909 u8 *next_hop = NULL;
4910
4911 if (!info->attrs[NL80211_ATTR_MAC])
4912 return -EINVAL;
4913
4914 if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP])
4915 return -EINVAL;
4916
4917 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
4918 next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]);
4919
Johannes Berg4c476992010-10-04 21:36:35 +02004920 if (!rdev->ops->add_mpath)
4921 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01004922
Johannes Berg4c476992010-10-04 21:36:35 +02004923 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
4924 return -EOPNOTSUPP;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004925
Hila Gonene35e4d22012-06-27 17:19:42 +03004926 return rdev_add_mpath(rdev, dev, dst, next_hop);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004927}
4928
4929static int nl80211_del_mpath(struct sk_buff *skb, struct genl_info *info)
4930{
Johannes Berg4c476992010-10-04 21:36:35 +02004931 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4932 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004933 u8 *dst = NULL;
4934
4935 if (info->attrs[NL80211_ATTR_MAC])
4936 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
4937
Johannes Berg4c476992010-10-04 21:36:35 +02004938 if (!rdev->ops->del_mpath)
4939 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01004940
Hila Gonene35e4d22012-06-27 17:19:42 +03004941 return rdev_del_mpath(rdev, dev, dst);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004942}
4943
Henning Rogge66be7d22014-09-12 08:58:49 +02004944static int nl80211_get_mpp(struct sk_buff *skb, struct genl_info *info)
4945{
4946 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4947 int err;
4948 struct net_device *dev = info->user_ptr[1];
4949 struct mpath_info pinfo;
4950 struct sk_buff *msg;
4951 u8 *dst = NULL;
4952 u8 mpp[ETH_ALEN];
4953
4954 memset(&pinfo, 0, sizeof(pinfo));
4955
4956 if (!info->attrs[NL80211_ATTR_MAC])
4957 return -EINVAL;
4958
4959 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
4960
4961 if (!rdev->ops->get_mpp)
4962 return -EOPNOTSUPP;
4963
4964 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
4965 return -EOPNOTSUPP;
4966
4967 err = rdev_get_mpp(rdev, dev, dst, mpp, &pinfo);
4968 if (err)
4969 return err;
4970
4971 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
4972 if (!msg)
4973 return -ENOMEM;
4974
4975 if (nl80211_send_mpath(msg, info->snd_portid, info->snd_seq, 0,
4976 dev, dst, mpp, &pinfo) < 0) {
4977 nlmsg_free(msg);
4978 return -ENOBUFS;
4979 }
4980
4981 return genlmsg_reply(msg, info);
4982}
4983
4984static int nl80211_dump_mpp(struct sk_buff *skb,
4985 struct netlink_callback *cb)
4986{
4987 struct mpath_info pinfo;
4988 struct cfg80211_registered_device *rdev;
4989 struct wireless_dev *wdev;
4990 u8 dst[ETH_ALEN];
4991 u8 mpp[ETH_ALEN];
4992 int path_idx = cb->args[2];
4993 int err;
4994
4995 err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev);
4996 if (err)
4997 return err;
4998
4999 if (!rdev->ops->dump_mpp) {
5000 err = -EOPNOTSUPP;
5001 goto out_err;
5002 }
5003
5004 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) {
5005 err = -EOPNOTSUPP;
5006 goto out_err;
5007 }
5008
5009 while (1) {
5010 err = rdev_dump_mpp(rdev, wdev->netdev, path_idx, dst,
5011 mpp, &pinfo);
5012 if (err == -ENOENT)
5013 break;
5014 if (err)
5015 goto out_err;
5016
5017 if (nl80211_send_mpath(skb, NETLINK_CB(cb->skb).portid,
5018 cb->nlh->nlmsg_seq, NLM_F_MULTI,
5019 wdev->netdev, dst, mpp,
5020 &pinfo) < 0)
5021 goto out;
5022
5023 path_idx++;
5024 }
5025
5026 out:
5027 cb->args[2] = path_idx;
5028 err = skb->len;
5029 out_err:
5030 nl80211_finish_wdev_dump(rdev);
5031 return err;
5032}
5033
Jouni Malinen9f1ba902008-08-07 20:07:01 +03005034static int nl80211_set_bss(struct sk_buff *skb, struct genl_info *info)
5035{
Johannes Berg4c476992010-10-04 21:36:35 +02005036 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5037 struct net_device *dev = info->user_ptr[1];
Simon Wunderlichc56589e2013-11-21 18:19:49 +01005038 struct wireless_dev *wdev = dev->ieee80211_ptr;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03005039 struct bss_parameters params;
Simon Wunderlichc56589e2013-11-21 18:19:49 +01005040 int err;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03005041
5042 memset(&params, 0, sizeof(params));
5043 /* default to not changing parameters */
5044 params.use_cts_prot = -1;
5045 params.use_short_preamble = -1;
5046 params.use_short_slot_time = -1;
Felix Fietkaufd8aaaf2010-04-27 01:23:35 +02005047 params.ap_isolate = -1;
Helmut Schaa50b12f52010-11-19 12:40:25 +01005048 params.ht_opmode = -1;
Johannes Berg53cabad2012-11-14 15:17:28 +01005049 params.p2p_ctwindow = -1;
5050 params.p2p_opp_ps = -1;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03005051
5052 if (info->attrs[NL80211_ATTR_BSS_CTS_PROT])
5053 params.use_cts_prot =
5054 nla_get_u8(info->attrs[NL80211_ATTR_BSS_CTS_PROT]);
5055 if (info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE])
5056 params.use_short_preamble =
5057 nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]);
5058 if (info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME])
5059 params.use_short_slot_time =
5060 nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]);
Jouni Malinen90c97a02008-10-30 16:59:22 +02005061 if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) {
5062 params.basic_rates =
5063 nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
5064 params.basic_rates_len =
5065 nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
5066 }
Felix Fietkaufd8aaaf2010-04-27 01:23:35 +02005067 if (info->attrs[NL80211_ATTR_AP_ISOLATE])
5068 params.ap_isolate = !!nla_get_u8(info->attrs[NL80211_ATTR_AP_ISOLATE]);
Helmut Schaa50b12f52010-11-19 12:40:25 +01005069 if (info->attrs[NL80211_ATTR_BSS_HT_OPMODE])
5070 params.ht_opmode =
5071 nla_get_u16(info->attrs[NL80211_ATTR_BSS_HT_OPMODE]);
Jouni Malinen9f1ba902008-08-07 20:07:01 +03005072
Johannes Berg53cabad2012-11-14 15:17:28 +01005073 if (info->attrs[NL80211_ATTR_P2P_CTWINDOW]) {
5074 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
5075 return -EINVAL;
5076 params.p2p_ctwindow =
5077 nla_get_s8(info->attrs[NL80211_ATTR_P2P_CTWINDOW]);
5078 if (params.p2p_ctwindow < 0)
5079 return -EINVAL;
5080 if (params.p2p_ctwindow != 0 &&
5081 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_CTWIN))
5082 return -EINVAL;
5083 }
5084
5085 if (info->attrs[NL80211_ATTR_P2P_OPPPS]) {
5086 u8 tmp;
5087
5088 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
5089 return -EINVAL;
5090 tmp = nla_get_u8(info->attrs[NL80211_ATTR_P2P_OPPPS]);
5091 if (tmp > 1)
5092 return -EINVAL;
5093 params.p2p_opp_ps = tmp;
5094 if (params.p2p_opp_ps &&
5095 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_OPPPS))
5096 return -EINVAL;
5097 }
5098
Johannes Berg4c476992010-10-04 21:36:35 +02005099 if (!rdev->ops->change_bss)
5100 return -EOPNOTSUPP;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03005101
Johannes Berg074ac8d2010-09-16 14:58:22 +02005102 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
Johannes Berg4c476992010-10-04 21:36:35 +02005103 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
5104 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02005105
Simon Wunderlichc56589e2013-11-21 18:19:49 +01005106 wdev_lock(wdev);
5107 err = rdev_change_bss(rdev, dev, &params);
5108 wdev_unlock(wdev);
5109
5110 return err;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03005111}
5112
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005113static int nl80211_req_set_reg(struct sk_buff *skb, struct genl_info *info)
5114{
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005115 char *data = NULL;
Ilan peer05050752015-03-04 00:32:06 -05005116 bool is_indoor;
Luis R. Rodriguez57b5ce02012-07-12 11:49:18 -07005117 enum nl80211_user_reg_hint_type user_reg_hint_type;
Ilan peer05050752015-03-04 00:32:06 -05005118 u32 owner_nlportid;
5119
Luis R. Rodriguez80778f12009-02-21 00:04:22 -05005120 /*
5121 * You should only get this when cfg80211 hasn't yet initialized
5122 * completely when built-in to the kernel right between the time
5123 * window between nl80211_init() and regulatory_init(), if that is
5124 * even possible.
5125 */
Johannes Berg458f4f92012-12-06 15:47:38 +01005126 if (unlikely(!rcu_access_pointer(cfg80211_regdomain)))
Luis R. Rodriguezfe33eb32009-02-21 00:04:30 -05005127 return -EINPROGRESS;
Luis R. Rodriguez80778f12009-02-21 00:04:22 -05005128
Luis R. Rodriguez57b5ce02012-07-12 11:49:18 -07005129 if (info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE])
5130 user_reg_hint_type =
5131 nla_get_u32(info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE]);
5132 else
5133 user_reg_hint_type = NL80211_USER_REG_HINT_USER;
5134
5135 switch (user_reg_hint_type) {
5136 case NL80211_USER_REG_HINT_USER:
5137 case NL80211_USER_REG_HINT_CELL_BASE:
Ilan Peer52616f22014-02-25 16:26:00 +02005138 if (!info->attrs[NL80211_ATTR_REG_ALPHA2])
5139 return -EINVAL;
5140
5141 data = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]);
5142 return regulatory_hint_user(data, user_reg_hint_type);
5143 case NL80211_USER_REG_HINT_INDOOR:
Ilan peer05050752015-03-04 00:32:06 -05005144 if (info->attrs[NL80211_ATTR_SOCKET_OWNER]) {
5145 owner_nlportid = info->snd_portid;
5146 is_indoor = !!info->attrs[NL80211_ATTR_REG_INDOOR];
5147 } else {
5148 owner_nlportid = 0;
5149 is_indoor = true;
5150 }
5151
5152 return regulatory_hint_indoor(is_indoor, owner_nlportid);
Luis R. Rodriguez57b5ce02012-07-12 11:49:18 -07005153 default:
5154 return -EINVAL;
5155 }
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005156}
5157
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005158static int nl80211_get_mesh_config(struct sk_buff *skb,
Johannes Berg29cbe682010-12-03 09:20:44 +01005159 struct genl_info *info)
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005160{
Johannes Berg4c476992010-10-04 21:36:35 +02005161 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg4c476992010-10-04 21:36:35 +02005162 struct net_device *dev = info->user_ptr[1];
Johannes Berg29cbe682010-12-03 09:20:44 +01005163 struct wireless_dev *wdev = dev->ieee80211_ptr;
5164 struct mesh_config cur_params;
5165 int err = 0;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005166 void *hdr;
5167 struct nlattr *pinfoattr;
5168 struct sk_buff *msg;
5169
Johannes Berg29cbe682010-12-03 09:20:44 +01005170 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT)
5171 return -EOPNOTSUPP;
5172
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005173 if (!rdev->ops->get_mesh_config)
Johannes Berg4c476992010-10-04 21:36:35 +02005174 return -EOPNOTSUPP;
Jouni Malinenf3f92582009-03-20 17:57:36 +02005175
Johannes Berg29cbe682010-12-03 09:20:44 +01005176 wdev_lock(wdev);
5177 /* If not connected, get default parameters */
5178 if (!wdev->mesh_id_len)
5179 memcpy(&cur_params, &default_mesh_config, sizeof(cur_params));
5180 else
Hila Gonene35e4d22012-06-27 17:19:42 +03005181 err = rdev_get_mesh_config(rdev, dev, &cur_params);
Johannes Berg29cbe682010-12-03 09:20:44 +01005182 wdev_unlock(wdev);
5183
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005184 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02005185 return err;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005186
5187 /* Draw up a netlink message to send back */
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07005188 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02005189 if (!msg)
5190 return -ENOMEM;
Eric W. Biederman15e47302012-09-07 20:12:54 +00005191 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005192 NL80211_CMD_GET_MESH_CONFIG);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005193 if (!hdr)
Julia Lawallefe1cf02011-01-28 15:17:11 +01005194 goto out;
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005195 pinfoattr = nla_nest_start(msg, NL80211_ATTR_MESH_CONFIG);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005196 if (!pinfoattr)
5197 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04005198 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
5199 nla_put_u16(msg, NL80211_MESHCONF_RETRY_TIMEOUT,
5200 cur_params.dot11MeshRetryTimeout) ||
5201 nla_put_u16(msg, NL80211_MESHCONF_CONFIRM_TIMEOUT,
5202 cur_params.dot11MeshConfirmTimeout) ||
5203 nla_put_u16(msg, NL80211_MESHCONF_HOLDING_TIMEOUT,
5204 cur_params.dot11MeshHoldingTimeout) ||
5205 nla_put_u16(msg, NL80211_MESHCONF_MAX_PEER_LINKS,
5206 cur_params.dot11MeshMaxPeerLinks) ||
5207 nla_put_u8(msg, NL80211_MESHCONF_MAX_RETRIES,
5208 cur_params.dot11MeshMaxRetries) ||
5209 nla_put_u8(msg, NL80211_MESHCONF_TTL,
5210 cur_params.dot11MeshTTL) ||
5211 nla_put_u8(msg, NL80211_MESHCONF_ELEMENT_TTL,
5212 cur_params.element_ttl) ||
5213 nla_put_u8(msg, NL80211_MESHCONF_AUTO_OPEN_PLINKS,
5214 cur_params.auto_open_plinks) ||
John W. Linville7eab0f62012-04-12 14:25:14 -04005215 nla_put_u32(msg, NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR,
5216 cur_params.dot11MeshNbrOffsetMaxNeighbor) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04005217 nla_put_u8(msg, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES,
5218 cur_params.dot11MeshHWMPmaxPREQretries) ||
5219 nla_put_u32(msg, NL80211_MESHCONF_PATH_REFRESH_TIME,
5220 cur_params.path_refresh_time) ||
5221 nla_put_u16(msg, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT,
5222 cur_params.min_discovery_timeout) ||
5223 nla_put_u32(msg, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT,
5224 cur_params.dot11MeshHWMPactivePathTimeout) ||
5225 nla_put_u16(msg, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL,
5226 cur_params.dot11MeshHWMPpreqMinInterval) ||
5227 nla_put_u16(msg, NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL,
5228 cur_params.dot11MeshHWMPperrMinInterval) ||
5229 nla_put_u16(msg, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME,
5230 cur_params.dot11MeshHWMPnetDiameterTraversalTime) ||
5231 nla_put_u8(msg, NL80211_MESHCONF_HWMP_ROOTMODE,
5232 cur_params.dot11MeshHWMPRootMode) ||
5233 nla_put_u16(msg, NL80211_MESHCONF_HWMP_RANN_INTERVAL,
5234 cur_params.dot11MeshHWMPRannInterval) ||
5235 nla_put_u8(msg, NL80211_MESHCONF_GATE_ANNOUNCEMENTS,
5236 cur_params.dot11MeshGateAnnouncementProtocol) ||
5237 nla_put_u8(msg, NL80211_MESHCONF_FORWARDING,
5238 cur_params.dot11MeshForwarding) ||
5239 nla_put_u32(msg, NL80211_MESHCONF_RSSI_THRESHOLD,
Ashok Nagarajan70c33ea2012-04-30 14:20:32 -07005240 cur_params.rssi_threshold) ||
5241 nla_put_u32(msg, NL80211_MESHCONF_HT_OPMODE,
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08005242 cur_params.ht_opmode) ||
5243 nla_put_u32(msg, NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT,
5244 cur_params.dot11MeshHWMPactivePathToRootTimeout) ||
5245 nla_put_u16(msg, NL80211_MESHCONF_HWMP_ROOT_INTERVAL,
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +08005246 cur_params.dot11MeshHWMProotInterval) ||
5247 nla_put_u16(msg, NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL,
Marco Porsch3b1c5a52013-01-07 16:04:52 +01005248 cur_params.dot11MeshHWMPconfirmationInterval) ||
5249 nla_put_u32(msg, NL80211_MESHCONF_POWER_MODE,
5250 cur_params.power_mode) ||
5251 nla_put_u16(msg, NL80211_MESHCONF_AWAKE_WINDOW,
Colleen Twitty8e7c0532013-06-03 09:53:39 -07005252 cur_params.dot11MeshAwakeWindowDuration) ||
5253 nla_put_u32(msg, NL80211_MESHCONF_PLINK_TIMEOUT,
5254 cur_params.plink_timeout))
David S. Miller9360ffd2012-03-29 04:41:26 -04005255 goto nla_put_failure;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005256 nla_nest_end(msg, pinfoattr);
5257 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02005258 return genlmsg_reply(msg, info);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005259
Johannes Berg3b858752009-03-12 09:55:09 +01005260 nla_put_failure:
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005261 genlmsg_cancel(msg, hdr);
Julia Lawallefe1cf02011-01-28 15:17:11 +01005262 out:
Yuri Ershovd080e272010-06-29 15:08:07 +04005263 nlmsg_free(msg);
Johannes Berg4c476992010-10-04 21:36:35 +02005264 return -ENOBUFS;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005265}
5266
Alexey Dobriyanb54452b2010-02-18 08:14:31 +00005267static const struct nla_policy nl80211_meshconf_params_policy[NL80211_MESHCONF_ATTR_MAX+1] = {
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005268 [NL80211_MESHCONF_RETRY_TIMEOUT] = { .type = NLA_U16 },
5269 [NL80211_MESHCONF_CONFIRM_TIMEOUT] = { .type = NLA_U16 },
5270 [NL80211_MESHCONF_HOLDING_TIMEOUT] = { .type = NLA_U16 },
5271 [NL80211_MESHCONF_MAX_PEER_LINKS] = { .type = NLA_U16 },
5272 [NL80211_MESHCONF_MAX_RETRIES] = { .type = NLA_U8 },
5273 [NL80211_MESHCONF_TTL] = { .type = NLA_U8 },
Javier Cardona45904f22010-12-03 09:20:40 +01005274 [NL80211_MESHCONF_ELEMENT_TTL] = { .type = NLA_U8 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005275 [NL80211_MESHCONF_AUTO_OPEN_PLINKS] = { .type = NLA_U8 },
Javier Cardonad299a1f2012-03-31 11:31:33 -07005276 [NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR] = { .type = NLA_U32 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005277 [NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES] = { .type = NLA_U8 },
5278 [NL80211_MESHCONF_PATH_REFRESH_TIME] = { .type = NLA_U32 },
5279 [NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT] = { .type = NLA_U16 },
5280 [NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT] = { .type = NLA_U32 },
5281 [NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL] = { .type = NLA_U16 },
Thomas Pedersendca7e942011-11-24 17:15:24 -08005282 [NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL] = { .type = NLA_U16 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005283 [NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME] = { .type = NLA_U16 },
Javier Cardona699403d2011-08-09 16:45:09 -07005284 [NL80211_MESHCONF_HWMP_ROOTMODE] = { .type = NLA_U8 },
Javier Cardona0507e152011-08-09 16:45:10 -07005285 [NL80211_MESHCONF_HWMP_RANN_INTERVAL] = { .type = NLA_U16 },
Javier Cardona16dd7262011-08-09 16:45:11 -07005286 [NL80211_MESHCONF_GATE_ANNOUNCEMENTS] = { .type = NLA_U8 },
Chun-Yeow Yeoh94f90652012-01-21 01:02:16 +08005287 [NL80211_MESHCONF_FORWARDING] = { .type = NLA_U8 },
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005288 [NL80211_MESHCONF_RSSI_THRESHOLD] = { .type = NLA_U32 },
5289 [NL80211_MESHCONF_HT_OPMODE] = { .type = NLA_U16 },
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08005290 [NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT] = { .type = NLA_U32 },
5291 [NL80211_MESHCONF_HWMP_ROOT_INTERVAL] = { .type = NLA_U16 },
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +08005292 [NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL] = { .type = NLA_U16 },
Marco Porsch3b1c5a52013-01-07 16:04:52 +01005293 [NL80211_MESHCONF_POWER_MODE] = { .type = NLA_U32 },
5294 [NL80211_MESHCONF_AWAKE_WINDOW] = { .type = NLA_U16 },
Colleen Twitty8e7c0532013-06-03 09:53:39 -07005295 [NL80211_MESHCONF_PLINK_TIMEOUT] = { .type = NLA_U32 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005296};
5297
Javier Cardonac80d5452010-12-16 17:37:49 -08005298static const struct nla_policy
5299 nl80211_mesh_setup_params_policy[NL80211_MESH_SETUP_ATTR_MAX+1] = {
Javier Cardonad299a1f2012-03-31 11:31:33 -07005300 [NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC] = { .type = NLA_U8 },
Javier Cardonac80d5452010-12-16 17:37:49 -08005301 [NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL] = { .type = NLA_U8 },
5302 [NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC] = { .type = NLA_U8 },
Javier Cardona15d5dda2011-04-07 15:08:28 -07005303 [NL80211_MESH_SETUP_USERSPACE_AUTH] = { .type = NLA_FLAG },
Colleen Twitty6e16d902013-05-08 11:45:59 -07005304 [NL80211_MESH_SETUP_AUTH_PROTOCOL] = { .type = NLA_U8 },
Thomas Pedersenbb2798d2013-03-04 13:06:10 -08005305 [NL80211_MESH_SETUP_USERSPACE_MPM] = { .type = NLA_FLAG },
Javier Cardona581a8b02011-04-07 15:08:27 -07005306 [NL80211_MESH_SETUP_IE] = { .type = NLA_BINARY,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005307 .len = IEEE80211_MAX_DATA_LEN },
Javier Cardonab130e5c2011-05-03 16:57:07 -07005308 [NL80211_MESH_SETUP_USERSPACE_AMPE] = { .type = NLA_FLAG },
Javier Cardonac80d5452010-12-16 17:37:49 -08005309};
5310
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005311static int nl80211_check_bool(const struct nlattr *nla, u8 min, u8 max, bool *out)
5312{
5313 u8 val = nla_get_u8(nla);
5314 if (val < min || val > max)
5315 return -EINVAL;
5316 *out = val;
5317 return 0;
5318}
5319
5320static int nl80211_check_u8(const struct nlattr *nla, u8 min, u8 max, u8 *out)
5321{
5322 u8 val = nla_get_u8(nla);
5323 if (val < min || val > max)
5324 return -EINVAL;
5325 *out = val;
5326 return 0;
5327}
5328
5329static int nl80211_check_u16(const struct nlattr *nla, u16 min, u16 max, u16 *out)
5330{
5331 u16 val = nla_get_u16(nla);
5332 if (val < min || val > max)
5333 return -EINVAL;
5334 *out = val;
5335 return 0;
5336}
5337
5338static int nl80211_check_u32(const struct nlattr *nla, u32 min, u32 max, u32 *out)
5339{
5340 u32 val = nla_get_u32(nla);
5341 if (val < min || val > max)
5342 return -EINVAL;
5343 *out = val;
5344 return 0;
5345}
5346
5347static int nl80211_check_s32(const struct nlattr *nla, s32 min, s32 max, s32 *out)
5348{
5349 s32 val = nla_get_s32(nla);
5350 if (val < min || val > max)
5351 return -EINVAL;
5352 *out = val;
5353 return 0;
5354}
5355
Johannes Bergff9a71a2016-08-11 14:59:53 +02005356static int nl80211_check_power_mode(const struct nlattr *nla,
5357 enum nl80211_mesh_power_mode min,
5358 enum nl80211_mesh_power_mode max,
5359 enum nl80211_mesh_power_mode *out)
5360{
5361 u32 val = nla_get_u32(nla);
5362 if (val < min || val > max)
5363 return -EINVAL;
5364 *out = val;
5365 return 0;
5366}
5367
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005368static int nl80211_parse_mesh_config(struct genl_info *info,
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005369 struct mesh_config *cfg,
5370 u32 *mask_out)
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005371{
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005372 struct nlattr *tb[NL80211_MESHCONF_ATTR_MAX + 1];
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005373 u32 mask = 0;
Masashi Honma97572352016-08-03 10:07:44 +09005374 u16 ht_opmode;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005375
Marco Porschea54fba2013-01-07 16:04:48 +01005376#define FILL_IN_MESH_PARAM_IF_SET(tb, cfg, param, min, max, mask, attr, fn) \
5377do { \
5378 if (tb[attr]) { \
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005379 if (fn(tb[attr], min, max, &cfg->param)) \
Marco Porschea54fba2013-01-07 16:04:48 +01005380 return -EINVAL; \
Marco Porschea54fba2013-01-07 16:04:48 +01005381 mask |= (1 << (attr - 1)); \
5382 } \
5383} while (0)
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005384
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005385 if (!info->attrs[NL80211_ATTR_MESH_CONFIG])
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005386 return -EINVAL;
5387 if (nla_parse_nested(tb, NL80211_MESHCONF_ATTR_MAX,
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005388 info->attrs[NL80211_ATTR_MESH_CONFIG],
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005389 nl80211_meshconf_params_policy))
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005390 return -EINVAL;
5391
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005392 /* This makes sure that there aren't more than 32 mesh config
5393 * parameters (otherwise our bitfield scheme would not work.) */
5394 BUILD_BUG_ON(NL80211_MESHCONF_ATTR_MAX > 32);
5395
5396 /* Fill in the params struct */
Marco Porschea54fba2013-01-07 16:04:48 +01005397 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshRetryTimeout, 1, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005398 mask, NL80211_MESHCONF_RETRY_TIMEOUT,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005399 nl80211_check_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01005400 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshConfirmTimeout, 1, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005401 mask, NL80211_MESHCONF_CONFIRM_TIMEOUT,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005402 nl80211_check_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01005403 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHoldingTimeout, 1, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005404 mask, NL80211_MESHCONF_HOLDING_TIMEOUT,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005405 nl80211_check_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01005406 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxPeerLinks, 0, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005407 mask, NL80211_MESHCONF_MAX_PEER_LINKS,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005408 nl80211_check_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01005409 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxRetries, 0, 16,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005410 mask, NL80211_MESHCONF_MAX_RETRIES,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005411 nl80211_check_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01005412 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshTTL, 1, 255,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005413 mask, NL80211_MESHCONF_TTL, nl80211_check_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01005414 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, element_ttl, 1, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005415 mask, NL80211_MESHCONF_ELEMENT_TTL,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005416 nl80211_check_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01005417 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, auto_open_plinks, 0, 1,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005418 mask, NL80211_MESHCONF_AUTO_OPEN_PLINKS,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005419 nl80211_check_bool);
Marco Porschea54fba2013-01-07 16:04:48 +01005420 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshNbrOffsetMaxNeighbor,
5421 1, 255, mask,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005422 NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005423 nl80211_check_u32);
Marco Porschea54fba2013-01-07 16:04:48 +01005424 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPmaxPREQretries, 0, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005425 mask, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005426 nl80211_check_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01005427 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, path_refresh_time, 1, 65535,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005428 mask, NL80211_MESHCONF_PATH_REFRESH_TIME,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005429 nl80211_check_u32);
Marco Porschea54fba2013-01-07 16:04:48 +01005430 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, min_discovery_timeout, 1, 65535,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005431 mask, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005432 nl80211_check_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01005433 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathTimeout,
5434 1, 65535, mask,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005435 NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005436 nl80211_check_u32);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005437 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPpreqMinInterval,
Marco Porschea54fba2013-01-07 16:04:48 +01005438 1, 65535, mask,
5439 NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005440 nl80211_check_u16);
Thomas Pedersendca7e942011-11-24 17:15:24 -08005441 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPperrMinInterval,
Marco Porschea54fba2013-01-07 16:04:48 +01005442 1, 65535, mask,
5443 NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005444 nl80211_check_u16);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005445 FILL_IN_MESH_PARAM_IF_SET(tb, cfg,
Marco Porschea54fba2013-01-07 16:04:48 +01005446 dot11MeshHWMPnetDiameterTraversalTime,
5447 1, 65535, mask,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005448 NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005449 nl80211_check_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01005450 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRootMode, 0, 4,
5451 mask, NL80211_MESHCONF_HWMP_ROOTMODE,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005452 nl80211_check_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01005453 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRannInterval, 1, 65535,
5454 mask, NL80211_MESHCONF_HWMP_RANN_INTERVAL,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005455 nl80211_check_u16);
Rui Paulo63c57232009-11-09 23:46:57 +00005456 FILL_IN_MESH_PARAM_IF_SET(tb, cfg,
Marco Porschea54fba2013-01-07 16:04:48 +01005457 dot11MeshGateAnnouncementProtocol, 0, 1,
5458 mask, NL80211_MESHCONF_GATE_ANNOUNCEMENTS,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005459 nl80211_check_bool);
Marco Porschea54fba2013-01-07 16:04:48 +01005460 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshForwarding, 0, 1,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005461 mask, NL80211_MESHCONF_FORWARDING,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005462 nl80211_check_bool);
Chun-Yeow Yeoh83374fe2013-07-11 18:24:03 +08005463 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, rssi_threshold, -255, 0,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005464 mask, NL80211_MESHCONF_RSSI_THRESHOLD,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005465 nl80211_check_s32);
Masashi Honma97572352016-08-03 10:07:44 +09005466 /*
5467 * Check HT operation mode based on
5468 * IEEE 802.11 2012 8.4.2.59 HT Operation element.
5469 */
5470 if (tb[NL80211_MESHCONF_HT_OPMODE]) {
5471 ht_opmode = nla_get_u16(tb[NL80211_MESHCONF_HT_OPMODE]);
5472
5473 if (ht_opmode & ~(IEEE80211_HT_OP_MODE_PROTECTION |
5474 IEEE80211_HT_OP_MODE_NON_GF_STA_PRSNT |
5475 IEEE80211_HT_OP_MODE_NON_HT_STA_PRSNT))
5476 return -EINVAL;
5477
5478 if ((ht_opmode & IEEE80211_HT_OP_MODE_NON_GF_STA_PRSNT) &&
5479 (ht_opmode & IEEE80211_HT_OP_MODE_NON_HT_STA_PRSNT))
5480 return -EINVAL;
5481
5482 switch (ht_opmode & IEEE80211_HT_OP_MODE_PROTECTION) {
5483 case IEEE80211_HT_OP_MODE_PROTECTION_NONE:
5484 case IEEE80211_HT_OP_MODE_PROTECTION_20MHZ:
5485 if (ht_opmode & IEEE80211_HT_OP_MODE_NON_HT_STA_PRSNT)
5486 return -EINVAL;
5487 break;
5488 case IEEE80211_HT_OP_MODE_PROTECTION_NONMEMBER:
5489 case IEEE80211_HT_OP_MODE_PROTECTION_NONHT_MIXED:
5490 if (!(ht_opmode & IEEE80211_HT_OP_MODE_NON_HT_STA_PRSNT))
5491 return -EINVAL;
5492 break;
5493 }
5494 cfg->ht_opmode = ht_opmode;
5495 }
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08005496 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathToRootTimeout,
Marco Porschea54fba2013-01-07 16:04:48 +01005497 1, 65535, mask,
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08005498 NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005499 nl80211_check_u32);
Marco Porschea54fba2013-01-07 16:04:48 +01005500 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMProotInterval, 1, 65535,
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08005501 mask, NL80211_MESHCONF_HWMP_ROOT_INTERVAL,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005502 nl80211_check_u16);
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +08005503 FILL_IN_MESH_PARAM_IF_SET(tb, cfg,
Marco Porschea54fba2013-01-07 16:04:48 +01005504 dot11MeshHWMPconfirmationInterval,
5505 1, 65535, mask,
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +08005506 NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005507 nl80211_check_u16);
Marco Porsch3b1c5a52013-01-07 16:04:52 +01005508 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, power_mode,
5509 NL80211_MESH_POWER_ACTIVE,
5510 NL80211_MESH_POWER_MAX,
5511 mask, NL80211_MESHCONF_POWER_MODE,
Johannes Bergff9a71a2016-08-11 14:59:53 +02005512 nl80211_check_power_mode);
Marco Porsch3b1c5a52013-01-07 16:04:52 +01005513 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshAwakeWindowDuration,
5514 0, 65535, mask,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005515 NL80211_MESHCONF_AWAKE_WINDOW, nl80211_check_u16);
Masashi Honma31f909a2015-02-24 22:42:16 +09005516 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, plink_timeout, 0, 0xffffffff,
Colleen Twitty8e7c0532013-06-03 09:53:39 -07005517 mask, NL80211_MESHCONF_PLINK_TIMEOUT,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005518 nl80211_check_u32);
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005519 if (mask_out)
5520 *mask_out = mask;
Javier Cardonac80d5452010-12-16 17:37:49 -08005521
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005522 return 0;
5523
5524#undef FILL_IN_MESH_PARAM_IF_SET
5525}
5526
Javier Cardonac80d5452010-12-16 17:37:49 -08005527static int nl80211_parse_mesh_setup(struct genl_info *info,
5528 struct mesh_setup *setup)
5529{
Thomas Pedersenbb2798d2013-03-04 13:06:10 -08005530 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Javier Cardonac80d5452010-12-16 17:37:49 -08005531 struct nlattr *tb[NL80211_MESH_SETUP_ATTR_MAX + 1];
5532
5533 if (!info->attrs[NL80211_ATTR_MESH_SETUP])
5534 return -EINVAL;
5535 if (nla_parse_nested(tb, NL80211_MESH_SETUP_ATTR_MAX,
5536 info->attrs[NL80211_ATTR_MESH_SETUP],
5537 nl80211_mesh_setup_params_policy))
5538 return -EINVAL;
5539
Javier Cardonad299a1f2012-03-31 11:31:33 -07005540 if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC])
5541 setup->sync_method =
5542 (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC])) ?
5543 IEEE80211_SYNC_METHOD_VENDOR :
5544 IEEE80211_SYNC_METHOD_NEIGHBOR_OFFSET;
5545
Javier Cardonac80d5452010-12-16 17:37:49 -08005546 if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL])
5547 setup->path_sel_proto =
5548 (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL])) ?
5549 IEEE80211_PATH_PROTOCOL_VENDOR :
5550 IEEE80211_PATH_PROTOCOL_HWMP;
5551
5552 if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC])
5553 setup->path_metric =
5554 (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC])) ?
5555 IEEE80211_PATH_METRIC_VENDOR :
5556 IEEE80211_PATH_METRIC_AIRTIME;
5557
Javier Cardona581a8b02011-04-07 15:08:27 -07005558 if (tb[NL80211_MESH_SETUP_IE]) {
Javier Cardonac80d5452010-12-16 17:37:49 -08005559 struct nlattr *ieattr =
Javier Cardona581a8b02011-04-07 15:08:27 -07005560 tb[NL80211_MESH_SETUP_IE];
Javier Cardonac80d5452010-12-16 17:37:49 -08005561 if (!is_valid_ie_attr(ieattr))
5562 return -EINVAL;
Javier Cardona581a8b02011-04-07 15:08:27 -07005563 setup->ie = nla_data(ieattr);
5564 setup->ie_len = nla_len(ieattr);
Javier Cardonac80d5452010-12-16 17:37:49 -08005565 }
Thomas Pedersenbb2798d2013-03-04 13:06:10 -08005566 if (tb[NL80211_MESH_SETUP_USERSPACE_MPM] &&
5567 !(rdev->wiphy.features & NL80211_FEATURE_USERSPACE_MPM))
5568 return -EINVAL;
5569 setup->user_mpm = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_MPM]);
Javier Cardonab130e5c2011-05-03 16:57:07 -07005570 setup->is_authenticated = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AUTH]);
5571 setup->is_secure = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AMPE]);
Thomas Pedersenbb2798d2013-03-04 13:06:10 -08005572 if (setup->is_secure)
5573 setup->user_mpm = true;
Javier Cardonac80d5452010-12-16 17:37:49 -08005574
Colleen Twitty6e16d902013-05-08 11:45:59 -07005575 if (tb[NL80211_MESH_SETUP_AUTH_PROTOCOL]) {
5576 if (!setup->user_mpm)
5577 return -EINVAL;
5578 setup->auth_id =
5579 nla_get_u8(tb[NL80211_MESH_SETUP_AUTH_PROTOCOL]);
5580 }
5581
Javier Cardonac80d5452010-12-16 17:37:49 -08005582 return 0;
5583}
5584
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005585static int nl80211_update_mesh_config(struct sk_buff *skb,
Johannes Berg29cbe682010-12-03 09:20:44 +01005586 struct genl_info *info)
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005587{
5588 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5589 struct net_device *dev = info->user_ptr[1];
Johannes Berg29cbe682010-12-03 09:20:44 +01005590 struct wireless_dev *wdev = dev->ieee80211_ptr;
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005591 struct mesh_config cfg;
5592 u32 mask;
5593 int err;
5594
Johannes Berg29cbe682010-12-03 09:20:44 +01005595 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT)
5596 return -EOPNOTSUPP;
5597
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005598 if (!rdev->ops->update_mesh_config)
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005599 return -EOPNOTSUPP;
5600
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005601 err = nl80211_parse_mesh_config(info, &cfg, &mask);
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005602 if (err)
5603 return err;
5604
Johannes Berg29cbe682010-12-03 09:20:44 +01005605 wdev_lock(wdev);
5606 if (!wdev->mesh_id_len)
5607 err = -ENOLINK;
5608
5609 if (!err)
Hila Gonene35e4d22012-06-27 17:19:42 +03005610 err = rdev_update_mesh_config(rdev, dev, mask, &cfg);
Johannes Berg29cbe682010-12-03 09:20:44 +01005611
5612 wdev_unlock(wdev);
5613
5614 return err;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005615}
5616
Arik Nemtsovad30ca22014-12-15 19:25:59 +02005617static int nl80211_put_regdom(const struct ieee80211_regdomain *regdom,
5618 struct sk_buff *msg)
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005619{
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005620 struct nlattr *nl_reg_rules;
5621 unsigned int i;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005622
Johannes Berg458f4f92012-12-06 15:47:38 +01005623 if (nla_put_string(msg, NL80211_ATTR_REG_ALPHA2, regdom->alpha2) ||
5624 (regdom->dfs_region &&
5625 nla_put_u8(msg, NL80211_ATTR_DFS_REGION, regdom->dfs_region)))
Arik Nemtsovad30ca22014-12-15 19:25:59 +02005626 goto nla_put_failure;
Johannes Berg458f4f92012-12-06 15:47:38 +01005627
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005628 nl_reg_rules = nla_nest_start(msg, NL80211_ATTR_REG_RULES);
5629 if (!nl_reg_rules)
Arik Nemtsovad30ca22014-12-15 19:25:59 +02005630 goto nla_put_failure;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005631
Johannes Berg458f4f92012-12-06 15:47:38 +01005632 for (i = 0; i < regdom->n_reg_rules; i++) {
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005633 struct nlattr *nl_reg_rule;
5634 const struct ieee80211_reg_rule *reg_rule;
5635 const struct ieee80211_freq_range *freq_range;
5636 const struct ieee80211_power_rule *power_rule;
Janusz Dziedzic97524822014-01-30 09:52:20 +01005637 unsigned int max_bandwidth_khz;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005638
Johannes Berg458f4f92012-12-06 15:47:38 +01005639 reg_rule = &regdom->reg_rules[i];
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005640 freq_range = &reg_rule->freq_range;
5641 power_rule = &reg_rule->power_rule;
5642
5643 nl_reg_rule = nla_nest_start(msg, i);
5644 if (!nl_reg_rule)
Arik Nemtsovad30ca22014-12-15 19:25:59 +02005645 goto nla_put_failure;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005646
Janusz Dziedzic97524822014-01-30 09:52:20 +01005647 max_bandwidth_khz = freq_range->max_bandwidth_khz;
5648 if (!max_bandwidth_khz)
5649 max_bandwidth_khz = reg_get_max_bandwidth(regdom,
5650 reg_rule);
5651
David S. Miller9360ffd2012-03-29 04:41:26 -04005652 if (nla_put_u32(msg, NL80211_ATTR_REG_RULE_FLAGS,
5653 reg_rule->flags) ||
5654 nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_START,
5655 freq_range->start_freq_khz) ||
5656 nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_END,
5657 freq_range->end_freq_khz) ||
5658 nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_MAX_BW,
Janusz Dziedzic97524822014-01-30 09:52:20 +01005659 max_bandwidth_khz) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04005660 nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN,
5661 power_rule->max_antenna_gain) ||
5662 nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_EIRP,
Janusz Dziedzic089027e2014-02-21 19:46:12 +01005663 power_rule->max_eirp) ||
5664 nla_put_u32(msg, NL80211_ATTR_DFS_CAC_TIME,
5665 reg_rule->dfs_cac_ms))
Arik Nemtsovad30ca22014-12-15 19:25:59 +02005666 goto nla_put_failure;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005667
5668 nla_nest_end(msg, nl_reg_rule);
5669 }
5670
5671 nla_nest_end(msg, nl_reg_rules);
Arik Nemtsovad30ca22014-12-15 19:25:59 +02005672 return 0;
5673
5674nla_put_failure:
5675 return -EMSGSIZE;
5676}
5677
5678static int nl80211_get_reg_do(struct sk_buff *skb, struct genl_info *info)
5679{
5680 const struct ieee80211_regdomain *regdom = NULL;
5681 struct cfg80211_registered_device *rdev;
5682 struct wiphy *wiphy = NULL;
5683 struct sk_buff *msg;
5684 void *hdr;
5685
5686 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
5687 if (!msg)
5688 return -ENOBUFS;
5689
5690 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
5691 NL80211_CMD_GET_REG);
5692 if (!hdr)
5693 goto put_failure;
5694
5695 if (info->attrs[NL80211_ATTR_WIPHY]) {
Arik Nemtsov1bdd7162014-12-15 19:26:01 +02005696 bool self_managed;
5697
Arik Nemtsovad30ca22014-12-15 19:25:59 +02005698 rdev = cfg80211_get_dev_from_info(genl_info_net(info), info);
5699 if (IS_ERR(rdev)) {
5700 nlmsg_free(msg);
5701 return PTR_ERR(rdev);
5702 }
5703
5704 wiphy = &rdev->wiphy;
Arik Nemtsov1bdd7162014-12-15 19:26:01 +02005705 self_managed = wiphy->regulatory_flags &
5706 REGULATORY_WIPHY_SELF_MANAGED;
Arik Nemtsovad30ca22014-12-15 19:25:59 +02005707 regdom = get_wiphy_regdom(wiphy);
5708
Arik Nemtsov1bdd7162014-12-15 19:26:01 +02005709 /* a self-managed-reg device must have a private regdom */
5710 if (WARN_ON(!regdom && self_managed)) {
5711 nlmsg_free(msg);
5712 return -EINVAL;
5713 }
5714
Arik Nemtsovad30ca22014-12-15 19:25:59 +02005715 if (regdom &&
5716 nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy)))
5717 goto nla_put_failure;
5718 }
5719
5720 if (!wiphy && reg_last_request_cell_base() &&
5721 nla_put_u32(msg, NL80211_ATTR_USER_REG_HINT_TYPE,
5722 NL80211_USER_REG_HINT_CELL_BASE))
5723 goto nla_put_failure;
5724
5725 rcu_read_lock();
5726
5727 if (!regdom)
5728 regdom = rcu_dereference(cfg80211_regdomain);
5729
5730 if (nl80211_put_regdom(regdom, msg))
5731 goto nla_put_failure_rcu;
5732
5733 rcu_read_unlock();
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005734
5735 genlmsg_end(msg, hdr);
Johannes Berg5fe231e2013-05-08 21:45:15 +02005736 return genlmsg_reply(msg, info);
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005737
Johannes Berg458f4f92012-12-06 15:47:38 +01005738nla_put_failure_rcu:
5739 rcu_read_unlock();
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005740nla_put_failure:
5741 genlmsg_cancel(msg, hdr);
Julia Lawallefe1cf02011-01-28 15:17:11 +01005742put_failure:
Yuri Ershovd080e272010-06-29 15:08:07 +04005743 nlmsg_free(msg);
Johannes Berg5fe231e2013-05-08 21:45:15 +02005744 return -EMSGSIZE;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005745}
5746
Arik Nemtsovad30ca22014-12-15 19:25:59 +02005747static int nl80211_send_regdom(struct sk_buff *msg, struct netlink_callback *cb,
5748 u32 seq, int flags, struct wiphy *wiphy,
5749 const struct ieee80211_regdomain *regdom)
5750{
5751 void *hdr = nl80211hdr_put(msg, NETLINK_CB(cb->skb).portid, seq, flags,
5752 NL80211_CMD_GET_REG);
5753
5754 if (!hdr)
5755 return -1;
5756
5757 genl_dump_check_consistent(cb, hdr, &nl80211_fam);
5758
5759 if (nl80211_put_regdom(regdom, msg))
5760 goto nla_put_failure;
5761
5762 if (!wiphy && reg_last_request_cell_base() &&
5763 nla_put_u32(msg, NL80211_ATTR_USER_REG_HINT_TYPE,
5764 NL80211_USER_REG_HINT_CELL_BASE))
5765 goto nla_put_failure;
5766
5767 if (wiphy &&
5768 nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy)))
5769 goto nla_put_failure;
5770
Arik Nemtsov1bdd7162014-12-15 19:26:01 +02005771 if (wiphy && wiphy->regulatory_flags & REGULATORY_WIPHY_SELF_MANAGED &&
5772 nla_put_flag(msg, NL80211_ATTR_WIPHY_SELF_MANAGED_REG))
5773 goto nla_put_failure;
5774
Johannes Berg053c0952015-01-16 22:09:00 +01005775 genlmsg_end(msg, hdr);
5776 return 0;
Arik Nemtsovad30ca22014-12-15 19:25:59 +02005777
5778nla_put_failure:
5779 genlmsg_cancel(msg, hdr);
5780 return -EMSGSIZE;
5781}
5782
5783static int nl80211_get_reg_dump(struct sk_buff *skb,
5784 struct netlink_callback *cb)
5785{
5786 const struct ieee80211_regdomain *regdom = NULL;
5787 struct cfg80211_registered_device *rdev;
5788 int err, reg_idx, start = cb->args[2];
5789
5790 rtnl_lock();
5791
5792 if (cfg80211_regdomain && start == 0) {
5793 err = nl80211_send_regdom(skb, cb, cb->nlh->nlmsg_seq,
5794 NLM_F_MULTI, NULL,
5795 rtnl_dereference(cfg80211_regdomain));
5796 if (err < 0)
5797 goto out_err;
5798 }
5799
5800 /* the global regdom is idx 0 */
5801 reg_idx = 1;
5802 list_for_each_entry(rdev, &cfg80211_rdev_list, list) {
5803 regdom = get_wiphy_regdom(&rdev->wiphy);
5804 if (!regdom)
5805 continue;
5806
5807 if (++reg_idx <= start)
5808 continue;
5809
5810 err = nl80211_send_regdom(skb, cb, cb->nlh->nlmsg_seq,
5811 NLM_F_MULTI, &rdev->wiphy, regdom);
5812 if (err < 0) {
5813 reg_idx--;
5814 break;
5815 }
5816 }
5817
5818 cb->args[2] = reg_idx;
5819 err = skb->len;
5820out_err:
5821 rtnl_unlock();
5822 return err;
5823}
5824
Johannes Bergb6863032015-10-15 09:25:18 +02005825#ifdef CONFIG_CFG80211_CRDA_SUPPORT
5826static const struct nla_policy reg_rule_policy[NL80211_REG_RULE_ATTR_MAX + 1] = {
5827 [NL80211_ATTR_REG_RULE_FLAGS] = { .type = NLA_U32 },
5828 [NL80211_ATTR_FREQ_RANGE_START] = { .type = NLA_U32 },
5829 [NL80211_ATTR_FREQ_RANGE_END] = { .type = NLA_U32 },
5830 [NL80211_ATTR_FREQ_RANGE_MAX_BW] = { .type = NLA_U32 },
5831 [NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN] = { .type = NLA_U32 },
5832 [NL80211_ATTR_POWER_RULE_MAX_EIRP] = { .type = NLA_U32 },
5833 [NL80211_ATTR_DFS_CAC_TIME] = { .type = NLA_U32 },
5834};
5835
5836static int parse_reg_rule(struct nlattr *tb[],
5837 struct ieee80211_reg_rule *reg_rule)
5838{
5839 struct ieee80211_freq_range *freq_range = &reg_rule->freq_range;
5840 struct ieee80211_power_rule *power_rule = &reg_rule->power_rule;
5841
5842 if (!tb[NL80211_ATTR_REG_RULE_FLAGS])
5843 return -EINVAL;
5844 if (!tb[NL80211_ATTR_FREQ_RANGE_START])
5845 return -EINVAL;
5846 if (!tb[NL80211_ATTR_FREQ_RANGE_END])
5847 return -EINVAL;
5848 if (!tb[NL80211_ATTR_FREQ_RANGE_MAX_BW])
5849 return -EINVAL;
5850 if (!tb[NL80211_ATTR_POWER_RULE_MAX_EIRP])
5851 return -EINVAL;
5852
5853 reg_rule->flags = nla_get_u32(tb[NL80211_ATTR_REG_RULE_FLAGS]);
5854
5855 freq_range->start_freq_khz =
5856 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_START]);
5857 freq_range->end_freq_khz =
5858 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_END]);
5859 freq_range->max_bandwidth_khz =
5860 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]);
5861
5862 power_rule->max_eirp =
5863 nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]);
5864
5865 if (tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN])
5866 power_rule->max_antenna_gain =
5867 nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]);
5868
5869 if (tb[NL80211_ATTR_DFS_CAC_TIME])
5870 reg_rule->dfs_cac_ms =
5871 nla_get_u32(tb[NL80211_ATTR_DFS_CAC_TIME]);
5872
5873 return 0;
5874}
5875
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005876static int nl80211_set_reg(struct sk_buff *skb, struct genl_info *info)
5877{
5878 struct nlattr *tb[NL80211_REG_RULE_ATTR_MAX + 1];
5879 struct nlattr *nl_reg_rule;
Johannes Bergea372c52014-11-28 14:54:31 +01005880 char *alpha2;
5881 int rem_reg_rules, r;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005882 u32 num_rules = 0, rule_idx = 0, size_of_regd;
Luis R. Rodriguez4c7d3982013-11-13 18:54:02 +01005883 enum nl80211_dfs_regions dfs_region = NL80211_DFS_UNSET;
Johannes Bergea372c52014-11-28 14:54:31 +01005884 struct ieee80211_regdomain *rd;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005885
5886 if (!info->attrs[NL80211_ATTR_REG_ALPHA2])
5887 return -EINVAL;
5888
5889 if (!info->attrs[NL80211_ATTR_REG_RULES])
5890 return -EINVAL;
5891
5892 alpha2 = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]);
5893
Luis R. Rodriguez8b60b072011-10-11 10:59:02 -07005894 if (info->attrs[NL80211_ATTR_DFS_REGION])
5895 dfs_region = nla_get_u8(info->attrs[NL80211_ATTR_DFS_REGION]);
5896
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005897 nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES],
Johannes Berg1a919312012-12-03 17:21:11 +01005898 rem_reg_rules) {
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005899 num_rules++;
5900 if (num_rules > NL80211_MAX_SUPP_REG_RULES)
Luis R. Rodriguez4776c6e2009-05-13 17:04:39 -04005901 return -EINVAL;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005902 }
5903
Luis R. Rodrigueze4387682013-11-05 09:18:01 -08005904 if (!reg_is_valid_request(alpha2))
5905 return -EINVAL;
5906
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005907 size_of_regd = sizeof(struct ieee80211_regdomain) +
Johannes Berg1a919312012-12-03 17:21:11 +01005908 num_rules * sizeof(struct ieee80211_reg_rule);
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005909
5910 rd = kzalloc(size_of_regd, GFP_KERNEL);
Johannes Berg6913b492012-12-04 00:48:59 +01005911 if (!rd)
5912 return -ENOMEM;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005913
5914 rd->n_reg_rules = num_rules;
5915 rd->alpha2[0] = alpha2[0];
5916 rd->alpha2[1] = alpha2[1];
5917
Luis R. Rodriguez8b60b072011-10-11 10:59:02 -07005918 /*
5919 * Disable DFS master mode if the DFS region was
5920 * not supported or known on this kernel.
5921 */
5922 if (reg_supported_dfs_region(dfs_region))
5923 rd->dfs_region = dfs_region;
5924
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005925 nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES],
Johannes Berg1a919312012-12-03 17:21:11 +01005926 rem_reg_rules) {
Johannes Bergae811e22014-01-24 10:17:47 +01005927 r = nla_parse(tb, NL80211_REG_RULE_ATTR_MAX,
5928 nla_data(nl_reg_rule), nla_len(nl_reg_rule),
5929 reg_rule_policy);
5930 if (r)
5931 goto bad_reg;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005932 r = parse_reg_rule(tb, &rd->reg_rules[rule_idx]);
5933 if (r)
5934 goto bad_reg;
5935
5936 rule_idx++;
5937
Luis R. Rodriguezd0e18f82009-05-13 17:04:40 -04005938 if (rule_idx > NL80211_MAX_SUPP_REG_RULES) {
5939 r = -EINVAL;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005940 goto bad_reg;
Luis R. Rodriguezd0e18f82009-05-13 17:04:40 -04005941 }
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005942 }
5943
Johannes Berg06627992016-06-09 10:40:09 +02005944 /* set_regdom takes ownership of rd */
5945 return set_regdom(rd, REGD_SOURCE_CRDA);
Johannes Bergd2372b32008-10-24 20:32:20 +02005946 bad_reg:
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005947 kfree(rd);
Luis R. Rodriguezd0e18f82009-05-13 17:04:40 -04005948 return r;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005949}
Johannes Bergb6863032015-10-15 09:25:18 +02005950#endif /* CONFIG_CFG80211_CRDA_SUPPORT */
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005951
Johannes Berg83f5e2c2009-06-17 17:41:49 +02005952static int validate_scan_freqs(struct nlattr *freqs)
5953{
5954 struct nlattr *attr1, *attr2;
5955 int n_channels = 0, tmp1, tmp2;
5956
5957 nla_for_each_nested(attr1, freqs, tmp1) {
5958 n_channels++;
5959 /*
5960 * Some hardware has a limited channel list for
5961 * scanning, and it is pretty much nonsensical
5962 * to scan for a channel twice, so disallow that
5963 * and don't require drivers to check that the
5964 * channel list they get isn't longer than what
5965 * they can scan, as long as they can scan all
5966 * the channels they registered at once.
5967 */
5968 nla_for_each_nested(attr2, freqs, tmp2)
5969 if (attr1 != attr2 &&
5970 nla_get_u32(attr1) == nla_get_u32(attr2))
5971 return 0;
5972 }
5973
5974 return n_channels;
5975}
5976
Johannes Berg57fbcce2016-04-12 15:56:15 +02005977static bool is_band_valid(struct wiphy *wiphy, enum nl80211_band b)
Arend van Spriel38de03d2016-03-02 20:37:18 +01005978{
Johannes Berg57fbcce2016-04-12 15:56:15 +02005979 return b < NUM_NL80211_BANDS && wiphy->bands[b];
Arend van Spriel38de03d2016-03-02 20:37:18 +01005980}
5981
5982static int parse_bss_select(struct nlattr *nla, struct wiphy *wiphy,
5983 struct cfg80211_bss_selection *bss_select)
5984{
5985 struct nlattr *attr[NL80211_BSS_SELECT_ATTR_MAX + 1];
5986 struct nlattr *nest;
5987 int err;
5988 bool found = false;
5989 int i;
5990
5991 /* only process one nested attribute */
5992 nest = nla_data(nla);
5993 if (!nla_ok(nest, nla_len(nest)))
5994 return -EINVAL;
5995
5996 err = nla_parse(attr, NL80211_BSS_SELECT_ATTR_MAX, nla_data(nest),
5997 nla_len(nest), nl80211_bss_select_policy);
5998 if (err)
5999 return err;
6000
6001 /* only one attribute may be given */
6002 for (i = 0; i <= NL80211_BSS_SELECT_ATTR_MAX; i++) {
6003 if (attr[i]) {
6004 if (found)
6005 return -EINVAL;
6006 found = true;
6007 }
6008 }
6009
6010 bss_select->behaviour = __NL80211_BSS_SELECT_ATTR_INVALID;
6011
6012 if (attr[NL80211_BSS_SELECT_ATTR_RSSI])
6013 bss_select->behaviour = NL80211_BSS_SELECT_ATTR_RSSI;
6014
6015 if (attr[NL80211_BSS_SELECT_ATTR_BAND_PREF]) {
6016 bss_select->behaviour = NL80211_BSS_SELECT_ATTR_BAND_PREF;
6017 bss_select->param.band_pref =
6018 nla_get_u32(attr[NL80211_BSS_SELECT_ATTR_BAND_PREF]);
6019 if (!is_band_valid(wiphy, bss_select->param.band_pref))
6020 return -EINVAL;
6021 }
6022
6023 if (attr[NL80211_BSS_SELECT_ATTR_RSSI_ADJUST]) {
6024 struct nl80211_bss_select_rssi_adjust *adj_param;
6025
6026 adj_param = nla_data(attr[NL80211_BSS_SELECT_ATTR_RSSI_ADJUST]);
6027 bss_select->behaviour = NL80211_BSS_SELECT_ATTR_RSSI_ADJUST;
6028 bss_select->param.adjust.band = adj_param->band;
6029 bss_select->param.adjust.delta = adj_param->delta;
6030 if (!is_band_valid(wiphy, bss_select->param.adjust.band))
6031 return -EINVAL;
6032 }
6033
6034 /* user-space did not provide behaviour attribute */
6035 if (bss_select->behaviour == __NL80211_BSS_SELECT_ATTR_INVALID)
6036 return -EINVAL;
6037
6038 if (!(wiphy->bss_select_support & BIT(bss_select->behaviour)))
6039 return -EINVAL;
6040
6041 return 0;
6042}
6043
Johannes Bergad2b26a2014-06-12 21:39:05 +02006044static int nl80211_parse_random_mac(struct nlattr **attrs,
6045 u8 *mac_addr, u8 *mac_addr_mask)
6046{
6047 int i;
6048
6049 if (!attrs[NL80211_ATTR_MAC] && !attrs[NL80211_ATTR_MAC_MASK]) {
Joe Perchesd2beae12015-03-02 19:54:58 -08006050 eth_zero_addr(mac_addr);
6051 eth_zero_addr(mac_addr_mask);
Johannes Bergad2b26a2014-06-12 21:39:05 +02006052 mac_addr[0] = 0x2;
6053 mac_addr_mask[0] = 0x3;
6054
6055 return 0;
6056 }
6057
6058 /* need both or none */
6059 if (!attrs[NL80211_ATTR_MAC] || !attrs[NL80211_ATTR_MAC_MASK])
6060 return -EINVAL;
6061
6062 memcpy(mac_addr, nla_data(attrs[NL80211_ATTR_MAC]), ETH_ALEN);
6063 memcpy(mac_addr_mask, nla_data(attrs[NL80211_ATTR_MAC_MASK]), ETH_ALEN);
6064
6065 /* don't allow or configure an mcast address */
6066 if (!is_multicast_ether_addr(mac_addr_mask) ||
6067 is_multicast_ether_addr(mac_addr))
6068 return -EINVAL;
6069
6070 /*
6071 * allow users to pass a MAC address that has bits set outside
6072 * of the mask, but don't bother drivers with having to deal
6073 * with such bits
6074 */
6075 for (i = 0; i < ETH_ALEN; i++)
6076 mac_addr[i] &= mac_addr_mask[i];
6077
6078 return 0;
6079}
6080
Johannes Berg2a519312009-02-10 21:25:55 +01006081static int nl80211_trigger_scan(struct sk_buff *skb, struct genl_info *info)
6082{
Johannes Berg4c476992010-10-04 21:36:35 +02006083 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Bergfd014282012-06-18 19:17:03 +02006084 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg2a519312009-02-10 21:25:55 +01006085 struct cfg80211_scan_request *request;
Johannes Berg2a519312009-02-10 21:25:55 +01006086 struct nlattr *attr;
6087 struct wiphy *wiphy;
Johannes Berg83f5e2c2009-06-17 17:41:49 +02006088 int err, tmp, n_ssids = 0, n_channels, i;
Jouni Malinen70692ad2009-02-16 19:39:13 +02006089 size_t ie_len;
Johannes Berg2a519312009-02-10 21:25:55 +01006090
Johannes Bergf4a11bb2009-03-27 12:40:28 +01006091 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
6092 return -EINVAL;
6093
Johannes Berg79c97e92009-07-07 03:56:12 +02006094 wiphy = &rdev->wiphy;
Johannes Berg2a519312009-02-10 21:25:55 +01006095
Johannes Berg4c476992010-10-04 21:36:35 +02006096 if (!rdev->ops->scan)
6097 return -EOPNOTSUPP;
Johannes Berg2a519312009-02-10 21:25:55 +01006098
Johannes Bergf9d15d12014-01-22 11:14:19 +02006099 if (rdev->scan_req || rdev->scan_msg) {
Johannes Bergf9f47522013-03-19 15:04:07 +01006100 err = -EBUSY;
6101 goto unlock;
6102 }
Johannes Berg2a519312009-02-10 21:25:55 +01006103
6104 if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
Johannes Berg83f5e2c2009-06-17 17:41:49 +02006105 n_channels = validate_scan_freqs(
6106 info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]);
Johannes Bergf9f47522013-03-19 15:04:07 +01006107 if (!n_channels) {
6108 err = -EINVAL;
6109 goto unlock;
6110 }
Johannes Berg2a519312009-02-10 21:25:55 +01006111 } else {
Ilan Peerbdfbec22014-01-09 11:37:23 +02006112 n_channels = ieee80211_get_num_supported_channels(wiphy);
Johannes Berg2a519312009-02-10 21:25:55 +01006113 }
6114
6115 if (info->attrs[NL80211_ATTR_SCAN_SSIDS])
6116 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp)
6117 n_ssids++;
6118
Johannes Bergf9f47522013-03-19 15:04:07 +01006119 if (n_ssids > wiphy->max_scan_ssids) {
6120 err = -EINVAL;
6121 goto unlock;
6122 }
Johannes Berg2a519312009-02-10 21:25:55 +01006123
Jouni Malinen70692ad2009-02-16 19:39:13 +02006124 if (info->attrs[NL80211_ATTR_IE])
6125 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
6126 else
6127 ie_len = 0;
6128
Johannes Bergf9f47522013-03-19 15:04:07 +01006129 if (ie_len > wiphy->max_scan_ie_len) {
6130 err = -EINVAL;
6131 goto unlock;
6132 }
Johannes Berg18a83652009-03-31 12:12:05 +02006133
Johannes Berg2a519312009-02-10 21:25:55 +01006134 request = kzalloc(sizeof(*request)
Luciano Coelhoa2cd43c2011-05-18 11:42:03 +03006135 + sizeof(*request->ssids) * n_ssids
6136 + sizeof(*request->channels) * n_channels
Jouni Malinen70692ad2009-02-16 19:39:13 +02006137 + ie_len, GFP_KERNEL);
Johannes Bergf9f47522013-03-19 15:04:07 +01006138 if (!request) {
6139 err = -ENOMEM;
6140 goto unlock;
6141 }
Johannes Berg2a519312009-02-10 21:25:55 +01006142
Johannes Berg2a519312009-02-10 21:25:55 +01006143 if (n_ssids)
Johannes Berg5ba63532009-08-07 17:54:07 +02006144 request->ssids = (void *)&request->channels[n_channels];
Johannes Berg2a519312009-02-10 21:25:55 +01006145 request->n_ssids = n_ssids;
Jouni Malinen70692ad2009-02-16 19:39:13 +02006146 if (ie_len) {
Johannes Berg13874e42015-01-23 11:25:20 +01006147 if (n_ssids)
Jouni Malinen70692ad2009-02-16 19:39:13 +02006148 request->ie = (void *)(request->ssids + n_ssids);
6149 else
6150 request->ie = (void *)(request->channels + n_channels);
6151 }
Johannes Berg2a519312009-02-10 21:25:55 +01006152
Johannes Berg584991d2009-11-02 13:32:03 +01006153 i = 0;
Johannes Berg2a519312009-02-10 21:25:55 +01006154 if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
6155 /* user specified, bail out if channel not found */
Johannes Berg2a519312009-02-10 21:25:55 +01006156 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_FREQUENCIES], tmp) {
Johannes Berg584991d2009-11-02 13:32:03 +01006157 struct ieee80211_channel *chan;
6158
6159 chan = ieee80211_get_channel(wiphy, nla_get_u32(attr));
6160
6161 if (!chan) {
Johannes Berg2a519312009-02-10 21:25:55 +01006162 err = -EINVAL;
6163 goto out_free;
6164 }
Johannes Berg584991d2009-11-02 13:32:03 +01006165
6166 /* ignore disabled channels */
6167 if (chan->flags & IEEE80211_CHAN_DISABLED)
6168 continue;
6169
6170 request->channels[i] = chan;
Johannes Berg2a519312009-02-10 21:25:55 +01006171 i++;
6172 }
6173 } else {
Johannes Berg57fbcce2016-04-12 15:56:15 +02006174 enum nl80211_band band;
Johannes Berg34850ab2011-07-18 18:08:35 +02006175
Johannes Berg2a519312009-02-10 21:25:55 +01006176 /* all channels */
Johannes Berg57fbcce2016-04-12 15:56:15 +02006177 for (band = 0; band < NUM_NL80211_BANDS; band++) {
Johannes Berg2a519312009-02-10 21:25:55 +01006178 int j;
Kirtika Ruchandani7a087e72016-05-29 19:51:23 -07006179
Johannes Berg2a519312009-02-10 21:25:55 +01006180 if (!wiphy->bands[band])
6181 continue;
6182 for (j = 0; j < wiphy->bands[band]->n_channels; j++) {
Johannes Berg584991d2009-11-02 13:32:03 +01006183 struct ieee80211_channel *chan;
6184
6185 chan = &wiphy->bands[band]->channels[j];
6186
6187 if (chan->flags & IEEE80211_CHAN_DISABLED)
6188 continue;
6189
6190 request->channels[i] = chan;
Johannes Berg2a519312009-02-10 21:25:55 +01006191 i++;
6192 }
6193 }
6194 }
6195
Johannes Berg584991d2009-11-02 13:32:03 +01006196 if (!i) {
6197 err = -EINVAL;
6198 goto out_free;
6199 }
6200
6201 request->n_channels = i;
6202
Johannes Berg2a519312009-02-10 21:25:55 +01006203 i = 0;
Johannes Berg13874e42015-01-23 11:25:20 +01006204 if (n_ssids) {
Johannes Berg2a519312009-02-10 21:25:55 +01006205 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) {
Luciano Coelho57a27e12011-06-07 20:42:26 +03006206 if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) {
Johannes Berg2a519312009-02-10 21:25:55 +01006207 err = -EINVAL;
6208 goto out_free;
6209 }
Luciano Coelho57a27e12011-06-07 20:42:26 +03006210 request->ssids[i].ssid_len = nla_len(attr);
Johannes Berg2a519312009-02-10 21:25:55 +01006211 memcpy(request->ssids[i].ssid, nla_data(attr), nla_len(attr));
Johannes Berg2a519312009-02-10 21:25:55 +01006212 i++;
6213 }
6214 }
6215
Jouni Malinen70692ad2009-02-16 19:39:13 +02006216 if (info->attrs[NL80211_ATTR_IE]) {
6217 request->ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Johannes Bergde95a542009-04-01 11:58:36 +02006218 memcpy((void *)request->ie,
6219 nla_data(info->attrs[NL80211_ATTR_IE]),
Jouni Malinen70692ad2009-02-16 19:39:13 +02006220 request->ie_len);
6221 }
6222
Johannes Berg57fbcce2016-04-12 15:56:15 +02006223 for (i = 0; i < NUM_NL80211_BANDS; i++)
Johannes Berga401d2b2011-07-20 00:52:16 +02006224 if (wiphy->bands[i])
6225 request->rates[i] =
6226 (1 << wiphy->bands[i]->n_bitrates) - 1;
Johannes Berg34850ab2011-07-18 18:08:35 +02006227
6228 if (info->attrs[NL80211_ATTR_SCAN_SUPP_RATES]) {
6229 nla_for_each_nested(attr,
6230 info->attrs[NL80211_ATTR_SCAN_SUPP_RATES],
6231 tmp) {
Johannes Berg57fbcce2016-04-12 15:56:15 +02006232 enum nl80211_band band = nla_type(attr);
Johannes Berg34850ab2011-07-18 18:08:35 +02006233
Johannes Berg57fbcce2016-04-12 15:56:15 +02006234 if (band < 0 || band >= NUM_NL80211_BANDS) {
Johannes Berg34850ab2011-07-18 18:08:35 +02006235 err = -EINVAL;
6236 goto out_free;
6237 }
Felix Fietkau1b09cd82013-11-20 19:40:41 +01006238
6239 if (!wiphy->bands[band])
6240 continue;
6241
Johannes Berg34850ab2011-07-18 18:08:35 +02006242 err = ieee80211_get_ratemask(wiphy->bands[band],
6243 nla_data(attr),
6244 nla_len(attr),
6245 &request->rates[band]);
6246 if (err)
6247 goto out_free;
6248 }
6249 }
6250
Avraham Stern1d762502016-07-05 17:10:13 +03006251 if (info->attrs[NL80211_ATTR_MEASUREMENT_DURATION]) {
6252 if (!wiphy_ext_feature_isset(wiphy,
6253 NL80211_EXT_FEATURE_SET_SCAN_DWELL)) {
6254 err = -EOPNOTSUPP;
6255 goto out_free;
6256 }
6257
6258 request->duration =
6259 nla_get_u16(info->attrs[NL80211_ATTR_MEASUREMENT_DURATION]);
6260 request->duration_mandatory =
6261 nla_get_flag(info->attrs[NL80211_ATTR_MEASUREMENT_DURATION_MANDATORY]);
6262 }
6263
Sam Leffler46856bb2012-10-11 21:03:32 -07006264 if (info->attrs[NL80211_ATTR_SCAN_FLAGS]) {
Sam Lefflered4737712012-10-11 21:03:31 -07006265 request->flags = nla_get_u32(
6266 info->attrs[NL80211_ATTR_SCAN_FLAGS]);
Johannes Berg00c3a6e2013-10-26 17:14:38 +02006267 if ((request->flags & NL80211_SCAN_FLAG_LOW_PRIORITY) &&
6268 !(wiphy->features & NL80211_FEATURE_LOW_PRIORITY_SCAN)) {
Sam Leffler46856bb2012-10-11 21:03:32 -07006269 err = -EOPNOTSUPP;
6270 goto out_free;
6271 }
Johannes Bergad2b26a2014-06-12 21:39:05 +02006272
6273 if (request->flags & NL80211_SCAN_FLAG_RANDOM_ADDR) {
6274 if (!(wiphy->features &
6275 NL80211_FEATURE_SCAN_RANDOM_MAC_ADDR)) {
6276 err = -EOPNOTSUPP;
6277 goto out_free;
6278 }
6279
6280 if (wdev->current_bss) {
6281 err = -EOPNOTSUPP;
6282 goto out_free;
6283 }
6284
6285 err = nl80211_parse_random_mac(info->attrs,
6286 request->mac_addr,
6287 request->mac_addr_mask);
6288 if (err)
6289 goto out_free;
6290 }
Sam Leffler46856bb2012-10-11 21:03:32 -07006291 }
Sam Lefflered4737712012-10-11 21:03:31 -07006292
Rajkumar Manoharane9f935e2011-09-25 14:53:30 +05306293 request->no_cck =
6294 nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]);
6295
Jouni Malinen818965d2016-02-26 22:12:47 +02006296 if (info->attrs[NL80211_ATTR_MAC])
6297 memcpy(request->bssid, nla_data(info->attrs[NL80211_ATTR_MAC]),
6298 ETH_ALEN);
6299 else
6300 eth_broadcast_addr(request->bssid);
6301
Johannes Bergfd014282012-06-18 19:17:03 +02006302 request->wdev = wdev;
Johannes Berg79c97e92009-07-07 03:56:12 +02006303 request->wiphy = &rdev->wiphy;
Sam Leffler15d60302012-10-11 21:03:34 -07006304 request->scan_start = jiffies;
Johannes Berg2a519312009-02-10 21:25:55 +01006305
Johannes Berg79c97e92009-07-07 03:56:12 +02006306 rdev->scan_req = request;
Hila Gonene35e4d22012-06-27 17:19:42 +03006307 err = rdev_scan(rdev, request);
Johannes Berg2a519312009-02-10 21:25:55 +01006308
Johannes Berg463d0182009-07-14 00:33:35 +02006309 if (!err) {
Johannes Bergfd014282012-06-18 19:17:03 +02006310 nl80211_send_scan_start(rdev, wdev);
6311 if (wdev->netdev)
6312 dev_hold(wdev->netdev);
Johannes Berg4c476992010-10-04 21:36:35 +02006313 } else {
Johannes Berg2a519312009-02-10 21:25:55 +01006314 out_free:
Johannes Berg79c97e92009-07-07 03:56:12 +02006315 rdev->scan_req = NULL;
Johannes Berg2a519312009-02-10 21:25:55 +01006316 kfree(request);
6317 }
Johannes Berg3b858752009-03-12 09:55:09 +01006318
Johannes Bergf9f47522013-03-19 15:04:07 +01006319 unlock:
Johannes Berg2a519312009-02-10 21:25:55 +01006320 return err;
6321}
6322
Vidyullatha Kanchanapally91d3ab42015-10-30 19:14:49 +05306323static int nl80211_abort_scan(struct sk_buff *skb, struct genl_info *info)
6324{
6325 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6326 struct wireless_dev *wdev = info->user_ptr[1];
6327
6328 if (!rdev->ops->abort_scan)
6329 return -EOPNOTSUPP;
6330
6331 if (rdev->scan_msg)
6332 return 0;
6333
6334 if (!rdev->scan_req)
6335 return -ENOENT;
6336
6337 rdev_abort_scan(rdev, wdev);
6338 return 0;
6339}
6340
Avraham Stern3b06d272015-10-12 09:51:34 +03006341static int
6342nl80211_parse_sched_scan_plans(struct wiphy *wiphy, int n_plans,
6343 struct cfg80211_sched_scan_request *request,
6344 struct nlattr **attrs)
6345{
6346 int tmp, err, i = 0;
6347 struct nlattr *attr;
6348
6349 if (!attrs[NL80211_ATTR_SCHED_SCAN_PLANS]) {
6350 u32 interval;
6351
6352 /*
6353 * If scan plans are not specified,
6354 * %NL80211_ATTR_SCHED_SCAN_INTERVAL must be specified. In this
6355 * case one scan plan will be set with the specified scan
6356 * interval and infinite number of iterations.
6357 */
6358 if (!attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL])
6359 return -EINVAL;
6360
6361 interval = nla_get_u32(attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]);
6362 if (!interval)
6363 return -EINVAL;
6364
6365 request->scan_plans[0].interval =
6366 DIV_ROUND_UP(interval, MSEC_PER_SEC);
6367 if (!request->scan_plans[0].interval)
6368 return -EINVAL;
6369
6370 if (request->scan_plans[0].interval >
6371 wiphy->max_sched_scan_plan_interval)
6372 request->scan_plans[0].interval =
6373 wiphy->max_sched_scan_plan_interval;
6374
6375 return 0;
6376 }
6377
6378 nla_for_each_nested(attr, attrs[NL80211_ATTR_SCHED_SCAN_PLANS], tmp) {
6379 struct nlattr *plan[NL80211_SCHED_SCAN_PLAN_MAX + 1];
6380
6381 if (WARN_ON(i >= n_plans))
6382 return -EINVAL;
6383
6384 err = nla_parse(plan, NL80211_SCHED_SCAN_PLAN_MAX,
6385 nla_data(attr), nla_len(attr),
6386 nl80211_plan_policy);
6387 if (err)
6388 return err;
6389
6390 if (!plan[NL80211_SCHED_SCAN_PLAN_INTERVAL])
6391 return -EINVAL;
6392
6393 request->scan_plans[i].interval =
6394 nla_get_u32(plan[NL80211_SCHED_SCAN_PLAN_INTERVAL]);
6395 if (!request->scan_plans[i].interval ||
6396 request->scan_plans[i].interval >
6397 wiphy->max_sched_scan_plan_interval)
6398 return -EINVAL;
6399
6400 if (plan[NL80211_SCHED_SCAN_PLAN_ITERATIONS]) {
6401 request->scan_plans[i].iterations =
6402 nla_get_u32(plan[NL80211_SCHED_SCAN_PLAN_ITERATIONS]);
6403 if (!request->scan_plans[i].iterations ||
6404 (request->scan_plans[i].iterations >
6405 wiphy->max_sched_scan_plan_iterations))
6406 return -EINVAL;
6407 } else if (i < n_plans - 1) {
6408 /*
6409 * All scan plans but the last one must specify
6410 * a finite number of iterations
6411 */
6412 return -EINVAL;
6413 }
6414
6415 i++;
6416 }
6417
6418 /*
6419 * The last scan plan must not specify the number of
6420 * iterations, it is supposed to run infinitely
6421 */
6422 if (request->scan_plans[n_plans - 1].iterations)
6423 return -EINVAL;
6424
6425 return 0;
6426}
6427
Luciano Coelho256da022014-11-10 16:13:46 +02006428static struct cfg80211_sched_scan_request *
Johannes Bergad2b26a2014-06-12 21:39:05 +02006429nl80211_parse_sched_scan(struct wiphy *wiphy, struct wireless_dev *wdev,
Luciano Coelho256da022014-11-10 16:13:46 +02006430 struct nlattr **attrs)
Luciano Coelho807f8a82011-05-11 17:09:35 +03006431{
6432 struct cfg80211_sched_scan_request *request;
Luciano Coelho807f8a82011-05-11 17:09:35 +03006433 struct nlattr *attr;
Avraham Stern3b06d272015-10-12 09:51:34 +03006434 int err, tmp, n_ssids = 0, n_match_sets = 0, n_channels, i, n_plans = 0;
Johannes Berg57fbcce2016-04-12 15:56:15 +02006435 enum nl80211_band band;
Luciano Coelho807f8a82011-05-11 17:09:35 +03006436 size_t ie_len;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03006437 struct nlattr *tb[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1];
Johannes Bergea73cbc2014-01-24 10:53:53 +01006438 s32 default_match_rssi = NL80211_SCAN_RSSI_THOLD_OFF;
Luciano Coelho807f8a82011-05-11 17:09:35 +03006439
Luciano Coelho256da022014-11-10 16:13:46 +02006440 if (!is_valid_ie_attr(attrs[NL80211_ATTR_IE]))
6441 return ERR_PTR(-EINVAL);
Luciano Coelho807f8a82011-05-11 17:09:35 +03006442
Luciano Coelho256da022014-11-10 16:13:46 +02006443 if (attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
Luciano Coelho807f8a82011-05-11 17:09:35 +03006444 n_channels = validate_scan_freqs(
Luciano Coelho256da022014-11-10 16:13:46 +02006445 attrs[NL80211_ATTR_SCAN_FREQUENCIES]);
Luciano Coelho807f8a82011-05-11 17:09:35 +03006446 if (!n_channels)
Luciano Coelho256da022014-11-10 16:13:46 +02006447 return ERR_PTR(-EINVAL);
Luciano Coelho807f8a82011-05-11 17:09:35 +03006448 } else {
Ilan Peerbdfbec22014-01-09 11:37:23 +02006449 n_channels = ieee80211_get_num_supported_channels(wiphy);
Luciano Coelho807f8a82011-05-11 17:09:35 +03006450 }
6451
Luciano Coelho256da022014-11-10 16:13:46 +02006452 if (attrs[NL80211_ATTR_SCAN_SSIDS])
6453 nla_for_each_nested(attr, attrs[NL80211_ATTR_SCAN_SSIDS],
Luciano Coelho807f8a82011-05-11 17:09:35 +03006454 tmp)
6455 n_ssids++;
6456
Luciano Coelho93b6aa62011-07-13 14:57:28 +03006457 if (n_ssids > wiphy->max_sched_scan_ssids)
Luciano Coelho256da022014-11-10 16:13:46 +02006458 return ERR_PTR(-EINVAL);
Luciano Coelho807f8a82011-05-11 17:09:35 +03006459
Johannes Bergea73cbc2014-01-24 10:53:53 +01006460 /*
6461 * First, count the number of 'real' matchsets. Due to an issue with
6462 * the old implementation, matchsets containing only the RSSI attribute
6463 * (NL80211_SCHED_SCAN_MATCH_ATTR_RSSI) are considered as the 'default'
6464 * RSSI for all matchsets, rather than their own matchset for reporting
6465 * all APs with a strong RSSI. This is needed to be compatible with
6466 * older userspace that treated a matchset with only the RSSI as the
6467 * global RSSI for all other matchsets - if there are other matchsets.
6468 */
Luciano Coelho256da022014-11-10 16:13:46 +02006469 if (attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) {
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03006470 nla_for_each_nested(attr,
Luciano Coelho256da022014-11-10 16:13:46 +02006471 attrs[NL80211_ATTR_SCHED_SCAN_MATCH],
Johannes Bergea73cbc2014-01-24 10:53:53 +01006472 tmp) {
6473 struct nlattr *rssi;
6474
6475 err = nla_parse(tb, NL80211_SCHED_SCAN_MATCH_ATTR_MAX,
6476 nla_data(attr), nla_len(attr),
6477 nl80211_match_policy);
6478 if (err)
Luciano Coelho256da022014-11-10 16:13:46 +02006479 return ERR_PTR(err);
Johannes Bergea73cbc2014-01-24 10:53:53 +01006480 /* add other standalone attributes here */
6481 if (tb[NL80211_SCHED_SCAN_MATCH_ATTR_SSID]) {
6482 n_match_sets++;
6483 continue;
6484 }
6485 rssi = tb[NL80211_SCHED_SCAN_MATCH_ATTR_RSSI];
6486 if (rssi)
6487 default_match_rssi = nla_get_s32(rssi);
6488 }
6489 }
6490
6491 /* However, if there's no other matchset, add the RSSI one */
6492 if (!n_match_sets && default_match_rssi != NL80211_SCAN_RSSI_THOLD_OFF)
6493 n_match_sets = 1;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03006494
6495 if (n_match_sets > wiphy->max_match_sets)
Luciano Coelho256da022014-11-10 16:13:46 +02006496 return ERR_PTR(-EINVAL);
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03006497
Luciano Coelho256da022014-11-10 16:13:46 +02006498 if (attrs[NL80211_ATTR_IE])
6499 ie_len = nla_len(attrs[NL80211_ATTR_IE]);
Luciano Coelho807f8a82011-05-11 17:09:35 +03006500 else
6501 ie_len = 0;
6502
Luciano Coelho5a865ba2011-07-13 14:57:29 +03006503 if (ie_len > wiphy->max_sched_scan_ie_len)
Luciano Coelho256da022014-11-10 16:13:46 +02006504 return ERR_PTR(-EINVAL);
Luciano Coelhoc10841c2011-06-30 08:32:41 +03006505
Avraham Stern3b06d272015-10-12 09:51:34 +03006506 if (attrs[NL80211_ATTR_SCHED_SCAN_PLANS]) {
6507 /*
6508 * NL80211_ATTR_SCHED_SCAN_INTERVAL must not be specified since
6509 * each scan plan already specifies its own interval
6510 */
6511 if (attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL])
6512 return ERR_PTR(-EINVAL);
6513
6514 nla_for_each_nested(attr,
6515 attrs[NL80211_ATTR_SCHED_SCAN_PLANS], tmp)
6516 n_plans++;
6517 } else {
6518 /*
6519 * The scan interval attribute is kept for backward
6520 * compatibility. If no scan plans are specified and sched scan
6521 * interval is specified, one scan plan will be set with this
6522 * scan interval and infinite number of iterations.
6523 */
6524 if (!attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL])
6525 return ERR_PTR(-EINVAL);
6526
6527 n_plans = 1;
6528 }
6529
6530 if (!n_plans || n_plans > wiphy->max_sched_scan_plans)
6531 return ERR_PTR(-EINVAL);
6532
Luciano Coelho807f8a82011-05-11 17:09:35 +03006533 request = kzalloc(sizeof(*request)
Luciano Coelhoa2cd43c2011-05-18 11:42:03 +03006534 + sizeof(*request->ssids) * n_ssids
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03006535 + sizeof(*request->match_sets) * n_match_sets
Avraham Stern3b06d272015-10-12 09:51:34 +03006536 + sizeof(*request->scan_plans) * n_plans
Luciano Coelhoa2cd43c2011-05-18 11:42:03 +03006537 + sizeof(*request->channels) * n_channels
Luciano Coelho807f8a82011-05-11 17:09:35 +03006538 + ie_len, GFP_KERNEL);
Luciano Coelho256da022014-11-10 16:13:46 +02006539 if (!request)
6540 return ERR_PTR(-ENOMEM);
Luciano Coelho807f8a82011-05-11 17:09:35 +03006541
6542 if (n_ssids)
6543 request->ssids = (void *)&request->channels[n_channels];
6544 request->n_ssids = n_ssids;
6545 if (ie_len) {
Johannes Berg13874e42015-01-23 11:25:20 +01006546 if (n_ssids)
Luciano Coelho807f8a82011-05-11 17:09:35 +03006547 request->ie = (void *)(request->ssids + n_ssids);
6548 else
6549 request->ie = (void *)(request->channels + n_channels);
6550 }
6551
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03006552 if (n_match_sets) {
6553 if (request->ie)
6554 request->match_sets = (void *)(request->ie + ie_len);
Johannes Berg13874e42015-01-23 11:25:20 +01006555 else if (n_ssids)
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03006556 request->match_sets =
6557 (void *)(request->ssids + n_ssids);
6558 else
6559 request->match_sets =
6560 (void *)(request->channels + n_channels);
6561 }
6562 request->n_match_sets = n_match_sets;
6563
Avraham Stern3b06d272015-10-12 09:51:34 +03006564 if (n_match_sets)
6565 request->scan_plans = (void *)(request->match_sets +
6566 n_match_sets);
6567 else if (request->ie)
6568 request->scan_plans = (void *)(request->ie + ie_len);
6569 else if (n_ssids)
6570 request->scan_plans = (void *)(request->ssids + n_ssids);
6571 else
6572 request->scan_plans = (void *)(request->channels + n_channels);
6573
6574 request->n_scan_plans = n_plans;
6575
Luciano Coelho807f8a82011-05-11 17:09:35 +03006576 i = 0;
Luciano Coelho256da022014-11-10 16:13:46 +02006577 if (attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
Luciano Coelho807f8a82011-05-11 17:09:35 +03006578 /* user specified, bail out if channel not found */
6579 nla_for_each_nested(attr,
Luciano Coelho256da022014-11-10 16:13:46 +02006580 attrs[NL80211_ATTR_SCAN_FREQUENCIES],
Luciano Coelho807f8a82011-05-11 17:09:35 +03006581 tmp) {
6582 struct ieee80211_channel *chan;
6583
6584 chan = ieee80211_get_channel(wiphy, nla_get_u32(attr));
6585
6586 if (!chan) {
6587 err = -EINVAL;
6588 goto out_free;
6589 }
6590
6591 /* ignore disabled channels */
6592 if (chan->flags & IEEE80211_CHAN_DISABLED)
6593 continue;
6594
6595 request->channels[i] = chan;
6596 i++;
6597 }
6598 } else {
6599 /* all channels */
Johannes Berg57fbcce2016-04-12 15:56:15 +02006600 for (band = 0; band < NUM_NL80211_BANDS; band++) {
Luciano Coelho807f8a82011-05-11 17:09:35 +03006601 int j;
Kirtika Ruchandani7a087e72016-05-29 19:51:23 -07006602
Luciano Coelho807f8a82011-05-11 17:09:35 +03006603 if (!wiphy->bands[band])
6604 continue;
6605 for (j = 0; j < wiphy->bands[band]->n_channels; j++) {
6606 struct ieee80211_channel *chan;
6607
6608 chan = &wiphy->bands[band]->channels[j];
6609
6610 if (chan->flags & IEEE80211_CHAN_DISABLED)
6611 continue;
6612
6613 request->channels[i] = chan;
6614 i++;
6615 }
6616 }
6617 }
6618
6619 if (!i) {
6620 err = -EINVAL;
6621 goto out_free;
6622 }
6623
6624 request->n_channels = i;
6625
6626 i = 0;
Johannes Berg13874e42015-01-23 11:25:20 +01006627 if (n_ssids) {
Luciano Coelho256da022014-11-10 16:13:46 +02006628 nla_for_each_nested(attr, attrs[NL80211_ATTR_SCAN_SSIDS],
Luciano Coelho807f8a82011-05-11 17:09:35 +03006629 tmp) {
Luciano Coelho57a27e12011-06-07 20:42:26 +03006630 if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) {
Luciano Coelho807f8a82011-05-11 17:09:35 +03006631 err = -EINVAL;
6632 goto out_free;
6633 }
Luciano Coelho57a27e12011-06-07 20:42:26 +03006634 request->ssids[i].ssid_len = nla_len(attr);
Luciano Coelho807f8a82011-05-11 17:09:35 +03006635 memcpy(request->ssids[i].ssid, nla_data(attr),
6636 nla_len(attr));
Luciano Coelho807f8a82011-05-11 17:09:35 +03006637 i++;
6638 }
6639 }
6640
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03006641 i = 0;
Luciano Coelho256da022014-11-10 16:13:46 +02006642 if (attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) {
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03006643 nla_for_each_nested(attr,
Luciano Coelho256da022014-11-10 16:13:46 +02006644 attrs[NL80211_ATTR_SCHED_SCAN_MATCH],
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03006645 tmp) {
Thomas Pedersen88e920b2012-06-21 11:09:54 -07006646 struct nlattr *ssid, *rssi;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03006647
Johannes Bergae811e22014-01-24 10:17:47 +01006648 err = nla_parse(tb, NL80211_SCHED_SCAN_MATCH_ATTR_MAX,
6649 nla_data(attr), nla_len(attr),
6650 nl80211_match_policy);
6651 if (err)
6652 goto out_free;
Johannes Berg4a4ab0d2012-06-13 11:17:11 +02006653 ssid = tb[NL80211_SCHED_SCAN_MATCH_ATTR_SSID];
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03006654 if (ssid) {
Johannes Bergea73cbc2014-01-24 10:53:53 +01006655 if (WARN_ON(i >= n_match_sets)) {
6656 /* this indicates a programming error,
6657 * the loop above should have verified
6658 * things properly
6659 */
6660 err = -EINVAL;
6661 goto out_free;
6662 }
6663
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03006664 if (nla_len(ssid) > IEEE80211_MAX_SSID_LEN) {
6665 err = -EINVAL;
6666 goto out_free;
6667 }
6668 memcpy(request->match_sets[i].ssid.ssid,
6669 nla_data(ssid), nla_len(ssid));
6670 request->match_sets[i].ssid.ssid_len =
6671 nla_len(ssid);
Kirtika Ruchandani56ab3642016-05-29 19:54:10 -07006672 /* special attribute - old implementation w/a */
Johannes Bergea73cbc2014-01-24 10:53:53 +01006673 request->match_sets[i].rssi_thold =
6674 default_match_rssi;
6675 rssi = tb[NL80211_SCHED_SCAN_MATCH_ATTR_RSSI];
6676 if (rssi)
6677 request->match_sets[i].rssi_thold =
6678 nla_get_s32(rssi);
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03006679 }
6680 i++;
6681 }
Johannes Bergea73cbc2014-01-24 10:53:53 +01006682
6683 /* there was no other matchset, so the RSSI one is alone */
Luciano Coelhof89f46c2014-12-01 11:32:09 +02006684 if (i == 0 && n_match_sets)
Johannes Bergea73cbc2014-01-24 10:53:53 +01006685 request->match_sets[0].rssi_thold = default_match_rssi;
6686
6687 request->min_rssi_thold = INT_MAX;
6688 for (i = 0; i < n_match_sets; i++)
6689 request->min_rssi_thold =
6690 min(request->match_sets[i].rssi_thold,
6691 request->min_rssi_thold);
6692 } else {
6693 request->min_rssi_thold = NL80211_SCAN_RSSI_THOLD_OFF;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03006694 }
6695
Johannes Berg9900e482014-02-04 21:01:25 +01006696 if (ie_len) {
6697 request->ie_len = ie_len;
Luciano Coelho807f8a82011-05-11 17:09:35 +03006698 memcpy((void *)request->ie,
Luciano Coelho256da022014-11-10 16:13:46 +02006699 nla_data(attrs[NL80211_ATTR_IE]),
Luciano Coelho807f8a82011-05-11 17:09:35 +03006700 request->ie_len);
6701 }
6702
Luciano Coelho256da022014-11-10 16:13:46 +02006703 if (attrs[NL80211_ATTR_SCAN_FLAGS]) {
Sam Lefflered4737712012-10-11 21:03:31 -07006704 request->flags = nla_get_u32(
Luciano Coelho256da022014-11-10 16:13:46 +02006705 attrs[NL80211_ATTR_SCAN_FLAGS]);
Johannes Berg00c3a6e2013-10-26 17:14:38 +02006706 if ((request->flags & NL80211_SCAN_FLAG_LOW_PRIORITY) &&
6707 !(wiphy->features & NL80211_FEATURE_LOW_PRIORITY_SCAN)) {
Sam Leffler46856bb2012-10-11 21:03:32 -07006708 err = -EOPNOTSUPP;
6709 goto out_free;
6710 }
Johannes Bergad2b26a2014-06-12 21:39:05 +02006711
6712 if (request->flags & NL80211_SCAN_FLAG_RANDOM_ADDR) {
6713 u32 flg = NL80211_FEATURE_SCHED_SCAN_RANDOM_MAC_ADDR;
6714
6715 if (!wdev) /* must be net-detect */
6716 flg = NL80211_FEATURE_ND_RANDOM_MAC_ADDR;
6717
6718 if (!(wiphy->features & flg)) {
6719 err = -EOPNOTSUPP;
6720 goto out_free;
6721 }
6722
6723 if (wdev && wdev->current_bss) {
6724 err = -EOPNOTSUPP;
6725 goto out_free;
6726 }
6727
6728 err = nl80211_parse_random_mac(attrs, request->mac_addr,
6729 request->mac_addr_mask);
6730 if (err)
6731 goto out_free;
6732 }
Sam Leffler46856bb2012-10-11 21:03:32 -07006733 }
Sam Lefflered4737712012-10-11 21:03:31 -07006734
Luciano Coelho9c748932015-01-16 16:04:09 +02006735 if (attrs[NL80211_ATTR_SCHED_SCAN_DELAY])
6736 request->delay =
6737 nla_get_u32(attrs[NL80211_ATTR_SCHED_SCAN_DELAY]);
6738
Avraham Stern3b06d272015-10-12 09:51:34 +03006739 err = nl80211_parse_sched_scan_plans(wiphy, n_plans, request, attrs);
6740 if (err)
6741 goto out_free;
6742
Sam Leffler15d60302012-10-11 21:03:34 -07006743 request->scan_start = jiffies;
Luciano Coelho807f8a82011-05-11 17:09:35 +03006744
Luciano Coelho256da022014-11-10 16:13:46 +02006745 return request;
Luciano Coelho807f8a82011-05-11 17:09:35 +03006746
6747out_free:
6748 kfree(request);
Luciano Coelho256da022014-11-10 16:13:46 +02006749 return ERR_PTR(err);
6750}
6751
6752static int nl80211_start_sched_scan(struct sk_buff *skb,
6753 struct genl_info *info)
6754{
6755 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6756 struct net_device *dev = info->user_ptr[1];
Johannes Bergad2b26a2014-06-12 21:39:05 +02006757 struct wireless_dev *wdev = dev->ieee80211_ptr;
Jukka Rissanen31a60ed2014-12-15 13:25:38 +02006758 struct cfg80211_sched_scan_request *sched_scan_req;
Luciano Coelho256da022014-11-10 16:13:46 +02006759 int err;
6760
6761 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) ||
6762 !rdev->ops->sched_scan_start)
6763 return -EOPNOTSUPP;
6764
6765 if (rdev->sched_scan_req)
6766 return -EINPROGRESS;
6767
Jukka Rissanen31a60ed2014-12-15 13:25:38 +02006768 sched_scan_req = nl80211_parse_sched_scan(&rdev->wiphy, wdev,
6769 info->attrs);
6770
6771 err = PTR_ERR_OR_ZERO(sched_scan_req);
Luciano Coelho256da022014-11-10 16:13:46 +02006772 if (err)
6773 goto out_err;
6774
Jukka Rissanen31a60ed2014-12-15 13:25:38 +02006775 err = rdev_sched_scan_start(rdev, dev, sched_scan_req);
Luciano Coelho256da022014-11-10 16:13:46 +02006776 if (err)
6777 goto out_free;
6778
Jukka Rissanen31a60ed2014-12-15 13:25:38 +02006779 sched_scan_req->dev = dev;
6780 sched_scan_req->wiphy = &rdev->wiphy;
6781
Jukka Rissanen93a1e862014-12-15 13:25:39 +02006782 if (info->attrs[NL80211_ATTR_SOCKET_OWNER])
6783 sched_scan_req->owner_nlportid = info->snd_portid;
6784
Jukka Rissanen31a60ed2014-12-15 13:25:38 +02006785 rcu_assign_pointer(rdev->sched_scan_req, sched_scan_req);
Luciano Coelho256da022014-11-10 16:13:46 +02006786
6787 nl80211_send_sched_scan(rdev, dev,
6788 NL80211_CMD_START_SCHED_SCAN);
6789 return 0;
6790
6791out_free:
Jukka Rissanen31a60ed2014-12-15 13:25:38 +02006792 kfree(sched_scan_req);
Luciano Coelho256da022014-11-10 16:13:46 +02006793out_err:
Luciano Coelho807f8a82011-05-11 17:09:35 +03006794 return err;
6795}
6796
6797static int nl80211_stop_sched_scan(struct sk_buff *skb,
6798 struct genl_info *info)
6799{
6800 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6801
6802 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) ||
6803 !rdev->ops->sched_scan_stop)
6804 return -EOPNOTSUPP;
6805
Johannes Berg5fe231e2013-05-08 21:45:15 +02006806 return __cfg80211_stop_sched_scan(rdev, false);
Luciano Coelho807f8a82011-05-11 17:09:35 +03006807}
6808
Simon Wunderlich04f39042013-02-08 18:16:19 +01006809static int nl80211_start_radar_detection(struct sk_buff *skb,
6810 struct genl_info *info)
6811{
6812 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6813 struct net_device *dev = info->user_ptr[1];
6814 struct wireless_dev *wdev = dev->ieee80211_ptr;
6815 struct cfg80211_chan_def chandef;
Luis R. Rodriguez55f74352013-11-25 20:56:10 +01006816 enum nl80211_dfs_regions dfs_region;
Janusz Dziedzic31559f32014-02-21 19:46:13 +01006817 unsigned int cac_time_ms;
Simon Wunderlich04f39042013-02-08 18:16:19 +01006818 int err;
6819
Luis R. Rodriguez55f74352013-11-25 20:56:10 +01006820 dfs_region = reg_get_dfs_region(wdev->wiphy);
6821 if (dfs_region == NL80211_DFS_UNSET)
6822 return -EINVAL;
6823
Simon Wunderlich04f39042013-02-08 18:16:19 +01006824 err = nl80211_parse_chandef(rdev, info, &chandef);
6825 if (err)
6826 return err;
6827
Simon Wunderlichff311bc2013-09-03 19:43:18 +02006828 if (netif_carrier_ok(dev))
6829 return -EBUSY;
6830
Simon Wunderlich04f39042013-02-08 18:16:19 +01006831 if (wdev->cac_started)
6832 return -EBUSY;
6833
Luciano Coelho2beb6dab2014-02-18 11:40:36 +02006834 err = cfg80211_chandef_dfs_required(wdev->wiphy, &chandef,
Luciano Coelho00ec75f2014-05-15 13:05:39 +03006835 wdev->iftype);
Simon Wunderlich04f39042013-02-08 18:16:19 +01006836 if (err < 0)
6837 return err;
6838
6839 if (err == 0)
6840 return -EINVAL;
6841
Janusz Dziedzicfe7c3a12013-11-05 14:48:48 +01006842 if (!cfg80211_chandef_dfs_usable(wdev->wiphy, &chandef))
Simon Wunderlich04f39042013-02-08 18:16:19 +01006843 return -EINVAL;
6844
6845 if (!rdev->ops->start_radar_detection)
6846 return -EOPNOTSUPP;
6847
Janusz Dziedzic31559f32014-02-21 19:46:13 +01006848 cac_time_ms = cfg80211_chandef_dfs_cac_time(&rdev->wiphy, &chandef);
6849 if (WARN_ON(!cac_time_ms))
6850 cac_time_ms = IEEE80211_DFS_MIN_CAC_TIME_MS;
6851
Ilan Peera1056b12015-10-22 22:27:46 +03006852 err = rdev_start_radar_detection(rdev, dev, &chandef, cac_time_ms);
Simon Wunderlich04f39042013-02-08 18:16:19 +01006853 if (!err) {
Michal Kazior9e0e2962014-01-29 14:22:27 +01006854 wdev->chandef = chandef;
Simon Wunderlich04f39042013-02-08 18:16:19 +01006855 wdev->cac_started = true;
6856 wdev->cac_start_time = jiffies;
Janusz Dziedzic31559f32014-02-21 19:46:13 +01006857 wdev->cac_time_ms = cac_time_ms;
Simon Wunderlich04f39042013-02-08 18:16:19 +01006858 }
Simon Wunderlich04f39042013-02-08 18:16:19 +01006859 return err;
6860}
6861
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006862static int nl80211_channel_switch(struct sk_buff *skb, struct genl_info *info)
6863{
6864 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6865 struct net_device *dev = info->user_ptr[1];
6866 struct wireless_dev *wdev = dev->ieee80211_ptr;
6867 struct cfg80211_csa_settings params;
6868 /* csa_attrs is defined static to avoid waste of stack size - this
6869 * function is called under RTNL lock, so this should not be a problem.
6870 */
6871 static struct nlattr *csa_attrs[NL80211_ATTR_MAX+1];
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006872 int err;
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02006873 bool need_new_beacon = false;
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03006874 int len, i;
Luciano Coelho252e07c2014-10-08 09:48:34 +03006875 u32 cs_count;
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006876
6877 if (!rdev->ops->channel_switch ||
6878 !(rdev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH))
6879 return -EOPNOTSUPP;
6880
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02006881 switch (dev->ieee80211_ptr->iftype) {
6882 case NL80211_IFTYPE_AP:
6883 case NL80211_IFTYPE_P2P_GO:
6884 need_new_beacon = true;
6885
6886 /* useless if AP is not running */
6887 if (!wdev->beacon_interval)
Johannes Berg1ff79df2014-01-22 10:05:27 +01006888 return -ENOTCONN;
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02006889 break;
6890 case NL80211_IFTYPE_ADHOC:
Johannes Berg1ff79df2014-01-22 10:05:27 +01006891 if (!wdev->ssid_len)
6892 return -ENOTCONN;
6893 break;
Chun-Yeow Yeohc6da6742013-10-14 19:08:28 -07006894 case NL80211_IFTYPE_MESH_POINT:
Johannes Berg1ff79df2014-01-22 10:05:27 +01006895 if (!wdev->mesh_id_len)
6896 return -ENOTCONN;
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02006897 break;
6898 default:
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006899 return -EOPNOTSUPP;
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02006900 }
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006901
6902 memset(&params, 0, sizeof(params));
6903
6904 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] ||
6905 !info->attrs[NL80211_ATTR_CH_SWITCH_COUNT])
6906 return -EINVAL;
6907
6908 /* only important for AP, IBSS and mesh create IEs internally */
Andrei Otcheretianskid0a361a2013-10-17 10:52:17 +02006909 if (need_new_beacon && !info->attrs[NL80211_ATTR_CSA_IES])
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006910 return -EINVAL;
6911
Luciano Coelho252e07c2014-10-08 09:48:34 +03006912 /* Even though the attribute is u32, the specification says
6913 * u8, so let's make sure we don't overflow.
6914 */
6915 cs_count = nla_get_u32(info->attrs[NL80211_ATTR_CH_SWITCH_COUNT]);
6916 if (cs_count > 255)
6917 return -EINVAL;
6918
6919 params.count = cs_count;
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006920
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02006921 if (!need_new_beacon)
6922 goto skip_beacons;
6923
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006924 err = nl80211_parse_beacon(info->attrs, &params.beacon_after);
6925 if (err)
6926 return err;
6927
6928 err = nla_parse_nested(csa_attrs, NL80211_ATTR_MAX,
6929 info->attrs[NL80211_ATTR_CSA_IES],
6930 nl80211_policy);
6931 if (err)
6932 return err;
6933
6934 err = nl80211_parse_beacon(csa_attrs, &params.beacon_csa);
6935 if (err)
6936 return err;
6937
6938 if (!csa_attrs[NL80211_ATTR_CSA_C_OFF_BEACON])
6939 return -EINVAL;
6940
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03006941 len = nla_len(csa_attrs[NL80211_ATTR_CSA_C_OFF_BEACON]);
6942 if (!len || (len % sizeof(u16)))
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006943 return -EINVAL;
6944
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03006945 params.n_counter_offsets_beacon = len / sizeof(u16);
6946 if (rdev->wiphy.max_num_csa_counters &&
6947 (params.n_counter_offsets_beacon >
6948 rdev->wiphy.max_num_csa_counters))
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006949 return -EINVAL;
6950
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03006951 params.counter_offsets_beacon =
6952 nla_data(csa_attrs[NL80211_ATTR_CSA_C_OFF_BEACON]);
6953
6954 /* sanity checks - counters should fit and be the same */
6955 for (i = 0; i < params.n_counter_offsets_beacon; i++) {
6956 u16 offset = params.counter_offsets_beacon[i];
6957
6958 if (offset >= params.beacon_csa.tail_len)
6959 return -EINVAL;
6960
6961 if (params.beacon_csa.tail[offset] != params.count)
6962 return -EINVAL;
6963 }
6964
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006965 if (csa_attrs[NL80211_ATTR_CSA_C_OFF_PRESP]) {
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03006966 len = nla_len(csa_attrs[NL80211_ATTR_CSA_C_OFF_PRESP]);
6967 if (!len || (len % sizeof(u16)))
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006968 return -EINVAL;
6969
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03006970 params.n_counter_offsets_presp = len / sizeof(u16);
6971 if (rdev->wiphy.max_num_csa_counters &&
6972 (params.n_counter_offsets_beacon >
6973 rdev->wiphy.max_num_csa_counters))
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006974 return -EINVAL;
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03006975
6976 params.counter_offsets_presp =
6977 nla_data(csa_attrs[NL80211_ATTR_CSA_C_OFF_PRESP]);
6978
6979 /* sanity checks - counters should fit and be the same */
6980 for (i = 0; i < params.n_counter_offsets_presp; i++) {
6981 u16 offset = params.counter_offsets_presp[i];
6982
6983 if (offset >= params.beacon_csa.probe_resp_len)
6984 return -EINVAL;
6985
6986 if (params.beacon_csa.probe_resp[offset] !=
6987 params.count)
6988 return -EINVAL;
6989 }
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006990 }
6991
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02006992skip_beacons:
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006993 err = nl80211_parse_chandef(rdev, info, &params.chandef);
6994 if (err)
6995 return err;
6996
Arik Nemtsov923b3522015-07-08 15:41:44 +03006997 if (!cfg80211_reg_can_beacon_relax(&rdev->wiphy, &params.chandef,
6998 wdev->iftype))
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006999 return -EINVAL;
7000
Luciano Coelho2beb6dab2014-02-18 11:40:36 +02007001 err = cfg80211_chandef_dfs_required(wdev->wiphy,
7002 &params.chandef,
7003 wdev->iftype);
7004 if (err < 0)
7005 return err;
7006
Fabian Frederickdcc6c2f2014-10-25 17:57:35 +02007007 if (err > 0)
Luciano Coelho2beb6dab2014-02-18 11:40:36 +02007008 params.radar_required = true;
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02007009
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02007010 if (info->attrs[NL80211_ATTR_CH_SWITCH_BLOCK_TX])
7011 params.block_tx = true;
7012
Simon Wunderlichc56589e2013-11-21 18:19:49 +01007013 wdev_lock(wdev);
7014 err = rdev_channel_switch(rdev, dev, &params);
7015 wdev_unlock(wdev);
7016
7017 return err;
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02007018}
7019
Johannes Berg9720bb32011-06-21 09:45:33 +02007020static int nl80211_send_bss(struct sk_buff *msg, struct netlink_callback *cb,
7021 u32 seq, int flags,
Johannes Berg2a519312009-02-10 21:25:55 +01007022 struct cfg80211_registered_device *rdev,
Johannes Berg48ab9052009-07-10 18:42:31 +02007023 struct wireless_dev *wdev,
7024 struct cfg80211_internal_bss *intbss)
Johannes Berg2a519312009-02-10 21:25:55 +01007025{
Johannes Berg48ab9052009-07-10 18:42:31 +02007026 struct cfg80211_bss *res = &intbss->pub;
Johannes Berg9caf0362012-11-29 01:25:20 +01007027 const struct cfg80211_bss_ies *ies;
Johannes Berg2a519312009-02-10 21:25:55 +01007028 void *hdr;
7029 struct nlattr *bss;
Johannes Berg48ab9052009-07-10 18:42:31 +02007030
7031 ASSERT_WDEV_LOCK(wdev);
Johannes Berg2a519312009-02-10 21:25:55 +01007032
Eric W. Biederman15e47302012-09-07 20:12:54 +00007033 hdr = nl80211hdr_put(msg, NETLINK_CB(cb->skb).portid, seq, flags,
Johannes Berg2a519312009-02-10 21:25:55 +01007034 NL80211_CMD_NEW_SCAN_RESULTS);
7035 if (!hdr)
7036 return -1;
7037
Johannes Berg9720bb32011-06-21 09:45:33 +02007038 genl_dump_check_consistent(cb, hdr, &nl80211_fam);
7039
Johannes Berg97990a02013-04-19 01:02:55 +02007040 if (nla_put_u32(msg, NL80211_ATTR_GENERATION, rdev->bss_generation))
7041 goto nla_put_failure;
7042 if (wdev->netdev &&
David S. Miller9360ffd2012-03-29 04:41:26 -04007043 nla_put_u32(msg, NL80211_ATTR_IFINDEX, wdev->netdev->ifindex))
7044 goto nla_put_failure;
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02007045 if (nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
7046 NL80211_ATTR_PAD))
Johannes Berg97990a02013-04-19 01:02:55 +02007047 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01007048
7049 bss = nla_nest_start(msg, NL80211_ATTR_BSS);
7050 if (!bss)
7051 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04007052 if ((!is_zero_ether_addr(res->bssid) &&
Johannes Berg9caf0362012-11-29 01:25:20 +01007053 nla_put(msg, NL80211_BSS_BSSID, ETH_ALEN, res->bssid)))
David S. Miller9360ffd2012-03-29 04:41:26 -04007054 goto nla_put_failure;
Johannes Berg9caf0362012-11-29 01:25:20 +01007055
7056 rcu_read_lock();
Johannes Berg0e227082014-08-12 20:34:30 +02007057 /* indicate whether we have probe response data or not */
7058 if (rcu_access_pointer(res->proberesp_ies) &&
7059 nla_put_flag(msg, NL80211_BSS_PRESP_DATA))
7060 goto fail_unlock_rcu;
7061
7062 /* this pointer prefers to be pointed to probe response data
7063 * but is always valid
7064 */
Johannes Berg9caf0362012-11-29 01:25:20 +01007065 ies = rcu_dereference(res->ies);
Johannes Berg8cef2c92013-02-05 16:54:31 +01007066 if (ies) {
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02007067 if (nla_put_u64_64bit(msg, NL80211_BSS_TSF, ies->tsf,
7068 NL80211_BSS_PAD))
Johannes Berg8cef2c92013-02-05 16:54:31 +01007069 goto fail_unlock_rcu;
Johannes Berg8cef2c92013-02-05 16:54:31 +01007070 if (ies->len && nla_put(msg, NL80211_BSS_INFORMATION_ELEMENTS,
7071 ies->len, ies->data))
7072 goto fail_unlock_rcu;
Johannes Berg9caf0362012-11-29 01:25:20 +01007073 }
Johannes Berg0e227082014-08-12 20:34:30 +02007074
7075 /* and this pointer is always (unless driver didn't know) beacon data */
Johannes Berg9caf0362012-11-29 01:25:20 +01007076 ies = rcu_dereference(res->beacon_ies);
Johannes Berg0e227082014-08-12 20:34:30 +02007077 if (ies && ies->from_beacon) {
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02007078 if (nla_put_u64_64bit(msg, NL80211_BSS_BEACON_TSF, ies->tsf,
7079 NL80211_BSS_PAD))
Johannes Berg8cef2c92013-02-05 16:54:31 +01007080 goto fail_unlock_rcu;
7081 if (ies->len && nla_put(msg, NL80211_BSS_BEACON_IES,
7082 ies->len, ies->data))
7083 goto fail_unlock_rcu;
Johannes Berg9caf0362012-11-29 01:25:20 +01007084 }
7085 rcu_read_unlock();
7086
David S. Miller9360ffd2012-03-29 04:41:26 -04007087 if (res->beacon_interval &&
7088 nla_put_u16(msg, NL80211_BSS_BEACON_INTERVAL, res->beacon_interval))
7089 goto nla_put_failure;
7090 if (nla_put_u16(msg, NL80211_BSS_CAPABILITY, res->capability) ||
7091 nla_put_u32(msg, NL80211_BSS_FREQUENCY, res->channel->center_freq) ||
Simon Wunderlichdcd6eac2013-07-08 16:55:49 +02007092 nla_put_u32(msg, NL80211_BSS_CHAN_WIDTH, res->scan_width) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04007093 nla_put_u32(msg, NL80211_BSS_SEEN_MS_AGO,
7094 jiffies_to_msecs(jiffies - intbss->ts)))
7095 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01007096
Avraham Stern1d762502016-07-05 17:10:13 +03007097 if (intbss->parent_tsf &&
7098 (nla_put_u64_64bit(msg, NL80211_BSS_PARENT_TSF,
7099 intbss->parent_tsf, NL80211_BSS_PAD) ||
7100 nla_put(msg, NL80211_BSS_PARENT_BSSID, ETH_ALEN,
7101 intbss->parent_bssid)))
7102 goto nla_put_failure;
7103
Dmitry Shmidt6e19bc42015-10-07 11:32:53 +02007104 if (intbss->ts_boottime &&
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02007105 nla_put_u64_64bit(msg, NL80211_BSS_LAST_SEEN_BOOTTIME,
7106 intbss->ts_boottime, NL80211_BSS_PAD))
Dmitry Shmidt6e19bc42015-10-07 11:32:53 +02007107 goto nla_put_failure;
7108
Johannes Berg77965c92009-02-18 18:45:06 +01007109 switch (rdev->wiphy.signal_type) {
Johannes Berg2a519312009-02-10 21:25:55 +01007110 case CFG80211_SIGNAL_TYPE_MBM:
David S. Miller9360ffd2012-03-29 04:41:26 -04007111 if (nla_put_u32(msg, NL80211_BSS_SIGNAL_MBM, res->signal))
7112 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01007113 break;
7114 case CFG80211_SIGNAL_TYPE_UNSPEC:
David S. Miller9360ffd2012-03-29 04:41:26 -04007115 if (nla_put_u8(msg, NL80211_BSS_SIGNAL_UNSPEC, res->signal))
7116 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01007117 break;
7118 default:
7119 break;
7120 }
7121
Johannes Berg48ab9052009-07-10 18:42:31 +02007122 switch (wdev->iftype) {
Johannes Berg074ac8d2010-09-16 14:58:22 +02007123 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Berg48ab9052009-07-10 18:42:31 +02007124 case NL80211_IFTYPE_STATION:
David S. Miller9360ffd2012-03-29 04:41:26 -04007125 if (intbss == wdev->current_bss &&
7126 nla_put_u32(msg, NL80211_BSS_STATUS,
7127 NL80211_BSS_STATUS_ASSOCIATED))
7128 goto nla_put_failure;
Johannes Berg48ab9052009-07-10 18:42:31 +02007129 break;
7130 case NL80211_IFTYPE_ADHOC:
David S. Miller9360ffd2012-03-29 04:41:26 -04007131 if (intbss == wdev->current_bss &&
7132 nla_put_u32(msg, NL80211_BSS_STATUS,
7133 NL80211_BSS_STATUS_IBSS_JOINED))
7134 goto nla_put_failure;
Johannes Berg48ab9052009-07-10 18:42:31 +02007135 break;
7136 default:
7137 break;
7138 }
7139
Johannes Berg2a519312009-02-10 21:25:55 +01007140 nla_nest_end(msg, bss);
7141
Johannes Berg053c0952015-01-16 22:09:00 +01007142 genlmsg_end(msg, hdr);
7143 return 0;
Johannes Berg2a519312009-02-10 21:25:55 +01007144
Johannes Berg8cef2c92013-02-05 16:54:31 +01007145 fail_unlock_rcu:
7146 rcu_read_unlock();
Johannes Berg2a519312009-02-10 21:25:55 +01007147 nla_put_failure:
7148 genlmsg_cancel(msg, hdr);
7149 return -EMSGSIZE;
7150}
7151
Johannes Berg97990a02013-04-19 01:02:55 +02007152static int nl80211_dump_scan(struct sk_buff *skb, struct netlink_callback *cb)
Johannes Berg2a519312009-02-10 21:25:55 +01007153{
Johannes Berg48ab9052009-07-10 18:42:31 +02007154 struct cfg80211_registered_device *rdev;
Johannes Berg2a519312009-02-10 21:25:55 +01007155 struct cfg80211_internal_bss *scan;
Johannes Berg48ab9052009-07-10 18:42:31 +02007156 struct wireless_dev *wdev;
Johannes Berg97990a02013-04-19 01:02:55 +02007157 int start = cb->args[2], idx = 0;
Johannes Berg2a519312009-02-10 21:25:55 +01007158 int err;
7159
Johannes Berg97990a02013-04-19 01:02:55 +02007160 err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev);
Johannes Berg67748892010-10-04 21:14:06 +02007161 if (err)
7162 return err;
Johannes Berg2a519312009-02-10 21:25:55 +01007163
Johannes Berg48ab9052009-07-10 18:42:31 +02007164 wdev_lock(wdev);
7165 spin_lock_bh(&rdev->bss_lock);
7166 cfg80211_bss_expire(rdev);
7167
Johannes Berg9720bb32011-06-21 09:45:33 +02007168 cb->seq = rdev->bss_generation;
7169
Johannes Berg48ab9052009-07-10 18:42:31 +02007170 list_for_each_entry(scan, &rdev->bss_list, list) {
Johannes Berg2a519312009-02-10 21:25:55 +01007171 if (++idx <= start)
7172 continue;
Johannes Berg9720bb32011-06-21 09:45:33 +02007173 if (nl80211_send_bss(skb, cb,
Johannes Berg2a519312009-02-10 21:25:55 +01007174 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Johannes Berg48ab9052009-07-10 18:42:31 +02007175 rdev, wdev, scan) < 0) {
Johannes Berg2a519312009-02-10 21:25:55 +01007176 idx--;
Johannes Berg67748892010-10-04 21:14:06 +02007177 break;
Johannes Berg2a519312009-02-10 21:25:55 +01007178 }
7179 }
7180
Johannes Berg48ab9052009-07-10 18:42:31 +02007181 spin_unlock_bh(&rdev->bss_lock);
7182 wdev_unlock(wdev);
Johannes Berg2a519312009-02-10 21:25:55 +01007183
Johannes Berg97990a02013-04-19 01:02:55 +02007184 cb->args[2] = idx;
7185 nl80211_finish_wdev_dump(rdev);
Johannes Berg2a519312009-02-10 21:25:55 +01007186
Johannes Berg67748892010-10-04 21:14:06 +02007187 return skb->len;
Johannes Berg2a519312009-02-10 21:25:55 +01007188}
7189
Eric W. Biederman15e47302012-09-07 20:12:54 +00007190static int nl80211_send_survey(struct sk_buff *msg, u32 portid, u32 seq,
Johannes Berg11f78ac2014-11-14 16:43:50 +01007191 int flags, struct net_device *dev,
7192 bool allow_radio_stats,
7193 struct survey_info *survey)
Holger Schurig61fa7132009-11-11 12:25:40 +01007194{
7195 void *hdr;
7196 struct nlattr *infoattr;
7197
Johannes Berg11f78ac2014-11-14 16:43:50 +01007198 /* skip radio stats if userspace didn't request them */
7199 if (!survey->channel && !allow_radio_stats)
7200 return 0;
7201
Eric W. Biederman15e47302012-09-07 20:12:54 +00007202 hdr = nl80211hdr_put(msg, portid, seq, flags,
Holger Schurig61fa7132009-11-11 12:25:40 +01007203 NL80211_CMD_NEW_SURVEY_RESULTS);
7204 if (!hdr)
7205 return -ENOMEM;
7206
David S. Miller9360ffd2012-03-29 04:41:26 -04007207 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex))
7208 goto nla_put_failure;
Holger Schurig61fa7132009-11-11 12:25:40 +01007209
7210 infoattr = nla_nest_start(msg, NL80211_ATTR_SURVEY_INFO);
7211 if (!infoattr)
7212 goto nla_put_failure;
7213
Johannes Berg11f78ac2014-11-14 16:43:50 +01007214 if (survey->channel &&
7215 nla_put_u32(msg, NL80211_SURVEY_INFO_FREQUENCY,
David S. Miller9360ffd2012-03-29 04:41:26 -04007216 survey->channel->center_freq))
7217 goto nla_put_failure;
7218
7219 if ((survey->filled & SURVEY_INFO_NOISE_DBM) &&
7220 nla_put_u8(msg, NL80211_SURVEY_INFO_NOISE, survey->noise))
7221 goto nla_put_failure;
7222 if ((survey->filled & SURVEY_INFO_IN_USE) &&
7223 nla_put_flag(msg, NL80211_SURVEY_INFO_IN_USE))
7224 goto nla_put_failure;
Johannes Berg4ed20be2014-11-14 16:35:34 +01007225 if ((survey->filled & SURVEY_INFO_TIME) &&
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02007226 nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME,
7227 survey->time, NL80211_SURVEY_INFO_PAD))
David S. Miller9360ffd2012-03-29 04:41:26 -04007228 goto nla_put_failure;
Johannes Berg4ed20be2014-11-14 16:35:34 +01007229 if ((survey->filled & SURVEY_INFO_TIME_BUSY) &&
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02007230 nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME_BUSY,
7231 survey->time_busy, NL80211_SURVEY_INFO_PAD))
David S. Miller9360ffd2012-03-29 04:41:26 -04007232 goto nla_put_failure;
Johannes Berg4ed20be2014-11-14 16:35:34 +01007233 if ((survey->filled & SURVEY_INFO_TIME_EXT_BUSY) &&
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02007234 nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME_EXT_BUSY,
7235 survey->time_ext_busy, NL80211_SURVEY_INFO_PAD))
David S. Miller9360ffd2012-03-29 04:41:26 -04007236 goto nla_put_failure;
Johannes Berg4ed20be2014-11-14 16:35:34 +01007237 if ((survey->filled & SURVEY_INFO_TIME_RX) &&
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02007238 nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME_RX,
7239 survey->time_rx, NL80211_SURVEY_INFO_PAD))
David S. Miller9360ffd2012-03-29 04:41:26 -04007240 goto nla_put_failure;
Johannes Berg4ed20be2014-11-14 16:35:34 +01007241 if ((survey->filled & SURVEY_INFO_TIME_TX) &&
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02007242 nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME_TX,
7243 survey->time_tx, NL80211_SURVEY_INFO_PAD))
David S. Miller9360ffd2012-03-29 04:41:26 -04007244 goto nla_put_failure;
Johannes Berg052536a2014-11-14 16:44:11 +01007245 if ((survey->filled & SURVEY_INFO_TIME_SCAN) &&
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02007246 nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME_SCAN,
7247 survey->time_scan, NL80211_SURVEY_INFO_PAD))
Johannes Berg052536a2014-11-14 16:44:11 +01007248 goto nla_put_failure;
Holger Schurig61fa7132009-11-11 12:25:40 +01007249
7250 nla_nest_end(msg, infoattr);
7251
Johannes Berg053c0952015-01-16 22:09:00 +01007252 genlmsg_end(msg, hdr);
7253 return 0;
Holger Schurig61fa7132009-11-11 12:25:40 +01007254
7255 nla_put_failure:
7256 genlmsg_cancel(msg, hdr);
7257 return -EMSGSIZE;
7258}
7259
Johannes Berg11f78ac2014-11-14 16:43:50 +01007260static int nl80211_dump_survey(struct sk_buff *skb, struct netlink_callback *cb)
Holger Schurig61fa7132009-11-11 12:25:40 +01007261{
7262 struct survey_info survey;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08007263 struct cfg80211_registered_device *rdev;
Johannes Berg97990a02013-04-19 01:02:55 +02007264 struct wireless_dev *wdev;
7265 int survey_idx = cb->args[2];
Holger Schurig61fa7132009-11-11 12:25:40 +01007266 int res;
Johannes Berg11f78ac2014-11-14 16:43:50 +01007267 bool radio_stats;
Holger Schurig61fa7132009-11-11 12:25:40 +01007268
Zhao, Gang1b8ec872014-04-21 12:53:02 +08007269 res = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev);
Johannes Berg67748892010-10-04 21:14:06 +02007270 if (res)
7271 return res;
Holger Schurig61fa7132009-11-11 12:25:40 +01007272
Johannes Berg11f78ac2014-11-14 16:43:50 +01007273 /* prepare_wdev_dump parsed the attributes */
7274 radio_stats = nl80211_fam.attrbuf[NL80211_ATTR_SURVEY_RADIO_STATS];
7275
Johannes Berg97990a02013-04-19 01:02:55 +02007276 if (!wdev->netdev) {
7277 res = -EINVAL;
7278 goto out_err;
7279 }
7280
Zhao, Gang1b8ec872014-04-21 12:53:02 +08007281 if (!rdev->ops->dump_survey) {
Holger Schurig61fa7132009-11-11 12:25:40 +01007282 res = -EOPNOTSUPP;
7283 goto out_err;
7284 }
7285
7286 while (1) {
Zhao, Gang1b8ec872014-04-21 12:53:02 +08007287 res = rdev_dump_survey(rdev, wdev->netdev, survey_idx, &survey);
Holger Schurig61fa7132009-11-11 12:25:40 +01007288 if (res == -ENOENT)
7289 break;
7290 if (res)
7291 goto out_err;
7292
Johannes Berg11f78ac2014-11-14 16:43:50 +01007293 /* don't send disabled channels, but do send non-channel data */
7294 if (survey.channel &&
7295 survey.channel->flags & IEEE80211_CHAN_DISABLED) {
Luis R. Rodriguez180cdc72011-05-27 07:24:02 -07007296 survey_idx++;
7297 continue;
7298 }
7299
Holger Schurig61fa7132009-11-11 12:25:40 +01007300 if (nl80211_send_survey(skb,
Eric W. Biederman15e47302012-09-07 20:12:54 +00007301 NETLINK_CB(cb->skb).portid,
Holger Schurig61fa7132009-11-11 12:25:40 +01007302 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Johannes Berg11f78ac2014-11-14 16:43:50 +01007303 wdev->netdev, radio_stats, &survey) < 0)
Holger Schurig61fa7132009-11-11 12:25:40 +01007304 goto out;
7305 survey_idx++;
7306 }
7307
7308 out:
Johannes Berg97990a02013-04-19 01:02:55 +02007309 cb->args[2] = survey_idx;
Holger Schurig61fa7132009-11-11 12:25:40 +01007310 res = skb->len;
7311 out_err:
Zhao, Gang1b8ec872014-04-21 12:53:02 +08007312 nl80211_finish_wdev_dump(rdev);
Holger Schurig61fa7132009-11-11 12:25:40 +01007313 return res;
7314}
7315
Samuel Ortizb23aa672009-07-01 21:26:54 +02007316static bool nl80211_valid_wpa_versions(u32 wpa_versions)
7317{
7318 return !(wpa_versions & ~(NL80211_WPA_VERSION_1 |
7319 NL80211_WPA_VERSION_2));
7320}
7321
Jouni Malinen636a5d32009-03-19 13:39:22 +02007322static int nl80211_authenticate(struct sk_buff *skb, struct genl_info *info)
7323{
Johannes Berg4c476992010-10-04 21:36:35 +02007324 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7325 struct net_device *dev = info->user_ptr[1];
Johannes Berg19957bb2009-07-02 17:20:43 +02007326 struct ieee80211_channel *chan;
Jouni Malinene39e5b52012-09-30 19:29:39 +03007327 const u8 *bssid, *ssid, *ie = NULL, *sae_data = NULL;
7328 int err, ssid_len, ie_len = 0, sae_data_len = 0;
Johannes Berg19957bb2009-07-02 17:20:43 +02007329 enum nl80211_auth_type auth_type;
Johannes Bergfffd0932009-07-08 14:22:54 +02007330 struct key_parse key;
Jouni Malinend5cdfac2010-04-04 09:37:19 +03007331 bool local_state_change;
Jouni Malinen636a5d32009-03-19 13:39:22 +02007332
Johannes Bergf4a11bb2009-03-27 12:40:28 +01007333 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
7334 return -EINVAL;
7335
7336 if (!info->attrs[NL80211_ATTR_MAC])
7337 return -EINVAL;
7338
Jouni Malinen17780922009-03-27 20:52:47 +02007339 if (!info->attrs[NL80211_ATTR_AUTH_TYPE])
7340 return -EINVAL;
7341
Johannes Berg19957bb2009-07-02 17:20:43 +02007342 if (!info->attrs[NL80211_ATTR_SSID])
7343 return -EINVAL;
7344
7345 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ])
7346 return -EINVAL;
7347
Johannes Bergfffd0932009-07-08 14:22:54 +02007348 err = nl80211_parse_key(info, &key);
7349 if (err)
7350 return err;
7351
7352 if (key.idx >= 0) {
Johannes Berge31b8212010-10-05 19:39:30 +02007353 if (key.type != -1 && key.type != NL80211_KEYTYPE_GROUP)
7354 return -EINVAL;
Johannes Bergfffd0932009-07-08 14:22:54 +02007355 if (!key.p.key || !key.p.key_len)
7356 return -EINVAL;
7357 if ((key.p.cipher != WLAN_CIPHER_SUITE_WEP40 ||
7358 key.p.key_len != WLAN_KEY_LEN_WEP40) &&
7359 (key.p.cipher != WLAN_CIPHER_SUITE_WEP104 ||
7360 key.p.key_len != WLAN_KEY_LEN_WEP104))
7361 return -EINVAL;
7362 if (key.idx > 4)
7363 return -EINVAL;
7364 } else {
7365 key.p.key_len = 0;
7366 key.p.key = NULL;
7367 }
7368
Johannes Bergafea0b72010-08-10 09:46:42 +02007369 if (key.idx >= 0) {
7370 int i;
7371 bool ok = false;
Kirtika Ruchandani7a087e72016-05-29 19:51:23 -07007372
Johannes Bergafea0b72010-08-10 09:46:42 +02007373 for (i = 0; i < rdev->wiphy.n_cipher_suites; i++) {
7374 if (key.p.cipher == rdev->wiphy.cipher_suites[i]) {
7375 ok = true;
7376 break;
7377 }
7378 }
Johannes Berg4c476992010-10-04 21:36:35 +02007379 if (!ok)
7380 return -EINVAL;
Johannes Bergafea0b72010-08-10 09:46:42 +02007381 }
7382
Johannes Berg4c476992010-10-04 21:36:35 +02007383 if (!rdev->ops->auth)
7384 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02007385
Johannes Berg074ac8d2010-09-16 14:58:22 +02007386 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02007387 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
7388 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02007389
Johannes Berg19957bb2009-07-02 17:20:43 +02007390 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen664834d2014-01-15 00:01:44 +02007391 chan = nl80211_get_valid_chan(&rdev->wiphy,
7392 info->attrs[NL80211_ATTR_WIPHY_FREQ]);
7393 if (!chan)
Johannes Berg4c476992010-10-04 21:36:35 +02007394 return -EINVAL;
Jouni Malinen636a5d32009-03-19 13:39:22 +02007395
Johannes Berg19957bb2009-07-02 17:20:43 +02007396 ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
7397 ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
7398
7399 if (info->attrs[NL80211_ATTR_IE]) {
7400 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
7401 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
7402 }
7403
7404 auth_type = nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]);
Jouni Malinene39e5b52012-09-30 19:29:39 +03007405 if (!nl80211_valid_auth_type(rdev, auth_type, NL80211_CMD_AUTHENTICATE))
Johannes Berg4c476992010-10-04 21:36:35 +02007406 return -EINVAL;
Johannes Berg19957bb2009-07-02 17:20:43 +02007407
Jouni Malinene39e5b52012-09-30 19:29:39 +03007408 if (auth_type == NL80211_AUTHTYPE_SAE &&
7409 !info->attrs[NL80211_ATTR_SAE_DATA])
7410 return -EINVAL;
7411
7412 if (info->attrs[NL80211_ATTR_SAE_DATA]) {
7413 if (auth_type != NL80211_AUTHTYPE_SAE)
7414 return -EINVAL;
7415 sae_data = nla_data(info->attrs[NL80211_ATTR_SAE_DATA]);
7416 sae_data_len = nla_len(info->attrs[NL80211_ATTR_SAE_DATA]);
7417 /* need to include at least Auth Transaction and Status Code */
7418 if (sae_data_len < 4)
7419 return -EINVAL;
7420 }
7421
Jouni Malinend5cdfac2010-04-04 09:37:19 +03007422 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE];
7423
Johannes Berg95de8172012-01-20 13:55:25 +01007424 /*
7425 * Since we no longer track auth state, ignore
7426 * requests to only change local state.
7427 */
7428 if (local_state_change)
7429 return 0;
7430
Johannes Berg91bf9b22013-05-15 17:44:01 +02007431 wdev_lock(dev->ieee80211_ptr);
7432 err = cfg80211_mlme_auth(rdev, dev, chan, auth_type, bssid,
7433 ssid, ssid_len, ie, ie_len,
7434 key.p.key, key.p.key_len, key.idx,
7435 sae_data, sae_data_len);
7436 wdev_unlock(dev->ieee80211_ptr);
7437 return err;
Jouni Malinen636a5d32009-03-19 13:39:22 +02007438}
7439
Johannes Bergc0692b82010-08-27 14:26:53 +03007440static int nl80211_crypto_settings(struct cfg80211_registered_device *rdev,
7441 struct genl_info *info,
Johannes Berg3dc27d22009-07-02 21:36:37 +02007442 struct cfg80211_crypto_settings *settings,
7443 int cipher_limit)
Samuel Ortizb23aa672009-07-01 21:26:54 +02007444{
Johannes Bergc0b2bbd2009-07-25 16:54:36 +02007445 memset(settings, 0, sizeof(*settings));
7446
Samuel Ortizb23aa672009-07-01 21:26:54 +02007447 settings->control_port = info->attrs[NL80211_ATTR_CONTROL_PORT];
7448
Johannes Bergc0692b82010-08-27 14:26:53 +03007449 if (info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]) {
7450 u16 proto;
Kirtika Ruchandani7a087e72016-05-29 19:51:23 -07007451
Johannes Bergc0692b82010-08-27 14:26:53 +03007452 proto = nla_get_u16(
7453 info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]);
7454 settings->control_port_ethertype = cpu_to_be16(proto);
7455 if (!(rdev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) &&
7456 proto != ETH_P_PAE)
7457 return -EINVAL;
7458 if (info->attrs[NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT])
7459 settings->control_port_no_encrypt = true;
7460 } else
7461 settings->control_port_ethertype = cpu_to_be16(ETH_P_PAE);
7462
Samuel Ortizb23aa672009-07-01 21:26:54 +02007463 if (info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]) {
7464 void *data;
7465 int len, i;
7466
7467 data = nla_data(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]);
7468 len = nla_len(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]);
7469 settings->n_ciphers_pairwise = len / sizeof(u32);
7470
7471 if (len % sizeof(u32))
7472 return -EINVAL;
7473
Johannes Berg3dc27d22009-07-02 21:36:37 +02007474 if (settings->n_ciphers_pairwise > cipher_limit)
Samuel Ortizb23aa672009-07-01 21:26:54 +02007475 return -EINVAL;
7476
7477 memcpy(settings->ciphers_pairwise, data, len);
7478
7479 for (i = 0; i < settings->n_ciphers_pairwise; i++)
Jouni Malinen38ba3c52011-09-21 18:14:56 +03007480 if (!cfg80211_supported_cipher_suite(
7481 &rdev->wiphy,
Samuel Ortizb23aa672009-07-01 21:26:54 +02007482 settings->ciphers_pairwise[i]))
7483 return -EINVAL;
7484 }
7485
7486 if (info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]) {
7487 settings->cipher_group =
7488 nla_get_u32(info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]);
Jouni Malinen38ba3c52011-09-21 18:14:56 +03007489 if (!cfg80211_supported_cipher_suite(&rdev->wiphy,
7490 settings->cipher_group))
Samuel Ortizb23aa672009-07-01 21:26:54 +02007491 return -EINVAL;
7492 }
7493
7494 if (info->attrs[NL80211_ATTR_WPA_VERSIONS]) {
7495 settings->wpa_versions =
7496 nla_get_u32(info->attrs[NL80211_ATTR_WPA_VERSIONS]);
7497 if (!nl80211_valid_wpa_versions(settings->wpa_versions))
7498 return -EINVAL;
7499 }
7500
7501 if (info->attrs[NL80211_ATTR_AKM_SUITES]) {
7502 void *data;
Jouni Malinen6d302402011-09-21 18:11:33 +03007503 int len;
Samuel Ortizb23aa672009-07-01 21:26:54 +02007504
7505 data = nla_data(info->attrs[NL80211_ATTR_AKM_SUITES]);
7506 len = nla_len(info->attrs[NL80211_ATTR_AKM_SUITES]);
7507 settings->n_akm_suites = len / sizeof(u32);
7508
7509 if (len % sizeof(u32))
7510 return -EINVAL;
7511
Jouni Malinen1b9ca022011-09-21 16:13:07 +03007512 if (settings->n_akm_suites > NL80211_MAX_NR_AKM_SUITES)
7513 return -EINVAL;
7514
Samuel Ortizb23aa672009-07-01 21:26:54 +02007515 memcpy(settings->akm_suites, data, len);
Samuel Ortizb23aa672009-07-01 21:26:54 +02007516 }
7517
7518 return 0;
7519}
7520
Jouni Malinen636a5d32009-03-19 13:39:22 +02007521static int nl80211_associate(struct sk_buff *skb, struct genl_info *info)
7522{
Johannes Berg4c476992010-10-04 21:36:35 +02007523 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7524 struct net_device *dev = info->user_ptr[1];
Johannes Bergf444de02010-05-05 15:25:02 +02007525 struct ieee80211_channel *chan;
Johannes Bergf62fab72013-02-21 20:09:09 +01007526 struct cfg80211_assoc_request req = {};
7527 const u8 *bssid, *ssid;
7528 int err, ssid_len = 0;
Jouni Malinen636a5d32009-03-19 13:39:22 +02007529
Johannes Bergf4a11bb2009-03-27 12:40:28 +01007530 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
7531 return -EINVAL;
7532
7533 if (!info->attrs[NL80211_ATTR_MAC] ||
Johannes Berg19957bb2009-07-02 17:20:43 +02007534 !info->attrs[NL80211_ATTR_SSID] ||
7535 !info->attrs[NL80211_ATTR_WIPHY_FREQ])
Johannes Bergf4a11bb2009-03-27 12:40:28 +01007536 return -EINVAL;
7537
Johannes Berg4c476992010-10-04 21:36:35 +02007538 if (!rdev->ops->assoc)
7539 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02007540
Johannes Berg074ac8d2010-09-16 14:58:22 +02007541 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02007542 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
7543 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02007544
Johannes Berg19957bb2009-07-02 17:20:43 +02007545 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02007546
Jouni Malinen664834d2014-01-15 00:01:44 +02007547 chan = nl80211_get_valid_chan(&rdev->wiphy,
7548 info->attrs[NL80211_ATTR_WIPHY_FREQ]);
7549 if (!chan)
Johannes Berg4c476992010-10-04 21:36:35 +02007550 return -EINVAL;
Jouni Malinen636a5d32009-03-19 13:39:22 +02007551
Johannes Berg19957bb2009-07-02 17:20:43 +02007552 ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
7553 ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02007554
7555 if (info->attrs[NL80211_ATTR_IE]) {
Johannes Bergf62fab72013-02-21 20:09:09 +01007556 req.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
7557 req.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02007558 }
7559
Jouni Malinendc6382c2009-05-06 22:09:37 +03007560 if (info->attrs[NL80211_ATTR_USE_MFP]) {
Johannes Berg4f5dadc2009-07-07 03:56:10 +02007561 enum nl80211_mfp mfp =
Jouni Malinendc6382c2009-05-06 22:09:37 +03007562 nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]);
Johannes Berg4f5dadc2009-07-07 03:56:10 +02007563 if (mfp == NL80211_MFP_REQUIRED)
Johannes Bergf62fab72013-02-21 20:09:09 +01007564 req.use_mfp = true;
Johannes Berg4c476992010-10-04 21:36:35 +02007565 else if (mfp != NL80211_MFP_NO)
7566 return -EINVAL;
Jouni Malinendc6382c2009-05-06 22:09:37 +03007567 }
7568
Johannes Berg3e5d7642009-07-07 14:37:26 +02007569 if (info->attrs[NL80211_ATTR_PREV_BSSID])
Johannes Bergf62fab72013-02-21 20:09:09 +01007570 req.prev_bssid = nla_data(info->attrs[NL80211_ATTR_PREV_BSSID]);
Johannes Berg3e5d7642009-07-07 14:37:26 +02007571
Ben Greear7e7c8922011-11-18 11:31:59 -08007572 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT]))
Johannes Bergf62fab72013-02-21 20:09:09 +01007573 req.flags |= ASSOC_REQ_DISABLE_HT;
Ben Greear7e7c8922011-11-18 11:31:59 -08007574
7575 if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
Johannes Bergf62fab72013-02-21 20:09:09 +01007576 memcpy(&req.ht_capa_mask,
7577 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]),
7578 sizeof(req.ht_capa_mask));
Ben Greear7e7c8922011-11-18 11:31:59 -08007579
7580 if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) {
Johannes Bergf62fab72013-02-21 20:09:09 +01007581 if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
Ben Greear7e7c8922011-11-18 11:31:59 -08007582 return -EINVAL;
Johannes Bergf62fab72013-02-21 20:09:09 +01007583 memcpy(&req.ht_capa,
7584 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]),
7585 sizeof(req.ht_capa));
Ben Greear7e7c8922011-11-18 11:31:59 -08007586 }
7587
Johannes Bergee2aca32013-02-21 17:36:01 +01007588 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_VHT]))
Johannes Bergf62fab72013-02-21 20:09:09 +01007589 req.flags |= ASSOC_REQ_DISABLE_VHT;
Johannes Bergee2aca32013-02-21 17:36:01 +01007590
7591 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK])
Johannes Bergf62fab72013-02-21 20:09:09 +01007592 memcpy(&req.vht_capa_mask,
7593 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]),
7594 sizeof(req.vht_capa_mask));
Johannes Bergee2aca32013-02-21 17:36:01 +01007595
7596 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) {
Johannes Bergf62fab72013-02-21 20:09:09 +01007597 if (!info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK])
Johannes Bergee2aca32013-02-21 17:36:01 +01007598 return -EINVAL;
Johannes Bergf62fab72013-02-21 20:09:09 +01007599 memcpy(&req.vht_capa,
7600 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]),
7601 sizeof(req.vht_capa));
Johannes Bergee2aca32013-02-21 17:36:01 +01007602 }
7603
Assaf Kraussbab5ab72014-09-03 15:25:01 +03007604 if (nla_get_flag(info->attrs[NL80211_ATTR_USE_RRM])) {
Beni Lev0c9ca112016-02-17 20:30:00 +02007605 if (!((rdev->wiphy.features &
7606 NL80211_FEATURE_DS_PARAM_SET_IE_IN_PROBES) &&
7607 (rdev->wiphy.features & NL80211_FEATURE_QUIET)) &&
7608 !wiphy_ext_feature_isset(&rdev->wiphy,
7609 NL80211_EXT_FEATURE_RRM))
Assaf Kraussbab5ab72014-09-03 15:25:01 +03007610 return -EINVAL;
7611 req.flags |= ASSOC_REQ_USE_RRM;
7612 }
7613
Johannes Bergf62fab72013-02-21 20:09:09 +01007614 err = nl80211_crypto_settings(rdev, info, &req.crypto, 1);
Johannes Berg91bf9b22013-05-15 17:44:01 +02007615 if (!err) {
7616 wdev_lock(dev->ieee80211_ptr);
Johannes Bergf62fab72013-02-21 20:09:09 +01007617 err = cfg80211_mlme_assoc(rdev, dev, chan, bssid,
7618 ssid, ssid_len, &req);
Johannes Berg91bf9b22013-05-15 17:44:01 +02007619 wdev_unlock(dev->ieee80211_ptr);
7620 }
Jouni Malinen636a5d32009-03-19 13:39:22 +02007621
Jouni Malinen636a5d32009-03-19 13:39:22 +02007622 return err;
7623}
7624
7625static int nl80211_deauthenticate(struct sk_buff *skb, struct genl_info *info)
7626{
Johannes Berg4c476992010-10-04 21:36:35 +02007627 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7628 struct net_device *dev = info->user_ptr[1];
Johannes Berg19957bb2009-07-02 17:20:43 +02007629 const u8 *ie = NULL, *bssid;
Johannes Berg91bf9b22013-05-15 17:44:01 +02007630 int ie_len = 0, err;
Johannes Berg19957bb2009-07-02 17:20:43 +02007631 u16 reason_code;
Jouni Malinend5cdfac2010-04-04 09:37:19 +03007632 bool local_state_change;
Jouni Malinen636a5d32009-03-19 13:39:22 +02007633
Johannes Bergf4a11bb2009-03-27 12:40:28 +01007634 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
7635 return -EINVAL;
7636
7637 if (!info->attrs[NL80211_ATTR_MAC])
7638 return -EINVAL;
7639
7640 if (!info->attrs[NL80211_ATTR_REASON_CODE])
7641 return -EINVAL;
7642
Johannes Berg4c476992010-10-04 21:36:35 +02007643 if (!rdev->ops->deauth)
7644 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02007645
Johannes Berg074ac8d2010-09-16 14:58:22 +02007646 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02007647 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
7648 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02007649
Johannes Berg19957bb2009-07-02 17:20:43 +02007650 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02007651
Johannes Berg19957bb2009-07-02 17:20:43 +02007652 reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
7653 if (reason_code == 0) {
Johannes Bergf4a11bb2009-03-27 12:40:28 +01007654 /* Reason Code 0 is reserved */
Johannes Berg4c476992010-10-04 21:36:35 +02007655 return -EINVAL;
Jouni Malinen255e7372009-03-20 21:21:17 +02007656 }
Jouni Malinen636a5d32009-03-19 13:39:22 +02007657
7658 if (info->attrs[NL80211_ATTR_IE]) {
Johannes Berg19957bb2009-07-02 17:20:43 +02007659 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
7660 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02007661 }
7662
Jouni Malinend5cdfac2010-04-04 09:37:19 +03007663 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE];
7664
Johannes Berg91bf9b22013-05-15 17:44:01 +02007665 wdev_lock(dev->ieee80211_ptr);
7666 err = cfg80211_mlme_deauth(rdev, dev, bssid, ie, ie_len, reason_code,
7667 local_state_change);
7668 wdev_unlock(dev->ieee80211_ptr);
7669 return err;
Jouni Malinen636a5d32009-03-19 13:39:22 +02007670}
7671
7672static int nl80211_disassociate(struct sk_buff *skb, struct genl_info *info)
7673{
Johannes Berg4c476992010-10-04 21:36:35 +02007674 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7675 struct net_device *dev = info->user_ptr[1];
Johannes Berg19957bb2009-07-02 17:20:43 +02007676 const u8 *ie = NULL, *bssid;
Johannes Berg91bf9b22013-05-15 17:44:01 +02007677 int ie_len = 0, err;
Johannes Berg19957bb2009-07-02 17:20:43 +02007678 u16 reason_code;
Jouni Malinend5cdfac2010-04-04 09:37:19 +03007679 bool local_state_change;
Jouni Malinen636a5d32009-03-19 13:39:22 +02007680
Johannes Bergf4a11bb2009-03-27 12:40:28 +01007681 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
7682 return -EINVAL;
7683
7684 if (!info->attrs[NL80211_ATTR_MAC])
7685 return -EINVAL;
7686
7687 if (!info->attrs[NL80211_ATTR_REASON_CODE])
7688 return -EINVAL;
7689
Johannes Berg4c476992010-10-04 21:36:35 +02007690 if (!rdev->ops->disassoc)
7691 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02007692
Johannes Berg074ac8d2010-09-16 14:58:22 +02007693 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02007694 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
7695 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02007696
Johannes Berg19957bb2009-07-02 17:20:43 +02007697 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02007698
Johannes Berg19957bb2009-07-02 17:20:43 +02007699 reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
7700 if (reason_code == 0) {
Johannes Bergf4a11bb2009-03-27 12:40:28 +01007701 /* Reason Code 0 is reserved */
Johannes Berg4c476992010-10-04 21:36:35 +02007702 return -EINVAL;
Jouni Malinen255e7372009-03-20 21:21:17 +02007703 }
Jouni Malinen636a5d32009-03-19 13:39:22 +02007704
7705 if (info->attrs[NL80211_ATTR_IE]) {
Johannes Berg19957bb2009-07-02 17:20:43 +02007706 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
7707 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02007708 }
7709
Jouni Malinend5cdfac2010-04-04 09:37:19 +03007710 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE];
7711
Johannes Berg91bf9b22013-05-15 17:44:01 +02007712 wdev_lock(dev->ieee80211_ptr);
7713 err = cfg80211_mlme_disassoc(rdev, dev, bssid, ie, ie_len, reason_code,
7714 local_state_change);
7715 wdev_unlock(dev->ieee80211_ptr);
7716 return err;
Jouni Malinen636a5d32009-03-19 13:39:22 +02007717}
7718
Felix Fietkaudd5b4cc2010-11-22 20:58:24 +01007719static bool
7720nl80211_parse_mcast_rate(struct cfg80211_registered_device *rdev,
Johannes Berg57fbcce2016-04-12 15:56:15 +02007721 int mcast_rate[NUM_NL80211_BANDS],
Felix Fietkaudd5b4cc2010-11-22 20:58:24 +01007722 int rateval)
7723{
7724 struct wiphy *wiphy = &rdev->wiphy;
7725 bool found = false;
7726 int band, i;
7727
Johannes Berg57fbcce2016-04-12 15:56:15 +02007728 for (band = 0; band < NUM_NL80211_BANDS; band++) {
Felix Fietkaudd5b4cc2010-11-22 20:58:24 +01007729 struct ieee80211_supported_band *sband;
7730
7731 sband = wiphy->bands[band];
7732 if (!sband)
7733 continue;
7734
7735 for (i = 0; i < sband->n_bitrates; i++) {
7736 if (sband->bitrates[i].bitrate == rateval) {
7737 mcast_rate[band] = i + 1;
7738 found = true;
7739 break;
7740 }
7741 }
7742 }
7743
7744 return found;
7745}
7746
Johannes Berg04a773a2009-04-19 21:24:32 +02007747static int nl80211_join_ibss(struct sk_buff *skb, struct genl_info *info)
7748{
Johannes Berg4c476992010-10-04 21:36:35 +02007749 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7750 struct net_device *dev = info->user_ptr[1];
Johannes Berg04a773a2009-04-19 21:24:32 +02007751 struct cfg80211_ibss_params ibss;
7752 struct wiphy *wiphy;
Johannes Bergfffd0932009-07-08 14:22:54 +02007753 struct cfg80211_cached_keys *connkeys = NULL;
Johannes Berg04a773a2009-04-19 21:24:32 +02007754 int err;
7755
Johannes Berg8e30bc52009-04-22 17:45:38 +02007756 memset(&ibss, 0, sizeof(ibss));
7757
Johannes Berg04a773a2009-04-19 21:24:32 +02007758 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
7759 return -EINVAL;
7760
Johannes Berg683b6d32012-11-08 21:25:48 +01007761 if (!info->attrs[NL80211_ATTR_SSID] ||
Johannes Berg04a773a2009-04-19 21:24:32 +02007762 !nla_len(info->attrs[NL80211_ATTR_SSID]))
7763 return -EINVAL;
7764
Johannes Berg8e30bc52009-04-22 17:45:38 +02007765 ibss.beacon_interval = 100;
7766
Purushottam Kushwaha12d20fc92016-08-11 15:14:02 +05307767 if (info->attrs[NL80211_ATTR_BEACON_INTERVAL])
Johannes Berg8e30bc52009-04-22 17:45:38 +02007768 ibss.beacon_interval =
7769 nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]);
Purushottam Kushwaha12d20fc92016-08-11 15:14:02 +05307770
7771 err = cfg80211_validate_beacon_int(rdev, ibss.beacon_interval);
7772 if (err)
7773 return err;
Johannes Berg8e30bc52009-04-22 17:45:38 +02007774
Johannes Berg4c476992010-10-04 21:36:35 +02007775 if (!rdev->ops->join_ibss)
7776 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02007777
Johannes Berg4c476992010-10-04 21:36:35 +02007778 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC)
7779 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02007780
Johannes Berg79c97e92009-07-07 03:56:12 +02007781 wiphy = &rdev->wiphy;
Johannes Berg04a773a2009-04-19 21:24:32 +02007782
Johannes Berg39193492011-09-16 13:45:25 +02007783 if (info->attrs[NL80211_ATTR_MAC]) {
Johannes Berg04a773a2009-04-19 21:24:32 +02007784 ibss.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Johannes Berg39193492011-09-16 13:45:25 +02007785
7786 if (!is_valid_ether_addr(ibss.bssid))
7787 return -EINVAL;
7788 }
Johannes Berg04a773a2009-04-19 21:24:32 +02007789 ibss.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
7790 ibss.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
7791
7792 if (info->attrs[NL80211_ATTR_IE]) {
7793 ibss.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
7794 ibss.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
7795 }
7796
Johannes Berg683b6d32012-11-08 21:25:48 +01007797 err = nl80211_parse_chandef(rdev, info, &ibss.chandef);
7798 if (err)
7799 return err;
Alexander Simon54858ee5b2011-11-30 16:56:32 +01007800
Ilan Peer174e0cd2014-02-23 09:13:01 +02007801 if (!cfg80211_reg_can_beacon(&rdev->wiphy, &ibss.chandef,
7802 NL80211_IFTYPE_ADHOC))
Alexander Simon54858ee5b2011-11-30 16:56:32 +01007803 return -EINVAL;
7804
Simon Wunderlich2f301ab2013-05-16 13:00:28 +02007805 switch (ibss.chandef.width) {
Simon Wunderlichbf372642013-07-08 16:55:58 +02007806 case NL80211_CHAN_WIDTH_5:
7807 case NL80211_CHAN_WIDTH_10:
Simon Wunderlich2f301ab2013-05-16 13:00:28 +02007808 case NL80211_CHAN_WIDTH_20_NOHT:
7809 break;
7810 case NL80211_CHAN_WIDTH_20:
7811 case NL80211_CHAN_WIDTH_40:
Janusz.Dziedzic@tieto.comffc11992015-02-21 16:52:39 +01007812 if (!(rdev->wiphy.features & NL80211_FEATURE_HT_IBSS))
7813 return -EINVAL;
7814 break;
7815 case NL80211_CHAN_WIDTH_80:
7816 case NL80211_CHAN_WIDTH_80P80:
7817 case NL80211_CHAN_WIDTH_160:
7818 if (!(rdev->wiphy.features & NL80211_FEATURE_HT_IBSS))
7819 return -EINVAL;
7820 if (!wiphy_ext_feature_isset(&rdev->wiphy,
7821 NL80211_EXT_FEATURE_VHT_IBSS))
7822 return -EINVAL;
7823 break;
Simon Wunderlich2f301ab2013-05-16 13:00:28 +02007824 default:
Johannes Bergdb9c64c2012-11-09 14:56:41 +01007825 return -EINVAL;
Simon Wunderlich2f301ab2013-05-16 13:00:28 +02007826 }
Johannes Bergdb9c64c2012-11-09 14:56:41 +01007827
Johannes Berg04a773a2009-04-19 21:24:32 +02007828 ibss.channel_fixed = !!info->attrs[NL80211_ATTR_FREQ_FIXED];
Johannes Bergfffd0932009-07-08 14:22:54 +02007829 ibss.privacy = !!info->attrs[NL80211_ATTR_PRIVACY];
Johannes Berg04a773a2009-04-19 21:24:32 +02007830
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03007831 if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) {
7832 u8 *rates =
7833 nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
7834 int n_rates =
7835 nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
7836 struct ieee80211_supported_band *sband =
Johannes Berg683b6d32012-11-08 21:25:48 +01007837 wiphy->bands[ibss.chandef.chan->band];
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03007838
Johannes Berg34850ab2011-07-18 18:08:35 +02007839 err = ieee80211_get_ratemask(sband, rates, n_rates,
7840 &ibss.basic_rates);
7841 if (err)
7842 return err;
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03007843 }
Felix Fietkaudd5b4cc2010-11-22 20:58:24 +01007844
Simon Wunderlich803768f2013-06-28 10:39:58 +02007845 if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
7846 memcpy(&ibss.ht_capa_mask,
7847 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]),
7848 sizeof(ibss.ht_capa_mask));
7849
7850 if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) {
7851 if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
7852 return -EINVAL;
7853 memcpy(&ibss.ht_capa,
7854 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]),
7855 sizeof(ibss.ht_capa));
7856 }
7857
Felix Fietkaudd5b4cc2010-11-22 20:58:24 +01007858 if (info->attrs[NL80211_ATTR_MCAST_RATE] &&
7859 !nl80211_parse_mcast_rate(rdev, ibss.mcast_rate,
7860 nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE])))
7861 return -EINVAL;
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03007862
Johannes Berg4c476992010-10-04 21:36:35 +02007863 if (ibss.privacy && info->attrs[NL80211_ATTR_KEYS]) {
Sujith Manoharande7044e2012-10-18 10:19:28 +05307864 bool no_ht = false;
7865
Johannes Berg4c476992010-10-04 21:36:35 +02007866 connkeys = nl80211_parse_connkeys(rdev,
Sujith Manoharande7044e2012-10-18 10:19:28 +05307867 info->attrs[NL80211_ATTR_KEYS],
7868 &no_ht);
Johannes Berg4c476992010-10-04 21:36:35 +02007869 if (IS_ERR(connkeys))
7870 return PTR_ERR(connkeys);
Sujith Manoharande7044e2012-10-18 10:19:28 +05307871
Johannes Berg3d9d1d62012-11-08 23:14:50 +01007872 if ((ibss.chandef.width != NL80211_CHAN_WIDTH_20_NOHT) &&
7873 no_ht) {
Ola Olsson5e950a72016-02-11 01:00:22 +01007874 kzfree(connkeys);
Sujith Manoharande7044e2012-10-18 10:19:28 +05307875 return -EINVAL;
7876 }
Johannes Berg4c476992010-10-04 21:36:35 +02007877 }
Johannes Berg04a773a2009-04-19 21:24:32 +02007878
Antonio Quartulli267335d2012-01-31 20:25:47 +01007879 ibss.control_port =
7880 nla_get_flag(info->attrs[NL80211_ATTR_CONTROL_PORT]);
7881
Simon Wunderlich5336fa82013-10-07 18:41:05 +02007882 ibss.userspace_handles_dfs =
7883 nla_get_flag(info->attrs[NL80211_ATTR_HANDLE_DFS]);
7884
Johannes Berg4c476992010-10-04 21:36:35 +02007885 err = cfg80211_join_ibss(rdev, dev, &ibss, connkeys);
Johannes Bergfffd0932009-07-08 14:22:54 +02007886 if (err)
Johannes Bergb47f6102014-09-10 13:39:54 +03007887 kzfree(connkeys);
Johannes Berg04a773a2009-04-19 21:24:32 +02007888 return err;
7889}
7890
7891static int nl80211_leave_ibss(struct sk_buff *skb, struct genl_info *info)
7892{
Johannes Berg4c476992010-10-04 21:36:35 +02007893 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7894 struct net_device *dev = info->user_ptr[1];
Johannes Berg04a773a2009-04-19 21:24:32 +02007895
Johannes Berg4c476992010-10-04 21:36:35 +02007896 if (!rdev->ops->leave_ibss)
7897 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02007898
Johannes Berg4c476992010-10-04 21:36:35 +02007899 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC)
7900 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02007901
Johannes Berg4c476992010-10-04 21:36:35 +02007902 return cfg80211_leave_ibss(rdev, dev, false);
Johannes Berg04a773a2009-04-19 21:24:32 +02007903}
7904
Antonio Quartullif4e583c2012-11-02 13:27:48 +01007905static int nl80211_set_mcast_rate(struct sk_buff *skb, struct genl_info *info)
7906{
7907 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7908 struct net_device *dev = info->user_ptr[1];
Johannes Berg57fbcce2016-04-12 15:56:15 +02007909 int mcast_rate[NUM_NL80211_BANDS];
Antonio Quartullif4e583c2012-11-02 13:27:48 +01007910 u32 nla_rate;
7911 int err;
7912
7913 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC &&
Bertold Van den Bergh876dc932015-08-05 16:02:21 +02007914 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT &&
7915 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_OCB)
Antonio Quartullif4e583c2012-11-02 13:27:48 +01007916 return -EOPNOTSUPP;
7917
7918 if (!rdev->ops->set_mcast_rate)
7919 return -EOPNOTSUPP;
7920
7921 memset(mcast_rate, 0, sizeof(mcast_rate));
7922
7923 if (!info->attrs[NL80211_ATTR_MCAST_RATE])
7924 return -EINVAL;
7925
7926 nla_rate = nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]);
7927 if (!nl80211_parse_mcast_rate(rdev, mcast_rate, nla_rate))
7928 return -EINVAL;
7929
Ilan Peera1056b12015-10-22 22:27:46 +03007930 err = rdev_set_mcast_rate(rdev, dev, mcast_rate);
Antonio Quartullif4e583c2012-11-02 13:27:48 +01007931
7932 return err;
7933}
7934
Johannes Bergad7e7182013-11-13 13:37:47 +01007935static struct sk_buff *
7936__cfg80211_alloc_vendor_skb(struct cfg80211_registered_device *rdev,
Ahmad Kholaif6c09e792015-02-26 15:26:53 +02007937 struct wireless_dev *wdev, int approxlen,
7938 u32 portid, u32 seq, enum nl80211_commands cmd,
Johannes Berg567ffc32013-12-18 14:43:31 +01007939 enum nl80211_attrs attr,
7940 const struct nl80211_vendor_cmd_info *info,
7941 gfp_t gfp)
Johannes Bergad7e7182013-11-13 13:37:47 +01007942{
7943 struct sk_buff *skb;
7944 void *hdr;
7945 struct nlattr *data;
7946
7947 skb = nlmsg_new(approxlen + 100, gfp);
7948 if (!skb)
7949 return NULL;
7950
7951 hdr = nl80211hdr_put(skb, portid, seq, 0, cmd);
7952 if (!hdr) {
7953 kfree_skb(skb);
7954 return NULL;
7955 }
7956
7957 if (nla_put_u32(skb, NL80211_ATTR_WIPHY, rdev->wiphy_idx))
7958 goto nla_put_failure;
Johannes Berg567ffc32013-12-18 14:43:31 +01007959
7960 if (info) {
7961 if (nla_put_u32(skb, NL80211_ATTR_VENDOR_ID,
7962 info->vendor_id))
7963 goto nla_put_failure;
7964 if (nla_put_u32(skb, NL80211_ATTR_VENDOR_SUBCMD,
7965 info->subcmd))
7966 goto nla_put_failure;
7967 }
7968
Ahmad Kholaif6c09e792015-02-26 15:26:53 +02007969 if (wdev) {
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02007970 if (nla_put_u64_64bit(skb, NL80211_ATTR_WDEV,
7971 wdev_id(wdev), NL80211_ATTR_PAD))
Ahmad Kholaif6c09e792015-02-26 15:26:53 +02007972 goto nla_put_failure;
7973 if (wdev->netdev &&
7974 nla_put_u32(skb, NL80211_ATTR_IFINDEX,
7975 wdev->netdev->ifindex))
7976 goto nla_put_failure;
7977 }
7978
Johannes Bergad7e7182013-11-13 13:37:47 +01007979 data = nla_nest_start(skb, attr);
7980
7981 ((void **)skb->cb)[0] = rdev;
7982 ((void **)skb->cb)[1] = hdr;
7983 ((void **)skb->cb)[2] = data;
7984
7985 return skb;
7986
7987 nla_put_failure:
7988 kfree_skb(skb);
7989 return NULL;
7990}
Antonio Quartullif4e583c2012-11-02 13:27:48 +01007991
Johannes Berge03ad6e2014-01-01 17:22:30 +01007992struct sk_buff *__cfg80211_alloc_event_skb(struct wiphy *wiphy,
Ahmad Kholaif6c09e792015-02-26 15:26:53 +02007993 struct wireless_dev *wdev,
Johannes Berge03ad6e2014-01-01 17:22:30 +01007994 enum nl80211_commands cmd,
7995 enum nl80211_attrs attr,
7996 int vendor_event_idx,
7997 int approxlen, gfp_t gfp)
7998{
Zhao, Gangf26cbf42014-04-21 12:53:03 +08007999 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berge03ad6e2014-01-01 17:22:30 +01008000 const struct nl80211_vendor_cmd_info *info;
8001
8002 switch (cmd) {
8003 case NL80211_CMD_TESTMODE:
8004 if (WARN_ON(vendor_event_idx != -1))
8005 return NULL;
8006 info = NULL;
8007 break;
8008 case NL80211_CMD_VENDOR:
8009 if (WARN_ON(vendor_event_idx < 0 ||
8010 vendor_event_idx >= wiphy->n_vendor_events))
8011 return NULL;
8012 info = &wiphy->vendor_events[vendor_event_idx];
8013 break;
8014 default:
8015 WARN_ON(1);
8016 return NULL;
8017 }
8018
Ahmad Kholaif6c09e792015-02-26 15:26:53 +02008019 return __cfg80211_alloc_vendor_skb(rdev, wdev, approxlen, 0, 0,
Johannes Berge03ad6e2014-01-01 17:22:30 +01008020 cmd, attr, info, gfp);
8021}
8022EXPORT_SYMBOL(__cfg80211_alloc_event_skb);
8023
8024void __cfg80211_send_event_skb(struct sk_buff *skb, gfp_t gfp)
8025{
8026 struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0];
8027 void *hdr = ((void **)skb->cb)[1];
8028 struct nlattr *data = ((void **)skb->cb)[2];
8029 enum nl80211_multicast_groups mcgrp = NL80211_MCGRP_TESTMODE;
8030
Johannes Bergbd8c78e2014-07-30 14:55:26 +02008031 /* clear CB data for netlink core to own from now on */
8032 memset(skb->cb, 0, sizeof(skb->cb));
8033
Johannes Berge03ad6e2014-01-01 17:22:30 +01008034 nla_nest_end(skb, data);
8035 genlmsg_end(skb, hdr);
8036
8037 if (data->nla_type == NL80211_ATTR_VENDOR_DATA)
8038 mcgrp = NL80211_MCGRP_VENDOR;
8039
8040 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), skb, 0,
8041 mcgrp, gfp);
8042}
8043EXPORT_SYMBOL(__cfg80211_send_event_skb);
8044
Johannes Bergaff89a92009-07-01 21:26:51 +02008045#ifdef CONFIG_NL80211_TESTMODE
Johannes Bergaff89a92009-07-01 21:26:51 +02008046static int nl80211_testmode_do(struct sk_buff *skb, struct genl_info *info)
8047{
Johannes Berg4c476992010-10-04 21:36:35 +02008048 struct cfg80211_registered_device *rdev = info->user_ptr[0];
David Spinadelfc73f112013-07-31 18:04:15 +03008049 struct wireless_dev *wdev =
8050 __cfg80211_wdev_from_attrs(genl_info_net(info), info->attrs);
Johannes Bergaff89a92009-07-01 21:26:51 +02008051 int err;
8052
David Spinadelfc73f112013-07-31 18:04:15 +03008053 if (!rdev->ops->testmode_cmd)
8054 return -EOPNOTSUPP;
8055
8056 if (IS_ERR(wdev)) {
8057 err = PTR_ERR(wdev);
8058 if (err != -EINVAL)
8059 return err;
8060 wdev = NULL;
8061 } else if (wdev->wiphy != &rdev->wiphy) {
8062 return -EINVAL;
8063 }
8064
Johannes Bergaff89a92009-07-01 21:26:51 +02008065 if (!info->attrs[NL80211_ATTR_TESTDATA])
8066 return -EINVAL;
8067
Johannes Bergad7e7182013-11-13 13:37:47 +01008068 rdev->cur_cmd_info = info;
David Spinadelfc73f112013-07-31 18:04:15 +03008069 err = rdev_testmode_cmd(rdev, wdev,
Johannes Bergaff89a92009-07-01 21:26:51 +02008070 nla_data(info->attrs[NL80211_ATTR_TESTDATA]),
8071 nla_len(info->attrs[NL80211_ATTR_TESTDATA]));
Johannes Bergad7e7182013-11-13 13:37:47 +01008072 rdev->cur_cmd_info = NULL;
Johannes Bergaff89a92009-07-01 21:26:51 +02008073
Johannes Bergaff89a92009-07-01 21:26:51 +02008074 return err;
8075}
8076
Wey-Yi Guy71063f02011-05-20 09:05:54 -07008077static int nl80211_testmode_dump(struct sk_buff *skb,
8078 struct netlink_callback *cb)
8079{
Johannes Berg00918d32011-12-13 17:22:05 +01008080 struct cfg80211_registered_device *rdev;
Wey-Yi Guy71063f02011-05-20 09:05:54 -07008081 int err;
8082 long phy_idx;
8083 void *data = NULL;
8084 int data_len = 0;
8085
Johannes Berg5fe231e2013-05-08 21:45:15 +02008086 rtnl_lock();
8087
Wey-Yi Guy71063f02011-05-20 09:05:54 -07008088 if (cb->args[0]) {
8089 /*
8090 * 0 is a valid index, but not valid for args[0],
8091 * so we need to offset by 1.
8092 */
8093 phy_idx = cb->args[0] - 1;
8094 } else {
8095 err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize,
8096 nl80211_fam.attrbuf, nl80211_fam.maxattr,
8097 nl80211_policy);
8098 if (err)
Johannes Berg5fe231e2013-05-08 21:45:15 +02008099 goto out_err;
Johannes Berg00918d32011-12-13 17:22:05 +01008100
Johannes Berg2bd7e352012-06-15 14:23:16 +02008101 rdev = __cfg80211_rdev_from_attrs(sock_net(skb->sk),
8102 nl80211_fam.attrbuf);
8103 if (IS_ERR(rdev)) {
Johannes Berg5fe231e2013-05-08 21:45:15 +02008104 err = PTR_ERR(rdev);
8105 goto out_err;
Johannes Berg00918d32011-12-13 17:22:05 +01008106 }
Johannes Berg2bd7e352012-06-15 14:23:16 +02008107 phy_idx = rdev->wiphy_idx;
8108 rdev = NULL;
Johannes Berg2bd7e352012-06-15 14:23:16 +02008109
Wey-Yi Guy71063f02011-05-20 09:05:54 -07008110 if (nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA])
8111 cb->args[1] =
8112 (long)nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA];
8113 }
8114
8115 if (cb->args[1]) {
8116 data = nla_data((void *)cb->args[1]);
8117 data_len = nla_len((void *)cb->args[1]);
8118 }
8119
Johannes Berg00918d32011-12-13 17:22:05 +01008120 rdev = cfg80211_rdev_by_wiphy_idx(phy_idx);
8121 if (!rdev) {
Johannes Berg5fe231e2013-05-08 21:45:15 +02008122 err = -ENOENT;
8123 goto out_err;
Wey-Yi Guy71063f02011-05-20 09:05:54 -07008124 }
Wey-Yi Guy71063f02011-05-20 09:05:54 -07008125
Johannes Berg00918d32011-12-13 17:22:05 +01008126 if (!rdev->ops->testmode_dump) {
Wey-Yi Guy71063f02011-05-20 09:05:54 -07008127 err = -EOPNOTSUPP;
8128 goto out_err;
8129 }
8130
8131 while (1) {
Eric W. Biederman15e47302012-09-07 20:12:54 +00008132 void *hdr = nl80211hdr_put(skb, NETLINK_CB(cb->skb).portid,
Wey-Yi Guy71063f02011-05-20 09:05:54 -07008133 cb->nlh->nlmsg_seq, NLM_F_MULTI,
8134 NL80211_CMD_TESTMODE);
8135 struct nlattr *tmdata;
8136
Dan Carpentercb35fba2013-08-14 14:50:01 +03008137 if (!hdr)
8138 break;
8139
David S. Miller9360ffd2012-03-29 04:41:26 -04008140 if (nla_put_u32(skb, NL80211_ATTR_WIPHY, phy_idx)) {
Wey-Yi Guy71063f02011-05-20 09:05:54 -07008141 genlmsg_cancel(skb, hdr);
8142 break;
8143 }
8144
8145 tmdata = nla_nest_start(skb, NL80211_ATTR_TESTDATA);
8146 if (!tmdata) {
8147 genlmsg_cancel(skb, hdr);
8148 break;
8149 }
Hila Gonene35e4d22012-06-27 17:19:42 +03008150 err = rdev_testmode_dump(rdev, skb, cb, data, data_len);
Wey-Yi Guy71063f02011-05-20 09:05:54 -07008151 nla_nest_end(skb, tmdata);
8152
8153 if (err == -ENOBUFS || err == -ENOENT) {
8154 genlmsg_cancel(skb, hdr);
8155 break;
8156 } else if (err) {
8157 genlmsg_cancel(skb, hdr);
8158 goto out_err;
8159 }
8160
8161 genlmsg_end(skb, hdr);
8162 }
8163
8164 err = skb->len;
8165 /* see above */
8166 cb->args[0] = phy_idx + 1;
8167 out_err:
Johannes Berg5fe231e2013-05-08 21:45:15 +02008168 rtnl_unlock();
Wey-Yi Guy71063f02011-05-20 09:05:54 -07008169 return err;
8170}
Johannes Bergaff89a92009-07-01 21:26:51 +02008171#endif
8172
Samuel Ortizb23aa672009-07-01 21:26:54 +02008173static int nl80211_connect(struct sk_buff *skb, struct genl_info *info)
8174{
Johannes Berg4c476992010-10-04 21:36:35 +02008175 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8176 struct net_device *dev = info->user_ptr[1];
Samuel Ortizb23aa672009-07-01 21:26:54 +02008177 struct cfg80211_connect_params connect;
8178 struct wiphy *wiphy;
Johannes Bergfffd0932009-07-08 14:22:54 +02008179 struct cfg80211_cached_keys *connkeys = NULL;
Samuel Ortizb23aa672009-07-01 21:26:54 +02008180 int err;
8181
8182 memset(&connect, 0, sizeof(connect));
8183
8184 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
8185 return -EINVAL;
8186
8187 if (!info->attrs[NL80211_ATTR_SSID] ||
8188 !nla_len(info->attrs[NL80211_ATTR_SSID]))
8189 return -EINVAL;
8190
8191 if (info->attrs[NL80211_ATTR_AUTH_TYPE]) {
8192 connect.auth_type =
8193 nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]);
Jouni Malinene39e5b52012-09-30 19:29:39 +03008194 if (!nl80211_valid_auth_type(rdev, connect.auth_type,
8195 NL80211_CMD_CONNECT))
Samuel Ortizb23aa672009-07-01 21:26:54 +02008196 return -EINVAL;
8197 } else
8198 connect.auth_type = NL80211_AUTHTYPE_AUTOMATIC;
8199
8200 connect.privacy = info->attrs[NL80211_ATTR_PRIVACY];
8201
Johannes Bergc0692b82010-08-27 14:26:53 +03008202 err = nl80211_crypto_settings(rdev, info, &connect.crypto,
Johannes Berg3dc27d22009-07-02 21:36:37 +02008203 NL80211_MAX_NR_CIPHER_SUITES);
Samuel Ortizb23aa672009-07-01 21:26:54 +02008204 if (err)
8205 return err;
Samuel Ortizb23aa672009-07-01 21:26:54 +02008206
Johannes Berg074ac8d2010-09-16 14:58:22 +02008207 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02008208 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
8209 return -EOPNOTSUPP;
Samuel Ortizb23aa672009-07-01 21:26:54 +02008210
Johannes Berg79c97e92009-07-07 03:56:12 +02008211 wiphy = &rdev->wiphy;
Samuel Ortizb23aa672009-07-01 21:26:54 +02008212
Bala Shanmugam4486ea92012-03-07 17:27:12 +05308213 connect.bg_scan_period = -1;
8214 if (info->attrs[NL80211_ATTR_BG_SCAN_PERIOD] &&
8215 (wiphy->flags & WIPHY_FLAG_SUPPORTS_FW_ROAM)) {
8216 connect.bg_scan_period =
8217 nla_get_u16(info->attrs[NL80211_ATTR_BG_SCAN_PERIOD]);
8218 }
8219
Samuel Ortizb23aa672009-07-01 21:26:54 +02008220 if (info->attrs[NL80211_ATTR_MAC])
8221 connect.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen1df4a512014-01-15 00:00:47 +02008222 else if (info->attrs[NL80211_ATTR_MAC_HINT])
8223 connect.bssid_hint =
8224 nla_data(info->attrs[NL80211_ATTR_MAC_HINT]);
Samuel Ortizb23aa672009-07-01 21:26:54 +02008225 connect.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
8226 connect.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
8227
8228 if (info->attrs[NL80211_ATTR_IE]) {
8229 connect.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
8230 connect.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
8231 }
8232
Jouni Malinencee00a92013-01-15 17:15:57 +02008233 if (info->attrs[NL80211_ATTR_USE_MFP]) {
8234 connect.mfp = nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]);
8235 if (connect.mfp != NL80211_MFP_REQUIRED &&
8236 connect.mfp != NL80211_MFP_NO)
8237 return -EINVAL;
8238 } else {
8239 connect.mfp = NL80211_MFP_NO;
8240 }
8241
Jouni Malinenba6fbac2016-03-29 13:53:27 +03008242 if (info->attrs[NL80211_ATTR_PREV_BSSID])
8243 connect.prev_bssid =
8244 nla_data(info->attrs[NL80211_ATTR_PREV_BSSID]);
8245
Samuel Ortizb23aa672009-07-01 21:26:54 +02008246 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
Jouni Malinen664834d2014-01-15 00:01:44 +02008247 connect.channel = nl80211_get_valid_chan(
8248 wiphy, info->attrs[NL80211_ATTR_WIPHY_FREQ]);
8249 if (!connect.channel)
Johannes Berg4c476992010-10-04 21:36:35 +02008250 return -EINVAL;
Jouni Malinen1df4a512014-01-15 00:00:47 +02008251 } else if (info->attrs[NL80211_ATTR_WIPHY_FREQ_HINT]) {
Jouni Malinen664834d2014-01-15 00:01:44 +02008252 connect.channel_hint = nl80211_get_valid_chan(
8253 wiphy, info->attrs[NL80211_ATTR_WIPHY_FREQ_HINT]);
8254 if (!connect.channel_hint)
Jouni Malinen1df4a512014-01-15 00:00:47 +02008255 return -EINVAL;
Samuel Ortizb23aa672009-07-01 21:26:54 +02008256 }
8257
Johannes Bergfffd0932009-07-08 14:22:54 +02008258 if (connect.privacy && info->attrs[NL80211_ATTR_KEYS]) {
8259 connkeys = nl80211_parse_connkeys(rdev,
Sujith Manoharande7044e2012-10-18 10:19:28 +05308260 info->attrs[NL80211_ATTR_KEYS], NULL);
Johannes Berg4c476992010-10-04 21:36:35 +02008261 if (IS_ERR(connkeys))
8262 return PTR_ERR(connkeys);
Johannes Bergfffd0932009-07-08 14:22:54 +02008263 }
8264
Ben Greear7e7c8922011-11-18 11:31:59 -08008265 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT]))
8266 connect.flags |= ASSOC_REQ_DISABLE_HT;
8267
8268 if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
8269 memcpy(&connect.ht_capa_mask,
8270 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]),
8271 sizeof(connect.ht_capa_mask));
8272
8273 if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) {
Wei Yongjunb4e4f472012-09-02 21:41:04 +08008274 if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) {
Johannes Bergb47f6102014-09-10 13:39:54 +03008275 kzfree(connkeys);
Ben Greear7e7c8922011-11-18 11:31:59 -08008276 return -EINVAL;
Wei Yongjunb4e4f472012-09-02 21:41:04 +08008277 }
Ben Greear7e7c8922011-11-18 11:31:59 -08008278 memcpy(&connect.ht_capa,
8279 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]),
8280 sizeof(connect.ht_capa));
8281 }
8282
Johannes Bergee2aca32013-02-21 17:36:01 +01008283 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_VHT]))
8284 connect.flags |= ASSOC_REQ_DISABLE_VHT;
8285
8286 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK])
8287 memcpy(&connect.vht_capa_mask,
8288 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]),
8289 sizeof(connect.vht_capa_mask));
8290
8291 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) {
8292 if (!info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) {
Johannes Bergb47f6102014-09-10 13:39:54 +03008293 kzfree(connkeys);
Johannes Bergee2aca32013-02-21 17:36:01 +01008294 return -EINVAL;
8295 }
8296 memcpy(&connect.vht_capa,
8297 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]),
8298 sizeof(connect.vht_capa));
8299 }
8300
Assaf Kraussbab5ab72014-09-03 15:25:01 +03008301 if (nla_get_flag(info->attrs[NL80211_ATTR_USE_RRM])) {
Beni Lev0c9ca112016-02-17 20:30:00 +02008302 if (!((rdev->wiphy.features &
8303 NL80211_FEATURE_DS_PARAM_SET_IE_IN_PROBES) &&
8304 (rdev->wiphy.features & NL80211_FEATURE_QUIET)) &&
8305 !wiphy_ext_feature_isset(&rdev->wiphy,
8306 NL80211_EXT_FEATURE_RRM)) {
Ola Olsson707554b2015-12-11 21:04:52 +01008307 kzfree(connkeys);
Assaf Kraussbab5ab72014-09-03 15:25:01 +03008308 return -EINVAL;
Ola Olsson707554b2015-12-11 21:04:52 +01008309 }
Assaf Kraussbab5ab72014-09-03 15:25:01 +03008310 connect.flags |= ASSOC_REQ_USE_RRM;
8311 }
8312
Lior David34d50512016-01-28 10:58:25 +02008313 connect.pbss = nla_get_flag(info->attrs[NL80211_ATTR_PBSS]);
Johannes Berg57fbcce2016-04-12 15:56:15 +02008314 if (connect.pbss && !rdev->wiphy.bands[NL80211_BAND_60GHZ]) {
Lior David34d50512016-01-28 10:58:25 +02008315 kzfree(connkeys);
8316 return -EOPNOTSUPP;
8317 }
8318
Arend van Spriel38de03d2016-03-02 20:37:18 +01008319 if (info->attrs[NL80211_ATTR_BSS_SELECT]) {
8320 /* bss selection makes no sense if bssid is set */
8321 if (connect.bssid) {
8322 kzfree(connkeys);
8323 return -EINVAL;
8324 }
8325
8326 err = parse_bss_select(info->attrs[NL80211_ATTR_BSS_SELECT],
8327 wiphy, &connect.bss_select);
8328 if (err) {
8329 kzfree(connkeys);
8330 return err;
8331 }
8332 }
8333
Johannes Berg83739b02013-05-15 17:44:01 +02008334 wdev_lock(dev->ieee80211_ptr);
Jouni Malinen4ce2bd92016-03-29 13:53:28 +03008335 err = cfg80211_connect(rdev, dev, &connect, connkeys,
8336 connect.prev_bssid);
Johannes Berg83739b02013-05-15 17:44:01 +02008337 wdev_unlock(dev->ieee80211_ptr);
Johannes Bergfffd0932009-07-08 14:22:54 +02008338 if (err)
Johannes Bergb47f6102014-09-10 13:39:54 +03008339 kzfree(connkeys);
Samuel Ortizb23aa672009-07-01 21:26:54 +02008340 return err;
8341}
8342
8343static int nl80211_disconnect(struct sk_buff *skb, struct genl_info *info)
8344{
Johannes Berg4c476992010-10-04 21:36:35 +02008345 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8346 struct net_device *dev = info->user_ptr[1];
Samuel Ortizb23aa672009-07-01 21:26:54 +02008347 u16 reason;
Johannes Berg83739b02013-05-15 17:44:01 +02008348 int ret;
Samuel Ortizb23aa672009-07-01 21:26:54 +02008349
8350 if (!info->attrs[NL80211_ATTR_REASON_CODE])
8351 reason = WLAN_REASON_DEAUTH_LEAVING;
8352 else
8353 reason = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
8354
8355 if (reason == 0)
8356 return -EINVAL;
8357
Johannes Berg074ac8d2010-09-16 14:58:22 +02008358 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02008359 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
8360 return -EOPNOTSUPP;
Samuel Ortizb23aa672009-07-01 21:26:54 +02008361
Johannes Berg83739b02013-05-15 17:44:01 +02008362 wdev_lock(dev->ieee80211_ptr);
8363 ret = cfg80211_disconnect(rdev, dev, reason, true);
8364 wdev_unlock(dev->ieee80211_ptr);
8365 return ret;
Samuel Ortizb23aa672009-07-01 21:26:54 +02008366}
8367
Johannes Berg463d0182009-07-14 00:33:35 +02008368static int nl80211_wiphy_netns(struct sk_buff *skb, struct genl_info *info)
8369{
Johannes Berg4c476992010-10-04 21:36:35 +02008370 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg463d0182009-07-14 00:33:35 +02008371 struct net *net;
8372 int err;
Johannes Berg463d0182009-07-14 00:33:35 +02008373
Vadim Kochan4b681c82015-01-12 16:34:05 +02008374 if (info->attrs[NL80211_ATTR_PID]) {
8375 u32 pid = nla_get_u32(info->attrs[NL80211_ATTR_PID]);
8376
8377 net = get_net_ns_by_pid(pid);
8378 } else if (info->attrs[NL80211_ATTR_NETNS_FD]) {
8379 u32 fd = nla_get_u32(info->attrs[NL80211_ATTR_NETNS_FD]);
8380
8381 net = get_net_ns_by_fd(fd);
8382 } else {
Johannes Berg463d0182009-07-14 00:33:35 +02008383 return -EINVAL;
Vadim Kochan4b681c82015-01-12 16:34:05 +02008384 }
Johannes Berg463d0182009-07-14 00:33:35 +02008385
Johannes Berg4c476992010-10-04 21:36:35 +02008386 if (IS_ERR(net))
8387 return PTR_ERR(net);
Johannes Berg463d0182009-07-14 00:33:35 +02008388
8389 err = 0;
8390
8391 /* check if anything to do */
Johannes Berg4c476992010-10-04 21:36:35 +02008392 if (!net_eq(wiphy_net(&rdev->wiphy), net))
8393 err = cfg80211_switch_netns(rdev, net);
Johannes Berg463d0182009-07-14 00:33:35 +02008394
Johannes Berg463d0182009-07-14 00:33:35 +02008395 put_net(net);
Johannes Berg463d0182009-07-14 00:33:35 +02008396 return err;
8397}
8398
Samuel Ortiz67fbb162009-11-24 23:59:15 +01008399static int nl80211_setdel_pmksa(struct sk_buff *skb, struct genl_info *info)
8400{
Johannes Berg4c476992010-10-04 21:36:35 +02008401 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Samuel Ortiz67fbb162009-11-24 23:59:15 +01008402 int (*rdev_ops)(struct wiphy *wiphy, struct net_device *dev,
8403 struct cfg80211_pmksa *pmksa) = NULL;
Johannes Berg4c476992010-10-04 21:36:35 +02008404 struct net_device *dev = info->user_ptr[1];
Samuel Ortiz67fbb162009-11-24 23:59:15 +01008405 struct cfg80211_pmksa pmksa;
8406
8407 memset(&pmksa, 0, sizeof(struct cfg80211_pmksa));
8408
8409 if (!info->attrs[NL80211_ATTR_MAC])
8410 return -EINVAL;
8411
8412 if (!info->attrs[NL80211_ATTR_PMKID])
8413 return -EINVAL;
8414
Samuel Ortiz67fbb162009-11-24 23:59:15 +01008415 pmksa.pmkid = nla_data(info->attrs[NL80211_ATTR_PMKID]);
8416 pmksa.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
8417
Johannes Berg074ac8d2010-09-16 14:58:22 +02008418 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02008419 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
8420 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01008421
8422 switch (info->genlhdr->cmd) {
8423 case NL80211_CMD_SET_PMKSA:
8424 rdev_ops = rdev->ops->set_pmksa;
8425 break;
8426 case NL80211_CMD_DEL_PMKSA:
8427 rdev_ops = rdev->ops->del_pmksa;
8428 break;
8429 default:
8430 WARN_ON(1);
8431 break;
8432 }
8433
Johannes Berg4c476992010-10-04 21:36:35 +02008434 if (!rdev_ops)
8435 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01008436
Johannes Berg4c476992010-10-04 21:36:35 +02008437 return rdev_ops(&rdev->wiphy, dev, &pmksa);
Samuel Ortiz67fbb162009-11-24 23:59:15 +01008438}
8439
8440static int nl80211_flush_pmksa(struct sk_buff *skb, struct genl_info *info)
8441{
Johannes Berg4c476992010-10-04 21:36:35 +02008442 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8443 struct net_device *dev = info->user_ptr[1];
Samuel Ortiz67fbb162009-11-24 23:59:15 +01008444
Johannes Berg074ac8d2010-09-16 14:58:22 +02008445 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02008446 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
8447 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01008448
Johannes Berg4c476992010-10-04 21:36:35 +02008449 if (!rdev->ops->flush_pmksa)
8450 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01008451
Hila Gonene35e4d22012-06-27 17:19:42 +03008452 return rdev_flush_pmksa(rdev, dev);
Samuel Ortiz67fbb162009-11-24 23:59:15 +01008453}
8454
Arik Nemtsov109086c2011-09-28 14:12:50 +03008455static int nl80211_tdls_mgmt(struct sk_buff *skb, struct genl_info *info)
8456{
8457 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8458 struct net_device *dev = info->user_ptr[1];
8459 u8 action_code, dialog_token;
Sunil Dutt Undekaridf942e72014-02-20 16:22:09 +05308460 u32 peer_capability = 0;
Arik Nemtsov109086c2011-09-28 14:12:50 +03008461 u16 status_code;
8462 u8 *peer;
Arik Nemtsov31fa97c2014-06-11 17:18:21 +03008463 bool initiator;
Arik Nemtsov109086c2011-09-28 14:12:50 +03008464
8465 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) ||
8466 !rdev->ops->tdls_mgmt)
8467 return -EOPNOTSUPP;
8468
8469 if (!info->attrs[NL80211_ATTR_TDLS_ACTION] ||
8470 !info->attrs[NL80211_ATTR_STATUS_CODE] ||
8471 !info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN] ||
8472 !info->attrs[NL80211_ATTR_IE] ||
8473 !info->attrs[NL80211_ATTR_MAC])
8474 return -EINVAL;
8475
8476 peer = nla_data(info->attrs[NL80211_ATTR_MAC]);
8477 action_code = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_ACTION]);
8478 status_code = nla_get_u16(info->attrs[NL80211_ATTR_STATUS_CODE]);
8479 dialog_token = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN]);
Arik Nemtsov31fa97c2014-06-11 17:18:21 +03008480 initiator = nla_get_flag(info->attrs[NL80211_ATTR_TDLS_INITIATOR]);
Sunil Dutt Undekaridf942e72014-02-20 16:22:09 +05308481 if (info->attrs[NL80211_ATTR_TDLS_PEER_CAPABILITY])
8482 peer_capability =
8483 nla_get_u32(info->attrs[NL80211_ATTR_TDLS_PEER_CAPABILITY]);
Arik Nemtsov109086c2011-09-28 14:12:50 +03008484
Hila Gonene35e4d22012-06-27 17:19:42 +03008485 return rdev_tdls_mgmt(rdev, dev, peer, action_code,
Sunil Dutt Undekaridf942e72014-02-20 16:22:09 +05308486 dialog_token, status_code, peer_capability,
Arik Nemtsov31fa97c2014-06-11 17:18:21 +03008487 initiator,
Hila Gonene35e4d22012-06-27 17:19:42 +03008488 nla_data(info->attrs[NL80211_ATTR_IE]),
8489 nla_len(info->attrs[NL80211_ATTR_IE]));
Arik Nemtsov109086c2011-09-28 14:12:50 +03008490}
8491
8492static int nl80211_tdls_oper(struct sk_buff *skb, struct genl_info *info)
8493{
8494 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8495 struct net_device *dev = info->user_ptr[1];
8496 enum nl80211_tdls_operation operation;
8497 u8 *peer;
8498
8499 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) ||
8500 !rdev->ops->tdls_oper)
8501 return -EOPNOTSUPP;
8502
8503 if (!info->attrs[NL80211_ATTR_TDLS_OPERATION] ||
8504 !info->attrs[NL80211_ATTR_MAC])
8505 return -EINVAL;
8506
8507 operation = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_OPERATION]);
8508 peer = nla_data(info->attrs[NL80211_ATTR_MAC]);
8509
Hila Gonene35e4d22012-06-27 17:19:42 +03008510 return rdev_tdls_oper(rdev, dev, peer, operation);
Arik Nemtsov109086c2011-09-28 14:12:50 +03008511}
8512
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008513static int nl80211_remain_on_channel(struct sk_buff *skb,
8514 struct genl_info *info)
8515{
Johannes Berg4c476992010-10-04 21:36:35 +02008516 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02008517 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg683b6d32012-11-08 21:25:48 +01008518 struct cfg80211_chan_def chandef;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008519 struct sk_buff *msg;
8520 void *hdr;
8521 u64 cookie;
Johannes Berg683b6d32012-11-08 21:25:48 +01008522 u32 duration;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008523 int err;
8524
8525 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] ||
8526 !info->attrs[NL80211_ATTR_DURATION])
8527 return -EINVAL;
8528
8529 duration = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]);
8530
Johannes Berg7c4ef712011-11-18 15:33:48 +01008531 if (!rdev->ops->remain_on_channel ||
8532 !(rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL))
Johannes Berg4c476992010-10-04 21:36:35 +02008533 return -EOPNOTSUPP;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008534
Johannes Bergebf348f2012-06-01 12:50:54 +02008535 /*
8536 * We should be on that channel for at least a minimum amount of
8537 * time (10ms) but no longer than the driver supports.
8538 */
8539 if (duration < NL80211_MIN_REMAIN_ON_CHANNEL_TIME ||
8540 duration > rdev->wiphy.max_remain_on_channel_duration)
8541 return -EINVAL;
8542
Johannes Berg683b6d32012-11-08 21:25:48 +01008543 err = nl80211_parse_chandef(rdev, info, &chandef);
8544 if (err)
8545 return err;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008546
8547 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02008548 if (!msg)
8549 return -ENOMEM;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008550
Eric W. Biederman15e47302012-09-07 20:12:54 +00008551 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008552 NL80211_CMD_REMAIN_ON_CHANNEL);
Dan Carpentercb35fba2013-08-14 14:50:01 +03008553 if (!hdr) {
8554 err = -ENOBUFS;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008555 goto free_msg;
8556 }
8557
Johannes Berg683b6d32012-11-08 21:25:48 +01008558 err = rdev_remain_on_channel(rdev, wdev, chandef.chan,
8559 duration, &cookie);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008560
8561 if (err)
8562 goto free_msg;
8563
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02008564 if (nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie,
8565 NL80211_ATTR_PAD))
David S. Miller9360ffd2012-03-29 04:41:26 -04008566 goto nla_put_failure;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008567
8568 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02008569
8570 return genlmsg_reply(msg, info);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008571
8572 nla_put_failure:
8573 err = -ENOBUFS;
8574 free_msg:
8575 nlmsg_free(msg);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008576 return err;
8577}
8578
8579static int nl80211_cancel_remain_on_channel(struct sk_buff *skb,
8580 struct genl_info *info)
8581{
Johannes Berg4c476992010-10-04 21:36:35 +02008582 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02008583 struct wireless_dev *wdev = info->user_ptr[1];
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008584 u64 cookie;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008585
8586 if (!info->attrs[NL80211_ATTR_COOKIE])
8587 return -EINVAL;
8588
Johannes Berg4c476992010-10-04 21:36:35 +02008589 if (!rdev->ops->cancel_remain_on_channel)
8590 return -EOPNOTSUPP;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008591
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008592 cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]);
8593
Hila Gonene35e4d22012-06-27 17:19:42 +03008594 return rdev_cancel_remain_on_channel(rdev, wdev, cookie);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008595}
8596
Jouni Malinen13ae75b2009-12-29 12:59:45 +02008597static u32 rateset_to_mask(struct ieee80211_supported_band *sband,
8598 u8 *rates, u8 rates_len)
8599{
8600 u8 i;
8601 u32 mask = 0;
8602
8603 for (i = 0; i < rates_len; i++) {
8604 int rate = (rates[i] & 0x7f) * 5;
8605 int ridx;
Kirtika Ruchandani7a087e72016-05-29 19:51:23 -07008606
Jouni Malinen13ae75b2009-12-29 12:59:45 +02008607 for (ridx = 0; ridx < sband->n_bitrates; ridx++) {
8608 struct ieee80211_rate *srate =
8609 &sband->bitrates[ridx];
8610 if (rate == srate->bitrate) {
8611 mask |= 1 << ridx;
8612 break;
8613 }
8614 }
8615 if (ridx == sband->n_bitrates)
8616 return 0; /* rate not found */
8617 }
8618
8619 return mask;
8620}
8621
Simon Wunderlich24db78c2012-01-28 17:25:32 +01008622static bool ht_rateset_to_mask(struct ieee80211_supported_band *sband,
8623 u8 *rates, u8 rates_len,
8624 u8 mcs[IEEE80211_HT_MCS_MASK_LEN])
8625{
8626 u8 i;
8627
8628 memset(mcs, 0, IEEE80211_HT_MCS_MASK_LEN);
8629
8630 for (i = 0; i < rates_len; i++) {
8631 int ridx, rbit;
8632
8633 ridx = rates[i] / 8;
8634 rbit = BIT(rates[i] % 8);
8635
8636 /* check validity */
Dan Carpenter910570b52012-02-01 10:42:11 +03008637 if ((ridx < 0) || (ridx >= IEEE80211_HT_MCS_MASK_LEN))
Simon Wunderlich24db78c2012-01-28 17:25:32 +01008638 return false;
8639
8640 /* check availability */
8641 if (sband->ht_cap.mcs.rx_mask[ridx] & rbit)
8642 mcs[ridx] |= rbit;
8643 else
8644 return false;
8645 }
8646
8647 return true;
8648}
8649
Janusz Dziedzic204e35a2013-12-05 20:42:58 +01008650static u16 vht_mcs_map_to_mcs_mask(u8 vht_mcs_map)
8651{
8652 u16 mcs_mask = 0;
8653
8654 switch (vht_mcs_map) {
8655 case IEEE80211_VHT_MCS_NOT_SUPPORTED:
8656 break;
8657 case IEEE80211_VHT_MCS_SUPPORT_0_7:
8658 mcs_mask = 0x00FF;
8659 break;
8660 case IEEE80211_VHT_MCS_SUPPORT_0_8:
8661 mcs_mask = 0x01FF;
8662 break;
8663 case IEEE80211_VHT_MCS_SUPPORT_0_9:
8664 mcs_mask = 0x03FF;
8665 break;
8666 default:
8667 break;
8668 }
8669
8670 return mcs_mask;
8671}
8672
8673static void vht_build_mcs_mask(u16 vht_mcs_map,
8674 u16 vht_mcs_mask[NL80211_VHT_NSS_MAX])
8675{
8676 u8 nss;
8677
8678 for (nss = 0; nss < NL80211_VHT_NSS_MAX; nss++) {
8679 vht_mcs_mask[nss] = vht_mcs_map_to_mcs_mask(vht_mcs_map & 0x03);
8680 vht_mcs_map >>= 2;
8681 }
8682}
8683
8684static bool vht_set_mcs_mask(struct ieee80211_supported_band *sband,
8685 struct nl80211_txrate_vht *txrate,
8686 u16 mcs[NL80211_VHT_NSS_MAX])
8687{
8688 u16 tx_mcs_map = le16_to_cpu(sband->vht_cap.vht_mcs.tx_mcs_map);
8689 u16 tx_mcs_mask[NL80211_VHT_NSS_MAX] = {};
8690 u8 i;
8691
8692 if (!sband->vht_cap.vht_supported)
8693 return false;
8694
8695 memset(mcs, 0, sizeof(u16) * NL80211_VHT_NSS_MAX);
8696
8697 /* Build vht_mcs_mask from VHT capabilities */
8698 vht_build_mcs_mask(tx_mcs_map, tx_mcs_mask);
8699
8700 for (i = 0; i < NL80211_VHT_NSS_MAX; i++) {
8701 if ((tx_mcs_mask[i] & txrate->mcs[i]) == txrate->mcs[i])
8702 mcs[i] = txrate->mcs[i];
8703 else
8704 return false;
8705 }
8706
8707 return true;
8708}
8709
Alexey Dobriyanb54452b2010-02-18 08:14:31 +00008710static const struct nla_policy nl80211_txattr_policy[NL80211_TXRATE_MAX + 1] = {
Jouni Malinen13ae75b2009-12-29 12:59:45 +02008711 [NL80211_TXRATE_LEGACY] = { .type = NLA_BINARY,
8712 .len = NL80211_MAX_SUPP_RATES },
Janusz Dziedzicd1e33e62013-12-05 10:02:15 +01008713 [NL80211_TXRATE_HT] = { .type = NLA_BINARY,
8714 .len = NL80211_MAX_SUPP_HT_RATES },
Janusz Dziedzic204e35a2013-12-05 20:42:58 +01008715 [NL80211_TXRATE_VHT] = { .len = sizeof(struct nl80211_txrate_vht)},
Janusz Dziedzic0b9323f2014-01-08 08:46:02 +01008716 [NL80211_TXRATE_GI] = { .type = NLA_U8 },
Jouni Malinen13ae75b2009-12-29 12:59:45 +02008717};
8718
8719static int nl80211_set_tx_bitrate_mask(struct sk_buff *skb,
8720 struct genl_info *info)
8721{
8722 struct nlattr *tb[NL80211_TXRATE_MAX + 1];
Johannes Berg4c476992010-10-04 21:36:35 +02008723 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Jouni Malinen13ae75b2009-12-29 12:59:45 +02008724 struct cfg80211_bitrate_mask mask;
Johannes Berg4c476992010-10-04 21:36:35 +02008725 int rem, i;
8726 struct net_device *dev = info->user_ptr[1];
Jouni Malinen13ae75b2009-12-29 12:59:45 +02008727 struct nlattr *tx_rates;
8728 struct ieee80211_supported_band *sband;
Janusz Dziedzic204e35a2013-12-05 20:42:58 +01008729 u16 vht_tx_mcs_map;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02008730
Johannes Berg4c476992010-10-04 21:36:35 +02008731 if (!rdev->ops->set_bitrate_mask)
8732 return -EOPNOTSUPP;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02008733
8734 memset(&mask, 0, sizeof(mask));
8735 /* Default to all rates enabled */
Johannes Berg57fbcce2016-04-12 15:56:15 +02008736 for (i = 0; i < NUM_NL80211_BANDS; i++) {
Jouni Malinen13ae75b2009-12-29 12:59:45 +02008737 sband = rdev->wiphy.bands[i];
Janusz Dziedzic78693032013-12-03 09:50:44 +01008738
8739 if (!sband)
8740 continue;
8741
8742 mask.control[i].legacy = (1 << sband->n_bitrates) - 1;
Janusz Dziedzicd1e33e62013-12-05 10:02:15 +01008743 memcpy(mask.control[i].ht_mcs,
Janusz Dziedzic78693032013-12-03 09:50:44 +01008744 sband->ht_cap.mcs.rx_mask,
Janusz Dziedzicd1e33e62013-12-05 10:02:15 +01008745 sizeof(mask.control[i].ht_mcs));
Janusz Dziedzic204e35a2013-12-05 20:42:58 +01008746
8747 if (!sband->vht_cap.vht_supported)
8748 continue;
8749
8750 vht_tx_mcs_map = le16_to_cpu(sband->vht_cap.vht_mcs.tx_mcs_map);
8751 vht_build_mcs_mask(vht_tx_mcs_map, mask.control[i].vht_mcs);
Jouni Malinen13ae75b2009-12-29 12:59:45 +02008752 }
8753
Janusz Dziedzicb9243ab2013-12-05 10:02:14 +01008754 /* if no rates are given set it back to the defaults */
8755 if (!info->attrs[NL80211_ATTR_TX_RATES])
8756 goto out;
8757
Jouni Malinen13ae75b2009-12-29 12:59:45 +02008758 /*
8759 * The nested attribute uses enum nl80211_band as the index. This maps
Johannes Berg57fbcce2016-04-12 15:56:15 +02008760 * directly to the enum nl80211_band values used in cfg80211.
Jouni Malinen13ae75b2009-12-29 12:59:45 +02008761 */
Simon Wunderlich24db78c2012-01-28 17:25:32 +01008762 BUILD_BUG_ON(NL80211_MAX_SUPP_HT_RATES > IEEE80211_HT_MCS_MASK_LEN * 8);
Johannes Bergae811e22014-01-24 10:17:47 +01008763 nla_for_each_nested(tx_rates, info->attrs[NL80211_ATTR_TX_RATES], rem) {
Johannes Berg57fbcce2016-04-12 15:56:15 +02008764 enum nl80211_band band = nla_type(tx_rates);
Johannes Bergae811e22014-01-24 10:17:47 +01008765 int err;
8766
Johannes Berg57fbcce2016-04-12 15:56:15 +02008767 if (band < 0 || band >= NUM_NL80211_BANDS)
Johannes Berg4c476992010-10-04 21:36:35 +02008768 return -EINVAL;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02008769 sband = rdev->wiphy.bands[band];
Johannes Berg4c476992010-10-04 21:36:35 +02008770 if (sband == NULL)
8771 return -EINVAL;
Johannes Bergae811e22014-01-24 10:17:47 +01008772 err = nla_parse(tb, NL80211_TXRATE_MAX, nla_data(tx_rates),
8773 nla_len(tx_rates), nl80211_txattr_policy);
8774 if (err)
8775 return err;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02008776 if (tb[NL80211_TXRATE_LEGACY]) {
8777 mask.control[band].legacy = rateset_to_mask(
8778 sband,
8779 nla_data(tb[NL80211_TXRATE_LEGACY]),
8780 nla_len(tb[NL80211_TXRATE_LEGACY]));
Bala Shanmugam218d2e22012-04-20 19:12:58 +05308781 if ((mask.control[band].legacy == 0) &&
8782 nla_len(tb[NL80211_TXRATE_LEGACY]))
8783 return -EINVAL;
Simon Wunderlich24db78c2012-01-28 17:25:32 +01008784 }
Janusz Dziedzicd1e33e62013-12-05 10:02:15 +01008785 if (tb[NL80211_TXRATE_HT]) {
Simon Wunderlich24db78c2012-01-28 17:25:32 +01008786 if (!ht_rateset_to_mask(
8787 sband,
Janusz Dziedzicd1e33e62013-12-05 10:02:15 +01008788 nla_data(tb[NL80211_TXRATE_HT]),
8789 nla_len(tb[NL80211_TXRATE_HT]),
8790 mask.control[band].ht_mcs))
Simon Wunderlich24db78c2012-01-28 17:25:32 +01008791 return -EINVAL;
8792 }
Janusz Dziedzic204e35a2013-12-05 20:42:58 +01008793 if (tb[NL80211_TXRATE_VHT]) {
8794 if (!vht_set_mcs_mask(
8795 sband,
8796 nla_data(tb[NL80211_TXRATE_VHT]),
8797 mask.control[band].vht_mcs))
8798 return -EINVAL;
8799 }
Janusz Dziedzic0b9323f2014-01-08 08:46:02 +01008800 if (tb[NL80211_TXRATE_GI]) {
8801 mask.control[band].gi =
8802 nla_get_u8(tb[NL80211_TXRATE_GI]);
8803 if (mask.control[band].gi > NL80211_TXRATE_FORCE_LGI)
8804 return -EINVAL;
8805 }
Simon Wunderlich24db78c2012-01-28 17:25:32 +01008806
8807 if (mask.control[band].legacy == 0) {
Janusz Dziedzic204e35a2013-12-05 20:42:58 +01008808 /* don't allow empty legacy rates if HT or VHT
8809 * are not even supported.
8810 */
8811 if (!(rdev->wiphy.bands[band]->ht_cap.ht_supported ||
8812 rdev->wiphy.bands[band]->vht_cap.vht_supported))
Simon Wunderlich24db78c2012-01-28 17:25:32 +01008813 return -EINVAL;
8814
8815 for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++)
Janusz Dziedzicd1e33e62013-12-05 10:02:15 +01008816 if (mask.control[band].ht_mcs[i])
Janusz Dziedzic204e35a2013-12-05 20:42:58 +01008817 goto out;
8818
8819 for (i = 0; i < NL80211_VHT_NSS_MAX; i++)
8820 if (mask.control[band].vht_mcs[i])
8821 goto out;
Simon Wunderlich24db78c2012-01-28 17:25:32 +01008822
8823 /* legacy and mcs rates may not be both empty */
Janusz Dziedzic204e35a2013-12-05 20:42:58 +01008824 return -EINVAL;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02008825 }
8826 }
8827
Janusz Dziedzicb9243ab2013-12-05 10:02:14 +01008828out:
Hila Gonene35e4d22012-06-27 17:19:42 +03008829 return rdev_set_bitrate_mask(rdev, dev, NULL, &mask);
Jouni Malinen13ae75b2009-12-29 12:59:45 +02008830}
8831
Johannes Berg2e161f72010-08-12 15:38:38 +02008832static int nl80211_register_mgmt(struct sk_buff *skb, struct genl_info *info)
Jouni Malinen026331c2010-02-15 12:53:10 +02008833{
Johannes Berg4c476992010-10-04 21:36:35 +02008834 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02008835 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg2e161f72010-08-12 15:38:38 +02008836 u16 frame_type = IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_ACTION;
Jouni Malinen026331c2010-02-15 12:53:10 +02008837
8838 if (!info->attrs[NL80211_ATTR_FRAME_MATCH])
8839 return -EINVAL;
8840
Johannes Berg2e161f72010-08-12 15:38:38 +02008841 if (info->attrs[NL80211_ATTR_FRAME_TYPE])
8842 frame_type = nla_get_u16(info->attrs[NL80211_ATTR_FRAME_TYPE]);
Jouni Malinen026331c2010-02-15 12:53:10 +02008843
Johannes Berg71bbc992012-06-15 15:30:18 +02008844 switch (wdev->iftype) {
8845 case NL80211_IFTYPE_STATION:
8846 case NL80211_IFTYPE_ADHOC:
8847 case NL80211_IFTYPE_P2P_CLIENT:
8848 case NL80211_IFTYPE_AP:
8849 case NL80211_IFTYPE_AP_VLAN:
8850 case NL80211_IFTYPE_MESH_POINT:
8851 case NL80211_IFTYPE_P2P_GO:
Johannes Berg98104fde2012-06-16 00:19:54 +02008852 case NL80211_IFTYPE_P2P_DEVICE:
Johannes Berg71bbc992012-06-15 15:30:18 +02008853 break;
8854 default:
Johannes Berg4c476992010-10-04 21:36:35 +02008855 return -EOPNOTSUPP;
Johannes Berg71bbc992012-06-15 15:30:18 +02008856 }
Jouni Malinen026331c2010-02-15 12:53:10 +02008857
8858 /* not much point in registering if we can't reply */
Johannes Berg4c476992010-10-04 21:36:35 +02008859 if (!rdev->ops->mgmt_tx)
8860 return -EOPNOTSUPP;
Jouni Malinen026331c2010-02-15 12:53:10 +02008861
Eric W. Biederman15e47302012-09-07 20:12:54 +00008862 return cfg80211_mlme_register_mgmt(wdev, info->snd_portid, frame_type,
Jouni Malinen026331c2010-02-15 12:53:10 +02008863 nla_data(info->attrs[NL80211_ATTR_FRAME_MATCH]),
8864 nla_len(info->attrs[NL80211_ATTR_FRAME_MATCH]));
Jouni Malinen026331c2010-02-15 12:53:10 +02008865}
8866
Johannes Berg2e161f72010-08-12 15:38:38 +02008867static int nl80211_tx_mgmt(struct sk_buff *skb, struct genl_info *info)
Jouni Malinen026331c2010-02-15 12:53:10 +02008868{
Johannes Berg4c476992010-10-04 21:36:35 +02008869 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02008870 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg683b6d32012-11-08 21:25:48 +01008871 struct cfg80211_chan_def chandef;
Jouni Malinen026331c2010-02-15 12:53:10 +02008872 int err;
Johannes Bergd64d3732011-11-10 09:44:46 +01008873 void *hdr = NULL;
Jouni Malinen026331c2010-02-15 12:53:10 +02008874 u64 cookie;
Johannes Berge247bd902011-11-04 11:18:21 +01008875 struct sk_buff *msg = NULL;
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02008876 struct cfg80211_mgmt_tx_params params = {
8877 .dont_wait_for_ack =
8878 info->attrs[NL80211_ATTR_DONT_WAIT_FOR_ACK],
8879 };
Jouni Malinen026331c2010-02-15 12:53:10 +02008880
Johannes Berg683b6d32012-11-08 21:25:48 +01008881 if (!info->attrs[NL80211_ATTR_FRAME])
Jouni Malinen026331c2010-02-15 12:53:10 +02008882 return -EINVAL;
8883
Johannes Berg4c476992010-10-04 21:36:35 +02008884 if (!rdev->ops->mgmt_tx)
8885 return -EOPNOTSUPP;
Jouni Malinen026331c2010-02-15 12:53:10 +02008886
Johannes Berg71bbc992012-06-15 15:30:18 +02008887 switch (wdev->iftype) {
Antonio Quartulliea141b752013-06-11 14:20:03 +02008888 case NL80211_IFTYPE_P2P_DEVICE:
8889 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ])
8890 return -EINVAL;
Johannes Berg71bbc992012-06-15 15:30:18 +02008891 case NL80211_IFTYPE_STATION:
8892 case NL80211_IFTYPE_ADHOC:
8893 case NL80211_IFTYPE_P2P_CLIENT:
8894 case NL80211_IFTYPE_AP:
8895 case NL80211_IFTYPE_AP_VLAN:
8896 case NL80211_IFTYPE_MESH_POINT:
8897 case NL80211_IFTYPE_P2P_GO:
8898 break;
8899 default:
Johannes Berg4c476992010-10-04 21:36:35 +02008900 return -EOPNOTSUPP;
Johannes Berg71bbc992012-06-15 15:30:18 +02008901 }
Jouni Malinen026331c2010-02-15 12:53:10 +02008902
Johannes Bergf7ca38d2010-11-25 10:02:29 +01008903 if (info->attrs[NL80211_ATTR_DURATION]) {
Johannes Berg7c4ef712011-11-18 15:33:48 +01008904 if (!(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX))
Johannes Bergf7ca38d2010-11-25 10:02:29 +01008905 return -EINVAL;
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02008906 params.wait = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]);
Johannes Bergebf348f2012-06-01 12:50:54 +02008907
8908 /*
8909 * We should wait on the channel for at least a minimum amount
8910 * of time (10ms) but no longer than the driver supports.
8911 */
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02008912 if (params.wait < NL80211_MIN_REMAIN_ON_CHANNEL_TIME ||
8913 params.wait > rdev->wiphy.max_remain_on_channel_duration)
Johannes Bergebf348f2012-06-01 12:50:54 +02008914 return -EINVAL;
Johannes Bergf7ca38d2010-11-25 10:02:29 +01008915 }
8916
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02008917 params.offchan = info->attrs[NL80211_ATTR_OFFCHANNEL_TX_OK];
Johannes Bergf7ca38d2010-11-25 10:02:29 +01008918
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02008919 if (params.offchan && !(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX))
Johannes Berg7c4ef712011-11-18 15:33:48 +01008920 return -EINVAL;
8921
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02008922 params.no_cck = nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]);
Rajkumar Manoharane9f935e2011-09-25 14:53:30 +05308923
Antonio Quartulliea141b752013-06-11 14:20:03 +02008924 /* get the channel if any has been specified, otherwise pass NULL to
8925 * the driver. The latter will use the current one
8926 */
8927 chandef.chan = NULL;
8928 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
8929 err = nl80211_parse_chandef(rdev, info, &chandef);
8930 if (err)
8931 return err;
8932 }
8933
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02008934 if (!chandef.chan && params.offchan)
Antonio Quartulliea141b752013-06-11 14:20:03 +02008935 return -EINVAL;
Jouni Malinen026331c2010-02-15 12:53:10 +02008936
Andrei Otcheretianski34d22ce2014-05-09 14:11:44 +03008937 params.buf = nla_data(info->attrs[NL80211_ATTR_FRAME]);
8938 params.len = nla_len(info->attrs[NL80211_ATTR_FRAME]);
8939
8940 if (info->attrs[NL80211_ATTR_CSA_C_OFFSETS_TX]) {
8941 int len = nla_len(info->attrs[NL80211_ATTR_CSA_C_OFFSETS_TX]);
8942 int i;
8943
8944 if (len % sizeof(u16))
8945 return -EINVAL;
8946
8947 params.n_csa_offsets = len / sizeof(u16);
8948 params.csa_offsets =
8949 nla_data(info->attrs[NL80211_ATTR_CSA_C_OFFSETS_TX]);
8950
8951 /* check that all the offsets fit the frame */
8952 for (i = 0; i < params.n_csa_offsets; i++) {
8953 if (params.csa_offsets[i] >= params.len)
8954 return -EINVAL;
8955 }
8956 }
8957
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02008958 if (!params.dont_wait_for_ack) {
Johannes Berge247bd902011-11-04 11:18:21 +01008959 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
8960 if (!msg)
8961 return -ENOMEM;
Jouni Malinen026331c2010-02-15 12:53:10 +02008962
Eric W. Biederman15e47302012-09-07 20:12:54 +00008963 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berge247bd902011-11-04 11:18:21 +01008964 NL80211_CMD_FRAME);
Dan Carpentercb35fba2013-08-14 14:50:01 +03008965 if (!hdr) {
8966 err = -ENOBUFS;
Johannes Berge247bd902011-11-04 11:18:21 +01008967 goto free_msg;
8968 }
Jouni Malinen026331c2010-02-15 12:53:10 +02008969 }
Johannes Berge247bd902011-11-04 11:18:21 +01008970
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02008971 params.chan = chandef.chan;
8972 err = cfg80211_mlme_mgmt_tx(rdev, wdev, &params, &cookie);
Jouni Malinen026331c2010-02-15 12:53:10 +02008973 if (err)
8974 goto free_msg;
8975
Johannes Berge247bd902011-11-04 11:18:21 +01008976 if (msg) {
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02008977 if (nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie,
8978 NL80211_ATTR_PAD))
David S. Miller9360ffd2012-03-29 04:41:26 -04008979 goto nla_put_failure;
Jouni Malinen026331c2010-02-15 12:53:10 +02008980
Johannes Berge247bd902011-11-04 11:18:21 +01008981 genlmsg_end(msg, hdr);
8982 return genlmsg_reply(msg, info);
8983 }
8984
8985 return 0;
Jouni Malinen026331c2010-02-15 12:53:10 +02008986
8987 nla_put_failure:
8988 err = -ENOBUFS;
8989 free_msg:
8990 nlmsg_free(msg);
Jouni Malinen026331c2010-02-15 12:53:10 +02008991 return err;
8992}
8993
Johannes Bergf7ca38d2010-11-25 10:02:29 +01008994static int nl80211_tx_mgmt_cancel_wait(struct sk_buff *skb, struct genl_info *info)
8995{
8996 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02008997 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Bergf7ca38d2010-11-25 10:02:29 +01008998 u64 cookie;
8999
9000 if (!info->attrs[NL80211_ATTR_COOKIE])
9001 return -EINVAL;
9002
9003 if (!rdev->ops->mgmt_tx_cancel_wait)
9004 return -EOPNOTSUPP;
9005
Johannes Berg71bbc992012-06-15 15:30:18 +02009006 switch (wdev->iftype) {
9007 case NL80211_IFTYPE_STATION:
9008 case NL80211_IFTYPE_ADHOC:
9009 case NL80211_IFTYPE_P2P_CLIENT:
9010 case NL80211_IFTYPE_AP:
9011 case NL80211_IFTYPE_AP_VLAN:
9012 case NL80211_IFTYPE_P2P_GO:
Johannes Berg98104fde2012-06-16 00:19:54 +02009013 case NL80211_IFTYPE_P2P_DEVICE:
Johannes Berg71bbc992012-06-15 15:30:18 +02009014 break;
9015 default:
Johannes Bergf7ca38d2010-11-25 10:02:29 +01009016 return -EOPNOTSUPP;
Johannes Berg71bbc992012-06-15 15:30:18 +02009017 }
Johannes Bergf7ca38d2010-11-25 10:02:29 +01009018
9019 cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]);
9020
Hila Gonene35e4d22012-06-27 17:19:42 +03009021 return rdev_mgmt_tx_cancel_wait(rdev, wdev, cookie);
Johannes Bergf7ca38d2010-11-25 10:02:29 +01009022}
9023
Kalle Valoffb9eb32010-02-17 17:58:10 +02009024static int nl80211_set_power_save(struct sk_buff *skb, struct genl_info *info)
9025{
Johannes Berg4c476992010-10-04 21:36:35 +02009026 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Kalle Valoffb9eb32010-02-17 17:58:10 +02009027 struct wireless_dev *wdev;
Johannes Berg4c476992010-10-04 21:36:35 +02009028 struct net_device *dev = info->user_ptr[1];
Kalle Valoffb9eb32010-02-17 17:58:10 +02009029 u8 ps_state;
9030 bool state;
9031 int err;
9032
Johannes Berg4c476992010-10-04 21:36:35 +02009033 if (!info->attrs[NL80211_ATTR_PS_STATE])
9034 return -EINVAL;
Kalle Valoffb9eb32010-02-17 17:58:10 +02009035
9036 ps_state = nla_get_u32(info->attrs[NL80211_ATTR_PS_STATE]);
9037
Johannes Berg4c476992010-10-04 21:36:35 +02009038 if (ps_state != NL80211_PS_DISABLED && ps_state != NL80211_PS_ENABLED)
9039 return -EINVAL;
Kalle Valoffb9eb32010-02-17 17:58:10 +02009040
9041 wdev = dev->ieee80211_ptr;
9042
Johannes Berg4c476992010-10-04 21:36:35 +02009043 if (!rdev->ops->set_power_mgmt)
9044 return -EOPNOTSUPP;
Kalle Valoffb9eb32010-02-17 17:58:10 +02009045
9046 state = (ps_state == NL80211_PS_ENABLED) ? true : false;
9047
9048 if (state == wdev->ps)
Johannes Berg4c476992010-10-04 21:36:35 +02009049 return 0;
Kalle Valoffb9eb32010-02-17 17:58:10 +02009050
Hila Gonene35e4d22012-06-27 17:19:42 +03009051 err = rdev_set_power_mgmt(rdev, dev, state, wdev->ps_timeout);
Johannes Berg4c476992010-10-04 21:36:35 +02009052 if (!err)
9053 wdev->ps = state;
Kalle Valoffb9eb32010-02-17 17:58:10 +02009054 return err;
9055}
9056
9057static int nl80211_get_power_save(struct sk_buff *skb, struct genl_info *info)
9058{
Johannes Berg4c476992010-10-04 21:36:35 +02009059 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Kalle Valoffb9eb32010-02-17 17:58:10 +02009060 enum nl80211_ps_state ps_state;
9061 struct wireless_dev *wdev;
Johannes Berg4c476992010-10-04 21:36:35 +02009062 struct net_device *dev = info->user_ptr[1];
Kalle Valoffb9eb32010-02-17 17:58:10 +02009063 struct sk_buff *msg;
9064 void *hdr;
9065 int err;
9066
Kalle Valoffb9eb32010-02-17 17:58:10 +02009067 wdev = dev->ieee80211_ptr;
9068
Johannes Berg4c476992010-10-04 21:36:35 +02009069 if (!rdev->ops->set_power_mgmt)
9070 return -EOPNOTSUPP;
Kalle Valoffb9eb32010-02-17 17:58:10 +02009071
9072 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02009073 if (!msg)
9074 return -ENOMEM;
Kalle Valoffb9eb32010-02-17 17:58:10 +02009075
Eric W. Biederman15e47302012-09-07 20:12:54 +00009076 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Kalle Valoffb9eb32010-02-17 17:58:10 +02009077 NL80211_CMD_GET_POWER_SAVE);
9078 if (!hdr) {
Johannes Berg4c476992010-10-04 21:36:35 +02009079 err = -ENOBUFS;
Kalle Valoffb9eb32010-02-17 17:58:10 +02009080 goto free_msg;
9081 }
9082
9083 if (wdev->ps)
9084 ps_state = NL80211_PS_ENABLED;
9085 else
9086 ps_state = NL80211_PS_DISABLED;
9087
David S. Miller9360ffd2012-03-29 04:41:26 -04009088 if (nla_put_u32(msg, NL80211_ATTR_PS_STATE, ps_state))
9089 goto nla_put_failure;
Kalle Valoffb9eb32010-02-17 17:58:10 +02009090
9091 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02009092 return genlmsg_reply(msg, info);
Kalle Valoffb9eb32010-02-17 17:58:10 +02009093
Johannes Berg4c476992010-10-04 21:36:35 +02009094 nla_put_failure:
Kalle Valoffb9eb32010-02-17 17:58:10 +02009095 err = -ENOBUFS;
Johannes Berg4c476992010-10-04 21:36:35 +02009096 free_msg:
Kalle Valoffb9eb32010-02-17 17:58:10 +02009097 nlmsg_free(msg);
Kalle Valoffb9eb32010-02-17 17:58:10 +02009098 return err;
9099}
9100
Johannes Berg94e860f2014-01-20 23:58:15 +01009101static const struct nla_policy
9102nl80211_attr_cqm_policy[NL80211_ATTR_CQM_MAX + 1] = {
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02009103 [NL80211_ATTR_CQM_RSSI_THOLD] = { .type = NLA_U32 },
9104 [NL80211_ATTR_CQM_RSSI_HYST] = { .type = NLA_U32 },
9105 [NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT] = { .type = NLA_U32 },
Thomas Pedersen84f10702012-07-12 16:17:33 -07009106 [NL80211_ATTR_CQM_TXE_RATE] = { .type = NLA_U32 },
9107 [NL80211_ATTR_CQM_TXE_PKTS] = { .type = NLA_U32 },
9108 [NL80211_ATTR_CQM_TXE_INTVL] = { .type = NLA_U32 },
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02009109};
9110
Thomas Pedersen84f10702012-07-12 16:17:33 -07009111static int nl80211_set_cqm_txe(struct genl_info *info,
Johannes Bergd9d8b012012-11-26 12:51:52 +01009112 u32 rate, u32 pkts, u32 intvl)
Thomas Pedersen84f10702012-07-12 16:17:33 -07009113{
9114 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Thomas Pedersen84f10702012-07-12 16:17:33 -07009115 struct net_device *dev = info->user_ptr[1];
Johannes Berg1da5fcc2013-08-06 14:10:48 +02009116 struct wireless_dev *wdev = dev->ieee80211_ptr;
Thomas Pedersen84f10702012-07-12 16:17:33 -07009117
Johannes Bergd9d8b012012-11-26 12:51:52 +01009118 if (rate > 100 || intvl > NL80211_CQM_TXE_MAX_INTVL)
Thomas Pedersen84f10702012-07-12 16:17:33 -07009119 return -EINVAL;
9120
Thomas Pedersen84f10702012-07-12 16:17:33 -07009121 if (!rdev->ops->set_cqm_txe_config)
9122 return -EOPNOTSUPP;
9123
9124 if (wdev->iftype != NL80211_IFTYPE_STATION &&
9125 wdev->iftype != NL80211_IFTYPE_P2P_CLIENT)
9126 return -EOPNOTSUPP;
9127
Hila Gonene35e4d22012-06-27 17:19:42 +03009128 return rdev_set_cqm_txe_config(rdev, dev, rate, pkts, intvl);
Thomas Pedersen84f10702012-07-12 16:17:33 -07009129}
9130
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02009131static int nl80211_set_cqm_rssi(struct genl_info *info,
9132 s32 threshold, u32 hysteresis)
9133{
Johannes Berg4c476992010-10-04 21:36:35 +02009134 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg4c476992010-10-04 21:36:35 +02009135 struct net_device *dev = info->user_ptr[1];
Johannes Berg1da5fcc2013-08-06 14:10:48 +02009136 struct wireless_dev *wdev = dev->ieee80211_ptr;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02009137
9138 if (threshold > 0)
9139 return -EINVAL;
9140
Johannes Berg1da5fcc2013-08-06 14:10:48 +02009141 /* disabling - hysteresis should also be zero then */
9142 if (threshold == 0)
9143 hysteresis = 0;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02009144
Johannes Berg4c476992010-10-04 21:36:35 +02009145 if (!rdev->ops->set_cqm_rssi_config)
9146 return -EOPNOTSUPP;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02009147
Johannes Berg074ac8d2010-09-16 14:58:22 +02009148 if (wdev->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02009149 wdev->iftype != NL80211_IFTYPE_P2P_CLIENT)
9150 return -EOPNOTSUPP;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02009151
Hila Gonene35e4d22012-06-27 17:19:42 +03009152 return rdev_set_cqm_rssi_config(rdev, dev, threshold, hysteresis);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02009153}
9154
9155static int nl80211_set_cqm(struct sk_buff *skb, struct genl_info *info)
9156{
9157 struct nlattr *attrs[NL80211_ATTR_CQM_MAX + 1];
9158 struct nlattr *cqm;
9159 int err;
9160
9161 cqm = info->attrs[NL80211_ATTR_CQM];
Johannes Berg1da5fcc2013-08-06 14:10:48 +02009162 if (!cqm)
9163 return -EINVAL;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02009164
9165 err = nla_parse_nested(attrs, NL80211_ATTR_CQM_MAX, cqm,
9166 nl80211_attr_cqm_policy);
9167 if (err)
Johannes Berg1da5fcc2013-08-06 14:10:48 +02009168 return err;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02009169
9170 if (attrs[NL80211_ATTR_CQM_RSSI_THOLD] &&
9171 attrs[NL80211_ATTR_CQM_RSSI_HYST]) {
Johannes Berg1da5fcc2013-08-06 14:10:48 +02009172 s32 threshold = nla_get_s32(attrs[NL80211_ATTR_CQM_RSSI_THOLD]);
9173 u32 hysteresis = nla_get_u32(attrs[NL80211_ATTR_CQM_RSSI_HYST]);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02009174
Johannes Berg1da5fcc2013-08-06 14:10:48 +02009175 return nl80211_set_cqm_rssi(info, threshold, hysteresis);
9176 }
9177
9178 if (attrs[NL80211_ATTR_CQM_TXE_RATE] &&
9179 attrs[NL80211_ATTR_CQM_TXE_PKTS] &&
9180 attrs[NL80211_ATTR_CQM_TXE_INTVL]) {
9181 u32 rate = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_RATE]);
9182 u32 pkts = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_PKTS]);
9183 u32 intvl = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_INTVL]);
9184
9185 return nl80211_set_cqm_txe(info, rate, pkts, intvl);
9186 }
9187
9188 return -EINVAL;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02009189}
9190
Rostislav Lisovy6e0bd6c2014-11-03 10:33:18 +01009191static int nl80211_join_ocb(struct sk_buff *skb, struct genl_info *info)
9192{
9193 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9194 struct net_device *dev = info->user_ptr[1];
9195 struct ocb_setup setup = {};
9196 int err;
9197
9198 err = nl80211_parse_chandef(rdev, info, &setup.chandef);
9199 if (err)
9200 return err;
9201
9202 return cfg80211_join_ocb(rdev, dev, &setup);
9203}
9204
9205static int nl80211_leave_ocb(struct sk_buff *skb, struct genl_info *info)
9206{
9207 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9208 struct net_device *dev = info->user_ptr[1];
9209
9210 return cfg80211_leave_ocb(rdev, dev);
9211}
9212
Johannes Berg29cbe682010-12-03 09:20:44 +01009213static int nl80211_join_mesh(struct sk_buff *skb, struct genl_info *info)
9214{
9215 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9216 struct net_device *dev = info->user_ptr[1];
9217 struct mesh_config cfg;
Javier Cardonac80d5452010-12-16 17:37:49 -08009218 struct mesh_setup setup;
Johannes Berg29cbe682010-12-03 09:20:44 +01009219 int err;
9220
9221 /* start with default */
9222 memcpy(&cfg, &default_mesh_config, sizeof(cfg));
Javier Cardonac80d5452010-12-16 17:37:49 -08009223 memcpy(&setup, &default_mesh_setup, sizeof(setup));
Johannes Berg29cbe682010-12-03 09:20:44 +01009224
Javier Cardona24bdd9f2010-12-16 17:37:48 -08009225 if (info->attrs[NL80211_ATTR_MESH_CONFIG]) {
Johannes Berg29cbe682010-12-03 09:20:44 +01009226 /* and parse parameters if given */
Javier Cardona24bdd9f2010-12-16 17:37:48 -08009227 err = nl80211_parse_mesh_config(info, &cfg, NULL);
Johannes Berg29cbe682010-12-03 09:20:44 +01009228 if (err)
9229 return err;
9230 }
9231
9232 if (!info->attrs[NL80211_ATTR_MESH_ID] ||
9233 !nla_len(info->attrs[NL80211_ATTR_MESH_ID]))
9234 return -EINVAL;
9235
Javier Cardonac80d5452010-12-16 17:37:49 -08009236 setup.mesh_id = nla_data(info->attrs[NL80211_ATTR_MESH_ID]);
9237 setup.mesh_id_len = nla_len(info->attrs[NL80211_ATTR_MESH_ID]);
9238
Chun-Yeow Yeoh4bb62342011-11-24 17:15:20 -08009239 if (info->attrs[NL80211_ATTR_MCAST_RATE] &&
9240 !nl80211_parse_mcast_rate(rdev, setup.mcast_rate,
9241 nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE])))
9242 return -EINVAL;
9243
Marco Porsch9bdbf042013-01-07 16:04:51 +01009244 if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) {
9245 setup.beacon_interval =
9246 nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]);
Purushottam Kushwaha12d20fc92016-08-11 15:14:02 +05309247
9248 err = cfg80211_validate_beacon_int(rdev, setup.beacon_interval);
9249 if (err)
9250 return err;
Marco Porsch9bdbf042013-01-07 16:04:51 +01009251 }
9252
9253 if (info->attrs[NL80211_ATTR_DTIM_PERIOD]) {
9254 setup.dtim_period =
9255 nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]);
9256 if (setup.dtim_period < 1 || setup.dtim_period > 100)
9257 return -EINVAL;
9258 }
9259
Javier Cardonac80d5452010-12-16 17:37:49 -08009260 if (info->attrs[NL80211_ATTR_MESH_SETUP]) {
9261 /* parse additional setup parameters if given */
9262 err = nl80211_parse_mesh_setup(info, &setup);
9263 if (err)
9264 return err;
9265 }
9266
Thomas Pedersend37bb182013-03-04 13:06:13 -08009267 if (setup.user_mpm)
9268 cfg.auto_open_plinks = false;
9269
Johannes Bergcc1d2802012-05-16 23:50:20 +02009270 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
Johannes Berg683b6d32012-11-08 21:25:48 +01009271 err = nl80211_parse_chandef(rdev, info, &setup.chandef);
9272 if (err)
9273 return err;
Johannes Bergcc1d2802012-05-16 23:50:20 +02009274 } else {
9275 /* cfg80211_join_mesh() will sort it out */
Johannes Berg683b6d32012-11-08 21:25:48 +01009276 setup.chandef.chan = NULL;
Johannes Bergcc1d2802012-05-16 23:50:20 +02009277 }
9278
Ashok Nagarajanffb3cf32013-06-03 10:33:36 -07009279 if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) {
9280 u8 *rates = nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
9281 int n_rates =
9282 nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
9283 struct ieee80211_supported_band *sband;
9284
9285 if (!setup.chandef.chan)
9286 return -EINVAL;
9287
9288 sband = rdev->wiphy.bands[setup.chandef.chan->band];
9289
9290 err = ieee80211_get_ratemask(sband, rates, n_rates,
9291 &setup.basic_rates);
9292 if (err)
9293 return err;
9294 }
9295
Javier Cardonac80d5452010-12-16 17:37:49 -08009296 return cfg80211_join_mesh(rdev, dev, &setup, &cfg);
Johannes Berg29cbe682010-12-03 09:20:44 +01009297}
9298
9299static int nl80211_leave_mesh(struct sk_buff *skb, struct genl_info *info)
9300{
9301 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9302 struct net_device *dev = info->user_ptr[1];
9303
9304 return cfg80211_leave_mesh(rdev, dev);
9305}
9306
Johannes Bergdfb89c52012-06-27 09:23:48 +02009307#ifdef CONFIG_PM
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08009308static int nl80211_send_wowlan_patterns(struct sk_buff *msg,
9309 struct cfg80211_registered_device *rdev)
9310{
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009311 struct cfg80211_wowlan *wowlan = rdev->wiphy.wowlan_config;
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08009312 struct nlattr *nl_pats, *nl_pat;
9313 int i, pat_len;
9314
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009315 if (!wowlan->n_patterns)
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08009316 return 0;
9317
9318 nl_pats = nla_nest_start(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN);
9319 if (!nl_pats)
9320 return -ENOBUFS;
9321
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009322 for (i = 0; i < wowlan->n_patterns; i++) {
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08009323 nl_pat = nla_nest_start(msg, i + 1);
9324 if (!nl_pat)
9325 return -ENOBUFS;
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009326 pat_len = wowlan->patterns[i].pattern_len;
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07009327 if (nla_put(msg, NL80211_PKTPAT_MASK, DIV_ROUND_UP(pat_len, 8),
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009328 wowlan->patterns[i].mask) ||
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07009329 nla_put(msg, NL80211_PKTPAT_PATTERN, pat_len,
9330 wowlan->patterns[i].pattern) ||
9331 nla_put_u32(msg, NL80211_PKTPAT_OFFSET,
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009332 wowlan->patterns[i].pkt_offset))
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08009333 return -ENOBUFS;
9334 nla_nest_end(msg, nl_pat);
9335 }
9336 nla_nest_end(msg, nl_pats);
9337
9338 return 0;
9339}
9340
Johannes Berg2a0e0472013-01-23 22:57:40 +01009341static int nl80211_send_wowlan_tcp(struct sk_buff *msg,
9342 struct cfg80211_wowlan_tcp *tcp)
9343{
9344 struct nlattr *nl_tcp;
9345
9346 if (!tcp)
9347 return 0;
9348
9349 nl_tcp = nla_nest_start(msg, NL80211_WOWLAN_TRIG_TCP_CONNECTION);
9350 if (!nl_tcp)
9351 return -ENOBUFS;
9352
Jiri Benc930345e2015-03-29 16:59:25 +02009353 if (nla_put_in_addr(msg, NL80211_WOWLAN_TCP_SRC_IPV4, tcp->src) ||
9354 nla_put_in_addr(msg, NL80211_WOWLAN_TCP_DST_IPV4, tcp->dst) ||
Johannes Berg2a0e0472013-01-23 22:57:40 +01009355 nla_put(msg, NL80211_WOWLAN_TCP_DST_MAC, ETH_ALEN, tcp->dst_mac) ||
9356 nla_put_u16(msg, NL80211_WOWLAN_TCP_SRC_PORT, tcp->src_port) ||
9357 nla_put_u16(msg, NL80211_WOWLAN_TCP_DST_PORT, tcp->dst_port) ||
9358 nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD,
9359 tcp->payload_len, tcp->payload) ||
9360 nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_INTERVAL,
9361 tcp->data_interval) ||
9362 nla_put(msg, NL80211_WOWLAN_TCP_WAKE_PAYLOAD,
9363 tcp->wake_len, tcp->wake_data) ||
9364 nla_put(msg, NL80211_WOWLAN_TCP_WAKE_MASK,
9365 DIV_ROUND_UP(tcp->wake_len, 8), tcp->wake_mask))
9366 return -ENOBUFS;
9367
9368 if (tcp->payload_seq.len &&
9369 nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ,
9370 sizeof(tcp->payload_seq), &tcp->payload_seq))
9371 return -ENOBUFS;
9372
9373 if (tcp->payload_tok.len &&
9374 nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN,
9375 sizeof(tcp->payload_tok) + tcp->tokens_size,
9376 &tcp->payload_tok))
9377 return -ENOBUFS;
9378
Johannes Berge248ad32013-05-16 10:24:28 +02009379 nla_nest_end(msg, nl_tcp);
9380
Johannes Berg2a0e0472013-01-23 22:57:40 +01009381 return 0;
9382}
9383
Luciano Coelho75453cc2015-01-09 14:06:37 +02009384static int nl80211_send_wowlan_nd(struct sk_buff *msg,
9385 struct cfg80211_sched_scan_request *req)
9386{
Avraham Stern3b06d272015-10-12 09:51:34 +03009387 struct nlattr *nd, *freqs, *matches, *match, *scan_plans, *scan_plan;
Luciano Coelho75453cc2015-01-09 14:06:37 +02009388 int i;
9389
9390 if (!req)
9391 return 0;
9392
9393 nd = nla_nest_start(msg, NL80211_WOWLAN_TRIG_NET_DETECT);
9394 if (!nd)
9395 return -ENOBUFS;
9396
Avraham Stern3b06d272015-10-12 09:51:34 +03009397 if (req->n_scan_plans == 1 &&
9398 nla_put_u32(msg, NL80211_ATTR_SCHED_SCAN_INTERVAL,
9399 req->scan_plans[0].interval * 1000))
Luciano Coelho75453cc2015-01-09 14:06:37 +02009400 return -ENOBUFS;
9401
Luciano Coelho21fea562015-03-17 16:36:01 +02009402 if (nla_put_u32(msg, NL80211_ATTR_SCHED_SCAN_DELAY, req->delay))
9403 return -ENOBUFS;
9404
Luciano Coelho75453cc2015-01-09 14:06:37 +02009405 freqs = nla_nest_start(msg, NL80211_ATTR_SCAN_FREQUENCIES);
9406 if (!freqs)
9407 return -ENOBUFS;
9408
9409 for (i = 0; i < req->n_channels; i++)
9410 nla_put_u32(msg, i, req->channels[i]->center_freq);
9411
9412 nla_nest_end(msg, freqs);
9413
9414 if (req->n_match_sets) {
9415 matches = nla_nest_start(msg, NL80211_ATTR_SCHED_SCAN_MATCH);
9416 for (i = 0; i < req->n_match_sets; i++) {
9417 match = nla_nest_start(msg, i);
9418 nla_put(msg, NL80211_SCHED_SCAN_MATCH_ATTR_SSID,
9419 req->match_sets[i].ssid.ssid_len,
9420 req->match_sets[i].ssid.ssid);
9421 nla_nest_end(msg, match);
9422 }
9423 nla_nest_end(msg, matches);
9424 }
9425
Avraham Stern3b06d272015-10-12 09:51:34 +03009426 scan_plans = nla_nest_start(msg, NL80211_ATTR_SCHED_SCAN_PLANS);
9427 if (!scan_plans)
9428 return -ENOBUFS;
9429
9430 for (i = 0; i < req->n_scan_plans; i++) {
9431 scan_plan = nla_nest_start(msg, i + 1);
9432 if (!scan_plan ||
9433 nla_put_u32(msg, NL80211_SCHED_SCAN_PLAN_INTERVAL,
9434 req->scan_plans[i].interval) ||
9435 (req->scan_plans[i].iterations &&
9436 nla_put_u32(msg, NL80211_SCHED_SCAN_PLAN_ITERATIONS,
9437 req->scan_plans[i].iterations)))
9438 return -ENOBUFS;
9439 nla_nest_end(msg, scan_plan);
9440 }
9441 nla_nest_end(msg, scan_plans);
9442
Luciano Coelho75453cc2015-01-09 14:06:37 +02009443 nla_nest_end(msg, nd);
9444
9445 return 0;
9446}
9447
Johannes Bergff1b6e62011-05-04 15:37:28 +02009448static int nl80211_get_wowlan(struct sk_buff *skb, struct genl_info *info)
9449{
9450 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9451 struct sk_buff *msg;
9452 void *hdr;
Johannes Berg2a0e0472013-01-23 22:57:40 +01009453 u32 size = NLMSG_DEFAULT_SIZE;
Johannes Bergff1b6e62011-05-04 15:37:28 +02009454
Johannes Berg964dc9e2013-06-03 17:25:34 +02009455 if (!rdev->wiphy.wowlan)
Johannes Bergff1b6e62011-05-04 15:37:28 +02009456 return -EOPNOTSUPP;
9457
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009458 if (rdev->wiphy.wowlan_config && rdev->wiphy.wowlan_config->tcp) {
Johannes Berg2a0e0472013-01-23 22:57:40 +01009459 /* adjust size to have room for all the data */
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009460 size += rdev->wiphy.wowlan_config->tcp->tokens_size +
9461 rdev->wiphy.wowlan_config->tcp->payload_len +
9462 rdev->wiphy.wowlan_config->tcp->wake_len +
9463 rdev->wiphy.wowlan_config->tcp->wake_len / 8;
Johannes Berg2a0e0472013-01-23 22:57:40 +01009464 }
9465
9466 msg = nlmsg_new(size, GFP_KERNEL);
Johannes Bergff1b6e62011-05-04 15:37:28 +02009467 if (!msg)
9468 return -ENOMEM;
9469
Eric W. Biederman15e47302012-09-07 20:12:54 +00009470 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Johannes Bergff1b6e62011-05-04 15:37:28 +02009471 NL80211_CMD_GET_WOWLAN);
9472 if (!hdr)
9473 goto nla_put_failure;
9474
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009475 if (rdev->wiphy.wowlan_config) {
Johannes Bergff1b6e62011-05-04 15:37:28 +02009476 struct nlattr *nl_wowlan;
9477
9478 nl_wowlan = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS);
9479 if (!nl_wowlan)
9480 goto nla_put_failure;
9481
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009482 if ((rdev->wiphy.wowlan_config->any &&
David S. Miller9360ffd2012-03-29 04:41:26 -04009483 nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009484 (rdev->wiphy.wowlan_config->disconnect &&
David S. Miller9360ffd2012-03-29 04:41:26 -04009485 nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009486 (rdev->wiphy.wowlan_config->magic_pkt &&
David S. Miller9360ffd2012-03-29 04:41:26 -04009487 nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009488 (rdev->wiphy.wowlan_config->gtk_rekey_failure &&
David S. Miller9360ffd2012-03-29 04:41:26 -04009489 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009490 (rdev->wiphy.wowlan_config->eap_identity_req &&
David S. Miller9360ffd2012-03-29 04:41:26 -04009491 nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009492 (rdev->wiphy.wowlan_config->four_way_handshake &&
David S. Miller9360ffd2012-03-29 04:41:26 -04009493 nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009494 (rdev->wiphy.wowlan_config->rfkill_release &&
David S. Miller9360ffd2012-03-29 04:41:26 -04009495 nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE)))
9496 goto nla_put_failure;
Johannes Berg2a0e0472013-01-23 22:57:40 +01009497
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08009498 if (nl80211_send_wowlan_patterns(msg, rdev))
9499 goto nla_put_failure;
Johannes Berg2a0e0472013-01-23 22:57:40 +01009500
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009501 if (nl80211_send_wowlan_tcp(msg,
9502 rdev->wiphy.wowlan_config->tcp))
Johannes Berg2a0e0472013-01-23 22:57:40 +01009503 goto nla_put_failure;
9504
Luciano Coelho75453cc2015-01-09 14:06:37 +02009505 if (nl80211_send_wowlan_nd(
9506 msg,
9507 rdev->wiphy.wowlan_config->nd_config))
9508 goto nla_put_failure;
9509
Johannes Bergff1b6e62011-05-04 15:37:28 +02009510 nla_nest_end(msg, nl_wowlan);
9511 }
9512
9513 genlmsg_end(msg, hdr);
9514 return genlmsg_reply(msg, info);
9515
9516nla_put_failure:
9517 nlmsg_free(msg);
9518 return -ENOBUFS;
9519}
9520
Johannes Berg2a0e0472013-01-23 22:57:40 +01009521static int nl80211_parse_wowlan_tcp(struct cfg80211_registered_device *rdev,
9522 struct nlattr *attr,
9523 struct cfg80211_wowlan *trig)
9524{
9525 struct nlattr *tb[NUM_NL80211_WOWLAN_TCP];
9526 struct cfg80211_wowlan_tcp *cfg;
9527 struct nl80211_wowlan_tcp_data_token *tok = NULL;
9528 struct nl80211_wowlan_tcp_data_seq *seq = NULL;
9529 u32 size;
9530 u32 data_size, wake_size, tokens_size = 0, wake_mask_size;
9531 int err, port;
9532
Johannes Berg964dc9e2013-06-03 17:25:34 +02009533 if (!rdev->wiphy.wowlan->tcp)
Johannes Berg2a0e0472013-01-23 22:57:40 +01009534 return -EINVAL;
9535
9536 err = nla_parse(tb, MAX_NL80211_WOWLAN_TCP,
9537 nla_data(attr), nla_len(attr),
9538 nl80211_wowlan_tcp_policy);
9539 if (err)
9540 return err;
9541
9542 if (!tb[NL80211_WOWLAN_TCP_SRC_IPV4] ||
9543 !tb[NL80211_WOWLAN_TCP_DST_IPV4] ||
9544 !tb[NL80211_WOWLAN_TCP_DST_MAC] ||
9545 !tb[NL80211_WOWLAN_TCP_DST_PORT] ||
9546 !tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD] ||
9547 !tb[NL80211_WOWLAN_TCP_DATA_INTERVAL] ||
9548 !tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD] ||
9549 !tb[NL80211_WOWLAN_TCP_WAKE_MASK])
9550 return -EINVAL;
9551
9552 data_size = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]);
Johannes Berg964dc9e2013-06-03 17:25:34 +02009553 if (data_size > rdev->wiphy.wowlan->tcp->data_payload_max)
Johannes Berg2a0e0472013-01-23 22:57:40 +01009554 return -EINVAL;
9555
9556 if (nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]) >
Johannes Berg964dc9e2013-06-03 17:25:34 +02009557 rdev->wiphy.wowlan->tcp->data_interval_max ||
Johannes Berg723d5682013-02-26 13:56:40 +01009558 nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]) == 0)
Johannes Berg2a0e0472013-01-23 22:57:40 +01009559 return -EINVAL;
9560
9561 wake_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]);
Johannes Berg964dc9e2013-06-03 17:25:34 +02009562 if (wake_size > rdev->wiphy.wowlan->tcp->wake_payload_max)
Johannes Berg2a0e0472013-01-23 22:57:40 +01009563 return -EINVAL;
9564
9565 wake_mask_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_MASK]);
9566 if (wake_mask_size != DIV_ROUND_UP(wake_size, 8))
9567 return -EINVAL;
9568
9569 if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]) {
9570 u32 tokln = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]);
9571
9572 tok = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]);
9573 tokens_size = tokln - sizeof(*tok);
9574
9575 if (!tok->len || tokens_size % tok->len)
9576 return -EINVAL;
Johannes Berg964dc9e2013-06-03 17:25:34 +02009577 if (!rdev->wiphy.wowlan->tcp->tok)
Johannes Berg2a0e0472013-01-23 22:57:40 +01009578 return -EINVAL;
Johannes Berg964dc9e2013-06-03 17:25:34 +02009579 if (tok->len > rdev->wiphy.wowlan->tcp->tok->max_len)
Johannes Berg2a0e0472013-01-23 22:57:40 +01009580 return -EINVAL;
Johannes Berg964dc9e2013-06-03 17:25:34 +02009581 if (tok->len < rdev->wiphy.wowlan->tcp->tok->min_len)
Johannes Berg2a0e0472013-01-23 22:57:40 +01009582 return -EINVAL;
Johannes Berg964dc9e2013-06-03 17:25:34 +02009583 if (tokens_size > rdev->wiphy.wowlan->tcp->tok->bufsize)
Johannes Berg2a0e0472013-01-23 22:57:40 +01009584 return -EINVAL;
9585 if (tok->offset + tok->len > data_size)
9586 return -EINVAL;
9587 }
9588
9589 if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]) {
9590 seq = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]);
Johannes Berg964dc9e2013-06-03 17:25:34 +02009591 if (!rdev->wiphy.wowlan->tcp->seq)
Johannes Berg2a0e0472013-01-23 22:57:40 +01009592 return -EINVAL;
9593 if (seq->len == 0 || seq->len > 4)
9594 return -EINVAL;
9595 if (seq->len + seq->offset > data_size)
9596 return -EINVAL;
9597 }
9598
9599 size = sizeof(*cfg);
9600 size += data_size;
9601 size += wake_size + wake_mask_size;
9602 size += tokens_size;
9603
9604 cfg = kzalloc(size, GFP_KERNEL);
9605 if (!cfg)
9606 return -ENOMEM;
Jiri Benc67b61f62015-03-29 16:59:26 +02009607 cfg->src = nla_get_in_addr(tb[NL80211_WOWLAN_TCP_SRC_IPV4]);
9608 cfg->dst = nla_get_in_addr(tb[NL80211_WOWLAN_TCP_DST_IPV4]);
Johannes Berg2a0e0472013-01-23 22:57:40 +01009609 memcpy(cfg->dst_mac, nla_data(tb[NL80211_WOWLAN_TCP_DST_MAC]),
9610 ETH_ALEN);
9611 if (tb[NL80211_WOWLAN_TCP_SRC_PORT])
9612 port = nla_get_u16(tb[NL80211_WOWLAN_TCP_SRC_PORT]);
9613 else
9614 port = 0;
9615#ifdef CONFIG_INET
9616 /* allocate a socket and port for it and use it */
9617 err = __sock_create(wiphy_net(&rdev->wiphy), PF_INET, SOCK_STREAM,
9618 IPPROTO_TCP, &cfg->sock, 1);
9619 if (err) {
9620 kfree(cfg);
9621 return err;
9622 }
9623 if (inet_csk_get_port(cfg->sock->sk, port)) {
9624 sock_release(cfg->sock);
9625 kfree(cfg);
9626 return -EADDRINUSE;
9627 }
9628 cfg->src_port = inet_sk(cfg->sock->sk)->inet_num;
9629#else
9630 if (!port) {
9631 kfree(cfg);
9632 return -EINVAL;
9633 }
9634 cfg->src_port = port;
9635#endif
9636
9637 cfg->dst_port = nla_get_u16(tb[NL80211_WOWLAN_TCP_DST_PORT]);
9638 cfg->payload_len = data_size;
9639 cfg->payload = (u8 *)cfg + sizeof(*cfg) + tokens_size;
9640 memcpy((void *)cfg->payload,
9641 nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]),
9642 data_size);
9643 if (seq)
9644 cfg->payload_seq = *seq;
9645 cfg->data_interval = nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]);
9646 cfg->wake_len = wake_size;
9647 cfg->wake_data = (u8 *)cfg + sizeof(*cfg) + tokens_size + data_size;
9648 memcpy((void *)cfg->wake_data,
9649 nla_data(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]),
9650 wake_size);
9651 cfg->wake_mask = (u8 *)cfg + sizeof(*cfg) + tokens_size +
9652 data_size + wake_size;
9653 memcpy((void *)cfg->wake_mask,
9654 nla_data(tb[NL80211_WOWLAN_TCP_WAKE_MASK]),
9655 wake_mask_size);
9656 if (tok) {
9657 cfg->tokens_size = tokens_size;
9658 memcpy(&cfg->payload_tok, tok, sizeof(*tok) + tokens_size);
9659 }
9660
9661 trig->tcp = cfg;
9662
9663 return 0;
9664}
9665
Luciano Coelho8cd4d452014-09-17 11:55:28 +03009666static int nl80211_parse_wowlan_nd(struct cfg80211_registered_device *rdev,
9667 const struct wiphy_wowlan_support *wowlan,
9668 struct nlattr *attr,
9669 struct cfg80211_wowlan *trig)
9670{
9671 struct nlattr **tb;
9672 int err;
9673
9674 tb = kzalloc(NUM_NL80211_ATTR * sizeof(*tb), GFP_KERNEL);
9675 if (!tb)
9676 return -ENOMEM;
9677
9678 if (!(wowlan->flags & WIPHY_WOWLAN_NET_DETECT)) {
9679 err = -EOPNOTSUPP;
9680 goto out;
9681 }
9682
9683 err = nla_parse(tb, NL80211_ATTR_MAX,
9684 nla_data(attr), nla_len(attr),
9685 nl80211_policy);
9686 if (err)
9687 goto out;
9688
Johannes Bergad2b26a2014-06-12 21:39:05 +02009689 trig->nd_config = nl80211_parse_sched_scan(&rdev->wiphy, NULL, tb);
Luciano Coelho8cd4d452014-09-17 11:55:28 +03009690 err = PTR_ERR_OR_ZERO(trig->nd_config);
9691 if (err)
9692 trig->nd_config = NULL;
9693
9694out:
9695 kfree(tb);
9696 return err;
9697}
9698
Johannes Bergff1b6e62011-05-04 15:37:28 +02009699static int nl80211_set_wowlan(struct sk_buff *skb, struct genl_info *info)
9700{
9701 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9702 struct nlattr *tb[NUM_NL80211_WOWLAN_TRIG];
Johannes Bergff1b6e62011-05-04 15:37:28 +02009703 struct cfg80211_wowlan new_triggers = {};
Johannes Bergae33bd82012-07-12 16:25:02 +02009704 struct cfg80211_wowlan *ntrig;
Johannes Berg964dc9e2013-06-03 17:25:34 +02009705 const struct wiphy_wowlan_support *wowlan = rdev->wiphy.wowlan;
Johannes Bergff1b6e62011-05-04 15:37:28 +02009706 int err, i;
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009707 bool prev_enabled = rdev->wiphy.wowlan_config;
Johannes Berg98fc4382015-03-01 09:10:13 +02009708 bool regular = false;
Johannes Bergff1b6e62011-05-04 15:37:28 +02009709
Johannes Berg964dc9e2013-06-03 17:25:34 +02009710 if (!wowlan)
Johannes Bergff1b6e62011-05-04 15:37:28 +02009711 return -EOPNOTSUPP;
9712
Johannes Bergae33bd82012-07-12 16:25:02 +02009713 if (!info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]) {
9714 cfg80211_rdev_free_wowlan(rdev);
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009715 rdev->wiphy.wowlan_config = NULL;
Johannes Bergae33bd82012-07-12 16:25:02 +02009716 goto set_wakeup;
9717 }
Johannes Bergff1b6e62011-05-04 15:37:28 +02009718
9719 err = nla_parse(tb, MAX_NL80211_WOWLAN_TRIG,
9720 nla_data(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]),
9721 nla_len(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]),
9722 nl80211_wowlan_policy);
9723 if (err)
9724 return err;
9725
9726 if (tb[NL80211_WOWLAN_TRIG_ANY]) {
9727 if (!(wowlan->flags & WIPHY_WOWLAN_ANY))
9728 return -EINVAL;
9729 new_triggers.any = true;
9730 }
9731
9732 if (tb[NL80211_WOWLAN_TRIG_DISCONNECT]) {
9733 if (!(wowlan->flags & WIPHY_WOWLAN_DISCONNECT))
9734 return -EINVAL;
9735 new_triggers.disconnect = true;
Johannes Berg98fc4382015-03-01 09:10:13 +02009736 regular = true;
Johannes Bergff1b6e62011-05-04 15:37:28 +02009737 }
9738
9739 if (tb[NL80211_WOWLAN_TRIG_MAGIC_PKT]) {
9740 if (!(wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT))
9741 return -EINVAL;
9742 new_triggers.magic_pkt = true;
Johannes Berg98fc4382015-03-01 09:10:13 +02009743 regular = true;
Johannes Bergff1b6e62011-05-04 15:37:28 +02009744 }
9745
Johannes Berg77dbbb12011-07-13 10:48:55 +02009746 if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED])
9747 return -EINVAL;
9748
9749 if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE]) {
9750 if (!(wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE))
9751 return -EINVAL;
9752 new_triggers.gtk_rekey_failure = true;
Johannes Berg98fc4382015-03-01 09:10:13 +02009753 regular = true;
Johannes Berg77dbbb12011-07-13 10:48:55 +02009754 }
9755
9756 if (tb[NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST]) {
9757 if (!(wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ))
9758 return -EINVAL;
9759 new_triggers.eap_identity_req = true;
Johannes Berg98fc4382015-03-01 09:10:13 +02009760 regular = true;
Johannes Berg77dbbb12011-07-13 10:48:55 +02009761 }
9762
9763 if (tb[NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE]) {
9764 if (!(wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE))
9765 return -EINVAL;
9766 new_triggers.four_way_handshake = true;
Johannes Berg98fc4382015-03-01 09:10:13 +02009767 regular = true;
Johannes Berg77dbbb12011-07-13 10:48:55 +02009768 }
9769
9770 if (tb[NL80211_WOWLAN_TRIG_RFKILL_RELEASE]) {
9771 if (!(wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE))
9772 return -EINVAL;
9773 new_triggers.rfkill_release = true;
Johannes Berg98fc4382015-03-01 09:10:13 +02009774 regular = true;
Johannes Berg77dbbb12011-07-13 10:48:55 +02009775 }
9776
Johannes Bergff1b6e62011-05-04 15:37:28 +02009777 if (tb[NL80211_WOWLAN_TRIG_PKT_PATTERN]) {
9778 struct nlattr *pat;
9779 int n_patterns = 0;
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08009780 int rem, pat_len, mask_len, pkt_offset;
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07009781 struct nlattr *pat_tb[NUM_NL80211_PKTPAT];
Johannes Bergff1b6e62011-05-04 15:37:28 +02009782
Johannes Berg98fc4382015-03-01 09:10:13 +02009783 regular = true;
9784
Johannes Bergff1b6e62011-05-04 15:37:28 +02009785 nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN],
9786 rem)
9787 n_patterns++;
9788 if (n_patterns > wowlan->n_patterns)
9789 return -EINVAL;
9790
9791 new_triggers.patterns = kcalloc(n_patterns,
9792 sizeof(new_triggers.patterns[0]),
9793 GFP_KERNEL);
9794 if (!new_triggers.patterns)
9795 return -ENOMEM;
9796
9797 new_triggers.n_patterns = n_patterns;
9798 i = 0;
9799
9800 nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN],
9801 rem) {
Johannes Berg922bd802014-05-19 17:59:50 +02009802 u8 *mask_pat;
9803
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07009804 nla_parse(pat_tb, MAX_NL80211_PKTPAT, nla_data(pat),
9805 nla_len(pat), NULL);
Johannes Bergff1b6e62011-05-04 15:37:28 +02009806 err = -EINVAL;
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07009807 if (!pat_tb[NL80211_PKTPAT_MASK] ||
9808 !pat_tb[NL80211_PKTPAT_PATTERN])
Johannes Bergff1b6e62011-05-04 15:37:28 +02009809 goto error;
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07009810 pat_len = nla_len(pat_tb[NL80211_PKTPAT_PATTERN]);
Johannes Bergff1b6e62011-05-04 15:37:28 +02009811 mask_len = DIV_ROUND_UP(pat_len, 8);
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07009812 if (nla_len(pat_tb[NL80211_PKTPAT_MASK]) != mask_len)
Johannes Bergff1b6e62011-05-04 15:37:28 +02009813 goto error;
9814 if (pat_len > wowlan->pattern_max_len ||
9815 pat_len < wowlan->pattern_min_len)
9816 goto error;
9817
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07009818 if (!pat_tb[NL80211_PKTPAT_OFFSET])
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08009819 pkt_offset = 0;
9820 else
9821 pkt_offset = nla_get_u32(
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07009822 pat_tb[NL80211_PKTPAT_OFFSET]);
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08009823 if (pkt_offset > wowlan->max_pkt_offset)
9824 goto error;
9825 new_triggers.patterns[i].pkt_offset = pkt_offset;
9826
Johannes Berg922bd802014-05-19 17:59:50 +02009827 mask_pat = kmalloc(mask_len + pat_len, GFP_KERNEL);
9828 if (!mask_pat) {
Johannes Bergff1b6e62011-05-04 15:37:28 +02009829 err = -ENOMEM;
9830 goto error;
9831 }
Johannes Berg922bd802014-05-19 17:59:50 +02009832 new_triggers.patterns[i].mask = mask_pat;
9833 memcpy(mask_pat, nla_data(pat_tb[NL80211_PKTPAT_MASK]),
Johannes Bergff1b6e62011-05-04 15:37:28 +02009834 mask_len);
Johannes Berg922bd802014-05-19 17:59:50 +02009835 mask_pat += mask_len;
9836 new_triggers.patterns[i].pattern = mask_pat;
Johannes Bergff1b6e62011-05-04 15:37:28 +02009837 new_triggers.patterns[i].pattern_len = pat_len;
Johannes Berg922bd802014-05-19 17:59:50 +02009838 memcpy(mask_pat,
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07009839 nla_data(pat_tb[NL80211_PKTPAT_PATTERN]),
Johannes Bergff1b6e62011-05-04 15:37:28 +02009840 pat_len);
9841 i++;
9842 }
9843 }
9844
Johannes Berg2a0e0472013-01-23 22:57:40 +01009845 if (tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION]) {
Johannes Berg98fc4382015-03-01 09:10:13 +02009846 regular = true;
Johannes Berg2a0e0472013-01-23 22:57:40 +01009847 err = nl80211_parse_wowlan_tcp(
9848 rdev, tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION],
9849 &new_triggers);
9850 if (err)
9851 goto error;
9852 }
9853
Luciano Coelho8cd4d452014-09-17 11:55:28 +03009854 if (tb[NL80211_WOWLAN_TRIG_NET_DETECT]) {
Johannes Berg98fc4382015-03-01 09:10:13 +02009855 regular = true;
Luciano Coelho8cd4d452014-09-17 11:55:28 +03009856 err = nl80211_parse_wowlan_nd(
9857 rdev, wowlan, tb[NL80211_WOWLAN_TRIG_NET_DETECT],
9858 &new_triggers);
9859 if (err)
9860 goto error;
9861 }
9862
Johannes Berg98fc4382015-03-01 09:10:13 +02009863 /* The 'any' trigger means the device continues operating more or less
9864 * as in its normal operation mode and wakes up the host on most of the
9865 * normal interrupts (like packet RX, ...)
9866 * It therefore makes little sense to combine with the more constrained
9867 * wakeup trigger modes.
9868 */
9869 if (new_triggers.any && regular) {
9870 err = -EINVAL;
9871 goto error;
9872 }
9873
Johannes Bergae33bd82012-07-12 16:25:02 +02009874 ntrig = kmemdup(&new_triggers, sizeof(new_triggers), GFP_KERNEL);
9875 if (!ntrig) {
9876 err = -ENOMEM;
9877 goto error;
Johannes Bergff1b6e62011-05-04 15:37:28 +02009878 }
Johannes Bergae33bd82012-07-12 16:25:02 +02009879 cfg80211_rdev_free_wowlan(rdev);
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009880 rdev->wiphy.wowlan_config = ntrig;
Johannes Bergff1b6e62011-05-04 15:37:28 +02009881
Johannes Bergae33bd82012-07-12 16:25:02 +02009882 set_wakeup:
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009883 if (rdev->ops->set_wakeup &&
9884 prev_enabled != !!rdev->wiphy.wowlan_config)
9885 rdev_set_wakeup(rdev, rdev->wiphy.wowlan_config);
Johannes Berg6d525632012-04-04 15:05:25 +02009886
Johannes Bergff1b6e62011-05-04 15:37:28 +02009887 return 0;
9888 error:
9889 for (i = 0; i < new_triggers.n_patterns; i++)
9890 kfree(new_triggers.patterns[i].mask);
9891 kfree(new_triggers.patterns);
Johannes Berg2a0e0472013-01-23 22:57:40 +01009892 if (new_triggers.tcp && new_triggers.tcp->sock)
9893 sock_release(new_triggers.tcp->sock);
9894 kfree(new_triggers.tcp);
Ola Olssone5dbe072015-12-12 23:17:17 +01009895 kfree(new_triggers.nd_config);
Johannes Bergff1b6e62011-05-04 15:37:28 +02009896 return err;
9897}
Johannes Bergdfb89c52012-06-27 09:23:48 +02009898#endif
Johannes Bergff1b6e62011-05-04 15:37:28 +02009899
Amitkumar Karwarbe29b992013-06-28 11:51:26 -07009900static int nl80211_send_coalesce_rules(struct sk_buff *msg,
9901 struct cfg80211_registered_device *rdev)
9902{
9903 struct nlattr *nl_pats, *nl_pat, *nl_rule, *nl_rules;
9904 int i, j, pat_len;
9905 struct cfg80211_coalesce_rules *rule;
9906
9907 if (!rdev->coalesce->n_rules)
9908 return 0;
9909
9910 nl_rules = nla_nest_start(msg, NL80211_ATTR_COALESCE_RULE);
9911 if (!nl_rules)
9912 return -ENOBUFS;
9913
9914 for (i = 0; i < rdev->coalesce->n_rules; i++) {
9915 nl_rule = nla_nest_start(msg, i + 1);
9916 if (!nl_rule)
9917 return -ENOBUFS;
9918
9919 rule = &rdev->coalesce->rules[i];
9920 if (nla_put_u32(msg, NL80211_ATTR_COALESCE_RULE_DELAY,
9921 rule->delay))
9922 return -ENOBUFS;
9923
9924 if (nla_put_u32(msg, NL80211_ATTR_COALESCE_RULE_CONDITION,
9925 rule->condition))
9926 return -ENOBUFS;
9927
9928 nl_pats = nla_nest_start(msg,
9929 NL80211_ATTR_COALESCE_RULE_PKT_PATTERN);
9930 if (!nl_pats)
9931 return -ENOBUFS;
9932
9933 for (j = 0; j < rule->n_patterns; j++) {
9934 nl_pat = nla_nest_start(msg, j + 1);
9935 if (!nl_pat)
9936 return -ENOBUFS;
9937 pat_len = rule->patterns[j].pattern_len;
9938 if (nla_put(msg, NL80211_PKTPAT_MASK,
9939 DIV_ROUND_UP(pat_len, 8),
9940 rule->patterns[j].mask) ||
9941 nla_put(msg, NL80211_PKTPAT_PATTERN, pat_len,
9942 rule->patterns[j].pattern) ||
9943 nla_put_u32(msg, NL80211_PKTPAT_OFFSET,
9944 rule->patterns[j].pkt_offset))
9945 return -ENOBUFS;
9946 nla_nest_end(msg, nl_pat);
9947 }
9948 nla_nest_end(msg, nl_pats);
9949 nla_nest_end(msg, nl_rule);
9950 }
9951 nla_nest_end(msg, nl_rules);
9952
9953 return 0;
9954}
9955
9956static int nl80211_get_coalesce(struct sk_buff *skb, struct genl_info *info)
9957{
9958 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9959 struct sk_buff *msg;
9960 void *hdr;
9961
9962 if (!rdev->wiphy.coalesce)
9963 return -EOPNOTSUPP;
9964
9965 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
9966 if (!msg)
9967 return -ENOMEM;
9968
9969 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
9970 NL80211_CMD_GET_COALESCE);
9971 if (!hdr)
9972 goto nla_put_failure;
9973
9974 if (rdev->coalesce && nl80211_send_coalesce_rules(msg, rdev))
9975 goto nla_put_failure;
9976
9977 genlmsg_end(msg, hdr);
9978 return genlmsg_reply(msg, info);
9979
9980nla_put_failure:
9981 nlmsg_free(msg);
9982 return -ENOBUFS;
9983}
9984
9985void cfg80211_rdev_free_coalesce(struct cfg80211_registered_device *rdev)
9986{
9987 struct cfg80211_coalesce *coalesce = rdev->coalesce;
9988 int i, j;
9989 struct cfg80211_coalesce_rules *rule;
9990
9991 if (!coalesce)
9992 return;
9993
9994 for (i = 0; i < coalesce->n_rules; i++) {
9995 rule = &coalesce->rules[i];
9996 for (j = 0; j < rule->n_patterns; j++)
9997 kfree(rule->patterns[j].mask);
9998 kfree(rule->patterns);
9999 }
10000 kfree(coalesce->rules);
10001 kfree(coalesce);
10002 rdev->coalesce = NULL;
10003}
10004
10005static int nl80211_parse_coalesce_rule(struct cfg80211_registered_device *rdev,
10006 struct nlattr *rule,
10007 struct cfg80211_coalesce_rules *new_rule)
10008{
10009 int err, i;
10010 const struct wiphy_coalesce_support *coalesce = rdev->wiphy.coalesce;
10011 struct nlattr *tb[NUM_NL80211_ATTR_COALESCE_RULE], *pat;
10012 int rem, pat_len, mask_len, pkt_offset, n_patterns = 0;
10013 struct nlattr *pat_tb[NUM_NL80211_PKTPAT];
10014
10015 err = nla_parse(tb, NL80211_ATTR_COALESCE_RULE_MAX, nla_data(rule),
10016 nla_len(rule), nl80211_coalesce_policy);
10017 if (err)
10018 return err;
10019
10020 if (tb[NL80211_ATTR_COALESCE_RULE_DELAY])
10021 new_rule->delay =
10022 nla_get_u32(tb[NL80211_ATTR_COALESCE_RULE_DELAY]);
10023 if (new_rule->delay > coalesce->max_delay)
10024 return -EINVAL;
10025
10026 if (tb[NL80211_ATTR_COALESCE_RULE_CONDITION])
10027 new_rule->condition =
10028 nla_get_u32(tb[NL80211_ATTR_COALESCE_RULE_CONDITION]);
10029 if (new_rule->condition != NL80211_COALESCE_CONDITION_MATCH &&
10030 new_rule->condition != NL80211_COALESCE_CONDITION_NO_MATCH)
10031 return -EINVAL;
10032
10033 if (!tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN])
10034 return -EINVAL;
10035
10036 nla_for_each_nested(pat, tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN],
10037 rem)
10038 n_patterns++;
10039 if (n_patterns > coalesce->n_patterns)
10040 return -EINVAL;
10041
10042 new_rule->patterns = kcalloc(n_patterns, sizeof(new_rule->patterns[0]),
10043 GFP_KERNEL);
10044 if (!new_rule->patterns)
10045 return -ENOMEM;
10046
10047 new_rule->n_patterns = n_patterns;
10048 i = 0;
10049
10050 nla_for_each_nested(pat, tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN],
10051 rem) {
Johannes Berg922bd802014-05-19 17:59:50 +020010052 u8 *mask_pat;
10053
Amitkumar Karwarbe29b992013-06-28 11:51:26 -070010054 nla_parse(pat_tb, MAX_NL80211_PKTPAT, nla_data(pat),
10055 nla_len(pat), NULL);
10056 if (!pat_tb[NL80211_PKTPAT_MASK] ||
10057 !pat_tb[NL80211_PKTPAT_PATTERN])
10058 return -EINVAL;
10059 pat_len = nla_len(pat_tb[NL80211_PKTPAT_PATTERN]);
10060 mask_len = DIV_ROUND_UP(pat_len, 8);
10061 if (nla_len(pat_tb[NL80211_PKTPAT_MASK]) != mask_len)
10062 return -EINVAL;
10063 if (pat_len > coalesce->pattern_max_len ||
10064 pat_len < coalesce->pattern_min_len)
10065 return -EINVAL;
10066
10067 if (!pat_tb[NL80211_PKTPAT_OFFSET])
10068 pkt_offset = 0;
10069 else
10070 pkt_offset = nla_get_u32(pat_tb[NL80211_PKTPAT_OFFSET]);
10071 if (pkt_offset > coalesce->max_pkt_offset)
10072 return -EINVAL;
10073 new_rule->patterns[i].pkt_offset = pkt_offset;
10074
Johannes Berg922bd802014-05-19 17:59:50 +020010075 mask_pat = kmalloc(mask_len + pat_len, GFP_KERNEL);
10076 if (!mask_pat)
Amitkumar Karwarbe29b992013-06-28 11:51:26 -070010077 return -ENOMEM;
Johannes Berg922bd802014-05-19 17:59:50 +020010078
10079 new_rule->patterns[i].mask = mask_pat;
10080 memcpy(mask_pat, nla_data(pat_tb[NL80211_PKTPAT_MASK]),
10081 mask_len);
10082
10083 mask_pat += mask_len;
10084 new_rule->patterns[i].pattern = mask_pat;
Amitkumar Karwarbe29b992013-06-28 11:51:26 -070010085 new_rule->patterns[i].pattern_len = pat_len;
Johannes Berg922bd802014-05-19 17:59:50 +020010086 memcpy(mask_pat, nla_data(pat_tb[NL80211_PKTPAT_PATTERN]),
10087 pat_len);
Amitkumar Karwarbe29b992013-06-28 11:51:26 -070010088 i++;
10089 }
10090
10091 return 0;
10092}
10093
10094static int nl80211_set_coalesce(struct sk_buff *skb, struct genl_info *info)
10095{
10096 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10097 const struct wiphy_coalesce_support *coalesce = rdev->wiphy.coalesce;
10098 struct cfg80211_coalesce new_coalesce = {};
10099 struct cfg80211_coalesce *n_coalesce;
10100 int err, rem_rule, n_rules = 0, i, j;
10101 struct nlattr *rule;
10102 struct cfg80211_coalesce_rules *tmp_rule;
10103
10104 if (!rdev->wiphy.coalesce || !rdev->ops->set_coalesce)
10105 return -EOPNOTSUPP;
10106
10107 if (!info->attrs[NL80211_ATTR_COALESCE_RULE]) {
10108 cfg80211_rdev_free_coalesce(rdev);
Ilan Peera1056b12015-10-22 22:27:46 +030010109 rdev_set_coalesce(rdev, NULL);
Amitkumar Karwarbe29b992013-06-28 11:51:26 -070010110 return 0;
10111 }
10112
10113 nla_for_each_nested(rule, info->attrs[NL80211_ATTR_COALESCE_RULE],
10114 rem_rule)
10115 n_rules++;
10116 if (n_rules > coalesce->n_rules)
10117 return -EINVAL;
10118
10119 new_coalesce.rules = kcalloc(n_rules, sizeof(new_coalesce.rules[0]),
10120 GFP_KERNEL);
10121 if (!new_coalesce.rules)
10122 return -ENOMEM;
10123
10124 new_coalesce.n_rules = n_rules;
10125 i = 0;
10126
10127 nla_for_each_nested(rule, info->attrs[NL80211_ATTR_COALESCE_RULE],
10128 rem_rule) {
10129 err = nl80211_parse_coalesce_rule(rdev, rule,
10130 &new_coalesce.rules[i]);
10131 if (err)
10132 goto error;
10133
10134 i++;
10135 }
10136
Ilan Peera1056b12015-10-22 22:27:46 +030010137 err = rdev_set_coalesce(rdev, &new_coalesce);
Amitkumar Karwarbe29b992013-06-28 11:51:26 -070010138 if (err)
10139 goto error;
10140
10141 n_coalesce = kmemdup(&new_coalesce, sizeof(new_coalesce), GFP_KERNEL);
10142 if (!n_coalesce) {
10143 err = -ENOMEM;
10144 goto error;
10145 }
10146 cfg80211_rdev_free_coalesce(rdev);
10147 rdev->coalesce = n_coalesce;
10148
10149 return 0;
10150error:
10151 for (i = 0; i < new_coalesce.n_rules; i++) {
10152 tmp_rule = &new_coalesce.rules[i];
10153 for (j = 0; j < tmp_rule->n_patterns; j++)
10154 kfree(tmp_rule->patterns[j].mask);
10155 kfree(tmp_rule->patterns);
10156 }
10157 kfree(new_coalesce.rules);
10158
10159 return err;
10160}
10161
Johannes Berge5497d72011-07-05 16:35:40 +020010162static int nl80211_set_rekey_data(struct sk_buff *skb, struct genl_info *info)
10163{
10164 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10165 struct net_device *dev = info->user_ptr[1];
10166 struct wireless_dev *wdev = dev->ieee80211_ptr;
10167 struct nlattr *tb[NUM_NL80211_REKEY_DATA];
10168 struct cfg80211_gtk_rekey_data rekey_data;
10169 int err;
10170
10171 if (!info->attrs[NL80211_ATTR_REKEY_DATA])
10172 return -EINVAL;
10173
10174 err = nla_parse(tb, MAX_NL80211_REKEY_DATA,
10175 nla_data(info->attrs[NL80211_ATTR_REKEY_DATA]),
10176 nla_len(info->attrs[NL80211_ATTR_REKEY_DATA]),
10177 nl80211_rekey_policy);
10178 if (err)
10179 return err;
10180
10181 if (nla_len(tb[NL80211_REKEY_DATA_REPLAY_CTR]) != NL80211_REPLAY_CTR_LEN)
10182 return -ERANGE;
10183 if (nla_len(tb[NL80211_REKEY_DATA_KEK]) != NL80211_KEK_LEN)
10184 return -ERANGE;
10185 if (nla_len(tb[NL80211_REKEY_DATA_KCK]) != NL80211_KCK_LEN)
10186 return -ERANGE;
10187
Johannes Berg78f686c2014-09-10 22:28:06 +030010188 rekey_data.kek = nla_data(tb[NL80211_REKEY_DATA_KEK]);
10189 rekey_data.kck = nla_data(tb[NL80211_REKEY_DATA_KCK]);
10190 rekey_data.replay_ctr = nla_data(tb[NL80211_REKEY_DATA_REPLAY_CTR]);
Johannes Berge5497d72011-07-05 16:35:40 +020010191
10192 wdev_lock(wdev);
10193 if (!wdev->current_bss) {
10194 err = -ENOTCONN;
10195 goto out;
10196 }
10197
10198 if (!rdev->ops->set_rekey_data) {
10199 err = -EOPNOTSUPP;
10200 goto out;
10201 }
10202
Hila Gonene35e4d22012-06-27 17:19:42 +030010203 err = rdev_set_rekey_data(rdev, dev, &rekey_data);
Johannes Berge5497d72011-07-05 16:35:40 +020010204 out:
10205 wdev_unlock(wdev);
10206 return err;
10207}
10208
Johannes Berg28946da2011-11-04 11:18:12 +010010209static int nl80211_register_unexpected_frame(struct sk_buff *skb,
10210 struct genl_info *info)
10211{
10212 struct net_device *dev = info->user_ptr[1];
10213 struct wireless_dev *wdev = dev->ieee80211_ptr;
10214
10215 if (wdev->iftype != NL80211_IFTYPE_AP &&
10216 wdev->iftype != NL80211_IFTYPE_P2P_GO)
10217 return -EINVAL;
10218
Eric W. Biederman15e47302012-09-07 20:12:54 +000010219 if (wdev->ap_unexpected_nlportid)
Johannes Berg28946da2011-11-04 11:18:12 +010010220 return -EBUSY;
10221
Eric W. Biederman15e47302012-09-07 20:12:54 +000010222 wdev->ap_unexpected_nlportid = info->snd_portid;
Johannes Berg28946da2011-11-04 11:18:12 +010010223 return 0;
10224}
10225
Johannes Berg7f6cf312011-11-04 11:18:15 +010010226static int nl80211_probe_client(struct sk_buff *skb,
10227 struct genl_info *info)
10228{
10229 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10230 struct net_device *dev = info->user_ptr[1];
10231 struct wireless_dev *wdev = dev->ieee80211_ptr;
10232 struct sk_buff *msg;
10233 void *hdr;
10234 const u8 *addr;
10235 u64 cookie;
10236 int err;
10237
10238 if (wdev->iftype != NL80211_IFTYPE_AP &&
10239 wdev->iftype != NL80211_IFTYPE_P2P_GO)
10240 return -EOPNOTSUPP;
10241
10242 if (!info->attrs[NL80211_ATTR_MAC])
10243 return -EINVAL;
10244
10245 if (!rdev->ops->probe_client)
10246 return -EOPNOTSUPP;
10247
10248 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
10249 if (!msg)
10250 return -ENOMEM;
10251
Eric W. Biederman15e47302012-09-07 20:12:54 +000010252 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berg7f6cf312011-11-04 11:18:15 +010010253 NL80211_CMD_PROBE_CLIENT);
Dan Carpentercb35fba2013-08-14 14:50:01 +030010254 if (!hdr) {
10255 err = -ENOBUFS;
Johannes Berg7f6cf312011-11-04 11:18:15 +010010256 goto free_msg;
10257 }
10258
10259 addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
10260
Hila Gonene35e4d22012-06-27 17:19:42 +030010261 err = rdev_probe_client(rdev, dev, addr, &cookie);
Johannes Berg7f6cf312011-11-04 11:18:15 +010010262 if (err)
10263 goto free_msg;
10264
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020010265 if (nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie,
10266 NL80211_ATTR_PAD))
David S. Miller9360ffd2012-03-29 04:41:26 -040010267 goto nla_put_failure;
Johannes Berg7f6cf312011-11-04 11:18:15 +010010268
10269 genlmsg_end(msg, hdr);
10270
10271 return genlmsg_reply(msg, info);
10272
10273 nla_put_failure:
10274 err = -ENOBUFS;
10275 free_msg:
10276 nlmsg_free(msg);
10277 return err;
10278}
10279
Johannes Berg5e7602302011-11-04 11:18:17 +010010280static int nl80211_register_beacons(struct sk_buff *skb, struct genl_info *info)
10281{
10282 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Ben Greear37c73b52012-10-26 14:49:25 -070010283 struct cfg80211_beacon_registration *reg, *nreg;
10284 int rv;
Johannes Berg5e7602302011-11-04 11:18:17 +010010285
10286 if (!(rdev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS))
10287 return -EOPNOTSUPP;
10288
Ben Greear37c73b52012-10-26 14:49:25 -070010289 nreg = kzalloc(sizeof(*nreg), GFP_KERNEL);
10290 if (!nreg)
10291 return -ENOMEM;
Johannes Berg5e7602302011-11-04 11:18:17 +010010292
Ben Greear37c73b52012-10-26 14:49:25 -070010293 /* First, check if already registered. */
10294 spin_lock_bh(&rdev->beacon_registrations_lock);
10295 list_for_each_entry(reg, &rdev->beacon_registrations, list) {
10296 if (reg->nlportid == info->snd_portid) {
10297 rv = -EALREADY;
10298 goto out_err;
10299 }
10300 }
10301 /* Add it to the list */
10302 nreg->nlportid = info->snd_portid;
10303 list_add(&nreg->list, &rdev->beacon_registrations);
10304
10305 spin_unlock_bh(&rdev->beacon_registrations_lock);
Johannes Berg5e7602302011-11-04 11:18:17 +010010306
10307 return 0;
Ben Greear37c73b52012-10-26 14:49:25 -070010308out_err:
10309 spin_unlock_bh(&rdev->beacon_registrations_lock);
10310 kfree(nreg);
10311 return rv;
Johannes Berg5e7602302011-11-04 11:18:17 +010010312}
10313
Johannes Berg98104fde2012-06-16 00:19:54 +020010314static int nl80211_start_p2p_device(struct sk_buff *skb, struct genl_info *info)
10315{
10316 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10317 struct wireless_dev *wdev = info->user_ptr[1];
10318 int err;
10319
10320 if (!rdev->ops->start_p2p_device)
10321 return -EOPNOTSUPP;
10322
10323 if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE)
10324 return -EOPNOTSUPP;
10325
10326 if (wdev->p2p_started)
10327 return 0;
10328
Luciano Coelhob6a55012014-02-27 11:07:21 +020010329 if (rfkill_blocked(rdev->rfkill))
10330 return -ERFKILL;
Johannes Berg98104fde2012-06-16 00:19:54 +020010331
Johannes Bergeeb126e2012-10-23 15:16:50 +020010332 err = rdev_start_p2p_device(rdev, wdev);
Johannes Berg98104fde2012-06-16 00:19:54 +020010333 if (err)
10334 return err;
10335
10336 wdev->p2p_started = true;
Johannes Berg98104fde2012-06-16 00:19:54 +020010337 rdev->opencount++;
Johannes Berg98104fde2012-06-16 00:19:54 +020010338
10339 return 0;
10340}
10341
10342static int nl80211_stop_p2p_device(struct sk_buff *skb, struct genl_info *info)
10343{
10344 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10345 struct wireless_dev *wdev = info->user_ptr[1];
10346
10347 if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE)
10348 return -EOPNOTSUPP;
10349
10350 if (!rdev->ops->stop_p2p_device)
10351 return -EOPNOTSUPP;
10352
Johannes Bergf9f47522013-03-19 15:04:07 +010010353 cfg80211_stop_p2p_device(rdev, wdev);
Johannes Berg98104fde2012-06-16 00:19:54 +020010354
10355 return 0;
10356}
10357
Johannes Berg3713b4e2013-02-14 16:19:38 +010010358static int nl80211_get_protocol_features(struct sk_buff *skb,
10359 struct genl_info *info)
10360{
10361 void *hdr;
10362 struct sk_buff *msg;
10363
10364 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
10365 if (!msg)
10366 return -ENOMEM;
10367
10368 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
10369 NL80211_CMD_GET_PROTOCOL_FEATURES);
10370 if (!hdr)
10371 goto nla_put_failure;
10372
10373 if (nla_put_u32(msg, NL80211_ATTR_PROTOCOL_FEATURES,
10374 NL80211_PROTOCOL_FEATURE_SPLIT_WIPHY_DUMP))
10375 goto nla_put_failure;
10376
10377 genlmsg_end(msg, hdr);
10378 return genlmsg_reply(msg, info);
10379
10380 nla_put_failure:
10381 kfree_skb(msg);
10382 return -ENOBUFS;
10383}
10384
Jouni Malinen355199e2013-02-27 17:14:27 +020010385static int nl80211_update_ft_ies(struct sk_buff *skb, struct genl_info *info)
10386{
10387 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10388 struct cfg80211_update_ft_ies_params ft_params;
10389 struct net_device *dev = info->user_ptr[1];
10390
10391 if (!rdev->ops->update_ft_ies)
10392 return -EOPNOTSUPP;
10393
10394 if (!info->attrs[NL80211_ATTR_MDID] ||
10395 !is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
10396 return -EINVAL;
10397
10398 memset(&ft_params, 0, sizeof(ft_params));
10399 ft_params.md = nla_get_u16(info->attrs[NL80211_ATTR_MDID]);
10400 ft_params.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
10401 ft_params.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
10402
10403 return rdev_update_ft_ies(rdev, dev, &ft_params);
10404}
10405
Arend van Spriel5de17982013-04-18 15:49:00 +020010406static int nl80211_crit_protocol_start(struct sk_buff *skb,
10407 struct genl_info *info)
10408{
10409 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10410 struct wireless_dev *wdev = info->user_ptr[1];
10411 enum nl80211_crit_proto_id proto = NL80211_CRIT_PROTO_UNSPEC;
10412 u16 duration;
10413 int ret;
10414
10415 if (!rdev->ops->crit_proto_start)
10416 return -EOPNOTSUPP;
10417
10418 if (WARN_ON(!rdev->ops->crit_proto_stop))
10419 return -EINVAL;
10420
10421 if (rdev->crit_proto_nlportid)
10422 return -EBUSY;
10423
10424 /* determine protocol if provided */
10425 if (info->attrs[NL80211_ATTR_CRIT_PROT_ID])
10426 proto = nla_get_u16(info->attrs[NL80211_ATTR_CRIT_PROT_ID]);
10427
10428 if (proto >= NUM_NL80211_CRIT_PROTO)
10429 return -EINVAL;
10430
10431 /* timeout must be provided */
10432 if (!info->attrs[NL80211_ATTR_MAX_CRIT_PROT_DURATION])
10433 return -EINVAL;
10434
10435 duration =
10436 nla_get_u16(info->attrs[NL80211_ATTR_MAX_CRIT_PROT_DURATION]);
10437
10438 if (duration > NL80211_CRIT_PROTO_MAX_DURATION)
10439 return -ERANGE;
10440
10441 ret = rdev_crit_proto_start(rdev, wdev, proto, duration);
10442 if (!ret)
10443 rdev->crit_proto_nlportid = info->snd_portid;
10444
10445 return ret;
10446}
10447
10448static int nl80211_crit_protocol_stop(struct sk_buff *skb,
10449 struct genl_info *info)
10450{
10451 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10452 struct wireless_dev *wdev = info->user_ptr[1];
10453
10454 if (!rdev->ops->crit_proto_stop)
10455 return -EOPNOTSUPP;
10456
10457 if (rdev->crit_proto_nlportid) {
10458 rdev->crit_proto_nlportid = 0;
10459 rdev_crit_proto_stop(rdev, wdev);
10460 }
10461 return 0;
10462}
10463
Johannes Bergad7e7182013-11-13 13:37:47 +010010464static int nl80211_vendor_cmd(struct sk_buff *skb, struct genl_info *info)
10465{
10466 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10467 struct wireless_dev *wdev =
10468 __cfg80211_wdev_from_attrs(genl_info_net(info), info->attrs);
10469 int i, err;
10470 u32 vid, subcmd;
10471
10472 if (!rdev->wiphy.vendor_commands)
10473 return -EOPNOTSUPP;
10474
10475 if (IS_ERR(wdev)) {
10476 err = PTR_ERR(wdev);
10477 if (err != -EINVAL)
10478 return err;
10479 wdev = NULL;
10480 } else if (wdev->wiphy != &rdev->wiphy) {
10481 return -EINVAL;
10482 }
10483
10484 if (!info->attrs[NL80211_ATTR_VENDOR_ID] ||
10485 !info->attrs[NL80211_ATTR_VENDOR_SUBCMD])
10486 return -EINVAL;
10487
10488 vid = nla_get_u32(info->attrs[NL80211_ATTR_VENDOR_ID]);
10489 subcmd = nla_get_u32(info->attrs[NL80211_ATTR_VENDOR_SUBCMD]);
10490 for (i = 0; i < rdev->wiphy.n_vendor_commands; i++) {
10491 const struct wiphy_vendor_command *vcmd;
10492 void *data = NULL;
10493 int len = 0;
10494
10495 vcmd = &rdev->wiphy.vendor_commands[i];
10496
10497 if (vcmd->info.vendor_id != vid || vcmd->info.subcmd != subcmd)
10498 continue;
10499
10500 if (vcmd->flags & (WIPHY_VENDOR_CMD_NEED_WDEV |
10501 WIPHY_VENDOR_CMD_NEED_NETDEV)) {
10502 if (!wdev)
10503 return -EINVAL;
10504 if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_NETDEV &&
10505 !wdev->netdev)
10506 return -EINVAL;
10507
10508 if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_RUNNING) {
10509 if (wdev->netdev &&
10510 !netif_running(wdev->netdev))
10511 return -ENETDOWN;
10512 if (!wdev->netdev && !wdev->p2p_started)
10513 return -ENETDOWN;
10514 }
Johannes Berg7bdbe402015-08-15 22:39:49 +030010515
10516 if (!vcmd->doit)
10517 return -EOPNOTSUPP;
Johannes Bergad7e7182013-11-13 13:37:47 +010010518 } else {
10519 wdev = NULL;
10520 }
10521
10522 if (info->attrs[NL80211_ATTR_VENDOR_DATA]) {
10523 data = nla_data(info->attrs[NL80211_ATTR_VENDOR_DATA]);
10524 len = nla_len(info->attrs[NL80211_ATTR_VENDOR_DATA]);
10525 }
10526
10527 rdev->cur_cmd_info = info;
10528 err = rdev->wiphy.vendor_commands[i].doit(&rdev->wiphy, wdev,
10529 data, len);
10530 rdev->cur_cmd_info = NULL;
10531 return err;
10532 }
10533
10534 return -EOPNOTSUPP;
10535}
10536
Johannes Berg7bdbe402015-08-15 22:39:49 +030010537static int nl80211_prepare_vendor_dump(struct sk_buff *skb,
10538 struct netlink_callback *cb,
10539 struct cfg80211_registered_device **rdev,
10540 struct wireless_dev **wdev)
10541{
10542 u32 vid, subcmd;
10543 unsigned int i;
10544 int vcmd_idx = -1;
10545 int err;
10546 void *data = NULL;
10547 unsigned int data_len = 0;
10548
10549 rtnl_lock();
10550
10551 if (cb->args[0]) {
10552 /* subtract the 1 again here */
10553 struct wiphy *wiphy = wiphy_idx_to_wiphy(cb->args[0] - 1);
10554 struct wireless_dev *tmp;
10555
10556 if (!wiphy) {
10557 err = -ENODEV;
10558 goto out_unlock;
10559 }
10560 *rdev = wiphy_to_rdev(wiphy);
10561 *wdev = NULL;
10562
10563 if (cb->args[1]) {
Johannes Berg53873f12016-05-03 16:52:04 +030010564 list_for_each_entry(tmp, &wiphy->wdev_list, list) {
Johannes Berg7bdbe402015-08-15 22:39:49 +030010565 if (tmp->identifier == cb->args[1] - 1) {
10566 *wdev = tmp;
10567 break;
10568 }
10569 }
10570 }
10571
10572 /* keep rtnl locked in successful case */
10573 return 0;
10574 }
10575
10576 err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize,
10577 nl80211_fam.attrbuf, nl80211_fam.maxattr,
10578 nl80211_policy);
10579 if (err)
10580 goto out_unlock;
10581
10582 if (!nl80211_fam.attrbuf[NL80211_ATTR_VENDOR_ID] ||
10583 !nl80211_fam.attrbuf[NL80211_ATTR_VENDOR_SUBCMD]) {
10584 err = -EINVAL;
10585 goto out_unlock;
10586 }
10587
10588 *wdev = __cfg80211_wdev_from_attrs(sock_net(skb->sk),
10589 nl80211_fam.attrbuf);
10590 if (IS_ERR(*wdev))
10591 *wdev = NULL;
10592
10593 *rdev = __cfg80211_rdev_from_attrs(sock_net(skb->sk),
10594 nl80211_fam.attrbuf);
10595 if (IS_ERR(*rdev)) {
10596 err = PTR_ERR(*rdev);
10597 goto out_unlock;
10598 }
10599
10600 vid = nla_get_u32(nl80211_fam.attrbuf[NL80211_ATTR_VENDOR_ID]);
10601 subcmd = nla_get_u32(nl80211_fam.attrbuf[NL80211_ATTR_VENDOR_SUBCMD]);
10602
10603 for (i = 0; i < (*rdev)->wiphy.n_vendor_commands; i++) {
10604 const struct wiphy_vendor_command *vcmd;
10605
10606 vcmd = &(*rdev)->wiphy.vendor_commands[i];
10607
10608 if (vcmd->info.vendor_id != vid || vcmd->info.subcmd != subcmd)
10609 continue;
10610
10611 if (!vcmd->dumpit) {
10612 err = -EOPNOTSUPP;
10613 goto out_unlock;
10614 }
10615
10616 vcmd_idx = i;
10617 break;
10618 }
10619
10620 if (vcmd_idx < 0) {
10621 err = -EOPNOTSUPP;
10622 goto out_unlock;
10623 }
10624
10625 if (nl80211_fam.attrbuf[NL80211_ATTR_VENDOR_DATA]) {
10626 data = nla_data(nl80211_fam.attrbuf[NL80211_ATTR_VENDOR_DATA]);
10627 data_len = nla_len(nl80211_fam.attrbuf[NL80211_ATTR_VENDOR_DATA]);
10628 }
10629
10630 /* 0 is the first index - add 1 to parse only once */
10631 cb->args[0] = (*rdev)->wiphy_idx + 1;
10632 /* add 1 to know if it was NULL */
10633 cb->args[1] = *wdev ? (*wdev)->identifier + 1 : 0;
10634 cb->args[2] = vcmd_idx;
10635 cb->args[3] = (unsigned long)data;
10636 cb->args[4] = data_len;
10637
10638 /* keep rtnl locked in successful case */
10639 return 0;
10640 out_unlock:
10641 rtnl_unlock();
10642 return err;
10643}
10644
10645static int nl80211_vendor_cmd_dump(struct sk_buff *skb,
10646 struct netlink_callback *cb)
10647{
10648 struct cfg80211_registered_device *rdev;
10649 struct wireless_dev *wdev;
10650 unsigned int vcmd_idx;
10651 const struct wiphy_vendor_command *vcmd;
10652 void *data;
10653 int data_len;
10654 int err;
10655 struct nlattr *vendor_data;
10656
10657 err = nl80211_prepare_vendor_dump(skb, cb, &rdev, &wdev);
10658 if (err)
10659 return err;
10660
10661 vcmd_idx = cb->args[2];
10662 data = (void *)cb->args[3];
10663 data_len = cb->args[4];
10664 vcmd = &rdev->wiphy.vendor_commands[vcmd_idx];
10665
10666 if (vcmd->flags & (WIPHY_VENDOR_CMD_NEED_WDEV |
10667 WIPHY_VENDOR_CMD_NEED_NETDEV)) {
10668 if (!wdev)
10669 return -EINVAL;
10670 if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_NETDEV &&
10671 !wdev->netdev)
10672 return -EINVAL;
10673
10674 if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_RUNNING) {
10675 if (wdev->netdev &&
10676 !netif_running(wdev->netdev))
10677 return -ENETDOWN;
10678 if (!wdev->netdev && !wdev->p2p_started)
10679 return -ENETDOWN;
10680 }
10681 }
10682
10683 while (1) {
10684 void *hdr = nl80211hdr_put(skb, NETLINK_CB(cb->skb).portid,
10685 cb->nlh->nlmsg_seq, NLM_F_MULTI,
10686 NL80211_CMD_VENDOR);
10687 if (!hdr)
10688 break;
10689
10690 if (nla_put_u32(skb, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020010691 (wdev && nla_put_u64_64bit(skb, NL80211_ATTR_WDEV,
10692 wdev_id(wdev),
10693 NL80211_ATTR_PAD))) {
Johannes Berg7bdbe402015-08-15 22:39:49 +030010694 genlmsg_cancel(skb, hdr);
10695 break;
10696 }
10697
10698 vendor_data = nla_nest_start(skb, NL80211_ATTR_VENDOR_DATA);
10699 if (!vendor_data) {
10700 genlmsg_cancel(skb, hdr);
10701 break;
10702 }
10703
10704 err = vcmd->dumpit(&rdev->wiphy, wdev, skb, data, data_len,
10705 (unsigned long *)&cb->args[5]);
10706 nla_nest_end(skb, vendor_data);
10707
10708 if (err == -ENOBUFS || err == -ENOENT) {
10709 genlmsg_cancel(skb, hdr);
10710 break;
10711 } else if (err) {
10712 genlmsg_cancel(skb, hdr);
10713 goto out;
10714 }
10715
10716 genlmsg_end(skb, hdr);
10717 }
10718
10719 err = skb->len;
10720 out:
10721 rtnl_unlock();
10722 return err;
10723}
10724
Johannes Bergad7e7182013-11-13 13:37:47 +010010725struct sk_buff *__cfg80211_alloc_reply_skb(struct wiphy *wiphy,
10726 enum nl80211_commands cmd,
10727 enum nl80211_attrs attr,
10728 int approxlen)
10729{
Zhao, Gangf26cbf42014-04-21 12:53:03 +080010730 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Bergad7e7182013-11-13 13:37:47 +010010731
10732 if (WARN_ON(!rdev->cur_cmd_info))
10733 return NULL;
10734
Ahmad Kholaif6c09e792015-02-26 15:26:53 +020010735 return __cfg80211_alloc_vendor_skb(rdev, NULL, approxlen,
Johannes Bergad7e7182013-11-13 13:37:47 +010010736 rdev->cur_cmd_info->snd_portid,
10737 rdev->cur_cmd_info->snd_seq,
Johannes Berg567ffc32013-12-18 14:43:31 +010010738 cmd, attr, NULL, GFP_KERNEL);
Johannes Bergad7e7182013-11-13 13:37:47 +010010739}
10740EXPORT_SYMBOL(__cfg80211_alloc_reply_skb);
10741
10742int cfg80211_vendor_cmd_reply(struct sk_buff *skb)
10743{
10744 struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0];
10745 void *hdr = ((void **)skb->cb)[1];
10746 struct nlattr *data = ((void **)skb->cb)[2];
10747
Johannes Bergbd8c78e2014-07-30 14:55:26 +020010748 /* clear CB data for netlink core to own from now on */
10749 memset(skb->cb, 0, sizeof(skb->cb));
10750
Johannes Bergad7e7182013-11-13 13:37:47 +010010751 if (WARN_ON(!rdev->cur_cmd_info)) {
10752 kfree_skb(skb);
10753 return -EINVAL;
10754 }
10755
10756 nla_nest_end(skb, data);
10757 genlmsg_end(skb, hdr);
10758 return genlmsg_reply(skb, rdev->cur_cmd_info);
10759}
10760EXPORT_SYMBOL_GPL(cfg80211_vendor_cmd_reply);
10761
Kyeyoon Parkfa9ffc72013-12-16 23:01:30 -080010762static int nl80211_set_qos_map(struct sk_buff *skb,
10763 struct genl_info *info)
10764{
10765 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10766 struct cfg80211_qos_map *qos_map = NULL;
10767 struct net_device *dev = info->user_ptr[1];
10768 u8 *pos, len, num_des, des_len, des;
10769 int ret;
10770
10771 if (!rdev->ops->set_qos_map)
10772 return -EOPNOTSUPP;
10773
10774 if (info->attrs[NL80211_ATTR_QOS_MAP]) {
10775 pos = nla_data(info->attrs[NL80211_ATTR_QOS_MAP]);
10776 len = nla_len(info->attrs[NL80211_ATTR_QOS_MAP]);
10777
10778 if (len % 2 || len < IEEE80211_QOS_MAP_LEN_MIN ||
10779 len > IEEE80211_QOS_MAP_LEN_MAX)
10780 return -EINVAL;
10781
10782 qos_map = kzalloc(sizeof(struct cfg80211_qos_map), GFP_KERNEL);
10783 if (!qos_map)
10784 return -ENOMEM;
10785
10786 num_des = (len - IEEE80211_QOS_MAP_LEN_MIN) >> 1;
10787 if (num_des) {
10788 des_len = num_des *
10789 sizeof(struct cfg80211_dscp_exception);
10790 memcpy(qos_map->dscp_exception, pos, des_len);
10791 qos_map->num_des = num_des;
10792 for (des = 0; des < num_des; des++) {
10793 if (qos_map->dscp_exception[des].up > 7) {
10794 kfree(qos_map);
10795 return -EINVAL;
10796 }
10797 }
10798 pos += des_len;
10799 }
10800 memcpy(qos_map->up, pos, IEEE80211_QOS_MAP_LEN_MIN);
10801 }
10802
10803 wdev_lock(dev->ieee80211_ptr);
10804 ret = nl80211_key_allowed(dev->ieee80211_ptr);
10805 if (!ret)
10806 ret = rdev_set_qos_map(rdev, dev, qos_map);
10807 wdev_unlock(dev->ieee80211_ptr);
10808
10809 kfree(qos_map);
10810 return ret;
10811}
10812
Johannes Berg960d01a2014-09-09 22:55:35 +030010813static int nl80211_add_tx_ts(struct sk_buff *skb, struct genl_info *info)
10814{
10815 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10816 struct net_device *dev = info->user_ptr[1];
10817 struct wireless_dev *wdev = dev->ieee80211_ptr;
10818 const u8 *peer;
10819 u8 tsid, up;
10820 u16 admitted_time = 0;
10821 int err;
10822
Johannes Berg723e73a2014-10-22 09:25:06 +020010823 if (!(rdev->wiphy.features & NL80211_FEATURE_SUPPORTS_WMM_ADMISSION))
Johannes Berg960d01a2014-09-09 22:55:35 +030010824 return -EOPNOTSUPP;
10825
10826 if (!info->attrs[NL80211_ATTR_TSID] || !info->attrs[NL80211_ATTR_MAC] ||
10827 !info->attrs[NL80211_ATTR_USER_PRIO])
10828 return -EINVAL;
10829
10830 tsid = nla_get_u8(info->attrs[NL80211_ATTR_TSID]);
10831 if (tsid >= IEEE80211_NUM_TIDS)
10832 return -EINVAL;
10833
10834 up = nla_get_u8(info->attrs[NL80211_ATTR_USER_PRIO]);
10835 if (up >= IEEE80211_NUM_UPS)
10836 return -EINVAL;
10837
10838 /* WMM uses TIDs 0-7 even for TSPEC */
Johannes Berg723e73a2014-10-22 09:25:06 +020010839 if (tsid >= IEEE80211_FIRST_TSPEC_TSID) {
Johannes Berg960d01a2014-09-09 22:55:35 +030010840 /* TODO: handle 802.11 TSPEC/admission control
Johannes Berg723e73a2014-10-22 09:25:06 +020010841 * need more attributes for that (e.g. BA session requirement);
10842 * change the WMM adminssion test above to allow both then
Johannes Berg960d01a2014-09-09 22:55:35 +030010843 */
10844 return -EINVAL;
10845 }
10846
10847 peer = nla_data(info->attrs[NL80211_ATTR_MAC]);
10848
10849 if (info->attrs[NL80211_ATTR_ADMITTED_TIME]) {
10850 admitted_time =
10851 nla_get_u16(info->attrs[NL80211_ATTR_ADMITTED_TIME]);
10852 if (!admitted_time)
10853 return -EINVAL;
10854 }
10855
10856 wdev_lock(wdev);
10857 switch (wdev->iftype) {
10858 case NL80211_IFTYPE_STATION:
10859 case NL80211_IFTYPE_P2P_CLIENT:
10860 if (wdev->current_bss)
10861 break;
10862 err = -ENOTCONN;
10863 goto out;
10864 default:
10865 err = -EOPNOTSUPP;
10866 goto out;
10867 }
10868
10869 err = rdev_add_tx_ts(rdev, dev, tsid, peer, up, admitted_time);
10870
10871 out:
10872 wdev_unlock(wdev);
10873 return err;
10874}
10875
10876static int nl80211_del_tx_ts(struct sk_buff *skb, struct genl_info *info)
10877{
10878 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10879 struct net_device *dev = info->user_ptr[1];
10880 struct wireless_dev *wdev = dev->ieee80211_ptr;
10881 const u8 *peer;
10882 u8 tsid;
10883 int err;
10884
10885 if (!info->attrs[NL80211_ATTR_TSID] || !info->attrs[NL80211_ATTR_MAC])
10886 return -EINVAL;
10887
10888 tsid = nla_get_u8(info->attrs[NL80211_ATTR_TSID]);
10889 peer = nla_data(info->attrs[NL80211_ATTR_MAC]);
10890
10891 wdev_lock(wdev);
10892 err = rdev_del_tx_ts(rdev, dev, tsid, peer);
10893 wdev_unlock(wdev);
10894
10895 return err;
10896}
10897
Arik Nemtsov1057d352014-11-19 12:54:26 +020010898static int nl80211_tdls_channel_switch(struct sk_buff *skb,
10899 struct genl_info *info)
10900{
10901 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10902 struct net_device *dev = info->user_ptr[1];
10903 struct wireless_dev *wdev = dev->ieee80211_ptr;
10904 struct cfg80211_chan_def chandef = {};
10905 const u8 *addr;
10906 u8 oper_class;
10907 int err;
10908
10909 if (!rdev->ops->tdls_channel_switch ||
10910 !(rdev->wiphy.features & NL80211_FEATURE_TDLS_CHANNEL_SWITCH))
10911 return -EOPNOTSUPP;
10912
10913 switch (dev->ieee80211_ptr->iftype) {
10914 case NL80211_IFTYPE_STATION:
10915 case NL80211_IFTYPE_P2P_CLIENT:
10916 break;
10917 default:
10918 return -EOPNOTSUPP;
10919 }
10920
10921 if (!info->attrs[NL80211_ATTR_MAC] ||
10922 !info->attrs[NL80211_ATTR_OPER_CLASS])
10923 return -EINVAL;
10924
10925 err = nl80211_parse_chandef(rdev, info, &chandef);
10926 if (err)
10927 return err;
10928
10929 /*
10930 * Don't allow wide channels on the 2.4Ghz band, as per IEEE802.11-2012
10931 * section 10.22.6.2.1. Disallow 5/10Mhz channels as well for now, the
10932 * specification is not defined for them.
10933 */
Johannes Berg57fbcce2016-04-12 15:56:15 +020010934 if (chandef.chan->band == NL80211_BAND_2GHZ &&
Arik Nemtsov1057d352014-11-19 12:54:26 +020010935 chandef.width != NL80211_CHAN_WIDTH_20_NOHT &&
10936 chandef.width != NL80211_CHAN_WIDTH_20)
10937 return -EINVAL;
10938
10939 /* we will be active on the TDLS link */
Arik Nemtsov923b3522015-07-08 15:41:44 +030010940 if (!cfg80211_reg_can_beacon_relax(&rdev->wiphy, &chandef,
10941 wdev->iftype))
Arik Nemtsov1057d352014-11-19 12:54:26 +020010942 return -EINVAL;
10943
10944 /* don't allow switching to DFS channels */
10945 if (cfg80211_chandef_dfs_required(wdev->wiphy, &chandef, wdev->iftype))
10946 return -EINVAL;
10947
10948 addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
10949 oper_class = nla_get_u8(info->attrs[NL80211_ATTR_OPER_CLASS]);
10950
10951 wdev_lock(wdev);
10952 err = rdev_tdls_channel_switch(rdev, dev, addr, oper_class, &chandef);
10953 wdev_unlock(wdev);
10954
10955 return err;
10956}
10957
10958static int nl80211_tdls_cancel_channel_switch(struct sk_buff *skb,
10959 struct genl_info *info)
10960{
10961 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10962 struct net_device *dev = info->user_ptr[1];
10963 struct wireless_dev *wdev = dev->ieee80211_ptr;
10964 const u8 *addr;
10965
10966 if (!rdev->ops->tdls_channel_switch ||
10967 !rdev->ops->tdls_cancel_channel_switch ||
10968 !(rdev->wiphy.features & NL80211_FEATURE_TDLS_CHANNEL_SWITCH))
10969 return -EOPNOTSUPP;
10970
10971 switch (dev->ieee80211_ptr->iftype) {
10972 case NL80211_IFTYPE_STATION:
10973 case NL80211_IFTYPE_P2P_CLIENT:
10974 break;
10975 default:
10976 return -EOPNOTSUPP;
10977 }
10978
10979 if (!info->attrs[NL80211_ATTR_MAC])
10980 return -EINVAL;
10981
10982 addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
10983
10984 wdev_lock(wdev);
10985 rdev_tdls_cancel_channel_switch(rdev, dev, addr);
10986 wdev_unlock(wdev);
10987
10988 return 0;
10989}
10990
Johannes Berg4c476992010-10-04 21:36:35 +020010991#define NL80211_FLAG_NEED_WIPHY 0x01
10992#define NL80211_FLAG_NEED_NETDEV 0x02
10993#define NL80211_FLAG_NEED_RTNL 0x04
Johannes Berg41265712010-10-04 21:14:05 +020010994#define NL80211_FLAG_CHECK_NETDEV_UP 0x08
10995#define NL80211_FLAG_NEED_NETDEV_UP (NL80211_FLAG_NEED_NETDEV |\
10996 NL80211_FLAG_CHECK_NETDEV_UP)
Johannes Berg1bf614e2012-06-15 15:23:36 +020010997#define NL80211_FLAG_NEED_WDEV 0x10
Johannes Berg98104fde2012-06-16 00:19:54 +020010998/* If a netdev is associated, it must be UP, P2P must be started */
Johannes Berg1bf614e2012-06-15 15:23:36 +020010999#define NL80211_FLAG_NEED_WDEV_UP (NL80211_FLAG_NEED_WDEV |\
11000 NL80211_FLAG_CHECK_NETDEV_UP)
Johannes Berg5393b912014-09-10 15:00:16 +030011001#define NL80211_FLAG_CLEAR_SKB 0x20
Johannes Berg4c476992010-10-04 21:36:35 +020011002
Johannes Bergf84f7712013-11-14 17:14:45 +010011003static int nl80211_pre_doit(const struct genl_ops *ops, struct sk_buff *skb,
Johannes Berg4c476992010-10-04 21:36:35 +020011004 struct genl_info *info)
11005{
11006 struct cfg80211_registered_device *rdev;
Johannes Berg89a54e42012-06-15 14:33:17 +020011007 struct wireless_dev *wdev;
Johannes Berg4c476992010-10-04 21:36:35 +020011008 struct net_device *dev;
Johannes Berg4c476992010-10-04 21:36:35 +020011009 bool rtnl = ops->internal_flags & NL80211_FLAG_NEED_RTNL;
11010
11011 if (rtnl)
11012 rtnl_lock();
11013
11014 if (ops->internal_flags & NL80211_FLAG_NEED_WIPHY) {
Johannes Berg4f7eff12012-06-15 14:14:22 +020011015 rdev = cfg80211_get_dev_from_info(genl_info_net(info), info);
Johannes Berg4c476992010-10-04 21:36:35 +020011016 if (IS_ERR(rdev)) {
11017 if (rtnl)
11018 rtnl_unlock();
11019 return PTR_ERR(rdev);
11020 }
11021 info->user_ptr[0] = rdev;
Johannes Berg1bf614e2012-06-15 15:23:36 +020011022 } else if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV ||
11023 ops->internal_flags & NL80211_FLAG_NEED_WDEV) {
Johannes Berg5fe231e2013-05-08 21:45:15 +020011024 ASSERT_RTNL();
11025
Johannes Berg89a54e42012-06-15 14:33:17 +020011026 wdev = __cfg80211_wdev_from_attrs(genl_info_net(info),
11027 info->attrs);
11028 if (IS_ERR(wdev)) {
Johannes Berg4c476992010-10-04 21:36:35 +020011029 if (rtnl)
11030 rtnl_unlock();
Johannes Berg89a54e42012-06-15 14:33:17 +020011031 return PTR_ERR(wdev);
Johannes Berg4c476992010-10-04 21:36:35 +020011032 }
Johannes Berg89a54e42012-06-15 14:33:17 +020011033
Johannes Berg89a54e42012-06-15 14:33:17 +020011034 dev = wdev->netdev;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080011035 rdev = wiphy_to_rdev(wdev->wiphy);
Johannes Berg89a54e42012-06-15 14:33:17 +020011036
Johannes Berg1bf614e2012-06-15 15:23:36 +020011037 if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV) {
11038 if (!dev) {
Johannes Berg1bf614e2012-06-15 15:23:36 +020011039 if (rtnl)
11040 rtnl_unlock();
11041 return -EINVAL;
11042 }
11043
11044 info->user_ptr[1] = dev;
11045 } else {
11046 info->user_ptr[1] = wdev;
Johannes Berg41265712010-10-04 21:14:05 +020011047 }
Johannes Berg89a54e42012-06-15 14:33:17 +020011048
Johannes Berg1bf614e2012-06-15 15:23:36 +020011049 if (dev) {
11050 if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP &&
11051 !netif_running(dev)) {
Johannes Berg1bf614e2012-06-15 15:23:36 +020011052 if (rtnl)
11053 rtnl_unlock();
11054 return -ENETDOWN;
11055 }
11056
11057 dev_hold(dev);
Johannes Berg98104fde2012-06-16 00:19:54 +020011058 } else if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP) {
11059 if (!wdev->p2p_started) {
Johannes Berg98104fde2012-06-16 00:19:54 +020011060 if (rtnl)
11061 rtnl_unlock();
11062 return -ENETDOWN;
11063 }
Johannes Berg1bf614e2012-06-15 15:23:36 +020011064 }
11065
Johannes Berg4c476992010-10-04 21:36:35 +020011066 info->user_ptr[0] = rdev;
Johannes Berg4c476992010-10-04 21:36:35 +020011067 }
11068
11069 return 0;
11070}
11071
Johannes Bergf84f7712013-11-14 17:14:45 +010011072static void nl80211_post_doit(const struct genl_ops *ops, struct sk_buff *skb,
Johannes Berg4c476992010-10-04 21:36:35 +020011073 struct genl_info *info)
11074{
Johannes Berg1bf614e2012-06-15 15:23:36 +020011075 if (info->user_ptr[1]) {
11076 if (ops->internal_flags & NL80211_FLAG_NEED_WDEV) {
11077 struct wireless_dev *wdev = info->user_ptr[1];
11078
11079 if (wdev->netdev)
11080 dev_put(wdev->netdev);
11081 } else {
11082 dev_put(info->user_ptr[1]);
11083 }
11084 }
Johannes Berg5393b912014-09-10 15:00:16 +030011085
Johannes Berg4c476992010-10-04 21:36:35 +020011086 if (ops->internal_flags & NL80211_FLAG_NEED_RTNL)
11087 rtnl_unlock();
Johannes Berg5393b912014-09-10 15:00:16 +030011088
11089 /* If needed, clear the netlink message payload from the SKB
11090 * as it might contain key data that shouldn't stick around on
11091 * the heap after the SKB is freed. The netlink message header
11092 * is still needed for further processing, so leave it intact.
11093 */
11094 if (ops->internal_flags & NL80211_FLAG_CLEAR_SKB) {
11095 struct nlmsghdr *nlh = nlmsg_hdr(skb);
11096
11097 memset(nlmsg_data(nlh), 0, nlmsg_len(nlh));
11098 }
Johannes Berg4c476992010-10-04 21:36:35 +020011099}
11100
Johannes Berg4534de82013-11-14 17:14:46 +010011101static const struct genl_ops nl80211_ops[] = {
Johannes Berg55682962007-09-20 13:09:35 -040011102 {
11103 .cmd = NL80211_CMD_GET_WIPHY,
11104 .doit = nl80211_get_wiphy,
11105 .dumpit = nl80211_dump_wiphy,
Johannes Berg86e8cf92013-06-19 10:57:22 +020011106 .done = nl80211_dump_wiphy_done,
Johannes Berg55682962007-09-20 13:09:35 -040011107 .policy = nl80211_policy,
11108 /* can be retrieved by unprivileged users */
Johannes Berg5fe231e2013-05-08 21:45:15 +020011109 .internal_flags = NL80211_FLAG_NEED_WIPHY |
11110 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -040011111 },
11112 {
11113 .cmd = NL80211_CMD_SET_WIPHY,
11114 .doit = nl80211_set_wiphy,
11115 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011116 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020011117 .internal_flags = NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -040011118 },
11119 {
11120 .cmd = NL80211_CMD_GET_INTERFACE,
11121 .doit = nl80211_get_interface,
11122 .dumpit = nl80211_dump_interface,
11123 .policy = nl80211_policy,
11124 /* can be retrieved by unprivileged users */
Johannes Berg5fe231e2013-05-08 21:45:15 +020011125 .internal_flags = NL80211_FLAG_NEED_WDEV |
11126 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -040011127 },
11128 {
11129 .cmd = NL80211_CMD_SET_INTERFACE,
11130 .doit = nl80211_set_interface,
11131 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011132 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020011133 .internal_flags = NL80211_FLAG_NEED_NETDEV |
11134 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -040011135 },
11136 {
11137 .cmd = NL80211_CMD_NEW_INTERFACE,
11138 .doit = nl80211_new_interface,
11139 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011140 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020011141 .internal_flags = NL80211_FLAG_NEED_WIPHY |
11142 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -040011143 },
11144 {
11145 .cmd = NL80211_CMD_DEL_INTERFACE,
11146 .doit = nl80211_del_interface,
11147 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011148 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg84efbb82012-06-16 00:00:26 +020011149 .internal_flags = NL80211_FLAG_NEED_WDEV |
Johannes Berg4c476992010-10-04 21:36:35 +020011150 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -040011151 },
Johannes Berg41ade002007-12-19 02:03:29 +010011152 {
11153 .cmd = NL80211_CMD_GET_KEY,
11154 .doit = nl80211_get_key,
11155 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011156 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020011157 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020011158 NL80211_FLAG_NEED_RTNL,
Johannes Berg41ade002007-12-19 02:03:29 +010011159 },
11160 {
11161 .cmd = NL80211_CMD_SET_KEY,
11162 .doit = nl80211_set_key,
11163 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011164 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020011165 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg5393b912014-09-10 15:00:16 +030011166 NL80211_FLAG_NEED_RTNL |
11167 NL80211_FLAG_CLEAR_SKB,
Johannes Berg41ade002007-12-19 02:03:29 +010011168 },
11169 {
11170 .cmd = NL80211_CMD_NEW_KEY,
11171 .doit = nl80211_new_key,
11172 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011173 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020011174 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg5393b912014-09-10 15:00:16 +030011175 NL80211_FLAG_NEED_RTNL |
11176 NL80211_FLAG_CLEAR_SKB,
Johannes Berg41ade002007-12-19 02:03:29 +010011177 },
11178 {
11179 .cmd = NL80211_CMD_DEL_KEY,
11180 .doit = nl80211_del_key,
11181 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011182 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020011183 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020011184 NL80211_FLAG_NEED_RTNL,
Johannes Berg41ade002007-12-19 02:03:29 +010011185 },
Johannes Berged1b6cc2007-12-19 02:03:32 +010011186 {
11187 .cmd = NL80211_CMD_SET_BEACON,
11188 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011189 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg88600202012-02-13 15:17:18 +010011190 .doit = nl80211_set_beacon,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020011191 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020011192 NL80211_FLAG_NEED_RTNL,
Johannes Berged1b6cc2007-12-19 02:03:32 +010011193 },
11194 {
Johannes Berg88600202012-02-13 15:17:18 +010011195 .cmd = NL80211_CMD_START_AP,
Johannes Berged1b6cc2007-12-19 02:03:32 +010011196 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011197 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg88600202012-02-13 15:17:18 +010011198 .doit = nl80211_start_ap,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020011199 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020011200 NL80211_FLAG_NEED_RTNL,
Johannes Berged1b6cc2007-12-19 02:03:32 +010011201 },
11202 {
Johannes Berg88600202012-02-13 15:17:18 +010011203 .cmd = NL80211_CMD_STOP_AP,
Johannes Berged1b6cc2007-12-19 02:03:32 +010011204 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011205 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg88600202012-02-13 15:17:18 +010011206 .doit = nl80211_stop_ap,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020011207 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020011208 NL80211_FLAG_NEED_RTNL,
Johannes Berged1b6cc2007-12-19 02:03:32 +010011209 },
Johannes Berg5727ef12007-12-19 02:03:34 +010011210 {
11211 .cmd = NL80211_CMD_GET_STATION,
11212 .doit = nl80211_get_station,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010011213 .dumpit = nl80211_dump_station,
Johannes Berg5727ef12007-12-19 02:03:34 +010011214 .policy = nl80211_policy,
Johannes Berg4c476992010-10-04 21:36:35 +020011215 .internal_flags = NL80211_FLAG_NEED_NETDEV |
11216 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +010011217 },
11218 {
11219 .cmd = NL80211_CMD_SET_STATION,
11220 .doit = nl80211_set_station,
11221 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011222 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020011223 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020011224 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +010011225 },
11226 {
11227 .cmd = NL80211_CMD_NEW_STATION,
11228 .doit = nl80211_new_station,
11229 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011230 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020011231 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020011232 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +010011233 },
11234 {
11235 .cmd = NL80211_CMD_DEL_STATION,
11236 .doit = nl80211_del_station,
11237 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011238 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020011239 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020011240 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +010011241 },
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010011242 {
11243 .cmd = NL80211_CMD_GET_MPATH,
11244 .doit = nl80211_get_mpath,
11245 .dumpit = nl80211_dump_mpath,
11246 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011247 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020011248 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020011249 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010011250 },
11251 {
Henning Rogge66be7d22014-09-12 08:58:49 +020011252 .cmd = NL80211_CMD_GET_MPP,
11253 .doit = nl80211_get_mpp,
11254 .dumpit = nl80211_dump_mpp,
11255 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011256 .flags = GENL_UNS_ADMIN_PERM,
Henning Rogge66be7d22014-09-12 08:58:49 +020011257 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
11258 NL80211_FLAG_NEED_RTNL,
11259 },
11260 {
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010011261 .cmd = NL80211_CMD_SET_MPATH,
11262 .doit = nl80211_set_mpath,
11263 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011264 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020011265 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020011266 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010011267 },
11268 {
11269 .cmd = NL80211_CMD_NEW_MPATH,
11270 .doit = nl80211_new_mpath,
11271 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011272 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020011273 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020011274 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010011275 },
11276 {
11277 .cmd = NL80211_CMD_DEL_MPATH,
11278 .doit = nl80211_del_mpath,
11279 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011280 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020011281 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020011282 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010011283 },
Jouni Malinen9f1ba902008-08-07 20:07:01 +030011284 {
11285 .cmd = NL80211_CMD_SET_BSS,
11286 .doit = nl80211_set_bss,
11287 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011288 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020011289 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020011290 NL80211_FLAG_NEED_RTNL,
Jouni Malinen9f1ba902008-08-07 20:07:01 +030011291 },
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -070011292 {
Luis R. Rodriguezf1303472009-01-30 09:26:42 -080011293 .cmd = NL80211_CMD_GET_REG,
Arik Nemtsovad30ca22014-12-15 19:25:59 +020011294 .doit = nl80211_get_reg_do,
11295 .dumpit = nl80211_get_reg_dump,
Luis R. Rodriguezf1303472009-01-30 09:26:42 -080011296 .policy = nl80211_policy,
Johannes Berg5fe231e2013-05-08 21:45:15 +020011297 .internal_flags = NL80211_FLAG_NEED_RTNL,
Luis R. Rodriguezf1303472009-01-30 09:26:42 -080011298 /* can be retrieved by unprivileged users */
11299 },
Johannes Bergb6863032015-10-15 09:25:18 +020011300#ifdef CONFIG_CFG80211_CRDA_SUPPORT
Luis R. Rodriguezf1303472009-01-30 09:26:42 -080011301 {
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -070011302 .cmd = NL80211_CMD_SET_REG,
11303 .doit = nl80211_set_reg,
11304 .policy = nl80211_policy,
11305 .flags = GENL_ADMIN_PERM,
Johannes Berg5fe231e2013-05-08 21:45:15 +020011306 .internal_flags = NL80211_FLAG_NEED_RTNL,
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -070011307 },
Johannes Bergb6863032015-10-15 09:25:18 +020011308#endif
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -070011309 {
11310 .cmd = NL80211_CMD_REQ_SET_REG,
11311 .doit = nl80211_req_set_reg,
11312 .policy = nl80211_policy,
11313 .flags = GENL_ADMIN_PERM,
11314 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -070011315 {
Javier Cardona24bdd9f2010-12-16 17:37:48 -080011316 .cmd = NL80211_CMD_GET_MESH_CONFIG,
11317 .doit = nl80211_get_mesh_config,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -070011318 .policy = nl80211_policy,
11319 /* can be retrieved by unprivileged users */
Johannes Berg2b5f8b02012-04-02 10:51:55 +020011320 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020011321 NL80211_FLAG_NEED_RTNL,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -070011322 },
11323 {
Javier Cardona24bdd9f2010-12-16 17:37:48 -080011324 .cmd = NL80211_CMD_SET_MESH_CONFIG,
11325 .doit = nl80211_update_mesh_config,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -070011326 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011327 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg29cbe682010-12-03 09:20:44 +010011328 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020011329 NL80211_FLAG_NEED_RTNL,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -070011330 },
Jouni Malinen9aed3cc2009-01-13 16:03:29 +020011331 {
Johannes Berg2a519312009-02-10 21:25:55 +010011332 .cmd = NL80211_CMD_TRIGGER_SCAN,
11333 .doit = nl80211_trigger_scan,
11334 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011335 .flags = GENL_UNS_ADMIN_PERM,
Johannes Bergfd014282012-06-18 19:17:03 +020011336 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020011337 NL80211_FLAG_NEED_RTNL,
Johannes Berg2a519312009-02-10 21:25:55 +010011338 },
11339 {
Vidyullatha Kanchanapally91d3ab42015-10-30 19:14:49 +053011340 .cmd = NL80211_CMD_ABORT_SCAN,
11341 .doit = nl80211_abort_scan,
11342 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011343 .flags = GENL_UNS_ADMIN_PERM,
Vidyullatha Kanchanapally91d3ab42015-10-30 19:14:49 +053011344 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
11345 NL80211_FLAG_NEED_RTNL,
11346 },
11347 {
Johannes Berg2a519312009-02-10 21:25:55 +010011348 .cmd = NL80211_CMD_GET_SCAN,
11349 .policy = nl80211_policy,
11350 .dumpit = nl80211_dump_scan,
11351 },
Jouni Malinen636a5d32009-03-19 13:39:22 +020011352 {
Luciano Coelho807f8a82011-05-11 17:09:35 +030011353 .cmd = NL80211_CMD_START_SCHED_SCAN,
11354 .doit = nl80211_start_sched_scan,
11355 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011356 .flags = GENL_UNS_ADMIN_PERM,
Luciano Coelho807f8a82011-05-11 17:09:35 +030011357 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
11358 NL80211_FLAG_NEED_RTNL,
11359 },
11360 {
11361 .cmd = NL80211_CMD_STOP_SCHED_SCAN,
11362 .doit = nl80211_stop_sched_scan,
11363 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011364 .flags = GENL_UNS_ADMIN_PERM,
Luciano Coelho807f8a82011-05-11 17:09:35 +030011365 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
11366 NL80211_FLAG_NEED_RTNL,
11367 },
11368 {
Jouni Malinen636a5d32009-03-19 13:39:22 +020011369 .cmd = NL80211_CMD_AUTHENTICATE,
11370 .doit = nl80211_authenticate,
11371 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011372 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020011373 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg5393b912014-09-10 15:00:16 +030011374 NL80211_FLAG_NEED_RTNL |
11375 NL80211_FLAG_CLEAR_SKB,
Jouni Malinen636a5d32009-03-19 13:39:22 +020011376 },
11377 {
11378 .cmd = NL80211_CMD_ASSOCIATE,
11379 .doit = nl80211_associate,
11380 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011381 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020011382 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020011383 NL80211_FLAG_NEED_RTNL,
Jouni Malinen636a5d32009-03-19 13:39:22 +020011384 },
11385 {
11386 .cmd = NL80211_CMD_DEAUTHENTICATE,
11387 .doit = nl80211_deauthenticate,
11388 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011389 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020011390 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020011391 NL80211_FLAG_NEED_RTNL,
Jouni Malinen636a5d32009-03-19 13:39:22 +020011392 },
11393 {
11394 .cmd = NL80211_CMD_DISASSOCIATE,
11395 .doit = nl80211_disassociate,
11396 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011397 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020011398 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020011399 NL80211_FLAG_NEED_RTNL,
Jouni Malinen636a5d32009-03-19 13:39:22 +020011400 },
Johannes Berg04a773a2009-04-19 21:24:32 +020011401 {
11402 .cmd = NL80211_CMD_JOIN_IBSS,
11403 .doit = nl80211_join_ibss,
11404 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011405 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020011406 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020011407 NL80211_FLAG_NEED_RTNL,
Johannes Berg04a773a2009-04-19 21:24:32 +020011408 },
11409 {
11410 .cmd = NL80211_CMD_LEAVE_IBSS,
11411 .doit = nl80211_leave_ibss,
11412 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011413 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020011414 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020011415 NL80211_FLAG_NEED_RTNL,
Johannes Berg04a773a2009-04-19 21:24:32 +020011416 },
Johannes Bergaff89a92009-07-01 21:26:51 +020011417#ifdef CONFIG_NL80211_TESTMODE
11418 {
11419 .cmd = NL80211_CMD_TESTMODE,
11420 .doit = nl80211_testmode_do,
Wey-Yi Guy71063f02011-05-20 09:05:54 -070011421 .dumpit = nl80211_testmode_dump,
Johannes Bergaff89a92009-07-01 21:26:51 +020011422 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011423 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020011424 .internal_flags = NL80211_FLAG_NEED_WIPHY |
11425 NL80211_FLAG_NEED_RTNL,
Johannes Bergaff89a92009-07-01 21:26:51 +020011426 },
11427#endif
Samuel Ortizb23aa672009-07-01 21:26:54 +020011428 {
11429 .cmd = NL80211_CMD_CONNECT,
11430 .doit = nl80211_connect,
11431 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011432 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020011433 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020011434 NL80211_FLAG_NEED_RTNL,
Samuel Ortizb23aa672009-07-01 21:26:54 +020011435 },
11436 {
11437 .cmd = NL80211_CMD_DISCONNECT,
11438 .doit = nl80211_disconnect,
11439 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011440 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020011441 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020011442 NL80211_FLAG_NEED_RTNL,
Samuel Ortizb23aa672009-07-01 21:26:54 +020011443 },
Johannes Berg463d0182009-07-14 00:33:35 +020011444 {
11445 .cmd = NL80211_CMD_SET_WIPHY_NETNS,
11446 .doit = nl80211_wiphy_netns,
11447 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011448 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020011449 .internal_flags = NL80211_FLAG_NEED_WIPHY |
11450 NL80211_FLAG_NEED_RTNL,
Johannes Berg463d0182009-07-14 00:33:35 +020011451 },
Holger Schurig61fa7132009-11-11 12:25:40 +010011452 {
11453 .cmd = NL80211_CMD_GET_SURVEY,
11454 .policy = nl80211_policy,
11455 .dumpit = nl80211_dump_survey,
11456 },
Samuel Ortiz67fbb162009-11-24 23:59:15 +010011457 {
11458 .cmd = NL80211_CMD_SET_PMKSA,
11459 .doit = nl80211_setdel_pmksa,
11460 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011461 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020011462 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020011463 NL80211_FLAG_NEED_RTNL,
Samuel Ortiz67fbb162009-11-24 23:59:15 +010011464 },
11465 {
11466 .cmd = NL80211_CMD_DEL_PMKSA,
11467 .doit = nl80211_setdel_pmksa,
11468 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011469 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020011470 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020011471 NL80211_FLAG_NEED_RTNL,
Samuel Ortiz67fbb162009-11-24 23:59:15 +010011472 },
11473 {
11474 .cmd = NL80211_CMD_FLUSH_PMKSA,
11475 .doit = nl80211_flush_pmksa,
11476 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011477 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020011478 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020011479 NL80211_FLAG_NEED_RTNL,
Samuel Ortiz67fbb162009-11-24 23:59:15 +010011480 },
Jouni Malinen9588bbd2009-12-23 13:15:41 +010011481 {
11482 .cmd = NL80211_CMD_REMAIN_ON_CHANNEL,
11483 .doit = nl80211_remain_on_channel,
11484 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011485 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +020011486 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020011487 NL80211_FLAG_NEED_RTNL,
Jouni Malinen9588bbd2009-12-23 13:15:41 +010011488 },
11489 {
11490 .cmd = NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL,
11491 .doit = nl80211_cancel_remain_on_channel,
11492 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011493 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +020011494 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020011495 NL80211_FLAG_NEED_RTNL,
Jouni Malinen9588bbd2009-12-23 13:15:41 +010011496 },
Jouni Malinen13ae75b2009-12-29 12:59:45 +020011497 {
11498 .cmd = NL80211_CMD_SET_TX_BITRATE_MASK,
11499 .doit = nl80211_set_tx_bitrate_mask,
11500 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011501 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020011502 .internal_flags = NL80211_FLAG_NEED_NETDEV |
11503 NL80211_FLAG_NEED_RTNL,
Jouni Malinen13ae75b2009-12-29 12:59:45 +020011504 },
Jouni Malinen026331c2010-02-15 12:53:10 +020011505 {
Johannes Berg2e161f72010-08-12 15:38:38 +020011506 .cmd = NL80211_CMD_REGISTER_FRAME,
11507 .doit = nl80211_register_mgmt,
Jouni Malinen026331c2010-02-15 12:53:10 +020011508 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011509 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +020011510 .internal_flags = NL80211_FLAG_NEED_WDEV |
Johannes Berg4c476992010-10-04 21:36:35 +020011511 NL80211_FLAG_NEED_RTNL,
Jouni Malinen026331c2010-02-15 12:53:10 +020011512 },
11513 {
Johannes Berg2e161f72010-08-12 15:38:38 +020011514 .cmd = NL80211_CMD_FRAME,
11515 .doit = nl80211_tx_mgmt,
Jouni Malinen026331c2010-02-15 12:53:10 +020011516 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011517 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +020011518 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020011519 NL80211_FLAG_NEED_RTNL,
Jouni Malinen026331c2010-02-15 12:53:10 +020011520 },
Kalle Valoffb9eb32010-02-17 17:58:10 +020011521 {
Johannes Bergf7ca38d2010-11-25 10:02:29 +010011522 .cmd = NL80211_CMD_FRAME_WAIT_CANCEL,
11523 .doit = nl80211_tx_mgmt_cancel_wait,
11524 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011525 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +020011526 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Bergf7ca38d2010-11-25 10:02:29 +010011527 NL80211_FLAG_NEED_RTNL,
11528 },
11529 {
Kalle Valoffb9eb32010-02-17 17:58:10 +020011530 .cmd = NL80211_CMD_SET_POWER_SAVE,
11531 .doit = nl80211_set_power_save,
11532 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011533 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020011534 .internal_flags = NL80211_FLAG_NEED_NETDEV |
11535 NL80211_FLAG_NEED_RTNL,
Kalle Valoffb9eb32010-02-17 17:58:10 +020011536 },
11537 {
11538 .cmd = NL80211_CMD_GET_POWER_SAVE,
11539 .doit = nl80211_get_power_save,
11540 .policy = nl80211_policy,
11541 /* can be retrieved by unprivileged users */
Johannes Berg4c476992010-10-04 21:36:35 +020011542 .internal_flags = NL80211_FLAG_NEED_NETDEV |
11543 NL80211_FLAG_NEED_RTNL,
Kalle Valoffb9eb32010-02-17 17:58:10 +020011544 },
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020011545 {
11546 .cmd = NL80211_CMD_SET_CQM,
11547 .doit = nl80211_set_cqm,
11548 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011549 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020011550 .internal_flags = NL80211_FLAG_NEED_NETDEV |
11551 NL80211_FLAG_NEED_RTNL,
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020011552 },
Johannes Bergf444de02010-05-05 15:25:02 +020011553 {
11554 .cmd = NL80211_CMD_SET_CHANNEL,
11555 .doit = nl80211_set_channel,
11556 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011557 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020011558 .internal_flags = NL80211_FLAG_NEED_NETDEV |
11559 NL80211_FLAG_NEED_RTNL,
Johannes Bergf444de02010-05-05 15:25:02 +020011560 },
Bill Jordane8347eb2010-10-01 13:54:28 -040011561 {
11562 .cmd = NL80211_CMD_SET_WDS_PEER,
11563 .doit = nl80211_set_wds_peer,
11564 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011565 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg43b19952010-10-07 13:10:30 +020011566 .internal_flags = NL80211_FLAG_NEED_NETDEV |
11567 NL80211_FLAG_NEED_RTNL,
Bill Jordane8347eb2010-10-01 13:54:28 -040011568 },
Johannes Berg29cbe682010-12-03 09:20:44 +010011569 {
11570 .cmd = NL80211_CMD_JOIN_MESH,
11571 .doit = nl80211_join_mesh,
11572 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011573 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg29cbe682010-12-03 09:20:44 +010011574 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
11575 NL80211_FLAG_NEED_RTNL,
11576 },
11577 {
11578 .cmd = NL80211_CMD_LEAVE_MESH,
11579 .doit = nl80211_leave_mesh,
11580 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011581 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg29cbe682010-12-03 09:20:44 +010011582 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
11583 NL80211_FLAG_NEED_RTNL,
11584 },
Rostislav Lisovy6e0bd6c2014-11-03 10:33:18 +010011585 {
11586 .cmd = NL80211_CMD_JOIN_OCB,
11587 .doit = nl80211_join_ocb,
11588 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011589 .flags = GENL_UNS_ADMIN_PERM,
Rostislav Lisovy6e0bd6c2014-11-03 10:33:18 +010011590 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
11591 NL80211_FLAG_NEED_RTNL,
11592 },
11593 {
11594 .cmd = NL80211_CMD_LEAVE_OCB,
11595 .doit = nl80211_leave_ocb,
11596 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011597 .flags = GENL_UNS_ADMIN_PERM,
Rostislav Lisovy6e0bd6c2014-11-03 10:33:18 +010011598 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
11599 NL80211_FLAG_NEED_RTNL,
11600 },
Johannes Bergdfb89c52012-06-27 09:23:48 +020011601#ifdef CONFIG_PM
Johannes Bergff1b6e62011-05-04 15:37:28 +020011602 {
11603 .cmd = NL80211_CMD_GET_WOWLAN,
11604 .doit = nl80211_get_wowlan,
11605 .policy = nl80211_policy,
11606 /* can be retrieved by unprivileged users */
11607 .internal_flags = NL80211_FLAG_NEED_WIPHY |
11608 NL80211_FLAG_NEED_RTNL,
11609 },
11610 {
11611 .cmd = NL80211_CMD_SET_WOWLAN,
11612 .doit = nl80211_set_wowlan,
11613 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011614 .flags = GENL_UNS_ADMIN_PERM,
Johannes Bergff1b6e62011-05-04 15:37:28 +020011615 .internal_flags = NL80211_FLAG_NEED_WIPHY |
11616 NL80211_FLAG_NEED_RTNL,
11617 },
Johannes Bergdfb89c52012-06-27 09:23:48 +020011618#endif
Johannes Berge5497d72011-07-05 16:35:40 +020011619 {
11620 .cmd = NL80211_CMD_SET_REKEY_OFFLOAD,
11621 .doit = nl80211_set_rekey_data,
11622 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011623 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berge5497d72011-07-05 16:35:40 +020011624 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg5393b912014-09-10 15:00:16 +030011625 NL80211_FLAG_NEED_RTNL |
11626 NL80211_FLAG_CLEAR_SKB,
Johannes Berge5497d72011-07-05 16:35:40 +020011627 },
Arik Nemtsov109086c2011-09-28 14:12:50 +030011628 {
11629 .cmd = NL80211_CMD_TDLS_MGMT,
11630 .doit = nl80211_tdls_mgmt,
11631 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011632 .flags = GENL_UNS_ADMIN_PERM,
Arik Nemtsov109086c2011-09-28 14:12:50 +030011633 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
11634 NL80211_FLAG_NEED_RTNL,
11635 },
11636 {
11637 .cmd = NL80211_CMD_TDLS_OPER,
11638 .doit = nl80211_tdls_oper,
11639 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011640 .flags = GENL_UNS_ADMIN_PERM,
Arik Nemtsov109086c2011-09-28 14:12:50 +030011641 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
11642 NL80211_FLAG_NEED_RTNL,
11643 },
Johannes Berg28946da2011-11-04 11:18:12 +010011644 {
11645 .cmd = NL80211_CMD_UNEXPECTED_FRAME,
11646 .doit = nl80211_register_unexpected_frame,
11647 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011648 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg28946da2011-11-04 11:18:12 +010011649 .internal_flags = NL80211_FLAG_NEED_NETDEV |
11650 NL80211_FLAG_NEED_RTNL,
11651 },
Johannes Berg7f6cf312011-11-04 11:18:15 +010011652 {
11653 .cmd = NL80211_CMD_PROBE_CLIENT,
11654 .doit = nl80211_probe_client,
11655 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011656 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020011657 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg7f6cf312011-11-04 11:18:15 +010011658 NL80211_FLAG_NEED_RTNL,
11659 },
Johannes Berg5e7602302011-11-04 11:18:17 +010011660 {
11661 .cmd = NL80211_CMD_REGISTER_BEACONS,
11662 .doit = nl80211_register_beacons,
11663 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011664 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg5e7602302011-11-04 11:18:17 +010011665 .internal_flags = NL80211_FLAG_NEED_WIPHY |
11666 NL80211_FLAG_NEED_RTNL,
11667 },
Simon Wunderlich1d9d9212011-11-18 14:20:43 +010011668 {
11669 .cmd = NL80211_CMD_SET_NOACK_MAP,
11670 .doit = nl80211_set_noack_map,
11671 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011672 .flags = GENL_UNS_ADMIN_PERM,
Simon Wunderlich1d9d9212011-11-18 14:20:43 +010011673 .internal_flags = NL80211_FLAG_NEED_NETDEV |
11674 NL80211_FLAG_NEED_RTNL,
11675 },
Johannes Berg98104fde2012-06-16 00:19:54 +020011676 {
11677 .cmd = NL80211_CMD_START_P2P_DEVICE,
11678 .doit = nl80211_start_p2p_device,
11679 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011680 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg98104fde2012-06-16 00:19:54 +020011681 .internal_flags = NL80211_FLAG_NEED_WDEV |
11682 NL80211_FLAG_NEED_RTNL,
11683 },
11684 {
11685 .cmd = NL80211_CMD_STOP_P2P_DEVICE,
11686 .doit = nl80211_stop_p2p_device,
11687 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011688 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg98104fde2012-06-16 00:19:54 +020011689 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
11690 NL80211_FLAG_NEED_RTNL,
11691 },
Antonio Quartullif4e583c2012-11-02 13:27:48 +010011692 {
11693 .cmd = NL80211_CMD_SET_MCAST_RATE,
11694 .doit = nl80211_set_mcast_rate,
11695 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011696 .flags = GENL_UNS_ADMIN_PERM,
Antonio Quartullif4e583c2012-11-02 13:27:48 +010011697 .internal_flags = NL80211_FLAG_NEED_NETDEV |
11698 NL80211_FLAG_NEED_RTNL,
11699 },
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +053011700 {
11701 .cmd = NL80211_CMD_SET_MAC_ACL,
11702 .doit = nl80211_set_mac_acl,
11703 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011704 .flags = GENL_UNS_ADMIN_PERM,
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +053011705 .internal_flags = NL80211_FLAG_NEED_NETDEV |
11706 NL80211_FLAG_NEED_RTNL,
11707 },
Simon Wunderlich04f39042013-02-08 18:16:19 +010011708 {
11709 .cmd = NL80211_CMD_RADAR_DETECT,
11710 .doit = nl80211_start_radar_detection,
11711 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011712 .flags = GENL_UNS_ADMIN_PERM,
Simon Wunderlich04f39042013-02-08 18:16:19 +010011713 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
11714 NL80211_FLAG_NEED_RTNL,
11715 },
Johannes Berg3713b4e2013-02-14 16:19:38 +010011716 {
11717 .cmd = NL80211_CMD_GET_PROTOCOL_FEATURES,
11718 .doit = nl80211_get_protocol_features,
11719 .policy = nl80211_policy,
11720 },
Jouni Malinen355199e2013-02-27 17:14:27 +020011721 {
11722 .cmd = NL80211_CMD_UPDATE_FT_IES,
11723 .doit = nl80211_update_ft_ies,
11724 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011725 .flags = GENL_UNS_ADMIN_PERM,
Jouni Malinen355199e2013-02-27 17:14:27 +020011726 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
11727 NL80211_FLAG_NEED_RTNL,
11728 },
Arend van Spriel5de17982013-04-18 15:49:00 +020011729 {
11730 .cmd = NL80211_CMD_CRIT_PROTOCOL_START,
11731 .doit = nl80211_crit_protocol_start,
11732 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011733 .flags = GENL_UNS_ADMIN_PERM,
Arend van Spriel5de17982013-04-18 15:49:00 +020011734 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
11735 NL80211_FLAG_NEED_RTNL,
11736 },
11737 {
11738 .cmd = NL80211_CMD_CRIT_PROTOCOL_STOP,
11739 .doit = nl80211_crit_protocol_stop,
11740 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011741 .flags = GENL_UNS_ADMIN_PERM,
Arend van Spriel5de17982013-04-18 15:49:00 +020011742 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
11743 NL80211_FLAG_NEED_RTNL,
Amitkumar Karwarbe29b992013-06-28 11:51:26 -070011744 },
11745 {
11746 .cmd = NL80211_CMD_GET_COALESCE,
11747 .doit = nl80211_get_coalesce,
11748 .policy = nl80211_policy,
11749 .internal_flags = NL80211_FLAG_NEED_WIPHY |
11750 NL80211_FLAG_NEED_RTNL,
11751 },
11752 {
11753 .cmd = NL80211_CMD_SET_COALESCE,
11754 .doit = nl80211_set_coalesce,
11755 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011756 .flags = GENL_UNS_ADMIN_PERM,
Amitkumar Karwarbe29b992013-06-28 11:51:26 -070011757 .internal_flags = NL80211_FLAG_NEED_WIPHY |
11758 NL80211_FLAG_NEED_RTNL,
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +020011759 },
11760 {
11761 .cmd = NL80211_CMD_CHANNEL_SWITCH,
11762 .doit = nl80211_channel_switch,
11763 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011764 .flags = GENL_UNS_ADMIN_PERM,
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +020011765 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
11766 NL80211_FLAG_NEED_RTNL,
11767 },
Johannes Bergad7e7182013-11-13 13:37:47 +010011768 {
11769 .cmd = NL80211_CMD_VENDOR,
11770 .doit = nl80211_vendor_cmd,
Johannes Berg7bdbe402015-08-15 22:39:49 +030011771 .dumpit = nl80211_vendor_cmd_dump,
Johannes Bergad7e7182013-11-13 13:37:47 +010011772 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011773 .flags = GENL_UNS_ADMIN_PERM,
Johannes Bergad7e7182013-11-13 13:37:47 +010011774 .internal_flags = NL80211_FLAG_NEED_WIPHY |
11775 NL80211_FLAG_NEED_RTNL,
11776 },
Kyeyoon Parkfa9ffc72013-12-16 23:01:30 -080011777 {
11778 .cmd = NL80211_CMD_SET_QOS_MAP,
11779 .doit = nl80211_set_qos_map,
11780 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011781 .flags = GENL_UNS_ADMIN_PERM,
Kyeyoon Parkfa9ffc72013-12-16 23:01:30 -080011782 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
11783 NL80211_FLAG_NEED_RTNL,
11784 },
Johannes Berg960d01a2014-09-09 22:55:35 +030011785 {
11786 .cmd = NL80211_CMD_ADD_TX_TS,
11787 .doit = nl80211_add_tx_ts,
11788 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011789 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg960d01a2014-09-09 22:55:35 +030011790 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
11791 NL80211_FLAG_NEED_RTNL,
11792 },
11793 {
11794 .cmd = NL80211_CMD_DEL_TX_TS,
11795 .doit = nl80211_del_tx_ts,
11796 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011797 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg960d01a2014-09-09 22:55:35 +030011798 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
11799 NL80211_FLAG_NEED_RTNL,
11800 },
Arik Nemtsov1057d352014-11-19 12:54:26 +020011801 {
11802 .cmd = NL80211_CMD_TDLS_CHANNEL_SWITCH,
11803 .doit = nl80211_tdls_channel_switch,
11804 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011805 .flags = GENL_UNS_ADMIN_PERM,
Arik Nemtsov1057d352014-11-19 12:54:26 +020011806 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
11807 NL80211_FLAG_NEED_RTNL,
11808 },
11809 {
11810 .cmd = NL80211_CMD_TDLS_CANCEL_CHANNEL_SWITCH,
11811 .doit = nl80211_tdls_cancel_channel_switch,
11812 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011813 .flags = GENL_UNS_ADMIN_PERM,
Arik Nemtsov1057d352014-11-19 12:54:26 +020011814 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
11815 NL80211_FLAG_NEED_RTNL,
11816 },
Johannes Berg55682962007-09-20 13:09:35 -040011817};
Jouni Malinen9588bbd2009-12-23 13:15:41 +010011818
Johannes Berg55682962007-09-20 13:09:35 -040011819/* notification functions */
11820
Johannes Berg3bb20552014-05-26 13:52:25 +020011821void nl80211_notify_wiphy(struct cfg80211_registered_device *rdev,
11822 enum nl80211_commands cmd)
Johannes Berg55682962007-09-20 13:09:35 -040011823{
11824 struct sk_buff *msg;
Johannes Berg86e8cf92013-06-19 10:57:22 +020011825 struct nl80211_dump_wiphy_state state = {};
Johannes Berg55682962007-09-20 13:09:35 -040011826
Johannes Berg3bb20552014-05-26 13:52:25 +020011827 WARN_ON(cmd != NL80211_CMD_NEW_WIPHY &&
11828 cmd != NL80211_CMD_DEL_WIPHY);
11829
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -070011830 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -040011831 if (!msg)
11832 return;
11833
Johannes Berg3bb20552014-05-26 13:52:25 +020011834 if (nl80211_send_wiphy(rdev, cmd, msg, 0, 0, 0, &state) < 0) {
Johannes Berg55682962007-09-20 13:09:35 -040011835 nlmsg_free(msg);
11836 return;
11837 }
11838
Johannes Berg68eb5502013-11-19 15:19:38 +010011839 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011840 NL80211_MCGRP_CONFIG, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -040011841}
11842
Denis Kenzior896ff062016-08-03 16:58:33 -050011843void nl80211_notify_iface(struct cfg80211_registered_device *rdev,
11844 struct wireless_dev *wdev,
11845 enum nl80211_commands cmd)
11846{
11847 struct sk_buff *msg;
11848
11849 WARN_ON(cmd != NL80211_CMD_NEW_INTERFACE &&
11850 cmd != NL80211_CMD_DEL_INTERFACE);
11851
11852 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
11853 if (!msg)
11854 return;
11855
11856 if (nl80211_send_iface(msg, 0, 0, 0, rdev, wdev,
11857 cmd == NL80211_CMD_DEL_INTERFACE) < 0) {
11858 nlmsg_free(msg);
11859 return;
11860 }
11861
11862 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
11863 NL80211_MCGRP_CONFIG, GFP_KERNEL);
11864}
11865
Johannes Berg362a4152009-05-24 16:43:15 +020011866static int nl80211_add_scan_req(struct sk_buff *msg,
11867 struct cfg80211_registered_device *rdev)
11868{
11869 struct cfg80211_scan_request *req = rdev->scan_req;
11870 struct nlattr *nest;
11871 int i;
11872
11873 if (WARN_ON(!req))
11874 return 0;
11875
11876 nest = nla_nest_start(msg, NL80211_ATTR_SCAN_SSIDS);
11877 if (!nest)
11878 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -040011879 for (i = 0; i < req->n_ssids; i++) {
11880 if (nla_put(msg, i, req->ssids[i].ssid_len, req->ssids[i].ssid))
11881 goto nla_put_failure;
11882 }
Johannes Berg362a4152009-05-24 16:43:15 +020011883 nla_nest_end(msg, nest);
11884
11885 nest = nla_nest_start(msg, NL80211_ATTR_SCAN_FREQUENCIES);
11886 if (!nest)
11887 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -040011888 for (i = 0; i < req->n_channels; i++) {
11889 if (nla_put_u32(msg, i, req->channels[i]->center_freq))
11890 goto nla_put_failure;
11891 }
Johannes Berg362a4152009-05-24 16:43:15 +020011892 nla_nest_end(msg, nest);
11893
David S. Miller9360ffd2012-03-29 04:41:26 -040011894 if (req->ie &&
11895 nla_put(msg, NL80211_ATTR_IE, req->ie_len, req->ie))
11896 goto nla_put_failure;
Johannes Berg362a4152009-05-24 16:43:15 +020011897
Johannes Bergae917c92013-10-25 11:05:22 +020011898 if (req->flags &&
11899 nla_put_u32(msg, NL80211_ATTR_SCAN_FLAGS, req->flags))
11900 goto nla_put_failure;
Sam Lefflered4737712012-10-11 21:03:31 -070011901
Avraham Stern1d762502016-07-05 17:10:13 +030011902 if (req->info.scan_start_tsf &&
11903 (nla_put_u64_64bit(msg, NL80211_ATTR_SCAN_START_TIME_TSF,
11904 req->info.scan_start_tsf, NL80211_BSS_PAD) ||
11905 nla_put(msg, NL80211_ATTR_SCAN_START_TIME_TSF_BSSID, ETH_ALEN,
11906 req->info.tsf_bssid)))
11907 goto nla_put_failure;
11908
Johannes Berg362a4152009-05-24 16:43:15 +020011909 return 0;
11910 nla_put_failure:
11911 return -ENOBUFS;
11912}
11913
Johannes Berga538e2d2009-06-16 19:56:42 +020011914static int nl80211_send_scan_msg(struct sk_buff *msg,
11915 struct cfg80211_registered_device *rdev,
Johannes Bergfd014282012-06-18 19:17:03 +020011916 struct wireless_dev *wdev,
Eric W. Biederman15e47302012-09-07 20:12:54 +000011917 u32 portid, u32 seq, int flags,
Johannes Berga538e2d2009-06-16 19:56:42 +020011918 u32 cmd)
Johannes Berg2a519312009-02-10 21:25:55 +010011919{
11920 void *hdr;
11921
Eric W. Biederman15e47302012-09-07 20:12:54 +000011922 hdr = nl80211hdr_put(msg, portid, seq, flags, cmd);
Johannes Berg2a519312009-02-10 21:25:55 +010011923 if (!hdr)
11924 return -1;
11925
David S. Miller9360ffd2012-03-29 04:41:26 -040011926 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Bergfd014282012-06-18 19:17:03 +020011927 (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
11928 wdev->netdev->ifindex)) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020011929 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
11930 NL80211_ATTR_PAD))
David S. Miller9360ffd2012-03-29 04:41:26 -040011931 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +010011932
Johannes Berg362a4152009-05-24 16:43:15 +020011933 /* ignore errors and send incomplete event anyway */
11934 nl80211_add_scan_req(msg, rdev);
Johannes Berg2a519312009-02-10 21:25:55 +010011935
Johannes Berg053c0952015-01-16 22:09:00 +010011936 genlmsg_end(msg, hdr);
11937 return 0;
Johannes Berg2a519312009-02-10 21:25:55 +010011938
11939 nla_put_failure:
11940 genlmsg_cancel(msg, hdr);
11941 return -EMSGSIZE;
11942}
11943
Luciano Coelho807f8a82011-05-11 17:09:35 +030011944static int
11945nl80211_send_sched_scan_msg(struct sk_buff *msg,
11946 struct cfg80211_registered_device *rdev,
11947 struct net_device *netdev,
Eric W. Biederman15e47302012-09-07 20:12:54 +000011948 u32 portid, u32 seq, int flags, u32 cmd)
Luciano Coelho807f8a82011-05-11 17:09:35 +030011949{
11950 void *hdr;
11951
Eric W. Biederman15e47302012-09-07 20:12:54 +000011952 hdr = nl80211hdr_put(msg, portid, seq, flags, cmd);
Luciano Coelho807f8a82011-05-11 17:09:35 +030011953 if (!hdr)
11954 return -1;
11955
David S. Miller9360ffd2012-03-29 04:41:26 -040011956 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
11957 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex))
11958 goto nla_put_failure;
Luciano Coelho807f8a82011-05-11 17:09:35 +030011959
Johannes Berg053c0952015-01-16 22:09:00 +010011960 genlmsg_end(msg, hdr);
11961 return 0;
Luciano Coelho807f8a82011-05-11 17:09:35 +030011962
11963 nla_put_failure:
11964 genlmsg_cancel(msg, hdr);
11965 return -EMSGSIZE;
11966}
11967
Johannes Berga538e2d2009-06-16 19:56:42 +020011968void nl80211_send_scan_start(struct cfg80211_registered_device *rdev,
Johannes Bergfd014282012-06-18 19:17:03 +020011969 struct wireless_dev *wdev)
Johannes Berga538e2d2009-06-16 19:56:42 +020011970{
11971 struct sk_buff *msg;
11972
Thomas Graf58050fc2012-06-28 03:57:45 +000011973 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berga538e2d2009-06-16 19:56:42 +020011974 if (!msg)
11975 return;
11976
Johannes Bergfd014282012-06-18 19:17:03 +020011977 if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0,
Johannes Berga538e2d2009-06-16 19:56:42 +020011978 NL80211_CMD_TRIGGER_SCAN) < 0) {
11979 nlmsg_free(msg);
11980 return;
11981 }
11982
Johannes Berg68eb5502013-11-19 15:19:38 +010011983 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011984 NL80211_MCGRP_SCAN, GFP_KERNEL);
Johannes Berga538e2d2009-06-16 19:56:42 +020011985}
11986
Johannes Bergf9d15d12014-01-22 11:14:19 +020011987struct sk_buff *nl80211_build_scan_msg(struct cfg80211_registered_device *rdev,
11988 struct wireless_dev *wdev, bool aborted)
Johannes Berg2a519312009-02-10 21:25:55 +010011989{
11990 struct sk_buff *msg;
11991
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -070011992 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg2a519312009-02-10 21:25:55 +010011993 if (!msg)
Johannes Bergf9d15d12014-01-22 11:14:19 +020011994 return NULL;
Johannes Berg2a519312009-02-10 21:25:55 +010011995
Johannes Bergfd014282012-06-18 19:17:03 +020011996 if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0,
Johannes Bergf9d15d12014-01-22 11:14:19 +020011997 aborted ? NL80211_CMD_SCAN_ABORTED :
11998 NL80211_CMD_NEW_SCAN_RESULTS) < 0) {
Johannes Berg2a519312009-02-10 21:25:55 +010011999 nlmsg_free(msg);
Johannes Bergf9d15d12014-01-22 11:14:19 +020012000 return NULL;
Johannes Berg2a519312009-02-10 21:25:55 +010012001 }
12002
Johannes Bergf9d15d12014-01-22 11:14:19 +020012003 return msg;
Johannes Berg2a519312009-02-10 21:25:55 +010012004}
12005
Johannes Bergf9d15d12014-01-22 11:14:19 +020012006void nl80211_send_scan_result(struct cfg80211_registered_device *rdev,
12007 struct sk_buff *msg)
Johannes Berg2a519312009-02-10 21:25:55 +010012008{
Johannes Berg2a519312009-02-10 21:25:55 +010012009 if (!msg)
12010 return;
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 Berg2a519312009-02-10 21:25:55 +010012014}
12015
Luciano Coelho807f8a82011-05-11 17:09:35 +030012016void nl80211_send_sched_scan_results(struct cfg80211_registered_device *rdev,
12017 struct net_device *netdev)
12018{
12019 struct sk_buff *msg;
12020
12021 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
12022 if (!msg)
12023 return;
12024
12025 if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0,
12026 NL80211_CMD_SCHED_SCAN_RESULTS) < 0) {
12027 nlmsg_free(msg);
12028 return;
12029 }
12030
Johannes Berg68eb5502013-11-19 15:19:38 +010012031 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010012032 NL80211_MCGRP_SCAN, GFP_KERNEL);
Luciano Coelho807f8a82011-05-11 17:09:35 +030012033}
12034
12035void nl80211_send_sched_scan(struct cfg80211_registered_device *rdev,
12036 struct net_device *netdev, u32 cmd)
12037{
12038 struct sk_buff *msg;
12039
Thomas Graf58050fc2012-06-28 03:57:45 +000012040 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Luciano Coelho807f8a82011-05-11 17:09:35 +030012041 if (!msg)
12042 return;
12043
12044 if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0, cmd) < 0) {
12045 nlmsg_free(msg);
12046 return;
12047 }
12048
Johannes Berg68eb5502013-11-19 15:19:38 +010012049 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010012050 NL80211_MCGRP_SCAN, GFP_KERNEL);
Luciano Coelho807f8a82011-05-11 17:09:35 +030012051}
12052
Jonathan Doronb0d7aa52014-12-15 19:26:00 +020012053static bool nl80211_reg_change_event_fill(struct sk_buff *msg,
12054 struct regulatory_request *request)
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040012055{
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040012056 /* Userspace can always count this one always being set */
David S. Miller9360ffd2012-03-29 04:41:26 -040012057 if (nla_put_u8(msg, NL80211_ATTR_REG_INITIATOR, request->initiator))
12058 goto nla_put_failure;
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040012059
David S. Miller9360ffd2012-03-29 04:41:26 -040012060 if (request->alpha2[0] == '0' && request->alpha2[1] == '0') {
12061 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
12062 NL80211_REGDOM_TYPE_WORLD))
12063 goto nla_put_failure;
12064 } else if (request->alpha2[0] == '9' && request->alpha2[1] == '9') {
12065 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
12066 NL80211_REGDOM_TYPE_CUSTOM_WORLD))
12067 goto nla_put_failure;
12068 } else if ((request->alpha2[0] == '9' && request->alpha2[1] == '8') ||
12069 request->intersect) {
12070 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
12071 NL80211_REGDOM_TYPE_INTERSECTION))
12072 goto nla_put_failure;
12073 } else {
12074 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
12075 NL80211_REGDOM_TYPE_COUNTRY) ||
12076 nla_put_string(msg, NL80211_ATTR_REG_ALPHA2,
12077 request->alpha2))
12078 goto nla_put_failure;
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040012079 }
12080
Arik Nemtsovad30ca22014-12-15 19:25:59 +020012081 if (request->wiphy_idx != WIPHY_IDX_INVALID) {
12082 struct wiphy *wiphy = wiphy_idx_to_wiphy(request->wiphy_idx);
12083
12084 if (wiphy &&
12085 nla_put_u32(msg, NL80211_ATTR_WIPHY, request->wiphy_idx))
12086 goto nla_put_failure;
Arik Nemtsov1bdd7162014-12-15 19:26:01 +020012087
12088 if (wiphy &&
12089 wiphy->regulatory_flags & REGULATORY_WIPHY_SELF_MANAGED &&
12090 nla_put_flag(msg, NL80211_ATTR_WIPHY_SELF_MANAGED_REG))
12091 goto nla_put_failure;
Arik Nemtsovad30ca22014-12-15 19:25:59 +020012092 }
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040012093
Jonathan Doronb0d7aa52014-12-15 19:26:00 +020012094 return true;
12095
12096nla_put_failure:
12097 return false;
12098}
12099
12100/*
12101 * This can happen on global regulatory changes or device specific settings
12102 * based on custom regulatory domains.
12103 */
12104void nl80211_common_reg_change_event(enum nl80211_commands cmd_id,
12105 struct regulatory_request *request)
12106{
12107 struct sk_buff *msg;
12108 void *hdr;
12109
12110 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
12111 if (!msg)
12112 return;
12113
12114 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd_id);
12115 if (!hdr) {
12116 nlmsg_free(msg);
12117 return;
12118 }
12119
12120 if (nl80211_reg_change_event_fill(msg, request) == false)
12121 goto nla_put_failure;
12122
Johannes Berg3b7b72e2011-10-22 19:05:51 +020012123 genlmsg_end(msg, hdr);
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040012124
Johannes Bergbc43b282009-07-25 10:54:13 +020012125 rcu_read_lock();
Johannes Berg68eb5502013-11-19 15:19:38 +010012126 genlmsg_multicast_allns(&nl80211_fam, msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010012127 NL80211_MCGRP_REGULATORY, GFP_ATOMIC);
Johannes Bergbc43b282009-07-25 10:54:13 +020012128 rcu_read_unlock();
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040012129
12130 return;
12131
12132nla_put_failure:
12133 genlmsg_cancel(msg, hdr);
12134 nlmsg_free(msg);
12135}
12136
Jouni Malinen6039f6d2009-03-19 13:39:21 +020012137static void nl80211_send_mlme_event(struct cfg80211_registered_device *rdev,
12138 struct net_device *netdev,
12139 const u8 *buf, size_t len,
Eliad Pellerb0b6aa22014-09-09 17:09:45 +030012140 enum nl80211_commands cmd, gfp_t gfp,
12141 int uapsd_queues)
Jouni Malinen6039f6d2009-03-19 13:39:21 +020012142{
12143 struct sk_buff *msg;
12144 void *hdr;
12145
Johannes Berge6d6e342009-07-01 21:26:47 +020012146 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020012147 if (!msg)
12148 return;
12149
12150 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
12151 if (!hdr) {
12152 nlmsg_free(msg);
12153 return;
12154 }
12155
David S. Miller9360ffd2012-03-29 04:41:26 -040012156 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
12157 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
12158 nla_put(msg, NL80211_ATTR_FRAME, len, buf))
12159 goto nla_put_failure;
Jouni Malinen6039f6d2009-03-19 13:39:21 +020012160
Eliad Pellerb0b6aa22014-09-09 17:09:45 +030012161 if (uapsd_queues >= 0) {
12162 struct nlattr *nla_wmm =
12163 nla_nest_start(msg, NL80211_ATTR_STA_WME);
12164 if (!nla_wmm)
12165 goto nla_put_failure;
12166
12167 if (nla_put_u8(msg, NL80211_STA_WME_UAPSD_QUEUES,
12168 uapsd_queues))
12169 goto nla_put_failure;
12170
12171 nla_nest_end(msg, nla_wmm);
12172 }
12173
Johannes Berg3b7b72e2011-10-22 19:05:51 +020012174 genlmsg_end(msg, hdr);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020012175
Johannes Berg68eb5502013-11-19 15:19:38 +010012176 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010012177 NL80211_MCGRP_MLME, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020012178 return;
12179
12180 nla_put_failure:
12181 genlmsg_cancel(msg, hdr);
12182 nlmsg_free(msg);
12183}
12184
12185void nl80211_send_rx_auth(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +020012186 struct net_device *netdev, const u8 *buf,
12187 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +020012188{
12189 nl80211_send_mlme_event(rdev, netdev, buf, len,
Eliad Pellerb0b6aa22014-09-09 17:09:45 +030012190 NL80211_CMD_AUTHENTICATE, gfp, -1);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020012191}
12192
12193void nl80211_send_rx_assoc(struct cfg80211_registered_device *rdev,
12194 struct net_device *netdev, const u8 *buf,
Eliad Pellerb0b6aa22014-09-09 17:09:45 +030012195 size_t len, gfp_t gfp, int uapsd_queues)
Jouni Malinen6039f6d2009-03-19 13:39:21 +020012196{
Johannes Berge6d6e342009-07-01 21:26:47 +020012197 nl80211_send_mlme_event(rdev, netdev, buf, len,
Eliad Pellerb0b6aa22014-09-09 17:09:45 +030012198 NL80211_CMD_ASSOCIATE, gfp, uapsd_queues);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020012199}
12200
Jouni Malinen53b46b82009-03-27 20:53:56 +020012201void nl80211_send_deauth(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +020012202 struct net_device *netdev, const u8 *buf,
12203 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +020012204{
12205 nl80211_send_mlme_event(rdev, netdev, buf, len,
Eliad Pellerb0b6aa22014-09-09 17:09:45 +030012206 NL80211_CMD_DEAUTHENTICATE, gfp, -1);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020012207}
12208
Jouni Malinen53b46b82009-03-27 20:53:56 +020012209void nl80211_send_disassoc(struct cfg80211_registered_device *rdev,
12210 struct net_device *netdev, const u8 *buf,
Johannes Berge6d6e342009-07-01 21:26:47 +020012211 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +020012212{
12213 nl80211_send_mlme_event(rdev, netdev, buf, len,
Eliad Pellerb0b6aa22014-09-09 17:09:45 +030012214 NL80211_CMD_DISASSOCIATE, gfp, -1);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020012215}
12216
Johannes Berg6ff57cf2013-05-16 00:55:00 +020012217void cfg80211_rx_unprot_mlme_mgmt(struct net_device *dev, const u8 *buf,
12218 size_t len)
Jouni Malinencf4e5942010-12-16 00:52:40 +020012219{
Johannes Berg947add32013-02-22 22:05:20 +010012220 struct wireless_dev *wdev = dev->ieee80211_ptr;
12221 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080012222 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg6ff57cf2013-05-16 00:55:00 +020012223 const struct ieee80211_mgmt *mgmt = (void *)buf;
12224 u32 cmd;
Jouni Malinencf4e5942010-12-16 00:52:40 +020012225
Johannes Berg6ff57cf2013-05-16 00:55:00 +020012226 if (WARN_ON(len < 2))
12227 return;
12228
12229 if (ieee80211_is_deauth(mgmt->frame_control))
12230 cmd = NL80211_CMD_UNPROT_DEAUTHENTICATE;
12231 else
12232 cmd = NL80211_CMD_UNPROT_DISASSOCIATE;
12233
12234 trace_cfg80211_rx_unprot_mlme_mgmt(dev, buf, len);
Eliad Pellerb0b6aa22014-09-09 17:09:45 +030012235 nl80211_send_mlme_event(rdev, dev, buf, len, cmd, GFP_ATOMIC, -1);
Jouni Malinencf4e5942010-12-16 00:52:40 +020012236}
Johannes Berg6ff57cf2013-05-16 00:55:00 +020012237EXPORT_SYMBOL(cfg80211_rx_unprot_mlme_mgmt);
Jouni Malinencf4e5942010-12-16 00:52:40 +020012238
Luis R. Rodriguez1b06bb42009-05-02 00:34:48 -040012239static void nl80211_send_mlme_timeout(struct cfg80211_registered_device *rdev,
12240 struct net_device *netdev, int cmd,
Johannes Berge6d6e342009-07-01 21:26:47 +020012241 const u8 *addr, gfp_t gfp)
Jouni Malinen1965c852009-04-22 21:38:25 +030012242{
12243 struct sk_buff *msg;
12244 void *hdr;
12245
Johannes Berge6d6e342009-07-01 21:26:47 +020012246 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +030012247 if (!msg)
12248 return;
12249
12250 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
12251 if (!hdr) {
12252 nlmsg_free(msg);
12253 return;
12254 }
12255
David S. Miller9360ffd2012-03-29 04:41:26 -040012256 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
12257 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
12258 nla_put_flag(msg, NL80211_ATTR_TIMED_OUT) ||
12259 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr))
12260 goto nla_put_failure;
Jouni Malinen1965c852009-04-22 21:38:25 +030012261
Johannes Berg3b7b72e2011-10-22 19:05:51 +020012262 genlmsg_end(msg, hdr);
Jouni Malinen1965c852009-04-22 21:38:25 +030012263
Johannes Berg68eb5502013-11-19 15:19:38 +010012264 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010012265 NL80211_MCGRP_MLME, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +030012266 return;
12267
12268 nla_put_failure:
12269 genlmsg_cancel(msg, hdr);
12270 nlmsg_free(msg);
12271}
12272
12273void nl80211_send_auth_timeout(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +020012274 struct net_device *netdev, const u8 *addr,
12275 gfp_t gfp)
Jouni Malinen1965c852009-04-22 21:38:25 +030012276{
12277 nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_AUTHENTICATE,
Johannes Berge6d6e342009-07-01 21:26:47 +020012278 addr, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +030012279}
12280
12281void nl80211_send_assoc_timeout(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +020012282 struct net_device *netdev, const u8 *addr,
12283 gfp_t gfp)
Jouni Malinen1965c852009-04-22 21:38:25 +030012284{
Johannes Berge6d6e342009-07-01 21:26:47 +020012285 nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_ASSOCIATE,
12286 addr, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +030012287}
12288
Samuel Ortizb23aa672009-07-01 21:26:54 +020012289void nl80211_send_connect_result(struct cfg80211_registered_device *rdev,
12290 struct net_device *netdev, const u8 *bssid,
12291 const u8 *req_ie, size_t req_ie_len,
12292 const u8 *resp_ie, size_t resp_ie_len,
Jouni Malinenbf1ecd22016-05-31 00:16:50 +030012293 int status, gfp_t gfp)
Samuel Ortizb23aa672009-07-01 21:26:54 +020012294{
12295 struct sk_buff *msg;
12296 void *hdr;
12297
Thomas Graf58050fc2012-06-28 03:57:45 +000012298 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +020012299 if (!msg)
12300 return;
12301
12302 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONNECT);
12303 if (!hdr) {
12304 nlmsg_free(msg);
12305 return;
12306 }
12307
David S. Miller9360ffd2012-03-29 04:41:26 -040012308 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
12309 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
12310 (bssid && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) ||
Jouni Malinenbf1ecd22016-05-31 00:16:50 +030012311 nla_put_u16(msg, NL80211_ATTR_STATUS_CODE,
12312 status < 0 ? WLAN_STATUS_UNSPECIFIED_FAILURE :
12313 status) ||
12314 (status < 0 && nla_put_flag(msg, NL80211_ATTR_TIMED_OUT)) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040012315 (req_ie &&
12316 nla_put(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie)) ||
12317 (resp_ie &&
12318 nla_put(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie)))
12319 goto nla_put_failure;
Samuel Ortizb23aa672009-07-01 21:26:54 +020012320
Johannes Berg3b7b72e2011-10-22 19:05:51 +020012321 genlmsg_end(msg, hdr);
Samuel Ortizb23aa672009-07-01 21:26:54 +020012322
Johannes Berg68eb5502013-11-19 15:19:38 +010012323 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010012324 NL80211_MCGRP_MLME, gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +020012325 return;
12326
12327 nla_put_failure:
12328 genlmsg_cancel(msg, hdr);
12329 nlmsg_free(msg);
Samuel Ortizb23aa672009-07-01 21:26:54 +020012330}
12331
12332void nl80211_send_roamed(struct cfg80211_registered_device *rdev,
12333 struct net_device *netdev, const u8 *bssid,
12334 const u8 *req_ie, size_t req_ie_len,
12335 const u8 *resp_ie, size_t resp_ie_len, gfp_t gfp)
12336{
12337 struct sk_buff *msg;
12338 void *hdr;
12339
Thomas Graf58050fc2012-06-28 03:57:45 +000012340 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +020012341 if (!msg)
12342 return;
12343
12344 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_ROAM);
12345 if (!hdr) {
12346 nlmsg_free(msg);
12347 return;
12348 }
12349
David S. Miller9360ffd2012-03-29 04:41:26 -040012350 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
12351 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
12352 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid) ||
12353 (req_ie &&
12354 nla_put(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie)) ||
12355 (resp_ie &&
12356 nla_put(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie)))
12357 goto nla_put_failure;
Samuel Ortizb23aa672009-07-01 21:26:54 +020012358
Johannes Berg3b7b72e2011-10-22 19:05:51 +020012359 genlmsg_end(msg, hdr);
Samuel Ortizb23aa672009-07-01 21:26:54 +020012360
Johannes Berg68eb5502013-11-19 15:19:38 +010012361 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010012362 NL80211_MCGRP_MLME, gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +020012363 return;
12364
12365 nla_put_failure:
12366 genlmsg_cancel(msg, hdr);
12367 nlmsg_free(msg);
Samuel Ortizb23aa672009-07-01 21:26:54 +020012368}
12369
12370void nl80211_send_disconnected(struct cfg80211_registered_device *rdev,
12371 struct net_device *netdev, u16 reason,
Johannes Berg667503dd2009-07-07 03:56:11 +020012372 const u8 *ie, size_t ie_len, bool from_ap)
Samuel Ortizb23aa672009-07-01 21:26:54 +020012373{
12374 struct sk_buff *msg;
12375 void *hdr;
12376
Thomas Graf58050fc2012-06-28 03:57:45 +000012377 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Samuel Ortizb23aa672009-07-01 21:26:54 +020012378 if (!msg)
12379 return;
12380
12381 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DISCONNECT);
12382 if (!hdr) {
12383 nlmsg_free(msg);
12384 return;
12385 }
12386
David S. Miller9360ffd2012-03-29 04:41:26 -040012387 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
12388 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
12389 (from_ap && reason &&
12390 nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason)) ||
12391 (from_ap &&
12392 nla_put_flag(msg, NL80211_ATTR_DISCONNECTED_BY_AP)) ||
12393 (ie && nla_put(msg, NL80211_ATTR_IE, ie_len, ie)))
12394 goto nla_put_failure;
Samuel Ortizb23aa672009-07-01 21:26:54 +020012395
Johannes Berg3b7b72e2011-10-22 19:05:51 +020012396 genlmsg_end(msg, hdr);
Samuel Ortizb23aa672009-07-01 21:26:54 +020012397
Johannes Berg68eb5502013-11-19 15:19:38 +010012398 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010012399 NL80211_MCGRP_MLME, GFP_KERNEL);
Samuel Ortizb23aa672009-07-01 21:26:54 +020012400 return;
12401
12402 nla_put_failure:
12403 genlmsg_cancel(msg, hdr);
12404 nlmsg_free(msg);
Samuel Ortizb23aa672009-07-01 21:26:54 +020012405}
12406
Johannes Berg04a773a2009-04-19 21:24:32 +020012407void nl80211_send_ibss_bssid(struct cfg80211_registered_device *rdev,
12408 struct net_device *netdev, const u8 *bssid,
12409 gfp_t gfp)
12410{
12411 struct sk_buff *msg;
12412 void *hdr;
12413
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -070012414 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Johannes Berg04a773a2009-04-19 21:24:32 +020012415 if (!msg)
12416 return;
12417
12418 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_JOIN_IBSS);
12419 if (!hdr) {
12420 nlmsg_free(msg);
12421 return;
12422 }
12423
David S. Miller9360ffd2012-03-29 04:41:26 -040012424 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
12425 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
12426 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid))
12427 goto nla_put_failure;
Johannes Berg04a773a2009-04-19 21:24:32 +020012428
Johannes Berg3b7b72e2011-10-22 19:05:51 +020012429 genlmsg_end(msg, hdr);
Johannes Berg04a773a2009-04-19 21:24:32 +020012430
Johannes Berg68eb5502013-11-19 15:19:38 +010012431 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010012432 NL80211_MCGRP_MLME, gfp);
Johannes Berg04a773a2009-04-19 21:24:32 +020012433 return;
12434
12435 nla_put_failure:
12436 genlmsg_cancel(msg, hdr);
12437 nlmsg_free(msg);
12438}
12439
Johannes Berg947add32013-02-22 22:05:20 +010012440void cfg80211_notify_new_peer_candidate(struct net_device *dev, const u8 *addr,
12441 const u8* ie, u8 ie_len, gfp_t gfp)
Javier Cardonac93b5e72011-04-07 15:08:34 -070012442{
Johannes Berg947add32013-02-22 22:05:20 +010012443 struct wireless_dev *wdev = dev->ieee80211_ptr;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080012444 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Javier Cardonac93b5e72011-04-07 15:08:34 -070012445 struct sk_buff *msg;
12446 void *hdr;
12447
Johannes Berg947add32013-02-22 22:05:20 +010012448 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_MESH_POINT))
12449 return;
12450
12451 trace_cfg80211_notify_new_peer_candidate(dev, addr);
12452
Javier Cardonac93b5e72011-04-07 15:08:34 -070012453 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
12454 if (!msg)
12455 return;
12456
12457 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NEW_PEER_CANDIDATE);
12458 if (!hdr) {
12459 nlmsg_free(msg);
12460 return;
12461 }
12462
David S. Miller9360ffd2012-03-29 04:41:26 -040012463 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg947add32013-02-22 22:05:20 +010012464 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
12465 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040012466 (ie_len && ie &&
12467 nla_put(msg, NL80211_ATTR_IE, ie_len , ie)))
12468 goto nla_put_failure;
Javier Cardonac93b5e72011-04-07 15:08:34 -070012469
Johannes Berg3b7b72e2011-10-22 19:05:51 +020012470 genlmsg_end(msg, hdr);
Javier Cardonac93b5e72011-04-07 15:08:34 -070012471
Johannes Berg68eb5502013-11-19 15:19:38 +010012472 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010012473 NL80211_MCGRP_MLME, gfp);
Javier Cardonac93b5e72011-04-07 15:08:34 -070012474 return;
12475
12476 nla_put_failure:
12477 genlmsg_cancel(msg, hdr);
12478 nlmsg_free(msg);
12479}
Johannes Berg947add32013-02-22 22:05:20 +010012480EXPORT_SYMBOL(cfg80211_notify_new_peer_candidate);
Javier Cardonac93b5e72011-04-07 15:08:34 -070012481
Jouni Malinena3b8b052009-03-27 21:59:49 +020012482void nl80211_michael_mic_failure(struct cfg80211_registered_device *rdev,
12483 struct net_device *netdev, const u8 *addr,
12484 enum nl80211_key_type key_type, int key_id,
Johannes Berge6d6e342009-07-01 21:26:47 +020012485 const u8 *tsc, gfp_t gfp)
Jouni Malinena3b8b052009-03-27 21:59:49 +020012486{
12487 struct sk_buff *msg;
12488 void *hdr;
12489
Johannes Berge6d6e342009-07-01 21:26:47 +020012490 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinena3b8b052009-03-27 21:59:49 +020012491 if (!msg)
12492 return;
12493
12494 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_MICHAEL_MIC_FAILURE);
12495 if (!hdr) {
12496 nlmsg_free(msg);
12497 return;
12498 }
12499
David S. Miller9360ffd2012-03-29 04:41:26 -040012500 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
12501 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
12502 (addr && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) ||
12503 nla_put_u32(msg, NL80211_ATTR_KEY_TYPE, key_type) ||
12504 (key_id != -1 &&
12505 nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_id)) ||
12506 (tsc && nla_put(msg, NL80211_ATTR_KEY_SEQ, 6, tsc)))
12507 goto nla_put_failure;
Jouni Malinena3b8b052009-03-27 21:59:49 +020012508
Johannes Berg3b7b72e2011-10-22 19:05:51 +020012509 genlmsg_end(msg, hdr);
Jouni Malinena3b8b052009-03-27 21:59:49 +020012510
Johannes Berg68eb5502013-11-19 15:19:38 +010012511 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010012512 NL80211_MCGRP_MLME, gfp);
Jouni Malinena3b8b052009-03-27 21:59:49 +020012513 return;
12514
12515 nla_put_failure:
12516 genlmsg_cancel(msg, hdr);
12517 nlmsg_free(msg);
12518}
12519
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040012520void nl80211_send_beacon_hint_event(struct wiphy *wiphy,
12521 struct ieee80211_channel *channel_before,
12522 struct ieee80211_channel *channel_after)
12523{
12524 struct sk_buff *msg;
12525 void *hdr;
12526 struct nlattr *nl_freq;
12527
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -070012528 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_ATOMIC);
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040012529 if (!msg)
12530 return;
12531
12532 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_BEACON_HINT);
12533 if (!hdr) {
12534 nlmsg_free(msg);
12535 return;
12536 }
12537
12538 /*
12539 * Since we are applying the beacon hint to a wiphy we know its
12540 * wiphy_idx is valid
12541 */
David S. Miller9360ffd2012-03-29 04:41:26 -040012542 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy)))
12543 goto nla_put_failure;
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040012544
12545 /* Before */
12546 nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_BEFORE);
12547 if (!nl_freq)
12548 goto nla_put_failure;
Johannes Bergcdc89b92013-02-18 23:54:36 +010012549 if (nl80211_msg_put_channel(msg, channel_before, false))
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040012550 goto nla_put_failure;
12551 nla_nest_end(msg, nl_freq);
12552
12553 /* After */
12554 nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_AFTER);
12555 if (!nl_freq)
12556 goto nla_put_failure;
Johannes Bergcdc89b92013-02-18 23:54:36 +010012557 if (nl80211_msg_put_channel(msg, channel_after, false))
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040012558 goto nla_put_failure;
12559 nla_nest_end(msg, nl_freq);
12560
Johannes Berg3b7b72e2011-10-22 19:05:51 +020012561 genlmsg_end(msg, hdr);
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040012562
Johannes Berg463d0182009-07-14 00:33:35 +020012563 rcu_read_lock();
Johannes Berg68eb5502013-11-19 15:19:38 +010012564 genlmsg_multicast_allns(&nl80211_fam, msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010012565 NL80211_MCGRP_REGULATORY, GFP_ATOMIC);
Johannes Berg463d0182009-07-14 00:33:35 +020012566 rcu_read_unlock();
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040012567
12568 return;
12569
12570nla_put_failure:
12571 genlmsg_cancel(msg, hdr);
12572 nlmsg_free(msg);
12573}
12574
Jouni Malinen9588bbd2009-12-23 13:15:41 +010012575static void nl80211_send_remain_on_chan_event(
12576 int cmd, struct cfg80211_registered_device *rdev,
Johannes Berg71bbc992012-06-15 15:30:18 +020012577 struct wireless_dev *wdev, u64 cookie,
Jouni Malinen9588bbd2009-12-23 13:15:41 +010012578 struct ieee80211_channel *chan,
Jouni Malinen9588bbd2009-12-23 13:15:41 +010012579 unsigned int duration, gfp_t gfp)
12580{
12581 struct sk_buff *msg;
12582 void *hdr;
12583
12584 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
12585 if (!msg)
12586 return;
12587
12588 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
12589 if (!hdr) {
12590 nlmsg_free(msg);
12591 return;
12592 }
12593
David S. Miller9360ffd2012-03-29 04:41:26 -040012594 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg71bbc992012-06-15 15:30:18 +020012595 (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
12596 wdev->netdev->ifindex)) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020012597 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
12598 NL80211_ATTR_PAD) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040012599 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, chan->center_freq) ||
Johannes Berg42d97a52012-11-08 18:31:02 +010012600 nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE,
12601 NL80211_CHAN_NO_HT) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020012602 nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie,
12603 NL80211_ATTR_PAD))
David S. Miller9360ffd2012-03-29 04:41:26 -040012604 goto nla_put_failure;
Jouni Malinen9588bbd2009-12-23 13:15:41 +010012605
David S. Miller9360ffd2012-03-29 04:41:26 -040012606 if (cmd == NL80211_CMD_REMAIN_ON_CHANNEL &&
12607 nla_put_u32(msg, NL80211_ATTR_DURATION, duration))
12608 goto nla_put_failure;
Jouni Malinen9588bbd2009-12-23 13:15:41 +010012609
Johannes Berg3b7b72e2011-10-22 19:05:51 +020012610 genlmsg_end(msg, hdr);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010012611
Johannes Berg68eb5502013-11-19 15:19:38 +010012612 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010012613 NL80211_MCGRP_MLME, gfp);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010012614 return;
12615
12616 nla_put_failure:
12617 genlmsg_cancel(msg, hdr);
12618 nlmsg_free(msg);
12619}
12620
Johannes Berg947add32013-02-22 22:05:20 +010012621void cfg80211_ready_on_channel(struct wireless_dev *wdev, u64 cookie,
12622 struct ieee80211_channel *chan,
12623 unsigned int duration, gfp_t gfp)
Jouni Malinen9588bbd2009-12-23 13:15:41 +010012624{
Johannes Berg947add32013-02-22 22:05:20 +010012625 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080012626 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg947add32013-02-22 22:05:20 +010012627
12628 trace_cfg80211_ready_on_channel(wdev, cookie, chan, duration);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010012629 nl80211_send_remain_on_chan_event(NL80211_CMD_REMAIN_ON_CHANNEL,
Johannes Berg71bbc992012-06-15 15:30:18 +020012630 rdev, wdev, cookie, chan,
Johannes Berg42d97a52012-11-08 18:31:02 +010012631 duration, gfp);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010012632}
Johannes Berg947add32013-02-22 22:05:20 +010012633EXPORT_SYMBOL(cfg80211_ready_on_channel);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010012634
Johannes Berg947add32013-02-22 22:05:20 +010012635void cfg80211_remain_on_channel_expired(struct wireless_dev *wdev, u64 cookie,
12636 struct ieee80211_channel *chan,
12637 gfp_t gfp)
Jouni Malinen9588bbd2009-12-23 13:15:41 +010012638{
Johannes Berg947add32013-02-22 22:05:20 +010012639 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080012640 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg947add32013-02-22 22:05:20 +010012641
12642 trace_cfg80211_ready_on_channel_expired(wdev, cookie, chan);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010012643 nl80211_send_remain_on_chan_event(NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL,
Johannes Berg42d97a52012-11-08 18:31:02 +010012644 rdev, wdev, cookie, chan, 0, gfp);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010012645}
Johannes Berg947add32013-02-22 22:05:20 +010012646EXPORT_SYMBOL(cfg80211_remain_on_channel_expired);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010012647
Johannes Berg947add32013-02-22 22:05:20 +010012648void cfg80211_new_sta(struct net_device *dev, const u8 *mac_addr,
12649 struct station_info *sinfo, gfp_t gfp)
Johannes Berg98b62182009-12-23 13:15:44 +010012650{
Johannes Berg947add32013-02-22 22:05:20 +010012651 struct wiphy *wiphy = dev->ieee80211_ptr->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080012652 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg98b62182009-12-23 13:15:44 +010012653 struct sk_buff *msg;
12654
Johannes Berg947add32013-02-22 22:05:20 +010012655 trace_cfg80211_new_sta(dev, mac_addr, sinfo);
12656
Thomas Graf58050fc2012-06-28 03:57:45 +000012657 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Johannes Berg98b62182009-12-23 13:15:44 +010012658 if (!msg)
12659 return;
12660
Johannes Bergcf5ead82014-11-14 17:14:00 +010012661 if (nl80211_send_station(msg, NL80211_CMD_NEW_STATION, 0, 0, 0,
John W. Linville66266b32012-03-15 13:25:41 -040012662 rdev, dev, mac_addr, sinfo) < 0) {
Johannes Berg98b62182009-12-23 13:15:44 +010012663 nlmsg_free(msg);
12664 return;
12665 }
12666
Johannes Berg68eb5502013-11-19 15:19:38 +010012667 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010012668 NL80211_MCGRP_MLME, gfp);
Johannes Berg98b62182009-12-23 13:15:44 +010012669}
Johannes Berg947add32013-02-22 22:05:20 +010012670EXPORT_SYMBOL(cfg80211_new_sta);
Johannes Berg98b62182009-12-23 13:15:44 +010012671
Johannes Bergcf5ead82014-11-14 17:14:00 +010012672void cfg80211_del_sta_sinfo(struct net_device *dev, const u8 *mac_addr,
12673 struct station_info *sinfo, gfp_t gfp)
Jouni Malinenec15e682011-03-23 15:29:52 +020012674{
Johannes Berg947add32013-02-22 22:05:20 +010012675 struct wiphy *wiphy = dev->ieee80211_ptr->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080012676 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Jouni Malinenec15e682011-03-23 15:29:52 +020012677 struct sk_buff *msg;
Johannes Bergcf5ead82014-11-14 17:14:00 +010012678 struct station_info empty_sinfo = {};
12679
12680 if (!sinfo)
12681 sinfo = &empty_sinfo;
Jouni Malinenec15e682011-03-23 15:29:52 +020012682
Johannes Berg947add32013-02-22 22:05:20 +010012683 trace_cfg80211_del_sta(dev, mac_addr);
12684
Thomas Graf58050fc2012-06-28 03:57:45 +000012685 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinenec15e682011-03-23 15:29:52 +020012686 if (!msg)
12687 return;
12688
Johannes Bergcf5ead82014-11-14 17:14:00 +010012689 if (nl80211_send_station(msg, NL80211_CMD_DEL_STATION, 0, 0, 0,
Johannes Berg57007122015-01-16 21:05:02 +010012690 rdev, dev, mac_addr, sinfo) < 0) {
Jouni Malinenec15e682011-03-23 15:29:52 +020012691 nlmsg_free(msg);
12692 return;
12693 }
12694
Johannes Berg68eb5502013-11-19 15:19:38 +010012695 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010012696 NL80211_MCGRP_MLME, gfp);
Jouni Malinenec15e682011-03-23 15:29:52 +020012697}
Johannes Bergcf5ead82014-11-14 17:14:00 +010012698EXPORT_SYMBOL(cfg80211_del_sta_sinfo);
Jouni Malinenec15e682011-03-23 15:29:52 +020012699
Johannes Berg947add32013-02-22 22:05:20 +010012700void cfg80211_conn_failed(struct net_device *dev, const u8 *mac_addr,
12701 enum nl80211_connect_failed_reason reason,
12702 gfp_t gfp)
Pandiyarajan Pitchaimuthued44a952012-09-18 16:50:49 +053012703{
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);
Pandiyarajan Pitchaimuthued44a952012-09-18 16:50:49 +053012706 struct sk_buff *msg;
12707 void *hdr;
12708
12709 msg = nlmsg_new(NLMSG_GOODSIZE, gfp);
12710 if (!msg)
12711 return;
12712
12713 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONN_FAILED);
12714 if (!hdr) {
12715 nlmsg_free(msg);
12716 return;
12717 }
12718
12719 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
12720 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) ||
12721 nla_put_u32(msg, NL80211_ATTR_CONN_FAILED_REASON, reason))
12722 goto nla_put_failure;
12723
12724 genlmsg_end(msg, hdr);
12725
Johannes Berg68eb5502013-11-19 15:19:38 +010012726 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010012727 NL80211_MCGRP_MLME, gfp);
Pandiyarajan Pitchaimuthued44a952012-09-18 16:50:49 +053012728 return;
12729
12730 nla_put_failure:
12731 genlmsg_cancel(msg, hdr);
12732 nlmsg_free(msg);
12733}
Johannes Berg947add32013-02-22 22:05:20 +010012734EXPORT_SYMBOL(cfg80211_conn_failed);
Pandiyarajan Pitchaimuthued44a952012-09-18 16:50:49 +053012735
Johannes Bergb92ab5d2011-11-04 11:18:19 +010012736static bool __nl80211_unexpected_frame(struct net_device *dev, u8 cmd,
12737 const u8 *addr, gfp_t gfp)
Johannes Berg28946da2011-11-04 11:18:12 +010012738{
12739 struct wireless_dev *wdev = dev->ieee80211_ptr;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080012740 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Johannes Berg28946da2011-11-04 11:18:12 +010012741 struct sk_buff *msg;
12742 void *hdr;
Eric W. Biederman15e47302012-09-07 20:12:54 +000012743 u32 nlportid = ACCESS_ONCE(wdev->ap_unexpected_nlportid);
Johannes Berg28946da2011-11-04 11:18:12 +010012744
Eric W. Biederman15e47302012-09-07 20:12:54 +000012745 if (!nlportid)
Johannes Berg28946da2011-11-04 11:18:12 +010012746 return false;
12747
12748 msg = nlmsg_new(100, gfp);
12749 if (!msg)
12750 return true;
12751
Johannes Bergb92ab5d2011-11-04 11:18:19 +010012752 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
Johannes Berg28946da2011-11-04 11:18:12 +010012753 if (!hdr) {
12754 nlmsg_free(msg);
12755 return true;
12756 }
12757
David S. Miller9360ffd2012-03-29 04:41:26 -040012758 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
12759 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
12760 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr))
12761 goto nla_put_failure;
Johannes Berg28946da2011-11-04 11:18:12 +010012762
Johannes Berg9c90a9f2013-06-04 12:46:03 +020012763 genlmsg_end(msg, hdr);
Eric W. Biederman15e47302012-09-07 20:12:54 +000012764 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid);
Johannes Berg28946da2011-11-04 11:18:12 +010012765 return true;
12766
12767 nla_put_failure:
12768 genlmsg_cancel(msg, hdr);
12769 nlmsg_free(msg);
12770 return true;
12771}
12772
Johannes Berg947add32013-02-22 22:05:20 +010012773bool cfg80211_rx_spurious_frame(struct net_device *dev,
12774 const u8 *addr, gfp_t gfp)
Johannes Bergb92ab5d2011-11-04 11:18:19 +010012775{
Johannes Berg947add32013-02-22 22:05:20 +010012776 struct wireless_dev *wdev = dev->ieee80211_ptr;
12777 bool ret;
Johannes Bergb92ab5d2011-11-04 11:18:19 +010012778
Johannes Berg947add32013-02-22 22:05:20 +010012779 trace_cfg80211_rx_spurious_frame(dev, addr);
12780
12781 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP &&
12782 wdev->iftype != NL80211_IFTYPE_P2P_GO)) {
12783 trace_cfg80211_return_bool(false);
12784 return false;
12785 }
12786 ret = __nl80211_unexpected_frame(dev, NL80211_CMD_UNEXPECTED_FRAME,
12787 addr, gfp);
12788 trace_cfg80211_return_bool(ret);
12789 return ret;
Johannes Bergb92ab5d2011-11-04 11:18:19 +010012790}
Johannes Berg947add32013-02-22 22:05:20 +010012791EXPORT_SYMBOL(cfg80211_rx_spurious_frame);
12792
12793bool cfg80211_rx_unexpected_4addr_frame(struct net_device *dev,
12794 const u8 *addr, gfp_t gfp)
12795{
12796 struct wireless_dev *wdev = dev->ieee80211_ptr;
12797 bool ret;
12798
12799 trace_cfg80211_rx_unexpected_4addr_frame(dev, addr);
12800
12801 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP &&
12802 wdev->iftype != NL80211_IFTYPE_P2P_GO &&
12803 wdev->iftype != NL80211_IFTYPE_AP_VLAN)) {
12804 trace_cfg80211_return_bool(false);
12805 return false;
12806 }
12807 ret = __nl80211_unexpected_frame(dev,
12808 NL80211_CMD_UNEXPECTED_4ADDR_FRAME,
12809 addr, gfp);
12810 trace_cfg80211_return_bool(ret);
12811 return ret;
12812}
12813EXPORT_SYMBOL(cfg80211_rx_unexpected_4addr_frame);
Johannes Bergb92ab5d2011-11-04 11:18:19 +010012814
Johannes Berg2e161f72010-08-12 15:38:38 +020012815int nl80211_send_mgmt(struct cfg80211_registered_device *rdev,
Eric W. Biederman15e47302012-09-07 20:12:54 +000012816 struct wireless_dev *wdev, u32 nlportid,
Johannes Berg804483e2012-03-05 22:18:41 +010012817 int freq, int sig_dbm,
Vladimir Kondratiev19504cf2013-08-15 14:51:28 +030012818 const u8 *buf, size_t len, u32 flags, gfp_t gfp)
Jouni Malinen026331c2010-02-15 12:53:10 +020012819{
Johannes Berg71bbc992012-06-15 15:30:18 +020012820 struct net_device *netdev = wdev->netdev;
Jouni Malinen026331c2010-02-15 12:53:10 +020012821 struct sk_buff *msg;
12822 void *hdr;
Jouni Malinen026331c2010-02-15 12:53:10 +020012823
12824 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
12825 if (!msg)
12826 return -ENOMEM;
12827
Johannes Berg2e161f72010-08-12 15:38:38 +020012828 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME);
Jouni Malinen026331c2010-02-15 12:53:10 +020012829 if (!hdr) {
12830 nlmsg_free(msg);
12831 return -ENOMEM;
12832 }
12833
David S. Miller9360ffd2012-03-29 04:41:26 -040012834 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg71bbc992012-06-15 15:30:18 +020012835 (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
12836 netdev->ifindex)) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020012837 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
12838 NL80211_ATTR_PAD) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040012839 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq) ||
12840 (sig_dbm &&
12841 nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) ||
Vladimir Kondratiev19504cf2013-08-15 14:51:28 +030012842 nla_put(msg, NL80211_ATTR_FRAME, len, buf) ||
12843 (flags &&
12844 nla_put_u32(msg, NL80211_ATTR_RXMGMT_FLAGS, flags)))
David S. Miller9360ffd2012-03-29 04:41:26 -040012845 goto nla_put_failure;
Jouni Malinen026331c2010-02-15 12:53:10 +020012846
Johannes Berg3b7b72e2011-10-22 19:05:51 +020012847 genlmsg_end(msg, hdr);
Jouni Malinen026331c2010-02-15 12:53:10 +020012848
Eric W. Biederman15e47302012-09-07 20:12:54 +000012849 return genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid);
Jouni Malinen026331c2010-02-15 12:53:10 +020012850
12851 nla_put_failure:
12852 genlmsg_cancel(msg, hdr);
12853 nlmsg_free(msg);
12854 return -ENOBUFS;
12855}
12856
Johannes Berg947add32013-02-22 22:05:20 +010012857void cfg80211_mgmt_tx_status(struct wireless_dev *wdev, u64 cookie,
12858 const u8 *buf, size_t len, bool ack, gfp_t gfp)
Jouni Malinen026331c2010-02-15 12:53:10 +020012859{
Johannes Berg947add32013-02-22 22:05:20 +010012860 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080012861 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg71bbc992012-06-15 15:30:18 +020012862 struct net_device *netdev = wdev->netdev;
Jouni Malinen026331c2010-02-15 12:53:10 +020012863 struct sk_buff *msg;
12864 void *hdr;
12865
Johannes Berg947add32013-02-22 22:05:20 +010012866 trace_cfg80211_mgmt_tx_status(wdev, cookie, ack);
12867
Jouni Malinen026331c2010-02-15 12:53:10 +020012868 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
12869 if (!msg)
12870 return;
12871
Johannes Berg2e161f72010-08-12 15:38:38 +020012872 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME_TX_STATUS);
Jouni Malinen026331c2010-02-15 12:53:10 +020012873 if (!hdr) {
12874 nlmsg_free(msg);
12875 return;
12876 }
12877
David S. Miller9360ffd2012-03-29 04:41:26 -040012878 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg71bbc992012-06-15 15:30:18 +020012879 (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
12880 netdev->ifindex)) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020012881 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
12882 NL80211_ATTR_PAD) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040012883 nla_put(msg, NL80211_ATTR_FRAME, len, buf) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020012884 nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie,
12885 NL80211_ATTR_PAD) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040012886 (ack && nla_put_flag(msg, NL80211_ATTR_ACK)))
12887 goto nla_put_failure;
Jouni Malinen026331c2010-02-15 12:53:10 +020012888
Johannes Berg3b7b72e2011-10-22 19:05:51 +020012889 genlmsg_end(msg, hdr);
Jouni Malinen026331c2010-02-15 12:53:10 +020012890
Johannes Berg68eb5502013-11-19 15:19:38 +010012891 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010012892 NL80211_MCGRP_MLME, gfp);
Jouni Malinen026331c2010-02-15 12:53:10 +020012893 return;
12894
12895 nla_put_failure:
12896 genlmsg_cancel(msg, hdr);
12897 nlmsg_free(msg);
12898}
Johannes Berg947add32013-02-22 22:05:20 +010012899EXPORT_SYMBOL(cfg80211_mgmt_tx_status);
Jouni Malinen026331c2010-02-15 12:53:10 +020012900
Johannes Berg5b97f492014-11-26 12:37:43 +010012901static struct sk_buff *cfg80211_prepare_cqm(struct net_device *dev,
12902 const char *mac, gfp_t gfp)
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020012903{
Johannes Berg947add32013-02-22 22:05:20 +010012904 struct wireless_dev *wdev = dev->ieee80211_ptr;
Johannes Berg5b97f492014-11-26 12:37:43 +010012905 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
12906 struct sk_buff *msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
12907 void **cb;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020012908
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020012909 if (!msg)
Johannes Berg5b97f492014-11-26 12:37:43 +010012910 return NULL;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020012911
Johannes Berg5b97f492014-11-26 12:37:43 +010012912 cb = (void **)msg->cb;
12913
12914 cb[0] = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM);
12915 if (!cb[0]) {
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020012916 nlmsg_free(msg);
Johannes Berg5b97f492014-11-26 12:37:43 +010012917 return NULL;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020012918 }
12919
David S. Miller9360ffd2012-03-29 04:41:26 -040012920 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg947add32013-02-22 22:05:20 +010012921 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex))
David S. Miller9360ffd2012-03-29 04:41:26 -040012922 goto nla_put_failure;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020012923
Johannes Berg5b97f492014-11-26 12:37:43 +010012924 if (mac && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac))
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020012925 goto nla_put_failure;
12926
Johannes Berg5b97f492014-11-26 12:37:43 +010012927 cb[1] = nla_nest_start(msg, NL80211_ATTR_CQM);
12928 if (!cb[1])
12929 goto nla_put_failure;
12930
12931 cb[2] = rdev;
12932
12933 return msg;
12934 nla_put_failure:
12935 nlmsg_free(msg);
12936 return NULL;
12937}
12938
12939static void cfg80211_send_cqm(struct sk_buff *msg, gfp_t gfp)
12940{
12941 void **cb = (void **)msg->cb;
12942 struct cfg80211_registered_device *rdev = cb[2];
12943
12944 nla_nest_end(msg, cb[1]);
12945 genlmsg_end(msg, cb[0]);
12946
12947 memset(msg->cb, 0, sizeof(msg->cb));
12948
12949 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
12950 NL80211_MCGRP_MLME, gfp);
12951}
12952
12953void cfg80211_cqm_rssi_notify(struct net_device *dev,
12954 enum nl80211_cqm_rssi_threshold_event rssi_event,
12955 gfp_t gfp)
12956{
12957 struct sk_buff *msg;
12958
12959 trace_cfg80211_cqm_rssi_notify(dev, rssi_event);
12960
Johannes Berg98f03342014-11-26 12:42:02 +010012961 if (WARN_ON(rssi_event != NL80211_CQM_RSSI_THRESHOLD_EVENT_LOW &&
12962 rssi_event != NL80211_CQM_RSSI_THRESHOLD_EVENT_HIGH))
12963 return;
12964
Johannes Berg5b97f492014-11-26 12:37:43 +010012965 msg = cfg80211_prepare_cqm(dev, NULL, gfp);
12966 if (!msg)
12967 return;
12968
David S. Miller9360ffd2012-03-29 04:41:26 -040012969 if (nla_put_u32(msg, NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT,
12970 rssi_event))
12971 goto nla_put_failure;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020012972
Johannes Berg5b97f492014-11-26 12:37:43 +010012973 cfg80211_send_cqm(msg, gfp);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020012974
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020012975 return;
12976
12977 nla_put_failure:
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020012978 nlmsg_free(msg);
12979}
Johannes Berg947add32013-02-22 22:05:20 +010012980EXPORT_SYMBOL(cfg80211_cqm_rssi_notify);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020012981
Johannes Berg5b97f492014-11-26 12:37:43 +010012982void cfg80211_cqm_txe_notify(struct net_device *dev,
12983 const u8 *peer, u32 num_packets,
12984 u32 rate, u32 intvl, gfp_t gfp)
12985{
12986 struct sk_buff *msg;
12987
12988 msg = cfg80211_prepare_cqm(dev, peer, gfp);
12989 if (!msg)
12990 return;
12991
12992 if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_PKTS, num_packets))
12993 goto nla_put_failure;
12994
12995 if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_RATE, rate))
12996 goto nla_put_failure;
12997
12998 if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_INTVL, intvl))
12999 goto nla_put_failure;
13000
13001 cfg80211_send_cqm(msg, gfp);
13002 return;
13003
13004 nla_put_failure:
13005 nlmsg_free(msg);
13006}
13007EXPORT_SYMBOL(cfg80211_cqm_txe_notify);
13008
13009void cfg80211_cqm_pktloss_notify(struct net_device *dev,
13010 const u8 *peer, u32 num_packets, gfp_t gfp)
13011{
13012 struct sk_buff *msg;
13013
13014 trace_cfg80211_cqm_pktloss_notify(dev, peer, num_packets);
13015
13016 msg = cfg80211_prepare_cqm(dev, peer, gfp);
13017 if (!msg)
13018 return;
13019
13020 if (nla_put_u32(msg, NL80211_ATTR_CQM_PKT_LOSS_EVENT, num_packets))
13021 goto nla_put_failure;
13022
13023 cfg80211_send_cqm(msg, gfp);
13024 return;
13025
13026 nla_put_failure:
13027 nlmsg_free(msg);
13028}
13029EXPORT_SYMBOL(cfg80211_cqm_pktloss_notify);
13030
Johannes Berg98f03342014-11-26 12:42:02 +010013031void cfg80211_cqm_beacon_loss_notify(struct net_device *dev, gfp_t gfp)
13032{
13033 struct sk_buff *msg;
13034
13035 msg = cfg80211_prepare_cqm(dev, NULL, gfp);
13036 if (!msg)
13037 return;
13038
13039 if (nla_put_flag(msg, NL80211_ATTR_CQM_BEACON_LOSS_EVENT))
13040 goto nla_put_failure;
13041
13042 cfg80211_send_cqm(msg, gfp);
13043 return;
13044
13045 nla_put_failure:
13046 nlmsg_free(msg);
13047}
13048EXPORT_SYMBOL(cfg80211_cqm_beacon_loss_notify);
13049
Johannes Berg947add32013-02-22 22:05:20 +010013050static void nl80211_gtk_rekey_notify(struct cfg80211_registered_device *rdev,
13051 struct net_device *netdev, const u8 *bssid,
13052 const u8 *replay_ctr, gfp_t gfp)
Johannes Berge5497d72011-07-05 16:35:40 +020013053{
13054 struct sk_buff *msg;
13055 struct nlattr *rekey_attr;
13056 void *hdr;
13057
Thomas Graf58050fc2012-06-28 03:57:45 +000013058 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Johannes Berge5497d72011-07-05 16:35:40 +020013059 if (!msg)
13060 return;
13061
13062 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_REKEY_OFFLOAD);
13063 if (!hdr) {
13064 nlmsg_free(msg);
13065 return;
13066 }
13067
David S. Miller9360ffd2012-03-29 04:41:26 -040013068 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
13069 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
13070 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid))
13071 goto nla_put_failure;
Johannes Berge5497d72011-07-05 16:35:40 +020013072
13073 rekey_attr = nla_nest_start(msg, NL80211_ATTR_REKEY_DATA);
13074 if (!rekey_attr)
13075 goto nla_put_failure;
13076
David S. Miller9360ffd2012-03-29 04:41:26 -040013077 if (nla_put(msg, NL80211_REKEY_DATA_REPLAY_CTR,
13078 NL80211_REPLAY_CTR_LEN, replay_ctr))
13079 goto nla_put_failure;
Johannes Berge5497d72011-07-05 16:35:40 +020013080
13081 nla_nest_end(msg, rekey_attr);
13082
Johannes Berg3b7b72e2011-10-22 19:05:51 +020013083 genlmsg_end(msg, hdr);
Johannes Berge5497d72011-07-05 16:35:40 +020013084
Johannes Berg68eb5502013-11-19 15:19:38 +010013085 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010013086 NL80211_MCGRP_MLME, gfp);
Johannes Berge5497d72011-07-05 16:35:40 +020013087 return;
13088
13089 nla_put_failure:
13090 genlmsg_cancel(msg, hdr);
13091 nlmsg_free(msg);
13092}
13093
Johannes Berg947add32013-02-22 22:05:20 +010013094void cfg80211_gtk_rekey_notify(struct net_device *dev, const u8 *bssid,
13095 const u8 *replay_ctr, gfp_t gfp)
13096{
13097 struct wireless_dev *wdev = dev->ieee80211_ptr;
13098 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080013099 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg947add32013-02-22 22:05:20 +010013100
13101 trace_cfg80211_gtk_rekey_notify(dev, bssid);
13102 nl80211_gtk_rekey_notify(rdev, dev, bssid, replay_ctr, gfp);
13103}
13104EXPORT_SYMBOL(cfg80211_gtk_rekey_notify);
13105
13106static void
13107nl80211_pmksa_candidate_notify(struct cfg80211_registered_device *rdev,
13108 struct net_device *netdev, int index,
13109 const u8 *bssid, bool preauth, gfp_t gfp)
Jouni Malinenc9df56b2011-09-16 18:56:23 +030013110{
13111 struct sk_buff *msg;
13112 struct nlattr *attr;
13113 void *hdr;
13114
Thomas Graf58050fc2012-06-28 03:57:45 +000013115 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinenc9df56b2011-09-16 18:56:23 +030013116 if (!msg)
13117 return;
13118
13119 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PMKSA_CANDIDATE);
13120 if (!hdr) {
13121 nlmsg_free(msg);
13122 return;
13123 }
13124
David S. Miller9360ffd2012-03-29 04:41:26 -040013125 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
13126 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex))
13127 goto nla_put_failure;
Jouni Malinenc9df56b2011-09-16 18:56:23 +030013128
13129 attr = nla_nest_start(msg, NL80211_ATTR_PMKSA_CANDIDATE);
13130 if (!attr)
13131 goto nla_put_failure;
13132
David S. Miller9360ffd2012-03-29 04:41:26 -040013133 if (nla_put_u32(msg, NL80211_PMKSA_CANDIDATE_INDEX, index) ||
13134 nla_put(msg, NL80211_PMKSA_CANDIDATE_BSSID, ETH_ALEN, bssid) ||
13135 (preauth &&
13136 nla_put_flag(msg, NL80211_PMKSA_CANDIDATE_PREAUTH)))
13137 goto nla_put_failure;
Jouni Malinenc9df56b2011-09-16 18:56:23 +030013138
13139 nla_nest_end(msg, attr);
13140
Johannes Berg3b7b72e2011-10-22 19:05:51 +020013141 genlmsg_end(msg, hdr);
Jouni Malinenc9df56b2011-09-16 18:56:23 +030013142
Johannes Berg68eb5502013-11-19 15:19:38 +010013143 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010013144 NL80211_MCGRP_MLME, gfp);
Jouni Malinenc9df56b2011-09-16 18:56:23 +030013145 return;
13146
13147 nla_put_failure:
13148 genlmsg_cancel(msg, hdr);
13149 nlmsg_free(msg);
13150}
13151
Johannes Berg947add32013-02-22 22:05:20 +010013152void cfg80211_pmksa_candidate_notify(struct net_device *dev, int index,
13153 const u8 *bssid, bool preauth, gfp_t gfp)
13154{
13155 struct wireless_dev *wdev = dev->ieee80211_ptr;
13156 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080013157 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg947add32013-02-22 22:05:20 +010013158
13159 trace_cfg80211_pmksa_candidate_notify(dev, index, bssid, preauth);
13160 nl80211_pmksa_candidate_notify(rdev, dev, index, bssid, preauth, gfp);
13161}
13162EXPORT_SYMBOL(cfg80211_pmksa_candidate_notify);
13163
13164static void nl80211_ch_switch_notify(struct cfg80211_registered_device *rdev,
13165 struct net_device *netdev,
13166 struct cfg80211_chan_def *chandef,
Luciano Coelhof8d75522014-11-07 14:31:35 +020013167 gfp_t gfp,
13168 enum nl80211_commands notif,
13169 u8 count)
Thomas Pedersen53145262012-04-06 13:35:47 -070013170{
13171 struct sk_buff *msg;
13172 void *hdr;
13173
Thomas Graf58050fc2012-06-28 03:57:45 +000013174 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Thomas Pedersen53145262012-04-06 13:35:47 -070013175 if (!msg)
13176 return;
13177
Luciano Coelhof8d75522014-11-07 14:31:35 +020013178 hdr = nl80211hdr_put(msg, 0, 0, 0, notif);
Thomas Pedersen53145262012-04-06 13:35:47 -070013179 if (!hdr) {
13180 nlmsg_free(msg);
13181 return;
13182 }
13183
Johannes Berg683b6d32012-11-08 21:25:48 +010013184 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex))
13185 goto nla_put_failure;
13186
13187 if (nl80211_send_chandef(msg, chandef))
John W. Linville7eab0f62012-04-12 14:25:14 -040013188 goto nla_put_failure;
Thomas Pedersen53145262012-04-06 13:35:47 -070013189
Luciano Coelhof8d75522014-11-07 14:31:35 +020013190 if ((notif == NL80211_CMD_CH_SWITCH_STARTED_NOTIFY) &&
13191 (nla_put_u32(msg, NL80211_ATTR_CH_SWITCH_COUNT, count)))
13192 goto nla_put_failure;
13193
Thomas Pedersen53145262012-04-06 13:35:47 -070013194 genlmsg_end(msg, hdr);
13195
Johannes Berg68eb5502013-11-19 15:19:38 +010013196 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010013197 NL80211_MCGRP_MLME, gfp);
Thomas Pedersen53145262012-04-06 13:35:47 -070013198 return;
13199
13200 nla_put_failure:
13201 genlmsg_cancel(msg, hdr);
13202 nlmsg_free(msg);
13203}
13204
Johannes Berg947add32013-02-22 22:05:20 +010013205void cfg80211_ch_switch_notify(struct net_device *dev,
13206 struct cfg80211_chan_def *chandef)
Thomas Pedersen84f10702012-07-12 16:17:33 -070013207{
Johannes Berg947add32013-02-22 22:05:20 +010013208 struct wireless_dev *wdev = dev->ieee80211_ptr;
13209 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080013210 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg947add32013-02-22 22:05:20 +010013211
Simon Wunderliche487eae2013-11-21 18:19:51 +010013212 ASSERT_WDEV_LOCK(wdev);
Johannes Berg947add32013-02-22 22:05:20 +010013213
Simon Wunderliche487eae2013-11-21 18:19:51 +010013214 trace_cfg80211_ch_switch_notify(dev, chandef);
Johannes Berg947add32013-02-22 22:05:20 +010013215
Michal Kazior9e0e2962014-01-29 14:22:27 +010013216 wdev->chandef = *chandef;
Janusz Dziedzic96f55f12014-01-24 14:29:21 +010013217 wdev->preset_chandef = *chandef;
Luciano Coelhof8d75522014-11-07 14:31:35 +020013218 nl80211_ch_switch_notify(rdev, dev, chandef, GFP_KERNEL,
13219 NL80211_CMD_CH_SWITCH_NOTIFY, 0);
Johannes Berg947add32013-02-22 22:05:20 +010013220}
13221EXPORT_SYMBOL(cfg80211_ch_switch_notify);
13222
Luciano Coelhof8d75522014-11-07 14:31:35 +020013223void cfg80211_ch_switch_started_notify(struct net_device *dev,
13224 struct cfg80211_chan_def *chandef,
13225 u8 count)
13226{
13227 struct wireless_dev *wdev = dev->ieee80211_ptr;
13228 struct wiphy *wiphy = wdev->wiphy;
13229 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
13230
13231 trace_cfg80211_ch_switch_started_notify(dev, chandef);
13232
13233 nl80211_ch_switch_notify(rdev, dev, chandef, GFP_KERNEL,
13234 NL80211_CMD_CH_SWITCH_STARTED_NOTIFY, count);
13235}
13236EXPORT_SYMBOL(cfg80211_ch_switch_started_notify);
13237
Thomas Pedersen84f10702012-07-12 16:17:33 -070013238void
Simon Wunderlich04f39042013-02-08 18:16:19 +010013239nl80211_radar_notify(struct cfg80211_registered_device *rdev,
Janusz Dziedzicd2859df2013-11-06 13:55:51 +010013240 const struct cfg80211_chan_def *chandef,
Simon Wunderlich04f39042013-02-08 18:16:19 +010013241 enum nl80211_radar_event event,
13242 struct net_device *netdev, gfp_t gfp)
13243{
13244 struct sk_buff *msg;
13245 void *hdr;
13246
13247 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
13248 if (!msg)
13249 return;
13250
13251 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_RADAR_DETECT);
13252 if (!hdr) {
13253 nlmsg_free(msg);
13254 return;
13255 }
13256
13257 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx))
13258 goto nla_put_failure;
13259
13260 /* NOP and radar events don't need a netdev parameter */
13261 if (netdev) {
13262 struct wireless_dev *wdev = netdev->ieee80211_ptr;
13263
13264 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020013265 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
13266 NL80211_ATTR_PAD))
Simon Wunderlich04f39042013-02-08 18:16:19 +010013267 goto nla_put_failure;
13268 }
13269
13270 if (nla_put_u32(msg, NL80211_ATTR_RADAR_EVENT, event))
13271 goto nla_put_failure;
13272
13273 if (nl80211_send_chandef(msg, chandef))
13274 goto nla_put_failure;
13275
Johannes Berg9c90a9f2013-06-04 12:46:03 +020013276 genlmsg_end(msg, hdr);
Simon Wunderlich04f39042013-02-08 18:16:19 +010013277
Johannes Berg68eb5502013-11-19 15:19:38 +010013278 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010013279 NL80211_MCGRP_MLME, gfp);
Simon Wunderlich04f39042013-02-08 18:16:19 +010013280 return;
13281
13282 nla_put_failure:
13283 genlmsg_cancel(msg, hdr);
13284 nlmsg_free(msg);
13285}
13286
Johannes Berg7f6cf312011-11-04 11:18:15 +010013287void cfg80211_probe_status(struct net_device *dev, const u8 *addr,
13288 u64 cookie, bool acked, gfp_t gfp)
13289{
13290 struct wireless_dev *wdev = dev->ieee80211_ptr;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080013291 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Johannes Berg7f6cf312011-11-04 11:18:15 +010013292 struct sk_buff *msg;
13293 void *hdr;
Johannes Berg7f6cf312011-11-04 11:18:15 +010013294
Beni Lev4ee3e062012-08-27 12:49:39 +030013295 trace_cfg80211_probe_status(dev, addr, cookie, acked);
13296
Thomas Graf58050fc2012-06-28 03:57:45 +000013297 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Beni Lev4ee3e062012-08-27 12:49:39 +030013298
Johannes Berg7f6cf312011-11-04 11:18:15 +010013299 if (!msg)
13300 return;
13301
13302 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PROBE_CLIENT);
13303 if (!hdr) {
13304 nlmsg_free(msg);
13305 return;
13306 }
13307
David S. Miller9360ffd2012-03-29 04:41:26 -040013308 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
13309 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
13310 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020013311 nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie,
13312 NL80211_ATTR_PAD) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040013313 (acked && nla_put_flag(msg, NL80211_ATTR_ACK)))
13314 goto nla_put_failure;
Johannes Berg7f6cf312011-11-04 11:18:15 +010013315
Johannes Berg9c90a9f2013-06-04 12:46:03 +020013316 genlmsg_end(msg, hdr);
Johannes Berg7f6cf312011-11-04 11:18:15 +010013317
Johannes Berg68eb5502013-11-19 15:19:38 +010013318 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010013319 NL80211_MCGRP_MLME, gfp);
Johannes Berg7f6cf312011-11-04 11:18:15 +010013320 return;
13321
13322 nla_put_failure:
13323 genlmsg_cancel(msg, hdr);
13324 nlmsg_free(msg);
13325}
13326EXPORT_SYMBOL(cfg80211_probe_status);
13327
Johannes Berg5e7602302011-11-04 11:18:17 +010013328void cfg80211_report_obss_beacon(struct wiphy *wiphy,
13329 const u8 *frame, size_t len,
Ben Greear37c73b52012-10-26 14:49:25 -070013330 int freq, int sig_dbm)
Johannes Berg5e7602302011-11-04 11:18:17 +010013331{
Zhao, Gangf26cbf42014-04-21 12:53:03 +080013332 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg5e7602302011-11-04 11:18:17 +010013333 struct sk_buff *msg;
13334 void *hdr;
Ben Greear37c73b52012-10-26 14:49:25 -070013335 struct cfg80211_beacon_registration *reg;
Johannes Berg5e7602302011-11-04 11:18:17 +010013336
Beni Lev4ee3e062012-08-27 12:49:39 +030013337 trace_cfg80211_report_obss_beacon(wiphy, frame, len, freq, sig_dbm);
13338
Ben Greear37c73b52012-10-26 14:49:25 -070013339 spin_lock_bh(&rdev->beacon_registrations_lock);
13340 list_for_each_entry(reg, &rdev->beacon_registrations, list) {
13341 msg = nlmsg_new(len + 100, GFP_ATOMIC);
13342 if (!msg) {
13343 spin_unlock_bh(&rdev->beacon_registrations_lock);
13344 return;
13345 }
Johannes Berg5e7602302011-11-04 11:18:17 +010013346
Ben Greear37c73b52012-10-26 14:49:25 -070013347 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME);
13348 if (!hdr)
13349 goto nla_put_failure;
Johannes Berg5e7602302011-11-04 11:18:17 +010013350
Ben Greear37c73b52012-10-26 14:49:25 -070013351 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
13352 (freq &&
13353 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq)) ||
13354 (sig_dbm &&
13355 nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) ||
13356 nla_put(msg, NL80211_ATTR_FRAME, len, frame))
13357 goto nla_put_failure;
13358
13359 genlmsg_end(msg, hdr);
13360
13361 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, reg->nlportid);
Johannes Berg5e7602302011-11-04 11:18:17 +010013362 }
Ben Greear37c73b52012-10-26 14:49:25 -070013363 spin_unlock_bh(&rdev->beacon_registrations_lock);
Johannes Berg5e7602302011-11-04 11:18:17 +010013364 return;
13365
13366 nla_put_failure:
Ben Greear37c73b52012-10-26 14:49:25 -070013367 spin_unlock_bh(&rdev->beacon_registrations_lock);
13368 if (hdr)
13369 genlmsg_cancel(msg, hdr);
Johannes Berg5e7602302011-11-04 11:18:17 +010013370 nlmsg_free(msg);
13371}
13372EXPORT_SYMBOL(cfg80211_report_obss_beacon);
13373
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010013374#ifdef CONFIG_PM
Luciano Coelho8cd4d452014-09-17 11:55:28 +030013375static int cfg80211_net_detect_results(struct sk_buff *msg,
13376 struct cfg80211_wowlan_wakeup *wakeup)
13377{
13378 struct cfg80211_wowlan_nd_info *nd = wakeup->net_detect;
13379 struct nlattr *nl_results, *nl_match, *nl_freqs;
13380 int i, j;
13381
13382 nl_results = nla_nest_start(
13383 msg, NL80211_WOWLAN_TRIG_NET_DETECT_RESULTS);
13384 if (!nl_results)
13385 return -EMSGSIZE;
13386
13387 for (i = 0; i < nd->n_matches; i++) {
13388 struct cfg80211_wowlan_nd_match *match = nd->matches[i];
13389
13390 nl_match = nla_nest_start(msg, i);
13391 if (!nl_match)
13392 break;
13393
13394 /* The SSID attribute is optional in nl80211, but for
13395 * simplicity reasons it's always present in the
13396 * cfg80211 structure. If a driver can't pass the
13397 * SSID, that needs to be changed. A zero length SSID
13398 * is still a valid SSID (wildcard), so it cannot be
13399 * used for this purpose.
13400 */
13401 if (nla_put(msg, NL80211_ATTR_SSID, match->ssid.ssid_len,
13402 match->ssid.ssid)) {
13403 nla_nest_cancel(msg, nl_match);
13404 goto out;
13405 }
13406
13407 if (match->n_channels) {
13408 nl_freqs = nla_nest_start(
13409 msg, NL80211_ATTR_SCAN_FREQUENCIES);
13410 if (!nl_freqs) {
13411 nla_nest_cancel(msg, nl_match);
13412 goto out;
13413 }
13414
13415 for (j = 0; j < match->n_channels; j++) {
Samuel Tan5528fae82015-02-09 21:29:15 +020013416 if (nla_put_u32(msg, j, match->channels[j])) {
Luciano Coelho8cd4d452014-09-17 11:55:28 +030013417 nla_nest_cancel(msg, nl_freqs);
13418 nla_nest_cancel(msg, nl_match);
13419 goto out;
13420 }
13421 }
13422
13423 nla_nest_end(msg, nl_freqs);
13424 }
13425
13426 nla_nest_end(msg, nl_match);
13427 }
13428
13429out:
13430 nla_nest_end(msg, nl_results);
13431 return 0;
13432}
13433
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010013434void cfg80211_report_wowlan_wakeup(struct wireless_dev *wdev,
13435 struct cfg80211_wowlan_wakeup *wakeup,
13436 gfp_t gfp)
13437{
Zhao, Gangf26cbf42014-04-21 12:53:03 +080013438 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010013439 struct sk_buff *msg;
13440 void *hdr;
Johannes Berg9c90a9f2013-06-04 12:46:03 +020013441 int size = 200;
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010013442
13443 trace_cfg80211_report_wowlan_wakeup(wdev->wiphy, wdev, wakeup);
13444
13445 if (wakeup)
13446 size += wakeup->packet_present_len;
13447
13448 msg = nlmsg_new(size, gfp);
13449 if (!msg)
13450 return;
13451
13452 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_WOWLAN);
13453 if (!hdr)
13454 goto free_msg;
13455
13456 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020013457 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
13458 NL80211_ATTR_PAD))
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010013459 goto free_msg;
13460
13461 if (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
13462 wdev->netdev->ifindex))
13463 goto free_msg;
13464
13465 if (wakeup) {
13466 struct nlattr *reasons;
13467
13468 reasons = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS);
Johannes Berg7fa322c2013-10-25 11:16:58 +020013469 if (!reasons)
13470 goto free_msg;
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010013471
13472 if (wakeup->disconnect &&
13473 nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT))
13474 goto free_msg;
13475 if (wakeup->magic_pkt &&
13476 nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT))
13477 goto free_msg;
13478 if (wakeup->gtk_rekey_failure &&
13479 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE))
13480 goto free_msg;
13481 if (wakeup->eap_identity_req &&
13482 nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST))
13483 goto free_msg;
13484 if (wakeup->four_way_handshake &&
13485 nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE))
13486 goto free_msg;
13487 if (wakeup->rfkill_release &&
13488 nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE))
13489 goto free_msg;
13490
13491 if (wakeup->pattern_idx >= 0 &&
13492 nla_put_u32(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN,
13493 wakeup->pattern_idx))
13494 goto free_msg;
13495
Johannes Bergae917c92013-10-25 11:05:22 +020013496 if (wakeup->tcp_match &&
13497 nla_put_flag(msg, NL80211_WOWLAN_TRIG_WAKEUP_TCP_MATCH))
13498 goto free_msg;
Johannes Berg2a0e0472013-01-23 22:57:40 +010013499
Johannes Bergae917c92013-10-25 11:05:22 +020013500 if (wakeup->tcp_connlost &&
13501 nla_put_flag(msg, NL80211_WOWLAN_TRIG_WAKEUP_TCP_CONNLOST))
13502 goto free_msg;
Johannes Berg2a0e0472013-01-23 22:57:40 +010013503
Johannes Bergae917c92013-10-25 11:05:22 +020013504 if (wakeup->tcp_nomoretokens &&
13505 nla_put_flag(msg,
13506 NL80211_WOWLAN_TRIG_WAKEUP_TCP_NOMORETOKENS))
13507 goto free_msg;
Johannes Berg2a0e0472013-01-23 22:57:40 +010013508
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010013509 if (wakeup->packet) {
13510 u32 pkt_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211;
13511 u32 len_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211_LEN;
13512
13513 if (!wakeup->packet_80211) {
13514 pkt_attr =
13515 NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023;
13516 len_attr =
13517 NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023_LEN;
13518 }
13519
13520 if (wakeup->packet_len &&
13521 nla_put_u32(msg, len_attr, wakeup->packet_len))
13522 goto free_msg;
13523
13524 if (nla_put(msg, pkt_attr, wakeup->packet_present_len,
13525 wakeup->packet))
13526 goto free_msg;
13527 }
13528
Luciano Coelho8cd4d452014-09-17 11:55:28 +030013529 if (wakeup->net_detect &&
13530 cfg80211_net_detect_results(msg, wakeup))
13531 goto free_msg;
13532
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010013533 nla_nest_end(msg, reasons);
13534 }
13535
Johannes Berg9c90a9f2013-06-04 12:46:03 +020013536 genlmsg_end(msg, hdr);
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010013537
Johannes Berg68eb5502013-11-19 15:19:38 +010013538 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010013539 NL80211_MCGRP_MLME, gfp);
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010013540 return;
13541
13542 free_msg:
13543 nlmsg_free(msg);
13544}
13545EXPORT_SYMBOL(cfg80211_report_wowlan_wakeup);
13546#endif
13547
Jouni Malinen3475b092012-11-16 22:49:57 +020013548void cfg80211_tdls_oper_request(struct net_device *dev, const u8 *peer,
13549 enum nl80211_tdls_operation oper,
13550 u16 reason_code, gfp_t gfp)
13551{
13552 struct wireless_dev *wdev = dev->ieee80211_ptr;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080013553 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Jouni Malinen3475b092012-11-16 22:49:57 +020013554 struct sk_buff *msg;
13555 void *hdr;
Jouni Malinen3475b092012-11-16 22:49:57 +020013556
13557 trace_cfg80211_tdls_oper_request(wdev->wiphy, dev, peer, oper,
13558 reason_code);
13559
13560 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
13561 if (!msg)
13562 return;
13563
13564 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_TDLS_OPER);
13565 if (!hdr) {
13566 nlmsg_free(msg);
13567 return;
13568 }
13569
13570 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
13571 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
13572 nla_put_u8(msg, NL80211_ATTR_TDLS_OPERATION, oper) ||
13573 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer) ||
13574 (reason_code > 0 &&
13575 nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason_code)))
13576 goto nla_put_failure;
13577
Johannes Berg9c90a9f2013-06-04 12:46:03 +020013578 genlmsg_end(msg, hdr);
Jouni Malinen3475b092012-11-16 22:49:57 +020013579
Johannes Berg68eb5502013-11-19 15:19:38 +010013580 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010013581 NL80211_MCGRP_MLME, gfp);
Jouni Malinen3475b092012-11-16 22:49:57 +020013582 return;
13583
13584 nla_put_failure:
13585 genlmsg_cancel(msg, hdr);
13586 nlmsg_free(msg);
13587}
13588EXPORT_SYMBOL(cfg80211_tdls_oper_request);
13589
Jouni Malinen026331c2010-02-15 12:53:10 +020013590static int nl80211_netlink_notify(struct notifier_block * nb,
13591 unsigned long state,
13592 void *_notify)
13593{
13594 struct netlink_notify *notify = _notify;
13595 struct cfg80211_registered_device *rdev;
13596 struct wireless_dev *wdev;
Ben Greear37c73b52012-10-26 14:49:25 -070013597 struct cfg80211_beacon_registration *reg, *tmp;
Jouni Malinen026331c2010-02-15 12:53:10 +020013598
Dmitry Ivanov8f815cd2016-04-06 17:23:18 +030013599 if (state != NETLINK_URELEASE || notify->protocol != NETLINK_GENERIC)
Jouni Malinen026331c2010-02-15 12:53:10 +020013600 return NOTIFY_DONE;
13601
13602 rcu_read_lock();
13603
Johannes Berg5e7602302011-11-04 11:18:17 +010013604 list_for_each_entry_rcu(rdev, &cfg80211_rdev_list, list) {
Johannes Berg78f22b62014-03-24 17:57:27 +010013605 bool schedule_destroy_work = false;
Jukka Rissanen93a1e862014-12-15 13:25:39 +020013606 bool schedule_scan_stop = false;
13607 struct cfg80211_sched_scan_request *sched_scan_req =
13608 rcu_dereference(rdev->sched_scan_req);
13609
13610 if (sched_scan_req && notify->portid &&
13611 sched_scan_req->owner_nlportid == notify->portid)
13612 schedule_scan_stop = true;
Johannes Berg78f22b62014-03-24 17:57:27 +010013613
Johannes Berg53873f12016-05-03 16:52:04 +030013614 list_for_each_entry_rcu(wdev, &rdev->wiphy.wdev_list, list) {
Eric W. Biederman15e47302012-09-07 20:12:54 +000013615 cfg80211_mlme_unregister_socket(wdev, notify->portid);
Ben Greear37c73b52012-10-26 14:49:25 -070013616
Johannes Berg78f22b62014-03-24 17:57:27 +010013617 if (wdev->owner_nlportid == notify->portid)
13618 schedule_destroy_work = true;
13619 }
13620
Ben Greear37c73b52012-10-26 14:49:25 -070013621 spin_lock_bh(&rdev->beacon_registrations_lock);
13622 list_for_each_entry_safe(reg, tmp, &rdev->beacon_registrations,
13623 list) {
13624 if (reg->nlportid == notify->portid) {
13625 list_del(&reg->list);
13626 kfree(reg);
13627 break;
13628 }
13629 }
13630 spin_unlock_bh(&rdev->beacon_registrations_lock);
Johannes Berg78f22b62014-03-24 17:57:27 +010013631
13632 if (schedule_destroy_work) {
13633 struct cfg80211_iface_destroy *destroy;
13634
13635 destroy = kzalloc(sizeof(*destroy), GFP_ATOMIC);
13636 if (destroy) {
13637 destroy->nlportid = notify->portid;
13638 spin_lock(&rdev->destroy_list_lock);
13639 list_add(&destroy->list, &rdev->destroy_list);
13640 spin_unlock(&rdev->destroy_list_lock);
13641 schedule_work(&rdev->destroy_work);
13642 }
Jukka Rissanen93a1e862014-12-15 13:25:39 +020013643 } else if (schedule_scan_stop) {
13644 sched_scan_req->owner_nlportid = 0;
13645
13646 if (rdev->ops->sched_scan_stop &&
13647 rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN)
13648 schedule_work(&rdev->sched_scan_stop_wk);
Johannes Berg78f22b62014-03-24 17:57:27 +010013649 }
Johannes Berg5e7602302011-11-04 11:18:17 +010013650 }
Jouni Malinen026331c2010-02-15 12:53:10 +020013651
13652 rcu_read_unlock();
13653
Ilan peer05050752015-03-04 00:32:06 -050013654 /*
13655 * It is possible that the user space process that is controlling the
13656 * indoor setting disappeared, so notify the regulatory core.
13657 */
13658 regulatory_netlink_notify(notify->portid);
Zhao, Gang6784c7d2014-04-21 12:53:04 +080013659 return NOTIFY_OK;
Jouni Malinen026331c2010-02-15 12:53:10 +020013660}
13661
13662static struct notifier_block nl80211_netlink_notifier = {
13663 .notifier_call = nl80211_netlink_notify,
13664};
13665
Jouni Malinen355199e2013-02-27 17:14:27 +020013666void cfg80211_ft_event(struct net_device *netdev,
13667 struct cfg80211_ft_event_params *ft_event)
13668{
13669 struct wiphy *wiphy = netdev->ieee80211_ptr->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080013670 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Jouni Malinen355199e2013-02-27 17:14:27 +020013671 struct sk_buff *msg;
13672 void *hdr;
Jouni Malinen355199e2013-02-27 17:14:27 +020013673
13674 trace_cfg80211_ft_event(wiphy, netdev, ft_event);
13675
13676 if (!ft_event->target_ap)
13677 return;
13678
13679 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
13680 if (!msg)
13681 return;
13682
13683 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FT_EVENT);
Johannes Bergae917c92013-10-25 11:05:22 +020013684 if (!hdr)
13685 goto out;
Jouni Malinen355199e2013-02-27 17:14:27 +020013686
Johannes Bergae917c92013-10-25 11:05:22 +020013687 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
13688 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
13689 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, ft_event->target_ap))
13690 goto out;
13691
13692 if (ft_event->ies &&
13693 nla_put(msg, NL80211_ATTR_IE, ft_event->ies_len, ft_event->ies))
13694 goto out;
13695 if (ft_event->ric_ies &&
13696 nla_put(msg, NL80211_ATTR_IE_RIC, ft_event->ric_ies_len,
13697 ft_event->ric_ies))
13698 goto out;
Jouni Malinen355199e2013-02-27 17:14:27 +020013699
Johannes Berg9c90a9f2013-06-04 12:46:03 +020013700 genlmsg_end(msg, hdr);
Jouni Malinen355199e2013-02-27 17:14:27 +020013701
Johannes Berg68eb5502013-11-19 15:19:38 +010013702 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010013703 NL80211_MCGRP_MLME, GFP_KERNEL);
Johannes Bergae917c92013-10-25 11:05:22 +020013704 return;
13705 out:
13706 nlmsg_free(msg);
Jouni Malinen355199e2013-02-27 17:14:27 +020013707}
13708EXPORT_SYMBOL(cfg80211_ft_event);
13709
Arend van Spriel5de17982013-04-18 15:49:00 +020013710void cfg80211_crit_proto_stopped(struct wireless_dev *wdev, gfp_t gfp)
13711{
13712 struct cfg80211_registered_device *rdev;
13713 struct sk_buff *msg;
13714 void *hdr;
13715 u32 nlportid;
13716
Zhao, Gangf26cbf42014-04-21 12:53:03 +080013717 rdev = wiphy_to_rdev(wdev->wiphy);
Arend van Spriel5de17982013-04-18 15:49:00 +020013718 if (!rdev->crit_proto_nlportid)
13719 return;
13720
13721 nlportid = rdev->crit_proto_nlportid;
13722 rdev->crit_proto_nlportid = 0;
13723
13724 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
13725 if (!msg)
13726 return;
13727
13728 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CRIT_PROTOCOL_STOP);
13729 if (!hdr)
13730 goto nla_put_failure;
13731
13732 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020013733 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
13734 NL80211_ATTR_PAD))
Arend van Spriel5de17982013-04-18 15:49:00 +020013735 goto nla_put_failure;
13736
13737 genlmsg_end(msg, hdr);
13738
13739 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid);
13740 return;
13741
13742 nla_put_failure:
13743 if (hdr)
13744 genlmsg_cancel(msg, hdr);
13745 nlmsg_free(msg);
Arend van Spriel5de17982013-04-18 15:49:00 +020013746}
13747EXPORT_SYMBOL(cfg80211_crit_proto_stopped);
13748
Johannes Berg348baf02014-01-24 14:06:29 +010013749void nl80211_send_ap_stopped(struct wireless_dev *wdev)
13750{
13751 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080013752 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg348baf02014-01-24 14:06:29 +010013753 struct sk_buff *msg;
13754 void *hdr;
13755
13756 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
13757 if (!msg)
13758 return;
13759
13760 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_STOP_AP);
13761 if (!hdr)
13762 goto out;
13763
13764 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
13765 nla_put_u32(msg, NL80211_ATTR_IFINDEX, wdev->netdev->ifindex) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020013766 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
13767 NL80211_ATTR_PAD))
Johannes Berg348baf02014-01-24 14:06:29 +010013768 goto out;
13769
13770 genlmsg_end(msg, hdr);
13771
13772 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(wiphy), msg, 0,
13773 NL80211_MCGRP_MLME, GFP_KERNEL);
13774 return;
13775 out:
13776 nlmsg_free(msg);
13777}
13778
Johannes Berg55682962007-09-20 13:09:35 -040013779/* initialisation/exit functions */
13780
13781int nl80211_init(void)
13782{
Michał Mirosław0d63cbb2009-05-21 10:34:06 +000013783 int err;
Johannes Berg55682962007-09-20 13:09:35 -040013784
Johannes Berg2a94fe42013-11-19 15:19:39 +010013785 err = genl_register_family_with_ops_groups(&nl80211_fam, nl80211_ops,
13786 nl80211_mcgrps);
Johannes Berg55682962007-09-20 13:09:35 -040013787 if (err)
13788 return err;
13789
Jouni Malinen026331c2010-02-15 12:53:10 +020013790 err = netlink_register_notifier(&nl80211_netlink_notifier);
13791 if (err)
13792 goto err_out;
13793
Johannes Berg55682962007-09-20 13:09:35 -040013794 return 0;
13795 err_out:
13796 genl_unregister_family(&nl80211_fam);
13797 return err;
13798}
13799
13800void nl80211_exit(void)
13801{
Jouni Malinen026331c2010-02-15 12:53:10 +020013802 netlink_unregister_notifier(&nl80211_netlink_notifier);
Johannes Berg55682962007-09-20 13:09:35 -040013803 genl_unregister_family(&nl80211_fam);
13804}