blob: 3011401f52c0a34317b2310dfa59912d4afe760c [file] [log] [blame]
Johannes Berg55682962007-09-20 13:09:35 -04001/*
2 * This is the new netlink-based wireless configuration interface.
3 *
Jouni Malinen026331c2010-02-15 12:53:10 +02004 * Copyright 2006-2010 Johannes Berg <johannes@sipsolutions.net>
Johannes Berg55682962007-09-20 13:09:35 -04005 */
6
7#include <linux/if.h>
8#include <linux/module.h>
9#include <linux/err.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090010#include <linux/slab.h>
Johannes Berg55682962007-09-20 13:09:35 -040011#include <linux/list.h>
12#include <linux/if_ether.h>
13#include <linux/ieee80211.h>
14#include <linux/nl80211.h>
15#include <linux/rtnetlink.h>
16#include <linux/netlink.h>
Johannes Berg2a519312009-02-10 21:25:55 +010017#include <linux/etherdevice.h>
Johannes Berg463d0182009-07-14 00:33:35 +020018#include <net/net_namespace.h>
Johannes Berg55682962007-09-20 13:09:35 -040019#include <net/genetlink.h>
20#include <net/cfg80211.h>
Johannes Berg463d0182009-07-14 00:33:35 +020021#include <net/sock.h>
Johannes Berg2a0e0472013-01-23 22:57:40 +010022#include <net/inet_connection_sock.h>
Johannes Berg55682962007-09-20 13:09:35 -040023#include "core.h"
24#include "nl80211.h"
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -070025#include "reg.h"
Hila Gonene35e4d22012-06-27 17:19:42 +030026#include "rdev-ops.h"
Johannes Berg55682962007-09-20 13:09:35 -040027
Jouni Malinen5fb628e2011-08-10 23:54:35 +030028static int nl80211_crypto_settings(struct cfg80211_registered_device *rdev,
29 struct genl_info *info,
30 struct cfg80211_crypto_settings *settings,
31 int cipher_limit);
32
Johannes Bergf84f7712013-11-14 17:14:45 +010033static int nl80211_pre_doit(const struct genl_ops *ops, struct sk_buff *skb,
Johannes Berg4c476992010-10-04 21:36:35 +020034 struct genl_info *info);
Johannes Bergf84f7712013-11-14 17:14:45 +010035static void nl80211_post_doit(const struct genl_ops *ops, struct sk_buff *skb,
Johannes Berg4c476992010-10-04 21:36:35 +020036 struct genl_info *info);
37
Johannes Berg55682962007-09-20 13:09:35 -040038/* the netlink family */
39static struct genl_family nl80211_fam = {
Marcel Holtmannfb4e1562013-04-28 16:22:06 -070040 .id = GENL_ID_GENERATE, /* don't bother with a hardcoded ID */
41 .name = NL80211_GENL_NAME, /* have users key off the name instead */
42 .hdrsize = 0, /* no private header */
43 .version = 1, /* no particular meaning now */
Johannes Berg55682962007-09-20 13:09:35 -040044 .maxattr = NL80211_ATTR_MAX,
Johannes Berg463d0182009-07-14 00:33:35 +020045 .netnsok = true,
Johannes Berg4c476992010-10-04 21:36:35 +020046 .pre_doit = nl80211_pre_doit,
47 .post_doit = nl80211_post_doit,
Johannes Berg55682962007-09-20 13:09:35 -040048};
49
Johannes Berg2a94fe42013-11-19 15:19:39 +010050/* multicast groups */
51enum nl80211_multicast_groups {
52 NL80211_MCGRP_CONFIG,
53 NL80211_MCGRP_SCAN,
54 NL80211_MCGRP_REGULATORY,
55 NL80211_MCGRP_MLME,
Johannes Berg567ffc32013-12-18 14:43:31 +010056 NL80211_MCGRP_VENDOR,
Johannes Berg2a94fe42013-11-19 15:19:39 +010057 NL80211_MCGRP_TESTMODE /* keep last - ifdef! */
58};
59
60static const struct genl_multicast_group nl80211_mcgrps[] = {
61 [NL80211_MCGRP_CONFIG] = { .name = "config", },
62 [NL80211_MCGRP_SCAN] = { .name = "scan", },
63 [NL80211_MCGRP_REGULATORY] = { .name = "regulatory", },
64 [NL80211_MCGRP_MLME] = { .name = "mlme", },
Johannes Berg567ffc32013-12-18 14:43:31 +010065 [NL80211_MCGRP_VENDOR] = { .name = "vendor", },
Johannes Berg2a94fe42013-11-19 15:19:39 +010066#ifdef CONFIG_NL80211_TESTMODE
67 [NL80211_MCGRP_TESTMODE] = { .name = "testmode", }
68#endif
69};
70
Johannes Berg89a54e42012-06-15 14:33:17 +020071/* returns ERR_PTR values */
72static struct wireless_dev *
73__cfg80211_wdev_from_attrs(struct net *netns, struct nlattr **attrs)
Johannes Berg55682962007-09-20 13:09:35 -040074{
Johannes Berg89a54e42012-06-15 14:33:17 +020075 struct cfg80211_registered_device *rdev;
76 struct wireless_dev *result = NULL;
77 bool have_ifidx = attrs[NL80211_ATTR_IFINDEX];
78 bool have_wdev_id = attrs[NL80211_ATTR_WDEV];
79 u64 wdev_id;
80 int wiphy_idx = -1;
81 int ifidx = -1;
Johannes Berg55682962007-09-20 13:09:35 -040082
Johannes Berg5fe231e2013-05-08 21:45:15 +020083 ASSERT_RTNL();
Johannes Berg55682962007-09-20 13:09:35 -040084
Johannes Berg89a54e42012-06-15 14:33:17 +020085 if (!have_ifidx && !have_wdev_id)
86 return ERR_PTR(-EINVAL);
Johannes Berg55682962007-09-20 13:09:35 -040087
Johannes Berg89a54e42012-06-15 14:33:17 +020088 if (have_ifidx)
89 ifidx = nla_get_u32(attrs[NL80211_ATTR_IFINDEX]);
90 if (have_wdev_id) {
91 wdev_id = nla_get_u64(attrs[NL80211_ATTR_WDEV]);
92 wiphy_idx = wdev_id >> 32;
Johannes Berg55682962007-09-20 13:09:35 -040093 }
94
Johannes Berg89a54e42012-06-15 14:33:17 +020095 list_for_each_entry(rdev, &cfg80211_rdev_list, list) {
96 struct wireless_dev *wdev;
97
98 if (wiphy_net(&rdev->wiphy) != netns)
99 continue;
100
101 if (have_wdev_id && rdev->wiphy_idx != wiphy_idx)
102 continue;
103
Johannes Berg89a54e42012-06-15 14:33:17 +0200104 list_for_each_entry(wdev, &rdev->wdev_list, list) {
105 if (have_ifidx && wdev->netdev &&
106 wdev->netdev->ifindex == ifidx) {
107 result = wdev;
108 break;
109 }
110 if (have_wdev_id && wdev->identifier == (u32)wdev_id) {
111 result = wdev;
112 break;
113 }
114 }
Johannes Berg89a54e42012-06-15 14:33:17 +0200115
116 if (result)
117 break;
118 }
119
120 if (result)
121 return result;
122 return ERR_PTR(-ENODEV);
Johannes Berg55682962007-09-20 13:09:35 -0400123}
124
Johannes Berga9455402012-06-15 13:32:49 +0200125static struct cfg80211_registered_device *
Johannes Berg878d9ec2012-06-15 14:18:32 +0200126__cfg80211_rdev_from_attrs(struct net *netns, struct nlattr **attrs)
Johannes Berga9455402012-06-15 13:32:49 +0200127{
Johannes Berg7fee4772012-06-15 14:09:58 +0200128 struct cfg80211_registered_device *rdev = NULL, *tmp;
129 struct net_device *netdev;
Johannes Berga9455402012-06-15 13:32:49 +0200130
Johannes Berg5fe231e2013-05-08 21:45:15 +0200131 ASSERT_RTNL();
Johannes Berga9455402012-06-15 13:32:49 +0200132
Johannes Berg878d9ec2012-06-15 14:18:32 +0200133 if (!attrs[NL80211_ATTR_WIPHY] &&
Johannes Berg89a54e42012-06-15 14:33:17 +0200134 !attrs[NL80211_ATTR_IFINDEX] &&
135 !attrs[NL80211_ATTR_WDEV])
Johannes Berg7fee4772012-06-15 14:09:58 +0200136 return ERR_PTR(-EINVAL);
137
Johannes Berg878d9ec2012-06-15 14:18:32 +0200138 if (attrs[NL80211_ATTR_WIPHY])
Johannes Berg7fee4772012-06-15 14:09:58 +0200139 rdev = cfg80211_rdev_by_wiphy_idx(
Johannes Berg878d9ec2012-06-15 14:18:32 +0200140 nla_get_u32(attrs[NL80211_ATTR_WIPHY]));
Johannes Berga9455402012-06-15 13:32:49 +0200141
Johannes Berg89a54e42012-06-15 14:33:17 +0200142 if (attrs[NL80211_ATTR_WDEV]) {
143 u64 wdev_id = nla_get_u64(attrs[NL80211_ATTR_WDEV]);
144 struct wireless_dev *wdev;
145 bool found = false;
146
147 tmp = cfg80211_rdev_by_wiphy_idx(wdev_id >> 32);
148 if (tmp) {
149 /* make sure wdev exists */
Johannes Berg89a54e42012-06-15 14:33:17 +0200150 list_for_each_entry(wdev, &tmp->wdev_list, list) {
151 if (wdev->identifier != (u32)wdev_id)
152 continue;
153 found = true;
154 break;
155 }
Johannes Berg89a54e42012-06-15 14:33:17 +0200156
157 if (!found)
158 tmp = NULL;
159
160 if (rdev && tmp != rdev)
161 return ERR_PTR(-EINVAL);
162 rdev = tmp;
163 }
164 }
165
Johannes Berg878d9ec2012-06-15 14:18:32 +0200166 if (attrs[NL80211_ATTR_IFINDEX]) {
167 int ifindex = nla_get_u32(attrs[NL80211_ATTR_IFINDEX]);
Ying Xue7f2b8562014-01-15 10:23:45 +0800168 netdev = __dev_get_by_index(netns, ifindex);
Johannes Berg7fee4772012-06-15 14:09:58 +0200169 if (netdev) {
170 if (netdev->ieee80211_ptr)
Zhao, Gangf26cbf42014-04-21 12:53:03 +0800171 tmp = wiphy_to_rdev(
172 netdev->ieee80211_ptr->wiphy);
Johannes Berg7fee4772012-06-15 14:09:58 +0200173 else
174 tmp = NULL;
175
Johannes Berg7fee4772012-06-15 14:09:58 +0200176 /* not wireless device -- return error */
177 if (!tmp)
178 return ERR_PTR(-EINVAL);
179
180 /* mismatch -- return error */
181 if (rdev && tmp != rdev)
182 return ERR_PTR(-EINVAL);
183
184 rdev = tmp;
Johannes Berga9455402012-06-15 13:32:49 +0200185 }
Johannes Berga9455402012-06-15 13:32:49 +0200186 }
187
Johannes Berg4f7eff12012-06-15 14:14:22 +0200188 if (!rdev)
189 return ERR_PTR(-ENODEV);
Johannes Berga9455402012-06-15 13:32:49 +0200190
Johannes Berg4f7eff12012-06-15 14:14:22 +0200191 if (netns != wiphy_net(&rdev->wiphy))
192 return ERR_PTR(-ENODEV);
193
194 return rdev;
Johannes Berga9455402012-06-15 13:32:49 +0200195}
196
197/*
198 * This function returns a pointer to the driver
199 * that the genl_info item that is passed refers to.
Johannes Berga9455402012-06-15 13:32:49 +0200200 *
201 * The result of this can be a PTR_ERR and hence must
202 * be checked with IS_ERR() for errors.
203 */
204static struct cfg80211_registered_device *
Johannes Berg4f7eff12012-06-15 14:14:22 +0200205cfg80211_get_dev_from_info(struct net *netns, struct genl_info *info)
Johannes Berga9455402012-06-15 13:32:49 +0200206{
Johannes Berg5fe231e2013-05-08 21:45:15 +0200207 return __cfg80211_rdev_from_attrs(netns, info->attrs);
Johannes Berga9455402012-06-15 13:32:49 +0200208}
209
Johannes Berg55682962007-09-20 13:09:35 -0400210/* policy for the attributes */
Alexey Dobriyanb54452b2010-02-18 08:14:31 +0000211static const struct nla_policy nl80211_policy[NL80211_ATTR_MAX+1] = {
Johannes Berg55682962007-09-20 13:09:35 -0400212 [NL80211_ATTR_WIPHY] = { .type = NLA_U32 },
213 [NL80211_ATTR_WIPHY_NAME] = { .type = NLA_NUL_STRING,
David S. Miller079e24e2009-05-26 21:15:00 -0700214 .len = 20-1 },
Jouni Malinen31888482008-10-30 16:59:24 +0200215 [NL80211_ATTR_WIPHY_TXQ_PARAMS] = { .type = NLA_NESTED },
Johannes Berg3d9d1d62012-11-08 23:14:50 +0100216
Jouni Malinen72bdcf32008-11-26 16:15:24 +0200217 [NL80211_ATTR_WIPHY_FREQ] = { .type = NLA_U32 },
Sujith094d05d2008-12-12 11:57:43 +0530218 [NL80211_ATTR_WIPHY_CHANNEL_TYPE] = { .type = NLA_U32 },
Johannes Berg3d9d1d62012-11-08 23:14:50 +0100219 [NL80211_ATTR_CHANNEL_WIDTH] = { .type = NLA_U32 },
220 [NL80211_ATTR_CENTER_FREQ1] = { .type = NLA_U32 },
221 [NL80211_ATTR_CENTER_FREQ2] = { .type = NLA_U32 },
222
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +0200223 [NL80211_ATTR_WIPHY_RETRY_SHORT] = { .type = NLA_U8 },
224 [NL80211_ATTR_WIPHY_RETRY_LONG] = { .type = NLA_U8 },
225 [NL80211_ATTR_WIPHY_FRAG_THRESHOLD] = { .type = NLA_U32 },
226 [NL80211_ATTR_WIPHY_RTS_THRESHOLD] = { .type = NLA_U32 },
Lukáš Turek81077e82009-12-21 22:50:47 +0100227 [NL80211_ATTR_WIPHY_COVERAGE_CLASS] = { .type = NLA_U8 },
Johannes Berg55682962007-09-20 13:09:35 -0400228
229 [NL80211_ATTR_IFTYPE] = { .type = NLA_U32 },
230 [NL80211_ATTR_IFINDEX] = { .type = NLA_U32 },
231 [NL80211_ATTR_IFNAME] = { .type = NLA_NUL_STRING, .len = IFNAMSIZ-1 },
Johannes Berg41ade002007-12-19 02:03:29 +0100232
Eliad Pellere007b852011-11-24 18:13:56 +0200233 [NL80211_ATTR_MAC] = { .len = ETH_ALEN },
234 [NL80211_ATTR_PREV_BSSID] = { .len = ETH_ALEN },
Johannes Berg41ade002007-12-19 02:03:29 +0100235
Johannes Bergb9454e82009-07-08 13:29:08 +0200236 [NL80211_ATTR_KEY] = { .type = NLA_NESTED, },
Johannes Berg41ade002007-12-19 02:03:29 +0100237 [NL80211_ATTR_KEY_DATA] = { .type = NLA_BINARY,
238 .len = WLAN_MAX_KEY_LEN },
239 [NL80211_ATTR_KEY_IDX] = { .type = NLA_U8 },
240 [NL80211_ATTR_KEY_CIPHER] = { .type = NLA_U32 },
241 [NL80211_ATTR_KEY_DEFAULT] = { .type = NLA_FLAG },
Jouni Malinen81962262011-11-02 23:36:31 +0200242 [NL80211_ATTR_KEY_SEQ] = { .type = NLA_BINARY, .len = 16 },
Johannes Berge31b8212010-10-05 19:39:30 +0200243 [NL80211_ATTR_KEY_TYPE] = { .type = NLA_U32 },
Johannes Berged1b6cc2007-12-19 02:03:32 +0100244
245 [NL80211_ATTR_BEACON_INTERVAL] = { .type = NLA_U32 },
246 [NL80211_ATTR_DTIM_PERIOD] = { .type = NLA_U32 },
247 [NL80211_ATTR_BEACON_HEAD] = { .type = NLA_BINARY,
248 .len = IEEE80211_MAX_DATA_LEN },
249 [NL80211_ATTR_BEACON_TAIL] = { .type = NLA_BINARY,
250 .len = IEEE80211_MAX_DATA_LEN },
Johannes Berg5727ef12007-12-19 02:03:34 +0100251 [NL80211_ATTR_STA_AID] = { .type = NLA_U16 },
252 [NL80211_ATTR_STA_FLAGS] = { .type = NLA_NESTED },
253 [NL80211_ATTR_STA_LISTEN_INTERVAL] = { .type = NLA_U16 },
254 [NL80211_ATTR_STA_SUPPORTED_RATES] = { .type = NLA_BINARY,
255 .len = NL80211_MAX_SUPP_RATES },
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +0100256 [NL80211_ATTR_STA_PLINK_ACTION] = { .type = NLA_U8 },
Johannes Berg5727ef12007-12-19 02:03:34 +0100257 [NL80211_ATTR_STA_VLAN] = { .type = NLA_U32 },
Johannes Berg0a9542e2008-10-15 11:54:04 +0200258 [NL80211_ATTR_MNTR_FLAGS] = { /* NLA_NESTED can't be empty */ },
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +0100259 [NL80211_ATTR_MESH_ID] = { .type = NLA_BINARY,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +0800260 .len = IEEE80211_MAX_MESH_ID_LEN },
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +0100261 [NL80211_ATTR_MPATH_NEXT_HOP] = { .type = NLA_U32 },
Jouni Malinen9f1ba902008-08-07 20:07:01 +0300262
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -0700263 [NL80211_ATTR_REG_ALPHA2] = { .type = NLA_STRING, .len = 2 },
264 [NL80211_ATTR_REG_RULES] = { .type = NLA_NESTED },
265
Jouni Malinen9f1ba902008-08-07 20:07:01 +0300266 [NL80211_ATTR_BSS_CTS_PROT] = { .type = NLA_U8 },
267 [NL80211_ATTR_BSS_SHORT_PREAMBLE] = { .type = NLA_U8 },
268 [NL80211_ATTR_BSS_SHORT_SLOT_TIME] = { .type = NLA_U8 },
Jouni Malinen90c97a02008-10-30 16:59:22 +0200269 [NL80211_ATTR_BSS_BASIC_RATES] = { .type = NLA_BINARY,
270 .len = NL80211_MAX_SUPP_RATES },
Helmut Schaa50b12f52010-11-19 12:40:25 +0100271 [NL80211_ATTR_BSS_HT_OPMODE] = { .type = NLA_U16 },
Jouni Malinen36aedc92008-08-25 11:58:58 +0300272
Javier Cardona24bdd9f2010-12-16 17:37:48 -0800273 [NL80211_ATTR_MESH_CONFIG] = { .type = NLA_NESTED },
Javier Cardona15d5dda2011-04-07 15:08:28 -0700274 [NL80211_ATTR_SUPPORT_MESH_AUTH] = { .type = NLA_FLAG },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -0700275
Johannes Berg6c739412011-11-03 09:27:01 +0100276 [NL80211_ATTR_HT_CAPABILITY] = { .len = NL80211_HT_CAPABILITY_LEN },
Jouni Malinen9aed3cc2009-01-13 16:03:29 +0200277
278 [NL80211_ATTR_MGMT_SUBTYPE] = { .type = NLA_U8 },
279 [NL80211_ATTR_IE] = { .type = NLA_BINARY,
280 .len = IEEE80211_MAX_DATA_LEN },
Johannes Berg2a519312009-02-10 21:25:55 +0100281 [NL80211_ATTR_SCAN_FREQUENCIES] = { .type = NLA_NESTED },
282 [NL80211_ATTR_SCAN_SSIDS] = { .type = NLA_NESTED },
Jouni Malinen636a5d32009-03-19 13:39:22 +0200283
284 [NL80211_ATTR_SSID] = { .type = NLA_BINARY,
285 .len = IEEE80211_MAX_SSID_LEN },
286 [NL80211_ATTR_AUTH_TYPE] = { .type = NLA_U32 },
287 [NL80211_ATTR_REASON_CODE] = { .type = NLA_U16 },
Johannes Berg04a773a2009-04-19 21:24:32 +0200288 [NL80211_ATTR_FREQ_FIXED] = { .type = NLA_FLAG },
Jouni Malinen1965c852009-04-22 21:38:25 +0300289 [NL80211_ATTR_TIMED_OUT] = { .type = NLA_FLAG },
Jouni Malinendc6382c2009-05-06 22:09:37 +0300290 [NL80211_ATTR_USE_MFP] = { .type = NLA_U32 },
Johannes Bergeccb8e82009-05-11 21:57:56 +0300291 [NL80211_ATTR_STA_FLAGS2] = {
292 .len = sizeof(struct nl80211_sta_flag_update),
293 },
Jouni Malinen3f77316c2009-05-11 21:57:57 +0300294 [NL80211_ATTR_CONTROL_PORT] = { .type = NLA_FLAG },
Johannes Bergc0692b82010-08-27 14:26:53 +0300295 [NL80211_ATTR_CONTROL_PORT_ETHERTYPE] = { .type = NLA_U16 },
296 [NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT] = { .type = NLA_FLAG },
Samuel Ortizb23aa672009-07-01 21:26:54 +0200297 [NL80211_ATTR_PRIVACY] = { .type = NLA_FLAG },
298 [NL80211_ATTR_CIPHER_SUITE_GROUP] = { .type = NLA_U32 },
299 [NL80211_ATTR_WPA_VERSIONS] = { .type = NLA_U32 },
Johannes Berg463d0182009-07-14 00:33:35 +0200300 [NL80211_ATTR_PID] = { .type = NLA_U32 },
Felix Fietkau8b787642009-11-10 18:53:10 +0100301 [NL80211_ATTR_4ADDR] = { .type = NLA_U8 },
Samuel Ortiz67fbb162009-11-24 23:59:15 +0100302 [NL80211_ATTR_PMKID] = { .type = NLA_BINARY,
303 .len = WLAN_PMKID_LEN },
Jouni Malinen9588bbd2009-12-23 13:15:41 +0100304 [NL80211_ATTR_DURATION] = { .type = NLA_U32 },
305 [NL80211_ATTR_COOKIE] = { .type = NLA_U64 },
Jouni Malinen13ae75b2009-12-29 12:59:45 +0200306 [NL80211_ATTR_TX_RATES] = { .type = NLA_NESTED },
Jouni Malinen026331c2010-02-15 12:53:10 +0200307 [NL80211_ATTR_FRAME] = { .type = NLA_BINARY,
308 .len = IEEE80211_MAX_DATA_LEN },
309 [NL80211_ATTR_FRAME_MATCH] = { .type = NLA_BINARY, },
Kalle Valoffb9eb32010-02-17 17:58:10 +0200310 [NL80211_ATTR_PS_STATE] = { .type = NLA_U32 },
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +0200311 [NL80211_ATTR_CQM] = { .type = NLA_NESTED, },
Jouni Malinend5cdfac2010-04-04 09:37:19 +0300312 [NL80211_ATTR_LOCAL_STATE_CHANGE] = { .type = NLA_FLAG },
Felix Fietkaufd8aaaf2010-04-27 01:23:35 +0200313 [NL80211_ATTR_AP_ISOLATE] = { .type = NLA_U8 },
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +0300314 [NL80211_ATTR_WIPHY_TX_POWER_SETTING] = { .type = NLA_U32 },
315 [NL80211_ATTR_WIPHY_TX_POWER_LEVEL] = { .type = NLA_U32 },
Johannes Berg2e161f72010-08-12 15:38:38 +0200316 [NL80211_ATTR_FRAME_TYPE] = { .type = NLA_U16 },
Bruno Randolfafe0cbf2010-11-10 12:50:50 +0900317 [NL80211_ATTR_WIPHY_ANTENNA_TX] = { .type = NLA_U32 },
318 [NL80211_ATTR_WIPHY_ANTENNA_RX] = { .type = NLA_U32 },
Felix Fietkau885a46d2010-11-11 15:07:22 +0100319 [NL80211_ATTR_MCAST_RATE] = { .type = NLA_U32 },
Johannes Bergf7ca38d2010-11-25 10:02:29 +0100320 [NL80211_ATTR_OFFCHANNEL_TX_OK] = { .type = NLA_FLAG },
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100321 [NL80211_ATTR_KEY_DEFAULT_TYPES] = { .type = NLA_NESTED },
Johannes Bergff1b6e62011-05-04 15:37:28 +0200322 [NL80211_ATTR_WOWLAN_TRIGGERS] = { .type = NLA_NESTED },
Javier Cardona9c3990a2011-05-03 16:57:11 -0700323 [NL80211_ATTR_STA_PLINK_STATE] = { .type = NLA_U8 },
Luciano Coelhobbe6ad62011-05-11 17:09:37 +0300324 [NL80211_ATTR_SCHED_SCAN_INTERVAL] = { .type = NLA_U32 },
Johannes Berge5497d72011-07-05 16:35:40 +0200325 [NL80211_ATTR_REKEY_DATA] = { .type = NLA_NESTED },
Johannes Berg34850ab2011-07-18 18:08:35 +0200326 [NL80211_ATTR_SCAN_SUPP_RATES] = { .type = NLA_NESTED },
Jouni Malinen32e9de82011-08-10 23:53:31 +0300327 [NL80211_ATTR_HIDDEN_SSID] = { .type = NLA_U32 },
Jouni Malinen9946ecf2011-08-10 23:55:56 +0300328 [NL80211_ATTR_IE_PROBE_RESP] = { .type = NLA_BINARY,
329 .len = IEEE80211_MAX_DATA_LEN },
330 [NL80211_ATTR_IE_ASSOC_RESP] = { .type = NLA_BINARY,
331 .len = IEEE80211_MAX_DATA_LEN },
Vivek Natarajanf4b34b52011-08-29 14:23:03 +0530332 [NL80211_ATTR_ROAM_SUPPORT] = { .type = NLA_FLAG },
Luciano Coelhoa1f1c212011-08-31 16:01:48 +0300333 [NL80211_ATTR_SCHED_SCAN_MATCH] = { .type = NLA_NESTED },
Rajkumar Manoharane9f935e2011-09-25 14:53:30 +0530334 [NL80211_ATTR_TX_NO_CCK_RATE] = { .type = NLA_FLAG },
Arik Nemtsov109086c2011-09-28 14:12:50 +0300335 [NL80211_ATTR_TDLS_ACTION] = { .type = NLA_U8 },
336 [NL80211_ATTR_TDLS_DIALOG_TOKEN] = { .type = NLA_U8 },
337 [NL80211_ATTR_TDLS_OPERATION] = { .type = NLA_U8 },
338 [NL80211_ATTR_TDLS_SUPPORT] = { .type = NLA_FLAG },
339 [NL80211_ATTR_TDLS_EXTERNAL_SETUP] = { .type = NLA_FLAG },
Arik Nemtsov31fa97c2014-06-11 17:18:21 +0300340 [NL80211_ATTR_TDLS_INITIATOR] = { .type = NLA_FLAG },
Johannes Berge247bd902011-11-04 11:18:21 +0100341 [NL80211_ATTR_DONT_WAIT_FOR_ACK] = { .type = NLA_FLAG },
Arik Nemtsov00f740e2011-11-10 11:28:56 +0200342 [NL80211_ATTR_PROBE_RESP] = { .type = NLA_BINARY,
343 .len = IEEE80211_MAX_DATA_LEN },
Luis R. Rodriguez8b60b072011-10-11 10:59:02 -0700344 [NL80211_ATTR_DFS_REGION] = { .type = NLA_U8 },
Ben Greear7e7c8922011-11-18 11:31:59 -0800345 [NL80211_ATTR_DISABLE_HT] = { .type = NLA_FLAG },
346 [NL80211_ATTR_HT_CAPABILITY_MASK] = {
347 .len = NL80211_HT_CAPABILITY_LEN
348 },
Simon Wunderlich1d9d9212011-11-18 14:20:43 +0100349 [NL80211_ATTR_NOACK_MAP] = { .type = NLA_U16 },
Vasanthakumar Thiagarajan1b658f12012-03-02 15:50:02 +0530350 [NL80211_ATTR_INACTIVITY_TIMEOUT] = { .type = NLA_U16 },
Bala Shanmugam4486ea92012-03-07 17:27:12 +0530351 [NL80211_ATTR_BG_SCAN_PERIOD] = { .type = NLA_U16 },
Johannes Berg89a54e42012-06-15 14:33:17 +0200352 [NL80211_ATTR_WDEV] = { .type = NLA_U64 },
Luis R. Rodriguez57b5ce02012-07-12 11:49:18 -0700353 [NL80211_ATTR_USER_REG_HINT_TYPE] = { .type = NLA_U32 },
Jouni Malinene39e5b52012-09-30 19:29:39 +0300354 [NL80211_ATTR_SAE_DATA] = { .type = NLA_BINARY, },
Mahesh Palivelaf461be3e2012-10-11 08:04:52 +0000355 [NL80211_ATTR_VHT_CAPABILITY] = { .len = NL80211_VHT_CAPABILITY_LEN },
Sam Lefflered4737712012-10-11 21:03:31 -0700356 [NL80211_ATTR_SCAN_FLAGS] = { .type = NLA_U32 },
Johannes Berg53cabad2012-11-14 15:17:28 +0100357 [NL80211_ATTR_P2P_CTWINDOW] = { .type = NLA_U8 },
358 [NL80211_ATTR_P2P_OPPPS] = { .type = NLA_U8 },
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +0530359 [NL80211_ATTR_ACL_POLICY] = {. type = NLA_U32 },
360 [NL80211_ATTR_MAC_ADDRS] = { .type = NLA_NESTED },
Jouni Malinen9d62a982013-02-14 21:10:13 +0200361 [NL80211_ATTR_STA_CAPABILITY] = { .type = NLA_U16 },
362 [NL80211_ATTR_STA_EXT_CAPABILITY] = { .type = NLA_BINARY, },
Johannes Berg3713b4e2013-02-14 16:19:38 +0100363 [NL80211_ATTR_SPLIT_WIPHY_DUMP] = { .type = NLA_FLAG, },
Johannes Bergee2aca32013-02-21 17:36:01 +0100364 [NL80211_ATTR_DISABLE_VHT] = { .type = NLA_FLAG },
365 [NL80211_ATTR_VHT_CAPABILITY_MASK] = {
366 .len = NL80211_VHT_CAPABILITY_LEN,
367 },
Jouni Malinen355199e2013-02-27 17:14:27 +0200368 [NL80211_ATTR_MDID] = { .type = NLA_U16 },
369 [NL80211_ATTR_IE_RIC] = { .type = NLA_BINARY,
370 .len = IEEE80211_MAX_DATA_LEN },
Jouni Malinen5e4b6f52013-05-16 20:11:08 +0300371 [NL80211_ATTR_PEER_AID] = { .type = NLA_U16 },
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +0200372 [NL80211_ATTR_CH_SWITCH_COUNT] = { .type = NLA_U32 },
373 [NL80211_ATTR_CH_SWITCH_BLOCK_TX] = { .type = NLA_FLAG },
374 [NL80211_ATTR_CSA_IES] = { .type = NLA_NESTED },
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +0300375 [NL80211_ATTR_CSA_C_OFF_BEACON] = { .type = NLA_BINARY },
376 [NL80211_ATTR_CSA_C_OFF_PRESP] = { .type = NLA_BINARY },
Sunil Duttc01fc9a2013-10-09 20:45:21 +0530377 [NL80211_ATTR_STA_SUPPORTED_CHANNELS] = { .type = NLA_BINARY },
378 [NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES] = { .type = NLA_BINARY },
Simon Wunderlich5336fa82013-10-07 18:41:05 +0200379 [NL80211_ATTR_HANDLE_DFS] = { .type = NLA_FLAG },
Marek Kwaczynski60f4a7b2013-12-03 10:04:59 +0100380 [NL80211_ATTR_OPMODE_NOTIF] = { .type = NLA_U8 },
Johannes Bergad7e7182013-11-13 13:37:47 +0100381 [NL80211_ATTR_VENDOR_ID] = { .type = NLA_U32 },
382 [NL80211_ATTR_VENDOR_SUBCMD] = { .type = NLA_U32 },
383 [NL80211_ATTR_VENDOR_DATA] = { .type = NLA_BINARY },
Kyeyoon Parkfa9ffc72013-12-16 23:01:30 -0800384 [NL80211_ATTR_QOS_MAP] = { .type = NLA_BINARY,
385 .len = IEEE80211_QOS_MAP_LEN_MAX },
Jouni Malinen1df4a512014-01-15 00:00:47 +0200386 [NL80211_ATTR_MAC_HINT] = { .len = ETH_ALEN },
387 [NL80211_ATTR_WIPHY_FREQ_HINT] = { .type = NLA_U32 },
Sunil Dutt Undekaridf942e72014-02-20 16:22:09 +0530388 [NL80211_ATTR_TDLS_PEER_CAPABILITY] = { .type = NLA_U32 },
Johannes Berg78f22b62014-03-24 17:57:27 +0100389 [NL80211_ATTR_IFACE_SOCKET_OWNER] = { .type = NLA_FLAG },
Andrei Otcheretianski34d22ce2014-05-09 14:11:44 +0300390 [NL80211_ATTR_CSA_C_OFFSETS_TX] = { .type = NLA_BINARY },
Johannes Berg55682962007-09-20 13:09:35 -0400391};
392
Johannes Berge31b8212010-10-05 19:39:30 +0200393/* policy for the key attributes */
Alexey Dobriyanb54452b2010-02-18 08:14:31 +0000394static const struct nla_policy nl80211_key_policy[NL80211_KEY_MAX + 1] = {
Johannes Bergfffd0932009-07-08 14:22:54 +0200395 [NL80211_KEY_DATA] = { .type = NLA_BINARY, .len = WLAN_MAX_KEY_LEN },
Johannes Bergb9454e82009-07-08 13:29:08 +0200396 [NL80211_KEY_IDX] = { .type = NLA_U8 },
397 [NL80211_KEY_CIPHER] = { .type = NLA_U32 },
Jouni Malinen81962262011-11-02 23:36:31 +0200398 [NL80211_KEY_SEQ] = { .type = NLA_BINARY, .len = 16 },
Johannes Bergb9454e82009-07-08 13:29:08 +0200399 [NL80211_KEY_DEFAULT] = { .type = NLA_FLAG },
400 [NL80211_KEY_DEFAULT_MGMT] = { .type = NLA_FLAG },
Johannes Berge31b8212010-10-05 19:39:30 +0200401 [NL80211_KEY_TYPE] = { .type = NLA_U32 },
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100402 [NL80211_KEY_DEFAULT_TYPES] = { .type = NLA_NESTED },
403};
404
405/* policy for the key default flags */
406static const struct nla_policy
407nl80211_key_default_policy[NUM_NL80211_KEY_DEFAULT_TYPES] = {
408 [NL80211_KEY_DEFAULT_TYPE_UNICAST] = { .type = NLA_FLAG },
409 [NL80211_KEY_DEFAULT_TYPE_MULTICAST] = { .type = NLA_FLAG },
Johannes Bergb9454e82009-07-08 13:29:08 +0200410};
411
Johannes Bergff1b6e62011-05-04 15:37:28 +0200412/* policy for WoWLAN attributes */
413static const struct nla_policy
414nl80211_wowlan_policy[NUM_NL80211_WOWLAN_TRIG] = {
415 [NL80211_WOWLAN_TRIG_ANY] = { .type = NLA_FLAG },
416 [NL80211_WOWLAN_TRIG_DISCONNECT] = { .type = NLA_FLAG },
417 [NL80211_WOWLAN_TRIG_MAGIC_PKT] = { .type = NLA_FLAG },
418 [NL80211_WOWLAN_TRIG_PKT_PATTERN] = { .type = NLA_NESTED },
Johannes Berg77dbbb12011-07-13 10:48:55 +0200419 [NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE] = { .type = NLA_FLAG },
420 [NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST] = { .type = NLA_FLAG },
421 [NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE] = { .type = NLA_FLAG },
422 [NL80211_WOWLAN_TRIG_RFKILL_RELEASE] = { .type = NLA_FLAG },
Johannes Berg2a0e0472013-01-23 22:57:40 +0100423 [NL80211_WOWLAN_TRIG_TCP_CONNECTION] = { .type = NLA_NESTED },
424};
425
426static const struct nla_policy
427nl80211_wowlan_tcp_policy[NUM_NL80211_WOWLAN_TCP] = {
428 [NL80211_WOWLAN_TCP_SRC_IPV4] = { .type = NLA_U32 },
429 [NL80211_WOWLAN_TCP_DST_IPV4] = { .type = NLA_U32 },
430 [NL80211_WOWLAN_TCP_DST_MAC] = { .len = ETH_ALEN },
431 [NL80211_WOWLAN_TCP_SRC_PORT] = { .type = NLA_U16 },
432 [NL80211_WOWLAN_TCP_DST_PORT] = { .type = NLA_U16 },
433 [NL80211_WOWLAN_TCP_DATA_PAYLOAD] = { .len = 1 },
434 [NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ] = {
435 .len = sizeof(struct nl80211_wowlan_tcp_data_seq)
436 },
437 [NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN] = {
438 .len = sizeof(struct nl80211_wowlan_tcp_data_token)
439 },
440 [NL80211_WOWLAN_TCP_DATA_INTERVAL] = { .type = NLA_U32 },
441 [NL80211_WOWLAN_TCP_WAKE_PAYLOAD] = { .len = 1 },
442 [NL80211_WOWLAN_TCP_WAKE_MASK] = { .len = 1 },
Johannes Bergff1b6e62011-05-04 15:37:28 +0200443};
444
Amitkumar Karwarbe29b992013-06-28 11:51:26 -0700445/* policy for coalesce rule attributes */
446static const struct nla_policy
447nl80211_coalesce_policy[NUM_NL80211_ATTR_COALESCE_RULE] = {
448 [NL80211_ATTR_COALESCE_RULE_DELAY] = { .type = NLA_U32 },
449 [NL80211_ATTR_COALESCE_RULE_CONDITION] = { .type = NLA_U32 },
450 [NL80211_ATTR_COALESCE_RULE_PKT_PATTERN] = { .type = NLA_NESTED },
451};
452
Johannes Berge5497d72011-07-05 16:35:40 +0200453/* policy for GTK rekey offload attributes */
454static const struct nla_policy
455nl80211_rekey_policy[NUM_NL80211_REKEY_DATA] = {
456 [NL80211_REKEY_DATA_KEK] = { .len = NL80211_KEK_LEN },
457 [NL80211_REKEY_DATA_KCK] = { .len = NL80211_KCK_LEN },
458 [NL80211_REKEY_DATA_REPLAY_CTR] = { .len = NL80211_REPLAY_CTR_LEN },
459};
460
Luciano Coelhoa1f1c212011-08-31 16:01:48 +0300461static const struct nla_policy
462nl80211_match_policy[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1] = {
Johannes Berg4a4ab0d2012-06-13 11:17:11 +0200463 [NL80211_SCHED_SCAN_MATCH_ATTR_SSID] = { .type = NLA_BINARY,
Luciano Coelhoa1f1c212011-08-31 16:01:48 +0300464 .len = IEEE80211_MAX_SSID_LEN },
Thomas Pedersen88e920b2012-06-21 11:09:54 -0700465 [NL80211_SCHED_SCAN_MATCH_ATTR_RSSI] = { .type = NLA_U32 },
Luciano Coelhoa1f1c212011-08-31 16:01:48 +0300466};
467
Johannes Berg97990a02013-04-19 01:02:55 +0200468static int nl80211_prepare_wdev_dump(struct sk_buff *skb,
469 struct netlink_callback *cb,
470 struct cfg80211_registered_device **rdev,
471 struct wireless_dev **wdev)
Holger Schuriga0438972009-11-11 11:30:02 +0100472{
Johannes Berg67748892010-10-04 21:14:06 +0200473 int err;
474
Johannes Berg67748892010-10-04 21:14:06 +0200475 rtnl_lock();
476
Johannes Berg97990a02013-04-19 01:02:55 +0200477 if (!cb->args[0]) {
478 err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize,
479 nl80211_fam.attrbuf, nl80211_fam.maxattr,
480 nl80211_policy);
481 if (err)
482 goto out_unlock;
483
484 *wdev = __cfg80211_wdev_from_attrs(sock_net(skb->sk),
485 nl80211_fam.attrbuf);
486 if (IS_ERR(*wdev)) {
487 err = PTR_ERR(*wdev);
488 goto out_unlock;
489 }
Zhao, Gangf26cbf42014-04-21 12:53:03 +0800490 *rdev = wiphy_to_rdev((*wdev)->wiphy);
Johannes Bergc319d502013-07-30 22:34:28 +0200491 /* 0 is the first index - add 1 to parse only once */
492 cb->args[0] = (*rdev)->wiphy_idx + 1;
Johannes Berg97990a02013-04-19 01:02:55 +0200493 cb->args[1] = (*wdev)->identifier;
494 } else {
Johannes Bergc319d502013-07-30 22:34:28 +0200495 /* subtract the 1 again here */
496 struct wiphy *wiphy = wiphy_idx_to_wiphy(cb->args[0] - 1);
Johannes Berg97990a02013-04-19 01:02:55 +0200497 struct wireless_dev *tmp;
498
499 if (!wiphy) {
500 err = -ENODEV;
501 goto out_unlock;
502 }
Zhao, Gangf26cbf42014-04-21 12:53:03 +0800503 *rdev = wiphy_to_rdev(wiphy);
Johannes Berg97990a02013-04-19 01:02:55 +0200504 *wdev = NULL;
505
Johannes Berg97990a02013-04-19 01:02:55 +0200506 list_for_each_entry(tmp, &(*rdev)->wdev_list, list) {
507 if (tmp->identifier == cb->args[1]) {
508 *wdev = tmp;
509 break;
510 }
511 }
Johannes Berg97990a02013-04-19 01:02:55 +0200512
513 if (!*wdev) {
514 err = -ENODEV;
515 goto out_unlock;
516 }
Johannes Berg67748892010-10-04 21:14:06 +0200517 }
518
Johannes Berg67748892010-10-04 21:14:06 +0200519 return 0;
Johannes Berg97990a02013-04-19 01:02:55 +0200520 out_unlock:
Johannes Berg67748892010-10-04 21:14:06 +0200521 rtnl_unlock();
522 return err;
523}
524
Johannes Berg97990a02013-04-19 01:02:55 +0200525static void nl80211_finish_wdev_dump(struct cfg80211_registered_device *rdev)
Johannes Berg67748892010-10-04 21:14:06 +0200526{
Johannes Berg67748892010-10-04 21:14:06 +0200527 rtnl_unlock();
528}
529
Johannes Bergf4a11bb2009-03-27 12:40:28 +0100530/* IE validation */
531static bool is_valid_ie_attr(const struct nlattr *attr)
532{
533 const u8 *pos;
534 int len;
535
536 if (!attr)
537 return true;
538
539 pos = nla_data(attr);
540 len = nla_len(attr);
541
542 while (len) {
543 u8 elemlen;
544
545 if (len < 2)
546 return false;
547 len -= 2;
548
549 elemlen = pos[1];
550 if (elemlen > len)
551 return false;
552
553 len -= elemlen;
554 pos += 2 + elemlen;
555 }
556
557 return true;
558}
559
Johannes Berg55682962007-09-20 13:09:35 -0400560/* message building helper */
Eric W. Biederman15e47302012-09-07 20:12:54 +0000561static inline void *nl80211hdr_put(struct sk_buff *skb, u32 portid, u32 seq,
Johannes Berg55682962007-09-20 13:09:35 -0400562 int flags, u8 cmd)
563{
564 /* since there is no private header just add the generic one */
Eric W. Biederman15e47302012-09-07 20:12:54 +0000565 return genlmsg_put(skb, portid, seq, &nl80211_fam, flags, cmd);
Johannes Berg55682962007-09-20 13:09:35 -0400566}
567
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400568static int nl80211_msg_put_channel(struct sk_buff *msg,
Johannes Bergcdc89b92013-02-18 23:54:36 +0100569 struct ieee80211_channel *chan,
570 bool large)
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400571{
Rostislav Lisovyea077c12014-04-15 14:37:55 +0200572 /* Some channels must be completely excluded from the
573 * list to protect old user-space tools from breaking
574 */
575 if (!large && chan->flags &
576 (IEEE80211_CHAN_NO_10MHZ | IEEE80211_CHAN_NO_20MHZ))
577 return 0;
578
David S. Miller9360ffd2012-03-29 04:41:26 -0400579 if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_FREQ,
580 chan->center_freq))
581 goto nla_put_failure;
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400582
David S. Miller9360ffd2012-03-29 04:41:26 -0400583 if ((chan->flags & IEEE80211_CHAN_DISABLED) &&
584 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_DISABLED))
585 goto nla_put_failure;
Luis R. Rodriguez8fe02e12013-10-21 19:22:25 +0200586 if (chan->flags & IEEE80211_CHAN_NO_IR) {
587 if (nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_IR))
588 goto nla_put_failure;
589 if (nla_put_flag(msg, __NL80211_FREQUENCY_ATTR_NO_IBSS))
590 goto nla_put_failure;
591 }
Johannes Bergcdc89b92013-02-18 23:54:36 +0100592 if (chan->flags & IEEE80211_CHAN_RADAR) {
593 if (nla_put_flag(msg, NL80211_FREQUENCY_ATTR_RADAR))
594 goto nla_put_failure;
595 if (large) {
596 u32 time;
597
598 time = elapsed_jiffies_msecs(chan->dfs_state_entered);
599
600 if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_DFS_STATE,
601 chan->dfs_state))
602 goto nla_put_failure;
603 if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_DFS_TIME,
604 time))
605 goto nla_put_failure;
Janusz Dziedzic089027e2014-02-21 19:46:12 +0100606 if (nla_put_u32(msg,
607 NL80211_FREQUENCY_ATTR_DFS_CAC_TIME,
608 chan->dfs_cac_ms))
609 goto nla_put_failure;
Johannes Bergcdc89b92013-02-18 23:54:36 +0100610 }
611 }
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400612
Johannes Bergfe1abaf2013-02-27 15:39:45 +0100613 if (large) {
614 if ((chan->flags & IEEE80211_CHAN_NO_HT40MINUS) &&
615 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_HT40_MINUS))
616 goto nla_put_failure;
617 if ((chan->flags & IEEE80211_CHAN_NO_HT40PLUS) &&
618 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_HT40_PLUS))
619 goto nla_put_failure;
620 if ((chan->flags & IEEE80211_CHAN_NO_80MHZ) &&
621 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_80MHZ))
622 goto nla_put_failure;
623 if ((chan->flags & IEEE80211_CHAN_NO_160MHZ) &&
624 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_160MHZ))
625 goto nla_put_failure;
David Spinadel570dbde2014-02-23 09:12:59 +0200626 if ((chan->flags & IEEE80211_CHAN_INDOOR_ONLY) &&
627 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_INDOOR_ONLY))
628 goto nla_put_failure;
629 if ((chan->flags & IEEE80211_CHAN_GO_CONCURRENT) &&
630 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_GO_CONCURRENT))
631 goto nla_put_failure;
Rostislav Lisovyea077c12014-04-15 14:37:55 +0200632 if ((chan->flags & IEEE80211_CHAN_NO_20MHZ) &&
633 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_20MHZ))
634 goto nla_put_failure;
635 if ((chan->flags & IEEE80211_CHAN_NO_10MHZ) &&
636 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_10MHZ))
637 goto nla_put_failure;
Johannes Bergfe1abaf2013-02-27 15:39:45 +0100638 }
639
David S. Miller9360ffd2012-03-29 04:41:26 -0400640 if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_MAX_TX_POWER,
641 DBM_TO_MBM(chan->max_power)))
642 goto nla_put_failure;
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400643
644 return 0;
645
646 nla_put_failure:
647 return -ENOBUFS;
648}
649
Johannes Berg55682962007-09-20 13:09:35 -0400650/* netlink command implementations */
651
Johannes Bergb9454e82009-07-08 13:29:08 +0200652struct key_parse {
653 struct key_params p;
654 int idx;
Johannes Berge31b8212010-10-05 19:39:30 +0200655 int type;
Johannes Bergb9454e82009-07-08 13:29:08 +0200656 bool def, defmgmt;
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100657 bool def_uni, def_multi;
Johannes Bergb9454e82009-07-08 13:29:08 +0200658};
659
660static int nl80211_parse_key_new(struct nlattr *key, struct key_parse *k)
661{
662 struct nlattr *tb[NL80211_KEY_MAX + 1];
663 int err = nla_parse_nested(tb, NL80211_KEY_MAX, key,
664 nl80211_key_policy);
665 if (err)
666 return err;
667
668 k->def = !!tb[NL80211_KEY_DEFAULT];
669 k->defmgmt = !!tb[NL80211_KEY_DEFAULT_MGMT];
670
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100671 if (k->def) {
672 k->def_uni = true;
673 k->def_multi = true;
674 }
675 if (k->defmgmt)
676 k->def_multi = true;
677
Johannes Bergb9454e82009-07-08 13:29:08 +0200678 if (tb[NL80211_KEY_IDX])
679 k->idx = nla_get_u8(tb[NL80211_KEY_IDX]);
680
681 if (tb[NL80211_KEY_DATA]) {
682 k->p.key = nla_data(tb[NL80211_KEY_DATA]);
683 k->p.key_len = nla_len(tb[NL80211_KEY_DATA]);
684 }
685
686 if (tb[NL80211_KEY_SEQ]) {
687 k->p.seq = nla_data(tb[NL80211_KEY_SEQ]);
688 k->p.seq_len = nla_len(tb[NL80211_KEY_SEQ]);
689 }
690
691 if (tb[NL80211_KEY_CIPHER])
692 k->p.cipher = nla_get_u32(tb[NL80211_KEY_CIPHER]);
693
Johannes Berge31b8212010-10-05 19:39:30 +0200694 if (tb[NL80211_KEY_TYPE]) {
695 k->type = nla_get_u32(tb[NL80211_KEY_TYPE]);
696 if (k->type < 0 || k->type >= NUM_NL80211_KEYTYPES)
697 return -EINVAL;
698 }
699
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100700 if (tb[NL80211_KEY_DEFAULT_TYPES]) {
701 struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES];
Johannes Berg2da8f412012-01-20 13:52:37 +0100702 err = nla_parse_nested(kdt, NUM_NL80211_KEY_DEFAULT_TYPES - 1,
703 tb[NL80211_KEY_DEFAULT_TYPES],
704 nl80211_key_default_policy);
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100705 if (err)
706 return err;
707
708 k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST];
709 k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST];
710 }
711
Johannes Bergb9454e82009-07-08 13:29:08 +0200712 return 0;
713}
714
715static int nl80211_parse_key_old(struct genl_info *info, struct key_parse *k)
716{
717 if (info->attrs[NL80211_ATTR_KEY_DATA]) {
718 k->p.key = nla_data(info->attrs[NL80211_ATTR_KEY_DATA]);
719 k->p.key_len = nla_len(info->attrs[NL80211_ATTR_KEY_DATA]);
720 }
721
722 if (info->attrs[NL80211_ATTR_KEY_SEQ]) {
723 k->p.seq = nla_data(info->attrs[NL80211_ATTR_KEY_SEQ]);
724 k->p.seq_len = nla_len(info->attrs[NL80211_ATTR_KEY_SEQ]);
725 }
726
727 if (info->attrs[NL80211_ATTR_KEY_IDX])
728 k->idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]);
729
730 if (info->attrs[NL80211_ATTR_KEY_CIPHER])
731 k->p.cipher = nla_get_u32(info->attrs[NL80211_ATTR_KEY_CIPHER]);
732
733 k->def = !!info->attrs[NL80211_ATTR_KEY_DEFAULT];
734 k->defmgmt = !!info->attrs[NL80211_ATTR_KEY_DEFAULT_MGMT];
735
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100736 if (k->def) {
737 k->def_uni = true;
738 k->def_multi = true;
739 }
740 if (k->defmgmt)
741 k->def_multi = true;
742
Johannes Berge31b8212010-10-05 19:39:30 +0200743 if (info->attrs[NL80211_ATTR_KEY_TYPE]) {
744 k->type = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]);
745 if (k->type < 0 || k->type >= NUM_NL80211_KEYTYPES)
746 return -EINVAL;
747 }
748
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100749 if (info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES]) {
750 struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES];
751 int err = nla_parse_nested(
752 kdt, NUM_NL80211_KEY_DEFAULT_TYPES - 1,
753 info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES],
754 nl80211_key_default_policy);
755 if (err)
756 return err;
757
758 k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST];
759 k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST];
760 }
761
Johannes Bergb9454e82009-07-08 13:29:08 +0200762 return 0;
763}
764
765static int nl80211_parse_key(struct genl_info *info, struct key_parse *k)
766{
767 int err;
768
769 memset(k, 0, sizeof(*k));
770 k->idx = -1;
Johannes Berge31b8212010-10-05 19:39:30 +0200771 k->type = -1;
Johannes Bergb9454e82009-07-08 13:29:08 +0200772
773 if (info->attrs[NL80211_ATTR_KEY])
774 err = nl80211_parse_key_new(info->attrs[NL80211_ATTR_KEY], k);
775 else
776 err = nl80211_parse_key_old(info, k);
777
778 if (err)
779 return err;
780
781 if (k->def && k->defmgmt)
782 return -EINVAL;
783
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100784 if (k->defmgmt) {
785 if (k->def_uni || !k->def_multi)
786 return -EINVAL;
787 }
788
Johannes Bergb9454e82009-07-08 13:29:08 +0200789 if (k->idx != -1) {
790 if (k->defmgmt) {
791 if (k->idx < 4 || k->idx > 5)
792 return -EINVAL;
793 } else if (k->def) {
794 if (k->idx < 0 || k->idx > 3)
795 return -EINVAL;
796 } else {
797 if (k->idx < 0 || k->idx > 5)
798 return -EINVAL;
799 }
800 }
801
802 return 0;
803}
804
Johannes Bergfffd0932009-07-08 14:22:54 +0200805static struct cfg80211_cached_keys *
806nl80211_parse_connkeys(struct cfg80211_registered_device *rdev,
Sujith Manoharande7044e2012-10-18 10:19:28 +0530807 struct nlattr *keys, bool *no_ht)
Johannes Bergfffd0932009-07-08 14:22:54 +0200808{
809 struct key_parse parse;
810 struct nlattr *key;
811 struct cfg80211_cached_keys *result;
812 int rem, err, def = 0;
813
814 result = kzalloc(sizeof(*result), GFP_KERNEL);
815 if (!result)
816 return ERR_PTR(-ENOMEM);
817
818 result->def = -1;
819 result->defmgmt = -1;
820
821 nla_for_each_nested(key, keys, rem) {
822 memset(&parse, 0, sizeof(parse));
823 parse.idx = -1;
824
825 err = nl80211_parse_key_new(key, &parse);
826 if (err)
827 goto error;
828 err = -EINVAL;
829 if (!parse.p.key)
830 goto error;
831 if (parse.idx < 0 || parse.idx > 4)
832 goto error;
833 if (parse.def) {
834 if (def)
835 goto error;
836 def = 1;
837 result->def = parse.idx;
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100838 if (!parse.def_uni || !parse.def_multi)
839 goto error;
Johannes Bergfffd0932009-07-08 14:22:54 +0200840 } else if (parse.defmgmt)
841 goto error;
842 err = cfg80211_validate_key_settings(rdev, &parse.p,
Johannes Berge31b8212010-10-05 19:39:30 +0200843 parse.idx, false, NULL);
Johannes Bergfffd0932009-07-08 14:22:54 +0200844 if (err)
845 goto error;
846 result->params[parse.idx].cipher = parse.p.cipher;
847 result->params[parse.idx].key_len = parse.p.key_len;
848 result->params[parse.idx].key = result->data[parse.idx];
849 memcpy(result->data[parse.idx], parse.p.key, parse.p.key_len);
Sujith Manoharande7044e2012-10-18 10:19:28 +0530850
851 if (parse.p.cipher == WLAN_CIPHER_SUITE_WEP40 ||
852 parse.p.cipher == WLAN_CIPHER_SUITE_WEP104) {
853 if (no_ht)
854 *no_ht = true;
855 }
Johannes Bergfffd0932009-07-08 14:22:54 +0200856 }
857
858 return result;
859 error:
860 kfree(result);
861 return ERR_PTR(err);
862}
863
864static int nl80211_key_allowed(struct wireless_dev *wdev)
865{
866 ASSERT_WDEV_LOCK(wdev);
867
Johannes Bergfffd0932009-07-08 14:22:54 +0200868 switch (wdev->iftype) {
869 case NL80211_IFTYPE_AP:
870 case NL80211_IFTYPE_AP_VLAN:
Johannes Berg074ac8d2010-09-16 14:58:22 +0200871 case NL80211_IFTYPE_P2P_GO:
Thomas Pedersenff973af2011-05-03 16:57:12 -0700872 case NL80211_IFTYPE_MESH_POINT:
Johannes Bergfffd0932009-07-08 14:22:54 +0200873 break;
874 case NL80211_IFTYPE_ADHOC:
Johannes Bergfffd0932009-07-08 14:22:54 +0200875 case NL80211_IFTYPE_STATION:
Johannes Berg074ac8d2010-09-16 14:58:22 +0200876 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Bergceca7b72013-05-16 00:55:45 +0200877 if (!wdev->current_bss)
Johannes Bergfffd0932009-07-08 14:22:54 +0200878 return -ENOLINK;
879 break;
880 default:
881 return -EINVAL;
882 }
883
884 return 0;
885}
886
Jouni Malinen664834d2014-01-15 00:01:44 +0200887static struct ieee80211_channel *nl80211_get_valid_chan(struct wiphy *wiphy,
888 struct nlattr *tb)
889{
890 struct ieee80211_channel *chan;
891
892 if (tb == NULL)
893 return NULL;
894 chan = ieee80211_get_channel(wiphy, nla_get_u32(tb));
895 if (!chan || chan->flags & IEEE80211_CHAN_DISABLED)
896 return NULL;
897 return chan;
898}
899
Johannes Berg7527a782011-05-13 10:58:57 +0200900static int nl80211_put_iftypes(struct sk_buff *msg, u32 attr, u16 ifmodes)
901{
902 struct nlattr *nl_modes = nla_nest_start(msg, attr);
903 int i;
904
905 if (!nl_modes)
906 goto nla_put_failure;
907
908 i = 0;
909 while (ifmodes) {
David S. Miller9360ffd2012-03-29 04:41:26 -0400910 if ((ifmodes & 1) && nla_put_flag(msg, i))
911 goto nla_put_failure;
Johannes Berg7527a782011-05-13 10:58:57 +0200912 ifmodes >>= 1;
913 i++;
914 }
915
916 nla_nest_end(msg, nl_modes);
917 return 0;
918
919nla_put_failure:
920 return -ENOBUFS;
921}
922
923static int nl80211_put_iface_combinations(struct wiphy *wiphy,
Johannes Bergcdc89b92013-02-18 23:54:36 +0100924 struct sk_buff *msg,
925 bool large)
Johannes Berg7527a782011-05-13 10:58:57 +0200926{
927 struct nlattr *nl_combis;
928 int i, j;
929
930 nl_combis = nla_nest_start(msg,
931 NL80211_ATTR_INTERFACE_COMBINATIONS);
932 if (!nl_combis)
933 goto nla_put_failure;
934
935 for (i = 0; i < wiphy->n_iface_combinations; i++) {
936 const struct ieee80211_iface_combination *c;
937 struct nlattr *nl_combi, *nl_limits;
938
939 c = &wiphy->iface_combinations[i];
940
941 nl_combi = nla_nest_start(msg, i + 1);
942 if (!nl_combi)
943 goto nla_put_failure;
944
945 nl_limits = nla_nest_start(msg, NL80211_IFACE_COMB_LIMITS);
946 if (!nl_limits)
947 goto nla_put_failure;
948
949 for (j = 0; j < c->n_limits; j++) {
950 struct nlattr *nl_limit;
951
952 nl_limit = nla_nest_start(msg, j + 1);
953 if (!nl_limit)
954 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -0400955 if (nla_put_u32(msg, NL80211_IFACE_LIMIT_MAX,
956 c->limits[j].max))
957 goto nla_put_failure;
Johannes Berg7527a782011-05-13 10:58:57 +0200958 if (nl80211_put_iftypes(msg, NL80211_IFACE_LIMIT_TYPES,
959 c->limits[j].types))
960 goto nla_put_failure;
961 nla_nest_end(msg, nl_limit);
962 }
963
964 nla_nest_end(msg, nl_limits);
965
David S. Miller9360ffd2012-03-29 04:41:26 -0400966 if (c->beacon_int_infra_match &&
967 nla_put_flag(msg, NL80211_IFACE_COMB_STA_AP_BI_MATCH))
968 goto nla_put_failure;
969 if (nla_put_u32(msg, NL80211_IFACE_COMB_NUM_CHANNELS,
970 c->num_different_channels) ||
971 nla_put_u32(msg, NL80211_IFACE_COMB_MAXNUM,
972 c->max_interfaces))
973 goto nla_put_failure;
Johannes Bergcdc89b92013-02-18 23:54:36 +0100974 if (large &&
Felix Fietkau8c48b502014-05-05 11:48:40 +0200975 (nla_put_u32(msg, NL80211_IFACE_COMB_RADAR_DETECT_WIDTHS,
976 c->radar_detect_widths) ||
977 nla_put_u32(msg, NL80211_IFACE_COMB_RADAR_DETECT_REGIONS,
978 c->radar_detect_regions)))
Johannes Bergcdc89b92013-02-18 23:54:36 +0100979 goto nla_put_failure;
Johannes Berg7527a782011-05-13 10:58:57 +0200980
981 nla_nest_end(msg, nl_combi);
982 }
983
984 nla_nest_end(msg, nl_combis);
985
986 return 0;
987nla_put_failure:
988 return -ENOBUFS;
989}
990
Johannes Berg3713b4e2013-02-14 16:19:38 +0100991#ifdef CONFIG_PM
Johannes Bergb56cf722013-02-20 01:02:38 +0100992static int nl80211_send_wowlan_tcp_caps(struct cfg80211_registered_device *rdev,
993 struct sk_buff *msg)
994{
Johannes Berg964dc9e2013-06-03 17:25:34 +0200995 const struct wiphy_wowlan_tcp_support *tcp = rdev->wiphy.wowlan->tcp;
Johannes Bergb56cf722013-02-20 01:02:38 +0100996 struct nlattr *nl_tcp;
997
998 if (!tcp)
999 return 0;
1000
1001 nl_tcp = nla_nest_start(msg, NL80211_WOWLAN_TRIG_TCP_CONNECTION);
1002 if (!nl_tcp)
1003 return -ENOBUFS;
1004
1005 if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD,
1006 tcp->data_payload_max))
1007 return -ENOBUFS;
1008
1009 if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD,
1010 tcp->data_payload_max))
1011 return -ENOBUFS;
1012
1013 if (tcp->seq && nla_put_flag(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ))
1014 return -ENOBUFS;
1015
1016 if (tcp->tok && nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN,
1017 sizeof(*tcp->tok), tcp->tok))
1018 return -ENOBUFS;
1019
1020 if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_INTERVAL,
1021 tcp->data_interval_max))
1022 return -ENOBUFS;
1023
1024 if (nla_put_u32(msg, NL80211_WOWLAN_TCP_WAKE_PAYLOAD,
1025 tcp->wake_payload_max))
1026 return -ENOBUFS;
1027
1028 nla_nest_end(msg, nl_tcp);
1029 return 0;
1030}
1031
Johannes Berg3713b4e2013-02-14 16:19:38 +01001032static int nl80211_send_wowlan(struct sk_buff *msg,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001033 struct cfg80211_registered_device *rdev,
Johannes Bergb56cf722013-02-20 01:02:38 +01001034 bool large)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001035{
1036 struct nlattr *nl_wowlan;
1037
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001038 if (!rdev->wiphy.wowlan)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001039 return 0;
1040
1041 nl_wowlan = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS_SUPPORTED);
1042 if (!nl_wowlan)
1043 return -ENOBUFS;
1044
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001045 if (((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_ANY) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001046 nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) ||
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001047 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_DISCONNECT) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001048 nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) ||
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001049 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001050 nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) ||
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001051 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_SUPPORTS_GTK_REKEY) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001052 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED)) ||
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001053 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001054 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) ||
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001055 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001056 nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) ||
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001057 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001058 nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) ||
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001059 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001060 nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE)))
1061 return -ENOBUFS;
1062
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001063 if (rdev->wiphy.wowlan->n_patterns) {
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07001064 struct nl80211_pattern_support pat = {
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001065 .max_patterns = rdev->wiphy.wowlan->n_patterns,
1066 .min_pattern_len = rdev->wiphy.wowlan->pattern_min_len,
1067 .max_pattern_len = rdev->wiphy.wowlan->pattern_max_len,
1068 .max_pkt_offset = rdev->wiphy.wowlan->max_pkt_offset,
Johannes Berg3713b4e2013-02-14 16:19:38 +01001069 };
1070
1071 if (nla_put(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN,
1072 sizeof(pat), &pat))
1073 return -ENOBUFS;
1074 }
1075
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001076 if (large && nl80211_send_wowlan_tcp_caps(rdev, msg))
Johannes Bergb56cf722013-02-20 01:02:38 +01001077 return -ENOBUFS;
1078
Johannes Berg3713b4e2013-02-14 16:19:38 +01001079 nla_nest_end(msg, nl_wowlan);
1080
1081 return 0;
1082}
1083#endif
1084
Amitkumar Karwarbe29b992013-06-28 11:51:26 -07001085static int nl80211_send_coalesce(struct sk_buff *msg,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001086 struct cfg80211_registered_device *rdev)
Amitkumar Karwarbe29b992013-06-28 11:51:26 -07001087{
1088 struct nl80211_coalesce_rule_support rule;
1089
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001090 if (!rdev->wiphy.coalesce)
Amitkumar Karwarbe29b992013-06-28 11:51:26 -07001091 return 0;
1092
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001093 rule.max_rules = rdev->wiphy.coalesce->n_rules;
1094 rule.max_delay = rdev->wiphy.coalesce->max_delay;
1095 rule.pat.max_patterns = rdev->wiphy.coalesce->n_patterns;
1096 rule.pat.min_pattern_len = rdev->wiphy.coalesce->pattern_min_len;
1097 rule.pat.max_pattern_len = rdev->wiphy.coalesce->pattern_max_len;
1098 rule.pat.max_pkt_offset = rdev->wiphy.coalesce->max_pkt_offset;
Amitkumar Karwarbe29b992013-06-28 11:51:26 -07001099
1100 if (nla_put(msg, NL80211_ATTR_COALESCE_RULE, sizeof(rule), &rule))
1101 return -ENOBUFS;
1102
1103 return 0;
1104}
1105
Johannes Berg3713b4e2013-02-14 16:19:38 +01001106static int nl80211_send_band_rateinfo(struct sk_buff *msg,
1107 struct ieee80211_supported_band *sband)
1108{
1109 struct nlattr *nl_rates, *nl_rate;
1110 struct ieee80211_rate *rate;
1111 int i;
1112
1113 /* add HT info */
1114 if (sband->ht_cap.ht_supported &&
1115 (nla_put(msg, NL80211_BAND_ATTR_HT_MCS_SET,
1116 sizeof(sband->ht_cap.mcs),
1117 &sband->ht_cap.mcs) ||
1118 nla_put_u16(msg, NL80211_BAND_ATTR_HT_CAPA,
1119 sband->ht_cap.cap) ||
1120 nla_put_u8(msg, NL80211_BAND_ATTR_HT_AMPDU_FACTOR,
1121 sband->ht_cap.ampdu_factor) ||
1122 nla_put_u8(msg, NL80211_BAND_ATTR_HT_AMPDU_DENSITY,
1123 sband->ht_cap.ampdu_density)))
1124 return -ENOBUFS;
1125
1126 /* add VHT info */
1127 if (sband->vht_cap.vht_supported &&
1128 (nla_put(msg, NL80211_BAND_ATTR_VHT_MCS_SET,
1129 sizeof(sband->vht_cap.vht_mcs),
1130 &sband->vht_cap.vht_mcs) ||
1131 nla_put_u32(msg, NL80211_BAND_ATTR_VHT_CAPA,
1132 sband->vht_cap.cap)))
1133 return -ENOBUFS;
1134
1135 /* add bitrates */
1136 nl_rates = nla_nest_start(msg, NL80211_BAND_ATTR_RATES);
1137 if (!nl_rates)
1138 return -ENOBUFS;
1139
1140 for (i = 0; i < sband->n_bitrates; i++) {
1141 nl_rate = nla_nest_start(msg, i);
1142 if (!nl_rate)
1143 return -ENOBUFS;
1144
1145 rate = &sband->bitrates[i];
1146 if (nla_put_u32(msg, NL80211_BITRATE_ATTR_RATE,
1147 rate->bitrate))
1148 return -ENOBUFS;
1149 if ((rate->flags & IEEE80211_RATE_SHORT_PREAMBLE) &&
1150 nla_put_flag(msg,
1151 NL80211_BITRATE_ATTR_2GHZ_SHORTPREAMBLE))
1152 return -ENOBUFS;
1153
1154 nla_nest_end(msg, nl_rate);
1155 }
1156
1157 nla_nest_end(msg, nl_rates);
1158
1159 return 0;
1160}
1161
1162static int
1163nl80211_send_mgmt_stypes(struct sk_buff *msg,
1164 const struct ieee80211_txrx_stypes *mgmt_stypes)
1165{
1166 u16 stypes;
1167 struct nlattr *nl_ftypes, *nl_ifs;
1168 enum nl80211_iftype ift;
1169 int i;
1170
1171 if (!mgmt_stypes)
1172 return 0;
1173
1174 nl_ifs = nla_nest_start(msg, NL80211_ATTR_TX_FRAME_TYPES);
1175 if (!nl_ifs)
1176 return -ENOBUFS;
1177
1178 for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) {
1179 nl_ftypes = nla_nest_start(msg, ift);
1180 if (!nl_ftypes)
1181 return -ENOBUFS;
1182 i = 0;
1183 stypes = mgmt_stypes[ift].tx;
1184 while (stypes) {
1185 if ((stypes & 1) &&
1186 nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE,
1187 (i << 4) | IEEE80211_FTYPE_MGMT))
1188 return -ENOBUFS;
1189 stypes >>= 1;
1190 i++;
1191 }
1192 nla_nest_end(msg, nl_ftypes);
1193 }
1194
1195 nla_nest_end(msg, nl_ifs);
1196
1197 nl_ifs = nla_nest_start(msg, NL80211_ATTR_RX_FRAME_TYPES);
1198 if (!nl_ifs)
1199 return -ENOBUFS;
1200
1201 for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) {
1202 nl_ftypes = nla_nest_start(msg, ift);
1203 if (!nl_ftypes)
1204 return -ENOBUFS;
1205 i = 0;
1206 stypes = mgmt_stypes[ift].rx;
1207 while (stypes) {
1208 if ((stypes & 1) &&
1209 nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE,
1210 (i << 4) | IEEE80211_FTYPE_MGMT))
1211 return -ENOBUFS;
1212 stypes >>= 1;
1213 i++;
1214 }
1215 nla_nest_end(msg, nl_ftypes);
1216 }
1217 nla_nest_end(msg, nl_ifs);
1218
1219 return 0;
1220}
1221
Johannes Berg86e8cf92013-06-19 10:57:22 +02001222struct nl80211_dump_wiphy_state {
1223 s64 filter_wiphy;
1224 long start;
1225 long split_start, band_start, chan_start;
1226 bool split;
1227};
1228
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001229static int nl80211_send_wiphy(struct cfg80211_registered_device *rdev,
Johannes Berg3bb20552014-05-26 13:52:25 +02001230 enum nl80211_commands cmd,
Johannes Berg3713b4e2013-02-14 16:19:38 +01001231 struct sk_buff *msg, u32 portid, u32 seq,
Johannes Berg86e8cf92013-06-19 10:57:22 +02001232 int flags, struct nl80211_dump_wiphy_state *state)
Johannes Berg55682962007-09-20 13:09:35 -04001233{
1234 void *hdr;
Johannes Bergee688b002008-01-24 19:38:39 +01001235 struct nlattr *nl_bands, *nl_band;
1236 struct nlattr *nl_freqs, *nl_freq;
Johannes Berg8fdc6212009-03-14 09:34:01 +01001237 struct nlattr *nl_cmds;
Johannes Bergee688b002008-01-24 19:38:39 +01001238 enum ieee80211_band band;
1239 struct ieee80211_channel *chan;
Johannes Bergee688b002008-01-24 19:38:39 +01001240 int i;
Johannes Berg2e161f72010-08-12 15:38:38 +02001241 const struct ieee80211_txrx_stypes *mgmt_stypes =
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001242 rdev->wiphy.mgmt_stypes;
Johannes Bergfe1abaf2013-02-27 15:39:45 +01001243 u32 features;
Johannes Berg55682962007-09-20 13:09:35 -04001244
Johannes Berg3bb20552014-05-26 13:52:25 +02001245 hdr = nl80211hdr_put(msg, portid, seq, flags, cmd);
Johannes Berg55682962007-09-20 13:09:35 -04001246 if (!hdr)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001247 return -ENOBUFS;
1248
Johannes Berg86e8cf92013-06-19 10:57:22 +02001249 if (WARN_ON(!state))
1250 return -EINVAL;
Johannes Berg55682962007-09-20 13:09:35 -04001251
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001252 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001253 nla_put_string(msg, NL80211_ATTR_WIPHY_NAME,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001254 wiphy_name(&rdev->wiphy)) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04001255 nla_put_u32(msg, NL80211_ATTR_GENERATION,
Johannes Berg3713b4e2013-02-14 16:19:38 +01001256 cfg80211_rdev_list_generation))
David S. Miller9360ffd2012-03-29 04:41:26 -04001257 goto nla_put_failure;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02001258
Johannes Berg3bb20552014-05-26 13:52:25 +02001259 if (cmd != NL80211_CMD_NEW_WIPHY)
1260 goto finish;
1261
Johannes Berg86e8cf92013-06-19 10:57:22 +02001262 switch (state->split_start) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001263 case 0:
1264 if (nla_put_u8(msg, NL80211_ATTR_WIPHY_RETRY_SHORT,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001265 rdev->wiphy.retry_short) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001266 nla_put_u8(msg, NL80211_ATTR_WIPHY_RETRY_LONG,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001267 rdev->wiphy.retry_long) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001268 nla_put_u32(msg, NL80211_ATTR_WIPHY_FRAG_THRESHOLD,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001269 rdev->wiphy.frag_threshold) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001270 nla_put_u32(msg, NL80211_ATTR_WIPHY_RTS_THRESHOLD,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001271 rdev->wiphy.rts_threshold) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001272 nla_put_u8(msg, NL80211_ATTR_WIPHY_COVERAGE_CLASS,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001273 rdev->wiphy.coverage_class) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001274 nla_put_u8(msg, NL80211_ATTR_MAX_NUM_SCAN_SSIDS,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001275 rdev->wiphy.max_scan_ssids) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001276 nla_put_u8(msg, NL80211_ATTR_MAX_NUM_SCHED_SCAN_SSIDS,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001277 rdev->wiphy.max_sched_scan_ssids) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001278 nla_put_u16(msg, NL80211_ATTR_MAX_SCAN_IE_LEN,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001279 rdev->wiphy.max_scan_ie_len) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001280 nla_put_u16(msg, NL80211_ATTR_MAX_SCHED_SCAN_IE_LEN,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001281 rdev->wiphy.max_sched_scan_ie_len) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001282 nla_put_u8(msg, NL80211_ATTR_MAX_MATCH_SETS,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001283 rdev->wiphy.max_match_sets))
Johannes Bergee688b002008-01-24 19:38:39 +01001284 goto nla_put_failure;
1285
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001286 if ((rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001287 nla_put_flag(msg, NL80211_ATTR_SUPPORT_IBSS_RSN))
1288 goto nla_put_failure;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001289 if ((rdev->wiphy.flags & WIPHY_FLAG_MESH_AUTH) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001290 nla_put_flag(msg, NL80211_ATTR_SUPPORT_MESH_AUTH))
1291 goto nla_put_failure;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001292 if ((rdev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001293 nla_put_flag(msg, NL80211_ATTR_SUPPORT_AP_UAPSD))
1294 goto nla_put_failure;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001295 if ((rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_FW_ROAM) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001296 nla_put_flag(msg, NL80211_ATTR_ROAM_SUPPORT))
1297 goto nla_put_failure;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001298 if ((rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001299 nla_put_flag(msg, NL80211_ATTR_TDLS_SUPPORT))
1300 goto nla_put_failure;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001301 if ((rdev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001302 nla_put_flag(msg, NL80211_ATTR_TDLS_EXTERNAL_SETUP))
David S. Miller9360ffd2012-03-29 04:41:26 -04001303 goto nla_put_failure;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001304 state->split_start++;
1305 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001306 break;
1307 case 1:
1308 if (nla_put(msg, NL80211_ATTR_CIPHER_SUITES,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001309 sizeof(u32) * rdev->wiphy.n_cipher_suites,
1310 rdev->wiphy.cipher_suites))
Mahesh Palivelabf0c111e2012-06-22 07:27:46 +00001311 goto nla_put_failure;
1312
Johannes Berg3713b4e2013-02-14 16:19:38 +01001313 if (nla_put_u8(msg, NL80211_ATTR_MAX_NUM_PMKIDS,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001314 rdev->wiphy.max_num_pmkids))
Johannes Bergee688b002008-01-24 19:38:39 +01001315 goto nla_put_failure;
1316
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001317 if ((rdev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001318 nla_put_flag(msg, NL80211_ATTR_CONTROL_PORT_ETHERTYPE))
1319 goto nla_put_failure;
Johannes Bergee688b002008-01-24 19:38:39 +01001320
Johannes Berg3713b4e2013-02-14 16:19:38 +01001321 if (nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_TX,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001322 rdev->wiphy.available_antennas_tx) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001323 nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_RX,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001324 rdev->wiphy.available_antennas_rx))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001325 goto nla_put_failure;
Johannes Bergee688b002008-01-24 19:38:39 +01001326
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001327 if ((rdev->wiphy.flags & WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001328 nla_put_u32(msg, NL80211_ATTR_PROBE_RESP_OFFLOAD,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001329 rdev->wiphy.probe_resp_offload))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001330 goto nla_put_failure;
Jouni Malinene2f367f262008-11-21 19:01:30 +02001331
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001332 if ((rdev->wiphy.available_antennas_tx ||
1333 rdev->wiphy.available_antennas_rx) &&
1334 rdev->ops->get_antenna) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001335 u32 tx_ant = 0, rx_ant = 0;
1336 int res;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001337 res = rdev_get_antenna(rdev, &tx_ant, &rx_ant);
Johannes Berg3713b4e2013-02-14 16:19:38 +01001338 if (!res) {
1339 if (nla_put_u32(msg,
1340 NL80211_ATTR_WIPHY_ANTENNA_TX,
1341 tx_ant) ||
1342 nla_put_u32(msg,
1343 NL80211_ATTR_WIPHY_ANTENNA_RX,
1344 rx_ant))
1345 goto nla_put_failure;
1346 }
Johannes Bergee688b002008-01-24 19:38:39 +01001347 }
1348
Johannes Berg86e8cf92013-06-19 10:57:22 +02001349 state->split_start++;
1350 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001351 break;
1352 case 2:
1353 if (nl80211_put_iftypes(msg, NL80211_ATTR_SUPPORTED_IFTYPES,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001354 rdev->wiphy.interface_modes))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001355 goto nla_put_failure;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001356 state->split_start++;
1357 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001358 break;
1359 case 3:
1360 nl_bands = nla_nest_start(msg, NL80211_ATTR_WIPHY_BANDS);
1361 if (!nl_bands)
Johannes Bergee688b002008-01-24 19:38:39 +01001362 goto nla_put_failure;
1363
Johannes Berg86e8cf92013-06-19 10:57:22 +02001364 for (band = state->band_start;
1365 band < IEEE80211_NUM_BANDS; band++) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001366 struct ieee80211_supported_band *sband;
1367
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001368 sband = rdev->wiphy.bands[band];
Johannes Berg3713b4e2013-02-14 16:19:38 +01001369
1370 if (!sband)
1371 continue;
1372
1373 nl_band = nla_nest_start(msg, band);
1374 if (!nl_band)
Johannes Bergee688b002008-01-24 19:38:39 +01001375 goto nla_put_failure;
1376
Johannes Berg86e8cf92013-06-19 10:57:22 +02001377 switch (state->chan_start) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001378 case 0:
1379 if (nl80211_send_band_rateinfo(msg, sband))
1380 goto nla_put_failure;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001381 state->chan_start++;
1382 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001383 break;
1384 default:
1385 /* add frequencies */
1386 nl_freqs = nla_nest_start(
1387 msg, NL80211_BAND_ATTR_FREQS);
1388 if (!nl_freqs)
1389 goto nla_put_failure;
Johannes Bergee688b002008-01-24 19:38:39 +01001390
Johannes Berg86e8cf92013-06-19 10:57:22 +02001391 for (i = state->chan_start - 1;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001392 i < sband->n_channels;
1393 i++) {
1394 nl_freq = nla_nest_start(msg, i);
1395 if (!nl_freq)
1396 goto nla_put_failure;
1397
1398 chan = &sband->channels[i];
1399
Johannes Berg86e8cf92013-06-19 10:57:22 +02001400 if (nl80211_msg_put_channel(
1401 msg, chan,
1402 state->split))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001403 goto nla_put_failure;
1404
1405 nla_nest_end(msg, nl_freq);
Johannes Berg86e8cf92013-06-19 10:57:22 +02001406 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001407 break;
1408 }
1409 if (i < sband->n_channels)
Johannes Berg86e8cf92013-06-19 10:57:22 +02001410 state->chan_start = i + 2;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001411 else
Johannes Berg86e8cf92013-06-19 10:57:22 +02001412 state->chan_start = 0;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001413 nla_nest_end(msg, nl_freqs);
1414 }
1415
1416 nla_nest_end(msg, nl_band);
1417
Johannes Berg86e8cf92013-06-19 10:57:22 +02001418 if (state->split) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001419 /* start again here */
Johannes Berg86e8cf92013-06-19 10:57:22 +02001420 if (state->chan_start)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001421 band--;
1422 break;
1423 }
Johannes Bergee688b002008-01-24 19:38:39 +01001424 }
Johannes Berg3713b4e2013-02-14 16:19:38 +01001425 nla_nest_end(msg, nl_bands);
Johannes Bergee688b002008-01-24 19:38:39 +01001426
Johannes Berg3713b4e2013-02-14 16:19:38 +01001427 if (band < IEEE80211_NUM_BANDS)
Johannes Berg86e8cf92013-06-19 10:57:22 +02001428 state->band_start = band + 1;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001429 else
Johannes Berg86e8cf92013-06-19 10:57:22 +02001430 state->band_start = 0;
Johannes Bergee688b002008-01-24 19:38:39 +01001431
Johannes Berg3713b4e2013-02-14 16:19:38 +01001432 /* if bands & channels are done, continue outside */
Johannes Berg86e8cf92013-06-19 10:57:22 +02001433 if (state->band_start == 0 && state->chan_start == 0)
1434 state->split_start++;
1435 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001436 break;
1437 case 4:
1438 nl_cmds = nla_nest_start(msg, NL80211_ATTR_SUPPORTED_COMMANDS);
1439 if (!nl_cmds)
David S. Miller9360ffd2012-03-29 04:41:26 -04001440 goto nla_put_failure;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001441
1442 i = 0;
1443#define CMD(op, n) \
1444 do { \
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001445 if (rdev->ops->op) { \
Johannes Berg3713b4e2013-02-14 16:19:38 +01001446 i++; \
1447 if (nla_put_u32(msg, i, NL80211_CMD_ ## n)) \
1448 goto nla_put_failure; \
1449 } \
1450 } while (0)
1451
1452 CMD(add_virtual_intf, NEW_INTERFACE);
1453 CMD(change_virtual_intf, SET_INTERFACE);
1454 CMD(add_key, NEW_KEY);
1455 CMD(start_ap, START_AP);
1456 CMD(add_station, NEW_STATION);
1457 CMD(add_mpath, NEW_MPATH);
1458 CMD(update_mesh_config, SET_MESH_CONFIG);
1459 CMD(change_bss, SET_BSS);
1460 CMD(auth, AUTHENTICATE);
1461 CMD(assoc, ASSOCIATE);
1462 CMD(deauth, DEAUTHENTICATE);
1463 CMD(disassoc, DISASSOCIATE);
1464 CMD(join_ibss, JOIN_IBSS);
1465 CMD(join_mesh, JOIN_MESH);
1466 CMD(set_pmksa, SET_PMKSA);
1467 CMD(del_pmksa, DEL_PMKSA);
1468 CMD(flush_pmksa, FLUSH_PMKSA);
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001469 if (rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001470 CMD(remain_on_channel, REMAIN_ON_CHANNEL);
1471 CMD(set_bitrate_mask, SET_TX_BITRATE_MASK);
1472 CMD(mgmt_tx, FRAME);
1473 CMD(mgmt_tx_cancel_wait, FRAME_WAIT_CANCEL);
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001474 if (rdev->wiphy.flags & WIPHY_FLAG_NETNS_OK) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001475 i++;
1476 if (nla_put_u32(msg, i, NL80211_CMD_SET_WIPHY_NETNS))
1477 goto nla_put_failure;
1478 }
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001479 if (rdev->ops->set_monitor_channel || rdev->ops->start_ap ||
1480 rdev->ops->join_mesh) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001481 i++;
1482 if (nla_put_u32(msg, i, NL80211_CMD_SET_CHANNEL))
1483 goto nla_put_failure;
1484 }
1485 CMD(set_wds_peer, SET_WDS_PEER);
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001486 if (rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001487 CMD(tdls_mgmt, TDLS_MGMT);
1488 CMD(tdls_oper, TDLS_OPER);
1489 }
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001490 if (rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001491 CMD(sched_scan_start, START_SCHED_SCAN);
1492 CMD(probe_client, PROBE_CLIENT);
1493 CMD(set_noack_map, SET_NOACK_MAP);
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001494 if (rdev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001495 i++;
1496 if (nla_put_u32(msg, i, NL80211_CMD_REGISTER_BEACONS))
1497 goto nla_put_failure;
1498 }
1499 CMD(start_p2p_device, START_P2P_DEVICE);
1500 CMD(set_mcast_rate, SET_MCAST_RATE);
Johannes Berg02df00e2014-06-10 14:06:25 +02001501#ifdef CONFIG_NL80211_TESTMODE
1502 CMD(testmode_cmd, TESTMODE);
1503#endif
Johannes Berg86e8cf92013-06-19 10:57:22 +02001504 if (state->split) {
Arend van Spriel5de17982013-04-18 15:49:00 +02001505 CMD(crit_proto_start, CRIT_PROTOCOL_START);
1506 CMD(crit_proto_stop, CRIT_PROTOCOL_STOP);
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001507 if (rdev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH)
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02001508 CMD(channel_switch, CHANNEL_SWITCH);
Johannes Berg02df00e2014-06-10 14:06:25 +02001509 CMD(set_qos_map, SET_QOS_MAP);
Arend van Spriel5de17982013-04-18 15:49:00 +02001510 }
Johannes Berg02df00e2014-06-10 14:06:25 +02001511 /* add into the if now */
Johannes Berg8fdc6212009-03-14 09:34:01 +01001512#undef CMD
Samuel Ortizb23aa672009-07-01 21:26:54 +02001513
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001514 if (rdev->ops->connect || rdev->ops->auth) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001515 i++;
1516 if (nla_put_u32(msg, i, NL80211_CMD_CONNECT))
Johannes Berg2e161f72010-08-12 15:38:38 +02001517 goto nla_put_failure;
Johannes Berg2e161f72010-08-12 15:38:38 +02001518 }
1519
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001520 if (rdev->ops->disconnect || rdev->ops->deauth) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001521 i++;
1522 if (nla_put_u32(msg, i, NL80211_CMD_DISCONNECT))
1523 goto nla_put_failure;
1524 }
Johannes Berg74b70a42010-08-24 12:15:53 +02001525
Johannes Berg3713b4e2013-02-14 16:19:38 +01001526 nla_nest_end(msg, nl_cmds);
Johannes Berg86e8cf92013-06-19 10:57:22 +02001527 state->split_start++;
1528 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001529 break;
1530 case 5:
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001531 if (rdev->ops->remain_on_channel &&
1532 (rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001533 nla_put_u32(msg,
1534 NL80211_ATTR_MAX_REMAIN_ON_CHANNEL_DURATION,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001535 rdev->wiphy.max_remain_on_channel_duration))
Johannes Berg2e161f72010-08-12 15:38:38 +02001536 goto nla_put_failure;
1537
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001538 if ((rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001539 nla_put_flag(msg, NL80211_ATTR_OFFCHANNEL_TX_OK))
1540 goto nla_put_failure;
Johannes Berg2e161f72010-08-12 15:38:38 +02001541
Johannes Berg3713b4e2013-02-14 16:19:38 +01001542 if (nl80211_send_mgmt_stypes(msg, mgmt_stypes))
1543 goto nla_put_failure;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001544 state->split_start++;
1545 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001546 break;
1547 case 6:
Johannes Bergdfb89c52012-06-27 09:23:48 +02001548#ifdef CONFIG_PM
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001549 if (nl80211_send_wowlan(msg, rdev, state->split))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001550 goto nla_put_failure;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001551 state->split_start++;
1552 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001553 break;
1554#else
Johannes Berg86e8cf92013-06-19 10:57:22 +02001555 state->split_start++;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001556#endif
1557 case 7:
1558 if (nl80211_put_iftypes(msg, NL80211_ATTR_SOFTWARE_IFTYPES,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001559 rdev->wiphy.software_iftypes))
Johannes Bergff1b6e62011-05-04 15:37:28 +02001560 goto nla_put_failure;
1561
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001562 if (nl80211_put_iface_combinations(&rdev->wiphy, msg,
Johannes Berg86e8cf92013-06-19 10:57:22 +02001563 state->split))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001564 goto nla_put_failure;
Johannes Bergff1b6e62011-05-04 15:37:28 +02001565
Johannes Berg86e8cf92013-06-19 10:57:22 +02001566 state->split_start++;
1567 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001568 break;
1569 case 8:
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001570 if ((rdev->wiphy.flags & WIPHY_FLAG_HAVE_AP_SME) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001571 nla_put_u32(msg, NL80211_ATTR_DEVICE_AP_SME,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001572 rdev->wiphy.ap_sme_capa))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001573 goto nla_put_failure;
1574
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001575 features = rdev->wiphy.features;
Johannes Bergfe1abaf2013-02-27 15:39:45 +01001576 /*
1577 * We can only add the per-channel limit information if the
1578 * dump is split, otherwise it makes it too big. Therefore
1579 * only advertise it in that case.
1580 */
Johannes Berg86e8cf92013-06-19 10:57:22 +02001581 if (state->split)
Johannes Bergfe1abaf2013-02-27 15:39:45 +01001582 features |= NL80211_FEATURE_ADVERTISE_CHAN_LIMITS;
1583 if (nla_put_u32(msg, NL80211_ATTR_FEATURE_FLAGS, features))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001584 goto nla_put_failure;
1585
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001586 if (rdev->wiphy.ht_capa_mod_mask &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001587 nla_put(msg, NL80211_ATTR_HT_CAPABILITY_MASK,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001588 sizeof(*rdev->wiphy.ht_capa_mod_mask),
1589 rdev->wiphy.ht_capa_mod_mask))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001590 goto nla_put_failure;
1591
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001592 if (rdev->wiphy.flags & WIPHY_FLAG_HAVE_AP_SME &&
1593 rdev->wiphy.max_acl_mac_addrs &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001594 nla_put_u32(msg, NL80211_ATTR_MAC_ACL_MAX,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001595 rdev->wiphy.max_acl_mac_addrs))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001596 goto nla_put_failure;
1597
1598 /*
1599 * Any information below this point is only available to
1600 * applications that can deal with it being split. This
1601 * helps ensure that newly added capabilities don't break
1602 * older tools by overrunning their buffers.
1603 *
1604 * We still increment split_start so that in the split
1605 * case we'll continue with more data in the next round,
1606 * but break unconditionally so unsplit data stops here.
1607 */
Johannes Berg86e8cf92013-06-19 10:57:22 +02001608 state->split_start++;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001609 break;
1610 case 9:
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001611 if (rdev->wiphy.extended_capabilities &&
Johannes Bergfe1abaf2013-02-27 15:39:45 +01001612 (nla_put(msg, NL80211_ATTR_EXT_CAPA,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001613 rdev->wiphy.extended_capabilities_len,
1614 rdev->wiphy.extended_capabilities) ||
Johannes Bergfe1abaf2013-02-27 15:39:45 +01001615 nla_put(msg, NL80211_ATTR_EXT_CAPA_MASK,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001616 rdev->wiphy.extended_capabilities_len,
1617 rdev->wiphy.extended_capabilities_mask)))
Johannes Bergfe1abaf2013-02-27 15:39:45 +01001618 goto nla_put_failure;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001619
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001620 if (rdev->wiphy.vht_capa_mod_mask &&
Johannes Bergee2aca32013-02-21 17:36:01 +01001621 nla_put(msg, NL80211_ATTR_VHT_CAPABILITY_MASK,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001622 sizeof(*rdev->wiphy.vht_capa_mod_mask),
1623 rdev->wiphy.vht_capa_mod_mask))
Johannes Bergee2aca32013-02-21 17:36:01 +01001624 goto nla_put_failure;
1625
Amitkumar Karwarbe29b992013-06-28 11:51:26 -07001626 state->split_start++;
1627 break;
1628 case 10:
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001629 if (nl80211_send_coalesce(msg, rdev))
Amitkumar Karwarbe29b992013-06-28 11:51:26 -07001630 goto nla_put_failure;
1631
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001632 if ((rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_5_10_MHZ) &&
Felix Fietkau01e0daa2013-11-09 14:57:54 +01001633 (nla_put_flag(msg, NL80211_ATTR_SUPPORT_5_MHZ) ||
1634 nla_put_flag(msg, NL80211_ATTR_SUPPORT_10_MHZ)))
1635 goto nla_put_failure;
Jouni Malinenb43504c2014-01-15 00:01:08 +02001636
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001637 if (rdev->wiphy.max_ap_assoc_sta &&
Jouni Malinenb43504c2014-01-15 00:01:08 +02001638 nla_put_u32(msg, NL80211_ATTR_MAX_AP_ASSOC_STA,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001639 rdev->wiphy.max_ap_assoc_sta))
Jouni Malinenb43504c2014-01-15 00:01:08 +02001640 goto nla_put_failure;
1641
Johannes Bergad7e7182013-11-13 13:37:47 +01001642 state->split_start++;
1643 break;
1644 case 11:
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001645 if (rdev->wiphy.n_vendor_commands) {
Johannes Berg567ffc32013-12-18 14:43:31 +01001646 const struct nl80211_vendor_cmd_info *info;
1647 struct nlattr *nested;
Johannes Bergad7e7182013-11-13 13:37:47 +01001648
Johannes Berg567ffc32013-12-18 14:43:31 +01001649 nested = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA);
1650 if (!nested)
Johannes Bergad7e7182013-11-13 13:37:47 +01001651 goto nla_put_failure;
Johannes Berg567ffc32013-12-18 14:43:31 +01001652
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001653 for (i = 0; i < rdev->wiphy.n_vendor_commands; i++) {
1654 info = &rdev->wiphy.vendor_commands[i].info;
Johannes Berg567ffc32013-12-18 14:43:31 +01001655 if (nla_put(msg, i + 1, sizeof(*info), info))
1656 goto nla_put_failure;
1657 }
1658 nla_nest_end(msg, nested);
1659 }
1660
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001661 if (rdev->wiphy.n_vendor_events) {
Johannes Berg567ffc32013-12-18 14:43:31 +01001662 const struct nl80211_vendor_cmd_info *info;
1663 struct nlattr *nested;
1664
1665 nested = nla_nest_start(msg,
1666 NL80211_ATTR_VENDOR_EVENTS);
1667 if (!nested)
1668 goto nla_put_failure;
1669
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001670 for (i = 0; i < rdev->wiphy.n_vendor_events; i++) {
1671 info = &rdev->wiphy.vendor_events[i];
Johannes Berg567ffc32013-12-18 14:43:31 +01001672 if (nla_put(msg, i + 1, sizeof(*info), info))
1673 goto nla_put_failure;
1674 }
1675 nla_nest_end(msg, nested);
1676 }
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03001677 state->split_start++;
1678 break;
1679 case 12:
1680 if (rdev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH &&
1681 nla_put_u8(msg, NL80211_ATTR_MAX_CSA_COUNTERS,
1682 rdev->wiphy.max_num_csa_counters))
1683 goto nla_put_failure;
Felix Fietkau01e0daa2013-11-09 14:57:54 +01001684
Johannes Berg3713b4e2013-02-14 16:19:38 +01001685 /* done */
Johannes Berg86e8cf92013-06-19 10:57:22 +02001686 state->split_start = 0;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001687 break;
Johannes Bergff1b6e62011-05-04 15:37:28 +02001688 }
Johannes Berg3bb20552014-05-26 13:52:25 +02001689 finish:
Johannes Berg55682962007-09-20 13:09:35 -04001690 return genlmsg_end(msg, hdr);
1691
1692 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07001693 genlmsg_cancel(msg, hdr);
1694 return -EMSGSIZE;
Johannes Berg55682962007-09-20 13:09:35 -04001695}
1696
Johannes Berg86e8cf92013-06-19 10:57:22 +02001697static int nl80211_dump_wiphy_parse(struct sk_buff *skb,
1698 struct netlink_callback *cb,
1699 struct nl80211_dump_wiphy_state *state)
1700{
1701 struct nlattr **tb = nl80211_fam.attrbuf;
1702 int ret = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize,
1703 tb, nl80211_fam.maxattr, nl80211_policy);
1704 /* ignore parse errors for backward compatibility */
1705 if (ret)
1706 return 0;
1707
1708 state->split = tb[NL80211_ATTR_SPLIT_WIPHY_DUMP];
1709 if (tb[NL80211_ATTR_WIPHY])
1710 state->filter_wiphy = nla_get_u32(tb[NL80211_ATTR_WIPHY]);
1711 if (tb[NL80211_ATTR_WDEV])
1712 state->filter_wiphy = nla_get_u64(tb[NL80211_ATTR_WDEV]) >> 32;
1713 if (tb[NL80211_ATTR_IFINDEX]) {
1714 struct net_device *netdev;
1715 struct cfg80211_registered_device *rdev;
1716 int ifidx = nla_get_u32(tb[NL80211_ATTR_IFINDEX]);
1717
Ying Xue7f2b8562014-01-15 10:23:45 +08001718 netdev = __dev_get_by_index(sock_net(skb->sk), ifidx);
Johannes Berg86e8cf92013-06-19 10:57:22 +02001719 if (!netdev)
1720 return -ENODEV;
1721 if (netdev->ieee80211_ptr) {
Zhao, Gangf26cbf42014-04-21 12:53:03 +08001722 rdev = wiphy_to_rdev(
Johannes Berg86e8cf92013-06-19 10:57:22 +02001723 netdev->ieee80211_ptr->wiphy);
1724 state->filter_wiphy = rdev->wiphy_idx;
1725 }
Johannes Berg86e8cf92013-06-19 10:57:22 +02001726 }
1727
1728 return 0;
1729}
1730
Johannes Berg55682962007-09-20 13:09:35 -04001731static int nl80211_dump_wiphy(struct sk_buff *skb, struct netlink_callback *cb)
1732{
Johannes Berg645e77d2013-03-01 14:03:49 +01001733 int idx = 0, ret;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001734 struct nl80211_dump_wiphy_state *state = (void *)cb->args[0];
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001735 struct cfg80211_registered_device *rdev;
Johannes Berg3a5a4232013-06-19 10:09:57 +02001736
Johannes Berg5fe231e2013-05-08 21:45:15 +02001737 rtnl_lock();
Johannes Berg86e8cf92013-06-19 10:57:22 +02001738 if (!state) {
1739 state = kzalloc(sizeof(*state), GFP_KERNEL);
John W. Linville57ed5cd2013-06-28 13:18:21 -04001740 if (!state) {
1741 rtnl_unlock();
Johannes Berg86e8cf92013-06-19 10:57:22 +02001742 return -ENOMEM;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001743 }
Johannes Berg86e8cf92013-06-19 10:57:22 +02001744 state->filter_wiphy = -1;
1745 ret = nl80211_dump_wiphy_parse(skb, cb, state);
1746 if (ret) {
1747 kfree(state);
1748 rtnl_unlock();
1749 return ret;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001750 }
Johannes Berg86e8cf92013-06-19 10:57:22 +02001751 cb->args[0] = (long)state;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001752 }
1753
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001754 list_for_each_entry(rdev, &cfg80211_rdev_list, list) {
1755 if (!net_eq(wiphy_net(&rdev->wiphy), sock_net(skb->sk)))
Johannes Berg463d0182009-07-14 00:33:35 +02001756 continue;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001757 if (++idx <= state->start)
Johannes Berg55682962007-09-20 13:09:35 -04001758 continue;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001759 if (state->filter_wiphy != -1 &&
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001760 state->filter_wiphy != rdev->wiphy_idx)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001761 continue;
1762 /* attempt to fit multiple wiphy data chunks into the skb */
1763 do {
Johannes Berg3bb20552014-05-26 13:52:25 +02001764 ret = nl80211_send_wiphy(rdev, NL80211_CMD_NEW_WIPHY,
1765 skb,
Johannes Berg3713b4e2013-02-14 16:19:38 +01001766 NETLINK_CB(cb->skb).portid,
1767 cb->nlh->nlmsg_seq,
Johannes Berg86e8cf92013-06-19 10:57:22 +02001768 NLM_F_MULTI, state);
Johannes Berg3713b4e2013-02-14 16:19:38 +01001769 if (ret < 0) {
1770 /*
1771 * If sending the wiphy data didn't fit (ENOBUFS
1772 * or EMSGSIZE returned), this SKB is still
1773 * empty (so it's not too big because another
1774 * wiphy dataset is already in the skb) and
1775 * we've not tried to adjust the dump allocation
1776 * yet ... then adjust the alloc size to be
1777 * bigger, and return 1 but with the empty skb.
1778 * This results in an empty message being RX'ed
1779 * in userspace, but that is ignored.
1780 *
1781 * We can then retry with the larger buffer.
1782 */
1783 if ((ret == -ENOBUFS || ret == -EMSGSIZE) &&
Pontus Fuchsf12cb282014-01-16 15:00:40 +01001784 !skb->len && !state->split &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001785 cb->min_dump_alloc < 4096) {
1786 cb->min_dump_alloc = 4096;
Pontus Fuchsf12cb282014-01-16 15:00:40 +01001787 state->split_start = 0;
David S. Millerd98cae64e2013-06-19 16:49:39 -07001788 rtnl_unlock();
Johannes Berg3713b4e2013-02-14 16:19:38 +01001789 return 1;
1790 }
1791 idx--;
1792 break;
Johannes Berg645e77d2013-03-01 14:03:49 +01001793 }
Johannes Berg86e8cf92013-06-19 10:57:22 +02001794 } while (state->split_start > 0);
Johannes Berg3713b4e2013-02-14 16:19:38 +01001795 break;
Johannes Berg55682962007-09-20 13:09:35 -04001796 }
Johannes Berg5fe231e2013-05-08 21:45:15 +02001797 rtnl_unlock();
Johannes Berg55682962007-09-20 13:09:35 -04001798
Johannes Berg86e8cf92013-06-19 10:57:22 +02001799 state->start = idx;
Johannes Berg55682962007-09-20 13:09:35 -04001800
1801 return skb->len;
1802}
1803
Johannes Berg86e8cf92013-06-19 10:57:22 +02001804static int nl80211_dump_wiphy_done(struct netlink_callback *cb)
1805{
1806 kfree((void *)cb->args[0]);
1807 return 0;
1808}
1809
Johannes Berg55682962007-09-20 13:09:35 -04001810static int nl80211_get_wiphy(struct sk_buff *skb, struct genl_info *info)
1811{
1812 struct sk_buff *msg;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001813 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg86e8cf92013-06-19 10:57:22 +02001814 struct nl80211_dump_wiphy_state state = {};
Johannes Berg55682962007-09-20 13:09:35 -04001815
Johannes Berg645e77d2013-03-01 14:03:49 +01001816 msg = nlmsg_new(4096, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -04001817 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02001818 return -ENOMEM;
Johannes Berg55682962007-09-20 13:09:35 -04001819
Johannes Berg3bb20552014-05-26 13:52:25 +02001820 if (nl80211_send_wiphy(rdev, NL80211_CMD_NEW_WIPHY, msg,
1821 info->snd_portid, info->snd_seq, 0,
Johannes Berg86e8cf92013-06-19 10:57:22 +02001822 &state) < 0) {
Johannes Berg4c476992010-10-04 21:36:35 +02001823 nlmsg_free(msg);
1824 return -ENOBUFS;
1825 }
Johannes Berg55682962007-09-20 13:09:35 -04001826
Johannes Berg134e6372009-07-10 09:51:34 +00001827 return genlmsg_reply(msg, info);
Johannes Berg55682962007-09-20 13:09:35 -04001828}
1829
Jouni Malinen31888482008-10-30 16:59:24 +02001830static const struct nla_policy txq_params_policy[NL80211_TXQ_ATTR_MAX + 1] = {
1831 [NL80211_TXQ_ATTR_QUEUE] = { .type = NLA_U8 },
1832 [NL80211_TXQ_ATTR_TXOP] = { .type = NLA_U16 },
1833 [NL80211_TXQ_ATTR_CWMIN] = { .type = NLA_U16 },
1834 [NL80211_TXQ_ATTR_CWMAX] = { .type = NLA_U16 },
1835 [NL80211_TXQ_ATTR_AIFS] = { .type = NLA_U8 },
1836};
1837
1838static int parse_txq_params(struct nlattr *tb[],
1839 struct ieee80211_txq_params *txq_params)
1840{
Johannes Berga3304b02012-03-28 11:04:24 +02001841 if (!tb[NL80211_TXQ_ATTR_AC] || !tb[NL80211_TXQ_ATTR_TXOP] ||
Jouni Malinen31888482008-10-30 16:59:24 +02001842 !tb[NL80211_TXQ_ATTR_CWMIN] || !tb[NL80211_TXQ_ATTR_CWMAX] ||
1843 !tb[NL80211_TXQ_ATTR_AIFS])
1844 return -EINVAL;
1845
Johannes Berga3304b02012-03-28 11:04:24 +02001846 txq_params->ac = nla_get_u8(tb[NL80211_TXQ_ATTR_AC]);
Jouni Malinen31888482008-10-30 16:59:24 +02001847 txq_params->txop = nla_get_u16(tb[NL80211_TXQ_ATTR_TXOP]);
1848 txq_params->cwmin = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMIN]);
1849 txq_params->cwmax = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMAX]);
1850 txq_params->aifs = nla_get_u8(tb[NL80211_TXQ_ATTR_AIFS]);
1851
Johannes Berga3304b02012-03-28 11:04:24 +02001852 if (txq_params->ac >= NL80211_NUM_ACS)
1853 return -EINVAL;
1854
Jouni Malinen31888482008-10-30 16:59:24 +02001855 return 0;
1856}
1857
Johannes Bergf444de02010-05-05 15:25:02 +02001858static bool nl80211_can_set_dev_channel(struct wireless_dev *wdev)
1859{
1860 /*
Johannes Bergcc1d2802012-05-16 23:50:20 +02001861 * You can only set the channel explicitly for WDS interfaces,
1862 * all others have their channel managed via their respective
1863 * "establish a connection" command (connect, join, ...)
1864 *
1865 * For AP/GO and mesh mode, the channel can be set with the
1866 * channel userspace API, but is only stored and passed to the
1867 * low-level driver when the AP starts or the mesh is joined.
1868 * This is for backward compatibility, userspace can also give
1869 * the channel in the start-ap or join-mesh commands instead.
Johannes Bergf444de02010-05-05 15:25:02 +02001870 *
1871 * Monitors are special as they are normally slaved to
Johannes Berge8c9bd52012-06-06 08:18:22 +02001872 * whatever else is going on, so they have their own special
1873 * operation to set the monitor channel if possible.
Johannes Bergf444de02010-05-05 15:25:02 +02001874 */
1875 return !wdev ||
1876 wdev->iftype == NL80211_IFTYPE_AP ||
Johannes Bergf444de02010-05-05 15:25:02 +02001877 wdev->iftype == NL80211_IFTYPE_MESH_POINT ||
Johannes Berg074ac8d2010-09-16 14:58:22 +02001878 wdev->iftype == NL80211_IFTYPE_MONITOR ||
1879 wdev->iftype == NL80211_IFTYPE_P2P_GO;
Johannes Bergf444de02010-05-05 15:25:02 +02001880}
1881
Johannes Berg683b6d32012-11-08 21:25:48 +01001882static int nl80211_parse_chandef(struct cfg80211_registered_device *rdev,
1883 struct genl_info *info,
1884 struct cfg80211_chan_def *chandef)
1885{
Mahesh Paliveladbeca2e2012-11-29 14:11:07 +05301886 u32 control_freq;
Johannes Berg683b6d32012-11-08 21:25:48 +01001887
1888 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ])
1889 return -EINVAL;
1890
1891 control_freq = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]);
1892
1893 chandef->chan = ieee80211_get_channel(&rdev->wiphy, control_freq);
Johannes Berg3d9d1d62012-11-08 23:14:50 +01001894 chandef->width = NL80211_CHAN_WIDTH_20_NOHT;
1895 chandef->center_freq1 = control_freq;
1896 chandef->center_freq2 = 0;
Johannes Berg683b6d32012-11-08 21:25:48 +01001897
1898 /* Primary channel not allowed */
1899 if (!chandef->chan || chandef->chan->flags & IEEE80211_CHAN_DISABLED)
1900 return -EINVAL;
1901
Johannes Berg3d9d1d62012-11-08 23:14:50 +01001902 if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]) {
1903 enum nl80211_channel_type chantype;
Johannes Berg683b6d32012-11-08 21:25:48 +01001904
Johannes Berg3d9d1d62012-11-08 23:14:50 +01001905 chantype = nla_get_u32(
1906 info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]);
1907
1908 switch (chantype) {
1909 case NL80211_CHAN_NO_HT:
1910 case NL80211_CHAN_HT20:
1911 case NL80211_CHAN_HT40PLUS:
1912 case NL80211_CHAN_HT40MINUS:
1913 cfg80211_chandef_create(chandef, chandef->chan,
1914 chantype);
1915 break;
1916 default:
Johannes Berg683b6d32012-11-08 21:25:48 +01001917 return -EINVAL;
Johannes Berg683b6d32012-11-08 21:25:48 +01001918 }
Johannes Berg3d9d1d62012-11-08 23:14:50 +01001919 } else if (info->attrs[NL80211_ATTR_CHANNEL_WIDTH]) {
1920 chandef->width =
1921 nla_get_u32(info->attrs[NL80211_ATTR_CHANNEL_WIDTH]);
1922 if (info->attrs[NL80211_ATTR_CENTER_FREQ1])
1923 chandef->center_freq1 =
1924 nla_get_u32(
1925 info->attrs[NL80211_ATTR_CENTER_FREQ1]);
1926 if (info->attrs[NL80211_ATTR_CENTER_FREQ2])
1927 chandef->center_freq2 =
1928 nla_get_u32(
1929 info->attrs[NL80211_ATTR_CENTER_FREQ2]);
1930 }
1931
Johannes Berg9f5e8f62012-11-22 16:59:45 +01001932 if (!cfg80211_chandef_valid(chandef))
Johannes Berg3d9d1d62012-11-08 23:14:50 +01001933 return -EINVAL;
1934
Johannes Berg9f5e8f62012-11-22 16:59:45 +01001935 if (!cfg80211_chandef_usable(&rdev->wiphy, chandef,
1936 IEEE80211_CHAN_DISABLED))
Johannes Berg3d9d1d62012-11-08 23:14:50 +01001937 return -EINVAL;
Johannes Berg3d9d1d62012-11-08 23:14:50 +01001938
Simon Wunderlich2f301ab2013-05-16 13:00:28 +02001939 if ((chandef->width == NL80211_CHAN_WIDTH_5 ||
1940 chandef->width == NL80211_CHAN_WIDTH_10) &&
1941 !(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_5_10_MHZ))
1942 return -EINVAL;
1943
Johannes Berg683b6d32012-11-08 21:25:48 +01001944 return 0;
1945}
1946
Johannes Bergf444de02010-05-05 15:25:02 +02001947static int __nl80211_set_channel(struct cfg80211_registered_device *rdev,
Jouni Malinene16821b2014-04-28 11:22:08 +03001948 struct net_device *dev,
Johannes Bergf444de02010-05-05 15:25:02 +02001949 struct genl_info *info)
1950{
Johannes Berg683b6d32012-11-08 21:25:48 +01001951 struct cfg80211_chan_def chandef;
Johannes Bergf444de02010-05-05 15:25:02 +02001952 int result;
Johannes Berge8c9bd52012-06-06 08:18:22 +02001953 enum nl80211_iftype iftype = NL80211_IFTYPE_MONITOR;
Jouni Malinene16821b2014-04-28 11:22:08 +03001954 struct wireless_dev *wdev = NULL;
Johannes Berge8c9bd52012-06-06 08:18:22 +02001955
Jouni Malinene16821b2014-04-28 11:22:08 +03001956 if (dev)
1957 wdev = dev->ieee80211_ptr;
Johannes Bergf444de02010-05-05 15:25:02 +02001958 if (!nl80211_can_set_dev_channel(wdev))
1959 return -EOPNOTSUPP;
Jouni Malinene16821b2014-04-28 11:22:08 +03001960 if (wdev)
1961 iftype = wdev->iftype;
Johannes Bergf444de02010-05-05 15:25:02 +02001962
Johannes Berg683b6d32012-11-08 21:25:48 +01001963 result = nl80211_parse_chandef(rdev, info, &chandef);
1964 if (result)
1965 return result;
Johannes Bergf444de02010-05-05 15:25:02 +02001966
Johannes Berge8c9bd52012-06-06 08:18:22 +02001967 switch (iftype) {
Johannes Bergaa430da2012-05-16 23:50:18 +02001968 case NL80211_IFTYPE_AP:
1969 case NL80211_IFTYPE_P2P_GO:
Ilan Peer174e0cd2014-02-23 09:13:01 +02001970 if (!cfg80211_reg_can_beacon(&rdev->wiphy, &chandef, iftype)) {
Johannes Bergaa430da2012-05-16 23:50:18 +02001971 result = -EINVAL;
1972 break;
1973 }
Jouni Malinene16821b2014-04-28 11:22:08 +03001974 if (wdev->beacon_interval) {
1975 if (!dev || !rdev->ops->set_ap_chanwidth ||
1976 !(rdev->wiphy.features &
1977 NL80211_FEATURE_AP_MODE_CHAN_WIDTH_CHANGE)) {
1978 result = -EBUSY;
1979 break;
1980 }
1981
1982 /* Only allow dynamic channel width changes */
1983 if (chandef.chan != wdev->preset_chandef.chan) {
1984 result = -EBUSY;
1985 break;
1986 }
1987 result = rdev_set_ap_chanwidth(rdev, dev, &chandef);
1988 if (result)
1989 break;
1990 }
Johannes Berg683b6d32012-11-08 21:25:48 +01001991 wdev->preset_chandef = chandef;
Johannes Bergaa430da2012-05-16 23:50:18 +02001992 result = 0;
1993 break;
Johannes Bergcc1d2802012-05-16 23:50:20 +02001994 case NL80211_IFTYPE_MESH_POINT:
Johannes Berg683b6d32012-11-08 21:25:48 +01001995 result = cfg80211_set_mesh_channel(rdev, wdev, &chandef);
Johannes Bergcc1d2802012-05-16 23:50:20 +02001996 break;
Johannes Berge8c9bd52012-06-06 08:18:22 +02001997 case NL80211_IFTYPE_MONITOR:
Johannes Berg683b6d32012-11-08 21:25:48 +01001998 result = cfg80211_set_monitor_channel(rdev, &chandef);
Johannes Berge8c9bd52012-06-06 08:18:22 +02001999 break;
Johannes Bergaa430da2012-05-16 23:50:18 +02002000 default:
Johannes Berge8c9bd52012-06-06 08:18:22 +02002001 result = -EINVAL;
Johannes Bergf444de02010-05-05 15:25:02 +02002002 }
Johannes Bergf444de02010-05-05 15:25:02 +02002003
2004 return result;
2005}
2006
2007static int nl80211_set_channel(struct sk_buff *skb, struct genl_info *info)
2008{
Johannes Berg4c476992010-10-04 21:36:35 +02002009 struct cfg80211_registered_device *rdev = info->user_ptr[0];
2010 struct net_device *netdev = info->user_ptr[1];
Johannes Bergf444de02010-05-05 15:25:02 +02002011
Jouni Malinene16821b2014-04-28 11:22:08 +03002012 return __nl80211_set_channel(rdev, netdev, info);
Johannes Bergf444de02010-05-05 15:25:02 +02002013}
2014
Bill Jordane8347eb2010-10-01 13:54:28 -04002015static int nl80211_set_wds_peer(struct sk_buff *skb, struct genl_info *info)
2016{
Johannes Berg43b19952010-10-07 13:10:30 +02002017 struct cfg80211_registered_device *rdev = info->user_ptr[0];
2018 struct net_device *dev = info->user_ptr[1];
2019 struct wireless_dev *wdev = dev->ieee80211_ptr;
Johannes Berg388ac772010-10-07 13:11:09 +02002020 const u8 *bssid;
Bill Jordane8347eb2010-10-01 13:54:28 -04002021
2022 if (!info->attrs[NL80211_ATTR_MAC])
2023 return -EINVAL;
2024
Johannes Berg43b19952010-10-07 13:10:30 +02002025 if (netif_running(dev))
2026 return -EBUSY;
Bill Jordane8347eb2010-10-01 13:54:28 -04002027
Johannes Berg43b19952010-10-07 13:10:30 +02002028 if (!rdev->ops->set_wds_peer)
2029 return -EOPNOTSUPP;
Bill Jordane8347eb2010-10-01 13:54:28 -04002030
Johannes Berg43b19952010-10-07 13:10:30 +02002031 if (wdev->iftype != NL80211_IFTYPE_WDS)
2032 return -EOPNOTSUPP;
Bill Jordane8347eb2010-10-01 13:54:28 -04002033
2034 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Hila Gonene35e4d22012-06-27 17:19:42 +03002035 return rdev_set_wds_peer(rdev, dev, bssid);
Bill Jordane8347eb2010-10-01 13:54:28 -04002036}
2037
2038
Johannes Berg55682962007-09-20 13:09:35 -04002039static int nl80211_set_wiphy(struct sk_buff *skb, struct genl_info *info)
2040{
2041 struct cfg80211_registered_device *rdev;
Johannes Bergf444de02010-05-05 15:25:02 +02002042 struct net_device *netdev = NULL;
2043 struct wireless_dev *wdev;
Bill Jordana1e567c2010-09-10 11:22:32 -04002044 int result = 0, rem_txq_params = 0;
Jouni Malinen31888482008-10-30 16:59:24 +02002045 struct nlattr *nl_txq_params;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002046 u32 changed;
2047 u8 retry_short = 0, retry_long = 0;
2048 u32 frag_threshold = 0, rts_threshold = 0;
Lukáš Turek81077e82009-12-21 22:50:47 +01002049 u8 coverage_class = 0;
Johannes Berg55682962007-09-20 13:09:35 -04002050
Johannes Berg5fe231e2013-05-08 21:45:15 +02002051 ASSERT_RTNL();
2052
Johannes Bergf444de02010-05-05 15:25:02 +02002053 /*
2054 * Try to find the wiphy and netdev. Normally this
2055 * function shouldn't need the netdev, but this is
2056 * done for backward compatibility -- previously
2057 * setting the channel was done per wiphy, but now
2058 * it is per netdev. Previous userland like hostapd
2059 * also passed a netdev to set_wiphy, so that it is
2060 * possible to let that go to the right netdev!
2061 */
Johannes Berg4bbf4d52009-03-24 09:35:46 +01002062
Johannes Bergf444de02010-05-05 15:25:02 +02002063 if (info->attrs[NL80211_ATTR_IFINDEX]) {
2064 int ifindex = nla_get_u32(info->attrs[NL80211_ATTR_IFINDEX]);
2065
Ying Xue7f2b8562014-01-15 10:23:45 +08002066 netdev = __dev_get_by_index(genl_info_net(info), ifindex);
Johannes Berg5fe231e2013-05-08 21:45:15 +02002067 if (netdev && netdev->ieee80211_ptr)
Zhao, Gangf26cbf42014-04-21 12:53:03 +08002068 rdev = wiphy_to_rdev(netdev->ieee80211_ptr->wiphy);
Johannes Berg5fe231e2013-05-08 21:45:15 +02002069 else
Johannes Bergf444de02010-05-05 15:25:02 +02002070 netdev = NULL;
Johannes Berg4bbf4d52009-03-24 09:35:46 +01002071 }
2072
Johannes Bergf444de02010-05-05 15:25:02 +02002073 if (!netdev) {
Johannes Berg878d9ec2012-06-15 14:18:32 +02002074 rdev = __cfg80211_rdev_from_attrs(genl_info_net(info),
2075 info->attrs);
Johannes Berg5fe231e2013-05-08 21:45:15 +02002076 if (IS_ERR(rdev))
Johannes Berg4c476992010-10-04 21:36:35 +02002077 return PTR_ERR(rdev);
Johannes Bergf444de02010-05-05 15:25:02 +02002078 wdev = NULL;
2079 netdev = NULL;
2080 result = 0;
Johannes Berg71fe96b2012-10-24 10:04:58 +02002081 } else
Johannes Bergf444de02010-05-05 15:25:02 +02002082 wdev = netdev->ieee80211_ptr;
Johannes Bergf444de02010-05-05 15:25:02 +02002083
2084 /*
2085 * end workaround code, by now the rdev is available
2086 * and locked, and wdev may or may not be NULL.
2087 */
Johannes Berg4bbf4d52009-03-24 09:35:46 +01002088
2089 if (info->attrs[NL80211_ATTR_WIPHY_NAME])
Jouni Malinen31888482008-10-30 16:59:24 +02002090 result = cfg80211_dev_rename(
2091 rdev, nla_data(info->attrs[NL80211_ATTR_WIPHY_NAME]));
Johannes Berg4bbf4d52009-03-24 09:35:46 +01002092
Johannes Berg4bbf4d52009-03-24 09:35:46 +01002093 if (result)
Ying Xue7f2b8562014-01-15 10:23:45 +08002094 return result;
Johannes Berg55682962007-09-20 13:09:35 -04002095
Jouni Malinen31888482008-10-30 16:59:24 +02002096 if (info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS]) {
2097 struct ieee80211_txq_params txq_params;
2098 struct nlattr *tb[NL80211_TXQ_ATTR_MAX + 1];
2099
Ying Xue7f2b8562014-01-15 10:23:45 +08002100 if (!rdev->ops->set_txq_params)
2101 return -EOPNOTSUPP;
Jouni Malinen31888482008-10-30 16:59:24 +02002102
Ying Xue7f2b8562014-01-15 10:23:45 +08002103 if (!netdev)
2104 return -EINVAL;
Eliad Pellerf70f01c2011-09-25 20:06:53 +03002105
Johannes Berg133a3ff2011-11-03 14:50:13 +01002106 if (netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
Ying Xue7f2b8562014-01-15 10:23:45 +08002107 netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
2108 return -EINVAL;
Johannes Berg133a3ff2011-11-03 14:50:13 +01002109
Ying Xue7f2b8562014-01-15 10:23:45 +08002110 if (!netif_running(netdev))
2111 return -ENETDOWN;
Johannes Berg2b5f8b02012-04-02 10:51:55 +02002112
Jouni Malinen31888482008-10-30 16:59:24 +02002113 nla_for_each_nested(nl_txq_params,
2114 info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS],
2115 rem_txq_params) {
Johannes Bergae811e22014-01-24 10:17:47 +01002116 result = nla_parse(tb, NL80211_TXQ_ATTR_MAX,
2117 nla_data(nl_txq_params),
2118 nla_len(nl_txq_params),
2119 txq_params_policy);
2120 if (result)
2121 return result;
Jouni Malinen31888482008-10-30 16:59:24 +02002122 result = parse_txq_params(tb, &txq_params);
2123 if (result)
Ying Xue7f2b8562014-01-15 10:23:45 +08002124 return result;
Jouni Malinen31888482008-10-30 16:59:24 +02002125
Hila Gonene35e4d22012-06-27 17:19:42 +03002126 result = rdev_set_txq_params(rdev, netdev,
2127 &txq_params);
Jouni Malinen31888482008-10-30 16:59:24 +02002128 if (result)
Ying Xue7f2b8562014-01-15 10:23:45 +08002129 return result;
Jouni Malinen31888482008-10-30 16:59:24 +02002130 }
2131 }
2132
Jouni Malinen72bdcf32008-11-26 16:15:24 +02002133 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
Jouni Malinene16821b2014-04-28 11:22:08 +03002134 result = __nl80211_set_channel(
2135 rdev,
2136 nl80211_can_set_dev_channel(wdev) ? netdev : NULL,
2137 info);
Jouni Malinen72bdcf32008-11-26 16:15:24 +02002138 if (result)
Ying Xue7f2b8562014-01-15 10:23:45 +08002139 return result;
Jouni Malinen72bdcf32008-11-26 16:15:24 +02002140 }
2141
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03002142 if (info->attrs[NL80211_ATTR_WIPHY_TX_POWER_SETTING]) {
Johannes Bergc8442112012-10-24 10:17:18 +02002143 struct wireless_dev *txp_wdev = wdev;
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03002144 enum nl80211_tx_power_setting type;
2145 int idx, mbm = 0;
2146
Johannes Bergc8442112012-10-24 10:17:18 +02002147 if (!(rdev->wiphy.features & NL80211_FEATURE_VIF_TXPOWER))
2148 txp_wdev = NULL;
2149
Ying Xue7f2b8562014-01-15 10:23:45 +08002150 if (!rdev->ops->set_tx_power)
2151 return -EOPNOTSUPP;
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03002152
2153 idx = NL80211_ATTR_WIPHY_TX_POWER_SETTING;
2154 type = nla_get_u32(info->attrs[idx]);
2155
2156 if (!info->attrs[NL80211_ATTR_WIPHY_TX_POWER_LEVEL] &&
Ying Xue7f2b8562014-01-15 10:23:45 +08002157 (type != NL80211_TX_POWER_AUTOMATIC))
2158 return -EINVAL;
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03002159
2160 if (type != NL80211_TX_POWER_AUTOMATIC) {
2161 idx = NL80211_ATTR_WIPHY_TX_POWER_LEVEL;
2162 mbm = nla_get_u32(info->attrs[idx]);
2163 }
2164
Johannes Bergc8442112012-10-24 10:17:18 +02002165 result = rdev_set_tx_power(rdev, txp_wdev, type, mbm);
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03002166 if (result)
Ying Xue7f2b8562014-01-15 10:23:45 +08002167 return result;
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03002168 }
2169
Bruno Randolfafe0cbf2010-11-10 12:50:50 +09002170 if (info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX] &&
2171 info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]) {
2172 u32 tx_ant, rx_ant;
Bruno Randolf7f531e02010-12-16 11:30:22 +09002173 if ((!rdev->wiphy.available_antennas_tx &&
2174 !rdev->wiphy.available_antennas_rx) ||
Ying Xue7f2b8562014-01-15 10:23:45 +08002175 !rdev->ops->set_antenna)
2176 return -EOPNOTSUPP;
Bruno Randolfafe0cbf2010-11-10 12:50:50 +09002177
2178 tx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX]);
2179 rx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]);
2180
Bruno Randolfa7ffac92010-12-08 13:59:24 +09002181 /* reject antenna configurations which don't match the
Bruno Randolf7f531e02010-12-16 11:30:22 +09002182 * available antenna masks, except for the "all" mask */
2183 if ((~tx_ant && (tx_ant & ~rdev->wiphy.available_antennas_tx)) ||
Ying Xue7f2b8562014-01-15 10:23:45 +08002184 (~rx_ant && (rx_ant & ~rdev->wiphy.available_antennas_rx)))
2185 return -EINVAL;
Bruno Randolfa7ffac92010-12-08 13:59:24 +09002186
Bruno Randolf7f531e02010-12-16 11:30:22 +09002187 tx_ant = tx_ant & rdev->wiphy.available_antennas_tx;
2188 rx_ant = rx_ant & rdev->wiphy.available_antennas_rx;
Bruno Randolfa7ffac92010-12-08 13:59:24 +09002189
Hila Gonene35e4d22012-06-27 17:19:42 +03002190 result = rdev_set_antenna(rdev, tx_ant, rx_ant);
Bruno Randolfafe0cbf2010-11-10 12:50:50 +09002191 if (result)
Ying Xue7f2b8562014-01-15 10:23:45 +08002192 return result;
Bruno Randolfafe0cbf2010-11-10 12:50:50 +09002193 }
2194
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002195 changed = 0;
2196
2197 if (info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]) {
2198 retry_short = nla_get_u8(
2199 info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]);
Ying Xue7f2b8562014-01-15 10:23:45 +08002200 if (retry_short == 0)
2201 return -EINVAL;
2202
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002203 changed |= WIPHY_PARAM_RETRY_SHORT;
2204 }
2205
2206 if (info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]) {
2207 retry_long = nla_get_u8(
2208 info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]);
Ying Xue7f2b8562014-01-15 10:23:45 +08002209 if (retry_long == 0)
2210 return -EINVAL;
2211
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002212 changed |= WIPHY_PARAM_RETRY_LONG;
2213 }
2214
2215 if (info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]) {
2216 frag_threshold = nla_get_u32(
2217 info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]);
Ying Xue7f2b8562014-01-15 10:23:45 +08002218 if (frag_threshold < 256)
2219 return -EINVAL;
2220
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002221 if (frag_threshold != (u32) -1) {
2222 /*
2223 * Fragments (apart from the last one) are required to
2224 * have even length. Make the fragmentation code
2225 * simpler by stripping LSB should someone try to use
2226 * odd threshold value.
2227 */
2228 frag_threshold &= ~0x1;
2229 }
2230 changed |= WIPHY_PARAM_FRAG_THRESHOLD;
2231 }
2232
2233 if (info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]) {
2234 rts_threshold = nla_get_u32(
2235 info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]);
2236 changed |= WIPHY_PARAM_RTS_THRESHOLD;
2237 }
2238
Lukáš Turek81077e82009-12-21 22:50:47 +01002239 if (info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]) {
2240 coverage_class = nla_get_u8(
2241 info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]);
2242 changed |= WIPHY_PARAM_COVERAGE_CLASS;
2243 }
2244
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002245 if (changed) {
2246 u8 old_retry_short, old_retry_long;
2247 u32 old_frag_threshold, old_rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01002248 u8 old_coverage_class;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002249
Ying Xue7f2b8562014-01-15 10:23:45 +08002250 if (!rdev->ops->set_wiphy_params)
2251 return -EOPNOTSUPP;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002252
2253 old_retry_short = rdev->wiphy.retry_short;
2254 old_retry_long = rdev->wiphy.retry_long;
2255 old_frag_threshold = rdev->wiphy.frag_threshold;
2256 old_rts_threshold = rdev->wiphy.rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01002257 old_coverage_class = rdev->wiphy.coverage_class;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002258
2259 if (changed & WIPHY_PARAM_RETRY_SHORT)
2260 rdev->wiphy.retry_short = retry_short;
2261 if (changed & WIPHY_PARAM_RETRY_LONG)
2262 rdev->wiphy.retry_long = retry_long;
2263 if (changed & WIPHY_PARAM_FRAG_THRESHOLD)
2264 rdev->wiphy.frag_threshold = frag_threshold;
2265 if (changed & WIPHY_PARAM_RTS_THRESHOLD)
2266 rdev->wiphy.rts_threshold = rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01002267 if (changed & WIPHY_PARAM_COVERAGE_CLASS)
2268 rdev->wiphy.coverage_class = coverage_class;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002269
Hila Gonene35e4d22012-06-27 17:19:42 +03002270 result = rdev_set_wiphy_params(rdev, changed);
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002271 if (result) {
2272 rdev->wiphy.retry_short = old_retry_short;
2273 rdev->wiphy.retry_long = old_retry_long;
2274 rdev->wiphy.frag_threshold = old_frag_threshold;
2275 rdev->wiphy.rts_threshold = old_rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01002276 rdev->wiphy.coverage_class = old_coverage_class;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002277 }
2278 }
Ying Xue7f2b8562014-01-15 10:23:45 +08002279 return 0;
Johannes Berg55682962007-09-20 13:09:35 -04002280}
2281
Johannes Berg71bbc992012-06-15 15:30:18 +02002282static inline u64 wdev_id(struct wireless_dev *wdev)
2283{
2284 return (u64)wdev->identifier |
Zhao, Gangf26cbf42014-04-21 12:53:03 +08002285 ((u64)wiphy_to_rdev(wdev->wiphy)->wiphy_idx << 32);
Johannes Berg71bbc992012-06-15 15:30:18 +02002286}
Johannes Berg55682962007-09-20 13:09:35 -04002287
Johannes Berg683b6d32012-11-08 21:25:48 +01002288static int nl80211_send_chandef(struct sk_buff *msg,
Janusz Dziedzicd2859df2013-11-06 13:55:51 +01002289 const struct cfg80211_chan_def *chandef)
Johannes Berg683b6d32012-11-08 21:25:48 +01002290{
Johannes Berg9f5e8f62012-11-22 16:59:45 +01002291 WARN_ON(!cfg80211_chandef_valid(chandef));
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002292
Johannes Berg683b6d32012-11-08 21:25:48 +01002293 if (nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ,
2294 chandef->chan->center_freq))
2295 return -ENOBUFS;
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002296 switch (chandef->width) {
2297 case NL80211_CHAN_WIDTH_20_NOHT:
2298 case NL80211_CHAN_WIDTH_20:
2299 case NL80211_CHAN_WIDTH_40:
2300 if (nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE,
2301 cfg80211_get_chandef_type(chandef)))
2302 return -ENOBUFS;
2303 break;
2304 default:
2305 break;
2306 }
2307 if (nla_put_u32(msg, NL80211_ATTR_CHANNEL_WIDTH, chandef->width))
2308 return -ENOBUFS;
2309 if (nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ1, chandef->center_freq1))
2310 return -ENOBUFS;
2311 if (chandef->center_freq2 &&
2312 nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ2, chandef->center_freq2))
Johannes Berg683b6d32012-11-08 21:25:48 +01002313 return -ENOBUFS;
2314 return 0;
2315}
2316
Eric W. Biederman15e47302012-09-07 20:12:54 +00002317static int nl80211_send_iface(struct sk_buff *msg, u32 portid, u32 seq, int flags,
Johannes Bergd7264052009-04-19 16:23:20 +02002318 struct cfg80211_registered_device *rdev,
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002319 struct wireless_dev *wdev)
Johannes Berg55682962007-09-20 13:09:35 -04002320{
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002321 struct net_device *dev = wdev->netdev;
Johannes Berg55682962007-09-20 13:09:35 -04002322 void *hdr;
2323
Eric W. Biederman15e47302012-09-07 20:12:54 +00002324 hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_INTERFACE);
Johannes Berg55682962007-09-20 13:09:35 -04002325 if (!hdr)
2326 return -1;
2327
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002328 if (dev &&
2329 (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
Johannes Berg98104fde2012-06-16 00:19:54 +02002330 nla_put_string(msg, NL80211_ATTR_IFNAME, dev->name)))
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002331 goto nla_put_failure;
2332
2333 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
2334 nla_put_u32(msg, NL80211_ATTR_IFTYPE, wdev->iftype) ||
Johannes Berg71bbc992012-06-15 15:30:18 +02002335 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) ||
Johannes Berg98104fde2012-06-16 00:19:54 +02002336 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, wdev_address(wdev)) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04002337 nla_put_u32(msg, NL80211_ATTR_GENERATION,
2338 rdev->devlist_generation ^
2339 (cfg80211_rdev_list_generation << 2)))
2340 goto nla_put_failure;
Johannes Bergf5ea9122009-08-07 16:17:38 +02002341
Johannes Berg5b7ccaf2012-07-12 19:45:08 +02002342 if (rdev->ops->get_channel) {
Johannes Berg683b6d32012-11-08 21:25:48 +01002343 int ret;
2344 struct cfg80211_chan_def chandef;
Johannes Berg5b7ccaf2012-07-12 19:45:08 +02002345
Johannes Berg683b6d32012-11-08 21:25:48 +01002346 ret = rdev_get_channel(rdev, wdev, &chandef);
2347 if (ret == 0) {
2348 if (nl80211_send_chandef(msg, &chandef))
2349 goto nla_put_failure;
2350 }
Pontus Fuchsd91df0e2012-04-03 16:39:58 +02002351 }
2352
Antonio Quartullib84e7a02012-11-07 12:52:20 +01002353 if (wdev->ssid_len) {
2354 if (nla_put(msg, NL80211_ATTR_SSID, wdev->ssid_len, wdev->ssid))
2355 goto nla_put_failure;
2356 }
2357
Johannes Berg55682962007-09-20 13:09:35 -04002358 return genlmsg_end(msg, hdr);
2359
2360 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07002361 genlmsg_cancel(msg, hdr);
2362 return -EMSGSIZE;
Johannes Berg55682962007-09-20 13:09:35 -04002363}
2364
2365static int nl80211_dump_interface(struct sk_buff *skb, struct netlink_callback *cb)
2366{
2367 int wp_idx = 0;
2368 int if_idx = 0;
2369 int wp_start = cb->args[0];
2370 int if_start = cb->args[1];
Johannes Bergf5ea9122009-08-07 16:17:38 +02002371 struct cfg80211_registered_device *rdev;
Johannes Berg55682962007-09-20 13:09:35 -04002372 struct wireless_dev *wdev;
2373
Johannes Berg5fe231e2013-05-08 21:45:15 +02002374 rtnl_lock();
Johannes Bergf5ea9122009-08-07 16:17:38 +02002375 list_for_each_entry(rdev, &cfg80211_rdev_list, list) {
2376 if (!net_eq(wiphy_net(&rdev->wiphy), sock_net(skb->sk)))
Johannes Berg463d0182009-07-14 00:33:35 +02002377 continue;
Johannes Bergbba95fe2008-07-29 13:22:51 +02002378 if (wp_idx < wp_start) {
2379 wp_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04002380 continue;
Johannes Bergbba95fe2008-07-29 13:22:51 +02002381 }
Johannes Berg55682962007-09-20 13:09:35 -04002382 if_idx = 0;
2383
Johannes Berg89a54e42012-06-15 14:33:17 +02002384 list_for_each_entry(wdev, &rdev->wdev_list, list) {
Johannes Bergbba95fe2008-07-29 13:22:51 +02002385 if (if_idx < if_start) {
2386 if_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04002387 continue;
Johannes Bergbba95fe2008-07-29 13:22:51 +02002388 }
Eric W. Biederman15e47302012-09-07 20:12:54 +00002389 if (nl80211_send_iface(skb, NETLINK_CB(cb->skb).portid,
Johannes Berg55682962007-09-20 13:09:35 -04002390 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002391 rdev, wdev) < 0) {
Johannes Bergbba95fe2008-07-29 13:22:51 +02002392 goto out;
2393 }
2394 if_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04002395 }
Johannes Bergbba95fe2008-07-29 13:22:51 +02002396
2397 wp_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04002398 }
Johannes Bergbba95fe2008-07-29 13:22:51 +02002399 out:
Johannes Berg5fe231e2013-05-08 21:45:15 +02002400 rtnl_unlock();
Johannes Berg55682962007-09-20 13:09:35 -04002401
2402 cb->args[0] = wp_idx;
2403 cb->args[1] = if_idx;
2404
2405 return skb->len;
2406}
2407
2408static int nl80211_get_interface(struct sk_buff *skb, struct genl_info *info)
2409{
2410 struct sk_buff *msg;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002411 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002412 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg55682962007-09-20 13:09:35 -04002413
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07002414 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -04002415 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02002416 return -ENOMEM;
Johannes Berg55682962007-09-20 13:09:35 -04002417
Eric W. Biederman15e47302012-09-07 20:12:54 +00002418 if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002419 rdev, wdev) < 0) {
Johannes Berg4c476992010-10-04 21:36:35 +02002420 nlmsg_free(msg);
2421 return -ENOBUFS;
2422 }
Johannes Berg55682962007-09-20 13:09:35 -04002423
Johannes Berg134e6372009-07-10 09:51:34 +00002424 return genlmsg_reply(msg, info);
Johannes Berg55682962007-09-20 13:09:35 -04002425}
2426
Michael Wu66f7ac52008-01-31 19:48:22 +01002427static const struct nla_policy mntr_flags_policy[NL80211_MNTR_FLAG_MAX + 1] = {
2428 [NL80211_MNTR_FLAG_FCSFAIL] = { .type = NLA_FLAG },
2429 [NL80211_MNTR_FLAG_PLCPFAIL] = { .type = NLA_FLAG },
2430 [NL80211_MNTR_FLAG_CONTROL] = { .type = NLA_FLAG },
2431 [NL80211_MNTR_FLAG_OTHER_BSS] = { .type = NLA_FLAG },
2432 [NL80211_MNTR_FLAG_COOK_FRAMES] = { .type = NLA_FLAG },
Felix Fietkaue057d3c2013-05-28 13:01:52 +02002433 [NL80211_MNTR_FLAG_ACTIVE] = { .type = NLA_FLAG },
Michael Wu66f7ac52008-01-31 19:48:22 +01002434};
2435
2436static int parse_monitor_flags(struct nlattr *nla, u32 *mntrflags)
2437{
2438 struct nlattr *flags[NL80211_MNTR_FLAG_MAX + 1];
2439 int flag;
2440
2441 *mntrflags = 0;
2442
2443 if (!nla)
2444 return -EINVAL;
2445
2446 if (nla_parse_nested(flags, NL80211_MNTR_FLAG_MAX,
2447 nla, mntr_flags_policy))
2448 return -EINVAL;
2449
2450 for (flag = 1; flag <= NL80211_MNTR_FLAG_MAX; flag++)
2451 if (flags[flag])
2452 *mntrflags |= (1<<flag);
2453
2454 return 0;
2455}
2456
Johannes Berg9bc383d2009-11-19 11:55:19 +01002457static int nl80211_valid_4addr(struct cfg80211_registered_device *rdev,
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002458 struct net_device *netdev, u8 use_4addr,
2459 enum nl80211_iftype iftype)
Johannes Berg9bc383d2009-11-19 11:55:19 +01002460{
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002461 if (!use_4addr) {
Jiri Pirkof350a0a82010-06-15 06:50:45 +00002462 if (netdev && (netdev->priv_flags & IFF_BRIDGE_PORT))
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002463 return -EBUSY;
Johannes Berg9bc383d2009-11-19 11:55:19 +01002464 return 0;
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002465 }
Johannes Berg9bc383d2009-11-19 11:55:19 +01002466
2467 switch (iftype) {
2468 case NL80211_IFTYPE_AP_VLAN:
2469 if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_AP)
2470 return 0;
2471 break;
2472 case NL80211_IFTYPE_STATION:
2473 if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_STATION)
2474 return 0;
2475 break;
2476 default:
2477 break;
2478 }
2479
2480 return -EOPNOTSUPP;
2481}
2482
Johannes Berg55682962007-09-20 13:09:35 -04002483static int nl80211_set_interface(struct sk_buff *skb, struct genl_info *info)
2484{
Johannes Berg4c476992010-10-04 21:36:35 +02002485 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002486 struct vif_params params;
Johannes Berge36d56b2009-06-09 21:04:43 +02002487 int err;
Johannes Berg04a773a2009-04-19 21:24:32 +02002488 enum nl80211_iftype otype, ntype;
Johannes Berg4c476992010-10-04 21:36:35 +02002489 struct net_device *dev = info->user_ptr[1];
Johannes Berg92ffe052008-09-16 20:39:36 +02002490 u32 _flags, *flags = NULL;
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002491 bool change = false;
Johannes Berg55682962007-09-20 13:09:35 -04002492
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002493 memset(&params, 0, sizeof(params));
2494
Johannes Berg04a773a2009-04-19 21:24:32 +02002495 otype = ntype = dev->ieee80211_ptr->iftype;
Johannes Berg55682962007-09-20 13:09:35 -04002496
Johannes Berg723b0382008-09-16 20:22:09 +02002497 if (info->attrs[NL80211_ATTR_IFTYPE]) {
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002498 ntype = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]);
Johannes Berg04a773a2009-04-19 21:24:32 +02002499 if (otype != ntype)
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002500 change = true;
Johannes Berg4c476992010-10-04 21:36:35 +02002501 if (ntype > NL80211_IFTYPE_MAX)
2502 return -EINVAL;
Johannes Berg723b0382008-09-16 20:22:09 +02002503 }
2504
Johannes Berg92ffe052008-09-16 20:39:36 +02002505 if (info->attrs[NL80211_ATTR_MESH_ID]) {
Johannes Berg29cbe682010-12-03 09:20:44 +01002506 struct wireless_dev *wdev = dev->ieee80211_ptr;
2507
Johannes Berg4c476992010-10-04 21:36:35 +02002508 if (ntype != NL80211_IFTYPE_MESH_POINT)
2509 return -EINVAL;
Johannes Berg29cbe682010-12-03 09:20:44 +01002510 if (netif_running(dev))
2511 return -EBUSY;
2512
2513 wdev_lock(wdev);
2514 BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN !=
2515 IEEE80211_MAX_MESH_ID_LEN);
2516 wdev->mesh_id_up_len =
2517 nla_len(info->attrs[NL80211_ATTR_MESH_ID]);
2518 memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]),
2519 wdev->mesh_id_up_len);
2520 wdev_unlock(wdev);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002521 }
2522
Felix Fietkau8b787642009-11-10 18:53:10 +01002523 if (info->attrs[NL80211_ATTR_4ADDR]) {
2524 params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]);
2525 change = true;
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002526 err = nl80211_valid_4addr(rdev, dev, params.use_4addr, ntype);
Johannes Berg9bc383d2009-11-19 11:55:19 +01002527 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02002528 return err;
Felix Fietkau8b787642009-11-10 18:53:10 +01002529 } else {
2530 params.use_4addr = -1;
2531 }
2532
Johannes Berg92ffe052008-09-16 20:39:36 +02002533 if (info->attrs[NL80211_ATTR_MNTR_FLAGS]) {
Johannes Berg4c476992010-10-04 21:36:35 +02002534 if (ntype != NL80211_IFTYPE_MONITOR)
2535 return -EINVAL;
Johannes Berg92ffe052008-09-16 20:39:36 +02002536 err = parse_monitor_flags(info->attrs[NL80211_ATTR_MNTR_FLAGS],
2537 &_flags);
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002538 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02002539 return err;
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002540
2541 flags = &_flags;
2542 change = true;
Johannes Berg92ffe052008-09-16 20:39:36 +02002543 }
Johannes Berg3b858752009-03-12 09:55:09 +01002544
Luciano Coelho18003292013-08-29 13:26:57 +03002545 if (flags && (*flags & MONITOR_FLAG_ACTIVE) &&
Felix Fietkaue057d3c2013-05-28 13:01:52 +02002546 !(rdev->wiphy.features & NL80211_FEATURE_ACTIVE_MONITOR))
2547 return -EOPNOTSUPP;
2548
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002549 if (change)
Johannes Berg3d54d252009-08-21 14:51:05 +02002550 err = cfg80211_change_iface(rdev, dev, ntype, flags, &params);
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002551 else
2552 err = 0;
Johannes Berg60719ff2008-09-16 14:55:09 +02002553
Johannes Berg9bc383d2009-11-19 11:55:19 +01002554 if (!err && params.use_4addr != -1)
2555 dev->ieee80211_ptr->use_4addr = params.use_4addr;
2556
Johannes Berg55682962007-09-20 13:09:35 -04002557 return err;
2558}
2559
2560static int nl80211_new_interface(struct sk_buff *skb, struct genl_info *info)
2561{
Johannes Berg4c476992010-10-04 21:36:35 +02002562 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002563 struct vif_params params;
Johannes Berg84efbb82012-06-16 00:00:26 +02002564 struct wireless_dev *wdev;
Johannes Berg1c90f9d2012-06-16 00:05:37 +02002565 struct sk_buff *msg;
Johannes Berg55682962007-09-20 13:09:35 -04002566 int err;
2567 enum nl80211_iftype type = NL80211_IFTYPE_UNSPECIFIED;
Michael Wu66f7ac52008-01-31 19:48:22 +01002568 u32 flags;
Johannes Berg55682962007-09-20 13:09:35 -04002569
Johannes Berg78f22b62014-03-24 17:57:27 +01002570 /* to avoid failing a new interface creation due to pending removal */
2571 cfg80211_destroy_ifaces(rdev);
2572
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002573 memset(&params, 0, sizeof(params));
2574
Johannes Berg55682962007-09-20 13:09:35 -04002575 if (!info->attrs[NL80211_ATTR_IFNAME])
2576 return -EINVAL;
2577
2578 if (info->attrs[NL80211_ATTR_IFTYPE]) {
2579 type = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]);
2580 if (type > NL80211_IFTYPE_MAX)
2581 return -EINVAL;
2582 }
2583
Johannes Berg79c97e92009-07-07 03:56:12 +02002584 if (!rdev->ops->add_virtual_intf ||
Johannes Berg4c476992010-10-04 21:36:35 +02002585 !(rdev->wiphy.interface_modes & (1 << type)))
2586 return -EOPNOTSUPP;
Johannes Berg55682962007-09-20 13:09:35 -04002587
Arend van Spriel1c18f142013-01-08 10:17:27 +01002588 if (type == NL80211_IFTYPE_P2P_DEVICE && info->attrs[NL80211_ATTR_MAC]) {
2589 nla_memcpy(params.macaddr, info->attrs[NL80211_ATTR_MAC],
2590 ETH_ALEN);
2591 if (!is_valid_ether_addr(params.macaddr))
2592 return -EADDRNOTAVAIL;
2593 }
2594
Johannes Berg9bc383d2009-11-19 11:55:19 +01002595 if (info->attrs[NL80211_ATTR_4ADDR]) {
Felix Fietkau8b787642009-11-10 18:53:10 +01002596 params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]);
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002597 err = nl80211_valid_4addr(rdev, NULL, params.use_4addr, type);
Johannes Berg9bc383d2009-11-19 11:55:19 +01002598 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02002599 return err;
Johannes Berg9bc383d2009-11-19 11:55:19 +01002600 }
Felix Fietkau8b787642009-11-10 18:53:10 +01002601
Johannes Berg1c90f9d2012-06-16 00:05:37 +02002602 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
2603 if (!msg)
2604 return -ENOMEM;
2605
Michael Wu66f7ac52008-01-31 19:48:22 +01002606 err = parse_monitor_flags(type == NL80211_IFTYPE_MONITOR ?
2607 info->attrs[NL80211_ATTR_MNTR_FLAGS] : NULL,
2608 &flags);
Felix Fietkaue057d3c2013-05-28 13:01:52 +02002609
Luciano Coelho18003292013-08-29 13:26:57 +03002610 if (!err && (flags & MONITOR_FLAG_ACTIVE) &&
Felix Fietkaue057d3c2013-05-28 13:01:52 +02002611 !(rdev->wiphy.features & NL80211_FEATURE_ACTIVE_MONITOR))
2612 return -EOPNOTSUPP;
2613
Hila Gonene35e4d22012-06-27 17:19:42 +03002614 wdev = rdev_add_virtual_intf(rdev,
2615 nla_data(info->attrs[NL80211_ATTR_IFNAME]),
2616 type, err ? NULL : &flags, &params);
Johannes Berg1c90f9d2012-06-16 00:05:37 +02002617 if (IS_ERR(wdev)) {
2618 nlmsg_free(msg);
Johannes Berg84efbb82012-06-16 00:00:26 +02002619 return PTR_ERR(wdev);
Johannes Berg1c90f9d2012-06-16 00:05:37 +02002620 }
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002621
Johannes Berg78f22b62014-03-24 17:57:27 +01002622 if (info->attrs[NL80211_ATTR_IFACE_SOCKET_OWNER])
2623 wdev->owner_nlportid = info->snd_portid;
2624
Johannes Berg98104fde2012-06-16 00:19:54 +02002625 switch (type) {
2626 case NL80211_IFTYPE_MESH_POINT:
2627 if (!info->attrs[NL80211_ATTR_MESH_ID])
2628 break;
Johannes Berg29cbe682010-12-03 09:20:44 +01002629 wdev_lock(wdev);
2630 BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN !=
2631 IEEE80211_MAX_MESH_ID_LEN);
2632 wdev->mesh_id_up_len =
2633 nla_len(info->attrs[NL80211_ATTR_MESH_ID]);
2634 memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]),
2635 wdev->mesh_id_up_len);
2636 wdev_unlock(wdev);
Johannes Berg98104fde2012-06-16 00:19:54 +02002637 break;
2638 case NL80211_IFTYPE_P2P_DEVICE:
2639 /*
2640 * P2P Device doesn't have a netdev, so doesn't go
2641 * through the netdev notifier and must be added here
2642 */
2643 mutex_init(&wdev->mtx);
2644 INIT_LIST_HEAD(&wdev->event_list);
2645 spin_lock_init(&wdev->event_lock);
2646 INIT_LIST_HEAD(&wdev->mgmt_registrations);
2647 spin_lock_init(&wdev->mgmt_registrations_lock);
2648
Johannes Berg98104fde2012-06-16 00:19:54 +02002649 wdev->identifier = ++rdev->wdev_id;
2650 list_add_rcu(&wdev->list, &rdev->wdev_list);
2651 rdev->devlist_generation++;
Johannes Berg98104fde2012-06-16 00:19:54 +02002652 break;
2653 default:
2654 break;
Johannes Berg29cbe682010-12-03 09:20:44 +01002655 }
2656
Eric W. Biederman15e47302012-09-07 20:12:54 +00002657 if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berg1c90f9d2012-06-16 00:05:37 +02002658 rdev, wdev) < 0) {
2659 nlmsg_free(msg);
2660 return -ENOBUFS;
2661 }
2662
2663 return genlmsg_reply(msg, info);
Johannes Berg55682962007-09-20 13:09:35 -04002664}
2665
2666static int nl80211_del_interface(struct sk_buff *skb, struct genl_info *info)
2667{
Johannes Berg4c476992010-10-04 21:36:35 +02002668 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg84efbb82012-06-16 00:00:26 +02002669 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg55682962007-09-20 13:09:35 -04002670
Johannes Berg4c476992010-10-04 21:36:35 +02002671 if (!rdev->ops->del_virtual_intf)
2672 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01002673
Johannes Berg84efbb82012-06-16 00:00:26 +02002674 /*
2675 * If we remove a wireless device without a netdev then clear
2676 * user_ptr[1] so that nl80211_post_doit won't dereference it
2677 * to check if it needs to do dev_put(). Otherwise it crashes
2678 * since the wdev has been freed, unlike with a netdev where
2679 * we need the dev_put() for the netdev to really be freed.
2680 */
2681 if (!wdev->netdev)
2682 info->user_ptr[1] = NULL;
2683
Hila Gonene35e4d22012-06-27 17:19:42 +03002684 return rdev_del_virtual_intf(rdev, wdev);
Johannes Berg55682962007-09-20 13:09:35 -04002685}
2686
Simon Wunderlich1d9d9212011-11-18 14:20:43 +01002687static int nl80211_set_noack_map(struct sk_buff *skb, struct genl_info *info)
2688{
2689 struct cfg80211_registered_device *rdev = info->user_ptr[0];
2690 struct net_device *dev = info->user_ptr[1];
2691 u16 noack_map;
2692
2693 if (!info->attrs[NL80211_ATTR_NOACK_MAP])
2694 return -EINVAL;
2695
2696 if (!rdev->ops->set_noack_map)
2697 return -EOPNOTSUPP;
2698
2699 noack_map = nla_get_u16(info->attrs[NL80211_ATTR_NOACK_MAP]);
2700
Hila Gonene35e4d22012-06-27 17:19:42 +03002701 return rdev_set_noack_map(rdev, dev, noack_map);
Simon Wunderlich1d9d9212011-11-18 14:20:43 +01002702}
2703
Johannes Berg41ade002007-12-19 02:03:29 +01002704struct get_key_cookie {
2705 struct sk_buff *msg;
2706 int error;
Johannes Bergb9454e82009-07-08 13:29:08 +02002707 int idx;
Johannes Berg41ade002007-12-19 02:03:29 +01002708};
2709
2710static void get_key_callback(void *c, struct key_params *params)
2711{
Johannes Bergb9454e82009-07-08 13:29:08 +02002712 struct nlattr *key;
Johannes Berg41ade002007-12-19 02:03:29 +01002713 struct get_key_cookie *cookie = c;
2714
David S. Miller9360ffd2012-03-29 04:41:26 -04002715 if ((params->key &&
2716 nla_put(cookie->msg, NL80211_ATTR_KEY_DATA,
2717 params->key_len, params->key)) ||
2718 (params->seq &&
2719 nla_put(cookie->msg, NL80211_ATTR_KEY_SEQ,
2720 params->seq_len, params->seq)) ||
2721 (params->cipher &&
2722 nla_put_u32(cookie->msg, NL80211_ATTR_KEY_CIPHER,
2723 params->cipher)))
2724 goto nla_put_failure;
Johannes Berg41ade002007-12-19 02:03:29 +01002725
Johannes Bergb9454e82009-07-08 13:29:08 +02002726 key = nla_nest_start(cookie->msg, NL80211_ATTR_KEY);
2727 if (!key)
2728 goto nla_put_failure;
2729
David S. Miller9360ffd2012-03-29 04:41:26 -04002730 if ((params->key &&
2731 nla_put(cookie->msg, NL80211_KEY_DATA,
2732 params->key_len, params->key)) ||
2733 (params->seq &&
2734 nla_put(cookie->msg, NL80211_KEY_SEQ,
2735 params->seq_len, params->seq)) ||
2736 (params->cipher &&
2737 nla_put_u32(cookie->msg, NL80211_KEY_CIPHER,
2738 params->cipher)))
2739 goto nla_put_failure;
Johannes Bergb9454e82009-07-08 13:29:08 +02002740
David S. Miller9360ffd2012-03-29 04:41:26 -04002741 if (nla_put_u8(cookie->msg, NL80211_ATTR_KEY_IDX, cookie->idx))
2742 goto nla_put_failure;
Johannes Bergb9454e82009-07-08 13:29:08 +02002743
2744 nla_nest_end(cookie->msg, key);
2745
Johannes Berg41ade002007-12-19 02:03:29 +01002746 return;
2747 nla_put_failure:
2748 cookie->error = 1;
2749}
2750
2751static int nl80211_get_key(struct sk_buff *skb, struct genl_info *info)
2752{
Johannes Berg4c476992010-10-04 21:36:35 +02002753 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg41ade002007-12-19 02:03:29 +01002754 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02002755 struct net_device *dev = info->user_ptr[1];
Johannes Berg41ade002007-12-19 02:03:29 +01002756 u8 key_idx = 0;
Johannes Berge31b8212010-10-05 19:39:30 +02002757 const u8 *mac_addr = NULL;
2758 bool pairwise;
Johannes Berg41ade002007-12-19 02:03:29 +01002759 struct get_key_cookie cookie = {
2760 .error = 0,
2761 };
2762 void *hdr;
2763 struct sk_buff *msg;
2764
2765 if (info->attrs[NL80211_ATTR_KEY_IDX])
2766 key_idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]);
2767
Jouni Malinen3cfcf6ac2009-01-08 13:32:02 +02002768 if (key_idx > 5)
Johannes Berg41ade002007-12-19 02:03:29 +01002769 return -EINVAL;
2770
2771 if (info->attrs[NL80211_ATTR_MAC])
2772 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
2773
Johannes Berge31b8212010-10-05 19:39:30 +02002774 pairwise = !!mac_addr;
2775 if (info->attrs[NL80211_ATTR_KEY_TYPE]) {
2776 u32 kt = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]);
2777 if (kt >= NUM_NL80211_KEYTYPES)
2778 return -EINVAL;
2779 if (kt != NL80211_KEYTYPE_GROUP &&
2780 kt != NL80211_KEYTYPE_PAIRWISE)
2781 return -EINVAL;
2782 pairwise = kt == NL80211_KEYTYPE_PAIRWISE;
2783 }
2784
Johannes Berg4c476992010-10-04 21:36:35 +02002785 if (!rdev->ops->get_key)
2786 return -EOPNOTSUPP;
Johannes Berg41ade002007-12-19 02:03:29 +01002787
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07002788 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02002789 if (!msg)
2790 return -ENOMEM;
Johannes Berg41ade002007-12-19 02:03:29 +01002791
Eric W. Biederman15e47302012-09-07 20:12:54 +00002792 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berg41ade002007-12-19 02:03:29 +01002793 NL80211_CMD_NEW_KEY);
Dan Carpentercb35fba2013-08-14 14:50:01 +03002794 if (!hdr)
Johannes Berg9fe271a2013-10-25 11:15:12 +02002795 goto nla_put_failure;
Johannes Berg41ade002007-12-19 02:03:29 +01002796
2797 cookie.msg = msg;
Johannes Bergb9454e82009-07-08 13:29:08 +02002798 cookie.idx = key_idx;
Johannes Berg41ade002007-12-19 02:03:29 +01002799
David S. Miller9360ffd2012-03-29 04:41:26 -04002800 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
2801 nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_idx))
2802 goto nla_put_failure;
2803 if (mac_addr &&
2804 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr))
2805 goto nla_put_failure;
Johannes Berg41ade002007-12-19 02:03:29 +01002806
Johannes Berge31b8212010-10-05 19:39:30 +02002807 if (pairwise && mac_addr &&
2808 !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN))
2809 return -ENOENT;
2810
Hila Gonene35e4d22012-06-27 17:19:42 +03002811 err = rdev_get_key(rdev, dev, key_idx, pairwise, mac_addr, &cookie,
2812 get_key_callback);
Johannes Berg41ade002007-12-19 02:03:29 +01002813
2814 if (err)
Niko Jokinen6c95e2a2009-07-15 11:00:53 +03002815 goto free_msg;
Johannes Berg41ade002007-12-19 02:03:29 +01002816
2817 if (cookie.error)
2818 goto nla_put_failure;
2819
2820 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02002821 return genlmsg_reply(msg, info);
Johannes Berg41ade002007-12-19 02:03:29 +01002822
2823 nla_put_failure:
2824 err = -ENOBUFS;
Niko Jokinen6c95e2a2009-07-15 11:00:53 +03002825 free_msg:
Johannes Berg41ade002007-12-19 02:03:29 +01002826 nlmsg_free(msg);
Johannes Berg41ade002007-12-19 02:03:29 +01002827 return err;
2828}
2829
2830static int nl80211_set_key(struct sk_buff *skb, struct genl_info *info)
2831{
Johannes Berg4c476992010-10-04 21:36:35 +02002832 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Bergb9454e82009-07-08 13:29:08 +02002833 struct key_parse key;
Johannes Berg41ade002007-12-19 02:03:29 +01002834 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02002835 struct net_device *dev = info->user_ptr[1];
Johannes Berg41ade002007-12-19 02:03:29 +01002836
Johannes Bergb9454e82009-07-08 13:29:08 +02002837 err = nl80211_parse_key(info, &key);
2838 if (err)
2839 return err;
2840
2841 if (key.idx < 0)
Johannes Berg41ade002007-12-19 02:03:29 +01002842 return -EINVAL;
2843
Johannes Bergb9454e82009-07-08 13:29:08 +02002844 /* only support setting default key */
2845 if (!key.def && !key.defmgmt)
Johannes Berg41ade002007-12-19 02:03:29 +01002846 return -EINVAL;
2847
Johannes Bergfffd0932009-07-08 14:22:54 +02002848 wdev_lock(dev->ieee80211_ptr);
Johannes Bergdbd2fd62010-12-09 19:58:59 +01002849
2850 if (key.def) {
2851 if (!rdev->ops->set_default_key) {
2852 err = -EOPNOTSUPP;
2853 goto out;
2854 }
2855
2856 err = nl80211_key_allowed(dev->ieee80211_ptr);
2857 if (err)
2858 goto out;
2859
Hila Gonene35e4d22012-06-27 17:19:42 +03002860 err = rdev_set_default_key(rdev, dev, key.idx,
Johannes Bergdbd2fd62010-12-09 19:58:59 +01002861 key.def_uni, key.def_multi);
2862
2863 if (err)
2864 goto out;
Johannes Bergfffd0932009-07-08 14:22:54 +02002865
Johannes Berg3d23e342009-09-29 23:27:28 +02002866#ifdef CONFIG_CFG80211_WEXT
Johannes Bergdbd2fd62010-12-09 19:58:59 +01002867 dev->ieee80211_ptr->wext.default_key = key.idx;
Johannes Berg08645122009-05-11 13:54:58 +02002868#endif
Johannes Bergdbd2fd62010-12-09 19:58:59 +01002869 } else {
2870 if (key.def_uni || !key.def_multi) {
2871 err = -EINVAL;
2872 goto out;
2873 }
2874
2875 if (!rdev->ops->set_default_mgmt_key) {
2876 err = -EOPNOTSUPP;
2877 goto out;
2878 }
2879
2880 err = nl80211_key_allowed(dev->ieee80211_ptr);
2881 if (err)
2882 goto out;
2883
Hila Gonene35e4d22012-06-27 17:19:42 +03002884 err = rdev_set_default_mgmt_key(rdev, dev, key.idx);
Johannes Bergdbd2fd62010-12-09 19:58:59 +01002885 if (err)
2886 goto out;
2887
2888#ifdef CONFIG_CFG80211_WEXT
2889 dev->ieee80211_ptr->wext.default_mgmt_key = key.idx;
2890#endif
2891 }
2892
2893 out:
Johannes Bergfffd0932009-07-08 14:22:54 +02002894 wdev_unlock(dev->ieee80211_ptr);
Johannes Berg41ade002007-12-19 02:03:29 +01002895
Johannes Berg41ade002007-12-19 02:03:29 +01002896 return err;
2897}
2898
2899static int nl80211_new_key(struct sk_buff *skb, struct genl_info *info)
2900{
Johannes Berg4c476992010-10-04 21:36:35 +02002901 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Bergfffd0932009-07-08 14:22:54 +02002902 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02002903 struct net_device *dev = info->user_ptr[1];
Johannes Bergb9454e82009-07-08 13:29:08 +02002904 struct key_parse key;
Johannes Berge31b8212010-10-05 19:39:30 +02002905 const u8 *mac_addr = NULL;
Johannes Berg41ade002007-12-19 02:03:29 +01002906
Johannes Bergb9454e82009-07-08 13:29:08 +02002907 err = nl80211_parse_key(info, &key);
2908 if (err)
2909 return err;
Johannes Berg41ade002007-12-19 02:03:29 +01002910
Johannes Bergb9454e82009-07-08 13:29:08 +02002911 if (!key.p.key)
Johannes Berg41ade002007-12-19 02:03:29 +01002912 return -EINVAL;
2913
Johannes Berg41ade002007-12-19 02:03:29 +01002914 if (info->attrs[NL80211_ATTR_MAC])
2915 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
2916
Johannes Berge31b8212010-10-05 19:39:30 +02002917 if (key.type == -1) {
2918 if (mac_addr)
2919 key.type = NL80211_KEYTYPE_PAIRWISE;
2920 else
2921 key.type = NL80211_KEYTYPE_GROUP;
2922 }
2923
2924 /* for now */
2925 if (key.type != NL80211_KEYTYPE_PAIRWISE &&
2926 key.type != NL80211_KEYTYPE_GROUP)
2927 return -EINVAL;
2928
Johannes Berg4c476992010-10-04 21:36:35 +02002929 if (!rdev->ops->add_key)
2930 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01002931
Johannes Berge31b8212010-10-05 19:39:30 +02002932 if (cfg80211_validate_key_settings(rdev, &key.p, key.idx,
2933 key.type == NL80211_KEYTYPE_PAIRWISE,
2934 mac_addr))
Johannes Berg4c476992010-10-04 21:36:35 +02002935 return -EINVAL;
Johannes Bergfffd0932009-07-08 14:22:54 +02002936
2937 wdev_lock(dev->ieee80211_ptr);
2938 err = nl80211_key_allowed(dev->ieee80211_ptr);
2939 if (!err)
Hila Gonene35e4d22012-06-27 17:19:42 +03002940 err = rdev_add_key(rdev, dev, key.idx,
2941 key.type == NL80211_KEYTYPE_PAIRWISE,
2942 mac_addr, &key.p);
Johannes Bergfffd0932009-07-08 14:22:54 +02002943 wdev_unlock(dev->ieee80211_ptr);
Johannes Berg41ade002007-12-19 02:03:29 +01002944
Johannes Berg41ade002007-12-19 02:03:29 +01002945 return err;
2946}
2947
2948static int nl80211_del_key(struct sk_buff *skb, struct genl_info *info)
2949{
Johannes Berg4c476992010-10-04 21:36:35 +02002950 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg41ade002007-12-19 02:03:29 +01002951 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02002952 struct net_device *dev = info->user_ptr[1];
Johannes Berg41ade002007-12-19 02:03:29 +01002953 u8 *mac_addr = NULL;
Johannes Bergb9454e82009-07-08 13:29:08 +02002954 struct key_parse key;
Johannes Berg41ade002007-12-19 02:03:29 +01002955
Johannes Bergb9454e82009-07-08 13:29:08 +02002956 err = nl80211_parse_key(info, &key);
2957 if (err)
2958 return err;
Johannes Berg41ade002007-12-19 02:03:29 +01002959
2960 if (info->attrs[NL80211_ATTR_MAC])
2961 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
2962
Johannes Berge31b8212010-10-05 19:39:30 +02002963 if (key.type == -1) {
2964 if (mac_addr)
2965 key.type = NL80211_KEYTYPE_PAIRWISE;
2966 else
2967 key.type = NL80211_KEYTYPE_GROUP;
2968 }
2969
2970 /* for now */
2971 if (key.type != NL80211_KEYTYPE_PAIRWISE &&
2972 key.type != NL80211_KEYTYPE_GROUP)
2973 return -EINVAL;
2974
Johannes Berg4c476992010-10-04 21:36:35 +02002975 if (!rdev->ops->del_key)
2976 return -EOPNOTSUPP;
Johannes Berg41ade002007-12-19 02:03:29 +01002977
Johannes Bergfffd0932009-07-08 14:22:54 +02002978 wdev_lock(dev->ieee80211_ptr);
2979 err = nl80211_key_allowed(dev->ieee80211_ptr);
Johannes Berge31b8212010-10-05 19:39:30 +02002980
2981 if (key.type == NL80211_KEYTYPE_PAIRWISE && mac_addr &&
2982 !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN))
2983 err = -ENOENT;
2984
Johannes Bergfffd0932009-07-08 14:22:54 +02002985 if (!err)
Hila Gonene35e4d22012-06-27 17:19:42 +03002986 err = rdev_del_key(rdev, dev, key.idx,
2987 key.type == NL80211_KEYTYPE_PAIRWISE,
2988 mac_addr);
Johannes Berg41ade002007-12-19 02:03:29 +01002989
Johannes Berg3d23e342009-09-29 23:27:28 +02002990#ifdef CONFIG_CFG80211_WEXT
Johannes Berg08645122009-05-11 13:54:58 +02002991 if (!err) {
Johannes Bergb9454e82009-07-08 13:29:08 +02002992 if (key.idx == dev->ieee80211_ptr->wext.default_key)
Johannes Berg08645122009-05-11 13:54:58 +02002993 dev->ieee80211_ptr->wext.default_key = -1;
Johannes Bergb9454e82009-07-08 13:29:08 +02002994 else if (key.idx == dev->ieee80211_ptr->wext.default_mgmt_key)
Johannes Berg08645122009-05-11 13:54:58 +02002995 dev->ieee80211_ptr->wext.default_mgmt_key = -1;
2996 }
2997#endif
Johannes Bergfffd0932009-07-08 14:22:54 +02002998 wdev_unlock(dev->ieee80211_ptr);
Johannes Berg08645122009-05-11 13:54:58 +02002999
Johannes Berg41ade002007-12-19 02:03:29 +01003000 return err;
3001}
3002
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +05303003/* This function returns an error or the number of nested attributes */
3004static int validate_acl_mac_addrs(struct nlattr *nl_attr)
3005{
3006 struct nlattr *attr;
3007 int n_entries = 0, tmp;
3008
3009 nla_for_each_nested(attr, nl_attr, tmp) {
3010 if (nla_len(attr) != ETH_ALEN)
3011 return -EINVAL;
3012
3013 n_entries++;
3014 }
3015
3016 return n_entries;
3017}
3018
3019/*
3020 * This function parses ACL information and allocates memory for ACL data.
3021 * On successful return, the calling function is responsible to free the
3022 * ACL buffer returned by this function.
3023 */
3024static struct cfg80211_acl_data *parse_acl_data(struct wiphy *wiphy,
3025 struct genl_info *info)
3026{
3027 enum nl80211_acl_policy acl_policy;
3028 struct nlattr *attr;
3029 struct cfg80211_acl_data *acl;
3030 int i = 0, n_entries, tmp;
3031
3032 if (!wiphy->max_acl_mac_addrs)
3033 return ERR_PTR(-EOPNOTSUPP);
3034
3035 if (!info->attrs[NL80211_ATTR_ACL_POLICY])
3036 return ERR_PTR(-EINVAL);
3037
3038 acl_policy = nla_get_u32(info->attrs[NL80211_ATTR_ACL_POLICY]);
3039 if (acl_policy != NL80211_ACL_POLICY_ACCEPT_UNLESS_LISTED &&
3040 acl_policy != NL80211_ACL_POLICY_DENY_UNLESS_LISTED)
3041 return ERR_PTR(-EINVAL);
3042
3043 if (!info->attrs[NL80211_ATTR_MAC_ADDRS])
3044 return ERR_PTR(-EINVAL);
3045
3046 n_entries = validate_acl_mac_addrs(info->attrs[NL80211_ATTR_MAC_ADDRS]);
3047 if (n_entries < 0)
3048 return ERR_PTR(n_entries);
3049
3050 if (n_entries > wiphy->max_acl_mac_addrs)
3051 return ERR_PTR(-ENOTSUPP);
3052
3053 acl = kzalloc(sizeof(*acl) + (sizeof(struct mac_address) * n_entries),
3054 GFP_KERNEL);
3055 if (!acl)
3056 return ERR_PTR(-ENOMEM);
3057
3058 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_MAC_ADDRS], tmp) {
3059 memcpy(acl->mac_addrs[i].addr, nla_data(attr), ETH_ALEN);
3060 i++;
3061 }
3062
3063 acl->n_acl_entries = n_entries;
3064 acl->acl_policy = acl_policy;
3065
3066 return acl;
3067}
3068
3069static int nl80211_set_mac_acl(struct sk_buff *skb, struct genl_info *info)
3070{
3071 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3072 struct net_device *dev = info->user_ptr[1];
3073 struct cfg80211_acl_data *acl;
3074 int err;
3075
3076 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
3077 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
3078 return -EOPNOTSUPP;
3079
3080 if (!dev->ieee80211_ptr->beacon_interval)
3081 return -EINVAL;
3082
3083 acl = parse_acl_data(&rdev->wiphy, info);
3084 if (IS_ERR(acl))
3085 return PTR_ERR(acl);
3086
3087 err = rdev_set_mac_acl(rdev, dev, acl);
3088
3089 kfree(acl);
3090
3091 return err;
3092}
3093
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003094static int nl80211_parse_beacon(struct nlattr *attrs[],
Johannes Berg88600202012-02-13 15:17:18 +01003095 struct cfg80211_beacon_data *bcn)
Johannes Berged1b6cc2007-12-19 02:03:32 +01003096{
Johannes Berg88600202012-02-13 15:17:18 +01003097 bool haveinfo = false;
Johannes Berged1b6cc2007-12-19 02:03:32 +01003098
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003099 if (!is_valid_ie_attr(attrs[NL80211_ATTR_BEACON_TAIL]) ||
3100 !is_valid_ie_attr(attrs[NL80211_ATTR_IE]) ||
3101 !is_valid_ie_attr(attrs[NL80211_ATTR_IE_PROBE_RESP]) ||
3102 !is_valid_ie_attr(attrs[NL80211_ATTR_IE_ASSOC_RESP]))
Johannes Bergf4a11bb2009-03-27 12:40:28 +01003103 return -EINVAL;
3104
Johannes Berg88600202012-02-13 15:17:18 +01003105 memset(bcn, 0, sizeof(*bcn));
Johannes Berged1b6cc2007-12-19 02:03:32 +01003106
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003107 if (attrs[NL80211_ATTR_BEACON_HEAD]) {
3108 bcn->head = nla_data(attrs[NL80211_ATTR_BEACON_HEAD]);
3109 bcn->head_len = nla_len(attrs[NL80211_ATTR_BEACON_HEAD]);
Johannes Berg88600202012-02-13 15:17:18 +01003110 if (!bcn->head_len)
3111 return -EINVAL;
3112 haveinfo = true;
Johannes Berged1b6cc2007-12-19 02:03:32 +01003113 }
3114
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003115 if (attrs[NL80211_ATTR_BEACON_TAIL]) {
3116 bcn->tail = nla_data(attrs[NL80211_ATTR_BEACON_TAIL]);
3117 bcn->tail_len = nla_len(attrs[NL80211_ATTR_BEACON_TAIL]);
Johannes Berg88600202012-02-13 15:17:18 +01003118 haveinfo = true;
Johannes Berged1b6cc2007-12-19 02:03:32 +01003119 }
3120
Johannes Berg4c476992010-10-04 21:36:35 +02003121 if (!haveinfo)
3122 return -EINVAL;
Johannes Berged1b6cc2007-12-19 02:03:32 +01003123
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003124 if (attrs[NL80211_ATTR_IE]) {
3125 bcn->beacon_ies = nla_data(attrs[NL80211_ATTR_IE]);
3126 bcn->beacon_ies_len = nla_len(attrs[NL80211_ATTR_IE]);
Jouni Malinen9946ecf2011-08-10 23:55:56 +03003127 }
3128
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003129 if (attrs[NL80211_ATTR_IE_PROBE_RESP]) {
Johannes Berg88600202012-02-13 15:17:18 +01003130 bcn->proberesp_ies =
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003131 nla_data(attrs[NL80211_ATTR_IE_PROBE_RESP]);
Johannes Berg88600202012-02-13 15:17:18 +01003132 bcn->proberesp_ies_len =
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003133 nla_len(attrs[NL80211_ATTR_IE_PROBE_RESP]);
Jouni Malinen9946ecf2011-08-10 23:55:56 +03003134 }
3135
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003136 if (attrs[NL80211_ATTR_IE_ASSOC_RESP]) {
Johannes Berg88600202012-02-13 15:17:18 +01003137 bcn->assocresp_ies =
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003138 nla_data(attrs[NL80211_ATTR_IE_ASSOC_RESP]);
Johannes Berg88600202012-02-13 15:17:18 +01003139 bcn->assocresp_ies_len =
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003140 nla_len(attrs[NL80211_ATTR_IE_ASSOC_RESP]);
Jouni Malinen9946ecf2011-08-10 23:55:56 +03003141 }
3142
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003143 if (attrs[NL80211_ATTR_PROBE_RESP]) {
3144 bcn->probe_resp = nla_data(attrs[NL80211_ATTR_PROBE_RESP]);
3145 bcn->probe_resp_len = nla_len(attrs[NL80211_ATTR_PROBE_RESP]);
Arik Nemtsov00f740e2011-11-10 11:28:56 +02003146 }
3147
Johannes Berg88600202012-02-13 15:17:18 +01003148 return 0;
3149}
3150
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003151static bool nl80211_get_ap_channel(struct cfg80211_registered_device *rdev,
3152 struct cfg80211_ap_settings *params)
3153{
3154 struct wireless_dev *wdev;
3155 bool ret = false;
3156
Johannes Berg89a54e42012-06-15 14:33:17 +02003157 list_for_each_entry(wdev, &rdev->wdev_list, list) {
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003158 if (wdev->iftype != NL80211_IFTYPE_AP &&
3159 wdev->iftype != NL80211_IFTYPE_P2P_GO)
3160 continue;
3161
Johannes Berg683b6d32012-11-08 21:25:48 +01003162 if (!wdev->preset_chandef.chan)
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003163 continue;
3164
Johannes Berg683b6d32012-11-08 21:25:48 +01003165 params->chandef = wdev->preset_chandef;
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003166 ret = true;
3167 break;
3168 }
3169
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003170 return ret;
3171}
3172
Jouni Malinene39e5b52012-09-30 19:29:39 +03003173static bool nl80211_valid_auth_type(struct cfg80211_registered_device *rdev,
3174 enum nl80211_auth_type auth_type,
3175 enum nl80211_commands cmd)
3176{
3177 if (auth_type > NL80211_AUTHTYPE_MAX)
3178 return false;
3179
3180 switch (cmd) {
3181 case NL80211_CMD_AUTHENTICATE:
3182 if (!(rdev->wiphy.features & NL80211_FEATURE_SAE) &&
3183 auth_type == NL80211_AUTHTYPE_SAE)
3184 return false;
3185 return true;
3186 case NL80211_CMD_CONNECT:
3187 case NL80211_CMD_START_AP:
3188 /* SAE not supported yet */
3189 if (auth_type == NL80211_AUTHTYPE_SAE)
3190 return false;
3191 return true;
3192 default:
3193 return false;
3194 }
3195}
3196
Johannes Berg88600202012-02-13 15:17:18 +01003197static int nl80211_start_ap(struct sk_buff *skb, struct genl_info *info)
3198{
3199 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3200 struct net_device *dev = info->user_ptr[1];
3201 struct wireless_dev *wdev = dev->ieee80211_ptr;
3202 struct cfg80211_ap_settings params;
3203 int err;
3204
3205 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
3206 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
3207 return -EOPNOTSUPP;
3208
3209 if (!rdev->ops->start_ap)
3210 return -EOPNOTSUPP;
3211
3212 if (wdev->beacon_interval)
3213 return -EALREADY;
3214
3215 memset(&params, 0, sizeof(params));
3216
3217 /* these are required for START_AP */
3218 if (!info->attrs[NL80211_ATTR_BEACON_INTERVAL] ||
3219 !info->attrs[NL80211_ATTR_DTIM_PERIOD] ||
3220 !info->attrs[NL80211_ATTR_BEACON_HEAD])
3221 return -EINVAL;
3222
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003223 err = nl80211_parse_beacon(info->attrs, &params.beacon);
Johannes Berg88600202012-02-13 15:17:18 +01003224 if (err)
3225 return err;
3226
3227 params.beacon_interval =
3228 nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]);
3229 params.dtim_period =
3230 nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]);
3231
3232 err = cfg80211_validate_beacon_int(rdev, params.beacon_interval);
3233 if (err)
3234 return err;
3235
3236 /*
3237 * In theory, some of these attributes should be required here
3238 * but since they were not used when the command was originally
3239 * added, keep them optional for old user space programs to let
3240 * them continue to work with drivers that do not need the
3241 * additional information -- drivers must check!
3242 */
3243 if (info->attrs[NL80211_ATTR_SSID]) {
3244 params.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
3245 params.ssid_len =
3246 nla_len(info->attrs[NL80211_ATTR_SSID]);
3247 if (params.ssid_len == 0 ||
3248 params.ssid_len > IEEE80211_MAX_SSID_LEN)
3249 return -EINVAL;
3250 }
3251
3252 if (info->attrs[NL80211_ATTR_HIDDEN_SSID]) {
3253 params.hidden_ssid = nla_get_u32(
3254 info->attrs[NL80211_ATTR_HIDDEN_SSID]);
3255 if (params.hidden_ssid != NL80211_HIDDEN_SSID_NOT_IN_USE &&
3256 params.hidden_ssid != NL80211_HIDDEN_SSID_ZERO_LEN &&
3257 params.hidden_ssid != NL80211_HIDDEN_SSID_ZERO_CONTENTS)
3258 return -EINVAL;
3259 }
3260
3261 params.privacy = !!info->attrs[NL80211_ATTR_PRIVACY];
3262
3263 if (info->attrs[NL80211_ATTR_AUTH_TYPE]) {
3264 params.auth_type = nla_get_u32(
3265 info->attrs[NL80211_ATTR_AUTH_TYPE]);
Jouni Malinene39e5b52012-09-30 19:29:39 +03003266 if (!nl80211_valid_auth_type(rdev, params.auth_type,
3267 NL80211_CMD_START_AP))
Johannes Berg88600202012-02-13 15:17:18 +01003268 return -EINVAL;
3269 } else
3270 params.auth_type = NL80211_AUTHTYPE_AUTOMATIC;
3271
3272 err = nl80211_crypto_settings(rdev, info, &params.crypto,
3273 NL80211_MAX_NR_CIPHER_SUITES);
3274 if (err)
3275 return err;
3276
Vasanthakumar Thiagarajan1b658f12012-03-02 15:50:02 +05303277 if (info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]) {
3278 if (!(rdev->wiphy.features & NL80211_FEATURE_INACTIVITY_TIMER))
3279 return -EOPNOTSUPP;
3280 params.inactivity_timeout = nla_get_u16(
3281 info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]);
3282 }
3283
Johannes Berg53cabad2012-11-14 15:17:28 +01003284 if (info->attrs[NL80211_ATTR_P2P_CTWINDOW]) {
3285 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
3286 return -EINVAL;
3287 params.p2p_ctwindow =
3288 nla_get_u8(info->attrs[NL80211_ATTR_P2P_CTWINDOW]);
3289 if (params.p2p_ctwindow > 127)
3290 return -EINVAL;
3291 if (params.p2p_ctwindow != 0 &&
3292 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_CTWIN))
3293 return -EINVAL;
3294 }
3295
3296 if (info->attrs[NL80211_ATTR_P2P_OPPPS]) {
3297 u8 tmp;
3298
3299 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
3300 return -EINVAL;
3301 tmp = nla_get_u8(info->attrs[NL80211_ATTR_P2P_OPPPS]);
3302 if (tmp > 1)
3303 return -EINVAL;
3304 params.p2p_opp_ps = tmp;
3305 if (params.p2p_opp_ps != 0 &&
3306 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_OPPPS))
3307 return -EINVAL;
3308 }
3309
Johannes Bergaa430da2012-05-16 23:50:18 +02003310 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
Johannes Berg683b6d32012-11-08 21:25:48 +01003311 err = nl80211_parse_chandef(rdev, info, &params.chandef);
3312 if (err)
3313 return err;
3314 } else if (wdev->preset_chandef.chan) {
3315 params.chandef = wdev->preset_chandef;
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003316 } else if (!nl80211_get_ap_channel(rdev, &params))
Johannes Bergaa430da2012-05-16 23:50:18 +02003317 return -EINVAL;
3318
Ilan Peer174e0cd2014-02-23 09:13:01 +02003319 if (!cfg80211_reg_can_beacon(&rdev->wiphy, &params.chandef,
3320 wdev->iftype))
Johannes Bergaa430da2012-05-16 23:50:18 +02003321 return -EINVAL;
3322
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +05303323 if (info->attrs[NL80211_ATTR_ACL_POLICY]) {
3324 params.acl = parse_acl_data(&rdev->wiphy, info);
3325 if (IS_ERR(params.acl))
3326 return PTR_ERR(params.acl);
3327 }
3328
Simon Wunderlichc56589e2013-11-21 18:19:49 +01003329 wdev_lock(wdev);
Hila Gonene35e4d22012-06-27 17:19:42 +03003330 err = rdev_start_ap(rdev, dev, &params);
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003331 if (!err) {
Johannes Berg683b6d32012-11-08 21:25:48 +01003332 wdev->preset_chandef = params.chandef;
Johannes Berg88600202012-02-13 15:17:18 +01003333 wdev->beacon_interval = params.beacon_interval;
Michal Kazior9e0e2962014-01-29 14:22:27 +01003334 wdev->chandef = params.chandef;
Antonio Quartulli06e191e2012-11-07 12:52:19 +01003335 wdev->ssid_len = params.ssid_len;
3336 memcpy(wdev->ssid, params.ssid, wdev->ssid_len);
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003337 }
Simon Wunderlichc56589e2013-11-21 18:19:49 +01003338 wdev_unlock(wdev);
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +05303339
3340 kfree(params.acl);
3341
Johannes Berg56d18932011-05-09 18:41:15 +02003342 return err;
Johannes Berged1b6cc2007-12-19 02:03:32 +01003343}
3344
Johannes Berg88600202012-02-13 15:17:18 +01003345static int nl80211_set_beacon(struct sk_buff *skb, struct genl_info *info)
3346{
3347 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3348 struct net_device *dev = info->user_ptr[1];
3349 struct wireless_dev *wdev = dev->ieee80211_ptr;
3350 struct cfg80211_beacon_data params;
3351 int err;
3352
3353 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
3354 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
3355 return -EOPNOTSUPP;
3356
3357 if (!rdev->ops->change_beacon)
3358 return -EOPNOTSUPP;
3359
3360 if (!wdev->beacon_interval)
3361 return -EINVAL;
3362
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003363 err = nl80211_parse_beacon(info->attrs, &params);
Johannes Berg88600202012-02-13 15:17:18 +01003364 if (err)
3365 return err;
3366
Simon Wunderlichc56589e2013-11-21 18:19:49 +01003367 wdev_lock(wdev);
3368 err = rdev_change_beacon(rdev, dev, &params);
3369 wdev_unlock(wdev);
3370
3371 return err;
Johannes Berg88600202012-02-13 15:17:18 +01003372}
3373
3374static int nl80211_stop_ap(struct sk_buff *skb, struct genl_info *info)
Johannes Berged1b6cc2007-12-19 02:03:32 +01003375{
Johannes Berg4c476992010-10-04 21:36:35 +02003376 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3377 struct net_device *dev = info->user_ptr[1];
Johannes Berged1b6cc2007-12-19 02:03:32 +01003378
Ilan Peer7c8d5e02014-02-25 15:33:38 +02003379 return cfg80211_stop_ap(rdev, dev, false);
Johannes Berged1b6cc2007-12-19 02:03:32 +01003380}
3381
Johannes Berg5727ef12007-12-19 02:03:34 +01003382static const struct nla_policy sta_flags_policy[NL80211_STA_FLAG_MAX + 1] = {
3383 [NL80211_STA_FLAG_AUTHORIZED] = { .type = NLA_FLAG },
3384 [NL80211_STA_FLAG_SHORT_PREAMBLE] = { .type = NLA_FLAG },
3385 [NL80211_STA_FLAG_WME] = { .type = NLA_FLAG },
Jouni Malinen0e467242009-05-11 21:57:55 +03003386 [NL80211_STA_FLAG_MFP] = { .type = NLA_FLAG },
Javier Cardonab39c48f2011-04-07 15:08:30 -07003387 [NL80211_STA_FLAG_AUTHENTICATED] = { .type = NLA_FLAG },
Johannes Bergd83023d2011-12-14 09:29:15 +01003388 [NL80211_STA_FLAG_TDLS_PEER] = { .type = NLA_FLAG },
Johannes Berg5727ef12007-12-19 02:03:34 +01003389};
3390
Johannes Bergeccb8e82009-05-11 21:57:56 +03003391static int parse_station_flags(struct genl_info *info,
Johannes Bergbdd3ae32012-01-02 13:30:03 +01003392 enum nl80211_iftype iftype,
Johannes Bergeccb8e82009-05-11 21:57:56 +03003393 struct station_parameters *params)
Johannes Berg5727ef12007-12-19 02:03:34 +01003394{
3395 struct nlattr *flags[NL80211_STA_FLAG_MAX + 1];
Johannes Bergeccb8e82009-05-11 21:57:56 +03003396 struct nlattr *nla;
Johannes Berg5727ef12007-12-19 02:03:34 +01003397 int flag;
3398
Johannes Bergeccb8e82009-05-11 21:57:56 +03003399 /*
3400 * Try parsing the new attribute first so userspace
3401 * can specify both for older kernels.
3402 */
3403 nla = info->attrs[NL80211_ATTR_STA_FLAGS2];
3404 if (nla) {
3405 struct nl80211_sta_flag_update *sta_flags;
Johannes Berg5727ef12007-12-19 02:03:34 +01003406
Johannes Bergeccb8e82009-05-11 21:57:56 +03003407 sta_flags = nla_data(nla);
3408 params->sta_flags_mask = sta_flags->mask;
3409 params->sta_flags_set = sta_flags->set;
Johannes Berg77ee7c82013-02-15 00:48:33 +01003410 params->sta_flags_set &= params->sta_flags_mask;
Johannes Bergeccb8e82009-05-11 21:57:56 +03003411 if ((params->sta_flags_mask |
3412 params->sta_flags_set) & BIT(__NL80211_STA_FLAG_INVALID))
3413 return -EINVAL;
3414 return 0;
3415 }
3416
3417 /* if present, parse the old attribute */
3418
3419 nla = info->attrs[NL80211_ATTR_STA_FLAGS];
Johannes Berg5727ef12007-12-19 02:03:34 +01003420 if (!nla)
3421 return 0;
3422
3423 if (nla_parse_nested(flags, NL80211_STA_FLAG_MAX,
3424 nla, sta_flags_policy))
3425 return -EINVAL;
3426
Johannes Bergbdd3ae32012-01-02 13:30:03 +01003427 /*
3428 * Only allow certain flags for interface types so that
3429 * other attributes are silently ignored. Remember that
3430 * this is backward compatibility code with old userspace
3431 * and shouldn't be hit in other cases anyway.
3432 */
3433 switch (iftype) {
3434 case NL80211_IFTYPE_AP:
3435 case NL80211_IFTYPE_AP_VLAN:
3436 case NL80211_IFTYPE_P2P_GO:
3437 params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) |
3438 BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) |
3439 BIT(NL80211_STA_FLAG_WME) |
3440 BIT(NL80211_STA_FLAG_MFP);
3441 break;
3442 case NL80211_IFTYPE_P2P_CLIENT:
3443 case NL80211_IFTYPE_STATION:
3444 params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) |
3445 BIT(NL80211_STA_FLAG_TDLS_PEER);
3446 break;
3447 case NL80211_IFTYPE_MESH_POINT:
3448 params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHENTICATED) |
3449 BIT(NL80211_STA_FLAG_MFP) |
3450 BIT(NL80211_STA_FLAG_AUTHORIZED);
3451 default:
3452 return -EINVAL;
3453 }
Johannes Berg5727ef12007-12-19 02:03:34 +01003454
Johannes Berg3383b5a2012-05-10 20:14:43 +02003455 for (flag = 1; flag <= NL80211_STA_FLAG_MAX; flag++) {
3456 if (flags[flag]) {
Johannes Bergeccb8e82009-05-11 21:57:56 +03003457 params->sta_flags_set |= (1<<flag);
Johannes Berg5727ef12007-12-19 02:03:34 +01003458
Johannes Berg3383b5a2012-05-10 20:14:43 +02003459 /* no longer support new API additions in old API */
3460 if (flag > NL80211_STA_FLAG_MAX_OLD_API)
3461 return -EINVAL;
3462 }
3463 }
3464
Johannes Berg5727ef12007-12-19 02:03:34 +01003465 return 0;
3466}
3467
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003468static bool nl80211_put_sta_rate(struct sk_buff *msg, struct rate_info *info,
3469 int attr)
3470{
3471 struct nlattr *rate;
Vladimir Kondratiev8eb41c82012-07-05 14:25:49 +03003472 u32 bitrate;
3473 u16 bitrate_compat;
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003474
3475 rate = nla_nest_start(msg, attr);
3476 if (!rate)
Johannes Bergdb9c64c2012-11-09 14:56:41 +01003477 return false;
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003478
3479 /* cfg80211_calculate_bitrate will return 0 for mcs >= 32 */
3480 bitrate = cfg80211_calculate_bitrate(info);
Vladimir Kondratiev8eb41c82012-07-05 14:25:49 +03003481 /* report 16-bit bitrate only if we can */
3482 bitrate_compat = bitrate < (1UL << 16) ? bitrate : 0;
Johannes Bergdb9c64c2012-11-09 14:56:41 +01003483 if (bitrate > 0 &&
3484 nla_put_u32(msg, NL80211_RATE_INFO_BITRATE32, bitrate))
3485 return false;
3486 if (bitrate_compat > 0 &&
3487 nla_put_u16(msg, NL80211_RATE_INFO_BITRATE, bitrate_compat))
3488 return false;
3489
3490 if (info->flags & RATE_INFO_FLAGS_MCS) {
3491 if (nla_put_u8(msg, NL80211_RATE_INFO_MCS, info->mcs))
3492 return false;
3493 if (info->flags & RATE_INFO_FLAGS_40_MHZ_WIDTH &&
3494 nla_put_flag(msg, NL80211_RATE_INFO_40_MHZ_WIDTH))
3495 return false;
3496 if (info->flags & RATE_INFO_FLAGS_SHORT_GI &&
3497 nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI))
3498 return false;
3499 } else if (info->flags & RATE_INFO_FLAGS_VHT_MCS) {
3500 if (nla_put_u8(msg, NL80211_RATE_INFO_VHT_MCS, info->mcs))
3501 return false;
3502 if (nla_put_u8(msg, NL80211_RATE_INFO_VHT_NSS, info->nss))
3503 return false;
3504 if (info->flags & RATE_INFO_FLAGS_40_MHZ_WIDTH &&
3505 nla_put_flag(msg, NL80211_RATE_INFO_40_MHZ_WIDTH))
3506 return false;
3507 if (info->flags & RATE_INFO_FLAGS_80_MHZ_WIDTH &&
3508 nla_put_flag(msg, NL80211_RATE_INFO_80_MHZ_WIDTH))
3509 return false;
3510 if (info->flags & RATE_INFO_FLAGS_80P80_MHZ_WIDTH &&
3511 nla_put_flag(msg, NL80211_RATE_INFO_80P80_MHZ_WIDTH))
3512 return false;
3513 if (info->flags & RATE_INFO_FLAGS_160_MHZ_WIDTH &&
3514 nla_put_flag(msg, NL80211_RATE_INFO_160_MHZ_WIDTH))
3515 return false;
3516 if (info->flags & RATE_INFO_FLAGS_SHORT_GI &&
3517 nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI))
3518 return false;
3519 }
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003520
3521 nla_nest_end(msg, rate);
3522 return true;
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003523}
3524
Felix Fietkau119363c2013-04-22 16:29:30 +02003525static bool nl80211_put_signal(struct sk_buff *msg, u8 mask, s8 *signal,
3526 int id)
3527{
3528 void *attr;
3529 int i = 0;
3530
3531 if (!mask)
3532 return true;
3533
3534 attr = nla_nest_start(msg, id);
3535 if (!attr)
3536 return false;
3537
3538 for (i = 0; i < IEEE80211_MAX_CHAINS; i++) {
3539 if (!(mask & BIT(i)))
3540 continue;
3541
3542 if (nla_put_u8(msg, i, signal[i]))
3543 return false;
3544 }
3545
3546 nla_nest_end(msg, attr);
3547
3548 return true;
3549}
3550
Eric W. Biederman15e47302012-09-07 20:12:54 +00003551static int nl80211_send_station(struct sk_buff *msg, u32 portid, u32 seq,
John W. Linville66266b32012-03-15 13:25:41 -04003552 int flags,
3553 struct cfg80211_registered_device *rdev,
3554 struct net_device *dev,
Johannes Berg98b62182009-12-23 13:15:44 +01003555 const u8 *mac_addr, struct station_info *sinfo)
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003556{
3557 void *hdr;
Paul Stewartf4263c92011-03-31 09:25:41 -07003558 struct nlattr *sinfoattr, *bss_param;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003559
Eric W. Biederman15e47302012-09-07 20:12:54 +00003560 hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_STATION);
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003561 if (!hdr)
3562 return -1;
3563
David S. Miller9360ffd2012-03-29 04:41:26 -04003564 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
3565 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) ||
3566 nla_put_u32(msg, NL80211_ATTR_GENERATION, sinfo->generation))
3567 goto nla_put_failure;
Johannes Bergf5ea9122009-08-07 16:17:38 +02003568
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003569 sinfoattr = nla_nest_start(msg, NL80211_ATTR_STA_INFO);
3570 if (!sinfoattr)
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003571 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04003572 if ((sinfo->filled & STATION_INFO_CONNECTED_TIME) &&
3573 nla_put_u32(msg, NL80211_STA_INFO_CONNECTED_TIME,
3574 sinfo->connected_time))
3575 goto nla_put_failure;
3576 if ((sinfo->filled & STATION_INFO_INACTIVE_TIME) &&
3577 nla_put_u32(msg, NL80211_STA_INFO_INACTIVE_TIME,
3578 sinfo->inactive_time))
3579 goto nla_put_failure;
Vladimir Kondratiev42745e02013-02-04 13:53:11 +02003580 if ((sinfo->filled & (STATION_INFO_RX_BYTES |
3581 STATION_INFO_RX_BYTES64)) &&
David S. Miller9360ffd2012-03-29 04:41:26 -04003582 nla_put_u32(msg, NL80211_STA_INFO_RX_BYTES,
Vladimir Kondratiev42745e02013-02-04 13:53:11 +02003583 (u32)sinfo->rx_bytes))
3584 goto nla_put_failure;
3585 if ((sinfo->filled & (STATION_INFO_TX_BYTES |
Felix Fietkau4325d722013-05-23 15:05:59 +02003586 STATION_INFO_TX_BYTES64)) &&
Vladimir Kondratiev42745e02013-02-04 13:53:11 +02003587 nla_put_u32(msg, NL80211_STA_INFO_TX_BYTES,
3588 (u32)sinfo->tx_bytes))
3589 goto nla_put_failure;
3590 if ((sinfo->filled & STATION_INFO_RX_BYTES64) &&
3591 nla_put_u64(msg, NL80211_STA_INFO_RX_BYTES64,
David S. Miller9360ffd2012-03-29 04:41:26 -04003592 sinfo->rx_bytes))
3593 goto nla_put_failure;
Vladimir Kondratiev42745e02013-02-04 13:53:11 +02003594 if ((sinfo->filled & STATION_INFO_TX_BYTES64) &&
3595 nla_put_u64(msg, NL80211_STA_INFO_TX_BYTES64,
David S. Miller9360ffd2012-03-29 04:41:26 -04003596 sinfo->tx_bytes))
3597 goto nla_put_failure;
3598 if ((sinfo->filled & STATION_INFO_LLID) &&
3599 nla_put_u16(msg, NL80211_STA_INFO_LLID, sinfo->llid))
3600 goto nla_put_failure;
3601 if ((sinfo->filled & STATION_INFO_PLID) &&
3602 nla_put_u16(msg, NL80211_STA_INFO_PLID, sinfo->plid))
3603 goto nla_put_failure;
3604 if ((sinfo->filled & STATION_INFO_PLINK_STATE) &&
3605 nla_put_u8(msg, NL80211_STA_INFO_PLINK_STATE,
3606 sinfo->plink_state))
3607 goto nla_put_failure;
John W. Linville66266b32012-03-15 13:25:41 -04003608 switch (rdev->wiphy.signal_type) {
3609 case CFG80211_SIGNAL_TYPE_MBM:
David S. Miller9360ffd2012-03-29 04:41:26 -04003610 if ((sinfo->filled & STATION_INFO_SIGNAL) &&
3611 nla_put_u8(msg, NL80211_STA_INFO_SIGNAL,
3612 sinfo->signal))
3613 goto nla_put_failure;
3614 if ((sinfo->filled & STATION_INFO_SIGNAL_AVG) &&
3615 nla_put_u8(msg, NL80211_STA_INFO_SIGNAL_AVG,
3616 sinfo->signal_avg))
3617 goto nla_put_failure;
John W. Linville66266b32012-03-15 13:25:41 -04003618 break;
3619 default:
3620 break;
3621 }
Felix Fietkau119363c2013-04-22 16:29:30 +02003622 if (sinfo->filled & STATION_INFO_CHAIN_SIGNAL) {
3623 if (!nl80211_put_signal(msg, sinfo->chains,
3624 sinfo->chain_signal,
3625 NL80211_STA_INFO_CHAIN_SIGNAL))
3626 goto nla_put_failure;
3627 }
3628 if (sinfo->filled & STATION_INFO_CHAIN_SIGNAL_AVG) {
3629 if (!nl80211_put_signal(msg, sinfo->chains,
3630 sinfo->chain_signal_avg,
3631 NL80211_STA_INFO_CHAIN_SIGNAL_AVG))
3632 goto nla_put_failure;
3633 }
Henning Rogge420e7fa2008-12-11 22:04:19 +01003634 if (sinfo->filled & STATION_INFO_TX_BITRATE) {
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003635 if (!nl80211_put_sta_rate(msg, &sinfo->txrate,
3636 NL80211_STA_INFO_TX_BITRATE))
Henning Rogge420e7fa2008-12-11 22:04:19 +01003637 goto nla_put_failure;
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003638 }
3639 if (sinfo->filled & STATION_INFO_RX_BITRATE) {
3640 if (!nl80211_put_sta_rate(msg, &sinfo->rxrate,
3641 NL80211_STA_INFO_RX_BITRATE))
3642 goto nla_put_failure;
Henning Rogge420e7fa2008-12-11 22:04:19 +01003643 }
David S. Miller9360ffd2012-03-29 04:41:26 -04003644 if ((sinfo->filled & STATION_INFO_RX_PACKETS) &&
3645 nla_put_u32(msg, NL80211_STA_INFO_RX_PACKETS,
3646 sinfo->rx_packets))
3647 goto nla_put_failure;
3648 if ((sinfo->filled & STATION_INFO_TX_PACKETS) &&
3649 nla_put_u32(msg, NL80211_STA_INFO_TX_PACKETS,
3650 sinfo->tx_packets))
3651 goto nla_put_failure;
3652 if ((sinfo->filled & STATION_INFO_TX_RETRIES) &&
3653 nla_put_u32(msg, NL80211_STA_INFO_TX_RETRIES,
3654 sinfo->tx_retries))
3655 goto nla_put_failure;
3656 if ((sinfo->filled & STATION_INFO_TX_FAILED) &&
3657 nla_put_u32(msg, NL80211_STA_INFO_TX_FAILED,
3658 sinfo->tx_failed))
3659 goto nla_put_failure;
Antonio Quartulli867d8492014-05-19 21:53:19 +02003660 if ((sinfo->filled & STATION_INFO_EXPECTED_THROUGHPUT) &&
3661 nla_put_u32(msg, NL80211_STA_INFO_EXPECTED_THROUGHPUT,
3662 sinfo->expected_throughput))
3663 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04003664 if ((sinfo->filled & STATION_INFO_BEACON_LOSS_COUNT) &&
3665 nla_put_u32(msg, NL80211_STA_INFO_BEACON_LOSS,
3666 sinfo->beacon_loss_count))
3667 goto nla_put_failure;
Marco Porsch3b1c5a52013-01-07 16:04:52 +01003668 if ((sinfo->filled & STATION_INFO_LOCAL_PM) &&
3669 nla_put_u32(msg, NL80211_STA_INFO_LOCAL_PM,
3670 sinfo->local_pm))
3671 goto nla_put_failure;
3672 if ((sinfo->filled & STATION_INFO_PEER_PM) &&
3673 nla_put_u32(msg, NL80211_STA_INFO_PEER_PM,
3674 sinfo->peer_pm))
3675 goto nla_put_failure;
3676 if ((sinfo->filled & STATION_INFO_NONPEER_PM) &&
3677 nla_put_u32(msg, NL80211_STA_INFO_NONPEER_PM,
3678 sinfo->nonpeer_pm))
3679 goto nla_put_failure;
Paul Stewartf4263c92011-03-31 09:25:41 -07003680 if (sinfo->filled & STATION_INFO_BSS_PARAM) {
3681 bss_param = nla_nest_start(msg, NL80211_STA_INFO_BSS_PARAM);
3682 if (!bss_param)
3683 goto nla_put_failure;
3684
David S. Miller9360ffd2012-03-29 04:41:26 -04003685 if (((sinfo->bss_param.flags & BSS_PARAM_FLAGS_CTS_PROT) &&
3686 nla_put_flag(msg, NL80211_STA_BSS_PARAM_CTS_PROT)) ||
3687 ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_PREAMBLE) &&
3688 nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_PREAMBLE)) ||
3689 ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_SLOT_TIME) &&
3690 nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_SLOT_TIME)) ||
3691 nla_put_u8(msg, NL80211_STA_BSS_PARAM_DTIM_PERIOD,
3692 sinfo->bss_param.dtim_period) ||
3693 nla_put_u16(msg, NL80211_STA_BSS_PARAM_BEACON_INTERVAL,
3694 sinfo->bss_param.beacon_interval))
3695 goto nla_put_failure;
Paul Stewartf4263c92011-03-31 09:25:41 -07003696
3697 nla_nest_end(msg, bss_param);
3698 }
David S. Miller9360ffd2012-03-29 04:41:26 -04003699 if ((sinfo->filled & STATION_INFO_STA_FLAGS) &&
3700 nla_put(msg, NL80211_STA_INFO_STA_FLAGS,
3701 sizeof(struct nl80211_sta_flag_update),
3702 &sinfo->sta_flags))
3703 goto nla_put_failure;
John W. Linville7eab0f62012-04-12 14:25:14 -04003704 if ((sinfo->filled & STATION_INFO_T_OFFSET) &&
3705 nla_put_u64(msg, NL80211_STA_INFO_T_OFFSET,
3706 sinfo->t_offset))
3707 goto nla_put_failure;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003708 nla_nest_end(msg, sinfoattr);
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003709
David S. Miller9360ffd2012-03-29 04:41:26 -04003710 if ((sinfo->filled & STATION_INFO_ASSOC_REQ_IES) &&
3711 nla_put(msg, NL80211_ATTR_IE, sinfo->assoc_req_ies_len,
3712 sinfo->assoc_req_ies))
3713 goto nla_put_failure;
Jouni Malinen50d3dfb2011-08-08 12:11:52 +03003714
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003715 return genlmsg_end(msg, hdr);
3716
3717 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07003718 genlmsg_cancel(msg, hdr);
3719 return -EMSGSIZE;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003720}
3721
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003722static int nl80211_dump_station(struct sk_buff *skb,
Johannes Bergbba95fe2008-07-29 13:22:51 +02003723 struct netlink_callback *cb)
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003724{
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003725 struct station_info sinfo;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08003726 struct cfg80211_registered_device *rdev;
Johannes Berg97990a02013-04-19 01:02:55 +02003727 struct wireless_dev *wdev;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003728 u8 mac_addr[ETH_ALEN];
Johannes Berg97990a02013-04-19 01:02:55 +02003729 int sta_idx = cb->args[2];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003730 int err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003731
Zhao, Gang1b8ec872014-04-21 12:53:02 +08003732 err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev);
Johannes Berg67748892010-10-04 21:14:06 +02003733 if (err)
3734 return err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02003735
Johannes Berg97990a02013-04-19 01:02:55 +02003736 if (!wdev->netdev) {
3737 err = -EINVAL;
3738 goto out_err;
3739 }
3740
Zhao, Gang1b8ec872014-04-21 12:53:02 +08003741 if (!rdev->ops->dump_station) {
Jouni Malineneec60b02009-03-20 21:21:19 +02003742 err = -EOPNOTSUPP;
Johannes Bergbba95fe2008-07-29 13:22:51 +02003743 goto out_err;
3744 }
3745
Johannes Bergbba95fe2008-07-29 13:22:51 +02003746 while (1) {
Jouni Malinenf612ced2011-08-11 11:46:22 +03003747 memset(&sinfo, 0, sizeof(sinfo));
Zhao, Gang1b8ec872014-04-21 12:53:02 +08003748 err = rdev_dump_station(rdev, wdev->netdev, sta_idx,
Hila Gonene35e4d22012-06-27 17:19:42 +03003749 mac_addr, &sinfo);
Johannes Bergbba95fe2008-07-29 13:22:51 +02003750 if (err == -ENOENT)
3751 break;
3752 if (err)
Johannes Berg3b858752009-03-12 09:55:09 +01003753 goto out_err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02003754
3755 if (nl80211_send_station(skb,
Eric W. Biederman15e47302012-09-07 20:12:54 +00003756 NETLINK_CB(cb->skb).portid,
Johannes Bergbba95fe2008-07-29 13:22:51 +02003757 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08003758 rdev, wdev->netdev, mac_addr,
Johannes Bergbba95fe2008-07-29 13:22:51 +02003759 &sinfo) < 0)
3760 goto out;
3761
3762 sta_idx++;
3763 }
3764
3765
3766 out:
Johannes Berg97990a02013-04-19 01:02:55 +02003767 cb->args[2] = sta_idx;
Johannes Bergbba95fe2008-07-29 13:22:51 +02003768 err = skb->len;
Johannes Bergbba95fe2008-07-29 13:22:51 +02003769 out_err:
Zhao, Gang1b8ec872014-04-21 12:53:02 +08003770 nl80211_finish_wdev_dump(rdev);
Johannes Bergbba95fe2008-07-29 13:22:51 +02003771
3772 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003773}
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003774
Johannes Berg5727ef12007-12-19 02:03:34 +01003775static int nl80211_get_station(struct sk_buff *skb, struct genl_info *info)
3776{
Johannes Berg4c476992010-10-04 21:36:35 +02003777 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3778 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003779 struct station_info sinfo;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003780 struct sk_buff *msg;
3781 u8 *mac_addr = NULL;
Johannes Berg4c476992010-10-04 21:36:35 +02003782 int err;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003783
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003784 memset(&sinfo, 0, sizeof(sinfo));
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003785
3786 if (!info->attrs[NL80211_ATTR_MAC])
3787 return -EINVAL;
3788
3789 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
3790
Johannes Berg4c476992010-10-04 21:36:35 +02003791 if (!rdev->ops->get_station)
3792 return -EOPNOTSUPP;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003793
Hila Gonene35e4d22012-06-27 17:19:42 +03003794 err = rdev_get_station(rdev, dev, mac_addr, &sinfo);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003795 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02003796 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003797
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07003798 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003799 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02003800 return -ENOMEM;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003801
Eric W. Biederman15e47302012-09-07 20:12:54 +00003802 if (nl80211_send_station(msg, info->snd_portid, info->snd_seq, 0,
John W. Linville66266b32012-03-15 13:25:41 -04003803 rdev, dev, mac_addr, &sinfo) < 0) {
Johannes Berg4c476992010-10-04 21:36:35 +02003804 nlmsg_free(msg);
3805 return -ENOBUFS;
3806 }
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003807
Johannes Berg4c476992010-10-04 21:36:35 +02003808 return genlmsg_reply(msg, info);
Johannes Berg5727ef12007-12-19 02:03:34 +01003809}
3810
Johannes Berg77ee7c82013-02-15 00:48:33 +01003811int cfg80211_check_station_change(struct wiphy *wiphy,
3812 struct station_parameters *params,
3813 enum cfg80211_station_type statype)
3814{
3815 if (params->listen_interval != -1)
3816 return -EINVAL;
Arik Nemtsovc72e1142014-07-17 17:14:29 +03003817 if (params->aid &&
3818 !(params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)))
Johannes Berg77ee7c82013-02-15 00:48:33 +01003819 return -EINVAL;
3820
3821 /* When you run into this, adjust the code below for the new flag */
3822 BUILD_BUG_ON(NL80211_STA_FLAG_MAX != 7);
3823
3824 switch (statype) {
Thomas Pederseneef941e2013-03-04 13:06:11 -08003825 case CFG80211_STA_MESH_PEER_KERNEL:
3826 case CFG80211_STA_MESH_PEER_USER:
Johannes Berg77ee7c82013-02-15 00:48:33 +01003827 /*
3828 * No ignoring the TDLS flag here -- the userspace mesh
3829 * code doesn't have the bug of including TDLS in the
3830 * mask everywhere.
3831 */
3832 if (params->sta_flags_mask &
3833 ~(BIT(NL80211_STA_FLAG_AUTHENTICATED) |
3834 BIT(NL80211_STA_FLAG_MFP) |
3835 BIT(NL80211_STA_FLAG_AUTHORIZED)))
3836 return -EINVAL;
3837 break;
3838 case CFG80211_STA_TDLS_PEER_SETUP:
3839 case CFG80211_STA_TDLS_PEER_ACTIVE:
3840 if (!(params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)))
3841 return -EINVAL;
3842 /* ignore since it can't change */
3843 params->sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER);
3844 break;
3845 default:
3846 /* disallow mesh-specific things */
3847 if (params->plink_action != NL80211_PLINK_ACTION_NO_ACTION)
3848 return -EINVAL;
3849 if (params->local_pm)
3850 return -EINVAL;
3851 if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE)
3852 return -EINVAL;
3853 }
3854
3855 if (statype != CFG80211_STA_TDLS_PEER_SETUP &&
3856 statype != CFG80211_STA_TDLS_PEER_ACTIVE) {
3857 /* TDLS can't be set, ... */
3858 if (params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))
3859 return -EINVAL;
3860 /*
3861 * ... but don't bother the driver with it. This works around
3862 * a hostapd/wpa_supplicant issue -- it always includes the
3863 * TLDS_PEER flag in the mask even for AP mode.
3864 */
3865 params->sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER);
3866 }
3867
3868 if (statype != CFG80211_STA_TDLS_PEER_SETUP) {
3869 /* reject other things that can't change */
3870 if (params->sta_modify_mask & STATION_PARAM_APPLY_UAPSD)
3871 return -EINVAL;
3872 if (params->sta_modify_mask & STATION_PARAM_APPLY_CAPABILITY)
3873 return -EINVAL;
3874 if (params->supported_rates)
3875 return -EINVAL;
3876 if (params->ext_capab || params->ht_capa || params->vht_capa)
3877 return -EINVAL;
3878 }
3879
3880 if (statype != CFG80211_STA_AP_CLIENT) {
3881 if (params->vlan)
3882 return -EINVAL;
3883 }
3884
3885 switch (statype) {
3886 case CFG80211_STA_AP_MLME_CLIENT:
3887 /* Use this only for authorizing/unauthorizing a station */
3888 if (!(params->sta_flags_mask & BIT(NL80211_STA_FLAG_AUTHORIZED)))
3889 return -EOPNOTSUPP;
3890 break;
3891 case CFG80211_STA_AP_CLIENT:
3892 /* accept only the listed bits */
3893 if (params->sta_flags_mask &
3894 ~(BIT(NL80211_STA_FLAG_AUTHORIZED) |
3895 BIT(NL80211_STA_FLAG_AUTHENTICATED) |
3896 BIT(NL80211_STA_FLAG_ASSOCIATED) |
3897 BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) |
3898 BIT(NL80211_STA_FLAG_WME) |
3899 BIT(NL80211_STA_FLAG_MFP)))
3900 return -EINVAL;
3901
3902 /* but authenticated/associated only if driver handles it */
3903 if (!(wiphy->features & NL80211_FEATURE_FULL_AP_CLIENT_STATE) &&
3904 params->sta_flags_mask &
3905 (BIT(NL80211_STA_FLAG_AUTHENTICATED) |
3906 BIT(NL80211_STA_FLAG_ASSOCIATED)))
3907 return -EINVAL;
3908 break;
3909 case CFG80211_STA_IBSS:
3910 case CFG80211_STA_AP_STA:
3911 /* reject any changes other than AUTHORIZED */
3912 if (params->sta_flags_mask & ~BIT(NL80211_STA_FLAG_AUTHORIZED))
3913 return -EINVAL;
3914 break;
3915 case CFG80211_STA_TDLS_PEER_SETUP:
3916 /* reject any changes other than AUTHORIZED or WME */
3917 if (params->sta_flags_mask & ~(BIT(NL80211_STA_FLAG_AUTHORIZED) |
3918 BIT(NL80211_STA_FLAG_WME)))
3919 return -EINVAL;
3920 /* force (at least) rates when authorizing */
3921 if (params->sta_flags_set & BIT(NL80211_STA_FLAG_AUTHORIZED) &&
3922 !params->supported_rates)
3923 return -EINVAL;
3924 break;
3925 case CFG80211_STA_TDLS_PEER_ACTIVE:
3926 /* reject any changes */
3927 return -EINVAL;
Thomas Pederseneef941e2013-03-04 13:06:11 -08003928 case CFG80211_STA_MESH_PEER_KERNEL:
Johannes Berg77ee7c82013-02-15 00:48:33 +01003929 if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE)
3930 return -EINVAL;
3931 break;
Thomas Pederseneef941e2013-03-04 13:06:11 -08003932 case CFG80211_STA_MESH_PEER_USER:
Johannes Berg77ee7c82013-02-15 00:48:33 +01003933 if (params->plink_action != NL80211_PLINK_ACTION_NO_ACTION)
3934 return -EINVAL;
3935 break;
3936 }
3937
3938 return 0;
3939}
3940EXPORT_SYMBOL(cfg80211_check_station_change);
3941
Johannes Berg5727ef12007-12-19 02:03:34 +01003942/*
Felix Fietkauc258d2d2009-11-11 17:23:31 +01003943 * Get vlan interface making sure it is running and on the right wiphy.
Johannes Berg5727ef12007-12-19 02:03:34 +01003944 */
Johannes Berg80b99892011-11-18 16:23:01 +01003945static struct net_device *get_vlan(struct genl_info *info,
3946 struct cfg80211_registered_device *rdev)
Johannes Berg5727ef12007-12-19 02:03:34 +01003947{
Johannes Berg463d0182009-07-14 00:33:35 +02003948 struct nlattr *vlanattr = info->attrs[NL80211_ATTR_STA_VLAN];
Johannes Berg80b99892011-11-18 16:23:01 +01003949 struct net_device *v;
3950 int ret;
Johannes Berg5727ef12007-12-19 02:03:34 +01003951
Johannes Berg80b99892011-11-18 16:23:01 +01003952 if (!vlanattr)
3953 return NULL;
3954
3955 v = dev_get_by_index(genl_info_net(info), nla_get_u32(vlanattr));
3956 if (!v)
3957 return ERR_PTR(-ENODEV);
3958
3959 if (!v->ieee80211_ptr || v->ieee80211_ptr->wiphy != &rdev->wiphy) {
3960 ret = -EINVAL;
3961 goto error;
Johannes Berg5727ef12007-12-19 02:03:34 +01003962 }
Johannes Berg80b99892011-11-18 16:23:01 +01003963
Johannes Berg77ee7c82013-02-15 00:48:33 +01003964 if (v->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN &&
3965 v->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
3966 v->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) {
3967 ret = -EINVAL;
3968 goto error;
3969 }
3970
Johannes Berg80b99892011-11-18 16:23:01 +01003971 if (!netif_running(v)) {
3972 ret = -ENETDOWN;
3973 goto error;
3974 }
3975
3976 return v;
3977 error:
3978 dev_put(v);
3979 return ERR_PTR(ret);
Johannes Berg5727ef12007-12-19 02:03:34 +01003980}
3981
Johannes Berg94e860f2014-01-20 23:58:15 +01003982static const struct nla_policy
3983nl80211_sta_wme_policy[NL80211_STA_WME_MAX + 1] = {
Jouni Malinendf881292013-02-14 21:10:54 +02003984 [NL80211_STA_WME_UAPSD_QUEUES] = { .type = NLA_U8 },
3985 [NL80211_STA_WME_MAX_SP] = { .type = NLA_U8 },
3986};
3987
Johannes Bergff276692013-02-15 00:09:01 +01003988static int nl80211_parse_sta_wme(struct genl_info *info,
3989 struct station_parameters *params)
Jouni Malinendf881292013-02-14 21:10:54 +02003990{
Jouni Malinendf881292013-02-14 21:10:54 +02003991 struct nlattr *tb[NL80211_STA_WME_MAX + 1];
3992 struct nlattr *nla;
3993 int err;
3994
Jouni Malinendf881292013-02-14 21:10:54 +02003995 /* parse WME attributes if present */
3996 if (!info->attrs[NL80211_ATTR_STA_WME])
3997 return 0;
3998
3999 nla = info->attrs[NL80211_ATTR_STA_WME];
4000 err = nla_parse_nested(tb, NL80211_STA_WME_MAX, nla,
4001 nl80211_sta_wme_policy);
4002 if (err)
4003 return err;
4004
4005 if (tb[NL80211_STA_WME_UAPSD_QUEUES])
4006 params->uapsd_queues = nla_get_u8(
4007 tb[NL80211_STA_WME_UAPSD_QUEUES]);
4008 if (params->uapsd_queues & ~IEEE80211_WMM_IE_STA_QOSINFO_AC_MASK)
4009 return -EINVAL;
4010
4011 if (tb[NL80211_STA_WME_MAX_SP])
4012 params->max_sp = nla_get_u8(tb[NL80211_STA_WME_MAX_SP]);
4013
4014 if (params->max_sp & ~IEEE80211_WMM_IE_STA_QOSINFO_SP_MASK)
4015 return -EINVAL;
4016
4017 params->sta_modify_mask |= STATION_PARAM_APPLY_UAPSD;
4018
4019 return 0;
4020}
4021
Sunil Duttc01fc9a2013-10-09 20:45:21 +05304022static int nl80211_parse_sta_channel_info(struct genl_info *info,
4023 struct station_parameters *params)
4024{
4025 if (info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]) {
4026 params->supported_channels =
4027 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]);
4028 params->supported_channels_len =
4029 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]);
4030 /*
4031 * Need to include at least one (first channel, number of
4032 * channels) tuple for each subband, and must have proper
4033 * tuples for the rest of the data as well.
4034 */
4035 if (params->supported_channels_len < 2)
4036 return -EINVAL;
4037 if (params->supported_channels_len % 2)
4038 return -EINVAL;
4039 }
4040
4041 if (info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]) {
4042 params->supported_oper_classes =
4043 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]);
4044 params->supported_oper_classes_len =
4045 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]);
4046 /*
4047 * The value of the Length field of the Supported Operating
4048 * Classes element is between 2 and 253.
4049 */
4050 if (params->supported_oper_classes_len < 2 ||
4051 params->supported_oper_classes_len > 253)
4052 return -EINVAL;
4053 }
4054 return 0;
4055}
4056
Johannes Bergff276692013-02-15 00:09:01 +01004057static int nl80211_set_station_tdls(struct genl_info *info,
4058 struct station_parameters *params)
4059{
Sunil Duttc01fc9a2013-10-09 20:45:21 +05304060 int err;
Johannes Bergff276692013-02-15 00:09:01 +01004061 /* Dummy STA entry gets updated once the peer capabilities are known */
Jouni Malinen5e4b6f52013-05-16 20:11:08 +03004062 if (info->attrs[NL80211_ATTR_PEER_AID])
4063 params->aid = nla_get_u16(info->attrs[NL80211_ATTR_PEER_AID]);
Johannes Bergff276692013-02-15 00:09:01 +01004064 if (info->attrs[NL80211_ATTR_HT_CAPABILITY])
4065 params->ht_capa =
4066 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]);
4067 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY])
4068 params->vht_capa =
4069 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]);
4070
Sunil Duttc01fc9a2013-10-09 20:45:21 +05304071 err = nl80211_parse_sta_channel_info(info, params);
4072 if (err)
4073 return err;
4074
Johannes Bergff276692013-02-15 00:09:01 +01004075 return nl80211_parse_sta_wme(info, params);
4076}
4077
Johannes Berg5727ef12007-12-19 02:03:34 +01004078static int nl80211_set_station(struct sk_buff *skb, struct genl_info *info)
4079{
Johannes Berg4c476992010-10-04 21:36:35 +02004080 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg4c476992010-10-04 21:36:35 +02004081 struct net_device *dev = info->user_ptr[1];
Johannes Berg5727ef12007-12-19 02:03:34 +01004082 struct station_parameters params;
Johannes Berg77ee7c82013-02-15 00:48:33 +01004083 u8 *mac_addr;
4084 int err;
Johannes Berg5727ef12007-12-19 02:03:34 +01004085
4086 memset(&params, 0, sizeof(params));
4087
4088 params.listen_interval = -1;
4089
Johannes Berg77ee7c82013-02-15 00:48:33 +01004090 if (!rdev->ops->change_station)
4091 return -EOPNOTSUPP;
4092
Johannes Berg5727ef12007-12-19 02:03:34 +01004093 if (info->attrs[NL80211_ATTR_STA_AID])
4094 return -EINVAL;
4095
4096 if (!info->attrs[NL80211_ATTR_MAC])
4097 return -EINVAL;
4098
4099 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
4100
4101 if (info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) {
4102 params.supported_rates =
4103 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
4104 params.supported_rates_len =
4105 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
4106 }
4107
Jouni Malinen9d62a982013-02-14 21:10:13 +02004108 if (info->attrs[NL80211_ATTR_STA_CAPABILITY]) {
4109 params.capability =
4110 nla_get_u16(info->attrs[NL80211_ATTR_STA_CAPABILITY]);
4111 params.sta_modify_mask |= STATION_PARAM_APPLY_CAPABILITY;
4112 }
4113
4114 if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]) {
4115 params.ext_capab =
4116 nla_data(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
4117 params.ext_capab_len =
4118 nla_len(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
4119 }
4120
Jouni Malinendf881292013-02-14 21:10:54 +02004121 if (info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL])
Johannes Bergba23d202012-12-27 17:32:09 +01004122 return -EINVAL;
Jouni Malinen36aedc92008-08-25 11:58:58 +03004123
Johannes Bergbdd3ae32012-01-02 13:30:03 +01004124 if (parse_station_flags(info, dev->ieee80211_ptr->iftype, &params))
Johannes Berg5727ef12007-12-19 02:03:34 +01004125 return -EINVAL;
4126
Johannes Bergf8bacc22013-02-14 23:27:01 +01004127 if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) {
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004128 params.plink_action =
Johannes Bergf8bacc22013-02-14 23:27:01 +01004129 nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]);
4130 if (params.plink_action >= NUM_NL80211_PLINK_ACTIONS)
4131 return -EINVAL;
4132 }
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004133
Johannes Bergf8bacc22013-02-14 23:27:01 +01004134 if (info->attrs[NL80211_ATTR_STA_PLINK_STATE]) {
Javier Cardona9c3990a2011-05-03 16:57:11 -07004135 params.plink_state =
Johannes Bergf8bacc22013-02-14 23:27:01 +01004136 nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_STATE]);
4137 if (params.plink_state >= NUM_NL80211_PLINK_STATES)
4138 return -EINVAL;
4139 params.sta_modify_mask |= STATION_PARAM_APPLY_PLINK_STATE;
4140 }
Javier Cardona9c3990a2011-05-03 16:57:11 -07004141
Marco Porsch3b1c5a52013-01-07 16:04:52 +01004142 if (info->attrs[NL80211_ATTR_LOCAL_MESH_POWER_MODE]) {
4143 enum nl80211_mesh_power_mode pm = nla_get_u32(
4144 info->attrs[NL80211_ATTR_LOCAL_MESH_POWER_MODE]);
4145
4146 if (pm <= NL80211_MESH_POWER_UNKNOWN ||
4147 pm > NL80211_MESH_POWER_MAX)
4148 return -EINVAL;
4149
4150 params.local_pm = pm;
4151 }
4152
Johannes Berg77ee7c82013-02-15 00:48:33 +01004153 /* Include parameters for TDLS peer (will check later) */
4154 err = nl80211_set_station_tdls(info, &params);
4155 if (err)
4156 return err;
4157
4158 params.vlan = get_vlan(info, rdev);
4159 if (IS_ERR(params.vlan))
4160 return PTR_ERR(params.vlan);
4161
Johannes Berga97f4422009-06-18 17:23:43 +02004162 switch (dev->ieee80211_ptr->iftype) {
4163 case NL80211_IFTYPE_AP:
4164 case NL80211_IFTYPE_AP_VLAN:
Johannes Berg074ac8d2010-09-16 14:58:22 +02004165 case NL80211_IFTYPE_P2P_GO:
Johannes Berg074ac8d2010-09-16 14:58:22 +02004166 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Berga97f4422009-06-18 17:23:43 +02004167 case NL80211_IFTYPE_STATION:
Antonio Quartulli267335d2012-01-31 20:25:47 +01004168 case NL80211_IFTYPE_ADHOC:
Johannes Berga97f4422009-06-18 17:23:43 +02004169 case NL80211_IFTYPE_MESH_POINT:
Johannes Berga97f4422009-06-18 17:23:43 +02004170 break;
4171 default:
Johannes Berg77ee7c82013-02-15 00:48:33 +01004172 err = -EOPNOTSUPP;
4173 goto out_put_vlan;
Johannes Berg034d6552009-05-27 10:35:29 +02004174 }
4175
Johannes Berg77ee7c82013-02-15 00:48:33 +01004176 /* driver will call cfg80211_check_station_change() */
Hila Gonene35e4d22012-06-27 17:19:42 +03004177 err = rdev_change_station(rdev, dev, mac_addr, &params);
Johannes Berg5727ef12007-12-19 02:03:34 +01004178
Johannes Berg77ee7c82013-02-15 00:48:33 +01004179 out_put_vlan:
Johannes Berg5727ef12007-12-19 02:03:34 +01004180 if (params.vlan)
4181 dev_put(params.vlan);
Johannes Berg3b858752009-03-12 09:55:09 +01004182
Johannes Berg5727ef12007-12-19 02:03:34 +01004183 return err;
4184}
4185
4186static int nl80211_new_station(struct sk_buff *skb, struct genl_info *info)
4187{
Johannes Berg4c476992010-10-04 21:36:35 +02004188 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg5727ef12007-12-19 02:03:34 +01004189 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02004190 struct net_device *dev = info->user_ptr[1];
Johannes Berg5727ef12007-12-19 02:03:34 +01004191 struct station_parameters params;
4192 u8 *mac_addr = NULL;
4193
4194 memset(&params, 0, sizeof(params));
4195
Johannes Berg984c3112013-02-14 23:43:25 +01004196 if (!rdev->ops->add_station)
4197 return -EOPNOTSUPP;
4198
Johannes Berg5727ef12007-12-19 02:03:34 +01004199 if (!info->attrs[NL80211_ATTR_MAC])
4200 return -EINVAL;
4201
Johannes Berg5727ef12007-12-19 02:03:34 +01004202 if (!info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL])
4203 return -EINVAL;
4204
4205 if (!info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES])
4206 return -EINVAL;
4207
Jouni Malinen5e4b6f52013-05-16 20:11:08 +03004208 if (!info->attrs[NL80211_ATTR_STA_AID] &&
4209 !info->attrs[NL80211_ATTR_PEER_AID])
Thadeu Lima de Souza Cascardo0e956c12010-02-12 12:34:50 -02004210 return -EINVAL;
4211
Johannes Berg5727ef12007-12-19 02:03:34 +01004212 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
4213 params.supported_rates =
4214 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
4215 params.supported_rates_len =
4216 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
4217 params.listen_interval =
4218 nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]);
Johannes Berg51b50fb2009-05-24 16:42:30 +02004219
Jouni Malinen3d124ea2013-05-27 18:24:02 +03004220 if (info->attrs[NL80211_ATTR_PEER_AID])
Jouni Malinen5e4b6f52013-05-16 20:11:08 +03004221 params.aid = nla_get_u16(info->attrs[NL80211_ATTR_PEER_AID]);
Jouni Malinen3d124ea2013-05-27 18:24:02 +03004222 else
4223 params.aid = nla_get_u16(info->attrs[NL80211_ATTR_STA_AID]);
Thadeu Lima de Souza Cascardo0e956c12010-02-12 12:34:50 -02004224 if (!params.aid || params.aid > IEEE80211_MAX_AID)
4225 return -EINVAL;
Johannes Berg51b50fb2009-05-24 16:42:30 +02004226
Jouni Malinen9d62a982013-02-14 21:10:13 +02004227 if (info->attrs[NL80211_ATTR_STA_CAPABILITY]) {
4228 params.capability =
4229 nla_get_u16(info->attrs[NL80211_ATTR_STA_CAPABILITY]);
4230 params.sta_modify_mask |= STATION_PARAM_APPLY_CAPABILITY;
4231 }
4232
4233 if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]) {
4234 params.ext_capab =
4235 nla_data(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
4236 params.ext_capab_len =
4237 nla_len(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
4238 }
4239
Jouni Malinen36aedc92008-08-25 11:58:58 +03004240 if (info->attrs[NL80211_ATTR_HT_CAPABILITY])
4241 params.ht_capa =
4242 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]);
Johannes Berg5727ef12007-12-19 02:03:34 +01004243
Mahesh Palivelaf461be3e2012-10-11 08:04:52 +00004244 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY])
4245 params.vht_capa =
4246 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]);
4247
Marek Kwaczynski60f4a7b2013-12-03 10:04:59 +01004248 if (info->attrs[NL80211_ATTR_OPMODE_NOTIF]) {
4249 params.opmode_notif_used = true;
4250 params.opmode_notif =
4251 nla_get_u8(info->attrs[NL80211_ATTR_OPMODE_NOTIF]);
4252 }
4253
Johannes Bergf8bacc22013-02-14 23:27:01 +01004254 if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) {
Javier Cardona96b78df2011-04-07 15:08:33 -07004255 params.plink_action =
Johannes Bergf8bacc22013-02-14 23:27:01 +01004256 nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]);
4257 if (params.plink_action >= NUM_NL80211_PLINK_ACTIONS)
4258 return -EINVAL;
4259 }
Javier Cardona96b78df2011-04-07 15:08:33 -07004260
Sunil Duttc01fc9a2013-10-09 20:45:21 +05304261 err = nl80211_parse_sta_channel_info(info, &params);
4262 if (err)
4263 return err;
4264
Johannes Bergff276692013-02-15 00:09:01 +01004265 err = nl80211_parse_sta_wme(info, &params);
4266 if (err)
4267 return err;
Johannes Bergbdd90d52011-12-14 12:20:27 +01004268
Johannes Bergbdd3ae32012-01-02 13:30:03 +01004269 if (parse_station_flags(info, dev->ieee80211_ptr->iftype, &params))
Johannes Berg5727ef12007-12-19 02:03:34 +01004270 return -EINVAL;
4271
Johannes Berg77ee7c82013-02-15 00:48:33 +01004272 /* When you run into this, adjust the code below for the new flag */
4273 BUILD_BUG_ON(NL80211_STA_FLAG_MAX != 7);
4274
Johannes Bergbdd90d52011-12-14 12:20:27 +01004275 switch (dev->ieee80211_ptr->iftype) {
4276 case NL80211_IFTYPE_AP:
4277 case NL80211_IFTYPE_AP_VLAN:
4278 case NL80211_IFTYPE_P2P_GO:
Johannes Berg984c3112013-02-14 23:43:25 +01004279 /* ignore WME attributes if iface/sta is not capable */
4280 if (!(rdev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) ||
4281 !(params.sta_flags_set & BIT(NL80211_STA_FLAG_WME)))
4282 params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD;
Eliad Pellerc75786c2011-08-23 14:37:46 +03004283
Johannes Bergbdd90d52011-12-14 12:20:27 +01004284 /* TDLS peers cannot be added */
Jouni Malinen3d124ea2013-05-27 18:24:02 +03004285 if ((params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) ||
4286 info->attrs[NL80211_ATTR_PEER_AID])
Johannes Berg4319e192011-09-07 11:50:48 +02004287 return -EINVAL;
Johannes Bergbdd90d52011-12-14 12:20:27 +01004288 /* but don't bother the driver with it */
4289 params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER);
Eliad Pellerc75786c2011-08-23 14:37:46 +03004290
Johannes Bergd582cff2012-10-26 17:53:44 +02004291 /* allow authenticated/associated only if driver handles it */
4292 if (!(rdev->wiphy.features &
4293 NL80211_FEATURE_FULL_AP_CLIENT_STATE) &&
4294 params.sta_flags_mask &
4295 (BIT(NL80211_STA_FLAG_AUTHENTICATED) |
4296 BIT(NL80211_STA_FLAG_ASSOCIATED)))
4297 return -EINVAL;
4298
Johannes Bergbdd90d52011-12-14 12:20:27 +01004299 /* must be last in here for error handling */
4300 params.vlan = get_vlan(info, rdev);
4301 if (IS_ERR(params.vlan))
4302 return PTR_ERR(params.vlan);
4303 break;
4304 case NL80211_IFTYPE_MESH_POINT:
Johannes Berg984c3112013-02-14 23:43:25 +01004305 /* ignore uAPSD data */
4306 params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD;
4307
Johannes Bergd582cff2012-10-26 17:53:44 +02004308 /* associated is disallowed */
4309 if (params.sta_flags_mask & BIT(NL80211_STA_FLAG_ASSOCIATED))
4310 return -EINVAL;
Johannes Bergbdd90d52011-12-14 12:20:27 +01004311 /* TDLS peers cannot be added */
Jouni Malinen3d124ea2013-05-27 18:24:02 +03004312 if ((params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) ||
4313 info->attrs[NL80211_ATTR_PEER_AID])
Johannes Berg4319e192011-09-07 11:50:48 +02004314 return -EINVAL;
Johannes Bergbdd90d52011-12-14 12:20:27 +01004315 break;
4316 case NL80211_IFTYPE_STATION:
Johannes Berg93d08f02013-03-04 09:29:46 +01004317 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Berg984c3112013-02-14 23:43:25 +01004318 /* ignore uAPSD data */
4319 params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD;
4320
Johannes Berg77ee7c82013-02-15 00:48:33 +01004321 /* these are disallowed */
4322 if (params.sta_flags_mask &
4323 (BIT(NL80211_STA_FLAG_ASSOCIATED) |
4324 BIT(NL80211_STA_FLAG_AUTHENTICATED)))
Johannes Bergd582cff2012-10-26 17:53:44 +02004325 return -EINVAL;
Johannes Bergbdd90d52011-12-14 12:20:27 +01004326 /* Only TDLS peers can be added */
4327 if (!(params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)))
4328 return -EINVAL;
4329 /* Can only add if TDLS ... */
4330 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS))
4331 return -EOPNOTSUPP;
4332 /* ... with external setup is supported */
4333 if (!(rdev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP))
4334 return -EOPNOTSUPP;
Johannes Berg77ee7c82013-02-15 00:48:33 +01004335 /*
4336 * Older wpa_supplicant versions always mark the TDLS peer
4337 * as authorized, but it shouldn't yet be.
4338 */
4339 params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_AUTHORIZED);
Johannes Bergbdd90d52011-12-14 12:20:27 +01004340 break;
4341 default:
4342 return -EOPNOTSUPP;
Eliad Pellerc75786c2011-08-23 14:37:46 +03004343 }
4344
Johannes Bergbdd90d52011-12-14 12:20:27 +01004345 /* be aware of params.vlan when changing code here */
Johannes Berg5727ef12007-12-19 02:03:34 +01004346
Hila Gonene35e4d22012-06-27 17:19:42 +03004347 err = rdev_add_station(rdev, dev, mac_addr, &params);
Johannes Berg5727ef12007-12-19 02:03:34 +01004348
Johannes Berg5727ef12007-12-19 02:03:34 +01004349 if (params.vlan)
4350 dev_put(params.vlan);
Johannes Berg5727ef12007-12-19 02:03:34 +01004351 return err;
4352}
4353
4354static int nl80211_del_station(struct sk_buff *skb, struct genl_info *info)
4355{
Johannes Berg4c476992010-10-04 21:36:35 +02004356 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4357 struct net_device *dev = info->user_ptr[1];
Johannes Berg5727ef12007-12-19 02:03:34 +01004358 u8 *mac_addr = NULL;
4359
4360 if (info->attrs[NL80211_ATTR_MAC])
4361 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
4362
Johannes Berge80cf852009-05-11 14:43:13 +02004363 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
Marco Porschd5d9de02010-03-30 10:00:16 +02004364 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN &&
Johannes Berg074ac8d2010-09-16 14:58:22 +02004365 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT &&
Johannes Berg4c476992010-10-04 21:36:35 +02004366 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
4367 return -EINVAL;
Johannes Berge80cf852009-05-11 14:43:13 +02004368
Johannes Berg4c476992010-10-04 21:36:35 +02004369 if (!rdev->ops->del_station)
4370 return -EOPNOTSUPP;
Johannes Berg5727ef12007-12-19 02:03:34 +01004371
Hila Gonene35e4d22012-06-27 17:19:42 +03004372 return rdev_del_station(rdev, dev, mac_addr);
Johannes Berg5727ef12007-12-19 02:03:34 +01004373}
4374
Eric W. Biederman15e47302012-09-07 20:12:54 +00004375static int nl80211_send_mpath(struct sk_buff *msg, u32 portid, u32 seq,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004376 int flags, struct net_device *dev,
4377 u8 *dst, u8 *next_hop,
4378 struct mpath_info *pinfo)
4379{
4380 void *hdr;
4381 struct nlattr *pinfoattr;
4382
Eric W. Biederman15e47302012-09-07 20:12:54 +00004383 hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_STATION);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004384 if (!hdr)
4385 return -1;
4386
David S. Miller9360ffd2012-03-29 04:41:26 -04004387 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
4388 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, dst) ||
4389 nla_put(msg, NL80211_ATTR_MPATH_NEXT_HOP, ETH_ALEN, next_hop) ||
4390 nla_put_u32(msg, NL80211_ATTR_GENERATION, pinfo->generation))
4391 goto nla_put_failure;
Johannes Bergf5ea9122009-08-07 16:17:38 +02004392
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004393 pinfoattr = nla_nest_start(msg, NL80211_ATTR_MPATH_INFO);
4394 if (!pinfoattr)
4395 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04004396 if ((pinfo->filled & MPATH_INFO_FRAME_QLEN) &&
4397 nla_put_u32(msg, NL80211_MPATH_INFO_FRAME_QLEN,
4398 pinfo->frame_qlen))
4399 goto nla_put_failure;
4400 if (((pinfo->filled & MPATH_INFO_SN) &&
4401 nla_put_u32(msg, NL80211_MPATH_INFO_SN, pinfo->sn)) ||
4402 ((pinfo->filled & MPATH_INFO_METRIC) &&
4403 nla_put_u32(msg, NL80211_MPATH_INFO_METRIC,
4404 pinfo->metric)) ||
4405 ((pinfo->filled & MPATH_INFO_EXPTIME) &&
4406 nla_put_u32(msg, NL80211_MPATH_INFO_EXPTIME,
4407 pinfo->exptime)) ||
4408 ((pinfo->filled & MPATH_INFO_FLAGS) &&
4409 nla_put_u8(msg, NL80211_MPATH_INFO_FLAGS,
4410 pinfo->flags)) ||
4411 ((pinfo->filled & MPATH_INFO_DISCOVERY_TIMEOUT) &&
4412 nla_put_u32(msg, NL80211_MPATH_INFO_DISCOVERY_TIMEOUT,
4413 pinfo->discovery_timeout)) ||
4414 ((pinfo->filled & MPATH_INFO_DISCOVERY_RETRIES) &&
4415 nla_put_u8(msg, NL80211_MPATH_INFO_DISCOVERY_RETRIES,
4416 pinfo->discovery_retries)))
4417 goto nla_put_failure;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004418
4419 nla_nest_end(msg, pinfoattr);
4420
4421 return genlmsg_end(msg, hdr);
4422
4423 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07004424 genlmsg_cancel(msg, hdr);
4425 return -EMSGSIZE;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004426}
4427
4428static int nl80211_dump_mpath(struct sk_buff *skb,
Johannes Bergbba95fe2008-07-29 13:22:51 +02004429 struct netlink_callback *cb)
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004430{
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004431 struct mpath_info pinfo;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08004432 struct cfg80211_registered_device *rdev;
Johannes Berg97990a02013-04-19 01:02:55 +02004433 struct wireless_dev *wdev;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004434 u8 dst[ETH_ALEN];
4435 u8 next_hop[ETH_ALEN];
Johannes Berg97990a02013-04-19 01:02:55 +02004436 int path_idx = cb->args[2];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004437 int err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004438
Zhao, Gang1b8ec872014-04-21 12:53:02 +08004439 err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev);
Johannes Berg67748892010-10-04 21:14:06 +02004440 if (err)
4441 return err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004442
Zhao, Gang1b8ec872014-04-21 12:53:02 +08004443 if (!rdev->ops->dump_mpath) {
Jouni Malineneec60b02009-03-20 21:21:19 +02004444 err = -EOPNOTSUPP;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004445 goto out_err;
4446 }
4447
Johannes Berg97990a02013-04-19 01:02:55 +02004448 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) {
Jouni Malineneec60b02009-03-20 21:21:19 +02004449 err = -EOPNOTSUPP;
Roel Kluin0448b5f2009-08-22 21:15:49 +02004450 goto out_err;
Jouni Malineneec60b02009-03-20 21:21:19 +02004451 }
4452
Johannes Bergbba95fe2008-07-29 13:22:51 +02004453 while (1) {
Zhao, Gang1b8ec872014-04-21 12:53:02 +08004454 err = rdev_dump_mpath(rdev, wdev->netdev, path_idx, dst,
Johannes Berg97990a02013-04-19 01:02:55 +02004455 next_hop, &pinfo);
Johannes Bergbba95fe2008-07-29 13:22:51 +02004456 if (err == -ENOENT)
4457 break;
4458 if (err)
Johannes Berg3b858752009-03-12 09:55:09 +01004459 goto out_err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004460
Eric W. Biederman15e47302012-09-07 20:12:54 +00004461 if (nl80211_send_mpath(skb, NETLINK_CB(cb->skb).portid,
Johannes Bergbba95fe2008-07-29 13:22:51 +02004462 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Johannes Berg97990a02013-04-19 01:02:55 +02004463 wdev->netdev, dst, next_hop,
Johannes Bergbba95fe2008-07-29 13:22:51 +02004464 &pinfo) < 0)
4465 goto out;
4466
4467 path_idx++;
4468 }
4469
4470
4471 out:
Johannes Berg97990a02013-04-19 01:02:55 +02004472 cb->args[2] = path_idx;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004473 err = skb->len;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004474 out_err:
Zhao, Gang1b8ec872014-04-21 12:53:02 +08004475 nl80211_finish_wdev_dump(rdev);
Johannes Bergbba95fe2008-07-29 13:22:51 +02004476 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004477}
4478
4479static int nl80211_get_mpath(struct sk_buff *skb, struct genl_info *info)
4480{
Johannes Berg4c476992010-10-04 21:36:35 +02004481 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004482 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02004483 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004484 struct mpath_info pinfo;
4485 struct sk_buff *msg;
4486 u8 *dst = NULL;
4487 u8 next_hop[ETH_ALEN];
4488
4489 memset(&pinfo, 0, sizeof(pinfo));
4490
4491 if (!info->attrs[NL80211_ATTR_MAC])
4492 return -EINVAL;
4493
4494 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
4495
Johannes Berg4c476992010-10-04 21:36:35 +02004496 if (!rdev->ops->get_mpath)
4497 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01004498
Johannes Berg4c476992010-10-04 21:36:35 +02004499 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
4500 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02004501
Hila Gonene35e4d22012-06-27 17:19:42 +03004502 err = rdev_get_mpath(rdev, dev, dst, next_hop, &pinfo);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004503 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02004504 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004505
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07004506 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004507 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02004508 return -ENOMEM;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004509
Eric W. Biederman15e47302012-09-07 20:12:54 +00004510 if (nl80211_send_mpath(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berg4c476992010-10-04 21:36:35 +02004511 dev, dst, next_hop, &pinfo) < 0) {
4512 nlmsg_free(msg);
4513 return -ENOBUFS;
4514 }
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004515
Johannes Berg4c476992010-10-04 21:36:35 +02004516 return genlmsg_reply(msg, info);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004517}
4518
4519static int nl80211_set_mpath(struct sk_buff *skb, struct genl_info *info)
4520{
Johannes Berg4c476992010-10-04 21:36:35 +02004521 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4522 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004523 u8 *dst = NULL;
4524 u8 *next_hop = NULL;
4525
4526 if (!info->attrs[NL80211_ATTR_MAC])
4527 return -EINVAL;
4528
4529 if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP])
4530 return -EINVAL;
4531
4532 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
4533 next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]);
4534
Johannes Berg4c476992010-10-04 21:36:35 +02004535 if (!rdev->ops->change_mpath)
4536 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01004537
Johannes Berg4c476992010-10-04 21:36:35 +02004538 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
4539 return -EOPNOTSUPP;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004540
Hila Gonene35e4d22012-06-27 17:19:42 +03004541 return rdev_change_mpath(rdev, dev, dst, next_hop);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004542}
Johannes Berg4c476992010-10-04 21:36:35 +02004543
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004544static int nl80211_new_mpath(struct sk_buff *skb, struct genl_info *info)
4545{
Johannes Berg4c476992010-10-04 21:36:35 +02004546 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4547 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004548 u8 *dst = NULL;
4549 u8 *next_hop = NULL;
4550
4551 if (!info->attrs[NL80211_ATTR_MAC])
4552 return -EINVAL;
4553
4554 if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP])
4555 return -EINVAL;
4556
4557 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
4558 next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]);
4559
Johannes Berg4c476992010-10-04 21:36:35 +02004560 if (!rdev->ops->add_mpath)
4561 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01004562
Johannes Berg4c476992010-10-04 21:36:35 +02004563 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
4564 return -EOPNOTSUPP;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004565
Hila Gonene35e4d22012-06-27 17:19:42 +03004566 return rdev_add_mpath(rdev, dev, dst, next_hop);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004567}
4568
4569static int nl80211_del_mpath(struct sk_buff *skb, struct genl_info *info)
4570{
Johannes Berg4c476992010-10-04 21:36:35 +02004571 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4572 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004573 u8 *dst = NULL;
4574
4575 if (info->attrs[NL80211_ATTR_MAC])
4576 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
4577
Johannes Berg4c476992010-10-04 21:36:35 +02004578 if (!rdev->ops->del_mpath)
4579 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01004580
Hila Gonene35e4d22012-06-27 17:19:42 +03004581 return rdev_del_mpath(rdev, dev, dst);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004582}
4583
Jouni Malinen9f1ba902008-08-07 20:07:01 +03004584static int nl80211_set_bss(struct sk_buff *skb, struct genl_info *info)
4585{
Johannes Berg4c476992010-10-04 21:36:35 +02004586 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4587 struct net_device *dev = info->user_ptr[1];
Simon Wunderlichc56589e2013-11-21 18:19:49 +01004588 struct wireless_dev *wdev = dev->ieee80211_ptr;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03004589 struct bss_parameters params;
Simon Wunderlichc56589e2013-11-21 18:19:49 +01004590 int err;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03004591
4592 memset(&params, 0, sizeof(params));
4593 /* default to not changing parameters */
4594 params.use_cts_prot = -1;
4595 params.use_short_preamble = -1;
4596 params.use_short_slot_time = -1;
Felix Fietkaufd8aaaf2010-04-27 01:23:35 +02004597 params.ap_isolate = -1;
Helmut Schaa50b12f52010-11-19 12:40:25 +01004598 params.ht_opmode = -1;
Johannes Berg53cabad2012-11-14 15:17:28 +01004599 params.p2p_ctwindow = -1;
4600 params.p2p_opp_ps = -1;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03004601
4602 if (info->attrs[NL80211_ATTR_BSS_CTS_PROT])
4603 params.use_cts_prot =
4604 nla_get_u8(info->attrs[NL80211_ATTR_BSS_CTS_PROT]);
4605 if (info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE])
4606 params.use_short_preamble =
4607 nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]);
4608 if (info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME])
4609 params.use_short_slot_time =
4610 nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]);
Jouni Malinen90c97a02008-10-30 16:59:22 +02004611 if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) {
4612 params.basic_rates =
4613 nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
4614 params.basic_rates_len =
4615 nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
4616 }
Felix Fietkaufd8aaaf2010-04-27 01:23:35 +02004617 if (info->attrs[NL80211_ATTR_AP_ISOLATE])
4618 params.ap_isolate = !!nla_get_u8(info->attrs[NL80211_ATTR_AP_ISOLATE]);
Helmut Schaa50b12f52010-11-19 12:40:25 +01004619 if (info->attrs[NL80211_ATTR_BSS_HT_OPMODE])
4620 params.ht_opmode =
4621 nla_get_u16(info->attrs[NL80211_ATTR_BSS_HT_OPMODE]);
Jouni Malinen9f1ba902008-08-07 20:07:01 +03004622
Johannes Berg53cabad2012-11-14 15:17:28 +01004623 if (info->attrs[NL80211_ATTR_P2P_CTWINDOW]) {
4624 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
4625 return -EINVAL;
4626 params.p2p_ctwindow =
4627 nla_get_s8(info->attrs[NL80211_ATTR_P2P_CTWINDOW]);
4628 if (params.p2p_ctwindow < 0)
4629 return -EINVAL;
4630 if (params.p2p_ctwindow != 0 &&
4631 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_CTWIN))
4632 return -EINVAL;
4633 }
4634
4635 if (info->attrs[NL80211_ATTR_P2P_OPPPS]) {
4636 u8 tmp;
4637
4638 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
4639 return -EINVAL;
4640 tmp = nla_get_u8(info->attrs[NL80211_ATTR_P2P_OPPPS]);
4641 if (tmp > 1)
4642 return -EINVAL;
4643 params.p2p_opp_ps = tmp;
4644 if (params.p2p_opp_ps &&
4645 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_OPPPS))
4646 return -EINVAL;
4647 }
4648
Johannes Berg4c476992010-10-04 21:36:35 +02004649 if (!rdev->ops->change_bss)
4650 return -EOPNOTSUPP;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03004651
Johannes Berg074ac8d2010-09-16 14:58:22 +02004652 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
Johannes Berg4c476992010-10-04 21:36:35 +02004653 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
4654 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02004655
Simon Wunderlichc56589e2013-11-21 18:19:49 +01004656 wdev_lock(wdev);
4657 err = rdev_change_bss(rdev, dev, &params);
4658 wdev_unlock(wdev);
4659
4660 return err;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03004661}
4662
Alexey Dobriyanb54452b2010-02-18 08:14:31 +00004663static const struct nla_policy reg_rule_policy[NL80211_REG_RULE_ATTR_MAX + 1] = {
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004664 [NL80211_ATTR_REG_RULE_FLAGS] = { .type = NLA_U32 },
4665 [NL80211_ATTR_FREQ_RANGE_START] = { .type = NLA_U32 },
4666 [NL80211_ATTR_FREQ_RANGE_END] = { .type = NLA_U32 },
4667 [NL80211_ATTR_FREQ_RANGE_MAX_BW] = { .type = NLA_U32 },
4668 [NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN] = { .type = NLA_U32 },
4669 [NL80211_ATTR_POWER_RULE_MAX_EIRP] = { .type = NLA_U32 },
Janusz Dziedzic089027e2014-02-21 19:46:12 +01004670 [NL80211_ATTR_DFS_CAC_TIME] = { .type = NLA_U32 },
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004671};
4672
4673static int parse_reg_rule(struct nlattr *tb[],
4674 struct ieee80211_reg_rule *reg_rule)
4675{
4676 struct ieee80211_freq_range *freq_range = &reg_rule->freq_range;
4677 struct ieee80211_power_rule *power_rule = &reg_rule->power_rule;
4678
4679 if (!tb[NL80211_ATTR_REG_RULE_FLAGS])
4680 return -EINVAL;
4681 if (!tb[NL80211_ATTR_FREQ_RANGE_START])
4682 return -EINVAL;
4683 if (!tb[NL80211_ATTR_FREQ_RANGE_END])
4684 return -EINVAL;
Janusz Dziedzicb0dfd2e2014-02-20 13:52:16 +01004685 if (!tb[NL80211_ATTR_FREQ_RANGE_MAX_BW])
4686 return -EINVAL;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004687 if (!tb[NL80211_ATTR_POWER_RULE_MAX_EIRP])
4688 return -EINVAL;
4689
4690 reg_rule->flags = nla_get_u32(tb[NL80211_ATTR_REG_RULE_FLAGS]);
4691
4692 freq_range->start_freq_khz =
4693 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_START]);
4694 freq_range->end_freq_khz =
4695 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_END]);
Janusz Dziedzicb0dfd2e2014-02-20 13:52:16 +01004696 freq_range->max_bandwidth_khz =
4697 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]);
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004698
4699 power_rule->max_eirp =
4700 nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]);
4701
4702 if (tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN])
4703 power_rule->max_antenna_gain =
4704 nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]);
4705
Janusz Dziedzic089027e2014-02-21 19:46:12 +01004706 if (tb[NL80211_ATTR_DFS_CAC_TIME])
4707 reg_rule->dfs_cac_ms =
4708 nla_get_u32(tb[NL80211_ATTR_DFS_CAC_TIME]);
4709
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004710 return 0;
4711}
4712
4713static int nl80211_req_set_reg(struct sk_buff *skb, struct genl_info *info)
4714{
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004715 char *data = NULL;
Luis R. Rodriguez57b5ce02012-07-12 11:49:18 -07004716 enum nl80211_user_reg_hint_type user_reg_hint_type;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004717
Luis R. Rodriguez80778f12009-02-21 00:04:22 -05004718 /*
4719 * You should only get this when cfg80211 hasn't yet initialized
4720 * completely when built-in to the kernel right between the time
4721 * window between nl80211_init() and regulatory_init(), if that is
4722 * even possible.
4723 */
Johannes Berg458f4f92012-12-06 15:47:38 +01004724 if (unlikely(!rcu_access_pointer(cfg80211_regdomain)))
Luis R. Rodriguezfe33eb32009-02-21 00:04:30 -05004725 return -EINPROGRESS;
Luis R. Rodriguez80778f12009-02-21 00:04:22 -05004726
Luis R. Rodriguez57b5ce02012-07-12 11:49:18 -07004727 if (info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE])
4728 user_reg_hint_type =
4729 nla_get_u32(info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE]);
4730 else
4731 user_reg_hint_type = NL80211_USER_REG_HINT_USER;
4732
4733 switch (user_reg_hint_type) {
4734 case NL80211_USER_REG_HINT_USER:
4735 case NL80211_USER_REG_HINT_CELL_BASE:
Ilan Peer52616f22014-02-25 16:26:00 +02004736 if (!info->attrs[NL80211_ATTR_REG_ALPHA2])
4737 return -EINVAL;
4738
4739 data = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]);
4740 return regulatory_hint_user(data, user_reg_hint_type);
4741 case NL80211_USER_REG_HINT_INDOOR:
4742 return regulatory_hint_indoor_user();
Luis R. Rodriguez57b5ce02012-07-12 11:49:18 -07004743 default:
4744 return -EINVAL;
4745 }
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004746}
4747
Javier Cardona24bdd9f2010-12-16 17:37:48 -08004748static int nl80211_get_mesh_config(struct sk_buff *skb,
Johannes Berg29cbe682010-12-03 09:20:44 +01004749 struct genl_info *info)
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004750{
Johannes Berg4c476992010-10-04 21:36:35 +02004751 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg4c476992010-10-04 21:36:35 +02004752 struct net_device *dev = info->user_ptr[1];
Johannes Berg29cbe682010-12-03 09:20:44 +01004753 struct wireless_dev *wdev = dev->ieee80211_ptr;
4754 struct mesh_config cur_params;
4755 int err = 0;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004756 void *hdr;
4757 struct nlattr *pinfoattr;
4758 struct sk_buff *msg;
4759
Johannes Berg29cbe682010-12-03 09:20:44 +01004760 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT)
4761 return -EOPNOTSUPP;
4762
Javier Cardona24bdd9f2010-12-16 17:37:48 -08004763 if (!rdev->ops->get_mesh_config)
Johannes Berg4c476992010-10-04 21:36:35 +02004764 return -EOPNOTSUPP;
Jouni Malinenf3f92582009-03-20 17:57:36 +02004765
Johannes Berg29cbe682010-12-03 09:20:44 +01004766 wdev_lock(wdev);
4767 /* If not connected, get default parameters */
4768 if (!wdev->mesh_id_len)
4769 memcpy(&cur_params, &default_mesh_config, sizeof(cur_params));
4770 else
Hila Gonene35e4d22012-06-27 17:19:42 +03004771 err = rdev_get_mesh_config(rdev, dev, &cur_params);
Johannes Berg29cbe682010-12-03 09:20:44 +01004772 wdev_unlock(wdev);
4773
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004774 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02004775 return err;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004776
4777 /* Draw up a netlink message to send back */
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07004778 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02004779 if (!msg)
4780 return -ENOMEM;
Eric W. Biederman15e47302012-09-07 20:12:54 +00004781 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Javier Cardona24bdd9f2010-12-16 17:37:48 -08004782 NL80211_CMD_GET_MESH_CONFIG);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004783 if (!hdr)
Julia Lawallefe1cf02011-01-28 15:17:11 +01004784 goto out;
Javier Cardona24bdd9f2010-12-16 17:37:48 -08004785 pinfoattr = nla_nest_start(msg, NL80211_ATTR_MESH_CONFIG);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004786 if (!pinfoattr)
4787 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04004788 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
4789 nla_put_u16(msg, NL80211_MESHCONF_RETRY_TIMEOUT,
4790 cur_params.dot11MeshRetryTimeout) ||
4791 nla_put_u16(msg, NL80211_MESHCONF_CONFIRM_TIMEOUT,
4792 cur_params.dot11MeshConfirmTimeout) ||
4793 nla_put_u16(msg, NL80211_MESHCONF_HOLDING_TIMEOUT,
4794 cur_params.dot11MeshHoldingTimeout) ||
4795 nla_put_u16(msg, NL80211_MESHCONF_MAX_PEER_LINKS,
4796 cur_params.dot11MeshMaxPeerLinks) ||
4797 nla_put_u8(msg, NL80211_MESHCONF_MAX_RETRIES,
4798 cur_params.dot11MeshMaxRetries) ||
4799 nla_put_u8(msg, NL80211_MESHCONF_TTL,
4800 cur_params.dot11MeshTTL) ||
4801 nla_put_u8(msg, NL80211_MESHCONF_ELEMENT_TTL,
4802 cur_params.element_ttl) ||
4803 nla_put_u8(msg, NL80211_MESHCONF_AUTO_OPEN_PLINKS,
4804 cur_params.auto_open_plinks) ||
John W. Linville7eab0f62012-04-12 14:25:14 -04004805 nla_put_u32(msg, NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR,
4806 cur_params.dot11MeshNbrOffsetMaxNeighbor) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04004807 nla_put_u8(msg, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES,
4808 cur_params.dot11MeshHWMPmaxPREQretries) ||
4809 nla_put_u32(msg, NL80211_MESHCONF_PATH_REFRESH_TIME,
4810 cur_params.path_refresh_time) ||
4811 nla_put_u16(msg, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT,
4812 cur_params.min_discovery_timeout) ||
4813 nla_put_u32(msg, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT,
4814 cur_params.dot11MeshHWMPactivePathTimeout) ||
4815 nla_put_u16(msg, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL,
4816 cur_params.dot11MeshHWMPpreqMinInterval) ||
4817 nla_put_u16(msg, NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL,
4818 cur_params.dot11MeshHWMPperrMinInterval) ||
4819 nla_put_u16(msg, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME,
4820 cur_params.dot11MeshHWMPnetDiameterTraversalTime) ||
4821 nla_put_u8(msg, NL80211_MESHCONF_HWMP_ROOTMODE,
4822 cur_params.dot11MeshHWMPRootMode) ||
4823 nla_put_u16(msg, NL80211_MESHCONF_HWMP_RANN_INTERVAL,
4824 cur_params.dot11MeshHWMPRannInterval) ||
4825 nla_put_u8(msg, NL80211_MESHCONF_GATE_ANNOUNCEMENTS,
4826 cur_params.dot11MeshGateAnnouncementProtocol) ||
4827 nla_put_u8(msg, NL80211_MESHCONF_FORWARDING,
4828 cur_params.dot11MeshForwarding) ||
4829 nla_put_u32(msg, NL80211_MESHCONF_RSSI_THRESHOLD,
Ashok Nagarajan70c33ea2012-04-30 14:20:32 -07004830 cur_params.rssi_threshold) ||
4831 nla_put_u32(msg, NL80211_MESHCONF_HT_OPMODE,
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08004832 cur_params.ht_opmode) ||
4833 nla_put_u32(msg, NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT,
4834 cur_params.dot11MeshHWMPactivePathToRootTimeout) ||
4835 nla_put_u16(msg, NL80211_MESHCONF_HWMP_ROOT_INTERVAL,
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +08004836 cur_params.dot11MeshHWMProotInterval) ||
4837 nla_put_u16(msg, NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL,
Marco Porsch3b1c5a52013-01-07 16:04:52 +01004838 cur_params.dot11MeshHWMPconfirmationInterval) ||
4839 nla_put_u32(msg, NL80211_MESHCONF_POWER_MODE,
4840 cur_params.power_mode) ||
4841 nla_put_u16(msg, NL80211_MESHCONF_AWAKE_WINDOW,
Colleen Twitty8e7c0532013-06-03 09:53:39 -07004842 cur_params.dot11MeshAwakeWindowDuration) ||
4843 nla_put_u32(msg, NL80211_MESHCONF_PLINK_TIMEOUT,
4844 cur_params.plink_timeout))
David S. Miller9360ffd2012-03-29 04:41:26 -04004845 goto nla_put_failure;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004846 nla_nest_end(msg, pinfoattr);
4847 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02004848 return genlmsg_reply(msg, info);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004849
Johannes Berg3b858752009-03-12 09:55:09 +01004850 nla_put_failure:
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004851 genlmsg_cancel(msg, hdr);
Julia Lawallefe1cf02011-01-28 15:17:11 +01004852 out:
Yuri Ershovd080e272010-06-29 15:08:07 +04004853 nlmsg_free(msg);
Johannes Berg4c476992010-10-04 21:36:35 +02004854 return -ENOBUFS;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004855}
4856
Alexey Dobriyanb54452b2010-02-18 08:14:31 +00004857static const struct nla_policy nl80211_meshconf_params_policy[NL80211_MESHCONF_ATTR_MAX+1] = {
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004858 [NL80211_MESHCONF_RETRY_TIMEOUT] = { .type = NLA_U16 },
4859 [NL80211_MESHCONF_CONFIRM_TIMEOUT] = { .type = NLA_U16 },
4860 [NL80211_MESHCONF_HOLDING_TIMEOUT] = { .type = NLA_U16 },
4861 [NL80211_MESHCONF_MAX_PEER_LINKS] = { .type = NLA_U16 },
4862 [NL80211_MESHCONF_MAX_RETRIES] = { .type = NLA_U8 },
4863 [NL80211_MESHCONF_TTL] = { .type = NLA_U8 },
Javier Cardona45904f22010-12-03 09:20:40 +01004864 [NL80211_MESHCONF_ELEMENT_TTL] = { .type = NLA_U8 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004865 [NL80211_MESHCONF_AUTO_OPEN_PLINKS] = { .type = NLA_U8 },
Javier Cardonad299a1f2012-03-31 11:31:33 -07004866 [NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR] = { .type = NLA_U32 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004867 [NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES] = { .type = NLA_U8 },
4868 [NL80211_MESHCONF_PATH_REFRESH_TIME] = { .type = NLA_U32 },
4869 [NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT] = { .type = NLA_U16 },
4870 [NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT] = { .type = NLA_U32 },
4871 [NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL] = { .type = NLA_U16 },
Thomas Pedersendca7e942011-11-24 17:15:24 -08004872 [NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL] = { .type = NLA_U16 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004873 [NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME] = { .type = NLA_U16 },
Javier Cardona699403d2011-08-09 16:45:09 -07004874 [NL80211_MESHCONF_HWMP_ROOTMODE] = { .type = NLA_U8 },
Javier Cardona0507e152011-08-09 16:45:10 -07004875 [NL80211_MESHCONF_HWMP_RANN_INTERVAL] = { .type = NLA_U16 },
Javier Cardona16dd7262011-08-09 16:45:11 -07004876 [NL80211_MESHCONF_GATE_ANNOUNCEMENTS] = { .type = NLA_U8 },
Chun-Yeow Yeoh94f90652012-01-21 01:02:16 +08004877 [NL80211_MESHCONF_FORWARDING] = { .type = NLA_U8 },
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004878 [NL80211_MESHCONF_RSSI_THRESHOLD] = { .type = NLA_U32 },
4879 [NL80211_MESHCONF_HT_OPMODE] = { .type = NLA_U16 },
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08004880 [NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT] = { .type = NLA_U32 },
4881 [NL80211_MESHCONF_HWMP_ROOT_INTERVAL] = { .type = NLA_U16 },
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +08004882 [NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL] = { .type = NLA_U16 },
Marco Porsch3b1c5a52013-01-07 16:04:52 +01004883 [NL80211_MESHCONF_POWER_MODE] = { .type = NLA_U32 },
4884 [NL80211_MESHCONF_AWAKE_WINDOW] = { .type = NLA_U16 },
Colleen Twitty8e7c0532013-06-03 09:53:39 -07004885 [NL80211_MESHCONF_PLINK_TIMEOUT] = { .type = NLA_U32 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004886};
4887
Javier Cardonac80d5452010-12-16 17:37:49 -08004888static const struct nla_policy
4889 nl80211_mesh_setup_params_policy[NL80211_MESH_SETUP_ATTR_MAX+1] = {
Javier Cardonad299a1f2012-03-31 11:31:33 -07004890 [NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC] = { .type = NLA_U8 },
Javier Cardonac80d5452010-12-16 17:37:49 -08004891 [NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL] = { .type = NLA_U8 },
4892 [NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC] = { .type = NLA_U8 },
Javier Cardona15d5dda2011-04-07 15:08:28 -07004893 [NL80211_MESH_SETUP_USERSPACE_AUTH] = { .type = NLA_FLAG },
Colleen Twitty6e16d902013-05-08 11:45:59 -07004894 [NL80211_MESH_SETUP_AUTH_PROTOCOL] = { .type = NLA_U8 },
Thomas Pedersenbb2798d2013-03-04 13:06:10 -08004895 [NL80211_MESH_SETUP_USERSPACE_MPM] = { .type = NLA_FLAG },
Javier Cardona581a8b02011-04-07 15:08:27 -07004896 [NL80211_MESH_SETUP_IE] = { .type = NLA_BINARY,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004897 .len = IEEE80211_MAX_DATA_LEN },
Javier Cardonab130e5c2011-05-03 16:57:07 -07004898 [NL80211_MESH_SETUP_USERSPACE_AMPE] = { .type = NLA_FLAG },
Javier Cardonac80d5452010-12-16 17:37:49 -08004899};
4900
Javier Cardona24bdd9f2010-12-16 17:37:48 -08004901static int nl80211_parse_mesh_config(struct genl_info *info,
Johannes Bergbd90fdc2010-12-03 09:20:43 +01004902 struct mesh_config *cfg,
4903 u32 *mask_out)
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004904{
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004905 struct nlattr *tb[NL80211_MESHCONF_ATTR_MAX + 1];
Johannes Bergbd90fdc2010-12-03 09:20:43 +01004906 u32 mask = 0;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004907
Marco Porschea54fba2013-01-07 16:04:48 +01004908#define FILL_IN_MESH_PARAM_IF_SET(tb, cfg, param, min, max, mask, attr, fn) \
4909do { \
4910 if (tb[attr]) { \
4911 if (fn(tb[attr]) < min || fn(tb[attr]) > max) \
4912 return -EINVAL; \
4913 cfg->param = fn(tb[attr]); \
4914 mask |= (1 << (attr - 1)); \
4915 } \
4916} while (0)
Johannes Bergbd90fdc2010-12-03 09:20:43 +01004917
4918
Javier Cardona24bdd9f2010-12-16 17:37:48 -08004919 if (!info->attrs[NL80211_ATTR_MESH_CONFIG])
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004920 return -EINVAL;
4921 if (nla_parse_nested(tb, NL80211_MESHCONF_ATTR_MAX,
Javier Cardona24bdd9f2010-12-16 17:37:48 -08004922 info->attrs[NL80211_ATTR_MESH_CONFIG],
Johannes Bergbd90fdc2010-12-03 09:20:43 +01004923 nl80211_meshconf_params_policy))
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004924 return -EINVAL;
4925
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004926 /* This makes sure that there aren't more than 32 mesh config
4927 * parameters (otherwise our bitfield scheme would not work.) */
4928 BUILD_BUG_ON(NL80211_MESHCONF_ATTR_MAX > 32);
4929
4930 /* Fill in the params struct */
Marco Porschea54fba2013-01-07 16:04:48 +01004931 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshRetryTimeout, 1, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004932 mask, NL80211_MESHCONF_RETRY_TIMEOUT,
4933 nla_get_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01004934 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshConfirmTimeout, 1, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004935 mask, NL80211_MESHCONF_CONFIRM_TIMEOUT,
4936 nla_get_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01004937 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHoldingTimeout, 1, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004938 mask, NL80211_MESHCONF_HOLDING_TIMEOUT,
4939 nla_get_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01004940 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxPeerLinks, 0, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004941 mask, NL80211_MESHCONF_MAX_PEER_LINKS,
4942 nla_get_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01004943 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxRetries, 0, 16,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004944 mask, NL80211_MESHCONF_MAX_RETRIES,
4945 nla_get_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01004946 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshTTL, 1, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004947 mask, NL80211_MESHCONF_TTL, nla_get_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01004948 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, element_ttl, 1, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004949 mask, NL80211_MESHCONF_ELEMENT_TTL,
4950 nla_get_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01004951 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, auto_open_plinks, 0, 1,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004952 mask, NL80211_MESHCONF_AUTO_OPEN_PLINKS,
4953 nla_get_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01004954 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshNbrOffsetMaxNeighbor,
4955 1, 255, mask,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004956 NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR,
4957 nla_get_u32);
Marco Porschea54fba2013-01-07 16:04:48 +01004958 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPmaxPREQretries, 0, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004959 mask, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES,
4960 nla_get_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01004961 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, path_refresh_time, 1, 65535,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004962 mask, NL80211_MESHCONF_PATH_REFRESH_TIME,
4963 nla_get_u32);
Marco Porschea54fba2013-01-07 16:04:48 +01004964 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, min_discovery_timeout, 1, 65535,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004965 mask, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT,
4966 nla_get_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01004967 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathTimeout,
4968 1, 65535, mask,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004969 NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT,
4970 nla_get_u32);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004971 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPpreqMinInterval,
Marco Porschea54fba2013-01-07 16:04:48 +01004972 1, 65535, mask,
4973 NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004974 nla_get_u16);
Thomas Pedersendca7e942011-11-24 17:15:24 -08004975 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPperrMinInterval,
Marco Porschea54fba2013-01-07 16:04:48 +01004976 1, 65535, mask,
4977 NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004978 nla_get_u16);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004979 FILL_IN_MESH_PARAM_IF_SET(tb, cfg,
Marco Porschea54fba2013-01-07 16:04:48 +01004980 dot11MeshHWMPnetDiameterTraversalTime,
4981 1, 65535, mask,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004982 NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME,
4983 nla_get_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01004984 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRootMode, 0, 4,
4985 mask, NL80211_MESHCONF_HWMP_ROOTMODE,
4986 nla_get_u8);
4987 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRannInterval, 1, 65535,
4988 mask, NL80211_MESHCONF_HWMP_RANN_INTERVAL,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004989 nla_get_u16);
Rui Paulo63c57232009-11-09 23:46:57 +00004990 FILL_IN_MESH_PARAM_IF_SET(tb, cfg,
Marco Porschea54fba2013-01-07 16:04:48 +01004991 dot11MeshGateAnnouncementProtocol, 0, 1,
4992 mask, NL80211_MESHCONF_GATE_ANNOUNCEMENTS,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004993 nla_get_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01004994 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshForwarding, 0, 1,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004995 mask, NL80211_MESHCONF_FORWARDING,
4996 nla_get_u8);
Chun-Yeow Yeoh83374fe2013-07-11 18:24:03 +08004997 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, rssi_threshold, -255, 0,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004998 mask, NL80211_MESHCONF_RSSI_THRESHOLD,
Chun-Yeow Yeoh83374fe2013-07-11 18:24:03 +08004999 nla_get_s32);
Marco Porschea54fba2013-01-07 16:04:48 +01005000 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, ht_opmode, 0, 16,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005001 mask, NL80211_MESHCONF_HT_OPMODE,
5002 nla_get_u16);
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08005003 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathToRootTimeout,
Marco Porschea54fba2013-01-07 16:04:48 +01005004 1, 65535, mask,
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08005005 NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT,
5006 nla_get_u32);
Marco Porschea54fba2013-01-07 16:04:48 +01005007 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMProotInterval, 1, 65535,
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08005008 mask, NL80211_MESHCONF_HWMP_ROOT_INTERVAL,
5009 nla_get_u16);
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +08005010 FILL_IN_MESH_PARAM_IF_SET(tb, cfg,
Marco Porschea54fba2013-01-07 16:04:48 +01005011 dot11MeshHWMPconfirmationInterval,
5012 1, 65535, mask,
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +08005013 NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL,
5014 nla_get_u16);
Marco Porsch3b1c5a52013-01-07 16:04:52 +01005015 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, power_mode,
5016 NL80211_MESH_POWER_ACTIVE,
5017 NL80211_MESH_POWER_MAX,
5018 mask, NL80211_MESHCONF_POWER_MODE,
5019 nla_get_u32);
5020 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshAwakeWindowDuration,
5021 0, 65535, mask,
5022 NL80211_MESHCONF_AWAKE_WINDOW, nla_get_u16);
Colleen Twitty8e7c0532013-06-03 09:53:39 -07005023 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, plink_timeout, 1, 0xffffffff,
5024 mask, NL80211_MESHCONF_PLINK_TIMEOUT,
5025 nla_get_u32);
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005026 if (mask_out)
5027 *mask_out = mask;
Javier Cardonac80d5452010-12-16 17:37:49 -08005028
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005029 return 0;
5030
5031#undef FILL_IN_MESH_PARAM_IF_SET
5032}
5033
Javier Cardonac80d5452010-12-16 17:37:49 -08005034static int nl80211_parse_mesh_setup(struct genl_info *info,
5035 struct mesh_setup *setup)
5036{
Thomas Pedersenbb2798d2013-03-04 13:06:10 -08005037 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Javier Cardonac80d5452010-12-16 17:37:49 -08005038 struct nlattr *tb[NL80211_MESH_SETUP_ATTR_MAX + 1];
5039
5040 if (!info->attrs[NL80211_ATTR_MESH_SETUP])
5041 return -EINVAL;
5042 if (nla_parse_nested(tb, NL80211_MESH_SETUP_ATTR_MAX,
5043 info->attrs[NL80211_ATTR_MESH_SETUP],
5044 nl80211_mesh_setup_params_policy))
5045 return -EINVAL;
5046
Javier Cardonad299a1f2012-03-31 11:31:33 -07005047 if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC])
5048 setup->sync_method =
5049 (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC])) ?
5050 IEEE80211_SYNC_METHOD_VENDOR :
5051 IEEE80211_SYNC_METHOD_NEIGHBOR_OFFSET;
5052
Javier Cardonac80d5452010-12-16 17:37:49 -08005053 if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL])
5054 setup->path_sel_proto =
5055 (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL])) ?
5056 IEEE80211_PATH_PROTOCOL_VENDOR :
5057 IEEE80211_PATH_PROTOCOL_HWMP;
5058
5059 if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC])
5060 setup->path_metric =
5061 (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC])) ?
5062 IEEE80211_PATH_METRIC_VENDOR :
5063 IEEE80211_PATH_METRIC_AIRTIME;
5064
Javier Cardona581a8b02011-04-07 15:08:27 -07005065
5066 if (tb[NL80211_MESH_SETUP_IE]) {
Javier Cardonac80d5452010-12-16 17:37:49 -08005067 struct nlattr *ieattr =
Javier Cardona581a8b02011-04-07 15:08:27 -07005068 tb[NL80211_MESH_SETUP_IE];
Javier Cardonac80d5452010-12-16 17:37:49 -08005069 if (!is_valid_ie_attr(ieattr))
5070 return -EINVAL;
Javier Cardona581a8b02011-04-07 15:08:27 -07005071 setup->ie = nla_data(ieattr);
5072 setup->ie_len = nla_len(ieattr);
Javier Cardonac80d5452010-12-16 17:37:49 -08005073 }
Thomas Pedersenbb2798d2013-03-04 13:06:10 -08005074 if (tb[NL80211_MESH_SETUP_USERSPACE_MPM] &&
5075 !(rdev->wiphy.features & NL80211_FEATURE_USERSPACE_MPM))
5076 return -EINVAL;
5077 setup->user_mpm = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_MPM]);
Javier Cardonab130e5c2011-05-03 16:57:07 -07005078 setup->is_authenticated = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AUTH]);
5079 setup->is_secure = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AMPE]);
Thomas Pedersenbb2798d2013-03-04 13:06:10 -08005080 if (setup->is_secure)
5081 setup->user_mpm = true;
Javier Cardonac80d5452010-12-16 17:37:49 -08005082
Colleen Twitty6e16d902013-05-08 11:45:59 -07005083 if (tb[NL80211_MESH_SETUP_AUTH_PROTOCOL]) {
5084 if (!setup->user_mpm)
5085 return -EINVAL;
5086 setup->auth_id =
5087 nla_get_u8(tb[NL80211_MESH_SETUP_AUTH_PROTOCOL]);
5088 }
5089
Javier Cardonac80d5452010-12-16 17:37:49 -08005090 return 0;
5091}
5092
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005093static int nl80211_update_mesh_config(struct sk_buff *skb,
Johannes Berg29cbe682010-12-03 09:20:44 +01005094 struct genl_info *info)
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005095{
5096 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5097 struct net_device *dev = info->user_ptr[1];
Johannes Berg29cbe682010-12-03 09:20:44 +01005098 struct wireless_dev *wdev = dev->ieee80211_ptr;
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005099 struct mesh_config cfg;
5100 u32 mask;
5101 int err;
5102
Johannes Berg29cbe682010-12-03 09:20:44 +01005103 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT)
5104 return -EOPNOTSUPP;
5105
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005106 if (!rdev->ops->update_mesh_config)
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005107 return -EOPNOTSUPP;
5108
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005109 err = nl80211_parse_mesh_config(info, &cfg, &mask);
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005110 if (err)
5111 return err;
5112
Johannes Berg29cbe682010-12-03 09:20:44 +01005113 wdev_lock(wdev);
5114 if (!wdev->mesh_id_len)
5115 err = -ENOLINK;
5116
5117 if (!err)
Hila Gonene35e4d22012-06-27 17:19:42 +03005118 err = rdev_update_mesh_config(rdev, dev, mask, &cfg);
Johannes Berg29cbe682010-12-03 09:20:44 +01005119
5120 wdev_unlock(wdev);
5121
5122 return err;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005123}
5124
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005125static int nl80211_get_reg(struct sk_buff *skb, struct genl_info *info)
5126{
Johannes Berg458f4f92012-12-06 15:47:38 +01005127 const struct ieee80211_regdomain *regdom;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005128 struct sk_buff *msg;
5129 void *hdr = NULL;
5130 struct nlattr *nl_reg_rules;
5131 unsigned int i;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005132
5133 if (!cfg80211_regdomain)
Johannes Berg5fe231e2013-05-08 21:45:15 +02005134 return -EINVAL;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005135
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07005136 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg5fe231e2013-05-08 21:45:15 +02005137 if (!msg)
5138 return -ENOBUFS;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005139
Eric W. Biederman15e47302012-09-07 20:12:54 +00005140 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005141 NL80211_CMD_GET_REG);
5142 if (!hdr)
Julia Lawallefe1cf02011-01-28 15:17:11 +01005143 goto put_failure;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005144
Luis R. Rodriguez57b5ce02012-07-12 11:49:18 -07005145 if (reg_last_request_cell_base() &&
5146 nla_put_u32(msg, NL80211_ATTR_USER_REG_HINT_TYPE,
5147 NL80211_USER_REG_HINT_CELL_BASE))
5148 goto nla_put_failure;
5149
Johannes Berg458f4f92012-12-06 15:47:38 +01005150 rcu_read_lock();
5151 regdom = rcu_dereference(cfg80211_regdomain);
5152
5153 if (nla_put_string(msg, NL80211_ATTR_REG_ALPHA2, regdom->alpha2) ||
5154 (regdom->dfs_region &&
5155 nla_put_u8(msg, NL80211_ATTR_DFS_REGION, regdom->dfs_region)))
5156 goto nla_put_failure_rcu;
5157
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005158 nl_reg_rules = nla_nest_start(msg, NL80211_ATTR_REG_RULES);
5159 if (!nl_reg_rules)
Johannes Berg458f4f92012-12-06 15:47:38 +01005160 goto nla_put_failure_rcu;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005161
Johannes Berg458f4f92012-12-06 15:47:38 +01005162 for (i = 0; i < regdom->n_reg_rules; i++) {
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005163 struct nlattr *nl_reg_rule;
5164 const struct ieee80211_reg_rule *reg_rule;
5165 const struct ieee80211_freq_range *freq_range;
5166 const struct ieee80211_power_rule *power_rule;
Janusz Dziedzic97524822014-01-30 09:52:20 +01005167 unsigned int max_bandwidth_khz;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005168
Johannes Berg458f4f92012-12-06 15:47:38 +01005169 reg_rule = &regdom->reg_rules[i];
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005170 freq_range = &reg_rule->freq_range;
5171 power_rule = &reg_rule->power_rule;
5172
5173 nl_reg_rule = nla_nest_start(msg, i);
5174 if (!nl_reg_rule)
Johannes Berg458f4f92012-12-06 15:47:38 +01005175 goto nla_put_failure_rcu;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005176
Janusz Dziedzic97524822014-01-30 09:52:20 +01005177 max_bandwidth_khz = freq_range->max_bandwidth_khz;
5178 if (!max_bandwidth_khz)
5179 max_bandwidth_khz = reg_get_max_bandwidth(regdom,
5180 reg_rule);
5181
David S. Miller9360ffd2012-03-29 04:41:26 -04005182 if (nla_put_u32(msg, NL80211_ATTR_REG_RULE_FLAGS,
5183 reg_rule->flags) ||
5184 nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_START,
5185 freq_range->start_freq_khz) ||
5186 nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_END,
5187 freq_range->end_freq_khz) ||
5188 nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_MAX_BW,
Janusz Dziedzic97524822014-01-30 09:52:20 +01005189 max_bandwidth_khz) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04005190 nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN,
5191 power_rule->max_antenna_gain) ||
5192 nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_EIRP,
Janusz Dziedzic089027e2014-02-21 19:46:12 +01005193 power_rule->max_eirp) ||
5194 nla_put_u32(msg, NL80211_ATTR_DFS_CAC_TIME,
5195 reg_rule->dfs_cac_ms))
Johannes Berg458f4f92012-12-06 15:47:38 +01005196 goto nla_put_failure_rcu;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005197
5198 nla_nest_end(msg, nl_reg_rule);
5199 }
Johannes Berg458f4f92012-12-06 15:47:38 +01005200 rcu_read_unlock();
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005201
5202 nla_nest_end(msg, nl_reg_rules);
5203
5204 genlmsg_end(msg, hdr);
Johannes Berg5fe231e2013-05-08 21:45:15 +02005205 return genlmsg_reply(msg, info);
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005206
Johannes Berg458f4f92012-12-06 15:47:38 +01005207nla_put_failure_rcu:
5208 rcu_read_unlock();
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005209nla_put_failure:
5210 genlmsg_cancel(msg, hdr);
Julia Lawallefe1cf02011-01-28 15:17:11 +01005211put_failure:
Yuri Ershovd080e272010-06-29 15:08:07 +04005212 nlmsg_free(msg);
Johannes Berg5fe231e2013-05-08 21:45:15 +02005213 return -EMSGSIZE;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005214}
5215
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005216static int nl80211_set_reg(struct sk_buff *skb, struct genl_info *info)
5217{
5218 struct nlattr *tb[NL80211_REG_RULE_ATTR_MAX + 1];
5219 struct nlattr *nl_reg_rule;
5220 char *alpha2 = NULL;
5221 int rem_reg_rules = 0, r = 0;
5222 u32 num_rules = 0, rule_idx = 0, size_of_regd;
Luis R. Rodriguez4c7d3982013-11-13 18:54:02 +01005223 enum nl80211_dfs_regions dfs_region = NL80211_DFS_UNSET;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005224 struct ieee80211_regdomain *rd = NULL;
5225
5226 if (!info->attrs[NL80211_ATTR_REG_ALPHA2])
5227 return -EINVAL;
5228
5229 if (!info->attrs[NL80211_ATTR_REG_RULES])
5230 return -EINVAL;
5231
5232 alpha2 = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]);
5233
Luis R. Rodriguez8b60b072011-10-11 10:59:02 -07005234 if (info->attrs[NL80211_ATTR_DFS_REGION])
5235 dfs_region = nla_get_u8(info->attrs[NL80211_ATTR_DFS_REGION]);
5236
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005237 nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES],
Johannes Berg1a919312012-12-03 17:21:11 +01005238 rem_reg_rules) {
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005239 num_rules++;
5240 if (num_rules > NL80211_MAX_SUPP_REG_RULES)
Luis R. Rodriguez4776c6e2009-05-13 17:04:39 -04005241 return -EINVAL;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005242 }
5243
Luis R. Rodrigueze4387682013-11-05 09:18:01 -08005244 if (!reg_is_valid_request(alpha2))
5245 return -EINVAL;
5246
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005247 size_of_regd = sizeof(struct ieee80211_regdomain) +
Johannes Berg1a919312012-12-03 17:21:11 +01005248 num_rules * sizeof(struct ieee80211_reg_rule);
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005249
5250 rd = kzalloc(size_of_regd, GFP_KERNEL);
Johannes Berg6913b492012-12-04 00:48:59 +01005251 if (!rd)
5252 return -ENOMEM;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005253
5254 rd->n_reg_rules = num_rules;
5255 rd->alpha2[0] = alpha2[0];
5256 rd->alpha2[1] = alpha2[1];
5257
Luis R. Rodriguez8b60b072011-10-11 10:59:02 -07005258 /*
5259 * Disable DFS master mode if the DFS region was
5260 * not supported or known on this kernel.
5261 */
5262 if (reg_supported_dfs_region(dfs_region))
5263 rd->dfs_region = dfs_region;
5264
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005265 nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES],
Johannes Berg1a919312012-12-03 17:21:11 +01005266 rem_reg_rules) {
Johannes Bergae811e22014-01-24 10:17:47 +01005267 r = nla_parse(tb, NL80211_REG_RULE_ATTR_MAX,
5268 nla_data(nl_reg_rule), nla_len(nl_reg_rule),
5269 reg_rule_policy);
5270 if (r)
5271 goto bad_reg;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005272 r = parse_reg_rule(tb, &rd->reg_rules[rule_idx]);
5273 if (r)
5274 goto bad_reg;
5275
5276 rule_idx++;
5277
Luis R. Rodriguezd0e18f82009-05-13 17:04:40 -04005278 if (rule_idx > NL80211_MAX_SUPP_REG_RULES) {
5279 r = -EINVAL;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005280 goto bad_reg;
Luis R. Rodriguezd0e18f82009-05-13 17:04:40 -04005281 }
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005282 }
5283
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005284 r = set_regdom(rd);
Johannes Berg6913b492012-12-04 00:48:59 +01005285 /* set_regdom took ownership */
Johannes Berg1a919312012-12-03 17:21:11 +01005286 rd = NULL;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005287
Johannes Bergd2372b32008-10-24 20:32:20 +02005288 bad_reg:
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005289 kfree(rd);
Luis R. Rodriguezd0e18f82009-05-13 17:04:40 -04005290 return r;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005291}
5292
Johannes Berg83f5e2c2009-06-17 17:41:49 +02005293static int validate_scan_freqs(struct nlattr *freqs)
5294{
5295 struct nlattr *attr1, *attr2;
5296 int n_channels = 0, tmp1, tmp2;
5297
5298 nla_for_each_nested(attr1, freqs, tmp1) {
5299 n_channels++;
5300 /*
5301 * Some hardware has a limited channel list for
5302 * scanning, and it is pretty much nonsensical
5303 * to scan for a channel twice, so disallow that
5304 * and don't require drivers to check that the
5305 * channel list they get isn't longer than what
5306 * they can scan, as long as they can scan all
5307 * the channels they registered at once.
5308 */
5309 nla_for_each_nested(attr2, freqs, tmp2)
5310 if (attr1 != attr2 &&
5311 nla_get_u32(attr1) == nla_get_u32(attr2))
5312 return 0;
5313 }
5314
5315 return n_channels;
5316}
5317
Johannes Berg2a519312009-02-10 21:25:55 +01005318static int nl80211_trigger_scan(struct sk_buff *skb, struct genl_info *info)
5319{
Johannes Berg4c476992010-10-04 21:36:35 +02005320 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Bergfd014282012-06-18 19:17:03 +02005321 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg2a519312009-02-10 21:25:55 +01005322 struct cfg80211_scan_request *request;
Johannes Berg2a519312009-02-10 21:25:55 +01005323 struct nlattr *attr;
5324 struct wiphy *wiphy;
Johannes Berg83f5e2c2009-06-17 17:41:49 +02005325 int err, tmp, n_ssids = 0, n_channels, i;
Jouni Malinen70692ad2009-02-16 19:39:13 +02005326 size_t ie_len;
Johannes Berg2a519312009-02-10 21:25:55 +01005327
Johannes Bergf4a11bb2009-03-27 12:40:28 +01005328 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
5329 return -EINVAL;
5330
Johannes Berg79c97e92009-07-07 03:56:12 +02005331 wiphy = &rdev->wiphy;
Johannes Berg2a519312009-02-10 21:25:55 +01005332
Johannes Berg4c476992010-10-04 21:36:35 +02005333 if (!rdev->ops->scan)
5334 return -EOPNOTSUPP;
Johannes Berg2a519312009-02-10 21:25:55 +01005335
Johannes Bergf9d15d12014-01-22 11:14:19 +02005336 if (rdev->scan_req || rdev->scan_msg) {
Johannes Bergf9f47522013-03-19 15:04:07 +01005337 err = -EBUSY;
5338 goto unlock;
5339 }
Johannes Berg2a519312009-02-10 21:25:55 +01005340
5341 if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
Johannes Berg83f5e2c2009-06-17 17:41:49 +02005342 n_channels = validate_scan_freqs(
5343 info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]);
Johannes Bergf9f47522013-03-19 15:04:07 +01005344 if (!n_channels) {
5345 err = -EINVAL;
5346 goto unlock;
5347 }
Johannes Berg2a519312009-02-10 21:25:55 +01005348 } else {
Ilan Peerbdfbec22014-01-09 11:37:23 +02005349 n_channels = ieee80211_get_num_supported_channels(wiphy);
Johannes Berg2a519312009-02-10 21:25:55 +01005350 }
5351
5352 if (info->attrs[NL80211_ATTR_SCAN_SSIDS])
5353 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp)
5354 n_ssids++;
5355
Johannes Bergf9f47522013-03-19 15:04:07 +01005356 if (n_ssids > wiphy->max_scan_ssids) {
5357 err = -EINVAL;
5358 goto unlock;
5359 }
Johannes Berg2a519312009-02-10 21:25:55 +01005360
Jouni Malinen70692ad2009-02-16 19:39:13 +02005361 if (info->attrs[NL80211_ATTR_IE])
5362 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
5363 else
5364 ie_len = 0;
5365
Johannes Bergf9f47522013-03-19 15:04:07 +01005366 if (ie_len > wiphy->max_scan_ie_len) {
5367 err = -EINVAL;
5368 goto unlock;
5369 }
Johannes Berg18a83652009-03-31 12:12:05 +02005370
Johannes Berg2a519312009-02-10 21:25:55 +01005371 request = kzalloc(sizeof(*request)
Luciano Coelhoa2cd43c2011-05-18 11:42:03 +03005372 + sizeof(*request->ssids) * n_ssids
5373 + sizeof(*request->channels) * n_channels
Jouni Malinen70692ad2009-02-16 19:39:13 +02005374 + ie_len, GFP_KERNEL);
Johannes Bergf9f47522013-03-19 15:04:07 +01005375 if (!request) {
5376 err = -ENOMEM;
5377 goto unlock;
5378 }
Johannes Berg2a519312009-02-10 21:25:55 +01005379
Johannes Berg2a519312009-02-10 21:25:55 +01005380 if (n_ssids)
Johannes Berg5ba63532009-08-07 17:54:07 +02005381 request->ssids = (void *)&request->channels[n_channels];
Johannes Berg2a519312009-02-10 21:25:55 +01005382 request->n_ssids = n_ssids;
Jouni Malinen70692ad2009-02-16 19:39:13 +02005383 if (ie_len) {
5384 if (request->ssids)
5385 request->ie = (void *)(request->ssids + n_ssids);
5386 else
5387 request->ie = (void *)(request->channels + n_channels);
5388 }
Johannes Berg2a519312009-02-10 21:25:55 +01005389
Johannes Berg584991d2009-11-02 13:32:03 +01005390 i = 0;
Johannes Berg2a519312009-02-10 21:25:55 +01005391 if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
5392 /* user specified, bail out if channel not found */
Johannes Berg2a519312009-02-10 21:25:55 +01005393 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_FREQUENCIES], tmp) {
Johannes Berg584991d2009-11-02 13:32:03 +01005394 struct ieee80211_channel *chan;
5395
5396 chan = ieee80211_get_channel(wiphy, nla_get_u32(attr));
5397
5398 if (!chan) {
Johannes Berg2a519312009-02-10 21:25:55 +01005399 err = -EINVAL;
5400 goto out_free;
5401 }
Johannes Berg584991d2009-11-02 13:32:03 +01005402
5403 /* ignore disabled channels */
5404 if (chan->flags & IEEE80211_CHAN_DISABLED)
5405 continue;
5406
5407 request->channels[i] = chan;
Johannes Berg2a519312009-02-10 21:25:55 +01005408 i++;
5409 }
5410 } else {
Johannes Berg34850ab2011-07-18 18:08:35 +02005411 enum ieee80211_band band;
5412
Johannes Berg2a519312009-02-10 21:25:55 +01005413 /* all channels */
Johannes Berg2a519312009-02-10 21:25:55 +01005414 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
5415 int j;
5416 if (!wiphy->bands[band])
5417 continue;
5418 for (j = 0; j < wiphy->bands[band]->n_channels; j++) {
Johannes Berg584991d2009-11-02 13:32:03 +01005419 struct ieee80211_channel *chan;
5420
5421 chan = &wiphy->bands[band]->channels[j];
5422
5423 if (chan->flags & IEEE80211_CHAN_DISABLED)
5424 continue;
5425
5426 request->channels[i] = chan;
Johannes Berg2a519312009-02-10 21:25:55 +01005427 i++;
5428 }
5429 }
5430 }
5431
Johannes Berg584991d2009-11-02 13:32:03 +01005432 if (!i) {
5433 err = -EINVAL;
5434 goto out_free;
5435 }
5436
5437 request->n_channels = i;
5438
Johannes Berg2a519312009-02-10 21:25:55 +01005439 i = 0;
5440 if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) {
5441 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) {
Luciano Coelho57a27e12011-06-07 20:42:26 +03005442 if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) {
Johannes Berg2a519312009-02-10 21:25:55 +01005443 err = -EINVAL;
5444 goto out_free;
5445 }
Luciano Coelho57a27e12011-06-07 20:42:26 +03005446 request->ssids[i].ssid_len = nla_len(attr);
Johannes Berg2a519312009-02-10 21:25:55 +01005447 memcpy(request->ssids[i].ssid, nla_data(attr), nla_len(attr));
Johannes Berg2a519312009-02-10 21:25:55 +01005448 i++;
5449 }
5450 }
5451
Jouni Malinen70692ad2009-02-16 19:39:13 +02005452 if (info->attrs[NL80211_ATTR_IE]) {
5453 request->ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Johannes Bergde95a542009-04-01 11:58:36 +02005454 memcpy((void *)request->ie,
5455 nla_data(info->attrs[NL80211_ATTR_IE]),
Jouni Malinen70692ad2009-02-16 19:39:13 +02005456 request->ie_len);
5457 }
5458
Johannes Berg34850ab2011-07-18 18:08:35 +02005459 for (i = 0; i < IEEE80211_NUM_BANDS; i++)
Johannes Berga401d2b2011-07-20 00:52:16 +02005460 if (wiphy->bands[i])
5461 request->rates[i] =
5462 (1 << wiphy->bands[i]->n_bitrates) - 1;
Johannes Berg34850ab2011-07-18 18:08:35 +02005463
5464 if (info->attrs[NL80211_ATTR_SCAN_SUPP_RATES]) {
5465 nla_for_each_nested(attr,
5466 info->attrs[NL80211_ATTR_SCAN_SUPP_RATES],
5467 tmp) {
5468 enum ieee80211_band band = nla_type(attr);
5469
Dan Carpenter84404622011-07-29 11:52:18 +03005470 if (band < 0 || band >= IEEE80211_NUM_BANDS) {
Johannes Berg34850ab2011-07-18 18:08:35 +02005471 err = -EINVAL;
5472 goto out_free;
5473 }
Felix Fietkau1b09cd82013-11-20 19:40:41 +01005474
5475 if (!wiphy->bands[band])
5476 continue;
5477
Johannes Berg34850ab2011-07-18 18:08:35 +02005478 err = ieee80211_get_ratemask(wiphy->bands[band],
5479 nla_data(attr),
5480 nla_len(attr),
5481 &request->rates[band]);
5482 if (err)
5483 goto out_free;
5484 }
5485 }
5486
Sam Leffler46856bb2012-10-11 21:03:32 -07005487 if (info->attrs[NL80211_ATTR_SCAN_FLAGS]) {
Sam Lefflered4737712012-10-11 21:03:31 -07005488 request->flags = nla_get_u32(
5489 info->attrs[NL80211_ATTR_SCAN_FLAGS]);
Johannes Berg00c3a6e2013-10-26 17:14:38 +02005490 if ((request->flags & NL80211_SCAN_FLAG_LOW_PRIORITY) &&
5491 !(wiphy->features & NL80211_FEATURE_LOW_PRIORITY_SCAN)) {
Sam Leffler46856bb2012-10-11 21:03:32 -07005492 err = -EOPNOTSUPP;
5493 goto out_free;
5494 }
5495 }
Sam Lefflered4737712012-10-11 21:03:31 -07005496
Rajkumar Manoharane9f935e2011-09-25 14:53:30 +05305497 request->no_cck =
5498 nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]);
5499
Johannes Bergfd014282012-06-18 19:17:03 +02005500 request->wdev = wdev;
Johannes Berg79c97e92009-07-07 03:56:12 +02005501 request->wiphy = &rdev->wiphy;
Sam Leffler15d60302012-10-11 21:03:34 -07005502 request->scan_start = jiffies;
Johannes Berg2a519312009-02-10 21:25:55 +01005503
Johannes Berg79c97e92009-07-07 03:56:12 +02005504 rdev->scan_req = request;
Hila Gonene35e4d22012-06-27 17:19:42 +03005505 err = rdev_scan(rdev, request);
Johannes Berg2a519312009-02-10 21:25:55 +01005506
Johannes Berg463d0182009-07-14 00:33:35 +02005507 if (!err) {
Johannes Bergfd014282012-06-18 19:17:03 +02005508 nl80211_send_scan_start(rdev, wdev);
5509 if (wdev->netdev)
5510 dev_hold(wdev->netdev);
Johannes Berg4c476992010-10-04 21:36:35 +02005511 } else {
Johannes Berg2a519312009-02-10 21:25:55 +01005512 out_free:
Johannes Berg79c97e92009-07-07 03:56:12 +02005513 rdev->scan_req = NULL;
Johannes Berg2a519312009-02-10 21:25:55 +01005514 kfree(request);
5515 }
Johannes Berg3b858752009-03-12 09:55:09 +01005516
Johannes Bergf9f47522013-03-19 15:04:07 +01005517 unlock:
Johannes Berg2a519312009-02-10 21:25:55 +01005518 return err;
5519}
5520
Luciano Coelho807f8a82011-05-11 17:09:35 +03005521static int nl80211_start_sched_scan(struct sk_buff *skb,
5522 struct genl_info *info)
5523{
5524 struct cfg80211_sched_scan_request *request;
5525 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5526 struct net_device *dev = info->user_ptr[1];
Luciano Coelho807f8a82011-05-11 17:09:35 +03005527 struct nlattr *attr;
5528 struct wiphy *wiphy;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005529 int err, tmp, n_ssids = 0, n_match_sets = 0, n_channels, i;
Luciano Coelhobbe6ad62011-05-11 17:09:37 +03005530 u32 interval;
Luciano Coelho807f8a82011-05-11 17:09:35 +03005531 enum ieee80211_band band;
5532 size_t ie_len;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005533 struct nlattr *tb[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1];
Johannes Bergea73cbc2014-01-24 10:53:53 +01005534 s32 default_match_rssi = NL80211_SCAN_RSSI_THOLD_OFF;
Luciano Coelho807f8a82011-05-11 17:09:35 +03005535
5536 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) ||
5537 !rdev->ops->sched_scan_start)
5538 return -EOPNOTSUPP;
5539
5540 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
5541 return -EINVAL;
5542
Luciano Coelhobbe6ad62011-05-11 17:09:37 +03005543 if (!info->attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL])
5544 return -EINVAL;
5545
5546 interval = nla_get_u32(info->attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]);
5547 if (interval == 0)
5548 return -EINVAL;
5549
Luciano Coelho807f8a82011-05-11 17:09:35 +03005550 wiphy = &rdev->wiphy;
5551
5552 if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
5553 n_channels = validate_scan_freqs(
5554 info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]);
5555 if (!n_channels)
5556 return -EINVAL;
5557 } else {
Ilan Peerbdfbec22014-01-09 11:37:23 +02005558 n_channels = ieee80211_get_num_supported_channels(wiphy);
Luciano Coelho807f8a82011-05-11 17:09:35 +03005559 }
5560
5561 if (info->attrs[NL80211_ATTR_SCAN_SSIDS])
5562 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS],
5563 tmp)
5564 n_ssids++;
5565
Luciano Coelho93b6aa62011-07-13 14:57:28 +03005566 if (n_ssids > wiphy->max_sched_scan_ssids)
Luciano Coelho807f8a82011-05-11 17:09:35 +03005567 return -EINVAL;
5568
Johannes Bergea73cbc2014-01-24 10:53:53 +01005569 /*
5570 * First, count the number of 'real' matchsets. Due to an issue with
5571 * the old implementation, matchsets containing only the RSSI attribute
5572 * (NL80211_SCHED_SCAN_MATCH_ATTR_RSSI) are considered as the 'default'
5573 * RSSI for all matchsets, rather than their own matchset for reporting
5574 * all APs with a strong RSSI. This is needed to be compatible with
5575 * older userspace that treated a matchset with only the RSSI as the
5576 * global RSSI for all other matchsets - if there are other matchsets.
5577 */
5578 if (info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) {
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005579 nla_for_each_nested(attr,
5580 info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH],
Johannes Bergea73cbc2014-01-24 10:53:53 +01005581 tmp) {
5582 struct nlattr *rssi;
5583
5584 err = nla_parse(tb, NL80211_SCHED_SCAN_MATCH_ATTR_MAX,
5585 nla_data(attr), nla_len(attr),
5586 nl80211_match_policy);
5587 if (err)
5588 return err;
5589 /* add other standalone attributes here */
5590 if (tb[NL80211_SCHED_SCAN_MATCH_ATTR_SSID]) {
5591 n_match_sets++;
5592 continue;
5593 }
5594 rssi = tb[NL80211_SCHED_SCAN_MATCH_ATTR_RSSI];
5595 if (rssi)
5596 default_match_rssi = nla_get_s32(rssi);
5597 }
5598 }
5599
5600 /* However, if there's no other matchset, add the RSSI one */
5601 if (!n_match_sets && default_match_rssi != NL80211_SCAN_RSSI_THOLD_OFF)
5602 n_match_sets = 1;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005603
5604 if (n_match_sets > wiphy->max_match_sets)
5605 return -EINVAL;
5606
Luciano Coelho807f8a82011-05-11 17:09:35 +03005607 if (info->attrs[NL80211_ATTR_IE])
5608 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
5609 else
5610 ie_len = 0;
5611
Luciano Coelho5a865ba2011-07-13 14:57:29 +03005612 if (ie_len > wiphy->max_sched_scan_ie_len)
Luciano Coelho807f8a82011-05-11 17:09:35 +03005613 return -EINVAL;
5614
Luciano Coelhoc10841c2011-06-30 08:32:41 +03005615 if (rdev->sched_scan_req) {
5616 err = -EINPROGRESS;
5617 goto out;
5618 }
5619
Luciano Coelho807f8a82011-05-11 17:09:35 +03005620 request = kzalloc(sizeof(*request)
Luciano Coelhoa2cd43c2011-05-18 11:42:03 +03005621 + sizeof(*request->ssids) * n_ssids
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005622 + sizeof(*request->match_sets) * n_match_sets
Luciano Coelhoa2cd43c2011-05-18 11:42:03 +03005623 + sizeof(*request->channels) * n_channels
Luciano Coelho807f8a82011-05-11 17:09:35 +03005624 + ie_len, GFP_KERNEL);
Luciano Coelhoc10841c2011-06-30 08:32:41 +03005625 if (!request) {
5626 err = -ENOMEM;
5627 goto out;
5628 }
Luciano Coelho807f8a82011-05-11 17:09:35 +03005629
5630 if (n_ssids)
5631 request->ssids = (void *)&request->channels[n_channels];
5632 request->n_ssids = n_ssids;
5633 if (ie_len) {
5634 if (request->ssids)
5635 request->ie = (void *)(request->ssids + n_ssids);
5636 else
5637 request->ie = (void *)(request->channels + n_channels);
5638 }
5639
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005640 if (n_match_sets) {
5641 if (request->ie)
5642 request->match_sets = (void *)(request->ie + ie_len);
5643 else if (request->ssids)
5644 request->match_sets =
5645 (void *)(request->ssids + n_ssids);
5646 else
5647 request->match_sets =
5648 (void *)(request->channels + n_channels);
5649 }
5650 request->n_match_sets = n_match_sets;
5651
Luciano Coelho807f8a82011-05-11 17:09:35 +03005652 i = 0;
5653 if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
5654 /* user specified, bail out if channel not found */
5655 nla_for_each_nested(attr,
5656 info->attrs[NL80211_ATTR_SCAN_FREQUENCIES],
5657 tmp) {
5658 struct ieee80211_channel *chan;
5659
5660 chan = ieee80211_get_channel(wiphy, nla_get_u32(attr));
5661
5662 if (!chan) {
5663 err = -EINVAL;
5664 goto out_free;
5665 }
5666
5667 /* ignore disabled channels */
5668 if (chan->flags & IEEE80211_CHAN_DISABLED)
5669 continue;
5670
5671 request->channels[i] = chan;
5672 i++;
5673 }
5674 } else {
5675 /* all channels */
5676 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
5677 int j;
5678 if (!wiphy->bands[band])
5679 continue;
5680 for (j = 0; j < wiphy->bands[band]->n_channels; j++) {
5681 struct ieee80211_channel *chan;
5682
5683 chan = &wiphy->bands[band]->channels[j];
5684
5685 if (chan->flags & IEEE80211_CHAN_DISABLED)
5686 continue;
5687
5688 request->channels[i] = chan;
5689 i++;
5690 }
5691 }
5692 }
5693
5694 if (!i) {
5695 err = -EINVAL;
5696 goto out_free;
5697 }
5698
5699 request->n_channels = i;
5700
5701 i = 0;
5702 if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) {
5703 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS],
5704 tmp) {
Luciano Coelho57a27e12011-06-07 20:42:26 +03005705 if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) {
Luciano Coelho807f8a82011-05-11 17:09:35 +03005706 err = -EINVAL;
5707 goto out_free;
5708 }
Luciano Coelho57a27e12011-06-07 20:42:26 +03005709 request->ssids[i].ssid_len = nla_len(attr);
Luciano Coelho807f8a82011-05-11 17:09:35 +03005710 memcpy(request->ssids[i].ssid, nla_data(attr),
5711 nla_len(attr));
Luciano Coelho807f8a82011-05-11 17:09:35 +03005712 i++;
5713 }
5714 }
5715
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005716 i = 0;
5717 if (info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) {
5718 nla_for_each_nested(attr,
5719 info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH],
5720 tmp) {
Thomas Pedersen88e920b2012-06-21 11:09:54 -07005721 struct nlattr *ssid, *rssi;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005722
Johannes Bergae811e22014-01-24 10:17:47 +01005723 err = nla_parse(tb, NL80211_SCHED_SCAN_MATCH_ATTR_MAX,
5724 nla_data(attr), nla_len(attr),
5725 nl80211_match_policy);
5726 if (err)
5727 goto out_free;
Johannes Berg4a4ab0d2012-06-13 11:17:11 +02005728 ssid = tb[NL80211_SCHED_SCAN_MATCH_ATTR_SSID];
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005729 if (ssid) {
Johannes Bergea73cbc2014-01-24 10:53:53 +01005730 if (WARN_ON(i >= n_match_sets)) {
5731 /* this indicates a programming error,
5732 * the loop above should have verified
5733 * things properly
5734 */
5735 err = -EINVAL;
5736 goto out_free;
5737 }
5738
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005739 if (nla_len(ssid) > IEEE80211_MAX_SSID_LEN) {
5740 err = -EINVAL;
5741 goto out_free;
5742 }
5743 memcpy(request->match_sets[i].ssid.ssid,
5744 nla_data(ssid), nla_len(ssid));
5745 request->match_sets[i].ssid.ssid_len =
5746 nla_len(ssid);
Johannes Bergea73cbc2014-01-24 10:53:53 +01005747 /* special attribute - old implemenation w/a */
5748 request->match_sets[i].rssi_thold =
5749 default_match_rssi;
5750 rssi = tb[NL80211_SCHED_SCAN_MATCH_ATTR_RSSI];
5751 if (rssi)
5752 request->match_sets[i].rssi_thold =
5753 nla_get_s32(rssi);
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005754 }
5755 i++;
5756 }
Johannes Bergea73cbc2014-01-24 10:53:53 +01005757
5758 /* there was no other matchset, so the RSSI one is alone */
5759 if (i == 0)
5760 request->match_sets[0].rssi_thold = default_match_rssi;
5761
5762 request->min_rssi_thold = INT_MAX;
5763 for (i = 0; i < n_match_sets; i++)
5764 request->min_rssi_thold =
5765 min(request->match_sets[i].rssi_thold,
5766 request->min_rssi_thold);
5767 } else {
5768 request->min_rssi_thold = NL80211_SCAN_RSSI_THOLD_OFF;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005769 }
5770
Johannes Berg9900e482014-02-04 21:01:25 +01005771 if (ie_len) {
5772 request->ie_len = ie_len;
Luciano Coelho807f8a82011-05-11 17:09:35 +03005773 memcpy((void *)request->ie,
5774 nla_data(info->attrs[NL80211_ATTR_IE]),
5775 request->ie_len);
5776 }
5777
Sam Leffler46856bb2012-10-11 21:03:32 -07005778 if (info->attrs[NL80211_ATTR_SCAN_FLAGS]) {
Sam Lefflered4737712012-10-11 21:03:31 -07005779 request->flags = nla_get_u32(
5780 info->attrs[NL80211_ATTR_SCAN_FLAGS]);
Johannes Berg00c3a6e2013-10-26 17:14:38 +02005781 if ((request->flags & NL80211_SCAN_FLAG_LOW_PRIORITY) &&
5782 !(wiphy->features & NL80211_FEATURE_LOW_PRIORITY_SCAN)) {
Sam Leffler46856bb2012-10-11 21:03:32 -07005783 err = -EOPNOTSUPP;
5784 goto out_free;
5785 }
5786 }
Sam Lefflered4737712012-10-11 21:03:31 -07005787
Luciano Coelho807f8a82011-05-11 17:09:35 +03005788 request->dev = dev;
5789 request->wiphy = &rdev->wiphy;
Luciano Coelhobbe6ad62011-05-11 17:09:37 +03005790 request->interval = interval;
Sam Leffler15d60302012-10-11 21:03:34 -07005791 request->scan_start = jiffies;
Luciano Coelho807f8a82011-05-11 17:09:35 +03005792
Hila Gonene35e4d22012-06-27 17:19:42 +03005793 err = rdev_sched_scan_start(rdev, dev, request);
Luciano Coelho807f8a82011-05-11 17:09:35 +03005794 if (!err) {
5795 rdev->sched_scan_req = request;
5796 nl80211_send_sched_scan(rdev, dev,
5797 NL80211_CMD_START_SCHED_SCAN);
5798 goto out;
5799 }
5800
5801out_free:
5802 kfree(request);
5803out:
5804 return err;
5805}
5806
5807static int nl80211_stop_sched_scan(struct sk_buff *skb,
5808 struct genl_info *info)
5809{
5810 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5811
5812 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) ||
5813 !rdev->ops->sched_scan_stop)
5814 return -EOPNOTSUPP;
5815
Johannes Berg5fe231e2013-05-08 21:45:15 +02005816 return __cfg80211_stop_sched_scan(rdev, false);
Luciano Coelho807f8a82011-05-11 17:09:35 +03005817}
5818
Simon Wunderlich04f39042013-02-08 18:16:19 +01005819static int nl80211_start_radar_detection(struct sk_buff *skb,
5820 struct genl_info *info)
5821{
5822 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5823 struct net_device *dev = info->user_ptr[1];
5824 struct wireless_dev *wdev = dev->ieee80211_ptr;
5825 struct cfg80211_chan_def chandef;
Luis R. Rodriguez55f74352013-11-25 20:56:10 +01005826 enum nl80211_dfs_regions dfs_region;
Janusz Dziedzic31559f32014-02-21 19:46:13 +01005827 unsigned int cac_time_ms;
Simon Wunderlich04f39042013-02-08 18:16:19 +01005828 int err;
5829
Luis R. Rodriguez55f74352013-11-25 20:56:10 +01005830 dfs_region = reg_get_dfs_region(wdev->wiphy);
5831 if (dfs_region == NL80211_DFS_UNSET)
5832 return -EINVAL;
5833
Simon Wunderlich04f39042013-02-08 18:16:19 +01005834 err = nl80211_parse_chandef(rdev, info, &chandef);
5835 if (err)
5836 return err;
5837
Simon Wunderlichff311bc2013-09-03 19:43:18 +02005838 if (netif_carrier_ok(dev))
5839 return -EBUSY;
5840
Simon Wunderlich04f39042013-02-08 18:16:19 +01005841 if (wdev->cac_started)
5842 return -EBUSY;
5843
Luciano Coelho2beb6da2014-02-18 11:40:36 +02005844 err = cfg80211_chandef_dfs_required(wdev->wiphy, &chandef,
Luciano Coelho00ec75f2014-05-15 13:05:39 +03005845 wdev->iftype);
Simon Wunderlich04f39042013-02-08 18:16:19 +01005846 if (err < 0)
5847 return err;
5848
5849 if (err == 0)
5850 return -EINVAL;
5851
Janusz Dziedzicfe7c3a12013-11-05 14:48:48 +01005852 if (!cfg80211_chandef_dfs_usable(wdev->wiphy, &chandef))
Simon Wunderlich04f39042013-02-08 18:16:19 +01005853 return -EINVAL;
5854
5855 if (!rdev->ops->start_radar_detection)
5856 return -EOPNOTSUPP;
5857
Janusz Dziedzic31559f32014-02-21 19:46:13 +01005858 cac_time_ms = cfg80211_chandef_dfs_cac_time(&rdev->wiphy, &chandef);
5859 if (WARN_ON(!cac_time_ms))
5860 cac_time_ms = IEEE80211_DFS_MIN_CAC_TIME_MS;
5861
5862 err = rdev->ops->start_radar_detection(&rdev->wiphy, dev, &chandef,
5863 cac_time_ms);
Simon Wunderlich04f39042013-02-08 18:16:19 +01005864 if (!err) {
Michal Kazior9e0e2962014-01-29 14:22:27 +01005865 wdev->chandef = chandef;
Simon Wunderlich04f39042013-02-08 18:16:19 +01005866 wdev->cac_started = true;
5867 wdev->cac_start_time = jiffies;
Janusz Dziedzic31559f32014-02-21 19:46:13 +01005868 wdev->cac_time_ms = cac_time_ms;
Simon Wunderlich04f39042013-02-08 18:16:19 +01005869 }
Simon Wunderlich04f39042013-02-08 18:16:19 +01005870 return err;
5871}
5872
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02005873static int nl80211_channel_switch(struct sk_buff *skb, struct genl_info *info)
5874{
5875 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5876 struct net_device *dev = info->user_ptr[1];
5877 struct wireless_dev *wdev = dev->ieee80211_ptr;
5878 struct cfg80211_csa_settings params;
5879 /* csa_attrs is defined static to avoid waste of stack size - this
5880 * function is called under RTNL lock, so this should not be a problem.
5881 */
5882 static struct nlattr *csa_attrs[NL80211_ATTR_MAX+1];
5883 u8 radar_detect_width = 0;
5884 int err;
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02005885 bool need_new_beacon = false;
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03005886 int len, i;
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02005887
5888 if (!rdev->ops->channel_switch ||
5889 !(rdev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH))
5890 return -EOPNOTSUPP;
5891
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02005892 switch (dev->ieee80211_ptr->iftype) {
5893 case NL80211_IFTYPE_AP:
5894 case NL80211_IFTYPE_P2P_GO:
5895 need_new_beacon = true;
5896
5897 /* useless if AP is not running */
5898 if (!wdev->beacon_interval)
Johannes Berg1ff79df2014-01-22 10:05:27 +01005899 return -ENOTCONN;
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02005900 break;
5901 case NL80211_IFTYPE_ADHOC:
Johannes Berg1ff79df2014-01-22 10:05:27 +01005902 if (!wdev->ssid_len)
5903 return -ENOTCONN;
5904 break;
Chun-Yeow Yeohc6da6742013-10-14 19:08:28 -07005905 case NL80211_IFTYPE_MESH_POINT:
Johannes Berg1ff79df2014-01-22 10:05:27 +01005906 if (!wdev->mesh_id_len)
5907 return -ENOTCONN;
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02005908 break;
5909 default:
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02005910 return -EOPNOTSUPP;
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02005911 }
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02005912
5913 memset(&params, 0, sizeof(params));
5914
5915 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] ||
5916 !info->attrs[NL80211_ATTR_CH_SWITCH_COUNT])
5917 return -EINVAL;
5918
5919 /* only important for AP, IBSS and mesh create IEs internally */
Andrei Otcheretianskid0a361a2013-10-17 10:52:17 +02005920 if (need_new_beacon && !info->attrs[NL80211_ATTR_CSA_IES])
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02005921 return -EINVAL;
5922
5923 params.count = nla_get_u32(info->attrs[NL80211_ATTR_CH_SWITCH_COUNT]);
5924
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02005925 if (!need_new_beacon)
5926 goto skip_beacons;
5927
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02005928 err = nl80211_parse_beacon(info->attrs, &params.beacon_after);
5929 if (err)
5930 return err;
5931
5932 err = nla_parse_nested(csa_attrs, NL80211_ATTR_MAX,
5933 info->attrs[NL80211_ATTR_CSA_IES],
5934 nl80211_policy);
5935 if (err)
5936 return err;
5937
5938 err = nl80211_parse_beacon(csa_attrs, &params.beacon_csa);
5939 if (err)
5940 return err;
5941
5942 if (!csa_attrs[NL80211_ATTR_CSA_C_OFF_BEACON])
5943 return -EINVAL;
5944
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03005945 len = nla_len(csa_attrs[NL80211_ATTR_CSA_C_OFF_BEACON]);
5946 if (!len || (len % sizeof(u16)))
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02005947 return -EINVAL;
5948
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03005949 params.n_counter_offsets_beacon = len / sizeof(u16);
5950 if (rdev->wiphy.max_num_csa_counters &&
5951 (params.n_counter_offsets_beacon >
5952 rdev->wiphy.max_num_csa_counters))
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02005953 return -EINVAL;
5954
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03005955 params.counter_offsets_beacon =
5956 nla_data(csa_attrs[NL80211_ATTR_CSA_C_OFF_BEACON]);
5957
5958 /* sanity checks - counters should fit and be the same */
5959 for (i = 0; i < params.n_counter_offsets_beacon; i++) {
5960 u16 offset = params.counter_offsets_beacon[i];
5961
5962 if (offset >= params.beacon_csa.tail_len)
5963 return -EINVAL;
5964
5965 if (params.beacon_csa.tail[offset] != params.count)
5966 return -EINVAL;
5967 }
5968
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02005969 if (csa_attrs[NL80211_ATTR_CSA_C_OFF_PRESP]) {
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03005970 len = nla_len(csa_attrs[NL80211_ATTR_CSA_C_OFF_PRESP]);
5971 if (!len || (len % sizeof(u16)))
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02005972 return -EINVAL;
5973
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03005974 params.n_counter_offsets_presp = len / sizeof(u16);
5975 if (rdev->wiphy.max_num_csa_counters &&
5976 (params.n_counter_offsets_beacon >
5977 rdev->wiphy.max_num_csa_counters))
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02005978 return -EINVAL;
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03005979
5980 params.counter_offsets_presp =
5981 nla_data(csa_attrs[NL80211_ATTR_CSA_C_OFF_PRESP]);
5982
5983 /* sanity checks - counters should fit and be the same */
5984 for (i = 0; i < params.n_counter_offsets_presp; i++) {
5985 u16 offset = params.counter_offsets_presp[i];
5986
5987 if (offset >= params.beacon_csa.probe_resp_len)
5988 return -EINVAL;
5989
5990 if (params.beacon_csa.probe_resp[offset] !=
5991 params.count)
5992 return -EINVAL;
5993 }
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02005994 }
5995
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02005996skip_beacons:
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02005997 err = nl80211_parse_chandef(rdev, info, &params.chandef);
5998 if (err)
5999 return err;
6000
Ilan Peer174e0cd2014-02-23 09:13:01 +02006001 if (!cfg80211_reg_can_beacon(&rdev->wiphy, &params.chandef,
6002 wdev->iftype))
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006003 return -EINVAL;
6004
Luciano Coelho2beb6da2014-02-18 11:40:36 +02006005 err = cfg80211_chandef_dfs_required(wdev->wiphy,
6006 &params.chandef,
6007 wdev->iftype);
6008 if (err < 0)
6009 return err;
6010
6011 if (err > 0) {
6012 radar_detect_width = BIT(params.chandef.width);
6013 params.radar_required = true;
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006014 }
6015
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006016 if (info->attrs[NL80211_ATTR_CH_SWITCH_BLOCK_TX])
6017 params.block_tx = true;
6018
Simon Wunderlichc56589e2013-11-21 18:19:49 +01006019 wdev_lock(wdev);
6020 err = rdev_channel_switch(rdev, dev, &params);
6021 wdev_unlock(wdev);
6022
6023 return err;
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006024}
6025
Johannes Berg9720bb32011-06-21 09:45:33 +02006026static int nl80211_send_bss(struct sk_buff *msg, struct netlink_callback *cb,
6027 u32 seq, int flags,
Johannes Berg2a519312009-02-10 21:25:55 +01006028 struct cfg80211_registered_device *rdev,
Johannes Berg48ab9052009-07-10 18:42:31 +02006029 struct wireless_dev *wdev,
6030 struct cfg80211_internal_bss *intbss)
Johannes Berg2a519312009-02-10 21:25:55 +01006031{
Johannes Berg48ab9052009-07-10 18:42:31 +02006032 struct cfg80211_bss *res = &intbss->pub;
Johannes Berg9caf0362012-11-29 01:25:20 +01006033 const struct cfg80211_bss_ies *ies;
Johannes Berg2a519312009-02-10 21:25:55 +01006034 void *hdr;
6035 struct nlattr *bss;
Johannes Berg48ab9052009-07-10 18:42:31 +02006036
6037 ASSERT_WDEV_LOCK(wdev);
Johannes Berg2a519312009-02-10 21:25:55 +01006038
Eric W. Biederman15e47302012-09-07 20:12:54 +00006039 hdr = nl80211hdr_put(msg, NETLINK_CB(cb->skb).portid, seq, flags,
Johannes Berg2a519312009-02-10 21:25:55 +01006040 NL80211_CMD_NEW_SCAN_RESULTS);
6041 if (!hdr)
6042 return -1;
6043
Johannes Berg9720bb32011-06-21 09:45:33 +02006044 genl_dump_check_consistent(cb, hdr, &nl80211_fam);
6045
Johannes Berg97990a02013-04-19 01:02:55 +02006046 if (nla_put_u32(msg, NL80211_ATTR_GENERATION, rdev->bss_generation))
6047 goto nla_put_failure;
6048 if (wdev->netdev &&
David S. Miller9360ffd2012-03-29 04:41:26 -04006049 nla_put_u32(msg, NL80211_ATTR_IFINDEX, wdev->netdev->ifindex))
6050 goto nla_put_failure;
Johannes Berg97990a02013-04-19 01:02:55 +02006051 if (nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)))
6052 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01006053
6054 bss = nla_nest_start(msg, NL80211_ATTR_BSS);
6055 if (!bss)
6056 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04006057 if ((!is_zero_ether_addr(res->bssid) &&
Johannes Berg9caf0362012-11-29 01:25:20 +01006058 nla_put(msg, NL80211_BSS_BSSID, ETH_ALEN, res->bssid)))
David S. Miller9360ffd2012-03-29 04:41:26 -04006059 goto nla_put_failure;
Johannes Berg9caf0362012-11-29 01:25:20 +01006060
6061 rcu_read_lock();
Johannes Berg0e227082014-08-12 20:34:30 +02006062 /* indicate whether we have probe response data or not */
6063 if (rcu_access_pointer(res->proberesp_ies) &&
6064 nla_put_flag(msg, NL80211_BSS_PRESP_DATA))
6065 goto fail_unlock_rcu;
6066
6067 /* this pointer prefers to be pointed to probe response data
6068 * but is always valid
6069 */
Johannes Berg9caf0362012-11-29 01:25:20 +01006070 ies = rcu_dereference(res->ies);
Johannes Berg8cef2c92013-02-05 16:54:31 +01006071 if (ies) {
6072 if (nla_put_u64(msg, NL80211_BSS_TSF, ies->tsf))
6073 goto fail_unlock_rcu;
Johannes Berg8cef2c92013-02-05 16:54:31 +01006074 if (ies->len && nla_put(msg, NL80211_BSS_INFORMATION_ELEMENTS,
6075 ies->len, ies->data))
6076 goto fail_unlock_rcu;
Johannes Berg9caf0362012-11-29 01:25:20 +01006077 }
Johannes Berg0e227082014-08-12 20:34:30 +02006078
6079 /* and this pointer is always (unless driver didn't know) beacon data */
Johannes Berg9caf0362012-11-29 01:25:20 +01006080 ies = rcu_dereference(res->beacon_ies);
Johannes Berg0e227082014-08-12 20:34:30 +02006081 if (ies && ies->from_beacon) {
6082 if (nla_put_u64(msg, NL80211_BSS_BEACON_TSF, ies->tsf))
Johannes Berg8cef2c92013-02-05 16:54:31 +01006083 goto fail_unlock_rcu;
6084 if (ies->len && nla_put(msg, NL80211_BSS_BEACON_IES,
6085 ies->len, ies->data))
6086 goto fail_unlock_rcu;
Johannes Berg9caf0362012-11-29 01:25:20 +01006087 }
6088 rcu_read_unlock();
6089
David S. Miller9360ffd2012-03-29 04:41:26 -04006090 if (res->beacon_interval &&
6091 nla_put_u16(msg, NL80211_BSS_BEACON_INTERVAL, res->beacon_interval))
6092 goto nla_put_failure;
6093 if (nla_put_u16(msg, NL80211_BSS_CAPABILITY, res->capability) ||
6094 nla_put_u32(msg, NL80211_BSS_FREQUENCY, res->channel->center_freq) ||
Simon Wunderlichdcd6eac2013-07-08 16:55:49 +02006095 nla_put_u32(msg, NL80211_BSS_CHAN_WIDTH, res->scan_width) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04006096 nla_put_u32(msg, NL80211_BSS_SEEN_MS_AGO,
6097 jiffies_to_msecs(jiffies - intbss->ts)))
6098 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01006099
Johannes Berg77965c92009-02-18 18:45:06 +01006100 switch (rdev->wiphy.signal_type) {
Johannes Berg2a519312009-02-10 21:25:55 +01006101 case CFG80211_SIGNAL_TYPE_MBM:
David S. Miller9360ffd2012-03-29 04:41:26 -04006102 if (nla_put_u32(msg, NL80211_BSS_SIGNAL_MBM, res->signal))
6103 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01006104 break;
6105 case CFG80211_SIGNAL_TYPE_UNSPEC:
David S. Miller9360ffd2012-03-29 04:41:26 -04006106 if (nla_put_u8(msg, NL80211_BSS_SIGNAL_UNSPEC, res->signal))
6107 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01006108 break;
6109 default:
6110 break;
6111 }
6112
Johannes Berg48ab9052009-07-10 18:42:31 +02006113 switch (wdev->iftype) {
Johannes Berg074ac8d2010-09-16 14:58:22 +02006114 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Berg48ab9052009-07-10 18:42:31 +02006115 case NL80211_IFTYPE_STATION:
David S. Miller9360ffd2012-03-29 04:41:26 -04006116 if (intbss == wdev->current_bss &&
6117 nla_put_u32(msg, NL80211_BSS_STATUS,
6118 NL80211_BSS_STATUS_ASSOCIATED))
6119 goto nla_put_failure;
Johannes Berg48ab9052009-07-10 18:42:31 +02006120 break;
6121 case NL80211_IFTYPE_ADHOC:
David S. Miller9360ffd2012-03-29 04:41:26 -04006122 if (intbss == wdev->current_bss &&
6123 nla_put_u32(msg, NL80211_BSS_STATUS,
6124 NL80211_BSS_STATUS_IBSS_JOINED))
6125 goto nla_put_failure;
Johannes Berg48ab9052009-07-10 18:42:31 +02006126 break;
6127 default:
6128 break;
6129 }
6130
Johannes Berg2a519312009-02-10 21:25:55 +01006131 nla_nest_end(msg, bss);
6132
6133 return genlmsg_end(msg, hdr);
6134
Johannes Berg8cef2c92013-02-05 16:54:31 +01006135 fail_unlock_rcu:
6136 rcu_read_unlock();
Johannes Berg2a519312009-02-10 21:25:55 +01006137 nla_put_failure:
6138 genlmsg_cancel(msg, hdr);
6139 return -EMSGSIZE;
6140}
6141
Johannes Berg97990a02013-04-19 01:02:55 +02006142static int nl80211_dump_scan(struct sk_buff *skb, struct netlink_callback *cb)
Johannes Berg2a519312009-02-10 21:25:55 +01006143{
Johannes Berg48ab9052009-07-10 18:42:31 +02006144 struct cfg80211_registered_device *rdev;
Johannes Berg2a519312009-02-10 21:25:55 +01006145 struct cfg80211_internal_bss *scan;
Johannes Berg48ab9052009-07-10 18:42:31 +02006146 struct wireless_dev *wdev;
Johannes Berg97990a02013-04-19 01:02:55 +02006147 int start = cb->args[2], idx = 0;
Johannes Berg2a519312009-02-10 21:25:55 +01006148 int err;
6149
Johannes Berg97990a02013-04-19 01:02:55 +02006150 err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev);
Johannes Berg67748892010-10-04 21:14:06 +02006151 if (err)
6152 return err;
Johannes Berg2a519312009-02-10 21:25:55 +01006153
Johannes Berg48ab9052009-07-10 18:42:31 +02006154 wdev_lock(wdev);
6155 spin_lock_bh(&rdev->bss_lock);
6156 cfg80211_bss_expire(rdev);
6157
Johannes Berg9720bb32011-06-21 09:45:33 +02006158 cb->seq = rdev->bss_generation;
6159
Johannes Berg48ab9052009-07-10 18:42:31 +02006160 list_for_each_entry(scan, &rdev->bss_list, list) {
Johannes Berg2a519312009-02-10 21:25:55 +01006161 if (++idx <= start)
6162 continue;
Johannes Berg9720bb32011-06-21 09:45:33 +02006163 if (nl80211_send_bss(skb, cb,
Johannes Berg2a519312009-02-10 21:25:55 +01006164 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Johannes Berg48ab9052009-07-10 18:42:31 +02006165 rdev, wdev, scan) < 0) {
Johannes Berg2a519312009-02-10 21:25:55 +01006166 idx--;
Johannes Berg67748892010-10-04 21:14:06 +02006167 break;
Johannes Berg2a519312009-02-10 21:25:55 +01006168 }
6169 }
6170
Johannes Berg48ab9052009-07-10 18:42:31 +02006171 spin_unlock_bh(&rdev->bss_lock);
6172 wdev_unlock(wdev);
Johannes Berg2a519312009-02-10 21:25:55 +01006173
Johannes Berg97990a02013-04-19 01:02:55 +02006174 cb->args[2] = idx;
6175 nl80211_finish_wdev_dump(rdev);
Johannes Berg2a519312009-02-10 21:25:55 +01006176
Johannes Berg67748892010-10-04 21:14:06 +02006177 return skb->len;
Johannes Berg2a519312009-02-10 21:25:55 +01006178}
6179
Eric W. Biederman15e47302012-09-07 20:12:54 +00006180static int nl80211_send_survey(struct sk_buff *msg, u32 portid, u32 seq,
Holger Schurig61fa7132009-11-11 12:25:40 +01006181 int flags, struct net_device *dev,
6182 struct survey_info *survey)
6183{
6184 void *hdr;
6185 struct nlattr *infoattr;
6186
Eric W. Biederman15e47302012-09-07 20:12:54 +00006187 hdr = nl80211hdr_put(msg, portid, seq, flags,
Holger Schurig61fa7132009-11-11 12:25:40 +01006188 NL80211_CMD_NEW_SURVEY_RESULTS);
6189 if (!hdr)
6190 return -ENOMEM;
6191
David S. Miller9360ffd2012-03-29 04:41:26 -04006192 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex))
6193 goto nla_put_failure;
Holger Schurig61fa7132009-11-11 12:25:40 +01006194
6195 infoattr = nla_nest_start(msg, NL80211_ATTR_SURVEY_INFO);
6196 if (!infoattr)
6197 goto nla_put_failure;
6198
David S. Miller9360ffd2012-03-29 04:41:26 -04006199 if (nla_put_u32(msg, NL80211_SURVEY_INFO_FREQUENCY,
6200 survey->channel->center_freq))
6201 goto nla_put_failure;
6202
6203 if ((survey->filled & SURVEY_INFO_NOISE_DBM) &&
6204 nla_put_u8(msg, NL80211_SURVEY_INFO_NOISE, survey->noise))
6205 goto nla_put_failure;
6206 if ((survey->filled & SURVEY_INFO_IN_USE) &&
6207 nla_put_flag(msg, NL80211_SURVEY_INFO_IN_USE))
6208 goto nla_put_failure;
6209 if ((survey->filled & SURVEY_INFO_CHANNEL_TIME) &&
6210 nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME,
6211 survey->channel_time))
6212 goto nla_put_failure;
6213 if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_BUSY) &&
6214 nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_BUSY,
6215 survey->channel_time_busy))
6216 goto nla_put_failure;
6217 if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_EXT_BUSY) &&
6218 nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_EXT_BUSY,
6219 survey->channel_time_ext_busy))
6220 goto nla_put_failure;
6221 if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_RX) &&
6222 nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_RX,
6223 survey->channel_time_rx))
6224 goto nla_put_failure;
6225 if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_TX) &&
6226 nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_TX,
6227 survey->channel_time_tx))
6228 goto nla_put_failure;
Holger Schurig61fa7132009-11-11 12:25:40 +01006229
6230 nla_nest_end(msg, infoattr);
6231
6232 return genlmsg_end(msg, hdr);
6233
6234 nla_put_failure:
6235 genlmsg_cancel(msg, hdr);
6236 return -EMSGSIZE;
6237}
6238
6239static int nl80211_dump_survey(struct sk_buff *skb,
6240 struct netlink_callback *cb)
6241{
6242 struct survey_info survey;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08006243 struct cfg80211_registered_device *rdev;
Johannes Berg97990a02013-04-19 01:02:55 +02006244 struct wireless_dev *wdev;
6245 int survey_idx = cb->args[2];
Holger Schurig61fa7132009-11-11 12:25:40 +01006246 int res;
6247
Zhao, Gang1b8ec872014-04-21 12:53:02 +08006248 res = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev);
Johannes Berg67748892010-10-04 21:14:06 +02006249 if (res)
6250 return res;
Holger Schurig61fa7132009-11-11 12:25:40 +01006251
Johannes Berg97990a02013-04-19 01:02:55 +02006252 if (!wdev->netdev) {
6253 res = -EINVAL;
6254 goto out_err;
6255 }
6256
Zhao, Gang1b8ec872014-04-21 12:53:02 +08006257 if (!rdev->ops->dump_survey) {
Holger Schurig61fa7132009-11-11 12:25:40 +01006258 res = -EOPNOTSUPP;
6259 goto out_err;
6260 }
6261
6262 while (1) {
Luis R. Rodriguez180cdc72011-05-27 07:24:02 -07006263 struct ieee80211_channel *chan;
6264
Zhao, Gang1b8ec872014-04-21 12:53:02 +08006265 res = rdev_dump_survey(rdev, wdev->netdev, survey_idx, &survey);
Holger Schurig61fa7132009-11-11 12:25:40 +01006266 if (res == -ENOENT)
6267 break;
6268 if (res)
6269 goto out_err;
6270
Luis R. Rodriguez180cdc72011-05-27 07:24:02 -07006271 /* Survey without a channel doesn't make sense */
6272 if (!survey.channel) {
6273 res = -EINVAL;
6274 goto out;
6275 }
6276
Zhao, Gang1b8ec872014-04-21 12:53:02 +08006277 chan = ieee80211_get_channel(&rdev->wiphy,
Luis R. Rodriguez180cdc72011-05-27 07:24:02 -07006278 survey.channel->center_freq);
6279 if (!chan || chan->flags & IEEE80211_CHAN_DISABLED) {
6280 survey_idx++;
6281 continue;
6282 }
6283
Holger Schurig61fa7132009-11-11 12:25:40 +01006284 if (nl80211_send_survey(skb,
Eric W. Biederman15e47302012-09-07 20:12:54 +00006285 NETLINK_CB(cb->skb).portid,
Holger Schurig61fa7132009-11-11 12:25:40 +01006286 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Johannes Berg97990a02013-04-19 01:02:55 +02006287 wdev->netdev, &survey) < 0)
Holger Schurig61fa7132009-11-11 12:25:40 +01006288 goto out;
6289 survey_idx++;
6290 }
6291
6292 out:
Johannes Berg97990a02013-04-19 01:02:55 +02006293 cb->args[2] = survey_idx;
Holger Schurig61fa7132009-11-11 12:25:40 +01006294 res = skb->len;
6295 out_err:
Zhao, Gang1b8ec872014-04-21 12:53:02 +08006296 nl80211_finish_wdev_dump(rdev);
Holger Schurig61fa7132009-11-11 12:25:40 +01006297 return res;
6298}
6299
Samuel Ortizb23aa672009-07-01 21:26:54 +02006300static bool nl80211_valid_wpa_versions(u32 wpa_versions)
6301{
6302 return !(wpa_versions & ~(NL80211_WPA_VERSION_1 |
6303 NL80211_WPA_VERSION_2));
6304}
6305
Jouni Malinen636a5d32009-03-19 13:39:22 +02006306static int nl80211_authenticate(struct sk_buff *skb, struct genl_info *info)
6307{
Johannes Berg4c476992010-10-04 21:36:35 +02006308 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6309 struct net_device *dev = info->user_ptr[1];
Johannes Berg19957bb2009-07-02 17:20:43 +02006310 struct ieee80211_channel *chan;
Jouni Malinene39e5b52012-09-30 19:29:39 +03006311 const u8 *bssid, *ssid, *ie = NULL, *sae_data = NULL;
6312 int err, ssid_len, ie_len = 0, sae_data_len = 0;
Johannes Berg19957bb2009-07-02 17:20:43 +02006313 enum nl80211_auth_type auth_type;
Johannes Bergfffd0932009-07-08 14:22:54 +02006314 struct key_parse key;
Jouni Malinend5cdfac2010-04-04 09:37:19 +03006315 bool local_state_change;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006316
Johannes Bergf4a11bb2009-03-27 12:40:28 +01006317 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
6318 return -EINVAL;
6319
6320 if (!info->attrs[NL80211_ATTR_MAC])
6321 return -EINVAL;
6322
Jouni Malinen17780922009-03-27 20:52:47 +02006323 if (!info->attrs[NL80211_ATTR_AUTH_TYPE])
6324 return -EINVAL;
6325
Johannes Berg19957bb2009-07-02 17:20:43 +02006326 if (!info->attrs[NL80211_ATTR_SSID])
6327 return -EINVAL;
6328
6329 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ])
6330 return -EINVAL;
6331
Johannes Bergfffd0932009-07-08 14:22:54 +02006332 err = nl80211_parse_key(info, &key);
6333 if (err)
6334 return err;
6335
6336 if (key.idx >= 0) {
Johannes Berge31b8212010-10-05 19:39:30 +02006337 if (key.type != -1 && key.type != NL80211_KEYTYPE_GROUP)
6338 return -EINVAL;
Johannes Bergfffd0932009-07-08 14:22:54 +02006339 if (!key.p.key || !key.p.key_len)
6340 return -EINVAL;
6341 if ((key.p.cipher != WLAN_CIPHER_SUITE_WEP40 ||
6342 key.p.key_len != WLAN_KEY_LEN_WEP40) &&
6343 (key.p.cipher != WLAN_CIPHER_SUITE_WEP104 ||
6344 key.p.key_len != WLAN_KEY_LEN_WEP104))
6345 return -EINVAL;
6346 if (key.idx > 4)
6347 return -EINVAL;
6348 } else {
6349 key.p.key_len = 0;
6350 key.p.key = NULL;
6351 }
6352
Johannes Bergafea0b72010-08-10 09:46:42 +02006353 if (key.idx >= 0) {
6354 int i;
6355 bool ok = false;
6356 for (i = 0; i < rdev->wiphy.n_cipher_suites; i++) {
6357 if (key.p.cipher == rdev->wiphy.cipher_suites[i]) {
6358 ok = true;
6359 break;
6360 }
6361 }
Johannes Berg4c476992010-10-04 21:36:35 +02006362 if (!ok)
6363 return -EINVAL;
Johannes Bergafea0b72010-08-10 09:46:42 +02006364 }
6365
Johannes Berg4c476992010-10-04 21:36:35 +02006366 if (!rdev->ops->auth)
6367 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006368
Johannes Berg074ac8d2010-09-16 14:58:22 +02006369 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02006370 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
6371 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02006372
Johannes Berg19957bb2009-07-02 17:20:43 +02006373 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen664834d2014-01-15 00:01:44 +02006374 chan = nl80211_get_valid_chan(&rdev->wiphy,
6375 info->attrs[NL80211_ATTR_WIPHY_FREQ]);
6376 if (!chan)
Johannes Berg4c476992010-10-04 21:36:35 +02006377 return -EINVAL;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006378
Johannes Berg19957bb2009-07-02 17:20:43 +02006379 ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
6380 ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
6381
6382 if (info->attrs[NL80211_ATTR_IE]) {
6383 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
6384 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
6385 }
6386
6387 auth_type = nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]);
Jouni Malinene39e5b52012-09-30 19:29:39 +03006388 if (!nl80211_valid_auth_type(rdev, auth_type, NL80211_CMD_AUTHENTICATE))
Johannes Berg4c476992010-10-04 21:36:35 +02006389 return -EINVAL;
Johannes Berg19957bb2009-07-02 17:20:43 +02006390
Jouni Malinene39e5b52012-09-30 19:29:39 +03006391 if (auth_type == NL80211_AUTHTYPE_SAE &&
6392 !info->attrs[NL80211_ATTR_SAE_DATA])
6393 return -EINVAL;
6394
6395 if (info->attrs[NL80211_ATTR_SAE_DATA]) {
6396 if (auth_type != NL80211_AUTHTYPE_SAE)
6397 return -EINVAL;
6398 sae_data = nla_data(info->attrs[NL80211_ATTR_SAE_DATA]);
6399 sae_data_len = nla_len(info->attrs[NL80211_ATTR_SAE_DATA]);
6400 /* need to include at least Auth Transaction and Status Code */
6401 if (sae_data_len < 4)
6402 return -EINVAL;
6403 }
6404
Jouni Malinend5cdfac2010-04-04 09:37:19 +03006405 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE];
6406
Johannes Berg95de8172012-01-20 13:55:25 +01006407 /*
6408 * Since we no longer track auth state, ignore
6409 * requests to only change local state.
6410 */
6411 if (local_state_change)
6412 return 0;
6413
Johannes Berg91bf9b22013-05-15 17:44:01 +02006414 wdev_lock(dev->ieee80211_ptr);
6415 err = cfg80211_mlme_auth(rdev, dev, chan, auth_type, bssid,
6416 ssid, ssid_len, ie, ie_len,
6417 key.p.key, key.p.key_len, key.idx,
6418 sae_data, sae_data_len);
6419 wdev_unlock(dev->ieee80211_ptr);
6420 return err;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006421}
6422
Johannes Bergc0692b82010-08-27 14:26:53 +03006423static int nl80211_crypto_settings(struct cfg80211_registered_device *rdev,
6424 struct genl_info *info,
Johannes Berg3dc27d22009-07-02 21:36:37 +02006425 struct cfg80211_crypto_settings *settings,
6426 int cipher_limit)
Samuel Ortizb23aa672009-07-01 21:26:54 +02006427{
Johannes Bergc0b2bbd2009-07-25 16:54:36 +02006428 memset(settings, 0, sizeof(*settings));
6429
Samuel Ortizb23aa672009-07-01 21:26:54 +02006430 settings->control_port = info->attrs[NL80211_ATTR_CONTROL_PORT];
6431
Johannes Bergc0692b82010-08-27 14:26:53 +03006432 if (info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]) {
6433 u16 proto;
6434 proto = nla_get_u16(
6435 info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]);
6436 settings->control_port_ethertype = cpu_to_be16(proto);
6437 if (!(rdev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) &&
6438 proto != ETH_P_PAE)
6439 return -EINVAL;
6440 if (info->attrs[NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT])
6441 settings->control_port_no_encrypt = true;
6442 } else
6443 settings->control_port_ethertype = cpu_to_be16(ETH_P_PAE);
6444
Samuel Ortizb23aa672009-07-01 21:26:54 +02006445 if (info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]) {
6446 void *data;
6447 int len, i;
6448
6449 data = nla_data(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]);
6450 len = nla_len(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]);
6451 settings->n_ciphers_pairwise = len / sizeof(u32);
6452
6453 if (len % sizeof(u32))
6454 return -EINVAL;
6455
Johannes Berg3dc27d22009-07-02 21:36:37 +02006456 if (settings->n_ciphers_pairwise > cipher_limit)
Samuel Ortizb23aa672009-07-01 21:26:54 +02006457 return -EINVAL;
6458
6459 memcpy(settings->ciphers_pairwise, data, len);
6460
6461 for (i = 0; i < settings->n_ciphers_pairwise; i++)
Jouni Malinen38ba3c52011-09-21 18:14:56 +03006462 if (!cfg80211_supported_cipher_suite(
6463 &rdev->wiphy,
Samuel Ortizb23aa672009-07-01 21:26:54 +02006464 settings->ciphers_pairwise[i]))
6465 return -EINVAL;
6466 }
6467
6468 if (info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]) {
6469 settings->cipher_group =
6470 nla_get_u32(info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]);
Jouni Malinen38ba3c52011-09-21 18:14:56 +03006471 if (!cfg80211_supported_cipher_suite(&rdev->wiphy,
6472 settings->cipher_group))
Samuel Ortizb23aa672009-07-01 21:26:54 +02006473 return -EINVAL;
6474 }
6475
6476 if (info->attrs[NL80211_ATTR_WPA_VERSIONS]) {
6477 settings->wpa_versions =
6478 nla_get_u32(info->attrs[NL80211_ATTR_WPA_VERSIONS]);
6479 if (!nl80211_valid_wpa_versions(settings->wpa_versions))
6480 return -EINVAL;
6481 }
6482
6483 if (info->attrs[NL80211_ATTR_AKM_SUITES]) {
6484 void *data;
Jouni Malinen6d302402011-09-21 18:11:33 +03006485 int len;
Samuel Ortizb23aa672009-07-01 21:26:54 +02006486
6487 data = nla_data(info->attrs[NL80211_ATTR_AKM_SUITES]);
6488 len = nla_len(info->attrs[NL80211_ATTR_AKM_SUITES]);
6489 settings->n_akm_suites = len / sizeof(u32);
6490
6491 if (len % sizeof(u32))
6492 return -EINVAL;
6493
Jouni Malinen1b9ca022011-09-21 16:13:07 +03006494 if (settings->n_akm_suites > NL80211_MAX_NR_AKM_SUITES)
6495 return -EINVAL;
6496
Samuel Ortizb23aa672009-07-01 21:26:54 +02006497 memcpy(settings->akm_suites, data, len);
Samuel Ortizb23aa672009-07-01 21:26:54 +02006498 }
6499
6500 return 0;
6501}
6502
Jouni Malinen636a5d32009-03-19 13:39:22 +02006503static int nl80211_associate(struct sk_buff *skb, struct genl_info *info)
6504{
Johannes Berg4c476992010-10-04 21:36:35 +02006505 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6506 struct net_device *dev = info->user_ptr[1];
Johannes Bergf444de02010-05-05 15:25:02 +02006507 struct ieee80211_channel *chan;
Johannes Bergf62fab72013-02-21 20:09:09 +01006508 struct cfg80211_assoc_request req = {};
6509 const u8 *bssid, *ssid;
6510 int err, ssid_len = 0;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006511
Johannes Bergf4a11bb2009-03-27 12:40:28 +01006512 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
6513 return -EINVAL;
6514
6515 if (!info->attrs[NL80211_ATTR_MAC] ||
Johannes Berg19957bb2009-07-02 17:20:43 +02006516 !info->attrs[NL80211_ATTR_SSID] ||
6517 !info->attrs[NL80211_ATTR_WIPHY_FREQ])
Johannes Bergf4a11bb2009-03-27 12:40:28 +01006518 return -EINVAL;
6519
Johannes Berg4c476992010-10-04 21:36:35 +02006520 if (!rdev->ops->assoc)
6521 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006522
Johannes Berg074ac8d2010-09-16 14:58:22 +02006523 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02006524 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
6525 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02006526
Johannes Berg19957bb2009-07-02 17:20:43 +02006527 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02006528
Jouni Malinen664834d2014-01-15 00:01:44 +02006529 chan = nl80211_get_valid_chan(&rdev->wiphy,
6530 info->attrs[NL80211_ATTR_WIPHY_FREQ]);
6531 if (!chan)
Johannes Berg4c476992010-10-04 21:36:35 +02006532 return -EINVAL;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006533
Johannes Berg19957bb2009-07-02 17:20:43 +02006534 ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
6535 ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02006536
6537 if (info->attrs[NL80211_ATTR_IE]) {
Johannes Bergf62fab72013-02-21 20:09:09 +01006538 req.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
6539 req.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02006540 }
6541
Jouni Malinendc6382c2009-05-06 22:09:37 +03006542 if (info->attrs[NL80211_ATTR_USE_MFP]) {
Johannes Berg4f5dadc2009-07-07 03:56:10 +02006543 enum nl80211_mfp mfp =
Jouni Malinendc6382c2009-05-06 22:09:37 +03006544 nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]);
Johannes Berg4f5dadc2009-07-07 03:56:10 +02006545 if (mfp == NL80211_MFP_REQUIRED)
Johannes Bergf62fab72013-02-21 20:09:09 +01006546 req.use_mfp = true;
Johannes Berg4c476992010-10-04 21:36:35 +02006547 else if (mfp != NL80211_MFP_NO)
6548 return -EINVAL;
Jouni Malinendc6382c2009-05-06 22:09:37 +03006549 }
6550
Johannes Berg3e5d7642009-07-07 14:37:26 +02006551 if (info->attrs[NL80211_ATTR_PREV_BSSID])
Johannes Bergf62fab72013-02-21 20:09:09 +01006552 req.prev_bssid = nla_data(info->attrs[NL80211_ATTR_PREV_BSSID]);
Johannes Berg3e5d7642009-07-07 14:37:26 +02006553
Ben Greear7e7c8922011-11-18 11:31:59 -08006554 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT]))
Johannes Bergf62fab72013-02-21 20:09:09 +01006555 req.flags |= ASSOC_REQ_DISABLE_HT;
Ben Greear7e7c8922011-11-18 11:31:59 -08006556
6557 if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
Johannes Bergf62fab72013-02-21 20:09:09 +01006558 memcpy(&req.ht_capa_mask,
6559 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]),
6560 sizeof(req.ht_capa_mask));
Ben Greear7e7c8922011-11-18 11:31:59 -08006561
6562 if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) {
Johannes Bergf62fab72013-02-21 20:09:09 +01006563 if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
Ben Greear7e7c8922011-11-18 11:31:59 -08006564 return -EINVAL;
Johannes Bergf62fab72013-02-21 20:09:09 +01006565 memcpy(&req.ht_capa,
6566 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]),
6567 sizeof(req.ht_capa));
Ben Greear7e7c8922011-11-18 11:31:59 -08006568 }
6569
Johannes Bergee2aca32013-02-21 17:36:01 +01006570 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_VHT]))
Johannes Bergf62fab72013-02-21 20:09:09 +01006571 req.flags |= ASSOC_REQ_DISABLE_VHT;
Johannes Bergee2aca32013-02-21 17:36:01 +01006572
6573 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK])
Johannes Bergf62fab72013-02-21 20:09:09 +01006574 memcpy(&req.vht_capa_mask,
6575 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]),
6576 sizeof(req.vht_capa_mask));
Johannes Bergee2aca32013-02-21 17:36:01 +01006577
6578 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) {
Johannes Bergf62fab72013-02-21 20:09:09 +01006579 if (!info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK])
Johannes Bergee2aca32013-02-21 17:36:01 +01006580 return -EINVAL;
Johannes Bergf62fab72013-02-21 20:09:09 +01006581 memcpy(&req.vht_capa,
6582 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]),
6583 sizeof(req.vht_capa));
Johannes Bergee2aca32013-02-21 17:36:01 +01006584 }
6585
Johannes Bergf62fab72013-02-21 20:09:09 +01006586 err = nl80211_crypto_settings(rdev, info, &req.crypto, 1);
Johannes Berg91bf9b22013-05-15 17:44:01 +02006587 if (!err) {
6588 wdev_lock(dev->ieee80211_ptr);
Johannes Bergf62fab72013-02-21 20:09:09 +01006589 err = cfg80211_mlme_assoc(rdev, dev, chan, bssid,
6590 ssid, ssid_len, &req);
Johannes Berg91bf9b22013-05-15 17:44:01 +02006591 wdev_unlock(dev->ieee80211_ptr);
6592 }
Jouni Malinen636a5d32009-03-19 13:39:22 +02006593
Jouni Malinen636a5d32009-03-19 13:39:22 +02006594 return err;
6595}
6596
6597static int nl80211_deauthenticate(struct sk_buff *skb, struct genl_info *info)
6598{
Johannes Berg4c476992010-10-04 21:36:35 +02006599 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6600 struct net_device *dev = info->user_ptr[1];
Johannes Berg19957bb2009-07-02 17:20:43 +02006601 const u8 *ie = NULL, *bssid;
Johannes Berg91bf9b22013-05-15 17:44:01 +02006602 int ie_len = 0, err;
Johannes Berg19957bb2009-07-02 17:20:43 +02006603 u16 reason_code;
Jouni Malinend5cdfac2010-04-04 09:37:19 +03006604 bool local_state_change;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006605
Johannes Bergf4a11bb2009-03-27 12:40:28 +01006606 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
6607 return -EINVAL;
6608
6609 if (!info->attrs[NL80211_ATTR_MAC])
6610 return -EINVAL;
6611
6612 if (!info->attrs[NL80211_ATTR_REASON_CODE])
6613 return -EINVAL;
6614
Johannes Berg4c476992010-10-04 21:36:35 +02006615 if (!rdev->ops->deauth)
6616 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006617
Johannes Berg074ac8d2010-09-16 14:58:22 +02006618 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02006619 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
6620 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02006621
Johannes Berg19957bb2009-07-02 17:20:43 +02006622 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02006623
Johannes Berg19957bb2009-07-02 17:20:43 +02006624 reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
6625 if (reason_code == 0) {
Johannes Bergf4a11bb2009-03-27 12:40:28 +01006626 /* Reason Code 0 is reserved */
Johannes Berg4c476992010-10-04 21:36:35 +02006627 return -EINVAL;
Jouni Malinen255e7372009-03-20 21:21:17 +02006628 }
Jouni Malinen636a5d32009-03-19 13:39:22 +02006629
6630 if (info->attrs[NL80211_ATTR_IE]) {
Johannes Berg19957bb2009-07-02 17:20:43 +02006631 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
6632 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02006633 }
6634
Jouni Malinend5cdfac2010-04-04 09:37:19 +03006635 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE];
6636
Johannes Berg91bf9b22013-05-15 17:44:01 +02006637 wdev_lock(dev->ieee80211_ptr);
6638 err = cfg80211_mlme_deauth(rdev, dev, bssid, ie, ie_len, reason_code,
6639 local_state_change);
6640 wdev_unlock(dev->ieee80211_ptr);
6641 return err;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006642}
6643
6644static int nl80211_disassociate(struct sk_buff *skb, struct genl_info *info)
6645{
Johannes Berg4c476992010-10-04 21:36:35 +02006646 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6647 struct net_device *dev = info->user_ptr[1];
Johannes Berg19957bb2009-07-02 17:20:43 +02006648 const u8 *ie = NULL, *bssid;
Johannes Berg91bf9b22013-05-15 17:44:01 +02006649 int ie_len = 0, err;
Johannes Berg19957bb2009-07-02 17:20:43 +02006650 u16 reason_code;
Jouni Malinend5cdfac2010-04-04 09:37:19 +03006651 bool local_state_change;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006652
Johannes Bergf4a11bb2009-03-27 12:40:28 +01006653 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
6654 return -EINVAL;
6655
6656 if (!info->attrs[NL80211_ATTR_MAC])
6657 return -EINVAL;
6658
6659 if (!info->attrs[NL80211_ATTR_REASON_CODE])
6660 return -EINVAL;
6661
Johannes Berg4c476992010-10-04 21:36:35 +02006662 if (!rdev->ops->disassoc)
6663 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006664
Johannes Berg074ac8d2010-09-16 14:58:22 +02006665 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02006666 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
6667 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02006668
Johannes Berg19957bb2009-07-02 17:20:43 +02006669 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02006670
Johannes Berg19957bb2009-07-02 17:20:43 +02006671 reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
6672 if (reason_code == 0) {
Johannes Bergf4a11bb2009-03-27 12:40:28 +01006673 /* Reason Code 0 is reserved */
Johannes Berg4c476992010-10-04 21:36:35 +02006674 return -EINVAL;
Jouni Malinen255e7372009-03-20 21:21:17 +02006675 }
Jouni Malinen636a5d32009-03-19 13:39:22 +02006676
6677 if (info->attrs[NL80211_ATTR_IE]) {
Johannes Berg19957bb2009-07-02 17:20:43 +02006678 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
6679 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02006680 }
6681
Jouni Malinend5cdfac2010-04-04 09:37:19 +03006682 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE];
6683
Johannes Berg91bf9b22013-05-15 17:44:01 +02006684 wdev_lock(dev->ieee80211_ptr);
6685 err = cfg80211_mlme_disassoc(rdev, dev, bssid, ie, ie_len, reason_code,
6686 local_state_change);
6687 wdev_unlock(dev->ieee80211_ptr);
6688 return err;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006689}
6690
Felix Fietkaudd5b4cc2010-11-22 20:58:24 +01006691static bool
6692nl80211_parse_mcast_rate(struct cfg80211_registered_device *rdev,
6693 int mcast_rate[IEEE80211_NUM_BANDS],
6694 int rateval)
6695{
6696 struct wiphy *wiphy = &rdev->wiphy;
6697 bool found = false;
6698 int band, i;
6699
6700 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
6701 struct ieee80211_supported_band *sband;
6702
6703 sband = wiphy->bands[band];
6704 if (!sband)
6705 continue;
6706
6707 for (i = 0; i < sband->n_bitrates; i++) {
6708 if (sband->bitrates[i].bitrate == rateval) {
6709 mcast_rate[band] = i + 1;
6710 found = true;
6711 break;
6712 }
6713 }
6714 }
6715
6716 return found;
6717}
6718
Johannes Berg04a773a2009-04-19 21:24:32 +02006719static int nl80211_join_ibss(struct sk_buff *skb, struct genl_info *info)
6720{
Johannes Berg4c476992010-10-04 21:36:35 +02006721 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6722 struct net_device *dev = info->user_ptr[1];
Johannes Berg04a773a2009-04-19 21:24:32 +02006723 struct cfg80211_ibss_params ibss;
6724 struct wiphy *wiphy;
Johannes Bergfffd0932009-07-08 14:22:54 +02006725 struct cfg80211_cached_keys *connkeys = NULL;
Johannes Berg04a773a2009-04-19 21:24:32 +02006726 int err;
6727
Johannes Berg8e30bc52009-04-22 17:45:38 +02006728 memset(&ibss, 0, sizeof(ibss));
6729
Johannes Berg04a773a2009-04-19 21:24:32 +02006730 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
6731 return -EINVAL;
6732
Johannes Berg683b6d32012-11-08 21:25:48 +01006733 if (!info->attrs[NL80211_ATTR_SSID] ||
Johannes Berg04a773a2009-04-19 21:24:32 +02006734 !nla_len(info->attrs[NL80211_ATTR_SSID]))
6735 return -EINVAL;
6736
Johannes Berg8e30bc52009-04-22 17:45:38 +02006737 ibss.beacon_interval = 100;
6738
6739 if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) {
6740 ibss.beacon_interval =
6741 nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]);
6742 if (ibss.beacon_interval < 1 || ibss.beacon_interval > 10000)
6743 return -EINVAL;
6744 }
6745
Johannes Berg4c476992010-10-04 21:36:35 +02006746 if (!rdev->ops->join_ibss)
6747 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02006748
Johannes Berg4c476992010-10-04 21:36:35 +02006749 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC)
6750 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02006751
Johannes Berg79c97e92009-07-07 03:56:12 +02006752 wiphy = &rdev->wiphy;
Johannes Berg04a773a2009-04-19 21:24:32 +02006753
Johannes Berg39193492011-09-16 13:45:25 +02006754 if (info->attrs[NL80211_ATTR_MAC]) {
Johannes Berg04a773a2009-04-19 21:24:32 +02006755 ibss.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Johannes Berg39193492011-09-16 13:45:25 +02006756
6757 if (!is_valid_ether_addr(ibss.bssid))
6758 return -EINVAL;
6759 }
Johannes Berg04a773a2009-04-19 21:24:32 +02006760 ibss.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
6761 ibss.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
6762
6763 if (info->attrs[NL80211_ATTR_IE]) {
6764 ibss.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
6765 ibss.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
6766 }
6767
Johannes Berg683b6d32012-11-08 21:25:48 +01006768 err = nl80211_parse_chandef(rdev, info, &ibss.chandef);
6769 if (err)
6770 return err;
Alexander Simon54858ee5b2011-11-30 16:56:32 +01006771
Ilan Peer174e0cd2014-02-23 09:13:01 +02006772 if (!cfg80211_reg_can_beacon(&rdev->wiphy, &ibss.chandef,
6773 NL80211_IFTYPE_ADHOC))
Alexander Simon54858ee5b2011-11-30 16:56:32 +01006774 return -EINVAL;
6775
Simon Wunderlich2f301ab2013-05-16 13:00:28 +02006776 switch (ibss.chandef.width) {
Simon Wunderlichbf372642013-07-08 16:55:58 +02006777 case NL80211_CHAN_WIDTH_5:
6778 case NL80211_CHAN_WIDTH_10:
Simon Wunderlich2f301ab2013-05-16 13:00:28 +02006779 case NL80211_CHAN_WIDTH_20_NOHT:
6780 break;
6781 case NL80211_CHAN_WIDTH_20:
6782 case NL80211_CHAN_WIDTH_40:
6783 if (rdev->wiphy.features & NL80211_FEATURE_HT_IBSS)
6784 break;
6785 default:
Johannes Bergdb9c64c2012-11-09 14:56:41 +01006786 return -EINVAL;
Simon Wunderlich2f301ab2013-05-16 13:00:28 +02006787 }
Johannes Bergdb9c64c2012-11-09 14:56:41 +01006788
Johannes Berg04a773a2009-04-19 21:24:32 +02006789 ibss.channel_fixed = !!info->attrs[NL80211_ATTR_FREQ_FIXED];
Johannes Bergfffd0932009-07-08 14:22:54 +02006790 ibss.privacy = !!info->attrs[NL80211_ATTR_PRIVACY];
Johannes Berg04a773a2009-04-19 21:24:32 +02006791
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03006792 if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) {
6793 u8 *rates =
6794 nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
6795 int n_rates =
6796 nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
6797 struct ieee80211_supported_band *sband =
Johannes Berg683b6d32012-11-08 21:25:48 +01006798 wiphy->bands[ibss.chandef.chan->band];
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03006799
Johannes Berg34850ab2011-07-18 18:08:35 +02006800 err = ieee80211_get_ratemask(sband, rates, n_rates,
6801 &ibss.basic_rates);
6802 if (err)
6803 return err;
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03006804 }
Felix Fietkaudd5b4cc2010-11-22 20:58:24 +01006805
Simon Wunderlich803768f2013-06-28 10:39:58 +02006806 if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
6807 memcpy(&ibss.ht_capa_mask,
6808 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]),
6809 sizeof(ibss.ht_capa_mask));
6810
6811 if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) {
6812 if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
6813 return -EINVAL;
6814 memcpy(&ibss.ht_capa,
6815 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]),
6816 sizeof(ibss.ht_capa));
6817 }
6818
Felix Fietkaudd5b4cc2010-11-22 20:58:24 +01006819 if (info->attrs[NL80211_ATTR_MCAST_RATE] &&
6820 !nl80211_parse_mcast_rate(rdev, ibss.mcast_rate,
6821 nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE])))
6822 return -EINVAL;
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03006823
Johannes Berg4c476992010-10-04 21:36:35 +02006824 if (ibss.privacy && info->attrs[NL80211_ATTR_KEYS]) {
Sujith Manoharande7044e2012-10-18 10:19:28 +05306825 bool no_ht = false;
6826
Johannes Berg4c476992010-10-04 21:36:35 +02006827 connkeys = nl80211_parse_connkeys(rdev,
Sujith Manoharande7044e2012-10-18 10:19:28 +05306828 info->attrs[NL80211_ATTR_KEYS],
6829 &no_ht);
Johannes Berg4c476992010-10-04 21:36:35 +02006830 if (IS_ERR(connkeys))
6831 return PTR_ERR(connkeys);
Sujith Manoharande7044e2012-10-18 10:19:28 +05306832
Johannes Berg3d9d1d62012-11-08 23:14:50 +01006833 if ((ibss.chandef.width != NL80211_CHAN_WIDTH_20_NOHT) &&
6834 no_ht) {
Sujith Manoharande7044e2012-10-18 10:19:28 +05306835 kfree(connkeys);
6836 return -EINVAL;
6837 }
Johannes Berg4c476992010-10-04 21:36:35 +02006838 }
Johannes Berg04a773a2009-04-19 21:24:32 +02006839
Antonio Quartulli267335d2012-01-31 20:25:47 +01006840 ibss.control_port =
6841 nla_get_flag(info->attrs[NL80211_ATTR_CONTROL_PORT]);
6842
Simon Wunderlich5336fa82013-10-07 18:41:05 +02006843 ibss.userspace_handles_dfs =
6844 nla_get_flag(info->attrs[NL80211_ATTR_HANDLE_DFS]);
6845
Johannes Berg4c476992010-10-04 21:36:35 +02006846 err = cfg80211_join_ibss(rdev, dev, &ibss, connkeys);
Johannes Bergfffd0932009-07-08 14:22:54 +02006847 if (err)
6848 kfree(connkeys);
Johannes Berg04a773a2009-04-19 21:24:32 +02006849 return err;
6850}
6851
6852static int nl80211_leave_ibss(struct sk_buff *skb, struct genl_info *info)
6853{
Johannes Berg4c476992010-10-04 21:36:35 +02006854 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6855 struct net_device *dev = info->user_ptr[1];
Johannes Berg04a773a2009-04-19 21:24:32 +02006856
Johannes Berg4c476992010-10-04 21:36:35 +02006857 if (!rdev->ops->leave_ibss)
6858 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02006859
Johannes Berg4c476992010-10-04 21:36:35 +02006860 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC)
6861 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02006862
Johannes Berg4c476992010-10-04 21:36:35 +02006863 return cfg80211_leave_ibss(rdev, dev, false);
Johannes Berg04a773a2009-04-19 21:24:32 +02006864}
6865
Antonio Quartullif4e583c2012-11-02 13:27:48 +01006866static int nl80211_set_mcast_rate(struct sk_buff *skb, struct genl_info *info)
6867{
6868 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6869 struct net_device *dev = info->user_ptr[1];
6870 int mcast_rate[IEEE80211_NUM_BANDS];
6871 u32 nla_rate;
6872 int err;
6873
6874 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC &&
6875 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
6876 return -EOPNOTSUPP;
6877
6878 if (!rdev->ops->set_mcast_rate)
6879 return -EOPNOTSUPP;
6880
6881 memset(mcast_rate, 0, sizeof(mcast_rate));
6882
6883 if (!info->attrs[NL80211_ATTR_MCAST_RATE])
6884 return -EINVAL;
6885
6886 nla_rate = nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]);
6887 if (!nl80211_parse_mcast_rate(rdev, mcast_rate, nla_rate))
6888 return -EINVAL;
6889
6890 err = rdev->ops->set_mcast_rate(&rdev->wiphy, dev, mcast_rate);
6891
6892 return err;
6893}
6894
Johannes Bergad7e7182013-11-13 13:37:47 +01006895static struct sk_buff *
6896__cfg80211_alloc_vendor_skb(struct cfg80211_registered_device *rdev,
6897 int approxlen, u32 portid, u32 seq,
6898 enum nl80211_commands cmd,
Johannes Berg567ffc32013-12-18 14:43:31 +01006899 enum nl80211_attrs attr,
6900 const struct nl80211_vendor_cmd_info *info,
6901 gfp_t gfp)
Johannes Bergad7e7182013-11-13 13:37:47 +01006902{
6903 struct sk_buff *skb;
6904 void *hdr;
6905 struct nlattr *data;
6906
6907 skb = nlmsg_new(approxlen + 100, gfp);
6908 if (!skb)
6909 return NULL;
6910
6911 hdr = nl80211hdr_put(skb, portid, seq, 0, cmd);
6912 if (!hdr) {
6913 kfree_skb(skb);
6914 return NULL;
6915 }
6916
6917 if (nla_put_u32(skb, NL80211_ATTR_WIPHY, rdev->wiphy_idx))
6918 goto nla_put_failure;
Johannes Berg567ffc32013-12-18 14:43:31 +01006919
6920 if (info) {
6921 if (nla_put_u32(skb, NL80211_ATTR_VENDOR_ID,
6922 info->vendor_id))
6923 goto nla_put_failure;
6924 if (nla_put_u32(skb, NL80211_ATTR_VENDOR_SUBCMD,
6925 info->subcmd))
6926 goto nla_put_failure;
6927 }
6928
Johannes Bergad7e7182013-11-13 13:37:47 +01006929 data = nla_nest_start(skb, attr);
6930
6931 ((void **)skb->cb)[0] = rdev;
6932 ((void **)skb->cb)[1] = hdr;
6933 ((void **)skb->cb)[2] = data;
6934
6935 return skb;
6936
6937 nla_put_failure:
6938 kfree_skb(skb);
6939 return NULL;
6940}
Antonio Quartullif4e583c2012-11-02 13:27:48 +01006941
Johannes Berge03ad6e2014-01-01 17:22:30 +01006942struct sk_buff *__cfg80211_alloc_event_skb(struct wiphy *wiphy,
6943 enum nl80211_commands cmd,
6944 enum nl80211_attrs attr,
6945 int vendor_event_idx,
6946 int approxlen, gfp_t gfp)
6947{
Zhao, Gangf26cbf42014-04-21 12:53:03 +08006948 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berge03ad6e2014-01-01 17:22:30 +01006949 const struct nl80211_vendor_cmd_info *info;
6950
6951 switch (cmd) {
6952 case NL80211_CMD_TESTMODE:
6953 if (WARN_ON(vendor_event_idx != -1))
6954 return NULL;
6955 info = NULL;
6956 break;
6957 case NL80211_CMD_VENDOR:
6958 if (WARN_ON(vendor_event_idx < 0 ||
6959 vendor_event_idx >= wiphy->n_vendor_events))
6960 return NULL;
6961 info = &wiphy->vendor_events[vendor_event_idx];
6962 break;
6963 default:
6964 WARN_ON(1);
6965 return NULL;
6966 }
6967
6968 return __cfg80211_alloc_vendor_skb(rdev, approxlen, 0, 0,
6969 cmd, attr, info, gfp);
6970}
6971EXPORT_SYMBOL(__cfg80211_alloc_event_skb);
6972
6973void __cfg80211_send_event_skb(struct sk_buff *skb, gfp_t gfp)
6974{
6975 struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0];
6976 void *hdr = ((void **)skb->cb)[1];
6977 struct nlattr *data = ((void **)skb->cb)[2];
6978 enum nl80211_multicast_groups mcgrp = NL80211_MCGRP_TESTMODE;
6979
6980 nla_nest_end(skb, data);
6981 genlmsg_end(skb, hdr);
6982
6983 if (data->nla_type == NL80211_ATTR_VENDOR_DATA)
6984 mcgrp = NL80211_MCGRP_VENDOR;
6985
6986 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), skb, 0,
6987 mcgrp, gfp);
6988}
6989EXPORT_SYMBOL(__cfg80211_send_event_skb);
6990
Johannes Bergaff89a92009-07-01 21:26:51 +02006991#ifdef CONFIG_NL80211_TESTMODE
Johannes Bergaff89a92009-07-01 21:26:51 +02006992static int nl80211_testmode_do(struct sk_buff *skb, struct genl_info *info)
6993{
Johannes Berg4c476992010-10-04 21:36:35 +02006994 struct cfg80211_registered_device *rdev = info->user_ptr[0];
David Spinadelfc73f112013-07-31 18:04:15 +03006995 struct wireless_dev *wdev =
6996 __cfg80211_wdev_from_attrs(genl_info_net(info), info->attrs);
Johannes Bergaff89a92009-07-01 21:26:51 +02006997 int err;
6998
David Spinadelfc73f112013-07-31 18:04:15 +03006999 if (!rdev->ops->testmode_cmd)
7000 return -EOPNOTSUPP;
7001
7002 if (IS_ERR(wdev)) {
7003 err = PTR_ERR(wdev);
7004 if (err != -EINVAL)
7005 return err;
7006 wdev = NULL;
7007 } else if (wdev->wiphy != &rdev->wiphy) {
7008 return -EINVAL;
7009 }
7010
Johannes Bergaff89a92009-07-01 21:26:51 +02007011 if (!info->attrs[NL80211_ATTR_TESTDATA])
7012 return -EINVAL;
7013
Johannes Bergad7e7182013-11-13 13:37:47 +01007014 rdev->cur_cmd_info = info;
David Spinadelfc73f112013-07-31 18:04:15 +03007015 err = rdev_testmode_cmd(rdev, wdev,
Johannes Bergaff89a92009-07-01 21:26:51 +02007016 nla_data(info->attrs[NL80211_ATTR_TESTDATA]),
7017 nla_len(info->attrs[NL80211_ATTR_TESTDATA]));
Johannes Bergad7e7182013-11-13 13:37:47 +01007018 rdev->cur_cmd_info = NULL;
Johannes Bergaff89a92009-07-01 21:26:51 +02007019
Johannes Bergaff89a92009-07-01 21:26:51 +02007020 return err;
7021}
7022
Wey-Yi Guy71063f02011-05-20 09:05:54 -07007023static int nl80211_testmode_dump(struct sk_buff *skb,
7024 struct netlink_callback *cb)
7025{
Johannes Berg00918d32011-12-13 17:22:05 +01007026 struct cfg80211_registered_device *rdev;
Wey-Yi Guy71063f02011-05-20 09:05:54 -07007027 int err;
7028 long phy_idx;
7029 void *data = NULL;
7030 int data_len = 0;
7031
Johannes Berg5fe231e2013-05-08 21:45:15 +02007032 rtnl_lock();
7033
Wey-Yi Guy71063f02011-05-20 09:05:54 -07007034 if (cb->args[0]) {
7035 /*
7036 * 0 is a valid index, but not valid for args[0],
7037 * so we need to offset by 1.
7038 */
7039 phy_idx = cb->args[0] - 1;
7040 } else {
7041 err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize,
7042 nl80211_fam.attrbuf, nl80211_fam.maxattr,
7043 nl80211_policy);
7044 if (err)
Johannes Berg5fe231e2013-05-08 21:45:15 +02007045 goto out_err;
Johannes Berg00918d32011-12-13 17:22:05 +01007046
Johannes Berg2bd7e352012-06-15 14:23:16 +02007047 rdev = __cfg80211_rdev_from_attrs(sock_net(skb->sk),
7048 nl80211_fam.attrbuf);
7049 if (IS_ERR(rdev)) {
Johannes Berg5fe231e2013-05-08 21:45:15 +02007050 err = PTR_ERR(rdev);
7051 goto out_err;
Johannes Berg00918d32011-12-13 17:22:05 +01007052 }
Johannes Berg2bd7e352012-06-15 14:23:16 +02007053 phy_idx = rdev->wiphy_idx;
7054 rdev = NULL;
Johannes Berg2bd7e352012-06-15 14:23:16 +02007055
Wey-Yi Guy71063f02011-05-20 09:05:54 -07007056 if (nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA])
7057 cb->args[1] =
7058 (long)nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA];
7059 }
7060
7061 if (cb->args[1]) {
7062 data = nla_data((void *)cb->args[1]);
7063 data_len = nla_len((void *)cb->args[1]);
7064 }
7065
Johannes Berg00918d32011-12-13 17:22:05 +01007066 rdev = cfg80211_rdev_by_wiphy_idx(phy_idx);
7067 if (!rdev) {
Johannes Berg5fe231e2013-05-08 21:45:15 +02007068 err = -ENOENT;
7069 goto out_err;
Wey-Yi Guy71063f02011-05-20 09:05:54 -07007070 }
Wey-Yi Guy71063f02011-05-20 09:05:54 -07007071
Johannes Berg00918d32011-12-13 17:22:05 +01007072 if (!rdev->ops->testmode_dump) {
Wey-Yi Guy71063f02011-05-20 09:05:54 -07007073 err = -EOPNOTSUPP;
7074 goto out_err;
7075 }
7076
7077 while (1) {
Eric W. Biederman15e47302012-09-07 20:12:54 +00007078 void *hdr = nl80211hdr_put(skb, NETLINK_CB(cb->skb).portid,
Wey-Yi Guy71063f02011-05-20 09:05:54 -07007079 cb->nlh->nlmsg_seq, NLM_F_MULTI,
7080 NL80211_CMD_TESTMODE);
7081 struct nlattr *tmdata;
7082
Dan Carpentercb35fba2013-08-14 14:50:01 +03007083 if (!hdr)
7084 break;
7085
David S. Miller9360ffd2012-03-29 04:41:26 -04007086 if (nla_put_u32(skb, NL80211_ATTR_WIPHY, phy_idx)) {
Wey-Yi Guy71063f02011-05-20 09:05:54 -07007087 genlmsg_cancel(skb, hdr);
7088 break;
7089 }
7090
7091 tmdata = nla_nest_start(skb, NL80211_ATTR_TESTDATA);
7092 if (!tmdata) {
7093 genlmsg_cancel(skb, hdr);
7094 break;
7095 }
Hila Gonene35e4d22012-06-27 17:19:42 +03007096 err = rdev_testmode_dump(rdev, skb, cb, data, data_len);
Wey-Yi Guy71063f02011-05-20 09:05:54 -07007097 nla_nest_end(skb, tmdata);
7098
7099 if (err == -ENOBUFS || err == -ENOENT) {
7100 genlmsg_cancel(skb, hdr);
7101 break;
7102 } else if (err) {
7103 genlmsg_cancel(skb, hdr);
7104 goto out_err;
7105 }
7106
7107 genlmsg_end(skb, hdr);
7108 }
7109
7110 err = skb->len;
7111 /* see above */
7112 cb->args[0] = phy_idx + 1;
7113 out_err:
Johannes Berg5fe231e2013-05-08 21:45:15 +02007114 rtnl_unlock();
Wey-Yi Guy71063f02011-05-20 09:05:54 -07007115 return err;
7116}
Johannes Bergaff89a92009-07-01 21:26:51 +02007117#endif
7118
Samuel Ortizb23aa672009-07-01 21:26:54 +02007119static int nl80211_connect(struct sk_buff *skb, struct genl_info *info)
7120{
Johannes Berg4c476992010-10-04 21:36:35 +02007121 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7122 struct net_device *dev = info->user_ptr[1];
Samuel Ortizb23aa672009-07-01 21:26:54 +02007123 struct cfg80211_connect_params connect;
7124 struct wiphy *wiphy;
Johannes Bergfffd0932009-07-08 14:22:54 +02007125 struct cfg80211_cached_keys *connkeys = NULL;
Samuel Ortizb23aa672009-07-01 21:26:54 +02007126 int err;
7127
7128 memset(&connect, 0, sizeof(connect));
7129
7130 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
7131 return -EINVAL;
7132
7133 if (!info->attrs[NL80211_ATTR_SSID] ||
7134 !nla_len(info->attrs[NL80211_ATTR_SSID]))
7135 return -EINVAL;
7136
7137 if (info->attrs[NL80211_ATTR_AUTH_TYPE]) {
7138 connect.auth_type =
7139 nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]);
Jouni Malinene39e5b52012-09-30 19:29:39 +03007140 if (!nl80211_valid_auth_type(rdev, connect.auth_type,
7141 NL80211_CMD_CONNECT))
Samuel Ortizb23aa672009-07-01 21:26:54 +02007142 return -EINVAL;
7143 } else
7144 connect.auth_type = NL80211_AUTHTYPE_AUTOMATIC;
7145
7146 connect.privacy = info->attrs[NL80211_ATTR_PRIVACY];
7147
Johannes Bergc0692b82010-08-27 14:26:53 +03007148 err = nl80211_crypto_settings(rdev, info, &connect.crypto,
Johannes Berg3dc27d22009-07-02 21:36:37 +02007149 NL80211_MAX_NR_CIPHER_SUITES);
Samuel Ortizb23aa672009-07-01 21:26:54 +02007150 if (err)
7151 return err;
Samuel Ortizb23aa672009-07-01 21:26:54 +02007152
Johannes Berg074ac8d2010-09-16 14:58:22 +02007153 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02007154 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
7155 return -EOPNOTSUPP;
Samuel Ortizb23aa672009-07-01 21:26:54 +02007156
Johannes Berg79c97e92009-07-07 03:56:12 +02007157 wiphy = &rdev->wiphy;
Samuel Ortizb23aa672009-07-01 21:26:54 +02007158
Bala Shanmugam4486ea92012-03-07 17:27:12 +05307159 connect.bg_scan_period = -1;
7160 if (info->attrs[NL80211_ATTR_BG_SCAN_PERIOD] &&
7161 (wiphy->flags & WIPHY_FLAG_SUPPORTS_FW_ROAM)) {
7162 connect.bg_scan_period =
7163 nla_get_u16(info->attrs[NL80211_ATTR_BG_SCAN_PERIOD]);
7164 }
7165
Samuel Ortizb23aa672009-07-01 21:26:54 +02007166 if (info->attrs[NL80211_ATTR_MAC])
7167 connect.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen1df4a512014-01-15 00:00:47 +02007168 else if (info->attrs[NL80211_ATTR_MAC_HINT])
7169 connect.bssid_hint =
7170 nla_data(info->attrs[NL80211_ATTR_MAC_HINT]);
Samuel Ortizb23aa672009-07-01 21:26:54 +02007171 connect.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
7172 connect.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
7173
7174 if (info->attrs[NL80211_ATTR_IE]) {
7175 connect.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
7176 connect.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
7177 }
7178
Jouni Malinencee00a92013-01-15 17:15:57 +02007179 if (info->attrs[NL80211_ATTR_USE_MFP]) {
7180 connect.mfp = nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]);
7181 if (connect.mfp != NL80211_MFP_REQUIRED &&
7182 connect.mfp != NL80211_MFP_NO)
7183 return -EINVAL;
7184 } else {
7185 connect.mfp = NL80211_MFP_NO;
7186 }
7187
Samuel Ortizb23aa672009-07-01 21:26:54 +02007188 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
Jouni Malinen664834d2014-01-15 00:01:44 +02007189 connect.channel = nl80211_get_valid_chan(
7190 wiphy, info->attrs[NL80211_ATTR_WIPHY_FREQ]);
7191 if (!connect.channel)
Johannes Berg4c476992010-10-04 21:36:35 +02007192 return -EINVAL;
Jouni Malinen1df4a512014-01-15 00:00:47 +02007193 } else if (info->attrs[NL80211_ATTR_WIPHY_FREQ_HINT]) {
Jouni Malinen664834d2014-01-15 00:01:44 +02007194 connect.channel_hint = nl80211_get_valid_chan(
7195 wiphy, info->attrs[NL80211_ATTR_WIPHY_FREQ_HINT]);
7196 if (!connect.channel_hint)
Jouni Malinen1df4a512014-01-15 00:00:47 +02007197 return -EINVAL;
Samuel Ortizb23aa672009-07-01 21:26:54 +02007198 }
7199
Johannes Bergfffd0932009-07-08 14:22:54 +02007200 if (connect.privacy && info->attrs[NL80211_ATTR_KEYS]) {
7201 connkeys = nl80211_parse_connkeys(rdev,
Sujith Manoharande7044e2012-10-18 10:19:28 +05307202 info->attrs[NL80211_ATTR_KEYS], NULL);
Johannes Berg4c476992010-10-04 21:36:35 +02007203 if (IS_ERR(connkeys))
7204 return PTR_ERR(connkeys);
Johannes Bergfffd0932009-07-08 14:22:54 +02007205 }
7206
Ben Greear7e7c8922011-11-18 11:31:59 -08007207 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT]))
7208 connect.flags |= ASSOC_REQ_DISABLE_HT;
7209
7210 if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
7211 memcpy(&connect.ht_capa_mask,
7212 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]),
7213 sizeof(connect.ht_capa_mask));
7214
7215 if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) {
Wei Yongjunb4e4f472012-09-02 21:41:04 +08007216 if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) {
7217 kfree(connkeys);
Ben Greear7e7c8922011-11-18 11:31:59 -08007218 return -EINVAL;
Wei Yongjunb4e4f472012-09-02 21:41:04 +08007219 }
Ben Greear7e7c8922011-11-18 11:31:59 -08007220 memcpy(&connect.ht_capa,
7221 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]),
7222 sizeof(connect.ht_capa));
7223 }
7224
Johannes Bergee2aca32013-02-21 17:36:01 +01007225 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_VHT]))
7226 connect.flags |= ASSOC_REQ_DISABLE_VHT;
7227
7228 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK])
7229 memcpy(&connect.vht_capa_mask,
7230 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]),
7231 sizeof(connect.vht_capa_mask));
7232
7233 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) {
7234 if (!info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) {
7235 kfree(connkeys);
7236 return -EINVAL;
7237 }
7238 memcpy(&connect.vht_capa,
7239 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]),
7240 sizeof(connect.vht_capa));
7241 }
7242
Johannes Berg83739b02013-05-15 17:44:01 +02007243 wdev_lock(dev->ieee80211_ptr);
7244 err = cfg80211_connect(rdev, dev, &connect, connkeys, NULL);
7245 wdev_unlock(dev->ieee80211_ptr);
Johannes Bergfffd0932009-07-08 14:22:54 +02007246 if (err)
7247 kfree(connkeys);
Samuel Ortizb23aa672009-07-01 21:26:54 +02007248 return err;
7249}
7250
7251static int nl80211_disconnect(struct sk_buff *skb, struct genl_info *info)
7252{
Johannes Berg4c476992010-10-04 21:36:35 +02007253 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7254 struct net_device *dev = info->user_ptr[1];
Samuel Ortizb23aa672009-07-01 21:26:54 +02007255 u16 reason;
Johannes Berg83739b02013-05-15 17:44:01 +02007256 int ret;
Samuel Ortizb23aa672009-07-01 21:26:54 +02007257
7258 if (!info->attrs[NL80211_ATTR_REASON_CODE])
7259 reason = WLAN_REASON_DEAUTH_LEAVING;
7260 else
7261 reason = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
7262
7263 if (reason == 0)
7264 return -EINVAL;
7265
Johannes Berg074ac8d2010-09-16 14:58:22 +02007266 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02007267 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
7268 return -EOPNOTSUPP;
Samuel Ortizb23aa672009-07-01 21:26:54 +02007269
Johannes Berg83739b02013-05-15 17:44:01 +02007270 wdev_lock(dev->ieee80211_ptr);
7271 ret = cfg80211_disconnect(rdev, dev, reason, true);
7272 wdev_unlock(dev->ieee80211_ptr);
7273 return ret;
Samuel Ortizb23aa672009-07-01 21:26:54 +02007274}
7275
Johannes Berg463d0182009-07-14 00:33:35 +02007276static int nl80211_wiphy_netns(struct sk_buff *skb, struct genl_info *info)
7277{
Johannes Berg4c476992010-10-04 21:36:35 +02007278 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg463d0182009-07-14 00:33:35 +02007279 struct net *net;
7280 int err;
7281 u32 pid;
7282
7283 if (!info->attrs[NL80211_ATTR_PID])
7284 return -EINVAL;
7285
7286 pid = nla_get_u32(info->attrs[NL80211_ATTR_PID]);
7287
Johannes Berg463d0182009-07-14 00:33:35 +02007288 net = get_net_ns_by_pid(pid);
Johannes Berg4c476992010-10-04 21:36:35 +02007289 if (IS_ERR(net))
7290 return PTR_ERR(net);
Johannes Berg463d0182009-07-14 00:33:35 +02007291
7292 err = 0;
7293
7294 /* check if anything to do */
Johannes Berg4c476992010-10-04 21:36:35 +02007295 if (!net_eq(wiphy_net(&rdev->wiphy), net))
7296 err = cfg80211_switch_netns(rdev, net);
Johannes Berg463d0182009-07-14 00:33:35 +02007297
Johannes Berg463d0182009-07-14 00:33:35 +02007298 put_net(net);
Johannes Berg463d0182009-07-14 00:33:35 +02007299 return err;
7300}
7301
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007302static int nl80211_setdel_pmksa(struct sk_buff *skb, struct genl_info *info)
7303{
Johannes Berg4c476992010-10-04 21:36:35 +02007304 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007305 int (*rdev_ops)(struct wiphy *wiphy, struct net_device *dev,
7306 struct cfg80211_pmksa *pmksa) = NULL;
Johannes Berg4c476992010-10-04 21:36:35 +02007307 struct net_device *dev = info->user_ptr[1];
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007308 struct cfg80211_pmksa pmksa;
7309
7310 memset(&pmksa, 0, sizeof(struct cfg80211_pmksa));
7311
7312 if (!info->attrs[NL80211_ATTR_MAC])
7313 return -EINVAL;
7314
7315 if (!info->attrs[NL80211_ATTR_PMKID])
7316 return -EINVAL;
7317
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007318 pmksa.pmkid = nla_data(info->attrs[NL80211_ATTR_PMKID]);
7319 pmksa.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
7320
Johannes Berg074ac8d2010-09-16 14:58:22 +02007321 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02007322 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
7323 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007324
7325 switch (info->genlhdr->cmd) {
7326 case NL80211_CMD_SET_PMKSA:
7327 rdev_ops = rdev->ops->set_pmksa;
7328 break;
7329 case NL80211_CMD_DEL_PMKSA:
7330 rdev_ops = rdev->ops->del_pmksa;
7331 break;
7332 default:
7333 WARN_ON(1);
7334 break;
7335 }
7336
Johannes Berg4c476992010-10-04 21:36:35 +02007337 if (!rdev_ops)
7338 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007339
Johannes Berg4c476992010-10-04 21:36:35 +02007340 return rdev_ops(&rdev->wiphy, dev, &pmksa);
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007341}
7342
7343static int nl80211_flush_pmksa(struct sk_buff *skb, struct genl_info *info)
7344{
Johannes Berg4c476992010-10-04 21:36:35 +02007345 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7346 struct net_device *dev = info->user_ptr[1];
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007347
Johannes Berg074ac8d2010-09-16 14:58:22 +02007348 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02007349 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
7350 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007351
Johannes Berg4c476992010-10-04 21:36:35 +02007352 if (!rdev->ops->flush_pmksa)
7353 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007354
Hila Gonene35e4d22012-06-27 17:19:42 +03007355 return rdev_flush_pmksa(rdev, dev);
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007356}
7357
Arik Nemtsov109086c2011-09-28 14:12:50 +03007358static int nl80211_tdls_mgmt(struct sk_buff *skb, struct genl_info *info)
7359{
7360 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7361 struct net_device *dev = info->user_ptr[1];
7362 u8 action_code, dialog_token;
Sunil Dutt Undekaridf942e72014-02-20 16:22:09 +05307363 u32 peer_capability = 0;
Arik Nemtsov109086c2011-09-28 14:12:50 +03007364 u16 status_code;
7365 u8 *peer;
Arik Nemtsov31fa97c2014-06-11 17:18:21 +03007366 bool initiator;
Arik Nemtsov109086c2011-09-28 14:12:50 +03007367
7368 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) ||
7369 !rdev->ops->tdls_mgmt)
7370 return -EOPNOTSUPP;
7371
7372 if (!info->attrs[NL80211_ATTR_TDLS_ACTION] ||
7373 !info->attrs[NL80211_ATTR_STATUS_CODE] ||
7374 !info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN] ||
7375 !info->attrs[NL80211_ATTR_IE] ||
7376 !info->attrs[NL80211_ATTR_MAC])
7377 return -EINVAL;
7378
7379 peer = nla_data(info->attrs[NL80211_ATTR_MAC]);
7380 action_code = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_ACTION]);
7381 status_code = nla_get_u16(info->attrs[NL80211_ATTR_STATUS_CODE]);
7382 dialog_token = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN]);
Arik Nemtsov31fa97c2014-06-11 17:18:21 +03007383 initiator = nla_get_flag(info->attrs[NL80211_ATTR_TDLS_INITIATOR]);
Sunil Dutt Undekaridf942e72014-02-20 16:22:09 +05307384 if (info->attrs[NL80211_ATTR_TDLS_PEER_CAPABILITY])
7385 peer_capability =
7386 nla_get_u32(info->attrs[NL80211_ATTR_TDLS_PEER_CAPABILITY]);
Arik Nemtsov109086c2011-09-28 14:12:50 +03007387
Hila Gonene35e4d22012-06-27 17:19:42 +03007388 return rdev_tdls_mgmt(rdev, dev, peer, action_code,
Sunil Dutt Undekaridf942e72014-02-20 16:22:09 +05307389 dialog_token, status_code, peer_capability,
Arik Nemtsov31fa97c2014-06-11 17:18:21 +03007390 initiator,
Hila Gonene35e4d22012-06-27 17:19:42 +03007391 nla_data(info->attrs[NL80211_ATTR_IE]),
7392 nla_len(info->attrs[NL80211_ATTR_IE]));
Arik Nemtsov109086c2011-09-28 14:12:50 +03007393}
7394
7395static int nl80211_tdls_oper(struct sk_buff *skb, struct genl_info *info)
7396{
7397 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7398 struct net_device *dev = info->user_ptr[1];
7399 enum nl80211_tdls_operation operation;
7400 u8 *peer;
7401
7402 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) ||
7403 !rdev->ops->tdls_oper)
7404 return -EOPNOTSUPP;
7405
7406 if (!info->attrs[NL80211_ATTR_TDLS_OPERATION] ||
7407 !info->attrs[NL80211_ATTR_MAC])
7408 return -EINVAL;
7409
7410 operation = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_OPERATION]);
7411 peer = nla_data(info->attrs[NL80211_ATTR_MAC]);
7412
Hila Gonene35e4d22012-06-27 17:19:42 +03007413 return rdev_tdls_oper(rdev, dev, peer, operation);
Arik Nemtsov109086c2011-09-28 14:12:50 +03007414}
7415
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007416static int nl80211_remain_on_channel(struct sk_buff *skb,
7417 struct genl_info *info)
7418{
Johannes Berg4c476992010-10-04 21:36:35 +02007419 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02007420 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg683b6d32012-11-08 21:25:48 +01007421 struct cfg80211_chan_def chandef;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007422 struct sk_buff *msg;
7423 void *hdr;
7424 u64 cookie;
Johannes Berg683b6d32012-11-08 21:25:48 +01007425 u32 duration;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007426 int err;
7427
7428 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] ||
7429 !info->attrs[NL80211_ATTR_DURATION])
7430 return -EINVAL;
7431
7432 duration = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]);
7433
Johannes Berg7c4ef712011-11-18 15:33:48 +01007434 if (!rdev->ops->remain_on_channel ||
7435 !(rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL))
Johannes Berg4c476992010-10-04 21:36:35 +02007436 return -EOPNOTSUPP;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007437
Johannes Bergebf348f2012-06-01 12:50:54 +02007438 /*
7439 * We should be on that channel for at least a minimum amount of
7440 * time (10ms) but no longer than the driver supports.
7441 */
7442 if (duration < NL80211_MIN_REMAIN_ON_CHANNEL_TIME ||
7443 duration > rdev->wiphy.max_remain_on_channel_duration)
7444 return -EINVAL;
7445
Johannes Berg683b6d32012-11-08 21:25:48 +01007446 err = nl80211_parse_chandef(rdev, info, &chandef);
7447 if (err)
7448 return err;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007449
7450 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02007451 if (!msg)
7452 return -ENOMEM;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007453
Eric W. Biederman15e47302012-09-07 20:12:54 +00007454 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007455 NL80211_CMD_REMAIN_ON_CHANNEL);
Dan Carpentercb35fba2013-08-14 14:50:01 +03007456 if (!hdr) {
7457 err = -ENOBUFS;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007458 goto free_msg;
7459 }
7460
Johannes Berg683b6d32012-11-08 21:25:48 +01007461 err = rdev_remain_on_channel(rdev, wdev, chandef.chan,
7462 duration, &cookie);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007463
7464 if (err)
7465 goto free_msg;
7466
David S. Miller9360ffd2012-03-29 04:41:26 -04007467 if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie))
7468 goto nla_put_failure;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007469
7470 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02007471
7472 return genlmsg_reply(msg, info);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007473
7474 nla_put_failure:
7475 err = -ENOBUFS;
7476 free_msg:
7477 nlmsg_free(msg);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007478 return err;
7479}
7480
7481static int nl80211_cancel_remain_on_channel(struct sk_buff *skb,
7482 struct genl_info *info)
7483{
Johannes Berg4c476992010-10-04 21:36:35 +02007484 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02007485 struct wireless_dev *wdev = info->user_ptr[1];
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007486 u64 cookie;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007487
7488 if (!info->attrs[NL80211_ATTR_COOKIE])
7489 return -EINVAL;
7490
Johannes Berg4c476992010-10-04 21:36:35 +02007491 if (!rdev->ops->cancel_remain_on_channel)
7492 return -EOPNOTSUPP;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007493
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007494 cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]);
7495
Hila Gonene35e4d22012-06-27 17:19:42 +03007496 return rdev_cancel_remain_on_channel(rdev, wdev, cookie);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007497}
7498
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007499static u32 rateset_to_mask(struct ieee80211_supported_band *sband,
7500 u8 *rates, u8 rates_len)
7501{
7502 u8 i;
7503 u32 mask = 0;
7504
7505 for (i = 0; i < rates_len; i++) {
7506 int rate = (rates[i] & 0x7f) * 5;
7507 int ridx;
7508 for (ridx = 0; ridx < sband->n_bitrates; ridx++) {
7509 struct ieee80211_rate *srate =
7510 &sband->bitrates[ridx];
7511 if (rate == srate->bitrate) {
7512 mask |= 1 << ridx;
7513 break;
7514 }
7515 }
7516 if (ridx == sband->n_bitrates)
7517 return 0; /* rate not found */
7518 }
7519
7520 return mask;
7521}
7522
Simon Wunderlich24db78c2012-01-28 17:25:32 +01007523static bool ht_rateset_to_mask(struct ieee80211_supported_band *sband,
7524 u8 *rates, u8 rates_len,
7525 u8 mcs[IEEE80211_HT_MCS_MASK_LEN])
7526{
7527 u8 i;
7528
7529 memset(mcs, 0, IEEE80211_HT_MCS_MASK_LEN);
7530
7531 for (i = 0; i < rates_len; i++) {
7532 int ridx, rbit;
7533
7534 ridx = rates[i] / 8;
7535 rbit = BIT(rates[i] % 8);
7536
7537 /* check validity */
Dan Carpenter910570b52012-02-01 10:42:11 +03007538 if ((ridx < 0) || (ridx >= IEEE80211_HT_MCS_MASK_LEN))
Simon Wunderlich24db78c2012-01-28 17:25:32 +01007539 return false;
7540
7541 /* check availability */
7542 if (sband->ht_cap.mcs.rx_mask[ridx] & rbit)
7543 mcs[ridx] |= rbit;
7544 else
7545 return false;
7546 }
7547
7548 return true;
7549}
7550
Janusz Dziedzic204e35a2013-12-05 20:42:58 +01007551static u16 vht_mcs_map_to_mcs_mask(u8 vht_mcs_map)
7552{
7553 u16 mcs_mask = 0;
7554
7555 switch (vht_mcs_map) {
7556 case IEEE80211_VHT_MCS_NOT_SUPPORTED:
7557 break;
7558 case IEEE80211_VHT_MCS_SUPPORT_0_7:
7559 mcs_mask = 0x00FF;
7560 break;
7561 case IEEE80211_VHT_MCS_SUPPORT_0_8:
7562 mcs_mask = 0x01FF;
7563 break;
7564 case IEEE80211_VHT_MCS_SUPPORT_0_9:
7565 mcs_mask = 0x03FF;
7566 break;
7567 default:
7568 break;
7569 }
7570
7571 return mcs_mask;
7572}
7573
7574static void vht_build_mcs_mask(u16 vht_mcs_map,
7575 u16 vht_mcs_mask[NL80211_VHT_NSS_MAX])
7576{
7577 u8 nss;
7578
7579 for (nss = 0; nss < NL80211_VHT_NSS_MAX; nss++) {
7580 vht_mcs_mask[nss] = vht_mcs_map_to_mcs_mask(vht_mcs_map & 0x03);
7581 vht_mcs_map >>= 2;
7582 }
7583}
7584
7585static bool vht_set_mcs_mask(struct ieee80211_supported_band *sband,
7586 struct nl80211_txrate_vht *txrate,
7587 u16 mcs[NL80211_VHT_NSS_MAX])
7588{
7589 u16 tx_mcs_map = le16_to_cpu(sband->vht_cap.vht_mcs.tx_mcs_map);
7590 u16 tx_mcs_mask[NL80211_VHT_NSS_MAX] = {};
7591 u8 i;
7592
7593 if (!sband->vht_cap.vht_supported)
7594 return false;
7595
7596 memset(mcs, 0, sizeof(u16) * NL80211_VHT_NSS_MAX);
7597
7598 /* Build vht_mcs_mask from VHT capabilities */
7599 vht_build_mcs_mask(tx_mcs_map, tx_mcs_mask);
7600
7601 for (i = 0; i < NL80211_VHT_NSS_MAX; i++) {
7602 if ((tx_mcs_mask[i] & txrate->mcs[i]) == txrate->mcs[i])
7603 mcs[i] = txrate->mcs[i];
7604 else
7605 return false;
7606 }
7607
7608 return true;
7609}
7610
Alexey Dobriyanb54452b2010-02-18 08:14:31 +00007611static const struct nla_policy nl80211_txattr_policy[NL80211_TXRATE_MAX + 1] = {
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007612 [NL80211_TXRATE_LEGACY] = { .type = NLA_BINARY,
7613 .len = NL80211_MAX_SUPP_RATES },
Janusz Dziedzicd1e33e62013-12-05 10:02:15 +01007614 [NL80211_TXRATE_HT] = { .type = NLA_BINARY,
7615 .len = NL80211_MAX_SUPP_HT_RATES },
Janusz Dziedzic204e35a2013-12-05 20:42:58 +01007616 [NL80211_TXRATE_VHT] = { .len = sizeof(struct nl80211_txrate_vht)},
Janusz Dziedzic0b9323f2014-01-08 08:46:02 +01007617 [NL80211_TXRATE_GI] = { .type = NLA_U8 },
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007618};
7619
7620static int nl80211_set_tx_bitrate_mask(struct sk_buff *skb,
7621 struct genl_info *info)
7622{
7623 struct nlattr *tb[NL80211_TXRATE_MAX + 1];
Johannes Berg4c476992010-10-04 21:36:35 +02007624 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007625 struct cfg80211_bitrate_mask mask;
Johannes Berg4c476992010-10-04 21:36:35 +02007626 int rem, i;
7627 struct net_device *dev = info->user_ptr[1];
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007628 struct nlattr *tx_rates;
7629 struct ieee80211_supported_band *sband;
Janusz Dziedzic204e35a2013-12-05 20:42:58 +01007630 u16 vht_tx_mcs_map;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007631
Johannes Berg4c476992010-10-04 21:36:35 +02007632 if (!rdev->ops->set_bitrate_mask)
7633 return -EOPNOTSUPP;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007634
7635 memset(&mask, 0, sizeof(mask));
7636 /* Default to all rates enabled */
7637 for (i = 0; i < IEEE80211_NUM_BANDS; i++) {
7638 sband = rdev->wiphy.bands[i];
Janusz Dziedzic78693032013-12-03 09:50:44 +01007639
7640 if (!sband)
7641 continue;
7642
7643 mask.control[i].legacy = (1 << sband->n_bitrates) - 1;
Janusz Dziedzicd1e33e62013-12-05 10:02:15 +01007644 memcpy(mask.control[i].ht_mcs,
Janusz Dziedzic78693032013-12-03 09:50:44 +01007645 sband->ht_cap.mcs.rx_mask,
Janusz Dziedzicd1e33e62013-12-05 10:02:15 +01007646 sizeof(mask.control[i].ht_mcs));
Janusz Dziedzic204e35a2013-12-05 20:42:58 +01007647
7648 if (!sband->vht_cap.vht_supported)
7649 continue;
7650
7651 vht_tx_mcs_map = le16_to_cpu(sband->vht_cap.vht_mcs.tx_mcs_map);
7652 vht_build_mcs_mask(vht_tx_mcs_map, mask.control[i].vht_mcs);
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007653 }
7654
Janusz Dziedzicb9243ab2013-12-05 10:02:14 +01007655 /* if no rates are given set it back to the defaults */
7656 if (!info->attrs[NL80211_ATTR_TX_RATES])
7657 goto out;
7658
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007659 /*
7660 * The nested attribute uses enum nl80211_band as the index. This maps
7661 * directly to the enum ieee80211_band values used in cfg80211.
7662 */
Simon Wunderlich24db78c2012-01-28 17:25:32 +01007663 BUILD_BUG_ON(NL80211_MAX_SUPP_HT_RATES > IEEE80211_HT_MCS_MASK_LEN * 8);
Johannes Bergae811e22014-01-24 10:17:47 +01007664 nla_for_each_nested(tx_rates, info->attrs[NL80211_ATTR_TX_RATES], rem) {
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007665 enum ieee80211_band band = nla_type(tx_rates);
Johannes Bergae811e22014-01-24 10:17:47 +01007666 int err;
7667
Johannes Berg4c476992010-10-04 21:36:35 +02007668 if (band < 0 || band >= IEEE80211_NUM_BANDS)
7669 return -EINVAL;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007670 sband = rdev->wiphy.bands[band];
Johannes Berg4c476992010-10-04 21:36:35 +02007671 if (sband == NULL)
7672 return -EINVAL;
Johannes Bergae811e22014-01-24 10:17:47 +01007673 err = nla_parse(tb, NL80211_TXRATE_MAX, nla_data(tx_rates),
7674 nla_len(tx_rates), nl80211_txattr_policy);
7675 if (err)
7676 return err;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007677 if (tb[NL80211_TXRATE_LEGACY]) {
7678 mask.control[band].legacy = rateset_to_mask(
7679 sband,
7680 nla_data(tb[NL80211_TXRATE_LEGACY]),
7681 nla_len(tb[NL80211_TXRATE_LEGACY]));
Bala Shanmugam218d2e22012-04-20 19:12:58 +05307682 if ((mask.control[band].legacy == 0) &&
7683 nla_len(tb[NL80211_TXRATE_LEGACY]))
7684 return -EINVAL;
Simon Wunderlich24db78c2012-01-28 17:25:32 +01007685 }
Janusz Dziedzicd1e33e62013-12-05 10:02:15 +01007686 if (tb[NL80211_TXRATE_HT]) {
Simon Wunderlich24db78c2012-01-28 17:25:32 +01007687 if (!ht_rateset_to_mask(
7688 sband,
Janusz Dziedzicd1e33e62013-12-05 10:02:15 +01007689 nla_data(tb[NL80211_TXRATE_HT]),
7690 nla_len(tb[NL80211_TXRATE_HT]),
7691 mask.control[band].ht_mcs))
Simon Wunderlich24db78c2012-01-28 17:25:32 +01007692 return -EINVAL;
7693 }
Janusz Dziedzic204e35a2013-12-05 20:42:58 +01007694 if (tb[NL80211_TXRATE_VHT]) {
7695 if (!vht_set_mcs_mask(
7696 sband,
7697 nla_data(tb[NL80211_TXRATE_VHT]),
7698 mask.control[band].vht_mcs))
7699 return -EINVAL;
7700 }
Janusz Dziedzic0b9323f2014-01-08 08:46:02 +01007701 if (tb[NL80211_TXRATE_GI]) {
7702 mask.control[band].gi =
7703 nla_get_u8(tb[NL80211_TXRATE_GI]);
7704 if (mask.control[band].gi > NL80211_TXRATE_FORCE_LGI)
7705 return -EINVAL;
7706 }
Simon Wunderlich24db78c2012-01-28 17:25:32 +01007707
7708 if (mask.control[band].legacy == 0) {
Janusz Dziedzic204e35a2013-12-05 20:42:58 +01007709 /* don't allow empty legacy rates if HT or VHT
7710 * are not even supported.
7711 */
7712 if (!(rdev->wiphy.bands[band]->ht_cap.ht_supported ||
7713 rdev->wiphy.bands[band]->vht_cap.vht_supported))
Simon Wunderlich24db78c2012-01-28 17:25:32 +01007714 return -EINVAL;
7715
7716 for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++)
Janusz Dziedzicd1e33e62013-12-05 10:02:15 +01007717 if (mask.control[band].ht_mcs[i])
Janusz Dziedzic204e35a2013-12-05 20:42:58 +01007718 goto out;
7719
7720 for (i = 0; i < NL80211_VHT_NSS_MAX; i++)
7721 if (mask.control[band].vht_mcs[i])
7722 goto out;
Simon Wunderlich24db78c2012-01-28 17:25:32 +01007723
7724 /* legacy and mcs rates may not be both empty */
Janusz Dziedzic204e35a2013-12-05 20:42:58 +01007725 return -EINVAL;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007726 }
7727 }
7728
Janusz Dziedzicb9243ab2013-12-05 10:02:14 +01007729out:
Hila Gonene35e4d22012-06-27 17:19:42 +03007730 return rdev_set_bitrate_mask(rdev, dev, NULL, &mask);
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007731}
7732
Johannes Berg2e161f72010-08-12 15:38:38 +02007733static int nl80211_register_mgmt(struct sk_buff *skb, struct genl_info *info)
Jouni Malinen026331c2010-02-15 12:53:10 +02007734{
Johannes Berg4c476992010-10-04 21:36:35 +02007735 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02007736 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg2e161f72010-08-12 15:38:38 +02007737 u16 frame_type = IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_ACTION;
Jouni Malinen026331c2010-02-15 12:53:10 +02007738
7739 if (!info->attrs[NL80211_ATTR_FRAME_MATCH])
7740 return -EINVAL;
7741
Johannes Berg2e161f72010-08-12 15:38:38 +02007742 if (info->attrs[NL80211_ATTR_FRAME_TYPE])
7743 frame_type = nla_get_u16(info->attrs[NL80211_ATTR_FRAME_TYPE]);
Jouni Malinen026331c2010-02-15 12:53:10 +02007744
Johannes Berg71bbc992012-06-15 15:30:18 +02007745 switch (wdev->iftype) {
7746 case NL80211_IFTYPE_STATION:
7747 case NL80211_IFTYPE_ADHOC:
7748 case NL80211_IFTYPE_P2P_CLIENT:
7749 case NL80211_IFTYPE_AP:
7750 case NL80211_IFTYPE_AP_VLAN:
7751 case NL80211_IFTYPE_MESH_POINT:
7752 case NL80211_IFTYPE_P2P_GO:
Johannes Berg98104fde2012-06-16 00:19:54 +02007753 case NL80211_IFTYPE_P2P_DEVICE:
Johannes Berg71bbc992012-06-15 15:30:18 +02007754 break;
7755 default:
Johannes Berg4c476992010-10-04 21:36:35 +02007756 return -EOPNOTSUPP;
Johannes Berg71bbc992012-06-15 15:30:18 +02007757 }
Jouni Malinen026331c2010-02-15 12:53:10 +02007758
7759 /* not much point in registering if we can't reply */
Johannes Berg4c476992010-10-04 21:36:35 +02007760 if (!rdev->ops->mgmt_tx)
7761 return -EOPNOTSUPP;
Jouni Malinen026331c2010-02-15 12:53:10 +02007762
Eric W. Biederman15e47302012-09-07 20:12:54 +00007763 return cfg80211_mlme_register_mgmt(wdev, info->snd_portid, frame_type,
Jouni Malinen026331c2010-02-15 12:53:10 +02007764 nla_data(info->attrs[NL80211_ATTR_FRAME_MATCH]),
7765 nla_len(info->attrs[NL80211_ATTR_FRAME_MATCH]));
Jouni Malinen026331c2010-02-15 12:53:10 +02007766}
7767
Johannes Berg2e161f72010-08-12 15:38:38 +02007768static int nl80211_tx_mgmt(struct sk_buff *skb, struct genl_info *info)
Jouni Malinen026331c2010-02-15 12:53:10 +02007769{
Johannes Berg4c476992010-10-04 21:36:35 +02007770 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02007771 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg683b6d32012-11-08 21:25:48 +01007772 struct cfg80211_chan_def chandef;
Jouni Malinen026331c2010-02-15 12:53:10 +02007773 int err;
Johannes Bergd64d3732011-11-10 09:44:46 +01007774 void *hdr = NULL;
Jouni Malinen026331c2010-02-15 12:53:10 +02007775 u64 cookie;
Johannes Berge247bd902011-11-04 11:18:21 +01007776 struct sk_buff *msg = NULL;
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02007777 struct cfg80211_mgmt_tx_params params = {
7778 .dont_wait_for_ack =
7779 info->attrs[NL80211_ATTR_DONT_WAIT_FOR_ACK],
7780 };
Jouni Malinen026331c2010-02-15 12:53:10 +02007781
Johannes Berg683b6d32012-11-08 21:25:48 +01007782 if (!info->attrs[NL80211_ATTR_FRAME])
Jouni Malinen026331c2010-02-15 12:53:10 +02007783 return -EINVAL;
7784
Johannes Berg4c476992010-10-04 21:36:35 +02007785 if (!rdev->ops->mgmt_tx)
7786 return -EOPNOTSUPP;
Jouni Malinen026331c2010-02-15 12:53:10 +02007787
Johannes Berg71bbc992012-06-15 15:30:18 +02007788 switch (wdev->iftype) {
Antonio Quartulliea141b752013-06-11 14:20:03 +02007789 case NL80211_IFTYPE_P2P_DEVICE:
7790 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ])
7791 return -EINVAL;
Johannes Berg71bbc992012-06-15 15:30:18 +02007792 case NL80211_IFTYPE_STATION:
7793 case NL80211_IFTYPE_ADHOC:
7794 case NL80211_IFTYPE_P2P_CLIENT:
7795 case NL80211_IFTYPE_AP:
7796 case NL80211_IFTYPE_AP_VLAN:
7797 case NL80211_IFTYPE_MESH_POINT:
7798 case NL80211_IFTYPE_P2P_GO:
7799 break;
7800 default:
Johannes Berg4c476992010-10-04 21:36:35 +02007801 return -EOPNOTSUPP;
Johannes Berg71bbc992012-06-15 15:30:18 +02007802 }
Jouni Malinen026331c2010-02-15 12:53:10 +02007803
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007804 if (info->attrs[NL80211_ATTR_DURATION]) {
Johannes Berg7c4ef712011-11-18 15:33:48 +01007805 if (!(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX))
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007806 return -EINVAL;
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02007807 params.wait = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]);
Johannes Bergebf348f2012-06-01 12:50:54 +02007808
7809 /*
7810 * We should wait on the channel for at least a minimum amount
7811 * of time (10ms) but no longer than the driver supports.
7812 */
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02007813 if (params.wait < NL80211_MIN_REMAIN_ON_CHANNEL_TIME ||
7814 params.wait > rdev->wiphy.max_remain_on_channel_duration)
Johannes Bergebf348f2012-06-01 12:50:54 +02007815 return -EINVAL;
7816
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007817 }
7818
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02007819 params.offchan = info->attrs[NL80211_ATTR_OFFCHANNEL_TX_OK];
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007820
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02007821 if (params.offchan && !(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX))
Johannes Berg7c4ef712011-11-18 15:33:48 +01007822 return -EINVAL;
7823
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02007824 params.no_cck = nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]);
Rajkumar Manoharane9f935e2011-09-25 14:53:30 +05307825
Antonio Quartulliea141b752013-06-11 14:20:03 +02007826 /* get the channel if any has been specified, otherwise pass NULL to
7827 * the driver. The latter will use the current one
7828 */
7829 chandef.chan = NULL;
7830 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
7831 err = nl80211_parse_chandef(rdev, info, &chandef);
7832 if (err)
7833 return err;
7834 }
7835
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02007836 if (!chandef.chan && params.offchan)
Antonio Quartulliea141b752013-06-11 14:20:03 +02007837 return -EINVAL;
Jouni Malinen026331c2010-02-15 12:53:10 +02007838
Andrei Otcheretianski34d22ce2014-05-09 14:11:44 +03007839 params.buf = nla_data(info->attrs[NL80211_ATTR_FRAME]);
7840 params.len = nla_len(info->attrs[NL80211_ATTR_FRAME]);
7841
7842 if (info->attrs[NL80211_ATTR_CSA_C_OFFSETS_TX]) {
7843 int len = nla_len(info->attrs[NL80211_ATTR_CSA_C_OFFSETS_TX]);
7844 int i;
7845
7846 if (len % sizeof(u16))
7847 return -EINVAL;
7848
7849 params.n_csa_offsets = len / sizeof(u16);
7850 params.csa_offsets =
7851 nla_data(info->attrs[NL80211_ATTR_CSA_C_OFFSETS_TX]);
7852
7853 /* check that all the offsets fit the frame */
7854 for (i = 0; i < params.n_csa_offsets; i++) {
7855 if (params.csa_offsets[i] >= params.len)
7856 return -EINVAL;
7857 }
7858 }
7859
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02007860 if (!params.dont_wait_for_ack) {
Johannes Berge247bd902011-11-04 11:18:21 +01007861 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
7862 if (!msg)
7863 return -ENOMEM;
Jouni Malinen026331c2010-02-15 12:53:10 +02007864
Eric W. Biederman15e47302012-09-07 20:12:54 +00007865 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berge247bd902011-11-04 11:18:21 +01007866 NL80211_CMD_FRAME);
Dan Carpentercb35fba2013-08-14 14:50:01 +03007867 if (!hdr) {
7868 err = -ENOBUFS;
Johannes Berge247bd902011-11-04 11:18:21 +01007869 goto free_msg;
7870 }
Jouni Malinen026331c2010-02-15 12:53:10 +02007871 }
Johannes Berge247bd902011-11-04 11:18:21 +01007872
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02007873 params.chan = chandef.chan;
7874 err = cfg80211_mlme_mgmt_tx(rdev, wdev, &params, &cookie);
Jouni Malinen026331c2010-02-15 12:53:10 +02007875 if (err)
7876 goto free_msg;
7877
Johannes Berge247bd902011-11-04 11:18:21 +01007878 if (msg) {
David S. Miller9360ffd2012-03-29 04:41:26 -04007879 if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie))
7880 goto nla_put_failure;
Jouni Malinen026331c2010-02-15 12:53:10 +02007881
Johannes Berge247bd902011-11-04 11:18:21 +01007882 genlmsg_end(msg, hdr);
7883 return genlmsg_reply(msg, info);
7884 }
7885
7886 return 0;
Jouni Malinen026331c2010-02-15 12:53:10 +02007887
7888 nla_put_failure:
7889 err = -ENOBUFS;
7890 free_msg:
7891 nlmsg_free(msg);
Jouni Malinen026331c2010-02-15 12:53:10 +02007892 return err;
7893}
7894
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007895static int nl80211_tx_mgmt_cancel_wait(struct sk_buff *skb, struct genl_info *info)
7896{
7897 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02007898 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007899 u64 cookie;
7900
7901 if (!info->attrs[NL80211_ATTR_COOKIE])
7902 return -EINVAL;
7903
7904 if (!rdev->ops->mgmt_tx_cancel_wait)
7905 return -EOPNOTSUPP;
7906
Johannes Berg71bbc992012-06-15 15:30:18 +02007907 switch (wdev->iftype) {
7908 case NL80211_IFTYPE_STATION:
7909 case NL80211_IFTYPE_ADHOC:
7910 case NL80211_IFTYPE_P2P_CLIENT:
7911 case NL80211_IFTYPE_AP:
7912 case NL80211_IFTYPE_AP_VLAN:
7913 case NL80211_IFTYPE_P2P_GO:
Johannes Berg98104fde2012-06-16 00:19:54 +02007914 case NL80211_IFTYPE_P2P_DEVICE:
Johannes Berg71bbc992012-06-15 15:30:18 +02007915 break;
7916 default:
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007917 return -EOPNOTSUPP;
Johannes Berg71bbc992012-06-15 15:30:18 +02007918 }
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007919
7920 cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]);
7921
Hila Gonene35e4d22012-06-27 17:19:42 +03007922 return rdev_mgmt_tx_cancel_wait(rdev, wdev, cookie);
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007923}
7924
Kalle Valoffb9eb32010-02-17 17:58:10 +02007925static int nl80211_set_power_save(struct sk_buff *skb, struct genl_info *info)
7926{
Johannes Berg4c476992010-10-04 21:36:35 +02007927 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Kalle Valoffb9eb32010-02-17 17:58:10 +02007928 struct wireless_dev *wdev;
Johannes Berg4c476992010-10-04 21:36:35 +02007929 struct net_device *dev = info->user_ptr[1];
Kalle Valoffb9eb32010-02-17 17:58:10 +02007930 u8 ps_state;
7931 bool state;
7932 int err;
7933
Johannes Berg4c476992010-10-04 21:36:35 +02007934 if (!info->attrs[NL80211_ATTR_PS_STATE])
7935 return -EINVAL;
Kalle Valoffb9eb32010-02-17 17:58:10 +02007936
7937 ps_state = nla_get_u32(info->attrs[NL80211_ATTR_PS_STATE]);
7938
Johannes Berg4c476992010-10-04 21:36:35 +02007939 if (ps_state != NL80211_PS_DISABLED && ps_state != NL80211_PS_ENABLED)
7940 return -EINVAL;
Kalle Valoffb9eb32010-02-17 17:58:10 +02007941
7942 wdev = dev->ieee80211_ptr;
7943
Johannes Berg4c476992010-10-04 21:36:35 +02007944 if (!rdev->ops->set_power_mgmt)
7945 return -EOPNOTSUPP;
Kalle Valoffb9eb32010-02-17 17:58:10 +02007946
7947 state = (ps_state == NL80211_PS_ENABLED) ? true : false;
7948
7949 if (state == wdev->ps)
Johannes Berg4c476992010-10-04 21:36:35 +02007950 return 0;
Kalle Valoffb9eb32010-02-17 17:58:10 +02007951
Hila Gonene35e4d22012-06-27 17:19:42 +03007952 err = rdev_set_power_mgmt(rdev, dev, state, wdev->ps_timeout);
Johannes Berg4c476992010-10-04 21:36:35 +02007953 if (!err)
7954 wdev->ps = state;
Kalle Valoffb9eb32010-02-17 17:58:10 +02007955 return err;
7956}
7957
7958static int nl80211_get_power_save(struct sk_buff *skb, struct genl_info *info)
7959{
Johannes Berg4c476992010-10-04 21:36:35 +02007960 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Kalle Valoffb9eb32010-02-17 17:58:10 +02007961 enum nl80211_ps_state ps_state;
7962 struct wireless_dev *wdev;
Johannes Berg4c476992010-10-04 21:36:35 +02007963 struct net_device *dev = info->user_ptr[1];
Kalle Valoffb9eb32010-02-17 17:58:10 +02007964 struct sk_buff *msg;
7965 void *hdr;
7966 int err;
7967
Kalle Valoffb9eb32010-02-17 17:58:10 +02007968 wdev = dev->ieee80211_ptr;
7969
Johannes Berg4c476992010-10-04 21:36:35 +02007970 if (!rdev->ops->set_power_mgmt)
7971 return -EOPNOTSUPP;
Kalle Valoffb9eb32010-02-17 17:58:10 +02007972
7973 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02007974 if (!msg)
7975 return -ENOMEM;
Kalle Valoffb9eb32010-02-17 17:58:10 +02007976
Eric W. Biederman15e47302012-09-07 20:12:54 +00007977 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Kalle Valoffb9eb32010-02-17 17:58:10 +02007978 NL80211_CMD_GET_POWER_SAVE);
7979 if (!hdr) {
Johannes Berg4c476992010-10-04 21:36:35 +02007980 err = -ENOBUFS;
Kalle Valoffb9eb32010-02-17 17:58:10 +02007981 goto free_msg;
7982 }
7983
7984 if (wdev->ps)
7985 ps_state = NL80211_PS_ENABLED;
7986 else
7987 ps_state = NL80211_PS_DISABLED;
7988
David S. Miller9360ffd2012-03-29 04:41:26 -04007989 if (nla_put_u32(msg, NL80211_ATTR_PS_STATE, ps_state))
7990 goto nla_put_failure;
Kalle Valoffb9eb32010-02-17 17:58:10 +02007991
7992 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02007993 return genlmsg_reply(msg, info);
Kalle Valoffb9eb32010-02-17 17:58:10 +02007994
Johannes Berg4c476992010-10-04 21:36:35 +02007995 nla_put_failure:
Kalle Valoffb9eb32010-02-17 17:58:10 +02007996 err = -ENOBUFS;
Johannes Berg4c476992010-10-04 21:36:35 +02007997 free_msg:
Kalle Valoffb9eb32010-02-17 17:58:10 +02007998 nlmsg_free(msg);
Kalle Valoffb9eb32010-02-17 17:58:10 +02007999 return err;
8000}
8001
Johannes Berg94e860f2014-01-20 23:58:15 +01008002static const struct nla_policy
8003nl80211_attr_cqm_policy[NL80211_ATTR_CQM_MAX + 1] = {
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008004 [NL80211_ATTR_CQM_RSSI_THOLD] = { .type = NLA_U32 },
8005 [NL80211_ATTR_CQM_RSSI_HYST] = { .type = NLA_U32 },
8006 [NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT] = { .type = NLA_U32 },
Thomas Pedersen84f10702012-07-12 16:17:33 -07008007 [NL80211_ATTR_CQM_TXE_RATE] = { .type = NLA_U32 },
8008 [NL80211_ATTR_CQM_TXE_PKTS] = { .type = NLA_U32 },
8009 [NL80211_ATTR_CQM_TXE_INTVL] = { .type = NLA_U32 },
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008010};
8011
Thomas Pedersen84f10702012-07-12 16:17:33 -07008012static int nl80211_set_cqm_txe(struct genl_info *info,
Johannes Bergd9d8b012012-11-26 12:51:52 +01008013 u32 rate, u32 pkts, u32 intvl)
Thomas Pedersen84f10702012-07-12 16:17:33 -07008014{
8015 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Thomas Pedersen84f10702012-07-12 16:17:33 -07008016 struct net_device *dev = info->user_ptr[1];
Johannes Berg1da5fcc2013-08-06 14:10:48 +02008017 struct wireless_dev *wdev = dev->ieee80211_ptr;
Thomas Pedersen84f10702012-07-12 16:17:33 -07008018
Johannes Bergd9d8b012012-11-26 12:51:52 +01008019 if (rate > 100 || intvl > NL80211_CQM_TXE_MAX_INTVL)
Thomas Pedersen84f10702012-07-12 16:17:33 -07008020 return -EINVAL;
8021
Thomas Pedersen84f10702012-07-12 16:17:33 -07008022 if (!rdev->ops->set_cqm_txe_config)
8023 return -EOPNOTSUPP;
8024
8025 if (wdev->iftype != NL80211_IFTYPE_STATION &&
8026 wdev->iftype != NL80211_IFTYPE_P2P_CLIENT)
8027 return -EOPNOTSUPP;
8028
Hila Gonene35e4d22012-06-27 17:19:42 +03008029 return rdev_set_cqm_txe_config(rdev, dev, rate, pkts, intvl);
Thomas Pedersen84f10702012-07-12 16:17:33 -07008030}
8031
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008032static int nl80211_set_cqm_rssi(struct genl_info *info,
8033 s32 threshold, u32 hysteresis)
8034{
Johannes Berg4c476992010-10-04 21:36:35 +02008035 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg4c476992010-10-04 21:36:35 +02008036 struct net_device *dev = info->user_ptr[1];
Johannes Berg1da5fcc2013-08-06 14:10:48 +02008037 struct wireless_dev *wdev = dev->ieee80211_ptr;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008038
8039 if (threshold > 0)
8040 return -EINVAL;
8041
Johannes Berg1da5fcc2013-08-06 14:10:48 +02008042 /* disabling - hysteresis should also be zero then */
8043 if (threshold == 0)
8044 hysteresis = 0;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008045
Johannes Berg4c476992010-10-04 21:36:35 +02008046 if (!rdev->ops->set_cqm_rssi_config)
8047 return -EOPNOTSUPP;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008048
Johannes Berg074ac8d2010-09-16 14:58:22 +02008049 if (wdev->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02008050 wdev->iftype != NL80211_IFTYPE_P2P_CLIENT)
8051 return -EOPNOTSUPP;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008052
Hila Gonene35e4d22012-06-27 17:19:42 +03008053 return rdev_set_cqm_rssi_config(rdev, dev, threshold, hysteresis);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008054}
8055
8056static int nl80211_set_cqm(struct sk_buff *skb, struct genl_info *info)
8057{
8058 struct nlattr *attrs[NL80211_ATTR_CQM_MAX + 1];
8059 struct nlattr *cqm;
8060 int err;
8061
8062 cqm = info->attrs[NL80211_ATTR_CQM];
Johannes Berg1da5fcc2013-08-06 14:10:48 +02008063 if (!cqm)
8064 return -EINVAL;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008065
8066 err = nla_parse_nested(attrs, NL80211_ATTR_CQM_MAX, cqm,
8067 nl80211_attr_cqm_policy);
8068 if (err)
Johannes Berg1da5fcc2013-08-06 14:10:48 +02008069 return err;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008070
8071 if (attrs[NL80211_ATTR_CQM_RSSI_THOLD] &&
8072 attrs[NL80211_ATTR_CQM_RSSI_HYST]) {
Johannes Berg1da5fcc2013-08-06 14:10:48 +02008073 s32 threshold = nla_get_s32(attrs[NL80211_ATTR_CQM_RSSI_THOLD]);
8074 u32 hysteresis = nla_get_u32(attrs[NL80211_ATTR_CQM_RSSI_HYST]);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008075
Johannes Berg1da5fcc2013-08-06 14:10:48 +02008076 return nl80211_set_cqm_rssi(info, threshold, hysteresis);
8077 }
8078
8079 if (attrs[NL80211_ATTR_CQM_TXE_RATE] &&
8080 attrs[NL80211_ATTR_CQM_TXE_PKTS] &&
8081 attrs[NL80211_ATTR_CQM_TXE_INTVL]) {
8082 u32 rate = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_RATE]);
8083 u32 pkts = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_PKTS]);
8084 u32 intvl = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_INTVL]);
8085
8086 return nl80211_set_cqm_txe(info, rate, pkts, intvl);
8087 }
8088
8089 return -EINVAL;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008090}
8091
Johannes Berg29cbe682010-12-03 09:20:44 +01008092static int nl80211_join_mesh(struct sk_buff *skb, struct genl_info *info)
8093{
8094 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8095 struct net_device *dev = info->user_ptr[1];
8096 struct mesh_config cfg;
Javier Cardonac80d5452010-12-16 17:37:49 -08008097 struct mesh_setup setup;
Johannes Berg29cbe682010-12-03 09:20:44 +01008098 int err;
8099
8100 /* start with default */
8101 memcpy(&cfg, &default_mesh_config, sizeof(cfg));
Javier Cardonac80d5452010-12-16 17:37:49 -08008102 memcpy(&setup, &default_mesh_setup, sizeof(setup));
Johannes Berg29cbe682010-12-03 09:20:44 +01008103
Javier Cardona24bdd9f2010-12-16 17:37:48 -08008104 if (info->attrs[NL80211_ATTR_MESH_CONFIG]) {
Johannes Berg29cbe682010-12-03 09:20:44 +01008105 /* and parse parameters if given */
Javier Cardona24bdd9f2010-12-16 17:37:48 -08008106 err = nl80211_parse_mesh_config(info, &cfg, NULL);
Johannes Berg29cbe682010-12-03 09:20:44 +01008107 if (err)
8108 return err;
8109 }
8110
8111 if (!info->attrs[NL80211_ATTR_MESH_ID] ||
8112 !nla_len(info->attrs[NL80211_ATTR_MESH_ID]))
8113 return -EINVAL;
8114
Javier Cardonac80d5452010-12-16 17:37:49 -08008115 setup.mesh_id = nla_data(info->attrs[NL80211_ATTR_MESH_ID]);
8116 setup.mesh_id_len = nla_len(info->attrs[NL80211_ATTR_MESH_ID]);
8117
Chun-Yeow Yeoh4bb62342011-11-24 17:15:20 -08008118 if (info->attrs[NL80211_ATTR_MCAST_RATE] &&
8119 !nl80211_parse_mcast_rate(rdev, setup.mcast_rate,
8120 nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE])))
8121 return -EINVAL;
8122
Marco Porsch9bdbf042013-01-07 16:04:51 +01008123 if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) {
8124 setup.beacon_interval =
8125 nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]);
8126 if (setup.beacon_interval < 10 ||
8127 setup.beacon_interval > 10000)
8128 return -EINVAL;
8129 }
8130
8131 if (info->attrs[NL80211_ATTR_DTIM_PERIOD]) {
8132 setup.dtim_period =
8133 nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]);
8134 if (setup.dtim_period < 1 || setup.dtim_period > 100)
8135 return -EINVAL;
8136 }
8137
Javier Cardonac80d5452010-12-16 17:37:49 -08008138 if (info->attrs[NL80211_ATTR_MESH_SETUP]) {
8139 /* parse additional setup parameters if given */
8140 err = nl80211_parse_mesh_setup(info, &setup);
8141 if (err)
8142 return err;
8143 }
8144
Thomas Pedersend37bb182013-03-04 13:06:13 -08008145 if (setup.user_mpm)
8146 cfg.auto_open_plinks = false;
8147
Johannes Bergcc1d2802012-05-16 23:50:20 +02008148 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
Johannes Berg683b6d32012-11-08 21:25:48 +01008149 err = nl80211_parse_chandef(rdev, info, &setup.chandef);
8150 if (err)
8151 return err;
Johannes Bergcc1d2802012-05-16 23:50:20 +02008152 } else {
8153 /* cfg80211_join_mesh() will sort it out */
Johannes Berg683b6d32012-11-08 21:25:48 +01008154 setup.chandef.chan = NULL;
Johannes Bergcc1d2802012-05-16 23:50:20 +02008155 }
8156
Ashok Nagarajanffb3cf32013-06-03 10:33:36 -07008157 if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) {
8158 u8 *rates = nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
8159 int n_rates =
8160 nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
8161 struct ieee80211_supported_band *sband;
8162
8163 if (!setup.chandef.chan)
8164 return -EINVAL;
8165
8166 sband = rdev->wiphy.bands[setup.chandef.chan->band];
8167
8168 err = ieee80211_get_ratemask(sband, rates, n_rates,
8169 &setup.basic_rates);
8170 if (err)
8171 return err;
8172 }
8173
Javier Cardonac80d5452010-12-16 17:37:49 -08008174 return cfg80211_join_mesh(rdev, dev, &setup, &cfg);
Johannes Berg29cbe682010-12-03 09:20:44 +01008175}
8176
8177static int nl80211_leave_mesh(struct sk_buff *skb, struct genl_info *info)
8178{
8179 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8180 struct net_device *dev = info->user_ptr[1];
8181
8182 return cfg80211_leave_mesh(rdev, dev);
8183}
8184
Johannes Bergdfb89c52012-06-27 09:23:48 +02008185#ifdef CONFIG_PM
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08008186static int nl80211_send_wowlan_patterns(struct sk_buff *msg,
8187 struct cfg80211_registered_device *rdev)
8188{
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008189 struct cfg80211_wowlan *wowlan = rdev->wiphy.wowlan_config;
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08008190 struct nlattr *nl_pats, *nl_pat;
8191 int i, pat_len;
8192
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008193 if (!wowlan->n_patterns)
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08008194 return 0;
8195
8196 nl_pats = nla_nest_start(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN);
8197 if (!nl_pats)
8198 return -ENOBUFS;
8199
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008200 for (i = 0; i < wowlan->n_patterns; i++) {
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08008201 nl_pat = nla_nest_start(msg, i + 1);
8202 if (!nl_pat)
8203 return -ENOBUFS;
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008204 pat_len = wowlan->patterns[i].pattern_len;
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07008205 if (nla_put(msg, NL80211_PKTPAT_MASK, DIV_ROUND_UP(pat_len, 8),
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008206 wowlan->patterns[i].mask) ||
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07008207 nla_put(msg, NL80211_PKTPAT_PATTERN, pat_len,
8208 wowlan->patterns[i].pattern) ||
8209 nla_put_u32(msg, NL80211_PKTPAT_OFFSET,
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008210 wowlan->patterns[i].pkt_offset))
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08008211 return -ENOBUFS;
8212 nla_nest_end(msg, nl_pat);
8213 }
8214 nla_nest_end(msg, nl_pats);
8215
8216 return 0;
8217}
8218
Johannes Berg2a0e0472013-01-23 22:57:40 +01008219static int nl80211_send_wowlan_tcp(struct sk_buff *msg,
8220 struct cfg80211_wowlan_tcp *tcp)
8221{
8222 struct nlattr *nl_tcp;
8223
8224 if (!tcp)
8225 return 0;
8226
8227 nl_tcp = nla_nest_start(msg, NL80211_WOWLAN_TRIG_TCP_CONNECTION);
8228 if (!nl_tcp)
8229 return -ENOBUFS;
8230
8231 if (nla_put_be32(msg, NL80211_WOWLAN_TCP_SRC_IPV4, tcp->src) ||
8232 nla_put_be32(msg, NL80211_WOWLAN_TCP_DST_IPV4, tcp->dst) ||
8233 nla_put(msg, NL80211_WOWLAN_TCP_DST_MAC, ETH_ALEN, tcp->dst_mac) ||
8234 nla_put_u16(msg, NL80211_WOWLAN_TCP_SRC_PORT, tcp->src_port) ||
8235 nla_put_u16(msg, NL80211_WOWLAN_TCP_DST_PORT, tcp->dst_port) ||
8236 nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD,
8237 tcp->payload_len, tcp->payload) ||
8238 nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_INTERVAL,
8239 tcp->data_interval) ||
8240 nla_put(msg, NL80211_WOWLAN_TCP_WAKE_PAYLOAD,
8241 tcp->wake_len, tcp->wake_data) ||
8242 nla_put(msg, NL80211_WOWLAN_TCP_WAKE_MASK,
8243 DIV_ROUND_UP(tcp->wake_len, 8), tcp->wake_mask))
8244 return -ENOBUFS;
8245
8246 if (tcp->payload_seq.len &&
8247 nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ,
8248 sizeof(tcp->payload_seq), &tcp->payload_seq))
8249 return -ENOBUFS;
8250
8251 if (tcp->payload_tok.len &&
8252 nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN,
8253 sizeof(tcp->payload_tok) + tcp->tokens_size,
8254 &tcp->payload_tok))
8255 return -ENOBUFS;
8256
Johannes Berge248ad32013-05-16 10:24:28 +02008257 nla_nest_end(msg, nl_tcp);
8258
Johannes Berg2a0e0472013-01-23 22:57:40 +01008259 return 0;
8260}
8261
Johannes Bergff1b6e62011-05-04 15:37:28 +02008262static int nl80211_get_wowlan(struct sk_buff *skb, struct genl_info *info)
8263{
8264 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8265 struct sk_buff *msg;
8266 void *hdr;
Johannes Berg2a0e0472013-01-23 22:57:40 +01008267 u32 size = NLMSG_DEFAULT_SIZE;
Johannes Bergff1b6e62011-05-04 15:37:28 +02008268
Johannes Berg964dc9e2013-06-03 17:25:34 +02008269 if (!rdev->wiphy.wowlan)
Johannes Bergff1b6e62011-05-04 15:37:28 +02008270 return -EOPNOTSUPP;
8271
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008272 if (rdev->wiphy.wowlan_config && rdev->wiphy.wowlan_config->tcp) {
Johannes Berg2a0e0472013-01-23 22:57:40 +01008273 /* adjust size to have room for all the data */
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008274 size += rdev->wiphy.wowlan_config->tcp->tokens_size +
8275 rdev->wiphy.wowlan_config->tcp->payload_len +
8276 rdev->wiphy.wowlan_config->tcp->wake_len +
8277 rdev->wiphy.wowlan_config->tcp->wake_len / 8;
Johannes Berg2a0e0472013-01-23 22:57:40 +01008278 }
8279
8280 msg = nlmsg_new(size, GFP_KERNEL);
Johannes Bergff1b6e62011-05-04 15:37:28 +02008281 if (!msg)
8282 return -ENOMEM;
8283
Eric W. Biederman15e47302012-09-07 20:12:54 +00008284 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Johannes Bergff1b6e62011-05-04 15:37:28 +02008285 NL80211_CMD_GET_WOWLAN);
8286 if (!hdr)
8287 goto nla_put_failure;
8288
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008289 if (rdev->wiphy.wowlan_config) {
Johannes Bergff1b6e62011-05-04 15:37:28 +02008290 struct nlattr *nl_wowlan;
8291
8292 nl_wowlan = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS);
8293 if (!nl_wowlan)
8294 goto nla_put_failure;
8295
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008296 if ((rdev->wiphy.wowlan_config->any &&
David S. Miller9360ffd2012-03-29 04:41:26 -04008297 nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008298 (rdev->wiphy.wowlan_config->disconnect &&
David S. Miller9360ffd2012-03-29 04:41:26 -04008299 nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008300 (rdev->wiphy.wowlan_config->magic_pkt &&
David S. Miller9360ffd2012-03-29 04:41:26 -04008301 nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008302 (rdev->wiphy.wowlan_config->gtk_rekey_failure &&
David S. Miller9360ffd2012-03-29 04:41:26 -04008303 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008304 (rdev->wiphy.wowlan_config->eap_identity_req &&
David S. Miller9360ffd2012-03-29 04:41:26 -04008305 nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008306 (rdev->wiphy.wowlan_config->four_way_handshake &&
David S. Miller9360ffd2012-03-29 04:41:26 -04008307 nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008308 (rdev->wiphy.wowlan_config->rfkill_release &&
David S. Miller9360ffd2012-03-29 04:41:26 -04008309 nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE)))
8310 goto nla_put_failure;
Johannes Berg2a0e0472013-01-23 22:57:40 +01008311
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08008312 if (nl80211_send_wowlan_patterns(msg, rdev))
8313 goto nla_put_failure;
Johannes Berg2a0e0472013-01-23 22:57:40 +01008314
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008315 if (nl80211_send_wowlan_tcp(msg,
8316 rdev->wiphy.wowlan_config->tcp))
Johannes Berg2a0e0472013-01-23 22:57:40 +01008317 goto nla_put_failure;
8318
Johannes Bergff1b6e62011-05-04 15:37:28 +02008319 nla_nest_end(msg, nl_wowlan);
8320 }
8321
8322 genlmsg_end(msg, hdr);
8323 return genlmsg_reply(msg, info);
8324
8325nla_put_failure:
8326 nlmsg_free(msg);
8327 return -ENOBUFS;
8328}
8329
Johannes Berg2a0e0472013-01-23 22:57:40 +01008330static int nl80211_parse_wowlan_tcp(struct cfg80211_registered_device *rdev,
8331 struct nlattr *attr,
8332 struct cfg80211_wowlan *trig)
8333{
8334 struct nlattr *tb[NUM_NL80211_WOWLAN_TCP];
8335 struct cfg80211_wowlan_tcp *cfg;
8336 struct nl80211_wowlan_tcp_data_token *tok = NULL;
8337 struct nl80211_wowlan_tcp_data_seq *seq = NULL;
8338 u32 size;
8339 u32 data_size, wake_size, tokens_size = 0, wake_mask_size;
8340 int err, port;
8341
Johannes Berg964dc9e2013-06-03 17:25:34 +02008342 if (!rdev->wiphy.wowlan->tcp)
Johannes Berg2a0e0472013-01-23 22:57:40 +01008343 return -EINVAL;
8344
8345 err = nla_parse(tb, MAX_NL80211_WOWLAN_TCP,
8346 nla_data(attr), nla_len(attr),
8347 nl80211_wowlan_tcp_policy);
8348 if (err)
8349 return err;
8350
8351 if (!tb[NL80211_WOWLAN_TCP_SRC_IPV4] ||
8352 !tb[NL80211_WOWLAN_TCP_DST_IPV4] ||
8353 !tb[NL80211_WOWLAN_TCP_DST_MAC] ||
8354 !tb[NL80211_WOWLAN_TCP_DST_PORT] ||
8355 !tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD] ||
8356 !tb[NL80211_WOWLAN_TCP_DATA_INTERVAL] ||
8357 !tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD] ||
8358 !tb[NL80211_WOWLAN_TCP_WAKE_MASK])
8359 return -EINVAL;
8360
8361 data_size = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]);
Johannes Berg964dc9e2013-06-03 17:25:34 +02008362 if (data_size > rdev->wiphy.wowlan->tcp->data_payload_max)
Johannes Berg2a0e0472013-01-23 22:57:40 +01008363 return -EINVAL;
8364
8365 if (nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]) >
Johannes Berg964dc9e2013-06-03 17:25:34 +02008366 rdev->wiphy.wowlan->tcp->data_interval_max ||
Johannes Berg723d5682013-02-26 13:56:40 +01008367 nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]) == 0)
Johannes Berg2a0e0472013-01-23 22:57:40 +01008368 return -EINVAL;
8369
8370 wake_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]);
Johannes Berg964dc9e2013-06-03 17:25:34 +02008371 if (wake_size > rdev->wiphy.wowlan->tcp->wake_payload_max)
Johannes Berg2a0e0472013-01-23 22:57:40 +01008372 return -EINVAL;
8373
8374 wake_mask_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_MASK]);
8375 if (wake_mask_size != DIV_ROUND_UP(wake_size, 8))
8376 return -EINVAL;
8377
8378 if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]) {
8379 u32 tokln = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]);
8380
8381 tok = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]);
8382 tokens_size = tokln - sizeof(*tok);
8383
8384 if (!tok->len || tokens_size % tok->len)
8385 return -EINVAL;
Johannes Berg964dc9e2013-06-03 17:25:34 +02008386 if (!rdev->wiphy.wowlan->tcp->tok)
Johannes Berg2a0e0472013-01-23 22:57:40 +01008387 return -EINVAL;
Johannes Berg964dc9e2013-06-03 17:25:34 +02008388 if (tok->len > rdev->wiphy.wowlan->tcp->tok->max_len)
Johannes Berg2a0e0472013-01-23 22:57:40 +01008389 return -EINVAL;
Johannes Berg964dc9e2013-06-03 17:25:34 +02008390 if (tok->len < rdev->wiphy.wowlan->tcp->tok->min_len)
Johannes Berg2a0e0472013-01-23 22:57:40 +01008391 return -EINVAL;
Johannes Berg964dc9e2013-06-03 17:25:34 +02008392 if (tokens_size > rdev->wiphy.wowlan->tcp->tok->bufsize)
Johannes Berg2a0e0472013-01-23 22:57:40 +01008393 return -EINVAL;
8394 if (tok->offset + tok->len > data_size)
8395 return -EINVAL;
8396 }
8397
8398 if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]) {
8399 seq = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]);
Johannes Berg964dc9e2013-06-03 17:25:34 +02008400 if (!rdev->wiphy.wowlan->tcp->seq)
Johannes Berg2a0e0472013-01-23 22:57:40 +01008401 return -EINVAL;
8402 if (seq->len == 0 || seq->len > 4)
8403 return -EINVAL;
8404 if (seq->len + seq->offset > data_size)
8405 return -EINVAL;
8406 }
8407
8408 size = sizeof(*cfg);
8409 size += data_size;
8410 size += wake_size + wake_mask_size;
8411 size += tokens_size;
8412
8413 cfg = kzalloc(size, GFP_KERNEL);
8414 if (!cfg)
8415 return -ENOMEM;
8416 cfg->src = nla_get_be32(tb[NL80211_WOWLAN_TCP_SRC_IPV4]);
8417 cfg->dst = nla_get_be32(tb[NL80211_WOWLAN_TCP_DST_IPV4]);
8418 memcpy(cfg->dst_mac, nla_data(tb[NL80211_WOWLAN_TCP_DST_MAC]),
8419 ETH_ALEN);
8420 if (tb[NL80211_WOWLAN_TCP_SRC_PORT])
8421 port = nla_get_u16(tb[NL80211_WOWLAN_TCP_SRC_PORT]);
8422 else
8423 port = 0;
8424#ifdef CONFIG_INET
8425 /* allocate a socket and port for it and use it */
8426 err = __sock_create(wiphy_net(&rdev->wiphy), PF_INET, SOCK_STREAM,
8427 IPPROTO_TCP, &cfg->sock, 1);
8428 if (err) {
8429 kfree(cfg);
8430 return err;
8431 }
8432 if (inet_csk_get_port(cfg->sock->sk, port)) {
8433 sock_release(cfg->sock);
8434 kfree(cfg);
8435 return -EADDRINUSE;
8436 }
8437 cfg->src_port = inet_sk(cfg->sock->sk)->inet_num;
8438#else
8439 if (!port) {
8440 kfree(cfg);
8441 return -EINVAL;
8442 }
8443 cfg->src_port = port;
8444#endif
8445
8446 cfg->dst_port = nla_get_u16(tb[NL80211_WOWLAN_TCP_DST_PORT]);
8447 cfg->payload_len = data_size;
8448 cfg->payload = (u8 *)cfg + sizeof(*cfg) + tokens_size;
8449 memcpy((void *)cfg->payload,
8450 nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]),
8451 data_size);
8452 if (seq)
8453 cfg->payload_seq = *seq;
8454 cfg->data_interval = nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]);
8455 cfg->wake_len = wake_size;
8456 cfg->wake_data = (u8 *)cfg + sizeof(*cfg) + tokens_size + data_size;
8457 memcpy((void *)cfg->wake_data,
8458 nla_data(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]),
8459 wake_size);
8460 cfg->wake_mask = (u8 *)cfg + sizeof(*cfg) + tokens_size +
8461 data_size + wake_size;
8462 memcpy((void *)cfg->wake_mask,
8463 nla_data(tb[NL80211_WOWLAN_TCP_WAKE_MASK]),
8464 wake_mask_size);
8465 if (tok) {
8466 cfg->tokens_size = tokens_size;
8467 memcpy(&cfg->payload_tok, tok, sizeof(*tok) + tokens_size);
8468 }
8469
8470 trig->tcp = cfg;
8471
8472 return 0;
8473}
8474
Johannes Bergff1b6e62011-05-04 15:37:28 +02008475static int nl80211_set_wowlan(struct sk_buff *skb, struct genl_info *info)
8476{
8477 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8478 struct nlattr *tb[NUM_NL80211_WOWLAN_TRIG];
Johannes Bergff1b6e62011-05-04 15:37:28 +02008479 struct cfg80211_wowlan new_triggers = {};
Johannes Bergae33bd82012-07-12 16:25:02 +02008480 struct cfg80211_wowlan *ntrig;
Johannes Berg964dc9e2013-06-03 17:25:34 +02008481 const struct wiphy_wowlan_support *wowlan = rdev->wiphy.wowlan;
Johannes Bergff1b6e62011-05-04 15:37:28 +02008482 int err, i;
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008483 bool prev_enabled = rdev->wiphy.wowlan_config;
Johannes Bergff1b6e62011-05-04 15:37:28 +02008484
Johannes Berg964dc9e2013-06-03 17:25:34 +02008485 if (!wowlan)
Johannes Bergff1b6e62011-05-04 15:37:28 +02008486 return -EOPNOTSUPP;
8487
Johannes Bergae33bd82012-07-12 16:25:02 +02008488 if (!info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]) {
8489 cfg80211_rdev_free_wowlan(rdev);
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008490 rdev->wiphy.wowlan_config = NULL;
Johannes Bergae33bd82012-07-12 16:25:02 +02008491 goto set_wakeup;
8492 }
Johannes Bergff1b6e62011-05-04 15:37:28 +02008493
8494 err = nla_parse(tb, MAX_NL80211_WOWLAN_TRIG,
8495 nla_data(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]),
8496 nla_len(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]),
8497 nl80211_wowlan_policy);
8498 if (err)
8499 return err;
8500
8501 if (tb[NL80211_WOWLAN_TRIG_ANY]) {
8502 if (!(wowlan->flags & WIPHY_WOWLAN_ANY))
8503 return -EINVAL;
8504 new_triggers.any = true;
8505 }
8506
8507 if (tb[NL80211_WOWLAN_TRIG_DISCONNECT]) {
8508 if (!(wowlan->flags & WIPHY_WOWLAN_DISCONNECT))
8509 return -EINVAL;
8510 new_triggers.disconnect = true;
8511 }
8512
8513 if (tb[NL80211_WOWLAN_TRIG_MAGIC_PKT]) {
8514 if (!(wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT))
8515 return -EINVAL;
8516 new_triggers.magic_pkt = true;
8517 }
8518
Johannes Berg77dbbb12011-07-13 10:48:55 +02008519 if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED])
8520 return -EINVAL;
8521
8522 if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE]) {
8523 if (!(wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE))
8524 return -EINVAL;
8525 new_triggers.gtk_rekey_failure = true;
8526 }
8527
8528 if (tb[NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST]) {
8529 if (!(wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ))
8530 return -EINVAL;
8531 new_triggers.eap_identity_req = true;
8532 }
8533
8534 if (tb[NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE]) {
8535 if (!(wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE))
8536 return -EINVAL;
8537 new_triggers.four_way_handshake = true;
8538 }
8539
8540 if (tb[NL80211_WOWLAN_TRIG_RFKILL_RELEASE]) {
8541 if (!(wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE))
8542 return -EINVAL;
8543 new_triggers.rfkill_release = true;
8544 }
8545
Johannes Bergff1b6e62011-05-04 15:37:28 +02008546 if (tb[NL80211_WOWLAN_TRIG_PKT_PATTERN]) {
8547 struct nlattr *pat;
8548 int n_patterns = 0;
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08008549 int rem, pat_len, mask_len, pkt_offset;
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07008550 struct nlattr *pat_tb[NUM_NL80211_PKTPAT];
Johannes Bergff1b6e62011-05-04 15:37:28 +02008551
8552 nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN],
8553 rem)
8554 n_patterns++;
8555 if (n_patterns > wowlan->n_patterns)
8556 return -EINVAL;
8557
8558 new_triggers.patterns = kcalloc(n_patterns,
8559 sizeof(new_triggers.patterns[0]),
8560 GFP_KERNEL);
8561 if (!new_triggers.patterns)
8562 return -ENOMEM;
8563
8564 new_triggers.n_patterns = n_patterns;
8565 i = 0;
8566
8567 nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN],
8568 rem) {
Johannes Berg922bd802014-05-19 17:59:50 +02008569 u8 *mask_pat;
8570
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07008571 nla_parse(pat_tb, MAX_NL80211_PKTPAT, nla_data(pat),
8572 nla_len(pat), NULL);
Johannes Bergff1b6e62011-05-04 15:37:28 +02008573 err = -EINVAL;
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07008574 if (!pat_tb[NL80211_PKTPAT_MASK] ||
8575 !pat_tb[NL80211_PKTPAT_PATTERN])
Johannes Bergff1b6e62011-05-04 15:37:28 +02008576 goto error;
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07008577 pat_len = nla_len(pat_tb[NL80211_PKTPAT_PATTERN]);
Johannes Bergff1b6e62011-05-04 15:37:28 +02008578 mask_len = DIV_ROUND_UP(pat_len, 8);
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07008579 if (nla_len(pat_tb[NL80211_PKTPAT_MASK]) != mask_len)
Johannes Bergff1b6e62011-05-04 15:37:28 +02008580 goto error;
8581 if (pat_len > wowlan->pattern_max_len ||
8582 pat_len < wowlan->pattern_min_len)
8583 goto error;
8584
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07008585 if (!pat_tb[NL80211_PKTPAT_OFFSET])
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08008586 pkt_offset = 0;
8587 else
8588 pkt_offset = nla_get_u32(
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07008589 pat_tb[NL80211_PKTPAT_OFFSET]);
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08008590 if (pkt_offset > wowlan->max_pkt_offset)
8591 goto error;
8592 new_triggers.patterns[i].pkt_offset = pkt_offset;
8593
Johannes Berg922bd802014-05-19 17:59:50 +02008594 mask_pat = kmalloc(mask_len + pat_len, GFP_KERNEL);
8595 if (!mask_pat) {
Johannes Bergff1b6e62011-05-04 15:37:28 +02008596 err = -ENOMEM;
8597 goto error;
8598 }
Johannes Berg922bd802014-05-19 17:59:50 +02008599 new_triggers.patterns[i].mask = mask_pat;
8600 memcpy(mask_pat, nla_data(pat_tb[NL80211_PKTPAT_MASK]),
Johannes Bergff1b6e62011-05-04 15:37:28 +02008601 mask_len);
Johannes Berg922bd802014-05-19 17:59:50 +02008602 mask_pat += mask_len;
8603 new_triggers.patterns[i].pattern = mask_pat;
Johannes Bergff1b6e62011-05-04 15:37:28 +02008604 new_triggers.patterns[i].pattern_len = pat_len;
Johannes Berg922bd802014-05-19 17:59:50 +02008605 memcpy(mask_pat,
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07008606 nla_data(pat_tb[NL80211_PKTPAT_PATTERN]),
Johannes Bergff1b6e62011-05-04 15:37:28 +02008607 pat_len);
8608 i++;
8609 }
8610 }
8611
Johannes Berg2a0e0472013-01-23 22:57:40 +01008612 if (tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION]) {
8613 err = nl80211_parse_wowlan_tcp(
8614 rdev, tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION],
8615 &new_triggers);
8616 if (err)
8617 goto error;
8618 }
8619
Johannes Bergae33bd82012-07-12 16:25:02 +02008620 ntrig = kmemdup(&new_triggers, sizeof(new_triggers), GFP_KERNEL);
8621 if (!ntrig) {
8622 err = -ENOMEM;
8623 goto error;
Johannes Bergff1b6e62011-05-04 15:37:28 +02008624 }
Johannes Bergae33bd82012-07-12 16:25:02 +02008625 cfg80211_rdev_free_wowlan(rdev);
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008626 rdev->wiphy.wowlan_config = ntrig;
Johannes Bergff1b6e62011-05-04 15:37:28 +02008627
Johannes Bergae33bd82012-07-12 16:25:02 +02008628 set_wakeup:
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008629 if (rdev->ops->set_wakeup &&
8630 prev_enabled != !!rdev->wiphy.wowlan_config)
8631 rdev_set_wakeup(rdev, rdev->wiphy.wowlan_config);
Johannes Berg6d525632012-04-04 15:05:25 +02008632
Johannes Bergff1b6e62011-05-04 15:37:28 +02008633 return 0;
8634 error:
8635 for (i = 0; i < new_triggers.n_patterns; i++)
8636 kfree(new_triggers.patterns[i].mask);
8637 kfree(new_triggers.patterns);
Johannes Berg2a0e0472013-01-23 22:57:40 +01008638 if (new_triggers.tcp && new_triggers.tcp->sock)
8639 sock_release(new_triggers.tcp->sock);
8640 kfree(new_triggers.tcp);
Johannes Bergff1b6e62011-05-04 15:37:28 +02008641 return err;
8642}
Johannes Bergdfb89c52012-06-27 09:23:48 +02008643#endif
Johannes Bergff1b6e62011-05-04 15:37:28 +02008644
Amitkumar Karwarbe29b992013-06-28 11:51:26 -07008645static int nl80211_send_coalesce_rules(struct sk_buff *msg,
8646 struct cfg80211_registered_device *rdev)
8647{
8648 struct nlattr *nl_pats, *nl_pat, *nl_rule, *nl_rules;
8649 int i, j, pat_len;
8650 struct cfg80211_coalesce_rules *rule;
8651
8652 if (!rdev->coalesce->n_rules)
8653 return 0;
8654
8655 nl_rules = nla_nest_start(msg, NL80211_ATTR_COALESCE_RULE);
8656 if (!nl_rules)
8657 return -ENOBUFS;
8658
8659 for (i = 0; i < rdev->coalesce->n_rules; i++) {
8660 nl_rule = nla_nest_start(msg, i + 1);
8661 if (!nl_rule)
8662 return -ENOBUFS;
8663
8664 rule = &rdev->coalesce->rules[i];
8665 if (nla_put_u32(msg, NL80211_ATTR_COALESCE_RULE_DELAY,
8666 rule->delay))
8667 return -ENOBUFS;
8668
8669 if (nla_put_u32(msg, NL80211_ATTR_COALESCE_RULE_CONDITION,
8670 rule->condition))
8671 return -ENOBUFS;
8672
8673 nl_pats = nla_nest_start(msg,
8674 NL80211_ATTR_COALESCE_RULE_PKT_PATTERN);
8675 if (!nl_pats)
8676 return -ENOBUFS;
8677
8678 for (j = 0; j < rule->n_patterns; j++) {
8679 nl_pat = nla_nest_start(msg, j + 1);
8680 if (!nl_pat)
8681 return -ENOBUFS;
8682 pat_len = rule->patterns[j].pattern_len;
8683 if (nla_put(msg, NL80211_PKTPAT_MASK,
8684 DIV_ROUND_UP(pat_len, 8),
8685 rule->patterns[j].mask) ||
8686 nla_put(msg, NL80211_PKTPAT_PATTERN, pat_len,
8687 rule->patterns[j].pattern) ||
8688 nla_put_u32(msg, NL80211_PKTPAT_OFFSET,
8689 rule->patterns[j].pkt_offset))
8690 return -ENOBUFS;
8691 nla_nest_end(msg, nl_pat);
8692 }
8693 nla_nest_end(msg, nl_pats);
8694 nla_nest_end(msg, nl_rule);
8695 }
8696 nla_nest_end(msg, nl_rules);
8697
8698 return 0;
8699}
8700
8701static int nl80211_get_coalesce(struct sk_buff *skb, struct genl_info *info)
8702{
8703 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8704 struct sk_buff *msg;
8705 void *hdr;
8706
8707 if (!rdev->wiphy.coalesce)
8708 return -EOPNOTSUPP;
8709
8710 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
8711 if (!msg)
8712 return -ENOMEM;
8713
8714 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
8715 NL80211_CMD_GET_COALESCE);
8716 if (!hdr)
8717 goto nla_put_failure;
8718
8719 if (rdev->coalesce && nl80211_send_coalesce_rules(msg, rdev))
8720 goto nla_put_failure;
8721
8722 genlmsg_end(msg, hdr);
8723 return genlmsg_reply(msg, info);
8724
8725nla_put_failure:
8726 nlmsg_free(msg);
8727 return -ENOBUFS;
8728}
8729
8730void cfg80211_rdev_free_coalesce(struct cfg80211_registered_device *rdev)
8731{
8732 struct cfg80211_coalesce *coalesce = rdev->coalesce;
8733 int i, j;
8734 struct cfg80211_coalesce_rules *rule;
8735
8736 if (!coalesce)
8737 return;
8738
8739 for (i = 0; i < coalesce->n_rules; i++) {
8740 rule = &coalesce->rules[i];
8741 for (j = 0; j < rule->n_patterns; j++)
8742 kfree(rule->patterns[j].mask);
8743 kfree(rule->patterns);
8744 }
8745 kfree(coalesce->rules);
8746 kfree(coalesce);
8747 rdev->coalesce = NULL;
8748}
8749
8750static int nl80211_parse_coalesce_rule(struct cfg80211_registered_device *rdev,
8751 struct nlattr *rule,
8752 struct cfg80211_coalesce_rules *new_rule)
8753{
8754 int err, i;
8755 const struct wiphy_coalesce_support *coalesce = rdev->wiphy.coalesce;
8756 struct nlattr *tb[NUM_NL80211_ATTR_COALESCE_RULE], *pat;
8757 int rem, pat_len, mask_len, pkt_offset, n_patterns = 0;
8758 struct nlattr *pat_tb[NUM_NL80211_PKTPAT];
8759
8760 err = nla_parse(tb, NL80211_ATTR_COALESCE_RULE_MAX, nla_data(rule),
8761 nla_len(rule), nl80211_coalesce_policy);
8762 if (err)
8763 return err;
8764
8765 if (tb[NL80211_ATTR_COALESCE_RULE_DELAY])
8766 new_rule->delay =
8767 nla_get_u32(tb[NL80211_ATTR_COALESCE_RULE_DELAY]);
8768 if (new_rule->delay > coalesce->max_delay)
8769 return -EINVAL;
8770
8771 if (tb[NL80211_ATTR_COALESCE_RULE_CONDITION])
8772 new_rule->condition =
8773 nla_get_u32(tb[NL80211_ATTR_COALESCE_RULE_CONDITION]);
8774 if (new_rule->condition != NL80211_COALESCE_CONDITION_MATCH &&
8775 new_rule->condition != NL80211_COALESCE_CONDITION_NO_MATCH)
8776 return -EINVAL;
8777
8778 if (!tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN])
8779 return -EINVAL;
8780
8781 nla_for_each_nested(pat, tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN],
8782 rem)
8783 n_patterns++;
8784 if (n_patterns > coalesce->n_patterns)
8785 return -EINVAL;
8786
8787 new_rule->patterns = kcalloc(n_patterns, sizeof(new_rule->patterns[0]),
8788 GFP_KERNEL);
8789 if (!new_rule->patterns)
8790 return -ENOMEM;
8791
8792 new_rule->n_patterns = n_patterns;
8793 i = 0;
8794
8795 nla_for_each_nested(pat, tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN],
8796 rem) {
Johannes Berg922bd802014-05-19 17:59:50 +02008797 u8 *mask_pat;
8798
Amitkumar Karwarbe29b992013-06-28 11:51:26 -07008799 nla_parse(pat_tb, MAX_NL80211_PKTPAT, nla_data(pat),
8800 nla_len(pat), NULL);
8801 if (!pat_tb[NL80211_PKTPAT_MASK] ||
8802 !pat_tb[NL80211_PKTPAT_PATTERN])
8803 return -EINVAL;
8804 pat_len = nla_len(pat_tb[NL80211_PKTPAT_PATTERN]);
8805 mask_len = DIV_ROUND_UP(pat_len, 8);
8806 if (nla_len(pat_tb[NL80211_PKTPAT_MASK]) != mask_len)
8807 return -EINVAL;
8808 if (pat_len > coalesce->pattern_max_len ||
8809 pat_len < coalesce->pattern_min_len)
8810 return -EINVAL;
8811
8812 if (!pat_tb[NL80211_PKTPAT_OFFSET])
8813 pkt_offset = 0;
8814 else
8815 pkt_offset = nla_get_u32(pat_tb[NL80211_PKTPAT_OFFSET]);
8816 if (pkt_offset > coalesce->max_pkt_offset)
8817 return -EINVAL;
8818 new_rule->patterns[i].pkt_offset = pkt_offset;
8819
Johannes Berg922bd802014-05-19 17:59:50 +02008820 mask_pat = kmalloc(mask_len + pat_len, GFP_KERNEL);
8821 if (!mask_pat)
Amitkumar Karwarbe29b992013-06-28 11:51:26 -07008822 return -ENOMEM;
Johannes Berg922bd802014-05-19 17:59:50 +02008823
8824 new_rule->patterns[i].mask = mask_pat;
8825 memcpy(mask_pat, nla_data(pat_tb[NL80211_PKTPAT_MASK]),
8826 mask_len);
8827
8828 mask_pat += mask_len;
8829 new_rule->patterns[i].pattern = mask_pat;
Amitkumar Karwarbe29b992013-06-28 11:51:26 -07008830 new_rule->patterns[i].pattern_len = pat_len;
Johannes Berg922bd802014-05-19 17:59:50 +02008831 memcpy(mask_pat, nla_data(pat_tb[NL80211_PKTPAT_PATTERN]),
8832 pat_len);
Amitkumar Karwarbe29b992013-06-28 11:51:26 -07008833 i++;
8834 }
8835
8836 return 0;
8837}
8838
8839static int nl80211_set_coalesce(struct sk_buff *skb, struct genl_info *info)
8840{
8841 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8842 const struct wiphy_coalesce_support *coalesce = rdev->wiphy.coalesce;
8843 struct cfg80211_coalesce new_coalesce = {};
8844 struct cfg80211_coalesce *n_coalesce;
8845 int err, rem_rule, n_rules = 0, i, j;
8846 struct nlattr *rule;
8847 struct cfg80211_coalesce_rules *tmp_rule;
8848
8849 if (!rdev->wiphy.coalesce || !rdev->ops->set_coalesce)
8850 return -EOPNOTSUPP;
8851
8852 if (!info->attrs[NL80211_ATTR_COALESCE_RULE]) {
8853 cfg80211_rdev_free_coalesce(rdev);
8854 rdev->ops->set_coalesce(&rdev->wiphy, NULL);
8855 return 0;
8856 }
8857
8858 nla_for_each_nested(rule, info->attrs[NL80211_ATTR_COALESCE_RULE],
8859 rem_rule)
8860 n_rules++;
8861 if (n_rules > coalesce->n_rules)
8862 return -EINVAL;
8863
8864 new_coalesce.rules = kcalloc(n_rules, sizeof(new_coalesce.rules[0]),
8865 GFP_KERNEL);
8866 if (!new_coalesce.rules)
8867 return -ENOMEM;
8868
8869 new_coalesce.n_rules = n_rules;
8870 i = 0;
8871
8872 nla_for_each_nested(rule, info->attrs[NL80211_ATTR_COALESCE_RULE],
8873 rem_rule) {
8874 err = nl80211_parse_coalesce_rule(rdev, rule,
8875 &new_coalesce.rules[i]);
8876 if (err)
8877 goto error;
8878
8879 i++;
8880 }
8881
8882 err = rdev->ops->set_coalesce(&rdev->wiphy, &new_coalesce);
8883 if (err)
8884 goto error;
8885
8886 n_coalesce = kmemdup(&new_coalesce, sizeof(new_coalesce), GFP_KERNEL);
8887 if (!n_coalesce) {
8888 err = -ENOMEM;
8889 goto error;
8890 }
8891 cfg80211_rdev_free_coalesce(rdev);
8892 rdev->coalesce = n_coalesce;
8893
8894 return 0;
8895error:
8896 for (i = 0; i < new_coalesce.n_rules; i++) {
8897 tmp_rule = &new_coalesce.rules[i];
8898 for (j = 0; j < tmp_rule->n_patterns; j++)
8899 kfree(tmp_rule->patterns[j].mask);
8900 kfree(tmp_rule->patterns);
8901 }
8902 kfree(new_coalesce.rules);
8903
8904 return err;
8905}
8906
Johannes Berge5497d72011-07-05 16:35:40 +02008907static int nl80211_set_rekey_data(struct sk_buff *skb, struct genl_info *info)
8908{
8909 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8910 struct net_device *dev = info->user_ptr[1];
8911 struct wireless_dev *wdev = dev->ieee80211_ptr;
8912 struct nlattr *tb[NUM_NL80211_REKEY_DATA];
8913 struct cfg80211_gtk_rekey_data rekey_data;
8914 int err;
8915
8916 if (!info->attrs[NL80211_ATTR_REKEY_DATA])
8917 return -EINVAL;
8918
8919 err = nla_parse(tb, MAX_NL80211_REKEY_DATA,
8920 nla_data(info->attrs[NL80211_ATTR_REKEY_DATA]),
8921 nla_len(info->attrs[NL80211_ATTR_REKEY_DATA]),
8922 nl80211_rekey_policy);
8923 if (err)
8924 return err;
8925
8926 if (nla_len(tb[NL80211_REKEY_DATA_REPLAY_CTR]) != NL80211_REPLAY_CTR_LEN)
8927 return -ERANGE;
8928 if (nla_len(tb[NL80211_REKEY_DATA_KEK]) != NL80211_KEK_LEN)
8929 return -ERANGE;
8930 if (nla_len(tb[NL80211_REKEY_DATA_KCK]) != NL80211_KCK_LEN)
8931 return -ERANGE;
8932
8933 memcpy(rekey_data.kek, nla_data(tb[NL80211_REKEY_DATA_KEK]),
8934 NL80211_KEK_LEN);
8935 memcpy(rekey_data.kck, nla_data(tb[NL80211_REKEY_DATA_KCK]),
8936 NL80211_KCK_LEN);
8937 memcpy(rekey_data.replay_ctr,
8938 nla_data(tb[NL80211_REKEY_DATA_REPLAY_CTR]),
8939 NL80211_REPLAY_CTR_LEN);
8940
8941 wdev_lock(wdev);
8942 if (!wdev->current_bss) {
8943 err = -ENOTCONN;
8944 goto out;
8945 }
8946
8947 if (!rdev->ops->set_rekey_data) {
8948 err = -EOPNOTSUPP;
8949 goto out;
8950 }
8951
Hila Gonene35e4d22012-06-27 17:19:42 +03008952 err = rdev_set_rekey_data(rdev, dev, &rekey_data);
Johannes Berge5497d72011-07-05 16:35:40 +02008953 out:
8954 wdev_unlock(wdev);
8955 return err;
8956}
8957
Johannes Berg28946da2011-11-04 11:18:12 +01008958static int nl80211_register_unexpected_frame(struct sk_buff *skb,
8959 struct genl_info *info)
8960{
8961 struct net_device *dev = info->user_ptr[1];
8962 struct wireless_dev *wdev = dev->ieee80211_ptr;
8963
8964 if (wdev->iftype != NL80211_IFTYPE_AP &&
8965 wdev->iftype != NL80211_IFTYPE_P2P_GO)
8966 return -EINVAL;
8967
Eric W. Biederman15e47302012-09-07 20:12:54 +00008968 if (wdev->ap_unexpected_nlportid)
Johannes Berg28946da2011-11-04 11:18:12 +01008969 return -EBUSY;
8970
Eric W. Biederman15e47302012-09-07 20:12:54 +00008971 wdev->ap_unexpected_nlportid = info->snd_portid;
Johannes Berg28946da2011-11-04 11:18:12 +01008972 return 0;
8973}
8974
Johannes Berg7f6cf312011-11-04 11:18:15 +01008975static int nl80211_probe_client(struct sk_buff *skb,
8976 struct genl_info *info)
8977{
8978 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8979 struct net_device *dev = info->user_ptr[1];
8980 struct wireless_dev *wdev = dev->ieee80211_ptr;
8981 struct sk_buff *msg;
8982 void *hdr;
8983 const u8 *addr;
8984 u64 cookie;
8985 int err;
8986
8987 if (wdev->iftype != NL80211_IFTYPE_AP &&
8988 wdev->iftype != NL80211_IFTYPE_P2P_GO)
8989 return -EOPNOTSUPP;
8990
8991 if (!info->attrs[NL80211_ATTR_MAC])
8992 return -EINVAL;
8993
8994 if (!rdev->ops->probe_client)
8995 return -EOPNOTSUPP;
8996
8997 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
8998 if (!msg)
8999 return -ENOMEM;
9000
Eric W. Biederman15e47302012-09-07 20:12:54 +00009001 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berg7f6cf312011-11-04 11:18:15 +01009002 NL80211_CMD_PROBE_CLIENT);
Dan Carpentercb35fba2013-08-14 14:50:01 +03009003 if (!hdr) {
9004 err = -ENOBUFS;
Johannes Berg7f6cf312011-11-04 11:18:15 +01009005 goto free_msg;
9006 }
9007
9008 addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
9009
Hila Gonene35e4d22012-06-27 17:19:42 +03009010 err = rdev_probe_client(rdev, dev, addr, &cookie);
Johannes Berg7f6cf312011-11-04 11:18:15 +01009011 if (err)
9012 goto free_msg;
9013
David S. Miller9360ffd2012-03-29 04:41:26 -04009014 if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie))
9015 goto nla_put_failure;
Johannes Berg7f6cf312011-11-04 11:18:15 +01009016
9017 genlmsg_end(msg, hdr);
9018
9019 return genlmsg_reply(msg, info);
9020
9021 nla_put_failure:
9022 err = -ENOBUFS;
9023 free_msg:
9024 nlmsg_free(msg);
9025 return err;
9026}
9027
Johannes Berg5e760232011-11-04 11:18:17 +01009028static int nl80211_register_beacons(struct sk_buff *skb, struct genl_info *info)
9029{
9030 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Ben Greear37c73b52012-10-26 14:49:25 -07009031 struct cfg80211_beacon_registration *reg, *nreg;
9032 int rv;
Johannes Berg5e760232011-11-04 11:18:17 +01009033
9034 if (!(rdev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS))
9035 return -EOPNOTSUPP;
9036
Ben Greear37c73b52012-10-26 14:49:25 -07009037 nreg = kzalloc(sizeof(*nreg), GFP_KERNEL);
9038 if (!nreg)
9039 return -ENOMEM;
Johannes Berg5e760232011-11-04 11:18:17 +01009040
Ben Greear37c73b52012-10-26 14:49:25 -07009041 /* First, check if already registered. */
9042 spin_lock_bh(&rdev->beacon_registrations_lock);
9043 list_for_each_entry(reg, &rdev->beacon_registrations, list) {
9044 if (reg->nlportid == info->snd_portid) {
9045 rv = -EALREADY;
9046 goto out_err;
9047 }
9048 }
9049 /* Add it to the list */
9050 nreg->nlportid = info->snd_portid;
9051 list_add(&nreg->list, &rdev->beacon_registrations);
9052
9053 spin_unlock_bh(&rdev->beacon_registrations_lock);
Johannes Berg5e760232011-11-04 11:18:17 +01009054
9055 return 0;
Ben Greear37c73b52012-10-26 14:49:25 -07009056out_err:
9057 spin_unlock_bh(&rdev->beacon_registrations_lock);
9058 kfree(nreg);
9059 return rv;
Johannes Berg5e760232011-11-04 11:18:17 +01009060}
9061
Johannes Berg98104fde2012-06-16 00:19:54 +02009062static int nl80211_start_p2p_device(struct sk_buff *skb, struct genl_info *info)
9063{
9064 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9065 struct wireless_dev *wdev = info->user_ptr[1];
9066 int err;
9067
9068 if (!rdev->ops->start_p2p_device)
9069 return -EOPNOTSUPP;
9070
9071 if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE)
9072 return -EOPNOTSUPP;
9073
9074 if (wdev->p2p_started)
9075 return 0;
9076
Luciano Coelhob6a55012014-02-27 11:07:21 +02009077 if (rfkill_blocked(rdev->rfkill))
9078 return -ERFKILL;
Johannes Berg98104fde2012-06-16 00:19:54 +02009079
Johannes Bergeeb126e2012-10-23 15:16:50 +02009080 err = rdev_start_p2p_device(rdev, wdev);
Johannes Berg98104fde2012-06-16 00:19:54 +02009081 if (err)
9082 return err;
9083
9084 wdev->p2p_started = true;
Johannes Berg98104fde2012-06-16 00:19:54 +02009085 rdev->opencount++;
Johannes Berg98104fde2012-06-16 00:19:54 +02009086
9087 return 0;
9088}
9089
9090static int nl80211_stop_p2p_device(struct sk_buff *skb, struct genl_info *info)
9091{
9092 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9093 struct wireless_dev *wdev = info->user_ptr[1];
9094
9095 if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE)
9096 return -EOPNOTSUPP;
9097
9098 if (!rdev->ops->stop_p2p_device)
9099 return -EOPNOTSUPP;
9100
Johannes Bergf9f47522013-03-19 15:04:07 +01009101 cfg80211_stop_p2p_device(rdev, wdev);
Johannes Berg98104fde2012-06-16 00:19:54 +02009102
9103 return 0;
9104}
9105
Johannes Berg3713b4e2013-02-14 16:19:38 +01009106static int nl80211_get_protocol_features(struct sk_buff *skb,
9107 struct genl_info *info)
9108{
9109 void *hdr;
9110 struct sk_buff *msg;
9111
9112 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
9113 if (!msg)
9114 return -ENOMEM;
9115
9116 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
9117 NL80211_CMD_GET_PROTOCOL_FEATURES);
9118 if (!hdr)
9119 goto nla_put_failure;
9120
9121 if (nla_put_u32(msg, NL80211_ATTR_PROTOCOL_FEATURES,
9122 NL80211_PROTOCOL_FEATURE_SPLIT_WIPHY_DUMP))
9123 goto nla_put_failure;
9124
9125 genlmsg_end(msg, hdr);
9126 return genlmsg_reply(msg, info);
9127
9128 nla_put_failure:
9129 kfree_skb(msg);
9130 return -ENOBUFS;
9131}
9132
Jouni Malinen355199e2013-02-27 17:14:27 +02009133static int nl80211_update_ft_ies(struct sk_buff *skb, struct genl_info *info)
9134{
9135 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9136 struct cfg80211_update_ft_ies_params ft_params;
9137 struct net_device *dev = info->user_ptr[1];
9138
9139 if (!rdev->ops->update_ft_ies)
9140 return -EOPNOTSUPP;
9141
9142 if (!info->attrs[NL80211_ATTR_MDID] ||
9143 !is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
9144 return -EINVAL;
9145
9146 memset(&ft_params, 0, sizeof(ft_params));
9147 ft_params.md = nla_get_u16(info->attrs[NL80211_ATTR_MDID]);
9148 ft_params.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
9149 ft_params.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
9150
9151 return rdev_update_ft_ies(rdev, dev, &ft_params);
9152}
9153
Arend van Spriel5de17982013-04-18 15:49:00 +02009154static int nl80211_crit_protocol_start(struct sk_buff *skb,
9155 struct genl_info *info)
9156{
9157 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9158 struct wireless_dev *wdev = info->user_ptr[1];
9159 enum nl80211_crit_proto_id proto = NL80211_CRIT_PROTO_UNSPEC;
9160 u16 duration;
9161 int ret;
9162
9163 if (!rdev->ops->crit_proto_start)
9164 return -EOPNOTSUPP;
9165
9166 if (WARN_ON(!rdev->ops->crit_proto_stop))
9167 return -EINVAL;
9168
9169 if (rdev->crit_proto_nlportid)
9170 return -EBUSY;
9171
9172 /* determine protocol if provided */
9173 if (info->attrs[NL80211_ATTR_CRIT_PROT_ID])
9174 proto = nla_get_u16(info->attrs[NL80211_ATTR_CRIT_PROT_ID]);
9175
9176 if (proto >= NUM_NL80211_CRIT_PROTO)
9177 return -EINVAL;
9178
9179 /* timeout must be provided */
9180 if (!info->attrs[NL80211_ATTR_MAX_CRIT_PROT_DURATION])
9181 return -EINVAL;
9182
9183 duration =
9184 nla_get_u16(info->attrs[NL80211_ATTR_MAX_CRIT_PROT_DURATION]);
9185
9186 if (duration > NL80211_CRIT_PROTO_MAX_DURATION)
9187 return -ERANGE;
9188
9189 ret = rdev_crit_proto_start(rdev, wdev, proto, duration);
9190 if (!ret)
9191 rdev->crit_proto_nlportid = info->snd_portid;
9192
9193 return ret;
9194}
9195
9196static int nl80211_crit_protocol_stop(struct sk_buff *skb,
9197 struct genl_info *info)
9198{
9199 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9200 struct wireless_dev *wdev = info->user_ptr[1];
9201
9202 if (!rdev->ops->crit_proto_stop)
9203 return -EOPNOTSUPP;
9204
9205 if (rdev->crit_proto_nlportid) {
9206 rdev->crit_proto_nlportid = 0;
9207 rdev_crit_proto_stop(rdev, wdev);
9208 }
9209 return 0;
9210}
9211
Johannes Bergad7e7182013-11-13 13:37:47 +01009212static int nl80211_vendor_cmd(struct sk_buff *skb, struct genl_info *info)
9213{
9214 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9215 struct wireless_dev *wdev =
9216 __cfg80211_wdev_from_attrs(genl_info_net(info), info->attrs);
9217 int i, err;
9218 u32 vid, subcmd;
9219
9220 if (!rdev->wiphy.vendor_commands)
9221 return -EOPNOTSUPP;
9222
9223 if (IS_ERR(wdev)) {
9224 err = PTR_ERR(wdev);
9225 if (err != -EINVAL)
9226 return err;
9227 wdev = NULL;
9228 } else if (wdev->wiphy != &rdev->wiphy) {
9229 return -EINVAL;
9230 }
9231
9232 if (!info->attrs[NL80211_ATTR_VENDOR_ID] ||
9233 !info->attrs[NL80211_ATTR_VENDOR_SUBCMD])
9234 return -EINVAL;
9235
9236 vid = nla_get_u32(info->attrs[NL80211_ATTR_VENDOR_ID]);
9237 subcmd = nla_get_u32(info->attrs[NL80211_ATTR_VENDOR_SUBCMD]);
9238 for (i = 0; i < rdev->wiphy.n_vendor_commands; i++) {
9239 const struct wiphy_vendor_command *vcmd;
9240 void *data = NULL;
9241 int len = 0;
9242
9243 vcmd = &rdev->wiphy.vendor_commands[i];
9244
9245 if (vcmd->info.vendor_id != vid || vcmd->info.subcmd != subcmd)
9246 continue;
9247
9248 if (vcmd->flags & (WIPHY_VENDOR_CMD_NEED_WDEV |
9249 WIPHY_VENDOR_CMD_NEED_NETDEV)) {
9250 if (!wdev)
9251 return -EINVAL;
9252 if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_NETDEV &&
9253 !wdev->netdev)
9254 return -EINVAL;
9255
9256 if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_RUNNING) {
9257 if (wdev->netdev &&
9258 !netif_running(wdev->netdev))
9259 return -ENETDOWN;
9260 if (!wdev->netdev && !wdev->p2p_started)
9261 return -ENETDOWN;
9262 }
9263 } else {
9264 wdev = NULL;
9265 }
9266
9267 if (info->attrs[NL80211_ATTR_VENDOR_DATA]) {
9268 data = nla_data(info->attrs[NL80211_ATTR_VENDOR_DATA]);
9269 len = nla_len(info->attrs[NL80211_ATTR_VENDOR_DATA]);
9270 }
9271
9272 rdev->cur_cmd_info = info;
9273 err = rdev->wiphy.vendor_commands[i].doit(&rdev->wiphy, wdev,
9274 data, len);
9275 rdev->cur_cmd_info = NULL;
9276 return err;
9277 }
9278
9279 return -EOPNOTSUPP;
9280}
9281
9282struct sk_buff *__cfg80211_alloc_reply_skb(struct wiphy *wiphy,
9283 enum nl80211_commands cmd,
9284 enum nl80211_attrs attr,
9285 int approxlen)
9286{
Zhao, Gangf26cbf42014-04-21 12:53:03 +08009287 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Bergad7e7182013-11-13 13:37:47 +01009288
9289 if (WARN_ON(!rdev->cur_cmd_info))
9290 return NULL;
9291
9292 return __cfg80211_alloc_vendor_skb(rdev, approxlen,
9293 rdev->cur_cmd_info->snd_portid,
9294 rdev->cur_cmd_info->snd_seq,
Johannes Berg567ffc32013-12-18 14:43:31 +01009295 cmd, attr, NULL, GFP_KERNEL);
Johannes Bergad7e7182013-11-13 13:37:47 +01009296}
9297EXPORT_SYMBOL(__cfg80211_alloc_reply_skb);
9298
9299int cfg80211_vendor_cmd_reply(struct sk_buff *skb)
9300{
9301 struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0];
9302 void *hdr = ((void **)skb->cb)[1];
9303 struct nlattr *data = ((void **)skb->cb)[2];
9304
9305 if (WARN_ON(!rdev->cur_cmd_info)) {
9306 kfree_skb(skb);
9307 return -EINVAL;
9308 }
9309
9310 nla_nest_end(skb, data);
9311 genlmsg_end(skb, hdr);
9312 return genlmsg_reply(skb, rdev->cur_cmd_info);
9313}
9314EXPORT_SYMBOL_GPL(cfg80211_vendor_cmd_reply);
9315
9316
Kyeyoon Parkfa9ffc72013-12-16 23:01:30 -08009317static int nl80211_set_qos_map(struct sk_buff *skb,
9318 struct genl_info *info)
9319{
9320 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9321 struct cfg80211_qos_map *qos_map = NULL;
9322 struct net_device *dev = info->user_ptr[1];
9323 u8 *pos, len, num_des, des_len, des;
9324 int ret;
9325
9326 if (!rdev->ops->set_qos_map)
9327 return -EOPNOTSUPP;
9328
9329 if (info->attrs[NL80211_ATTR_QOS_MAP]) {
9330 pos = nla_data(info->attrs[NL80211_ATTR_QOS_MAP]);
9331 len = nla_len(info->attrs[NL80211_ATTR_QOS_MAP]);
9332
9333 if (len % 2 || len < IEEE80211_QOS_MAP_LEN_MIN ||
9334 len > IEEE80211_QOS_MAP_LEN_MAX)
9335 return -EINVAL;
9336
9337 qos_map = kzalloc(sizeof(struct cfg80211_qos_map), GFP_KERNEL);
9338 if (!qos_map)
9339 return -ENOMEM;
9340
9341 num_des = (len - IEEE80211_QOS_MAP_LEN_MIN) >> 1;
9342 if (num_des) {
9343 des_len = num_des *
9344 sizeof(struct cfg80211_dscp_exception);
9345 memcpy(qos_map->dscp_exception, pos, des_len);
9346 qos_map->num_des = num_des;
9347 for (des = 0; des < num_des; des++) {
9348 if (qos_map->dscp_exception[des].up > 7) {
9349 kfree(qos_map);
9350 return -EINVAL;
9351 }
9352 }
9353 pos += des_len;
9354 }
9355 memcpy(qos_map->up, pos, IEEE80211_QOS_MAP_LEN_MIN);
9356 }
9357
9358 wdev_lock(dev->ieee80211_ptr);
9359 ret = nl80211_key_allowed(dev->ieee80211_ptr);
9360 if (!ret)
9361 ret = rdev_set_qos_map(rdev, dev, qos_map);
9362 wdev_unlock(dev->ieee80211_ptr);
9363
9364 kfree(qos_map);
9365 return ret;
9366}
9367
Johannes Berg4c476992010-10-04 21:36:35 +02009368#define NL80211_FLAG_NEED_WIPHY 0x01
9369#define NL80211_FLAG_NEED_NETDEV 0x02
9370#define NL80211_FLAG_NEED_RTNL 0x04
Johannes Berg41265712010-10-04 21:14:05 +02009371#define NL80211_FLAG_CHECK_NETDEV_UP 0x08
9372#define NL80211_FLAG_NEED_NETDEV_UP (NL80211_FLAG_NEED_NETDEV |\
9373 NL80211_FLAG_CHECK_NETDEV_UP)
Johannes Berg1bf614e2012-06-15 15:23:36 +02009374#define NL80211_FLAG_NEED_WDEV 0x10
Johannes Berg98104fde2012-06-16 00:19:54 +02009375/* If a netdev is associated, it must be UP, P2P must be started */
Johannes Berg1bf614e2012-06-15 15:23:36 +02009376#define NL80211_FLAG_NEED_WDEV_UP (NL80211_FLAG_NEED_WDEV |\
9377 NL80211_FLAG_CHECK_NETDEV_UP)
Johannes Berg4c476992010-10-04 21:36:35 +02009378
Johannes Bergf84f7712013-11-14 17:14:45 +01009379static int nl80211_pre_doit(const struct genl_ops *ops, struct sk_buff *skb,
Johannes Berg4c476992010-10-04 21:36:35 +02009380 struct genl_info *info)
9381{
9382 struct cfg80211_registered_device *rdev;
Johannes Berg89a54e42012-06-15 14:33:17 +02009383 struct wireless_dev *wdev;
Johannes Berg4c476992010-10-04 21:36:35 +02009384 struct net_device *dev;
Johannes Berg4c476992010-10-04 21:36:35 +02009385 bool rtnl = ops->internal_flags & NL80211_FLAG_NEED_RTNL;
9386
9387 if (rtnl)
9388 rtnl_lock();
9389
9390 if (ops->internal_flags & NL80211_FLAG_NEED_WIPHY) {
Johannes Berg4f7eff12012-06-15 14:14:22 +02009391 rdev = cfg80211_get_dev_from_info(genl_info_net(info), info);
Johannes Berg4c476992010-10-04 21:36:35 +02009392 if (IS_ERR(rdev)) {
9393 if (rtnl)
9394 rtnl_unlock();
9395 return PTR_ERR(rdev);
9396 }
9397 info->user_ptr[0] = rdev;
Johannes Berg1bf614e2012-06-15 15:23:36 +02009398 } else if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV ||
9399 ops->internal_flags & NL80211_FLAG_NEED_WDEV) {
Johannes Berg5fe231e2013-05-08 21:45:15 +02009400 ASSERT_RTNL();
9401
Johannes Berg89a54e42012-06-15 14:33:17 +02009402 wdev = __cfg80211_wdev_from_attrs(genl_info_net(info),
9403 info->attrs);
9404 if (IS_ERR(wdev)) {
Johannes Berg4c476992010-10-04 21:36:35 +02009405 if (rtnl)
9406 rtnl_unlock();
Johannes Berg89a54e42012-06-15 14:33:17 +02009407 return PTR_ERR(wdev);
Johannes Berg4c476992010-10-04 21:36:35 +02009408 }
Johannes Berg89a54e42012-06-15 14:33:17 +02009409
Johannes Berg89a54e42012-06-15 14:33:17 +02009410 dev = wdev->netdev;
Zhao, Gangf26cbf42014-04-21 12:53:03 +08009411 rdev = wiphy_to_rdev(wdev->wiphy);
Johannes Berg89a54e42012-06-15 14:33:17 +02009412
Johannes Berg1bf614e2012-06-15 15:23:36 +02009413 if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV) {
9414 if (!dev) {
Johannes Berg1bf614e2012-06-15 15:23:36 +02009415 if (rtnl)
9416 rtnl_unlock();
9417 return -EINVAL;
9418 }
9419
9420 info->user_ptr[1] = dev;
9421 } else {
9422 info->user_ptr[1] = wdev;
Johannes Berg41265712010-10-04 21:14:05 +02009423 }
Johannes Berg89a54e42012-06-15 14:33:17 +02009424
Johannes Berg1bf614e2012-06-15 15:23:36 +02009425 if (dev) {
9426 if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP &&
9427 !netif_running(dev)) {
Johannes Berg1bf614e2012-06-15 15:23:36 +02009428 if (rtnl)
9429 rtnl_unlock();
9430 return -ENETDOWN;
9431 }
9432
9433 dev_hold(dev);
Johannes Berg98104fde2012-06-16 00:19:54 +02009434 } else if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP) {
9435 if (!wdev->p2p_started) {
Johannes Berg98104fde2012-06-16 00:19:54 +02009436 if (rtnl)
9437 rtnl_unlock();
9438 return -ENETDOWN;
9439 }
Johannes Berg1bf614e2012-06-15 15:23:36 +02009440 }
9441
Johannes Berg4c476992010-10-04 21:36:35 +02009442 info->user_ptr[0] = rdev;
Johannes Berg4c476992010-10-04 21:36:35 +02009443 }
9444
9445 return 0;
9446}
9447
Johannes Bergf84f7712013-11-14 17:14:45 +01009448static void nl80211_post_doit(const struct genl_ops *ops, struct sk_buff *skb,
Johannes Berg4c476992010-10-04 21:36:35 +02009449 struct genl_info *info)
9450{
Johannes Berg1bf614e2012-06-15 15:23:36 +02009451 if (info->user_ptr[1]) {
9452 if (ops->internal_flags & NL80211_FLAG_NEED_WDEV) {
9453 struct wireless_dev *wdev = info->user_ptr[1];
9454
9455 if (wdev->netdev)
9456 dev_put(wdev->netdev);
9457 } else {
9458 dev_put(info->user_ptr[1]);
9459 }
9460 }
Johannes Berg4c476992010-10-04 21:36:35 +02009461 if (ops->internal_flags & NL80211_FLAG_NEED_RTNL)
9462 rtnl_unlock();
9463}
9464
Johannes Berg4534de82013-11-14 17:14:46 +01009465static const struct genl_ops nl80211_ops[] = {
Johannes Berg55682962007-09-20 13:09:35 -04009466 {
9467 .cmd = NL80211_CMD_GET_WIPHY,
9468 .doit = nl80211_get_wiphy,
9469 .dumpit = nl80211_dump_wiphy,
Johannes Berg86e8cf92013-06-19 10:57:22 +02009470 .done = nl80211_dump_wiphy_done,
Johannes Berg55682962007-09-20 13:09:35 -04009471 .policy = nl80211_policy,
9472 /* can be retrieved by unprivileged users */
Johannes Berg5fe231e2013-05-08 21:45:15 +02009473 .internal_flags = NL80211_FLAG_NEED_WIPHY |
9474 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -04009475 },
9476 {
9477 .cmd = NL80211_CMD_SET_WIPHY,
9478 .doit = nl80211_set_wiphy,
9479 .policy = nl80211_policy,
9480 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02009481 .internal_flags = NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -04009482 },
9483 {
9484 .cmd = NL80211_CMD_GET_INTERFACE,
9485 .doit = nl80211_get_interface,
9486 .dumpit = nl80211_dump_interface,
9487 .policy = nl80211_policy,
9488 /* can be retrieved by unprivileged users */
Johannes Berg5fe231e2013-05-08 21:45:15 +02009489 .internal_flags = NL80211_FLAG_NEED_WDEV |
9490 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -04009491 },
9492 {
9493 .cmd = NL80211_CMD_SET_INTERFACE,
9494 .doit = nl80211_set_interface,
9495 .policy = nl80211_policy,
9496 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02009497 .internal_flags = NL80211_FLAG_NEED_NETDEV |
9498 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -04009499 },
9500 {
9501 .cmd = NL80211_CMD_NEW_INTERFACE,
9502 .doit = nl80211_new_interface,
9503 .policy = nl80211_policy,
9504 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02009505 .internal_flags = NL80211_FLAG_NEED_WIPHY |
9506 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -04009507 },
9508 {
9509 .cmd = NL80211_CMD_DEL_INTERFACE,
9510 .doit = nl80211_del_interface,
9511 .policy = nl80211_policy,
9512 .flags = GENL_ADMIN_PERM,
Johannes Berg84efbb82012-06-16 00:00:26 +02009513 .internal_flags = NL80211_FLAG_NEED_WDEV |
Johannes Berg4c476992010-10-04 21:36:35 +02009514 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -04009515 },
Johannes Berg41ade002007-12-19 02:03:29 +01009516 {
9517 .cmd = NL80211_CMD_GET_KEY,
9518 .doit = nl80211_get_key,
9519 .policy = nl80211_policy,
9520 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02009521 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009522 NL80211_FLAG_NEED_RTNL,
Johannes Berg41ade002007-12-19 02:03:29 +01009523 },
9524 {
9525 .cmd = NL80211_CMD_SET_KEY,
9526 .doit = nl80211_set_key,
9527 .policy = nl80211_policy,
9528 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02009529 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009530 NL80211_FLAG_NEED_RTNL,
Johannes Berg41ade002007-12-19 02:03:29 +01009531 },
9532 {
9533 .cmd = NL80211_CMD_NEW_KEY,
9534 .doit = nl80211_new_key,
9535 .policy = nl80211_policy,
9536 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02009537 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009538 NL80211_FLAG_NEED_RTNL,
Johannes Berg41ade002007-12-19 02:03:29 +01009539 },
9540 {
9541 .cmd = NL80211_CMD_DEL_KEY,
9542 .doit = nl80211_del_key,
9543 .policy = nl80211_policy,
9544 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02009545 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009546 NL80211_FLAG_NEED_RTNL,
Johannes Berg41ade002007-12-19 02:03:29 +01009547 },
Johannes Berged1b6cc2007-12-19 02:03:32 +01009548 {
9549 .cmd = NL80211_CMD_SET_BEACON,
9550 .policy = nl80211_policy,
9551 .flags = GENL_ADMIN_PERM,
Johannes Berg88600202012-02-13 15:17:18 +01009552 .doit = nl80211_set_beacon,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02009553 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009554 NL80211_FLAG_NEED_RTNL,
Johannes Berged1b6cc2007-12-19 02:03:32 +01009555 },
9556 {
Johannes Berg88600202012-02-13 15:17:18 +01009557 .cmd = NL80211_CMD_START_AP,
Johannes Berged1b6cc2007-12-19 02:03:32 +01009558 .policy = nl80211_policy,
9559 .flags = GENL_ADMIN_PERM,
Johannes Berg88600202012-02-13 15:17:18 +01009560 .doit = nl80211_start_ap,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02009561 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009562 NL80211_FLAG_NEED_RTNL,
Johannes Berged1b6cc2007-12-19 02:03:32 +01009563 },
9564 {
Johannes Berg88600202012-02-13 15:17:18 +01009565 .cmd = NL80211_CMD_STOP_AP,
Johannes Berged1b6cc2007-12-19 02:03:32 +01009566 .policy = nl80211_policy,
9567 .flags = GENL_ADMIN_PERM,
Johannes Berg88600202012-02-13 15:17:18 +01009568 .doit = nl80211_stop_ap,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02009569 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009570 NL80211_FLAG_NEED_RTNL,
Johannes Berged1b6cc2007-12-19 02:03:32 +01009571 },
Johannes Berg5727ef12007-12-19 02:03:34 +01009572 {
9573 .cmd = NL80211_CMD_GET_STATION,
9574 .doit = nl80211_get_station,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01009575 .dumpit = nl80211_dump_station,
Johannes Berg5727ef12007-12-19 02:03:34 +01009576 .policy = nl80211_policy,
Johannes Berg4c476992010-10-04 21:36:35 +02009577 .internal_flags = NL80211_FLAG_NEED_NETDEV |
9578 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +01009579 },
9580 {
9581 .cmd = NL80211_CMD_SET_STATION,
9582 .doit = nl80211_set_station,
9583 .policy = nl80211_policy,
9584 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02009585 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009586 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +01009587 },
9588 {
9589 .cmd = NL80211_CMD_NEW_STATION,
9590 .doit = nl80211_new_station,
9591 .policy = nl80211_policy,
9592 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02009593 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009594 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +01009595 },
9596 {
9597 .cmd = NL80211_CMD_DEL_STATION,
9598 .doit = nl80211_del_station,
9599 .policy = nl80211_policy,
9600 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02009601 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009602 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +01009603 },
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01009604 {
9605 .cmd = NL80211_CMD_GET_MPATH,
9606 .doit = nl80211_get_mpath,
9607 .dumpit = nl80211_dump_mpath,
9608 .policy = nl80211_policy,
9609 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02009610 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009611 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01009612 },
9613 {
9614 .cmd = NL80211_CMD_SET_MPATH,
9615 .doit = nl80211_set_mpath,
9616 .policy = nl80211_policy,
9617 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02009618 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009619 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01009620 },
9621 {
9622 .cmd = NL80211_CMD_NEW_MPATH,
9623 .doit = nl80211_new_mpath,
9624 .policy = nl80211_policy,
9625 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02009626 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009627 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01009628 },
9629 {
9630 .cmd = NL80211_CMD_DEL_MPATH,
9631 .doit = nl80211_del_mpath,
9632 .policy = nl80211_policy,
9633 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02009634 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009635 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01009636 },
Jouni Malinen9f1ba902008-08-07 20:07:01 +03009637 {
9638 .cmd = NL80211_CMD_SET_BSS,
9639 .doit = nl80211_set_bss,
9640 .policy = nl80211_policy,
9641 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02009642 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009643 NL80211_FLAG_NEED_RTNL,
Jouni Malinen9f1ba902008-08-07 20:07:01 +03009644 },
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07009645 {
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08009646 .cmd = NL80211_CMD_GET_REG,
9647 .doit = nl80211_get_reg,
9648 .policy = nl80211_policy,
Johannes Berg5fe231e2013-05-08 21:45:15 +02009649 .internal_flags = NL80211_FLAG_NEED_RTNL,
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08009650 /* can be retrieved by unprivileged users */
9651 },
9652 {
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07009653 .cmd = NL80211_CMD_SET_REG,
9654 .doit = nl80211_set_reg,
9655 .policy = nl80211_policy,
9656 .flags = GENL_ADMIN_PERM,
Johannes Berg5fe231e2013-05-08 21:45:15 +02009657 .internal_flags = NL80211_FLAG_NEED_RTNL,
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07009658 },
9659 {
9660 .cmd = NL80211_CMD_REQ_SET_REG,
9661 .doit = nl80211_req_set_reg,
9662 .policy = nl80211_policy,
9663 .flags = GENL_ADMIN_PERM,
9664 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07009665 {
Javier Cardona24bdd9f2010-12-16 17:37:48 -08009666 .cmd = NL80211_CMD_GET_MESH_CONFIG,
9667 .doit = nl80211_get_mesh_config,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07009668 .policy = nl80211_policy,
9669 /* can be retrieved by unprivileged users */
Johannes Berg2b5f8b02012-04-02 10:51:55 +02009670 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009671 NL80211_FLAG_NEED_RTNL,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07009672 },
9673 {
Javier Cardona24bdd9f2010-12-16 17:37:48 -08009674 .cmd = NL80211_CMD_SET_MESH_CONFIG,
9675 .doit = nl80211_update_mesh_config,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07009676 .policy = nl80211_policy,
9677 .flags = GENL_ADMIN_PERM,
Johannes Berg29cbe682010-12-03 09:20:44 +01009678 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009679 NL80211_FLAG_NEED_RTNL,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07009680 },
Jouni Malinen9aed3cc2009-01-13 16:03:29 +02009681 {
Johannes Berg2a519312009-02-10 21:25:55 +01009682 .cmd = NL80211_CMD_TRIGGER_SCAN,
9683 .doit = nl80211_trigger_scan,
9684 .policy = nl80211_policy,
9685 .flags = GENL_ADMIN_PERM,
Johannes Bergfd014282012-06-18 19:17:03 +02009686 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009687 NL80211_FLAG_NEED_RTNL,
Johannes Berg2a519312009-02-10 21:25:55 +01009688 },
9689 {
9690 .cmd = NL80211_CMD_GET_SCAN,
9691 .policy = nl80211_policy,
9692 .dumpit = nl80211_dump_scan,
9693 },
Jouni Malinen636a5d32009-03-19 13:39:22 +02009694 {
Luciano Coelho807f8a82011-05-11 17:09:35 +03009695 .cmd = NL80211_CMD_START_SCHED_SCAN,
9696 .doit = nl80211_start_sched_scan,
9697 .policy = nl80211_policy,
9698 .flags = GENL_ADMIN_PERM,
9699 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
9700 NL80211_FLAG_NEED_RTNL,
9701 },
9702 {
9703 .cmd = NL80211_CMD_STOP_SCHED_SCAN,
9704 .doit = nl80211_stop_sched_scan,
9705 .policy = nl80211_policy,
9706 .flags = GENL_ADMIN_PERM,
9707 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
9708 NL80211_FLAG_NEED_RTNL,
9709 },
9710 {
Jouni Malinen636a5d32009-03-19 13:39:22 +02009711 .cmd = NL80211_CMD_AUTHENTICATE,
9712 .doit = nl80211_authenticate,
9713 .policy = nl80211_policy,
9714 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02009715 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009716 NL80211_FLAG_NEED_RTNL,
Jouni Malinen636a5d32009-03-19 13:39:22 +02009717 },
9718 {
9719 .cmd = NL80211_CMD_ASSOCIATE,
9720 .doit = nl80211_associate,
9721 .policy = nl80211_policy,
9722 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02009723 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009724 NL80211_FLAG_NEED_RTNL,
Jouni Malinen636a5d32009-03-19 13:39:22 +02009725 },
9726 {
9727 .cmd = NL80211_CMD_DEAUTHENTICATE,
9728 .doit = nl80211_deauthenticate,
9729 .policy = nl80211_policy,
9730 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02009731 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009732 NL80211_FLAG_NEED_RTNL,
Jouni Malinen636a5d32009-03-19 13:39:22 +02009733 },
9734 {
9735 .cmd = NL80211_CMD_DISASSOCIATE,
9736 .doit = nl80211_disassociate,
9737 .policy = nl80211_policy,
9738 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02009739 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009740 NL80211_FLAG_NEED_RTNL,
Jouni Malinen636a5d32009-03-19 13:39:22 +02009741 },
Johannes Berg04a773a2009-04-19 21:24:32 +02009742 {
9743 .cmd = NL80211_CMD_JOIN_IBSS,
9744 .doit = nl80211_join_ibss,
9745 .policy = nl80211_policy,
9746 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02009747 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009748 NL80211_FLAG_NEED_RTNL,
Johannes Berg04a773a2009-04-19 21:24:32 +02009749 },
9750 {
9751 .cmd = NL80211_CMD_LEAVE_IBSS,
9752 .doit = nl80211_leave_ibss,
9753 .policy = nl80211_policy,
9754 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02009755 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009756 NL80211_FLAG_NEED_RTNL,
Johannes Berg04a773a2009-04-19 21:24:32 +02009757 },
Johannes Bergaff89a92009-07-01 21:26:51 +02009758#ifdef CONFIG_NL80211_TESTMODE
9759 {
9760 .cmd = NL80211_CMD_TESTMODE,
9761 .doit = nl80211_testmode_do,
Wey-Yi Guy71063f02011-05-20 09:05:54 -07009762 .dumpit = nl80211_testmode_dump,
Johannes Bergaff89a92009-07-01 21:26:51 +02009763 .policy = nl80211_policy,
9764 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02009765 .internal_flags = NL80211_FLAG_NEED_WIPHY |
9766 NL80211_FLAG_NEED_RTNL,
Johannes Bergaff89a92009-07-01 21:26:51 +02009767 },
9768#endif
Samuel Ortizb23aa672009-07-01 21:26:54 +02009769 {
9770 .cmd = NL80211_CMD_CONNECT,
9771 .doit = nl80211_connect,
9772 .policy = nl80211_policy,
9773 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02009774 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009775 NL80211_FLAG_NEED_RTNL,
Samuel Ortizb23aa672009-07-01 21:26:54 +02009776 },
9777 {
9778 .cmd = NL80211_CMD_DISCONNECT,
9779 .doit = nl80211_disconnect,
9780 .policy = nl80211_policy,
9781 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02009782 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009783 NL80211_FLAG_NEED_RTNL,
Samuel Ortizb23aa672009-07-01 21:26:54 +02009784 },
Johannes Berg463d0182009-07-14 00:33:35 +02009785 {
9786 .cmd = NL80211_CMD_SET_WIPHY_NETNS,
9787 .doit = nl80211_wiphy_netns,
9788 .policy = nl80211_policy,
9789 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02009790 .internal_flags = NL80211_FLAG_NEED_WIPHY |
9791 NL80211_FLAG_NEED_RTNL,
Johannes Berg463d0182009-07-14 00:33:35 +02009792 },
Holger Schurig61fa7132009-11-11 12:25:40 +01009793 {
9794 .cmd = NL80211_CMD_GET_SURVEY,
9795 .policy = nl80211_policy,
9796 .dumpit = nl80211_dump_survey,
9797 },
Samuel Ortiz67fbb162009-11-24 23:59:15 +01009798 {
9799 .cmd = NL80211_CMD_SET_PMKSA,
9800 .doit = nl80211_setdel_pmksa,
9801 .policy = nl80211_policy,
9802 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02009803 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009804 NL80211_FLAG_NEED_RTNL,
Samuel Ortiz67fbb162009-11-24 23:59:15 +01009805 },
9806 {
9807 .cmd = NL80211_CMD_DEL_PMKSA,
9808 .doit = nl80211_setdel_pmksa,
9809 .policy = nl80211_policy,
9810 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02009811 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009812 NL80211_FLAG_NEED_RTNL,
Samuel Ortiz67fbb162009-11-24 23:59:15 +01009813 },
9814 {
9815 .cmd = NL80211_CMD_FLUSH_PMKSA,
9816 .doit = nl80211_flush_pmksa,
9817 .policy = nl80211_policy,
9818 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02009819 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009820 NL80211_FLAG_NEED_RTNL,
Samuel Ortiz67fbb162009-11-24 23:59:15 +01009821 },
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009822 {
9823 .cmd = NL80211_CMD_REMAIN_ON_CHANNEL,
9824 .doit = nl80211_remain_on_channel,
9825 .policy = nl80211_policy,
9826 .flags = GENL_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +02009827 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009828 NL80211_FLAG_NEED_RTNL,
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009829 },
9830 {
9831 .cmd = NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL,
9832 .doit = nl80211_cancel_remain_on_channel,
9833 .policy = nl80211_policy,
9834 .flags = GENL_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +02009835 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009836 NL80211_FLAG_NEED_RTNL,
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009837 },
Jouni Malinen13ae75b2009-12-29 12:59:45 +02009838 {
9839 .cmd = NL80211_CMD_SET_TX_BITRATE_MASK,
9840 .doit = nl80211_set_tx_bitrate_mask,
9841 .policy = nl80211_policy,
9842 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02009843 .internal_flags = NL80211_FLAG_NEED_NETDEV |
9844 NL80211_FLAG_NEED_RTNL,
Jouni Malinen13ae75b2009-12-29 12:59:45 +02009845 },
Jouni Malinen026331c2010-02-15 12:53:10 +02009846 {
Johannes Berg2e161f72010-08-12 15:38:38 +02009847 .cmd = NL80211_CMD_REGISTER_FRAME,
9848 .doit = nl80211_register_mgmt,
Jouni Malinen026331c2010-02-15 12:53:10 +02009849 .policy = nl80211_policy,
9850 .flags = GENL_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +02009851 .internal_flags = NL80211_FLAG_NEED_WDEV |
Johannes Berg4c476992010-10-04 21:36:35 +02009852 NL80211_FLAG_NEED_RTNL,
Jouni Malinen026331c2010-02-15 12:53:10 +02009853 },
9854 {
Johannes Berg2e161f72010-08-12 15:38:38 +02009855 .cmd = NL80211_CMD_FRAME,
9856 .doit = nl80211_tx_mgmt,
Jouni Malinen026331c2010-02-15 12:53:10 +02009857 .policy = nl80211_policy,
9858 .flags = GENL_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +02009859 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009860 NL80211_FLAG_NEED_RTNL,
Jouni Malinen026331c2010-02-15 12:53:10 +02009861 },
Kalle Valoffb9eb32010-02-17 17:58:10 +02009862 {
Johannes Bergf7ca38d2010-11-25 10:02:29 +01009863 .cmd = NL80211_CMD_FRAME_WAIT_CANCEL,
9864 .doit = nl80211_tx_mgmt_cancel_wait,
9865 .policy = nl80211_policy,
9866 .flags = GENL_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +02009867 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Bergf7ca38d2010-11-25 10:02:29 +01009868 NL80211_FLAG_NEED_RTNL,
9869 },
9870 {
Kalle Valoffb9eb32010-02-17 17:58:10 +02009871 .cmd = NL80211_CMD_SET_POWER_SAVE,
9872 .doit = nl80211_set_power_save,
9873 .policy = nl80211_policy,
9874 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02009875 .internal_flags = NL80211_FLAG_NEED_NETDEV |
9876 NL80211_FLAG_NEED_RTNL,
Kalle Valoffb9eb32010-02-17 17:58:10 +02009877 },
9878 {
9879 .cmd = NL80211_CMD_GET_POWER_SAVE,
9880 .doit = nl80211_get_power_save,
9881 .policy = nl80211_policy,
9882 /* can be retrieved by unprivileged users */
Johannes Berg4c476992010-10-04 21:36:35 +02009883 .internal_flags = NL80211_FLAG_NEED_NETDEV |
9884 NL80211_FLAG_NEED_RTNL,
Kalle Valoffb9eb32010-02-17 17:58:10 +02009885 },
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02009886 {
9887 .cmd = NL80211_CMD_SET_CQM,
9888 .doit = nl80211_set_cqm,
9889 .policy = nl80211_policy,
9890 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02009891 .internal_flags = NL80211_FLAG_NEED_NETDEV |
9892 NL80211_FLAG_NEED_RTNL,
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02009893 },
Johannes Bergf444de02010-05-05 15:25:02 +02009894 {
9895 .cmd = NL80211_CMD_SET_CHANNEL,
9896 .doit = nl80211_set_channel,
9897 .policy = nl80211_policy,
9898 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02009899 .internal_flags = NL80211_FLAG_NEED_NETDEV |
9900 NL80211_FLAG_NEED_RTNL,
Johannes Bergf444de02010-05-05 15:25:02 +02009901 },
Bill Jordane8347eb2010-10-01 13:54:28 -04009902 {
9903 .cmd = NL80211_CMD_SET_WDS_PEER,
9904 .doit = nl80211_set_wds_peer,
9905 .policy = nl80211_policy,
9906 .flags = GENL_ADMIN_PERM,
Johannes Berg43b19952010-10-07 13:10:30 +02009907 .internal_flags = NL80211_FLAG_NEED_NETDEV |
9908 NL80211_FLAG_NEED_RTNL,
Bill Jordane8347eb2010-10-01 13:54:28 -04009909 },
Johannes Berg29cbe682010-12-03 09:20:44 +01009910 {
9911 .cmd = NL80211_CMD_JOIN_MESH,
9912 .doit = nl80211_join_mesh,
9913 .policy = nl80211_policy,
9914 .flags = GENL_ADMIN_PERM,
9915 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
9916 NL80211_FLAG_NEED_RTNL,
9917 },
9918 {
9919 .cmd = NL80211_CMD_LEAVE_MESH,
9920 .doit = nl80211_leave_mesh,
9921 .policy = nl80211_policy,
9922 .flags = GENL_ADMIN_PERM,
9923 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
9924 NL80211_FLAG_NEED_RTNL,
9925 },
Johannes Bergdfb89c52012-06-27 09:23:48 +02009926#ifdef CONFIG_PM
Johannes Bergff1b6e62011-05-04 15:37:28 +02009927 {
9928 .cmd = NL80211_CMD_GET_WOWLAN,
9929 .doit = nl80211_get_wowlan,
9930 .policy = nl80211_policy,
9931 /* can be retrieved by unprivileged users */
9932 .internal_flags = NL80211_FLAG_NEED_WIPHY |
9933 NL80211_FLAG_NEED_RTNL,
9934 },
9935 {
9936 .cmd = NL80211_CMD_SET_WOWLAN,
9937 .doit = nl80211_set_wowlan,
9938 .policy = nl80211_policy,
9939 .flags = GENL_ADMIN_PERM,
9940 .internal_flags = NL80211_FLAG_NEED_WIPHY |
9941 NL80211_FLAG_NEED_RTNL,
9942 },
Johannes Bergdfb89c52012-06-27 09:23:48 +02009943#endif
Johannes Berge5497d72011-07-05 16:35:40 +02009944 {
9945 .cmd = NL80211_CMD_SET_REKEY_OFFLOAD,
9946 .doit = nl80211_set_rekey_data,
9947 .policy = nl80211_policy,
9948 .flags = GENL_ADMIN_PERM,
9949 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
9950 NL80211_FLAG_NEED_RTNL,
9951 },
Arik Nemtsov109086c2011-09-28 14:12:50 +03009952 {
9953 .cmd = NL80211_CMD_TDLS_MGMT,
9954 .doit = nl80211_tdls_mgmt,
9955 .policy = nl80211_policy,
9956 .flags = GENL_ADMIN_PERM,
9957 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
9958 NL80211_FLAG_NEED_RTNL,
9959 },
9960 {
9961 .cmd = NL80211_CMD_TDLS_OPER,
9962 .doit = nl80211_tdls_oper,
9963 .policy = nl80211_policy,
9964 .flags = GENL_ADMIN_PERM,
9965 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
9966 NL80211_FLAG_NEED_RTNL,
9967 },
Johannes Berg28946da2011-11-04 11:18:12 +01009968 {
9969 .cmd = NL80211_CMD_UNEXPECTED_FRAME,
9970 .doit = nl80211_register_unexpected_frame,
9971 .policy = nl80211_policy,
9972 .flags = GENL_ADMIN_PERM,
9973 .internal_flags = NL80211_FLAG_NEED_NETDEV |
9974 NL80211_FLAG_NEED_RTNL,
9975 },
Johannes Berg7f6cf312011-11-04 11:18:15 +01009976 {
9977 .cmd = NL80211_CMD_PROBE_CLIENT,
9978 .doit = nl80211_probe_client,
9979 .policy = nl80211_policy,
9980 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02009981 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg7f6cf312011-11-04 11:18:15 +01009982 NL80211_FLAG_NEED_RTNL,
9983 },
Johannes Berg5e760232011-11-04 11:18:17 +01009984 {
9985 .cmd = NL80211_CMD_REGISTER_BEACONS,
9986 .doit = nl80211_register_beacons,
9987 .policy = nl80211_policy,
9988 .flags = GENL_ADMIN_PERM,
9989 .internal_flags = NL80211_FLAG_NEED_WIPHY |
9990 NL80211_FLAG_NEED_RTNL,
9991 },
Simon Wunderlich1d9d9212011-11-18 14:20:43 +01009992 {
9993 .cmd = NL80211_CMD_SET_NOACK_MAP,
9994 .doit = nl80211_set_noack_map,
9995 .policy = nl80211_policy,
9996 .flags = GENL_ADMIN_PERM,
9997 .internal_flags = NL80211_FLAG_NEED_NETDEV |
9998 NL80211_FLAG_NEED_RTNL,
9999 },
Johannes Berg98104fde2012-06-16 00:19:54 +020010000 {
10001 .cmd = NL80211_CMD_START_P2P_DEVICE,
10002 .doit = nl80211_start_p2p_device,
10003 .policy = nl80211_policy,
10004 .flags = GENL_ADMIN_PERM,
10005 .internal_flags = NL80211_FLAG_NEED_WDEV |
10006 NL80211_FLAG_NEED_RTNL,
10007 },
10008 {
10009 .cmd = NL80211_CMD_STOP_P2P_DEVICE,
10010 .doit = nl80211_stop_p2p_device,
10011 .policy = nl80211_policy,
10012 .flags = GENL_ADMIN_PERM,
10013 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
10014 NL80211_FLAG_NEED_RTNL,
10015 },
Antonio Quartullif4e583c2012-11-02 13:27:48 +010010016 {
10017 .cmd = NL80211_CMD_SET_MCAST_RATE,
10018 .doit = nl80211_set_mcast_rate,
10019 .policy = nl80211_policy,
10020 .flags = GENL_ADMIN_PERM,
10021 .internal_flags = NL80211_FLAG_NEED_NETDEV |
10022 NL80211_FLAG_NEED_RTNL,
10023 },
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +053010024 {
10025 .cmd = NL80211_CMD_SET_MAC_ACL,
10026 .doit = nl80211_set_mac_acl,
10027 .policy = nl80211_policy,
10028 .flags = GENL_ADMIN_PERM,
10029 .internal_flags = NL80211_FLAG_NEED_NETDEV |
10030 NL80211_FLAG_NEED_RTNL,
10031 },
Simon Wunderlich04f39042013-02-08 18:16:19 +010010032 {
10033 .cmd = NL80211_CMD_RADAR_DETECT,
10034 .doit = nl80211_start_radar_detection,
10035 .policy = nl80211_policy,
10036 .flags = GENL_ADMIN_PERM,
10037 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
10038 NL80211_FLAG_NEED_RTNL,
10039 },
Johannes Berg3713b4e2013-02-14 16:19:38 +010010040 {
10041 .cmd = NL80211_CMD_GET_PROTOCOL_FEATURES,
10042 .doit = nl80211_get_protocol_features,
10043 .policy = nl80211_policy,
10044 },
Jouni Malinen355199e2013-02-27 17:14:27 +020010045 {
10046 .cmd = NL80211_CMD_UPDATE_FT_IES,
10047 .doit = nl80211_update_ft_ies,
10048 .policy = nl80211_policy,
10049 .flags = GENL_ADMIN_PERM,
10050 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
10051 NL80211_FLAG_NEED_RTNL,
10052 },
Arend van Spriel5de17982013-04-18 15:49:00 +020010053 {
10054 .cmd = NL80211_CMD_CRIT_PROTOCOL_START,
10055 .doit = nl80211_crit_protocol_start,
10056 .policy = nl80211_policy,
10057 .flags = GENL_ADMIN_PERM,
10058 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
10059 NL80211_FLAG_NEED_RTNL,
10060 },
10061 {
10062 .cmd = NL80211_CMD_CRIT_PROTOCOL_STOP,
10063 .doit = nl80211_crit_protocol_stop,
10064 .policy = nl80211_policy,
10065 .flags = GENL_ADMIN_PERM,
10066 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
10067 NL80211_FLAG_NEED_RTNL,
Amitkumar Karwarbe29b992013-06-28 11:51:26 -070010068 },
10069 {
10070 .cmd = NL80211_CMD_GET_COALESCE,
10071 .doit = nl80211_get_coalesce,
10072 .policy = nl80211_policy,
10073 .internal_flags = NL80211_FLAG_NEED_WIPHY |
10074 NL80211_FLAG_NEED_RTNL,
10075 },
10076 {
10077 .cmd = NL80211_CMD_SET_COALESCE,
10078 .doit = nl80211_set_coalesce,
10079 .policy = nl80211_policy,
10080 .flags = GENL_ADMIN_PERM,
10081 .internal_flags = NL80211_FLAG_NEED_WIPHY |
10082 NL80211_FLAG_NEED_RTNL,
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +020010083 },
10084 {
10085 .cmd = NL80211_CMD_CHANNEL_SWITCH,
10086 .doit = nl80211_channel_switch,
10087 .policy = nl80211_policy,
10088 .flags = GENL_ADMIN_PERM,
10089 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
10090 NL80211_FLAG_NEED_RTNL,
10091 },
Johannes Bergad7e7182013-11-13 13:37:47 +010010092 {
10093 .cmd = NL80211_CMD_VENDOR,
10094 .doit = nl80211_vendor_cmd,
10095 .policy = nl80211_policy,
10096 .flags = GENL_ADMIN_PERM,
10097 .internal_flags = NL80211_FLAG_NEED_WIPHY |
10098 NL80211_FLAG_NEED_RTNL,
10099 },
Kyeyoon Parkfa9ffc72013-12-16 23:01:30 -080010100 {
10101 .cmd = NL80211_CMD_SET_QOS_MAP,
10102 .doit = nl80211_set_qos_map,
10103 .policy = nl80211_policy,
10104 .flags = GENL_ADMIN_PERM,
10105 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
10106 NL80211_FLAG_NEED_RTNL,
10107 },
Johannes Berg55682962007-09-20 13:09:35 -040010108};
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010109
Johannes Berg55682962007-09-20 13:09:35 -040010110/* notification functions */
10111
Johannes Berg3bb20552014-05-26 13:52:25 +020010112void nl80211_notify_wiphy(struct cfg80211_registered_device *rdev,
10113 enum nl80211_commands cmd)
Johannes Berg55682962007-09-20 13:09:35 -040010114{
10115 struct sk_buff *msg;
Johannes Berg86e8cf92013-06-19 10:57:22 +020010116 struct nl80211_dump_wiphy_state state = {};
Johannes Berg55682962007-09-20 13:09:35 -040010117
Johannes Berg3bb20552014-05-26 13:52:25 +020010118 WARN_ON(cmd != NL80211_CMD_NEW_WIPHY &&
10119 cmd != NL80211_CMD_DEL_WIPHY);
10120
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -070010121 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -040010122 if (!msg)
10123 return;
10124
Johannes Berg3bb20552014-05-26 13:52:25 +020010125 if (nl80211_send_wiphy(rdev, cmd, msg, 0, 0, 0, &state) < 0) {
Johannes Berg55682962007-09-20 13:09:35 -040010126 nlmsg_free(msg);
10127 return;
10128 }
10129
Johannes Berg68eb5502013-11-19 15:19:38 +010010130 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010010131 NL80211_MCGRP_CONFIG, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -040010132}
10133
Johannes Berg362a4152009-05-24 16:43:15 +020010134static int nl80211_add_scan_req(struct sk_buff *msg,
10135 struct cfg80211_registered_device *rdev)
10136{
10137 struct cfg80211_scan_request *req = rdev->scan_req;
10138 struct nlattr *nest;
10139 int i;
10140
10141 if (WARN_ON(!req))
10142 return 0;
10143
10144 nest = nla_nest_start(msg, NL80211_ATTR_SCAN_SSIDS);
10145 if (!nest)
10146 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -040010147 for (i = 0; i < req->n_ssids; i++) {
10148 if (nla_put(msg, i, req->ssids[i].ssid_len, req->ssids[i].ssid))
10149 goto nla_put_failure;
10150 }
Johannes Berg362a4152009-05-24 16:43:15 +020010151 nla_nest_end(msg, nest);
10152
10153 nest = nla_nest_start(msg, NL80211_ATTR_SCAN_FREQUENCIES);
10154 if (!nest)
10155 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -040010156 for (i = 0; i < req->n_channels; i++) {
10157 if (nla_put_u32(msg, i, req->channels[i]->center_freq))
10158 goto nla_put_failure;
10159 }
Johannes Berg362a4152009-05-24 16:43:15 +020010160 nla_nest_end(msg, nest);
10161
David S. Miller9360ffd2012-03-29 04:41:26 -040010162 if (req->ie &&
10163 nla_put(msg, NL80211_ATTR_IE, req->ie_len, req->ie))
10164 goto nla_put_failure;
Johannes Berg362a4152009-05-24 16:43:15 +020010165
Johannes Bergae917c92013-10-25 11:05:22 +020010166 if (req->flags &&
10167 nla_put_u32(msg, NL80211_ATTR_SCAN_FLAGS, req->flags))
10168 goto nla_put_failure;
Sam Lefflered4737712012-10-11 21:03:31 -070010169
Johannes Berg362a4152009-05-24 16:43:15 +020010170 return 0;
10171 nla_put_failure:
10172 return -ENOBUFS;
10173}
10174
Johannes Berga538e2d2009-06-16 19:56:42 +020010175static int nl80211_send_scan_msg(struct sk_buff *msg,
10176 struct cfg80211_registered_device *rdev,
Johannes Bergfd014282012-06-18 19:17:03 +020010177 struct wireless_dev *wdev,
Eric W. Biederman15e47302012-09-07 20:12:54 +000010178 u32 portid, u32 seq, int flags,
Johannes Berga538e2d2009-06-16 19:56:42 +020010179 u32 cmd)
Johannes Berg2a519312009-02-10 21:25:55 +010010180{
10181 void *hdr;
10182
Eric W. Biederman15e47302012-09-07 20:12:54 +000010183 hdr = nl80211hdr_put(msg, portid, seq, flags, cmd);
Johannes Berg2a519312009-02-10 21:25:55 +010010184 if (!hdr)
10185 return -1;
10186
David S. Miller9360ffd2012-03-29 04:41:26 -040010187 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Bergfd014282012-06-18 19:17:03 +020010188 (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
10189 wdev->netdev->ifindex)) ||
10190 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)))
David S. Miller9360ffd2012-03-29 04:41:26 -040010191 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +010010192
Johannes Berg362a4152009-05-24 16:43:15 +020010193 /* ignore errors and send incomplete event anyway */
10194 nl80211_add_scan_req(msg, rdev);
Johannes Berg2a519312009-02-10 21:25:55 +010010195
10196 return genlmsg_end(msg, hdr);
10197
10198 nla_put_failure:
10199 genlmsg_cancel(msg, hdr);
10200 return -EMSGSIZE;
10201}
10202
Luciano Coelho807f8a82011-05-11 17:09:35 +030010203static int
10204nl80211_send_sched_scan_msg(struct sk_buff *msg,
10205 struct cfg80211_registered_device *rdev,
10206 struct net_device *netdev,
Eric W. Biederman15e47302012-09-07 20:12:54 +000010207 u32 portid, u32 seq, int flags, u32 cmd)
Luciano Coelho807f8a82011-05-11 17:09:35 +030010208{
10209 void *hdr;
10210
Eric W. Biederman15e47302012-09-07 20:12:54 +000010211 hdr = nl80211hdr_put(msg, portid, seq, flags, cmd);
Luciano Coelho807f8a82011-05-11 17:09:35 +030010212 if (!hdr)
10213 return -1;
10214
David S. Miller9360ffd2012-03-29 04:41:26 -040010215 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
10216 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex))
10217 goto nla_put_failure;
Luciano Coelho807f8a82011-05-11 17:09:35 +030010218
10219 return genlmsg_end(msg, hdr);
10220
10221 nla_put_failure:
10222 genlmsg_cancel(msg, hdr);
10223 return -EMSGSIZE;
10224}
10225
Johannes Berga538e2d2009-06-16 19:56:42 +020010226void nl80211_send_scan_start(struct cfg80211_registered_device *rdev,
Johannes Bergfd014282012-06-18 19:17:03 +020010227 struct wireless_dev *wdev)
Johannes Berga538e2d2009-06-16 19:56:42 +020010228{
10229 struct sk_buff *msg;
10230
Thomas Graf58050fc2012-06-28 03:57:45 +000010231 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berga538e2d2009-06-16 19:56:42 +020010232 if (!msg)
10233 return;
10234
Johannes Bergfd014282012-06-18 19:17:03 +020010235 if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0,
Johannes Berga538e2d2009-06-16 19:56:42 +020010236 NL80211_CMD_TRIGGER_SCAN) < 0) {
10237 nlmsg_free(msg);
10238 return;
10239 }
10240
Johannes Berg68eb5502013-11-19 15:19:38 +010010241 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010010242 NL80211_MCGRP_SCAN, GFP_KERNEL);
Johannes Berga538e2d2009-06-16 19:56:42 +020010243}
10244
Johannes Bergf9d15d12014-01-22 11:14:19 +020010245struct sk_buff *nl80211_build_scan_msg(struct cfg80211_registered_device *rdev,
10246 struct wireless_dev *wdev, bool aborted)
Johannes Berg2a519312009-02-10 21:25:55 +010010247{
10248 struct sk_buff *msg;
10249
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -070010250 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg2a519312009-02-10 21:25:55 +010010251 if (!msg)
Johannes Bergf9d15d12014-01-22 11:14:19 +020010252 return NULL;
Johannes Berg2a519312009-02-10 21:25:55 +010010253
Johannes Bergfd014282012-06-18 19:17:03 +020010254 if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0,
Johannes Bergf9d15d12014-01-22 11:14:19 +020010255 aborted ? NL80211_CMD_SCAN_ABORTED :
10256 NL80211_CMD_NEW_SCAN_RESULTS) < 0) {
Johannes Berg2a519312009-02-10 21:25:55 +010010257 nlmsg_free(msg);
Johannes Bergf9d15d12014-01-22 11:14:19 +020010258 return NULL;
Johannes Berg2a519312009-02-10 21:25:55 +010010259 }
10260
Johannes Bergf9d15d12014-01-22 11:14:19 +020010261 return msg;
Johannes Berg2a519312009-02-10 21:25:55 +010010262}
10263
Johannes Bergf9d15d12014-01-22 11:14:19 +020010264void nl80211_send_scan_result(struct cfg80211_registered_device *rdev,
10265 struct sk_buff *msg)
Johannes Berg2a519312009-02-10 21:25:55 +010010266{
Johannes Berg2a519312009-02-10 21:25:55 +010010267 if (!msg)
10268 return;
10269
Johannes Berg68eb5502013-11-19 15:19:38 +010010270 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010010271 NL80211_MCGRP_SCAN, GFP_KERNEL);
Johannes Berg2a519312009-02-10 21:25:55 +010010272}
10273
Luciano Coelho807f8a82011-05-11 17:09:35 +030010274void nl80211_send_sched_scan_results(struct cfg80211_registered_device *rdev,
10275 struct net_device *netdev)
10276{
10277 struct sk_buff *msg;
10278
10279 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
10280 if (!msg)
10281 return;
10282
10283 if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0,
10284 NL80211_CMD_SCHED_SCAN_RESULTS) < 0) {
10285 nlmsg_free(msg);
10286 return;
10287 }
10288
Johannes Berg68eb5502013-11-19 15:19:38 +010010289 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010010290 NL80211_MCGRP_SCAN, GFP_KERNEL);
Luciano Coelho807f8a82011-05-11 17:09:35 +030010291}
10292
10293void nl80211_send_sched_scan(struct cfg80211_registered_device *rdev,
10294 struct net_device *netdev, u32 cmd)
10295{
10296 struct sk_buff *msg;
10297
Thomas Graf58050fc2012-06-28 03:57:45 +000010298 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Luciano Coelho807f8a82011-05-11 17:09:35 +030010299 if (!msg)
10300 return;
10301
10302 if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0, cmd) < 0) {
10303 nlmsg_free(msg);
10304 return;
10305 }
10306
Johannes Berg68eb5502013-11-19 15:19:38 +010010307 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010010308 NL80211_MCGRP_SCAN, GFP_KERNEL);
Luciano Coelho807f8a82011-05-11 17:09:35 +030010309}
10310
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040010311/*
10312 * This can happen on global regulatory changes or device specific settings
10313 * based on custom world regulatory domains.
10314 */
10315void nl80211_send_reg_change_event(struct regulatory_request *request)
10316{
10317 struct sk_buff *msg;
10318 void *hdr;
10319
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -070010320 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040010321 if (!msg)
10322 return;
10323
10324 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_CHANGE);
10325 if (!hdr) {
10326 nlmsg_free(msg);
10327 return;
10328 }
10329
10330 /* Userspace can always count this one always being set */
David S. Miller9360ffd2012-03-29 04:41:26 -040010331 if (nla_put_u8(msg, NL80211_ATTR_REG_INITIATOR, request->initiator))
10332 goto nla_put_failure;
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040010333
David S. Miller9360ffd2012-03-29 04:41:26 -040010334 if (request->alpha2[0] == '0' && request->alpha2[1] == '0') {
10335 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
10336 NL80211_REGDOM_TYPE_WORLD))
10337 goto nla_put_failure;
10338 } else if (request->alpha2[0] == '9' && request->alpha2[1] == '9') {
10339 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
10340 NL80211_REGDOM_TYPE_CUSTOM_WORLD))
10341 goto nla_put_failure;
10342 } else if ((request->alpha2[0] == '9' && request->alpha2[1] == '8') ||
10343 request->intersect) {
10344 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
10345 NL80211_REGDOM_TYPE_INTERSECTION))
10346 goto nla_put_failure;
10347 } else {
10348 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
10349 NL80211_REGDOM_TYPE_COUNTRY) ||
10350 nla_put_string(msg, NL80211_ATTR_REG_ALPHA2,
10351 request->alpha2))
10352 goto nla_put_failure;
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040010353 }
10354
Johannes Bergf4173762012-12-03 18:23:37 +010010355 if (request->wiphy_idx != WIPHY_IDX_INVALID &&
David S. Miller9360ffd2012-03-29 04:41:26 -040010356 nla_put_u32(msg, NL80211_ATTR_WIPHY, request->wiphy_idx))
10357 goto nla_put_failure;
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040010358
Johannes Berg3b7b72e2011-10-22 19:05:51 +020010359 genlmsg_end(msg, hdr);
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040010360
Johannes Bergbc43b282009-07-25 10:54:13 +020010361 rcu_read_lock();
Johannes Berg68eb5502013-11-19 15:19:38 +010010362 genlmsg_multicast_allns(&nl80211_fam, msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010010363 NL80211_MCGRP_REGULATORY, GFP_ATOMIC);
Johannes Bergbc43b282009-07-25 10:54:13 +020010364 rcu_read_unlock();
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040010365
10366 return;
10367
10368nla_put_failure:
10369 genlmsg_cancel(msg, hdr);
10370 nlmsg_free(msg);
10371}
10372
Jouni Malinen6039f6d2009-03-19 13:39:21 +020010373static void nl80211_send_mlme_event(struct cfg80211_registered_device *rdev,
10374 struct net_device *netdev,
10375 const u8 *buf, size_t len,
Johannes Berge6d6e342009-07-01 21:26:47 +020010376 enum nl80211_commands cmd, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +020010377{
10378 struct sk_buff *msg;
10379 void *hdr;
10380
Johannes Berge6d6e342009-07-01 21:26:47 +020010381 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020010382 if (!msg)
10383 return;
10384
10385 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
10386 if (!hdr) {
10387 nlmsg_free(msg);
10388 return;
10389 }
10390
David S. Miller9360ffd2012-03-29 04:41:26 -040010391 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
10392 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
10393 nla_put(msg, NL80211_ATTR_FRAME, len, buf))
10394 goto nla_put_failure;
Jouni Malinen6039f6d2009-03-19 13:39:21 +020010395
Johannes Berg3b7b72e2011-10-22 19:05:51 +020010396 genlmsg_end(msg, hdr);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020010397
Johannes Berg68eb5502013-11-19 15:19:38 +010010398 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010010399 NL80211_MCGRP_MLME, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020010400 return;
10401
10402 nla_put_failure:
10403 genlmsg_cancel(msg, hdr);
10404 nlmsg_free(msg);
10405}
10406
10407void nl80211_send_rx_auth(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +020010408 struct net_device *netdev, const u8 *buf,
10409 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +020010410{
10411 nl80211_send_mlme_event(rdev, netdev, buf, len,
Johannes Berge6d6e342009-07-01 21:26:47 +020010412 NL80211_CMD_AUTHENTICATE, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020010413}
10414
10415void nl80211_send_rx_assoc(struct cfg80211_registered_device *rdev,
10416 struct net_device *netdev, const u8 *buf,
Johannes Berge6d6e342009-07-01 21:26:47 +020010417 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +020010418{
Johannes Berge6d6e342009-07-01 21:26:47 +020010419 nl80211_send_mlme_event(rdev, netdev, buf, len,
10420 NL80211_CMD_ASSOCIATE, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020010421}
10422
Jouni Malinen53b46b82009-03-27 20:53:56 +020010423void nl80211_send_deauth(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +020010424 struct net_device *netdev, const u8 *buf,
10425 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +020010426{
10427 nl80211_send_mlme_event(rdev, netdev, buf, len,
Johannes Berge6d6e342009-07-01 21:26:47 +020010428 NL80211_CMD_DEAUTHENTICATE, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020010429}
10430
Jouni Malinen53b46b82009-03-27 20:53:56 +020010431void nl80211_send_disassoc(struct cfg80211_registered_device *rdev,
10432 struct net_device *netdev, const u8 *buf,
Johannes Berge6d6e342009-07-01 21:26:47 +020010433 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +020010434{
10435 nl80211_send_mlme_event(rdev, netdev, buf, len,
Johannes Berge6d6e342009-07-01 21:26:47 +020010436 NL80211_CMD_DISASSOCIATE, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020010437}
10438
Johannes Berg6ff57cf2013-05-16 00:55:00 +020010439void cfg80211_rx_unprot_mlme_mgmt(struct net_device *dev, const u8 *buf,
10440 size_t len)
Jouni Malinencf4e5942010-12-16 00:52:40 +020010441{
Johannes Berg947add32013-02-22 22:05:20 +010010442 struct wireless_dev *wdev = dev->ieee80211_ptr;
10443 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080010444 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg6ff57cf2013-05-16 00:55:00 +020010445 const struct ieee80211_mgmt *mgmt = (void *)buf;
10446 u32 cmd;
Jouni Malinencf4e5942010-12-16 00:52:40 +020010447
Johannes Berg6ff57cf2013-05-16 00:55:00 +020010448 if (WARN_ON(len < 2))
10449 return;
10450
10451 if (ieee80211_is_deauth(mgmt->frame_control))
10452 cmd = NL80211_CMD_UNPROT_DEAUTHENTICATE;
10453 else
10454 cmd = NL80211_CMD_UNPROT_DISASSOCIATE;
10455
10456 trace_cfg80211_rx_unprot_mlme_mgmt(dev, buf, len);
10457 nl80211_send_mlme_event(rdev, dev, buf, len, cmd, GFP_ATOMIC);
Jouni Malinencf4e5942010-12-16 00:52:40 +020010458}
Johannes Berg6ff57cf2013-05-16 00:55:00 +020010459EXPORT_SYMBOL(cfg80211_rx_unprot_mlme_mgmt);
Jouni Malinencf4e5942010-12-16 00:52:40 +020010460
Luis R. Rodriguez1b06bb42009-05-02 00:34:48 -040010461static void nl80211_send_mlme_timeout(struct cfg80211_registered_device *rdev,
10462 struct net_device *netdev, int cmd,
Johannes Berge6d6e342009-07-01 21:26:47 +020010463 const u8 *addr, gfp_t gfp)
Jouni Malinen1965c852009-04-22 21:38:25 +030010464{
10465 struct sk_buff *msg;
10466 void *hdr;
10467
Johannes Berge6d6e342009-07-01 21:26:47 +020010468 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +030010469 if (!msg)
10470 return;
10471
10472 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
10473 if (!hdr) {
10474 nlmsg_free(msg);
10475 return;
10476 }
10477
David S. Miller9360ffd2012-03-29 04:41:26 -040010478 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
10479 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
10480 nla_put_flag(msg, NL80211_ATTR_TIMED_OUT) ||
10481 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr))
10482 goto nla_put_failure;
Jouni Malinen1965c852009-04-22 21:38:25 +030010483
Johannes Berg3b7b72e2011-10-22 19:05:51 +020010484 genlmsg_end(msg, hdr);
Jouni Malinen1965c852009-04-22 21:38:25 +030010485
Johannes Berg68eb5502013-11-19 15:19:38 +010010486 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010010487 NL80211_MCGRP_MLME, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +030010488 return;
10489
10490 nla_put_failure:
10491 genlmsg_cancel(msg, hdr);
10492 nlmsg_free(msg);
10493}
10494
10495void nl80211_send_auth_timeout(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +020010496 struct net_device *netdev, const u8 *addr,
10497 gfp_t gfp)
Jouni Malinen1965c852009-04-22 21:38:25 +030010498{
10499 nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_AUTHENTICATE,
Johannes Berge6d6e342009-07-01 21:26:47 +020010500 addr, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +030010501}
10502
10503void nl80211_send_assoc_timeout(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +020010504 struct net_device *netdev, const u8 *addr,
10505 gfp_t gfp)
Jouni Malinen1965c852009-04-22 21:38:25 +030010506{
Johannes Berge6d6e342009-07-01 21:26:47 +020010507 nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_ASSOCIATE,
10508 addr, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +030010509}
10510
Samuel Ortizb23aa672009-07-01 21:26:54 +020010511void nl80211_send_connect_result(struct cfg80211_registered_device *rdev,
10512 struct net_device *netdev, const u8 *bssid,
10513 const u8 *req_ie, size_t req_ie_len,
10514 const u8 *resp_ie, size_t resp_ie_len,
10515 u16 status, gfp_t gfp)
10516{
10517 struct sk_buff *msg;
10518 void *hdr;
10519
Thomas Graf58050fc2012-06-28 03:57:45 +000010520 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +020010521 if (!msg)
10522 return;
10523
10524 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONNECT);
10525 if (!hdr) {
10526 nlmsg_free(msg);
10527 return;
10528 }
10529
David S. Miller9360ffd2012-03-29 04:41:26 -040010530 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
10531 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
10532 (bssid && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) ||
10533 nla_put_u16(msg, NL80211_ATTR_STATUS_CODE, status) ||
10534 (req_ie &&
10535 nla_put(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie)) ||
10536 (resp_ie &&
10537 nla_put(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie)))
10538 goto nla_put_failure;
Samuel Ortizb23aa672009-07-01 21:26:54 +020010539
Johannes Berg3b7b72e2011-10-22 19:05:51 +020010540 genlmsg_end(msg, hdr);
Samuel Ortizb23aa672009-07-01 21:26:54 +020010541
Johannes Berg68eb5502013-11-19 15:19:38 +010010542 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010010543 NL80211_MCGRP_MLME, gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +020010544 return;
10545
10546 nla_put_failure:
10547 genlmsg_cancel(msg, hdr);
10548 nlmsg_free(msg);
10549
10550}
10551
10552void nl80211_send_roamed(struct cfg80211_registered_device *rdev,
10553 struct net_device *netdev, const u8 *bssid,
10554 const u8 *req_ie, size_t req_ie_len,
10555 const u8 *resp_ie, size_t resp_ie_len, gfp_t gfp)
10556{
10557 struct sk_buff *msg;
10558 void *hdr;
10559
Thomas Graf58050fc2012-06-28 03:57:45 +000010560 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +020010561 if (!msg)
10562 return;
10563
10564 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_ROAM);
10565 if (!hdr) {
10566 nlmsg_free(msg);
10567 return;
10568 }
10569
David S. Miller9360ffd2012-03-29 04:41:26 -040010570 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
10571 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
10572 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid) ||
10573 (req_ie &&
10574 nla_put(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie)) ||
10575 (resp_ie &&
10576 nla_put(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie)))
10577 goto nla_put_failure;
Samuel Ortizb23aa672009-07-01 21:26:54 +020010578
Johannes Berg3b7b72e2011-10-22 19:05:51 +020010579 genlmsg_end(msg, hdr);
Samuel Ortizb23aa672009-07-01 21:26:54 +020010580
Johannes Berg68eb5502013-11-19 15:19:38 +010010581 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010010582 NL80211_MCGRP_MLME, gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +020010583 return;
10584
10585 nla_put_failure:
10586 genlmsg_cancel(msg, hdr);
10587 nlmsg_free(msg);
10588
10589}
10590
10591void nl80211_send_disconnected(struct cfg80211_registered_device *rdev,
10592 struct net_device *netdev, u16 reason,
Johannes Berg667503dd2009-07-07 03:56:11 +020010593 const u8 *ie, size_t ie_len, bool from_ap)
Samuel Ortizb23aa672009-07-01 21:26:54 +020010594{
10595 struct sk_buff *msg;
10596 void *hdr;
10597
Thomas Graf58050fc2012-06-28 03:57:45 +000010598 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Samuel Ortizb23aa672009-07-01 21:26:54 +020010599 if (!msg)
10600 return;
10601
10602 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DISCONNECT);
10603 if (!hdr) {
10604 nlmsg_free(msg);
10605 return;
10606 }
10607
David S. Miller9360ffd2012-03-29 04:41:26 -040010608 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
10609 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
10610 (from_ap && reason &&
10611 nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason)) ||
10612 (from_ap &&
10613 nla_put_flag(msg, NL80211_ATTR_DISCONNECTED_BY_AP)) ||
10614 (ie && nla_put(msg, NL80211_ATTR_IE, ie_len, ie)))
10615 goto nla_put_failure;
Samuel Ortizb23aa672009-07-01 21:26:54 +020010616
Johannes Berg3b7b72e2011-10-22 19:05:51 +020010617 genlmsg_end(msg, hdr);
Samuel Ortizb23aa672009-07-01 21:26:54 +020010618
Johannes Berg68eb5502013-11-19 15:19:38 +010010619 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010010620 NL80211_MCGRP_MLME, GFP_KERNEL);
Samuel Ortizb23aa672009-07-01 21:26:54 +020010621 return;
10622
10623 nla_put_failure:
10624 genlmsg_cancel(msg, hdr);
10625 nlmsg_free(msg);
10626
10627}
10628
Johannes Berg04a773a2009-04-19 21:24:32 +020010629void nl80211_send_ibss_bssid(struct cfg80211_registered_device *rdev,
10630 struct net_device *netdev, const u8 *bssid,
10631 gfp_t gfp)
10632{
10633 struct sk_buff *msg;
10634 void *hdr;
10635
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -070010636 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Johannes Berg04a773a2009-04-19 21:24:32 +020010637 if (!msg)
10638 return;
10639
10640 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_JOIN_IBSS);
10641 if (!hdr) {
10642 nlmsg_free(msg);
10643 return;
10644 }
10645
David S. Miller9360ffd2012-03-29 04:41:26 -040010646 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
10647 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
10648 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid))
10649 goto nla_put_failure;
Johannes Berg04a773a2009-04-19 21:24:32 +020010650
Johannes Berg3b7b72e2011-10-22 19:05:51 +020010651 genlmsg_end(msg, hdr);
Johannes Berg04a773a2009-04-19 21:24:32 +020010652
Johannes Berg68eb5502013-11-19 15:19:38 +010010653 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010010654 NL80211_MCGRP_MLME, gfp);
Johannes Berg04a773a2009-04-19 21:24:32 +020010655 return;
10656
10657 nla_put_failure:
10658 genlmsg_cancel(msg, hdr);
10659 nlmsg_free(msg);
10660}
10661
Johannes Berg947add32013-02-22 22:05:20 +010010662void cfg80211_notify_new_peer_candidate(struct net_device *dev, const u8 *addr,
10663 const u8* ie, u8 ie_len, gfp_t gfp)
Javier Cardonac93b5e72011-04-07 15:08:34 -070010664{
Johannes Berg947add32013-02-22 22:05:20 +010010665 struct wireless_dev *wdev = dev->ieee80211_ptr;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080010666 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Javier Cardonac93b5e72011-04-07 15:08:34 -070010667 struct sk_buff *msg;
10668 void *hdr;
10669
Johannes Berg947add32013-02-22 22:05:20 +010010670 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_MESH_POINT))
10671 return;
10672
10673 trace_cfg80211_notify_new_peer_candidate(dev, addr);
10674
Javier Cardonac93b5e72011-04-07 15:08:34 -070010675 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
10676 if (!msg)
10677 return;
10678
10679 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NEW_PEER_CANDIDATE);
10680 if (!hdr) {
10681 nlmsg_free(msg);
10682 return;
10683 }
10684
David S. Miller9360ffd2012-03-29 04:41:26 -040010685 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg947add32013-02-22 22:05:20 +010010686 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
10687 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040010688 (ie_len && ie &&
10689 nla_put(msg, NL80211_ATTR_IE, ie_len , ie)))
10690 goto nla_put_failure;
Javier Cardonac93b5e72011-04-07 15:08:34 -070010691
Johannes Berg3b7b72e2011-10-22 19:05:51 +020010692 genlmsg_end(msg, hdr);
Javier Cardonac93b5e72011-04-07 15:08:34 -070010693
Johannes Berg68eb5502013-11-19 15:19:38 +010010694 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010010695 NL80211_MCGRP_MLME, gfp);
Javier Cardonac93b5e72011-04-07 15:08:34 -070010696 return;
10697
10698 nla_put_failure:
10699 genlmsg_cancel(msg, hdr);
10700 nlmsg_free(msg);
10701}
Johannes Berg947add32013-02-22 22:05:20 +010010702EXPORT_SYMBOL(cfg80211_notify_new_peer_candidate);
Javier Cardonac93b5e72011-04-07 15:08:34 -070010703
Jouni Malinena3b8b052009-03-27 21:59:49 +020010704void nl80211_michael_mic_failure(struct cfg80211_registered_device *rdev,
10705 struct net_device *netdev, const u8 *addr,
10706 enum nl80211_key_type key_type, int key_id,
Johannes Berge6d6e342009-07-01 21:26:47 +020010707 const u8 *tsc, gfp_t gfp)
Jouni Malinena3b8b052009-03-27 21:59:49 +020010708{
10709 struct sk_buff *msg;
10710 void *hdr;
10711
Johannes Berge6d6e342009-07-01 21:26:47 +020010712 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinena3b8b052009-03-27 21:59:49 +020010713 if (!msg)
10714 return;
10715
10716 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_MICHAEL_MIC_FAILURE);
10717 if (!hdr) {
10718 nlmsg_free(msg);
10719 return;
10720 }
10721
David S. Miller9360ffd2012-03-29 04:41:26 -040010722 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
10723 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
10724 (addr && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) ||
10725 nla_put_u32(msg, NL80211_ATTR_KEY_TYPE, key_type) ||
10726 (key_id != -1 &&
10727 nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_id)) ||
10728 (tsc && nla_put(msg, NL80211_ATTR_KEY_SEQ, 6, tsc)))
10729 goto nla_put_failure;
Jouni Malinena3b8b052009-03-27 21:59:49 +020010730
Johannes Berg3b7b72e2011-10-22 19:05:51 +020010731 genlmsg_end(msg, hdr);
Jouni Malinena3b8b052009-03-27 21:59:49 +020010732
Johannes Berg68eb5502013-11-19 15:19:38 +010010733 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010010734 NL80211_MCGRP_MLME, gfp);
Jouni Malinena3b8b052009-03-27 21:59:49 +020010735 return;
10736
10737 nla_put_failure:
10738 genlmsg_cancel(msg, hdr);
10739 nlmsg_free(msg);
10740}
10741
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040010742void nl80211_send_beacon_hint_event(struct wiphy *wiphy,
10743 struct ieee80211_channel *channel_before,
10744 struct ieee80211_channel *channel_after)
10745{
10746 struct sk_buff *msg;
10747 void *hdr;
10748 struct nlattr *nl_freq;
10749
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -070010750 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_ATOMIC);
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040010751 if (!msg)
10752 return;
10753
10754 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_BEACON_HINT);
10755 if (!hdr) {
10756 nlmsg_free(msg);
10757 return;
10758 }
10759
10760 /*
10761 * Since we are applying the beacon hint to a wiphy we know its
10762 * wiphy_idx is valid
10763 */
David S. Miller9360ffd2012-03-29 04:41:26 -040010764 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy)))
10765 goto nla_put_failure;
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040010766
10767 /* Before */
10768 nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_BEFORE);
10769 if (!nl_freq)
10770 goto nla_put_failure;
Johannes Bergcdc89b92013-02-18 23:54:36 +010010771 if (nl80211_msg_put_channel(msg, channel_before, false))
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040010772 goto nla_put_failure;
10773 nla_nest_end(msg, nl_freq);
10774
10775 /* After */
10776 nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_AFTER);
10777 if (!nl_freq)
10778 goto nla_put_failure;
Johannes Bergcdc89b92013-02-18 23:54:36 +010010779 if (nl80211_msg_put_channel(msg, channel_after, false))
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040010780 goto nla_put_failure;
10781 nla_nest_end(msg, nl_freq);
10782
Johannes Berg3b7b72e2011-10-22 19:05:51 +020010783 genlmsg_end(msg, hdr);
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040010784
Johannes Berg463d0182009-07-14 00:33:35 +020010785 rcu_read_lock();
Johannes Berg68eb5502013-11-19 15:19:38 +010010786 genlmsg_multicast_allns(&nl80211_fam, msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010010787 NL80211_MCGRP_REGULATORY, GFP_ATOMIC);
Johannes Berg463d0182009-07-14 00:33:35 +020010788 rcu_read_unlock();
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040010789
10790 return;
10791
10792nla_put_failure:
10793 genlmsg_cancel(msg, hdr);
10794 nlmsg_free(msg);
10795}
10796
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010797static void nl80211_send_remain_on_chan_event(
10798 int cmd, struct cfg80211_registered_device *rdev,
Johannes Berg71bbc992012-06-15 15:30:18 +020010799 struct wireless_dev *wdev, u64 cookie,
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010800 struct ieee80211_channel *chan,
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010801 unsigned int duration, gfp_t gfp)
10802{
10803 struct sk_buff *msg;
10804 void *hdr;
10805
10806 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
10807 if (!msg)
10808 return;
10809
10810 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
10811 if (!hdr) {
10812 nlmsg_free(msg);
10813 return;
10814 }
10815
David S. Miller9360ffd2012-03-29 04:41:26 -040010816 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg71bbc992012-06-15 15:30:18 +020010817 (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
10818 wdev->netdev->ifindex)) ||
Johannes Berg00f53352012-07-17 11:53:12 +020010819 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040010820 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, chan->center_freq) ||
Johannes Berg42d97a52012-11-08 18:31:02 +010010821 nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE,
10822 NL80211_CHAN_NO_HT) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040010823 nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie))
10824 goto nla_put_failure;
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010825
David S. Miller9360ffd2012-03-29 04:41:26 -040010826 if (cmd == NL80211_CMD_REMAIN_ON_CHANNEL &&
10827 nla_put_u32(msg, NL80211_ATTR_DURATION, duration))
10828 goto nla_put_failure;
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010829
Johannes Berg3b7b72e2011-10-22 19:05:51 +020010830 genlmsg_end(msg, hdr);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010831
Johannes Berg68eb5502013-11-19 15:19:38 +010010832 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010010833 NL80211_MCGRP_MLME, gfp);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010834 return;
10835
10836 nla_put_failure:
10837 genlmsg_cancel(msg, hdr);
10838 nlmsg_free(msg);
10839}
10840
Johannes Berg947add32013-02-22 22:05:20 +010010841void cfg80211_ready_on_channel(struct wireless_dev *wdev, u64 cookie,
10842 struct ieee80211_channel *chan,
10843 unsigned int duration, gfp_t gfp)
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010844{
Johannes Berg947add32013-02-22 22:05:20 +010010845 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080010846 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg947add32013-02-22 22:05:20 +010010847
10848 trace_cfg80211_ready_on_channel(wdev, cookie, chan, duration);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010849 nl80211_send_remain_on_chan_event(NL80211_CMD_REMAIN_ON_CHANNEL,
Johannes Berg71bbc992012-06-15 15:30:18 +020010850 rdev, wdev, cookie, chan,
Johannes Berg42d97a52012-11-08 18:31:02 +010010851 duration, gfp);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010852}
Johannes Berg947add32013-02-22 22:05:20 +010010853EXPORT_SYMBOL(cfg80211_ready_on_channel);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010854
Johannes Berg947add32013-02-22 22:05:20 +010010855void cfg80211_remain_on_channel_expired(struct wireless_dev *wdev, u64 cookie,
10856 struct ieee80211_channel *chan,
10857 gfp_t gfp)
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010858{
Johannes Berg947add32013-02-22 22:05:20 +010010859 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080010860 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg947add32013-02-22 22:05:20 +010010861
10862 trace_cfg80211_ready_on_channel_expired(wdev, cookie, chan);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010863 nl80211_send_remain_on_chan_event(NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL,
Johannes Berg42d97a52012-11-08 18:31:02 +010010864 rdev, wdev, cookie, chan, 0, gfp);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010865}
Johannes Berg947add32013-02-22 22:05:20 +010010866EXPORT_SYMBOL(cfg80211_remain_on_channel_expired);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010867
Johannes Berg947add32013-02-22 22:05:20 +010010868void cfg80211_new_sta(struct net_device *dev, const u8 *mac_addr,
10869 struct station_info *sinfo, gfp_t gfp)
Johannes Berg98b62182009-12-23 13:15:44 +010010870{
Johannes Berg947add32013-02-22 22:05:20 +010010871 struct wiphy *wiphy = dev->ieee80211_ptr->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080010872 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg98b62182009-12-23 13:15:44 +010010873 struct sk_buff *msg;
10874
Johannes Berg947add32013-02-22 22:05:20 +010010875 trace_cfg80211_new_sta(dev, mac_addr, sinfo);
10876
Thomas Graf58050fc2012-06-28 03:57:45 +000010877 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Johannes Berg98b62182009-12-23 13:15:44 +010010878 if (!msg)
10879 return;
10880
John W. Linville66266b32012-03-15 13:25:41 -040010881 if (nl80211_send_station(msg, 0, 0, 0,
10882 rdev, dev, mac_addr, sinfo) < 0) {
Johannes Berg98b62182009-12-23 13:15:44 +010010883 nlmsg_free(msg);
10884 return;
10885 }
10886
Johannes Berg68eb5502013-11-19 15:19:38 +010010887 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010010888 NL80211_MCGRP_MLME, gfp);
Johannes Berg98b62182009-12-23 13:15:44 +010010889}
Johannes Berg947add32013-02-22 22:05:20 +010010890EXPORT_SYMBOL(cfg80211_new_sta);
Johannes Berg98b62182009-12-23 13:15:44 +010010891
Johannes Berg947add32013-02-22 22:05:20 +010010892void cfg80211_del_sta(struct net_device *dev, const u8 *mac_addr, gfp_t gfp)
Jouni Malinenec15e682011-03-23 15:29:52 +020010893{
Johannes Berg947add32013-02-22 22:05:20 +010010894 struct wiphy *wiphy = dev->ieee80211_ptr->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080010895 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Jouni Malinenec15e682011-03-23 15:29:52 +020010896 struct sk_buff *msg;
10897 void *hdr;
10898
Johannes Berg947add32013-02-22 22:05:20 +010010899 trace_cfg80211_del_sta(dev, mac_addr);
10900
Thomas Graf58050fc2012-06-28 03:57:45 +000010901 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinenec15e682011-03-23 15:29:52 +020010902 if (!msg)
10903 return;
10904
10905 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DEL_STATION);
10906 if (!hdr) {
10907 nlmsg_free(msg);
10908 return;
10909 }
10910
David S. Miller9360ffd2012-03-29 04:41:26 -040010911 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
10912 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr))
10913 goto nla_put_failure;
Jouni Malinenec15e682011-03-23 15:29:52 +020010914
Johannes Berg3b7b72e2011-10-22 19:05:51 +020010915 genlmsg_end(msg, hdr);
Jouni Malinenec15e682011-03-23 15:29:52 +020010916
Johannes Berg68eb5502013-11-19 15:19:38 +010010917 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010010918 NL80211_MCGRP_MLME, gfp);
Jouni Malinenec15e682011-03-23 15:29:52 +020010919 return;
10920
10921 nla_put_failure:
10922 genlmsg_cancel(msg, hdr);
10923 nlmsg_free(msg);
10924}
Johannes Berg947add32013-02-22 22:05:20 +010010925EXPORT_SYMBOL(cfg80211_del_sta);
Jouni Malinenec15e682011-03-23 15:29:52 +020010926
Johannes Berg947add32013-02-22 22:05:20 +010010927void cfg80211_conn_failed(struct net_device *dev, const u8 *mac_addr,
10928 enum nl80211_connect_failed_reason reason,
10929 gfp_t gfp)
Pandiyarajan Pitchaimuthued44a952012-09-18 16:50:49 +053010930{
Johannes Berg947add32013-02-22 22:05:20 +010010931 struct wiphy *wiphy = dev->ieee80211_ptr->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080010932 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Pandiyarajan Pitchaimuthued44a952012-09-18 16:50:49 +053010933 struct sk_buff *msg;
10934 void *hdr;
10935
10936 msg = nlmsg_new(NLMSG_GOODSIZE, gfp);
10937 if (!msg)
10938 return;
10939
10940 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONN_FAILED);
10941 if (!hdr) {
10942 nlmsg_free(msg);
10943 return;
10944 }
10945
10946 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
10947 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) ||
10948 nla_put_u32(msg, NL80211_ATTR_CONN_FAILED_REASON, reason))
10949 goto nla_put_failure;
10950
10951 genlmsg_end(msg, hdr);
10952
Johannes Berg68eb5502013-11-19 15:19:38 +010010953 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010010954 NL80211_MCGRP_MLME, gfp);
Pandiyarajan Pitchaimuthued44a952012-09-18 16:50:49 +053010955 return;
10956
10957 nla_put_failure:
10958 genlmsg_cancel(msg, hdr);
10959 nlmsg_free(msg);
10960}
Johannes Berg947add32013-02-22 22:05:20 +010010961EXPORT_SYMBOL(cfg80211_conn_failed);
Pandiyarajan Pitchaimuthued44a952012-09-18 16:50:49 +053010962
Johannes Bergb92ab5d2011-11-04 11:18:19 +010010963static bool __nl80211_unexpected_frame(struct net_device *dev, u8 cmd,
10964 const u8 *addr, gfp_t gfp)
Johannes Berg28946da2011-11-04 11:18:12 +010010965{
10966 struct wireless_dev *wdev = dev->ieee80211_ptr;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080010967 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Johannes Berg28946da2011-11-04 11:18:12 +010010968 struct sk_buff *msg;
10969 void *hdr;
Eric W. Biederman15e47302012-09-07 20:12:54 +000010970 u32 nlportid = ACCESS_ONCE(wdev->ap_unexpected_nlportid);
Johannes Berg28946da2011-11-04 11:18:12 +010010971
Eric W. Biederman15e47302012-09-07 20:12:54 +000010972 if (!nlportid)
Johannes Berg28946da2011-11-04 11:18:12 +010010973 return false;
10974
10975 msg = nlmsg_new(100, gfp);
10976 if (!msg)
10977 return true;
10978
Johannes Bergb92ab5d2011-11-04 11:18:19 +010010979 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
Johannes Berg28946da2011-11-04 11:18:12 +010010980 if (!hdr) {
10981 nlmsg_free(msg);
10982 return true;
10983 }
10984
David S. Miller9360ffd2012-03-29 04:41:26 -040010985 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
10986 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
10987 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr))
10988 goto nla_put_failure;
Johannes Berg28946da2011-11-04 11:18:12 +010010989
Johannes Berg9c90a9f2013-06-04 12:46:03 +020010990 genlmsg_end(msg, hdr);
Eric W. Biederman15e47302012-09-07 20:12:54 +000010991 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid);
Johannes Berg28946da2011-11-04 11:18:12 +010010992 return true;
10993
10994 nla_put_failure:
10995 genlmsg_cancel(msg, hdr);
10996 nlmsg_free(msg);
10997 return true;
10998}
10999
Johannes Berg947add32013-02-22 22:05:20 +010011000bool cfg80211_rx_spurious_frame(struct net_device *dev,
11001 const u8 *addr, gfp_t gfp)
Johannes Bergb92ab5d2011-11-04 11:18:19 +010011002{
Johannes Berg947add32013-02-22 22:05:20 +010011003 struct wireless_dev *wdev = dev->ieee80211_ptr;
11004 bool ret;
Johannes Bergb92ab5d2011-11-04 11:18:19 +010011005
Johannes Berg947add32013-02-22 22:05:20 +010011006 trace_cfg80211_rx_spurious_frame(dev, addr);
11007
11008 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP &&
11009 wdev->iftype != NL80211_IFTYPE_P2P_GO)) {
11010 trace_cfg80211_return_bool(false);
11011 return false;
11012 }
11013 ret = __nl80211_unexpected_frame(dev, NL80211_CMD_UNEXPECTED_FRAME,
11014 addr, gfp);
11015 trace_cfg80211_return_bool(ret);
11016 return ret;
Johannes Bergb92ab5d2011-11-04 11:18:19 +010011017}
Johannes Berg947add32013-02-22 22:05:20 +010011018EXPORT_SYMBOL(cfg80211_rx_spurious_frame);
11019
11020bool cfg80211_rx_unexpected_4addr_frame(struct net_device *dev,
11021 const u8 *addr, gfp_t gfp)
11022{
11023 struct wireless_dev *wdev = dev->ieee80211_ptr;
11024 bool ret;
11025
11026 trace_cfg80211_rx_unexpected_4addr_frame(dev, addr);
11027
11028 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP &&
11029 wdev->iftype != NL80211_IFTYPE_P2P_GO &&
11030 wdev->iftype != NL80211_IFTYPE_AP_VLAN)) {
11031 trace_cfg80211_return_bool(false);
11032 return false;
11033 }
11034 ret = __nl80211_unexpected_frame(dev,
11035 NL80211_CMD_UNEXPECTED_4ADDR_FRAME,
11036 addr, gfp);
11037 trace_cfg80211_return_bool(ret);
11038 return ret;
11039}
11040EXPORT_SYMBOL(cfg80211_rx_unexpected_4addr_frame);
Johannes Bergb92ab5d2011-11-04 11:18:19 +010011041
Johannes Berg2e161f72010-08-12 15:38:38 +020011042int nl80211_send_mgmt(struct cfg80211_registered_device *rdev,
Eric W. Biederman15e47302012-09-07 20:12:54 +000011043 struct wireless_dev *wdev, u32 nlportid,
Johannes Berg804483e2012-03-05 22:18:41 +010011044 int freq, int sig_dbm,
Vladimir Kondratiev19504cf2013-08-15 14:51:28 +030011045 const u8 *buf, size_t len, u32 flags, gfp_t gfp)
Jouni Malinen026331c2010-02-15 12:53:10 +020011046{
Johannes Berg71bbc992012-06-15 15:30:18 +020011047 struct net_device *netdev = wdev->netdev;
Jouni Malinen026331c2010-02-15 12:53:10 +020011048 struct sk_buff *msg;
11049 void *hdr;
Jouni Malinen026331c2010-02-15 12:53:10 +020011050
11051 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
11052 if (!msg)
11053 return -ENOMEM;
11054
Johannes Berg2e161f72010-08-12 15:38:38 +020011055 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME);
Jouni Malinen026331c2010-02-15 12:53:10 +020011056 if (!hdr) {
11057 nlmsg_free(msg);
11058 return -ENOMEM;
11059 }
11060
David S. Miller9360ffd2012-03-29 04:41:26 -040011061 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg71bbc992012-06-15 15:30:18 +020011062 (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
11063 netdev->ifindex)) ||
Ilan Peera8384902013-05-08 16:35:55 +030011064 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040011065 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq) ||
11066 (sig_dbm &&
11067 nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) ||
Vladimir Kondratiev19504cf2013-08-15 14:51:28 +030011068 nla_put(msg, NL80211_ATTR_FRAME, len, buf) ||
11069 (flags &&
11070 nla_put_u32(msg, NL80211_ATTR_RXMGMT_FLAGS, flags)))
David S. Miller9360ffd2012-03-29 04:41:26 -040011071 goto nla_put_failure;
Jouni Malinen026331c2010-02-15 12:53:10 +020011072
Johannes Berg3b7b72e2011-10-22 19:05:51 +020011073 genlmsg_end(msg, hdr);
Jouni Malinen026331c2010-02-15 12:53:10 +020011074
Eric W. Biederman15e47302012-09-07 20:12:54 +000011075 return genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid);
Jouni Malinen026331c2010-02-15 12:53:10 +020011076
11077 nla_put_failure:
11078 genlmsg_cancel(msg, hdr);
11079 nlmsg_free(msg);
11080 return -ENOBUFS;
11081}
11082
Johannes Berg947add32013-02-22 22:05:20 +010011083void cfg80211_mgmt_tx_status(struct wireless_dev *wdev, u64 cookie,
11084 const u8 *buf, size_t len, bool ack, gfp_t gfp)
Jouni Malinen026331c2010-02-15 12:53:10 +020011085{
Johannes Berg947add32013-02-22 22:05:20 +010011086 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080011087 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg71bbc992012-06-15 15:30:18 +020011088 struct net_device *netdev = wdev->netdev;
Jouni Malinen026331c2010-02-15 12:53:10 +020011089 struct sk_buff *msg;
11090 void *hdr;
11091
Johannes Berg947add32013-02-22 22:05:20 +010011092 trace_cfg80211_mgmt_tx_status(wdev, cookie, ack);
11093
Jouni Malinen026331c2010-02-15 12:53:10 +020011094 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
11095 if (!msg)
11096 return;
11097
Johannes Berg2e161f72010-08-12 15:38:38 +020011098 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME_TX_STATUS);
Jouni Malinen026331c2010-02-15 12:53:10 +020011099 if (!hdr) {
11100 nlmsg_free(msg);
11101 return;
11102 }
11103
David S. Miller9360ffd2012-03-29 04:41:26 -040011104 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg71bbc992012-06-15 15:30:18 +020011105 (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
11106 netdev->ifindex)) ||
Ilan Peera8384902013-05-08 16:35:55 +030011107 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040011108 nla_put(msg, NL80211_ATTR_FRAME, len, buf) ||
11109 nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie) ||
11110 (ack && nla_put_flag(msg, NL80211_ATTR_ACK)))
11111 goto nla_put_failure;
Jouni Malinen026331c2010-02-15 12:53:10 +020011112
Johannes Berg3b7b72e2011-10-22 19:05:51 +020011113 genlmsg_end(msg, hdr);
Jouni Malinen026331c2010-02-15 12:53:10 +020011114
Johannes Berg68eb5502013-11-19 15:19:38 +010011115 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011116 NL80211_MCGRP_MLME, gfp);
Jouni Malinen026331c2010-02-15 12:53:10 +020011117 return;
11118
11119 nla_put_failure:
11120 genlmsg_cancel(msg, hdr);
11121 nlmsg_free(msg);
11122}
Johannes Berg947add32013-02-22 22:05:20 +010011123EXPORT_SYMBOL(cfg80211_mgmt_tx_status);
Jouni Malinen026331c2010-02-15 12:53:10 +020011124
Johannes Berg947add32013-02-22 22:05:20 +010011125void cfg80211_cqm_rssi_notify(struct net_device *dev,
11126 enum nl80211_cqm_rssi_threshold_event rssi_event,
11127 gfp_t gfp)
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020011128{
Johannes Berg947add32013-02-22 22:05:20 +010011129 struct wireless_dev *wdev = dev->ieee80211_ptr;
11130 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080011131 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020011132 struct sk_buff *msg;
11133 struct nlattr *pinfoattr;
11134 void *hdr;
11135
Johannes Berg947add32013-02-22 22:05:20 +010011136 trace_cfg80211_cqm_rssi_notify(dev, rssi_event);
11137
Thomas Graf58050fc2012-06-28 03:57:45 +000011138 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020011139 if (!msg)
11140 return;
11141
11142 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM);
11143 if (!hdr) {
11144 nlmsg_free(msg);
11145 return;
11146 }
11147
David S. Miller9360ffd2012-03-29 04:41:26 -040011148 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg947add32013-02-22 22:05:20 +010011149 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex))
David S. Miller9360ffd2012-03-29 04:41:26 -040011150 goto nla_put_failure;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020011151
11152 pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM);
11153 if (!pinfoattr)
11154 goto nla_put_failure;
11155
David S. Miller9360ffd2012-03-29 04:41:26 -040011156 if (nla_put_u32(msg, NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT,
11157 rssi_event))
11158 goto nla_put_failure;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020011159
11160 nla_nest_end(msg, pinfoattr);
11161
Johannes Berg3b7b72e2011-10-22 19:05:51 +020011162 genlmsg_end(msg, hdr);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020011163
Johannes Berg68eb5502013-11-19 15:19:38 +010011164 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011165 NL80211_MCGRP_MLME, gfp);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020011166 return;
11167
11168 nla_put_failure:
11169 genlmsg_cancel(msg, hdr);
11170 nlmsg_free(msg);
11171}
Johannes Berg947add32013-02-22 22:05:20 +010011172EXPORT_SYMBOL(cfg80211_cqm_rssi_notify);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020011173
Johannes Berg947add32013-02-22 22:05:20 +010011174static void nl80211_gtk_rekey_notify(struct cfg80211_registered_device *rdev,
11175 struct net_device *netdev, const u8 *bssid,
11176 const u8 *replay_ctr, gfp_t gfp)
Johannes Berge5497d72011-07-05 16:35:40 +020011177{
11178 struct sk_buff *msg;
11179 struct nlattr *rekey_attr;
11180 void *hdr;
11181
Thomas Graf58050fc2012-06-28 03:57:45 +000011182 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Johannes Berge5497d72011-07-05 16:35:40 +020011183 if (!msg)
11184 return;
11185
11186 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_REKEY_OFFLOAD);
11187 if (!hdr) {
11188 nlmsg_free(msg);
11189 return;
11190 }
11191
David S. Miller9360ffd2012-03-29 04:41:26 -040011192 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
11193 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
11194 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid))
11195 goto nla_put_failure;
Johannes Berge5497d72011-07-05 16:35:40 +020011196
11197 rekey_attr = nla_nest_start(msg, NL80211_ATTR_REKEY_DATA);
11198 if (!rekey_attr)
11199 goto nla_put_failure;
11200
David S. Miller9360ffd2012-03-29 04:41:26 -040011201 if (nla_put(msg, NL80211_REKEY_DATA_REPLAY_CTR,
11202 NL80211_REPLAY_CTR_LEN, replay_ctr))
11203 goto nla_put_failure;
Johannes Berge5497d72011-07-05 16:35:40 +020011204
11205 nla_nest_end(msg, rekey_attr);
11206
Johannes Berg3b7b72e2011-10-22 19:05:51 +020011207 genlmsg_end(msg, hdr);
Johannes Berge5497d72011-07-05 16:35:40 +020011208
Johannes Berg68eb5502013-11-19 15:19:38 +010011209 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011210 NL80211_MCGRP_MLME, gfp);
Johannes Berge5497d72011-07-05 16:35:40 +020011211 return;
11212
11213 nla_put_failure:
11214 genlmsg_cancel(msg, hdr);
11215 nlmsg_free(msg);
11216}
11217
Johannes Berg947add32013-02-22 22:05:20 +010011218void cfg80211_gtk_rekey_notify(struct net_device *dev, const u8 *bssid,
11219 const u8 *replay_ctr, gfp_t gfp)
11220{
11221 struct wireless_dev *wdev = dev->ieee80211_ptr;
11222 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080011223 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg947add32013-02-22 22:05:20 +010011224
11225 trace_cfg80211_gtk_rekey_notify(dev, bssid);
11226 nl80211_gtk_rekey_notify(rdev, dev, bssid, replay_ctr, gfp);
11227}
11228EXPORT_SYMBOL(cfg80211_gtk_rekey_notify);
11229
11230static void
11231nl80211_pmksa_candidate_notify(struct cfg80211_registered_device *rdev,
11232 struct net_device *netdev, int index,
11233 const u8 *bssid, bool preauth, gfp_t gfp)
Jouni Malinenc9df56b2011-09-16 18:56:23 +030011234{
11235 struct sk_buff *msg;
11236 struct nlattr *attr;
11237 void *hdr;
11238
Thomas Graf58050fc2012-06-28 03:57:45 +000011239 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinenc9df56b2011-09-16 18:56:23 +030011240 if (!msg)
11241 return;
11242
11243 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PMKSA_CANDIDATE);
11244 if (!hdr) {
11245 nlmsg_free(msg);
11246 return;
11247 }
11248
David S. Miller9360ffd2012-03-29 04:41:26 -040011249 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
11250 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex))
11251 goto nla_put_failure;
Jouni Malinenc9df56b2011-09-16 18:56:23 +030011252
11253 attr = nla_nest_start(msg, NL80211_ATTR_PMKSA_CANDIDATE);
11254 if (!attr)
11255 goto nla_put_failure;
11256
David S. Miller9360ffd2012-03-29 04:41:26 -040011257 if (nla_put_u32(msg, NL80211_PMKSA_CANDIDATE_INDEX, index) ||
11258 nla_put(msg, NL80211_PMKSA_CANDIDATE_BSSID, ETH_ALEN, bssid) ||
11259 (preauth &&
11260 nla_put_flag(msg, NL80211_PMKSA_CANDIDATE_PREAUTH)))
11261 goto nla_put_failure;
Jouni Malinenc9df56b2011-09-16 18:56:23 +030011262
11263 nla_nest_end(msg, attr);
11264
Johannes Berg3b7b72e2011-10-22 19:05:51 +020011265 genlmsg_end(msg, hdr);
Jouni Malinenc9df56b2011-09-16 18:56:23 +030011266
Johannes Berg68eb5502013-11-19 15:19:38 +010011267 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011268 NL80211_MCGRP_MLME, gfp);
Jouni Malinenc9df56b2011-09-16 18:56:23 +030011269 return;
11270
11271 nla_put_failure:
11272 genlmsg_cancel(msg, hdr);
11273 nlmsg_free(msg);
11274}
11275
Johannes Berg947add32013-02-22 22:05:20 +010011276void cfg80211_pmksa_candidate_notify(struct net_device *dev, int index,
11277 const u8 *bssid, bool preauth, gfp_t gfp)
11278{
11279 struct wireless_dev *wdev = dev->ieee80211_ptr;
11280 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080011281 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg947add32013-02-22 22:05:20 +010011282
11283 trace_cfg80211_pmksa_candidate_notify(dev, index, bssid, preauth);
11284 nl80211_pmksa_candidate_notify(rdev, dev, index, bssid, preauth, gfp);
11285}
11286EXPORT_SYMBOL(cfg80211_pmksa_candidate_notify);
11287
11288static void nl80211_ch_switch_notify(struct cfg80211_registered_device *rdev,
11289 struct net_device *netdev,
11290 struct cfg80211_chan_def *chandef,
11291 gfp_t gfp)
Thomas Pedersen53145262012-04-06 13:35:47 -070011292{
11293 struct sk_buff *msg;
11294 void *hdr;
11295
Thomas Graf58050fc2012-06-28 03:57:45 +000011296 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Thomas Pedersen53145262012-04-06 13:35:47 -070011297 if (!msg)
11298 return;
11299
11300 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CH_SWITCH_NOTIFY);
11301 if (!hdr) {
11302 nlmsg_free(msg);
11303 return;
11304 }
11305
Johannes Berg683b6d32012-11-08 21:25:48 +010011306 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex))
11307 goto nla_put_failure;
11308
11309 if (nl80211_send_chandef(msg, chandef))
John W. Linville7eab0f62012-04-12 14:25:14 -040011310 goto nla_put_failure;
Thomas Pedersen53145262012-04-06 13:35:47 -070011311
11312 genlmsg_end(msg, hdr);
11313
Johannes Berg68eb5502013-11-19 15:19:38 +010011314 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011315 NL80211_MCGRP_MLME, gfp);
Thomas Pedersen53145262012-04-06 13:35:47 -070011316 return;
11317
11318 nla_put_failure:
11319 genlmsg_cancel(msg, hdr);
11320 nlmsg_free(msg);
11321}
11322
Johannes Berg947add32013-02-22 22:05:20 +010011323void cfg80211_ch_switch_notify(struct net_device *dev,
11324 struct cfg80211_chan_def *chandef)
Thomas Pedersen84f10702012-07-12 16:17:33 -070011325{
Johannes Berg947add32013-02-22 22:05:20 +010011326 struct wireless_dev *wdev = dev->ieee80211_ptr;
11327 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080011328 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg947add32013-02-22 22:05:20 +010011329
Simon Wunderliche487eae2013-11-21 18:19:51 +010011330 ASSERT_WDEV_LOCK(wdev);
Johannes Berg947add32013-02-22 22:05:20 +010011331
Simon Wunderliche487eae2013-11-21 18:19:51 +010011332 trace_cfg80211_ch_switch_notify(dev, chandef);
Johannes Berg947add32013-02-22 22:05:20 +010011333
11334 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP &&
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +020011335 wdev->iftype != NL80211_IFTYPE_P2P_GO &&
Chun-Yeow Yeohb8456a12013-10-17 15:55:02 -070011336 wdev->iftype != NL80211_IFTYPE_ADHOC &&
11337 wdev->iftype != NL80211_IFTYPE_MESH_POINT))
Simon Wunderliche487eae2013-11-21 18:19:51 +010011338 return;
Johannes Berg947add32013-02-22 22:05:20 +010011339
Michal Kazior9e0e2962014-01-29 14:22:27 +010011340 wdev->chandef = *chandef;
Janusz Dziedzic96f55f12014-01-24 14:29:21 +010011341 wdev->preset_chandef = *chandef;
Johannes Berg947add32013-02-22 22:05:20 +010011342 nl80211_ch_switch_notify(rdev, dev, chandef, GFP_KERNEL);
Johannes Berg947add32013-02-22 22:05:20 +010011343}
11344EXPORT_SYMBOL(cfg80211_ch_switch_notify);
11345
11346void cfg80211_cqm_txe_notify(struct net_device *dev,
11347 const u8 *peer, u32 num_packets,
11348 u32 rate, u32 intvl, gfp_t gfp)
11349{
11350 struct wireless_dev *wdev = dev->ieee80211_ptr;
11351 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080011352 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Thomas Pedersen84f10702012-07-12 16:17:33 -070011353 struct sk_buff *msg;
11354 struct nlattr *pinfoattr;
11355 void *hdr;
11356
11357 msg = nlmsg_new(NLMSG_GOODSIZE, gfp);
11358 if (!msg)
11359 return;
11360
11361 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM);
11362 if (!hdr) {
11363 nlmsg_free(msg);
11364 return;
11365 }
11366
11367 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg947add32013-02-22 22:05:20 +010011368 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
Thomas Pedersen84f10702012-07-12 16:17:33 -070011369 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer))
11370 goto nla_put_failure;
11371
11372 pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM);
11373 if (!pinfoattr)
11374 goto nla_put_failure;
11375
11376 if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_PKTS, num_packets))
11377 goto nla_put_failure;
11378
11379 if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_RATE, rate))
11380 goto nla_put_failure;
11381
11382 if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_INTVL, intvl))
11383 goto nla_put_failure;
11384
11385 nla_nest_end(msg, pinfoattr);
11386
11387 genlmsg_end(msg, hdr);
11388
Johannes Berg68eb5502013-11-19 15:19:38 +010011389 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011390 NL80211_MCGRP_MLME, gfp);
Thomas Pedersen84f10702012-07-12 16:17:33 -070011391 return;
11392
11393 nla_put_failure:
11394 genlmsg_cancel(msg, hdr);
11395 nlmsg_free(msg);
11396}
Johannes Berg947add32013-02-22 22:05:20 +010011397EXPORT_SYMBOL(cfg80211_cqm_txe_notify);
Thomas Pedersen84f10702012-07-12 16:17:33 -070011398
11399void
Simon Wunderlich04f39042013-02-08 18:16:19 +010011400nl80211_radar_notify(struct cfg80211_registered_device *rdev,
Janusz Dziedzicd2859df2013-11-06 13:55:51 +010011401 const struct cfg80211_chan_def *chandef,
Simon Wunderlich04f39042013-02-08 18:16:19 +010011402 enum nl80211_radar_event event,
11403 struct net_device *netdev, gfp_t gfp)
11404{
11405 struct sk_buff *msg;
11406 void *hdr;
11407
11408 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
11409 if (!msg)
11410 return;
11411
11412 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_RADAR_DETECT);
11413 if (!hdr) {
11414 nlmsg_free(msg);
11415 return;
11416 }
11417
11418 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx))
11419 goto nla_put_failure;
11420
11421 /* NOP and radar events don't need a netdev parameter */
11422 if (netdev) {
11423 struct wireless_dev *wdev = netdev->ieee80211_ptr;
11424
11425 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
11426 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)))
11427 goto nla_put_failure;
11428 }
11429
11430 if (nla_put_u32(msg, NL80211_ATTR_RADAR_EVENT, event))
11431 goto nla_put_failure;
11432
11433 if (nl80211_send_chandef(msg, chandef))
11434 goto nla_put_failure;
11435
Johannes Berg9c90a9f2013-06-04 12:46:03 +020011436 genlmsg_end(msg, hdr);
Simon Wunderlich04f39042013-02-08 18:16:19 +010011437
Johannes Berg68eb5502013-11-19 15:19:38 +010011438 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011439 NL80211_MCGRP_MLME, gfp);
Simon Wunderlich04f39042013-02-08 18:16:19 +010011440 return;
11441
11442 nla_put_failure:
11443 genlmsg_cancel(msg, hdr);
11444 nlmsg_free(msg);
11445}
11446
Johannes Berg947add32013-02-22 22:05:20 +010011447void cfg80211_cqm_pktloss_notify(struct net_device *dev,
11448 const u8 *peer, u32 num_packets, gfp_t gfp)
Johannes Bergc063dbf2010-11-24 08:10:05 +010011449{
Johannes Berg947add32013-02-22 22:05:20 +010011450 struct wireless_dev *wdev = dev->ieee80211_ptr;
11451 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080011452 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Bergc063dbf2010-11-24 08:10:05 +010011453 struct sk_buff *msg;
11454 struct nlattr *pinfoattr;
11455 void *hdr;
11456
Johannes Berg947add32013-02-22 22:05:20 +010011457 trace_cfg80211_cqm_pktloss_notify(dev, peer, num_packets);
11458
Thomas Graf58050fc2012-06-28 03:57:45 +000011459 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Johannes Bergc063dbf2010-11-24 08:10:05 +010011460 if (!msg)
11461 return;
11462
11463 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM);
11464 if (!hdr) {
11465 nlmsg_free(msg);
11466 return;
11467 }
11468
David S. Miller9360ffd2012-03-29 04:41:26 -040011469 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg947add32013-02-22 22:05:20 +010011470 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040011471 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer))
11472 goto nla_put_failure;
Johannes Bergc063dbf2010-11-24 08:10:05 +010011473
11474 pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM);
11475 if (!pinfoattr)
11476 goto nla_put_failure;
11477
David S. Miller9360ffd2012-03-29 04:41:26 -040011478 if (nla_put_u32(msg, NL80211_ATTR_CQM_PKT_LOSS_EVENT, num_packets))
11479 goto nla_put_failure;
Johannes Bergc063dbf2010-11-24 08:10:05 +010011480
11481 nla_nest_end(msg, pinfoattr);
11482
Johannes Berg3b7b72e2011-10-22 19:05:51 +020011483 genlmsg_end(msg, hdr);
Johannes Bergc063dbf2010-11-24 08:10:05 +010011484
Johannes Berg68eb5502013-11-19 15:19:38 +010011485 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011486 NL80211_MCGRP_MLME, gfp);
Johannes Bergc063dbf2010-11-24 08:10:05 +010011487 return;
11488
11489 nla_put_failure:
11490 genlmsg_cancel(msg, hdr);
11491 nlmsg_free(msg);
11492}
Johannes Berg947add32013-02-22 22:05:20 +010011493EXPORT_SYMBOL(cfg80211_cqm_pktloss_notify);
Johannes Bergc063dbf2010-11-24 08:10:05 +010011494
Johannes Berg7f6cf312011-11-04 11:18:15 +010011495void cfg80211_probe_status(struct net_device *dev, const u8 *addr,
11496 u64 cookie, bool acked, gfp_t gfp)
11497{
11498 struct wireless_dev *wdev = dev->ieee80211_ptr;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080011499 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Johannes Berg7f6cf312011-11-04 11:18:15 +010011500 struct sk_buff *msg;
11501 void *hdr;
Johannes Berg7f6cf312011-11-04 11:18:15 +010011502
Beni Lev4ee3e062012-08-27 12:49:39 +030011503 trace_cfg80211_probe_status(dev, addr, cookie, acked);
11504
Thomas Graf58050fc2012-06-28 03:57:45 +000011505 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Beni Lev4ee3e062012-08-27 12:49:39 +030011506
Johannes Berg7f6cf312011-11-04 11:18:15 +010011507 if (!msg)
11508 return;
11509
11510 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PROBE_CLIENT);
11511 if (!hdr) {
11512 nlmsg_free(msg);
11513 return;
11514 }
11515
David S. Miller9360ffd2012-03-29 04:41:26 -040011516 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
11517 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
11518 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) ||
11519 nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie) ||
11520 (acked && nla_put_flag(msg, NL80211_ATTR_ACK)))
11521 goto nla_put_failure;
Johannes Berg7f6cf312011-11-04 11:18:15 +010011522
Johannes Berg9c90a9f2013-06-04 12:46:03 +020011523 genlmsg_end(msg, hdr);
Johannes Berg7f6cf312011-11-04 11:18:15 +010011524
Johannes Berg68eb5502013-11-19 15:19:38 +010011525 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011526 NL80211_MCGRP_MLME, gfp);
Johannes Berg7f6cf312011-11-04 11:18:15 +010011527 return;
11528
11529 nla_put_failure:
11530 genlmsg_cancel(msg, hdr);
11531 nlmsg_free(msg);
11532}
11533EXPORT_SYMBOL(cfg80211_probe_status);
11534
Johannes Berg5e760232011-11-04 11:18:17 +010011535void cfg80211_report_obss_beacon(struct wiphy *wiphy,
11536 const u8 *frame, size_t len,
Ben Greear37c73b52012-10-26 14:49:25 -070011537 int freq, int sig_dbm)
Johannes Berg5e760232011-11-04 11:18:17 +010011538{
Zhao, Gangf26cbf42014-04-21 12:53:03 +080011539 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg5e760232011-11-04 11:18:17 +010011540 struct sk_buff *msg;
11541 void *hdr;
Ben Greear37c73b52012-10-26 14:49:25 -070011542 struct cfg80211_beacon_registration *reg;
Johannes Berg5e760232011-11-04 11:18:17 +010011543
Beni Lev4ee3e062012-08-27 12:49:39 +030011544 trace_cfg80211_report_obss_beacon(wiphy, frame, len, freq, sig_dbm);
11545
Ben Greear37c73b52012-10-26 14:49:25 -070011546 spin_lock_bh(&rdev->beacon_registrations_lock);
11547 list_for_each_entry(reg, &rdev->beacon_registrations, list) {
11548 msg = nlmsg_new(len + 100, GFP_ATOMIC);
11549 if (!msg) {
11550 spin_unlock_bh(&rdev->beacon_registrations_lock);
11551 return;
11552 }
Johannes Berg5e760232011-11-04 11:18:17 +010011553
Ben Greear37c73b52012-10-26 14:49:25 -070011554 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME);
11555 if (!hdr)
11556 goto nla_put_failure;
Johannes Berg5e760232011-11-04 11:18:17 +010011557
Ben Greear37c73b52012-10-26 14:49:25 -070011558 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
11559 (freq &&
11560 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq)) ||
11561 (sig_dbm &&
11562 nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) ||
11563 nla_put(msg, NL80211_ATTR_FRAME, len, frame))
11564 goto nla_put_failure;
11565
11566 genlmsg_end(msg, hdr);
11567
11568 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, reg->nlportid);
Johannes Berg5e760232011-11-04 11:18:17 +010011569 }
Ben Greear37c73b52012-10-26 14:49:25 -070011570 spin_unlock_bh(&rdev->beacon_registrations_lock);
Johannes Berg5e760232011-11-04 11:18:17 +010011571 return;
11572
11573 nla_put_failure:
Ben Greear37c73b52012-10-26 14:49:25 -070011574 spin_unlock_bh(&rdev->beacon_registrations_lock);
11575 if (hdr)
11576 genlmsg_cancel(msg, hdr);
Johannes Berg5e760232011-11-04 11:18:17 +010011577 nlmsg_free(msg);
11578}
11579EXPORT_SYMBOL(cfg80211_report_obss_beacon);
11580
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010011581#ifdef CONFIG_PM
11582void cfg80211_report_wowlan_wakeup(struct wireless_dev *wdev,
11583 struct cfg80211_wowlan_wakeup *wakeup,
11584 gfp_t gfp)
11585{
Zhao, Gangf26cbf42014-04-21 12:53:03 +080011586 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010011587 struct sk_buff *msg;
11588 void *hdr;
Johannes Berg9c90a9f2013-06-04 12:46:03 +020011589 int size = 200;
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010011590
11591 trace_cfg80211_report_wowlan_wakeup(wdev->wiphy, wdev, wakeup);
11592
11593 if (wakeup)
11594 size += wakeup->packet_present_len;
11595
11596 msg = nlmsg_new(size, gfp);
11597 if (!msg)
11598 return;
11599
11600 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_WOWLAN);
11601 if (!hdr)
11602 goto free_msg;
11603
11604 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
11605 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)))
11606 goto free_msg;
11607
11608 if (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
11609 wdev->netdev->ifindex))
11610 goto free_msg;
11611
11612 if (wakeup) {
11613 struct nlattr *reasons;
11614
11615 reasons = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS);
Johannes Berg7fa322c2013-10-25 11:16:58 +020011616 if (!reasons)
11617 goto free_msg;
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010011618
11619 if (wakeup->disconnect &&
11620 nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT))
11621 goto free_msg;
11622 if (wakeup->magic_pkt &&
11623 nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT))
11624 goto free_msg;
11625 if (wakeup->gtk_rekey_failure &&
11626 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE))
11627 goto free_msg;
11628 if (wakeup->eap_identity_req &&
11629 nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST))
11630 goto free_msg;
11631 if (wakeup->four_way_handshake &&
11632 nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE))
11633 goto free_msg;
11634 if (wakeup->rfkill_release &&
11635 nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE))
11636 goto free_msg;
11637
11638 if (wakeup->pattern_idx >= 0 &&
11639 nla_put_u32(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN,
11640 wakeup->pattern_idx))
11641 goto free_msg;
11642
Johannes Bergae917c92013-10-25 11:05:22 +020011643 if (wakeup->tcp_match &&
11644 nla_put_flag(msg, NL80211_WOWLAN_TRIG_WAKEUP_TCP_MATCH))
11645 goto free_msg;
Johannes Berg2a0e0472013-01-23 22:57:40 +010011646
Johannes Bergae917c92013-10-25 11:05:22 +020011647 if (wakeup->tcp_connlost &&
11648 nla_put_flag(msg, NL80211_WOWLAN_TRIG_WAKEUP_TCP_CONNLOST))
11649 goto free_msg;
Johannes Berg2a0e0472013-01-23 22:57:40 +010011650
Johannes Bergae917c92013-10-25 11:05:22 +020011651 if (wakeup->tcp_nomoretokens &&
11652 nla_put_flag(msg,
11653 NL80211_WOWLAN_TRIG_WAKEUP_TCP_NOMORETOKENS))
11654 goto free_msg;
Johannes Berg2a0e0472013-01-23 22:57:40 +010011655
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010011656 if (wakeup->packet) {
11657 u32 pkt_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211;
11658 u32 len_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211_LEN;
11659
11660 if (!wakeup->packet_80211) {
11661 pkt_attr =
11662 NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023;
11663 len_attr =
11664 NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023_LEN;
11665 }
11666
11667 if (wakeup->packet_len &&
11668 nla_put_u32(msg, len_attr, wakeup->packet_len))
11669 goto free_msg;
11670
11671 if (nla_put(msg, pkt_attr, wakeup->packet_present_len,
11672 wakeup->packet))
11673 goto free_msg;
11674 }
11675
11676 nla_nest_end(msg, reasons);
11677 }
11678
Johannes Berg9c90a9f2013-06-04 12:46:03 +020011679 genlmsg_end(msg, hdr);
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010011680
Johannes Berg68eb5502013-11-19 15:19:38 +010011681 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011682 NL80211_MCGRP_MLME, gfp);
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010011683 return;
11684
11685 free_msg:
11686 nlmsg_free(msg);
11687}
11688EXPORT_SYMBOL(cfg80211_report_wowlan_wakeup);
11689#endif
11690
Jouni Malinen3475b092012-11-16 22:49:57 +020011691void cfg80211_tdls_oper_request(struct net_device *dev, const u8 *peer,
11692 enum nl80211_tdls_operation oper,
11693 u16 reason_code, gfp_t gfp)
11694{
11695 struct wireless_dev *wdev = dev->ieee80211_ptr;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080011696 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Jouni Malinen3475b092012-11-16 22:49:57 +020011697 struct sk_buff *msg;
11698 void *hdr;
Jouni Malinen3475b092012-11-16 22:49:57 +020011699
11700 trace_cfg80211_tdls_oper_request(wdev->wiphy, dev, peer, oper,
11701 reason_code);
11702
11703 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
11704 if (!msg)
11705 return;
11706
11707 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_TDLS_OPER);
11708 if (!hdr) {
11709 nlmsg_free(msg);
11710 return;
11711 }
11712
11713 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
11714 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
11715 nla_put_u8(msg, NL80211_ATTR_TDLS_OPERATION, oper) ||
11716 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer) ||
11717 (reason_code > 0 &&
11718 nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason_code)))
11719 goto nla_put_failure;
11720
Johannes Berg9c90a9f2013-06-04 12:46:03 +020011721 genlmsg_end(msg, hdr);
Jouni Malinen3475b092012-11-16 22:49:57 +020011722
Johannes Berg68eb5502013-11-19 15:19:38 +010011723 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011724 NL80211_MCGRP_MLME, gfp);
Jouni Malinen3475b092012-11-16 22:49:57 +020011725 return;
11726
11727 nla_put_failure:
11728 genlmsg_cancel(msg, hdr);
11729 nlmsg_free(msg);
11730}
11731EXPORT_SYMBOL(cfg80211_tdls_oper_request);
11732
Jouni Malinen026331c2010-02-15 12:53:10 +020011733static int nl80211_netlink_notify(struct notifier_block * nb,
11734 unsigned long state,
11735 void *_notify)
11736{
11737 struct netlink_notify *notify = _notify;
11738 struct cfg80211_registered_device *rdev;
11739 struct wireless_dev *wdev;
Ben Greear37c73b52012-10-26 14:49:25 -070011740 struct cfg80211_beacon_registration *reg, *tmp;
Jouni Malinen026331c2010-02-15 12:53:10 +020011741
11742 if (state != NETLINK_URELEASE)
11743 return NOTIFY_DONE;
11744
11745 rcu_read_lock();
11746
Johannes Berg5e760232011-11-04 11:18:17 +010011747 list_for_each_entry_rcu(rdev, &cfg80211_rdev_list, list) {
Johannes Berg78f22b62014-03-24 17:57:27 +010011748 bool schedule_destroy_work = false;
11749
11750 list_for_each_entry_rcu(wdev, &rdev->wdev_list, list) {
Eric W. Biederman15e47302012-09-07 20:12:54 +000011751 cfg80211_mlme_unregister_socket(wdev, notify->portid);
Ben Greear37c73b52012-10-26 14:49:25 -070011752
Johannes Berg78f22b62014-03-24 17:57:27 +010011753 if (wdev->owner_nlportid == notify->portid)
11754 schedule_destroy_work = true;
11755 }
11756
Ben Greear37c73b52012-10-26 14:49:25 -070011757 spin_lock_bh(&rdev->beacon_registrations_lock);
11758 list_for_each_entry_safe(reg, tmp, &rdev->beacon_registrations,
11759 list) {
11760 if (reg->nlportid == notify->portid) {
11761 list_del(&reg->list);
11762 kfree(reg);
11763 break;
11764 }
11765 }
11766 spin_unlock_bh(&rdev->beacon_registrations_lock);
Johannes Berg78f22b62014-03-24 17:57:27 +010011767
11768 if (schedule_destroy_work) {
11769 struct cfg80211_iface_destroy *destroy;
11770
11771 destroy = kzalloc(sizeof(*destroy), GFP_ATOMIC);
11772 if (destroy) {
11773 destroy->nlportid = notify->portid;
11774 spin_lock(&rdev->destroy_list_lock);
11775 list_add(&destroy->list, &rdev->destroy_list);
11776 spin_unlock(&rdev->destroy_list_lock);
11777 schedule_work(&rdev->destroy_work);
11778 }
11779 }
Johannes Berg5e760232011-11-04 11:18:17 +010011780 }
Jouni Malinen026331c2010-02-15 12:53:10 +020011781
11782 rcu_read_unlock();
11783
Zhao, Gang6784c7d2014-04-21 12:53:04 +080011784 return NOTIFY_OK;
Jouni Malinen026331c2010-02-15 12:53:10 +020011785}
11786
11787static struct notifier_block nl80211_netlink_notifier = {
11788 .notifier_call = nl80211_netlink_notify,
11789};
11790
Jouni Malinen355199e2013-02-27 17:14:27 +020011791void cfg80211_ft_event(struct net_device *netdev,
11792 struct cfg80211_ft_event_params *ft_event)
11793{
11794 struct wiphy *wiphy = netdev->ieee80211_ptr->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080011795 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Jouni Malinen355199e2013-02-27 17:14:27 +020011796 struct sk_buff *msg;
11797 void *hdr;
Jouni Malinen355199e2013-02-27 17:14:27 +020011798
11799 trace_cfg80211_ft_event(wiphy, netdev, ft_event);
11800
11801 if (!ft_event->target_ap)
11802 return;
11803
11804 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
11805 if (!msg)
11806 return;
11807
11808 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FT_EVENT);
Johannes Bergae917c92013-10-25 11:05:22 +020011809 if (!hdr)
11810 goto out;
Jouni Malinen355199e2013-02-27 17:14:27 +020011811
Johannes Bergae917c92013-10-25 11:05:22 +020011812 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
11813 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
11814 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, ft_event->target_ap))
11815 goto out;
11816
11817 if (ft_event->ies &&
11818 nla_put(msg, NL80211_ATTR_IE, ft_event->ies_len, ft_event->ies))
11819 goto out;
11820 if (ft_event->ric_ies &&
11821 nla_put(msg, NL80211_ATTR_IE_RIC, ft_event->ric_ies_len,
11822 ft_event->ric_ies))
11823 goto out;
Jouni Malinen355199e2013-02-27 17:14:27 +020011824
Johannes Berg9c90a9f2013-06-04 12:46:03 +020011825 genlmsg_end(msg, hdr);
Jouni Malinen355199e2013-02-27 17:14:27 +020011826
Johannes Berg68eb5502013-11-19 15:19:38 +010011827 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011828 NL80211_MCGRP_MLME, GFP_KERNEL);
Johannes Bergae917c92013-10-25 11:05:22 +020011829 return;
11830 out:
11831 nlmsg_free(msg);
Jouni Malinen355199e2013-02-27 17:14:27 +020011832}
11833EXPORT_SYMBOL(cfg80211_ft_event);
11834
Arend van Spriel5de17982013-04-18 15:49:00 +020011835void cfg80211_crit_proto_stopped(struct wireless_dev *wdev, gfp_t gfp)
11836{
11837 struct cfg80211_registered_device *rdev;
11838 struct sk_buff *msg;
11839 void *hdr;
11840 u32 nlportid;
11841
Zhao, Gangf26cbf42014-04-21 12:53:03 +080011842 rdev = wiphy_to_rdev(wdev->wiphy);
Arend van Spriel5de17982013-04-18 15:49:00 +020011843 if (!rdev->crit_proto_nlportid)
11844 return;
11845
11846 nlportid = rdev->crit_proto_nlportid;
11847 rdev->crit_proto_nlportid = 0;
11848
11849 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
11850 if (!msg)
11851 return;
11852
11853 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CRIT_PROTOCOL_STOP);
11854 if (!hdr)
11855 goto nla_put_failure;
11856
11857 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
11858 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)))
11859 goto nla_put_failure;
11860
11861 genlmsg_end(msg, hdr);
11862
11863 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid);
11864 return;
11865
11866 nla_put_failure:
11867 if (hdr)
11868 genlmsg_cancel(msg, hdr);
11869 nlmsg_free(msg);
11870
11871}
11872EXPORT_SYMBOL(cfg80211_crit_proto_stopped);
11873
Johannes Berg348baf02014-01-24 14:06:29 +010011874void nl80211_send_ap_stopped(struct wireless_dev *wdev)
11875{
11876 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080011877 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg348baf02014-01-24 14:06:29 +010011878 struct sk_buff *msg;
11879 void *hdr;
11880
11881 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
11882 if (!msg)
11883 return;
11884
11885 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_STOP_AP);
11886 if (!hdr)
11887 goto out;
11888
11889 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
11890 nla_put_u32(msg, NL80211_ATTR_IFINDEX, wdev->netdev->ifindex) ||
11891 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)))
11892 goto out;
11893
11894 genlmsg_end(msg, hdr);
11895
11896 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(wiphy), msg, 0,
11897 NL80211_MCGRP_MLME, GFP_KERNEL);
11898 return;
11899 out:
11900 nlmsg_free(msg);
11901}
11902
Johannes Berg55682962007-09-20 13:09:35 -040011903/* initialisation/exit functions */
11904
11905int nl80211_init(void)
11906{
Michał Mirosław0d63cbb2009-05-21 10:34:06 +000011907 int err;
Johannes Berg55682962007-09-20 13:09:35 -040011908
Johannes Berg2a94fe42013-11-19 15:19:39 +010011909 err = genl_register_family_with_ops_groups(&nl80211_fam, nl80211_ops,
11910 nl80211_mcgrps);
Johannes Berg55682962007-09-20 13:09:35 -040011911 if (err)
11912 return err;
11913
Jouni Malinen026331c2010-02-15 12:53:10 +020011914 err = netlink_register_notifier(&nl80211_netlink_notifier);
11915 if (err)
11916 goto err_out;
11917
Johannes Berg55682962007-09-20 13:09:35 -040011918 return 0;
11919 err_out:
11920 genl_unregister_family(&nl80211_fam);
11921 return err;
11922}
11923
11924void nl80211_exit(void)
11925{
Jouni Malinen026331c2010-02-15 12:53:10 +020011926 netlink_unregister_notifier(&nl80211_netlink_notifier);
Johannes Berg55682962007-09-20 13:09:35 -040011927 genl_unregister_family(&nl80211_fam);
11928}