blob: ca75f60041d2156ba4b61cb7c05bd0b85883e525 [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 Berg55682962007-09-20 13:09:35 -04005 */
6
7#include <linux/if.h>
8#include <linux/module.h>
9#include <linux/err.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090010#include <linux/slab.h>
Johannes Berg55682962007-09-20 13:09:35 -040011#include <linux/list.h>
12#include <linux/if_ether.h>
13#include <linux/ieee80211.h>
14#include <linux/nl80211.h>
15#include <linux/rtnetlink.h>
16#include <linux/netlink.h>
Johannes Berg2a519312009-02-10 21:25:55 +010017#include <linux/etherdevice.h>
Johannes Berg463d0182009-07-14 00:33:35 +020018#include <net/net_namespace.h>
Johannes Berg55682962007-09-20 13:09:35 -040019#include <net/genetlink.h>
20#include <net/cfg80211.h>
Johannes Berg463d0182009-07-14 00:33:35 +020021#include <net/sock.h>
Johannes Berg2a0e0472013-01-23 22:57:40 +010022#include <net/inet_connection_sock.h>
Johannes Berg55682962007-09-20 13:09:35 -040023#include "core.h"
24#include "nl80211.h"
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -070025#include "reg.h"
Hila Gonene35e4d22012-06-27 17:19:42 +030026#include "rdev-ops.h"
Johannes Berg55682962007-09-20 13:09:35 -040027
Jouni Malinen5fb628e2011-08-10 23:54:35 +030028static int nl80211_crypto_settings(struct cfg80211_registered_device *rdev,
29 struct genl_info *info,
30 struct cfg80211_crypto_settings *settings,
31 int cipher_limit);
32
Johannes Bergf84f7712013-11-14 17:14:45 +010033static int nl80211_pre_doit(const struct genl_ops *ops, struct sk_buff *skb,
Johannes Berg4c476992010-10-04 21:36:35 +020034 struct genl_info *info);
Johannes Bergf84f7712013-11-14 17:14:45 +010035static void nl80211_post_doit(const struct genl_ops *ops, struct sk_buff *skb,
Johannes Berg4c476992010-10-04 21:36:35 +020036 struct genl_info *info);
37
Johannes Berg55682962007-09-20 13:09:35 -040038/* the netlink family */
39static struct genl_family nl80211_fam = {
Marcel Holtmannfb4e1562013-04-28 16:22:06 -070040 .id = GENL_ID_GENERATE, /* don't bother with a hardcoded ID */
41 .name = NL80211_GENL_NAME, /* have users key off the name instead */
42 .hdrsize = 0, /* no private header */
43 .version = 1, /* no particular meaning now */
Johannes Berg55682962007-09-20 13:09:35 -040044 .maxattr = NL80211_ATTR_MAX,
Johannes Berg463d0182009-07-14 00:33:35 +020045 .netnsok = true,
Johannes Berg4c476992010-10-04 21:36:35 +020046 .pre_doit = nl80211_pre_doit,
47 .post_doit = nl80211_post_doit,
Johannes Berg55682962007-09-20 13:09:35 -040048};
49
Johannes Berg2a94fe42013-11-19 15:19:39 +010050/* multicast groups */
51enum nl80211_multicast_groups {
52 NL80211_MCGRP_CONFIG,
53 NL80211_MCGRP_SCAN,
54 NL80211_MCGRP_REGULATORY,
55 NL80211_MCGRP_MLME,
Johannes Berg567ffc32013-12-18 14:43:31 +010056 NL80211_MCGRP_VENDOR,
Johannes Berg2a94fe42013-11-19 15:19:39 +010057 NL80211_MCGRP_TESTMODE /* keep last - ifdef! */
58};
59
60static const struct genl_multicast_group nl80211_mcgrps[] = {
61 [NL80211_MCGRP_CONFIG] = { .name = "config", },
62 [NL80211_MCGRP_SCAN] = { .name = "scan", },
63 [NL80211_MCGRP_REGULATORY] = { .name = "regulatory", },
64 [NL80211_MCGRP_MLME] = { .name = "mlme", },
Johannes Berg567ffc32013-12-18 14:43:31 +010065 [NL80211_MCGRP_VENDOR] = { .name = "vendor", },
Johannes Berg2a94fe42013-11-19 15:19:39 +010066#ifdef CONFIG_NL80211_TESTMODE
67 [NL80211_MCGRP_TESTMODE] = { .name = "testmode", }
68#endif
69};
70
Johannes Berg89a54e42012-06-15 14:33:17 +020071/* returns ERR_PTR values */
72static struct wireless_dev *
73__cfg80211_wdev_from_attrs(struct net *netns, struct nlattr **attrs)
Johannes Berg55682962007-09-20 13:09:35 -040074{
Johannes Berg89a54e42012-06-15 14:33:17 +020075 struct cfg80211_registered_device *rdev;
76 struct wireless_dev *result = NULL;
77 bool have_ifidx = attrs[NL80211_ATTR_IFINDEX];
78 bool have_wdev_id = attrs[NL80211_ATTR_WDEV];
79 u64 wdev_id;
80 int wiphy_idx = -1;
81 int ifidx = -1;
Johannes Berg55682962007-09-20 13:09:35 -040082
Johannes Berg5fe231e2013-05-08 21:45:15 +020083 ASSERT_RTNL();
Johannes Berg55682962007-09-20 13:09:35 -040084
Johannes Berg89a54e42012-06-15 14:33:17 +020085 if (!have_ifidx && !have_wdev_id)
86 return ERR_PTR(-EINVAL);
Johannes Berg55682962007-09-20 13:09:35 -040087
Johannes Berg89a54e42012-06-15 14:33:17 +020088 if (have_ifidx)
89 ifidx = nla_get_u32(attrs[NL80211_ATTR_IFINDEX]);
90 if (have_wdev_id) {
91 wdev_id = nla_get_u64(attrs[NL80211_ATTR_WDEV]);
92 wiphy_idx = wdev_id >> 32;
Johannes Berg55682962007-09-20 13:09:35 -040093 }
94
Johannes Berg89a54e42012-06-15 14:33:17 +020095 list_for_each_entry(rdev, &cfg80211_rdev_list, list) {
96 struct wireless_dev *wdev;
97
98 if (wiphy_net(&rdev->wiphy) != netns)
99 continue;
100
101 if (have_wdev_id && rdev->wiphy_idx != wiphy_idx)
102 continue;
103
Johannes Berg89a54e42012-06-15 14:33:17 +0200104 list_for_each_entry(wdev, &rdev->wdev_list, list) {
105 if (have_ifidx && wdev->netdev &&
106 wdev->netdev->ifindex == ifidx) {
107 result = wdev;
108 break;
109 }
110 if (have_wdev_id && wdev->identifier == (u32)wdev_id) {
111 result = wdev;
112 break;
113 }
114 }
Johannes Berg89a54e42012-06-15 14:33:17 +0200115
116 if (result)
117 break;
118 }
119
120 if (result)
121 return result;
122 return ERR_PTR(-ENODEV);
Johannes Berg55682962007-09-20 13:09:35 -0400123}
124
Johannes Berga9455402012-06-15 13:32:49 +0200125static struct cfg80211_registered_device *
Johannes Berg878d9ec2012-06-15 14:18:32 +0200126__cfg80211_rdev_from_attrs(struct net *netns, struct nlattr **attrs)
Johannes Berga9455402012-06-15 13:32:49 +0200127{
Johannes Berg7fee4772012-06-15 14:09:58 +0200128 struct cfg80211_registered_device *rdev = NULL, *tmp;
129 struct net_device *netdev;
Johannes Berga9455402012-06-15 13:32:49 +0200130
Johannes Berg5fe231e2013-05-08 21:45:15 +0200131 ASSERT_RTNL();
Johannes Berga9455402012-06-15 13:32:49 +0200132
Johannes Berg878d9ec2012-06-15 14:18:32 +0200133 if (!attrs[NL80211_ATTR_WIPHY] &&
Johannes Berg89a54e42012-06-15 14:33:17 +0200134 !attrs[NL80211_ATTR_IFINDEX] &&
135 !attrs[NL80211_ATTR_WDEV])
Johannes Berg7fee4772012-06-15 14:09:58 +0200136 return ERR_PTR(-EINVAL);
137
Johannes Berg878d9ec2012-06-15 14:18:32 +0200138 if (attrs[NL80211_ATTR_WIPHY])
Johannes Berg7fee4772012-06-15 14:09:58 +0200139 rdev = cfg80211_rdev_by_wiphy_idx(
Johannes Berg878d9ec2012-06-15 14:18:32 +0200140 nla_get_u32(attrs[NL80211_ATTR_WIPHY]));
Johannes Berga9455402012-06-15 13:32:49 +0200141
Johannes Berg89a54e42012-06-15 14:33:17 +0200142 if (attrs[NL80211_ATTR_WDEV]) {
143 u64 wdev_id = nla_get_u64(attrs[NL80211_ATTR_WDEV]);
144 struct wireless_dev *wdev;
145 bool found = false;
146
147 tmp = cfg80211_rdev_by_wiphy_idx(wdev_id >> 32);
148 if (tmp) {
149 /* make sure wdev exists */
Johannes Berg89a54e42012-06-15 14:33:17 +0200150 list_for_each_entry(wdev, &tmp->wdev_list, list) {
151 if (wdev->identifier != (u32)wdev_id)
152 continue;
153 found = true;
154 break;
155 }
Johannes Berg89a54e42012-06-15 14:33:17 +0200156
157 if (!found)
158 tmp = NULL;
159
160 if (rdev && tmp != rdev)
161 return ERR_PTR(-EINVAL);
162 rdev = tmp;
163 }
164 }
165
Johannes Berg878d9ec2012-06-15 14:18:32 +0200166 if (attrs[NL80211_ATTR_IFINDEX]) {
167 int ifindex = nla_get_u32(attrs[NL80211_ATTR_IFINDEX]);
Ying Xue7f2b8562014-01-15 10:23:45 +0800168 netdev = __dev_get_by_index(netns, ifindex);
Johannes Berg7fee4772012-06-15 14:09:58 +0200169 if (netdev) {
170 if (netdev->ieee80211_ptr)
Zhao, Gangf26cbf42014-04-21 12:53:03 +0800171 tmp = wiphy_to_rdev(
172 netdev->ieee80211_ptr->wiphy);
Johannes Berg7fee4772012-06-15 14:09:58 +0200173 else
174 tmp = NULL;
175
Johannes Berg7fee4772012-06-15 14:09:58 +0200176 /* not wireless device -- return error */
177 if (!tmp)
178 return ERR_PTR(-EINVAL);
179
180 /* mismatch -- return error */
181 if (rdev && tmp != rdev)
182 return ERR_PTR(-EINVAL);
183
184 rdev = tmp;
Johannes Berga9455402012-06-15 13:32:49 +0200185 }
Johannes Berga9455402012-06-15 13:32:49 +0200186 }
187
Johannes Berg4f7eff12012-06-15 14:14:22 +0200188 if (!rdev)
189 return ERR_PTR(-ENODEV);
Johannes Berga9455402012-06-15 13:32:49 +0200190
Johannes Berg4f7eff12012-06-15 14:14:22 +0200191 if (netns != wiphy_net(&rdev->wiphy))
192 return ERR_PTR(-ENODEV);
193
194 return rdev;
Johannes Berga9455402012-06-15 13:32:49 +0200195}
196
197/*
198 * This function returns a pointer to the driver
199 * that the genl_info item that is passed refers to.
Johannes Berga9455402012-06-15 13:32:49 +0200200 *
201 * The result of this can be a PTR_ERR and hence must
202 * be checked with IS_ERR() for errors.
203 */
204static struct cfg80211_registered_device *
Johannes Berg4f7eff12012-06-15 14:14:22 +0200205cfg80211_get_dev_from_info(struct net *netns, struct genl_info *info)
Johannes Berga9455402012-06-15 13:32:49 +0200206{
Johannes Berg5fe231e2013-05-08 21:45:15 +0200207 return __cfg80211_rdev_from_attrs(netns, info->attrs);
Johannes Berga9455402012-06-15 13:32:49 +0200208}
209
Johannes Berg55682962007-09-20 13:09:35 -0400210/* policy for the attributes */
Alexey Dobriyanb54452b2010-02-18 08:14:31 +0000211static const struct nla_policy nl80211_policy[NL80211_ATTR_MAX+1] = {
Johannes Berg55682962007-09-20 13:09:35 -0400212 [NL80211_ATTR_WIPHY] = { .type = NLA_U32 },
213 [NL80211_ATTR_WIPHY_NAME] = { .type = NLA_NUL_STRING,
David S. Miller079e24e2009-05-26 21:15:00 -0700214 .len = 20-1 },
Jouni Malinen31888482008-10-30 16:59:24 +0200215 [NL80211_ATTR_WIPHY_TXQ_PARAMS] = { .type = NLA_NESTED },
Johannes Berg3d9d1d62012-11-08 23:14:50 +0100216
Jouni Malinen72bdcf32008-11-26 16:15:24 +0200217 [NL80211_ATTR_WIPHY_FREQ] = { .type = NLA_U32 },
Sujith094d05d2008-12-12 11:57:43 +0530218 [NL80211_ATTR_WIPHY_CHANNEL_TYPE] = { .type = NLA_U32 },
Johannes Berg3d9d1d62012-11-08 23:14:50 +0100219 [NL80211_ATTR_CHANNEL_WIDTH] = { .type = NLA_U32 },
220 [NL80211_ATTR_CENTER_FREQ1] = { .type = NLA_U32 },
221 [NL80211_ATTR_CENTER_FREQ2] = { .type = NLA_U32 },
222
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +0200223 [NL80211_ATTR_WIPHY_RETRY_SHORT] = { .type = NLA_U8 },
224 [NL80211_ATTR_WIPHY_RETRY_LONG] = { .type = NLA_U8 },
225 [NL80211_ATTR_WIPHY_FRAG_THRESHOLD] = { .type = NLA_U32 },
226 [NL80211_ATTR_WIPHY_RTS_THRESHOLD] = { .type = NLA_U32 },
Lukáš Turek81077e82009-12-21 22:50:47 +0100227 [NL80211_ATTR_WIPHY_COVERAGE_CLASS] = { .type = NLA_U8 },
Johannes Berg55682962007-09-20 13:09:35 -0400228
229 [NL80211_ATTR_IFTYPE] = { .type = NLA_U32 },
230 [NL80211_ATTR_IFINDEX] = { .type = NLA_U32 },
231 [NL80211_ATTR_IFNAME] = { .type = NLA_NUL_STRING, .len = IFNAMSIZ-1 },
Johannes Berg41ade002007-12-19 02:03:29 +0100232
Eliad Pellere007b852011-11-24 18:13:56 +0200233 [NL80211_ATTR_MAC] = { .len = ETH_ALEN },
234 [NL80211_ATTR_PREV_BSSID] = { .len = ETH_ALEN },
Johannes Berg41ade002007-12-19 02:03:29 +0100235
Johannes Bergb9454e82009-07-08 13:29:08 +0200236 [NL80211_ATTR_KEY] = { .type = NLA_NESTED, },
Johannes Berg41ade002007-12-19 02:03:29 +0100237 [NL80211_ATTR_KEY_DATA] = { .type = NLA_BINARY,
238 .len = WLAN_MAX_KEY_LEN },
239 [NL80211_ATTR_KEY_IDX] = { .type = NLA_U8 },
240 [NL80211_ATTR_KEY_CIPHER] = { .type = NLA_U32 },
241 [NL80211_ATTR_KEY_DEFAULT] = { .type = NLA_FLAG },
Jouni Malinen81962262011-11-02 23:36:31 +0200242 [NL80211_ATTR_KEY_SEQ] = { .type = NLA_BINARY, .len = 16 },
Johannes Berge31b8212010-10-05 19:39:30 +0200243 [NL80211_ATTR_KEY_TYPE] = { .type = NLA_U32 },
Johannes Berged1b6cc2007-12-19 02:03:32 +0100244
245 [NL80211_ATTR_BEACON_INTERVAL] = { .type = NLA_U32 },
246 [NL80211_ATTR_DTIM_PERIOD] = { .type = NLA_U32 },
247 [NL80211_ATTR_BEACON_HEAD] = { .type = NLA_BINARY,
248 .len = IEEE80211_MAX_DATA_LEN },
249 [NL80211_ATTR_BEACON_TAIL] = { .type = NLA_BINARY,
250 .len = IEEE80211_MAX_DATA_LEN },
Johannes Berg5727ef12007-12-19 02:03:34 +0100251 [NL80211_ATTR_STA_AID] = { .type = NLA_U16 },
252 [NL80211_ATTR_STA_FLAGS] = { .type = NLA_NESTED },
253 [NL80211_ATTR_STA_LISTEN_INTERVAL] = { .type = NLA_U16 },
254 [NL80211_ATTR_STA_SUPPORTED_RATES] = { .type = NLA_BINARY,
255 .len = NL80211_MAX_SUPP_RATES },
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +0100256 [NL80211_ATTR_STA_PLINK_ACTION] = { .type = NLA_U8 },
Johannes Berg5727ef12007-12-19 02:03:34 +0100257 [NL80211_ATTR_STA_VLAN] = { .type = NLA_U32 },
Johannes Berg0a9542e2008-10-15 11:54:04 +0200258 [NL80211_ATTR_MNTR_FLAGS] = { /* NLA_NESTED can't be empty */ },
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +0100259 [NL80211_ATTR_MESH_ID] = { .type = NLA_BINARY,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +0800260 .len = IEEE80211_MAX_MESH_ID_LEN },
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +0100261 [NL80211_ATTR_MPATH_NEXT_HOP] = { .type = NLA_U32 },
Jouni Malinen9f1ba902008-08-07 20:07:01 +0300262
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -0700263 [NL80211_ATTR_REG_ALPHA2] = { .type = NLA_STRING, .len = 2 },
264 [NL80211_ATTR_REG_RULES] = { .type = NLA_NESTED },
265
Jouni Malinen9f1ba902008-08-07 20:07:01 +0300266 [NL80211_ATTR_BSS_CTS_PROT] = { .type = NLA_U8 },
267 [NL80211_ATTR_BSS_SHORT_PREAMBLE] = { .type = NLA_U8 },
268 [NL80211_ATTR_BSS_SHORT_SLOT_TIME] = { .type = NLA_U8 },
Jouni Malinen90c97a02008-10-30 16:59:22 +0200269 [NL80211_ATTR_BSS_BASIC_RATES] = { .type = NLA_BINARY,
270 .len = NL80211_MAX_SUPP_RATES },
Helmut Schaa50b12f52010-11-19 12:40:25 +0100271 [NL80211_ATTR_BSS_HT_OPMODE] = { .type = NLA_U16 },
Jouni Malinen36aedc92008-08-25 11:58:58 +0300272
Javier Cardona24bdd9f2010-12-16 17:37:48 -0800273 [NL80211_ATTR_MESH_CONFIG] = { .type = NLA_NESTED },
Javier Cardona15d5dda2011-04-07 15:08:28 -0700274 [NL80211_ATTR_SUPPORT_MESH_AUTH] = { .type = NLA_FLAG },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -0700275
Johannes Berg6c739412011-11-03 09:27:01 +0100276 [NL80211_ATTR_HT_CAPABILITY] = { .len = NL80211_HT_CAPABILITY_LEN },
Jouni Malinen9aed3cc2009-01-13 16:03:29 +0200277
278 [NL80211_ATTR_MGMT_SUBTYPE] = { .type = NLA_U8 },
279 [NL80211_ATTR_IE] = { .type = NLA_BINARY,
280 .len = IEEE80211_MAX_DATA_LEN },
Johannes Berg2a519312009-02-10 21:25:55 +0100281 [NL80211_ATTR_SCAN_FREQUENCIES] = { .type = NLA_NESTED },
282 [NL80211_ATTR_SCAN_SSIDS] = { .type = NLA_NESTED },
Jouni Malinen636a5d32009-03-19 13:39:22 +0200283
284 [NL80211_ATTR_SSID] = { .type = NLA_BINARY,
285 .len = IEEE80211_MAX_SSID_LEN },
286 [NL80211_ATTR_AUTH_TYPE] = { .type = NLA_U32 },
287 [NL80211_ATTR_REASON_CODE] = { .type = NLA_U16 },
Johannes Berg04a773a2009-04-19 21:24:32 +0200288 [NL80211_ATTR_FREQ_FIXED] = { .type = NLA_FLAG },
Jouni Malinen1965c852009-04-22 21:38:25 +0300289 [NL80211_ATTR_TIMED_OUT] = { .type = NLA_FLAG },
Jouni Malinendc6382c2009-05-06 22:09:37 +0300290 [NL80211_ATTR_USE_MFP] = { .type = NLA_U32 },
Johannes Bergeccb8e82009-05-11 21:57:56 +0300291 [NL80211_ATTR_STA_FLAGS2] = {
292 .len = sizeof(struct nl80211_sta_flag_update),
293 },
Jouni Malinen3f77316c2009-05-11 21:57:57 +0300294 [NL80211_ATTR_CONTROL_PORT] = { .type = NLA_FLAG },
Johannes Bergc0692b82010-08-27 14:26:53 +0300295 [NL80211_ATTR_CONTROL_PORT_ETHERTYPE] = { .type = NLA_U16 },
296 [NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT] = { .type = NLA_FLAG },
Samuel Ortizb23aa672009-07-01 21:26:54 +0200297 [NL80211_ATTR_PRIVACY] = { .type = NLA_FLAG },
298 [NL80211_ATTR_CIPHER_SUITE_GROUP] = { .type = NLA_U32 },
299 [NL80211_ATTR_WPA_VERSIONS] = { .type = NLA_U32 },
Johannes Berg463d0182009-07-14 00:33:35 +0200300 [NL80211_ATTR_PID] = { .type = NLA_U32 },
Felix Fietkau8b787642009-11-10 18:53:10 +0100301 [NL80211_ATTR_4ADDR] = { .type = NLA_U8 },
Samuel Ortiz67fbb162009-11-24 23:59:15 +0100302 [NL80211_ATTR_PMKID] = { .type = NLA_BINARY,
303 .len = WLAN_PMKID_LEN },
Jouni Malinen9588bbd2009-12-23 13:15:41 +0100304 [NL80211_ATTR_DURATION] = { .type = NLA_U32 },
305 [NL80211_ATTR_COOKIE] = { .type = NLA_U64 },
Jouni Malinen13ae75b2009-12-29 12:59:45 +0200306 [NL80211_ATTR_TX_RATES] = { .type = NLA_NESTED },
Jouni Malinen026331c2010-02-15 12:53:10 +0200307 [NL80211_ATTR_FRAME] = { .type = NLA_BINARY,
308 .len = IEEE80211_MAX_DATA_LEN },
309 [NL80211_ATTR_FRAME_MATCH] = { .type = NLA_BINARY, },
Kalle Valoffb9eb32010-02-17 17:58:10 +0200310 [NL80211_ATTR_PS_STATE] = { .type = NLA_U32 },
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +0200311 [NL80211_ATTR_CQM] = { .type = NLA_NESTED, },
Jouni Malinend5cdfac2010-04-04 09:37:19 +0300312 [NL80211_ATTR_LOCAL_STATE_CHANGE] = { .type = NLA_FLAG },
Felix Fietkaufd8aaaf2010-04-27 01:23:35 +0200313 [NL80211_ATTR_AP_ISOLATE] = { .type = NLA_U8 },
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +0300314 [NL80211_ATTR_WIPHY_TX_POWER_SETTING] = { .type = NLA_U32 },
315 [NL80211_ATTR_WIPHY_TX_POWER_LEVEL] = { .type = NLA_U32 },
Johannes Berg2e161f72010-08-12 15:38:38 +0200316 [NL80211_ATTR_FRAME_TYPE] = { .type = NLA_U16 },
Bruno Randolfafe0cbf2010-11-10 12:50:50 +0900317 [NL80211_ATTR_WIPHY_ANTENNA_TX] = { .type = NLA_U32 },
318 [NL80211_ATTR_WIPHY_ANTENNA_RX] = { .type = NLA_U32 },
Felix Fietkau885a46d2010-11-11 15:07:22 +0100319 [NL80211_ATTR_MCAST_RATE] = { .type = NLA_U32 },
Johannes Bergf7ca38d2010-11-25 10:02:29 +0100320 [NL80211_ATTR_OFFCHANNEL_TX_OK] = { .type = NLA_FLAG },
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100321 [NL80211_ATTR_KEY_DEFAULT_TYPES] = { .type = NLA_NESTED },
Johannes Bergff1b6e62011-05-04 15:37:28 +0200322 [NL80211_ATTR_WOWLAN_TRIGGERS] = { .type = NLA_NESTED },
Javier Cardona9c3990a2011-05-03 16:57:11 -0700323 [NL80211_ATTR_STA_PLINK_STATE] = { .type = NLA_U8 },
Luciano Coelhobbe6ad62011-05-11 17:09:37 +0300324 [NL80211_ATTR_SCHED_SCAN_INTERVAL] = { .type = NLA_U32 },
Johannes Berge5497d72011-07-05 16:35:40 +0200325 [NL80211_ATTR_REKEY_DATA] = { .type = NLA_NESTED },
Johannes Berg34850ab2011-07-18 18:08:35 +0200326 [NL80211_ATTR_SCAN_SUPP_RATES] = { .type = NLA_NESTED },
Jouni Malinen32e9de82011-08-10 23:53:31 +0300327 [NL80211_ATTR_HIDDEN_SSID] = { .type = NLA_U32 },
Jouni Malinen9946ecf2011-08-10 23:55:56 +0300328 [NL80211_ATTR_IE_PROBE_RESP] = { .type = NLA_BINARY,
329 .len = IEEE80211_MAX_DATA_LEN },
330 [NL80211_ATTR_IE_ASSOC_RESP] = { .type = NLA_BINARY,
331 .len = IEEE80211_MAX_DATA_LEN },
Vivek Natarajanf4b34b52011-08-29 14:23:03 +0530332 [NL80211_ATTR_ROAM_SUPPORT] = { .type = NLA_FLAG },
Luciano Coelhoa1f1c212011-08-31 16:01:48 +0300333 [NL80211_ATTR_SCHED_SCAN_MATCH] = { .type = NLA_NESTED },
Rajkumar Manoharane9f935e2011-09-25 14:53:30 +0530334 [NL80211_ATTR_TX_NO_CCK_RATE] = { .type = NLA_FLAG },
Arik Nemtsov109086c2011-09-28 14:12:50 +0300335 [NL80211_ATTR_TDLS_ACTION] = { .type = NLA_U8 },
336 [NL80211_ATTR_TDLS_DIALOG_TOKEN] = { .type = NLA_U8 },
337 [NL80211_ATTR_TDLS_OPERATION] = { .type = NLA_U8 },
338 [NL80211_ATTR_TDLS_SUPPORT] = { .type = NLA_FLAG },
339 [NL80211_ATTR_TDLS_EXTERNAL_SETUP] = { .type = NLA_FLAG },
Johannes Berge247bd902011-11-04 11:18:21 +0100340 [NL80211_ATTR_DONT_WAIT_FOR_ACK] = { .type = NLA_FLAG },
Arik Nemtsov00f740e2011-11-10 11:28:56 +0200341 [NL80211_ATTR_PROBE_RESP] = { .type = NLA_BINARY,
342 .len = IEEE80211_MAX_DATA_LEN },
Luis R. Rodriguez8b60b072011-10-11 10:59:02 -0700343 [NL80211_ATTR_DFS_REGION] = { .type = NLA_U8 },
Ben Greear7e7c8922011-11-18 11:31:59 -0800344 [NL80211_ATTR_DISABLE_HT] = { .type = NLA_FLAG },
345 [NL80211_ATTR_HT_CAPABILITY_MASK] = {
346 .len = NL80211_HT_CAPABILITY_LEN
347 },
Simon Wunderlich1d9d9212011-11-18 14:20:43 +0100348 [NL80211_ATTR_NOACK_MAP] = { .type = NLA_U16 },
Vasanthakumar Thiagarajan1b658f12012-03-02 15:50:02 +0530349 [NL80211_ATTR_INACTIVITY_TIMEOUT] = { .type = NLA_U16 },
Bala Shanmugam4486ea92012-03-07 17:27:12 +0530350 [NL80211_ATTR_BG_SCAN_PERIOD] = { .type = NLA_U16 },
Johannes Berg89a54e42012-06-15 14:33:17 +0200351 [NL80211_ATTR_WDEV] = { .type = NLA_U64 },
Luis R. Rodriguez57b5ce02012-07-12 11:49:18 -0700352 [NL80211_ATTR_USER_REG_HINT_TYPE] = { .type = NLA_U32 },
Jouni Malinene39e5b52012-09-30 19:29:39 +0300353 [NL80211_ATTR_SAE_DATA] = { .type = NLA_BINARY, },
Mahesh Palivelaf461be3e2012-10-11 08:04:52 +0000354 [NL80211_ATTR_VHT_CAPABILITY] = { .len = NL80211_VHT_CAPABILITY_LEN },
Sam Lefflered4737712012-10-11 21:03:31 -0700355 [NL80211_ATTR_SCAN_FLAGS] = { .type = NLA_U32 },
Johannes Berg53cabad2012-11-14 15:17:28 +0100356 [NL80211_ATTR_P2P_CTWINDOW] = { .type = NLA_U8 },
357 [NL80211_ATTR_P2P_OPPPS] = { .type = NLA_U8 },
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +0530358 [NL80211_ATTR_ACL_POLICY] = {. type = NLA_U32 },
359 [NL80211_ATTR_MAC_ADDRS] = { .type = NLA_NESTED },
Jouni Malinen9d62a982013-02-14 21:10:13 +0200360 [NL80211_ATTR_STA_CAPABILITY] = { .type = NLA_U16 },
361 [NL80211_ATTR_STA_EXT_CAPABILITY] = { .type = NLA_BINARY, },
Johannes Berg3713b4e2013-02-14 16:19:38 +0100362 [NL80211_ATTR_SPLIT_WIPHY_DUMP] = { .type = NLA_FLAG, },
Johannes Bergee2aca32013-02-21 17:36:01 +0100363 [NL80211_ATTR_DISABLE_VHT] = { .type = NLA_FLAG },
364 [NL80211_ATTR_VHT_CAPABILITY_MASK] = {
365 .len = NL80211_VHT_CAPABILITY_LEN,
366 },
Jouni Malinen355199e2013-02-27 17:14:27 +0200367 [NL80211_ATTR_MDID] = { .type = NLA_U16 },
368 [NL80211_ATTR_IE_RIC] = { .type = NLA_BINARY,
369 .len = IEEE80211_MAX_DATA_LEN },
Jouni Malinen5e4b6f52013-05-16 20:11:08 +0300370 [NL80211_ATTR_PEER_AID] = { .type = NLA_U16 },
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +0200371 [NL80211_ATTR_CH_SWITCH_COUNT] = { .type = NLA_U32 },
372 [NL80211_ATTR_CH_SWITCH_BLOCK_TX] = { .type = NLA_FLAG },
373 [NL80211_ATTR_CSA_IES] = { .type = NLA_NESTED },
374 [NL80211_ATTR_CSA_C_OFF_BEACON] = { .type = NLA_U16 },
375 [NL80211_ATTR_CSA_C_OFF_PRESP] = { .type = NLA_U16 },
Sunil Duttc01fc9a2013-10-09 20:45:21 +0530376 [NL80211_ATTR_STA_SUPPORTED_CHANNELS] = { .type = NLA_BINARY },
377 [NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES] = { .type = NLA_BINARY },
Simon Wunderlich5336fa82013-10-07 18:41:05 +0200378 [NL80211_ATTR_HANDLE_DFS] = { .type = NLA_FLAG },
Marek Kwaczynski60f4a7b2013-12-03 10:04:59 +0100379 [NL80211_ATTR_OPMODE_NOTIF] = { .type = NLA_U8 },
Johannes Bergad7e7182013-11-13 13:37:47 +0100380 [NL80211_ATTR_VENDOR_ID] = { .type = NLA_U32 },
381 [NL80211_ATTR_VENDOR_SUBCMD] = { .type = NLA_U32 },
382 [NL80211_ATTR_VENDOR_DATA] = { .type = NLA_BINARY },
Kyeyoon Parkfa9ffc72013-12-16 23:01:30 -0800383 [NL80211_ATTR_QOS_MAP] = { .type = NLA_BINARY,
384 .len = IEEE80211_QOS_MAP_LEN_MAX },
Jouni Malinen1df4a512014-01-15 00:00:47 +0200385 [NL80211_ATTR_MAC_HINT] = { .len = ETH_ALEN },
386 [NL80211_ATTR_WIPHY_FREQ_HINT] = { .type = NLA_U32 },
Sunil Dutt Undekaridf942e72014-02-20 16:22:09 +0530387 [NL80211_ATTR_TDLS_PEER_CAPABILITY] = { .type = NLA_U32 },
Johannes Berg78f22b62014-03-24 17:57:27 +0100388 [NL80211_ATTR_IFACE_SOCKET_OWNER] = { .type = NLA_FLAG },
Johannes Berg55682962007-09-20 13:09:35 -0400389};
390
Johannes Berge31b8212010-10-05 19:39:30 +0200391/* policy for the key attributes */
Alexey Dobriyanb54452b2010-02-18 08:14:31 +0000392static const struct nla_policy nl80211_key_policy[NL80211_KEY_MAX + 1] = {
Johannes Bergfffd0932009-07-08 14:22:54 +0200393 [NL80211_KEY_DATA] = { .type = NLA_BINARY, .len = WLAN_MAX_KEY_LEN },
Johannes Bergb9454e82009-07-08 13:29:08 +0200394 [NL80211_KEY_IDX] = { .type = NLA_U8 },
395 [NL80211_KEY_CIPHER] = { .type = NLA_U32 },
Jouni Malinen81962262011-11-02 23:36:31 +0200396 [NL80211_KEY_SEQ] = { .type = NLA_BINARY, .len = 16 },
Johannes Bergb9454e82009-07-08 13:29:08 +0200397 [NL80211_KEY_DEFAULT] = { .type = NLA_FLAG },
398 [NL80211_KEY_DEFAULT_MGMT] = { .type = NLA_FLAG },
Johannes Berge31b8212010-10-05 19:39:30 +0200399 [NL80211_KEY_TYPE] = { .type = NLA_U32 },
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100400 [NL80211_KEY_DEFAULT_TYPES] = { .type = NLA_NESTED },
401};
402
403/* policy for the key default flags */
404static const struct nla_policy
405nl80211_key_default_policy[NUM_NL80211_KEY_DEFAULT_TYPES] = {
406 [NL80211_KEY_DEFAULT_TYPE_UNICAST] = { .type = NLA_FLAG },
407 [NL80211_KEY_DEFAULT_TYPE_MULTICAST] = { .type = NLA_FLAG },
Johannes Bergb9454e82009-07-08 13:29:08 +0200408};
409
Johannes Bergff1b6e62011-05-04 15:37:28 +0200410/* policy for WoWLAN attributes */
411static const struct nla_policy
412nl80211_wowlan_policy[NUM_NL80211_WOWLAN_TRIG] = {
413 [NL80211_WOWLAN_TRIG_ANY] = { .type = NLA_FLAG },
414 [NL80211_WOWLAN_TRIG_DISCONNECT] = { .type = NLA_FLAG },
415 [NL80211_WOWLAN_TRIG_MAGIC_PKT] = { .type = NLA_FLAG },
416 [NL80211_WOWLAN_TRIG_PKT_PATTERN] = { .type = NLA_NESTED },
Johannes Berg77dbbb12011-07-13 10:48:55 +0200417 [NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE] = { .type = NLA_FLAG },
418 [NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST] = { .type = NLA_FLAG },
419 [NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE] = { .type = NLA_FLAG },
420 [NL80211_WOWLAN_TRIG_RFKILL_RELEASE] = { .type = NLA_FLAG },
Johannes Berg2a0e0472013-01-23 22:57:40 +0100421 [NL80211_WOWLAN_TRIG_TCP_CONNECTION] = { .type = NLA_NESTED },
422};
423
424static const struct nla_policy
425nl80211_wowlan_tcp_policy[NUM_NL80211_WOWLAN_TCP] = {
426 [NL80211_WOWLAN_TCP_SRC_IPV4] = { .type = NLA_U32 },
427 [NL80211_WOWLAN_TCP_DST_IPV4] = { .type = NLA_U32 },
428 [NL80211_WOWLAN_TCP_DST_MAC] = { .len = ETH_ALEN },
429 [NL80211_WOWLAN_TCP_SRC_PORT] = { .type = NLA_U16 },
430 [NL80211_WOWLAN_TCP_DST_PORT] = { .type = NLA_U16 },
431 [NL80211_WOWLAN_TCP_DATA_PAYLOAD] = { .len = 1 },
432 [NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ] = {
433 .len = sizeof(struct nl80211_wowlan_tcp_data_seq)
434 },
435 [NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN] = {
436 .len = sizeof(struct nl80211_wowlan_tcp_data_token)
437 },
438 [NL80211_WOWLAN_TCP_DATA_INTERVAL] = { .type = NLA_U32 },
439 [NL80211_WOWLAN_TCP_WAKE_PAYLOAD] = { .len = 1 },
440 [NL80211_WOWLAN_TCP_WAKE_MASK] = { .len = 1 },
Johannes Bergff1b6e62011-05-04 15:37:28 +0200441};
442
Amitkumar Karwarbe29b992013-06-28 11:51:26 -0700443/* policy for coalesce rule attributes */
444static const struct nla_policy
445nl80211_coalesce_policy[NUM_NL80211_ATTR_COALESCE_RULE] = {
446 [NL80211_ATTR_COALESCE_RULE_DELAY] = { .type = NLA_U32 },
447 [NL80211_ATTR_COALESCE_RULE_CONDITION] = { .type = NLA_U32 },
448 [NL80211_ATTR_COALESCE_RULE_PKT_PATTERN] = { .type = NLA_NESTED },
449};
450
Johannes Berge5497d72011-07-05 16:35:40 +0200451/* policy for GTK rekey offload attributes */
452static const struct nla_policy
453nl80211_rekey_policy[NUM_NL80211_REKEY_DATA] = {
454 [NL80211_REKEY_DATA_KEK] = { .len = NL80211_KEK_LEN },
455 [NL80211_REKEY_DATA_KCK] = { .len = NL80211_KCK_LEN },
456 [NL80211_REKEY_DATA_REPLAY_CTR] = { .len = NL80211_REPLAY_CTR_LEN },
457};
458
Luciano Coelhoa1f1c212011-08-31 16:01:48 +0300459static const struct nla_policy
460nl80211_match_policy[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1] = {
Johannes Berg4a4ab0d2012-06-13 11:17:11 +0200461 [NL80211_SCHED_SCAN_MATCH_ATTR_SSID] = { .type = NLA_BINARY,
Luciano Coelhoa1f1c212011-08-31 16:01:48 +0300462 .len = IEEE80211_MAX_SSID_LEN },
Thomas Pedersen88e920b2012-06-21 11:09:54 -0700463 [NL80211_SCHED_SCAN_MATCH_ATTR_RSSI] = { .type = NLA_U32 },
Luciano Coelhoa1f1c212011-08-31 16:01:48 +0300464};
465
Johannes Berg97990a02013-04-19 01:02:55 +0200466static int nl80211_prepare_wdev_dump(struct sk_buff *skb,
467 struct netlink_callback *cb,
468 struct cfg80211_registered_device **rdev,
469 struct wireless_dev **wdev)
Holger Schuriga0438972009-11-11 11:30:02 +0100470{
Johannes Berg67748892010-10-04 21:14:06 +0200471 int err;
472
Johannes Berg67748892010-10-04 21:14:06 +0200473 rtnl_lock();
474
Johannes Berg97990a02013-04-19 01:02:55 +0200475 if (!cb->args[0]) {
476 err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize,
477 nl80211_fam.attrbuf, nl80211_fam.maxattr,
478 nl80211_policy);
479 if (err)
480 goto out_unlock;
481
482 *wdev = __cfg80211_wdev_from_attrs(sock_net(skb->sk),
483 nl80211_fam.attrbuf);
484 if (IS_ERR(*wdev)) {
485 err = PTR_ERR(*wdev);
486 goto out_unlock;
487 }
Zhao, Gangf26cbf42014-04-21 12:53:03 +0800488 *rdev = wiphy_to_rdev((*wdev)->wiphy);
Johannes Bergc319d502013-07-30 22:34:28 +0200489 /* 0 is the first index - add 1 to parse only once */
490 cb->args[0] = (*rdev)->wiphy_idx + 1;
Johannes Berg97990a02013-04-19 01:02:55 +0200491 cb->args[1] = (*wdev)->identifier;
492 } else {
Johannes Bergc319d502013-07-30 22:34:28 +0200493 /* subtract the 1 again here */
494 struct wiphy *wiphy = wiphy_idx_to_wiphy(cb->args[0] - 1);
Johannes Berg97990a02013-04-19 01:02:55 +0200495 struct wireless_dev *tmp;
496
497 if (!wiphy) {
498 err = -ENODEV;
499 goto out_unlock;
500 }
Zhao, Gangf26cbf42014-04-21 12:53:03 +0800501 *rdev = wiphy_to_rdev(wiphy);
Johannes Berg97990a02013-04-19 01:02:55 +0200502 *wdev = NULL;
503
Johannes Berg97990a02013-04-19 01:02:55 +0200504 list_for_each_entry(tmp, &(*rdev)->wdev_list, list) {
505 if (tmp->identifier == cb->args[1]) {
506 *wdev = tmp;
507 break;
508 }
509 }
Johannes Berg97990a02013-04-19 01:02:55 +0200510
511 if (!*wdev) {
512 err = -ENODEV;
513 goto out_unlock;
514 }
Johannes Berg67748892010-10-04 21:14:06 +0200515 }
516
Johannes Berg67748892010-10-04 21:14:06 +0200517 return 0;
Johannes Berg97990a02013-04-19 01:02:55 +0200518 out_unlock:
Johannes Berg67748892010-10-04 21:14:06 +0200519 rtnl_unlock();
520 return err;
521}
522
Johannes Berg97990a02013-04-19 01:02:55 +0200523static void nl80211_finish_wdev_dump(struct cfg80211_registered_device *rdev)
Johannes Berg67748892010-10-04 21:14:06 +0200524{
Johannes Berg67748892010-10-04 21:14:06 +0200525 rtnl_unlock();
526}
527
Johannes Bergf4a11bb2009-03-27 12:40:28 +0100528/* IE validation */
529static bool is_valid_ie_attr(const struct nlattr *attr)
530{
531 const u8 *pos;
532 int len;
533
534 if (!attr)
535 return true;
536
537 pos = nla_data(attr);
538 len = nla_len(attr);
539
540 while (len) {
541 u8 elemlen;
542
543 if (len < 2)
544 return false;
545 len -= 2;
546
547 elemlen = pos[1];
548 if (elemlen > len)
549 return false;
550
551 len -= elemlen;
552 pos += 2 + elemlen;
553 }
554
555 return true;
556}
557
Johannes Berg55682962007-09-20 13:09:35 -0400558/* message building helper */
Eric W. Biederman15e47302012-09-07 20:12:54 +0000559static inline void *nl80211hdr_put(struct sk_buff *skb, u32 portid, u32 seq,
Johannes Berg55682962007-09-20 13:09:35 -0400560 int flags, u8 cmd)
561{
562 /* since there is no private header just add the generic one */
Eric W. Biederman15e47302012-09-07 20:12:54 +0000563 return genlmsg_put(skb, portid, seq, &nl80211_fam, flags, cmd);
Johannes Berg55682962007-09-20 13:09:35 -0400564}
565
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400566static int nl80211_msg_put_channel(struct sk_buff *msg,
Johannes Bergcdc89b92013-02-18 23:54:36 +0100567 struct ieee80211_channel *chan,
568 bool large)
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400569{
Rostislav Lisovyea077c12014-04-15 14:37:55 +0200570 /* Some channels must be completely excluded from the
571 * list to protect old user-space tools from breaking
572 */
573 if (!large && chan->flags &
574 (IEEE80211_CHAN_NO_10MHZ | IEEE80211_CHAN_NO_20MHZ))
575 return 0;
576
David S. Miller9360ffd2012-03-29 04:41:26 -0400577 if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_FREQ,
578 chan->center_freq))
579 goto nla_put_failure;
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400580
David S. Miller9360ffd2012-03-29 04:41:26 -0400581 if ((chan->flags & IEEE80211_CHAN_DISABLED) &&
582 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_DISABLED))
583 goto nla_put_failure;
Luis R. Rodriguez8fe02e12013-10-21 19:22:25 +0200584 if (chan->flags & IEEE80211_CHAN_NO_IR) {
585 if (nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_IR))
586 goto nla_put_failure;
587 if (nla_put_flag(msg, __NL80211_FREQUENCY_ATTR_NO_IBSS))
588 goto nla_put_failure;
589 }
Johannes Bergcdc89b92013-02-18 23:54:36 +0100590 if (chan->flags & IEEE80211_CHAN_RADAR) {
591 if (nla_put_flag(msg, NL80211_FREQUENCY_ATTR_RADAR))
592 goto nla_put_failure;
593 if (large) {
594 u32 time;
595
596 time = elapsed_jiffies_msecs(chan->dfs_state_entered);
597
598 if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_DFS_STATE,
599 chan->dfs_state))
600 goto nla_put_failure;
601 if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_DFS_TIME,
602 time))
603 goto nla_put_failure;
Janusz Dziedzic089027e2014-02-21 19:46:12 +0100604 if (nla_put_u32(msg,
605 NL80211_FREQUENCY_ATTR_DFS_CAC_TIME,
606 chan->dfs_cac_ms))
607 goto nla_put_failure;
Johannes Bergcdc89b92013-02-18 23:54:36 +0100608 }
609 }
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400610
Johannes Bergfe1abaf2013-02-27 15:39:45 +0100611 if (large) {
612 if ((chan->flags & IEEE80211_CHAN_NO_HT40MINUS) &&
613 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_HT40_MINUS))
614 goto nla_put_failure;
615 if ((chan->flags & IEEE80211_CHAN_NO_HT40PLUS) &&
616 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_HT40_PLUS))
617 goto nla_put_failure;
618 if ((chan->flags & IEEE80211_CHAN_NO_80MHZ) &&
619 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_80MHZ))
620 goto nla_put_failure;
621 if ((chan->flags & IEEE80211_CHAN_NO_160MHZ) &&
622 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_160MHZ))
623 goto nla_put_failure;
David Spinadel570dbde2014-02-23 09:12:59 +0200624 if ((chan->flags & IEEE80211_CHAN_INDOOR_ONLY) &&
625 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_INDOOR_ONLY))
626 goto nla_put_failure;
627 if ((chan->flags & IEEE80211_CHAN_GO_CONCURRENT) &&
628 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_GO_CONCURRENT))
629 goto nla_put_failure;
Rostislav Lisovyea077c12014-04-15 14:37:55 +0200630 if ((chan->flags & IEEE80211_CHAN_NO_20MHZ) &&
631 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_20MHZ))
632 goto nla_put_failure;
633 if ((chan->flags & IEEE80211_CHAN_NO_10MHZ) &&
634 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_10MHZ))
635 goto nla_put_failure;
Johannes Bergfe1abaf2013-02-27 15:39:45 +0100636 }
637
David S. Miller9360ffd2012-03-29 04:41:26 -0400638 if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_MAX_TX_POWER,
639 DBM_TO_MBM(chan->max_power)))
640 goto nla_put_failure;
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400641
642 return 0;
643
644 nla_put_failure:
645 return -ENOBUFS;
646}
647
Johannes Berg55682962007-09-20 13:09:35 -0400648/* netlink command implementations */
649
Johannes Bergb9454e82009-07-08 13:29:08 +0200650struct key_parse {
651 struct key_params p;
652 int idx;
Johannes Berge31b8212010-10-05 19:39:30 +0200653 int type;
Johannes Bergb9454e82009-07-08 13:29:08 +0200654 bool def, defmgmt;
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100655 bool def_uni, def_multi;
Johannes Bergb9454e82009-07-08 13:29:08 +0200656};
657
658static int nl80211_parse_key_new(struct nlattr *key, struct key_parse *k)
659{
660 struct nlattr *tb[NL80211_KEY_MAX + 1];
661 int err = nla_parse_nested(tb, NL80211_KEY_MAX, key,
662 nl80211_key_policy);
663 if (err)
664 return err;
665
666 k->def = !!tb[NL80211_KEY_DEFAULT];
667 k->defmgmt = !!tb[NL80211_KEY_DEFAULT_MGMT];
668
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100669 if (k->def) {
670 k->def_uni = true;
671 k->def_multi = true;
672 }
673 if (k->defmgmt)
674 k->def_multi = true;
675
Johannes Bergb9454e82009-07-08 13:29:08 +0200676 if (tb[NL80211_KEY_IDX])
677 k->idx = nla_get_u8(tb[NL80211_KEY_IDX]);
678
679 if (tb[NL80211_KEY_DATA]) {
680 k->p.key = nla_data(tb[NL80211_KEY_DATA]);
681 k->p.key_len = nla_len(tb[NL80211_KEY_DATA]);
682 }
683
684 if (tb[NL80211_KEY_SEQ]) {
685 k->p.seq = nla_data(tb[NL80211_KEY_SEQ]);
686 k->p.seq_len = nla_len(tb[NL80211_KEY_SEQ]);
687 }
688
689 if (tb[NL80211_KEY_CIPHER])
690 k->p.cipher = nla_get_u32(tb[NL80211_KEY_CIPHER]);
691
Johannes Berge31b8212010-10-05 19:39:30 +0200692 if (tb[NL80211_KEY_TYPE]) {
693 k->type = nla_get_u32(tb[NL80211_KEY_TYPE]);
694 if (k->type < 0 || k->type >= NUM_NL80211_KEYTYPES)
695 return -EINVAL;
696 }
697
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100698 if (tb[NL80211_KEY_DEFAULT_TYPES]) {
699 struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES];
Johannes Berg2da8f412012-01-20 13:52:37 +0100700 err = nla_parse_nested(kdt, NUM_NL80211_KEY_DEFAULT_TYPES - 1,
701 tb[NL80211_KEY_DEFAULT_TYPES],
702 nl80211_key_default_policy);
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100703 if (err)
704 return err;
705
706 k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST];
707 k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST];
708 }
709
Johannes Bergb9454e82009-07-08 13:29:08 +0200710 return 0;
711}
712
713static int nl80211_parse_key_old(struct genl_info *info, struct key_parse *k)
714{
715 if (info->attrs[NL80211_ATTR_KEY_DATA]) {
716 k->p.key = nla_data(info->attrs[NL80211_ATTR_KEY_DATA]);
717 k->p.key_len = nla_len(info->attrs[NL80211_ATTR_KEY_DATA]);
718 }
719
720 if (info->attrs[NL80211_ATTR_KEY_SEQ]) {
721 k->p.seq = nla_data(info->attrs[NL80211_ATTR_KEY_SEQ]);
722 k->p.seq_len = nla_len(info->attrs[NL80211_ATTR_KEY_SEQ]);
723 }
724
725 if (info->attrs[NL80211_ATTR_KEY_IDX])
726 k->idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]);
727
728 if (info->attrs[NL80211_ATTR_KEY_CIPHER])
729 k->p.cipher = nla_get_u32(info->attrs[NL80211_ATTR_KEY_CIPHER]);
730
731 k->def = !!info->attrs[NL80211_ATTR_KEY_DEFAULT];
732 k->defmgmt = !!info->attrs[NL80211_ATTR_KEY_DEFAULT_MGMT];
733
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100734 if (k->def) {
735 k->def_uni = true;
736 k->def_multi = true;
737 }
738 if (k->defmgmt)
739 k->def_multi = true;
740
Johannes Berge31b8212010-10-05 19:39:30 +0200741 if (info->attrs[NL80211_ATTR_KEY_TYPE]) {
742 k->type = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]);
743 if (k->type < 0 || k->type >= NUM_NL80211_KEYTYPES)
744 return -EINVAL;
745 }
746
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100747 if (info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES]) {
748 struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES];
749 int err = nla_parse_nested(
750 kdt, NUM_NL80211_KEY_DEFAULT_TYPES - 1,
751 info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES],
752 nl80211_key_default_policy);
753 if (err)
754 return err;
755
756 k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST];
757 k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST];
758 }
759
Johannes Bergb9454e82009-07-08 13:29:08 +0200760 return 0;
761}
762
763static int nl80211_parse_key(struct genl_info *info, struct key_parse *k)
764{
765 int err;
766
767 memset(k, 0, sizeof(*k));
768 k->idx = -1;
Johannes Berge31b8212010-10-05 19:39:30 +0200769 k->type = -1;
Johannes Bergb9454e82009-07-08 13:29:08 +0200770
771 if (info->attrs[NL80211_ATTR_KEY])
772 err = nl80211_parse_key_new(info->attrs[NL80211_ATTR_KEY], k);
773 else
774 err = nl80211_parse_key_old(info, k);
775
776 if (err)
777 return err;
778
779 if (k->def && k->defmgmt)
780 return -EINVAL;
781
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100782 if (k->defmgmt) {
783 if (k->def_uni || !k->def_multi)
784 return -EINVAL;
785 }
786
Johannes Bergb9454e82009-07-08 13:29:08 +0200787 if (k->idx != -1) {
788 if (k->defmgmt) {
789 if (k->idx < 4 || k->idx > 5)
790 return -EINVAL;
791 } else if (k->def) {
792 if (k->idx < 0 || k->idx > 3)
793 return -EINVAL;
794 } else {
795 if (k->idx < 0 || k->idx > 5)
796 return -EINVAL;
797 }
798 }
799
800 return 0;
801}
802
Johannes Bergfffd0932009-07-08 14:22:54 +0200803static struct cfg80211_cached_keys *
804nl80211_parse_connkeys(struct cfg80211_registered_device *rdev,
Sujith Manoharande7044e2012-10-18 10:19:28 +0530805 struct nlattr *keys, bool *no_ht)
Johannes Bergfffd0932009-07-08 14:22:54 +0200806{
807 struct key_parse parse;
808 struct nlattr *key;
809 struct cfg80211_cached_keys *result;
810 int rem, err, def = 0;
811
812 result = kzalloc(sizeof(*result), GFP_KERNEL);
813 if (!result)
814 return ERR_PTR(-ENOMEM);
815
816 result->def = -1;
817 result->defmgmt = -1;
818
819 nla_for_each_nested(key, keys, rem) {
820 memset(&parse, 0, sizeof(parse));
821 parse.idx = -1;
822
823 err = nl80211_parse_key_new(key, &parse);
824 if (err)
825 goto error;
826 err = -EINVAL;
827 if (!parse.p.key)
828 goto error;
829 if (parse.idx < 0 || parse.idx > 4)
830 goto error;
831 if (parse.def) {
832 if (def)
833 goto error;
834 def = 1;
835 result->def = parse.idx;
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100836 if (!parse.def_uni || !parse.def_multi)
837 goto error;
Johannes Bergfffd0932009-07-08 14:22:54 +0200838 } else if (parse.defmgmt)
839 goto error;
840 err = cfg80211_validate_key_settings(rdev, &parse.p,
Johannes Berge31b8212010-10-05 19:39:30 +0200841 parse.idx, false, NULL);
Johannes Bergfffd0932009-07-08 14:22:54 +0200842 if (err)
843 goto error;
844 result->params[parse.idx].cipher = parse.p.cipher;
845 result->params[parse.idx].key_len = parse.p.key_len;
846 result->params[parse.idx].key = result->data[parse.idx];
847 memcpy(result->data[parse.idx], parse.p.key, parse.p.key_len);
Sujith Manoharande7044e2012-10-18 10:19:28 +0530848
849 if (parse.p.cipher == WLAN_CIPHER_SUITE_WEP40 ||
850 parse.p.cipher == WLAN_CIPHER_SUITE_WEP104) {
851 if (no_ht)
852 *no_ht = true;
853 }
Johannes Bergfffd0932009-07-08 14:22:54 +0200854 }
855
856 return result;
857 error:
858 kfree(result);
859 return ERR_PTR(err);
860}
861
862static int nl80211_key_allowed(struct wireless_dev *wdev)
863{
864 ASSERT_WDEV_LOCK(wdev);
865
Johannes Bergfffd0932009-07-08 14:22:54 +0200866 switch (wdev->iftype) {
867 case NL80211_IFTYPE_AP:
868 case NL80211_IFTYPE_AP_VLAN:
Johannes Berg074ac8d2010-09-16 14:58:22 +0200869 case NL80211_IFTYPE_P2P_GO:
Thomas Pedersenff973af2011-05-03 16:57:12 -0700870 case NL80211_IFTYPE_MESH_POINT:
Johannes Bergfffd0932009-07-08 14:22:54 +0200871 break;
872 case NL80211_IFTYPE_ADHOC:
Johannes Bergfffd0932009-07-08 14:22:54 +0200873 case NL80211_IFTYPE_STATION:
Johannes Berg074ac8d2010-09-16 14:58:22 +0200874 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Bergceca7b72013-05-16 00:55:45 +0200875 if (!wdev->current_bss)
Johannes Bergfffd0932009-07-08 14:22:54 +0200876 return -ENOLINK;
877 break;
878 default:
879 return -EINVAL;
880 }
881
882 return 0;
883}
884
Jouni Malinen664834d2014-01-15 00:01:44 +0200885static struct ieee80211_channel *nl80211_get_valid_chan(struct wiphy *wiphy,
886 struct nlattr *tb)
887{
888 struct ieee80211_channel *chan;
889
890 if (tb == NULL)
891 return NULL;
892 chan = ieee80211_get_channel(wiphy, nla_get_u32(tb));
893 if (!chan || chan->flags & IEEE80211_CHAN_DISABLED)
894 return NULL;
895 return chan;
896}
897
Johannes Berg7527a782011-05-13 10:58:57 +0200898static int nl80211_put_iftypes(struct sk_buff *msg, u32 attr, u16 ifmodes)
899{
900 struct nlattr *nl_modes = nla_nest_start(msg, attr);
901 int i;
902
903 if (!nl_modes)
904 goto nla_put_failure;
905
906 i = 0;
907 while (ifmodes) {
David S. Miller9360ffd2012-03-29 04:41:26 -0400908 if ((ifmodes & 1) && nla_put_flag(msg, i))
909 goto nla_put_failure;
Johannes Berg7527a782011-05-13 10:58:57 +0200910 ifmodes >>= 1;
911 i++;
912 }
913
914 nla_nest_end(msg, nl_modes);
915 return 0;
916
917nla_put_failure:
918 return -ENOBUFS;
919}
920
921static int nl80211_put_iface_combinations(struct wiphy *wiphy,
Johannes Bergcdc89b92013-02-18 23:54:36 +0100922 struct sk_buff *msg,
923 bool large)
Johannes Berg7527a782011-05-13 10:58:57 +0200924{
925 struct nlattr *nl_combis;
926 int i, j;
927
928 nl_combis = nla_nest_start(msg,
929 NL80211_ATTR_INTERFACE_COMBINATIONS);
930 if (!nl_combis)
931 goto nla_put_failure;
932
933 for (i = 0; i < wiphy->n_iface_combinations; i++) {
934 const struct ieee80211_iface_combination *c;
935 struct nlattr *nl_combi, *nl_limits;
936
937 c = &wiphy->iface_combinations[i];
938
939 nl_combi = nla_nest_start(msg, i + 1);
940 if (!nl_combi)
941 goto nla_put_failure;
942
943 nl_limits = nla_nest_start(msg, NL80211_IFACE_COMB_LIMITS);
944 if (!nl_limits)
945 goto nla_put_failure;
946
947 for (j = 0; j < c->n_limits; j++) {
948 struct nlattr *nl_limit;
949
950 nl_limit = nla_nest_start(msg, j + 1);
951 if (!nl_limit)
952 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -0400953 if (nla_put_u32(msg, NL80211_IFACE_LIMIT_MAX,
954 c->limits[j].max))
955 goto nla_put_failure;
Johannes Berg7527a782011-05-13 10:58:57 +0200956 if (nl80211_put_iftypes(msg, NL80211_IFACE_LIMIT_TYPES,
957 c->limits[j].types))
958 goto nla_put_failure;
959 nla_nest_end(msg, nl_limit);
960 }
961
962 nla_nest_end(msg, nl_limits);
963
David S. Miller9360ffd2012-03-29 04:41:26 -0400964 if (c->beacon_int_infra_match &&
965 nla_put_flag(msg, NL80211_IFACE_COMB_STA_AP_BI_MATCH))
966 goto nla_put_failure;
967 if (nla_put_u32(msg, NL80211_IFACE_COMB_NUM_CHANNELS,
968 c->num_different_channels) ||
969 nla_put_u32(msg, NL80211_IFACE_COMB_MAXNUM,
970 c->max_interfaces))
971 goto nla_put_failure;
Johannes Bergcdc89b92013-02-18 23:54:36 +0100972 if (large &&
973 nla_put_u32(msg, NL80211_IFACE_COMB_RADAR_DETECT_WIDTHS,
974 c->radar_detect_widths))
975 goto nla_put_failure;
Johannes Berg7527a782011-05-13 10:58:57 +0200976
977 nla_nest_end(msg, nl_combi);
978 }
979
980 nla_nest_end(msg, nl_combis);
981
982 return 0;
983nla_put_failure:
984 return -ENOBUFS;
985}
986
Johannes Berg3713b4e2013-02-14 16:19:38 +0100987#ifdef CONFIG_PM
Johannes Bergb56cf722013-02-20 01:02:38 +0100988static int nl80211_send_wowlan_tcp_caps(struct cfg80211_registered_device *rdev,
989 struct sk_buff *msg)
990{
Johannes Berg964dc9e2013-06-03 17:25:34 +0200991 const struct wiphy_wowlan_tcp_support *tcp = rdev->wiphy.wowlan->tcp;
Johannes Bergb56cf722013-02-20 01:02:38 +0100992 struct nlattr *nl_tcp;
993
994 if (!tcp)
995 return 0;
996
997 nl_tcp = nla_nest_start(msg, NL80211_WOWLAN_TRIG_TCP_CONNECTION);
998 if (!nl_tcp)
999 return -ENOBUFS;
1000
1001 if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD,
1002 tcp->data_payload_max))
1003 return -ENOBUFS;
1004
1005 if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD,
1006 tcp->data_payload_max))
1007 return -ENOBUFS;
1008
1009 if (tcp->seq && nla_put_flag(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ))
1010 return -ENOBUFS;
1011
1012 if (tcp->tok && nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN,
1013 sizeof(*tcp->tok), tcp->tok))
1014 return -ENOBUFS;
1015
1016 if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_INTERVAL,
1017 tcp->data_interval_max))
1018 return -ENOBUFS;
1019
1020 if (nla_put_u32(msg, NL80211_WOWLAN_TCP_WAKE_PAYLOAD,
1021 tcp->wake_payload_max))
1022 return -ENOBUFS;
1023
1024 nla_nest_end(msg, nl_tcp);
1025 return 0;
1026}
1027
Johannes Berg3713b4e2013-02-14 16:19:38 +01001028static int nl80211_send_wowlan(struct sk_buff *msg,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001029 struct cfg80211_registered_device *rdev,
Johannes Bergb56cf722013-02-20 01:02:38 +01001030 bool large)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001031{
1032 struct nlattr *nl_wowlan;
1033
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001034 if (!rdev->wiphy.wowlan)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001035 return 0;
1036
1037 nl_wowlan = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS_SUPPORTED);
1038 if (!nl_wowlan)
1039 return -ENOBUFS;
1040
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001041 if (((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_ANY) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001042 nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) ||
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001043 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_DISCONNECT) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001044 nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) ||
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001045 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001046 nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) ||
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001047 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_SUPPORTS_GTK_REKEY) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001048 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED)) ||
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001049 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001050 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) ||
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001051 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001052 nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) ||
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001053 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001054 nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) ||
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001055 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001056 nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE)))
1057 return -ENOBUFS;
1058
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001059 if (rdev->wiphy.wowlan->n_patterns) {
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07001060 struct nl80211_pattern_support pat = {
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001061 .max_patterns = rdev->wiphy.wowlan->n_patterns,
1062 .min_pattern_len = rdev->wiphy.wowlan->pattern_min_len,
1063 .max_pattern_len = rdev->wiphy.wowlan->pattern_max_len,
1064 .max_pkt_offset = rdev->wiphy.wowlan->max_pkt_offset,
Johannes Berg3713b4e2013-02-14 16:19:38 +01001065 };
1066
1067 if (nla_put(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN,
1068 sizeof(pat), &pat))
1069 return -ENOBUFS;
1070 }
1071
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001072 if (large && nl80211_send_wowlan_tcp_caps(rdev, msg))
Johannes Bergb56cf722013-02-20 01:02:38 +01001073 return -ENOBUFS;
1074
Johannes Berg3713b4e2013-02-14 16:19:38 +01001075 nla_nest_end(msg, nl_wowlan);
1076
1077 return 0;
1078}
1079#endif
1080
Amitkumar Karwarbe29b992013-06-28 11:51:26 -07001081static int nl80211_send_coalesce(struct sk_buff *msg,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001082 struct cfg80211_registered_device *rdev)
Amitkumar Karwarbe29b992013-06-28 11:51:26 -07001083{
1084 struct nl80211_coalesce_rule_support rule;
1085
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001086 if (!rdev->wiphy.coalesce)
Amitkumar Karwarbe29b992013-06-28 11:51:26 -07001087 return 0;
1088
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001089 rule.max_rules = rdev->wiphy.coalesce->n_rules;
1090 rule.max_delay = rdev->wiphy.coalesce->max_delay;
1091 rule.pat.max_patterns = rdev->wiphy.coalesce->n_patterns;
1092 rule.pat.min_pattern_len = rdev->wiphy.coalesce->pattern_min_len;
1093 rule.pat.max_pattern_len = rdev->wiphy.coalesce->pattern_max_len;
1094 rule.pat.max_pkt_offset = rdev->wiphy.coalesce->max_pkt_offset;
Amitkumar Karwarbe29b992013-06-28 11:51:26 -07001095
1096 if (nla_put(msg, NL80211_ATTR_COALESCE_RULE, sizeof(rule), &rule))
1097 return -ENOBUFS;
1098
1099 return 0;
1100}
1101
Johannes Berg3713b4e2013-02-14 16:19:38 +01001102static int nl80211_send_band_rateinfo(struct sk_buff *msg,
1103 struct ieee80211_supported_band *sband)
1104{
1105 struct nlattr *nl_rates, *nl_rate;
1106 struct ieee80211_rate *rate;
1107 int i;
1108
1109 /* add HT info */
1110 if (sband->ht_cap.ht_supported &&
1111 (nla_put(msg, NL80211_BAND_ATTR_HT_MCS_SET,
1112 sizeof(sband->ht_cap.mcs),
1113 &sband->ht_cap.mcs) ||
1114 nla_put_u16(msg, NL80211_BAND_ATTR_HT_CAPA,
1115 sband->ht_cap.cap) ||
1116 nla_put_u8(msg, NL80211_BAND_ATTR_HT_AMPDU_FACTOR,
1117 sband->ht_cap.ampdu_factor) ||
1118 nla_put_u8(msg, NL80211_BAND_ATTR_HT_AMPDU_DENSITY,
1119 sband->ht_cap.ampdu_density)))
1120 return -ENOBUFS;
1121
1122 /* add VHT info */
1123 if (sband->vht_cap.vht_supported &&
1124 (nla_put(msg, NL80211_BAND_ATTR_VHT_MCS_SET,
1125 sizeof(sband->vht_cap.vht_mcs),
1126 &sband->vht_cap.vht_mcs) ||
1127 nla_put_u32(msg, NL80211_BAND_ATTR_VHT_CAPA,
1128 sband->vht_cap.cap)))
1129 return -ENOBUFS;
1130
1131 /* add bitrates */
1132 nl_rates = nla_nest_start(msg, NL80211_BAND_ATTR_RATES);
1133 if (!nl_rates)
1134 return -ENOBUFS;
1135
1136 for (i = 0; i < sband->n_bitrates; i++) {
1137 nl_rate = nla_nest_start(msg, i);
1138 if (!nl_rate)
1139 return -ENOBUFS;
1140
1141 rate = &sband->bitrates[i];
1142 if (nla_put_u32(msg, NL80211_BITRATE_ATTR_RATE,
1143 rate->bitrate))
1144 return -ENOBUFS;
1145 if ((rate->flags & IEEE80211_RATE_SHORT_PREAMBLE) &&
1146 nla_put_flag(msg,
1147 NL80211_BITRATE_ATTR_2GHZ_SHORTPREAMBLE))
1148 return -ENOBUFS;
1149
1150 nla_nest_end(msg, nl_rate);
1151 }
1152
1153 nla_nest_end(msg, nl_rates);
1154
1155 return 0;
1156}
1157
1158static int
1159nl80211_send_mgmt_stypes(struct sk_buff *msg,
1160 const struct ieee80211_txrx_stypes *mgmt_stypes)
1161{
1162 u16 stypes;
1163 struct nlattr *nl_ftypes, *nl_ifs;
1164 enum nl80211_iftype ift;
1165 int i;
1166
1167 if (!mgmt_stypes)
1168 return 0;
1169
1170 nl_ifs = nla_nest_start(msg, NL80211_ATTR_TX_FRAME_TYPES);
1171 if (!nl_ifs)
1172 return -ENOBUFS;
1173
1174 for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) {
1175 nl_ftypes = nla_nest_start(msg, ift);
1176 if (!nl_ftypes)
1177 return -ENOBUFS;
1178 i = 0;
1179 stypes = mgmt_stypes[ift].tx;
1180 while (stypes) {
1181 if ((stypes & 1) &&
1182 nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE,
1183 (i << 4) | IEEE80211_FTYPE_MGMT))
1184 return -ENOBUFS;
1185 stypes >>= 1;
1186 i++;
1187 }
1188 nla_nest_end(msg, nl_ftypes);
1189 }
1190
1191 nla_nest_end(msg, nl_ifs);
1192
1193 nl_ifs = nla_nest_start(msg, NL80211_ATTR_RX_FRAME_TYPES);
1194 if (!nl_ifs)
1195 return -ENOBUFS;
1196
1197 for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) {
1198 nl_ftypes = nla_nest_start(msg, ift);
1199 if (!nl_ftypes)
1200 return -ENOBUFS;
1201 i = 0;
1202 stypes = mgmt_stypes[ift].rx;
1203 while (stypes) {
1204 if ((stypes & 1) &&
1205 nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE,
1206 (i << 4) | IEEE80211_FTYPE_MGMT))
1207 return -ENOBUFS;
1208 stypes >>= 1;
1209 i++;
1210 }
1211 nla_nest_end(msg, nl_ftypes);
1212 }
1213 nla_nest_end(msg, nl_ifs);
1214
1215 return 0;
1216}
1217
Johannes Berg86e8cf92013-06-19 10:57:22 +02001218struct nl80211_dump_wiphy_state {
1219 s64 filter_wiphy;
1220 long start;
1221 long split_start, band_start, chan_start;
1222 bool split;
1223};
1224
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001225static int nl80211_send_wiphy(struct cfg80211_registered_device *rdev,
Johannes Berg3713b4e2013-02-14 16:19:38 +01001226 struct sk_buff *msg, u32 portid, u32 seq,
Johannes Berg86e8cf92013-06-19 10:57:22 +02001227 int flags, struct nl80211_dump_wiphy_state *state)
Johannes Berg55682962007-09-20 13:09:35 -04001228{
1229 void *hdr;
Johannes Bergee688b002008-01-24 19:38:39 +01001230 struct nlattr *nl_bands, *nl_band;
1231 struct nlattr *nl_freqs, *nl_freq;
Johannes Berg8fdc6212009-03-14 09:34:01 +01001232 struct nlattr *nl_cmds;
Johannes Bergee688b002008-01-24 19:38:39 +01001233 enum ieee80211_band band;
1234 struct ieee80211_channel *chan;
Johannes Bergee688b002008-01-24 19:38:39 +01001235 int i;
Johannes Berg2e161f72010-08-12 15:38:38 +02001236 const struct ieee80211_txrx_stypes *mgmt_stypes =
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001237 rdev->wiphy.mgmt_stypes;
Johannes Bergfe1abaf2013-02-27 15:39:45 +01001238 u32 features;
Johannes Berg55682962007-09-20 13:09:35 -04001239
Eric W. Biederman15e47302012-09-07 20:12:54 +00001240 hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_WIPHY);
Johannes Berg55682962007-09-20 13:09:35 -04001241 if (!hdr)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001242 return -ENOBUFS;
1243
Johannes Berg86e8cf92013-06-19 10:57:22 +02001244 if (WARN_ON(!state))
1245 return -EINVAL;
Johannes Berg55682962007-09-20 13:09:35 -04001246
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001247 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001248 nla_put_string(msg, NL80211_ATTR_WIPHY_NAME,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001249 wiphy_name(&rdev->wiphy)) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04001250 nla_put_u32(msg, NL80211_ATTR_GENERATION,
Johannes Berg3713b4e2013-02-14 16:19:38 +01001251 cfg80211_rdev_list_generation))
David S. Miller9360ffd2012-03-29 04:41:26 -04001252 goto nla_put_failure;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02001253
Johannes Berg86e8cf92013-06-19 10:57:22 +02001254 switch (state->split_start) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001255 case 0:
1256 if (nla_put_u8(msg, NL80211_ATTR_WIPHY_RETRY_SHORT,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001257 rdev->wiphy.retry_short) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001258 nla_put_u8(msg, NL80211_ATTR_WIPHY_RETRY_LONG,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001259 rdev->wiphy.retry_long) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001260 nla_put_u32(msg, NL80211_ATTR_WIPHY_FRAG_THRESHOLD,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001261 rdev->wiphy.frag_threshold) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001262 nla_put_u32(msg, NL80211_ATTR_WIPHY_RTS_THRESHOLD,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001263 rdev->wiphy.rts_threshold) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001264 nla_put_u8(msg, NL80211_ATTR_WIPHY_COVERAGE_CLASS,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001265 rdev->wiphy.coverage_class) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001266 nla_put_u8(msg, NL80211_ATTR_MAX_NUM_SCAN_SSIDS,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001267 rdev->wiphy.max_scan_ssids) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001268 nla_put_u8(msg, NL80211_ATTR_MAX_NUM_SCHED_SCAN_SSIDS,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001269 rdev->wiphy.max_sched_scan_ssids) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001270 nla_put_u16(msg, NL80211_ATTR_MAX_SCAN_IE_LEN,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001271 rdev->wiphy.max_scan_ie_len) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001272 nla_put_u16(msg, NL80211_ATTR_MAX_SCHED_SCAN_IE_LEN,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001273 rdev->wiphy.max_sched_scan_ie_len) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001274 nla_put_u8(msg, NL80211_ATTR_MAX_MATCH_SETS,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001275 rdev->wiphy.max_match_sets))
Johannes Bergee688b002008-01-24 19:38:39 +01001276 goto nla_put_failure;
1277
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001278 if ((rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001279 nla_put_flag(msg, NL80211_ATTR_SUPPORT_IBSS_RSN))
1280 goto nla_put_failure;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001281 if ((rdev->wiphy.flags & WIPHY_FLAG_MESH_AUTH) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001282 nla_put_flag(msg, NL80211_ATTR_SUPPORT_MESH_AUTH))
1283 goto nla_put_failure;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001284 if ((rdev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001285 nla_put_flag(msg, NL80211_ATTR_SUPPORT_AP_UAPSD))
1286 goto nla_put_failure;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001287 if ((rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_FW_ROAM) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001288 nla_put_flag(msg, NL80211_ATTR_ROAM_SUPPORT))
1289 goto nla_put_failure;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001290 if ((rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001291 nla_put_flag(msg, NL80211_ATTR_TDLS_SUPPORT))
1292 goto nla_put_failure;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001293 if ((rdev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001294 nla_put_flag(msg, NL80211_ATTR_TDLS_EXTERNAL_SETUP))
David S. Miller9360ffd2012-03-29 04:41:26 -04001295 goto nla_put_failure;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001296 state->split_start++;
1297 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001298 break;
1299 case 1:
1300 if (nla_put(msg, NL80211_ATTR_CIPHER_SUITES,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001301 sizeof(u32) * rdev->wiphy.n_cipher_suites,
1302 rdev->wiphy.cipher_suites))
Mahesh Palivelabf0c111e2012-06-22 07:27:46 +00001303 goto nla_put_failure;
1304
Johannes Berg3713b4e2013-02-14 16:19:38 +01001305 if (nla_put_u8(msg, NL80211_ATTR_MAX_NUM_PMKIDS,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001306 rdev->wiphy.max_num_pmkids))
Johannes Bergee688b002008-01-24 19:38:39 +01001307 goto nla_put_failure;
1308
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001309 if ((rdev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001310 nla_put_flag(msg, NL80211_ATTR_CONTROL_PORT_ETHERTYPE))
1311 goto nla_put_failure;
Johannes Bergee688b002008-01-24 19:38:39 +01001312
Johannes Berg3713b4e2013-02-14 16:19:38 +01001313 if (nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_TX,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001314 rdev->wiphy.available_antennas_tx) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001315 nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_RX,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001316 rdev->wiphy.available_antennas_rx))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001317 goto nla_put_failure;
Johannes Bergee688b002008-01-24 19:38:39 +01001318
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001319 if ((rdev->wiphy.flags & WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001320 nla_put_u32(msg, NL80211_ATTR_PROBE_RESP_OFFLOAD,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001321 rdev->wiphy.probe_resp_offload))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001322 goto nla_put_failure;
Jouni Malinene2f367f262008-11-21 19:01:30 +02001323
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001324 if ((rdev->wiphy.available_antennas_tx ||
1325 rdev->wiphy.available_antennas_rx) &&
1326 rdev->ops->get_antenna) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001327 u32 tx_ant = 0, rx_ant = 0;
1328 int res;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001329 res = rdev_get_antenna(rdev, &tx_ant, &rx_ant);
Johannes Berg3713b4e2013-02-14 16:19:38 +01001330 if (!res) {
1331 if (nla_put_u32(msg,
1332 NL80211_ATTR_WIPHY_ANTENNA_TX,
1333 tx_ant) ||
1334 nla_put_u32(msg,
1335 NL80211_ATTR_WIPHY_ANTENNA_RX,
1336 rx_ant))
1337 goto nla_put_failure;
1338 }
Johannes Bergee688b002008-01-24 19:38:39 +01001339 }
1340
Johannes Berg86e8cf92013-06-19 10:57:22 +02001341 state->split_start++;
1342 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001343 break;
1344 case 2:
1345 if (nl80211_put_iftypes(msg, NL80211_ATTR_SUPPORTED_IFTYPES,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001346 rdev->wiphy.interface_modes))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001347 goto nla_put_failure;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001348 state->split_start++;
1349 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001350 break;
1351 case 3:
1352 nl_bands = nla_nest_start(msg, NL80211_ATTR_WIPHY_BANDS);
1353 if (!nl_bands)
Johannes Bergee688b002008-01-24 19:38:39 +01001354 goto nla_put_failure;
1355
Johannes Berg86e8cf92013-06-19 10:57:22 +02001356 for (band = state->band_start;
1357 band < IEEE80211_NUM_BANDS; band++) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001358 struct ieee80211_supported_band *sband;
1359
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001360 sband = rdev->wiphy.bands[band];
Johannes Berg3713b4e2013-02-14 16:19:38 +01001361
1362 if (!sband)
1363 continue;
1364
1365 nl_band = nla_nest_start(msg, band);
1366 if (!nl_band)
Johannes Bergee688b002008-01-24 19:38:39 +01001367 goto nla_put_failure;
1368
Johannes Berg86e8cf92013-06-19 10:57:22 +02001369 switch (state->chan_start) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001370 case 0:
1371 if (nl80211_send_band_rateinfo(msg, sband))
1372 goto nla_put_failure;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001373 state->chan_start++;
1374 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001375 break;
1376 default:
1377 /* add frequencies */
1378 nl_freqs = nla_nest_start(
1379 msg, NL80211_BAND_ATTR_FREQS);
1380 if (!nl_freqs)
1381 goto nla_put_failure;
Johannes Bergee688b002008-01-24 19:38:39 +01001382
Johannes Berg86e8cf92013-06-19 10:57:22 +02001383 for (i = state->chan_start - 1;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001384 i < sband->n_channels;
1385 i++) {
1386 nl_freq = nla_nest_start(msg, i);
1387 if (!nl_freq)
1388 goto nla_put_failure;
1389
1390 chan = &sband->channels[i];
1391
Johannes Berg86e8cf92013-06-19 10:57:22 +02001392 if (nl80211_msg_put_channel(
1393 msg, chan,
1394 state->split))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001395 goto nla_put_failure;
1396
1397 nla_nest_end(msg, nl_freq);
Johannes Berg86e8cf92013-06-19 10:57:22 +02001398 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001399 break;
1400 }
1401 if (i < sband->n_channels)
Johannes Berg86e8cf92013-06-19 10:57:22 +02001402 state->chan_start = i + 2;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001403 else
Johannes Berg86e8cf92013-06-19 10:57:22 +02001404 state->chan_start = 0;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001405 nla_nest_end(msg, nl_freqs);
1406 }
1407
1408 nla_nest_end(msg, nl_band);
1409
Johannes Berg86e8cf92013-06-19 10:57:22 +02001410 if (state->split) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001411 /* start again here */
Johannes Berg86e8cf92013-06-19 10:57:22 +02001412 if (state->chan_start)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001413 band--;
1414 break;
1415 }
Johannes Bergee688b002008-01-24 19:38:39 +01001416 }
Johannes Berg3713b4e2013-02-14 16:19:38 +01001417 nla_nest_end(msg, nl_bands);
Johannes Bergee688b002008-01-24 19:38:39 +01001418
Johannes Berg3713b4e2013-02-14 16:19:38 +01001419 if (band < IEEE80211_NUM_BANDS)
Johannes Berg86e8cf92013-06-19 10:57:22 +02001420 state->band_start = band + 1;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001421 else
Johannes Berg86e8cf92013-06-19 10:57:22 +02001422 state->band_start = 0;
Johannes Bergee688b002008-01-24 19:38:39 +01001423
Johannes Berg3713b4e2013-02-14 16:19:38 +01001424 /* if bands & channels are done, continue outside */
Johannes Berg86e8cf92013-06-19 10:57:22 +02001425 if (state->band_start == 0 && state->chan_start == 0)
1426 state->split_start++;
1427 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001428 break;
1429 case 4:
1430 nl_cmds = nla_nest_start(msg, NL80211_ATTR_SUPPORTED_COMMANDS);
1431 if (!nl_cmds)
David S. Miller9360ffd2012-03-29 04:41:26 -04001432 goto nla_put_failure;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001433
1434 i = 0;
1435#define CMD(op, n) \
1436 do { \
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001437 if (rdev->ops->op) { \
Johannes Berg3713b4e2013-02-14 16:19:38 +01001438 i++; \
1439 if (nla_put_u32(msg, i, NL80211_CMD_ ## n)) \
1440 goto nla_put_failure; \
1441 } \
1442 } while (0)
1443
1444 CMD(add_virtual_intf, NEW_INTERFACE);
1445 CMD(change_virtual_intf, SET_INTERFACE);
1446 CMD(add_key, NEW_KEY);
1447 CMD(start_ap, START_AP);
1448 CMD(add_station, NEW_STATION);
1449 CMD(add_mpath, NEW_MPATH);
1450 CMD(update_mesh_config, SET_MESH_CONFIG);
1451 CMD(change_bss, SET_BSS);
1452 CMD(auth, AUTHENTICATE);
1453 CMD(assoc, ASSOCIATE);
1454 CMD(deauth, DEAUTHENTICATE);
1455 CMD(disassoc, DISASSOCIATE);
1456 CMD(join_ibss, JOIN_IBSS);
1457 CMD(join_mesh, JOIN_MESH);
1458 CMD(set_pmksa, SET_PMKSA);
1459 CMD(del_pmksa, DEL_PMKSA);
1460 CMD(flush_pmksa, FLUSH_PMKSA);
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001461 if (rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001462 CMD(remain_on_channel, REMAIN_ON_CHANNEL);
1463 CMD(set_bitrate_mask, SET_TX_BITRATE_MASK);
1464 CMD(mgmt_tx, FRAME);
1465 CMD(mgmt_tx_cancel_wait, FRAME_WAIT_CANCEL);
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001466 if (rdev->wiphy.flags & WIPHY_FLAG_NETNS_OK) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001467 i++;
1468 if (nla_put_u32(msg, i, NL80211_CMD_SET_WIPHY_NETNS))
1469 goto nla_put_failure;
1470 }
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001471 if (rdev->ops->set_monitor_channel || rdev->ops->start_ap ||
1472 rdev->ops->join_mesh) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001473 i++;
1474 if (nla_put_u32(msg, i, NL80211_CMD_SET_CHANNEL))
1475 goto nla_put_failure;
1476 }
1477 CMD(set_wds_peer, SET_WDS_PEER);
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001478 if (rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001479 CMD(tdls_mgmt, TDLS_MGMT);
1480 CMD(tdls_oper, TDLS_OPER);
1481 }
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001482 if (rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001483 CMD(sched_scan_start, START_SCHED_SCAN);
1484 CMD(probe_client, PROBE_CLIENT);
1485 CMD(set_noack_map, SET_NOACK_MAP);
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001486 if (rdev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001487 i++;
1488 if (nla_put_u32(msg, i, NL80211_CMD_REGISTER_BEACONS))
1489 goto nla_put_failure;
1490 }
1491 CMD(start_p2p_device, START_P2P_DEVICE);
1492 CMD(set_mcast_rate, SET_MCAST_RATE);
Johannes Berg86e8cf92013-06-19 10:57:22 +02001493 if (state->split) {
Arend van Spriel5de17982013-04-18 15:49:00 +02001494 CMD(crit_proto_start, CRIT_PROTOCOL_START);
1495 CMD(crit_proto_stop, CRIT_PROTOCOL_STOP);
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001496 if (rdev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH)
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02001497 CMD(channel_switch, CHANNEL_SWITCH);
Arend van Spriel5de17982013-04-18 15:49:00 +02001498 }
Kyeyoon Parkfa9ffc72013-12-16 23:01:30 -08001499 CMD(set_qos_map, SET_QOS_MAP);
Johannes Berg8fdc6212009-03-14 09:34:01 +01001500
Kalle Valo4745fc02011-11-17 19:06:10 +02001501#ifdef CONFIG_NL80211_TESTMODE
Johannes Berg3713b4e2013-02-14 16:19:38 +01001502 CMD(testmode_cmd, TESTMODE);
Kalle Valo4745fc02011-11-17 19:06:10 +02001503#endif
1504
Johannes Berg8fdc6212009-03-14 09:34:01 +01001505#undef CMD
Samuel Ortizb23aa672009-07-01 21:26:54 +02001506
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001507 if (rdev->ops->connect || rdev->ops->auth) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001508 i++;
1509 if (nla_put_u32(msg, i, NL80211_CMD_CONNECT))
Johannes Berg2e161f72010-08-12 15:38:38 +02001510 goto nla_put_failure;
Johannes Berg2e161f72010-08-12 15:38:38 +02001511 }
1512
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001513 if (rdev->ops->disconnect || rdev->ops->deauth) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001514 i++;
1515 if (nla_put_u32(msg, i, NL80211_CMD_DISCONNECT))
1516 goto nla_put_failure;
1517 }
Johannes Berg74b70a42010-08-24 12:15:53 +02001518
Johannes Berg3713b4e2013-02-14 16:19:38 +01001519 nla_nest_end(msg, nl_cmds);
Johannes Berg86e8cf92013-06-19 10:57:22 +02001520 state->split_start++;
1521 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001522 break;
1523 case 5:
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001524 if (rdev->ops->remain_on_channel &&
1525 (rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001526 nla_put_u32(msg,
1527 NL80211_ATTR_MAX_REMAIN_ON_CHANNEL_DURATION,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001528 rdev->wiphy.max_remain_on_channel_duration))
Johannes Berg2e161f72010-08-12 15:38:38 +02001529 goto nla_put_failure;
1530
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001531 if ((rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001532 nla_put_flag(msg, NL80211_ATTR_OFFCHANNEL_TX_OK))
1533 goto nla_put_failure;
Johannes Berg2e161f72010-08-12 15:38:38 +02001534
Johannes Berg3713b4e2013-02-14 16:19:38 +01001535 if (nl80211_send_mgmt_stypes(msg, mgmt_stypes))
1536 goto nla_put_failure;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001537 state->split_start++;
1538 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001539 break;
1540 case 6:
Johannes Bergdfb89c52012-06-27 09:23:48 +02001541#ifdef CONFIG_PM
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001542 if (nl80211_send_wowlan(msg, rdev, state->split))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001543 goto nla_put_failure;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001544 state->split_start++;
1545 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001546 break;
1547#else
Johannes Berg86e8cf92013-06-19 10:57:22 +02001548 state->split_start++;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001549#endif
1550 case 7:
1551 if (nl80211_put_iftypes(msg, NL80211_ATTR_SOFTWARE_IFTYPES,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001552 rdev->wiphy.software_iftypes))
Johannes Bergff1b6e62011-05-04 15:37:28 +02001553 goto nla_put_failure;
1554
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001555 if (nl80211_put_iface_combinations(&rdev->wiphy, msg,
Johannes Berg86e8cf92013-06-19 10:57:22 +02001556 state->split))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001557 goto nla_put_failure;
Johannes Bergff1b6e62011-05-04 15:37:28 +02001558
Johannes Berg86e8cf92013-06-19 10:57:22 +02001559 state->split_start++;
1560 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001561 break;
1562 case 8:
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001563 if ((rdev->wiphy.flags & WIPHY_FLAG_HAVE_AP_SME) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001564 nla_put_u32(msg, NL80211_ATTR_DEVICE_AP_SME,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001565 rdev->wiphy.ap_sme_capa))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001566 goto nla_put_failure;
1567
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001568 features = rdev->wiphy.features;
Johannes Bergfe1abaf2013-02-27 15:39:45 +01001569 /*
1570 * We can only add the per-channel limit information if the
1571 * dump is split, otherwise it makes it too big. Therefore
1572 * only advertise it in that case.
1573 */
Johannes Berg86e8cf92013-06-19 10:57:22 +02001574 if (state->split)
Johannes Bergfe1abaf2013-02-27 15:39:45 +01001575 features |= NL80211_FEATURE_ADVERTISE_CHAN_LIMITS;
1576 if (nla_put_u32(msg, NL80211_ATTR_FEATURE_FLAGS, features))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001577 goto nla_put_failure;
1578
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001579 if (rdev->wiphy.ht_capa_mod_mask &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001580 nla_put(msg, NL80211_ATTR_HT_CAPABILITY_MASK,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001581 sizeof(*rdev->wiphy.ht_capa_mod_mask),
1582 rdev->wiphy.ht_capa_mod_mask))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001583 goto nla_put_failure;
1584
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001585 if (rdev->wiphy.flags & WIPHY_FLAG_HAVE_AP_SME &&
1586 rdev->wiphy.max_acl_mac_addrs &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001587 nla_put_u32(msg, NL80211_ATTR_MAC_ACL_MAX,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001588 rdev->wiphy.max_acl_mac_addrs))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001589 goto nla_put_failure;
1590
1591 /*
1592 * Any information below this point is only available to
1593 * applications that can deal with it being split. This
1594 * helps ensure that newly added capabilities don't break
1595 * older tools by overrunning their buffers.
1596 *
1597 * We still increment split_start so that in the split
1598 * case we'll continue with more data in the next round,
1599 * but break unconditionally so unsplit data stops here.
1600 */
Johannes Berg86e8cf92013-06-19 10:57:22 +02001601 state->split_start++;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001602 break;
1603 case 9:
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001604 if (rdev->wiphy.extended_capabilities &&
Johannes Bergfe1abaf2013-02-27 15:39:45 +01001605 (nla_put(msg, NL80211_ATTR_EXT_CAPA,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001606 rdev->wiphy.extended_capabilities_len,
1607 rdev->wiphy.extended_capabilities) ||
Johannes Bergfe1abaf2013-02-27 15:39:45 +01001608 nla_put(msg, NL80211_ATTR_EXT_CAPA_MASK,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001609 rdev->wiphy.extended_capabilities_len,
1610 rdev->wiphy.extended_capabilities_mask)))
Johannes Bergfe1abaf2013-02-27 15:39:45 +01001611 goto nla_put_failure;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001612
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001613 if (rdev->wiphy.vht_capa_mod_mask &&
Johannes Bergee2aca32013-02-21 17:36:01 +01001614 nla_put(msg, NL80211_ATTR_VHT_CAPABILITY_MASK,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001615 sizeof(*rdev->wiphy.vht_capa_mod_mask),
1616 rdev->wiphy.vht_capa_mod_mask))
Johannes Bergee2aca32013-02-21 17:36:01 +01001617 goto nla_put_failure;
1618
Amitkumar Karwarbe29b992013-06-28 11:51:26 -07001619 state->split_start++;
1620 break;
1621 case 10:
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001622 if (nl80211_send_coalesce(msg, rdev))
Amitkumar Karwarbe29b992013-06-28 11:51:26 -07001623 goto nla_put_failure;
1624
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001625 if ((rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_5_10_MHZ) &&
Felix Fietkau01e0daa2013-11-09 14:57:54 +01001626 (nla_put_flag(msg, NL80211_ATTR_SUPPORT_5_MHZ) ||
1627 nla_put_flag(msg, NL80211_ATTR_SUPPORT_10_MHZ)))
1628 goto nla_put_failure;
Jouni Malinenb43504c2014-01-15 00:01:08 +02001629
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001630 if (rdev->wiphy.max_ap_assoc_sta &&
Jouni Malinenb43504c2014-01-15 00:01:08 +02001631 nla_put_u32(msg, NL80211_ATTR_MAX_AP_ASSOC_STA,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001632 rdev->wiphy.max_ap_assoc_sta))
Jouni Malinenb43504c2014-01-15 00:01:08 +02001633 goto nla_put_failure;
1634
Johannes Bergad7e7182013-11-13 13:37:47 +01001635 state->split_start++;
1636 break;
1637 case 11:
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001638 if (rdev->wiphy.n_vendor_commands) {
Johannes Berg567ffc32013-12-18 14:43:31 +01001639 const struct nl80211_vendor_cmd_info *info;
1640 struct nlattr *nested;
Johannes Bergad7e7182013-11-13 13:37:47 +01001641
Johannes Berg567ffc32013-12-18 14:43:31 +01001642 nested = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA);
1643 if (!nested)
Johannes Bergad7e7182013-11-13 13:37:47 +01001644 goto nla_put_failure;
Johannes Berg567ffc32013-12-18 14:43:31 +01001645
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001646 for (i = 0; i < rdev->wiphy.n_vendor_commands; i++) {
1647 info = &rdev->wiphy.vendor_commands[i].info;
Johannes Berg567ffc32013-12-18 14:43:31 +01001648 if (nla_put(msg, i + 1, sizeof(*info), info))
1649 goto nla_put_failure;
1650 }
1651 nla_nest_end(msg, nested);
1652 }
1653
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001654 if (rdev->wiphy.n_vendor_events) {
Johannes Berg567ffc32013-12-18 14:43:31 +01001655 const struct nl80211_vendor_cmd_info *info;
1656 struct nlattr *nested;
1657
1658 nested = nla_nest_start(msg,
1659 NL80211_ATTR_VENDOR_EVENTS);
1660 if (!nested)
1661 goto nla_put_failure;
1662
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001663 for (i = 0; i < rdev->wiphy.n_vendor_events; i++) {
1664 info = &rdev->wiphy.vendor_events[i];
Johannes Berg567ffc32013-12-18 14:43:31 +01001665 if (nla_put(msg, i + 1, sizeof(*info), info))
1666 goto nla_put_failure;
1667 }
1668 nla_nest_end(msg, nested);
1669 }
Felix Fietkau01e0daa2013-11-09 14:57:54 +01001670
Johannes Berg3713b4e2013-02-14 16:19:38 +01001671 /* done */
Johannes Berg86e8cf92013-06-19 10:57:22 +02001672 state->split_start = 0;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001673 break;
Johannes Bergff1b6e62011-05-04 15:37:28 +02001674 }
Johannes Berg55682962007-09-20 13:09:35 -04001675 return genlmsg_end(msg, hdr);
1676
1677 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07001678 genlmsg_cancel(msg, hdr);
1679 return -EMSGSIZE;
Johannes Berg55682962007-09-20 13:09:35 -04001680}
1681
Johannes Berg86e8cf92013-06-19 10:57:22 +02001682static int nl80211_dump_wiphy_parse(struct sk_buff *skb,
1683 struct netlink_callback *cb,
1684 struct nl80211_dump_wiphy_state *state)
1685{
1686 struct nlattr **tb = nl80211_fam.attrbuf;
1687 int ret = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize,
1688 tb, nl80211_fam.maxattr, nl80211_policy);
1689 /* ignore parse errors for backward compatibility */
1690 if (ret)
1691 return 0;
1692
1693 state->split = tb[NL80211_ATTR_SPLIT_WIPHY_DUMP];
1694 if (tb[NL80211_ATTR_WIPHY])
1695 state->filter_wiphy = nla_get_u32(tb[NL80211_ATTR_WIPHY]);
1696 if (tb[NL80211_ATTR_WDEV])
1697 state->filter_wiphy = nla_get_u64(tb[NL80211_ATTR_WDEV]) >> 32;
1698 if (tb[NL80211_ATTR_IFINDEX]) {
1699 struct net_device *netdev;
1700 struct cfg80211_registered_device *rdev;
1701 int ifidx = nla_get_u32(tb[NL80211_ATTR_IFINDEX]);
1702
Ying Xue7f2b8562014-01-15 10:23:45 +08001703 netdev = __dev_get_by_index(sock_net(skb->sk), ifidx);
Johannes Berg86e8cf92013-06-19 10:57:22 +02001704 if (!netdev)
1705 return -ENODEV;
1706 if (netdev->ieee80211_ptr) {
Zhao, Gangf26cbf42014-04-21 12:53:03 +08001707 rdev = wiphy_to_rdev(
Johannes Berg86e8cf92013-06-19 10:57:22 +02001708 netdev->ieee80211_ptr->wiphy);
1709 state->filter_wiphy = rdev->wiphy_idx;
1710 }
Johannes Berg86e8cf92013-06-19 10:57:22 +02001711 }
1712
1713 return 0;
1714}
1715
Johannes Berg55682962007-09-20 13:09:35 -04001716static int nl80211_dump_wiphy(struct sk_buff *skb, struct netlink_callback *cb)
1717{
Johannes Berg645e77d2013-03-01 14:03:49 +01001718 int idx = 0, ret;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001719 struct nl80211_dump_wiphy_state *state = (void *)cb->args[0];
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001720 struct cfg80211_registered_device *rdev;
Johannes Berg3a5a4232013-06-19 10:09:57 +02001721
Johannes Berg5fe231e2013-05-08 21:45:15 +02001722 rtnl_lock();
Johannes Berg86e8cf92013-06-19 10:57:22 +02001723 if (!state) {
1724 state = kzalloc(sizeof(*state), GFP_KERNEL);
John W. Linville57ed5cd2013-06-28 13:18:21 -04001725 if (!state) {
1726 rtnl_unlock();
Johannes Berg86e8cf92013-06-19 10:57:22 +02001727 return -ENOMEM;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001728 }
Johannes Berg86e8cf92013-06-19 10:57:22 +02001729 state->filter_wiphy = -1;
1730 ret = nl80211_dump_wiphy_parse(skb, cb, state);
1731 if (ret) {
1732 kfree(state);
1733 rtnl_unlock();
1734 return ret;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001735 }
Johannes Berg86e8cf92013-06-19 10:57:22 +02001736 cb->args[0] = (long)state;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001737 }
1738
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001739 list_for_each_entry(rdev, &cfg80211_rdev_list, list) {
1740 if (!net_eq(wiphy_net(&rdev->wiphy), sock_net(skb->sk)))
Johannes Berg463d0182009-07-14 00:33:35 +02001741 continue;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001742 if (++idx <= state->start)
Johannes Berg55682962007-09-20 13:09:35 -04001743 continue;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001744 if (state->filter_wiphy != -1 &&
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001745 state->filter_wiphy != rdev->wiphy_idx)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001746 continue;
1747 /* attempt to fit multiple wiphy data chunks into the skb */
1748 do {
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001749 ret = nl80211_send_wiphy(rdev, skb,
Johannes Berg3713b4e2013-02-14 16:19:38 +01001750 NETLINK_CB(cb->skb).portid,
1751 cb->nlh->nlmsg_seq,
Johannes Berg86e8cf92013-06-19 10:57:22 +02001752 NLM_F_MULTI, state);
Johannes Berg3713b4e2013-02-14 16:19:38 +01001753 if (ret < 0) {
1754 /*
1755 * If sending the wiphy data didn't fit (ENOBUFS
1756 * or EMSGSIZE returned), this SKB is still
1757 * empty (so it's not too big because another
1758 * wiphy dataset is already in the skb) and
1759 * we've not tried to adjust the dump allocation
1760 * yet ... then adjust the alloc size to be
1761 * bigger, and return 1 but with the empty skb.
1762 * This results in an empty message being RX'ed
1763 * in userspace, but that is ignored.
1764 *
1765 * We can then retry with the larger buffer.
1766 */
1767 if ((ret == -ENOBUFS || ret == -EMSGSIZE) &&
Pontus Fuchsf12cb282014-01-16 15:00:40 +01001768 !skb->len && !state->split &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001769 cb->min_dump_alloc < 4096) {
1770 cb->min_dump_alloc = 4096;
Pontus Fuchsf12cb282014-01-16 15:00:40 +01001771 state->split_start = 0;
David S. Millerd98cae64e2013-06-19 16:49:39 -07001772 rtnl_unlock();
Johannes Berg3713b4e2013-02-14 16:19:38 +01001773 return 1;
1774 }
1775 idx--;
1776 break;
Johannes Berg645e77d2013-03-01 14:03:49 +01001777 }
Johannes Berg86e8cf92013-06-19 10:57:22 +02001778 } while (state->split_start > 0);
Johannes Berg3713b4e2013-02-14 16:19:38 +01001779 break;
Johannes Berg55682962007-09-20 13:09:35 -04001780 }
Johannes Berg5fe231e2013-05-08 21:45:15 +02001781 rtnl_unlock();
Johannes Berg55682962007-09-20 13:09:35 -04001782
Johannes Berg86e8cf92013-06-19 10:57:22 +02001783 state->start = idx;
Johannes Berg55682962007-09-20 13:09:35 -04001784
1785 return skb->len;
1786}
1787
Johannes Berg86e8cf92013-06-19 10:57:22 +02001788static int nl80211_dump_wiphy_done(struct netlink_callback *cb)
1789{
1790 kfree((void *)cb->args[0]);
1791 return 0;
1792}
1793
Johannes Berg55682962007-09-20 13:09:35 -04001794static int nl80211_get_wiphy(struct sk_buff *skb, struct genl_info *info)
1795{
1796 struct sk_buff *msg;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001797 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg86e8cf92013-06-19 10:57:22 +02001798 struct nl80211_dump_wiphy_state state = {};
Johannes Berg55682962007-09-20 13:09:35 -04001799
Johannes Berg645e77d2013-03-01 14:03:49 +01001800 msg = nlmsg_new(4096, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -04001801 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02001802 return -ENOMEM;
Johannes Berg55682962007-09-20 13:09:35 -04001803
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001804 if (nl80211_send_wiphy(rdev, msg, info->snd_portid, info->snd_seq, 0,
Johannes Berg86e8cf92013-06-19 10:57:22 +02001805 &state) < 0) {
Johannes Berg4c476992010-10-04 21:36:35 +02001806 nlmsg_free(msg);
1807 return -ENOBUFS;
1808 }
Johannes Berg55682962007-09-20 13:09:35 -04001809
Johannes Berg134e6372009-07-10 09:51:34 +00001810 return genlmsg_reply(msg, info);
Johannes Berg55682962007-09-20 13:09:35 -04001811}
1812
Jouni Malinen31888482008-10-30 16:59:24 +02001813static const struct nla_policy txq_params_policy[NL80211_TXQ_ATTR_MAX + 1] = {
1814 [NL80211_TXQ_ATTR_QUEUE] = { .type = NLA_U8 },
1815 [NL80211_TXQ_ATTR_TXOP] = { .type = NLA_U16 },
1816 [NL80211_TXQ_ATTR_CWMIN] = { .type = NLA_U16 },
1817 [NL80211_TXQ_ATTR_CWMAX] = { .type = NLA_U16 },
1818 [NL80211_TXQ_ATTR_AIFS] = { .type = NLA_U8 },
1819};
1820
1821static int parse_txq_params(struct nlattr *tb[],
1822 struct ieee80211_txq_params *txq_params)
1823{
Johannes Berga3304b02012-03-28 11:04:24 +02001824 if (!tb[NL80211_TXQ_ATTR_AC] || !tb[NL80211_TXQ_ATTR_TXOP] ||
Jouni Malinen31888482008-10-30 16:59:24 +02001825 !tb[NL80211_TXQ_ATTR_CWMIN] || !tb[NL80211_TXQ_ATTR_CWMAX] ||
1826 !tb[NL80211_TXQ_ATTR_AIFS])
1827 return -EINVAL;
1828
Johannes Berga3304b02012-03-28 11:04:24 +02001829 txq_params->ac = nla_get_u8(tb[NL80211_TXQ_ATTR_AC]);
Jouni Malinen31888482008-10-30 16:59:24 +02001830 txq_params->txop = nla_get_u16(tb[NL80211_TXQ_ATTR_TXOP]);
1831 txq_params->cwmin = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMIN]);
1832 txq_params->cwmax = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMAX]);
1833 txq_params->aifs = nla_get_u8(tb[NL80211_TXQ_ATTR_AIFS]);
1834
Johannes Berga3304b02012-03-28 11:04:24 +02001835 if (txq_params->ac >= NL80211_NUM_ACS)
1836 return -EINVAL;
1837
Jouni Malinen31888482008-10-30 16:59:24 +02001838 return 0;
1839}
1840
Johannes Bergf444de02010-05-05 15:25:02 +02001841static bool nl80211_can_set_dev_channel(struct wireless_dev *wdev)
1842{
1843 /*
Johannes Bergcc1d2802012-05-16 23:50:20 +02001844 * You can only set the channel explicitly for WDS interfaces,
1845 * all others have their channel managed via their respective
1846 * "establish a connection" command (connect, join, ...)
1847 *
1848 * For AP/GO and mesh mode, the channel can be set with the
1849 * channel userspace API, but is only stored and passed to the
1850 * low-level driver when the AP starts or the mesh is joined.
1851 * This is for backward compatibility, userspace can also give
1852 * the channel in the start-ap or join-mesh commands instead.
Johannes Bergf444de02010-05-05 15:25:02 +02001853 *
1854 * Monitors are special as they are normally slaved to
Johannes Berge8c9bd52012-06-06 08:18:22 +02001855 * whatever else is going on, so they have their own special
1856 * operation to set the monitor channel if possible.
Johannes Bergf444de02010-05-05 15:25:02 +02001857 */
1858 return !wdev ||
1859 wdev->iftype == NL80211_IFTYPE_AP ||
Johannes Bergf444de02010-05-05 15:25:02 +02001860 wdev->iftype == NL80211_IFTYPE_MESH_POINT ||
Johannes Berg074ac8d2010-09-16 14:58:22 +02001861 wdev->iftype == NL80211_IFTYPE_MONITOR ||
1862 wdev->iftype == NL80211_IFTYPE_P2P_GO;
Johannes Bergf444de02010-05-05 15:25:02 +02001863}
1864
Johannes Berg683b6d32012-11-08 21:25:48 +01001865static int nl80211_parse_chandef(struct cfg80211_registered_device *rdev,
1866 struct genl_info *info,
1867 struct cfg80211_chan_def *chandef)
1868{
Mahesh Paliveladbeca2e2012-11-29 14:11:07 +05301869 u32 control_freq;
Johannes Berg683b6d32012-11-08 21:25:48 +01001870
1871 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ])
1872 return -EINVAL;
1873
1874 control_freq = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]);
1875
1876 chandef->chan = ieee80211_get_channel(&rdev->wiphy, control_freq);
Johannes Berg3d9d1d62012-11-08 23:14:50 +01001877 chandef->width = NL80211_CHAN_WIDTH_20_NOHT;
1878 chandef->center_freq1 = control_freq;
1879 chandef->center_freq2 = 0;
Johannes Berg683b6d32012-11-08 21:25:48 +01001880
1881 /* Primary channel not allowed */
1882 if (!chandef->chan || chandef->chan->flags & IEEE80211_CHAN_DISABLED)
1883 return -EINVAL;
1884
Johannes Berg3d9d1d62012-11-08 23:14:50 +01001885 if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]) {
1886 enum nl80211_channel_type chantype;
Johannes Berg683b6d32012-11-08 21:25:48 +01001887
Johannes Berg3d9d1d62012-11-08 23:14:50 +01001888 chantype = nla_get_u32(
1889 info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]);
1890
1891 switch (chantype) {
1892 case NL80211_CHAN_NO_HT:
1893 case NL80211_CHAN_HT20:
1894 case NL80211_CHAN_HT40PLUS:
1895 case NL80211_CHAN_HT40MINUS:
1896 cfg80211_chandef_create(chandef, chandef->chan,
1897 chantype);
1898 break;
1899 default:
Johannes Berg683b6d32012-11-08 21:25:48 +01001900 return -EINVAL;
Johannes Berg683b6d32012-11-08 21:25:48 +01001901 }
Johannes Berg3d9d1d62012-11-08 23:14:50 +01001902 } else if (info->attrs[NL80211_ATTR_CHANNEL_WIDTH]) {
1903 chandef->width =
1904 nla_get_u32(info->attrs[NL80211_ATTR_CHANNEL_WIDTH]);
1905 if (info->attrs[NL80211_ATTR_CENTER_FREQ1])
1906 chandef->center_freq1 =
1907 nla_get_u32(
1908 info->attrs[NL80211_ATTR_CENTER_FREQ1]);
1909 if (info->attrs[NL80211_ATTR_CENTER_FREQ2])
1910 chandef->center_freq2 =
1911 nla_get_u32(
1912 info->attrs[NL80211_ATTR_CENTER_FREQ2]);
1913 }
1914
Johannes Berg9f5e8f62012-11-22 16:59:45 +01001915 if (!cfg80211_chandef_valid(chandef))
Johannes Berg3d9d1d62012-11-08 23:14:50 +01001916 return -EINVAL;
1917
Johannes Berg9f5e8f62012-11-22 16:59:45 +01001918 if (!cfg80211_chandef_usable(&rdev->wiphy, chandef,
1919 IEEE80211_CHAN_DISABLED))
Johannes Berg3d9d1d62012-11-08 23:14:50 +01001920 return -EINVAL;
Johannes Berg3d9d1d62012-11-08 23:14:50 +01001921
Simon Wunderlich2f301ab2013-05-16 13:00:28 +02001922 if ((chandef->width == NL80211_CHAN_WIDTH_5 ||
1923 chandef->width == NL80211_CHAN_WIDTH_10) &&
1924 !(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_5_10_MHZ))
1925 return -EINVAL;
1926
Johannes Berg683b6d32012-11-08 21:25:48 +01001927 return 0;
1928}
1929
Johannes Bergf444de02010-05-05 15:25:02 +02001930static int __nl80211_set_channel(struct cfg80211_registered_device *rdev,
1931 struct wireless_dev *wdev,
1932 struct genl_info *info)
1933{
Johannes Berg683b6d32012-11-08 21:25:48 +01001934 struct cfg80211_chan_def chandef;
Johannes Bergf444de02010-05-05 15:25:02 +02001935 int result;
Johannes Berge8c9bd52012-06-06 08:18:22 +02001936 enum nl80211_iftype iftype = NL80211_IFTYPE_MONITOR;
1937
1938 if (wdev)
1939 iftype = wdev->iftype;
Johannes Bergf444de02010-05-05 15:25:02 +02001940
Johannes Bergf444de02010-05-05 15:25:02 +02001941 if (!nl80211_can_set_dev_channel(wdev))
1942 return -EOPNOTSUPP;
1943
Johannes Berg683b6d32012-11-08 21:25:48 +01001944 result = nl80211_parse_chandef(rdev, info, &chandef);
1945 if (result)
1946 return result;
Johannes Bergf444de02010-05-05 15:25:02 +02001947
Johannes Berge8c9bd52012-06-06 08:18:22 +02001948 switch (iftype) {
Johannes Bergaa430da2012-05-16 23:50:18 +02001949 case NL80211_IFTYPE_AP:
1950 case NL80211_IFTYPE_P2P_GO:
1951 if (wdev->beacon_interval) {
1952 result = -EBUSY;
1953 break;
1954 }
Ilan Peer174e0cd2014-02-23 09:13:01 +02001955 if (!cfg80211_reg_can_beacon(&rdev->wiphy, &chandef, iftype)) {
Johannes Bergaa430da2012-05-16 23:50:18 +02001956 result = -EINVAL;
1957 break;
1958 }
Johannes Berg683b6d32012-11-08 21:25:48 +01001959 wdev->preset_chandef = chandef;
Johannes Bergaa430da2012-05-16 23:50:18 +02001960 result = 0;
1961 break;
Johannes Bergcc1d2802012-05-16 23:50:20 +02001962 case NL80211_IFTYPE_MESH_POINT:
Johannes Berg683b6d32012-11-08 21:25:48 +01001963 result = cfg80211_set_mesh_channel(rdev, wdev, &chandef);
Johannes Bergcc1d2802012-05-16 23:50:20 +02001964 break;
Johannes Berge8c9bd52012-06-06 08:18:22 +02001965 case NL80211_IFTYPE_MONITOR:
Johannes Berg683b6d32012-11-08 21:25:48 +01001966 result = cfg80211_set_monitor_channel(rdev, &chandef);
Johannes Berge8c9bd52012-06-06 08:18:22 +02001967 break;
Johannes Bergaa430da2012-05-16 23:50:18 +02001968 default:
Johannes Berge8c9bd52012-06-06 08:18:22 +02001969 result = -EINVAL;
Johannes Bergf444de02010-05-05 15:25:02 +02001970 }
Johannes Bergf444de02010-05-05 15:25:02 +02001971
1972 return result;
1973}
1974
1975static int nl80211_set_channel(struct sk_buff *skb, struct genl_info *info)
1976{
Johannes Berg4c476992010-10-04 21:36:35 +02001977 struct cfg80211_registered_device *rdev = info->user_ptr[0];
1978 struct net_device *netdev = info->user_ptr[1];
Johannes Bergf444de02010-05-05 15:25:02 +02001979
Johannes Berg4c476992010-10-04 21:36:35 +02001980 return __nl80211_set_channel(rdev, netdev->ieee80211_ptr, info);
Johannes Bergf444de02010-05-05 15:25:02 +02001981}
1982
Bill Jordane8347eb2010-10-01 13:54:28 -04001983static int nl80211_set_wds_peer(struct sk_buff *skb, struct genl_info *info)
1984{
Johannes Berg43b19952010-10-07 13:10:30 +02001985 struct cfg80211_registered_device *rdev = info->user_ptr[0];
1986 struct net_device *dev = info->user_ptr[1];
1987 struct wireless_dev *wdev = dev->ieee80211_ptr;
Johannes Berg388ac772010-10-07 13:11:09 +02001988 const u8 *bssid;
Bill Jordane8347eb2010-10-01 13:54:28 -04001989
1990 if (!info->attrs[NL80211_ATTR_MAC])
1991 return -EINVAL;
1992
Johannes Berg43b19952010-10-07 13:10:30 +02001993 if (netif_running(dev))
1994 return -EBUSY;
Bill Jordane8347eb2010-10-01 13:54:28 -04001995
Johannes Berg43b19952010-10-07 13:10:30 +02001996 if (!rdev->ops->set_wds_peer)
1997 return -EOPNOTSUPP;
Bill Jordane8347eb2010-10-01 13:54:28 -04001998
Johannes Berg43b19952010-10-07 13:10:30 +02001999 if (wdev->iftype != NL80211_IFTYPE_WDS)
2000 return -EOPNOTSUPP;
Bill Jordane8347eb2010-10-01 13:54:28 -04002001
2002 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Hila Gonene35e4d22012-06-27 17:19:42 +03002003 return rdev_set_wds_peer(rdev, dev, bssid);
Bill Jordane8347eb2010-10-01 13:54:28 -04002004}
2005
2006
Johannes Berg55682962007-09-20 13:09:35 -04002007static int nl80211_set_wiphy(struct sk_buff *skb, struct genl_info *info)
2008{
2009 struct cfg80211_registered_device *rdev;
Johannes Bergf444de02010-05-05 15:25:02 +02002010 struct net_device *netdev = NULL;
2011 struct wireless_dev *wdev;
Bill Jordana1e567c2010-09-10 11:22:32 -04002012 int result = 0, rem_txq_params = 0;
Jouni Malinen31888482008-10-30 16:59:24 +02002013 struct nlattr *nl_txq_params;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002014 u32 changed;
2015 u8 retry_short = 0, retry_long = 0;
2016 u32 frag_threshold = 0, rts_threshold = 0;
Lukáš Turek81077e82009-12-21 22:50:47 +01002017 u8 coverage_class = 0;
Johannes Berg55682962007-09-20 13:09:35 -04002018
Johannes Berg5fe231e2013-05-08 21:45:15 +02002019 ASSERT_RTNL();
2020
Johannes Bergf444de02010-05-05 15:25:02 +02002021 /*
2022 * Try to find the wiphy and netdev. Normally this
2023 * function shouldn't need the netdev, but this is
2024 * done for backward compatibility -- previously
2025 * setting the channel was done per wiphy, but now
2026 * it is per netdev. Previous userland like hostapd
2027 * also passed a netdev to set_wiphy, so that it is
2028 * possible to let that go to the right netdev!
2029 */
Johannes Berg4bbf4d52009-03-24 09:35:46 +01002030
Johannes Bergf444de02010-05-05 15:25:02 +02002031 if (info->attrs[NL80211_ATTR_IFINDEX]) {
2032 int ifindex = nla_get_u32(info->attrs[NL80211_ATTR_IFINDEX]);
2033
Ying Xue7f2b8562014-01-15 10:23:45 +08002034 netdev = __dev_get_by_index(genl_info_net(info), ifindex);
Johannes Berg5fe231e2013-05-08 21:45:15 +02002035 if (netdev && netdev->ieee80211_ptr)
Zhao, Gangf26cbf42014-04-21 12:53:03 +08002036 rdev = wiphy_to_rdev(netdev->ieee80211_ptr->wiphy);
Johannes Berg5fe231e2013-05-08 21:45:15 +02002037 else
Johannes Bergf444de02010-05-05 15:25:02 +02002038 netdev = NULL;
Johannes Berg4bbf4d52009-03-24 09:35:46 +01002039 }
2040
Johannes Bergf444de02010-05-05 15:25:02 +02002041 if (!netdev) {
Johannes Berg878d9ec2012-06-15 14:18:32 +02002042 rdev = __cfg80211_rdev_from_attrs(genl_info_net(info),
2043 info->attrs);
Johannes Berg5fe231e2013-05-08 21:45:15 +02002044 if (IS_ERR(rdev))
Johannes Berg4c476992010-10-04 21:36:35 +02002045 return PTR_ERR(rdev);
Johannes Bergf444de02010-05-05 15:25:02 +02002046 wdev = NULL;
2047 netdev = NULL;
2048 result = 0;
Johannes Berg71fe96b2012-10-24 10:04:58 +02002049 } else
Johannes Bergf444de02010-05-05 15:25:02 +02002050 wdev = netdev->ieee80211_ptr;
Johannes Bergf444de02010-05-05 15:25:02 +02002051
2052 /*
2053 * end workaround code, by now the rdev is available
2054 * and locked, and wdev may or may not be NULL.
2055 */
Johannes Berg4bbf4d52009-03-24 09:35:46 +01002056
2057 if (info->attrs[NL80211_ATTR_WIPHY_NAME])
Jouni Malinen31888482008-10-30 16:59:24 +02002058 result = cfg80211_dev_rename(
2059 rdev, nla_data(info->attrs[NL80211_ATTR_WIPHY_NAME]));
Johannes Berg4bbf4d52009-03-24 09:35:46 +01002060
Johannes Berg4bbf4d52009-03-24 09:35:46 +01002061 if (result)
Ying Xue7f2b8562014-01-15 10:23:45 +08002062 return result;
Johannes Berg55682962007-09-20 13:09:35 -04002063
Jouni Malinen31888482008-10-30 16:59:24 +02002064 if (info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS]) {
2065 struct ieee80211_txq_params txq_params;
2066 struct nlattr *tb[NL80211_TXQ_ATTR_MAX + 1];
2067
Ying Xue7f2b8562014-01-15 10:23:45 +08002068 if (!rdev->ops->set_txq_params)
2069 return -EOPNOTSUPP;
Jouni Malinen31888482008-10-30 16:59:24 +02002070
Ying Xue7f2b8562014-01-15 10:23:45 +08002071 if (!netdev)
2072 return -EINVAL;
Eliad Pellerf70f01c2011-09-25 20:06:53 +03002073
Johannes Berg133a3ff2011-11-03 14:50:13 +01002074 if (netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
Ying Xue7f2b8562014-01-15 10:23:45 +08002075 netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
2076 return -EINVAL;
Johannes Berg133a3ff2011-11-03 14:50:13 +01002077
Ying Xue7f2b8562014-01-15 10:23:45 +08002078 if (!netif_running(netdev))
2079 return -ENETDOWN;
Johannes Berg2b5f8b02012-04-02 10:51:55 +02002080
Jouni Malinen31888482008-10-30 16:59:24 +02002081 nla_for_each_nested(nl_txq_params,
2082 info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS],
2083 rem_txq_params) {
Johannes Bergae811e22014-01-24 10:17:47 +01002084 result = nla_parse(tb, NL80211_TXQ_ATTR_MAX,
2085 nla_data(nl_txq_params),
2086 nla_len(nl_txq_params),
2087 txq_params_policy);
2088 if (result)
2089 return result;
Jouni Malinen31888482008-10-30 16:59:24 +02002090 result = parse_txq_params(tb, &txq_params);
2091 if (result)
Ying Xue7f2b8562014-01-15 10:23:45 +08002092 return result;
Jouni Malinen31888482008-10-30 16:59:24 +02002093
Hila Gonene35e4d22012-06-27 17:19:42 +03002094 result = rdev_set_txq_params(rdev, netdev,
2095 &txq_params);
Jouni Malinen31888482008-10-30 16:59:24 +02002096 if (result)
Ying Xue7f2b8562014-01-15 10:23:45 +08002097 return result;
Jouni Malinen31888482008-10-30 16:59:24 +02002098 }
2099 }
2100
Jouni Malinen72bdcf32008-11-26 16:15:24 +02002101 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
Johannes Berg71fe96b2012-10-24 10:04:58 +02002102 result = __nl80211_set_channel(rdev,
2103 nl80211_can_set_dev_channel(wdev) ? wdev : NULL,
2104 info);
Jouni Malinen72bdcf32008-11-26 16:15:24 +02002105 if (result)
Ying Xue7f2b8562014-01-15 10:23:45 +08002106 return result;
Jouni Malinen72bdcf32008-11-26 16:15:24 +02002107 }
2108
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03002109 if (info->attrs[NL80211_ATTR_WIPHY_TX_POWER_SETTING]) {
Johannes Bergc8442112012-10-24 10:17:18 +02002110 struct wireless_dev *txp_wdev = wdev;
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03002111 enum nl80211_tx_power_setting type;
2112 int idx, mbm = 0;
2113
Johannes Bergc8442112012-10-24 10:17:18 +02002114 if (!(rdev->wiphy.features & NL80211_FEATURE_VIF_TXPOWER))
2115 txp_wdev = NULL;
2116
Ying Xue7f2b8562014-01-15 10:23:45 +08002117 if (!rdev->ops->set_tx_power)
2118 return -EOPNOTSUPP;
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03002119
2120 idx = NL80211_ATTR_WIPHY_TX_POWER_SETTING;
2121 type = nla_get_u32(info->attrs[idx]);
2122
2123 if (!info->attrs[NL80211_ATTR_WIPHY_TX_POWER_LEVEL] &&
Ying Xue7f2b8562014-01-15 10:23:45 +08002124 (type != NL80211_TX_POWER_AUTOMATIC))
2125 return -EINVAL;
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03002126
2127 if (type != NL80211_TX_POWER_AUTOMATIC) {
2128 idx = NL80211_ATTR_WIPHY_TX_POWER_LEVEL;
2129 mbm = nla_get_u32(info->attrs[idx]);
2130 }
2131
Johannes Bergc8442112012-10-24 10:17:18 +02002132 result = rdev_set_tx_power(rdev, txp_wdev, type, mbm);
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03002133 if (result)
Ying Xue7f2b8562014-01-15 10:23:45 +08002134 return result;
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03002135 }
2136
Bruno Randolfafe0cbf2010-11-10 12:50:50 +09002137 if (info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX] &&
2138 info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]) {
2139 u32 tx_ant, rx_ant;
Bruno Randolf7f531e02010-12-16 11:30:22 +09002140 if ((!rdev->wiphy.available_antennas_tx &&
2141 !rdev->wiphy.available_antennas_rx) ||
Ying Xue7f2b8562014-01-15 10:23:45 +08002142 !rdev->ops->set_antenna)
2143 return -EOPNOTSUPP;
Bruno Randolfafe0cbf2010-11-10 12:50:50 +09002144
2145 tx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX]);
2146 rx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]);
2147
Bruno Randolfa7ffac92010-12-08 13:59:24 +09002148 /* reject antenna configurations which don't match the
Bruno Randolf7f531e02010-12-16 11:30:22 +09002149 * available antenna masks, except for the "all" mask */
2150 if ((~tx_ant && (tx_ant & ~rdev->wiphy.available_antennas_tx)) ||
Ying Xue7f2b8562014-01-15 10:23:45 +08002151 (~rx_ant && (rx_ant & ~rdev->wiphy.available_antennas_rx)))
2152 return -EINVAL;
Bruno Randolfa7ffac92010-12-08 13:59:24 +09002153
Bruno Randolf7f531e02010-12-16 11:30:22 +09002154 tx_ant = tx_ant & rdev->wiphy.available_antennas_tx;
2155 rx_ant = rx_ant & rdev->wiphy.available_antennas_rx;
Bruno Randolfa7ffac92010-12-08 13:59:24 +09002156
Hila Gonene35e4d22012-06-27 17:19:42 +03002157 result = rdev_set_antenna(rdev, tx_ant, rx_ant);
Bruno Randolfafe0cbf2010-11-10 12:50:50 +09002158 if (result)
Ying Xue7f2b8562014-01-15 10:23:45 +08002159 return result;
Bruno Randolfafe0cbf2010-11-10 12:50:50 +09002160 }
2161
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002162 changed = 0;
2163
2164 if (info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]) {
2165 retry_short = nla_get_u8(
2166 info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]);
Ying Xue7f2b8562014-01-15 10:23:45 +08002167 if (retry_short == 0)
2168 return -EINVAL;
2169
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002170 changed |= WIPHY_PARAM_RETRY_SHORT;
2171 }
2172
2173 if (info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]) {
2174 retry_long = nla_get_u8(
2175 info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]);
Ying Xue7f2b8562014-01-15 10:23:45 +08002176 if (retry_long == 0)
2177 return -EINVAL;
2178
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002179 changed |= WIPHY_PARAM_RETRY_LONG;
2180 }
2181
2182 if (info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]) {
2183 frag_threshold = nla_get_u32(
2184 info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]);
Ying Xue7f2b8562014-01-15 10:23:45 +08002185 if (frag_threshold < 256)
2186 return -EINVAL;
2187
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002188 if (frag_threshold != (u32) -1) {
2189 /*
2190 * Fragments (apart from the last one) are required to
2191 * have even length. Make the fragmentation code
2192 * simpler by stripping LSB should someone try to use
2193 * odd threshold value.
2194 */
2195 frag_threshold &= ~0x1;
2196 }
2197 changed |= WIPHY_PARAM_FRAG_THRESHOLD;
2198 }
2199
2200 if (info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]) {
2201 rts_threshold = nla_get_u32(
2202 info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]);
2203 changed |= WIPHY_PARAM_RTS_THRESHOLD;
2204 }
2205
Lukáš Turek81077e82009-12-21 22:50:47 +01002206 if (info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]) {
2207 coverage_class = nla_get_u8(
2208 info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]);
2209 changed |= WIPHY_PARAM_COVERAGE_CLASS;
2210 }
2211
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002212 if (changed) {
2213 u8 old_retry_short, old_retry_long;
2214 u32 old_frag_threshold, old_rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01002215 u8 old_coverage_class;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002216
Ying Xue7f2b8562014-01-15 10:23:45 +08002217 if (!rdev->ops->set_wiphy_params)
2218 return -EOPNOTSUPP;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002219
2220 old_retry_short = rdev->wiphy.retry_short;
2221 old_retry_long = rdev->wiphy.retry_long;
2222 old_frag_threshold = rdev->wiphy.frag_threshold;
2223 old_rts_threshold = rdev->wiphy.rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01002224 old_coverage_class = rdev->wiphy.coverage_class;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002225
2226 if (changed & WIPHY_PARAM_RETRY_SHORT)
2227 rdev->wiphy.retry_short = retry_short;
2228 if (changed & WIPHY_PARAM_RETRY_LONG)
2229 rdev->wiphy.retry_long = retry_long;
2230 if (changed & WIPHY_PARAM_FRAG_THRESHOLD)
2231 rdev->wiphy.frag_threshold = frag_threshold;
2232 if (changed & WIPHY_PARAM_RTS_THRESHOLD)
2233 rdev->wiphy.rts_threshold = rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01002234 if (changed & WIPHY_PARAM_COVERAGE_CLASS)
2235 rdev->wiphy.coverage_class = coverage_class;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002236
Hila Gonene35e4d22012-06-27 17:19:42 +03002237 result = rdev_set_wiphy_params(rdev, changed);
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002238 if (result) {
2239 rdev->wiphy.retry_short = old_retry_short;
2240 rdev->wiphy.retry_long = old_retry_long;
2241 rdev->wiphy.frag_threshold = old_frag_threshold;
2242 rdev->wiphy.rts_threshold = old_rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01002243 rdev->wiphy.coverage_class = old_coverage_class;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002244 }
2245 }
Ying Xue7f2b8562014-01-15 10:23:45 +08002246 return 0;
Johannes Berg55682962007-09-20 13:09:35 -04002247}
2248
Johannes Berg71bbc992012-06-15 15:30:18 +02002249static inline u64 wdev_id(struct wireless_dev *wdev)
2250{
2251 return (u64)wdev->identifier |
Zhao, Gangf26cbf42014-04-21 12:53:03 +08002252 ((u64)wiphy_to_rdev(wdev->wiphy)->wiphy_idx << 32);
Johannes Berg71bbc992012-06-15 15:30:18 +02002253}
Johannes Berg55682962007-09-20 13:09:35 -04002254
Johannes Berg683b6d32012-11-08 21:25:48 +01002255static int nl80211_send_chandef(struct sk_buff *msg,
Janusz Dziedzicd2859df2013-11-06 13:55:51 +01002256 const struct cfg80211_chan_def *chandef)
Johannes Berg683b6d32012-11-08 21:25:48 +01002257{
Johannes Berg9f5e8f62012-11-22 16:59:45 +01002258 WARN_ON(!cfg80211_chandef_valid(chandef));
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002259
Johannes Berg683b6d32012-11-08 21:25:48 +01002260 if (nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ,
2261 chandef->chan->center_freq))
2262 return -ENOBUFS;
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002263 switch (chandef->width) {
2264 case NL80211_CHAN_WIDTH_20_NOHT:
2265 case NL80211_CHAN_WIDTH_20:
2266 case NL80211_CHAN_WIDTH_40:
2267 if (nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE,
2268 cfg80211_get_chandef_type(chandef)))
2269 return -ENOBUFS;
2270 break;
2271 default:
2272 break;
2273 }
2274 if (nla_put_u32(msg, NL80211_ATTR_CHANNEL_WIDTH, chandef->width))
2275 return -ENOBUFS;
2276 if (nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ1, chandef->center_freq1))
2277 return -ENOBUFS;
2278 if (chandef->center_freq2 &&
2279 nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ2, chandef->center_freq2))
Johannes Berg683b6d32012-11-08 21:25:48 +01002280 return -ENOBUFS;
2281 return 0;
2282}
2283
Eric W. Biederman15e47302012-09-07 20:12:54 +00002284static int nl80211_send_iface(struct sk_buff *msg, u32 portid, u32 seq, int flags,
Johannes Bergd7264052009-04-19 16:23:20 +02002285 struct cfg80211_registered_device *rdev,
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002286 struct wireless_dev *wdev)
Johannes Berg55682962007-09-20 13:09:35 -04002287{
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002288 struct net_device *dev = wdev->netdev;
Johannes Berg55682962007-09-20 13:09:35 -04002289 void *hdr;
2290
Eric W. Biederman15e47302012-09-07 20:12:54 +00002291 hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_INTERFACE);
Johannes Berg55682962007-09-20 13:09:35 -04002292 if (!hdr)
2293 return -1;
2294
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002295 if (dev &&
2296 (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
Johannes Berg98104fde2012-06-16 00:19:54 +02002297 nla_put_string(msg, NL80211_ATTR_IFNAME, dev->name)))
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002298 goto nla_put_failure;
2299
2300 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
2301 nla_put_u32(msg, NL80211_ATTR_IFTYPE, wdev->iftype) ||
Johannes Berg71bbc992012-06-15 15:30:18 +02002302 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) ||
Johannes Berg98104fde2012-06-16 00:19:54 +02002303 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, wdev_address(wdev)) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04002304 nla_put_u32(msg, NL80211_ATTR_GENERATION,
2305 rdev->devlist_generation ^
2306 (cfg80211_rdev_list_generation << 2)))
2307 goto nla_put_failure;
Johannes Bergf5ea9122009-08-07 16:17:38 +02002308
Johannes Berg5b7ccaf2012-07-12 19:45:08 +02002309 if (rdev->ops->get_channel) {
Johannes Berg683b6d32012-11-08 21:25:48 +01002310 int ret;
2311 struct cfg80211_chan_def chandef;
Johannes Berg5b7ccaf2012-07-12 19:45:08 +02002312
Johannes Berg683b6d32012-11-08 21:25:48 +01002313 ret = rdev_get_channel(rdev, wdev, &chandef);
2314 if (ret == 0) {
2315 if (nl80211_send_chandef(msg, &chandef))
2316 goto nla_put_failure;
2317 }
Pontus Fuchsd91df0e2012-04-03 16:39:58 +02002318 }
2319
Antonio Quartullib84e7a02012-11-07 12:52:20 +01002320 if (wdev->ssid_len) {
2321 if (nla_put(msg, NL80211_ATTR_SSID, wdev->ssid_len, wdev->ssid))
2322 goto nla_put_failure;
2323 }
2324
Johannes Berg55682962007-09-20 13:09:35 -04002325 return genlmsg_end(msg, hdr);
2326
2327 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07002328 genlmsg_cancel(msg, hdr);
2329 return -EMSGSIZE;
Johannes Berg55682962007-09-20 13:09:35 -04002330}
2331
2332static int nl80211_dump_interface(struct sk_buff *skb, struct netlink_callback *cb)
2333{
2334 int wp_idx = 0;
2335 int if_idx = 0;
2336 int wp_start = cb->args[0];
2337 int if_start = cb->args[1];
Johannes Bergf5ea9122009-08-07 16:17:38 +02002338 struct cfg80211_registered_device *rdev;
Johannes Berg55682962007-09-20 13:09:35 -04002339 struct wireless_dev *wdev;
2340
Johannes Berg5fe231e2013-05-08 21:45:15 +02002341 rtnl_lock();
Johannes Bergf5ea9122009-08-07 16:17:38 +02002342 list_for_each_entry(rdev, &cfg80211_rdev_list, list) {
2343 if (!net_eq(wiphy_net(&rdev->wiphy), sock_net(skb->sk)))
Johannes Berg463d0182009-07-14 00:33:35 +02002344 continue;
Johannes Bergbba95fe2008-07-29 13:22:51 +02002345 if (wp_idx < wp_start) {
2346 wp_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04002347 continue;
Johannes Bergbba95fe2008-07-29 13:22:51 +02002348 }
Johannes Berg55682962007-09-20 13:09:35 -04002349 if_idx = 0;
2350
Johannes Berg89a54e42012-06-15 14:33:17 +02002351 list_for_each_entry(wdev, &rdev->wdev_list, list) {
Johannes Bergbba95fe2008-07-29 13:22:51 +02002352 if (if_idx < if_start) {
2353 if_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04002354 continue;
Johannes Bergbba95fe2008-07-29 13:22:51 +02002355 }
Eric W. Biederman15e47302012-09-07 20:12:54 +00002356 if (nl80211_send_iface(skb, NETLINK_CB(cb->skb).portid,
Johannes Berg55682962007-09-20 13:09:35 -04002357 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002358 rdev, wdev) < 0) {
Johannes Bergbba95fe2008-07-29 13:22:51 +02002359 goto out;
2360 }
2361 if_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04002362 }
Johannes Bergbba95fe2008-07-29 13:22:51 +02002363
2364 wp_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04002365 }
Johannes Bergbba95fe2008-07-29 13:22:51 +02002366 out:
Johannes Berg5fe231e2013-05-08 21:45:15 +02002367 rtnl_unlock();
Johannes Berg55682962007-09-20 13:09:35 -04002368
2369 cb->args[0] = wp_idx;
2370 cb->args[1] = if_idx;
2371
2372 return skb->len;
2373}
2374
2375static int nl80211_get_interface(struct sk_buff *skb, struct genl_info *info)
2376{
2377 struct sk_buff *msg;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002378 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002379 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg55682962007-09-20 13:09:35 -04002380
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07002381 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -04002382 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02002383 return -ENOMEM;
Johannes Berg55682962007-09-20 13:09:35 -04002384
Eric W. Biederman15e47302012-09-07 20:12:54 +00002385 if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002386 rdev, wdev) < 0) {
Johannes Berg4c476992010-10-04 21:36:35 +02002387 nlmsg_free(msg);
2388 return -ENOBUFS;
2389 }
Johannes Berg55682962007-09-20 13:09:35 -04002390
Johannes Berg134e6372009-07-10 09:51:34 +00002391 return genlmsg_reply(msg, info);
Johannes Berg55682962007-09-20 13:09:35 -04002392}
2393
Michael Wu66f7ac52008-01-31 19:48:22 +01002394static const struct nla_policy mntr_flags_policy[NL80211_MNTR_FLAG_MAX + 1] = {
2395 [NL80211_MNTR_FLAG_FCSFAIL] = { .type = NLA_FLAG },
2396 [NL80211_MNTR_FLAG_PLCPFAIL] = { .type = NLA_FLAG },
2397 [NL80211_MNTR_FLAG_CONTROL] = { .type = NLA_FLAG },
2398 [NL80211_MNTR_FLAG_OTHER_BSS] = { .type = NLA_FLAG },
2399 [NL80211_MNTR_FLAG_COOK_FRAMES] = { .type = NLA_FLAG },
Felix Fietkaue057d3c2013-05-28 13:01:52 +02002400 [NL80211_MNTR_FLAG_ACTIVE] = { .type = NLA_FLAG },
Michael Wu66f7ac52008-01-31 19:48:22 +01002401};
2402
2403static int parse_monitor_flags(struct nlattr *nla, u32 *mntrflags)
2404{
2405 struct nlattr *flags[NL80211_MNTR_FLAG_MAX + 1];
2406 int flag;
2407
2408 *mntrflags = 0;
2409
2410 if (!nla)
2411 return -EINVAL;
2412
2413 if (nla_parse_nested(flags, NL80211_MNTR_FLAG_MAX,
2414 nla, mntr_flags_policy))
2415 return -EINVAL;
2416
2417 for (flag = 1; flag <= NL80211_MNTR_FLAG_MAX; flag++)
2418 if (flags[flag])
2419 *mntrflags |= (1<<flag);
2420
2421 return 0;
2422}
2423
Johannes Berg9bc383d2009-11-19 11:55:19 +01002424static int nl80211_valid_4addr(struct cfg80211_registered_device *rdev,
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002425 struct net_device *netdev, u8 use_4addr,
2426 enum nl80211_iftype iftype)
Johannes Berg9bc383d2009-11-19 11:55:19 +01002427{
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002428 if (!use_4addr) {
Jiri Pirkof350a0a82010-06-15 06:50:45 +00002429 if (netdev && (netdev->priv_flags & IFF_BRIDGE_PORT))
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002430 return -EBUSY;
Johannes Berg9bc383d2009-11-19 11:55:19 +01002431 return 0;
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002432 }
Johannes Berg9bc383d2009-11-19 11:55:19 +01002433
2434 switch (iftype) {
2435 case NL80211_IFTYPE_AP_VLAN:
2436 if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_AP)
2437 return 0;
2438 break;
2439 case NL80211_IFTYPE_STATION:
2440 if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_STATION)
2441 return 0;
2442 break;
2443 default:
2444 break;
2445 }
2446
2447 return -EOPNOTSUPP;
2448}
2449
Johannes Berg55682962007-09-20 13:09:35 -04002450static int nl80211_set_interface(struct sk_buff *skb, struct genl_info *info)
2451{
Johannes Berg4c476992010-10-04 21:36:35 +02002452 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002453 struct vif_params params;
Johannes Berge36d56b2009-06-09 21:04:43 +02002454 int err;
Johannes Berg04a773a2009-04-19 21:24:32 +02002455 enum nl80211_iftype otype, ntype;
Johannes Berg4c476992010-10-04 21:36:35 +02002456 struct net_device *dev = info->user_ptr[1];
Johannes Berg92ffe052008-09-16 20:39:36 +02002457 u32 _flags, *flags = NULL;
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002458 bool change = false;
Johannes Berg55682962007-09-20 13:09:35 -04002459
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002460 memset(&params, 0, sizeof(params));
2461
Johannes Berg04a773a2009-04-19 21:24:32 +02002462 otype = ntype = dev->ieee80211_ptr->iftype;
Johannes Berg55682962007-09-20 13:09:35 -04002463
Johannes Berg723b0382008-09-16 20:22:09 +02002464 if (info->attrs[NL80211_ATTR_IFTYPE]) {
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002465 ntype = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]);
Johannes Berg04a773a2009-04-19 21:24:32 +02002466 if (otype != ntype)
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002467 change = true;
Johannes Berg4c476992010-10-04 21:36:35 +02002468 if (ntype > NL80211_IFTYPE_MAX)
2469 return -EINVAL;
Johannes Berg723b0382008-09-16 20:22:09 +02002470 }
2471
Johannes Berg92ffe052008-09-16 20:39:36 +02002472 if (info->attrs[NL80211_ATTR_MESH_ID]) {
Johannes Berg29cbe682010-12-03 09:20:44 +01002473 struct wireless_dev *wdev = dev->ieee80211_ptr;
2474
Johannes Berg4c476992010-10-04 21:36:35 +02002475 if (ntype != NL80211_IFTYPE_MESH_POINT)
2476 return -EINVAL;
Johannes Berg29cbe682010-12-03 09:20:44 +01002477 if (netif_running(dev))
2478 return -EBUSY;
2479
2480 wdev_lock(wdev);
2481 BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN !=
2482 IEEE80211_MAX_MESH_ID_LEN);
2483 wdev->mesh_id_up_len =
2484 nla_len(info->attrs[NL80211_ATTR_MESH_ID]);
2485 memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]),
2486 wdev->mesh_id_up_len);
2487 wdev_unlock(wdev);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002488 }
2489
Felix Fietkau8b787642009-11-10 18:53:10 +01002490 if (info->attrs[NL80211_ATTR_4ADDR]) {
2491 params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]);
2492 change = true;
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002493 err = nl80211_valid_4addr(rdev, dev, params.use_4addr, ntype);
Johannes Berg9bc383d2009-11-19 11:55:19 +01002494 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02002495 return err;
Felix Fietkau8b787642009-11-10 18:53:10 +01002496 } else {
2497 params.use_4addr = -1;
2498 }
2499
Johannes Berg92ffe052008-09-16 20:39:36 +02002500 if (info->attrs[NL80211_ATTR_MNTR_FLAGS]) {
Johannes Berg4c476992010-10-04 21:36:35 +02002501 if (ntype != NL80211_IFTYPE_MONITOR)
2502 return -EINVAL;
Johannes Berg92ffe052008-09-16 20:39:36 +02002503 err = parse_monitor_flags(info->attrs[NL80211_ATTR_MNTR_FLAGS],
2504 &_flags);
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002505 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02002506 return err;
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002507
2508 flags = &_flags;
2509 change = true;
Johannes Berg92ffe052008-09-16 20:39:36 +02002510 }
Johannes Berg3b858752009-03-12 09:55:09 +01002511
Luciano Coelho18003292013-08-29 13:26:57 +03002512 if (flags && (*flags & MONITOR_FLAG_ACTIVE) &&
Felix Fietkaue057d3c2013-05-28 13:01:52 +02002513 !(rdev->wiphy.features & NL80211_FEATURE_ACTIVE_MONITOR))
2514 return -EOPNOTSUPP;
2515
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002516 if (change)
Johannes Berg3d54d252009-08-21 14:51:05 +02002517 err = cfg80211_change_iface(rdev, dev, ntype, flags, &params);
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002518 else
2519 err = 0;
Johannes Berg60719ff2008-09-16 14:55:09 +02002520
Johannes Berg9bc383d2009-11-19 11:55:19 +01002521 if (!err && params.use_4addr != -1)
2522 dev->ieee80211_ptr->use_4addr = params.use_4addr;
2523
Johannes Berg55682962007-09-20 13:09:35 -04002524 return err;
2525}
2526
2527static int nl80211_new_interface(struct sk_buff *skb, struct genl_info *info)
2528{
Johannes Berg4c476992010-10-04 21:36:35 +02002529 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002530 struct vif_params params;
Johannes Berg84efbb82012-06-16 00:00:26 +02002531 struct wireless_dev *wdev;
Johannes Berg1c90f9d2012-06-16 00:05:37 +02002532 struct sk_buff *msg;
Johannes Berg55682962007-09-20 13:09:35 -04002533 int err;
2534 enum nl80211_iftype type = NL80211_IFTYPE_UNSPECIFIED;
Michael Wu66f7ac52008-01-31 19:48:22 +01002535 u32 flags;
Johannes Berg55682962007-09-20 13:09:35 -04002536
Johannes Berg78f22b62014-03-24 17:57:27 +01002537 /* to avoid failing a new interface creation due to pending removal */
2538 cfg80211_destroy_ifaces(rdev);
2539
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002540 memset(&params, 0, sizeof(params));
2541
Johannes Berg55682962007-09-20 13:09:35 -04002542 if (!info->attrs[NL80211_ATTR_IFNAME])
2543 return -EINVAL;
2544
2545 if (info->attrs[NL80211_ATTR_IFTYPE]) {
2546 type = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]);
2547 if (type > NL80211_IFTYPE_MAX)
2548 return -EINVAL;
2549 }
2550
Johannes Berg79c97e92009-07-07 03:56:12 +02002551 if (!rdev->ops->add_virtual_intf ||
Johannes Berg4c476992010-10-04 21:36:35 +02002552 !(rdev->wiphy.interface_modes & (1 << type)))
2553 return -EOPNOTSUPP;
Johannes Berg55682962007-09-20 13:09:35 -04002554
Arend van Spriel1c18f142013-01-08 10:17:27 +01002555 if (type == NL80211_IFTYPE_P2P_DEVICE && info->attrs[NL80211_ATTR_MAC]) {
2556 nla_memcpy(params.macaddr, info->attrs[NL80211_ATTR_MAC],
2557 ETH_ALEN);
2558 if (!is_valid_ether_addr(params.macaddr))
2559 return -EADDRNOTAVAIL;
2560 }
2561
Johannes Berg9bc383d2009-11-19 11:55:19 +01002562 if (info->attrs[NL80211_ATTR_4ADDR]) {
Felix Fietkau8b787642009-11-10 18:53:10 +01002563 params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]);
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002564 err = nl80211_valid_4addr(rdev, NULL, params.use_4addr, type);
Johannes Berg9bc383d2009-11-19 11:55:19 +01002565 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02002566 return err;
Johannes Berg9bc383d2009-11-19 11:55:19 +01002567 }
Felix Fietkau8b787642009-11-10 18:53:10 +01002568
Johannes Berg1c90f9d2012-06-16 00:05:37 +02002569 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
2570 if (!msg)
2571 return -ENOMEM;
2572
Michael Wu66f7ac52008-01-31 19:48:22 +01002573 err = parse_monitor_flags(type == NL80211_IFTYPE_MONITOR ?
2574 info->attrs[NL80211_ATTR_MNTR_FLAGS] : NULL,
2575 &flags);
Felix Fietkaue057d3c2013-05-28 13:01:52 +02002576
Luciano Coelho18003292013-08-29 13:26:57 +03002577 if (!err && (flags & MONITOR_FLAG_ACTIVE) &&
Felix Fietkaue057d3c2013-05-28 13:01:52 +02002578 !(rdev->wiphy.features & NL80211_FEATURE_ACTIVE_MONITOR))
2579 return -EOPNOTSUPP;
2580
Hila Gonene35e4d22012-06-27 17:19:42 +03002581 wdev = rdev_add_virtual_intf(rdev,
2582 nla_data(info->attrs[NL80211_ATTR_IFNAME]),
2583 type, err ? NULL : &flags, &params);
Johannes Berg1c90f9d2012-06-16 00:05:37 +02002584 if (IS_ERR(wdev)) {
2585 nlmsg_free(msg);
Johannes Berg84efbb82012-06-16 00:00:26 +02002586 return PTR_ERR(wdev);
Johannes Berg1c90f9d2012-06-16 00:05:37 +02002587 }
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002588
Johannes Berg78f22b62014-03-24 17:57:27 +01002589 if (info->attrs[NL80211_ATTR_IFACE_SOCKET_OWNER])
2590 wdev->owner_nlportid = info->snd_portid;
2591
Johannes Berg98104fde2012-06-16 00:19:54 +02002592 switch (type) {
2593 case NL80211_IFTYPE_MESH_POINT:
2594 if (!info->attrs[NL80211_ATTR_MESH_ID])
2595 break;
Johannes Berg29cbe682010-12-03 09:20:44 +01002596 wdev_lock(wdev);
2597 BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN !=
2598 IEEE80211_MAX_MESH_ID_LEN);
2599 wdev->mesh_id_up_len =
2600 nla_len(info->attrs[NL80211_ATTR_MESH_ID]);
2601 memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]),
2602 wdev->mesh_id_up_len);
2603 wdev_unlock(wdev);
Johannes Berg98104fde2012-06-16 00:19:54 +02002604 break;
2605 case NL80211_IFTYPE_P2P_DEVICE:
2606 /*
2607 * P2P Device doesn't have a netdev, so doesn't go
2608 * through the netdev notifier and must be added here
2609 */
2610 mutex_init(&wdev->mtx);
2611 INIT_LIST_HEAD(&wdev->event_list);
2612 spin_lock_init(&wdev->event_lock);
2613 INIT_LIST_HEAD(&wdev->mgmt_registrations);
2614 spin_lock_init(&wdev->mgmt_registrations_lock);
2615
Johannes Berg98104fde2012-06-16 00:19:54 +02002616 wdev->identifier = ++rdev->wdev_id;
2617 list_add_rcu(&wdev->list, &rdev->wdev_list);
2618 rdev->devlist_generation++;
Johannes Berg98104fde2012-06-16 00:19:54 +02002619 break;
2620 default:
2621 break;
Johannes Berg29cbe682010-12-03 09:20:44 +01002622 }
2623
Eric W. Biederman15e47302012-09-07 20:12:54 +00002624 if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berg1c90f9d2012-06-16 00:05:37 +02002625 rdev, wdev) < 0) {
2626 nlmsg_free(msg);
2627 return -ENOBUFS;
2628 }
2629
2630 return genlmsg_reply(msg, info);
Johannes Berg55682962007-09-20 13:09:35 -04002631}
2632
2633static int nl80211_del_interface(struct sk_buff *skb, struct genl_info *info)
2634{
Johannes Berg4c476992010-10-04 21:36:35 +02002635 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg84efbb82012-06-16 00:00:26 +02002636 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg55682962007-09-20 13:09:35 -04002637
Johannes Berg4c476992010-10-04 21:36:35 +02002638 if (!rdev->ops->del_virtual_intf)
2639 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01002640
Johannes Berg84efbb82012-06-16 00:00:26 +02002641 /*
2642 * If we remove a wireless device without a netdev then clear
2643 * user_ptr[1] so that nl80211_post_doit won't dereference it
2644 * to check if it needs to do dev_put(). Otherwise it crashes
2645 * since the wdev has been freed, unlike with a netdev where
2646 * we need the dev_put() for the netdev to really be freed.
2647 */
2648 if (!wdev->netdev)
2649 info->user_ptr[1] = NULL;
2650
Hila Gonene35e4d22012-06-27 17:19:42 +03002651 return rdev_del_virtual_intf(rdev, wdev);
Johannes Berg55682962007-09-20 13:09:35 -04002652}
2653
Simon Wunderlich1d9d9212011-11-18 14:20:43 +01002654static int nl80211_set_noack_map(struct sk_buff *skb, struct genl_info *info)
2655{
2656 struct cfg80211_registered_device *rdev = info->user_ptr[0];
2657 struct net_device *dev = info->user_ptr[1];
2658 u16 noack_map;
2659
2660 if (!info->attrs[NL80211_ATTR_NOACK_MAP])
2661 return -EINVAL;
2662
2663 if (!rdev->ops->set_noack_map)
2664 return -EOPNOTSUPP;
2665
2666 noack_map = nla_get_u16(info->attrs[NL80211_ATTR_NOACK_MAP]);
2667
Hila Gonene35e4d22012-06-27 17:19:42 +03002668 return rdev_set_noack_map(rdev, dev, noack_map);
Simon Wunderlich1d9d9212011-11-18 14:20:43 +01002669}
2670
Johannes Berg41ade002007-12-19 02:03:29 +01002671struct get_key_cookie {
2672 struct sk_buff *msg;
2673 int error;
Johannes Bergb9454e82009-07-08 13:29:08 +02002674 int idx;
Johannes Berg41ade002007-12-19 02:03:29 +01002675};
2676
2677static void get_key_callback(void *c, struct key_params *params)
2678{
Johannes Bergb9454e82009-07-08 13:29:08 +02002679 struct nlattr *key;
Johannes Berg41ade002007-12-19 02:03:29 +01002680 struct get_key_cookie *cookie = c;
2681
David S. Miller9360ffd2012-03-29 04:41:26 -04002682 if ((params->key &&
2683 nla_put(cookie->msg, NL80211_ATTR_KEY_DATA,
2684 params->key_len, params->key)) ||
2685 (params->seq &&
2686 nla_put(cookie->msg, NL80211_ATTR_KEY_SEQ,
2687 params->seq_len, params->seq)) ||
2688 (params->cipher &&
2689 nla_put_u32(cookie->msg, NL80211_ATTR_KEY_CIPHER,
2690 params->cipher)))
2691 goto nla_put_failure;
Johannes Berg41ade002007-12-19 02:03:29 +01002692
Johannes Bergb9454e82009-07-08 13:29:08 +02002693 key = nla_nest_start(cookie->msg, NL80211_ATTR_KEY);
2694 if (!key)
2695 goto nla_put_failure;
2696
David S. Miller9360ffd2012-03-29 04:41:26 -04002697 if ((params->key &&
2698 nla_put(cookie->msg, NL80211_KEY_DATA,
2699 params->key_len, params->key)) ||
2700 (params->seq &&
2701 nla_put(cookie->msg, NL80211_KEY_SEQ,
2702 params->seq_len, params->seq)) ||
2703 (params->cipher &&
2704 nla_put_u32(cookie->msg, NL80211_KEY_CIPHER,
2705 params->cipher)))
2706 goto nla_put_failure;
Johannes Bergb9454e82009-07-08 13:29:08 +02002707
David S. Miller9360ffd2012-03-29 04:41:26 -04002708 if (nla_put_u8(cookie->msg, NL80211_ATTR_KEY_IDX, cookie->idx))
2709 goto nla_put_failure;
Johannes Bergb9454e82009-07-08 13:29:08 +02002710
2711 nla_nest_end(cookie->msg, key);
2712
Johannes Berg41ade002007-12-19 02:03:29 +01002713 return;
2714 nla_put_failure:
2715 cookie->error = 1;
2716}
2717
2718static int nl80211_get_key(struct sk_buff *skb, struct genl_info *info)
2719{
Johannes Berg4c476992010-10-04 21:36:35 +02002720 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg41ade002007-12-19 02:03:29 +01002721 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02002722 struct net_device *dev = info->user_ptr[1];
Johannes Berg41ade002007-12-19 02:03:29 +01002723 u8 key_idx = 0;
Johannes Berge31b8212010-10-05 19:39:30 +02002724 const u8 *mac_addr = NULL;
2725 bool pairwise;
Johannes Berg41ade002007-12-19 02:03:29 +01002726 struct get_key_cookie cookie = {
2727 .error = 0,
2728 };
2729 void *hdr;
2730 struct sk_buff *msg;
2731
2732 if (info->attrs[NL80211_ATTR_KEY_IDX])
2733 key_idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]);
2734
Jouni Malinen3cfcf6ac2009-01-08 13:32:02 +02002735 if (key_idx > 5)
Johannes Berg41ade002007-12-19 02:03:29 +01002736 return -EINVAL;
2737
2738 if (info->attrs[NL80211_ATTR_MAC])
2739 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
2740
Johannes Berge31b8212010-10-05 19:39:30 +02002741 pairwise = !!mac_addr;
2742 if (info->attrs[NL80211_ATTR_KEY_TYPE]) {
2743 u32 kt = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]);
2744 if (kt >= NUM_NL80211_KEYTYPES)
2745 return -EINVAL;
2746 if (kt != NL80211_KEYTYPE_GROUP &&
2747 kt != NL80211_KEYTYPE_PAIRWISE)
2748 return -EINVAL;
2749 pairwise = kt == NL80211_KEYTYPE_PAIRWISE;
2750 }
2751
Johannes Berg4c476992010-10-04 21:36:35 +02002752 if (!rdev->ops->get_key)
2753 return -EOPNOTSUPP;
Johannes Berg41ade002007-12-19 02:03:29 +01002754
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07002755 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02002756 if (!msg)
2757 return -ENOMEM;
Johannes Berg41ade002007-12-19 02:03:29 +01002758
Eric W. Biederman15e47302012-09-07 20:12:54 +00002759 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berg41ade002007-12-19 02:03:29 +01002760 NL80211_CMD_NEW_KEY);
Dan Carpentercb35fba2013-08-14 14:50:01 +03002761 if (!hdr)
Johannes Berg9fe271a2013-10-25 11:15:12 +02002762 goto nla_put_failure;
Johannes Berg41ade002007-12-19 02:03:29 +01002763
2764 cookie.msg = msg;
Johannes Bergb9454e82009-07-08 13:29:08 +02002765 cookie.idx = key_idx;
Johannes Berg41ade002007-12-19 02:03:29 +01002766
David S. Miller9360ffd2012-03-29 04:41:26 -04002767 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
2768 nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_idx))
2769 goto nla_put_failure;
2770 if (mac_addr &&
2771 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr))
2772 goto nla_put_failure;
Johannes Berg41ade002007-12-19 02:03:29 +01002773
Johannes Berge31b8212010-10-05 19:39:30 +02002774 if (pairwise && mac_addr &&
2775 !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN))
2776 return -ENOENT;
2777
Hila Gonene35e4d22012-06-27 17:19:42 +03002778 err = rdev_get_key(rdev, dev, key_idx, pairwise, mac_addr, &cookie,
2779 get_key_callback);
Johannes Berg41ade002007-12-19 02:03:29 +01002780
2781 if (err)
Niko Jokinen6c95e2a2009-07-15 11:00:53 +03002782 goto free_msg;
Johannes Berg41ade002007-12-19 02:03:29 +01002783
2784 if (cookie.error)
2785 goto nla_put_failure;
2786
2787 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02002788 return genlmsg_reply(msg, info);
Johannes Berg41ade002007-12-19 02:03:29 +01002789
2790 nla_put_failure:
2791 err = -ENOBUFS;
Niko Jokinen6c95e2a2009-07-15 11:00:53 +03002792 free_msg:
Johannes Berg41ade002007-12-19 02:03:29 +01002793 nlmsg_free(msg);
Johannes Berg41ade002007-12-19 02:03:29 +01002794 return err;
2795}
2796
2797static int nl80211_set_key(struct sk_buff *skb, struct genl_info *info)
2798{
Johannes Berg4c476992010-10-04 21:36:35 +02002799 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Bergb9454e82009-07-08 13:29:08 +02002800 struct key_parse key;
Johannes Berg41ade002007-12-19 02:03:29 +01002801 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02002802 struct net_device *dev = info->user_ptr[1];
Johannes Berg41ade002007-12-19 02:03:29 +01002803
Johannes Bergb9454e82009-07-08 13:29:08 +02002804 err = nl80211_parse_key(info, &key);
2805 if (err)
2806 return err;
2807
2808 if (key.idx < 0)
Johannes Berg41ade002007-12-19 02:03:29 +01002809 return -EINVAL;
2810
Johannes Bergb9454e82009-07-08 13:29:08 +02002811 /* only support setting default key */
2812 if (!key.def && !key.defmgmt)
Johannes Berg41ade002007-12-19 02:03:29 +01002813 return -EINVAL;
2814
Johannes Bergfffd0932009-07-08 14:22:54 +02002815 wdev_lock(dev->ieee80211_ptr);
Johannes Bergdbd2fd62010-12-09 19:58:59 +01002816
2817 if (key.def) {
2818 if (!rdev->ops->set_default_key) {
2819 err = -EOPNOTSUPP;
2820 goto out;
2821 }
2822
2823 err = nl80211_key_allowed(dev->ieee80211_ptr);
2824 if (err)
2825 goto out;
2826
Hila Gonene35e4d22012-06-27 17:19:42 +03002827 err = rdev_set_default_key(rdev, dev, key.idx,
Johannes Bergdbd2fd62010-12-09 19:58:59 +01002828 key.def_uni, key.def_multi);
2829
2830 if (err)
2831 goto out;
Johannes Bergfffd0932009-07-08 14:22:54 +02002832
Johannes Berg3d23e342009-09-29 23:27:28 +02002833#ifdef CONFIG_CFG80211_WEXT
Johannes Bergdbd2fd62010-12-09 19:58:59 +01002834 dev->ieee80211_ptr->wext.default_key = key.idx;
Johannes Berg08645122009-05-11 13:54:58 +02002835#endif
Johannes Bergdbd2fd62010-12-09 19:58:59 +01002836 } else {
2837 if (key.def_uni || !key.def_multi) {
2838 err = -EINVAL;
2839 goto out;
2840 }
2841
2842 if (!rdev->ops->set_default_mgmt_key) {
2843 err = -EOPNOTSUPP;
2844 goto out;
2845 }
2846
2847 err = nl80211_key_allowed(dev->ieee80211_ptr);
2848 if (err)
2849 goto out;
2850
Hila Gonene35e4d22012-06-27 17:19:42 +03002851 err = rdev_set_default_mgmt_key(rdev, dev, key.idx);
Johannes Bergdbd2fd62010-12-09 19:58:59 +01002852 if (err)
2853 goto out;
2854
2855#ifdef CONFIG_CFG80211_WEXT
2856 dev->ieee80211_ptr->wext.default_mgmt_key = key.idx;
2857#endif
2858 }
2859
2860 out:
Johannes Bergfffd0932009-07-08 14:22:54 +02002861 wdev_unlock(dev->ieee80211_ptr);
Johannes Berg41ade002007-12-19 02:03:29 +01002862
Johannes Berg41ade002007-12-19 02:03:29 +01002863 return err;
2864}
2865
2866static int nl80211_new_key(struct sk_buff *skb, struct genl_info *info)
2867{
Johannes Berg4c476992010-10-04 21:36:35 +02002868 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Bergfffd0932009-07-08 14:22:54 +02002869 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02002870 struct net_device *dev = info->user_ptr[1];
Johannes Bergb9454e82009-07-08 13:29:08 +02002871 struct key_parse key;
Johannes Berge31b8212010-10-05 19:39:30 +02002872 const u8 *mac_addr = NULL;
Johannes Berg41ade002007-12-19 02:03:29 +01002873
Johannes Bergb9454e82009-07-08 13:29:08 +02002874 err = nl80211_parse_key(info, &key);
2875 if (err)
2876 return err;
Johannes Berg41ade002007-12-19 02:03:29 +01002877
Johannes Bergb9454e82009-07-08 13:29:08 +02002878 if (!key.p.key)
Johannes Berg41ade002007-12-19 02:03:29 +01002879 return -EINVAL;
2880
Johannes Berg41ade002007-12-19 02:03:29 +01002881 if (info->attrs[NL80211_ATTR_MAC])
2882 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
2883
Johannes Berge31b8212010-10-05 19:39:30 +02002884 if (key.type == -1) {
2885 if (mac_addr)
2886 key.type = NL80211_KEYTYPE_PAIRWISE;
2887 else
2888 key.type = NL80211_KEYTYPE_GROUP;
2889 }
2890
2891 /* for now */
2892 if (key.type != NL80211_KEYTYPE_PAIRWISE &&
2893 key.type != NL80211_KEYTYPE_GROUP)
2894 return -EINVAL;
2895
Johannes Berg4c476992010-10-04 21:36:35 +02002896 if (!rdev->ops->add_key)
2897 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01002898
Johannes Berge31b8212010-10-05 19:39:30 +02002899 if (cfg80211_validate_key_settings(rdev, &key.p, key.idx,
2900 key.type == NL80211_KEYTYPE_PAIRWISE,
2901 mac_addr))
Johannes Berg4c476992010-10-04 21:36:35 +02002902 return -EINVAL;
Johannes Bergfffd0932009-07-08 14:22:54 +02002903
2904 wdev_lock(dev->ieee80211_ptr);
2905 err = nl80211_key_allowed(dev->ieee80211_ptr);
2906 if (!err)
Hila Gonene35e4d22012-06-27 17:19:42 +03002907 err = rdev_add_key(rdev, dev, key.idx,
2908 key.type == NL80211_KEYTYPE_PAIRWISE,
2909 mac_addr, &key.p);
Johannes Bergfffd0932009-07-08 14:22:54 +02002910 wdev_unlock(dev->ieee80211_ptr);
Johannes Berg41ade002007-12-19 02:03:29 +01002911
Johannes Berg41ade002007-12-19 02:03:29 +01002912 return err;
2913}
2914
2915static int nl80211_del_key(struct sk_buff *skb, struct genl_info *info)
2916{
Johannes Berg4c476992010-10-04 21:36:35 +02002917 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg41ade002007-12-19 02:03:29 +01002918 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02002919 struct net_device *dev = info->user_ptr[1];
Johannes Berg41ade002007-12-19 02:03:29 +01002920 u8 *mac_addr = NULL;
Johannes Bergb9454e82009-07-08 13:29:08 +02002921 struct key_parse key;
Johannes Berg41ade002007-12-19 02:03:29 +01002922
Johannes Bergb9454e82009-07-08 13:29:08 +02002923 err = nl80211_parse_key(info, &key);
2924 if (err)
2925 return err;
Johannes Berg41ade002007-12-19 02:03:29 +01002926
2927 if (info->attrs[NL80211_ATTR_MAC])
2928 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
2929
Johannes Berge31b8212010-10-05 19:39:30 +02002930 if (key.type == -1) {
2931 if (mac_addr)
2932 key.type = NL80211_KEYTYPE_PAIRWISE;
2933 else
2934 key.type = NL80211_KEYTYPE_GROUP;
2935 }
2936
2937 /* for now */
2938 if (key.type != NL80211_KEYTYPE_PAIRWISE &&
2939 key.type != NL80211_KEYTYPE_GROUP)
2940 return -EINVAL;
2941
Johannes Berg4c476992010-10-04 21:36:35 +02002942 if (!rdev->ops->del_key)
2943 return -EOPNOTSUPP;
Johannes Berg41ade002007-12-19 02:03:29 +01002944
Johannes Bergfffd0932009-07-08 14:22:54 +02002945 wdev_lock(dev->ieee80211_ptr);
2946 err = nl80211_key_allowed(dev->ieee80211_ptr);
Johannes Berge31b8212010-10-05 19:39:30 +02002947
2948 if (key.type == NL80211_KEYTYPE_PAIRWISE && mac_addr &&
2949 !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN))
2950 err = -ENOENT;
2951
Johannes Bergfffd0932009-07-08 14:22:54 +02002952 if (!err)
Hila Gonene35e4d22012-06-27 17:19:42 +03002953 err = rdev_del_key(rdev, dev, key.idx,
2954 key.type == NL80211_KEYTYPE_PAIRWISE,
2955 mac_addr);
Johannes Berg41ade002007-12-19 02:03:29 +01002956
Johannes Berg3d23e342009-09-29 23:27:28 +02002957#ifdef CONFIG_CFG80211_WEXT
Johannes Berg08645122009-05-11 13:54:58 +02002958 if (!err) {
Johannes Bergb9454e82009-07-08 13:29:08 +02002959 if (key.idx == dev->ieee80211_ptr->wext.default_key)
Johannes Berg08645122009-05-11 13:54:58 +02002960 dev->ieee80211_ptr->wext.default_key = -1;
Johannes Bergb9454e82009-07-08 13:29:08 +02002961 else if (key.idx == dev->ieee80211_ptr->wext.default_mgmt_key)
Johannes Berg08645122009-05-11 13:54:58 +02002962 dev->ieee80211_ptr->wext.default_mgmt_key = -1;
2963 }
2964#endif
Johannes Bergfffd0932009-07-08 14:22:54 +02002965 wdev_unlock(dev->ieee80211_ptr);
Johannes Berg08645122009-05-11 13:54:58 +02002966
Johannes Berg41ade002007-12-19 02:03:29 +01002967 return err;
2968}
2969
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +05302970/* This function returns an error or the number of nested attributes */
2971static int validate_acl_mac_addrs(struct nlattr *nl_attr)
2972{
2973 struct nlattr *attr;
2974 int n_entries = 0, tmp;
2975
2976 nla_for_each_nested(attr, nl_attr, tmp) {
2977 if (nla_len(attr) != ETH_ALEN)
2978 return -EINVAL;
2979
2980 n_entries++;
2981 }
2982
2983 return n_entries;
2984}
2985
2986/*
2987 * This function parses ACL information and allocates memory for ACL data.
2988 * On successful return, the calling function is responsible to free the
2989 * ACL buffer returned by this function.
2990 */
2991static struct cfg80211_acl_data *parse_acl_data(struct wiphy *wiphy,
2992 struct genl_info *info)
2993{
2994 enum nl80211_acl_policy acl_policy;
2995 struct nlattr *attr;
2996 struct cfg80211_acl_data *acl;
2997 int i = 0, n_entries, tmp;
2998
2999 if (!wiphy->max_acl_mac_addrs)
3000 return ERR_PTR(-EOPNOTSUPP);
3001
3002 if (!info->attrs[NL80211_ATTR_ACL_POLICY])
3003 return ERR_PTR(-EINVAL);
3004
3005 acl_policy = nla_get_u32(info->attrs[NL80211_ATTR_ACL_POLICY]);
3006 if (acl_policy != NL80211_ACL_POLICY_ACCEPT_UNLESS_LISTED &&
3007 acl_policy != NL80211_ACL_POLICY_DENY_UNLESS_LISTED)
3008 return ERR_PTR(-EINVAL);
3009
3010 if (!info->attrs[NL80211_ATTR_MAC_ADDRS])
3011 return ERR_PTR(-EINVAL);
3012
3013 n_entries = validate_acl_mac_addrs(info->attrs[NL80211_ATTR_MAC_ADDRS]);
3014 if (n_entries < 0)
3015 return ERR_PTR(n_entries);
3016
3017 if (n_entries > wiphy->max_acl_mac_addrs)
3018 return ERR_PTR(-ENOTSUPP);
3019
3020 acl = kzalloc(sizeof(*acl) + (sizeof(struct mac_address) * n_entries),
3021 GFP_KERNEL);
3022 if (!acl)
3023 return ERR_PTR(-ENOMEM);
3024
3025 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_MAC_ADDRS], tmp) {
3026 memcpy(acl->mac_addrs[i].addr, nla_data(attr), ETH_ALEN);
3027 i++;
3028 }
3029
3030 acl->n_acl_entries = n_entries;
3031 acl->acl_policy = acl_policy;
3032
3033 return acl;
3034}
3035
3036static int nl80211_set_mac_acl(struct sk_buff *skb, struct genl_info *info)
3037{
3038 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3039 struct net_device *dev = info->user_ptr[1];
3040 struct cfg80211_acl_data *acl;
3041 int err;
3042
3043 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
3044 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
3045 return -EOPNOTSUPP;
3046
3047 if (!dev->ieee80211_ptr->beacon_interval)
3048 return -EINVAL;
3049
3050 acl = parse_acl_data(&rdev->wiphy, info);
3051 if (IS_ERR(acl))
3052 return PTR_ERR(acl);
3053
3054 err = rdev_set_mac_acl(rdev, dev, acl);
3055
3056 kfree(acl);
3057
3058 return err;
3059}
3060
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003061static int nl80211_parse_beacon(struct nlattr *attrs[],
Johannes Berg88600202012-02-13 15:17:18 +01003062 struct cfg80211_beacon_data *bcn)
Johannes Berged1b6cc2007-12-19 02:03:32 +01003063{
Johannes Berg88600202012-02-13 15:17:18 +01003064 bool haveinfo = false;
Johannes Berged1b6cc2007-12-19 02:03:32 +01003065
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003066 if (!is_valid_ie_attr(attrs[NL80211_ATTR_BEACON_TAIL]) ||
3067 !is_valid_ie_attr(attrs[NL80211_ATTR_IE]) ||
3068 !is_valid_ie_attr(attrs[NL80211_ATTR_IE_PROBE_RESP]) ||
3069 !is_valid_ie_attr(attrs[NL80211_ATTR_IE_ASSOC_RESP]))
Johannes Bergf4a11bb2009-03-27 12:40:28 +01003070 return -EINVAL;
3071
Johannes Berg88600202012-02-13 15:17:18 +01003072 memset(bcn, 0, sizeof(*bcn));
Johannes Berged1b6cc2007-12-19 02:03:32 +01003073
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003074 if (attrs[NL80211_ATTR_BEACON_HEAD]) {
3075 bcn->head = nla_data(attrs[NL80211_ATTR_BEACON_HEAD]);
3076 bcn->head_len = nla_len(attrs[NL80211_ATTR_BEACON_HEAD]);
Johannes Berg88600202012-02-13 15:17:18 +01003077 if (!bcn->head_len)
3078 return -EINVAL;
3079 haveinfo = true;
Johannes Berged1b6cc2007-12-19 02:03:32 +01003080 }
3081
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003082 if (attrs[NL80211_ATTR_BEACON_TAIL]) {
3083 bcn->tail = nla_data(attrs[NL80211_ATTR_BEACON_TAIL]);
3084 bcn->tail_len = nla_len(attrs[NL80211_ATTR_BEACON_TAIL]);
Johannes Berg88600202012-02-13 15:17:18 +01003085 haveinfo = true;
Johannes Berged1b6cc2007-12-19 02:03:32 +01003086 }
3087
Johannes Berg4c476992010-10-04 21:36:35 +02003088 if (!haveinfo)
3089 return -EINVAL;
Johannes Berged1b6cc2007-12-19 02:03:32 +01003090
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003091 if (attrs[NL80211_ATTR_IE]) {
3092 bcn->beacon_ies = nla_data(attrs[NL80211_ATTR_IE]);
3093 bcn->beacon_ies_len = nla_len(attrs[NL80211_ATTR_IE]);
Jouni Malinen9946ecf2011-08-10 23:55:56 +03003094 }
3095
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003096 if (attrs[NL80211_ATTR_IE_PROBE_RESP]) {
Johannes Berg88600202012-02-13 15:17:18 +01003097 bcn->proberesp_ies =
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003098 nla_data(attrs[NL80211_ATTR_IE_PROBE_RESP]);
Johannes Berg88600202012-02-13 15:17:18 +01003099 bcn->proberesp_ies_len =
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003100 nla_len(attrs[NL80211_ATTR_IE_PROBE_RESP]);
Jouni Malinen9946ecf2011-08-10 23:55:56 +03003101 }
3102
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003103 if (attrs[NL80211_ATTR_IE_ASSOC_RESP]) {
Johannes Berg88600202012-02-13 15:17:18 +01003104 bcn->assocresp_ies =
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003105 nla_data(attrs[NL80211_ATTR_IE_ASSOC_RESP]);
Johannes Berg88600202012-02-13 15:17:18 +01003106 bcn->assocresp_ies_len =
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003107 nla_len(attrs[NL80211_ATTR_IE_ASSOC_RESP]);
Jouni Malinen9946ecf2011-08-10 23:55:56 +03003108 }
3109
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003110 if (attrs[NL80211_ATTR_PROBE_RESP]) {
3111 bcn->probe_resp = nla_data(attrs[NL80211_ATTR_PROBE_RESP]);
3112 bcn->probe_resp_len = nla_len(attrs[NL80211_ATTR_PROBE_RESP]);
Arik Nemtsov00f740e2011-11-10 11:28:56 +02003113 }
3114
Johannes Berg88600202012-02-13 15:17:18 +01003115 return 0;
3116}
3117
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003118static bool nl80211_get_ap_channel(struct cfg80211_registered_device *rdev,
3119 struct cfg80211_ap_settings *params)
3120{
3121 struct wireless_dev *wdev;
3122 bool ret = false;
3123
Johannes Berg89a54e42012-06-15 14:33:17 +02003124 list_for_each_entry(wdev, &rdev->wdev_list, list) {
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003125 if (wdev->iftype != NL80211_IFTYPE_AP &&
3126 wdev->iftype != NL80211_IFTYPE_P2P_GO)
3127 continue;
3128
Johannes Berg683b6d32012-11-08 21:25:48 +01003129 if (!wdev->preset_chandef.chan)
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003130 continue;
3131
Johannes Berg683b6d32012-11-08 21:25:48 +01003132 params->chandef = wdev->preset_chandef;
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003133 ret = true;
3134 break;
3135 }
3136
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003137 return ret;
3138}
3139
Jouni Malinene39e5b52012-09-30 19:29:39 +03003140static bool nl80211_valid_auth_type(struct cfg80211_registered_device *rdev,
3141 enum nl80211_auth_type auth_type,
3142 enum nl80211_commands cmd)
3143{
3144 if (auth_type > NL80211_AUTHTYPE_MAX)
3145 return false;
3146
3147 switch (cmd) {
3148 case NL80211_CMD_AUTHENTICATE:
3149 if (!(rdev->wiphy.features & NL80211_FEATURE_SAE) &&
3150 auth_type == NL80211_AUTHTYPE_SAE)
3151 return false;
3152 return true;
3153 case NL80211_CMD_CONNECT:
3154 case NL80211_CMD_START_AP:
3155 /* SAE not supported yet */
3156 if (auth_type == NL80211_AUTHTYPE_SAE)
3157 return false;
3158 return true;
3159 default:
3160 return false;
3161 }
3162}
3163
Johannes Berg88600202012-02-13 15:17:18 +01003164static int nl80211_start_ap(struct sk_buff *skb, struct genl_info *info)
3165{
3166 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3167 struct net_device *dev = info->user_ptr[1];
3168 struct wireless_dev *wdev = dev->ieee80211_ptr;
3169 struct cfg80211_ap_settings params;
3170 int err;
3171
3172 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
3173 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
3174 return -EOPNOTSUPP;
3175
3176 if (!rdev->ops->start_ap)
3177 return -EOPNOTSUPP;
3178
3179 if (wdev->beacon_interval)
3180 return -EALREADY;
3181
3182 memset(&params, 0, sizeof(params));
3183
3184 /* these are required for START_AP */
3185 if (!info->attrs[NL80211_ATTR_BEACON_INTERVAL] ||
3186 !info->attrs[NL80211_ATTR_DTIM_PERIOD] ||
3187 !info->attrs[NL80211_ATTR_BEACON_HEAD])
3188 return -EINVAL;
3189
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003190 err = nl80211_parse_beacon(info->attrs, &params.beacon);
Johannes Berg88600202012-02-13 15:17:18 +01003191 if (err)
3192 return err;
3193
3194 params.beacon_interval =
3195 nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]);
3196 params.dtim_period =
3197 nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]);
3198
3199 err = cfg80211_validate_beacon_int(rdev, params.beacon_interval);
3200 if (err)
3201 return err;
3202
3203 /*
3204 * In theory, some of these attributes should be required here
3205 * but since they were not used when the command was originally
3206 * added, keep them optional for old user space programs to let
3207 * them continue to work with drivers that do not need the
3208 * additional information -- drivers must check!
3209 */
3210 if (info->attrs[NL80211_ATTR_SSID]) {
3211 params.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
3212 params.ssid_len =
3213 nla_len(info->attrs[NL80211_ATTR_SSID]);
3214 if (params.ssid_len == 0 ||
3215 params.ssid_len > IEEE80211_MAX_SSID_LEN)
3216 return -EINVAL;
3217 }
3218
3219 if (info->attrs[NL80211_ATTR_HIDDEN_SSID]) {
3220 params.hidden_ssid = nla_get_u32(
3221 info->attrs[NL80211_ATTR_HIDDEN_SSID]);
3222 if (params.hidden_ssid != NL80211_HIDDEN_SSID_NOT_IN_USE &&
3223 params.hidden_ssid != NL80211_HIDDEN_SSID_ZERO_LEN &&
3224 params.hidden_ssid != NL80211_HIDDEN_SSID_ZERO_CONTENTS)
3225 return -EINVAL;
3226 }
3227
3228 params.privacy = !!info->attrs[NL80211_ATTR_PRIVACY];
3229
3230 if (info->attrs[NL80211_ATTR_AUTH_TYPE]) {
3231 params.auth_type = nla_get_u32(
3232 info->attrs[NL80211_ATTR_AUTH_TYPE]);
Jouni Malinene39e5b52012-09-30 19:29:39 +03003233 if (!nl80211_valid_auth_type(rdev, params.auth_type,
3234 NL80211_CMD_START_AP))
Johannes Berg88600202012-02-13 15:17:18 +01003235 return -EINVAL;
3236 } else
3237 params.auth_type = NL80211_AUTHTYPE_AUTOMATIC;
3238
3239 err = nl80211_crypto_settings(rdev, info, &params.crypto,
3240 NL80211_MAX_NR_CIPHER_SUITES);
3241 if (err)
3242 return err;
3243
Vasanthakumar Thiagarajan1b658f12012-03-02 15:50:02 +05303244 if (info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]) {
3245 if (!(rdev->wiphy.features & NL80211_FEATURE_INACTIVITY_TIMER))
3246 return -EOPNOTSUPP;
3247 params.inactivity_timeout = nla_get_u16(
3248 info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]);
3249 }
3250
Johannes Berg53cabad2012-11-14 15:17:28 +01003251 if (info->attrs[NL80211_ATTR_P2P_CTWINDOW]) {
3252 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
3253 return -EINVAL;
3254 params.p2p_ctwindow =
3255 nla_get_u8(info->attrs[NL80211_ATTR_P2P_CTWINDOW]);
3256 if (params.p2p_ctwindow > 127)
3257 return -EINVAL;
3258 if (params.p2p_ctwindow != 0 &&
3259 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_CTWIN))
3260 return -EINVAL;
3261 }
3262
3263 if (info->attrs[NL80211_ATTR_P2P_OPPPS]) {
3264 u8 tmp;
3265
3266 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
3267 return -EINVAL;
3268 tmp = nla_get_u8(info->attrs[NL80211_ATTR_P2P_OPPPS]);
3269 if (tmp > 1)
3270 return -EINVAL;
3271 params.p2p_opp_ps = tmp;
3272 if (params.p2p_opp_ps != 0 &&
3273 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_OPPPS))
3274 return -EINVAL;
3275 }
3276
Johannes Bergaa430da2012-05-16 23:50:18 +02003277 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
Johannes Berg683b6d32012-11-08 21:25:48 +01003278 err = nl80211_parse_chandef(rdev, info, &params.chandef);
3279 if (err)
3280 return err;
3281 } else if (wdev->preset_chandef.chan) {
3282 params.chandef = wdev->preset_chandef;
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003283 } else if (!nl80211_get_ap_channel(rdev, &params))
Johannes Bergaa430da2012-05-16 23:50:18 +02003284 return -EINVAL;
3285
Ilan Peer174e0cd2014-02-23 09:13:01 +02003286 if (!cfg80211_reg_can_beacon(&rdev->wiphy, &params.chandef,
3287 wdev->iftype))
Johannes Bergaa430da2012-05-16 23:50:18 +02003288 return -EINVAL;
3289
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +05303290 if (info->attrs[NL80211_ATTR_ACL_POLICY]) {
3291 params.acl = parse_acl_data(&rdev->wiphy, info);
3292 if (IS_ERR(params.acl))
3293 return PTR_ERR(params.acl);
3294 }
3295
Simon Wunderlichc56589e2013-11-21 18:19:49 +01003296 wdev_lock(wdev);
Hila Gonene35e4d22012-06-27 17:19:42 +03003297 err = rdev_start_ap(rdev, dev, &params);
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003298 if (!err) {
Johannes Berg683b6d32012-11-08 21:25:48 +01003299 wdev->preset_chandef = params.chandef;
Johannes Berg88600202012-02-13 15:17:18 +01003300 wdev->beacon_interval = params.beacon_interval;
Michal Kazior9e0e2962014-01-29 14:22:27 +01003301 wdev->chandef = params.chandef;
Antonio Quartulli06e191e2012-11-07 12:52:19 +01003302 wdev->ssid_len = params.ssid_len;
3303 memcpy(wdev->ssid, params.ssid, wdev->ssid_len);
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003304 }
Simon Wunderlichc56589e2013-11-21 18:19:49 +01003305 wdev_unlock(wdev);
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +05303306
3307 kfree(params.acl);
3308
Johannes Berg56d18932011-05-09 18:41:15 +02003309 return err;
Johannes Berged1b6cc2007-12-19 02:03:32 +01003310}
3311
Johannes Berg88600202012-02-13 15:17:18 +01003312static int nl80211_set_beacon(struct sk_buff *skb, struct genl_info *info)
3313{
3314 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3315 struct net_device *dev = info->user_ptr[1];
3316 struct wireless_dev *wdev = dev->ieee80211_ptr;
3317 struct cfg80211_beacon_data params;
3318 int err;
3319
3320 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
3321 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
3322 return -EOPNOTSUPP;
3323
3324 if (!rdev->ops->change_beacon)
3325 return -EOPNOTSUPP;
3326
3327 if (!wdev->beacon_interval)
3328 return -EINVAL;
3329
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003330 err = nl80211_parse_beacon(info->attrs, &params);
Johannes Berg88600202012-02-13 15:17:18 +01003331 if (err)
3332 return err;
3333
Simon Wunderlichc56589e2013-11-21 18:19:49 +01003334 wdev_lock(wdev);
3335 err = rdev_change_beacon(rdev, dev, &params);
3336 wdev_unlock(wdev);
3337
3338 return err;
Johannes Berg88600202012-02-13 15:17:18 +01003339}
3340
3341static int nl80211_stop_ap(struct sk_buff *skb, struct genl_info *info)
Johannes Berged1b6cc2007-12-19 02:03:32 +01003342{
Johannes Berg4c476992010-10-04 21:36:35 +02003343 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3344 struct net_device *dev = info->user_ptr[1];
Johannes Berged1b6cc2007-12-19 02:03:32 +01003345
Ilan Peer7c8d5e02014-02-25 15:33:38 +02003346 return cfg80211_stop_ap(rdev, dev, false);
Johannes Berged1b6cc2007-12-19 02:03:32 +01003347}
3348
Johannes Berg5727ef12007-12-19 02:03:34 +01003349static const struct nla_policy sta_flags_policy[NL80211_STA_FLAG_MAX + 1] = {
3350 [NL80211_STA_FLAG_AUTHORIZED] = { .type = NLA_FLAG },
3351 [NL80211_STA_FLAG_SHORT_PREAMBLE] = { .type = NLA_FLAG },
3352 [NL80211_STA_FLAG_WME] = { .type = NLA_FLAG },
Jouni Malinen0e467242009-05-11 21:57:55 +03003353 [NL80211_STA_FLAG_MFP] = { .type = NLA_FLAG },
Javier Cardonab39c48f2011-04-07 15:08:30 -07003354 [NL80211_STA_FLAG_AUTHENTICATED] = { .type = NLA_FLAG },
Johannes Bergd83023d2011-12-14 09:29:15 +01003355 [NL80211_STA_FLAG_TDLS_PEER] = { .type = NLA_FLAG },
Johannes Berg5727ef12007-12-19 02:03:34 +01003356};
3357
Johannes Bergeccb8e82009-05-11 21:57:56 +03003358static int parse_station_flags(struct genl_info *info,
Johannes Bergbdd3ae32012-01-02 13:30:03 +01003359 enum nl80211_iftype iftype,
Johannes Bergeccb8e82009-05-11 21:57:56 +03003360 struct station_parameters *params)
Johannes Berg5727ef12007-12-19 02:03:34 +01003361{
3362 struct nlattr *flags[NL80211_STA_FLAG_MAX + 1];
Johannes Bergeccb8e82009-05-11 21:57:56 +03003363 struct nlattr *nla;
Johannes Berg5727ef12007-12-19 02:03:34 +01003364 int flag;
3365
Johannes Bergeccb8e82009-05-11 21:57:56 +03003366 /*
3367 * Try parsing the new attribute first so userspace
3368 * can specify both for older kernels.
3369 */
3370 nla = info->attrs[NL80211_ATTR_STA_FLAGS2];
3371 if (nla) {
3372 struct nl80211_sta_flag_update *sta_flags;
Johannes Berg5727ef12007-12-19 02:03:34 +01003373
Johannes Bergeccb8e82009-05-11 21:57:56 +03003374 sta_flags = nla_data(nla);
3375 params->sta_flags_mask = sta_flags->mask;
3376 params->sta_flags_set = sta_flags->set;
Johannes Berg77ee7c82013-02-15 00:48:33 +01003377 params->sta_flags_set &= params->sta_flags_mask;
Johannes Bergeccb8e82009-05-11 21:57:56 +03003378 if ((params->sta_flags_mask |
3379 params->sta_flags_set) & BIT(__NL80211_STA_FLAG_INVALID))
3380 return -EINVAL;
3381 return 0;
3382 }
3383
3384 /* if present, parse the old attribute */
3385
3386 nla = info->attrs[NL80211_ATTR_STA_FLAGS];
Johannes Berg5727ef12007-12-19 02:03:34 +01003387 if (!nla)
3388 return 0;
3389
3390 if (nla_parse_nested(flags, NL80211_STA_FLAG_MAX,
3391 nla, sta_flags_policy))
3392 return -EINVAL;
3393
Johannes Bergbdd3ae32012-01-02 13:30:03 +01003394 /*
3395 * Only allow certain flags for interface types so that
3396 * other attributes are silently ignored. Remember that
3397 * this is backward compatibility code with old userspace
3398 * and shouldn't be hit in other cases anyway.
3399 */
3400 switch (iftype) {
3401 case NL80211_IFTYPE_AP:
3402 case NL80211_IFTYPE_AP_VLAN:
3403 case NL80211_IFTYPE_P2P_GO:
3404 params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) |
3405 BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) |
3406 BIT(NL80211_STA_FLAG_WME) |
3407 BIT(NL80211_STA_FLAG_MFP);
3408 break;
3409 case NL80211_IFTYPE_P2P_CLIENT:
3410 case NL80211_IFTYPE_STATION:
3411 params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) |
3412 BIT(NL80211_STA_FLAG_TDLS_PEER);
3413 break;
3414 case NL80211_IFTYPE_MESH_POINT:
3415 params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHENTICATED) |
3416 BIT(NL80211_STA_FLAG_MFP) |
3417 BIT(NL80211_STA_FLAG_AUTHORIZED);
3418 default:
3419 return -EINVAL;
3420 }
Johannes Berg5727ef12007-12-19 02:03:34 +01003421
Johannes Berg3383b5a2012-05-10 20:14:43 +02003422 for (flag = 1; flag <= NL80211_STA_FLAG_MAX; flag++) {
3423 if (flags[flag]) {
Johannes Bergeccb8e82009-05-11 21:57:56 +03003424 params->sta_flags_set |= (1<<flag);
Johannes Berg5727ef12007-12-19 02:03:34 +01003425
Johannes Berg3383b5a2012-05-10 20:14:43 +02003426 /* no longer support new API additions in old API */
3427 if (flag > NL80211_STA_FLAG_MAX_OLD_API)
3428 return -EINVAL;
3429 }
3430 }
3431
Johannes Berg5727ef12007-12-19 02:03:34 +01003432 return 0;
3433}
3434
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003435static bool nl80211_put_sta_rate(struct sk_buff *msg, struct rate_info *info,
3436 int attr)
3437{
3438 struct nlattr *rate;
Vladimir Kondratiev8eb41c82012-07-05 14:25:49 +03003439 u32 bitrate;
3440 u16 bitrate_compat;
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003441
3442 rate = nla_nest_start(msg, attr);
3443 if (!rate)
Johannes Bergdb9c64c2012-11-09 14:56:41 +01003444 return false;
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003445
3446 /* cfg80211_calculate_bitrate will return 0 for mcs >= 32 */
3447 bitrate = cfg80211_calculate_bitrate(info);
Vladimir Kondratiev8eb41c82012-07-05 14:25:49 +03003448 /* report 16-bit bitrate only if we can */
3449 bitrate_compat = bitrate < (1UL << 16) ? bitrate : 0;
Johannes Bergdb9c64c2012-11-09 14:56:41 +01003450 if (bitrate > 0 &&
3451 nla_put_u32(msg, NL80211_RATE_INFO_BITRATE32, bitrate))
3452 return false;
3453 if (bitrate_compat > 0 &&
3454 nla_put_u16(msg, NL80211_RATE_INFO_BITRATE, bitrate_compat))
3455 return false;
3456
3457 if (info->flags & RATE_INFO_FLAGS_MCS) {
3458 if (nla_put_u8(msg, NL80211_RATE_INFO_MCS, info->mcs))
3459 return false;
3460 if (info->flags & RATE_INFO_FLAGS_40_MHZ_WIDTH &&
3461 nla_put_flag(msg, NL80211_RATE_INFO_40_MHZ_WIDTH))
3462 return false;
3463 if (info->flags & RATE_INFO_FLAGS_SHORT_GI &&
3464 nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI))
3465 return false;
3466 } else if (info->flags & RATE_INFO_FLAGS_VHT_MCS) {
3467 if (nla_put_u8(msg, NL80211_RATE_INFO_VHT_MCS, info->mcs))
3468 return false;
3469 if (nla_put_u8(msg, NL80211_RATE_INFO_VHT_NSS, info->nss))
3470 return false;
3471 if (info->flags & RATE_INFO_FLAGS_40_MHZ_WIDTH &&
3472 nla_put_flag(msg, NL80211_RATE_INFO_40_MHZ_WIDTH))
3473 return false;
3474 if (info->flags & RATE_INFO_FLAGS_80_MHZ_WIDTH &&
3475 nla_put_flag(msg, NL80211_RATE_INFO_80_MHZ_WIDTH))
3476 return false;
3477 if (info->flags & RATE_INFO_FLAGS_80P80_MHZ_WIDTH &&
3478 nla_put_flag(msg, NL80211_RATE_INFO_80P80_MHZ_WIDTH))
3479 return false;
3480 if (info->flags & RATE_INFO_FLAGS_160_MHZ_WIDTH &&
3481 nla_put_flag(msg, NL80211_RATE_INFO_160_MHZ_WIDTH))
3482 return false;
3483 if (info->flags & RATE_INFO_FLAGS_SHORT_GI &&
3484 nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI))
3485 return false;
3486 }
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003487
3488 nla_nest_end(msg, rate);
3489 return true;
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003490}
3491
Felix Fietkau119363c2013-04-22 16:29:30 +02003492static bool nl80211_put_signal(struct sk_buff *msg, u8 mask, s8 *signal,
3493 int id)
3494{
3495 void *attr;
3496 int i = 0;
3497
3498 if (!mask)
3499 return true;
3500
3501 attr = nla_nest_start(msg, id);
3502 if (!attr)
3503 return false;
3504
3505 for (i = 0; i < IEEE80211_MAX_CHAINS; i++) {
3506 if (!(mask & BIT(i)))
3507 continue;
3508
3509 if (nla_put_u8(msg, i, signal[i]))
3510 return false;
3511 }
3512
3513 nla_nest_end(msg, attr);
3514
3515 return true;
3516}
3517
Eric W. Biederman15e47302012-09-07 20:12:54 +00003518static int nl80211_send_station(struct sk_buff *msg, u32 portid, u32 seq,
John W. Linville66266b32012-03-15 13:25:41 -04003519 int flags,
3520 struct cfg80211_registered_device *rdev,
3521 struct net_device *dev,
Johannes Berg98b62182009-12-23 13:15:44 +01003522 const u8 *mac_addr, struct station_info *sinfo)
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003523{
3524 void *hdr;
Paul Stewartf4263c92011-03-31 09:25:41 -07003525 struct nlattr *sinfoattr, *bss_param;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003526
Eric W. Biederman15e47302012-09-07 20:12:54 +00003527 hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_STATION);
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003528 if (!hdr)
3529 return -1;
3530
David S. Miller9360ffd2012-03-29 04:41:26 -04003531 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
3532 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) ||
3533 nla_put_u32(msg, NL80211_ATTR_GENERATION, sinfo->generation))
3534 goto nla_put_failure;
Johannes Bergf5ea9122009-08-07 16:17:38 +02003535
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003536 sinfoattr = nla_nest_start(msg, NL80211_ATTR_STA_INFO);
3537 if (!sinfoattr)
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003538 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04003539 if ((sinfo->filled & STATION_INFO_CONNECTED_TIME) &&
3540 nla_put_u32(msg, NL80211_STA_INFO_CONNECTED_TIME,
3541 sinfo->connected_time))
3542 goto nla_put_failure;
3543 if ((sinfo->filled & STATION_INFO_INACTIVE_TIME) &&
3544 nla_put_u32(msg, NL80211_STA_INFO_INACTIVE_TIME,
3545 sinfo->inactive_time))
3546 goto nla_put_failure;
Vladimir Kondratiev42745e02013-02-04 13:53:11 +02003547 if ((sinfo->filled & (STATION_INFO_RX_BYTES |
3548 STATION_INFO_RX_BYTES64)) &&
David S. Miller9360ffd2012-03-29 04:41:26 -04003549 nla_put_u32(msg, NL80211_STA_INFO_RX_BYTES,
Vladimir Kondratiev42745e02013-02-04 13:53:11 +02003550 (u32)sinfo->rx_bytes))
3551 goto nla_put_failure;
3552 if ((sinfo->filled & (STATION_INFO_TX_BYTES |
Felix Fietkau4325d722013-05-23 15:05:59 +02003553 STATION_INFO_TX_BYTES64)) &&
Vladimir Kondratiev42745e02013-02-04 13:53:11 +02003554 nla_put_u32(msg, NL80211_STA_INFO_TX_BYTES,
3555 (u32)sinfo->tx_bytes))
3556 goto nla_put_failure;
3557 if ((sinfo->filled & STATION_INFO_RX_BYTES64) &&
3558 nla_put_u64(msg, NL80211_STA_INFO_RX_BYTES64,
David S. Miller9360ffd2012-03-29 04:41:26 -04003559 sinfo->rx_bytes))
3560 goto nla_put_failure;
Vladimir Kondratiev42745e02013-02-04 13:53:11 +02003561 if ((sinfo->filled & STATION_INFO_TX_BYTES64) &&
3562 nla_put_u64(msg, NL80211_STA_INFO_TX_BYTES64,
David S. Miller9360ffd2012-03-29 04:41:26 -04003563 sinfo->tx_bytes))
3564 goto nla_put_failure;
3565 if ((sinfo->filled & STATION_INFO_LLID) &&
3566 nla_put_u16(msg, NL80211_STA_INFO_LLID, sinfo->llid))
3567 goto nla_put_failure;
3568 if ((sinfo->filled & STATION_INFO_PLID) &&
3569 nla_put_u16(msg, NL80211_STA_INFO_PLID, sinfo->plid))
3570 goto nla_put_failure;
3571 if ((sinfo->filled & STATION_INFO_PLINK_STATE) &&
3572 nla_put_u8(msg, NL80211_STA_INFO_PLINK_STATE,
3573 sinfo->plink_state))
3574 goto nla_put_failure;
John W. Linville66266b32012-03-15 13:25:41 -04003575 switch (rdev->wiphy.signal_type) {
3576 case CFG80211_SIGNAL_TYPE_MBM:
David S. Miller9360ffd2012-03-29 04:41:26 -04003577 if ((sinfo->filled & STATION_INFO_SIGNAL) &&
3578 nla_put_u8(msg, NL80211_STA_INFO_SIGNAL,
3579 sinfo->signal))
3580 goto nla_put_failure;
3581 if ((sinfo->filled & STATION_INFO_SIGNAL_AVG) &&
3582 nla_put_u8(msg, NL80211_STA_INFO_SIGNAL_AVG,
3583 sinfo->signal_avg))
3584 goto nla_put_failure;
John W. Linville66266b32012-03-15 13:25:41 -04003585 break;
3586 default:
3587 break;
3588 }
Felix Fietkau119363c2013-04-22 16:29:30 +02003589 if (sinfo->filled & STATION_INFO_CHAIN_SIGNAL) {
3590 if (!nl80211_put_signal(msg, sinfo->chains,
3591 sinfo->chain_signal,
3592 NL80211_STA_INFO_CHAIN_SIGNAL))
3593 goto nla_put_failure;
3594 }
3595 if (sinfo->filled & STATION_INFO_CHAIN_SIGNAL_AVG) {
3596 if (!nl80211_put_signal(msg, sinfo->chains,
3597 sinfo->chain_signal_avg,
3598 NL80211_STA_INFO_CHAIN_SIGNAL_AVG))
3599 goto nla_put_failure;
3600 }
Henning Rogge420e7fa2008-12-11 22:04:19 +01003601 if (sinfo->filled & STATION_INFO_TX_BITRATE) {
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003602 if (!nl80211_put_sta_rate(msg, &sinfo->txrate,
3603 NL80211_STA_INFO_TX_BITRATE))
Henning Rogge420e7fa2008-12-11 22:04:19 +01003604 goto nla_put_failure;
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003605 }
3606 if (sinfo->filled & STATION_INFO_RX_BITRATE) {
3607 if (!nl80211_put_sta_rate(msg, &sinfo->rxrate,
3608 NL80211_STA_INFO_RX_BITRATE))
3609 goto nla_put_failure;
Henning Rogge420e7fa2008-12-11 22:04:19 +01003610 }
David S. Miller9360ffd2012-03-29 04:41:26 -04003611 if ((sinfo->filled & STATION_INFO_RX_PACKETS) &&
3612 nla_put_u32(msg, NL80211_STA_INFO_RX_PACKETS,
3613 sinfo->rx_packets))
3614 goto nla_put_failure;
3615 if ((sinfo->filled & STATION_INFO_TX_PACKETS) &&
3616 nla_put_u32(msg, NL80211_STA_INFO_TX_PACKETS,
3617 sinfo->tx_packets))
3618 goto nla_put_failure;
3619 if ((sinfo->filled & STATION_INFO_TX_RETRIES) &&
3620 nla_put_u32(msg, NL80211_STA_INFO_TX_RETRIES,
3621 sinfo->tx_retries))
3622 goto nla_put_failure;
3623 if ((sinfo->filled & STATION_INFO_TX_FAILED) &&
3624 nla_put_u32(msg, NL80211_STA_INFO_TX_FAILED,
3625 sinfo->tx_failed))
3626 goto nla_put_failure;
3627 if ((sinfo->filled & STATION_INFO_BEACON_LOSS_COUNT) &&
3628 nla_put_u32(msg, NL80211_STA_INFO_BEACON_LOSS,
3629 sinfo->beacon_loss_count))
3630 goto nla_put_failure;
Marco Porsch3b1c5a52013-01-07 16:04:52 +01003631 if ((sinfo->filled & STATION_INFO_LOCAL_PM) &&
3632 nla_put_u32(msg, NL80211_STA_INFO_LOCAL_PM,
3633 sinfo->local_pm))
3634 goto nla_put_failure;
3635 if ((sinfo->filled & STATION_INFO_PEER_PM) &&
3636 nla_put_u32(msg, NL80211_STA_INFO_PEER_PM,
3637 sinfo->peer_pm))
3638 goto nla_put_failure;
3639 if ((sinfo->filled & STATION_INFO_NONPEER_PM) &&
3640 nla_put_u32(msg, NL80211_STA_INFO_NONPEER_PM,
3641 sinfo->nonpeer_pm))
3642 goto nla_put_failure;
Paul Stewartf4263c92011-03-31 09:25:41 -07003643 if (sinfo->filled & STATION_INFO_BSS_PARAM) {
3644 bss_param = nla_nest_start(msg, NL80211_STA_INFO_BSS_PARAM);
3645 if (!bss_param)
3646 goto nla_put_failure;
3647
David S. Miller9360ffd2012-03-29 04:41:26 -04003648 if (((sinfo->bss_param.flags & BSS_PARAM_FLAGS_CTS_PROT) &&
3649 nla_put_flag(msg, NL80211_STA_BSS_PARAM_CTS_PROT)) ||
3650 ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_PREAMBLE) &&
3651 nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_PREAMBLE)) ||
3652 ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_SLOT_TIME) &&
3653 nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_SLOT_TIME)) ||
3654 nla_put_u8(msg, NL80211_STA_BSS_PARAM_DTIM_PERIOD,
3655 sinfo->bss_param.dtim_period) ||
3656 nla_put_u16(msg, NL80211_STA_BSS_PARAM_BEACON_INTERVAL,
3657 sinfo->bss_param.beacon_interval))
3658 goto nla_put_failure;
Paul Stewartf4263c92011-03-31 09:25:41 -07003659
3660 nla_nest_end(msg, bss_param);
3661 }
David S. Miller9360ffd2012-03-29 04:41:26 -04003662 if ((sinfo->filled & STATION_INFO_STA_FLAGS) &&
3663 nla_put(msg, NL80211_STA_INFO_STA_FLAGS,
3664 sizeof(struct nl80211_sta_flag_update),
3665 &sinfo->sta_flags))
3666 goto nla_put_failure;
John W. Linville7eab0f62012-04-12 14:25:14 -04003667 if ((sinfo->filled & STATION_INFO_T_OFFSET) &&
3668 nla_put_u64(msg, NL80211_STA_INFO_T_OFFSET,
3669 sinfo->t_offset))
3670 goto nla_put_failure;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003671 nla_nest_end(msg, sinfoattr);
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003672
David S. Miller9360ffd2012-03-29 04:41:26 -04003673 if ((sinfo->filled & STATION_INFO_ASSOC_REQ_IES) &&
3674 nla_put(msg, NL80211_ATTR_IE, sinfo->assoc_req_ies_len,
3675 sinfo->assoc_req_ies))
3676 goto nla_put_failure;
Jouni Malinen50d3dfb2011-08-08 12:11:52 +03003677
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003678 return genlmsg_end(msg, hdr);
3679
3680 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07003681 genlmsg_cancel(msg, hdr);
3682 return -EMSGSIZE;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003683}
3684
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003685static int nl80211_dump_station(struct sk_buff *skb,
Johannes Bergbba95fe2008-07-29 13:22:51 +02003686 struct netlink_callback *cb)
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003687{
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003688 struct station_info sinfo;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08003689 struct cfg80211_registered_device *rdev;
Johannes Berg97990a02013-04-19 01:02:55 +02003690 struct wireless_dev *wdev;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003691 u8 mac_addr[ETH_ALEN];
Johannes Berg97990a02013-04-19 01:02:55 +02003692 int sta_idx = cb->args[2];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003693 int err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003694
Zhao, Gang1b8ec872014-04-21 12:53:02 +08003695 err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev);
Johannes Berg67748892010-10-04 21:14:06 +02003696 if (err)
3697 return err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02003698
Johannes Berg97990a02013-04-19 01:02:55 +02003699 if (!wdev->netdev) {
3700 err = -EINVAL;
3701 goto out_err;
3702 }
3703
Zhao, Gang1b8ec872014-04-21 12:53:02 +08003704 if (!rdev->ops->dump_station) {
Jouni Malineneec60b02009-03-20 21:21:19 +02003705 err = -EOPNOTSUPP;
Johannes Bergbba95fe2008-07-29 13:22:51 +02003706 goto out_err;
3707 }
3708
Johannes Bergbba95fe2008-07-29 13:22:51 +02003709 while (1) {
Jouni Malinenf612ced2011-08-11 11:46:22 +03003710 memset(&sinfo, 0, sizeof(sinfo));
Zhao, Gang1b8ec872014-04-21 12:53:02 +08003711 err = rdev_dump_station(rdev, wdev->netdev, sta_idx,
Hila Gonene35e4d22012-06-27 17:19:42 +03003712 mac_addr, &sinfo);
Johannes Bergbba95fe2008-07-29 13:22:51 +02003713 if (err == -ENOENT)
3714 break;
3715 if (err)
Johannes Berg3b858752009-03-12 09:55:09 +01003716 goto out_err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02003717
3718 if (nl80211_send_station(skb,
Eric W. Biederman15e47302012-09-07 20:12:54 +00003719 NETLINK_CB(cb->skb).portid,
Johannes Bergbba95fe2008-07-29 13:22:51 +02003720 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08003721 rdev, wdev->netdev, mac_addr,
Johannes Bergbba95fe2008-07-29 13:22:51 +02003722 &sinfo) < 0)
3723 goto out;
3724
3725 sta_idx++;
3726 }
3727
3728
3729 out:
Johannes Berg97990a02013-04-19 01:02:55 +02003730 cb->args[2] = sta_idx;
Johannes Bergbba95fe2008-07-29 13:22:51 +02003731 err = skb->len;
Johannes Bergbba95fe2008-07-29 13:22:51 +02003732 out_err:
Zhao, Gang1b8ec872014-04-21 12:53:02 +08003733 nl80211_finish_wdev_dump(rdev);
Johannes Bergbba95fe2008-07-29 13:22:51 +02003734
3735 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003736}
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003737
Johannes Berg5727ef12007-12-19 02:03:34 +01003738static int nl80211_get_station(struct sk_buff *skb, struct genl_info *info)
3739{
Johannes Berg4c476992010-10-04 21:36:35 +02003740 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3741 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003742 struct station_info sinfo;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003743 struct sk_buff *msg;
3744 u8 *mac_addr = NULL;
Johannes Berg4c476992010-10-04 21:36:35 +02003745 int err;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003746
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003747 memset(&sinfo, 0, sizeof(sinfo));
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003748
3749 if (!info->attrs[NL80211_ATTR_MAC])
3750 return -EINVAL;
3751
3752 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
3753
Johannes Berg4c476992010-10-04 21:36:35 +02003754 if (!rdev->ops->get_station)
3755 return -EOPNOTSUPP;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003756
Hila Gonene35e4d22012-06-27 17:19:42 +03003757 err = rdev_get_station(rdev, dev, mac_addr, &sinfo);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003758 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02003759 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003760
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07003761 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003762 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02003763 return -ENOMEM;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003764
Eric W. Biederman15e47302012-09-07 20:12:54 +00003765 if (nl80211_send_station(msg, info->snd_portid, info->snd_seq, 0,
John W. Linville66266b32012-03-15 13:25:41 -04003766 rdev, dev, mac_addr, &sinfo) < 0) {
Johannes Berg4c476992010-10-04 21:36:35 +02003767 nlmsg_free(msg);
3768 return -ENOBUFS;
3769 }
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003770
Johannes Berg4c476992010-10-04 21:36:35 +02003771 return genlmsg_reply(msg, info);
Johannes Berg5727ef12007-12-19 02:03:34 +01003772}
3773
Johannes Berg77ee7c82013-02-15 00:48:33 +01003774int cfg80211_check_station_change(struct wiphy *wiphy,
3775 struct station_parameters *params,
3776 enum cfg80211_station_type statype)
3777{
3778 if (params->listen_interval != -1)
3779 return -EINVAL;
3780 if (params->aid)
3781 return -EINVAL;
3782
3783 /* When you run into this, adjust the code below for the new flag */
3784 BUILD_BUG_ON(NL80211_STA_FLAG_MAX != 7);
3785
3786 switch (statype) {
Thomas Pederseneef941e2013-03-04 13:06:11 -08003787 case CFG80211_STA_MESH_PEER_KERNEL:
3788 case CFG80211_STA_MESH_PEER_USER:
Johannes Berg77ee7c82013-02-15 00:48:33 +01003789 /*
3790 * No ignoring the TDLS flag here -- the userspace mesh
3791 * code doesn't have the bug of including TDLS in the
3792 * mask everywhere.
3793 */
3794 if (params->sta_flags_mask &
3795 ~(BIT(NL80211_STA_FLAG_AUTHENTICATED) |
3796 BIT(NL80211_STA_FLAG_MFP) |
3797 BIT(NL80211_STA_FLAG_AUTHORIZED)))
3798 return -EINVAL;
3799 break;
3800 case CFG80211_STA_TDLS_PEER_SETUP:
3801 case CFG80211_STA_TDLS_PEER_ACTIVE:
3802 if (!(params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)))
3803 return -EINVAL;
3804 /* ignore since it can't change */
3805 params->sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER);
3806 break;
3807 default:
3808 /* disallow mesh-specific things */
3809 if (params->plink_action != NL80211_PLINK_ACTION_NO_ACTION)
3810 return -EINVAL;
3811 if (params->local_pm)
3812 return -EINVAL;
3813 if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE)
3814 return -EINVAL;
3815 }
3816
3817 if (statype != CFG80211_STA_TDLS_PEER_SETUP &&
3818 statype != CFG80211_STA_TDLS_PEER_ACTIVE) {
3819 /* TDLS can't be set, ... */
3820 if (params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))
3821 return -EINVAL;
3822 /*
3823 * ... but don't bother the driver with it. This works around
3824 * a hostapd/wpa_supplicant issue -- it always includes the
3825 * TLDS_PEER flag in the mask even for AP mode.
3826 */
3827 params->sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER);
3828 }
3829
3830 if (statype != CFG80211_STA_TDLS_PEER_SETUP) {
3831 /* reject other things that can't change */
3832 if (params->sta_modify_mask & STATION_PARAM_APPLY_UAPSD)
3833 return -EINVAL;
3834 if (params->sta_modify_mask & STATION_PARAM_APPLY_CAPABILITY)
3835 return -EINVAL;
3836 if (params->supported_rates)
3837 return -EINVAL;
3838 if (params->ext_capab || params->ht_capa || params->vht_capa)
3839 return -EINVAL;
3840 }
3841
3842 if (statype != CFG80211_STA_AP_CLIENT) {
3843 if (params->vlan)
3844 return -EINVAL;
3845 }
3846
3847 switch (statype) {
3848 case CFG80211_STA_AP_MLME_CLIENT:
3849 /* Use this only for authorizing/unauthorizing a station */
3850 if (!(params->sta_flags_mask & BIT(NL80211_STA_FLAG_AUTHORIZED)))
3851 return -EOPNOTSUPP;
3852 break;
3853 case CFG80211_STA_AP_CLIENT:
3854 /* accept only the listed bits */
3855 if (params->sta_flags_mask &
3856 ~(BIT(NL80211_STA_FLAG_AUTHORIZED) |
3857 BIT(NL80211_STA_FLAG_AUTHENTICATED) |
3858 BIT(NL80211_STA_FLAG_ASSOCIATED) |
3859 BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) |
3860 BIT(NL80211_STA_FLAG_WME) |
3861 BIT(NL80211_STA_FLAG_MFP)))
3862 return -EINVAL;
3863
3864 /* but authenticated/associated only if driver handles it */
3865 if (!(wiphy->features & NL80211_FEATURE_FULL_AP_CLIENT_STATE) &&
3866 params->sta_flags_mask &
3867 (BIT(NL80211_STA_FLAG_AUTHENTICATED) |
3868 BIT(NL80211_STA_FLAG_ASSOCIATED)))
3869 return -EINVAL;
3870 break;
3871 case CFG80211_STA_IBSS:
3872 case CFG80211_STA_AP_STA:
3873 /* reject any changes other than AUTHORIZED */
3874 if (params->sta_flags_mask & ~BIT(NL80211_STA_FLAG_AUTHORIZED))
3875 return -EINVAL;
3876 break;
3877 case CFG80211_STA_TDLS_PEER_SETUP:
3878 /* reject any changes other than AUTHORIZED or WME */
3879 if (params->sta_flags_mask & ~(BIT(NL80211_STA_FLAG_AUTHORIZED) |
3880 BIT(NL80211_STA_FLAG_WME)))
3881 return -EINVAL;
3882 /* force (at least) rates when authorizing */
3883 if (params->sta_flags_set & BIT(NL80211_STA_FLAG_AUTHORIZED) &&
3884 !params->supported_rates)
3885 return -EINVAL;
3886 break;
3887 case CFG80211_STA_TDLS_PEER_ACTIVE:
3888 /* reject any changes */
3889 return -EINVAL;
Thomas Pederseneef941e2013-03-04 13:06:11 -08003890 case CFG80211_STA_MESH_PEER_KERNEL:
Johannes Berg77ee7c82013-02-15 00:48:33 +01003891 if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE)
3892 return -EINVAL;
3893 break;
Thomas Pederseneef941e2013-03-04 13:06:11 -08003894 case CFG80211_STA_MESH_PEER_USER:
Johannes Berg77ee7c82013-02-15 00:48:33 +01003895 if (params->plink_action != NL80211_PLINK_ACTION_NO_ACTION)
3896 return -EINVAL;
3897 break;
3898 }
3899
3900 return 0;
3901}
3902EXPORT_SYMBOL(cfg80211_check_station_change);
3903
Johannes Berg5727ef12007-12-19 02:03:34 +01003904/*
Felix Fietkauc258d2d2009-11-11 17:23:31 +01003905 * Get vlan interface making sure it is running and on the right wiphy.
Johannes Berg5727ef12007-12-19 02:03:34 +01003906 */
Johannes Berg80b99892011-11-18 16:23:01 +01003907static struct net_device *get_vlan(struct genl_info *info,
3908 struct cfg80211_registered_device *rdev)
Johannes Berg5727ef12007-12-19 02:03:34 +01003909{
Johannes Berg463d0182009-07-14 00:33:35 +02003910 struct nlattr *vlanattr = info->attrs[NL80211_ATTR_STA_VLAN];
Johannes Berg80b99892011-11-18 16:23:01 +01003911 struct net_device *v;
3912 int ret;
Johannes Berg5727ef12007-12-19 02:03:34 +01003913
Johannes Berg80b99892011-11-18 16:23:01 +01003914 if (!vlanattr)
3915 return NULL;
3916
3917 v = dev_get_by_index(genl_info_net(info), nla_get_u32(vlanattr));
3918 if (!v)
3919 return ERR_PTR(-ENODEV);
3920
3921 if (!v->ieee80211_ptr || v->ieee80211_ptr->wiphy != &rdev->wiphy) {
3922 ret = -EINVAL;
3923 goto error;
Johannes Berg5727ef12007-12-19 02:03:34 +01003924 }
Johannes Berg80b99892011-11-18 16:23:01 +01003925
Johannes Berg77ee7c82013-02-15 00:48:33 +01003926 if (v->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN &&
3927 v->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
3928 v->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) {
3929 ret = -EINVAL;
3930 goto error;
3931 }
3932
Johannes Berg80b99892011-11-18 16:23:01 +01003933 if (!netif_running(v)) {
3934 ret = -ENETDOWN;
3935 goto error;
3936 }
3937
3938 return v;
3939 error:
3940 dev_put(v);
3941 return ERR_PTR(ret);
Johannes Berg5727ef12007-12-19 02:03:34 +01003942}
3943
Johannes Berg94e860f2014-01-20 23:58:15 +01003944static const struct nla_policy
3945nl80211_sta_wme_policy[NL80211_STA_WME_MAX + 1] = {
Jouni Malinendf881292013-02-14 21:10:54 +02003946 [NL80211_STA_WME_UAPSD_QUEUES] = { .type = NLA_U8 },
3947 [NL80211_STA_WME_MAX_SP] = { .type = NLA_U8 },
3948};
3949
Johannes Bergff276692013-02-15 00:09:01 +01003950static int nl80211_parse_sta_wme(struct genl_info *info,
3951 struct station_parameters *params)
Jouni Malinendf881292013-02-14 21:10:54 +02003952{
Jouni Malinendf881292013-02-14 21:10:54 +02003953 struct nlattr *tb[NL80211_STA_WME_MAX + 1];
3954 struct nlattr *nla;
3955 int err;
3956
Jouni Malinendf881292013-02-14 21:10:54 +02003957 /* parse WME attributes if present */
3958 if (!info->attrs[NL80211_ATTR_STA_WME])
3959 return 0;
3960
3961 nla = info->attrs[NL80211_ATTR_STA_WME];
3962 err = nla_parse_nested(tb, NL80211_STA_WME_MAX, nla,
3963 nl80211_sta_wme_policy);
3964 if (err)
3965 return err;
3966
3967 if (tb[NL80211_STA_WME_UAPSD_QUEUES])
3968 params->uapsd_queues = nla_get_u8(
3969 tb[NL80211_STA_WME_UAPSD_QUEUES]);
3970 if (params->uapsd_queues & ~IEEE80211_WMM_IE_STA_QOSINFO_AC_MASK)
3971 return -EINVAL;
3972
3973 if (tb[NL80211_STA_WME_MAX_SP])
3974 params->max_sp = nla_get_u8(tb[NL80211_STA_WME_MAX_SP]);
3975
3976 if (params->max_sp & ~IEEE80211_WMM_IE_STA_QOSINFO_SP_MASK)
3977 return -EINVAL;
3978
3979 params->sta_modify_mask |= STATION_PARAM_APPLY_UAPSD;
3980
3981 return 0;
3982}
3983
Sunil Duttc01fc9a2013-10-09 20:45:21 +05303984static int nl80211_parse_sta_channel_info(struct genl_info *info,
3985 struct station_parameters *params)
3986{
3987 if (info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]) {
3988 params->supported_channels =
3989 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]);
3990 params->supported_channels_len =
3991 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]);
3992 /*
3993 * Need to include at least one (first channel, number of
3994 * channels) tuple for each subband, and must have proper
3995 * tuples for the rest of the data as well.
3996 */
3997 if (params->supported_channels_len < 2)
3998 return -EINVAL;
3999 if (params->supported_channels_len % 2)
4000 return -EINVAL;
4001 }
4002
4003 if (info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]) {
4004 params->supported_oper_classes =
4005 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]);
4006 params->supported_oper_classes_len =
4007 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]);
4008 /*
4009 * The value of the Length field of the Supported Operating
4010 * Classes element is between 2 and 253.
4011 */
4012 if (params->supported_oper_classes_len < 2 ||
4013 params->supported_oper_classes_len > 253)
4014 return -EINVAL;
4015 }
4016 return 0;
4017}
4018
Johannes Bergff276692013-02-15 00:09:01 +01004019static int nl80211_set_station_tdls(struct genl_info *info,
4020 struct station_parameters *params)
4021{
Sunil Duttc01fc9a2013-10-09 20:45:21 +05304022 int err;
Johannes Bergff276692013-02-15 00:09:01 +01004023 /* Dummy STA entry gets updated once the peer capabilities are known */
Jouni Malinen5e4b6f52013-05-16 20:11:08 +03004024 if (info->attrs[NL80211_ATTR_PEER_AID])
4025 params->aid = nla_get_u16(info->attrs[NL80211_ATTR_PEER_AID]);
Johannes Bergff276692013-02-15 00:09:01 +01004026 if (info->attrs[NL80211_ATTR_HT_CAPABILITY])
4027 params->ht_capa =
4028 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]);
4029 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY])
4030 params->vht_capa =
4031 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]);
4032
Sunil Duttc01fc9a2013-10-09 20:45:21 +05304033 err = nl80211_parse_sta_channel_info(info, params);
4034 if (err)
4035 return err;
4036
Johannes Bergff276692013-02-15 00:09:01 +01004037 return nl80211_parse_sta_wme(info, params);
4038}
4039
Johannes Berg5727ef12007-12-19 02:03:34 +01004040static int nl80211_set_station(struct sk_buff *skb, struct genl_info *info)
4041{
Johannes Berg4c476992010-10-04 21:36:35 +02004042 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg4c476992010-10-04 21:36:35 +02004043 struct net_device *dev = info->user_ptr[1];
Johannes Berg5727ef12007-12-19 02:03:34 +01004044 struct station_parameters params;
Johannes Berg77ee7c82013-02-15 00:48:33 +01004045 u8 *mac_addr;
4046 int err;
Johannes Berg5727ef12007-12-19 02:03:34 +01004047
4048 memset(&params, 0, sizeof(params));
4049
4050 params.listen_interval = -1;
4051
Johannes Berg77ee7c82013-02-15 00:48:33 +01004052 if (!rdev->ops->change_station)
4053 return -EOPNOTSUPP;
4054
Johannes Berg5727ef12007-12-19 02:03:34 +01004055 if (info->attrs[NL80211_ATTR_STA_AID])
4056 return -EINVAL;
4057
4058 if (!info->attrs[NL80211_ATTR_MAC])
4059 return -EINVAL;
4060
4061 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
4062
4063 if (info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) {
4064 params.supported_rates =
4065 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
4066 params.supported_rates_len =
4067 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
4068 }
4069
Jouni Malinen9d62a982013-02-14 21:10:13 +02004070 if (info->attrs[NL80211_ATTR_STA_CAPABILITY]) {
4071 params.capability =
4072 nla_get_u16(info->attrs[NL80211_ATTR_STA_CAPABILITY]);
4073 params.sta_modify_mask |= STATION_PARAM_APPLY_CAPABILITY;
4074 }
4075
4076 if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]) {
4077 params.ext_capab =
4078 nla_data(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
4079 params.ext_capab_len =
4080 nla_len(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
4081 }
4082
Jouni Malinendf881292013-02-14 21:10:54 +02004083 if (info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL])
Johannes Bergba23d202012-12-27 17:32:09 +01004084 return -EINVAL;
Jouni Malinen36aedc92008-08-25 11:58:58 +03004085
Johannes Bergbdd3ae32012-01-02 13:30:03 +01004086 if (parse_station_flags(info, dev->ieee80211_ptr->iftype, &params))
Johannes Berg5727ef12007-12-19 02:03:34 +01004087 return -EINVAL;
4088
Johannes Bergf8bacc22013-02-14 23:27:01 +01004089 if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) {
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004090 params.plink_action =
Johannes Bergf8bacc22013-02-14 23:27:01 +01004091 nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]);
4092 if (params.plink_action >= NUM_NL80211_PLINK_ACTIONS)
4093 return -EINVAL;
4094 }
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004095
Johannes Bergf8bacc22013-02-14 23:27:01 +01004096 if (info->attrs[NL80211_ATTR_STA_PLINK_STATE]) {
Javier Cardona9c3990a2011-05-03 16:57:11 -07004097 params.plink_state =
Johannes Bergf8bacc22013-02-14 23:27:01 +01004098 nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_STATE]);
4099 if (params.plink_state >= NUM_NL80211_PLINK_STATES)
4100 return -EINVAL;
4101 params.sta_modify_mask |= STATION_PARAM_APPLY_PLINK_STATE;
4102 }
Javier Cardona9c3990a2011-05-03 16:57:11 -07004103
Marco Porsch3b1c5a52013-01-07 16:04:52 +01004104 if (info->attrs[NL80211_ATTR_LOCAL_MESH_POWER_MODE]) {
4105 enum nl80211_mesh_power_mode pm = nla_get_u32(
4106 info->attrs[NL80211_ATTR_LOCAL_MESH_POWER_MODE]);
4107
4108 if (pm <= NL80211_MESH_POWER_UNKNOWN ||
4109 pm > NL80211_MESH_POWER_MAX)
4110 return -EINVAL;
4111
4112 params.local_pm = pm;
4113 }
4114
Johannes Berg77ee7c82013-02-15 00:48:33 +01004115 /* Include parameters for TDLS peer (will check later) */
4116 err = nl80211_set_station_tdls(info, &params);
4117 if (err)
4118 return err;
4119
4120 params.vlan = get_vlan(info, rdev);
4121 if (IS_ERR(params.vlan))
4122 return PTR_ERR(params.vlan);
4123
Johannes Berga97f4422009-06-18 17:23:43 +02004124 switch (dev->ieee80211_ptr->iftype) {
4125 case NL80211_IFTYPE_AP:
4126 case NL80211_IFTYPE_AP_VLAN:
Johannes Berg074ac8d2010-09-16 14:58:22 +02004127 case NL80211_IFTYPE_P2P_GO:
Johannes Berg074ac8d2010-09-16 14:58:22 +02004128 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Berga97f4422009-06-18 17:23:43 +02004129 case NL80211_IFTYPE_STATION:
Antonio Quartulli267335d2012-01-31 20:25:47 +01004130 case NL80211_IFTYPE_ADHOC:
Johannes Berga97f4422009-06-18 17:23:43 +02004131 case NL80211_IFTYPE_MESH_POINT:
Johannes Berga97f4422009-06-18 17:23:43 +02004132 break;
4133 default:
Johannes Berg77ee7c82013-02-15 00:48:33 +01004134 err = -EOPNOTSUPP;
4135 goto out_put_vlan;
Johannes Berg034d6552009-05-27 10:35:29 +02004136 }
4137
Johannes Berg77ee7c82013-02-15 00:48:33 +01004138 /* driver will call cfg80211_check_station_change() */
Hila Gonene35e4d22012-06-27 17:19:42 +03004139 err = rdev_change_station(rdev, dev, mac_addr, &params);
Johannes Berg5727ef12007-12-19 02:03:34 +01004140
Johannes Berg77ee7c82013-02-15 00:48:33 +01004141 out_put_vlan:
Johannes Berg5727ef12007-12-19 02:03:34 +01004142 if (params.vlan)
4143 dev_put(params.vlan);
Johannes Berg3b858752009-03-12 09:55:09 +01004144
Johannes Berg5727ef12007-12-19 02:03:34 +01004145 return err;
4146}
4147
4148static int nl80211_new_station(struct sk_buff *skb, struct genl_info *info)
4149{
Johannes Berg4c476992010-10-04 21:36:35 +02004150 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg5727ef12007-12-19 02:03:34 +01004151 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02004152 struct net_device *dev = info->user_ptr[1];
Johannes Berg5727ef12007-12-19 02:03:34 +01004153 struct station_parameters params;
4154 u8 *mac_addr = NULL;
4155
4156 memset(&params, 0, sizeof(params));
4157
Johannes Berg984c3112013-02-14 23:43:25 +01004158 if (!rdev->ops->add_station)
4159 return -EOPNOTSUPP;
4160
Johannes Berg5727ef12007-12-19 02:03:34 +01004161 if (!info->attrs[NL80211_ATTR_MAC])
4162 return -EINVAL;
4163
Johannes Berg5727ef12007-12-19 02:03:34 +01004164 if (!info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL])
4165 return -EINVAL;
4166
4167 if (!info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES])
4168 return -EINVAL;
4169
Jouni Malinen5e4b6f52013-05-16 20:11:08 +03004170 if (!info->attrs[NL80211_ATTR_STA_AID] &&
4171 !info->attrs[NL80211_ATTR_PEER_AID])
Thadeu Lima de Souza Cascardo0e956c12010-02-12 12:34:50 -02004172 return -EINVAL;
4173
Johannes Berg5727ef12007-12-19 02:03:34 +01004174 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
4175 params.supported_rates =
4176 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
4177 params.supported_rates_len =
4178 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
4179 params.listen_interval =
4180 nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]);
Johannes Berg51b50fb2009-05-24 16:42:30 +02004181
Jouni Malinen3d124ea2013-05-27 18:24:02 +03004182 if (info->attrs[NL80211_ATTR_PEER_AID])
Jouni Malinen5e4b6f52013-05-16 20:11:08 +03004183 params.aid = nla_get_u16(info->attrs[NL80211_ATTR_PEER_AID]);
Jouni Malinen3d124ea2013-05-27 18:24:02 +03004184 else
4185 params.aid = nla_get_u16(info->attrs[NL80211_ATTR_STA_AID]);
Thadeu Lima de Souza Cascardo0e956c12010-02-12 12:34:50 -02004186 if (!params.aid || params.aid > IEEE80211_MAX_AID)
4187 return -EINVAL;
Johannes Berg51b50fb2009-05-24 16:42:30 +02004188
Jouni Malinen9d62a982013-02-14 21:10:13 +02004189 if (info->attrs[NL80211_ATTR_STA_CAPABILITY]) {
4190 params.capability =
4191 nla_get_u16(info->attrs[NL80211_ATTR_STA_CAPABILITY]);
4192 params.sta_modify_mask |= STATION_PARAM_APPLY_CAPABILITY;
4193 }
4194
4195 if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]) {
4196 params.ext_capab =
4197 nla_data(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
4198 params.ext_capab_len =
4199 nla_len(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
4200 }
4201
Jouni Malinen36aedc92008-08-25 11:58:58 +03004202 if (info->attrs[NL80211_ATTR_HT_CAPABILITY])
4203 params.ht_capa =
4204 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]);
Johannes Berg5727ef12007-12-19 02:03:34 +01004205
Mahesh Palivelaf461be3e2012-10-11 08:04:52 +00004206 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY])
4207 params.vht_capa =
4208 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]);
4209
Marek Kwaczynski60f4a7b2013-12-03 10:04:59 +01004210 if (info->attrs[NL80211_ATTR_OPMODE_NOTIF]) {
4211 params.opmode_notif_used = true;
4212 params.opmode_notif =
4213 nla_get_u8(info->attrs[NL80211_ATTR_OPMODE_NOTIF]);
4214 }
4215
Johannes Bergf8bacc22013-02-14 23:27:01 +01004216 if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) {
Javier Cardona96b78df2011-04-07 15:08:33 -07004217 params.plink_action =
Johannes Bergf8bacc22013-02-14 23:27:01 +01004218 nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]);
4219 if (params.plink_action >= NUM_NL80211_PLINK_ACTIONS)
4220 return -EINVAL;
4221 }
Javier Cardona96b78df2011-04-07 15:08:33 -07004222
Sunil Duttc01fc9a2013-10-09 20:45:21 +05304223 err = nl80211_parse_sta_channel_info(info, &params);
4224 if (err)
4225 return err;
4226
Johannes Bergff276692013-02-15 00:09:01 +01004227 err = nl80211_parse_sta_wme(info, &params);
4228 if (err)
4229 return err;
Johannes Bergbdd90d52011-12-14 12:20:27 +01004230
Johannes Bergbdd3ae32012-01-02 13:30:03 +01004231 if (parse_station_flags(info, dev->ieee80211_ptr->iftype, &params))
Johannes Berg5727ef12007-12-19 02:03:34 +01004232 return -EINVAL;
4233
Johannes Berg77ee7c82013-02-15 00:48:33 +01004234 /* When you run into this, adjust the code below for the new flag */
4235 BUILD_BUG_ON(NL80211_STA_FLAG_MAX != 7);
4236
Johannes Bergbdd90d52011-12-14 12:20:27 +01004237 switch (dev->ieee80211_ptr->iftype) {
4238 case NL80211_IFTYPE_AP:
4239 case NL80211_IFTYPE_AP_VLAN:
4240 case NL80211_IFTYPE_P2P_GO:
Johannes Berg984c3112013-02-14 23:43:25 +01004241 /* ignore WME attributes if iface/sta is not capable */
4242 if (!(rdev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) ||
4243 !(params.sta_flags_set & BIT(NL80211_STA_FLAG_WME)))
4244 params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD;
Eliad Pellerc75786c2011-08-23 14:37:46 +03004245
Johannes Bergbdd90d52011-12-14 12:20:27 +01004246 /* TDLS peers cannot be added */
Jouni Malinen3d124ea2013-05-27 18:24:02 +03004247 if ((params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) ||
4248 info->attrs[NL80211_ATTR_PEER_AID])
Johannes Berg4319e192011-09-07 11:50:48 +02004249 return -EINVAL;
Johannes Bergbdd90d52011-12-14 12:20:27 +01004250 /* but don't bother the driver with it */
4251 params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER);
Eliad Pellerc75786c2011-08-23 14:37:46 +03004252
Johannes Bergd582cff2012-10-26 17:53:44 +02004253 /* allow authenticated/associated only if driver handles it */
4254 if (!(rdev->wiphy.features &
4255 NL80211_FEATURE_FULL_AP_CLIENT_STATE) &&
4256 params.sta_flags_mask &
4257 (BIT(NL80211_STA_FLAG_AUTHENTICATED) |
4258 BIT(NL80211_STA_FLAG_ASSOCIATED)))
4259 return -EINVAL;
4260
Johannes Bergbdd90d52011-12-14 12:20:27 +01004261 /* must be last in here for error handling */
4262 params.vlan = get_vlan(info, rdev);
4263 if (IS_ERR(params.vlan))
4264 return PTR_ERR(params.vlan);
4265 break;
4266 case NL80211_IFTYPE_MESH_POINT:
Johannes Berg984c3112013-02-14 23:43:25 +01004267 /* ignore uAPSD data */
4268 params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD;
4269
Johannes Bergd582cff2012-10-26 17:53:44 +02004270 /* associated is disallowed */
4271 if (params.sta_flags_mask & BIT(NL80211_STA_FLAG_ASSOCIATED))
4272 return -EINVAL;
Johannes Bergbdd90d52011-12-14 12:20:27 +01004273 /* TDLS peers cannot be added */
Jouni Malinen3d124ea2013-05-27 18:24:02 +03004274 if ((params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) ||
4275 info->attrs[NL80211_ATTR_PEER_AID])
Johannes Berg4319e192011-09-07 11:50:48 +02004276 return -EINVAL;
Johannes Bergbdd90d52011-12-14 12:20:27 +01004277 break;
4278 case NL80211_IFTYPE_STATION:
Johannes Berg93d08f02013-03-04 09:29:46 +01004279 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Berg984c3112013-02-14 23:43:25 +01004280 /* ignore uAPSD data */
4281 params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD;
4282
Johannes Berg77ee7c82013-02-15 00:48:33 +01004283 /* these are disallowed */
4284 if (params.sta_flags_mask &
4285 (BIT(NL80211_STA_FLAG_ASSOCIATED) |
4286 BIT(NL80211_STA_FLAG_AUTHENTICATED)))
Johannes Bergd582cff2012-10-26 17:53:44 +02004287 return -EINVAL;
Johannes Bergbdd90d52011-12-14 12:20:27 +01004288 /* Only TDLS peers can be added */
4289 if (!(params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)))
4290 return -EINVAL;
4291 /* Can only add if TDLS ... */
4292 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS))
4293 return -EOPNOTSUPP;
4294 /* ... with external setup is supported */
4295 if (!(rdev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP))
4296 return -EOPNOTSUPP;
Johannes Berg77ee7c82013-02-15 00:48:33 +01004297 /*
4298 * Older wpa_supplicant versions always mark the TDLS peer
4299 * as authorized, but it shouldn't yet be.
4300 */
4301 params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_AUTHORIZED);
Johannes Bergbdd90d52011-12-14 12:20:27 +01004302 break;
4303 default:
4304 return -EOPNOTSUPP;
Eliad Pellerc75786c2011-08-23 14:37:46 +03004305 }
4306
Johannes Bergbdd90d52011-12-14 12:20:27 +01004307 /* be aware of params.vlan when changing code here */
Johannes Berg5727ef12007-12-19 02:03:34 +01004308
Hila Gonene35e4d22012-06-27 17:19:42 +03004309 err = rdev_add_station(rdev, dev, mac_addr, &params);
Johannes Berg5727ef12007-12-19 02:03:34 +01004310
Johannes Berg5727ef12007-12-19 02:03:34 +01004311 if (params.vlan)
4312 dev_put(params.vlan);
Johannes Berg5727ef12007-12-19 02:03:34 +01004313 return err;
4314}
4315
4316static int nl80211_del_station(struct sk_buff *skb, struct genl_info *info)
4317{
Johannes Berg4c476992010-10-04 21:36:35 +02004318 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4319 struct net_device *dev = info->user_ptr[1];
Johannes Berg5727ef12007-12-19 02:03:34 +01004320 u8 *mac_addr = NULL;
4321
4322 if (info->attrs[NL80211_ATTR_MAC])
4323 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
4324
Johannes Berge80cf852009-05-11 14:43:13 +02004325 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
Marco Porschd5d9de02010-03-30 10:00:16 +02004326 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN &&
Johannes Berg074ac8d2010-09-16 14:58:22 +02004327 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT &&
Johannes Berg4c476992010-10-04 21:36:35 +02004328 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
4329 return -EINVAL;
Johannes Berge80cf852009-05-11 14:43:13 +02004330
Johannes Berg4c476992010-10-04 21:36:35 +02004331 if (!rdev->ops->del_station)
4332 return -EOPNOTSUPP;
Johannes Berg5727ef12007-12-19 02:03:34 +01004333
Hila Gonene35e4d22012-06-27 17:19:42 +03004334 return rdev_del_station(rdev, dev, mac_addr);
Johannes Berg5727ef12007-12-19 02:03:34 +01004335}
4336
Eric W. Biederman15e47302012-09-07 20:12:54 +00004337static int nl80211_send_mpath(struct sk_buff *msg, u32 portid, u32 seq,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004338 int flags, struct net_device *dev,
4339 u8 *dst, u8 *next_hop,
4340 struct mpath_info *pinfo)
4341{
4342 void *hdr;
4343 struct nlattr *pinfoattr;
4344
Eric W. Biederman15e47302012-09-07 20:12:54 +00004345 hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_STATION);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004346 if (!hdr)
4347 return -1;
4348
David S. Miller9360ffd2012-03-29 04:41:26 -04004349 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
4350 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, dst) ||
4351 nla_put(msg, NL80211_ATTR_MPATH_NEXT_HOP, ETH_ALEN, next_hop) ||
4352 nla_put_u32(msg, NL80211_ATTR_GENERATION, pinfo->generation))
4353 goto nla_put_failure;
Johannes Bergf5ea9122009-08-07 16:17:38 +02004354
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004355 pinfoattr = nla_nest_start(msg, NL80211_ATTR_MPATH_INFO);
4356 if (!pinfoattr)
4357 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04004358 if ((pinfo->filled & MPATH_INFO_FRAME_QLEN) &&
4359 nla_put_u32(msg, NL80211_MPATH_INFO_FRAME_QLEN,
4360 pinfo->frame_qlen))
4361 goto nla_put_failure;
4362 if (((pinfo->filled & MPATH_INFO_SN) &&
4363 nla_put_u32(msg, NL80211_MPATH_INFO_SN, pinfo->sn)) ||
4364 ((pinfo->filled & MPATH_INFO_METRIC) &&
4365 nla_put_u32(msg, NL80211_MPATH_INFO_METRIC,
4366 pinfo->metric)) ||
4367 ((pinfo->filled & MPATH_INFO_EXPTIME) &&
4368 nla_put_u32(msg, NL80211_MPATH_INFO_EXPTIME,
4369 pinfo->exptime)) ||
4370 ((pinfo->filled & MPATH_INFO_FLAGS) &&
4371 nla_put_u8(msg, NL80211_MPATH_INFO_FLAGS,
4372 pinfo->flags)) ||
4373 ((pinfo->filled & MPATH_INFO_DISCOVERY_TIMEOUT) &&
4374 nla_put_u32(msg, NL80211_MPATH_INFO_DISCOVERY_TIMEOUT,
4375 pinfo->discovery_timeout)) ||
4376 ((pinfo->filled & MPATH_INFO_DISCOVERY_RETRIES) &&
4377 nla_put_u8(msg, NL80211_MPATH_INFO_DISCOVERY_RETRIES,
4378 pinfo->discovery_retries)))
4379 goto nla_put_failure;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004380
4381 nla_nest_end(msg, pinfoattr);
4382
4383 return genlmsg_end(msg, hdr);
4384
4385 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07004386 genlmsg_cancel(msg, hdr);
4387 return -EMSGSIZE;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004388}
4389
4390static int nl80211_dump_mpath(struct sk_buff *skb,
Johannes Bergbba95fe2008-07-29 13:22:51 +02004391 struct netlink_callback *cb)
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004392{
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004393 struct mpath_info pinfo;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08004394 struct cfg80211_registered_device *rdev;
Johannes Berg97990a02013-04-19 01:02:55 +02004395 struct wireless_dev *wdev;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004396 u8 dst[ETH_ALEN];
4397 u8 next_hop[ETH_ALEN];
Johannes Berg97990a02013-04-19 01:02:55 +02004398 int path_idx = cb->args[2];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004399 int err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004400
Zhao, Gang1b8ec872014-04-21 12:53:02 +08004401 err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev);
Johannes Berg67748892010-10-04 21:14:06 +02004402 if (err)
4403 return err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004404
Zhao, Gang1b8ec872014-04-21 12:53:02 +08004405 if (!rdev->ops->dump_mpath) {
Jouni Malineneec60b02009-03-20 21:21:19 +02004406 err = -EOPNOTSUPP;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004407 goto out_err;
4408 }
4409
Johannes Berg97990a02013-04-19 01:02:55 +02004410 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) {
Jouni Malineneec60b02009-03-20 21:21:19 +02004411 err = -EOPNOTSUPP;
Roel Kluin0448b5f2009-08-22 21:15:49 +02004412 goto out_err;
Jouni Malineneec60b02009-03-20 21:21:19 +02004413 }
4414
Johannes Bergbba95fe2008-07-29 13:22:51 +02004415 while (1) {
Zhao, Gang1b8ec872014-04-21 12:53:02 +08004416 err = rdev_dump_mpath(rdev, wdev->netdev, path_idx, dst,
Johannes Berg97990a02013-04-19 01:02:55 +02004417 next_hop, &pinfo);
Johannes Bergbba95fe2008-07-29 13:22:51 +02004418 if (err == -ENOENT)
4419 break;
4420 if (err)
Johannes Berg3b858752009-03-12 09:55:09 +01004421 goto out_err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004422
Eric W. Biederman15e47302012-09-07 20:12:54 +00004423 if (nl80211_send_mpath(skb, NETLINK_CB(cb->skb).portid,
Johannes Bergbba95fe2008-07-29 13:22:51 +02004424 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Johannes Berg97990a02013-04-19 01:02:55 +02004425 wdev->netdev, dst, next_hop,
Johannes Bergbba95fe2008-07-29 13:22:51 +02004426 &pinfo) < 0)
4427 goto out;
4428
4429 path_idx++;
4430 }
4431
4432
4433 out:
Johannes Berg97990a02013-04-19 01:02:55 +02004434 cb->args[2] = path_idx;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004435 err = skb->len;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004436 out_err:
Zhao, Gang1b8ec872014-04-21 12:53:02 +08004437 nl80211_finish_wdev_dump(rdev);
Johannes Bergbba95fe2008-07-29 13:22:51 +02004438 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004439}
4440
4441static int nl80211_get_mpath(struct sk_buff *skb, struct genl_info *info)
4442{
Johannes Berg4c476992010-10-04 21:36:35 +02004443 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004444 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02004445 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004446 struct mpath_info pinfo;
4447 struct sk_buff *msg;
4448 u8 *dst = NULL;
4449 u8 next_hop[ETH_ALEN];
4450
4451 memset(&pinfo, 0, sizeof(pinfo));
4452
4453 if (!info->attrs[NL80211_ATTR_MAC])
4454 return -EINVAL;
4455
4456 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
4457
Johannes Berg4c476992010-10-04 21:36:35 +02004458 if (!rdev->ops->get_mpath)
4459 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01004460
Johannes Berg4c476992010-10-04 21:36:35 +02004461 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
4462 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02004463
Hila Gonene35e4d22012-06-27 17:19:42 +03004464 err = rdev_get_mpath(rdev, dev, dst, next_hop, &pinfo);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004465 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02004466 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004467
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07004468 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004469 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02004470 return -ENOMEM;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004471
Eric W. Biederman15e47302012-09-07 20:12:54 +00004472 if (nl80211_send_mpath(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berg4c476992010-10-04 21:36:35 +02004473 dev, dst, next_hop, &pinfo) < 0) {
4474 nlmsg_free(msg);
4475 return -ENOBUFS;
4476 }
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004477
Johannes Berg4c476992010-10-04 21:36:35 +02004478 return genlmsg_reply(msg, info);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004479}
4480
4481static int nl80211_set_mpath(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];
4484 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004485 u8 *dst = NULL;
4486 u8 *next_hop = NULL;
4487
4488 if (!info->attrs[NL80211_ATTR_MAC])
4489 return -EINVAL;
4490
4491 if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP])
4492 return -EINVAL;
4493
4494 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
4495 next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]);
4496
Johannes Berg4c476992010-10-04 21:36:35 +02004497 if (!rdev->ops->change_mpath)
4498 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01004499
Johannes Berg4c476992010-10-04 21:36:35 +02004500 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
4501 return -EOPNOTSUPP;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004502
Hila Gonene35e4d22012-06-27 17:19:42 +03004503 return rdev_change_mpath(rdev, dev, dst, next_hop);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004504}
Johannes Berg4c476992010-10-04 21:36:35 +02004505
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004506static int nl80211_new_mpath(struct sk_buff *skb, struct genl_info *info)
4507{
Johannes Berg4c476992010-10-04 21:36:35 +02004508 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4509 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004510 u8 *dst = NULL;
4511 u8 *next_hop = NULL;
4512
4513 if (!info->attrs[NL80211_ATTR_MAC])
4514 return -EINVAL;
4515
4516 if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP])
4517 return -EINVAL;
4518
4519 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
4520 next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]);
4521
Johannes Berg4c476992010-10-04 21:36:35 +02004522 if (!rdev->ops->add_mpath)
4523 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01004524
Johannes Berg4c476992010-10-04 21:36:35 +02004525 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
4526 return -EOPNOTSUPP;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004527
Hila Gonene35e4d22012-06-27 17:19:42 +03004528 return rdev_add_mpath(rdev, dev, dst, next_hop);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004529}
4530
4531static int nl80211_del_mpath(struct sk_buff *skb, struct genl_info *info)
4532{
Johannes Berg4c476992010-10-04 21:36:35 +02004533 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4534 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004535 u8 *dst = NULL;
4536
4537 if (info->attrs[NL80211_ATTR_MAC])
4538 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
4539
Johannes Berg4c476992010-10-04 21:36:35 +02004540 if (!rdev->ops->del_mpath)
4541 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01004542
Hila Gonene35e4d22012-06-27 17:19:42 +03004543 return rdev_del_mpath(rdev, dev, dst);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004544}
4545
Jouni Malinen9f1ba902008-08-07 20:07:01 +03004546static int nl80211_set_bss(struct sk_buff *skb, struct genl_info *info)
4547{
Johannes Berg4c476992010-10-04 21:36:35 +02004548 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4549 struct net_device *dev = info->user_ptr[1];
Simon Wunderlichc56589e2013-11-21 18:19:49 +01004550 struct wireless_dev *wdev = dev->ieee80211_ptr;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03004551 struct bss_parameters params;
Simon Wunderlichc56589e2013-11-21 18:19:49 +01004552 int err;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03004553
4554 memset(&params, 0, sizeof(params));
4555 /* default to not changing parameters */
4556 params.use_cts_prot = -1;
4557 params.use_short_preamble = -1;
4558 params.use_short_slot_time = -1;
Felix Fietkaufd8aaaf2010-04-27 01:23:35 +02004559 params.ap_isolate = -1;
Helmut Schaa50b12f52010-11-19 12:40:25 +01004560 params.ht_opmode = -1;
Johannes Berg53cabad2012-11-14 15:17:28 +01004561 params.p2p_ctwindow = -1;
4562 params.p2p_opp_ps = -1;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03004563
4564 if (info->attrs[NL80211_ATTR_BSS_CTS_PROT])
4565 params.use_cts_prot =
4566 nla_get_u8(info->attrs[NL80211_ATTR_BSS_CTS_PROT]);
4567 if (info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE])
4568 params.use_short_preamble =
4569 nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]);
4570 if (info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME])
4571 params.use_short_slot_time =
4572 nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]);
Jouni Malinen90c97a02008-10-30 16:59:22 +02004573 if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) {
4574 params.basic_rates =
4575 nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
4576 params.basic_rates_len =
4577 nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
4578 }
Felix Fietkaufd8aaaf2010-04-27 01:23:35 +02004579 if (info->attrs[NL80211_ATTR_AP_ISOLATE])
4580 params.ap_isolate = !!nla_get_u8(info->attrs[NL80211_ATTR_AP_ISOLATE]);
Helmut Schaa50b12f52010-11-19 12:40:25 +01004581 if (info->attrs[NL80211_ATTR_BSS_HT_OPMODE])
4582 params.ht_opmode =
4583 nla_get_u16(info->attrs[NL80211_ATTR_BSS_HT_OPMODE]);
Jouni Malinen9f1ba902008-08-07 20:07:01 +03004584
Johannes Berg53cabad2012-11-14 15:17:28 +01004585 if (info->attrs[NL80211_ATTR_P2P_CTWINDOW]) {
4586 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
4587 return -EINVAL;
4588 params.p2p_ctwindow =
4589 nla_get_s8(info->attrs[NL80211_ATTR_P2P_CTWINDOW]);
4590 if (params.p2p_ctwindow < 0)
4591 return -EINVAL;
4592 if (params.p2p_ctwindow != 0 &&
4593 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_CTWIN))
4594 return -EINVAL;
4595 }
4596
4597 if (info->attrs[NL80211_ATTR_P2P_OPPPS]) {
4598 u8 tmp;
4599
4600 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
4601 return -EINVAL;
4602 tmp = nla_get_u8(info->attrs[NL80211_ATTR_P2P_OPPPS]);
4603 if (tmp > 1)
4604 return -EINVAL;
4605 params.p2p_opp_ps = tmp;
4606 if (params.p2p_opp_ps &&
4607 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_OPPPS))
4608 return -EINVAL;
4609 }
4610
Johannes Berg4c476992010-10-04 21:36:35 +02004611 if (!rdev->ops->change_bss)
4612 return -EOPNOTSUPP;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03004613
Johannes Berg074ac8d2010-09-16 14:58:22 +02004614 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
Johannes Berg4c476992010-10-04 21:36:35 +02004615 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
4616 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02004617
Simon Wunderlichc56589e2013-11-21 18:19:49 +01004618 wdev_lock(wdev);
4619 err = rdev_change_bss(rdev, dev, &params);
4620 wdev_unlock(wdev);
4621
4622 return err;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03004623}
4624
Alexey Dobriyanb54452b2010-02-18 08:14:31 +00004625static const struct nla_policy reg_rule_policy[NL80211_REG_RULE_ATTR_MAX + 1] = {
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004626 [NL80211_ATTR_REG_RULE_FLAGS] = { .type = NLA_U32 },
4627 [NL80211_ATTR_FREQ_RANGE_START] = { .type = NLA_U32 },
4628 [NL80211_ATTR_FREQ_RANGE_END] = { .type = NLA_U32 },
4629 [NL80211_ATTR_FREQ_RANGE_MAX_BW] = { .type = NLA_U32 },
4630 [NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN] = { .type = NLA_U32 },
4631 [NL80211_ATTR_POWER_RULE_MAX_EIRP] = { .type = NLA_U32 },
Janusz Dziedzic089027e2014-02-21 19:46:12 +01004632 [NL80211_ATTR_DFS_CAC_TIME] = { .type = NLA_U32 },
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004633};
4634
4635static int parse_reg_rule(struct nlattr *tb[],
4636 struct ieee80211_reg_rule *reg_rule)
4637{
4638 struct ieee80211_freq_range *freq_range = &reg_rule->freq_range;
4639 struct ieee80211_power_rule *power_rule = &reg_rule->power_rule;
4640
4641 if (!tb[NL80211_ATTR_REG_RULE_FLAGS])
4642 return -EINVAL;
4643 if (!tb[NL80211_ATTR_FREQ_RANGE_START])
4644 return -EINVAL;
4645 if (!tb[NL80211_ATTR_FREQ_RANGE_END])
4646 return -EINVAL;
Janusz Dziedzicb0dfd2e2014-02-20 13:52:16 +01004647 if (!tb[NL80211_ATTR_FREQ_RANGE_MAX_BW])
4648 return -EINVAL;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004649 if (!tb[NL80211_ATTR_POWER_RULE_MAX_EIRP])
4650 return -EINVAL;
4651
4652 reg_rule->flags = nla_get_u32(tb[NL80211_ATTR_REG_RULE_FLAGS]);
4653
4654 freq_range->start_freq_khz =
4655 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_START]);
4656 freq_range->end_freq_khz =
4657 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_END]);
Janusz Dziedzicb0dfd2e2014-02-20 13:52:16 +01004658 freq_range->max_bandwidth_khz =
4659 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]);
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004660
4661 power_rule->max_eirp =
4662 nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]);
4663
4664 if (tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN])
4665 power_rule->max_antenna_gain =
4666 nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]);
4667
Janusz Dziedzic089027e2014-02-21 19:46:12 +01004668 if (tb[NL80211_ATTR_DFS_CAC_TIME])
4669 reg_rule->dfs_cac_ms =
4670 nla_get_u32(tb[NL80211_ATTR_DFS_CAC_TIME]);
4671
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004672 return 0;
4673}
4674
4675static int nl80211_req_set_reg(struct sk_buff *skb, struct genl_info *info)
4676{
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004677 char *data = NULL;
Luis R. Rodriguez57b5ce02012-07-12 11:49:18 -07004678 enum nl80211_user_reg_hint_type user_reg_hint_type;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004679
Luis R. Rodriguez80778f12009-02-21 00:04:22 -05004680 /*
4681 * You should only get this when cfg80211 hasn't yet initialized
4682 * completely when built-in to the kernel right between the time
4683 * window between nl80211_init() and regulatory_init(), if that is
4684 * even possible.
4685 */
Johannes Berg458f4f92012-12-06 15:47:38 +01004686 if (unlikely(!rcu_access_pointer(cfg80211_regdomain)))
Luis R. Rodriguezfe33eb32009-02-21 00:04:30 -05004687 return -EINPROGRESS;
Luis R. Rodriguez80778f12009-02-21 00:04:22 -05004688
Luis R. Rodriguez57b5ce02012-07-12 11:49:18 -07004689 if (info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE])
4690 user_reg_hint_type =
4691 nla_get_u32(info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE]);
4692 else
4693 user_reg_hint_type = NL80211_USER_REG_HINT_USER;
4694
4695 switch (user_reg_hint_type) {
4696 case NL80211_USER_REG_HINT_USER:
4697 case NL80211_USER_REG_HINT_CELL_BASE:
Ilan Peer52616f22014-02-25 16:26:00 +02004698 if (!info->attrs[NL80211_ATTR_REG_ALPHA2])
4699 return -EINVAL;
4700
4701 data = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]);
4702 return regulatory_hint_user(data, user_reg_hint_type);
4703 case NL80211_USER_REG_HINT_INDOOR:
4704 return regulatory_hint_indoor_user();
Luis R. Rodriguez57b5ce02012-07-12 11:49:18 -07004705 default:
4706 return -EINVAL;
4707 }
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004708}
4709
Javier Cardona24bdd9f2010-12-16 17:37:48 -08004710static int nl80211_get_mesh_config(struct sk_buff *skb,
Johannes Berg29cbe682010-12-03 09:20:44 +01004711 struct genl_info *info)
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004712{
Johannes Berg4c476992010-10-04 21:36:35 +02004713 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg4c476992010-10-04 21:36:35 +02004714 struct net_device *dev = info->user_ptr[1];
Johannes Berg29cbe682010-12-03 09:20:44 +01004715 struct wireless_dev *wdev = dev->ieee80211_ptr;
4716 struct mesh_config cur_params;
4717 int err = 0;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004718 void *hdr;
4719 struct nlattr *pinfoattr;
4720 struct sk_buff *msg;
4721
Johannes Berg29cbe682010-12-03 09:20:44 +01004722 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT)
4723 return -EOPNOTSUPP;
4724
Javier Cardona24bdd9f2010-12-16 17:37:48 -08004725 if (!rdev->ops->get_mesh_config)
Johannes Berg4c476992010-10-04 21:36:35 +02004726 return -EOPNOTSUPP;
Jouni Malinenf3f92582009-03-20 17:57:36 +02004727
Johannes Berg29cbe682010-12-03 09:20:44 +01004728 wdev_lock(wdev);
4729 /* If not connected, get default parameters */
4730 if (!wdev->mesh_id_len)
4731 memcpy(&cur_params, &default_mesh_config, sizeof(cur_params));
4732 else
Hila Gonene35e4d22012-06-27 17:19:42 +03004733 err = rdev_get_mesh_config(rdev, dev, &cur_params);
Johannes Berg29cbe682010-12-03 09:20:44 +01004734 wdev_unlock(wdev);
4735
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004736 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02004737 return err;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004738
4739 /* Draw up a netlink message to send back */
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07004740 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02004741 if (!msg)
4742 return -ENOMEM;
Eric W. Biederman15e47302012-09-07 20:12:54 +00004743 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Javier Cardona24bdd9f2010-12-16 17:37:48 -08004744 NL80211_CMD_GET_MESH_CONFIG);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004745 if (!hdr)
Julia Lawallefe1cf02011-01-28 15:17:11 +01004746 goto out;
Javier Cardona24bdd9f2010-12-16 17:37:48 -08004747 pinfoattr = nla_nest_start(msg, NL80211_ATTR_MESH_CONFIG);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004748 if (!pinfoattr)
4749 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04004750 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
4751 nla_put_u16(msg, NL80211_MESHCONF_RETRY_TIMEOUT,
4752 cur_params.dot11MeshRetryTimeout) ||
4753 nla_put_u16(msg, NL80211_MESHCONF_CONFIRM_TIMEOUT,
4754 cur_params.dot11MeshConfirmTimeout) ||
4755 nla_put_u16(msg, NL80211_MESHCONF_HOLDING_TIMEOUT,
4756 cur_params.dot11MeshHoldingTimeout) ||
4757 nla_put_u16(msg, NL80211_MESHCONF_MAX_PEER_LINKS,
4758 cur_params.dot11MeshMaxPeerLinks) ||
4759 nla_put_u8(msg, NL80211_MESHCONF_MAX_RETRIES,
4760 cur_params.dot11MeshMaxRetries) ||
4761 nla_put_u8(msg, NL80211_MESHCONF_TTL,
4762 cur_params.dot11MeshTTL) ||
4763 nla_put_u8(msg, NL80211_MESHCONF_ELEMENT_TTL,
4764 cur_params.element_ttl) ||
4765 nla_put_u8(msg, NL80211_MESHCONF_AUTO_OPEN_PLINKS,
4766 cur_params.auto_open_plinks) ||
John W. Linville7eab0f62012-04-12 14:25:14 -04004767 nla_put_u32(msg, NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR,
4768 cur_params.dot11MeshNbrOffsetMaxNeighbor) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04004769 nla_put_u8(msg, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES,
4770 cur_params.dot11MeshHWMPmaxPREQretries) ||
4771 nla_put_u32(msg, NL80211_MESHCONF_PATH_REFRESH_TIME,
4772 cur_params.path_refresh_time) ||
4773 nla_put_u16(msg, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT,
4774 cur_params.min_discovery_timeout) ||
4775 nla_put_u32(msg, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT,
4776 cur_params.dot11MeshHWMPactivePathTimeout) ||
4777 nla_put_u16(msg, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL,
4778 cur_params.dot11MeshHWMPpreqMinInterval) ||
4779 nla_put_u16(msg, NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL,
4780 cur_params.dot11MeshHWMPperrMinInterval) ||
4781 nla_put_u16(msg, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME,
4782 cur_params.dot11MeshHWMPnetDiameterTraversalTime) ||
4783 nla_put_u8(msg, NL80211_MESHCONF_HWMP_ROOTMODE,
4784 cur_params.dot11MeshHWMPRootMode) ||
4785 nla_put_u16(msg, NL80211_MESHCONF_HWMP_RANN_INTERVAL,
4786 cur_params.dot11MeshHWMPRannInterval) ||
4787 nla_put_u8(msg, NL80211_MESHCONF_GATE_ANNOUNCEMENTS,
4788 cur_params.dot11MeshGateAnnouncementProtocol) ||
4789 nla_put_u8(msg, NL80211_MESHCONF_FORWARDING,
4790 cur_params.dot11MeshForwarding) ||
4791 nla_put_u32(msg, NL80211_MESHCONF_RSSI_THRESHOLD,
Ashok Nagarajan70c33ea2012-04-30 14:20:32 -07004792 cur_params.rssi_threshold) ||
4793 nla_put_u32(msg, NL80211_MESHCONF_HT_OPMODE,
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08004794 cur_params.ht_opmode) ||
4795 nla_put_u32(msg, NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT,
4796 cur_params.dot11MeshHWMPactivePathToRootTimeout) ||
4797 nla_put_u16(msg, NL80211_MESHCONF_HWMP_ROOT_INTERVAL,
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +08004798 cur_params.dot11MeshHWMProotInterval) ||
4799 nla_put_u16(msg, NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL,
Marco Porsch3b1c5a52013-01-07 16:04:52 +01004800 cur_params.dot11MeshHWMPconfirmationInterval) ||
4801 nla_put_u32(msg, NL80211_MESHCONF_POWER_MODE,
4802 cur_params.power_mode) ||
4803 nla_put_u16(msg, NL80211_MESHCONF_AWAKE_WINDOW,
Colleen Twitty8e7c0532013-06-03 09:53:39 -07004804 cur_params.dot11MeshAwakeWindowDuration) ||
4805 nla_put_u32(msg, NL80211_MESHCONF_PLINK_TIMEOUT,
4806 cur_params.plink_timeout))
David S. Miller9360ffd2012-03-29 04:41:26 -04004807 goto nla_put_failure;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004808 nla_nest_end(msg, pinfoattr);
4809 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02004810 return genlmsg_reply(msg, info);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004811
Johannes Berg3b858752009-03-12 09:55:09 +01004812 nla_put_failure:
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004813 genlmsg_cancel(msg, hdr);
Julia Lawallefe1cf02011-01-28 15:17:11 +01004814 out:
Yuri Ershovd080e272010-06-29 15:08:07 +04004815 nlmsg_free(msg);
Johannes Berg4c476992010-10-04 21:36:35 +02004816 return -ENOBUFS;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004817}
4818
Alexey Dobriyanb54452b2010-02-18 08:14:31 +00004819static const struct nla_policy nl80211_meshconf_params_policy[NL80211_MESHCONF_ATTR_MAX+1] = {
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004820 [NL80211_MESHCONF_RETRY_TIMEOUT] = { .type = NLA_U16 },
4821 [NL80211_MESHCONF_CONFIRM_TIMEOUT] = { .type = NLA_U16 },
4822 [NL80211_MESHCONF_HOLDING_TIMEOUT] = { .type = NLA_U16 },
4823 [NL80211_MESHCONF_MAX_PEER_LINKS] = { .type = NLA_U16 },
4824 [NL80211_MESHCONF_MAX_RETRIES] = { .type = NLA_U8 },
4825 [NL80211_MESHCONF_TTL] = { .type = NLA_U8 },
Javier Cardona45904f22010-12-03 09:20:40 +01004826 [NL80211_MESHCONF_ELEMENT_TTL] = { .type = NLA_U8 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004827 [NL80211_MESHCONF_AUTO_OPEN_PLINKS] = { .type = NLA_U8 },
Javier Cardonad299a1f2012-03-31 11:31:33 -07004828 [NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR] = { .type = NLA_U32 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004829 [NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES] = { .type = NLA_U8 },
4830 [NL80211_MESHCONF_PATH_REFRESH_TIME] = { .type = NLA_U32 },
4831 [NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT] = { .type = NLA_U16 },
4832 [NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT] = { .type = NLA_U32 },
4833 [NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL] = { .type = NLA_U16 },
Thomas Pedersendca7e942011-11-24 17:15:24 -08004834 [NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL] = { .type = NLA_U16 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004835 [NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME] = { .type = NLA_U16 },
Javier Cardona699403d2011-08-09 16:45:09 -07004836 [NL80211_MESHCONF_HWMP_ROOTMODE] = { .type = NLA_U8 },
Javier Cardona0507e152011-08-09 16:45:10 -07004837 [NL80211_MESHCONF_HWMP_RANN_INTERVAL] = { .type = NLA_U16 },
Javier Cardona16dd7262011-08-09 16:45:11 -07004838 [NL80211_MESHCONF_GATE_ANNOUNCEMENTS] = { .type = NLA_U8 },
Chun-Yeow Yeoh94f90652012-01-21 01:02:16 +08004839 [NL80211_MESHCONF_FORWARDING] = { .type = NLA_U8 },
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004840 [NL80211_MESHCONF_RSSI_THRESHOLD] = { .type = NLA_U32 },
4841 [NL80211_MESHCONF_HT_OPMODE] = { .type = NLA_U16 },
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08004842 [NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT] = { .type = NLA_U32 },
4843 [NL80211_MESHCONF_HWMP_ROOT_INTERVAL] = { .type = NLA_U16 },
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +08004844 [NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL] = { .type = NLA_U16 },
Marco Porsch3b1c5a52013-01-07 16:04:52 +01004845 [NL80211_MESHCONF_POWER_MODE] = { .type = NLA_U32 },
4846 [NL80211_MESHCONF_AWAKE_WINDOW] = { .type = NLA_U16 },
Colleen Twitty8e7c0532013-06-03 09:53:39 -07004847 [NL80211_MESHCONF_PLINK_TIMEOUT] = { .type = NLA_U32 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004848};
4849
Javier Cardonac80d5452010-12-16 17:37:49 -08004850static const struct nla_policy
4851 nl80211_mesh_setup_params_policy[NL80211_MESH_SETUP_ATTR_MAX+1] = {
Javier Cardonad299a1f2012-03-31 11:31:33 -07004852 [NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC] = { .type = NLA_U8 },
Javier Cardonac80d5452010-12-16 17:37:49 -08004853 [NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL] = { .type = NLA_U8 },
4854 [NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC] = { .type = NLA_U8 },
Javier Cardona15d5dda2011-04-07 15:08:28 -07004855 [NL80211_MESH_SETUP_USERSPACE_AUTH] = { .type = NLA_FLAG },
Colleen Twitty6e16d902013-05-08 11:45:59 -07004856 [NL80211_MESH_SETUP_AUTH_PROTOCOL] = { .type = NLA_U8 },
Thomas Pedersenbb2798d2013-03-04 13:06:10 -08004857 [NL80211_MESH_SETUP_USERSPACE_MPM] = { .type = NLA_FLAG },
Javier Cardona581a8b02011-04-07 15:08:27 -07004858 [NL80211_MESH_SETUP_IE] = { .type = NLA_BINARY,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004859 .len = IEEE80211_MAX_DATA_LEN },
Javier Cardonab130e5c2011-05-03 16:57:07 -07004860 [NL80211_MESH_SETUP_USERSPACE_AMPE] = { .type = NLA_FLAG },
Javier Cardonac80d5452010-12-16 17:37:49 -08004861};
4862
Javier Cardona24bdd9f2010-12-16 17:37:48 -08004863static int nl80211_parse_mesh_config(struct genl_info *info,
Johannes Bergbd90fdc2010-12-03 09:20:43 +01004864 struct mesh_config *cfg,
4865 u32 *mask_out)
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004866{
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004867 struct nlattr *tb[NL80211_MESHCONF_ATTR_MAX + 1];
Johannes Bergbd90fdc2010-12-03 09:20:43 +01004868 u32 mask = 0;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004869
Marco Porschea54fba2013-01-07 16:04:48 +01004870#define FILL_IN_MESH_PARAM_IF_SET(tb, cfg, param, min, max, mask, attr, fn) \
4871do { \
4872 if (tb[attr]) { \
4873 if (fn(tb[attr]) < min || fn(tb[attr]) > max) \
4874 return -EINVAL; \
4875 cfg->param = fn(tb[attr]); \
4876 mask |= (1 << (attr - 1)); \
4877 } \
4878} while (0)
Johannes Bergbd90fdc2010-12-03 09:20:43 +01004879
4880
Javier Cardona24bdd9f2010-12-16 17:37:48 -08004881 if (!info->attrs[NL80211_ATTR_MESH_CONFIG])
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004882 return -EINVAL;
4883 if (nla_parse_nested(tb, NL80211_MESHCONF_ATTR_MAX,
Javier Cardona24bdd9f2010-12-16 17:37:48 -08004884 info->attrs[NL80211_ATTR_MESH_CONFIG],
Johannes Bergbd90fdc2010-12-03 09:20:43 +01004885 nl80211_meshconf_params_policy))
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004886 return -EINVAL;
4887
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004888 /* This makes sure that there aren't more than 32 mesh config
4889 * parameters (otherwise our bitfield scheme would not work.) */
4890 BUILD_BUG_ON(NL80211_MESHCONF_ATTR_MAX > 32);
4891
4892 /* Fill in the params struct */
Marco Porschea54fba2013-01-07 16:04:48 +01004893 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshRetryTimeout, 1, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004894 mask, NL80211_MESHCONF_RETRY_TIMEOUT,
4895 nla_get_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01004896 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshConfirmTimeout, 1, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004897 mask, NL80211_MESHCONF_CONFIRM_TIMEOUT,
4898 nla_get_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01004899 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHoldingTimeout, 1, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004900 mask, NL80211_MESHCONF_HOLDING_TIMEOUT,
4901 nla_get_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01004902 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxPeerLinks, 0, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004903 mask, NL80211_MESHCONF_MAX_PEER_LINKS,
4904 nla_get_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01004905 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxRetries, 0, 16,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004906 mask, NL80211_MESHCONF_MAX_RETRIES,
4907 nla_get_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01004908 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshTTL, 1, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004909 mask, NL80211_MESHCONF_TTL, nla_get_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01004910 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, element_ttl, 1, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004911 mask, NL80211_MESHCONF_ELEMENT_TTL,
4912 nla_get_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01004913 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, auto_open_plinks, 0, 1,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004914 mask, NL80211_MESHCONF_AUTO_OPEN_PLINKS,
4915 nla_get_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01004916 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshNbrOffsetMaxNeighbor,
4917 1, 255, mask,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004918 NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR,
4919 nla_get_u32);
Marco Porschea54fba2013-01-07 16:04:48 +01004920 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPmaxPREQretries, 0, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004921 mask, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES,
4922 nla_get_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01004923 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, path_refresh_time, 1, 65535,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004924 mask, NL80211_MESHCONF_PATH_REFRESH_TIME,
4925 nla_get_u32);
Marco Porschea54fba2013-01-07 16:04:48 +01004926 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, min_discovery_timeout, 1, 65535,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004927 mask, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT,
4928 nla_get_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01004929 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathTimeout,
4930 1, 65535, mask,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004931 NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT,
4932 nla_get_u32);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004933 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPpreqMinInterval,
Marco Porschea54fba2013-01-07 16:04:48 +01004934 1, 65535, mask,
4935 NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004936 nla_get_u16);
Thomas Pedersendca7e942011-11-24 17:15:24 -08004937 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPperrMinInterval,
Marco Porschea54fba2013-01-07 16:04:48 +01004938 1, 65535, mask,
4939 NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004940 nla_get_u16);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004941 FILL_IN_MESH_PARAM_IF_SET(tb, cfg,
Marco Porschea54fba2013-01-07 16:04:48 +01004942 dot11MeshHWMPnetDiameterTraversalTime,
4943 1, 65535, mask,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004944 NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME,
4945 nla_get_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01004946 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRootMode, 0, 4,
4947 mask, NL80211_MESHCONF_HWMP_ROOTMODE,
4948 nla_get_u8);
4949 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRannInterval, 1, 65535,
4950 mask, NL80211_MESHCONF_HWMP_RANN_INTERVAL,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004951 nla_get_u16);
Rui Paulo63c57232009-11-09 23:46:57 +00004952 FILL_IN_MESH_PARAM_IF_SET(tb, cfg,
Marco Porschea54fba2013-01-07 16:04:48 +01004953 dot11MeshGateAnnouncementProtocol, 0, 1,
4954 mask, NL80211_MESHCONF_GATE_ANNOUNCEMENTS,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004955 nla_get_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01004956 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshForwarding, 0, 1,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004957 mask, NL80211_MESHCONF_FORWARDING,
4958 nla_get_u8);
Chun-Yeow Yeoh83374fe2013-07-11 18:24:03 +08004959 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, rssi_threshold, -255, 0,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004960 mask, NL80211_MESHCONF_RSSI_THRESHOLD,
Chun-Yeow Yeoh83374fe2013-07-11 18:24:03 +08004961 nla_get_s32);
Marco Porschea54fba2013-01-07 16:04:48 +01004962 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, ht_opmode, 0, 16,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004963 mask, NL80211_MESHCONF_HT_OPMODE,
4964 nla_get_u16);
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08004965 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathToRootTimeout,
Marco Porschea54fba2013-01-07 16:04:48 +01004966 1, 65535, mask,
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08004967 NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT,
4968 nla_get_u32);
Marco Porschea54fba2013-01-07 16:04:48 +01004969 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMProotInterval, 1, 65535,
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08004970 mask, NL80211_MESHCONF_HWMP_ROOT_INTERVAL,
4971 nla_get_u16);
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +08004972 FILL_IN_MESH_PARAM_IF_SET(tb, cfg,
Marco Porschea54fba2013-01-07 16:04:48 +01004973 dot11MeshHWMPconfirmationInterval,
4974 1, 65535, mask,
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +08004975 NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL,
4976 nla_get_u16);
Marco Porsch3b1c5a52013-01-07 16:04:52 +01004977 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, power_mode,
4978 NL80211_MESH_POWER_ACTIVE,
4979 NL80211_MESH_POWER_MAX,
4980 mask, NL80211_MESHCONF_POWER_MODE,
4981 nla_get_u32);
4982 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshAwakeWindowDuration,
4983 0, 65535, mask,
4984 NL80211_MESHCONF_AWAKE_WINDOW, nla_get_u16);
Colleen Twitty8e7c0532013-06-03 09:53:39 -07004985 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, plink_timeout, 1, 0xffffffff,
4986 mask, NL80211_MESHCONF_PLINK_TIMEOUT,
4987 nla_get_u32);
Johannes Bergbd90fdc2010-12-03 09:20:43 +01004988 if (mask_out)
4989 *mask_out = mask;
Javier Cardonac80d5452010-12-16 17:37:49 -08004990
Johannes Bergbd90fdc2010-12-03 09:20:43 +01004991 return 0;
4992
4993#undef FILL_IN_MESH_PARAM_IF_SET
4994}
4995
Javier Cardonac80d5452010-12-16 17:37:49 -08004996static int nl80211_parse_mesh_setup(struct genl_info *info,
4997 struct mesh_setup *setup)
4998{
Thomas Pedersenbb2798d2013-03-04 13:06:10 -08004999 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Javier Cardonac80d5452010-12-16 17:37:49 -08005000 struct nlattr *tb[NL80211_MESH_SETUP_ATTR_MAX + 1];
5001
5002 if (!info->attrs[NL80211_ATTR_MESH_SETUP])
5003 return -EINVAL;
5004 if (nla_parse_nested(tb, NL80211_MESH_SETUP_ATTR_MAX,
5005 info->attrs[NL80211_ATTR_MESH_SETUP],
5006 nl80211_mesh_setup_params_policy))
5007 return -EINVAL;
5008
Javier Cardonad299a1f2012-03-31 11:31:33 -07005009 if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC])
5010 setup->sync_method =
5011 (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC])) ?
5012 IEEE80211_SYNC_METHOD_VENDOR :
5013 IEEE80211_SYNC_METHOD_NEIGHBOR_OFFSET;
5014
Javier Cardonac80d5452010-12-16 17:37:49 -08005015 if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL])
5016 setup->path_sel_proto =
5017 (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL])) ?
5018 IEEE80211_PATH_PROTOCOL_VENDOR :
5019 IEEE80211_PATH_PROTOCOL_HWMP;
5020
5021 if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC])
5022 setup->path_metric =
5023 (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC])) ?
5024 IEEE80211_PATH_METRIC_VENDOR :
5025 IEEE80211_PATH_METRIC_AIRTIME;
5026
Javier Cardona581a8b02011-04-07 15:08:27 -07005027
5028 if (tb[NL80211_MESH_SETUP_IE]) {
Javier Cardonac80d5452010-12-16 17:37:49 -08005029 struct nlattr *ieattr =
Javier Cardona581a8b02011-04-07 15:08:27 -07005030 tb[NL80211_MESH_SETUP_IE];
Javier Cardonac80d5452010-12-16 17:37:49 -08005031 if (!is_valid_ie_attr(ieattr))
5032 return -EINVAL;
Javier Cardona581a8b02011-04-07 15:08:27 -07005033 setup->ie = nla_data(ieattr);
5034 setup->ie_len = nla_len(ieattr);
Javier Cardonac80d5452010-12-16 17:37:49 -08005035 }
Thomas Pedersenbb2798d2013-03-04 13:06:10 -08005036 if (tb[NL80211_MESH_SETUP_USERSPACE_MPM] &&
5037 !(rdev->wiphy.features & NL80211_FEATURE_USERSPACE_MPM))
5038 return -EINVAL;
5039 setup->user_mpm = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_MPM]);
Javier Cardonab130e5c2011-05-03 16:57:07 -07005040 setup->is_authenticated = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AUTH]);
5041 setup->is_secure = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AMPE]);
Thomas Pedersenbb2798d2013-03-04 13:06:10 -08005042 if (setup->is_secure)
5043 setup->user_mpm = true;
Javier Cardonac80d5452010-12-16 17:37:49 -08005044
Colleen Twitty6e16d902013-05-08 11:45:59 -07005045 if (tb[NL80211_MESH_SETUP_AUTH_PROTOCOL]) {
5046 if (!setup->user_mpm)
5047 return -EINVAL;
5048 setup->auth_id =
5049 nla_get_u8(tb[NL80211_MESH_SETUP_AUTH_PROTOCOL]);
5050 }
5051
Javier Cardonac80d5452010-12-16 17:37:49 -08005052 return 0;
5053}
5054
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005055static int nl80211_update_mesh_config(struct sk_buff *skb,
Johannes Berg29cbe682010-12-03 09:20:44 +01005056 struct genl_info *info)
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005057{
5058 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5059 struct net_device *dev = info->user_ptr[1];
Johannes Berg29cbe682010-12-03 09:20:44 +01005060 struct wireless_dev *wdev = dev->ieee80211_ptr;
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005061 struct mesh_config cfg;
5062 u32 mask;
5063 int err;
5064
Johannes Berg29cbe682010-12-03 09:20:44 +01005065 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT)
5066 return -EOPNOTSUPP;
5067
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005068 if (!rdev->ops->update_mesh_config)
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005069 return -EOPNOTSUPP;
5070
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005071 err = nl80211_parse_mesh_config(info, &cfg, &mask);
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005072 if (err)
5073 return err;
5074
Johannes Berg29cbe682010-12-03 09:20:44 +01005075 wdev_lock(wdev);
5076 if (!wdev->mesh_id_len)
5077 err = -ENOLINK;
5078
5079 if (!err)
Hila Gonene35e4d22012-06-27 17:19:42 +03005080 err = rdev_update_mesh_config(rdev, dev, mask, &cfg);
Johannes Berg29cbe682010-12-03 09:20:44 +01005081
5082 wdev_unlock(wdev);
5083
5084 return err;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005085}
5086
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005087static int nl80211_get_reg(struct sk_buff *skb, struct genl_info *info)
5088{
Johannes Berg458f4f92012-12-06 15:47:38 +01005089 const struct ieee80211_regdomain *regdom;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005090 struct sk_buff *msg;
5091 void *hdr = NULL;
5092 struct nlattr *nl_reg_rules;
5093 unsigned int i;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005094
5095 if (!cfg80211_regdomain)
Johannes Berg5fe231e2013-05-08 21:45:15 +02005096 return -EINVAL;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005097
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07005098 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg5fe231e2013-05-08 21:45:15 +02005099 if (!msg)
5100 return -ENOBUFS;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005101
Eric W. Biederman15e47302012-09-07 20:12:54 +00005102 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005103 NL80211_CMD_GET_REG);
5104 if (!hdr)
Julia Lawallefe1cf02011-01-28 15:17:11 +01005105 goto put_failure;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005106
Luis R. Rodriguez57b5ce02012-07-12 11:49:18 -07005107 if (reg_last_request_cell_base() &&
5108 nla_put_u32(msg, NL80211_ATTR_USER_REG_HINT_TYPE,
5109 NL80211_USER_REG_HINT_CELL_BASE))
5110 goto nla_put_failure;
5111
Johannes Berg458f4f92012-12-06 15:47:38 +01005112 rcu_read_lock();
5113 regdom = rcu_dereference(cfg80211_regdomain);
5114
5115 if (nla_put_string(msg, NL80211_ATTR_REG_ALPHA2, regdom->alpha2) ||
5116 (regdom->dfs_region &&
5117 nla_put_u8(msg, NL80211_ATTR_DFS_REGION, regdom->dfs_region)))
5118 goto nla_put_failure_rcu;
5119
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005120 nl_reg_rules = nla_nest_start(msg, NL80211_ATTR_REG_RULES);
5121 if (!nl_reg_rules)
Johannes Berg458f4f92012-12-06 15:47:38 +01005122 goto nla_put_failure_rcu;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005123
Johannes Berg458f4f92012-12-06 15:47:38 +01005124 for (i = 0; i < regdom->n_reg_rules; i++) {
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005125 struct nlattr *nl_reg_rule;
5126 const struct ieee80211_reg_rule *reg_rule;
5127 const struct ieee80211_freq_range *freq_range;
5128 const struct ieee80211_power_rule *power_rule;
Janusz Dziedzic97524822014-01-30 09:52:20 +01005129 unsigned int max_bandwidth_khz;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005130
Johannes Berg458f4f92012-12-06 15:47:38 +01005131 reg_rule = &regdom->reg_rules[i];
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005132 freq_range = &reg_rule->freq_range;
5133 power_rule = &reg_rule->power_rule;
5134
5135 nl_reg_rule = nla_nest_start(msg, i);
5136 if (!nl_reg_rule)
Johannes Berg458f4f92012-12-06 15:47:38 +01005137 goto nla_put_failure_rcu;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005138
Janusz Dziedzic97524822014-01-30 09:52:20 +01005139 max_bandwidth_khz = freq_range->max_bandwidth_khz;
5140 if (!max_bandwidth_khz)
5141 max_bandwidth_khz = reg_get_max_bandwidth(regdom,
5142 reg_rule);
5143
David S. Miller9360ffd2012-03-29 04:41:26 -04005144 if (nla_put_u32(msg, NL80211_ATTR_REG_RULE_FLAGS,
5145 reg_rule->flags) ||
5146 nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_START,
5147 freq_range->start_freq_khz) ||
5148 nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_END,
5149 freq_range->end_freq_khz) ||
5150 nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_MAX_BW,
Janusz Dziedzic97524822014-01-30 09:52:20 +01005151 max_bandwidth_khz) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04005152 nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN,
5153 power_rule->max_antenna_gain) ||
5154 nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_EIRP,
Janusz Dziedzic089027e2014-02-21 19:46:12 +01005155 power_rule->max_eirp) ||
5156 nla_put_u32(msg, NL80211_ATTR_DFS_CAC_TIME,
5157 reg_rule->dfs_cac_ms))
Johannes Berg458f4f92012-12-06 15:47:38 +01005158 goto nla_put_failure_rcu;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005159
5160 nla_nest_end(msg, nl_reg_rule);
5161 }
Johannes Berg458f4f92012-12-06 15:47:38 +01005162 rcu_read_unlock();
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005163
5164 nla_nest_end(msg, nl_reg_rules);
5165
5166 genlmsg_end(msg, hdr);
Johannes Berg5fe231e2013-05-08 21:45:15 +02005167 return genlmsg_reply(msg, info);
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005168
Johannes Berg458f4f92012-12-06 15:47:38 +01005169nla_put_failure_rcu:
5170 rcu_read_unlock();
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005171nla_put_failure:
5172 genlmsg_cancel(msg, hdr);
Julia Lawallefe1cf02011-01-28 15:17:11 +01005173put_failure:
Yuri Ershovd080e272010-06-29 15:08:07 +04005174 nlmsg_free(msg);
Johannes Berg5fe231e2013-05-08 21:45:15 +02005175 return -EMSGSIZE;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005176}
5177
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005178static int nl80211_set_reg(struct sk_buff *skb, struct genl_info *info)
5179{
5180 struct nlattr *tb[NL80211_REG_RULE_ATTR_MAX + 1];
5181 struct nlattr *nl_reg_rule;
5182 char *alpha2 = NULL;
5183 int rem_reg_rules = 0, r = 0;
5184 u32 num_rules = 0, rule_idx = 0, size_of_regd;
Luis R. Rodriguez4c7d3982013-11-13 18:54:02 +01005185 enum nl80211_dfs_regions dfs_region = NL80211_DFS_UNSET;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005186 struct ieee80211_regdomain *rd = NULL;
5187
5188 if (!info->attrs[NL80211_ATTR_REG_ALPHA2])
5189 return -EINVAL;
5190
5191 if (!info->attrs[NL80211_ATTR_REG_RULES])
5192 return -EINVAL;
5193
5194 alpha2 = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]);
5195
Luis R. Rodriguez8b60b072011-10-11 10:59:02 -07005196 if (info->attrs[NL80211_ATTR_DFS_REGION])
5197 dfs_region = nla_get_u8(info->attrs[NL80211_ATTR_DFS_REGION]);
5198
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005199 nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES],
Johannes Berg1a919312012-12-03 17:21:11 +01005200 rem_reg_rules) {
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005201 num_rules++;
5202 if (num_rules > NL80211_MAX_SUPP_REG_RULES)
Luis R. Rodriguez4776c6e2009-05-13 17:04:39 -04005203 return -EINVAL;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005204 }
5205
Luis R. Rodrigueze4387682013-11-05 09:18:01 -08005206 if (!reg_is_valid_request(alpha2))
5207 return -EINVAL;
5208
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005209 size_of_regd = sizeof(struct ieee80211_regdomain) +
Johannes Berg1a919312012-12-03 17:21:11 +01005210 num_rules * sizeof(struct ieee80211_reg_rule);
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005211
5212 rd = kzalloc(size_of_regd, GFP_KERNEL);
Johannes Berg6913b492012-12-04 00:48:59 +01005213 if (!rd)
5214 return -ENOMEM;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005215
5216 rd->n_reg_rules = num_rules;
5217 rd->alpha2[0] = alpha2[0];
5218 rd->alpha2[1] = alpha2[1];
5219
Luis R. Rodriguez8b60b072011-10-11 10:59:02 -07005220 /*
5221 * Disable DFS master mode if the DFS region was
5222 * not supported or known on this kernel.
5223 */
5224 if (reg_supported_dfs_region(dfs_region))
5225 rd->dfs_region = dfs_region;
5226
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005227 nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES],
Johannes Berg1a919312012-12-03 17:21:11 +01005228 rem_reg_rules) {
Johannes Bergae811e22014-01-24 10:17:47 +01005229 r = nla_parse(tb, NL80211_REG_RULE_ATTR_MAX,
5230 nla_data(nl_reg_rule), nla_len(nl_reg_rule),
5231 reg_rule_policy);
5232 if (r)
5233 goto bad_reg;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005234 r = parse_reg_rule(tb, &rd->reg_rules[rule_idx]);
5235 if (r)
5236 goto bad_reg;
5237
5238 rule_idx++;
5239
Luis R. Rodriguezd0e18f82009-05-13 17:04:40 -04005240 if (rule_idx > NL80211_MAX_SUPP_REG_RULES) {
5241 r = -EINVAL;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005242 goto bad_reg;
Luis R. Rodriguezd0e18f82009-05-13 17:04:40 -04005243 }
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005244 }
5245
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005246 r = set_regdom(rd);
Johannes Berg6913b492012-12-04 00:48:59 +01005247 /* set_regdom took ownership */
Johannes Berg1a919312012-12-03 17:21:11 +01005248 rd = NULL;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005249
Johannes Bergd2372b32008-10-24 20:32:20 +02005250 bad_reg:
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005251 kfree(rd);
Luis R. Rodriguezd0e18f82009-05-13 17:04:40 -04005252 return r;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005253}
5254
Johannes Berg83f5e2c2009-06-17 17:41:49 +02005255static int validate_scan_freqs(struct nlattr *freqs)
5256{
5257 struct nlattr *attr1, *attr2;
5258 int n_channels = 0, tmp1, tmp2;
5259
5260 nla_for_each_nested(attr1, freqs, tmp1) {
5261 n_channels++;
5262 /*
5263 * Some hardware has a limited channel list for
5264 * scanning, and it is pretty much nonsensical
5265 * to scan for a channel twice, so disallow that
5266 * and don't require drivers to check that the
5267 * channel list they get isn't longer than what
5268 * they can scan, as long as they can scan all
5269 * the channels they registered at once.
5270 */
5271 nla_for_each_nested(attr2, freqs, tmp2)
5272 if (attr1 != attr2 &&
5273 nla_get_u32(attr1) == nla_get_u32(attr2))
5274 return 0;
5275 }
5276
5277 return n_channels;
5278}
5279
Johannes Berg2a519312009-02-10 21:25:55 +01005280static int nl80211_trigger_scan(struct sk_buff *skb, struct genl_info *info)
5281{
Johannes Berg4c476992010-10-04 21:36:35 +02005282 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Bergfd014282012-06-18 19:17:03 +02005283 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg2a519312009-02-10 21:25:55 +01005284 struct cfg80211_scan_request *request;
Johannes Berg2a519312009-02-10 21:25:55 +01005285 struct nlattr *attr;
5286 struct wiphy *wiphy;
Johannes Berg83f5e2c2009-06-17 17:41:49 +02005287 int err, tmp, n_ssids = 0, n_channels, i;
Jouni Malinen70692ad2009-02-16 19:39:13 +02005288 size_t ie_len;
Johannes Berg2a519312009-02-10 21:25:55 +01005289
Johannes Bergf4a11bb2009-03-27 12:40:28 +01005290 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
5291 return -EINVAL;
5292
Johannes Berg79c97e92009-07-07 03:56:12 +02005293 wiphy = &rdev->wiphy;
Johannes Berg2a519312009-02-10 21:25:55 +01005294
Johannes Berg4c476992010-10-04 21:36:35 +02005295 if (!rdev->ops->scan)
5296 return -EOPNOTSUPP;
Johannes Berg2a519312009-02-10 21:25:55 +01005297
Johannes Bergf9d15d12014-01-22 11:14:19 +02005298 if (rdev->scan_req || rdev->scan_msg) {
Johannes Bergf9f47522013-03-19 15:04:07 +01005299 err = -EBUSY;
5300 goto unlock;
5301 }
Johannes Berg2a519312009-02-10 21:25:55 +01005302
5303 if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
Johannes Berg83f5e2c2009-06-17 17:41:49 +02005304 n_channels = validate_scan_freqs(
5305 info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]);
Johannes Bergf9f47522013-03-19 15:04:07 +01005306 if (!n_channels) {
5307 err = -EINVAL;
5308 goto unlock;
5309 }
Johannes Berg2a519312009-02-10 21:25:55 +01005310 } else {
Ilan Peerbdfbec22014-01-09 11:37:23 +02005311 n_channels = ieee80211_get_num_supported_channels(wiphy);
Johannes Berg2a519312009-02-10 21:25:55 +01005312 }
5313
5314 if (info->attrs[NL80211_ATTR_SCAN_SSIDS])
5315 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp)
5316 n_ssids++;
5317
Johannes Bergf9f47522013-03-19 15:04:07 +01005318 if (n_ssids > wiphy->max_scan_ssids) {
5319 err = -EINVAL;
5320 goto unlock;
5321 }
Johannes Berg2a519312009-02-10 21:25:55 +01005322
Jouni Malinen70692ad2009-02-16 19:39:13 +02005323 if (info->attrs[NL80211_ATTR_IE])
5324 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
5325 else
5326 ie_len = 0;
5327
Johannes Bergf9f47522013-03-19 15:04:07 +01005328 if (ie_len > wiphy->max_scan_ie_len) {
5329 err = -EINVAL;
5330 goto unlock;
5331 }
Johannes Berg18a83652009-03-31 12:12:05 +02005332
Johannes Berg2a519312009-02-10 21:25:55 +01005333 request = kzalloc(sizeof(*request)
Luciano Coelhoa2cd43c2011-05-18 11:42:03 +03005334 + sizeof(*request->ssids) * n_ssids
5335 + sizeof(*request->channels) * n_channels
Jouni Malinen70692ad2009-02-16 19:39:13 +02005336 + ie_len, GFP_KERNEL);
Johannes Bergf9f47522013-03-19 15:04:07 +01005337 if (!request) {
5338 err = -ENOMEM;
5339 goto unlock;
5340 }
Johannes Berg2a519312009-02-10 21:25:55 +01005341
Johannes Berg2a519312009-02-10 21:25:55 +01005342 if (n_ssids)
Johannes Berg5ba63532009-08-07 17:54:07 +02005343 request->ssids = (void *)&request->channels[n_channels];
Johannes Berg2a519312009-02-10 21:25:55 +01005344 request->n_ssids = n_ssids;
Jouni Malinen70692ad2009-02-16 19:39:13 +02005345 if (ie_len) {
5346 if (request->ssids)
5347 request->ie = (void *)(request->ssids + n_ssids);
5348 else
5349 request->ie = (void *)(request->channels + n_channels);
5350 }
Johannes Berg2a519312009-02-10 21:25:55 +01005351
Johannes Berg584991d2009-11-02 13:32:03 +01005352 i = 0;
Johannes Berg2a519312009-02-10 21:25:55 +01005353 if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
5354 /* user specified, bail out if channel not found */
Johannes Berg2a519312009-02-10 21:25:55 +01005355 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_FREQUENCIES], tmp) {
Johannes Berg584991d2009-11-02 13:32:03 +01005356 struct ieee80211_channel *chan;
5357
5358 chan = ieee80211_get_channel(wiphy, nla_get_u32(attr));
5359
5360 if (!chan) {
Johannes Berg2a519312009-02-10 21:25:55 +01005361 err = -EINVAL;
5362 goto out_free;
5363 }
Johannes Berg584991d2009-11-02 13:32:03 +01005364
5365 /* ignore disabled channels */
5366 if (chan->flags & IEEE80211_CHAN_DISABLED)
5367 continue;
5368
5369 request->channels[i] = chan;
Johannes Berg2a519312009-02-10 21:25:55 +01005370 i++;
5371 }
5372 } else {
Johannes Berg34850ab2011-07-18 18:08:35 +02005373 enum ieee80211_band band;
5374
Johannes Berg2a519312009-02-10 21:25:55 +01005375 /* all channels */
Johannes Berg2a519312009-02-10 21:25:55 +01005376 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
5377 int j;
5378 if (!wiphy->bands[band])
5379 continue;
5380 for (j = 0; j < wiphy->bands[band]->n_channels; j++) {
Johannes Berg584991d2009-11-02 13:32:03 +01005381 struct ieee80211_channel *chan;
5382
5383 chan = &wiphy->bands[band]->channels[j];
5384
5385 if (chan->flags & IEEE80211_CHAN_DISABLED)
5386 continue;
5387
5388 request->channels[i] = chan;
Johannes Berg2a519312009-02-10 21:25:55 +01005389 i++;
5390 }
5391 }
5392 }
5393
Johannes Berg584991d2009-11-02 13:32:03 +01005394 if (!i) {
5395 err = -EINVAL;
5396 goto out_free;
5397 }
5398
5399 request->n_channels = i;
5400
Johannes Berg2a519312009-02-10 21:25:55 +01005401 i = 0;
5402 if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) {
5403 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) {
Luciano Coelho57a27e12011-06-07 20:42:26 +03005404 if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) {
Johannes Berg2a519312009-02-10 21:25:55 +01005405 err = -EINVAL;
5406 goto out_free;
5407 }
Luciano Coelho57a27e12011-06-07 20:42:26 +03005408 request->ssids[i].ssid_len = nla_len(attr);
Johannes Berg2a519312009-02-10 21:25:55 +01005409 memcpy(request->ssids[i].ssid, nla_data(attr), nla_len(attr));
Johannes Berg2a519312009-02-10 21:25:55 +01005410 i++;
5411 }
5412 }
5413
Jouni Malinen70692ad2009-02-16 19:39:13 +02005414 if (info->attrs[NL80211_ATTR_IE]) {
5415 request->ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Johannes Bergde95a542009-04-01 11:58:36 +02005416 memcpy((void *)request->ie,
5417 nla_data(info->attrs[NL80211_ATTR_IE]),
Jouni Malinen70692ad2009-02-16 19:39:13 +02005418 request->ie_len);
5419 }
5420
Johannes Berg34850ab2011-07-18 18:08:35 +02005421 for (i = 0; i < IEEE80211_NUM_BANDS; i++)
Johannes Berga401d2b2011-07-20 00:52:16 +02005422 if (wiphy->bands[i])
5423 request->rates[i] =
5424 (1 << wiphy->bands[i]->n_bitrates) - 1;
Johannes Berg34850ab2011-07-18 18:08:35 +02005425
5426 if (info->attrs[NL80211_ATTR_SCAN_SUPP_RATES]) {
5427 nla_for_each_nested(attr,
5428 info->attrs[NL80211_ATTR_SCAN_SUPP_RATES],
5429 tmp) {
5430 enum ieee80211_band band = nla_type(attr);
5431
Dan Carpenter84404622011-07-29 11:52:18 +03005432 if (band < 0 || band >= IEEE80211_NUM_BANDS) {
Johannes Berg34850ab2011-07-18 18:08:35 +02005433 err = -EINVAL;
5434 goto out_free;
5435 }
Felix Fietkau1b09cd82013-11-20 19:40:41 +01005436
5437 if (!wiphy->bands[band])
5438 continue;
5439
Johannes Berg34850ab2011-07-18 18:08:35 +02005440 err = ieee80211_get_ratemask(wiphy->bands[band],
5441 nla_data(attr),
5442 nla_len(attr),
5443 &request->rates[band]);
5444 if (err)
5445 goto out_free;
5446 }
5447 }
5448
Sam Leffler46856bb2012-10-11 21:03:32 -07005449 if (info->attrs[NL80211_ATTR_SCAN_FLAGS]) {
Sam Lefflered4737712012-10-11 21:03:31 -07005450 request->flags = nla_get_u32(
5451 info->attrs[NL80211_ATTR_SCAN_FLAGS]);
Johannes Berg00c3a6e2013-10-26 17:14:38 +02005452 if ((request->flags & NL80211_SCAN_FLAG_LOW_PRIORITY) &&
5453 !(wiphy->features & NL80211_FEATURE_LOW_PRIORITY_SCAN)) {
Sam Leffler46856bb2012-10-11 21:03:32 -07005454 err = -EOPNOTSUPP;
5455 goto out_free;
5456 }
5457 }
Sam Lefflered4737712012-10-11 21:03:31 -07005458
Rajkumar Manoharane9f935e2011-09-25 14:53:30 +05305459 request->no_cck =
5460 nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]);
5461
Johannes Bergfd014282012-06-18 19:17:03 +02005462 request->wdev = wdev;
Johannes Berg79c97e92009-07-07 03:56:12 +02005463 request->wiphy = &rdev->wiphy;
Sam Leffler15d60302012-10-11 21:03:34 -07005464 request->scan_start = jiffies;
Johannes Berg2a519312009-02-10 21:25:55 +01005465
Johannes Berg79c97e92009-07-07 03:56:12 +02005466 rdev->scan_req = request;
Hila Gonene35e4d22012-06-27 17:19:42 +03005467 err = rdev_scan(rdev, request);
Johannes Berg2a519312009-02-10 21:25:55 +01005468
Johannes Berg463d0182009-07-14 00:33:35 +02005469 if (!err) {
Johannes Bergfd014282012-06-18 19:17:03 +02005470 nl80211_send_scan_start(rdev, wdev);
5471 if (wdev->netdev)
5472 dev_hold(wdev->netdev);
Johannes Berg4c476992010-10-04 21:36:35 +02005473 } else {
Johannes Berg2a519312009-02-10 21:25:55 +01005474 out_free:
Johannes Berg79c97e92009-07-07 03:56:12 +02005475 rdev->scan_req = NULL;
Johannes Berg2a519312009-02-10 21:25:55 +01005476 kfree(request);
5477 }
Johannes Berg3b858752009-03-12 09:55:09 +01005478
Johannes Bergf9f47522013-03-19 15:04:07 +01005479 unlock:
Johannes Berg2a519312009-02-10 21:25:55 +01005480 return err;
5481}
5482
Luciano Coelho807f8a82011-05-11 17:09:35 +03005483static int nl80211_start_sched_scan(struct sk_buff *skb,
5484 struct genl_info *info)
5485{
5486 struct cfg80211_sched_scan_request *request;
5487 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5488 struct net_device *dev = info->user_ptr[1];
Luciano Coelho807f8a82011-05-11 17:09:35 +03005489 struct nlattr *attr;
5490 struct wiphy *wiphy;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005491 int err, tmp, n_ssids = 0, n_match_sets = 0, n_channels, i;
Luciano Coelhobbe6ad62011-05-11 17:09:37 +03005492 u32 interval;
Luciano Coelho807f8a82011-05-11 17:09:35 +03005493 enum ieee80211_band band;
5494 size_t ie_len;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005495 struct nlattr *tb[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1];
Johannes Bergea73cbc2014-01-24 10:53:53 +01005496 s32 default_match_rssi = NL80211_SCAN_RSSI_THOLD_OFF;
Luciano Coelho807f8a82011-05-11 17:09:35 +03005497
5498 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) ||
5499 !rdev->ops->sched_scan_start)
5500 return -EOPNOTSUPP;
5501
5502 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
5503 return -EINVAL;
5504
Luciano Coelhobbe6ad62011-05-11 17:09:37 +03005505 if (!info->attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL])
5506 return -EINVAL;
5507
5508 interval = nla_get_u32(info->attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]);
5509 if (interval == 0)
5510 return -EINVAL;
5511
Luciano Coelho807f8a82011-05-11 17:09:35 +03005512 wiphy = &rdev->wiphy;
5513
5514 if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
5515 n_channels = validate_scan_freqs(
5516 info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]);
5517 if (!n_channels)
5518 return -EINVAL;
5519 } else {
Ilan Peerbdfbec22014-01-09 11:37:23 +02005520 n_channels = ieee80211_get_num_supported_channels(wiphy);
Luciano Coelho807f8a82011-05-11 17:09:35 +03005521 }
5522
5523 if (info->attrs[NL80211_ATTR_SCAN_SSIDS])
5524 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS],
5525 tmp)
5526 n_ssids++;
5527
Luciano Coelho93b6aa62011-07-13 14:57:28 +03005528 if (n_ssids > wiphy->max_sched_scan_ssids)
Luciano Coelho807f8a82011-05-11 17:09:35 +03005529 return -EINVAL;
5530
Johannes Bergea73cbc2014-01-24 10:53:53 +01005531 /*
5532 * First, count the number of 'real' matchsets. Due to an issue with
5533 * the old implementation, matchsets containing only the RSSI attribute
5534 * (NL80211_SCHED_SCAN_MATCH_ATTR_RSSI) are considered as the 'default'
5535 * RSSI for all matchsets, rather than their own matchset for reporting
5536 * all APs with a strong RSSI. This is needed to be compatible with
5537 * older userspace that treated a matchset with only the RSSI as the
5538 * global RSSI for all other matchsets - if there are other matchsets.
5539 */
5540 if (info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) {
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005541 nla_for_each_nested(attr,
5542 info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH],
Johannes Bergea73cbc2014-01-24 10:53:53 +01005543 tmp) {
5544 struct nlattr *rssi;
5545
5546 err = nla_parse(tb, NL80211_SCHED_SCAN_MATCH_ATTR_MAX,
5547 nla_data(attr), nla_len(attr),
5548 nl80211_match_policy);
5549 if (err)
5550 return err;
5551 /* add other standalone attributes here */
5552 if (tb[NL80211_SCHED_SCAN_MATCH_ATTR_SSID]) {
5553 n_match_sets++;
5554 continue;
5555 }
5556 rssi = tb[NL80211_SCHED_SCAN_MATCH_ATTR_RSSI];
5557 if (rssi)
5558 default_match_rssi = nla_get_s32(rssi);
5559 }
5560 }
5561
5562 /* However, if there's no other matchset, add the RSSI one */
5563 if (!n_match_sets && default_match_rssi != NL80211_SCAN_RSSI_THOLD_OFF)
5564 n_match_sets = 1;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005565
5566 if (n_match_sets > wiphy->max_match_sets)
5567 return -EINVAL;
5568
Luciano Coelho807f8a82011-05-11 17:09:35 +03005569 if (info->attrs[NL80211_ATTR_IE])
5570 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
5571 else
5572 ie_len = 0;
5573
Luciano Coelho5a865ba2011-07-13 14:57:29 +03005574 if (ie_len > wiphy->max_sched_scan_ie_len)
Luciano Coelho807f8a82011-05-11 17:09:35 +03005575 return -EINVAL;
5576
Luciano Coelhoc10841c2011-06-30 08:32:41 +03005577 if (rdev->sched_scan_req) {
5578 err = -EINPROGRESS;
5579 goto out;
5580 }
5581
Luciano Coelho807f8a82011-05-11 17:09:35 +03005582 request = kzalloc(sizeof(*request)
Luciano Coelhoa2cd43c2011-05-18 11:42:03 +03005583 + sizeof(*request->ssids) * n_ssids
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005584 + sizeof(*request->match_sets) * n_match_sets
Luciano Coelhoa2cd43c2011-05-18 11:42:03 +03005585 + sizeof(*request->channels) * n_channels
Luciano Coelho807f8a82011-05-11 17:09:35 +03005586 + ie_len, GFP_KERNEL);
Luciano Coelhoc10841c2011-06-30 08:32:41 +03005587 if (!request) {
5588 err = -ENOMEM;
5589 goto out;
5590 }
Luciano Coelho807f8a82011-05-11 17:09:35 +03005591
5592 if (n_ssids)
5593 request->ssids = (void *)&request->channels[n_channels];
5594 request->n_ssids = n_ssids;
5595 if (ie_len) {
5596 if (request->ssids)
5597 request->ie = (void *)(request->ssids + n_ssids);
5598 else
5599 request->ie = (void *)(request->channels + n_channels);
5600 }
5601
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005602 if (n_match_sets) {
5603 if (request->ie)
5604 request->match_sets = (void *)(request->ie + ie_len);
5605 else if (request->ssids)
5606 request->match_sets =
5607 (void *)(request->ssids + n_ssids);
5608 else
5609 request->match_sets =
5610 (void *)(request->channels + n_channels);
5611 }
5612 request->n_match_sets = n_match_sets;
5613
Luciano Coelho807f8a82011-05-11 17:09:35 +03005614 i = 0;
5615 if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
5616 /* user specified, bail out if channel not found */
5617 nla_for_each_nested(attr,
5618 info->attrs[NL80211_ATTR_SCAN_FREQUENCIES],
5619 tmp) {
5620 struct ieee80211_channel *chan;
5621
5622 chan = ieee80211_get_channel(wiphy, nla_get_u32(attr));
5623
5624 if (!chan) {
5625 err = -EINVAL;
5626 goto out_free;
5627 }
5628
5629 /* ignore disabled channels */
5630 if (chan->flags & IEEE80211_CHAN_DISABLED)
5631 continue;
5632
5633 request->channels[i] = chan;
5634 i++;
5635 }
5636 } else {
5637 /* all channels */
5638 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
5639 int j;
5640 if (!wiphy->bands[band])
5641 continue;
5642 for (j = 0; j < wiphy->bands[band]->n_channels; j++) {
5643 struct ieee80211_channel *chan;
5644
5645 chan = &wiphy->bands[band]->channels[j];
5646
5647 if (chan->flags & IEEE80211_CHAN_DISABLED)
5648 continue;
5649
5650 request->channels[i] = chan;
5651 i++;
5652 }
5653 }
5654 }
5655
5656 if (!i) {
5657 err = -EINVAL;
5658 goto out_free;
5659 }
5660
5661 request->n_channels = i;
5662
5663 i = 0;
5664 if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) {
5665 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS],
5666 tmp) {
Luciano Coelho57a27e12011-06-07 20:42:26 +03005667 if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) {
Luciano Coelho807f8a82011-05-11 17:09:35 +03005668 err = -EINVAL;
5669 goto out_free;
5670 }
Luciano Coelho57a27e12011-06-07 20:42:26 +03005671 request->ssids[i].ssid_len = nla_len(attr);
Luciano Coelho807f8a82011-05-11 17:09:35 +03005672 memcpy(request->ssids[i].ssid, nla_data(attr),
5673 nla_len(attr));
Luciano Coelho807f8a82011-05-11 17:09:35 +03005674 i++;
5675 }
5676 }
5677
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005678 i = 0;
5679 if (info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) {
5680 nla_for_each_nested(attr,
5681 info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH],
5682 tmp) {
Thomas Pedersen88e920b2012-06-21 11:09:54 -07005683 struct nlattr *ssid, *rssi;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005684
Johannes Bergae811e22014-01-24 10:17:47 +01005685 err = nla_parse(tb, NL80211_SCHED_SCAN_MATCH_ATTR_MAX,
5686 nla_data(attr), nla_len(attr),
5687 nl80211_match_policy);
5688 if (err)
5689 goto out_free;
Johannes Berg4a4ab0d2012-06-13 11:17:11 +02005690 ssid = tb[NL80211_SCHED_SCAN_MATCH_ATTR_SSID];
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005691 if (ssid) {
Johannes Bergea73cbc2014-01-24 10:53:53 +01005692 if (WARN_ON(i >= n_match_sets)) {
5693 /* this indicates a programming error,
5694 * the loop above should have verified
5695 * things properly
5696 */
5697 err = -EINVAL;
5698 goto out_free;
5699 }
5700
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005701 if (nla_len(ssid) > IEEE80211_MAX_SSID_LEN) {
5702 err = -EINVAL;
5703 goto out_free;
5704 }
5705 memcpy(request->match_sets[i].ssid.ssid,
5706 nla_data(ssid), nla_len(ssid));
5707 request->match_sets[i].ssid.ssid_len =
5708 nla_len(ssid);
Johannes Bergea73cbc2014-01-24 10:53:53 +01005709 /* special attribute - old implemenation w/a */
5710 request->match_sets[i].rssi_thold =
5711 default_match_rssi;
5712 rssi = tb[NL80211_SCHED_SCAN_MATCH_ATTR_RSSI];
5713 if (rssi)
5714 request->match_sets[i].rssi_thold =
5715 nla_get_s32(rssi);
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005716 }
5717 i++;
5718 }
Johannes Bergea73cbc2014-01-24 10:53:53 +01005719
5720 /* there was no other matchset, so the RSSI one is alone */
5721 if (i == 0)
5722 request->match_sets[0].rssi_thold = default_match_rssi;
5723
5724 request->min_rssi_thold = INT_MAX;
5725 for (i = 0; i < n_match_sets; i++)
5726 request->min_rssi_thold =
5727 min(request->match_sets[i].rssi_thold,
5728 request->min_rssi_thold);
5729 } else {
5730 request->min_rssi_thold = NL80211_SCAN_RSSI_THOLD_OFF;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005731 }
5732
Johannes Berg9900e482014-02-04 21:01:25 +01005733 if (ie_len) {
5734 request->ie_len = ie_len;
Luciano Coelho807f8a82011-05-11 17:09:35 +03005735 memcpy((void *)request->ie,
5736 nla_data(info->attrs[NL80211_ATTR_IE]),
5737 request->ie_len);
5738 }
5739
Sam Leffler46856bb2012-10-11 21:03:32 -07005740 if (info->attrs[NL80211_ATTR_SCAN_FLAGS]) {
Sam Lefflered4737712012-10-11 21:03:31 -07005741 request->flags = nla_get_u32(
5742 info->attrs[NL80211_ATTR_SCAN_FLAGS]);
Johannes Berg00c3a6e2013-10-26 17:14:38 +02005743 if ((request->flags & NL80211_SCAN_FLAG_LOW_PRIORITY) &&
5744 !(wiphy->features & NL80211_FEATURE_LOW_PRIORITY_SCAN)) {
Sam Leffler46856bb2012-10-11 21:03:32 -07005745 err = -EOPNOTSUPP;
5746 goto out_free;
5747 }
5748 }
Sam Lefflered4737712012-10-11 21:03:31 -07005749
Luciano Coelho807f8a82011-05-11 17:09:35 +03005750 request->dev = dev;
5751 request->wiphy = &rdev->wiphy;
Luciano Coelhobbe6ad62011-05-11 17:09:37 +03005752 request->interval = interval;
Sam Leffler15d60302012-10-11 21:03:34 -07005753 request->scan_start = jiffies;
Luciano Coelho807f8a82011-05-11 17:09:35 +03005754
Hila Gonene35e4d22012-06-27 17:19:42 +03005755 err = rdev_sched_scan_start(rdev, dev, request);
Luciano Coelho807f8a82011-05-11 17:09:35 +03005756 if (!err) {
5757 rdev->sched_scan_req = request;
5758 nl80211_send_sched_scan(rdev, dev,
5759 NL80211_CMD_START_SCHED_SCAN);
5760 goto out;
5761 }
5762
5763out_free:
5764 kfree(request);
5765out:
5766 return err;
5767}
5768
5769static int nl80211_stop_sched_scan(struct sk_buff *skb,
5770 struct genl_info *info)
5771{
5772 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5773
5774 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) ||
5775 !rdev->ops->sched_scan_stop)
5776 return -EOPNOTSUPP;
5777
Johannes Berg5fe231e2013-05-08 21:45:15 +02005778 return __cfg80211_stop_sched_scan(rdev, false);
Luciano Coelho807f8a82011-05-11 17:09:35 +03005779}
5780
Simon Wunderlich04f39042013-02-08 18:16:19 +01005781static int nl80211_start_radar_detection(struct sk_buff *skb,
5782 struct genl_info *info)
5783{
5784 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5785 struct net_device *dev = info->user_ptr[1];
5786 struct wireless_dev *wdev = dev->ieee80211_ptr;
5787 struct cfg80211_chan_def chandef;
Luis R. Rodriguez55f74352013-11-25 20:56:10 +01005788 enum nl80211_dfs_regions dfs_region;
Janusz Dziedzic31559f32014-02-21 19:46:13 +01005789 unsigned int cac_time_ms;
Simon Wunderlich04f39042013-02-08 18:16:19 +01005790 int err;
5791
Luis R. Rodriguez55f74352013-11-25 20:56:10 +01005792 dfs_region = reg_get_dfs_region(wdev->wiphy);
5793 if (dfs_region == NL80211_DFS_UNSET)
5794 return -EINVAL;
5795
Simon Wunderlich04f39042013-02-08 18:16:19 +01005796 err = nl80211_parse_chandef(rdev, info, &chandef);
5797 if (err)
5798 return err;
5799
Simon Wunderlichff311bc2013-09-03 19:43:18 +02005800 if (netif_carrier_ok(dev))
5801 return -EBUSY;
5802
Simon Wunderlich04f39042013-02-08 18:16:19 +01005803 if (wdev->cac_started)
5804 return -EBUSY;
5805
Luciano Coelho2beb6da2014-02-18 11:40:36 +02005806 err = cfg80211_chandef_dfs_required(wdev->wiphy, &chandef,
5807 NL80211_IFTYPE_UNSPECIFIED);
Simon Wunderlich04f39042013-02-08 18:16:19 +01005808 if (err < 0)
5809 return err;
5810
5811 if (err == 0)
5812 return -EINVAL;
5813
Janusz Dziedzicfe7c3a12013-11-05 14:48:48 +01005814 if (!cfg80211_chandef_dfs_usable(wdev->wiphy, &chandef))
Simon Wunderlich04f39042013-02-08 18:16:19 +01005815 return -EINVAL;
5816
5817 if (!rdev->ops->start_radar_detection)
5818 return -EOPNOTSUPP;
5819
Janusz Dziedzic31559f32014-02-21 19:46:13 +01005820 cac_time_ms = cfg80211_chandef_dfs_cac_time(&rdev->wiphy, &chandef);
5821 if (WARN_ON(!cac_time_ms))
5822 cac_time_ms = IEEE80211_DFS_MIN_CAC_TIME_MS;
5823
5824 err = rdev->ops->start_radar_detection(&rdev->wiphy, dev, &chandef,
5825 cac_time_ms);
Simon Wunderlich04f39042013-02-08 18:16:19 +01005826 if (!err) {
Michal Kazior9e0e2962014-01-29 14:22:27 +01005827 wdev->chandef = chandef;
Simon Wunderlich04f39042013-02-08 18:16:19 +01005828 wdev->cac_started = true;
5829 wdev->cac_start_time = jiffies;
Janusz Dziedzic31559f32014-02-21 19:46:13 +01005830 wdev->cac_time_ms = cac_time_ms;
Simon Wunderlich04f39042013-02-08 18:16:19 +01005831 }
Simon Wunderlich04f39042013-02-08 18:16:19 +01005832 return err;
5833}
5834
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02005835static int nl80211_channel_switch(struct sk_buff *skb, struct genl_info *info)
5836{
5837 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5838 struct net_device *dev = info->user_ptr[1];
5839 struct wireless_dev *wdev = dev->ieee80211_ptr;
5840 struct cfg80211_csa_settings params;
5841 /* csa_attrs is defined static to avoid waste of stack size - this
5842 * function is called under RTNL lock, so this should not be a problem.
5843 */
5844 static struct nlattr *csa_attrs[NL80211_ATTR_MAX+1];
5845 u8 radar_detect_width = 0;
5846 int err;
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02005847 bool need_new_beacon = false;
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02005848
5849 if (!rdev->ops->channel_switch ||
5850 !(rdev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH))
5851 return -EOPNOTSUPP;
5852
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02005853 switch (dev->ieee80211_ptr->iftype) {
5854 case NL80211_IFTYPE_AP:
5855 case NL80211_IFTYPE_P2P_GO:
5856 need_new_beacon = true;
5857
5858 /* useless if AP is not running */
5859 if (!wdev->beacon_interval)
Johannes Berg1ff79df2014-01-22 10:05:27 +01005860 return -ENOTCONN;
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02005861 break;
5862 case NL80211_IFTYPE_ADHOC:
Johannes Berg1ff79df2014-01-22 10:05:27 +01005863 if (!wdev->ssid_len)
5864 return -ENOTCONN;
5865 break;
Chun-Yeow Yeohc6da6742013-10-14 19:08:28 -07005866 case NL80211_IFTYPE_MESH_POINT:
Johannes Berg1ff79df2014-01-22 10:05:27 +01005867 if (!wdev->mesh_id_len)
5868 return -ENOTCONN;
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02005869 break;
5870 default:
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02005871 return -EOPNOTSUPP;
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02005872 }
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02005873
5874 memset(&params, 0, sizeof(params));
5875
5876 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] ||
5877 !info->attrs[NL80211_ATTR_CH_SWITCH_COUNT])
5878 return -EINVAL;
5879
5880 /* only important for AP, IBSS and mesh create IEs internally */
Andrei Otcheretianskid0a361a2013-10-17 10:52:17 +02005881 if (need_new_beacon && !info->attrs[NL80211_ATTR_CSA_IES])
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02005882 return -EINVAL;
5883
5884 params.count = nla_get_u32(info->attrs[NL80211_ATTR_CH_SWITCH_COUNT]);
5885
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02005886 if (!need_new_beacon)
5887 goto skip_beacons;
5888
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02005889 err = nl80211_parse_beacon(info->attrs, &params.beacon_after);
5890 if (err)
5891 return err;
5892
5893 err = nla_parse_nested(csa_attrs, NL80211_ATTR_MAX,
5894 info->attrs[NL80211_ATTR_CSA_IES],
5895 nl80211_policy);
5896 if (err)
5897 return err;
5898
5899 err = nl80211_parse_beacon(csa_attrs, &params.beacon_csa);
5900 if (err)
5901 return err;
5902
5903 if (!csa_attrs[NL80211_ATTR_CSA_C_OFF_BEACON])
5904 return -EINVAL;
5905
5906 params.counter_offset_beacon =
5907 nla_get_u16(csa_attrs[NL80211_ATTR_CSA_C_OFF_BEACON]);
5908 if (params.counter_offset_beacon >= params.beacon_csa.tail_len)
5909 return -EINVAL;
5910
5911 /* sanity check - counters should be the same */
5912 if (params.beacon_csa.tail[params.counter_offset_beacon] !=
5913 params.count)
5914 return -EINVAL;
5915
5916 if (csa_attrs[NL80211_ATTR_CSA_C_OFF_PRESP]) {
5917 params.counter_offset_presp =
5918 nla_get_u16(csa_attrs[NL80211_ATTR_CSA_C_OFF_PRESP]);
5919 if (params.counter_offset_presp >=
5920 params.beacon_csa.probe_resp_len)
5921 return -EINVAL;
5922
5923 if (params.beacon_csa.probe_resp[params.counter_offset_presp] !=
5924 params.count)
5925 return -EINVAL;
5926 }
5927
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02005928skip_beacons:
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02005929 err = nl80211_parse_chandef(rdev, info, &params.chandef);
5930 if (err)
5931 return err;
5932
Ilan Peer174e0cd2014-02-23 09:13:01 +02005933 if (!cfg80211_reg_can_beacon(&rdev->wiphy, &params.chandef,
5934 wdev->iftype))
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02005935 return -EINVAL;
5936
Luciano Coelho2beb6da2014-02-18 11:40:36 +02005937 err = cfg80211_chandef_dfs_required(wdev->wiphy,
5938 &params.chandef,
5939 wdev->iftype);
5940 if (err < 0)
5941 return err;
5942
5943 if (err > 0) {
5944 radar_detect_width = BIT(params.chandef.width);
5945 params.radar_required = true;
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02005946 }
5947
Luciano Coelho73de86a2014-02-13 11:31:59 +02005948 /* TODO: I left this here for now. With channel switch, the
5949 * verification is a bit more complicated, because we only do
5950 * it later when the channel switch really happens.
5951 */
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02005952 err = cfg80211_can_use_iftype_chan(rdev, wdev, wdev->iftype,
5953 params.chandef.chan,
5954 CHAN_MODE_SHARED,
5955 radar_detect_width);
5956 if (err)
5957 return err;
5958
5959 if (info->attrs[NL80211_ATTR_CH_SWITCH_BLOCK_TX])
5960 params.block_tx = true;
5961
Simon Wunderlichc56589e2013-11-21 18:19:49 +01005962 wdev_lock(wdev);
5963 err = rdev_channel_switch(rdev, dev, &params);
5964 wdev_unlock(wdev);
5965
5966 return err;
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02005967}
5968
Johannes Berg9720bb32011-06-21 09:45:33 +02005969static int nl80211_send_bss(struct sk_buff *msg, struct netlink_callback *cb,
5970 u32 seq, int flags,
Johannes Berg2a519312009-02-10 21:25:55 +01005971 struct cfg80211_registered_device *rdev,
Johannes Berg48ab9052009-07-10 18:42:31 +02005972 struct wireless_dev *wdev,
5973 struct cfg80211_internal_bss *intbss)
Johannes Berg2a519312009-02-10 21:25:55 +01005974{
Johannes Berg48ab9052009-07-10 18:42:31 +02005975 struct cfg80211_bss *res = &intbss->pub;
Johannes Berg9caf0362012-11-29 01:25:20 +01005976 const struct cfg80211_bss_ies *ies;
Johannes Berg2a519312009-02-10 21:25:55 +01005977 void *hdr;
5978 struct nlattr *bss;
Johannes Berg8cef2c92013-02-05 16:54:31 +01005979 bool tsf = false;
Johannes Berg48ab9052009-07-10 18:42:31 +02005980
5981 ASSERT_WDEV_LOCK(wdev);
Johannes Berg2a519312009-02-10 21:25:55 +01005982
Eric W. Biederman15e47302012-09-07 20:12:54 +00005983 hdr = nl80211hdr_put(msg, NETLINK_CB(cb->skb).portid, seq, flags,
Johannes Berg2a519312009-02-10 21:25:55 +01005984 NL80211_CMD_NEW_SCAN_RESULTS);
5985 if (!hdr)
5986 return -1;
5987
Johannes Berg9720bb32011-06-21 09:45:33 +02005988 genl_dump_check_consistent(cb, hdr, &nl80211_fam);
5989
Johannes Berg97990a02013-04-19 01:02:55 +02005990 if (nla_put_u32(msg, NL80211_ATTR_GENERATION, rdev->bss_generation))
5991 goto nla_put_failure;
5992 if (wdev->netdev &&
David S. Miller9360ffd2012-03-29 04:41:26 -04005993 nla_put_u32(msg, NL80211_ATTR_IFINDEX, wdev->netdev->ifindex))
5994 goto nla_put_failure;
Johannes Berg97990a02013-04-19 01:02:55 +02005995 if (nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)))
5996 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01005997
5998 bss = nla_nest_start(msg, NL80211_ATTR_BSS);
5999 if (!bss)
6000 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04006001 if ((!is_zero_ether_addr(res->bssid) &&
Johannes Berg9caf0362012-11-29 01:25:20 +01006002 nla_put(msg, NL80211_BSS_BSSID, ETH_ALEN, res->bssid)))
David S. Miller9360ffd2012-03-29 04:41:26 -04006003 goto nla_put_failure;
Johannes Berg9caf0362012-11-29 01:25:20 +01006004
6005 rcu_read_lock();
6006 ies = rcu_dereference(res->ies);
Johannes Berg8cef2c92013-02-05 16:54:31 +01006007 if (ies) {
6008 if (nla_put_u64(msg, NL80211_BSS_TSF, ies->tsf))
6009 goto fail_unlock_rcu;
6010 tsf = true;
6011 if (ies->len && nla_put(msg, NL80211_BSS_INFORMATION_ELEMENTS,
6012 ies->len, ies->data))
6013 goto fail_unlock_rcu;
Johannes Berg9caf0362012-11-29 01:25:20 +01006014 }
6015 ies = rcu_dereference(res->beacon_ies);
Johannes Berg8cef2c92013-02-05 16:54:31 +01006016 if (ies) {
6017 if (!tsf && nla_put_u64(msg, NL80211_BSS_TSF, ies->tsf))
6018 goto fail_unlock_rcu;
6019 if (ies->len && nla_put(msg, NL80211_BSS_BEACON_IES,
6020 ies->len, ies->data))
6021 goto fail_unlock_rcu;
Johannes Berg9caf0362012-11-29 01:25:20 +01006022 }
6023 rcu_read_unlock();
6024
David S. Miller9360ffd2012-03-29 04:41:26 -04006025 if (res->beacon_interval &&
6026 nla_put_u16(msg, NL80211_BSS_BEACON_INTERVAL, res->beacon_interval))
6027 goto nla_put_failure;
6028 if (nla_put_u16(msg, NL80211_BSS_CAPABILITY, res->capability) ||
6029 nla_put_u32(msg, NL80211_BSS_FREQUENCY, res->channel->center_freq) ||
Simon Wunderlichdcd6eac2013-07-08 16:55:49 +02006030 nla_put_u32(msg, NL80211_BSS_CHAN_WIDTH, res->scan_width) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04006031 nla_put_u32(msg, NL80211_BSS_SEEN_MS_AGO,
6032 jiffies_to_msecs(jiffies - intbss->ts)))
6033 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01006034
Johannes Berg77965c92009-02-18 18:45:06 +01006035 switch (rdev->wiphy.signal_type) {
Johannes Berg2a519312009-02-10 21:25:55 +01006036 case CFG80211_SIGNAL_TYPE_MBM:
David S. Miller9360ffd2012-03-29 04:41:26 -04006037 if (nla_put_u32(msg, NL80211_BSS_SIGNAL_MBM, res->signal))
6038 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01006039 break;
6040 case CFG80211_SIGNAL_TYPE_UNSPEC:
David S. Miller9360ffd2012-03-29 04:41:26 -04006041 if (nla_put_u8(msg, NL80211_BSS_SIGNAL_UNSPEC, res->signal))
6042 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01006043 break;
6044 default:
6045 break;
6046 }
6047
Johannes Berg48ab9052009-07-10 18:42:31 +02006048 switch (wdev->iftype) {
Johannes Berg074ac8d2010-09-16 14:58:22 +02006049 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Berg48ab9052009-07-10 18:42:31 +02006050 case NL80211_IFTYPE_STATION:
David S. Miller9360ffd2012-03-29 04:41:26 -04006051 if (intbss == wdev->current_bss &&
6052 nla_put_u32(msg, NL80211_BSS_STATUS,
6053 NL80211_BSS_STATUS_ASSOCIATED))
6054 goto nla_put_failure;
Johannes Berg48ab9052009-07-10 18:42:31 +02006055 break;
6056 case NL80211_IFTYPE_ADHOC:
David S. Miller9360ffd2012-03-29 04:41:26 -04006057 if (intbss == wdev->current_bss &&
6058 nla_put_u32(msg, NL80211_BSS_STATUS,
6059 NL80211_BSS_STATUS_IBSS_JOINED))
6060 goto nla_put_failure;
Johannes Berg48ab9052009-07-10 18:42:31 +02006061 break;
6062 default:
6063 break;
6064 }
6065
Johannes Berg2a519312009-02-10 21:25:55 +01006066 nla_nest_end(msg, bss);
6067
6068 return genlmsg_end(msg, hdr);
6069
Johannes Berg8cef2c92013-02-05 16:54:31 +01006070 fail_unlock_rcu:
6071 rcu_read_unlock();
Johannes Berg2a519312009-02-10 21:25:55 +01006072 nla_put_failure:
6073 genlmsg_cancel(msg, hdr);
6074 return -EMSGSIZE;
6075}
6076
Johannes Berg97990a02013-04-19 01:02:55 +02006077static int nl80211_dump_scan(struct sk_buff *skb, struct netlink_callback *cb)
Johannes Berg2a519312009-02-10 21:25:55 +01006078{
Johannes Berg48ab9052009-07-10 18:42:31 +02006079 struct cfg80211_registered_device *rdev;
Johannes Berg2a519312009-02-10 21:25:55 +01006080 struct cfg80211_internal_bss *scan;
Johannes Berg48ab9052009-07-10 18:42:31 +02006081 struct wireless_dev *wdev;
Johannes Berg97990a02013-04-19 01:02:55 +02006082 int start = cb->args[2], idx = 0;
Johannes Berg2a519312009-02-10 21:25:55 +01006083 int err;
6084
Johannes Berg97990a02013-04-19 01:02:55 +02006085 err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev);
Johannes Berg67748892010-10-04 21:14:06 +02006086 if (err)
6087 return err;
Johannes Berg2a519312009-02-10 21:25:55 +01006088
Johannes Berg48ab9052009-07-10 18:42:31 +02006089 wdev_lock(wdev);
6090 spin_lock_bh(&rdev->bss_lock);
6091 cfg80211_bss_expire(rdev);
6092
Johannes Berg9720bb32011-06-21 09:45:33 +02006093 cb->seq = rdev->bss_generation;
6094
Johannes Berg48ab9052009-07-10 18:42:31 +02006095 list_for_each_entry(scan, &rdev->bss_list, list) {
Johannes Berg2a519312009-02-10 21:25:55 +01006096 if (++idx <= start)
6097 continue;
Johannes Berg9720bb32011-06-21 09:45:33 +02006098 if (nl80211_send_bss(skb, cb,
Johannes Berg2a519312009-02-10 21:25:55 +01006099 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Johannes Berg48ab9052009-07-10 18:42:31 +02006100 rdev, wdev, scan) < 0) {
Johannes Berg2a519312009-02-10 21:25:55 +01006101 idx--;
Johannes Berg67748892010-10-04 21:14:06 +02006102 break;
Johannes Berg2a519312009-02-10 21:25:55 +01006103 }
6104 }
6105
Johannes Berg48ab9052009-07-10 18:42:31 +02006106 spin_unlock_bh(&rdev->bss_lock);
6107 wdev_unlock(wdev);
Johannes Berg2a519312009-02-10 21:25:55 +01006108
Johannes Berg97990a02013-04-19 01:02:55 +02006109 cb->args[2] = idx;
6110 nl80211_finish_wdev_dump(rdev);
Johannes Berg2a519312009-02-10 21:25:55 +01006111
Johannes Berg67748892010-10-04 21:14:06 +02006112 return skb->len;
Johannes Berg2a519312009-02-10 21:25:55 +01006113}
6114
Eric W. Biederman15e47302012-09-07 20:12:54 +00006115static int nl80211_send_survey(struct sk_buff *msg, u32 portid, u32 seq,
Holger Schurig61fa7132009-11-11 12:25:40 +01006116 int flags, struct net_device *dev,
6117 struct survey_info *survey)
6118{
6119 void *hdr;
6120 struct nlattr *infoattr;
6121
Eric W. Biederman15e47302012-09-07 20:12:54 +00006122 hdr = nl80211hdr_put(msg, portid, seq, flags,
Holger Schurig61fa7132009-11-11 12:25:40 +01006123 NL80211_CMD_NEW_SURVEY_RESULTS);
6124 if (!hdr)
6125 return -ENOMEM;
6126
David S. Miller9360ffd2012-03-29 04:41:26 -04006127 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex))
6128 goto nla_put_failure;
Holger Schurig61fa7132009-11-11 12:25:40 +01006129
6130 infoattr = nla_nest_start(msg, NL80211_ATTR_SURVEY_INFO);
6131 if (!infoattr)
6132 goto nla_put_failure;
6133
David S. Miller9360ffd2012-03-29 04:41:26 -04006134 if (nla_put_u32(msg, NL80211_SURVEY_INFO_FREQUENCY,
6135 survey->channel->center_freq))
6136 goto nla_put_failure;
6137
6138 if ((survey->filled & SURVEY_INFO_NOISE_DBM) &&
6139 nla_put_u8(msg, NL80211_SURVEY_INFO_NOISE, survey->noise))
6140 goto nla_put_failure;
6141 if ((survey->filled & SURVEY_INFO_IN_USE) &&
6142 nla_put_flag(msg, NL80211_SURVEY_INFO_IN_USE))
6143 goto nla_put_failure;
6144 if ((survey->filled & SURVEY_INFO_CHANNEL_TIME) &&
6145 nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME,
6146 survey->channel_time))
6147 goto nla_put_failure;
6148 if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_BUSY) &&
6149 nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_BUSY,
6150 survey->channel_time_busy))
6151 goto nla_put_failure;
6152 if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_EXT_BUSY) &&
6153 nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_EXT_BUSY,
6154 survey->channel_time_ext_busy))
6155 goto nla_put_failure;
6156 if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_RX) &&
6157 nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_RX,
6158 survey->channel_time_rx))
6159 goto nla_put_failure;
6160 if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_TX) &&
6161 nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_TX,
6162 survey->channel_time_tx))
6163 goto nla_put_failure;
Holger Schurig61fa7132009-11-11 12:25:40 +01006164
6165 nla_nest_end(msg, infoattr);
6166
6167 return genlmsg_end(msg, hdr);
6168
6169 nla_put_failure:
6170 genlmsg_cancel(msg, hdr);
6171 return -EMSGSIZE;
6172}
6173
6174static int nl80211_dump_survey(struct sk_buff *skb,
6175 struct netlink_callback *cb)
6176{
6177 struct survey_info survey;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08006178 struct cfg80211_registered_device *rdev;
Johannes Berg97990a02013-04-19 01:02:55 +02006179 struct wireless_dev *wdev;
6180 int survey_idx = cb->args[2];
Holger Schurig61fa7132009-11-11 12:25:40 +01006181 int res;
6182
Zhao, Gang1b8ec872014-04-21 12:53:02 +08006183 res = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev);
Johannes Berg67748892010-10-04 21:14:06 +02006184 if (res)
6185 return res;
Holger Schurig61fa7132009-11-11 12:25:40 +01006186
Johannes Berg97990a02013-04-19 01:02:55 +02006187 if (!wdev->netdev) {
6188 res = -EINVAL;
6189 goto out_err;
6190 }
6191
Zhao, Gang1b8ec872014-04-21 12:53:02 +08006192 if (!rdev->ops->dump_survey) {
Holger Schurig61fa7132009-11-11 12:25:40 +01006193 res = -EOPNOTSUPP;
6194 goto out_err;
6195 }
6196
6197 while (1) {
Luis R. Rodriguez180cdc72011-05-27 07:24:02 -07006198 struct ieee80211_channel *chan;
6199
Zhao, Gang1b8ec872014-04-21 12:53:02 +08006200 res = rdev_dump_survey(rdev, wdev->netdev, survey_idx, &survey);
Holger Schurig61fa7132009-11-11 12:25:40 +01006201 if (res == -ENOENT)
6202 break;
6203 if (res)
6204 goto out_err;
6205
Luis R. Rodriguez180cdc72011-05-27 07:24:02 -07006206 /* Survey without a channel doesn't make sense */
6207 if (!survey.channel) {
6208 res = -EINVAL;
6209 goto out;
6210 }
6211
Zhao, Gang1b8ec872014-04-21 12:53:02 +08006212 chan = ieee80211_get_channel(&rdev->wiphy,
Luis R. Rodriguez180cdc72011-05-27 07:24:02 -07006213 survey.channel->center_freq);
6214 if (!chan || chan->flags & IEEE80211_CHAN_DISABLED) {
6215 survey_idx++;
6216 continue;
6217 }
6218
Holger Schurig61fa7132009-11-11 12:25:40 +01006219 if (nl80211_send_survey(skb,
Eric W. Biederman15e47302012-09-07 20:12:54 +00006220 NETLINK_CB(cb->skb).portid,
Holger Schurig61fa7132009-11-11 12:25:40 +01006221 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Johannes Berg97990a02013-04-19 01:02:55 +02006222 wdev->netdev, &survey) < 0)
Holger Schurig61fa7132009-11-11 12:25:40 +01006223 goto out;
6224 survey_idx++;
6225 }
6226
6227 out:
Johannes Berg97990a02013-04-19 01:02:55 +02006228 cb->args[2] = survey_idx;
Holger Schurig61fa7132009-11-11 12:25:40 +01006229 res = skb->len;
6230 out_err:
Zhao, Gang1b8ec872014-04-21 12:53:02 +08006231 nl80211_finish_wdev_dump(rdev);
Holger Schurig61fa7132009-11-11 12:25:40 +01006232 return res;
6233}
6234
Samuel Ortizb23aa672009-07-01 21:26:54 +02006235static bool nl80211_valid_wpa_versions(u32 wpa_versions)
6236{
6237 return !(wpa_versions & ~(NL80211_WPA_VERSION_1 |
6238 NL80211_WPA_VERSION_2));
6239}
6240
Jouni Malinen636a5d32009-03-19 13:39:22 +02006241static int nl80211_authenticate(struct sk_buff *skb, struct genl_info *info)
6242{
Johannes Berg4c476992010-10-04 21:36:35 +02006243 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6244 struct net_device *dev = info->user_ptr[1];
Johannes Berg19957bb2009-07-02 17:20:43 +02006245 struct ieee80211_channel *chan;
Jouni Malinene39e5b52012-09-30 19:29:39 +03006246 const u8 *bssid, *ssid, *ie = NULL, *sae_data = NULL;
6247 int err, ssid_len, ie_len = 0, sae_data_len = 0;
Johannes Berg19957bb2009-07-02 17:20:43 +02006248 enum nl80211_auth_type auth_type;
Johannes Bergfffd0932009-07-08 14:22:54 +02006249 struct key_parse key;
Jouni Malinend5cdfac2010-04-04 09:37:19 +03006250 bool local_state_change;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006251
Johannes Bergf4a11bb2009-03-27 12:40:28 +01006252 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
6253 return -EINVAL;
6254
6255 if (!info->attrs[NL80211_ATTR_MAC])
6256 return -EINVAL;
6257
Jouni Malinen17780922009-03-27 20:52:47 +02006258 if (!info->attrs[NL80211_ATTR_AUTH_TYPE])
6259 return -EINVAL;
6260
Johannes Berg19957bb2009-07-02 17:20:43 +02006261 if (!info->attrs[NL80211_ATTR_SSID])
6262 return -EINVAL;
6263
6264 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ])
6265 return -EINVAL;
6266
Johannes Bergfffd0932009-07-08 14:22:54 +02006267 err = nl80211_parse_key(info, &key);
6268 if (err)
6269 return err;
6270
6271 if (key.idx >= 0) {
Johannes Berge31b8212010-10-05 19:39:30 +02006272 if (key.type != -1 && key.type != NL80211_KEYTYPE_GROUP)
6273 return -EINVAL;
Johannes Bergfffd0932009-07-08 14:22:54 +02006274 if (!key.p.key || !key.p.key_len)
6275 return -EINVAL;
6276 if ((key.p.cipher != WLAN_CIPHER_SUITE_WEP40 ||
6277 key.p.key_len != WLAN_KEY_LEN_WEP40) &&
6278 (key.p.cipher != WLAN_CIPHER_SUITE_WEP104 ||
6279 key.p.key_len != WLAN_KEY_LEN_WEP104))
6280 return -EINVAL;
6281 if (key.idx > 4)
6282 return -EINVAL;
6283 } else {
6284 key.p.key_len = 0;
6285 key.p.key = NULL;
6286 }
6287
Johannes Bergafea0b72010-08-10 09:46:42 +02006288 if (key.idx >= 0) {
6289 int i;
6290 bool ok = false;
6291 for (i = 0; i < rdev->wiphy.n_cipher_suites; i++) {
6292 if (key.p.cipher == rdev->wiphy.cipher_suites[i]) {
6293 ok = true;
6294 break;
6295 }
6296 }
Johannes Berg4c476992010-10-04 21:36:35 +02006297 if (!ok)
6298 return -EINVAL;
Johannes Bergafea0b72010-08-10 09:46:42 +02006299 }
6300
Johannes Berg4c476992010-10-04 21:36:35 +02006301 if (!rdev->ops->auth)
6302 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006303
Johannes Berg074ac8d2010-09-16 14:58:22 +02006304 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02006305 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
6306 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02006307
Johannes Berg19957bb2009-07-02 17:20:43 +02006308 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen664834d2014-01-15 00:01:44 +02006309 chan = nl80211_get_valid_chan(&rdev->wiphy,
6310 info->attrs[NL80211_ATTR_WIPHY_FREQ]);
6311 if (!chan)
Johannes Berg4c476992010-10-04 21:36:35 +02006312 return -EINVAL;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006313
Johannes Berg19957bb2009-07-02 17:20:43 +02006314 ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
6315 ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
6316
6317 if (info->attrs[NL80211_ATTR_IE]) {
6318 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
6319 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
6320 }
6321
6322 auth_type = nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]);
Jouni Malinene39e5b52012-09-30 19:29:39 +03006323 if (!nl80211_valid_auth_type(rdev, auth_type, NL80211_CMD_AUTHENTICATE))
Johannes Berg4c476992010-10-04 21:36:35 +02006324 return -EINVAL;
Johannes Berg19957bb2009-07-02 17:20:43 +02006325
Jouni Malinene39e5b52012-09-30 19:29:39 +03006326 if (auth_type == NL80211_AUTHTYPE_SAE &&
6327 !info->attrs[NL80211_ATTR_SAE_DATA])
6328 return -EINVAL;
6329
6330 if (info->attrs[NL80211_ATTR_SAE_DATA]) {
6331 if (auth_type != NL80211_AUTHTYPE_SAE)
6332 return -EINVAL;
6333 sae_data = nla_data(info->attrs[NL80211_ATTR_SAE_DATA]);
6334 sae_data_len = nla_len(info->attrs[NL80211_ATTR_SAE_DATA]);
6335 /* need to include at least Auth Transaction and Status Code */
6336 if (sae_data_len < 4)
6337 return -EINVAL;
6338 }
6339
Jouni Malinend5cdfac2010-04-04 09:37:19 +03006340 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE];
6341
Johannes Berg95de8172012-01-20 13:55:25 +01006342 /*
6343 * Since we no longer track auth state, ignore
6344 * requests to only change local state.
6345 */
6346 if (local_state_change)
6347 return 0;
6348
Johannes Berg91bf9b22013-05-15 17:44:01 +02006349 wdev_lock(dev->ieee80211_ptr);
6350 err = cfg80211_mlme_auth(rdev, dev, chan, auth_type, bssid,
6351 ssid, ssid_len, ie, ie_len,
6352 key.p.key, key.p.key_len, key.idx,
6353 sae_data, sae_data_len);
6354 wdev_unlock(dev->ieee80211_ptr);
6355 return err;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006356}
6357
Johannes Bergc0692b82010-08-27 14:26:53 +03006358static int nl80211_crypto_settings(struct cfg80211_registered_device *rdev,
6359 struct genl_info *info,
Johannes Berg3dc27d22009-07-02 21:36:37 +02006360 struct cfg80211_crypto_settings *settings,
6361 int cipher_limit)
Samuel Ortizb23aa672009-07-01 21:26:54 +02006362{
Johannes Bergc0b2bbd2009-07-25 16:54:36 +02006363 memset(settings, 0, sizeof(*settings));
6364
Samuel Ortizb23aa672009-07-01 21:26:54 +02006365 settings->control_port = info->attrs[NL80211_ATTR_CONTROL_PORT];
6366
Johannes Bergc0692b82010-08-27 14:26:53 +03006367 if (info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]) {
6368 u16 proto;
6369 proto = nla_get_u16(
6370 info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]);
6371 settings->control_port_ethertype = cpu_to_be16(proto);
6372 if (!(rdev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) &&
6373 proto != ETH_P_PAE)
6374 return -EINVAL;
6375 if (info->attrs[NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT])
6376 settings->control_port_no_encrypt = true;
6377 } else
6378 settings->control_port_ethertype = cpu_to_be16(ETH_P_PAE);
6379
Samuel Ortizb23aa672009-07-01 21:26:54 +02006380 if (info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]) {
6381 void *data;
6382 int len, i;
6383
6384 data = nla_data(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]);
6385 len = nla_len(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]);
6386 settings->n_ciphers_pairwise = len / sizeof(u32);
6387
6388 if (len % sizeof(u32))
6389 return -EINVAL;
6390
Johannes Berg3dc27d22009-07-02 21:36:37 +02006391 if (settings->n_ciphers_pairwise > cipher_limit)
Samuel Ortizb23aa672009-07-01 21:26:54 +02006392 return -EINVAL;
6393
6394 memcpy(settings->ciphers_pairwise, data, len);
6395
6396 for (i = 0; i < settings->n_ciphers_pairwise; i++)
Jouni Malinen38ba3c52011-09-21 18:14:56 +03006397 if (!cfg80211_supported_cipher_suite(
6398 &rdev->wiphy,
Samuel Ortizb23aa672009-07-01 21:26:54 +02006399 settings->ciphers_pairwise[i]))
6400 return -EINVAL;
6401 }
6402
6403 if (info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]) {
6404 settings->cipher_group =
6405 nla_get_u32(info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]);
Jouni Malinen38ba3c52011-09-21 18:14:56 +03006406 if (!cfg80211_supported_cipher_suite(&rdev->wiphy,
6407 settings->cipher_group))
Samuel Ortizb23aa672009-07-01 21:26:54 +02006408 return -EINVAL;
6409 }
6410
6411 if (info->attrs[NL80211_ATTR_WPA_VERSIONS]) {
6412 settings->wpa_versions =
6413 nla_get_u32(info->attrs[NL80211_ATTR_WPA_VERSIONS]);
6414 if (!nl80211_valid_wpa_versions(settings->wpa_versions))
6415 return -EINVAL;
6416 }
6417
6418 if (info->attrs[NL80211_ATTR_AKM_SUITES]) {
6419 void *data;
Jouni Malinen6d302402011-09-21 18:11:33 +03006420 int len;
Samuel Ortizb23aa672009-07-01 21:26:54 +02006421
6422 data = nla_data(info->attrs[NL80211_ATTR_AKM_SUITES]);
6423 len = nla_len(info->attrs[NL80211_ATTR_AKM_SUITES]);
6424 settings->n_akm_suites = len / sizeof(u32);
6425
6426 if (len % sizeof(u32))
6427 return -EINVAL;
6428
Jouni Malinen1b9ca022011-09-21 16:13:07 +03006429 if (settings->n_akm_suites > NL80211_MAX_NR_AKM_SUITES)
6430 return -EINVAL;
6431
Samuel Ortizb23aa672009-07-01 21:26:54 +02006432 memcpy(settings->akm_suites, data, len);
Samuel Ortizb23aa672009-07-01 21:26:54 +02006433 }
6434
6435 return 0;
6436}
6437
Jouni Malinen636a5d32009-03-19 13:39:22 +02006438static int nl80211_associate(struct sk_buff *skb, struct genl_info *info)
6439{
Johannes Berg4c476992010-10-04 21:36:35 +02006440 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6441 struct net_device *dev = info->user_ptr[1];
Johannes Bergf444de02010-05-05 15:25:02 +02006442 struct ieee80211_channel *chan;
Johannes Bergf62fab72013-02-21 20:09:09 +01006443 struct cfg80211_assoc_request req = {};
6444 const u8 *bssid, *ssid;
6445 int err, ssid_len = 0;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006446
Johannes Bergf4a11bb2009-03-27 12:40:28 +01006447 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
6448 return -EINVAL;
6449
6450 if (!info->attrs[NL80211_ATTR_MAC] ||
Johannes Berg19957bb2009-07-02 17:20:43 +02006451 !info->attrs[NL80211_ATTR_SSID] ||
6452 !info->attrs[NL80211_ATTR_WIPHY_FREQ])
Johannes Bergf4a11bb2009-03-27 12:40:28 +01006453 return -EINVAL;
6454
Johannes Berg4c476992010-10-04 21:36:35 +02006455 if (!rdev->ops->assoc)
6456 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006457
Johannes Berg074ac8d2010-09-16 14:58:22 +02006458 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02006459 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
6460 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02006461
Johannes Berg19957bb2009-07-02 17:20:43 +02006462 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02006463
Jouni Malinen664834d2014-01-15 00:01:44 +02006464 chan = nl80211_get_valid_chan(&rdev->wiphy,
6465 info->attrs[NL80211_ATTR_WIPHY_FREQ]);
6466 if (!chan)
Johannes Berg4c476992010-10-04 21:36:35 +02006467 return -EINVAL;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006468
Johannes Berg19957bb2009-07-02 17:20:43 +02006469 ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
6470 ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02006471
6472 if (info->attrs[NL80211_ATTR_IE]) {
Johannes Bergf62fab72013-02-21 20:09:09 +01006473 req.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
6474 req.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02006475 }
6476
Jouni Malinendc6382c2009-05-06 22:09:37 +03006477 if (info->attrs[NL80211_ATTR_USE_MFP]) {
Johannes Berg4f5dadc2009-07-07 03:56:10 +02006478 enum nl80211_mfp mfp =
Jouni Malinendc6382c2009-05-06 22:09:37 +03006479 nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]);
Johannes Berg4f5dadc2009-07-07 03:56:10 +02006480 if (mfp == NL80211_MFP_REQUIRED)
Johannes Bergf62fab72013-02-21 20:09:09 +01006481 req.use_mfp = true;
Johannes Berg4c476992010-10-04 21:36:35 +02006482 else if (mfp != NL80211_MFP_NO)
6483 return -EINVAL;
Jouni Malinendc6382c2009-05-06 22:09:37 +03006484 }
6485
Johannes Berg3e5d7642009-07-07 14:37:26 +02006486 if (info->attrs[NL80211_ATTR_PREV_BSSID])
Johannes Bergf62fab72013-02-21 20:09:09 +01006487 req.prev_bssid = nla_data(info->attrs[NL80211_ATTR_PREV_BSSID]);
Johannes Berg3e5d7642009-07-07 14:37:26 +02006488
Ben Greear7e7c8922011-11-18 11:31:59 -08006489 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT]))
Johannes Bergf62fab72013-02-21 20:09:09 +01006490 req.flags |= ASSOC_REQ_DISABLE_HT;
Ben Greear7e7c8922011-11-18 11:31:59 -08006491
6492 if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
Johannes Bergf62fab72013-02-21 20:09:09 +01006493 memcpy(&req.ht_capa_mask,
6494 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]),
6495 sizeof(req.ht_capa_mask));
Ben Greear7e7c8922011-11-18 11:31:59 -08006496
6497 if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) {
Johannes Bergf62fab72013-02-21 20:09:09 +01006498 if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
Ben Greear7e7c8922011-11-18 11:31:59 -08006499 return -EINVAL;
Johannes Bergf62fab72013-02-21 20:09:09 +01006500 memcpy(&req.ht_capa,
6501 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]),
6502 sizeof(req.ht_capa));
Ben Greear7e7c8922011-11-18 11:31:59 -08006503 }
6504
Johannes Bergee2aca32013-02-21 17:36:01 +01006505 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_VHT]))
Johannes Bergf62fab72013-02-21 20:09:09 +01006506 req.flags |= ASSOC_REQ_DISABLE_VHT;
Johannes Bergee2aca32013-02-21 17:36:01 +01006507
6508 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK])
Johannes Bergf62fab72013-02-21 20:09:09 +01006509 memcpy(&req.vht_capa_mask,
6510 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]),
6511 sizeof(req.vht_capa_mask));
Johannes Bergee2aca32013-02-21 17:36:01 +01006512
6513 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) {
Johannes Bergf62fab72013-02-21 20:09:09 +01006514 if (!info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK])
Johannes Bergee2aca32013-02-21 17:36:01 +01006515 return -EINVAL;
Johannes Bergf62fab72013-02-21 20:09:09 +01006516 memcpy(&req.vht_capa,
6517 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]),
6518 sizeof(req.vht_capa));
Johannes Bergee2aca32013-02-21 17:36:01 +01006519 }
6520
Johannes Bergf62fab72013-02-21 20:09:09 +01006521 err = nl80211_crypto_settings(rdev, info, &req.crypto, 1);
Johannes Berg91bf9b22013-05-15 17:44:01 +02006522 if (!err) {
6523 wdev_lock(dev->ieee80211_ptr);
Johannes Bergf62fab72013-02-21 20:09:09 +01006524 err = cfg80211_mlme_assoc(rdev, dev, chan, bssid,
6525 ssid, ssid_len, &req);
Johannes Berg91bf9b22013-05-15 17:44:01 +02006526 wdev_unlock(dev->ieee80211_ptr);
6527 }
Jouni Malinen636a5d32009-03-19 13:39:22 +02006528
Jouni Malinen636a5d32009-03-19 13:39:22 +02006529 return err;
6530}
6531
6532static int nl80211_deauthenticate(struct sk_buff *skb, struct genl_info *info)
6533{
Johannes Berg4c476992010-10-04 21:36:35 +02006534 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6535 struct net_device *dev = info->user_ptr[1];
Johannes Berg19957bb2009-07-02 17:20:43 +02006536 const u8 *ie = NULL, *bssid;
Johannes Berg91bf9b22013-05-15 17:44:01 +02006537 int ie_len = 0, err;
Johannes Berg19957bb2009-07-02 17:20:43 +02006538 u16 reason_code;
Jouni Malinend5cdfac2010-04-04 09:37:19 +03006539 bool local_state_change;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006540
Johannes Bergf4a11bb2009-03-27 12:40:28 +01006541 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
6542 return -EINVAL;
6543
6544 if (!info->attrs[NL80211_ATTR_MAC])
6545 return -EINVAL;
6546
6547 if (!info->attrs[NL80211_ATTR_REASON_CODE])
6548 return -EINVAL;
6549
Johannes Berg4c476992010-10-04 21:36:35 +02006550 if (!rdev->ops->deauth)
6551 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006552
Johannes Berg074ac8d2010-09-16 14:58:22 +02006553 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02006554 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
6555 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02006556
Johannes Berg19957bb2009-07-02 17:20:43 +02006557 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02006558
Johannes Berg19957bb2009-07-02 17:20:43 +02006559 reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
6560 if (reason_code == 0) {
Johannes Bergf4a11bb2009-03-27 12:40:28 +01006561 /* Reason Code 0 is reserved */
Johannes Berg4c476992010-10-04 21:36:35 +02006562 return -EINVAL;
Jouni Malinen255e7372009-03-20 21:21:17 +02006563 }
Jouni Malinen636a5d32009-03-19 13:39:22 +02006564
6565 if (info->attrs[NL80211_ATTR_IE]) {
Johannes Berg19957bb2009-07-02 17:20:43 +02006566 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
6567 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02006568 }
6569
Jouni Malinend5cdfac2010-04-04 09:37:19 +03006570 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE];
6571
Johannes Berg91bf9b22013-05-15 17:44:01 +02006572 wdev_lock(dev->ieee80211_ptr);
6573 err = cfg80211_mlme_deauth(rdev, dev, bssid, ie, ie_len, reason_code,
6574 local_state_change);
6575 wdev_unlock(dev->ieee80211_ptr);
6576 return err;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006577}
6578
6579static int nl80211_disassociate(struct sk_buff *skb, struct genl_info *info)
6580{
Johannes Berg4c476992010-10-04 21:36:35 +02006581 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6582 struct net_device *dev = info->user_ptr[1];
Johannes Berg19957bb2009-07-02 17:20:43 +02006583 const u8 *ie = NULL, *bssid;
Johannes Berg91bf9b22013-05-15 17:44:01 +02006584 int ie_len = 0, err;
Johannes Berg19957bb2009-07-02 17:20:43 +02006585 u16 reason_code;
Jouni Malinend5cdfac2010-04-04 09:37:19 +03006586 bool local_state_change;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006587
Johannes Bergf4a11bb2009-03-27 12:40:28 +01006588 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
6589 return -EINVAL;
6590
6591 if (!info->attrs[NL80211_ATTR_MAC])
6592 return -EINVAL;
6593
6594 if (!info->attrs[NL80211_ATTR_REASON_CODE])
6595 return -EINVAL;
6596
Johannes Berg4c476992010-10-04 21:36:35 +02006597 if (!rdev->ops->disassoc)
6598 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006599
Johannes Berg074ac8d2010-09-16 14:58:22 +02006600 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02006601 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
6602 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02006603
Johannes Berg19957bb2009-07-02 17:20:43 +02006604 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02006605
Johannes Berg19957bb2009-07-02 17:20:43 +02006606 reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
6607 if (reason_code == 0) {
Johannes Bergf4a11bb2009-03-27 12:40:28 +01006608 /* Reason Code 0 is reserved */
Johannes Berg4c476992010-10-04 21:36:35 +02006609 return -EINVAL;
Jouni Malinen255e7372009-03-20 21:21:17 +02006610 }
Jouni Malinen636a5d32009-03-19 13:39:22 +02006611
6612 if (info->attrs[NL80211_ATTR_IE]) {
Johannes Berg19957bb2009-07-02 17:20:43 +02006613 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
6614 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02006615 }
6616
Jouni Malinend5cdfac2010-04-04 09:37:19 +03006617 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE];
6618
Johannes Berg91bf9b22013-05-15 17:44:01 +02006619 wdev_lock(dev->ieee80211_ptr);
6620 err = cfg80211_mlme_disassoc(rdev, dev, bssid, ie, ie_len, reason_code,
6621 local_state_change);
6622 wdev_unlock(dev->ieee80211_ptr);
6623 return err;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006624}
6625
Felix Fietkaudd5b4cc2010-11-22 20:58:24 +01006626static bool
6627nl80211_parse_mcast_rate(struct cfg80211_registered_device *rdev,
6628 int mcast_rate[IEEE80211_NUM_BANDS],
6629 int rateval)
6630{
6631 struct wiphy *wiphy = &rdev->wiphy;
6632 bool found = false;
6633 int band, i;
6634
6635 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
6636 struct ieee80211_supported_band *sband;
6637
6638 sband = wiphy->bands[band];
6639 if (!sband)
6640 continue;
6641
6642 for (i = 0; i < sband->n_bitrates; i++) {
6643 if (sband->bitrates[i].bitrate == rateval) {
6644 mcast_rate[band] = i + 1;
6645 found = true;
6646 break;
6647 }
6648 }
6649 }
6650
6651 return found;
6652}
6653
Johannes Berg04a773a2009-04-19 21:24:32 +02006654static int nl80211_join_ibss(struct sk_buff *skb, struct genl_info *info)
6655{
Johannes Berg4c476992010-10-04 21:36:35 +02006656 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6657 struct net_device *dev = info->user_ptr[1];
Johannes Berg04a773a2009-04-19 21:24:32 +02006658 struct cfg80211_ibss_params ibss;
6659 struct wiphy *wiphy;
Johannes Bergfffd0932009-07-08 14:22:54 +02006660 struct cfg80211_cached_keys *connkeys = NULL;
Johannes Berg04a773a2009-04-19 21:24:32 +02006661 int err;
6662
Johannes Berg8e30bc52009-04-22 17:45:38 +02006663 memset(&ibss, 0, sizeof(ibss));
6664
Johannes Berg04a773a2009-04-19 21:24:32 +02006665 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
6666 return -EINVAL;
6667
Johannes Berg683b6d32012-11-08 21:25:48 +01006668 if (!info->attrs[NL80211_ATTR_SSID] ||
Johannes Berg04a773a2009-04-19 21:24:32 +02006669 !nla_len(info->attrs[NL80211_ATTR_SSID]))
6670 return -EINVAL;
6671
Johannes Berg8e30bc52009-04-22 17:45:38 +02006672 ibss.beacon_interval = 100;
6673
6674 if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) {
6675 ibss.beacon_interval =
6676 nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]);
6677 if (ibss.beacon_interval < 1 || ibss.beacon_interval > 10000)
6678 return -EINVAL;
6679 }
6680
Johannes Berg4c476992010-10-04 21:36:35 +02006681 if (!rdev->ops->join_ibss)
6682 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02006683
Johannes Berg4c476992010-10-04 21:36:35 +02006684 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC)
6685 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02006686
Johannes Berg79c97e92009-07-07 03:56:12 +02006687 wiphy = &rdev->wiphy;
Johannes Berg04a773a2009-04-19 21:24:32 +02006688
Johannes Berg39193492011-09-16 13:45:25 +02006689 if (info->attrs[NL80211_ATTR_MAC]) {
Johannes Berg04a773a2009-04-19 21:24:32 +02006690 ibss.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Johannes Berg39193492011-09-16 13:45:25 +02006691
6692 if (!is_valid_ether_addr(ibss.bssid))
6693 return -EINVAL;
6694 }
Johannes Berg04a773a2009-04-19 21:24:32 +02006695 ibss.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
6696 ibss.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
6697
6698 if (info->attrs[NL80211_ATTR_IE]) {
6699 ibss.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
6700 ibss.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
6701 }
6702
Johannes Berg683b6d32012-11-08 21:25:48 +01006703 err = nl80211_parse_chandef(rdev, info, &ibss.chandef);
6704 if (err)
6705 return err;
Alexander Simon54858ee5b2011-11-30 16:56:32 +01006706
Ilan Peer174e0cd2014-02-23 09:13:01 +02006707 if (!cfg80211_reg_can_beacon(&rdev->wiphy, &ibss.chandef,
6708 NL80211_IFTYPE_ADHOC))
Alexander Simon54858ee5b2011-11-30 16:56:32 +01006709 return -EINVAL;
6710
Simon Wunderlich2f301ab2013-05-16 13:00:28 +02006711 switch (ibss.chandef.width) {
Simon Wunderlichbf372642013-07-08 16:55:58 +02006712 case NL80211_CHAN_WIDTH_5:
6713 case NL80211_CHAN_WIDTH_10:
Simon Wunderlich2f301ab2013-05-16 13:00:28 +02006714 case NL80211_CHAN_WIDTH_20_NOHT:
6715 break;
6716 case NL80211_CHAN_WIDTH_20:
6717 case NL80211_CHAN_WIDTH_40:
6718 if (rdev->wiphy.features & NL80211_FEATURE_HT_IBSS)
6719 break;
6720 default:
Johannes Bergdb9c64c2012-11-09 14:56:41 +01006721 return -EINVAL;
Simon Wunderlich2f301ab2013-05-16 13:00:28 +02006722 }
Johannes Bergdb9c64c2012-11-09 14:56:41 +01006723
Johannes Berg04a773a2009-04-19 21:24:32 +02006724 ibss.channel_fixed = !!info->attrs[NL80211_ATTR_FREQ_FIXED];
Johannes Bergfffd0932009-07-08 14:22:54 +02006725 ibss.privacy = !!info->attrs[NL80211_ATTR_PRIVACY];
Johannes Berg04a773a2009-04-19 21:24:32 +02006726
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03006727 if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) {
6728 u8 *rates =
6729 nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
6730 int n_rates =
6731 nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
6732 struct ieee80211_supported_band *sband =
Johannes Berg683b6d32012-11-08 21:25:48 +01006733 wiphy->bands[ibss.chandef.chan->band];
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03006734
Johannes Berg34850ab2011-07-18 18:08:35 +02006735 err = ieee80211_get_ratemask(sband, rates, n_rates,
6736 &ibss.basic_rates);
6737 if (err)
6738 return err;
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03006739 }
Felix Fietkaudd5b4cc2010-11-22 20:58:24 +01006740
Simon Wunderlich803768f2013-06-28 10:39:58 +02006741 if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
6742 memcpy(&ibss.ht_capa_mask,
6743 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]),
6744 sizeof(ibss.ht_capa_mask));
6745
6746 if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) {
6747 if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
6748 return -EINVAL;
6749 memcpy(&ibss.ht_capa,
6750 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]),
6751 sizeof(ibss.ht_capa));
6752 }
6753
Felix Fietkaudd5b4cc2010-11-22 20:58:24 +01006754 if (info->attrs[NL80211_ATTR_MCAST_RATE] &&
6755 !nl80211_parse_mcast_rate(rdev, ibss.mcast_rate,
6756 nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE])))
6757 return -EINVAL;
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03006758
Johannes Berg4c476992010-10-04 21:36:35 +02006759 if (ibss.privacy && info->attrs[NL80211_ATTR_KEYS]) {
Sujith Manoharande7044e2012-10-18 10:19:28 +05306760 bool no_ht = false;
6761
Johannes Berg4c476992010-10-04 21:36:35 +02006762 connkeys = nl80211_parse_connkeys(rdev,
Sujith Manoharande7044e2012-10-18 10:19:28 +05306763 info->attrs[NL80211_ATTR_KEYS],
6764 &no_ht);
Johannes Berg4c476992010-10-04 21:36:35 +02006765 if (IS_ERR(connkeys))
6766 return PTR_ERR(connkeys);
Sujith Manoharande7044e2012-10-18 10:19:28 +05306767
Johannes Berg3d9d1d62012-11-08 23:14:50 +01006768 if ((ibss.chandef.width != NL80211_CHAN_WIDTH_20_NOHT) &&
6769 no_ht) {
Sujith Manoharande7044e2012-10-18 10:19:28 +05306770 kfree(connkeys);
6771 return -EINVAL;
6772 }
Johannes Berg4c476992010-10-04 21:36:35 +02006773 }
Johannes Berg04a773a2009-04-19 21:24:32 +02006774
Antonio Quartulli267335d2012-01-31 20:25:47 +01006775 ibss.control_port =
6776 nla_get_flag(info->attrs[NL80211_ATTR_CONTROL_PORT]);
6777
Simon Wunderlich5336fa82013-10-07 18:41:05 +02006778 ibss.userspace_handles_dfs =
6779 nla_get_flag(info->attrs[NL80211_ATTR_HANDLE_DFS]);
6780
Johannes Berg4c476992010-10-04 21:36:35 +02006781 err = cfg80211_join_ibss(rdev, dev, &ibss, connkeys);
Johannes Bergfffd0932009-07-08 14:22:54 +02006782 if (err)
6783 kfree(connkeys);
Johannes Berg04a773a2009-04-19 21:24:32 +02006784 return err;
6785}
6786
6787static int nl80211_leave_ibss(struct sk_buff *skb, struct genl_info *info)
6788{
Johannes Berg4c476992010-10-04 21:36:35 +02006789 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6790 struct net_device *dev = info->user_ptr[1];
Johannes Berg04a773a2009-04-19 21:24:32 +02006791
Johannes Berg4c476992010-10-04 21:36:35 +02006792 if (!rdev->ops->leave_ibss)
6793 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02006794
Johannes Berg4c476992010-10-04 21:36:35 +02006795 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC)
6796 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02006797
Johannes Berg4c476992010-10-04 21:36:35 +02006798 return cfg80211_leave_ibss(rdev, dev, false);
Johannes Berg04a773a2009-04-19 21:24:32 +02006799}
6800
Antonio Quartullif4e583c2012-11-02 13:27:48 +01006801static int nl80211_set_mcast_rate(struct sk_buff *skb, struct genl_info *info)
6802{
6803 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6804 struct net_device *dev = info->user_ptr[1];
6805 int mcast_rate[IEEE80211_NUM_BANDS];
6806 u32 nla_rate;
6807 int err;
6808
6809 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC &&
6810 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
6811 return -EOPNOTSUPP;
6812
6813 if (!rdev->ops->set_mcast_rate)
6814 return -EOPNOTSUPP;
6815
6816 memset(mcast_rate, 0, sizeof(mcast_rate));
6817
6818 if (!info->attrs[NL80211_ATTR_MCAST_RATE])
6819 return -EINVAL;
6820
6821 nla_rate = nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]);
6822 if (!nl80211_parse_mcast_rate(rdev, mcast_rate, nla_rate))
6823 return -EINVAL;
6824
6825 err = rdev->ops->set_mcast_rate(&rdev->wiphy, dev, mcast_rate);
6826
6827 return err;
6828}
6829
Johannes Bergad7e7182013-11-13 13:37:47 +01006830static struct sk_buff *
6831__cfg80211_alloc_vendor_skb(struct cfg80211_registered_device *rdev,
6832 int approxlen, u32 portid, u32 seq,
6833 enum nl80211_commands cmd,
Johannes Berg567ffc32013-12-18 14:43:31 +01006834 enum nl80211_attrs attr,
6835 const struct nl80211_vendor_cmd_info *info,
6836 gfp_t gfp)
Johannes Bergad7e7182013-11-13 13:37:47 +01006837{
6838 struct sk_buff *skb;
6839 void *hdr;
6840 struct nlattr *data;
6841
6842 skb = nlmsg_new(approxlen + 100, gfp);
6843 if (!skb)
6844 return NULL;
6845
6846 hdr = nl80211hdr_put(skb, portid, seq, 0, cmd);
6847 if (!hdr) {
6848 kfree_skb(skb);
6849 return NULL;
6850 }
6851
6852 if (nla_put_u32(skb, NL80211_ATTR_WIPHY, rdev->wiphy_idx))
6853 goto nla_put_failure;
Johannes Berg567ffc32013-12-18 14:43:31 +01006854
6855 if (info) {
6856 if (nla_put_u32(skb, NL80211_ATTR_VENDOR_ID,
6857 info->vendor_id))
6858 goto nla_put_failure;
6859 if (nla_put_u32(skb, NL80211_ATTR_VENDOR_SUBCMD,
6860 info->subcmd))
6861 goto nla_put_failure;
6862 }
6863
Johannes Bergad7e7182013-11-13 13:37:47 +01006864 data = nla_nest_start(skb, attr);
6865
6866 ((void **)skb->cb)[0] = rdev;
6867 ((void **)skb->cb)[1] = hdr;
6868 ((void **)skb->cb)[2] = data;
6869
6870 return skb;
6871
6872 nla_put_failure:
6873 kfree_skb(skb);
6874 return NULL;
6875}
Antonio Quartullif4e583c2012-11-02 13:27:48 +01006876
Johannes Berge03ad6e2014-01-01 17:22:30 +01006877struct sk_buff *__cfg80211_alloc_event_skb(struct wiphy *wiphy,
6878 enum nl80211_commands cmd,
6879 enum nl80211_attrs attr,
6880 int vendor_event_idx,
6881 int approxlen, gfp_t gfp)
6882{
Zhao, Gangf26cbf42014-04-21 12:53:03 +08006883 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berge03ad6e2014-01-01 17:22:30 +01006884 const struct nl80211_vendor_cmd_info *info;
6885
6886 switch (cmd) {
6887 case NL80211_CMD_TESTMODE:
6888 if (WARN_ON(vendor_event_idx != -1))
6889 return NULL;
6890 info = NULL;
6891 break;
6892 case NL80211_CMD_VENDOR:
6893 if (WARN_ON(vendor_event_idx < 0 ||
6894 vendor_event_idx >= wiphy->n_vendor_events))
6895 return NULL;
6896 info = &wiphy->vendor_events[vendor_event_idx];
6897 break;
6898 default:
6899 WARN_ON(1);
6900 return NULL;
6901 }
6902
6903 return __cfg80211_alloc_vendor_skb(rdev, approxlen, 0, 0,
6904 cmd, attr, info, gfp);
6905}
6906EXPORT_SYMBOL(__cfg80211_alloc_event_skb);
6907
6908void __cfg80211_send_event_skb(struct sk_buff *skb, gfp_t gfp)
6909{
6910 struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0];
6911 void *hdr = ((void **)skb->cb)[1];
6912 struct nlattr *data = ((void **)skb->cb)[2];
6913 enum nl80211_multicast_groups mcgrp = NL80211_MCGRP_TESTMODE;
6914
6915 nla_nest_end(skb, data);
6916 genlmsg_end(skb, hdr);
6917
6918 if (data->nla_type == NL80211_ATTR_VENDOR_DATA)
6919 mcgrp = NL80211_MCGRP_VENDOR;
6920
6921 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), skb, 0,
6922 mcgrp, gfp);
6923}
6924EXPORT_SYMBOL(__cfg80211_send_event_skb);
6925
Johannes Bergaff89a92009-07-01 21:26:51 +02006926#ifdef CONFIG_NL80211_TESTMODE
Johannes Bergaff89a92009-07-01 21:26:51 +02006927static int nl80211_testmode_do(struct sk_buff *skb, struct genl_info *info)
6928{
Johannes Berg4c476992010-10-04 21:36:35 +02006929 struct cfg80211_registered_device *rdev = info->user_ptr[0];
David Spinadelfc73f112013-07-31 18:04:15 +03006930 struct wireless_dev *wdev =
6931 __cfg80211_wdev_from_attrs(genl_info_net(info), info->attrs);
Johannes Bergaff89a92009-07-01 21:26:51 +02006932 int err;
6933
David Spinadelfc73f112013-07-31 18:04:15 +03006934 if (!rdev->ops->testmode_cmd)
6935 return -EOPNOTSUPP;
6936
6937 if (IS_ERR(wdev)) {
6938 err = PTR_ERR(wdev);
6939 if (err != -EINVAL)
6940 return err;
6941 wdev = NULL;
6942 } else if (wdev->wiphy != &rdev->wiphy) {
6943 return -EINVAL;
6944 }
6945
Johannes Bergaff89a92009-07-01 21:26:51 +02006946 if (!info->attrs[NL80211_ATTR_TESTDATA])
6947 return -EINVAL;
6948
Johannes Bergad7e7182013-11-13 13:37:47 +01006949 rdev->cur_cmd_info = info;
David Spinadelfc73f112013-07-31 18:04:15 +03006950 err = rdev_testmode_cmd(rdev, wdev,
Johannes Bergaff89a92009-07-01 21:26:51 +02006951 nla_data(info->attrs[NL80211_ATTR_TESTDATA]),
6952 nla_len(info->attrs[NL80211_ATTR_TESTDATA]));
Johannes Bergad7e7182013-11-13 13:37:47 +01006953 rdev->cur_cmd_info = NULL;
Johannes Bergaff89a92009-07-01 21:26:51 +02006954
Johannes Bergaff89a92009-07-01 21:26:51 +02006955 return err;
6956}
6957
Wey-Yi Guy71063f02011-05-20 09:05:54 -07006958static int nl80211_testmode_dump(struct sk_buff *skb,
6959 struct netlink_callback *cb)
6960{
Johannes Berg00918d32011-12-13 17:22:05 +01006961 struct cfg80211_registered_device *rdev;
Wey-Yi Guy71063f02011-05-20 09:05:54 -07006962 int err;
6963 long phy_idx;
6964 void *data = NULL;
6965 int data_len = 0;
6966
Johannes Berg5fe231e2013-05-08 21:45:15 +02006967 rtnl_lock();
6968
Wey-Yi Guy71063f02011-05-20 09:05:54 -07006969 if (cb->args[0]) {
6970 /*
6971 * 0 is a valid index, but not valid for args[0],
6972 * so we need to offset by 1.
6973 */
6974 phy_idx = cb->args[0] - 1;
6975 } else {
6976 err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize,
6977 nl80211_fam.attrbuf, nl80211_fam.maxattr,
6978 nl80211_policy);
6979 if (err)
Johannes Berg5fe231e2013-05-08 21:45:15 +02006980 goto out_err;
Johannes Berg00918d32011-12-13 17:22:05 +01006981
Johannes Berg2bd7e352012-06-15 14:23:16 +02006982 rdev = __cfg80211_rdev_from_attrs(sock_net(skb->sk),
6983 nl80211_fam.attrbuf);
6984 if (IS_ERR(rdev)) {
Johannes Berg5fe231e2013-05-08 21:45:15 +02006985 err = PTR_ERR(rdev);
6986 goto out_err;
Johannes Berg00918d32011-12-13 17:22:05 +01006987 }
Johannes Berg2bd7e352012-06-15 14:23:16 +02006988 phy_idx = rdev->wiphy_idx;
6989 rdev = NULL;
Johannes Berg2bd7e352012-06-15 14:23:16 +02006990
Wey-Yi Guy71063f02011-05-20 09:05:54 -07006991 if (nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA])
6992 cb->args[1] =
6993 (long)nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA];
6994 }
6995
6996 if (cb->args[1]) {
6997 data = nla_data((void *)cb->args[1]);
6998 data_len = nla_len((void *)cb->args[1]);
6999 }
7000
Johannes Berg00918d32011-12-13 17:22:05 +01007001 rdev = cfg80211_rdev_by_wiphy_idx(phy_idx);
7002 if (!rdev) {
Johannes Berg5fe231e2013-05-08 21:45:15 +02007003 err = -ENOENT;
7004 goto out_err;
Wey-Yi Guy71063f02011-05-20 09:05:54 -07007005 }
Wey-Yi Guy71063f02011-05-20 09:05:54 -07007006
Johannes Berg00918d32011-12-13 17:22:05 +01007007 if (!rdev->ops->testmode_dump) {
Wey-Yi Guy71063f02011-05-20 09:05:54 -07007008 err = -EOPNOTSUPP;
7009 goto out_err;
7010 }
7011
7012 while (1) {
Eric W. Biederman15e47302012-09-07 20:12:54 +00007013 void *hdr = nl80211hdr_put(skb, NETLINK_CB(cb->skb).portid,
Wey-Yi Guy71063f02011-05-20 09:05:54 -07007014 cb->nlh->nlmsg_seq, NLM_F_MULTI,
7015 NL80211_CMD_TESTMODE);
7016 struct nlattr *tmdata;
7017
Dan Carpentercb35fba2013-08-14 14:50:01 +03007018 if (!hdr)
7019 break;
7020
David S. Miller9360ffd2012-03-29 04:41:26 -04007021 if (nla_put_u32(skb, NL80211_ATTR_WIPHY, phy_idx)) {
Wey-Yi Guy71063f02011-05-20 09:05:54 -07007022 genlmsg_cancel(skb, hdr);
7023 break;
7024 }
7025
7026 tmdata = nla_nest_start(skb, NL80211_ATTR_TESTDATA);
7027 if (!tmdata) {
7028 genlmsg_cancel(skb, hdr);
7029 break;
7030 }
Hila Gonene35e4d22012-06-27 17:19:42 +03007031 err = rdev_testmode_dump(rdev, skb, cb, data, data_len);
Wey-Yi Guy71063f02011-05-20 09:05:54 -07007032 nla_nest_end(skb, tmdata);
7033
7034 if (err == -ENOBUFS || err == -ENOENT) {
7035 genlmsg_cancel(skb, hdr);
7036 break;
7037 } else if (err) {
7038 genlmsg_cancel(skb, hdr);
7039 goto out_err;
7040 }
7041
7042 genlmsg_end(skb, hdr);
7043 }
7044
7045 err = skb->len;
7046 /* see above */
7047 cb->args[0] = phy_idx + 1;
7048 out_err:
Johannes Berg5fe231e2013-05-08 21:45:15 +02007049 rtnl_unlock();
Wey-Yi Guy71063f02011-05-20 09:05:54 -07007050 return err;
7051}
Johannes Bergaff89a92009-07-01 21:26:51 +02007052#endif
7053
Samuel Ortizb23aa672009-07-01 21:26:54 +02007054static int nl80211_connect(struct sk_buff *skb, struct genl_info *info)
7055{
Johannes Berg4c476992010-10-04 21:36:35 +02007056 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7057 struct net_device *dev = info->user_ptr[1];
Samuel Ortizb23aa672009-07-01 21:26:54 +02007058 struct cfg80211_connect_params connect;
7059 struct wiphy *wiphy;
Johannes Bergfffd0932009-07-08 14:22:54 +02007060 struct cfg80211_cached_keys *connkeys = NULL;
Samuel Ortizb23aa672009-07-01 21:26:54 +02007061 int err;
7062
7063 memset(&connect, 0, sizeof(connect));
7064
7065 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
7066 return -EINVAL;
7067
7068 if (!info->attrs[NL80211_ATTR_SSID] ||
7069 !nla_len(info->attrs[NL80211_ATTR_SSID]))
7070 return -EINVAL;
7071
7072 if (info->attrs[NL80211_ATTR_AUTH_TYPE]) {
7073 connect.auth_type =
7074 nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]);
Jouni Malinene39e5b52012-09-30 19:29:39 +03007075 if (!nl80211_valid_auth_type(rdev, connect.auth_type,
7076 NL80211_CMD_CONNECT))
Samuel Ortizb23aa672009-07-01 21:26:54 +02007077 return -EINVAL;
7078 } else
7079 connect.auth_type = NL80211_AUTHTYPE_AUTOMATIC;
7080
7081 connect.privacy = info->attrs[NL80211_ATTR_PRIVACY];
7082
Johannes Bergc0692b82010-08-27 14:26:53 +03007083 err = nl80211_crypto_settings(rdev, info, &connect.crypto,
Johannes Berg3dc27d22009-07-02 21:36:37 +02007084 NL80211_MAX_NR_CIPHER_SUITES);
Samuel Ortizb23aa672009-07-01 21:26:54 +02007085 if (err)
7086 return err;
Samuel Ortizb23aa672009-07-01 21:26:54 +02007087
Johannes Berg074ac8d2010-09-16 14:58:22 +02007088 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02007089 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
7090 return -EOPNOTSUPP;
Samuel Ortizb23aa672009-07-01 21:26:54 +02007091
Johannes Berg79c97e92009-07-07 03:56:12 +02007092 wiphy = &rdev->wiphy;
Samuel Ortizb23aa672009-07-01 21:26:54 +02007093
Bala Shanmugam4486ea92012-03-07 17:27:12 +05307094 connect.bg_scan_period = -1;
7095 if (info->attrs[NL80211_ATTR_BG_SCAN_PERIOD] &&
7096 (wiphy->flags & WIPHY_FLAG_SUPPORTS_FW_ROAM)) {
7097 connect.bg_scan_period =
7098 nla_get_u16(info->attrs[NL80211_ATTR_BG_SCAN_PERIOD]);
7099 }
7100
Samuel Ortizb23aa672009-07-01 21:26:54 +02007101 if (info->attrs[NL80211_ATTR_MAC])
7102 connect.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen1df4a512014-01-15 00:00:47 +02007103 else if (info->attrs[NL80211_ATTR_MAC_HINT])
7104 connect.bssid_hint =
7105 nla_data(info->attrs[NL80211_ATTR_MAC_HINT]);
Samuel Ortizb23aa672009-07-01 21:26:54 +02007106 connect.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
7107 connect.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
7108
7109 if (info->attrs[NL80211_ATTR_IE]) {
7110 connect.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
7111 connect.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
7112 }
7113
Jouni Malinencee00a92013-01-15 17:15:57 +02007114 if (info->attrs[NL80211_ATTR_USE_MFP]) {
7115 connect.mfp = nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]);
7116 if (connect.mfp != NL80211_MFP_REQUIRED &&
7117 connect.mfp != NL80211_MFP_NO)
7118 return -EINVAL;
7119 } else {
7120 connect.mfp = NL80211_MFP_NO;
7121 }
7122
Samuel Ortizb23aa672009-07-01 21:26:54 +02007123 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
Jouni Malinen664834d2014-01-15 00:01:44 +02007124 connect.channel = nl80211_get_valid_chan(
7125 wiphy, info->attrs[NL80211_ATTR_WIPHY_FREQ]);
7126 if (!connect.channel)
Johannes Berg4c476992010-10-04 21:36:35 +02007127 return -EINVAL;
Jouni Malinen1df4a512014-01-15 00:00:47 +02007128 } else if (info->attrs[NL80211_ATTR_WIPHY_FREQ_HINT]) {
Jouni Malinen664834d2014-01-15 00:01:44 +02007129 connect.channel_hint = nl80211_get_valid_chan(
7130 wiphy, info->attrs[NL80211_ATTR_WIPHY_FREQ_HINT]);
7131 if (!connect.channel_hint)
Jouni Malinen1df4a512014-01-15 00:00:47 +02007132 return -EINVAL;
Samuel Ortizb23aa672009-07-01 21:26:54 +02007133 }
7134
Johannes Bergfffd0932009-07-08 14:22:54 +02007135 if (connect.privacy && info->attrs[NL80211_ATTR_KEYS]) {
7136 connkeys = nl80211_parse_connkeys(rdev,
Sujith Manoharande7044e2012-10-18 10:19:28 +05307137 info->attrs[NL80211_ATTR_KEYS], NULL);
Johannes Berg4c476992010-10-04 21:36:35 +02007138 if (IS_ERR(connkeys))
7139 return PTR_ERR(connkeys);
Johannes Bergfffd0932009-07-08 14:22:54 +02007140 }
7141
Ben Greear7e7c8922011-11-18 11:31:59 -08007142 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT]))
7143 connect.flags |= ASSOC_REQ_DISABLE_HT;
7144
7145 if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
7146 memcpy(&connect.ht_capa_mask,
7147 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]),
7148 sizeof(connect.ht_capa_mask));
7149
7150 if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) {
Wei Yongjunb4e4f472012-09-02 21:41:04 +08007151 if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) {
7152 kfree(connkeys);
Ben Greear7e7c8922011-11-18 11:31:59 -08007153 return -EINVAL;
Wei Yongjunb4e4f472012-09-02 21:41:04 +08007154 }
Ben Greear7e7c8922011-11-18 11:31:59 -08007155 memcpy(&connect.ht_capa,
7156 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]),
7157 sizeof(connect.ht_capa));
7158 }
7159
Johannes Bergee2aca32013-02-21 17:36:01 +01007160 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_VHT]))
7161 connect.flags |= ASSOC_REQ_DISABLE_VHT;
7162
7163 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK])
7164 memcpy(&connect.vht_capa_mask,
7165 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]),
7166 sizeof(connect.vht_capa_mask));
7167
7168 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) {
7169 if (!info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) {
7170 kfree(connkeys);
7171 return -EINVAL;
7172 }
7173 memcpy(&connect.vht_capa,
7174 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]),
7175 sizeof(connect.vht_capa));
7176 }
7177
Johannes Berg83739b02013-05-15 17:44:01 +02007178 wdev_lock(dev->ieee80211_ptr);
7179 err = cfg80211_connect(rdev, dev, &connect, connkeys, NULL);
7180 wdev_unlock(dev->ieee80211_ptr);
Johannes Bergfffd0932009-07-08 14:22:54 +02007181 if (err)
7182 kfree(connkeys);
Samuel Ortizb23aa672009-07-01 21:26:54 +02007183 return err;
7184}
7185
7186static int nl80211_disconnect(struct sk_buff *skb, struct genl_info *info)
7187{
Johannes Berg4c476992010-10-04 21:36:35 +02007188 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7189 struct net_device *dev = info->user_ptr[1];
Samuel Ortizb23aa672009-07-01 21:26:54 +02007190 u16 reason;
Johannes Berg83739b02013-05-15 17:44:01 +02007191 int ret;
Samuel Ortizb23aa672009-07-01 21:26:54 +02007192
7193 if (!info->attrs[NL80211_ATTR_REASON_CODE])
7194 reason = WLAN_REASON_DEAUTH_LEAVING;
7195 else
7196 reason = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
7197
7198 if (reason == 0)
7199 return -EINVAL;
7200
Johannes Berg074ac8d2010-09-16 14:58:22 +02007201 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02007202 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
7203 return -EOPNOTSUPP;
Samuel Ortizb23aa672009-07-01 21:26:54 +02007204
Johannes Berg83739b02013-05-15 17:44:01 +02007205 wdev_lock(dev->ieee80211_ptr);
7206 ret = cfg80211_disconnect(rdev, dev, reason, true);
7207 wdev_unlock(dev->ieee80211_ptr);
7208 return ret;
Samuel Ortizb23aa672009-07-01 21:26:54 +02007209}
7210
Johannes Berg463d0182009-07-14 00:33:35 +02007211static int nl80211_wiphy_netns(struct sk_buff *skb, struct genl_info *info)
7212{
Johannes Berg4c476992010-10-04 21:36:35 +02007213 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg463d0182009-07-14 00:33:35 +02007214 struct net *net;
7215 int err;
7216 u32 pid;
7217
7218 if (!info->attrs[NL80211_ATTR_PID])
7219 return -EINVAL;
7220
7221 pid = nla_get_u32(info->attrs[NL80211_ATTR_PID]);
7222
Johannes Berg463d0182009-07-14 00:33:35 +02007223 net = get_net_ns_by_pid(pid);
Johannes Berg4c476992010-10-04 21:36:35 +02007224 if (IS_ERR(net))
7225 return PTR_ERR(net);
Johannes Berg463d0182009-07-14 00:33:35 +02007226
7227 err = 0;
7228
7229 /* check if anything to do */
Johannes Berg4c476992010-10-04 21:36:35 +02007230 if (!net_eq(wiphy_net(&rdev->wiphy), net))
7231 err = cfg80211_switch_netns(rdev, net);
Johannes Berg463d0182009-07-14 00:33:35 +02007232
Johannes Berg463d0182009-07-14 00:33:35 +02007233 put_net(net);
Johannes Berg463d0182009-07-14 00:33:35 +02007234 return err;
7235}
7236
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007237static int nl80211_setdel_pmksa(struct sk_buff *skb, struct genl_info *info)
7238{
Johannes Berg4c476992010-10-04 21:36:35 +02007239 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007240 int (*rdev_ops)(struct wiphy *wiphy, struct net_device *dev,
7241 struct cfg80211_pmksa *pmksa) = NULL;
Johannes Berg4c476992010-10-04 21:36:35 +02007242 struct net_device *dev = info->user_ptr[1];
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007243 struct cfg80211_pmksa pmksa;
7244
7245 memset(&pmksa, 0, sizeof(struct cfg80211_pmksa));
7246
7247 if (!info->attrs[NL80211_ATTR_MAC])
7248 return -EINVAL;
7249
7250 if (!info->attrs[NL80211_ATTR_PMKID])
7251 return -EINVAL;
7252
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007253 pmksa.pmkid = nla_data(info->attrs[NL80211_ATTR_PMKID]);
7254 pmksa.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
7255
Johannes Berg074ac8d2010-09-16 14:58:22 +02007256 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02007257 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
7258 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007259
7260 switch (info->genlhdr->cmd) {
7261 case NL80211_CMD_SET_PMKSA:
7262 rdev_ops = rdev->ops->set_pmksa;
7263 break;
7264 case NL80211_CMD_DEL_PMKSA:
7265 rdev_ops = rdev->ops->del_pmksa;
7266 break;
7267 default:
7268 WARN_ON(1);
7269 break;
7270 }
7271
Johannes Berg4c476992010-10-04 21:36:35 +02007272 if (!rdev_ops)
7273 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007274
Johannes Berg4c476992010-10-04 21:36:35 +02007275 return rdev_ops(&rdev->wiphy, dev, &pmksa);
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007276}
7277
7278static int nl80211_flush_pmksa(struct sk_buff *skb, struct genl_info *info)
7279{
Johannes Berg4c476992010-10-04 21:36:35 +02007280 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7281 struct net_device *dev = info->user_ptr[1];
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007282
Johannes Berg074ac8d2010-09-16 14:58:22 +02007283 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02007284 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
7285 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007286
Johannes Berg4c476992010-10-04 21:36:35 +02007287 if (!rdev->ops->flush_pmksa)
7288 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007289
Hila Gonene35e4d22012-06-27 17:19:42 +03007290 return rdev_flush_pmksa(rdev, dev);
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007291}
7292
Arik Nemtsov109086c2011-09-28 14:12:50 +03007293static int nl80211_tdls_mgmt(struct sk_buff *skb, struct genl_info *info)
7294{
7295 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7296 struct net_device *dev = info->user_ptr[1];
7297 u8 action_code, dialog_token;
Sunil Dutt Undekaridf942e72014-02-20 16:22:09 +05307298 u32 peer_capability = 0;
Arik Nemtsov109086c2011-09-28 14:12:50 +03007299 u16 status_code;
7300 u8 *peer;
7301
7302 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) ||
7303 !rdev->ops->tdls_mgmt)
7304 return -EOPNOTSUPP;
7305
7306 if (!info->attrs[NL80211_ATTR_TDLS_ACTION] ||
7307 !info->attrs[NL80211_ATTR_STATUS_CODE] ||
7308 !info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN] ||
7309 !info->attrs[NL80211_ATTR_IE] ||
7310 !info->attrs[NL80211_ATTR_MAC])
7311 return -EINVAL;
7312
7313 peer = nla_data(info->attrs[NL80211_ATTR_MAC]);
7314 action_code = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_ACTION]);
7315 status_code = nla_get_u16(info->attrs[NL80211_ATTR_STATUS_CODE]);
7316 dialog_token = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN]);
Sunil Dutt Undekaridf942e72014-02-20 16:22:09 +05307317 if (info->attrs[NL80211_ATTR_TDLS_PEER_CAPABILITY])
7318 peer_capability =
7319 nla_get_u32(info->attrs[NL80211_ATTR_TDLS_PEER_CAPABILITY]);
Arik Nemtsov109086c2011-09-28 14:12:50 +03007320
Hila Gonene35e4d22012-06-27 17:19:42 +03007321 return rdev_tdls_mgmt(rdev, dev, peer, action_code,
Sunil Dutt Undekaridf942e72014-02-20 16:22:09 +05307322 dialog_token, status_code, peer_capability,
Hila Gonene35e4d22012-06-27 17:19:42 +03007323 nla_data(info->attrs[NL80211_ATTR_IE]),
7324 nla_len(info->attrs[NL80211_ATTR_IE]));
Arik Nemtsov109086c2011-09-28 14:12:50 +03007325}
7326
7327static int nl80211_tdls_oper(struct sk_buff *skb, struct genl_info *info)
7328{
7329 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7330 struct net_device *dev = info->user_ptr[1];
7331 enum nl80211_tdls_operation operation;
7332 u8 *peer;
7333
7334 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) ||
7335 !rdev->ops->tdls_oper)
7336 return -EOPNOTSUPP;
7337
7338 if (!info->attrs[NL80211_ATTR_TDLS_OPERATION] ||
7339 !info->attrs[NL80211_ATTR_MAC])
7340 return -EINVAL;
7341
7342 operation = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_OPERATION]);
7343 peer = nla_data(info->attrs[NL80211_ATTR_MAC]);
7344
Hila Gonene35e4d22012-06-27 17:19:42 +03007345 return rdev_tdls_oper(rdev, dev, peer, operation);
Arik Nemtsov109086c2011-09-28 14:12:50 +03007346}
7347
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007348static int nl80211_remain_on_channel(struct sk_buff *skb,
7349 struct genl_info *info)
7350{
Johannes Berg4c476992010-10-04 21:36:35 +02007351 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02007352 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg683b6d32012-11-08 21:25:48 +01007353 struct cfg80211_chan_def chandef;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007354 struct sk_buff *msg;
7355 void *hdr;
7356 u64 cookie;
Johannes Berg683b6d32012-11-08 21:25:48 +01007357 u32 duration;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007358 int err;
7359
7360 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] ||
7361 !info->attrs[NL80211_ATTR_DURATION])
7362 return -EINVAL;
7363
7364 duration = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]);
7365
Johannes Berg7c4ef712011-11-18 15:33:48 +01007366 if (!rdev->ops->remain_on_channel ||
7367 !(rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL))
Johannes Berg4c476992010-10-04 21:36:35 +02007368 return -EOPNOTSUPP;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007369
Johannes Bergebf348f2012-06-01 12:50:54 +02007370 /*
7371 * We should be on that channel for at least a minimum amount of
7372 * time (10ms) but no longer than the driver supports.
7373 */
7374 if (duration < NL80211_MIN_REMAIN_ON_CHANNEL_TIME ||
7375 duration > rdev->wiphy.max_remain_on_channel_duration)
7376 return -EINVAL;
7377
Johannes Berg683b6d32012-11-08 21:25:48 +01007378 err = nl80211_parse_chandef(rdev, info, &chandef);
7379 if (err)
7380 return err;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007381
7382 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02007383 if (!msg)
7384 return -ENOMEM;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007385
Eric W. Biederman15e47302012-09-07 20:12:54 +00007386 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007387 NL80211_CMD_REMAIN_ON_CHANNEL);
Dan Carpentercb35fba2013-08-14 14:50:01 +03007388 if (!hdr) {
7389 err = -ENOBUFS;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007390 goto free_msg;
7391 }
7392
Johannes Berg683b6d32012-11-08 21:25:48 +01007393 err = rdev_remain_on_channel(rdev, wdev, chandef.chan,
7394 duration, &cookie);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007395
7396 if (err)
7397 goto free_msg;
7398
David S. Miller9360ffd2012-03-29 04:41:26 -04007399 if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie))
7400 goto nla_put_failure;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007401
7402 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02007403
7404 return genlmsg_reply(msg, info);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007405
7406 nla_put_failure:
7407 err = -ENOBUFS;
7408 free_msg:
7409 nlmsg_free(msg);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007410 return err;
7411}
7412
7413static int nl80211_cancel_remain_on_channel(struct sk_buff *skb,
7414 struct genl_info *info)
7415{
Johannes Berg4c476992010-10-04 21:36:35 +02007416 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02007417 struct wireless_dev *wdev = info->user_ptr[1];
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007418 u64 cookie;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007419
7420 if (!info->attrs[NL80211_ATTR_COOKIE])
7421 return -EINVAL;
7422
Johannes Berg4c476992010-10-04 21:36:35 +02007423 if (!rdev->ops->cancel_remain_on_channel)
7424 return -EOPNOTSUPP;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007425
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007426 cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]);
7427
Hila Gonene35e4d22012-06-27 17:19:42 +03007428 return rdev_cancel_remain_on_channel(rdev, wdev, cookie);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007429}
7430
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007431static u32 rateset_to_mask(struct ieee80211_supported_band *sband,
7432 u8 *rates, u8 rates_len)
7433{
7434 u8 i;
7435 u32 mask = 0;
7436
7437 for (i = 0; i < rates_len; i++) {
7438 int rate = (rates[i] & 0x7f) * 5;
7439 int ridx;
7440 for (ridx = 0; ridx < sband->n_bitrates; ridx++) {
7441 struct ieee80211_rate *srate =
7442 &sband->bitrates[ridx];
7443 if (rate == srate->bitrate) {
7444 mask |= 1 << ridx;
7445 break;
7446 }
7447 }
7448 if (ridx == sband->n_bitrates)
7449 return 0; /* rate not found */
7450 }
7451
7452 return mask;
7453}
7454
Simon Wunderlich24db78c2012-01-28 17:25:32 +01007455static bool ht_rateset_to_mask(struct ieee80211_supported_band *sband,
7456 u8 *rates, u8 rates_len,
7457 u8 mcs[IEEE80211_HT_MCS_MASK_LEN])
7458{
7459 u8 i;
7460
7461 memset(mcs, 0, IEEE80211_HT_MCS_MASK_LEN);
7462
7463 for (i = 0; i < rates_len; i++) {
7464 int ridx, rbit;
7465
7466 ridx = rates[i] / 8;
7467 rbit = BIT(rates[i] % 8);
7468
7469 /* check validity */
Dan Carpenter910570b52012-02-01 10:42:11 +03007470 if ((ridx < 0) || (ridx >= IEEE80211_HT_MCS_MASK_LEN))
Simon Wunderlich24db78c2012-01-28 17:25:32 +01007471 return false;
7472
7473 /* check availability */
7474 if (sband->ht_cap.mcs.rx_mask[ridx] & rbit)
7475 mcs[ridx] |= rbit;
7476 else
7477 return false;
7478 }
7479
7480 return true;
7481}
7482
Janusz Dziedzic204e35a2013-12-05 20:42:58 +01007483static u16 vht_mcs_map_to_mcs_mask(u8 vht_mcs_map)
7484{
7485 u16 mcs_mask = 0;
7486
7487 switch (vht_mcs_map) {
7488 case IEEE80211_VHT_MCS_NOT_SUPPORTED:
7489 break;
7490 case IEEE80211_VHT_MCS_SUPPORT_0_7:
7491 mcs_mask = 0x00FF;
7492 break;
7493 case IEEE80211_VHT_MCS_SUPPORT_0_8:
7494 mcs_mask = 0x01FF;
7495 break;
7496 case IEEE80211_VHT_MCS_SUPPORT_0_9:
7497 mcs_mask = 0x03FF;
7498 break;
7499 default:
7500 break;
7501 }
7502
7503 return mcs_mask;
7504}
7505
7506static void vht_build_mcs_mask(u16 vht_mcs_map,
7507 u16 vht_mcs_mask[NL80211_VHT_NSS_MAX])
7508{
7509 u8 nss;
7510
7511 for (nss = 0; nss < NL80211_VHT_NSS_MAX; nss++) {
7512 vht_mcs_mask[nss] = vht_mcs_map_to_mcs_mask(vht_mcs_map & 0x03);
7513 vht_mcs_map >>= 2;
7514 }
7515}
7516
7517static bool vht_set_mcs_mask(struct ieee80211_supported_band *sband,
7518 struct nl80211_txrate_vht *txrate,
7519 u16 mcs[NL80211_VHT_NSS_MAX])
7520{
7521 u16 tx_mcs_map = le16_to_cpu(sband->vht_cap.vht_mcs.tx_mcs_map);
7522 u16 tx_mcs_mask[NL80211_VHT_NSS_MAX] = {};
7523 u8 i;
7524
7525 if (!sband->vht_cap.vht_supported)
7526 return false;
7527
7528 memset(mcs, 0, sizeof(u16) * NL80211_VHT_NSS_MAX);
7529
7530 /* Build vht_mcs_mask from VHT capabilities */
7531 vht_build_mcs_mask(tx_mcs_map, tx_mcs_mask);
7532
7533 for (i = 0; i < NL80211_VHT_NSS_MAX; i++) {
7534 if ((tx_mcs_mask[i] & txrate->mcs[i]) == txrate->mcs[i])
7535 mcs[i] = txrate->mcs[i];
7536 else
7537 return false;
7538 }
7539
7540 return true;
7541}
7542
Alexey Dobriyanb54452b2010-02-18 08:14:31 +00007543static const struct nla_policy nl80211_txattr_policy[NL80211_TXRATE_MAX + 1] = {
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007544 [NL80211_TXRATE_LEGACY] = { .type = NLA_BINARY,
7545 .len = NL80211_MAX_SUPP_RATES },
Janusz Dziedzicd1e33e62013-12-05 10:02:15 +01007546 [NL80211_TXRATE_HT] = { .type = NLA_BINARY,
7547 .len = NL80211_MAX_SUPP_HT_RATES },
Janusz Dziedzic204e35a2013-12-05 20:42:58 +01007548 [NL80211_TXRATE_VHT] = { .len = sizeof(struct nl80211_txrate_vht)},
Janusz Dziedzic0b9323f2014-01-08 08:46:02 +01007549 [NL80211_TXRATE_GI] = { .type = NLA_U8 },
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007550};
7551
7552static int nl80211_set_tx_bitrate_mask(struct sk_buff *skb,
7553 struct genl_info *info)
7554{
7555 struct nlattr *tb[NL80211_TXRATE_MAX + 1];
Johannes Berg4c476992010-10-04 21:36:35 +02007556 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007557 struct cfg80211_bitrate_mask mask;
Johannes Berg4c476992010-10-04 21:36:35 +02007558 int rem, i;
7559 struct net_device *dev = info->user_ptr[1];
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007560 struct nlattr *tx_rates;
7561 struct ieee80211_supported_band *sband;
Janusz Dziedzic204e35a2013-12-05 20:42:58 +01007562 u16 vht_tx_mcs_map;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007563
Johannes Berg4c476992010-10-04 21:36:35 +02007564 if (!rdev->ops->set_bitrate_mask)
7565 return -EOPNOTSUPP;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007566
7567 memset(&mask, 0, sizeof(mask));
7568 /* Default to all rates enabled */
7569 for (i = 0; i < IEEE80211_NUM_BANDS; i++) {
7570 sband = rdev->wiphy.bands[i];
Janusz Dziedzic78693032013-12-03 09:50:44 +01007571
7572 if (!sband)
7573 continue;
7574
7575 mask.control[i].legacy = (1 << sband->n_bitrates) - 1;
Janusz Dziedzicd1e33e62013-12-05 10:02:15 +01007576 memcpy(mask.control[i].ht_mcs,
Janusz Dziedzic78693032013-12-03 09:50:44 +01007577 sband->ht_cap.mcs.rx_mask,
Janusz Dziedzicd1e33e62013-12-05 10:02:15 +01007578 sizeof(mask.control[i].ht_mcs));
Janusz Dziedzic204e35a2013-12-05 20:42:58 +01007579
7580 if (!sband->vht_cap.vht_supported)
7581 continue;
7582
7583 vht_tx_mcs_map = le16_to_cpu(sband->vht_cap.vht_mcs.tx_mcs_map);
7584 vht_build_mcs_mask(vht_tx_mcs_map, mask.control[i].vht_mcs);
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007585 }
7586
Janusz Dziedzicb9243ab2013-12-05 10:02:14 +01007587 /* if no rates are given set it back to the defaults */
7588 if (!info->attrs[NL80211_ATTR_TX_RATES])
7589 goto out;
7590
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007591 /*
7592 * The nested attribute uses enum nl80211_band as the index. This maps
7593 * directly to the enum ieee80211_band values used in cfg80211.
7594 */
Simon Wunderlich24db78c2012-01-28 17:25:32 +01007595 BUILD_BUG_ON(NL80211_MAX_SUPP_HT_RATES > IEEE80211_HT_MCS_MASK_LEN * 8);
Johannes Bergae811e22014-01-24 10:17:47 +01007596 nla_for_each_nested(tx_rates, info->attrs[NL80211_ATTR_TX_RATES], rem) {
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007597 enum ieee80211_band band = nla_type(tx_rates);
Johannes Bergae811e22014-01-24 10:17:47 +01007598 int err;
7599
Johannes Berg4c476992010-10-04 21:36:35 +02007600 if (band < 0 || band >= IEEE80211_NUM_BANDS)
7601 return -EINVAL;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007602 sband = rdev->wiphy.bands[band];
Johannes Berg4c476992010-10-04 21:36:35 +02007603 if (sband == NULL)
7604 return -EINVAL;
Johannes Bergae811e22014-01-24 10:17:47 +01007605 err = nla_parse(tb, NL80211_TXRATE_MAX, nla_data(tx_rates),
7606 nla_len(tx_rates), nl80211_txattr_policy);
7607 if (err)
7608 return err;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007609 if (tb[NL80211_TXRATE_LEGACY]) {
7610 mask.control[band].legacy = rateset_to_mask(
7611 sband,
7612 nla_data(tb[NL80211_TXRATE_LEGACY]),
7613 nla_len(tb[NL80211_TXRATE_LEGACY]));
Bala Shanmugam218d2e22012-04-20 19:12:58 +05307614 if ((mask.control[band].legacy == 0) &&
7615 nla_len(tb[NL80211_TXRATE_LEGACY]))
7616 return -EINVAL;
Simon Wunderlich24db78c2012-01-28 17:25:32 +01007617 }
Janusz Dziedzicd1e33e62013-12-05 10:02:15 +01007618 if (tb[NL80211_TXRATE_HT]) {
Simon Wunderlich24db78c2012-01-28 17:25:32 +01007619 if (!ht_rateset_to_mask(
7620 sband,
Janusz Dziedzicd1e33e62013-12-05 10:02:15 +01007621 nla_data(tb[NL80211_TXRATE_HT]),
7622 nla_len(tb[NL80211_TXRATE_HT]),
7623 mask.control[band].ht_mcs))
Simon Wunderlich24db78c2012-01-28 17:25:32 +01007624 return -EINVAL;
7625 }
Janusz Dziedzic204e35a2013-12-05 20:42:58 +01007626 if (tb[NL80211_TXRATE_VHT]) {
7627 if (!vht_set_mcs_mask(
7628 sband,
7629 nla_data(tb[NL80211_TXRATE_VHT]),
7630 mask.control[band].vht_mcs))
7631 return -EINVAL;
7632 }
Janusz Dziedzic0b9323f2014-01-08 08:46:02 +01007633 if (tb[NL80211_TXRATE_GI]) {
7634 mask.control[band].gi =
7635 nla_get_u8(tb[NL80211_TXRATE_GI]);
7636 if (mask.control[band].gi > NL80211_TXRATE_FORCE_LGI)
7637 return -EINVAL;
7638 }
Simon Wunderlich24db78c2012-01-28 17:25:32 +01007639
7640 if (mask.control[band].legacy == 0) {
Janusz Dziedzic204e35a2013-12-05 20:42:58 +01007641 /* don't allow empty legacy rates if HT or VHT
7642 * are not even supported.
7643 */
7644 if (!(rdev->wiphy.bands[band]->ht_cap.ht_supported ||
7645 rdev->wiphy.bands[band]->vht_cap.vht_supported))
Simon Wunderlich24db78c2012-01-28 17:25:32 +01007646 return -EINVAL;
7647
7648 for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++)
Janusz Dziedzicd1e33e62013-12-05 10:02:15 +01007649 if (mask.control[band].ht_mcs[i])
Janusz Dziedzic204e35a2013-12-05 20:42:58 +01007650 goto out;
7651
7652 for (i = 0; i < NL80211_VHT_NSS_MAX; i++)
7653 if (mask.control[band].vht_mcs[i])
7654 goto out;
Simon Wunderlich24db78c2012-01-28 17:25:32 +01007655
7656 /* legacy and mcs rates may not be both empty */
Janusz Dziedzic204e35a2013-12-05 20:42:58 +01007657 return -EINVAL;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007658 }
7659 }
7660
Janusz Dziedzicb9243ab2013-12-05 10:02:14 +01007661out:
Hila Gonene35e4d22012-06-27 17:19:42 +03007662 return rdev_set_bitrate_mask(rdev, dev, NULL, &mask);
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007663}
7664
Johannes Berg2e161f72010-08-12 15:38:38 +02007665static int nl80211_register_mgmt(struct sk_buff *skb, struct genl_info *info)
Jouni Malinen026331c2010-02-15 12:53:10 +02007666{
Johannes Berg4c476992010-10-04 21:36:35 +02007667 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02007668 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg2e161f72010-08-12 15:38:38 +02007669 u16 frame_type = IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_ACTION;
Jouni Malinen026331c2010-02-15 12:53:10 +02007670
7671 if (!info->attrs[NL80211_ATTR_FRAME_MATCH])
7672 return -EINVAL;
7673
Johannes Berg2e161f72010-08-12 15:38:38 +02007674 if (info->attrs[NL80211_ATTR_FRAME_TYPE])
7675 frame_type = nla_get_u16(info->attrs[NL80211_ATTR_FRAME_TYPE]);
Jouni Malinen026331c2010-02-15 12:53:10 +02007676
Johannes Berg71bbc992012-06-15 15:30:18 +02007677 switch (wdev->iftype) {
7678 case NL80211_IFTYPE_STATION:
7679 case NL80211_IFTYPE_ADHOC:
7680 case NL80211_IFTYPE_P2P_CLIENT:
7681 case NL80211_IFTYPE_AP:
7682 case NL80211_IFTYPE_AP_VLAN:
7683 case NL80211_IFTYPE_MESH_POINT:
7684 case NL80211_IFTYPE_P2P_GO:
Johannes Berg98104fde2012-06-16 00:19:54 +02007685 case NL80211_IFTYPE_P2P_DEVICE:
Johannes Berg71bbc992012-06-15 15:30:18 +02007686 break;
7687 default:
Johannes Berg4c476992010-10-04 21:36:35 +02007688 return -EOPNOTSUPP;
Johannes Berg71bbc992012-06-15 15:30:18 +02007689 }
Jouni Malinen026331c2010-02-15 12:53:10 +02007690
7691 /* not much point in registering if we can't reply */
Johannes Berg4c476992010-10-04 21:36:35 +02007692 if (!rdev->ops->mgmt_tx)
7693 return -EOPNOTSUPP;
Jouni Malinen026331c2010-02-15 12:53:10 +02007694
Eric W. Biederman15e47302012-09-07 20:12:54 +00007695 return cfg80211_mlme_register_mgmt(wdev, info->snd_portid, frame_type,
Jouni Malinen026331c2010-02-15 12:53:10 +02007696 nla_data(info->attrs[NL80211_ATTR_FRAME_MATCH]),
7697 nla_len(info->attrs[NL80211_ATTR_FRAME_MATCH]));
Jouni Malinen026331c2010-02-15 12:53:10 +02007698}
7699
Johannes Berg2e161f72010-08-12 15:38:38 +02007700static int nl80211_tx_mgmt(struct sk_buff *skb, struct genl_info *info)
Jouni Malinen026331c2010-02-15 12:53:10 +02007701{
Johannes Berg4c476992010-10-04 21:36:35 +02007702 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02007703 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg683b6d32012-11-08 21:25:48 +01007704 struct cfg80211_chan_def chandef;
Jouni Malinen026331c2010-02-15 12:53:10 +02007705 int err;
Johannes Bergd64d3732011-11-10 09:44:46 +01007706 void *hdr = NULL;
Jouni Malinen026331c2010-02-15 12:53:10 +02007707 u64 cookie;
Johannes Berge247bd902011-11-04 11:18:21 +01007708 struct sk_buff *msg = NULL;
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02007709 struct cfg80211_mgmt_tx_params params = {
7710 .dont_wait_for_ack =
7711 info->attrs[NL80211_ATTR_DONT_WAIT_FOR_ACK],
7712 };
Jouni Malinen026331c2010-02-15 12:53:10 +02007713
Johannes Berg683b6d32012-11-08 21:25:48 +01007714 if (!info->attrs[NL80211_ATTR_FRAME])
Jouni Malinen026331c2010-02-15 12:53:10 +02007715 return -EINVAL;
7716
Johannes Berg4c476992010-10-04 21:36:35 +02007717 if (!rdev->ops->mgmt_tx)
7718 return -EOPNOTSUPP;
Jouni Malinen026331c2010-02-15 12:53:10 +02007719
Johannes Berg71bbc992012-06-15 15:30:18 +02007720 switch (wdev->iftype) {
Antonio Quartulliea141b752013-06-11 14:20:03 +02007721 case NL80211_IFTYPE_P2P_DEVICE:
7722 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ])
7723 return -EINVAL;
Johannes Berg71bbc992012-06-15 15:30:18 +02007724 case NL80211_IFTYPE_STATION:
7725 case NL80211_IFTYPE_ADHOC:
7726 case NL80211_IFTYPE_P2P_CLIENT:
7727 case NL80211_IFTYPE_AP:
7728 case NL80211_IFTYPE_AP_VLAN:
7729 case NL80211_IFTYPE_MESH_POINT:
7730 case NL80211_IFTYPE_P2P_GO:
7731 break;
7732 default:
Johannes Berg4c476992010-10-04 21:36:35 +02007733 return -EOPNOTSUPP;
Johannes Berg71bbc992012-06-15 15:30:18 +02007734 }
Jouni Malinen026331c2010-02-15 12:53:10 +02007735
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007736 if (info->attrs[NL80211_ATTR_DURATION]) {
Johannes Berg7c4ef712011-11-18 15:33:48 +01007737 if (!(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX))
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007738 return -EINVAL;
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02007739 params.wait = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]);
Johannes Bergebf348f2012-06-01 12:50:54 +02007740
7741 /*
7742 * We should wait on the channel for at least a minimum amount
7743 * of time (10ms) but no longer than the driver supports.
7744 */
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02007745 if (params.wait < NL80211_MIN_REMAIN_ON_CHANNEL_TIME ||
7746 params.wait > rdev->wiphy.max_remain_on_channel_duration)
Johannes Bergebf348f2012-06-01 12:50:54 +02007747 return -EINVAL;
7748
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007749 }
7750
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02007751 params.offchan = info->attrs[NL80211_ATTR_OFFCHANNEL_TX_OK];
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007752
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02007753 if (params.offchan && !(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX))
Johannes Berg7c4ef712011-11-18 15:33:48 +01007754 return -EINVAL;
7755
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02007756 params.no_cck = nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]);
Rajkumar Manoharane9f935e2011-09-25 14:53:30 +05307757
Antonio Quartulliea141b752013-06-11 14:20:03 +02007758 /* get the channel if any has been specified, otherwise pass NULL to
7759 * the driver. The latter will use the current one
7760 */
7761 chandef.chan = NULL;
7762 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
7763 err = nl80211_parse_chandef(rdev, info, &chandef);
7764 if (err)
7765 return err;
7766 }
7767
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02007768 if (!chandef.chan && params.offchan)
Antonio Quartulliea141b752013-06-11 14:20:03 +02007769 return -EINVAL;
Jouni Malinen026331c2010-02-15 12:53:10 +02007770
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02007771 if (!params.dont_wait_for_ack) {
Johannes Berge247bd902011-11-04 11:18:21 +01007772 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
7773 if (!msg)
7774 return -ENOMEM;
Jouni Malinen026331c2010-02-15 12:53:10 +02007775
Eric W. Biederman15e47302012-09-07 20:12:54 +00007776 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berge247bd902011-11-04 11:18:21 +01007777 NL80211_CMD_FRAME);
Dan Carpentercb35fba2013-08-14 14:50:01 +03007778 if (!hdr) {
7779 err = -ENOBUFS;
Johannes Berge247bd902011-11-04 11:18:21 +01007780 goto free_msg;
7781 }
Jouni Malinen026331c2010-02-15 12:53:10 +02007782 }
Johannes Berge247bd902011-11-04 11:18:21 +01007783
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02007784 params.buf = nla_data(info->attrs[NL80211_ATTR_FRAME]);
7785 params.len = nla_len(info->attrs[NL80211_ATTR_FRAME]);
7786 params.chan = chandef.chan;
7787 err = cfg80211_mlme_mgmt_tx(rdev, wdev, &params, &cookie);
Jouni Malinen026331c2010-02-15 12:53:10 +02007788 if (err)
7789 goto free_msg;
7790
Johannes Berge247bd902011-11-04 11:18:21 +01007791 if (msg) {
David S. Miller9360ffd2012-03-29 04:41:26 -04007792 if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie))
7793 goto nla_put_failure;
Jouni Malinen026331c2010-02-15 12:53:10 +02007794
Johannes Berge247bd902011-11-04 11:18:21 +01007795 genlmsg_end(msg, hdr);
7796 return genlmsg_reply(msg, info);
7797 }
7798
7799 return 0;
Jouni Malinen026331c2010-02-15 12:53:10 +02007800
7801 nla_put_failure:
7802 err = -ENOBUFS;
7803 free_msg:
7804 nlmsg_free(msg);
Jouni Malinen026331c2010-02-15 12:53:10 +02007805 return err;
7806}
7807
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007808static int nl80211_tx_mgmt_cancel_wait(struct sk_buff *skb, struct genl_info *info)
7809{
7810 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02007811 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007812 u64 cookie;
7813
7814 if (!info->attrs[NL80211_ATTR_COOKIE])
7815 return -EINVAL;
7816
7817 if (!rdev->ops->mgmt_tx_cancel_wait)
7818 return -EOPNOTSUPP;
7819
Johannes Berg71bbc992012-06-15 15:30:18 +02007820 switch (wdev->iftype) {
7821 case NL80211_IFTYPE_STATION:
7822 case NL80211_IFTYPE_ADHOC:
7823 case NL80211_IFTYPE_P2P_CLIENT:
7824 case NL80211_IFTYPE_AP:
7825 case NL80211_IFTYPE_AP_VLAN:
7826 case NL80211_IFTYPE_P2P_GO:
Johannes Berg98104fde2012-06-16 00:19:54 +02007827 case NL80211_IFTYPE_P2P_DEVICE:
Johannes Berg71bbc992012-06-15 15:30:18 +02007828 break;
7829 default:
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007830 return -EOPNOTSUPP;
Johannes Berg71bbc992012-06-15 15:30:18 +02007831 }
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007832
7833 cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]);
7834
Hila Gonene35e4d22012-06-27 17:19:42 +03007835 return rdev_mgmt_tx_cancel_wait(rdev, wdev, cookie);
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007836}
7837
Kalle Valoffb9eb32010-02-17 17:58:10 +02007838static int nl80211_set_power_save(struct sk_buff *skb, struct genl_info *info)
7839{
Johannes Berg4c476992010-10-04 21:36:35 +02007840 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Kalle Valoffb9eb32010-02-17 17:58:10 +02007841 struct wireless_dev *wdev;
Johannes Berg4c476992010-10-04 21:36:35 +02007842 struct net_device *dev = info->user_ptr[1];
Kalle Valoffb9eb32010-02-17 17:58:10 +02007843 u8 ps_state;
7844 bool state;
7845 int err;
7846
Johannes Berg4c476992010-10-04 21:36:35 +02007847 if (!info->attrs[NL80211_ATTR_PS_STATE])
7848 return -EINVAL;
Kalle Valoffb9eb32010-02-17 17:58:10 +02007849
7850 ps_state = nla_get_u32(info->attrs[NL80211_ATTR_PS_STATE]);
7851
Johannes Berg4c476992010-10-04 21:36:35 +02007852 if (ps_state != NL80211_PS_DISABLED && ps_state != NL80211_PS_ENABLED)
7853 return -EINVAL;
Kalle Valoffb9eb32010-02-17 17:58:10 +02007854
7855 wdev = dev->ieee80211_ptr;
7856
Johannes Berg4c476992010-10-04 21:36:35 +02007857 if (!rdev->ops->set_power_mgmt)
7858 return -EOPNOTSUPP;
Kalle Valoffb9eb32010-02-17 17:58:10 +02007859
7860 state = (ps_state == NL80211_PS_ENABLED) ? true : false;
7861
7862 if (state == wdev->ps)
Johannes Berg4c476992010-10-04 21:36:35 +02007863 return 0;
Kalle Valoffb9eb32010-02-17 17:58:10 +02007864
Hila Gonene35e4d22012-06-27 17:19:42 +03007865 err = rdev_set_power_mgmt(rdev, dev, state, wdev->ps_timeout);
Johannes Berg4c476992010-10-04 21:36:35 +02007866 if (!err)
7867 wdev->ps = state;
Kalle Valoffb9eb32010-02-17 17:58:10 +02007868 return err;
7869}
7870
7871static int nl80211_get_power_save(struct sk_buff *skb, struct genl_info *info)
7872{
Johannes Berg4c476992010-10-04 21:36:35 +02007873 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Kalle Valoffb9eb32010-02-17 17:58:10 +02007874 enum nl80211_ps_state ps_state;
7875 struct wireless_dev *wdev;
Johannes Berg4c476992010-10-04 21:36:35 +02007876 struct net_device *dev = info->user_ptr[1];
Kalle Valoffb9eb32010-02-17 17:58:10 +02007877 struct sk_buff *msg;
7878 void *hdr;
7879 int err;
7880
Kalle Valoffb9eb32010-02-17 17:58:10 +02007881 wdev = dev->ieee80211_ptr;
7882
Johannes Berg4c476992010-10-04 21:36:35 +02007883 if (!rdev->ops->set_power_mgmt)
7884 return -EOPNOTSUPP;
Kalle Valoffb9eb32010-02-17 17:58:10 +02007885
7886 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02007887 if (!msg)
7888 return -ENOMEM;
Kalle Valoffb9eb32010-02-17 17:58:10 +02007889
Eric W. Biederman15e47302012-09-07 20:12:54 +00007890 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Kalle Valoffb9eb32010-02-17 17:58:10 +02007891 NL80211_CMD_GET_POWER_SAVE);
7892 if (!hdr) {
Johannes Berg4c476992010-10-04 21:36:35 +02007893 err = -ENOBUFS;
Kalle Valoffb9eb32010-02-17 17:58:10 +02007894 goto free_msg;
7895 }
7896
7897 if (wdev->ps)
7898 ps_state = NL80211_PS_ENABLED;
7899 else
7900 ps_state = NL80211_PS_DISABLED;
7901
David S. Miller9360ffd2012-03-29 04:41:26 -04007902 if (nla_put_u32(msg, NL80211_ATTR_PS_STATE, ps_state))
7903 goto nla_put_failure;
Kalle Valoffb9eb32010-02-17 17:58:10 +02007904
7905 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02007906 return genlmsg_reply(msg, info);
Kalle Valoffb9eb32010-02-17 17:58:10 +02007907
Johannes Berg4c476992010-10-04 21:36:35 +02007908 nla_put_failure:
Kalle Valoffb9eb32010-02-17 17:58:10 +02007909 err = -ENOBUFS;
Johannes Berg4c476992010-10-04 21:36:35 +02007910 free_msg:
Kalle Valoffb9eb32010-02-17 17:58:10 +02007911 nlmsg_free(msg);
Kalle Valoffb9eb32010-02-17 17:58:10 +02007912 return err;
7913}
7914
Johannes Berg94e860f2014-01-20 23:58:15 +01007915static const struct nla_policy
7916nl80211_attr_cqm_policy[NL80211_ATTR_CQM_MAX + 1] = {
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02007917 [NL80211_ATTR_CQM_RSSI_THOLD] = { .type = NLA_U32 },
7918 [NL80211_ATTR_CQM_RSSI_HYST] = { .type = NLA_U32 },
7919 [NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT] = { .type = NLA_U32 },
Thomas Pedersen84f10702012-07-12 16:17:33 -07007920 [NL80211_ATTR_CQM_TXE_RATE] = { .type = NLA_U32 },
7921 [NL80211_ATTR_CQM_TXE_PKTS] = { .type = NLA_U32 },
7922 [NL80211_ATTR_CQM_TXE_INTVL] = { .type = NLA_U32 },
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02007923};
7924
Thomas Pedersen84f10702012-07-12 16:17:33 -07007925static int nl80211_set_cqm_txe(struct genl_info *info,
Johannes Bergd9d8b012012-11-26 12:51:52 +01007926 u32 rate, u32 pkts, u32 intvl)
Thomas Pedersen84f10702012-07-12 16:17:33 -07007927{
7928 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Thomas Pedersen84f10702012-07-12 16:17:33 -07007929 struct net_device *dev = info->user_ptr[1];
Johannes Berg1da5fcc2013-08-06 14:10:48 +02007930 struct wireless_dev *wdev = dev->ieee80211_ptr;
Thomas Pedersen84f10702012-07-12 16:17:33 -07007931
Johannes Bergd9d8b012012-11-26 12:51:52 +01007932 if (rate > 100 || intvl > NL80211_CQM_TXE_MAX_INTVL)
Thomas Pedersen84f10702012-07-12 16:17:33 -07007933 return -EINVAL;
7934
Thomas Pedersen84f10702012-07-12 16:17:33 -07007935 if (!rdev->ops->set_cqm_txe_config)
7936 return -EOPNOTSUPP;
7937
7938 if (wdev->iftype != NL80211_IFTYPE_STATION &&
7939 wdev->iftype != NL80211_IFTYPE_P2P_CLIENT)
7940 return -EOPNOTSUPP;
7941
Hila Gonene35e4d22012-06-27 17:19:42 +03007942 return rdev_set_cqm_txe_config(rdev, dev, rate, pkts, intvl);
Thomas Pedersen84f10702012-07-12 16:17:33 -07007943}
7944
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02007945static int nl80211_set_cqm_rssi(struct genl_info *info,
7946 s32 threshold, u32 hysteresis)
7947{
Johannes Berg4c476992010-10-04 21:36:35 +02007948 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg4c476992010-10-04 21:36:35 +02007949 struct net_device *dev = info->user_ptr[1];
Johannes Berg1da5fcc2013-08-06 14:10:48 +02007950 struct wireless_dev *wdev = dev->ieee80211_ptr;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02007951
7952 if (threshold > 0)
7953 return -EINVAL;
7954
Johannes Berg1da5fcc2013-08-06 14:10:48 +02007955 /* disabling - hysteresis should also be zero then */
7956 if (threshold == 0)
7957 hysteresis = 0;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02007958
Johannes Berg4c476992010-10-04 21:36:35 +02007959 if (!rdev->ops->set_cqm_rssi_config)
7960 return -EOPNOTSUPP;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02007961
Johannes Berg074ac8d2010-09-16 14:58:22 +02007962 if (wdev->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02007963 wdev->iftype != NL80211_IFTYPE_P2P_CLIENT)
7964 return -EOPNOTSUPP;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02007965
Hila Gonene35e4d22012-06-27 17:19:42 +03007966 return rdev_set_cqm_rssi_config(rdev, dev, threshold, hysteresis);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02007967}
7968
7969static int nl80211_set_cqm(struct sk_buff *skb, struct genl_info *info)
7970{
7971 struct nlattr *attrs[NL80211_ATTR_CQM_MAX + 1];
7972 struct nlattr *cqm;
7973 int err;
7974
7975 cqm = info->attrs[NL80211_ATTR_CQM];
Johannes Berg1da5fcc2013-08-06 14:10:48 +02007976 if (!cqm)
7977 return -EINVAL;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02007978
7979 err = nla_parse_nested(attrs, NL80211_ATTR_CQM_MAX, cqm,
7980 nl80211_attr_cqm_policy);
7981 if (err)
Johannes Berg1da5fcc2013-08-06 14:10:48 +02007982 return err;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02007983
7984 if (attrs[NL80211_ATTR_CQM_RSSI_THOLD] &&
7985 attrs[NL80211_ATTR_CQM_RSSI_HYST]) {
Johannes Berg1da5fcc2013-08-06 14:10:48 +02007986 s32 threshold = nla_get_s32(attrs[NL80211_ATTR_CQM_RSSI_THOLD]);
7987 u32 hysteresis = nla_get_u32(attrs[NL80211_ATTR_CQM_RSSI_HYST]);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02007988
Johannes Berg1da5fcc2013-08-06 14:10:48 +02007989 return nl80211_set_cqm_rssi(info, threshold, hysteresis);
7990 }
7991
7992 if (attrs[NL80211_ATTR_CQM_TXE_RATE] &&
7993 attrs[NL80211_ATTR_CQM_TXE_PKTS] &&
7994 attrs[NL80211_ATTR_CQM_TXE_INTVL]) {
7995 u32 rate = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_RATE]);
7996 u32 pkts = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_PKTS]);
7997 u32 intvl = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_INTVL]);
7998
7999 return nl80211_set_cqm_txe(info, rate, pkts, intvl);
8000 }
8001
8002 return -EINVAL;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008003}
8004
Johannes Berg29cbe682010-12-03 09:20:44 +01008005static int nl80211_join_mesh(struct sk_buff *skb, struct genl_info *info)
8006{
8007 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8008 struct net_device *dev = info->user_ptr[1];
8009 struct mesh_config cfg;
Javier Cardonac80d5452010-12-16 17:37:49 -08008010 struct mesh_setup setup;
Johannes Berg29cbe682010-12-03 09:20:44 +01008011 int err;
8012
8013 /* start with default */
8014 memcpy(&cfg, &default_mesh_config, sizeof(cfg));
Javier Cardonac80d5452010-12-16 17:37:49 -08008015 memcpy(&setup, &default_mesh_setup, sizeof(setup));
Johannes Berg29cbe682010-12-03 09:20:44 +01008016
Javier Cardona24bdd9f2010-12-16 17:37:48 -08008017 if (info->attrs[NL80211_ATTR_MESH_CONFIG]) {
Johannes Berg29cbe682010-12-03 09:20:44 +01008018 /* and parse parameters if given */
Javier Cardona24bdd9f2010-12-16 17:37:48 -08008019 err = nl80211_parse_mesh_config(info, &cfg, NULL);
Johannes Berg29cbe682010-12-03 09:20:44 +01008020 if (err)
8021 return err;
8022 }
8023
8024 if (!info->attrs[NL80211_ATTR_MESH_ID] ||
8025 !nla_len(info->attrs[NL80211_ATTR_MESH_ID]))
8026 return -EINVAL;
8027
Javier Cardonac80d5452010-12-16 17:37:49 -08008028 setup.mesh_id = nla_data(info->attrs[NL80211_ATTR_MESH_ID]);
8029 setup.mesh_id_len = nla_len(info->attrs[NL80211_ATTR_MESH_ID]);
8030
Chun-Yeow Yeoh4bb62342011-11-24 17:15:20 -08008031 if (info->attrs[NL80211_ATTR_MCAST_RATE] &&
8032 !nl80211_parse_mcast_rate(rdev, setup.mcast_rate,
8033 nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE])))
8034 return -EINVAL;
8035
Marco Porsch9bdbf042013-01-07 16:04:51 +01008036 if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) {
8037 setup.beacon_interval =
8038 nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]);
8039 if (setup.beacon_interval < 10 ||
8040 setup.beacon_interval > 10000)
8041 return -EINVAL;
8042 }
8043
8044 if (info->attrs[NL80211_ATTR_DTIM_PERIOD]) {
8045 setup.dtim_period =
8046 nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]);
8047 if (setup.dtim_period < 1 || setup.dtim_period > 100)
8048 return -EINVAL;
8049 }
8050
Javier Cardonac80d5452010-12-16 17:37:49 -08008051 if (info->attrs[NL80211_ATTR_MESH_SETUP]) {
8052 /* parse additional setup parameters if given */
8053 err = nl80211_parse_mesh_setup(info, &setup);
8054 if (err)
8055 return err;
8056 }
8057
Thomas Pedersend37bb182013-03-04 13:06:13 -08008058 if (setup.user_mpm)
8059 cfg.auto_open_plinks = false;
8060
Johannes Bergcc1d2802012-05-16 23:50:20 +02008061 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
Johannes Berg683b6d32012-11-08 21:25:48 +01008062 err = nl80211_parse_chandef(rdev, info, &setup.chandef);
8063 if (err)
8064 return err;
Johannes Bergcc1d2802012-05-16 23:50:20 +02008065 } else {
8066 /* cfg80211_join_mesh() will sort it out */
Johannes Berg683b6d32012-11-08 21:25:48 +01008067 setup.chandef.chan = NULL;
Johannes Bergcc1d2802012-05-16 23:50:20 +02008068 }
8069
Ashok Nagarajanffb3cf32013-06-03 10:33:36 -07008070 if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) {
8071 u8 *rates = nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
8072 int n_rates =
8073 nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
8074 struct ieee80211_supported_band *sband;
8075
8076 if (!setup.chandef.chan)
8077 return -EINVAL;
8078
8079 sband = rdev->wiphy.bands[setup.chandef.chan->band];
8080
8081 err = ieee80211_get_ratemask(sband, rates, n_rates,
8082 &setup.basic_rates);
8083 if (err)
8084 return err;
8085 }
8086
Javier Cardonac80d5452010-12-16 17:37:49 -08008087 return cfg80211_join_mesh(rdev, dev, &setup, &cfg);
Johannes Berg29cbe682010-12-03 09:20:44 +01008088}
8089
8090static int nl80211_leave_mesh(struct sk_buff *skb, struct genl_info *info)
8091{
8092 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8093 struct net_device *dev = info->user_ptr[1];
8094
8095 return cfg80211_leave_mesh(rdev, dev);
8096}
8097
Johannes Bergdfb89c52012-06-27 09:23:48 +02008098#ifdef CONFIG_PM
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08008099static int nl80211_send_wowlan_patterns(struct sk_buff *msg,
8100 struct cfg80211_registered_device *rdev)
8101{
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008102 struct cfg80211_wowlan *wowlan = rdev->wiphy.wowlan_config;
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08008103 struct nlattr *nl_pats, *nl_pat;
8104 int i, pat_len;
8105
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008106 if (!wowlan->n_patterns)
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08008107 return 0;
8108
8109 nl_pats = nla_nest_start(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN);
8110 if (!nl_pats)
8111 return -ENOBUFS;
8112
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008113 for (i = 0; i < wowlan->n_patterns; i++) {
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08008114 nl_pat = nla_nest_start(msg, i + 1);
8115 if (!nl_pat)
8116 return -ENOBUFS;
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008117 pat_len = wowlan->patterns[i].pattern_len;
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07008118 if (nla_put(msg, NL80211_PKTPAT_MASK, DIV_ROUND_UP(pat_len, 8),
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008119 wowlan->patterns[i].mask) ||
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07008120 nla_put(msg, NL80211_PKTPAT_PATTERN, pat_len,
8121 wowlan->patterns[i].pattern) ||
8122 nla_put_u32(msg, NL80211_PKTPAT_OFFSET,
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008123 wowlan->patterns[i].pkt_offset))
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08008124 return -ENOBUFS;
8125 nla_nest_end(msg, nl_pat);
8126 }
8127 nla_nest_end(msg, nl_pats);
8128
8129 return 0;
8130}
8131
Johannes Berg2a0e0472013-01-23 22:57:40 +01008132static int nl80211_send_wowlan_tcp(struct sk_buff *msg,
8133 struct cfg80211_wowlan_tcp *tcp)
8134{
8135 struct nlattr *nl_tcp;
8136
8137 if (!tcp)
8138 return 0;
8139
8140 nl_tcp = nla_nest_start(msg, NL80211_WOWLAN_TRIG_TCP_CONNECTION);
8141 if (!nl_tcp)
8142 return -ENOBUFS;
8143
8144 if (nla_put_be32(msg, NL80211_WOWLAN_TCP_SRC_IPV4, tcp->src) ||
8145 nla_put_be32(msg, NL80211_WOWLAN_TCP_DST_IPV4, tcp->dst) ||
8146 nla_put(msg, NL80211_WOWLAN_TCP_DST_MAC, ETH_ALEN, tcp->dst_mac) ||
8147 nla_put_u16(msg, NL80211_WOWLAN_TCP_SRC_PORT, tcp->src_port) ||
8148 nla_put_u16(msg, NL80211_WOWLAN_TCP_DST_PORT, tcp->dst_port) ||
8149 nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD,
8150 tcp->payload_len, tcp->payload) ||
8151 nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_INTERVAL,
8152 tcp->data_interval) ||
8153 nla_put(msg, NL80211_WOWLAN_TCP_WAKE_PAYLOAD,
8154 tcp->wake_len, tcp->wake_data) ||
8155 nla_put(msg, NL80211_WOWLAN_TCP_WAKE_MASK,
8156 DIV_ROUND_UP(tcp->wake_len, 8), tcp->wake_mask))
8157 return -ENOBUFS;
8158
8159 if (tcp->payload_seq.len &&
8160 nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ,
8161 sizeof(tcp->payload_seq), &tcp->payload_seq))
8162 return -ENOBUFS;
8163
8164 if (tcp->payload_tok.len &&
8165 nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN,
8166 sizeof(tcp->payload_tok) + tcp->tokens_size,
8167 &tcp->payload_tok))
8168 return -ENOBUFS;
8169
Johannes Berge248ad32013-05-16 10:24:28 +02008170 nla_nest_end(msg, nl_tcp);
8171
Johannes Berg2a0e0472013-01-23 22:57:40 +01008172 return 0;
8173}
8174
Johannes Bergff1b6e62011-05-04 15:37:28 +02008175static int nl80211_get_wowlan(struct sk_buff *skb, struct genl_info *info)
8176{
8177 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8178 struct sk_buff *msg;
8179 void *hdr;
Johannes Berg2a0e0472013-01-23 22:57:40 +01008180 u32 size = NLMSG_DEFAULT_SIZE;
Johannes Bergff1b6e62011-05-04 15:37:28 +02008181
Johannes Berg964dc9e2013-06-03 17:25:34 +02008182 if (!rdev->wiphy.wowlan)
Johannes Bergff1b6e62011-05-04 15:37:28 +02008183 return -EOPNOTSUPP;
8184
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008185 if (rdev->wiphy.wowlan_config && rdev->wiphy.wowlan_config->tcp) {
Johannes Berg2a0e0472013-01-23 22:57:40 +01008186 /* adjust size to have room for all the data */
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008187 size += rdev->wiphy.wowlan_config->tcp->tokens_size +
8188 rdev->wiphy.wowlan_config->tcp->payload_len +
8189 rdev->wiphy.wowlan_config->tcp->wake_len +
8190 rdev->wiphy.wowlan_config->tcp->wake_len / 8;
Johannes Berg2a0e0472013-01-23 22:57:40 +01008191 }
8192
8193 msg = nlmsg_new(size, GFP_KERNEL);
Johannes Bergff1b6e62011-05-04 15:37:28 +02008194 if (!msg)
8195 return -ENOMEM;
8196
Eric W. Biederman15e47302012-09-07 20:12:54 +00008197 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Johannes Bergff1b6e62011-05-04 15:37:28 +02008198 NL80211_CMD_GET_WOWLAN);
8199 if (!hdr)
8200 goto nla_put_failure;
8201
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008202 if (rdev->wiphy.wowlan_config) {
Johannes Bergff1b6e62011-05-04 15:37:28 +02008203 struct nlattr *nl_wowlan;
8204
8205 nl_wowlan = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS);
8206 if (!nl_wowlan)
8207 goto nla_put_failure;
8208
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008209 if ((rdev->wiphy.wowlan_config->any &&
David S. Miller9360ffd2012-03-29 04:41:26 -04008210 nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008211 (rdev->wiphy.wowlan_config->disconnect &&
David S. Miller9360ffd2012-03-29 04:41:26 -04008212 nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008213 (rdev->wiphy.wowlan_config->magic_pkt &&
David S. Miller9360ffd2012-03-29 04:41:26 -04008214 nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008215 (rdev->wiphy.wowlan_config->gtk_rekey_failure &&
David S. Miller9360ffd2012-03-29 04:41:26 -04008216 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008217 (rdev->wiphy.wowlan_config->eap_identity_req &&
David S. Miller9360ffd2012-03-29 04:41:26 -04008218 nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008219 (rdev->wiphy.wowlan_config->four_way_handshake &&
David S. Miller9360ffd2012-03-29 04:41:26 -04008220 nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008221 (rdev->wiphy.wowlan_config->rfkill_release &&
David S. Miller9360ffd2012-03-29 04:41:26 -04008222 nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE)))
8223 goto nla_put_failure;
Johannes Berg2a0e0472013-01-23 22:57:40 +01008224
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08008225 if (nl80211_send_wowlan_patterns(msg, rdev))
8226 goto nla_put_failure;
Johannes Berg2a0e0472013-01-23 22:57:40 +01008227
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008228 if (nl80211_send_wowlan_tcp(msg,
8229 rdev->wiphy.wowlan_config->tcp))
Johannes Berg2a0e0472013-01-23 22:57:40 +01008230 goto nla_put_failure;
8231
Johannes Bergff1b6e62011-05-04 15:37:28 +02008232 nla_nest_end(msg, nl_wowlan);
8233 }
8234
8235 genlmsg_end(msg, hdr);
8236 return genlmsg_reply(msg, info);
8237
8238nla_put_failure:
8239 nlmsg_free(msg);
8240 return -ENOBUFS;
8241}
8242
Johannes Berg2a0e0472013-01-23 22:57:40 +01008243static int nl80211_parse_wowlan_tcp(struct cfg80211_registered_device *rdev,
8244 struct nlattr *attr,
8245 struct cfg80211_wowlan *trig)
8246{
8247 struct nlattr *tb[NUM_NL80211_WOWLAN_TCP];
8248 struct cfg80211_wowlan_tcp *cfg;
8249 struct nl80211_wowlan_tcp_data_token *tok = NULL;
8250 struct nl80211_wowlan_tcp_data_seq *seq = NULL;
8251 u32 size;
8252 u32 data_size, wake_size, tokens_size = 0, wake_mask_size;
8253 int err, port;
8254
Johannes Berg964dc9e2013-06-03 17:25:34 +02008255 if (!rdev->wiphy.wowlan->tcp)
Johannes Berg2a0e0472013-01-23 22:57:40 +01008256 return -EINVAL;
8257
8258 err = nla_parse(tb, MAX_NL80211_WOWLAN_TCP,
8259 nla_data(attr), nla_len(attr),
8260 nl80211_wowlan_tcp_policy);
8261 if (err)
8262 return err;
8263
8264 if (!tb[NL80211_WOWLAN_TCP_SRC_IPV4] ||
8265 !tb[NL80211_WOWLAN_TCP_DST_IPV4] ||
8266 !tb[NL80211_WOWLAN_TCP_DST_MAC] ||
8267 !tb[NL80211_WOWLAN_TCP_DST_PORT] ||
8268 !tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD] ||
8269 !tb[NL80211_WOWLAN_TCP_DATA_INTERVAL] ||
8270 !tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD] ||
8271 !tb[NL80211_WOWLAN_TCP_WAKE_MASK])
8272 return -EINVAL;
8273
8274 data_size = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]);
Johannes Berg964dc9e2013-06-03 17:25:34 +02008275 if (data_size > rdev->wiphy.wowlan->tcp->data_payload_max)
Johannes Berg2a0e0472013-01-23 22:57:40 +01008276 return -EINVAL;
8277
8278 if (nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]) >
Johannes Berg964dc9e2013-06-03 17:25:34 +02008279 rdev->wiphy.wowlan->tcp->data_interval_max ||
Johannes Berg723d5682013-02-26 13:56:40 +01008280 nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]) == 0)
Johannes Berg2a0e0472013-01-23 22:57:40 +01008281 return -EINVAL;
8282
8283 wake_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]);
Johannes Berg964dc9e2013-06-03 17:25:34 +02008284 if (wake_size > rdev->wiphy.wowlan->tcp->wake_payload_max)
Johannes Berg2a0e0472013-01-23 22:57:40 +01008285 return -EINVAL;
8286
8287 wake_mask_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_MASK]);
8288 if (wake_mask_size != DIV_ROUND_UP(wake_size, 8))
8289 return -EINVAL;
8290
8291 if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]) {
8292 u32 tokln = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]);
8293
8294 tok = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]);
8295 tokens_size = tokln - sizeof(*tok);
8296
8297 if (!tok->len || tokens_size % tok->len)
8298 return -EINVAL;
Johannes Berg964dc9e2013-06-03 17:25:34 +02008299 if (!rdev->wiphy.wowlan->tcp->tok)
Johannes Berg2a0e0472013-01-23 22:57:40 +01008300 return -EINVAL;
Johannes Berg964dc9e2013-06-03 17:25:34 +02008301 if (tok->len > rdev->wiphy.wowlan->tcp->tok->max_len)
Johannes Berg2a0e0472013-01-23 22:57:40 +01008302 return -EINVAL;
Johannes Berg964dc9e2013-06-03 17:25:34 +02008303 if (tok->len < rdev->wiphy.wowlan->tcp->tok->min_len)
Johannes Berg2a0e0472013-01-23 22:57:40 +01008304 return -EINVAL;
Johannes Berg964dc9e2013-06-03 17:25:34 +02008305 if (tokens_size > rdev->wiphy.wowlan->tcp->tok->bufsize)
Johannes Berg2a0e0472013-01-23 22:57:40 +01008306 return -EINVAL;
8307 if (tok->offset + tok->len > data_size)
8308 return -EINVAL;
8309 }
8310
8311 if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]) {
8312 seq = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]);
Johannes Berg964dc9e2013-06-03 17:25:34 +02008313 if (!rdev->wiphy.wowlan->tcp->seq)
Johannes Berg2a0e0472013-01-23 22:57:40 +01008314 return -EINVAL;
8315 if (seq->len == 0 || seq->len > 4)
8316 return -EINVAL;
8317 if (seq->len + seq->offset > data_size)
8318 return -EINVAL;
8319 }
8320
8321 size = sizeof(*cfg);
8322 size += data_size;
8323 size += wake_size + wake_mask_size;
8324 size += tokens_size;
8325
8326 cfg = kzalloc(size, GFP_KERNEL);
8327 if (!cfg)
8328 return -ENOMEM;
8329 cfg->src = nla_get_be32(tb[NL80211_WOWLAN_TCP_SRC_IPV4]);
8330 cfg->dst = nla_get_be32(tb[NL80211_WOWLAN_TCP_DST_IPV4]);
8331 memcpy(cfg->dst_mac, nla_data(tb[NL80211_WOWLAN_TCP_DST_MAC]),
8332 ETH_ALEN);
8333 if (tb[NL80211_WOWLAN_TCP_SRC_PORT])
8334 port = nla_get_u16(tb[NL80211_WOWLAN_TCP_SRC_PORT]);
8335 else
8336 port = 0;
8337#ifdef CONFIG_INET
8338 /* allocate a socket and port for it and use it */
8339 err = __sock_create(wiphy_net(&rdev->wiphy), PF_INET, SOCK_STREAM,
8340 IPPROTO_TCP, &cfg->sock, 1);
8341 if (err) {
8342 kfree(cfg);
8343 return err;
8344 }
8345 if (inet_csk_get_port(cfg->sock->sk, port)) {
8346 sock_release(cfg->sock);
8347 kfree(cfg);
8348 return -EADDRINUSE;
8349 }
8350 cfg->src_port = inet_sk(cfg->sock->sk)->inet_num;
8351#else
8352 if (!port) {
8353 kfree(cfg);
8354 return -EINVAL;
8355 }
8356 cfg->src_port = port;
8357#endif
8358
8359 cfg->dst_port = nla_get_u16(tb[NL80211_WOWLAN_TCP_DST_PORT]);
8360 cfg->payload_len = data_size;
8361 cfg->payload = (u8 *)cfg + sizeof(*cfg) + tokens_size;
8362 memcpy((void *)cfg->payload,
8363 nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]),
8364 data_size);
8365 if (seq)
8366 cfg->payload_seq = *seq;
8367 cfg->data_interval = nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]);
8368 cfg->wake_len = wake_size;
8369 cfg->wake_data = (u8 *)cfg + sizeof(*cfg) + tokens_size + data_size;
8370 memcpy((void *)cfg->wake_data,
8371 nla_data(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]),
8372 wake_size);
8373 cfg->wake_mask = (u8 *)cfg + sizeof(*cfg) + tokens_size +
8374 data_size + wake_size;
8375 memcpy((void *)cfg->wake_mask,
8376 nla_data(tb[NL80211_WOWLAN_TCP_WAKE_MASK]),
8377 wake_mask_size);
8378 if (tok) {
8379 cfg->tokens_size = tokens_size;
8380 memcpy(&cfg->payload_tok, tok, sizeof(*tok) + tokens_size);
8381 }
8382
8383 trig->tcp = cfg;
8384
8385 return 0;
8386}
8387
Johannes Bergff1b6e62011-05-04 15:37:28 +02008388static int nl80211_set_wowlan(struct sk_buff *skb, struct genl_info *info)
8389{
8390 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8391 struct nlattr *tb[NUM_NL80211_WOWLAN_TRIG];
Johannes Bergff1b6e62011-05-04 15:37:28 +02008392 struct cfg80211_wowlan new_triggers = {};
Johannes Bergae33bd82012-07-12 16:25:02 +02008393 struct cfg80211_wowlan *ntrig;
Johannes Berg964dc9e2013-06-03 17:25:34 +02008394 const struct wiphy_wowlan_support *wowlan = rdev->wiphy.wowlan;
Johannes Bergff1b6e62011-05-04 15:37:28 +02008395 int err, i;
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008396 bool prev_enabled = rdev->wiphy.wowlan_config;
Johannes Bergff1b6e62011-05-04 15:37:28 +02008397
Johannes Berg964dc9e2013-06-03 17:25:34 +02008398 if (!wowlan)
Johannes Bergff1b6e62011-05-04 15:37:28 +02008399 return -EOPNOTSUPP;
8400
Johannes Bergae33bd82012-07-12 16:25:02 +02008401 if (!info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]) {
8402 cfg80211_rdev_free_wowlan(rdev);
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008403 rdev->wiphy.wowlan_config = NULL;
Johannes Bergae33bd82012-07-12 16:25:02 +02008404 goto set_wakeup;
8405 }
Johannes Bergff1b6e62011-05-04 15:37:28 +02008406
8407 err = nla_parse(tb, MAX_NL80211_WOWLAN_TRIG,
8408 nla_data(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]),
8409 nla_len(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]),
8410 nl80211_wowlan_policy);
8411 if (err)
8412 return err;
8413
8414 if (tb[NL80211_WOWLAN_TRIG_ANY]) {
8415 if (!(wowlan->flags & WIPHY_WOWLAN_ANY))
8416 return -EINVAL;
8417 new_triggers.any = true;
8418 }
8419
8420 if (tb[NL80211_WOWLAN_TRIG_DISCONNECT]) {
8421 if (!(wowlan->flags & WIPHY_WOWLAN_DISCONNECT))
8422 return -EINVAL;
8423 new_triggers.disconnect = true;
8424 }
8425
8426 if (tb[NL80211_WOWLAN_TRIG_MAGIC_PKT]) {
8427 if (!(wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT))
8428 return -EINVAL;
8429 new_triggers.magic_pkt = true;
8430 }
8431
Johannes Berg77dbbb12011-07-13 10:48:55 +02008432 if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED])
8433 return -EINVAL;
8434
8435 if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE]) {
8436 if (!(wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE))
8437 return -EINVAL;
8438 new_triggers.gtk_rekey_failure = true;
8439 }
8440
8441 if (tb[NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST]) {
8442 if (!(wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ))
8443 return -EINVAL;
8444 new_triggers.eap_identity_req = true;
8445 }
8446
8447 if (tb[NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE]) {
8448 if (!(wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE))
8449 return -EINVAL;
8450 new_triggers.four_way_handshake = true;
8451 }
8452
8453 if (tb[NL80211_WOWLAN_TRIG_RFKILL_RELEASE]) {
8454 if (!(wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE))
8455 return -EINVAL;
8456 new_triggers.rfkill_release = true;
8457 }
8458
Johannes Bergff1b6e62011-05-04 15:37:28 +02008459 if (tb[NL80211_WOWLAN_TRIG_PKT_PATTERN]) {
8460 struct nlattr *pat;
8461 int n_patterns = 0;
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08008462 int rem, pat_len, mask_len, pkt_offset;
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07008463 struct nlattr *pat_tb[NUM_NL80211_PKTPAT];
Johannes Bergff1b6e62011-05-04 15:37:28 +02008464
8465 nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN],
8466 rem)
8467 n_patterns++;
8468 if (n_patterns > wowlan->n_patterns)
8469 return -EINVAL;
8470
8471 new_triggers.patterns = kcalloc(n_patterns,
8472 sizeof(new_triggers.patterns[0]),
8473 GFP_KERNEL);
8474 if (!new_triggers.patterns)
8475 return -ENOMEM;
8476
8477 new_triggers.n_patterns = n_patterns;
8478 i = 0;
8479
8480 nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN],
8481 rem) {
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07008482 nla_parse(pat_tb, MAX_NL80211_PKTPAT, nla_data(pat),
8483 nla_len(pat), NULL);
Johannes Bergff1b6e62011-05-04 15:37:28 +02008484 err = -EINVAL;
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07008485 if (!pat_tb[NL80211_PKTPAT_MASK] ||
8486 !pat_tb[NL80211_PKTPAT_PATTERN])
Johannes Bergff1b6e62011-05-04 15:37:28 +02008487 goto error;
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07008488 pat_len = nla_len(pat_tb[NL80211_PKTPAT_PATTERN]);
Johannes Bergff1b6e62011-05-04 15:37:28 +02008489 mask_len = DIV_ROUND_UP(pat_len, 8);
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07008490 if (nla_len(pat_tb[NL80211_PKTPAT_MASK]) != mask_len)
Johannes Bergff1b6e62011-05-04 15:37:28 +02008491 goto error;
8492 if (pat_len > wowlan->pattern_max_len ||
8493 pat_len < wowlan->pattern_min_len)
8494 goto error;
8495
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07008496 if (!pat_tb[NL80211_PKTPAT_OFFSET])
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08008497 pkt_offset = 0;
8498 else
8499 pkt_offset = nla_get_u32(
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07008500 pat_tb[NL80211_PKTPAT_OFFSET]);
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08008501 if (pkt_offset > wowlan->max_pkt_offset)
8502 goto error;
8503 new_triggers.patterns[i].pkt_offset = pkt_offset;
8504
Johannes Bergff1b6e62011-05-04 15:37:28 +02008505 new_triggers.patterns[i].mask =
8506 kmalloc(mask_len + pat_len, GFP_KERNEL);
8507 if (!new_triggers.patterns[i].mask) {
8508 err = -ENOMEM;
8509 goto error;
8510 }
8511 new_triggers.patterns[i].pattern =
8512 new_triggers.patterns[i].mask + mask_len;
8513 memcpy(new_triggers.patterns[i].mask,
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07008514 nla_data(pat_tb[NL80211_PKTPAT_MASK]),
Johannes Bergff1b6e62011-05-04 15:37:28 +02008515 mask_len);
8516 new_triggers.patterns[i].pattern_len = pat_len;
8517 memcpy(new_triggers.patterns[i].pattern,
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07008518 nla_data(pat_tb[NL80211_PKTPAT_PATTERN]),
Johannes Bergff1b6e62011-05-04 15:37:28 +02008519 pat_len);
8520 i++;
8521 }
8522 }
8523
Johannes Berg2a0e0472013-01-23 22:57:40 +01008524 if (tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION]) {
8525 err = nl80211_parse_wowlan_tcp(
8526 rdev, tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION],
8527 &new_triggers);
8528 if (err)
8529 goto error;
8530 }
8531
Johannes Bergae33bd82012-07-12 16:25:02 +02008532 ntrig = kmemdup(&new_triggers, sizeof(new_triggers), GFP_KERNEL);
8533 if (!ntrig) {
8534 err = -ENOMEM;
8535 goto error;
Johannes Bergff1b6e62011-05-04 15:37:28 +02008536 }
Johannes Bergae33bd82012-07-12 16:25:02 +02008537 cfg80211_rdev_free_wowlan(rdev);
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008538 rdev->wiphy.wowlan_config = ntrig;
Johannes Bergff1b6e62011-05-04 15:37:28 +02008539
Johannes Bergae33bd82012-07-12 16:25:02 +02008540 set_wakeup:
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008541 if (rdev->ops->set_wakeup &&
8542 prev_enabled != !!rdev->wiphy.wowlan_config)
8543 rdev_set_wakeup(rdev, rdev->wiphy.wowlan_config);
Johannes Berg6d525632012-04-04 15:05:25 +02008544
Johannes Bergff1b6e62011-05-04 15:37:28 +02008545 return 0;
8546 error:
8547 for (i = 0; i < new_triggers.n_patterns; i++)
8548 kfree(new_triggers.patterns[i].mask);
8549 kfree(new_triggers.patterns);
Johannes Berg2a0e0472013-01-23 22:57:40 +01008550 if (new_triggers.tcp && new_triggers.tcp->sock)
8551 sock_release(new_triggers.tcp->sock);
8552 kfree(new_triggers.tcp);
Johannes Bergff1b6e62011-05-04 15:37:28 +02008553 return err;
8554}
Johannes Bergdfb89c52012-06-27 09:23:48 +02008555#endif
Johannes Bergff1b6e62011-05-04 15:37:28 +02008556
Amitkumar Karwarbe29b992013-06-28 11:51:26 -07008557static int nl80211_send_coalesce_rules(struct sk_buff *msg,
8558 struct cfg80211_registered_device *rdev)
8559{
8560 struct nlattr *nl_pats, *nl_pat, *nl_rule, *nl_rules;
8561 int i, j, pat_len;
8562 struct cfg80211_coalesce_rules *rule;
8563
8564 if (!rdev->coalesce->n_rules)
8565 return 0;
8566
8567 nl_rules = nla_nest_start(msg, NL80211_ATTR_COALESCE_RULE);
8568 if (!nl_rules)
8569 return -ENOBUFS;
8570
8571 for (i = 0; i < rdev->coalesce->n_rules; i++) {
8572 nl_rule = nla_nest_start(msg, i + 1);
8573 if (!nl_rule)
8574 return -ENOBUFS;
8575
8576 rule = &rdev->coalesce->rules[i];
8577 if (nla_put_u32(msg, NL80211_ATTR_COALESCE_RULE_DELAY,
8578 rule->delay))
8579 return -ENOBUFS;
8580
8581 if (nla_put_u32(msg, NL80211_ATTR_COALESCE_RULE_CONDITION,
8582 rule->condition))
8583 return -ENOBUFS;
8584
8585 nl_pats = nla_nest_start(msg,
8586 NL80211_ATTR_COALESCE_RULE_PKT_PATTERN);
8587 if (!nl_pats)
8588 return -ENOBUFS;
8589
8590 for (j = 0; j < rule->n_patterns; j++) {
8591 nl_pat = nla_nest_start(msg, j + 1);
8592 if (!nl_pat)
8593 return -ENOBUFS;
8594 pat_len = rule->patterns[j].pattern_len;
8595 if (nla_put(msg, NL80211_PKTPAT_MASK,
8596 DIV_ROUND_UP(pat_len, 8),
8597 rule->patterns[j].mask) ||
8598 nla_put(msg, NL80211_PKTPAT_PATTERN, pat_len,
8599 rule->patterns[j].pattern) ||
8600 nla_put_u32(msg, NL80211_PKTPAT_OFFSET,
8601 rule->patterns[j].pkt_offset))
8602 return -ENOBUFS;
8603 nla_nest_end(msg, nl_pat);
8604 }
8605 nla_nest_end(msg, nl_pats);
8606 nla_nest_end(msg, nl_rule);
8607 }
8608 nla_nest_end(msg, nl_rules);
8609
8610 return 0;
8611}
8612
8613static int nl80211_get_coalesce(struct sk_buff *skb, struct genl_info *info)
8614{
8615 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8616 struct sk_buff *msg;
8617 void *hdr;
8618
8619 if (!rdev->wiphy.coalesce)
8620 return -EOPNOTSUPP;
8621
8622 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
8623 if (!msg)
8624 return -ENOMEM;
8625
8626 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
8627 NL80211_CMD_GET_COALESCE);
8628 if (!hdr)
8629 goto nla_put_failure;
8630
8631 if (rdev->coalesce && nl80211_send_coalesce_rules(msg, rdev))
8632 goto nla_put_failure;
8633
8634 genlmsg_end(msg, hdr);
8635 return genlmsg_reply(msg, info);
8636
8637nla_put_failure:
8638 nlmsg_free(msg);
8639 return -ENOBUFS;
8640}
8641
8642void cfg80211_rdev_free_coalesce(struct cfg80211_registered_device *rdev)
8643{
8644 struct cfg80211_coalesce *coalesce = rdev->coalesce;
8645 int i, j;
8646 struct cfg80211_coalesce_rules *rule;
8647
8648 if (!coalesce)
8649 return;
8650
8651 for (i = 0; i < coalesce->n_rules; i++) {
8652 rule = &coalesce->rules[i];
8653 for (j = 0; j < rule->n_patterns; j++)
8654 kfree(rule->patterns[j].mask);
8655 kfree(rule->patterns);
8656 }
8657 kfree(coalesce->rules);
8658 kfree(coalesce);
8659 rdev->coalesce = NULL;
8660}
8661
8662static int nl80211_parse_coalesce_rule(struct cfg80211_registered_device *rdev,
8663 struct nlattr *rule,
8664 struct cfg80211_coalesce_rules *new_rule)
8665{
8666 int err, i;
8667 const struct wiphy_coalesce_support *coalesce = rdev->wiphy.coalesce;
8668 struct nlattr *tb[NUM_NL80211_ATTR_COALESCE_RULE], *pat;
8669 int rem, pat_len, mask_len, pkt_offset, n_patterns = 0;
8670 struct nlattr *pat_tb[NUM_NL80211_PKTPAT];
8671
8672 err = nla_parse(tb, NL80211_ATTR_COALESCE_RULE_MAX, nla_data(rule),
8673 nla_len(rule), nl80211_coalesce_policy);
8674 if (err)
8675 return err;
8676
8677 if (tb[NL80211_ATTR_COALESCE_RULE_DELAY])
8678 new_rule->delay =
8679 nla_get_u32(tb[NL80211_ATTR_COALESCE_RULE_DELAY]);
8680 if (new_rule->delay > coalesce->max_delay)
8681 return -EINVAL;
8682
8683 if (tb[NL80211_ATTR_COALESCE_RULE_CONDITION])
8684 new_rule->condition =
8685 nla_get_u32(tb[NL80211_ATTR_COALESCE_RULE_CONDITION]);
8686 if (new_rule->condition != NL80211_COALESCE_CONDITION_MATCH &&
8687 new_rule->condition != NL80211_COALESCE_CONDITION_NO_MATCH)
8688 return -EINVAL;
8689
8690 if (!tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN])
8691 return -EINVAL;
8692
8693 nla_for_each_nested(pat, tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN],
8694 rem)
8695 n_patterns++;
8696 if (n_patterns > coalesce->n_patterns)
8697 return -EINVAL;
8698
8699 new_rule->patterns = kcalloc(n_patterns, sizeof(new_rule->patterns[0]),
8700 GFP_KERNEL);
8701 if (!new_rule->patterns)
8702 return -ENOMEM;
8703
8704 new_rule->n_patterns = n_patterns;
8705 i = 0;
8706
8707 nla_for_each_nested(pat, tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN],
8708 rem) {
8709 nla_parse(pat_tb, MAX_NL80211_PKTPAT, nla_data(pat),
8710 nla_len(pat), NULL);
8711 if (!pat_tb[NL80211_PKTPAT_MASK] ||
8712 !pat_tb[NL80211_PKTPAT_PATTERN])
8713 return -EINVAL;
8714 pat_len = nla_len(pat_tb[NL80211_PKTPAT_PATTERN]);
8715 mask_len = DIV_ROUND_UP(pat_len, 8);
8716 if (nla_len(pat_tb[NL80211_PKTPAT_MASK]) != mask_len)
8717 return -EINVAL;
8718 if (pat_len > coalesce->pattern_max_len ||
8719 pat_len < coalesce->pattern_min_len)
8720 return -EINVAL;
8721
8722 if (!pat_tb[NL80211_PKTPAT_OFFSET])
8723 pkt_offset = 0;
8724 else
8725 pkt_offset = nla_get_u32(pat_tb[NL80211_PKTPAT_OFFSET]);
8726 if (pkt_offset > coalesce->max_pkt_offset)
8727 return -EINVAL;
8728 new_rule->patterns[i].pkt_offset = pkt_offset;
8729
8730 new_rule->patterns[i].mask =
8731 kmalloc(mask_len + pat_len, GFP_KERNEL);
8732 if (!new_rule->patterns[i].mask)
8733 return -ENOMEM;
8734 new_rule->patterns[i].pattern =
8735 new_rule->patterns[i].mask + mask_len;
8736 memcpy(new_rule->patterns[i].mask,
8737 nla_data(pat_tb[NL80211_PKTPAT_MASK]), mask_len);
8738 new_rule->patterns[i].pattern_len = pat_len;
8739 memcpy(new_rule->patterns[i].pattern,
8740 nla_data(pat_tb[NL80211_PKTPAT_PATTERN]), pat_len);
8741 i++;
8742 }
8743
8744 return 0;
8745}
8746
8747static int nl80211_set_coalesce(struct sk_buff *skb, struct genl_info *info)
8748{
8749 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8750 const struct wiphy_coalesce_support *coalesce = rdev->wiphy.coalesce;
8751 struct cfg80211_coalesce new_coalesce = {};
8752 struct cfg80211_coalesce *n_coalesce;
8753 int err, rem_rule, n_rules = 0, i, j;
8754 struct nlattr *rule;
8755 struct cfg80211_coalesce_rules *tmp_rule;
8756
8757 if (!rdev->wiphy.coalesce || !rdev->ops->set_coalesce)
8758 return -EOPNOTSUPP;
8759
8760 if (!info->attrs[NL80211_ATTR_COALESCE_RULE]) {
8761 cfg80211_rdev_free_coalesce(rdev);
8762 rdev->ops->set_coalesce(&rdev->wiphy, NULL);
8763 return 0;
8764 }
8765
8766 nla_for_each_nested(rule, info->attrs[NL80211_ATTR_COALESCE_RULE],
8767 rem_rule)
8768 n_rules++;
8769 if (n_rules > coalesce->n_rules)
8770 return -EINVAL;
8771
8772 new_coalesce.rules = kcalloc(n_rules, sizeof(new_coalesce.rules[0]),
8773 GFP_KERNEL);
8774 if (!new_coalesce.rules)
8775 return -ENOMEM;
8776
8777 new_coalesce.n_rules = n_rules;
8778 i = 0;
8779
8780 nla_for_each_nested(rule, info->attrs[NL80211_ATTR_COALESCE_RULE],
8781 rem_rule) {
8782 err = nl80211_parse_coalesce_rule(rdev, rule,
8783 &new_coalesce.rules[i]);
8784 if (err)
8785 goto error;
8786
8787 i++;
8788 }
8789
8790 err = rdev->ops->set_coalesce(&rdev->wiphy, &new_coalesce);
8791 if (err)
8792 goto error;
8793
8794 n_coalesce = kmemdup(&new_coalesce, sizeof(new_coalesce), GFP_KERNEL);
8795 if (!n_coalesce) {
8796 err = -ENOMEM;
8797 goto error;
8798 }
8799 cfg80211_rdev_free_coalesce(rdev);
8800 rdev->coalesce = n_coalesce;
8801
8802 return 0;
8803error:
8804 for (i = 0; i < new_coalesce.n_rules; i++) {
8805 tmp_rule = &new_coalesce.rules[i];
8806 for (j = 0; j < tmp_rule->n_patterns; j++)
8807 kfree(tmp_rule->patterns[j].mask);
8808 kfree(tmp_rule->patterns);
8809 }
8810 kfree(new_coalesce.rules);
8811
8812 return err;
8813}
8814
Johannes Berge5497d72011-07-05 16:35:40 +02008815static int nl80211_set_rekey_data(struct sk_buff *skb, struct genl_info *info)
8816{
8817 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8818 struct net_device *dev = info->user_ptr[1];
8819 struct wireless_dev *wdev = dev->ieee80211_ptr;
8820 struct nlattr *tb[NUM_NL80211_REKEY_DATA];
8821 struct cfg80211_gtk_rekey_data rekey_data;
8822 int err;
8823
8824 if (!info->attrs[NL80211_ATTR_REKEY_DATA])
8825 return -EINVAL;
8826
8827 err = nla_parse(tb, MAX_NL80211_REKEY_DATA,
8828 nla_data(info->attrs[NL80211_ATTR_REKEY_DATA]),
8829 nla_len(info->attrs[NL80211_ATTR_REKEY_DATA]),
8830 nl80211_rekey_policy);
8831 if (err)
8832 return err;
8833
8834 if (nla_len(tb[NL80211_REKEY_DATA_REPLAY_CTR]) != NL80211_REPLAY_CTR_LEN)
8835 return -ERANGE;
8836 if (nla_len(tb[NL80211_REKEY_DATA_KEK]) != NL80211_KEK_LEN)
8837 return -ERANGE;
8838 if (nla_len(tb[NL80211_REKEY_DATA_KCK]) != NL80211_KCK_LEN)
8839 return -ERANGE;
8840
8841 memcpy(rekey_data.kek, nla_data(tb[NL80211_REKEY_DATA_KEK]),
8842 NL80211_KEK_LEN);
8843 memcpy(rekey_data.kck, nla_data(tb[NL80211_REKEY_DATA_KCK]),
8844 NL80211_KCK_LEN);
8845 memcpy(rekey_data.replay_ctr,
8846 nla_data(tb[NL80211_REKEY_DATA_REPLAY_CTR]),
8847 NL80211_REPLAY_CTR_LEN);
8848
8849 wdev_lock(wdev);
8850 if (!wdev->current_bss) {
8851 err = -ENOTCONN;
8852 goto out;
8853 }
8854
8855 if (!rdev->ops->set_rekey_data) {
8856 err = -EOPNOTSUPP;
8857 goto out;
8858 }
8859
Hila Gonene35e4d22012-06-27 17:19:42 +03008860 err = rdev_set_rekey_data(rdev, dev, &rekey_data);
Johannes Berge5497d72011-07-05 16:35:40 +02008861 out:
8862 wdev_unlock(wdev);
8863 return err;
8864}
8865
Johannes Berg28946da2011-11-04 11:18:12 +01008866static int nl80211_register_unexpected_frame(struct sk_buff *skb,
8867 struct genl_info *info)
8868{
8869 struct net_device *dev = info->user_ptr[1];
8870 struct wireless_dev *wdev = dev->ieee80211_ptr;
8871
8872 if (wdev->iftype != NL80211_IFTYPE_AP &&
8873 wdev->iftype != NL80211_IFTYPE_P2P_GO)
8874 return -EINVAL;
8875
Eric W. Biederman15e47302012-09-07 20:12:54 +00008876 if (wdev->ap_unexpected_nlportid)
Johannes Berg28946da2011-11-04 11:18:12 +01008877 return -EBUSY;
8878
Eric W. Biederman15e47302012-09-07 20:12:54 +00008879 wdev->ap_unexpected_nlportid = info->snd_portid;
Johannes Berg28946da2011-11-04 11:18:12 +01008880 return 0;
8881}
8882
Johannes Berg7f6cf312011-11-04 11:18:15 +01008883static int nl80211_probe_client(struct sk_buff *skb,
8884 struct genl_info *info)
8885{
8886 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8887 struct net_device *dev = info->user_ptr[1];
8888 struct wireless_dev *wdev = dev->ieee80211_ptr;
8889 struct sk_buff *msg;
8890 void *hdr;
8891 const u8 *addr;
8892 u64 cookie;
8893 int err;
8894
8895 if (wdev->iftype != NL80211_IFTYPE_AP &&
8896 wdev->iftype != NL80211_IFTYPE_P2P_GO)
8897 return -EOPNOTSUPP;
8898
8899 if (!info->attrs[NL80211_ATTR_MAC])
8900 return -EINVAL;
8901
8902 if (!rdev->ops->probe_client)
8903 return -EOPNOTSUPP;
8904
8905 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
8906 if (!msg)
8907 return -ENOMEM;
8908
Eric W. Biederman15e47302012-09-07 20:12:54 +00008909 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berg7f6cf312011-11-04 11:18:15 +01008910 NL80211_CMD_PROBE_CLIENT);
Dan Carpentercb35fba2013-08-14 14:50:01 +03008911 if (!hdr) {
8912 err = -ENOBUFS;
Johannes Berg7f6cf312011-11-04 11:18:15 +01008913 goto free_msg;
8914 }
8915
8916 addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
8917
Hila Gonene35e4d22012-06-27 17:19:42 +03008918 err = rdev_probe_client(rdev, dev, addr, &cookie);
Johannes Berg7f6cf312011-11-04 11:18:15 +01008919 if (err)
8920 goto free_msg;
8921
David S. Miller9360ffd2012-03-29 04:41:26 -04008922 if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie))
8923 goto nla_put_failure;
Johannes Berg7f6cf312011-11-04 11:18:15 +01008924
8925 genlmsg_end(msg, hdr);
8926
8927 return genlmsg_reply(msg, info);
8928
8929 nla_put_failure:
8930 err = -ENOBUFS;
8931 free_msg:
8932 nlmsg_free(msg);
8933 return err;
8934}
8935
Johannes Berg5e760232011-11-04 11:18:17 +01008936static int nl80211_register_beacons(struct sk_buff *skb, struct genl_info *info)
8937{
8938 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Ben Greear37c73b52012-10-26 14:49:25 -07008939 struct cfg80211_beacon_registration *reg, *nreg;
8940 int rv;
Johannes Berg5e760232011-11-04 11:18:17 +01008941
8942 if (!(rdev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS))
8943 return -EOPNOTSUPP;
8944
Ben Greear37c73b52012-10-26 14:49:25 -07008945 nreg = kzalloc(sizeof(*nreg), GFP_KERNEL);
8946 if (!nreg)
8947 return -ENOMEM;
Johannes Berg5e760232011-11-04 11:18:17 +01008948
Ben Greear37c73b52012-10-26 14:49:25 -07008949 /* First, check if already registered. */
8950 spin_lock_bh(&rdev->beacon_registrations_lock);
8951 list_for_each_entry(reg, &rdev->beacon_registrations, list) {
8952 if (reg->nlportid == info->snd_portid) {
8953 rv = -EALREADY;
8954 goto out_err;
8955 }
8956 }
8957 /* Add it to the list */
8958 nreg->nlportid = info->snd_portid;
8959 list_add(&nreg->list, &rdev->beacon_registrations);
8960
8961 spin_unlock_bh(&rdev->beacon_registrations_lock);
Johannes Berg5e760232011-11-04 11:18:17 +01008962
8963 return 0;
Ben Greear37c73b52012-10-26 14:49:25 -07008964out_err:
8965 spin_unlock_bh(&rdev->beacon_registrations_lock);
8966 kfree(nreg);
8967 return rv;
Johannes Berg5e760232011-11-04 11:18:17 +01008968}
8969
Johannes Berg98104fde2012-06-16 00:19:54 +02008970static int nl80211_start_p2p_device(struct sk_buff *skb, struct genl_info *info)
8971{
8972 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8973 struct wireless_dev *wdev = info->user_ptr[1];
8974 int err;
8975
8976 if (!rdev->ops->start_p2p_device)
8977 return -EOPNOTSUPP;
8978
8979 if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE)
8980 return -EOPNOTSUPP;
8981
8982 if (wdev->p2p_started)
8983 return 0;
8984
Luciano Coelhob6a55012014-02-27 11:07:21 +02008985 if (rfkill_blocked(rdev->rfkill))
8986 return -ERFKILL;
Johannes Berg98104fde2012-06-16 00:19:54 +02008987
Johannes Bergeeb126e2012-10-23 15:16:50 +02008988 err = rdev_start_p2p_device(rdev, wdev);
Johannes Berg98104fde2012-06-16 00:19:54 +02008989 if (err)
8990 return err;
8991
8992 wdev->p2p_started = true;
Johannes Berg98104fde2012-06-16 00:19:54 +02008993 rdev->opencount++;
Johannes Berg98104fde2012-06-16 00:19:54 +02008994
8995 return 0;
8996}
8997
8998static int nl80211_stop_p2p_device(struct sk_buff *skb, struct genl_info *info)
8999{
9000 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9001 struct wireless_dev *wdev = info->user_ptr[1];
9002
9003 if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE)
9004 return -EOPNOTSUPP;
9005
9006 if (!rdev->ops->stop_p2p_device)
9007 return -EOPNOTSUPP;
9008
Johannes Bergf9f47522013-03-19 15:04:07 +01009009 cfg80211_stop_p2p_device(rdev, wdev);
Johannes Berg98104fde2012-06-16 00:19:54 +02009010
9011 return 0;
9012}
9013
Johannes Berg3713b4e2013-02-14 16:19:38 +01009014static int nl80211_get_protocol_features(struct sk_buff *skb,
9015 struct genl_info *info)
9016{
9017 void *hdr;
9018 struct sk_buff *msg;
9019
9020 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
9021 if (!msg)
9022 return -ENOMEM;
9023
9024 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
9025 NL80211_CMD_GET_PROTOCOL_FEATURES);
9026 if (!hdr)
9027 goto nla_put_failure;
9028
9029 if (nla_put_u32(msg, NL80211_ATTR_PROTOCOL_FEATURES,
9030 NL80211_PROTOCOL_FEATURE_SPLIT_WIPHY_DUMP))
9031 goto nla_put_failure;
9032
9033 genlmsg_end(msg, hdr);
9034 return genlmsg_reply(msg, info);
9035
9036 nla_put_failure:
9037 kfree_skb(msg);
9038 return -ENOBUFS;
9039}
9040
Jouni Malinen355199e2013-02-27 17:14:27 +02009041static int nl80211_update_ft_ies(struct sk_buff *skb, struct genl_info *info)
9042{
9043 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9044 struct cfg80211_update_ft_ies_params ft_params;
9045 struct net_device *dev = info->user_ptr[1];
9046
9047 if (!rdev->ops->update_ft_ies)
9048 return -EOPNOTSUPP;
9049
9050 if (!info->attrs[NL80211_ATTR_MDID] ||
9051 !is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
9052 return -EINVAL;
9053
9054 memset(&ft_params, 0, sizeof(ft_params));
9055 ft_params.md = nla_get_u16(info->attrs[NL80211_ATTR_MDID]);
9056 ft_params.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
9057 ft_params.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
9058
9059 return rdev_update_ft_ies(rdev, dev, &ft_params);
9060}
9061
Arend van Spriel5de17982013-04-18 15:49:00 +02009062static int nl80211_crit_protocol_start(struct sk_buff *skb,
9063 struct genl_info *info)
9064{
9065 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9066 struct wireless_dev *wdev = info->user_ptr[1];
9067 enum nl80211_crit_proto_id proto = NL80211_CRIT_PROTO_UNSPEC;
9068 u16 duration;
9069 int ret;
9070
9071 if (!rdev->ops->crit_proto_start)
9072 return -EOPNOTSUPP;
9073
9074 if (WARN_ON(!rdev->ops->crit_proto_stop))
9075 return -EINVAL;
9076
9077 if (rdev->crit_proto_nlportid)
9078 return -EBUSY;
9079
9080 /* determine protocol if provided */
9081 if (info->attrs[NL80211_ATTR_CRIT_PROT_ID])
9082 proto = nla_get_u16(info->attrs[NL80211_ATTR_CRIT_PROT_ID]);
9083
9084 if (proto >= NUM_NL80211_CRIT_PROTO)
9085 return -EINVAL;
9086
9087 /* timeout must be provided */
9088 if (!info->attrs[NL80211_ATTR_MAX_CRIT_PROT_DURATION])
9089 return -EINVAL;
9090
9091 duration =
9092 nla_get_u16(info->attrs[NL80211_ATTR_MAX_CRIT_PROT_DURATION]);
9093
9094 if (duration > NL80211_CRIT_PROTO_MAX_DURATION)
9095 return -ERANGE;
9096
9097 ret = rdev_crit_proto_start(rdev, wdev, proto, duration);
9098 if (!ret)
9099 rdev->crit_proto_nlportid = info->snd_portid;
9100
9101 return ret;
9102}
9103
9104static int nl80211_crit_protocol_stop(struct sk_buff *skb,
9105 struct genl_info *info)
9106{
9107 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9108 struct wireless_dev *wdev = info->user_ptr[1];
9109
9110 if (!rdev->ops->crit_proto_stop)
9111 return -EOPNOTSUPP;
9112
9113 if (rdev->crit_proto_nlportid) {
9114 rdev->crit_proto_nlportid = 0;
9115 rdev_crit_proto_stop(rdev, wdev);
9116 }
9117 return 0;
9118}
9119
Johannes Bergad7e7182013-11-13 13:37:47 +01009120static int nl80211_vendor_cmd(struct sk_buff *skb, struct genl_info *info)
9121{
9122 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9123 struct wireless_dev *wdev =
9124 __cfg80211_wdev_from_attrs(genl_info_net(info), info->attrs);
9125 int i, err;
9126 u32 vid, subcmd;
9127
9128 if (!rdev->wiphy.vendor_commands)
9129 return -EOPNOTSUPP;
9130
9131 if (IS_ERR(wdev)) {
9132 err = PTR_ERR(wdev);
9133 if (err != -EINVAL)
9134 return err;
9135 wdev = NULL;
9136 } else if (wdev->wiphy != &rdev->wiphy) {
9137 return -EINVAL;
9138 }
9139
9140 if (!info->attrs[NL80211_ATTR_VENDOR_ID] ||
9141 !info->attrs[NL80211_ATTR_VENDOR_SUBCMD])
9142 return -EINVAL;
9143
9144 vid = nla_get_u32(info->attrs[NL80211_ATTR_VENDOR_ID]);
9145 subcmd = nla_get_u32(info->attrs[NL80211_ATTR_VENDOR_SUBCMD]);
9146 for (i = 0; i < rdev->wiphy.n_vendor_commands; i++) {
9147 const struct wiphy_vendor_command *vcmd;
9148 void *data = NULL;
9149 int len = 0;
9150
9151 vcmd = &rdev->wiphy.vendor_commands[i];
9152
9153 if (vcmd->info.vendor_id != vid || vcmd->info.subcmd != subcmd)
9154 continue;
9155
9156 if (vcmd->flags & (WIPHY_VENDOR_CMD_NEED_WDEV |
9157 WIPHY_VENDOR_CMD_NEED_NETDEV)) {
9158 if (!wdev)
9159 return -EINVAL;
9160 if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_NETDEV &&
9161 !wdev->netdev)
9162 return -EINVAL;
9163
9164 if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_RUNNING) {
9165 if (wdev->netdev &&
9166 !netif_running(wdev->netdev))
9167 return -ENETDOWN;
9168 if (!wdev->netdev && !wdev->p2p_started)
9169 return -ENETDOWN;
9170 }
9171 } else {
9172 wdev = NULL;
9173 }
9174
9175 if (info->attrs[NL80211_ATTR_VENDOR_DATA]) {
9176 data = nla_data(info->attrs[NL80211_ATTR_VENDOR_DATA]);
9177 len = nla_len(info->attrs[NL80211_ATTR_VENDOR_DATA]);
9178 }
9179
9180 rdev->cur_cmd_info = info;
9181 err = rdev->wiphy.vendor_commands[i].doit(&rdev->wiphy, wdev,
9182 data, len);
9183 rdev->cur_cmd_info = NULL;
9184 return err;
9185 }
9186
9187 return -EOPNOTSUPP;
9188}
9189
9190struct sk_buff *__cfg80211_alloc_reply_skb(struct wiphy *wiphy,
9191 enum nl80211_commands cmd,
9192 enum nl80211_attrs attr,
9193 int approxlen)
9194{
Zhao, Gangf26cbf42014-04-21 12:53:03 +08009195 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Bergad7e7182013-11-13 13:37:47 +01009196
9197 if (WARN_ON(!rdev->cur_cmd_info))
9198 return NULL;
9199
9200 return __cfg80211_alloc_vendor_skb(rdev, approxlen,
9201 rdev->cur_cmd_info->snd_portid,
9202 rdev->cur_cmd_info->snd_seq,
Johannes Berg567ffc32013-12-18 14:43:31 +01009203 cmd, attr, NULL, GFP_KERNEL);
Johannes Bergad7e7182013-11-13 13:37:47 +01009204}
9205EXPORT_SYMBOL(__cfg80211_alloc_reply_skb);
9206
9207int cfg80211_vendor_cmd_reply(struct sk_buff *skb)
9208{
9209 struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0];
9210 void *hdr = ((void **)skb->cb)[1];
9211 struct nlattr *data = ((void **)skb->cb)[2];
9212
9213 if (WARN_ON(!rdev->cur_cmd_info)) {
9214 kfree_skb(skb);
9215 return -EINVAL;
9216 }
9217
9218 nla_nest_end(skb, data);
9219 genlmsg_end(skb, hdr);
9220 return genlmsg_reply(skb, rdev->cur_cmd_info);
9221}
9222EXPORT_SYMBOL_GPL(cfg80211_vendor_cmd_reply);
9223
9224
Kyeyoon Parkfa9ffc72013-12-16 23:01:30 -08009225static int nl80211_set_qos_map(struct sk_buff *skb,
9226 struct genl_info *info)
9227{
9228 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9229 struct cfg80211_qos_map *qos_map = NULL;
9230 struct net_device *dev = info->user_ptr[1];
9231 u8 *pos, len, num_des, des_len, des;
9232 int ret;
9233
9234 if (!rdev->ops->set_qos_map)
9235 return -EOPNOTSUPP;
9236
9237 if (info->attrs[NL80211_ATTR_QOS_MAP]) {
9238 pos = nla_data(info->attrs[NL80211_ATTR_QOS_MAP]);
9239 len = nla_len(info->attrs[NL80211_ATTR_QOS_MAP]);
9240
9241 if (len % 2 || len < IEEE80211_QOS_MAP_LEN_MIN ||
9242 len > IEEE80211_QOS_MAP_LEN_MAX)
9243 return -EINVAL;
9244
9245 qos_map = kzalloc(sizeof(struct cfg80211_qos_map), GFP_KERNEL);
9246 if (!qos_map)
9247 return -ENOMEM;
9248
9249 num_des = (len - IEEE80211_QOS_MAP_LEN_MIN) >> 1;
9250 if (num_des) {
9251 des_len = num_des *
9252 sizeof(struct cfg80211_dscp_exception);
9253 memcpy(qos_map->dscp_exception, pos, des_len);
9254 qos_map->num_des = num_des;
9255 for (des = 0; des < num_des; des++) {
9256 if (qos_map->dscp_exception[des].up > 7) {
9257 kfree(qos_map);
9258 return -EINVAL;
9259 }
9260 }
9261 pos += des_len;
9262 }
9263 memcpy(qos_map->up, pos, IEEE80211_QOS_MAP_LEN_MIN);
9264 }
9265
9266 wdev_lock(dev->ieee80211_ptr);
9267 ret = nl80211_key_allowed(dev->ieee80211_ptr);
9268 if (!ret)
9269 ret = rdev_set_qos_map(rdev, dev, qos_map);
9270 wdev_unlock(dev->ieee80211_ptr);
9271
9272 kfree(qos_map);
9273 return ret;
9274}
9275
Johannes Berg4c476992010-10-04 21:36:35 +02009276#define NL80211_FLAG_NEED_WIPHY 0x01
9277#define NL80211_FLAG_NEED_NETDEV 0x02
9278#define NL80211_FLAG_NEED_RTNL 0x04
Johannes Berg41265712010-10-04 21:14:05 +02009279#define NL80211_FLAG_CHECK_NETDEV_UP 0x08
9280#define NL80211_FLAG_NEED_NETDEV_UP (NL80211_FLAG_NEED_NETDEV |\
9281 NL80211_FLAG_CHECK_NETDEV_UP)
Johannes Berg1bf614e2012-06-15 15:23:36 +02009282#define NL80211_FLAG_NEED_WDEV 0x10
Johannes Berg98104fde2012-06-16 00:19:54 +02009283/* If a netdev is associated, it must be UP, P2P must be started */
Johannes Berg1bf614e2012-06-15 15:23:36 +02009284#define NL80211_FLAG_NEED_WDEV_UP (NL80211_FLAG_NEED_WDEV |\
9285 NL80211_FLAG_CHECK_NETDEV_UP)
Johannes Berg4c476992010-10-04 21:36:35 +02009286
Johannes Bergf84f7712013-11-14 17:14:45 +01009287static int nl80211_pre_doit(const struct genl_ops *ops, struct sk_buff *skb,
Johannes Berg4c476992010-10-04 21:36:35 +02009288 struct genl_info *info)
9289{
9290 struct cfg80211_registered_device *rdev;
Johannes Berg89a54e42012-06-15 14:33:17 +02009291 struct wireless_dev *wdev;
Johannes Berg4c476992010-10-04 21:36:35 +02009292 struct net_device *dev;
Johannes Berg4c476992010-10-04 21:36:35 +02009293 bool rtnl = ops->internal_flags & NL80211_FLAG_NEED_RTNL;
9294
9295 if (rtnl)
9296 rtnl_lock();
9297
9298 if (ops->internal_flags & NL80211_FLAG_NEED_WIPHY) {
Johannes Berg4f7eff12012-06-15 14:14:22 +02009299 rdev = cfg80211_get_dev_from_info(genl_info_net(info), info);
Johannes Berg4c476992010-10-04 21:36:35 +02009300 if (IS_ERR(rdev)) {
9301 if (rtnl)
9302 rtnl_unlock();
9303 return PTR_ERR(rdev);
9304 }
9305 info->user_ptr[0] = rdev;
Johannes Berg1bf614e2012-06-15 15:23:36 +02009306 } else if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV ||
9307 ops->internal_flags & NL80211_FLAG_NEED_WDEV) {
Johannes Berg5fe231e2013-05-08 21:45:15 +02009308 ASSERT_RTNL();
9309
Johannes Berg89a54e42012-06-15 14:33:17 +02009310 wdev = __cfg80211_wdev_from_attrs(genl_info_net(info),
9311 info->attrs);
9312 if (IS_ERR(wdev)) {
Johannes Berg4c476992010-10-04 21:36:35 +02009313 if (rtnl)
9314 rtnl_unlock();
Johannes Berg89a54e42012-06-15 14:33:17 +02009315 return PTR_ERR(wdev);
Johannes Berg4c476992010-10-04 21:36:35 +02009316 }
Johannes Berg89a54e42012-06-15 14:33:17 +02009317
Johannes Berg89a54e42012-06-15 14:33:17 +02009318 dev = wdev->netdev;
Zhao, Gangf26cbf42014-04-21 12:53:03 +08009319 rdev = wiphy_to_rdev(wdev->wiphy);
Johannes Berg89a54e42012-06-15 14:33:17 +02009320
Johannes Berg1bf614e2012-06-15 15:23:36 +02009321 if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV) {
9322 if (!dev) {
Johannes Berg1bf614e2012-06-15 15:23:36 +02009323 if (rtnl)
9324 rtnl_unlock();
9325 return -EINVAL;
9326 }
9327
9328 info->user_ptr[1] = dev;
9329 } else {
9330 info->user_ptr[1] = wdev;
Johannes Berg41265712010-10-04 21:14:05 +02009331 }
Johannes Berg89a54e42012-06-15 14:33:17 +02009332
Johannes Berg1bf614e2012-06-15 15:23:36 +02009333 if (dev) {
9334 if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP &&
9335 !netif_running(dev)) {
Johannes Berg1bf614e2012-06-15 15:23:36 +02009336 if (rtnl)
9337 rtnl_unlock();
9338 return -ENETDOWN;
9339 }
9340
9341 dev_hold(dev);
Johannes Berg98104fde2012-06-16 00:19:54 +02009342 } else if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP) {
9343 if (!wdev->p2p_started) {
Johannes Berg98104fde2012-06-16 00:19:54 +02009344 if (rtnl)
9345 rtnl_unlock();
9346 return -ENETDOWN;
9347 }
Johannes Berg1bf614e2012-06-15 15:23:36 +02009348 }
9349
Johannes Berg4c476992010-10-04 21:36:35 +02009350 info->user_ptr[0] = rdev;
Johannes Berg4c476992010-10-04 21:36:35 +02009351 }
9352
9353 return 0;
9354}
9355
Johannes Bergf84f7712013-11-14 17:14:45 +01009356static void nl80211_post_doit(const struct genl_ops *ops, struct sk_buff *skb,
Johannes Berg4c476992010-10-04 21:36:35 +02009357 struct genl_info *info)
9358{
Johannes Berg1bf614e2012-06-15 15:23:36 +02009359 if (info->user_ptr[1]) {
9360 if (ops->internal_flags & NL80211_FLAG_NEED_WDEV) {
9361 struct wireless_dev *wdev = info->user_ptr[1];
9362
9363 if (wdev->netdev)
9364 dev_put(wdev->netdev);
9365 } else {
9366 dev_put(info->user_ptr[1]);
9367 }
9368 }
Johannes Berg4c476992010-10-04 21:36:35 +02009369 if (ops->internal_flags & NL80211_FLAG_NEED_RTNL)
9370 rtnl_unlock();
9371}
9372
Johannes Berg4534de82013-11-14 17:14:46 +01009373static const struct genl_ops nl80211_ops[] = {
Johannes Berg55682962007-09-20 13:09:35 -04009374 {
9375 .cmd = NL80211_CMD_GET_WIPHY,
9376 .doit = nl80211_get_wiphy,
9377 .dumpit = nl80211_dump_wiphy,
Johannes Berg86e8cf92013-06-19 10:57:22 +02009378 .done = nl80211_dump_wiphy_done,
Johannes Berg55682962007-09-20 13:09:35 -04009379 .policy = nl80211_policy,
9380 /* can be retrieved by unprivileged users */
Johannes Berg5fe231e2013-05-08 21:45:15 +02009381 .internal_flags = NL80211_FLAG_NEED_WIPHY |
9382 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -04009383 },
9384 {
9385 .cmd = NL80211_CMD_SET_WIPHY,
9386 .doit = nl80211_set_wiphy,
9387 .policy = nl80211_policy,
9388 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02009389 .internal_flags = NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -04009390 },
9391 {
9392 .cmd = NL80211_CMD_GET_INTERFACE,
9393 .doit = nl80211_get_interface,
9394 .dumpit = nl80211_dump_interface,
9395 .policy = nl80211_policy,
9396 /* can be retrieved by unprivileged users */
Johannes Berg5fe231e2013-05-08 21:45:15 +02009397 .internal_flags = NL80211_FLAG_NEED_WDEV |
9398 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -04009399 },
9400 {
9401 .cmd = NL80211_CMD_SET_INTERFACE,
9402 .doit = nl80211_set_interface,
9403 .policy = nl80211_policy,
9404 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02009405 .internal_flags = NL80211_FLAG_NEED_NETDEV |
9406 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -04009407 },
9408 {
9409 .cmd = NL80211_CMD_NEW_INTERFACE,
9410 .doit = nl80211_new_interface,
9411 .policy = nl80211_policy,
9412 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02009413 .internal_flags = NL80211_FLAG_NEED_WIPHY |
9414 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -04009415 },
9416 {
9417 .cmd = NL80211_CMD_DEL_INTERFACE,
9418 .doit = nl80211_del_interface,
9419 .policy = nl80211_policy,
9420 .flags = GENL_ADMIN_PERM,
Johannes Berg84efbb82012-06-16 00:00:26 +02009421 .internal_flags = NL80211_FLAG_NEED_WDEV |
Johannes Berg4c476992010-10-04 21:36:35 +02009422 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -04009423 },
Johannes Berg41ade002007-12-19 02:03:29 +01009424 {
9425 .cmd = NL80211_CMD_GET_KEY,
9426 .doit = nl80211_get_key,
9427 .policy = nl80211_policy,
9428 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02009429 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009430 NL80211_FLAG_NEED_RTNL,
Johannes Berg41ade002007-12-19 02:03:29 +01009431 },
9432 {
9433 .cmd = NL80211_CMD_SET_KEY,
9434 .doit = nl80211_set_key,
9435 .policy = nl80211_policy,
9436 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02009437 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009438 NL80211_FLAG_NEED_RTNL,
Johannes Berg41ade002007-12-19 02:03:29 +01009439 },
9440 {
9441 .cmd = NL80211_CMD_NEW_KEY,
9442 .doit = nl80211_new_key,
9443 .policy = nl80211_policy,
9444 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02009445 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009446 NL80211_FLAG_NEED_RTNL,
Johannes Berg41ade002007-12-19 02:03:29 +01009447 },
9448 {
9449 .cmd = NL80211_CMD_DEL_KEY,
9450 .doit = nl80211_del_key,
9451 .policy = nl80211_policy,
9452 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02009453 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009454 NL80211_FLAG_NEED_RTNL,
Johannes Berg41ade002007-12-19 02:03:29 +01009455 },
Johannes Berged1b6cc2007-12-19 02:03:32 +01009456 {
9457 .cmd = NL80211_CMD_SET_BEACON,
9458 .policy = nl80211_policy,
9459 .flags = GENL_ADMIN_PERM,
Johannes Berg88600202012-02-13 15:17:18 +01009460 .doit = nl80211_set_beacon,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02009461 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009462 NL80211_FLAG_NEED_RTNL,
Johannes Berged1b6cc2007-12-19 02:03:32 +01009463 },
9464 {
Johannes Berg88600202012-02-13 15:17:18 +01009465 .cmd = NL80211_CMD_START_AP,
Johannes Berged1b6cc2007-12-19 02:03:32 +01009466 .policy = nl80211_policy,
9467 .flags = GENL_ADMIN_PERM,
Johannes Berg88600202012-02-13 15:17:18 +01009468 .doit = nl80211_start_ap,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02009469 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009470 NL80211_FLAG_NEED_RTNL,
Johannes Berged1b6cc2007-12-19 02:03:32 +01009471 },
9472 {
Johannes Berg88600202012-02-13 15:17:18 +01009473 .cmd = NL80211_CMD_STOP_AP,
Johannes Berged1b6cc2007-12-19 02:03:32 +01009474 .policy = nl80211_policy,
9475 .flags = GENL_ADMIN_PERM,
Johannes Berg88600202012-02-13 15:17:18 +01009476 .doit = nl80211_stop_ap,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02009477 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009478 NL80211_FLAG_NEED_RTNL,
Johannes Berged1b6cc2007-12-19 02:03:32 +01009479 },
Johannes Berg5727ef12007-12-19 02:03:34 +01009480 {
9481 .cmd = NL80211_CMD_GET_STATION,
9482 .doit = nl80211_get_station,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01009483 .dumpit = nl80211_dump_station,
Johannes Berg5727ef12007-12-19 02:03:34 +01009484 .policy = nl80211_policy,
Johannes Berg4c476992010-10-04 21:36:35 +02009485 .internal_flags = NL80211_FLAG_NEED_NETDEV |
9486 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +01009487 },
9488 {
9489 .cmd = NL80211_CMD_SET_STATION,
9490 .doit = nl80211_set_station,
9491 .policy = nl80211_policy,
9492 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02009493 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009494 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +01009495 },
9496 {
9497 .cmd = NL80211_CMD_NEW_STATION,
9498 .doit = nl80211_new_station,
9499 .policy = nl80211_policy,
9500 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02009501 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009502 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +01009503 },
9504 {
9505 .cmd = NL80211_CMD_DEL_STATION,
9506 .doit = nl80211_del_station,
9507 .policy = nl80211_policy,
9508 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02009509 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009510 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +01009511 },
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01009512 {
9513 .cmd = NL80211_CMD_GET_MPATH,
9514 .doit = nl80211_get_mpath,
9515 .dumpit = nl80211_dump_mpath,
9516 .policy = nl80211_policy,
9517 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02009518 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009519 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01009520 },
9521 {
9522 .cmd = NL80211_CMD_SET_MPATH,
9523 .doit = nl80211_set_mpath,
9524 .policy = nl80211_policy,
9525 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02009526 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009527 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01009528 },
9529 {
9530 .cmd = NL80211_CMD_NEW_MPATH,
9531 .doit = nl80211_new_mpath,
9532 .policy = nl80211_policy,
9533 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02009534 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009535 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01009536 },
9537 {
9538 .cmd = NL80211_CMD_DEL_MPATH,
9539 .doit = nl80211_del_mpath,
9540 .policy = nl80211_policy,
9541 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02009542 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009543 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01009544 },
Jouni Malinen9f1ba902008-08-07 20:07:01 +03009545 {
9546 .cmd = NL80211_CMD_SET_BSS,
9547 .doit = nl80211_set_bss,
9548 .policy = nl80211_policy,
9549 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02009550 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009551 NL80211_FLAG_NEED_RTNL,
Jouni Malinen9f1ba902008-08-07 20:07:01 +03009552 },
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07009553 {
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08009554 .cmd = NL80211_CMD_GET_REG,
9555 .doit = nl80211_get_reg,
9556 .policy = nl80211_policy,
Johannes Berg5fe231e2013-05-08 21:45:15 +02009557 .internal_flags = NL80211_FLAG_NEED_RTNL,
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08009558 /* can be retrieved by unprivileged users */
9559 },
9560 {
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07009561 .cmd = NL80211_CMD_SET_REG,
9562 .doit = nl80211_set_reg,
9563 .policy = nl80211_policy,
9564 .flags = GENL_ADMIN_PERM,
Johannes Berg5fe231e2013-05-08 21:45:15 +02009565 .internal_flags = NL80211_FLAG_NEED_RTNL,
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07009566 },
9567 {
9568 .cmd = NL80211_CMD_REQ_SET_REG,
9569 .doit = nl80211_req_set_reg,
9570 .policy = nl80211_policy,
9571 .flags = GENL_ADMIN_PERM,
9572 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07009573 {
Javier Cardona24bdd9f2010-12-16 17:37:48 -08009574 .cmd = NL80211_CMD_GET_MESH_CONFIG,
9575 .doit = nl80211_get_mesh_config,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07009576 .policy = nl80211_policy,
9577 /* can be retrieved by unprivileged users */
Johannes Berg2b5f8b02012-04-02 10:51:55 +02009578 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009579 NL80211_FLAG_NEED_RTNL,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07009580 },
9581 {
Javier Cardona24bdd9f2010-12-16 17:37:48 -08009582 .cmd = NL80211_CMD_SET_MESH_CONFIG,
9583 .doit = nl80211_update_mesh_config,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07009584 .policy = nl80211_policy,
9585 .flags = GENL_ADMIN_PERM,
Johannes Berg29cbe682010-12-03 09:20:44 +01009586 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009587 NL80211_FLAG_NEED_RTNL,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07009588 },
Jouni Malinen9aed3cc2009-01-13 16:03:29 +02009589 {
Johannes Berg2a519312009-02-10 21:25:55 +01009590 .cmd = NL80211_CMD_TRIGGER_SCAN,
9591 .doit = nl80211_trigger_scan,
9592 .policy = nl80211_policy,
9593 .flags = GENL_ADMIN_PERM,
Johannes Bergfd014282012-06-18 19:17:03 +02009594 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009595 NL80211_FLAG_NEED_RTNL,
Johannes Berg2a519312009-02-10 21:25:55 +01009596 },
9597 {
9598 .cmd = NL80211_CMD_GET_SCAN,
9599 .policy = nl80211_policy,
9600 .dumpit = nl80211_dump_scan,
9601 },
Jouni Malinen636a5d32009-03-19 13:39:22 +02009602 {
Luciano Coelho807f8a82011-05-11 17:09:35 +03009603 .cmd = NL80211_CMD_START_SCHED_SCAN,
9604 .doit = nl80211_start_sched_scan,
9605 .policy = nl80211_policy,
9606 .flags = GENL_ADMIN_PERM,
9607 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
9608 NL80211_FLAG_NEED_RTNL,
9609 },
9610 {
9611 .cmd = NL80211_CMD_STOP_SCHED_SCAN,
9612 .doit = nl80211_stop_sched_scan,
9613 .policy = nl80211_policy,
9614 .flags = GENL_ADMIN_PERM,
9615 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
9616 NL80211_FLAG_NEED_RTNL,
9617 },
9618 {
Jouni Malinen636a5d32009-03-19 13:39:22 +02009619 .cmd = NL80211_CMD_AUTHENTICATE,
9620 .doit = nl80211_authenticate,
9621 .policy = nl80211_policy,
9622 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02009623 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009624 NL80211_FLAG_NEED_RTNL,
Jouni Malinen636a5d32009-03-19 13:39:22 +02009625 },
9626 {
9627 .cmd = NL80211_CMD_ASSOCIATE,
9628 .doit = nl80211_associate,
9629 .policy = nl80211_policy,
9630 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02009631 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009632 NL80211_FLAG_NEED_RTNL,
Jouni Malinen636a5d32009-03-19 13:39:22 +02009633 },
9634 {
9635 .cmd = NL80211_CMD_DEAUTHENTICATE,
9636 .doit = nl80211_deauthenticate,
9637 .policy = nl80211_policy,
9638 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02009639 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009640 NL80211_FLAG_NEED_RTNL,
Jouni Malinen636a5d32009-03-19 13:39:22 +02009641 },
9642 {
9643 .cmd = NL80211_CMD_DISASSOCIATE,
9644 .doit = nl80211_disassociate,
9645 .policy = nl80211_policy,
9646 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02009647 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009648 NL80211_FLAG_NEED_RTNL,
Jouni Malinen636a5d32009-03-19 13:39:22 +02009649 },
Johannes Berg04a773a2009-04-19 21:24:32 +02009650 {
9651 .cmd = NL80211_CMD_JOIN_IBSS,
9652 .doit = nl80211_join_ibss,
9653 .policy = nl80211_policy,
9654 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02009655 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009656 NL80211_FLAG_NEED_RTNL,
Johannes Berg04a773a2009-04-19 21:24:32 +02009657 },
9658 {
9659 .cmd = NL80211_CMD_LEAVE_IBSS,
9660 .doit = nl80211_leave_ibss,
9661 .policy = nl80211_policy,
9662 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02009663 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009664 NL80211_FLAG_NEED_RTNL,
Johannes Berg04a773a2009-04-19 21:24:32 +02009665 },
Johannes Bergaff89a92009-07-01 21:26:51 +02009666#ifdef CONFIG_NL80211_TESTMODE
9667 {
9668 .cmd = NL80211_CMD_TESTMODE,
9669 .doit = nl80211_testmode_do,
Wey-Yi Guy71063f02011-05-20 09:05:54 -07009670 .dumpit = nl80211_testmode_dump,
Johannes Bergaff89a92009-07-01 21:26:51 +02009671 .policy = nl80211_policy,
9672 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02009673 .internal_flags = NL80211_FLAG_NEED_WIPHY |
9674 NL80211_FLAG_NEED_RTNL,
Johannes Bergaff89a92009-07-01 21:26:51 +02009675 },
9676#endif
Samuel Ortizb23aa672009-07-01 21:26:54 +02009677 {
9678 .cmd = NL80211_CMD_CONNECT,
9679 .doit = nl80211_connect,
9680 .policy = nl80211_policy,
9681 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02009682 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009683 NL80211_FLAG_NEED_RTNL,
Samuel Ortizb23aa672009-07-01 21:26:54 +02009684 },
9685 {
9686 .cmd = NL80211_CMD_DISCONNECT,
9687 .doit = nl80211_disconnect,
9688 .policy = nl80211_policy,
9689 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02009690 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009691 NL80211_FLAG_NEED_RTNL,
Samuel Ortizb23aa672009-07-01 21:26:54 +02009692 },
Johannes Berg463d0182009-07-14 00:33:35 +02009693 {
9694 .cmd = NL80211_CMD_SET_WIPHY_NETNS,
9695 .doit = nl80211_wiphy_netns,
9696 .policy = nl80211_policy,
9697 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02009698 .internal_flags = NL80211_FLAG_NEED_WIPHY |
9699 NL80211_FLAG_NEED_RTNL,
Johannes Berg463d0182009-07-14 00:33:35 +02009700 },
Holger Schurig61fa7132009-11-11 12:25:40 +01009701 {
9702 .cmd = NL80211_CMD_GET_SURVEY,
9703 .policy = nl80211_policy,
9704 .dumpit = nl80211_dump_survey,
9705 },
Samuel Ortiz67fbb162009-11-24 23:59:15 +01009706 {
9707 .cmd = NL80211_CMD_SET_PMKSA,
9708 .doit = nl80211_setdel_pmksa,
9709 .policy = nl80211_policy,
9710 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02009711 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009712 NL80211_FLAG_NEED_RTNL,
Samuel Ortiz67fbb162009-11-24 23:59:15 +01009713 },
9714 {
9715 .cmd = NL80211_CMD_DEL_PMKSA,
9716 .doit = nl80211_setdel_pmksa,
9717 .policy = nl80211_policy,
9718 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02009719 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009720 NL80211_FLAG_NEED_RTNL,
Samuel Ortiz67fbb162009-11-24 23:59:15 +01009721 },
9722 {
9723 .cmd = NL80211_CMD_FLUSH_PMKSA,
9724 .doit = nl80211_flush_pmksa,
9725 .policy = nl80211_policy,
9726 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02009727 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009728 NL80211_FLAG_NEED_RTNL,
Samuel Ortiz67fbb162009-11-24 23:59:15 +01009729 },
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009730 {
9731 .cmd = NL80211_CMD_REMAIN_ON_CHANNEL,
9732 .doit = nl80211_remain_on_channel,
9733 .policy = nl80211_policy,
9734 .flags = GENL_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +02009735 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009736 NL80211_FLAG_NEED_RTNL,
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009737 },
9738 {
9739 .cmd = NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL,
9740 .doit = nl80211_cancel_remain_on_channel,
9741 .policy = nl80211_policy,
9742 .flags = GENL_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +02009743 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009744 NL80211_FLAG_NEED_RTNL,
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009745 },
Jouni Malinen13ae75b2009-12-29 12:59:45 +02009746 {
9747 .cmd = NL80211_CMD_SET_TX_BITRATE_MASK,
9748 .doit = nl80211_set_tx_bitrate_mask,
9749 .policy = nl80211_policy,
9750 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02009751 .internal_flags = NL80211_FLAG_NEED_NETDEV |
9752 NL80211_FLAG_NEED_RTNL,
Jouni Malinen13ae75b2009-12-29 12:59:45 +02009753 },
Jouni Malinen026331c2010-02-15 12:53:10 +02009754 {
Johannes Berg2e161f72010-08-12 15:38:38 +02009755 .cmd = NL80211_CMD_REGISTER_FRAME,
9756 .doit = nl80211_register_mgmt,
Jouni Malinen026331c2010-02-15 12:53:10 +02009757 .policy = nl80211_policy,
9758 .flags = GENL_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +02009759 .internal_flags = NL80211_FLAG_NEED_WDEV |
Johannes Berg4c476992010-10-04 21:36:35 +02009760 NL80211_FLAG_NEED_RTNL,
Jouni Malinen026331c2010-02-15 12:53:10 +02009761 },
9762 {
Johannes Berg2e161f72010-08-12 15:38:38 +02009763 .cmd = NL80211_CMD_FRAME,
9764 .doit = nl80211_tx_mgmt,
Jouni Malinen026331c2010-02-15 12:53:10 +02009765 .policy = nl80211_policy,
9766 .flags = GENL_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +02009767 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009768 NL80211_FLAG_NEED_RTNL,
Jouni Malinen026331c2010-02-15 12:53:10 +02009769 },
Kalle Valoffb9eb32010-02-17 17:58:10 +02009770 {
Johannes Bergf7ca38d2010-11-25 10:02:29 +01009771 .cmd = NL80211_CMD_FRAME_WAIT_CANCEL,
9772 .doit = nl80211_tx_mgmt_cancel_wait,
9773 .policy = nl80211_policy,
9774 .flags = GENL_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +02009775 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Bergf7ca38d2010-11-25 10:02:29 +01009776 NL80211_FLAG_NEED_RTNL,
9777 },
9778 {
Kalle Valoffb9eb32010-02-17 17:58:10 +02009779 .cmd = NL80211_CMD_SET_POWER_SAVE,
9780 .doit = nl80211_set_power_save,
9781 .policy = nl80211_policy,
9782 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02009783 .internal_flags = NL80211_FLAG_NEED_NETDEV |
9784 NL80211_FLAG_NEED_RTNL,
Kalle Valoffb9eb32010-02-17 17:58:10 +02009785 },
9786 {
9787 .cmd = NL80211_CMD_GET_POWER_SAVE,
9788 .doit = nl80211_get_power_save,
9789 .policy = nl80211_policy,
9790 /* can be retrieved by unprivileged users */
Johannes Berg4c476992010-10-04 21:36:35 +02009791 .internal_flags = NL80211_FLAG_NEED_NETDEV |
9792 NL80211_FLAG_NEED_RTNL,
Kalle Valoffb9eb32010-02-17 17:58:10 +02009793 },
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02009794 {
9795 .cmd = NL80211_CMD_SET_CQM,
9796 .doit = nl80211_set_cqm,
9797 .policy = nl80211_policy,
9798 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02009799 .internal_flags = NL80211_FLAG_NEED_NETDEV |
9800 NL80211_FLAG_NEED_RTNL,
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02009801 },
Johannes Bergf444de02010-05-05 15:25:02 +02009802 {
9803 .cmd = NL80211_CMD_SET_CHANNEL,
9804 .doit = nl80211_set_channel,
9805 .policy = nl80211_policy,
9806 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02009807 .internal_flags = NL80211_FLAG_NEED_NETDEV |
9808 NL80211_FLAG_NEED_RTNL,
Johannes Bergf444de02010-05-05 15:25:02 +02009809 },
Bill Jordane8347eb2010-10-01 13:54:28 -04009810 {
9811 .cmd = NL80211_CMD_SET_WDS_PEER,
9812 .doit = nl80211_set_wds_peer,
9813 .policy = nl80211_policy,
9814 .flags = GENL_ADMIN_PERM,
Johannes Berg43b19952010-10-07 13:10:30 +02009815 .internal_flags = NL80211_FLAG_NEED_NETDEV |
9816 NL80211_FLAG_NEED_RTNL,
Bill Jordane8347eb2010-10-01 13:54:28 -04009817 },
Johannes Berg29cbe682010-12-03 09:20:44 +01009818 {
9819 .cmd = NL80211_CMD_JOIN_MESH,
9820 .doit = nl80211_join_mesh,
9821 .policy = nl80211_policy,
9822 .flags = GENL_ADMIN_PERM,
9823 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
9824 NL80211_FLAG_NEED_RTNL,
9825 },
9826 {
9827 .cmd = NL80211_CMD_LEAVE_MESH,
9828 .doit = nl80211_leave_mesh,
9829 .policy = nl80211_policy,
9830 .flags = GENL_ADMIN_PERM,
9831 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
9832 NL80211_FLAG_NEED_RTNL,
9833 },
Johannes Bergdfb89c52012-06-27 09:23:48 +02009834#ifdef CONFIG_PM
Johannes Bergff1b6e62011-05-04 15:37:28 +02009835 {
9836 .cmd = NL80211_CMD_GET_WOWLAN,
9837 .doit = nl80211_get_wowlan,
9838 .policy = nl80211_policy,
9839 /* can be retrieved by unprivileged users */
9840 .internal_flags = NL80211_FLAG_NEED_WIPHY |
9841 NL80211_FLAG_NEED_RTNL,
9842 },
9843 {
9844 .cmd = NL80211_CMD_SET_WOWLAN,
9845 .doit = nl80211_set_wowlan,
9846 .policy = nl80211_policy,
9847 .flags = GENL_ADMIN_PERM,
9848 .internal_flags = NL80211_FLAG_NEED_WIPHY |
9849 NL80211_FLAG_NEED_RTNL,
9850 },
Johannes Bergdfb89c52012-06-27 09:23:48 +02009851#endif
Johannes Berge5497d72011-07-05 16:35:40 +02009852 {
9853 .cmd = NL80211_CMD_SET_REKEY_OFFLOAD,
9854 .doit = nl80211_set_rekey_data,
9855 .policy = nl80211_policy,
9856 .flags = GENL_ADMIN_PERM,
9857 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
9858 NL80211_FLAG_NEED_RTNL,
9859 },
Arik Nemtsov109086c2011-09-28 14:12:50 +03009860 {
9861 .cmd = NL80211_CMD_TDLS_MGMT,
9862 .doit = nl80211_tdls_mgmt,
9863 .policy = nl80211_policy,
9864 .flags = GENL_ADMIN_PERM,
9865 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
9866 NL80211_FLAG_NEED_RTNL,
9867 },
9868 {
9869 .cmd = NL80211_CMD_TDLS_OPER,
9870 .doit = nl80211_tdls_oper,
9871 .policy = nl80211_policy,
9872 .flags = GENL_ADMIN_PERM,
9873 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
9874 NL80211_FLAG_NEED_RTNL,
9875 },
Johannes Berg28946da2011-11-04 11:18:12 +01009876 {
9877 .cmd = NL80211_CMD_UNEXPECTED_FRAME,
9878 .doit = nl80211_register_unexpected_frame,
9879 .policy = nl80211_policy,
9880 .flags = GENL_ADMIN_PERM,
9881 .internal_flags = NL80211_FLAG_NEED_NETDEV |
9882 NL80211_FLAG_NEED_RTNL,
9883 },
Johannes Berg7f6cf312011-11-04 11:18:15 +01009884 {
9885 .cmd = NL80211_CMD_PROBE_CLIENT,
9886 .doit = nl80211_probe_client,
9887 .policy = nl80211_policy,
9888 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02009889 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg7f6cf312011-11-04 11:18:15 +01009890 NL80211_FLAG_NEED_RTNL,
9891 },
Johannes Berg5e760232011-11-04 11:18:17 +01009892 {
9893 .cmd = NL80211_CMD_REGISTER_BEACONS,
9894 .doit = nl80211_register_beacons,
9895 .policy = nl80211_policy,
9896 .flags = GENL_ADMIN_PERM,
9897 .internal_flags = NL80211_FLAG_NEED_WIPHY |
9898 NL80211_FLAG_NEED_RTNL,
9899 },
Simon Wunderlich1d9d9212011-11-18 14:20:43 +01009900 {
9901 .cmd = NL80211_CMD_SET_NOACK_MAP,
9902 .doit = nl80211_set_noack_map,
9903 .policy = nl80211_policy,
9904 .flags = GENL_ADMIN_PERM,
9905 .internal_flags = NL80211_FLAG_NEED_NETDEV |
9906 NL80211_FLAG_NEED_RTNL,
9907 },
Johannes Berg98104fde2012-06-16 00:19:54 +02009908 {
9909 .cmd = NL80211_CMD_START_P2P_DEVICE,
9910 .doit = nl80211_start_p2p_device,
9911 .policy = nl80211_policy,
9912 .flags = GENL_ADMIN_PERM,
9913 .internal_flags = NL80211_FLAG_NEED_WDEV |
9914 NL80211_FLAG_NEED_RTNL,
9915 },
9916 {
9917 .cmd = NL80211_CMD_STOP_P2P_DEVICE,
9918 .doit = nl80211_stop_p2p_device,
9919 .policy = nl80211_policy,
9920 .flags = GENL_ADMIN_PERM,
9921 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
9922 NL80211_FLAG_NEED_RTNL,
9923 },
Antonio Quartullif4e583c2012-11-02 13:27:48 +01009924 {
9925 .cmd = NL80211_CMD_SET_MCAST_RATE,
9926 .doit = nl80211_set_mcast_rate,
9927 .policy = nl80211_policy,
9928 .flags = GENL_ADMIN_PERM,
9929 .internal_flags = NL80211_FLAG_NEED_NETDEV |
9930 NL80211_FLAG_NEED_RTNL,
9931 },
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +05309932 {
9933 .cmd = NL80211_CMD_SET_MAC_ACL,
9934 .doit = nl80211_set_mac_acl,
9935 .policy = nl80211_policy,
9936 .flags = GENL_ADMIN_PERM,
9937 .internal_flags = NL80211_FLAG_NEED_NETDEV |
9938 NL80211_FLAG_NEED_RTNL,
9939 },
Simon Wunderlich04f39042013-02-08 18:16:19 +01009940 {
9941 .cmd = NL80211_CMD_RADAR_DETECT,
9942 .doit = nl80211_start_radar_detection,
9943 .policy = nl80211_policy,
9944 .flags = GENL_ADMIN_PERM,
9945 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
9946 NL80211_FLAG_NEED_RTNL,
9947 },
Johannes Berg3713b4e2013-02-14 16:19:38 +01009948 {
9949 .cmd = NL80211_CMD_GET_PROTOCOL_FEATURES,
9950 .doit = nl80211_get_protocol_features,
9951 .policy = nl80211_policy,
9952 },
Jouni Malinen355199e2013-02-27 17:14:27 +02009953 {
9954 .cmd = NL80211_CMD_UPDATE_FT_IES,
9955 .doit = nl80211_update_ft_ies,
9956 .policy = nl80211_policy,
9957 .flags = GENL_ADMIN_PERM,
9958 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
9959 NL80211_FLAG_NEED_RTNL,
9960 },
Arend van Spriel5de17982013-04-18 15:49:00 +02009961 {
9962 .cmd = NL80211_CMD_CRIT_PROTOCOL_START,
9963 .doit = nl80211_crit_protocol_start,
9964 .policy = nl80211_policy,
9965 .flags = GENL_ADMIN_PERM,
9966 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
9967 NL80211_FLAG_NEED_RTNL,
9968 },
9969 {
9970 .cmd = NL80211_CMD_CRIT_PROTOCOL_STOP,
9971 .doit = nl80211_crit_protocol_stop,
9972 .policy = nl80211_policy,
9973 .flags = GENL_ADMIN_PERM,
9974 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
9975 NL80211_FLAG_NEED_RTNL,
Amitkumar Karwarbe29b992013-06-28 11:51:26 -07009976 },
9977 {
9978 .cmd = NL80211_CMD_GET_COALESCE,
9979 .doit = nl80211_get_coalesce,
9980 .policy = nl80211_policy,
9981 .internal_flags = NL80211_FLAG_NEED_WIPHY |
9982 NL80211_FLAG_NEED_RTNL,
9983 },
9984 {
9985 .cmd = NL80211_CMD_SET_COALESCE,
9986 .doit = nl80211_set_coalesce,
9987 .policy = nl80211_policy,
9988 .flags = GENL_ADMIN_PERM,
9989 .internal_flags = NL80211_FLAG_NEED_WIPHY |
9990 NL80211_FLAG_NEED_RTNL,
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02009991 },
9992 {
9993 .cmd = NL80211_CMD_CHANNEL_SWITCH,
9994 .doit = nl80211_channel_switch,
9995 .policy = nl80211_policy,
9996 .flags = GENL_ADMIN_PERM,
9997 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
9998 NL80211_FLAG_NEED_RTNL,
9999 },
Johannes Bergad7e7182013-11-13 13:37:47 +010010000 {
10001 .cmd = NL80211_CMD_VENDOR,
10002 .doit = nl80211_vendor_cmd,
10003 .policy = nl80211_policy,
10004 .flags = GENL_ADMIN_PERM,
10005 .internal_flags = NL80211_FLAG_NEED_WIPHY |
10006 NL80211_FLAG_NEED_RTNL,
10007 },
Kyeyoon Parkfa9ffc72013-12-16 23:01:30 -080010008 {
10009 .cmd = NL80211_CMD_SET_QOS_MAP,
10010 .doit = nl80211_set_qos_map,
10011 .policy = nl80211_policy,
10012 .flags = GENL_ADMIN_PERM,
10013 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
10014 NL80211_FLAG_NEED_RTNL,
10015 },
Johannes Berg55682962007-09-20 13:09:35 -040010016};
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010017
Johannes Berg55682962007-09-20 13:09:35 -040010018/* notification functions */
10019
10020void nl80211_notify_dev_rename(struct cfg80211_registered_device *rdev)
10021{
10022 struct sk_buff *msg;
Johannes Berg86e8cf92013-06-19 10:57:22 +020010023 struct nl80211_dump_wiphy_state state = {};
Johannes Berg55682962007-09-20 13:09:35 -040010024
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -070010025 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -040010026 if (!msg)
10027 return;
10028
Johannes Berg86e8cf92013-06-19 10:57:22 +020010029 if (nl80211_send_wiphy(rdev, msg, 0, 0, 0, &state) < 0) {
Johannes Berg55682962007-09-20 13:09:35 -040010030 nlmsg_free(msg);
10031 return;
10032 }
10033
Johannes Berg68eb5502013-11-19 15:19:38 +010010034 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010010035 NL80211_MCGRP_CONFIG, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -040010036}
10037
Johannes Berg362a4152009-05-24 16:43:15 +020010038static int nl80211_add_scan_req(struct sk_buff *msg,
10039 struct cfg80211_registered_device *rdev)
10040{
10041 struct cfg80211_scan_request *req = rdev->scan_req;
10042 struct nlattr *nest;
10043 int i;
10044
10045 if (WARN_ON(!req))
10046 return 0;
10047
10048 nest = nla_nest_start(msg, NL80211_ATTR_SCAN_SSIDS);
10049 if (!nest)
10050 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -040010051 for (i = 0; i < req->n_ssids; i++) {
10052 if (nla_put(msg, i, req->ssids[i].ssid_len, req->ssids[i].ssid))
10053 goto nla_put_failure;
10054 }
Johannes Berg362a4152009-05-24 16:43:15 +020010055 nla_nest_end(msg, nest);
10056
10057 nest = nla_nest_start(msg, NL80211_ATTR_SCAN_FREQUENCIES);
10058 if (!nest)
10059 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -040010060 for (i = 0; i < req->n_channels; i++) {
10061 if (nla_put_u32(msg, i, req->channels[i]->center_freq))
10062 goto nla_put_failure;
10063 }
Johannes Berg362a4152009-05-24 16:43:15 +020010064 nla_nest_end(msg, nest);
10065
David S. Miller9360ffd2012-03-29 04:41:26 -040010066 if (req->ie &&
10067 nla_put(msg, NL80211_ATTR_IE, req->ie_len, req->ie))
10068 goto nla_put_failure;
Johannes Berg362a4152009-05-24 16:43:15 +020010069
Johannes Bergae917c92013-10-25 11:05:22 +020010070 if (req->flags &&
10071 nla_put_u32(msg, NL80211_ATTR_SCAN_FLAGS, req->flags))
10072 goto nla_put_failure;
Sam Lefflered4737712012-10-11 21:03:31 -070010073
Johannes Berg362a4152009-05-24 16:43:15 +020010074 return 0;
10075 nla_put_failure:
10076 return -ENOBUFS;
10077}
10078
Johannes Berga538e2d2009-06-16 19:56:42 +020010079static int nl80211_send_scan_msg(struct sk_buff *msg,
10080 struct cfg80211_registered_device *rdev,
Johannes Bergfd014282012-06-18 19:17:03 +020010081 struct wireless_dev *wdev,
Eric W. Biederman15e47302012-09-07 20:12:54 +000010082 u32 portid, u32 seq, int flags,
Johannes Berga538e2d2009-06-16 19:56:42 +020010083 u32 cmd)
Johannes Berg2a519312009-02-10 21:25:55 +010010084{
10085 void *hdr;
10086
Eric W. Biederman15e47302012-09-07 20:12:54 +000010087 hdr = nl80211hdr_put(msg, portid, seq, flags, cmd);
Johannes Berg2a519312009-02-10 21:25:55 +010010088 if (!hdr)
10089 return -1;
10090
David S. Miller9360ffd2012-03-29 04:41:26 -040010091 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Bergfd014282012-06-18 19:17:03 +020010092 (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
10093 wdev->netdev->ifindex)) ||
10094 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)))
David S. Miller9360ffd2012-03-29 04:41:26 -040010095 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +010010096
Johannes Berg362a4152009-05-24 16:43:15 +020010097 /* ignore errors and send incomplete event anyway */
10098 nl80211_add_scan_req(msg, rdev);
Johannes Berg2a519312009-02-10 21:25:55 +010010099
10100 return genlmsg_end(msg, hdr);
10101
10102 nla_put_failure:
10103 genlmsg_cancel(msg, hdr);
10104 return -EMSGSIZE;
10105}
10106
Luciano Coelho807f8a82011-05-11 17:09:35 +030010107static int
10108nl80211_send_sched_scan_msg(struct sk_buff *msg,
10109 struct cfg80211_registered_device *rdev,
10110 struct net_device *netdev,
Eric W. Biederman15e47302012-09-07 20:12:54 +000010111 u32 portid, u32 seq, int flags, u32 cmd)
Luciano Coelho807f8a82011-05-11 17:09:35 +030010112{
10113 void *hdr;
10114
Eric W. Biederman15e47302012-09-07 20:12:54 +000010115 hdr = nl80211hdr_put(msg, portid, seq, flags, cmd);
Luciano Coelho807f8a82011-05-11 17:09:35 +030010116 if (!hdr)
10117 return -1;
10118
David S. Miller9360ffd2012-03-29 04:41:26 -040010119 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
10120 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex))
10121 goto nla_put_failure;
Luciano Coelho807f8a82011-05-11 17:09:35 +030010122
10123 return genlmsg_end(msg, hdr);
10124
10125 nla_put_failure:
10126 genlmsg_cancel(msg, hdr);
10127 return -EMSGSIZE;
10128}
10129
Johannes Berga538e2d2009-06-16 19:56:42 +020010130void nl80211_send_scan_start(struct cfg80211_registered_device *rdev,
Johannes Bergfd014282012-06-18 19:17:03 +020010131 struct wireless_dev *wdev)
Johannes Berga538e2d2009-06-16 19:56:42 +020010132{
10133 struct sk_buff *msg;
10134
Thomas Graf58050fc2012-06-28 03:57:45 +000010135 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berga538e2d2009-06-16 19:56:42 +020010136 if (!msg)
10137 return;
10138
Johannes Bergfd014282012-06-18 19:17:03 +020010139 if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0,
Johannes Berga538e2d2009-06-16 19:56:42 +020010140 NL80211_CMD_TRIGGER_SCAN) < 0) {
10141 nlmsg_free(msg);
10142 return;
10143 }
10144
Johannes Berg68eb5502013-11-19 15:19:38 +010010145 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010010146 NL80211_MCGRP_SCAN, GFP_KERNEL);
Johannes Berga538e2d2009-06-16 19:56:42 +020010147}
10148
Johannes Bergf9d15d12014-01-22 11:14:19 +020010149struct sk_buff *nl80211_build_scan_msg(struct cfg80211_registered_device *rdev,
10150 struct wireless_dev *wdev, bool aborted)
Johannes Berg2a519312009-02-10 21:25:55 +010010151{
10152 struct sk_buff *msg;
10153
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -070010154 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg2a519312009-02-10 21:25:55 +010010155 if (!msg)
Johannes Bergf9d15d12014-01-22 11:14:19 +020010156 return NULL;
Johannes Berg2a519312009-02-10 21:25:55 +010010157
Johannes Bergfd014282012-06-18 19:17:03 +020010158 if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0,
Johannes Bergf9d15d12014-01-22 11:14:19 +020010159 aborted ? NL80211_CMD_SCAN_ABORTED :
10160 NL80211_CMD_NEW_SCAN_RESULTS) < 0) {
Johannes Berg2a519312009-02-10 21:25:55 +010010161 nlmsg_free(msg);
Johannes Bergf9d15d12014-01-22 11:14:19 +020010162 return NULL;
Johannes Berg2a519312009-02-10 21:25:55 +010010163 }
10164
Johannes Bergf9d15d12014-01-22 11:14:19 +020010165 return msg;
Johannes Berg2a519312009-02-10 21:25:55 +010010166}
10167
Johannes Bergf9d15d12014-01-22 11:14:19 +020010168void nl80211_send_scan_result(struct cfg80211_registered_device *rdev,
10169 struct sk_buff *msg)
Johannes Berg2a519312009-02-10 21:25:55 +010010170{
Johannes Berg2a519312009-02-10 21:25:55 +010010171 if (!msg)
10172 return;
10173
Johannes Berg68eb5502013-11-19 15:19:38 +010010174 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010010175 NL80211_MCGRP_SCAN, GFP_KERNEL);
Johannes Berg2a519312009-02-10 21:25:55 +010010176}
10177
Luciano Coelho807f8a82011-05-11 17:09:35 +030010178void nl80211_send_sched_scan_results(struct cfg80211_registered_device *rdev,
10179 struct net_device *netdev)
10180{
10181 struct sk_buff *msg;
10182
10183 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
10184 if (!msg)
10185 return;
10186
10187 if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0,
10188 NL80211_CMD_SCHED_SCAN_RESULTS) < 0) {
10189 nlmsg_free(msg);
10190 return;
10191 }
10192
Johannes Berg68eb5502013-11-19 15:19:38 +010010193 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010010194 NL80211_MCGRP_SCAN, GFP_KERNEL);
Luciano Coelho807f8a82011-05-11 17:09:35 +030010195}
10196
10197void nl80211_send_sched_scan(struct cfg80211_registered_device *rdev,
10198 struct net_device *netdev, u32 cmd)
10199{
10200 struct sk_buff *msg;
10201
Thomas Graf58050fc2012-06-28 03:57:45 +000010202 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Luciano Coelho807f8a82011-05-11 17:09:35 +030010203 if (!msg)
10204 return;
10205
10206 if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0, cmd) < 0) {
10207 nlmsg_free(msg);
10208 return;
10209 }
10210
Johannes Berg68eb5502013-11-19 15:19:38 +010010211 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010010212 NL80211_MCGRP_SCAN, GFP_KERNEL);
Luciano Coelho807f8a82011-05-11 17:09:35 +030010213}
10214
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040010215/*
10216 * This can happen on global regulatory changes or device specific settings
10217 * based on custom world regulatory domains.
10218 */
10219void nl80211_send_reg_change_event(struct regulatory_request *request)
10220{
10221 struct sk_buff *msg;
10222 void *hdr;
10223
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -070010224 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040010225 if (!msg)
10226 return;
10227
10228 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_CHANGE);
10229 if (!hdr) {
10230 nlmsg_free(msg);
10231 return;
10232 }
10233
10234 /* Userspace can always count this one always being set */
David S. Miller9360ffd2012-03-29 04:41:26 -040010235 if (nla_put_u8(msg, NL80211_ATTR_REG_INITIATOR, request->initiator))
10236 goto nla_put_failure;
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040010237
David S. Miller9360ffd2012-03-29 04:41:26 -040010238 if (request->alpha2[0] == '0' && request->alpha2[1] == '0') {
10239 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
10240 NL80211_REGDOM_TYPE_WORLD))
10241 goto nla_put_failure;
10242 } else if (request->alpha2[0] == '9' && request->alpha2[1] == '9') {
10243 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
10244 NL80211_REGDOM_TYPE_CUSTOM_WORLD))
10245 goto nla_put_failure;
10246 } else if ((request->alpha2[0] == '9' && request->alpha2[1] == '8') ||
10247 request->intersect) {
10248 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
10249 NL80211_REGDOM_TYPE_INTERSECTION))
10250 goto nla_put_failure;
10251 } else {
10252 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
10253 NL80211_REGDOM_TYPE_COUNTRY) ||
10254 nla_put_string(msg, NL80211_ATTR_REG_ALPHA2,
10255 request->alpha2))
10256 goto nla_put_failure;
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040010257 }
10258
Johannes Bergf4173762012-12-03 18:23:37 +010010259 if (request->wiphy_idx != WIPHY_IDX_INVALID &&
David S. Miller9360ffd2012-03-29 04:41:26 -040010260 nla_put_u32(msg, NL80211_ATTR_WIPHY, request->wiphy_idx))
10261 goto nla_put_failure;
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040010262
Johannes Berg3b7b72e2011-10-22 19:05:51 +020010263 genlmsg_end(msg, hdr);
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040010264
Johannes Bergbc43b282009-07-25 10:54:13 +020010265 rcu_read_lock();
Johannes Berg68eb5502013-11-19 15:19:38 +010010266 genlmsg_multicast_allns(&nl80211_fam, msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010010267 NL80211_MCGRP_REGULATORY, GFP_ATOMIC);
Johannes Bergbc43b282009-07-25 10:54:13 +020010268 rcu_read_unlock();
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040010269
10270 return;
10271
10272nla_put_failure:
10273 genlmsg_cancel(msg, hdr);
10274 nlmsg_free(msg);
10275}
10276
Jouni Malinen6039f6d2009-03-19 13:39:21 +020010277static void nl80211_send_mlme_event(struct cfg80211_registered_device *rdev,
10278 struct net_device *netdev,
10279 const u8 *buf, size_t len,
Johannes Berge6d6e342009-07-01 21:26:47 +020010280 enum nl80211_commands cmd, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +020010281{
10282 struct sk_buff *msg;
10283 void *hdr;
10284
Johannes Berge6d6e342009-07-01 21:26:47 +020010285 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020010286 if (!msg)
10287 return;
10288
10289 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
10290 if (!hdr) {
10291 nlmsg_free(msg);
10292 return;
10293 }
10294
David S. Miller9360ffd2012-03-29 04:41:26 -040010295 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
10296 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
10297 nla_put(msg, NL80211_ATTR_FRAME, len, buf))
10298 goto nla_put_failure;
Jouni Malinen6039f6d2009-03-19 13:39:21 +020010299
Johannes Berg3b7b72e2011-10-22 19:05:51 +020010300 genlmsg_end(msg, hdr);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020010301
Johannes Berg68eb5502013-11-19 15:19:38 +010010302 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010010303 NL80211_MCGRP_MLME, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020010304 return;
10305
10306 nla_put_failure:
10307 genlmsg_cancel(msg, hdr);
10308 nlmsg_free(msg);
10309}
10310
10311void nl80211_send_rx_auth(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +020010312 struct net_device *netdev, const u8 *buf,
10313 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +020010314{
10315 nl80211_send_mlme_event(rdev, netdev, buf, len,
Johannes Berge6d6e342009-07-01 21:26:47 +020010316 NL80211_CMD_AUTHENTICATE, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020010317}
10318
10319void nl80211_send_rx_assoc(struct cfg80211_registered_device *rdev,
10320 struct net_device *netdev, const u8 *buf,
Johannes Berge6d6e342009-07-01 21:26:47 +020010321 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +020010322{
Johannes Berge6d6e342009-07-01 21:26:47 +020010323 nl80211_send_mlme_event(rdev, netdev, buf, len,
10324 NL80211_CMD_ASSOCIATE, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020010325}
10326
Jouni Malinen53b46b82009-03-27 20:53:56 +020010327void nl80211_send_deauth(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +020010328 struct net_device *netdev, const u8 *buf,
10329 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +020010330{
10331 nl80211_send_mlme_event(rdev, netdev, buf, len,
Johannes Berge6d6e342009-07-01 21:26:47 +020010332 NL80211_CMD_DEAUTHENTICATE, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020010333}
10334
Jouni Malinen53b46b82009-03-27 20:53:56 +020010335void nl80211_send_disassoc(struct cfg80211_registered_device *rdev,
10336 struct net_device *netdev, const u8 *buf,
Johannes Berge6d6e342009-07-01 21:26:47 +020010337 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +020010338{
10339 nl80211_send_mlme_event(rdev, netdev, buf, len,
Johannes Berge6d6e342009-07-01 21:26:47 +020010340 NL80211_CMD_DISASSOCIATE, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020010341}
10342
Johannes Berg6ff57cf2013-05-16 00:55:00 +020010343void cfg80211_rx_unprot_mlme_mgmt(struct net_device *dev, const u8 *buf,
10344 size_t len)
Jouni Malinencf4e5942010-12-16 00:52:40 +020010345{
Johannes Berg947add32013-02-22 22:05:20 +010010346 struct wireless_dev *wdev = dev->ieee80211_ptr;
10347 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080010348 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg6ff57cf2013-05-16 00:55:00 +020010349 const struct ieee80211_mgmt *mgmt = (void *)buf;
10350 u32 cmd;
Jouni Malinencf4e5942010-12-16 00:52:40 +020010351
Johannes Berg6ff57cf2013-05-16 00:55:00 +020010352 if (WARN_ON(len < 2))
10353 return;
10354
10355 if (ieee80211_is_deauth(mgmt->frame_control))
10356 cmd = NL80211_CMD_UNPROT_DEAUTHENTICATE;
10357 else
10358 cmd = NL80211_CMD_UNPROT_DISASSOCIATE;
10359
10360 trace_cfg80211_rx_unprot_mlme_mgmt(dev, buf, len);
10361 nl80211_send_mlme_event(rdev, dev, buf, len, cmd, GFP_ATOMIC);
Jouni Malinencf4e5942010-12-16 00:52:40 +020010362}
Johannes Berg6ff57cf2013-05-16 00:55:00 +020010363EXPORT_SYMBOL(cfg80211_rx_unprot_mlme_mgmt);
Jouni Malinencf4e5942010-12-16 00:52:40 +020010364
Luis R. Rodriguez1b06bb42009-05-02 00:34:48 -040010365static void nl80211_send_mlme_timeout(struct cfg80211_registered_device *rdev,
10366 struct net_device *netdev, int cmd,
Johannes Berge6d6e342009-07-01 21:26:47 +020010367 const u8 *addr, gfp_t gfp)
Jouni Malinen1965c852009-04-22 21:38:25 +030010368{
10369 struct sk_buff *msg;
10370 void *hdr;
10371
Johannes Berge6d6e342009-07-01 21:26:47 +020010372 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +030010373 if (!msg)
10374 return;
10375
10376 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
10377 if (!hdr) {
10378 nlmsg_free(msg);
10379 return;
10380 }
10381
David S. Miller9360ffd2012-03-29 04:41:26 -040010382 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
10383 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
10384 nla_put_flag(msg, NL80211_ATTR_TIMED_OUT) ||
10385 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr))
10386 goto nla_put_failure;
Jouni Malinen1965c852009-04-22 21:38:25 +030010387
Johannes Berg3b7b72e2011-10-22 19:05:51 +020010388 genlmsg_end(msg, hdr);
Jouni Malinen1965c852009-04-22 21:38:25 +030010389
Johannes Berg68eb5502013-11-19 15:19:38 +010010390 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010010391 NL80211_MCGRP_MLME, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +030010392 return;
10393
10394 nla_put_failure:
10395 genlmsg_cancel(msg, hdr);
10396 nlmsg_free(msg);
10397}
10398
10399void nl80211_send_auth_timeout(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +020010400 struct net_device *netdev, const u8 *addr,
10401 gfp_t gfp)
Jouni Malinen1965c852009-04-22 21:38:25 +030010402{
10403 nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_AUTHENTICATE,
Johannes Berge6d6e342009-07-01 21:26:47 +020010404 addr, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +030010405}
10406
10407void nl80211_send_assoc_timeout(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +020010408 struct net_device *netdev, const u8 *addr,
10409 gfp_t gfp)
Jouni Malinen1965c852009-04-22 21:38:25 +030010410{
Johannes Berge6d6e342009-07-01 21:26:47 +020010411 nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_ASSOCIATE,
10412 addr, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +030010413}
10414
Samuel Ortizb23aa672009-07-01 21:26:54 +020010415void nl80211_send_connect_result(struct cfg80211_registered_device *rdev,
10416 struct net_device *netdev, const u8 *bssid,
10417 const u8 *req_ie, size_t req_ie_len,
10418 const u8 *resp_ie, size_t resp_ie_len,
10419 u16 status, gfp_t gfp)
10420{
10421 struct sk_buff *msg;
10422 void *hdr;
10423
Thomas Graf58050fc2012-06-28 03:57:45 +000010424 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +020010425 if (!msg)
10426 return;
10427
10428 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONNECT);
10429 if (!hdr) {
10430 nlmsg_free(msg);
10431 return;
10432 }
10433
David S. Miller9360ffd2012-03-29 04:41:26 -040010434 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
10435 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
10436 (bssid && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) ||
10437 nla_put_u16(msg, NL80211_ATTR_STATUS_CODE, status) ||
10438 (req_ie &&
10439 nla_put(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie)) ||
10440 (resp_ie &&
10441 nla_put(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie)))
10442 goto nla_put_failure;
Samuel Ortizb23aa672009-07-01 21:26:54 +020010443
Johannes Berg3b7b72e2011-10-22 19:05:51 +020010444 genlmsg_end(msg, hdr);
Samuel Ortizb23aa672009-07-01 21:26:54 +020010445
Johannes Berg68eb5502013-11-19 15:19:38 +010010446 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010010447 NL80211_MCGRP_MLME, gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +020010448 return;
10449
10450 nla_put_failure:
10451 genlmsg_cancel(msg, hdr);
10452 nlmsg_free(msg);
10453
10454}
10455
10456void nl80211_send_roamed(struct cfg80211_registered_device *rdev,
10457 struct net_device *netdev, const u8 *bssid,
10458 const u8 *req_ie, size_t req_ie_len,
10459 const u8 *resp_ie, size_t resp_ie_len, gfp_t gfp)
10460{
10461 struct sk_buff *msg;
10462 void *hdr;
10463
Thomas Graf58050fc2012-06-28 03:57:45 +000010464 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +020010465 if (!msg)
10466 return;
10467
10468 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_ROAM);
10469 if (!hdr) {
10470 nlmsg_free(msg);
10471 return;
10472 }
10473
David S. Miller9360ffd2012-03-29 04:41:26 -040010474 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
10475 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
10476 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid) ||
10477 (req_ie &&
10478 nla_put(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie)) ||
10479 (resp_ie &&
10480 nla_put(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie)))
10481 goto nla_put_failure;
Samuel Ortizb23aa672009-07-01 21:26:54 +020010482
Johannes Berg3b7b72e2011-10-22 19:05:51 +020010483 genlmsg_end(msg, hdr);
Samuel Ortizb23aa672009-07-01 21:26:54 +020010484
Johannes Berg68eb5502013-11-19 15:19:38 +010010485 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010010486 NL80211_MCGRP_MLME, gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +020010487 return;
10488
10489 nla_put_failure:
10490 genlmsg_cancel(msg, hdr);
10491 nlmsg_free(msg);
10492
10493}
10494
10495void nl80211_send_disconnected(struct cfg80211_registered_device *rdev,
10496 struct net_device *netdev, u16 reason,
Johannes Berg667503dd2009-07-07 03:56:11 +020010497 const u8 *ie, size_t ie_len, bool from_ap)
Samuel Ortizb23aa672009-07-01 21:26:54 +020010498{
10499 struct sk_buff *msg;
10500 void *hdr;
10501
Thomas Graf58050fc2012-06-28 03:57:45 +000010502 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Samuel Ortizb23aa672009-07-01 21:26:54 +020010503 if (!msg)
10504 return;
10505
10506 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DISCONNECT);
10507 if (!hdr) {
10508 nlmsg_free(msg);
10509 return;
10510 }
10511
David S. Miller9360ffd2012-03-29 04:41:26 -040010512 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
10513 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
10514 (from_ap && reason &&
10515 nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason)) ||
10516 (from_ap &&
10517 nla_put_flag(msg, NL80211_ATTR_DISCONNECTED_BY_AP)) ||
10518 (ie && nla_put(msg, NL80211_ATTR_IE, ie_len, ie)))
10519 goto nla_put_failure;
Samuel Ortizb23aa672009-07-01 21:26:54 +020010520
Johannes Berg3b7b72e2011-10-22 19:05:51 +020010521 genlmsg_end(msg, hdr);
Samuel Ortizb23aa672009-07-01 21:26:54 +020010522
Johannes Berg68eb5502013-11-19 15:19:38 +010010523 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010010524 NL80211_MCGRP_MLME, GFP_KERNEL);
Samuel Ortizb23aa672009-07-01 21:26:54 +020010525 return;
10526
10527 nla_put_failure:
10528 genlmsg_cancel(msg, hdr);
10529 nlmsg_free(msg);
10530
10531}
10532
Johannes Berg04a773a2009-04-19 21:24:32 +020010533void nl80211_send_ibss_bssid(struct cfg80211_registered_device *rdev,
10534 struct net_device *netdev, const u8 *bssid,
10535 gfp_t gfp)
10536{
10537 struct sk_buff *msg;
10538 void *hdr;
10539
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -070010540 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Johannes Berg04a773a2009-04-19 21:24:32 +020010541 if (!msg)
10542 return;
10543
10544 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_JOIN_IBSS);
10545 if (!hdr) {
10546 nlmsg_free(msg);
10547 return;
10548 }
10549
David S. Miller9360ffd2012-03-29 04:41:26 -040010550 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
10551 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
10552 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid))
10553 goto nla_put_failure;
Johannes Berg04a773a2009-04-19 21:24:32 +020010554
Johannes Berg3b7b72e2011-10-22 19:05:51 +020010555 genlmsg_end(msg, hdr);
Johannes Berg04a773a2009-04-19 21:24:32 +020010556
Johannes Berg68eb5502013-11-19 15:19:38 +010010557 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010010558 NL80211_MCGRP_MLME, gfp);
Johannes Berg04a773a2009-04-19 21:24:32 +020010559 return;
10560
10561 nla_put_failure:
10562 genlmsg_cancel(msg, hdr);
10563 nlmsg_free(msg);
10564}
10565
Johannes Berg947add32013-02-22 22:05:20 +010010566void cfg80211_notify_new_peer_candidate(struct net_device *dev, const u8 *addr,
10567 const u8* ie, u8 ie_len, gfp_t gfp)
Javier Cardonac93b5e72011-04-07 15:08:34 -070010568{
Johannes Berg947add32013-02-22 22:05:20 +010010569 struct wireless_dev *wdev = dev->ieee80211_ptr;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080010570 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Javier Cardonac93b5e72011-04-07 15:08:34 -070010571 struct sk_buff *msg;
10572 void *hdr;
10573
Johannes Berg947add32013-02-22 22:05:20 +010010574 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_MESH_POINT))
10575 return;
10576
10577 trace_cfg80211_notify_new_peer_candidate(dev, addr);
10578
Javier Cardonac93b5e72011-04-07 15:08:34 -070010579 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
10580 if (!msg)
10581 return;
10582
10583 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NEW_PEER_CANDIDATE);
10584 if (!hdr) {
10585 nlmsg_free(msg);
10586 return;
10587 }
10588
David S. Miller9360ffd2012-03-29 04:41:26 -040010589 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg947add32013-02-22 22:05:20 +010010590 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
10591 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040010592 (ie_len && ie &&
10593 nla_put(msg, NL80211_ATTR_IE, ie_len , ie)))
10594 goto nla_put_failure;
Javier Cardonac93b5e72011-04-07 15:08:34 -070010595
Johannes Berg3b7b72e2011-10-22 19:05:51 +020010596 genlmsg_end(msg, hdr);
Javier Cardonac93b5e72011-04-07 15:08:34 -070010597
Johannes Berg68eb5502013-11-19 15:19:38 +010010598 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010010599 NL80211_MCGRP_MLME, gfp);
Javier Cardonac93b5e72011-04-07 15:08:34 -070010600 return;
10601
10602 nla_put_failure:
10603 genlmsg_cancel(msg, hdr);
10604 nlmsg_free(msg);
10605}
Johannes Berg947add32013-02-22 22:05:20 +010010606EXPORT_SYMBOL(cfg80211_notify_new_peer_candidate);
Javier Cardonac93b5e72011-04-07 15:08:34 -070010607
Jouni Malinena3b8b052009-03-27 21:59:49 +020010608void nl80211_michael_mic_failure(struct cfg80211_registered_device *rdev,
10609 struct net_device *netdev, const u8 *addr,
10610 enum nl80211_key_type key_type, int key_id,
Johannes Berge6d6e342009-07-01 21:26:47 +020010611 const u8 *tsc, gfp_t gfp)
Jouni Malinena3b8b052009-03-27 21:59:49 +020010612{
10613 struct sk_buff *msg;
10614 void *hdr;
10615
Johannes Berge6d6e342009-07-01 21:26:47 +020010616 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinena3b8b052009-03-27 21:59:49 +020010617 if (!msg)
10618 return;
10619
10620 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_MICHAEL_MIC_FAILURE);
10621 if (!hdr) {
10622 nlmsg_free(msg);
10623 return;
10624 }
10625
David S. Miller9360ffd2012-03-29 04:41:26 -040010626 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
10627 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
10628 (addr && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) ||
10629 nla_put_u32(msg, NL80211_ATTR_KEY_TYPE, key_type) ||
10630 (key_id != -1 &&
10631 nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_id)) ||
10632 (tsc && nla_put(msg, NL80211_ATTR_KEY_SEQ, 6, tsc)))
10633 goto nla_put_failure;
Jouni Malinena3b8b052009-03-27 21:59:49 +020010634
Johannes Berg3b7b72e2011-10-22 19:05:51 +020010635 genlmsg_end(msg, hdr);
Jouni Malinena3b8b052009-03-27 21:59:49 +020010636
Johannes Berg68eb5502013-11-19 15:19:38 +010010637 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010010638 NL80211_MCGRP_MLME, gfp);
Jouni Malinena3b8b052009-03-27 21:59:49 +020010639 return;
10640
10641 nla_put_failure:
10642 genlmsg_cancel(msg, hdr);
10643 nlmsg_free(msg);
10644}
10645
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040010646void nl80211_send_beacon_hint_event(struct wiphy *wiphy,
10647 struct ieee80211_channel *channel_before,
10648 struct ieee80211_channel *channel_after)
10649{
10650 struct sk_buff *msg;
10651 void *hdr;
10652 struct nlattr *nl_freq;
10653
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -070010654 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_ATOMIC);
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040010655 if (!msg)
10656 return;
10657
10658 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_BEACON_HINT);
10659 if (!hdr) {
10660 nlmsg_free(msg);
10661 return;
10662 }
10663
10664 /*
10665 * Since we are applying the beacon hint to a wiphy we know its
10666 * wiphy_idx is valid
10667 */
David S. Miller9360ffd2012-03-29 04:41:26 -040010668 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy)))
10669 goto nla_put_failure;
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040010670
10671 /* Before */
10672 nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_BEFORE);
10673 if (!nl_freq)
10674 goto nla_put_failure;
Johannes Bergcdc89b92013-02-18 23:54:36 +010010675 if (nl80211_msg_put_channel(msg, channel_before, false))
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040010676 goto nla_put_failure;
10677 nla_nest_end(msg, nl_freq);
10678
10679 /* After */
10680 nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_AFTER);
10681 if (!nl_freq)
10682 goto nla_put_failure;
Johannes Bergcdc89b92013-02-18 23:54:36 +010010683 if (nl80211_msg_put_channel(msg, channel_after, false))
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040010684 goto nla_put_failure;
10685 nla_nest_end(msg, nl_freq);
10686
Johannes Berg3b7b72e2011-10-22 19:05:51 +020010687 genlmsg_end(msg, hdr);
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040010688
Johannes Berg463d0182009-07-14 00:33:35 +020010689 rcu_read_lock();
Johannes Berg68eb5502013-11-19 15:19:38 +010010690 genlmsg_multicast_allns(&nl80211_fam, msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010010691 NL80211_MCGRP_REGULATORY, GFP_ATOMIC);
Johannes Berg463d0182009-07-14 00:33:35 +020010692 rcu_read_unlock();
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040010693
10694 return;
10695
10696nla_put_failure:
10697 genlmsg_cancel(msg, hdr);
10698 nlmsg_free(msg);
10699}
10700
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010701static void nl80211_send_remain_on_chan_event(
10702 int cmd, struct cfg80211_registered_device *rdev,
Johannes Berg71bbc992012-06-15 15:30:18 +020010703 struct wireless_dev *wdev, u64 cookie,
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010704 struct ieee80211_channel *chan,
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010705 unsigned int duration, gfp_t gfp)
10706{
10707 struct sk_buff *msg;
10708 void *hdr;
10709
10710 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
10711 if (!msg)
10712 return;
10713
10714 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
10715 if (!hdr) {
10716 nlmsg_free(msg);
10717 return;
10718 }
10719
David S. Miller9360ffd2012-03-29 04:41:26 -040010720 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg71bbc992012-06-15 15:30:18 +020010721 (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
10722 wdev->netdev->ifindex)) ||
Johannes Berg00f53352012-07-17 11:53:12 +020010723 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040010724 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, chan->center_freq) ||
Johannes Berg42d97a52012-11-08 18:31:02 +010010725 nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE,
10726 NL80211_CHAN_NO_HT) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040010727 nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie))
10728 goto nla_put_failure;
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010729
David S. Miller9360ffd2012-03-29 04:41:26 -040010730 if (cmd == NL80211_CMD_REMAIN_ON_CHANNEL &&
10731 nla_put_u32(msg, NL80211_ATTR_DURATION, duration))
10732 goto nla_put_failure;
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010733
Johannes Berg3b7b72e2011-10-22 19:05:51 +020010734 genlmsg_end(msg, hdr);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010735
Johannes Berg68eb5502013-11-19 15:19:38 +010010736 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010010737 NL80211_MCGRP_MLME, gfp);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010738 return;
10739
10740 nla_put_failure:
10741 genlmsg_cancel(msg, hdr);
10742 nlmsg_free(msg);
10743}
10744
Johannes Berg947add32013-02-22 22:05:20 +010010745void cfg80211_ready_on_channel(struct wireless_dev *wdev, u64 cookie,
10746 struct ieee80211_channel *chan,
10747 unsigned int duration, gfp_t gfp)
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010748{
Johannes Berg947add32013-02-22 22:05:20 +010010749 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080010750 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg947add32013-02-22 22:05:20 +010010751
10752 trace_cfg80211_ready_on_channel(wdev, cookie, chan, duration);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010753 nl80211_send_remain_on_chan_event(NL80211_CMD_REMAIN_ON_CHANNEL,
Johannes Berg71bbc992012-06-15 15:30:18 +020010754 rdev, wdev, cookie, chan,
Johannes Berg42d97a52012-11-08 18:31:02 +010010755 duration, gfp);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010756}
Johannes Berg947add32013-02-22 22:05:20 +010010757EXPORT_SYMBOL(cfg80211_ready_on_channel);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010758
Johannes Berg947add32013-02-22 22:05:20 +010010759void cfg80211_remain_on_channel_expired(struct wireless_dev *wdev, u64 cookie,
10760 struct ieee80211_channel *chan,
10761 gfp_t gfp)
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010762{
Johannes Berg947add32013-02-22 22:05:20 +010010763 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080010764 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg947add32013-02-22 22:05:20 +010010765
10766 trace_cfg80211_ready_on_channel_expired(wdev, cookie, chan);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010767 nl80211_send_remain_on_chan_event(NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL,
Johannes Berg42d97a52012-11-08 18:31:02 +010010768 rdev, wdev, cookie, chan, 0, gfp);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010769}
Johannes Berg947add32013-02-22 22:05:20 +010010770EXPORT_SYMBOL(cfg80211_remain_on_channel_expired);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010771
Johannes Berg947add32013-02-22 22:05:20 +010010772void cfg80211_new_sta(struct net_device *dev, const u8 *mac_addr,
10773 struct station_info *sinfo, gfp_t gfp)
Johannes Berg98b62182009-12-23 13:15:44 +010010774{
Johannes Berg947add32013-02-22 22:05:20 +010010775 struct wiphy *wiphy = dev->ieee80211_ptr->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080010776 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg98b62182009-12-23 13:15:44 +010010777 struct sk_buff *msg;
10778
Johannes Berg947add32013-02-22 22:05:20 +010010779 trace_cfg80211_new_sta(dev, mac_addr, sinfo);
10780
Thomas Graf58050fc2012-06-28 03:57:45 +000010781 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Johannes Berg98b62182009-12-23 13:15:44 +010010782 if (!msg)
10783 return;
10784
John W. Linville66266b32012-03-15 13:25:41 -040010785 if (nl80211_send_station(msg, 0, 0, 0,
10786 rdev, dev, mac_addr, sinfo) < 0) {
Johannes Berg98b62182009-12-23 13:15:44 +010010787 nlmsg_free(msg);
10788 return;
10789 }
10790
Johannes Berg68eb5502013-11-19 15:19:38 +010010791 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010010792 NL80211_MCGRP_MLME, gfp);
Johannes Berg98b62182009-12-23 13:15:44 +010010793}
Johannes Berg947add32013-02-22 22:05:20 +010010794EXPORT_SYMBOL(cfg80211_new_sta);
Johannes Berg98b62182009-12-23 13:15:44 +010010795
Johannes Berg947add32013-02-22 22:05:20 +010010796void cfg80211_del_sta(struct net_device *dev, const u8 *mac_addr, gfp_t gfp)
Jouni Malinenec15e682011-03-23 15:29:52 +020010797{
Johannes Berg947add32013-02-22 22:05:20 +010010798 struct wiphy *wiphy = dev->ieee80211_ptr->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080010799 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Jouni Malinenec15e682011-03-23 15:29:52 +020010800 struct sk_buff *msg;
10801 void *hdr;
10802
Johannes Berg947add32013-02-22 22:05:20 +010010803 trace_cfg80211_del_sta(dev, mac_addr);
10804
Thomas Graf58050fc2012-06-28 03:57:45 +000010805 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinenec15e682011-03-23 15:29:52 +020010806 if (!msg)
10807 return;
10808
10809 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DEL_STATION);
10810 if (!hdr) {
10811 nlmsg_free(msg);
10812 return;
10813 }
10814
David S. Miller9360ffd2012-03-29 04:41:26 -040010815 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
10816 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr))
10817 goto nla_put_failure;
Jouni Malinenec15e682011-03-23 15:29:52 +020010818
Johannes Berg3b7b72e2011-10-22 19:05:51 +020010819 genlmsg_end(msg, hdr);
Jouni Malinenec15e682011-03-23 15:29:52 +020010820
Johannes Berg68eb5502013-11-19 15:19:38 +010010821 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010010822 NL80211_MCGRP_MLME, gfp);
Jouni Malinenec15e682011-03-23 15:29:52 +020010823 return;
10824
10825 nla_put_failure:
10826 genlmsg_cancel(msg, hdr);
10827 nlmsg_free(msg);
10828}
Johannes Berg947add32013-02-22 22:05:20 +010010829EXPORT_SYMBOL(cfg80211_del_sta);
Jouni Malinenec15e682011-03-23 15:29:52 +020010830
Johannes Berg947add32013-02-22 22:05:20 +010010831void cfg80211_conn_failed(struct net_device *dev, const u8 *mac_addr,
10832 enum nl80211_connect_failed_reason reason,
10833 gfp_t gfp)
Pandiyarajan Pitchaimuthued44a952012-09-18 16:50:49 +053010834{
Johannes Berg947add32013-02-22 22:05:20 +010010835 struct wiphy *wiphy = dev->ieee80211_ptr->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080010836 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Pandiyarajan Pitchaimuthued44a952012-09-18 16:50:49 +053010837 struct sk_buff *msg;
10838 void *hdr;
10839
10840 msg = nlmsg_new(NLMSG_GOODSIZE, gfp);
10841 if (!msg)
10842 return;
10843
10844 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONN_FAILED);
10845 if (!hdr) {
10846 nlmsg_free(msg);
10847 return;
10848 }
10849
10850 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
10851 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) ||
10852 nla_put_u32(msg, NL80211_ATTR_CONN_FAILED_REASON, reason))
10853 goto nla_put_failure;
10854
10855 genlmsg_end(msg, hdr);
10856
Johannes Berg68eb5502013-11-19 15:19:38 +010010857 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010010858 NL80211_MCGRP_MLME, gfp);
Pandiyarajan Pitchaimuthued44a952012-09-18 16:50:49 +053010859 return;
10860
10861 nla_put_failure:
10862 genlmsg_cancel(msg, hdr);
10863 nlmsg_free(msg);
10864}
Johannes Berg947add32013-02-22 22:05:20 +010010865EXPORT_SYMBOL(cfg80211_conn_failed);
Pandiyarajan Pitchaimuthued44a952012-09-18 16:50:49 +053010866
Johannes Bergb92ab5d2011-11-04 11:18:19 +010010867static bool __nl80211_unexpected_frame(struct net_device *dev, u8 cmd,
10868 const u8 *addr, gfp_t gfp)
Johannes Berg28946da2011-11-04 11:18:12 +010010869{
10870 struct wireless_dev *wdev = dev->ieee80211_ptr;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080010871 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Johannes Berg28946da2011-11-04 11:18:12 +010010872 struct sk_buff *msg;
10873 void *hdr;
Eric W. Biederman15e47302012-09-07 20:12:54 +000010874 u32 nlportid = ACCESS_ONCE(wdev->ap_unexpected_nlportid);
Johannes Berg28946da2011-11-04 11:18:12 +010010875
Eric W. Biederman15e47302012-09-07 20:12:54 +000010876 if (!nlportid)
Johannes Berg28946da2011-11-04 11:18:12 +010010877 return false;
10878
10879 msg = nlmsg_new(100, gfp);
10880 if (!msg)
10881 return true;
10882
Johannes Bergb92ab5d2011-11-04 11:18:19 +010010883 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
Johannes Berg28946da2011-11-04 11:18:12 +010010884 if (!hdr) {
10885 nlmsg_free(msg);
10886 return true;
10887 }
10888
David S. Miller9360ffd2012-03-29 04:41:26 -040010889 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
10890 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
10891 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr))
10892 goto nla_put_failure;
Johannes Berg28946da2011-11-04 11:18:12 +010010893
Johannes Berg9c90a9f2013-06-04 12:46:03 +020010894 genlmsg_end(msg, hdr);
Eric W. Biederman15e47302012-09-07 20:12:54 +000010895 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid);
Johannes Berg28946da2011-11-04 11:18:12 +010010896 return true;
10897
10898 nla_put_failure:
10899 genlmsg_cancel(msg, hdr);
10900 nlmsg_free(msg);
10901 return true;
10902}
10903
Johannes Berg947add32013-02-22 22:05:20 +010010904bool cfg80211_rx_spurious_frame(struct net_device *dev,
10905 const u8 *addr, gfp_t gfp)
Johannes Bergb92ab5d2011-11-04 11:18:19 +010010906{
Johannes Berg947add32013-02-22 22:05:20 +010010907 struct wireless_dev *wdev = dev->ieee80211_ptr;
10908 bool ret;
Johannes Bergb92ab5d2011-11-04 11:18:19 +010010909
Johannes Berg947add32013-02-22 22:05:20 +010010910 trace_cfg80211_rx_spurious_frame(dev, addr);
10911
10912 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP &&
10913 wdev->iftype != NL80211_IFTYPE_P2P_GO)) {
10914 trace_cfg80211_return_bool(false);
10915 return false;
10916 }
10917 ret = __nl80211_unexpected_frame(dev, NL80211_CMD_UNEXPECTED_FRAME,
10918 addr, gfp);
10919 trace_cfg80211_return_bool(ret);
10920 return ret;
Johannes Bergb92ab5d2011-11-04 11:18:19 +010010921}
Johannes Berg947add32013-02-22 22:05:20 +010010922EXPORT_SYMBOL(cfg80211_rx_spurious_frame);
10923
10924bool cfg80211_rx_unexpected_4addr_frame(struct net_device *dev,
10925 const u8 *addr, gfp_t gfp)
10926{
10927 struct wireless_dev *wdev = dev->ieee80211_ptr;
10928 bool ret;
10929
10930 trace_cfg80211_rx_unexpected_4addr_frame(dev, addr);
10931
10932 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP &&
10933 wdev->iftype != NL80211_IFTYPE_P2P_GO &&
10934 wdev->iftype != NL80211_IFTYPE_AP_VLAN)) {
10935 trace_cfg80211_return_bool(false);
10936 return false;
10937 }
10938 ret = __nl80211_unexpected_frame(dev,
10939 NL80211_CMD_UNEXPECTED_4ADDR_FRAME,
10940 addr, gfp);
10941 trace_cfg80211_return_bool(ret);
10942 return ret;
10943}
10944EXPORT_SYMBOL(cfg80211_rx_unexpected_4addr_frame);
Johannes Bergb92ab5d2011-11-04 11:18:19 +010010945
Johannes Berg2e161f72010-08-12 15:38:38 +020010946int nl80211_send_mgmt(struct cfg80211_registered_device *rdev,
Eric W. Biederman15e47302012-09-07 20:12:54 +000010947 struct wireless_dev *wdev, u32 nlportid,
Johannes Berg804483e2012-03-05 22:18:41 +010010948 int freq, int sig_dbm,
Vladimir Kondratiev19504cf2013-08-15 14:51:28 +030010949 const u8 *buf, size_t len, u32 flags, gfp_t gfp)
Jouni Malinen026331c2010-02-15 12:53:10 +020010950{
Johannes Berg71bbc992012-06-15 15:30:18 +020010951 struct net_device *netdev = wdev->netdev;
Jouni Malinen026331c2010-02-15 12:53:10 +020010952 struct sk_buff *msg;
10953 void *hdr;
Jouni Malinen026331c2010-02-15 12:53:10 +020010954
10955 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
10956 if (!msg)
10957 return -ENOMEM;
10958
Johannes Berg2e161f72010-08-12 15:38:38 +020010959 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME);
Jouni Malinen026331c2010-02-15 12:53:10 +020010960 if (!hdr) {
10961 nlmsg_free(msg);
10962 return -ENOMEM;
10963 }
10964
David S. Miller9360ffd2012-03-29 04:41:26 -040010965 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg71bbc992012-06-15 15:30:18 +020010966 (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
10967 netdev->ifindex)) ||
Ilan Peera8384902013-05-08 16:35:55 +030010968 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040010969 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq) ||
10970 (sig_dbm &&
10971 nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) ||
Vladimir Kondratiev19504cf2013-08-15 14:51:28 +030010972 nla_put(msg, NL80211_ATTR_FRAME, len, buf) ||
10973 (flags &&
10974 nla_put_u32(msg, NL80211_ATTR_RXMGMT_FLAGS, flags)))
David S. Miller9360ffd2012-03-29 04:41:26 -040010975 goto nla_put_failure;
Jouni Malinen026331c2010-02-15 12:53:10 +020010976
Johannes Berg3b7b72e2011-10-22 19:05:51 +020010977 genlmsg_end(msg, hdr);
Jouni Malinen026331c2010-02-15 12:53:10 +020010978
Eric W. Biederman15e47302012-09-07 20:12:54 +000010979 return genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid);
Jouni Malinen026331c2010-02-15 12:53:10 +020010980
10981 nla_put_failure:
10982 genlmsg_cancel(msg, hdr);
10983 nlmsg_free(msg);
10984 return -ENOBUFS;
10985}
10986
Johannes Berg947add32013-02-22 22:05:20 +010010987void cfg80211_mgmt_tx_status(struct wireless_dev *wdev, u64 cookie,
10988 const u8 *buf, size_t len, bool ack, gfp_t gfp)
Jouni Malinen026331c2010-02-15 12:53:10 +020010989{
Johannes Berg947add32013-02-22 22:05:20 +010010990 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080010991 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg71bbc992012-06-15 15:30:18 +020010992 struct net_device *netdev = wdev->netdev;
Jouni Malinen026331c2010-02-15 12:53:10 +020010993 struct sk_buff *msg;
10994 void *hdr;
10995
Johannes Berg947add32013-02-22 22:05:20 +010010996 trace_cfg80211_mgmt_tx_status(wdev, cookie, ack);
10997
Jouni Malinen026331c2010-02-15 12:53:10 +020010998 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
10999 if (!msg)
11000 return;
11001
Johannes Berg2e161f72010-08-12 15:38:38 +020011002 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME_TX_STATUS);
Jouni Malinen026331c2010-02-15 12:53:10 +020011003 if (!hdr) {
11004 nlmsg_free(msg);
11005 return;
11006 }
11007
David S. Miller9360ffd2012-03-29 04:41:26 -040011008 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg71bbc992012-06-15 15:30:18 +020011009 (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
11010 netdev->ifindex)) ||
Ilan Peera8384902013-05-08 16:35:55 +030011011 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040011012 nla_put(msg, NL80211_ATTR_FRAME, len, buf) ||
11013 nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie) ||
11014 (ack && nla_put_flag(msg, NL80211_ATTR_ACK)))
11015 goto nla_put_failure;
Jouni Malinen026331c2010-02-15 12:53:10 +020011016
Johannes Berg3b7b72e2011-10-22 19:05:51 +020011017 genlmsg_end(msg, hdr);
Jouni Malinen026331c2010-02-15 12:53:10 +020011018
Johannes Berg68eb5502013-11-19 15:19:38 +010011019 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011020 NL80211_MCGRP_MLME, gfp);
Jouni Malinen026331c2010-02-15 12:53:10 +020011021 return;
11022
11023 nla_put_failure:
11024 genlmsg_cancel(msg, hdr);
11025 nlmsg_free(msg);
11026}
Johannes Berg947add32013-02-22 22:05:20 +010011027EXPORT_SYMBOL(cfg80211_mgmt_tx_status);
Jouni Malinen026331c2010-02-15 12:53:10 +020011028
Johannes Berg947add32013-02-22 22:05:20 +010011029void cfg80211_cqm_rssi_notify(struct net_device *dev,
11030 enum nl80211_cqm_rssi_threshold_event rssi_event,
11031 gfp_t gfp)
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020011032{
Johannes Berg947add32013-02-22 22:05:20 +010011033 struct wireless_dev *wdev = dev->ieee80211_ptr;
11034 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080011035 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020011036 struct sk_buff *msg;
11037 struct nlattr *pinfoattr;
11038 void *hdr;
11039
Johannes Berg947add32013-02-22 22:05:20 +010011040 trace_cfg80211_cqm_rssi_notify(dev, rssi_event);
11041
Thomas Graf58050fc2012-06-28 03:57:45 +000011042 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020011043 if (!msg)
11044 return;
11045
11046 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM);
11047 if (!hdr) {
11048 nlmsg_free(msg);
11049 return;
11050 }
11051
David S. Miller9360ffd2012-03-29 04:41:26 -040011052 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg947add32013-02-22 22:05:20 +010011053 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex))
David S. Miller9360ffd2012-03-29 04:41:26 -040011054 goto nla_put_failure;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020011055
11056 pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM);
11057 if (!pinfoattr)
11058 goto nla_put_failure;
11059
David S. Miller9360ffd2012-03-29 04:41:26 -040011060 if (nla_put_u32(msg, NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT,
11061 rssi_event))
11062 goto nla_put_failure;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020011063
11064 nla_nest_end(msg, pinfoattr);
11065
Johannes Berg3b7b72e2011-10-22 19:05:51 +020011066 genlmsg_end(msg, hdr);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020011067
Johannes Berg68eb5502013-11-19 15:19:38 +010011068 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011069 NL80211_MCGRP_MLME, gfp);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020011070 return;
11071
11072 nla_put_failure:
11073 genlmsg_cancel(msg, hdr);
11074 nlmsg_free(msg);
11075}
Johannes Berg947add32013-02-22 22:05:20 +010011076EXPORT_SYMBOL(cfg80211_cqm_rssi_notify);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020011077
Johannes Berg947add32013-02-22 22:05:20 +010011078static void nl80211_gtk_rekey_notify(struct cfg80211_registered_device *rdev,
11079 struct net_device *netdev, const u8 *bssid,
11080 const u8 *replay_ctr, gfp_t gfp)
Johannes Berge5497d72011-07-05 16:35:40 +020011081{
11082 struct sk_buff *msg;
11083 struct nlattr *rekey_attr;
11084 void *hdr;
11085
Thomas Graf58050fc2012-06-28 03:57:45 +000011086 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Johannes Berge5497d72011-07-05 16:35:40 +020011087 if (!msg)
11088 return;
11089
11090 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_REKEY_OFFLOAD);
11091 if (!hdr) {
11092 nlmsg_free(msg);
11093 return;
11094 }
11095
David S. Miller9360ffd2012-03-29 04:41:26 -040011096 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
11097 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
11098 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid))
11099 goto nla_put_failure;
Johannes Berge5497d72011-07-05 16:35:40 +020011100
11101 rekey_attr = nla_nest_start(msg, NL80211_ATTR_REKEY_DATA);
11102 if (!rekey_attr)
11103 goto nla_put_failure;
11104
David S. Miller9360ffd2012-03-29 04:41:26 -040011105 if (nla_put(msg, NL80211_REKEY_DATA_REPLAY_CTR,
11106 NL80211_REPLAY_CTR_LEN, replay_ctr))
11107 goto nla_put_failure;
Johannes Berge5497d72011-07-05 16:35:40 +020011108
11109 nla_nest_end(msg, rekey_attr);
11110
Johannes Berg3b7b72e2011-10-22 19:05:51 +020011111 genlmsg_end(msg, hdr);
Johannes Berge5497d72011-07-05 16:35:40 +020011112
Johannes Berg68eb5502013-11-19 15:19:38 +010011113 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011114 NL80211_MCGRP_MLME, gfp);
Johannes Berge5497d72011-07-05 16:35:40 +020011115 return;
11116
11117 nla_put_failure:
11118 genlmsg_cancel(msg, hdr);
11119 nlmsg_free(msg);
11120}
11121
Johannes Berg947add32013-02-22 22:05:20 +010011122void cfg80211_gtk_rekey_notify(struct net_device *dev, const u8 *bssid,
11123 const u8 *replay_ctr, gfp_t gfp)
11124{
11125 struct wireless_dev *wdev = dev->ieee80211_ptr;
11126 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080011127 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg947add32013-02-22 22:05:20 +010011128
11129 trace_cfg80211_gtk_rekey_notify(dev, bssid);
11130 nl80211_gtk_rekey_notify(rdev, dev, bssid, replay_ctr, gfp);
11131}
11132EXPORT_SYMBOL(cfg80211_gtk_rekey_notify);
11133
11134static void
11135nl80211_pmksa_candidate_notify(struct cfg80211_registered_device *rdev,
11136 struct net_device *netdev, int index,
11137 const u8 *bssid, bool preauth, gfp_t gfp)
Jouni Malinenc9df56b2011-09-16 18:56:23 +030011138{
11139 struct sk_buff *msg;
11140 struct nlattr *attr;
11141 void *hdr;
11142
Thomas Graf58050fc2012-06-28 03:57:45 +000011143 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinenc9df56b2011-09-16 18:56:23 +030011144 if (!msg)
11145 return;
11146
11147 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PMKSA_CANDIDATE);
11148 if (!hdr) {
11149 nlmsg_free(msg);
11150 return;
11151 }
11152
David S. Miller9360ffd2012-03-29 04:41:26 -040011153 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
11154 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex))
11155 goto nla_put_failure;
Jouni Malinenc9df56b2011-09-16 18:56:23 +030011156
11157 attr = nla_nest_start(msg, NL80211_ATTR_PMKSA_CANDIDATE);
11158 if (!attr)
11159 goto nla_put_failure;
11160
David S. Miller9360ffd2012-03-29 04:41:26 -040011161 if (nla_put_u32(msg, NL80211_PMKSA_CANDIDATE_INDEX, index) ||
11162 nla_put(msg, NL80211_PMKSA_CANDIDATE_BSSID, ETH_ALEN, bssid) ||
11163 (preauth &&
11164 nla_put_flag(msg, NL80211_PMKSA_CANDIDATE_PREAUTH)))
11165 goto nla_put_failure;
Jouni Malinenc9df56b2011-09-16 18:56:23 +030011166
11167 nla_nest_end(msg, attr);
11168
Johannes Berg3b7b72e2011-10-22 19:05:51 +020011169 genlmsg_end(msg, hdr);
Jouni Malinenc9df56b2011-09-16 18:56:23 +030011170
Johannes Berg68eb5502013-11-19 15:19:38 +010011171 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011172 NL80211_MCGRP_MLME, gfp);
Jouni Malinenc9df56b2011-09-16 18:56:23 +030011173 return;
11174
11175 nla_put_failure:
11176 genlmsg_cancel(msg, hdr);
11177 nlmsg_free(msg);
11178}
11179
Johannes Berg947add32013-02-22 22:05:20 +010011180void cfg80211_pmksa_candidate_notify(struct net_device *dev, int index,
11181 const u8 *bssid, bool preauth, gfp_t gfp)
11182{
11183 struct wireless_dev *wdev = dev->ieee80211_ptr;
11184 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080011185 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg947add32013-02-22 22:05:20 +010011186
11187 trace_cfg80211_pmksa_candidate_notify(dev, index, bssid, preauth);
11188 nl80211_pmksa_candidate_notify(rdev, dev, index, bssid, preauth, gfp);
11189}
11190EXPORT_SYMBOL(cfg80211_pmksa_candidate_notify);
11191
11192static void nl80211_ch_switch_notify(struct cfg80211_registered_device *rdev,
11193 struct net_device *netdev,
11194 struct cfg80211_chan_def *chandef,
11195 gfp_t gfp)
Thomas Pedersen53145262012-04-06 13:35:47 -070011196{
11197 struct sk_buff *msg;
11198 void *hdr;
11199
Thomas Graf58050fc2012-06-28 03:57:45 +000011200 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Thomas Pedersen53145262012-04-06 13:35:47 -070011201 if (!msg)
11202 return;
11203
11204 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CH_SWITCH_NOTIFY);
11205 if (!hdr) {
11206 nlmsg_free(msg);
11207 return;
11208 }
11209
Johannes Berg683b6d32012-11-08 21:25:48 +010011210 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex))
11211 goto nla_put_failure;
11212
11213 if (nl80211_send_chandef(msg, chandef))
John W. Linville7eab0f62012-04-12 14:25:14 -040011214 goto nla_put_failure;
Thomas Pedersen53145262012-04-06 13:35:47 -070011215
11216 genlmsg_end(msg, hdr);
11217
Johannes Berg68eb5502013-11-19 15:19:38 +010011218 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011219 NL80211_MCGRP_MLME, gfp);
Thomas Pedersen53145262012-04-06 13:35:47 -070011220 return;
11221
11222 nla_put_failure:
11223 genlmsg_cancel(msg, hdr);
11224 nlmsg_free(msg);
11225}
11226
Johannes Berg947add32013-02-22 22:05:20 +010011227void cfg80211_ch_switch_notify(struct net_device *dev,
11228 struct cfg80211_chan_def *chandef)
Thomas Pedersen84f10702012-07-12 16:17:33 -070011229{
Johannes Berg947add32013-02-22 22:05:20 +010011230 struct wireless_dev *wdev = dev->ieee80211_ptr;
11231 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080011232 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg947add32013-02-22 22:05:20 +010011233
Simon Wunderliche487eae2013-11-21 18:19:51 +010011234 ASSERT_WDEV_LOCK(wdev);
Johannes Berg947add32013-02-22 22:05:20 +010011235
Simon Wunderliche487eae2013-11-21 18:19:51 +010011236 trace_cfg80211_ch_switch_notify(dev, chandef);
Johannes Berg947add32013-02-22 22:05:20 +010011237
11238 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP &&
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +020011239 wdev->iftype != NL80211_IFTYPE_P2P_GO &&
Chun-Yeow Yeohb8456a12013-10-17 15:55:02 -070011240 wdev->iftype != NL80211_IFTYPE_ADHOC &&
11241 wdev->iftype != NL80211_IFTYPE_MESH_POINT))
Simon Wunderliche487eae2013-11-21 18:19:51 +010011242 return;
Johannes Berg947add32013-02-22 22:05:20 +010011243
Michal Kazior9e0e2962014-01-29 14:22:27 +010011244 wdev->chandef = *chandef;
Janusz Dziedzic96f55f12014-01-24 14:29:21 +010011245 wdev->preset_chandef = *chandef;
Johannes Berg947add32013-02-22 22:05:20 +010011246 nl80211_ch_switch_notify(rdev, dev, chandef, GFP_KERNEL);
Johannes Berg947add32013-02-22 22:05:20 +010011247}
11248EXPORT_SYMBOL(cfg80211_ch_switch_notify);
11249
11250void cfg80211_cqm_txe_notify(struct net_device *dev,
11251 const u8 *peer, u32 num_packets,
11252 u32 rate, u32 intvl, gfp_t gfp)
11253{
11254 struct wireless_dev *wdev = dev->ieee80211_ptr;
11255 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080011256 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Thomas Pedersen84f10702012-07-12 16:17:33 -070011257 struct sk_buff *msg;
11258 struct nlattr *pinfoattr;
11259 void *hdr;
11260
11261 msg = nlmsg_new(NLMSG_GOODSIZE, gfp);
11262 if (!msg)
11263 return;
11264
11265 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM);
11266 if (!hdr) {
11267 nlmsg_free(msg);
11268 return;
11269 }
11270
11271 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg947add32013-02-22 22:05:20 +010011272 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
Thomas Pedersen84f10702012-07-12 16:17:33 -070011273 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer))
11274 goto nla_put_failure;
11275
11276 pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM);
11277 if (!pinfoattr)
11278 goto nla_put_failure;
11279
11280 if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_PKTS, num_packets))
11281 goto nla_put_failure;
11282
11283 if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_RATE, rate))
11284 goto nla_put_failure;
11285
11286 if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_INTVL, intvl))
11287 goto nla_put_failure;
11288
11289 nla_nest_end(msg, pinfoattr);
11290
11291 genlmsg_end(msg, hdr);
11292
Johannes Berg68eb5502013-11-19 15:19:38 +010011293 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011294 NL80211_MCGRP_MLME, gfp);
Thomas Pedersen84f10702012-07-12 16:17:33 -070011295 return;
11296
11297 nla_put_failure:
11298 genlmsg_cancel(msg, hdr);
11299 nlmsg_free(msg);
11300}
Johannes Berg947add32013-02-22 22:05:20 +010011301EXPORT_SYMBOL(cfg80211_cqm_txe_notify);
Thomas Pedersen84f10702012-07-12 16:17:33 -070011302
11303void
Simon Wunderlich04f39042013-02-08 18:16:19 +010011304nl80211_radar_notify(struct cfg80211_registered_device *rdev,
Janusz Dziedzicd2859df2013-11-06 13:55:51 +010011305 const struct cfg80211_chan_def *chandef,
Simon Wunderlich04f39042013-02-08 18:16:19 +010011306 enum nl80211_radar_event event,
11307 struct net_device *netdev, gfp_t gfp)
11308{
11309 struct sk_buff *msg;
11310 void *hdr;
11311
11312 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
11313 if (!msg)
11314 return;
11315
11316 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_RADAR_DETECT);
11317 if (!hdr) {
11318 nlmsg_free(msg);
11319 return;
11320 }
11321
11322 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx))
11323 goto nla_put_failure;
11324
11325 /* NOP and radar events don't need a netdev parameter */
11326 if (netdev) {
11327 struct wireless_dev *wdev = netdev->ieee80211_ptr;
11328
11329 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
11330 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)))
11331 goto nla_put_failure;
11332 }
11333
11334 if (nla_put_u32(msg, NL80211_ATTR_RADAR_EVENT, event))
11335 goto nla_put_failure;
11336
11337 if (nl80211_send_chandef(msg, chandef))
11338 goto nla_put_failure;
11339
Johannes Berg9c90a9f2013-06-04 12:46:03 +020011340 genlmsg_end(msg, hdr);
Simon Wunderlich04f39042013-02-08 18:16:19 +010011341
Johannes Berg68eb5502013-11-19 15:19:38 +010011342 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011343 NL80211_MCGRP_MLME, gfp);
Simon Wunderlich04f39042013-02-08 18:16:19 +010011344 return;
11345
11346 nla_put_failure:
11347 genlmsg_cancel(msg, hdr);
11348 nlmsg_free(msg);
11349}
11350
Johannes Berg947add32013-02-22 22:05:20 +010011351void cfg80211_cqm_pktloss_notify(struct net_device *dev,
11352 const u8 *peer, u32 num_packets, gfp_t gfp)
Johannes Bergc063dbf2010-11-24 08:10:05 +010011353{
Johannes Berg947add32013-02-22 22:05:20 +010011354 struct wireless_dev *wdev = dev->ieee80211_ptr;
11355 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080011356 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Bergc063dbf2010-11-24 08:10:05 +010011357 struct sk_buff *msg;
11358 struct nlattr *pinfoattr;
11359 void *hdr;
11360
Johannes Berg947add32013-02-22 22:05:20 +010011361 trace_cfg80211_cqm_pktloss_notify(dev, peer, num_packets);
11362
Thomas Graf58050fc2012-06-28 03:57:45 +000011363 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Johannes Bergc063dbf2010-11-24 08:10:05 +010011364 if (!msg)
11365 return;
11366
11367 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM);
11368 if (!hdr) {
11369 nlmsg_free(msg);
11370 return;
11371 }
11372
David S. Miller9360ffd2012-03-29 04:41:26 -040011373 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg947add32013-02-22 22:05:20 +010011374 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040011375 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer))
11376 goto nla_put_failure;
Johannes Bergc063dbf2010-11-24 08:10:05 +010011377
11378 pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM);
11379 if (!pinfoattr)
11380 goto nla_put_failure;
11381
David S. Miller9360ffd2012-03-29 04:41:26 -040011382 if (nla_put_u32(msg, NL80211_ATTR_CQM_PKT_LOSS_EVENT, num_packets))
11383 goto nla_put_failure;
Johannes Bergc063dbf2010-11-24 08:10:05 +010011384
11385 nla_nest_end(msg, pinfoattr);
11386
Johannes Berg3b7b72e2011-10-22 19:05:51 +020011387 genlmsg_end(msg, hdr);
Johannes Bergc063dbf2010-11-24 08:10:05 +010011388
Johannes Berg68eb5502013-11-19 15:19:38 +010011389 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011390 NL80211_MCGRP_MLME, gfp);
Johannes Bergc063dbf2010-11-24 08:10:05 +010011391 return;
11392
11393 nla_put_failure:
11394 genlmsg_cancel(msg, hdr);
11395 nlmsg_free(msg);
11396}
Johannes Berg947add32013-02-22 22:05:20 +010011397EXPORT_SYMBOL(cfg80211_cqm_pktloss_notify);
Johannes Bergc063dbf2010-11-24 08:10:05 +010011398
Johannes Berg7f6cf312011-11-04 11:18:15 +010011399void cfg80211_probe_status(struct net_device *dev, const u8 *addr,
11400 u64 cookie, bool acked, gfp_t gfp)
11401{
11402 struct wireless_dev *wdev = dev->ieee80211_ptr;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080011403 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Johannes Berg7f6cf312011-11-04 11:18:15 +010011404 struct sk_buff *msg;
11405 void *hdr;
Johannes Berg7f6cf312011-11-04 11:18:15 +010011406
Beni Lev4ee3e062012-08-27 12:49:39 +030011407 trace_cfg80211_probe_status(dev, addr, cookie, acked);
11408
Thomas Graf58050fc2012-06-28 03:57:45 +000011409 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Beni Lev4ee3e062012-08-27 12:49:39 +030011410
Johannes Berg7f6cf312011-11-04 11:18:15 +010011411 if (!msg)
11412 return;
11413
11414 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PROBE_CLIENT);
11415 if (!hdr) {
11416 nlmsg_free(msg);
11417 return;
11418 }
11419
David S. Miller9360ffd2012-03-29 04:41:26 -040011420 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
11421 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
11422 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) ||
11423 nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie) ||
11424 (acked && nla_put_flag(msg, NL80211_ATTR_ACK)))
11425 goto nla_put_failure;
Johannes Berg7f6cf312011-11-04 11:18:15 +010011426
Johannes Berg9c90a9f2013-06-04 12:46:03 +020011427 genlmsg_end(msg, hdr);
Johannes Berg7f6cf312011-11-04 11:18:15 +010011428
Johannes Berg68eb5502013-11-19 15:19:38 +010011429 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011430 NL80211_MCGRP_MLME, gfp);
Johannes Berg7f6cf312011-11-04 11:18:15 +010011431 return;
11432
11433 nla_put_failure:
11434 genlmsg_cancel(msg, hdr);
11435 nlmsg_free(msg);
11436}
11437EXPORT_SYMBOL(cfg80211_probe_status);
11438
Johannes Berg5e760232011-11-04 11:18:17 +010011439void cfg80211_report_obss_beacon(struct wiphy *wiphy,
11440 const u8 *frame, size_t len,
Ben Greear37c73b52012-10-26 14:49:25 -070011441 int freq, int sig_dbm)
Johannes Berg5e760232011-11-04 11:18:17 +010011442{
Zhao, Gangf26cbf42014-04-21 12:53:03 +080011443 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg5e760232011-11-04 11:18:17 +010011444 struct sk_buff *msg;
11445 void *hdr;
Ben Greear37c73b52012-10-26 14:49:25 -070011446 struct cfg80211_beacon_registration *reg;
Johannes Berg5e760232011-11-04 11:18:17 +010011447
Beni Lev4ee3e062012-08-27 12:49:39 +030011448 trace_cfg80211_report_obss_beacon(wiphy, frame, len, freq, sig_dbm);
11449
Ben Greear37c73b52012-10-26 14:49:25 -070011450 spin_lock_bh(&rdev->beacon_registrations_lock);
11451 list_for_each_entry(reg, &rdev->beacon_registrations, list) {
11452 msg = nlmsg_new(len + 100, GFP_ATOMIC);
11453 if (!msg) {
11454 spin_unlock_bh(&rdev->beacon_registrations_lock);
11455 return;
11456 }
Johannes Berg5e760232011-11-04 11:18:17 +010011457
Ben Greear37c73b52012-10-26 14:49:25 -070011458 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME);
11459 if (!hdr)
11460 goto nla_put_failure;
Johannes Berg5e760232011-11-04 11:18:17 +010011461
Ben Greear37c73b52012-10-26 14:49:25 -070011462 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
11463 (freq &&
11464 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq)) ||
11465 (sig_dbm &&
11466 nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) ||
11467 nla_put(msg, NL80211_ATTR_FRAME, len, frame))
11468 goto nla_put_failure;
11469
11470 genlmsg_end(msg, hdr);
11471
11472 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, reg->nlportid);
Johannes Berg5e760232011-11-04 11:18:17 +010011473 }
Ben Greear37c73b52012-10-26 14:49:25 -070011474 spin_unlock_bh(&rdev->beacon_registrations_lock);
Johannes Berg5e760232011-11-04 11:18:17 +010011475 return;
11476
11477 nla_put_failure:
Ben Greear37c73b52012-10-26 14:49:25 -070011478 spin_unlock_bh(&rdev->beacon_registrations_lock);
11479 if (hdr)
11480 genlmsg_cancel(msg, hdr);
Johannes Berg5e760232011-11-04 11:18:17 +010011481 nlmsg_free(msg);
11482}
11483EXPORT_SYMBOL(cfg80211_report_obss_beacon);
11484
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010011485#ifdef CONFIG_PM
11486void cfg80211_report_wowlan_wakeup(struct wireless_dev *wdev,
11487 struct cfg80211_wowlan_wakeup *wakeup,
11488 gfp_t gfp)
11489{
Zhao, Gangf26cbf42014-04-21 12:53:03 +080011490 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010011491 struct sk_buff *msg;
11492 void *hdr;
Johannes Berg9c90a9f2013-06-04 12:46:03 +020011493 int size = 200;
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010011494
11495 trace_cfg80211_report_wowlan_wakeup(wdev->wiphy, wdev, wakeup);
11496
11497 if (wakeup)
11498 size += wakeup->packet_present_len;
11499
11500 msg = nlmsg_new(size, gfp);
11501 if (!msg)
11502 return;
11503
11504 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_WOWLAN);
11505 if (!hdr)
11506 goto free_msg;
11507
11508 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
11509 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)))
11510 goto free_msg;
11511
11512 if (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
11513 wdev->netdev->ifindex))
11514 goto free_msg;
11515
11516 if (wakeup) {
11517 struct nlattr *reasons;
11518
11519 reasons = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS);
Johannes Berg7fa322c2013-10-25 11:16:58 +020011520 if (!reasons)
11521 goto free_msg;
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010011522
11523 if (wakeup->disconnect &&
11524 nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT))
11525 goto free_msg;
11526 if (wakeup->magic_pkt &&
11527 nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT))
11528 goto free_msg;
11529 if (wakeup->gtk_rekey_failure &&
11530 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE))
11531 goto free_msg;
11532 if (wakeup->eap_identity_req &&
11533 nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST))
11534 goto free_msg;
11535 if (wakeup->four_way_handshake &&
11536 nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE))
11537 goto free_msg;
11538 if (wakeup->rfkill_release &&
11539 nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE))
11540 goto free_msg;
11541
11542 if (wakeup->pattern_idx >= 0 &&
11543 nla_put_u32(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN,
11544 wakeup->pattern_idx))
11545 goto free_msg;
11546
Johannes Bergae917c92013-10-25 11:05:22 +020011547 if (wakeup->tcp_match &&
11548 nla_put_flag(msg, NL80211_WOWLAN_TRIG_WAKEUP_TCP_MATCH))
11549 goto free_msg;
Johannes Berg2a0e0472013-01-23 22:57:40 +010011550
Johannes Bergae917c92013-10-25 11:05:22 +020011551 if (wakeup->tcp_connlost &&
11552 nla_put_flag(msg, NL80211_WOWLAN_TRIG_WAKEUP_TCP_CONNLOST))
11553 goto free_msg;
Johannes Berg2a0e0472013-01-23 22:57:40 +010011554
Johannes Bergae917c92013-10-25 11:05:22 +020011555 if (wakeup->tcp_nomoretokens &&
11556 nla_put_flag(msg,
11557 NL80211_WOWLAN_TRIG_WAKEUP_TCP_NOMORETOKENS))
11558 goto free_msg;
Johannes Berg2a0e0472013-01-23 22:57:40 +010011559
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010011560 if (wakeup->packet) {
11561 u32 pkt_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211;
11562 u32 len_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211_LEN;
11563
11564 if (!wakeup->packet_80211) {
11565 pkt_attr =
11566 NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023;
11567 len_attr =
11568 NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023_LEN;
11569 }
11570
11571 if (wakeup->packet_len &&
11572 nla_put_u32(msg, len_attr, wakeup->packet_len))
11573 goto free_msg;
11574
11575 if (nla_put(msg, pkt_attr, wakeup->packet_present_len,
11576 wakeup->packet))
11577 goto free_msg;
11578 }
11579
11580 nla_nest_end(msg, reasons);
11581 }
11582
Johannes Berg9c90a9f2013-06-04 12:46:03 +020011583 genlmsg_end(msg, hdr);
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010011584
Johannes Berg68eb5502013-11-19 15:19:38 +010011585 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011586 NL80211_MCGRP_MLME, gfp);
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010011587 return;
11588
11589 free_msg:
11590 nlmsg_free(msg);
11591}
11592EXPORT_SYMBOL(cfg80211_report_wowlan_wakeup);
11593#endif
11594
Jouni Malinen3475b092012-11-16 22:49:57 +020011595void cfg80211_tdls_oper_request(struct net_device *dev, const u8 *peer,
11596 enum nl80211_tdls_operation oper,
11597 u16 reason_code, gfp_t gfp)
11598{
11599 struct wireless_dev *wdev = dev->ieee80211_ptr;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080011600 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Jouni Malinen3475b092012-11-16 22:49:57 +020011601 struct sk_buff *msg;
11602 void *hdr;
Jouni Malinen3475b092012-11-16 22:49:57 +020011603
11604 trace_cfg80211_tdls_oper_request(wdev->wiphy, dev, peer, oper,
11605 reason_code);
11606
11607 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
11608 if (!msg)
11609 return;
11610
11611 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_TDLS_OPER);
11612 if (!hdr) {
11613 nlmsg_free(msg);
11614 return;
11615 }
11616
11617 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
11618 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
11619 nla_put_u8(msg, NL80211_ATTR_TDLS_OPERATION, oper) ||
11620 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer) ||
11621 (reason_code > 0 &&
11622 nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason_code)))
11623 goto nla_put_failure;
11624
Johannes Berg9c90a9f2013-06-04 12:46:03 +020011625 genlmsg_end(msg, hdr);
Jouni Malinen3475b092012-11-16 22:49:57 +020011626
Johannes Berg68eb5502013-11-19 15:19:38 +010011627 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011628 NL80211_MCGRP_MLME, gfp);
Jouni Malinen3475b092012-11-16 22:49:57 +020011629 return;
11630
11631 nla_put_failure:
11632 genlmsg_cancel(msg, hdr);
11633 nlmsg_free(msg);
11634}
11635EXPORT_SYMBOL(cfg80211_tdls_oper_request);
11636
Jouni Malinen026331c2010-02-15 12:53:10 +020011637static int nl80211_netlink_notify(struct notifier_block * nb,
11638 unsigned long state,
11639 void *_notify)
11640{
11641 struct netlink_notify *notify = _notify;
11642 struct cfg80211_registered_device *rdev;
11643 struct wireless_dev *wdev;
Ben Greear37c73b52012-10-26 14:49:25 -070011644 struct cfg80211_beacon_registration *reg, *tmp;
Jouni Malinen026331c2010-02-15 12:53:10 +020011645
11646 if (state != NETLINK_URELEASE)
11647 return NOTIFY_DONE;
11648
11649 rcu_read_lock();
11650
Johannes Berg5e760232011-11-04 11:18:17 +010011651 list_for_each_entry_rcu(rdev, &cfg80211_rdev_list, list) {
Johannes Berg78f22b62014-03-24 17:57:27 +010011652 bool schedule_destroy_work = false;
11653
11654 list_for_each_entry_rcu(wdev, &rdev->wdev_list, list) {
Eric W. Biederman15e47302012-09-07 20:12:54 +000011655 cfg80211_mlme_unregister_socket(wdev, notify->portid);
Ben Greear37c73b52012-10-26 14:49:25 -070011656
Johannes Berg78f22b62014-03-24 17:57:27 +010011657 if (wdev->owner_nlportid == notify->portid)
11658 schedule_destroy_work = true;
11659 }
11660
Ben Greear37c73b52012-10-26 14:49:25 -070011661 spin_lock_bh(&rdev->beacon_registrations_lock);
11662 list_for_each_entry_safe(reg, tmp, &rdev->beacon_registrations,
11663 list) {
11664 if (reg->nlportid == notify->portid) {
11665 list_del(&reg->list);
11666 kfree(reg);
11667 break;
11668 }
11669 }
11670 spin_unlock_bh(&rdev->beacon_registrations_lock);
Johannes Berg78f22b62014-03-24 17:57:27 +010011671
11672 if (schedule_destroy_work) {
11673 struct cfg80211_iface_destroy *destroy;
11674
11675 destroy = kzalloc(sizeof(*destroy), GFP_ATOMIC);
11676 if (destroy) {
11677 destroy->nlportid = notify->portid;
11678 spin_lock(&rdev->destroy_list_lock);
11679 list_add(&destroy->list, &rdev->destroy_list);
11680 spin_unlock(&rdev->destroy_list_lock);
11681 schedule_work(&rdev->destroy_work);
11682 }
11683 }
Johannes Berg5e760232011-11-04 11:18:17 +010011684 }
Jouni Malinen026331c2010-02-15 12:53:10 +020011685
11686 rcu_read_unlock();
11687
Zhao, Gang6784c7d2014-04-21 12:53:04 +080011688 return NOTIFY_OK;
Jouni Malinen026331c2010-02-15 12:53:10 +020011689}
11690
11691static struct notifier_block nl80211_netlink_notifier = {
11692 .notifier_call = nl80211_netlink_notify,
11693};
11694
Jouni Malinen355199e2013-02-27 17:14:27 +020011695void cfg80211_ft_event(struct net_device *netdev,
11696 struct cfg80211_ft_event_params *ft_event)
11697{
11698 struct wiphy *wiphy = netdev->ieee80211_ptr->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080011699 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Jouni Malinen355199e2013-02-27 17:14:27 +020011700 struct sk_buff *msg;
11701 void *hdr;
Jouni Malinen355199e2013-02-27 17:14:27 +020011702
11703 trace_cfg80211_ft_event(wiphy, netdev, ft_event);
11704
11705 if (!ft_event->target_ap)
11706 return;
11707
11708 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
11709 if (!msg)
11710 return;
11711
11712 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FT_EVENT);
Johannes Bergae917c92013-10-25 11:05:22 +020011713 if (!hdr)
11714 goto out;
Jouni Malinen355199e2013-02-27 17:14:27 +020011715
Johannes Bergae917c92013-10-25 11:05:22 +020011716 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
11717 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
11718 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, ft_event->target_ap))
11719 goto out;
11720
11721 if (ft_event->ies &&
11722 nla_put(msg, NL80211_ATTR_IE, ft_event->ies_len, ft_event->ies))
11723 goto out;
11724 if (ft_event->ric_ies &&
11725 nla_put(msg, NL80211_ATTR_IE_RIC, ft_event->ric_ies_len,
11726 ft_event->ric_ies))
11727 goto out;
Jouni Malinen355199e2013-02-27 17:14:27 +020011728
Johannes Berg9c90a9f2013-06-04 12:46:03 +020011729 genlmsg_end(msg, hdr);
Jouni Malinen355199e2013-02-27 17:14:27 +020011730
Johannes Berg68eb5502013-11-19 15:19:38 +010011731 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011732 NL80211_MCGRP_MLME, GFP_KERNEL);
Johannes Bergae917c92013-10-25 11:05:22 +020011733 return;
11734 out:
11735 nlmsg_free(msg);
Jouni Malinen355199e2013-02-27 17:14:27 +020011736}
11737EXPORT_SYMBOL(cfg80211_ft_event);
11738
Arend van Spriel5de17982013-04-18 15:49:00 +020011739void cfg80211_crit_proto_stopped(struct wireless_dev *wdev, gfp_t gfp)
11740{
11741 struct cfg80211_registered_device *rdev;
11742 struct sk_buff *msg;
11743 void *hdr;
11744 u32 nlportid;
11745
Zhao, Gangf26cbf42014-04-21 12:53:03 +080011746 rdev = wiphy_to_rdev(wdev->wiphy);
Arend van Spriel5de17982013-04-18 15:49:00 +020011747 if (!rdev->crit_proto_nlportid)
11748 return;
11749
11750 nlportid = rdev->crit_proto_nlportid;
11751 rdev->crit_proto_nlportid = 0;
11752
11753 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
11754 if (!msg)
11755 return;
11756
11757 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CRIT_PROTOCOL_STOP);
11758 if (!hdr)
11759 goto nla_put_failure;
11760
11761 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
11762 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)))
11763 goto nla_put_failure;
11764
11765 genlmsg_end(msg, hdr);
11766
11767 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid);
11768 return;
11769
11770 nla_put_failure:
11771 if (hdr)
11772 genlmsg_cancel(msg, hdr);
11773 nlmsg_free(msg);
11774
11775}
11776EXPORT_SYMBOL(cfg80211_crit_proto_stopped);
11777
Johannes Berg348baf02014-01-24 14:06:29 +010011778void nl80211_send_ap_stopped(struct wireless_dev *wdev)
11779{
11780 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080011781 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg348baf02014-01-24 14:06:29 +010011782 struct sk_buff *msg;
11783 void *hdr;
11784
11785 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
11786 if (!msg)
11787 return;
11788
11789 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_STOP_AP);
11790 if (!hdr)
11791 goto out;
11792
11793 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
11794 nla_put_u32(msg, NL80211_ATTR_IFINDEX, wdev->netdev->ifindex) ||
11795 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)))
11796 goto out;
11797
11798 genlmsg_end(msg, hdr);
11799
11800 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(wiphy), msg, 0,
11801 NL80211_MCGRP_MLME, GFP_KERNEL);
11802 return;
11803 out:
11804 nlmsg_free(msg);
11805}
11806
Johannes Berg55682962007-09-20 13:09:35 -040011807/* initialisation/exit functions */
11808
11809int nl80211_init(void)
11810{
Michał Mirosław0d63cbb2009-05-21 10:34:06 +000011811 int err;
Johannes Berg55682962007-09-20 13:09:35 -040011812
Johannes Berg2a94fe42013-11-19 15:19:39 +010011813 err = genl_register_family_with_ops_groups(&nl80211_fam, nl80211_ops,
11814 nl80211_mcgrps);
Johannes Berg55682962007-09-20 13:09:35 -040011815 if (err)
11816 return err;
11817
Jouni Malinen026331c2010-02-15 12:53:10 +020011818 err = netlink_register_notifier(&nl80211_netlink_notifier);
11819 if (err)
11820 goto err_out;
11821
Johannes Berg55682962007-09-20 13:09:35 -040011822 return 0;
11823 err_out:
11824 genl_unregister_family(&nl80211_fam);
11825 return err;
11826}
11827
11828void nl80211_exit(void)
11829{
Jouni Malinen026331c2010-02-15 12:53:10 +020011830 netlink_unregister_notifier(&nl80211_netlink_notifier);
Johannes Berg55682962007-09-20 13:09:35 -040011831 genl_unregister_family(&nl80211_fam);
11832}