blob: 9ed6ef6fd2c5413250dd9d11e6566cd5723c6546 [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)
171 tmp = wiphy_to_dev(
172 netdev->ieee80211_ptr->wiphy);
173 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 Malinendc6382ce2009-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 },
Johannes Berg55682962007-09-20 13:09:35 -0400387};
388
Johannes Berge31b8212010-10-05 19:39:30 +0200389/* policy for the key attributes */
Alexey Dobriyanb54452b2010-02-18 08:14:31 +0000390static const struct nla_policy nl80211_key_policy[NL80211_KEY_MAX + 1] = {
Johannes Bergfffd0932009-07-08 14:22:54 +0200391 [NL80211_KEY_DATA] = { .type = NLA_BINARY, .len = WLAN_MAX_KEY_LEN },
Johannes Bergb9454e82009-07-08 13:29:08 +0200392 [NL80211_KEY_IDX] = { .type = NLA_U8 },
393 [NL80211_KEY_CIPHER] = { .type = NLA_U32 },
Jouni Malinen81962262011-11-02 23:36:31 +0200394 [NL80211_KEY_SEQ] = { .type = NLA_BINARY, .len = 16 },
Johannes Bergb9454e82009-07-08 13:29:08 +0200395 [NL80211_KEY_DEFAULT] = { .type = NLA_FLAG },
396 [NL80211_KEY_DEFAULT_MGMT] = { .type = NLA_FLAG },
Johannes Berge31b8212010-10-05 19:39:30 +0200397 [NL80211_KEY_TYPE] = { .type = NLA_U32 },
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100398 [NL80211_KEY_DEFAULT_TYPES] = { .type = NLA_NESTED },
399};
400
401/* policy for the key default flags */
402static const struct nla_policy
403nl80211_key_default_policy[NUM_NL80211_KEY_DEFAULT_TYPES] = {
404 [NL80211_KEY_DEFAULT_TYPE_UNICAST] = { .type = NLA_FLAG },
405 [NL80211_KEY_DEFAULT_TYPE_MULTICAST] = { .type = NLA_FLAG },
Johannes Bergb9454e82009-07-08 13:29:08 +0200406};
407
Johannes Bergff1b6e62011-05-04 15:37:28 +0200408/* policy for WoWLAN attributes */
409static const struct nla_policy
410nl80211_wowlan_policy[NUM_NL80211_WOWLAN_TRIG] = {
411 [NL80211_WOWLAN_TRIG_ANY] = { .type = NLA_FLAG },
412 [NL80211_WOWLAN_TRIG_DISCONNECT] = { .type = NLA_FLAG },
413 [NL80211_WOWLAN_TRIG_MAGIC_PKT] = { .type = NLA_FLAG },
414 [NL80211_WOWLAN_TRIG_PKT_PATTERN] = { .type = NLA_NESTED },
Johannes Berg77dbbb12011-07-13 10:48:55 +0200415 [NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE] = { .type = NLA_FLAG },
416 [NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST] = { .type = NLA_FLAG },
417 [NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE] = { .type = NLA_FLAG },
418 [NL80211_WOWLAN_TRIG_RFKILL_RELEASE] = { .type = NLA_FLAG },
Johannes Berg2a0e0472013-01-23 22:57:40 +0100419 [NL80211_WOWLAN_TRIG_TCP_CONNECTION] = { .type = NLA_NESTED },
420};
421
422static const struct nla_policy
423nl80211_wowlan_tcp_policy[NUM_NL80211_WOWLAN_TCP] = {
424 [NL80211_WOWLAN_TCP_SRC_IPV4] = { .type = NLA_U32 },
425 [NL80211_WOWLAN_TCP_DST_IPV4] = { .type = NLA_U32 },
426 [NL80211_WOWLAN_TCP_DST_MAC] = { .len = ETH_ALEN },
427 [NL80211_WOWLAN_TCP_SRC_PORT] = { .type = NLA_U16 },
428 [NL80211_WOWLAN_TCP_DST_PORT] = { .type = NLA_U16 },
429 [NL80211_WOWLAN_TCP_DATA_PAYLOAD] = { .len = 1 },
430 [NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ] = {
431 .len = sizeof(struct nl80211_wowlan_tcp_data_seq)
432 },
433 [NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN] = {
434 .len = sizeof(struct nl80211_wowlan_tcp_data_token)
435 },
436 [NL80211_WOWLAN_TCP_DATA_INTERVAL] = { .type = NLA_U32 },
437 [NL80211_WOWLAN_TCP_WAKE_PAYLOAD] = { .len = 1 },
438 [NL80211_WOWLAN_TCP_WAKE_MASK] = { .len = 1 },
Johannes Bergff1b6e62011-05-04 15:37:28 +0200439};
440
Amitkumar Karwarbe29b992013-06-28 11:51:26 -0700441/* policy for coalesce rule attributes */
442static const struct nla_policy
443nl80211_coalesce_policy[NUM_NL80211_ATTR_COALESCE_RULE] = {
444 [NL80211_ATTR_COALESCE_RULE_DELAY] = { .type = NLA_U32 },
445 [NL80211_ATTR_COALESCE_RULE_CONDITION] = { .type = NLA_U32 },
446 [NL80211_ATTR_COALESCE_RULE_PKT_PATTERN] = { .type = NLA_NESTED },
447};
448
Johannes Berge5497d72011-07-05 16:35:40 +0200449/* policy for GTK rekey offload attributes */
450static const struct nla_policy
451nl80211_rekey_policy[NUM_NL80211_REKEY_DATA] = {
452 [NL80211_REKEY_DATA_KEK] = { .len = NL80211_KEK_LEN },
453 [NL80211_REKEY_DATA_KCK] = { .len = NL80211_KCK_LEN },
454 [NL80211_REKEY_DATA_REPLAY_CTR] = { .len = NL80211_REPLAY_CTR_LEN },
455};
456
Luciano Coelhoa1f1c212011-08-31 16:01:48 +0300457static const struct nla_policy
458nl80211_match_policy[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1] = {
Johannes Berg4a4ab0d2012-06-13 11:17:11 +0200459 [NL80211_SCHED_SCAN_MATCH_ATTR_SSID] = { .type = NLA_BINARY,
Luciano Coelhoa1f1c212011-08-31 16:01:48 +0300460 .len = IEEE80211_MAX_SSID_LEN },
Thomas Pedersen88e920b2012-06-21 11:09:54 -0700461 [NL80211_SCHED_SCAN_MATCH_ATTR_RSSI] = { .type = NLA_U32 },
Luciano Coelhoa1f1c212011-08-31 16:01:48 +0300462};
463
Johannes Berg97990a02013-04-19 01:02:55 +0200464static int nl80211_prepare_wdev_dump(struct sk_buff *skb,
465 struct netlink_callback *cb,
466 struct cfg80211_registered_device **rdev,
467 struct wireless_dev **wdev)
Holger Schuriga0438972009-11-11 11:30:02 +0100468{
Johannes Berg67748892010-10-04 21:14:06 +0200469 int err;
470
Johannes Berg67748892010-10-04 21:14:06 +0200471 rtnl_lock();
472
Johannes Berg97990a02013-04-19 01:02:55 +0200473 if (!cb->args[0]) {
474 err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize,
475 nl80211_fam.attrbuf, nl80211_fam.maxattr,
476 nl80211_policy);
477 if (err)
478 goto out_unlock;
479
480 *wdev = __cfg80211_wdev_from_attrs(sock_net(skb->sk),
481 nl80211_fam.attrbuf);
482 if (IS_ERR(*wdev)) {
483 err = PTR_ERR(*wdev);
484 goto out_unlock;
485 }
486 *rdev = wiphy_to_dev((*wdev)->wiphy);
Johannes Bergc319d502013-07-30 22:34:28 +0200487 /* 0 is the first index - add 1 to parse only once */
488 cb->args[0] = (*rdev)->wiphy_idx + 1;
Johannes Berg97990a02013-04-19 01:02:55 +0200489 cb->args[1] = (*wdev)->identifier;
490 } else {
Johannes Bergc319d502013-07-30 22:34:28 +0200491 /* subtract the 1 again here */
492 struct wiphy *wiphy = wiphy_idx_to_wiphy(cb->args[0] - 1);
Johannes Berg97990a02013-04-19 01:02:55 +0200493 struct wireless_dev *tmp;
494
495 if (!wiphy) {
496 err = -ENODEV;
497 goto out_unlock;
498 }
499 *rdev = wiphy_to_dev(wiphy);
500 *wdev = NULL;
501
Johannes Berg97990a02013-04-19 01:02:55 +0200502 list_for_each_entry(tmp, &(*rdev)->wdev_list, list) {
503 if (tmp->identifier == cb->args[1]) {
504 *wdev = tmp;
505 break;
506 }
507 }
Johannes Berg97990a02013-04-19 01:02:55 +0200508
509 if (!*wdev) {
510 err = -ENODEV;
511 goto out_unlock;
512 }
Johannes Berg67748892010-10-04 21:14:06 +0200513 }
514
Johannes Berg67748892010-10-04 21:14:06 +0200515 return 0;
Johannes Berg97990a02013-04-19 01:02:55 +0200516 out_unlock:
Johannes Berg67748892010-10-04 21:14:06 +0200517 rtnl_unlock();
518 return err;
519}
520
Johannes Berg97990a02013-04-19 01:02:55 +0200521static void nl80211_finish_wdev_dump(struct cfg80211_registered_device *rdev)
Johannes Berg67748892010-10-04 21:14:06 +0200522{
Johannes Berg67748892010-10-04 21:14:06 +0200523 rtnl_unlock();
524}
525
Johannes Bergf4a11bb2009-03-27 12:40:28 +0100526/* IE validation */
527static bool is_valid_ie_attr(const struct nlattr *attr)
528{
529 const u8 *pos;
530 int len;
531
532 if (!attr)
533 return true;
534
535 pos = nla_data(attr);
536 len = nla_len(attr);
537
538 while (len) {
539 u8 elemlen;
540
541 if (len < 2)
542 return false;
543 len -= 2;
544
545 elemlen = pos[1];
546 if (elemlen > len)
547 return false;
548
549 len -= elemlen;
550 pos += 2 + elemlen;
551 }
552
553 return true;
554}
555
Johannes Berg55682962007-09-20 13:09:35 -0400556/* message building helper */
Eric W. Biederman15e47302012-09-07 20:12:54 +0000557static inline void *nl80211hdr_put(struct sk_buff *skb, u32 portid, u32 seq,
Johannes Berg55682962007-09-20 13:09:35 -0400558 int flags, u8 cmd)
559{
560 /* since there is no private header just add the generic one */
Eric W. Biederman15e47302012-09-07 20:12:54 +0000561 return genlmsg_put(skb, portid, seq, &nl80211_fam, flags, cmd);
Johannes Berg55682962007-09-20 13:09:35 -0400562}
563
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400564static int nl80211_msg_put_channel(struct sk_buff *msg,
Johannes Bergcdc89b92013-02-18 23:54:36 +0100565 struct ieee80211_channel *chan,
566 bool large)
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400567{
David S. Miller9360ffd2012-03-29 04:41:26 -0400568 if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_FREQ,
569 chan->center_freq))
570 goto nla_put_failure;
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400571
David S. Miller9360ffd2012-03-29 04:41:26 -0400572 if ((chan->flags & IEEE80211_CHAN_DISABLED) &&
573 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_DISABLED))
574 goto nla_put_failure;
Luis R. Rodriguez8fe02e12013-10-21 19:22:25 +0200575 if (chan->flags & IEEE80211_CHAN_NO_IR) {
576 if (nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_IR))
577 goto nla_put_failure;
578 if (nla_put_flag(msg, __NL80211_FREQUENCY_ATTR_NO_IBSS))
579 goto nla_put_failure;
580 }
Johannes Bergcdc89b92013-02-18 23:54:36 +0100581 if (chan->flags & IEEE80211_CHAN_RADAR) {
582 if (nla_put_flag(msg, NL80211_FREQUENCY_ATTR_RADAR))
583 goto nla_put_failure;
584 if (large) {
585 u32 time;
586
587 time = elapsed_jiffies_msecs(chan->dfs_state_entered);
588
589 if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_DFS_STATE,
590 chan->dfs_state))
591 goto nla_put_failure;
592 if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_DFS_TIME,
593 time))
594 goto nla_put_failure;
595 }
596 }
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400597
Johannes Bergfe1abaf2013-02-27 15:39:45 +0100598 if (large) {
599 if ((chan->flags & IEEE80211_CHAN_NO_HT40MINUS) &&
600 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_HT40_MINUS))
601 goto nla_put_failure;
602 if ((chan->flags & IEEE80211_CHAN_NO_HT40PLUS) &&
603 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_HT40_PLUS))
604 goto nla_put_failure;
605 if ((chan->flags & IEEE80211_CHAN_NO_80MHZ) &&
606 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_80MHZ))
607 goto nla_put_failure;
608 if ((chan->flags & IEEE80211_CHAN_NO_160MHZ) &&
609 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_160MHZ))
610 goto nla_put_failure;
611 }
612
David S. Miller9360ffd2012-03-29 04:41:26 -0400613 if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_MAX_TX_POWER,
614 DBM_TO_MBM(chan->max_power)))
615 goto nla_put_failure;
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400616
617 return 0;
618
619 nla_put_failure:
620 return -ENOBUFS;
621}
622
Johannes Berg55682962007-09-20 13:09:35 -0400623/* netlink command implementations */
624
Johannes Bergb9454e82009-07-08 13:29:08 +0200625struct key_parse {
626 struct key_params p;
627 int idx;
Johannes Berge31b8212010-10-05 19:39:30 +0200628 int type;
Johannes Bergb9454e82009-07-08 13:29:08 +0200629 bool def, defmgmt;
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100630 bool def_uni, def_multi;
Johannes Bergb9454e82009-07-08 13:29:08 +0200631};
632
633static int nl80211_parse_key_new(struct nlattr *key, struct key_parse *k)
634{
635 struct nlattr *tb[NL80211_KEY_MAX + 1];
636 int err = nla_parse_nested(tb, NL80211_KEY_MAX, key,
637 nl80211_key_policy);
638 if (err)
639 return err;
640
641 k->def = !!tb[NL80211_KEY_DEFAULT];
642 k->defmgmt = !!tb[NL80211_KEY_DEFAULT_MGMT];
643
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100644 if (k->def) {
645 k->def_uni = true;
646 k->def_multi = true;
647 }
648 if (k->defmgmt)
649 k->def_multi = true;
650
Johannes Bergb9454e82009-07-08 13:29:08 +0200651 if (tb[NL80211_KEY_IDX])
652 k->idx = nla_get_u8(tb[NL80211_KEY_IDX]);
653
654 if (tb[NL80211_KEY_DATA]) {
655 k->p.key = nla_data(tb[NL80211_KEY_DATA]);
656 k->p.key_len = nla_len(tb[NL80211_KEY_DATA]);
657 }
658
659 if (tb[NL80211_KEY_SEQ]) {
660 k->p.seq = nla_data(tb[NL80211_KEY_SEQ]);
661 k->p.seq_len = nla_len(tb[NL80211_KEY_SEQ]);
662 }
663
664 if (tb[NL80211_KEY_CIPHER])
665 k->p.cipher = nla_get_u32(tb[NL80211_KEY_CIPHER]);
666
Johannes Berge31b8212010-10-05 19:39:30 +0200667 if (tb[NL80211_KEY_TYPE]) {
668 k->type = nla_get_u32(tb[NL80211_KEY_TYPE]);
669 if (k->type < 0 || k->type >= NUM_NL80211_KEYTYPES)
670 return -EINVAL;
671 }
672
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100673 if (tb[NL80211_KEY_DEFAULT_TYPES]) {
674 struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES];
Johannes Berg2da8f412012-01-20 13:52:37 +0100675 err = nla_parse_nested(kdt, NUM_NL80211_KEY_DEFAULT_TYPES - 1,
676 tb[NL80211_KEY_DEFAULT_TYPES],
677 nl80211_key_default_policy);
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100678 if (err)
679 return err;
680
681 k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST];
682 k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST];
683 }
684
Johannes Bergb9454e82009-07-08 13:29:08 +0200685 return 0;
686}
687
688static int nl80211_parse_key_old(struct genl_info *info, struct key_parse *k)
689{
690 if (info->attrs[NL80211_ATTR_KEY_DATA]) {
691 k->p.key = nla_data(info->attrs[NL80211_ATTR_KEY_DATA]);
692 k->p.key_len = nla_len(info->attrs[NL80211_ATTR_KEY_DATA]);
693 }
694
695 if (info->attrs[NL80211_ATTR_KEY_SEQ]) {
696 k->p.seq = nla_data(info->attrs[NL80211_ATTR_KEY_SEQ]);
697 k->p.seq_len = nla_len(info->attrs[NL80211_ATTR_KEY_SEQ]);
698 }
699
700 if (info->attrs[NL80211_ATTR_KEY_IDX])
701 k->idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]);
702
703 if (info->attrs[NL80211_ATTR_KEY_CIPHER])
704 k->p.cipher = nla_get_u32(info->attrs[NL80211_ATTR_KEY_CIPHER]);
705
706 k->def = !!info->attrs[NL80211_ATTR_KEY_DEFAULT];
707 k->defmgmt = !!info->attrs[NL80211_ATTR_KEY_DEFAULT_MGMT];
708
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100709 if (k->def) {
710 k->def_uni = true;
711 k->def_multi = true;
712 }
713 if (k->defmgmt)
714 k->def_multi = true;
715
Johannes Berge31b8212010-10-05 19:39:30 +0200716 if (info->attrs[NL80211_ATTR_KEY_TYPE]) {
717 k->type = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]);
718 if (k->type < 0 || k->type >= NUM_NL80211_KEYTYPES)
719 return -EINVAL;
720 }
721
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100722 if (info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES]) {
723 struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES];
724 int err = nla_parse_nested(
725 kdt, NUM_NL80211_KEY_DEFAULT_TYPES - 1,
726 info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES],
727 nl80211_key_default_policy);
728 if (err)
729 return err;
730
731 k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST];
732 k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST];
733 }
734
Johannes Bergb9454e82009-07-08 13:29:08 +0200735 return 0;
736}
737
738static int nl80211_parse_key(struct genl_info *info, struct key_parse *k)
739{
740 int err;
741
742 memset(k, 0, sizeof(*k));
743 k->idx = -1;
Johannes Berge31b8212010-10-05 19:39:30 +0200744 k->type = -1;
Johannes Bergb9454e82009-07-08 13:29:08 +0200745
746 if (info->attrs[NL80211_ATTR_KEY])
747 err = nl80211_parse_key_new(info->attrs[NL80211_ATTR_KEY], k);
748 else
749 err = nl80211_parse_key_old(info, k);
750
751 if (err)
752 return err;
753
754 if (k->def && k->defmgmt)
755 return -EINVAL;
756
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100757 if (k->defmgmt) {
758 if (k->def_uni || !k->def_multi)
759 return -EINVAL;
760 }
761
Johannes Bergb9454e82009-07-08 13:29:08 +0200762 if (k->idx != -1) {
763 if (k->defmgmt) {
764 if (k->idx < 4 || k->idx > 5)
765 return -EINVAL;
766 } else if (k->def) {
767 if (k->idx < 0 || k->idx > 3)
768 return -EINVAL;
769 } else {
770 if (k->idx < 0 || k->idx > 5)
771 return -EINVAL;
772 }
773 }
774
775 return 0;
776}
777
Johannes Bergfffd0932009-07-08 14:22:54 +0200778static struct cfg80211_cached_keys *
779nl80211_parse_connkeys(struct cfg80211_registered_device *rdev,
Sujith Manoharande7044e2012-10-18 10:19:28 +0530780 struct nlattr *keys, bool *no_ht)
Johannes Bergfffd0932009-07-08 14:22:54 +0200781{
782 struct key_parse parse;
783 struct nlattr *key;
784 struct cfg80211_cached_keys *result;
785 int rem, err, def = 0;
786
787 result = kzalloc(sizeof(*result), GFP_KERNEL);
788 if (!result)
789 return ERR_PTR(-ENOMEM);
790
791 result->def = -1;
792 result->defmgmt = -1;
793
794 nla_for_each_nested(key, keys, rem) {
795 memset(&parse, 0, sizeof(parse));
796 parse.idx = -1;
797
798 err = nl80211_parse_key_new(key, &parse);
799 if (err)
800 goto error;
801 err = -EINVAL;
802 if (!parse.p.key)
803 goto error;
804 if (parse.idx < 0 || parse.idx > 4)
805 goto error;
806 if (parse.def) {
807 if (def)
808 goto error;
809 def = 1;
810 result->def = parse.idx;
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100811 if (!parse.def_uni || !parse.def_multi)
812 goto error;
Johannes Bergfffd0932009-07-08 14:22:54 +0200813 } else if (parse.defmgmt)
814 goto error;
815 err = cfg80211_validate_key_settings(rdev, &parse.p,
Johannes Berge31b8212010-10-05 19:39:30 +0200816 parse.idx, false, NULL);
Johannes Bergfffd0932009-07-08 14:22:54 +0200817 if (err)
818 goto error;
819 result->params[parse.idx].cipher = parse.p.cipher;
820 result->params[parse.idx].key_len = parse.p.key_len;
821 result->params[parse.idx].key = result->data[parse.idx];
822 memcpy(result->data[parse.idx], parse.p.key, parse.p.key_len);
Sujith Manoharande7044e2012-10-18 10:19:28 +0530823
824 if (parse.p.cipher == WLAN_CIPHER_SUITE_WEP40 ||
825 parse.p.cipher == WLAN_CIPHER_SUITE_WEP104) {
826 if (no_ht)
827 *no_ht = true;
828 }
Johannes Bergfffd0932009-07-08 14:22:54 +0200829 }
830
831 return result;
832 error:
833 kfree(result);
834 return ERR_PTR(err);
835}
836
837static int nl80211_key_allowed(struct wireless_dev *wdev)
838{
839 ASSERT_WDEV_LOCK(wdev);
840
Johannes Bergfffd0932009-07-08 14:22:54 +0200841 switch (wdev->iftype) {
842 case NL80211_IFTYPE_AP:
843 case NL80211_IFTYPE_AP_VLAN:
Johannes Berg074ac8d2010-09-16 14:58:22 +0200844 case NL80211_IFTYPE_P2P_GO:
Thomas Pedersenff973af2011-05-03 16:57:12 -0700845 case NL80211_IFTYPE_MESH_POINT:
Johannes Bergfffd0932009-07-08 14:22:54 +0200846 break;
847 case NL80211_IFTYPE_ADHOC:
Johannes Bergfffd0932009-07-08 14:22:54 +0200848 case NL80211_IFTYPE_STATION:
Johannes Berg074ac8d2010-09-16 14:58:22 +0200849 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Bergceca7b72013-05-16 00:55:45 +0200850 if (!wdev->current_bss)
Johannes Bergfffd0932009-07-08 14:22:54 +0200851 return -ENOLINK;
852 break;
853 default:
854 return -EINVAL;
855 }
856
857 return 0;
858}
859
Jouni Malinen664834d2014-01-15 00:01:44 +0200860static struct ieee80211_channel *nl80211_get_valid_chan(struct wiphy *wiphy,
861 struct nlattr *tb)
862{
863 struct ieee80211_channel *chan;
864
865 if (tb == NULL)
866 return NULL;
867 chan = ieee80211_get_channel(wiphy, nla_get_u32(tb));
868 if (!chan || chan->flags & IEEE80211_CHAN_DISABLED)
869 return NULL;
870 return chan;
871}
872
Johannes Berg7527a782011-05-13 10:58:57 +0200873static int nl80211_put_iftypes(struct sk_buff *msg, u32 attr, u16 ifmodes)
874{
875 struct nlattr *nl_modes = nla_nest_start(msg, attr);
876 int i;
877
878 if (!nl_modes)
879 goto nla_put_failure;
880
881 i = 0;
882 while (ifmodes) {
David S. Miller9360ffd2012-03-29 04:41:26 -0400883 if ((ifmodes & 1) && nla_put_flag(msg, i))
884 goto nla_put_failure;
Johannes Berg7527a782011-05-13 10:58:57 +0200885 ifmodes >>= 1;
886 i++;
887 }
888
889 nla_nest_end(msg, nl_modes);
890 return 0;
891
892nla_put_failure:
893 return -ENOBUFS;
894}
895
896static int nl80211_put_iface_combinations(struct wiphy *wiphy,
Johannes Bergcdc89b92013-02-18 23:54:36 +0100897 struct sk_buff *msg,
898 bool large)
Johannes Berg7527a782011-05-13 10:58:57 +0200899{
900 struct nlattr *nl_combis;
901 int i, j;
902
903 nl_combis = nla_nest_start(msg,
904 NL80211_ATTR_INTERFACE_COMBINATIONS);
905 if (!nl_combis)
906 goto nla_put_failure;
907
908 for (i = 0; i < wiphy->n_iface_combinations; i++) {
909 const struct ieee80211_iface_combination *c;
910 struct nlattr *nl_combi, *nl_limits;
911
912 c = &wiphy->iface_combinations[i];
913
914 nl_combi = nla_nest_start(msg, i + 1);
915 if (!nl_combi)
916 goto nla_put_failure;
917
918 nl_limits = nla_nest_start(msg, NL80211_IFACE_COMB_LIMITS);
919 if (!nl_limits)
920 goto nla_put_failure;
921
922 for (j = 0; j < c->n_limits; j++) {
923 struct nlattr *nl_limit;
924
925 nl_limit = nla_nest_start(msg, j + 1);
926 if (!nl_limit)
927 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -0400928 if (nla_put_u32(msg, NL80211_IFACE_LIMIT_MAX,
929 c->limits[j].max))
930 goto nla_put_failure;
Johannes Berg7527a782011-05-13 10:58:57 +0200931 if (nl80211_put_iftypes(msg, NL80211_IFACE_LIMIT_TYPES,
932 c->limits[j].types))
933 goto nla_put_failure;
934 nla_nest_end(msg, nl_limit);
935 }
936
937 nla_nest_end(msg, nl_limits);
938
David S. Miller9360ffd2012-03-29 04:41:26 -0400939 if (c->beacon_int_infra_match &&
940 nla_put_flag(msg, NL80211_IFACE_COMB_STA_AP_BI_MATCH))
941 goto nla_put_failure;
942 if (nla_put_u32(msg, NL80211_IFACE_COMB_NUM_CHANNELS,
943 c->num_different_channels) ||
944 nla_put_u32(msg, NL80211_IFACE_COMB_MAXNUM,
945 c->max_interfaces))
946 goto nla_put_failure;
Johannes Bergcdc89b92013-02-18 23:54:36 +0100947 if (large &&
948 nla_put_u32(msg, NL80211_IFACE_COMB_RADAR_DETECT_WIDTHS,
949 c->radar_detect_widths))
950 goto nla_put_failure;
Johannes Berg7527a782011-05-13 10:58:57 +0200951
952 nla_nest_end(msg, nl_combi);
953 }
954
955 nla_nest_end(msg, nl_combis);
956
957 return 0;
958nla_put_failure:
959 return -ENOBUFS;
960}
961
Johannes Berg3713b4e2013-02-14 16:19:38 +0100962#ifdef CONFIG_PM
Johannes Bergb56cf722013-02-20 01:02:38 +0100963static int nl80211_send_wowlan_tcp_caps(struct cfg80211_registered_device *rdev,
964 struct sk_buff *msg)
965{
Johannes Berg964dc9e2013-06-03 17:25:34 +0200966 const struct wiphy_wowlan_tcp_support *tcp = rdev->wiphy.wowlan->tcp;
Johannes Bergb56cf722013-02-20 01:02:38 +0100967 struct nlattr *nl_tcp;
968
969 if (!tcp)
970 return 0;
971
972 nl_tcp = nla_nest_start(msg, NL80211_WOWLAN_TRIG_TCP_CONNECTION);
973 if (!nl_tcp)
974 return -ENOBUFS;
975
976 if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD,
977 tcp->data_payload_max))
978 return -ENOBUFS;
979
980 if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD,
981 tcp->data_payload_max))
982 return -ENOBUFS;
983
984 if (tcp->seq && nla_put_flag(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ))
985 return -ENOBUFS;
986
987 if (tcp->tok && nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN,
988 sizeof(*tcp->tok), tcp->tok))
989 return -ENOBUFS;
990
991 if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_INTERVAL,
992 tcp->data_interval_max))
993 return -ENOBUFS;
994
995 if (nla_put_u32(msg, NL80211_WOWLAN_TCP_WAKE_PAYLOAD,
996 tcp->wake_payload_max))
997 return -ENOBUFS;
998
999 nla_nest_end(msg, nl_tcp);
1000 return 0;
1001}
1002
Johannes Berg3713b4e2013-02-14 16:19:38 +01001003static int nl80211_send_wowlan(struct sk_buff *msg,
Johannes Bergb56cf722013-02-20 01:02:38 +01001004 struct cfg80211_registered_device *dev,
1005 bool large)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001006{
1007 struct nlattr *nl_wowlan;
1008
Johannes Berg964dc9e2013-06-03 17:25:34 +02001009 if (!dev->wiphy.wowlan)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001010 return 0;
1011
1012 nl_wowlan = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS_SUPPORTED);
1013 if (!nl_wowlan)
1014 return -ENOBUFS;
1015
Johannes Berg964dc9e2013-06-03 17:25:34 +02001016 if (((dev->wiphy.wowlan->flags & WIPHY_WOWLAN_ANY) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001017 nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) ||
Johannes Berg964dc9e2013-06-03 17:25:34 +02001018 ((dev->wiphy.wowlan->flags & WIPHY_WOWLAN_DISCONNECT) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001019 nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) ||
Johannes Berg964dc9e2013-06-03 17:25:34 +02001020 ((dev->wiphy.wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001021 nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) ||
Johannes Berg964dc9e2013-06-03 17:25:34 +02001022 ((dev->wiphy.wowlan->flags & WIPHY_WOWLAN_SUPPORTS_GTK_REKEY) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001023 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED)) ||
Johannes Berg964dc9e2013-06-03 17:25:34 +02001024 ((dev->wiphy.wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001025 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) ||
Johannes Berg964dc9e2013-06-03 17:25:34 +02001026 ((dev->wiphy.wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001027 nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) ||
Johannes Berg964dc9e2013-06-03 17:25:34 +02001028 ((dev->wiphy.wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001029 nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) ||
Johannes Berg964dc9e2013-06-03 17:25:34 +02001030 ((dev->wiphy.wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001031 nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE)))
1032 return -ENOBUFS;
1033
Johannes Berg964dc9e2013-06-03 17:25:34 +02001034 if (dev->wiphy.wowlan->n_patterns) {
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07001035 struct nl80211_pattern_support pat = {
Johannes Berg964dc9e2013-06-03 17:25:34 +02001036 .max_patterns = dev->wiphy.wowlan->n_patterns,
1037 .min_pattern_len = dev->wiphy.wowlan->pattern_min_len,
1038 .max_pattern_len = dev->wiphy.wowlan->pattern_max_len,
1039 .max_pkt_offset = dev->wiphy.wowlan->max_pkt_offset,
Johannes Berg3713b4e2013-02-14 16:19:38 +01001040 };
1041
1042 if (nla_put(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN,
1043 sizeof(pat), &pat))
1044 return -ENOBUFS;
1045 }
1046
Johannes Bergb56cf722013-02-20 01:02:38 +01001047 if (large && nl80211_send_wowlan_tcp_caps(dev, msg))
1048 return -ENOBUFS;
1049
Johannes Berg3713b4e2013-02-14 16:19:38 +01001050 nla_nest_end(msg, nl_wowlan);
1051
1052 return 0;
1053}
1054#endif
1055
Amitkumar Karwarbe29b992013-06-28 11:51:26 -07001056static int nl80211_send_coalesce(struct sk_buff *msg,
1057 struct cfg80211_registered_device *dev)
1058{
1059 struct nl80211_coalesce_rule_support rule;
1060
1061 if (!dev->wiphy.coalesce)
1062 return 0;
1063
1064 rule.max_rules = dev->wiphy.coalesce->n_rules;
1065 rule.max_delay = dev->wiphy.coalesce->max_delay;
1066 rule.pat.max_patterns = dev->wiphy.coalesce->n_patterns;
1067 rule.pat.min_pattern_len = dev->wiphy.coalesce->pattern_min_len;
1068 rule.pat.max_pattern_len = dev->wiphy.coalesce->pattern_max_len;
1069 rule.pat.max_pkt_offset = dev->wiphy.coalesce->max_pkt_offset;
1070
1071 if (nla_put(msg, NL80211_ATTR_COALESCE_RULE, sizeof(rule), &rule))
1072 return -ENOBUFS;
1073
1074 return 0;
1075}
1076
Johannes Berg3713b4e2013-02-14 16:19:38 +01001077static int nl80211_send_band_rateinfo(struct sk_buff *msg,
1078 struct ieee80211_supported_band *sband)
1079{
1080 struct nlattr *nl_rates, *nl_rate;
1081 struct ieee80211_rate *rate;
1082 int i;
1083
1084 /* add HT info */
1085 if (sband->ht_cap.ht_supported &&
1086 (nla_put(msg, NL80211_BAND_ATTR_HT_MCS_SET,
1087 sizeof(sband->ht_cap.mcs),
1088 &sband->ht_cap.mcs) ||
1089 nla_put_u16(msg, NL80211_BAND_ATTR_HT_CAPA,
1090 sband->ht_cap.cap) ||
1091 nla_put_u8(msg, NL80211_BAND_ATTR_HT_AMPDU_FACTOR,
1092 sband->ht_cap.ampdu_factor) ||
1093 nla_put_u8(msg, NL80211_BAND_ATTR_HT_AMPDU_DENSITY,
1094 sband->ht_cap.ampdu_density)))
1095 return -ENOBUFS;
1096
1097 /* add VHT info */
1098 if (sband->vht_cap.vht_supported &&
1099 (nla_put(msg, NL80211_BAND_ATTR_VHT_MCS_SET,
1100 sizeof(sband->vht_cap.vht_mcs),
1101 &sband->vht_cap.vht_mcs) ||
1102 nla_put_u32(msg, NL80211_BAND_ATTR_VHT_CAPA,
1103 sband->vht_cap.cap)))
1104 return -ENOBUFS;
1105
1106 /* add bitrates */
1107 nl_rates = nla_nest_start(msg, NL80211_BAND_ATTR_RATES);
1108 if (!nl_rates)
1109 return -ENOBUFS;
1110
1111 for (i = 0; i < sband->n_bitrates; i++) {
1112 nl_rate = nla_nest_start(msg, i);
1113 if (!nl_rate)
1114 return -ENOBUFS;
1115
1116 rate = &sband->bitrates[i];
1117 if (nla_put_u32(msg, NL80211_BITRATE_ATTR_RATE,
1118 rate->bitrate))
1119 return -ENOBUFS;
1120 if ((rate->flags & IEEE80211_RATE_SHORT_PREAMBLE) &&
1121 nla_put_flag(msg,
1122 NL80211_BITRATE_ATTR_2GHZ_SHORTPREAMBLE))
1123 return -ENOBUFS;
1124
1125 nla_nest_end(msg, nl_rate);
1126 }
1127
1128 nla_nest_end(msg, nl_rates);
1129
1130 return 0;
1131}
1132
1133static int
1134nl80211_send_mgmt_stypes(struct sk_buff *msg,
1135 const struct ieee80211_txrx_stypes *mgmt_stypes)
1136{
1137 u16 stypes;
1138 struct nlattr *nl_ftypes, *nl_ifs;
1139 enum nl80211_iftype ift;
1140 int i;
1141
1142 if (!mgmt_stypes)
1143 return 0;
1144
1145 nl_ifs = nla_nest_start(msg, NL80211_ATTR_TX_FRAME_TYPES);
1146 if (!nl_ifs)
1147 return -ENOBUFS;
1148
1149 for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) {
1150 nl_ftypes = nla_nest_start(msg, ift);
1151 if (!nl_ftypes)
1152 return -ENOBUFS;
1153 i = 0;
1154 stypes = mgmt_stypes[ift].tx;
1155 while (stypes) {
1156 if ((stypes & 1) &&
1157 nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE,
1158 (i << 4) | IEEE80211_FTYPE_MGMT))
1159 return -ENOBUFS;
1160 stypes >>= 1;
1161 i++;
1162 }
1163 nla_nest_end(msg, nl_ftypes);
1164 }
1165
1166 nla_nest_end(msg, nl_ifs);
1167
1168 nl_ifs = nla_nest_start(msg, NL80211_ATTR_RX_FRAME_TYPES);
1169 if (!nl_ifs)
1170 return -ENOBUFS;
1171
1172 for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) {
1173 nl_ftypes = nla_nest_start(msg, ift);
1174 if (!nl_ftypes)
1175 return -ENOBUFS;
1176 i = 0;
1177 stypes = mgmt_stypes[ift].rx;
1178 while (stypes) {
1179 if ((stypes & 1) &&
1180 nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE,
1181 (i << 4) | IEEE80211_FTYPE_MGMT))
1182 return -ENOBUFS;
1183 stypes >>= 1;
1184 i++;
1185 }
1186 nla_nest_end(msg, nl_ftypes);
1187 }
1188 nla_nest_end(msg, nl_ifs);
1189
1190 return 0;
1191}
1192
Johannes Berg86e8cf92013-06-19 10:57:22 +02001193struct nl80211_dump_wiphy_state {
1194 s64 filter_wiphy;
1195 long start;
1196 long split_start, band_start, chan_start;
1197 bool split;
1198};
1199
Johannes Berg3713b4e2013-02-14 16:19:38 +01001200static int nl80211_send_wiphy(struct cfg80211_registered_device *dev,
1201 struct sk_buff *msg, u32 portid, u32 seq,
Johannes Berg86e8cf92013-06-19 10:57:22 +02001202 int flags, struct nl80211_dump_wiphy_state *state)
Johannes Berg55682962007-09-20 13:09:35 -04001203{
1204 void *hdr;
Johannes Bergee688b002008-01-24 19:38:39 +01001205 struct nlattr *nl_bands, *nl_band;
1206 struct nlattr *nl_freqs, *nl_freq;
Johannes Berg8fdc6212009-03-14 09:34:01 +01001207 struct nlattr *nl_cmds;
Johannes Bergee688b002008-01-24 19:38:39 +01001208 enum ieee80211_band band;
1209 struct ieee80211_channel *chan;
Johannes Bergee688b002008-01-24 19:38:39 +01001210 int i;
Johannes Berg2e161f72010-08-12 15:38:38 +02001211 const struct ieee80211_txrx_stypes *mgmt_stypes =
1212 dev->wiphy.mgmt_stypes;
Johannes Bergfe1abaf2013-02-27 15:39:45 +01001213 u32 features;
Johannes Berg55682962007-09-20 13:09:35 -04001214
Eric W. Biederman15e47302012-09-07 20:12:54 +00001215 hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_WIPHY);
Johannes Berg55682962007-09-20 13:09:35 -04001216 if (!hdr)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001217 return -ENOBUFS;
1218
Johannes Berg86e8cf92013-06-19 10:57:22 +02001219 if (WARN_ON(!state))
1220 return -EINVAL;
Johannes Berg55682962007-09-20 13:09:35 -04001221
David S. Miller9360ffd2012-03-29 04:41:26 -04001222 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, dev->wiphy_idx) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001223 nla_put_string(msg, NL80211_ATTR_WIPHY_NAME,
1224 wiphy_name(&dev->wiphy)) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04001225 nla_put_u32(msg, NL80211_ATTR_GENERATION,
Johannes Berg3713b4e2013-02-14 16:19:38 +01001226 cfg80211_rdev_list_generation))
David S. Miller9360ffd2012-03-29 04:41:26 -04001227 goto nla_put_failure;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02001228
Johannes Berg86e8cf92013-06-19 10:57:22 +02001229 switch (state->split_start) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001230 case 0:
1231 if (nla_put_u8(msg, NL80211_ATTR_WIPHY_RETRY_SHORT,
1232 dev->wiphy.retry_short) ||
1233 nla_put_u8(msg, NL80211_ATTR_WIPHY_RETRY_LONG,
1234 dev->wiphy.retry_long) ||
1235 nla_put_u32(msg, NL80211_ATTR_WIPHY_FRAG_THRESHOLD,
1236 dev->wiphy.frag_threshold) ||
1237 nla_put_u32(msg, NL80211_ATTR_WIPHY_RTS_THRESHOLD,
1238 dev->wiphy.rts_threshold) ||
1239 nla_put_u8(msg, NL80211_ATTR_WIPHY_COVERAGE_CLASS,
1240 dev->wiphy.coverage_class) ||
1241 nla_put_u8(msg, NL80211_ATTR_MAX_NUM_SCAN_SSIDS,
1242 dev->wiphy.max_scan_ssids) ||
1243 nla_put_u8(msg, NL80211_ATTR_MAX_NUM_SCHED_SCAN_SSIDS,
1244 dev->wiphy.max_sched_scan_ssids) ||
1245 nla_put_u16(msg, NL80211_ATTR_MAX_SCAN_IE_LEN,
1246 dev->wiphy.max_scan_ie_len) ||
1247 nla_put_u16(msg, NL80211_ATTR_MAX_SCHED_SCAN_IE_LEN,
1248 dev->wiphy.max_sched_scan_ie_len) ||
1249 nla_put_u8(msg, NL80211_ATTR_MAX_MATCH_SETS,
1250 dev->wiphy.max_match_sets))
Johannes Bergee688b002008-01-24 19:38:39 +01001251 goto nla_put_failure;
1252
Johannes Berg3713b4e2013-02-14 16:19:38 +01001253 if ((dev->wiphy.flags & WIPHY_FLAG_IBSS_RSN) &&
1254 nla_put_flag(msg, NL80211_ATTR_SUPPORT_IBSS_RSN))
1255 goto nla_put_failure;
1256 if ((dev->wiphy.flags & WIPHY_FLAG_MESH_AUTH) &&
1257 nla_put_flag(msg, NL80211_ATTR_SUPPORT_MESH_AUTH))
1258 goto nla_put_failure;
1259 if ((dev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) &&
1260 nla_put_flag(msg, NL80211_ATTR_SUPPORT_AP_UAPSD))
1261 goto nla_put_failure;
1262 if ((dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_FW_ROAM) &&
1263 nla_put_flag(msg, NL80211_ATTR_ROAM_SUPPORT))
1264 goto nla_put_failure;
1265 if ((dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) &&
1266 nla_put_flag(msg, NL80211_ATTR_TDLS_SUPPORT))
1267 goto nla_put_failure;
1268 if ((dev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP) &&
1269 nla_put_flag(msg, NL80211_ATTR_TDLS_EXTERNAL_SETUP))
David S. Miller9360ffd2012-03-29 04:41:26 -04001270 goto nla_put_failure;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001271 state->split_start++;
1272 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001273 break;
1274 case 1:
1275 if (nla_put(msg, NL80211_ATTR_CIPHER_SUITES,
1276 sizeof(u32) * dev->wiphy.n_cipher_suites,
1277 dev->wiphy.cipher_suites))
Mahesh Palivelabf0c111e2012-06-22 07:27:46 +00001278 goto nla_put_failure;
1279
Johannes Berg3713b4e2013-02-14 16:19:38 +01001280 if (nla_put_u8(msg, NL80211_ATTR_MAX_NUM_PMKIDS,
1281 dev->wiphy.max_num_pmkids))
Johannes Bergee688b002008-01-24 19:38:39 +01001282 goto nla_put_failure;
1283
Johannes Berg3713b4e2013-02-14 16:19:38 +01001284 if ((dev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) &&
1285 nla_put_flag(msg, NL80211_ATTR_CONTROL_PORT_ETHERTYPE))
1286 goto nla_put_failure;
Johannes Bergee688b002008-01-24 19:38:39 +01001287
Johannes Berg3713b4e2013-02-14 16:19:38 +01001288 if (nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_TX,
1289 dev->wiphy.available_antennas_tx) ||
1290 nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_RX,
1291 dev->wiphy.available_antennas_rx))
1292 goto nla_put_failure;
Johannes Bergee688b002008-01-24 19:38:39 +01001293
Johannes Berg3713b4e2013-02-14 16:19:38 +01001294 if ((dev->wiphy.flags & WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD) &&
1295 nla_put_u32(msg, NL80211_ATTR_PROBE_RESP_OFFLOAD,
1296 dev->wiphy.probe_resp_offload))
1297 goto nla_put_failure;
Jouni Malinene2f367f262008-11-21 19:01:30 +02001298
Johannes Berg3713b4e2013-02-14 16:19:38 +01001299 if ((dev->wiphy.available_antennas_tx ||
1300 dev->wiphy.available_antennas_rx) &&
1301 dev->ops->get_antenna) {
1302 u32 tx_ant = 0, rx_ant = 0;
1303 int res;
1304 res = rdev_get_antenna(dev, &tx_ant, &rx_ant);
1305 if (!res) {
1306 if (nla_put_u32(msg,
1307 NL80211_ATTR_WIPHY_ANTENNA_TX,
1308 tx_ant) ||
1309 nla_put_u32(msg,
1310 NL80211_ATTR_WIPHY_ANTENNA_RX,
1311 rx_ant))
1312 goto nla_put_failure;
1313 }
Johannes Bergee688b002008-01-24 19:38:39 +01001314 }
1315
Johannes Berg86e8cf92013-06-19 10:57:22 +02001316 state->split_start++;
1317 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001318 break;
1319 case 2:
1320 if (nl80211_put_iftypes(msg, NL80211_ATTR_SUPPORTED_IFTYPES,
1321 dev->wiphy.interface_modes))
1322 goto nla_put_failure;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001323 state->split_start++;
1324 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001325 break;
1326 case 3:
1327 nl_bands = nla_nest_start(msg, NL80211_ATTR_WIPHY_BANDS);
1328 if (!nl_bands)
Johannes Bergee688b002008-01-24 19:38:39 +01001329 goto nla_put_failure;
1330
Johannes Berg86e8cf92013-06-19 10:57:22 +02001331 for (band = state->band_start;
1332 band < IEEE80211_NUM_BANDS; band++) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001333 struct ieee80211_supported_band *sband;
1334
1335 sband = dev->wiphy.bands[band];
1336
1337 if (!sband)
1338 continue;
1339
1340 nl_band = nla_nest_start(msg, band);
1341 if (!nl_band)
Johannes Bergee688b002008-01-24 19:38:39 +01001342 goto nla_put_failure;
1343
Johannes Berg86e8cf92013-06-19 10:57:22 +02001344 switch (state->chan_start) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001345 case 0:
1346 if (nl80211_send_band_rateinfo(msg, sband))
1347 goto nla_put_failure;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001348 state->chan_start++;
1349 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001350 break;
1351 default:
1352 /* add frequencies */
1353 nl_freqs = nla_nest_start(
1354 msg, NL80211_BAND_ATTR_FREQS);
1355 if (!nl_freqs)
1356 goto nla_put_failure;
Johannes Bergee688b002008-01-24 19:38:39 +01001357
Johannes Berg86e8cf92013-06-19 10:57:22 +02001358 for (i = state->chan_start - 1;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001359 i < sband->n_channels;
1360 i++) {
1361 nl_freq = nla_nest_start(msg, i);
1362 if (!nl_freq)
1363 goto nla_put_failure;
1364
1365 chan = &sband->channels[i];
1366
Johannes Berg86e8cf92013-06-19 10:57:22 +02001367 if (nl80211_msg_put_channel(
1368 msg, chan,
1369 state->split))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001370 goto nla_put_failure;
1371
1372 nla_nest_end(msg, nl_freq);
Johannes Berg86e8cf92013-06-19 10:57:22 +02001373 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001374 break;
1375 }
1376 if (i < sband->n_channels)
Johannes Berg86e8cf92013-06-19 10:57:22 +02001377 state->chan_start = i + 2;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001378 else
Johannes Berg86e8cf92013-06-19 10:57:22 +02001379 state->chan_start = 0;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001380 nla_nest_end(msg, nl_freqs);
1381 }
1382
1383 nla_nest_end(msg, nl_band);
1384
Johannes Berg86e8cf92013-06-19 10:57:22 +02001385 if (state->split) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001386 /* start again here */
Johannes Berg86e8cf92013-06-19 10:57:22 +02001387 if (state->chan_start)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001388 band--;
1389 break;
1390 }
Johannes Bergee688b002008-01-24 19:38:39 +01001391 }
Johannes Berg3713b4e2013-02-14 16:19:38 +01001392 nla_nest_end(msg, nl_bands);
Johannes Bergee688b002008-01-24 19:38:39 +01001393
Johannes Berg3713b4e2013-02-14 16:19:38 +01001394 if (band < IEEE80211_NUM_BANDS)
Johannes Berg86e8cf92013-06-19 10:57:22 +02001395 state->band_start = band + 1;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001396 else
Johannes Berg86e8cf92013-06-19 10:57:22 +02001397 state->band_start = 0;
Johannes Bergee688b002008-01-24 19:38:39 +01001398
Johannes Berg3713b4e2013-02-14 16:19:38 +01001399 /* if bands & channels are done, continue outside */
Johannes Berg86e8cf92013-06-19 10:57:22 +02001400 if (state->band_start == 0 && state->chan_start == 0)
1401 state->split_start++;
1402 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001403 break;
1404 case 4:
1405 nl_cmds = nla_nest_start(msg, NL80211_ATTR_SUPPORTED_COMMANDS);
1406 if (!nl_cmds)
David S. Miller9360ffd2012-03-29 04:41:26 -04001407 goto nla_put_failure;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001408
1409 i = 0;
1410#define CMD(op, n) \
1411 do { \
1412 if (dev->ops->op) { \
1413 i++; \
1414 if (nla_put_u32(msg, i, NL80211_CMD_ ## n)) \
1415 goto nla_put_failure; \
1416 } \
1417 } while (0)
1418
1419 CMD(add_virtual_intf, NEW_INTERFACE);
1420 CMD(change_virtual_intf, SET_INTERFACE);
1421 CMD(add_key, NEW_KEY);
1422 CMD(start_ap, START_AP);
1423 CMD(add_station, NEW_STATION);
1424 CMD(add_mpath, NEW_MPATH);
1425 CMD(update_mesh_config, SET_MESH_CONFIG);
1426 CMD(change_bss, SET_BSS);
1427 CMD(auth, AUTHENTICATE);
1428 CMD(assoc, ASSOCIATE);
1429 CMD(deauth, DEAUTHENTICATE);
1430 CMD(disassoc, DISASSOCIATE);
1431 CMD(join_ibss, JOIN_IBSS);
1432 CMD(join_mesh, JOIN_MESH);
1433 CMD(set_pmksa, SET_PMKSA);
1434 CMD(del_pmksa, DEL_PMKSA);
1435 CMD(flush_pmksa, FLUSH_PMKSA);
1436 if (dev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL)
1437 CMD(remain_on_channel, REMAIN_ON_CHANNEL);
1438 CMD(set_bitrate_mask, SET_TX_BITRATE_MASK);
1439 CMD(mgmt_tx, FRAME);
1440 CMD(mgmt_tx_cancel_wait, FRAME_WAIT_CANCEL);
1441 if (dev->wiphy.flags & WIPHY_FLAG_NETNS_OK) {
1442 i++;
1443 if (nla_put_u32(msg, i, NL80211_CMD_SET_WIPHY_NETNS))
1444 goto nla_put_failure;
1445 }
1446 if (dev->ops->set_monitor_channel || dev->ops->start_ap ||
1447 dev->ops->join_mesh) {
1448 i++;
1449 if (nla_put_u32(msg, i, NL80211_CMD_SET_CHANNEL))
1450 goto nla_put_failure;
1451 }
1452 CMD(set_wds_peer, SET_WDS_PEER);
1453 if (dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) {
1454 CMD(tdls_mgmt, TDLS_MGMT);
1455 CMD(tdls_oper, TDLS_OPER);
1456 }
1457 if (dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN)
1458 CMD(sched_scan_start, START_SCHED_SCAN);
1459 CMD(probe_client, PROBE_CLIENT);
1460 CMD(set_noack_map, SET_NOACK_MAP);
1461 if (dev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS) {
1462 i++;
1463 if (nla_put_u32(msg, i, NL80211_CMD_REGISTER_BEACONS))
1464 goto nla_put_failure;
1465 }
1466 CMD(start_p2p_device, START_P2P_DEVICE);
1467 CMD(set_mcast_rate, SET_MCAST_RATE);
Johannes Berg86e8cf92013-06-19 10:57:22 +02001468 if (state->split) {
Arend van Spriel5de17982013-04-18 15:49:00 +02001469 CMD(crit_proto_start, CRIT_PROTOCOL_START);
1470 CMD(crit_proto_stop, CRIT_PROTOCOL_STOP);
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02001471 if (dev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH)
1472 CMD(channel_switch, CHANNEL_SWITCH);
Arend van Spriel5de17982013-04-18 15:49:00 +02001473 }
Kyeyoon Parkfa9ffc72013-12-16 23:01:30 -08001474 CMD(set_qos_map, SET_QOS_MAP);
Johannes Berg8fdc6212009-03-14 09:34:01 +01001475
Kalle Valo4745fc02011-11-17 19:06:10 +02001476#ifdef CONFIG_NL80211_TESTMODE
Johannes Berg3713b4e2013-02-14 16:19:38 +01001477 CMD(testmode_cmd, TESTMODE);
Kalle Valo4745fc02011-11-17 19:06:10 +02001478#endif
1479
Johannes Berg8fdc6212009-03-14 09:34:01 +01001480#undef CMD
Samuel Ortizb23aa672009-07-01 21:26:54 +02001481
Johannes Berg3713b4e2013-02-14 16:19:38 +01001482 if (dev->ops->connect || dev->ops->auth) {
1483 i++;
1484 if (nla_put_u32(msg, i, NL80211_CMD_CONNECT))
Johannes Berg2e161f72010-08-12 15:38:38 +02001485 goto nla_put_failure;
Johannes Berg2e161f72010-08-12 15:38:38 +02001486 }
1487
Johannes Berg3713b4e2013-02-14 16:19:38 +01001488 if (dev->ops->disconnect || dev->ops->deauth) {
1489 i++;
1490 if (nla_put_u32(msg, i, NL80211_CMD_DISCONNECT))
1491 goto nla_put_failure;
1492 }
Johannes Berg74b70a42010-08-24 12:15:53 +02001493
Johannes Berg3713b4e2013-02-14 16:19:38 +01001494 nla_nest_end(msg, nl_cmds);
Johannes Berg86e8cf92013-06-19 10:57:22 +02001495 state->split_start++;
1496 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001497 break;
1498 case 5:
1499 if (dev->ops->remain_on_channel &&
1500 (dev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL) &&
1501 nla_put_u32(msg,
1502 NL80211_ATTR_MAX_REMAIN_ON_CHANNEL_DURATION,
1503 dev->wiphy.max_remain_on_channel_duration))
Johannes Berg2e161f72010-08-12 15:38:38 +02001504 goto nla_put_failure;
1505
Johannes Berg3713b4e2013-02-14 16:19:38 +01001506 if ((dev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX) &&
1507 nla_put_flag(msg, NL80211_ATTR_OFFCHANNEL_TX_OK))
1508 goto nla_put_failure;
Johannes Berg2e161f72010-08-12 15:38:38 +02001509
Johannes Berg3713b4e2013-02-14 16:19:38 +01001510 if (nl80211_send_mgmt_stypes(msg, mgmt_stypes))
1511 goto nla_put_failure;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001512 state->split_start++;
1513 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001514 break;
1515 case 6:
Johannes Bergdfb89c52012-06-27 09:23:48 +02001516#ifdef CONFIG_PM
Johannes Berg86e8cf92013-06-19 10:57:22 +02001517 if (nl80211_send_wowlan(msg, dev, state->split))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001518 goto nla_put_failure;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001519 state->split_start++;
1520 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001521 break;
1522#else
Johannes Berg86e8cf92013-06-19 10:57:22 +02001523 state->split_start++;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001524#endif
1525 case 7:
1526 if (nl80211_put_iftypes(msg, NL80211_ATTR_SOFTWARE_IFTYPES,
1527 dev->wiphy.software_iftypes))
Johannes Bergff1b6e62011-05-04 15:37:28 +02001528 goto nla_put_failure;
1529
Johannes Berg86e8cf92013-06-19 10:57:22 +02001530 if (nl80211_put_iface_combinations(&dev->wiphy, msg,
1531 state->split))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001532 goto nla_put_failure;
Johannes Bergff1b6e62011-05-04 15:37:28 +02001533
Johannes Berg86e8cf92013-06-19 10:57:22 +02001534 state->split_start++;
1535 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001536 break;
1537 case 8:
1538 if ((dev->wiphy.flags & WIPHY_FLAG_HAVE_AP_SME) &&
1539 nla_put_u32(msg, NL80211_ATTR_DEVICE_AP_SME,
1540 dev->wiphy.ap_sme_capa))
1541 goto nla_put_failure;
1542
Johannes Bergfe1abaf2013-02-27 15:39:45 +01001543 features = dev->wiphy.features;
1544 /*
1545 * We can only add the per-channel limit information if the
1546 * dump is split, otherwise it makes it too big. Therefore
1547 * only advertise it in that case.
1548 */
Johannes Berg86e8cf92013-06-19 10:57:22 +02001549 if (state->split)
Johannes Bergfe1abaf2013-02-27 15:39:45 +01001550 features |= NL80211_FEATURE_ADVERTISE_CHAN_LIMITS;
1551 if (nla_put_u32(msg, NL80211_ATTR_FEATURE_FLAGS, features))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001552 goto nla_put_failure;
1553
1554 if (dev->wiphy.ht_capa_mod_mask &&
1555 nla_put(msg, NL80211_ATTR_HT_CAPABILITY_MASK,
1556 sizeof(*dev->wiphy.ht_capa_mod_mask),
1557 dev->wiphy.ht_capa_mod_mask))
1558 goto nla_put_failure;
1559
1560 if (dev->wiphy.flags & WIPHY_FLAG_HAVE_AP_SME &&
1561 dev->wiphy.max_acl_mac_addrs &&
1562 nla_put_u32(msg, NL80211_ATTR_MAC_ACL_MAX,
1563 dev->wiphy.max_acl_mac_addrs))
1564 goto nla_put_failure;
1565
1566 /*
1567 * Any information below this point is only available to
1568 * applications that can deal with it being split. This
1569 * helps ensure that newly added capabilities don't break
1570 * older tools by overrunning their buffers.
1571 *
1572 * We still increment split_start so that in the split
1573 * case we'll continue with more data in the next round,
1574 * but break unconditionally so unsplit data stops here.
1575 */
Johannes Berg86e8cf92013-06-19 10:57:22 +02001576 state->split_start++;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001577 break;
1578 case 9:
Johannes Bergfe1abaf2013-02-27 15:39:45 +01001579 if (dev->wiphy.extended_capabilities &&
1580 (nla_put(msg, NL80211_ATTR_EXT_CAPA,
1581 dev->wiphy.extended_capabilities_len,
1582 dev->wiphy.extended_capabilities) ||
1583 nla_put(msg, NL80211_ATTR_EXT_CAPA_MASK,
1584 dev->wiphy.extended_capabilities_len,
1585 dev->wiphy.extended_capabilities_mask)))
1586 goto nla_put_failure;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001587
Johannes Bergee2aca32013-02-21 17:36:01 +01001588 if (dev->wiphy.vht_capa_mod_mask &&
1589 nla_put(msg, NL80211_ATTR_VHT_CAPABILITY_MASK,
1590 sizeof(*dev->wiphy.vht_capa_mod_mask),
1591 dev->wiphy.vht_capa_mod_mask))
1592 goto nla_put_failure;
1593
Amitkumar Karwarbe29b992013-06-28 11:51:26 -07001594 state->split_start++;
1595 break;
1596 case 10:
1597 if (nl80211_send_coalesce(msg, dev))
1598 goto nla_put_failure;
1599
Felix Fietkau01e0daa2013-11-09 14:57:54 +01001600 if ((dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_5_10_MHZ) &&
1601 (nla_put_flag(msg, NL80211_ATTR_SUPPORT_5_MHZ) ||
1602 nla_put_flag(msg, NL80211_ATTR_SUPPORT_10_MHZ)))
1603 goto nla_put_failure;
Jouni Malinenb43504c2014-01-15 00:01:08 +02001604
1605 if (dev->wiphy.max_ap_assoc_sta &&
1606 nla_put_u32(msg, NL80211_ATTR_MAX_AP_ASSOC_STA,
1607 dev->wiphy.max_ap_assoc_sta))
1608 goto nla_put_failure;
1609
Johannes Bergad7e7182013-11-13 13:37:47 +01001610 state->split_start++;
1611 break;
1612 case 11:
Johannes Berg567ffc32013-12-18 14:43:31 +01001613 if (dev->wiphy.n_vendor_commands) {
1614 const struct nl80211_vendor_cmd_info *info;
1615 struct nlattr *nested;
Johannes Bergad7e7182013-11-13 13:37:47 +01001616
Johannes Berg567ffc32013-12-18 14:43:31 +01001617 nested = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA);
1618 if (!nested)
Johannes Bergad7e7182013-11-13 13:37:47 +01001619 goto nla_put_failure;
Johannes Berg567ffc32013-12-18 14:43:31 +01001620
1621 for (i = 0; i < dev->wiphy.n_vendor_commands; i++) {
1622 info = &dev->wiphy.vendor_commands[i].info;
1623 if (nla_put(msg, i + 1, sizeof(*info), info))
1624 goto nla_put_failure;
1625 }
1626 nla_nest_end(msg, nested);
1627 }
1628
1629 if (dev->wiphy.n_vendor_events) {
1630 const struct nl80211_vendor_cmd_info *info;
1631 struct nlattr *nested;
1632
1633 nested = nla_nest_start(msg,
1634 NL80211_ATTR_VENDOR_EVENTS);
1635 if (!nested)
1636 goto nla_put_failure;
1637
1638 for (i = 0; i < dev->wiphy.n_vendor_events; i++) {
1639 info = &dev->wiphy.vendor_events[i];
1640 if (nla_put(msg, i + 1, sizeof(*info), info))
1641 goto nla_put_failure;
1642 }
1643 nla_nest_end(msg, nested);
1644 }
Felix Fietkau01e0daa2013-11-09 14:57:54 +01001645
Johannes Berg3713b4e2013-02-14 16:19:38 +01001646 /* done */
Johannes Berg86e8cf92013-06-19 10:57:22 +02001647 state->split_start = 0;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001648 break;
Johannes Bergff1b6e62011-05-04 15:37:28 +02001649 }
Johannes Berg55682962007-09-20 13:09:35 -04001650 return genlmsg_end(msg, hdr);
1651
1652 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07001653 genlmsg_cancel(msg, hdr);
1654 return -EMSGSIZE;
Johannes Berg55682962007-09-20 13:09:35 -04001655}
1656
Johannes Berg86e8cf92013-06-19 10:57:22 +02001657static int nl80211_dump_wiphy_parse(struct sk_buff *skb,
1658 struct netlink_callback *cb,
1659 struct nl80211_dump_wiphy_state *state)
1660{
1661 struct nlattr **tb = nl80211_fam.attrbuf;
1662 int ret = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize,
1663 tb, nl80211_fam.maxattr, nl80211_policy);
1664 /* ignore parse errors for backward compatibility */
1665 if (ret)
1666 return 0;
1667
1668 state->split = tb[NL80211_ATTR_SPLIT_WIPHY_DUMP];
1669 if (tb[NL80211_ATTR_WIPHY])
1670 state->filter_wiphy = nla_get_u32(tb[NL80211_ATTR_WIPHY]);
1671 if (tb[NL80211_ATTR_WDEV])
1672 state->filter_wiphy = nla_get_u64(tb[NL80211_ATTR_WDEV]) >> 32;
1673 if (tb[NL80211_ATTR_IFINDEX]) {
1674 struct net_device *netdev;
1675 struct cfg80211_registered_device *rdev;
1676 int ifidx = nla_get_u32(tb[NL80211_ATTR_IFINDEX]);
1677
Ying Xue7f2b8562014-01-15 10:23:45 +08001678 netdev = __dev_get_by_index(sock_net(skb->sk), ifidx);
Johannes Berg86e8cf92013-06-19 10:57:22 +02001679 if (!netdev)
1680 return -ENODEV;
1681 if (netdev->ieee80211_ptr) {
1682 rdev = wiphy_to_dev(
1683 netdev->ieee80211_ptr->wiphy);
1684 state->filter_wiphy = rdev->wiphy_idx;
1685 }
Johannes Berg86e8cf92013-06-19 10:57:22 +02001686 }
1687
1688 return 0;
1689}
1690
Johannes Berg55682962007-09-20 13:09:35 -04001691static int nl80211_dump_wiphy(struct sk_buff *skb, struct netlink_callback *cb)
1692{
Johannes Berg645e77d2013-03-01 14:03:49 +01001693 int idx = 0, ret;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001694 struct nl80211_dump_wiphy_state *state = (void *)cb->args[0];
Johannes Berg55682962007-09-20 13:09:35 -04001695 struct cfg80211_registered_device *dev;
Johannes Berg3a5a4232013-06-19 10:09:57 +02001696
Johannes Berg5fe231e2013-05-08 21:45:15 +02001697 rtnl_lock();
Johannes Berg86e8cf92013-06-19 10:57:22 +02001698 if (!state) {
1699 state = kzalloc(sizeof(*state), GFP_KERNEL);
John W. Linville57ed5cd2013-06-28 13:18:21 -04001700 if (!state) {
1701 rtnl_unlock();
Johannes Berg86e8cf92013-06-19 10:57:22 +02001702 return -ENOMEM;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001703 }
Johannes Berg86e8cf92013-06-19 10:57:22 +02001704 state->filter_wiphy = -1;
1705 ret = nl80211_dump_wiphy_parse(skb, cb, state);
1706 if (ret) {
1707 kfree(state);
1708 rtnl_unlock();
1709 return ret;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001710 }
Johannes Berg86e8cf92013-06-19 10:57:22 +02001711 cb->args[0] = (long)state;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001712 }
1713
Johannes Berg79c97e92009-07-07 03:56:12 +02001714 list_for_each_entry(dev, &cfg80211_rdev_list, list) {
Johannes Berg463d0182009-07-14 00:33:35 +02001715 if (!net_eq(wiphy_net(&dev->wiphy), sock_net(skb->sk)))
1716 continue;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001717 if (++idx <= state->start)
Johannes Berg55682962007-09-20 13:09:35 -04001718 continue;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001719 if (state->filter_wiphy != -1 &&
1720 state->filter_wiphy != dev->wiphy_idx)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001721 continue;
1722 /* attempt to fit multiple wiphy data chunks into the skb */
1723 do {
1724 ret = nl80211_send_wiphy(dev, skb,
1725 NETLINK_CB(cb->skb).portid,
1726 cb->nlh->nlmsg_seq,
Johannes Berg86e8cf92013-06-19 10:57:22 +02001727 NLM_F_MULTI, state);
Johannes Berg3713b4e2013-02-14 16:19:38 +01001728 if (ret < 0) {
1729 /*
1730 * If sending the wiphy data didn't fit (ENOBUFS
1731 * or EMSGSIZE returned), this SKB is still
1732 * empty (so it's not too big because another
1733 * wiphy dataset is already in the skb) and
1734 * we've not tried to adjust the dump allocation
1735 * yet ... then adjust the alloc size to be
1736 * bigger, and return 1 but with the empty skb.
1737 * This results in an empty message being RX'ed
1738 * in userspace, but that is ignored.
1739 *
1740 * We can then retry with the larger buffer.
1741 */
1742 if ((ret == -ENOBUFS || ret == -EMSGSIZE) &&
1743 !skb->len &&
1744 cb->min_dump_alloc < 4096) {
1745 cb->min_dump_alloc = 4096;
David S. Millerd98cae64e2013-06-19 16:49:39 -07001746 rtnl_unlock();
Johannes Berg3713b4e2013-02-14 16:19:38 +01001747 return 1;
1748 }
1749 idx--;
1750 break;
Johannes Berg645e77d2013-03-01 14:03:49 +01001751 }
Johannes Berg86e8cf92013-06-19 10:57:22 +02001752 } while (state->split_start > 0);
Johannes Berg3713b4e2013-02-14 16:19:38 +01001753 break;
Johannes Berg55682962007-09-20 13:09:35 -04001754 }
Johannes Berg5fe231e2013-05-08 21:45:15 +02001755 rtnl_unlock();
Johannes Berg55682962007-09-20 13:09:35 -04001756
Johannes Berg86e8cf92013-06-19 10:57:22 +02001757 state->start = idx;
Johannes Berg55682962007-09-20 13:09:35 -04001758
1759 return skb->len;
1760}
1761
Johannes Berg86e8cf92013-06-19 10:57:22 +02001762static int nl80211_dump_wiphy_done(struct netlink_callback *cb)
1763{
1764 kfree((void *)cb->args[0]);
1765 return 0;
1766}
1767
Johannes Berg55682962007-09-20 13:09:35 -04001768static int nl80211_get_wiphy(struct sk_buff *skb, struct genl_info *info)
1769{
1770 struct sk_buff *msg;
Johannes Berg4c476992010-10-04 21:36:35 +02001771 struct cfg80211_registered_device *dev = info->user_ptr[0];
Johannes Berg86e8cf92013-06-19 10:57:22 +02001772 struct nl80211_dump_wiphy_state state = {};
Johannes Berg55682962007-09-20 13:09:35 -04001773
Johannes Berg645e77d2013-03-01 14:03:49 +01001774 msg = nlmsg_new(4096, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -04001775 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02001776 return -ENOMEM;
Johannes Berg55682962007-09-20 13:09:35 -04001777
Johannes Berg3713b4e2013-02-14 16:19:38 +01001778 if (nl80211_send_wiphy(dev, msg, info->snd_portid, info->snd_seq, 0,
Johannes Berg86e8cf92013-06-19 10:57:22 +02001779 &state) < 0) {
Johannes Berg4c476992010-10-04 21:36:35 +02001780 nlmsg_free(msg);
1781 return -ENOBUFS;
1782 }
Johannes Berg55682962007-09-20 13:09:35 -04001783
Johannes Berg134e6372009-07-10 09:51:34 +00001784 return genlmsg_reply(msg, info);
Johannes Berg55682962007-09-20 13:09:35 -04001785}
1786
Jouni Malinen31888482008-10-30 16:59:24 +02001787static const struct nla_policy txq_params_policy[NL80211_TXQ_ATTR_MAX + 1] = {
1788 [NL80211_TXQ_ATTR_QUEUE] = { .type = NLA_U8 },
1789 [NL80211_TXQ_ATTR_TXOP] = { .type = NLA_U16 },
1790 [NL80211_TXQ_ATTR_CWMIN] = { .type = NLA_U16 },
1791 [NL80211_TXQ_ATTR_CWMAX] = { .type = NLA_U16 },
1792 [NL80211_TXQ_ATTR_AIFS] = { .type = NLA_U8 },
1793};
1794
1795static int parse_txq_params(struct nlattr *tb[],
1796 struct ieee80211_txq_params *txq_params)
1797{
Johannes Berga3304b02012-03-28 11:04:24 +02001798 if (!tb[NL80211_TXQ_ATTR_AC] || !tb[NL80211_TXQ_ATTR_TXOP] ||
Jouni Malinen31888482008-10-30 16:59:24 +02001799 !tb[NL80211_TXQ_ATTR_CWMIN] || !tb[NL80211_TXQ_ATTR_CWMAX] ||
1800 !tb[NL80211_TXQ_ATTR_AIFS])
1801 return -EINVAL;
1802
Johannes Berga3304b02012-03-28 11:04:24 +02001803 txq_params->ac = nla_get_u8(tb[NL80211_TXQ_ATTR_AC]);
Jouni Malinen31888482008-10-30 16:59:24 +02001804 txq_params->txop = nla_get_u16(tb[NL80211_TXQ_ATTR_TXOP]);
1805 txq_params->cwmin = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMIN]);
1806 txq_params->cwmax = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMAX]);
1807 txq_params->aifs = nla_get_u8(tb[NL80211_TXQ_ATTR_AIFS]);
1808
Johannes Berga3304b02012-03-28 11:04:24 +02001809 if (txq_params->ac >= NL80211_NUM_ACS)
1810 return -EINVAL;
1811
Jouni Malinen31888482008-10-30 16:59:24 +02001812 return 0;
1813}
1814
Johannes Bergf444de02010-05-05 15:25:02 +02001815static bool nl80211_can_set_dev_channel(struct wireless_dev *wdev)
1816{
1817 /*
Johannes Bergcc1d2802012-05-16 23:50:20 +02001818 * You can only set the channel explicitly for WDS interfaces,
1819 * all others have their channel managed via their respective
1820 * "establish a connection" command (connect, join, ...)
1821 *
1822 * For AP/GO and mesh mode, the channel can be set with the
1823 * channel userspace API, but is only stored and passed to the
1824 * low-level driver when the AP starts or the mesh is joined.
1825 * This is for backward compatibility, userspace can also give
1826 * the channel in the start-ap or join-mesh commands instead.
Johannes Bergf444de02010-05-05 15:25:02 +02001827 *
1828 * Monitors are special as they are normally slaved to
Johannes Berge8c9bd52012-06-06 08:18:22 +02001829 * whatever else is going on, so they have their own special
1830 * operation to set the monitor channel if possible.
Johannes Bergf444de02010-05-05 15:25:02 +02001831 */
1832 return !wdev ||
1833 wdev->iftype == NL80211_IFTYPE_AP ||
Johannes Bergf444de02010-05-05 15:25:02 +02001834 wdev->iftype == NL80211_IFTYPE_MESH_POINT ||
Johannes Berg074ac8d2010-09-16 14:58:22 +02001835 wdev->iftype == NL80211_IFTYPE_MONITOR ||
1836 wdev->iftype == NL80211_IFTYPE_P2P_GO;
Johannes Bergf444de02010-05-05 15:25:02 +02001837}
1838
Johannes Berg683b6d32012-11-08 21:25:48 +01001839static int nl80211_parse_chandef(struct cfg80211_registered_device *rdev,
1840 struct genl_info *info,
1841 struct cfg80211_chan_def *chandef)
1842{
Mahesh Paliveladbeca2e2012-11-29 14:11:07 +05301843 u32 control_freq;
Johannes Berg683b6d32012-11-08 21:25:48 +01001844
1845 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ])
1846 return -EINVAL;
1847
1848 control_freq = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]);
1849
1850 chandef->chan = ieee80211_get_channel(&rdev->wiphy, control_freq);
Johannes Berg3d9d1d62012-11-08 23:14:50 +01001851 chandef->width = NL80211_CHAN_WIDTH_20_NOHT;
1852 chandef->center_freq1 = control_freq;
1853 chandef->center_freq2 = 0;
Johannes Berg683b6d32012-11-08 21:25:48 +01001854
1855 /* Primary channel not allowed */
1856 if (!chandef->chan || chandef->chan->flags & IEEE80211_CHAN_DISABLED)
1857 return -EINVAL;
1858
Johannes Berg3d9d1d62012-11-08 23:14:50 +01001859 if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]) {
1860 enum nl80211_channel_type chantype;
Johannes Berg683b6d32012-11-08 21:25:48 +01001861
Johannes Berg3d9d1d62012-11-08 23:14:50 +01001862 chantype = nla_get_u32(
1863 info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]);
1864
1865 switch (chantype) {
1866 case NL80211_CHAN_NO_HT:
1867 case NL80211_CHAN_HT20:
1868 case NL80211_CHAN_HT40PLUS:
1869 case NL80211_CHAN_HT40MINUS:
1870 cfg80211_chandef_create(chandef, chandef->chan,
1871 chantype);
1872 break;
1873 default:
Johannes Berg683b6d32012-11-08 21:25:48 +01001874 return -EINVAL;
Johannes Berg683b6d32012-11-08 21:25:48 +01001875 }
Johannes Berg3d9d1d62012-11-08 23:14:50 +01001876 } else if (info->attrs[NL80211_ATTR_CHANNEL_WIDTH]) {
1877 chandef->width =
1878 nla_get_u32(info->attrs[NL80211_ATTR_CHANNEL_WIDTH]);
1879 if (info->attrs[NL80211_ATTR_CENTER_FREQ1])
1880 chandef->center_freq1 =
1881 nla_get_u32(
1882 info->attrs[NL80211_ATTR_CENTER_FREQ1]);
1883 if (info->attrs[NL80211_ATTR_CENTER_FREQ2])
1884 chandef->center_freq2 =
1885 nla_get_u32(
1886 info->attrs[NL80211_ATTR_CENTER_FREQ2]);
1887 }
1888
Johannes Berg9f5e8f62012-11-22 16:59:45 +01001889 if (!cfg80211_chandef_valid(chandef))
Johannes Berg3d9d1d62012-11-08 23:14:50 +01001890 return -EINVAL;
1891
Johannes Berg9f5e8f62012-11-22 16:59:45 +01001892 if (!cfg80211_chandef_usable(&rdev->wiphy, chandef,
1893 IEEE80211_CHAN_DISABLED))
Johannes Berg3d9d1d62012-11-08 23:14:50 +01001894 return -EINVAL;
Johannes Berg3d9d1d62012-11-08 23:14:50 +01001895
Simon Wunderlich2f301ab2013-05-16 13:00:28 +02001896 if ((chandef->width == NL80211_CHAN_WIDTH_5 ||
1897 chandef->width == NL80211_CHAN_WIDTH_10) &&
1898 !(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_5_10_MHZ))
1899 return -EINVAL;
1900
Johannes Berg683b6d32012-11-08 21:25:48 +01001901 return 0;
1902}
1903
Johannes Bergf444de02010-05-05 15:25:02 +02001904static int __nl80211_set_channel(struct cfg80211_registered_device *rdev,
1905 struct wireless_dev *wdev,
1906 struct genl_info *info)
1907{
Johannes Berg683b6d32012-11-08 21:25:48 +01001908 struct cfg80211_chan_def chandef;
Johannes Bergf444de02010-05-05 15:25:02 +02001909 int result;
Johannes Berge8c9bd52012-06-06 08:18:22 +02001910 enum nl80211_iftype iftype = NL80211_IFTYPE_MONITOR;
1911
1912 if (wdev)
1913 iftype = wdev->iftype;
Johannes Bergf444de02010-05-05 15:25:02 +02001914
Johannes Bergf444de02010-05-05 15:25:02 +02001915 if (!nl80211_can_set_dev_channel(wdev))
1916 return -EOPNOTSUPP;
1917
Johannes Berg683b6d32012-11-08 21:25:48 +01001918 result = nl80211_parse_chandef(rdev, info, &chandef);
1919 if (result)
1920 return result;
Johannes Bergf444de02010-05-05 15:25:02 +02001921
Johannes Berge8c9bd52012-06-06 08:18:22 +02001922 switch (iftype) {
Johannes Bergaa430da2012-05-16 23:50:18 +02001923 case NL80211_IFTYPE_AP:
1924 case NL80211_IFTYPE_P2P_GO:
1925 if (wdev->beacon_interval) {
1926 result = -EBUSY;
1927 break;
1928 }
Johannes Berg683b6d32012-11-08 21:25:48 +01001929 if (!cfg80211_reg_can_beacon(&rdev->wiphy, &chandef)) {
Johannes Bergaa430da2012-05-16 23:50:18 +02001930 result = -EINVAL;
1931 break;
1932 }
Johannes Berg683b6d32012-11-08 21:25:48 +01001933 wdev->preset_chandef = chandef;
Johannes Bergaa430da2012-05-16 23:50:18 +02001934 result = 0;
1935 break;
Johannes Bergcc1d2802012-05-16 23:50:20 +02001936 case NL80211_IFTYPE_MESH_POINT:
Johannes Berg683b6d32012-11-08 21:25:48 +01001937 result = cfg80211_set_mesh_channel(rdev, wdev, &chandef);
Johannes Bergcc1d2802012-05-16 23:50:20 +02001938 break;
Johannes Berge8c9bd52012-06-06 08:18:22 +02001939 case NL80211_IFTYPE_MONITOR:
Johannes Berg683b6d32012-11-08 21:25:48 +01001940 result = cfg80211_set_monitor_channel(rdev, &chandef);
Johannes Berge8c9bd52012-06-06 08:18:22 +02001941 break;
Johannes Bergaa430da2012-05-16 23:50:18 +02001942 default:
Johannes Berge8c9bd52012-06-06 08:18:22 +02001943 result = -EINVAL;
Johannes Bergf444de02010-05-05 15:25:02 +02001944 }
Johannes Bergf444de02010-05-05 15:25:02 +02001945
1946 return result;
1947}
1948
1949static int nl80211_set_channel(struct sk_buff *skb, struct genl_info *info)
1950{
Johannes Berg4c476992010-10-04 21:36:35 +02001951 struct cfg80211_registered_device *rdev = info->user_ptr[0];
1952 struct net_device *netdev = info->user_ptr[1];
Johannes Bergf444de02010-05-05 15:25:02 +02001953
Johannes Berg4c476992010-10-04 21:36:35 +02001954 return __nl80211_set_channel(rdev, netdev->ieee80211_ptr, info);
Johannes Bergf444de02010-05-05 15:25:02 +02001955}
1956
Bill Jordane8347eb2010-10-01 13:54:28 -04001957static int nl80211_set_wds_peer(struct sk_buff *skb, struct genl_info *info)
1958{
Johannes Berg43b19952010-10-07 13:10:30 +02001959 struct cfg80211_registered_device *rdev = info->user_ptr[0];
1960 struct net_device *dev = info->user_ptr[1];
1961 struct wireless_dev *wdev = dev->ieee80211_ptr;
Johannes Berg388ac772010-10-07 13:11:09 +02001962 const u8 *bssid;
Bill Jordane8347eb2010-10-01 13:54:28 -04001963
1964 if (!info->attrs[NL80211_ATTR_MAC])
1965 return -EINVAL;
1966
Johannes Berg43b19952010-10-07 13:10:30 +02001967 if (netif_running(dev))
1968 return -EBUSY;
Bill Jordane8347eb2010-10-01 13:54:28 -04001969
Johannes Berg43b19952010-10-07 13:10:30 +02001970 if (!rdev->ops->set_wds_peer)
1971 return -EOPNOTSUPP;
Bill Jordane8347eb2010-10-01 13:54:28 -04001972
Johannes Berg43b19952010-10-07 13:10:30 +02001973 if (wdev->iftype != NL80211_IFTYPE_WDS)
1974 return -EOPNOTSUPP;
Bill Jordane8347eb2010-10-01 13:54:28 -04001975
1976 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Hila Gonene35e4d22012-06-27 17:19:42 +03001977 return rdev_set_wds_peer(rdev, dev, bssid);
Bill Jordane8347eb2010-10-01 13:54:28 -04001978}
1979
1980
Johannes Berg55682962007-09-20 13:09:35 -04001981static int nl80211_set_wiphy(struct sk_buff *skb, struct genl_info *info)
1982{
1983 struct cfg80211_registered_device *rdev;
Johannes Bergf444de02010-05-05 15:25:02 +02001984 struct net_device *netdev = NULL;
1985 struct wireless_dev *wdev;
Bill Jordana1e567c2010-09-10 11:22:32 -04001986 int result = 0, rem_txq_params = 0;
Jouni Malinen31888482008-10-30 16:59:24 +02001987 struct nlattr *nl_txq_params;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02001988 u32 changed;
1989 u8 retry_short = 0, retry_long = 0;
1990 u32 frag_threshold = 0, rts_threshold = 0;
Lukáš Turek81077e82009-12-21 22:50:47 +01001991 u8 coverage_class = 0;
Johannes Berg55682962007-09-20 13:09:35 -04001992
Johannes Berg5fe231e2013-05-08 21:45:15 +02001993 ASSERT_RTNL();
1994
Johannes Bergf444de02010-05-05 15:25:02 +02001995 /*
1996 * Try to find the wiphy and netdev. Normally this
1997 * function shouldn't need the netdev, but this is
1998 * done for backward compatibility -- previously
1999 * setting the channel was done per wiphy, but now
2000 * it is per netdev. Previous userland like hostapd
2001 * also passed a netdev to set_wiphy, so that it is
2002 * possible to let that go to the right netdev!
2003 */
Johannes Berg4bbf4d52009-03-24 09:35:46 +01002004
Johannes Bergf444de02010-05-05 15:25:02 +02002005 if (info->attrs[NL80211_ATTR_IFINDEX]) {
2006 int ifindex = nla_get_u32(info->attrs[NL80211_ATTR_IFINDEX]);
2007
Ying Xue7f2b8562014-01-15 10:23:45 +08002008 netdev = __dev_get_by_index(genl_info_net(info), ifindex);
Johannes Berg5fe231e2013-05-08 21:45:15 +02002009 if (netdev && netdev->ieee80211_ptr)
Johannes Bergf444de02010-05-05 15:25:02 +02002010 rdev = wiphy_to_dev(netdev->ieee80211_ptr->wiphy);
Johannes Berg5fe231e2013-05-08 21:45:15 +02002011 else
Johannes Bergf444de02010-05-05 15:25:02 +02002012 netdev = NULL;
Johannes Berg4bbf4d52009-03-24 09:35:46 +01002013 }
2014
Johannes Bergf444de02010-05-05 15:25:02 +02002015 if (!netdev) {
Johannes Berg878d9ec2012-06-15 14:18:32 +02002016 rdev = __cfg80211_rdev_from_attrs(genl_info_net(info),
2017 info->attrs);
Johannes Berg5fe231e2013-05-08 21:45:15 +02002018 if (IS_ERR(rdev))
Johannes Berg4c476992010-10-04 21:36:35 +02002019 return PTR_ERR(rdev);
Johannes Bergf444de02010-05-05 15:25:02 +02002020 wdev = NULL;
2021 netdev = NULL;
2022 result = 0;
Johannes Berg71fe96b2012-10-24 10:04:58 +02002023 } else
Johannes Bergf444de02010-05-05 15:25:02 +02002024 wdev = netdev->ieee80211_ptr;
Johannes Bergf444de02010-05-05 15:25:02 +02002025
2026 /*
2027 * end workaround code, by now the rdev is available
2028 * and locked, and wdev may or may not be NULL.
2029 */
Johannes Berg4bbf4d52009-03-24 09:35:46 +01002030
2031 if (info->attrs[NL80211_ATTR_WIPHY_NAME])
Jouni Malinen31888482008-10-30 16:59:24 +02002032 result = cfg80211_dev_rename(
2033 rdev, nla_data(info->attrs[NL80211_ATTR_WIPHY_NAME]));
Johannes Berg4bbf4d52009-03-24 09:35:46 +01002034
Johannes Berg4bbf4d52009-03-24 09:35:46 +01002035 if (result)
Ying Xue7f2b8562014-01-15 10:23:45 +08002036 return result;
Johannes Berg55682962007-09-20 13:09:35 -04002037
Jouni Malinen31888482008-10-30 16:59:24 +02002038 if (info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS]) {
2039 struct ieee80211_txq_params txq_params;
2040 struct nlattr *tb[NL80211_TXQ_ATTR_MAX + 1];
2041
Ying Xue7f2b8562014-01-15 10:23:45 +08002042 if (!rdev->ops->set_txq_params)
2043 return -EOPNOTSUPP;
Jouni Malinen31888482008-10-30 16:59:24 +02002044
Ying Xue7f2b8562014-01-15 10:23:45 +08002045 if (!netdev)
2046 return -EINVAL;
Eliad Pellerf70f01c2011-09-25 20:06:53 +03002047
Johannes Berg133a3ff2011-11-03 14:50:13 +01002048 if (netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
Ying Xue7f2b8562014-01-15 10:23:45 +08002049 netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
2050 return -EINVAL;
Johannes Berg133a3ff2011-11-03 14:50:13 +01002051
Ying Xue7f2b8562014-01-15 10:23:45 +08002052 if (!netif_running(netdev))
2053 return -ENETDOWN;
Johannes Berg2b5f8b02012-04-02 10:51:55 +02002054
Jouni Malinen31888482008-10-30 16:59:24 +02002055 nla_for_each_nested(nl_txq_params,
2056 info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS],
2057 rem_txq_params) {
Johannes Bergae811e22014-01-24 10:17:47 +01002058 result = nla_parse(tb, NL80211_TXQ_ATTR_MAX,
2059 nla_data(nl_txq_params),
2060 nla_len(nl_txq_params),
2061 txq_params_policy);
2062 if (result)
2063 return result;
Jouni Malinen31888482008-10-30 16:59:24 +02002064 result = parse_txq_params(tb, &txq_params);
2065 if (result)
Ying Xue7f2b8562014-01-15 10:23:45 +08002066 return result;
Jouni Malinen31888482008-10-30 16:59:24 +02002067
Hila Gonene35e4d22012-06-27 17:19:42 +03002068 result = rdev_set_txq_params(rdev, netdev,
2069 &txq_params);
Jouni Malinen31888482008-10-30 16:59:24 +02002070 if (result)
Ying Xue7f2b8562014-01-15 10:23:45 +08002071 return result;
Jouni Malinen31888482008-10-30 16:59:24 +02002072 }
2073 }
2074
Jouni Malinen72bdcf32008-11-26 16:15:24 +02002075 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
Johannes Berg71fe96b2012-10-24 10:04:58 +02002076 result = __nl80211_set_channel(rdev,
2077 nl80211_can_set_dev_channel(wdev) ? wdev : NULL,
2078 info);
Jouni Malinen72bdcf32008-11-26 16:15:24 +02002079 if (result)
Ying Xue7f2b8562014-01-15 10:23:45 +08002080 return result;
Jouni Malinen72bdcf32008-11-26 16:15:24 +02002081 }
2082
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03002083 if (info->attrs[NL80211_ATTR_WIPHY_TX_POWER_SETTING]) {
Johannes Bergc8442112012-10-24 10:17:18 +02002084 struct wireless_dev *txp_wdev = wdev;
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03002085 enum nl80211_tx_power_setting type;
2086 int idx, mbm = 0;
2087
Johannes Bergc8442112012-10-24 10:17:18 +02002088 if (!(rdev->wiphy.features & NL80211_FEATURE_VIF_TXPOWER))
2089 txp_wdev = NULL;
2090
Ying Xue7f2b8562014-01-15 10:23:45 +08002091 if (!rdev->ops->set_tx_power)
2092 return -EOPNOTSUPP;
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03002093
2094 idx = NL80211_ATTR_WIPHY_TX_POWER_SETTING;
2095 type = nla_get_u32(info->attrs[idx]);
2096
2097 if (!info->attrs[NL80211_ATTR_WIPHY_TX_POWER_LEVEL] &&
Ying Xue7f2b8562014-01-15 10:23:45 +08002098 (type != NL80211_TX_POWER_AUTOMATIC))
2099 return -EINVAL;
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03002100
2101 if (type != NL80211_TX_POWER_AUTOMATIC) {
2102 idx = NL80211_ATTR_WIPHY_TX_POWER_LEVEL;
2103 mbm = nla_get_u32(info->attrs[idx]);
2104 }
2105
Johannes Bergc8442112012-10-24 10:17:18 +02002106 result = rdev_set_tx_power(rdev, txp_wdev, type, mbm);
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03002107 if (result)
Ying Xue7f2b8562014-01-15 10:23:45 +08002108 return result;
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03002109 }
2110
Bruno Randolfafe0cbf2010-11-10 12:50:50 +09002111 if (info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX] &&
2112 info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]) {
2113 u32 tx_ant, rx_ant;
Bruno Randolf7f531e02010-12-16 11:30:22 +09002114 if ((!rdev->wiphy.available_antennas_tx &&
2115 !rdev->wiphy.available_antennas_rx) ||
Ying Xue7f2b8562014-01-15 10:23:45 +08002116 !rdev->ops->set_antenna)
2117 return -EOPNOTSUPP;
Bruno Randolfafe0cbf2010-11-10 12:50:50 +09002118
2119 tx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX]);
2120 rx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]);
2121
Bruno Randolfa7ffac92010-12-08 13:59:24 +09002122 /* reject antenna configurations which don't match the
Bruno Randolf7f531e02010-12-16 11:30:22 +09002123 * available antenna masks, except for the "all" mask */
2124 if ((~tx_ant && (tx_ant & ~rdev->wiphy.available_antennas_tx)) ||
Ying Xue7f2b8562014-01-15 10:23:45 +08002125 (~rx_ant && (rx_ant & ~rdev->wiphy.available_antennas_rx)))
2126 return -EINVAL;
Bruno Randolfa7ffac92010-12-08 13:59:24 +09002127
Bruno Randolf7f531e02010-12-16 11:30:22 +09002128 tx_ant = tx_ant & rdev->wiphy.available_antennas_tx;
2129 rx_ant = rx_ant & rdev->wiphy.available_antennas_rx;
Bruno Randolfa7ffac92010-12-08 13:59:24 +09002130
Hila Gonene35e4d22012-06-27 17:19:42 +03002131 result = rdev_set_antenna(rdev, tx_ant, rx_ant);
Bruno Randolfafe0cbf2010-11-10 12:50:50 +09002132 if (result)
Ying Xue7f2b8562014-01-15 10:23:45 +08002133 return result;
Bruno Randolfafe0cbf2010-11-10 12:50:50 +09002134 }
2135
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002136 changed = 0;
2137
2138 if (info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]) {
2139 retry_short = nla_get_u8(
2140 info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]);
Ying Xue7f2b8562014-01-15 10:23:45 +08002141 if (retry_short == 0)
2142 return -EINVAL;
2143
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002144 changed |= WIPHY_PARAM_RETRY_SHORT;
2145 }
2146
2147 if (info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]) {
2148 retry_long = nla_get_u8(
2149 info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]);
Ying Xue7f2b8562014-01-15 10:23:45 +08002150 if (retry_long == 0)
2151 return -EINVAL;
2152
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002153 changed |= WIPHY_PARAM_RETRY_LONG;
2154 }
2155
2156 if (info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]) {
2157 frag_threshold = nla_get_u32(
2158 info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]);
Ying Xue7f2b8562014-01-15 10:23:45 +08002159 if (frag_threshold < 256)
2160 return -EINVAL;
2161
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002162 if (frag_threshold != (u32) -1) {
2163 /*
2164 * Fragments (apart from the last one) are required to
2165 * have even length. Make the fragmentation code
2166 * simpler by stripping LSB should someone try to use
2167 * odd threshold value.
2168 */
2169 frag_threshold &= ~0x1;
2170 }
2171 changed |= WIPHY_PARAM_FRAG_THRESHOLD;
2172 }
2173
2174 if (info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]) {
2175 rts_threshold = nla_get_u32(
2176 info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]);
2177 changed |= WIPHY_PARAM_RTS_THRESHOLD;
2178 }
2179
Lukáš Turek81077e82009-12-21 22:50:47 +01002180 if (info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]) {
2181 coverage_class = nla_get_u8(
2182 info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]);
2183 changed |= WIPHY_PARAM_COVERAGE_CLASS;
2184 }
2185
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002186 if (changed) {
2187 u8 old_retry_short, old_retry_long;
2188 u32 old_frag_threshold, old_rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01002189 u8 old_coverage_class;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002190
Ying Xue7f2b8562014-01-15 10:23:45 +08002191 if (!rdev->ops->set_wiphy_params)
2192 return -EOPNOTSUPP;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002193
2194 old_retry_short = rdev->wiphy.retry_short;
2195 old_retry_long = rdev->wiphy.retry_long;
2196 old_frag_threshold = rdev->wiphy.frag_threshold;
2197 old_rts_threshold = rdev->wiphy.rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01002198 old_coverage_class = rdev->wiphy.coverage_class;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002199
2200 if (changed & WIPHY_PARAM_RETRY_SHORT)
2201 rdev->wiphy.retry_short = retry_short;
2202 if (changed & WIPHY_PARAM_RETRY_LONG)
2203 rdev->wiphy.retry_long = retry_long;
2204 if (changed & WIPHY_PARAM_FRAG_THRESHOLD)
2205 rdev->wiphy.frag_threshold = frag_threshold;
2206 if (changed & WIPHY_PARAM_RTS_THRESHOLD)
2207 rdev->wiphy.rts_threshold = rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01002208 if (changed & WIPHY_PARAM_COVERAGE_CLASS)
2209 rdev->wiphy.coverage_class = coverage_class;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002210
Hila Gonene35e4d22012-06-27 17:19:42 +03002211 result = rdev_set_wiphy_params(rdev, changed);
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002212 if (result) {
2213 rdev->wiphy.retry_short = old_retry_short;
2214 rdev->wiphy.retry_long = old_retry_long;
2215 rdev->wiphy.frag_threshold = old_frag_threshold;
2216 rdev->wiphy.rts_threshold = old_rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01002217 rdev->wiphy.coverage_class = old_coverage_class;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002218 }
2219 }
Ying Xue7f2b8562014-01-15 10:23:45 +08002220 return 0;
Johannes Berg55682962007-09-20 13:09:35 -04002221}
2222
Johannes Berg71bbc992012-06-15 15:30:18 +02002223static inline u64 wdev_id(struct wireless_dev *wdev)
2224{
2225 return (u64)wdev->identifier |
2226 ((u64)wiphy_to_dev(wdev->wiphy)->wiphy_idx << 32);
2227}
Johannes Berg55682962007-09-20 13:09:35 -04002228
Johannes Berg683b6d32012-11-08 21:25:48 +01002229static int nl80211_send_chandef(struct sk_buff *msg,
Janusz Dziedzicd2859df2013-11-06 13:55:51 +01002230 const struct cfg80211_chan_def *chandef)
Johannes Berg683b6d32012-11-08 21:25:48 +01002231{
Johannes Berg9f5e8f62012-11-22 16:59:45 +01002232 WARN_ON(!cfg80211_chandef_valid(chandef));
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002233
Johannes Berg683b6d32012-11-08 21:25:48 +01002234 if (nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ,
2235 chandef->chan->center_freq))
2236 return -ENOBUFS;
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002237 switch (chandef->width) {
2238 case NL80211_CHAN_WIDTH_20_NOHT:
2239 case NL80211_CHAN_WIDTH_20:
2240 case NL80211_CHAN_WIDTH_40:
2241 if (nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE,
2242 cfg80211_get_chandef_type(chandef)))
2243 return -ENOBUFS;
2244 break;
2245 default:
2246 break;
2247 }
2248 if (nla_put_u32(msg, NL80211_ATTR_CHANNEL_WIDTH, chandef->width))
2249 return -ENOBUFS;
2250 if (nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ1, chandef->center_freq1))
2251 return -ENOBUFS;
2252 if (chandef->center_freq2 &&
2253 nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ2, chandef->center_freq2))
Johannes Berg683b6d32012-11-08 21:25:48 +01002254 return -ENOBUFS;
2255 return 0;
2256}
2257
Eric W. Biederman15e47302012-09-07 20:12:54 +00002258static int nl80211_send_iface(struct sk_buff *msg, u32 portid, u32 seq, int flags,
Johannes Bergd7264052009-04-19 16:23:20 +02002259 struct cfg80211_registered_device *rdev,
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002260 struct wireless_dev *wdev)
Johannes Berg55682962007-09-20 13:09:35 -04002261{
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002262 struct net_device *dev = wdev->netdev;
Johannes Berg55682962007-09-20 13:09:35 -04002263 void *hdr;
2264
Eric W. Biederman15e47302012-09-07 20:12:54 +00002265 hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_INTERFACE);
Johannes Berg55682962007-09-20 13:09:35 -04002266 if (!hdr)
2267 return -1;
2268
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002269 if (dev &&
2270 (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
Johannes Berg98104fde2012-06-16 00:19:54 +02002271 nla_put_string(msg, NL80211_ATTR_IFNAME, dev->name)))
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002272 goto nla_put_failure;
2273
2274 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
2275 nla_put_u32(msg, NL80211_ATTR_IFTYPE, wdev->iftype) ||
Johannes Berg71bbc992012-06-15 15:30:18 +02002276 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) ||
Johannes Berg98104fde2012-06-16 00:19:54 +02002277 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, wdev_address(wdev)) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04002278 nla_put_u32(msg, NL80211_ATTR_GENERATION,
2279 rdev->devlist_generation ^
2280 (cfg80211_rdev_list_generation << 2)))
2281 goto nla_put_failure;
Johannes Bergf5ea9122009-08-07 16:17:38 +02002282
Johannes Berg5b7ccaf2012-07-12 19:45:08 +02002283 if (rdev->ops->get_channel) {
Johannes Berg683b6d32012-11-08 21:25:48 +01002284 int ret;
2285 struct cfg80211_chan_def chandef;
Johannes Berg5b7ccaf2012-07-12 19:45:08 +02002286
Johannes Berg683b6d32012-11-08 21:25:48 +01002287 ret = rdev_get_channel(rdev, wdev, &chandef);
2288 if (ret == 0) {
2289 if (nl80211_send_chandef(msg, &chandef))
2290 goto nla_put_failure;
2291 }
Pontus Fuchsd91df0e2012-04-03 16:39:58 +02002292 }
2293
Antonio Quartullib84e7a02012-11-07 12:52:20 +01002294 if (wdev->ssid_len) {
2295 if (nla_put(msg, NL80211_ATTR_SSID, wdev->ssid_len, wdev->ssid))
2296 goto nla_put_failure;
2297 }
2298
Johannes Berg55682962007-09-20 13:09:35 -04002299 return genlmsg_end(msg, hdr);
2300
2301 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07002302 genlmsg_cancel(msg, hdr);
2303 return -EMSGSIZE;
Johannes Berg55682962007-09-20 13:09:35 -04002304}
2305
2306static int nl80211_dump_interface(struct sk_buff *skb, struct netlink_callback *cb)
2307{
2308 int wp_idx = 0;
2309 int if_idx = 0;
2310 int wp_start = cb->args[0];
2311 int if_start = cb->args[1];
Johannes Bergf5ea9122009-08-07 16:17:38 +02002312 struct cfg80211_registered_device *rdev;
Johannes Berg55682962007-09-20 13:09:35 -04002313 struct wireless_dev *wdev;
2314
Johannes Berg5fe231e2013-05-08 21:45:15 +02002315 rtnl_lock();
Johannes Bergf5ea9122009-08-07 16:17:38 +02002316 list_for_each_entry(rdev, &cfg80211_rdev_list, list) {
2317 if (!net_eq(wiphy_net(&rdev->wiphy), sock_net(skb->sk)))
Johannes Berg463d0182009-07-14 00:33:35 +02002318 continue;
Johannes Bergbba95fe2008-07-29 13:22:51 +02002319 if (wp_idx < wp_start) {
2320 wp_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04002321 continue;
Johannes Bergbba95fe2008-07-29 13:22:51 +02002322 }
Johannes Berg55682962007-09-20 13:09:35 -04002323 if_idx = 0;
2324
Johannes Berg89a54e42012-06-15 14:33:17 +02002325 list_for_each_entry(wdev, &rdev->wdev_list, list) {
Johannes Bergbba95fe2008-07-29 13:22:51 +02002326 if (if_idx < if_start) {
2327 if_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04002328 continue;
Johannes Bergbba95fe2008-07-29 13:22:51 +02002329 }
Eric W. Biederman15e47302012-09-07 20:12:54 +00002330 if (nl80211_send_iface(skb, NETLINK_CB(cb->skb).portid,
Johannes Berg55682962007-09-20 13:09:35 -04002331 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002332 rdev, wdev) < 0) {
Johannes Bergbba95fe2008-07-29 13:22:51 +02002333 goto out;
2334 }
2335 if_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04002336 }
Johannes Bergbba95fe2008-07-29 13:22:51 +02002337
2338 wp_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04002339 }
Johannes Bergbba95fe2008-07-29 13:22:51 +02002340 out:
Johannes Berg5fe231e2013-05-08 21:45:15 +02002341 rtnl_unlock();
Johannes Berg55682962007-09-20 13:09:35 -04002342
2343 cb->args[0] = wp_idx;
2344 cb->args[1] = if_idx;
2345
2346 return skb->len;
2347}
2348
2349static int nl80211_get_interface(struct sk_buff *skb, struct genl_info *info)
2350{
2351 struct sk_buff *msg;
Johannes Berg4c476992010-10-04 21:36:35 +02002352 struct cfg80211_registered_device *dev = info->user_ptr[0];
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002353 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg55682962007-09-20 13:09:35 -04002354
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07002355 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -04002356 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02002357 return -ENOMEM;
Johannes Berg55682962007-09-20 13:09:35 -04002358
Eric W. Biederman15e47302012-09-07 20:12:54 +00002359 if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002360 dev, wdev) < 0) {
Johannes Berg4c476992010-10-04 21:36:35 +02002361 nlmsg_free(msg);
2362 return -ENOBUFS;
2363 }
Johannes Berg55682962007-09-20 13:09:35 -04002364
Johannes Berg134e6372009-07-10 09:51:34 +00002365 return genlmsg_reply(msg, info);
Johannes Berg55682962007-09-20 13:09:35 -04002366}
2367
Michael Wu66f7ac52008-01-31 19:48:22 +01002368static const struct nla_policy mntr_flags_policy[NL80211_MNTR_FLAG_MAX + 1] = {
2369 [NL80211_MNTR_FLAG_FCSFAIL] = { .type = NLA_FLAG },
2370 [NL80211_MNTR_FLAG_PLCPFAIL] = { .type = NLA_FLAG },
2371 [NL80211_MNTR_FLAG_CONTROL] = { .type = NLA_FLAG },
2372 [NL80211_MNTR_FLAG_OTHER_BSS] = { .type = NLA_FLAG },
2373 [NL80211_MNTR_FLAG_COOK_FRAMES] = { .type = NLA_FLAG },
Felix Fietkaue057d3c2013-05-28 13:01:52 +02002374 [NL80211_MNTR_FLAG_ACTIVE] = { .type = NLA_FLAG },
Michael Wu66f7ac52008-01-31 19:48:22 +01002375};
2376
2377static int parse_monitor_flags(struct nlattr *nla, u32 *mntrflags)
2378{
2379 struct nlattr *flags[NL80211_MNTR_FLAG_MAX + 1];
2380 int flag;
2381
2382 *mntrflags = 0;
2383
2384 if (!nla)
2385 return -EINVAL;
2386
2387 if (nla_parse_nested(flags, NL80211_MNTR_FLAG_MAX,
2388 nla, mntr_flags_policy))
2389 return -EINVAL;
2390
2391 for (flag = 1; flag <= NL80211_MNTR_FLAG_MAX; flag++)
2392 if (flags[flag])
2393 *mntrflags |= (1<<flag);
2394
2395 return 0;
2396}
2397
Johannes Berg9bc383d2009-11-19 11:55:19 +01002398static int nl80211_valid_4addr(struct cfg80211_registered_device *rdev,
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002399 struct net_device *netdev, u8 use_4addr,
2400 enum nl80211_iftype iftype)
Johannes Berg9bc383d2009-11-19 11:55:19 +01002401{
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002402 if (!use_4addr) {
Jiri Pirkof350a0a82010-06-15 06:50:45 +00002403 if (netdev && (netdev->priv_flags & IFF_BRIDGE_PORT))
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002404 return -EBUSY;
Johannes Berg9bc383d2009-11-19 11:55:19 +01002405 return 0;
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002406 }
Johannes Berg9bc383d2009-11-19 11:55:19 +01002407
2408 switch (iftype) {
2409 case NL80211_IFTYPE_AP_VLAN:
2410 if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_AP)
2411 return 0;
2412 break;
2413 case NL80211_IFTYPE_STATION:
2414 if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_STATION)
2415 return 0;
2416 break;
2417 default:
2418 break;
2419 }
2420
2421 return -EOPNOTSUPP;
2422}
2423
Johannes Berg55682962007-09-20 13:09:35 -04002424static int nl80211_set_interface(struct sk_buff *skb, struct genl_info *info)
2425{
Johannes Berg4c476992010-10-04 21:36:35 +02002426 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002427 struct vif_params params;
Johannes Berge36d56b2009-06-09 21:04:43 +02002428 int err;
Johannes Berg04a773a2009-04-19 21:24:32 +02002429 enum nl80211_iftype otype, ntype;
Johannes Berg4c476992010-10-04 21:36:35 +02002430 struct net_device *dev = info->user_ptr[1];
Johannes Berg92ffe052008-09-16 20:39:36 +02002431 u32 _flags, *flags = NULL;
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002432 bool change = false;
Johannes Berg55682962007-09-20 13:09:35 -04002433
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002434 memset(&params, 0, sizeof(params));
2435
Johannes Berg04a773a2009-04-19 21:24:32 +02002436 otype = ntype = dev->ieee80211_ptr->iftype;
Johannes Berg55682962007-09-20 13:09:35 -04002437
Johannes Berg723b0382008-09-16 20:22:09 +02002438 if (info->attrs[NL80211_ATTR_IFTYPE]) {
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002439 ntype = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]);
Johannes Berg04a773a2009-04-19 21:24:32 +02002440 if (otype != ntype)
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002441 change = true;
Johannes Berg4c476992010-10-04 21:36:35 +02002442 if (ntype > NL80211_IFTYPE_MAX)
2443 return -EINVAL;
Johannes Berg723b0382008-09-16 20:22:09 +02002444 }
2445
Johannes Berg92ffe052008-09-16 20:39:36 +02002446 if (info->attrs[NL80211_ATTR_MESH_ID]) {
Johannes Berg29cbe682010-12-03 09:20:44 +01002447 struct wireless_dev *wdev = dev->ieee80211_ptr;
2448
Johannes Berg4c476992010-10-04 21:36:35 +02002449 if (ntype != NL80211_IFTYPE_MESH_POINT)
2450 return -EINVAL;
Johannes Berg29cbe682010-12-03 09:20:44 +01002451 if (netif_running(dev))
2452 return -EBUSY;
2453
2454 wdev_lock(wdev);
2455 BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN !=
2456 IEEE80211_MAX_MESH_ID_LEN);
2457 wdev->mesh_id_up_len =
2458 nla_len(info->attrs[NL80211_ATTR_MESH_ID]);
2459 memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]),
2460 wdev->mesh_id_up_len);
2461 wdev_unlock(wdev);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002462 }
2463
Felix Fietkau8b787642009-11-10 18:53:10 +01002464 if (info->attrs[NL80211_ATTR_4ADDR]) {
2465 params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]);
2466 change = true;
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002467 err = nl80211_valid_4addr(rdev, dev, params.use_4addr, ntype);
Johannes Berg9bc383d2009-11-19 11:55:19 +01002468 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02002469 return err;
Felix Fietkau8b787642009-11-10 18:53:10 +01002470 } else {
2471 params.use_4addr = -1;
2472 }
2473
Johannes Berg92ffe052008-09-16 20:39:36 +02002474 if (info->attrs[NL80211_ATTR_MNTR_FLAGS]) {
Johannes Berg4c476992010-10-04 21:36:35 +02002475 if (ntype != NL80211_IFTYPE_MONITOR)
2476 return -EINVAL;
Johannes Berg92ffe052008-09-16 20:39:36 +02002477 err = parse_monitor_flags(info->attrs[NL80211_ATTR_MNTR_FLAGS],
2478 &_flags);
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002479 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02002480 return err;
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002481
2482 flags = &_flags;
2483 change = true;
Johannes Berg92ffe052008-09-16 20:39:36 +02002484 }
Johannes Berg3b858752009-03-12 09:55:09 +01002485
Luciano Coelho18003292013-08-29 13:26:57 +03002486 if (flags && (*flags & MONITOR_FLAG_ACTIVE) &&
Felix Fietkaue057d3c2013-05-28 13:01:52 +02002487 !(rdev->wiphy.features & NL80211_FEATURE_ACTIVE_MONITOR))
2488 return -EOPNOTSUPP;
2489
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002490 if (change)
Johannes Berg3d54d252009-08-21 14:51:05 +02002491 err = cfg80211_change_iface(rdev, dev, ntype, flags, &params);
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002492 else
2493 err = 0;
Johannes Berg60719ff2008-09-16 14:55:09 +02002494
Johannes Berg9bc383d2009-11-19 11:55:19 +01002495 if (!err && params.use_4addr != -1)
2496 dev->ieee80211_ptr->use_4addr = params.use_4addr;
2497
Johannes Berg55682962007-09-20 13:09:35 -04002498 return err;
2499}
2500
2501static int nl80211_new_interface(struct sk_buff *skb, struct genl_info *info)
2502{
Johannes Berg4c476992010-10-04 21:36:35 +02002503 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002504 struct vif_params params;
Johannes Berg84efbb82012-06-16 00:00:26 +02002505 struct wireless_dev *wdev;
Johannes Berg1c90f9d2012-06-16 00:05:37 +02002506 struct sk_buff *msg;
Johannes Berg55682962007-09-20 13:09:35 -04002507 int err;
2508 enum nl80211_iftype type = NL80211_IFTYPE_UNSPECIFIED;
Michael Wu66f7ac52008-01-31 19:48:22 +01002509 u32 flags;
Johannes Berg55682962007-09-20 13:09:35 -04002510
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002511 memset(&params, 0, sizeof(params));
2512
Johannes Berg55682962007-09-20 13:09:35 -04002513 if (!info->attrs[NL80211_ATTR_IFNAME])
2514 return -EINVAL;
2515
2516 if (info->attrs[NL80211_ATTR_IFTYPE]) {
2517 type = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]);
2518 if (type > NL80211_IFTYPE_MAX)
2519 return -EINVAL;
2520 }
2521
Johannes Berg79c97e92009-07-07 03:56:12 +02002522 if (!rdev->ops->add_virtual_intf ||
Johannes Berg4c476992010-10-04 21:36:35 +02002523 !(rdev->wiphy.interface_modes & (1 << type)))
2524 return -EOPNOTSUPP;
Johannes Berg55682962007-09-20 13:09:35 -04002525
Arend van Spriel1c18f142013-01-08 10:17:27 +01002526 if (type == NL80211_IFTYPE_P2P_DEVICE && info->attrs[NL80211_ATTR_MAC]) {
2527 nla_memcpy(params.macaddr, info->attrs[NL80211_ATTR_MAC],
2528 ETH_ALEN);
2529 if (!is_valid_ether_addr(params.macaddr))
2530 return -EADDRNOTAVAIL;
2531 }
2532
Johannes Berg9bc383d2009-11-19 11:55:19 +01002533 if (info->attrs[NL80211_ATTR_4ADDR]) {
Felix Fietkau8b787642009-11-10 18:53:10 +01002534 params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]);
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002535 err = nl80211_valid_4addr(rdev, NULL, params.use_4addr, type);
Johannes Berg9bc383d2009-11-19 11:55:19 +01002536 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02002537 return err;
Johannes Berg9bc383d2009-11-19 11:55:19 +01002538 }
Felix Fietkau8b787642009-11-10 18:53:10 +01002539
Johannes Berg1c90f9d2012-06-16 00:05:37 +02002540 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
2541 if (!msg)
2542 return -ENOMEM;
2543
Michael Wu66f7ac52008-01-31 19:48:22 +01002544 err = parse_monitor_flags(type == NL80211_IFTYPE_MONITOR ?
2545 info->attrs[NL80211_ATTR_MNTR_FLAGS] : NULL,
2546 &flags);
Felix Fietkaue057d3c2013-05-28 13:01:52 +02002547
Luciano Coelho18003292013-08-29 13:26:57 +03002548 if (!err && (flags & MONITOR_FLAG_ACTIVE) &&
Felix Fietkaue057d3c2013-05-28 13:01:52 +02002549 !(rdev->wiphy.features & NL80211_FEATURE_ACTIVE_MONITOR))
2550 return -EOPNOTSUPP;
2551
Hila Gonene35e4d22012-06-27 17:19:42 +03002552 wdev = rdev_add_virtual_intf(rdev,
2553 nla_data(info->attrs[NL80211_ATTR_IFNAME]),
2554 type, err ? NULL : &flags, &params);
Johannes Berg1c90f9d2012-06-16 00:05:37 +02002555 if (IS_ERR(wdev)) {
2556 nlmsg_free(msg);
Johannes Berg84efbb82012-06-16 00:00:26 +02002557 return PTR_ERR(wdev);
Johannes Berg1c90f9d2012-06-16 00:05:37 +02002558 }
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002559
Johannes Berg98104fde2012-06-16 00:19:54 +02002560 switch (type) {
2561 case NL80211_IFTYPE_MESH_POINT:
2562 if (!info->attrs[NL80211_ATTR_MESH_ID])
2563 break;
Johannes Berg29cbe682010-12-03 09:20:44 +01002564 wdev_lock(wdev);
2565 BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN !=
2566 IEEE80211_MAX_MESH_ID_LEN);
2567 wdev->mesh_id_up_len =
2568 nla_len(info->attrs[NL80211_ATTR_MESH_ID]);
2569 memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]),
2570 wdev->mesh_id_up_len);
2571 wdev_unlock(wdev);
Johannes Berg98104fde2012-06-16 00:19:54 +02002572 break;
2573 case NL80211_IFTYPE_P2P_DEVICE:
2574 /*
2575 * P2P Device doesn't have a netdev, so doesn't go
2576 * through the netdev notifier and must be added here
2577 */
2578 mutex_init(&wdev->mtx);
2579 INIT_LIST_HEAD(&wdev->event_list);
2580 spin_lock_init(&wdev->event_lock);
2581 INIT_LIST_HEAD(&wdev->mgmt_registrations);
2582 spin_lock_init(&wdev->mgmt_registrations_lock);
2583
Johannes Berg98104fde2012-06-16 00:19:54 +02002584 wdev->identifier = ++rdev->wdev_id;
2585 list_add_rcu(&wdev->list, &rdev->wdev_list);
2586 rdev->devlist_generation++;
Johannes Berg98104fde2012-06-16 00:19:54 +02002587 break;
2588 default:
2589 break;
Johannes Berg29cbe682010-12-03 09:20:44 +01002590 }
2591
Eric W. Biederman15e47302012-09-07 20:12:54 +00002592 if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berg1c90f9d2012-06-16 00:05:37 +02002593 rdev, wdev) < 0) {
2594 nlmsg_free(msg);
2595 return -ENOBUFS;
2596 }
2597
2598 return genlmsg_reply(msg, info);
Johannes Berg55682962007-09-20 13:09:35 -04002599}
2600
2601static int nl80211_del_interface(struct sk_buff *skb, struct genl_info *info)
2602{
Johannes Berg4c476992010-10-04 21:36:35 +02002603 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg84efbb82012-06-16 00:00:26 +02002604 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg55682962007-09-20 13:09:35 -04002605
Johannes Berg4c476992010-10-04 21:36:35 +02002606 if (!rdev->ops->del_virtual_intf)
2607 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01002608
Johannes Berg84efbb82012-06-16 00:00:26 +02002609 /*
2610 * If we remove a wireless device without a netdev then clear
2611 * user_ptr[1] so that nl80211_post_doit won't dereference it
2612 * to check if it needs to do dev_put(). Otherwise it crashes
2613 * since the wdev has been freed, unlike with a netdev where
2614 * we need the dev_put() for the netdev to really be freed.
2615 */
2616 if (!wdev->netdev)
2617 info->user_ptr[1] = NULL;
2618
Hila Gonene35e4d22012-06-27 17:19:42 +03002619 return rdev_del_virtual_intf(rdev, wdev);
Johannes Berg55682962007-09-20 13:09:35 -04002620}
2621
Simon Wunderlich1d9d9212011-11-18 14:20:43 +01002622static int nl80211_set_noack_map(struct sk_buff *skb, struct genl_info *info)
2623{
2624 struct cfg80211_registered_device *rdev = info->user_ptr[0];
2625 struct net_device *dev = info->user_ptr[1];
2626 u16 noack_map;
2627
2628 if (!info->attrs[NL80211_ATTR_NOACK_MAP])
2629 return -EINVAL;
2630
2631 if (!rdev->ops->set_noack_map)
2632 return -EOPNOTSUPP;
2633
2634 noack_map = nla_get_u16(info->attrs[NL80211_ATTR_NOACK_MAP]);
2635
Hila Gonene35e4d22012-06-27 17:19:42 +03002636 return rdev_set_noack_map(rdev, dev, noack_map);
Simon Wunderlich1d9d9212011-11-18 14:20:43 +01002637}
2638
Johannes Berg41ade002007-12-19 02:03:29 +01002639struct get_key_cookie {
2640 struct sk_buff *msg;
2641 int error;
Johannes Bergb9454e82009-07-08 13:29:08 +02002642 int idx;
Johannes Berg41ade002007-12-19 02:03:29 +01002643};
2644
2645static void get_key_callback(void *c, struct key_params *params)
2646{
Johannes Bergb9454e82009-07-08 13:29:08 +02002647 struct nlattr *key;
Johannes Berg41ade002007-12-19 02:03:29 +01002648 struct get_key_cookie *cookie = c;
2649
David S. Miller9360ffd2012-03-29 04:41:26 -04002650 if ((params->key &&
2651 nla_put(cookie->msg, NL80211_ATTR_KEY_DATA,
2652 params->key_len, params->key)) ||
2653 (params->seq &&
2654 nla_put(cookie->msg, NL80211_ATTR_KEY_SEQ,
2655 params->seq_len, params->seq)) ||
2656 (params->cipher &&
2657 nla_put_u32(cookie->msg, NL80211_ATTR_KEY_CIPHER,
2658 params->cipher)))
2659 goto nla_put_failure;
Johannes Berg41ade002007-12-19 02:03:29 +01002660
Johannes Bergb9454e82009-07-08 13:29:08 +02002661 key = nla_nest_start(cookie->msg, NL80211_ATTR_KEY);
2662 if (!key)
2663 goto nla_put_failure;
2664
David S. Miller9360ffd2012-03-29 04:41:26 -04002665 if ((params->key &&
2666 nla_put(cookie->msg, NL80211_KEY_DATA,
2667 params->key_len, params->key)) ||
2668 (params->seq &&
2669 nla_put(cookie->msg, NL80211_KEY_SEQ,
2670 params->seq_len, params->seq)) ||
2671 (params->cipher &&
2672 nla_put_u32(cookie->msg, NL80211_KEY_CIPHER,
2673 params->cipher)))
2674 goto nla_put_failure;
Johannes Bergb9454e82009-07-08 13:29:08 +02002675
David S. Miller9360ffd2012-03-29 04:41:26 -04002676 if (nla_put_u8(cookie->msg, NL80211_ATTR_KEY_IDX, cookie->idx))
2677 goto nla_put_failure;
Johannes Bergb9454e82009-07-08 13:29:08 +02002678
2679 nla_nest_end(cookie->msg, key);
2680
Johannes Berg41ade002007-12-19 02:03:29 +01002681 return;
2682 nla_put_failure:
2683 cookie->error = 1;
2684}
2685
2686static int nl80211_get_key(struct sk_buff *skb, struct genl_info *info)
2687{
Johannes Berg4c476992010-10-04 21:36:35 +02002688 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg41ade002007-12-19 02:03:29 +01002689 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02002690 struct net_device *dev = info->user_ptr[1];
Johannes Berg41ade002007-12-19 02:03:29 +01002691 u8 key_idx = 0;
Johannes Berge31b8212010-10-05 19:39:30 +02002692 const u8 *mac_addr = NULL;
2693 bool pairwise;
Johannes Berg41ade002007-12-19 02:03:29 +01002694 struct get_key_cookie cookie = {
2695 .error = 0,
2696 };
2697 void *hdr;
2698 struct sk_buff *msg;
2699
2700 if (info->attrs[NL80211_ATTR_KEY_IDX])
2701 key_idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]);
2702
Jouni Malinen3cfcf6ac2009-01-08 13:32:02 +02002703 if (key_idx > 5)
Johannes Berg41ade002007-12-19 02:03:29 +01002704 return -EINVAL;
2705
2706 if (info->attrs[NL80211_ATTR_MAC])
2707 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
2708
Johannes Berge31b8212010-10-05 19:39:30 +02002709 pairwise = !!mac_addr;
2710 if (info->attrs[NL80211_ATTR_KEY_TYPE]) {
2711 u32 kt = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]);
2712 if (kt >= NUM_NL80211_KEYTYPES)
2713 return -EINVAL;
2714 if (kt != NL80211_KEYTYPE_GROUP &&
2715 kt != NL80211_KEYTYPE_PAIRWISE)
2716 return -EINVAL;
2717 pairwise = kt == NL80211_KEYTYPE_PAIRWISE;
2718 }
2719
Johannes Berg4c476992010-10-04 21:36:35 +02002720 if (!rdev->ops->get_key)
2721 return -EOPNOTSUPP;
Johannes Berg41ade002007-12-19 02:03:29 +01002722
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07002723 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02002724 if (!msg)
2725 return -ENOMEM;
Johannes Berg41ade002007-12-19 02:03:29 +01002726
Eric W. Biederman15e47302012-09-07 20:12:54 +00002727 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berg41ade002007-12-19 02:03:29 +01002728 NL80211_CMD_NEW_KEY);
Dan Carpentercb35fba2013-08-14 14:50:01 +03002729 if (!hdr)
Johannes Berg9fe271a2013-10-25 11:15:12 +02002730 goto nla_put_failure;
Johannes Berg41ade002007-12-19 02:03:29 +01002731
2732 cookie.msg = msg;
Johannes Bergb9454e82009-07-08 13:29:08 +02002733 cookie.idx = key_idx;
Johannes Berg41ade002007-12-19 02:03:29 +01002734
David S. Miller9360ffd2012-03-29 04:41:26 -04002735 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
2736 nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_idx))
2737 goto nla_put_failure;
2738 if (mac_addr &&
2739 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr))
2740 goto nla_put_failure;
Johannes Berg41ade002007-12-19 02:03:29 +01002741
Johannes Berge31b8212010-10-05 19:39:30 +02002742 if (pairwise && mac_addr &&
2743 !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN))
2744 return -ENOENT;
2745
Hila Gonene35e4d22012-06-27 17:19:42 +03002746 err = rdev_get_key(rdev, dev, key_idx, pairwise, mac_addr, &cookie,
2747 get_key_callback);
Johannes Berg41ade002007-12-19 02:03:29 +01002748
2749 if (err)
Niko Jokinen6c95e2a2009-07-15 11:00:53 +03002750 goto free_msg;
Johannes Berg41ade002007-12-19 02:03:29 +01002751
2752 if (cookie.error)
2753 goto nla_put_failure;
2754
2755 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02002756 return genlmsg_reply(msg, info);
Johannes Berg41ade002007-12-19 02:03:29 +01002757
2758 nla_put_failure:
2759 err = -ENOBUFS;
Niko Jokinen6c95e2a2009-07-15 11:00:53 +03002760 free_msg:
Johannes Berg41ade002007-12-19 02:03:29 +01002761 nlmsg_free(msg);
Johannes Berg41ade002007-12-19 02:03:29 +01002762 return err;
2763}
2764
2765static int nl80211_set_key(struct sk_buff *skb, struct genl_info *info)
2766{
Johannes Berg4c476992010-10-04 21:36:35 +02002767 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Bergb9454e82009-07-08 13:29:08 +02002768 struct key_parse key;
Johannes Berg41ade002007-12-19 02:03:29 +01002769 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02002770 struct net_device *dev = info->user_ptr[1];
Johannes Berg41ade002007-12-19 02:03:29 +01002771
Johannes Bergb9454e82009-07-08 13:29:08 +02002772 err = nl80211_parse_key(info, &key);
2773 if (err)
2774 return err;
2775
2776 if (key.idx < 0)
Johannes Berg41ade002007-12-19 02:03:29 +01002777 return -EINVAL;
2778
Johannes Bergb9454e82009-07-08 13:29:08 +02002779 /* only support setting default key */
2780 if (!key.def && !key.defmgmt)
Johannes Berg41ade002007-12-19 02:03:29 +01002781 return -EINVAL;
2782
Johannes Bergfffd0932009-07-08 14:22:54 +02002783 wdev_lock(dev->ieee80211_ptr);
Johannes Bergdbd2fd62010-12-09 19:58:59 +01002784
2785 if (key.def) {
2786 if (!rdev->ops->set_default_key) {
2787 err = -EOPNOTSUPP;
2788 goto out;
2789 }
2790
2791 err = nl80211_key_allowed(dev->ieee80211_ptr);
2792 if (err)
2793 goto out;
2794
Hila Gonene35e4d22012-06-27 17:19:42 +03002795 err = rdev_set_default_key(rdev, dev, key.idx,
Johannes Bergdbd2fd62010-12-09 19:58:59 +01002796 key.def_uni, key.def_multi);
2797
2798 if (err)
2799 goto out;
Johannes Bergfffd0932009-07-08 14:22:54 +02002800
Johannes Berg3d23e342009-09-29 23:27:28 +02002801#ifdef CONFIG_CFG80211_WEXT
Johannes Bergdbd2fd62010-12-09 19:58:59 +01002802 dev->ieee80211_ptr->wext.default_key = key.idx;
Johannes Berg08645122009-05-11 13:54:58 +02002803#endif
Johannes Bergdbd2fd62010-12-09 19:58:59 +01002804 } else {
2805 if (key.def_uni || !key.def_multi) {
2806 err = -EINVAL;
2807 goto out;
2808 }
2809
2810 if (!rdev->ops->set_default_mgmt_key) {
2811 err = -EOPNOTSUPP;
2812 goto out;
2813 }
2814
2815 err = nl80211_key_allowed(dev->ieee80211_ptr);
2816 if (err)
2817 goto out;
2818
Hila Gonene35e4d22012-06-27 17:19:42 +03002819 err = rdev_set_default_mgmt_key(rdev, dev, key.idx);
Johannes Bergdbd2fd62010-12-09 19:58:59 +01002820 if (err)
2821 goto out;
2822
2823#ifdef CONFIG_CFG80211_WEXT
2824 dev->ieee80211_ptr->wext.default_mgmt_key = key.idx;
2825#endif
2826 }
2827
2828 out:
Johannes Bergfffd0932009-07-08 14:22:54 +02002829 wdev_unlock(dev->ieee80211_ptr);
Johannes Berg41ade002007-12-19 02:03:29 +01002830
Johannes Berg41ade002007-12-19 02:03:29 +01002831 return err;
2832}
2833
2834static int nl80211_new_key(struct sk_buff *skb, struct genl_info *info)
2835{
Johannes Berg4c476992010-10-04 21:36:35 +02002836 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Bergfffd0932009-07-08 14:22:54 +02002837 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02002838 struct net_device *dev = info->user_ptr[1];
Johannes Bergb9454e82009-07-08 13:29:08 +02002839 struct key_parse key;
Johannes Berge31b8212010-10-05 19:39:30 +02002840 const u8 *mac_addr = NULL;
Johannes Berg41ade002007-12-19 02:03:29 +01002841
Johannes Bergb9454e82009-07-08 13:29:08 +02002842 err = nl80211_parse_key(info, &key);
2843 if (err)
2844 return err;
Johannes Berg41ade002007-12-19 02:03:29 +01002845
Johannes Bergb9454e82009-07-08 13:29:08 +02002846 if (!key.p.key)
Johannes Berg41ade002007-12-19 02:03:29 +01002847 return -EINVAL;
2848
Johannes Berg41ade002007-12-19 02:03:29 +01002849 if (info->attrs[NL80211_ATTR_MAC])
2850 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
2851
Johannes Berge31b8212010-10-05 19:39:30 +02002852 if (key.type == -1) {
2853 if (mac_addr)
2854 key.type = NL80211_KEYTYPE_PAIRWISE;
2855 else
2856 key.type = NL80211_KEYTYPE_GROUP;
2857 }
2858
2859 /* for now */
2860 if (key.type != NL80211_KEYTYPE_PAIRWISE &&
2861 key.type != NL80211_KEYTYPE_GROUP)
2862 return -EINVAL;
2863
Johannes Berg4c476992010-10-04 21:36:35 +02002864 if (!rdev->ops->add_key)
2865 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01002866
Johannes Berge31b8212010-10-05 19:39:30 +02002867 if (cfg80211_validate_key_settings(rdev, &key.p, key.idx,
2868 key.type == NL80211_KEYTYPE_PAIRWISE,
2869 mac_addr))
Johannes Berg4c476992010-10-04 21:36:35 +02002870 return -EINVAL;
Johannes Bergfffd0932009-07-08 14:22:54 +02002871
2872 wdev_lock(dev->ieee80211_ptr);
2873 err = nl80211_key_allowed(dev->ieee80211_ptr);
2874 if (!err)
Hila Gonene35e4d22012-06-27 17:19:42 +03002875 err = rdev_add_key(rdev, dev, key.idx,
2876 key.type == NL80211_KEYTYPE_PAIRWISE,
2877 mac_addr, &key.p);
Johannes Bergfffd0932009-07-08 14:22:54 +02002878 wdev_unlock(dev->ieee80211_ptr);
Johannes Berg41ade002007-12-19 02:03:29 +01002879
Johannes Berg41ade002007-12-19 02:03:29 +01002880 return err;
2881}
2882
2883static int nl80211_del_key(struct sk_buff *skb, struct genl_info *info)
2884{
Johannes Berg4c476992010-10-04 21:36:35 +02002885 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg41ade002007-12-19 02:03:29 +01002886 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02002887 struct net_device *dev = info->user_ptr[1];
Johannes Berg41ade002007-12-19 02:03:29 +01002888 u8 *mac_addr = NULL;
Johannes Bergb9454e82009-07-08 13:29:08 +02002889 struct key_parse key;
Johannes Berg41ade002007-12-19 02:03:29 +01002890
Johannes Bergb9454e82009-07-08 13:29:08 +02002891 err = nl80211_parse_key(info, &key);
2892 if (err)
2893 return err;
Johannes Berg41ade002007-12-19 02:03:29 +01002894
2895 if (info->attrs[NL80211_ATTR_MAC])
2896 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
2897
Johannes Berge31b8212010-10-05 19:39:30 +02002898 if (key.type == -1) {
2899 if (mac_addr)
2900 key.type = NL80211_KEYTYPE_PAIRWISE;
2901 else
2902 key.type = NL80211_KEYTYPE_GROUP;
2903 }
2904
2905 /* for now */
2906 if (key.type != NL80211_KEYTYPE_PAIRWISE &&
2907 key.type != NL80211_KEYTYPE_GROUP)
2908 return -EINVAL;
2909
Johannes Berg4c476992010-10-04 21:36:35 +02002910 if (!rdev->ops->del_key)
2911 return -EOPNOTSUPP;
Johannes Berg41ade002007-12-19 02:03:29 +01002912
Johannes Bergfffd0932009-07-08 14:22:54 +02002913 wdev_lock(dev->ieee80211_ptr);
2914 err = nl80211_key_allowed(dev->ieee80211_ptr);
Johannes Berge31b8212010-10-05 19:39:30 +02002915
2916 if (key.type == NL80211_KEYTYPE_PAIRWISE && mac_addr &&
2917 !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN))
2918 err = -ENOENT;
2919
Johannes Bergfffd0932009-07-08 14:22:54 +02002920 if (!err)
Hila Gonene35e4d22012-06-27 17:19:42 +03002921 err = rdev_del_key(rdev, dev, key.idx,
2922 key.type == NL80211_KEYTYPE_PAIRWISE,
2923 mac_addr);
Johannes Berg41ade002007-12-19 02:03:29 +01002924
Johannes Berg3d23e342009-09-29 23:27:28 +02002925#ifdef CONFIG_CFG80211_WEXT
Johannes Berg08645122009-05-11 13:54:58 +02002926 if (!err) {
Johannes Bergb9454e82009-07-08 13:29:08 +02002927 if (key.idx == dev->ieee80211_ptr->wext.default_key)
Johannes Berg08645122009-05-11 13:54:58 +02002928 dev->ieee80211_ptr->wext.default_key = -1;
Johannes Bergb9454e82009-07-08 13:29:08 +02002929 else if (key.idx == dev->ieee80211_ptr->wext.default_mgmt_key)
Johannes Berg08645122009-05-11 13:54:58 +02002930 dev->ieee80211_ptr->wext.default_mgmt_key = -1;
2931 }
2932#endif
Johannes Bergfffd0932009-07-08 14:22:54 +02002933 wdev_unlock(dev->ieee80211_ptr);
Johannes Berg08645122009-05-11 13:54:58 +02002934
Johannes Berg41ade002007-12-19 02:03:29 +01002935 return err;
2936}
2937
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +05302938/* This function returns an error or the number of nested attributes */
2939static int validate_acl_mac_addrs(struct nlattr *nl_attr)
2940{
2941 struct nlattr *attr;
2942 int n_entries = 0, tmp;
2943
2944 nla_for_each_nested(attr, nl_attr, tmp) {
2945 if (nla_len(attr) != ETH_ALEN)
2946 return -EINVAL;
2947
2948 n_entries++;
2949 }
2950
2951 return n_entries;
2952}
2953
2954/*
2955 * This function parses ACL information and allocates memory for ACL data.
2956 * On successful return, the calling function is responsible to free the
2957 * ACL buffer returned by this function.
2958 */
2959static struct cfg80211_acl_data *parse_acl_data(struct wiphy *wiphy,
2960 struct genl_info *info)
2961{
2962 enum nl80211_acl_policy acl_policy;
2963 struct nlattr *attr;
2964 struct cfg80211_acl_data *acl;
2965 int i = 0, n_entries, tmp;
2966
2967 if (!wiphy->max_acl_mac_addrs)
2968 return ERR_PTR(-EOPNOTSUPP);
2969
2970 if (!info->attrs[NL80211_ATTR_ACL_POLICY])
2971 return ERR_PTR(-EINVAL);
2972
2973 acl_policy = nla_get_u32(info->attrs[NL80211_ATTR_ACL_POLICY]);
2974 if (acl_policy != NL80211_ACL_POLICY_ACCEPT_UNLESS_LISTED &&
2975 acl_policy != NL80211_ACL_POLICY_DENY_UNLESS_LISTED)
2976 return ERR_PTR(-EINVAL);
2977
2978 if (!info->attrs[NL80211_ATTR_MAC_ADDRS])
2979 return ERR_PTR(-EINVAL);
2980
2981 n_entries = validate_acl_mac_addrs(info->attrs[NL80211_ATTR_MAC_ADDRS]);
2982 if (n_entries < 0)
2983 return ERR_PTR(n_entries);
2984
2985 if (n_entries > wiphy->max_acl_mac_addrs)
2986 return ERR_PTR(-ENOTSUPP);
2987
2988 acl = kzalloc(sizeof(*acl) + (sizeof(struct mac_address) * n_entries),
2989 GFP_KERNEL);
2990 if (!acl)
2991 return ERR_PTR(-ENOMEM);
2992
2993 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_MAC_ADDRS], tmp) {
2994 memcpy(acl->mac_addrs[i].addr, nla_data(attr), ETH_ALEN);
2995 i++;
2996 }
2997
2998 acl->n_acl_entries = n_entries;
2999 acl->acl_policy = acl_policy;
3000
3001 return acl;
3002}
3003
3004static int nl80211_set_mac_acl(struct sk_buff *skb, struct genl_info *info)
3005{
3006 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3007 struct net_device *dev = info->user_ptr[1];
3008 struct cfg80211_acl_data *acl;
3009 int err;
3010
3011 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
3012 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
3013 return -EOPNOTSUPP;
3014
3015 if (!dev->ieee80211_ptr->beacon_interval)
3016 return -EINVAL;
3017
3018 acl = parse_acl_data(&rdev->wiphy, info);
3019 if (IS_ERR(acl))
3020 return PTR_ERR(acl);
3021
3022 err = rdev_set_mac_acl(rdev, dev, acl);
3023
3024 kfree(acl);
3025
3026 return err;
3027}
3028
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003029static int nl80211_parse_beacon(struct nlattr *attrs[],
Johannes Berg88600202012-02-13 15:17:18 +01003030 struct cfg80211_beacon_data *bcn)
Johannes Berged1b6cc2007-12-19 02:03:32 +01003031{
Johannes Berg88600202012-02-13 15:17:18 +01003032 bool haveinfo = false;
Johannes Berged1b6cc2007-12-19 02:03:32 +01003033
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003034 if (!is_valid_ie_attr(attrs[NL80211_ATTR_BEACON_TAIL]) ||
3035 !is_valid_ie_attr(attrs[NL80211_ATTR_IE]) ||
3036 !is_valid_ie_attr(attrs[NL80211_ATTR_IE_PROBE_RESP]) ||
3037 !is_valid_ie_attr(attrs[NL80211_ATTR_IE_ASSOC_RESP]))
Johannes Bergf4a11bb2009-03-27 12:40:28 +01003038 return -EINVAL;
3039
Johannes Berg88600202012-02-13 15:17:18 +01003040 memset(bcn, 0, sizeof(*bcn));
Johannes Berged1b6cc2007-12-19 02:03:32 +01003041
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003042 if (attrs[NL80211_ATTR_BEACON_HEAD]) {
3043 bcn->head = nla_data(attrs[NL80211_ATTR_BEACON_HEAD]);
3044 bcn->head_len = nla_len(attrs[NL80211_ATTR_BEACON_HEAD]);
Johannes Berg88600202012-02-13 15:17:18 +01003045 if (!bcn->head_len)
3046 return -EINVAL;
3047 haveinfo = true;
Johannes Berged1b6cc2007-12-19 02:03:32 +01003048 }
3049
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003050 if (attrs[NL80211_ATTR_BEACON_TAIL]) {
3051 bcn->tail = nla_data(attrs[NL80211_ATTR_BEACON_TAIL]);
3052 bcn->tail_len = nla_len(attrs[NL80211_ATTR_BEACON_TAIL]);
Johannes Berg88600202012-02-13 15:17:18 +01003053 haveinfo = true;
Johannes Berged1b6cc2007-12-19 02:03:32 +01003054 }
3055
Johannes Berg4c476992010-10-04 21:36:35 +02003056 if (!haveinfo)
3057 return -EINVAL;
Johannes Berged1b6cc2007-12-19 02:03:32 +01003058
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003059 if (attrs[NL80211_ATTR_IE]) {
3060 bcn->beacon_ies = nla_data(attrs[NL80211_ATTR_IE]);
3061 bcn->beacon_ies_len = nla_len(attrs[NL80211_ATTR_IE]);
Jouni Malinen9946ecf2011-08-10 23:55:56 +03003062 }
3063
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003064 if (attrs[NL80211_ATTR_IE_PROBE_RESP]) {
Johannes Berg88600202012-02-13 15:17:18 +01003065 bcn->proberesp_ies =
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003066 nla_data(attrs[NL80211_ATTR_IE_PROBE_RESP]);
Johannes Berg88600202012-02-13 15:17:18 +01003067 bcn->proberesp_ies_len =
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003068 nla_len(attrs[NL80211_ATTR_IE_PROBE_RESP]);
Jouni Malinen9946ecf2011-08-10 23:55:56 +03003069 }
3070
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003071 if (attrs[NL80211_ATTR_IE_ASSOC_RESP]) {
Johannes Berg88600202012-02-13 15:17:18 +01003072 bcn->assocresp_ies =
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003073 nla_data(attrs[NL80211_ATTR_IE_ASSOC_RESP]);
Johannes Berg88600202012-02-13 15:17:18 +01003074 bcn->assocresp_ies_len =
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003075 nla_len(attrs[NL80211_ATTR_IE_ASSOC_RESP]);
Jouni Malinen9946ecf2011-08-10 23:55:56 +03003076 }
3077
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003078 if (attrs[NL80211_ATTR_PROBE_RESP]) {
3079 bcn->probe_resp = nla_data(attrs[NL80211_ATTR_PROBE_RESP]);
3080 bcn->probe_resp_len = nla_len(attrs[NL80211_ATTR_PROBE_RESP]);
Arik Nemtsov00f740e2011-11-10 11:28:56 +02003081 }
3082
Johannes Berg88600202012-02-13 15:17:18 +01003083 return 0;
3084}
3085
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003086static bool nl80211_get_ap_channel(struct cfg80211_registered_device *rdev,
3087 struct cfg80211_ap_settings *params)
3088{
3089 struct wireless_dev *wdev;
3090 bool ret = false;
3091
Johannes Berg89a54e42012-06-15 14:33:17 +02003092 list_for_each_entry(wdev, &rdev->wdev_list, list) {
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003093 if (wdev->iftype != NL80211_IFTYPE_AP &&
3094 wdev->iftype != NL80211_IFTYPE_P2P_GO)
3095 continue;
3096
Johannes Berg683b6d32012-11-08 21:25:48 +01003097 if (!wdev->preset_chandef.chan)
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003098 continue;
3099
Johannes Berg683b6d32012-11-08 21:25:48 +01003100 params->chandef = wdev->preset_chandef;
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003101 ret = true;
3102 break;
3103 }
3104
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003105 return ret;
3106}
3107
Jouni Malinene39e5b52012-09-30 19:29:39 +03003108static bool nl80211_valid_auth_type(struct cfg80211_registered_device *rdev,
3109 enum nl80211_auth_type auth_type,
3110 enum nl80211_commands cmd)
3111{
3112 if (auth_type > NL80211_AUTHTYPE_MAX)
3113 return false;
3114
3115 switch (cmd) {
3116 case NL80211_CMD_AUTHENTICATE:
3117 if (!(rdev->wiphy.features & NL80211_FEATURE_SAE) &&
3118 auth_type == NL80211_AUTHTYPE_SAE)
3119 return false;
3120 return true;
3121 case NL80211_CMD_CONNECT:
3122 case NL80211_CMD_START_AP:
3123 /* SAE not supported yet */
3124 if (auth_type == NL80211_AUTHTYPE_SAE)
3125 return false;
3126 return true;
3127 default:
3128 return false;
3129 }
3130}
3131
Johannes Berg88600202012-02-13 15:17:18 +01003132static int nl80211_start_ap(struct sk_buff *skb, struct genl_info *info)
3133{
3134 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3135 struct net_device *dev = info->user_ptr[1];
3136 struct wireless_dev *wdev = dev->ieee80211_ptr;
3137 struct cfg80211_ap_settings params;
3138 int err;
Simon Wunderlich04f39042013-02-08 18:16:19 +01003139 u8 radar_detect_width = 0;
Johannes Berg88600202012-02-13 15:17:18 +01003140
3141 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
3142 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
3143 return -EOPNOTSUPP;
3144
3145 if (!rdev->ops->start_ap)
3146 return -EOPNOTSUPP;
3147
3148 if (wdev->beacon_interval)
3149 return -EALREADY;
3150
3151 memset(&params, 0, sizeof(params));
3152
3153 /* these are required for START_AP */
3154 if (!info->attrs[NL80211_ATTR_BEACON_INTERVAL] ||
3155 !info->attrs[NL80211_ATTR_DTIM_PERIOD] ||
3156 !info->attrs[NL80211_ATTR_BEACON_HEAD])
3157 return -EINVAL;
3158
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003159 err = nl80211_parse_beacon(info->attrs, &params.beacon);
Johannes Berg88600202012-02-13 15:17:18 +01003160 if (err)
3161 return err;
3162
3163 params.beacon_interval =
3164 nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]);
3165 params.dtim_period =
3166 nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]);
3167
3168 err = cfg80211_validate_beacon_int(rdev, params.beacon_interval);
3169 if (err)
3170 return err;
3171
3172 /*
3173 * In theory, some of these attributes should be required here
3174 * but since they were not used when the command was originally
3175 * added, keep them optional for old user space programs to let
3176 * them continue to work with drivers that do not need the
3177 * additional information -- drivers must check!
3178 */
3179 if (info->attrs[NL80211_ATTR_SSID]) {
3180 params.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
3181 params.ssid_len =
3182 nla_len(info->attrs[NL80211_ATTR_SSID]);
3183 if (params.ssid_len == 0 ||
3184 params.ssid_len > IEEE80211_MAX_SSID_LEN)
3185 return -EINVAL;
3186 }
3187
3188 if (info->attrs[NL80211_ATTR_HIDDEN_SSID]) {
3189 params.hidden_ssid = nla_get_u32(
3190 info->attrs[NL80211_ATTR_HIDDEN_SSID]);
3191 if (params.hidden_ssid != NL80211_HIDDEN_SSID_NOT_IN_USE &&
3192 params.hidden_ssid != NL80211_HIDDEN_SSID_ZERO_LEN &&
3193 params.hidden_ssid != NL80211_HIDDEN_SSID_ZERO_CONTENTS)
3194 return -EINVAL;
3195 }
3196
3197 params.privacy = !!info->attrs[NL80211_ATTR_PRIVACY];
3198
3199 if (info->attrs[NL80211_ATTR_AUTH_TYPE]) {
3200 params.auth_type = nla_get_u32(
3201 info->attrs[NL80211_ATTR_AUTH_TYPE]);
Jouni Malinene39e5b52012-09-30 19:29:39 +03003202 if (!nl80211_valid_auth_type(rdev, params.auth_type,
3203 NL80211_CMD_START_AP))
Johannes Berg88600202012-02-13 15:17:18 +01003204 return -EINVAL;
3205 } else
3206 params.auth_type = NL80211_AUTHTYPE_AUTOMATIC;
3207
3208 err = nl80211_crypto_settings(rdev, info, &params.crypto,
3209 NL80211_MAX_NR_CIPHER_SUITES);
3210 if (err)
3211 return err;
3212
Vasanthakumar Thiagarajan1b658f12012-03-02 15:50:02 +05303213 if (info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]) {
3214 if (!(rdev->wiphy.features & NL80211_FEATURE_INACTIVITY_TIMER))
3215 return -EOPNOTSUPP;
3216 params.inactivity_timeout = nla_get_u16(
3217 info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]);
3218 }
3219
Johannes Berg53cabad2012-11-14 15:17:28 +01003220 if (info->attrs[NL80211_ATTR_P2P_CTWINDOW]) {
3221 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
3222 return -EINVAL;
3223 params.p2p_ctwindow =
3224 nla_get_u8(info->attrs[NL80211_ATTR_P2P_CTWINDOW]);
3225 if (params.p2p_ctwindow > 127)
3226 return -EINVAL;
3227 if (params.p2p_ctwindow != 0 &&
3228 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_CTWIN))
3229 return -EINVAL;
3230 }
3231
3232 if (info->attrs[NL80211_ATTR_P2P_OPPPS]) {
3233 u8 tmp;
3234
3235 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
3236 return -EINVAL;
3237 tmp = nla_get_u8(info->attrs[NL80211_ATTR_P2P_OPPPS]);
3238 if (tmp > 1)
3239 return -EINVAL;
3240 params.p2p_opp_ps = tmp;
3241 if (params.p2p_opp_ps != 0 &&
3242 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_OPPPS))
3243 return -EINVAL;
3244 }
3245
Johannes Bergaa430da2012-05-16 23:50:18 +02003246 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
Johannes Berg683b6d32012-11-08 21:25:48 +01003247 err = nl80211_parse_chandef(rdev, info, &params.chandef);
3248 if (err)
3249 return err;
3250 } else if (wdev->preset_chandef.chan) {
3251 params.chandef = wdev->preset_chandef;
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003252 } else if (!nl80211_get_ap_channel(rdev, &params))
Johannes Bergaa430da2012-05-16 23:50:18 +02003253 return -EINVAL;
3254
Johannes Berg683b6d32012-11-08 21:25:48 +01003255 if (!cfg80211_reg_can_beacon(&rdev->wiphy, &params.chandef))
Johannes Bergaa430da2012-05-16 23:50:18 +02003256 return -EINVAL;
3257
Simon Wunderlich04f39042013-02-08 18:16:19 +01003258 err = cfg80211_chandef_dfs_required(wdev->wiphy, &params.chandef);
3259 if (err < 0)
3260 return err;
3261 if (err) {
3262 radar_detect_width = BIT(params.chandef.width);
3263 params.radar_required = true;
3264 }
3265
Simon Wunderlich04f39042013-02-08 18:16:19 +01003266 err = cfg80211_can_use_iftype_chan(rdev, wdev, wdev->iftype,
3267 params.chandef.chan,
3268 CHAN_MODE_SHARED,
3269 radar_detect_width);
Michal Kaziore4e32452012-06-29 12:47:08 +02003270 if (err)
3271 return err;
3272
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +05303273 if (info->attrs[NL80211_ATTR_ACL_POLICY]) {
3274 params.acl = parse_acl_data(&rdev->wiphy, info);
3275 if (IS_ERR(params.acl))
3276 return PTR_ERR(params.acl);
3277 }
3278
Simon Wunderlichc56589e2013-11-21 18:19:49 +01003279 wdev_lock(wdev);
Hila Gonene35e4d22012-06-27 17:19:42 +03003280 err = rdev_start_ap(rdev, dev, &params);
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003281 if (!err) {
Johannes Berg683b6d32012-11-08 21:25:48 +01003282 wdev->preset_chandef = params.chandef;
Johannes Berg88600202012-02-13 15:17:18 +01003283 wdev->beacon_interval = params.beacon_interval;
Johannes Berg683b6d32012-11-08 21:25:48 +01003284 wdev->channel = params.chandef.chan;
Antonio Quartulli06e191e2012-11-07 12:52:19 +01003285 wdev->ssid_len = params.ssid_len;
3286 memcpy(wdev->ssid, params.ssid, wdev->ssid_len);
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003287 }
Simon Wunderlichc56589e2013-11-21 18:19:49 +01003288 wdev_unlock(wdev);
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +05303289
3290 kfree(params.acl);
3291
Johannes Berg56d18932011-05-09 18:41:15 +02003292 return err;
Johannes Berged1b6cc2007-12-19 02:03:32 +01003293}
3294
Johannes Berg88600202012-02-13 15:17:18 +01003295static int nl80211_set_beacon(struct sk_buff *skb, struct genl_info *info)
3296{
3297 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3298 struct net_device *dev = info->user_ptr[1];
3299 struct wireless_dev *wdev = dev->ieee80211_ptr;
3300 struct cfg80211_beacon_data params;
3301 int err;
3302
3303 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
3304 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
3305 return -EOPNOTSUPP;
3306
3307 if (!rdev->ops->change_beacon)
3308 return -EOPNOTSUPP;
3309
3310 if (!wdev->beacon_interval)
3311 return -EINVAL;
3312
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003313 err = nl80211_parse_beacon(info->attrs, &params);
Johannes Berg88600202012-02-13 15:17:18 +01003314 if (err)
3315 return err;
3316
Simon Wunderlichc56589e2013-11-21 18:19:49 +01003317 wdev_lock(wdev);
3318 err = rdev_change_beacon(rdev, dev, &params);
3319 wdev_unlock(wdev);
3320
3321 return err;
Johannes Berg88600202012-02-13 15:17:18 +01003322}
3323
3324static int nl80211_stop_ap(struct sk_buff *skb, struct genl_info *info)
Johannes Berged1b6cc2007-12-19 02:03:32 +01003325{
Johannes Berg4c476992010-10-04 21:36:35 +02003326 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3327 struct net_device *dev = info->user_ptr[1];
Johannes Berged1b6cc2007-12-19 02:03:32 +01003328
Michal Kazior60771782012-06-29 12:46:56 +02003329 return cfg80211_stop_ap(rdev, dev);
Johannes Berged1b6cc2007-12-19 02:03:32 +01003330}
3331
Johannes Berg5727ef12007-12-19 02:03:34 +01003332static const struct nla_policy sta_flags_policy[NL80211_STA_FLAG_MAX + 1] = {
3333 [NL80211_STA_FLAG_AUTHORIZED] = { .type = NLA_FLAG },
3334 [NL80211_STA_FLAG_SHORT_PREAMBLE] = { .type = NLA_FLAG },
3335 [NL80211_STA_FLAG_WME] = { .type = NLA_FLAG },
Jouni Malinen0e467242009-05-11 21:57:55 +03003336 [NL80211_STA_FLAG_MFP] = { .type = NLA_FLAG },
Javier Cardonab39c48f2011-04-07 15:08:30 -07003337 [NL80211_STA_FLAG_AUTHENTICATED] = { .type = NLA_FLAG },
Johannes Bergd83023d2011-12-14 09:29:15 +01003338 [NL80211_STA_FLAG_TDLS_PEER] = { .type = NLA_FLAG },
Johannes Berg5727ef12007-12-19 02:03:34 +01003339};
3340
Johannes Bergeccb8e82009-05-11 21:57:56 +03003341static int parse_station_flags(struct genl_info *info,
Johannes Bergbdd3ae32012-01-02 13:30:03 +01003342 enum nl80211_iftype iftype,
Johannes Bergeccb8e82009-05-11 21:57:56 +03003343 struct station_parameters *params)
Johannes Berg5727ef12007-12-19 02:03:34 +01003344{
3345 struct nlattr *flags[NL80211_STA_FLAG_MAX + 1];
Johannes Bergeccb8e82009-05-11 21:57:56 +03003346 struct nlattr *nla;
Johannes Berg5727ef12007-12-19 02:03:34 +01003347 int flag;
3348
Johannes Bergeccb8e82009-05-11 21:57:56 +03003349 /*
3350 * Try parsing the new attribute first so userspace
3351 * can specify both for older kernels.
3352 */
3353 nla = info->attrs[NL80211_ATTR_STA_FLAGS2];
3354 if (nla) {
3355 struct nl80211_sta_flag_update *sta_flags;
Johannes Berg5727ef12007-12-19 02:03:34 +01003356
Johannes Bergeccb8e82009-05-11 21:57:56 +03003357 sta_flags = nla_data(nla);
3358 params->sta_flags_mask = sta_flags->mask;
3359 params->sta_flags_set = sta_flags->set;
Johannes Berg77ee7c82013-02-15 00:48:33 +01003360 params->sta_flags_set &= params->sta_flags_mask;
Johannes Bergeccb8e82009-05-11 21:57:56 +03003361 if ((params->sta_flags_mask |
3362 params->sta_flags_set) & BIT(__NL80211_STA_FLAG_INVALID))
3363 return -EINVAL;
3364 return 0;
3365 }
3366
3367 /* if present, parse the old attribute */
3368
3369 nla = info->attrs[NL80211_ATTR_STA_FLAGS];
Johannes Berg5727ef12007-12-19 02:03:34 +01003370 if (!nla)
3371 return 0;
3372
3373 if (nla_parse_nested(flags, NL80211_STA_FLAG_MAX,
3374 nla, sta_flags_policy))
3375 return -EINVAL;
3376
Johannes Bergbdd3ae32012-01-02 13:30:03 +01003377 /*
3378 * Only allow certain flags for interface types so that
3379 * other attributes are silently ignored. Remember that
3380 * this is backward compatibility code with old userspace
3381 * and shouldn't be hit in other cases anyway.
3382 */
3383 switch (iftype) {
3384 case NL80211_IFTYPE_AP:
3385 case NL80211_IFTYPE_AP_VLAN:
3386 case NL80211_IFTYPE_P2P_GO:
3387 params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) |
3388 BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) |
3389 BIT(NL80211_STA_FLAG_WME) |
3390 BIT(NL80211_STA_FLAG_MFP);
3391 break;
3392 case NL80211_IFTYPE_P2P_CLIENT:
3393 case NL80211_IFTYPE_STATION:
3394 params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) |
3395 BIT(NL80211_STA_FLAG_TDLS_PEER);
3396 break;
3397 case NL80211_IFTYPE_MESH_POINT:
3398 params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHENTICATED) |
3399 BIT(NL80211_STA_FLAG_MFP) |
3400 BIT(NL80211_STA_FLAG_AUTHORIZED);
3401 default:
3402 return -EINVAL;
3403 }
Johannes Berg5727ef12007-12-19 02:03:34 +01003404
Johannes Berg3383b5a2012-05-10 20:14:43 +02003405 for (flag = 1; flag <= NL80211_STA_FLAG_MAX; flag++) {
3406 if (flags[flag]) {
Johannes Bergeccb8e82009-05-11 21:57:56 +03003407 params->sta_flags_set |= (1<<flag);
Johannes Berg5727ef12007-12-19 02:03:34 +01003408
Johannes Berg3383b5a2012-05-10 20:14:43 +02003409 /* no longer support new API additions in old API */
3410 if (flag > NL80211_STA_FLAG_MAX_OLD_API)
3411 return -EINVAL;
3412 }
3413 }
3414
Johannes Berg5727ef12007-12-19 02:03:34 +01003415 return 0;
3416}
3417
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003418static bool nl80211_put_sta_rate(struct sk_buff *msg, struct rate_info *info,
3419 int attr)
3420{
3421 struct nlattr *rate;
Vladimir Kondratiev8eb41c82012-07-05 14:25:49 +03003422 u32 bitrate;
3423 u16 bitrate_compat;
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003424
3425 rate = nla_nest_start(msg, attr);
3426 if (!rate)
Johannes Bergdb9c64c2012-11-09 14:56:41 +01003427 return false;
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003428
3429 /* cfg80211_calculate_bitrate will return 0 for mcs >= 32 */
3430 bitrate = cfg80211_calculate_bitrate(info);
Vladimir Kondratiev8eb41c82012-07-05 14:25:49 +03003431 /* report 16-bit bitrate only if we can */
3432 bitrate_compat = bitrate < (1UL << 16) ? bitrate : 0;
Johannes Bergdb9c64c2012-11-09 14:56:41 +01003433 if (bitrate > 0 &&
3434 nla_put_u32(msg, NL80211_RATE_INFO_BITRATE32, bitrate))
3435 return false;
3436 if (bitrate_compat > 0 &&
3437 nla_put_u16(msg, NL80211_RATE_INFO_BITRATE, bitrate_compat))
3438 return false;
3439
3440 if (info->flags & RATE_INFO_FLAGS_MCS) {
3441 if (nla_put_u8(msg, NL80211_RATE_INFO_MCS, info->mcs))
3442 return false;
3443 if (info->flags & RATE_INFO_FLAGS_40_MHZ_WIDTH &&
3444 nla_put_flag(msg, NL80211_RATE_INFO_40_MHZ_WIDTH))
3445 return false;
3446 if (info->flags & RATE_INFO_FLAGS_SHORT_GI &&
3447 nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI))
3448 return false;
3449 } else if (info->flags & RATE_INFO_FLAGS_VHT_MCS) {
3450 if (nla_put_u8(msg, NL80211_RATE_INFO_VHT_MCS, info->mcs))
3451 return false;
3452 if (nla_put_u8(msg, NL80211_RATE_INFO_VHT_NSS, info->nss))
3453 return false;
3454 if (info->flags & RATE_INFO_FLAGS_40_MHZ_WIDTH &&
3455 nla_put_flag(msg, NL80211_RATE_INFO_40_MHZ_WIDTH))
3456 return false;
3457 if (info->flags & RATE_INFO_FLAGS_80_MHZ_WIDTH &&
3458 nla_put_flag(msg, NL80211_RATE_INFO_80_MHZ_WIDTH))
3459 return false;
3460 if (info->flags & RATE_INFO_FLAGS_80P80_MHZ_WIDTH &&
3461 nla_put_flag(msg, NL80211_RATE_INFO_80P80_MHZ_WIDTH))
3462 return false;
3463 if (info->flags & RATE_INFO_FLAGS_160_MHZ_WIDTH &&
3464 nla_put_flag(msg, NL80211_RATE_INFO_160_MHZ_WIDTH))
3465 return false;
3466 if (info->flags & RATE_INFO_FLAGS_SHORT_GI &&
3467 nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI))
3468 return false;
3469 }
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003470
3471 nla_nest_end(msg, rate);
3472 return true;
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003473}
3474
Felix Fietkau119363c2013-04-22 16:29:30 +02003475static bool nl80211_put_signal(struct sk_buff *msg, u8 mask, s8 *signal,
3476 int id)
3477{
3478 void *attr;
3479 int i = 0;
3480
3481 if (!mask)
3482 return true;
3483
3484 attr = nla_nest_start(msg, id);
3485 if (!attr)
3486 return false;
3487
3488 for (i = 0; i < IEEE80211_MAX_CHAINS; i++) {
3489 if (!(mask & BIT(i)))
3490 continue;
3491
3492 if (nla_put_u8(msg, i, signal[i]))
3493 return false;
3494 }
3495
3496 nla_nest_end(msg, attr);
3497
3498 return true;
3499}
3500
Eric W. Biederman15e47302012-09-07 20:12:54 +00003501static int nl80211_send_station(struct sk_buff *msg, u32 portid, u32 seq,
John W. Linville66266b32012-03-15 13:25:41 -04003502 int flags,
3503 struct cfg80211_registered_device *rdev,
3504 struct net_device *dev,
Johannes Berg98b62182009-12-23 13:15:44 +01003505 const u8 *mac_addr, struct station_info *sinfo)
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003506{
3507 void *hdr;
Paul Stewartf4263c92011-03-31 09:25:41 -07003508 struct nlattr *sinfoattr, *bss_param;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003509
Eric W. Biederman15e47302012-09-07 20:12:54 +00003510 hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_STATION);
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003511 if (!hdr)
3512 return -1;
3513
David S. Miller9360ffd2012-03-29 04:41:26 -04003514 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
3515 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) ||
3516 nla_put_u32(msg, NL80211_ATTR_GENERATION, sinfo->generation))
3517 goto nla_put_failure;
Johannes Bergf5ea9122009-08-07 16:17:38 +02003518
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003519 sinfoattr = nla_nest_start(msg, NL80211_ATTR_STA_INFO);
3520 if (!sinfoattr)
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003521 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04003522 if ((sinfo->filled & STATION_INFO_CONNECTED_TIME) &&
3523 nla_put_u32(msg, NL80211_STA_INFO_CONNECTED_TIME,
3524 sinfo->connected_time))
3525 goto nla_put_failure;
3526 if ((sinfo->filled & STATION_INFO_INACTIVE_TIME) &&
3527 nla_put_u32(msg, NL80211_STA_INFO_INACTIVE_TIME,
3528 sinfo->inactive_time))
3529 goto nla_put_failure;
Vladimir Kondratiev42745e02013-02-04 13:53:11 +02003530 if ((sinfo->filled & (STATION_INFO_RX_BYTES |
3531 STATION_INFO_RX_BYTES64)) &&
David S. Miller9360ffd2012-03-29 04:41:26 -04003532 nla_put_u32(msg, NL80211_STA_INFO_RX_BYTES,
Vladimir Kondratiev42745e02013-02-04 13:53:11 +02003533 (u32)sinfo->rx_bytes))
3534 goto nla_put_failure;
3535 if ((sinfo->filled & (STATION_INFO_TX_BYTES |
Felix Fietkau4325d722013-05-23 15:05:59 +02003536 STATION_INFO_TX_BYTES64)) &&
Vladimir Kondratiev42745e02013-02-04 13:53:11 +02003537 nla_put_u32(msg, NL80211_STA_INFO_TX_BYTES,
3538 (u32)sinfo->tx_bytes))
3539 goto nla_put_failure;
3540 if ((sinfo->filled & STATION_INFO_RX_BYTES64) &&
3541 nla_put_u64(msg, NL80211_STA_INFO_RX_BYTES64,
David S. Miller9360ffd2012-03-29 04:41:26 -04003542 sinfo->rx_bytes))
3543 goto nla_put_failure;
Vladimir Kondratiev42745e02013-02-04 13:53:11 +02003544 if ((sinfo->filled & STATION_INFO_TX_BYTES64) &&
3545 nla_put_u64(msg, NL80211_STA_INFO_TX_BYTES64,
David S. Miller9360ffd2012-03-29 04:41:26 -04003546 sinfo->tx_bytes))
3547 goto nla_put_failure;
3548 if ((sinfo->filled & STATION_INFO_LLID) &&
3549 nla_put_u16(msg, NL80211_STA_INFO_LLID, sinfo->llid))
3550 goto nla_put_failure;
3551 if ((sinfo->filled & STATION_INFO_PLID) &&
3552 nla_put_u16(msg, NL80211_STA_INFO_PLID, sinfo->plid))
3553 goto nla_put_failure;
3554 if ((sinfo->filled & STATION_INFO_PLINK_STATE) &&
3555 nla_put_u8(msg, NL80211_STA_INFO_PLINK_STATE,
3556 sinfo->plink_state))
3557 goto nla_put_failure;
John W. Linville66266b32012-03-15 13:25:41 -04003558 switch (rdev->wiphy.signal_type) {
3559 case CFG80211_SIGNAL_TYPE_MBM:
David S. Miller9360ffd2012-03-29 04:41:26 -04003560 if ((sinfo->filled & STATION_INFO_SIGNAL) &&
3561 nla_put_u8(msg, NL80211_STA_INFO_SIGNAL,
3562 sinfo->signal))
3563 goto nla_put_failure;
3564 if ((sinfo->filled & STATION_INFO_SIGNAL_AVG) &&
3565 nla_put_u8(msg, NL80211_STA_INFO_SIGNAL_AVG,
3566 sinfo->signal_avg))
3567 goto nla_put_failure;
John W. Linville66266b32012-03-15 13:25:41 -04003568 break;
3569 default:
3570 break;
3571 }
Felix Fietkau119363c2013-04-22 16:29:30 +02003572 if (sinfo->filled & STATION_INFO_CHAIN_SIGNAL) {
3573 if (!nl80211_put_signal(msg, sinfo->chains,
3574 sinfo->chain_signal,
3575 NL80211_STA_INFO_CHAIN_SIGNAL))
3576 goto nla_put_failure;
3577 }
3578 if (sinfo->filled & STATION_INFO_CHAIN_SIGNAL_AVG) {
3579 if (!nl80211_put_signal(msg, sinfo->chains,
3580 sinfo->chain_signal_avg,
3581 NL80211_STA_INFO_CHAIN_SIGNAL_AVG))
3582 goto nla_put_failure;
3583 }
Henning Rogge420e7fa2008-12-11 22:04:19 +01003584 if (sinfo->filled & STATION_INFO_TX_BITRATE) {
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003585 if (!nl80211_put_sta_rate(msg, &sinfo->txrate,
3586 NL80211_STA_INFO_TX_BITRATE))
Henning Rogge420e7fa2008-12-11 22:04:19 +01003587 goto nla_put_failure;
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003588 }
3589 if (sinfo->filled & STATION_INFO_RX_BITRATE) {
3590 if (!nl80211_put_sta_rate(msg, &sinfo->rxrate,
3591 NL80211_STA_INFO_RX_BITRATE))
3592 goto nla_put_failure;
Henning Rogge420e7fa2008-12-11 22:04:19 +01003593 }
David S. Miller9360ffd2012-03-29 04:41:26 -04003594 if ((sinfo->filled & STATION_INFO_RX_PACKETS) &&
3595 nla_put_u32(msg, NL80211_STA_INFO_RX_PACKETS,
3596 sinfo->rx_packets))
3597 goto nla_put_failure;
3598 if ((sinfo->filled & STATION_INFO_TX_PACKETS) &&
3599 nla_put_u32(msg, NL80211_STA_INFO_TX_PACKETS,
3600 sinfo->tx_packets))
3601 goto nla_put_failure;
3602 if ((sinfo->filled & STATION_INFO_TX_RETRIES) &&
3603 nla_put_u32(msg, NL80211_STA_INFO_TX_RETRIES,
3604 sinfo->tx_retries))
3605 goto nla_put_failure;
3606 if ((sinfo->filled & STATION_INFO_TX_FAILED) &&
3607 nla_put_u32(msg, NL80211_STA_INFO_TX_FAILED,
3608 sinfo->tx_failed))
3609 goto nla_put_failure;
3610 if ((sinfo->filled & STATION_INFO_BEACON_LOSS_COUNT) &&
3611 nla_put_u32(msg, NL80211_STA_INFO_BEACON_LOSS,
3612 sinfo->beacon_loss_count))
3613 goto nla_put_failure;
Marco Porsch3b1c5a52013-01-07 16:04:52 +01003614 if ((sinfo->filled & STATION_INFO_LOCAL_PM) &&
3615 nla_put_u32(msg, NL80211_STA_INFO_LOCAL_PM,
3616 sinfo->local_pm))
3617 goto nla_put_failure;
3618 if ((sinfo->filled & STATION_INFO_PEER_PM) &&
3619 nla_put_u32(msg, NL80211_STA_INFO_PEER_PM,
3620 sinfo->peer_pm))
3621 goto nla_put_failure;
3622 if ((sinfo->filled & STATION_INFO_NONPEER_PM) &&
3623 nla_put_u32(msg, NL80211_STA_INFO_NONPEER_PM,
3624 sinfo->nonpeer_pm))
3625 goto nla_put_failure;
Paul Stewartf4263c92011-03-31 09:25:41 -07003626 if (sinfo->filled & STATION_INFO_BSS_PARAM) {
3627 bss_param = nla_nest_start(msg, NL80211_STA_INFO_BSS_PARAM);
3628 if (!bss_param)
3629 goto nla_put_failure;
3630
David S. Miller9360ffd2012-03-29 04:41:26 -04003631 if (((sinfo->bss_param.flags & BSS_PARAM_FLAGS_CTS_PROT) &&
3632 nla_put_flag(msg, NL80211_STA_BSS_PARAM_CTS_PROT)) ||
3633 ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_PREAMBLE) &&
3634 nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_PREAMBLE)) ||
3635 ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_SLOT_TIME) &&
3636 nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_SLOT_TIME)) ||
3637 nla_put_u8(msg, NL80211_STA_BSS_PARAM_DTIM_PERIOD,
3638 sinfo->bss_param.dtim_period) ||
3639 nla_put_u16(msg, NL80211_STA_BSS_PARAM_BEACON_INTERVAL,
3640 sinfo->bss_param.beacon_interval))
3641 goto nla_put_failure;
Paul Stewartf4263c92011-03-31 09:25:41 -07003642
3643 nla_nest_end(msg, bss_param);
3644 }
David S. Miller9360ffd2012-03-29 04:41:26 -04003645 if ((sinfo->filled & STATION_INFO_STA_FLAGS) &&
3646 nla_put(msg, NL80211_STA_INFO_STA_FLAGS,
3647 sizeof(struct nl80211_sta_flag_update),
3648 &sinfo->sta_flags))
3649 goto nla_put_failure;
John W. Linville7eab0f62012-04-12 14:25:14 -04003650 if ((sinfo->filled & STATION_INFO_T_OFFSET) &&
3651 nla_put_u64(msg, NL80211_STA_INFO_T_OFFSET,
3652 sinfo->t_offset))
3653 goto nla_put_failure;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003654 nla_nest_end(msg, sinfoattr);
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003655
David S. Miller9360ffd2012-03-29 04:41:26 -04003656 if ((sinfo->filled & STATION_INFO_ASSOC_REQ_IES) &&
3657 nla_put(msg, NL80211_ATTR_IE, sinfo->assoc_req_ies_len,
3658 sinfo->assoc_req_ies))
3659 goto nla_put_failure;
Jouni Malinen50d3dfb2011-08-08 12:11:52 +03003660
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003661 return genlmsg_end(msg, hdr);
3662
3663 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07003664 genlmsg_cancel(msg, hdr);
3665 return -EMSGSIZE;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003666}
3667
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003668static int nl80211_dump_station(struct sk_buff *skb,
Johannes Bergbba95fe2008-07-29 13:22:51 +02003669 struct netlink_callback *cb)
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003670{
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003671 struct station_info sinfo;
3672 struct cfg80211_registered_device *dev;
Johannes Berg97990a02013-04-19 01:02:55 +02003673 struct wireless_dev *wdev;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003674 u8 mac_addr[ETH_ALEN];
Johannes Berg97990a02013-04-19 01:02:55 +02003675 int sta_idx = cb->args[2];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003676 int err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003677
Johannes Berg97990a02013-04-19 01:02:55 +02003678 err = nl80211_prepare_wdev_dump(skb, cb, &dev, &wdev);
Johannes Berg67748892010-10-04 21:14:06 +02003679 if (err)
3680 return err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02003681
Johannes Berg97990a02013-04-19 01:02:55 +02003682 if (!wdev->netdev) {
3683 err = -EINVAL;
3684 goto out_err;
3685 }
3686
Johannes Bergbba95fe2008-07-29 13:22:51 +02003687 if (!dev->ops->dump_station) {
Jouni Malineneec60b02009-03-20 21:21:19 +02003688 err = -EOPNOTSUPP;
Johannes Bergbba95fe2008-07-29 13:22:51 +02003689 goto out_err;
3690 }
3691
Johannes Bergbba95fe2008-07-29 13:22:51 +02003692 while (1) {
Jouni Malinenf612ced2011-08-11 11:46:22 +03003693 memset(&sinfo, 0, sizeof(sinfo));
Johannes Berg97990a02013-04-19 01:02:55 +02003694 err = rdev_dump_station(dev, wdev->netdev, sta_idx,
Hila Gonene35e4d22012-06-27 17:19:42 +03003695 mac_addr, &sinfo);
Johannes Bergbba95fe2008-07-29 13:22:51 +02003696 if (err == -ENOENT)
3697 break;
3698 if (err)
Johannes Berg3b858752009-03-12 09:55:09 +01003699 goto out_err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02003700
3701 if (nl80211_send_station(skb,
Eric W. Biederman15e47302012-09-07 20:12:54 +00003702 NETLINK_CB(cb->skb).portid,
Johannes Bergbba95fe2008-07-29 13:22:51 +02003703 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Johannes Berg97990a02013-04-19 01:02:55 +02003704 dev, wdev->netdev, mac_addr,
Johannes Bergbba95fe2008-07-29 13:22:51 +02003705 &sinfo) < 0)
3706 goto out;
3707
3708 sta_idx++;
3709 }
3710
3711
3712 out:
Johannes Berg97990a02013-04-19 01:02:55 +02003713 cb->args[2] = sta_idx;
Johannes Bergbba95fe2008-07-29 13:22:51 +02003714 err = skb->len;
Johannes Bergbba95fe2008-07-29 13:22:51 +02003715 out_err:
Johannes Berg97990a02013-04-19 01:02:55 +02003716 nl80211_finish_wdev_dump(dev);
Johannes Bergbba95fe2008-07-29 13:22:51 +02003717
3718 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003719}
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003720
Johannes Berg5727ef12007-12-19 02:03:34 +01003721static int nl80211_get_station(struct sk_buff *skb, struct genl_info *info)
3722{
Johannes Berg4c476992010-10-04 21:36:35 +02003723 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3724 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003725 struct station_info sinfo;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003726 struct sk_buff *msg;
3727 u8 *mac_addr = NULL;
Johannes Berg4c476992010-10-04 21:36:35 +02003728 int err;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003729
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003730 memset(&sinfo, 0, sizeof(sinfo));
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003731
3732 if (!info->attrs[NL80211_ATTR_MAC])
3733 return -EINVAL;
3734
3735 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
3736
Johannes Berg4c476992010-10-04 21:36:35 +02003737 if (!rdev->ops->get_station)
3738 return -EOPNOTSUPP;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003739
Hila Gonene35e4d22012-06-27 17:19:42 +03003740 err = rdev_get_station(rdev, dev, mac_addr, &sinfo);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003741 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02003742 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003743
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07003744 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003745 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02003746 return -ENOMEM;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003747
Eric W. Biederman15e47302012-09-07 20:12:54 +00003748 if (nl80211_send_station(msg, info->snd_portid, info->snd_seq, 0,
John W. Linville66266b32012-03-15 13:25:41 -04003749 rdev, dev, mac_addr, &sinfo) < 0) {
Johannes Berg4c476992010-10-04 21:36:35 +02003750 nlmsg_free(msg);
3751 return -ENOBUFS;
3752 }
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003753
Johannes Berg4c476992010-10-04 21:36:35 +02003754 return genlmsg_reply(msg, info);
Johannes Berg5727ef12007-12-19 02:03:34 +01003755}
3756
Johannes Berg77ee7c82013-02-15 00:48:33 +01003757int cfg80211_check_station_change(struct wiphy *wiphy,
3758 struct station_parameters *params,
3759 enum cfg80211_station_type statype)
3760{
3761 if (params->listen_interval != -1)
3762 return -EINVAL;
3763 if (params->aid)
3764 return -EINVAL;
3765
3766 /* When you run into this, adjust the code below for the new flag */
3767 BUILD_BUG_ON(NL80211_STA_FLAG_MAX != 7);
3768
3769 switch (statype) {
Thomas Pederseneef941e2013-03-04 13:06:11 -08003770 case CFG80211_STA_MESH_PEER_KERNEL:
3771 case CFG80211_STA_MESH_PEER_USER:
Johannes Berg77ee7c82013-02-15 00:48:33 +01003772 /*
3773 * No ignoring the TDLS flag here -- the userspace mesh
3774 * code doesn't have the bug of including TDLS in the
3775 * mask everywhere.
3776 */
3777 if (params->sta_flags_mask &
3778 ~(BIT(NL80211_STA_FLAG_AUTHENTICATED) |
3779 BIT(NL80211_STA_FLAG_MFP) |
3780 BIT(NL80211_STA_FLAG_AUTHORIZED)))
3781 return -EINVAL;
3782 break;
3783 case CFG80211_STA_TDLS_PEER_SETUP:
3784 case CFG80211_STA_TDLS_PEER_ACTIVE:
3785 if (!(params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)))
3786 return -EINVAL;
3787 /* ignore since it can't change */
3788 params->sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER);
3789 break;
3790 default:
3791 /* disallow mesh-specific things */
3792 if (params->plink_action != NL80211_PLINK_ACTION_NO_ACTION)
3793 return -EINVAL;
3794 if (params->local_pm)
3795 return -EINVAL;
3796 if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE)
3797 return -EINVAL;
3798 }
3799
3800 if (statype != CFG80211_STA_TDLS_PEER_SETUP &&
3801 statype != CFG80211_STA_TDLS_PEER_ACTIVE) {
3802 /* TDLS can't be set, ... */
3803 if (params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))
3804 return -EINVAL;
3805 /*
3806 * ... but don't bother the driver with it. This works around
3807 * a hostapd/wpa_supplicant issue -- it always includes the
3808 * TLDS_PEER flag in the mask even for AP mode.
3809 */
3810 params->sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER);
3811 }
3812
3813 if (statype != CFG80211_STA_TDLS_PEER_SETUP) {
3814 /* reject other things that can't change */
3815 if (params->sta_modify_mask & STATION_PARAM_APPLY_UAPSD)
3816 return -EINVAL;
3817 if (params->sta_modify_mask & STATION_PARAM_APPLY_CAPABILITY)
3818 return -EINVAL;
3819 if (params->supported_rates)
3820 return -EINVAL;
3821 if (params->ext_capab || params->ht_capa || params->vht_capa)
3822 return -EINVAL;
3823 }
3824
3825 if (statype != CFG80211_STA_AP_CLIENT) {
3826 if (params->vlan)
3827 return -EINVAL;
3828 }
3829
3830 switch (statype) {
3831 case CFG80211_STA_AP_MLME_CLIENT:
3832 /* Use this only for authorizing/unauthorizing a station */
3833 if (!(params->sta_flags_mask & BIT(NL80211_STA_FLAG_AUTHORIZED)))
3834 return -EOPNOTSUPP;
3835 break;
3836 case CFG80211_STA_AP_CLIENT:
3837 /* accept only the listed bits */
3838 if (params->sta_flags_mask &
3839 ~(BIT(NL80211_STA_FLAG_AUTHORIZED) |
3840 BIT(NL80211_STA_FLAG_AUTHENTICATED) |
3841 BIT(NL80211_STA_FLAG_ASSOCIATED) |
3842 BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) |
3843 BIT(NL80211_STA_FLAG_WME) |
3844 BIT(NL80211_STA_FLAG_MFP)))
3845 return -EINVAL;
3846
3847 /* but authenticated/associated only if driver handles it */
3848 if (!(wiphy->features & NL80211_FEATURE_FULL_AP_CLIENT_STATE) &&
3849 params->sta_flags_mask &
3850 (BIT(NL80211_STA_FLAG_AUTHENTICATED) |
3851 BIT(NL80211_STA_FLAG_ASSOCIATED)))
3852 return -EINVAL;
3853 break;
3854 case CFG80211_STA_IBSS:
3855 case CFG80211_STA_AP_STA:
3856 /* reject any changes other than AUTHORIZED */
3857 if (params->sta_flags_mask & ~BIT(NL80211_STA_FLAG_AUTHORIZED))
3858 return -EINVAL;
3859 break;
3860 case CFG80211_STA_TDLS_PEER_SETUP:
3861 /* reject any changes other than AUTHORIZED or WME */
3862 if (params->sta_flags_mask & ~(BIT(NL80211_STA_FLAG_AUTHORIZED) |
3863 BIT(NL80211_STA_FLAG_WME)))
3864 return -EINVAL;
3865 /* force (at least) rates when authorizing */
3866 if (params->sta_flags_set & BIT(NL80211_STA_FLAG_AUTHORIZED) &&
3867 !params->supported_rates)
3868 return -EINVAL;
3869 break;
3870 case CFG80211_STA_TDLS_PEER_ACTIVE:
3871 /* reject any changes */
3872 return -EINVAL;
Thomas Pederseneef941e2013-03-04 13:06:11 -08003873 case CFG80211_STA_MESH_PEER_KERNEL:
Johannes Berg77ee7c82013-02-15 00:48:33 +01003874 if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE)
3875 return -EINVAL;
3876 break;
Thomas Pederseneef941e2013-03-04 13:06:11 -08003877 case CFG80211_STA_MESH_PEER_USER:
Johannes Berg77ee7c82013-02-15 00:48:33 +01003878 if (params->plink_action != NL80211_PLINK_ACTION_NO_ACTION)
3879 return -EINVAL;
3880 break;
3881 }
3882
3883 return 0;
3884}
3885EXPORT_SYMBOL(cfg80211_check_station_change);
3886
Johannes Berg5727ef12007-12-19 02:03:34 +01003887/*
Felix Fietkauc258d2d2009-11-11 17:23:31 +01003888 * Get vlan interface making sure it is running and on the right wiphy.
Johannes Berg5727ef12007-12-19 02:03:34 +01003889 */
Johannes Berg80b99892011-11-18 16:23:01 +01003890static struct net_device *get_vlan(struct genl_info *info,
3891 struct cfg80211_registered_device *rdev)
Johannes Berg5727ef12007-12-19 02:03:34 +01003892{
Johannes Berg463d0182009-07-14 00:33:35 +02003893 struct nlattr *vlanattr = info->attrs[NL80211_ATTR_STA_VLAN];
Johannes Berg80b99892011-11-18 16:23:01 +01003894 struct net_device *v;
3895 int ret;
Johannes Berg5727ef12007-12-19 02:03:34 +01003896
Johannes Berg80b99892011-11-18 16:23:01 +01003897 if (!vlanattr)
3898 return NULL;
3899
3900 v = dev_get_by_index(genl_info_net(info), nla_get_u32(vlanattr));
3901 if (!v)
3902 return ERR_PTR(-ENODEV);
3903
3904 if (!v->ieee80211_ptr || v->ieee80211_ptr->wiphy != &rdev->wiphy) {
3905 ret = -EINVAL;
3906 goto error;
Johannes Berg5727ef12007-12-19 02:03:34 +01003907 }
Johannes Berg80b99892011-11-18 16:23:01 +01003908
Johannes Berg77ee7c82013-02-15 00:48:33 +01003909 if (v->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN &&
3910 v->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
3911 v->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) {
3912 ret = -EINVAL;
3913 goto error;
3914 }
3915
Johannes Berg80b99892011-11-18 16:23:01 +01003916 if (!netif_running(v)) {
3917 ret = -ENETDOWN;
3918 goto error;
3919 }
3920
3921 return v;
3922 error:
3923 dev_put(v);
3924 return ERR_PTR(ret);
Johannes Berg5727ef12007-12-19 02:03:34 +01003925}
3926
Johannes Berg94e860f2014-01-20 23:58:15 +01003927static const struct nla_policy
3928nl80211_sta_wme_policy[NL80211_STA_WME_MAX + 1] = {
Jouni Malinendf881292013-02-14 21:10:54 +02003929 [NL80211_STA_WME_UAPSD_QUEUES] = { .type = NLA_U8 },
3930 [NL80211_STA_WME_MAX_SP] = { .type = NLA_U8 },
3931};
3932
Johannes Bergff276692013-02-15 00:09:01 +01003933static int nl80211_parse_sta_wme(struct genl_info *info,
3934 struct station_parameters *params)
Jouni Malinendf881292013-02-14 21:10:54 +02003935{
Jouni Malinendf881292013-02-14 21:10:54 +02003936 struct nlattr *tb[NL80211_STA_WME_MAX + 1];
3937 struct nlattr *nla;
3938 int err;
3939
Jouni Malinendf881292013-02-14 21:10:54 +02003940 /* parse WME attributes if present */
3941 if (!info->attrs[NL80211_ATTR_STA_WME])
3942 return 0;
3943
3944 nla = info->attrs[NL80211_ATTR_STA_WME];
3945 err = nla_parse_nested(tb, NL80211_STA_WME_MAX, nla,
3946 nl80211_sta_wme_policy);
3947 if (err)
3948 return err;
3949
3950 if (tb[NL80211_STA_WME_UAPSD_QUEUES])
3951 params->uapsd_queues = nla_get_u8(
3952 tb[NL80211_STA_WME_UAPSD_QUEUES]);
3953 if (params->uapsd_queues & ~IEEE80211_WMM_IE_STA_QOSINFO_AC_MASK)
3954 return -EINVAL;
3955
3956 if (tb[NL80211_STA_WME_MAX_SP])
3957 params->max_sp = nla_get_u8(tb[NL80211_STA_WME_MAX_SP]);
3958
3959 if (params->max_sp & ~IEEE80211_WMM_IE_STA_QOSINFO_SP_MASK)
3960 return -EINVAL;
3961
3962 params->sta_modify_mask |= STATION_PARAM_APPLY_UAPSD;
3963
3964 return 0;
3965}
3966
Sunil Duttc01fc9a2013-10-09 20:45:21 +05303967static int nl80211_parse_sta_channel_info(struct genl_info *info,
3968 struct station_parameters *params)
3969{
3970 if (info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]) {
3971 params->supported_channels =
3972 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]);
3973 params->supported_channels_len =
3974 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]);
3975 /*
3976 * Need to include at least one (first channel, number of
3977 * channels) tuple for each subband, and must have proper
3978 * tuples for the rest of the data as well.
3979 */
3980 if (params->supported_channels_len < 2)
3981 return -EINVAL;
3982 if (params->supported_channels_len % 2)
3983 return -EINVAL;
3984 }
3985
3986 if (info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]) {
3987 params->supported_oper_classes =
3988 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]);
3989 params->supported_oper_classes_len =
3990 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]);
3991 /*
3992 * The value of the Length field of the Supported Operating
3993 * Classes element is between 2 and 253.
3994 */
3995 if (params->supported_oper_classes_len < 2 ||
3996 params->supported_oper_classes_len > 253)
3997 return -EINVAL;
3998 }
3999 return 0;
4000}
4001
Johannes Bergff276692013-02-15 00:09:01 +01004002static int nl80211_set_station_tdls(struct genl_info *info,
4003 struct station_parameters *params)
4004{
Sunil Duttc01fc9a2013-10-09 20:45:21 +05304005 int err;
Johannes Bergff276692013-02-15 00:09:01 +01004006 /* Dummy STA entry gets updated once the peer capabilities are known */
Jouni Malinen5e4b6f52013-05-16 20:11:08 +03004007 if (info->attrs[NL80211_ATTR_PEER_AID])
4008 params->aid = nla_get_u16(info->attrs[NL80211_ATTR_PEER_AID]);
Johannes Bergff276692013-02-15 00:09:01 +01004009 if (info->attrs[NL80211_ATTR_HT_CAPABILITY])
4010 params->ht_capa =
4011 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]);
4012 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY])
4013 params->vht_capa =
4014 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]);
4015
Sunil Duttc01fc9a2013-10-09 20:45:21 +05304016 err = nl80211_parse_sta_channel_info(info, params);
4017 if (err)
4018 return err;
4019
Johannes Bergff276692013-02-15 00:09:01 +01004020 return nl80211_parse_sta_wme(info, params);
4021}
4022
Johannes Berg5727ef12007-12-19 02:03:34 +01004023static int nl80211_set_station(struct sk_buff *skb, struct genl_info *info)
4024{
Johannes Berg4c476992010-10-04 21:36:35 +02004025 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg4c476992010-10-04 21:36:35 +02004026 struct net_device *dev = info->user_ptr[1];
Johannes Berg5727ef12007-12-19 02:03:34 +01004027 struct station_parameters params;
Johannes Berg77ee7c82013-02-15 00:48:33 +01004028 u8 *mac_addr;
4029 int err;
Johannes Berg5727ef12007-12-19 02:03:34 +01004030
4031 memset(&params, 0, sizeof(params));
4032
4033 params.listen_interval = -1;
4034
Johannes Berg77ee7c82013-02-15 00:48:33 +01004035 if (!rdev->ops->change_station)
4036 return -EOPNOTSUPP;
4037
Johannes Berg5727ef12007-12-19 02:03:34 +01004038 if (info->attrs[NL80211_ATTR_STA_AID])
4039 return -EINVAL;
4040
4041 if (!info->attrs[NL80211_ATTR_MAC])
4042 return -EINVAL;
4043
4044 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
4045
4046 if (info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) {
4047 params.supported_rates =
4048 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
4049 params.supported_rates_len =
4050 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
4051 }
4052
Jouni Malinen9d62a982013-02-14 21:10:13 +02004053 if (info->attrs[NL80211_ATTR_STA_CAPABILITY]) {
4054 params.capability =
4055 nla_get_u16(info->attrs[NL80211_ATTR_STA_CAPABILITY]);
4056 params.sta_modify_mask |= STATION_PARAM_APPLY_CAPABILITY;
4057 }
4058
4059 if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]) {
4060 params.ext_capab =
4061 nla_data(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
4062 params.ext_capab_len =
4063 nla_len(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
4064 }
4065
Jouni Malinendf881292013-02-14 21:10:54 +02004066 if (info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL])
Johannes Bergba23d202012-12-27 17:32:09 +01004067 return -EINVAL;
Jouni Malinen36aedc92008-08-25 11:58:58 +03004068
Johannes Bergbdd3ae32012-01-02 13:30:03 +01004069 if (parse_station_flags(info, dev->ieee80211_ptr->iftype, &params))
Johannes Berg5727ef12007-12-19 02:03:34 +01004070 return -EINVAL;
4071
Johannes Bergf8bacc22013-02-14 23:27:01 +01004072 if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) {
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004073 params.plink_action =
Johannes Bergf8bacc22013-02-14 23:27:01 +01004074 nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]);
4075 if (params.plink_action >= NUM_NL80211_PLINK_ACTIONS)
4076 return -EINVAL;
4077 }
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004078
Johannes Bergf8bacc22013-02-14 23:27:01 +01004079 if (info->attrs[NL80211_ATTR_STA_PLINK_STATE]) {
Javier Cardona9c3990a2011-05-03 16:57:11 -07004080 params.plink_state =
Johannes Bergf8bacc22013-02-14 23:27:01 +01004081 nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_STATE]);
4082 if (params.plink_state >= NUM_NL80211_PLINK_STATES)
4083 return -EINVAL;
4084 params.sta_modify_mask |= STATION_PARAM_APPLY_PLINK_STATE;
4085 }
Javier Cardona9c3990a2011-05-03 16:57:11 -07004086
Marco Porsch3b1c5a52013-01-07 16:04:52 +01004087 if (info->attrs[NL80211_ATTR_LOCAL_MESH_POWER_MODE]) {
4088 enum nl80211_mesh_power_mode pm = nla_get_u32(
4089 info->attrs[NL80211_ATTR_LOCAL_MESH_POWER_MODE]);
4090
4091 if (pm <= NL80211_MESH_POWER_UNKNOWN ||
4092 pm > NL80211_MESH_POWER_MAX)
4093 return -EINVAL;
4094
4095 params.local_pm = pm;
4096 }
4097
Johannes Berg77ee7c82013-02-15 00:48:33 +01004098 /* Include parameters for TDLS peer (will check later) */
4099 err = nl80211_set_station_tdls(info, &params);
4100 if (err)
4101 return err;
4102
4103 params.vlan = get_vlan(info, rdev);
4104 if (IS_ERR(params.vlan))
4105 return PTR_ERR(params.vlan);
4106
Johannes Berga97f4422009-06-18 17:23:43 +02004107 switch (dev->ieee80211_ptr->iftype) {
4108 case NL80211_IFTYPE_AP:
4109 case NL80211_IFTYPE_AP_VLAN:
Johannes Berg074ac8d2010-09-16 14:58:22 +02004110 case NL80211_IFTYPE_P2P_GO:
Johannes Berg074ac8d2010-09-16 14:58:22 +02004111 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Berga97f4422009-06-18 17:23:43 +02004112 case NL80211_IFTYPE_STATION:
Antonio Quartulli267335d2012-01-31 20:25:47 +01004113 case NL80211_IFTYPE_ADHOC:
Johannes Berga97f4422009-06-18 17:23:43 +02004114 case NL80211_IFTYPE_MESH_POINT:
Johannes Berga97f4422009-06-18 17:23:43 +02004115 break;
4116 default:
Johannes Berg77ee7c82013-02-15 00:48:33 +01004117 err = -EOPNOTSUPP;
4118 goto out_put_vlan;
Johannes Berg034d6552009-05-27 10:35:29 +02004119 }
4120
Johannes Berg77ee7c82013-02-15 00:48:33 +01004121 /* driver will call cfg80211_check_station_change() */
Hila Gonene35e4d22012-06-27 17:19:42 +03004122 err = rdev_change_station(rdev, dev, mac_addr, &params);
Johannes Berg5727ef12007-12-19 02:03:34 +01004123
Johannes Berg77ee7c82013-02-15 00:48:33 +01004124 out_put_vlan:
Johannes Berg5727ef12007-12-19 02:03:34 +01004125 if (params.vlan)
4126 dev_put(params.vlan);
Johannes Berg3b858752009-03-12 09:55:09 +01004127
Johannes Berg5727ef12007-12-19 02:03:34 +01004128 return err;
4129}
4130
4131static int nl80211_new_station(struct sk_buff *skb, struct genl_info *info)
4132{
Johannes Berg4c476992010-10-04 21:36:35 +02004133 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg5727ef12007-12-19 02:03:34 +01004134 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02004135 struct net_device *dev = info->user_ptr[1];
Johannes Berg5727ef12007-12-19 02:03:34 +01004136 struct station_parameters params;
4137 u8 *mac_addr = NULL;
4138
4139 memset(&params, 0, sizeof(params));
4140
Johannes Berg984c3112013-02-14 23:43:25 +01004141 if (!rdev->ops->add_station)
4142 return -EOPNOTSUPP;
4143
Johannes Berg5727ef12007-12-19 02:03:34 +01004144 if (!info->attrs[NL80211_ATTR_MAC])
4145 return -EINVAL;
4146
Johannes Berg5727ef12007-12-19 02:03:34 +01004147 if (!info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL])
4148 return -EINVAL;
4149
4150 if (!info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES])
4151 return -EINVAL;
4152
Jouni Malinen5e4b6f52013-05-16 20:11:08 +03004153 if (!info->attrs[NL80211_ATTR_STA_AID] &&
4154 !info->attrs[NL80211_ATTR_PEER_AID])
Thadeu Lima de Souza Cascardo0e956c12010-02-12 12:34:50 -02004155 return -EINVAL;
4156
Johannes Berg5727ef12007-12-19 02:03:34 +01004157 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
4158 params.supported_rates =
4159 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
4160 params.supported_rates_len =
4161 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
4162 params.listen_interval =
4163 nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]);
Johannes Berg51b50fb2009-05-24 16:42:30 +02004164
Jouni Malinen3d124ea2013-05-27 18:24:02 +03004165 if (info->attrs[NL80211_ATTR_PEER_AID])
Jouni Malinen5e4b6f52013-05-16 20:11:08 +03004166 params.aid = nla_get_u16(info->attrs[NL80211_ATTR_PEER_AID]);
Jouni Malinen3d124ea2013-05-27 18:24:02 +03004167 else
4168 params.aid = nla_get_u16(info->attrs[NL80211_ATTR_STA_AID]);
Thadeu Lima de Souza Cascardo0e956c12010-02-12 12:34:50 -02004169 if (!params.aid || params.aid > IEEE80211_MAX_AID)
4170 return -EINVAL;
Johannes Berg51b50fb2009-05-24 16:42:30 +02004171
Jouni Malinen9d62a982013-02-14 21:10:13 +02004172 if (info->attrs[NL80211_ATTR_STA_CAPABILITY]) {
4173 params.capability =
4174 nla_get_u16(info->attrs[NL80211_ATTR_STA_CAPABILITY]);
4175 params.sta_modify_mask |= STATION_PARAM_APPLY_CAPABILITY;
4176 }
4177
4178 if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]) {
4179 params.ext_capab =
4180 nla_data(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
4181 params.ext_capab_len =
4182 nla_len(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
4183 }
4184
Jouni Malinen36aedc92008-08-25 11:58:58 +03004185 if (info->attrs[NL80211_ATTR_HT_CAPABILITY])
4186 params.ht_capa =
4187 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]);
Johannes Berg5727ef12007-12-19 02:03:34 +01004188
Mahesh Palivelaf461be3e2012-10-11 08:04:52 +00004189 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY])
4190 params.vht_capa =
4191 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]);
4192
Marek Kwaczynski60f4a7b2013-12-03 10:04:59 +01004193 if (info->attrs[NL80211_ATTR_OPMODE_NOTIF]) {
4194 params.opmode_notif_used = true;
4195 params.opmode_notif =
4196 nla_get_u8(info->attrs[NL80211_ATTR_OPMODE_NOTIF]);
4197 }
4198
Johannes Bergf8bacc22013-02-14 23:27:01 +01004199 if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) {
Javier Cardona96b78df2011-04-07 15:08:33 -07004200 params.plink_action =
Johannes Bergf8bacc22013-02-14 23:27:01 +01004201 nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]);
4202 if (params.plink_action >= NUM_NL80211_PLINK_ACTIONS)
4203 return -EINVAL;
4204 }
Javier Cardona96b78df2011-04-07 15:08:33 -07004205
Sunil Duttc01fc9a2013-10-09 20:45:21 +05304206 err = nl80211_parse_sta_channel_info(info, &params);
4207 if (err)
4208 return err;
4209
Johannes Bergff276692013-02-15 00:09:01 +01004210 err = nl80211_parse_sta_wme(info, &params);
4211 if (err)
4212 return err;
Johannes Bergbdd90d52011-12-14 12:20:27 +01004213
Johannes Bergbdd3ae32012-01-02 13:30:03 +01004214 if (parse_station_flags(info, dev->ieee80211_ptr->iftype, &params))
Johannes Berg5727ef12007-12-19 02:03:34 +01004215 return -EINVAL;
4216
Johannes Berg77ee7c82013-02-15 00:48:33 +01004217 /* When you run into this, adjust the code below for the new flag */
4218 BUILD_BUG_ON(NL80211_STA_FLAG_MAX != 7);
4219
Johannes Bergbdd90d52011-12-14 12:20:27 +01004220 switch (dev->ieee80211_ptr->iftype) {
4221 case NL80211_IFTYPE_AP:
4222 case NL80211_IFTYPE_AP_VLAN:
4223 case NL80211_IFTYPE_P2P_GO:
Johannes Berg984c3112013-02-14 23:43:25 +01004224 /* ignore WME attributes if iface/sta is not capable */
4225 if (!(rdev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) ||
4226 !(params.sta_flags_set & BIT(NL80211_STA_FLAG_WME)))
4227 params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD;
Eliad Pellerc75786c2011-08-23 14:37:46 +03004228
Johannes Bergbdd90d52011-12-14 12:20:27 +01004229 /* TDLS peers cannot be added */
Jouni Malinen3d124ea2013-05-27 18:24:02 +03004230 if ((params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) ||
4231 info->attrs[NL80211_ATTR_PEER_AID])
Johannes Berg4319e192011-09-07 11:50:48 +02004232 return -EINVAL;
Johannes Bergbdd90d52011-12-14 12:20:27 +01004233 /* but don't bother the driver with it */
4234 params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER);
Eliad Pellerc75786c2011-08-23 14:37:46 +03004235
Johannes Bergd582cff2012-10-26 17:53:44 +02004236 /* allow authenticated/associated only if driver handles it */
4237 if (!(rdev->wiphy.features &
4238 NL80211_FEATURE_FULL_AP_CLIENT_STATE) &&
4239 params.sta_flags_mask &
4240 (BIT(NL80211_STA_FLAG_AUTHENTICATED) |
4241 BIT(NL80211_STA_FLAG_ASSOCIATED)))
4242 return -EINVAL;
4243
Johannes Bergbdd90d52011-12-14 12:20:27 +01004244 /* must be last in here for error handling */
4245 params.vlan = get_vlan(info, rdev);
4246 if (IS_ERR(params.vlan))
4247 return PTR_ERR(params.vlan);
4248 break;
4249 case NL80211_IFTYPE_MESH_POINT:
Johannes Berg984c3112013-02-14 23:43:25 +01004250 /* ignore uAPSD data */
4251 params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD;
4252
Johannes Bergd582cff2012-10-26 17:53:44 +02004253 /* associated is disallowed */
4254 if (params.sta_flags_mask & BIT(NL80211_STA_FLAG_ASSOCIATED))
4255 return -EINVAL;
Johannes Bergbdd90d52011-12-14 12:20:27 +01004256 /* TDLS peers cannot be added */
Jouni Malinen3d124ea2013-05-27 18:24:02 +03004257 if ((params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) ||
4258 info->attrs[NL80211_ATTR_PEER_AID])
Johannes Berg4319e192011-09-07 11:50:48 +02004259 return -EINVAL;
Johannes Bergbdd90d52011-12-14 12:20:27 +01004260 break;
4261 case NL80211_IFTYPE_STATION:
Johannes Berg93d08f02013-03-04 09:29:46 +01004262 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Berg984c3112013-02-14 23:43:25 +01004263 /* ignore uAPSD data */
4264 params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD;
4265
Johannes Berg77ee7c82013-02-15 00:48:33 +01004266 /* these are disallowed */
4267 if (params.sta_flags_mask &
4268 (BIT(NL80211_STA_FLAG_ASSOCIATED) |
4269 BIT(NL80211_STA_FLAG_AUTHENTICATED)))
Johannes Bergd582cff2012-10-26 17:53:44 +02004270 return -EINVAL;
Johannes Bergbdd90d52011-12-14 12:20:27 +01004271 /* Only TDLS peers can be added */
4272 if (!(params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)))
4273 return -EINVAL;
4274 /* Can only add if TDLS ... */
4275 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS))
4276 return -EOPNOTSUPP;
4277 /* ... with external setup is supported */
4278 if (!(rdev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP))
4279 return -EOPNOTSUPP;
Johannes Berg77ee7c82013-02-15 00:48:33 +01004280 /*
4281 * Older wpa_supplicant versions always mark the TDLS peer
4282 * as authorized, but it shouldn't yet be.
4283 */
4284 params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_AUTHORIZED);
Johannes Bergbdd90d52011-12-14 12:20:27 +01004285 break;
4286 default:
4287 return -EOPNOTSUPP;
Eliad Pellerc75786c2011-08-23 14:37:46 +03004288 }
4289
Johannes Bergbdd90d52011-12-14 12:20:27 +01004290 /* be aware of params.vlan when changing code here */
Johannes Berg5727ef12007-12-19 02:03:34 +01004291
Hila Gonene35e4d22012-06-27 17:19:42 +03004292 err = rdev_add_station(rdev, dev, mac_addr, &params);
Johannes Berg5727ef12007-12-19 02:03:34 +01004293
Johannes Berg5727ef12007-12-19 02:03:34 +01004294 if (params.vlan)
4295 dev_put(params.vlan);
Johannes Berg5727ef12007-12-19 02:03:34 +01004296 return err;
4297}
4298
4299static int nl80211_del_station(struct sk_buff *skb, struct genl_info *info)
4300{
Johannes Berg4c476992010-10-04 21:36:35 +02004301 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4302 struct net_device *dev = info->user_ptr[1];
Johannes Berg5727ef12007-12-19 02:03:34 +01004303 u8 *mac_addr = NULL;
4304
4305 if (info->attrs[NL80211_ATTR_MAC])
4306 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
4307
Johannes Berge80cf852009-05-11 14:43:13 +02004308 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
Marco Porschd5d9de02010-03-30 10:00:16 +02004309 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN &&
Johannes Berg074ac8d2010-09-16 14:58:22 +02004310 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT &&
Johannes Berg4c476992010-10-04 21:36:35 +02004311 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
4312 return -EINVAL;
Johannes Berge80cf852009-05-11 14:43:13 +02004313
Johannes Berg4c476992010-10-04 21:36:35 +02004314 if (!rdev->ops->del_station)
4315 return -EOPNOTSUPP;
Johannes Berg5727ef12007-12-19 02:03:34 +01004316
Hila Gonene35e4d22012-06-27 17:19:42 +03004317 return rdev_del_station(rdev, dev, mac_addr);
Johannes Berg5727ef12007-12-19 02:03:34 +01004318}
4319
Eric W. Biederman15e47302012-09-07 20:12:54 +00004320static int nl80211_send_mpath(struct sk_buff *msg, u32 portid, u32 seq,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004321 int flags, struct net_device *dev,
4322 u8 *dst, u8 *next_hop,
4323 struct mpath_info *pinfo)
4324{
4325 void *hdr;
4326 struct nlattr *pinfoattr;
4327
Eric W. Biederman15e47302012-09-07 20:12:54 +00004328 hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_STATION);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004329 if (!hdr)
4330 return -1;
4331
David S. Miller9360ffd2012-03-29 04:41:26 -04004332 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
4333 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, dst) ||
4334 nla_put(msg, NL80211_ATTR_MPATH_NEXT_HOP, ETH_ALEN, next_hop) ||
4335 nla_put_u32(msg, NL80211_ATTR_GENERATION, pinfo->generation))
4336 goto nla_put_failure;
Johannes Bergf5ea9122009-08-07 16:17:38 +02004337
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004338 pinfoattr = nla_nest_start(msg, NL80211_ATTR_MPATH_INFO);
4339 if (!pinfoattr)
4340 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04004341 if ((pinfo->filled & MPATH_INFO_FRAME_QLEN) &&
4342 nla_put_u32(msg, NL80211_MPATH_INFO_FRAME_QLEN,
4343 pinfo->frame_qlen))
4344 goto nla_put_failure;
4345 if (((pinfo->filled & MPATH_INFO_SN) &&
4346 nla_put_u32(msg, NL80211_MPATH_INFO_SN, pinfo->sn)) ||
4347 ((pinfo->filled & MPATH_INFO_METRIC) &&
4348 nla_put_u32(msg, NL80211_MPATH_INFO_METRIC,
4349 pinfo->metric)) ||
4350 ((pinfo->filled & MPATH_INFO_EXPTIME) &&
4351 nla_put_u32(msg, NL80211_MPATH_INFO_EXPTIME,
4352 pinfo->exptime)) ||
4353 ((pinfo->filled & MPATH_INFO_FLAGS) &&
4354 nla_put_u8(msg, NL80211_MPATH_INFO_FLAGS,
4355 pinfo->flags)) ||
4356 ((pinfo->filled & MPATH_INFO_DISCOVERY_TIMEOUT) &&
4357 nla_put_u32(msg, NL80211_MPATH_INFO_DISCOVERY_TIMEOUT,
4358 pinfo->discovery_timeout)) ||
4359 ((pinfo->filled & MPATH_INFO_DISCOVERY_RETRIES) &&
4360 nla_put_u8(msg, NL80211_MPATH_INFO_DISCOVERY_RETRIES,
4361 pinfo->discovery_retries)))
4362 goto nla_put_failure;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004363
4364 nla_nest_end(msg, pinfoattr);
4365
4366 return genlmsg_end(msg, hdr);
4367
4368 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07004369 genlmsg_cancel(msg, hdr);
4370 return -EMSGSIZE;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004371}
4372
4373static int nl80211_dump_mpath(struct sk_buff *skb,
Johannes Bergbba95fe2008-07-29 13:22:51 +02004374 struct netlink_callback *cb)
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004375{
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004376 struct mpath_info pinfo;
4377 struct cfg80211_registered_device *dev;
Johannes Berg97990a02013-04-19 01:02:55 +02004378 struct wireless_dev *wdev;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004379 u8 dst[ETH_ALEN];
4380 u8 next_hop[ETH_ALEN];
Johannes Berg97990a02013-04-19 01:02:55 +02004381 int path_idx = cb->args[2];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004382 int err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004383
Johannes Berg97990a02013-04-19 01:02:55 +02004384 err = nl80211_prepare_wdev_dump(skb, cb, &dev, &wdev);
Johannes Berg67748892010-10-04 21:14:06 +02004385 if (err)
4386 return err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004387
4388 if (!dev->ops->dump_mpath) {
Jouni Malineneec60b02009-03-20 21:21:19 +02004389 err = -EOPNOTSUPP;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004390 goto out_err;
4391 }
4392
Johannes Berg97990a02013-04-19 01:02:55 +02004393 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) {
Jouni Malineneec60b02009-03-20 21:21:19 +02004394 err = -EOPNOTSUPP;
Roel Kluin0448b5f2009-08-22 21:15:49 +02004395 goto out_err;
Jouni Malineneec60b02009-03-20 21:21:19 +02004396 }
4397
Johannes Bergbba95fe2008-07-29 13:22:51 +02004398 while (1) {
Johannes Berg97990a02013-04-19 01:02:55 +02004399 err = rdev_dump_mpath(dev, wdev->netdev, path_idx, dst,
4400 next_hop, &pinfo);
Johannes Bergbba95fe2008-07-29 13:22:51 +02004401 if (err == -ENOENT)
4402 break;
4403 if (err)
Johannes Berg3b858752009-03-12 09:55:09 +01004404 goto out_err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004405
Eric W. Biederman15e47302012-09-07 20:12:54 +00004406 if (nl80211_send_mpath(skb, NETLINK_CB(cb->skb).portid,
Johannes Bergbba95fe2008-07-29 13:22:51 +02004407 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Johannes Berg97990a02013-04-19 01:02:55 +02004408 wdev->netdev, dst, next_hop,
Johannes Bergbba95fe2008-07-29 13:22:51 +02004409 &pinfo) < 0)
4410 goto out;
4411
4412 path_idx++;
4413 }
4414
4415
4416 out:
Johannes Berg97990a02013-04-19 01:02:55 +02004417 cb->args[2] = path_idx;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004418 err = skb->len;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004419 out_err:
Johannes Berg97990a02013-04-19 01:02:55 +02004420 nl80211_finish_wdev_dump(dev);
Johannes Bergbba95fe2008-07-29 13:22:51 +02004421 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004422}
4423
4424static int nl80211_get_mpath(struct sk_buff *skb, struct genl_info *info)
4425{
Johannes Berg4c476992010-10-04 21:36:35 +02004426 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004427 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02004428 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004429 struct mpath_info pinfo;
4430 struct sk_buff *msg;
4431 u8 *dst = NULL;
4432 u8 next_hop[ETH_ALEN];
4433
4434 memset(&pinfo, 0, sizeof(pinfo));
4435
4436 if (!info->attrs[NL80211_ATTR_MAC])
4437 return -EINVAL;
4438
4439 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
4440
Johannes Berg4c476992010-10-04 21:36:35 +02004441 if (!rdev->ops->get_mpath)
4442 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01004443
Johannes Berg4c476992010-10-04 21:36:35 +02004444 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
4445 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02004446
Hila Gonene35e4d22012-06-27 17:19:42 +03004447 err = rdev_get_mpath(rdev, dev, dst, next_hop, &pinfo);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004448 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02004449 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004450
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07004451 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004452 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02004453 return -ENOMEM;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004454
Eric W. Biederman15e47302012-09-07 20:12:54 +00004455 if (nl80211_send_mpath(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berg4c476992010-10-04 21:36:35 +02004456 dev, dst, next_hop, &pinfo) < 0) {
4457 nlmsg_free(msg);
4458 return -ENOBUFS;
4459 }
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004460
Johannes Berg4c476992010-10-04 21:36:35 +02004461 return genlmsg_reply(msg, info);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004462}
4463
4464static int nl80211_set_mpath(struct sk_buff *skb, struct genl_info *info)
4465{
Johannes Berg4c476992010-10-04 21:36:35 +02004466 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4467 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004468 u8 *dst = NULL;
4469 u8 *next_hop = NULL;
4470
4471 if (!info->attrs[NL80211_ATTR_MAC])
4472 return -EINVAL;
4473
4474 if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP])
4475 return -EINVAL;
4476
4477 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
4478 next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]);
4479
Johannes Berg4c476992010-10-04 21:36:35 +02004480 if (!rdev->ops->change_mpath)
4481 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01004482
Johannes Berg4c476992010-10-04 21:36:35 +02004483 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
4484 return -EOPNOTSUPP;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004485
Hila Gonene35e4d22012-06-27 17:19:42 +03004486 return rdev_change_mpath(rdev, dev, dst, next_hop);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004487}
Johannes Berg4c476992010-10-04 21:36:35 +02004488
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004489static int nl80211_new_mpath(struct sk_buff *skb, struct genl_info *info)
4490{
Johannes Berg4c476992010-10-04 21:36:35 +02004491 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4492 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004493 u8 *dst = NULL;
4494 u8 *next_hop = NULL;
4495
4496 if (!info->attrs[NL80211_ATTR_MAC])
4497 return -EINVAL;
4498
4499 if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP])
4500 return -EINVAL;
4501
4502 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
4503 next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]);
4504
Johannes Berg4c476992010-10-04 21:36:35 +02004505 if (!rdev->ops->add_mpath)
4506 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01004507
Johannes Berg4c476992010-10-04 21:36:35 +02004508 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
4509 return -EOPNOTSUPP;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004510
Hila Gonene35e4d22012-06-27 17:19:42 +03004511 return rdev_add_mpath(rdev, dev, dst, next_hop);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004512}
4513
4514static int nl80211_del_mpath(struct sk_buff *skb, struct genl_info *info)
4515{
Johannes Berg4c476992010-10-04 21:36:35 +02004516 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4517 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004518 u8 *dst = NULL;
4519
4520 if (info->attrs[NL80211_ATTR_MAC])
4521 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
4522
Johannes Berg4c476992010-10-04 21:36:35 +02004523 if (!rdev->ops->del_mpath)
4524 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01004525
Hila Gonene35e4d22012-06-27 17:19:42 +03004526 return rdev_del_mpath(rdev, dev, dst);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004527}
4528
Jouni Malinen9f1ba902008-08-07 20:07:01 +03004529static int nl80211_set_bss(struct sk_buff *skb, struct genl_info *info)
4530{
Johannes Berg4c476992010-10-04 21:36:35 +02004531 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4532 struct net_device *dev = info->user_ptr[1];
Simon Wunderlichc56589e2013-11-21 18:19:49 +01004533 struct wireless_dev *wdev = dev->ieee80211_ptr;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03004534 struct bss_parameters params;
Simon Wunderlichc56589e2013-11-21 18:19:49 +01004535 int err;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03004536
4537 memset(&params, 0, sizeof(params));
4538 /* default to not changing parameters */
4539 params.use_cts_prot = -1;
4540 params.use_short_preamble = -1;
4541 params.use_short_slot_time = -1;
Felix Fietkaufd8aaaf2010-04-27 01:23:35 +02004542 params.ap_isolate = -1;
Helmut Schaa50b12f52010-11-19 12:40:25 +01004543 params.ht_opmode = -1;
Johannes Berg53cabad2012-11-14 15:17:28 +01004544 params.p2p_ctwindow = -1;
4545 params.p2p_opp_ps = -1;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03004546
4547 if (info->attrs[NL80211_ATTR_BSS_CTS_PROT])
4548 params.use_cts_prot =
4549 nla_get_u8(info->attrs[NL80211_ATTR_BSS_CTS_PROT]);
4550 if (info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE])
4551 params.use_short_preamble =
4552 nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]);
4553 if (info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME])
4554 params.use_short_slot_time =
4555 nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]);
Jouni Malinen90c97a02008-10-30 16:59:22 +02004556 if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) {
4557 params.basic_rates =
4558 nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
4559 params.basic_rates_len =
4560 nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
4561 }
Felix Fietkaufd8aaaf2010-04-27 01:23:35 +02004562 if (info->attrs[NL80211_ATTR_AP_ISOLATE])
4563 params.ap_isolate = !!nla_get_u8(info->attrs[NL80211_ATTR_AP_ISOLATE]);
Helmut Schaa50b12f52010-11-19 12:40:25 +01004564 if (info->attrs[NL80211_ATTR_BSS_HT_OPMODE])
4565 params.ht_opmode =
4566 nla_get_u16(info->attrs[NL80211_ATTR_BSS_HT_OPMODE]);
Jouni Malinen9f1ba902008-08-07 20:07:01 +03004567
Johannes Berg53cabad2012-11-14 15:17:28 +01004568 if (info->attrs[NL80211_ATTR_P2P_CTWINDOW]) {
4569 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
4570 return -EINVAL;
4571 params.p2p_ctwindow =
4572 nla_get_s8(info->attrs[NL80211_ATTR_P2P_CTWINDOW]);
4573 if (params.p2p_ctwindow < 0)
4574 return -EINVAL;
4575 if (params.p2p_ctwindow != 0 &&
4576 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_CTWIN))
4577 return -EINVAL;
4578 }
4579
4580 if (info->attrs[NL80211_ATTR_P2P_OPPPS]) {
4581 u8 tmp;
4582
4583 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
4584 return -EINVAL;
4585 tmp = nla_get_u8(info->attrs[NL80211_ATTR_P2P_OPPPS]);
4586 if (tmp > 1)
4587 return -EINVAL;
4588 params.p2p_opp_ps = tmp;
4589 if (params.p2p_opp_ps &&
4590 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_OPPPS))
4591 return -EINVAL;
4592 }
4593
Johannes Berg4c476992010-10-04 21:36:35 +02004594 if (!rdev->ops->change_bss)
4595 return -EOPNOTSUPP;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03004596
Johannes Berg074ac8d2010-09-16 14:58:22 +02004597 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
Johannes Berg4c476992010-10-04 21:36:35 +02004598 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
4599 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02004600
Simon Wunderlichc56589e2013-11-21 18:19:49 +01004601 wdev_lock(wdev);
4602 err = rdev_change_bss(rdev, dev, &params);
4603 wdev_unlock(wdev);
4604
4605 return err;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03004606}
4607
Alexey Dobriyanb54452b2010-02-18 08:14:31 +00004608static const struct nla_policy reg_rule_policy[NL80211_REG_RULE_ATTR_MAX + 1] = {
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004609 [NL80211_ATTR_REG_RULE_FLAGS] = { .type = NLA_U32 },
4610 [NL80211_ATTR_FREQ_RANGE_START] = { .type = NLA_U32 },
4611 [NL80211_ATTR_FREQ_RANGE_END] = { .type = NLA_U32 },
4612 [NL80211_ATTR_FREQ_RANGE_MAX_BW] = { .type = NLA_U32 },
4613 [NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN] = { .type = NLA_U32 },
4614 [NL80211_ATTR_POWER_RULE_MAX_EIRP] = { .type = NLA_U32 },
4615};
4616
4617static int parse_reg_rule(struct nlattr *tb[],
4618 struct ieee80211_reg_rule *reg_rule)
4619{
4620 struct ieee80211_freq_range *freq_range = &reg_rule->freq_range;
4621 struct ieee80211_power_rule *power_rule = &reg_rule->power_rule;
4622
4623 if (!tb[NL80211_ATTR_REG_RULE_FLAGS])
4624 return -EINVAL;
4625 if (!tb[NL80211_ATTR_FREQ_RANGE_START])
4626 return -EINVAL;
4627 if (!tb[NL80211_ATTR_FREQ_RANGE_END])
4628 return -EINVAL;
4629 if (!tb[NL80211_ATTR_FREQ_RANGE_MAX_BW])
4630 return -EINVAL;
4631 if (!tb[NL80211_ATTR_POWER_RULE_MAX_EIRP])
4632 return -EINVAL;
4633
4634 reg_rule->flags = nla_get_u32(tb[NL80211_ATTR_REG_RULE_FLAGS]);
4635
4636 freq_range->start_freq_khz =
4637 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_START]);
4638 freq_range->end_freq_khz =
4639 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_END]);
4640 freq_range->max_bandwidth_khz =
4641 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]);
4642
4643 power_rule->max_eirp =
4644 nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]);
4645
4646 if (tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN])
4647 power_rule->max_antenna_gain =
4648 nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]);
4649
4650 return 0;
4651}
4652
4653static int nl80211_req_set_reg(struct sk_buff *skb, struct genl_info *info)
4654{
4655 int r;
4656 char *data = NULL;
Luis R. Rodriguez57b5ce02012-07-12 11:49:18 -07004657 enum nl80211_user_reg_hint_type user_reg_hint_type;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004658
Luis R. Rodriguez80778f12009-02-21 00:04:22 -05004659 /*
4660 * You should only get this when cfg80211 hasn't yet initialized
4661 * completely when built-in to the kernel right between the time
4662 * window between nl80211_init() and regulatory_init(), if that is
4663 * even possible.
4664 */
Johannes Berg458f4f92012-12-06 15:47:38 +01004665 if (unlikely(!rcu_access_pointer(cfg80211_regdomain)))
Luis R. Rodriguezfe33eb32009-02-21 00:04:30 -05004666 return -EINPROGRESS;
Luis R. Rodriguez80778f12009-02-21 00:04:22 -05004667
Luis R. Rodriguezfe33eb32009-02-21 00:04:30 -05004668 if (!info->attrs[NL80211_ATTR_REG_ALPHA2])
4669 return -EINVAL;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004670
4671 data = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]);
4672
Luis R. Rodriguez57b5ce02012-07-12 11:49:18 -07004673 if (info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE])
4674 user_reg_hint_type =
4675 nla_get_u32(info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE]);
4676 else
4677 user_reg_hint_type = NL80211_USER_REG_HINT_USER;
4678
4679 switch (user_reg_hint_type) {
4680 case NL80211_USER_REG_HINT_USER:
4681 case NL80211_USER_REG_HINT_CELL_BASE:
4682 break;
4683 default:
4684 return -EINVAL;
4685 }
4686
4687 r = regulatory_hint_user(data, user_reg_hint_type);
Luis R. Rodriguezfe33eb32009-02-21 00:04:30 -05004688
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004689 return r;
4690}
4691
Javier Cardona24bdd9f2010-12-16 17:37:48 -08004692static int nl80211_get_mesh_config(struct sk_buff *skb,
Johannes Berg29cbe682010-12-03 09:20:44 +01004693 struct genl_info *info)
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004694{
Johannes Berg4c476992010-10-04 21:36:35 +02004695 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg4c476992010-10-04 21:36:35 +02004696 struct net_device *dev = info->user_ptr[1];
Johannes Berg29cbe682010-12-03 09:20:44 +01004697 struct wireless_dev *wdev = dev->ieee80211_ptr;
4698 struct mesh_config cur_params;
4699 int err = 0;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004700 void *hdr;
4701 struct nlattr *pinfoattr;
4702 struct sk_buff *msg;
4703
Johannes Berg29cbe682010-12-03 09:20:44 +01004704 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT)
4705 return -EOPNOTSUPP;
4706
Javier Cardona24bdd9f2010-12-16 17:37:48 -08004707 if (!rdev->ops->get_mesh_config)
Johannes Berg4c476992010-10-04 21:36:35 +02004708 return -EOPNOTSUPP;
Jouni Malinenf3f92582009-03-20 17:57:36 +02004709
Johannes Berg29cbe682010-12-03 09:20:44 +01004710 wdev_lock(wdev);
4711 /* If not connected, get default parameters */
4712 if (!wdev->mesh_id_len)
4713 memcpy(&cur_params, &default_mesh_config, sizeof(cur_params));
4714 else
Hila Gonene35e4d22012-06-27 17:19:42 +03004715 err = rdev_get_mesh_config(rdev, dev, &cur_params);
Johannes Berg29cbe682010-12-03 09:20:44 +01004716 wdev_unlock(wdev);
4717
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004718 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02004719 return err;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004720
4721 /* Draw up a netlink message to send back */
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07004722 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02004723 if (!msg)
4724 return -ENOMEM;
Eric W. Biederman15e47302012-09-07 20:12:54 +00004725 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Javier Cardona24bdd9f2010-12-16 17:37:48 -08004726 NL80211_CMD_GET_MESH_CONFIG);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004727 if (!hdr)
Julia Lawallefe1cf02011-01-28 15:17:11 +01004728 goto out;
Javier Cardona24bdd9f2010-12-16 17:37:48 -08004729 pinfoattr = nla_nest_start(msg, NL80211_ATTR_MESH_CONFIG);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004730 if (!pinfoattr)
4731 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04004732 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
4733 nla_put_u16(msg, NL80211_MESHCONF_RETRY_TIMEOUT,
4734 cur_params.dot11MeshRetryTimeout) ||
4735 nla_put_u16(msg, NL80211_MESHCONF_CONFIRM_TIMEOUT,
4736 cur_params.dot11MeshConfirmTimeout) ||
4737 nla_put_u16(msg, NL80211_MESHCONF_HOLDING_TIMEOUT,
4738 cur_params.dot11MeshHoldingTimeout) ||
4739 nla_put_u16(msg, NL80211_MESHCONF_MAX_PEER_LINKS,
4740 cur_params.dot11MeshMaxPeerLinks) ||
4741 nla_put_u8(msg, NL80211_MESHCONF_MAX_RETRIES,
4742 cur_params.dot11MeshMaxRetries) ||
4743 nla_put_u8(msg, NL80211_MESHCONF_TTL,
4744 cur_params.dot11MeshTTL) ||
4745 nla_put_u8(msg, NL80211_MESHCONF_ELEMENT_TTL,
4746 cur_params.element_ttl) ||
4747 nla_put_u8(msg, NL80211_MESHCONF_AUTO_OPEN_PLINKS,
4748 cur_params.auto_open_plinks) ||
John W. Linville7eab0f62012-04-12 14:25:14 -04004749 nla_put_u32(msg, NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR,
4750 cur_params.dot11MeshNbrOffsetMaxNeighbor) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04004751 nla_put_u8(msg, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES,
4752 cur_params.dot11MeshHWMPmaxPREQretries) ||
4753 nla_put_u32(msg, NL80211_MESHCONF_PATH_REFRESH_TIME,
4754 cur_params.path_refresh_time) ||
4755 nla_put_u16(msg, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT,
4756 cur_params.min_discovery_timeout) ||
4757 nla_put_u32(msg, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT,
4758 cur_params.dot11MeshHWMPactivePathTimeout) ||
4759 nla_put_u16(msg, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL,
4760 cur_params.dot11MeshHWMPpreqMinInterval) ||
4761 nla_put_u16(msg, NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL,
4762 cur_params.dot11MeshHWMPperrMinInterval) ||
4763 nla_put_u16(msg, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME,
4764 cur_params.dot11MeshHWMPnetDiameterTraversalTime) ||
4765 nla_put_u8(msg, NL80211_MESHCONF_HWMP_ROOTMODE,
4766 cur_params.dot11MeshHWMPRootMode) ||
4767 nla_put_u16(msg, NL80211_MESHCONF_HWMP_RANN_INTERVAL,
4768 cur_params.dot11MeshHWMPRannInterval) ||
4769 nla_put_u8(msg, NL80211_MESHCONF_GATE_ANNOUNCEMENTS,
4770 cur_params.dot11MeshGateAnnouncementProtocol) ||
4771 nla_put_u8(msg, NL80211_MESHCONF_FORWARDING,
4772 cur_params.dot11MeshForwarding) ||
4773 nla_put_u32(msg, NL80211_MESHCONF_RSSI_THRESHOLD,
Ashok Nagarajan70c33ea2012-04-30 14:20:32 -07004774 cur_params.rssi_threshold) ||
4775 nla_put_u32(msg, NL80211_MESHCONF_HT_OPMODE,
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08004776 cur_params.ht_opmode) ||
4777 nla_put_u32(msg, NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT,
4778 cur_params.dot11MeshHWMPactivePathToRootTimeout) ||
4779 nla_put_u16(msg, NL80211_MESHCONF_HWMP_ROOT_INTERVAL,
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +08004780 cur_params.dot11MeshHWMProotInterval) ||
4781 nla_put_u16(msg, NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL,
Marco Porsch3b1c5a52013-01-07 16:04:52 +01004782 cur_params.dot11MeshHWMPconfirmationInterval) ||
4783 nla_put_u32(msg, NL80211_MESHCONF_POWER_MODE,
4784 cur_params.power_mode) ||
4785 nla_put_u16(msg, NL80211_MESHCONF_AWAKE_WINDOW,
Colleen Twitty8e7c0532013-06-03 09:53:39 -07004786 cur_params.dot11MeshAwakeWindowDuration) ||
4787 nla_put_u32(msg, NL80211_MESHCONF_PLINK_TIMEOUT,
4788 cur_params.plink_timeout))
David S. Miller9360ffd2012-03-29 04:41:26 -04004789 goto nla_put_failure;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004790 nla_nest_end(msg, pinfoattr);
4791 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02004792 return genlmsg_reply(msg, info);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004793
Johannes Berg3b858752009-03-12 09:55:09 +01004794 nla_put_failure:
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004795 genlmsg_cancel(msg, hdr);
Julia Lawallefe1cf02011-01-28 15:17:11 +01004796 out:
Yuri Ershovd080e272010-06-29 15:08:07 +04004797 nlmsg_free(msg);
Johannes Berg4c476992010-10-04 21:36:35 +02004798 return -ENOBUFS;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004799}
4800
Alexey Dobriyanb54452b2010-02-18 08:14:31 +00004801static const struct nla_policy nl80211_meshconf_params_policy[NL80211_MESHCONF_ATTR_MAX+1] = {
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004802 [NL80211_MESHCONF_RETRY_TIMEOUT] = { .type = NLA_U16 },
4803 [NL80211_MESHCONF_CONFIRM_TIMEOUT] = { .type = NLA_U16 },
4804 [NL80211_MESHCONF_HOLDING_TIMEOUT] = { .type = NLA_U16 },
4805 [NL80211_MESHCONF_MAX_PEER_LINKS] = { .type = NLA_U16 },
4806 [NL80211_MESHCONF_MAX_RETRIES] = { .type = NLA_U8 },
4807 [NL80211_MESHCONF_TTL] = { .type = NLA_U8 },
Javier Cardona45904f22010-12-03 09:20:40 +01004808 [NL80211_MESHCONF_ELEMENT_TTL] = { .type = NLA_U8 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004809 [NL80211_MESHCONF_AUTO_OPEN_PLINKS] = { .type = NLA_U8 },
Javier Cardonad299a1f2012-03-31 11:31:33 -07004810 [NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR] = { .type = NLA_U32 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004811 [NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES] = { .type = NLA_U8 },
4812 [NL80211_MESHCONF_PATH_REFRESH_TIME] = { .type = NLA_U32 },
4813 [NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT] = { .type = NLA_U16 },
4814 [NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT] = { .type = NLA_U32 },
4815 [NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL] = { .type = NLA_U16 },
Thomas Pedersendca7e942011-11-24 17:15:24 -08004816 [NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL] = { .type = NLA_U16 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004817 [NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME] = { .type = NLA_U16 },
Javier Cardona699403d2011-08-09 16:45:09 -07004818 [NL80211_MESHCONF_HWMP_ROOTMODE] = { .type = NLA_U8 },
Javier Cardona0507e152011-08-09 16:45:10 -07004819 [NL80211_MESHCONF_HWMP_RANN_INTERVAL] = { .type = NLA_U16 },
Javier Cardona16dd7262011-08-09 16:45:11 -07004820 [NL80211_MESHCONF_GATE_ANNOUNCEMENTS] = { .type = NLA_U8 },
Chun-Yeow Yeoh94f90652012-01-21 01:02:16 +08004821 [NL80211_MESHCONF_FORWARDING] = { .type = NLA_U8 },
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004822 [NL80211_MESHCONF_RSSI_THRESHOLD] = { .type = NLA_U32 },
4823 [NL80211_MESHCONF_HT_OPMODE] = { .type = NLA_U16 },
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08004824 [NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT] = { .type = NLA_U32 },
4825 [NL80211_MESHCONF_HWMP_ROOT_INTERVAL] = { .type = NLA_U16 },
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +08004826 [NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL] = { .type = NLA_U16 },
Marco Porsch3b1c5a52013-01-07 16:04:52 +01004827 [NL80211_MESHCONF_POWER_MODE] = { .type = NLA_U32 },
4828 [NL80211_MESHCONF_AWAKE_WINDOW] = { .type = NLA_U16 },
Colleen Twitty8e7c0532013-06-03 09:53:39 -07004829 [NL80211_MESHCONF_PLINK_TIMEOUT] = { .type = NLA_U32 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004830};
4831
Javier Cardonac80d5452010-12-16 17:37:49 -08004832static const struct nla_policy
4833 nl80211_mesh_setup_params_policy[NL80211_MESH_SETUP_ATTR_MAX+1] = {
Javier Cardonad299a1f2012-03-31 11:31:33 -07004834 [NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC] = { .type = NLA_U8 },
Javier Cardonac80d5452010-12-16 17:37:49 -08004835 [NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL] = { .type = NLA_U8 },
4836 [NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC] = { .type = NLA_U8 },
Javier Cardona15d5dda2011-04-07 15:08:28 -07004837 [NL80211_MESH_SETUP_USERSPACE_AUTH] = { .type = NLA_FLAG },
Colleen Twitty6e16d902013-05-08 11:45:59 -07004838 [NL80211_MESH_SETUP_AUTH_PROTOCOL] = { .type = NLA_U8 },
Thomas Pedersenbb2798d2013-03-04 13:06:10 -08004839 [NL80211_MESH_SETUP_USERSPACE_MPM] = { .type = NLA_FLAG },
Javier Cardona581a8b02011-04-07 15:08:27 -07004840 [NL80211_MESH_SETUP_IE] = { .type = NLA_BINARY,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004841 .len = IEEE80211_MAX_DATA_LEN },
Javier Cardonab130e5c2011-05-03 16:57:07 -07004842 [NL80211_MESH_SETUP_USERSPACE_AMPE] = { .type = NLA_FLAG },
Javier Cardonac80d5452010-12-16 17:37:49 -08004843};
4844
Javier Cardona24bdd9f2010-12-16 17:37:48 -08004845static int nl80211_parse_mesh_config(struct genl_info *info,
Johannes Bergbd90fdc2010-12-03 09:20:43 +01004846 struct mesh_config *cfg,
4847 u32 *mask_out)
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004848{
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004849 struct nlattr *tb[NL80211_MESHCONF_ATTR_MAX + 1];
Johannes Bergbd90fdc2010-12-03 09:20:43 +01004850 u32 mask = 0;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004851
Marco Porschea54fba2013-01-07 16:04:48 +01004852#define FILL_IN_MESH_PARAM_IF_SET(tb, cfg, param, min, max, mask, attr, fn) \
4853do { \
4854 if (tb[attr]) { \
4855 if (fn(tb[attr]) < min || fn(tb[attr]) > max) \
4856 return -EINVAL; \
4857 cfg->param = fn(tb[attr]); \
4858 mask |= (1 << (attr - 1)); \
4859 } \
4860} while (0)
Johannes Bergbd90fdc2010-12-03 09:20:43 +01004861
4862
Javier Cardona24bdd9f2010-12-16 17:37:48 -08004863 if (!info->attrs[NL80211_ATTR_MESH_CONFIG])
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004864 return -EINVAL;
4865 if (nla_parse_nested(tb, NL80211_MESHCONF_ATTR_MAX,
Javier Cardona24bdd9f2010-12-16 17:37:48 -08004866 info->attrs[NL80211_ATTR_MESH_CONFIG],
Johannes Bergbd90fdc2010-12-03 09:20:43 +01004867 nl80211_meshconf_params_policy))
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004868 return -EINVAL;
4869
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004870 /* This makes sure that there aren't more than 32 mesh config
4871 * parameters (otherwise our bitfield scheme would not work.) */
4872 BUILD_BUG_ON(NL80211_MESHCONF_ATTR_MAX > 32);
4873
4874 /* Fill in the params struct */
Marco Porschea54fba2013-01-07 16:04:48 +01004875 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshRetryTimeout, 1, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004876 mask, NL80211_MESHCONF_RETRY_TIMEOUT,
4877 nla_get_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01004878 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshConfirmTimeout, 1, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004879 mask, NL80211_MESHCONF_CONFIRM_TIMEOUT,
4880 nla_get_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01004881 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHoldingTimeout, 1, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004882 mask, NL80211_MESHCONF_HOLDING_TIMEOUT,
4883 nla_get_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01004884 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxPeerLinks, 0, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004885 mask, NL80211_MESHCONF_MAX_PEER_LINKS,
4886 nla_get_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01004887 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxRetries, 0, 16,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004888 mask, NL80211_MESHCONF_MAX_RETRIES,
4889 nla_get_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01004890 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshTTL, 1, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004891 mask, NL80211_MESHCONF_TTL, nla_get_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01004892 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, element_ttl, 1, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004893 mask, NL80211_MESHCONF_ELEMENT_TTL,
4894 nla_get_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01004895 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, auto_open_plinks, 0, 1,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004896 mask, NL80211_MESHCONF_AUTO_OPEN_PLINKS,
4897 nla_get_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01004898 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshNbrOffsetMaxNeighbor,
4899 1, 255, mask,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004900 NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR,
4901 nla_get_u32);
Marco Porschea54fba2013-01-07 16:04:48 +01004902 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPmaxPREQretries, 0, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004903 mask, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES,
4904 nla_get_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01004905 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, path_refresh_time, 1, 65535,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004906 mask, NL80211_MESHCONF_PATH_REFRESH_TIME,
4907 nla_get_u32);
Marco Porschea54fba2013-01-07 16:04:48 +01004908 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, min_discovery_timeout, 1, 65535,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004909 mask, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT,
4910 nla_get_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01004911 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathTimeout,
4912 1, 65535, mask,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004913 NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT,
4914 nla_get_u32);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004915 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPpreqMinInterval,
Marco Porschea54fba2013-01-07 16:04:48 +01004916 1, 65535, mask,
4917 NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004918 nla_get_u16);
Thomas Pedersendca7e942011-11-24 17:15:24 -08004919 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPperrMinInterval,
Marco Porschea54fba2013-01-07 16:04:48 +01004920 1, 65535, mask,
4921 NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004922 nla_get_u16);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004923 FILL_IN_MESH_PARAM_IF_SET(tb, cfg,
Marco Porschea54fba2013-01-07 16:04:48 +01004924 dot11MeshHWMPnetDiameterTraversalTime,
4925 1, 65535, mask,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004926 NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME,
4927 nla_get_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01004928 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRootMode, 0, 4,
4929 mask, NL80211_MESHCONF_HWMP_ROOTMODE,
4930 nla_get_u8);
4931 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRannInterval, 1, 65535,
4932 mask, NL80211_MESHCONF_HWMP_RANN_INTERVAL,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004933 nla_get_u16);
Rui Paulo63c57232009-11-09 23:46:57 +00004934 FILL_IN_MESH_PARAM_IF_SET(tb, cfg,
Marco Porschea54fba2013-01-07 16:04:48 +01004935 dot11MeshGateAnnouncementProtocol, 0, 1,
4936 mask, NL80211_MESHCONF_GATE_ANNOUNCEMENTS,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004937 nla_get_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01004938 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshForwarding, 0, 1,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004939 mask, NL80211_MESHCONF_FORWARDING,
4940 nla_get_u8);
Chun-Yeow Yeoh83374fe2013-07-11 18:24:03 +08004941 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, rssi_threshold, -255, 0,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004942 mask, NL80211_MESHCONF_RSSI_THRESHOLD,
Chun-Yeow Yeoh83374fe2013-07-11 18:24:03 +08004943 nla_get_s32);
Marco Porschea54fba2013-01-07 16:04:48 +01004944 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, ht_opmode, 0, 16,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004945 mask, NL80211_MESHCONF_HT_OPMODE,
4946 nla_get_u16);
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08004947 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathToRootTimeout,
Marco Porschea54fba2013-01-07 16:04:48 +01004948 1, 65535, mask,
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08004949 NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT,
4950 nla_get_u32);
Marco Porschea54fba2013-01-07 16:04:48 +01004951 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMProotInterval, 1, 65535,
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08004952 mask, NL80211_MESHCONF_HWMP_ROOT_INTERVAL,
4953 nla_get_u16);
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +08004954 FILL_IN_MESH_PARAM_IF_SET(tb, cfg,
Marco Porschea54fba2013-01-07 16:04:48 +01004955 dot11MeshHWMPconfirmationInterval,
4956 1, 65535, mask,
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +08004957 NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL,
4958 nla_get_u16);
Marco Porsch3b1c5a52013-01-07 16:04:52 +01004959 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, power_mode,
4960 NL80211_MESH_POWER_ACTIVE,
4961 NL80211_MESH_POWER_MAX,
4962 mask, NL80211_MESHCONF_POWER_MODE,
4963 nla_get_u32);
4964 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshAwakeWindowDuration,
4965 0, 65535, mask,
4966 NL80211_MESHCONF_AWAKE_WINDOW, nla_get_u16);
Colleen Twitty8e7c0532013-06-03 09:53:39 -07004967 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, plink_timeout, 1, 0xffffffff,
4968 mask, NL80211_MESHCONF_PLINK_TIMEOUT,
4969 nla_get_u32);
Johannes Bergbd90fdc2010-12-03 09:20:43 +01004970 if (mask_out)
4971 *mask_out = mask;
Javier Cardonac80d5452010-12-16 17:37:49 -08004972
Johannes Bergbd90fdc2010-12-03 09:20:43 +01004973 return 0;
4974
4975#undef FILL_IN_MESH_PARAM_IF_SET
4976}
4977
Javier Cardonac80d5452010-12-16 17:37:49 -08004978static int nl80211_parse_mesh_setup(struct genl_info *info,
4979 struct mesh_setup *setup)
4980{
Thomas Pedersenbb2798d2013-03-04 13:06:10 -08004981 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Javier Cardonac80d5452010-12-16 17:37:49 -08004982 struct nlattr *tb[NL80211_MESH_SETUP_ATTR_MAX + 1];
4983
4984 if (!info->attrs[NL80211_ATTR_MESH_SETUP])
4985 return -EINVAL;
4986 if (nla_parse_nested(tb, NL80211_MESH_SETUP_ATTR_MAX,
4987 info->attrs[NL80211_ATTR_MESH_SETUP],
4988 nl80211_mesh_setup_params_policy))
4989 return -EINVAL;
4990
Javier Cardonad299a1f2012-03-31 11:31:33 -07004991 if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC])
4992 setup->sync_method =
4993 (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC])) ?
4994 IEEE80211_SYNC_METHOD_VENDOR :
4995 IEEE80211_SYNC_METHOD_NEIGHBOR_OFFSET;
4996
Javier Cardonac80d5452010-12-16 17:37:49 -08004997 if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL])
4998 setup->path_sel_proto =
4999 (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL])) ?
5000 IEEE80211_PATH_PROTOCOL_VENDOR :
5001 IEEE80211_PATH_PROTOCOL_HWMP;
5002
5003 if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC])
5004 setup->path_metric =
5005 (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC])) ?
5006 IEEE80211_PATH_METRIC_VENDOR :
5007 IEEE80211_PATH_METRIC_AIRTIME;
5008
Javier Cardona581a8b02011-04-07 15:08:27 -07005009
5010 if (tb[NL80211_MESH_SETUP_IE]) {
Javier Cardonac80d5452010-12-16 17:37:49 -08005011 struct nlattr *ieattr =
Javier Cardona581a8b02011-04-07 15:08:27 -07005012 tb[NL80211_MESH_SETUP_IE];
Javier Cardonac80d5452010-12-16 17:37:49 -08005013 if (!is_valid_ie_attr(ieattr))
5014 return -EINVAL;
Javier Cardona581a8b02011-04-07 15:08:27 -07005015 setup->ie = nla_data(ieattr);
5016 setup->ie_len = nla_len(ieattr);
Javier Cardonac80d5452010-12-16 17:37:49 -08005017 }
Thomas Pedersenbb2798d2013-03-04 13:06:10 -08005018 if (tb[NL80211_MESH_SETUP_USERSPACE_MPM] &&
5019 !(rdev->wiphy.features & NL80211_FEATURE_USERSPACE_MPM))
5020 return -EINVAL;
5021 setup->user_mpm = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_MPM]);
Javier Cardonab130e5c2011-05-03 16:57:07 -07005022 setup->is_authenticated = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AUTH]);
5023 setup->is_secure = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AMPE]);
Thomas Pedersenbb2798d2013-03-04 13:06:10 -08005024 if (setup->is_secure)
5025 setup->user_mpm = true;
Javier Cardonac80d5452010-12-16 17:37:49 -08005026
Colleen Twitty6e16d902013-05-08 11:45:59 -07005027 if (tb[NL80211_MESH_SETUP_AUTH_PROTOCOL]) {
5028 if (!setup->user_mpm)
5029 return -EINVAL;
5030 setup->auth_id =
5031 nla_get_u8(tb[NL80211_MESH_SETUP_AUTH_PROTOCOL]);
5032 }
5033
Javier Cardonac80d5452010-12-16 17:37:49 -08005034 return 0;
5035}
5036
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005037static int nl80211_update_mesh_config(struct sk_buff *skb,
Johannes Berg29cbe682010-12-03 09:20:44 +01005038 struct genl_info *info)
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005039{
5040 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5041 struct net_device *dev = info->user_ptr[1];
Johannes Berg29cbe682010-12-03 09:20:44 +01005042 struct wireless_dev *wdev = dev->ieee80211_ptr;
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005043 struct mesh_config cfg;
5044 u32 mask;
5045 int err;
5046
Johannes Berg29cbe682010-12-03 09:20:44 +01005047 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT)
5048 return -EOPNOTSUPP;
5049
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005050 if (!rdev->ops->update_mesh_config)
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005051 return -EOPNOTSUPP;
5052
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005053 err = nl80211_parse_mesh_config(info, &cfg, &mask);
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005054 if (err)
5055 return err;
5056
Johannes Berg29cbe682010-12-03 09:20:44 +01005057 wdev_lock(wdev);
5058 if (!wdev->mesh_id_len)
5059 err = -ENOLINK;
5060
5061 if (!err)
Hila Gonene35e4d22012-06-27 17:19:42 +03005062 err = rdev_update_mesh_config(rdev, dev, mask, &cfg);
Johannes Berg29cbe682010-12-03 09:20:44 +01005063
5064 wdev_unlock(wdev);
5065
5066 return err;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005067}
5068
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005069static int nl80211_get_reg(struct sk_buff *skb, struct genl_info *info)
5070{
Johannes Berg458f4f92012-12-06 15:47:38 +01005071 const struct ieee80211_regdomain *regdom;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005072 struct sk_buff *msg;
5073 void *hdr = NULL;
5074 struct nlattr *nl_reg_rules;
5075 unsigned int i;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005076
5077 if (!cfg80211_regdomain)
Johannes Berg5fe231e2013-05-08 21:45:15 +02005078 return -EINVAL;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005079
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07005080 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg5fe231e2013-05-08 21:45:15 +02005081 if (!msg)
5082 return -ENOBUFS;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005083
Eric W. Biederman15e47302012-09-07 20:12:54 +00005084 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005085 NL80211_CMD_GET_REG);
5086 if (!hdr)
Julia Lawallefe1cf02011-01-28 15:17:11 +01005087 goto put_failure;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005088
Luis R. Rodriguez57b5ce02012-07-12 11:49:18 -07005089 if (reg_last_request_cell_base() &&
5090 nla_put_u32(msg, NL80211_ATTR_USER_REG_HINT_TYPE,
5091 NL80211_USER_REG_HINT_CELL_BASE))
5092 goto nla_put_failure;
5093
Johannes Berg458f4f92012-12-06 15:47:38 +01005094 rcu_read_lock();
5095 regdom = rcu_dereference(cfg80211_regdomain);
5096
5097 if (nla_put_string(msg, NL80211_ATTR_REG_ALPHA2, regdom->alpha2) ||
5098 (regdom->dfs_region &&
5099 nla_put_u8(msg, NL80211_ATTR_DFS_REGION, regdom->dfs_region)))
5100 goto nla_put_failure_rcu;
5101
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005102 nl_reg_rules = nla_nest_start(msg, NL80211_ATTR_REG_RULES);
5103 if (!nl_reg_rules)
Johannes Berg458f4f92012-12-06 15:47:38 +01005104 goto nla_put_failure_rcu;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005105
Johannes Berg458f4f92012-12-06 15:47:38 +01005106 for (i = 0; i < regdom->n_reg_rules; i++) {
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005107 struct nlattr *nl_reg_rule;
5108 const struct ieee80211_reg_rule *reg_rule;
5109 const struct ieee80211_freq_range *freq_range;
5110 const struct ieee80211_power_rule *power_rule;
5111
Johannes Berg458f4f92012-12-06 15:47:38 +01005112 reg_rule = &regdom->reg_rules[i];
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005113 freq_range = &reg_rule->freq_range;
5114 power_rule = &reg_rule->power_rule;
5115
5116 nl_reg_rule = nla_nest_start(msg, i);
5117 if (!nl_reg_rule)
Johannes Berg458f4f92012-12-06 15:47:38 +01005118 goto nla_put_failure_rcu;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005119
David S. Miller9360ffd2012-03-29 04:41:26 -04005120 if (nla_put_u32(msg, NL80211_ATTR_REG_RULE_FLAGS,
5121 reg_rule->flags) ||
5122 nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_START,
5123 freq_range->start_freq_khz) ||
5124 nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_END,
5125 freq_range->end_freq_khz) ||
5126 nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_MAX_BW,
5127 freq_range->max_bandwidth_khz) ||
5128 nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN,
5129 power_rule->max_antenna_gain) ||
5130 nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_EIRP,
5131 power_rule->max_eirp))
Johannes Berg458f4f92012-12-06 15:47:38 +01005132 goto nla_put_failure_rcu;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005133
5134 nla_nest_end(msg, nl_reg_rule);
5135 }
Johannes Berg458f4f92012-12-06 15:47:38 +01005136 rcu_read_unlock();
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005137
5138 nla_nest_end(msg, nl_reg_rules);
5139
5140 genlmsg_end(msg, hdr);
Johannes Berg5fe231e2013-05-08 21:45:15 +02005141 return genlmsg_reply(msg, info);
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005142
Johannes Berg458f4f92012-12-06 15:47:38 +01005143nla_put_failure_rcu:
5144 rcu_read_unlock();
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005145nla_put_failure:
5146 genlmsg_cancel(msg, hdr);
Julia Lawallefe1cf02011-01-28 15:17:11 +01005147put_failure:
Yuri Ershovd080e272010-06-29 15:08:07 +04005148 nlmsg_free(msg);
Johannes Berg5fe231e2013-05-08 21:45:15 +02005149 return -EMSGSIZE;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005150}
5151
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005152static int nl80211_set_reg(struct sk_buff *skb, struct genl_info *info)
5153{
5154 struct nlattr *tb[NL80211_REG_RULE_ATTR_MAX + 1];
5155 struct nlattr *nl_reg_rule;
5156 char *alpha2 = NULL;
5157 int rem_reg_rules = 0, r = 0;
5158 u32 num_rules = 0, rule_idx = 0, size_of_regd;
Luis R. Rodriguez4c7d3982013-11-13 18:54:02 +01005159 enum nl80211_dfs_regions dfs_region = NL80211_DFS_UNSET;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005160 struct ieee80211_regdomain *rd = NULL;
5161
5162 if (!info->attrs[NL80211_ATTR_REG_ALPHA2])
5163 return -EINVAL;
5164
5165 if (!info->attrs[NL80211_ATTR_REG_RULES])
5166 return -EINVAL;
5167
5168 alpha2 = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]);
5169
Luis R. Rodriguez8b60b072011-10-11 10:59:02 -07005170 if (info->attrs[NL80211_ATTR_DFS_REGION])
5171 dfs_region = nla_get_u8(info->attrs[NL80211_ATTR_DFS_REGION]);
5172
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005173 nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES],
Johannes Berg1a919312012-12-03 17:21:11 +01005174 rem_reg_rules) {
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005175 num_rules++;
5176 if (num_rules > NL80211_MAX_SUPP_REG_RULES)
Luis R. Rodriguez4776c6e2009-05-13 17:04:39 -04005177 return -EINVAL;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005178 }
5179
Luis R. Rodrigueze4387682013-11-05 09:18:01 -08005180 if (!reg_is_valid_request(alpha2))
5181 return -EINVAL;
5182
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005183 size_of_regd = sizeof(struct ieee80211_regdomain) +
Johannes Berg1a919312012-12-03 17:21:11 +01005184 num_rules * sizeof(struct ieee80211_reg_rule);
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005185
5186 rd = kzalloc(size_of_regd, GFP_KERNEL);
Johannes Berg6913b492012-12-04 00:48:59 +01005187 if (!rd)
5188 return -ENOMEM;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005189
5190 rd->n_reg_rules = num_rules;
5191 rd->alpha2[0] = alpha2[0];
5192 rd->alpha2[1] = alpha2[1];
5193
Luis R. Rodriguez8b60b072011-10-11 10:59:02 -07005194 /*
5195 * Disable DFS master mode if the DFS region was
5196 * not supported or known on this kernel.
5197 */
5198 if (reg_supported_dfs_region(dfs_region))
5199 rd->dfs_region = dfs_region;
5200
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005201 nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES],
Johannes Berg1a919312012-12-03 17:21:11 +01005202 rem_reg_rules) {
Johannes Bergae811e22014-01-24 10:17:47 +01005203 r = nla_parse(tb, NL80211_REG_RULE_ATTR_MAX,
5204 nla_data(nl_reg_rule), nla_len(nl_reg_rule),
5205 reg_rule_policy);
5206 if (r)
5207 goto bad_reg;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005208 r = parse_reg_rule(tb, &rd->reg_rules[rule_idx]);
5209 if (r)
5210 goto bad_reg;
5211
5212 rule_idx++;
5213
Luis R. Rodriguezd0e18f82009-05-13 17:04:40 -04005214 if (rule_idx > NL80211_MAX_SUPP_REG_RULES) {
5215 r = -EINVAL;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005216 goto bad_reg;
Luis R. Rodriguezd0e18f82009-05-13 17:04:40 -04005217 }
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005218 }
5219
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005220 r = set_regdom(rd);
Johannes Berg6913b492012-12-04 00:48:59 +01005221 /* set_regdom took ownership */
Johannes Berg1a919312012-12-03 17:21:11 +01005222 rd = NULL;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005223
Johannes Bergd2372b32008-10-24 20:32:20 +02005224 bad_reg:
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005225 kfree(rd);
Luis R. Rodriguezd0e18f82009-05-13 17:04:40 -04005226 return r;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005227}
5228
Johannes Berg83f5e2c2009-06-17 17:41:49 +02005229static int validate_scan_freqs(struct nlattr *freqs)
5230{
5231 struct nlattr *attr1, *attr2;
5232 int n_channels = 0, tmp1, tmp2;
5233
5234 nla_for_each_nested(attr1, freqs, tmp1) {
5235 n_channels++;
5236 /*
5237 * Some hardware has a limited channel list for
5238 * scanning, and it is pretty much nonsensical
5239 * to scan for a channel twice, so disallow that
5240 * and don't require drivers to check that the
5241 * channel list they get isn't longer than what
5242 * they can scan, as long as they can scan all
5243 * the channels they registered at once.
5244 */
5245 nla_for_each_nested(attr2, freqs, tmp2)
5246 if (attr1 != attr2 &&
5247 nla_get_u32(attr1) == nla_get_u32(attr2))
5248 return 0;
5249 }
5250
5251 return n_channels;
5252}
5253
Johannes Berg2a519312009-02-10 21:25:55 +01005254static int nl80211_trigger_scan(struct sk_buff *skb, struct genl_info *info)
5255{
Johannes Berg4c476992010-10-04 21:36:35 +02005256 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Bergfd014282012-06-18 19:17:03 +02005257 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg2a519312009-02-10 21:25:55 +01005258 struct cfg80211_scan_request *request;
Johannes Berg2a519312009-02-10 21:25:55 +01005259 struct nlattr *attr;
5260 struct wiphy *wiphy;
Johannes Berg83f5e2c2009-06-17 17:41:49 +02005261 int err, tmp, n_ssids = 0, n_channels, i;
Jouni Malinen70692ad2009-02-16 19:39:13 +02005262 size_t ie_len;
Johannes Berg2a519312009-02-10 21:25:55 +01005263
Johannes Bergf4a11bb2009-03-27 12:40:28 +01005264 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
5265 return -EINVAL;
5266
Johannes Berg79c97e92009-07-07 03:56:12 +02005267 wiphy = &rdev->wiphy;
Johannes Berg2a519312009-02-10 21:25:55 +01005268
Johannes Berg4c476992010-10-04 21:36:35 +02005269 if (!rdev->ops->scan)
5270 return -EOPNOTSUPP;
Johannes Berg2a519312009-02-10 21:25:55 +01005271
Johannes Bergf9f47522013-03-19 15:04:07 +01005272 if (rdev->scan_req) {
5273 err = -EBUSY;
5274 goto unlock;
5275 }
Johannes Berg2a519312009-02-10 21:25:55 +01005276
5277 if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
Johannes Berg83f5e2c2009-06-17 17:41:49 +02005278 n_channels = validate_scan_freqs(
5279 info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]);
Johannes Bergf9f47522013-03-19 15:04:07 +01005280 if (!n_channels) {
5281 err = -EINVAL;
5282 goto unlock;
5283 }
Johannes Berg2a519312009-02-10 21:25:55 +01005284 } else {
Ilan Peerbdfbec22014-01-09 11:37:23 +02005285 n_channels = ieee80211_get_num_supported_channels(wiphy);
Johannes Berg2a519312009-02-10 21:25:55 +01005286 }
5287
5288 if (info->attrs[NL80211_ATTR_SCAN_SSIDS])
5289 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp)
5290 n_ssids++;
5291
Johannes Bergf9f47522013-03-19 15:04:07 +01005292 if (n_ssids > wiphy->max_scan_ssids) {
5293 err = -EINVAL;
5294 goto unlock;
5295 }
Johannes Berg2a519312009-02-10 21:25:55 +01005296
Jouni Malinen70692ad2009-02-16 19:39:13 +02005297 if (info->attrs[NL80211_ATTR_IE])
5298 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
5299 else
5300 ie_len = 0;
5301
Johannes Bergf9f47522013-03-19 15:04:07 +01005302 if (ie_len > wiphy->max_scan_ie_len) {
5303 err = -EINVAL;
5304 goto unlock;
5305 }
Johannes Berg18a83652009-03-31 12:12:05 +02005306
Johannes Berg2a519312009-02-10 21:25:55 +01005307 request = kzalloc(sizeof(*request)
Luciano Coelhoa2cd43c2011-05-18 11:42:03 +03005308 + sizeof(*request->ssids) * n_ssids
5309 + sizeof(*request->channels) * n_channels
Jouni Malinen70692ad2009-02-16 19:39:13 +02005310 + ie_len, GFP_KERNEL);
Johannes Bergf9f47522013-03-19 15:04:07 +01005311 if (!request) {
5312 err = -ENOMEM;
5313 goto unlock;
5314 }
Johannes Berg2a519312009-02-10 21:25:55 +01005315
Johannes Berg2a519312009-02-10 21:25:55 +01005316 if (n_ssids)
Johannes Berg5ba63532009-08-07 17:54:07 +02005317 request->ssids = (void *)&request->channels[n_channels];
Johannes Berg2a519312009-02-10 21:25:55 +01005318 request->n_ssids = n_ssids;
Jouni Malinen70692ad2009-02-16 19:39:13 +02005319 if (ie_len) {
5320 if (request->ssids)
5321 request->ie = (void *)(request->ssids + n_ssids);
5322 else
5323 request->ie = (void *)(request->channels + n_channels);
5324 }
Johannes Berg2a519312009-02-10 21:25:55 +01005325
Johannes Berg584991d2009-11-02 13:32:03 +01005326 i = 0;
Johannes Berg2a519312009-02-10 21:25:55 +01005327 if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
5328 /* user specified, bail out if channel not found */
Johannes Berg2a519312009-02-10 21:25:55 +01005329 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_FREQUENCIES], tmp) {
Johannes Berg584991d2009-11-02 13:32:03 +01005330 struct ieee80211_channel *chan;
5331
5332 chan = ieee80211_get_channel(wiphy, nla_get_u32(attr));
5333
5334 if (!chan) {
Johannes Berg2a519312009-02-10 21:25:55 +01005335 err = -EINVAL;
5336 goto out_free;
5337 }
Johannes Berg584991d2009-11-02 13:32:03 +01005338
5339 /* ignore disabled channels */
5340 if (chan->flags & IEEE80211_CHAN_DISABLED)
5341 continue;
5342
5343 request->channels[i] = chan;
Johannes Berg2a519312009-02-10 21:25:55 +01005344 i++;
5345 }
5346 } else {
Johannes Berg34850ab2011-07-18 18:08:35 +02005347 enum ieee80211_band band;
5348
Johannes Berg2a519312009-02-10 21:25:55 +01005349 /* all channels */
Johannes Berg2a519312009-02-10 21:25:55 +01005350 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
5351 int j;
5352 if (!wiphy->bands[band])
5353 continue;
5354 for (j = 0; j < wiphy->bands[band]->n_channels; j++) {
Johannes Berg584991d2009-11-02 13:32:03 +01005355 struct ieee80211_channel *chan;
5356
5357 chan = &wiphy->bands[band]->channels[j];
5358
5359 if (chan->flags & IEEE80211_CHAN_DISABLED)
5360 continue;
5361
5362 request->channels[i] = chan;
Johannes Berg2a519312009-02-10 21:25:55 +01005363 i++;
5364 }
5365 }
5366 }
5367
Johannes Berg584991d2009-11-02 13:32:03 +01005368 if (!i) {
5369 err = -EINVAL;
5370 goto out_free;
5371 }
5372
5373 request->n_channels = i;
5374
Johannes Berg2a519312009-02-10 21:25:55 +01005375 i = 0;
5376 if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) {
5377 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) {
Luciano Coelho57a27e12011-06-07 20:42:26 +03005378 if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) {
Johannes Berg2a519312009-02-10 21:25:55 +01005379 err = -EINVAL;
5380 goto out_free;
5381 }
Luciano Coelho57a27e12011-06-07 20:42:26 +03005382 request->ssids[i].ssid_len = nla_len(attr);
Johannes Berg2a519312009-02-10 21:25:55 +01005383 memcpy(request->ssids[i].ssid, nla_data(attr), nla_len(attr));
Johannes Berg2a519312009-02-10 21:25:55 +01005384 i++;
5385 }
5386 }
5387
Jouni Malinen70692ad2009-02-16 19:39:13 +02005388 if (info->attrs[NL80211_ATTR_IE]) {
5389 request->ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Johannes Bergde95a542009-04-01 11:58:36 +02005390 memcpy((void *)request->ie,
5391 nla_data(info->attrs[NL80211_ATTR_IE]),
Jouni Malinen70692ad2009-02-16 19:39:13 +02005392 request->ie_len);
5393 }
5394
Johannes Berg34850ab2011-07-18 18:08:35 +02005395 for (i = 0; i < IEEE80211_NUM_BANDS; i++)
Johannes Berga401d2b2011-07-20 00:52:16 +02005396 if (wiphy->bands[i])
5397 request->rates[i] =
5398 (1 << wiphy->bands[i]->n_bitrates) - 1;
Johannes Berg34850ab2011-07-18 18:08:35 +02005399
5400 if (info->attrs[NL80211_ATTR_SCAN_SUPP_RATES]) {
5401 nla_for_each_nested(attr,
5402 info->attrs[NL80211_ATTR_SCAN_SUPP_RATES],
5403 tmp) {
5404 enum ieee80211_band band = nla_type(attr);
5405
Dan Carpenter84404622011-07-29 11:52:18 +03005406 if (band < 0 || band >= IEEE80211_NUM_BANDS) {
Johannes Berg34850ab2011-07-18 18:08:35 +02005407 err = -EINVAL;
5408 goto out_free;
5409 }
Felix Fietkau1b09cd82013-11-20 19:40:41 +01005410
5411 if (!wiphy->bands[band])
5412 continue;
5413
Johannes Berg34850ab2011-07-18 18:08:35 +02005414 err = ieee80211_get_ratemask(wiphy->bands[band],
5415 nla_data(attr),
5416 nla_len(attr),
5417 &request->rates[band]);
5418 if (err)
5419 goto out_free;
5420 }
5421 }
5422
Sam Leffler46856bb2012-10-11 21:03:32 -07005423 if (info->attrs[NL80211_ATTR_SCAN_FLAGS]) {
Sam Lefflered4737712012-10-11 21:03:31 -07005424 request->flags = nla_get_u32(
5425 info->attrs[NL80211_ATTR_SCAN_FLAGS]);
Johannes Berg00c3a6e2013-10-26 17:14:38 +02005426 if ((request->flags & NL80211_SCAN_FLAG_LOW_PRIORITY) &&
5427 !(wiphy->features & NL80211_FEATURE_LOW_PRIORITY_SCAN)) {
Sam Leffler46856bb2012-10-11 21:03:32 -07005428 err = -EOPNOTSUPP;
5429 goto out_free;
5430 }
5431 }
Sam Lefflered4737712012-10-11 21:03:31 -07005432
Rajkumar Manoharane9f935e2011-09-25 14:53:30 +05305433 request->no_cck =
5434 nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]);
5435
Johannes Bergfd014282012-06-18 19:17:03 +02005436 request->wdev = wdev;
Johannes Berg79c97e92009-07-07 03:56:12 +02005437 request->wiphy = &rdev->wiphy;
Sam Leffler15d60302012-10-11 21:03:34 -07005438 request->scan_start = jiffies;
Johannes Berg2a519312009-02-10 21:25:55 +01005439
Johannes Berg79c97e92009-07-07 03:56:12 +02005440 rdev->scan_req = request;
Hila Gonene35e4d22012-06-27 17:19:42 +03005441 err = rdev_scan(rdev, request);
Johannes Berg2a519312009-02-10 21:25:55 +01005442
Johannes Berg463d0182009-07-14 00:33:35 +02005443 if (!err) {
Johannes Bergfd014282012-06-18 19:17:03 +02005444 nl80211_send_scan_start(rdev, wdev);
5445 if (wdev->netdev)
5446 dev_hold(wdev->netdev);
Johannes Berg4c476992010-10-04 21:36:35 +02005447 } else {
Johannes Berg2a519312009-02-10 21:25:55 +01005448 out_free:
Johannes Berg79c97e92009-07-07 03:56:12 +02005449 rdev->scan_req = NULL;
Johannes Berg2a519312009-02-10 21:25:55 +01005450 kfree(request);
5451 }
Johannes Berg3b858752009-03-12 09:55:09 +01005452
Johannes Bergf9f47522013-03-19 15:04:07 +01005453 unlock:
Johannes Berg2a519312009-02-10 21:25:55 +01005454 return err;
5455}
5456
Luciano Coelho807f8a82011-05-11 17:09:35 +03005457static int nl80211_start_sched_scan(struct sk_buff *skb,
5458 struct genl_info *info)
5459{
5460 struct cfg80211_sched_scan_request *request;
5461 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5462 struct net_device *dev = info->user_ptr[1];
Luciano Coelho807f8a82011-05-11 17:09:35 +03005463 struct nlattr *attr;
5464 struct wiphy *wiphy;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005465 int err, tmp, n_ssids = 0, n_match_sets = 0, n_channels, i;
Luciano Coelhobbe6ad62011-05-11 17:09:37 +03005466 u32 interval;
Luciano Coelho807f8a82011-05-11 17:09:35 +03005467 enum ieee80211_band band;
5468 size_t ie_len;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005469 struct nlattr *tb[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1];
Luciano Coelho807f8a82011-05-11 17:09:35 +03005470
5471 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) ||
5472 !rdev->ops->sched_scan_start)
5473 return -EOPNOTSUPP;
5474
5475 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
5476 return -EINVAL;
5477
Luciano Coelhobbe6ad62011-05-11 17:09:37 +03005478 if (!info->attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL])
5479 return -EINVAL;
5480
5481 interval = nla_get_u32(info->attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]);
5482 if (interval == 0)
5483 return -EINVAL;
5484
Luciano Coelho807f8a82011-05-11 17:09:35 +03005485 wiphy = &rdev->wiphy;
5486
5487 if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
5488 n_channels = validate_scan_freqs(
5489 info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]);
5490 if (!n_channels)
5491 return -EINVAL;
5492 } else {
Ilan Peerbdfbec22014-01-09 11:37:23 +02005493 n_channels = ieee80211_get_num_supported_channels(wiphy);
Luciano Coelho807f8a82011-05-11 17:09:35 +03005494 }
5495
5496 if (info->attrs[NL80211_ATTR_SCAN_SSIDS])
5497 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS],
5498 tmp)
5499 n_ssids++;
5500
Luciano Coelho93b6aa62011-07-13 14:57:28 +03005501 if (n_ssids > wiphy->max_sched_scan_ssids)
Luciano Coelho807f8a82011-05-11 17:09:35 +03005502 return -EINVAL;
5503
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005504 if (info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH])
5505 nla_for_each_nested(attr,
5506 info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH],
5507 tmp)
5508 n_match_sets++;
5509
5510 if (n_match_sets > wiphy->max_match_sets)
5511 return -EINVAL;
5512
Luciano Coelho807f8a82011-05-11 17:09:35 +03005513 if (info->attrs[NL80211_ATTR_IE])
5514 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
5515 else
5516 ie_len = 0;
5517
Luciano Coelho5a865ba2011-07-13 14:57:29 +03005518 if (ie_len > wiphy->max_sched_scan_ie_len)
Luciano Coelho807f8a82011-05-11 17:09:35 +03005519 return -EINVAL;
5520
Luciano Coelhoc10841c2011-06-30 08:32:41 +03005521 if (rdev->sched_scan_req) {
5522 err = -EINPROGRESS;
5523 goto out;
5524 }
5525
Luciano Coelho807f8a82011-05-11 17:09:35 +03005526 request = kzalloc(sizeof(*request)
Luciano Coelhoa2cd43c2011-05-18 11:42:03 +03005527 + sizeof(*request->ssids) * n_ssids
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005528 + sizeof(*request->match_sets) * n_match_sets
Luciano Coelhoa2cd43c2011-05-18 11:42:03 +03005529 + sizeof(*request->channels) * n_channels
Luciano Coelho807f8a82011-05-11 17:09:35 +03005530 + ie_len, GFP_KERNEL);
Luciano Coelhoc10841c2011-06-30 08:32:41 +03005531 if (!request) {
5532 err = -ENOMEM;
5533 goto out;
5534 }
Luciano Coelho807f8a82011-05-11 17:09:35 +03005535
5536 if (n_ssids)
5537 request->ssids = (void *)&request->channels[n_channels];
5538 request->n_ssids = n_ssids;
5539 if (ie_len) {
5540 if (request->ssids)
5541 request->ie = (void *)(request->ssids + n_ssids);
5542 else
5543 request->ie = (void *)(request->channels + n_channels);
5544 }
5545
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005546 if (n_match_sets) {
5547 if (request->ie)
5548 request->match_sets = (void *)(request->ie + ie_len);
5549 else if (request->ssids)
5550 request->match_sets =
5551 (void *)(request->ssids + n_ssids);
5552 else
5553 request->match_sets =
5554 (void *)(request->channels + n_channels);
5555 }
5556 request->n_match_sets = n_match_sets;
5557
Luciano Coelho807f8a82011-05-11 17:09:35 +03005558 i = 0;
5559 if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
5560 /* user specified, bail out if channel not found */
5561 nla_for_each_nested(attr,
5562 info->attrs[NL80211_ATTR_SCAN_FREQUENCIES],
5563 tmp) {
5564 struct ieee80211_channel *chan;
5565
5566 chan = ieee80211_get_channel(wiphy, nla_get_u32(attr));
5567
5568 if (!chan) {
5569 err = -EINVAL;
5570 goto out_free;
5571 }
5572
5573 /* ignore disabled channels */
5574 if (chan->flags & IEEE80211_CHAN_DISABLED)
5575 continue;
5576
5577 request->channels[i] = chan;
5578 i++;
5579 }
5580 } else {
5581 /* all channels */
5582 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
5583 int j;
5584 if (!wiphy->bands[band])
5585 continue;
5586 for (j = 0; j < wiphy->bands[band]->n_channels; j++) {
5587 struct ieee80211_channel *chan;
5588
5589 chan = &wiphy->bands[band]->channels[j];
5590
5591 if (chan->flags & IEEE80211_CHAN_DISABLED)
5592 continue;
5593
5594 request->channels[i] = chan;
5595 i++;
5596 }
5597 }
5598 }
5599
5600 if (!i) {
5601 err = -EINVAL;
5602 goto out_free;
5603 }
5604
5605 request->n_channels = i;
5606
5607 i = 0;
5608 if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) {
5609 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS],
5610 tmp) {
Luciano Coelho57a27e12011-06-07 20:42:26 +03005611 if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) {
Luciano Coelho807f8a82011-05-11 17:09:35 +03005612 err = -EINVAL;
5613 goto out_free;
5614 }
Luciano Coelho57a27e12011-06-07 20:42:26 +03005615 request->ssids[i].ssid_len = nla_len(attr);
Luciano Coelho807f8a82011-05-11 17:09:35 +03005616 memcpy(request->ssids[i].ssid, nla_data(attr),
5617 nla_len(attr));
Luciano Coelho807f8a82011-05-11 17:09:35 +03005618 i++;
5619 }
5620 }
5621
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005622 i = 0;
5623 if (info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) {
5624 nla_for_each_nested(attr,
5625 info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH],
5626 tmp) {
Thomas Pedersen88e920b2012-06-21 11:09:54 -07005627 struct nlattr *ssid, *rssi;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005628
Johannes Bergae811e22014-01-24 10:17:47 +01005629 err = nla_parse(tb, NL80211_SCHED_SCAN_MATCH_ATTR_MAX,
5630 nla_data(attr), nla_len(attr),
5631 nl80211_match_policy);
5632 if (err)
5633 goto out_free;
Johannes Berg4a4ab0d2012-06-13 11:17:11 +02005634 ssid = tb[NL80211_SCHED_SCAN_MATCH_ATTR_SSID];
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005635 if (ssid) {
5636 if (nla_len(ssid) > IEEE80211_MAX_SSID_LEN) {
5637 err = -EINVAL;
5638 goto out_free;
5639 }
5640 memcpy(request->match_sets[i].ssid.ssid,
5641 nla_data(ssid), nla_len(ssid));
5642 request->match_sets[i].ssid.ssid_len =
5643 nla_len(ssid);
5644 }
Thomas Pedersen88e920b2012-06-21 11:09:54 -07005645 rssi = tb[NL80211_SCHED_SCAN_MATCH_ATTR_RSSI];
5646 if (rssi)
5647 request->rssi_thold = nla_get_u32(rssi);
5648 else
5649 request->rssi_thold =
5650 NL80211_SCAN_RSSI_THOLD_OFF;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005651 i++;
5652 }
5653 }
5654
Luciano Coelho807f8a82011-05-11 17:09:35 +03005655 if (info->attrs[NL80211_ATTR_IE]) {
5656 request->ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
5657 memcpy((void *)request->ie,
5658 nla_data(info->attrs[NL80211_ATTR_IE]),
5659 request->ie_len);
5660 }
5661
Sam Leffler46856bb2012-10-11 21:03:32 -07005662 if (info->attrs[NL80211_ATTR_SCAN_FLAGS]) {
Sam Lefflered4737712012-10-11 21:03:31 -07005663 request->flags = nla_get_u32(
5664 info->attrs[NL80211_ATTR_SCAN_FLAGS]);
Johannes Berg00c3a6e2013-10-26 17:14:38 +02005665 if ((request->flags & NL80211_SCAN_FLAG_LOW_PRIORITY) &&
5666 !(wiphy->features & NL80211_FEATURE_LOW_PRIORITY_SCAN)) {
Sam Leffler46856bb2012-10-11 21:03:32 -07005667 err = -EOPNOTSUPP;
5668 goto out_free;
5669 }
5670 }
Sam Lefflered4737712012-10-11 21:03:31 -07005671
Luciano Coelho807f8a82011-05-11 17:09:35 +03005672 request->dev = dev;
5673 request->wiphy = &rdev->wiphy;
Luciano Coelhobbe6ad62011-05-11 17:09:37 +03005674 request->interval = interval;
Sam Leffler15d60302012-10-11 21:03:34 -07005675 request->scan_start = jiffies;
Luciano Coelho807f8a82011-05-11 17:09:35 +03005676
Hila Gonene35e4d22012-06-27 17:19:42 +03005677 err = rdev_sched_scan_start(rdev, dev, request);
Luciano Coelho807f8a82011-05-11 17:09:35 +03005678 if (!err) {
5679 rdev->sched_scan_req = request;
5680 nl80211_send_sched_scan(rdev, dev,
5681 NL80211_CMD_START_SCHED_SCAN);
5682 goto out;
5683 }
5684
5685out_free:
5686 kfree(request);
5687out:
5688 return err;
5689}
5690
5691static int nl80211_stop_sched_scan(struct sk_buff *skb,
5692 struct genl_info *info)
5693{
5694 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5695
5696 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) ||
5697 !rdev->ops->sched_scan_stop)
5698 return -EOPNOTSUPP;
5699
Johannes Berg5fe231e2013-05-08 21:45:15 +02005700 return __cfg80211_stop_sched_scan(rdev, false);
Luciano Coelho807f8a82011-05-11 17:09:35 +03005701}
5702
Simon Wunderlich04f39042013-02-08 18:16:19 +01005703static int nl80211_start_radar_detection(struct sk_buff *skb,
5704 struct genl_info *info)
5705{
5706 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5707 struct net_device *dev = info->user_ptr[1];
5708 struct wireless_dev *wdev = dev->ieee80211_ptr;
5709 struct cfg80211_chan_def chandef;
Luis R. Rodriguez55f74352013-11-25 20:56:10 +01005710 enum nl80211_dfs_regions dfs_region;
Simon Wunderlich04f39042013-02-08 18:16:19 +01005711 int err;
5712
Luis R. Rodriguez55f74352013-11-25 20:56:10 +01005713 dfs_region = reg_get_dfs_region(wdev->wiphy);
5714 if (dfs_region == NL80211_DFS_UNSET)
5715 return -EINVAL;
5716
Simon Wunderlich04f39042013-02-08 18:16:19 +01005717 err = nl80211_parse_chandef(rdev, info, &chandef);
5718 if (err)
5719 return err;
5720
Simon Wunderlichff311bc2013-09-03 19:43:18 +02005721 if (netif_carrier_ok(dev))
5722 return -EBUSY;
5723
Simon Wunderlich04f39042013-02-08 18:16:19 +01005724 if (wdev->cac_started)
5725 return -EBUSY;
5726
5727 err = cfg80211_chandef_dfs_required(wdev->wiphy, &chandef);
5728 if (err < 0)
5729 return err;
5730
5731 if (err == 0)
5732 return -EINVAL;
5733
Janusz Dziedzicfe7c3a12013-11-05 14:48:48 +01005734 if (!cfg80211_chandef_dfs_usable(wdev->wiphy, &chandef))
Simon Wunderlich04f39042013-02-08 18:16:19 +01005735 return -EINVAL;
5736
5737 if (!rdev->ops->start_radar_detection)
5738 return -EOPNOTSUPP;
5739
Simon Wunderlich04f39042013-02-08 18:16:19 +01005740 err = cfg80211_can_use_iftype_chan(rdev, wdev, wdev->iftype,
5741 chandef.chan, CHAN_MODE_SHARED,
5742 BIT(chandef.width));
5743 if (err)
Johannes Berg5fe231e2013-05-08 21:45:15 +02005744 return err;
Simon Wunderlich04f39042013-02-08 18:16:19 +01005745
5746 err = rdev->ops->start_radar_detection(&rdev->wiphy, dev, &chandef);
5747 if (!err) {
5748 wdev->channel = chandef.chan;
5749 wdev->cac_started = true;
5750 wdev->cac_start_time = jiffies;
5751 }
Simon Wunderlich04f39042013-02-08 18:16:19 +01005752 return err;
5753}
5754
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02005755static int nl80211_channel_switch(struct sk_buff *skb, struct genl_info *info)
5756{
5757 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5758 struct net_device *dev = info->user_ptr[1];
5759 struct wireless_dev *wdev = dev->ieee80211_ptr;
5760 struct cfg80211_csa_settings params;
5761 /* csa_attrs is defined static to avoid waste of stack size - this
5762 * function is called under RTNL lock, so this should not be a problem.
5763 */
5764 static struct nlattr *csa_attrs[NL80211_ATTR_MAX+1];
5765 u8 radar_detect_width = 0;
5766 int err;
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02005767 bool need_new_beacon = false;
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02005768
5769 if (!rdev->ops->channel_switch ||
5770 !(rdev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH))
5771 return -EOPNOTSUPP;
5772
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02005773 switch (dev->ieee80211_ptr->iftype) {
5774 case NL80211_IFTYPE_AP:
5775 case NL80211_IFTYPE_P2P_GO:
5776 need_new_beacon = true;
5777
5778 /* useless if AP is not running */
5779 if (!wdev->beacon_interval)
Johannes Berg1ff79df2014-01-22 10:05:27 +01005780 return -ENOTCONN;
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02005781 break;
5782 case NL80211_IFTYPE_ADHOC:
Johannes Berg1ff79df2014-01-22 10:05:27 +01005783 if (!wdev->ssid_len)
5784 return -ENOTCONN;
5785 break;
Chun-Yeow Yeohc6da6742013-10-14 19:08:28 -07005786 case NL80211_IFTYPE_MESH_POINT:
Johannes Berg1ff79df2014-01-22 10:05:27 +01005787 if (!wdev->mesh_id_len)
5788 return -ENOTCONN;
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02005789 break;
5790 default:
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02005791 return -EOPNOTSUPP;
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02005792 }
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02005793
5794 memset(&params, 0, sizeof(params));
5795
5796 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] ||
5797 !info->attrs[NL80211_ATTR_CH_SWITCH_COUNT])
5798 return -EINVAL;
5799
5800 /* only important for AP, IBSS and mesh create IEs internally */
Andrei Otcheretianskid0a361a2013-10-17 10:52:17 +02005801 if (need_new_beacon && !info->attrs[NL80211_ATTR_CSA_IES])
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02005802 return -EINVAL;
5803
5804 params.count = nla_get_u32(info->attrs[NL80211_ATTR_CH_SWITCH_COUNT]);
5805
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02005806 if (!need_new_beacon)
5807 goto skip_beacons;
5808
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02005809 err = nl80211_parse_beacon(info->attrs, &params.beacon_after);
5810 if (err)
5811 return err;
5812
5813 err = nla_parse_nested(csa_attrs, NL80211_ATTR_MAX,
5814 info->attrs[NL80211_ATTR_CSA_IES],
5815 nl80211_policy);
5816 if (err)
5817 return err;
5818
5819 err = nl80211_parse_beacon(csa_attrs, &params.beacon_csa);
5820 if (err)
5821 return err;
5822
5823 if (!csa_attrs[NL80211_ATTR_CSA_C_OFF_BEACON])
5824 return -EINVAL;
5825
5826 params.counter_offset_beacon =
5827 nla_get_u16(csa_attrs[NL80211_ATTR_CSA_C_OFF_BEACON]);
5828 if (params.counter_offset_beacon >= params.beacon_csa.tail_len)
5829 return -EINVAL;
5830
5831 /* sanity check - counters should be the same */
5832 if (params.beacon_csa.tail[params.counter_offset_beacon] !=
5833 params.count)
5834 return -EINVAL;
5835
5836 if (csa_attrs[NL80211_ATTR_CSA_C_OFF_PRESP]) {
5837 params.counter_offset_presp =
5838 nla_get_u16(csa_attrs[NL80211_ATTR_CSA_C_OFF_PRESP]);
5839 if (params.counter_offset_presp >=
5840 params.beacon_csa.probe_resp_len)
5841 return -EINVAL;
5842
5843 if (params.beacon_csa.probe_resp[params.counter_offset_presp] !=
5844 params.count)
5845 return -EINVAL;
5846 }
5847
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02005848skip_beacons:
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02005849 err = nl80211_parse_chandef(rdev, info, &params.chandef);
5850 if (err)
5851 return err;
5852
5853 if (!cfg80211_reg_can_beacon(&rdev->wiphy, &params.chandef))
5854 return -EINVAL;
5855
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02005856 if (dev->ieee80211_ptr->iftype == NL80211_IFTYPE_AP ||
Simon Wunderlich5336fa82013-10-07 18:41:05 +02005857 dev->ieee80211_ptr->iftype == NL80211_IFTYPE_P2P_GO ||
5858 dev->ieee80211_ptr->iftype == NL80211_IFTYPE_ADHOC) {
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02005859 err = cfg80211_chandef_dfs_required(wdev->wiphy,
5860 &params.chandef);
5861 if (err < 0) {
5862 return err;
5863 } else if (err) {
5864 radar_detect_width = BIT(params.chandef.width);
5865 params.radar_required = true;
5866 }
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02005867 }
5868
5869 err = cfg80211_can_use_iftype_chan(rdev, wdev, wdev->iftype,
5870 params.chandef.chan,
5871 CHAN_MODE_SHARED,
5872 radar_detect_width);
5873 if (err)
5874 return err;
5875
5876 if (info->attrs[NL80211_ATTR_CH_SWITCH_BLOCK_TX])
5877 params.block_tx = true;
5878
Simon Wunderlichc56589e2013-11-21 18:19:49 +01005879 wdev_lock(wdev);
5880 err = rdev_channel_switch(rdev, dev, &params);
5881 wdev_unlock(wdev);
5882
5883 return err;
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02005884}
5885
Johannes Berg9720bb32011-06-21 09:45:33 +02005886static int nl80211_send_bss(struct sk_buff *msg, struct netlink_callback *cb,
5887 u32 seq, int flags,
Johannes Berg2a519312009-02-10 21:25:55 +01005888 struct cfg80211_registered_device *rdev,
Johannes Berg48ab9052009-07-10 18:42:31 +02005889 struct wireless_dev *wdev,
5890 struct cfg80211_internal_bss *intbss)
Johannes Berg2a519312009-02-10 21:25:55 +01005891{
Johannes Berg48ab9052009-07-10 18:42:31 +02005892 struct cfg80211_bss *res = &intbss->pub;
Johannes Berg9caf0362012-11-29 01:25:20 +01005893 const struct cfg80211_bss_ies *ies;
Johannes Berg2a519312009-02-10 21:25:55 +01005894 void *hdr;
5895 struct nlattr *bss;
Johannes Berg8cef2c92013-02-05 16:54:31 +01005896 bool tsf = false;
Johannes Berg48ab9052009-07-10 18:42:31 +02005897
5898 ASSERT_WDEV_LOCK(wdev);
Johannes Berg2a519312009-02-10 21:25:55 +01005899
Eric W. Biederman15e47302012-09-07 20:12:54 +00005900 hdr = nl80211hdr_put(msg, NETLINK_CB(cb->skb).portid, seq, flags,
Johannes Berg2a519312009-02-10 21:25:55 +01005901 NL80211_CMD_NEW_SCAN_RESULTS);
5902 if (!hdr)
5903 return -1;
5904
Johannes Berg9720bb32011-06-21 09:45:33 +02005905 genl_dump_check_consistent(cb, hdr, &nl80211_fam);
5906
Johannes Berg97990a02013-04-19 01:02:55 +02005907 if (nla_put_u32(msg, NL80211_ATTR_GENERATION, rdev->bss_generation))
5908 goto nla_put_failure;
5909 if (wdev->netdev &&
David S. Miller9360ffd2012-03-29 04:41:26 -04005910 nla_put_u32(msg, NL80211_ATTR_IFINDEX, wdev->netdev->ifindex))
5911 goto nla_put_failure;
Johannes Berg97990a02013-04-19 01:02:55 +02005912 if (nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)))
5913 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01005914
5915 bss = nla_nest_start(msg, NL80211_ATTR_BSS);
5916 if (!bss)
5917 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04005918 if ((!is_zero_ether_addr(res->bssid) &&
Johannes Berg9caf0362012-11-29 01:25:20 +01005919 nla_put(msg, NL80211_BSS_BSSID, ETH_ALEN, res->bssid)))
David S. Miller9360ffd2012-03-29 04:41:26 -04005920 goto nla_put_failure;
Johannes Berg9caf0362012-11-29 01:25:20 +01005921
5922 rcu_read_lock();
5923 ies = rcu_dereference(res->ies);
Johannes Berg8cef2c92013-02-05 16:54:31 +01005924 if (ies) {
5925 if (nla_put_u64(msg, NL80211_BSS_TSF, ies->tsf))
5926 goto fail_unlock_rcu;
5927 tsf = true;
5928 if (ies->len && nla_put(msg, NL80211_BSS_INFORMATION_ELEMENTS,
5929 ies->len, ies->data))
5930 goto fail_unlock_rcu;
Johannes Berg9caf0362012-11-29 01:25:20 +01005931 }
5932 ies = rcu_dereference(res->beacon_ies);
Johannes Berg8cef2c92013-02-05 16:54:31 +01005933 if (ies) {
5934 if (!tsf && nla_put_u64(msg, NL80211_BSS_TSF, ies->tsf))
5935 goto fail_unlock_rcu;
5936 if (ies->len && nla_put(msg, NL80211_BSS_BEACON_IES,
5937 ies->len, ies->data))
5938 goto fail_unlock_rcu;
Johannes Berg9caf0362012-11-29 01:25:20 +01005939 }
5940 rcu_read_unlock();
5941
David S. Miller9360ffd2012-03-29 04:41:26 -04005942 if (res->beacon_interval &&
5943 nla_put_u16(msg, NL80211_BSS_BEACON_INTERVAL, res->beacon_interval))
5944 goto nla_put_failure;
5945 if (nla_put_u16(msg, NL80211_BSS_CAPABILITY, res->capability) ||
5946 nla_put_u32(msg, NL80211_BSS_FREQUENCY, res->channel->center_freq) ||
Simon Wunderlichdcd6eac2013-07-08 16:55:49 +02005947 nla_put_u32(msg, NL80211_BSS_CHAN_WIDTH, res->scan_width) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04005948 nla_put_u32(msg, NL80211_BSS_SEEN_MS_AGO,
5949 jiffies_to_msecs(jiffies - intbss->ts)))
5950 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01005951
Johannes Berg77965c92009-02-18 18:45:06 +01005952 switch (rdev->wiphy.signal_type) {
Johannes Berg2a519312009-02-10 21:25:55 +01005953 case CFG80211_SIGNAL_TYPE_MBM:
David S. Miller9360ffd2012-03-29 04:41:26 -04005954 if (nla_put_u32(msg, NL80211_BSS_SIGNAL_MBM, res->signal))
5955 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01005956 break;
5957 case CFG80211_SIGNAL_TYPE_UNSPEC:
David S. Miller9360ffd2012-03-29 04:41:26 -04005958 if (nla_put_u8(msg, NL80211_BSS_SIGNAL_UNSPEC, res->signal))
5959 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01005960 break;
5961 default:
5962 break;
5963 }
5964
Johannes Berg48ab9052009-07-10 18:42:31 +02005965 switch (wdev->iftype) {
Johannes Berg074ac8d2010-09-16 14:58:22 +02005966 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Berg48ab9052009-07-10 18:42:31 +02005967 case NL80211_IFTYPE_STATION:
David S. Miller9360ffd2012-03-29 04:41:26 -04005968 if (intbss == wdev->current_bss &&
5969 nla_put_u32(msg, NL80211_BSS_STATUS,
5970 NL80211_BSS_STATUS_ASSOCIATED))
5971 goto nla_put_failure;
Johannes Berg48ab9052009-07-10 18:42:31 +02005972 break;
5973 case NL80211_IFTYPE_ADHOC:
David S. Miller9360ffd2012-03-29 04:41:26 -04005974 if (intbss == wdev->current_bss &&
5975 nla_put_u32(msg, NL80211_BSS_STATUS,
5976 NL80211_BSS_STATUS_IBSS_JOINED))
5977 goto nla_put_failure;
Johannes Berg48ab9052009-07-10 18:42:31 +02005978 break;
5979 default:
5980 break;
5981 }
5982
Johannes Berg2a519312009-02-10 21:25:55 +01005983 nla_nest_end(msg, bss);
5984
5985 return genlmsg_end(msg, hdr);
5986
Johannes Berg8cef2c92013-02-05 16:54:31 +01005987 fail_unlock_rcu:
5988 rcu_read_unlock();
Johannes Berg2a519312009-02-10 21:25:55 +01005989 nla_put_failure:
5990 genlmsg_cancel(msg, hdr);
5991 return -EMSGSIZE;
5992}
5993
Johannes Berg97990a02013-04-19 01:02:55 +02005994static int nl80211_dump_scan(struct sk_buff *skb, struct netlink_callback *cb)
Johannes Berg2a519312009-02-10 21:25:55 +01005995{
Johannes Berg48ab9052009-07-10 18:42:31 +02005996 struct cfg80211_registered_device *rdev;
Johannes Berg2a519312009-02-10 21:25:55 +01005997 struct cfg80211_internal_bss *scan;
Johannes Berg48ab9052009-07-10 18:42:31 +02005998 struct wireless_dev *wdev;
Johannes Berg97990a02013-04-19 01:02:55 +02005999 int start = cb->args[2], idx = 0;
Johannes Berg2a519312009-02-10 21:25:55 +01006000 int err;
6001
Johannes Berg97990a02013-04-19 01:02:55 +02006002 err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev);
Johannes Berg67748892010-10-04 21:14:06 +02006003 if (err)
6004 return err;
Johannes Berg2a519312009-02-10 21:25:55 +01006005
Johannes Berg48ab9052009-07-10 18:42:31 +02006006 wdev_lock(wdev);
6007 spin_lock_bh(&rdev->bss_lock);
6008 cfg80211_bss_expire(rdev);
6009
Johannes Berg9720bb32011-06-21 09:45:33 +02006010 cb->seq = rdev->bss_generation;
6011
Johannes Berg48ab9052009-07-10 18:42:31 +02006012 list_for_each_entry(scan, &rdev->bss_list, list) {
Johannes Berg2a519312009-02-10 21:25:55 +01006013 if (++idx <= start)
6014 continue;
Johannes Berg9720bb32011-06-21 09:45:33 +02006015 if (nl80211_send_bss(skb, cb,
Johannes Berg2a519312009-02-10 21:25:55 +01006016 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Johannes Berg48ab9052009-07-10 18:42:31 +02006017 rdev, wdev, scan) < 0) {
Johannes Berg2a519312009-02-10 21:25:55 +01006018 idx--;
Johannes Berg67748892010-10-04 21:14:06 +02006019 break;
Johannes Berg2a519312009-02-10 21:25:55 +01006020 }
6021 }
6022
Johannes Berg48ab9052009-07-10 18:42:31 +02006023 spin_unlock_bh(&rdev->bss_lock);
6024 wdev_unlock(wdev);
Johannes Berg2a519312009-02-10 21:25:55 +01006025
Johannes Berg97990a02013-04-19 01:02:55 +02006026 cb->args[2] = idx;
6027 nl80211_finish_wdev_dump(rdev);
Johannes Berg2a519312009-02-10 21:25:55 +01006028
Johannes Berg67748892010-10-04 21:14:06 +02006029 return skb->len;
Johannes Berg2a519312009-02-10 21:25:55 +01006030}
6031
Eric W. Biederman15e47302012-09-07 20:12:54 +00006032static int nl80211_send_survey(struct sk_buff *msg, u32 portid, u32 seq,
Holger Schurig61fa7132009-11-11 12:25:40 +01006033 int flags, struct net_device *dev,
6034 struct survey_info *survey)
6035{
6036 void *hdr;
6037 struct nlattr *infoattr;
6038
Eric W. Biederman15e47302012-09-07 20:12:54 +00006039 hdr = nl80211hdr_put(msg, portid, seq, flags,
Holger Schurig61fa7132009-11-11 12:25:40 +01006040 NL80211_CMD_NEW_SURVEY_RESULTS);
6041 if (!hdr)
6042 return -ENOMEM;
6043
David S. Miller9360ffd2012-03-29 04:41:26 -04006044 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex))
6045 goto nla_put_failure;
Holger Schurig61fa7132009-11-11 12:25:40 +01006046
6047 infoattr = nla_nest_start(msg, NL80211_ATTR_SURVEY_INFO);
6048 if (!infoattr)
6049 goto nla_put_failure;
6050
David S. Miller9360ffd2012-03-29 04:41:26 -04006051 if (nla_put_u32(msg, NL80211_SURVEY_INFO_FREQUENCY,
6052 survey->channel->center_freq))
6053 goto nla_put_failure;
6054
6055 if ((survey->filled & SURVEY_INFO_NOISE_DBM) &&
6056 nla_put_u8(msg, NL80211_SURVEY_INFO_NOISE, survey->noise))
6057 goto nla_put_failure;
6058 if ((survey->filled & SURVEY_INFO_IN_USE) &&
6059 nla_put_flag(msg, NL80211_SURVEY_INFO_IN_USE))
6060 goto nla_put_failure;
6061 if ((survey->filled & SURVEY_INFO_CHANNEL_TIME) &&
6062 nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME,
6063 survey->channel_time))
6064 goto nla_put_failure;
6065 if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_BUSY) &&
6066 nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_BUSY,
6067 survey->channel_time_busy))
6068 goto nla_put_failure;
6069 if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_EXT_BUSY) &&
6070 nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_EXT_BUSY,
6071 survey->channel_time_ext_busy))
6072 goto nla_put_failure;
6073 if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_RX) &&
6074 nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_RX,
6075 survey->channel_time_rx))
6076 goto nla_put_failure;
6077 if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_TX) &&
6078 nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_TX,
6079 survey->channel_time_tx))
6080 goto nla_put_failure;
Holger Schurig61fa7132009-11-11 12:25:40 +01006081
6082 nla_nest_end(msg, infoattr);
6083
6084 return genlmsg_end(msg, hdr);
6085
6086 nla_put_failure:
6087 genlmsg_cancel(msg, hdr);
6088 return -EMSGSIZE;
6089}
6090
6091static int nl80211_dump_survey(struct sk_buff *skb,
6092 struct netlink_callback *cb)
6093{
6094 struct survey_info survey;
6095 struct cfg80211_registered_device *dev;
Johannes Berg97990a02013-04-19 01:02:55 +02006096 struct wireless_dev *wdev;
6097 int survey_idx = cb->args[2];
Holger Schurig61fa7132009-11-11 12:25:40 +01006098 int res;
6099
Johannes Berg97990a02013-04-19 01:02:55 +02006100 res = nl80211_prepare_wdev_dump(skb, cb, &dev, &wdev);
Johannes Berg67748892010-10-04 21:14:06 +02006101 if (res)
6102 return res;
Holger Schurig61fa7132009-11-11 12:25:40 +01006103
Johannes Berg97990a02013-04-19 01:02:55 +02006104 if (!wdev->netdev) {
6105 res = -EINVAL;
6106 goto out_err;
6107 }
6108
Holger Schurig61fa7132009-11-11 12:25:40 +01006109 if (!dev->ops->dump_survey) {
6110 res = -EOPNOTSUPP;
6111 goto out_err;
6112 }
6113
6114 while (1) {
Luis R. Rodriguez180cdc72011-05-27 07:24:02 -07006115 struct ieee80211_channel *chan;
6116
Johannes Berg97990a02013-04-19 01:02:55 +02006117 res = rdev_dump_survey(dev, wdev->netdev, survey_idx, &survey);
Holger Schurig61fa7132009-11-11 12:25:40 +01006118 if (res == -ENOENT)
6119 break;
6120 if (res)
6121 goto out_err;
6122
Luis R. Rodriguez180cdc72011-05-27 07:24:02 -07006123 /* Survey without a channel doesn't make sense */
6124 if (!survey.channel) {
6125 res = -EINVAL;
6126 goto out;
6127 }
6128
6129 chan = ieee80211_get_channel(&dev->wiphy,
6130 survey.channel->center_freq);
6131 if (!chan || chan->flags & IEEE80211_CHAN_DISABLED) {
6132 survey_idx++;
6133 continue;
6134 }
6135
Holger Schurig61fa7132009-11-11 12:25:40 +01006136 if (nl80211_send_survey(skb,
Eric W. Biederman15e47302012-09-07 20:12:54 +00006137 NETLINK_CB(cb->skb).portid,
Holger Schurig61fa7132009-11-11 12:25:40 +01006138 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Johannes Berg97990a02013-04-19 01:02:55 +02006139 wdev->netdev, &survey) < 0)
Holger Schurig61fa7132009-11-11 12:25:40 +01006140 goto out;
6141 survey_idx++;
6142 }
6143
6144 out:
Johannes Berg97990a02013-04-19 01:02:55 +02006145 cb->args[2] = survey_idx;
Holger Schurig61fa7132009-11-11 12:25:40 +01006146 res = skb->len;
6147 out_err:
Johannes Berg97990a02013-04-19 01:02:55 +02006148 nl80211_finish_wdev_dump(dev);
Holger Schurig61fa7132009-11-11 12:25:40 +01006149 return res;
6150}
6151
Samuel Ortizb23aa672009-07-01 21:26:54 +02006152static bool nl80211_valid_wpa_versions(u32 wpa_versions)
6153{
6154 return !(wpa_versions & ~(NL80211_WPA_VERSION_1 |
6155 NL80211_WPA_VERSION_2));
6156}
6157
Jouni Malinen636a5d32009-03-19 13:39:22 +02006158static int nl80211_authenticate(struct sk_buff *skb, struct genl_info *info)
6159{
Johannes Berg4c476992010-10-04 21:36:35 +02006160 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6161 struct net_device *dev = info->user_ptr[1];
Johannes Berg19957bb2009-07-02 17:20:43 +02006162 struct ieee80211_channel *chan;
Jouni Malinene39e5b52012-09-30 19:29:39 +03006163 const u8 *bssid, *ssid, *ie = NULL, *sae_data = NULL;
6164 int err, ssid_len, ie_len = 0, sae_data_len = 0;
Johannes Berg19957bb2009-07-02 17:20:43 +02006165 enum nl80211_auth_type auth_type;
Johannes Bergfffd0932009-07-08 14:22:54 +02006166 struct key_parse key;
Jouni Malinend5cdfac2010-04-04 09:37:19 +03006167 bool local_state_change;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006168
Johannes Bergf4a11bb2009-03-27 12:40:28 +01006169 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
6170 return -EINVAL;
6171
6172 if (!info->attrs[NL80211_ATTR_MAC])
6173 return -EINVAL;
6174
Jouni Malinen17780922009-03-27 20:52:47 +02006175 if (!info->attrs[NL80211_ATTR_AUTH_TYPE])
6176 return -EINVAL;
6177
Johannes Berg19957bb2009-07-02 17:20:43 +02006178 if (!info->attrs[NL80211_ATTR_SSID])
6179 return -EINVAL;
6180
6181 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ])
6182 return -EINVAL;
6183
Johannes Bergfffd0932009-07-08 14:22:54 +02006184 err = nl80211_parse_key(info, &key);
6185 if (err)
6186 return err;
6187
6188 if (key.idx >= 0) {
Johannes Berge31b8212010-10-05 19:39:30 +02006189 if (key.type != -1 && key.type != NL80211_KEYTYPE_GROUP)
6190 return -EINVAL;
Johannes Bergfffd0932009-07-08 14:22:54 +02006191 if (!key.p.key || !key.p.key_len)
6192 return -EINVAL;
6193 if ((key.p.cipher != WLAN_CIPHER_SUITE_WEP40 ||
6194 key.p.key_len != WLAN_KEY_LEN_WEP40) &&
6195 (key.p.cipher != WLAN_CIPHER_SUITE_WEP104 ||
6196 key.p.key_len != WLAN_KEY_LEN_WEP104))
6197 return -EINVAL;
6198 if (key.idx > 4)
6199 return -EINVAL;
6200 } else {
6201 key.p.key_len = 0;
6202 key.p.key = NULL;
6203 }
6204
Johannes Bergafea0b72010-08-10 09:46:42 +02006205 if (key.idx >= 0) {
6206 int i;
6207 bool ok = false;
6208 for (i = 0; i < rdev->wiphy.n_cipher_suites; i++) {
6209 if (key.p.cipher == rdev->wiphy.cipher_suites[i]) {
6210 ok = true;
6211 break;
6212 }
6213 }
Johannes Berg4c476992010-10-04 21:36:35 +02006214 if (!ok)
6215 return -EINVAL;
Johannes Bergafea0b72010-08-10 09:46:42 +02006216 }
6217
Johannes Berg4c476992010-10-04 21:36:35 +02006218 if (!rdev->ops->auth)
6219 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006220
Johannes Berg074ac8d2010-09-16 14:58:22 +02006221 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02006222 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
6223 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02006224
Johannes Berg19957bb2009-07-02 17:20:43 +02006225 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen664834d2014-01-15 00:01:44 +02006226 chan = nl80211_get_valid_chan(&rdev->wiphy,
6227 info->attrs[NL80211_ATTR_WIPHY_FREQ]);
6228 if (!chan)
Johannes Berg4c476992010-10-04 21:36:35 +02006229 return -EINVAL;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006230
Johannes Berg19957bb2009-07-02 17:20:43 +02006231 ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
6232 ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
6233
6234 if (info->attrs[NL80211_ATTR_IE]) {
6235 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
6236 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
6237 }
6238
6239 auth_type = nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]);
Jouni Malinene39e5b52012-09-30 19:29:39 +03006240 if (!nl80211_valid_auth_type(rdev, auth_type, NL80211_CMD_AUTHENTICATE))
Johannes Berg4c476992010-10-04 21:36:35 +02006241 return -EINVAL;
Johannes Berg19957bb2009-07-02 17:20:43 +02006242
Jouni Malinene39e5b52012-09-30 19:29:39 +03006243 if (auth_type == NL80211_AUTHTYPE_SAE &&
6244 !info->attrs[NL80211_ATTR_SAE_DATA])
6245 return -EINVAL;
6246
6247 if (info->attrs[NL80211_ATTR_SAE_DATA]) {
6248 if (auth_type != NL80211_AUTHTYPE_SAE)
6249 return -EINVAL;
6250 sae_data = nla_data(info->attrs[NL80211_ATTR_SAE_DATA]);
6251 sae_data_len = nla_len(info->attrs[NL80211_ATTR_SAE_DATA]);
6252 /* need to include at least Auth Transaction and Status Code */
6253 if (sae_data_len < 4)
6254 return -EINVAL;
6255 }
6256
Jouni Malinend5cdfac2010-04-04 09:37:19 +03006257 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE];
6258
Johannes Berg95de8172012-01-20 13:55:25 +01006259 /*
6260 * Since we no longer track auth state, ignore
6261 * requests to only change local state.
6262 */
6263 if (local_state_change)
6264 return 0;
6265
Johannes Berg91bf9b22013-05-15 17:44:01 +02006266 wdev_lock(dev->ieee80211_ptr);
6267 err = cfg80211_mlme_auth(rdev, dev, chan, auth_type, bssid,
6268 ssid, ssid_len, ie, ie_len,
6269 key.p.key, key.p.key_len, key.idx,
6270 sae_data, sae_data_len);
6271 wdev_unlock(dev->ieee80211_ptr);
6272 return err;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006273}
6274
Johannes Bergc0692b82010-08-27 14:26:53 +03006275static int nl80211_crypto_settings(struct cfg80211_registered_device *rdev,
6276 struct genl_info *info,
Johannes Berg3dc27d22009-07-02 21:36:37 +02006277 struct cfg80211_crypto_settings *settings,
6278 int cipher_limit)
Samuel Ortizb23aa672009-07-01 21:26:54 +02006279{
Johannes Bergc0b2bbd2009-07-25 16:54:36 +02006280 memset(settings, 0, sizeof(*settings));
6281
Samuel Ortizb23aa672009-07-01 21:26:54 +02006282 settings->control_port = info->attrs[NL80211_ATTR_CONTROL_PORT];
6283
Johannes Bergc0692b82010-08-27 14:26:53 +03006284 if (info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]) {
6285 u16 proto;
6286 proto = nla_get_u16(
6287 info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]);
6288 settings->control_port_ethertype = cpu_to_be16(proto);
6289 if (!(rdev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) &&
6290 proto != ETH_P_PAE)
6291 return -EINVAL;
6292 if (info->attrs[NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT])
6293 settings->control_port_no_encrypt = true;
6294 } else
6295 settings->control_port_ethertype = cpu_to_be16(ETH_P_PAE);
6296
Samuel Ortizb23aa672009-07-01 21:26:54 +02006297 if (info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]) {
6298 void *data;
6299 int len, i;
6300
6301 data = nla_data(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]);
6302 len = nla_len(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]);
6303 settings->n_ciphers_pairwise = len / sizeof(u32);
6304
6305 if (len % sizeof(u32))
6306 return -EINVAL;
6307
Johannes Berg3dc27d22009-07-02 21:36:37 +02006308 if (settings->n_ciphers_pairwise > cipher_limit)
Samuel Ortizb23aa672009-07-01 21:26:54 +02006309 return -EINVAL;
6310
6311 memcpy(settings->ciphers_pairwise, data, len);
6312
6313 for (i = 0; i < settings->n_ciphers_pairwise; i++)
Jouni Malinen38ba3c52011-09-21 18:14:56 +03006314 if (!cfg80211_supported_cipher_suite(
6315 &rdev->wiphy,
Samuel Ortizb23aa672009-07-01 21:26:54 +02006316 settings->ciphers_pairwise[i]))
6317 return -EINVAL;
6318 }
6319
6320 if (info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]) {
6321 settings->cipher_group =
6322 nla_get_u32(info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]);
Jouni Malinen38ba3c52011-09-21 18:14:56 +03006323 if (!cfg80211_supported_cipher_suite(&rdev->wiphy,
6324 settings->cipher_group))
Samuel Ortizb23aa672009-07-01 21:26:54 +02006325 return -EINVAL;
6326 }
6327
6328 if (info->attrs[NL80211_ATTR_WPA_VERSIONS]) {
6329 settings->wpa_versions =
6330 nla_get_u32(info->attrs[NL80211_ATTR_WPA_VERSIONS]);
6331 if (!nl80211_valid_wpa_versions(settings->wpa_versions))
6332 return -EINVAL;
6333 }
6334
6335 if (info->attrs[NL80211_ATTR_AKM_SUITES]) {
6336 void *data;
Jouni Malinen6d302402011-09-21 18:11:33 +03006337 int len;
Samuel Ortizb23aa672009-07-01 21:26:54 +02006338
6339 data = nla_data(info->attrs[NL80211_ATTR_AKM_SUITES]);
6340 len = nla_len(info->attrs[NL80211_ATTR_AKM_SUITES]);
6341 settings->n_akm_suites = len / sizeof(u32);
6342
6343 if (len % sizeof(u32))
6344 return -EINVAL;
6345
Jouni Malinen1b9ca022011-09-21 16:13:07 +03006346 if (settings->n_akm_suites > NL80211_MAX_NR_AKM_SUITES)
6347 return -EINVAL;
6348
Samuel Ortizb23aa672009-07-01 21:26:54 +02006349 memcpy(settings->akm_suites, data, len);
Samuel Ortizb23aa672009-07-01 21:26:54 +02006350 }
6351
6352 return 0;
6353}
6354
Jouni Malinen636a5d32009-03-19 13:39:22 +02006355static int nl80211_associate(struct sk_buff *skb, struct genl_info *info)
6356{
Johannes Berg4c476992010-10-04 21:36:35 +02006357 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6358 struct net_device *dev = info->user_ptr[1];
Johannes Bergf444de02010-05-05 15:25:02 +02006359 struct ieee80211_channel *chan;
Johannes Bergf62fab72013-02-21 20:09:09 +01006360 struct cfg80211_assoc_request req = {};
6361 const u8 *bssid, *ssid;
6362 int err, ssid_len = 0;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006363
Johannes Bergf4a11bb2009-03-27 12:40:28 +01006364 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
6365 return -EINVAL;
6366
6367 if (!info->attrs[NL80211_ATTR_MAC] ||
Johannes Berg19957bb2009-07-02 17:20:43 +02006368 !info->attrs[NL80211_ATTR_SSID] ||
6369 !info->attrs[NL80211_ATTR_WIPHY_FREQ])
Johannes Bergf4a11bb2009-03-27 12:40:28 +01006370 return -EINVAL;
6371
Johannes Berg4c476992010-10-04 21:36:35 +02006372 if (!rdev->ops->assoc)
6373 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006374
Johannes Berg074ac8d2010-09-16 14:58:22 +02006375 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02006376 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
6377 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02006378
Johannes Berg19957bb2009-07-02 17:20:43 +02006379 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02006380
Jouni Malinen664834d2014-01-15 00:01:44 +02006381 chan = nl80211_get_valid_chan(&rdev->wiphy,
6382 info->attrs[NL80211_ATTR_WIPHY_FREQ]);
6383 if (!chan)
Johannes Berg4c476992010-10-04 21:36:35 +02006384 return -EINVAL;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006385
Johannes Berg19957bb2009-07-02 17:20:43 +02006386 ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
6387 ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02006388
6389 if (info->attrs[NL80211_ATTR_IE]) {
Johannes Bergf62fab72013-02-21 20:09:09 +01006390 req.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
6391 req.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02006392 }
6393
Jouni Malinendc6382ce2009-05-06 22:09:37 +03006394 if (info->attrs[NL80211_ATTR_USE_MFP]) {
Johannes Berg4f5dadc2009-07-07 03:56:10 +02006395 enum nl80211_mfp mfp =
Jouni Malinendc6382ce2009-05-06 22:09:37 +03006396 nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]);
Johannes Berg4f5dadc2009-07-07 03:56:10 +02006397 if (mfp == NL80211_MFP_REQUIRED)
Johannes Bergf62fab72013-02-21 20:09:09 +01006398 req.use_mfp = true;
Johannes Berg4c476992010-10-04 21:36:35 +02006399 else if (mfp != NL80211_MFP_NO)
6400 return -EINVAL;
Jouni Malinendc6382ce2009-05-06 22:09:37 +03006401 }
6402
Johannes Berg3e5d7642009-07-07 14:37:26 +02006403 if (info->attrs[NL80211_ATTR_PREV_BSSID])
Johannes Bergf62fab72013-02-21 20:09:09 +01006404 req.prev_bssid = nla_data(info->attrs[NL80211_ATTR_PREV_BSSID]);
Johannes Berg3e5d7642009-07-07 14:37:26 +02006405
Ben Greear7e7c8922011-11-18 11:31:59 -08006406 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT]))
Johannes Bergf62fab72013-02-21 20:09:09 +01006407 req.flags |= ASSOC_REQ_DISABLE_HT;
Ben Greear7e7c8922011-11-18 11:31:59 -08006408
6409 if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
Johannes Bergf62fab72013-02-21 20:09:09 +01006410 memcpy(&req.ht_capa_mask,
6411 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]),
6412 sizeof(req.ht_capa_mask));
Ben Greear7e7c8922011-11-18 11:31:59 -08006413
6414 if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) {
Johannes Bergf62fab72013-02-21 20:09:09 +01006415 if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
Ben Greear7e7c8922011-11-18 11:31:59 -08006416 return -EINVAL;
Johannes Bergf62fab72013-02-21 20:09:09 +01006417 memcpy(&req.ht_capa,
6418 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]),
6419 sizeof(req.ht_capa));
Ben Greear7e7c8922011-11-18 11:31:59 -08006420 }
6421
Johannes Bergee2aca32013-02-21 17:36:01 +01006422 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_VHT]))
Johannes Bergf62fab72013-02-21 20:09:09 +01006423 req.flags |= ASSOC_REQ_DISABLE_VHT;
Johannes Bergee2aca32013-02-21 17:36:01 +01006424
6425 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK])
Johannes Bergf62fab72013-02-21 20:09:09 +01006426 memcpy(&req.vht_capa_mask,
6427 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]),
6428 sizeof(req.vht_capa_mask));
Johannes Bergee2aca32013-02-21 17:36:01 +01006429
6430 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) {
Johannes Bergf62fab72013-02-21 20:09:09 +01006431 if (!info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK])
Johannes Bergee2aca32013-02-21 17:36:01 +01006432 return -EINVAL;
Johannes Bergf62fab72013-02-21 20:09:09 +01006433 memcpy(&req.vht_capa,
6434 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]),
6435 sizeof(req.vht_capa));
Johannes Bergee2aca32013-02-21 17:36:01 +01006436 }
6437
Johannes Bergf62fab72013-02-21 20:09:09 +01006438 err = nl80211_crypto_settings(rdev, info, &req.crypto, 1);
Johannes Berg91bf9b22013-05-15 17:44:01 +02006439 if (!err) {
6440 wdev_lock(dev->ieee80211_ptr);
Johannes Bergf62fab72013-02-21 20:09:09 +01006441 err = cfg80211_mlme_assoc(rdev, dev, chan, bssid,
6442 ssid, ssid_len, &req);
Johannes Berg91bf9b22013-05-15 17:44:01 +02006443 wdev_unlock(dev->ieee80211_ptr);
6444 }
Jouni Malinen636a5d32009-03-19 13:39:22 +02006445
Jouni Malinen636a5d32009-03-19 13:39:22 +02006446 return err;
6447}
6448
6449static int nl80211_deauthenticate(struct sk_buff *skb, struct genl_info *info)
6450{
Johannes Berg4c476992010-10-04 21:36:35 +02006451 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6452 struct net_device *dev = info->user_ptr[1];
Johannes Berg19957bb2009-07-02 17:20:43 +02006453 const u8 *ie = NULL, *bssid;
Johannes Berg91bf9b22013-05-15 17:44:01 +02006454 int ie_len = 0, err;
Johannes Berg19957bb2009-07-02 17:20:43 +02006455 u16 reason_code;
Jouni Malinend5cdfac2010-04-04 09:37:19 +03006456 bool local_state_change;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006457
Johannes Bergf4a11bb2009-03-27 12:40:28 +01006458 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
6459 return -EINVAL;
6460
6461 if (!info->attrs[NL80211_ATTR_MAC])
6462 return -EINVAL;
6463
6464 if (!info->attrs[NL80211_ATTR_REASON_CODE])
6465 return -EINVAL;
6466
Johannes Berg4c476992010-10-04 21:36:35 +02006467 if (!rdev->ops->deauth)
6468 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006469
Johannes Berg074ac8d2010-09-16 14:58:22 +02006470 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02006471 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
6472 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02006473
Johannes Berg19957bb2009-07-02 17:20:43 +02006474 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02006475
Johannes Berg19957bb2009-07-02 17:20:43 +02006476 reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
6477 if (reason_code == 0) {
Johannes Bergf4a11bb2009-03-27 12:40:28 +01006478 /* Reason Code 0 is reserved */
Johannes Berg4c476992010-10-04 21:36:35 +02006479 return -EINVAL;
Jouni Malinen255e7372009-03-20 21:21:17 +02006480 }
Jouni Malinen636a5d32009-03-19 13:39:22 +02006481
6482 if (info->attrs[NL80211_ATTR_IE]) {
Johannes Berg19957bb2009-07-02 17:20:43 +02006483 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
6484 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02006485 }
6486
Jouni Malinend5cdfac2010-04-04 09:37:19 +03006487 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE];
6488
Johannes Berg91bf9b22013-05-15 17:44:01 +02006489 wdev_lock(dev->ieee80211_ptr);
6490 err = cfg80211_mlme_deauth(rdev, dev, bssid, ie, ie_len, reason_code,
6491 local_state_change);
6492 wdev_unlock(dev->ieee80211_ptr);
6493 return err;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006494}
6495
6496static int nl80211_disassociate(struct sk_buff *skb, struct genl_info *info)
6497{
Johannes Berg4c476992010-10-04 21:36:35 +02006498 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6499 struct net_device *dev = info->user_ptr[1];
Johannes Berg19957bb2009-07-02 17:20:43 +02006500 const u8 *ie = NULL, *bssid;
Johannes Berg91bf9b22013-05-15 17:44:01 +02006501 int ie_len = 0, err;
Johannes Berg19957bb2009-07-02 17:20:43 +02006502 u16 reason_code;
Jouni Malinend5cdfac2010-04-04 09:37:19 +03006503 bool local_state_change;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006504
Johannes Bergf4a11bb2009-03-27 12:40:28 +01006505 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
6506 return -EINVAL;
6507
6508 if (!info->attrs[NL80211_ATTR_MAC])
6509 return -EINVAL;
6510
6511 if (!info->attrs[NL80211_ATTR_REASON_CODE])
6512 return -EINVAL;
6513
Johannes Berg4c476992010-10-04 21:36:35 +02006514 if (!rdev->ops->disassoc)
6515 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006516
Johannes Berg074ac8d2010-09-16 14:58:22 +02006517 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02006518 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
6519 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02006520
Johannes Berg19957bb2009-07-02 17:20:43 +02006521 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02006522
Johannes Berg19957bb2009-07-02 17:20:43 +02006523 reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
6524 if (reason_code == 0) {
Johannes Bergf4a11bb2009-03-27 12:40:28 +01006525 /* Reason Code 0 is reserved */
Johannes Berg4c476992010-10-04 21:36:35 +02006526 return -EINVAL;
Jouni Malinen255e7372009-03-20 21:21:17 +02006527 }
Jouni Malinen636a5d32009-03-19 13:39:22 +02006528
6529 if (info->attrs[NL80211_ATTR_IE]) {
Johannes Berg19957bb2009-07-02 17:20:43 +02006530 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
6531 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02006532 }
6533
Jouni Malinend5cdfac2010-04-04 09:37:19 +03006534 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE];
6535
Johannes Berg91bf9b22013-05-15 17:44:01 +02006536 wdev_lock(dev->ieee80211_ptr);
6537 err = cfg80211_mlme_disassoc(rdev, dev, bssid, ie, ie_len, reason_code,
6538 local_state_change);
6539 wdev_unlock(dev->ieee80211_ptr);
6540 return err;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006541}
6542
Felix Fietkaudd5b4cc2010-11-22 20:58:24 +01006543static bool
6544nl80211_parse_mcast_rate(struct cfg80211_registered_device *rdev,
6545 int mcast_rate[IEEE80211_NUM_BANDS],
6546 int rateval)
6547{
6548 struct wiphy *wiphy = &rdev->wiphy;
6549 bool found = false;
6550 int band, i;
6551
6552 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
6553 struct ieee80211_supported_band *sband;
6554
6555 sband = wiphy->bands[band];
6556 if (!sband)
6557 continue;
6558
6559 for (i = 0; i < sband->n_bitrates; i++) {
6560 if (sband->bitrates[i].bitrate == rateval) {
6561 mcast_rate[band] = i + 1;
6562 found = true;
6563 break;
6564 }
6565 }
6566 }
6567
6568 return found;
6569}
6570
Johannes Berg04a773a2009-04-19 21:24:32 +02006571static int nl80211_join_ibss(struct sk_buff *skb, struct genl_info *info)
6572{
Johannes Berg4c476992010-10-04 21:36:35 +02006573 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6574 struct net_device *dev = info->user_ptr[1];
Johannes Berg04a773a2009-04-19 21:24:32 +02006575 struct cfg80211_ibss_params ibss;
6576 struct wiphy *wiphy;
Johannes Bergfffd0932009-07-08 14:22:54 +02006577 struct cfg80211_cached_keys *connkeys = NULL;
Johannes Berg04a773a2009-04-19 21:24:32 +02006578 int err;
6579
Johannes Berg8e30bc52009-04-22 17:45:38 +02006580 memset(&ibss, 0, sizeof(ibss));
6581
Johannes Berg04a773a2009-04-19 21:24:32 +02006582 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
6583 return -EINVAL;
6584
Johannes Berg683b6d32012-11-08 21:25:48 +01006585 if (!info->attrs[NL80211_ATTR_SSID] ||
Johannes Berg04a773a2009-04-19 21:24:32 +02006586 !nla_len(info->attrs[NL80211_ATTR_SSID]))
6587 return -EINVAL;
6588
Johannes Berg8e30bc52009-04-22 17:45:38 +02006589 ibss.beacon_interval = 100;
6590
6591 if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) {
6592 ibss.beacon_interval =
6593 nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]);
6594 if (ibss.beacon_interval < 1 || ibss.beacon_interval > 10000)
6595 return -EINVAL;
6596 }
6597
Johannes Berg4c476992010-10-04 21:36:35 +02006598 if (!rdev->ops->join_ibss)
6599 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02006600
Johannes Berg4c476992010-10-04 21:36:35 +02006601 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC)
6602 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02006603
Johannes Berg79c97e92009-07-07 03:56:12 +02006604 wiphy = &rdev->wiphy;
Johannes Berg04a773a2009-04-19 21:24:32 +02006605
Johannes Berg39193492011-09-16 13:45:25 +02006606 if (info->attrs[NL80211_ATTR_MAC]) {
Johannes Berg04a773a2009-04-19 21:24:32 +02006607 ibss.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Johannes Berg39193492011-09-16 13:45:25 +02006608
6609 if (!is_valid_ether_addr(ibss.bssid))
6610 return -EINVAL;
6611 }
Johannes Berg04a773a2009-04-19 21:24:32 +02006612 ibss.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
6613 ibss.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
6614
6615 if (info->attrs[NL80211_ATTR_IE]) {
6616 ibss.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
6617 ibss.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
6618 }
6619
Johannes Berg683b6d32012-11-08 21:25:48 +01006620 err = nl80211_parse_chandef(rdev, info, &ibss.chandef);
6621 if (err)
6622 return err;
Alexander Simon54858ee5b2011-11-30 16:56:32 +01006623
Johannes Berg683b6d32012-11-08 21:25:48 +01006624 if (!cfg80211_reg_can_beacon(&rdev->wiphy, &ibss.chandef))
Alexander Simon54858ee5b2011-11-30 16:56:32 +01006625 return -EINVAL;
6626
Simon Wunderlich2f301ab2013-05-16 13:00:28 +02006627 switch (ibss.chandef.width) {
Simon Wunderlichbf372642013-07-08 16:55:58 +02006628 case NL80211_CHAN_WIDTH_5:
6629 case NL80211_CHAN_WIDTH_10:
Simon Wunderlich2f301ab2013-05-16 13:00:28 +02006630 case NL80211_CHAN_WIDTH_20_NOHT:
6631 break;
6632 case NL80211_CHAN_WIDTH_20:
6633 case NL80211_CHAN_WIDTH_40:
6634 if (rdev->wiphy.features & NL80211_FEATURE_HT_IBSS)
6635 break;
6636 default:
Johannes Bergdb9c64c2012-11-09 14:56:41 +01006637 return -EINVAL;
Simon Wunderlich2f301ab2013-05-16 13:00:28 +02006638 }
Johannes Bergdb9c64c2012-11-09 14:56:41 +01006639
Johannes Berg04a773a2009-04-19 21:24:32 +02006640 ibss.channel_fixed = !!info->attrs[NL80211_ATTR_FREQ_FIXED];
Johannes Bergfffd0932009-07-08 14:22:54 +02006641 ibss.privacy = !!info->attrs[NL80211_ATTR_PRIVACY];
Johannes Berg04a773a2009-04-19 21:24:32 +02006642
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03006643 if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) {
6644 u8 *rates =
6645 nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
6646 int n_rates =
6647 nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
6648 struct ieee80211_supported_band *sband =
Johannes Berg683b6d32012-11-08 21:25:48 +01006649 wiphy->bands[ibss.chandef.chan->band];
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03006650
Johannes Berg34850ab2011-07-18 18:08:35 +02006651 err = ieee80211_get_ratemask(sband, rates, n_rates,
6652 &ibss.basic_rates);
6653 if (err)
6654 return err;
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03006655 }
Felix Fietkaudd5b4cc2010-11-22 20:58:24 +01006656
Simon Wunderlich803768f2013-06-28 10:39:58 +02006657 if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
6658 memcpy(&ibss.ht_capa_mask,
6659 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]),
6660 sizeof(ibss.ht_capa_mask));
6661
6662 if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) {
6663 if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
6664 return -EINVAL;
6665 memcpy(&ibss.ht_capa,
6666 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]),
6667 sizeof(ibss.ht_capa));
6668 }
6669
Felix Fietkaudd5b4cc2010-11-22 20:58:24 +01006670 if (info->attrs[NL80211_ATTR_MCAST_RATE] &&
6671 !nl80211_parse_mcast_rate(rdev, ibss.mcast_rate,
6672 nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE])))
6673 return -EINVAL;
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03006674
Johannes Berg4c476992010-10-04 21:36:35 +02006675 if (ibss.privacy && info->attrs[NL80211_ATTR_KEYS]) {
Sujith Manoharande7044e2012-10-18 10:19:28 +05306676 bool no_ht = false;
6677
Johannes Berg4c476992010-10-04 21:36:35 +02006678 connkeys = nl80211_parse_connkeys(rdev,
Sujith Manoharande7044e2012-10-18 10:19:28 +05306679 info->attrs[NL80211_ATTR_KEYS],
6680 &no_ht);
Johannes Berg4c476992010-10-04 21:36:35 +02006681 if (IS_ERR(connkeys))
6682 return PTR_ERR(connkeys);
Sujith Manoharande7044e2012-10-18 10:19:28 +05306683
Johannes Berg3d9d1d62012-11-08 23:14:50 +01006684 if ((ibss.chandef.width != NL80211_CHAN_WIDTH_20_NOHT) &&
6685 no_ht) {
Sujith Manoharande7044e2012-10-18 10:19:28 +05306686 kfree(connkeys);
6687 return -EINVAL;
6688 }
Johannes Berg4c476992010-10-04 21:36:35 +02006689 }
Johannes Berg04a773a2009-04-19 21:24:32 +02006690
Antonio Quartulli267335d2012-01-31 20:25:47 +01006691 ibss.control_port =
6692 nla_get_flag(info->attrs[NL80211_ATTR_CONTROL_PORT]);
6693
Simon Wunderlich5336fa82013-10-07 18:41:05 +02006694 ibss.userspace_handles_dfs =
6695 nla_get_flag(info->attrs[NL80211_ATTR_HANDLE_DFS]);
6696
Johannes Berg4c476992010-10-04 21:36:35 +02006697 err = cfg80211_join_ibss(rdev, dev, &ibss, connkeys);
Johannes Bergfffd0932009-07-08 14:22:54 +02006698 if (err)
6699 kfree(connkeys);
Johannes Berg04a773a2009-04-19 21:24:32 +02006700 return err;
6701}
6702
6703static int nl80211_leave_ibss(struct sk_buff *skb, struct genl_info *info)
6704{
Johannes Berg4c476992010-10-04 21:36:35 +02006705 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6706 struct net_device *dev = info->user_ptr[1];
Johannes Berg04a773a2009-04-19 21:24:32 +02006707
Johannes Berg4c476992010-10-04 21:36:35 +02006708 if (!rdev->ops->leave_ibss)
6709 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02006710
Johannes Berg4c476992010-10-04 21:36:35 +02006711 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC)
6712 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02006713
Johannes Berg4c476992010-10-04 21:36:35 +02006714 return cfg80211_leave_ibss(rdev, dev, false);
Johannes Berg04a773a2009-04-19 21:24:32 +02006715}
6716
Antonio Quartullif4e583c2012-11-02 13:27:48 +01006717static int nl80211_set_mcast_rate(struct sk_buff *skb, struct genl_info *info)
6718{
6719 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6720 struct net_device *dev = info->user_ptr[1];
6721 int mcast_rate[IEEE80211_NUM_BANDS];
6722 u32 nla_rate;
6723 int err;
6724
6725 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC &&
6726 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
6727 return -EOPNOTSUPP;
6728
6729 if (!rdev->ops->set_mcast_rate)
6730 return -EOPNOTSUPP;
6731
6732 memset(mcast_rate, 0, sizeof(mcast_rate));
6733
6734 if (!info->attrs[NL80211_ATTR_MCAST_RATE])
6735 return -EINVAL;
6736
6737 nla_rate = nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]);
6738 if (!nl80211_parse_mcast_rate(rdev, mcast_rate, nla_rate))
6739 return -EINVAL;
6740
6741 err = rdev->ops->set_mcast_rate(&rdev->wiphy, dev, mcast_rate);
6742
6743 return err;
6744}
6745
Johannes Bergad7e7182013-11-13 13:37:47 +01006746static struct sk_buff *
6747__cfg80211_alloc_vendor_skb(struct cfg80211_registered_device *rdev,
6748 int approxlen, u32 portid, u32 seq,
6749 enum nl80211_commands cmd,
Johannes Berg567ffc32013-12-18 14:43:31 +01006750 enum nl80211_attrs attr,
6751 const struct nl80211_vendor_cmd_info *info,
6752 gfp_t gfp)
Johannes Bergad7e7182013-11-13 13:37:47 +01006753{
6754 struct sk_buff *skb;
6755 void *hdr;
6756 struct nlattr *data;
6757
6758 skb = nlmsg_new(approxlen + 100, gfp);
6759 if (!skb)
6760 return NULL;
6761
6762 hdr = nl80211hdr_put(skb, portid, seq, 0, cmd);
6763 if (!hdr) {
6764 kfree_skb(skb);
6765 return NULL;
6766 }
6767
6768 if (nla_put_u32(skb, NL80211_ATTR_WIPHY, rdev->wiphy_idx))
6769 goto nla_put_failure;
Johannes Berg567ffc32013-12-18 14:43:31 +01006770
6771 if (info) {
6772 if (nla_put_u32(skb, NL80211_ATTR_VENDOR_ID,
6773 info->vendor_id))
6774 goto nla_put_failure;
6775 if (nla_put_u32(skb, NL80211_ATTR_VENDOR_SUBCMD,
6776 info->subcmd))
6777 goto nla_put_failure;
6778 }
6779
Johannes Bergad7e7182013-11-13 13:37:47 +01006780 data = nla_nest_start(skb, attr);
6781
6782 ((void **)skb->cb)[0] = rdev;
6783 ((void **)skb->cb)[1] = hdr;
6784 ((void **)skb->cb)[2] = data;
6785
6786 return skb;
6787
6788 nla_put_failure:
6789 kfree_skb(skb);
6790 return NULL;
6791}
Antonio Quartullif4e583c2012-11-02 13:27:48 +01006792
Johannes Berge03ad6e2014-01-01 17:22:30 +01006793struct sk_buff *__cfg80211_alloc_event_skb(struct wiphy *wiphy,
6794 enum nl80211_commands cmd,
6795 enum nl80211_attrs attr,
6796 int vendor_event_idx,
6797 int approxlen, gfp_t gfp)
6798{
6799 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
6800 const struct nl80211_vendor_cmd_info *info;
6801
6802 switch (cmd) {
6803 case NL80211_CMD_TESTMODE:
6804 if (WARN_ON(vendor_event_idx != -1))
6805 return NULL;
6806 info = NULL;
6807 break;
6808 case NL80211_CMD_VENDOR:
6809 if (WARN_ON(vendor_event_idx < 0 ||
6810 vendor_event_idx >= wiphy->n_vendor_events))
6811 return NULL;
6812 info = &wiphy->vendor_events[vendor_event_idx];
6813 break;
6814 default:
6815 WARN_ON(1);
6816 return NULL;
6817 }
6818
6819 return __cfg80211_alloc_vendor_skb(rdev, approxlen, 0, 0,
6820 cmd, attr, info, gfp);
6821}
6822EXPORT_SYMBOL(__cfg80211_alloc_event_skb);
6823
6824void __cfg80211_send_event_skb(struct sk_buff *skb, gfp_t gfp)
6825{
6826 struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0];
6827 void *hdr = ((void **)skb->cb)[1];
6828 struct nlattr *data = ((void **)skb->cb)[2];
6829 enum nl80211_multicast_groups mcgrp = NL80211_MCGRP_TESTMODE;
6830
6831 nla_nest_end(skb, data);
6832 genlmsg_end(skb, hdr);
6833
6834 if (data->nla_type == NL80211_ATTR_VENDOR_DATA)
6835 mcgrp = NL80211_MCGRP_VENDOR;
6836
6837 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), skb, 0,
6838 mcgrp, gfp);
6839}
6840EXPORT_SYMBOL(__cfg80211_send_event_skb);
6841
Johannes Bergaff89a92009-07-01 21:26:51 +02006842#ifdef CONFIG_NL80211_TESTMODE
Johannes Bergaff89a92009-07-01 21:26:51 +02006843static int nl80211_testmode_do(struct sk_buff *skb, struct genl_info *info)
6844{
Johannes Berg4c476992010-10-04 21:36:35 +02006845 struct cfg80211_registered_device *rdev = info->user_ptr[0];
David Spinadelfc73f112013-07-31 18:04:15 +03006846 struct wireless_dev *wdev =
6847 __cfg80211_wdev_from_attrs(genl_info_net(info), info->attrs);
Johannes Bergaff89a92009-07-01 21:26:51 +02006848 int err;
6849
David Spinadelfc73f112013-07-31 18:04:15 +03006850 if (!rdev->ops->testmode_cmd)
6851 return -EOPNOTSUPP;
6852
6853 if (IS_ERR(wdev)) {
6854 err = PTR_ERR(wdev);
6855 if (err != -EINVAL)
6856 return err;
6857 wdev = NULL;
6858 } else if (wdev->wiphy != &rdev->wiphy) {
6859 return -EINVAL;
6860 }
6861
Johannes Bergaff89a92009-07-01 21:26:51 +02006862 if (!info->attrs[NL80211_ATTR_TESTDATA])
6863 return -EINVAL;
6864
Johannes Bergad7e7182013-11-13 13:37:47 +01006865 rdev->cur_cmd_info = info;
David Spinadelfc73f112013-07-31 18:04:15 +03006866 err = rdev_testmode_cmd(rdev, wdev,
Johannes Bergaff89a92009-07-01 21:26:51 +02006867 nla_data(info->attrs[NL80211_ATTR_TESTDATA]),
6868 nla_len(info->attrs[NL80211_ATTR_TESTDATA]));
Johannes Bergad7e7182013-11-13 13:37:47 +01006869 rdev->cur_cmd_info = NULL;
Johannes Bergaff89a92009-07-01 21:26:51 +02006870
Johannes Bergaff89a92009-07-01 21:26:51 +02006871 return err;
6872}
6873
Wey-Yi Guy71063f02011-05-20 09:05:54 -07006874static int nl80211_testmode_dump(struct sk_buff *skb,
6875 struct netlink_callback *cb)
6876{
Johannes Berg00918d32011-12-13 17:22:05 +01006877 struct cfg80211_registered_device *rdev;
Wey-Yi Guy71063f02011-05-20 09:05:54 -07006878 int err;
6879 long phy_idx;
6880 void *data = NULL;
6881 int data_len = 0;
6882
Johannes Berg5fe231e2013-05-08 21:45:15 +02006883 rtnl_lock();
6884
Wey-Yi Guy71063f02011-05-20 09:05:54 -07006885 if (cb->args[0]) {
6886 /*
6887 * 0 is a valid index, but not valid for args[0],
6888 * so we need to offset by 1.
6889 */
6890 phy_idx = cb->args[0] - 1;
6891 } else {
6892 err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize,
6893 nl80211_fam.attrbuf, nl80211_fam.maxattr,
6894 nl80211_policy);
6895 if (err)
Johannes Berg5fe231e2013-05-08 21:45:15 +02006896 goto out_err;
Johannes Berg00918d32011-12-13 17:22:05 +01006897
Johannes Berg2bd7e352012-06-15 14:23:16 +02006898 rdev = __cfg80211_rdev_from_attrs(sock_net(skb->sk),
6899 nl80211_fam.attrbuf);
6900 if (IS_ERR(rdev)) {
Johannes Berg5fe231e2013-05-08 21:45:15 +02006901 err = PTR_ERR(rdev);
6902 goto out_err;
Johannes Berg00918d32011-12-13 17:22:05 +01006903 }
Johannes Berg2bd7e352012-06-15 14:23:16 +02006904 phy_idx = rdev->wiphy_idx;
6905 rdev = NULL;
Johannes Berg2bd7e352012-06-15 14:23:16 +02006906
Wey-Yi Guy71063f02011-05-20 09:05:54 -07006907 if (nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA])
6908 cb->args[1] =
6909 (long)nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA];
6910 }
6911
6912 if (cb->args[1]) {
6913 data = nla_data((void *)cb->args[1]);
6914 data_len = nla_len((void *)cb->args[1]);
6915 }
6916
Johannes Berg00918d32011-12-13 17:22:05 +01006917 rdev = cfg80211_rdev_by_wiphy_idx(phy_idx);
6918 if (!rdev) {
Johannes Berg5fe231e2013-05-08 21:45:15 +02006919 err = -ENOENT;
6920 goto out_err;
Wey-Yi Guy71063f02011-05-20 09:05:54 -07006921 }
Wey-Yi Guy71063f02011-05-20 09:05:54 -07006922
Johannes Berg00918d32011-12-13 17:22:05 +01006923 if (!rdev->ops->testmode_dump) {
Wey-Yi Guy71063f02011-05-20 09:05:54 -07006924 err = -EOPNOTSUPP;
6925 goto out_err;
6926 }
6927
6928 while (1) {
Eric W. Biederman15e47302012-09-07 20:12:54 +00006929 void *hdr = nl80211hdr_put(skb, NETLINK_CB(cb->skb).portid,
Wey-Yi Guy71063f02011-05-20 09:05:54 -07006930 cb->nlh->nlmsg_seq, NLM_F_MULTI,
6931 NL80211_CMD_TESTMODE);
6932 struct nlattr *tmdata;
6933
Dan Carpentercb35fba2013-08-14 14:50:01 +03006934 if (!hdr)
6935 break;
6936
David S. Miller9360ffd2012-03-29 04:41:26 -04006937 if (nla_put_u32(skb, NL80211_ATTR_WIPHY, phy_idx)) {
Wey-Yi Guy71063f02011-05-20 09:05:54 -07006938 genlmsg_cancel(skb, hdr);
6939 break;
6940 }
6941
6942 tmdata = nla_nest_start(skb, NL80211_ATTR_TESTDATA);
6943 if (!tmdata) {
6944 genlmsg_cancel(skb, hdr);
6945 break;
6946 }
Hila Gonene35e4d22012-06-27 17:19:42 +03006947 err = rdev_testmode_dump(rdev, skb, cb, data, data_len);
Wey-Yi Guy71063f02011-05-20 09:05:54 -07006948 nla_nest_end(skb, tmdata);
6949
6950 if (err == -ENOBUFS || err == -ENOENT) {
6951 genlmsg_cancel(skb, hdr);
6952 break;
6953 } else if (err) {
6954 genlmsg_cancel(skb, hdr);
6955 goto out_err;
6956 }
6957
6958 genlmsg_end(skb, hdr);
6959 }
6960
6961 err = skb->len;
6962 /* see above */
6963 cb->args[0] = phy_idx + 1;
6964 out_err:
Johannes Berg5fe231e2013-05-08 21:45:15 +02006965 rtnl_unlock();
Wey-Yi Guy71063f02011-05-20 09:05:54 -07006966 return err;
6967}
Johannes Bergaff89a92009-07-01 21:26:51 +02006968#endif
6969
Samuel Ortizb23aa672009-07-01 21:26:54 +02006970static int nl80211_connect(struct sk_buff *skb, struct genl_info *info)
6971{
Johannes Berg4c476992010-10-04 21:36:35 +02006972 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6973 struct net_device *dev = info->user_ptr[1];
Samuel Ortizb23aa672009-07-01 21:26:54 +02006974 struct cfg80211_connect_params connect;
6975 struct wiphy *wiphy;
Johannes Bergfffd0932009-07-08 14:22:54 +02006976 struct cfg80211_cached_keys *connkeys = NULL;
Samuel Ortizb23aa672009-07-01 21:26:54 +02006977 int err;
6978
6979 memset(&connect, 0, sizeof(connect));
6980
6981 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
6982 return -EINVAL;
6983
6984 if (!info->attrs[NL80211_ATTR_SSID] ||
6985 !nla_len(info->attrs[NL80211_ATTR_SSID]))
6986 return -EINVAL;
6987
6988 if (info->attrs[NL80211_ATTR_AUTH_TYPE]) {
6989 connect.auth_type =
6990 nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]);
Jouni Malinene39e5b52012-09-30 19:29:39 +03006991 if (!nl80211_valid_auth_type(rdev, connect.auth_type,
6992 NL80211_CMD_CONNECT))
Samuel Ortizb23aa672009-07-01 21:26:54 +02006993 return -EINVAL;
6994 } else
6995 connect.auth_type = NL80211_AUTHTYPE_AUTOMATIC;
6996
6997 connect.privacy = info->attrs[NL80211_ATTR_PRIVACY];
6998
Johannes Bergc0692b82010-08-27 14:26:53 +03006999 err = nl80211_crypto_settings(rdev, info, &connect.crypto,
Johannes Berg3dc27d22009-07-02 21:36:37 +02007000 NL80211_MAX_NR_CIPHER_SUITES);
Samuel Ortizb23aa672009-07-01 21:26:54 +02007001 if (err)
7002 return err;
Samuel Ortizb23aa672009-07-01 21:26:54 +02007003
Johannes Berg074ac8d2010-09-16 14:58:22 +02007004 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02007005 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
7006 return -EOPNOTSUPP;
Samuel Ortizb23aa672009-07-01 21:26:54 +02007007
Johannes Berg79c97e92009-07-07 03:56:12 +02007008 wiphy = &rdev->wiphy;
Samuel Ortizb23aa672009-07-01 21:26:54 +02007009
Bala Shanmugam4486ea92012-03-07 17:27:12 +05307010 connect.bg_scan_period = -1;
7011 if (info->attrs[NL80211_ATTR_BG_SCAN_PERIOD] &&
7012 (wiphy->flags & WIPHY_FLAG_SUPPORTS_FW_ROAM)) {
7013 connect.bg_scan_period =
7014 nla_get_u16(info->attrs[NL80211_ATTR_BG_SCAN_PERIOD]);
7015 }
7016
Samuel Ortizb23aa672009-07-01 21:26:54 +02007017 if (info->attrs[NL80211_ATTR_MAC])
7018 connect.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen1df4a512014-01-15 00:00:47 +02007019 else if (info->attrs[NL80211_ATTR_MAC_HINT])
7020 connect.bssid_hint =
7021 nla_data(info->attrs[NL80211_ATTR_MAC_HINT]);
Samuel Ortizb23aa672009-07-01 21:26:54 +02007022 connect.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
7023 connect.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
7024
7025 if (info->attrs[NL80211_ATTR_IE]) {
7026 connect.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
7027 connect.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
7028 }
7029
Jouni Malinencee00a92013-01-15 17:15:57 +02007030 if (info->attrs[NL80211_ATTR_USE_MFP]) {
7031 connect.mfp = nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]);
7032 if (connect.mfp != NL80211_MFP_REQUIRED &&
7033 connect.mfp != NL80211_MFP_NO)
7034 return -EINVAL;
7035 } else {
7036 connect.mfp = NL80211_MFP_NO;
7037 }
7038
Samuel Ortizb23aa672009-07-01 21:26:54 +02007039 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
Jouni Malinen664834d2014-01-15 00:01:44 +02007040 connect.channel = nl80211_get_valid_chan(
7041 wiphy, info->attrs[NL80211_ATTR_WIPHY_FREQ]);
7042 if (!connect.channel)
Johannes Berg4c476992010-10-04 21:36:35 +02007043 return -EINVAL;
Jouni Malinen1df4a512014-01-15 00:00:47 +02007044 } else if (info->attrs[NL80211_ATTR_WIPHY_FREQ_HINT]) {
Jouni Malinen664834d2014-01-15 00:01:44 +02007045 connect.channel_hint = nl80211_get_valid_chan(
7046 wiphy, info->attrs[NL80211_ATTR_WIPHY_FREQ_HINT]);
7047 if (!connect.channel_hint)
Jouni Malinen1df4a512014-01-15 00:00:47 +02007048 return -EINVAL;
Samuel Ortizb23aa672009-07-01 21:26:54 +02007049 }
7050
Johannes Bergfffd0932009-07-08 14:22:54 +02007051 if (connect.privacy && info->attrs[NL80211_ATTR_KEYS]) {
7052 connkeys = nl80211_parse_connkeys(rdev,
Sujith Manoharande7044e2012-10-18 10:19:28 +05307053 info->attrs[NL80211_ATTR_KEYS], NULL);
Johannes Berg4c476992010-10-04 21:36:35 +02007054 if (IS_ERR(connkeys))
7055 return PTR_ERR(connkeys);
Johannes Bergfffd0932009-07-08 14:22:54 +02007056 }
7057
Ben Greear7e7c8922011-11-18 11:31:59 -08007058 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT]))
7059 connect.flags |= ASSOC_REQ_DISABLE_HT;
7060
7061 if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
7062 memcpy(&connect.ht_capa_mask,
7063 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]),
7064 sizeof(connect.ht_capa_mask));
7065
7066 if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) {
Wei Yongjunb4e4f472012-09-02 21:41:04 +08007067 if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) {
7068 kfree(connkeys);
Ben Greear7e7c8922011-11-18 11:31:59 -08007069 return -EINVAL;
Wei Yongjunb4e4f472012-09-02 21:41:04 +08007070 }
Ben Greear7e7c8922011-11-18 11:31:59 -08007071 memcpy(&connect.ht_capa,
7072 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]),
7073 sizeof(connect.ht_capa));
7074 }
7075
Johannes Bergee2aca32013-02-21 17:36:01 +01007076 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_VHT]))
7077 connect.flags |= ASSOC_REQ_DISABLE_VHT;
7078
7079 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK])
7080 memcpy(&connect.vht_capa_mask,
7081 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]),
7082 sizeof(connect.vht_capa_mask));
7083
7084 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) {
7085 if (!info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) {
7086 kfree(connkeys);
7087 return -EINVAL;
7088 }
7089 memcpy(&connect.vht_capa,
7090 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]),
7091 sizeof(connect.vht_capa));
7092 }
7093
Johannes Berg83739b02013-05-15 17:44:01 +02007094 wdev_lock(dev->ieee80211_ptr);
7095 err = cfg80211_connect(rdev, dev, &connect, connkeys, NULL);
7096 wdev_unlock(dev->ieee80211_ptr);
Johannes Bergfffd0932009-07-08 14:22:54 +02007097 if (err)
7098 kfree(connkeys);
Samuel Ortizb23aa672009-07-01 21:26:54 +02007099 return err;
7100}
7101
7102static int nl80211_disconnect(struct sk_buff *skb, struct genl_info *info)
7103{
Johannes Berg4c476992010-10-04 21:36:35 +02007104 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7105 struct net_device *dev = info->user_ptr[1];
Samuel Ortizb23aa672009-07-01 21:26:54 +02007106 u16 reason;
Johannes Berg83739b02013-05-15 17:44:01 +02007107 int ret;
Samuel Ortizb23aa672009-07-01 21:26:54 +02007108
7109 if (!info->attrs[NL80211_ATTR_REASON_CODE])
7110 reason = WLAN_REASON_DEAUTH_LEAVING;
7111 else
7112 reason = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
7113
7114 if (reason == 0)
7115 return -EINVAL;
7116
Johannes Berg074ac8d2010-09-16 14:58:22 +02007117 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02007118 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
7119 return -EOPNOTSUPP;
Samuel Ortizb23aa672009-07-01 21:26:54 +02007120
Johannes Berg83739b02013-05-15 17:44:01 +02007121 wdev_lock(dev->ieee80211_ptr);
7122 ret = cfg80211_disconnect(rdev, dev, reason, true);
7123 wdev_unlock(dev->ieee80211_ptr);
7124 return ret;
Samuel Ortizb23aa672009-07-01 21:26:54 +02007125}
7126
Johannes Berg463d0182009-07-14 00:33:35 +02007127static int nl80211_wiphy_netns(struct sk_buff *skb, struct genl_info *info)
7128{
Johannes Berg4c476992010-10-04 21:36:35 +02007129 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg463d0182009-07-14 00:33:35 +02007130 struct net *net;
7131 int err;
7132 u32 pid;
7133
7134 if (!info->attrs[NL80211_ATTR_PID])
7135 return -EINVAL;
7136
7137 pid = nla_get_u32(info->attrs[NL80211_ATTR_PID]);
7138
Johannes Berg463d0182009-07-14 00:33:35 +02007139 net = get_net_ns_by_pid(pid);
Johannes Berg4c476992010-10-04 21:36:35 +02007140 if (IS_ERR(net))
7141 return PTR_ERR(net);
Johannes Berg463d0182009-07-14 00:33:35 +02007142
7143 err = 0;
7144
7145 /* check if anything to do */
Johannes Berg4c476992010-10-04 21:36:35 +02007146 if (!net_eq(wiphy_net(&rdev->wiphy), net))
7147 err = cfg80211_switch_netns(rdev, net);
Johannes Berg463d0182009-07-14 00:33:35 +02007148
Johannes Berg463d0182009-07-14 00:33:35 +02007149 put_net(net);
Johannes Berg463d0182009-07-14 00:33:35 +02007150 return err;
7151}
7152
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007153static int nl80211_setdel_pmksa(struct sk_buff *skb, struct genl_info *info)
7154{
Johannes Berg4c476992010-10-04 21:36:35 +02007155 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007156 int (*rdev_ops)(struct wiphy *wiphy, struct net_device *dev,
7157 struct cfg80211_pmksa *pmksa) = NULL;
Johannes Berg4c476992010-10-04 21:36:35 +02007158 struct net_device *dev = info->user_ptr[1];
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007159 struct cfg80211_pmksa pmksa;
7160
7161 memset(&pmksa, 0, sizeof(struct cfg80211_pmksa));
7162
7163 if (!info->attrs[NL80211_ATTR_MAC])
7164 return -EINVAL;
7165
7166 if (!info->attrs[NL80211_ATTR_PMKID])
7167 return -EINVAL;
7168
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007169 pmksa.pmkid = nla_data(info->attrs[NL80211_ATTR_PMKID]);
7170 pmksa.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
7171
Johannes Berg074ac8d2010-09-16 14:58:22 +02007172 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02007173 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
7174 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007175
7176 switch (info->genlhdr->cmd) {
7177 case NL80211_CMD_SET_PMKSA:
7178 rdev_ops = rdev->ops->set_pmksa;
7179 break;
7180 case NL80211_CMD_DEL_PMKSA:
7181 rdev_ops = rdev->ops->del_pmksa;
7182 break;
7183 default:
7184 WARN_ON(1);
7185 break;
7186 }
7187
Johannes Berg4c476992010-10-04 21:36:35 +02007188 if (!rdev_ops)
7189 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007190
Johannes Berg4c476992010-10-04 21:36:35 +02007191 return rdev_ops(&rdev->wiphy, dev, &pmksa);
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007192}
7193
7194static int nl80211_flush_pmksa(struct sk_buff *skb, struct genl_info *info)
7195{
Johannes Berg4c476992010-10-04 21:36:35 +02007196 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7197 struct net_device *dev = info->user_ptr[1];
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007198
Johannes Berg074ac8d2010-09-16 14:58:22 +02007199 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02007200 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
7201 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007202
Johannes Berg4c476992010-10-04 21:36:35 +02007203 if (!rdev->ops->flush_pmksa)
7204 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007205
Hila Gonene35e4d22012-06-27 17:19:42 +03007206 return rdev_flush_pmksa(rdev, dev);
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007207}
7208
Arik Nemtsov109086c2011-09-28 14:12:50 +03007209static int nl80211_tdls_mgmt(struct sk_buff *skb, struct genl_info *info)
7210{
7211 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7212 struct net_device *dev = info->user_ptr[1];
7213 u8 action_code, dialog_token;
7214 u16 status_code;
7215 u8 *peer;
7216
7217 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) ||
7218 !rdev->ops->tdls_mgmt)
7219 return -EOPNOTSUPP;
7220
7221 if (!info->attrs[NL80211_ATTR_TDLS_ACTION] ||
7222 !info->attrs[NL80211_ATTR_STATUS_CODE] ||
7223 !info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN] ||
7224 !info->attrs[NL80211_ATTR_IE] ||
7225 !info->attrs[NL80211_ATTR_MAC])
7226 return -EINVAL;
7227
7228 peer = nla_data(info->attrs[NL80211_ATTR_MAC]);
7229 action_code = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_ACTION]);
7230 status_code = nla_get_u16(info->attrs[NL80211_ATTR_STATUS_CODE]);
7231 dialog_token = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN]);
7232
Hila Gonene35e4d22012-06-27 17:19:42 +03007233 return rdev_tdls_mgmt(rdev, dev, peer, action_code,
7234 dialog_token, status_code,
7235 nla_data(info->attrs[NL80211_ATTR_IE]),
7236 nla_len(info->attrs[NL80211_ATTR_IE]));
Arik Nemtsov109086c2011-09-28 14:12:50 +03007237}
7238
7239static int nl80211_tdls_oper(struct sk_buff *skb, struct genl_info *info)
7240{
7241 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7242 struct net_device *dev = info->user_ptr[1];
7243 enum nl80211_tdls_operation operation;
7244 u8 *peer;
7245
7246 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) ||
7247 !rdev->ops->tdls_oper)
7248 return -EOPNOTSUPP;
7249
7250 if (!info->attrs[NL80211_ATTR_TDLS_OPERATION] ||
7251 !info->attrs[NL80211_ATTR_MAC])
7252 return -EINVAL;
7253
7254 operation = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_OPERATION]);
7255 peer = nla_data(info->attrs[NL80211_ATTR_MAC]);
7256
Hila Gonene35e4d22012-06-27 17:19:42 +03007257 return rdev_tdls_oper(rdev, dev, peer, operation);
Arik Nemtsov109086c2011-09-28 14:12:50 +03007258}
7259
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007260static int nl80211_remain_on_channel(struct sk_buff *skb,
7261 struct genl_info *info)
7262{
Johannes Berg4c476992010-10-04 21:36:35 +02007263 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02007264 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg683b6d32012-11-08 21:25:48 +01007265 struct cfg80211_chan_def chandef;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007266 struct sk_buff *msg;
7267 void *hdr;
7268 u64 cookie;
Johannes Berg683b6d32012-11-08 21:25:48 +01007269 u32 duration;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007270 int err;
7271
7272 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] ||
7273 !info->attrs[NL80211_ATTR_DURATION])
7274 return -EINVAL;
7275
7276 duration = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]);
7277
Johannes Berg7c4ef712011-11-18 15:33:48 +01007278 if (!rdev->ops->remain_on_channel ||
7279 !(rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL))
Johannes Berg4c476992010-10-04 21:36:35 +02007280 return -EOPNOTSUPP;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007281
Johannes Bergebf348f2012-06-01 12:50:54 +02007282 /*
7283 * We should be on that channel for at least a minimum amount of
7284 * time (10ms) but no longer than the driver supports.
7285 */
7286 if (duration < NL80211_MIN_REMAIN_ON_CHANNEL_TIME ||
7287 duration > rdev->wiphy.max_remain_on_channel_duration)
7288 return -EINVAL;
7289
Johannes Berg683b6d32012-11-08 21:25:48 +01007290 err = nl80211_parse_chandef(rdev, info, &chandef);
7291 if (err)
7292 return err;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007293
7294 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02007295 if (!msg)
7296 return -ENOMEM;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007297
Eric W. Biederman15e47302012-09-07 20:12:54 +00007298 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007299 NL80211_CMD_REMAIN_ON_CHANNEL);
Dan Carpentercb35fba2013-08-14 14:50:01 +03007300 if (!hdr) {
7301 err = -ENOBUFS;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007302 goto free_msg;
7303 }
7304
Johannes Berg683b6d32012-11-08 21:25:48 +01007305 err = rdev_remain_on_channel(rdev, wdev, chandef.chan,
7306 duration, &cookie);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007307
7308 if (err)
7309 goto free_msg;
7310
David S. Miller9360ffd2012-03-29 04:41:26 -04007311 if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie))
7312 goto nla_put_failure;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007313
7314 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02007315
7316 return genlmsg_reply(msg, info);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007317
7318 nla_put_failure:
7319 err = -ENOBUFS;
7320 free_msg:
7321 nlmsg_free(msg);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007322 return err;
7323}
7324
7325static int nl80211_cancel_remain_on_channel(struct sk_buff *skb,
7326 struct genl_info *info)
7327{
Johannes Berg4c476992010-10-04 21:36:35 +02007328 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02007329 struct wireless_dev *wdev = info->user_ptr[1];
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007330 u64 cookie;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007331
7332 if (!info->attrs[NL80211_ATTR_COOKIE])
7333 return -EINVAL;
7334
Johannes Berg4c476992010-10-04 21:36:35 +02007335 if (!rdev->ops->cancel_remain_on_channel)
7336 return -EOPNOTSUPP;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007337
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007338 cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]);
7339
Hila Gonene35e4d22012-06-27 17:19:42 +03007340 return rdev_cancel_remain_on_channel(rdev, wdev, cookie);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007341}
7342
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007343static u32 rateset_to_mask(struct ieee80211_supported_band *sband,
7344 u8 *rates, u8 rates_len)
7345{
7346 u8 i;
7347 u32 mask = 0;
7348
7349 for (i = 0; i < rates_len; i++) {
7350 int rate = (rates[i] & 0x7f) * 5;
7351 int ridx;
7352 for (ridx = 0; ridx < sband->n_bitrates; ridx++) {
7353 struct ieee80211_rate *srate =
7354 &sband->bitrates[ridx];
7355 if (rate == srate->bitrate) {
7356 mask |= 1 << ridx;
7357 break;
7358 }
7359 }
7360 if (ridx == sband->n_bitrates)
7361 return 0; /* rate not found */
7362 }
7363
7364 return mask;
7365}
7366
Simon Wunderlich24db78c2012-01-28 17:25:32 +01007367static bool ht_rateset_to_mask(struct ieee80211_supported_band *sband,
7368 u8 *rates, u8 rates_len,
7369 u8 mcs[IEEE80211_HT_MCS_MASK_LEN])
7370{
7371 u8 i;
7372
7373 memset(mcs, 0, IEEE80211_HT_MCS_MASK_LEN);
7374
7375 for (i = 0; i < rates_len; i++) {
7376 int ridx, rbit;
7377
7378 ridx = rates[i] / 8;
7379 rbit = BIT(rates[i] % 8);
7380
7381 /* check validity */
Dan Carpenter910570b52012-02-01 10:42:11 +03007382 if ((ridx < 0) || (ridx >= IEEE80211_HT_MCS_MASK_LEN))
Simon Wunderlich24db78c2012-01-28 17:25:32 +01007383 return false;
7384
7385 /* check availability */
7386 if (sband->ht_cap.mcs.rx_mask[ridx] & rbit)
7387 mcs[ridx] |= rbit;
7388 else
7389 return false;
7390 }
7391
7392 return true;
7393}
7394
Janusz Dziedzic204e35a2013-12-05 20:42:58 +01007395static u16 vht_mcs_map_to_mcs_mask(u8 vht_mcs_map)
7396{
7397 u16 mcs_mask = 0;
7398
7399 switch (vht_mcs_map) {
7400 case IEEE80211_VHT_MCS_NOT_SUPPORTED:
7401 break;
7402 case IEEE80211_VHT_MCS_SUPPORT_0_7:
7403 mcs_mask = 0x00FF;
7404 break;
7405 case IEEE80211_VHT_MCS_SUPPORT_0_8:
7406 mcs_mask = 0x01FF;
7407 break;
7408 case IEEE80211_VHT_MCS_SUPPORT_0_9:
7409 mcs_mask = 0x03FF;
7410 break;
7411 default:
7412 break;
7413 }
7414
7415 return mcs_mask;
7416}
7417
7418static void vht_build_mcs_mask(u16 vht_mcs_map,
7419 u16 vht_mcs_mask[NL80211_VHT_NSS_MAX])
7420{
7421 u8 nss;
7422
7423 for (nss = 0; nss < NL80211_VHT_NSS_MAX; nss++) {
7424 vht_mcs_mask[nss] = vht_mcs_map_to_mcs_mask(vht_mcs_map & 0x03);
7425 vht_mcs_map >>= 2;
7426 }
7427}
7428
7429static bool vht_set_mcs_mask(struct ieee80211_supported_band *sband,
7430 struct nl80211_txrate_vht *txrate,
7431 u16 mcs[NL80211_VHT_NSS_MAX])
7432{
7433 u16 tx_mcs_map = le16_to_cpu(sband->vht_cap.vht_mcs.tx_mcs_map);
7434 u16 tx_mcs_mask[NL80211_VHT_NSS_MAX] = {};
7435 u8 i;
7436
7437 if (!sband->vht_cap.vht_supported)
7438 return false;
7439
7440 memset(mcs, 0, sizeof(u16) * NL80211_VHT_NSS_MAX);
7441
7442 /* Build vht_mcs_mask from VHT capabilities */
7443 vht_build_mcs_mask(tx_mcs_map, tx_mcs_mask);
7444
7445 for (i = 0; i < NL80211_VHT_NSS_MAX; i++) {
7446 if ((tx_mcs_mask[i] & txrate->mcs[i]) == txrate->mcs[i])
7447 mcs[i] = txrate->mcs[i];
7448 else
7449 return false;
7450 }
7451
7452 return true;
7453}
7454
Alexey Dobriyanb54452b2010-02-18 08:14:31 +00007455static const struct nla_policy nl80211_txattr_policy[NL80211_TXRATE_MAX + 1] = {
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007456 [NL80211_TXRATE_LEGACY] = { .type = NLA_BINARY,
7457 .len = NL80211_MAX_SUPP_RATES },
Janusz Dziedzicd1e33e62013-12-05 10:02:15 +01007458 [NL80211_TXRATE_HT] = { .type = NLA_BINARY,
7459 .len = NL80211_MAX_SUPP_HT_RATES },
Janusz Dziedzic204e35a2013-12-05 20:42:58 +01007460 [NL80211_TXRATE_VHT] = { .len = sizeof(struct nl80211_txrate_vht)},
Janusz Dziedzic0b9323f2014-01-08 08:46:02 +01007461 [NL80211_TXRATE_GI] = { .type = NLA_U8 },
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007462};
7463
7464static int nl80211_set_tx_bitrate_mask(struct sk_buff *skb,
7465 struct genl_info *info)
7466{
7467 struct nlattr *tb[NL80211_TXRATE_MAX + 1];
Johannes Berg4c476992010-10-04 21:36:35 +02007468 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007469 struct cfg80211_bitrate_mask mask;
Johannes Berg4c476992010-10-04 21:36:35 +02007470 int rem, i;
7471 struct net_device *dev = info->user_ptr[1];
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007472 struct nlattr *tx_rates;
7473 struct ieee80211_supported_band *sband;
Janusz Dziedzic204e35a2013-12-05 20:42:58 +01007474 u16 vht_tx_mcs_map;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007475
Johannes Berg4c476992010-10-04 21:36:35 +02007476 if (!rdev->ops->set_bitrate_mask)
7477 return -EOPNOTSUPP;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007478
7479 memset(&mask, 0, sizeof(mask));
7480 /* Default to all rates enabled */
7481 for (i = 0; i < IEEE80211_NUM_BANDS; i++) {
7482 sband = rdev->wiphy.bands[i];
Janusz Dziedzic78693032013-12-03 09:50:44 +01007483
7484 if (!sband)
7485 continue;
7486
7487 mask.control[i].legacy = (1 << sband->n_bitrates) - 1;
Janusz Dziedzicd1e33e62013-12-05 10:02:15 +01007488 memcpy(mask.control[i].ht_mcs,
Janusz Dziedzic78693032013-12-03 09:50:44 +01007489 sband->ht_cap.mcs.rx_mask,
Janusz Dziedzicd1e33e62013-12-05 10:02:15 +01007490 sizeof(mask.control[i].ht_mcs));
Janusz Dziedzic204e35a2013-12-05 20:42:58 +01007491
7492 if (!sband->vht_cap.vht_supported)
7493 continue;
7494
7495 vht_tx_mcs_map = le16_to_cpu(sband->vht_cap.vht_mcs.tx_mcs_map);
7496 vht_build_mcs_mask(vht_tx_mcs_map, mask.control[i].vht_mcs);
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007497 }
7498
Janusz Dziedzicb9243ab2013-12-05 10:02:14 +01007499 /* if no rates are given set it back to the defaults */
7500 if (!info->attrs[NL80211_ATTR_TX_RATES])
7501 goto out;
7502
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007503 /*
7504 * The nested attribute uses enum nl80211_band as the index. This maps
7505 * directly to the enum ieee80211_band values used in cfg80211.
7506 */
Simon Wunderlich24db78c2012-01-28 17:25:32 +01007507 BUILD_BUG_ON(NL80211_MAX_SUPP_HT_RATES > IEEE80211_HT_MCS_MASK_LEN * 8);
Johannes Bergae811e22014-01-24 10:17:47 +01007508 nla_for_each_nested(tx_rates, info->attrs[NL80211_ATTR_TX_RATES], rem) {
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007509 enum ieee80211_band band = nla_type(tx_rates);
Johannes Bergae811e22014-01-24 10:17:47 +01007510 int err;
7511
Johannes Berg4c476992010-10-04 21:36:35 +02007512 if (band < 0 || band >= IEEE80211_NUM_BANDS)
7513 return -EINVAL;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007514 sband = rdev->wiphy.bands[band];
Johannes Berg4c476992010-10-04 21:36:35 +02007515 if (sband == NULL)
7516 return -EINVAL;
Johannes Bergae811e22014-01-24 10:17:47 +01007517 err = nla_parse(tb, NL80211_TXRATE_MAX, nla_data(tx_rates),
7518 nla_len(tx_rates), nl80211_txattr_policy);
7519 if (err)
7520 return err;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007521 if (tb[NL80211_TXRATE_LEGACY]) {
7522 mask.control[band].legacy = rateset_to_mask(
7523 sband,
7524 nla_data(tb[NL80211_TXRATE_LEGACY]),
7525 nla_len(tb[NL80211_TXRATE_LEGACY]));
Bala Shanmugam218d2e22012-04-20 19:12:58 +05307526 if ((mask.control[band].legacy == 0) &&
7527 nla_len(tb[NL80211_TXRATE_LEGACY]))
7528 return -EINVAL;
Simon Wunderlich24db78c2012-01-28 17:25:32 +01007529 }
Janusz Dziedzicd1e33e62013-12-05 10:02:15 +01007530 if (tb[NL80211_TXRATE_HT]) {
Simon Wunderlich24db78c2012-01-28 17:25:32 +01007531 if (!ht_rateset_to_mask(
7532 sband,
Janusz Dziedzicd1e33e62013-12-05 10:02:15 +01007533 nla_data(tb[NL80211_TXRATE_HT]),
7534 nla_len(tb[NL80211_TXRATE_HT]),
7535 mask.control[band].ht_mcs))
Simon Wunderlich24db78c2012-01-28 17:25:32 +01007536 return -EINVAL;
7537 }
Janusz Dziedzic204e35a2013-12-05 20:42:58 +01007538 if (tb[NL80211_TXRATE_VHT]) {
7539 if (!vht_set_mcs_mask(
7540 sband,
7541 nla_data(tb[NL80211_TXRATE_VHT]),
7542 mask.control[band].vht_mcs))
7543 return -EINVAL;
7544 }
Janusz Dziedzic0b9323f2014-01-08 08:46:02 +01007545 if (tb[NL80211_TXRATE_GI]) {
7546 mask.control[band].gi =
7547 nla_get_u8(tb[NL80211_TXRATE_GI]);
7548 if (mask.control[band].gi > NL80211_TXRATE_FORCE_LGI)
7549 return -EINVAL;
7550 }
Simon Wunderlich24db78c2012-01-28 17:25:32 +01007551
7552 if (mask.control[band].legacy == 0) {
Janusz Dziedzic204e35a2013-12-05 20:42:58 +01007553 /* don't allow empty legacy rates if HT or VHT
7554 * are not even supported.
7555 */
7556 if (!(rdev->wiphy.bands[band]->ht_cap.ht_supported ||
7557 rdev->wiphy.bands[band]->vht_cap.vht_supported))
Simon Wunderlich24db78c2012-01-28 17:25:32 +01007558 return -EINVAL;
7559
7560 for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++)
Janusz Dziedzicd1e33e62013-12-05 10:02:15 +01007561 if (mask.control[band].ht_mcs[i])
Janusz Dziedzic204e35a2013-12-05 20:42:58 +01007562 goto out;
7563
7564 for (i = 0; i < NL80211_VHT_NSS_MAX; i++)
7565 if (mask.control[band].vht_mcs[i])
7566 goto out;
Simon Wunderlich24db78c2012-01-28 17:25:32 +01007567
7568 /* legacy and mcs rates may not be both empty */
Janusz Dziedzic204e35a2013-12-05 20:42:58 +01007569 return -EINVAL;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007570 }
7571 }
7572
Janusz Dziedzicb9243ab2013-12-05 10:02:14 +01007573out:
Hila Gonene35e4d22012-06-27 17:19:42 +03007574 return rdev_set_bitrate_mask(rdev, dev, NULL, &mask);
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007575}
7576
Johannes Berg2e161f72010-08-12 15:38:38 +02007577static int nl80211_register_mgmt(struct sk_buff *skb, struct genl_info *info)
Jouni Malinen026331c2010-02-15 12:53:10 +02007578{
Johannes Berg4c476992010-10-04 21:36:35 +02007579 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02007580 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg2e161f72010-08-12 15:38:38 +02007581 u16 frame_type = IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_ACTION;
Jouni Malinen026331c2010-02-15 12:53:10 +02007582
7583 if (!info->attrs[NL80211_ATTR_FRAME_MATCH])
7584 return -EINVAL;
7585
Johannes Berg2e161f72010-08-12 15:38:38 +02007586 if (info->attrs[NL80211_ATTR_FRAME_TYPE])
7587 frame_type = nla_get_u16(info->attrs[NL80211_ATTR_FRAME_TYPE]);
Jouni Malinen026331c2010-02-15 12:53:10 +02007588
Johannes Berg71bbc992012-06-15 15:30:18 +02007589 switch (wdev->iftype) {
7590 case NL80211_IFTYPE_STATION:
7591 case NL80211_IFTYPE_ADHOC:
7592 case NL80211_IFTYPE_P2P_CLIENT:
7593 case NL80211_IFTYPE_AP:
7594 case NL80211_IFTYPE_AP_VLAN:
7595 case NL80211_IFTYPE_MESH_POINT:
7596 case NL80211_IFTYPE_P2P_GO:
Johannes Berg98104fde2012-06-16 00:19:54 +02007597 case NL80211_IFTYPE_P2P_DEVICE:
Johannes Berg71bbc992012-06-15 15:30:18 +02007598 break;
7599 default:
Johannes Berg4c476992010-10-04 21:36:35 +02007600 return -EOPNOTSUPP;
Johannes Berg71bbc992012-06-15 15:30:18 +02007601 }
Jouni Malinen026331c2010-02-15 12:53:10 +02007602
7603 /* not much point in registering if we can't reply */
Johannes Berg4c476992010-10-04 21:36:35 +02007604 if (!rdev->ops->mgmt_tx)
7605 return -EOPNOTSUPP;
Jouni Malinen026331c2010-02-15 12:53:10 +02007606
Eric W. Biederman15e47302012-09-07 20:12:54 +00007607 return cfg80211_mlme_register_mgmt(wdev, info->snd_portid, frame_type,
Jouni Malinen026331c2010-02-15 12:53:10 +02007608 nla_data(info->attrs[NL80211_ATTR_FRAME_MATCH]),
7609 nla_len(info->attrs[NL80211_ATTR_FRAME_MATCH]));
Jouni Malinen026331c2010-02-15 12:53:10 +02007610}
7611
Johannes Berg2e161f72010-08-12 15:38:38 +02007612static int nl80211_tx_mgmt(struct sk_buff *skb, struct genl_info *info)
Jouni Malinen026331c2010-02-15 12:53:10 +02007613{
Johannes Berg4c476992010-10-04 21:36:35 +02007614 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02007615 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg683b6d32012-11-08 21:25:48 +01007616 struct cfg80211_chan_def chandef;
Jouni Malinen026331c2010-02-15 12:53:10 +02007617 int err;
Johannes Bergd64d3732011-11-10 09:44:46 +01007618 void *hdr = NULL;
Jouni Malinen026331c2010-02-15 12:53:10 +02007619 u64 cookie;
Johannes Berge247bd902011-11-04 11:18:21 +01007620 struct sk_buff *msg = NULL;
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02007621 struct cfg80211_mgmt_tx_params params = {
7622 .dont_wait_for_ack =
7623 info->attrs[NL80211_ATTR_DONT_WAIT_FOR_ACK],
7624 };
Jouni Malinen026331c2010-02-15 12:53:10 +02007625
Johannes Berg683b6d32012-11-08 21:25:48 +01007626 if (!info->attrs[NL80211_ATTR_FRAME])
Jouni Malinen026331c2010-02-15 12:53:10 +02007627 return -EINVAL;
7628
Johannes Berg4c476992010-10-04 21:36:35 +02007629 if (!rdev->ops->mgmt_tx)
7630 return -EOPNOTSUPP;
Jouni Malinen026331c2010-02-15 12:53:10 +02007631
Johannes Berg71bbc992012-06-15 15:30:18 +02007632 switch (wdev->iftype) {
Antonio Quartulliea141b752013-06-11 14:20:03 +02007633 case NL80211_IFTYPE_P2P_DEVICE:
7634 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ])
7635 return -EINVAL;
Johannes Berg71bbc992012-06-15 15:30:18 +02007636 case NL80211_IFTYPE_STATION:
7637 case NL80211_IFTYPE_ADHOC:
7638 case NL80211_IFTYPE_P2P_CLIENT:
7639 case NL80211_IFTYPE_AP:
7640 case NL80211_IFTYPE_AP_VLAN:
7641 case NL80211_IFTYPE_MESH_POINT:
7642 case NL80211_IFTYPE_P2P_GO:
7643 break;
7644 default:
Johannes Berg4c476992010-10-04 21:36:35 +02007645 return -EOPNOTSUPP;
Johannes Berg71bbc992012-06-15 15:30:18 +02007646 }
Jouni Malinen026331c2010-02-15 12:53:10 +02007647
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007648 if (info->attrs[NL80211_ATTR_DURATION]) {
Johannes Berg7c4ef712011-11-18 15:33:48 +01007649 if (!(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX))
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007650 return -EINVAL;
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02007651 params.wait = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]);
Johannes Bergebf348f2012-06-01 12:50:54 +02007652
7653 /*
7654 * We should wait on the channel for at least a minimum amount
7655 * of time (10ms) but no longer than the driver supports.
7656 */
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02007657 if (params.wait < NL80211_MIN_REMAIN_ON_CHANNEL_TIME ||
7658 params.wait > rdev->wiphy.max_remain_on_channel_duration)
Johannes Bergebf348f2012-06-01 12:50:54 +02007659 return -EINVAL;
7660
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007661 }
7662
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02007663 params.offchan = info->attrs[NL80211_ATTR_OFFCHANNEL_TX_OK];
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007664
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02007665 if (params.offchan && !(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX))
Johannes Berg7c4ef712011-11-18 15:33:48 +01007666 return -EINVAL;
7667
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02007668 params.no_cck = nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]);
Rajkumar Manoharane9f935e2011-09-25 14:53:30 +05307669
Antonio Quartulliea141b752013-06-11 14:20:03 +02007670 /* get the channel if any has been specified, otherwise pass NULL to
7671 * the driver. The latter will use the current one
7672 */
7673 chandef.chan = NULL;
7674 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
7675 err = nl80211_parse_chandef(rdev, info, &chandef);
7676 if (err)
7677 return err;
7678 }
7679
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02007680 if (!chandef.chan && params.offchan)
Antonio Quartulliea141b752013-06-11 14:20:03 +02007681 return -EINVAL;
Jouni Malinen026331c2010-02-15 12:53:10 +02007682
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02007683 if (!params.dont_wait_for_ack) {
Johannes Berge247bd902011-11-04 11:18:21 +01007684 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
7685 if (!msg)
7686 return -ENOMEM;
Jouni Malinen026331c2010-02-15 12:53:10 +02007687
Eric W. Biederman15e47302012-09-07 20:12:54 +00007688 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berge247bd902011-11-04 11:18:21 +01007689 NL80211_CMD_FRAME);
Dan Carpentercb35fba2013-08-14 14:50:01 +03007690 if (!hdr) {
7691 err = -ENOBUFS;
Johannes Berge247bd902011-11-04 11:18:21 +01007692 goto free_msg;
7693 }
Jouni Malinen026331c2010-02-15 12:53:10 +02007694 }
Johannes Berge247bd902011-11-04 11:18:21 +01007695
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02007696 params.buf = nla_data(info->attrs[NL80211_ATTR_FRAME]);
7697 params.len = nla_len(info->attrs[NL80211_ATTR_FRAME]);
7698 params.chan = chandef.chan;
7699 err = cfg80211_mlme_mgmt_tx(rdev, wdev, &params, &cookie);
Jouni Malinen026331c2010-02-15 12:53:10 +02007700 if (err)
7701 goto free_msg;
7702
Johannes Berge247bd902011-11-04 11:18:21 +01007703 if (msg) {
David S. Miller9360ffd2012-03-29 04:41:26 -04007704 if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie))
7705 goto nla_put_failure;
Jouni Malinen026331c2010-02-15 12:53:10 +02007706
Johannes Berge247bd902011-11-04 11:18:21 +01007707 genlmsg_end(msg, hdr);
7708 return genlmsg_reply(msg, info);
7709 }
7710
7711 return 0;
Jouni Malinen026331c2010-02-15 12:53:10 +02007712
7713 nla_put_failure:
7714 err = -ENOBUFS;
7715 free_msg:
7716 nlmsg_free(msg);
Jouni Malinen026331c2010-02-15 12:53:10 +02007717 return err;
7718}
7719
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007720static int nl80211_tx_mgmt_cancel_wait(struct sk_buff *skb, struct genl_info *info)
7721{
7722 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02007723 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007724 u64 cookie;
7725
7726 if (!info->attrs[NL80211_ATTR_COOKIE])
7727 return -EINVAL;
7728
7729 if (!rdev->ops->mgmt_tx_cancel_wait)
7730 return -EOPNOTSUPP;
7731
Johannes Berg71bbc992012-06-15 15:30:18 +02007732 switch (wdev->iftype) {
7733 case NL80211_IFTYPE_STATION:
7734 case NL80211_IFTYPE_ADHOC:
7735 case NL80211_IFTYPE_P2P_CLIENT:
7736 case NL80211_IFTYPE_AP:
7737 case NL80211_IFTYPE_AP_VLAN:
7738 case NL80211_IFTYPE_P2P_GO:
Johannes Berg98104fde2012-06-16 00:19:54 +02007739 case NL80211_IFTYPE_P2P_DEVICE:
Johannes Berg71bbc992012-06-15 15:30:18 +02007740 break;
7741 default:
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007742 return -EOPNOTSUPP;
Johannes Berg71bbc992012-06-15 15:30:18 +02007743 }
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007744
7745 cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]);
7746
Hila Gonene35e4d22012-06-27 17:19:42 +03007747 return rdev_mgmt_tx_cancel_wait(rdev, wdev, cookie);
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007748}
7749
Kalle Valoffb9eb32010-02-17 17:58:10 +02007750static int nl80211_set_power_save(struct sk_buff *skb, struct genl_info *info)
7751{
Johannes Berg4c476992010-10-04 21:36:35 +02007752 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Kalle Valoffb9eb32010-02-17 17:58:10 +02007753 struct wireless_dev *wdev;
Johannes Berg4c476992010-10-04 21:36:35 +02007754 struct net_device *dev = info->user_ptr[1];
Kalle Valoffb9eb32010-02-17 17:58:10 +02007755 u8 ps_state;
7756 bool state;
7757 int err;
7758
Johannes Berg4c476992010-10-04 21:36:35 +02007759 if (!info->attrs[NL80211_ATTR_PS_STATE])
7760 return -EINVAL;
Kalle Valoffb9eb32010-02-17 17:58:10 +02007761
7762 ps_state = nla_get_u32(info->attrs[NL80211_ATTR_PS_STATE]);
7763
Johannes Berg4c476992010-10-04 21:36:35 +02007764 if (ps_state != NL80211_PS_DISABLED && ps_state != NL80211_PS_ENABLED)
7765 return -EINVAL;
Kalle Valoffb9eb32010-02-17 17:58:10 +02007766
7767 wdev = dev->ieee80211_ptr;
7768
Johannes Berg4c476992010-10-04 21:36:35 +02007769 if (!rdev->ops->set_power_mgmt)
7770 return -EOPNOTSUPP;
Kalle Valoffb9eb32010-02-17 17:58:10 +02007771
7772 state = (ps_state == NL80211_PS_ENABLED) ? true : false;
7773
7774 if (state == wdev->ps)
Johannes Berg4c476992010-10-04 21:36:35 +02007775 return 0;
Kalle Valoffb9eb32010-02-17 17:58:10 +02007776
Hila Gonene35e4d22012-06-27 17:19:42 +03007777 err = rdev_set_power_mgmt(rdev, dev, state, wdev->ps_timeout);
Johannes Berg4c476992010-10-04 21:36:35 +02007778 if (!err)
7779 wdev->ps = state;
Kalle Valoffb9eb32010-02-17 17:58:10 +02007780 return err;
7781}
7782
7783static int nl80211_get_power_save(struct sk_buff *skb, struct genl_info *info)
7784{
Johannes Berg4c476992010-10-04 21:36:35 +02007785 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Kalle Valoffb9eb32010-02-17 17:58:10 +02007786 enum nl80211_ps_state ps_state;
7787 struct wireless_dev *wdev;
Johannes Berg4c476992010-10-04 21:36:35 +02007788 struct net_device *dev = info->user_ptr[1];
Kalle Valoffb9eb32010-02-17 17:58:10 +02007789 struct sk_buff *msg;
7790 void *hdr;
7791 int err;
7792
Kalle Valoffb9eb32010-02-17 17:58:10 +02007793 wdev = dev->ieee80211_ptr;
7794
Johannes Berg4c476992010-10-04 21:36:35 +02007795 if (!rdev->ops->set_power_mgmt)
7796 return -EOPNOTSUPP;
Kalle Valoffb9eb32010-02-17 17:58:10 +02007797
7798 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02007799 if (!msg)
7800 return -ENOMEM;
Kalle Valoffb9eb32010-02-17 17:58:10 +02007801
Eric W. Biederman15e47302012-09-07 20:12:54 +00007802 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Kalle Valoffb9eb32010-02-17 17:58:10 +02007803 NL80211_CMD_GET_POWER_SAVE);
7804 if (!hdr) {
Johannes Berg4c476992010-10-04 21:36:35 +02007805 err = -ENOBUFS;
Kalle Valoffb9eb32010-02-17 17:58:10 +02007806 goto free_msg;
7807 }
7808
7809 if (wdev->ps)
7810 ps_state = NL80211_PS_ENABLED;
7811 else
7812 ps_state = NL80211_PS_DISABLED;
7813
David S. Miller9360ffd2012-03-29 04:41:26 -04007814 if (nla_put_u32(msg, NL80211_ATTR_PS_STATE, ps_state))
7815 goto nla_put_failure;
Kalle Valoffb9eb32010-02-17 17:58:10 +02007816
7817 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02007818 return genlmsg_reply(msg, info);
Kalle Valoffb9eb32010-02-17 17:58:10 +02007819
Johannes Berg4c476992010-10-04 21:36:35 +02007820 nla_put_failure:
Kalle Valoffb9eb32010-02-17 17:58:10 +02007821 err = -ENOBUFS;
Johannes Berg4c476992010-10-04 21:36:35 +02007822 free_msg:
Kalle Valoffb9eb32010-02-17 17:58:10 +02007823 nlmsg_free(msg);
Kalle Valoffb9eb32010-02-17 17:58:10 +02007824 return err;
7825}
7826
Johannes Berg94e860f2014-01-20 23:58:15 +01007827static const struct nla_policy
7828nl80211_attr_cqm_policy[NL80211_ATTR_CQM_MAX + 1] = {
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02007829 [NL80211_ATTR_CQM_RSSI_THOLD] = { .type = NLA_U32 },
7830 [NL80211_ATTR_CQM_RSSI_HYST] = { .type = NLA_U32 },
7831 [NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT] = { .type = NLA_U32 },
Thomas Pedersen84f10702012-07-12 16:17:33 -07007832 [NL80211_ATTR_CQM_TXE_RATE] = { .type = NLA_U32 },
7833 [NL80211_ATTR_CQM_TXE_PKTS] = { .type = NLA_U32 },
7834 [NL80211_ATTR_CQM_TXE_INTVL] = { .type = NLA_U32 },
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02007835};
7836
Thomas Pedersen84f10702012-07-12 16:17:33 -07007837static int nl80211_set_cqm_txe(struct genl_info *info,
Johannes Bergd9d8b012012-11-26 12:51:52 +01007838 u32 rate, u32 pkts, u32 intvl)
Thomas Pedersen84f10702012-07-12 16:17:33 -07007839{
7840 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Thomas Pedersen84f10702012-07-12 16:17:33 -07007841 struct net_device *dev = info->user_ptr[1];
Johannes Berg1da5fcc2013-08-06 14:10:48 +02007842 struct wireless_dev *wdev = dev->ieee80211_ptr;
Thomas Pedersen84f10702012-07-12 16:17:33 -07007843
Johannes Bergd9d8b012012-11-26 12:51:52 +01007844 if (rate > 100 || intvl > NL80211_CQM_TXE_MAX_INTVL)
Thomas Pedersen84f10702012-07-12 16:17:33 -07007845 return -EINVAL;
7846
Thomas Pedersen84f10702012-07-12 16:17:33 -07007847 if (!rdev->ops->set_cqm_txe_config)
7848 return -EOPNOTSUPP;
7849
7850 if (wdev->iftype != NL80211_IFTYPE_STATION &&
7851 wdev->iftype != NL80211_IFTYPE_P2P_CLIENT)
7852 return -EOPNOTSUPP;
7853
Hila Gonene35e4d22012-06-27 17:19:42 +03007854 return rdev_set_cqm_txe_config(rdev, dev, rate, pkts, intvl);
Thomas Pedersen84f10702012-07-12 16:17:33 -07007855}
7856
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02007857static int nl80211_set_cqm_rssi(struct genl_info *info,
7858 s32 threshold, u32 hysteresis)
7859{
Johannes Berg4c476992010-10-04 21:36:35 +02007860 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg4c476992010-10-04 21:36:35 +02007861 struct net_device *dev = info->user_ptr[1];
Johannes Berg1da5fcc2013-08-06 14:10:48 +02007862 struct wireless_dev *wdev = dev->ieee80211_ptr;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02007863
7864 if (threshold > 0)
7865 return -EINVAL;
7866
Johannes Berg1da5fcc2013-08-06 14:10:48 +02007867 /* disabling - hysteresis should also be zero then */
7868 if (threshold == 0)
7869 hysteresis = 0;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02007870
Johannes Berg4c476992010-10-04 21:36:35 +02007871 if (!rdev->ops->set_cqm_rssi_config)
7872 return -EOPNOTSUPP;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02007873
Johannes Berg074ac8d2010-09-16 14:58:22 +02007874 if (wdev->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02007875 wdev->iftype != NL80211_IFTYPE_P2P_CLIENT)
7876 return -EOPNOTSUPP;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02007877
Hila Gonene35e4d22012-06-27 17:19:42 +03007878 return rdev_set_cqm_rssi_config(rdev, dev, threshold, hysteresis);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02007879}
7880
7881static int nl80211_set_cqm(struct sk_buff *skb, struct genl_info *info)
7882{
7883 struct nlattr *attrs[NL80211_ATTR_CQM_MAX + 1];
7884 struct nlattr *cqm;
7885 int err;
7886
7887 cqm = info->attrs[NL80211_ATTR_CQM];
Johannes Berg1da5fcc2013-08-06 14:10:48 +02007888 if (!cqm)
7889 return -EINVAL;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02007890
7891 err = nla_parse_nested(attrs, NL80211_ATTR_CQM_MAX, cqm,
7892 nl80211_attr_cqm_policy);
7893 if (err)
Johannes Berg1da5fcc2013-08-06 14:10:48 +02007894 return err;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02007895
7896 if (attrs[NL80211_ATTR_CQM_RSSI_THOLD] &&
7897 attrs[NL80211_ATTR_CQM_RSSI_HYST]) {
Johannes Berg1da5fcc2013-08-06 14:10:48 +02007898 s32 threshold = nla_get_s32(attrs[NL80211_ATTR_CQM_RSSI_THOLD]);
7899 u32 hysteresis = nla_get_u32(attrs[NL80211_ATTR_CQM_RSSI_HYST]);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02007900
Johannes Berg1da5fcc2013-08-06 14:10:48 +02007901 return nl80211_set_cqm_rssi(info, threshold, hysteresis);
7902 }
7903
7904 if (attrs[NL80211_ATTR_CQM_TXE_RATE] &&
7905 attrs[NL80211_ATTR_CQM_TXE_PKTS] &&
7906 attrs[NL80211_ATTR_CQM_TXE_INTVL]) {
7907 u32 rate = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_RATE]);
7908 u32 pkts = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_PKTS]);
7909 u32 intvl = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_INTVL]);
7910
7911 return nl80211_set_cqm_txe(info, rate, pkts, intvl);
7912 }
7913
7914 return -EINVAL;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02007915}
7916
Johannes Berg29cbe682010-12-03 09:20:44 +01007917static int nl80211_join_mesh(struct sk_buff *skb, struct genl_info *info)
7918{
7919 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7920 struct net_device *dev = info->user_ptr[1];
7921 struct mesh_config cfg;
Javier Cardonac80d5452010-12-16 17:37:49 -08007922 struct mesh_setup setup;
Johannes Berg29cbe682010-12-03 09:20:44 +01007923 int err;
7924
7925 /* start with default */
7926 memcpy(&cfg, &default_mesh_config, sizeof(cfg));
Javier Cardonac80d5452010-12-16 17:37:49 -08007927 memcpy(&setup, &default_mesh_setup, sizeof(setup));
Johannes Berg29cbe682010-12-03 09:20:44 +01007928
Javier Cardona24bdd9f2010-12-16 17:37:48 -08007929 if (info->attrs[NL80211_ATTR_MESH_CONFIG]) {
Johannes Berg29cbe682010-12-03 09:20:44 +01007930 /* and parse parameters if given */
Javier Cardona24bdd9f2010-12-16 17:37:48 -08007931 err = nl80211_parse_mesh_config(info, &cfg, NULL);
Johannes Berg29cbe682010-12-03 09:20:44 +01007932 if (err)
7933 return err;
7934 }
7935
7936 if (!info->attrs[NL80211_ATTR_MESH_ID] ||
7937 !nla_len(info->attrs[NL80211_ATTR_MESH_ID]))
7938 return -EINVAL;
7939
Javier Cardonac80d5452010-12-16 17:37:49 -08007940 setup.mesh_id = nla_data(info->attrs[NL80211_ATTR_MESH_ID]);
7941 setup.mesh_id_len = nla_len(info->attrs[NL80211_ATTR_MESH_ID]);
7942
Chun-Yeow Yeoh4bb62342011-11-24 17:15:20 -08007943 if (info->attrs[NL80211_ATTR_MCAST_RATE] &&
7944 !nl80211_parse_mcast_rate(rdev, setup.mcast_rate,
7945 nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE])))
7946 return -EINVAL;
7947
Marco Porsch9bdbf042013-01-07 16:04:51 +01007948 if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) {
7949 setup.beacon_interval =
7950 nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]);
7951 if (setup.beacon_interval < 10 ||
7952 setup.beacon_interval > 10000)
7953 return -EINVAL;
7954 }
7955
7956 if (info->attrs[NL80211_ATTR_DTIM_PERIOD]) {
7957 setup.dtim_period =
7958 nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]);
7959 if (setup.dtim_period < 1 || setup.dtim_period > 100)
7960 return -EINVAL;
7961 }
7962
Javier Cardonac80d5452010-12-16 17:37:49 -08007963 if (info->attrs[NL80211_ATTR_MESH_SETUP]) {
7964 /* parse additional setup parameters if given */
7965 err = nl80211_parse_mesh_setup(info, &setup);
7966 if (err)
7967 return err;
7968 }
7969
Thomas Pedersend37bb182013-03-04 13:06:13 -08007970 if (setup.user_mpm)
7971 cfg.auto_open_plinks = false;
7972
Johannes Bergcc1d2802012-05-16 23:50:20 +02007973 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
Johannes Berg683b6d32012-11-08 21:25:48 +01007974 err = nl80211_parse_chandef(rdev, info, &setup.chandef);
7975 if (err)
7976 return err;
Johannes Bergcc1d2802012-05-16 23:50:20 +02007977 } else {
7978 /* cfg80211_join_mesh() will sort it out */
Johannes Berg683b6d32012-11-08 21:25:48 +01007979 setup.chandef.chan = NULL;
Johannes Bergcc1d2802012-05-16 23:50:20 +02007980 }
7981
Ashok Nagarajanffb3cf32013-06-03 10:33:36 -07007982 if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) {
7983 u8 *rates = nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
7984 int n_rates =
7985 nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
7986 struct ieee80211_supported_band *sband;
7987
7988 if (!setup.chandef.chan)
7989 return -EINVAL;
7990
7991 sband = rdev->wiphy.bands[setup.chandef.chan->band];
7992
7993 err = ieee80211_get_ratemask(sband, rates, n_rates,
7994 &setup.basic_rates);
7995 if (err)
7996 return err;
7997 }
7998
Javier Cardonac80d5452010-12-16 17:37:49 -08007999 return cfg80211_join_mesh(rdev, dev, &setup, &cfg);
Johannes Berg29cbe682010-12-03 09:20:44 +01008000}
8001
8002static int nl80211_leave_mesh(struct sk_buff *skb, struct genl_info *info)
8003{
8004 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8005 struct net_device *dev = info->user_ptr[1];
8006
8007 return cfg80211_leave_mesh(rdev, dev);
8008}
8009
Johannes Bergdfb89c52012-06-27 09:23:48 +02008010#ifdef CONFIG_PM
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08008011static int nl80211_send_wowlan_patterns(struct sk_buff *msg,
8012 struct cfg80211_registered_device *rdev)
8013{
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008014 struct cfg80211_wowlan *wowlan = rdev->wiphy.wowlan_config;
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08008015 struct nlattr *nl_pats, *nl_pat;
8016 int i, pat_len;
8017
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008018 if (!wowlan->n_patterns)
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08008019 return 0;
8020
8021 nl_pats = nla_nest_start(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN);
8022 if (!nl_pats)
8023 return -ENOBUFS;
8024
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008025 for (i = 0; i < wowlan->n_patterns; i++) {
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08008026 nl_pat = nla_nest_start(msg, i + 1);
8027 if (!nl_pat)
8028 return -ENOBUFS;
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008029 pat_len = wowlan->patterns[i].pattern_len;
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07008030 if (nla_put(msg, NL80211_PKTPAT_MASK, DIV_ROUND_UP(pat_len, 8),
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008031 wowlan->patterns[i].mask) ||
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07008032 nla_put(msg, NL80211_PKTPAT_PATTERN, pat_len,
8033 wowlan->patterns[i].pattern) ||
8034 nla_put_u32(msg, NL80211_PKTPAT_OFFSET,
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008035 wowlan->patterns[i].pkt_offset))
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08008036 return -ENOBUFS;
8037 nla_nest_end(msg, nl_pat);
8038 }
8039 nla_nest_end(msg, nl_pats);
8040
8041 return 0;
8042}
8043
Johannes Berg2a0e0472013-01-23 22:57:40 +01008044static int nl80211_send_wowlan_tcp(struct sk_buff *msg,
8045 struct cfg80211_wowlan_tcp *tcp)
8046{
8047 struct nlattr *nl_tcp;
8048
8049 if (!tcp)
8050 return 0;
8051
8052 nl_tcp = nla_nest_start(msg, NL80211_WOWLAN_TRIG_TCP_CONNECTION);
8053 if (!nl_tcp)
8054 return -ENOBUFS;
8055
8056 if (nla_put_be32(msg, NL80211_WOWLAN_TCP_SRC_IPV4, tcp->src) ||
8057 nla_put_be32(msg, NL80211_WOWLAN_TCP_DST_IPV4, tcp->dst) ||
8058 nla_put(msg, NL80211_WOWLAN_TCP_DST_MAC, ETH_ALEN, tcp->dst_mac) ||
8059 nla_put_u16(msg, NL80211_WOWLAN_TCP_SRC_PORT, tcp->src_port) ||
8060 nla_put_u16(msg, NL80211_WOWLAN_TCP_DST_PORT, tcp->dst_port) ||
8061 nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD,
8062 tcp->payload_len, tcp->payload) ||
8063 nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_INTERVAL,
8064 tcp->data_interval) ||
8065 nla_put(msg, NL80211_WOWLAN_TCP_WAKE_PAYLOAD,
8066 tcp->wake_len, tcp->wake_data) ||
8067 nla_put(msg, NL80211_WOWLAN_TCP_WAKE_MASK,
8068 DIV_ROUND_UP(tcp->wake_len, 8), tcp->wake_mask))
8069 return -ENOBUFS;
8070
8071 if (tcp->payload_seq.len &&
8072 nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ,
8073 sizeof(tcp->payload_seq), &tcp->payload_seq))
8074 return -ENOBUFS;
8075
8076 if (tcp->payload_tok.len &&
8077 nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN,
8078 sizeof(tcp->payload_tok) + tcp->tokens_size,
8079 &tcp->payload_tok))
8080 return -ENOBUFS;
8081
Johannes Berge248ad32013-05-16 10:24:28 +02008082 nla_nest_end(msg, nl_tcp);
8083
Johannes Berg2a0e0472013-01-23 22:57:40 +01008084 return 0;
8085}
8086
Johannes Bergff1b6e62011-05-04 15:37:28 +02008087static int nl80211_get_wowlan(struct sk_buff *skb, struct genl_info *info)
8088{
8089 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8090 struct sk_buff *msg;
8091 void *hdr;
Johannes Berg2a0e0472013-01-23 22:57:40 +01008092 u32 size = NLMSG_DEFAULT_SIZE;
Johannes Bergff1b6e62011-05-04 15:37:28 +02008093
Johannes Berg964dc9e2013-06-03 17:25:34 +02008094 if (!rdev->wiphy.wowlan)
Johannes Bergff1b6e62011-05-04 15:37:28 +02008095 return -EOPNOTSUPP;
8096
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008097 if (rdev->wiphy.wowlan_config && rdev->wiphy.wowlan_config->tcp) {
Johannes Berg2a0e0472013-01-23 22:57:40 +01008098 /* adjust size to have room for all the data */
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008099 size += rdev->wiphy.wowlan_config->tcp->tokens_size +
8100 rdev->wiphy.wowlan_config->tcp->payload_len +
8101 rdev->wiphy.wowlan_config->tcp->wake_len +
8102 rdev->wiphy.wowlan_config->tcp->wake_len / 8;
Johannes Berg2a0e0472013-01-23 22:57:40 +01008103 }
8104
8105 msg = nlmsg_new(size, GFP_KERNEL);
Johannes Bergff1b6e62011-05-04 15:37:28 +02008106 if (!msg)
8107 return -ENOMEM;
8108
Eric W. Biederman15e47302012-09-07 20:12:54 +00008109 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Johannes Bergff1b6e62011-05-04 15:37:28 +02008110 NL80211_CMD_GET_WOWLAN);
8111 if (!hdr)
8112 goto nla_put_failure;
8113
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008114 if (rdev->wiphy.wowlan_config) {
Johannes Bergff1b6e62011-05-04 15:37:28 +02008115 struct nlattr *nl_wowlan;
8116
8117 nl_wowlan = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS);
8118 if (!nl_wowlan)
8119 goto nla_put_failure;
8120
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008121 if ((rdev->wiphy.wowlan_config->any &&
David S. Miller9360ffd2012-03-29 04:41:26 -04008122 nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008123 (rdev->wiphy.wowlan_config->disconnect &&
David S. Miller9360ffd2012-03-29 04:41:26 -04008124 nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008125 (rdev->wiphy.wowlan_config->magic_pkt &&
David S. Miller9360ffd2012-03-29 04:41:26 -04008126 nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008127 (rdev->wiphy.wowlan_config->gtk_rekey_failure &&
David S. Miller9360ffd2012-03-29 04:41:26 -04008128 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008129 (rdev->wiphy.wowlan_config->eap_identity_req &&
David S. Miller9360ffd2012-03-29 04:41:26 -04008130 nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008131 (rdev->wiphy.wowlan_config->four_way_handshake &&
David S. Miller9360ffd2012-03-29 04:41:26 -04008132 nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008133 (rdev->wiphy.wowlan_config->rfkill_release &&
David S. Miller9360ffd2012-03-29 04:41:26 -04008134 nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE)))
8135 goto nla_put_failure;
Johannes Berg2a0e0472013-01-23 22:57:40 +01008136
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08008137 if (nl80211_send_wowlan_patterns(msg, rdev))
8138 goto nla_put_failure;
Johannes Berg2a0e0472013-01-23 22:57:40 +01008139
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008140 if (nl80211_send_wowlan_tcp(msg,
8141 rdev->wiphy.wowlan_config->tcp))
Johannes Berg2a0e0472013-01-23 22:57:40 +01008142 goto nla_put_failure;
8143
Johannes Bergff1b6e62011-05-04 15:37:28 +02008144 nla_nest_end(msg, nl_wowlan);
8145 }
8146
8147 genlmsg_end(msg, hdr);
8148 return genlmsg_reply(msg, info);
8149
8150nla_put_failure:
8151 nlmsg_free(msg);
8152 return -ENOBUFS;
8153}
8154
Johannes Berg2a0e0472013-01-23 22:57:40 +01008155static int nl80211_parse_wowlan_tcp(struct cfg80211_registered_device *rdev,
8156 struct nlattr *attr,
8157 struct cfg80211_wowlan *trig)
8158{
8159 struct nlattr *tb[NUM_NL80211_WOWLAN_TCP];
8160 struct cfg80211_wowlan_tcp *cfg;
8161 struct nl80211_wowlan_tcp_data_token *tok = NULL;
8162 struct nl80211_wowlan_tcp_data_seq *seq = NULL;
8163 u32 size;
8164 u32 data_size, wake_size, tokens_size = 0, wake_mask_size;
8165 int err, port;
8166
Johannes Berg964dc9e2013-06-03 17:25:34 +02008167 if (!rdev->wiphy.wowlan->tcp)
Johannes Berg2a0e0472013-01-23 22:57:40 +01008168 return -EINVAL;
8169
8170 err = nla_parse(tb, MAX_NL80211_WOWLAN_TCP,
8171 nla_data(attr), nla_len(attr),
8172 nl80211_wowlan_tcp_policy);
8173 if (err)
8174 return err;
8175
8176 if (!tb[NL80211_WOWLAN_TCP_SRC_IPV4] ||
8177 !tb[NL80211_WOWLAN_TCP_DST_IPV4] ||
8178 !tb[NL80211_WOWLAN_TCP_DST_MAC] ||
8179 !tb[NL80211_WOWLAN_TCP_DST_PORT] ||
8180 !tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD] ||
8181 !tb[NL80211_WOWLAN_TCP_DATA_INTERVAL] ||
8182 !tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD] ||
8183 !tb[NL80211_WOWLAN_TCP_WAKE_MASK])
8184 return -EINVAL;
8185
8186 data_size = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]);
Johannes Berg964dc9e2013-06-03 17:25:34 +02008187 if (data_size > rdev->wiphy.wowlan->tcp->data_payload_max)
Johannes Berg2a0e0472013-01-23 22:57:40 +01008188 return -EINVAL;
8189
8190 if (nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]) >
Johannes Berg964dc9e2013-06-03 17:25:34 +02008191 rdev->wiphy.wowlan->tcp->data_interval_max ||
Johannes Berg723d5682013-02-26 13:56:40 +01008192 nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]) == 0)
Johannes Berg2a0e0472013-01-23 22:57:40 +01008193 return -EINVAL;
8194
8195 wake_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]);
Johannes Berg964dc9e2013-06-03 17:25:34 +02008196 if (wake_size > rdev->wiphy.wowlan->tcp->wake_payload_max)
Johannes Berg2a0e0472013-01-23 22:57:40 +01008197 return -EINVAL;
8198
8199 wake_mask_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_MASK]);
8200 if (wake_mask_size != DIV_ROUND_UP(wake_size, 8))
8201 return -EINVAL;
8202
8203 if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]) {
8204 u32 tokln = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]);
8205
8206 tok = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]);
8207 tokens_size = tokln - sizeof(*tok);
8208
8209 if (!tok->len || tokens_size % tok->len)
8210 return -EINVAL;
Johannes Berg964dc9e2013-06-03 17:25:34 +02008211 if (!rdev->wiphy.wowlan->tcp->tok)
Johannes Berg2a0e0472013-01-23 22:57:40 +01008212 return -EINVAL;
Johannes Berg964dc9e2013-06-03 17:25:34 +02008213 if (tok->len > rdev->wiphy.wowlan->tcp->tok->max_len)
Johannes Berg2a0e0472013-01-23 22:57:40 +01008214 return -EINVAL;
Johannes Berg964dc9e2013-06-03 17:25:34 +02008215 if (tok->len < rdev->wiphy.wowlan->tcp->tok->min_len)
Johannes Berg2a0e0472013-01-23 22:57:40 +01008216 return -EINVAL;
Johannes Berg964dc9e2013-06-03 17:25:34 +02008217 if (tokens_size > rdev->wiphy.wowlan->tcp->tok->bufsize)
Johannes Berg2a0e0472013-01-23 22:57:40 +01008218 return -EINVAL;
8219 if (tok->offset + tok->len > data_size)
8220 return -EINVAL;
8221 }
8222
8223 if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]) {
8224 seq = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]);
Johannes Berg964dc9e2013-06-03 17:25:34 +02008225 if (!rdev->wiphy.wowlan->tcp->seq)
Johannes Berg2a0e0472013-01-23 22:57:40 +01008226 return -EINVAL;
8227 if (seq->len == 0 || seq->len > 4)
8228 return -EINVAL;
8229 if (seq->len + seq->offset > data_size)
8230 return -EINVAL;
8231 }
8232
8233 size = sizeof(*cfg);
8234 size += data_size;
8235 size += wake_size + wake_mask_size;
8236 size += tokens_size;
8237
8238 cfg = kzalloc(size, GFP_KERNEL);
8239 if (!cfg)
8240 return -ENOMEM;
8241 cfg->src = nla_get_be32(tb[NL80211_WOWLAN_TCP_SRC_IPV4]);
8242 cfg->dst = nla_get_be32(tb[NL80211_WOWLAN_TCP_DST_IPV4]);
8243 memcpy(cfg->dst_mac, nla_data(tb[NL80211_WOWLAN_TCP_DST_MAC]),
8244 ETH_ALEN);
8245 if (tb[NL80211_WOWLAN_TCP_SRC_PORT])
8246 port = nla_get_u16(tb[NL80211_WOWLAN_TCP_SRC_PORT]);
8247 else
8248 port = 0;
8249#ifdef CONFIG_INET
8250 /* allocate a socket and port for it and use it */
8251 err = __sock_create(wiphy_net(&rdev->wiphy), PF_INET, SOCK_STREAM,
8252 IPPROTO_TCP, &cfg->sock, 1);
8253 if (err) {
8254 kfree(cfg);
8255 return err;
8256 }
8257 if (inet_csk_get_port(cfg->sock->sk, port)) {
8258 sock_release(cfg->sock);
8259 kfree(cfg);
8260 return -EADDRINUSE;
8261 }
8262 cfg->src_port = inet_sk(cfg->sock->sk)->inet_num;
8263#else
8264 if (!port) {
8265 kfree(cfg);
8266 return -EINVAL;
8267 }
8268 cfg->src_port = port;
8269#endif
8270
8271 cfg->dst_port = nla_get_u16(tb[NL80211_WOWLAN_TCP_DST_PORT]);
8272 cfg->payload_len = data_size;
8273 cfg->payload = (u8 *)cfg + sizeof(*cfg) + tokens_size;
8274 memcpy((void *)cfg->payload,
8275 nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]),
8276 data_size);
8277 if (seq)
8278 cfg->payload_seq = *seq;
8279 cfg->data_interval = nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]);
8280 cfg->wake_len = wake_size;
8281 cfg->wake_data = (u8 *)cfg + sizeof(*cfg) + tokens_size + data_size;
8282 memcpy((void *)cfg->wake_data,
8283 nla_data(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]),
8284 wake_size);
8285 cfg->wake_mask = (u8 *)cfg + sizeof(*cfg) + tokens_size +
8286 data_size + wake_size;
8287 memcpy((void *)cfg->wake_mask,
8288 nla_data(tb[NL80211_WOWLAN_TCP_WAKE_MASK]),
8289 wake_mask_size);
8290 if (tok) {
8291 cfg->tokens_size = tokens_size;
8292 memcpy(&cfg->payload_tok, tok, sizeof(*tok) + tokens_size);
8293 }
8294
8295 trig->tcp = cfg;
8296
8297 return 0;
8298}
8299
Johannes Bergff1b6e62011-05-04 15:37:28 +02008300static int nl80211_set_wowlan(struct sk_buff *skb, struct genl_info *info)
8301{
8302 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8303 struct nlattr *tb[NUM_NL80211_WOWLAN_TRIG];
Johannes Bergff1b6e62011-05-04 15:37:28 +02008304 struct cfg80211_wowlan new_triggers = {};
Johannes Bergae33bd82012-07-12 16:25:02 +02008305 struct cfg80211_wowlan *ntrig;
Johannes Berg964dc9e2013-06-03 17:25:34 +02008306 const struct wiphy_wowlan_support *wowlan = rdev->wiphy.wowlan;
Johannes Bergff1b6e62011-05-04 15:37:28 +02008307 int err, i;
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008308 bool prev_enabled = rdev->wiphy.wowlan_config;
Johannes Bergff1b6e62011-05-04 15:37:28 +02008309
Johannes Berg964dc9e2013-06-03 17:25:34 +02008310 if (!wowlan)
Johannes Bergff1b6e62011-05-04 15:37:28 +02008311 return -EOPNOTSUPP;
8312
Johannes Bergae33bd82012-07-12 16:25:02 +02008313 if (!info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]) {
8314 cfg80211_rdev_free_wowlan(rdev);
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008315 rdev->wiphy.wowlan_config = NULL;
Johannes Bergae33bd82012-07-12 16:25:02 +02008316 goto set_wakeup;
8317 }
Johannes Bergff1b6e62011-05-04 15:37:28 +02008318
8319 err = nla_parse(tb, MAX_NL80211_WOWLAN_TRIG,
8320 nla_data(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]),
8321 nla_len(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]),
8322 nl80211_wowlan_policy);
8323 if (err)
8324 return err;
8325
8326 if (tb[NL80211_WOWLAN_TRIG_ANY]) {
8327 if (!(wowlan->flags & WIPHY_WOWLAN_ANY))
8328 return -EINVAL;
8329 new_triggers.any = true;
8330 }
8331
8332 if (tb[NL80211_WOWLAN_TRIG_DISCONNECT]) {
8333 if (!(wowlan->flags & WIPHY_WOWLAN_DISCONNECT))
8334 return -EINVAL;
8335 new_triggers.disconnect = true;
8336 }
8337
8338 if (tb[NL80211_WOWLAN_TRIG_MAGIC_PKT]) {
8339 if (!(wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT))
8340 return -EINVAL;
8341 new_triggers.magic_pkt = true;
8342 }
8343
Johannes Berg77dbbb12011-07-13 10:48:55 +02008344 if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED])
8345 return -EINVAL;
8346
8347 if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE]) {
8348 if (!(wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE))
8349 return -EINVAL;
8350 new_triggers.gtk_rekey_failure = true;
8351 }
8352
8353 if (tb[NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST]) {
8354 if (!(wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ))
8355 return -EINVAL;
8356 new_triggers.eap_identity_req = true;
8357 }
8358
8359 if (tb[NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE]) {
8360 if (!(wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE))
8361 return -EINVAL;
8362 new_triggers.four_way_handshake = true;
8363 }
8364
8365 if (tb[NL80211_WOWLAN_TRIG_RFKILL_RELEASE]) {
8366 if (!(wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE))
8367 return -EINVAL;
8368 new_triggers.rfkill_release = true;
8369 }
8370
Johannes Bergff1b6e62011-05-04 15:37:28 +02008371 if (tb[NL80211_WOWLAN_TRIG_PKT_PATTERN]) {
8372 struct nlattr *pat;
8373 int n_patterns = 0;
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08008374 int rem, pat_len, mask_len, pkt_offset;
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07008375 struct nlattr *pat_tb[NUM_NL80211_PKTPAT];
Johannes Bergff1b6e62011-05-04 15:37:28 +02008376
8377 nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN],
8378 rem)
8379 n_patterns++;
8380 if (n_patterns > wowlan->n_patterns)
8381 return -EINVAL;
8382
8383 new_triggers.patterns = kcalloc(n_patterns,
8384 sizeof(new_triggers.patterns[0]),
8385 GFP_KERNEL);
8386 if (!new_triggers.patterns)
8387 return -ENOMEM;
8388
8389 new_triggers.n_patterns = n_patterns;
8390 i = 0;
8391
8392 nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN],
8393 rem) {
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07008394 nla_parse(pat_tb, MAX_NL80211_PKTPAT, nla_data(pat),
8395 nla_len(pat), NULL);
Johannes Bergff1b6e62011-05-04 15:37:28 +02008396 err = -EINVAL;
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07008397 if (!pat_tb[NL80211_PKTPAT_MASK] ||
8398 !pat_tb[NL80211_PKTPAT_PATTERN])
Johannes Bergff1b6e62011-05-04 15:37:28 +02008399 goto error;
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07008400 pat_len = nla_len(pat_tb[NL80211_PKTPAT_PATTERN]);
Johannes Bergff1b6e62011-05-04 15:37:28 +02008401 mask_len = DIV_ROUND_UP(pat_len, 8);
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07008402 if (nla_len(pat_tb[NL80211_PKTPAT_MASK]) != mask_len)
Johannes Bergff1b6e62011-05-04 15:37:28 +02008403 goto error;
8404 if (pat_len > wowlan->pattern_max_len ||
8405 pat_len < wowlan->pattern_min_len)
8406 goto error;
8407
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07008408 if (!pat_tb[NL80211_PKTPAT_OFFSET])
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08008409 pkt_offset = 0;
8410 else
8411 pkt_offset = nla_get_u32(
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07008412 pat_tb[NL80211_PKTPAT_OFFSET]);
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08008413 if (pkt_offset > wowlan->max_pkt_offset)
8414 goto error;
8415 new_triggers.patterns[i].pkt_offset = pkt_offset;
8416
Johannes Bergff1b6e62011-05-04 15:37:28 +02008417 new_triggers.patterns[i].mask =
8418 kmalloc(mask_len + pat_len, GFP_KERNEL);
8419 if (!new_triggers.patterns[i].mask) {
8420 err = -ENOMEM;
8421 goto error;
8422 }
8423 new_triggers.patterns[i].pattern =
8424 new_triggers.patterns[i].mask + mask_len;
8425 memcpy(new_triggers.patterns[i].mask,
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07008426 nla_data(pat_tb[NL80211_PKTPAT_MASK]),
Johannes Bergff1b6e62011-05-04 15:37:28 +02008427 mask_len);
8428 new_triggers.patterns[i].pattern_len = pat_len;
8429 memcpy(new_triggers.patterns[i].pattern,
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07008430 nla_data(pat_tb[NL80211_PKTPAT_PATTERN]),
Johannes Bergff1b6e62011-05-04 15:37:28 +02008431 pat_len);
8432 i++;
8433 }
8434 }
8435
Johannes Berg2a0e0472013-01-23 22:57:40 +01008436 if (tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION]) {
8437 err = nl80211_parse_wowlan_tcp(
8438 rdev, tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION],
8439 &new_triggers);
8440 if (err)
8441 goto error;
8442 }
8443
Johannes Bergae33bd82012-07-12 16:25:02 +02008444 ntrig = kmemdup(&new_triggers, sizeof(new_triggers), GFP_KERNEL);
8445 if (!ntrig) {
8446 err = -ENOMEM;
8447 goto error;
Johannes Bergff1b6e62011-05-04 15:37:28 +02008448 }
Johannes Bergae33bd82012-07-12 16:25:02 +02008449 cfg80211_rdev_free_wowlan(rdev);
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008450 rdev->wiphy.wowlan_config = ntrig;
Johannes Bergff1b6e62011-05-04 15:37:28 +02008451
Johannes Bergae33bd82012-07-12 16:25:02 +02008452 set_wakeup:
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008453 if (rdev->ops->set_wakeup &&
8454 prev_enabled != !!rdev->wiphy.wowlan_config)
8455 rdev_set_wakeup(rdev, rdev->wiphy.wowlan_config);
Johannes Berg6d525632012-04-04 15:05:25 +02008456
Johannes Bergff1b6e62011-05-04 15:37:28 +02008457 return 0;
8458 error:
8459 for (i = 0; i < new_triggers.n_patterns; i++)
8460 kfree(new_triggers.patterns[i].mask);
8461 kfree(new_triggers.patterns);
Johannes Berg2a0e0472013-01-23 22:57:40 +01008462 if (new_triggers.tcp && new_triggers.tcp->sock)
8463 sock_release(new_triggers.tcp->sock);
8464 kfree(new_triggers.tcp);
Johannes Bergff1b6e62011-05-04 15:37:28 +02008465 return err;
8466}
Johannes Bergdfb89c52012-06-27 09:23:48 +02008467#endif
Johannes Bergff1b6e62011-05-04 15:37:28 +02008468
Amitkumar Karwarbe29b992013-06-28 11:51:26 -07008469static int nl80211_send_coalesce_rules(struct sk_buff *msg,
8470 struct cfg80211_registered_device *rdev)
8471{
8472 struct nlattr *nl_pats, *nl_pat, *nl_rule, *nl_rules;
8473 int i, j, pat_len;
8474 struct cfg80211_coalesce_rules *rule;
8475
8476 if (!rdev->coalesce->n_rules)
8477 return 0;
8478
8479 nl_rules = nla_nest_start(msg, NL80211_ATTR_COALESCE_RULE);
8480 if (!nl_rules)
8481 return -ENOBUFS;
8482
8483 for (i = 0; i < rdev->coalesce->n_rules; i++) {
8484 nl_rule = nla_nest_start(msg, i + 1);
8485 if (!nl_rule)
8486 return -ENOBUFS;
8487
8488 rule = &rdev->coalesce->rules[i];
8489 if (nla_put_u32(msg, NL80211_ATTR_COALESCE_RULE_DELAY,
8490 rule->delay))
8491 return -ENOBUFS;
8492
8493 if (nla_put_u32(msg, NL80211_ATTR_COALESCE_RULE_CONDITION,
8494 rule->condition))
8495 return -ENOBUFS;
8496
8497 nl_pats = nla_nest_start(msg,
8498 NL80211_ATTR_COALESCE_RULE_PKT_PATTERN);
8499 if (!nl_pats)
8500 return -ENOBUFS;
8501
8502 for (j = 0; j < rule->n_patterns; j++) {
8503 nl_pat = nla_nest_start(msg, j + 1);
8504 if (!nl_pat)
8505 return -ENOBUFS;
8506 pat_len = rule->patterns[j].pattern_len;
8507 if (nla_put(msg, NL80211_PKTPAT_MASK,
8508 DIV_ROUND_UP(pat_len, 8),
8509 rule->patterns[j].mask) ||
8510 nla_put(msg, NL80211_PKTPAT_PATTERN, pat_len,
8511 rule->patterns[j].pattern) ||
8512 nla_put_u32(msg, NL80211_PKTPAT_OFFSET,
8513 rule->patterns[j].pkt_offset))
8514 return -ENOBUFS;
8515 nla_nest_end(msg, nl_pat);
8516 }
8517 nla_nest_end(msg, nl_pats);
8518 nla_nest_end(msg, nl_rule);
8519 }
8520 nla_nest_end(msg, nl_rules);
8521
8522 return 0;
8523}
8524
8525static int nl80211_get_coalesce(struct sk_buff *skb, struct genl_info *info)
8526{
8527 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8528 struct sk_buff *msg;
8529 void *hdr;
8530
8531 if (!rdev->wiphy.coalesce)
8532 return -EOPNOTSUPP;
8533
8534 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
8535 if (!msg)
8536 return -ENOMEM;
8537
8538 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
8539 NL80211_CMD_GET_COALESCE);
8540 if (!hdr)
8541 goto nla_put_failure;
8542
8543 if (rdev->coalesce && nl80211_send_coalesce_rules(msg, rdev))
8544 goto nla_put_failure;
8545
8546 genlmsg_end(msg, hdr);
8547 return genlmsg_reply(msg, info);
8548
8549nla_put_failure:
8550 nlmsg_free(msg);
8551 return -ENOBUFS;
8552}
8553
8554void cfg80211_rdev_free_coalesce(struct cfg80211_registered_device *rdev)
8555{
8556 struct cfg80211_coalesce *coalesce = rdev->coalesce;
8557 int i, j;
8558 struct cfg80211_coalesce_rules *rule;
8559
8560 if (!coalesce)
8561 return;
8562
8563 for (i = 0; i < coalesce->n_rules; i++) {
8564 rule = &coalesce->rules[i];
8565 for (j = 0; j < rule->n_patterns; j++)
8566 kfree(rule->patterns[j].mask);
8567 kfree(rule->patterns);
8568 }
8569 kfree(coalesce->rules);
8570 kfree(coalesce);
8571 rdev->coalesce = NULL;
8572}
8573
8574static int nl80211_parse_coalesce_rule(struct cfg80211_registered_device *rdev,
8575 struct nlattr *rule,
8576 struct cfg80211_coalesce_rules *new_rule)
8577{
8578 int err, i;
8579 const struct wiphy_coalesce_support *coalesce = rdev->wiphy.coalesce;
8580 struct nlattr *tb[NUM_NL80211_ATTR_COALESCE_RULE], *pat;
8581 int rem, pat_len, mask_len, pkt_offset, n_patterns = 0;
8582 struct nlattr *pat_tb[NUM_NL80211_PKTPAT];
8583
8584 err = nla_parse(tb, NL80211_ATTR_COALESCE_RULE_MAX, nla_data(rule),
8585 nla_len(rule), nl80211_coalesce_policy);
8586 if (err)
8587 return err;
8588
8589 if (tb[NL80211_ATTR_COALESCE_RULE_DELAY])
8590 new_rule->delay =
8591 nla_get_u32(tb[NL80211_ATTR_COALESCE_RULE_DELAY]);
8592 if (new_rule->delay > coalesce->max_delay)
8593 return -EINVAL;
8594
8595 if (tb[NL80211_ATTR_COALESCE_RULE_CONDITION])
8596 new_rule->condition =
8597 nla_get_u32(tb[NL80211_ATTR_COALESCE_RULE_CONDITION]);
8598 if (new_rule->condition != NL80211_COALESCE_CONDITION_MATCH &&
8599 new_rule->condition != NL80211_COALESCE_CONDITION_NO_MATCH)
8600 return -EINVAL;
8601
8602 if (!tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN])
8603 return -EINVAL;
8604
8605 nla_for_each_nested(pat, tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN],
8606 rem)
8607 n_patterns++;
8608 if (n_patterns > coalesce->n_patterns)
8609 return -EINVAL;
8610
8611 new_rule->patterns = kcalloc(n_patterns, sizeof(new_rule->patterns[0]),
8612 GFP_KERNEL);
8613 if (!new_rule->patterns)
8614 return -ENOMEM;
8615
8616 new_rule->n_patterns = n_patterns;
8617 i = 0;
8618
8619 nla_for_each_nested(pat, tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN],
8620 rem) {
8621 nla_parse(pat_tb, MAX_NL80211_PKTPAT, nla_data(pat),
8622 nla_len(pat), NULL);
8623 if (!pat_tb[NL80211_PKTPAT_MASK] ||
8624 !pat_tb[NL80211_PKTPAT_PATTERN])
8625 return -EINVAL;
8626 pat_len = nla_len(pat_tb[NL80211_PKTPAT_PATTERN]);
8627 mask_len = DIV_ROUND_UP(pat_len, 8);
8628 if (nla_len(pat_tb[NL80211_PKTPAT_MASK]) != mask_len)
8629 return -EINVAL;
8630 if (pat_len > coalesce->pattern_max_len ||
8631 pat_len < coalesce->pattern_min_len)
8632 return -EINVAL;
8633
8634 if (!pat_tb[NL80211_PKTPAT_OFFSET])
8635 pkt_offset = 0;
8636 else
8637 pkt_offset = nla_get_u32(pat_tb[NL80211_PKTPAT_OFFSET]);
8638 if (pkt_offset > coalesce->max_pkt_offset)
8639 return -EINVAL;
8640 new_rule->patterns[i].pkt_offset = pkt_offset;
8641
8642 new_rule->patterns[i].mask =
8643 kmalloc(mask_len + pat_len, GFP_KERNEL);
8644 if (!new_rule->patterns[i].mask)
8645 return -ENOMEM;
8646 new_rule->patterns[i].pattern =
8647 new_rule->patterns[i].mask + mask_len;
8648 memcpy(new_rule->patterns[i].mask,
8649 nla_data(pat_tb[NL80211_PKTPAT_MASK]), mask_len);
8650 new_rule->patterns[i].pattern_len = pat_len;
8651 memcpy(new_rule->patterns[i].pattern,
8652 nla_data(pat_tb[NL80211_PKTPAT_PATTERN]), pat_len);
8653 i++;
8654 }
8655
8656 return 0;
8657}
8658
8659static int nl80211_set_coalesce(struct sk_buff *skb, struct genl_info *info)
8660{
8661 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8662 const struct wiphy_coalesce_support *coalesce = rdev->wiphy.coalesce;
8663 struct cfg80211_coalesce new_coalesce = {};
8664 struct cfg80211_coalesce *n_coalesce;
8665 int err, rem_rule, n_rules = 0, i, j;
8666 struct nlattr *rule;
8667 struct cfg80211_coalesce_rules *tmp_rule;
8668
8669 if (!rdev->wiphy.coalesce || !rdev->ops->set_coalesce)
8670 return -EOPNOTSUPP;
8671
8672 if (!info->attrs[NL80211_ATTR_COALESCE_RULE]) {
8673 cfg80211_rdev_free_coalesce(rdev);
8674 rdev->ops->set_coalesce(&rdev->wiphy, NULL);
8675 return 0;
8676 }
8677
8678 nla_for_each_nested(rule, info->attrs[NL80211_ATTR_COALESCE_RULE],
8679 rem_rule)
8680 n_rules++;
8681 if (n_rules > coalesce->n_rules)
8682 return -EINVAL;
8683
8684 new_coalesce.rules = kcalloc(n_rules, sizeof(new_coalesce.rules[0]),
8685 GFP_KERNEL);
8686 if (!new_coalesce.rules)
8687 return -ENOMEM;
8688
8689 new_coalesce.n_rules = n_rules;
8690 i = 0;
8691
8692 nla_for_each_nested(rule, info->attrs[NL80211_ATTR_COALESCE_RULE],
8693 rem_rule) {
8694 err = nl80211_parse_coalesce_rule(rdev, rule,
8695 &new_coalesce.rules[i]);
8696 if (err)
8697 goto error;
8698
8699 i++;
8700 }
8701
8702 err = rdev->ops->set_coalesce(&rdev->wiphy, &new_coalesce);
8703 if (err)
8704 goto error;
8705
8706 n_coalesce = kmemdup(&new_coalesce, sizeof(new_coalesce), GFP_KERNEL);
8707 if (!n_coalesce) {
8708 err = -ENOMEM;
8709 goto error;
8710 }
8711 cfg80211_rdev_free_coalesce(rdev);
8712 rdev->coalesce = n_coalesce;
8713
8714 return 0;
8715error:
8716 for (i = 0; i < new_coalesce.n_rules; i++) {
8717 tmp_rule = &new_coalesce.rules[i];
8718 for (j = 0; j < tmp_rule->n_patterns; j++)
8719 kfree(tmp_rule->patterns[j].mask);
8720 kfree(tmp_rule->patterns);
8721 }
8722 kfree(new_coalesce.rules);
8723
8724 return err;
8725}
8726
Johannes Berge5497d72011-07-05 16:35:40 +02008727static int nl80211_set_rekey_data(struct sk_buff *skb, struct genl_info *info)
8728{
8729 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8730 struct net_device *dev = info->user_ptr[1];
8731 struct wireless_dev *wdev = dev->ieee80211_ptr;
8732 struct nlattr *tb[NUM_NL80211_REKEY_DATA];
8733 struct cfg80211_gtk_rekey_data rekey_data;
8734 int err;
8735
8736 if (!info->attrs[NL80211_ATTR_REKEY_DATA])
8737 return -EINVAL;
8738
8739 err = nla_parse(tb, MAX_NL80211_REKEY_DATA,
8740 nla_data(info->attrs[NL80211_ATTR_REKEY_DATA]),
8741 nla_len(info->attrs[NL80211_ATTR_REKEY_DATA]),
8742 nl80211_rekey_policy);
8743 if (err)
8744 return err;
8745
8746 if (nla_len(tb[NL80211_REKEY_DATA_REPLAY_CTR]) != NL80211_REPLAY_CTR_LEN)
8747 return -ERANGE;
8748 if (nla_len(tb[NL80211_REKEY_DATA_KEK]) != NL80211_KEK_LEN)
8749 return -ERANGE;
8750 if (nla_len(tb[NL80211_REKEY_DATA_KCK]) != NL80211_KCK_LEN)
8751 return -ERANGE;
8752
8753 memcpy(rekey_data.kek, nla_data(tb[NL80211_REKEY_DATA_KEK]),
8754 NL80211_KEK_LEN);
8755 memcpy(rekey_data.kck, nla_data(tb[NL80211_REKEY_DATA_KCK]),
8756 NL80211_KCK_LEN);
8757 memcpy(rekey_data.replay_ctr,
8758 nla_data(tb[NL80211_REKEY_DATA_REPLAY_CTR]),
8759 NL80211_REPLAY_CTR_LEN);
8760
8761 wdev_lock(wdev);
8762 if (!wdev->current_bss) {
8763 err = -ENOTCONN;
8764 goto out;
8765 }
8766
8767 if (!rdev->ops->set_rekey_data) {
8768 err = -EOPNOTSUPP;
8769 goto out;
8770 }
8771
Hila Gonene35e4d22012-06-27 17:19:42 +03008772 err = rdev_set_rekey_data(rdev, dev, &rekey_data);
Johannes Berge5497d72011-07-05 16:35:40 +02008773 out:
8774 wdev_unlock(wdev);
8775 return err;
8776}
8777
Johannes Berg28946da2011-11-04 11:18:12 +01008778static int nl80211_register_unexpected_frame(struct sk_buff *skb,
8779 struct genl_info *info)
8780{
8781 struct net_device *dev = info->user_ptr[1];
8782 struct wireless_dev *wdev = dev->ieee80211_ptr;
8783
8784 if (wdev->iftype != NL80211_IFTYPE_AP &&
8785 wdev->iftype != NL80211_IFTYPE_P2P_GO)
8786 return -EINVAL;
8787
Eric W. Biederman15e47302012-09-07 20:12:54 +00008788 if (wdev->ap_unexpected_nlportid)
Johannes Berg28946da2011-11-04 11:18:12 +01008789 return -EBUSY;
8790
Eric W. Biederman15e47302012-09-07 20:12:54 +00008791 wdev->ap_unexpected_nlportid = info->snd_portid;
Johannes Berg28946da2011-11-04 11:18:12 +01008792 return 0;
8793}
8794
Johannes Berg7f6cf312011-11-04 11:18:15 +01008795static int nl80211_probe_client(struct sk_buff *skb,
8796 struct genl_info *info)
8797{
8798 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8799 struct net_device *dev = info->user_ptr[1];
8800 struct wireless_dev *wdev = dev->ieee80211_ptr;
8801 struct sk_buff *msg;
8802 void *hdr;
8803 const u8 *addr;
8804 u64 cookie;
8805 int err;
8806
8807 if (wdev->iftype != NL80211_IFTYPE_AP &&
8808 wdev->iftype != NL80211_IFTYPE_P2P_GO)
8809 return -EOPNOTSUPP;
8810
8811 if (!info->attrs[NL80211_ATTR_MAC])
8812 return -EINVAL;
8813
8814 if (!rdev->ops->probe_client)
8815 return -EOPNOTSUPP;
8816
8817 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
8818 if (!msg)
8819 return -ENOMEM;
8820
Eric W. Biederman15e47302012-09-07 20:12:54 +00008821 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berg7f6cf312011-11-04 11:18:15 +01008822 NL80211_CMD_PROBE_CLIENT);
Dan Carpentercb35fba2013-08-14 14:50:01 +03008823 if (!hdr) {
8824 err = -ENOBUFS;
Johannes Berg7f6cf312011-11-04 11:18:15 +01008825 goto free_msg;
8826 }
8827
8828 addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
8829
Hila Gonene35e4d22012-06-27 17:19:42 +03008830 err = rdev_probe_client(rdev, dev, addr, &cookie);
Johannes Berg7f6cf312011-11-04 11:18:15 +01008831 if (err)
8832 goto free_msg;
8833
David S. Miller9360ffd2012-03-29 04:41:26 -04008834 if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie))
8835 goto nla_put_failure;
Johannes Berg7f6cf312011-11-04 11:18:15 +01008836
8837 genlmsg_end(msg, hdr);
8838
8839 return genlmsg_reply(msg, info);
8840
8841 nla_put_failure:
8842 err = -ENOBUFS;
8843 free_msg:
8844 nlmsg_free(msg);
8845 return err;
8846}
8847
Johannes Berg5e760232011-11-04 11:18:17 +01008848static int nl80211_register_beacons(struct sk_buff *skb, struct genl_info *info)
8849{
8850 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Ben Greear37c73b52012-10-26 14:49:25 -07008851 struct cfg80211_beacon_registration *reg, *nreg;
8852 int rv;
Johannes Berg5e760232011-11-04 11:18:17 +01008853
8854 if (!(rdev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS))
8855 return -EOPNOTSUPP;
8856
Ben Greear37c73b52012-10-26 14:49:25 -07008857 nreg = kzalloc(sizeof(*nreg), GFP_KERNEL);
8858 if (!nreg)
8859 return -ENOMEM;
Johannes Berg5e760232011-11-04 11:18:17 +01008860
Ben Greear37c73b52012-10-26 14:49:25 -07008861 /* First, check if already registered. */
8862 spin_lock_bh(&rdev->beacon_registrations_lock);
8863 list_for_each_entry(reg, &rdev->beacon_registrations, list) {
8864 if (reg->nlportid == info->snd_portid) {
8865 rv = -EALREADY;
8866 goto out_err;
8867 }
8868 }
8869 /* Add it to the list */
8870 nreg->nlportid = info->snd_portid;
8871 list_add(&nreg->list, &rdev->beacon_registrations);
8872
8873 spin_unlock_bh(&rdev->beacon_registrations_lock);
Johannes Berg5e760232011-11-04 11:18:17 +01008874
8875 return 0;
Ben Greear37c73b52012-10-26 14:49:25 -07008876out_err:
8877 spin_unlock_bh(&rdev->beacon_registrations_lock);
8878 kfree(nreg);
8879 return rv;
Johannes Berg5e760232011-11-04 11:18:17 +01008880}
8881
Johannes Berg98104fde2012-06-16 00:19:54 +02008882static int nl80211_start_p2p_device(struct sk_buff *skb, struct genl_info *info)
8883{
8884 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8885 struct wireless_dev *wdev = info->user_ptr[1];
8886 int err;
8887
8888 if (!rdev->ops->start_p2p_device)
8889 return -EOPNOTSUPP;
8890
8891 if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE)
8892 return -EOPNOTSUPP;
8893
8894 if (wdev->p2p_started)
8895 return 0;
8896
Johannes Berg98104fde2012-06-16 00:19:54 +02008897 err = cfg80211_can_add_interface(rdev, wdev->iftype);
Johannes Berg98104fde2012-06-16 00:19:54 +02008898 if (err)
8899 return err;
8900
Johannes Bergeeb126e2012-10-23 15:16:50 +02008901 err = rdev_start_p2p_device(rdev, wdev);
Johannes Berg98104fde2012-06-16 00:19:54 +02008902 if (err)
8903 return err;
8904
8905 wdev->p2p_started = true;
Johannes Berg98104fde2012-06-16 00:19:54 +02008906 rdev->opencount++;
Johannes Berg98104fde2012-06-16 00:19:54 +02008907
8908 return 0;
8909}
8910
8911static int nl80211_stop_p2p_device(struct sk_buff *skb, struct genl_info *info)
8912{
8913 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8914 struct wireless_dev *wdev = info->user_ptr[1];
8915
8916 if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE)
8917 return -EOPNOTSUPP;
8918
8919 if (!rdev->ops->stop_p2p_device)
8920 return -EOPNOTSUPP;
8921
Johannes Bergf9f47522013-03-19 15:04:07 +01008922 cfg80211_stop_p2p_device(rdev, wdev);
Johannes Berg98104fde2012-06-16 00:19:54 +02008923
8924 return 0;
8925}
8926
Johannes Berg3713b4e2013-02-14 16:19:38 +01008927static int nl80211_get_protocol_features(struct sk_buff *skb,
8928 struct genl_info *info)
8929{
8930 void *hdr;
8931 struct sk_buff *msg;
8932
8933 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
8934 if (!msg)
8935 return -ENOMEM;
8936
8937 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
8938 NL80211_CMD_GET_PROTOCOL_FEATURES);
8939 if (!hdr)
8940 goto nla_put_failure;
8941
8942 if (nla_put_u32(msg, NL80211_ATTR_PROTOCOL_FEATURES,
8943 NL80211_PROTOCOL_FEATURE_SPLIT_WIPHY_DUMP))
8944 goto nla_put_failure;
8945
8946 genlmsg_end(msg, hdr);
8947 return genlmsg_reply(msg, info);
8948
8949 nla_put_failure:
8950 kfree_skb(msg);
8951 return -ENOBUFS;
8952}
8953
Jouni Malinen355199e2013-02-27 17:14:27 +02008954static int nl80211_update_ft_ies(struct sk_buff *skb, struct genl_info *info)
8955{
8956 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8957 struct cfg80211_update_ft_ies_params ft_params;
8958 struct net_device *dev = info->user_ptr[1];
8959
8960 if (!rdev->ops->update_ft_ies)
8961 return -EOPNOTSUPP;
8962
8963 if (!info->attrs[NL80211_ATTR_MDID] ||
8964 !is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
8965 return -EINVAL;
8966
8967 memset(&ft_params, 0, sizeof(ft_params));
8968 ft_params.md = nla_get_u16(info->attrs[NL80211_ATTR_MDID]);
8969 ft_params.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
8970 ft_params.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
8971
8972 return rdev_update_ft_ies(rdev, dev, &ft_params);
8973}
8974
Arend van Spriel5de17982013-04-18 15:49:00 +02008975static int nl80211_crit_protocol_start(struct sk_buff *skb,
8976 struct genl_info *info)
8977{
8978 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8979 struct wireless_dev *wdev = info->user_ptr[1];
8980 enum nl80211_crit_proto_id proto = NL80211_CRIT_PROTO_UNSPEC;
8981 u16 duration;
8982 int ret;
8983
8984 if (!rdev->ops->crit_proto_start)
8985 return -EOPNOTSUPP;
8986
8987 if (WARN_ON(!rdev->ops->crit_proto_stop))
8988 return -EINVAL;
8989
8990 if (rdev->crit_proto_nlportid)
8991 return -EBUSY;
8992
8993 /* determine protocol if provided */
8994 if (info->attrs[NL80211_ATTR_CRIT_PROT_ID])
8995 proto = nla_get_u16(info->attrs[NL80211_ATTR_CRIT_PROT_ID]);
8996
8997 if (proto >= NUM_NL80211_CRIT_PROTO)
8998 return -EINVAL;
8999
9000 /* timeout must be provided */
9001 if (!info->attrs[NL80211_ATTR_MAX_CRIT_PROT_DURATION])
9002 return -EINVAL;
9003
9004 duration =
9005 nla_get_u16(info->attrs[NL80211_ATTR_MAX_CRIT_PROT_DURATION]);
9006
9007 if (duration > NL80211_CRIT_PROTO_MAX_DURATION)
9008 return -ERANGE;
9009
9010 ret = rdev_crit_proto_start(rdev, wdev, proto, duration);
9011 if (!ret)
9012 rdev->crit_proto_nlportid = info->snd_portid;
9013
9014 return ret;
9015}
9016
9017static int nl80211_crit_protocol_stop(struct sk_buff *skb,
9018 struct genl_info *info)
9019{
9020 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9021 struct wireless_dev *wdev = info->user_ptr[1];
9022
9023 if (!rdev->ops->crit_proto_stop)
9024 return -EOPNOTSUPP;
9025
9026 if (rdev->crit_proto_nlportid) {
9027 rdev->crit_proto_nlportid = 0;
9028 rdev_crit_proto_stop(rdev, wdev);
9029 }
9030 return 0;
9031}
9032
Johannes Bergad7e7182013-11-13 13:37:47 +01009033static int nl80211_vendor_cmd(struct sk_buff *skb, struct genl_info *info)
9034{
9035 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9036 struct wireless_dev *wdev =
9037 __cfg80211_wdev_from_attrs(genl_info_net(info), info->attrs);
9038 int i, err;
9039 u32 vid, subcmd;
9040
9041 if (!rdev->wiphy.vendor_commands)
9042 return -EOPNOTSUPP;
9043
9044 if (IS_ERR(wdev)) {
9045 err = PTR_ERR(wdev);
9046 if (err != -EINVAL)
9047 return err;
9048 wdev = NULL;
9049 } else if (wdev->wiphy != &rdev->wiphy) {
9050 return -EINVAL;
9051 }
9052
9053 if (!info->attrs[NL80211_ATTR_VENDOR_ID] ||
9054 !info->attrs[NL80211_ATTR_VENDOR_SUBCMD])
9055 return -EINVAL;
9056
9057 vid = nla_get_u32(info->attrs[NL80211_ATTR_VENDOR_ID]);
9058 subcmd = nla_get_u32(info->attrs[NL80211_ATTR_VENDOR_SUBCMD]);
9059 for (i = 0; i < rdev->wiphy.n_vendor_commands; i++) {
9060 const struct wiphy_vendor_command *vcmd;
9061 void *data = NULL;
9062 int len = 0;
9063
9064 vcmd = &rdev->wiphy.vendor_commands[i];
9065
9066 if (vcmd->info.vendor_id != vid || vcmd->info.subcmd != subcmd)
9067 continue;
9068
9069 if (vcmd->flags & (WIPHY_VENDOR_CMD_NEED_WDEV |
9070 WIPHY_VENDOR_CMD_NEED_NETDEV)) {
9071 if (!wdev)
9072 return -EINVAL;
9073 if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_NETDEV &&
9074 !wdev->netdev)
9075 return -EINVAL;
9076
9077 if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_RUNNING) {
9078 if (wdev->netdev &&
9079 !netif_running(wdev->netdev))
9080 return -ENETDOWN;
9081 if (!wdev->netdev && !wdev->p2p_started)
9082 return -ENETDOWN;
9083 }
9084 } else {
9085 wdev = NULL;
9086 }
9087
9088 if (info->attrs[NL80211_ATTR_VENDOR_DATA]) {
9089 data = nla_data(info->attrs[NL80211_ATTR_VENDOR_DATA]);
9090 len = nla_len(info->attrs[NL80211_ATTR_VENDOR_DATA]);
9091 }
9092
9093 rdev->cur_cmd_info = info;
9094 err = rdev->wiphy.vendor_commands[i].doit(&rdev->wiphy, wdev,
9095 data, len);
9096 rdev->cur_cmd_info = NULL;
9097 return err;
9098 }
9099
9100 return -EOPNOTSUPP;
9101}
9102
9103struct sk_buff *__cfg80211_alloc_reply_skb(struct wiphy *wiphy,
9104 enum nl80211_commands cmd,
9105 enum nl80211_attrs attr,
9106 int approxlen)
9107{
9108 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
9109
9110 if (WARN_ON(!rdev->cur_cmd_info))
9111 return NULL;
9112
9113 return __cfg80211_alloc_vendor_skb(rdev, approxlen,
9114 rdev->cur_cmd_info->snd_portid,
9115 rdev->cur_cmd_info->snd_seq,
Johannes Berg567ffc32013-12-18 14:43:31 +01009116 cmd, attr, NULL, GFP_KERNEL);
Johannes Bergad7e7182013-11-13 13:37:47 +01009117}
9118EXPORT_SYMBOL(__cfg80211_alloc_reply_skb);
9119
9120int cfg80211_vendor_cmd_reply(struct sk_buff *skb)
9121{
9122 struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0];
9123 void *hdr = ((void **)skb->cb)[1];
9124 struct nlattr *data = ((void **)skb->cb)[2];
9125
9126 if (WARN_ON(!rdev->cur_cmd_info)) {
9127 kfree_skb(skb);
9128 return -EINVAL;
9129 }
9130
9131 nla_nest_end(skb, data);
9132 genlmsg_end(skb, hdr);
9133 return genlmsg_reply(skb, rdev->cur_cmd_info);
9134}
9135EXPORT_SYMBOL_GPL(cfg80211_vendor_cmd_reply);
9136
9137
Kyeyoon Parkfa9ffc72013-12-16 23:01:30 -08009138static int nl80211_set_qos_map(struct sk_buff *skb,
9139 struct genl_info *info)
9140{
9141 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9142 struct cfg80211_qos_map *qos_map = NULL;
9143 struct net_device *dev = info->user_ptr[1];
9144 u8 *pos, len, num_des, des_len, des;
9145 int ret;
9146
9147 if (!rdev->ops->set_qos_map)
9148 return -EOPNOTSUPP;
9149
9150 if (info->attrs[NL80211_ATTR_QOS_MAP]) {
9151 pos = nla_data(info->attrs[NL80211_ATTR_QOS_MAP]);
9152 len = nla_len(info->attrs[NL80211_ATTR_QOS_MAP]);
9153
9154 if (len % 2 || len < IEEE80211_QOS_MAP_LEN_MIN ||
9155 len > IEEE80211_QOS_MAP_LEN_MAX)
9156 return -EINVAL;
9157
9158 qos_map = kzalloc(sizeof(struct cfg80211_qos_map), GFP_KERNEL);
9159 if (!qos_map)
9160 return -ENOMEM;
9161
9162 num_des = (len - IEEE80211_QOS_MAP_LEN_MIN) >> 1;
9163 if (num_des) {
9164 des_len = num_des *
9165 sizeof(struct cfg80211_dscp_exception);
9166 memcpy(qos_map->dscp_exception, pos, des_len);
9167 qos_map->num_des = num_des;
9168 for (des = 0; des < num_des; des++) {
9169 if (qos_map->dscp_exception[des].up > 7) {
9170 kfree(qos_map);
9171 return -EINVAL;
9172 }
9173 }
9174 pos += des_len;
9175 }
9176 memcpy(qos_map->up, pos, IEEE80211_QOS_MAP_LEN_MIN);
9177 }
9178
9179 wdev_lock(dev->ieee80211_ptr);
9180 ret = nl80211_key_allowed(dev->ieee80211_ptr);
9181 if (!ret)
9182 ret = rdev_set_qos_map(rdev, dev, qos_map);
9183 wdev_unlock(dev->ieee80211_ptr);
9184
9185 kfree(qos_map);
9186 return ret;
9187}
9188
Johannes Berg4c476992010-10-04 21:36:35 +02009189#define NL80211_FLAG_NEED_WIPHY 0x01
9190#define NL80211_FLAG_NEED_NETDEV 0x02
9191#define NL80211_FLAG_NEED_RTNL 0x04
Johannes Berg41265712010-10-04 21:14:05 +02009192#define NL80211_FLAG_CHECK_NETDEV_UP 0x08
9193#define NL80211_FLAG_NEED_NETDEV_UP (NL80211_FLAG_NEED_NETDEV |\
9194 NL80211_FLAG_CHECK_NETDEV_UP)
Johannes Berg1bf614e2012-06-15 15:23:36 +02009195#define NL80211_FLAG_NEED_WDEV 0x10
Johannes Berg98104fde2012-06-16 00:19:54 +02009196/* If a netdev is associated, it must be UP, P2P must be started */
Johannes Berg1bf614e2012-06-15 15:23:36 +02009197#define NL80211_FLAG_NEED_WDEV_UP (NL80211_FLAG_NEED_WDEV |\
9198 NL80211_FLAG_CHECK_NETDEV_UP)
Johannes Berg4c476992010-10-04 21:36:35 +02009199
Johannes Bergf84f7712013-11-14 17:14:45 +01009200static int nl80211_pre_doit(const struct genl_ops *ops, struct sk_buff *skb,
Johannes Berg4c476992010-10-04 21:36:35 +02009201 struct genl_info *info)
9202{
9203 struct cfg80211_registered_device *rdev;
Johannes Berg89a54e42012-06-15 14:33:17 +02009204 struct wireless_dev *wdev;
Johannes Berg4c476992010-10-04 21:36:35 +02009205 struct net_device *dev;
Johannes Berg4c476992010-10-04 21:36:35 +02009206 bool rtnl = ops->internal_flags & NL80211_FLAG_NEED_RTNL;
9207
9208 if (rtnl)
9209 rtnl_lock();
9210
9211 if (ops->internal_flags & NL80211_FLAG_NEED_WIPHY) {
Johannes Berg4f7eff12012-06-15 14:14:22 +02009212 rdev = cfg80211_get_dev_from_info(genl_info_net(info), info);
Johannes Berg4c476992010-10-04 21:36:35 +02009213 if (IS_ERR(rdev)) {
9214 if (rtnl)
9215 rtnl_unlock();
9216 return PTR_ERR(rdev);
9217 }
9218 info->user_ptr[0] = rdev;
Johannes Berg1bf614e2012-06-15 15:23:36 +02009219 } else if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV ||
9220 ops->internal_flags & NL80211_FLAG_NEED_WDEV) {
Johannes Berg5fe231e2013-05-08 21:45:15 +02009221 ASSERT_RTNL();
9222
Johannes Berg89a54e42012-06-15 14:33:17 +02009223 wdev = __cfg80211_wdev_from_attrs(genl_info_net(info),
9224 info->attrs);
9225 if (IS_ERR(wdev)) {
Johannes Berg4c476992010-10-04 21:36:35 +02009226 if (rtnl)
9227 rtnl_unlock();
Johannes Berg89a54e42012-06-15 14:33:17 +02009228 return PTR_ERR(wdev);
Johannes Berg4c476992010-10-04 21:36:35 +02009229 }
Johannes Berg89a54e42012-06-15 14:33:17 +02009230
Johannes Berg89a54e42012-06-15 14:33:17 +02009231 dev = wdev->netdev;
9232 rdev = wiphy_to_dev(wdev->wiphy);
9233
Johannes Berg1bf614e2012-06-15 15:23:36 +02009234 if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV) {
9235 if (!dev) {
Johannes Berg1bf614e2012-06-15 15:23:36 +02009236 if (rtnl)
9237 rtnl_unlock();
9238 return -EINVAL;
9239 }
9240
9241 info->user_ptr[1] = dev;
9242 } else {
9243 info->user_ptr[1] = wdev;
Johannes Berg41265712010-10-04 21:14:05 +02009244 }
Johannes Berg89a54e42012-06-15 14:33:17 +02009245
Johannes Berg1bf614e2012-06-15 15:23:36 +02009246 if (dev) {
9247 if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP &&
9248 !netif_running(dev)) {
Johannes Berg1bf614e2012-06-15 15:23:36 +02009249 if (rtnl)
9250 rtnl_unlock();
9251 return -ENETDOWN;
9252 }
9253
9254 dev_hold(dev);
Johannes Berg98104fde2012-06-16 00:19:54 +02009255 } else if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP) {
9256 if (!wdev->p2p_started) {
Johannes Berg98104fde2012-06-16 00:19:54 +02009257 if (rtnl)
9258 rtnl_unlock();
9259 return -ENETDOWN;
9260 }
Johannes Berg1bf614e2012-06-15 15:23:36 +02009261 }
9262
Johannes Berg4c476992010-10-04 21:36:35 +02009263 info->user_ptr[0] = rdev;
Johannes Berg4c476992010-10-04 21:36:35 +02009264 }
9265
9266 return 0;
9267}
9268
Johannes Bergf84f7712013-11-14 17:14:45 +01009269static void nl80211_post_doit(const struct genl_ops *ops, struct sk_buff *skb,
Johannes Berg4c476992010-10-04 21:36:35 +02009270 struct genl_info *info)
9271{
Johannes Berg1bf614e2012-06-15 15:23:36 +02009272 if (info->user_ptr[1]) {
9273 if (ops->internal_flags & NL80211_FLAG_NEED_WDEV) {
9274 struct wireless_dev *wdev = info->user_ptr[1];
9275
9276 if (wdev->netdev)
9277 dev_put(wdev->netdev);
9278 } else {
9279 dev_put(info->user_ptr[1]);
9280 }
9281 }
Johannes Berg4c476992010-10-04 21:36:35 +02009282 if (ops->internal_flags & NL80211_FLAG_NEED_RTNL)
9283 rtnl_unlock();
9284}
9285
Johannes Berg4534de82013-11-14 17:14:46 +01009286static const struct genl_ops nl80211_ops[] = {
Johannes Berg55682962007-09-20 13:09:35 -04009287 {
9288 .cmd = NL80211_CMD_GET_WIPHY,
9289 .doit = nl80211_get_wiphy,
9290 .dumpit = nl80211_dump_wiphy,
Johannes Berg86e8cf92013-06-19 10:57:22 +02009291 .done = nl80211_dump_wiphy_done,
Johannes Berg55682962007-09-20 13:09:35 -04009292 .policy = nl80211_policy,
9293 /* can be retrieved by unprivileged users */
Johannes Berg5fe231e2013-05-08 21:45:15 +02009294 .internal_flags = NL80211_FLAG_NEED_WIPHY |
9295 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -04009296 },
9297 {
9298 .cmd = NL80211_CMD_SET_WIPHY,
9299 .doit = nl80211_set_wiphy,
9300 .policy = nl80211_policy,
9301 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02009302 .internal_flags = NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -04009303 },
9304 {
9305 .cmd = NL80211_CMD_GET_INTERFACE,
9306 .doit = nl80211_get_interface,
9307 .dumpit = nl80211_dump_interface,
9308 .policy = nl80211_policy,
9309 /* can be retrieved by unprivileged users */
Johannes Berg5fe231e2013-05-08 21:45:15 +02009310 .internal_flags = NL80211_FLAG_NEED_WDEV |
9311 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -04009312 },
9313 {
9314 .cmd = NL80211_CMD_SET_INTERFACE,
9315 .doit = nl80211_set_interface,
9316 .policy = nl80211_policy,
9317 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02009318 .internal_flags = NL80211_FLAG_NEED_NETDEV |
9319 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -04009320 },
9321 {
9322 .cmd = NL80211_CMD_NEW_INTERFACE,
9323 .doit = nl80211_new_interface,
9324 .policy = nl80211_policy,
9325 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02009326 .internal_flags = NL80211_FLAG_NEED_WIPHY |
9327 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -04009328 },
9329 {
9330 .cmd = NL80211_CMD_DEL_INTERFACE,
9331 .doit = nl80211_del_interface,
9332 .policy = nl80211_policy,
9333 .flags = GENL_ADMIN_PERM,
Johannes Berg84efbb82012-06-16 00:00:26 +02009334 .internal_flags = NL80211_FLAG_NEED_WDEV |
Johannes Berg4c476992010-10-04 21:36:35 +02009335 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -04009336 },
Johannes Berg41ade002007-12-19 02:03:29 +01009337 {
9338 .cmd = NL80211_CMD_GET_KEY,
9339 .doit = nl80211_get_key,
9340 .policy = nl80211_policy,
9341 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02009342 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009343 NL80211_FLAG_NEED_RTNL,
Johannes Berg41ade002007-12-19 02:03:29 +01009344 },
9345 {
9346 .cmd = NL80211_CMD_SET_KEY,
9347 .doit = nl80211_set_key,
9348 .policy = nl80211_policy,
9349 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02009350 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009351 NL80211_FLAG_NEED_RTNL,
Johannes Berg41ade002007-12-19 02:03:29 +01009352 },
9353 {
9354 .cmd = NL80211_CMD_NEW_KEY,
9355 .doit = nl80211_new_key,
9356 .policy = nl80211_policy,
9357 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02009358 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009359 NL80211_FLAG_NEED_RTNL,
Johannes Berg41ade002007-12-19 02:03:29 +01009360 },
9361 {
9362 .cmd = NL80211_CMD_DEL_KEY,
9363 .doit = nl80211_del_key,
9364 .policy = nl80211_policy,
9365 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02009366 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009367 NL80211_FLAG_NEED_RTNL,
Johannes Berg41ade002007-12-19 02:03:29 +01009368 },
Johannes Berged1b6cc2007-12-19 02:03:32 +01009369 {
9370 .cmd = NL80211_CMD_SET_BEACON,
9371 .policy = nl80211_policy,
9372 .flags = GENL_ADMIN_PERM,
Johannes Berg88600202012-02-13 15:17:18 +01009373 .doit = nl80211_set_beacon,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02009374 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009375 NL80211_FLAG_NEED_RTNL,
Johannes Berged1b6cc2007-12-19 02:03:32 +01009376 },
9377 {
Johannes Berg88600202012-02-13 15:17:18 +01009378 .cmd = NL80211_CMD_START_AP,
Johannes Berged1b6cc2007-12-19 02:03:32 +01009379 .policy = nl80211_policy,
9380 .flags = GENL_ADMIN_PERM,
Johannes Berg88600202012-02-13 15:17:18 +01009381 .doit = nl80211_start_ap,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02009382 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009383 NL80211_FLAG_NEED_RTNL,
Johannes Berged1b6cc2007-12-19 02:03:32 +01009384 },
9385 {
Johannes Berg88600202012-02-13 15:17:18 +01009386 .cmd = NL80211_CMD_STOP_AP,
Johannes Berged1b6cc2007-12-19 02:03:32 +01009387 .policy = nl80211_policy,
9388 .flags = GENL_ADMIN_PERM,
Johannes Berg88600202012-02-13 15:17:18 +01009389 .doit = nl80211_stop_ap,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02009390 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009391 NL80211_FLAG_NEED_RTNL,
Johannes Berged1b6cc2007-12-19 02:03:32 +01009392 },
Johannes Berg5727ef12007-12-19 02:03:34 +01009393 {
9394 .cmd = NL80211_CMD_GET_STATION,
9395 .doit = nl80211_get_station,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01009396 .dumpit = nl80211_dump_station,
Johannes Berg5727ef12007-12-19 02:03:34 +01009397 .policy = nl80211_policy,
Johannes Berg4c476992010-10-04 21:36:35 +02009398 .internal_flags = NL80211_FLAG_NEED_NETDEV |
9399 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +01009400 },
9401 {
9402 .cmd = NL80211_CMD_SET_STATION,
9403 .doit = nl80211_set_station,
9404 .policy = nl80211_policy,
9405 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02009406 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009407 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +01009408 },
9409 {
9410 .cmd = NL80211_CMD_NEW_STATION,
9411 .doit = nl80211_new_station,
9412 .policy = nl80211_policy,
9413 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02009414 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009415 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +01009416 },
9417 {
9418 .cmd = NL80211_CMD_DEL_STATION,
9419 .doit = nl80211_del_station,
9420 .policy = nl80211_policy,
9421 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02009422 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009423 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +01009424 },
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01009425 {
9426 .cmd = NL80211_CMD_GET_MPATH,
9427 .doit = nl80211_get_mpath,
9428 .dumpit = nl80211_dump_mpath,
9429 .policy = nl80211_policy,
9430 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02009431 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009432 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01009433 },
9434 {
9435 .cmd = NL80211_CMD_SET_MPATH,
9436 .doit = nl80211_set_mpath,
9437 .policy = nl80211_policy,
9438 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02009439 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009440 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01009441 },
9442 {
9443 .cmd = NL80211_CMD_NEW_MPATH,
9444 .doit = nl80211_new_mpath,
9445 .policy = nl80211_policy,
9446 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02009447 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009448 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01009449 },
9450 {
9451 .cmd = NL80211_CMD_DEL_MPATH,
9452 .doit = nl80211_del_mpath,
9453 .policy = nl80211_policy,
9454 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02009455 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009456 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01009457 },
Jouni Malinen9f1ba902008-08-07 20:07:01 +03009458 {
9459 .cmd = NL80211_CMD_SET_BSS,
9460 .doit = nl80211_set_bss,
9461 .policy = nl80211_policy,
9462 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02009463 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009464 NL80211_FLAG_NEED_RTNL,
Jouni Malinen9f1ba902008-08-07 20:07:01 +03009465 },
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07009466 {
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08009467 .cmd = NL80211_CMD_GET_REG,
9468 .doit = nl80211_get_reg,
9469 .policy = nl80211_policy,
Johannes Berg5fe231e2013-05-08 21:45:15 +02009470 .internal_flags = NL80211_FLAG_NEED_RTNL,
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08009471 /* can be retrieved by unprivileged users */
9472 },
9473 {
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07009474 .cmd = NL80211_CMD_SET_REG,
9475 .doit = nl80211_set_reg,
9476 .policy = nl80211_policy,
9477 .flags = GENL_ADMIN_PERM,
Johannes Berg5fe231e2013-05-08 21:45:15 +02009478 .internal_flags = NL80211_FLAG_NEED_RTNL,
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07009479 },
9480 {
9481 .cmd = NL80211_CMD_REQ_SET_REG,
9482 .doit = nl80211_req_set_reg,
9483 .policy = nl80211_policy,
9484 .flags = GENL_ADMIN_PERM,
9485 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07009486 {
Javier Cardona24bdd9f2010-12-16 17:37:48 -08009487 .cmd = NL80211_CMD_GET_MESH_CONFIG,
9488 .doit = nl80211_get_mesh_config,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07009489 .policy = nl80211_policy,
9490 /* can be retrieved by unprivileged users */
Johannes Berg2b5f8b02012-04-02 10:51:55 +02009491 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009492 NL80211_FLAG_NEED_RTNL,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07009493 },
9494 {
Javier Cardona24bdd9f2010-12-16 17:37:48 -08009495 .cmd = NL80211_CMD_SET_MESH_CONFIG,
9496 .doit = nl80211_update_mesh_config,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07009497 .policy = nl80211_policy,
9498 .flags = GENL_ADMIN_PERM,
Johannes Berg29cbe682010-12-03 09:20:44 +01009499 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009500 NL80211_FLAG_NEED_RTNL,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07009501 },
Jouni Malinen9aed3cc2009-01-13 16:03:29 +02009502 {
Johannes Berg2a519312009-02-10 21:25:55 +01009503 .cmd = NL80211_CMD_TRIGGER_SCAN,
9504 .doit = nl80211_trigger_scan,
9505 .policy = nl80211_policy,
9506 .flags = GENL_ADMIN_PERM,
Johannes Bergfd014282012-06-18 19:17:03 +02009507 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009508 NL80211_FLAG_NEED_RTNL,
Johannes Berg2a519312009-02-10 21:25:55 +01009509 },
9510 {
9511 .cmd = NL80211_CMD_GET_SCAN,
9512 .policy = nl80211_policy,
9513 .dumpit = nl80211_dump_scan,
9514 },
Jouni Malinen636a5d32009-03-19 13:39:22 +02009515 {
Luciano Coelho807f8a82011-05-11 17:09:35 +03009516 .cmd = NL80211_CMD_START_SCHED_SCAN,
9517 .doit = nl80211_start_sched_scan,
9518 .policy = nl80211_policy,
9519 .flags = GENL_ADMIN_PERM,
9520 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
9521 NL80211_FLAG_NEED_RTNL,
9522 },
9523 {
9524 .cmd = NL80211_CMD_STOP_SCHED_SCAN,
9525 .doit = nl80211_stop_sched_scan,
9526 .policy = nl80211_policy,
9527 .flags = GENL_ADMIN_PERM,
9528 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
9529 NL80211_FLAG_NEED_RTNL,
9530 },
9531 {
Jouni Malinen636a5d32009-03-19 13:39:22 +02009532 .cmd = NL80211_CMD_AUTHENTICATE,
9533 .doit = nl80211_authenticate,
9534 .policy = nl80211_policy,
9535 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02009536 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009537 NL80211_FLAG_NEED_RTNL,
Jouni Malinen636a5d32009-03-19 13:39:22 +02009538 },
9539 {
9540 .cmd = NL80211_CMD_ASSOCIATE,
9541 .doit = nl80211_associate,
9542 .policy = nl80211_policy,
9543 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02009544 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009545 NL80211_FLAG_NEED_RTNL,
Jouni Malinen636a5d32009-03-19 13:39:22 +02009546 },
9547 {
9548 .cmd = NL80211_CMD_DEAUTHENTICATE,
9549 .doit = nl80211_deauthenticate,
9550 .policy = nl80211_policy,
9551 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02009552 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009553 NL80211_FLAG_NEED_RTNL,
Jouni Malinen636a5d32009-03-19 13:39:22 +02009554 },
9555 {
9556 .cmd = NL80211_CMD_DISASSOCIATE,
9557 .doit = nl80211_disassociate,
9558 .policy = nl80211_policy,
9559 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02009560 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009561 NL80211_FLAG_NEED_RTNL,
Jouni Malinen636a5d32009-03-19 13:39:22 +02009562 },
Johannes Berg04a773a2009-04-19 21:24:32 +02009563 {
9564 .cmd = NL80211_CMD_JOIN_IBSS,
9565 .doit = nl80211_join_ibss,
9566 .policy = nl80211_policy,
9567 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02009568 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009569 NL80211_FLAG_NEED_RTNL,
Johannes Berg04a773a2009-04-19 21:24:32 +02009570 },
9571 {
9572 .cmd = NL80211_CMD_LEAVE_IBSS,
9573 .doit = nl80211_leave_ibss,
9574 .policy = nl80211_policy,
9575 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02009576 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009577 NL80211_FLAG_NEED_RTNL,
Johannes Berg04a773a2009-04-19 21:24:32 +02009578 },
Johannes Bergaff89a92009-07-01 21:26:51 +02009579#ifdef CONFIG_NL80211_TESTMODE
9580 {
9581 .cmd = NL80211_CMD_TESTMODE,
9582 .doit = nl80211_testmode_do,
Wey-Yi Guy71063f02011-05-20 09:05:54 -07009583 .dumpit = nl80211_testmode_dump,
Johannes Bergaff89a92009-07-01 21:26:51 +02009584 .policy = nl80211_policy,
9585 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02009586 .internal_flags = NL80211_FLAG_NEED_WIPHY |
9587 NL80211_FLAG_NEED_RTNL,
Johannes Bergaff89a92009-07-01 21:26:51 +02009588 },
9589#endif
Samuel Ortizb23aa672009-07-01 21:26:54 +02009590 {
9591 .cmd = NL80211_CMD_CONNECT,
9592 .doit = nl80211_connect,
9593 .policy = nl80211_policy,
9594 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02009595 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009596 NL80211_FLAG_NEED_RTNL,
Samuel Ortizb23aa672009-07-01 21:26:54 +02009597 },
9598 {
9599 .cmd = NL80211_CMD_DISCONNECT,
9600 .doit = nl80211_disconnect,
9601 .policy = nl80211_policy,
9602 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02009603 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009604 NL80211_FLAG_NEED_RTNL,
Samuel Ortizb23aa672009-07-01 21:26:54 +02009605 },
Johannes Berg463d0182009-07-14 00:33:35 +02009606 {
9607 .cmd = NL80211_CMD_SET_WIPHY_NETNS,
9608 .doit = nl80211_wiphy_netns,
9609 .policy = nl80211_policy,
9610 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02009611 .internal_flags = NL80211_FLAG_NEED_WIPHY |
9612 NL80211_FLAG_NEED_RTNL,
Johannes Berg463d0182009-07-14 00:33:35 +02009613 },
Holger Schurig61fa7132009-11-11 12:25:40 +01009614 {
9615 .cmd = NL80211_CMD_GET_SURVEY,
9616 .policy = nl80211_policy,
9617 .dumpit = nl80211_dump_survey,
9618 },
Samuel Ortiz67fbb162009-11-24 23:59:15 +01009619 {
9620 .cmd = NL80211_CMD_SET_PMKSA,
9621 .doit = nl80211_setdel_pmksa,
9622 .policy = nl80211_policy,
9623 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02009624 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009625 NL80211_FLAG_NEED_RTNL,
Samuel Ortiz67fbb162009-11-24 23:59:15 +01009626 },
9627 {
9628 .cmd = NL80211_CMD_DEL_PMKSA,
9629 .doit = nl80211_setdel_pmksa,
9630 .policy = nl80211_policy,
9631 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02009632 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009633 NL80211_FLAG_NEED_RTNL,
Samuel Ortiz67fbb162009-11-24 23:59:15 +01009634 },
9635 {
9636 .cmd = NL80211_CMD_FLUSH_PMKSA,
9637 .doit = nl80211_flush_pmksa,
9638 .policy = nl80211_policy,
9639 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02009640 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009641 NL80211_FLAG_NEED_RTNL,
Samuel Ortiz67fbb162009-11-24 23:59:15 +01009642 },
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009643 {
9644 .cmd = NL80211_CMD_REMAIN_ON_CHANNEL,
9645 .doit = nl80211_remain_on_channel,
9646 .policy = nl80211_policy,
9647 .flags = GENL_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +02009648 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009649 NL80211_FLAG_NEED_RTNL,
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009650 },
9651 {
9652 .cmd = NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL,
9653 .doit = nl80211_cancel_remain_on_channel,
9654 .policy = nl80211_policy,
9655 .flags = GENL_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +02009656 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009657 NL80211_FLAG_NEED_RTNL,
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009658 },
Jouni Malinen13ae75b2009-12-29 12:59:45 +02009659 {
9660 .cmd = NL80211_CMD_SET_TX_BITRATE_MASK,
9661 .doit = nl80211_set_tx_bitrate_mask,
9662 .policy = nl80211_policy,
9663 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02009664 .internal_flags = NL80211_FLAG_NEED_NETDEV |
9665 NL80211_FLAG_NEED_RTNL,
Jouni Malinen13ae75b2009-12-29 12:59:45 +02009666 },
Jouni Malinen026331c2010-02-15 12:53:10 +02009667 {
Johannes Berg2e161f72010-08-12 15:38:38 +02009668 .cmd = NL80211_CMD_REGISTER_FRAME,
9669 .doit = nl80211_register_mgmt,
Jouni Malinen026331c2010-02-15 12:53:10 +02009670 .policy = nl80211_policy,
9671 .flags = GENL_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +02009672 .internal_flags = NL80211_FLAG_NEED_WDEV |
Johannes Berg4c476992010-10-04 21:36:35 +02009673 NL80211_FLAG_NEED_RTNL,
Jouni Malinen026331c2010-02-15 12:53:10 +02009674 },
9675 {
Johannes Berg2e161f72010-08-12 15:38:38 +02009676 .cmd = NL80211_CMD_FRAME,
9677 .doit = nl80211_tx_mgmt,
Jouni Malinen026331c2010-02-15 12:53:10 +02009678 .policy = nl80211_policy,
9679 .flags = GENL_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +02009680 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009681 NL80211_FLAG_NEED_RTNL,
Jouni Malinen026331c2010-02-15 12:53:10 +02009682 },
Kalle Valoffb9eb32010-02-17 17:58:10 +02009683 {
Johannes Bergf7ca38d2010-11-25 10:02:29 +01009684 .cmd = NL80211_CMD_FRAME_WAIT_CANCEL,
9685 .doit = nl80211_tx_mgmt_cancel_wait,
9686 .policy = nl80211_policy,
9687 .flags = GENL_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +02009688 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Bergf7ca38d2010-11-25 10:02:29 +01009689 NL80211_FLAG_NEED_RTNL,
9690 },
9691 {
Kalle Valoffb9eb32010-02-17 17:58:10 +02009692 .cmd = NL80211_CMD_SET_POWER_SAVE,
9693 .doit = nl80211_set_power_save,
9694 .policy = nl80211_policy,
9695 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02009696 .internal_flags = NL80211_FLAG_NEED_NETDEV |
9697 NL80211_FLAG_NEED_RTNL,
Kalle Valoffb9eb32010-02-17 17:58:10 +02009698 },
9699 {
9700 .cmd = NL80211_CMD_GET_POWER_SAVE,
9701 .doit = nl80211_get_power_save,
9702 .policy = nl80211_policy,
9703 /* can be retrieved by unprivileged users */
Johannes Berg4c476992010-10-04 21:36:35 +02009704 .internal_flags = NL80211_FLAG_NEED_NETDEV |
9705 NL80211_FLAG_NEED_RTNL,
Kalle Valoffb9eb32010-02-17 17:58:10 +02009706 },
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02009707 {
9708 .cmd = NL80211_CMD_SET_CQM,
9709 .doit = nl80211_set_cqm,
9710 .policy = nl80211_policy,
9711 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02009712 .internal_flags = NL80211_FLAG_NEED_NETDEV |
9713 NL80211_FLAG_NEED_RTNL,
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02009714 },
Johannes Bergf444de02010-05-05 15:25:02 +02009715 {
9716 .cmd = NL80211_CMD_SET_CHANNEL,
9717 .doit = nl80211_set_channel,
9718 .policy = nl80211_policy,
9719 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02009720 .internal_flags = NL80211_FLAG_NEED_NETDEV |
9721 NL80211_FLAG_NEED_RTNL,
Johannes Bergf444de02010-05-05 15:25:02 +02009722 },
Bill Jordane8347eb2010-10-01 13:54:28 -04009723 {
9724 .cmd = NL80211_CMD_SET_WDS_PEER,
9725 .doit = nl80211_set_wds_peer,
9726 .policy = nl80211_policy,
9727 .flags = GENL_ADMIN_PERM,
Johannes Berg43b19952010-10-07 13:10:30 +02009728 .internal_flags = NL80211_FLAG_NEED_NETDEV |
9729 NL80211_FLAG_NEED_RTNL,
Bill Jordane8347eb2010-10-01 13:54:28 -04009730 },
Johannes Berg29cbe682010-12-03 09:20:44 +01009731 {
9732 .cmd = NL80211_CMD_JOIN_MESH,
9733 .doit = nl80211_join_mesh,
9734 .policy = nl80211_policy,
9735 .flags = GENL_ADMIN_PERM,
9736 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
9737 NL80211_FLAG_NEED_RTNL,
9738 },
9739 {
9740 .cmd = NL80211_CMD_LEAVE_MESH,
9741 .doit = nl80211_leave_mesh,
9742 .policy = nl80211_policy,
9743 .flags = GENL_ADMIN_PERM,
9744 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
9745 NL80211_FLAG_NEED_RTNL,
9746 },
Johannes Bergdfb89c52012-06-27 09:23:48 +02009747#ifdef CONFIG_PM
Johannes Bergff1b6e62011-05-04 15:37:28 +02009748 {
9749 .cmd = NL80211_CMD_GET_WOWLAN,
9750 .doit = nl80211_get_wowlan,
9751 .policy = nl80211_policy,
9752 /* can be retrieved by unprivileged users */
9753 .internal_flags = NL80211_FLAG_NEED_WIPHY |
9754 NL80211_FLAG_NEED_RTNL,
9755 },
9756 {
9757 .cmd = NL80211_CMD_SET_WOWLAN,
9758 .doit = nl80211_set_wowlan,
9759 .policy = nl80211_policy,
9760 .flags = GENL_ADMIN_PERM,
9761 .internal_flags = NL80211_FLAG_NEED_WIPHY |
9762 NL80211_FLAG_NEED_RTNL,
9763 },
Johannes Bergdfb89c52012-06-27 09:23:48 +02009764#endif
Johannes Berge5497d72011-07-05 16:35:40 +02009765 {
9766 .cmd = NL80211_CMD_SET_REKEY_OFFLOAD,
9767 .doit = nl80211_set_rekey_data,
9768 .policy = nl80211_policy,
9769 .flags = GENL_ADMIN_PERM,
9770 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
9771 NL80211_FLAG_NEED_RTNL,
9772 },
Arik Nemtsov109086c2011-09-28 14:12:50 +03009773 {
9774 .cmd = NL80211_CMD_TDLS_MGMT,
9775 .doit = nl80211_tdls_mgmt,
9776 .policy = nl80211_policy,
9777 .flags = GENL_ADMIN_PERM,
9778 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
9779 NL80211_FLAG_NEED_RTNL,
9780 },
9781 {
9782 .cmd = NL80211_CMD_TDLS_OPER,
9783 .doit = nl80211_tdls_oper,
9784 .policy = nl80211_policy,
9785 .flags = GENL_ADMIN_PERM,
9786 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
9787 NL80211_FLAG_NEED_RTNL,
9788 },
Johannes Berg28946da2011-11-04 11:18:12 +01009789 {
9790 .cmd = NL80211_CMD_UNEXPECTED_FRAME,
9791 .doit = nl80211_register_unexpected_frame,
9792 .policy = nl80211_policy,
9793 .flags = GENL_ADMIN_PERM,
9794 .internal_flags = NL80211_FLAG_NEED_NETDEV |
9795 NL80211_FLAG_NEED_RTNL,
9796 },
Johannes Berg7f6cf312011-11-04 11:18:15 +01009797 {
9798 .cmd = NL80211_CMD_PROBE_CLIENT,
9799 .doit = nl80211_probe_client,
9800 .policy = nl80211_policy,
9801 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02009802 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg7f6cf312011-11-04 11:18:15 +01009803 NL80211_FLAG_NEED_RTNL,
9804 },
Johannes Berg5e760232011-11-04 11:18:17 +01009805 {
9806 .cmd = NL80211_CMD_REGISTER_BEACONS,
9807 .doit = nl80211_register_beacons,
9808 .policy = nl80211_policy,
9809 .flags = GENL_ADMIN_PERM,
9810 .internal_flags = NL80211_FLAG_NEED_WIPHY |
9811 NL80211_FLAG_NEED_RTNL,
9812 },
Simon Wunderlich1d9d9212011-11-18 14:20:43 +01009813 {
9814 .cmd = NL80211_CMD_SET_NOACK_MAP,
9815 .doit = nl80211_set_noack_map,
9816 .policy = nl80211_policy,
9817 .flags = GENL_ADMIN_PERM,
9818 .internal_flags = NL80211_FLAG_NEED_NETDEV |
9819 NL80211_FLAG_NEED_RTNL,
9820 },
Johannes Berg98104fde2012-06-16 00:19:54 +02009821 {
9822 .cmd = NL80211_CMD_START_P2P_DEVICE,
9823 .doit = nl80211_start_p2p_device,
9824 .policy = nl80211_policy,
9825 .flags = GENL_ADMIN_PERM,
9826 .internal_flags = NL80211_FLAG_NEED_WDEV |
9827 NL80211_FLAG_NEED_RTNL,
9828 },
9829 {
9830 .cmd = NL80211_CMD_STOP_P2P_DEVICE,
9831 .doit = nl80211_stop_p2p_device,
9832 .policy = nl80211_policy,
9833 .flags = GENL_ADMIN_PERM,
9834 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
9835 NL80211_FLAG_NEED_RTNL,
9836 },
Antonio Quartullif4e583c2012-11-02 13:27:48 +01009837 {
9838 .cmd = NL80211_CMD_SET_MCAST_RATE,
9839 .doit = nl80211_set_mcast_rate,
9840 .policy = nl80211_policy,
9841 .flags = GENL_ADMIN_PERM,
9842 .internal_flags = NL80211_FLAG_NEED_NETDEV |
9843 NL80211_FLAG_NEED_RTNL,
9844 },
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +05309845 {
9846 .cmd = NL80211_CMD_SET_MAC_ACL,
9847 .doit = nl80211_set_mac_acl,
9848 .policy = nl80211_policy,
9849 .flags = GENL_ADMIN_PERM,
9850 .internal_flags = NL80211_FLAG_NEED_NETDEV |
9851 NL80211_FLAG_NEED_RTNL,
9852 },
Simon Wunderlich04f39042013-02-08 18:16:19 +01009853 {
9854 .cmd = NL80211_CMD_RADAR_DETECT,
9855 .doit = nl80211_start_radar_detection,
9856 .policy = nl80211_policy,
9857 .flags = GENL_ADMIN_PERM,
9858 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
9859 NL80211_FLAG_NEED_RTNL,
9860 },
Johannes Berg3713b4e2013-02-14 16:19:38 +01009861 {
9862 .cmd = NL80211_CMD_GET_PROTOCOL_FEATURES,
9863 .doit = nl80211_get_protocol_features,
9864 .policy = nl80211_policy,
9865 },
Jouni Malinen355199e2013-02-27 17:14:27 +02009866 {
9867 .cmd = NL80211_CMD_UPDATE_FT_IES,
9868 .doit = nl80211_update_ft_ies,
9869 .policy = nl80211_policy,
9870 .flags = GENL_ADMIN_PERM,
9871 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
9872 NL80211_FLAG_NEED_RTNL,
9873 },
Arend van Spriel5de17982013-04-18 15:49:00 +02009874 {
9875 .cmd = NL80211_CMD_CRIT_PROTOCOL_START,
9876 .doit = nl80211_crit_protocol_start,
9877 .policy = nl80211_policy,
9878 .flags = GENL_ADMIN_PERM,
9879 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
9880 NL80211_FLAG_NEED_RTNL,
9881 },
9882 {
9883 .cmd = NL80211_CMD_CRIT_PROTOCOL_STOP,
9884 .doit = nl80211_crit_protocol_stop,
9885 .policy = nl80211_policy,
9886 .flags = GENL_ADMIN_PERM,
9887 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
9888 NL80211_FLAG_NEED_RTNL,
Amitkumar Karwarbe29b992013-06-28 11:51:26 -07009889 },
9890 {
9891 .cmd = NL80211_CMD_GET_COALESCE,
9892 .doit = nl80211_get_coalesce,
9893 .policy = nl80211_policy,
9894 .internal_flags = NL80211_FLAG_NEED_WIPHY |
9895 NL80211_FLAG_NEED_RTNL,
9896 },
9897 {
9898 .cmd = NL80211_CMD_SET_COALESCE,
9899 .doit = nl80211_set_coalesce,
9900 .policy = nl80211_policy,
9901 .flags = GENL_ADMIN_PERM,
9902 .internal_flags = NL80211_FLAG_NEED_WIPHY |
9903 NL80211_FLAG_NEED_RTNL,
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02009904 },
9905 {
9906 .cmd = NL80211_CMD_CHANNEL_SWITCH,
9907 .doit = nl80211_channel_switch,
9908 .policy = nl80211_policy,
9909 .flags = GENL_ADMIN_PERM,
9910 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
9911 NL80211_FLAG_NEED_RTNL,
9912 },
Johannes Bergad7e7182013-11-13 13:37:47 +01009913 {
9914 .cmd = NL80211_CMD_VENDOR,
9915 .doit = nl80211_vendor_cmd,
9916 .policy = nl80211_policy,
9917 .flags = GENL_ADMIN_PERM,
9918 .internal_flags = NL80211_FLAG_NEED_WIPHY |
9919 NL80211_FLAG_NEED_RTNL,
9920 },
Kyeyoon Parkfa9ffc72013-12-16 23:01:30 -08009921 {
9922 .cmd = NL80211_CMD_SET_QOS_MAP,
9923 .doit = nl80211_set_qos_map,
9924 .policy = nl80211_policy,
9925 .flags = GENL_ADMIN_PERM,
9926 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
9927 NL80211_FLAG_NEED_RTNL,
9928 },
Johannes Berg55682962007-09-20 13:09:35 -04009929};
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009930
Johannes Berg55682962007-09-20 13:09:35 -04009931/* notification functions */
9932
9933void nl80211_notify_dev_rename(struct cfg80211_registered_device *rdev)
9934{
9935 struct sk_buff *msg;
Johannes Berg86e8cf92013-06-19 10:57:22 +02009936 struct nl80211_dump_wiphy_state state = {};
Johannes Berg55682962007-09-20 13:09:35 -04009937
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07009938 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -04009939 if (!msg)
9940 return;
9941
Johannes Berg86e8cf92013-06-19 10:57:22 +02009942 if (nl80211_send_wiphy(rdev, msg, 0, 0, 0, &state) < 0) {
Johannes Berg55682962007-09-20 13:09:35 -04009943 nlmsg_free(msg);
9944 return;
9945 }
9946
Johannes Berg68eb5502013-11-19 15:19:38 +01009947 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +01009948 NL80211_MCGRP_CONFIG, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -04009949}
9950
Johannes Berg362a4152009-05-24 16:43:15 +02009951static int nl80211_add_scan_req(struct sk_buff *msg,
9952 struct cfg80211_registered_device *rdev)
9953{
9954 struct cfg80211_scan_request *req = rdev->scan_req;
9955 struct nlattr *nest;
9956 int i;
9957
9958 if (WARN_ON(!req))
9959 return 0;
9960
9961 nest = nla_nest_start(msg, NL80211_ATTR_SCAN_SSIDS);
9962 if (!nest)
9963 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04009964 for (i = 0; i < req->n_ssids; i++) {
9965 if (nla_put(msg, i, req->ssids[i].ssid_len, req->ssids[i].ssid))
9966 goto nla_put_failure;
9967 }
Johannes Berg362a4152009-05-24 16:43:15 +02009968 nla_nest_end(msg, nest);
9969
9970 nest = nla_nest_start(msg, NL80211_ATTR_SCAN_FREQUENCIES);
9971 if (!nest)
9972 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04009973 for (i = 0; i < req->n_channels; i++) {
9974 if (nla_put_u32(msg, i, req->channels[i]->center_freq))
9975 goto nla_put_failure;
9976 }
Johannes Berg362a4152009-05-24 16:43:15 +02009977 nla_nest_end(msg, nest);
9978
David S. Miller9360ffd2012-03-29 04:41:26 -04009979 if (req->ie &&
9980 nla_put(msg, NL80211_ATTR_IE, req->ie_len, req->ie))
9981 goto nla_put_failure;
Johannes Berg362a4152009-05-24 16:43:15 +02009982
Johannes Bergae917c92013-10-25 11:05:22 +02009983 if (req->flags &&
9984 nla_put_u32(msg, NL80211_ATTR_SCAN_FLAGS, req->flags))
9985 goto nla_put_failure;
Sam Lefflered4737712012-10-11 21:03:31 -07009986
Johannes Berg362a4152009-05-24 16:43:15 +02009987 return 0;
9988 nla_put_failure:
9989 return -ENOBUFS;
9990}
9991
Johannes Berga538e2d2009-06-16 19:56:42 +02009992static int nl80211_send_scan_msg(struct sk_buff *msg,
9993 struct cfg80211_registered_device *rdev,
Johannes Bergfd014282012-06-18 19:17:03 +02009994 struct wireless_dev *wdev,
Eric W. Biederman15e47302012-09-07 20:12:54 +00009995 u32 portid, u32 seq, int flags,
Johannes Berga538e2d2009-06-16 19:56:42 +02009996 u32 cmd)
Johannes Berg2a519312009-02-10 21:25:55 +01009997{
9998 void *hdr;
9999
Eric W. Biederman15e47302012-09-07 20:12:54 +000010000 hdr = nl80211hdr_put(msg, portid, seq, flags, cmd);
Johannes Berg2a519312009-02-10 21:25:55 +010010001 if (!hdr)
10002 return -1;
10003
David S. Miller9360ffd2012-03-29 04:41:26 -040010004 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Bergfd014282012-06-18 19:17:03 +020010005 (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
10006 wdev->netdev->ifindex)) ||
10007 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)))
David S. Miller9360ffd2012-03-29 04:41:26 -040010008 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +010010009
Johannes Berg362a4152009-05-24 16:43:15 +020010010 /* ignore errors and send incomplete event anyway */
10011 nl80211_add_scan_req(msg, rdev);
Johannes Berg2a519312009-02-10 21:25:55 +010010012
10013 return genlmsg_end(msg, hdr);
10014
10015 nla_put_failure:
10016 genlmsg_cancel(msg, hdr);
10017 return -EMSGSIZE;
10018}
10019
Luciano Coelho807f8a82011-05-11 17:09:35 +030010020static int
10021nl80211_send_sched_scan_msg(struct sk_buff *msg,
10022 struct cfg80211_registered_device *rdev,
10023 struct net_device *netdev,
Eric W. Biederman15e47302012-09-07 20:12:54 +000010024 u32 portid, u32 seq, int flags, u32 cmd)
Luciano Coelho807f8a82011-05-11 17:09:35 +030010025{
10026 void *hdr;
10027
Eric W. Biederman15e47302012-09-07 20:12:54 +000010028 hdr = nl80211hdr_put(msg, portid, seq, flags, cmd);
Luciano Coelho807f8a82011-05-11 17:09:35 +030010029 if (!hdr)
10030 return -1;
10031
David S. Miller9360ffd2012-03-29 04:41:26 -040010032 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
10033 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex))
10034 goto nla_put_failure;
Luciano Coelho807f8a82011-05-11 17:09:35 +030010035
10036 return genlmsg_end(msg, hdr);
10037
10038 nla_put_failure:
10039 genlmsg_cancel(msg, hdr);
10040 return -EMSGSIZE;
10041}
10042
Johannes Berga538e2d2009-06-16 19:56:42 +020010043void nl80211_send_scan_start(struct cfg80211_registered_device *rdev,
Johannes Bergfd014282012-06-18 19:17:03 +020010044 struct wireless_dev *wdev)
Johannes Berga538e2d2009-06-16 19:56:42 +020010045{
10046 struct sk_buff *msg;
10047
Thomas Graf58050fc2012-06-28 03:57:45 +000010048 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berga538e2d2009-06-16 19:56:42 +020010049 if (!msg)
10050 return;
10051
Johannes Bergfd014282012-06-18 19:17:03 +020010052 if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0,
Johannes Berga538e2d2009-06-16 19:56:42 +020010053 NL80211_CMD_TRIGGER_SCAN) < 0) {
10054 nlmsg_free(msg);
10055 return;
10056 }
10057
Johannes Berg68eb5502013-11-19 15:19:38 +010010058 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010010059 NL80211_MCGRP_SCAN, GFP_KERNEL);
Johannes Berga538e2d2009-06-16 19:56:42 +020010060}
10061
Johannes Berg2a519312009-02-10 21:25:55 +010010062void nl80211_send_scan_done(struct cfg80211_registered_device *rdev,
Johannes Bergfd014282012-06-18 19:17:03 +020010063 struct wireless_dev *wdev)
Johannes Berg2a519312009-02-10 21:25:55 +010010064{
10065 struct sk_buff *msg;
10066
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -070010067 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg2a519312009-02-10 21:25:55 +010010068 if (!msg)
10069 return;
10070
Johannes Bergfd014282012-06-18 19:17:03 +020010071 if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0,
Johannes Berga538e2d2009-06-16 19:56:42 +020010072 NL80211_CMD_NEW_SCAN_RESULTS) < 0) {
Johannes Berg2a519312009-02-10 21:25:55 +010010073 nlmsg_free(msg);
10074 return;
10075 }
10076
Johannes Berg68eb5502013-11-19 15:19:38 +010010077 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010010078 NL80211_MCGRP_SCAN, GFP_KERNEL);
Johannes Berg2a519312009-02-10 21:25:55 +010010079}
10080
10081void nl80211_send_scan_aborted(struct cfg80211_registered_device *rdev,
Johannes Bergfd014282012-06-18 19:17:03 +020010082 struct wireless_dev *wdev)
Johannes Berg2a519312009-02-10 21:25:55 +010010083{
10084 struct sk_buff *msg;
10085
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -070010086 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg2a519312009-02-10 21:25:55 +010010087 if (!msg)
10088 return;
10089
Johannes Bergfd014282012-06-18 19:17:03 +020010090 if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0,
Johannes Berga538e2d2009-06-16 19:56:42 +020010091 NL80211_CMD_SCAN_ABORTED) < 0) {
Johannes Berg2a519312009-02-10 21:25:55 +010010092 nlmsg_free(msg);
10093 return;
10094 }
10095
Johannes Berg68eb5502013-11-19 15:19:38 +010010096 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010010097 NL80211_MCGRP_SCAN, GFP_KERNEL);
Johannes Berg2a519312009-02-10 21:25:55 +010010098}
10099
Luciano Coelho807f8a82011-05-11 17:09:35 +030010100void nl80211_send_sched_scan_results(struct cfg80211_registered_device *rdev,
10101 struct net_device *netdev)
10102{
10103 struct sk_buff *msg;
10104
10105 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
10106 if (!msg)
10107 return;
10108
10109 if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0,
10110 NL80211_CMD_SCHED_SCAN_RESULTS) < 0) {
10111 nlmsg_free(msg);
10112 return;
10113 }
10114
Johannes Berg68eb5502013-11-19 15:19:38 +010010115 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010010116 NL80211_MCGRP_SCAN, GFP_KERNEL);
Luciano Coelho807f8a82011-05-11 17:09:35 +030010117}
10118
10119void nl80211_send_sched_scan(struct cfg80211_registered_device *rdev,
10120 struct net_device *netdev, u32 cmd)
10121{
10122 struct sk_buff *msg;
10123
Thomas Graf58050fc2012-06-28 03:57:45 +000010124 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Luciano Coelho807f8a82011-05-11 17:09:35 +030010125 if (!msg)
10126 return;
10127
10128 if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0, cmd) < 0) {
10129 nlmsg_free(msg);
10130 return;
10131 }
10132
Johannes Berg68eb5502013-11-19 15:19:38 +010010133 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010010134 NL80211_MCGRP_SCAN, GFP_KERNEL);
Luciano Coelho807f8a82011-05-11 17:09:35 +030010135}
10136
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040010137/*
10138 * This can happen on global regulatory changes or device specific settings
10139 * based on custom world regulatory domains.
10140 */
10141void nl80211_send_reg_change_event(struct regulatory_request *request)
10142{
10143 struct sk_buff *msg;
10144 void *hdr;
10145
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -070010146 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040010147 if (!msg)
10148 return;
10149
10150 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_CHANGE);
10151 if (!hdr) {
10152 nlmsg_free(msg);
10153 return;
10154 }
10155
10156 /* Userspace can always count this one always being set */
David S. Miller9360ffd2012-03-29 04:41:26 -040010157 if (nla_put_u8(msg, NL80211_ATTR_REG_INITIATOR, request->initiator))
10158 goto nla_put_failure;
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040010159
David S. Miller9360ffd2012-03-29 04:41:26 -040010160 if (request->alpha2[0] == '0' && request->alpha2[1] == '0') {
10161 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
10162 NL80211_REGDOM_TYPE_WORLD))
10163 goto nla_put_failure;
10164 } else if (request->alpha2[0] == '9' && request->alpha2[1] == '9') {
10165 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
10166 NL80211_REGDOM_TYPE_CUSTOM_WORLD))
10167 goto nla_put_failure;
10168 } else if ((request->alpha2[0] == '9' && request->alpha2[1] == '8') ||
10169 request->intersect) {
10170 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
10171 NL80211_REGDOM_TYPE_INTERSECTION))
10172 goto nla_put_failure;
10173 } else {
10174 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
10175 NL80211_REGDOM_TYPE_COUNTRY) ||
10176 nla_put_string(msg, NL80211_ATTR_REG_ALPHA2,
10177 request->alpha2))
10178 goto nla_put_failure;
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040010179 }
10180
Johannes Bergf4173762012-12-03 18:23:37 +010010181 if (request->wiphy_idx != WIPHY_IDX_INVALID &&
David S. Miller9360ffd2012-03-29 04:41:26 -040010182 nla_put_u32(msg, NL80211_ATTR_WIPHY, request->wiphy_idx))
10183 goto nla_put_failure;
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040010184
Johannes Berg3b7b72e2011-10-22 19:05:51 +020010185 genlmsg_end(msg, hdr);
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040010186
Johannes Bergbc43b282009-07-25 10:54:13 +020010187 rcu_read_lock();
Johannes Berg68eb5502013-11-19 15:19:38 +010010188 genlmsg_multicast_allns(&nl80211_fam, msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010010189 NL80211_MCGRP_REGULATORY, GFP_ATOMIC);
Johannes Bergbc43b282009-07-25 10:54:13 +020010190 rcu_read_unlock();
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040010191
10192 return;
10193
10194nla_put_failure:
10195 genlmsg_cancel(msg, hdr);
10196 nlmsg_free(msg);
10197}
10198
Jouni Malinen6039f6d2009-03-19 13:39:21 +020010199static void nl80211_send_mlme_event(struct cfg80211_registered_device *rdev,
10200 struct net_device *netdev,
10201 const u8 *buf, size_t len,
Johannes Berge6d6e342009-07-01 21:26:47 +020010202 enum nl80211_commands cmd, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +020010203{
10204 struct sk_buff *msg;
10205 void *hdr;
10206
Johannes Berge6d6e342009-07-01 21:26:47 +020010207 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020010208 if (!msg)
10209 return;
10210
10211 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
10212 if (!hdr) {
10213 nlmsg_free(msg);
10214 return;
10215 }
10216
David S. Miller9360ffd2012-03-29 04:41:26 -040010217 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
10218 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
10219 nla_put(msg, NL80211_ATTR_FRAME, len, buf))
10220 goto nla_put_failure;
Jouni Malinen6039f6d2009-03-19 13:39:21 +020010221
Johannes Berg3b7b72e2011-10-22 19:05:51 +020010222 genlmsg_end(msg, hdr);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020010223
Johannes Berg68eb5502013-11-19 15:19:38 +010010224 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010010225 NL80211_MCGRP_MLME, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020010226 return;
10227
10228 nla_put_failure:
10229 genlmsg_cancel(msg, hdr);
10230 nlmsg_free(msg);
10231}
10232
10233void nl80211_send_rx_auth(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +020010234 struct net_device *netdev, const u8 *buf,
10235 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +020010236{
10237 nl80211_send_mlme_event(rdev, netdev, buf, len,
Johannes Berge6d6e342009-07-01 21:26:47 +020010238 NL80211_CMD_AUTHENTICATE, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020010239}
10240
10241void nl80211_send_rx_assoc(struct cfg80211_registered_device *rdev,
10242 struct net_device *netdev, const u8 *buf,
Johannes Berge6d6e342009-07-01 21:26:47 +020010243 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +020010244{
Johannes Berge6d6e342009-07-01 21:26:47 +020010245 nl80211_send_mlme_event(rdev, netdev, buf, len,
10246 NL80211_CMD_ASSOCIATE, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020010247}
10248
Jouni Malinen53b46b82009-03-27 20:53:56 +020010249void nl80211_send_deauth(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +020010250 struct net_device *netdev, const u8 *buf,
10251 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +020010252{
10253 nl80211_send_mlme_event(rdev, netdev, buf, len,
Johannes Berge6d6e342009-07-01 21:26:47 +020010254 NL80211_CMD_DEAUTHENTICATE, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020010255}
10256
Jouni Malinen53b46b82009-03-27 20:53:56 +020010257void nl80211_send_disassoc(struct cfg80211_registered_device *rdev,
10258 struct net_device *netdev, const u8 *buf,
Johannes Berge6d6e342009-07-01 21:26:47 +020010259 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +020010260{
10261 nl80211_send_mlme_event(rdev, netdev, buf, len,
Johannes Berge6d6e342009-07-01 21:26:47 +020010262 NL80211_CMD_DISASSOCIATE, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020010263}
10264
Johannes Berg6ff57cf2013-05-16 00:55:00 +020010265void cfg80211_rx_unprot_mlme_mgmt(struct net_device *dev, const u8 *buf,
10266 size_t len)
Jouni Malinencf4e5942010-12-16 00:52:40 +020010267{
Johannes Berg947add32013-02-22 22:05:20 +010010268 struct wireless_dev *wdev = dev->ieee80211_ptr;
10269 struct wiphy *wiphy = wdev->wiphy;
10270 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
Johannes Berg6ff57cf2013-05-16 00:55:00 +020010271 const struct ieee80211_mgmt *mgmt = (void *)buf;
10272 u32 cmd;
Jouni Malinencf4e5942010-12-16 00:52:40 +020010273
Johannes Berg6ff57cf2013-05-16 00:55:00 +020010274 if (WARN_ON(len < 2))
10275 return;
10276
10277 if (ieee80211_is_deauth(mgmt->frame_control))
10278 cmd = NL80211_CMD_UNPROT_DEAUTHENTICATE;
10279 else
10280 cmd = NL80211_CMD_UNPROT_DISASSOCIATE;
10281
10282 trace_cfg80211_rx_unprot_mlme_mgmt(dev, buf, len);
10283 nl80211_send_mlme_event(rdev, dev, buf, len, cmd, GFP_ATOMIC);
Jouni Malinencf4e5942010-12-16 00:52:40 +020010284}
Johannes Berg6ff57cf2013-05-16 00:55:00 +020010285EXPORT_SYMBOL(cfg80211_rx_unprot_mlme_mgmt);
Jouni Malinencf4e5942010-12-16 00:52:40 +020010286
Luis R. Rodriguez1b06bb42009-05-02 00:34:48 -040010287static void nl80211_send_mlme_timeout(struct cfg80211_registered_device *rdev,
10288 struct net_device *netdev, int cmd,
Johannes Berge6d6e342009-07-01 21:26:47 +020010289 const u8 *addr, gfp_t gfp)
Jouni Malinen1965c852009-04-22 21:38:25 +030010290{
10291 struct sk_buff *msg;
10292 void *hdr;
10293
Johannes Berge6d6e342009-07-01 21:26:47 +020010294 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +030010295 if (!msg)
10296 return;
10297
10298 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
10299 if (!hdr) {
10300 nlmsg_free(msg);
10301 return;
10302 }
10303
David S. Miller9360ffd2012-03-29 04:41:26 -040010304 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
10305 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
10306 nla_put_flag(msg, NL80211_ATTR_TIMED_OUT) ||
10307 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr))
10308 goto nla_put_failure;
Jouni Malinen1965c852009-04-22 21:38:25 +030010309
Johannes Berg3b7b72e2011-10-22 19:05:51 +020010310 genlmsg_end(msg, hdr);
Jouni Malinen1965c852009-04-22 21:38:25 +030010311
Johannes Berg68eb5502013-11-19 15:19:38 +010010312 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010010313 NL80211_MCGRP_MLME, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +030010314 return;
10315
10316 nla_put_failure:
10317 genlmsg_cancel(msg, hdr);
10318 nlmsg_free(msg);
10319}
10320
10321void nl80211_send_auth_timeout(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +020010322 struct net_device *netdev, const u8 *addr,
10323 gfp_t gfp)
Jouni Malinen1965c852009-04-22 21:38:25 +030010324{
10325 nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_AUTHENTICATE,
Johannes Berge6d6e342009-07-01 21:26:47 +020010326 addr, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +030010327}
10328
10329void nl80211_send_assoc_timeout(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +020010330 struct net_device *netdev, const u8 *addr,
10331 gfp_t gfp)
Jouni Malinen1965c852009-04-22 21:38:25 +030010332{
Johannes Berge6d6e342009-07-01 21:26:47 +020010333 nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_ASSOCIATE,
10334 addr, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +030010335}
10336
Samuel Ortizb23aa672009-07-01 21:26:54 +020010337void nl80211_send_connect_result(struct cfg80211_registered_device *rdev,
10338 struct net_device *netdev, const u8 *bssid,
10339 const u8 *req_ie, size_t req_ie_len,
10340 const u8 *resp_ie, size_t resp_ie_len,
10341 u16 status, gfp_t gfp)
10342{
10343 struct sk_buff *msg;
10344 void *hdr;
10345
Thomas Graf58050fc2012-06-28 03:57:45 +000010346 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +020010347 if (!msg)
10348 return;
10349
10350 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONNECT);
10351 if (!hdr) {
10352 nlmsg_free(msg);
10353 return;
10354 }
10355
David S. Miller9360ffd2012-03-29 04:41:26 -040010356 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
10357 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
10358 (bssid && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) ||
10359 nla_put_u16(msg, NL80211_ATTR_STATUS_CODE, status) ||
10360 (req_ie &&
10361 nla_put(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie)) ||
10362 (resp_ie &&
10363 nla_put(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie)))
10364 goto nla_put_failure;
Samuel Ortizb23aa672009-07-01 21:26:54 +020010365
Johannes Berg3b7b72e2011-10-22 19:05:51 +020010366 genlmsg_end(msg, hdr);
Samuel Ortizb23aa672009-07-01 21:26:54 +020010367
Johannes Berg68eb5502013-11-19 15:19:38 +010010368 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010010369 NL80211_MCGRP_MLME, gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +020010370 return;
10371
10372 nla_put_failure:
10373 genlmsg_cancel(msg, hdr);
10374 nlmsg_free(msg);
10375
10376}
10377
10378void nl80211_send_roamed(struct cfg80211_registered_device *rdev,
10379 struct net_device *netdev, const u8 *bssid,
10380 const u8 *req_ie, size_t req_ie_len,
10381 const u8 *resp_ie, size_t resp_ie_len, gfp_t gfp)
10382{
10383 struct sk_buff *msg;
10384 void *hdr;
10385
Thomas Graf58050fc2012-06-28 03:57:45 +000010386 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +020010387 if (!msg)
10388 return;
10389
10390 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_ROAM);
10391 if (!hdr) {
10392 nlmsg_free(msg);
10393 return;
10394 }
10395
David S. Miller9360ffd2012-03-29 04:41:26 -040010396 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
10397 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
10398 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid) ||
10399 (req_ie &&
10400 nla_put(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie)) ||
10401 (resp_ie &&
10402 nla_put(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie)))
10403 goto nla_put_failure;
Samuel Ortizb23aa672009-07-01 21:26:54 +020010404
Johannes Berg3b7b72e2011-10-22 19:05:51 +020010405 genlmsg_end(msg, hdr);
Samuel Ortizb23aa672009-07-01 21:26:54 +020010406
Johannes Berg68eb5502013-11-19 15:19:38 +010010407 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010010408 NL80211_MCGRP_MLME, gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +020010409 return;
10410
10411 nla_put_failure:
10412 genlmsg_cancel(msg, hdr);
10413 nlmsg_free(msg);
10414
10415}
10416
10417void nl80211_send_disconnected(struct cfg80211_registered_device *rdev,
10418 struct net_device *netdev, u16 reason,
Johannes Berg667503d2009-07-07 03:56:11 +020010419 const u8 *ie, size_t ie_len, bool from_ap)
Samuel Ortizb23aa672009-07-01 21:26:54 +020010420{
10421 struct sk_buff *msg;
10422 void *hdr;
10423
Thomas Graf58050fc2012-06-28 03:57:45 +000010424 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Samuel Ortizb23aa672009-07-01 21:26:54 +020010425 if (!msg)
10426 return;
10427
10428 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DISCONNECT);
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 (from_ap && reason &&
10437 nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason)) ||
10438 (from_ap &&
10439 nla_put_flag(msg, NL80211_ATTR_DISCONNECTED_BY_AP)) ||
10440 (ie && nla_put(msg, NL80211_ATTR_IE, ie_len, ie)))
10441 goto nla_put_failure;
Samuel Ortizb23aa672009-07-01 21:26:54 +020010442
Johannes Berg3b7b72e2011-10-22 19:05:51 +020010443 genlmsg_end(msg, hdr);
Samuel Ortizb23aa672009-07-01 21:26:54 +020010444
Johannes Berg68eb5502013-11-19 15:19:38 +010010445 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010010446 NL80211_MCGRP_MLME, GFP_KERNEL);
Samuel Ortizb23aa672009-07-01 21:26:54 +020010447 return;
10448
10449 nla_put_failure:
10450 genlmsg_cancel(msg, hdr);
10451 nlmsg_free(msg);
10452
10453}
10454
Johannes Berg04a773a2009-04-19 21:24:32 +020010455void nl80211_send_ibss_bssid(struct cfg80211_registered_device *rdev,
10456 struct net_device *netdev, const u8 *bssid,
10457 gfp_t gfp)
10458{
10459 struct sk_buff *msg;
10460 void *hdr;
10461
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -070010462 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Johannes Berg04a773a2009-04-19 21:24:32 +020010463 if (!msg)
10464 return;
10465
10466 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_JOIN_IBSS);
10467 if (!hdr) {
10468 nlmsg_free(msg);
10469 return;
10470 }
10471
David S. Miller9360ffd2012-03-29 04:41:26 -040010472 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
10473 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
10474 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid))
10475 goto nla_put_failure;
Johannes Berg04a773a2009-04-19 21:24:32 +020010476
Johannes Berg3b7b72e2011-10-22 19:05:51 +020010477 genlmsg_end(msg, hdr);
Johannes Berg04a773a2009-04-19 21:24:32 +020010478
Johannes Berg68eb5502013-11-19 15:19:38 +010010479 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010010480 NL80211_MCGRP_MLME, gfp);
Johannes Berg04a773a2009-04-19 21:24:32 +020010481 return;
10482
10483 nla_put_failure:
10484 genlmsg_cancel(msg, hdr);
10485 nlmsg_free(msg);
10486}
10487
Johannes Berg947add32013-02-22 22:05:20 +010010488void cfg80211_notify_new_peer_candidate(struct net_device *dev, const u8 *addr,
10489 const u8* ie, u8 ie_len, gfp_t gfp)
Javier Cardonac93b5e72011-04-07 15:08:34 -070010490{
Johannes Berg947add32013-02-22 22:05:20 +010010491 struct wireless_dev *wdev = dev->ieee80211_ptr;
10492 struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
Javier Cardonac93b5e72011-04-07 15:08:34 -070010493 struct sk_buff *msg;
10494 void *hdr;
10495
Johannes Berg947add32013-02-22 22:05:20 +010010496 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_MESH_POINT))
10497 return;
10498
10499 trace_cfg80211_notify_new_peer_candidate(dev, addr);
10500
Javier Cardonac93b5e72011-04-07 15:08:34 -070010501 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
10502 if (!msg)
10503 return;
10504
10505 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NEW_PEER_CANDIDATE);
10506 if (!hdr) {
10507 nlmsg_free(msg);
10508 return;
10509 }
10510
David S. Miller9360ffd2012-03-29 04:41:26 -040010511 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg947add32013-02-22 22:05:20 +010010512 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
10513 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040010514 (ie_len && ie &&
10515 nla_put(msg, NL80211_ATTR_IE, ie_len , ie)))
10516 goto nla_put_failure;
Javier Cardonac93b5e72011-04-07 15:08:34 -070010517
Johannes Berg3b7b72e2011-10-22 19:05:51 +020010518 genlmsg_end(msg, hdr);
Javier Cardonac93b5e72011-04-07 15:08:34 -070010519
Johannes Berg68eb5502013-11-19 15:19:38 +010010520 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010010521 NL80211_MCGRP_MLME, gfp);
Javier Cardonac93b5e72011-04-07 15:08:34 -070010522 return;
10523
10524 nla_put_failure:
10525 genlmsg_cancel(msg, hdr);
10526 nlmsg_free(msg);
10527}
Johannes Berg947add32013-02-22 22:05:20 +010010528EXPORT_SYMBOL(cfg80211_notify_new_peer_candidate);
Javier Cardonac93b5e72011-04-07 15:08:34 -070010529
Jouni Malinena3b8b052009-03-27 21:59:49 +020010530void nl80211_michael_mic_failure(struct cfg80211_registered_device *rdev,
10531 struct net_device *netdev, const u8 *addr,
10532 enum nl80211_key_type key_type, int key_id,
Johannes Berge6d6e342009-07-01 21:26:47 +020010533 const u8 *tsc, gfp_t gfp)
Jouni Malinena3b8b052009-03-27 21:59:49 +020010534{
10535 struct sk_buff *msg;
10536 void *hdr;
10537
Johannes Berge6d6e342009-07-01 21:26:47 +020010538 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinena3b8b052009-03-27 21:59:49 +020010539 if (!msg)
10540 return;
10541
10542 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_MICHAEL_MIC_FAILURE);
10543 if (!hdr) {
10544 nlmsg_free(msg);
10545 return;
10546 }
10547
David S. Miller9360ffd2012-03-29 04:41:26 -040010548 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
10549 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
10550 (addr && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) ||
10551 nla_put_u32(msg, NL80211_ATTR_KEY_TYPE, key_type) ||
10552 (key_id != -1 &&
10553 nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_id)) ||
10554 (tsc && nla_put(msg, NL80211_ATTR_KEY_SEQ, 6, tsc)))
10555 goto nla_put_failure;
Jouni Malinena3b8b052009-03-27 21:59:49 +020010556
Johannes Berg3b7b72e2011-10-22 19:05:51 +020010557 genlmsg_end(msg, hdr);
Jouni Malinena3b8b052009-03-27 21:59:49 +020010558
Johannes Berg68eb5502013-11-19 15:19:38 +010010559 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010010560 NL80211_MCGRP_MLME, gfp);
Jouni Malinena3b8b052009-03-27 21:59:49 +020010561 return;
10562
10563 nla_put_failure:
10564 genlmsg_cancel(msg, hdr);
10565 nlmsg_free(msg);
10566}
10567
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040010568void nl80211_send_beacon_hint_event(struct wiphy *wiphy,
10569 struct ieee80211_channel *channel_before,
10570 struct ieee80211_channel *channel_after)
10571{
10572 struct sk_buff *msg;
10573 void *hdr;
10574 struct nlattr *nl_freq;
10575
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -070010576 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_ATOMIC);
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040010577 if (!msg)
10578 return;
10579
10580 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_BEACON_HINT);
10581 if (!hdr) {
10582 nlmsg_free(msg);
10583 return;
10584 }
10585
10586 /*
10587 * Since we are applying the beacon hint to a wiphy we know its
10588 * wiphy_idx is valid
10589 */
David S. Miller9360ffd2012-03-29 04:41:26 -040010590 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy)))
10591 goto nla_put_failure;
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040010592
10593 /* Before */
10594 nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_BEFORE);
10595 if (!nl_freq)
10596 goto nla_put_failure;
Johannes Bergcdc89b92013-02-18 23:54:36 +010010597 if (nl80211_msg_put_channel(msg, channel_before, false))
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040010598 goto nla_put_failure;
10599 nla_nest_end(msg, nl_freq);
10600
10601 /* After */
10602 nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_AFTER);
10603 if (!nl_freq)
10604 goto nla_put_failure;
Johannes Bergcdc89b92013-02-18 23:54:36 +010010605 if (nl80211_msg_put_channel(msg, channel_after, false))
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040010606 goto nla_put_failure;
10607 nla_nest_end(msg, nl_freq);
10608
Johannes Berg3b7b72e2011-10-22 19:05:51 +020010609 genlmsg_end(msg, hdr);
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040010610
Johannes Berg463d0182009-07-14 00:33:35 +020010611 rcu_read_lock();
Johannes Berg68eb5502013-11-19 15:19:38 +010010612 genlmsg_multicast_allns(&nl80211_fam, msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010010613 NL80211_MCGRP_REGULATORY, GFP_ATOMIC);
Johannes Berg463d0182009-07-14 00:33:35 +020010614 rcu_read_unlock();
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040010615
10616 return;
10617
10618nla_put_failure:
10619 genlmsg_cancel(msg, hdr);
10620 nlmsg_free(msg);
10621}
10622
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010623static void nl80211_send_remain_on_chan_event(
10624 int cmd, struct cfg80211_registered_device *rdev,
Johannes Berg71bbc992012-06-15 15:30:18 +020010625 struct wireless_dev *wdev, u64 cookie,
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010626 struct ieee80211_channel *chan,
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010627 unsigned int duration, gfp_t gfp)
10628{
10629 struct sk_buff *msg;
10630 void *hdr;
10631
10632 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
10633 if (!msg)
10634 return;
10635
10636 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
10637 if (!hdr) {
10638 nlmsg_free(msg);
10639 return;
10640 }
10641
David S. Miller9360ffd2012-03-29 04:41:26 -040010642 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg71bbc992012-06-15 15:30:18 +020010643 (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
10644 wdev->netdev->ifindex)) ||
Johannes Berg00f53352012-07-17 11:53:12 +020010645 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040010646 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, chan->center_freq) ||
Johannes Berg42d97a52012-11-08 18:31:02 +010010647 nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE,
10648 NL80211_CHAN_NO_HT) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040010649 nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie))
10650 goto nla_put_failure;
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010651
David S. Miller9360ffd2012-03-29 04:41:26 -040010652 if (cmd == NL80211_CMD_REMAIN_ON_CHANNEL &&
10653 nla_put_u32(msg, NL80211_ATTR_DURATION, duration))
10654 goto nla_put_failure;
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010655
Johannes Berg3b7b72e2011-10-22 19:05:51 +020010656 genlmsg_end(msg, hdr);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010657
Johannes Berg68eb5502013-11-19 15:19:38 +010010658 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010010659 NL80211_MCGRP_MLME, gfp);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010660 return;
10661
10662 nla_put_failure:
10663 genlmsg_cancel(msg, hdr);
10664 nlmsg_free(msg);
10665}
10666
Johannes Berg947add32013-02-22 22:05:20 +010010667void cfg80211_ready_on_channel(struct wireless_dev *wdev, u64 cookie,
10668 struct ieee80211_channel *chan,
10669 unsigned int duration, gfp_t gfp)
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010670{
Johannes Berg947add32013-02-22 22:05:20 +010010671 struct wiphy *wiphy = wdev->wiphy;
10672 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
10673
10674 trace_cfg80211_ready_on_channel(wdev, cookie, chan, duration);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010675 nl80211_send_remain_on_chan_event(NL80211_CMD_REMAIN_ON_CHANNEL,
Johannes Berg71bbc992012-06-15 15:30:18 +020010676 rdev, wdev, cookie, chan,
Johannes Berg42d97a52012-11-08 18:31:02 +010010677 duration, gfp);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010678}
Johannes Berg947add32013-02-22 22:05:20 +010010679EXPORT_SYMBOL(cfg80211_ready_on_channel);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010680
Johannes Berg947add32013-02-22 22:05:20 +010010681void cfg80211_remain_on_channel_expired(struct wireless_dev *wdev, u64 cookie,
10682 struct ieee80211_channel *chan,
10683 gfp_t gfp)
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010684{
Johannes Berg947add32013-02-22 22:05:20 +010010685 struct wiphy *wiphy = wdev->wiphy;
10686 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
10687
10688 trace_cfg80211_ready_on_channel_expired(wdev, cookie, chan);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010689 nl80211_send_remain_on_chan_event(NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL,
Johannes Berg42d97a52012-11-08 18:31:02 +010010690 rdev, wdev, cookie, chan, 0, gfp);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010691}
Johannes Berg947add32013-02-22 22:05:20 +010010692EXPORT_SYMBOL(cfg80211_remain_on_channel_expired);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010693
Johannes Berg947add32013-02-22 22:05:20 +010010694void cfg80211_new_sta(struct net_device *dev, const u8 *mac_addr,
10695 struct station_info *sinfo, gfp_t gfp)
Johannes Berg98b62182009-12-23 13:15:44 +010010696{
Johannes Berg947add32013-02-22 22:05:20 +010010697 struct wiphy *wiphy = dev->ieee80211_ptr->wiphy;
10698 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
Johannes Berg98b62182009-12-23 13:15:44 +010010699 struct sk_buff *msg;
10700
Johannes Berg947add32013-02-22 22:05:20 +010010701 trace_cfg80211_new_sta(dev, mac_addr, sinfo);
10702
Thomas Graf58050fc2012-06-28 03:57:45 +000010703 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Johannes Berg98b62182009-12-23 13:15:44 +010010704 if (!msg)
10705 return;
10706
John W. Linville66266b32012-03-15 13:25:41 -040010707 if (nl80211_send_station(msg, 0, 0, 0,
10708 rdev, dev, mac_addr, sinfo) < 0) {
Johannes Berg98b62182009-12-23 13:15:44 +010010709 nlmsg_free(msg);
10710 return;
10711 }
10712
Johannes Berg68eb5502013-11-19 15:19:38 +010010713 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010010714 NL80211_MCGRP_MLME, gfp);
Johannes Berg98b62182009-12-23 13:15:44 +010010715}
Johannes Berg947add32013-02-22 22:05:20 +010010716EXPORT_SYMBOL(cfg80211_new_sta);
Johannes Berg98b62182009-12-23 13:15:44 +010010717
Johannes Berg947add32013-02-22 22:05:20 +010010718void cfg80211_del_sta(struct net_device *dev, const u8 *mac_addr, gfp_t gfp)
Jouni Malinenec15e682011-03-23 15:29:52 +020010719{
Johannes Berg947add32013-02-22 22:05:20 +010010720 struct wiphy *wiphy = dev->ieee80211_ptr->wiphy;
10721 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
Jouni Malinenec15e682011-03-23 15:29:52 +020010722 struct sk_buff *msg;
10723 void *hdr;
10724
Johannes Berg947add32013-02-22 22:05:20 +010010725 trace_cfg80211_del_sta(dev, mac_addr);
10726
Thomas Graf58050fc2012-06-28 03:57:45 +000010727 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinenec15e682011-03-23 15:29:52 +020010728 if (!msg)
10729 return;
10730
10731 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DEL_STATION);
10732 if (!hdr) {
10733 nlmsg_free(msg);
10734 return;
10735 }
10736
David S. Miller9360ffd2012-03-29 04:41:26 -040010737 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
10738 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr))
10739 goto nla_put_failure;
Jouni Malinenec15e682011-03-23 15:29:52 +020010740
Johannes Berg3b7b72e2011-10-22 19:05:51 +020010741 genlmsg_end(msg, hdr);
Jouni Malinenec15e682011-03-23 15:29:52 +020010742
Johannes Berg68eb5502013-11-19 15:19:38 +010010743 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010010744 NL80211_MCGRP_MLME, gfp);
Jouni Malinenec15e682011-03-23 15:29:52 +020010745 return;
10746
10747 nla_put_failure:
10748 genlmsg_cancel(msg, hdr);
10749 nlmsg_free(msg);
10750}
Johannes Berg947add32013-02-22 22:05:20 +010010751EXPORT_SYMBOL(cfg80211_del_sta);
Jouni Malinenec15e682011-03-23 15:29:52 +020010752
Johannes Berg947add32013-02-22 22:05:20 +010010753void cfg80211_conn_failed(struct net_device *dev, const u8 *mac_addr,
10754 enum nl80211_connect_failed_reason reason,
10755 gfp_t gfp)
Pandiyarajan Pitchaimuthued44a952012-09-18 16:50:49 +053010756{
Johannes Berg947add32013-02-22 22:05:20 +010010757 struct wiphy *wiphy = dev->ieee80211_ptr->wiphy;
10758 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
Pandiyarajan Pitchaimuthued44a952012-09-18 16:50:49 +053010759 struct sk_buff *msg;
10760 void *hdr;
10761
10762 msg = nlmsg_new(NLMSG_GOODSIZE, gfp);
10763 if (!msg)
10764 return;
10765
10766 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONN_FAILED);
10767 if (!hdr) {
10768 nlmsg_free(msg);
10769 return;
10770 }
10771
10772 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
10773 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) ||
10774 nla_put_u32(msg, NL80211_ATTR_CONN_FAILED_REASON, reason))
10775 goto nla_put_failure;
10776
10777 genlmsg_end(msg, hdr);
10778
Johannes Berg68eb5502013-11-19 15:19:38 +010010779 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010010780 NL80211_MCGRP_MLME, gfp);
Pandiyarajan Pitchaimuthued44a952012-09-18 16:50:49 +053010781 return;
10782
10783 nla_put_failure:
10784 genlmsg_cancel(msg, hdr);
10785 nlmsg_free(msg);
10786}
Johannes Berg947add32013-02-22 22:05:20 +010010787EXPORT_SYMBOL(cfg80211_conn_failed);
Pandiyarajan Pitchaimuthued44a952012-09-18 16:50:49 +053010788
Johannes Bergb92ab5d2011-11-04 11:18:19 +010010789static bool __nl80211_unexpected_frame(struct net_device *dev, u8 cmd,
10790 const u8 *addr, gfp_t gfp)
Johannes Berg28946da2011-11-04 11:18:12 +010010791{
10792 struct wireless_dev *wdev = dev->ieee80211_ptr;
10793 struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
10794 struct sk_buff *msg;
10795 void *hdr;
Eric W. Biederman15e47302012-09-07 20:12:54 +000010796 u32 nlportid = ACCESS_ONCE(wdev->ap_unexpected_nlportid);
Johannes Berg28946da2011-11-04 11:18:12 +010010797
Eric W. Biederman15e47302012-09-07 20:12:54 +000010798 if (!nlportid)
Johannes Berg28946da2011-11-04 11:18:12 +010010799 return false;
10800
10801 msg = nlmsg_new(100, gfp);
10802 if (!msg)
10803 return true;
10804
Johannes Bergb92ab5d2011-11-04 11:18:19 +010010805 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
Johannes Berg28946da2011-11-04 11:18:12 +010010806 if (!hdr) {
10807 nlmsg_free(msg);
10808 return true;
10809 }
10810
David S. Miller9360ffd2012-03-29 04:41:26 -040010811 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
10812 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
10813 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr))
10814 goto nla_put_failure;
Johannes Berg28946da2011-11-04 11:18:12 +010010815
Johannes Berg9c90a9f2013-06-04 12:46:03 +020010816 genlmsg_end(msg, hdr);
Eric W. Biederman15e47302012-09-07 20:12:54 +000010817 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid);
Johannes Berg28946da2011-11-04 11:18:12 +010010818 return true;
10819
10820 nla_put_failure:
10821 genlmsg_cancel(msg, hdr);
10822 nlmsg_free(msg);
10823 return true;
10824}
10825
Johannes Berg947add32013-02-22 22:05:20 +010010826bool cfg80211_rx_spurious_frame(struct net_device *dev,
10827 const u8 *addr, gfp_t gfp)
Johannes Bergb92ab5d2011-11-04 11:18:19 +010010828{
Johannes Berg947add32013-02-22 22:05:20 +010010829 struct wireless_dev *wdev = dev->ieee80211_ptr;
10830 bool ret;
Johannes Bergb92ab5d2011-11-04 11:18:19 +010010831
Johannes Berg947add32013-02-22 22:05:20 +010010832 trace_cfg80211_rx_spurious_frame(dev, addr);
10833
10834 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP &&
10835 wdev->iftype != NL80211_IFTYPE_P2P_GO)) {
10836 trace_cfg80211_return_bool(false);
10837 return false;
10838 }
10839 ret = __nl80211_unexpected_frame(dev, NL80211_CMD_UNEXPECTED_FRAME,
10840 addr, gfp);
10841 trace_cfg80211_return_bool(ret);
10842 return ret;
Johannes Bergb92ab5d2011-11-04 11:18:19 +010010843}
Johannes Berg947add32013-02-22 22:05:20 +010010844EXPORT_SYMBOL(cfg80211_rx_spurious_frame);
10845
10846bool cfg80211_rx_unexpected_4addr_frame(struct net_device *dev,
10847 const u8 *addr, gfp_t gfp)
10848{
10849 struct wireless_dev *wdev = dev->ieee80211_ptr;
10850 bool ret;
10851
10852 trace_cfg80211_rx_unexpected_4addr_frame(dev, addr);
10853
10854 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP &&
10855 wdev->iftype != NL80211_IFTYPE_P2P_GO &&
10856 wdev->iftype != NL80211_IFTYPE_AP_VLAN)) {
10857 trace_cfg80211_return_bool(false);
10858 return false;
10859 }
10860 ret = __nl80211_unexpected_frame(dev,
10861 NL80211_CMD_UNEXPECTED_4ADDR_FRAME,
10862 addr, gfp);
10863 trace_cfg80211_return_bool(ret);
10864 return ret;
10865}
10866EXPORT_SYMBOL(cfg80211_rx_unexpected_4addr_frame);
Johannes Bergb92ab5d2011-11-04 11:18:19 +010010867
Johannes Berg2e161f72010-08-12 15:38:38 +020010868int nl80211_send_mgmt(struct cfg80211_registered_device *rdev,
Eric W. Biederman15e47302012-09-07 20:12:54 +000010869 struct wireless_dev *wdev, u32 nlportid,
Johannes Berg804483e2012-03-05 22:18:41 +010010870 int freq, int sig_dbm,
Vladimir Kondratiev19504cf2013-08-15 14:51:28 +030010871 const u8 *buf, size_t len, u32 flags, gfp_t gfp)
Jouni Malinen026331c2010-02-15 12:53:10 +020010872{
Johannes Berg71bbc992012-06-15 15:30:18 +020010873 struct net_device *netdev = wdev->netdev;
Jouni Malinen026331c2010-02-15 12:53:10 +020010874 struct sk_buff *msg;
10875 void *hdr;
Jouni Malinen026331c2010-02-15 12:53:10 +020010876
10877 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
10878 if (!msg)
10879 return -ENOMEM;
10880
Johannes Berg2e161f72010-08-12 15:38:38 +020010881 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME);
Jouni Malinen026331c2010-02-15 12:53:10 +020010882 if (!hdr) {
10883 nlmsg_free(msg);
10884 return -ENOMEM;
10885 }
10886
David S. Miller9360ffd2012-03-29 04:41:26 -040010887 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg71bbc992012-06-15 15:30:18 +020010888 (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
10889 netdev->ifindex)) ||
Ilan Peera8384902013-05-08 16:35:55 +030010890 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040010891 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq) ||
10892 (sig_dbm &&
10893 nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) ||
Vladimir Kondratiev19504cf2013-08-15 14:51:28 +030010894 nla_put(msg, NL80211_ATTR_FRAME, len, buf) ||
10895 (flags &&
10896 nla_put_u32(msg, NL80211_ATTR_RXMGMT_FLAGS, flags)))
David S. Miller9360ffd2012-03-29 04:41:26 -040010897 goto nla_put_failure;
Jouni Malinen026331c2010-02-15 12:53:10 +020010898
Johannes Berg3b7b72e2011-10-22 19:05:51 +020010899 genlmsg_end(msg, hdr);
Jouni Malinen026331c2010-02-15 12:53:10 +020010900
Eric W. Biederman15e47302012-09-07 20:12:54 +000010901 return genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid);
Jouni Malinen026331c2010-02-15 12:53:10 +020010902
10903 nla_put_failure:
10904 genlmsg_cancel(msg, hdr);
10905 nlmsg_free(msg);
10906 return -ENOBUFS;
10907}
10908
Johannes Berg947add32013-02-22 22:05:20 +010010909void cfg80211_mgmt_tx_status(struct wireless_dev *wdev, u64 cookie,
10910 const u8 *buf, size_t len, bool ack, gfp_t gfp)
Jouni Malinen026331c2010-02-15 12:53:10 +020010911{
Johannes Berg947add32013-02-22 22:05:20 +010010912 struct wiphy *wiphy = wdev->wiphy;
10913 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
Johannes Berg71bbc992012-06-15 15:30:18 +020010914 struct net_device *netdev = wdev->netdev;
Jouni Malinen026331c2010-02-15 12:53:10 +020010915 struct sk_buff *msg;
10916 void *hdr;
10917
Johannes Berg947add32013-02-22 22:05:20 +010010918 trace_cfg80211_mgmt_tx_status(wdev, cookie, ack);
10919
Jouni Malinen026331c2010-02-15 12:53:10 +020010920 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
10921 if (!msg)
10922 return;
10923
Johannes Berg2e161f72010-08-12 15:38:38 +020010924 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME_TX_STATUS);
Jouni Malinen026331c2010-02-15 12:53:10 +020010925 if (!hdr) {
10926 nlmsg_free(msg);
10927 return;
10928 }
10929
David S. Miller9360ffd2012-03-29 04:41:26 -040010930 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg71bbc992012-06-15 15:30:18 +020010931 (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
10932 netdev->ifindex)) ||
Ilan Peera8384902013-05-08 16:35:55 +030010933 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040010934 nla_put(msg, NL80211_ATTR_FRAME, len, buf) ||
10935 nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie) ||
10936 (ack && nla_put_flag(msg, NL80211_ATTR_ACK)))
10937 goto nla_put_failure;
Jouni Malinen026331c2010-02-15 12:53:10 +020010938
Johannes Berg3b7b72e2011-10-22 19:05:51 +020010939 genlmsg_end(msg, hdr);
Jouni Malinen026331c2010-02-15 12:53:10 +020010940
Johannes Berg68eb5502013-11-19 15:19:38 +010010941 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010010942 NL80211_MCGRP_MLME, gfp);
Jouni Malinen026331c2010-02-15 12:53:10 +020010943 return;
10944
10945 nla_put_failure:
10946 genlmsg_cancel(msg, hdr);
10947 nlmsg_free(msg);
10948}
Johannes Berg947add32013-02-22 22:05:20 +010010949EXPORT_SYMBOL(cfg80211_mgmt_tx_status);
Jouni Malinen026331c2010-02-15 12:53:10 +020010950
Johannes Berg947add32013-02-22 22:05:20 +010010951void cfg80211_cqm_rssi_notify(struct net_device *dev,
10952 enum nl80211_cqm_rssi_threshold_event rssi_event,
10953 gfp_t gfp)
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020010954{
Johannes Berg947add32013-02-22 22:05:20 +010010955 struct wireless_dev *wdev = dev->ieee80211_ptr;
10956 struct wiphy *wiphy = wdev->wiphy;
10957 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020010958 struct sk_buff *msg;
10959 struct nlattr *pinfoattr;
10960 void *hdr;
10961
Johannes Berg947add32013-02-22 22:05:20 +010010962 trace_cfg80211_cqm_rssi_notify(dev, rssi_event);
10963
Thomas Graf58050fc2012-06-28 03:57:45 +000010964 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020010965 if (!msg)
10966 return;
10967
10968 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM);
10969 if (!hdr) {
10970 nlmsg_free(msg);
10971 return;
10972 }
10973
David S. Miller9360ffd2012-03-29 04:41:26 -040010974 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg947add32013-02-22 22:05:20 +010010975 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex))
David S. Miller9360ffd2012-03-29 04:41:26 -040010976 goto nla_put_failure;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020010977
10978 pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM);
10979 if (!pinfoattr)
10980 goto nla_put_failure;
10981
David S. Miller9360ffd2012-03-29 04:41:26 -040010982 if (nla_put_u32(msg, NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT,
10983 rssi_event))
10984 goto nla_put_failure;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020010985
10986 nla_nest_end(msg, pinfoattr);
10987
Johannes Berg3b7b72e2011-10-22 19:05:51 +020010988 genlmsg_end(msg, hdr);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020010989
Johannes Berg68eb5502013-11-19 15:19:38 +010010990 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010010991 NL80211_MCGRP_MLME, gfp);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020010992 return;
10993
10994 nla_put_failure:
10995 genlmsg_cancel(msg, hdr);
10996 nlmsg_free(msg);
10997}
Johannes Berg947add32013-02-22 22:05:20 +010010998EXPORT_SYMBOL(cfg80211_cqm_rssi_notify);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020010999
Johannes Berg947add32013-02-22 22:05:20 +010011000static void nl80211_gtk_rekey_notify(struct cfg80211_registered_device *rdev,
11001 struct net_device *netdev, const u8 *bssid,
11002 const u8 *replay_ctr, gfp_t gfp)
Johannes Berge5497d72011-07-05 16:35:40 +020011003{
11004 struct sk_buff *msg;
11005 struct nlattr *rekey_attr;
11006 void *hdr;
11007
Thomas Graf58050fc2012-06-28 03:57:45 +000011008 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Johannes Berge5497d72011-07-05 16:35:40 +020011009 if (!msg)
11010 return;
11011
11012 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_REKEY_OFFLOAD);
11013 if (!hdr) {
11014 nlmsg_free(msg);
11015 return;
11016 }
11017
David S. Miller9360ffd2012-03-29 04:41:26 -040011018 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
11019 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
11020 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid))
11021 goto nla_put_failure;
Johannes Berge5497d72011-07-05 16:35:40 +020011022
11023 rekey_attr = nla_nest_start(msg, NL80211_ATTR_REKEY_DATA);
11024 if (!rekey_attr)
11025 goto nla_put_failure;
11026
David S. Miller9360ffd2012-03-29 04:41:26 -040011027 if (nla_put(msg, NL80211_REKEY_DATA_REPLAY_CTR,
11028 NL80211_REPLAY_CTR_LEN, replay_ctr))
11029 goto nla_put_failure;
Johannes Berge5497d72011-07-05 16:35:40 +020011030
11031 nla_nest_end(msg, rekey_attr);
11032
Johannes Berg3b7b72e2011-10-22 19:05:51 +020011033 genlmsg_end(msg, hdr);
Johannes Berge5497d72011-07-05 16:35:40 +020011034
Johannes Berg68eb5502013-11-19 15:19:38 +010011035 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011036 NL80211_MCGRP_MLME, gfp);
Johannes Berge5497d72011-07-05 16:35:40 +020011037 return;
11038
11039 nla_put_failure:
11040 genlmsg_cancel(msg, hdr);
11041 nlmsg_free(msg);
11042}
11043
Johannes Berg947add32013-02-22 22:05:20 +010011044void cfg80211_gtk_rekey_notify(struct net_device *dev, const u8 *bssid,
11045 const u8 *replay_ctr, gfp_t gfp)
11046{
11047 struct wireless_dev *wdev = dev->ieee80211_ptr;
11048 struct wiphy *wiphy = wdev->wiphy;
11049 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
11050
11051 trace_cfg80211_gtk_rekey_notify(dev, bssid);
11052 nl80211_gtk_rekey_notify(rdev, dev, bssid, replay_ctr, gfp);
11053}
11054EXPORT_SYMBOL(cfg80211_gtk_rekey_notify);
11055
11056static void
11057nl80211_pmksa_candidate_notify(struct cfg80211_registered_device *rdev,
11058 struct net_device *netdev, int index,
11059 const u8 *bssid, bool preauth, gfp_t gfp)
Jouni Malinenc9df56b2011-09-16 18:56:23 +030011060{
11061 struct sk_buff *msg;
11062 struct nlattr *attr;
11063 void *hdr;
11064
Thomas Graf58050fc2012-06-28 03:57:45 +000011065 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinenc9df56b2011-09-16 18:56:23 +030011066 if (!msg)
11067 return;
11068
11069 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PMKSA_CANDIDATE);
11070 if (!hdr) {
11071 nlmsg_free(msg);
11072 return;
11073 }
11074
David S. Miller9360ffd2012-03-29 04:41:26 -040011075 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
11076 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex))
11077 goto nla_put_failure;
Jouni Malinenc9df56b2011-09-16 18:56:23 +030011078
11079 attr = nla_nest_start(msg, NL80211_ATTR_PMKSA_CANDIDATE);
11080 if (!attr)
11081 goto nla_put_failure;
11082
David S. Miller9360ffd2012-03-29 04:41:26 -040011083 if (nla_put_u32(msg, NL80211_PMKSA_CANDIDATE_INDEX, index) ||
11084 nla_put(msg, NL80211_PMKSA_CANDIDATE_BSSID, ETH_ALEN, bssid) ||
11085 (preauth &&
11086 nla_put_flag(msg, NL80211_PMKSA_CANDIDATE_PREAUTH)))
11087 goto nla_put_failure;
Jouni Malinenc9df56b2011-09-16 18:56:23 +030011088
11089 nla_nest_end(msg, attr);
11090
Johannes Berg3b7b72e2011-10-22 19:05:51 +020011091 genlmsg_end(msg, hdr);
Jouni Malinenc9df56b2011-09-16 18:56:23 +030011092
Johannes Berg68eb5502013-11-19 15:19:38 +010011093 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011094 NL80211_MCGRP_MLME, gfp);
Jouni Malinenc9df56b2011-09-16 18:56:23 +030011095 return;
11096
11097 nla_put_failure:
11098 genlmsg_cancel(msg, hdr);
11099 nlmsg_free(msg);
11100}
11101
Johannes Berg947add32013-02-22 22:05:20 +010011102void cfg80211_pmksa_candidate_notify(struct net_device *dev, int index,
11103 const u8 *bssid, bool preauth, gfp_t gfp)
11104{
11105 struct wireless_dev *wdev = dev->ieee80211_ptr;
11106 struct wiphy *wiphy = wdev->wiphy;
11107 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
11108
11109 trace_cfg80211_pmksa_candidate_notify(dev, index, bssid, preauth);
11110 nl80211_pmksa_candidate_notify(rdev, dev, index, bssid, preauth, gfp);
11111}
11112EXPORT_SYMBOL(cfg80211_pmksa_candidate_notify);
11113
11114static void nl80211_ch_switch_notify(struct cfg80211_registered_device *rdev,
11115 struct net_device *netdev,
11116 struct cfg80211_chan_def *chandef,
11117 gfp_t gfp)
Thomas Pedersen53145262012-04-06 13:35:47 -070011118{
11119 struct sk_buff *msg;
11120 void *hdr;
11121
Thomas Graf58050fc2012-06-28 03:57:45 +000011122 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Thomas Pedersen53145262012-04-06 13:35:47 -070011123 if (!msg)
11124 return;
11125
11126 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CH_SWITCH_NOTIFY);
11127 if (!hdr) {
11128 nlmsg_free(msg);
11129 return;
11130 }
11131
Johannes Berg683b6d32012-11-08 21:25:48 +010011132 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex))
11133 goto nla_put_failure;
11134
11135 if (nl80211_send_chandef(msg, chandef))
John W. Linville7eab0f62012-04-12 14:25:14 -040011136 goto nla_put_failure;
Thomas Pedersen53145262012-04-06 13:35:47 -070011137
11138 genlmsg_end(msg, hdr);
11139
Johannes Berg68eb5502013-11-19 15:19:38 +010011140 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011141 NL80211_MCGRP_MLME, gfp);
Thomas Pedersen53145262012-04-06 13:35:47 -070011142 return;
11143
11144 nla_put_failure:
11145 genlmsg_cancel(msg, hdr);
11146 nlmsg_free(msg);
11147}
11148
Johannes Berg947add32013-02-22 22:05:20 +010011149void cfg80211_ch_switch_notify(struct net_device *dev,
11150 struct cfg80211_chan_def *chandef)
Thomas Pedersen84f10702012-07-12 16:17:33 -070011151{
Johannes Berg947add32013-02-22 22:05:20 +010011152 struct wireless_dev *wdev = dev->ieee80211_ptr;
11153 struct wiphy *wiphy = wdev->wiphy;
11154 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
11155
Simon Wunderliche487eae2013-11-21 18:19:51 +010011156 ASSERT_WDEV_LOCK(wdev);
Johannes Berg947add32013-02-22 22:05:20 +010011157
Simon Wunderliche487eae2013-11-21 18:19:51 +010011158 trace_cfg80211_ch_switch_notify(dev, chandef);
Johannes Berg947add32013-02-22 22:05:20 +010011159
11160 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP &&
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +020011161 wdev->iftype != NL80211_IFTYPE_P2P_GO &&
Chun-Yeow Yeohb8456a12013-10-17 15:55:02 -070011162 wdev->iftype != NL80211_IFTYPE_ADHOC &&
11163 wdev->iftype != NL80211_IFTYPE_MESH_POINT))
Simon Wunderliche487eae2013-11-21 18:19:51 +010011164 return;
Johannes Berg947add32013-02-22 22:05:20 +010011165
11166 wdev->channel = chandef->chan;
11167 nl80211_ch_switch_notify(rdev, dev, chandef, GFP_KERNEL);
Johannes Berg947add32013-02-22 22:05:20 +010011168}
11169EXPORT_SYMBOL(cfg80211_ch_switch_notify);
11170
11171void cfg80211_cqm_txe_notify(struct net_device *dev,
11172 const u8 *peer, u32 num_packets,
11173 u32 rate, u32 intvl, gfp_t gfp)
11174{
11175 struct wireless_dev *wdev = dev->ieee80211_ptr;
11176 struct wiphy *wiphy = wdev->wiphy;
11177 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
Thomas Pedersen84f10702012-07-12 16:17:33 -070011178 struct sk_buff *msg;
11179 struct nlattr *pinfoattr;
11180 void *hdr;
11181
11182 msg = nlmsg_new(NLMSG_GOODSIZE, gfp);
11183 if (!msg)
11184 return;
11185
11186 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM);
11187 if (!hdr) {
11188 nlmsg_free(msg);
11189 return;
11190 }
11191
11192 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg947add32013-02-22 22:05:20 +010011193 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
Thomas Pedersen84f10702012-07-12 16:17:33 -070011194 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer))
11195 goto nla_put_failure;
11196
11197 pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM);
11198 if (!pinfoattr)
11199 goto nla_put_failure;
11200
11201 if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_PKTS, num_packets))
11202 goto nla_put_failure;
11203
11204 if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_RATE, rate))
11205 goto nla_put_failure;
11206
11207 if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_INTVL, intvl))
11208 goto nla_put_failure;
11209
11210 nla_nest_end(msg, pinfoattr);
11211
11212 genlmsg_end(msg, hdr);
11213
Johannes Berg68eb5502013-11-19 15:19:38 +010011214 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011215 NL80211_MCGRP_MLME, gfp);
Thomas Pedersen84f10702012-07-12 16:17:33 -070011216 return;
11217
11218 nla_put_failure:
11219 genlmsg_cancel(msg, hdr);
11220 nlmsg_free(msg);
11221}
Johannes Berg947add32013-02-22 22:05:20 +010011222EXPORT_SYMBOL(cfg80211_cqm_txe_notify);
Thomas Pedersen84f10702012-07-12 16:17:33 -070011223
11224void
Simon Wunderlich04f39042013-02-08 18:16:19 +010011225nl80211_radar_notify(struct cfg80211_registered_device *rdev,
Janusz Dziedzicd2859df2013-11-06 13:55:51 +010011226 const struct cfg80211_chan_def *chandef,
Simon Wunderlich04f39042013-02-08 18:16:19 +010011227 enum nl80211_radar_event event,
11228 struct net_device *netdev, gfp_t gfp)
11229{
11230 struct sk_buff *msg;
11231 void *hdr;
11232
11233 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
11234 if (!msg)
11235 return;
11236
11237 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_RADAR_DETECT);
11238 if (!hdr) {
11239 nlmsg_free(msg);
11240 return;
11241 }
11242
11243 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx))
11244 goto nla_put_failure;
11245
11246 /* NOP and radar events don't need a netdev parameter */
11247 if (netdev) {
11248 struct wireless_dev *wdev = netdev->ieee80211_ptr;
11249
11250 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
11251 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)))
11252 goto nla_put_failure;
11253 }
11254
11255 if (nla_put_u32(msg, NL80211_ATTR_RADAR_EVENT, event))
11256 goto nla_put_failure;
11257
11258 if (nl80211_send_chandef(msg, chandef))
11259 goto nla_put_failure;
11260
Johannes Berg9c90a9f2013-06-04 12:46:03 +020011261 genlmsg_end(msg, hdr);
Simon Wunderlich04f39042013-02-08 18:16:19 +010011262
Johannes Berg68eb5502013-11-19 15:19:38 +010011263 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011264 NL80211_MCGRP_MLME, gfp);
Simon Wunderlich04f39042013-02-08 18:16:19 +010011265 return;
11266
11267 nla_put_failure:
11268 genlmsg_cancel(msg, hdr);
11269 nlmsg_free(msg);
11270}
11271
Johannes Berg947add32013-02-22 22:05:20 +010011272void cfg80211_cqm_pktloss_notify(struct net_device *dev,
11273 const u8 *peer, u32 num_packets, gfp_t gfp)
Johannes Bergc063dbf2010-11-24 08:10:05 +010011274{
Johannes Berg947add32013-02-22 22:05:20 +010011275 struct wireless_dev *wdev = dev->ieee80211_ptr;
11276 struct wiphy *wiphy = wdev->wiphy;
11277 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
Johannes Bergc063dbf2010-11-24 08:10:05 +010011278 struct sk_buff *msg;
11279 struct nlattr *pinfoattr;
11280 void *hdr;
11281
Johannes Berg947add32013-02-22 22:05:20 +010011282 trace_cfg80211_cqm_pktloss_notify(dev, peer, num_packets);
11283
Thomas Graf58050fc2012-06-28 03:57:45 +000011284 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Johannes Bergc063dbf2010-11-24 08:10:05 +010011285 if (!msg)
11286 return;
11287
11288 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM);
11289 if (!hdr) {
11290 nlmsg_free(msg);
11291 return;
11292 }
11293
David S. Miller9360ffd2012-03-29 04:41:26 -040011294 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg947add32013-02-22 22:05:20 +010011295 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040011296 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer))
11297 goto nla_put_failure;
Johannes Bergc063dbf2010-11-24 08:10:05 +010011298
11299 pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM);
11300 if (!pinfoattr)
11301 goto nla_put_failure;
11302
David S. Miller9360ffd2012-03-29 04:41:26 -040011303 if (nla_put_u32(msg, NL80211_ATTR_CQM_PKT_LOSS_EVENT, num_packets))
11304 goto nla_put_failure;
Johannes Bergc063dbf2010-11-24 08:10:05 +010011305
11306 nla_nest_end(msg, pinfoattr);
11307
Johannes Berg3b7b72e2011-10-22 19:05:51 +020011308 genlmsg_end(msg, hdr);
Johannes Bergc063dbf2010-11-24 08:10:05 +010011309
Johannes Berg68eb5502013-11-19 15:19:38 +010011310 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011311 NL80211_MCGRP_MLME, gfp);
Johannes Bergc063dbf2010-11-24 08:10:05 +010011312 return;
11313
11314 nla_put_failure:
11315 genlmsg_cancel(msg, hdr);
11316 nlmsg_free(msg);
11317}
Johannes Berg947add32013-02-22 22:05:20 +010011318EXPORT_SYMBOL(cfg80211_cqm_pktloss_notify);
Johannes Bergc063dbf2010-11-24 08:10:05 +010011319
Johannes Berg7f6cf312011-11-04 11:18:15 +010011320void cfg80211_probe_status(struct net_device *dev, const u8 *addr,
11321 u64 cookie, bool acked, gfp_t gfp)
11322{
11323 struct wireless_dev *wdev = dev->ieee80211_ptr;
11324 struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
11325 struct sk_buff *msg;
11326 void *hdr;
Johannes Berg7f6cf312011-11-04 11:18:15 +010011327
Beni Lev4ee3e062012-08-27 12:49:39 +030011328 trace_cfg80211_probe_status(dev, addr, cookie, acked);
11329
Thomas Graf58050fc2012-06-28 03:57:45 +000011330 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Beni Lev4ee3e062012-08-27 12:49:39 +030011331
Johannes Berg7f6cf312011-11-04 11:18:15 +010011332 if (!msg)
11333 return;
11334
11335 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PROBE_CLIENT);
11336 if (!hdr) {
11337 nlmsg_free(msg);
11338 return;
11339 }
11340
David S. Miller9360ffd2012-03-29 04:41:26 -040011341 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
11342 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
11343 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) ||
11344 nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie) ||
11345 (acked && nla_put_flag(msg, NL80211_ATTR_ACK)))
11346 goto nla_put_failure;
Johannes Berg7f6cf312011-11-04 11:18:15 +010011347
Johannes Berg9c90a9f2013-06-04 12:46:03 +020011348 genlmsg_end(msg, hdr);
Johannes Berg7f6cf312011-11-04 11:18:15 +010011349
Johannes Berg68eb5502013-11-19 15:19:38 +010011350 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011351 NL80211_MCGRP_MLME, gfp);
Johannes Berg7f6cf312011-11-04 11:18:15 +010011352 return;
11353
11354 nla_put_failure:
11355 genlmsg_cancel(msg, hdr);
11356 nlmsg_free(msg);
11357}
11358EXPORT_SYMBOL(cfg80211_probe_status);
11359
Johannes Berg5e760232011-11-04 11:18:17 +010011360void cfg80211_report_obss_beacon(struct wiphy *wiphy,
11361 const u8 *frame, size_t len,
Ben Greear37c73b52012-10-26 14:49:25 -070011362 int freq, int sig_dbm)
Johannes Berg5e760232011-11-04 11:18:17 +010011363{
11364 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
11365 struct sk_buff *msg;
11366 void *hdr;
Ben Greear37c73b52012-10-26 14:49:25 -070011367 struct cfg80211_beacon_registration *reg;
Johannes Berg5e760232011-11-04 11:18:17 +010011368
Beni Lev4ee3e062012-08-27 12:49:39 +030011369 trace_cfg80211_report_obss_beacon(wiphy, frame, len, freq, sig_dbm);
11370
Ben Greear37c73b52012-10-26 14:49:25 -070011371 spin_lock_bh(&rdev->beacon_registrations_lock);
11372 list_for_each_entry(reg, &rdev->beacon_registrations, list) {
11373 msg = nlmsg_new(len + 100, GFP_ATOMIC);
11374 if (!msg) {
11375 spin_unlock_bh(&rdev->beacon_registrations_lock);
11376 return;
11377 }
Johannes Berg5e760232011-11-04 11:18:17 +010011378
Ben Greear37c73b52012-10-26 14:49:25 -070011379 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME);
11380 if (!hdr)
11381 goto nla_put_failure;
Johannes Berg5e760232011-11-04 11:18:17 +010011382
Ben Greear37c73b52012-10-26 14:49:25 -070011383 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
11384 (freq &&
11385 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq)) ||
11386 (sig_dbm &&
11387 nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) ||
11388 nla_put(msg, NL80211_ATTR_FRAME, len, frame))
11389 goto nla_put_failure;
11390
11391 genlmsg_end(msg, hdr);
11392
11393 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, reg->nlportid);
Johannes Berg5e760232011-11-04 11:18:17 +010011394 }
Ben Greear37c73b52012-10-26 14:49:25 -070011395 spin_unlock_bh(&rdev->beacon_registrations_lock);
Johannes Berg5e760232011-11-04 11:18:17 +010011396 return;
11397
11398 nla_put_failure:
Ben Greear37c73b52012-10-26 14:49:25 -070011399 spin_unlock_bh(&rdev->beacon_registrations_lock);
11400 if (hdr)
11401 genlmsg_cancel(msg, hdr);
Johannes Berg5e760232011-11-04 11:18:17 +010011402 nlmsg_free(msg);
11403}
11404EXPORT_SYMBOL(cfg80211_report_obss_beacon);
11405
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010011406#ifdef CONFIG_PM
11407void cfg80211_report_wowlan_wakeup(struct wireless_dev *wdev,
11408 struct cfg80211_wowlan_wakeup *wakeup,
11409 gfp_t gfp)
11410{
11411 struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
11412 struct sk_buff *msg;
11413 void *hdr;
Johannes Berg9c90a9f2013-06-04 12:46:03 +020011414 int size = 200;
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010011415
11416 trace_cfg80211_report_wowlan_wakeup(wdev->wiphy, wdev, wakeup);
11417
11418 if (wakeup)
11419 size += wakeup->packet_present_len;
11420
11421 msg = nlmsg_new(size, gfp);
11422 if (!msg)
11423 return;
11424
11425 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_WOWLAN);
11426 if (!hdr)
11427 goto free_msg;
11428
11429 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
11430 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)))
11431 goto free_msg;
11432
11433 if (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
11434 wdev->netdev->ifindex))
11435 goto free_msg;
11436
11437 if (wakeup) {
11438 struct nlattr *reasons;
11439
11440 reasons = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS);
Johannes Berg7fa322c2013-10-25 11:16:58 +020011441 if (!reasons)
11442 goto free_msg;
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010011443
11444 if (wakeup->disconnect &&
11445 nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT))
11446 goto free_msg;
11447 if (wakeup->magic_pkt &&
11448 nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT))
11449 goto free_msg;
11450 if (wakeup->gtk_rekey_failure &&
11451 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE))
11452 goto free_msg;
11453 if (wakeup->eap_identity_req &&
11454 nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST))
11455 goto free_msg;
11456 if (wakeup->four_way_handshake &&
11457 nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE))
11458 goto free_msg;
11459 if (wakeup->rfkill_release &&
11460 nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE))
11461 goto free_msg;
11462
11463 if (wakeup->pattern_idx >= 0 &&
11464 nla_put_u32(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN,
11465 wakeup->pattern_idx))
11466 goto free_msg;
11467
Johannes Bergae917c92013-10-25 11:05:22 +020011468 if (wakeup->tcp_match &&
11469 nla_put_flag(msg, NL80211_WOWLAN_TRIG_WAKEUP_TCP_MATCH))
11470 goto free_msg;
Johannes Berg2a0e0472013-01-23 22:57:40 +010011471
Johannes Bergae917c92013-10-25 11:05:22 +020011472 if (wakeup->tcp_connlost &&
11473 nla_put_flag(msg, NL80211_WOWLAN_TRIG_WAKEUP_TCP_CONNLOST))
11474 goto free_msg;
Johannes Berg2a0e0472013-01-23 22:57:40 +010011475
Johannes Bergae917c92013-10-25 11:05:22 +020011476 if (wakeup->tcp_nomoretokens &&
11477 nla_put_flag(msg,
11478 NL80211_WOWLAN_TRIG_WAKEUP_TCP_NOMORETOKENS))
11479 goto free_msg;
Johannes Berg2a0e0472013-01-23 22:57:40 +010011480
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010011481 if (wakeup->packet) {
11482 u32 pkt_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211;
11483 u32 len_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211_LEN;
11484
11485 if (!wakeup->packet_80211) {
11486 pkt_attr =
11487 NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023;
11488 len_attr =
11489 NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023_LEN;
11490 }
11491
11492 if (wakeup->packet_len &&
11493 nla_put_u32(msg, len_attr, wakeup->packet_len))
11494 goto free_msg;
11495
11496 if (nla_put(msg, pkt_attr, wakeup->packet_present_len,
11497 wakeup->packet))
11498 goto free_msg;
11499 }
11500
11501 nla_nest_end(msg, reasons);
11502 }
11503
Johannes Berg9c90a9f2013-06-04 12:46:03 +020011504 genlmsg_end(msg, hdr);
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010011505
Johannes Berg68eb5502013-11-19 15:19:38 +010011506 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011507 NL80211_MCGRP_MLME, gfp);
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010011508 return;
11509
11510 free_msg:
11511 nlmsg_free(msg);
11512}
11513EXPORT_SYMBOL(cfg80211_report_wowlan_wakeup);
11514#endif
11515
Jouni Malinen3475b092012-11-16 22:49:57 +020011516void cfg80211_tdls_oper_request(struct net_device *dev, const u8 *peer,
11517 enum nl80211_tdls_operation oper,
11518 u16 reason_code, gfp_t gfp)
11519{
11520 struct wireless_dev *wdev = dev->ieee80211_ptr;
11521 struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
11522 struct sk_buff *msg;
11523 void *hdr;
Jouni Malinen3475b092012-11-16 22:49:57 +020011524
11525 trace_cfg80211_tdls_oper_request(wdev->wiphy, dev, peer, oper,
11526 reason_code);
11527
11528 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
11529 if (!msg)
11530 return;
11531
11532 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_TDLS_OPER);
11533 if (!hdr) {
11534 nlmsg_free(msg);
11535 return;
11536 }
11537
11538 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
11539 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
11540 nla_put_u8(msg, NL80211_ATTR_TDLS_OPERATION, oper) ||
11541 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer) ||
11542 (reason_code > 0 &&
11543 nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason_code)))
11544 goto nla_put_failure;
11545
Johannes Berg9c90a9f2013-06-04 12:46:03 +020011546 genlmsg_end(msg, hdr);
Jouni Malinen3475b092012-11-16 22:49:57 +020011547
Johannes Berg68eb5502013-11-19 15:19:38 +010011548 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011549 NL80211_MCGRP_MLME, gfp);
Jouni Malinen3475b092012-11-16 22:49:57 +020011550 return;
11551
11552 nla_put_failure:
11553 genlmsg_cancel(msg, hdr);
11554 nlmsg_free(msg);
11555}
11556EXPORT_SYMBOL(cfg80211_tdls_oper_request);
11557
Jouni Malinen026331c2010-02-15 12:53:10 +020011558static int nl80211_netlink_notify(struct notifier_block * nb,
11559 unsigned long state,
11560 void *_notify)
11561{
11562 struct netlink_notify *notify = _notify;
11563 struct cfg80211_registered_device *rdev;
11564 struct wireless_dev *wdev;
Ben Greear37c73b52012-10-26 14:49:25 -070011565 struct cfg80211_beacon_registration *reg, *tmp;
Jouni Malinen026331c2010-02-15 12:53:10 +020011566
11567 if (state != NETLINK_URELEASE)
11568 return NOTIFY_DONE;
11569
11570 rcu_read_lock();
11571
Johannes Berg5e760232011-11-04 11:18:17 +010011572 list_for_each_entry_rcu(rdev, &cfg80211_rdev_list, list) {
Johannes Berg89a54e42012-06-15 14:33:17 +020011573 list_for_each_entry_rcu(wdev, &rdev->wdev_list, list)
Eric W. Biederman15e47302012-09-07 20:12:54 +000011574 cfg80211_mlme_unregister_socket(wdev, notify->portid);
Ben Greear37c73b52012-10-26 14:49:25 -070011575
11576 spin_lock_bh(&rdev->beacon_registrations_lock);
11577 list_for_each_entry_safe(reg, tmp, &rdev->beacon_registrations,
11578 list) {
11579 if (reg->nlportid == notify->portid) {
11580 list_del(&reg->list);
11581 kfree(reg);
11582 break;
11583 }
11584 }
11585 spin_unlock_bh(&rdev->beacon_registrations_lock);
Johannes Berg5e760232011-11-04 11:18:17 +010011586 }
Jouni Malinen026331c2010-02-15 12:53:10 +020011587
11588 rcu_read_unlock();
11589
11590 return NOTIFY_DONE;
11591}
11592
11593static struct notifier_block nl80211_netlink_notifier = {
11594 .notifier_call = nl80211_netlink_notify,
11595};
11596
Jouni Malinen355199e2013-02-27 17:14:27 +020011597void cfg80211_ft_event(struct net_device *netdev,
11598 struct cfg80211_ft_event_params *ft_event)
11599{
11600 struct wiphy *wiphy = netdev->ieee80211_ptr->wiphy;
11601 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
11602 struct sk_buff *msg;
11603 void *hdr;
Jouni Malinen355199e2013-02-27 17:14:27 +020011604
11605 trace_cfg80211_ft_event(wiphy, netdev, ft_event);
11606
11607 if (!ft_event->target_ap)
11608 return;
11609
11610 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
11611 if (!msg)
11612 return;
11613
11614 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FT_EVENT);
Johannes Bergae917c92013-10-25 11:05:22 +020011615 if (!hdr)
11616 goto out;
Jouni Malinen355199e2013-02-27 17:14:27 +020011617
Johannes Bergae917c92013-10-25 11:05:22 +020011618 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
11619 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
11620 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, ft_event->target_ap))
11621 goto out;
11622
11623 if (ft_event->ies &&
11624 nla_put(msg, NL80211_ATTR_IE, ft_event->ies_len, ft_event->ies))
11625 goto out;
11626 if (ft_event->ric_ies &&
11627 nla_put(msg, NL80211_ATTR_IE_RIC, ft_event->ric_ies_len,
11628 ft_event->ric_ies))
11629 goto out;
Jouni Malinen355199e2013-02-27 17:14:27 +020011630
Johannes Berg9c90a9f2013-06-04 12:46:03 +020011631 genlmsg_end(msg, hdr);
Jouni Malinen355199e2013-02-27 17:14:27 +020011632
Johannes Berg68eb5502013-11-19 15:19:38 +010011633 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011634 NL80211_MCGRP_MLME, GFP_KERNEL);
Johannes Bergae917c92013-10-25 11:05:22 +020011635 return;
11636 out:
11637 nlmsg_free(msg);
Jouni Malinen355199e2013-02-27 17:14:27 +020011638}
11639EXPORT_SYMBOL(cfg80211_ft_event);
11640
Arend van Spriel5de17982013-04-18 15:49:00 +020011641void cfg80211_crit_proto_stopped(struct wireless_dev *wdev, gfp_t gfp)
11642{
11643 struct cfg80211_registered_device *rdev;
11644 struct sk_buff *msg;
11645 void *hdr;
11646 u32 nlportid;
11647
11648 rdev = wiphy_to_dev(wdev->wiphy);
11649 if (!rdev->crit_proto_nlportid)
11650 return;
11651
11652 nlportid = rdev->crit_proto_nlportid;
11653 rdev->crit_proto_nlportid = 0;
11654
11655 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
11656 if (!msg)
11657 return;
11658
11659 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CRIT_PROTOCOL_STOP);
11660 if (!hdr)
11661 goto nla_put_failure;
11662
11663 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
11664 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)))
11665 goto nla_put_failure;
11666
11667 genlmsg_end(msg, hdr);
11668
11669 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid);
11670 return;
11671
11672 nla_put_failure:
11673 if (hdr)
11674 genlmsg_cancel(msg, hdr);
11675 nlmsg_free(msg);
11676
11677}
11678EXPORT_SYMBOL(cfg80211_crit_proto_stopped);
11679
Johannes Berg55682962007-09-20 13:09:35 -040011680/* initialisation/exit functions */
11681
11682int nl80211_init(void)
11683{
Michał Mirosław0d63cbb2009-05-21 10:34:06 +000011684 int err;
Johannes Berg55682962007-09-20 13:09:35 -040011685
Johannes Berg2a94fe42013-11-19 15:19:39 +010011686 err = genl_register_family_with_ops_groups(&nl80211_fam, nl80211_ops,
11687 nl80211_mcgrps);
Johannes Berg55682962007-09-20 13:09:35 -040011688 if (err)
11689 return err;
11690
Jouni Malinen026331c2010-02-15 12:53:10 +020011691 err = netlink_register_notifier(&nl80211_netlink_notifier);
11692 if (err)
11693 goto err_out;
11694
Johannes Berg55682962007-09-20 13:09:35 -040011695 return 0;
11696 err_out:
11697 genl_unregister_family(&nl80211_fam);
11698 return err;
11699}
11700
11701void nl80211_exit(void)
11702{
Jouni Malinen026331c2010-02-15 12:53:10 +020011703 netlink_unregister_notifier(&nl80211_netlink_notifier);
Johannes Berg55682962007-09-20 13:09:35 -040011704 genl_unregister_family(&nl80211_fam);
11705}