blob: 6e7d580ec645b22099ece3f83b0d30e1c2e6ffcb [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 Malinendc6382c2009-05-06 22:09:37 +0300290 [NL80211_ATTR_USE_MFP] = { .type = NLA_U32 },
Johannes Bergeccb8e82009-05-11 21:57:56 +0300291 [NL80211_ATTR_STA_FLAGS2] = {
292 .len = sizeof(struct nl80211_sta_flag_update),
293 },
Jouni Malinen3f77316c2009-05-11 21:57:57 +0300294 [NL80211_ATTR_CONTROL_PORT] = { .type = NLA_FLAG },
Johannes Bergc0692b82010-08-27 14:26:53 +0300295 [NL80211_ATTR_CONTROL_PORT_ETHERTYPE] = { .type = NLA_U16 },
296 [NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT] = { .type = NLA_FLAG },
Samuel Ortizb23aa672009-07-01 21:26:54 +0200297 [NL80211_ATTR_PRIVACY] = { .type = NLA_FLAG },
298 [NL80211_ATTR_CIPHER_SUITE_GROUP] = { .type = NLA_U32 },
299 [NL80211_ATTR_WPA_VERSIONS] = { .type = NLA_U32 },
Johannes Berg463d0182009-07-14 00:33:35 +0200300 [NL80211_ATTR_PID] = { .type = NLA_U32 },
Felix Fietkau8b787642009-11-10 18:53:10 +0100301 [NL80211_ATTR_4ADDR] = { .type = NLA_U8 },
Samuel Ortiz67fbb162009-11-24 23:59:15 +0100302 [NL80211_ATTR_PMKID] = { .type = NLA_BINARY,
303 .len = WLAN_PMKID_LEN },
Jouni Malinen9588bbd2009-12-23 13:15:41 +0100304 [NL80211_ATTR_DURATION] = { .type = NLA_U32 },
305 [NL80211_ATTR_COOKIE] = { .type = NLA_U64 },
Jouni Malinen13ae75b2009-12-29 12:59:45 +0200306 [NL80211_ATTR_TX_RATES] = { .type = NLA_NESTED },
Jouni Malinen026331c2010-02-15 12:53:10 +0200307 [NL80211_ATTR_FRAME] = { .type = NLA_BINARY,
308 .len = IEEE80211_MAX_DATA_LEN },
309 [NL80211_ATTR_FRAME_MATCH] = { .type = NLA_BINARY, },
Kalle Valoffb9eb32010-02-17 17:58:10 +0200310 [NL80211_ATTR_PS_STATE] = { .type = NLA_U32 },
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +0200311 [NL80211_ATTR_CQM] = { .type = NLA_NESTED, },
Jouni Malinend5cdfac2010-04-04 09:37:19 +0300312 [NL80211_ATTR_LOCAL_STATE_CHANGE] = { .type = NLA_FLAG },
Felix Fietkaufd8aaaf2010-04-27 01:23:35 +0200313 [NL80211_ATTR_AP_ISOLATE] = { .type = NLA_U8 },
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +0300314 [NL80211_ATTR_WIPHY_TX_POWER_SETTING] = { .type = NLA_U32 },
315 [NL80211_ATTR_WIPHY_TX_POWER_LEVEL] = { .type = NLA_U32 },
Johannes Berg2e161f72010-08-12 15:38:38 +0200316 [NL80211_ATTR_FRAME_TYPE] = { .type = NLA_U16 },
Bruno Randolfafe0cbf2010-11-10 12:50:50 +0900317 [NL80211_ATTR_WIPHY_ANTENNA_TX] = { .type = NLA_U32 },
318 [NL80211_ATTR_WIPHY_ANTENNA_RX] = { .type = NLA_U32 },
Felix Fietkau885a46d2010-11-11 15:07:22 +0100319 [NL80211_ATTR_MCAST_RATE] = { .type = NLA_U32 },
Johannes Bergf7ca38d2010-11-25 10:02:29 +0100320 [NL80211_ATTR_OFFCHANNEL_TX_OK] = { .type = NLA_FLAG },
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100321 [NL80211_ATTR_KEY_DEFAULT_TYPES] = { .type = NLA_NESTED },
Johannes Bergff1b6e62011-05-04 15:37:28 +0200322 [NL80211_ATTR_WOWLAN_TRIGGERS] = { .type = NLA_NESTED },
Javier Cardona9c3990a2011-05-03 16:57:11 -0700323 [NL80211_ATTR_STA_PLINK_STATE] = { .type = NLA_U8 },
Luciano Coelhobbe6ad62011-05-11 17:09:37 +0300324 [NL80211_ATTR_SCHED_SCAN_INTERVAL] = { .type = NLA_U32 },
Johannes Berge5497d72011-07-05 16:35:40 +0200325 [NL80211_ATTR_REKEY_DATA] = { .type = NLA_NESTED },
Johannes Berg34850ab2011-07-18 18:08:35 +0200326 [NL80211_ATTR_SCAN_SUPP_RATES] = { .type = NLA_NESTED },
Jouni Malinen32e9de82011-08-10 23:53:31 +0300327 [NL80211_ATTR_HIDDEN_SSID] = { .type = NLA_U32 },
Jouni Malinen9946ecf2011-08-10 23:55:56 +0300328 [NL80211_ATTR_IE_PROBE_RESP] = { .type = NLA_BINARY,
329 .len = IEEE80211_MAX_DATA_LEN },
330 [NL80211_ATTR_IE_ASSOC_RESP] = { .type = NLA_BINARY,
331 .len = IEEE80211_MAX_DATA_LEN },
Vivek Natarajanf4b34b52011-08-29 14:23:03 +0530332 [NL80211_ATTR_ROAM_SUPPORT] = { .type = NLA_FLAG },
Luciano Coelhoa1f1c212011-08-31 16:01:48 +0300333 [NL80211_ATTR_SCHED_SCAN_MATCH] = { .type = NLA_NESTED },
Rajkumar Manoharane9f935e2011-09-25 14:53:30 +0530334 [NL80211_ATTR_TX_NO_CCK_RATE] = { .type = NLA_FLAG },
Arik Nemtsov109086c2011-09-28 14:12:50 +0300335 [NL80211_ATTR_TDLS_ACTION] = { .type = NLA_U8 },
336 [NL80211_ATTR_TDLS_DIALOG_TOKEN] = { .type = NLA_U8 },
337 [NL80211_ATTR_TDLS_OPERATION] = { .type = NLA_U8 },
338 [NL80211_ATTR_TDLS_SUPPORT] = { .type = NLA_FLAG },
339 [NL80211_ATTR_TDLS_EXTERNAL_SETUP] = { .type = NLA_FLAG },
Johannes Berge247bd902011-11-04 11:18:21 +0100340 [NL80211_ATTR_DONT_WAIT_FOR_ACK] = { .type = NLA_FLAG },
Arik Nemtsov00f740e2011-11-10 11:28:56 +0200341 [NL80211_ATTR_PROBE_RESP] = { .type = NLA_BINARY,
342 .len = IEEE80211_MAX_DATA_LEN },
Luis R. Rodriguez8b60b072011-10-11 10:59:02 -0700343 [NL80211_ATTR_DFS_REGION] = { .type = NLA_U8 },
Ben Greear7e7c8922011-11-18 11:31:59 -0800344 [NL80211_ATTR_DISABLE_HT] = { .type = NLA_FLAG },
345 [NL80211_ATTR_HT_CAPABILITY_MASK] = {
346 .len = NL80211_HT_CAPABILITY_LEN
347 },
Simon Wunderlich1d9d9212011-11-18 14:20:43 +0100348 [NL80211_ATTR_NOACK_MAP] = { .type = NLA_U16 },
Vasanthakumar Thiagarajan1b658f12012-03-02 15:50:02 +0530349 [NL80211_ATTR_INACTIVITY_TIMEOUT] = { .type = NLA_U16 },
Bala Shanmugam4486ea92012-03-07 17:27:12 +0530350 [NL80211_ATTR_BG_SCAN_PERIOD] = { .type = NLA_U16 },
Johannes Berg89a54e42012-06-15 14:33:17 +0200351 [NL80211_ATTR_WDEV] = { .type = NLA_U64 },
Luis R. Rodriguez57b5ce02012-07-12 11:49:18 -0700352 [NL80211_ATTR_USER_REG_HINT_TYPE] = { .type = NLA_U32 },
Jouni Malinene39e5b52012-09-30 19:29:39 +0300353 [NL80211_ATTR_SAE_DATA] = { .type = NLA_BINARY, },
Mahesh Palivelaf461be3e2012-10-11 08:04:52 +0000354 [NL80211_ATTR_VHT_CAPABILITY] = { .len = NL80211_VHT_CAPABILITY_LEN },
Sam Lefflered4737712012-10-11 21:03:31 -0700355 [NL80211_ATTR_SCAN_FLAGS] = { .type = NLA_U32 },
Johannes Berg53cabad2012-11-14 15:17:28 +0100356 [NL80211_ATTR_P2P_CTWINDOW] = { .type = NLA_U8 },
357 [NL80211_ATTR_P2P_OPPPS] = { .type = NLA_U8 },
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +0530358 [NL80211_ATTR_ACL_POLICY] = {. type = NLA_U32 },
359 [NL80211_ATTR_MAC_ADDRS] = { .type = NLA_NESTED },
Jouni Malinen9d62a982013-02-14 21:10:13 +0200360 [NL80211_ATTR_STA_CAPABILITY] = { .type = NLA_U16 },
361 [NL80211_ATTR_STA_EXT_CAPABILITY] = { .type = NLA_BINARY, },
Johannes Berg3713b4e2013-02-14 16:19:38 +0100362 [NL80211_ATTR_SPLIT_WIPHY_DUMP] = { .type = NLA_FLAG, },
Johannes Bergee2aca32013-02-21 17:36:01 +0100363 [NL80211_ATTR_DISABLE_VHT] = { .type = NLA_FLAG },
364 [NL80211_ATTR_VHT_CAPABILITY_MASK] = {
365 .len = NL80211_VHT_CAPABILITY_LEN,
366 },
Jouni Malinen355199e2013-02-27 17:14:27 +0200367 [NL80211_ATTR_MDID] = { .type = NLA_U16 },
368 [NL80211_ATTR_IE_RIC] = { .type = NLA_BINARY,
369 .len = IEEE80211_MAX_DATA_LEN },
Jouni Malinen5e4b6f52013-05-16 20:11:08 +0300370 [NL80211_ATTR_PEER_AID] = { .type = NLA_U16 },
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +0200371 [NL80211_ATTR_CH_SWITCH_COUNT] = { .type = NLA_U32 },
372 [NL80211_ATTR_CH_SWITCH_BLOCK_TX] = { .type = NLA_FLAG },
373 [NL80211_ATTR_CSA_IES] = { .type = NLA_NESTED },
374 [NL80211_ATTR_CSA_C_OFF_BEACON] = { .type = NLA_U16 },
375 [NL80211_ATTR_CSA_C_OFF_PRESP] = { .type = NLA_U16 },
Sunil Duttc01fc9a2013-10-09 20:45:21 +0530376 [NL80211_ATTR_STA_SUPPORTED_CHANNELS] = { .type = NLA_BINARY },
377 [NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES] = { .type = NLA_BINARY },
Simon Wunderlich5336fa82013-10-07 18:41:05 +0200378 [NL80211_ATTR_HANDLE_DFS] = { .type = NLA_FLAG },
Marek Kwaczynski60f4a7b2013-12-03 10:04:59 +0100379 [NL80211_ATTR_OPMODE_NOTIF] = { .type = NLA_U8 },
Johannes Bergad7e7182013-11-13 13:37:47 +0100380 [NL80211_ATTR_VENDOR_ID] = { .type = NLA_U32 },
381 [NL80211_ATTR_VENDOR_SUBCMD] = { .type = NLA_U32 },
382 [NL80211_ATTR_VENDOR_DATA] = { .type = NLA_BINARY },
Kyeyoon Parkfa9ffc72013-12-16 23:01:30 -0800383 [NL80211_ATTR_QOS_MAP] = { .type = NLA_BINARY,
384 .len = IEEE80211_QOS_MAP_LEN_MAX },
Jouni Malinen1df4a512014-01-15 00:00:47 +0200385 [NL80211_ATTR_MAC_HINT] = { .len = ETH_ALEN },
386 [NL80211_ATTR_WIPHY_FREQ_HINT] = { .type = NLA_U32 },
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
Johannes Berg7527a782011-05-13 10:58:57 +0200860static int nl80211_put_iftypes(struct sk_buff *msg, u32 attr, u16 ifmodes)
861{
862 struct nlattr *nl_modes = nla_nest_start(msg, attr);
863 int i;
864
865 if (!nl_modes)
866 goto nla_put_failure;
867
868 i = 0;
869 while (ifmodes) {
David S. Miller9360ffd2012-03-29 04:41:26 -0400870 if ((ifmodes & 1) && nla_put_flag(msg, i))
871 goto nla_put_failure;
Johannes Berg7527a782011-05-13 10:58:57 +0200872 ifmodes >>= 1;
873 i++;
874 }
875
876 nla_nest_end(msg, nl_modes);
877 return 0;
878
879nla_put_failure:
880 return -ENOBUFS;
881}
882
883static int nl80211_put_iface_combinations(struct wiphy *wiphy,
Johannes Bergcdc89b92013-02-18 23:54:36 +0100884 struct sk_buff *msg,
885 bool large)
Johannes Berg7527a782011-05-13 10:58:57 +0200886{
887 struct nlattr *nl_combis;
888 int i, j;
889
890 nl_combis = nla_nest_start(msg,
891 NL80211_ATTR_INTERFACE_COMBINATIONS);
892 if (!nl_combis)
893 goto nla_put_failure;
894
895 for (i = 0; i < wiphy->n_iface_combinations; i++) {
896 const struct ieee80211_iface_combination *c;
897 struct nlattr *nl_combi, *nl_limits;
898
899 c = &wiphy->iface_combinations[i];
900
901 nl_combi = nla_nest_start(msg, i + 1);
902 if (!nl_combi)
903 goto nla_put_failure;
904
905 nl_limits = nla_nest_start(msg, NL80211_IFACE_COMB_LIMITS);
906 if (!nl_limits)
907 goto nla_put_failure;
908
909 for (j = 0; j < c->n_limits; j++) {
910 struct nlattr *nl_limit;
911
912 nl_limit = nla_nest_start(msg, j + 1);
913 if (!nl_limit)
914 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -0400915 if (nla_put_u32(msg, NL80211_IFACE_LIMIT_MAX,
916 c->limits[j].max))
917 goto nla_put_failure;
Johannes Berg7527a782011-05-13 10:58:57 +0200918 if (nl80211_put_iftypes(msg, NL80211_IFACE_LIMIT_TYPES,
919 c->limits[j].types))
920 goto nla_put_failure;
921 nla_nest_end(msg, nl_limit);
922 }
923
924 nla_nest_end(msg, nl_limits);
925
David S. Miller9360ffd2012-03-29 04:41:26 -0400926 if (c->beacon_int_infra_match &&
927 nla_put_flag(msg, NL80211_IFACE_COMB_STA_AP_BI_MATCH))
928 goto nla_put_failure;
929 if (nla_put_u32(msg, NL80211_IFACE_COMB_NUM_CHANNELS,
930 c->num_different_channels) ||
931 nla_put_u32(msg, NL80211_IFACE_COMB_MAXNUM,
932 c->max_interfaces))
933 goto nla_put_failure;
Johannes Bergcdc89b92013-02-18 23:54:36 +0100934 if (large &&
935 nla_put_u32(msg, NL80211_IFACE_COMB_RADAR_DETECT_WIDTHS,
936 c->radar_detect_widths))
937 goto nla_put_failure;
Johannes Berg7527a782011-05-13 10:58:57 +0200938
939 nla_nest_end(msg, nl_combi);
940 }
941
942 nla_nest_end(msg, nl_combis);
943
944 return 0;
945nla_put_failure:
946 return -ENOBUFS;
947}
948
Johannes Berg3713b4e2013-02-14 16:19:38 +0100949#ifdef CONFIG_PM
Johannes Bergb56cf722013-02-20 01:02:38 +0100950static int nl80211_send_wowlan_tcp_caps(struct cfg80211_registered_device *rdev,
951 struct sk_buff *msg)
952{
Johannes Berg964dc9e2013-06-03 17:25:34 +0200953 const struct wiphy_wowlan_tcp_support *tcp = rdev->wiphy.wowlan->tcp;
Johannes Bergb56cf722013-02-20 01:02:38 +0100954 struct nlattr *nl_tcp;
955
956 if (!tcp)
957 return 0;
958
959 nl_tcp = nla_nest_start(msg, NL80211_WOWLAN_TRIG_TCP_CONNECTION);
960 if (!nl_tcp)
961 return -ENOBUFS;
962
963 if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD,
964 tcp->data_payload_max))
965 return -ENOBUFS;
966
967 if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD,
968 tcp->data_payload_max))
969 return -ENOBUFS;
970
971 if (tcp->seq && nla_put_flag(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ))
972 return -ENOBUFS;
973
974 if (tcp->tok && nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN,
975 sizeof(*tcp->tok), tcp->tok))
976 return -ENOBUFS;
977
978 if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_INTERVAL,
979 tcp->data_interval_max))
980 return -ENOBUFS;
981
982 if (nla_put_u32(msg, NL80211_WOWLAN_TCP_WAKE_PAYLOAD,
983 tcp->wake_payload_max))
984 return -ENOBUFS;
985
986 nla_nest_end(msg, nl_tcp);
987 return 0;
988}
989
Johannes Berg3713b4e2013-02-14 16:19:38 +0100990static int nl80211_send_wowlan(struct sk_buff *msg,
Johannes Bergb56cf722013-02-20 01:02:38 +0100991 struct cfg80211_registered_device *dev,
992 bool large)
Johannes Berg3713b4e2013-02-14 16:19:38 +0100993{
994 struct nlattr *nl_wowlan;
995
Johannes Berg964dc9e2013-06-03 17:25:34 +0200996 if (!dev->wiphy.wowlan)
Johannes Berg3713b4e2013-02-14 16:19:38 +0100997 return 0;
998
999 nl_wowlan = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS_SUPPORTED);
1000 if (!nl_wowlan)
1001 return -ENOBUFS;
1002
Johannes Berg964dc9e2013-06-03 17:25:34 +02001003 if (((dev->wiphy.wowlan->flags & WIPHY_WOWLAN_ANY) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001004 nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) ||
Johannes Berg964dc9e2013-06-03 17:25:34 +02001005 ((dev->wiphy.wowlan->flags & WIPHY_WOWLAN_DISCONNECT) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001006 nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) ||
Johannes Berg964dc9e2013-06-03 17:25:34 +02001007 ((dev->wiphy.wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001008 nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) ||
Johannes Berg964dc9e2013-06-03 17:25:34 +02001009 ((dev->wiphy.wowlan->flags & WIPHY_WOWLAN_SUPPORTS_GTK_REKEY) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001010 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED)) ||
Johannes Berg964dc9e2013-06-03 17:25:34 +02001011 ((dev->wiphy.wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001012 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) ||
Johannes Berg964dc9e2013-06-03 17:25:34 +02001013 ((dev->wiphy.wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001014 nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) ||
Johannes Berg964dc9e2013-06-03 17:25:34 +02001015 ((dev->wiphy.wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001016 nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) ||
Johannes Berg964dc9e2013-06-03 17:25:34 +02001017 ((dev->wiphy.wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001018 nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE)))
1019 return -ENOBUFS;
1020
Johannes Berg964dc9e2013-06-03 17:25:34 +02001021 if (dev->wiphy.wowlan->n_patterns) {
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07001022 struct nl80211_pattern_support pat = {
Johannes Berg964dc9e2013-06-03 17:25:34 +02001023 .max_patterns = dev->wiphy.wowlan->n_patterns,
1024 .min_pattern_len = dev->wiphy.wowlan->pattern_min_len,
1025 .max_pattern_len = dev->wiphy.wowlan->pattern_max_len,
1026 .max_pkt_offset = dev->wiphy.wowlan->max_pkt_offset,
Johannes Berg3713b4e2013-02-14 16:19:38 +01001027 };
1028
1029 if (nla_put(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN,
1030 sizeof(pat), &pat))
1031 return -ENOBUFS;
1032 }
1033
Johannes Bergb56cf722013-02-20 01:02:38 +01001034 if (large && nl80211_send_wowlan_tcp_caps(dev, msg))
1035 return -ENOBUFS;
1036
Johannes Berg3713b4e2013-02-14 16:19:38 +01001037 nla_nest_end(msg, nl_wowlan);
1038
1039 return 0;
1040}
1041#endif
1042
Amitkumar Karwarbe29b992013-06-28 11:51:26 -07001043static int nl80211_send_coalesce(struct sk_buff *msg,
1044 struct cfg80211_registered_device *dev)
1045{
1046 struct nl80211_coalesce_rule_support rule;
1047
1048 if (!dev->wiphy.coalesce)
1049 return 0;
1050
1051 rule.max_rules = dev->wiphy.coalesce->n_rules;
1052 rule.max_delay = dev->wiphy.coalesce->max_delay;
1053 rule.pat.max_patterns = dev->wiphy.coalesce->n_patterns;
1054 rule.pat.min_pattern_len = dev->wiphy.coalesce->pattern_min_len;
1055 rule.pat.max_pattern_len = dev->wiphy.coalesce->pattern_max_len;
1056 rule.pat.max_pkt_offset = dev->wiphy.coalesce->max_pkt_offset;
1057
1058 if (nla_put(msg, NL80211_ATTR_COALESCE_RULE, sizeof(rule), &rule))
1059 return -ENOBUFS;
1060
1061 return 0;
1062}
1063
Johannes Berg3713b4e2013-02-14 16:19:38 +01001064static int nl80211_send_band_rateinfo(struct sk_buff *msg,
1065 struct ieee80211_supported_band *sband)
1066{
1067 struct nlattr *nl_rates, *nl_rate;
1068 struct ieee80211_rate *rate;
1069 int i;
1070
1071 /* add HT info */
1072 if (sband->ht_cap.ht_supported &&
1073 (nla_put(msg, NL80211_BAND_ATTR_HT_MCS_SET,
1074 sizeof(sband->ht_cap.mcs),
1075 &sband->ht_cap.mcs) ||
1076 nla_put_u16(msg, NL80211_BAND_ATTR_HT_CAPA,
1077 sband->ht_cap.cap) ||
1078 nla_put_u8(msg, NL80211_BAND_ATTR_HT_AMPDU_FACTOR,
1079 sband->ht_cap.ampdu_factor) ||
1080 nla_put_u8(msg, NL80211_BAND_ATTR_HT_AMPDU_DENSITY,
1081 sband->ht_cap.ampdu_density)))
1082 return -ENOBUFS;
1083
1084 /* add VHT info */
1085 if (sband->vht_cap.vht_supported &&
1086 (nla_put(msg, NL80211_BAND_ATTR_VHT_MCS_SET,
1087 sizeof(sband->vht_cap.vht_mcs),
1088 &sband->vht_cap.vht_mcs) ||
1089 nla_put_u32(msg, NL80211_BAND_ATTR_VHT_CAPA,
1090 sband->vht_cap.cap)))
1091 return -ENOBUFS;
1092
1093 /* add bitrates */
1094 nl_rates = nla_nest_start(msg, NL80211_BAND_ATTR_RATES);
1095 if (!nl_rates)
1096 return -ENOBUFS;
1097
1098 for (i = 0; i < sband->n_bitrates; i++) {
1099 nl_rate = nla_nest_start(msg, i);
1100 if (!nl_rate)
1101 return -ENOBUFS;
1102
1103 rate = &sband->bitrates[i];
1104 if (nla_put_u32(msg, NL80211_BITRATE_ATTR_RATE,
1105 rate->bitrate))
1106 return -ENOBUFS;
1107 if ((rate->flags & IEEE80211_RATE_SHORT_PREAMBLE) &&
1108 nla_put_flag(msg,
1109 NL80211_BITRATE_ATTR_2GHZ_SHORTPREAMBLE))
1110 return -ENOBUFS;
1111
1112 nla_nest_end(msg, nl_rate);
1113 }
1114
1115 nla_nest_end(msg, nl_rates);
1116
1117 return 0;
1118}
1119
1120static int
1121nl80211_send_mgmt_stypes(struct sk_buff *msg,
1122 const struct ieee80211_txrx_stypes *mgmt_stypes)
1123{
1124 u16 stypes;
1125 struct nlattr *nl_ftypes, *nl_ifs;
1126 enum nl80211_iftype ift;
1127 int i;
1128
1129 if (!mgmt_stypes)
1130 return 0;
1131
1132 nl_ifs = nla_nest_start(msg, NL80211_ATTR_TX_FRAME_TYPES);
1133 if (!nl_ifs)
1134 return -ENOBUFS;
1135
1136 for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) {
1137 nl_ftypes = nla_nest_start(msg, ift);
1138 if (!nl_ftypes)
1139 return -ENOBUFS;
1140 i = 0;
1141 stypes = mgmt_stypes[ift].tx;
1142 while (stypes) {
1143 if ((stypes & 1) &&
1144 nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE,
1145 (i << 4) | IEEE80211_FTYPE_MGMT))
1146 return -ENOBUFS;
1147 stypes >>= 1;
1148 i++;
1149 }
1150 nla_nest_end(msg, nl_ftypes);
1151 }
1152
1153 nla_nest_end(msg, nl_ifs);
1154
1155 nl_ifs = nla_nest_start(msg, NL80211_ATTR_RX_FRAME_TYPES);
1156 if (!nl_ifs)
1157 return -ENOBUFS;
1158
1159 for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) {
1160 nl_ftypes = nla_nest_start(msg, ift);
1161 if (!nl_ftypes)
1162 return -ENOBUFS;
1163 i = 0;
1164 stypes = mgmt_stypes[ift].rx;
1165 while (stypes) {
1166 if ((stypes & 1) &&
1167 nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE,
1168 (i << 4) | IEEE80211_FTYPE_MGMT))
1169 return -ENOBUFS;
1170 stypes >>= 1;
1171 i++;
1172 }
1173 nla_nest_end(msg, nl_ftypes);
1174 }
1175 nla_nest_end(msg, nl_ifs);
1176
1177 return 0;
1178}
1179
Johannes Berg86e8cf92013-06-19 10:57:22 +02001180struct nl80211_dump_wiphy_state {
1181 s64 filter_wiphy;
1182 long start;
1183 long split_start, band_start, chan_start;
1184 bool split;
1185};
1186
Johannes Berg3713b4e2013-02-14 16:19:38 +01001187static int nl80211_send_wiphy(struct cfg80211_registered_device *dev,
1188 struct sk_buff *msg, u32 portid, u32 seq,
Johannes Berg86e8cf92013-06-19 10:57:22 +02001189 int flags, struct nl80211_dump_wiphy_state *state)
Johannes Berg55682962007-09-20 13:09:35 -04001190{
1191 void *hdr;
Johannes Bergee688b002008-01-24 19:38:39 +01001192 struct nlattr *nl_bands, *nl_band;
1193 struct nlattr *nl_freqs, *nl_freq;
Johannes Berg8fdc6212009-03-14 09:34:01 +01001194 struct nlattr *nl_cmds;
Johannes Bergee688b002008-01-24 19:38:39 +01001195 enum ieee80211_band band;
1196 struct ieee80211_channel *chan;
Johannes Bergee688b002008-01-24 19:38:39 +01001197 int i;
Johannes Berg2e161f72010-08-12 15:38:38 +02001198 const struct ieee80211_txrx_stypes *mgmt_stypes =
1199 dev->wiphy.mgmt_stypes;
Johannes Bergfe1abaf2013-02-27 15:39:45 +01001200 u32 features;
Johannes Berg55682962007-09-20 13:09:35 -04001201
Eric W. Biederman15e47302012-09-07 20:12:54 +00001202 hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_WIPHY);
Johannes Berg55682962007-09-20 13:09:35 -04001203 if (!hdr)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001204 return -ENOBUFS;
1205
Johannes Berg86e8cf92013-06-19 10:57:22 +02001206 if (WARN_ON(!state))
1207 return -EINVAL;
Johannes Berg55682962007-09-20 13:09:35 -04001208
David S. Miller9360ffd2012-03-29 04:41:26 -04001209 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, dev->wiphy_idx) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001210 nla_put_string(msg, NL80211_ATTR_WIPHY_NAME,
1211 wiphy_name(&dev->wiphy)) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04001212 nla_put_u32(msg, NL80211_ATTR_GENERATION,
Johannes Berg3713b4e2013-02-14 16:19:38 +01001213 cfg80211_rdev_list_generation))
David S. Miller9360ffd2012-03-29 04:41:26 -04001214 goto nla_put_failure;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02001215
Johannes Berg86e8cf92013-06-19 10:57:22 +02001216 switch (state->split_start) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001217 case 0:
1218 if (nla_put_u8(msg, NL80211_ATTR_WIPHY_RETRY_SHORT,
1219 dev->wiphy.retry_short) ||
1220 nla_put_u8(msg, NL80211_ATTR_WIPHY_RETRY_LONG,
1221 dev->wiphy.retry_long) ||
1222 nla_put_u32(msg, NL80211_ATTR_WIPHY_FRAG_THRESHOLD,
1223 dev->wiphy.frag_threshold) ||
1224 nla_put_u32(msg, NL80211_ATTR_WIPHY_RTS_THRESHOLD,
1225 dev->wiphy.rts_threshold) ||
1226 nla_put_u8(msg, NL80211_ATTR_WIPHY_COVERAGE_CLASS,
1227 dev->wiphy.coverage_class) ||
1228 nla_put_u8(msg, NL80211_ATTR_MAX_NUM_SCAN_SSIDS,
1229 dev->wiphy.max_scan_ssids) ||
1230 nla_put_u8(msg, NL80211_ATTR_MAX_NUM_SCHED_SCAN_SSIDS,
1231 dev->wiphy.max_sched_scan_ssids) ||
1232 nla_put_u16(msg, NL80211_ATTR_MAX_SCAN_IE_LEN,
1233 dev->wiphy.max_scan_ie_len) ||
1234 nla_put_u16(msg, NL80211_ATTR_MAX_SCHED_SCAN_IE_LEN,
1235 dev->wiphy.max_sched_scan_ie_len) ||
1236 nla_put_u8(msg, NL80211_ATTR_MAX_MATCH_SETS,
1237 dev->wiphy.max_match_sets))
Johannes Bergee688b002008-01-24 19:38:39 +01001238 goto nla_put_failure;
1239
Johannes Berg3713b4e2013-02-14 16:19:38 +01001240 if ((dev->wiphy.flags & WIPHY_FLAG_IBSS_RSN) &&
1241 nla_put_flag(msg, NL80211_ATTR_SUPPORT_IBSS_RSN))
1242 goto nla_put_failure;
1243 if ((dev->wiphy.flags & WIPHY_FLAG_MESH_AUTH) &&
1244 nla_put_flag(msg, NL80211_ATTR_SUPPORT_MESH_AUTH))
1245 goto nla_put_failure;
1246 if ((dev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) &&
1247 nla_put_flag(msg, NL80211_ATTR_SUPPORT_AP_UAPSD))
1248 goto nla_put_failure;
1249 if ((dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_FW_ROAM) &&
1250 nla_put_flag(msg, NL80211_ATTR_ROAM_SUPPORT))
1251 goto nla_put_failure;
1252 if ((dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) &&
1253 nla_put_flag(msg, NL80211_ATTR_TDLS_SUPPORT))
1254 goto nla_put_failure;
1255 if ((dev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP) &&
1256 nla_put_flag(msg, NL80211_ATTR_TDLS_EXTERNAL_SETUP))
David S. Miller9360ffd2012-03-29 04:41:26 -04001257 goto nla_put_failure;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001258 state->split_start++;
1259 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001260 break;
1261 case 1:
1262 if (nla_put(msg, NL80211_ATTR_CIPHER_SUITES,
1263 sizeof(u32) * dev->wiphy.n_cipher_suites,
1264 dev->wiphy.cipher_suites))
Mahesh Palivelabf0c111e2012-06-22 07:27:46 +00001265 goto nla_put_failure;
1266
Johannes Berg3713b4e2013-02-14 16:19:38 +01001267 if (nla_put_u8(msg, NL80211_ATTR_MAX_NUM_PMKIDS,
1268 dev->wiphy.max_num_pmkids))
Johannes Bergee688b002008-01-24 19:38:39 +01001269 goto nla_put_failure;
1270
Johannes Berg3713b4e2013-02-14 16:19:38 +01001271 if ((dev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) &&
1272 nla_put_flag(msg, NL80211_ATTR_CONTROL_PORT_ETHERTYPE))
1273 goto nla_put_failure;
Johannes Bergee688b002008-01-24 19:38:39 +01001274
Johannes Berg3713b4e2013-02-14 16:19:38 +01001275 if (nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_TX,
1276 dev->wiphy.available_antennas_tx) ||
1277 nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_RX,
1278 dev->wiphy.available_antennas_rx))
1279 goto nla_put_failure;
Johannes Bergee688b002008-01-24 19:38:39 +01001280
Johannes Berg3713b4e2013-02-14 16:19:38 +01001281 if ((dev->wiphy.flags & WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD) &&
1282 nla_put_u32(msg, NL80211_ATTR_PROBE_RESP_OFFLOAD,
1283 dev->wiphy.probe_resp_offload))
1284 goto nla_put_failure;
Jouni Malinene2f367f262008-11-21 19:01:30 +02001285
Johannes Berg3713b4e2013-02-14 16:19:38 +01001286 if ((dev->wiphy.available_antennas_tx ||
1287 dev->wiphy.available_antennas_rx) &&
1288 dev->ops->get_antenna) {
1289 u32 tx_ant = 0, rx_ant = 0;
1290 int res;
1291 res = rdev_get_antenna(dev, &tx_ant, &rx_ant);
1292 if (!res) {
1293 if (nla_put_u32(msg,
1294 NL80211_ATTR_WIPHY_ANTENNA_TX,
1295 tx_ant) ||
1296 nla_put_u32(msg,
1297 NL80211_ATTR_WIPHY_ANTENNA_RX,
1298 rx_ant))
1299 goto nla_put_failure;
1300 }
Johannes Bergee688b002008-01-24 19:38:39 +01001301 }
1302
Johannes Berg86e8cf92013-06-19 10:57:22 +02001303 state->split_start++;
1304 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001305 break;
1306 case 2:
1307 if (nl80211_put_iftypes(msg, NL80211_ATTR_SUPPORTED_IFTYPES,
1308 dev->wiphy.interface_modes))
1309 goto nla_put_failure;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001310 state->split_start++;
1311 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001312 break;
1313 case 3:
1314 nl_bands = nla_nest_start(msg, NL80211_ATTR_WIPHY_BANDS);
1315 if (!nl_bands)
Johannes Bergee688b002008-01-24 19:38:39 +01001316 goto nla_put_failure;
1317
Johannes Berg86e8cf92013-06-19 10:57:22 +02001318 for (band = state->band_start;
1319 band < IEEE80211_NUM_BANDS; band++) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001320 struct ieee80211_supported_band *sband;
1321
1322 sband = dev->wiphy.bands[band];
1323
1324 if (!sband)
1325 continue;
1326
1327 nl_band = nla_nest_start(msg, band);
1328 if (!nl_band)
Johannes Bergee688b002008-01-24 19:38:39 +01001329 goto nla_put_failure;
1330
Johannes Berg86e8cf92013-06-19 10:57:22 +02001331 switch (state->chan_start) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001332 case 0:
1333 if (nl80211_send_band_rateinfo(msg, sband))
1334 goto nla_put_failure;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001335 state->chan_start++;
1336 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001337 break;
1338 default:
1339 /* add frequencies */
1340 nl_freqs = nla_nest_start(
1341 msg, NL80211_BAND_ATTR_FREQS);
1342 if (!nl_freqs)
1343 goto nla_put_failure;
Johannes Bergee688b002008-01-24 19:38:39 +01001344
Johannes Berg86e8cf92013-06-19 10:57:22 +02001345 for (i = state->chan_start - 1;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001346 i < sband->n_channels;
1347 i++) {
1348 nl_freq = nla_nest_start(msg, i);
1349 if (!nl_freq)
1350 goto nla_put_failure;
1351
1352 chan = &sband->channels[i];
1353
Johannes Berg86e8cf92013-06-19 10:57:22 +02001354 if (nl80211_msg_put_channel(
1355 msg, chan,
1356 state->split))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001357 goto nla_put_failure;
1358
1359 nla_nest_end(msg, nl_freq);
Johannes Berg86e8cf92013-06-19 10:57:22 +02001360 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001361 break;
1362 }
1363 if (i < sband->n_channels)
Johannes Berg86e8cf92013-06-19 10:57:22 +02001364 state->chan_start = i + 2;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001365 else
Johannes Berg86e8cf92013-06-19 10:57:22 +02001366 state->chan_start = 0;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001367 nla_nest_end(msg, nl_freqs);
1368 }
1369
1370 nla_nest_end(msg, nl_band);
1371
Johannes Berg86e8cf92013-06-19 10:57:22 +02001372 if (state->split) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001373 /* start again here */
Johannes Berg86e8cf92013-06-19 10:57:22 +02001374 if (state->chan_start)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001375 band--;
1376 break;
1377 }
Johannes Bergee688b002008-01-24 19:38:39 +01001378 }
Johannes Berg3713b4e2013-02-14 16:19:38 +01001379 nla_nest_end(msg, nl_bands);
Johannes Bergee688b002008-01-24 19:38:39 +01001380
Johannes Berg3713b4e2013-02-14 16:19:38 +01001381 if (band < IEEE80211_NUM_BANDS)
Johannes Berg86e8cf92013-06-19 10:57:22 +02001382 state->band_start = band + 1;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001383 else
Johannes Berg86e8cf92013-06-19 10:57:22 +02001384 state->band_start = 0;
Johannes Bergee688b002008-01-24 19:38:39 +01001385
Johannes Berg3713b4e2013-02-14 16:19:38 +01001386 /* if bands & channels are done, continue outside */
Johannes Berg86e8cf92013-06-19 10:57:22 +02001387 if (state->band_start == 0 && state->chan_start == 0)
1388 state->split_start++;
1389 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001390 break;
1391 case 4:
1392 nl_cmds = nla_nest_start(msg, NL80211_ATTR_SUPPORTED_COMMANDS);
1393 if (!nl_cmds)
David S. Miller9360ffd2012-03-29 04:41:26 -04001394 goto nla_put_failure;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001395
1396 i = 0;
1397#define CMD(op, n) \
1398 do { \
1399 if (dev->ops->op) { \
1400 i++; \
1401 if (nla_put_u32(msg, i, NL80211_CMD_ ## n)) \
1402 goto nla_put_failure; \
1403 } \
1404 } while (0)
1405
1406 CMD(add_virtual_intf, NEW_INTERFACE);
1407 CMD(change_virtual_intf, SET_INTERFACE);
1408 CMD(add_key, NEW_KEY);
1409 CMD(start_ap, START_AP);
1410 CMD(add_station, NEW_STATION);
1411 CMD(add_mpath, NEW_MPATH);
1412 CMD(update_mesh_config, SET_MESH_CONFIG);
1413 CMD(change_bss, SET_BSS);
1414 CMD(auth, AUTHENTICATE);
1415 CMD(assoc, ASSOCIATE);
1416 CMD(deauth, DEAUTHENTICATE);
1417 CMD(disassoc, DISASSOCIATE);
1418 CMD(join_ibss, JOIN_IBSS);
1419 CMD(join_mesh, JOIN_MESH);
1420 CMD(set_pmksa, SET_PMKSA);
1421 CMD(del_pmksa, DEL_PMKSA);
1422 CMD(flush_pmksa, FLUSH_PMKSA);
1423 if (dev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL)
1424 CMD(remain_on_channel, REMAIN_ON_CHANNEL);
1425 CMD(set_bitrate_mask, SET_TX_BITRATE_MASK);
1426 CMD(mgmt_tx, FRAME);
1427 CMD(mgmt_tx_cancel_wait, FRAME_WAIT_CANCEL);
1428 if (dev->wiphy.flags & WIPHY_FLAG_NETNS_OK) {
1429 i++;
1430 if (nla_put_u32(msg, i, NL80211_CMD_SET_WIPHY_NETNS))
1431 goto nla_put_failure;
1432 }
1433 if (dev->ops->set_monitor_channel || dev->ops->start_ap ||
1434 dev->ops->join_mesh) {
1435 i++;
1436 if (nla_put_u32(msg, i, NL80211_CMD_SET_CHANNEL))
1437 goto nla_put_failure;
1438 }
1439 CMD(set_wds_peer, SET_WDS_PEER);
1440 if (dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) {
1441 CMD(tdls_mgmt, TDLS_MGMT);
1442 CMD(tdls_oper, TDLS_OPER);
1443 }
1444 if (dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN)
1445 CMD(sched_scan_start, START_SCHED_SCAN);
1446 CMD(probe_client, PROBE_CLIENT);
1447 CMD(set_noack_map, SET_NOACK_MAP);
1448 if (dev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS) {
1449 i++;
1450 if (nla_put_u32(msg, i, NL80211_CMD_REGISTER_BEACONS))
1451 goto nla_put_failure;
1452 }
1453 CMD(start_p2p_device, START_P2P_DEVICE);
1454 CMD(set_mcast_rate, SET_MCAST_RATE);
Johannes Berg86e8cf92013-06-19 10:57:22 +02001455 if (state->split) {
Arend van Spriel5de17982013-04-18 15:49:00 +02001456 CMD(crit_proto_start, CRIT_PROTOCOL_START);
1457 CMD(crit_proto_stop, CRIT_PROTOCOL_STOP);
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02001458 if (dev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH)
1459 CMD(channel_switch, CHANNEL_SWITCH);
Arend van Spriel5de17982013-04-18 15:49:00 +02001460 }
Kyeyoon Parkfa9ffc72013-12-16 23:01:30 -08001461 CMD(set_qos_map, SET_QOS_MAP);
Johannes Berg8fdc6212009-03-14 09:34:01 +01001462
Kalle Valo4745fc02011-11-17 19:06:10 +02001463#ifdef CONFIG_NL80211_TESTMODE
Johannes Berg3713b4e2013-02-14 16:19:38 +01001464 CMD(testmode_cmd, TESTMODE);
Kalle Valo4745fc02011-11-17 19:06:10 +02001465#endif
1466
Johannes Berg8fdc6212009-03-14 09:34:01 +01001467#undef CMD
Samuel Ortizb23aa672009-07-01 21:26:54 +02001468
Johannes Berg3713b4e2013-02-14 16:19:38 +01001469 if (dev->ops->connect || dev->ops->auth) {
1470 i++;
1471 if (nla_put_u32(msg, i, NL80211_CMD_CONNECT))
Johannes Berg2e161f72010-08-12 15:38:38 +02001472 goto nla_put_failure;
Johannes Berg2e161f72010-08-12 15:38:38 +02001473 }
1474
Johannes Berg3713b4e2013-02-14 16:19:38 +01001475 if (dev->ops->disconnect || dev->ops->deauth) {
1476 i++;
1477 if (nla_put_u32(msg, i, NL80211_CMD_DISCONNECT))
1478 goto nla_put_failure;
1479 }
Johannes Berg74b70a42010-08-24 12:15:53 +02001480
Johannes Berg3713b4e2013-02-14 16:19:38 +01001481 nla_nest_end(msg, nl_cmds);
Johannes Berg86e8cf92013-06-19 10:57:22 +02001482 state->split_start++;
1483 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001484 break;
1485 case 5:
1486 if (dev->ops->remain_on_channel &&
1487 (dev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL) &&
1488 nla_put_u32(msg,
1489 NL80211_ATTR_MAX_REMAIN_ON_CHANNEL_DURATION,
1490 dev->wiphy.max_remain_on_channel_duration))
Johannes Berg2e161f72010-08-12 15:38:38 +02001491 goto nla_put_failure;
1492
Johannes Berg3713b4e2013-02-14 16:19:38 +01001493 if ((dev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX) &&
1494 nla_put_flag(msg, NL80211_ATTR_OFFCHANNEL_TX_OK))
1495 goto nla_put_failure;
Johannes Berg2e161f72010-08-12 15:38:38 +02001496
Johannes Berg3713b4e2013-02-14 16:19:38 +01001497 if (nl80211_send_mgmt_stypes(msg, mgmt_stypes))
1498 goto nla_put_failure;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001499 state->split_start++;
1500 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001501 break;
1502 case 6:
Johannes Bergdfb89c52012-06-27 09:23:48 +02001503#ifdef CONFIG_PM
Johannes Berg86e8cf92013-06-19 10:57:22 +02001504 if (nl80211_send_wowlan(msg, dev, state->split))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001505 goto nla_put_failure;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001506 state->split_start++;
1507 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001508 break;
1509#else
Johannes Berg86e8cf92013-06-19 10:57:22 +02001510 state->split_start++;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001511#endif
1512 case 7:
1513 if (nl80211_put_iftypes(msg, NL80211_ATTR_SOFTWARE_IFTYPES,
1514 dev->wiphy.software_iftypes))
Johannes Bergff1b6e62011-05-04 15:37:28 +02001515 goto nla_put_failure;
1516
Johannes Berg86e8cf92013-06-19 10:57:22 +02001517 if (nl80211_put_iface_combinations(&dev->wiphy, msg,
1518 state->split))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001519 goto nla_put_failure;
Johannes Bergff1b6e62011-05-04 15:37:28 +02001520
Johannes Berg86e8cf92013-06-19 10:57:22 +02001521 state->split_start++;
1522 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001523 break;
1524 case 8:
1525 if ((dev->wiphy.flags & WIPHY_FLAG_HAVE_AP_SME) &&
1526 nla_put_u32(msg, NL80211_ATTR_DEVICE_AP_SME,
1527 dev->wiphy.ap_sme_capa))
1528 goto nla_put_failure;
1529
Johannes Bergfe1abaf2013-02-27 15:39:45 +01001530 features = dev->wiphy.features;
1531 /*
1532 * We can only add the per-channel limit information if the
1533 * dump is split, otherwise it makes it too big. Therefore
1534 * only advertise it in that case.
1535 */
Johannes Berg86e8cf92013-06-19 10:57:22 +02001536 if (state->split)
Johannes Bergfe1abaf2013-02-27 15:39:45 +01001537 features |= NL80211_FEATURE_ADVERTISE_CHAN_LIMITS;
1538 if (nla_put_u32(msg, NL80211_ATTR_FEATURE_FLAGS, features))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001539 goto nla_put_failure;
1540
1541 if (dev->wiphy.ht_capa_mod_mask &&
1542 nla_put(msg, NL80211_ATTR_HT_CAPABILITY_MASK,
1543 sizeof(*dev->wiphy.ht_capa_mod_mask),
1544 dev->wiphy.ht_capa_mod_mask))
1545 goto nla_put_failure;
1546
1547 if (dev->wiphy.flags & WIPHY_FLAG_HAVE_AP_SME &&
1548 dev->wiphy.max_acl_mac_addrs &&
1549 nla_put_u32(msg, NL80211_ATTR_MAC_ACL_MAX,
1550 dev->wiphy.max_acl_mac_addrs))
1551 goto nla_put_failure;
1552
1553 /*
1554 * Any information below this point is only available to
1555 * applications that can deal with it being split. This
1556 * helps ensure that newly added capabilities don't break
1557 * older tools by overrunning their buffers.
1558 *
1559 * We still increment split_start so that in the split
1560 * case we'll continue with more data in the next round,
1561 * but break unconditionally so unsplit data stops here.
1562 */
Johannes Berg86e8cf92013-06-19 10:57:22 +02001563 state->split_start++;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001564 break;
1565 case 9:
Johannes Bergfe1abaf2013-02-27 15:39:45 +01001566 if (dev->wiphy.extended_capabilities &&
1567 (nla_put(msg, NL80211_ATTR_EXT_CAPA,
1568 dev->wiphy.extended_capabilities_len,
1569 dev->wiphy.extended_capabilities) ||
1570 nla_put(msg, NL80211_ATTR_EXT_CAPA_MASK,
1571 dev->wiphy.extended_capabilities_len,
1572 dev->wiphy.extended_capabilities_mask)))
1573 goto nla_put_failure;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001574
Johannes Bergee2aca32013-02-21 17:36:01 +01001575 if (dev->wiphy.vht_capa_mod_mask &&
1576 nla_put(msg, NL80211_ATTR_VHT_CAPABILITY_MASK,
1577 sizeof(*dev->wiphy.vht_capa_mod_mask),
1578 dev->wiphy.vht_capa_mod_mask))
1579 goto nla_put_failure;
1580
Amitkumar Karwarbe29b992013-06-28 11:51:26 -07001581 state->split_start++;
1582 break;
1583 case 10:
1584 if (nl80211_send_coalesce(msg, dev))
1585 goto nla_put_failure;
1586
Felix Fietkau01e0daa2013-11-09 14:57:54 +01001587 if ((dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_5_10_MHZ) &&
1588 (nla_put_flag(msg, NL80211_ATTR_SUPPORT_5_MHZ) ||
1589 nla_put_flag(msg, NL80211_ATTR_SUPPORT_10_MHZ)))
1590 goto nla_put_failure;
Johannes Bergad7e7182013-11-13 13:37:47 +01001591 state->split_start++;
1592 break;
1593 case 11:
Johannes Berg567ffc32013-12-18 14:43:31 +01001594 if (dev->wiphy.n_vendor_commands) {
1595 const struct nl80211_vendor_cmd_info *info;
1596 struct nlattr *nested;
Johannes Bergad7e7182013-11-13 13:37:47 +01001597
Johannes Berg567ffc32013-12-18 14:43:31 +01001598 nested = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA);
1599 if (!nested)
Johannes Bergad7e7182013-11-13 13:37:47 +01001600 goto nla_put_failure;
Johannes Berg567ffc32013-12-18 14:43:31 +01001601
1602 for (i = 0; i < dev->wiphy.n_vendor_commands; i++) {
1603 info = &dev->wiphy.vendor_commands[i].info;
1604 if (nla_put(msg, i + 1, sizeof(*info), info))
1605 goto nla_put_failure;
1606 }
1607 nla_nest_end(msg, nested);
1608 }
1609
1610 if (dev->wiphy.n_vendor_events) {
1611 const struct nl80211_vendor_cmd_info *info;
1612 struct nlattr *nested;
1613
1614 nested = nla_nest_start(msg,
1615 NL80211_ATTR_VENDOR_EVENTS);
1616 if (!nested)
1617 goto nla_put_failure;
1618
1619 for (i = 0; i < dev->wiphy.n_vendor_events; i++) {
1620 info = &dev->wiphy.vendor_events[i];
1621 if (nla_put(msg, i + 1, sizeof(*info), info))
1622 goto nla_put_failure;
1623 }
1624 nla_nest_end(msg, nested);
1625 }
Felix Fietkau01e0daa2013-11-09 14:57:54 +01001626
Johannes Berg3713b4e2013-02-14 16:19:38 +01001627 /* done */
Johannes Berg86e8cf92013-06-19 10:57:22 +02001628 state->split_start = 0;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001629 break;
Johannes Bergff1b6e62011-05-04 15:37:28 +02001630 }
Johannes Berg55682962007-09-20 13:09:35 -04001631 return genlmsg_end(msg, hdr);
1632
1633 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07001634 genlmsg_cancel(msg, hdr);
1635 return -EMSGSIZE;
Johannes Berg55682962007-09-20 13:09:35 -04001636}
1637
Johannes Berg86e8cf92013-06-19 10:57:22 +02001638static int nl80211_dump_wiphy_parse(struct sk_buff *skb,
1639 struct netlink_callback *cb,
1640 struct nl80211_dump_wiphy_state *state)
1641{
1642 struct nlattr **tb = nl80211_fam.attrbuf;
1643 int ret = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize,
1644 tb, nl80211_fam.maxattr, nl80211_policy);
1645 /* ignore parse errors for backward compatibility */
1646 if (ret)
1647 return 0;
1648
1649 state->split = tb[NL80211_ATTR_SPLIT_WIPHY_DUMP];
1650 if (tb[NL80211_ATTR_WIPHY])
1651 state->filter_wiphy = nla_get_u32(tb[NL80211_ATTR_WIPHY]);
1652 if (tb[NL80211_ATTR_WDEV])
1653 state->filter_wiphy = nla_get_u64(tb[NL80211_ATTR_WDEV]) >> 32;
1654 if (tb[NL80211_ATTR_IFINDEX]) {
1655 struct net_device *netdev;
1656 struct cfg80211_registered_device *rdev;
1657 int ifidx = nla_get_u32(tb[NL80211_ATTR_IFINDEX]);
1658
Ying Xue7f2b8562014-01-15 10:23:45 +08001659 netdev = __dev_get_by_index(sock_net(skb->sk), ifidx);
Johannes Berg86e8cf92013-06-19 10:57:22 +02001660 if (!netdev)
1661 return -ENODEV;
1662 if (netdev->ieee80211_ptr) {
1663 rdev = wiphy_to_dev(
1664 netdev->ieee80211_ptr->wiphy);
1665 state->filter_wiphy = rdev->wiphy_idx;
1666 }
Johannes Berg86e8cf92013-06-19 10:57:22 +02001667 }
1668
1669 return 0;
1670}
1671
Johannes Berg55682962007-09-20 13:09:35 -04001672static int nl80211_dump_wiphy(struct sk_buff *skb, struct netlink_callback *cb)
1673{
Johannes Berg645e77d2013-03-01 14:03:49 +01001674 int idx = 0, ret;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001675 struct nl80211_dump_wiphy_state *state = (void *)cb->args[0];
Johannes Berg55682962007-09-20 13:09:35 -04001676 struct cfg80211_registered_device *dev;
Johannes Berg3a5a4232013-06-19 10:09:57 +02001677
Johannes Berg5fe231e2013-05-08 21:45:15 +02001678 rtnl_lock();
Johannes Berg86e8cf92013-06-19 10:57:22 +02001679 if (!state) {
1680 state = kzalloc(sizeof(*state), GFP_KERNEL);
John W. Linville57ed5cd2013-06-28 13:18:21 -04001681 if (!state) {
1682 rtnl_unlock();
Johannes Berg86e8cf92013-06-19 10:57:22 +02001683 return -ENOMEM;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001684 }
Johannes Berg86e8cf92013-06-19 10:57:22 +02001685 state->filter_wiphy = -1;
1686 ret = nl80211_dump_wiphy_parse(skb, cb, state);
1687 if (ret) {
1688 kfree(state);
1689 rtnl_unlock();
1690 return ret;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001691 }
Johannes Berg86e8cf92013-06-19 10:57:22 +02001692 cb->args[0] = (long)state;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001693 }
1694
Johannes Berg79c97e92009-07-07 03:56:12 +02001695 list_for_each_entry(dev, &cfg80211_rdev_list, list) {
Johannes Berg463d0182009-07-14 00:33:35 +02001696 if (!net_eq(wiphy_net(&dev->wiphy), sock_net(skb->sk)))
1697 continue;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001698 if (++idx <= state->start)
Johannes Berg55682962007-09-20 13:09:35 -04001699 continue;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001700 if (state->filter_wiphy != -1 &&
1701 state->filter_wiphy != dev->wiphy_idx)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001702 continue;
1703 /* attempt to fit multiple wiphy data chunks into the skb */
1704 do {
1705 ret = nl80211_send_wiphy(dev, skb,
1706 NETLINK_CB(cb->skb).portid,
1707 cb->nlh->nlmsg_seq,
Johannes Berg86e8cf92013-06-19 10:57:22 +02001708 NLM_F_MULTI, state);
Johannes Berg3713b4e2013-02-14 16:19:38 +01001709 if (ret < 0) {
1710 /*
1711 * If sending the wiphy data didn't fit (ENOBUFS
1712 * or EMSGSIZE returned), this SKB is still
1713 * empty (so it's not too big because another
1714 * wiphy dataset is already in the skb) and
1715 * we've not tried to adjust the dump allocation
1716 * yet ... then adjust the alloc size to be
1717 * bigger, and return 1 but with the empty skb.
1718 * This results in an empty message being RX'ed
1719 * in userspace, but that is ignored.
1720 *
1721 * We can then retry with the larger buffer.
1722 */
1723 if ((ret == -ENOBUFS || ret == -EMSGSIZE) &&
1724 !skb->len &&
1725 cb->min_dump_alloc < 4096) {
1726 cb->min_dump_alloc = 4096;
David S. Millerd98cae64e2013-06-19 16:49:39 -07001727 rtnl_unlock();
Johannes Berg3713b4e2013-02-14 16:19:38 +01001728 return 1;
1729 }
1730 idx--;
1731 break;
Johannes Berg645e77d2013-03-01 14:03:49 +01001732 }
Johannes Berg86e8cf92013-06-19 10:57:22 +02001733 } while (state->split_start > 0);
Johannes Berg3713b4e2013-02-14 16:19:38 +01001734 break;
Johannes Berg55682962007-09-20 13:09:35 -04001735 }
Johannes Berg5fe231e2013-05-08 21:45:15 +02001736 rtnl_unlock();
Johannes Berg55682962007-09-20 13:09:35 -04001737
Johannes Berg86e8cf92013-06-19 10:57:22 +02001738 state->start = idx;
Johannes Berg55682962007-09-20 13:09:35 -04001739
1740 return skb->len;
1741}
1742
Johannes Berg86e8cf92013-06-19 10:57:22 +02001743static int nl80211_dump_wiphy_done(struct netlink_callback *cb)
1744{
1745 kfree((void *)cb->args[0]);
1746 return 0;
1747}
1748
Johannes Berg55682962007-09-20 13:09:35 -04001749static int nl80211_get_wiphy(struct sk_buff *skb, struct genl_info *info)
1750{
1751 struct sk_buff *msg;
Johannes Berg4c476992010-10-04 21:36:35 +02001752 struct cfg80211_registered_device *dev = info->user_ptr[0];
Johannes Berg86e8cf92013-06-19 10:57:22 +02001753 struct nl80211_dump_wiphy_state state = {};
Johannes Berg55682962007-09-20 13:09:35 -04001754
Johannes Berg645e77d2013-03-01 14:03:49 +01001755 msg = nlmsg_new(4096, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -04001756 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02001757 return -ENOMEM;
Johannes Berg55682962007-09-20 13:09:35 -04001758
Johannes Berg3713b4e2013-02-14 16:19:38 +01001759 if (nl80211_send_wiphy(dev, msg, info->snd_portid, info->snd_seq, 0,
Johannes Berg86e8cf92013-06-19 10:57:22 +02001760 &state) < 0) {
Johannes Berg4c476992010-10-04 21:36:35 +02001761 nlmsg_free(msg);
1762 return -ENOBUFS;
1763 }
Johannes Berg55682962007-09-20 13:09:35 -04001764
Johannes Berg134e6372009-07-10 09:51:34 +00001765 return genlmsg_reply(msg, info);
Johannes Berg55682962007-09-20 13:09:35 -04001766}
1767
Jouni Malinen31888482008-10-30 16:59:24 +02001768static const struct nla_policy txq_params_policy[NL80211_TXQ_ATTR_MAX + 1] = {
1769 [NL80211_TXQ_ATTR_QUEUE] = { .type = NLA_U8 },
1770 [NL80211_TXQ_ATTR_TXOP] = { .type = NLA_U16 },
1771 [NL80211_TXQ_ATTR_CWMIN] = { .type = NLA_U16 },
1772 [NL80211_TXQ_ATTR_CWMAX] = { .type = NLA_U16 },
1773 [NL80211_TXQ_ATTR_AIFS] = { .type = NLA_U8 },
1774};
1775
1776static int parse_txq_params(struct nlattr *tb[],
1777 struct ieee80211_txq_params *txq_params)
1778{
Johannes Berga3304b02012-03-28 11:04:24 +02001779 if (!tb[NL80211_TXQ_ATTR_AC] || !tb[NL80211_TXQ_ATTR_TXOP] ||
Jouni Malinen31888482008-10-30 16:59:24 +02001780 !tb[NL80211_TXQ_ATTR_CWMIN] || !tb[NL80211_TXQ_ATTR_CWMAX] ||
1781 !tb[NL80211_TXQ_ATTR_AIFS])
1782 return -EINVAL;
1783
Johannes Berga3304b02012-03-28 11:04:24 +02001784 txq_params->ac = nla_get_u8(tb[NL80211_TXQ_ATTR_AC]);
Jouni Malinen31888482008-10-30 16:59:24 +02001785 txq_params->txop = nla_get_u16(tb[NL80211_TXQ_ATTR_TXOP]);
1786 txq_params->cwmin = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMIN]);
1787 txq_params->cwmax = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMAX]);
1788 txq_params->aifs = nla_get_u8(tb[NL80211_TXQ_ATTR_AIFS]);
1789
Johannes Berga3304b02012-03-28 11:04:24 +02001790 if (txq_params->ac >= NL80211_NUM_ACS)
1791 return -EINVAL;
1792
Jouni Malinen31888482008-10-30 16:59:24 +02001793 return 0;
1794}
1795
Johannes Bergf444de02010-05-05 15:25:02 +02001796static bool nl80211_can_set_dev_channel(struct wireless_dev *wdev)
1797{
1798 /*
Johannes Bergcc1d2802012-05-16 23:50:20 +02001799 * You can only set the channel explicitly for WDS interfaces,
1800 * all others have their channel managed via their respective
1801 * "establish a connection" command (connect, join, ...)
1802 *
1803 * For AP/GO and mesh mode, the channel can be set with the
1804 * channel userspace API, but is only stored and passed to the
1805 * low-level driver when the AP starts or the mesh is joined.
1806 * This is for backward compatibility, userspace can also give
1807 * the channel in the start-ap or join-mesh commands instead.
Johannes Bergf444de02010-05-05 15:25:02 +02001808 *
1809 * Monitors are special as they are normally slaved to
Johannes Berge8c9bd52012-06-06 08:18:22 +02001810 * whatever else is going on, so they have their own special
1811 * operation to set the monitor channel if possible.
Johannes Bergf444de02010-05-05 15:25:02 +02001812 */
1813 return !wdev ||
1814 wdev->iftype == NL80211_IFTYPE_AP ||
Johannes Bergf444de02010-05-05 15:25:02 +02001815 wdev->iftype == NL80211_IFTYPE_MESH_POINT ||
Johannes Berg074ac8d2010-09-16 14:58:22 +02001816 wdev->iftype == NL80211_IFTYPE_MONITOR ||
1817 wdev->iftype == NL80211_IFTYPE_P2P_GO;
Johannes Bergf444de02010-05-05 15:25:02 +02001818}
1819
Johannes Berg683b6d32012-11-08 21:25:48 +01001820static int nl80211_parse_chandef(struct cfg80211_registered_device *rdev,
1821 struct genl_info *info,
1822 struct cfg80211_chan_def *chandef)
1823{
Mahesh Paliveladbeca2e2012-11-29 14:11:07 +05301824 u32 control_freq;
Johannes Berg683b6d32012-11-08 21:25:48 +01001825
1826 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ])
1827 return -EINVAL;
1828
1829 control_freq = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]);
1830
1831 chandef->chan = ieee80211_get_channel(&rdev->wiphy, control_freq);
Johannes Berg3d9d1d62012-11-08 23:14:50 +01001832 chandef->width = NL80211_CHAN_WIDTH_20_NOHT;
1833 chandef->center_freq1 = control_freq;
1834 chandef->center_freq2 = 0;
Johannes Berg683b6d32012-11-08 21:25:48 +01001835
1836 /* Primary channel not allowed */
1837 if (!chandef->chan || chandef->chan->flags & IEEE80211_CHAN_DISABLED)
1838 return -EINVAL;
1839
Johannes Berg3d9d1d62012-11-08 23:14:50 +01001840 if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]) {
1841 enum nl80211_channel_type chantype;
Johannes Berg683b6d32012-11-08 21:25:48 +01001842
Johannes Berg3d9d1d62012-11-08 23:14:50 +01001843 chantype = nla_get_u32(
1844 info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]);
1845
1846 switch (chantype) {
1847 case NL80211_CHAN_NO_HT:
1848 case NL80211_CHAN_HT20:
1849 case NL80211_CHAN_HT40PLUS:
1850 case NL80211_CHAN_HT40MINUS:
1851 cfg80211_chandef_create(chandef, chandef->chan,
1852 chantype);
1853 break;
1854 default:
Johannes Berg683b6d32012-11-08 21:25:48 +01001855 return -EINVAL;
Johannes Berg683b6d32012-11-08 21:25:48 +01001856 }
Johannes Berg3d9d1d62012-11-08 23:14:50 +01001857 } else if (info->attrs[NL80211_ATTR_CHANNEL_WIDTH]) {
1858 chandef->width =
1859 nla_get_u32(info->attrs[NL80211_ATTR_CHANNEL_WIDTH]);
1860 if (info->attrs[NL80211_ATTR_CENTER_FREQ1])
1861 chandef->center_freq1 =
1862 nla_get_u32(
1863 info->attrs[NL80211_ATTR_CENTER_FREQ1]);
1864 if (info->attrs[NL80211_ATTR_CENTER_FREQ2])
1865 chandef->center_freq2 =
1866 nla_get_u32(
1867 info->attrs[NL80211_ATTR_CENTER_FREQ2]);
1868 }
1869
Johannes Berg9f5e8f62012-11-22 16:59:45 +01001870 if (!cfg80211_chandef_valid(chandef))
Johannes Berg3d9d1d62012-11-08 23:14:50 +01001871 return -EINVAL;
1872
Johannes Berg9f5e8f62012-11-22 16:59:45 +01001873 if (!cfg80211_chandef_usable(&rdev->wiphy, chandef,
1874 IEEE80211_CHAN_DISABLED))
Johannes Berg3d9d1d62012-11-08 23:14:50 +01001875 return -EINVAL;
Johannes Berg3d9d1d62012-11-08 23:14:50 +01001876
Simon Wunderlich2f301ab2013-05-16 13:00:28 +02001877 if ((chandef->width == NL80211_CHAN_WIDTH_5 ||
1878 chandef->width == NL80211_CHAN_WIDTH_10) &&
1879 !(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_5_10_MHZ))
1880 return -EINVAL;
1881
Johannes Berg683b6d32012-11-08 21:25:48 +01001882 return 0;
1883}
1884
Johannes Bergf444de02010-05-05 15:25:02 +02001885static int __nl80211_set_channel(struct cfg80211_registered_device *rdev,
1886 struct wireless_dev *wdev,
1887 struct genl_info *info)
1888{
Johannes Berg683b6d32012-11-08 21:25:48 +01001889 struct cfg80211_chan_def chandef;
Johannes Bergf444de02010-05-05 15:25:02 +02001890 int result;
Johannes Berge8c9bd52012-06-06 08:18:22 +02001891 enum nl80211_iftype iftype = NL80211_IFTYPE_MONITOR;
1892
1893 if (wdev)
1894 iftype = wdev->iftype;
Johannes Bergf444de02010-05-05 15:25:02 +02001895
Johannes Bergf444de02010-05-05 15:25:02 +02001896 if (!nl80211_can_set_dev_channel(wdev))
1897 return -EOPNOTSUPP;
1898
Johannes Berg683b6d32012-11-08 21:25:48 +01001899 result = nl80211_parse_chandef(rdev, info, &chandef);
1900 if (result)
1901 return result;
Johannes Bergf444de02010-05-05 15:25:02 +02001902
Johannes Berge8c9bd52012-06-06 08:18:22 +02001903 switch (iftype) {
Johannes Bergaa430da2012-05-16 23:50:18 +02001904 case NL80211_IFTYPE_AP:
1905 case NL80211_IFTYPE_P2P_GO:
1906 if (wdev->beacon_interval) {
1907 result = -EBUSY;
1908 break;
1909 }
Johannes Berg683b6d32012-11-08 21:25:48 +01001910 if (!cfg80211_reg_can_beacon(&rdev->wiphy, &chandef)) {
Johannes Bergaa430da2012-05-16 23:50:18 +02001911 result = -EINVAL;
1912 break;
1913 }
Johannes Berg683b6d32012-11-08 21:25:48 +01001914 wdev->preset_chandef = chandef;
Johannes Bergaa430da2012-05-16 23:50:18 +02001915 result = 0;
1916 break;
Johannes Bergcc1d2802012-05-16 23:50:20 +02001917 case NL80211_IFTYPE_MESH_POINT:
Johannes Berg683b6d32012-11-08 21:25:48 +01001918 result = cfg80211_set_mesh_channel(rdev, wdev, &chandef);
Johannes Bergcc1d2802012-05-16 23:50:20 +02001919 break;
Johannes Berge8c9bd52012-06-06 08:18:22 +02001920 case NL80211_IFTYPE_MONITOR:
Johannes Berg683b6d32012-11-08 21:25:48 +01001921 result = cfg80211_set_monitor_channel(rdev, &chandef);
Johannes Berge8c9bd52012-06-06 08:18:22 +02001922 break;
Johannes Bergaa430da2012-05-16 23:50:18 +02001923 default:
Johannes Berge8c9bd52012-06-06 08:18:22 +02001924 result = -EINVAL;
Johannes Bergf444de02010-05-05 15:25:02 +02001925 }
Johannes Bergf444de02010-05-05 15:25:02 +02001926
1927 return result;
1928}
1929
1930static int nl80211_set_channel(struct sk_buff *skb, struct genl_info *info)
1931{
Johannes Berg4c476992010-10-04 21:36:35 +02001932 struct cfg80211_registered_device *rdev = info->user_ptr[0];
1933 struct net_device *netdev = info->user_ptr[1];
Johannes Bergf444de02010-05-05 15:25:02 +02001934
Johannes Berg4c476992010-10-04 21:36:35 +02001935 return __nl80211_set_channel(rdev, netdev->ieee80211_ptr, info);
Johannes Bergf444de02010-05-05 15:25:02 +02001936}
1937
Bill Jordane8347eb2010-10-01 13:54:28 -04001938static int nl80211_set_wds_peer(struct sk_buff *skb, struct genl_info *info)
1939{
Johannes Berg43b19952010-10-07 13:10:30 +02001940 struct cfg80211_registered_device *rdev = info->user_ptr[0];
1941 struct net_device *dev = info->user_ptr[1];
1942 struct wireless_dev *wdev = dev->ieee80211_ptr;
Johannes Berg388ac772010-10-07 13:11:09 +02001943 const u8 *bssid;
Bill Jordane8347eb2010-10-01 13:54:28 -04001944
1945 if (!info->attrs[NL80211_ATTR_MAC])
1946 return -EINVAL;
1947
Johannes Berg43b19952010-10-07 13:10:30 +02001948 if (netif_running(dev))
1949 return -EBUSY;
Bill Jordane8347eb2010-10-01 13:54:28 -04001950
Johannes Berg43b19952010-10-07 13:10:30 +02001951 if (!rdev->ops->set_wds_peer)
1952 return -EOPNOTSUPP;
Bill Jordane8347eb2010-10-01 13:54:28 -04001953
Johannes Berg43b19952010-10-07 13:10:30 +02001954 if (wdev->iftype != NL80211_IFTYPE_WDS)
1955 return -EOPNOTSUPP;
Bill Jordane8347eb2010-10-01 13:54:28 -04001956
1957 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Hila Gonene35e4d22012-06-27 17:19:42 +03001958 return rdev_set_wds_peer(rdev, dev, bssid);
Bill Jordane8347eb2010-10-01 13:54:28 -04001959}
1960
1961
Johannes Berg55682962007-09-20 13:09:35 -04001962static int nl80211_set_wiphy(struct sk_buff *skb, struct genl_info *info)
1963{
1964 struct cfg80211_registered_device *rdev;
Johannes Bergf444de02010-05-05 15:25:02 +02001965 struct net_device *netdev = NULL;
1966 struct wireless_dev *wdev;
Bill Jordana1e567c2010-09-10 11:22:32 -04001967 int result = 0, rem_txq_params = 0;
Jouni Malinen31888482008-10-30 16:59:24 +02001968 struct nlattr *nl_txq_params;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02001969 u32 changed;
1970 u8 retry_short = 0, retry_long = 0;
1971 u32 frag_threshold = 0, rts_threshold = 0;
Lukáš Turek81077e82009-12-21 22:50:47 +01001972 u8 coverage_class = 0;
Johannes Berg55682962007-09-20 13:09:35 -04001973
Johannes Berg5fe231e2013-05-08 21:45:15 +02001974 ASSERT_RTNL();
1975
Johannes Bergf444de02010-05-05 15:25:02 +02001976 /*
1977 * Try to find the wiphy and netdev. Normally this
1978 * function shouldn't need the netdev, but this is
1979 * done for backward compatibility -- previously
1980 * setting the channel was done per wiphy, but now
1981 * it is per netdev. Previous userland like hostapd
1982 * also passed a netdev to set_wiphy, so that it is
1983 * possible to let that go to the right netdev!
1984 */
Johannes Berg4bbf4d52009-03-24 09:35:46 +01001985
Johannes Bergf444de02010-05-05 15:25:02 +02001986 if (info->attrs[NL80211_ATTR_IFINDEX]) {
1987 int ifindex = nla_get_u32(info->attrs[NL80211_ATTR_IFINDEX]);
1988
Ying Xue7f2b8562014-01-15 10:23:45 +08001989 netdev = __dev_get_by_index(genl_info_net(info), ifindex);
Johannes Berg5fe231e2013-05-08 21:45:15 +02001990 if (netdev && netdev->ieee80211_ptr)
Johannes Bergf444de02010-05-05 15:25:02 +02001991 rdev = wiphy_to_dev(netdev->ieee80211_ptr->wiphy);
Johannes Berg5fe231e2013-05-08 21:45:15 +02001992 else
Johannes Bergf444de02010-05-05 15:25:02 +02001993 netdev = NULL;
Johannes Berg4bbf4d52009-03-24 09:35:46 +01001994 }
1995
Johannes Bergf444de02010-05-05 15:25:02 +02001996 if (!netdev) {
Johannes Berg878d9ec2012-06-15 14:18:32 +02001997 rdev = __cfg80211_rdev_from_attrs(genl_info_net(info),
1998 info->attrs);
Johannes Berg5fe231e2013-05-08 21:45:15 +02001999 if (IS_ERR(rdev))
Johannes Berg4c476992010-10-04 21:36:35 +02002000 return PTR_ERR(rdev);
Johannes Bergf444de02010-05-05 15:25:02 +02002001 wdev = NULL;
2002 netdev = NULL;
2003 result = 0;
Johannes Berg71fe96b2012-10-24 10:04:58 +02002004 } else
Johannes Bergf444de02010-05-05 15:25:02 +02002005 wdev = netdev->ieee80211_ptr;
Johannes Bergf444de02010-05-05 15:25:02 +02002006
2007 /*
2008 * end workaround code, by now the rdev is available
2009 * and locked, and wdev may or may not be NULL.
2010 */
Johannes Berg4bbf4d52009-03-24 09:35:46 +01002011
2012 if (info->attrs[NL80211_ATTR_WIPHY_NAME])
Jouni Malinen31888482008-10-30 16:59:24 +02002013 result = cfg80211_dev_rename(
2014 rdev, nla_data(info->attrs[NL80211_ATTR_WIPHY_NAME]));
Johannes Berg4bbf4d52009-03-24 09:35:46 +01002015
Johannes Berg4bbf4d52009-03-24 09:35:46 +01002016 if (result)
Ying Xue7f2b8562014-01-15 10:23:45 +08002017 return result;
Johannes Berg55682962007-09-20 13:09:35 -04002018
Jouni Malinen31888482008-10-30 16:59:24 +02002019 if (info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS]) {
2020 struct ieee80211_txq_params txq_params;
2021 struct nlattr *tb[NL80211_TXQ_ATTR_MAX + 1];
2022
Ying Xue7f2b8562014-01-15 10:23:45 +08002023 if (!rdev->ops->set_txq_params)
2024 return -EOPNOTSUPP;
Jouni Malinen31888482008-10-30 16:59:24 +02002025
Ying Xue7f2b8562014-01-15 10:23:45 +08002026 if (!netdev)
2027 return -EINVAL;
Eliad Pellerf70f01c2011-09-25 20:06:53 +03002028
Johannes Berg133a3ff2011-11-03 14:50:13 +01002029 if (netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
Ying Xue7f2b8562014-01-15 10:23:45 +08002030 netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
2031 return -EINVAL;
Johannes Berg133a3ff2011-11-03 14:50:13 +01002032
Ying Xue7f2b8562014-01-15 10:23:45 +08002033 if (!netif_running(netdev))
2034 return -ENETDOWN;
Johannes Berg2b5f8b02012-04-02 10:51:55 +02002035
Jouni Malinen31888482008-10-30 16:59:24 +02002036 nla_for_each_nested(nl_txq_params,
2037 info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS],
2038 rem_txq_params) {
2039 nla_parse(tb, NL80211_TXQ_ATTR_MAX,
2040 nla_data(nl_txq_params),
2041 nla_len(nl_txq_params),
2042 txq_params_policy);
2043 result = parse_txq_params(tb, &txq_params);
2044 if (result)
Ying Xue7f2b8562014-01-15 10:23:45 +08002045 return result;
Jouni Malinen31888482008-10-30 16:59:24 +02002046
Hila Gonene35e4d22012-06-27 17:19:42 +03002047 result = rdev_set_txq_params(rdev, netdev,
2048 &txq_params);
Jouni Malinen31888482008-10-30 16:59:24 +02002049 if (result)
Ying Xue7f2b8562014-01-15 10:23:45 +08002050 return result;
Jouni Malinen31888482008-10-30 16:59:24 +02002051 }
2052 }
2053
Jouni Malinen72bdcf32008-11-26 16:15:24 +02002054 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
Johannes Berg71fe96b2012-10-24 10:04:58 +02002055 result = __nl80211_set_channel(rdev,
2056 nl80211_can_set_dev_channel(wdev) ? wdev : NULL,
2057 info);
Jouni Malinen72bdcf32008-11-26 16:15:24 +02002058 if (result)
Ying Xue7f2b8562014-01-15 10:23:45 +08002059 return result;
Jouni Malinen72bdcf32008-11-26 16:15:24 +02002060 }
2061
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03002062 if (info->attrs[NL80211_ATTR_WIPHY_TX_POWER_SETTING]) {
Johannes Bergc8442112012-10-24 10:17:18 +02002063 struct wireless_dev *txp_wdev = wdev;
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03002064 enum nl80211_tx_power_setting type;
2065 int idx, mbm = 0;
2066
Johannes Bergc8442112012-10-24 10:17:18 +02002067 if (!(rdev->wiphy.features & NL80211_FEATURE_VIF_TXPOWER))
2068 txp_wdev = NULL;
2069
Ying Xue7f2b8562014-01-15 10:23:45 +08002070 if (!rdev->ops->set_tx_power)
2071 return -EOPNOTSUPP;
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03002072
2073 idx = NL80211_ATTR_WIPHY_TX_POWER_SETTING;
2074 type = nla_get_u32(info->attrs[idx]);
2075
2076 if (!info->attrs[NL80211_ATTR_WIPHY_TX_POWER_LEVEL] &&
Ying Xue7f2b8562014-01-15 10:23:45 +08002077 (type != NL80211_TX_POWER_AUTOMATIC))
2078 return -EINVAL;
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03002079
2080 if (type != NL80211_TX_POWER_AUTOMATIC) {
2081 idx = NL80211_ATTR_WIPHY_TX_POWER_LEVEL;
2082 mbm = nla_get_u32(info->attrs[idx]);
2083 }
2084
Johannes Bergc8442112012-10-24 10:17:18 +02002085 result = rdev_set_tx_power(rdev, txp_wdev, type, mbm);
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03002086 if (result)
Ying Xue7f2b8562014-01-15 10:23:45 +08002087 return result;
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03002088 }
2089
Bruno Randolfafe0cbf2010-11-10 12:50:50 +09002090 if (info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX] &&
2091 info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]) {
2092 u32 tx_ant, rx_ant;
Bruno Randolf7f531e02010-12-16 11:30:22 +09002093 if ((!rdev->wiphy.available_antennas_tx &&
2094 !rdev->wiphy.available_antennas_rx) ||
Ying Xue7f2b8562014-01-15 10:23:45 +08002095 !rdev->ops->set_antenna)
2096 return -EOPNOTSUPP;
Bruno Randolfafe0cbf2010-11-10 12:50:50 +09002097
2098 tx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX]);
2099 rx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]);
2100
Bruno Randolfa7ffac92010-12-08 13:59:24 +09002101 /* reject antenna configurations which don't match the
Bruno Randolf7f531e02010-12-16 11:30:22 +09002102 * available antenna masks, except for the "all" mask */
2103 if ((~tx_ant && (tx_ant & ~rdev->wiphy.available_antennas_tx)) ||
Ying Xue7f2b8562014-01-15 10:23:45 +08002104 (~rx_ant && (rx_ant & ~rdev->wiphy.available_antennas_rx)))
2105 return -EINVAL;
Bruno Randolfa7ffac92010-12-08 13:59:24 +09002106
Bruno Randolf7f531e02010-12-16 11:30:22 +09002107 tx_ant = tx_ant & rdev->wiphy.available_antennas_tx;
2108 rx_ant = rx_ant & rdev->wiphy.available_antennas_rx;
Bruno Randolfa7ffac92010-12-08 13:59:24 +09002109
Hila Gonene35e4d22012-06-27 17:19:42 +03002110 result = rdev_set_antenna(rdev, tx_ant, rx_ant);
Bruno Randolfafe0cbf2010-11-10 12:50:50 +09002111 if (result)
Ying Xue7f2b8562014-01-15 10:23:45 +08002112 return result;
Bruno Randolfafe0cbf2010-11-10 12:50:50 +09002113 }
2114
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002115 changed = 0;
2116
2117 if (info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]) {
2118 retry_short = nla_get_u8(
2119 info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]);
Ying Xue7f2b8562014-01-15 10:23:45 +08002120 if (retry_short == 0)
2121 return -EINVAL;
2122
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002123 changed |= WIPHY_PARAM_RETRY_SHORT;
2124 }
2125
2126 if (info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]) {
2127 retry_long = nla_get_u8(
2128 info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]);
Ying Xue7f2b8562014-01-15 10:23:45 +08002129 if (retry_long == 0)
2130 return -EINVAL;
2131
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002132 changed |= WIPHY_PARAM_RETRY_LONG;
2133 }
2134
2135 if (info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]) {
2136 frag_threshold = nla_get_u32(
2137 info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]);
Ying Xue7f2b8562014-01-15 10:23:45 +08002138 if (frag_threshold < 256)
2139 return -EINVAL;
2140
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002141 if (frag_threshold != (u32) -1) {
2142 /*
2143 * Fragments (apart from the last one) are required to
2144 * have even length. Make the fragmentation code
2145 * simpler by stripping LSB should someone try to use
2146 * odd threshold value.
2147 */
2148 frag_threshold &= ~0x1;
2149 }
2150 changed |= WIPHY_PARAM_FRAG_THRESHOLD;
2151 }
2152
2153 if (info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]) {
2154 rts_threshold = nla_get_u32(
2155 info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]);
2156 changed |= WIPHY_PARAM_RTS_THRESHOLD;
2157 }
2158
Lukáš Turek81077e82009-12-21 22:50:47 +01002159 if (info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]) {
2160 coverage_class = nla_get_u8(
2161 info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]);
2162 changed |= WIPHY_PARAM_COVERAGE_CLASS;
2163 }
2164
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002165 if (changed) {
2166 u8 old_retry_short, old_retry_long;
2167 u32 old_frag_threshold, old_rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01002168 u8 old_coverage_class;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002169
Ying Xue7f2b8562014-01-15 10:23:45 +08002170 if (!rdev->ops->set_wiphy_params)
2171 return -EOPNOTSUPP;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002172
2173 old_retry_short = rdev->wiphy.retry_short;
2174 old_retry_long = rdev->wiphy.retry_long;
2175 old_frag_threshold = rdev->wiphy.frag_threshold;
2176 old_rts_threshold = rdev->wiphy.rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01002177 old_coverage_class = rdev->wiphy.coverage_class;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002178
2179 if (changed & WIPHY_PARAM_RETRY_SHORT)
2180 rdev->wiphy.retry_short = retry_short;
2181 if (changed & WIPHY_PARAM_RETRY_LONG)
2182 rdev->wiphy.retry_long = retry_long;
2183 if (changed & WIPHY_PARAM_FRAG_THRESHOLD)
2184 rdev->wiphy.frag_threshold = frag_threshold;
2185 if (changed & WIPHY_PARAM_RTS_THRESHOLD)
2186 rdev->wiphy.rts_threshold = rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01002187 if (changed & WIPHY_PARAM_COVERAGE_CLASS)
2188 rdev->wiphy.coverage_class = coverage_class;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002189
Hila Gonene35e4d22012-06-27 17:19:42 +03002190 result = rdev_set_wiphy_params(rdev, changed);
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002191 if (result) {
2192 rdev->wiphy.retry_short = old_retry_short;
2193 rdev->wiphy.retry_long = old_retry_long;
2194 rdev->wiphy.frag_threshold = old_frag_threshold;
2195 rdev->wiphy.rts_threshold = old_rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01002196 rdev->wiphy.coverage_class = old_coverage_class;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002197 }
2198 }
Ying Xue7f2b8562014-01-15 10:23:45 +08002199 return 0;
Johannes Berg55682962007-09-20 13:09:35 -04002200}
2201
Johannes Berg71bbc992012-06-15 15:30:18 +02002202static inline u64 wdev_id(struct wireless_dev *wdev)
2203{
2204 return (u64)wdev->identifier |
2205 ((u64)wiphy_to_dev(wdev->wiphy)->wiphy_idx << 32);
2206}
Johannes Berg55682962007-09-20 13:09:35 -04002207
Johannes Berg683b6d32012-11-08 21:25:48 +01002208static int nl80211_send_chandef(struct sk_buff *msg,
Janusz Dziedzicd2859df2013-11-06 13:55:51 +01002209 const struct cfg80211_chan_def *chandef)
Johannes Berg683b6d32012-11-08 21:25:48 +01002210{
Johannes Berg9f5e8f62012-11-22 16:59:45 +01002211 WARN_ON(!cfg80211_chandef_valid(chandef));
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002212
Johannes Berg683b6d32012-11-08 21:25:48 +01002213 if (nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ,
2214 chandef->chan->center_freq))
2215 return -ENOBUFS;
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002216 switch (chandef->width) {
2217 case NL80211_CHAN_WIDTH_20_NOHT:
2218 case NL80211_CHAN_WIDTH_20:
2219 case NL80211_CHAN_WIDTH_40:
2220 if (nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE,
2221 cfg80211_get_chandef_type(chandef)))
2222 return -ENOBUFS;
2223 break;
2224 default:
2225 break;
2226 }
2227 if (nla_put_u32(msg, NL80211_ATTR_CHANNEL_WIDTH, chandef->width))
2228 return -ENOBUFS;
2229 if (nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ1, chandef->center_freq1))
2230 return -ENOBUFS;
2231 if (chandef->center_freq2 &&
2232 nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ2, chandef->center_freq2))
Johannes Berg683b6d32012-11-08 21:25:48 +01002233 return -ENOBUFS;
2234 return 0;
2235}
2236
Eric W. Biederman15e47302012-09-07 20:12:54 +00002237static int nl80211_send_iface(struct sk_buff *msg, u32 portid, u32 seq, int flags,
Johannes Bergd7264052009-04-19 16:23:20 +02002238 struct cfg80211_registered_device *rdev,
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002239 struct wireless_dev *wdev)
Johannes Berg55682962007-09-20 13:09:35 -04002240{
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002241 struct net_device *dev = wdev->netdev;
Johannes Berg55682962007-09-20 13:09:35 -04002242 void *hdr;
2243
Eric W. Biederman15e47302012-09-07 20:12:54 +00002244 hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_INTERFACE);
Johannes Berg55682962007-09-20 13:09:35 -04002245 if (!hdr)
2246 return -1;
2247
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002248 if (dev &&
2249 (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
Johannes Berg98104fde2012-06-16 00:19:54 +02002250 nla_put_string(msg, NL80211_ATTR_IFNAME, dev->name)))
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002251 goto nla_put_failure;
2252
2253 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
2254 nla_put_u32(msg, NL80211_ATTR_IFTYPE, wdev->iftype) ||
Johannes Berg71bbc992012-06-15 15:30:18 +02002255 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) ||
Johannes Berg98104fde2012-06-16 00:19:54 +02002256 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, wdev_address(wdev)) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04002257 nla_put_u32(msg, NL80211_ATTR_GENERATION,
2258 rdev->devlist_generation ^
2259 (cfg80211_rdev_list_generation << 2)))
2260 goto nla_put_failure;
Johannes Bergf5ea9122009-08-07 16:17:38 +02002261
Johannes Berg5b7ccaf2012-07-12 19:45:08 +02002262 if (rdev->ops->get_channel) {
Johannes Berg683b6d32012-11-08 21:25:48 +01002263 int ret;
2264 struct cfg80211_chan_def chandef;
Johannes Berg5b7ccaf2012-07-12 19:45:08 +02002265
Johannes Berg683b6d32012-11-08 21:25:48 +01002266 ret = rdev_get_channel(rdev, wdev, &chandef);
2267 if (ret == 0) {
2268 if (nl80211_send_chandef(msg, &chandef))
2269 goto nla_put_failure;
2270 }
Pontus Fuchsd91df0e2012-04-03 16:39:58 +02002271 }
2272
Antonio Quartullib84e7a02012-11-07 12:52:20 +01002273 if (wdev->ssid_len) {
2274 if (nla_put(msg, NL80211_ATTR_SSID, wdev->ssid_len, wdev->ssid))
2275 goto nla_put_failure;
2276 }
2277
Johannes Berg55682962007-09-20 13:09:35 -04002278 return genlmsg_end(msg, hdr);
2279
2280 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07002281 genlmsg_cancel(msg, hdr);
2282 return -EMSGSIZE;
Johannes Berg55682962007-09-20 13:09:35 -04002283}
2284
2285static int nl80211_dump_interface(struct sk_buff *skb, struct netlink_callback *cb)
2286{
2287 int wp_idx = 0;
2288 int if_idx = 0;
2289 int wp_start = cb->args[0];
2290 int if_start = cb->args[1];
Johannes Bergf5ea9122009-08-07 16:17:38 +02002291 struct cfg80211_registered_device *rdev;
Johannes Berg55682962007-09-20 13:09:35 -04002292 struct wireless_dev *wdev;
2293
Johannes Berg5fe231e2013-05-08 21:45:15 +02002294 rtnl_lock();
Johannes Bergf5ea9122009-08-07 16:17:38 +02002295 list_for_each_entry(rdev, &cfg80211_rdev_list, list) {
2296 if (!net_eq(wiphy_net(&rdev->wiphy), sock_net(skb->sk)))
Johannes Berg463d0182009-07-14 00:33:35 +02002297 continue;
Johannes Bergbba95fe2008-07-29 13:22:51 +02002298 if (wp_idx < wp_start) {
2299 wp_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04002300 continue;
Johannes Bergbba95fe2008-07-29 13:22:51 +02002301 }
Johannes Berg55682962007-09-20 13:09:35 -04002302 if_idx = 0;
2303
Johannes Berg89a54e42012-06-15 14:33:17 +02002304 list_for_each_entry(wdev, &rdev->wdev_list, list) {
Johannes Bergbba95fe2008-07-29 13:22:51 +02002305 if (if_idx < if_start) {
2306 if_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04002307 continue;
Johannes Bergbba95fe2008-07-29 13:22:51 +02002308 }
Eric W. Biederman15e47302012-09-07 20:12:54 +00002309 if (nl80211_send_iface(skb, NETLINK_CB(cb->skb).portid,
Johannes Berg55682962007-09-20 13:09:35 -04002310 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002311 rdev, wdev) < 0) {
Johannes Bergbba95fe2008-07-29 13:22:51 +02002312 goto out;
2313 }
2314 if_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04002315 }
Johannes Bergbba95fe2008-07-29 13:22:51 +02002316
2317 wp_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04002318 }
Johannes Bergbba95fe2008-07-29 13:22:51 +02002319 out:
Johannes Berg5fe231e2013-05-08 21:45:15 +02002320 rtnl_unlock();
Johannes Berg55682962007-09-20 13:09:35 -04002321
2322 cb->args[0] = wp_idx;
2323 cb->args[1] = if_idx;
2324
2325 return skb->len;
2326}
2327
2328static int nl80211_get_interface(struct sk_buff *skb, struct genl_info *info)
2329{
2330 struct sk_buff *msg;
Johannes Berg4c476992010-10-04 21:36:35 +02002331 struct cfg80211_registered_device *dev = info->user_ptr[0];
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002332 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg55682962007-09-20 13:09:35 -04002333
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07002334 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -04002335 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02002336 return -ENOMEM;
Johannes Berg55682962007-09-20 13:09:35 -04002337
Eric W. Biederman15e47302012-09-07 20:12:54 +00002338 if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002339 dev, wdev) < 0) {
Johannes Berg4c476992010-10-04 21:36:35 +02002340 nlmsg_free(msg);
2341 return -ENOBUFS;
2342 }
Johannes Berg55682962007-09-20 13:09:35 -04002343
Johannes Berg134e6372009-07-10 09:51:34 +00002344 return genlmsg_reply(msg, info);
Johannes Berg55682962007-09-20 13:09:35 -04002345}
2346
Michael Wu66f7ac52008-01-31 19:48:22 +01002347static const struct nla_policy mntr_flags_policy[NL80211_MNTR_FLAG_MAX + 1] = {
2348 [NL80211_MNTR_FLAG_FCSFAIL] = { .type = NLA_FLAG },
2349 [NL80211_MNTR_FLAG_PLCPFAIL] = { .type = NLA_FLAG },
2350 [NL80211_MNTR_FLAG_CONTROL] = { .type = NLA_FLAG },
2351 [NL80211_MNTR_FLAG_OTHER_BSS] = { .type = NLA_FLAG },
2352 [NL80211_MNTR_FLAG_COOK_FRAMES] = { .type = NLA_FLAG },
Felix Fietkaue057d3c2013-05-28 13:01:52 +02002353 [NL80211_MNTR_FLAG_ACTIVE] = { .type = NLA_FLAG },
Michael Wu66f7ac52008-01-31 19:48:22 +01002354};
2355
2356static int parse_monitor_flags(struct nlattr *nla, u32 *mntrflags)
2357{
2358 struct nlattr *flags[NL80211_MNTR_FLAG_MAX + 1];
2359 int flag;
2360
2361 *mntrflags = 0;
2362
2363 if (!nla)
2364 return -EINVAL;
2365
2366 if (nla_parse_nested(flags, NL80211_MNTR_FLAG_MAX,
2367 nla, mntr_flags_policy))
2368 return -EINVAL;
2369
2370 for (flag = 1; flag <= NL80211_MNTR_FLAG_MAX; flag++)
2371 if (flags[flag])
2372 *mntrflags |= (1<<flag);
2373
2374 return 0;
2375}
2376
Johannes Berg9bc383d2009-11-19 11:55:19 +01002377static int nl80211_valid_4addr(struct cfg80211_registered_device *rdev,
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002378 struct net_device *netdev, u8 use_4addr,
2379 enum nl80211_iftype iftype)
Johannes Berg9bc383d2009-11-19 11:55:19 +01002380{
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002381 if (!use_4addr) {
Jiri Pirkof350a0a82010-06-15 06:50:45 +00002382 if (netdev && (netdev->priv_flags & IFF_BRIDGE_PORT))
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002383 return -EBUSY;
Johannes Berg9bc383d2009-11-19 11:55:19 +01002384 return 0;
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002385 }
Johannes Berg9bc383d2009-11-19 11:55:19 +01002386
2387 switch (iftype) {
2388 case NL80211_IFTYPE_AP_VLAN:
2389 if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_AP)
2390 return 0;
2391 break;
2392 case NL80211_IFTYPE_STATION:
2393 if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_STATION)
2394 return 0;
2395 break;
2396 default:
2397 break;
2398 }
2399
2400 return -EOPNOTSUPP;
2401}
2402
Johannes Berg55682962007-09-20 13:09:35 -04002403static int nl80211_set_interface(struct sk_buff *skb, struct genl_info *info)
2404{
Johannes Berg4c476992010-10-04 21:36:35 +02002405 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002406 struct vif_params params;
Johannes Berge36d56b2009-06-09 21:04:43 +02002407 int err;
Johannes Berg04a773a2009-04-19 21:24:32 +02002408 enum nl80211_iftype otype, ntype;
Johannes Berg4c476992010-10-04 21:36:35 +02002409 struct net_device *dev = info->user_ptr[1];
Johannes Berg92ffe052008-09-16 20:39:36 +02002410 u32 _flags, *flags = NULL;
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002411 bool change = false;
Johannes Berg55682962007-09-20 13:09:35 -04002412
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002413 memset(&params, 0, sizeof(params));
2414
Johannes Berg04a773a2009-04-19 21:24:32 +02002415 otype = ntype = dev->ieee80211_ptr->iftype;
Johannes Berg55682962007-09-20 13:09:35 -04002416
Johannes Berg723b0382008-09-16 20:22:09 +02002417 if (info->attrs[NL80211_ATTR_IFTYPE]) {
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002418 ntype = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]);
Johannes Berg04a773a2009-04-19 21:24:32 +02002419 if (otype != ntype)
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002420 change = true;
Johannes Berg4c476992010-10-04 21:36:35 +02002421 if (ntype > NL80211_IFTYPE_MAX)
2422 return -EINVAL;
Johannes Berg723b0382008-09-16 20:22:09 +02002423 }
2424
Johannes Berg92ffe052008-09-16 20:39:36 +02002425 if (info->attrs[NL80211_ATTR_MESH_ID]) {
Johannes Berg29cbe682010-12-03 09:20:44 +01002426 struct wireless_dev *wdev = dev->ieee80211_ptr;
2427
Johannes Berg4c476992010-10-04 21:36:35 +02002428 if (ntype != NL80211_IFTYPE_MESH_POINT)
2429 return -EINVAL;
Johannes Berg29cbe682010-12-03 09:20:44 +01002430 if (netif_running(dev))
2431 return -EBUSY;
2432
2433 wdev_lock(wdev);
2434 BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN !=
2435 IEEE80211_MAX_MESH_ID_LEN);
2436 wdev->mesh_id_up_len =
2437 nla_len(info->attrs[NL80211_ATTR_MESH_ID]);
2438 memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]),
2439 wdev->mesh_id_up_len);
2440 wdev_unlock(wdev);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002441 }
2442
Felix Fietkau8b787642009-11-10 18:53:10 +01002443 if (info->attrs[NL80211_ATTR_4ADDR]) {
2444 params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]);
2445 change = true;
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002446 err = nl80211_valid_4addr(rdev, dev, params.use_4addr, ntype);
Johannes Berg9bc383d2009-11-19 11:55:19 +01002447 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02002448 return err;
Felix Fietkau8b787642009-11-10 18:53:10 +01002449 } else {
2450 params.use_4addr = -1;
2451 }
2452
Johannes Berg92ffe052008-09-16 20:39:36 +02002453 if (info->attrs[NL80211_ATTR_MNTR_FLAGS]) {
Johannes Berg4c476992010-10-04 21:36:35 +02002454 if (ntype != NL80211_IFTYPE_MONITOR)
2455 return -EINVAL;
Johannes Berg92ffe052008-09-16 20:39:36 +02002456 err = parse_monitor_flags(info->attrs[NL80211_ATTR_MNTR_FLAGS],
2457 &_flags);
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002458 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02002459 return err;
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002460
2461 flags = &_flags;
2462 change = true;
Johannes Berg92ffe052008-09-16 20:39:36 +02002463 }
Johannes Berg3b858752009-03-12 09:55:09 +01002464
Luciano Coelho18003292013-08-29 13:26:57 +03002465 if (flags && (*flags & MONITOR_FLAG_ACTIVE) &&
Felix Fietkaue057d3c2013-05-28 13:01:52 +02002466 !(rdev->wiphy.features & NL80211_FEATURE_ACTIVE_MONITOR))
2467 return -EOPNOTSUPP;
2468
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002469 if (change)
Johannes Berg3d54d252009-08-21 14:51:05 +02002470 err = cfg80211_change_iface(rdev, dev, ntype, flags, &params);
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002471 else
2472 err = 0;
Johannes Berg60719ff2008-09-16 14:55:09 +02002473
Johannes Berg9bc383d2009-11-19 11:55:19 +01002474 if (!err && params.use_4addr != -1)
2475 dev->ieee80211_ptr->use_4addr = params.use_4addr;
2476
Johannes Berg55682962007-09-20 13:09:35 -04002477 return err;
2478}
2479
2480static int nl80211_new_interface(struct sk_buff *skb, struct genl_info *info)
2481{
Johannes Berg4c476992010-10-04 21:36:35 +02002482 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002483 struct vif_params params;
Johannes Berg84efbb82012-06-16 00:00:26 +02002484 struct wireless_dev *wdev;
Johannes Berg1c90f9d2012-06-16 00:05:37 +02002485 struct sk_buff *msg;
Johannes Berg55682962007-09-20 13:09:35 -04002486 int err;
2487 enum nl80211_iftype type = NL80211_IFTYPE_UNSPECIFIED;
Michael Wu66f7ac52008-01-31 19:48:22 +01002488 u32 flags;
Johannes Berg55682962007-09-20 13:09:35 -04002489
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002490 memset(&params, 0, sizeof(params));
2491
Johannes Berg55682962007-09-20 13:09:35 -04002492 if (!info->attrs[NL80211_ATTR_IFNAME])
2493 return -EINVAL;
2494
2495 if (info->attrs[NL80211_ATTR_IFTYPE]) {
2496 type = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]);
2497 if (type > NL80211_IFTYPE_MAX)
2498 return -EINVAL;
2499 }
2500
Johannes Berg79c97e92009-07-07 03:56:12 +02002501 if (!rdev->ops->add_virtual_intf ||
Johannes Berg4c476992010-10-04 21:36:35 +02002502 !(rdev->wiphy.interface_modes & (1 << type)))
2503 return -EOPNOTSUPP;
Johannes Berg55682962007-09-20 13:09:35 -04002504
Arend van Spriel1c18f142013-01-08 10:17:27 +01002505 if (type == NL80211_IFTYPE_P2P_DEVICE && info->attrs[NL80211_ATTR_MAC]) {
2506 nla_memcpy(params.macaddr, info->attrs[NL80211_ATTR_MAC],
2507 ETH_ALEN);
2508 if (!is_valid_ether_addr(params.macaddr))
2509 return -EADDRNOTAVAIL;
2510 }
2511
Johannes Berg9bc383d2009-11-19 11:55:19 +01002512 if (info->attrs[NL80211_ATTR_4ADDR]) {
Felix Fietkau8b787642009-11-10 18:53:10 +01002513 params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]);
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002514 err = nl80211_valid_4addr(rdev, NULL, params.use_4addr, type);
Johannes Berg9bc383d2009-11-19 11:55:19 +01002515 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02002516 return err;
Johannes Berg9bc383d2009-11-19 11:55:19 +01002517 }
Felix Fietkau8b787642009-11-10 18:53:10 +01002518
Johannes Berg1c90f9d2012-06-16 00:05:37 +02002519 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
2520 if (!msg)
2521 return -ENOMEM;
2522
Michael Wu66f7ac52008-01-31 19:48:22 +01002523 err = parse_monitor_flags(type == NL80211_IFTYPE_MONITOR ?
2524 info->attrs[NL80211_ATTR_MNTR_FLAGS] : NULL,
2525 &flags);
Felix Fietkaue057d3c2013-05-28 13:01:52 +02002526
Luciano Coelho18003292013-08-29 13:26:57 +03002527 if (!err && (flags & MONITOR_FLAG_ACTIVE) &&
Felix Fietkaue057d3c2013-05-28 13:01:52 +02002528 !(rdev->wiphy.features & NL80211_FEATURE_ACTIVE_MONITOR))
2529 return -EOPNOTSUPP;
2530
Hila Gonene35e4d22012-06-27 17:19:42 +03002531 wdev = rdev_add_virtual_intf(rdev,
2532 nla_data(info->attrs[NL80211_ATTR_IFNAME]),
2533 type, err ? NULL : &flags, &params);
Johannes Berg1c90f9d2012-06-16 00:05:37 +02002534 if (IS_ERR(wdev)) {
2535 nlmsg_free(msg);
Johannes Berg84efbb82012-06-16 00:00:26 +02002536 return PTR_ERR(wdev);
Johannes Berg1c90f9d2012-06-16 00:05:37 +02002537 }
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002538
Johannes Berg98104fde2012-06-16 00:19:54 +02002539 switch (type) {
2540 case NL80211_IFTYPE_MESH_POINT:
2541 if (!info->attrs[NL80211_ATTR_MESH_ID])
2542 break;
Johannes Berg29cbe682010-12-03 09:20:44 +01002543 wdev_lock(wdev);
2544 BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN !=
2545 IEEE80211_MAX_MESH_ID_LEN);
2546 wdev->mesh_id_up_len =
2547 nla_len(info->attrs[NL80211_ATTR_MESH_ID]);
2548 memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]),
2549 wdev->mesh_id_up_len);
2550 wdev_unlock(wdev);
Johannes Berg98104fde2012-06-16 00:19:54 +02002551 break;
2552 case NL80211_IFTYPE_P2P_DEVICE:
2553 /*
2554 * P2P Device doesn't have a netdev, so doesn't go
2555 * through the netdev notifier and must be added here
2556 */
2557 mutex_init(&wdev->mtx);
2558 INIT_LIST_HEAD(&wdev->event_list);
2559 spin_lock_init(&wdev->event_lock);
2560 INIT_LIST_HEAD(&wdev->mgmt_registrations);
2561 spin_lock_init(&wdev->mgmt_registrations_lock);
2562
Johannes Berg98104fde2012-06-16 00:19:54 +02002563 wdev->identifier = ++rdev->wdev_id;
2564 list_add_rcu(&wdev->list, &rdev->wdev_list);
2565 rdev->devlist_generation++;
Johannes Berg98104fde2012-06-16 00:19:54 +02002566 break;
2567 default:
2568 break;
Johannes Berg29cbe682010-12-03 09:20:44 +01002569 }
2570
Eric W. Biederman15e47302012-09-07 20:12:54 +00002571 if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berg1c90f9d2012-06-16 00:05:37 +02002572 rdev, wdev) < 0) {
2573 nlmsg_free(msg);
2574 return -ENOBUFS;
2575 }
2576
2577 return genlmsg_reply(msg, info);
Johannes Berg55682962007-09-20 13:09:35 -04002578}
2579
2580static int nl80211_del_interface(struct sk_buff *skb, struct genl_info *info)
2581{
Johannes Berg4c476992010-10-04 21:36:35 +02002582 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg84efbb82012-06-16 00:00:26 +02002583 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg55682962007-09-20 13:09:35 -04002584
Johannes Berg4c476992010-10-04 21:36:35 +02002585 if (!rdev->ops->del_virtual_intf)
2586 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01002587
Johannes Berg84efbb82012-06-16 00:00:26 +02002588 /*
2589 * If we remove a wireless device without a netdev then clear
2590 * user_ptr[1] so that nl80211_post_doit won't dereference it
2591 * to check if it needs to do dev_put(). Otherwise it crashes
2592 * since the wdev has been freed, unlike with a netdev where
2593 * we need the dev_put() for the netdev to really be freed.
2594 */
2595 if (!wdev->netdev)
2596 info->user_ptr[1] = NULL;
2597
Hila Gonene35e4d22012-06-27 17:19:42 +03002598 return rdev_del_virtual_intf(rdev, wdev);
Johannes Berg55682962007-09-20 13:09:35 -04002599}
2600
Simon Wunderlich1d9d9212011-11-18 14:20:43 +01002601static int nl80211_set_noack_map(struct sk_buff *skb, struct genl_info *info)
2602{
2603 struct cfg80211_registered_device *rdev = info->user_ptr[0];
2604 struct net_device *dev = info->user_ptr[1];
2605 u16 noack_map;
2606
2607 if (!info->attrs[NL80211_ATTR_NOACK_MAP])
2608 return -EINVAL;
2609
2610 if (!rdev->ops->set_noack_map)
2611 return -EOPNOTSUPP;
2612
2613 noack_map = nla_get_u16(info->attrs[NL80211_ATTR_NOACK_MAP]);
2614
Hila Gonene35e4d22012-06-27 17:19:42 +03002615 return rdev_set_noack_map(rdev, dev, noack_map);
Simon Wunderlich1d9d9212011-11-18 14:20:43 +01002616}
2617
Johannes Berg41ade002007-12-19 02:03:29 +01002618struct get_key_cookie {
2619 struct sk_buff *msg;
2620 int error;
Johannes Bergb9454e82009-07-08 13:29:08 +02002621 int idx;
Johannes Berg41ade002007-12-19 02:03:29 +01002622};
2623
2624static void get_key_callback(void *c, struct key_params *params)
2625{
Johannes Bergb9454e82009-07-08 13:29:08 +02002626 struct nlattr *key;
Johannes Berg41ade002007-12-19 02:03:29 +01002627 struct get_key_cookie *cookie = c;
2628
David S. Miller9360ffd2012-03-29 04:41:26 -04002629 if ((params->key &&
2630 nla_put(cookie->msg, NL80211_ATTR_KEY_DATA,
2631 params->key_len, params->key)) ||
2632 (params->seq &&
2633 nla_put(cookie->msg, NL80211_ATTR_KEY_SEQ,
2634 params->seq_len, params->seq)) ||
2635 (params->cipher &&
2636 nla_put_u32(cookie->msg, NL80211_ATTR_KEY_CIPHER,
2637 params->cipher)))
2638 goto nla_put_failure;
Johannes Berg41ade002007-12-19 02:03:29 +01002639
Johannes Bergb9454e82009-07-08 13:29:08 +02002640 key = nla_nest_start(cookie->msg, NL80211_ATTR_KEY);
2641 if (!key)
2642 goto nla_put_failure;
2643
David S. Miller9360ffd2012-03-29 04:41:26 -04002644 if ((params->key &&
2645 nla_put(cookie->msg, NL80211_KEY_DATA,
2646 params->key_len, params->key)) ||
2647 (params->seq &&
2648 nla_put(cookie->msg, NL80211_KEY_SEQ,
2649 params->seq_len, params->seq)) ||
2650 (params->cipher &&
2651 nla_put_u32(cookie->msg, NL80211_KEY_CIPHER,
2652 params->cipher)))
2653 goto nla_put_failure;
Johannes Bergb9454e82009-07-08 13:29:08 +02002654
David S. Miller9360ffd2012-03-29 04:41:26 -04002655 if (nla_put_u8(cookie->msg, NL80211_ATTR_KEY_IDX, cookie->idx))
2656 goto nla_put_failure;
Johannes Bergb9454e82009-07-08 13:29:08 +02002657
2658 nla_nest_end(cookie->msg, key);
2659
Johannes Berg41ade002007-12-19 02:03:29 +01002660 return;
2661 nla_put_failure:
2662 cookie->error = 1;
2663}
2664
2665static int nl80211_get_key(struct sk_buff *skb, struct genl_info *info)
2666{
Johannes Berg4c476992010-10-04 21:36:35 +02002667 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg41ade002007-12-19 02:03:29 +01002668 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02002669 struct net_device *dev = info->user_ptr[1];
Johannes Berg41ade002007-12-19 02:03:29 +01002670 u8 key_idx = 0;
Johannes Berge31b8212010-10-05 19:39:30 +02002671 const u8 *mac_addr = NULL;
2672 bool pairwise;
Johannes Berg41ade002007-12-19 02:03:29 +01002673 struct get_key_cookie cookie = {
2674 .error = 0,
2675 };
2676 void *hdr;
2677 struct sk_buff *msg;
2678
2679 if (info->attrs[NL80211_ATTR_KEY_IDX])
2680 key_idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]);
2681
Jouni Malinen3cfcf6ac2009-01-08 13:32:02 +02002682 if (key_idx > 5)
Johannes Berg41ade002007-12-19 02:03:29 +01002683 return -EINVAL;
2684
2685 if (info->attrs[NL80211_ATTR_MAC])
2686 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
2687
Johannes Berge31b8212010-10-05 19:39:30 +02002688 pairwise = !!mac_addr;
2689 if (info->attrs[NL80211_ATTR_KEY_TYPE]) {
2690 u32 kt = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]);
2691 if (kt >= NUM_NL80211_KEYTYPES)
2692 return -EINVAL;
2693 if (kt != NL80211_KEYTYPE_GROUP &&
2694 kt != NL80211_KEYTYPE_PAIRWISE)
2695 return -EINVAL;
2696 pairwise = kt == NL80211_KEYTYPE_PAIRWISE;
2697 }
2698
Johannes Berg4c476992010-10-04 21:36:35 +02002699 if (!rdev->ops->get_key)
2700 return -EOPNOTSUPP;
Johannes Berg41ade002007-12-19 02:03:29 +01002701
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07002702 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02002703 if (!msg)
2704 return -ENOMEM;
Johannes Berg41ade002007-12-19 02:03:29 +01002705
Eric W. Biederman15e47302012-09-07 20:12:54 +00002706 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berg41ade002007-12-19 02:03:29 +01002707 NL80211_CMD_NEW_KEY);
Dan Carpentercb35fba2013-08-14 14:50:01 +03002708 if (!hdr)
Johannes Berg9fe271a2013-10-25 11:15:12 +02002709 goto nla_put_failure;
Johannes Berg41ade002007-12-19 02:03:29 +01002710
2711 cookie.msg = msg;
Johannes Bergb9454e82009-07-08 13:29:08 +02002712 cookie.idx = key_idx;
Johannes Berg41ade002007-12-19 02:03:29 +01002713
David S. Miller9360ffd2012-03-29 04:41:26 -04002714 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
2715 nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_idx))
2716 goto nla_put_failure;
2717 if (mac_addr &&
2718 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr))
2719 goto nla_put_failure;
Johannes Berg41ade002007-12-19 02:03:29 +01002720
Johannes Berge31b8212010-10-05 19:39:30 +02002721 if (pairwise && mac_addr &&
2722 !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN))
2723 return -ENOENT;
2724
Hila Gonene35e4d22012-06-27 17:19:42 +03002725 err = rdev_get_key(rdev, dev, key_idx, pairwise, mac_addr, &cookie,
2726 get_key_callback);
Johannes Berg41ade002007-12-19 02:03:29 +01002727
2728 if (err)
Niko Jokinen6c95e2a2009-07-15 11:00:53 +03002729 goto free_msg;
Johannes Berg41ade002007-12-19 02:03:29 +01002730
2731 if (cookie.error)
2732 goto nla_put_failure;
2733
2734 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02002735 return genlmsg_reply(msg, info);
Johannes Berg41ade002007-12-19 02:03:29 +01002736
2737 nla_put_failure:
2738 err = -ENOBUFS;
Niko Jokinen6c95e2a2009-07-15 11:00:53 +03002739 free_msg:
Johannes Berg41ade002007-12-19 02:03:29 +01002740 nlmsg_free(msg);
Johannes Berg41ade002007-12-19 02:03:29 +01002741 return err;
2742}
2743
2744static int nl80211_set_key(struct sk_buff *skb, struct genl_info *info)
2745{
Johannes Berg4c476992010-10-04 21:36:35 +02002746 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Bergb9454e82009-07-08 13:29:08 +02002747 struct key_parse key;
Johannes Berg41ade002007-12-19 02:03:29 +01002748 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02002749 struct net_device *dev = info->user_ptr[1];
Johannes Berg41ade002007-12-19 02:03:29 +01002750
Johannes Bergb9454e82009-07-08 13:29:08 +02002751 err = nl80211_parse_key(info, &key);
2752 if (err)
2753 return err;
2754
2755 if (key.idx < 0)
Johannes Berg41ade002007-12-19 02:03:29 +01002756 return -EINVAL;
2757
Johannes Bergb9454e82009-07-08 13:29:08 +02002758 /* only support setting default key */
2759 if (!key.def && !key.defmgmt)
Johannes Berg41ade002007-12-19 02:03:29 +01002760 return -EINVAL;
2761
Johannes Bergfffd0932009-07-08 14:22:54 +02002762 wdev_lock(dev->ieee80211_ptr);
Johannes Bergdbd2fd62010-12-09 19:58:59 +01002763
2764 if (key.def) {
2765 if (!rdev->ops->set_default_key) {
2766 err = -EOPNOTSUPP;
2767 goto out;
2768 }
2769
2770 err = nl80211_key_allowed(dev->ieee80211_ptr);
2771 if (err)
2772 goto out;
2773
Hila Gonene35e4d22012-06-27 17:19:42 +03002774 err = rdev_set_default_key(rdev, dev, key.idx,
Johannes Bergdbd2fd62010-12-09 19:58:59 +01002775 key.def_uni, key.def_multi);
2776
2777 if (err)
2778 goto out;
Johannes Bergfffd0932009-07-08 14:22:54 +02002779
Johannes Berg3d23e342009-09-29 23:27:28 +02002780#ifdef CONFIG_CFG80211_WEXT
Johannes Bergdbd2fd62010-12-09 19:58:59 +01002781 dev->ieee80211_ptr->wext.default_key = key.idx;
Johannes Berg08645122009-05-11 13:54:58 +02002782#endif
Johannes Bergdbd2fd62010-12-09 19:58:59 +01002783 } else {
2784 if (key.def_uni || !key.def_multi) {
2785 err = -EINVAL;
2786 goto out;
2787 }
2788
2789 if (!rdev->ops->set_default_mgmt_key) {
2790 err = -EOPNOTSUPP;
2791 goto out;
2792 }
2793
2794 err = nl80211_key_allowed(dev->ieee80211_ptr);
2795 if (err)
2796 goto out;
2797
Hila Gonene35e4d22012-06-27 17:19:42 +03002798 err = rdev_set_default_mgmt_key(rdev, dev, key.idx);
Johannes Bergdbd2fd62010-12-09 19:58:59 +01002799 if (err)
2800 goto out;
2801
2802#ifdef CONFIG_CFG80211_WEXT
2803 dev->ieee80211_ptr->wext.default_mgmt_key = key.idx;
2804#endif
2805 }
2806
2807 out:
Johannes Bergfffd0932009-07-08 14:22:54 +02002808 wdev_unlock(dev->ieee80211_ptr);
Johannes Berg41ade002007-12-19 02:03:29 +01002809
Johannes Berg41ade002007-12-19 02:03:29 +01002810 return err;
2811}
2812
2813static int nl80211_new_key(struct sk_buff *skb, struct genl_info *info)
2814{
Johannes Berg4c476992010-10-04 21:36:35 +02002815 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Bergfffd0932009-07-08 14:22:54 +02002816 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02002817 struct net_device *dev = info->user_ptr[1];
Johannes Bergb9454e82009-07-08 13:29:08 +02002818 struct key_parse key;
Johannes Berge31b8212010-10-05 19:39:30 +02002819 const u8 *mac_addr = NULL;
Johannes Berg41ade002007-12-19 02:03:29 +01002820
Johannes Bergb9454e82009-07-08 13:29:08 +02002821 err = nl80211_parse_key(info, &key);
2822 if (err)
2823 return err;
Johannes Berg41ade002007-12-19 02:03:29 +01002824
Johannes Bergb9454e82009-07-08 13:29:08 +02002825 if (!key.p.key)
Johannes Berg41ade002007-12-19 02:03:29 +01002826 return -EINVAL;
2827
Johannes Berg41ade002007-12-19 02:03:29 +01002828 if (info->attrs[NL80211_ATTR_MAC])
2829 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
2830
Johannes Berge31b8212010-10-05 19:39:30 +02002831 if (key.type == -1) {
2832 if (mac_addr)
2833 key.type = NL80211_KEYTYPE_PAIRWISE;
2834 else
2835 key.type = NL80211_KEYTYPE_GROUP;
2836 }
2837
2838 /* for now */
2839 if (key.type != NL80211_KEYTYPE_PAIRWISE &&
2840 key.type != NL80211_KEYTYPE_GROUP)
2841 return -EINVAL;
2842
Johannes Berg4c476992010-10-04 21:36:35 +02002843 if (!rdev->ops->add_key)
2844 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01002845
Johannes Berge31b8212010-10-05 19:39:30 +02002846 if (cfg80211_validate_key_settings(rdev, &key.p, key.idx,
2847 key.type == NL80211_KEYTYPE_PAIRWISE,
2848 mac_addr))
Johannes Berg4c476992010-10-04 21:36:35 +02002849 return -EINVAL;
Johannes Bergfffd0932009-07-08 14:22:54 +02002850
2851 wdev_lock(dev->ieee80211_ptr);
2852 err = nl80211_key_allowed(dev->ieee80211_ptr);
2853 if (!err)
Hila Gonene35e4d22012-06-27 17:19:42 +03002854 err = rdev_add_key(rdev, dev, key.idx,
2855 key.type == NL80211_KEYTYPE_PAIRWISE,
2856 mac_addr, &key.p);
Johannes Bergfffd0932009-07-08 14:22:54 +02002857 wdev_unlock(dev->ieee80211_ptr);
Johannes Berg41ade002007-12-19 02:03:29 +01002858
Johannes Berg41ade002007-12-19 02:03:29 +01002859 return err;
2860}
2861
2862static int nl80211_del_key(struct sk_buff *skb, struct genl_info *info)
2863{
Johannes Berg4c476992010-10-04 21:36:35 +02002864 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg41ade002007-12-19 02:03:29 +01002865 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02002866 struct net_device *dev = info->user_ptr[1];
Johannes Berg41ade002007-12-19 02:03:29 +01002867 u8 *mac_addr = NULL;
Johannes Bergb9454e82009-07-08 13:29:08 +02002868 struct key_parse key;
Johannes Berg41ade002007-12-19 02:03:29 +01002869
Johannes Bergb9454e82009-07-08 13:29:08 +02002870 err = nl80211_parse_key(info, &key);
2871 if (err)
2872 return err;
Johannes Berg41ade002007-12-19 02:03:29 +01002873
2874 if (info->attrs[NL80211_ATTR_MAC])
2875 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
2876
Johannes Berge31b8212010-10-05 19:39:30 +02002877 if (key.type == -1) {
2878 if (mac_addr)
2879 key.type = NL80211_KEYTYPE_PAIRWISE;
2880 else
2881 key.type = NL80211_KEYTYPE_GROUP;
2882 }
2883
2884 /* for now */
2885 if (key.type != NL80211_KEYTYPE_PAIRWISE &&
2886 key.type != NL80211_KEYTYPE_GROUP)
2887 return -EINVAL;
2888
Johannes Berg4c476992010-10-04 21:36:35 +02002889 if (!rdev->ops->del_key)
2890 return -EOPNOTSUPP;
Johannes Berg41ade002007-12-19 02:03:29 +01002891
Johannes Bergfffd0932009-07-08 14:22:54 +02002892 wdev_lock(dev->ieee80211_ptr);
2893 err = nl80211_key_allowed(dev->ieee80211_ptr);
Johannes Berge31b8212010-10-05 19:39:30 +02002894
2895 if (key.type == NL80211_KEYTYPE_PAIRWISE && mac_addr &&
2896 !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN))
2897 err = -ENOENT;
2898
Johannes Bergfffd0932009-07-08 14:22:54 +02002899 if (!err)
Hila Gonene35e4d22012-06-27 17:19:42 +03002900 err = rdev_del_key(rdev, dev, key.idx,
2901 key.type == NL80211_KEYTYPE_PAIRWISE,
2902 mac_addr);
Johannes Berg41ade002007-12-19 02:03:29 +01002903
Johannes Berg3d23e342009-09-29 23:27:28 +02002904#ifdef CONFIG_CFG80211_WEXT
Johannes Berg08645122009-05-11 13:54:58 +02002905 if (!err) {
Johannes Bergb9454e82009-07-08 13:29:08 +02002906 if (key.idx == dev->ieee80211_ptr->wext.default_key)
Johannes Berg08645122009-05-11 13:54:58 +02002907 dev->ieee80211_ptr->wext.default_key = -1;
Johannes Bergb9454e82009-07-08 13:29:08 +02002908 else if (key.idx == dev->ieee80211_ptr->wext.default_mgmt_key)
Johannes Berg08645122009-05-11 13:54:58 +02002909 dev->ieee80211_ptr->wext.default_mgmt_key = -1;
2910 }
2911#endif
Johannes Bergfffd0932009-07-08 14:22:54 +02002912 wdev_unlock(dev->ieee80211_ptr);
Johannes Berg08645122009-05-11 13:54:58 +02002913
Johannes Berg41ade002007-12-19 02:03:29 +01002914 return err;
2915}
2916
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +05302917/* This function returns an error or the number of nested attributes */
2918static int validate_acl_mac_addrs(struct nlattr *nl_attr)
2919{
2920 struct nlattr *attr;
2921 int n_entries = 0, tmp;
2922
2923 nla_for_each_nested(attr, nl_attr, tmp) {
2924 if (nla_len(attr) != ETH_ALEN)
2925 return -EINVAL;
2926
2927 n_entries++;
2928 }
2929
2930 return n_entries;
2931}
2932
2933/*
2934 * This function parses ACL information and allocates memory for ACL data.
2935 * On successful return, the calling function is responsible to free the
2936 * ACL buffer returned by this function.
2937 */
2938static struct cfg80211_acl_data *parse_acl_data(struct wiphy *wiphy,
2939 struct genl_info *info)
2940{
2941 enum nl80211_acl_policy acl_policy;
2942 struct nlattr *attr;
2943 struct cfg80211_acl_data *acl;
2944 int i = 0, n_entries, tmp;
2945
2946 if (!wiphy->max_acl_mac_addrs)
2947 return ERR_PTR(-EOPNOTSUPP);
2948
2949 if (!info->attrs[NL80211_ATTR_ACL_POLICY])
2950 return ERR_PTR(-EINVAL);
2951
2952 acl_policy = nla_get_u32(info->attrs[NL80211_ATTR_ACL_POLICY]);
2953 if (acl_policy != NL80211_ACL_POLICY_ACCEPT_UNLESS_LISTED &&
2954 acl_policy != NL80211_ACL_POLICY_DENY_UNLESS_LISTED)
2955 return ERR_PTR(-EINVAL);
2956
2957 if (!info->attrs[NL80211_ATTR_MAC_ADDRS])
2958 return ERR_PTR(-EINVAL);
2959
2960 n_entries = validate_acl_mac_addrs(info->attrs[NL80211_ATTR_MAC_ADDRS]);
2961 if (n_entries < 0)
2962 return ERR_PTR(n_entries);
2963
2964 if (n_entries > wiphy->max_acl_mac_addrs)
2965 return ERR_PTR(-ENOTSUPP);
2966
2967 acl = kzalloc(sizeof(*acl) + (sizeof(struct mac_address) * n_entries),
2968 GFP_KERNEL);
2969 if (!acl)
2970 return ERR_PTR(-ENOMEM);
2971
2972 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_MAC_ADDRS], tmp) {
2973 memcpy(acl->mac_addrs[i].addr, nla_data(attr), ETH_ALEN);
2974 i++;
2975 }
2976
2977 acl->n_acl_entries = n_entries;
2978 acl->acl_policy = acl_policy;
2979
2980 return acl;
2981}
2982
2983static int nl80211_set_mac_acl(struct sk_buff *skb, struct genl_info *info)
2984{
2985 struct cfg80211_registered_device *rdev = info->user_ptr[0];
2986 struct net_device *dev = info->user_ptr[1];
2987 struct cfg80211_acl_data *acl;
2988 int err;
2989
2990 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
2991 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
2992 return -EOPNOTSUPP;
2993
2994 if (!dev->ieee80211_ptr->beacon_interval)
2995 return -EINVAL;
2996
2997 acl = parse_acl_data(&rdev->wiphy, info);
2998 if (IS_ERR(acl))
2999 return PTR_ERR(acl);
3000
3001 err = rdev_set_mac_acl(rdev, dev, acl);
3002
3003 kfree(acl);
3004
3005 return err;
3006}
3007
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003008static int nl80211_parse_beacon(struct nlattr *attrs[],
Johannes Berg88600202012-02-13 15:17:18 +01003009 struct cfg80211_beacon_data *bcn)
Johannes Berged1b6cc2007-12-19 02:03:32 +01003010{
Johannes Berg88600202012-02-13 15:17:18 +01003011 bool haveinfo = false;
Johannes Berged1b6cc2007-12-19 02:03:32 +01003012
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003013 if (!is_valid_ie_attr(attrs[NL80211_ATTR_BEACON_TAIL]) ||
3014 !is_valid_ie_attr(attrs[NL80211_ATTR_IE]) ||
3015 !is_valid_ie_attr(attrs[NL80211_ATTR_IE_PROBE_RESP]) ||
3016 !is_valid_ie_attr(attrs[NL80211_ATTR_IE_ASSOC_RESP]))
Johannes Bergf4a11bb2009-03-27 12:40:28 +01003017 return -EINVAL;
3018
Johannes Berg88600202012-02-13 15:17:18 +01003019 memset(bcn, 0, sizeof(*bcn));
Johannes Berged1b6cc2007-12-19 02:03:32 +01003020
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003021 if (attrs[NL80211_ATTR_BEACON_HEAD]) {
3022 bcn->head = nla_data(attrs[NL80211_ATTR_BEACON_HEAD]);
3023 bcn->head_len = nla_len(attrs[NL80211_ATTR_BEACON_HEAD]);
Johannes Berg88600202012-02-13 15:17:18 +01003024 if (!bcn->head_len)
3025 return -EINVAL;
3026 haveinfo = true;
Johannes Berged1b6cc2007-12-19 02:03:32 +01003027 }
3028
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003029 if (attrs[NL80211_ATTR_BEACON_TAIL]) {
3030 bcn->tail = nla_data(attrs[NL80211_ATTR_BEACON_TAIL]);
3031 bcn->tail_len = nla_len(attrs[NL80211_ATTR_BEACON_TAIL]);
Johannes Berg88600202012-02-13 15:17:18 +01003032 haveinfo = true;
Johannes Berged1b6cc2007-12-19 02:03:32 +01003033 }
3034
Johannes Berg4c476992010-10-04 21:36:35 +02003035 if (!haveinfo)
3036 return -EINVAL;
Johannes Berged1b6cc2007-12-19 02:03:32 +01003037
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003038 if (attrs[NL80211_ATTR_IE]) {
3039 bcn->beacon_ies = nla_data(attrs[NL80211_ATTR_IE]);
3040 bcn->beacon_ies_len = nla_len(attrs[NL80211_ATTR_IE]);
Jouni Malinen9946ecf2011-08-10 23:55:56 +03003041 }
3042
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003043 if (attrs[NL80211_ATTR_IE_PROBE_RESP]) {
Johannes Berg88600202012-02-13 15:17:18 +01003044 bcn->proberesp_ies =
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003045 nla_data(attrs[NL80211_ATTR_IE_PROBE_RESP]);
Johannes Berg88600202012-02-13 15:17:18 +01003046 bcn->proberesp_ies_len =
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003047 nla_len(attrs[NL80211_ATTR_IE_PROBE_RESP]);
Jouni Malinen9946ecf2011-08-10 23:55:56 +03003048 }
3049
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003050 if (attrs[NL80211_ATTR_IE_ASSOC_RESP]) {
Johannes Berg88600202012-02-13 15:17:18 +01003051 bcn->assocresp_ies =
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003052 nla_data(attrs[NL80211_ATTR_IE_ASSOC_RESP]);
Johannes Berg88600202012-02-13 15:17:18 +01003053 bcn->assocresp_ies_len =
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003054 nla_len(attrs[NL80211_ATTR_IE_ASSOC_RESP]);
Jouni Malinen9946ecf2011-08-10 23:55:56 +03003055 }
3056
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003057 if (attrs[NL80211_ATTR_PROBE_RESP]) {
3058 bcn->probe_resp = nla_data(attrs[NL80211_ATTR_PROBE_RESP]);
3059 bcn->probe_resp_len = nla_len(attrs[NL80211_ATTR_PROBE_RESP]);
Arik Nemtsov00f740e2011-11-10 11:28:56 +02003060 }
3061
Johannes Berg88600202012-02-13 15:17:18 +01003062 return 0;
3063}
3064
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003065static bool nl80211_get_ap_channel(struct cfg80211_registered_device *rdev,
3066 struct cfg80211_ap_settings *params)
3067{
3068 struct wireless_dev *wdev;
3069 bool ret = false;
3070
Johannes Berg89a54e42012-06-15 14:33:17 +02003071 list_for_each_entry(wdev, &rdev->wdev_list, list) {
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003072 if (wdev->iftype != NL80211_IFTYPE_AP &&
3073 wdev->iftype != NL80211_IFTYPE_P2P_GO)
3074 continue;
3075
Johannes Berg683b6d32012-11-08 21:25:48 +01003076 if (!wdev->preset_chandef.chan)
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003077 continue;
3078
Johannes Berg683b6d32012-11-08 21:25:48 +01003079 params->chandef = wdev->preset_chandef;
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003080 ret = true;
3081 break;
3082 }
3083
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003084 return ret;
3085}
3086
Jouni Malinene39e5b52012-09-30 19:29:39 +03003087static bool nl80211_valid_auth_type(struct cfg80211_registered_device *rdev,
3088 enum nl80211_auth_type auth_type,
3089 enum nl80211_commands cmd)
3090{
3091 if (auth_type > NL80211_AUTHTYPE_MAX)
3092 return false;
3093
3094 switch (cmd) {
3095 case NL80211_CMD_AUTHENTICATE:
3096 if (!(rdev->wiphy.features & NL80211_FEATURE_SAE) &&
3097 auth_type == NL80211_AUTHTYPE_SAE)
3098 return false;
3099 return true;
3100 case NL80211_CMD_CONNECT:
3101 case NL80211_CMD_START_AP:
3102 /* SAE not supported yet */
3103 if (auth_type == NL80211_AUTHTYPE_SAE)
3104 return false;
3105 return true;
3106 default:
3107 return false;
3108 }
3109}
3110
Johannes Berg88600202012-02-13 15:17:18 +01003111static int nl80211_start_ap(struct sk_buff *skb, struct genl_info *info)
3112{
3113 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3114 struct net_device *dev = info->user_ptr[1];
3115 struct wireless_dev *wdev = dev->ieee80211_ptr;
3116 struct cfg80211_ap_settings params;
3117 int err;
Simon Wunderlich04f39042013-02-08 18:16:19 +01003118 u8 radar_detect_width = 0;
Johannes Berg88600202012-02-13 15:17:18 +01003119
3120 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
3121 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
3122 return -EOPNOTSUPP;
3123
3124 if (!rdev->ops->start_ap)
3125 return -EOPNOTSUPP;
3126
3127 if (wdev->beacon_interval)
3128 return -EALREADY;
3129
3130 memset(&params, 0, sizeof(params));
3131
3132 /* these are required for START_AP */
3133 if (!info->attrs[NL80211_ATTR_BEACON_INTERVAL] ||
3134 !info->attrs[NL80211_ATTR_DTIM_PERIOD] ||
3135 !info->attrs[NL80211_ATTR_BEACON_HEAD])
3136 return -EINVAL;
3137
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003138 err = nl80211_parse_beacon(info->attrs, &params.beacon);
Johannes Berg88600202012-02-13 15:17:18 +01003139 if (err)
3140 return err;
3141
3142 params.beacon_interval =
3143 nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]);
3144 params.dtim_period =
3145 nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]);
3146
3147 err = cfg80211_validate_beacon_int(rdev, params.beacon_interval);
3148 if (err)
3149 return err;
3150
3151 /*
3152 * In theory, some of these attributes should be required here
3153 * but since they were not used when the command was originally
3154 * added, keep them optional for old user space programs to let
3155 * them continue to work with drivers that do not need the
3156 * additional information -- drivers must check!
3157 */
3158 if (info->attrs[NL80211_ATTR_SSID]) {
3159 params.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
3160 params.ssid_len =
3161 nla_len(info->attrs[NL80211_ATTR_SSID]);
3162 if (params.ssid_len == 0 ||
3163 params.ssid_len > IEEE80211_MAX_SSID_LEN)
3164 return -EINVAL;
3165 }
3166
3167 if (info->attrs[NL80211_ATTR_HIDDEN_SSID]) {
3168 params.hidden_ssid = nla_get_u32(
3169 info->attrs[NL80211_ATTR_HIDDEN_SSID]);
3170 if (params.hidden_ssid != NL80211_HIDDEN_SSID_NOT_IN_USE &&
3171 params.hidden_ssid != NL80211_HIDDEN_SSID_ZERO_LEN &&
3172 params.hidden_ssid != NL80211_HIDDEN_SSID_ZERO_CONTENTS)
3173 return -EINVAL;
3174 }
3175
3176 params.privacy = !!info->attrs[NL80211_ATTR_PRIVACY];
3177
3178 if (info->attrs[NL80211_ATTR_AUTH_TYPE]) {
3179 params.auth_type = nla_get_u32(
3180 info->attrs[NL80211_ATTR_AUTH_TYPE]);
Jouni Malinene39e5b52012-09-30 19:29:39 +03003181 if (!nl80211_valid_auth_type(rdev, params.auth_type,
3182 NL80211_CMD_START_AP))
Johannes Berg88600202012-02-13 15:17:18 +01003183 return -EINVAL;
3184 } else
3185 params.auth_type = NL80211_AUTHTYPE_AUTOMATIC;
3186
3187 err = nl80211_crypto_settings(rdev, info, &params.crypto,
3188 NL80211_MAX_NR_CIPHER_SUITES);
3189 if (err)
3190 return err;
3191
Vasanthakumar Thiagarajan1b658f12012-03-02 15:50:02 +05303192 if (info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]) {
3193 if (!(rdev->wiphy.features & NL80211_FEATURE_INACTIVITY_TIMER))
3194 return -EOPNOTSUPP;
3195 params.inactivity_timeout = nla_get_u16(
3196 info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]);
3197 }
3198
Johannes Berg53cabad2012-11-14 15:17:28 +01003199 if (info->attrs[NL80211_ATTR_P2P_CTWINDOW]) {
3200 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
3201 return -EINVAL;
3202 params.p2p_ctwindow =
3203 nla_get_u8(info->attrs[NL80211_ATTR_P2P_CTWINDOW]);
3204 if (params.p2p_ctwindow > 127)
3205 return -EINVAL;
3206 if (params.p2p_ctwindow != 0 &&
3207 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_CTWIN))
3208 return -EINVAL;
3209 }
3210
3211 if (info->attrs[NL80211_ATTR_P2P_OPPPS]) {
3212 u8 tmp;
3213
3214 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
3215 return -EINVAL;
3216 tmp = nla_get_u8(info->attrs[NL80211_ATTR_P2P_OPPPS]);
3217 if (tmp > 1)
3218 return -EINVAL;
3219 params.p2p_opp_ps = tmp;
3220 if (params.p2p_opp_ps != 0 &&
3221 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_OPPPS))
3222 return -EINVAL;
3223 }
3224
Johannes Bergaa430da2012-05-16 23:50:18 +02003225 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
Johannes Berg683b6d32012-11-08 21:25:48 +01003226 err = nl80211_parse_chandef(rdev, info, &params.chandef);
3227 if (err)
3228 return err;
3229 } else if (wdev->preset_chandef.chan) {
3230 params.chandef = wdev->preset_chandef;
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003231 } else if (!nl80211_get_ap_channel(rdev, &params))
Johannes Bergaa430da2012-05-16 23:50:18 +02003232 return -EINVAL;
3233
Johannes Berg683b6d32012-11-08 21:25:48 +01003234 if (!cfg80211_reg_can_beacon(&rdev->wiphy, &params.chandef))
Johannes Bergaa430da2012-05-16 23:50:18 +02003235 return -EINVAL;
3236
Simon Wunderlich04f39042013-02-08 18:16:19 +01003237 err = cfg80211_chandef_dfs_required(wdev->wiphy, &params.chandef);
3238 if (err < 0)
3239 return err;
3240 if (err) {
3241 radar_detect_width = BIT(params.chandef.width);
3242 params.radar_required = true;
3243 }
3244
Simon Wunderlich04f39042013-02-08 18:16:19 +01003245 err = cfg80211_can_use_iftype_chan(rdev, wdev, wdev->iftype,
3246 params.chandef.chan,
3247 CHAN_MODE_SHARED,
3248 radar_detect_width);
Michal Kaziore4e32452012-06-29 12:47:08 +02003249 if (err)
3250 return err;
3251
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +05303252 if (info->attrs[NL80211_ATTR_ACL_POLICY]) {
3253 params.acl = parse_acl_data(&rdev->wiphy, info);
3254 if (IS_ERR(params.acl))
3255 return PTR_ERR(params.acl);
3256 }
3257
Simon Wunderlichc56589e2013-11-21 18:19:49 +01003258 wdev_lock(wdev);
Hila Gonene35e4d22012-06-27 17:19:42 +03003259 err = rdev_start_ap(rdev, dev, &params);
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003260 if (!err) {
Johannes Berg683b6d32012-11-08 21:25:48 +01003261 wdev->preset_chandef = params.chandef;
Johannes Berg88600202012-02-13 15:17:18 +01003262 wdev->beacon_interval = params.beacon_interval;
Johannes Berg683b6d32012-11-08 21:25:48 +01003263 wdev->channel = params.chandef.chan;
Antonio Quartulli06e191e2012-11-07 12:52:19 +01003264 wdev->ssid_len = params.ssid_len;
3265 memcpy(wdev->ssid, params.ssid, wdev->ssid_len);
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003266 }
Simon Wunderlichc56589e2013-11-21 18:19:49 +01003267 wdev_unlock(wdev);
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +05303268
3269 kfree(params.acl);
3270
Johannes Berg56d18932011-05-09 18:41:15 +02003271 return err;
Johannes Berged1b6cc2007-12-19 02:03:32 +01003272}
3273
Johannes Berg88600202012-02-13 15:17:18 +01003274static int nl80211_set_beacon(struct sk_buff *skb, struct genl_info *info)
3275{
3276 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3277 struct net_device *dev = info->user_ptr[1];
3278 struct wireless_dev *wdev = dev->ieee80211_ptr;
3279 struct cfg80211_beacon_data params;
3280 int err;
3281
3282 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
3283 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
3284 return -EOPNOTSUPP;
3285
3286 if (!rdev->ops->change_beacon)
3287 return -EOPNOTSUPP;
3288
3289 if (!wdev->beacon_interval)
3290 return -EINVAL;
3291
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003292 err = nl80211_parse_beacon(info->attrs, &params);
Johannes Berg88600202012-02-13 15:17:18 +01003293 if (err)
3294 return err;
3295
Simon Wunderlichc56589e2013-11-21 18:19:49 +01003296 wdev_lock(wdev);
3297 err = rdev_change_beacon(rdev, dev, &params);
3298 wdev_unlock(wdev);
3299
3300 return err;
Johannes Berg88600202012-02-13 15:17:18 +01003301}
3302
3303static int nl80211_stop_ap(struct sk_buff *skb, struct genl_info *info)
Johannes Berged1b6cc2007-12-19 02:03:32 +01003304{
Johannes Berg4c476992010-10-04 21:36:35 +02003305 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3306 struct net_device *dev = info->user_ptr[1];
Johannes Berged1b6cc2007-12-19 02:03:32 +01003307
Michal Kazior60771782012-06-29 12:46:56 +02003308 return cfg80211_stop_ap(rdev, dev);
Johannes Berged1b6cc2007-12-19 02:03:32 +01003309}
3310
Johannes Berg5727ef12007-12-19 02:03:34 +01003311static const struct nla_policy sta_flags_policy[NL80211_STA_FLAG_MAX + 1] = {
3312 [NL80211_STA_FLAG_AUTHORIZED] = { .type = NLA_FLAG },
3313 [NL80211_STA_FLAG_SHORT_PREAMBLE] = { .type = NLA_FLAG },
3314 [NL80211_STA_FLAG_WME] = { .type = NLA_FLAG },
Jouni Malinen0e467242009-05-11 21:57:55 +03003315 [NL80211_STA_FLAG_MFP] = { .type = NLA_FLAG },
Javier Cardonab39c48f2011-04-07 15:08:30 -07003316 [NL80211_STA_FLAG_AUTHENTICATED] = { .type = NLA_FLAG },
Johannes Bergd83023d2011-12-14 09:29:15 +01003317 [NL80211_STA_FLAG_TDLS_PEER] = { .type = NLA_FLAG },
Johannes Berg5727ef12007-12-19 02:03:34 +01003318};
3319
Johannes Bergeccb8e82009-05-11 21:57:56 +03003320static int parse_station_flags(struct genl_info *info,
Johannes Bergbdd3ae32012-01-02 13:30:03 +01003321 enum nl80211_iftype iftype,
Johannes Bergeccb8e82009-05-11 21:57:56 +03003322 struct station_parameters *params)
Johannes Berg5727ef12007-12-19 02:03:34 +01003323{
3324 struct nlattr *flags[NL80211_STA_FLAG_MAX + 1];
Johannes Bergeccb8e82009-05-11 21:57:56 +03003325 struct nlattr *nla;
Johannes Berg5727ef12007-12-19 02:03:34 +01003326 int flag;
3327
Johannes Bergeccb8e82009-05-11 21:57:56 +03003328 /*
3329 * Try parsing the new attribute first so userspace
3330 * can specify both for older kernels.
3331 */
3332 nla = info->attrs[NL80211_ATTR_STA_FLAGS2];
3333 if (nla) {
3334 struct nl80211_sta_flag_update *sta_flags;
Johannes Berg5727ef12007-12-19 02:03:34 +01003335
Johannes Bergeccb8e82009-05-11 21:57:56 +03003336 sta_flags = nla_data(nla);
3337 params->sta_flags_mask = sta_flags->mask;
3338 params->sta_flags_set = sta_flags->set;
Johannes Berg77ee7c82013-02-15 00:48:33 +01003339 params->sta_flags_set &= params->sta_flags_mask;
Johannes Bergeccb8e82009-05-11 21:57:56 +03003340 if ((params->sta_flags_mask |
3341 params->sta_flags_set) & BIT(__NL80211_STA_FLAG_INVALID))
3342 return -EINVAL;
3343 return 0;
3344 }
3345
3346 /* if present, parse the old attribute */
3347
3348 nla = info->attrs[NL80211_ATTR_STA_FLAGS];
Johannes Berg5727ef12007-12-19 02:03:34 +01003349 if (!nla)
3350 return 0;
3351
3352 if (nla_parse_nested(flags, NL80211_STA_FLAG_MAX,
3353 nla, sta_flags_policy))
3354 return -EINVAL;
3355
Johannes Bergbdd3ae32012-01-02 13:30:03 +01003356 /*
3357 * Only allow certain flags for interface types so that
3358 * other attributes are silently ignored. Remember that
3359 * this is backward compatibility code with old userspace
3360 * and shouldn't be hit in other cases anyway.
3361 */
3362 switch (iftype) {
3363 case NL80211_IFTYPE_AP:
3364 case NL80211_IFTYPE_AP_VLAN:
3365 case NL80211_IFTYPE_P2P_GO:
3366 params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) |
3367 BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) |
3368 BIT(NL80211_STA_FLAG_WME) |
3369 BIT(NL80211_STA_FLAG_MFP);
3370 break;
3371 case NL80211_IFTYPE_P2P_CLIENT:
3372 case NL80211_IFTYPE_STATION:
3373 params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) |
3374 BIT(NL80211_STA_FLAG_TDLS_PEER);
3375 break;
3376 case NL80211_IFTYPE_MESH_POINT:
3377 params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHENTICATED) |
3378 BIT(NL80211_STA_FLAG_MFP) |
3379 BIT(NL80211_STA_FLAG_AUTHORIZED);
3380 default:
3381 return -EINVAL;
3382 }
Johannes Berg5727ef12007-12-19 02:03:34 +01003383
Johannes Berg3383b5a2012-05-10 20:14:43 +02003384 for (flag = 1; flag <= NL80211_STA_FLAG_MAX; flag++) {
3385 if (flags[flag]) {
Johannes Bergeccb8e82009-05-11 21:57:56 +03003386 params->sta_flags_set |= (1<<flag);
Johannes Berg5727ef12007-12-19 02:03:34 +01003387
Johannes Berg3383b5a2012-05-10 20:14:43 +02003388 /* no longer support new API additions in old API */
3389 if (flag > NL80211_STA_FLAG_MAX_OLD_API)
3390 return -EINVAL;
3391 }
3392 }
3393
Johannes Berg5727ef12007-12-19 02:03:34 +01003394 return 0;
3395}
3396
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003397static bool nl80211_put_sta_rate(struct sk_buff *msg, struct rate_info *info,
3398 int attr)
3399{
3400 struct nlattr *rate;
Vladimir Kondratiev8eb41c82012-07-05 14:25:49 +03003401 u32 bitrate;
3402 u16 bitrate_compat;
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003403
3404 rate = nla_nest_start(msg, attr);
3405 if (!rate)
Johannes Bergdb9c64c2012-11-09 14:56:41 +01003406 return false;
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003407
3408 /* cfg80211_calculate_bitrate will return 0 for mcs >= 32 */
3409 bitrate = cfg80211_calculate_bitrate(info);
Vladimir Kondratiev8eb41c82012-07-05 14:25:49 +03003410 /* report 16-bit bitrate only if we can */
3411 bitrate_compat = bitrate < (1UL << 16) ? bitrate : 0;
Johannes Bergdb9c64c2012-11-09 14:56:41 +01003412 if (bitrate > 0 &&
3413 nla_put_u32(msg, NL80211_RATE_INFO_BITRATE32, bitrate))
3414 return false;
3415 if (bitrate_compat > 0 &&
3416 nla_put_u16(msg, NL80211_RATE_INFO_BITRATE, bitrate_compat))
3417 return false;
3418
3419 if (info->flags & RATE_INFO_FLAGS_MCS) {
3420 if (nla_put_u8(msg, NL80211_RATE_INFO_MCS, info->mcs))
3421 return false;
3422 if (info->flags & RATE_INFO_FLAGS_40_MHZ_WIDTH &&
3423 nla_put_flag(msg, NL80211_RATE_INFO_40_MHZ_WIDTH))
3424 return false;
3425 if (info->flags & RATE_INFO_FLAGS_SHORT_GI &&
3426 nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI))
3427 return false;
3428 } else if (info->flags & RATE_INFO_FLAGS_VHT_MCS) {
3429 if (nla_put_u8(msg, NL80211_RATE_INFO_VHT_MCS, info->mcs))
3430 return false;
3431 if (nla_put_u8(msg, NL80211_RATE_INFO_VHT_NSS, info->nss))
3432 return false;
3433 if (info->flags & RATE_INFO_FLAGS_40_MHZ_WIDTH &&
3434 nla_put_flag(msg, NL80211_RATE_INFO_40_MHZ_WIDTH))
3435 return false;
3436 if (info->flags & RATE_INFO_FLAGS_80_MHZ_WIDTH &&
3437 nla_put_flag(msg, NL80211_RATE_INFO_80_MHZ_WIDTH))
3438 return false;
3439 if (info->flags & RATE_INFO_FLAGS_80P80_MHZ_WIDTH &&
3440 nla_put_flag(msg, NL80211_RATE_INFO_80P80_MHZ_WIDTH))
3441 return false;
3442 if (info->flags & RATE_INFO_FLAGS_160_MHZ_WIDTH &&
3443 nla_put_flag(msg, NL80211_RATE_INFO_160_MHZ_WIDTH))
3444 return false;
3445 if (info->flags & RATE_INFO_FLAGS_SHORT_GI &&
3446 nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI))
3447 return false;
3448 }
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003449
3450 nla_nest_end(msg, rate);
3451 return true;
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003452}
3453
Felix Fietkau119363c2013-04-22 16:29:30 +02003454static bool nl80211_put_signal(struct sk_buff *msg, u8 mask, s8 *signal,
3455 int id)
3456{
3457 void *attr;
3458 int i = 0;
3459
3460 if (!mask)
3461 return true;
3462
3463 attr = nla_nest_start(msg, id);
3464 if (!attr)
3465 return false;
3466
3467 for (i = 0; i < IEEE80211_MAX_CHAINS; i++) {
3468 if (!(mask & BIT(i)))
3469 continue;
3470
3471 if (nla_put_u8(msg, i, signal[i]))
3472 return false;
3473 }
3474
3475 nla_nest_end(msg, attr);
3476
3477 return true;
3478}
3479
Eric W. Biederman15e47302012-09-07 20:12:54 +00003480static int nl80211_send_station(struct sk_buff *msg, u32 portid, u32 seq,
John W. Linville66266b32012-03-15 13:25:41 -04003481 int flags,
3482 struct cfg80211_registered_device *rdev,
3483 struct net_device *dev,
Johannes Berg98b62182009-12-23 13:15:44 +01003484 const u8 *mac_addr, struct station_info *sinfo)
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003485{
3486 void *hdr;
Paul Stewartf4263c92011-03-31 09:25:41 -07003487 struct nlattr *sinfoattr, *bss_param;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003488
Eric W. Biederman15e47302012-09-07 20:12:54 +00003489 hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_STATION);
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003490 if (!hdr)
3491 return -1;
3492
David S. Miller9360ffd2012-03-29 04:41:26 -04003493 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
3494 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) ||
3495 nla_put_u32(msg, NL80211_ATTR_GENERATION, sinfo->generation))
3496 goto nla_put_failure;
Johannes Bergf5ea9122009-08-07 16:17:38 +02003497
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003498 sinfoattr = nla_nest_start(msg, NL80211_ATTR_STA_INFO);
3499 if (!sinfoattr)
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003500 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04003501 if ((sinfo->filled & STATION_INFO_CONNECTED_TIME) &&
3502 nla_put_u32(msg, NL80211_STA_INFO_CONNECTED_TIME,
3503 sinfo->connected_time))
3504 goto nla_put_failure;
3505 if ((sinfo->filled & STATION_INFO_INACTIVE_TIME) &&
3506 nla_put_u32(msg, NL80211_STA_INFO_INACTIVE_TIME,
3507 sinfo->inactive_time))
3508 goto nla_put_failure;
Vladimir Kondratiev42745e02013-02-04 13:53:11 +02003509 if ((sinfo->filled & (STATION_INFO_RX_BYTES |
3510 STATION_INFO_RX_BYTES64)) &&
David S. Miller9360ffd2012-03-29 04:41:26 -04003511 nla_put_u32(msg, NL80211_STA_INFO_RX_BYTES,
Vladimir Kondratiev42745e02013-02-04 13:53:11 +02003512 (u32)sinfo->rx_bytes))
3513 goto nla_put_failure;
3514 if ((sinfo->filled & (STATION_INFO_TX_BYTES |
Felix Fietkau4325d722013-05-23 15:05:59 +02003515 STATION_INFO_TX_BYTES64)) &&
Vladimir Kondratiev42745e02013-02-04 13:53:11 +02003516 nla_put_u32(msg, NL80211_STA_INFO_TX_BYTES,
3517 (u32)sinfo->tx_bytes))
3518 goto nla_put_failure;
3519 if ((sinfo->filled & STATION_INFO_RX_BYTES64) &&
3520 nla_put_u64(msg, NL80211_STA_INFO_RX_BYTES64,
David S. Miller9360ffd2012-03-29 04:41:26 -04003521 sinfo->rx_bytes))
3522 goto nla_put_failure;
Vladimir Kondratiev42745e02013-02-04 13:53:11 +02003523 if ((sinfo->filled & STATION_INFO_TX_BYTES64) &&
3524 nla_put_u64(msg, NL80211_STA_INFO_TX_BYTES64,
David S. Miller9360ffd2012-03-29 04:41:26 -04003525 sinfo->tx_bytes))
3526 goto nla_put_failure;
3527 if ((sinfo->filled & STATION_INFO_LLID) &&
3528 nla_put_u16(msg, NL80211_STA_INFO_LLID, sinfo->llid))
3529 goto nla_put_failure;
3530 if ((sinfo->filled & STATION_INFO_PLID) &&
3531 nla_put_u16(msg, NL80211_STA_INFO_PLID, sinfo->plid))
3532 goto nla_put_failure;
3533 if ((sinfo->filled & STATION_INFO_PLINK_STATE) &&
3534 nla_put_u8(msg, NL80211_STA_INFO_PLINK_STATE,
3535 sinfo->plink_state))
3536 goto nla_put_failure;
John W. Linville66266b32012-03-15 13:25:41 -04003537 switch (rdev->wiphy.signal_type) {
3538 case CFG80211_SIGNAL_TYPE_MBM:
David S. Miller9360ffd2012-03-29 04:41:26 -04003539 if ((sinfo->filled & STATION_INFO_SIGNAL) &&
3540 nla_put_u8(msg, NL80211_STA_INFO_SIGNAL,
3541 sinfo->signal))
3542 goto nla_put_failure;
3543 if ((sinfo->filled & STATION_INFO_SIGNAL_AVG) &&
3544 nla_put_u8(msg, NL80211_STA_INFO_SIGNAL_AVG,
3545 sinfo->signal_avg))
3546 goto nla_put_failure;
John W. Linville66266b32012-03-15 13:25:41 -04003547 break;
3548 default:
3549 break;
3550 }
Felix Fietkau119363c2013-04-22 16:29:30 +02003551 if (sinfo->filled & STATION_INFO_CHAIN_SIGNAL) {
3552 if (!nl80211_put_signal(msg, sinfo->chains,
3553 sinfo->chain_signal,
3554 NL80211_STA_INFO_CHAIN_SIGNAL))
3555 goto nla_put_failure;
3556 }
3557 if (sinfo->filled & STATION_INFO_CHAIN_SIGNAL_AVG) {
3558 if (!nl80211_put_signal(msg, sinfo->chains,
3559 sinfo->chain_signal_avg,
3560 NL80211_STA_INFO_CHAIN_SIGNAL_AVG))
3561 goto nla_put_failure;
3562 }
Henning Rogge420e7fa2008-12-11 22:04:19 +01003563 if (sinfo->filled & STATION_INFO_TX_BITRATE) {
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003564 if (!nl80211_put_sta_rate(msg, &sinfo->txrate,
3565 NL80211_STA_INFO_TX_BITRATE))
Henning Rogge420e7fa2008-12-11 22:04:19 +01003566 goto nla_put_failure;
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003567 }
3568 if (sinfo->filled & STATION_INFO_RX_BITRATE) {
3569 if (!nl80211_put_sta_rate(msg, &sinfo->rxrate,
3570 NL80211_STA_INFO_RX_BITRATE))
3571 goto nla_put_failure;
Henning Rogge420e7fa2008-12-11 22:04:19 +01003572 }
David S. Miller9360ffd2012-03-29 04:41:26 -04003573 if ((sinfo->filled & STATION_INFO_RX_PACKETS) &&
3574 nla_put_u32(msg, NL80211_STA_INFO_RX_PACKETS,
3575 sinfo->rx_packets))
3576 goto nla_put_failure;
3577 if ((sinfo->filled & STATION_INFO_TX_PACKETS) &&
3578 nla_put_u32(msg, NL80211_STA_INFO_TX_PACKETS,
3579 sinfo->tx_packets))
3580 goto nla_put_failure;
3581 if ((sinfo->filled & STATION_INFO_TX_RETRIES) &&
3582 nla_put_u32(msg, NL80211_STA_INFO_TX_RETRIES,
3583 sinfo->tx_retries))
3584 goto nla_put_failure;
3585 if ((sinfo->filled & STATION_INFO_TX_FAILED) &&
3586 nla_put_u32(msg, NL80211_STA_INFO_TX_FAILED,
3587 sinfo->tx_failed))
3588 goto nla_put_failure;
3589 if ((sinfo->filled & STATION_INFO_BEACON_LOSS_COUNT) &&
3590 nla_put_u32(msg, NL80211_STA_INFO_BEACON_LOSS,
3591 sinfo->beacon_loss_count))
3592 goto nla_put_failure;
Marco Porsch3b1c5a52013-01-07 16:04:52 +01003593 if ((sinfo->filled & STATION_INFO_LOCAL_PM) &&
3594 nla_put_u32(msg, NL80211_STA_INFO_LOCAL_PM,
3595 sinfo->local_pm))
3596 goto nla_put_failure;
3597 if ((sinfo->filled & STATION_INFO_PEER_PM) &&
3598 nla_put_u32(msg, NL80211_STA_INFO_PEER_PM,
3599 sinfo->peer_pm))
3600 goto nla_put_failure;
3601 if ((sinfo->filled & STATION_INFO_NONPEER_PM) &&
3602 nla_put_u32(msg, NL80211_STA_INFO_NONPEER_PM,
3603 sinfo->nonpeer_pm))
3604 goto nla_put_failure;
Paul Stewartf4263c92011-03-31 09:25:41 -07003605 if (sinfo->filled & STATION_INFO_BSS_PARAM) {
3606 bss_param = nla_nest_start(msg, NL80211_STA_INFO_BSS_PARAM);
3607 if (!bss_param)
3608 goto nla_put_failure;
3609
David S. Miller9360ffd2012-03-29 04:41:26 -04003610 if (((sinfo->bss_param.flags & BSS_PARAM_FLAGS_CTS_PROT) &&
3611 nla_put_flag(msg, NL80211_STA_BSS_PARAM_CTS_PROT)) ||
3612 ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_PREAMBLE) &&
3613 nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_PREAMBLE)) ||
3614 ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_SLOT_TIME) &&
3615 nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_SLOT_TIME)) ||
3616 nla_put_u8(msg, NL80211_STA_BSS_PARAM_DTIM_PERIOD,
3617 sinfo->bss_param.dtim_period) ||
3618 nla_put_u16(msg, NL80211_STA_BSS_PARAM_BEACON_INTERVAL,
3619 sinfo->bss_param.beacon_interval))
3620 goto nla_put_failure;
Paul Stewartf4263c92011-03-31 09:25:41 -07003621
3622 nla_nest_end(msg, bss_param);
3623 }
David S. Miller9360ffd2012-03-29 04:41:26 -04003624 if ((sinfo->filled & STATION_INFO_STA_FLAGS) &&
3625 nla_put(msg, NL80211_STA_INFO_STA_FLAGS,
3626 sizeof(struct nl80211_sta_flag_update),
3627 &sinfo->sta_flags))
3628 goto nla_put_failure;
John W. Linville7eab0f62012-04-12 14:25:14 -04003629 if ((sinfo->filled & STATION_INFO_T_OFFSET) &&
3630 nla_put_u64(msg, NL80211_STA_INFO_T_OFFSET,
3631 sinfo->t_offset))
3632 goto nla_put_failure;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003633 nla_nest_end(msg, sinfoattr);
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003634
David S. Miller9360ffd2012-03-29 04:41:26 -04003635 if ((sinfo->filled & STATION_INFO_ASSOC_REQ_IES) &&
3636 nla_put(msg, NL80211_ATTR_IE, sinfo->assoc_req_ies_len,
3637 sinfo->assoc_req_ies))
3638 goto nla_put_failure;
Jouni Malinen50d3dfb2011-08-08 12:11:52 +03003639
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003640 return genlmsg_end(msg, hdr);
3641
3642 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07003643 genlmsg_cancel(msg, hdr);
3644 return -EMSGSIZE;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003645}
3646
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003647static int nl80211_dump_station(struct sk_buff *skb,
Johannes Bergbba95fe2008-07-29 13:22:51 +02003648 struct netlink_callback *cb)
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003649{
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003650 struct station_info sinfo;
3651 struct cfg80211_registered_device *dev;
Johannes Berg97990a02013-04-19 01:02:55 +02003652 struct wireless_dev *wdev;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003653 u8 mac_addr[ETH_ALEN];
Johannes Berg97990a02013-04-19 01:02:55 +02003654 int sta_idx = cb->args[2];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003655 int err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003656
Johannes Berg97990a02013-04-19 01:02:55 +02003657 err = nl80211_prepare_wdev_dump(skb, cb, &dev, &wdev);
Johannes Berg67748892010-10-04 21:14:06 +02003658 if (err)
3659 return err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02003660
Johannes Berg97990a02013-04-19 01:02:55 +02003661 if (!wdev->netdev) {
3662 err = -EINVAL;
3663 goto out_err;
3664 }
3665
Johannes Bergbba95fe2008-07-29 13:22:51 +02003666 if (!dev->ops->dump_station) {
Jouni Malineneec60b02009-03-20 21:21:19 +02003667 err = -EOPNOTSUPP;
Johannes Bergbba95fe2008-07-29 13:22:51 +02003668 goto out_err;
3669 }
3670
Johannes Bergbba95fe2008-07-29 13:22:51 +02003671 while (1) {
Jouni Malinenf612ced2011-08-11 11:46:22 +03003672 memset(&sinfo, 0, sizeof(sinfo));
Johannes Berg97990a02013-04-19 01:02:55 +02003673 err = rdev_dump_station(dev, wdev->netdev, sta_idx,
Hila Gonene35e4d22012-06-27 17:19:42 +03003674 mac_addr, &sinfo);
Johannes Bergbba95fe2008-07-29 13:22:51 +02003675 if (err == -ENOENT)
3676 break;
3677 if (err)
Johannes Berg3b858752009-03-12 09:55:09 +01003678 goto out_err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02003679
3680 if (nl80211_send_station(skb,
Eric W. Biederman15e47302012-09-07 20:12:54 +00003681 NETLINK_CB(cb->skb).portid,
Johannes Bergbba95fe2008-07-29 13:22:51 +02003682 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Johannes Berg97990a02013-04-19 01:02:55 +02003683 dev, wdev->netdev, mac_addr,
Johannes Bergbba95fe2008-07-29 13:22:51 +02003684 &sinfo) < 0)
3685 goto out;
3686
3687 sta_idx++;
3688 }
3689
3690
3691 out:
Johannes Berg97990a02013-04-19 01:02:55 +02003692 cb->args[2] = sta_idx;
Johannes Bergbba95fe2008-07-29 13:22:51 +02003693 err = skb->len;
Johannes Bergbba95fe2008-07-29 13:22:51 +02003694 out_err:
Johannes Berg97990a02013-04-19 01:02:55 +02003695 nl80211_finish_wdev_dump(dev);
Johannes Bergbba95fe2008-07-29 13:22:51 +02003696
3697 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003698}
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003699
Johannes Berg5727ef12007-12-19 02:03:34 +01003700static int nl80211_get_station(struct sk_buff *skb, struct genl_info *info)
3701{
Johannes Berg4c476992010-10-04 21:36:35 +02003702 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3703 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003704 struct station_info sinfo;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003705 struct sk_buff *msg;
3706 u8 *mac_addr = NULL;
Johannes Berg4c476992010-10-04 21:36:35 +02003707 int err;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003708
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003709 memset(&sinfo, 0, sizeof(sinfo));
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003710
3711 if (!info->attrs[NL80211_ATTR_MAC])
3712 return -EINVAL;
3713
3714 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
3715
Johannes Berg4c476992010-10-04 21:36:35 +02003716 if (!rdev->ops->get_station)
3717 return -EOPNOTSUPP;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003718
Hila Gonene35e4d22012-06-27 17:19:42 +03003719 err = rdev_get_station(rdev, dev, mac_addr, &sinfo);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003720 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02003721 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003722
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07003723 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003724 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02003725 return -ENOMEM;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003726
Eric W. Biederman15e47302012-09-07 20:12:54 +00003727 if (nl80211_send_station(msg, info->snd_portid, info->snd_seq, 0,
John W. Linville66266b32012-03-15 13:25:41 -04003728 rdev, dev, mac_addr, &sinfo) < 0) {
Johannes Berg4c476992010-10-04 21:36:35 +02003729 nlmsg_free(msg);
3730 return -ENOBUFS;
3731 }
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003732
Johannes Berg4c476992010-10-04 21:36:35 +02003733 return genlmsg_reply(msg, info);
Johannes Berg5727ef12007-12-19 02:03:34 +01003734}
3735
Johannes Berg77ee7c82013-02-15 00:48:33 +01003736int cfg80211_check_station_change(struct wiphy *wiphy,
3737 struct station_parameters *params,
3738 enum cfg80211_station_type statype)
3739{
3740 if (params->listen_interval != -1)
3741 return -EINVAL;
3742 if (params->aid)
3743 return -EINVAL;
3744
3745 /* When you run into this, adjust the code below for the new flag */
3746 BUILD_BUG_ON(NL80211_STA_FLAG_MAX != 7);
3747
3748 switch (statype) {
Thomas Pederseneef941e2013-03-04 13:06:11 -08003749 case CFG80211_STA_MESH_PEER_KERNEL:
3750 case CFG80211_STA_MESH_PEER_USER:
Johannes Berg77ee7c82013-02-15 00:48:33 +01003751 /*
3752 * No ignoring the TDLS flag here -- the userspace mesh
3753 * code doesn't have the bug of including TDLS in the
3754 * mask everywhere.
3755 */
3756 if (params->sta_flags_mask &
3757 ~(BIT(NL80211_STA_FLAG_AUTHENTICATED) |
3758 BIT(NL80211_STA_FLAG_MFP) |
3759 BIT(NL80211_STA_FLAG_AUTHORIZED)))
3760 return -EINVAL;
3761 break;
3762 case CFG80211_STA_TDLS_PEER_SETUP:
3763 case CFG80211_STA_TDLS_PEER_ACTIVE:
3764 if (!(params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)))
3765 return -EINVAL;
3766 /* ignore since it can't change */
3767 params->sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER);
3768 break;
3769 default:
3770 /* disallow mesh-specific things */
3771 if (params->plink_action != NL80211_PLINK_ACTION_NO_ACTION)
3772 return -EINVAL;
3773 if (params->local_pm)
3774 return -EINVAL;
3775 if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE)
3776 return -EINVAL;
3777 }
3778
3779 if (statype != CFG80211_STA_TDLS_PEER_SETUP &&
3780 statype != CFG80211_STA_TDLS_PEER_ACTIVE) {
3781 /* TDLS can't be set, ... */
3782 if (params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))
3783 return -EINVAL;
3784 /*
3785 * ... but don't bother the driver with it. This works around
3786 * a hostapd/wpa_supplicant issue -- it always includes the
3787 * TLDS_PEER flag in the mask even for AP mode.
3788 */
3789 params->sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER);
3790 }
3791
3792 if (statype != CFG80211_STA_TDLS_PEER_SETUP) {
3793 /* reject other things that can't change */
3794 if (params->sta_modify_mask & STATION_PARAM_APPLY_UAPSD)
3795 return -EINVAL;
3796 if (params->sta_modify_mask & STATION_PARAM_APPLY_CAPABILITY)
3797 return -EINVAL;
3798 if (params->supported_rates)
3799 return -EINVAL;
3800 if (params->ext_capab || params->ht_capa || params->vht_capa)
3801 return -EINVAL;
3802 }
3803
3804 if (statype != CFG80211_STA_AP_CLIENT) {
3805 if (params->vlan)
3806 return -EINVAL;
3807 }
3808
3809 switch (statype) {
3810 case CFG80211_STA_AP_MLME_CLIENT:
3811 /* Use this only for authorizing/unauthorizing a station */
3812 if (!(params->sta_flags_mask & BIT(NL80211_STA_FLAG_AUTHORIZED)))
3813 return -EOPNOTSUPP;
3814 break;
3815 case CFG80211_STA_AP_CLIENT:
3816 /* accept only the listed bits */
3817 if (params->sta_flags_mask &
3818 ~(BIT(NL80211_STA_FLAG_AUTHORIZED) |
3819 BIT(NL80211_STA_FLAG_AUTHENTICATED) |
3820 BIT(NL80211_STA_FLAG_ASSOCIATED) |
3821 BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) |
3822 BIT(NL80211_STA_FLAG_WME) |
3823 BIT(NL80211_STA_FLAG_MFP)))
3824 return -EINVAL;
3825
3826 /* but authenticated/associated only if driver handles it */
3827 if (!(wiphy->features & NL80211_FEATURE_FULL_AP_CLIENT_STATE) &&
3828 params->sta_flags_mask &
3829 (BIT(NL80211_STA_FLAG_AUTHENTICATED) |
3830 BIT(NL80211_STA_FLAG_ASSOCIATED)))
3831 return -EINVAL;
3832 break;
3833 case CFG80211_STA_IBSS:
3834 case CFG80211_STA_AP_STA:
3835 /* reject any changes other than AUTHORIZED */
3836 if (params->sta_flags_mask & ~BIT(NL80211_STA_FLAG_AUTHORIZED))
3837 return -EINVAL;
3838 break;
3839 case CFG80211_STA_TDLS_PEER_SETUP:
3840 /* reject any changes other than AUTHORIZED or WME */
3841 if (params->sta_flags_mask & ~(BIT(NL80211_STA_FLAG_AUTHORIZED) |
3842 BIT(NL80211_STA_FLAG_WME)))
3843 return -EINVAL;
3844 /* force (at least) rates when authorizing */
3845 if (params->sta_flags_set & BIT(NL80211_STA_FLAG_AUTHORIZED) &&
3846 !params->supported_rates)
3847 return -EINVAL;
3848 break;
3849 case CFG80211_STA_TDLS_PEER_ACTIVE:
3850 /* reject any changes */
3851 return -EINVAL;
Thomas Pederseneef941e2013-03-04 13:06:11 -08003852 case CFG80211_STA_MESH_PEER_KERNEL:
Johannes Berg77ee7c82013-02-15 00:48:33 +01003853 if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE)
3854 return -EINVAL;
3855 break;
Thomas Pederseneef941e2013-03-04 13:06:11 -08003856 case CFG80211_STA_MESH_PEER_USER:
Johannes Berg77ee7c82013-02-15 00:48:33 +01003857 if (params->plink_action != NL80211_PLINK_ACTION_NO_ACTION)
3858 return -EINVAL;
3859 break;
3860 }
3861
3862 return 0;
3863}
3864EXPORT_SYMBOL(cfg80211_check_station_change);
3865
Johannes Berg5727ef12007-12-19 02:03:34 +01003866/*
Felix Fietkauc258d2d2009-11-11 17:23:31 +01003867 * Get vlan interface making sure it is running and on the right wiphy.
Johannes Berg5727ef12007-12-19 02:03:34 +01003868 */
Johannes Berg80b99892011-11-18 16:23:01 +01003869static struct net_device *get_vlan(struct genl_info *info,
3870 struct cfg80211_registered_device *rdev)
Johannes Berg5727ef12007-12-19 02:03:34 +01003871{
Johannes Berg463d0182009-07-14 00:33:35 +02003872 struct nlattr *vlanattr = info->attrs[NL80211_ATTR_STA_VLAN];
Johannes Berg80b99892011-11-18 16:23:01 +01003873 struct net_device *v;
3874 int ret;
Johannes Berg5727ef12007-12-19 02:03:34 +01003875
Johannes Berg80b99892011-11-18 16:23:01 +01003876 if (!vlanattr)
3877 return NULL;
3878
3879 v = dev_get_by_index(genl_info_net(info), nla_get_u32(vlanattr));
3880 if (!v)
3881 return ERR_PTR(-ENODEV);
3882
3883 if (!v->ieee80211_ptr || v->ieee80211_ptr->wiphy != &rdev->wiphy) {
3884 ret = -EINVAL;
3885 goto error;
Johannes Berg5727ef12007-12-19 02:03:34 +01003886 }
Johannes Berg80b99892011-11-18 16:23:01 +01003887
Johannes Berg77ee7c82013-02-15 00:48:33 +01003888 if (v->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN &&
3889 v->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
3890 v->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) {
3891 ret = -EINVAL;
3892 goto error;
3893 }
3894
Johannes Berg80b99892011-11-18 16:23:01 +01003895 if (!netif_running(v)) {
3896 ret = -ENETDOWN;
3897 goto error;
3898 }
3899
3900 return v;
3901 error:
3902 dev_put(v);
3903 return ERR_PTR(ret);
Johannes Berg5727ef12007-12-19 02:03:34 +01003904}
3905
Jouni Malinendf881292013-02-14 21:10:54 +02003906static struct nla_policy
3907nl80211_sta_wme_policy[NL80211_STA_WME_MAX + 1] __read_mostly = {
3908 [NL80211_STA_WME_UAPSD_QUEUES] = { .type = NLA_U8 },
3909 [NL80211_STA_WME_MAX_SP] = { .type = NLA_U8 },
3910};
3911
Johannes Bergff276692013-02-15 00:09:01 +01003912static int nl80211_parse_sta_wme(struct genl_info *info,
3913 struct station_parameters *params)
Jouni Malinendf881292013-02-14 21:10:54 +02003914{
Jouni Malinendf881292013-02-14 21:10:54 +02003915 struct nlattr *tb[NL80211_STA_WME_MAX + 1];
3916 struct nlattr *nla;
3917 int err;
3918
Jouni Malinendf881292013-02-14 21:10:54 +02003919 /* parse WME attributes if present */
3920 if (!info->attrs[NL80211_ATTR_STA_WME])
3921 return 0;
3922
3923 nla = info->attrs[NL80211_ATTR_STA_WME];
3924 err = nla_parse_nested(tb, NL80211_STA_WME_MAX, nla,
3925 nl80211_sta_wme_policy);
3926 if (err)
3927 return err;
3928
3929 if (tb[NL80211_STA_WME_UAPSD_QUEUES])
3930 params->uapsd_queues = nla_get_u8(
3931 tb[NL80211_STA_WME_UAPSD_QUEUES]);
3932 if (params->uapsd_queues & ~IEEE80211_WMM_IE_STA_QOSINFO_AC_MASK)
3933 return -EINVAL;
3934
3935 if (tb[NL80211_STA_WME_MAX_SP])
3936 params->max_sp = nla_get_u8(tb[NL80211_STA_WME_MAX_SP]);
3937
3938 if (params->max_sp & ~IEEE80211_WMM_IE_STA_QOSINFO_SP_MASK)
3939 return -EINVAL;
3940
3941 params->sta_modify_mask |= STATION_PARAM_APPLY_UAPSD;
3942
3943 return 0;
3944}
3945
Sunil Duttc01fc9a2013-10-09 20:45:21 +05303946static int nl80211_parse_sta_channel_info(struct genl_info *info,
3947 struct station_parameters *params)
3948{
3949 if (info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]) {
3950 params->supported_channels =
3951 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]);
3952 params->supported_channels_len =
3953 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]);
3954 /*
3955 * Need to include at least one (first channel, number of
3956 * channels) tuple for each subband, and must have proper
3957 * tuples for the rest of the data as well.
3958 */
3959 if (params->supported_channels_len < 2)
3960 return -EINVAL;
3961 if (params->supported_channels_len % 2)
3962 return -EINVAL;
3963 }
3964
3965 if (info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]) {
3966 params->supported_oper_classes =
3967 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]);
3968 params->supported_oper_classes_len =
3969 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]);
3970 /*
3971 * The value of the Length field of the Supported Operating
3972 * Classes element is between 2 and 253.
3973 */
3974 if (params->supported_oper_classes_len < 2 ||
3975 params->supported_oper_classes_len > 253)
3976 return -EINVAL;
3977 }
3978 return 0;
3979}
3980
Johannes Bergff276692013-02-15 00:09:01 +01003981static int nl80211_set_station_tdls(struct genl_info *info,
3982 struct station_parameters *params)
3983{
Sunil Duttc01fc9a2013-10-09 20:45:21 +05303984 int err;
Johannes Bergff276692013-02-15 00:09:01 +01003985 /* Dummy STA entry gets updated once the peer capabilities are known */
Jouni Malinen5e4b6f52013-05-16 20:11:08 +03003986 if (info->attrs[NL80211_ATTR_PEER_AID])
3987 params->aid = nla_get_u16(info->attrs[NL80211_ATTR_PEER_AID]);
Johannes Bergff276692013-02-15 00:09:01 +01003988 if (info->attrs[NL80211_ATTR_HT_CAPABILITY])
3989 params->ht_capa =
3990 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]);
3991 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY])
3992 params->vht_capa =
3993 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]);
3994
Sunil Duttc01fc9a2013-10-09 20:45:21 +05303995 err = nl80211_parse_sta_channel_info(info, params);
3996 if (err)
3997 return err;
3998
Johannes Bergff276692013-02-15 00:09:01 +01003999 return nl80211_parse_sta_wme(info, params);
4000}
4001
Johannes Berg5727ef12007-12-19 02:03:34 +01004002static int nl80211_set_station(struct sk_buff *skb, struct genl_info *info)
4003{
Johannes Berg4c476992010-10-04 21:36:35 +02004004 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg4c476992010-10-04 21:36:35 +02004005 struct net_device *dev = info->user_ptr[1];
Johannes Berg5727ef12007-12-19 02:03:34 +01004006 struct station_parameters params;
Johannes Berg77ee7c82013-02-15 00:48:33 +01004007 u8 *mac_addr;
4008 int err;
Johannes Berg5727ef12007-12-19 02:03:34 +01004009
4010 memset(&params, 0, sizeof(params));
4011
4012 params.listen_interval = -1;
4013
Johannes Berg77ee7c82013-02-15 00:48:33 +01004014 if (!rdev->ops->change_station)
4015 return -EOPNOTSUPP;
4016
Johannes Berg5727ef12007-12-19 02:03:34 +01004017 if (info->attrs[NL80211_ATTR_STA_AID])
4018 return -EINVAL;
4019
4020 if (!info->attrs[NL80211_ATTR_MAC])
4021 return -EINVAL;
4022
4023 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
4024
4025 if (info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) {
4026 params.supported_rates =
4027 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
4028 params.supported_rates_len =
4029 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
4030 }
4031
Jouni Malinen9d62a982013-02-14 21:10:13 +02004032 if (info->attrs[NL80211_ATTR_STA_CAPABILITY]) {
4033 params.capability =
4034 nla_get_u16(info->attrs[NL80211_ATTR_STA_CAPABILITY]);
4035 params.sta_modify_mask |= STATION_PARAM_APPLY_CAPABILITY;
4036 }
4037
4038 if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]) {
4039 params.ext_capab =
4040 nla_data(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
4041 params.ext_capab_len =
4042 nla_len(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
4043 }
4044
Jouni Malinendf881292013-02-14 21:10:54 +02004045 if (info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL])
Johannes Bergba23d202012-12-27 17:32:09 +01004046 return -EINVAL;
Jouni Malinen36aedc92008-08-25 11:58:58 +03004047
Johannes Bergbdd3ae32012-01-02 13:30:03 +01004048 if (parse_station_flags(info, dev->ieee80211_ptr->iftype, &params))
Johannes Berg5727ef12007-12-19 02:03:34 +01004049 return -EINVAL;
4050
Johannes Bergf8bacc22013-02-14 23:27:01 +01004051 if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) {
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004052 params.plink_action =
Johannes Bergf8bacc22013-02-14 23:27:01 +01004053 nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]);
4054 if (params.plink_action >= NUM_NL80211_PLINK_ACTIONS)
4055 return -EINVAL;
4056 }
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004057
Johannes Bergf8bacc22013-02-14 23:27:01 +01004058 if (info->attrs[NL80211_ATTR_STA_PLINK_STATE]) {
Javier Cardona9c3990a2011-05-03 16:57:11 -07004059 params.plink_state =
Johannes Bergf8bacc22013-02-14 23:27:01 +01004060 nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_STATE]);
4061 if (params.plink_state >= NUM_NL80211_PLINK_STATES)
4062 return -EINVAL;
4063 params.sta_modify_mask |= STATION_PARAM_APPLY_PLINK_STATE;
4064 }
Javier Cardona9c3990a2011-05-03 16:57:11 -07004065
Marco Porsch3b1c5a52013-01-07 16:04:52 +01004066 if (info->attrs[NL80211_ATTR_LOCAL_MESH_POWER_MODE]) {
4067 enum nl80211_mesh_power_mode pm = nla_get_u32(
4068 info->attrs[NL80211_ATTR_LOCAL_MESH_POWER_MODE]);
4069
4070 if (pm <= NL80211_MESH_POWER_UNKNOWN ||
4071 pm > NL80211_MESH_POWER_MAX)
4072 return -EINVAL;
4073
4074 params.local_pm = pm;
4075 }
4076
Johannes Berg77ee7c82013-02-15 00:48:33 +01004077 /* Include parameters for TDLS peer (will check later) */
4078 err = nl80211_set_station_tdls(info, &params);
4079 if (err)
4080 return err;
4081
4082 params.vlan = get_vlan(info, rdev);
4083 if (IS_ERR(params.vlan))
4084 return PTR_ERR(params.vlan);
4085
Johannes Berga97f4422009-06-18 17:23:43 +02004086 switch (dev->ieee80211_ptr->iftype) {
4087 case NL80211_IFTYPE_AP:
4088 case NL80211_IFTYPE_AP_VLAN:
Johannes Berg074ac8d2010-09-16 14:58:22 +02004089 case NL80211_IFTYPE_P2P_GO:
Johannes Berg074ac8d2010-09-16 14:58:22 +02004090 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Berga97f4422009-06-18 17:23:43 +02004091 case NL80211_IFTYPE_STATION:
Antonio Quartulli267335d2012-01-31 20:25:47 +01004092 case NL80211_IFTYPE_ADHOC:
Johannes Berga97f4422009-06-18 17:23:43 +02004093 case NL80211_IFTYPE_MESH_POINT:
Johannes Berga97f4422009-06-18 17:23:43 +02004094 break;
4095 default:
Johannes Berg77ee7c82013-02-15 00:48:33 +01004096 err = -EOPNOTSUPP;
4097 goto out_put_vlan;
Johannes Berg034d6552009-05-27 10:35:29 +02004098 }
4099
Johannes Berg77ee7c82013-02-15 00:48:33 +01004100 /* driver will call cfg80211_check_station_change() */
Hila Gonene35e4d22012-06-27 17:19:42 +03004101 err = rdev_change_station(rdev, dev, mac_addr, &params);
Johannes Berg5727ef12007-12-19 02:03:34 +01004102
Johannes Berg77ee7c82013-02-15 00:48:33 +01004103 out_put_vlan:
Johannes Berg5727ef12007-12-19 02:03:34 +01004104 if (params.vlan)
4105 dev_put(params.vlan);
Johannes Berg3b858752009-03-12 09:55:09 +01004106
Johannes Berg5727ef12007-12-19 02:03:34 +01004107 return err;
4108}
4109
4110static int nl80211_new_station(struct sk_buff *skb, struct genl_info *info)
4111{
Johannes Berg4c476992010-10-04 21:36:35 +02004112 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg5727ef12007-12-19 02:03:34 +01004113 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02004114 struct net_device *dev = info->user_ptr[1];
Johannes Berg5727ef12007-12-19 02:03:34 +01004115 struct station_parameters params;
4116 u8 *mac_addr = NULL;
4117
4118 memset(&params, 0, sizeof(params));
4119
Johannes Berg984c3112013-02-14 23:43:25 +01004120 if (!rdev->ops->add_station)
4121 return -EOPNOTSUPP;
4122
Johannes Berg5727ef12007-12-19 02:03:34 +01004123 if (!info->attrs[NL80211_ATTR_MAC])
4124 return -EINVAL;
4125
Johannes Berg5727ef12007-12-19 02:03:34 +01004126 if (!info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL])
4127 return -EINVAL;
4128
4129 if (!info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES])
4130 return -EINVAL;
4131
Jouni Malinen5e4b6f52013-05-16 20:11:08 +03004132 if (!info->attrs[NL80211_ATTR_STA_AID] &&
4133 !info->attrs[NL80211_ATTR_PEER_AID])
Thadeu Lima de Souza Cascardo0e956c12010-02-12 12:34:50 -02004134 return -EINVAL;
4135
Johannes Berg5727ef12007-12-19 02:03:34 +01004136 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
4137 params.supported_rates =
4138 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
4139 params.supported_rates_len =
4140 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
4141 params.listen_interval =
4142 nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]);
Johannes Berg51b50fb2009-05-24 16:42:30 +02004143
Jouni Malinen3d124ea2013-05-27 18:24:02 +03004144 if (info->attrs[NL80211_ATTR_PEER_AID])
Jouni Malinen5e4b6f52013-05-16 20:11:08 +03004145 params.aid = nla_get_u16(info->attrs[NL80211_ATTR_PEER_AID]);
Jouni Malinen3d124ea2013-05-27 18:24:02 +03004146 else
4147 params.aid = nla_get_u16(info->attrs[NL80211_ATTR_STA_AID]);
Thadeu Lima de Souza Cascardo0e956c12010-02-12 12:34:50 -02004148 if (!params.aid || params.aid > IEEE80211_MAX_AID)
4149 return -EINVAL;
Johannes Berg51b50fb2009-05-24 16:42:30 +02004150
Jouni Malinen9d62a982013-02-14 21:10:13 +02004151 if (info->attrs[NL80211_ATTR_STA_CAPABILITY]) {
4152 params.capability =
4153 nla_get_u16(info->attrs[NL80211_ATTR_STA_CAPABILITY]);
4154 params.sta_modify_mask |= STATION_PARAM_APPLY_CAPABILITY;
4155 }
4156
4157 if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]) {
4158 params.ext_capab =
4159 nla_data(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
4160 params.ext_capab_len =
4161 nla_len(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
4162 }
4163
Jouni Malinen36aedc92008-08-25 11:58:58 +03004164 if (info->attrs[NL80211_ATTR_HT_CAPABILITY])
4165 params.ht_capa =
4166 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]);
Johannes Berg5727ef12007-12-19 02:03:34 +01004167
Mahesh Palivelaf461be3e2012-10-11 08:04:52 +00004168 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY])
4169 params.vht_capa =
4170 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]);
4171
Marek Kwaczynski60f4a7b2013-12-03 10:04:59 +01004172 if (info->attrs[NL80211_ATTR_OPMODE_NOTIF]) {
4173 params.opmode_notif_used = true;
4174 params.opmode_notif =
4175 nla_get_u8(info->attrs[NL80211_ATTR_OPMODE_NOTIF]);
4176 }
4177
Johannes Bergf8bacc22013-02-14 23:27:01 +01004178 if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) {
Javier Cardona96b78df2011-04-07 15:08:33 -07004179 params.plink_action =
Johannes Bergf8bacc22013-02-14 23:27:01 +01004180 nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]);
4181 if (params.plink_action >= NUM_NL80211_PLINK_ACTIONS)
4182 return -EINVAL;
4183 }
Javier Cardona96b78df2011-04-07 15:08:33 -07004184
Sunil Duttc01fc9a2013-10-09 20:45:21 +05304185 err = nl80211_parse_sta_channel_info(info, &params);
4186 if (err)
4187 return err;
4188
Johannes Bergff276692013-02-15 00:09:01 +01004189 err = nl80211_parse_sta_wme(info, &params);
4190 if (err)
4191 return err;
Johannes Bergbdd90d52011-12-14 12:20:27 +01004192
Johannes Bergbdd3ae32012-01-02 13:30:03 +01004193 if (parse_station_flags(info, dev->ieee80211_ptr->iftype, &params))
Johannes Berg5727ef12007-12-19 02:03:34 +01004194 return -EINVAL;
4195
Johannes Berg77ee7c82013-02-15 00:48:33 +01004196 /* When you run into this, adjust the code below for the new flag */
4197 BUILD_BUG_ON(NL80211_STA_FLAG_MAX != 7);
4198
Johannes Bergbdd90d52011-12-14 12:20:27 +01004199 switch (dev->ieee80211_ptr->iftype) {
4200 case NL80211_IFTYPE_AP:
4201 case NL80211_IFTYPE_AP_VLAN:
4202 case NL80211_IFTYPE_P2P_GO:
Johannes Berg984c3112013-02-14 23:43:25 +01004203 /* ignore WME attributes if iface/sta is not capable */
4204 if (!(rdev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) ||
4205 !(params.sta_flags_set & BIT(NL80211_STA_FLAG_WME)))
4206 params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD;
Eliad Pellerc75786c2011-08-23 14:37:46 +03004207
Johannes Bergbdd90d52011-12-14 12:20:27 +01004208 /* TDLS peers cannot be added */
Jouni Malinen3d124ea2013-05-27 18:24:02 +03004209 if ((params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) ||
4210 info->attrs[NL80211_ATTR_PEER_AID])
Johannes Berg4319e192011-09-07 11:50:48 +02004211 return -EINVAL;
Johannes Bergbdd90d52011-12-14 12:20:27 +01004212 /* but don't bother the driver with it */
4213 params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER);
Eliad Pellerc75786c2011-08-23 14:37:46 +03004214
Johannes Bergd582cff2012-10-26 17:53:44 +02004215 /* allow authenticated/associated only if driver handles it */
4216 if (!(rdev->wiphy.features &
4217 NL80211_FEATURE_FULL_AP_CLIENT_STATE) &&
4218 params.sta_flags_mask &
4219 (BIT(NL80211_STA_FLAG_AUTHENTICATED) |
4220 BIT(NL80211_STA_FLAG_ASSOCIATED)))
4221 return -EINVAL;
4222
Johannes Bergbdd90d52011-12-14 12:20:27 +01004223 /* must be last in here for error handling */
4224 params.vlan = get_vlan(info, rdev);
4225 if (IS_ERR(params.vlan))
4226 return PTR_ERR(params.vlan);
4227 break;
4228 case NL80211_IFTYPE_MESH_POINT:
Johannes Berg984c3112013-02-14 23:43:25 +01004229 /* ignore uAPSD data */
4230 params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD;
4231
Johannes Bergd582cff2012-10-26 17:53:44 +02004232 /* associated is disallowed */
4233 if (params.sta_flags_mask & BIT(NL80211_STA_FLAG_ASSOCIATED))
4234 return -EINVAL;
Johannes Bergbdd90d52011-12-14 12:20:27 +01004235 /* TDLS peers cannot be added */
Jouni Malinen3d124ea2013-05-27 18:24:02 +03004236 if ((params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) ||
4237 info->attrs[NL80211_ATTR_PEER_AID])
Johannes Berg4319e192011-09-07 11:50:48 +02004238 return -EINVAL;
Johannes Bergbdd90d52011-12-14 12:20:27 +01004239 break;
4240 case NL80211_IFTYPE_STATION:
Johannes Berg93d08f02013-03-04 09:29:46 +01004241 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Berg984c3112013-02-14 23:43:25 +01004242 /* ignore uAPSD data */
4243 params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD;
4244
Johannes Berg77ee7c82013-02-15 00:48:33 +01004245 /* these are disallowed */
4246 if (params.sta_flags_mask &
4247 (BIT(NL80211_STA_FLAG_ASSOCIATED) |
4248 BIT(NL80211_STA_FLAG_AUTHENTICATED)))
Johannes Bergd582cff2012-10-26 17:53:44 +02004249 return -EINVAL;
Johannes Bergbdd90d52011-12-14 12:20:27 +01004250 /* Only TDLS peers can be added */
4251 if (!(params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)))
4252 return -EINVAL;
4253 /* Can only add if TDLS ... */
4254 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS))
4255 return -EOPNOTSUPP;
4256 /* ... with external setup is supported */
4257 if (!(rdev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP))
4258 return -EOPNOTSUPP;
Johannes Berg77ee7c82013-02-15 00:48:33 +01004259 /*
4260 * Older wpa_supplicant versions always mark the TDLS peer
4261 * as authorized, but it shouldn't yet be.
4262 */
4263 params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_AUTHORIZED);
Johannes Bergbdd90d52011-12-14 12:20:27 +01004264 break;
4265 default:
4266 return -EOPNOTSUPP;
Eliad Pellerc75786c2011-08-23 14:37:46 +03004267 }
4268
Johannes Bergbdd90d52011-12-14 12:20:27 +01004269 /* be aware of params.vlan when changing code here */
Johannes Berg5727ef12007-12-19 02:03:34 +01004270
Hila Gonene35e4d22012-06-27 17:19:42 +03004271 err = rdev_add_station(rdev, dev, mac_addr, &params);
Johannes Berg5727ef12007-12-19 02:03:34 +01004272
Johannes Berg5727ef12007-12-19 02:03:34 +01004273 if (params.vlan)
4274 dev_put(params.vlan);
Johannes Berg5727ef12007-12-19 02:03:34 +01004275 return err;
4276}
4277
4278static int nl80211_del_station(struct sk_buff *skb, struct genl_info *info)
4279{
Johannes Berg4c476992010-10-04 21:36:35 +02004280 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4281 struct net_device *dev = info->user_ptr[1];
Johannes Berg5727ef12007-12-19 02:03:34 +01004282 u8 *mac_addr = NULL;
4283
4284 if (info->attrs[NL80211_ATTR_MAC])
4285 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
4286
Johannes Berge80cf852009-05-11 14:43:13 +02004287 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
Marco Porschd5d9de02010-03-30 10:00:16 +02004288 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN &&
Johannes Berg074ac8d2010-09-16 14:58:22 +02004289 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT &&
Johannes Berg4c476992010-10-04 21:36:35 +02004290 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
4291 return -EINVAL;
Johannes Berge80cf852009-05-11 14:43:13 +02004292
Johannes Berg4c476992010-10-04 21:36:35 +02004293 if (!rdev->ops->del_station)
4294 return -EOPNOTSUPP;
Johannes Berg5727ef12007-12-19 02:03:34 +01004295
Hila Gonene35e4d22012-06-27 17:19:42 +03004296 return rdev_del_station(rdev, dev, mac_addr);
Johannes Berg5727ef12007-12-19 02:03:34 +01004297}
4298
Eric W. Biederman15e47302012-09-07 20:12:54 +00004299static int nl80211_send_mpath(struct sk_buff *msg, u32 portid, u32 seq,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004300 int flags, struct net_device *dev,
4301 u8 *dst, u8 *next_hop,
4302 struct mpath_info *pinfo)
4303{
4304 void *hdr;
4305 struct nlattr *pinfoattr;
4306
Eric W. Biederman15e47302012-09-07 20:12:54 +00004307 hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_STATION);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004308 if (!hdr)
4309 return -1;
4310
David S. Miller9360ffd2012-03-29 04:41:26 -04004311 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
4312 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, dst) ||
4313 nla_put(msg, NL80211_ATTR_MPATH_NEXT_HOP, ETH_ALEN, next_hop) ||
4314 nla_put_u32(msg, NL80211_ATTR_GENERATION, pinfo->generation))
4315 goto nla_put_failure;
Johannes Bergf5ea9122009-08-07 16:17:38 +02004316
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004317 pinfoattr = nla_nest_start(msg, NL80211_ATTR_MPATH_INFO);
4318 if (!pinfoattr)
4319 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04004320 if ((pinfo->filled & MPATH_INFO_FRAME_QLEN) &&
4321 nla_put_u32(msg, NL80211_MPATH_INFO_FRAME_QLEN,
4322 pinfo->frame_qlen))
4323 goto nla_put_failure;
4324 if (((pinfo->filled & MPATH_INFO_SN) &&
4325 nla_put_u32(msg, NL80211_MPATH_INFO_SN, pinfo->sn)) ||
4326 ((pinfo->filled & MPATH_INFO_METRIC) &&
4327 nla_put_u32(msg, NL80211_MPATH_INFO_METRIC,
4328 pinfo->metric)) ||
4329 ((pinfo->filled & MPATH_INFO_EXPTIME) &&
4330 nla_put_u32(msg, NL80211_MPATH_INFO_EXPTIME,
4331 pinfo->exptime)) ||
4332 ((pinfo->filled & MPATH_INFO_FLAGS) &&
4333 nla_put_u8(msg, NL80211_MPATH_INFO_FLAGS,
4334 pinfo->flags)) ||
4335 ((pinfo->filled & MPATH_INFO_DISCOVERY_TIMEOUT) &&
4336 nla_put_u32(msg, NL80211_MPATH_INFO_DISCOVERY_TIMEOUT,
4337 pinfo->discovery_timeout)) ||
4338 ((pinfo->filled & MPATH_INFO_DISCOVERY_RETRIES) &&
4339 nla_put_u8(msg, NL80211_MPATH_INFO_DISCOVERY_RETRIES,
4340 pinfo->discovery_retries)))
4341 goto nla_put_failure;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004342
4343 nla_nest_end(msg, pinfoattr);
4344
4345 return genlmsg_end(msg, hdr);
4346
4347 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07004348 genlmsg_cancel(msg, hdr);
4349 return -EMSGSIZE;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004350}
4351
4352static int nl80211_dump_mpath(struct sk_buff *skb,
Johannes Bergbba95fe2008-07-29 13:22:51 +02004353 struct netlink_callback *cb)
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004354{
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004355 struct mpath_info pinfo;
4356 struct cfg80211_registered_device *dev;
Johannes Berg97990a02013-04-19 01:02:55 +02004357 struct wireless_dev *wdev;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004358 u8 dst[ETH_ALEN];
4359 u8 next_hop[ETH_ALEN];
Johannes Berg97990a02013-04-19 01:02:55 +02004360 int path_idx = cb->args[2];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004361 int err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004362
Johannes Berg97990a02013-04-19 01:02:55 +02004363 err = nl80211_prepare_wdev_dump(skb, cb, &dev, &wdev);
Johannes Berg67748892010-10-04 21:14:06 +02004364 if (err)
4365 return err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004366
4367 if (!dev->ops->dump_mpath) {
Jouni Malineneec60b02009-03-20 21:21:19 +02004368 err = -EOPNOTSUPP;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004369 goto out_err;
4370 }
4371
Johannes Berg97990a02013-04-19 01:02:55 +02004372 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) {
Jouni Malineneec60b02009-03-20 21:21:19 +02004373 err = -EOPNOTSUPP;
Roel Kluin0448b5f2009-08-22 21:15:49 +02004374 goto out_err;
Jouni Malineneec60b02009-03-20 21:21:19 +02004375 }
4376
Johannes Bergbba95fe2008-07-29 13:22:51 +02004377 while (1) {
Johannes Berg97990a02013-04-19 01:02:55 +02004378 err = rdev_dump_mpath(dev, wdev->netdev, path_idx, dst,
4379 next_hop, &pinfo);
Johannes Bergbba95fe2008-07-29 13:22:51 +02004380 if (err == -ENOENT)
4381 break;
4382 if (err)
Johannes Berg3b858752009-03-12 09:55:09 +01004383 goto out_err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004384
Eric W. Biederman15e47302012-09-07 20:12:54 +00004385 if (nl80211_send_mpath(skb, NETLINK_CB(cb->skb).portid,
Johannes Bergbba95fe2008-07-29 13:22:51 +02004386 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Johannes Berg97990a02013-04-19 01:02:55 +02004387 wdev->netdev, dst, next_hop,
Johannes Bergbba95fe2008-07-29 13:22:51 +02004388 &pinfo) < 0)
4389 goto out;
4390
4391 path_idx++;
4392 }
4393
4394
4395 out:
Johannes Berg97990a02013-04-19 01:02:55 +02004396 cb->args[2] = path_idx;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004397 err = skb->len;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004398 out_err:
Johannes Berg97990a02013-04-19 01:02:55 +02004399 nl80211_finish_wdev_dump(dev);
Johannes Bergbba95fe2008-07-29 13:22:51 +02004400 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004401}
4402
4403static int nl80211_get_mpath(struct sk_buff *skb, struct genl_info *info)
4404{
Johannes Berg4c476992010-10-04 21:36:35 +02004405 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004406 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02004407 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004408 struct mpath_info pinfo;
4409 struct sk_buff *msg;
4410 u8 *dst = NULL;
4411 u8 next_hop[ETH_ALEN];
4412
4413 memset(&pinfo, 0, sizeof(pinfo));
4414
4415 if (!info->attrs[NL80211_ATTR_MAC])
4416 return -EINVAL;
4417
4418 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
4419
Johannes Berg4c476992010-10-04 21:36:35 +02004420 if (!rdev->ops->get_mpath)
4421 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01004422
Johannes Berg4c476992010-10-04 21:36:35 +02004423 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
4424 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02004425
Hila Gonene35e4d22012-06-27 17:19:42 +03004426 err = rdev_get_mpath(rdev, dev, dst, next_hop, &pinfo);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004427 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02004428 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004429
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07004430 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004431 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02004432 return -ENOMEM;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004433
Eric W. Biederman15e47302012-09-07 20:12:54 +00004434 if (nl80211_send_mpath(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berg4c476992010-10-04 21:36:35 +02004435 dev, dst, next_hop, &pinfo) < 0) {
4436 nlmsg_free(msg);
4437 return -ENOBUFS;
4438 }
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004439
Johannes Berg4c476992010-10-04 21:36:35 +02004440 return genlmsg_reply(msg, info);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004441}
4442
4443static int nl80211_set_mpath(struct sk_buff *skb, struct genl_info *info)
4444{
Johannes Berg4c476992010-10-04 21:36:35 +02004445 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4446 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004447 u8 *dst = NULL;
4448 u8 *next_hop = NULL;
4449
4450 if (!info->attrs[NL80211_ATTR_MAC])
4451 return -EINVAL;
4452
4453 if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP])
4454 return -EINVAL;
4455
4456 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
4457 next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]);
4458
Johannes Berg4c476992010-10-04 21:36:35 +02004459 if (!rdev->ops->change_mpath)
4460 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01004461
Johannes Berg4c476992010-10-04 21:36:35 +02004462 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
4463 return -EOPNOTSUPP;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004464
Hila Gonene35e4d22012-06-27 17:19:42 +03004465 return rdev_change_mpath(rdev, dev, dst, next_hop);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004466}
Johannes Berg4c476992010-10-04 21:36:35 +02004467
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004468static int nl80211_new_mpath(struct sk_buff *skb, struct genl_info *info)
4469{
Johannes Berg4c476992010-10-04 21:36:35 +02004470 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4471 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004472 u8 *dst = NULL;
4473 u8 *next_hop = NULL;
4474
4475 if (!info->attrs[NL80211_ATTR_MAC])
4476 return -EINVAL;
4477
4478 if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP])
4479 return -EINVAL;
4480
4481 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
4482 next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]);
4483
Johannes Berg4c476992010-10-04 21:36:35 +02004484 if (!rdev->ops->add_mpath)
4485 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01004486
Johannes Berg4c476992010-10-04 21:36:35 +02004487 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
4488 return -EOPNOTSUPP;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004489
Hila Gonene35e4d22012-06-27 17:19:42 +03004490 return rdev_add_mpath(rdev, dev, dst, next_hop);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004491}
4492
4493static int nl80211_del_mpath(struct sk_buff *skb, struct genl_info *info)
4494{
Johannes Berg4c476992010-10-04 21:36:35 +02004495 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4496 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004497 u8 *dst = NULL;
4498
4499 if (info->attrs[NL80211_ATTR_MAC])
4500 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
4501
Johannes Berg4c476992010-10-04 21:36:35 +02004502 if (!rdev->ops->del_mpath)
4503 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01004504
Hila Gonene35e4d22012-06-27 17:19:42 +03004505 return rdev_del_mpath(rdev, dev, dst);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004506}
4507
Jouni Malinen9f1ba902008-08-07 20:07:01 +03004508static int nl80211_set_bss(struct sk_buff *skb, struct genl_info *info)
4509{
Johannes Berg4c476992010-10-04 21:36:35 +02004510 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4511 struct net_device *dev = info->user_ptr[1];
Simon Wunderlichc56589e2013-11-21 18:19:49 +01004512 struct wireless_dev *wdev = dev->ieee80211_ptr;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03004513 struct bss_parameters params;
Simon Wunderlichc56589e2013-11-21 18:19:49 +01004514 int err;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03004515
4516 memset(&params, 0, sizeof(params));
4517 /* default to not changing parameters */
4518 params.use_cts_prot = -1;
4519 params.use_short_preamble = -1;
4520 params.use_short_slot_time = -1;
Felix Fietkaufd8aaaf2010-04-27 01:23:35 +02004521 params.ap_isolate = -1;
Helmut Schaa50b12f52010-11-19 12:40:25 +01004522 params.ht_opmode = -1;
Johannes Berg53cabad2012-11-14 15:17:28 +01004523 params.p2p_ctwindow = -1;
4524 params.p2p_opp_ps = -1;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03004525
4526 if (info->attrs[NL80211_ATTR_BSS_CTS_PROT])
4527 params.use_cts_prot =
4528 nla_get_u8(info->attrs[NL80211_ATTR_BSS_CTS_PROT]);
4529 if (info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE])
4530 params.use_short_preamble =
4531 nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]);
4532 if (info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME])
4533 params.use_short_slot_time =
4534 nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]);
Jouni Malinen90c97a02008-10-30 16:59:22 +02004535 if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) {
4536 params.basic_rates =
4537 nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
4538 params.basic_rates_len =
4539 nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
4540 }
Felix Fietkaufd8aaaf2010-04-27 01:23:35 +02004541 if (info->attrs[NL80211_ATTR_AP_ISOLATE])
4542 params.ap_isolate = !!nla_get_u8(info->attrs[NL80211_ATTR_AP_ISOLATE]);
Helmut Schaa50b12f52010-11-19 12:40:25 +01004543 if (info->attrs[NL80211_ATTR_BSS_HT_OPMODE])
4544 params.ht_opmode =
4545 nla_get_u16(info->attrs[NL80211_ATTR_BSS_HT_OPMODE]);
Jouni Malinen9f1ba902008-08-07 20:07:01 +03004546
Johannes Berg53cabad2012-11-14 15:17:28 +01004547 if (info->attrs[NL80211_ATTR_P2P_CTWINDOW]) {
4548 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
4549 return -EINVAL;
4550 params.p2p_ctwindow =
4551 nla_get_s8(info->attrs[NL80211_ATTR_P2P_CTWINDOW]);
4552 if (params.p2p_ctwindow < 0)
4553 return -EINVAL;
4554 if (params.p2p_ctwindow != 0 &&
4555 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_CTWIN))
4556 return -EINVAL;
4557 }
4558
4559 if (info->attrs[NL80211_ATTR_P2P_OPPPS]) {
4560 u8 tmp;
4561
4562 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
4563 return -EINVAL;
4564 tmp = nla_get_u8(info->attrs[NL80211_ATTR_P2P_OPPPS]);
4565 if (tmp > 1)
4566 return -EINVAL;
4567 params.p2p_opp_ps = tmp;
4568 if (params.p2p_opp_ps &&
4569 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_OPPPS))
4570 return -EINVAL;
4571 }
4572
Johannes Berg4c476992010-10-04 21:36:35 +02004573 if (!rdev->ops->change_bss)
4574 return -EOPNOTSUPP;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03004575
Johannes Berg074ac8d2010-09-16 14:58:22 +02004576 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
Johannes Berg4c476992010-10-04 21:36:35 +02004577 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
4578 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02004579
Simon Wunderlichc56589e2013-11-21 18:19:49 +01004580 wdev_lock(wdev);
4581 err = rdev_change_bss(rdev, dev, &params);
4582 wdev_unlock(wdev);
4583
4584 return err;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03004585}
4586
Alexey Dobriyanb54452b2010-02-18 08:14:31 +00004587static const struct nla_policy reg_rule_policy[NL80211_REG_RULE_ATTR_MAX + 1] = {
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004588 [NL80211_ATTR_REG_RULE_FLAGS] = { .type = NLA_U32 },
4589 [NL80211_ATTR_FREQ_RANGE_START] = { .type = NLA_U32 },
4590 [NL80211_ATTR_FREQ_RANGE_END] = { .type = NLA_U32 },
4591 [NL80211_ATTR_FREQ_RANGE_MAX_BW] = { .type = NLA_U32 },
4592 [NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN] = { .type = NLA_U32 },
4593 [NL80211_ATTR_POWER_RULE_MAX_EIRP] = { .type = NLA_U32 },
4594};
4595
4596static int parse_reg_rule(struct nlattr *tb[],
4597 struct ieee80211_reg_rule *reg_rule)
4598{
4599 struct ieee80211_freq_range *freq_range = &reg_rule->freq_range;
4600 struct ieee80211_power_rule *power_rule = &reg_rule->power_rule;
4601
4602 if (!tb[NL80211_ATTR_REG_RULE_FLAGS])
4603 return -EINVAL;
4604 if (!tb[NL80211_ATTR_FREQ_RANGE_START])
4605 return -EINVAL;
4606 if (!tb[NL80211_ATTR_FREQ_RANGE_END])
4607 return -EINVAL;
4608 if (!tb[NL80211_ATTR_FREQ_RANGE_MAX_BW])
4609 return -EINVAL;
4610 if (!tb[NL80211_ATTR_POWER_RULE_MAX_EIRP])
4611 return -EINVAL;
4612
4613 reg_rule->flags = nla_get_u32(tb[NL80211_ATTR_REG_RULE_FLAGS]);
4614
4615 freq_range->start_freq_khz =
4616 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_START]);
4617 freq_range->end_freq_khz =
4618 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_END]);
4619 freq_range->max_bandwidth_khz =
4620 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]);
4621
4622 power_rule->max_eirp =
4623 nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]);
4624
4625 if (tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN])
4626 power_rule->max_antenna_gain =
4627 nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]);
4628
4629 return 0;
4630}
4631
4632static int nl80211_req_set_reg(struct sk_buff *skb, struct genl_info *info)
4633{
4634 int r;
4635 char *data = NULL;
Luis R. Rodriguez57b5ce02012-07-12 11:49:18 -07004636 enum nl80211_user_reg_hint_type user_reg_hint_type;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004637
Luis R. Rodriguez80778f12009-02-21 00:04:22 -05004638 /*
4639 * You should only get this when cfg80211 hasn't yet initialized
4640 * completely when built-in to the kernel right between the time
4641 * window between nl80211_init() and regulatory_init(), if that is
4642 * even possible.
4643 */
Johannes Berg458f4f92012-12-06 15:47:38 +01004644 if (unlikely(!rcu_access_pointer(cfg80211_regdomain)))
Luis R. Rodriguezfe33eb32009-02-21 00:04:30 -05004645 return -EINPROGRESS;
Luis R. Rodriguez80778f12009-02-21 00:04:22 -05004646
Luis R. Rodriguezfe33eb32009-02-21 00:04:30 -05004647 if (!info->attrs[NL80211_ATTR_REG_ALPHA2])
4648 return -EINVAL;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004649
4650 data = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]);
4651
Luis R. Rodriguez57b5ce02012-07-12 11:49:18 -07004652 if (info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE])
4653 user_reg_hint_type =
4654 nla_get_u32(info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE]);
4655 else
4656 user_reg_hint_type = NL80211_USER_REG_HINT_USER;
4657
4658 switch (user_reg_hint_type) {
4659 case NL80211_USER_REG_HINT_USER:
4660 case NL80211_USER_REG_HINT_CELL_BASE:
4661 break;
4662 default:
4663 return -EINVAL;
4664 }
4665
4666 r = regulatory_hint_user(data, user_reg_hint_type);
Luis R. Rodriguezfe33eb32009-02-21 00:04:30 -05004667
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004668 return r;
4669}
4670
Javier Cardona24bdd9f2010-12-16 17:37:48 -08004671static int nl80211_get_mesh_config(struct sk_buff *skb,
Johannes Berg29cbe682010-12-03 09:20:44 +01004672 struct genl_info *info)
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004673{
Johannes Berg4c476992010-10-04 21:36:35 +02004674 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg4c476992010-10-04 21:36:35 +02004675 struct net_device *dev = info->user_ptr[1];
Johannes Berg29cbe682010-12-03 09:20:44 +01004676 struct wireless_dev *wdev = dev->ieee80211_ptr;
4677 struct mesh_config cur_params;
4678 int err = 0;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004679 void *hdr;
4680 struct nlattr *pinfoattr;
4681 struct sk_buff *msg;
4682
Johannes Berg29cbe682010-12-03 09:20:44 +01004683 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT)
4684 return -EOPNOTSUPP;
4685
Javier Cardona24bdd9f2010-12-16 17:37:48 -08004686 if (!rdev->ops->get_mesh_config)
Johannes Berg4c476992010-10-04 21:36:35 +02004687 return -EOPNOTSUPP;
Jouni Malinenf3f92582009-03-20 17:57:36 +02004688
Johannes Berg29cbe682010-12-03 09:20:44 +01004689 wdev_lock(wdev);
4690 /* If not connected, get default parameters */
4691 if (!wdev->mesh_id_len)
4692 memcpy(&cur_params, &default_mesh_config, sizeof(cur_params));
4693 else
Hila Gonene35e4d22012-06-27 17:19:42 +03004694 err = rdev_get_mesh_config(rdev, dev, &cur_params);
Johannes Berg29cbe682010-12-03 09:20:44 +01004695 wdev_unlock(wdev);
4696
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004697 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02004698 return err;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004699
4700 /* Draw up a netlink message to send back */
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07004701 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02004702 if (!msg)
4703 return -ENOMEM;
Eric W. Biederman15e47302012-09-07 20:12:54 +00004704 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Javier Cardona24bdd9f2010-12-16 17:37:48 -08004705 NL80211_CMD_GET_MESH_CONFIG);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004706 if (!hdr)
Julia Lawallefe1cf02011-01-28 15:17:11 +01004707 goto out;
Javier Cardona24bdd9f2010-12-16 17:37:48 -08004708 pinfoattr = nla_nest_start(msg, NL80211_ATTR_MESH_CONFIG);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004709 if (!pinfoattr)
4710 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04004711 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
4712 nla_put_u16(msg, NL80211_MESHCONF_RETRY_TIMEOUT,
4713 cur_params.dot11MeshRetryTimeout) ||
4714 nla_put_u16(msg, NL80211_MESHCONF_CONFIRM_TIMEOUT,
4715 cur_params.dot11MeshConfirmTimeout) ||
4716 nla_put_u16(msg, NL80211_MESHCONF_HOLDING_TIMEOUT,
4717 cur_params.dot11MeshHoldingTimeout) ||
4718 nla_put_u16(msg, NL80211_MESHCONF_MAX_PEER_LINKS,
4719 cur_params.dot11MeshMaxPeerLinks) ||
4720 nla_put_u8(msg, NL80211_MESHCONF_MAX_RETRIES,
4721 cur_params.dot11MeshMaxRetries) ||
4722 nla_put_u8(msg, NL80211_MESHCONF_TTL,
4723 cur_params.dot11MeshTTL) ||
4724 nla_put_u8(msg, NL80211_MESHCONF_ELEMENT_TTL,
4725 cur_params.element_ttl) ||
4726 nla_put_u8(msg, NL80211_MESHCONF_AUTO_OPEN_PLINKS,
4727 cur_params.auto_open_plinks) ||
John W. Linville7eab0f62012-04-12 14:25:14 -04004728 nla_put_u32(msg, NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR,
4729 cur_params.dot11MeshNbrOffsetMaxNeighbor) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04004730 nla_put_u8(msg, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES,
4731 cur_params.dot11MeshHWMPmaxPREQretries) ||
4732 nla_put_u32(msg, NL80211_MESHCONF_PATH_REFRESH_TIME,
4733 cur_params.path_refresh_time) ||
4734 nla_put_u16(msg, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT,
4735 cur_params.min_discovery_timeout) ||
4736 nla_put_u32(msg, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT,
4737 cur_params.dot11MeshHWMPactivePathTimeout) ||
4738 nla_put_u16(msg, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL,
4739 cur_params.dot11MeshHWMPpreqMinInterval) ||
4740 nla_put_u16(msg, NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL,
4741 cur_params.dot11MeshHWMPperrMinInterval) ||
4742 nla_put_u16(msg, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME,
4743 cur_params.dot11MeshHWMPnetDiameterTraversalTime) ||
4744 nla_put_u8(msg, NL80211_MESHCONF_HWMP_ROOTMODE,
4745 cur_params.dot11MeshHWMPRootMode) ||
4746 nla_put_u16(msg, NL80211_MESHCONF_HWMP_RANN_INTERVAL,
4747 cur_params.dot11MeshHWMPRannInterval) ||
4748 nla_put_u8(msg, NL80211_MESHCONF_GATE_ANNOUNCEMENTS,
4749 cur_params.dot11MeshGateAnnouncementProtocol) ||
4750 nla_put_u8(msg, NL80211_MESHCONF_FORWARDING,
4751 cur_params.dot11MeshForwarding) ||
4752 nla_put_u32(msg, NL80211_MESHCONF_RSSI_THRESHOLD,
Ashok Nagarajan70c33ea2012-04-30 14:20:32 -07004753 cur_params.rssi_threshold) ||
4754 nla_put_u32(msg, NL80211_MESHCONF_HT_OPMODE,
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08004755 cur_params.ht_opmode) ||
4756 nla_put_u32(msg, NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT,
4757 cur_params.dot11MeshHWMPactivePathToRootTimeout) ||
4758 nla_put_u16(msg, NL80211_MESHCONF_HWMP_ROOT_INTERVAL,
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +08004759 cur_params.dot11MeshHWMProotInterval) ||
4760 nla_put_u16(msg, NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL,
Marco Porsch3b1c5a52013-01-07 16:04:52 +01004761 cur_params.dot11MeshHWMPconfirmationInterval) ||
4762 nla_put_u32(msg, NL80211_MESHCONF_POWER_MODE,
4763 cur_params.power_mode) ||
4764 nla_put_u16(msg, NL80211_MESHCONF_AWAKE_WINDOW,
Colleen Twitty8e7c0532013-06-03 09:53:39 -07004765 cur_params.dot11MeshAwakeWindowDuration) ||
4766 nla_put_u32(msg, NL80211_MESHCONF_PLINK_TIMEOUT,
4767 cur_params.plink_timeout))
David S. Miller9360ffd2012-03-29 04:41:26 -04004768 goto nla_put_failure;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004769 nla_nest_end(msg, pinfoattr);
4770 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02004771 return genlmsg_reply(msg, info);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004772
Johannes Berg3b858752009-03-12 09:55:09 +01004773 nla_put_failure:
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004774 genlmsg_cancel(msg, hdr);
Julia Lawallefe1cf02011-01-28 15:17:11 +01004775 out:
Yuri Ershovd080e272010-06-29 15:08:07 +04004776 nlmsg_free(msg);
Johannes Berg4c476992010-10-04 21:36:35 +02004777 return -ENOBUFS;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004778}
4779
Alexey Dobriyanb54452b2010-02-18 08:14:31 +00004780static const struct nla_policy nl80211_meshconf_params_policy[NL80211_MESHCONF_ATTR_MAX+1] = {
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004781 [NL80211_MESHCONF_RETRY_TIMEOUT] = { .type = NLA_U16 },
4782 [NL80211_MESHCONF_CONFIRM_TIMEOUT] = { .type = NLA_U16 },
4783 [NL80211_MESHCONF_HOLDING_TIMEOUT] = { .type = NLA_U16 },
4784 [NL80211_MESHCONF_MAX_PEER_LINKS] = { .type = NLA_U16 },
4785 [NL80211_MESHCONF_MAX_RETRIES] = { .type = NLA_U8 },
4786 [NL80211_MESHCONF_TTL] = { .type = NLA_U8 },
Javier Cardona45904f22010-12-03 09:20:40 +01004787 [NL80211_MESHCONF_ELEMENT_TTL] = { .type = NLA_U8 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004788 [NL80211_MESHCONF_AUTO_OPEN_PLINKS] = { .type = NLA_U8 },
Javier Cardonad299a1f2012-03-31 11:31:33 -07004789 [NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR] = { .type = NLA_U32 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004790 [NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES] = { .type = NLA_U8 },
4791 [NL80211_MESHCONF_PATH_REFRESH_TIME] = { .type = NLA_U32 },
4792 [NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT] = { .type = NLA_U16 },
4793 [NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT] = { .type = NLA_U32 },
4794 [NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL] = { .type = NLA_U16 },
Thomas Pedersendca7e942011-11-24 17:15:24 -08004795 [NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL] = { .type = NLA_U16 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004796 [NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME] = { .type = NLA_U16 },
Javier Cardona699403d2011-08-09 16:45:09 -07004797 [NL80211_MESHCONF_HWMP_ROOTMODE] = { .type = NLA_U8 },
Javier Cardona0507e152011-08-09 16:45:10 -07004798 [NL80211_MESHCONF_HWMP_RANN_INTERVAL] = { .type = NLA_U16 },
Javier Cardona16dd7262011-08-09 16:45:11 -07004799 [NL80211_MESHCONF_GATE_ANNOUNCEMENTS] = { .type = NLA_U8 },
Chun-Yeow Yeoh94f90652012-01-21 01:02:16 +08004800 [NL80211_MESHCONF_FORWARDING] = { .type = NLA_U8 },
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004801 [NL80211_MESHCONF_RSSI_THRESHOLD] = { .type = NLA_U32 },
4802 [NL80211_MESHCONF_HT_OPMODE] = { .type = NLA_U16 },
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08004803 [NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT] = { .type = NLA_U32 },
4804 [NL80211_MESHCONF_HWMP_ROOT_INTERVAL] = { .type = NLA_U16 },
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +08004805 [NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL] = { .type = NLA_U16 },
Marco Porsch3b1c5a52013-01-07 16:04:52 +01004806 [NL80211_MESHCONF_POWER_MODE] = { .type = NLA_U32 },
4807 [NL80211_MESHCONF_AWAKE_WINDOW] = { .type = NLA_U16 },
Colleen Twitty8e7c0532013-06-03 09:53:39 -07004808 [NL80211_MESHCONF_PLINK_TIMEOUT] = { .type = NLA_U32 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004809};
4810
Javier Cardonac80d5452010-12-16 17:37:49 -08004811static const struct nla_policy
4812 nl80211_mesh_setup_params_policy[NL80211_MESH_SETUP_ATTR_MAX+1] = {
Javier Cardonad299a1f2012-03-31 11:31:33 -07004813 [NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC] = { .type = NLA_U8 },
Javier Cardonac80d5452010-12-16 17:37:49 -08004814 [NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL] = { .type = NLA_U8 },
4815 [NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC] = { .type = NLA_U8 },
Javier Cardona15d5dda2011-04-07 15:08:28 -07004816 [NL80211_MESH_SETUP_USERSPACE_AUTH] = { .type = NLA_FLAG },
Colleen Twitty6e16d902013-05-08 11:45:59 -07004817 [NL80211_MESH_SETUP_AUTH_PROTOCOL] = { .type = NLA_U8 },
Thomas Pedersenbb2798d2013-03-04 13:06:10 -08004818 [NL80211_MESH_SETUP_USERSPACE_MPM] = { .type = NLA_FLAG },
Javier Cardona581a8b02011-04-07 15:08:27 -07004819 [NL80211_MESH_SETUP_IE] = { .type = NLA_BINARY,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004820 .len = IEEE80211_MAX_DATA_LEN },
Javier Cardonab130e5c2011-05-03 16:57:07 -07004821 [NL80211_MESH_SETUP_USERSPACE_AMPE] = { .type = NLA_FLAG },
Javier Cardonac80d5452010-12-16 17:37:49 -08004822};
4823
Javier Cardona24bdd9f2010-12-16 17:37:48 -08004824static int nl80211_parse_mesh_config(struct genl_info *info,
Johannes Bergbd90fdc2010-12-03 09:20:43 +01004825 struct mesh_config *cfg,
4826 u32 *mask_out)
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004827{
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004828 struct nlattr *tb[NL80211_MESHCONF_ATTR_MAX + 1];
Johannes Bergbd90fdc2010-12-03 09:20:43 +01004829 u32 mask = 0;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004830
Marco Porschea54fba2013-01-07 16:04:48 +01004831#define FILL_IN_MESH_PARAM_IF_SET(tb, cfg, param, min, max, mask, attr, fn) \
4832do { \
4833 if (tb[attr]) { \
4834 if (fn(tb[attr]) < min || fn(tb[attr]) > max) \
4835 return -EINVAL; \
4836 cfg->param = fn(tb[attr]); \
4837 mask |= (1 << (attr - 1)); \
4838 } \
4839} while (0)
Johannes Bergbd90fdc2010-12-03 09:20:43 +01004840
4841
Javier Cardona24bdd9f2010-12-16 17:37:48 -08004842 if (!info->attrs[NL80211_ATTR_MESH_CONFIG])
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004843 return -EINVAL;
4844 if (nla_parse_nested(tb, NL80211_MESHCONF_ATTR_MAX,
Javier Cardona24bdd9f2010-12-16 17:37:48 -08004845 info->attrs[NL80211_ATTR_MESH_CONFIG],
Johannes Bergbd90fdc2010-12-03 09:20:43 +01004846 nl80211_meshconf_params_policy))
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004847 return -EINVAL;
4848
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004849 /* This makes sure that there aren't more than 32 mesh config
4850 * parameters (otherwise our bitfield scheme would not work.) */
4851 BUILD_BUG_ON(NL80211_MESHCONF_ATTR_MAX > 32);
4852
4853 /* Fill in the params struct */
Marco Porschea54fba2013-01-07 16:04:48 +01004854 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshRetryTimeout, 1, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004855 mask, NL80211_MESHCONF_RETRY_TIMEOUT,
4856 nla_get_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01004857 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshConfirmTimeout, 1, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004858 mask, NL80211_MESHCONF_CONFIRM_TIMEOUT,
4859 nla_get_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01004860 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHoldingTimeout, 1, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004861 mask, NL80211_MESHCONF_HOLDING_TIMEOUT,
4862 nla_get_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01004863 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxPeerLinks, 0, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004864 mask, NL80211_MESHCONF_MAX_PEER_LINKS,
4865 nla_get_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01004866 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxRetries, 0, 16,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004867 mask, NL80211_MESHCONF_MAX_RETRIES,
4868 nla_get_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01004869 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshTTL, 1, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004870 mask, NL80211_MESHCONF_TTL, nla_get_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01004871 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, element_ttl, 1, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004872 mask, NL80211_MESHCONF_ELEMENT_TTL,
4873 nla_get_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01004874 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, auto_open_plinks, 0, 1,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004875 mask, NL80211_MESHCONF_AUTO_OPEN_PLINKS,
4876 nla_get_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01004877 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshNbrOffsetMaxNeighbor,
4878 1, 255, mask,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004879 NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR,
4880 nla_get_u32);
Marco Porschea54fba2013-01-07 16:04:48 +01004881 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPmaxPREQretries, 0, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004882 mask, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES,
4883 nla_get_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01004884 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, path_refresh_time, 1, 65535,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004885 mask, NL80211_MESHCONF_PATH_REFRESH_TIME,
4886 nla_get_u32);
Marco Porschea54fba2013-01-07 16:04:48 +01004887 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, min_discovery_timeout, 1, 65535,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004888 mask, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT,
4889 nla_get_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01004890 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathTimeout,
4891 1, 65535, mask,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004892 NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT,
4893 nla_get_u32);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004894 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPpreqMinInterval,
Marco Porschea54fba2013-01-07 16:04:48 +01004895 1, 65535, mask,
4896 NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004897 nla_get_u16);
Thomas Pedersendca7e942011-11-24 17:15:24 -08004898 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPperrMinInterval,
Marco Porschea54fba2013-01-07 16:04:48 +01004899 1, 65535, mask,
4900 NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004901 nla_get_u16);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004902 FILL_IN_MESH_PARAM_IF_SET(tb, cfg,
Marco Porschea54fba2013-01-07 16:04:48 +01004903 dot11MeshHWMPnetDiameterTraversalTime,
4904 1, 65535, mask,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004905 NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME,
4906 nla_get_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01004907 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRootMode, 0, 4,
4908 mask, NL80211_MESHCONF_HWMP_ROOTMODE,
4909 nla_get_u8);
4910 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRannInterval, 1, 65535,
4911 mask, NL80211_MESHCONF_HWMP_RANN_INTERVAL,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004912 nla_get_u16);
Rui Paulo63c57232009-11-09 23:46:57 +00004913 FILL_IN_MESH_PARAM_IF_SET(tb, cfg,
Marco Porschea54fba2013-01-07 16:04:48 +01004914 dot11MeshGateAnnouncementProtocol, 0, 1,
4915 mask, NL80211_MESHCONF_GATE_ANNOUNCEMENTS,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004916 nla_get_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01004917 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshForwarding, 0, 1,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004918 mask, NL80211_MESHCONF_FORWARDING,
4919 nla_get_u8);
Chun-Yeow Yeoh83374fe2013-07-11 18:24:03 +08004920 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, rssi_threshold, -255, 0,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004921 mask, NL80211_MESHCONF_RSSI_THRESHOLD,
Chun-Yeow Yeoh83374fe2013-07-11 18:24:03 +08004922 nla_get_s32);
Marco Porschea54fba2013-01-07 16:04:48 +01004923 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, ht_opmode, 0, 16,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004924 mask, NL80211_MESHCONF_HT_OPMODE,
4925 nla_get_u16);
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08004926 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathToRootTimeout,
Marco Porschea54fba2013-01-07 16:04:48 +01004927 1, 65535, mask,
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08004928 NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT,
4929 nla_get_u32);
Marco Porschea54fba2013-01-07 16:04:48 +01004930 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMProotInterval, 1, 65535,
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08004931 mask, NL80211_MESHCONF_HWMP_ROOT_INTERVAL,
4932 nla_get_u16);
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +08004933 FILL_IN_MESH_PARAM_IF_SET(tb, cfg,
Marco Porschea54fba2013-01-07 16:04:48 +01004934 dot11MeshHWMPconfirmationInterval,
4935 1, 65535, mask,
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +08004936 NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL,
4937 nla_get_u16);
Marco Porsch3b1c5a52013-01-07 16:04:52 +01004938 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, power_mode,
4939 NL80211_MESH_POWER_ACTIVE,
4940 NL80211_MESH_POWER_MAX,
4941 mask, NL80211_MESHCONF_POWER_MODE,
4942 nla_get_u32);
4943 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshAwakeWindowDuration,
4944 0, 65535, mask,
4945 NL80211_MESHCONF_AWAKE_WINDOW, nla_get_u16);
Colleen Twitty8e7c0532013-06-03 09:53:39 -07004946 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, plink_timeout, 1, 0xffffffff,
4947 mask, NL80211_MESHCONF_PLINK_TIMEOUT,
4948 nla_get_u32);
Johannes Bergbd90fdc2010-12-03 09:20:43 +01004949 if (mask_out)
4950 *mask_out = mask;
Javier Cardonac80d5452010-12-16 17:37:49 -08004951
Johannes Bergbd90fdc2010-12-03 09:20:43 +01004952 return 0;
4953
4954#undef FILL_IN_MESH_PARAM_IF_SET
4955}
4956
Javier Cardonac80d5452010-12-16 17:37:49 -08004957static int nl80211_parse_mesh_setup(struct genl_info *info,
4958 struct mesh_setup *setup)
4959{
Thomas Pedersenbb2798d2013-03-04 13:06:10 -08004960 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Javier Cardonac80d5452010-12-16 17:37:49 -08004961 struct nlattr *tb[NL80211_MESH_SETUP_ATTR_MAX + 1];
4962
4963 if (!info->attrs[NL80211_ATTR_MESH_SETUP])
4964 return -EINVAL;
4965 if (nla_parse_nested(tb, NL80211_MESH_SETUP_ATTR_MAX,
4966 info->attrs[NL80211_ATTR_MESH_SETUP],
4967 nl80211_mesh_setup_params_policy))
4968 return -EINVAL;
4969
Javier Cardonad299a1f2012-03-31 11:31:33 -07004970 if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC])
4971 setup->sync_method =
4972 (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC])) ?
4973 IEEE80211_SYNC_METHOD_VENDOR :
4974 IEEE80211_SYNC_METHOD_NEIGHBOR_OFFSET;
4975
Javier Cardonac80d5452010-12-16 17:37:49 -08004976 if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL])
4977 setup->path_sel_proto =
4978 (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL])) ?
4979 IEEE80211_PATH_PROTOCOL_VENDOR :
4980 IEEE80211_PATH_PROTOCOL_HWMP;
4981
4982 if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC])
4983 setup->path_metric =
4984 (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC])) ?
4985 IEEE80211_PATH_METRIC_VENDOR :
4986 IEEE80211_PATH_METRIC_AIRTIME;
4987
Javier Cardona581a8b02011-04-07 15:08:27 -07004988
4989 if (tb[NL80211_MESH_SETUP_IE]) {
Javier Cardonac80d5452010-12-16 17:37:49 -08004990 struct nlattr *ieattr =
Javier Cardona581a8b02011-04-07 15:08:27 -07004991 tb[NL80211_MESH_SETUP_IE];
Javier Cardonac80d5452010-12-16 17:37:49 -08004992 if (!is_valid_ie_attr(ieattr))
4993 return -EINVAL;
Javier Cardona581a8b02011-04-07 15:08:27 -07004994 setup->ie = nla_data(ieattr);
4995 setup->ie_len = nla_len(ieattr);
Javier Cardonac80d5452010-12-16 17:37:49 -08004996 }
Thomas Pedersenbb2798d2013-03-04 13:06:10 -08004997 if (tb[NL80211_MESH_SETUP_USERSPACE_MPM] &&
4998 !(rdev->wiphy.features & NL80211_FEATURE_USERSPACE_MPM))
4999 return -EINVAL;
5000 setup->user_mpm = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_MPM]);
Javier Cardonab130e5c2011-05-03 16:57:07 -07005001 setup->is_authenticated = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AUTH]);
5002 setup->is_secure = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AMPE]);
Thomas Pedersenbb2798d2013-03-04 13:06:10 -08005003 if (setup->is_secure)
5004 setup->user_mpm = true;
Javier Cardonac80d5452010-12-16 17:37:49 -08005005
Colleen Twitty6e16d902013-05-08 11:45:59 -07005006 if (tb[NL80211_MESH_SETUP_AUTH_PROTOCOL]) {
5007 if (!setup->user_mpm)
5008 return -EINVAL;
5009 setup->auth_id =
5010 nla_get_u8(tb[NL80211_MESH_SETUP_AUTH_PROTOCOL]);
5011 }
5012
Javier Cardonac80d5452010-12-16 17:37:49 -08005013 return 0;
5014}
5015
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005016static int nl80211_update_mesh_config(struct sk_buff *skb,
Johannes Berg29cbe682010-12-03 09:20:44 +01005017 struct genl_info *info)
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005018{
5019 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5020 struct net_device *dev = info->user_ptr[1];
Johannes Berg29cbe682010-12-03 09:20:44 +01005021 struct wireless_dev *wdev = dev->ieee80211_ptr;
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005022 struct mesh_config cfg;
5023 u32 mask;
5024 int err;
5025
Johannes Berg29cbe682010-12-03 09:20:44 +01005026 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT)
5027 return -EOPNOTSUPP;
5028
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005029 if (!rdev->ops->update_mesh_config)
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005030 return -EOPNOTSUPP;
5031
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005032 err = nl80211_parse_mesh_config(info, &cfg, &mask);
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005033 if (err)
5034 return err;
5035
Johannes Berg29cbe682010-12-03 09:20:44 +01005036 wdev_lock(wdev);
5037 if (!wdev->mesh_id_len)
5038 err = -ENOLINK;
5039
5040 if (!err)
Hila Gonene35e4d22012-06-27 17:19:42 +03005041 err = rdev_update_mesh_config(rdev, dev, mask, &cfg);
Johannes Berg29cbe682010-12-03 09:20:44 +01005042
5043 wdev_unlock(wdev);
5044
5045 return err;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005046}
5047
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005048static int nl80211_get_reg(struct sk_buff *skb, struct genl_info *info)
5049{
Johannes Berg458f4f92012-12-06 15:47:38 +01005050 const struct ieee80211_regdomain *regdom;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005051 struct sk_buff *msg;
5052 void *hdr = NULL;
5053 struct nlattr *nl_reg_rules;
5054 unsigned int i;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005055
5056 if (!cfg80211_regdomain)
Johannes Berg5fe231e2013-05-08 21:45:15 +02005057 return -EINVAL;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005058
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07005059 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg5fe231e2013-05-08 21:45:15 +02005060 if (!msg)
5061 return -ENOBUFS;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005062
Eric W. Biederman15e47302012-09-07 20:12:54 +00005063 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005064 NL80211_CMD_GET_REG);
5065 if (!hdr)
Julia Lawallefe1cf02011-01-28 15:17:11 +01005066 goto put_failure;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005067
Luis R. Rodriguez57b5ce02012-07-12 11:49:18 -07005068 if (reg_last_request_cell_base() &&
5069 nla_put_u32(msg, NL80211_ATTR_USER_REG_HINT_TYPE,
5070 NL80211_USER_REG_HINT_CELL_BASE))
5071 goto nla_put_failure;
5072
Johannes Berg458f4f92012-12-06 15:47:38 +01005073 rcu_read_lock();
5074 regdom = rcu_dereference(cfg80211_regdomain);
5075
5076 if (nla_put_string(msg, NL80211_ATTR_REG_ALPHA2, regdom->alpha2) ||
5077 (regdom->dfs_region &&
5078 nla_put_u8(msg, NL80211_ATTR_DFS_REGION, regdom->dfs_region)))
5079 goto nla_put_failure_rcu;
5080
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005081 nl_reg_rules = nla_nest_start(msg, NL80211_ATTR_REG_RULES);
5082 if (!nl_reg_rules)
Johannes Berg458f4f92012-12-06 15:47:38 +01005083 goto nla_put_failure_rcu;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005084
Johannes Berg458f4f92012-12-06 15:47:38 +01005085 for (i = 0; i < regdom->n_reg_rules; i++) {
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005086 struct nlattr *nl_reg_rule;
5087 const struct ieee80211_reg_rule *reg_rule;
5088 const struct ieee80211_freq_range *freq_range;
5089 const struct ieee80211_power_rule *power_rule;
5090
Johannes Berg458f4f92012-12-06 15:47:38 +01005091 reg_rule = &regdom->reg_rules[i];
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005092 freq_range = &reg_rule->freq_range;
5093 power_rule = &reg_rule->power_rule;
5094
5095 nl_reg_rule = nla_nest_start(msg, i);
5096 if (!nl_reg_rule)
Johannes Berg458f4f92012-12-06 15:47:38 +01005097 goto nla_put_failure_rcu;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005098
David S. Miller9360ffd2012-03-29 04:41:26 -04005099 if (nla_put_u32(msg, NL80211_ATTR_REG_RULE_FLAGS,
5100 reg_rule->flags) ||
5101 nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_START,
5102 freq_range->start_freq_khz) ||
5103 nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_END,
5104 freq_range->end_freq_khz) ||
5105 nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_MAX_BW,
5106 freq_range->max_bandwidth_khz) ||
5107 nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN,
5108 power_rule->max_antenna_gain) ||
5109 nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_EIRP,
5110 power_rule->max_eirp))
Johannes Berg458f4f92012-12-06 15:47:38 +01005111 goto nla_put_failure_rcu;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005112
5113 nla_nest_end(msg, nl_reg_rule);
5114 }
Johannes Berg458f4f92012-12-06 15:47:38 +01005115 rcu_read_unlock();
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005116
5117 nla_nest_end(msg, nl_reg_rules);
5118
5119 genlmsg_end(msg, hdr);
Johannes Berg5fe231e2013-05-08 21:45:15 +02005120 return genlmsg_reply(msg, info);
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005121
Johannes Berg458f4f92012-12-06 15:47:38 +01005122nla_put_failure_rcu:
5123 rcu_read_unlock();
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005124nla_put_failure:
5125 genlmsg_cancel(msg, hdr);
Julia Lawallefe1cf02011-01-28 15:17:11 +01005126put_failure:
Yuri Ershovd080e272010-06-29 15:08:07 +04005127 nlmsg_free(msg);
Johannes Berg5fe231e2013-05-08 21:45:15 +02005128 return -EMSGSIZE;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005129}
5130
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005131static int nl80211_set_reg(struct sk_buff *skb, struct genl_info *info)
5132{
5133 struct nlattr *tb[NL80211_REG_RULE_ATTR_MAX + 1];
5134 struct nlattr *nl_reg_rule;
5135 char *alpha2 = NULL;
5136 int rem_reg_rules = 0, r = 0;
5137 u32 num_rules = 0, rule_idx = 0, size_of_regd;
Luis R. Rodriguez4c7d3982013-11-13 18:54:02 +01005138 enum nl80211_dfs_regions dfs_region = NL80211_DFS_UNSET;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005139 struct ieee80211_regdomain *rd = NULL;
5140
5141 if (!info->attrs[NL80211_ATTR_REG_ALPHA2])
5142 return -EINVAL;
5143
5144 if (!info->attrs[NL80211_ATTR_REG_RULES])
5145 return -EINVAL;
5146
5147 alpha2 = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]);
5148
Luis R. Rodriguez8b60b072011-10-11 10:59:02 -07005149 if (info->attrs[NL80211_ATTR_DFS_REGION])
5150 dfs_region = nla_get_u8(info->attrs[NL80211_ATTR_DFS_REGION]);
5151
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005152 nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES],
Johannes Berg1a919312012-12-03 17:21:11 +01005153 rem_reg_rules) {
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005154 num_rules++;
5155 if (num_rules > NL80211_MAX_SUPP_REG_RULES)
Luis R. Rodriguez4776c6e2009-05-13 17:04:39 -04005156 return -EINVAL;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005157 }
5158
Luis R. Rodrigueze4387682013-11-05 09:18:01 -08005159 if (!reg_is_valid_request(alpha2))
5160 return -EINVAL;
5161
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005162 size_of_regd = sizeof(struct ieee80211_regdomain) +
Johannes Berg1a919312012-12-03 17:21:11 +01005163 num_rules * sizeof(struct ieee80211_reg_rule);
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005164
5165 rd = kzalloc(size_of_regd, GFP_KERNEL);
Johannes Berg6913b492012-12-04 00:48:59 +01005166 if (!rd)
5167 return -ENOMEM;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005168
5169 rd->n_reg_rules = num_rules;
5170 rd->alpha2[0] = alpha2[0];
5171 rd->alpha2[1] = alpha2[1];
5172
Luis R. Rodriguez8b60b072011-10-11 10:59:02 -07005173 /*
5174 * Disable DFS master mode if the DFS region was
5175 * not supported or known on this kernel.
5176 */
5177 if (reg_supported_dfs_region(dfs_region))
5178 rd->dfs_region = dfs_region;
5179
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005180 nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES],
Johannes Berg1a919312012-12-03 17:21:11 +01005181 rem_reg_rules) {
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005182 nla_parse(tb, NL80211_REG_RULE_ATTR_MAX,
Johannes Berg1a919312012-12-03 17:21:11 +01005183 nla_data(nl_reg_rule), nla_len(nl_reg_rule),
5184 reg_rule_policy);
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005185 r = parse_reg_rule(tb, &rd->reg_rules[rule_idx]);
5186 if (r)
5187 goto bad_reg;
5188
5189 rule_idx++;
5190
Luis R. Rodriguezd0e18f82009-05-13 17:04:40 -04005191 if (rule_idx > NL80211_MAX_SUPP_REG_RULES) {
5192 r = -EINVAL;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005193 goto bad_reg;
Luis R. Rodriguezd0e18f82009-05-13 17:04:40 -04005194 }
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005195 }
5196
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005197 r = set_regdom(rd);
Johannes Berg6913b492012-12-04 00:48:59 +01005198 /* set_regdom took ownership */
Johannes Berg1a919312012-12-03 17:21:11 +01005199 rd = NULL;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005200
Johannes Bergd2372b32008-10-24 20:32:20 +02005201 bad_reg:
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005202 kfree(rd);
Luis R. Rodriguezd0e18f82009-05-13 17:04:40 -04005203 return r;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005204}
5205
Johannes Berg83f5e2c2009-06-17 17:41:49 +02005206static int validate_scan_freqs(struct nlattr *freqs)
5207{
5208 struct nlattr *attr1, *attr2;
5209 int n_channels = 0, tmp1, tmp2;
5210
5211 nla_for_each_nested(attr1, freqs, tmp1) {
5212 n_channels++;
5213 /*
5214 * Some hardware has a limited channel list for
5215 * scanning, and it is pretty much nonsensical
5216 * to scan for a channel twice, so disallow that
5217 * and don't require drivers to check that the
5218 * channel list they get isn't longer than what
5219 * they can scan, as long as they can scan all
5220 * the channels they registered at once.
5221 */
5222 nla_for_each_nested(attr2, freqs, tmp2)
5223 if (attr1 != attr2 &&
5224 nla_get_u32(attr1) == nla_get_u32(attr2))
5225 return 0;
5226 }
5227
5228 return n_channels;
5229}
5230
Johannes Berg2a519312009-02-10 21:25:55 +01005231static int nl80211_trigger_scan(struct sk_buff *skb, struct genl_info *info)
5232{
Johannes Berg4c476992010-10-04 21:36:35 +02005233 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Bergfd014282012-06-18 19:17:03 +02005234 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg2a519312009-02-10 21:25:55 +01005235 struct cfg80211_scan_request *request;
Johannes Berg2a519312009-02-10 21:25:55 +01005236 struct nlattr *attr;
5237 struct wiphy *wiphy;
Johannes Berg83f5e2c2009-06-17 17:41:49 +02005238 int err, tmp, n_ssids = 0, n_channels, i;
Jouni Malinen70692ad2009-02-16 19:39:13 +02005239 size_t ie_len;
Johannes Berg2a519312009-02-10 21:25:55 +01005240
Johannes Bergf4a11bb2009-03-27 12:40:28 +01005241 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
5242 return -EINVAL;
5243
Johannes Berg79c97e92009-07-07 03:56:12 +02005244 wiphy = &rdev->wiphy;
Johannes Berg2a519312009-02-10 21:25:55 +01005245
Johannes Berg4c476992010-10-04 21:36:35 +02005246 if (!rdev->ops->scan)
5247 return -EOPNOTSUPP;
Johannes Berg2a519312009-02-10 21:25:55 +01005248
Johannes Bergf9f47522013-03-19 15:04:07 +01005249 if (rdev->scan_req) {
5250 err = -EBUSY;
5251 goto unlock;
5252 }
Johannes Berg2a519312009-02-10 21:25:55 +01005253
5254 if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
Johannes Berg83f5e2c2009-06-17 17:41:49 +02005255 n_channels = validate_scan_freqs(
5256 info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]);
Johannes Bergf9f47522013-03-19 15:04:07 +01005257 if (!n_channels) {
5258 err = -EINVAL;
5259 goto unlock;
5260 }
Johannes Berg2a519312009-02-10 21:25:55 +01005261 } else {
Ilan Peerbdfbec22014-01-09 11:37:23 +02005262 n_channels = ieee80211_get_num_supported_channels(wiphy);
Johannes Berg2a519312009-02-10 21:25:55 +01005263 }
5264
5265 if (info->attrs[NL80211_ATTR_SCAN_SSIDS])
5266 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp)
5267 n_ssids++;
5268
Johannes Bergf9f47522013-03-19 15:04:07 +01005269 if (n_ssids > wiphy->max_scan_ssids) {
5270 err = -EINVAL;
5271 goto unlock;
5272 }
Johannes Berg2a519312009-02-10 21:25:55 +01005273
Jouni Malinen70692ad2009-02-16 19:39:13 +02005274 if (info->attrs[NL80211_ATTR_IE])
5275 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
5276 else
5277 ie_len = 0;
5278
Johannes Bergf9f47522013-03-19 15:04:07 +01005279 if (ie_len > wiphy->max_scan_ie_len) {
5280 err = -EINVAL;
5281 goto unlock;
5282 }
Johannes Berg18a83652009-03-31 12:12:05 +02005283
Johannes Berg2a519312009-02-10 21:25:55 +01005284 request = kzalloc(sizeof(*request)
Luciano Coelhoa2cd43c2011-05-18 11:42:03 +03005285 + sizeof(*request->ssids) * n_ssids
5286 + sizeof(*request->channels) * n_channels
Jouni Malinen70692ad2009-02-16 19:39:13 +02005287 + ie_len, GFP_KERNEL);
Johannes Bergf9f47522013-03-19 15:04:07 +01005288 if (!request) {
5289 err = -ENOMEM;
5290 goto unlock;
5291 }
Johannes Berg2a519312009-02-10 21:25:55 +01005292
Johannes Berg2a519312009-02-10 21:25:55 +01005293 if (n_ssids)
Johannes Berg5ba63532009-08-07 17:54:07 +02005294 request->ssids = (void *)&request->channels[n_channels];
Johannes Berg2a519312009-02-10 21:25:55 +01005295 request->n_ssids = n_ssids;
Jouni Malinen70692ad2009-02-16 19:39:13 +02005296 if (ie_len) {
5297 if (request->ssids)
5298 request->ie = (void *)(request->ssids + n_ssids);
5299 else
5300 request->ie = (void *)(request->channels + n_channels);
5301 }
Johannes Berg2a519312009-02-10 21:25:55 +01005302
Johannes Berg584991d2009-11-02 13:32:03 +01005303 i = 0;
Johannes Berg2a519312009-02-10 21:25:55 +01005304 if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
5305 /* user specified, bail out if channel not found */
Johannes Berg2a519312009-02-10 21:25:55 +01005306 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_FREQUENCIES], tmp) {
Johannes Berg584991d2009-11-02 13:32:03 +01005307 struct ieee80211_channel *chan;
5308
5309 chan = ieee80211_get_channel(wiphy, nla_get_u32(attr));
5310
5311 if (!chan) {
Johannes Berg2a519312009-02-10 21:25:55 +01005312 err = -EINVAL;
5313 goto out_free;
5314 }
Johannes Berg584991d2009-11-02 13:32:03 +01005315
5316 /* ignore disabled channels */
5317 if (chan->flags & IEEE80211_CHAN_DISABLED)
5318 continue;
5319
5320 request->channels[i] = chan;
Johannes Berg2a519312009-02-10 21:25:55 +01005321 i++;
5322 }
5323 } else {
Johannes Berg34850ab2011-07-18 18:08:35 +02005324 enum ieee80211_band band;
5325
Johannes Berg2a519312009-02-10 21:25:55 +01005326 /* all channels */
Johannes Berg2a519312009-02-10 21:25:55 +01005327 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
5328 int j;
5329 if (!wiphy->bands[band])
5330 continue;
5331 for (j = 0; j < wiphy->bands[band]->n_channels; j++) {
Johannes Berg584991d2009-11-02 13:32:03 +01005332 struct ieee80211_channel *chan;
5333
5334 chan = &wiphy->bands[band]->channels[j];
5335
5336 if (chan->flags & IEEE80211_CHAN_DISABLED)
5337 continue;
5338
5339 request->channels[i] = chan;
Johannes Berg2a519312009-02-10 21:25:55 +01005340 i++;
5341 }
5342 }
5343 }
5344
Johannes Berg584991d2009-11-02 13:32:03 +01005345 if (!i) {
5346 err = -EINVAL;
5347 goto out_free;
5348 }
5349
5350 request->n_channels = i;
5351
Johannes Berg2a519312009-02-10 21:25:55 +01005352 i = 0;
5353 if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) {
5354 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) {
Luciano Coelho57a27e12011-06-07 20:42:26 +03005355 if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) {
Johannes Berg2a519312009-02-10 21:25:55 +01005356 err = -EINVAL;
5357 goto out_free;
5358 }
Luciano Coelho57a27e12011-06-07 20:42:26 +03005359 request->ssids[i].ssid_len = nla_len(attr);
Johannes Berg2a519312009-02-10 21:25:55 +01005360 memcpy(request->ssids[i].ssid, nla_data(attr), nla_len(attr));
Johannes Berg2a519312009-02-10 21:25:55 +01005361 i++;
5362 }
5363 }
5364
Jouni Malinen70692ad2009-02-16 19:39:13 +02005365 if (info->attrs[NL80211_ATTR_IE]) {
5366 request->ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Johannes Bergde95a542009-04-01 11:58:36 +02005367 memcpy((void *)request->ie,
5368 nla_data(info->attrs[NL80211_ATTR_IE]),
Jouni Malinen70692ad2009-02-16 19:39:13 +02005369 request->ie_len);
5370 }
5371
Johannes Berg34850ab2011-07-18 18:08:35 +02005372 for (i = 0; i < IEEE80211_NUM_BANDS; i++)
Johannes Berga401d2b2011-07-20 00:52:16 +02005373 if (wiphy->bands[i])
5374 request->rates[i] =
5375 (1 << wiphy->bands[i]->n_bitrates) - 1;
Johannes Berg34850ab2011-07-18 18:08:35 +02005376
5377 if (info->attrs[NL80211_ATTR_SCAN_SUPP_RATES]) {
5378 nla_for_each_nested(attr,
5379 info->attrs[NL80211_ATTR_SCAN_SUPP_RATES],
5380 tmp) {
5381 enum ieee80211_band band = nla_type(attr);
5382
Dan Carpenter84404622011-07-29 11:52:18 +03005383 if (band < 0 || band >= IEEE80211_NUM_BANDS) {
Johannes Berg34850ab2011-07-18 18:08:35 +02005384 err = -EINVAL;
5385 goto out_free;
5386 }
Felix Fietkau1b09cd82013-11-20 19:40:41 +01005387
5388 if (!wiphy->bands[band])
5389 continue;
5390
Johannes Berg34850ab2011-07-18 18:08:35 +02005391 err = ieee80211_get_ratemask(wiphy->bands[band],
5392 nla_data(attr),
5393 nla_len(attr),
5394 &request->rates[band]);
5395 if (err)
5396 goto out_free;
5397 }
5398 }
5399
Sam Leffler46856bb2012-10-11 21:03:32 -07005400 if (info->attrs[NL80211_ATTR_SCAN_FLAGS]) {
Sam Lefflered4737712012-10-11 21:03:31 -07005401 request->flags = nla_get_u32(
5402 info->attrs[NL80211_ATTR_SCAN_FLAGS]);
Johannes Berg00c3a6e2013-10-26 17:14:38 +02005403 if ((request->flags & NL80211_SCAN_FLAG_LOW_PRIORITY) &&
5404 !(wiphy->features & NL80211_FEATURE_LOW_PRIORITY_SCAN)) {
Sam Leffler46856bb2012-10-11 21:03:32 -07005405 err = -EOPNOTSUPP;
5406 goto out_free;
5407 }
5408 }
Sam Lefflered4737712012-10-11 21:03:31 -07005409
Rajkumar Manoharane9f935e2011-09-25 14:53:30 +05305410 request->no_cck =
5411 nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]);
5412
Johannes Bergfd014282012-06-18 19:17:03 +02005413 request->wdev = wdev;
Johannes Berg79c97e92009-07-07 03:56:12 +02005414 request->wiphy = &rdev->wiphy;
Sam Leffler15d60302012-10-11 21:03:34 -07005415 request->scan_start = jiffies;
Johannes Berg2a519312009-02-10 21:25:55 +01005416
Johannes Berg79c97e92009-07-07 03:56:12 +02005417 rdev->scan_req = request;
Hila Gonene35e4d22012-06-27 17:19:42 +03005418 err = rdev_scan(rdev, request);
Johannes Berg2a519312009-02-10 21:25:55 +01005419
Johannes Berg463d0182009-07-14 00:33:35 +02005420 if (!err) {
Johannes Bergfd014282012-06-18 19:17:03 +02005421 nl80211_send_scan_start(rdev, wdev);
5422 if (wdev->netdev)
5423 dev_hold(wdev->netdev);
Johannes Berg4c476992010-10-04 21:36:35 +02005424 } else {
Johannes Berg2a519312009-02-10 21:25:55 +01005425 out_free:
Johannes Berg79c97e92009-07-07 03:56:12 +02005426 rdev->scan_req = NULL;
Johannes Berg2a519312009-02-10 21:25:55 +01005427 kfree(request);
5428 }
Johannes Berg3b858752009-03-12 09:55:09 +01005429
Johannes Bergf9f47522013-03-19 15:04:07 +01005430 unlock:
Johannes Berg2a519312009-02-10 21:25:55 +01005431 return err;
5432}
5433
Luciano Coelho807f8a82011-05-11 17:09:35 +03005434static int nl80211_start_sched_scan(struct sk_buff *skb,
5435 struct genl_info *info)
5436{
5437 struct cfg80211_sched_scan_request *request;
5438 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5439 struct net_device *dev = info->user_ptr[1];
Luciano Coelho807f8a82011-05-11 17:09:35 +03005440 struct nlattr *attr;
5441 struct wiphy *wiphy;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005442 int err, tmp, n_ssids = 0, n_match_sets = 0, n_channels, i;
Luciano Coelhobbe6ad62011-05-11 17:09:37 +03005443 u32 interval;
Luciano Coelho807f8a82011-05-11 17:09:35 +03005444 enum ieee80211_band band;
5445 size_t ie_len;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005446 struct nlattr *tb[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1];
Luciano Coelho807f8a82011-05-11 17:09:35 +03005447
5448 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) ||
5449 !rdev->ops->sched_scan_start)
5450 return -EOPNOTSUPP;
5451
5452 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
5453 return -EINVAL;
5454
Luciano Coelhobbe6ad62011-05-11 17:09:37 +03005455 if (!info->attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL])
5456 return -EINVAL;
5457
5458 interval = nla_get_u32(info->attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]);
5459 if (interval == 0)
5460 return -EINVAL;
5461
Luciano Coelho807f8a82011-05-11 17:09:35 +03005462 wiphy = &rdev->wiphy;
5463
5464 if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
5465 n_channels = validate_scan_freqs(
5466 info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]);
5467 if (!n_channels)
5468 return -EINVAL;
5469 } else {
Ilan Peerbdfbec22014-01-09 11:37:23 +02005470 n_channels = ieee80211_get_num_supported_channels(wiphy);
Luciano Coelho807f8a82011-05-11 17:09:35 +03005471 }
5472
5473 if (info->attrs[NL80211_ATTR_SCAN_SSIDS])
5474 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS],
5475 tmp)
5476 n_ssids++;
5477
Luciano Coelho93b6aa62011-07-13 14:57:28 +03005478 if (n_ssids > wiphy->max_sched_scan_ssids)
Luciano Coelho807f8a82011-05-11 17:09:35 +03005479 return -EINVAL;
5480
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005481 if (info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH])
5482 nla_for_each_nested(attr,
5483 info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH],
5484 tmp)
5485 n_match_sets++;
5486
5487 if (n_match_sets > wiphy->max_match_sets)
5488 return -EINVAL;
5489
Luciano Coelho807f8a82011-05-11 17:09:35 +03005490 if (info->attrs[NL80211_ATTR_IE])
5491 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
5492 else
5493 ie_len = 0;
5494
Luciano Coelho5a865ba2011-07-13 14:57:29 +03005495 if (ie_len > wiphy->max_sched_scan_ie_len)
Luciano Coelho807f8a82011-05-11 17:09:35 +03005496 return -EINVAL;
5497
Luciano Coelhoc10841c2011-06-30 08:32:41 +03005498 if (rdev->sched_scan_req) {
5499 err = -EINPROGRESS;
5500 goto out;
5501 }
5502
Luciano Coelho807f8a82011-05-11 17:09:35 +03005503 request = kzalloc(sizeof(*request)
Luciano Coelhoa2cd43c2011-05-18 11:42:03 +03005504 + sizeof(*request->ssids) * n_ssids
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005505 + sizeof(*request->match_sets) * n_match_sets
Luciano Coelhoa2cd43c2011-05-18 11:42:03 +03005506 + sizeof(*request->channels) * n_channels
Luciano Coelho807f8a82011-05-11 17:09:35 +03005507 + ie_len, GFP_KERNEL);
Luciano Coelhoc10841c2011-06-30 08:32:41 +03005508 if (!request) {
5509 err = -ENOMEM;
5510 goto out;
5511 }
Luciano Coelho807f8a82011-05-11 17:09:35 +03005512
5513 if (n_ssids)
5514 request->ssids = (void *)&request->channels[n_channels];
5515 request->n_ssids = n_ssids;
5516 if (ie_len) {
5517 if (request->ssids)
5518 request->ie = (void *)(request->ssids + n_ssids);
5519 else
5520 request->ie = (void *)(request->channels + n_channels);
5521 }
5522
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005523 if (n_match_sets) {
5524 if (request->ie)
5525 request->match_sets = (void *)(request->ie + ie_len);
5526 else if (request->ssids)
5527 request->match_sets =
5528 (void *)(request->ssids + n_ssids);
5529 else
5530 request->match_sets =
5531 (void *)(request->channels + n_channels);
5532 }
5533 request->n_match_sets = n_match_sets;
5534
Luciano Coelho807f8a82011-05-11 17:09:35 +03005535 i = 0;
5536 if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
5537 /* user specified, bail out if channel not found */
5538 nla_for_each_nested(attr,
5539 info->attrs[NL80211_ATTR_SCAN_FREQUENCIES],
5540 tmp) {
5541 struct ieee80211_channel *chan;
5542
5543 chan = ieee80211_get_channel(wiphy, nla_get_u32(attr));
5544
5545 if (!chan) {
5546 err = -EINVAL;
5547 goto out_free;
5548 }
5549
5550 /* ignore disabled channels */
5551 if (chan->flags & IEEE80211_CHAN_DISABLED)
5552 continue;
5553
5554 request->channels[i] = chan;
5555 i++;
5556 }
5557 } else {
5558 /* all channels */
5559 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
5560 int j;
5561 if (!wiphy->bands[band])
5562 continue;
5563 for (j = 0; j < wiphy->bands[band]->n_channels; j++) {
5564 struct ieee80211_channel *chan;
5565
5566 chan = &wiphy->bands[band]->channels[j];
5567
5568 if (chan->flags & IEEE80211_CHAN_DISABLED)
5569 continue;
5570
5571 request->channels[i] = chan;
5572 i++;
5573 }
5574 }
5575 }
5576
5577 if (!i) {
5578 err = -EINVAL;
5579 goto out_free;
5580 }
5581
5582 request->n_channels = i;
5583
5584 i = 0;
5585 if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) {
5586 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS],
5587 tmp) {
Luciano Coelho57a27e12011-06-07 20:42:26 +03005588 if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) {
Luciano Coelho807f8a82011-05-11 17:09:35 +03005589 err = -EINVAL;
5590 goto out_free;
5591 }
Luciano Coelho57a27e12011-06-07 20:42:26 +03005592 request->ssids[i].ssid_len = nla_len(attr);
Luciano Coelho807f8a82011-05-11 17:09:35 +03005593 memcpy(request->ssids[i].ssid, nla_data(attr),
5594 nla_len(attr));
Luciano Coelho807f8a82011-05-11 17:09:35 +03005595 i++;
5596 }
5597 }
5598
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005599 i = 0;
5600 if (info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) {
5601 nla_for_each_nested(attr,
5602 info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH],
5603 tmp) {
Thomas Pedersen88e920b2012-06-21 11:09:54 -07005604 struct nlattr *ssid, *rssi;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005605
5606 nla_parse(tb, NL80211_SCHED_SCAN_MATCH_ATTR_MAX,
5607 nla_data(attr), nla_len(attr),
5608 nl80211_match_policy);
Johannes Berg4a4ab0d2012-06-13 11:17:11 +02005609 ssid = tb[NL80211_SCHED_SCAN_MATCH_ATTR_SSID];
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005610 if (ssid) {
5611 if (nla_len(ssid) > IEEE80211_MAX_SSID_LEN) {
5612 err = -EINVAL;
5613 goto out_free;
5614 }
5615 memcpy(request->match_sets[i].ssid.ssid,
5616 nla_data(ssid), nla_len(ssid));
5617 request->match_sets[i].ssid.ssid_len =
5618 nla_len(ssid);
5619 }
Thomas Pedersen88e920b2012-06-21 11:09:54 -07005620 rssi = tb[NL80211_SCHED_SCAN_MATCH_ATTR_RSSI];
5621 if (rssi)
5622 request->rssi_thold = nla_get_u32(rssi);
5623 else
5624 request->rssi_thold =
5625 NL80211_SCAN_RSSI_THOLD_OFF;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005626 i++;
5627 }
5628 }
5629
Luciano Coelho807f8a82011-05-11 17:09:35 +03005630 if (info->attrs[NL80211_ATTR_IE]) {
5631 request->ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
5632 memcpy((void *)request->ie,
5633 nla_data(info->attrs[NL80211_ATTR_IE]),
5634 request->ie_len);
5635 }
5636
Sam Leffler46856bb2012-10-11 21:03:32 -07005637 if (info->attrs[NL80211_ATTR_SCAN_FLAGS]) {
Sam Lefflered4737712012-10-11 21:03:31 -07005638 request->flags = nla_get_u32(
5639 info->attrs[NL80211_ATTR_SCAN_FLAGS]);
Johannes Berg00c3a6e2013-10-26 17:14:38 +02005640 if ((request->flags & NL80211_SCAN_FLAG_LOW_PRIORITY) &&
5641 !(wiphy->features & NL80211_FEATURE_LOW_PRIORITY_SCAN)) {
Sam Leffler46856bb2012-10-11 21:03:32 -07005642 err = -EOPNOTSUPP;
5643 goto out_free;
5644 }
5645 }
Sam Lefflered4737712012-10-11 21:03:31 -07005646
Luciano Coelho807f8a82011-05-11 17:09:35 +03005647 request->dev = dev;
5648 request->wiphy = &rdev->wiphy;
Luciano Coelhobbe6ad62011-05-11 17:09:37 +03005649 request->interval = interval;
Sam Leffler15d60302012-10-11 21:03:34 -07005650 request->scan_start = jiffies;
Luciano Coelho807f8a82011-05-11 17:09:35 +03005651
Hila Gonene35e4d22012-06-27 17:19:42 +03005652 err = rdev_sched_scan_start(rdev, dev, request);
Luciano Coelho807f8a82011-05-11 17:09:35 +03005653 if (!err) {
5654 rdev->sched_scan_req = request;
5655 nl80211_send_sched_scan(rdev, dev,
5656 NL80211_CMD_START_SCHED_SCAN);
5657 goto out;
5658 }
5659
5660out_free:
5661 kfree(request);
5662out:
5663 return err;
5664}
5665
5666static int nl80211_stop_sched_scan(struct sk_buff *skb,
5667 struct genl_info *info)
5668{
5669 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5670
5671 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) ||
5672 !rdev->ops->sched_scan_stop)
5673 return -EOPNOTSUPP;
5674
Johannes Berg5fe231e2013-05-08 21:45:15 +02005675 return __cfg80211_stop_sched_scan(rdev, false);
Luciano Coelho807f8a82011-05-11 17:09:35 +03005676}
5677
Simon Wunderlich04f39042013-02-08 18:16:19 +01005678static int nl80211_start_radar_detection(struct sk_buff *skb,
5679 struct genl_info *info)
5680{
5681 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5682 struct net_device *dev = info->user_ptr[1];
5683 struct wireless_dev *wdev = dev->ieee80211_ptr;
5684 struct cfg80211_chan_def chandef;
Luis R. Rodriguez55f74352013-11-25 20:56:10 +01005685 enum nl80211_dfs_regions dfs_region;
Simon Wunderlich04f39042013-02-08 18:16:19 +01005686 int err;
5687
Luis R. Rodriguez55f74352013-11-25 20:56:10 +01005688 dfs_region = reg_get_dfs_region(wdev->wiphy);
5689 if (dfs_region == NL80211_DFS_UNSET)
5690 return -EINVAL;
5691
Simon Wunderlich04f39042013-02-08 18:16:19 +01005692 err = nl80211_parse_chandef(rdev, info, &chandef);
5693 if (err)
5694 return err;
5695
Simon Wunderlichff311bc2013-09-03 19:43:18 +02005696 if (netif_carrier_ok(dev))
5697 return -EBUSY;
5698
Simon Wunderlich04f39042013-02-08 18:16:19 +01005699 if (wdev->cac_started)
5700 return -EBUSY;
5701
5702 err = cfg80211_chandef_dfs_required(wdev->wiphy, &chandef);
5703 if (err < 0)
5704 return err;
5705
5706 if (err == 0)
5707 return -EINVAL;
5708
Janusz Dziedzicfe7c3a12013-11-05 14:48:48 +01005709 if (!cfg80211_chandef_dfs_usable(wdev->wiphy, &chandef))
Simon Wunderlich04f39042013-02-08 18:16:19 +01005710 return -EINVAL;
5711
5712 if (!rdev->ops->start_radar_detection)
5713 return -EOPNOTSUPP;
5714
Simon Wunderlich04f39042013-02-08 18:16:19 +01005715 err = cfg80211_can_use_iftype_chan(rdev, wdev, wdev->iftype,
5716 chandef.chan, CHAN_MODE_SHARED,
5717 BIT(chandef.width));
5718 if (err)
Johannes Berg5fe231e2013-05-08 21:45:15 +02005719 return err;
Simon Wunderlich04f39042013-02-08 18:16:19 +01005720
5721 err = rdev->ops->start_radar_detection(&rdev->wiphy, dev, &chandef);
5722 if (!err) {
5723 wdev->channel = chandef.chan;
5724 wdev->cac_started = true;
5725 wdev->cac_start_time = jiffies;
5726 }
Simon Wunderlich04f39042013-02-08 18:16:19 +01005727 return err;
5728}
5729
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02005730static int nl80211_channel_switch(struct sk_buff *skb, struct genl_info *info)
5731{
5732 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5733 struct net_device *dev = info->user_ptr[1];
5734 struct wireless_dev *wdev = dev->ieee80211_ptr;
5735 struct cfg80211_csa_settings params;
5736 /* csa_attrs is defined static to avoid waste of stack size - this
5737 * function is called under RTNL lock, so this should not be a problem.
5738 */
5739 static struct nlattr *csa_attrs[NL80211_ATTR_MAX+1];
5740 u8 radar_detect_width = 0;
5741 int err;
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02005742 bool need_new_beacon = false;
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02005743
5744 if (!rdev->ops->channel_switch ||
5745 !(rdev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH))
5746 return -EOPNOTSUPP;
5747
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02005748 switch (dev->ieee80211_ptr->iftype) {
5749 case NL80211_IFTYPE_AP:
5750 case NL80211_IFTYPE_P2P_GO:
5751 need_new_beacon = true;
5752
5753 /* useless if AP is not running */
5754 if (!wdev->beacon_interval)
5755 return -EINVAL;
5756 break;
5757 case NL80211_IFTYPE_ADHOC:
Chun-Yeow Yeohc6da6742013-10-14 19:08:28 -07005758 case NL80211_IFTYPE_MESH_POINT:
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02005759 break;
5760 default:
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02005761 return -EOPNOTSUPP;
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02005762 }
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02005763
5764 memset(&params, 0, sizeof(params));
5765
5766 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] ||
5767 !info->attrs[NL80211_ATTR_CH_SWITCH_COUNT])
5768 return -EINVAL;
5769
5770 /* only important for AP, IBSS and mesh create IEs internally */
Andrei Otcheretianskid0a361a2013-10-17 10:52:17 +02005771 if (need_new_beacon && !info->attrs[NL80211_ATTR_CSA_IES])
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02005772 return -EINVAL;
5773
5774 params.count = nla_get_u32(info->attrs[NL80211_ATTR_CH_SWITCH_COUNT]);
5775
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02005776 if (!need_new_beacon)
5777 goto skip_beacons;
5778
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02005779 err = nl80211_parse_beacon(info->attrs, &params.beacon_after);
5780 if (err)
5781 return err;
5782
5783 err = nla_parse_nested(csa_attrs, NL80211_ATTR_MAX,
5784 info->attrs[NL80211_ATTR_CSA_IES],
5785 nl80211_policy);
5786 if (err)
5787 return err;
5788
5789 err = nl80211_parse_beacon(csa_attrs, &params.beacon_csa);
5790 if (err)
5791 return err;
5792
5793 if (!csa_attrs[NL80211_ATTR_CSA_C_OFF_BEACON])
5794 return -EINVAL;
5795
5796 params.counter_offset_beacon =
5797 nla_get_u16(csa_attrs[NL80211_ATTR_CSA_C_OFF_BEACON]);
5798 if (params.counter_offset_beacon >= params.beacon_csa.tail_len)
5799 return -EINVAL;
5800
5801 /* sanity check - counters should be the same */
5802 if (params.beacon_csa.tail[params.counter_offset_beacon] !=
5803 params.count)
5804 return -EINVAL;
5805
5806 if (csa_attrs[NL80211_ATTR_CSA_C_OFF_PRESP]) {
5807 params.counter_offset_presp =
5808 nla_get_u16(csa_attrs[NL80211_ATTR_CSA_C_OFF_PRESP]);
5809 if (params.counter_offset_presp >=
5810 params.beacon_csa.probe_resp_len)
5811 return -EINVAL;
5812
5813 if (params.beacon_csa.probe_resp[params.counter_offset_presp] !=
5814 params.count)
5815 return -EINVAL;
5816 }
5817
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02005818skip_beacons:
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02005819 err = nl80211_parse_chandef(rdev, info, &params.chandef);
5820 if (err)
5821 return err;
5822
5823 if (!cfg80211_reg_can_beacon(&rdev->wiphy, &params.chandef))
5824 return -EINVAL;
5825
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02005826 if (dev->ieee80211_ptr->iftype == NL80211_IFTYPE_AP ||
Simon Wunderlich5336fa82013-10-07 18:41:05 +02005827 dev->ieee80211_ptr->iftype == NL80211_IFTYPE_P2P_GO ||
5828 dev->ieee80211_ptr->iftype == NL80211_IFTYPE_ADHOC) {
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02005829 err = cfg80211_chandef_dfs_required(wdev->wiphy,
5830 &params.chandef);
5831 if (err < 0) {
5832 return err;
5833 } else if (err) {
5834 radar_detect_width = BIT(params.chandef.width);
5835 params.radar_required = true;
5836 }
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02005837 }
5838
5839 err = cfg80211_can_use_iftype_chan(rdev, wdev, wdev->iftype,
5840 params.chandef.chan,
5841 CHAN_MODE_SHARED,
5842 radar_detect_width);
5843 if (err)
5844 return err;
5845
5846 if (info->attrs[NL80211_ATTR_CH_SWITCH_BLOCK_TX])
5847 params.block_tx = true;
5848
Simon Wunderlichc56589e2013-11-21 18:19:49 +01005849 wdev_lock(wdev);
5850 err = rdev_channel_switch(rdev, dev, &params);
5851 wdev_unlock(wdev);
5852
5853 return err;
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02005854}
5855
Johannes Berg9720bb32011-06-21 09:45:33 +02005856static int nl80211_send_bss(struct sk_buff *msg, struct netlink_callback *cb,
5857 u32 seq, int flags,
Johannes Berg2a519312009-02-10 21:25:55 +01005858 struct cfg80211_registered_device *rdev,
Johannes Berg48ab9052009-07-10 18:42:31 +02005859 struct wireless_dev *wdev,
5860 struct cfg80211_internal_bss *intbss)
Johannes Berg2a519312009-02-10 21:25:55 +01005861{
Johannes Berg48ab9052009-07-10 18:42:31 +02005862 struct cfg80211_bss *res = &intbss->pub;
Johannes Berg9caf0362012-11-29 01:25:20 +01005863 const struct cfg80211_bss_ies *ies;
Johannes Berg2a519312009-02-10 21:25:55 +01005864 void *hdr;
5865 struct nlattr *bss;
Johannes Berg8cef2c92013-02-05 16:54:31 +01005866 bool tsf = false;
Johannes Berg48ab9052009-07-10 18:42:31 +02005867
5868 ASSERT_WDEV_LOCK(wdev);
Johannes Berg2a519312009-02-10 21:25:55 +01005869
Eric W. Biederman15e47302012-09-07 20:12:54 +00005870 hdr = nl80211hdr_put(msg, NETLINK_CB(cb->skb).portid, seq, flags,
Johannes Berg2a519312009-02-10 21:25:55 +01005871 NL80211_CMD_NEW_SCAN_RESULTS);
5872 if (!hdr)
5873 return -1;
5874
Johannes Berg9720bb32011-06-21 09:45:33 +02005875 genl_dump_check_consistent(cb, hdr, &nl80211_fam);
5876
Johannes Berg97990a02013-04-19 01:02:55 +02005877 if (nla_put_u32(msg, NL80211_ATTR_GENERATION, rdev->bss_generation))
5878 goto nla_put_failure;
5879 if (wdev->netdev &&
David S. Miller9360ffd2012-03-29 04:41:26 -04005880 nla_put_u32(msg, NL80211_ATTR_IFINDEX, wdev->netdev->ifindex))
5881 goto nla_put_failure;
Johannes Berg97990a02013-04-19 01:02:55 +02005882 if (nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)))
5883 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01005884
5885 bss = nla_nest_start(msg, NL80211_ATTR_BSS);
5886 if (!bss)
5887 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04005888 if ((!is_zero_ether_addr(res->bssid) &&
Johannes Berg9caf0362012-11-29 01:25:20 +01005889 nla_put(msg, NL80211_BSS_BSSID, ETH_ALEN, res->bssid)))
David S. Miller9360ffd2012-03-29 04:41:26 -04005890 goto nla_put_failure;
Johannes Berg9caf0362012-11-29 01:25:20 +01005891
5892 rcu_read_lock();
5893 ies = rcu_dereference(res->ies);
Johannes Berg8cef2c92013-02-05 16:54:31 +01005894 if (ies) {
5895 if (nla_put_u64(msg, NL80211_BSS_TSF, ies->tsf))
5896 goto fail_unlock_rcu;
5897 tsf = true;
5898 if (ies->len && nla_put(msg, NL80211_BSS_INFORMATION_ELEMENTS,
5899 ies->len, ies->data))
5900 goto fail_unlock_rcu;
Johannes Berg9caf0362012-11-29 01:25:20 +01005901 }
5902 ies = rcu_dereference(res->beacon_ies);
Johannes Berg8cef2c92013-02-05 16:54:31 +01005903 if (ies) {
5904 if (!tsf && nla_put_u64(msg, NL80211_BSS_TSF, ies->tsf))
5905 goto fail_unlock_rcu;
5906 if (ies->len && nla_put(msg, NL80211_BSS_BEACON_IES,
5907 ies->len, ies->data))
5908 goto fail_unlock_rcu;
Johannes Berg9caf0362012-11-29 01:25:20 +01005909 }
5910 rcu_read_unlock();
5911
David S. Miller9360ffd2012-03-29 04:41:26 -04005912 if (res->beacon_interval &&
5913 nla_put_u16(msg, NL80211_BSS_BEACON_INTERVAL, res->beacon_interval))
5914 goto nla_put_failure;
5915 if (nla_put_u16(msg, NL80211_BSS_CAPABILITY, res->capability) ||
5916 nla_put_u32(msg, NL80211_BSS_FREQUENCY, res->channel->center_freq) ||
Simon Wunderlichdcd6eac2013-07-08 16:55:49 +02005917 nla_put_u32(msg, NL80211_BSS_CHAN_WIDTH, res->scan_width) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04005918 nla_put_u32(msg, NL80211_BSS_SEEN_MS_AGO,
5919 jiffies_to_msecs(jiffies - intbss->ts)))
5920 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01005921
Johannes Berg77965c92009-02-18 18:45:06 +01005922 switch (rdev->wiphy.signal_type) {
Johannes Berg2a519312009-02-10 21:25:55 +01005923 case CFG80211_SIGNAL_TYPE_MBM:
David S. Miller9360ffd2012-03-29 04:41:26 -04005924 if (nla_put_u32(msg, NL80211_BSS_SIGNAL_MBM, res->signal))
5925 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01005926 break;
5927 case CFG80211_SIGNAL_TYPE_UNSPEC:
David S. Miller9360ffd2012-03-29 04:41:26 -04005928 if (nla_put_u8(msg, NL80211_BSS_SIGNAL_UNSPEC, res->signal))
5929 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01005930 break;
5931 default:
5932 break;
5933 }
5934
Johannes Berg48ab9052009-07-10 18:42:31 +02005935 switch (wdev->iftype) {
Johannes Berg074ac8d2010-09-16 14:58:22 +02005936 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Berg48ab9052009-07-10 18:42:31 +02005937 case NL80211_IFTYPE_STATION:
David S. Miller9360ffd2012-03-29 04:41:26 -04005938 if (intbss == wdev->current_bss &&
5939 nla_put_u32(msg, NL80211_BSS_STATUS,
5940 NL80211_BSS_STATUS_ASSOCIATED))
5941 goto nla_put_failure;
Johannes Berg48ab9052009-07-10 18:42:31 +02005942 break;
5943 case NL80211_IFTYPE_ADHOC:
David S. Miller9360ffd2012-03-29 04:41:26 -04005944 if (intbss == wdev->current_bss &&
5945 nla_put_u32(msg, NL80211_BSS_STATUS,
5946 NL80211_BSS_STATUS_IBSS_JOINED))
5947 goto nla_put_failure;
Johannes Berg48ab9052009-07-10 18:42:31 +02005948 break;
5949 default:
5950 break;
5951 }
5952
Johannes Berg2a519312009-02-10 21:25:55 +01005953 nla_nest_end(msg, bss);
5954
5955 return genlmsg_end(msg, hdr);
5956
Johannes Berg8cef2c92013-02-05 16:54:31 +01005957 fail_unlock_rcu:
5958 rcu_read_unlock();
Johannes Berg2a519312009-02-10 21:25:55 +01005959 nla_put_failure:
5960 genlmsg_cancel(msg, hdr);
5961 return -EMSGSIZE;
5962}
5963
Johannes Berg97990a02013-04-19 01:02:55 +02005964static int nl80211_dump_scan(struct sk_buff *skb, struct netlink_callback *cb)
Johannes Berg2a519312009-02-10 21:25:55 +01005965{
Johannes Berg48ab9052009-07-10 18:42:31 +02005966 struct cfg80211_registered_device *rdev;
Johannes Berg2a519312009-02-10 21:25:55 +01005967 struct cfg80211_internal_bss *scan;
Johannes Berg48ab9052009-07-10 18:42:31 +02005968 struct wireless_dev *wdev;
Johannes Berg97990a02013-04-19 01:02:55 +02005969 int start = cb->args[2], idx = 0;
Johannes Berg2a519312009-02-10 21:25:55 +01005970 int err;
5971
Johannes Berg97990a02013-04-19 01:02:55 +02005972 err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev);
Johannes Berg67748892010-10-04 21:14:06 +02005973 if (err)
5974 return err;
Johannes Berg2a519312009-02-10 21:25:55 +01005975
Johannes Berg48ab9052009-07-10 18:42:31 +02005976 wdev_lock(wdev);
5977 spin_lock_bh(&rdev->bss_lock);
5978 cfg80211_bss_expire(rdev);
5979
Johannes Berg9720bb32011-06-21 09:45:33 +02005980 cb->seq = rdev->bss_generation;
5981
Johannes Berg48ab9052009-07-10 18:42:31 +02005982 list_for_each_entry(scan, &rdev->bss_list, list) {
Johannes Berg2a519312009-02-10 21:25:55 +01005983 if (++idx <= start)
5984 continue;
Johannes Berg9720bb32011-06-21 09:45:33 +02005985 if (nl80211_send_bss(skb, cb,
Johannes Berg2a519312009-02-10 21:25:55 +01005986 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Johannes Berg48ab9052009-07-10 18:42:31 +02005987 rdev, wdev, scan) < 0) {
Johannes Berg2a519312009-02-10 21:25:55 +01005988 idx--;
Johannes Berg67748892010-10-04 21:14:06 +02005989 break;
Johannes Berg2a519312009-02-10 21:25:55 +01005990 }
5991 }
5992
Johannes Berg48ab9052009-07-10 18:42:31 +02005993 spin_unlock_bh(&rdev->bss_lock);
5994 wdev_unlock(wdev);
Johannes Berg2a519312009-02-10 21:25:55 +01005995
Johannes Berg97990a02013-04-19 01:02:55 +02005996 cb->args[2] = idx;
5997 nl80211_finish_wdev_dump(rdev);
Johannes Berg2a519312009-02-10 21:25:55 +01005998
Johannes Berg67748892010-10-04 21:14:06 +02005999 return skb->len;
Johannes Berg2a519312009-02-10 21:25:55 +01006000}
6001
Eric W. Biederman15e47302012-09-07 20:12:54 +00006002static int nl80211_send_survey(struct sk_buff *msg, u32 portid, u32 seq,
Holger Schurig61fa7132009-11-11 12:25:40 +01006003 int flags, struct net_device *dev,
6004 struct survey_info *survey)
6005{
6006 void *hdr;
6007 struct nlattr *infoattr;
6008
Eric W. Biederman15e47302012-09-07 20:12:54 +00006009 hdr = nl80211hdr_put(msg, portid, seq, flags,
Holger Schurig61fa7132009-11-11 12:25:40 +01006010 NL80211_CMD_NEW_SURVEY_RESULTS);
6011 if (!hdr)
6012 return -ENOMEM;
6013
David S. Miller9360ffd2012-03-29 04:41:26 -04006014 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex))
6015 goto nla_put_failure;
Holger Schurig61fa7132009-11-11 12:25:40 +01006016
6017 infoattr = nla_nest_start(msg, NL80211_ATTR_SURVEY_INFO);
6018 if (!infoattr)
6019 goto nla_put_failure;
6020
David S. Miller9360ffd2012-03-29 04:41:26 -04006021 if (nla_put_u32(msg, NL80211_SURVEY_INFO_FREQUENCY,
6022 survey->channel->center_freq))
6023 goto nla_put_failure;
6024
6025 if ((survey->filled & SURVEY_INFO_NOISE_DBM) &&
6026 nla_put_u8(msg, NL80211_SURVEY_INFO_NOISE, survey->noise))
6027 goto nla_put_failure;
6028 if ((survey->filled & SURVEY_INFO_IN_USE) &&
6029 nla_put_flag(msg, NL80211_SURVEY_INFO_IN_USE))
6030 goto nla_put_failure;
6031 if ((survey->filled & SURVEY_INFO_CHANNEL_TIME) &&
6032 nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME,
6033 survey->channel_time))
6034 goto nla_put_failure;
6035 if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_BUSY) &&
6036 nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_BUSY,
6037 survey->channel_time_busy))
6038 goto nla_put_failure;
6039 if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_EXT_BUSY) &&
6040 nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_EXT_BUSY,
6041 survey->channel_time_ext_busy))
6042 goto nla_put_failure;
6043 if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_RX) &&
6044 nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_RX,
6045 survey->channel_time_rx))
6046 goto nla_put_failure;
6047 if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_TX) &&
6048 nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_TX,
6049 survey->channel_time_tx))
6050 goto nla_put_failure;
Holger Schurig61fa7132009-11-11 12:25:40 +01006051
6052 nla_nest_end(msg, infoattr);
6053
6054 return genlmsg_end(msg, hdr);
6055
6056 nla_put_failure:
6057 genlmsg_cancel(msg, hdr);
6058 return -EMSGSIZE;
6059}
6060
6061static int nl80211_dump_survey(struct sk_buff *skb,
6062 struct netlink_callback *cb)
6063{
6064 struct survey_info survey;
6065 struct cfg80211_registered_device *dev;
Johannes Berg97990a02013-04-19 01:02:55 +02006066 struct wireless_dev *wdev;
6067 int survey_idx = cb->args[2];
Holger Schurig61fa7132009-11-11 12:25:40 +01006068 int res;
6069
Johannes Berg97990a02013-04-19 01:02:55 +02006070 res = nl80211_prepare_wdev_dump(skb, cb, &dev, &wdev);
Johannes Berg67748892010-10-04 21:14:06 +02006071 if (res)
6072 return res;
Holger Schurig61fa7132009-11-11 12:25:40 +01006073
Johannes Berg97990a02013-04-19 01:02:55 +02006074 if (!wdev->netdev) {
6075 res = -EINVAL;
6076 goto out_err;
6077 }
6078
Holger Schurig61fa7132009-11-11 12:25:40 +01006079 if (!dev->ops->dump_survey) {
6080 res = -EOPNOTSUPP;
6081 goto out_err;
6082 }
6083
6084 while (1) {
Luis R. Rodriguez180cdc72011-05-27 07:24:02 -07006085 struct ieee80211_channel *chan;
6086
Johannes Berg97990a02013-04-19 01:02:55 +02006087 res = rdev_dump_survey(dev, wdev->netdev, survey_idx, &survey);
Holger Schurig61fa7132009-11-11 12:25:40 +01006088 if (res == -ENOENT)
6089 break;
6090 if (res)
6091 goto out_err;
6092
Luis R. Rodriguez180cdc72011-05-27 07:24:02 -07006093 /* Survey without a channel doesn't make sense */
6094 if (!survey.channel) {
6095 res = -EINVAL;
6096 goto out;
6097 }
6098
6099 chan = ieee80211_get_channel(&dev->wiphy,
6100 survey.channel->center_freq);
6101 if (!chan || chan->flags & IEEE80211_CHAN_DISABLED) {
6102 survey_idx++;
6103 continue;
6104 }
6105
Holger Schurig61fa7132009-11-11 12:25:40 +01006106 if (nl80211_send_survey(skb,
Eric W. Biederman15e47302012-09-07 20:12:54 +00006107 NETLINK_CB(cb->skb).portid,
Holger Schurig61fa7132009-11-11 12:25:40 +01006108 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Johannes Berg97990a02013-04-19 01:02:55 +02006109 wdev->netdev, &survey) < 0)
Holger Schurig61fa7132009-11-11 12:25:40 +01006110 goto out;
6111 survey_idx++;
6112 }
6113
6114 out:
Johannes Berg97990a02013-04-19 01:02:55 +02006115 cb->args[2] = survey_idx;
Holger Schurig61fa7132009-11-11 12:25:40 +01006116 res = skb->len;
6117 out_err:
Johannes Berg97990a02013-04-19 01:02:55 +02006118 nl80211_finish_wdev_dump(dev);
Holger Schurig61fa7132009-11-11 12:25:40 +01006119 return res;
6120}
6121
Samuel Ortizb23aa672009-07-01 21:26:54 +02006122static bool nl80211_valid_wpa_versions(u32 wpa_versions)
6123{
6124 return !(wpa_versions & ~(NL80211_WPA_VERSION_1 |
6125 NL80211_WPA_VERSION_2));
6126}
6127
Jouni Malinen636a5d32009-03-19 13:39:22 +02006128static int nl80211_authenticate(struct sk_buff *skb, struct genl_info *info)
6129{
Johannes Berg4c476992010-10-04 21:36:35 +02006130 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6131 struct net_device *dev = info->user_ptr[1];
Johannes Berg19957bb2009-07-02 17:20:43 +02006132 struct ieee80211_channel *chan;
Jouni Malinene39e5b52012-09-30 19:29:39 +03006133 const u8 *bssid, *ssid, *ie = NULL, *sae_data = NULL;
6134 int err, ssid_len, ie_len = 0, sae_data_len = 0;
Johannes Berg19957bb2009-07-02 17:20:43 +02006135 enum nl80211_auth_type auth_type;
Johannes Bergfffd0932009-07-08 14:22:54 +02006136 struct key_parse key;
Jouni Malinend5cdfac2010-04-04 09:37:19 +03006137 bool local_state_change;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006138
Johannes Bergf4a11bb2009-03-27 12:40:28 +01006139 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
6140 return -EINVAL;
6141
6142 if (!info->attrs[NL80211_ATTR_MAC])
6143 return -EINVAL;
6144
Jouni Malinen17780922009-03-27 20:52:47 +02006145 if (!info->attrs[NL80211_ATTR_AUTH_TYPE])
6146 return -EINVAL;
6147
Johannes Berg19957bb2009-07-02 17:20:43 +02006148 if (!info->attrs[NL80211_ATTR_SSID])
6149 return -EINVAL;
6150
6151 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ])
6152 return -EINVAL;
6153
Johannes Bergfffd0932009-07-08 14:22:54 +02006154 err = nl80211_parse_key(info, &key);
6155 if (err)
6156 return err;
6157
6158 if (key.idx >= 0) {
Johannes Berge31b8212010-10-05 19:39:30 +02006159 if (key.type != -1 && key.type != NL80211_KEYTYPE_GROUP)
6160 return -EINVAL;
Johannes Bergfffd0932009-07-08 14:22:54 +02006161 if (!key.p.key || !key.p.key_len)
6162 return -EINVAL;
6163 if ((key.p.cipher != WLAN_CIPHER_SUITE_WEP40 ||
6164 key.p.key_len != WLAN_KEY_LEN_WEP40) &&
6165 (key.p.cipher != WLAN_CIPHER_SUITE_WEP104 ||
6166 key.p.key_len != WLAN_KEY_LEN_WEP104))
6167 return -EINVAL;
6168 if (key.idx > 4)
6169 return -EINVAL;
6170 } else {
6171 key.p.key_len = 0;
6172 key.p.key = NULL;
6173 }
6174
Johannes Bergafea0b72010-08-10 09:46:42 +02006175 if (key.idx >= 0) {
6176 int i;
6177 bool ok = false;
6178 for (i = 0; i < rdev->wiphy.n_cipher_suites; i++) {
6179 if (key.p.cipher == rdev->wiphy.cipher_suites[i]) {
6180 ok = true;
6181 break;
6182 }
6183 }
Johannes Berg4c476992010-10-04 21:36:35 +02006184 if (!ok)
6185 return -EINVAL;
Johannes Bergafea0b72010-08-10 09:46:42 +02006186 }
6187
Johannes Berg4c476992010-10-04 21:36:35 +02006188 if (!rdev->ops->auth)
6189 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006190
Johannes Berg074ac8d2010-09-16 14:58:22 +02006191 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02006192 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
6193 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02006194
Johannes Berg19957bb2009-07-02 17:20:43 +02006195 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Johannes Berg79c97e92009-07-07 03:56:12 +02006196 chan = ieee80211_get_channel(&rdev->wiphy,
Johannes Berg19957bb2009-07-02 17:20:43 +02006197 nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]));
Johannes Berg4c476992010-10-04 21:36:35 +02006198 if (!chan || (chan->flags & IEEE80211_CHAN_DISABLED))
6199 return -EINVAL;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006200
Johannes Berg19957bb2009-07-02 17:20:43 +02006201 ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
6202 ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
6203
6204 if (info->attrs[NL80211_ATTR_IE]) {
6205 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
6206 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
6207 }
6208
6209 auth_type = nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]);
Jouni Malinene39e5b52012-09-30 19:29:39 +03006210 if (!nl80211_valid_auth_type(rdev, auth_type, NL80211_CMD_AUTHENTICATE))
Johannes Berg4c476992010-10-04 21:36:35 +02006211 return -EINVAL;
Johannes Berg19957bb2009-07-02 17:20:43 +02006212
Jouni Malinene39e5b52012-09-30 19:29:39 +03006213 if (auth_type == NL80211_AUTHTYPE_SAE &&
6214 !info->attrs[NL80211_ATTR_SAE_DATA])
6215 return -EINVAL;
6216
6217 if (info->attrs[NL80211_ATTR_SAE_DATA]) {
6218 if (auth_type != NL80211_AUTHTYPE_SAE)
6219 return -EINVAL;
6220 sae_data = nla_data(info->attrs[NL80211_ATTR_SAE_DATA]);
6221 sae_data_len = nla_len(info->attrs[NL80211_ATTR_SAE_DATA]);
6222 /* need to include at least Auth Transaction and Status Code */
6223 if (sae_data_len < 4)
6224 return -EINVAL;
6225 }
6226
Jouni Malinend5cdfac2010-04-04 09:37:19 +03006227 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE];
6228
Johannes Berg95de8172012-01-20 13:55:25 +01006229 /*
6230 * Since we no longer track auth state, ignore
6231 * requests to only change local state.
6232 */
6233 if (local_state_change)
6234 return 0;
6235
Johannes Berg91bf9b22013-05-15 17:44:01 +02006236 wdev_lock(dev->ieee80211_ptr);
6237 err = cfg80211_mlme_auth(rdev, dev, chan, auth_type, bssid,
6238 ssid, ssid_len, ie, ie_len,
6239 key.p.key, key.p.key_len, key.idx,
6240 sae_data, sae_data_len);
6241 wdev_unlock(dev->ieee80211_ptr);
6242 return err;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006243}
6244
Johannes Bergc0692b82010-08-27 14:26:53 +03006245static int nl80211_crypto_settings(struct cfg80211_registered_device *rdev,
6246 struct genl_info *info,
Johannes Berg3dc27d22009-07-02 21:36:37 +02006247 struct cfg80211_crypto_settings *settings,
6248 int cipher_limit)
Samuel Ortizb23aa672009-07-01 21:26:54 +02006249{
Johannes Bergc0b2bbd2009-07-25 16:54:36 +02006250 memset(settings, 0, sizeof(*settings));
6251
Samuel Ortizb23aa672009-07-01 21:26:54 +02006252 settings->control_port = info->attrs[NL80211_ATTR_CONTROL_PORT];
6253
Johannes Bergc0692b82010-08-27 14:26:53 +03006254 if (info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]) {
6255 u16 proto;
6256 proto = nla_get_u16(
6257 info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]);
6258 settings->control_port_ethertype = cpu_to_be16(proto);
6259 if (!(rdev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) &&
6260 proto != ETH_P_PAE)
6261 return -EINVAL;
6262 if (info->attrs[NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT])
6263 settings->control_port_no_encrypt = true;
6264 } else
6265 settings->control_port_ethertype = cpu_to_be16(ETH_P_PAE);
6266
Samuel Ortizb23aa672009-07-01 21:26:54 +02006267 if (info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]) {
6268 void *data;
6269 int len, i;
6270
6271 data = nla_data(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]);
6272 len = nla_len(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]);
6273 settings->n_ciphers_pairwise = len / sizeof(u32);
6274
6275 if (len % sizeof(u32))
6276 return -EINVAL;
6277
Johannes Berg3dc27d22009-07-02 21:36:37 +02006278 if (settings->n_ciphers_pairwise > cipher_limit)
Samuel Ortizb23aa672009-07-01 21:26:54 +02006279 return -EINVAL;
6280
6281 memcpy(settings->ciphers_pairwise, data, len);
6282
6283 for (i = 0; i < settings->n_ciphers_pairwise; i++)
Jouni Malinen38ba3c52011-09-21 18:14:56 +03006284 if (!cfg80211_supported_cipher_suite(
6285 &rdev->wiphy,
Samuel Ortizb23aa672009-07-01 21:26:54 +02006286 settings->ciphers_pairwise[i]))
6287 return -EINVAL;
6288 }
6289
6290 if (info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]) {
6291 settings->cipher_group =
6292 nla_get_u32(info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]);
Jouni Malinen38ba3c52011-09-21 18:14:56 +03006293 if (!cfg80211_supported_cipher_suite(&rdev->wiphy,
6294 settings->cipher_group))
Samuel Ortizb23aa672009-07-01 21:26:54 +02006295 return -EINVAL;
6296 }
6297
6298 if (info->attrs[NL80211_ATTR_WPA_VERSIONS]) {
6299 settings->wpa_versions =
6300 nla_get_u32(info->attrs[NL80211_ATTR_WPA_VERSIONS]);
6301 if (!nl80211_valid_wpa_versions(settings->wpa_versions))
6302 return -EINVAL;
6303 }
6304
6305 if (info->attrs[NL80211_ATTR_AKM_SUITES]) {
6306 void *data;
Jouni Malinen6d302402011-09-21 18:11:33 +03006307 int len;
Samuel Ortizb23aa672009-07-01 21:26:54 +02006308
6309 data = nla_data(info->attrs[NL80211_ATTR_AKM_SUITES]);
6310 len = nla_len(info->attrs[NL80211_ATTR_AKM_SUITES]);
6311 settings->n_akm_suites = len / sizeof(u32);
6312
6313 if (len % sizeof(u32))
6314 return -EINVAL;
6315
Jouni Malinen1b9ca022011-09-21 16:13:07 +03006316 if (settings->n_akm_suites > NL80211_MAX_NR_AKM_SUITES)
6317 return -EINVAL;
6318
Samuel Ortizb23aa672009-07-01 21:26:54 +02006319 memcpy(settings->akm_suites, data, len);
Samuel Ortizb23aa672009-07-01 21:26:54 +02006320 }
6321
6322 return 0;
6323}
6324
Jouni Malinen636a5d32009-03-19 13:39:22 +02006325static int nl80211_associate(struct sk_buff *skb, struct genl_info *info)
6326{
Johannes Berg4c476992010-10-04 21:36:35 +02006327 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6328 struct net_device *dev = info->user_ptr[1];
Johannes Bergf444de02010-05-05 15:25:02 +02006329 struct ieee80211_channel *chan;
Johannes Bergf62fab72013-02-21 20:09:09 +01006330 struct cfg80211_assoc_request req = {};
6331 const u8 *bssid, *ssid;
6332 int err, ssid_len = 0;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006333
Johannes Bergf4a11bb2009-03-27 12:40:28 +01006334 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
6335 return -EINVAL;
6336
6337 if (!info->attrs[NL80211_ATTR_MAC] ||
Johannes Berg19957bb2009-07-02 17:20:43 +02006338 !info->attrs[NL80211_ATTR_SSID] ||
6339 !info->attrs[NL80211_ATTR_WIPHY_FREQ])
Johannes Bergf4a11bb2009-03-27 12:40:28 +01006340 return -EINVAL;
6341
Johannes Berg4c476992010-10-04 21:36:35 +02006342 if (!rdev->ops->assoc)
6343 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006344
Johannes Berg074ac8d2010-09-16 14:58:22 +02006345 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02006346 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
6347 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02006348
Johannes Berg19957bb2009-07-02 17:20:43 +02006349 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02006350
Johannes Berg19957bb2009-07-02 17:20:43 +02006351 chan = ieee80211_get_channel(&rdev->wiphy,
6352 nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]));
Johannes Berg4c476992010-10-04 21:36:35 +02006353 if (!chan || (chan->flags & IEEE80211_CHAN_DISABLED))
6354 return -EINVAL;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006355
Johannes Berg19957bb2009-07-02 17:20:43 +02006356 ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
6357 ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02006358
6359 if (info->attrs[NL80211_ATTR_IE]) {
Johannes Bergf62fab72013-02-21 20:09:09 +01006360 req.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
6361 req.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02006362 }
6363
Jouni Malinendc6382c2009-05-06 22:09:37 +03006364 if (info->attrs[NL80211_ATTR_USE_MFP]) {
Johannes Berg4f5dadc2009-07-07 03:56:10 +02006365 enum nl80211_mfp mfp =
Jouni Malinendc6382c2009-05-06 22:09:37 +03006366 nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]);
Johannes Berg4f5dadc2009-07-07 03:56:10 +02006367 if (mfp == NL80211_MFP_REQUIRED)
Johannes Bergf62fab72013-02-21 20:09:09 +01006368 req.use_mfp = true;
Johannes Berg4c476992010-10-04 21:36:35 +02006369 else if (mfp != NL80211_MFP_NO)
6370 return -EINVAL;
Jouni Malinendc6382c2009-05-06 22:09:37 +03006371 }
6372
Johannes Berg3e5d7642009-07-07 14:37:26 +02006373 if (info->attrs[NL80211_ATTR_PREV_BSSID])
Johannes Bergf62fab72013-02-21 20:09:09 +01006374 req.prev_bssid = nla_data(info->attrs[NL80211_ATTR_PREV_BSSID]);
Johannes Berg3e5d7642009-07-07 14:37:26 +02006375
Ben Greear7e7c8922011-11-18 11:31:59 -08006376 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT]))
Johannes Bergf62fab72013-02-21 20:09:09 +01006377 req.flags |= ASSOC_REQ_DISABLE_HT;
Ben Greear7e7c8922011-11-18 11:31:59 -08006378
6379 if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
Johannes Bergf62fab72013-02-21 20:09:09 +01006380 memcpy(&req.ht_capa_mask,
6381 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]),
6382 sizeof(req.ht_capa_mask));
Ben Greear7e7c8922011-11-18 11:31:59 -08006383
6384 if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) {
Johannes Bergf62fab72013-02-21 20:09:09 +01006385 if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
Ben Greear7e7c8922011-11-18 11:31:59 -08006386 return -EINVAL;
Johannes Bergf62fab72013-02-21 20:09:09 +01006387 memcpy(&req.ht_capa,
6388 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]),
6389 sizeof(req.ht_capa));
Ben Greear7e7c8922011-11-18 11:31:59 -08006390 }
6391
Johannes Bergee2aca32013-02-21 17:36:01 +01006392 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_VHT]))
Johannes Bergf62fab72013-02-21 20:09:09 +01006393 req.flags |= ASSOC_REQ_DISABLE_VHT;
Johannes Bergee2aca32013-02-21 17:36:01 +01006394
6395 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK])
Johannes Bergf62fab72013-02-21 20:09:09 +01006396 memcpy(&req.vht_capa_mask,
6397 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]),
6398 sizeof(req.vht_capa_mask));
Johannes Bergee2aca32013-02-21 17:36:01 +01006399
6400 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) {
Johannes Bergf62fab72013-02-21 20:09:09 +01006401 if (!info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK])
Johannes Bergee2aca32013-02-21 17:36:01 +01006402 return -EINVAL;
Johannes Bergf62fab72013-02-21 20:09:09 +01006403 memcpy(&req.vht_capa,
6404 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]),
6405 sizeof(req.vht_capa));
Johannes Bergee2aca32013-02-21 17:36:01 +01006406 }
6407
Johannes Bergf62fab72013-02-21 20:09:09 +01006408 err = nl80211_crypto_settings(rdev, info, &req.crypto, 1);
Johannes Berg91bf9b22013-05-15 17:44:01 +02006409 if (!err) {
6410 wdev_lock(dev->ieee80211_ptr);
Johannes Bergf62fab72013-02-21 20:09:09 +01006411 err = cfg80211_mlme_assoc(rdev, dev, chan, bssid,
6412 ssid, ssid_len, &req);
Johannes Berg91bf9b22013-05-15 17:44:01 +02006413 wdev_unlock(dev->ieee80211_ptr);
6414 }
Jouni Malinen636a5d32009-03-19 13:39:22 +02006415
Jouni Malinen636a5d32009-03-19 13:39:22 +02006416 return err;
6417}
6418
6419static int nl80211_deauthenticate(struct sk_buff *skb, struct genl_info *info)
6420{
Johannes Berg4c476992010-10-04 21:36:35 +02006421 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6422 struct net_device *dev = info->user_ptr[1];
Johannes Berg19957bb2009-07-02 17:20:43 +02006423 const u8 *ie = NULL, *bssid;
Johannes Berg91bf9b22013-05-15 17:44:01 +02006424 int ie_len = 0, err;
Johannes Berg19957bb2009-07-02 17:20:43 +02006425 u16 reason_code;
Jouni Malinend5cdfac2010-04-04 09:37:19 +03006426 bool local_state_change;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006427
Johannes Bergf4a11bb2009-03-27 12:40:28 +01006428 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
6429 return -EINVAL;
6430
6431 if (!info->attrs[NL80211_ATTR_MAC])
6432 return -EINVAL;
6433
6434 if (!info->attrs[NL80211_ATTR_REASON_CODE])
6435 return -EINVAL;
6436
Johannes Berg4c476992010-10-04 21:36:35 +02006437 if (!rdev->ops->deauth)
6438 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006439
Johannes Berg074ac8d2010-09-16 14:58:22 +02006440 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02006441 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
6442 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02006443
Johannes Berg19957bb2009-07-02 17:20:43 +02006444 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02006445
Johannes Berg19957bb2009-07-02 17:20:43 +02006446 reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
6447 if (reason_code == 0) {
Johannes Bergf4a11bb2009-03-27 12:40:28 +01006448 /* Reason Code 0 is reserved */
Johannes Berg4c476992010-10-04 21:36:35 +02006449 return -EINVAL;
Jouni Malinen255e7372009-03-20 21:21:17 +02006450 }
Jouni Malinen636a5d32009-03-19 13:39:22 +02006451
6452 if (info->attrs[NL80211_ATTR_IE]) {
Johannes Berg19957bb2009-07-02 17:20:43 +02006453 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
6454 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02006455 }
6456
Jouni Malinend5cdfac2010-04-04 09:37:19 +03006457 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE];
6458
Johannes Berg91bf9b22013-05-15 17:44:01 +02006459 wdev_lock(dev->ieee80211_ptr);
6460 err = cfg80211_mlme_deauth(rdev, dev, bssid, ie, ie_len, reason_code,
6461 local_state_change);
6462 wdev_unlock(dev->ieee80211_ptr);
6463 return err;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006464}
6465
6466static int nl80211_disassociate(struct sk_buff *skb, struct genl_info *info)
6467{
Johannes Berg4c476992010-10-04 21:36:35 +02006468 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6469 struct net_device *dev = info->user_ptr[1];
Johannes Berg19957bb2009-07-02 17:20:43 +02006470 const u8 *ie = NULL, *bssid;
Johannes Berg91bf9b22013-05-15 17:44:01 +02006471 int ie_len = 0, err;
Johannes Berg19957bb2009-07-02 17:20:43 +02006472 u16 reason_code;
Jouni Malinend5cdfac2010-04-04 09:37:19 +03006473 bool local_state_change;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006474
Johannes Bergf4a11bb2009-03-27 12:40:28 +01006475 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
6476 return -EINVAL;
6477
6478 if (!info->attrs[NL80211_ATTR_MAC])
6479 return -EINVAL;
6480
6481 if (!info->attrs[NL80211_ATTR_REASON_CODE])
6482 return -EINVAL;
6483
Johannes Berg4c476992010-10-04 21:36:35 +02006484 if (!rdev->ops->disassoc)
6485 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006486
Johannes Berg074ac8d2010-09-16 14:58:22 +02006487 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02006488 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
6489 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02006490
Johannes Berg19957bb2009-07-02 17:20:43 +02006491 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02006492
Johannes Berg19957bb2009-07-02 17:20:43 +02006493 reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
6494 if (reason_code == 0) {
Johannes Bergf4a11bb2009-03-27 12:40:28 +01006495 /* Reason Code 0 is reserved */
Johannes Berg4c476992010-10-04 21:36:35 +02006496 return -EINVAL;
Jouni Malinen255e7372009-03-20 21:21:17 +02006497 }
Jouni Malinen636a5d32009-03-19 13:39:22 +02006498
6499 if (info->attrs[NL80211_ATTR_IE]) {
Johannes Berg19957bb2009-07-02 17:20:43 +02006500 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
6501 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02006502 }
6503
Jouni Malinend5cdfac2010-04-04 09:37:19 +03006504 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE];
6505
Johannes Berg91bf9b22013-05-15 17:44:01 +02006506 wdev_lock(dev->ieee80211_ptr);
6507 err = cfg80211_mlme_disassoc(rdev, dev, bssid, ie, ie_len, reason_code,
6508 local_state_change);
6509 wdev_unlock(dev->ieee80211_ptr);
6510 return err;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006511}
6512
Felix Fietkaudd5b4cc2010-11-22 20:58:24 +01006513static bool
6514nl80211_parse_mcast_rate(struct cfg80211_registered_device *rdev,
6515 int mcast_rate[IEEE80211_NUM_BANDS],
6516 int rateval)
6517{
6518 struct wiphy *wiphy = &rdev->wiphy;
6519 bool found = false;
6520 int band, i;
6521
6522 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
6523 struct ieee80211_supported_band *sband;
6524
6525 sband = wiphy->bands[band];
6526 if (!sband)
6527 continue;
6528
6529 for (i = 0; i < sband->n_bitrates; i++) {
6530 if (sband->bitrates[i].bitrate == rateval) {
6531 mcast_rate[band] = i + 1;
6532 found = true;
6533 break;
6534 }
6535 }
6536 }
6537
6538 return found;
6539}
6540
Johannes Berg04a773a2009-04-19 21:24:32 +02006541static int nl80211_join_ibss(struct sk_buff *skb, struct genl_info *info)
6542{
Johannes Berg4c476992010-10-04 21:36:35 +02006543 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6544 struct net_device *dev = info->user_ptr[1];
Johannes Berg04a773a2009-04-19 21:24:32 +02006545 struct cfg80211_ibss_params ibss;
6546 struct wiphy *wiphy;
Johannes Bergfffd0932009-07-08 14:22:54 +02006547 struct cfg80211_cached_keys *connkeys = NULL;
Johannes Berg04a773a2009-04-19 21:24:32 +02006548 int err;
6549
Johannes Berg8e30bc52009-04-22 17:45:38 +02006550 memset(&ibss, 0, sizeof(ibss));
6551
Johannes Berg04a773a2009-04-19 21:24:32 +02006552 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
6553 return -EINVAL;
6554
Johannes Berg683b6d32012-11-08 21:25:48 +01006555 if (!info->attrs[NL80211_ATTR_SSID] ||
Johannes Berg04a773a2009-04-19 21:24:32 +02006556 !nla_len(info->attrs[NL80211_ATTR_SSID]))
6557 return -EINVAL;
6558
Johannes Berg8e30bc52009-04-22 17:45:38 +02006559 ibss.beacon_interval = 100;
6560
6561 if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) {
6562 ibss.beacon_interval =
6563 nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]);
6564 if (ibss.beacon_interval < 1 || ibss.beacon_interval > 10000)
6565 return -EINVAL;
6566 }
6567
Johannes Berg4c476992010-10-04 21:36:35 +02006568 if (!rdev->ops->join_ibss)
6569 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02006570
Johannes Berg4c476992010-10-04 21:36:35 +02006571 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC)
6572 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02006573
Johannes Berg79c97e92009-07-07 03:56:12 +02006574 wiphy = &rdev->wiphy;
Johannes Berg04a773a2009-04-19 21:24:32 +02006575
Johannes Berg39193492011-09-16 13:45:25 +02006576 if (info->attrs[NL80211_ATTR_MAC]) {
Johannes Berg04a773a2009-04-19 21:24:32 +02006577 ibss.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Johannes Berg39193492011-09-16 13:45:25 +02006578
6579 if (!is_valid_ether_addr(ibss.bssid))
6580 return -EINVAL;
6581 }
Johannes Berg04a773a2009-04-19 21:24:32 +02006582 ibss.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
6583 ibss.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
6584
6585 if (info->attrs[NL80211_ATTR_IE]) {
6586 ibss.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
6587 ibss.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
6588 }
6589
Johannes Berg683b6d32012-11-08 21:25:48 +01006590 err = nl80211_parse_chandef(rdev, info, &ibss.chandef);
6591 if (err)
6592 return err;
Alexander Simon54858ee5b2011-11-30 16:56:32 +01006593
Johannes Berg683b6d32012-11-08 21:25:48 +01006594 if (!cfg80211_reg_can_beacon(&rdev->wiphy, &ibss.chandef))
Alexander Simon54858ee5b2011-11-30 16:56:32 +01006595 return -EINVAL;
6596
Simon Wunderlich2f301ab2013-05-16 13:00:28 +02006597 switch (ibss.chandef.width) {
Simon Wunderlichbf372642013-07-08 16:55:58 +02006598 case NL80211_CHAN_WIDTH_5:
6599 case NL80211_CHAN_WIDTH_10:
Simon Wunderlich2f301ab2013-05-16 13:00:28 +02006600 case NL80211_CHAN_WIDTH_20_NOHT:
6601 break;
6602 case NL80211_CHAN_WIDTH_20:
6603 case NL80211_CHAN_WIDTH_40:
6604 if (rdev->wiphy.features & NL80211_FEATURE_HT_IBSS)
6605 break;
6606 default:
Johannes Bergdb9c64c2012-11-09 14:56:41 +01006607 return -EINVAL;
Simon Wunderlich2f301ab2013-05-16 13:00:28 +02006608 }
Johannes Bergdb9c64c2012-11-09 14:56:41 +01006609
Johannes Berg04a773a2009-04-19 21:24:32 +02006610 ibss.channel_fixed = !!info->attrs[NL80211_ATTR_FREQ_FIXED];
Johannes Bergfffd0932009-07-08 14:22:54 +02006611 ibss.privacy = !!info->attrs[NL80211_ATTR_PRIVACY];
Johannes Berg04a773a2009-04-19 21:24:32 +02006612
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03006613 if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) {
6614 u8 *rates =
6615 nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
6616 int n_rates =
6617 nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
6618 struct ieee80211_supported_band *sband =
Johannes Berg683b6d32012-11-08 21:25:48 +01006619 wiphy->bands[ibss.chandef.chan->band];
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03006620
Johannes Berg34850ab2011-07-18 18:08:35 +02006621 err = ieee80211_get_ratemask(sband, rates, n_rates,
6622 &ibss.basic_rates);
6623 if (err)
6624 return err;
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03006625 }
Felix Fietkaudd5b4cc2010-11-22 20:58:24 +01006626
Simon Wunderlich803768f2013-06-28 10:39:58 +02006627 if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
6628 memcpy(&ibss.ht_capa_mask,
6629 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]),
6630 sizeof(ibss.ht_capa_mask));
6631
6632 if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) {
6633 if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
6634 return -EINVAL;
6635 memcpy(&ibss.ht_capa,
6636 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]),
6637 sizeof(ibss.ht_capa));
6638 }
6639
Felix Fietkaudd5b4cc2010-11-22 20:58:24 +01006640 if (info->attrs[NL80211_ATTR_MCAST_RATE] &&
6641 !nl80211_parse_mcast_rate(rdev, ibss.mcast_rate,
6642 nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE])))
6643 return -EINVAL;
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03006644
Johannes Berg4c476992010-10-04 21:36:35 +02006645 if (ibss.privacy && info->attrs[NL80211_ATTR_KEYS]) {
Sujith Manoharande7044e2012-10-18 10:19:28 +05306646 bool no_ht = false;
6647
Johannes Berg4c476992010-10-04 21:36:35 +02006648 connkeys = nl80211_parse_connkeys(rdev,
Sujith Manoharande7044e2012-10-18 10:19:28 +05306649 info->attrs[NL80211_ATTR_KEYS],
6650 &no_ht);
Johannes Berg4c476992010-10-04 21:36:35 +02006651 if (IS_ERR(connkeys))
6652 return PTR_ERR(connkeys);
Sujith Manoharande7044e2012-10-18 10:19:28 +05306653
Johannes Berg3d9d1d62012-11-08 23:14:50 +01006654 if ((ibss.chandef.width != NL80211_CHAN_WIDTH_20_NOHT) &&
6655 no_ht) {
Sujith Manoharande7044e2012-10-18 10:19:28 +05306656 kfree(connkeys);
6657 return -EINVAL;
6658 }
Johannes Berg4c476992010-10-04 21:36:35 +02006659 }
Johannes Berg04a773a2009-04-19 21:24:32 +02006660
Antonio Quartulli267335d2012-01-31 20:25:47 +01006661 ibss.control_port =
6662 nla_get_flag(info->attrs[NL80211_ATTR_CONTROL_PORT]);
6663
Simon Wunderlich5336fa82013-10-07 18:41:05 +02006664 ibss.userspace_handles_dfs =
6665 nla_get_flag(info->attrs[NL80211_ATTR_HANDLE_DFS]);
6666
Johannes Berg4c476992010-10-04 21:36:35 +02006667 err = cfg80211_join_ibss(rdev, dev, &ibss, connkeys);
Johannes Bergfffd0932009-07-08 14:22:54 +02006668 if (err)
6669 kfree(connkeys);
Johannes Berg04a773a2009-04-19 21:24:32 +02006670 return err;
6671}
6672
6673static int nl80211_leave_ibss(struct sk_buff *skb, struct genl_info *info)
6674{
Johannes Berg4c476992010-10-04 21:36:35 +02006675 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6676 struct net_device *dev = info->user_ptr[1];
Johannes Berg04a773a2009-04-19 21:24:32 +02006677
Johannes Berg4c476992010-10-04 21:36:35 +02006678 if (!rdev->ops->leave_ibss)
6679 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02006680
Johannes Berg4c476992010-10-04 21:36:35 +02006681 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC)
6682 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02006683
Johannes Berg4c476992010-10-04 21:36:35 +02006684 return cfg80211_leave_ibss(rdev, dev, false);
Johannes Berg04a773a2009-04-19 21:24:32 +02006685}
6686
Antonio Quartullif4e583c2012-11-02 13:27:48 +01006687static int nl80211_set_mcast_rate(struct sk_buff *skb, struct genl_info *info)
6688{
6689 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6690 struct net_device *dev = info->user_ptr[1];
6691 int mcast_rate[IEEE80211_NUM_BANDS];
6692 u32 nla_rate;
6693 int err;
6694
6695 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC &&
6696 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
6697 return -EOPNOTSUPP;
6698
6699 if (!rdev->ops->set_mcast_rate)
6700 return -EOPNOTSUPP;
6701
6702 memset(mcast_rate, 0, sizeof(mcast_rate));
6703
6704 if (!info->attrs[NL80211_ATTR_MCAST_RATE])
6705 return -EINVAL;
6706
6707 nla_rate = nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]);
6708 if (!nl80211_parse_mcast_rate(rdev, mcast_rate, nla_rate))
6709 return -EINVAL;
6710
6711 err = rdev->ops->set_mcast_rate(&rdev->wiphy, dev, mcast_rate);
6712
6713 return err;
6714}
6715
Johannes Bergad7e7182013-11-13 13:37:47 +01006716static struct sk_buff *
6717__cfg80211_alloc_vendor_skb(struct cfg80211_registered_device *rdev,
6718 int approxlen, u32 portid, u32 seq,
6719 enum nl80211_commands cmd,
Johannes Berg567ffc32013-12-18 14:43:31 +01006720 enum nl80211_attrs attr,
6721 const struct nl80211_vendor_cmd_info *info,
6722 gfp_t gfp)
Johannes Bergad7e7182013-11-13 13:37:47 +01006723{
6724 struct sk_buff *skb;
6725 void *hdr;
6726 struct nlattr *data;
6727
6728 skb = nlmsg_new(approxlen + 100, gfp);
6729 if (!skb)
6730 return NULL;
6731
6732 hdr = nl80211hdr_put(skb, portid, seq, 0, cmd);
6733 if (!hdr) {
6734 kfree_skb(skb);
6735 return NULL;
6736 }
6737
6738 if (nla_put_u32(skb, NL80211_ATTR_WIPHY, rdev->wiphy_idx))
6739 goto nla_put_failure;
Johannes Berg567ffc32013-12-18 14:43:31 +01006740
6741 if (info) {
6742 if (nla_put_u32(skb, NL80211_ATTR_VENDOR_ID,
6743 info->vendor_id))
6744 goto nla_put_failure;
6745 if (nla_put_u32(skb, NL80211_ATTR_VENDOR_SUBCMD,
6746 info->subcmd))
6747 goto nla_put_failure;
6748 }
6749
Johannes Bergad7e7182013-11-13 13:37:47 +01006750 data = nla_nest_start(skb, attr);
6751
6752 ((void **)skb->cb)[0] = rdev;
6753 ((void **)skb->cb)[1] = hdr;
6754 ((void **)skb->cb)[2] = data;
6755
6756 return skb;
6757
6758 nla_put_failure:
6759 kfree_skb(skb);
6760 return NULL;
6761}
Antonio Quartullif4e583c2012-11-02 13:27:48 +01006762
Johannes Berge03ad6e2014-01-01 17:22:30 +01006763struct sk_buff *__cfg80211_alloc_event_skb(struct wiphy *wiphy,
6764 enum nl80211_commands cmd,
6765 enum nl80211_attrs attr,
6766 int vendor_event_idx,
6767 int approxlen, gfp_t gfp)
6768{
6769 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
6770 const struct nl80211_vendor_cmd_info *info;
6771
6772 switch (cmd) {
6773 case NL80211_CMD_TESTMODE:
6774 if (WARN_ON(vendor_event_idx != -1))
6775 return NULL;
6776 info = NULL;
6777 break;
6778 case NL80211_CMD_VENDOR:
6779 if (WARN_ON(vendor_event_idx < 0 ||
6780 vendor_event_idx >= wiphy->n_vendor_events))
6781 return NULL;
6782 info = &wiphy->vendor_events[vendor_event_idx];
6783 break;
6784 default:
6785 WARN_ON(1);
6786 return NULL;
6787 }
6788
6789 return __cfg80211_alloc_vendor_skb(rdev, approxlen, 0, 0,
6790 cmd, attr, info, gfp);
6791}
6792EXPORT_SYMBOL(__cfg80211_alloc_event_skb);
6793
6794void __cfg80211_send_event_skb(struct sk_buff *skb, gfp_t gfp)
6795{
6796 struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0];
6797 void *hdr = ((void **)skb->cb)[1];
6798 struct nlattr *data = ((void **)skb->cb)[2];
6799 enum nl80211_multicast_groups mcgrp = NL80211_MCGRP_TESTMODE;
6800
6801 nla_nest_end(skb, data);
6802 genlmsg_end(skb, hdr);
6803
6804 if (data->nla_type == NL80211_ATTR_VENDOR_DATA)
6805 mcgrp = NL80211_MCGRP_VENDOR;
6806
6807 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), skb, 0,
6808 mcgrp, gfp);
6809}
6810EXPORT_SYMBOL(__cfg80211_send_event_skb);
6811
Johannes Bergaff89a92009-07-01 21:26:51 +02006812#ifdef CONFIG_NL80211_TESTMODE
Johannes Bergaff89a92009-07-01 21:26:51 +02006813static int nl80211_testmode_do(struct sk_buff *skb, struct genl_info *info)
6814{
Johannes Berg4c476992010-10-04 21:36:35 +02006815 struct cfg80211_registered_device *rdev = info->user_ptr[0];
David Spinadelfc73f112013-07-31 18:04:15 +03006816 struct wireless_dev *wdev =
6817 __cfg80211_wdev_from_attrs(genl_info_net(info), info->attrs);
Johannes Bergaff89a92009-07-01 21:26:51 +02006818 int err;
6819
David Spinadelfc73f112013-07-31 18:04:15 +03006820 if (!rdev->ops->testmode_cmd)
6821 return -EOPNOTSUPP;
6822
6823 if (IS_ERR(wdev)) {
6824 err = PTR_ERR(wdev);
6825 if (err != -EINVAL)
6826 return err;
6827 wdev = NULL;
6828 } else if (wdev->wiphy != &rdev->wiphy) {
6829 return -EINVAL;
6830 }
6831
Johannes Bergaff89a92009-07-01 21:26:51 +02006832 if (!info->attrs[NL80211_ATTR_TESTDATA])
6833 return -EINVAL;
6834
Johannes Bergad7e7182013-11-13 13:37:47 +01006835 rdev->cur_cmd_info = info;
David Spinadelfc73f112013-07-31 18:04:15 +03006836 err = rdev_testmode_cmd(rdev, wdev,
Johannes Bergaff89a92009-07-01 21:26:51 +02006837 nla_data(info->attrs[NL80211_ATTR_TESTDATA]),
6838 nla_len(info->attrs[NL80211_ATTR_TESTDATA]));
Johannes Bergad7e7182013-11-13 13:37:47 +01006839 rdev->cur_cmd_info = NULL;
Johannes Bergaff89a92009-07-01 21:26:51 +02006840
Johannes Bergaff89a92009-07-01 21:26:51 +02006841 return err;
6842}
6843
Wey-Yi Guy71063f02011-05-20 09:05:54 -07006844static int nl80211_testmode_dump(struct sk_buff *skb,
6845 struct netlink_callback *cb)
6846{
Johannes Berg00918d32011-12-13 17:22:05 +01006847 struct cfg80211_registered_device *rdev;
Wey-Yi Guy71063f02011-05-20 09:05:54 -07006848 int err;
6849 long phy_idx;
6850 void *data = NULL;
6851 int data_len = 0;
6852
Johannes Berg5fe231e2013-05-08 21:45:15 +02006853 rtnl_lock();
6854
Wey-Yi Guy71063f02011-05-20 09:05:54 -07006855 if (cb->args[0]) {
6856 /*
6857 * 0 is a valid index, but not valid for args[0],
6858 * so we need to offset by 1.
6859 */
6860 phy_idx = cb->args[0] - 1;
6861 } else {
6862 err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize,
6863 nl80211_fam.attrbuf, nl80211_fam.maxattr,
6864 nl80211_policy);
6865 if (err)
Johannes Berg5fe231e2013-05-08 21:45:15 +02006866 goto out_err;
Johannes Berg00918d32011-12-13 17:22:05 +01006867
Johannes Berg2bd7e352012-06-15 14:23:16 +02006868 rdev = __cfg80211_rdev_from_attrs(sock_net(skb->sk),
6869 nl80211_fam.attrbuf);
6870 if (IS_ERR(rdev)) {
Johannes Berg5fe231e2013-05-08 21:45:15 +02006871 err = PTR_ERR(rdev);
6872 goto out_err;
Johannes Berg00918d32011-12-13 17:22:05 +01006873 }
Johannes Berg2bd7e352012-06-15 14:23:16 +02006874 phy_idx = rdev->wiphy_idx;
6875 rdev = NULL;
Johannes Berg2bd7e352012-06-15 14:23:16 +02006876
Wey-Yi Guy71063f02011-05-20 09:05:54 -07006877 if (nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA])
6878 cb->args[1] =
6879 (long)nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA];
6880 }
6881
6882 if (cb->args[1]) {
6883 data = nla_data((void *)cb->args[1]);
6884 data_len = nla_len((void *)cb->args[1]);
6885 }
6886
Johannes Berg00918d32011-12-13 17:22:05 +01006887 rdev = cfg80211_rdev_by_wiphy_idx(phy_idx);
6888 if (!rdev) {
Johannes Berg5fe231e2013-05-08 21:45:15 +02006889 err = -ENOENT;
6890 goto out_err;
Wey-Yi Guy71063f02011-05-20 09:05:54 -07006891 }
Wey-Yi Guy71063f02011-05-20 09:05:54 -07006892
Johannes Berg00918d32011-12-13 17:22:05 +01006893 if (!rdev->ops->testmode_dump) {
Wey-Yi Guy71063f02011-05-20 09:05:54 -07006894 err = -EOPNOTSUPP;
6895 goto out_err;
6896 }
6897
6898 while (1) {
Eric W. Biederman15e47302012-09-07 20:12:54 +00006899 void *hdr = nl80211hdr_put(skb, NETLINK_CB(cb->skb).portid,
Wey-Yi Guy71063f02011-05-20 09:05:54 -07006900 cb->nlh->nlmsg_seq, NLM_F_MULTI,
6901 NL80211_CMD_TESTMODE);
6902 struct nlattr *tmdata;
6903
Dan Carpentercb35fba2013-08-14 14:50:01 +03006904 if (!hdr)
6905 break;
6906
David S. Miller9360ffd2012-03-29 04:41:26 -04006907 if (nla_put_u32(skb, NL80211_ATTR_WIPHY, phy_idx)) {
Wey-Yi Guy71063f02011-05-20 09:05:54 -07006908 genlmsg_cancel(skb, hdr);
6909 break;
6910 }
6911
6912 tmdata = nla_nest_start(skb, NL80211_ATTR_TESTDATA);
6913 if (!tmdata) {
6914 genlmsg_cancel(skb, hdr);
6915 break;
6916 }
Hila Gonene35e4d22012-06-27 17:19:42 +03006917 err = rdev_testmode_dump(rdev, skb, cb, data, data_len);
Wey-Yi Guy71063f02011-05-20 09:05:54 -07006918 nla_nest_end(skb, tmdata);
6919
6920 if (err == -ENOBUFS || err == -ENOENT) {
6921 genlmsg_cancel(skb, hdr);
6922 break;
6923 } else if (err) {
6924 genlmsg_cancel(skb, hdr);
6925 goto out_err;
6926 }
6927
6928 genlmsg_end(skb, hdr);
6929 }
6930
6931 err = skb->len;
6932 /* see above */
6933 cb->args[0] = phy_idx + 1;
6934 out_err:
Johannes Berg5fe231e2013-05-08 21:45:15 +02006935 rtnl_unlock();
Wey-Yi Guy71063f02011-05-20 09:05:54 -07006936 return err;
6937}
Johannes Bergaff89a92009-07-01 21:26:51 +02006938#endif
6939
Samuel Ortizb23aa672009-07-01 21:26:54 +02006940static int nl80211_connect(struct sk_buff *skb, struct genl_info *info)
6941{
Johannes Berg4c476992010-10-04 21:36:35 +02006942 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6943 struct net_device *dev = info->user_ptr[1];
Samuel Ortizb23aa672009-07-01 21:26:54 +02006944 struct cfg80211_connect_params connect;
6945 struct wiphy *wiphy;
Johannes Bergfffd0932009-07-08 14:22:54 +02006946 struct cfg80211_cached_keys *connkeys = NULL;
Samuel Ortizb23aa672009-07-01 21:26:54 +02006947 int err;
6948
6949 memset(&connect, 0, sizeof(connect));
6950
6951 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
6952 return -EINVAL;
6953
6954 if (!info->attrs[NL80211_ATTR_SSID] ||
6955 !nla_len(info->attrs[NL80211_ATTR_SSID]))
6956 return -EINVAL;
6957
6958 if (info->attrs[NL80211_ATTR_AUTH_TYPE]) {
6959 connect.auth_type =
6960 nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]);
Jouni Malinene39e5b52012-09-30 19:29:39 +03006961 if (!nl80211_valid_auth_type(rdev, connect.auth_type,
6962 NL80211_CMD_CONNECT))
Samuel Ortizb23aa672009-07-01 21:26:54 +02006963 return -EINVAL;
6964 } else
6965 connect.auth_type = NL80211_AUTHTYPE_AUTOMATIC;
6966
6967 connect.privacy = info->attrs[NL80211_ATTR_PRIVACY];
6968
Johannes Bergc0692b82010-08-27 14:26:53 +03006969 err = nl80211_crypto_settings(rdev, info, &connect.crypto,
Johannes Berg3dc27d22009-07-02 21:36:37 +02006970 NL80211_MAX_NR_CIPHER_SUITES);
Samuel Ortizb23aa672009-07-01 21:26:54 +02006971 if (err)
6972 return err;
Samuel Ortizb23aa672009-07-01 21:26:54 +02006973
Johannes Berg074ac8d2010-09-16 14:58:22 +02006974 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02006975 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
6976 return -EOPNOTSUPP;
Samuel Ortizb23aa672009-07-01 21:26:54 +02006977
Johannes Berg79c97e92009-07-07 03:56:12 +02006978 wiphy = &rdev->wiphy;
Samuel Ortizb23aa672009-07-01 21:26:54 +02006979
Bala Shanmugam4486ea92012-03-07 17:27:12 +05306980 connect.bg_scan_period = -1;
6981 if (info->attrs[NL80211_ATTR_BG_SCAN_PERIOD] &&
6982 (wiphy->flags & WIPHY_FLAG_SUPPORTS_FW_ROAM)) {
6983 connect.bg_scan_period =
6984 nla_get_u16(info->attrs[NL80211_ATTR_BG_SCAN_PERIOD]);
6985 }
6986
Samuel Ortizb23aa672009-07-01 21:26:54 +02006987 if (info->attrs[NL80211_ATTR_MAC])
6988 connect.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen1df4a512014-01-15 00:00:47 +02006989 else if (info->attrs[NL80211_ATTR_MAC_HINT])
6990 connect.bssid_hint =
6991 nla_data(info->attrs[NL80211_ATTR_MAC_HINT]);
Samuel Ortizb23aa672009-07-01 21:26:54 +02006992 connect.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
6993 connect.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
6994
6995 if (info->attrs[NL80211_ATTR_IE]) {
6996 connect.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
6997 connect.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
6998 }
6999
Jouni Malinencee00a92013-01-15 17:15:57 +02007000 if (info->attrs[NL80211_ATTR_USE_MFP]) {
7001 connect.mfp = nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]);
7002 if (connect.mfp != NL80211_MFP_REQUIRED &&
7003 connect.mfp != NL80211_MFP_NO)
7004 return -EINVAL;
7005 } else {
7006 connect.mfp = NL80211_MFP_NO;
7007 }
7008
Samuel Ortizb23aa672009-07-01 21:26:54 +02007009 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
7010 connect.channel =
7011 ieee80211_get_channel(wiphy,
7012 nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]));
7013 if (!connect.channel ||
Johannes Berg4c476992010-10-04 21:36:35 +02007014 connect.channel->flags & IEEE80211_CHAN_DISABLED)
7015 return -EINVAL;
Jouni Malinen1df4a512014-01-15 00:00:47 +02007016 } else if (info->attrs[NL80211_ATTR_WIPHY_FREQ_HINT]) {
7017 connect.channel_hint =
7018 ieee80211_get_channel(wiphy,
7019 nla_get_u32(
7020 info->attrs[NL80211_ATTR_WIPHY_FREQ_HINT]));
7021 if (!connect.channel_hint ||
7022 connect.channel_hint->flags & IEEE80211_CHAN_DISABLED)
7023 return -EINVAL;
Samuel Ortizb23aa672009-07-01 21:26:54 +02007024 }
7025
Johannes Bergfffd0932009-07-08 14:22:54 +02007026 if (connect.privacy && info->attrs[NL80211_ATTR_KEYS]) {
7027 connkeys = nl80211_parse_connkeys(rdev,
Sujith Manoharande7044e2012-10-18 10:19:28 +05307028 info->attrs[NL80211_ATTR_KEYS], NULL);
Johannes Berg4c476992010-10-04 21:36:35 +02007029 if (IS_ERR(connkeys))
7030 return PTR_ERR(connkeys);
Johannes Bergfffd0932009-07-08 14:22:54 +02007031 }
7032
Ben Greear7e7c8922011-11-18 11:31:59 -08007033 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT]))
7034 connect.flags |= ASSOC_REQ_DISABLE_HT;
7035
7036 if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
7037 memcpy(&connect.ht_capa_mask,
7038 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]),
7039 sizeof(connect.ht_capa_mask));
7040
7041 if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) {
Wei Yongjunb4e4f472012-09-02 21:41:04 +08007042 if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) {
7043 kfree(connkeys);
Ben Greear7e7c8922011-11-18 11:31:59 -08007044 return -EINVAL;
Wei Yongjunb4e4f472012-09-02 21:41:04 +08007045 }
Ben Greear7e7c8922011-11-18 11:31:59 -08007046 memcpy(&connect.ht_capa,
7047 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]),
7048 sizeof(connect.ht_capa));
7049 }
7050
Johannes Bergee2aca32013-02-21 17:36:01 +01007051 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_VHT]))
7052 connect.flags |= ASSOC_REQ_DISABLE_VHT;
7053
7054 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK])
7055 memcpy(&connect.vht_capa_mask,
7056 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]),
7057 sizeof(connect.vht_capa_mask));
7058
7059 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) {
7060 if (!info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) {
7061 kfree(connkeys);
7062 return -EINVAL;
7063 }
7064 memcpy(&connect.vht_capa,
7065 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]),
7066 sizeof(connect.vht_capa));
7067 }
7068
Johannes Berg83739b02013-05-15 17:44:01 +02007069 wdev_lock(dev->ieee80211_ptr);
7070 err = cfg80211_connect(rdev, dev, &connect, connkeys, NULL);
7071 wdev_unlock(dev->ieee80211_ptr);
Johannes Bergfffd0932009-07-08 14:22:54 +02007072 if (err)
7073 kfree(connkeys);
Samuel Ortizb23aa672009-07-01 21:26:54 +02007074 return err;
7075}
7076
7077static int nl80211_disconnect(struct sk_buff *skb, struct genl_info *info)
7078{
Johannes Berg4c476992010-10-04 21:36:35 +02007079 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7080 struct net_device *dev = info->user_ptr[1];
Samuel Ortizb23aa672009-07-01 21:26:54 +02007081 u16 reason;
Johannes Berg83739b02013-05-15 17:44:01 +02007082 int ret;
Samuel Ortizb23aa672009-07-01 21:26:54 +02007083
7084 if (!info->attrs[NL80211_ATTR_REASON_CODE])
7085 reason = WLAN_REASON_DEAUTH_LEAVING;
7086 else
7087 reason = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
7088
7089 if (reason == 0)
7090 return -EINVAL;
7091
Johannes Berg074ac8d2010-09-16 14:58:22 +02007092 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02007093 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
7094 return -EOPNOTSUPP;
Samuel Ortizb23aa672009-07-01 21:26:54 +02007095
Johannes Berg83739b02013-05-15 17:44:01 +02007096 wdev_lock(dev->ieee80211_ptr);
7097 ret = cfg80211_disconnect(rdev, dev, reason, true);
7098 wdev_unlock(dev->ieee80211_ptr);
7099 return ret;
Samuel Ortizb23aa672009-07-01 21:26:54 +02007100}
7101
Johannes Berg463d0182009-07-14 00:33:35 +02007102static int nl80211_wiphy_netns(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];
Johannes Berg463d0182009-07-14 00:33:35 +02007105 struct net *net;
7106 int err;
7107 u32 pid;
7108
7109 if (!info->attrs[NL80211_ATTR_PID])
7110 return -EINVAL;
7111
7112 pid = nla_get_u32(info->attrs[NL80211_ATTR_PID]);
7113
Johannes Berg463d0182009-07-14 00:33:35 +02007114 net = get_net_ns_by_pid(pid);
Johannes Berg4c476992010-10-04 21:36:35 +02007115 if (IS_ERR(net))
7116 return PTR_ERR(net);
Johannes Berg463d0182009-07-14 00:33:35 +02007117
7118 err = 0;
7119
7120 /* check if anything to do */
Johannes Berg4c476992010-10-04 21:36:35 +02007121 if (!net_eq(wiphy_net(&rdev->wiphy), net))
7122 err = cfg80211_switch_netns(rdev, net);
Johannes Berg463d0182009-07-14 00:33:35 +02007123
Johannes Berg463d0182009-07-14 00:33:35 +02007124 put_net(net);
Johannes Berg463d0182009-07-14 00:33:35 +02007125 return err;
7126}
7127
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007128static int nl80211_setdel_pmksa(struct sk_buff *skb, struct genl_info *info)
7129{
Johannes Berg4c476992010-10-04 21:36:35 +02007130 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007131 int (*rdev_ops)(struct wiphy *wiphy, struct net_device *dev,
7132 struct cfg80211_pmksa *pmksa) = NULL;
Johannes Berg4c476992010-10-04 21:36:35 +02007133 struct net_device *dev = info->user_ptr[1];
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007134 struct cfg80211_pmksa pmksa;
7135
7136 memset(&pmksa, 0, sizeof(struct cfg80211_pmksa));
7137
7138 if (!info->attrs[NL80211_ATTR_MAC])
7139 return -EINVAL;
7140
7141 if (!info->attrs[NL80211_ATTR_PMKID])
7142 return -EINVAL;
7143
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007144 pmksa.pmkid = nla_data(info->attrs[NL80211_ATTR_PMKID]);
7145 pmksa.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
7146
Johannes Berg074ac8d2010-09-16 14:58:22 +02007147 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02007148 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
7149 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007150
7151 switch (info->genlhdr->cmd) {
7152 case NL80211_CMD_SET_PMKSA:
7153 rdev_ops = rdev->ops->set_pmksa;
7154 break;
7155 case NL80211_CMD_DEL_PMKSA:
7156 rdev_ops = rdev->ops->del_pmksa;
7157 break;
7158 default:
7159 WARN_ON(1);
7160 break;
7161 }
7162
Johannes Berg4c476992010-10-04 21:36:35 +02007163 if (!rdev_ops)
7164 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007165
Johannes Berg4c476992010-10-04 21:36:35 +02007166 return rdev_ops(&rdev->wiphy, dev, &pmksa);
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007167}
7168
7169static int nl80211_flush_pmksa(struct sk_buff *skb, struct genl_info *info)
7170{
Johannes Berg4c476992010-10-04 21:36:35 +02007171 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7172 struct net_device *dev = info->user_ptr[1];
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007173
Johannes Berg074ac8d2010-09-16 14:58:22 +02007174 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02007175 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
7176 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007177
Johannes Berg4c476992010-10-04 21:36:35 +02007178 if (!rdev->ops->flush_pmksa)
7179 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007180
Hila Gonene35e4d22012-06-27 17:19:42 +03007181 return rdev_flush_pmksa(rdev, dev);
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007182}
7183
Arik Nemtsov109086c2011-09-28 14:12:50 +03007184static int nl80211_tdls_mgmt(struct sk_buff *skb, struct genl_info *info)
7185{
7186 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7187 struct net_device *dev = info->user_ptr[1];
7188 u8 action_code, dialog_token;
7189 u16 status_code;
7190 u8 *peer;
7191
7192 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) ||
7193 !rdev->ops->tdls_mgmt)
7194 return -EOPNOTSUPP;
7195
7196 if (!info->attrs[NL80211_ATTR_TDLS_ACTION] ||
7197 !info->attrs[NL80211_ATTR_STATUS_CODE] ||
7198 !info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN] ||
7199 !info->attrs[NL80211_ATTR_IE] ||
7200 !info->attrs[NL80211_ATTR_MAC])
7201 return -EINVAL;
7202
7203 peer = nla_data(info->attrs[NL80211_ATTR_MAC]);
7204 action_code = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_ACTION]);
7205 status_code = nla_get_u16(info->attrs[NL80211_ATTR_STATUS_CODE]);
7206 dialog_token = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN]);
7207
Hila Gonene35e4d22012-06-27 17:19:42 +03007208 return rdev_tdls_mgmt(rdev, dev, peer, action_code,
7209 dialog_token, status_code,
7210 nla_data(info->attrs[NL80211_ATTR_IE]),
7211 nla_len(info->attrs[NL80211_ATTR_IE]));
Arik Nemtsov109086c2011-09-28 14:12:50 +03007212}
7213
7214static int nl80211_tdls_oper(struct sk_buff *skb, struct genl_info *info)
7215{
7216 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7217 struct net_device *dev = info->user_ptr[1];
7218 enum nl80211_tdls_operation operation;
7219 u8 *peer;
7220
7221 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) ||
7222 !rdev->ops->tdls_oper)
7223 return -EOPNOTSUPP;
7224
7225 if (!info->attrs[NL80211_ATTR_TDLS_OPERATION] ||
7226 !info->attrs[NL80211_ATTR_MAC])
7227 return -EINVAL;
7228
7229 operation = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_OPERATION]);
7230 peer = nla_data(info->attrs[NL80211_ATTR_MAC]);
7231
Hila Gonene35e4d22012-06-27 17:19:42 +03007232 return rdev_tdls_oper(rdev, dev, peer, operation);
Arik Nemtsov109086c2011-09-28 14:12:50 +03007233}
7234
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007235static int nl80211_remain_on_channel(struct sk_buff *skb,
7236 struct genl_info *info)
7237{
Johannes Berg4c476992010-10-04 21:36:35 +02007238 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02007239 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg683b6d32012-11-08 21:25:48 +01007240 struct cfg80211_chan_def chandef;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007241 struct sk_buff *msg;
7242 void *hdr;
7243 u64 cookie;
Johannes Berg683b6d32012-11-08 21:25:48 +01007244 u32 duration;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007245 int err;
7246
7247 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] ||
7248 !info->attrs[NL80211_ATTR_DURATION])
7249 return -EINVAL;
7250
7251 duration = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]);
7252
Johannes Berg7c4ef712011-11-18 15:33:48 +01007253 if (!rdev->ops->remain_on_channel ||
7254 !(rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL))
Johannes Berg4c476992010-10-04 21:36:35 +02007255 return -EOPNOTSUPP;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007256
Johannes Bergebf348f2012-06-01 12:50:54 +02007257 /*
7258 * We should be on that channel for at least a minimum amount of
7259 * time (10ms) but no longer than the driver supports.
7260 */
7261 if (duration < NL80211_MIN_REMAIN_ON_CHANNEL_TIME ||
7262 duration > rdev->wiphy.max_remain_on_channel_duration)
7263 return -EINVAL;
7264
Johannes Berg683b6d32012-11-08 21:25:48 +01007265 err = nl80211_parse_chandef(rdev, info, &chandef);
7266 if (err)
7267 return err;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007268
7269 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02007270 if (!msg)
7271 return -ENOMEM;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007272
Eric W. Biederman15e47302012-09-07 20:12:54 +00007273 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007274 NL80211_CMD_REMAIN_ON_CHANNEL);
Dan Carpentercb35fba2013-08-14 14:50:01 +03007275 if (!hdr) {
7276 err = -ENOBUFS;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007277 goto free_msg;
7278 }
7279
Johannes Berg683b6d32012-11-08 21:25:48 +01007280 err = rdev_remain_on_channel(rdev, wdev, chandef.chan,
7281 duration, &cookie);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007282
7283 if (err)
7284 goto free_msg;
7285
David S. Miller9360ffd2012-03-29 04:41:26 -04007286 if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie))
7287 goto nla_put_failure;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007288
7289 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02007290
7291 return genlmsg_reply(msg, info);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007292
7293 nla_put_failure:
7294 err = -ENOBUFS;
7295 free_msg:
7296 nlmsg_free(msg);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007297 return err;
7298}
7299
7300static int nl80211_cancel_remain_on_channel(struct sk_buff *skb,
7301 struct genl_info *info)
7302{
Johannes Berg4c476992010-10-04 21:36:35 +02007303 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02007304 struct wireless_dev *wdev = info->user_ptr[1];
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007305 u64 cookie;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007306
7307 if (!info->attrs[NL80211_ATTR_COOKIE])
7308 return -EINVAL;
7309
Johannes Berg4c476992010-10-04 21:36:35 +02007310 if (!rdev->ops->cancel_remain_on_channel)
7311 return -EOPNOTSUPP;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007312
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007313 cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]);
7314
Hila Gonene35e4d22012-06-27 17:19:42 +03007315 return rdev_cancel_remain_on_channel(rdev, wdev, cookie);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007316}
7317
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007318static u32 rateset_to_mask(struct ieee80211_supported_band *sband,
7319 u8 *rates, u8 rates_len)
7320{
7321 u8 i;
7322 u32 mask = 0;
7323
7324 for (i = 0; i < rates_len; i++) {
7325 int rate = (rates[i] & 0x7f) * 5;
7326 int ridx;
7327 for (ridx = 0; ridx < sband->n_bitrates; ridx++) {
7328 struct ieee80211_rate *srate =
7329 &sband->bitrates[ridx];
7330 if (rate == srate->bitrate) {
7331 mask |= 1 << ridx;
7332 break;
7333 }
7334 }
7335 if (ridx == sband->n_bitrates)
7336 return 0; /* rate not found */
7337 }
7338
7339 return mask;
7340}
7341
Simon Wunderlich24db78c2012-01-28 17:25:32 +01007342static bool ht_rateset_to_mask(struct ieee80211_supported_band *sband,
7343 u8 *rates, u8 rates_len,
7344 u8 mcs[IEEE80211_HT_MCS_MASK_LEN])
7345{
7346 u8 i;
7347
7348 memset(mcs, 0, IEEE80211_HT_MCS_MASK_LEN);
7349
7350 for (i = 0; i < rates_len; i++) {
7351 int ridx, rbit;
7352
7353 ridx = rates[i] / 8;
7354 rbit = BIT(rates[i] % 8);
7355
7356 /* check validity */
Dan Carpenter910570b52012-02-01 10:42:11 +03007357 if ((ridx < 0) || (ridx >= IEEE80211_HT_MCS_MASK_LEN))
Simon Wunderlich24db78c2012-01-28 17:25:32 +01007358 return false;
7359
7360 /* check availability */
7361 if (sband->ht_cap.mcs.rx_mask[ridx] & rbit)
7362 mcs[ridx] |= rbit;
7363 else
7364 return false;
7365 }
7366
7367 return true;
7368}
7369
Janusz Dziedzic204e35a2013-12-05 20:42:58 +01007370static u16 vht_mcs_map_to_mcs_mask(u8 vht_mcs_map)
7371{
7372 u16 mcs_mask = 0;
7373
7374 switch (vht_mcs_map) {
7375 case IEEE80211_VHT_MCS_NOT_SUPPORTED:
7376 break;
7377 case IEEE80211_VHT_MCS_SUPPORT_0_7:
7378 mcs_mask = 0x00FF;
7379 break;
7380 case IEEE80211_VHT_MCS_SUPPORT_0_8:
7381 mcs_mask = 0x01FF;
7382 break;
7383 case IEEE80211_VHT_MCS_SUPPORT_0_9:
7384 mcs_mask = 0x03FF;
7385 break;
7386 default:
7387 break;
7388 }
7389
7390 return mcs_mask;
7391}
7392
7393static void vht_build_mcs_mask(u16 vht_mcs_map,
7394 u16 vht_mcs_mask[NL80211_VHT_NSS_MAX])
7395{
7396 u8 nss;
7397
7398 for (nss = 0; nss < NL80211_VHT_NSS_MAX; nss++) {
7399 vht_mcs_mask[nss] = vht_mcs_map_to_mcs_mask(vht_mcs_map & 0x03);
7400 vht_mcs_map >>= 2;
7401 }
7402}
7403
7404static bool vht_set_mcs_mask(struct ieee80211_supported_band *sband,
7405 struct nl80211_txrate_vht *txrate,
7406 u16 mcs[NL80211_VHT_NSS_MAX])
7407{
7408 u16 tx_mcs_map = le16_to_cpu(sband->vht_cap.vht_mcs.tx_mcs_map);
7409 u16 tx_mcs_mask[NL80211_VHT_NSS_MAX] = {};
7410 u8 i;
7411
7412 if (!sband->vht_cap.vht_supported)
7413 return false;
7414
7415 memset(mcs, 0, sizeof(u16) * NL80211_VHT_NSS_MAX);
7416
7417 /* Build vht_mcs_mask from VHT capabilities */
7418 vht_build_mcs_mask(tx_mcs_map, tx_mcs_mask);
7419
7420 for (i = 0; i < NL80211_VHT_NSS_MAX; i++) {
7421 if ((tx_mcs_mask[i] & txrate->mcs[i]) == txrate->mcs[i])
7422 mcs[i] = txrate->mcs[i];
7423 else
7424 return false;
7425 }
7426
7427 return true;
7428}
7429
Alexey Dobriyanb54452b2010-02-18 08:14:31 +00007430static const struct nla_policy nl80211_txattr_policy[NL80211_TXRATE_MAX + 1] = {
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007431 [NL80211_TXRATE_LEGACY] = { .type = NLA_BINARY,
7432 .len = NL80211_MAX_SUPP_RATES },
Janusz Dziedzicd1e33e62013-12-05 10:02:15 +01007433 [NL80211_TXRATE_HT] = { .type = NLA_BINARY,
7434 .len = NL80211_MAX_SUPP_HT_RATES },
Janusz Dziedzic204e35a2013-12-05 20:42:58 +01007435 [NL80211_TXRATE_VHT] = { .len = sizeof(struct nl80211_txrate_vht)},
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007436};
7437
7438static int nl80211_set_tx_bitrate_mask(struct sk_buff *skb,
7439 struct genl_info *info)
7440{
7441 struct nlattr *tb[NL80211_TXRATE_MAX + 1];
Johannes Berg4c476992010-10-04 21:36:35 +02007442 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007443 struct cfg80211_bitrate_mask mask;
Johannes Berg4c476992010-10-04 21:36:35 +02007444 int rem, i;
7445 struct net_device *dev = info->user_ptr[1];
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007446 struct nlattr *tx_rates;
7447 struct ieee80211_supported_band *sband;
Janusz Dziedzic204e35a2013-12-05 20:42:58 +01007448 u16 vht_tx_mcs_map;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007449
Johannes Berg4c476992010-10-04 21:36:35 +02007450 if (!rdev->ops->set_bitrate_mask)
7451 return -EOPNOTSUPP;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007452
7453 memset(&mask, 0, sizeof(mask));
7454 /* Default to all rates enabled */
7455 for (i = 0; i < IEEE80211_NUM_BANDS; i++) {
7456 sband = rdev->wiphy.bands[i];
Janusz Dziedzic78693032013-12-03 09:50:44 +01007457
7458 if (!sband)
7459 continue;
7460
7461 mask.control[i].legacy = (1 << sband->n_bitrates) - 1;
Janusz Dziedzicd1e33e62013-12-05 10:02:15 +01007462 memcpy(mask.control[i].ht_mcs,
Janusz Dziedzic78693032013-12-03 09:50:44 +01007463 sband->ht_cap.mcs.rx_mask,
Janusz Dziedzicd1e33e62013-12-05 10:02:15 +01007464 sizeof(mask.control[i].ht_mcs));
Janusz Dziedzic204e35a2013-12-05 20:42:58 +01007465
7466 if (!sband->vht_cap.vht_supported)
7467 continue;
7468
7469 vht_tx_mcs_map = le16_to_cpu(sband->vht_cap.vht_mcs.tx_mcs_map);
7470 vht_build_mcs_mask(vht_tx_mcs_map, mask.control[i].vht_mcs);
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007471 }
7472
Janusz Dziedzicb9243ab2013-12-05 10:02:14 +01007473 /* if no rates are given set it back to the defaults */
7474 if (!info->attrs[NL80211_ATTR_TX_RATES])
7475 goto out;
7476
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007477 /*
7478 * The nested attribute uses enum nl80211_band as the index. This maps
7479 * directly to the enum ieee80211_band values used in cfg80211.
7480 */
Simon Wunderlich24db78c2012-01-28 17:25:32 +01007481 BUILD_BUG_ON(NL80211_MAX_SUPP_HT_RATES > IEEE80211_HT_MCS_MASK_LEN * 8);
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007482 nla_for_each_nested(tx_rates, info->attrs[NL80211_ATTR_TX_RATES], rem)
7483 {
7484 enum ieee80211_band band = nla_type(tx_rates);
Johannes Berg4c476992010-10-04 21:36:35 +02007485 if (band < 0 || band >= IEEE80211_NUM_BANDS)
7486 return -EINVAL;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007487 sband = rdev->wiphy.bands[band];
Johannes Berg4c476992010-10-04 21:36:35 +02007488 if (sband == NULL)
7489 return -EINVAL;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007490 nla_parse(tb, NL80211_TXRATE_MAX, nla_data(tx_rates),
7491 nla_len(tx_rates), nl80211_txattr_policy);
7492 if (tb[NL80211_TXRATE_LEGACY]) {
7493 mask.control[band].legacy = rateset_to_mask(
7494 sband,
7495 nla_data(tb[NL80211_TXRATE_LEGACY]),
7496 nla_len(tb[NL80211_TXRATE_LEGACY]));
Bala Shanmugam218d2e22012-04-20 19:12:58 +05307497 if ((mask.control[band].legacy == 0) &&
7498 nla_len(tb[NL80211_TXRATE_LEGACY]))
7499 return -EINVAL;
Simon Wunderlich24db78c2012-01-28 17:25:32 +01007500 }
Janusz Dziedzicd1e33e62013-12-05 10:02:15 +01007501 if (tb[NL80211_TXRATE_HT]) {
Simon Wunderlich24db78c2012-01-28 17:25:32 +01007502 if (!ht_rateset_to_mask(
7503 sband,
Janusz Dziedzicd1e33e62013-12-05 10:02:15 +01007504 nla_data(tb[NL80211_TXRATE_HT]),
7505 nla_len(tb[NL80211_TXRATE_HT]),
7506 mask.control[band].ht_mcs))
Simon Wunderlich24db78c2012-01-28 17:25:32 +01007507 return -EINVAL;
7508 }
Janusz Dziedzic204e35a2013-12-05 20:42:58 +01007509 if (tb[NL80211_TXRATE_VHT]) {
7510 if (!vht_set_mcs_mask(
7511 sband,
7512 nla_data(tb[NL80211_TXRATE_VHT]),
7513 mask.control[band].vht_mcs))
7514 return -EINVAL;
7515 }
Simon Wunderlich24db78c2012-01-28 17:25:32 +01007516
7517 if (mask.control[band].legacy == 0) {
Janusz Dziedzic204e35a2013-12-05 20:42:58 +01007518 /* don't allow empty legacy rates if HT or VHT
7519 * are not even supported.
7520 */
7521 if (!(rdev->wiphy.bands[band]->ht_cap.ht_supported ||
7522 rdev->wiphy.bands[band]->vht_cap.vht_supported))
Simon Wunderlich24db78c2012-01-28 17:25:32 +01007523 return -EINVAL;
7524
7525 for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++)
Janusz Dziedzicd1e33e62013-12-05 10:02:15 +01007526 if (mask.control[band].ht_mcs[i])
Janusz Dziedzic204e35a2013-12-05 20:42:58 +01007527 goto out;
7528
7529 for (i = 0; i < NL80211_VHT_NSS_MAX; i++)
7530 if (mask.control[band].vht_mcs[i])
7531 goto out;
Simon Wunderlich24db78c2012-01-28 17:25:32 +01007532
7533 /* legacy and mcs rates may not be both empty */
Janusz Dziedzic204e35a2013-12-05 20:42:58 +01007534 return -EINVAL;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007535 }
7536 }
7537
Janusz Dziedzicb9243ab2013-12-05 10:02:14 +01007538out:
Hila Gonene35e4d22012-06-27 17:19:42 +03007539 return rdev_set_bitrate_mask(rdev, dev, NULL, &mask);
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007540}
7541
Johannes Berg2e161f72010-08-12 15:38:38 +02007542static int nl80211_register_mgmt(struct sk_buff *skb, struct genl_info *info)
Jouni Malinen026331c2010-02-15 12:53:10 +02007543{
Johannes Berg4c476992010-10-04 21:36:35 +02007544 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02007545 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg2e161f72010-08-12 15:38:38 +02007546 u16 frame_type = IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_ACTION;
Jouni Malinen026331c2010-02-15 12:53:10 +02007547
7548 if (!info->attrs[NL80211_ATTR_FRAME_MATCH])
7549 return -EINVAL;
7550
Johannes Berg2e161f72010-08-12 15:38:38 +02007551 if (info->attrs[NL80211_ATTR_FRAME_TYPE])
7552 frame_type = nla_get_u16(info->attrs[NL80211_ATTR_FRAME_TYPE]);
Jouni Malinen026331c2010-02-15 12:53:10 +02007553
Johannes Berg71bbc992012-06-15 15:30:18 +02007554 switch (wdev->iftype) {
7555 case NL80211_IFTYPE_STATION:
7556 case NL80211_IFTYPE_ADHOC:
7557 case NL80211_IFTYPE_P2P_CLIENT:
7558 case NL80211_IFTYPE_AP:
7559 case NL80211_IFTYPE_AP_VLAN:
7560 case NL80211_IFTYPE_MESH_POINT:
7561 case NL80211_IFTYPE_P2P_GO:
Johannes Berg98104fde2012-06-16 00:19:54 +02007562 case NL80211_IFTYPE_P2P_DEVICE:
Johannes Berg71bbc992012-06-15 15:30:18 +02007563 break;
7564 default:
Johannes Berg4c476992010-10-04 21:36:35 +02007565 return -EOPNOTSUPP;
Johannes Berg71bbc992012-06-15 15:30:18 +02007566 }
Jouni Malinen026331c2010-02-15 12:53:10 +02007567
7568 /* not much point in registering if we can't reply */
Johannes Berg4c476992010-10-04 21:36:35 +02007569 if (!rdev->ops->mgmt_tx)
7570 return -EOPNOTSUPP;
Jouni Malinen026331c2010-02-15 12:53:10 +02007571
Eric W. Biederman15e47302012-09-07 20:12:54 +00007572 return cfg80211_mlme_register_mgmt(wdev, info->snd_portid, frame_type,
Jouni Malinen026331c2010-02-15 12:53:10 +02007573 nla_data(info->attrs[NL80211_ATTR_FRAME_MATCH]),
7574 nla_len(info->attrs[NL80211_ATTR_FRAME_MATCH]));
Jouni Malinen026331c2010-02-15 12:53:10 +02007575}
7576
Johannes Berg2e161f72010-08-12 15:38:38 +02007577static int nl80211_tx_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 Berg683b6d32012-11-08 21:25:48 +01007581 struct cfg80211_chan_def chandef;
Jouni Malinen026331c2010-02-15 12:53:10 +02007582 int err;
Johannes Bergd64d3732011-11-10 09:44:46 +01007583 void *hdr = NULL;
Jouni Malinen026331c2010-02-15 12:53:10 +02007584 u64 cookie;
Johannes Berge247bd902011-11-04 11:18:21 +01007585 struct sk_buff *msg = NULL;
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02007586 struct cfg80211_mgmt_tx_params params = {
7587 .dont_wait_for_ack =
7588 info->attrs[NL80211_ATTR_DONT_WAIT_FOR_ACK],
7589 };
Jouni Malinen026331c2010-02-15 12:53:10 +02007590
Johannes Berg683b6d32012-11-08 21:25:48 +01007591 if (!info->attrs[NL80211_ATTR_FRAME])
Jouni Malinen026331c2010-02-15 12:53:10 +02007592 return -EINVAL;
7593
Johannes Berg4c476992010-10-04 21:36:35 +02007594 if (!rdev->ops->mgmt_tx)
7595 return -EOPNOTSUPP;
Jouni Malinen026331c2010-02-15 12:53:10 +02007596
Johannes Berg71bbc992012-06-15 15:30:18 +02007597 switch (wdev->iftype) {
Antonio Quartulliea141b752013-06-11 14:20:03 +02007598 case NL80211_IFTYPE_P2P_DEVICE:
7599 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ])
7600 return -EINVAL;
Johannes Berg71bbc992012-06-15 15:30:18 +02007601 case NL80211_IFTYPE_STATION:
7602 case NL80211_IFTYPE_ADHOC:
7603 case NL80211_IFTYPE_P2P_CLIENT:
7604 case NL80211_IFTYPE_AP:
7605 case NL80211_IFTYPE_AP_VLAN:
7606 case NL80211_IFTYPE_MESH_POINT:
7607 case NL80211_IFTYPE_P2P_GO:
7608 break;
7609 default:
Johannes Berg4c476992010-10-04 21:36:35 +02007610 return -EOPNOTSUPP;
Johannes Berg71bbc992012-06-15 15:30:18 +02007611 }
Jouni Malinen026331c2010-02-15 12:53:10 +02007612
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007613 if (info->attrs[NL80211_ATTR_DURATION]) {
Johannes Berg7c4ef712011-11-18 15:33:48 +01007614 if (!(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX))
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007615 return -EINVAL;
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02007616 params.wait = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]);
Johannes Bergebf348f2012-06-01 12:50:54 +02007617
7618 /*
7619 * We should wait on the channel for at least a minimum amount
7620 * of time (10ms) but no longer than the driver supports.
7621 */
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02007622 if (params.wait < NL80211_MIN_REMAIN_ON_CHANNEL_TIME ||
7623 params.wait > rdev->wiphy.max_remain_on_channel_duration)
Johannes Bergebf348f2012-06-01 12:50:54 +02007624 return -EINVAL;
7625
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007626 }
7627
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02007628 params.offchan = info->attrs[NL80211_ATTR_OFFCHANNEL_TX_OK];
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007629
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02007630 if (params.offchan && !(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX))
Johannes Berg7c4ef712011-11-18 15:33:48 +01007631 return -EINVAL;
7632
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02007633 params.no_cck = nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]);
Rajkumar Manoharane9f935e2011-09-25 14:53:30 +05307634
Antonio Quartulliea141b752013-06-11 14:20:03 +02007635 /* get the channel if any has been specified, otherwise pass NULL to
7636 * the driver. The latter will use the current one
7637 */
7638 chandef.chan = NULL;
7639 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
7640 err = nl80211_parse_chandef(rdev, info, &chandef);
7641 if (err)
7642 return err;
7643 }
7644
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02007645 if (!chandef.chan && params.offchan)
Antonio Quartulliea141b752013-06-11 14:20:03 +02007646 return -EINVAL;
Jouni Malinen026331c2010-02-15 12:53:10 +02007647
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02007648 if (!params.dont_wait_for_ack) {
Johannes Berge247bd902011-11-04 11:18:21 +01007649 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
7650 if (!msg)
7651 return -ENOMEM;
Jouni Malinen026331c2010-02-15 12:53:10 +02007652
Eric W. Biederman15e47302012-09-07 20:12:54 +00007653 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berge247bd902011-11-04 11:18:21 +01007654 NL80211_CMD_FRAME);
Dan Carpentercb35fba2013-08-14 14:50:01 +03007655 if (!hdr) {
7656 err = -ENOBUFS;
Johannes Berge247bd902011-11-04 11:18:21 +01007657 goto free_msg;
7658 }
Jouni Malinen026331c2010-02-15 12:53:10 +02007659 }
Johannes Berge247bd902011-11-04 11:18:21 +01007660
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02007661 params.buf = nla_data(info->attrs[NL80211_ATTR_FRAME]);
7662 params.len = nla_len(info->attrs[NL80211_ATTR_FRAME]);
7663 params.chan = chandef.chan;
7664 err = cfg80211_mlme_mgmt_tx(rdev, wdev, &params, &cookie);
Jouni Malinen026331c2010-02-15 12:53:10 +02007665 if (err)
7666 goto free_msg;
7667
Johannes Berge247bd902011-11-04 11:18:21 +01007668 if (msg) {
David S. Miller9360ffd2012-03-29 04:41:26 -04007669 if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie))
7670 goto nla_put_failure;
Jouni Malinen026331c2010-02-15 12:53:10 +02007671
Johannes Berge247bd902011-11-04 11:18:21 +01007672 genlmsg_end(msg, hdr);
7673 return genlmsg_reply(msg, info);
7674 }
7675
7676 return 0;
Jouni Malinen026331c2010-02-15 12:53:10 +02007677
7678 nla_put_failure:
7679 err = -ENOBUFS;
7680 free_msg:
7681 nlmsg_free(msg);
Jouni Malinen026331c2010-02-15 12:53:10 +02007682 return err;
7683}
7684
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007685static int nl80211_tx_mgmt_cancel_wait(struct sk_buff *skb, struct genl_info *info)
7686{
7687 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02007688 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007689 u64 cookie;
7690
7691 if (!info->attrs[NL80211_ATTR_COOKIE])
7692 return -EINVAL;
7693
7694 if (!rdev->ops->mgmt_tx_cancel_wait)
7695 return -EOPNOTSUPP;
7696
Johannes Berg71bbc992012-06-15 15:30:18 +02007697 switch (wdev->iftype) {
7698 case NL80211_IFTYPE_STATION:
7699 case NL80211_IFTYPE_ADHOC:
7700 case NL80211_IFTYPE_P2P_CLIENT:
7701 case NL80211_IFTYPE_AP:
7702 case NL80211_IFTYPE_AP_VLAN:
7703 case NL80211_IFTYPE_P2P_GO:
Johannes Berg98104fde2012-06-16 00:19:54 +02007704 case NL80211_IFTYPE_P2P_DEVICE:
Johannes Berg71bbc992012-06-15 15:30:18 +02007705 break;
7706 default:
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007707 return -EOPNOTSUPP;
Johannes Berg71bbc992012-06-15 15:30:18 +02007708 }
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007709
7710 cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]);
7711
Hila Gonene35e4d22012-06-27 17:19:42 +03007712 return rdev_mgmt_tx_cancel_wait(rdev, wdev, cookie);
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007713}
7714
Kalle Valoffb9eb32010-02-17 17:58:10 +02007715static int nl80211_set_power_save(struct sk_buff *skb, struct genl_info *info)
7716{
Johannes Berg4c476992010-10-04 21:36:35 +02007717 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Kalle Valoffb9eb32010-02-17 17:58:10 +02007718 struct wireless_dev *wdev;
Johannes Berg4c476992010-10-04 21:36:35 +02007719 struct net_device *dev = info->user_ptr[1];
Kalle Valoffb9eb32010-02-17 17:58:10 +02007720 u8 ps_state;
7721 bool state;
7722 int err;
7723
Johannes Berg4c476992010-10-04 21:36:35 +02007724 if (!info->attrs[NL80211_ATTR_PS_STATE])
7725 return -EINVAL;
Kalle Valoffb9eb32010-02-17 17:58:10 +02007726
7727 ps_state = nla_get_u32(info->attrs[NL80211_ATTR_PS_STATE]);
7728
Johannes Berg4c476992010-10-04 21:36:35 +02007729 if (ps_state != NL80211_PS_DISABLED && ps_state != NL80211_PS_ENABLED)
7730 return -EINVAL;
Kalle Valoffb9eb32010-02-17 17:58:10 +02007731
7732 wdev = dev->ieee80211_ptr;
7733
Johannes Berg4c476992010-10-04 21:36:35 +02007734 if (!rdev->ops->set_power_mgmt)
7735 return -EOPNOTSUPP;
Kalle Valoffb9eb32010-02-17 17:58:10 +02007736
7737 state = (ps_state == NL80211_PS_ENABLED) ? true : false;
7738
7739 if (state == wdev->ps)
Johannes Berg4c476992010-10-04 21:36:35 +02007740 return 0;
Kalle Valoffb9eb32010-02-17 17:58:10 +02007741
Hila Gonene35e4d22012-06-27 17:19:42 +03007742 err = rdev_set_power_mgmt(rdev, dev, state, wdev->ps_timeout);
Johannes Berg4c476992010-10-04 21:36:35 +02007743 if (!err)
7744 wdev->ps = state;
Kalle Valoffb9eb32010-02-17 17:58:10 +02007745 return err;
7746}
7747
7748static int nl80211_get_power_save(struct sk_buff *skb, struct genl_info *info)
7749{
Johannes Berg4c476992010-10-04 21:36:35 +02007750 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Kalle Valoffb9eb32010-02-17 17:58:10 +02007751 enum nl80211_ps_state ps_state;
7752 struct wireless_dev *wdev;
Johannes Berg4c476992010-10-04 21:36:35 +02007753 struct net_device *dev = info->user_ptr[1];
Kalle Valoffb9eb32010-02-17 17:58:10 +02007754 struct sk_buff *msg;
7755 void *hdr;
7756 int err;
7757
Kalle Valoffb9eb32010-02-17 17:58:10 +02007758 wdev = dev->ieee80211_ptr;
7759
Johannes Berg4c476992010-10-04 21:36:35 +02007760 if (!rdev->ops->set_power_mgmt)
7761 return -EOPNOTSUPP;
Kalle Valoffb9eb32010-02-17 17:58:10 +02007762
7763 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02007764 if (!msg)
7765 return -ENOMEM;
Kalle Valoffb9eb32010-02-17 17:58:10 +02007766
Eric W. Biederman15e47302012-09-07 20:12:54 +00007767 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Kalle Valoffb9eb32010-02-17 17:58:10 +02007768 NL80211_CMD_GET_POWER_SAVE);
7769 if (!hdr) {
Johannes Berg4c476992010-10-04 21:36:35 +02007770 err = -ENOBUFS;
Kalle Valoffb9eb32010-02-17 17:58:10 +02007771 goto free_msg;
7772 }
7773
7774 if (wdev->ps)
7775 ps_state = NL80211_PS_ENABLED;
7776 else
7777 ps_state = NL80211_PS_DISABLED;
7778
David S. Miller9360ffd2012-03-29 04:41:26 -04007779 if (nla_put_u32(msg, NL80211_ATTR_PS_STATE, ps_state))
7780 goto nla_put_failure;
Kalle Valoffb9eb32010-02-17 17:58:10 +02007781
7782 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02007783 return genlmsg_reply(msg, info);
Kalle Valoffb9eb32010-02-17 17:58:10 +02007784
Johannes Berg4c476992010-10-04 21:36:35 +02007785 nla_put_failure:
Kalle Valoffb9eb32010-02-17 17:58:10 +02007786 err = -ENOBUFS;
Johannes Berg4c476992010-10-04 21:36:35 +02007787 free_msg:
Kalle Valoffb9eb32010-02-17 17:58:10 +02007788 nlmsg_free(msg);
Kalle Valoffb9eb32010-02-17 17:58:10 +02007789 return err;
7790}
7791
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02007792static struct nla_policy
7793nl80211_attr_cqm_policy[NL80211_ATTR_CQM_MAX + 1] __read_mostly = {
7794 [NL80211_ATTR_CQM_RSSI_THOLD] = { .type = NLA_U32 },
7795 [NL80211_ATTR_CQM_RSSI_HYST] = { .type = NLA_U32 },
7796 [NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT] = { .type = NLA_U32 },
Thomas Pedersen84f10702012-07-12 16:17:33 -07007797 [NL80211_ATTR_CQM_TXE_RATE] = { .type = NLA_U32 },
7798 [NL80211_ATTR_CQM_TXE_PKTS] = { .type = NLA_U32 },
7799 [NL80211_ATTR_CQM_TXE_INTVL] = { .type = NLA_U32 },
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02007800};
7801
Thomas Pedersen84f10702012-07-12 16:17:33 -07007802static int nl80211_set_cqm_txe(struct genl_info *info,
Johannes Bergd9d8b012012-11-26 12:51:52 +01007803 u32 rate, u32 pkts, u32 intvl)
Thomas Pedersen84f10702012-07-12 16:17:33 -07007804{
7805 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Thomas Pedersen84f10702012-07-12 16:17:33 -07007806 struct net_device *dev = info->user_ptr[1];
Johannes Berg1da5fcc2013-08-06 14:10:48 +02007807 struct wireless_dev *wdev = dev->ieee80211_ptr;
Thomas Pedersen84f10702012-07-12 16:17:33 -07007808
Johannes Bergd9d8b012012-11-26 12:51:52 +01007809 if (rate > 100 || intvl > NL80211_CQM_TXE_MAX_INTVL)
Thomas Pedersen84f10702012-07-12 16:17:33 -07007810 return -EINVAL;
7811
Thomas Pedersen84f10702012-07-12 16:17:33 -07007812 if (!rdev->ops->set_cqm_txe_config)
7813 return -EOPNOTSUPP;
7814
7815 if (wdev->iftype != NL80211_IFTYPE_STATION &&
7816 wdev->iftype != NL80211_IFTYPE_P2P_CLIENT)
7817 return -EOPNOTSUPP;
7818
Hila Gonene35e4d22012-06-27 17:19:42 +03007819 return rdev_set_cqm_txe_config(rdev, dev, rate, pkts, intvl);
Thomas Pedersen84f10702012-07-12 16:17:33 -07007820}
7821
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02007822static int nl80211_set_cqm_rssi(struct genl_info *info,
7823 s32 threshold, u32 hysteresis)
7824{
Johannes Berg4c476992010-10-04 21:36:35 +02007825 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg4c476992010-10-04 21:36:35 +02007826 struct net_device *dev = info->user_ptr[1];
Johannes Berg1da5fcc2013-08-06 14:10:48 +02007827 struct wireless_dev *wdev = dev->ieee80211_ptr;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02007828
7829 if (threshold > 0)
7830 return -EINVAL;
7831
Johannes Berg1da5fcc2013-08-06 14:10:48 +02007832 /* disabling - hysteresis should also be zero then */
7833 if (threshold == 0)
7834 hysteresis = 0;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02007835
Johannes Berg4c476992010-10-04 21:36:35 +02007836 if (!rdev->ops->set_cqm_rssi_config)
7837 return -EOPNOTSUPP;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02007838
Johannes Berg074ac8d2010-09-16 14:58:22 +02007839 if (wdev->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02007840 wdev->iftype != NL80211_IFTYPE_P2P_CLIENT)
7841 return -EOPNOTSUPP;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02007842
Hila Gonene35e4d22012-06-27 17:19:42 +03007843 return rdev_set_cqm_rssi_config(rdev, dev, threshold, hysteresis);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02007844}
7845
7846static int nl80211_set_cqm(struct sk_buff *skb, struct genl_info *info)
7847{
7848 struct nlattr *attrs[NL80211_ATTR_CQM_MAX + 1];
7849 struct nlattr *cqm;
7850 int err;
7851
7852 cqm = info->attrs[NL80211_ATTR_CQM];
Johannes Berg1da5fcc2013-08-06 14:10:48 +02007853 if (!cqm)
7854 return -EINVAL;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02007855
7856 err = nla_parse_nested(attrs, NL80211_ATTR_CQM_MAX, cqm,
7857 nl80211_attr_cqm_policy);
7858 if (err)
Johannes Berg1da5fcc2013-08-06 14:10:48 +02007859 return err;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02007860
7861 if (attrs[NL80211_ATTR_CQM_RSSI_THOLD] &&
7862 attrs[NL80211_ATTR_CQM_RSSI_HYST]) {
Johannes Berg1da5fcc2013-08-06 14:10:48 +02007863 s32 threshold = nla_get_s32(attrs[NL80211_ATTR_CQM_RSSI_THOLD]);
7864 u32 hysteresis = nla_get_u32(attrs[NL80211_ATTR_CQM_RSSI_HYST]);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02007865
Johannes Berg1da5fcc2013-08-06 14:10:48 +02007866 return nl80211_set_cqm_rssi(info, threshold, hysteresis);
7867 }
7868
7869 if (attrs[NL80211_ATTR_CQM_TXE_RATE] &&
7870 attrs[NL80211_ATTR_CQM_TXE_PKTS] &&
7871 attrs[NL80211_ATTR_CQM_TXE_INTVL]) {
7872 u32 rate = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_RATE]);
7873 u32 pkts = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_PKTS]);
7874 u32 intvl = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_INTVL]);
7875
7876 return nl80211_set_cqm_txe(info, rate, pkts, intvl);
7877 }
7878
7879 return -EINVAL;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02007880}
7881
Johannes Berg29cbe682010-12-03 09:20:44 +01007882static int nl80211_join_mesh(struct sk_buff *skb, struct genl_info *info)
7883{
7884 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7885 struct net_device *dev = info->user_ptr[1];
7886 struct mesh_config cfg;
Javier Cardonac80d5452010-12-16 17:37:49 -08007887 struct mesh_setup setup;
Johannes Berg29cbe682010-12-03 09:20:44 +01007888 int err;
7889
7890 /* start with default */
7891 memcpy(&cfg, &default_mesh_config, sizeof(cfg));
Javier Cardonac80d5452010-12-16 17:37:49 -08007892 memcpy(&setup, &default_mesh_setup, sizeof(setup));
Johannes Berg29cbe682010-12-03 09:20:44 +01007893
Javier Cardona24bdd9f2010-12-16 17:37:48 -08007894 if (info->attrs[NL80211_ATTR_MESH_CONFIG]) {
Johannes Berg29cbe682010-12-03 09:20:44 +01007895 /* and parse parameters if given */
Javier Cardona24bdd9f2010-12-16 17:37:48 -08007896 err = nl80211_parse_mesh_config(info, &cfg, NULL);
Johannes Berg29cbe682010-12-03 09:20:44 +01007897 if (err)
7898 return err;
7899 }
7900
7901 if (!info->attrs[NL80211_ATTR_MESH_ID] ||
7902 !nla_len(info->attrs[NL80211_ATTR_MESH_ID]))
7903 return -EINVAL;
7904
Javier Cardonac80d5452010-12-16 17:37:49 -08007905 setup.mesh_id = nla_data(info->attrs[NL80211_ATTR_MESH_ID]);
7906 setup.mesh_id_len = nla_len(info->attrs[NL80211_ATTR_MESH_ID]);
7907
Chun-Yeow Yeoh4bb62342011-11-24 17:15:20 -08007908 if (info->attrs[NL80211_ATTR_MCAST_RATE] &&
7909 !nl80211_parse_mcast_rate(rdev, setup.mcast_rate,
7910 nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE])))
7911 return -EINVAL;
7912
Marco Porsch9bdbf042013-01-07 16:04:51 +01007913 if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) {
7914 setup.beacon_interval =
7915 nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]);
7916 if (setup.beacon_interval < 10 ||
7917 setup.beacon_interval > 10000)
7918 return -EINVAL;
7919 }
7920
7921 if (info->attrs[NL80211_ATTR_DTIM_PERIOD]) {
7922 setup.dtim_period =
7923 nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]);
7924 if (setup.dtim_period < 1 || setup.dtim_period > 100)
7925 return -EINVAL;
7926 }
7927
Javier Cardonac80d5452010-12-16 17:37:49 -08007928 if (info->attrs[NL80211_ATTR_MESH_SETUP]) {
7929 /* parse additional setup parameters if given */
7930 err = nl80211_parse_mesh_setup(info, &setup);
7931 if (err)
7932 return err;
7933 }
7934
Thomas Pedersend37bb182013-03-04 13:06:13 -08007935 if (setup.user_mpm)
7936 cfg.auto_open_plinks = false;
7937
Johannes Bergcc1d2802012-05-16 23:50:20 +02007938 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
Johannes Berg683b6d32012-11-08 21:25:48 +01007939 err = nl80211_parse_chandef(rdev, info, &setup.chandef);
7940 if (err)
7941 return err;
Johannes Bergcc1d2802012-05-16 23:50:20 +02007942 } else {
7943 /* cfg80211_join_mesh() will sort it out */
Johannes Berg683b6d32012-11-08 21:25:48 +01007944 setup.chandef.chan = NULL;
Johannes Bergcc1d2802012-05-16 23:50:20 +02007945 }
7946
Ashok Nagarajanffb3cf32013-06-03 10:33:36 -07007947 if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) {
7948 u8 *rates = nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
7949 int n_rates =
7950 nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
7951 struct ieee80211_supported_band *sband;
7952
7953 if (!setup.chandef.chan)
7954 return -EINVAL;
7955
7956 sband = rdev->wiphy.bands[setup.chandef.chan->band];
7957
7958 err = ieee80211_get_ratemask(sband, rates, n_rates,
7959 &setup.basic_rates);
7960 if (err)
7961 return err;
7962 }
7963
Javier Cardonac80d5452010-12-16 17:37:49 -08007964 return cfg80211_join_mesh(rdev, dev, &setup, &cfg);
Johannes Berg29cbe682010-12-03 09:20:44 +01007965}
7966
7967static int nl80211_leave_mesh(struct sk_buff *skb, struct genl_info *info)
7968{
7969 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7970 struct net_device *dev = info->user_ptr[1];
7971
7972 return cfg80211_leave_mesh(rdev, dev);
7973}
7974
Johannes Bergdfb89c52012-06-27 09:23:48 +02007975#ifdef CONFIG_PM
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08007976static int nl80211_send_wowlan_patterns(struct sk_buff *msg,
7977 struct cfg80211_registered_device *rdev)
7978{
Johannes Berg6abb9cb2013-05-15 09:30:07 +02007979 struct cfg80211_wowlan *wowlan = rdev->wiphy.wowlan_config;
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08007980 struct nlattr *nl_pats, *nl_pat;
7981 int i, pat_len;
7982
Johannes Berg6abb9cb2013-05-15 09:30:07 +02007983 if (!wowlan->n_patterns)
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08007984 return 0;
7985
7986 nl_pats = nla_nest_start(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN);
7987 if (!nl_pats)
7988 return -ENOBUFS;
7989
Johannes Berg6abb9cb2013-05-15 09:30:07 +02007990 for (i = 0; i < wowlan->n_patterns; i++) {
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08007991 nl_pat = nla_nest_start(msg, i + 1);
7992 if (!nl_pat)
7993 return -ENOBUFS;
Johannes Berg6abb9cb2013-05-15 09:30:07 +02007994 pat_len = wowlan->patterns[i].pattern_len;
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07007995 if (nla_put(msg, NL80211_PKTPAT_MASK, DIV_ROUND_UP(pat_len, 8),
Johannes Berg6abb9cb2013-05-15 09:30:07 +02007996 wowlan->patterns[i].mask) ||
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07007997 nla_put(msg, NL80211_PKTPAT_PATTERN, pat_len,
7998 wowlan->patterns[i].pattern) ||
7999 nla_put_u32(msg, NL80211_PKTPAT_OFFSET,
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008000 wowlan->patterns[i].pkt_offset))
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08008001 return -ENOBUFS;
8002 nla_nest_end(msg, nl_pat);
8003 }
8004 nla_nest_end(msg, nl_pats);
8005
8006 return 0;
8007}
8008
Johannes Berg2a0e0472013-01-23 22:57:40 +01008009static int nl80211_send_wowlan_tcp(struct sk_buff *msg,
8010 struct cfg80211_wowlan_tcp *tcp)
8011{
8012 struct nlattr *nl_tcp;
8013
8014 if (!tcp)
8015 return 0;
8016
8017 nl_tcp = nla_nest_start(msg, NL80211_WOWLAN_TRIG_TCP_CONNECTION);
8018 if (!nl_tcp)
8019 return -ENOBUFS;
8020
8021 if (nla_put_be32(msg, NL80211_WOWLAN_TCP_SRC_IPV4, tcp->src) ||
8022 nla_put_be32(msg, NL80211_WOWLAN_TCP_DST_IPV4, tcp->dst) ||
8023 nla_put(msg, NL80211_WOWLAN_TCP_DST_MAC, ETH_ALEN, tcp->dst_mac) ||
8024 nla_put_u16(msg, NL80211_WOWLAN_TCP_SRC_PORT, tcp->src_port) ||
8025 nla_put_u16(msg, NL80211_WOWLAN_TCP_DST_PORT, tcp->dst_port) ||
8026 nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD,
8027 tcp->payload_len, tcp->payload) ||
8028 nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_INTERVAL,
8029 tcp->data_interval) ||
8030 nla_put(msg, NL80211_WOWLAN_TCP_WAKE_PAYLOAD,
8031 tcp->wake_len, tcp->wake_data) ||
8032 nla_put(msg, NL80211_WOWLAN_TCP_WAKE_MASK,
8033 DIV_ROUND_UP(tcp->wake_len, 8), tcp->wake_mask))
8034 return -ENOBUFS;
8035
8036 if (tcp->payload_seq.len &&
8037 nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ,
8038 sizeof(tcp->payload_seq), &tcp->payload_seq))
8039 return -ENOBUFS;
8040
8041 if (tcp->payload_tok.len &&
8042 nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN,
8043 sizeof(tcp->payload_tok) + tcp->tokens_size,
8044 &tcp->payload_tok))
8045 return -ENOBUFS;
8046
Johannes Berge248ad32013-05-16 10:24:28 +02008047 nla_nest_end(msg, nl_tcp);
8048
Johannes Berg2a0e0472013-01-23 22:57:40 +01008049 return 0;
8050}
8051
Johannes Bergff1b6e62011-05-04 15:37:28 +02008052static int nl80211_get_wowlan(struct sk_buff *skb, struct genl_info *info)
8053{
8054 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8055 struct sk_buff *msg;
8056 void *hdr;
Johannes Berg2a0e0472013-01-23 22:57:40 +01008057 u32 size = NLMSG_DEFAULT_SIZE;
Johannes Bergff1b6e62011-05-04 15:37:28 +02008058
Johannes Berg964dc9e2013-06-03 17:25:34 +02008059 if (!rdev->wiphy.wowlan)
Johannes Bergff1b6e62011-05-04 15:37:28 +02008060 return -EOPNOTSUPP;
8061
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008062 if (rdev->wiphy.wowlan_config && rdev->wiphy.wowlan_config->tcp) {
Johannes Berg2a0e0472013-01-23 22:57:40 +01008063 /* adjust size to have room for all the data */
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008064 size += rdev->wiphy.wowlan_config->tcp->tokens_size +
8065 rdev->wiphy.wowlan_config->tcp->payload_len +
8066 rdev->wiphy.wowlan_config->tcp->wake_len +
8067 rdev->wiphy.wowlan_config->tcp->wake_len / 8;
Johannes Berg2a0e0472013-01-23 22:57:40 +01008068 }
8069
8070 msg = nlmsg_new(size, GFP_KERNEL);
Johannes Bergff1b6e62011-05-04 15:37:28 +02008071 if (!msg)
8072 return -ENOMEM;
8073
Eric W. Biederman15e47302012-09-07 20:12:54 +00008074 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Johannes Bergff1b6e62011-05-04 15:37:28 +02008075 NL80211_CMD_GET_WOWLAN);
8076 if (!hdr)
8077 goto nla_put_failure;
8078
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008079 if (rdev->wiphy.wowlan_config) {
Johannes Bergff1b6e62011-05-04 15:37:28 +02008080 struct nlattr *nl_wowlan;
8081
8082 nl_wowlan = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS);
8083 if (!nl_wowlan)
8084 goto nla_put_failure;
8085
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008086 if ((rdev->wiphy.wowlan_config->any &&
David S. Miller9360ffd2012-03-29 04:41:26 -04008087 nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008088 (rdev->wiphy.wowlan_config->disconnect &&
David S. Miller9360ffd2012-03-29 04:41:26 -04008089 nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008090 (rdev->wiphy.wowlan_config->magic_pkt &&
David S. Miller9360ffd2012-03-29 04:41:26 -04008091 nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008092 (rdev->wiphy.wowlan_config->gtk_rekey_failure &&
David S. Miller9360ffd2012-03-29 04:41:26 -04008093 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008094 (rdev->wiphy.wowlan_config->eap_identity_req &&
David S. Miller9360ffd2012-03-29 04:41:26 -04008095 nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008096 (rdev->wiphy.wowlan_config->four_way_handshake &&
David S. Miller9360ffd2012-03-29 04:41:26 -04008097 nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008098 (rdev->wiphy.wowlan_config->rfkill_release &&
David S. Miller9360ffd2012-03-29 04:41:26 -04008099 nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE)))
8100 goto nla_put_failure;
Johannes Berg2a0e0472013-01-23 22:57:40 +01008101
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08008102 if (nl80211_send_wowlan_patterns(msg, rdev))
8103 goto nla_put_failure;
Johannes Berg2a0e0472013-01-23 22:57:40 +01008104
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008105 if (nl80211_send_wowlan_tcp(msg,
8106 rdev->wiphy.wowlan_config->tcp))
Johannes Berg2a0e0472013-01-23 22:57:40 +01008107 goto nla_put_failure;
8108
Johannes Bergff1b6e62011-05-04 15:37:28 +02008109 nla_nest_end(msg, nl_wowlan);
8110 }
8111
8112 genlmsg_end(msg, hdr);
8113 return genlmsg_reply(msg, info);
8114
8115nla_put_failure:
8116 nlmsg_free(msg);
8117 return -ENOBUFS;
8118}
8119
Johannes Berg2a0e0472013-01-23 22:57:40 +01008120static int nl80211_parse_wowlan_tcp(struct cfg80211_registered_device *rdev,
8121 struct nlattr *attr,
8122 struct cfg80211_wowlan *trig)
8123{
8124 struct nlattr *tb[NUM_NL80211_WOWLAN_TCP];
8125 struct cfg80211_wowlan_tcp *cfg;
8126 struct nl80211_wowlan_tcp_data_token *tok = NULL;
8127 struct nl80211_wowlan_tcp_data_seq *seq = NULL;
8128 u32 size;
8129 u32 data_size, wake_size, tokens_size = 0, wake_mask_size;
8130 int err, port;
8131
Johannes Berg964dc9e2013-06-03 17:25:34 +02008132 if (!rdev->wiphy.wowlan->tcp)
Johannes Berg2a0e0472013-01-23 22:57:40 +01008133 return -EINVAL;
8134
8135 err = nla_parse(tb, MAX_NL80211_WOWLAN_TCP,
8136 nla_data(attr), nla_len(attr),
8137 nl80211_wowlan_tcp_policy);
8138 if (err)
8139 return err;
8140
8141 if (!tb[NL80211_WOWLAN_TCP_SRC_IPV4] ||
8142 !tb[NL80211_WOWLAN_TCP_DST_IPV4] ||
8143 !tb[NL80211_WOWLAN_TCP_DST_MAC] ||
8144 !tb[NL80211_WOWLAN_TCP_DST_PORT] ||
8145 !tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD] ||
8146 !tb[NL80211_WOWLAN_TCP_DATA_INTERVAL] ||
8147 !tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD] ||
8148 !tb[NL80211_WOWLAN_TCP_WAKE_MASK])
8149 return -EINVAL;
8150
8151 data_size = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]);
Johannes Berg964dc9e2013-06-03 17:25:34 +02008152 if (data_size > rdev->wiphy.wowlan->tcp->data_payload_max)
Johannes Berg2a0e0472013-01-23 22:57:40 +01008153 return -EINVAL;
8154
8155 if (nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]) >
Johannes Berg964dc9e2013-06-03 17:25:34 +02008156 rdev->wiphy.wowlan->tcp->data_interval_max ||
Johannes Berg723d5682013-02-26 13:56:40 +01008157 nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]) == 0)
Johannes Berg2a0e0472013-01-23 22:57:40 +01008158 return -EINVAL;
8159
8160 wake_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]);
Johannes Berg964dc9e2013-06-03 17:25:34 +02008161 if (wake_size > rdev->wiphy.wowlan->tcp->wake_payload_max)
Johannes Berg2a0e0472013-01-23 22:57:40 +01008162 return -EINVAL;
8163
8164 wake_mask_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_MASK]);
8165 if (wake_mask_size != DIV_ROUND_UP(wake_size, 8))
8166 return -EINVAL;
8167
8168 if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]) {
8169 u32 tokln = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]);
8170
8171 tok = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]);
8172 tokens_size = tokln - sizeof(*tok);
8173
8174 if (!tok->len || tokens_size % tok->len)
8175 return -EINVAL;
Johannes Berg964dc9e2013-06-03 17:25:34 +02008176 if (!rdev->wiphy.wowlan->tcp->tok)
Johannes Berg2a0e0472013-01-23 22:57:40 +01008177 return -EINVAL;
Johannes Berg964dc9e2013-06-03 17:25:34 +02008178 if (tok->len > rdev->wiphy.wowlan->tcp->tok->max_len)
Johannes Berg2a0e0472013-01-23 22:57:40 +01008179 return -EINVAL;
Johannes Berg964dc9e2013-06-03 17:25:34 +02008180 if (tok->len < rdev->wiphy.wowlan->tcp->tok->min_len)
Johannes Berg2a0e0472013-01-23 22:57:40 +01008181 return -EINVAL;
Johannes Berg964dc9e2013-06-03 17:25:34 +02008182 if (tokens_size > rdev->wiphy.wowlan->tcp->tok->bufsize)
Johannes Berg2a0e0472013-01-23 22:57:40 +01008183 return -EINVAL;
8184 if (tok->offset + tok->len > data_size)
8185 return -EINVAL;
8186 }
8187
8188 if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]) {
8189 seq = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]);
Johannes Berg964dc9e2013-06-03 17:25:34 +02008190 if (!rdev->wiphy.wowlan->tcp->seq)
Johannes Berg2a0e0472013-01-23 22:57:40 +01008191 return -EINVAL;
8192 if (seq->len == 0 || seq->len > 4)
8193 return -EINVAL;
8194 if (seq->len + seq->offset > data_size)
8195 return -EINVAL;
8196 }
8197
8198 size = sizeof(*cfg);
8199 size += data_size;
8200 size += wake_size + wake_mask_size;
8201 size += tokens_size;
8202
8203 cfg = kzalloc(size, GFP_KERNEL);
8204 if (!cfg)
8205 return -ENOMEM;
8206 cfg->src = nla_get_be32(tb[NL80211_WOWLAN_TCP_SRC_IPV4]);
8207 cfg->dst = nla_get_be32(tb[NL80211_WOWLAN_TCP_DST_IPV4]);
8208 memcpy(cfg->dst_mac, nla_data(tb[NL80211_WOWLAN_TCP_DST_MAC]),
8209 ETH_ALEN);
8210 if (tb[NL80211_WOWLAN_TCP_SRC_PORT])
8211 port = nla_get_u16(tb[NL80211_WOWLAN_TCP_SRC_PORT]);
8212 else
8213 port = 0;
8214#ifdef CONFIG_INET
8215 /* allocate a socket and port for it and use it */
8216 err = __sock_create(wiphy_net(&rdev->wiphy), PF_INET, SOCK_STREAM,
8217 IPPROTO_TCP, &cfg->sock, 1);
8218 if (err) {
8219 kfree(cfg);
8220 return err;
8221 }
8222 if (inet_csk_get_port(cfg->sock->sk, port)) {
8223 sock_release(cfg->sock);
8224 kfree(cfg);
8225 return -EADDRINUSE;
8226 }
8227 cfg->src_port = inet_sk(cfg->sock->sk)->inet_num;
8228#else
8229 if (!port) {
8230 kfree(cfg);
8231 return -EINVAL;
8232 }
8233 cfg->src_port = port;
8234#endif
8235
8236 cfg->dst_port = nla_get_u16(tb[NL80211_WOWLAN_TCP_DST_PORT]);
8237 cfg->payload_len = data_size;
8238 cfg->payload = (u8 *)cfg + sizeof(*cfg) + tokens_size;
8239 memcpy((void *)cfg->payload,
8240 nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]),
8241 data_size);
8242 if (seq)
8243 cfg->payload_seq = *seq;
8244 cfg->data_interval = nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]);
8245 cfg->wake_len = wake_size;
8246 cfg->wake_data = (u8 *)cfg + sizeof(*cfg) + tokens_size + data_size;
8247 memcpy((void *)cfg->wake_data,
8248 nla_data(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]),
8249 wake_size);
8250 cfg->wake_mask = (u8 *)cfg + sizeof(*cfg) + tokens_size +
8251 data_size + wake_size;
8252 memcpy((void *)cfg->wake_mask,
8253 nla_data(tb[NL80211_WOWLAN_TCP_WAKE_MASK]),
8254 wake_mask_size);
8255 if (tok) {
8256 cfg->tokens_size = tokens_size;
8257 memcpy(&cfg->payload_tok, tok, sizeof(*tok) + tokens_size);
8258 }
8259
8260 trig->tcp = cfg;
8261
8262 return 0;
8263}
8264
Johannes Bergff1b6e62011-05-04 15:37:28 +02008265static int nl80211_set_wowlan(struct sk_buff *skb, struct genl_info *info)
8266{
8267 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8268 struct nlattr *tb[NUM_NL80211_WOWLAN_TRIG];
Johannes Bergff1b6e62011-05-04 15:37:28 +02008269 struct cfg80211_wowlan new_triggers = {};
Johannes Bergae33bd82012-07-12 16:25:02 +02008270 struct cfg80211_wowlan *ntrig;
Johannes Berg964dc9e2013-06-03 17:25:34 +02008271 const struct wiphy_wowlan_support *wowlan = rdev->wiphy.wowlan;
Johannes Bergff1b6e62011-05-04 15:37:28 +02008272 int err, i;
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008273 bool prev_enabled = rdev->wiphy.wowlan_config;
Johannes Bergff1b6e62011-05-04 15:37:28 +02008274
Johannes Berg964dc9e2013-06-03 17:25:34 +02008275 if (!wowlan)
Johannes Bergff1b6e62011-05-04 15:37:28 +02008276 return -EOPNOTSUPP;
8277
Johannes Bergae33bd82012-07-12 16:25:02 +02008278 if (!info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]) {
8279 cfg80211_rdev_free_wowlan(rdev);
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008280 rdev->wiphy.wowlan_config = NULL;
Johannes Bergae33bd82012-07-12 16:25:02 +02008281 goto set_wakeup;
8282 }
Johannes Bergff1b6e62011-05-04 15:37:28 +02008283
8284 err = nla_parse(tb, MAX_NL80211_WOWLAN_TRIG,
8285 nla_data(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]),
8286 nla_len(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]),
8287 nl80211_wowlan_policy);
8288 if (err)
8289 return err;
8290
8291 if (tb[NL80211_WOWLAN_TRIG_ANY]) {
8292 if (!(wowlan->flags & WIPHY_WOWLAN_ANY))
8293 return -EINVAL;
8294 new_triggers.any = true;
8295 }
8296
8297 if (tb[NL80211_WOWLAN_TRIG_DISCONNECT]) {
8298 if (!(wowlan->flags & WIPHY_WOWLAN_DISCONNECT))
8299 return -EINVAL;
8300 new_triggers.disconnect = true;
8301 }
8302
8303 if (tb[NL80211_WOWLAN_TRIG_MAGIC_PKT]) {
8304 if (!(wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT))
8305 return -EINVAL;
8306 new_triggers.magic_pkt = true;
8307 }
8308
Johannes Berg77dbbb12011-07-13 10:48:55 +02008309 if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED])
8310 return -EINVAL;
8311
8312 if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE]) {
8313 if (!(wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE))
8314 return -EINVAL;
8315 new_triggers.gtk_rekey_failure = true;
8316 }
8317
8318 if (tb[NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST]) {
8319 if (!(wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ))
8320 return -EINVAL;
8321 new_triggers.eap_identity_req = true;
8322 }
8323
8324 if (tb[NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE]) {
8325 if (!(wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE))
8326 return -EINVAL;
8327 new_triggers.four_way_handshake = true;
8328 }
8329
8330 if (tb[NL80211_WOWLAN_TRIG_RFKILL_RELEASE]) {
8331 if (!(wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE))
8332 return -EINVAL;
8333 new_triggers.rfkill_release = true;
8334 }
8335
Johannes Bergff1b6e62011-05-04 15:37:28 +02008336 if (tb[NL80211_WOWLAN_TRIG_PKT_PATTERN]) {
8337 struct nlattr *pat;
8338 int n_patterns = 0;
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08008339 int rem, pat_len, mask_len, pkt_offset;
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07008340 struct nlattr *pat_tb[NUM_NL80211_PKTPAT];
Johannes Bergff1b6e62011-05-04 15:37:28 +02008341
8342 nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN],
8343 rem)
8344 n_patterns++;
8345 if (n_patterns > wowlan->n_patterns)
8346 return -EINVAL;
8347
8348 new_triggers.patterns = kcalloc(n_patterns,
8349 sizeof(new_triggers.patterns[0]),
8350 GFP_KERNEL);
8351 if (!new_triggers.patterns)
8352 return -ENOMEM;
8353
8354 new_triggers.n_patterns = n_patterns;
8355 i = 0;
8356
8357 nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN],
8358 rem) {
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07008359 nla_parse(pat_tb, MAX_NL80211_PKTPAT, nla_data(pat),
8360 nla_len(pat), NULL);
Johannes Bergff1b6e62011-05-04 15:37:28 +02008361 err = -EINVAL;
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07008362 if (!pat_tb[NL80211_PKTPAT_MASK] ||
8363 !pat_tb[NL80211_PKTPAT_PATTERN])
Johannes Bergff1b6e62011-05-04 15:37:28 +02008364 goto error;
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07008365 pat_len = nla_len(pat_tb[NL80211_PKTPAT_PATTERN]);
Johannes Bergff1b6e62011-05-04 15:37:28 +02008366 mask_len = DIV_ROUND_UP(pat_len, 8);
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07008367 if (nla_len(pat_tb[NL80211_PKTPAT_MASK]) != mask_len)
Johannes Bergff1b6e62011-05-04 15:37:28 +02008368 goto error;
8369 if (pat_len > wowlan->pattern_max_len ||
8370 pat_len < wowlan->pattern_min_len)
8371 goto error;
8372
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07008373 if (!pat_tb[NL80211_PKTPAT_OFFSET])
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08008374 pkt_offset = 0;
8375 else
8376 pkt_offset = nla_get_u32(
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07008377 pat_tb[NL80211_PKTPAT_OFFSET]);
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08008378 if (pkt_offset > wowlan->max_pkt_offset)
8379 goto error;
8380 new_triggers.patterns[i].pkt_offset = pkt_offset;
8381
Johannes Bergff1b6e62011-05-04 15:37:28 +02008382 new_triggers.patterns[i].mask =
8383 kmalloc(mask_len + pat_len, GFP_KERNEL);
8384 if (!new_triggers.patterns[i].mask) {
8385 err = -ENOMEM;
8386 goto error;
8387 }
8388 new_triggers.patterns[i].pattern =
8389 new_triggers.patterns[i].mask + mask_len;
8390 memcpy(new_triggers.patterns[i].mask,
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07008391 nla_data(pat_tb[NL80211_PKTPAT_MASK]),
Johannes Bergff1b6e62011-05-04 15:37:28 +02008392 mask_len);
8393 new_triggers.patterns[i].pattern_len = pat_len;
8394 memcpy(new_triggers.patterns[i].pattern,
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07008395 nla_data(pat_tb[NL80211_PKTPAT_PATTERN]),
Johannes Bergff1b6e62011-05-04 15:37:28 +02008396 pat_len);
8397 i++;
8398 }
8399 }
8400
Johannes Berg2a0e0472013-01-23 22:57:40 +01008401 if (tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION]) {
8402 err = nl80211_parse_wowlan_tcp(
8403 rdev, tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION],
8404 &new_triggers);
8405 if (err)
8406 goto error;
8407 }
8408
Johannes Bergae33bd82012-07-12 16:25:02 +02008409 ntrig = kmemdup(&new_triggers, sizeof(new_triggers), GFP_KERNEL);
8410 if (!ntrig) {
8411 err = -ENOMEM;
8412 goto error;
Johannes Bergff1b6e62011-05-04 15:37:28 +02008413 }
Johannes Bergae33bd82012-07-12 16:25:02 +02008414 cfg80211_rdev_free_wowlan(rdev);
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008415 rdev->wiphy.wowlan_config = ntrig;
Johannes Bergff1b6e62011-05-04 15:37:28 +02008416
Johannes Bergae33bd82012-07-12 16:25:02 +02008417 set_wakeup:
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008418 if (rdev->ops->set_wakeup &&
8419 prev_enabled != !!rdev->wiphy.wowlan_config)
8420 rdev_set_wakeup(rdev, rdev->wiphy.wowlan_config);
Johannes Berg6d525632012-04-04 15:05:25 +02008421
Johannes Bergff1b6e62011-05-04 15:37:28 +02008422 return 0;
8423 error:
8424 for (i = 0; i < new_triggers.n_patterns; i++)
8425 kfree(new_triggers.patterns[i].mask);
8426 kfree(new_triggers.patterns);
Johannes Berg2a0e0472013-01-23 22:57:40 +01008427 if (new_triggers.tcp && new_triggers.tcp->sock)
8428 sock_release(new_triggers.tcp->sock);
8429 kfree(new_triggers.tcp);
Johannes Bergff1b6e62011-05-04 15:37:28 +02008430 return err;
8431}
Johannes Bergdfb89c52012-06-27 09:23:48 +02008432#endif
Johannes Bergff1b6e62011-05-04 15:37:28 +02008433
Amitkumar Karwarbe29b992013-06-28 11:51:26 -07008434static int nl80211_send_coalesce_rules(struct sk_buff *msg,
8435 struct cfg80211_registered_device *rdev)
8436{
8437 struct nlattr *nl_pats, *nl_pat, *nl_rule, *nl_rules;
8438 int i, j, pat_len;
8439 struct cfg80211_coalesce_rules *rule;
8440
8441 if (!rdev->coalesce->n_rules)
8442 return 0;
8443
8444 nl_rules = nla_nest_start(msg, NL80211_ATTR_COALESCE_RULE);
8445 if (!nl_rules)
8446 return -ENOBUFS;
8447
8448 for (i = 0; i < rdev->coalesce->n_rules; i++) {
8449 nl_rule = nla_nest_start(msg, i + 1);
8450 if (!nl_rule)
8451 return -ENOBUFS;
8452
8453 rule = &rdev->coalesce->rules[i];
8454 if (nla_put_u32(msg, NL80211_ATTR_COALESCE_RULE_DELAY,
8455 rule->delay))
8456 return -ENOBUFS;
8457
8458 if (nla_put_u32(msg, NL80211_ATTR_COALESCE_RULE_CONDITION,
8459 rule->condition))
8460 return -ENOBUFS;
8461
8462 nl_pats = nla_nest_start(msg,
8463 NL80211_ATTR_COALESCE_RULE_PKT_PATTERN);
8464 if (!nl_pats)
8465 return -ENOBUFS;
8466
8467 for (j = 0; j < rule->n_patterns; j++) {
8468 nl_pat = nla_nest_start(msg, j + 1);
8469 if (!nl_pat)
8470 return -ENOBUFS;
8471 pat_len = rule->patterns[j].pattern_len;
8472 if (nla_put(msg, NL80211_PKTPAT_MASK,
8473 DIV_ROUND_UP(pat_len, 8),
8474 rule->patterns[j].mask) ||
8475 nla_put(msg, NL80211_PKTPAT_PATTERN, pat_len,
8476 rule->patterns[j].pattern) ||
8477 nla_put_u32(msg, NL80211_PKTPAT_OFFSET,
8478 rule->patterns[j].pkt_offset))
8479 return -ENOBUFS;
8480 nla_nest_end(msg, nl_pat);
8481 }
8482 nla_nest_end(msg, nl_pats);
8483 nla_nest_end(msg, nl_rule);
8484 }
8485 nla_nest_end(msg, nl_rules);
8486
8487 return 0;
8488}
8489
8490static int nl80211_get_coalesce(struct sk_buff *skb, struct genl_info *info)
8491{
8492 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8493 struct sk_buff *msg;
8494 void *hdr;
8495
8496 if (!rdev->wiphy.coalesce)
8497 return -EOPNOTSUPP;
8498
8499 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
8500 if (!msg)
8501 return -ENOMEM;
8502
8503 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
8504 NL80211_CMD_GET_COALESCE);
8505 if (!hdr)
8506 goto nla_put_failure;
8507
8508 if (rdev->coalesce && nl80211_send_coalesce_rules(msg, rdev))
8509 goto nla_put_failure;
8510
8511 genlmsg_end(msg, hdr);
8512 return genlmsg_reply(msg, info);
8513
8514nla_put_failure:
8515 nlmsg_free(msg);
8516 return -ENOBUFS;
8517}
8518
8519void cfg80211_rdev_free_coalesce(struct cfg80211_registered_device *rdev)
8520{
8521 struct cfg80211_coalesce *coalesce = rdev->coalesce;
8522 int i, j;
8523 struct cfg80211_coalesce_rules *rule;
8524
8525 if (!coalesce)
8526 return;
8527
8528 for (i = 0; i < coalesce->n_rules; i++) {
8529 rule = &coalesce->rules[i];
8530 for (j = 0; j < rule->n_patterns; j++)
8531 kfree(rule->patterns[j].mask);
8532 kfree(rule->patterns);
8533 }
8534 kfree(coalesce->rules);
8535 kfree(coalesce);
8536 rdev->coalesce = NULL;
8537}
8538
8539static int nl80211_parse_coalesce_rule(struct cfg80211_registered_device *rdev,
8540 struct nlattr *rule,
8541 struct cfg80211_coalesce_rules *new_rule)
8542{
8543 int err, i;
8544 const struct wiphy_coalesce_support *coalesce = rdev->wiphy.coalesce;
8545 struct nlattr *tb[NUM_NL80211_ATTR_COALESCE_RULE], *pat;
8546 int rem, pat_len, mask_len, pkt_offset, n_patterns = 0;
8547 struct nlattr *pat_tb[NUM_NL80211_PKTPAT];
8548
8549 err = nla_parse(tb, NL80211_ATTR_COALESCE_RULE_MAX, nla_data(rule),
8550 nla_len(rule), nl80211_coalesce_policy);
8551 if (err)
8552 return err;
8553
8554 if (tb[NL80211_ATTR_COALESCE_RULE_DELAY])
8555 new_rule->delay =
8556 nla_get_u32(tb[NL80211_ATTR_COALESCE_RULE_DELAY]);
8557 if (new_rule->delay > coalesce->max_delay)
8558 return -EINVAL;
8559
8560 if (tb[NL80211_ATTR_COALESCE_RULE_CONDITION])
8561 new_rule->condition =
8562 nla_get_u32(tb[NL80211_ATTR_COALESCE_RULE_CONDITION]);
8563 if (new_rule->condition != NL80211_COALESCE_CONDITION_MATCH &&
8564 new_rule->condition != NL80211_COALESCE_CONDITION_NO_MATCH)
8565 return -EINVAL;
8566
8567 if (!tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN])
8568 return -EINVAL;
8569
8570 nla_for_each_nested(pat, tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN],
8571 rem)
8572 n_patterns++;
8573 if (n_patterns > coalesce->n_patterns)
8574 return -EINVAL;
8575
8576 new_rule->patterns = kcalloc(n_patterns, sizeof(new_rule->patterns[0]),
8577 GFP_KERNEL);
8578 if (!new_rule->patterns)
8579 return -ENOMEM;
8580
8581 new_rule->n_patterns = n_patterns;
8582 i = 0;
8583
8584 nla_for_each_nested(pat, tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN],
8585 rem) {
8586 nla_parse(pat_tb, MAX_NL80211_PKTPAT, nla_data(pat),
8587 nla_len(pat), NULL);
8588 if (!pat_tb[NL80211_PKTPAT_MASK] ||
8589 !pat_tb[NL80211_PKTPAT_PATTERN])
8590 return -EINVAL;
8591 pat_len = nla_len(pat_tb[NL80211_PKTPAT_PATTERN]);
8592 mask_len = DIV_ROUND_UP(pat_len, 8);
8593 if (nla_len(pat_tb[NL80211_PKTPAT_MASK]) != mask_len)
8594 return -EINVAL;
8595 if (pat_len > coalesce->pattern_max_len ||
8596 pat_len < coalesce->pattern_min_len)
8597 return -EINVAL;
8598
8599 if (!pat_tb[NL80211_PKTPAT_OFFSET])
8600 pkt_offset = 0;
8601 else
8602 pkt_offset = nla_get_u32(pat_tb[NL80211_PKTPAT_OFFSET]);
8603 if (pkt_offset > coalesce->max_pkt_offset)
8604 return -EINVAL;
8605 new_rule->patterns[i].pkt_offset = pkt_offset;
8606
8607 new_rule->patterns[i].mask =
8608 kmalloc(mask_len + pat_len, GFP_KERNEL);
8609 if (!new_rule->patterns[i].mask)
8610 return -ENOMEM;
8611 new_rule->patterns[i].pattern =
8612 new_rule->patterns[i].mask + mask_len;
8613 memcpy(new_rule->patterns[i].mask,
8614 nla_data(pat_tb[NL80211_PKTPAT_MASK]), mask_len);
8615 new_rule->patterns[i].pattern_len = pat_len;
8616 memcpy(new_rule->patterns[i].pattern,
8617 nla_data(pat_tb[NL80211_PKTPAT_PATTERN]), pat_len);
8618 i++;
8619 }
8620
8621 return 0;
8622}
8623
8624static int nl80211_set_coalesce(struct sk_buff *skb, struct genl_info *info)
8625{
8626 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8627 const struct wiphy_coalesce_support *coalesce = rdev->wiphy.coalesce;
8628 struct cfg80211_coalesce new_coalesce = {};
8629 struct cfg80211_coalesce *n_coalesce;
8630 int err, rem_rule, n_rules = 0, i, j;
8631 struct nlattr *rule;
8632 struct cfg80211_coalesce_rules *tmp_rule;
8633
8634 if (!rdev->wiphy.coalesce || !rdev->ops->set_coalesce)
8635 return -EOPNOTSUPP;
8636
8637 if (!info->attrs[NL80211_ATTR_COALESCE_RULE]) {
8638 cfg80211_rdev_free_coalesce(rdev);
8639 rdev->ops->set_coalesce(&rdev->wiphy, NULL);
8640 return 0;
8641 }
8642
8643 nla_for_each_nested(rule, info->attrs[NL80211_ATTR_COALESCE_RULE],
8644 rem_rule)
8645 n_rules++;
8646 if (n_rules > coalesce->n_rules)
8647 return -EINVAL;
8648
8649 new_coalesce.rules = kcalloc(n_rules, sizeof(new_coalesce.rules[0]),
8650 GFP_KERNEL);
8651 if (!new_coalesce.rules)
8652 return -ENOMEM;
8653
8654 new_coalesce.n_rules = n_rules;
8655 i = 0;
8656
8657 nla_for_each_nested(rule, info->attrs[NL80211_ATTR_COALESCE_RULE],
8658 rem_rule) {
8659 err = nl80211_parse_coalesce_rule(rdev, rule,
8660 &new_coalesce.rules[i]);
8661 if (err)
8662 goto error;
8663
8664 i++;
8665 }
8666
8667 err = rdev->ops->set_coalesce(&rdev->wiphy, &new_coalesce);
8668 if (err)
8669 goto error;
8670
8671 n_coalesce = kmemdup(&new_coalesce, sizeof(new_coalesce), GFP_KERNEL);
8672 if (!n_coalesce) {
8673 err = -ENOMEM;
8674 goto error;
8675 }
8676 cfg80211_rdev_free_coalesce(rdev);
8677 rdev->coalesce = n_coalesce;
8678
8679 return 0;
8680error:
8681 for (i = 0; i < new_coalesce.n_rules; i++) {
8682 tmp_rule = &new_coalesce.rules[i];
8683 for (j = 0; j < tmp_rule->n_patterns; j++)
8684 kfree(tmp_rule->patterns[j].mask);
8685 kfree(tmp_rule->patterns);
8686 }
8687 kfree(new_coalesce.rules);
8688
8689 return err;
8690}
8691
Johannes Berge5497d72011-07-05 16:35:40 +02008692static int nl80211_set_rekey_data(struct sk_buff *skb, struct genl_info *info)
8693{
8694 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8695 struct net_device *dev = info->user_ptr[1];
8696 struct wireless_dev *wdev = dev->ieee80211_ptr;
8697 struct nlattr *tb[NUM_NL80211_REKEY_DATA];
8698 struct cfg80211_gtk_rekey_data rekey_data;
8699 int err;
8700
8701 if (!info->attrs[NL80211_ATTR_REKEY_DATA])
8702 return -EINVAL;
8703
8704 err = nla_parse(tb, MAX_NL80211_REKEY_DATA,
8705 nla_data(info->attrs[NL80211_ATTR_REKEY_DATA]),
8706 nla_len(info->attrs[NL80211_ATTR_REKEY_DATA]),
8707 nl80211_rekey_policy);
8708 if (err)
8709 return err;
8710
8711 if (nla_len(tb[NL80211_REKEY_DATA_REPLAY_CTR]) != NL80211_REPLAY_CTR_LEN)
8712 return -ERANGE;
8713 if (nla_len(tb[NL80211_REKEY_DATA_KEK]) != NL80211_KEK_LEN)
8714 return -ERANGE;
8715 if (nla_len(tb[NL80211_REKEY_DATA_KCK]) != NL80211_KCK_LEN)
8716 return -ERANGE;
8717
8718 memcpy(rekey_data.kek, nla_data(tb[NL80211_REKEY_DATA_KEK]),
8719 NL80211_KEK_LEN);
8720 memcpy(rekey_data.kck, nla_data(tb[NL80211_REKEY_DATA_KCK]),
8721 NL80211_KCK_LEN);
8722 memcpy(rekey_data.replay_ctr,
8723 nla_data(tb[NL80211_REKEY_DATA_REPLAY_CTR]),
8724 NL80211_REPLAY_CTR_LEN);
8725
8726 wdev_lock(wdev);
8727 if (!wdev->current_bss) {
8728 err = -ENOTCONN;
8729 goto out;
8730 }
8731
8732 if (!rdev->ops->set_rekey_data) {
8733 err = -EOPNOTSUPP;
8734 goto out;
8735 }
8736
Hila Gonene35e4d22012-06-27 17:19:42 +03008737 err = rdev_set_rekey_data(rdev, dev, &rekey_data);
Johannes Berge5497d72011-07-05 16:35:40 +02008738 out:
8739 wdev_unlock(wdev);
8740 return err;
8741}
8742
Johannes Berg28946da2011-11-04 11:18:12 +01008743static int nl80211_register_unexpected_frame(struct sk_buff *skb,
8744 struct genl_info *info)
8745{
8746 struct net_device *dev = info->user_ptr[1];
8747 struct wireless_dev *wdev = dev->ieee80211_ptr;
8748
8749 if (wdev->iftype != NL80211_IFTYPE_AP &&
8750 wdev->iftype != NL80211_IFTYPE_P2P_GO)
8751 return -EINVAL;
8752
Eric W. Biederman15e47302012-09-07 20:12:54 +00008753 if (wdev->ap_unexpected_nlportid)
Johannes Berg28946da2011-11-04 11:18:12 +01008754 return -EBUSY;
8755
Eric W. Biederman15e47302012-09-07 20:12:54 +00008756 wdev->ap_unexpected_nlportid = info->snd_portid;
Johannes Berg28946da2011-11-04 11:18:12 +01008757 return 0;
8758}
8759
Johannes Berg7f6cf312011-11-04 11:18:15 +01008760static int nl80211_probe_client(struct sk_buff *skb,
8761 struct genl_info *info)
8762{
8763 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8764 struct net_device *dev = info->user_ptr[1];
8765 struct wireless_dev *wdev = dev->ieee80211_ptr;
8766 struct sk_buff *msg;
8767 void *hdr;
8768 const u8 *addr;
8769 u64 cookie;
8770 int err;
8771
8772 if (wdev->iftype != NL80211_IFTYPE_AP &&
8773 wdev->iftype != NL80211_IFTYPE_P2P_GO)
8774 return -EOPNOTSUPP;
8775
8776 if (!info->attrs[NL80211_ATTR_MAC])
8777 return -EINVAL;
8778
8779 if (!rdev->ops->probe_client)
8780 return -EOPNOTSUPP;
8781
8782 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
8783 if (!msg)
8784 return -ENOMEM;
8785
Eric W. Biederman15e47302012-09-07 20:12:54 +00008786 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berg7f6cf312011-11-04 11:18:15 +01008787 NL80211_CMD_PROBE_CLIENT);
Dan Carpentercb35fba2013-08-14 14:50:01 +03008788 if (!hdr) {
8789 err = -ENOBUFS;
Johannes Berg7f6cf312011-11-04 11:18:15 +01008790 goto free_msg;
8791 }
8792
8793 addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
8794
Hila Gonene35e4d22012-06-27 17:19:42 +03008795 err = rdev_probe_client(rdev, dev, addr, &cookie);
Johannes Berg7f6cf312011-11-04 11:18:15 +01008796 if (err)
8797 goto free_msg;
8798
David S. Miller9360ffd2012-03-29 04:41:26 -04008799 if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie))
8800 goto nla_put_failure;
Johannes Berg7f6cf312011-11-04 11:18:15 +01008801
8802 genlmsg_end(msg, hdr);
8803
8804 return genlmsg_reply(msg, info);
8805
8806 nla_put_failure:
8807 err = -ENOBUFS;
8808 free_msg:
8809 nlmsg_free(msg);
8810 return err;
8811}
8812
Johannes Berg5e760232011-11-04 11:18:17 +01008813static int nl80211_register_beacons(struct sk_buff *skb, struct genl_info *info)
8814{
8815 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Ben Greear37c73b52012-10-26 14:49:25 -07008816 struct cfg80211_beacon_registration *reg, *nreg;
8817 int rv;
Johannes Berg5e760232011-11-04 11:18:17 +01008818
8819 if (!(rdev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS))
8820 return -EOPNOTSUPP;
8821
Ben Greear37c73b52012-10-26 14:49:25 -07008822 nreg = kzalloc(sizeof(*nreg), GFP_KERNEL);
8823 if (!nreg)
8824 return -ENOMEM;
Johannes Berg5e760232011-11-04 11:18:17 +01008825
Ben Greear37c73b52012-10-26 14:49:25 -07008826 /* First, check if already registered. */
8827 spin_lock_bh(&rdev->beacon_registrations_lock);
8828 list_for_each_entry(reg, &rdev->beacon_registrations, list) {
8829 if (reg->nlportid == info->snd_portid) {
8830 rv = -EALREADY;
8831 goto out_err;
8832 }
8833 }
8834 /* Add it to the list */
8835 nreg->nlportid = info->snd_portid;
8836 list_add(&nreg->list, &rdev->beacon_registrations);
8837
8838 spin_unlock_bh(&rdev->beacon_registrations_lock);
Johannes Berg5e760232011-11-04 11:18:17 +01008839
8840 return 0;
Ben Greear37c73b52012-10-26 14:49:25 -07008841out_err:
8842 spin_unlock_bh(&rdev->beacon_registrations_lock);
8843 kfree(nreg);
8844 return rv;
Johannes Berg5e760232011-11-04 11:18:17 +01008845}
8846
Johannes Berg98104fde2012-06-16 00:19:54 +02008847static int nl80211_start_p2p_device(struct sk_buff *skb, struct genl_info *info)
8848{
8849 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8850 struct wireless_dev *wdev = info->user_ptr[1];
8851 int err;
8852
8853 if (!rdev->ops->start_p2p_device)
8854 return -EOPNOTSUPP;
8855
8856 if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE)
8857 return -EOPNOTSUPP;
8858
8859 if (wdev->p2p_started)
8860 return 0;
8861
Johannes Berg98104fde2012-06-16 00:19:54 +02008862 err = cfg80211_can_add_interface(rdev, wdev->iftype);
Johannes Berg98104fde2012-06-16 00:19:54 +02008863 if (err)
8864 return err;
8865
Johannes Bergeeb126e2012-10-23 15:16:50 +02008866 err = rdev_start_p2p_device(rdev, wdev);
Johannes Berg98104fde2012-06-16 00:19:54 +02008867 if (err)
8868 return err;
8869
8870 wdev->p2p_started = true;
Johannes Berg98104fde2012-06-16 00:19:54 +02008871 rdev->opencount++;
Johannes Berg98104fde2012-06-16 00:19:54 +02008872
8873 return 0;
8874}
8875
8876static int nl80211_stop_p2p_device(struct sk_buff *skb, struct genl_info *info)
8877{
8878 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8879 struct wireless_dev *wdev = info->user_ptr[1];
8880
8881 if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE)
8882 return -EOPNOTSUPP;
8883
8884 if (!rdev->ops->stop_p2p_device)
8885 return -EOPNOTSUPP;
8886
Johannes Bergf9f47522013-03-19 15:04:07 +01008887 cfg80211_stop_p2p_device(rdev, wdev);
Johannes Berg98104fde2012-06-16 00:19:54 +02008888
8889 return 0;
8890}
8891
Johannes Berg3713b4e2013-02-14 16:19:38 +01008892static int nl80211_get_protocol_features(struct sk_buff *skb,
8893 struct genl_info *info)
8894{
8895 void *hdr;
8896 struct sk_buff *msg;
8897
8898 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
8899 if (!msg)
8900 return -ENOMEM;
8901
8902 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
8903 NL80211_CMD_GET_PROTOCOL_FEATURES);
8904 if (!hdr)
8905 goto nla_put_failure;
8906
8907 if (nla_put_u32(msg, NL80211_ATTR_PROTOCOL_FEATURES,
8908 NL80211_PROTOCOL_FEATURE_SPLIT_WIPHY_DUMP))
8909 goto nla_put_failure;
8910
8911 genlmsg_end(msg, hdr);
8912 return genlmsg_reply(msg, info);
8913
8914 nla_put_failure:
8915 kfree_skb(msg);
8916 return -ENOBUFS;
8917}
8918
Jouni Malinen355199e2013-02-27 17:14:27 +02008919static int nl80211_update_ft_ies(struct sk_buff *skb, struct genl_info *info)
8920{
8921 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8922 struct cfg80211_update_ft_ies_params ft_params;
8923 struct net_device *dev = info->user_ptr[1];
8924
8925 if (!rdev->ops->update_ft_ies)
8926 return -EOPNOTSUPP;
8927
8928 if (!info->attrs[NL80211_ATTR_MDID] ||
8929 !is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
8930 return -EINVAL;
8931
8932 memset(&ft_params, 0, sizeof(ft_params));
8933 ft_params.md = nla_get_u16(info->attrs[NL80211_ATTR_MDID]);
8934 ft_params.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
8935 ft_params.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
8936
8937 return rdev_update_ft_ies(rdev, dev, &ft_params);
8938}
8939
Arend van Spriel5de17982013-04-18 15:49:00 +02008940static int nl80211_crit_protocol_start(struct sk_buff *skb,
8941 struct genl_info *info)
8942{
8943 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8944 struct wireless_dev *wdev = info->user_ptr[1];
8945 enum nl80211_crit_proto_id proto = NL80211_CRIT_PROTO_UNSPEC;
8946 u16 duration;
8947 int ret;
8948
8949 if (!rdev->ops->crit_proto_start)
8950 return -EOPNOTSUPP;
8951
8952 if (WARN_ON(!rdev->ops->crit_proto_stop))
8953 return -EINVAL;
8954
8955 if (rdev->crit_proto_nlportid)
8956 return -EBUSY;
8957
8958 /* determine protocol if provided */
8959 if (info->attrs[NL80211_ATTR_CRIT_PROT_ID])
8960 proto = nla_get_u16(info->attrs[NL80211_ATTR_CRIT_PROT_ID]);
8961
8962 if (proto >= NUM_NL80211_CRIT_PROTO)
8963 return -EINVAL;
8964
8965 /* timeout must be provided */
8966 if (!info->attrs[NL80211_ATTR_MAX_CRIT_PROT_DURATION])
8967 return -EINVAL;
8968
8969 duration =
8970 nla_get_u16(info->attrs[NL80211_ATTR_MAX_CRIT_PROT_DURATION]);
8971
8972 if (duration > NL80211_CRIT_PROTO_MAX_DURATION)
8973 return -ERANGE;
8974
8975 ret = rdev_crit_proto_start(rdev, wdev, proto, duration);
8976 if (!ret)
8977 rdev->crit_proto_nlportid = info->snd_portid;
8978
8979 return ret;
8980}
8981
8982static int nl80211_crit_protocol_stop(struct sk_buff *skb,
8983 struct genl_info *info)
8984{
8985 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8986 struct wireless_dev *wdev = info->user_ptr[1];
8987
8988 if (!rdev->ops->crit_proto_stop)
8989 return -EOPNOTSUPP;
8990
8991 if (rdev->crit_proto_nlportid) {
8992 rdev->crit_proto_nlportid = 0;
8993 rdev_crit_proto_stop(rdev, wdev);
8994 }
8995 return 0;
8996}
8997
Johannes Bergad7e7182013-11-13 13:37:47 +01008998static int nl80211_vendor_cmd(struct sk_buff *skb, struct genl_info *info)
8999{
9000 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9001 struct wireless_dev *wdev =
9002 __cfg80211_wdev_from_attrs(genl_info_net(info), info->attrs);
9003 int i, err;
9004 u32 vid, subcmd;
9005
9006 if (!rdev->wiphy.vendor_commands)
9007 return -EOPNOTSUPP;
9008
9009 if (IS_ERR(wdev)) {
9010 err = PTR_ERR(wdev);
9011 if (err != -EINVAL)
9012 return err;
9013 wdev = NULL;
9014 } else if (wdev->wiphy != &rdev->wiphy) {
9015 return -EINVAL;
9016 }
9017
9018 if (!info->attrs[NL80211_ATTR_VENDOR_ID] ||
9019 !info->attrs[NL80211_ATTR_VENDOR_SUBCMD])
9020 return -EINVAL;
9021
9022 vid = nla_get_u32(info->attrs[NL80211_ATTR_VENDOR_ID]);
9023 subcmd = nla_get_u32(info->attrs[NL80211_ATTR_VENDOR_SUBCMD]);
9024 for (i = 0; i < rdev->wiphy.n_vendor_commands; i++) {
9025 const struct wiphy_vendor_command *vcmd;
9026 void *data = NULL;
9027 int len = 0;
9028
9029 vcmd = &rdev->wiphy.vendor_commands[i];
9030
9031 if (vcmd->info.vendor_id != vid || vcmd->info.subcmd != subcmd)
9032 continue;
9033
9034 if (vcmd->flags & (WIPHY_VENDOR_CMD_NEED_WDEV |
9035 WIPHY_VENDOR_CMD_NEED_NETDEV)) {
9036 if (!wdev)
9037 return -EINVAL;
9038 if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_NETDEV &&
9039 !wdev->netdev)
9040 return -EINVAL;
9041
9042 if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_RUNNING) {
9043 if (wdev->netdev &&
9044 !netif_running(wdev->netdev))
9045 return -ENETDOWN;
9046 if (!wdev->netdev && !wdev->p2p_started)
9047 return -ENETDOWN;
9048 }
9049 } else {
9050 wdev = NULL;
9051 }
9052
9053 if (info->attrs[NL80211_ATTR_VENDOR_DATA]) {
9054 data = nla_data(info->attrs[NL80211_ATTR_VENDOR_DATA]);
9055 len = nla_len(info->attrs[NL80211_ATTR_VENDOR_DATA]);
9056 }
9057
9058 rdev->cur_cmd_info = info;
9059 err = rdev->wiphy.vendor_commands[i].doit(&rdev->wiphy, wdev,
9060 data, len);
9061 rdev->cur_cmd_info = NULL;
9062 return err;
9063 }
9064
9065 return -EOPNOTSUPP;
9066}
9067
9068struct sk_buff *__cfg80211_alloc_reply_skb(struct wiphy *wiphy,
9069 enum nl80211_commands cmd,
9070 enum nl80211_attrs attr,
9071 int approxlen)
9072{
9073 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
9074
9075 if (WARN_ON(!rdev->cur_cmd_info))
9076 return NULL;
9077
9078 return __cfg80211_alloc_vendor_skb(rdev, approxlen,
9079 rdev->cur_cmd_info->snd_portid,
9080 rdev->cur_cmd_info->snd_seq,
Johannes Berg567ffc32013-12-18 14:43:31 +01009081 cmd, attr, NULL, GFP_KERNEL);
Johannes Bergad7e7182013-11-13 13:37:47 +01009082}
9083EXPORT_SYMBOL(__cfg80211_alloc_reply_skb);
9084
9085int cfg80211_vendor_cmd_reply(struct sk_buff *skb)
9086{
9087 struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0];
9088 void *hdr = ((void **)skb->cb)[1];
9089 struct nlattr *data = ((void **)skb->cb)[2];
9090
9091 if (WARN_ON(!rdev->cur_cmd_info)) {
9092 kfree_skb(skb);
9093 return -EINVAL;
9094 }
9095
9096 nla_nest_end(skb, data);
9097 genlmsg_end(skb, hdr);
9098 return genlmsg_reply(skb, rdev->cur_cmd_info);
9099}
9100EXPORT_SYMBOL_GPL(cfg80211_vendor_cmd_reply);
9101
9102
Kyeyoon Parkfa9ffc72013-12-16 23:01:30 -08009103static int nl80211_set_qos_map(struct sk_buff *skb,
9104 struct genl_info *info)
9105{
9106 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9107 struct cfg80211_qos_map *qos_map = NULL;
9108 struct net_device *dev = info->user_ptr[1];
9109 u8 *pos, len, num_des, des_len, des;
9110 int ret;
9111
9112 if (!rdev->ops->set_qos_map)
9113 return -EOPNOTSUPP;
9114
9115 if (info->attrs[NL80211_ATTR_QOS_MAP]) {
9116 pos = nla_data(info->attrs[NL80211_ATTR_QOS_MAP]);
9117 len = nla_len(info->attrs[NL80211_ATTR_QOS_MAP]);
9118
9119 if (len % 2 || len < IEEE80211_QOS_MAP_LEN_MIN ||
9120 len > IEEE80211_QOS_MAP_LEN_MAX)
9121 return -EINVAL;
9122
9123 qos_map = kzalloc(sizeof(struct cfg80211_qos_map), GFP_KERNEL);
9124 if (!qos_map)
9125 return -ENOMEM;
9126
9127 num_des = (len - IEEE80211_QOS_MAP_LEN_MIN) >> 1;
9128 if (num_des) {
9129 des_len = num_des *
9130 sizeof(struct cfg80211_dscp_exception);
9131 memcpy(qos_map->dscp_exception, pos, des_len);
9132 qos_map->num_des = num_des;
9133 for (des = 0; des < num_des; des++) {
9134 if (qos_map->dscp_exception[des].up > 7) {
9135 kfree(qos_map);
9136 return -EINVAL;
9137 }
9138 }
9139 pos += des_len;
9140 }
9141 memcpy(qos_map->up, pos, IEEE80211_QOS_MAP_LEN_MIN);
9142 }
9143
9144 wdev_lock(dev->ieee80211_ptr);
9145 ret = nl80211_key_allowed(dev->ieee80211_ptr);
9146 if (!ret)
9147 ret = rdev_set_qos_map(rdev, dev, qos_map);
9148 wdev_unlock(dev->ieee80211_ptr);
9149
9150 kfree(qos_map);
9151 return ret;
9152}
9153
Johannes Berg4c476992010-10-04 21:36:35 +02009154#define NL80211_FLAG_NEED_WIPHY 0x01
9155#define NL80211_FLAG_NEED_NETDEV 0x02
9156#define NL80211_FLAG_NEED_RTNL 0x04
Johannes Berg41265712010-10-04 21:14:05 +02009157#define NL80211_FLAG_CHECK_NETDEV_UP 0x08
9158#define NL80211_FLAG_NEED_NETDEV_UP (NL80211_FLAG_NEED_NETDEV |\
9159 NL80211_FLAG_CHECK_NETDEV_UP)
Johannes Berg1bf614e2012-06-15 15:23:36 +02009160#define NL80211_FLAG_NEED_WDEV 0x10
Johannes Berg98104fde2012-06-16 00:19:54 +02009161/* If a netdev is associated, it must be UP, P2P must be started */
Johannes Berg1bf614e2012-06-15 15:23:36 +02009162#define NL80211_FLAG_NEED_WDEV_UP (NL80211_FLAG_NEED_WDEV |\
9163 NL80211_FLAG_CHECK_NETDEV_UP)
Johannes Berg4c476992010-10-04 21:36:35 +02009164
Johannes Bergf84f7712013-11-14 17:14:45 +01009165static int nl80211_pre_doit(const struct genl_ops *ops, struct sk_buff *skb,
Johannes Berg4c476992010-10-04 21:36:35 +02009166 struct genl_info *info)
9167{
9168 struct cfg80211_registered_device *rdev;
Johannes Berg89a54e42012-06-15 14:33:17 +02009169 struct wireless_dev *wdev;
Johannes Berg4c476992010-10-04 21:36:35 +02009170 struct net_device *dev;
Johannes Berg4c476992010-10-04 21:36:35 +02009171 bool rtnl = ops->internal_flags & NL80211_FLAG_NEED_RTNL;
9172
9173 if (rtnl)
9174 rtnl_lock();
9175
9176 if (ops->internal_flags & NL80211_FLAG_NEED_WIPHY) {
Johannes Berg4f7eff12012-06-15 14:14:22 +02009177 rdev = cfg80211_get_dev_from_info(genl_info_net(info), info);
Johannes Berg4c476992010-10-04 21:36:35 +02009178 if (IS_ERR(rdev)) {
9179 if (rtnl)
9180 rtnl_unlock();
9181 return PTR_ERR(rdev);
9182 }
9183 info->user_ptr[0] = rdev;
Johannes Berg1bf614e2012-06-15 15:23:36 +02009184 } else if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV ||
9185 ops->internal_flags & NL80211_FLAG_NEED_WDEV) {
Johannes Berg5fe231e2013-05-08 21:45:15 +02009186 ASSERT_RTNL();
9187
Johannes Berg89a54e42012-06-15 14:33:17 +02009188 wdev = __cfg80211_wdev_from_attrs(genl_info_net(info),
9189 info->attrs);
9190 if (IS_ERR(wdev)) {
Johannes Berg4c476992010-10-04 21:36:35 +02009191 if (rtnl)
9192 rtnl_unlock();
Johannes Berg89a54e42012-06-15 14:33:17 +02009193 return PTR_ERR(wdev);
Johannes Berg4c476992010-10-04 21:36:35 +02009194 }
Johannes Berg89a54e42012-06-15 14:33:17 +02009195
Johannes Berg89a54e42012-06-15 14:33:17 +02009196 dev = wdev->netdev;
9197 rdev = wiphy_to_dev(wdev->wiphy);
9198
Johannes Berg1bf614e2012-06-15 15:23:36 +02009199 if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV) {
9200 if (!dev) {
Johannes Berg1bf614e2012-06-15 15:23:36 +02009201 if (rtnl)
9202 rtnl_unlock();
9203 return -EINVAL;
9204 }
9205
9206 info->user_ptr[1] = dev;
9207 } else {
9208 info->user_ptr[1] = wdev;
Johannes Berg41265712010-10-04 21:14:05 +02009209 }
Johannes Berg89a54e42012-06-15 14:33:17 +02009210
Johannes Berg1bf614e2012-06-15 15:23:36 +02009211 if (dev) {
9212 if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP &&
9213 !netif_running(dev)) {
Johannes Berg1bf614e2012-06-15 15:23:36 +02009214 if (rtnl)
9215 rtnl_unlock();
9216 return -ENETDOWN;
9217 }
9218
9219 dev_hold(dev);
Johannes Berg98104fde2012-06-16 00:19:54 +02009220 } else if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP) {
9221 if (!wdev->p2p_started) {
Johannes Berg98104fde2012-06-16 00:19:54 +02009222 if (rtnl)
9223 rtnl_unlock();
9224 return -ENETDOWN;
9225 }
Johannes Berg1bf614e2012-06-15 15:23:36 +02009226 }
9227
Johannes Berg4c476992010-10-04 21:36:35 +02009228 info->user_ptr[0] = rdev;
Johannes Berg4c476992010-10-04 21:36:35 +02009229 }
9230
9231 return 0;
9232}
9233
Johannes Bergf84f7712013-11-14 17:14:45 +01009234static void nl80211_post_doit(const struct genl_ops *ops, struct sk_buff *skb,
Johannes Berg4c476992010-10-04 21:36:35 +02009235 struct genl_info *info)
9236{
Johannes Berg1bf614e2012-06-15 15:23:36 +02009237 if (info->user_ptr[1]) {
9238 if (ops->internal_flags & NL80211_FLAG_NEED_WDEV) {
9239 struct wireless_dev *wdev = info->user_ptr[1];
9240
9241 if (wdev->netdev)
9242 dev_put(wdev->netdev);
9243 } else {
9244 dev_put(info->user_ptr[1]);
9245 }
9246 }
Johannes Berg4c476992010-10-04 21:36:35 +02009247 if (ops->internal_flags & NL80211_FLAG_NEED_RTNL)
9248 rtnl_unlock();
9249}
9250
Johannes Berg4534de82013-11-14 17:14:46 +01009251static const struct genl_ops nl80211_ops[] = {
Johannes Berg55682962007-09-20 13:09:35 -04009252 {
9253 .cmd = NL80211_CMD_GET_WIPHY,
9254 .doit = nl80211_get_wiphy,
9255 .dumpit = nl80211_dump_wiphy,
Johannes Berg86e8cf92013-06-19 10:57:22 +02009256 .done = nl80211_dump_wiphy_done,
Johannes Berg55682962007-09-20 13:09:35 -04009257 .policy = nl80211_policy,
9258 /* can be retrieved by unprivileged users */
Johannes Berg5fe231e2013-05-08 21:45:15 +02009259 .internal_flags = NL80211_FLAG_NEED_WIPHY |
9260 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -04009261 },
9262 {
9263 .cmd = NL80211_CMD_SET_WIPHY,
9264 .doit = nl80211_set_wiphy,
9265 .policy = nl80211_policy,
9266 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02009267 .internal_flags = NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -04009268 },
9269 {
9270 .cmd = NL80211_CMD_GET_INTERFACE,
9271 .doit = nl80211_get_interface,
9272 .dumpit = nl80211_dump_interface,
9273 .policy = nl80211_policy,
9274 /* can be retrieved by unprivileged users */
Johannes Berg5fe231e2013-05-08 21:45:15 +02009275 .internal_flags = NL80211_FLAG_NEED_WDEV |
9276 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -04009277 },
9278 {
9279 .cmd = NL80211_CMD_SET_INTERFACE,
9280 .doit = nl80211_set_interface,
9281 .policy = nl80211_policy,
9282 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02009283 .internal_flags = NL80211_FLAG_NEED_NETDEV |
9284 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -04009285 },
9286 {
9287 .cmd = NL80211_CMD_NEW_INTERFACE,
9288 .doit = nl80211_new_interface,
9289 .policy = nl80211_policy,
9290 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02009291 .internal_flags = NL80211_FLAG_NEED_WIPHY |
9292 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -04009293 },
9294 {
9295 .cmd = NL80211_CMD_DEL_INTERFACE,
9296 .doit = nl80211_del_interface,
9297 .policy = nl80211_policy,
9298 .flags = GENL_ADMIN_PERM,
Johannes Berg84efbb82012-06-16 00:00:26 +02009299 .internal_flags = NL80211_FLAG_NEED_WDEV |
Johannes Berg4c476992010-10-04 21:36:35 +02009300 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -04009301 },
Johannes Berg41ade002007-12-19 02:03:29 +01009302 {
9303 .cmd = NL80211_CMD_GET_KEY,
9304 .doit = nl80211_get_key,
9305 .policy = nl80211_policy,
9306 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02009307 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009308 NL80211_FLAG_NEED_RTNL,
Johannes Berg41ade002007-12-19 02:03:29 +01009309 },
9310 {
9311 .cmd = NL80211_CMD_SET_KEY,
9312 .doit = nl80211_set_key,
9313 .policy = nl80211_policy,
9314 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02009315 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009316 NL80211_FLAG_NEED_RTNL,
Johannes Berg41ade002007-12-19 02:03:29 +01009317 },
9318 {
9319 .cmd = NL80211_CMD_NEW_KEY,
9320 .doit = nl80211_new_key,
9321 .policy = nl80211_policy,
9322 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02009323 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009324 NL80211_FLAG_NEED_RTNL,
Johannes Berg41ade002007-12-19 02:03:29 +01009325 },
9326 {
9327 .cmd = NL80211_CMD_DEL_KEY,
9328 .doit = nl80211_del_key,
9329 .policy = nl80211_policy,
9330 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02009331 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009332 NL80211_FLAG_NEED_RTNL,
Johannes Berg41ade002007-12-19 02:03:29 +01009333 },
Johannes Berged1b6cc2007-12-19 02:03:32 +01009334 {
9335 .cmd = NL80211_CMD_SET_BEACON,
9336 .policy = nl80211_policy,
9337 .flags = GENL_ADMIN_PERM,
Johannes Berg88600202012-02-13 15:17:18 +01009338 .doit = nl80211_set_beacon,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02009339 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009340 NL80211_FLAG_NEED_RTNL,
Johannes Berged1b6cc2007-12-19 02:03:32 +01009341 },
9342 {
Johannes Berg88600202012-02-13 15:17:18 +01009343 .cmd = NL80211_CMD_START_AP,
Johannes Berged1b6cc2007-12-19 02:03:32 +01009344 .policy = nl80211_policy,
9345 .flags = GENL_ADMIN_PERM,
Johannes Berg88600202012-02-13 15:17:18 +01009346 .doit = nl80211_start_ap,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02009347 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009348 NL80211_FLAG_NEED_RTNL,
Johannes Berged1b6cc2007-12-19 02:03:32 +01009349 },
9350 {
Johannes Berg88600202012-02-13 15:17:18 +01009351 .cmd = NL80211_CMD_STOP_AP,
Johannes Berged1b6cc2007-12-19 02:03:32 +01009352 .policy = nl80211_policy,
9353 .flags = GENL_ADMIN_PERM,
Johannes Berg88600202012-02-13 15:17:18 +01009354 .doit = nl80211_stop_ap,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02009355 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009356 NL80211_FLAG_NEED_RTNL,
Johannes Berged1b6cc2007-12-19 02:03:32 +01009357 },
Johannes Berg5727ef12007-12-19 02:03:34 +01009358 {
9359 .cmd = NL80211_CMD_GET_STATION,
9360 .doit = nl80211_get_station,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01009361 .dumpit = nl80211_dump_station,
Johannes Berg5727ef12007-12-19 02:03:34 +01009362 .policy = nl80211_policy,
Johannes Berg4c476992010-10-04 21:36:35 +02009363 .internal_flags = NL80211_FLAG_NEED_NETDEV |
9364 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +01009365 },
9366 {
9367 .cmd = NL80211_CMD_SET_STATION,
9368 .doit = nl80211_set_station,
9369 .policy = nl80211_policy,
9370 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02009371 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009372 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +01009373 },
9374 {
9375 .cmd = NL80211_CMD_NEW_STATION,
9376 .doit = nl80211_new_station,
9377 .policy = nl80211_policy,
9378 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02009379 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009380 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +01009381 },
9382 {
9383 .cmd = NL80211_CMD_DEL_STATION,
9384 .doit = nl80211_del_station,
9385 .policy = nl80211_policy,
9386 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02009387 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009388 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +01009389 },
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01009390 {
9391 .cmd = NL80211_CMD_GET_MPATH,
9392 .doit = nl80211_get_mpath,
9393 .dumpit = nl80211_dump_mpath,
9394 .policy = nl80211_policy,
9395 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02009396 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009397 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01009398 },
9399 {
9400 .cmd = NL80211_CMD_SET_MPATH,
9401 .doit = nl80211_set_mpath,
9402 .policy = nl80211_policy,
9403 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02009404 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009405 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01009406 },
9407 {
9408 .cmd = NL80211_CMD_NEW_MPATH,
9409 .doit = nl80211_new_mpath,
9410 .policy = nl80211_policy,
9411 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02009412 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009413 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01009414 },
9415 {
9416 .cmd = NL80211_CMD_DEL_MPATH,
9417 .doit = nl80211_del_mpath,
9418 .policy = nl80211_policy,
9419 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02009420 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009421 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01009422 },
Jouni Malinen9f1ba902008-08-07 20:07:01 +03009423 {
9424 .cmd = NL80211_CMD_SET_BSS,
9425 .doit = nl80211_set_bss,
9426 .policy = nl80211_policy,
9427 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02009428 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009429 NL80211_FLAG_NEED_RTNL,
Jouni Malinen9f1ba902008-08-07 20:07:01 +03009430 },
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07009431 {
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08009432 .cmd = NL80211_CMD_GET_REG,
9433 .doit = nl80211_get_reg,
9434 .policy = nl80211_policy,
Johannes Berg5fe231e2013-05-08 21:45:15 +02009435 .internal_flags = NL80211_FLAG_NEED_RTNL,
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08009436 /* can be retrieved by unprivileged users */
9437 },
9438 {
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07009439 .cmd = NL80211_CMD_SET_REG,
9440 .doit = nl80211_set_reg,
9441 .policy = nl80211_policy,
9442 .flags = GENL_ADMIN_PERM,
Johannes Berg5fe231e2013-05-08 21:45:15 +02009443 .internal_flags = NL80211_FLAG_NEED_RTNL,
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07009444 },
9445 {
9446 .cmd = NL80211_CMD_REQ_SET_REG,
9447 .doit = nl80211_req_set_reg,
9448 .policy = nl80211_policy,
9449 .flags = GENL_ADMIN_PERM,
9450 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07009451 {
Javier Cardona24bdd9f2010-12-16 17:37:48 -08009452 .cmd = NL80211_CMD_GET_MESH_CONFIG,
9453 .doit = nl80211_get_mesh_config,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07009454 .policy = nl80211_policy,
9455 /* can be retrieved by unprivileged users */
Johannes Berg2b5f8b02012-04-02 10:51:55 +02009456 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009457 NL80211_FLAG_NEED_RTNL,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07009458 },
9459 {
Javier Cardona24bdd9f2010-12-16 17:37:48 -08009460 .cmd = NL80211_CMD_SET_MESH_CONFIG,
9461 .doit = nl80211_update_mesh_config,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07009462 .policy = nl80211_policy,
9463 .flags = GENL_ADMIN_PERM,
Johannes Berg29cbe682010-12-03 09:20:44 +01009464 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009465 NL80211_FLAG_NEED_RTNL,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07009466 },
Jouni Malinen9aed3cc2009-01-13 16:03:29 +02009467 {
Johannes Berg2a519312009-02-10 21:25:55 +01009468 .cmd = NL80211_CMD_TRIGGER_SCAN,
9469 .doit = nl80211_trigger_scan,
9470 .policy = nl80211_policy,
9471 .flags = GENL_ADMIN_PERM,
Johannes Bergfd014282012-06-18 19:17:03 +02009472 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009473 NL80211_FLAG_NEED_RTNL,
Johannes Berg2a519312009-02-10 21:25:55 +01009474 },
9475 {
9476 .cmd = NL80211_CMD_GET_SCAN,
9477 .policy = nl80211_policy,
9478 .dumpit = nl80211_dump_scan,
9479 },
Jouni Malinen636a5d32009-03-19 13:39:22 +02009480 {
Luciano Coelho807f8a82011-05-11 17:09:35 +03009481 .cmd = NL80211_CMD_START_SCHED_SCAN,
9482 .doit = nl80211_start_sched_scan,
9483 .policy = nl80211_policy,
9484 .flags = GENL_ADMIN_PERM,
9485 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
9486 NL80211_FLAG_NEED_RTNL,
9487 },
9488 {
9489 .cmd = NL80211_CMD_STOP_SCHED_SCAN,
9490 .doit = nl80211_stop_sched_scan,
9491 .policy = nl80211_policy,
9492 .flags = GENL_ADMIN_PERM,
9493 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
9494 NL80211_FLAG_NEED_RTNL,
9495 },
9496 {
Jouni Malinen636a5d32009-03-19 13:39:22 +02009497 .cmd = NL80211_CMD_AUTHENTICATE,
9498 .doit = nl80211_authenticate,
9499 .policy = nl80211_policy,
9500 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02009501 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009502 NL80211_FLAG_NEED_RTNL,
Jouni Malinen636a5d32009-03-19 13:39:22 +02009503 },
9504 {
9505 .cmd = NL80211_CMD_ASSOCIATE,
9506 .doit = nl80211_associate,
9507 .policy = nl80211_policy,
9508 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02009509 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009510 NL80211_FLAG_NEED_RTNL,
Jouni Malinen636a5d32009-03-19 13:39:22 +02009511 },
9512 {
9513 .cmd = NL80211_CMD_DEAUTHENTICATE,
9514 .doit = nl80211_deauthenticate,
9515 .policy = nl80211_policy,
9516 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02009517 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009518 NL80211_FLAG_NEED_RTNL,
Jouni Malinen636a5d32009-03-19 13:39:22 +02009519 },
9520 {
9521 .cmd = NL80211_CMD_DISASSOCIATE,
9522 .doit = nl80211_disassociate,
9523 .policy = nl80211_policy,
9524 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02009525 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009526 NL80211_FLAG_NEED_RTNL,
Jouni Malinen636a5d32009-03-19 13:39:22 +02009527 },
Johannes Berg04a773a2009-04-19 21:24:32 +02009528 {
9529 .cmd = NL80211_CMD_JOIN_IBSS,
9530 .doit = nl80211_join_ibss,
9531 .policy = nl80211_policy,
9532 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02009533 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009534 NL80211_FLAG_NEED_RTNL,
Johannes Berg04a773a2009-04-19 21:24:32 +02009535 },
9536 {
9537 .cmd = NL80211_CMD_LEAVE_IBSS,
9538 .doit = nl80211_leave_ibss,
9539 .policy = nl80211_policy,
9540 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02009541 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009542 NL80211_FLAG_NEED_RTNL,
Johannes Berg04a773a2009-04-19 21:24:32 +02009543 },
Johannes Bergaff89a92009-07-01 21:26:51 +02009544#ifdef CONFIG_NL80211_TESTMODE
9545 {
9546 .cmd = NL80211_CMD_TESTMODE,
9547 .doit = nl80211_testmode_do,
Wey-Yi Guy71063f02011-05-20 09:05:54 -07009548 .dumpit = nl80211_testmode_dump,
Johannes Bergaff89a92009-07-01 21:26:51 +02009549 .policy = nl80211_policy,
9550 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02009551 .internal_flags = NL80211_FLAG_NEED_WIPHY |
9552 NL80211_FLAG_NEED_RTNL,
Johannes Bergaff89a92009-07-01 21:26:51 +02009553 },
9554#endif
Samuel Ortizb23aa672009-07-01 21:26:54 +02009555 {
9556 .cmd = NL80211_CMD_CONNECT,
9557 .doit = nl80211_connect,
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,
Samuel Ortizb23aa672009-07-01 21:26:54 +02009562 },
9563 {
9564 .cmd = NL80211_CMD_DISCONNECT,
9565 .doit = nl80211_disconnect,
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,
Samuel Ortizb23aa672009-07-01 21:26:54 +02009570 },
Johannes Berg463d0182009-07-14 00:33:35 +02009571 {
9572 .cmd = NL80211_CMD_SET_WIPHY_NETNS,
9573 .doit = nl80211_wiphy_netns,
9574 .policy = nl80211_policy,
9575 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02009576 .internal_flags = NL80211_FLAG_NEED_WIPHY |
9577 NL80211_FLAG_NEED_RTNL,
Johannes Berg463d0182009-07-14 00:33:35 +02009578 },
Holger Schurig61fa7132009-11-11 12:25:40 +01009579 {
9580 .cmd = NL80211_CMD_GET_SURVEY,
9581 .policy = nl80211_policy,
9582 .dumpit = nl80211_dump_survey,
9583 },
Samuel Ortiz67fbb162009-11-24 23:59:15 +01009584 {
9585 .cmd = NL80211_CMD_SET_PMKSA,
9586 .doit = nl80211_setdel_pmksa,
9587 .policy = nl80211_policy,
9588 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02009589 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009590 NL80211_FLAG_NEED_RTNL,
Samuel Ortiz67fbb162009-11-24 23:59:15 +01009591 },
9592 {
9593 .cmd = NL80211_CMD_DEL_PMKSA,
9594 .doit = nl80211_setdel_pmksa,
9595 .policy = nl80211_policy,
9596 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02009597 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009598 NL80211_FLAG_NEED_RTNL,
Samuel Ortiz67fbb162009-11-24 23:59:15 +01009599 },
9600 {
9601 .cmd = NL80211_CMD_FLUSH_PMKSA,
9602 .doit = nl80211_flush_pmksa,
9603 .policy = nl80211_policy,
9604 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02009605 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009606 NL80211_FLAG_NEED_RTNL,
Samuel Ortiz67fbb162009-11-24 23:59:15 +01009607 },
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009608 {
9609 .cmd = NL80211_CMD_REMAIN_ON_CHANNEL,
9610 .doit = nl80211_remain_on_channel,
9611 .policy = nl80211_policy,
9612 .flags = GENL_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +02009613 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009614 NL80211_FLAG_NEED_RTNL,
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009615 },
9616 {
9617 .cmd = NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL,
9618 .doit = nl80211_cancel_remain_on_channel,
9619 .policy = nl80211_policy,
9620 .flags = GENL_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +02009621 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009622 NL80211_FLAG_NEED_RTNL,
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009623 },
Jouni Malinen13ae75b2009-12-29 12:59:45 +02009624 {
9625 .cmd = NL80211_CMD_SET_TX_BITRATE_MASK,
9626 .doit = nl80211_set_tx_bitrate_mask,
9627 .policy = nl80211_policy,
9628 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02009629 .internal_flags = NL80211_FLAG_NEED_NETDEV |
9630 NL80211_FLAG_NEED_RTNL,
Jouni Malinen13ae75b2009-12-29 12:59:45 +02009631 },
Jouni Malinen026331c2010-02-15 12:53:10 +02009632 {
Johannes Berg2e161f72010-08-12 15:38:38 +02009633 .cmd = NL80211_CMD_REGISTER_FRAME,
9634 .doit = nl80211_register_mgmt,
Jouni Malinen026331c2010-02-15 12:53:10 +02009635 .policy = nl80211_policy,
9636 .flags = GENL_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +02009637 .internal_flags = NL80211_FLAG_NEED_WDEV |
Johannes Berg4c476992010-10-04 21:36:35 +02009638 NL80211_FLAG_NEED_RTNL,
Jouni Malinen026331c2010-02-15 12:53:10 +02009639 },
9640 {
Johannes Berg2e161f72010-08-12 15:38:38 +02009641 .cmd = NL80211_CMD_FRAME,
9642 .doit = nl80211_tx_mgmt,
Jouni Malinen026331c2010-02-15 12:53:10 +02009643 .policy = nl80211_policy,
9644 .flags = GENL_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +02009645 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009646 NL80211_FLAG_NEED_RTNL,
Jouni Malinen026331c2010-02-15 12:53:10 +02009647 },
Kalle Valoffb9eb32010-02-17 17:58:10 +02009648 {
Johannes Bergf7ca38d2010-11-25 10:02:29 +01009649 .cmd = NL80211_CMD_FRAME_WAIT_CANCEL,
9650 .doit = nl80211_tx_mgmt_cancel_wait,
9651 .policy = nl80211_policy,
9652 .flags = GENL_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +02009653 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Bergf7ca38d2010-11-25 10:02:29 +01009654 NL80211_FLAG_NEED_RTNL,
9655 },
9656 {
Kalle Valoffb9eb32010-02-17 17:58:10 +02009657 .cmd = NL80211_CMD_SET_POWER_SAVE,
9658 .doit = nl80211_set_power_save,
9659 .policy = nl80211_policy,
9660 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02009661 .internal_flags = NL80211_FLAG_NEED_NETDEV |
9662 NL80211_FLAG_NEED_RTNL,
Kalle Valoffb9eb32010-02-17 17:58:10 +02009663 },
9664 {
9665 .cmd = NL80211_CMD_GET_POWER_SAVE,
9666 .doit = nl80211_get_power_save,
9667 .policy = nl80211_policy,
9668 /* can be retrieved by unprivileged users */
Johannes Berg4c476992010-10-04 21:36:35 +02009669 .internal_flags = NL80211_FLAG_NEED_NETDEV |
9670 NL80211_FLAG_NEED_RTNL,
Kalle Valoffb9eb32010-02-17 17:58:10 +02009671 },
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02009672 {
9673 .cmd = NL80211_CMD_SET_CQM,
9674 .doit = nl80211_set_cqm,
9675 .policy = nl80211_policy,
9676 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02009677 .internal_flags = NL80211_FLAG_NEED_NETDEV |
9678 NL80211_FLAG_NEED_RTNL,
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02009679 },
Johannes Bergf444de02010-05-05 15:25:02 +02009680 {
9681 .cmd = NL80211_CMD_SET_CHANNEL,
9682 .doit = nl80211_set_channel,
9683 .policy = nl80211_policy,
9684 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02009685 .internal_flags = NL80211_FLAG_NEED_NETDEV |
9686 NL80211_FLAG_NEED_RTNL,
Johannes Bergf444de02010-05-05 15:25:02 +02009687 },
Bill Jordane8347eb2010-10-01 13:54:28 -04009688 {
9689 .cmd = NL80211_CMD_SET_WDS_PEER,
9690 .doit = nl80211_set_wds_peer,
9691 .policy = nl80211_policy,
9692 .flags = GENL_ADMIN_PERM,
Johannes Berg43b19952010-10-07 13:10:30 +02009693 .internal_flags = NL80211_FLAG_NEED_NETDEV |
9694 NL80211_FLAG_NEED_RTNL,
Bill Jordane8347eb2010-10-01 13:54:28 -04009695 },
Johannes Berg29cbe682010-12-03 09:20:44 +01009696 {
9697 .cmd = NL80211_CMD_JOIN_MESH,
9698 .doit = nl80211_join_mesh,
9699 .policy = nl80211_policy,
9700 .flags = GENL_ADMIN_PERM,
9701 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
9702 NL80211_FLAG_NEED_RTNL,
9703 },
9704 {
9705 .cmd = NL80211_CMD_LEAVE_MESH,
9706 .doit = nl80211_leave_mesh,
9707 .policy = nl80211_policy,
9708 .flags = GENL_ADMIN_PERM,
9709 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
9710 NL80211_FLAG_NEED_RTNL,
9711 },
Johannes Bergdfb89c52012-06-27 09:23:48 +02009712#ifdef CONFIG_PM
Johannes Bergff1b6e62011-05-04 15:37:28 +02009713 {
9714 .cmd = NL80211_CMD_GET_WOWLAN,
9715 .doit = nl80211_get_wowlan,
9716 .policy = nl80211_policy,
9717 /* can be retrieved by unprivileged users */
9718 .internal_flags = NL80211_FLAG_NEED_WIPHY |
9719 NL80211_FLAG_NEED_RTNL,
9720 },
9721 {
9722 .cmd = NL80211_CMD_SET_WOWLAN,
9723 .doit = nl80211_set_wowlan,
9724 .policy = nl80211_policy,
9725 .flags = GENL_ADMIN_PERM,
9726 .internal_flags = NL80211_FLAG_NEED_WIPHY |
9727 NL80211_FLAG_NEED_RTNL,
9728 },
Johannes Bergdfb89c52012-06-27 09:23:48 +02009729#endif
Johannes Berge5497d72011-07-05 16:35:40 +02009730 {
9731 .cmd = NL80211_CMD_SET_REKEY_OFFLOAD,
9732 .doit = nl80211_set_rekey_data,
9733 .policy = nl80211_policy,
9734 .flags = GENL_ADMIN_PERM,
9735 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
9736 NL80211_FLAG_NEED_RTNL,
9737 },
Arik Nemtsov109086c2011-09-28 14:12:50 +03009738 {
9739 .cmd = NL80211_CMD_TDLS_MGMT,
9740 .doit = nl80211_tdls_mgmt,
9741 .policy = nl80211_policy,
9742 .flags = GENL_ADMIN_PERM,
9743 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
9744 NL80211_FLAG_NEED_RTNL,
9745 },
9746 {
9747 .cmd = NL80211_CMD_TDLS_OPER,
9748 .doit = nl80211_tdls_oper,
9749 .policy = nl80211_policy,
9750 .flags = GENL_ADMIN_PERM,
9751 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
9752 NL80211_FLAG_NEED_RTNL,
9753 },
Johannes Berg28946da2011-11-04 11:18:12 +01009754 {
9755 .cmd = NL80211_CMD_UNEXPECTED_FRAME,
9756 .doit = nl80211_register_unexpected_frame,
9757 .policy = nl80211_policy,
9758 .flags = GENL_ADMIN_PERM,
9759 .internal_flags = NL80211_FLAG_NEED_NETDEV |
9760 NL80211_FLAG_NEED_RTNL,
9761 },
Johannes Berg7f6cf312011-11-04 11:18:15 +01009762 {
9763 .cmd = NL80211_CMD_PROBE_CLIENT,
9764 .doit = nl80211_probe_client,
9765 .policy = nl80211_policy,
9766 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02009767 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg7f6cf312011-11-04 11:18:15 +01009768 NL80211_FLAG_NEED_RTNL,
9769 },
Johannes Berg5e760232011-11-04 11:18:17 +01009770 {
9771 .cmd = NL80211_CMD_REGISTER_BEACONS,
9772 .doit = nl80211_register_beacons,
9773 .policy = nl80211_policy,
9774 .flags = GENL_ADMIN_PERM,
9775 .internal_flags = NL80211_FLAG_NEED_WIPHY |
9776 NL80211_FLAG_NEED_RTNL,
9777 },
Simon Wunderlich1d9d9212011-11-18 14:20:43 +01009778 {
9779 .cmd = NL80211_CMD_SET_NOACK_MAP,
9780 .doit = nl80211_set_noack_map,
9781 .policy = nl80211_policy,
9782 .flags = GENL_ADMIN_PERM,
9783 .internal_flags = NL80211_FLAG_NEED_NETDEV |
9784 NL80211_FLAG_NEED_RTNL,
9785 },
Johannes Berg98104fde2012-06-16 00:19:54 +02009786 {
9787 .cmd = NL80211_CMD_START_P2P_DEVICE,
9788 .doit = nl80211_start_p2p_device,
9789 .policy = nl80211_policy,
9790 .flags = GENL_ADMIN_PERM,
9791 .internal_flags = NL80211_FLAG_NEED_WDEV |
9792 NL80211_FLAG_NEED_RTNL,
9793 },
9794 {
9795 .cmd = NL80211_CMD_STOP_P2P_DEVICE,
9796 .doit = nl80211_stop_p2p_device,
9797 .policy = nl80211_policy,
9798 .flags = GENL_ADMIN_PERM,
9799 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
9800 NL80211_FLAG_NEED_RTNL,
9801 },
Antonio Quartullif4e583c2012-11-02 13:27:48 +01009802 {
9803 .cmd = NL80211_CMD_SET_MCAST_RATE,
9804 .doit = nl80211_set_mcast_rate,
9805 .policy = nl80211_policy,
9806 .flags = GENL_ADMIN_PERM,
9807 .internal_flags = NL80211_FLAG_NEED_NETDEV |
9808 NL80211_FLAG_NEED_RTNL,
9809 },
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +05309810 {
9811 .cmd = NL80211_CMD_SET_MAC_ACL,
9812 .doit = nl80211_set_mac_acl,
9813 .policy = nl80211_policy,
9814 .flags = GENL_ADMIN_PERM,
9815 .internal_flags = NL80211_FLAG_NEED_NETDEV |
9816 NL80211_FLAG_NEED_RTNL,
9817 },
Simon Wunderlich04f39042013-02-08 18:16:19 +01009818 {
9819 .cmd = NL80211_CMD_RADAR_DETECT,
9820 .doit = nl80211_start_radar_detection,
9821 .policy = nl80211_policy,
9822 .flags = GENL_ADMIN_PERM,
9823 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
9824 NL80211_FLAG_NEED_RTNL,
9825 },
Johannes Berg3713b4e2013-02-14 16:19:38 +01009826 {
9827 .cmd = NL80211_CMD_GET_PROTOCOL_FEATURES,
9828 .doit = nl80211_get_protocol_features,
9829 .policy = nl80211_policy,
9830 },
Jouni Malinen355199e2013-02-27 17:14:27 +02009831 {
9832 .cmd = NL80211_CMD_UPDATE_FT_IES,
9833 .doit = nl80211_update_ft_ies,
9834 .policy = nl80211_policy,
9835 .flags = GENL_ADMIN_PERM,
9836 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
9837 NL80211_FLAG_NEED_RTNL,
9838 },
Arend van Spriel5de17982013-04-18 15:49:00 +02009839 {
9840 .cmd = NL80211_CMD_CRIT_PROTOCOL_START,
9841 .doit = nl80211_crit_protocol_start,
9842 .policy = nl80211_policy,
9843 .flags = GENL_ADMIN_PERM,
9844 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
9845 NL80211_FLAG_NEED_RTNL,
9846 },
9847 {
9848 .cmd = NL80211_CMD_CRIT_PROTOCOL_STOP,
9849 .doit = nl80211_crit_protocol_stop,
9850 .policy = nl80211_policy,
9851 .flags = GENL_ADMIN_PERM,
9852 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
9853 NL80211_FLAG_NEED_RTNL,
Amitkumar Karwarbe29b992013-06-28 11:51:26 -07009854 },
9855 {
9856 .cmd = NL80211_CMD_GET_COALESCE,
9857 .doit = nl80211_get_coalesce,
9858 .policy = nl80211_policy,
9859 .internal_flags = NL80211_FLAG_NEED_WIPHY |
9860 NL80211_FLAG_NEED_RTNL,
9861 },
9862 {
9863 .cmd = NL80211_CMD_SET_COALESCE,
9864 .doit = nl80211_set_coalesce,
9865 .policy = nl80211_policy,
9866 .flags = GENL_ADMIN_PERM,
9867 .internal_flags = NL80211_FLAG_NEED_WIPHY |
9868 NL80211_FLAG_NEED_RTNL,
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02009869 },
9870 {
9871 .cmd = NL80211_CMD_CHANNEL_SWITCH,
9872 .doit = nl80211_channel_switch,
9873 .policy = nl80211_policy,
9874 .flags = GENL_ADMIN_PERM,
9875 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
9876 NL80211_FLAG_NEED_RTNL,
9877 },
Johannes Bergad7e7182013-11-13 13:37:47 +01009878 {
9879 .cmd = NL80211_CMD_VENDOR,
9880 .doit = nl80211_vendor_cmd,
9881 .policy = nl80211_policy,
9882 .flags = GENL_ADMIN_PERM,
9883 .internal_flags = NL80211_FLAG_NEED_WIPHY |
9884 NL80211_FLAG_NEED_RTNL,
9885 },
Kyeyoon Parkfa9ffc72013-12-16 23:01:30 -08009886 {
9887 .cmd = NL80211_CMD_SET_QOS_MAP,
9888 .doit = nl80211_set_qos_map,
9889 .policy = nl80211_policy,
9890 .flags = GENL_ADMIN_PERM,
9891 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
9892 NL80211_FLAG_NEED_RTNL,
9893 },
Johannes Berg55682962007-09-20 13:09:35 -04009894};
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009895
Johannes Berg55682962007-09-20 13:09:35 -04009896/* notification functions */
9897
9898void nl80211_notify_dev_rename(struct cfg80211_registered_device *rdev)
9899{
9900 struct sk_buff *msg;
Johannes Berg86e8cf92013-06-19 10:57:22 +02009901 struct nl80211_dump_wiphy_state state = {};
Johannes Berg55682962007-09-20 13:09:35 -04009902
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07009903 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -04009904 if (!msg)
9905 return;
9906
Johannes Berg86e8cf92013-06-19 10:57:22 +02009907 if (nl80211_send_wiphy(rdev, msg, 0, 0, 0, &state) < 0) {
Johannes Berg55682962007-09-20 13:09:35 -04009908 nlmsg_free(msg);
9909 return;
9910 }
9911
Johannes Berg68eb5502013-11-19 15:19:38 +01009912 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +01009913 NL80211_MCGRP_CONFIG, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -04009914}
9915
Johannes Berg362a4152009-05-24 16:43:15 +02009916static int nl80211_add_scan_req(struct sk_buff *msg,
9917 struct cfg80211_registered_device *rdev)
9918{
9919 struct cfg80211_scan_request *req = rdev->scan_req;
9920 struct nlattr *nest;
9921 int i;
9922
9923 if (WARN_ON(!req))
9924 return 0;
9925
9926 nest = nla_nest_start(msg, NL80211_ATTR_SCAN_SSIDS);
9927 if (!nest)
9928 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04009929 for (i = 0; i < req->n_ssids; i++) {
9930 if (nla_put(msg, i, req->ssids[i].ssid_len, req->ssids[i].ssid))
9931 goto nla_put_failure;
9932 }
Johannes Berg362a4152009-05-24 16:43:15 +02009933 nla_nest_end(msg, nest);
9934
9935 nest = nla_nest_start(msg, NL80211_ATTR_SCAN_FREQUENCIES);
9936 if (!nest)
9937 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04009938 for (i = 0; i < req->n_channels; i++) {
9939 if (nla_put_u32(msg, i, req->channels[i]->center_freq))
9940 goto nla_put_failure;
9941 }
Johannes Berg362a4152009-05-24 16:43:15 +02009942 nla_nest_end(msg, nest);
9943
David S. Miller9360ffd2012-03-29 04:41:26 -04009944 if (req->ie &&
9945 nla_put(msg, NL80211_ATTR_IE, req->ie_len, req->ie))
9946 goto nla_put_failure;
Johannes Berg362a4152009-05-24 16:43:15 +02009947
Johannes Bergae917c92013-10-25 11:05:22 +02009948 if (req->flags &&
9949 nla_put_u32(msg, NL80211_ATTR_SCAN_FLAGS, req->flags))
9950 goto nla_put_failure;
Sam Lefflered4737712012-10-11 21:03:31 -07009951
Johannes Berg362a4152009-05-24 16:43:15 +02009952 return 0;
9953 nla_put_failure:
9954 return -ENOBUFS;
9955}
9956
Johannes Berga538e2d2009-06-16 19:56:42 +02009957static int nl80211_send_scan_msg(struct sk_buff *msg,
9958 struct cfg80211_registered_device *rdev,
Johannes Bergfd014282012-06-18 19:17:03 +02009959 struct wireless_dev *wdev,
Eric W. Biederman15e47302012-09-07 20:12:54 +00009960 u32 portid, u32 seq, int flags,
Johannes Berga538e2d2009-06-16 19:56:42 +02009961 u32 cmd)
Johannes Berg2a519312009-02-10 21:25:55 +01009962{
9963 void *hdr;
9964
Eric W. Biederman15e47302012-09-07 20:12:54 +00009965 hdr = nl80211hdr_put(msg, portid, seq, flags, cmd);
Johannes Berg2a519312009-02-10 21:25:55 +01009966 if (!hdr)
9967 return -1;
9968
David S. Miller9360ffd2012-03-29 04:41:26 -04009969 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Bergfd014282012-06-18 19:17:03 +02009970 (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
9971 wdev->netdev->ifindex)) ||
9972 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)))
David S. Miller9360ffd2012-03-29 04:41:26 -04009973 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01009974
Johannes Berg362a4152009-05-24 16:43:15 +02009975 /* ignore errors and send incomplete event anyway */
9976 nl80211_add_scan_req(msg, rdev);
Johannes Berg2a519312009-02-10 21:25:55 +01009977
9978 return genlmsg_end(msg, hdr);
9979
9980 nla_put_failure:
9981 genlmsg_cancel(msg, hdr);
9982 return -EMSGSIZE;
9983}
9984
Luciano Coelho807f8a82011-05-11 17:09:35 +03009985static int
9986nl80211_send_sched_scan_msg(struct sk_buff *msg,
9987 struct cfg80211_registered_device *rdev,
9988 struct net_device *netdev,
Eric W. Biederman15e47302012-09-07 20:12:54 +00009989 u32 portid, u32 seq, int flags, u32 cmd)
Luciano Coelho807f8a82011-05-11 17:09:35 +03009990{
9991 void *hdr;
9992
Eric W. Biederman15e47302012-09-07 20:12:54 +00009993 hdr = nl80211hdr_put(msg, portid, seq, flags, cmd);
Luciano Coelho807f8a82011-05-11 17:09:35 +03009994 if (!hdr)
9995 return -1;
9996
David S. Miller9360ffd2012-03-29 04:41:26 -04009997 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
9998 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex))
9999 goto nla_put_failure;
Luciano Coelho807f8a82011-05-11 17:09:35 +030010000
10001 return genlmsg_end(msg, hdr);
10002
10003 nla_put_failure:
10004 genlmsg_cancel(msg, hdr);
10005 return -EMSGSIZE;
10006}
10007
Johannes Berga538e2d2009-06-16 19:56:42 +020010008void nl80211_send_scan_start(struct cfg80211_registered_device *rdev,
Johannes Bergfd014282012-06-18 19:17:03 +020010009 struct wireless_dev *wdev)
Johannes Berga538e2d2009-06-16 19:56:42 +020010010{
10011 struct sk_buff *msg;
10012
Thomas Graf58050fc2012-06-28 03:57:45 +000010013 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berga538e2d2009-06-16 19:56:42 +020010014 if (!msg)
10015 return;
10016
Johannes Bergfd014282012-06-18 19:17:03 +020010017 if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0,
Johannes Berga538e2d2009-06-16 19:56:42 +020010018 NL80211_CMD_TRIGGER_SCAN) < 0) {
10019 nlmsg_free(msg);
10020 return;
10021 }
10022
Johannes Berg68eb5502013-11-19 15:19:38 +010010023 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010010024 NL80211_MCGRP_SCAN, GFP_KERNEL);
Johannes Berga538e2d2009-06-16 19:56:42 +020010025}
10026
Johannes Berg2a519312009-02-10 21:25:55 +010010027void nl80211_send_scan_done(struct cfg80211_registered_device *rdev,
Johannes Bergfd014282012-06-18 19:17:03 +020010028 struct wireless_dev *wdev)
Johannes Berg2a519312009-02-10 21:25:55 +010010029{
10030 struct sk_buff *msg;
10031
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -070010032 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg2a519312009-02-10 21:25:55 +010010033 if (!msg)
10034 return;
10035
Johannes Bergfd014282012-06-18 19:17:03 +020010036 if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0,
Johannes Berga538e2d2009-06-16 19:56:42 +020010037 NL80211_CMD_NEW_SCAN_RESULTS) < 0) {
Johannes Berg2a519312009-02-10 21:25:55 +010010038 nlmsg_free(msg);
10039 return;
10040 }
10041
Johannes Berg68eb5502013-11-19 15:19:38 +010010042 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010010043 NL80211_MCGRP_SCAN, GFP_KERNEL);
Johannes Berg2a519312009-02-10 21:25:55 +010010044}
10045
10046void nl80211_send_scan_aborted(struct cfg80211_registered_device *rdev,
Johannes Bergfd014282012-06-18 19:17:03 +020010047 struct wireless_dev *wdev)
Johannes Berg2a519312009-02-10 21:25:55 +010010048{
10049 struct sk_buff *msg;
10050
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -070010051 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg2a519312009-02-10 21:25:55 +010010052 if (!msg)
10053 return;
10054
Johannes Bergfd014282012-06-18 19:17:03 +020010055 if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0,
Johannes Berga538e2d2009-06-16 19:56:42 +020010056 NL80211_CMD_SCAN_ABORTED) < 0) {
Johannes Berg2a519312009-02-10 21:25:55 +010010057 nlmsg_free(msg);
10058 return;
10059 }
10060
Johannes Berg68eb5502013-11-19 15:19:38 +010010061 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010010062 NL80211_MCGRP_SCAN, GFP_KERNEL);
Johannes Berg2a519312009-02-10 21:25:55 +010010063}
10064
Luciano Coelho807f8a82011-05-11 17:09:35 +030010065void nl80211_send_sched_scan_results(struct cfg80211_registered_device *rdev,
10066 struct net_device *netdev)
10067{
10068 struct sk_buff *msg;
10069
10070 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
10071 if (!msg)
10072 return;
10073
10074 if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0,
10075 NL80211_CMD_SCHED_SCAN_RESULTS) < 0) {
10076 nlmsg_free(msg);
10077 return;
10078 }
10079
Johannes Berg68eb5502013-11-19 15:19:38 +010010080 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010010081 NL80211_MCGRP_SCAN, GFP_KERNEL);
Luciano Coelho807f8a82011-05-11 17:09:35 +030010082}
10083
10084void nl80211_send_sched_scan(struct cfg80211_registered_device *rdev,
10085 struct net_device *netdev, u32 cmd)
10086{
10087 struct sk_buff *msg;
10088
Thomas Graf58050fc2012-06-28 03:57:45 +000010089 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Luciano Coelho807f8a82011-05-11 17:09:35 +030010090 if (!msg)
10091 return;
10092
10093 if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0, cmd) < 0) {
10094 nlmsg_free(msg);
10095 return;
10096 }
10097
Johannes Berg68eb5502013-11-19 15:19:38 +010010098 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010010099 NL80211_MCGRP_SCAN, GFP_KERNEL);
Luciano Coelho807f8a82011-05-11 17:09:35 +030010100}
10101
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040010102/*
10103 * This can happen on global regulatory changes or device specific settings
10104 * based on custom world regulatory domains.
10105 */
10106void nl80211_send_reg_change_event(struct regulatory_request *request)
10107{
10108 struct sk_buff *msg;
10109 void *hdr;
10110
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -070010111 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040010112 if (!msg)
10113 return;
10114
10115 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_CHANGE);
10116 if (!hdr) {
10117 nlmsg_free(msg);
10118 return;
10119 }
10120
10121 /* Userspace can always count this one always being set */
David S. Miller9360ffd2012-03-29 04:41:26 -040010122 if (nla_put_u8(msg, NL80211_ATTR_REG_INITIATOR, request->initiator))
10123 goto nla_put_failure;
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040010124
David S. Miller9360ffd2012-03-29 04:41:26 -040010125 if (request->alpha2[0] == '0' && request->alpha2[1] == '0') {
10126 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
10127 NL80211_REGDOM_TYPE_WORLD))
10128 goto nla_put_failure;
10129 } else if (request->alpha2[0] == '9' && request->alpha2[1] == '9') {
10130 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
10131 NL80211_REGDOM_TYPE_CUSTOM_WORLD))
10132 goto nla_put_failure;
10133 } else if ((request->alpha2[0] == '9' && request->alpha2[1] == '8') ||
10134 request->intersect) {
10135 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
10136 NL80211_REGDOM_TYPE_INTERSECTION))
10137 goto nla_put_failure;
10138 } else {
10139 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
10140 NL80211_REGDOM_TYPE_COUNTRY) ||
10141 nla_put_string(msg, NL80211_ATTR_REG_ALPHA2,
10142 request->alpha2))
10143 goto nla_put_failure;
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040010144 }
10145
Johannes Bergf4173762012-12-03 18:23:37 +010010146 if (request->wiphy_idx != WIPHY_IDX_INVALID &&
David S. Miller9360ffd2012-03-29 04:41:26 -040010147 nla_put_u32(msg, NL80211_ATTR_WIPHY, request->wiphy_idx))
10148 goto nla_put_failure;
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040010149
Johannes Berg3b7b72e2011-10-22 19:05:51 +020010150 genlmsg_end(msg, hdr);
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040010151
Johannes Bergbc43b282009-07-25 10:54:13 +020010152 rcu_read_lock();
Johannes Berg68eb5502013-11-19 15:19:38 +010010153 genlmsg_multicast_allns(&nl80211_fam, msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010010154 NL80211_MCGRP_REGULATORY, GFP_ATOMIC);
Johannes Bergbc43b282009-07-25 10:54:13 +020010155 rcu_read_unlock();
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040010156
10157 return;
10158
10159nla_put_failure:
10160 genlmsg_cancel(msg, hdr);
10161 nlmsg_free(msg);
10162}
10163
Jouni Malinen6039f6d2009-03-19 13:39:21 +020010164static void nl80211_send_mlme_event(struct cfg80211_registered_device *rdev,
10165 struct net_device *netdev,
10166 const u8 *buf, size_t len,
Johannes Berge6d6e342009-07-01 21:26:47 +020010167 enum nl80211_commands cmd, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +020010168{
10169 struct sk_buff *msg;
10170 void *hdr;
10171
Johannes Berge6d6e342009-07-01 21:26:47 +020010172 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020010173 if (!msg)
10174 return;
10175
10176 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
10177 if (!hdr) {
10178 nlmsg_free(msg);
10179 return;
10180 }
10181
David S. Miller9360ffd2012-03-29 04:41:26 -040010182 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
10183 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
10184 nla_put(msg, NL80211_ATTR_FRAME, len, buf))
10185 goto nla_put_failure;
Jouni Malinen6039f6d2009-03-19 13:39:21 +020010186
Johannes Berg3b7b72e2011-10-22 19:05:51 +020010187 genlmsg_end(msg, hdr);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020010188
Johannes Berg68eb5502013-11-19 15:19:38 +010010189 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010010190 NL80211_MCGRP_MLME, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020010191 return;
10192
10193 nla_put_failure:
10194 genlmsg_cancel(msg, hdr);
10195 nlmsg_free(msg);
10196}
10197
10198void nl80211_send_rx_auth(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +020010199 struct net_device *netdev, const u8 *buf,
10200 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +020010201{
10202 nl80211_send_mlme_event(rdev, netdev, buf, len,
Johannes Berge6d6e342009-07-01 21:26:47 +020010203 NL80211_CMD_AUTHENTICATE, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020010204}
10205
10206void nl80211_send_rx_assoc(struct cfg80211_registered_device *rdev,
10207 struct net_device *netdev, const u8 *buf,
Johannes Berge6d6e342009-07-01 21:26:47 +020010208 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +020010209{
Johannes Berge6d6e342009-07-01 21:26:47 +020010210 nl80211_send_mlme_event(rdev, netdev, buf, len,
10211 NL80211_CMD_ASSOCIATE, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020010212}
10213
Jouni Malinen53b46b82009-03-27 20:53:56 +020010214void nl80211_send_deauth(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +020010215 struct net_device *netdev, const u8 *buf,
10216 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +020010217{
10218 nl80211_send_mlme_event(rdev, netdev, buf, len,
Johannes Berge6d6e342009-07-01 21:26:47 +020010219 NL80211_CMD_DEAUTHENTICATE, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020010220}
10221
Jouni Malinen53b46b82009-03-27 20:53:56 +020010222void nl80211_send_disassoc(struct cfg80211_registered_device *rdev,
10223 struct net_device *netdev, const u8 *buf,
Johannes Berge6d6e342009-07-01 21:26:47 +020010224 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +020010225{
10226 nl80211_send_mlme_event(rdev, netdev, buf, len,
Johannes Berge6d6e342009-07-01 21:26:47 +020010227 NL80211_CMD_DISASSOCIATE, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020010228}
10229
Johannes Berg6ff57cf2013-05-16 00:55:00 +020010230void cfg80211_rx_unprot_mlme_mgmt(struct net_device *dev, const u8 *buf,
10231 size_t len)
Jouni Malinencf4e5942010-12-16 00:52:40 +020010232{
Johannes Berg947add32013-02-22 22:05:20 +010010233 struct wireless_dev *wdev = dev->ieee80211_ptr;
10234 struct wiphy *wiphy = wdev->wiphy;
10235 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
Johannes Berg6ff57cf2013-05-16 00:55:00 +020010236 const struct ieee80211_mgmt *mgmt = (void *)buf;
10237 u32 cmd;
Jouni Malinencf4e5942010-12-16 00:52:40 +020010238
Johannes Berg6ff57cf2013-05-16 00:55:00 +020010239 if (WARN_ON(len < 2))
10240 return;
10241
10242 if (ieee80211_is_deauth(mgmt->frame_control))
10243 cmd = NL80211_CMD_UNPROT_DEAUTHENTICATE;
10244 else
10245 cmd = NL80211_CMD_UNPROT_DISASSOCIATE;
10246
10247 trace_cfg80211_rx_unprot_mlme_mgmt(dev, buf, len);
10248 nl80211_send_mlme_event(rdev, dev, buf, len, cmd, GFP_ATOMIC);
Jouni Malinencf4e5942010-12-16 00:52:40 +020010249}
Johannes Berg6ff57cf2013-05-16 00:55:00 +020010250EXPORT_SYMBOL(cfg80211_rx_unprot_mlme_mgmt);
Jouni Malinencf4e5942010-12-16 00:52:40 +020010251
Luis R. Rodriguez1b06bb42009-05-02 00:34:48 -040010252static void nl80211_send_mlme_timeout(struct cfg80211_registered_device *rdev,
10253 struct net_device *netdev, int cmd,
Johannes Berge6d6e342009-07-01 21:26:47 +020010254 const u8 *addr, gfp_t gfp)
Jouni Malinen1965c852009-04-22 21:38:25 +030010255{
10256 struct sk_buff *msg;
10257 void *hdr;
10258
Johannes Berge6d6e342009-07-01 21:26:47 +020010259 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +030010260 if (!msg)
10261 return;
10262
10263 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
10264 if (!hdr) {
10265 nlmsg_free(msg);
10266 return;
10267 }
10268
David S. Miller9360ffd2012-03-29 04:41:26 -040010269 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
10270 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
10271 nla_put_flag(msg, NL80211_ATTR_TIMED_OUT) ||
10272 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr))
10273 goto nla_put_failure;
Jouni Malinen1965c852009-04-22 21:38:25 +030010274
Johannes Berg3b7b72e2011-10-22 19:05:51 +020010275 genlmsg_end(msg, hdr);
Jouni Malinen1965c852009-04-22 21:38:25 +030010276
Johannes Berg68eb5502013-11-19 15:19:38 +010010277 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010010278 NL80211_MCGRP_MLME, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +030010279 return;
10280
10281 nla_put_failure:
10282 genlmsg_cancel(msg, hdr);
10283 nlmsg_free(msg);
10284}
10285
10286void nl80211_send_auth_timeout(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +020010287 struct net_device *netdev, const u8 *addr,
10288 gfp_t gfp)
Jouni Malinen1965c852009-04-22 21:38:25 +030010289{
10290 nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_AUTHENTICATE,
Johannes Berge6d6e342009-07-01 21:26:47 +020010291 addr, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +030010292}
10293
10294void nl80211_send_assoc_timeout(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +020010295 struct net_device *netdev, const u8 *addr,
10296 gfp_t gfp)
Jouni Malinen1965c852009-04-22 21:38:25 +030010297{
Johannes Berge6d6e342009-07-01 21:26:47 +020010298 nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_ASSOCIATE,
10299 addr, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +030010300}
10301
Samuel Ortizb23aa672009-07-01 21:26:54 +020010302void nl80211_send_connect_result(struct cfg80211_registered_device *rdev,
10303 struct net_device *netdev, const u8 *bssid,
10304 const u8 *req_ie, size_t req_ie_len,
10305 const u8 *resp_ie, size_t resp_ie_len,
10306 u16 status, gfp_t gfp)
10307{
10308 struct sk_buff *msg;
10309 void *hdr;
10310
Thomas Graf58050fc2012-06-28 03:57:45 +000010311 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +020010312 if (!msg)
10313 return;
10314
10315 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONNECT);
10316 if (!hdr) {
10317 nlmsg_free(msg);
10318 return;
10319 }
10320
David S. Miller9360ffd2012-03-29 04:41:26 -040010321 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
10322 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
10323 (bssid && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) ||
10324 nla_put_u16(msg, NL80211_ATTR_STATUS_CODE, status) ||
10325 (req_ie &&
10326 nla_put(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie)) ||
10327 (resp_ie &&
10328 nla_put(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie)))
10329 goto nla_put_failure;
Samuel Ortizb23aa672009-07-01 21:26:54 +020010330
Johannes Berg3b7b72e2011-10-22 19:05:51 +020010331 genlmsg_end(msg, hdr);
Samuel Ortizb23aa672009-07-01 21:26:54 +020010332
Johannes Berg68eb5502013-11-19 15:19:38 +010010333 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010010334 NL80211_MCGRP_MLME, gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +020010335 return;
10336
10337 nla_put_failure:
10338 genlmsg_cancel(msg, hdr);
10339 nlmsg_free(msg);
10340
10341}
10342
10343void nl80211_send_roamed(struct cfg80211_registered_device *rdev,
10344 struct net_device *netdev, const u8 *bssid,
10345 const u8 *req_ie, size_t req_ie_len,
10346 const u8 *resp_ie, size_t resp_ie_len, gfp_t gfp)
10347{
10348 struct sk_buff *msg;
10349 void *hdr;
10350
Thomas Graf58050fc2012-06-28 03:57:45 +000010351 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +020010352 if (!msg)
10353 return;
10354
10355 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_ROAM);
10356 if (!hdr) {
10357 nlmsg_free(msg);
10358 return;
10359 }
10360
David S. Miller9360ffd2012-03-29 04:41:26 -040010361 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
10362 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
10363 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid) ||
10364 (req_ie &&
10365 nla_put(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie)) ||
10366 (resp_ie &&
10367 nla_put(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie)))
10368 goto nla_put_failure;
Samuel Ortizb23aa672009-07-01 21:26:54 +020010369
Johannes Berg3b7b72e2011-10-22 19:05:51 +020010370 genlmsg_end(msg, hdr);
Samuel Ortizb23aa672009-07-01 21:26:54 +020010371
Johannes Berg68eb5502013-11-19 15:19:38 +010010372 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010010373 NL80211_MCGRP_MLME, gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +020010374 return;
10375
10376 nla_put_failure:
10377 genlmsg_cancel(msg, hdr);
10378 nlmsg_free(msg);
10379
10380}
10381
10382void nl80211_send_disconnected(struct cfg80211_registered_device *rdev,
10383 struct net_device *netdev, u16 reason,
Johannes Berg667503dd2009-07-07 03:56:11 +020010384 const u8 *ie, size_t ie_len, bool from_ap)
Samuel Ortizb23aa672009-07-01 21:26:54 +020010385{
10386 struct sk_buff *msg;
10387 void *hdr;
10388
Thomas Graf58050fc2012-06-28 03:57:45 +000010389 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Samuel Ortizb23aa672009-07-01 21:26:54 +020010390 if (!msg)
10391 return;
10392
10393 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DISCONNECT);
10394 if (!hdr) {
10395 nlmsg_free(msg);
10396 return;
10397 }
10398
David S. Miller9360ffd2012-03-29 04:41:26 -040010399 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
10400 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
10401 (from_ap && reason &&
10402 nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason)) ||
10403 (from_ap &&
10404 nla_put_flag(msg, NL80211_ATTR_DISCONNECTED_BY_AP)) ||
10405 (ie && nla_put(msg, NL80211_ATTR_IE, ie_len, ie)))
10406 goto nla_put_failure;
Samuel Ortizb23aa672009-07-01 21:26:54 +020010407
Johannes Berg3b7b72e2011-10-22 19:05:51 +020010408 genlmsg_end(msg, hdr);
Samuel Ortizb23aa672009-07-01 21:26:54 +020010409
Johannes Berg68eb5502013-11-19 15:19:38 +010010410 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010010411 NL80211_MCGRP_MLME, GFP_KERNEL);
Samuel Ortizb23aa672009-07-01 21:26:54 +020010412 return;
10413
10414 nla_put_failure:
10415 genlmsg_cancel(msg, hdr);
10416 nlmsg_free(msg);
10417
10418}
10419
Johannes Berg04a773a2009-04-19 21:24:32 +020010420void nl80211_send_ibss_bssid(struct cfg80211_registered_device *rdev,
10421 struct net_device *netdev, const u8 *bssid,
10422 gfp_t gfp)
10423{
10424 struct sk_buff *msg;
10425 void *hdr;
10426
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -070010427 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Johannes Berg04a773a2009-04-19 21:24:32 +020010428 if (!msg)
10429 return;
10430
10431 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_JOIN_IBSS);
10432 if (!hdr) {
10433 nlmsg_free(msg);
10434 return;
10435 }
10436
David S. Miller9360ffd2012-03-29 04:41:26 -040010437 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
10438 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
10439 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid))
10440 goto nla_put_failure;
Johannes Berg04a773a2009-04-19 21:24:32 +020010441
Johannes Berg3b7b72e2011-10-22 19:05:51 +020010442 genlmsg_end(msg, hdr);
Johannes Berg04a773a2009-04-19 21:24:32 +020010443
Johannes Berg68eb5502013-11-19 15:19:38 +010010444 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010010445 NL80211_MCGRP_MLME, gfp);
Johannes Berg04a773a2009-04-19 21:24:32 +020010446 return;
10447
10448 nla_put_failure:
10449 genlmsg_cancel(msg, hdr);
10450 nlmsg_free(msg);
10451}
10452
Johannes Berg947add32013-02-22 22:05:20 +010010453void cfg80211_notify_new_peer_candidate(struct net_device *dev, const u8 *addr,
10454 const u8* ie, u8 ie_len, gfp_t gfp)
Javier Cardonac93b5e72011-04-07 15:08:34 -070010455{
Johannes Berg947add32013-02-22 22:05:20 +010010456 struct wireless_dev *wdev = dev->ieee80211_ptr;
10457 struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
Javier Cardonac93b5e72011-04-07 15:08:34 -070010458 struct sk_buff *msg;
10459 void *hdr;
10460
Johannes Berg947add32013-02-22 22:05:20 +010010461 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_MESH_POINT))
10462 return;
10463
10464 trace_cfg80211_notify_new_peer_candidate(dev, addr);
10465
Javier Cardonac93b5e72011-04-07 15:08:34 -070010466 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
10467 if (!msg)
10468 return;
10469
10470 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NEW_PEER_CANDIDATE);
10471 if (!hdr) {
10472 nlmsg_free(msg);
10473 return;
10474 }
10475
David S. Miller9360ffd2012-03-29 04:41:26 -040010476 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg947add32013-02-22 22:05:20 +010010477 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
10478 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040010479 (ie_len && ie &&
10480 nla_put(msg, NL80211_ATTR_IE, ie_len , ie)))
10481 goto nla_put_failure;
Javier Cardonac93b5e72011-04-07 15:08:34 -070010482
Johannes Berg3b7b72e2011-10-22 19:05:51 +020010483 genlmsg_end(msg, hdr);
Javier Cardonac93b5e72011-04-07 15:08:34 -070010484
Johannes Berg68eb5502013-11-19 15:19:38 +010010485 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010010486 NL80211_MCGRP_MLME, gfp);
Javier Cardonac93b5e72011-04-07 15:08:34 -070010487 return;
10488
10489 nla_put_failure:
10490 genlmsg_cancel(msg, hdr);
10491 nlmsg_free(msg);
10492}
Johannes Berg947add32013-02-22 22:05:20 +010010493EXPORT_SYMBOL(cfg80211_notify_new_peer_candidate);
Javier Cardonac93b5e72011-04-07 15:08:34 -070010494
Jouni Malinena3b8b052009-03-27 21:59:49 +020010495void nl80211_michael_mic_failure(struct cfg80211_registered_device *rdev,
10496 struct net_device *netdev, const u8 *addr,
10497 enum nl80211_key_type key_type, int key_id,
Johannes Berge6d6e342009-07-01 21:26:47 +020010498 const u8 *tsc, gfp_t gfp)
Jouni Malinena3b8b052009-03-27 21:59:49 +020010499{
10500 struct sk_buff *msg;
10501 void *hdr;
10502
Johannes Berge6d6e342009-07-01 21:26:47 +020010503 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinena3b8b052009-03-27 21:59:49 +020010504 if (!msg)
10505 return;
10506
10507 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_MICHAEL_MIC_FAILURE);
10508 if (!hdr) {
10509 nlmsg_free(msg);
10510 return;
10511 }
10512
David S. Miller9360ffd2012-03-29 04:41:26 -040010513 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
10514 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
10515 (addr && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) ||
10516 nla_put_u32(msg, NL80211_ATTR_KEY_TYPE, key_type) ||
10517 (key_id != -1 &&
10518 nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_id)) ||
10519 (tsc && nla_put(msg, NL80211_ATTR_KEY_SEQ, 6, tsc)))
10520 goto nla_put_failure;
Jouni Malinena3b8b052009-03-27 21:59:49 +020010521
Johannes Berg3b7b72e2011-10-22 19:05:51 +020010522 genlmsg_end(msg, hdr);
Jouni Malinena3b8b052009-03-27 21:59:49 +020010523
Johannes Berg68eb5502013-11-19 15:19:38 +010010524 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010010525 NL80211_MCGRP_MLME, gfp);
Jouni Malinena3b8b052009-03-27 21:59:49 +020010526 return;
10527
10528 nla_put_failure:
10529 genlmsg_cancel(msg, hdr);
10530 nlmsg_free(msg);
10531}
10532
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040010533void nl80211_send_beacon_hint_event(struct wiphy *wiphy,
10534 struct ieee80211_channel *channel_before,
10535 struct ieee80211_channel *channel_after)
10536{
10537 struct sk_buff *msg;
10538 void *hdr;
10539 struct nlattr *nl_freq;
10540
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -070010541 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_ATOMIC);
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040010542 if (!msg)
10543 return;
10544
10545 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_BEACON_HINT);
10546 if (!hdr) {
10547 nlmsg_free(msg);
10548 return;
10549 }
10550
10551 /*
10552 * Since we are applying the beacon hint to a wiphy we know its
10553 * wiphy_idx is valid
10554 */
David S. Miller9360ffd2012-03-29 04:41:26 -040010555 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy)))
10556 goto nla_put_failure;
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040010557
10558 /* Before */
10559 nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_BEFORE);
10560 if (!nl_freq)
10561 goto nla_put_failure;
Johannes Bergcdc89b92013-02-18 23:54:36 +010010562 if (nl80211_msg_put_channel(msg, channel_before, false))
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040010563 goto nla_put_failure;
10564 nla_nest_end(msg, nl_freq);
10565
10566 /* After */
10567 nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_AFTER);
10568 if (!nl_freq)
10569 goto nla_put_failure;
Johannes Bergcdc89b92013-02-18 23:54:36 +010010570 if (nl80211_msg_put_channel(msg, channel_after, false))
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040010571 goto nla_put_failure;
10572 nla_nest_end(msg, nl_freq);
10573
Johannes Berg3b7b72e2011-10-22 19:05:51 +020010574 genlmsg_end(msg, hdr);
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040010575
Johannes Berg463d0182009-07-14 00:33:35 +020010576 rcu_read_lock();
Johannes Berg68eb5502013-11-19 15:19:38 +010010577 genlmsg_multicast_allns(&nl80211_fam, msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010010578 NL80211_MCGRP_REGULATORY, GFP_ATOMIC);
Johannes Berg463d0182009-07-14 00:33:35 +020010579 rcu_read_unlock();
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040010580
10581 return;
10582
10583nla_put_failure:
10584 genlmsg_cancel(msg, hdr);
10585 nlmsg_free(msg);
10586}
10587
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010588static void nl80211_send_remain_on_chan_event(
10589 int cmd, struct cfg80211_registered_device *rdev,
Johannes Berg71bbc992012-06-15 15:30:18 +020010590 struct wireless_dev *wdev, u64 cookie,
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010591 struct ieee80211_channel *chan,
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010592 unsigned int duration, gfp_t gfp)
10593{
10594 struct sk_buff *msg;
10595 void *hdr;
10596
10597 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
10598 if (!msg)
10599 return;
10600
10601 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
10602 if (!hdr) {
10603 nlmsg_free(msg);
10604 return;
10605 }
10606
David S. Miller9360ffd2012-03-29 04:41:26 -040010607 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg71bbc992012-06-15 15:30:18 +020010608 (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
10609 wdev->netdev->ifindex)) ||
Johannes Berg00f53352012-07-17 11:53:12 +020010610 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040010611 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, chan->center_freq) ||
Johannes Berg42d97a52012-11-08 18:31:02 +010010612 nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE,
10613 NL80211_CHAN_NO_HT) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040010614 nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie))
10615 goto nla_put_failure;
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010616
David S. Miller9360ffd2012-03-29 04:41:26 -040010617 if (cmd == NL80211_CMD_REMAIN_ON_CHANNEL &&
10618 nla_put_u32(msg, NL80211_ATTR_DURATION, duration))
10619 goto nla_put_failure;
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010620
Johannes Berg3b7b72e2011-10-22 19:05:51 +020010621 genlmsg_end(msg, hdr);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010622
Johannes Berg68eb5502013-11-19 15:19:38 +010010623 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010010624 NL80211_MCGRP_MLME, gfp);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010625 return;
10626
10627 nla_put_failure:
10628 genlmsg_cancel(msg, hdr);
10629 nlmsg_free(msg);
10630}
10631
Johannes Berg947add32013-02-22 22:05:20 +010010632void cfg80211_ready_on_channel(struct wireless_dev *wdev, u64 cookie,
10633 struct ieee80211_channel *chan,
10634 unsigned int duration, gfp_t gfp)
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010635{
Johannes Berg947add32013-02-22 22:05:20 +010010636 struct wiphy *wiphy = wdev->wiphy;
10637 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
10638
10639 trace_cfg80211_ready_on_channel(wdev, cookie, chan, duration);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010640 nl80211_send_remain_on_chan_event(NL80211_CMD_REMAIN_ON_CHANNEL,
Johannes Berg71bbc992012-06-15 15:30:18 +020010641 rdev, wdev, cookie, chan,
Johannes Berg42d97a52012-11-08 18:31:02 +010010642 duration, gfp);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010643}
Johannes Berg947add32013-02-22 22:05:20 +010010644EXPORT_SYMBOL(cfg80211_ready_on_channel);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010645
Johannes Berg947add32013-02-22 22:05:20 +010010646void cfg80211_remain_on_channel_expired(struct wireless_dev *wdev, u64 cookie,
10647 struct ieee80211_channel *chan,
10648 gfp_t gfp)
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010649{
Johannes Berg947add32013-02-22 22:05:20 +010010650 struct wiphy *wiphy = wdev->wiphy;
10651 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
10652
10653 trace_cfg80211_ready_on_channel_expired(wdev, cookie, chan);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010654 nl80211_send_remain_on_chan_event(NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL,
Johannes Berg42d97a52012-11-08 18:31:02 +010010655 rdev, wdev, cookie, chan, 0, gfp);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010656}
Johannes Berg947add32013-02-22 22:05:20 +010010657EXPORT_SYMBOL(cfg80211_remain_on_channel_expired);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010658
Johannes Berg947add32013-02-22 22:05:20 +010010659void cfg80211_new_sta(struct net_device *dev, const u8 *mac_addr,
10660 struct station_info *sinfo, gfp_t gfp)
Johannes Berg98b62182009-12-23 13:15:44 +010010661{
Johannes Berg947add32013-02-22 22:05:20 +010010662 struct wiphy *wiphy = dev->ieee80211_ptr->wiphy;
10663 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
Johannes Berg98b62182009-12-23 13:15:44 +010010664 struct sk_buff *msg;
10665
Johannes Berg947add32013-02-22 22:05:20 +010010666 trace_cfg80211_new_sta(dev, mac_addr, sinfo);
10667
Thomas Graf58050fc2012-06-28 03:57:45 +000010668 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Johannes Berg98b62182009-12-23 13:15:44 +010010669 if (!msg)
10670 return;
10671
John W. Linville66266b32012-03-15 13:25:41 -040010672 if (nl80211_send_station(msg, 0, 0, 0,
10673 rdev, dev, mac_addr, sinfo) < 0) {
Johannes Berg98b62182009-12-23 13:15:44 +010010674 nlmsg_free(msg);
10675 return;
10676 }
10677
Johannes Berg68eb5502013-11-19 15:19:38 +010010678 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010010679 NL80211_MCGRP_MLME, gfp);
Johannes Berg98b62182009-12-23 13:15:44 +010010680}
Johannes Berg947add32013-02-22 22:05:20 +010010681EXPORT_SYMBOL(cfg80211_new_sta);
Johannes Berg98b62182009-12-23 13:15:44 +010010682
Johannes Berg947add32013-02-22 22:05:20 +010010683void cfg80211_del_sta(struct net_device *dev, const u8 *mac_addr, gfp_t gfp)
Jouni Malinenec15e682011-03-23 15:29:52 +020010684{
Johannes Berg947add32013-02-22 22:05:20 +010010685 struct wiphy *wiphy = dev->ieee80211_ptr->wiphy;
10686 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
Jouni Malinenec15e682011-03-23 15:29:52 +020010687 struct sk_buff *msg;
10688 void *hdr;
10689
Johannes Berg947add32013-02-22 22:05:20 +010010690 trace_cfg80211_del_sta(dev, mac_addr);
10691
Thomas Graf58050fc2012-06-28 03:57:45 +000010692 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinenec15e682011-03-23 15:29:52 +020010693 if (!msg)
10694 return;
10695
10696 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DEL_STATION);
10697 if (!hdr) {
10698 nlmsg_free(msg);
10699 return;
10700 }
10701
David S. Miller9360ffd2012-03-29 04:41:26 -040010702 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
10703 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr))
10704 goto nla_put_failure;
Jouni Malinenec15e682011-03-23 15:29:52 +020010705
Johannes Berg3b7b72e2011-10-22 19:05:51 +020010706 genlmsg_end(msg, hdr);
Jouni Malinenec15e682011-03-23 15:29:52 +020010707
Johannes Berg68eb5502013-11-19 15:19:38 +010010708 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010010709 NL80211_MCGRP_MLME, gfp);
Jouni Malinenec15e682011-03-23 15:29:52 +020010710 return;
10711
10712 nla_put_failure:
10713 genlmsg_cancel(msg, hdr);
10714 nlmsg_free(msg);
10715}
Johannes Berg947add32013-02-22 22:05:20 +010010716EXPORT_SYMBOL(cfg80211_del_sta);
Jouni Malinenec15e682011-03-23 15:29:52 +020010717
Johannes Berg947add32013-02-22 22:05:20 +010010718void cfg80211_conn_failed(struct net_device *dev, const u8 *mac_addr,
10719 enum nl80211_connect_failed_reason reason,
10720 gfp_t gfp)
Pandiyarajan Pitchaimuthued44a952012-09-18 16:50:49 +053010721{
Johannes Berg947add32013-02-22 22:05:20 +010010722 struct wiphy *wiphy = dev->ieee80211_ptr->wiphy;
10723 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
Pandiyarajan Pitchaimuthued44a952012-09-18 16:50:49 +053010724 struct sk_buff *msg;
10725 void *hdr;
10726
10727 msg = nlmsg_new(NLMSG_GOODSIZE, gfp);
10728 if (!msg)
10729 return;
10730
10731 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONN_FAILED);
10732 if (!hdr) {
10733 nlmsg_free(msg);
10734 return;
10735 }
10736
10737 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
10738 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) ||
10739 nla_put_u32(msg, NL80211_ATTR_CONN_FAILED_REASON, reason))
10740 goto nla_put_failure;
10741
10742 genlmsg_end(msg, hdr);
10743
Johannes Berg68eb5502013-11-19 15:19:38 +010010744 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010010745 NL80211_MCGRP_MLME, gfp);
Pandiyarajan Pitchaimuthued44a952012-09-18 16:50:49 +053010746 return;
10747
10748 nla_put_failure:
10749 genlmsg_cancel(msg, hdr);
10750 nlmsg_free(msg);
10751}
Johannes Berg947add32013-02-22 22:05:20 +010010752EXPORT_SYMBOL(cfg80211_conn_failed);
Pandiyarajan Pitchaimuthued44a952012-09-18 16:50:49 +053010753
Johannes Bergb92ab5d2011-11-04 11:18:19 +010010754static bool __nl80211_unexpected_frame(struct net_device *dev, u8 cmd,
10755 const u8 *addr, gfp_t gfp)
Johannes Berg28946da2011-11-04 11:18:12 +010010756{
10757 struct wireless_dev *wdev = dev->ieee80211_ptr;
10758 struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
10759 struct sk_buff *msg;
10760 void *hdr;
Eric W. Biederman15e47302012-09-07 20:12:54 +000010761 u32 nlportid = ACCESS_ONCE(wdev->ap_unexpected_nlportid);
Johannes Berg28946da2011-11-04 11:18:12 +010010762
Eric W. Biederman15e47302012-09-07 20:12:54 +000010763 if (!nlportid)
Johannes Berg28946da2011-11-04 11:18:12 +010010764 return false;
10765
10766 msg = nlmsg_new(100, gfp);
10767 if (!msg)
10768 return true;
10769
Johannes Bergb92ab5d2011-11-04 11:18:19 +010010770 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
Johannes Berg28946da2011-11-04 11:18:12 +010010771 if (!hdr) {
10772 nlmsg_free(msg);
10773 return true;
10774 }
10775
David S. Miller9360ffd2012-03-29 04:41:26 -040010776 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
10777 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
10778 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr))
10779 goto nla_put_failure;
Johannes Berg28946da2011-11-04 11:18:12 +010010780
Johannes Berg9c90a9f2013-06-04 12:46:03 +020010781 genlmsg_end(msg, hdr);
Eric W. Biederman15e47302012-09-07 20:12:54 +000010782 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid);
Johannes Berg28946da2011-11-04 11:18:12 +010010783 return true;
10784
10785 nla_put_failure:
10786 genlmsg_cancel(msg, hdr);
10787 nlmsg_free(msg);
10788 return true;
10789}
10790
Johannes Berg947add32013-02-22 22:05:20 +010010791bool cfg80211_rx_spurious_frame(struct net_device *dev,
10792 const u8 *addr, gfp_t gfp)
Johannes Bergb92ab5d2011-11-04 11:18:19 +010010793{
Johannes Berg947add32013-02-22 22:05:20 +010010794 struct wireless_dev *wdev = dev->ieee80211_ptr;
10795 bool ret;
Johannes Bergb92ab5d2011-11-04 11:18:19 +010010796
Johannes Berg947add32013-02-22 22:05:20 +010010797 trace_cfg80211_rx_spurious_frame(dev, addr);
10798
10799 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP &&
10800 wdev->iftype != NL80211_IFTYPE_P2P_GO)) {
10801 trace_cfg80211_return_bool(false);
10802 return false;
10803 }
10804 ret = __nl80211_unexpected_frame(dev, NL80211_CMD_UNEXPECTED_FRAME,
10805 addr, gfp);
10806 trace_cfg80211_return_bool(ret);
10807 return ret;
Johannes Bergb92ab5d2011-11-04 11:18:19 +010010808}
Johannes Berg947add32013-02-22 22:05:20 +010010809EXPORT_SYMBOL(cfg80211_rx_spurious_frame);
10810
10811bool cfg80211_rx_unexpected_4addr_frame(struct net_device *dev,
10812 const u8 *addr, gfp_t gfp)
10813{
10814 struct wireless_dev *wdev = dev->ieee80211_ptr;
10815 bool ret;
10816
10817 trace_cfg80211_rx_unexpected_4addr_frame(dev, addr);
10818
10819 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP &&
10820 wdev->iftype != NL80211_IFTYPE_P2P_GO &&
10821 wdev->iftype != NL80211_IFTYPE_AP_VLAN)) {
10822 trace_cfg80211_return_bool(false);
10823 return false;
10824 }
10825 ret = __nl80211_unexpected_frame(dev,
10826 NL80211_CMD_UNEXPECTED_4ADDR_FRAME,
10827 addr, gfp);
10828 trace_cfg80211_return_bool(ret);
10829 return ret;
10830}
10831EXPORT_SYMBOL(cfg80211_rx_unexpected_4addr_frame);
Johannes Bergb92ab5d2011-11-04 11:18:19 +010010832
Johannes Berg2e161f72010-08-12 15:38:38 +020010833int nl80211_send_mgmt(struct cfg80211_registered_device *rdev,
Eric W. Biederman15e47302012-09-07 20:12:54 +000010834 struct wireless_dev *wdev, u32 nlportid,
Johannes Berg804483e2012-03-05 22:18:41 +010010835 int freq, int sig_dbm,
Vladimir Kondratiev19504cf2013-08-15 14:51:28 +030010836 const u8 *buf, size_t len, u32 flags, gfp_t gfp)
Jouni Malinen026331c2010-02-15 12:53:10 +020010837{
Johannes Berg71bbc992012-06-15 15:30:18 +020010838 struct net_device *netdev = wdev->netdev;
Jouni Malinen026331c2010-02-15 12:53:10 +020010839 struct sk_buff *msg;
10840 void *hdr;
Jouni Malinen026331c2010-02-15 12:53:10 +020010841
10842 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
10843 if (!msg)
10844 return -ENOMEM;
10845
Johannes Berg2e161f72010-08-12 15:38:38 +020010846 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME);
Jouni Malinen026331c2010-02-15 12:53:10 +020010847 if (!hdr) {
10848 nlmsg_free(msg);
10849 return -ENOMEM;
10850 }
10851
David S. Miller9360ffd2012-03-29 04:41:26 -040010852 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg71bbc992012-06-15 15:30:18 +020010853 (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
10854 netdev->ifindex)) ||
Ilan Peera8384902013-05-08 16:35:55 +030010855 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040010856 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq) ||
10857 (sig_dbm &&
10858 nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) ||
Vladimir Kondratiev19504cf2013-08-15 14:51:28 +030010859 nla_put(msg, NL80211_ATTR_FRAME, len, buf) ||
10860 (flags &&
10861 nla_put_u32(msg, NL80211_ATTR_RXMGMT_FLAGS, flags)))
David S. Miller9360ffd2012-03-29 04:41:26 -040010862 goto nla_put_failure;
Jouni Malinen026331c2010-02-15 12:53:10 +020010863
Johannes Berg3b7b72e2011-10-22 19:05:51 +020010864 genlmsg_end(msg, hdr);
Jouni Malinen026331c2010-02-15 12:53:10 +020010865
Eric W. Biederman15e47302012-09-07 20:12:54 +000010866 return genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid);
Jouni Malinen026331c2010-02-15 12:53:10 +020010867
10868 nla_put_failure:
10869 genlmsg_cancel(msg, hdr);
10870 nlmsg_free(msg);
10871 return -ENOBUFS;
10872}
10873
Johannes Berg947add32013-02-22 22:05:20 +010010874void cfg80211_mgmt_tx_status(struct wireless_dev *wdev, u64 cookie,
10875 const u8 *buf, size_t len, bool ack, gfp_t gfp)
Jouni Malinen026331c2010-02-15 12:53:10 +020010876{
Johannes Berg947add32013-02-22 22:05:20 +010010877 struct wiphy *wiphy = wdev->wiphy;
10878 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
Johannes Berg71bbc992012-06-15 15:30:18 +020010879 struct net_device *netdev = wdev->netdev;
Jouni Malinen026331c2010-02-15 12:53:10 +020010880 struct sk_buff *msg;
10881 void *hdr;
10882
Johannes Berg947add32013-02-22 22:05:20 +010010883 trace_cfg80211_mgmt_tx_status(wdev, cookie, ack);
10884
Jouni Malinen026331c2010-02-15 12:53:10 +020010885 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
10886 if (!msg)
10887 return;
10888
Johannes Berg2e161f72010-08-12 15:38:38 +020010889 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME_TX_STATUS);
Jouni Malinen026331c2010-02-15 12:53:10 +020010890 if (!hdr) {
10891 nlmsg_free(msg);
10892 return;
10893 }
10894
David S. Miller9360ffd2012-03-29 04:41:26 -040010895 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg71bbc992012-06-15 15:30:18 +020010896 (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
10897 netdev->ifindex)) ||
Ilan Peera8384902013-05-08 16:35:55 +030010898 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040010899 nla_put(msg, NL80211_ATTR_FRAME, len, buf) ||
10900 nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie) ||
10901 (ack && nla_put_flag(msg, NL80211_ATTR_ACK)))
10902 goto nla_put_failure;
Jouni Malinen026331c2010-02-15 12:53:10 +020010903
Johannes Berg3b7b72e2011-10-22 19:05:51 +020010904 genlmsg_end(msg, hdr);
Jouni Malinen026331c2010-02-15 12:53:10 +020010905
Johannes Berg68eb5502013-11-19 15:19:38 +010010906 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010010907 NL80211_MCGRP_MLME, gfp);
Jouni Malinen026331c2010-02-15 12:53:10 +020010908 return;
10909
10910 nla_put_failure:
10911 genlmsg_cancel(msg, hdr);
10912 nlmsg_free(msg);
10913}
Johannes Berg947add32013-02-22 22:05:20 +010010914EXPORT_SYMBOL(cfg80211_mgmt_tx_status);
Jouni Malinen026331c2010-02-15 12:53:10 +020010915
Johannes Berg947add32013-02-22 22:05:20 +010010916void cfg80211_cqm_rssi_notify(struct net_device *dev,
10917 enum nl80211_cqm_rssi_threshold_event rssi_event,
10918 gfp_t gfp)
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020010919{
Johannes Berg947add32013-02-22 22:05:20 +010010920 struct wireless_dev *wdev = dev->ieee80211_ptr;
10921 struct wiphy *wiphy = wdev->wiphy;
10922 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020010923 struct sk_buff *msg;
10924 struct nlattr *pinfoattr;
10925 void *hdr;
10926
Johannes Berg947add32013-02-22 22:05:20 +010010927 trace_cfg80211_cqm_rssi_notify(dev, rssi_event);
10928
Thomas Graf58050fc2012-06-28 03:57:45 +000010929 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020010930 if (!msg)
10931 return;
10932
10933 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM);
10934 if (!hdr) {
10935 nlmsg_free(msg);
10936 return;
10937 }
10938
David S. Miller9360ffd2012-03-29 04:41:26 -040010939 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg947add32013-02-22 22:05:20 +010010940 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex))
David S. Miller9360ffd2012-03-29 04:41:26 -040010941 goto nla_put_failure;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020010942
10943 pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM);
10944 if (!pinfoattr)
10945 goto nla_put_failure;
10946
David S. Miller9360ffd2012-03-29 04:41:26 -040010947 if (nla_put_u32(msg, NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT,
10948 rssi_event))
10949 goto nla_put_failure;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020010950
10951 nla_nest_end(msg, pinfoattr);
10952
Johannes Berg3b7b72e2011-10-22 19:05:51 +020010953 genlmsg_end(msg, hdr);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020010954
Johannes Berg68eb5502013-11-19 15:19:38 +010010955 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010010956 NL80211_MCGRP_MLME, gfp);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020010957 return;
10958
10959 nla_put_failure:
10960 genlmsg_cancel(msg, hdr);
10961 nlmsg_free(msg);
10962}
Johannes Berg947add32013-02-22 22:05:20 +010010963EXPORT_SYMBOL(cfg80211_cqm_rssi_notify);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020010964
Johannes Berg947add32013-02-22 22:05:20 +010010965static void nl80211_gtk_rekey_notify(struct cfg80211_registered_device *rdev,
10966 struct net_device *netdev, const u8 *bssid,
10967 const u8 *replay_ctr, gfp_t gfp)
Johannes Berge5497d72011-07-05 16:35:40 +020010968{
10969 struct sk_buff *msg;
10970 struct nlattr *rekey_attr;
10971 void *hdr;
10972
Thomas Graf58050fc2012-06-28 03:57:45 +000010973 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Johannes Berge5497d72011-07-05 16:35:40 +020010974 if (!msg)
10975 return;
10976
10977 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_REKEY_OFFLOAD);
10978 if (!hdr) {
10979 nlmsg_free(msg);
10980 return;
10981 }
10982
David S. Miller9360ffd2012-03-29 04:41:26 -040010983 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
10984 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
10985 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid))
10986 goto nla_put_failure;
Johannes Berge5497d72011-07-05 16:35:40 +020010987
10988 rekey_attr = nla_nest_start(msg, NL80211_ATTR_REKEY_DATA);
10989 if (!rekey_attr)
10990 goto nla_put_failure;
10991
David S. Miller9360ffd2012-03-29 04:41:26 -040010992 if (nla_put(msg, NL80211_REKEY_DATA_REPLAY_CTR,
10993 NL80211_REPLAY_CTR_LEN, replay_ctr))
10994 goto nla_put_failure;
Johannes Berge5497d72011-07-05 16:35:40 +020010995
10996 nla_nest_end(msg, rekey_attr);
10997
Johannes Berg3b7b72e2011-10-22 19:05:51 +020010998 genlmsg_end(msg, hdr);
Johannes Berge5497d72011-07-05 16:35:40 +020010999
Johannes Berg68eb5502013-11-19 15:19:38 +010011000 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011001 NL80211_MCGRP_MLME, gfp);
Johannes Berge5497d72011-07-05 16:35:40 +020011002 return;
11003
11004 nla_put_failure:
11005 genlmsg_cancel(msg, hdr);
11006 nlmsg_free(msg);
11007}
11008
Johannes Berg947add32013-02-22 22:05:20 +010011009void cfg80211_gtk_rekey_notify(struct net_device *dev, const u8 *bssid,
11010 const u8 *replay_ctr, gfp_t gfp)
11011{
11012 struct wireless_dev *wdev = dev->ieee80211_ptr;
11013 struct wiphy *wiphy = wdev->wiphy;
11014 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
11015
11016 trace_cfg80211_gtk_rekey_notify(dev, bssid);
11017 nl80211_gtk_rekey_notify(rdev, dev, bssid, replay_ctr, gfp);
11018}
11019EXPORT_SYMBOL(cfg80211_gtk_rekey_notify);
11020
11021static void
11022nl80211_pmksa_candidate_notify(struct cfg80211_registered_device *rdev,
11023 struct net_device *netdev, int index,
11024 const u8 *bssid, bool preauth, gfp_t gfp)
Jouni Malinenc9df56b2011-09-16 18:56:23 +030011025{
11026 struct sk_buff *msg;
11027 struct nlattr *attr;
11028 void *hdr;
11029
Thomas Graf58050fc2012-06-28 03:57:45 +000011030 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinenc9df56b2011-09-16 18:56:23 +030011031 if (!msg)
11032 return;
11033
11034 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PMKSA_CANDIDATE);
11035 if (!hdr) {
11036 nlmsg_free(msg);
11037 return;
11038 }
11039
David S. Miller9360ffd2012-03-29 04:41:26 -040011040 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
11041 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex))
11042 goto nla_put_failure;
Jouni Malinenc9df56b2011-09-16 18:56:23 +030011043
11044 attr = nla_nest_start(msg, NL80211_ATTR_PMKSA_CANDIDATE);
11045 if (!attr)
11046 goto nla_put_failure;
11047
David S. Miller9360ffd2012-03-29 04:41:26 -040011048 if (nla_put_u32(msg, NL80211_PMKSA_CANDIDATE_INDEX, index) ||
11049 nla_put(msg, NL80211_PMKSA_CANDIDATE_BSSID, ETH_ALEN, bssid) ||
11050 (preauth &&
11051 nla_put_flag(msg, NL80211_PMKSA_CANDIDATE_PREAUTH)))
11052 goto nla_put_failure;
Jouni Malinenc9df56b2011-09-16 18:56:23 +030011053
11054 nla_nest_end(msg, attr);
11055
Johannes Berg3b7b72e2011-10-22 19:05:51 +020011056 genlmsg_end(msg, hdr);
Jouni Malinenc9df56b2011-09-16 18:56:23 +030011057
Johannes Berg68eb5502013-11-19 15:19:38 +010011058 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011059 NL80211_MCGRP_MLME, gfp);
Jouni Malinenc9df56b2011-09-16 18:56:23 +030011060 return;
11061
11062 nla_put_failure:
11063 genlmsg_cancel(msg, hdr);
11064 nlmsg_free(msg);
11065}
11066
Johannes Berg947add32013-02-22 22:05:20 +010011067void cfg80211_pmksa_candidate_notify(struct net_device *dev, int index,
11068 const u8 *bssid, bool preauth, gfp_t gfp)
11069{
11070 struct wireless_dev *wdev = dev->ieee80211_ptr;
11071 struct wiphy *wiphy = wdev->wiphy;
11072 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
11073
11074 trace_cfg80211_pmksa_candidate_notify(dev, index, bssid, preauth);
11075 nl80211_pmksa_candidate_notify(rdev, dev, index, bssid, preauth, gfp);
11076}
11077EXPORT_SYMBOL(cfg80211_pmksa_candidate_notify);
11078
11079static void nl80211_ch_switch_notify(struct cfg80211_registered_device *rdev,
11080 struct net_device *netdev,
11081 struct cfg80211_chan_def *chandef,
11082 gfp_t gfp)
Thomas Pedersen53145262012-04-06 13:35:47 -070011083{
11084 struct sk_buff *msg;
11085 void *hdr;
11086
Thomas Graf58050fc2012-06-28 03:57:45 +000011087 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Thomas Pedersen53145262012-04-06 13:35:47 -070011088 if (!msg)
11089 return;
11090
11091 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CH_SWITCH_NOTIFY);
11092 if (!hdr) {
11093 nlmsg_free(msg);
11094 return;
11095 }
11096
Johannes Berg683b6d32012-11-08 21:25:48 +010011097 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex))
11098 goto nla_put_failure;
11099
11100 if (nl80211_send_chandef(msg, chandef))
John W. Linville7eab0f62012-04-12 14:25:14 -040011101 goto nla_put_failure;
Thomas Pedersen53145262012-04-06 13:35:47 -070011102
11103 genlmsg_end(msg, hdr);
11104
Johannes Berg68eb5502013-11-19 15:19:38 +010011105 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011106 NL80211_MCGRP_MLME, gfp);
Thomas Pedersen53145262012-04-06 13:35:47 -070011107 return;
11108
11109 nla_put_failure:
11110 genlmsg_cancel(msg, hdr);
11111 nlmsg_free(msg);
11112}
11113
Johannes Berg947add32013-02-22 22:05:20 +010011114void cfg80211_ch_switch_notify(struct net_device *dev,
11115 struct cfg80211_chan_def *chandef)
Thomas Pedersen84f10702012-07-12 16:17:33 -070011116{
Johannes Berg947add32013-02-22 22:05:20 +010011117 struct wireless_dev *wdev = dev->ieee80211_ptr;
11118 struct wiphy *wiphy = wdev->wiphy;
11119 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
11120
Simon Wunderliche487eae2013-11-21 18:19:51 +010011121 ASSERT_WDEV_LOCK(wdev);
Johannes Berg947add32013-02-22 22:05:20 +010011122
Simon Wunderliche487eae2013-11-21 18:19:51 +010011123 trace_cfg80211_ch_switch_notify(dev, chandef);
Johannes Berg947add32013-02-22 22:05:20 +010011124
11125 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP &&
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +020011126 wdev->iftype != NL80211_IFTYPE_P2P_GO &&
Chun-Yeow Yeohb8456a12013-10-17 15:55:02 -070011127 wdev->iftype != NL80211_IFTYPE_ADHOC &&
11128 wdev->iftype != NL80211_IFTYPE_MESH_POINT))
Simon Wunderliche487eae2013-11-21 18:19:51 +010011129 return;
Johannes Berg947add32013-02-22 22:05:20 +010011130
11131 wdev->channel = chandef->chan;
11132 nl80211_ch_switch_notify(rdev, dev, chandef, GFP_KERNEL);
Johannes Berg947add32013-02-22 22:05:20 +010011133}
11134EXPORT_SYMBOL(cfg80211_ch_switch_notify);
11135
11136void cfg80211_cqm_txe_notify(struct net_device *dev,
11137 const u8 *peer, u32 num_packets,
11138 u32 rate, u32 intvl, gfp_t gfp)
11139{
11140 struct wireless_dev *wdev = dev->ieee80211_ptr;
11141 struct wiphy *wiphy = wdev->wiphy;
11142 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
Thomas Pedersen84f10702012-07-12 16:17:33 -070011143 struct sk_buff *msg;
11144 struct nlattr *pinfoattr;
11145 void *hdr;
11146
11147 msg = nlmsg_new(NLMSG_GOODSIZE, gfp);
11148 if (!msg)
11149 return;
11150
11151 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM);
11152 if (!hdr) {
11153 nlmsg_free(msg);
11154 return;
11155 }
11156
11157 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg947add32013-02-22 22:05:20 +010011158 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
Thomas Pedersen84f10702012-07-12 16:17:33 -070011159 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer))
11160 goto nla_put_failure;
11161
11162 pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM);
11163 if (!pinfoattr)
11164 goto nla_put_failure;
11165
11166 if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_PKTS, num_packets))
11167 goto nla_put_failure;
11168
11169 if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_RATE, rate))
11170 goto nla_put_failure;
11171
11172 if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_INTVL, intvl))
11173 goto nla_put_failure;
11174
11175 nla_nest_end(msg, pinfoattr);
11176
11177 genlmsg_end(msg, hdr);
11178
Johannes Berg68eb5502013-11-19 15:19:38 +010011179 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011180 NL80211_MCGRP_MLME, gfp);
Thomas Pedersen84f10702012-07-12 16:17:33 -070011181 return;
11182
11183 nla_put_failure:
11184 genlmsg_cancel(msg, hdr);
11185 nlmsg_free(msg);
11186}
Johannes Berg947add32013-02-22 22:05:20 +010011187EXPORT_SYMBOL(cfg80211_cqm_txe_notify);
Thomas Pedersen84f10702012-07-12 16:17:33 -070011188
11189void
Simon Wunderlich04f39042013-02-08 18:16:19 +010011190nl80211_radar_notify(struct cfg80211_registered_device *rdev,
Janusz Dziedzicd2859df2013-11-06 13:55:51 +010011191 const struct cfg80211_chan_def *chandef,
Simon Wunderlich04f39042013-02-08 18:16:19 +010011192 enum nl80211_radar_event event,
11193 struct net_device *netdev, gfp_t gfp)
11194{
11195 struct sk_buff *msg;
11196 void *hdr;
11197
11198 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
11199 if (!msg)
11200 return;
11201
11202 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_RADAR_DETECT);
11203 if (!hdr) {
11204 nlmsg_free(msg);
11205 return;
11206 }
11207
11208 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx))
11209 goto nla_put_failure;
11210
11211 /* NOP and radar events don't need a netdev parameter */
11212 if (netdev) {
11213 struct wireless_dev *wdev = netdev->ieee80211_ptr;
11214
11215 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
11216 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)))
11217 goto nla_put_failure;
11218 }
11219
11220 if (nla_put_u32(msg, NL80211_ATTR_RADAR_EVENT, event))
11221 goto nla_put_failure;
11222
11223 if (nl80211_send_chandef(msg, chandef))
11224 goto nla_put_failure;
11225
Johannes Berg9c90a9f2013-06-04 12:46:03 +020011226 genlmsg_end(msg, hdr);
Simon Wunderlich04f39042013-02-08 18:16:19 +010011227
Johannes Berg68eb5502013-11-19 15:19:38 +010011228 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011229 NL80211_MCGRP_MLME, gfp);
Simon Wunderlich04f39042013-02-08 18:16:19 +010011230 return;
11231
11232 nla_put_failure:
11233 genlmsg_cancel(msg, hdr);
11234 nlmsg_free(msg);
11235}
11236
Johannes Berg947add32013-02-22 22:05:20 +010011237void cfg80211_cqm_pktloss_notify(struct net_device *dev,
11238 const u8 *peer, u32 num_packets, gfp_t gfp)
Johannes Bergc063dbf2010-11-24 08:10:05 +010011239{
Johannes Berg947add32013-02-22 22:05:20 +010011240 struct wireless_dev *wdev = dev->ieee80211_ptr;
11241 struct wiphy *wiphy = wdev->wiphy;
11242 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
Johannes Bergc063dbf2010-11-24 08:10:05 +010011243 struct sk_buff *msg;
11244 struct nlattr *pinfoattr;
11245 void *hdr;
11246
Johannes Berg947add32013-02-22 22:05:20 +010011247 trace_cfg80211_cqm_pktloss_notify(dev, peer, num_packets);
11248
Thomas Graf58050fc2012-06-28 03:57:45 +000011249 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Johannes Bergc063dbf2010-11-24 08:10:05 +010011250 if (!msg)
11251 return;
11252
11253 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM);
11254 if (!hdr) {
11255 nlmsg_free(msg);
11256 return;
11257 }
11258
David S. Miller9360ffd2012-03-29 04:41:26 -040011259 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg947add32013-02-22 22:05:20 +010011260 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040011261 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer))
11262 goto nla_put_failure;
Johannes Bergc063dbf2010-11-24 08:10:05 +010011263
11264 pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM);
11265 if (!pinfoattr)
11266 goto nla_put_failure;
11267
David S. Miller9360ffd2012-03-29 04:41:26 -040011268 if (nla_put_u32(msg, NL80211_ATTR_CQM_PKT_LOSS_EVENT, num_packets))
11269 goto nla_put_failure;
Johannes Bergc063dbf2010-11-24 08:10:05 +010011270
11271 nla_nest_end(msg, pinfoattr);
11272
Johannes Berg3b7b72e2011-10-22 19:05:51 +020011273 genlmsg_end(msg, hdr);
Johannes Bergc063dbf2010-11-24 08:10:05 +010011274
Johannes Berg68eb5502013-11-19 15:19:38 +010011275 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011276 NL80211_MCGRP_MLME, gfp);
Johannes Bergc063dbf2010-11-24 08:10:05 +010011277 return;
11278
11279 nla_put_failure:
11280 genlmsg_cancel(msg, hdr);
11281 nlmsg_free(msg);
11282}
Johannes Berg947add32013-02-22 22:05:20 +010011283EXPORT_SYMBOL(cfg80211_cqm_pktloss_notify);
Johannes Bergc063dbf2010-11-24 08:10:05 +010011284
Johannes Berg7f6cf312011-11-04 11:18:15 +010011285void cfg80211_probe_status(struct net_device *dev, const u8 *addr,
11286 u64 cookie, bool acked, gfp_t gfp)
11287{
11288 struct wireless_dev *wdev = dev->ieee80211_ptr;
11289 struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
11290 struct sk_buff *msg;
11291 void *hdr;
Johannes Berg7f6cf312011-11-04 11:18:15 +010011292
Beni Lev4ee3e062012-08-27 12:49:39 +030011293 trace_cfg80211_probe_status(dev, addr, cookie, acked);
11294
Thomas Graf58050fc2012-06-28 03:57:45 +000011295 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Beni Lev4ee3e062012-08-27 12:49:39 +030011296
Johannes Berg7f6cf312011-11-04 11:18:15 +010011297 if (!msg)
11298 return;
11299
11300 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PROBE_CLIENT);
11301 if (!hdr) {
11302 nlmsg_free(msg);
11303 return;
11304 }
11305
David S. Miller9360ffd2012-03-29 04:41:26 -040011306 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
11307 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
11308 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) ||
11309 nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie) ||
11310 (acked && nla_put_flag(msg, NL80211_ATTR_ACK)))
11311 goto nla_put_failure;
Johannes Berg7f6cf312011-11-04 11:18:15 +010011312
Johannes Berg9c90a9f2013-06-04 12:46:03 +020011313 genlmsg_end(msg, hdr);
Johannes Berg7f6cf312011-11-04 11:18:15 +010011314
Johannes Berg68eb5502013-11-19 15:19:38 +010011315 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011316 NL80211_MCGRP_MLME, gfp);
Johannes Berg7f6cf312011-11-04 11:18:15 +010011317 return;
11318
11319 nla_put_failure:
11320 genlmsg_cancel(msg, hdr);
11321 nlmsg_free(msg);
11322}
11323EXPORT_SYMBOL(cfg80211_probe_status);
11324
Johannes Berg5e760232011-11-04 11:18:17 +010011325void cfg80211_report_obss_beacon(struct wiphy *wiphy,
11326 const u8 *frame, size_t len,
Ben Greear37c73b52012-10-26 14:49:25 -070011327 int freq, int sig_dbm)
Johannes Berg5e760232011-11-04 11:18:17 +010011328{
11329 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
11330 struct sk_buff *msg;
11331 void *hdr;
Ben Greear37c73b52012-10-26 14:49:25 -070011332 struct cfg80211_beacon_registration *reg;
Johannes Berg5e760232011-11-04 11:18:17 +010011333
Beni Lev4ee3e062012-08-27 12:49:39 +030011334 trace_cfg80211_report_obss_beacon(wiphy, frame, len, freq, sig_dbm);
11335
Ben Greear37c73b52012-10-26 14:49:25 -070011336 spin_lock_bh(&rdev->beacon_registrations_lock);
11337 list_for_each_entry(reg, &rdev->beacon_registrations, list) {
11338 msg = nlmsg_new(len + 100, GFP_ATOMIC);
11339 if (!msg) {
11340 spin_unlock_bh(&rdev->beacon_registrations_lock);
11341 return;
11342 }
Johannes Berg5e760232011-11-04 11:18:17 +010011343
Ben Greear37c73b52012-10-26 14:49:25 -070011344 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME);
11345 if (!hdr)
11346 goto nla_put_failure;
Johannes Berg5e760232011-11-04 11:18:17 +010011347
Ben Greear37c73b52012-10-26 14:49:25 -070011348 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
11349 (freq &&
11350 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq)) ||
11351 (sig_dbm &&
11352 nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) ||
11353 nla_put(msg, NL80211_ATTR_FRAME, len, frame))
11354 goto nla_put_failure;
11355
11356 genlmsg_end(msg, hdr);
11357
11358 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, reg->nlportid);
Johannes Berg5e760232011-11-04 11:18:17 +010011359 }
Ben Greear37c73b52012-10-26 14:49:25 -070011360 spin_unlock_bh(&rdev->beacon_registrations_lock);
Johannes Berg5e760232011-11-04 11:18:17 +010011361 return;
11362
11363 nla_put_failure:
Ben Greear37c73b52012-10-26 14:49:25 -070011364 spin_unlock_bh(&rdev->beacon_registrations_lock);
11365 if (hdr)
11366 genlmsg_cancel(msg, hdr);
Johannes Berg5e760232011-11-04 11:18:17 +010011367 nlmsg_free(msg);
11368}
11369EXPORT_SYMBOL(cfg80211_report_obss_beacon);
11370
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010011371#ifdef CONFIG_PM
11372void cfg80211_report_wowlan_wakeup(struct wireless_dev *wdev,
11373 struct cfg80211_wowlan_wakeup *wakeup,
11374 gfp_t gfp)
11375{
11376 struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
11377 struct sk_buff *msg;
11378 void *hdr;
Johannes Berg9c90a9f2013-06-04 12:46:03 +020011379 int size = 200;
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010011380
11381 trace_cfg80211_report_wowlan_wakeup(wdev->wiphy, wdev, wakeup);
11382
11383 if (wakeup)
11384 size += wakeup->packet_present_len;
11385
11386 msg = nlmsg_new(size, gfp);
11387 if (!msg)
11388 return;
11389
11390 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_WOWLAN);
11391 if (!hdr)
11392 goto free_msg;
11393
11394 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
11395 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)))
11396 goto free_msg;
11397
11398 if (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
11399 wdev->netdev->ifindex))
11400 goto free_msg;
11401
11402 if (wakeup) {
11403 struct nlattr *reasons;
11404
11405 reasons = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS);
Johannes Berg7fa322c2013-10-25 11:16:58 +020011406 if (!reasons)
11407 goto free_msg;
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010011408
11409 if (wakeup->disconnect &&
11410 nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT))
11411 goto free_msg;
11412 if (wakeup->magic_pkt &&
11413 nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT))
11414 goto free_msg;
11415 if (wakeup->gtk_rekey_failure &&
11416 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE))
11417 goto free_msg;
11418 if (wakeup->eap_identity_req &&
11419 nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST))
11420 goto free_msg;
11421 if (wakeup->four_way_handshake &&
11422 nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE))
11423 goto free_msg;
11424 if (wakeup->rfkill_release &&
11425 nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE))
11426 goto free_msg;
11427
11428 if (wakeup->pattern_idx >= 0 &&
11429 nla_put_u32(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN,
11430 wakeup->pattern_idx))
11431 goto free_msg;
11432
Johannes Bergae917c92013-10-25 11:05:22 +020011433 if (wakeup->tcp_match &&
11434 nla_put_flag(msg, NL80211_WOWLAN_TRIG_WAKEUP_TCP_MATCH))
11435 goto free_msg;
Johannes Berg2a0e0472013-01-23 22:57:40 +010011436
Johannes Bergae917c92013-10-25 11:05:22 +020011437 if (wakeup->tcp_connlost &&
11438 nla_put_flag(msg, NL80211_WOWLAN_TRIG_WAKEUP_TCP_CONNLOST))
11439 goto free_msg;
Johannes Berg2a0e0472013-01-23 22:57:40 +010011440
Johannes Bergae917c92013-10-25 11:05:22 +020011441 if (wakeup->tcp_nomoretokens &&
11442 nla_put_flag(msg,
11443 NL80211_WOWLAN_TRIG_WAKEUP_TCP_NOMORETOKENS))
11444 goto free_msg;
Johannes Berg2a0e0472013-01-23 22:57:40 +010011445
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010011446 if (wakeup->packet) {
11447 u32 pkt_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211;
11448 u32 len_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211_LEN;
11449
11450 if (!wakeup->packet_80211) {
11451 pkt_attr =
11452 NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023;
11453 len_attr =
11454 NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023_LEN;
11455 }
11456
11457 if (wakeup->packet_len &&
11458 nla_put_u32(msg, len_attr, wakeup->packet_len))
11459 goto free_msg;
11460
11461 if (nla_put(msg, pkt_attr, wakeup->packet_present_len,
11462 wakeup->packet))
11463 goto free_msg;
11464 }
11465
11466 nla_nest_end(msg, reasons);
11467 }
11468
Johannes Berg9c90a9f2013-06-04 12:46:03 +020011469 genlmsg_end(msg, hdr);
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010011470
Johannes Berg68eb5502013-11-19 15:19:38 +010011471 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011472 NL80211_MCGRP_MLME, gfp);
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010011473 return;
11474
11475 free_msg:
11476 nlmsg_free(msg);
11477}
11478EXPORT_SYMBOL(cfg80211_report_wowlan_wakeup);
11479#endif
11480
Jouni Malinen3475b092012-11-16 22:49:57 +020011481void cfg80211_tdls_oper_request(struct net_device *dev, const u8 *peer,
11482 enum nl80211_tdls_operation oper,
11483 u16 reason_code, gfp_t gfp)
11484{
11485 struct wireless_dev *wdev = dev->ieee80211_ptr;
11486 struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
11487 struct sk_buff *msg;
11488 void *hdr;
Jouni Malinen3475b092012-11-16 22:49:57 +020011489
11490 trace_cfg80211_tdls_oper_request(wdev->wiphy, dev, peer, oper,
11491 reason_code);
11492
11493 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
11494 if (!msg)
11495 return;
11496
11497 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_TDLS_OPER);
11498 if (!hdr) {
11499 nlmsg_free(msg);
11500 return;
11501 }
11502
11503 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
11504 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
11505 nla_put_u8(msg, NL80211_ATTR_TDLS_OPERATION, oper) ||
11506 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer) ||
11507 (reason_code > 0 &&
11508 nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason_code)))
11509 goto nla_put_failure;
11510
Johannes Berg9c90a9f2013-06-04 12:46:03 +020011511 genlmsg_end(msg, hdr);
Jouni Malinen3475b092012-11-16 22:49:57 +020011512
Johannes Berg68eb5502013-11-19 15:19:38 +010011513 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011514 NL80211_MCGRP_MLME, gfp);
Jouni Malinen3475b092012-11-16 22:49:57 +020011515 return;
11516
11517 nla_put_failure:
11518 genlmsg_cancel(msg, hdr);
11519 nlmsg_free(msg);
11520}
11521EXPORT_SYMBOL(cfg80211_tdls_oper_request);
11522
Jouni Malinen026331c2010-02-15 12:53:10 +020011523static int nl80211_netlink_notify(struct notifier_block * nb,
11524 unsigned long state,
11525 void *_notify)
11526{
11527 struct netlink_notify *notify = _notify;
11528 struct cfg80211_registered_device *rdev;
11529 struct wireless_dev *wdev;
Ben Greear37c73b52012-10-26 14:49:25 -070011530 struct cfg80211_beacon_registration *reg, *tmp;
Jouni Malinen026331c2010-02-15 12:53:10 +020011531
11532 if (state != NETLINK_URELEASE)
11533 return NOTIFY_DONE;
11534
11535 rcu_read_lock();
11536
Johannes Berg5e760232011-11-04 11:18:17 +010011537 list_for_each_entry_rcu(rdev, &cfg80211_rdev_list, list) {
Johannes Berg89a54e42012-06-15 14:33:17 +020011538 list_for_each_entry_rcu(wdev, &rdev->wdev_list, list)
Eric W. Biederman15e47302012-09-07 20:12:54 +000011539 cfg80211_mlme_unregister_socket(wdev, notify->portid);
Ben Greear37c73b52012-10-26 14:49:25 -070011540
11541 spin_lock_bh(&rdev->beacon_registrations_lock);
11542 list_for_each_entry_safe(reg, tmp, &rdev->beacon_registrations,
11543 list) {
11544 if (reg->nlportid == notify->portid) {
11545 list_del(&reg->list);
11546 kfree(reg);
11547 break;
11548 }
11549 }
11550 spin_unlock_bh(&rdev->beacon_registrations_lock);
Johannes Berg5e760232011-11-04 11:18:17 +010011551 }
Jouni Malinen026331c2010-02-15 12:53:10 +020011552
11553 rcu_read_unlock();
11554
11555 return NOTIFY_DONE;
11556}
11557
11558static struct notifier_block nl80211_netlink_notifier = {
11559 .notifier_call = nl80211_netlink_notify,
11560};
11561
Jouni Malinen355199e2013-02-27 17:14:27 +020011562void cfg80211_ft_event(struct net_device *netdev,
11563 struct cfg80211_ft_event_params *ft_event)
11564{
11565 struct wiphy *wiphy = netdev->ieee80211_ptr->wiphy;
11566 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
11567 struct sk_buff *msg;
11568 void *hdr;
Jouni Malinen355199e2013-02-27 17:14:27 +020011569
11570 trace_cfg80211_ft_event(wiphy, netdev, ft_event);
11571
11572 if (!ft_event->target_ap)
11573 return;
11574
11575 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
11576 if (!msg)
11577 return;
11578
11579 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FT_EVENT);
Johannes Bergae917c92013-10-25 11:05:22 +020011580 if (!hdr)
11581 goto out;
Jouni Malinen355199e2013-02-27 17:14:27 +020011582
Johannes Bergae917c92013-10-25 11:05:22 +020011583 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
11584 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
11585 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, ft_event->target_ap))
11586 goto out;
11587
11588 if (ft_event->ies &&
11589 nla_put(msg, NL80211_ATTR_IE, ft_event->ies_len, ft_event->ies))
11590 goto out;
11591 if (ft_event->ric_ies &&
11592 nla_put(msg, NL80211_ATTR_IE_RIC, ft_event->ric_ies_len,
11593 ft_event->ric_ies))
11594 goto out;
Jouni Malinen355199e2013-02-27 17:14:27 +020011595
Johannes Berg9c90a9f2013-06-04 12:46:03 +020011596 genlmsg_end(msg, hdr);
Jouni Malinen355199e2013-02-27 17:14:27 +020011597
Johannes Berg68eb5502013-11-19 15:19:38 +010011598 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011599 NL80211_MCGRP_MLME, GFP_KERNEL);
Johannes Bergae917c92013-10-25 11:05:22 +020011600 return;
11601 out:
11602 nlmsg_free(msg);
Jouni Malinen355199e2013-02-27 17:14:27 +020011603}
11604EXPORT_SYMBOL(cfg80211_ft_event);
11605
Arend van Spriel5de17982013-04-18 15:49:00 +020011606void cfg80211_crit_proto_stopped(struct wireless_dev *wdev, gfp_t gfp)
11607{
11608 struct cfg80211_registered_device *rdev;
11609 struct sk_buff *msg;
11610 void *hdr;
11611 u32 nlportid;
11612
11613 rdev = wiphy_to_dev(wdev->wiphy);
11614 if (!rdev->crit_proto_nlportid)
11615 return;
11616
11617 nlportid = rdev->crit_proto_nlportid;
11618 rdev->crit_proto_nlportid = 0;
11619
11620 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
11621 if (!msg)
11622 return;
11623
11624 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CRIT_PROTOCOL_STOP);
11625 if (!hdr)
11626 goto nla_put_failure;
11627
11628 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
11629 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)))
11630 goto nla_put_failure;
11631
11632 genlmsg_end(msg, hdr);
11633
11634 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid);
11635 return;
11636
11637 nla_put_failure:
11638 if (hdr)
11639 genlmsg_cancel(msg, hdr);
11640 nlmsg_free(msg);
11641
11642}
11643EXPORT_SYMBOL(cfg80211_crit_proto_stopped);
11644
Johannes Berg55682962007-09-20 13:09:35 -040011645/* initialisation/exit functions */
11646
11647int nl80211_init(void)
11648{
Michał Mirosław0d63cbb2009-05-21 10:34:06 +000011649 int err;
Johannes Berg55682962007-09-20 13:09:35 -040011650
Johannes Berg2a94fe42013-11-19 15:19:39 +010011651 err = genl_register_family_with_ops_groups(&nl80211_fam, nl80211_ops,
11652 nl80211_mcgrps);
Johannes Berg55682962007-09-20 13:09:35 -040011653 if (err)
11654 return err;
11655
Jouni Malinen026331c2010-02-15 12:53:10 +020011656 err = netlink_register_notifier(&nl80211_netlink_notifier);
11657 if (err)
11658 goto err_out;
11659
Johannes Berg55682962007-09-20 13:09:35 -040011660 return 0;
11661 err_out:
11662 genl_unregister_family(&nl80211_fam);
11663 return err;
11664}
11665
11666void nl80211_exit(void)
11667{
Jouni Malinen026331c2010-02-15 12:53:10 +020011668 netlink_unregister_notifier(&nl80211_netlink_notifier);
Johannes Berg55682962007-09-20 13:09:35 -040011669 genl_unregister_family(&nl80211_fam);
11670}