blob: 6668daf6932667bee1f80f6d4c7bdcefef36346c [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 Malinendc6382ce2009-05-06 22:09:37 +0300290 [NL80211_ATTR_USE_MFP] = { .type = NLA_U32 },
Johannes Bergeccb8e82009-05-11 21:57:56 +0300291 [NL80211_ATTR_STA_FLAGS2] = {
292 .len = sizeof(struct nl80211_sta_flag_update),
293 },
Jouni Malinen3f77316c2009-05-11 21:57:57 +0300294 [NL80211_ATTR_CONTROL_PORT] = { .type = NLA_FLAG },
Johannes Bergc0692b82010-08-27 14:26:53 +0300295 [NL80211_ATTR_CONTROL_PORT_ETHERTYPE] = { .type = NLA_U16 },
296 [NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT] = { .type = NLA_FLAG },
Samuel Ortizb23aa672009-07-01 21:26:54 +0200297 [NL80211_ATTR_PRIVACY] = { .type = NLA_FLAG },
298 [NL80211_ATTR_CIPHER_SUITE_GROUP] = { .type = NLA_U32 },
299 [NL80211_ATTR_WPA_VERSIONS] = { .type = NLA_U32 },
Johannes Berg463d0182009-07-14 00:33:35 +0200300 [NL80211_ATTR_PID] = { .type = NLA_U32 },
Felix Fietkau8b787642009-11-10 18:53:10 +0100301 [NL80211_ATTR_4ADDR] = { .type = NLA_U8 },
Samuel Ortiz67fbb162009-11-24 23:59:15 +0100302 [NL80211_ATTR_PMKID] = { .type = NLA_BINARY,
303 .len = WLAN_PMKID_LEN },
Jouni Malinen9588bbd2009-12-23 13:15:41 +0100304 [NL80211_ATTR_DURATION] = { .type = NLA_U32 },
305 [NL80211_ATTR_COOKIE] = { .type = NLA_U64 },
Jouni Malinen13ae75b2009-12-29 12:59:45 +0200306 [NL80211_ATTR_TX_RATES] = { .type = NLA_NESTED },
Jouni Malinen026331c2010-02-15 12:53:10 +0200307 [NL80211_ATTR_FRAME] = { .type = NLA_BINARY,
308 .len = IEEE80211_MAX_DATA_LEN },
309 [NL80211_ATTR_FRAME_MATCH] = { .type = NLA_BINARY, },
Kalle Valoffb9eb32010-02-17 17:58:10 +0200310 [NL80211_ATTR_PS_STATE] = { .type = NLA_U32 },
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +0200311 [NL80211_ATTR_CQM] = { .type = NLA_NESTED, },
Jouni Malinend5cdfac2010-04-04 09:37:19 +0300312 [NL80211_ATTR_LOCAL_STATE_CHANGE] = { .type = NLA_FLAG },
Felix Fietkaufd8aaaf2010-04-27 01:23:35 +0200313 [NL80211_ATTR_AP_ISOLATE] = { .type = NLA_U8 },
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +0300314 [NL80211_ATTR_WIPHY_TX_POWER_SETTING] = { .type = NLA_U32 },
315 [NL80211_ATTR_WIPHY_TX_POWER_LEVEL] = { .type = NLA_U32 },
Johannes Berg2e161f72010-08-12 15:38:38 +0200316 [NL80211_ATTR_FRAME_TYPE] = { .type = NLA_U16 },
Bruno Randolfafe0cbf2010-11-10 12:50:50 +0900317 [NL80211_ATTR_WIPHY_ANTENNA_TX] = { .type = NLA_U32 },
318 [NL80211_ATTR_WIPHY_ANTENNA_RX] = { .type = NLA_U32 },
Felix Fietkau885a46d2010-11-11 15:07:22 +0100319 [NL80211_ATTR_MCAST_RATE] = { .type = NLA_U32 },
Johannes Bergf7ca38d2010-11-25 10:02:29 +0100320 [NL80211_ATTR_OFFCHANNEL_TX_OK] = { .type = NLA_FLAG },
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100321 [NL80211_ATTR_KEY_DEFAULT_TYPES] = { .type = NLA_NESTED },
Johannes Bergff1b6e62011-05-04 15:37:28 +0200322 [NL80211_ATTR_WOWLAN_TRIGGERS] = { .type = NLA_NESTED },
Javier Cardona9c3990a2011-05-03 16:57:11 -0700323 [NL80211_ATTR_STA_PLINK_STATE] = { .type = NLA_U8 },
Luciano Coelhobbe6ad62011-05-11 17:09:37 +0300324 [NL80211_ATTR_SCHED_SCAN_INTERVAL] = { .type = NLA_U32 },
Johannes Berge5497d72011-07-05 16:35:40 +0200325 [NL80211_ATTR_REKEY_DATA] = { .type = NLA_NESTED },
Johannes Berg34850ab2011-07-18 18:08:35 +0200326 [NL80211_ATTR_SCAN_SUPP_RATES] = { .type = NLA_NESTED },
Jouni Malinen32e9de82011-08-10 23:53:31 +0300327 [NL80211_ATTR_HIDDEN_SSID] = { .type = NLA_U32 },
Jouni Malinen9946ecf2011-08-10 23:55:56 +0300328 [NL80211_ATTR_IE_PROBE_RESP] = { .type = NLA_BINARY,
329 .len = IEEE80211_MAX_DATA_LEN },
330 [NL80211_ATTR_IE_ASSOC_RESP] = { .type = NLA_BINARY,
331 .len = IEEE80211_MAX_DATA_LEN },
Vivek Natarajanf4b34b52011-08-29 14:23:03 +0530332 [NL80211_ATTR_ROAM_SUPPORT] = { .type = NLA_FLAG },
Luciano Coelhoa1f1c212011-08-31 16:01:48 +0300333 [NL80211_ATTR_SCHED_SCAN_MATCH] = { .type = NLA_NESTED },
Rajkumar Manoharane9f935e2011-09-25 14:53:30 +0530334 [NL80211_ATTR_TX_NO_CCK_RATE] = { .type = NLA_FLAG },
Arik Nemtsov109086c2011-09-28 14:12:50 +0300335 [NL80211_ATTR_TDLS_ACTION] = { .type = NLA_U8 },
336 [NL80211_ATTR_TDLS_DIALOG_TOKEN] = { .type = NLA_U8 },
337 [NL80211_ATTR_TDLS_OPERATION] = { .type = NLA_U8 },
338 [NL80211_ATTR_TDLS_SUPPORT] = { .type = NLA_FLAG },
339 [NL80211_ATTR_TDLS_EXTERNAL_SETUP] = { .type = NLA_FLAG },
Johannes Berge247bd902011-11-04 11:18:21 +0100340 [NL80211_ATTR_DONT_WAIT_FOR_ACK] = { .type = NLA_FLAG },
Arik Nemtsov00f740e2011-11-10 11:28:56 +0200341 [NL80211_ATTR_PROBE_RESP] = { .type = NLA_BINARY,
342 .len = IEEE80211_MAX_DATA_LEN },
Luis R. Rodriguez8b60b072011-10-11 10:59:02 -0700343 [NL80211_ATTR_DFS_REGION] = { .type = NLA_U8 },
Ben Greear7e7c8922011-11-18 11:31:59 -0800344 [NL80211_ATTR_DISABLE_HT] = { .type = NLA_FLAG },
345 [NL80211_ATTR_HT_CAPABILITY_MASK] = {
346 .len = NL80211_HT_CAPABILITY_LEN
347 },
Simon Wunderlich1d9d9212011-11-18 14:20:43 +0100348 [NL80211_ATTR_NOACK_MAP] = { .type = NLA_U16 },
Vasanthakumar Thiagarajan1b658f12012-03-02 15:50:02 +0530349 [NL80211_ATTR_INACTIVITY_TIMEOUT] = { .type = NLA_U16 },
Bala Shanmugam4486ea92012-03-07 17:27:12 +0530350 [NL80211_ATTR_BG_SCAN_PERIOD] = { .type = NLA_U16 },
Johannes Berg89a54e42012-06-15 14:33:17 +0200351 [NL80211_ATTR_WDEV] = { .type = NLA_U64 },
Luis R. Rodriguez57b5ce02012-07-12 11:49:18 -0700352 [NL80211_ATTR_USER_REG_HINT_TYPE] = { .type = NLA_U32 },
Jouni Malinene39e5b52012-09-30 19:29:39 +0300353 [NL80211_ATTR_SAE_DATA] = { .type = NLA_BINARY, },
Mahesh Palivelaf461be3e2012-10-11 08:04:52 +0000354 [NL80211_ATTR_VHT_CAPABILITY] = { .len = NL80211_VHT_CAPABILITY_LEN },
Sam Lefflered4737712012-10-11 21:03:31 -0700355 [NL80211_ATTR_SCAN_FLAGS] = { .type = NLA_U32 },
Johannes Berg53cabad2012-11-14 15:17:28 +0100356 [NL80211_ATTR_P2P_CTWINDOW] = { .type = NLA_U8 },
357 [NL80211_ATTR_P2P_OPPPS] = { .type = NLA_U8 },
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +0530358 [NL80211_ATTR_ACL_POLICY] = {. type = NLA_U32 },
359 [NL80211_ATTR_MAC_ADDRS] = { .type = NLA_NESTED },
Jouni Malinen9d62a982013-02-14 21:10:13 +0200360 [NL80211_ATTR_STA_CAPABILITY] = { .type = NLA_U16 },
361 [NL80211_ATTR_STA_EXT_CAPABILITY] = { .type = NLA_BINARY, },
Johannes Berg3713b4e2013-02-14 16:19:38 +0100362 [NL80211_ATTR_SPLIT_WIPHY_DUMP] = { .type = NLA_FLAG, },
Johannes Bergee2aca32013-02-21 17:36:01 +0100363 [NL80211_ATTR_DISABLE_VHT] = { .type = NLA_FLAG },
364 [NL80211_ATTR_VHT_CAPABILITY_MASK] = {
365 .len = NL80211_VHT_CAPABILITY_LEN,
366 },
Jouni Malinen355199e2013-02-27 17:14:27 +0200367 [NL80211_ATTR_MDID] = { .type = NLA_U16 },
368 [NL80211_ATTR_IE_RIC] = { .type = NLA_BINARY,
369 .len = IEEE80211_MAX_DATA_LEN },
Jouni Malinen5e4b6f52013-05-16 20:11:08 +0300370 [NL80211_ATTR_PEER_AID] = { .type = NLA_U16 },
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +0200371 [NL80211_ATTR_CH_SWITCH_COUNT] = { .type = NLA_U32 },
372 [NL80211_ATTR_CH_SWITCH_BLOCK_TX] = { .type = NLA_FLAG },
373 [NL80211_ATTR_CSA_IES] = { .type = NLA_NESTED },
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +0300374 [NL80211_ATTR_CSA_C_OFF_BEACON] = { .type = NLA_BINARY },
375 [NL80211_ATTR_CSA_C_OFF_PRESP] = { .type = NLA_BINARY },
Sunil Duttc01fc9a2013-10-09 20:45:21 +0530376 [NL80211_ATTR_STA_SUPPORTED_CHANNELS] = { .type = NLA_BINARY },
377 [NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES] = { .type = NLA_BINARY },
Simon Wunderlich5336fa82013-10-07 18:41:05 +0200378 [NL80211_ATTR_HANDLE_DFS] = { .type = NLA_FLAG },
Marek Kwaczynski60f4a7b2013-12-03 10:04:59 +0100379 [NL80211_ATTR_OPMODE_NOTIF] = { .type = NLA_U8 },
Johannes Bergad7e7182013-11-13 13:37:47 +0100380 [NL80211_ATTR_VENDOR_ID] = { .type = NLA_U32 },
381 [NL80211_ATTR_VENDOR_SUBCMD] = { .type = NLA_U32 },
382 [NL80211_ATTR_VENDOR_DATA] = { .type = NLA_BINARY },
Kyeyoon Parkfa9ffc72013-12-16 23:01:30 -0800383 [NL80211_ATTR_QOS_MAP] = { .type = NLA_BINARY,
384 .len = IEEE80211_QOS_MAP_LEN_MAX },
Jouni Malinen1df4a512014-01-15 00:00:47 +0200385 [NL80211_ATTR_MAC_HINT] = { .len = ETH_ALEN },
386 [NL80211_ATTR_WIPHY_FREQ_HINT] = { .type = NLA_U32 },
Sunil Dutt Undekaridf942e72014-02-20 16:22:09 +0530387 [NL80211_ATTR_TDLS_PEER_CAPABILITY] = { .type = NLA_U32 },
Johannes Berg78f22b62014-03-24 17:57:27 +0100388 [NL80211_ATTR_IFACE_SOCKET_OWNER] = { .type = NLA_FLAG },
Andrei Otcheretianski34d22ce2014-05-09 14:11:44 +0300389 [NL80211_ATTR_CSA_C_OFFSETS_TX] = { .type = NLA_BINARY },
Johannes Berg55682962007-09-20 13:09:35 -0400390};
391
Johannes Berge31b8212010-10-05 19:39:30 +0200392/* policy for the key attributes */
Alexey Dobriyanb54452b2010-02-18 08:14:31 +0000393static const struct nla_policy nl80211_key_policy[NL80211_KEY_MAX + 1] = {
Johannes Bergfffd0932009-07-08 14:22:54 +0200394 [NL80211_KEY_DATA] = { .type = NLA_BINARY, .len = WLAN_MAX_KEY_LEN },
Johannes Bergb9454e82009-07-08 13:29:08 +0200395 [NL80211_KEY_IDX] = { .type = NLA_U8 },
396 [NL80211_KEY_CIPHER] = { .type = NLA_U32 },
Jouni Malinen81962262011-11-02 23:36:31 +0200397 [NL80211_KEY_SEQ] = { .type = NLA_BINARY, .len = 16 },
Johannes Bergb9454e82009-07-08 13:29:08 +0200398 [NL80211_KEY_DEFAULT] = { .type = NLA_FLAG },
399 [NL80211_KEY_DEFAULT_MGMT] = { .type = NLA_FLAG },
Johannes Berge31b8212010-10-05 19:39:30 +0200400 [NL80211_KEY_TYPE] = { .type = NLA_U32 },
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100401 [NL80211_KEY_DEFAULT_TYPES] = { .type = NLA_NESTED },
402};
403
404/* policy for the key default flags */
405static const struct nla_policy
406nl80211_key_default_policy[NUM_NL80211_KEY_DEFAULT_TYPES] = {
407 [NL80211_KEY_DEFAULT_TYPE_UNICAST] = { .type = NLA_FLAG },
408 [NL80211_KEY_DEFAULT_TYPE_MULTICAST] = { .type = NLA_FLAG },
Johannes Bergb9454e82009-07-08 13:29:08 +0200409};
410
Johannes Bergff1b6e62011-05-04 15:37:28 +0200411/* policy for WoWLAN attributes */
412static const struct nla_policy
413nl80211_wowlan_policy[NUM_NL80211_WOWLAN_TRIG] = {
414 [NL80211_WOWLAN_TRIG_ANY] = { .type = NLA_FLAG },
415 [NL80211_WOWLAN_TRIG_DISCONNECT] = { .type = NLA_FLAG },
416 [NL80211_WOWLAN_TRIG_MAGIC_PKT] = { .type = NLA_FLAG },
417 [NL80211_WOWLAN_TRIG_PKT_PATTERN] = { .type = NLA_NESTED },
Johannes Berg77dbbb12011-07-13 10:48:55 +0200418 [NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE] = { .type = NLA_FLAG },
419 [NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST] = { .type = NLA_FLAG },
420 [NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE] = { .type = NLA_FLAG },
421 [NL80211_WOWLAN_TRIG_RFKILL_RELEASE] = { .type = NLA_FLAG },
Johannes Berg2a0e0472013-01-23 22:57:40 +0100422 [NL80211_WOWLAN_TRIG_TCP_CONNECTION] = { .type = NLA_NESTED },
423};
424
425static const struct nla_policy
426nl80211_wowlan_tcp_policy[NUM_NL80211_WOWLAN_TCP] = {
427 [NL80211_WOWLAN_TCP_SRC_IPV4] = { .type = NLA_U32 },
428 [NL80211_WOWLAN_TCP_DST_IPV4] = { .type = NLA_U32 },
429 [NL80211_WOWLAN_TCP_DST_MAC] = { .len = ETH_ALEN },
430 [NL80211_WOWLAN_TCP_SRC_PORT] = { .type = NLA_U16 },
431 [NL80211_WOWLAN_TCP_DST_PORT] = { .type = NLA_U16 },
432 [NL80211_WOWLAN_TCP_DATA_PAYLOAD] = { .len = 1 },
433 [NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ] = {
434 .len = sizeof(struct nl80211_wowlan_tcp_data_seq)
435 },
436 [NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN] = {
437 .len = sizeof(struct nl80211_wowlan_tcp_data_token)
438 },
439 [NL80211_WOWLAN_TCP_DATA_INTERVAL] = { .type = NLA_U32 },
440 [NL80211_WOWLAN_TCP_WAKE_PAYLOAD] = { .len = 1 },
441 [NL80211_WOWLAN_TCP_WAKE_MASK] = { .len = 1 },
Johannes Bergff1b6e62011-05-04 15:37:28 +0200442};
443
Amitkumar Karwarbe29b992013-06-28 11:51:26 -0700444/* policy for coalesce rule attributes */
445static const struct nla_policy
446nl80211_coalesce_policy[NUM_NL80211_ATTR_COALESCE_RULE] = {
447 [NL80211_ATTR_COALESCE_RULE_DELAY] = { .type = NLA_U32 },
448 [NL80211_ATTR_COALESCE_RULE_CONDITION] = { .type = NLA_U32 },
449 [NL80211_ATTR_COALESCE_RULE_PKT_PATTERN] = { .type = NLA_NESTED },
450};
451
Johannes Berge5497d72011-07-05 16:35:40 +0200452/* policy for GTK rekey offload attributes */
453static const struct nla_policy
454nl80211_rekey_policy[NUM_NL80211_REKEY_DATA] = {
455 [NL80211_REKEY_DATA_KEK] = { .len = NL80211_KEK_LEN },
456 [NL80211_REKEY_DATA_KCK] = { .len = NL80211_KCK_LEN },
457 [NL80211_REKEY_DATA_REPLAY_CTR] = { .len = NL80211_REPLAY_CTR_LEN },
458};
459
Luciano Coelhoa1f1c212011-08-31 16:01:48 +0300460static const struct nla_policy
461nl80211_match_policy[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1] = {
Johannes Berg4a4ab0d2012-06-13 11:17:11 +0200462 [NL80211_SCHED_SCAN_MATCH_ATTR_SSID] = { .type = NLA_BINARY,
Luciano Coelhoa1f1c212011-08-31 16:01:48 +0300463 .len = IEEE80211_MAX_SSID_LEN },
Thomas Pedersen88e920b2012-06-21 11:09:54 -0700464 [NL80211_SCHED_SCAN_MATCH_ATTR_RSSI] = { .type = NLA_U32 },
Luciano Coelhoa1f1c212011-08-31 16:01:48 +0300465};
466
Johannes Berg97990a02013-04-19 01:02:55 +0200467static int nl80211_prepare_wdev_dump(struct sk_buff *skb,
468 struct netlink_callback *cb,
469 struct cfg80211_registered_device **rdev,
470 struct wireless_dev **wdev)
Holger Schuriga0438972009-11-11 11:30:02 +0100471{
Johannes Berg67748892010-10-04 21:14:06 +0200472 int err;
473
Johannes Berg67748892010-10-04 21:14:06 +0200474 rtnl_lock();
475
Johannes Berg97990a02013-04-19 01:02:55 +0200476 if (!cb->args[0]) {
477 err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize,
478 nl80211_fam.attrbuf, nl80211_fam.maxattr,
479 nl80211_policy);
480 if (err)
481 goto out_unlock;
482
483 *wdev = __cfg80211_wdev_from_attrs(sock_net(skb->sk),
484 nl80211_fam.attrbuf);
485 if (IS_ERR(*wdev)) {
486 err = PTR_ERR(*wdev);
487 goto out_unlock;
488 }
Zhao, Gangf26cbf42014-04-21 12:53:03 +0800489 *rdev = wiphy_to_rdev((*wdev)->wiphy);
Johannes Bergc319d502013-07-30 22:34:28 +0200490 /* 0 is the first index - add 1 to parse only once */
491 cb->args[0] = (*rdev)->wiphy_idx + 1;
Johannes Berg97990a02013-04-19 01:02:55 +0200492 cb->args[1] = (*wdev)->identifier;
493 } else {
Johannes Bergc319d502013-07-30 22:34:28 +0200494 /* subtract the 1 again here */
495 struct wiphy *wiphy = wiphy_idx_to_wiphy(cb->args[0] - 1);
Johannes Berg97990a02013-04-19 01:02:55 +0200496 struct wireless_dev *tmp;
497
498 if (!wiphy) {
499 err = -ENODEV;
500 goto out_unlock;
501 }
Zhao, Gangf26cbf42014-04-21 12:53:03 +0800502 *rdev = wiphy_to_rdev(wiphy);
Johannes Berg97990a02013-04-19 01:02:55 +0200503 *wdev = NULL;
504
Johannes Berg97990a02013-04-19 01:02:55 +0200505 list_for_each_entry(tmp, &(*rdev)->wdev_list, list) {
506 if (tmp->identifier == cb->args[1]) {
507 *wdev = tmp;
508 break;
509 }
510 }
Johannes Berg97990a02013-04-19 01:02:55 +0200511
512 if (!*wdev) {
513 err = -ENODEV;
514 goto out_unlock;
515 }
Johannes Berg67748892010-10-04 21:14:06 +0200516 }
517
Johannes Berg67748892010-10-04 21:14:06 +0200518 return 0;
Johannes Berg97990a02013-04-19 01:02:55 +0200519 out_unlock:
Johannes Berg67748892010-10-04 21:14:06 +0200520 rtnl_unlock();
521 return err;
522}
523
Johannes Berg97990a02013-04-19 01:02:55 +0200524static void nl80211_finish_wdev_dump(struct cfg80211_registered_device *rdev)
Johannes Berg67748892010-10-04 21:14:06 +0200525{
Johannes Berg67748892010-10-04 21:14:06 +0200526 rtnl_unlock();
527}
528
Johannes Bergf4a11bb2009-03-27 12:40:28 +0100529/* IE validation */
530static bool is_valid_ie_attr(const struct nlattr *attr)
531{
532 const u8 *pos;
533 int len;
534
535 if (!attr)
536 return true;
537
538 pos = nla_data(attr);
539 len = nla_len(attr);
540
541 while (len) {
542 u8 elemlen;
543
544 if (len < 2)
545 return false;
546 len -= 2;
547
548 elemlen = pos[1];
549 if (elemlen > len)
550 return false;
551
552 len -= elemlen;
553 pos += 2 + elemlen;
554 }
555
556 return true;
557}
558
Johannes Berg55682962007-09-20 13:09:35 -0400559/* message building helper */
Eric W. Biederman15e47302012-09-07 20:12:54 +0000560static inline void *nl80211hdr_put(struct sk_buff *skb, u32 portid, u32 seq,
Johannes Berg55682962007-09-20 13:09:35 -0400561 int flags, u8 cmd)
562{
563 /* since there is no private header just add the generic one */
Eric W. Biederman15e47302012-09-07 20:12:54 +0000564 return genlmsg_put(skb, portid, seq, &nl80211_fam, flags, cmd);
Johannes Berg55682962007-09-20 13:09:35 -0400565}
566
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400567static int nl80211_msg_put_channel(struct sk_buff *msg,
Johannes Bergcdc89b92013-02-18 23:54:36 +0100568 struct ieee80211_channel *chan,
569 bool large)
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400570{
Rostislav Lisovyea077c12014-04-15 14:37:55 +0200571 /* Some channels must be completely excluded from the
572 * list to protect old user-space tools from breaking
573 */
574 if (!large && chan->flags &
575 (IEEE80211_CHAN_NO_10MHZ | IEEE80211_CHAN_NO_20MHZ))
576 return 0;
577
David S. Miller9360ffd2012-03-29 04:41:26 -0400578 if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_FREQ,
579 chan->center_freq))
580 goto nla_put_failure;
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400581
David S. Miller9360ffd2012-03-29 04:41:26 -0400582 if ((chan->flags & IEEE80211_CHAN_DISABLED) &&
583 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_DISABLED))
584 goto nla_put_failure;
Luis R. Rodriguez8fe02e12013-10-21 19:22:25 +0200585 if (chan->flags & IEEE80211_CHAN_NO_IR) {
586 if (nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_IR))
587 goto nla_put_failure;
588 if (nla_put_flag(msg, __NL80211_FREQUENCY_ATTR_NO_IBSS))
589 goto nla_put_failure;
590 }
Johannes Bergcdc89b92013-02-18 23:54:36 +0100591 if (chan->flags & IEEE80211_CHAN_RADAR) {
592 if (nla_put_flag(msg, NL80211_FREQUENCY_ATTR_RADAR))
593 goto nla_put_failure;
594 if (large) {
595 u32 time;
596
597 time = elapsed_jiffies_msecs(chan->dfs_state_entered);
598
599 if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_DFS_STATE,
600 chan->dfs_state))
601 goto nla_put_failure;
602 if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_DFS_TIME,
603 time))
604 goto nla_put_failure;
Janusz Dziedzic089027e2014-02-21 19:46:12 +0100605 if (nla_put_u32(msg,
606 NL80211_FREQUENCY_ATTR_DFS_CAC_TIME,
607 chan->dfs_cac_ms))
608 goto nla_put_failure;
Johannes Bergcdc89b92013-02-18 23:54:36 +0100609 }
610 }
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400611
Johannes Bergfe1abaf2013-02-27 15:39:45 +0100612 if (large) {
613 if ((chan->flags & IEEE80211_CHAN_NO_HT40MINUS) &&
614 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_HT40_MINUS))
615 goto nla_put_failure;
616 if ((chan->flags & IEEE80211_CHAN_NO_HT40PLUS) &&
617 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_HT40_PLUS))
618 goto nla_put_failure;
619 if ((chan->flags & IEEE80211_CHAN_NO_80MHZ) &&
620 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_80MHZ))
621 goto nla_put_failure;
622 if ((chan->flags & IEEE80211_CHAN_NO_160MHZ) &&
623 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_160MHZ))
624 goto nla_put_failure;
David Spinadel570dbde2014-02-23 09:12:59 +0200625 if ((chan->flags & IEEE80211_CHAN_INDOOR_ONLY) &&
626 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_INDOOR_ONLY))
627 goto nla_put_failure;
628 if ((chan->flags & IEEE80211_CHAN_GO_CONCURRENT) &&
629 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_GO_CONCURRENT))
630 goto nla_put_failure;
Rostislav Lisovyea077c12014-04-15 14:37:55 +0200631 if ((chan->flags & IEEE80211_CHAN_NO_20MHZ) &&
632 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_20MHZ))
633 goto nla_put_failure;
634 if ((chan->flags & IEEE80211_CHAN_NO_10MHZ) &&
635 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_10MHZ))
636 goto nla_put_failure;
Johannes Bergfe1abaf2013-02-27 15:39:45 +0100637 }
638
David S. Miller9360ffd2012-03-29 04:41:26 -0400639 if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_MAX_TX_POWER,
640 DBM_TO_MBM(chan->max_power)))
641 goto nla_put_failure;
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400642
643 return 0;
644
645 nla_put_failure:
646 return -ENOBUFS;
647}
648
Johannes Berg55682962007-09-20 13:09:35 -0400649/* netlink command implementations */
650
Johannes Bergb9454e82009-07-08 13:29:08 +0200651struct key_parse {
652 struct key_params p;
653 int idx;
Johannes Berge31b8212010-10-05 19:39:30 +0200654 int type;
Johannes Bergb9454e82009-07-08 13:29:08 +0200655 bool def, defmgmt;
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100656 bool def_uni, def_multi;
Johannes Bergb9454e82009-07-08 13:29:08 +0200657};
658
659static int nl80211_parse_key_new(struct nlattr *key, struct key_parse *k)
660{
661 struct nlattr *tb[NL80211_KEY_MAX + 1];
662 int err = nla_parse_nested(tb, NL80211_KEY_MAX, key,
663 nl80211_key_policy);
664 if (err)
665 return err;
666
667 k->def = !!tb[NL80211_KEY_DEFAULT];
668 k->defmgmt = !!tb[NL80211_KEY_DEFAULT_MGMT];
669
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100670 if (k->def) {
671 k->def_uni = true;
672 k->def_multi = true;
673 }
674 if (k->defmgmt)
675 k->def_multi = true;
676
Johannes Bergb9454e82009-07-08 13:29:08 +0200677 if (tb[NL80211_KEY_IDX])
678 k->idx = nla_get_u8(tb[NL80211_KEY_IDX]);
679
680 if (tb[NL80211_KEY_DATA]) {
681 k->p.key = nla_data(tb[NL80211_KEY_DATA]);
682 k->p.key_len = nla_len(tb[NL80211_KEY_DATA]);
683 }
684
685 if (tb[NL80211_KEY_SEQ]) {
686 k->p.seq = nla_data(tb[NL80211_KEY_SEQ]);
687 k->p.seq_len = nla_len(tb[NL80211_KEY_SEQ]);
688 }
689
690 if (tb[NL80211_KEY_CIPHER])
691 k->p.cipher = nla_get_u32(tb[NL80211_KEY_CIPHER]);
692
Johannes Berge31b8212010-10-05 19:39:30 +0200693 if (tb[NL80211_KEY_TYPE]) {
694 k->type = nla_get_u32(tb[NL80211_KEY_TYPE]);
695 if (k->type < 0 || k->type >= NUM_NL80211_KEYTYPES)
696 return -EINVAL;
697 }
698
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100699 if (tb[NL80211_KEY_DEFAULT_TYPES]) {
700 struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES];
Johannes Berg2da8f412012-01-20 13:52:37 +0100701 err = nla_parse_nested(kdt, NUM_NL80211_KEY_DEFAULT_TYPES - 1,
702 tb[NL80211_KEY_DEFAULT_TYPES],
703 nl80211_key_default_policy);
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100704 if (err)
705 return err;
706
707 k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST];
708 k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST];
709 }
710
Johannes Bergb9454e82009-07-08 13:29:08 +0200711 return 0;
712}
713
714static int nl80211_parse_key_old(struct genl_info *info, struct key_parse *k)
715{
716 if (info->attrs[NL80211_ATTR_KEY_DATA]) {
717 k->p.key = nla_data(info->attrs[NL80211_ATTR_KEY_DATA]);
718 k->p.key_len = nla_len(info->attrs[NL80211_ATTR_KEY_DATA]);
719 }
720
721 if (info->attrs[NL80211_ATTR_KEY_SEQ]) {
722 k->p.seq = nla_data(info->attrs[NL80211_ATTR_KEY_SEQ]);
723 k->p.seq_len = nla_len(info->attrs[NL80211_ATTR_KEY_SEQ]);
724 }
725
726 if (info->attrs[NL80211_ATTR_KEY_IDX])
727 k->idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]);
728
729 if (info->attrs[NL80211_ATTR_KEY_CIPHER])
730 k->p.cipher = nla_get_u32(info->attrs[NL80211_ATTR_KEY_CIPHER]);
731
732 k->def = !!info->attrs[NL80211_ATTR_KEY_DEFAULT];
733 k->defmgmt = !!info->attrs[NL80211_ATTR_KEY_DEFAULT_MGMT];
734
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100735 if (k->def) {
736 k->def_uni = true;
737 k->def_multi = true;
738 }
739 if (k->defmgmt)
740 k->def_multi = true;
741
Johannes Berge31b8212010-10-05 19:39:30 +0200742 if (info->attrs[NL80211_ATTR_KEY_TYPE]) {
743 k->type = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]);
744 if (k->type < 0 || k->type >= NUM_NL80211_KEYTYPES)
745 return -EINVAL;
746 }
747
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100748 if (info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES]) {
749 struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES];
750 int err = nla_parse_nested(
751 kdt, NUM_NL80211_KEY_DEFAULT_TYPES - 1,
752 info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES],
753 nl80211_key_default_policy);
754 if (err)
755 return err;
756
757 k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST];
758 k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST];
759 }
760
Johannes Bergb9454e82009-07-08 13:29:08 +0200761 return 0;
762}
763
764static int nl80211_parse_key(struct genl_info *info, struct key_parse *k)
765{
766 int err;
767
768 memset(k, 0, sizeof(*k));
769 k->idx = -1;
Johannes Berge31b8212010-10-05 19:39:30 +0200770 k->type = -1;
Johannes Bergb9454e82009-07-08 13:29:08 +0200771
772 if (info->attrs[NL80211_ATTR_KEY])
773 err = nl80211_parse_key_new(info->attrs[NL80211_ATTR_KEY], k);
774 else
775 err = nl80211_parse_key_old(info, k);
776
777 if (err)
778 return err;
779
780 if (k->def && k->defmgmt)
781 return -EINVAL;
782
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100783 if (k->defmgmt) {
784 if (k->def_uni || !k->def_multi)
785 return -EINVAL;
786 }
787
Johannes Bergb9454e82009-07-08 13:29:08 +0200788 if (k->idx != -1) {
789 if (k->defmgmt) {
790 if (k->idx < 4 || k->idx > 5)
791 return -EINVAL;
792 } else if (k->def) {
793 if (k->idx < 0 || k->idx > 3)
794 return -EINVAL;
795 } else {
796 if (k->idx < 0 || k->idx > 5)
797 return -EINVAL;
798 }
799 }
800
801 return 0;
802}
803
Johannes Bergfffd0932009-07-08 14:22:54 +0200804static struct cfg80211_cached_keys *
805nl80211_parse_connkeys(struct cfg80211_registered_device *rdev,
Sujith Manoharande7044e2012-10-18 10:19:28 +0530806 struct nlattr *keys, bool *no_ht)
Johannes Bergfffd0932009-07-08 14:22:54 +0200807{
808 struct key_parse parse;
809 struct nlattr *key;
810 struct cfg80211_cached_keys *result;
811 int rem, err, def = 0;
812
813 result = kzalloc(sizeof(*result), GFP_KERNEL);
814 if (!result)
815 return ERR_PTR(-ENOMEM);
816
817 result->def = -1;
818 result->defmgmt = -1;
819
820 nla_for_each_nested(key, keys, rem) {
821 memset(&parse, 0, sizeof(parse));
822 parse.idx = -1;
823
824 err = nl80211_parse_key_new(key, &parse);
825 if (err)
826 goto error;
827 err = -EINVAL;
828 if (!parse.p.key)
829 goto error;
830 if (parse.idx < 0 || parse.idx > 4)
831 goto error;
832 if (parse.def) {
833 if (def)
834 goto error;
835 def = 1;
836 result->def = parse.idx;
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100837 if (!parse.def_uni || !parse.def_multi)
838 goto error;
Johannes Bergfffd0932009-07-08 14:22:54 +0200839 } else if (parse.defmgmt)
840 goto error;
841 err = cfg80211_validate_key_settings(rdev, &parse.p,
Johannes Berge31b8212010-10-05 19:39:30 +0200842 parse.idx, false, NULL);
Johannes Bergfffd0932009-07-08 14:22:54 +0200843 if (err)
844 goto error;
845 result->params[parse.idx].cipher = parse.p.cipher;
846 result->params[parse.idx].key_len = parse.p.key_len;
847 result->params[parse.idx].key = result->data[parse.idx];
848 memcpy(result->data[parse.idx], parse.p.key, parse.p.key_len);
Sujith Manoharande7044e2012-10-18 10:19:28 +0530849
850 if (parse.p.cipher == WLAN_CIPHER_SUITE_WEP40 ||
851 parse.p.cipher == WLAN_CIPHER_SUITE_WEP104) {
852 if (no_ht)
853 *no_ht = true;
854 }
Johannes Bergfffd0932009-07-08 14:22:54 +0200855 }
856
857 return result;
858 error:
859 kfree(result);
860 return ERR_PTR(err);
861}
862
863static int nl80211_key_allowed(struct wireless_dev *wdev)
864{
865 ASSERT_WDEV_LOCK(wdev);
866
Johannes Bergfffd0932009-07-08 14:22:54 +0200867 switch (wdev->iftype) {
868 case NL80211_IFTYPE_AP:
869 case NL80211_IFTYPE_AP_VLAN:
Johannes Berg074ac8d2010-09-16 14:58:22 +0200870 case NL80211_IFTYPE_P2P_GO:
Thomas Pedersenff973af2011-05-03 16:57:12 -0700871 case NL80211_IFTYPE_MESH_POINT:
Johannes Bergfffd0932009-07-08 14:22:54 +0200872 break;
873 case NL80211_IFTYPE_ADHOC:
Johannes Bergfffd0932009-07-08 14:22:54 +0200874 case NL80211_IFTYPE_STATION:
Johannes Berg074ac8d2010-09-16 14:58:22 +0200875 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Bergceca7b72013-05-16 00:55:45 +0200876 if (!wdev->current_bss)
Johannes Bergfffd0932009-07-08 14:22:54 +0200877 return -ENOLINK;
878 break;
879 default:
880 return -EINVAL;
881 }
882
883 return 0;
884}
885
Jouni Malinen664834d2014-01-15 00:01:44 +0200886static struct ieee80211_channel *nl80211_get_valid_chan(struct wiphy *wiphy,
887 struct nlattr *tb)
888{
889 struct ieee80211_channel *chan;
890
891 if (tb == NULL)
892 return NULL;
893 chan = ieee80211_get_channel(wiphy, nla_get_u32(tb));
894 if (!chan || chan->flags & IEEE80211_CHAN_DISABLED)
895 return NULL;
896 return chan;
897}
898
Johannes Berg7527a782011-05-13 10:58:57 +0200899static int nl80211_put_iftypes(struct sk_buff *msg, u32 attr, u16 ifmodes)
900{
901 struct nlattr *nl_modes = nla_nest_start(msg, attr);
902 int i;
903
904 if (!nl_modes)
905 goto nla_put_failure;
906
907 i = 0;
908 while (ifmodes) {
David S. Miller9360ffd2012-03-29 04:41:26 -0400909 if ((ifmodes & 1) && nla_put_flag(msg, i))
910 goto nla_put_failure;
Johannes Berg7527a782011-05-13 10:58:57 +0200911 ifmodes >>= 1;
912 i++;
913 }
914
915 nla_nest_end(msg, nl_modes);
916 return 0;
917
918nla_put_failure:
919 return -ENOBUFS;
920}
921
922static int nl80211_put_iface_combinations(struct wiphy *wiphy,
Johannes Bergcdc89b92013-02-18 23:54:36 +0100923 struct sk_buff *msg,
924 bool large)
Johannes Berg7527a782011-05-13 10:58:57 +0200925{
926 struct nlattr *nl_combis;
927 int i, j;
928
929 nl_combis = nla_nest_start(msg,
930 NL80211_ATTR_INTERFACE_COMBINATIONS);
931 if (!nl_combis)
932 goto nla_put_failure;
933
934 for (i = 0; i < wiphy->n_iface_combinations; i++) {
935 const struct ieee80211_iface_combination *c;
936 struct nlattr *nl_combi, *nl_limits;
937
938 c = &wiphy->iface_combinations[i];
939
940 nl_combi = nla_nest_start(msg, i + 1);
941 if (!nl_combi)
942 goto nla_put_failure;
943
944 nl_limits = nla_nest_start(msg, NL80211_IFACE_COMB_LIMITS);
945 if (!nl_limits)
946 goto nla_put_failure;
947
948 for (j = 0; j < c->n_limits; j++) {
949 struct nlattr *nl_limit;
950
951 nl_limit = nla_nest_start(msg, j + 1);
952 if (!nl_limit)
953 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -0400954 if (nla_put_u32(msg, NL80211_IFACE_LIMIT_MAX,
955 c->limits[j].max))
956 goto nla_put_failure;
Johannes Berg7527a782011-05-13 10:58:57 +0200957 if (nl80211_put_iftypes(msg, NL80211_IFACE_LIMIT_TYPES,
958 c->limits[j].types))
959 goto nla_put_failure;
960 nla_nest_end(msg, nl_limit);
961 }
962
963 nla_nest_end(msg, nl_limits);
964
David S. Miller9360ffd2012-03-29 04:41:26 -0400965 if (c->beacon_int_infra_match &&
966 nla_put_flag(msg, NL80211_IFACE_COMB_STA_AP_BI_MATCH))
967 goto nla_put_failure;
968 if (nla_put_u32(msg, NL80211_IFACE_COMB_NUM_CHANNELS,
969 c->num_different_channels) ||
970 nla_put_u32(msg, NL80211_IFACE_COMB_MAXNUM,
971 c->max_interfaces))
972 goto nla_put_failure;
Johannes Bergcdc89b92013-02-18 23:54:36 +0100973 if (large &&
Felix Fietkau8c48b502014-05-05 11:48:40 +0200974 (nla_put_u32(msg, NL80211_IFACE_COMB_RADAR_DETECT_WIDTHS,
975 c->radar_detect_widths) ||
976 nla_put_u32(msg, NL80211_IFACE_COMB_RADAR_DETECT_REGIONS,
977 c->radar_detect_regions)))
Johannes Bergcdc89b92013-02-18 23:54:36 +0100978 goto nla_put_failure;
Johannes Berg7527a782011-05-13 10:58:57 +0200979
980 nla_nest_end(msg, nl_combi);
981 }
982
983 nla_nest_end(msg, nl_combis);
984
985 return 0;
986nla_put_failure:
987 return -ENOBUFS;
988}
989
Johannes Berg3713b4e2013-02-14 16:19:38 +0100990#ifdef CONFIG_PM
Johannes Bergb56cf722013-02-20 01:02:38 +0100991static int nl80211_send_wowlan_tcp_caps(struct cfg80211_registered_device *rdev,
992 struct sk_buff *msg)
993{
Johannes Berg964dc9e2013-06-03 17:25:34 +0200994 const struct wiphy_wowlan_tcp_support *tcp = rdev->wiphy.wowlan->tcp;
Johannes Bergb56cf722013-02-20 01:02:38 +0100995 struct nlattr *nl_tcp;
996
997 if (!tcp)
998 return 0;
999
1000 nl_tcp = nla_nest_start(msg, NL80211_WOWLAN_TRIG_TCP_CONNECTION);
1001 if (!nl_tcp)
1002 return -ENOBUFS;
1003
1004 if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD,
1005 tcp->data_payload_max))
1006 return -ENOBUFS;
1007
1008 if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD,
1009 tcp->data_payload_max))
1010 return -ENOBUFS;
1011
1012 if (tcp->seq && nla_put_flag(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ))
1013 return -ENOBUFS;
1014
1015 if (tcp->tok && nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN,
1016 sizeof(*tcp->tok), tcp->tok))
1017 return -ENOBUFS;
1018
1019 if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_INTERVAL,
1020 tcp->data_interval_max))
1021 return -ENOBUFS;
1022
1023 if (nla_put_u32(msg, NL80211_WOWLAN_TCP_WAKE_PAYLOAD,
1024 tcp->wake_payload_max))
1025 return -ENOBUFS;
1026
1027 nla_nest_end(msg, nl_tcp);
1028 return 0;
1029}
1030
Johannes Berg3713b4e2013-02-14 16:19:38 +01001031static int nl80211_send_wowlan(struct sk_buff *msg,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001032 struct cfg80211_registered_device *rdev,
Johannes Bergb56cf722013-02-20 01:02:38 +01001033 bool large)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001034{
1035 struct nlattr *nl_wowlan;
1036
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001037 if (!rdev->wiphy.wowlan)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001038 return 0;
1039
1040 nl_wowlan = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS_SUPPORTED);
1041 if (!nl_wowlan)
1042 return -ENOBUFS;
1043
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001044 if (((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_ANY) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001045 nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) ||
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001046 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_DISCONNECT) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001047 nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) ||
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001048 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001049 nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) ||
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001050 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_SUPPORTS_GTK_REKEY) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001051 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED)) ||
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001052 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001053 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) ||
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001054 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001055 nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) ||
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001056 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001057 nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) ||
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001058 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001059 nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE)))
1060 return -ENOBUFS;
1061
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001062 if (rdev->wiphy.wowlan->n_patterns) {
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07001063 struct nl80211_pattern_support pat = {
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001064 .max_patterns = rdev->wiphy.wowlan->n_patterns,
1065 .min_pattern_len = rdev->wiphy.wowlan->pattern_min_len,
1066 .max_pattern_len = rdev->wiphy.wowlan->pattern_max_len,
1067 .max_pkt_offset = rdev->wiphy.wowlan->max_pkt_offset,
Johannes Berg3713b4e2013-02-14 16:19:38 +01001068 };
1069
1070 if (nla_put(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN,
1071 sizeof(pat), &pat))
1072 return -ENOBUFS;
1073 }
1074
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001075 if (large && nl80211_send_wowlan_tcp_caps(rdev, msg))
Johannes Bergb56cf722013-02-20 01:02:38 +01001076 return -ENOBUFS;
1077
Johannes Berg3713b4e2013-02-14 16:19:38 +01001078 nla_nest_end(msg, nl_wowlan);
1079
1080 return 0;
1081}
1082#endif
1083
Amitkumar Karwarbe29b992013-06-28 11:51:26 -07001084static int nl80211_send_coalesce(struct sk_buff *msg,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001085 struct cfg80211_registered_device *rdev)
Amitkumar Karwarbe29b992013-06-28 11:51:26 -07001086{
1087 struct nl80211_coalesce_rule_support rule;
1088
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001089 if (!rdev->wiphy.coalesce)
Amitkumar Karwarbe29b992013-06-28 11:51:26 -07001090 return 0;
1091
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001092 rule.max_rules = rdev->wiphy.coalesce->n_rules;
1093 rule.max_delay = rdev->wiphy.coalesce->max_delay;
1094 rule.pat.max_patterns = rdev->wiphy.coalesce->n_patterns;
1095 rule.pat.min_pattern_len = rdev->wiphy.coalesce->pattern_min_len;
1096 rule.pat.max_pattern_len = rdev->wiphy.coalesce->pattern_max_len;
1097 rule.pat.max_pkt_offset = rdev->wiphy.coalesce->max_pkt_offset;
Amitkumar Karwarbe29b992013-06-28 11:51:26 -07001098
1099 if (nla_put(msg, NL80211_ATTR_COALESCE_RULE, sizeof(rule), &rule))
1100 return -ENOBUFS;
1101
1102 return 0;
1103}
1104
Johannes Berg3713b4e2013-02-14 16:19:38 +01001105static int nl80211_send_band_rateinfo(struct sk_buff *msg,
1106 struct ieee80211_supported_band *sband)
1107{
1108 struct nlattr *nl_rates, *nl_rate;
1109 struct ieee80211_rate *rate;
1110 int i;
1111
1112 /* add HT info */
1113 if (sband->ht_cap.ht_supported &&
1114 (nla_put(msg, NL80211_BAND_ATTR_HT_MCS_SET,
1115 sizeof(sband->ht_cap.mcs),
1116 &sband->ht_cap.mcs) ||
1117 nla_put_u16(msg, NL80211_BAND_ATTR_HT_CAPA,
1118 sband->ht_cap.cap) ||
1119 nla_put_u8(msg, NL80211_BAND_ATTR_HT_AMPDU_FACTOR,
1120 sband->ht_cap.ampdu_factor) ||
1121 nla_put_u8(msg, NL80211_BAND_ATTR_HT_AMPDU_DENSITY,
1122 sband->ht_cap.ampdu_density)))
1123 return -ENOBUFS;
1124
1125 /* add VHT info */
1126 if (sband->vht_cap.vht_supported &&
1127 (nla_put(msg, NL80211_BAND_ATTR_VHT_MCS_SET,
1128 sizeof(sband->vht_cap.vht_mcs),
1129 &sband->vht_cap.vht_mcs) ||
1130 nla_put_u32(msg, NL80211_BAND_ATTR_VHT_CAPA,
1131 sband->vht_cap.cap)))
1132 return -ENOBUFS;
1133
1134 /* add bitrates */
1135 nl_rates = nla_nest_start(msg, NL80211_BAND_ATTR_RATES);
1136 if (!nl_rates)
1137 return -ENOBUFS;
1138
1139 for (i = 0; i < sband->n_bitrates; i++) {
1140 nl_rate = nla_nest_start(msg, i);
1141 if (!nl_rate)
1142 return -ENOBUFS;
1143
1144 rate = &sband->bitrates[i];
1145 if (nla_put_u32(msg, NL80211_BITRATE_ATTR_RATE,
1146 rate->bitrate))
1147 return -ENOBUFS;
1148 if ((rate->flags & IEEE80211_RATE_SHORT_PREAMBLE) &&
1149 nla_put_flag(msg,
1150 NL80211_BITRATE_ATTR_2GHZ_SHORTPREAMBLE))
1151 return -ENOBUFS;
1152
1153 nla_nest_end(msg, nl_rate);
1154 }
1155
1156 nla_nest_end(msg, nl_rates);
1157
1158 return 0;
1159}
1160
1161static int
1162nl80211_send_mgmt_stypes(struct sk_buff *msg,
1163 const struct ieee80211_txrx_stypes *mgmt_stypes)
1164{
1165 u16 stypes;
1166 struct nlattr *nl_ftypes, *nl_ifs;
1167 enum nl80211_iftype ift;
1168 int i;
1169
1170 if (!mgmt_stypes)
1171 return 0;
1172
1173 nl_ifs = nla_nest_start(msg, NL80211_ATTR_TX_FRAME_TYPES);
1174 if (!nl_ifs)
1175 return -ENOBUFS;
1176
1177 for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) {
1178 nl_ftypes = nla_nest_start(msg, ift);
1179 if (!nl_ftypes)
1180 return -ENOBUFS;
1181 i = 0;
1182 stypes = mgmt_stypes[ift].tx;
1183 while (stypes) {
1184 if ((stypes & 1) &&
1185 nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE,
1186 (i << 4) | IEEE80211_FTYPE_MGMT))
1187 return -ENOBUFS;
1188 stypes >>= 1;
1189 i++;
1190 }
1191 nla_nest_end(msg, nl_ftypes);
1192 }
1193
1194 nla_nest_end(msg, nl_ifs);
1195
1196 nl_ifs = nla_nest_start(msg, NL80211_ATTR_RX_FRAME_TYPES);
1197 if (!nl_ifs)
1198 return -ENOBUFS;
1199
1200 for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) {
1201 nl_ftypes = nla_nest_start(msg, ift);
1202 if (!nl_ftypes)
1203 return -ENOBUFS;
1204 i = 0;
1205 stypes = mgmt_stypes[ift].rx;
1206 while (stypes) {
1207 if ((stypes & 1) &&
1208 nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE,
1209 (i << 4) | IEEE80211_FTYPE_MGMT))
1210 return -ENOBUFS;
1211 stypes >>= 1;
1212 i++;
1213 }
1214 nla_nest_end(msg, nl_ftypes);
1215 }
1216 nla_nest_end(msg, nl_ifs);
1217
1218 return 0;
1219}
1220
Johannes Berg86e8cf92013-06-19 10:57:22 +02001221struct nl80211_dump_wiphy_state {
1222 s64 filter_wiphy;
1223 long start;
1224 long split_start, band_start, chan_start;
1225 bool split;
1226};
1227
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001228static int nl80211_send_wiphy(struct cfg80211_registered_device *rdev,
Johannes Berg3bb20552014-05-26 13:52:25 +02001229 enum nl80211_commands cmd,
Johannes Berg3713b4e2013-02-14 16:19:38 +01001230 struct sk_buff *msg, u32 portid, u32 seq,
Johannes Berg86e8cf92013-06-19 10:57:22 +02001231 int flags, struct nl80211_dump_wiphy_state *state)
Johannes Berg55682962007-09-20 13:09:35 -04001232{
1233 void *hdr;
Johannes Bergee688b002008-01-24 19:38:39 +01001234 struct nlattr *nl_bands, *nl_band;
1235 struct nlattr *nl_freqs, *nl_freq;
Johannes Berg8fdc6212009-03-14 09:34:01 +01001236 struct nlattr *nl_cmds;
Johannes Bergee688b002008-01-24 19:38:39 +01001237 enum ieee80211_band band;
1238 struct ieee80211_channel *chan;
Johannes Bergee688b002008-01-24 19:38:39 +01001239 int i;
Johannes Berg2e161f72010-08-12 15:38:38 +02001240 const struct ieee80211_txrx_stypes *mgmt_stypes =
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001241 rdev->wiphy.mgmt_stypes;
Johannes Bergfe1abaf2013-02-27 15:39:45 +01001242 u32 features;
Johannes Berg55682962007-09-20 13:09:35 -04001243
Johannes Berg3bb20552014-05-26 13:52:25 +02001244 hdr = nl80211hdr_put(msg, portid, seq, flags, cmd);
Johannes Berg55682962007-09-20 13:09:35 -04001245 if (!hdr)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001246 return -ENOBUFS;
1247
Johannes Berg86e8cf92013-06-19 10:57:22 +02001248 if (WARN_ON(!state))
1249 return -EINVAL;
Johannes Berg55682962007-09-20 13:09:35 -04001250
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001251 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001252 nla_put_string(msg, NL80211_ATTR_WIPHY_NAME,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001253 wiphy_name(&rdev->wiphy)) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04001254 nla_put_u32(msg, NL80211_ATTR_GENERATION,
Johannes Berg3713b4e2013-02-14 16:19:38 +01001255 cfg80211_rdev_list_generation))
David S. Miller9360ffd2012-03-29 04:41:26 -04001256 goto nla_put_failure;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02001257
Johannes Berg3bb20552014-05-26 13:52:25 +02001258 if (cmd != NL80211_CMD_NEW_WIPHY)
1259 goto finish;
1260
Johannes Berg86e8cf92013-06-19 10:57:22 +02001261 switch (state->split_start) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001262 case 0:
1263 if (nla_put_u8(msg, NL80211_ATTR_WIPHY_RETRY_SHORT,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001264 rdev->wiphy.retry_short) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001265 nla_put_u8(msg, NL80211_ATTR_WIPHY_RETRY_LONG,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001266 rdev->wiphy.retry_long) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001267 nla_put_u32(msg, NL80211_ATTR_WIPHY_FRAG_THRESHOLD,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001268 rdev->wiphy.frag_threshold) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001269 nla_put_u32(msg, NL80211_ATTR_WIPHY_RTS_THRESHOLD,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001270 rdev->wiphy.rts_threshold) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001271 nla_put_u8(msg, NL80211_ATTR_WIPHY_COVERAGE_CLASS,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001272 rdev->wiphy.coverage_class) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001273 nla_put_u8(msg, NL80211_ATTR_MAX_NUM_SCAN_SSIDS,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001274 rdev->wiphy.max_scan_ssids) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001275 nla_put_u8(msg, NL80211_ATTR_MAX_NUM_SCHED_SCAN_SSIDS,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001276 rdev->wiphy.max_sched_scan_ssids) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001277 nla_put_u16(msg, NL80211_ATTR_MAX_SCAN_IE_LEN,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001278 rdev->wiphy.max_scan_ie_len) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001279 nla_put_u16(msg, NL80211_ATTR_MAX_SCHED_SCAN_IE_LEN,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001280 rdev->wiphy.max_sched_scan_ie_len) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001281 nla_put_u8(msg, NL80211_ATTR_MAX_MATCH_SETS,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001282 rdev->wiphy.max_match_sets))
Johannes Bergee688b002008-01-24 19:38:39 +01001283 goto nla_put_failure;
1284
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001285 if ((rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001286 nla_put_flag(msg, NL80211_ATTR_SUPPORT_IBSS_RSN))
1287 goto nla_put_failure;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001288 if ((rdev->wiphy.flags & WIPHY_FLAG_MESH_AUTH) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001289 nla_put_flag(msg, NL80211_ATTR_SUPPORT_MESH_AUTH))
1290 goto nla_put_failure;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001291 if ((rdev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001292 nla_put_flag(msg, NL80211_ATTR_SUPPORT_AP_UAPSD))
1293 goto nla_put_failure;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001294 if ((rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_FW_ROAM) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001295 nla_put_flag(msg, NL80211_ATTR_ROAM_SUPPORT))
1296 goto nla_put_failure;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001297 if ((rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001298 nla_put_flag(msg, NL80211_ATTR_TDLS_SUPPORT))
1299 goto nla_put_failure;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001300 if ((rdev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001301 nla_put_flag(msg, NL80211_ATTR_TDLS_EXTERNAL_SETUP))
David S. Miller9360ffd2012-03-29 04:41:26 -04001302 goto nla_put_failure;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001303 state->split_start++;
1304 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001305 break;
1306 case 1:
1307 if (nla_put(msg, NL80211_ATTR_CIPHER_SUITES,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001308 sizeof(u32) * rdev->wiphy.n_cipher_suites,
1309 rdev->wiphy.cipher_suites))
Mahesh Palivelabf0c111e2012-06-22 07:27:46 +00001310 goto nla_put_failure;
1311
Johannes Berg3713b4e2013-02-14 16:19:38 +01001312 if (nla_put_u8(msg, NL80211_ATTR_MAX_NUM_PMKIDS,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001313 rdev->wiphy.max_num_pmkids))
Johannes Bergee688b002008-01-24 19:38:39 +01001314 goto nla_put_failure;
1315
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001316 if ((rdev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001317 nla_put_flag(msg, NL80211_ATTR_CONTROL_PORT_ETHERTYPE))
1318 goto nla_put_failure;
Johannes Bergee688b002008-01-24 19:38:39 +01001319
Johannes Berg3713b4e2013-02-14 16:19:38 +01001320 if (nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_TX,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001321 rdev->wiphy.available_antennas_tx) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001322 nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_RX,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001323 rdev->wiphy.available_antennas_rx))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001324 goto nla_put_failure;
Johannes Bergee688b002008-01-24 19:38:39 +01001325
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001326 if ((rdev->wiphy.flags & WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001327 nla_put_u32(msg, NL80211_ATTR_PROBE_RESP_OFFLOAD,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001328 rdev->wiphy.probe_resp_offload))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001329 goto nla_put_failure;
Jouni Malinene2f367f262008-11-21 19:01:30 +02001330
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001331 if ((rdev->wiphy.available_antennas_tx ||
1332 rdev->wiphy.available_antennas_rx) &&
1333 rdev->ops->get_antenna) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001334 u32 tx_ant = 0, rx_ant = 0;
1335 int res;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001336 res = rdev_get_antenna(rdev, &tx_ant, &rx_ant);
Johannes Berg3713b4e2013-02-14 16:19:38 +01001337 if (!res) {
1338 if (nla_put_u32(msg,
1339 NL80211_ATTR_WIPHY_ANTENNA_TX,
1340 tx_ant) ||
1341 nla_put_u32(msg,
1342 NL80211_ATTR_WIPHY_ANTENNA_RX,
1343 rx_ant))
1344 goto nla_put_failure;
1345 }
Johannes Bergee688b002008-01-24 19:38:39 +01001346 }
1347
Johannes Berg86e8cf92013-06-19 10:57:22 +02001348 state->split_start++;
1349 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001350 break;
1351 case 2:
1352 if (nl80211_put_iftypes(msg, NL80211_ATTR_SUPPORTED_IFTYPES,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001353 rdev->wiphy.interface_modes))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001354 goto nla_put_failure;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001355 state->split_start++;
1356 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001357 break;
1358 case 3:
1359 nl_bands = nla_nest_start(msg, NL80211_ATTR_WIPHY_BANDS);
1360 if (!nl_bands)
Johannes Bergee688b002008-01-24 19:38:39 +01001361 goto nla_put_failure;
1362
Johannes Berg86e8cf92013-06-19 10:57:22 +02001363 for (band = state->band_start;
1364 band < IEEE80211_NUM_BANDS; band++) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001365 struct ieee80211_supported_band *sband;
1366
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001367 sband = rdev->wiphy.bands[band];
Johannes Berg3713b4e2013-02-14 16:19:38 +01001368
1369 if (!sband)
1370 continue;
1371
1372 nl_band = nla_nest_start(msg, band);
1373 if (!nl_band)
Johannes Bergee688b002008-01-24 19:38:39 +01001374 goto nla_put_failure;
1375
Johannes Berg86e8cf92013-06-19 10:57:22 +02001376 switch (state->chan_start) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001377 case 0:
1378 if (nl80211_send_band_rateinfo(msg, sband))
1379 goto nla_put_failure;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001380 state->chan_start++;
1381 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001382 break;
1383 default:
1384 /* add frequencies */
1385 nl_freqs = nla_nest_start(
1386 msg, NL80211_BAND_ATTR_FREQS);
1387 if (!nl_freqs)
1388 goto nla_put_failure;
Johannes Bergee688b002008-01-24 19:38:39 +01001389
Johannes Berg86e8cf92013-06-19 10:57:22 +02001390 for (i = state->chan_start - 1;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001391 i < sband->n_channels;
1392 i++) {
1393 nl_freq = nla_nest_start(msg, i);
1394 if (!nl_freq)
1395 goto nla_put_failure;
1396
1397 chan = &sband->channels[i];
1398
Johannes Berg86e8cf92013-06-19 10:57:22 +02001399 if (nl80211_msg_put_channel(
1400 msg, chan,
1401 state->split))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001402 goto nla_put_failure;
1403
1404 nla_nest_end(msg, nl_freq);
Johannes Berg86e8cf92013-06-19 10:57:22 +02001405 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001406 break;
1407 }
1408 if (i < sband->n_channels)
Johannes Berg86e8cf92013-06-19 10:57:22 +02001409 state->chan_start = i + 2;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001410 else
Johannes Berg86e8cf92013-06-19 10:57:22 +02001411 state->chan_start = 0;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001412 nla_nest_end(msg, nl_freqs);
1413 }
1414
1415 nla_nest_end(msg, nl_band);
1416
Johannes Berg86e8cf92013-06-19 10:57:22 +02001417 if (state->split) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001418 /* start again here */
Johannes Berg86e8cf92013-06-19 10:57:22 +02001419 if (state->chan_start)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001420 band--;
1421 break;
1422 }
Johannes Bergee688b002008-01-24 19:38:39 +01001423 }
Johannes Berg3713b4e2013-02-14 16:19:38 +01001424 nla_nest_end(msg, nl_bands);
Johannes Bergee688b002008-01-24 19:38:39 +01001425
Johannes Berg3713b4e2013-02-14 16:19:38 +01001426 if (band < IEEE80211_NUM_BANDS)
Johannes Berg86e8cf92013-06-19 10:57:22 +02001427 state->band_start = band + 1;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001428 else
Johannes Berg86e8cf92013-06-19 10:57:22 +02001429 state->band_start = 0;
Johannes Bergee688b002008-01-24 19:38:39 +01001430
Johannes Berg3713b4e2013-02-14 16:19:38 +01001431 /* if bands & channels are done, continue outside */
Johannes Berg86e8cf92013-06-19 10:57:22 +02001432 if (state->band_start == 0 && state->chan_start == 0)
1433 state->split_start++;
1434 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001435 break;
1436 case 4:
1437 nl_cmds = nla_nest_start(msg, NL80211_ATTR_SUPPORTED_COMMANDS);
1438 if (!nl_cmds)
David S. Miller9360ffd2012-03-29 04:41:26 -04001439 goto nla_put_failure;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001440
1441 i = 0;
1442#define CMD(op, n) \
1443 do { \
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001444 if (rdev->ops->op) { \
Johannes Berg3713b4e2013-02-14 16:19:38 +01001445 i++; \
1446 if (nla_put_u32(msg, i, NL80211_CMD_ ## n)) \
1447 goto nla_put_failure; \
1448 } \
1449 } while (0)
1450
1451 CMD(add_virtual_intf, NEW_INTERFACE);
1452 CMD(change_virtual_intf, SET_INTERFACE);
1453 CMD(add_key, NEW_KEY);
1454 CMD(start_ap, START_AP);
1455 CMD(add_station, NEW_STATION);
1456 CMD(add_mpath, NEW_MPATH);
1457 CMD(update_mesh_config, SET_MESH_CONFIG);
1458 CMD(change_bss, SET_BSS);
1459 CMD(auth, AUTHENTICATE);
1460 CMD(assoc, ASSOCIATE);
1461 CMD(deauth, DEAUTHENTICATE);
1462 CMD(disassoc, DISASSOCIATE);
1463 CMD(join_ibss, JOIN_IBSS);
1464 CMD(join_mesh, JOIN_MESH);
1465 CMD(set_pmksa, SET_PMKSA);
1466 CMD(del_pmksa, DEL_PMKSA);
1467 CMD(flush_pmksa, FLUSH_PMKSA);
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001468 if (rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001469 CMD(remain_on_channel, REMAIN_ON_CHANNEL);
1470 CMD(set_bitrate_mask, SET_TX_BITRATE_MASK);
1471 CMD(mgmt_tx, FRAME);
1472 CMD(mgmt_tx_cancel_wait, FRAME_WAIT_CANCEL);
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001473 if (rdev->wiphy.flags & WIPHY_FLAG_NETNS_OK) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001474 i++;
1475 if (nla_put_u32(msg, i, NL80211_CMD_SET_WIPHY_NETNS))
1476 goto nla_put_failure;
1477 }
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001478 if (rdev->ops->set_monitor_channel || rdev->ops->start_ap ||
1479 rdev->ops->join_mesh) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001480 i++;
1481 if (nla_put_u32(msg, i, NL80211_CMD_SET_CHANNEL))
1482 goto nla_put_failure;
1483 }
1484 CMD(set_wds_peer, SET_WDS_PEER);
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001485 if (rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001486 CMD(tdls_mgmt, TDLS_MGMT);
1487 CMD(tdls_oper, TDLS_OPER);
1488 }
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001489 if (rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001490 CMD(sched_scan_start, START_SCHED_SCAN);
1491 CMD(probe_client, PROBE_CLIENT);
1492 CMD(set_noack_map, SET_NOACK_MAP);
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001493 if (rdev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001494 i++;
1495 if (nla_put_u32(msg, i, NL80211_CMD_REGISTER_BEACONS))
1496 goto nla_put_failure;
1497 }
1498 CMD(start_p2p_device, START_P2P_DEVICE);
1499 CMD(set_mcast_rate, SET_MCAST_RATE);
Johannes Berg02df00e2014-06-10 14:06:25 +02001500#ifdef CONFIG_NL80211_TESTMODE
1501 CMD(testmode_cmd, TESTMODE);
1502#endif
Johannes Berg86e8cf92013-06-19 10:57:22 +02001503 if (state->split) {
Arend van Spriel5de17982013-04-18 15:49:00 +02001504 CMD(crit_proto_start, CRIT_PROTOCOL_START);
1505 CMD(crit_proto_stop, CRIT_PROTOCOL_STOP);
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001506 if (rdev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH)
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02001507 CMD(channel_switch, CHANNEL_SWITCH);
Johannes Berg02df00e2014-06-10 14:06:25 +02001508 CMD(set_qos_map, SET_QOS_MAP);
Arend van Spriel5de17982013-04-18 15:49:00 +02001509 }
Johannes Berg02df00e2014-06-10 14:06:25 +02001510 /* add into the if now */
Johannes Berg8fdc6212009-03-14 09:34:01 +01001511#undef CMD
Samuel Ortizb23aa672009-07-01 21:26:54 +02001512
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001513 if (rdev->ops->connect || rdev->ops->auth) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001514 i++;
1515 if (nla_put_u32(msg, i, NL80211_CMD_CONNECT))
Johannes Berg2e161f72010-08-12 15:38:38 +02001516 goto nla_put_failure;
Johannes Berg2e161f72010-08-12 15:38:38 +02001517 }
1518
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001519 if (rdev->ops->disconnect || rdev->ops->deauth) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001520 i++;
1521 if (nla_put_u32(msg, i, NL80211_CMD_DISCONNECT))
1522 goto nla_put_failure;
1523 }
Johannes Berg74b70a42010-08-24 12:15:53 +02001524
Johannes Berg3713b4e2013-02-14 16:19:38 +01001525 nla_nest_end(msg, nl_cmds);
Johannes Berg86e8cf92013-06-19 10:57:22 +02001526 state->split_start++;
1527 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001528 break;
1529 case 5:
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001530 if (rdev->ops->remain_on_channel &&
1531 (rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001532 nla_put_u32(msg,
1533 NL80211_ATTR_MAX_REMAIN_ON_CHANNEL_DURATION,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001534 rdev->wiphy.max_remain_on_channel_duration))
Johannes Berg2e161f72010-08-12 15:38:38 +02001535 goto nla_put_failure;
1536
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001537 if ((rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001538 nla_put_flag(msg, NL80211_ATTR_OFFCHANNEL_TX_OK))
1539 goto nla_put_failure;
Johannes Berg2e161f72010-08-12 15:38:38 +02001540
Johannes Berg3713b4e2013-02-14 16:19:38 +01001541 if (nl80211_send_mgmt_stypes(msg, mgmt_stypes))
1542 goto nla_put_failure;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001543 state->split_start++;
1544 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001545 break;
1546 case 6:
Johannes Bergdfb89c52012-06-27 09:23:48 +02001547#ifdef CONFIG_PM
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001548 if (nl80211_send_wowlan(msg, rdev, state->split))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001549 goto nla_put_failure;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001550 state->split_start++;
1551 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001552 break;
1553#else
Johannes Berg86e8cf92013-06-19 10:57:22 +02001554 state->split_start++;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001555#endif
1556 case 7:
1557 if (nl80211_put_iftypes(msg, NL80211_ATTR_SOFTWARE_IFTYPES,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001558 rdev->wiphy.software_iftypes))
Johannes Bergff1b6e62011-05-04 15:37:28 +02001559 goto nla_put_failure;
1560
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001561 if (nl80211_put_iface_combinations(&rdev->wiphy, msg,
Johannes Berg86e8cf92013-06-19 10:57:22 +02001562 state->split))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001563 goto nla_put_failure;
Johannes Bergff1b6e62011-05-04 15:37:28 +02001564
Johannes Berg86e8cf92013-06-19 10:57:22 +02001565 state->split_start++;
1566 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001567 break;
1568 case 8:
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001569 if ((rdev->wiphy.flags & WIPHY_FLAG_HAVE_AP_SME) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001570 nla_put_u32(msg, NL80211_ATTR_DEVICE_AP_SME,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001571 rdev->wiphy.ap_sme_capa))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001572 goto nla_put_failure;
1573
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001574 features = rdev->wiphy.features;
Johannes Bergfe1abaf2013-02-27 15:39:45 +01001575 /*
1576 * We can only add the per-channel limit information if the
1577 * dump is split, otherwise it makes it too big. Therefore
1578 * only advertise it in that case.
1579 */
Johannes Berg86e8cf92013-06-19 10:57:22 +02001580 if (state->split)
Johannes Bergfe1abaf2013-02-27 15:39:45 +01001581 features |= NL80211_FEATURE_ADVERTISE_CHAN_LIMITS;
1582 if (nla_put_u32(msg, NL80211_ATTR_FEATURE_FLAGS, features))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001583 goto nla_put_failure;
1584
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001585 if (rdev->wiphy.ht_capa_mod_mask &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001586 nla_put(msg, NL80211_ATTR_HT_CAPABILITY_MASK,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001587 sizeof(*rdev->wiphy.ht_capa_mod_mask),
1588 rdev->wiphy.ht_capa_mod_mask))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001589 goto nla_put_failure;
1590
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001591 if (rdev->wiphy.flags & WIPHY_FLAG_HAVE_AP_SME &&
1592 rdev->wiphy.max_acl_mac_addrs &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001593 nla_put_u32(msg, NL80211_ATTR_MAC_ACL_MAX,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001594 rdev->wiphy.max_acl_mac_addrs))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001595 goto nla_put_failure;
1596
1597 /*
1598 * Any information below this point is only available to
1599 * applications that can deal with it being split. This
1600 * helps ensure that newly added capabilities don't break
1601 * older tools by overrunning their buffers.
1602 *
1603 * We still increment split_start so that in the split
1604 * case we'll continue with more data in the next round,
1605 * but break unconditionally so unsplit data stops here.
1606 */
Johannes Berg86e8cf92013-06-19 10:57:22 +02001607 state->split_start++;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001608 break;
1609 case 9:
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001610 if (rdev->wiphy.extended_capabilities &&
Johannes Bergfe1abaf2013-02-27 15:39:45 +01001611 (nla_put(msg, NL80211_ATTR_EXT_CAPA,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001612 rdev->wiphy.extended_capabilities_len,
1613 rdev->wiphy.extended_capabilities) ||
Johannes Bergfe1abaf2013-02-27 15:39:45 +01001614 nla_put(msg, NL80211_ATTR_EXT_CAPA_MASK,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001615 rdev->wiphy.extended_capabilities_len,
1616 rdev->wiphy.extended_capabilities_mask)))
Johannes Bergfe1abaf2013-02-27 15:39:45 +01001617 goto nla_put_failure;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001618
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001619 if (rdev->wiphy.vht_capa_mod_mask &&
Johannes Bergee2aca32013-02-21 17:36:01 +01001620 nla_put(msg, NL80211_ATTR_VHT_CAPABILITY_MASK,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001621 sizeof(*rdev->wiphy.vht_capa_mod_mask),
1622 rdev->wiphy.vht_capa_mod_mask))
Johannes Bergee2aca32013-02-21 17:36:01 +01001623 goto nla_put_failure;
1624
Amitkumar Karwarbe29b992013-06-28 11:51:26 -07001625 state->split_start++;
1626 break;
1627 case 10:
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001628 if (nl80211_send_coalesce(msg, rdev))
Amitkumar Karwarbe29b992013-06-28 11:51:26 -07001629 goto nla_put_failure;
1630
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001631 if ((rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_5_10_MHZ) &&
Felix Fietkau01e0daa2013-11-09 14:57:54 +01001632 (nla_put_flag(msg, NL80211_ATTR_SUPPORT_5_MHZ) ||
1633 nla_put_flag(msg, NL80211_ATTR_SUPPORT_10_MHZ)))
1634 goto nla_put_failure;
Jouni Malinenb43504c2014-01-15 00:01:08 +02001635
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001636 if (rdev->wiphy.max_ap_assoc_sta &&
Jouni Malinenb43504c2014-01-15 00:01:08 +02001637 nla_put_u32(msg, NL80211_ATTR_MAX_AP_ASSOC_STA,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001638 rdev->wiphy.max_ap_assoc_sta))
Jouni Malinenb43504c2014-01-15 00:01:08 +02001639 goto nla_put_failure;
1640
Johannes Bergad7e7182013-11-13 13:37:47 +01001641 state->split_start++;
1642 break;
1643 case 11:
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001644 if (rdev->wiphy.n_vendor_commands) {
Johannes Berg567ffc32013-12-18 14:43:31 +01001645 const struct nl80211_vendor_cmd_info *info;
1646 struct nlattr *nested;
Johannes Bergad7e7182013-11-13 13:37:47 +01001647
Johannes Berg567ffc32013-12-18 14:43:31 +01001648 nested = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA);
1649 if (!nested)
Johannes Bergad7e7182013-11-13 13:37:47 +01001650 goto nla_put_failure;
Johannes Berg567ffc32013-12-18 14:43:31 +01001651
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001652 for (i = 0; i < rdev->wiphy.n_vendor_commands; i++) {
1653 info = &rdev->wiphy.vendor_commands[i].info;
Johannes Berg567ffc32013-12-18 14:43:31 +01001654 if (nla_put(msg, i + 1, sizeof(*info), info))
1655 goto nla_put_failure;
1656 }
1657 nla_nest_end(msg, nested);
1658 }
1659
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001660 if (rdev->wiphy.n_vendor_events) {
Johannes Berg567ffc32013-12-18 14:43:31 +01001661 const struct nl80211_vendor_cmd_info *info;
1662 struct nlattr *nested;
1663
1664 nested = nla_nest_start(msg,
1665 NL80211_ATTR_VENDOR_EVENTS);
1666 if (!nested)
1667 goto nla_put_failure;
1668
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001669 for (i = 0; i < rdev->wiphy.n_vendor_events; i++) {
1670 info = &rdev->wiphy.vendor_events[i];
Johannes Berg567ffc32013-12-18 14:43:31 +01001671 if (nla_put(msg, i + 1, sizeof(*info), info))
1672 goto nla_put_failure;
1673 }
1674 nla_nest_end(msg, nested);
1675 }
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03001676 state->split_start++;
1677 break;
1678 case 12:
1679 if (rdev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH &&
1680 nla_put_u8(msg, NL80211_ATTR_MAX_CSA_COUNTERS,
1681 rdev->wiphy.max_num_csa_counters))
1682 goto nla_put_failure;
Felix Fietkau01e0daa2013-11-09 14:57:54 +01001683
Johannes Berg3713b4e2013-02-14 16:19:38 +01001684 /* done */
Johannes Berg86e8cf92013-06-19 10:57:22 +02001685 state->split_start = 0;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001686 break;
Johannes Bergff1b6e62011-05-04 15:37:28 +02001687 }
Johannes Berg3bb20552014-05-26 13:52:25 +02001688 finish:
Johannes Berg55682962007-09-20 13:09:35 -04001689 return genlmsg_end(msg, hdr);
1690
1691 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07001692 genlmsg_cancel(msg, hdr);
1693 return -EMSGSIZE;
Johannes Berg55682962007-09-20 13:09:35 -04001694}
1695
Johannes Berg86e8cf92013-06-19 10:57:22 +02001696static int nl80211_dump_wiphy_parse(struct sk_buff *skb,
1697 struct netlink_callback *cb,
1698 struct nl80211_dump_wiphy_state *state)
1699{
1700 struct nlattr **tb = nl80211_fam.attrbuf;
1701 int ret = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize,
1702 tb, nl80211_fam.maxattr, nl80211_policy);
1703 /* ignore parse errors for backward compatibility */
1704 if (ret)
1705 return 0;
1706
1707 state->split = tb[NL80211_ATTR_SPLIT_WIPHY_DUMP];
1708 if (tb[NL80211_ATTR_WIPHY])
1709 state->filter_wiphy = nla_get_u32(tb[NL80211_ATTR_WIPHY]);
1710 if (tb[NL80211_ATTR_WDEV])
1711 state->filter_wiphy = nla_get_u64(tb[NL80211_ATTR_WDEV]) >> 32;
1712 if (tb[NL80211_ATTR_IFINDEX]) {
1713 struct net_device *netdev;
1714 struct cfg80211_registered_device *rdev;
1715 int ifidx = nla_get_u32(tb[NL80211_ATTR_IFINDEX]);
1716
Ying Xue7f2b8562014-01-15 10:23:45 +08001717 netdev = __dev_get_by_index(sock_net(skb->sk), ifidx);
Johannes Berg86e8cf92013-06-19 10:57:22 +02001718 if (!netdev)
1719 return -ENODEV;
1720 if (netdev->ieee80211_ptr) {
Zhao, Gangf26cbf42014-04-21 12:53:03 +08001721 rdev = wiphy_to_rdev(
Johannes Berg86e8cf92013-06-19 10:57:22 +02001722 netdev->ieee80211_ptr->wiphy);
1723 state->filter_wiphy = rdev->wiphy_idx;
1724 }
Johannes Berg86e8cf92013-06-19 10:57:22 +02001725 }
1726
1727 return 0;
1728}
1729
Johannes Berg55682962007-09-20 13:09:35 -04001730static int nl80211_dump_wiphy(struct sk_buff *skb, struct netlink_callback *cb)
1731{
Johannes Berg645e77d2013-03-01 14:03:49 +01001732 int idx = 0, ret;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001733 struct nl80211_dump_wiphy_state *state = (void *)cb->args[0];
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001734 struct cfg80211_registered_device *rdev;
Johannes Berg3a5a4232013-06-19 10:09:57 +02001735
Johannes Berg5fe231e2013-05-08 21:45:15 +02001736 rtnl_lock();
Johannes Berg86e8cf92013-06-19 10:57:22 +02001737 if (!state) {
1738 state = kzalloc(sizeof(*state), GFP_KERNEL);
John W. Linville57ed5cd2013-06-28 13:18:21 -04001739 if (!state) {
1740 rtnl_unlock();
Johannes Berg86e8cf92013-06-19 10:57:22 +02001741 return -ENOMEM;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001742 }
Johannes Berg86e8cf92013-06-19 10:57:22 +02001743 state->filter_wiphy = -1;
1744 ret = nl80211_dump_wiphy_parse(skb, cb, state);
1745 if (ret) {
1746 kfree(state);
1747 rtnl_unlock();
1748 return ret;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001749 }
Johannes Berg86e8cf92013-06-19 10:57:22 +02001750 cb->args[0] = (long)state;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001751 }
1752
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001753 list_for_each_entry(rdev, &cfg80211_rdev_list, list) {
1754 if (!net_eq(wiphy_net(&rdev->wiphy), sock_net(skb->sk)))
Johannes Berg463d0182009-07-14 00:33:35 +02001755 continue;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001756 if (++idx <= state->start)
Johannes Berg55682962007-09-20 13:09:35 -04001757 continue;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001758 if (state->filter_wiphy != -1 &&
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001759 state->filter_wiphy != rdev->wiphy_idx)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001760 continue;
1761 /* attempt to fit multiple wiphy data chunks into the skb */
1762 do {
Johannes Berg3bb20552014-05-26 13:52:25 +02001763 ret = nl80211_send_wiphy(rdev, NL80211_CMD_NEW_WIPHY,
1764 skb,
Johannes Berg3713b4e2013-02-14 16:19:38 +01001765 NETLINK_CB(cb->skb).portid,
1766 cb->nlh->nlmsg_seq,
Johannes Berg86e8cf92013-06-19 10:57:22 +02001767 NLM_F_MULTI, state);
Johannes Berg3713b4e2013-02-14 16:19:38 +01001768 if (ret < 0) {
1769 /*
1770 * If sending the wiphy data didn't fit (ENOBUFS
1771 * or EMSGSIZE returned), this SKB is still
1772 * empty (so it's not too big because another
1773 * wiphy dataset is already in the skb) and
1774 * we've not tried to adjust the dump allocation
1775 * yet ... then adjust the alloc size to be
1776 * bigger, and return 1 but with the empty skb.
1777 * This results in an empty message being RX'ed
1778 * in userspace, but that is ignored.
1779 *
1780 * We can then retry with the larger buffer.
1781 */
1782 if ((ret == -ENOBUFS || ret == -EMSGSIZE) &&
Pontus Fuchsf12cb282014-01-16 15:00:40 +01001783 !skb->len && !state->split &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001784 cb->min_dump_alloc < 4096) {
1785 cb->min_dump_alloc = 4096;
Pontus Fuchsf12cb282014-01-16 15:00:40 +01001786 state->split_start = 0;
David S. Millerd98cae64e2013-06-19 16:49:39 -07001787 rtnl_unlock();
Johannes Berg3713b4e2013-02-14 16:19:38 +01001788 return 1;
1789 }
1790 idx--;
1791 break;
Johannes Berg645e77d2013-03-01 14:03:49 +01001792 }
Johannes Berg86e8cf92013-06-19 10:57:22 +02001793 } while (state->split_start > 0);
Johannes Berg3713b4e2013-02-14 16:19:38 +01001794 break;
Johannes Berg55682962007-09-20 13:09:35 -04001795 }
Johannes Berg5fe231e2013-05-08 21:45:15 +02001796 rtnl_unlock();
Johannes Berg55682962007-09-20 13:09:35 -04001797
Johannes Berg86e8cf92013-06-19 10:57:22 +02001798 state->start = idx;
Johannes Berg55682962007-09-20 13:09:35 -04001799
1800 return skb->len;
1801}
1802
Johannes Berg86e8cf92013-06-19 10:57:22 +02001803static int nl80211_dump_wiphy_done(struct netlink_callback *cb)
1804{
1805 kfree((void *)cb->args[0]);
1806 return 0;
1807}
1808
Johannes Berg55682962007-09-20 13:09:35 -04001809static int nl80211_get_wiphy(struct sk_buff *skb, struct genl_info *info)
1810{
1811 struct sk_buff *msg;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001812 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg86e8cf92013-06-19 10:57:22 +02001813 struct nl80211_dump_wiphy_state state = {};
Johannes Berg55682962007-09-20 13:09:35 -04001814
Johannes Berg645e77d2013-03-01 14:03:49 +01001815 msg = nlmsg_new(4096, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -04001816 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02001817 return -ENOMEM;
Johannes Berg55682962007-09-20 13:09:35 -04001818
Johannes Berg3bb20552014-05-26 13:52:25 +02001819 if (nl80211_send_wiphy(rdev, NL80211_CMD_NEW_WIPHY, msg,
1820 info->snd_portid, info->snd_seq, 0,
Johannes Berg86e8cf92013-06-19 10:57:22 +02001821 &state) < 0) {
Johannes Berg4c476992010-10-04 21:36:35 +02001822 nlmsg_free(msg);
1823 return -ENOBUFS;
1824 }
Johannes Berg55682962007-09-20 13:09:35 -04001825
Johannes Berg134e6372009-07-10 09:51:34 +00001826 return genlmsg_reply(msg, info);
Johannes Berg55682962007-09-20 13:09:35 -04001827}
1828
Jouni Malinen31888482008-10-30 16:59:24 +02001829static const struct nla_policy txq_params_policy[NL80211_TXQ_ATTR_MAX + 1] = {
1830 [NL80211_TXQ_ATTR_QUEUE] = { .type = NLA_U8 },
1831 [NL80211_TXQ_ATTR_TXOP] = { .type = NLA_U16 },
1832 [NL80211_TXQ_ATTR_CWMIN] = { .type = NLA_U16 },
1833 [NL80211_TXQ_ATTR_CWMAX] = { .type = NLA_U16 },
1834 [NL80211_TXQ_ATTR_AIFS] = { .type = NLA_U8 },
1835};
1836
1837static int parse_txq_params(struct nlattr *tb[],
1838 struct ieee80211_txq_params *txq_params)
1839{
Johannes Berga3304b02012-03-28 11:04:24 +02001840 if (!tb[NL80211_TXQ_ATTR_AC] || !tb[NL80211_TXQ_ATTR_TXOP] ||
Jouni Malinen31888482008-10-30 16:59:24 +02001841 !tb[NL80211_TXQ_ATTR_CWMIN] || !tb[NL80211_TXQ_ATTR_CWMAX] ||
1842 !tb[NL80211_TXQ_ATTR_AIFS])
1843 return -EINVAL;
1844
Johannes Berga3304b02012-03-28 11:04:24 +02001845 txq_params->ac = nla_get_u8(tb[NL80211_TXQ_ATTR_AC]);
Jouni Malinen31888482008-10-30 16:59:24 +02001846 txq_params->txop = nla_get_u16(tb[NL80211_TXQ_ATTR_TXOP]);
1847 txq_params->cwmin = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMIN]);
1848 txq_params->cwmax = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMAX]);
1849 txq_params->aifs = nla_get_u8(tb[NL80211_TXQ_ATTR_AIFS]);
1850
Johannes Berga3304b02012-03-28 11:04:24 +02001851 if (txq_params->ac >= NL80211_NUM_ACS)
1852 return -EINVAL;
1853
Jouni Malinen31888482008-10-30 16:59:24 +02001854 return 0;
1855}
1856
Johannes Bergf444de02010-05-05 15:25:02 +02001857static bool nl80211_can_set_dev_channel(struct wireless_dev *wdev)
1858{
1859 /*
Johannes Bergcc1d2802012-05-16 23:50:20 +02001860 * You can only set the channel explicitly for WDS interfaces,
1861 * all others have their channel managed via their respective
1862 * "establish a connection" command (connect, join, ...)
1863 *
1864 * For AP/GO and mesh mode, the channel can be set with the
1865 * channel userspace API, but is only stored and passed to the
1866 * low-level driver when the AP starts or the mesh is joined.
1867 * This is for backward compatibility, userspace can also give
1868 * the channel in the start-ap or join-mesh commands instead.
Johannes Bergf444de02010-05-05 15:25:02 +02001869 *
1870 * Monitors are special as they are normally slaved to
Johannes Berge8c9bd52012-06-06 08:18:22 +02001871 * whatever else is going on, so they have their own special
1872 * operation to set the monitor channel if possible.
Johannes Bergf444de02010-05-05 15:25:02 +02001873 */
1874 return !wdev ||
1875 wdev->iftype == NL80211_IFTYPE_AP ||
Johannes Bergf444de02010-05-05 15:25:02 +02001876 wdev->iftype == NL80211_IFTYPE_MESH_POINT ||
Johannes Berg074ac8d2010-09-16 14:58:22 +02001877 wdev->iftype == NL80211_IFTYPE_MONITOR ||
1878 wdev->iftype == NL80211_IFTYPE_P2P_GO;
Johannes Bergf444de02010-05-05 15:25:02 +02001879}
1880
Johannes Berg683b6d32012-11-08 21:25:48 +01001881static int nl80211_parse_chandef(struct cfg80211_registered_device *rdev,
1882 struct genl_info *info,
1883 struct cfg80211_chan_def *chandef)
1884{
Mahesh Paliveladbeca2e2012-11-29 14:11:07 +05301885 u32 control_freq;
Johannes Berg683b6d32012-11-08 21:25:48 +01001886
1887 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ])
1888 return -EINVAL;
1889
1890 control_freq = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]);
1891
1892 chandef->chan = ieee80211_get_channel(&rdev->wiphy, control_freq);
Johannes Berg3d9d1d62012-11-08 23:14:50 +01001893 chandef->width = NL80211_CHAN_WIDTH_20_NOHT;
1894 chandef->center_freq1 = control_freq;
1895 chandef->center_freq2 = 0;
Johannes Berg683b6d32012-11-08 21:25:48 +01001896
1897 /* Primary channel not allowed */
1898 if (!chandef->chan || chandef->chan->flags & IEEE80211_CHAN_DISABLED)
1899 return -EINVAL;
1900
Johannes Berg3d9d1d62012-11-08 23:14:50 +01001901 if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]) {
1902 enum nl80211_channel_type chantype;
Johannes Berg683b6d32012-11-08 21:25:48 +01001903
Johannes Berg3d9d1d62012-11-08 23:14:50 +01001904 chantype = nla_get_u32(
1905 info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]);
1906
1907 switch (chantype) {
1908 case NL80211_CHAN_NO_HT:
1909 case NL80211_CHAN_HT20:
1910 case NL80211_CHAN_HT40PLUS:
1911 case NL80211_CHAN_HT40MINUS:
1912 cfg80211_chandef_create(chandef, chandef->chan,
1913 chantype);
1914 break;
1915 default:
Johannes Berg683b6d32012-11-08 21:25:48 +01001916 return -EINVAL;
Johannes Berg683b6d32012-11-08 21:25:48 +01001917 }
Johannes Berg3d9d1d62012-11-08 23:14:50 +01001918 } else if (info->attrs[NL80211_ATTR_CHANNEL_WIDTH]) {
1919 chandef->width =
1920 nla_get_u32(info->attrs[NL80211_ATTR_CHANNEL_WIDTH]);
1921 if (info->attrs[NL80211_ATTR_CENTER_FREQ1])
1922 chandef->center_freq1 =
1923 nla_get_u32(
1924 info->attrs[NL80211_ATTR_CENTER_FREQ1]);
1925 if (info->attrs[NL80211_ATTR_CENTER_FREQ2])
1926 chandef->center_freq2 =
1927 nla_get_u32(
1928 info->attrs[NL80211_ATTR_CENTER_FREQ2]);
1929 }
1930
Johannes Berg9f5e8f62012-11-22 16:59:45 +01001931 if (!cfg80211_chandef_valid(chandef))
Johannes Berg3d9d1d62012-11-08 23:14:50 +01001932 return -EINVAL;
1933
Johannes Berg9f5e8f62012-11-22 16:59:45 +01001934 if (!cfg80211_chandef_usable(&rdev->wiphy, chandef,
1935 IEEE80211_CHAN_DISABLED))
Johannes Berg3d9d1d62012-11-08 23:14:50 +01001936 return -EINVAL;
Johannes Berg3d9d1d62012-11-08 23:14:50 +01001937
Simon Wunderlich2f301ab2013-05-16 13:00:28 +02001938 if ((chandef->width == NL80211_CHAN_WIDTH_5 ||
1939 chandef->width == NL80211_CHAN_WIDTH_10) &&
1940 !(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_5_10_MHZ))
1941 return -EINVAL;
1942
Johannes Berg683b6d32012-11-08 21:25:48 +01001943 return 0;
1944}
1945
Johannes Bergf444de02010-05-05 15:25:02 +02001946static int __nl80211_set_channel(struct cfg80211_registered_device *rdev,
Jouni Malinene16821b2014-04-28 11:22:08 +03001947 struct net_device *dev,
Johannes Bergf444de02010-05-05 15:25:02 +02001948 struct genl_info *info)
1949{
Johannes Berg683b6d32012-11-08 21:25:48 +01001950 struct cfg80211_chan_def chandef;
Johannes Bergf444de02010-05-05 15:25:02 +02001951 int result;
Johannes Berge8c9bd52012-06-06 08:18:22 +02001952 enum nl80211_iftype iftype = NL80211_IFTYPE_MONITOR;
Jouni Malinene16821b2014-04-28 11:22:08 +03001953 struct wireless_dev *wdev = NULL;
Johannes Berge8c9bd52012-06-06 08:18:22 +02001954
Jouni Malinene16821b2014-04-28 11:22:08 +03001955 if (dev)
1956 wdev = dev->ieee80211_ptr;
Johannes Bergf444de02010-05-05 15:25:02 +02001957 if (!nl80211_can_set_dev_channel(wdev))
1958 return -EOPNOTSUPP;
Jouni Malinene16821b2014-04-28 11:22:08 +03001959 if (wdev)
1960 iftype = wdev->iftype;
Johannes Bergf444de02010-05-05 15:25:02 +02001961
Johannes Berg683b6d32012-11-08 21:25:48 +01001962 result = nl80211_parse_chandef(rdev, info, &chandef);
1963 if (result)
1964 return result;
Johannes Bergf444de02010-05-05 15:25:02 +02001965
Johannes Berge8c9bd52012-06-06 08:18:22 +02001966 switch (iftype) {
Johannes Bergaa430da2012-05-16 23:50:18 +02001967 case NL80211_IFTYPE_AP:
1968 case NL80211_IFTYPE_P2P_GO:
Ilan Peer174e0cd2014-02-23 09:13:01 +02001969 if (!cfg80211_reg_can_beacon(&rdev->wiphy, &chandef, iftype)) {
Johannes Bergaa430da2012-05-16 23:50:18 +02001970 result = -EINVAL;
1971 break;
1972 }
Jouni Malinene16821b2014-04-28 11:22:08 +03001973 if (wdev->beacon_interval) {
1974 if (!dev || !rdev->ops->set_ap_chanwidth ||
1975 !(rdev->wiphy.features &
1976 NL80211_FEATURE_AP_MODE_CHAN_WIDTH_CHANGE)) {
1977 result = -EBUSY;
1978 break;
1979 }
1980
1981 /* Only allow dynamic channel width changes */
1982 if (chandef.chan != wdev->preset_chandef.chan) {
1983 result = -EBUSY;
1984 break;
1985 }
1986 result = rdev_set_ap_chanwidth(rdev, dev, &chandef);
1987 if (result)
1988 break;
1989 }
Johannes Berg683b6d32012-11-08 21:25:48 +01001990 wdev->preset_chandef = chandef;
Johannes Bergaa430da2012-05-16 23:50:18 +02001991 result = 0;
1992 break;
Johannes Bergcc1d2802012-05-16 23:50:20 +02001993 case NL80211_IFTYPE_MESH_POINT:
Johannes Berg683b6d32012-11-08 21:25:48 +01001994 result = cfg80211_set_mesh_channel(rdev, wdev, &chandef);
Johannes Bergcc1d2802012-05-16 23:50:20 +02001995 break;
Johannes Berge8c9bd52012-06-06 08:18:22 +02001996 case NL80211_IFTYPE_MONITOR:
Johannes Berg683b6d32012-11-08 21:25:48 +01001997 result = cfg80211_set_monitor_channel(rdev, &chandef);
Johannes Berge8c9bd52012-06-06 08:18:22 +02001998 break;
Johannes Bergaa430da2012-05-16 23:50:18 +02001999 default:
Johannes Berge8c9bd52012-06-06 08:18:22 +02002000 result = -EINVAL;
Johannes Bergf444de02010-05-05 15:25:02 +02002001 }
Johannes Bergf444de02010-05-05 15:25:02 +02002002
2003 return result;
2004}
2005
2006static int nl80211_set_channel(struct sk_buff *skb, struct genl_info *info)
2007{
Johannes Berg4c476992010-10-04 21:36:35 +02002008 struct cfg80211_registered_device *rdev = info->user_ptr[0];
2009 struct net_device *netdev = info->user_ptr[1];
Johannes Bergf444de02010-05-05 15:25:02 +02002010
Jouni Malinene16821b2014-04-28 11:22:08 +03002011 return __nl80211_set_channel(rdev, netdev, info);
Johannes Bergf444de02010-05-05 15:25:02 +02002012}
2013
Bill Jordane8347eb2010-10-01 13:54:28 -04002014static int nl80211_set_wds_peer(struct sk_buff *skb, struct genl_info *info)
2015{
Johannes Berg43b19952010-10-07 13:10:30 +02002016 struct cfg80211_registered_device *rdev = info->user_ptr[0];
2017 struct net_device *dev = info->user_ptr[1];
2018 struct wireless_dev *wdev = dev->ieee80211_ptr;
Johannes Berg388ac772010-10-07 13:11:09 +02002019 const u8 *bssid;
Bill Jordane8347eb2010-10-01 13:54:28 -04002020
2021 if (!info->attrs[NL80211_ATTR_MAC])
2022 return -EINVAL;
2023
Johannes Berg43b19952010-10-07 13:10:30 +02002024 if (netif_running(dev))
2025 return -EBUSY;
Bill Jordane8347eb2010-10-01 13:54:28 -04002026
Johannes Berg43b19952010-10-07 13:10:30 +02002027 if (!rdev->ops->set_wds_peer)
2028 return -EOPNOTSUPP;
Bill Jordane8347eb2010-10-01 13:54:28 -04002029
Johannes Berg43b19952010-10-07 13:10:30 +02002030 if (wdev->iftype != NL80211_IFTYPE_WDS)
2031 return -EOPNOTSUPP;
Bill Jordane8347eb2010-10-01 13:54:28 -04002032
2033 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Hila Gonene35e4d22012-06-27 17:19:42 +03002034 return rdev_set_wds_peer(rdev, dev, bssid);
Bill Jordane8347eb2010-10-01 13:54:28 -04002035}
2036
2037
Johannes Berg55682962007-09-20 13:09:35 -04002038static int nl80211_set_wiphy(struct sk_buff *skb, struct genl_info *info)
2039{
2040 struct cfg80211_registered_device *rdev;
Johannes Bergf444de02010-05-05 15:25:02 +02002041 struct net_device *netdev = NULL;
2042 struct wireless_dev *wdev;
Bill Jordana1e567c2010-09-10 11:22:32 -04002043 int result = 0, rem_txq_params = 0;
Jouni Malinen31888482008-10-30 16:59:24 +02002044 struct nlattr *nl_txq_params;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002045 u32 changed;
2046 u8 retry_short = 0, retry_long = 0;
2047 u32 frag_threshold = 0, rts_threshold = 0;
Lukáš Turek81077e82009-12-21 22:50:47 +01002048 u8 coverage_class = 0;
Johannes Berg55682962007-09-20 13:09:35 -04002049
Johannes Berg5fe231e2013-05-08 21:45:15 +02002050 ASSERT_RTNL();
2051
Johannes Bergf444de02010-05-05 15:25:02 +02002052 /*
2053 * Try to find the wiphy and netdev. Normally this
2054 * function shouldn't need the netdev, but this is
2055 * done for backward compatibility -- previously
2056 * setting the channel was done per wiphy, but now
2057 * it is per netdev. Previous userland like hostapd
2058 * also passed a netdev to set_wiphy, so that it is
2059 * possible to let that go to the right netdev!
2060 */
Johannes Berg4bbf4d52009-03-24 09:35:46 +01002061
Johannes Bergf444de02010-05-05 15:25:02 +02002062 if (info->attrs[NL80211_ATTR_IFINDEX]) {
2063 int ifindex = nla_get_u32(info->attrs[NL80211_ATTR_IFINDEX]);
2064
Ying Xue7f2b8562014-01-15 10:23:45 +08002065 netdev = __dev_get_by_index(genl_info_net(info), ifindex);
Johannes Berg5fe231e2013-05-08 21:45:15 +02002066 if (netdev && netdev->ieee80211_ptr)
Zhao, Gangf26cbf42014-04-21 12:53:03 +08002067 rdev = wiphy_to_rdev(netdev->ieee80211_ptr->wiphy);
Johannes Berg5fe231e2013-05-08 21:45:15 +02002068 else
Johannes Bergf444de02010-05-05 15:25:02 +02002069 netdev = NULL;
Johannes Berg4bbf4d52009-03-24 09:35:46 +01002070 }
2071
Johannes Bergf444de02010-05-05 15:25:02 +02002072 if (!netdev) {
Johannes Berg878d9ec2012-06-15 14:18:32 +02002073 rdev = __cfg80211_rdev_from_attrs(genl_info_net(info),
2074 info->attrs);
Johannes Berg5fe231e2013-05-08 21:45:15 +02002075 if (IS_ERR(rdev))
Johannes Berg4c476992010-10-04 21:36:35 +02002076 return PTR_ERR(rdev);
Johannes Bergf444de02010-05-05 15:25:02 +02002077 wdev = NULL;
2078 netdev = NULL;
2079 result = 0;
Johannes Berg71fe96b2012-10-24 10:04:58 +02002080 } else
Johannes Bergf444de02010-05-05 15:25:02 +02002081 wdev = netdev->ieee80211_ptr;
Johannes Bergf444de02010-05-05 15:25:02 +02002082
2083 /*
2084 * end workaround code, by now the rdev is available
2085 * and locked, and wdev may or may not be NULL.
2086 */
Johannes Berg4bbf4d52009-03-24 09:35:46 +01002087
2088 if (info->attrs[NL80211_ATTR_WIPHY_NAME])
Jouni Malinen31888482008-10-30 16:59:24 +02002089 result = cfg80211_dev_rename(
2090 rdev, nla_data(info->attrs[NL80211_ATTR_WIPHY_NAME]));
Johannes Berg4bbf4d52009-03-24 09:35:46 +01002091
Johannes Berg4bbf4d52009-03-24 09:35:46 +01002092 if (result)
Ying Xue7f2b8562014-01-15 10:23:45 +08002093 return result;
Johannes Berg55682962007-09-20 13:09:35 -04002094
Jouni Malinen31888482008-10-30 16:59:24 +02002095 if (info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS]) {
2096 struct ieee80211_txq_params txq_params;
2097 struct nlattr *tb[NL80211_TXQ_ATTR_MAX + 1];
2098
Ying Xue7f2b8562014-01-15 10:23:45 +08002099 if (!rdev->ops->set_txq_params)
2100 return -EOPNOTSUPP;
Jouni Malinen31888482008-10-30 16:59:24 +02002101
Ying Xue7f2b8562014-01-15 10:23:45 +08002102 if (!netdev)
2103 return -EINVAL;
Eliad Pellerf70f01c2011-09-25 20:06:53 +03002104
Johannes Berg133a3ff2011-11-03 14:50:13 +01002105 if (netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
Ying Xue7f2b8562014-01-15 10:23:45 +08002106 netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
2107 return -EINVAL;
Johannes Berg133a3ff2011-11-03 14:50:13 +01002108
Ying Xue7f2b8562014-01-15 10:23:45 +08002109 if (!netif_running(netdev))
2110 return -ENETDOWN;
Johannes Berg2b5f8b02012-04-02 10:51:55 +02002111
Jouni Malinen31888482008-10-30 16:59:24 +02002112 nla_for_each_nested(nl_txq_params,
2113 info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS],
2114 rem_txq_params) {
Johannes Bergae811e22014-01-24 10:17:47 +01002115 result = nla_parse(tb, NL80211_TXQ_ATTR_MAX,
2116 nla_data(nl_txq_params),
2117 nla_len(nl_txq_params),
2118 txq_params_policy);
2119 if (result)
2120 return result;
Jouni Malinen31888482008-10-30 16:59:24 +02002121 result = parse_txq_params(tb, &txq_params);
2122 if (result)
Ying Xue7f2b8562014-01-15 10:23:45 +08002123 return result;
Jouni Malinen31888482008-10-30 16:59:24 +02002124
Hila Gonene35e4d22012-06-27 17:19:42 +03002125 result = rdev_set_txq_params(rdev, netdev,
2126 &txq_params);
Jouni Malinen31888482008-10-30 16:59:24 +02002127 if (result)
Ying Xue7f2b8562014-01-15 10:23:45 +08002128 return result;
Jouni Malinen31888482008-10-30 16:59:24 +02002129 }
2130 }
2131
Jouni Malinen72bdcf32008-11-26 16:15:24 +02002132 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
Jouni Malinene16821b2014-04-28 11:22:08 +03002133 result = __nl80211_set_channel(
2134 rdev,
2135 nl80211_can_set_dev_channel(wdev) ? netdev : NULL,
2136 info);
Jouni Malinen72bdcf32008-11-26 16:15:24 +02002137 if (result)
Ying Xue7f2b8562014-01-15 10:23:45 +08002138 return result;
Jouni Malinen72bdcf32008-11-26 16:15:24 +02002139 }
2140
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03002141 if (info->attrs[NL80211_ATTR_WIPHY_TX_POWER_SETTING]) {
Johannes Bergc8442112012-10-24 10:17:18 +02002142 struct wireless_dev *txp_wdev = wdev;
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03002143 enum nl80211_tx_power_setting type;
2144 int idx, mbm = 0;
2145
Johannes Bergc8442112012-10-24 10:17:18 +02002146 if (!(rdev->wiphy.features & NL80211_FEATURE_VIF_TXPOWER))
2147 txp_wdev = NULL;
2148
Ying Xue7f2b8562014-01-15 10:23:45 +08002149 if (!rdev->ops->set_tx_power)
2150 return -EOPNOTSUPP;
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03002151
2152 idx = NL80211_ATTR_WIPHY_TX_POWER_SETTING;
2153 type = nla_get_u32(info->attrs[idx]);
2154
2155 if (!info->attrs[NL80211_ATTR_WIPHY_TX_POWER_LEVEL] &&
Ying Xue7f2b8562014-01-15 10:23:45 +08002156 (type != NL80211_TX_POWER_AUTOMATIC))
2157 return -EINVAL;
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03002158
2159 if (type != NL80211_TX_POWER_AUTOMATIC) {
2160 idx = NL80211_ATTR_WIPHY_TX_POWER_LEVEL;
2161 mbm = nla_get_u32(info->attrs[idx]);
2162 }
2163
Johannes Bergc8442112012-10-24 10:17:18 +02002164 result = rdev_set_tx_power(rdev, txp_wdev, type, mbm);
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03002165 if (result)
Ying Xue7f2b8562014-01-15 10:23:45 +08002166 return result;
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03002167 }
2168
Bruno Randolfafe0cbf2010-11-10 12:50:50 +09002169 if (info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX] &&
2170 info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]) {
2171 u32 tx_ant, rx_ant;
Bruno Randolf7f531e02010-12-16 11:30:22 +09002172 if ((!rdev->wiphy.available_antennas_tx &&
2173 !rdev->wiphy.available_antennas_rx) ||
Ying Xue7f2b8562014-01-15 10:23:45 +08002174 !rdev->ops->set_antenna)
2175 return -EOPNOTSUPP;
Bruno Randolfafe0cbf2010-11-10 12:50:50 +09002176
2177 tx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX]);
2178 rx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]);
2179
Bruno Randolfa7ffac92010-12-08 13:59:24 +09002180 /* reject antenna configurations which don't match the
Bruno Randolf7f531e02010-12-16 11:30:22 +09002181 * available antenna masks, except for the "all" mask */
2182 if ((~tx_ant && (tx_ant & ~rdev->wiphy.available_antennas_tx)) ||
Ying Xue7f2b8562014-01-15 10:23:45 +08002183 (~rx_ant && (rx_ant & ~rdev->wiphy.available_antennas_rx)))
2184 return -EINVAL;
Bruno Randolfa7ffac92010-12-08 13:59:24 +09002185
Bruno Randolf7f531e02010-12-16 11:30:22 +09002186 tx_ant = tx_ant & rdev->wiphy.available_antennas_tx;
2187 rx_ant = rx_ant & rdev->wiphy.available_antennas_rx;
Bruno Randolfa7ffac92010-12-08 13:59:24 +09002188
Hila Gonene35e4d22012-06-27 17:19:42 +03002189 result = rdev_set_antenna(rdev, tx_ant, rx_ant);
Bruno Randolfafe0cbf2010-11-10 12:50:50 +09002190 if (result)
Ying Xue7f2b8562014-01-15 10:23:45 +08002191 return result;
Bruno Randolfafe0cbf2010-11-10 12:50:50 +09002192 }
2193
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002194 changed = 0;
2195
2196 if (info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]) {
2197 retry_short = nla_get_u8(
2198 info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]);
Ying Xue7f2b8562014-01-15 10:23:45 +08002199 if (retry_short == 0)
2200 return -EINVAL;
2201
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002202 changed |= WIPHY_PARAM_RETRY_SHORT;
2203 }
2204
2205 if (info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]) {
2206 retry_long = nla_get_u8(
2207 info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]);
Ying Xue7f2b8562014-01-15 10:23:45 +08002208 if (retry_long == 0)
2209 return -EINVAL;
2210
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002211 changed |= WIPHY_PARAM_RETRY_LONG;
2212 }
2213
2214 if (info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]) {
2215 frag_threshold = nla_get_u32(
2216 info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]);
Ying Xue7f2b8562014-01-15 10:23:45 +08002217 if (frag_threshold < 256)
2218 return -EINVAL;
2219
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002220 if (frag_threshold != (u32) -1) {
2221 /*
2222 * Fragments (apart from the last one) are required to
2223 * have even length. Make the fragmentation code
2224 * simpler by stripping LSB should someone try to use
2225 * odd threshold value.
2226 */
2227 frag_threshold &= ~0x1;
2228 }
2229 changed |= WIPHY_PARAM_FRAG_THRESHOLD;
2230 }
2231
2232 if (info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]) {
2233 rts_threshold = nla_get_u32(
2234 info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]);
2235 changed |= WIPHY_PARAM_RTS_THRESHOLD;
2236 }
2237
Lukáš Turek81077e82009-12-21 22:50:47 +01002238 if (info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]) {
2239 coverage_class = nla_get_u8(
2240 info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]);
2241 changed |= WIPHY_PARAM_COVERAGE_CLASS;
2242 }
2243
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002244 if (changed) {
2245 u8 old_retry_short, old_retry_long;
2246 u32 old_frag_threshold, old_rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01002247 u8 old_coverage_class;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002248
Ying Xue7f2b8562014-01-15 10:23:45 +08002249 if (!rdev->ops->set_wiphy_params)
2250 return -EOPNOTSUPP;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002251
2252 old_retry_short = rdev->wiphy.retry_short;
2253 old_retry_long = rdev->wiphy.retry_long;
2254 old_frag_threshold = rdev->wiphy.frag_threshold;
2255 old_rts_threshold = rdev->wiphy.rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01002256 old_coverage_class = rdev->wiphy.coverage_class;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002257
2258 if (changed & WIPHY_PARAM_RETRY_SHORT)
2259 rdev->wiphy.retry_short = retry_short;
2260 if (changed & WIPHY_PARAM_RETRY_LONG)
2261 rdev->wiphy.retry_long = retry_long;
2262 if (changed & WIPHY_PARAM_FRAG_THRESHOLD)
2263 rdev->wiphy.frag_threshold = frag_threshold;
2264 if (changed & WIPHY_PARAM_RTS_THRESHOLD)
2265 rdev->wiphy.rts_threshold = rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01002266 if (changed & WIPHY_PARAM_COVERAGE_CLASS)
2267 rdev->wiphy.coverage_class = coverage_class;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002268
Hila Gonene35e4d22012-06-27 17:19:42 +03002269 result = rdev_set_wiphy_params(rdev, changed);
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002270 if (result) {
2271 rdev->wiphy.retry_short = old_retry_short;
2272 rdev->wiphy.retry_long = old_retry_long;
2273 rdev->wiphy.frag_threshold = old_frag_threshold;
2274 rdev->wiphy.rts_threshold = old_rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01002275 rdev->wiphy.coverage_class = old_coverage_class;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002276 }
2277 }
Ying Xue7f2b8562014-01-15 10:23:45 +08002278 return 0;
Johannes Berg55682962007-09-20 13:09:35 -04002279}
2280
Johannes Berg71bbc992012-06-15 15:30:18 +02002281static inline u64 wdev_id(struct wireless_dev *wdev)
2282{
2283 return (u64)wdev->identifier |
Zhao, Gangf26cbf42014-04-21 12:53:03 +08002284 ((u64)wiphy_to_rdev(wdev->wiphy)->wiphy_idx << 32);
Johannes Berg71bbc992012-06-15 15:30:18 +02002285}
Johannes Berg55682962007-09-20 13:09:35 -04002286
Johannes Berg683b6d32012-11-08 21:25:48 +01002287static int nl80211_send_chandef(struct sk_buff *msg,
Janusz Dziedzicd2859df2013-11-06 13:55:51 +01002288 const struct cfg80211_chan_def *chandef)
Johannes Berg683b6d32012-11-08 21:25:48 +01002289{
Johannes Berg9f5e8f62012-11-22 16:59:45 +01002290 WARN_ON(!cfg80211_chandef_valid(chandef));
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002291
Johannes Berg683b6d32012-11-08 21:25:48 +01002292 if (nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ,
2293 chandef->chan->center_freq))
2294 return -ENOBUFS;
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002295 switch (chandef->width) {
2296 case NL80211_CHAN_WIDTH_20_NOHT:
2297 case NL80211_CHAN_WIDTH_20:
2298 case NL80211_CHAN_WIDTH_40:
2299 if (nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE,
2300 cfg80211_get_chandef_type(chandef)))
2301 return -ENOBUFS;
2302 break;
2303 default:
2304 break;
2305 }
2306 if (nla_put_u32(msg, NL80211_ATTR_CHANNEL_WIDTH, chandef->width))
2307 return -ENOBUFS;
2308 if (nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ1, chandef->center_freq1))
2309 return -ENOBUFS;
2310 if (chandef->center_freq2 &&
2311 nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ2, chandef->center_freq2))
Johannes Berg683b6d32012-11-08 21:25:48 +01002312 return -ENOBUFS;
2313 return 0;
2314}
2315
Eric W. Biederman15e47302012-09-07 20:12:54 +00002316static int nl80211_send_iface(struct sk_buff *msg, u32 portid, u32 seq, int flags,
Johannes Bergd7264052009-04-19 16:23:20 +02002317 struct cfg80211_registered_device *rdev,
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002318 struct wireless_dev *wdev)
Johannes Berg55682962007-09-20 13:09:35 -04002319{
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002320 struct net_device *dev = wdev->netdev;
Johannes Berg55682962007-09-20 13:09:35 -04002321 void *hdr;
2322
Eric W. Biederman15e47302012-09-07 20:12:54 +00002323 hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_INTERFACE);
Johannes Berg55682962007-09-20 13:09:35 -04002324 if (!hdr)
2325 return -1;
2326
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002327 if (dev &&
2328 (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
Johannes Berg98104fde2012-06-16 00:19:54 +02002329 nla_put_string(msg, NL80211_ATTR_IFNAME, dev->name)))
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002330 goto nla_put_failure;
2331
2332 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
2333 nla_put_u32(msg, NL80211_ATTR_IFTYPE, wdev->iftype) ||
Johannes Berg71bbc992012-06-15 15:30:18 +02002334 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) ||
Johannes Berg98104fde2012-06-16 00:19:54 +02002335 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, wdev_address(wdev)) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04002336 nla_put_u32(msg, NL80211_ATTR_GENERATION,
2337 rdev->devlist_generation ^
2338 (cfg80211_rdev_list_generation << 2)))
2339 goto nla_put_failure;
Johannes Bergf5ea9122009-08-07 16:17:38 +02002340
Johannes Berg5b7ccaf2012-07-12 19:45:08 +02002341 if (rdev->ops->get_channel) {
Johannes Berg683b6d32012-11-08 21:25:48 +01002342 int ret;
2343 struct cfg80211_chan_def chandef;
Johannes Berg5b7ccaf2012-07-12 19:45:08 +02002344
Johannes Berg683b6d32012-11-08 21:25:48 +01002345 ret = rdev_get_channel(rdev, wdev, &chandef);
2346 if (ret == 0) {
2347 if (nl80211_send_chandef(msg, &chandef))
2348 goto nla_put_failure;
2349 }
Pontus Fuchsd91df0e2012-04-03 16:39:58 +02002350 }
2351
Antonio Quartullib84e7a02012-11-07 12:52:20 +01002352 if (wdev->ssid_len) {
2353 if (nla_put(msg, NL80211_ATTR_SSID, wdev->ssid_len, wdev->ssid))
2354 goto nla_put_failure;
2355 }
2356
Johannes Berg55682962007-09-20 13:09:35 -04002357 return genlmsg_end(msg, hdr);
2358
2359 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07002360 genlmsg_cancel(msg, hdr);
2361 return -EMSGSIZE;
Johannes Berg55682962007-09-20 13:09:35 -04002362}
2363
2364static int nl80211_dump_interface(struct sk_buff *skb, struct netlink_callback *cb)
2365{
2366 int wp_idx = 0;
2367 int if_idx = 0;
2368 int wp_start = cb->args[0];
2369 int if_start = cb->args[1];
Johannes Bergf5ea9122009-08-07 16:17:38 +02002370 struct cfg80211_registered_device *rdev;
Johannes Berg55682962007-09-20 13:09:35 -04002371 struct wireless_dev *wdev;
2372
Johannes Berg5fe231e2013-05-08 21:45:15 +02002373 rtnl_lock();
Johannes Bergf5ea9122009-08-07 16:17:38 +02002374 list_for_each_entry(rdev, &cfg80211_rdev_list, list) {
2375 if (!net_eq(wiphy_net(&rdev->wiphy), sock_net(skb->sk)))
Johannes Berg463d0182009-07-14 00:33:35 +02002376 continue;
Johannes Bergbba95fe2008-07-29 13:22:51 +02002377 if (wp_idx < wp_start) {
2378 wp_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04002379 continue;
Johannes Bergbba95fe2008-07-29 13:22:51 +02002380 }
Johannes Berg55682962007-09-20 13:09:35 -04002381 if_idx = 0;
2382
Johannes Berg89a54e42012-06-15 14:33:17 +02002383 list_for_each_entry(wdev, &rdev->wdev_list, list) {
Johannes Bergbba95fe2008-07-29 13:22:51 +02002384 if (if_idx < if_start) {
2385 if_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04002386 continue;
Johannes Bergbba95fe2008-07-29 13:22:51 +02002387 }
Eric W. Biederman15e47302012-09-07 20:12:54 +00002388 if (nl80211_send_iface(skb, NETLINK_CB(cb->skb).portid,
Johannes Berg55682962007-09-20 13:09:35 -04002389 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002390 rdev, wdev) < 0) {
Johannes Bergbba95fe2008-07-29 13:22:51 +02002391 goto out;
2392 }
2393 if_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04002394 }
Johannes Bergbba95fe2008-07-29 13:22:51 +02002395
2396 wp_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04002397 }
Johannes Bergbba95fe2008-07-29 13:22:51 +02002398 out:
Johannes Berg5fe231e2013-05-08 21:45:15 +02002399 rtnl_unlock();
Johannes Berg55682962007-09-20 13:09:35 -04002400
2401 cb->args[0] = wp_idx;
2402 cb->args[1] = if_idx;
2403
2404 return skb->len;
2405}
2406
2407static int nl80211_get_interface(struct sk_buff *skb, struct genl_info *info)
2408{
2409 struct sk_buff *msg;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002410 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002411 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg55682962007-09-20 13:09:35 -04002412
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07002413 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -04002414 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02002415 return -ENOMEM;
Johannes Berg55682962007-09-20 13:09:35 -04002416
Eric W. Biederman15e47302012-09-07 20:12:54 +00002417 if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002418 rdev, wdev) < 0) {
Johannes Berg4c476992010-10-04 21:36:35 +02002419 nlmsg_free(msg);
2420 return -ENOBUFS;
2421 }
Johannes Berg55682962007-09-20 13:09:35 -04002422
Johannes Berg134e6372009-07-10 09:51:34 +00002423 return genlmsg_reply(msg, info);
Johannes Berg55682962007-09-20 13:09:35 -04002424}
2425
Michael Wu66f7ac52008-01-31 19:48:22 +01002426static const struct nla_policy mntr_flags_policy[NL80211_MNTR_FLAG_MAX + 1] = {
2427 [NL80211_MNTR_FLAG_FCSFAIL] = { .type = NLA_FLAG },
2428 [NL80211_MNTR_FLAG_PLCPFAIL] = { .type = NLA_FLAG },
2429 [NL80211_MNTR_FLAG_CONTROL] = { .type = NLA_FLAG },
2430 [NL80211_MNTR_FLAG_OTHER_BSS] = { .type = NLA_FLAG },
2431 [NL80211_MNTR_FLAG_COOK_FRAMES] = { .type = NLA_FLAG },
Felix Fietkaue057d3c2013-05-28 13:01:52 +02002432 [NL80211_MNTR_FLAG_ACTIVE] = { .type = NLA_FLAG },
Michael Wu66f7ac52008-01-31 19:48:22 +01002433};
2434
2435static int parse_monitor_flags(struct nlattr *nla, u32 *mntrflags)
2436{
2437 struct nlattr *flags[NL80211_MNTR_FLAG_MAX + 1];
2438 int flag;
2439
2440 *mntrflags = 0;
2441
2442 if (!nla)
2443 return -EINVAL;
2444
2445 if (nla_parse_nested(flags, NL80211_MNTR_FLAG_MAX,
2446 nla, mntr_flags_policy))
2447 return -EINVAL;
2448
2449 for (flag = 1; flag <= NL80211_MNTR_FLAG_MAX; flag++)
2450 if (flags[flag])
2451 *mntrflags |= (1<<flag);
2452
2453 return 0;
2454}
2455
Johannes Berg9bc383d2009-11-19 11:55:19 +01002456static int nl80211_valid_4addr(struct cfg80211_registered_device *rdev,
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002457 struct net_device *netdev, u8 use_4addr,
2458 enum nl80211_iftype iftype)
Johannes Berg9bc383d2009-11-19 11:55:19 +01002459{
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002460 if (!use_4addr) {
Jiri Pirkof350a0a82010-06-15 06:50:45 +00002461 if (netdev && (netdev->priv_flags & IFF_BRIDGE_PORT))
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002462 return -EBUSY;
Johannes Berg9bc383d2009-11-19 11:55:19 +01002463 return 0;
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002464 }
Johannes Berg9bc383d2009-11-19 11:55:19 +01002465
2466 switch (iftype) {
2467 case NL80211_IFTYPE_AP_VLAN:
2468 if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_AP)
2469 return 0;
2470 break;
2471 case NL80211_IFTYPE_STATION:
2472 if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_STATION)
2473 return 0;
2474 break;
2475 default:
2476 break;
2477 }
2478
2479 return -EOPNOTSUPP;
2480}
2481
Johannes Berg55682962007-09-20 13:09:35 -04002482static int nl80211_set_interface(struct sk_buff *skb, struct genl_info *info)
2483{
Johannes Berg4c476992010-10-04 21:36:35 +02002484 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002485 struct vif_params params;
Johannes Berge36d56b2009-06-09 21:04:43 +02002486 int err;
Johannes Berg04a773a2009-04-19 21:24:32 +02002487 enum nl80211_iftype otype, ntype;
Johannes Berg4c476992010-10-04 21:36:35 +02002488 struct net_device *dev = info->user_ptr[1];
Johannes Berg92ffe052008-09-16 20:39:36 +02002489 u32 _flags, *flags = NULL;
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002490 bool change = false;
Johannes Berg55682962007-09-20 13:09:35 -04002491
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002492 memset(&params, 0, sizeof(params));
2493
Johannes Berg04a773a2009-04-19 21:24:32 +02002494 otype = ntype = dev->ieee80211_ptr->iftype;
Johannes Berg55682962007-09-20 13:09:35 -04002495
Johannes Berg723b0382008-09-16 20:22:09 +02002496 if (info->attrs[NL80211_ATTR_IFTYPE]) {
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002497 ntype = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]);
Johannes Berg04a773a2009-04-19 21:24:32 +02002498 if (otype != ntype)
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002499 change = true;
Johannes Berg4c476992010-10-04 21:36:35 +02002500 if (ntype > NL80211_IFTYPE_MAX)
2501 return -EINVAL;
Johannes Berg723b0382008-09-16 20:22:09 +02002502 }
2503
Johannes Berg92ffe052008-09-16 20:39:36 +02002504 if (info->attrs[NL80211_ATTR_MESH_ID]) {
Johannes Berg29cbe682010-12-03 09:20:44 +01002505 struct wireless_dev *wdev = dev->ieee80211_ptr;
2506
Johannes Berg4c476992010-10-04 21:36:35 +02002507 if (ntype != NL80211_IFTYPE_MESH_POINT)
2508 return -EINVAL;
Johannes Berg29cbe682010-12-03 09:20:44 +01002509 if (netif_running(dev))
2510 return -EBUSY;
2511
2512 wdev_lock(wdev);
2513 BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN !=
2514 IEEE80211_MAX_MESH_ID_LEN);
2515 wdev->mesh_id_up_len =
2516 nla_len(info->attrs[NL80211_ATTR_MESH_ID]);
2517 memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]),
2518 wdev->mesh_id_up_len);
2519 wdev_unlock(wdev);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002520 }
2521
Felix Fietkau8b787642009-11-10 18:53:10 +01002522 if (info->attrs[NL80211_ATTR_4ADDR]) {
2523 params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]);
2524 change = true;
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002525 err = nl80211_valid_4addr(rdev, dev, params.use_4addr, ntype);
Johannes Berg9bc383d2009-11-19 11:55:19 +01002526 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02002527 return err;
Felix Fietkau8b787642009-11-10 18:53:10 +01002528 } else {
2529 params.use_4addr = -1;
2530 }
2531
Johannes Berg92ffe052008-09-16 20:39:36 +02002532 if (info->attrs[NL80211_ATTR_MNTR_FLAGS]) {
Johannes Berg4c476992010-10-04 21:36:35 +02002533 if (ntype != NL80211_IFTYPE_MONITOR)
2534 return -EINVAL;
Johannes Berg92ffe052008-09-16 20:39:36 +02002535 err = parse_monitor_flags(info->attrs[NL80211_ATTR_MNTR_FLAGS],
2536 &_flags);
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002537 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02002538 return err;
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002539
2540 flags = &_flags;
2541 change = true;
Johannes Berg92ffe052008-09-16 20:39:36 +02002542 }
Johannes Berg3b858752009-03-12 09:55:09 +01002543
Luciano Coelho18003292013-08-29 13:26:57 +03002544 if (flags && (*flags & MONITOR_FLAG_ACTIVE) &&
Felix Fietkaue057d3c2013-05-28 13:01:52 +02002545 !(rdev->wiphy.features & NL80211_FEATURE_ACTIVE_MONITOR))
2546 return -EOPNOTSUPP;
2547
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002548 if (change)
Johannes Berg3d54d252009-08-21 14:51:05 +02002549 err = cfg80211_change_iface(rdev, dev, ntype, flags, &params);
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002550 else
2551 err = 0;
Johannes Berg60719ff2008-09-16 14:55:09 +02002552
Johannes Berg9bc383d2009-11-19 11:55:19 +01002553 if (!err && params.use_4addr != -1)
2554 dev->ieee80211_ptr->use_4addr = params.use_4addr;
2555
Johannes Berg55682962007-09-20 13:09:35 -04002556 return err;
2557}
2558
2559static int nl80211_new_interface(struct sk_buff *skb, struct genl_info *info)
2560{
Johannes Berg4c476992010-10-04 21:36:35 +02002561 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002562 struct vif_params params;
Johannes Berg84efbb82012-06-16 00:00:26 +02002563 struct wireless_dev *wdev;
Johannes Berg1c90f9d2012-06-16 00:05:37 +02002564 struct sk_buff *msg;
Johannes Berg55682962007-09-20 13:09:35 -04002565 int err;
2566 enum nl80211_iftype type = NL80211_IFTYPE_UNSPECIFIED;
Michael Wu66f7ac52008-01-31 19:48:22 +01002567 u32 flags;
Johannes Berg55682962007-09-20 13:09:35 -04002568
Johannes Berg78f22b62014-03-24 17:57:27 +01002569 /* to avoid failing a new interface creation due to pending removal */
2570 cfg80211_destroy_ifaces(rdev);
2571
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002572 memset(&params, 0, sizeof(params));
2573
Johannes Berg55682962007-09-20 13:09:35 -04002574 if (!info->attrs[NL80211_ATTR_IFNAME])
2575 return -EINVAL;
2576
2577 if (info->attrs[NL80211_ATTR_IFTYPE]) {
2578 type = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]);
2579 if (type > NL80211_IFTYPE_MAX)
2580 return -EINVAL;
2581 }
2582
Johannes Berg79c97e92009-07-07 03:56:12 +02002583 if (!rdev->ops->add_virtual_intf ||
Johannes Berg4c476992010-10-04 21:36:35 +02002584 !(rdev->wiphy.interface_modes & (1 << type)))
2585 return -EOPNOTSUPP;
Johannes Berg55682962007-09-20 13:09:35 -04002586
Arend van Spriel1c18f142013-01-08 10:17:27 +01002587 if (type == NL80211_IFTYPE_P2P_DEVICE && info->attrs[NL80211_ATTR_MAC]) {
2588 nla_memcpy(params.macaddr, info->attrs[NL80211_ATTR_MAC],
2589 ETH_ALEN);
2590 if (!is_valid_ether_addr(params.macaddr))
2591 return -EADDRNOTAVAIL;
2592 }
2593
Johannes Berg9bc383d2009-11-19 11:55:19 +01002594 if (info->attrs[NL80211_ATTR_4ADDR]) {
Felix Fietkau8b787642009-11-10 18:53:10 +01002595 params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]);
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002596 err = nl80211_valid_4addr(rdev, NULL, params.use_4addr, type);
Johannes Berg9bc383d2009-11-19 11:55:19 +01002597 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02002598 return err;
Johannes Berg9bc383d2009-11-19 11:55:19 +01002599 }
Felix Fietkau8b787642009-11-10 18:53:10 +01002600
Johannes Berg1c90f9d2012-06-16 00:05:37 +02002601 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
2602 if (!msg)
2603 return -ENOMEM;
2604
Michael Wu66f7ac52008-01-31 19:48:22 +01002605 err = parse_monitor_flags(type == NL80211_IFTYPE_MONITOR ?
2606 info->attrs[NL80211_ATTR_MNTR_FLAGS] : NULL,
2607 &flags);
Felix Fietkaue057d3c2013-05-28 13:01:52 +02002608
Luciano Coelho18003292013-08-29 13:26:57 +03002609 if (!err && (flags & MONITOR_FLAG_ACTIVE) &&
Felix Fietkaue057d3c2013-05-28 13:01:52 +02002610 !(rdev->wiphy.features & NL80211_FEATURE_ACTIVE_MONITOR))
2611 return -EOPNOTSUPP;
2612
Hila Gonene35e4d22012-06-27 17:19:42 +03002613 wdev = rdev_add_virtual_intf(rdev,
2614 nla_data(info->attrs[NL80211_ATTR_IFNAME]),
2615 type, err ? NULL : &flags, &params);
Johannes Berg1c90f9d2012-06-16 00:05:37 +02002616 if (IS_ERR(wdev)) {
2617 nlmsg_free(msg);
Johannes Berg84efbb82012-06-16 00:00:26 +02002618 return PTR_ERR(wdev);
Johannes Berg1c90f9d2012-06-16 00:05:37 +02002619 }
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002620
Johannes Berg78f22b62014-03-24 17:57:27 +01002621 if (info->attrs[NL80211_ATTR_IFACE_SOCKET_OWNER])
2622 wdev->owner_nlportid = info->snd_portid;
2623
Johannes Berg98104fde2012-06-16 00:19:54 +02002624 switch (type) {
2625 case NL80211_IFTYPE_MESH_POINT:
2626 if (!info->attrs[NL80211_ATTR_MESH_ID])
2627 break;
Johannes Berg29cbe682010-12-03 09:20:44 +01002628 wdev_lock(wdev);
2629 BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN !=
2630 IEEE80211_MAX_MESH_ID_LEN);
2631 wdev->mesh_id_up_len =
2632 nla_len(info->attrs[NL80211_ATTR_MESH_ID]);
2633 memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]),
2634 wdev->mesh_id_up_len);
2635 wdev_unlock(wdev);
Johannes Berg98104fde2012-06-16 00:19:54 +02002636 break;
2637 case NL80211_IFTYPE_P2P_DEVICE:
2638 /*
2639 * P2P Device doesn't have a netdev, so doesn't go
2640 * through the netdev notifier and must be added here
2641 */
2642 mutex_init(&wdev->mtx);
2643 INIT_LIST_HEAD(&wdev->event_list);
2644 spin_lock_init(&wdev->event_lock);
2645 INIT_LIST_HEAD(&wdev->mgmt_registrations);
2646 spin_lock_init(&wdev->mgmt_registrations_lock);
2647
Johannes Berg98104fde2012-06-16 00:19:54 +02002648 wdev->identifier = ++rdev->wdev_id;
2649 list_add_rcu(&wdev->list, &rdev->wdev_list);
2650 rdev->devlist_generation++;
Johannes Berg98104fde2012-06-16 00:19:54 +02002651 break;
2652 default:
2653 break;
Johannes Berg29cbe682010-12-03 09:20:44 +01002654 }
2655
Eric W. Biederman15e47302012-09-07 20:12:54 +00002656 if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berg1c90f9d2012-06-16 00:05:37 +02002657 rdev, wdev) < 0) {
2658 nlmsg_free(msg);
2659 return -ENOBUFS;
2660 }
2661
2662 return genlmsg_reply(msg, info);
Johannes Berg55682962007-09-20 13:09:35 -04002663}
2664
2665static int nl80211_del_interface(struct sk_buff *skb, struct genl_info *info)
2666{
Johannes Berg4c476992010-10-04 21:36:35 +02002667 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg84efbb82012-06-16 00:00:26 +02002668 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg55682962007-09-20 13:09:35 -04002669
Johannes Berg4c476992010-10-04 21:36:35 +02002670 if (!rdev->ops->del_virtual_intf)
2671 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01002672
Johannes Berg84efbb82012-06-16 00:00:26 +02002673 /*
2674 * If we remove a wireless device without a netdev then clear
2675 * user_ptr[1] so that nl80211_post_doit won't dereference it
2676 * to check if it needs to do dev_put(). Otherwise it crashes
2677 * since the wdev has been freed, unlike with a netdev where
2678 * we need the dev_put() for the netdev to really be freed.
2679 */
2680 if (!wdev->netdev)
2681 info->user_ptr[1] = NULL;
2682
Hila Gonene35e4d22012-06-27 17:19:42 +03002683 return rdev_del_virtual_intf(rdev, wdev);
Johannes Berg55682962007-09-20 13:09:35 -04002684}
2685
Simon Wunderlich1d9d9212011-11-18 14:20:43 +01002686static int nl80211_set_noack_map(struct sk_buff *skb, struct genl_info *info)
2687{
2688 struct cfg80211_registered_device *rdev = info->user_ptr[0];
2689 struct net_device *dev = info->user_ptr[1];
2690 u16 noack_map;
2691
2692 if (!info->attrs[NL80211_ATTR_NOACK_MAP])
2693 return -EINVAL;
2694
2695 if (!rdev->ops->set_noack_map)
2696 return -EOPNOTSUPP;
2697
2698 noack_map = nla_get_u16(info->attrs[NL80211_ATTR_NOACK_MAP]);
2699
Hila Gonene35e4d22012-06-27 17:19:42 +03002700 return rdev_set_noack_map(rdev, dev, noack_map);
Simon Wunderlich1d9d9212011-11-18 14:20:43 +01002701}
2702
Johannes Berg41ade002007-12-19 02:03:29 +01002703struct get_key_cookie {
2704 struct sk_buff *msg;
2705 int error;
Johannes Bergb9454e82009-07-08 13:29:08 +02002706 int idx;
Johannes Berg41ade002007-12-19 02:03:29 +01002707};
2708
2709static void get_key_callback(void *c, struct key_params *params)
2710{
Johannes Bergb9454e82009-07-08 13:29:08 +02002711 struct nlattr *key;
Johannes Berg41ade002007-12-19 02:03:29 +01002712 struct get_key_cookie *cookie = c;
2713
David S. Miller9360ffd2012-03-29 04:41:26 -04002714 if ((params->key &&
2715 nla_put(cookie->msg, NL80211_ATTR_KEY_DATA,
2716 params->key_len, params->key)) ||
2717 (params->seq &&
2718 nla_put(cookie->msg, NL80211_ATTR_KEY_SEQ,
2719 params->seq_len, params->seq)) ||
2720 (params->cipher &&
2721 nla_put_u32(cookie->msg, NL80211_ATTR_KEY_CIPHER,
2722 params->cipher)))
2723 goto nla_put_failure;
Johannes Berg41ade002007-12-19 02:03:29 +01002724
Johannes Bergb9454e82009-07-08 13:29:08 +02002725 key = nla_nest_start(cookie->msg, NL80211_ATTR_KEY);
2726 if (!key)
2727 goto nla_put_failure;
2728
David S. Miller9360ffd2012-03-29 04:41:26 -04002729 if ((params->key &&
2730 nla_put(cookie->msg, NL80211_KEY_DATA,
2731 params->key_len, params->key)) ||
2732 (params->seq &&
2733 nla_put(cookie->msg, NL80211_KEY_SEQ,
2734 params->seq_len, params->seq)) ||
2735 (params->cipher &&
2736 nla_put_u32(cookie->msg, NL80211_KEY_CIPHER,
2737 params->cipher)))
2738 goto nla_put_failure;
Johannes Bergb9454e82009-07-08 13:29:08 +02002739
David S. Miller9360ffd2012-03-29 04:41:26 -04002740 if (nla_put_u8(cookie->msg, NL80211_ATTR_KEY_IDX, cookie->idx))
2741 goto nla_put_failure;
Johannes Bergb9454e82009-07-08 13:29:08 +02002742
2743 nla_nest_end(cookie->msg, key);
2744
Johannes Berg41ade002007-12-19 02:03:29 +01002745 return;
2746 nla_put_failure:
2747 cookie->error = 1;
2748}
2749
2750static int nl80211_get_key(struct sk_buff *skb, struct genl_info *info)
2751{
Johannes Berg4c476992010-10-04 21:36:35 +02002752 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg41ade002007-12-19 02:03:29 +01002753 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02002754 struct net_device *dev = info->user_ptr[1];
Johannes Berg41ade002007-12-19 02:03:29 +01002755 u8 key_idx = 0;
Johannes Berge31b8212010-10-05 19:39:30 +02002756 const u8 *mac_addr = NULL;
2757 bool pairwise;
Johannes Berg41ade002007-12-19 02:03:29 +01002758 struct get_key_cookie cookie = {
2759 .error = 0,
2760 };
2761 void *hdr;
2762 struct sk_buff *msg;
2763
2764 if (info->attrs[NL80211_ATTR_KEY_IDX])
2765 key_idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]);
2766
Jouni Malinen3cfcf6ac2009-01-08 13:32:02 +02002767 if (key_idx > 5)
Johannes Berg41ade002007-12-19 02:03:29 +01002768 return -EINVAL;
2769
2770 if (info->attrs[NL80211_ATTR_MAC])
2771 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
2772
Johannes Berge31b8212010-10-05 19:39:30 +02002773 pairwise = !!mac_addr;
2774 if (info->attrs[NL80211_ATTR_KEY_TYPE]) {
2775 u32 kt = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]);
2776 if (kt >= NUM_NL80211_KEYTYPES)
2777 return -EINVAL;
2778 if (kt != NL80211_KEYTYPE_GROUP &&
2779 kt != NL80211_KEYTYPE_PAIRWISE)
2780 return -EINVAL;
2781 pairwise = kt == NL80211_KEYTYPE_PAIRWISE;
2782 }
2783
Johannes Berg4c476992010-10-04 21:36:35 +02002784 if (!rdev->ops->get_key)
2785 return -EOPNOTSUPP;
Johannes Berg41ade002007-12-19 02:03:29 +01002786
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07002787 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02002788 if (!msg)
2789 return -ENOMEM;
Johannes Berg41ade002007-12-19 02:03:29 +01002790
Eric W. Biederman15e47302012-09-07 20:12:54 +00002791 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berg41ade002007-12-19 02:03:29 +01002792 NL80211_CMD_NEW_KEY);
Dan Carpentercb35fba2013-08-14 14:50:01 +03002793 if (!hdr)
Johannes Berg9fe271a2013-10-25 11:15:12 +02002794 goto nla_put_failure;
Johannes Berg41ade002007-12-19 02:03:29 +01002795
2796 cookie.msg = msg;
Johannes Bergb9454e82009-07-08 13:29:08 +02002797 cookie.idx = key_idx;
Johannes Berg41ade002007-12-19 02:03:29 +01002798
David S. Miller9360ffd2012-03-29 04:41:26 -04002799 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
2800 nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_idx))
2801 goto nla_put_failure;
2802 if (mac_addr &&
2803 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr))
2804 goto nla_put_failure;
Johannes Berg41ade002007-12-19 02:03:29 +01002805
Johannes Berge31b8212010-10-05 19:39:30 +02002806 if (pairwise && mac_addr &&
2807 !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN))
2808 return -ENOENT;
2809
Hila Gonene35e4d22012-06-27 17:19:42 +03002810 err = rdev_get_key(rdev, dev, key_idx, pairwise, mac_addr, &cookie,
2811 get_key_callback);
Johannes Berg41ade002007-12-19 02:03:29 +01002812
2813 if (err)
Niko Jokinen6c95e2a2009-07-15 11:00:53 +03002814 goto free_msg;
Johannes Berg41ade002007-12-19 02:03:29 +01002815
2816 if (cookie.error)
2817 goto nla_put_failure;
2818
2819 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02002820 return genlmsg_reply(msg, info);
Johannes Berg41ade002007-12-19 02:03:29 +01002821
2822 nla_put_failure:
2823 err = -ENOBUFS;
Niko Jokinen6c95e2a2009-07-15 11:00:53 +03002824 free_msg:
Johannes Berg41ade002007-12-19 02:03:29 +01002825 nlmsg_free(msg);
Johannes Berg41ade002007-12-19 02:03:29 +01002826 return err;
2827}
2828
2829static int nl80211_set_key(struct sk_buff *skb, struct genl_info *info)
2830{
Johannes Berg4c476992010-10-04 21:36:35 +02002831 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Bergb9454e82009-07-08 13:29:08 +02002832 struct key_parse key;
Johannes Berg41ade002007-12-19 02:03:29 +01002833 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02002834 struct net_device *dev = info->user_ptr[1];
Johannes Berg41ade002007-12-19 02:03:29 +01002835
Johannes Bergb9454e82009-07-08 13:29:08 +02002836 err = nl80211_parse_key(info, &key);
2837 if (err)
2838 return err;
2839
2840 if (key.idx < 0)
Johannes Berg41ade002007-12-19 02:03:29 +01002841 return -EINVAL;
2842
Johannes Bergb9454e82009-07-08 13:29:08 +02002843 /* only support setting default key */
2844 if (!key.def && !key.defmgmt)
Johannes Berg41ade002007-12-19 02:03:29 +01002845 return -EINVAL;
2846
Johannes Bergfffd0932009-07-08 14:22:54 +02002847 wdev_lock(dev->ieee80211_ptr);
Johannes Bergdbd2fd62010-12-09 19:58:59 +01002848
2849 if (key.def) {
2850 if (!rdev->ops->set_default_key) {
2851 err = -EOPNOTSUPP;
2852 goto out;
2853 }
2854
2855 err = nl80211_key_allowed(dev->ieee80211_ptr);
2856 if (err)
2857 goto out;
2858
Hila Gonene35e4d22012-06-27 17:19:42 +03002859 err = rdev_set_default_key(rdev, dev, key.idx,
Johannes Bergdbd2fd62010-12-09 19:58:59 +01002860 key.def_uni, key.def_multi);
2861
2862 if (err)
2863 goto out;
Johannes Bergfffd0932009-07-08 14:22:54 +02002864
Johannes Berg3d23e342009-09-29 23:27:28 +02002865#ifdef CONFIG_CFG80211_WEXT
Johannes Bergdbd2fd62010-12-09 19:58:59 +01002866 dev->ieee80211_ptr->wext.default_key = key.idx;
Johannes Berg08645122009-05-11 13:54:58 +02002867#endif
Johannes Bergdbd2fd62010-12-09 19:58:59 +01002868 } else {
2869 if (key.def_uni || !key.def_multi) {
2870 err = -EINVAL;
2871 goto out;
2872 }
2873
2874 if (!rdev->ops->set_default_mgmt_key) {
2875 err = -EOPNOTSUPP;
2876 goto out;
2877 }
2878
2879 err = nl80211_key_allowed(dev->ieee80211_ptr);
2880 if (err)
2881 goto out;
2882
Hila Gonene35e4d22012-06-27 17:19:42 +03002883 err = rdev_set_default_mgmt_key(rdev, dev, key.idx);
Johannes Bergdbd2fd62010-12-09 19:58:59 +01002884 if (err)
2885 goto out;
2886
2887#ifdef CONFIG_CFG80211_WEXT
2888 dev->ieee80211_ptr->wext.default_mgmt_key = key.idx;
2889#endif
2890 }
2891
2892 out:
Johannes Bergfffd0932009-07-08 14:22:54 +02002893 wdev_unlock(dev->ieee80211_ptr);
Johannes Berg41ade002007-12-19 02:03:29 +01002894
Johannes Berg41ade002007-12-19 02:03:29 +01002895 return err;
2896}
2897
2898static int nl80211_new_key(struct sk_buff *skb, struct genl_info *info)
2899{
Johannes Berg4c476992010-10-04 21:36:35 +02002900 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Bergfffd0932009-07-08 14:22:54 +02002901 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02002902 struct net_device *dev = info->user_ptr[1];
Johannes Bergb9454e82009-07-08 13:29:08 +02002903 struct key_parse key;
Johannes Berge31b8212010-10-05 19:39:30 +02002904 const u8 *mac_addr = NULL;
Johannes Berg41ade002007-12-19 02:03:29 +01002905
Johannes Bergb9454e82009-07-08 13:29:08 +02002906 err = nl80211_parse_key(info, &key);
2907 if (err)
2908 return err;
Johannes Berg41ade002007-12-19 02:03:29 +01002909
Johannes Bergb9454e82009-07-08 13:29:08 +02002910 if (!key.p.key)
Johannes Berg41ade002007-12-19 02:03:29 +01002911 return -EINVAL;
2912
Johannes Berg41ade002007-12-19 02:03:29 +01002913 if (info->attrs[NL80211_ATTR_MAC])
2914 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
2915
Johannes Berge31b8212010-10-05 19:39:30 +02002916 if (key.type == -1) {
2917 if (mac_addr)
2918 key.type = NL80211_KEYTYPE_PAIRWISE;
2919 else
2920 key.type = NL80211_KEYTYPE_GROUP;
2921 }
2922
2923 /* for now */
2924 if (key.type != NL80211_KEYTYPE_PAIRWISE &&
2925 key.type != NL80211_KEYTYPE_GROUP)
2926 return -EINVAL;
2927
Johannes Berg4c476992010-10-04 21:36:35 +02002928 if (!rdev->ops->add_key)
2929 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01002930
Johannes Berge31b8212010-10-05 19:39:30 +02002931 if (cfg80211_validate_key_settings(rdev, &key.p, key.idx,
2932 key.type == NL80211_KEYTYPE_PAIRWISE,
2933 mac_addr))
Johannes Berg4c476992010-10-04 21:36:35 +02002934 return -EINVAL;
Johannes Bergfffd0932009-07-08 14:22:54 +02002935
2936 wdev_lock(dev->ieee80211_ptr);
2937 err = nl80211_key_allowed(dev->ieee80211_ptr);
2938 if (!err)
Hila Gonene35e4d22012-06-27 17:19:42 +03002939 err = rdev_add_key(rdev, dev, key.idx,
2940 key.type == NL80211_KEYTYPE_PAIRWISE,
2941 mac_addr, &key.p);
Johannes Bergfffd0932009-07-08 14:22:54 +02002942 wdev_unlock(dev->ieee80211_ptr);
Johannes Berg41ade002007-12-19 02:03:29 +01002943
Johannes Berg41ade002007-12-19 02:03:29 +01002944 return err;
2945}
2946
2947static int nl80211_del_key(struct sk_buff *skb, struct genl_info *info)
2948{
Johannes Berg4c476992010-10-04 21:36:35 +02002949 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg41ade002007-12-19 02:03:29 +01002950 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02002951 struct net_device *dev = info->user_ptr[1];
Johannes Berg41ade002007-12-19 02:03:29 +01002952 u8 *mac_addr = NULL;
Johannes Bergb9454e82009-07-08 13:29:08 +02002953 struct key_parse key;
Johannes Berg41ade002007-12-19 02:03:29 +01002954
Johannes Bergb9454e82009-07-08 13:29:08 +02002955 err = nl80211_parse_key(info, &key);
2956 if (err)
2957 return err;
Johannes Berg41ade002007-12-19 02:03:29 +01002958
2959 if (info->attrs[NL80211_ATTR_MAC])
2960 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
2961
Johannes Berge31b8212010-10-05 19:39:30 +02002962 if (key.type == -1) {
2963 if (mac_addr)
2964 key.type = NL80211_KEYTYPE_PAIRWISE;
2965 else
2966 key.type = NL80211_KEYTYPE_GROUP;
2967 }
2968
2969 /* for now */
2970 if (key.type != NL80211_KEYTYPE_PAIRWISE &&
2971 key.type != NL80211_KEYTYPE_GROUP)
2972 return -EINVAL;
2973
Johannes Berg4c476992010-10-04 21:36:35 +02002974 if (!rdev->ops->del_key)
2975 return -EOPNOTSUPP;
Johannes Berg41ade002007-12-19 02:03:29 +01002976
Johannes Bergfffd0932009-07-08 14:22:54 +02002977 wdev_lock(dev->ieee80211_ptr);
2978 err = nl80211_key_allowed(dev->ieee80211_ptr);
Johannes Berge31b8212010-10-05 19:39:30 +02002979
2980 if (key.type == NL80211_KEYTYPE_PAIRWISE && mac_addr &&
2981 !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN))
2982 err = -ENOENT;
2983
Johannes Bergfffd0932009-07-08 14:22:54 +02002984 if (!err)
Hila Gonene35e4d22012-06-27 17:19:42 +03002985 err = rdev_del_key(rdev, dev, key.idx,
2986 key.type == NL80211_KEYTYPE_PAIRWISE,
2987 mac_addr);
Johannes Berg41ade002007-12-19 02:03:29 +01002988
Johannes Berg3d23e342009-09-29 23:27:28 +02002989#ifdef CONFIG_CFG80211_WEXT
Johannes Berg08645122009-05-11 13:54:58 +02002990 if (!err) {
Johannes Bergb9454e82009-07-08 13:29:08 +02002991 if (key.idx == dev->ieee80211_ptr->wext.default_key)
Johannes Berg08645122009-05-11 13:54:58 +02002992 dev->ieee80211_ptr->wext.default_key = -1;
Johannes Bergb9454e82009-07-08 13:29:08 +02002993 else if (key.idx == dev->ieee80211_ptr->wext.default_mgmt_key)
Johannes Berg08645122009-05-11 13:54:58 +02002994 dev->ieee80211_ptr->wext.default_mgmt_key = -1;
2995 }
2996#endif
Johannes Bergfffd0932009-07-08 14:22:54 +02002997 wdev_unlock(dev->ieee80211_ptr);
Johannes Berg08645122009-05-11 13:54:58 +02002998
Johannes Berg41ade002007-12-19 02:03:29 +01002999 return err;
3000}
3001
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +05303002/* This function returns an error or the number of nested attributes */
3003static int validate_acl_mac_addrs(struct nlattr *nl_attr)
3004{
3005 struct nlattr *attr;
3006 int n_entries = 0, tmp;
3007
3008 nla_for_each_nested(attr, nl_attr, tmp) {
3009 if (nla_len(attr) != ETH_ALEN)
3010 return -EINVAL;
3011
3012 n_entries++;
3013 }
3014
3015 return n_entries;
3016}
3017
3018/*
3019 * This function parses ACL information and allocates memory for ACL data.
3020 * On successful return, the calling function is responsible to free the
3021 * ACL buffer returned by this function.
3022 */
3023static struct cfg80211_acl_data *parse_acl_data(struct wiphy *wiphy,
3024 struct genl_info *info)
3025{
3026 enum nl80211_acl_policy acl_policy;
3027 struct nlattr *attr;
3028 struct cfg80211_acl_data *acl;
3029 int i = 0, n_entries, tmp;
3030
3031 if (!wiphy->max_acl_mac_addrs)
3032 return ERR_PTR(-EOPNOTSUPP);
3033
3034 if (!info->attrs[NL80211_ATTR_ACL_POLICY])
3035 return ERR_PTR(-EINVAL);
3036
3037 acl_policy = nla_get_u32(info->attrs[NL80211_ATTR_ACL_POLICY]);
3038 if (acl_policy != NL80211_ACL_POLICY_ACCEPT_UNLESS_LISTED &&
3039 acl_policy != NL80211_ACL_POLICY_DENY_UNLESS_LISTED)
3040 return ERR_PTR(-EINVAL);
3041
3042 if (!info->attrs[NL80211_ATTR_MAC_ADDRS])
3043 return ERR_PTR(-EINVAL);
3044
3045 n_entries = validate_acl_mac_addrs(info->attrs[NL80211_ATTR_MAC_ADDRS]);
3046 if (n_entries < 0)
3047 return ERR_PTR(n_entries);
3048
3049 if (n_entries > wiphy->max_acl_mac_addrs)
3050 return ERR_PTR(-ENOTSUPP);
3051
3052 acl = kzalloc(sizeof(*acl) + (sizeof(struct mac_address) * n_entries),
3053 GFP_KERNEL);
3054 if (!acl)
3055 return ERR_PTR(-ENOMEM);
3056
3057 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_MAC_ADDRS], tmp) {
3058 memcpy(acl->mac_addrs[i].addr, nla_data(attr), ETH_ALEN);
3059 i++;
3060 }
3061
3062 acl->n_acl_entries = n_entries;
3063 acl->acl_policy = acl_policy;
3064
3065 return acl;
3066}
3067
3068static int nl80211_set_mac_acl(struct sk_buff *skb, struct genl_info *info)
3069{
3070 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3071 struct net_device *dev = info->user_ptr[1];
3072 struct cfg80211_acl_data *acl;
3073 int err;
3074
3075 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
3076 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
3077 return -EOPNOTSUPP;
3078
3079 if (!dev->ieee80211_ptr->beacon_interval)
3080 return -EINVAL;
3081
3082 acl = parse_acl_data(&rdev->wiphy, info);
3083 if (IS_ERR(acl))
3084 return PTR_ERR(acl);
3085
3086 err = rdev_set_mac_acl(rdev, dev, acl);
3087
3088 kfree(acl);
3089
3090 return err;
3091}
3092
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003093static int nl80211_parse_beacon(struct nlattr *attrs[],
Johannes Berg88600202012-02-13 15:17:18 +01003094 struct cfg80211_beacon_data *bcn)
Johannes Berged1b6cc2007-12-19 02:03:32 +01003095{
Johannes Berg88600202012-02-13 15:17:18 +01003096 bool haveinfo = false;
Johannes Berged1b6cc2007-12-19 02:03:32 +01003097
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003098 if (!is_valid_ie_attr(attrs[NL80211_ATTR_BEACON_TAIL]) ||
3099 !is_valid_ie_attr(attrs[NL80211_ATTR_IE]) ||
3100 !is_valid_ie_attr(attrs[NL80211_ATTR_IE_PROBE_RESP]) ||
3101 !is_valid_ie_attr(attrs[NL80211_ATTR_IE_ASSOC_RESP]))
Johannes Bergf4a11bb2009-03-27 12:40:28 +01003102 return -EINVAL;
3103
Johannes Berg88600202012-02-13 15:17:18 +01003104 memset(bcn, 0, sizeof(*bcn));
Johannes Berged1b6cc2007-12-19 02:03:32 +01003105
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003106 if (attrs[NL80211_ATTR_BEACON_HEAD]) {
3107 bcn->head = nla_data(attrs[NL80211_ATTR_BEACON_HEAD]);
3108 bcn->head_len = nla_len(attrs[NL80211_ATTR_BEACON_HEAD]);
Johannes Berg88600202012-02-13 15:17:18 +01003109 if (!bcn->head_len)
3110 return -EINVAL;
3111 haveinfo = true;
Johannes Berged1b6cc2007-12-19 02:03:32 +01003112 }
3113
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003114 if (attrs[NL80211_ATTR_BEACON_TAIL]) {
3115 bcn->tail = nla_data(attrs[NL80211_ATTR_BEACON_TAIL]);
3116 bcn->tail_len = nla_len(attrs[NL80211_ATTR_BEACON_TAIL]);
Johannes Berg88600202012-02-13 15:17:18 +01003117 haveinfo = true;
Johannes Berged1b6cc2007-12-19 02:03:32 +01003118 }
3119
Johannes Berg4c476992010-10-04 21:36:35 +02003120 if (!haveinfo)
3121 return -EINVAL;
Johannes Berged1b6cc2007-12-19 02:03:32 +01003122
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003123 if (attrs[NL80211_ATTR_IE]) {
3124 bcn->beacon_ies = nla_data(attrs[NL80211_ATTR_IE]);
3125 bcn->beacon_ies_len = nla_len(attrs[NL80211_ATTR_IE]);
Jouni Malinen9946ecf2011-08-10 23:55:56 +03003126 }
3127
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003128 if (attrs[NL80211_ATTR_IE_PROBE_RESP]) {
Johannes Berg88600202012-02-13 15:17:18 +01003129 bcn->proberesp_ies =
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003130 nla_data(attrs[NL80211_ATTR_IE_PROBE_RESP]);
Johannes Berg88600202012-02-13 15:17:18 +01003131 bcn->proberesp_ies_len =
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003132 nla_len(attrs[NL80211_ATTR_IE_PROBE_RESP]);
Jouni Malinen9946ecf2011-08-10 23:55:56 +03003133 }
3134
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003135 if (attrs[NL80211_ATTR_IE_ASSOC_RESP]) {
Johannes Berg88600202012-02-13 15:17:18 +01003136 bcn->assocresp_ies =
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003137 nla_data(attrs[NL80211_ATTR_IE_ASSOC_RESP]);
Johannes Berg88600202012-02-13 15:17:18 +01003138 bcn->assocresp_ies_len =
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003139 nla_len(attrs[NL80211_ATTR_IE_ASSOC_RESP]);
Jouni Malinen9946ecf2011-08-10 23:55:56 +03003140 }
3141
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003142 if (attrs[NL80211_ATTR_PROBE_RESP]) {
3143 bcn->probe_resp = nla_data(attrs[NL80211_ATTR_PROBE_RESP]);
3144 bcn->probe_resp_len = nla_len(attrs[NL80211_ATTR_PROBE_RESP]);
Arik Nemtsov00f740e2011-11-10 11:28:56 +02003145 }
3146
Johannes Berg88600202012-02-13 15:17:18 +01003147 return 0;
3148}
3149
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003150static bool nl80211_get_ap_channel(struct cfg80211_registered_device *rdev,
3151 struct cfg80211_ap_settings *params)
3152{
3153 struct wireless_dev *wdev;
3154 bool ret = false;
3155
Johannes Berg89a54e42012-06-15 14:33:17 +02003156 list_for_each_entry(wdev, &rdev->wdev_list, list) {
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003157 if (wdev->iftype != NL80211_IFTYPE_AP &&
3158 wdev->iftype != NL80211_IFTYPE_P2P_GO)
3159 continue;
3160
Johannes Berg683b6d32012-11-08 21:25:48 +01003161 if (!wdev->preset_chandef.chan)
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003162 continue;
3163
Johannes Berg683b6d32012-11-08 21:25:48 +01003164 params->chandef = wdev->preset_chandef;
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003165 ret = true;
3166 break;
3167 }
3168
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003169 return ret;
3170}
3171
Jouni Malinene39e5b52012-09-30 19:29:39 +03003172static bool nl80211_valid_auth_type(struct cfg80211_registered_device *rdev,
3173 enum nl80211_auth_type auth_type,
3174 enum nl80211_commands cmd)
3175{
3176 if (auth_type > NL80211_AUTHTYPE_MAX)
3177 return false;
3178
3179 switch (cmd) {
3180 case NL80211_CMD_AUTHENTICATE:
3181 if (!(rdev->wiphy.features & NL80211_FEATURE_SAE) &&
3182 auth_type == NL80211_AUTHTYPE_SAE)
3183 return false;
3184 return true;
3185 case NL80211_CMD_CONNECT:
3186 case NL80211_CMD_START_AP:
3187 /* SAE not supported yet */
3188 if (auth_type == NL80211_AUTHTYPE_SAE)
3189 return false;
3190 return true;
3191 default:
3192 return false;
3193 }
3194}
3195
Johannes Berg88600202012-02-13 15:17:18 +01003196static int nl80211_start_ap(struct sk_buff *skb, struct genl_info *info)
3197{
3198 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3199 struct net_device *dev = info->user_ptr[1];
3200 struct wireless_dev *wdev = dev->ieee80211_ptr;
3201 struct cfg80211_ap_settings params;
3202 int err;
3203
3204 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
3205 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
3206 return -EOPNOTSUPP;
3207
3208 if (!rdev->ops->start_ap)
3209 return -EOPNOTSUPP;
3210
3211 if (wdev->beacon_interval)
3212 return -EALREADY;
3213
3214 memset(&params, 0, sizeof(params));
3215
3216 /* these are required for START_AP */
3217 if (!info->attrs[NL80211_ATTR_BEACON_INTERVAL] ||
3218 !info->attrs[NL80211_ATTR_DTIM_PERIOD] ||
3219 !info->attrs[NL80211_ATTR_BEACON_HEAD])
3220 return -EINVAL;
3221
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003222 err = nl80211_parse_beacon(info->attrs, &params.beacon);
Johannes Berg88600202012-02-13 15:17:18 +01003223 if (err)
3224 return err;
3225
3226 params.beacon_interval =
3227 nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]);
3228 params.dtim_period =
3229 nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]);
3230
3231 err = cfg80211_validate_beacon_int(rdev, params.beacon_interval);
3232 if (err)
3233 return err;
3234
3235 /*
3236 * In theory, some of these attributes should be required here
3237 * but since they were not used when the command was originally
3238 * added, keep them optional for old user space programs to let
3239 * them continue to work with drivers that do not need the
3240 * additional information -- drivers must check!
3241 */
3242 if (info->attrs[NL80211_ATTR_SSID]) {
3243 params.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
3244 params.ssid_len =
3245 nla_len(info->attrs[NL80211_ATTR_SSID]);
3246 if (params.ssid_len == 0 ||
3247 params.ssid_len > IEEE80211_MAX_SSID_LEN)
3248 return -EINVAL;
3249 }
3250
3251 if (info->attrs[NL80211_ATTR_HIDDEN_SSID]) {
3252 params.hidden_ssid = nla_get_u32(
3253 info->attrs[NL80211_ATTR_HIDDEN_SSID]);
3254 if (params.hidden_ssid != NL80211_HIDDEN_SSID_NOT_IN_USE &&
3255 params.hidden_ssid != NL80211_HIDDEN_SSID_ZERO_LEN &&
3256 params.hidden_ssid != NL80211_HIDDEN_SSID_ZERO_CONTENTS)
3257 return -EINVAL;
3258 }
3259
3260 params.privacy = !!info->attrs[NL80211_ATTR_PRIVACY];
3261
3262 if (info->attrs[NL80211_ATTR_AUTH_TYPE]) {
3263 params.auth_type = nla_get_u32(
3264 info->attrs[NL80211_ATTR_AUTH_TYPE]);
Jouni Malinene39e5b52012-09-30 19:29:39 +03003265 if (!nl80211_valid_auth_type(rdev, params.auth_type,
3266 NL80211_CMD_START_AP))
Johannes Berg88600202012-02-13 15:17:18 +01003267 return -EINVAL;
3268 } else
3269 params.auth_type = NL80211_AUTHTYPE_AUTOMATIC;
3270
3271 err = nl80211_crypto_settings(rdev, info, &params.crypto,
3272 NL80211_MAX_NR_CIPHER_SUITES);
3273 if (err)
3274 return err;
3275
Vasanthakumar Thiagarajan1b658f12012-03-02 15:50:02 +05303276 if (info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]) {
3277 if (!(rdev->wiphy.features & NL80211_FEATURE_INACTIVITY_TIMER))
3278 return -EOPNOTSUPP;
3279 params.inactivity_timeout = nla_get_u16(
3280 info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]);
3281 }
3282
Johannes Berg53cabad2012-11-14 15:17:28 +01003283 if (info->attrs[NL80211_ATTR_P2P_CTWINDOW]) {
3284 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
3285 return -EINVAL;
3286 params.p2p_ctwindow =
3287 nla_get_u8(info->attrs[NL80211_ATTR_P2P_CTWINDOW]);
3288 if (params.p2p_ctwindow > 127)
3289 return -EINVAL;
3290 if (params.p2p_ctwindow != 0 &&
3291 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_CTWIN))
3292 return -EINVAL;
3293 }
3294
3295 if (info->attrs[NL80211_ATTR_P2P_OPPPS]) {
3296 u8 tmp;
3297
3298 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
3299 return -EINVAL;
3300 tmp = nla_get_u8(info->attrs[NL80211_ATTR_P2P_OPPPS]);
3301 if (tmp > 1)
3302 return -EINVAL;
3303 params.p2p_opp_ps = tmp;
3304 if (params.p2p_opp_ps != 0 &&
3305 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_OPPPS))
3306 return -EINVAL;
3307 }
3308
Johannes Bergaa430da2012-05-16 23:50:18 +02003309 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
Johannes Berg683b6d32012-11-08 21:25:48 +01003310 err = nl80211_parse_chandef(rdev, info, &params.chandef);
3311 if (err)
3312 return err;
3313 } else if (wdev->preset_chandef.chan) {
3314 params.chandef = wdev->preset_chandef;
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003315 } else if (!nl80211_get_ap_channel(rdev, &params))
Johannes Bergaa430da2012-05-16 23:50:18 +02003316 return -EINVAL;
3317
Ilan Peer174e0cd2014-02-23 09:13:01 +02003318 if (!cfg80211_reg_can_beacon(&rdev->wiphy, &params.chandef,
3319 wdev->iftype))
Johannes Bergaa430da2012-05-16 23:50:18 +02003320 return -EINVAL;
3321
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +05303322 if (info->attrs[NL80211_ATTR_ACL_POLICY]) {
3323 params.acl = parse_acl_data(&rdev->wiphy, info);
3324 if (IS_ERR(params.acl))
3325 return PTR_ERR(params.acl);
3326 }
3327
Simon Wunderlichc56589e2013-11-21 18:19:49 +01003328 wdev_lock(wdev);
Hila Gonene35e4d22012-06-27 17:19:42 +03003329 err = rdev_start_ap(rdev, dev, &params);
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003330 if (!err) {
Johannes Berg683b6d32012-11-08 21:25:48 +01003331 wdev->preset_chandef = params.chandef;
Johannes Berg88600202012-02-13 15:17:18 +01003332 wdev->beacon_interval = params.beacon_interval;
Michal Kazior9e0e2962014-01-29 14:22:27 +01003333 wdev->chandef = params.chandef;
Antonio Quartulli06e191e2012-11-07 12:52:19 +01003334 wdev->ssid_len = params.ssid_len;
3335 memcpy(wdev->ssid, params.ssid, wdev->ssid_len);
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003336 }
Simon Wunderlichc56589e2013-11-21 18:19:49 +01003337 wdev_unlock(wdev);
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +05303338
3339 kfree(params.acl);
3340
Johannes Berg56d18932011-05-09 18:41:15 +02003341 return err;
Johannes Berged1b6cc2007-12-19 02:03:32 +01003342}
3343
Johannes Berg88600202012-02-13 15:17:18 +01003344static int nl80211_set_beacon(struct sk_buff *skb, struct genl_info *info)
3345{
3346 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3347 struct net_device *dev = info->user_ptr[1];
3348 struct wireless_dev *wdev = dev->ieee80211_ptr;
3349 struct cfg80211_beacon_data params;
3350 int err;
3351
3352 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
3353 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
3354 return -EOPNOTSUPP;
3355
3356 if (!rdev->ops->change_beacon)
3357 return -EOPNOTSUPP;
3358
3359 if (!wdev->beacon_interval)
3360 return -EINVAL;
3361
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003362 err = nl80211_parse_beacon(info->attrs, &params);
Johannes Berg88600202012-02-13 15:17:18 +01003363 if (err)
3364 return err;
3365
Simon Wunderlichc56589e2013-11-21 18:19:49 +01003366 wdev_lock(wdev);
3367 err = rdev_change_beacon(rdev, dev, &params);
3368 wdev_unlock(wdev);
3369
3370 return err;
Johannes Berg88600202012-02-13 15:17:18 +01003371}
3372
3373static int nl80211_stop_ap(struct sk_buff *skb, struct genl_info *info)
Johannes Berged1b6cc2007-12-19 02:03:32 +01003374{
Johannes Berg4c476992010-10-04 21:36:35 +02003375 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3376 struct net_device *dev = info->user_ptr[1];
Johannes Berged1b6cc2007-12-19 02:03:32 +01003377
Ilan Peer7c8d5e02014-02-25 15:33:38 +02003378 return cfg80211_stop_ap(rdev, dev, false);
Johannes Berged1b6cc2007-12-19 02:03:32 +01003379}
3380
Johannes Berg5727ef12007-12-19 02:03:34 +01003381static const struct nla_policy sta_flags_policy[NL80211_STA_FLAG_MAX + 1] = {
3382 [NL80211_STA_FLAG_AUTHORIZED] = { .type = NLA_FLAG },
3383 [NL80211_STA_FLAG_SHORT_PREAMBLE] = { .type = NLA_FLAG },
3384 [NL80211_STA_FLAG_WME] = { .type = NLA_FLAG },
Jouni Malinen0e467242009-05-11 21:57:55 +03003385 [NL80211_STA_FLAG_MFP] = { .type = NLA_FLAG },
Javier Cardonab39c48f2011-04-07 15:08:30 -07003386 [NL80211_STA_FLAG_AUTHENTICATED] = { .type = NLA_FLAG },
Johannes Bergd83023d2011-12-14 09:29:15 +01003387 [NL80211_STA_FLAG_TDLS_PEER] = { .type = NLA_FLAG },
Johannes Berg5727ef12007-12-19 02:03:34 +01003388};
3389
Johannes Bergeccb8e82009-05-11 21:57:56 +03003390static int parse_station_flags(struct genl_info *info,
Johannes Bergbdd3ae32012-01-02 13:30:03 +01003391 enum nl80211_iftype iftype,
Johannes Bergeccb8e82009-05-11 21:57:56 +03003392 struct station_parameters *params)
Johannes Berg5727ef12007-12-19 02:03:34 +01003393{
3394 struct nlattr *flags[NL80211_STA_FLAG_MAX + 1];
Johannes Bergeccb8e82009-05-11 21:57:56 +03003395 struct nlattr *nla;
Johannes Berg5727ef12007-12-19 02:03:34 +01003396 int flag;
3397
Johannes Bergeccb8e82009-05-11 21:57:56 +03003398 /*
3399 * Try parsing the new attribute first so userspace
3400 * can specify both for older kernels.
3401 */
3402 nla = info->attrs[NL80211_ATTR_STA_FLAGS2];
3403 if (nla) {
3404 struct nl80211_sta_flag_update *sta_flags;
Johannes Berg5727ef12007-12-19 02:03:34 +01003405
Johannes Bergeccb8e82009-05-11 21:57:56 +03003406 sta_flags = nla_data(nla);
3407 params->sta_flags_mask = sta_flags->mask;
3408 params->sta_flags_set = sta_flags->set;
Johannes Berg77ee7c82013-02-15 00:48:33 +01003409 params->sta_flags_set &= params->sta_flags_mask;
Johannes Bergeccb8e82009-05-11 21:57:56 +03003410 if ((params->sta_flags_mask |
3411 params->sta_flags_set) & BIT(__NL80211_STA_FLAG_INVALID))
3412 return -EINVAL;
3413 return 0;
3414 }
3415
3416 /* if present, parse the old attribute */
3417
3418 nla = info->attrs[NL80211_ATTR_STA_FLAGS];
Johannes Berg5727ef12007-12-19 02:03:34 +01003419 if (!nla)
3420 return 0;
3421
3422 if (nla_parse_nested(flags, NL80211_STA_FLAG_MAX,
3423 nla, sta_flags_policy))
3424 return -EINVAL;
3425
Johannes Bergbdd3ae32012-01-02 13:30:03 +01003426 /*
3427 * Only allow certain flags for interface types so that
3428 * other attributes are silently ignored. Remember that
3429 * this is backward compatibility code with old userspace
3430 * and shouldn't be hit in other cases anyway.
3431 */
3432 switch (iftype) {
3433 case NL80211_IFTYPE_AP:
3434 case NL80211_IFTYPE_AP_VLAN:
3435 case NL80211_IFTYPE_P2P_GO:
3436 params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) |
3437 BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) |
3438 BIT(NL80211_STA_FLAG_WME) |
3439 BIT(NL80211_STA_FLAG_MFP);
3440 break;
3441 case NL80211_IFTYPE_P2P_CLIENT:
3442 case NL80211_IFTYPE_STATION:
3443 params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) |
3444 BIT(NL80211_STA_FLAG_TDLS_PEER);
3445 break;
3446 case NL80211_IFTYPE_MESH_POINT:
3447 params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHENTICATED) |
3448 BIT(NL80211_STA_FLAG_MFP) |
3449 BIT(NL80211_STA_FLAG_AUTHORIZED);
3450 default:
3451 return -EINVAL;
3452 }
Johannes Berg5727ef12007-12-19 02:03:34 +01003453
Johannes Berg3383b5a2012-05-10 20:14:43 +02003454 for (flag = 1; flag <= NL80211_STA_FLAG_MAX; flag++) {
3455 if (flags[flag]) {
Johannes Bergeccb8e82009-05-11 21:57:56 +03003456 params->sta_flags_set |= (1<<flag);
Johannes Berg5727ef12007-12-19 02:03:34 +01003457
Johannes Berg3383b5a2012-05-10 20:14:43 +02003458 /* no longer support new API additions in old API */
3459 if (flag > NL80211_STA_FLAG_MAX_OLD_API)
3460 return -EINVAL;
3461 }
3462 }
3463
Johannes Berg5727ef12007-12-19 02:03:34 +01003464 return 0;
3465}
3466
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003467static bool nl80211_put_sta_rate(struct sk_buff *msg, struct rate_info *info,
3468 int attr)
3469{
3470 struct nlattr *rate;
Vladimir Kondratiev8eb41c82012-07-05 14:25:49 +03003471 u32 bitrate;
3472 u16 bitrate_compat;
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003473
3474 rate = nla_nest_start(msg, attr);
3475 if (!rate)
Johannes Bergdb9c64c2012-11-09 14:56:41 +01003476 return false;
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003477
3478 /* cfg80211_calculate_bitrate will return 0 for mcs >= 32 */
3479 bitrate = cfg80211_calculate_bitrate(info);
Vladimir Kondratiev8eb41c82012-07-05 14:25:49 +03003480 /* report 16-bit bitrate only if we can */
3481 bitrate_compat = bitrate < (1UL << 16) ? bitrate : 0;
Johannes Bergdb9c64c2012-11-09 14:56:41 +01003482 if (bitrate > 0 &&
3483 nla_put_u32(msg, NL80211_RATE_INFO_BITRATE32, bitrate))
3484 return false;
3485 if (bitrate_compat > 0 &&
3486 nla_put_u16(msg, NL80211_RATE_INFO_BITRATE, bitrate_compat))
3487 return false;
3488
3489 if (info->flags & RATE_INFO_FLAGS_MCS) {
3490 if (nla_put_u8(msg, NL80211_RATE_INFO_MCS, info->mcs))
3491 return false;
3492 if (info->flags & RATE_INFO_FLAGS_40_MHZ_WIDTH &&
3493 nla_put_flag(msg, NL80211_RATE_INFO_40_MHZ_WIDTH))
3494 return false;
3495 if (info->flags & RATE_INFO_FLAGS_SHORT_GI &&
3496 nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI))
3497 return false;
3498 } else if (info->flags & RATE_INFO_FLAGS_VHT_MCS) {
3499 if (nla_put_u8(msg, NL80211_RATE_INFO_VHT_MCS, info->mcs))
3500 return false;
3501 if (nla_put_u8(msg, NL80211_RATE_INFO_VHT_NSS, info->nss))
3502 return false;
3503 if (info->flags & RATE_INFO_FLAGS_40_MHZ_WIDTH &&
3504 nla_put_flag(msg, NL80211_RATE_INFO_40_MHZ_WIDTH))
3505 return false;
3506 if (info->flags & RATE_INFO_FLAGS_80_MHZ_WIDTH &&
3507 nla_put_flag(msg, NL80211_RATE_INFO_80_MHZ_WIDTH))
3508 return false;
3509 if (info->flags & RATE_INFO_FLAGS_80P80_MHZ_WIDTH &&
3510 nla_put_flag(msg, NL80211_RATE_INFO_80P80_MHZ_WIDTH))
3511 return false;
3512 if (info->flags & RATE_INFO_FLAGS_160_MHZ_WIDTH &&
3513 nla_put_flag(msg, NL80211_RATE_INFO_160_MHZ_WIDTH))
3514 return false;
3515 if (info->flags & RATE_INFO_FLAGS_SHORT_GI &&
3516 nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI))
3517 return false;
3518 }
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003519
3520 nla_nest_end(msg, rate);
3521 return true;
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003522}
3523
Felix Fietkau119363c2013-04-22 16:29:30 +02003524static bool nl80211_put_signal(struct sk_buff *msg, u8 mask, s8 *signal,
3525 int id)
3526{
3527 void *attr;
3528 int i = 0;
3529
3530 if (!mask)
3531 return true;
3532
3533 attr = nla_nest_start(msg, id);
3534 if (!attr)
3535 return false;
3536
3537 for (i = 0; i < IEEE80211_MAX_CHAINS; i++) {
3538 if (!(mask & BIT(i)))
3539 continue;
3540
3541 if (nla_put_u8(msg, i, signal[i]))
3542 return false;
3543 }
3544
3545 nla_nest_end(msg, attr);
3546
3547 return true;
3548}
3549
Eric W. Biederman15e47302012-09-07 20:12:54 +00003550static int nl80211_send_station(struct sk_buff *msg, u32 portid, u32 seq,
John W. Linville66266b32012-03-15 13:25:41 -04003551 int flags,
3552 struct cfg80211_registered_device *rdev,
3553 struct net_device *dev,
Johannes Berg98b62182009-12-23 13:15:44 +01003554 const u8 *mac_addr, struct station_info *sinfo)
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003555{
3556 void *hdr;
Paul Stewartf4263c92011-03-31 09:25:41 -07003557 struct nlattr *sinfoattr, *bss_param;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003558
Eric W. Biederman15e47302012-09-07 20:12:54 +00003559 hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_STATION);
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003560 if (!hdr)
3561 return -1;
3562
David S. Miller9360ffd2012-03-29 04:41:26 -04003563 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
3564 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) ||
3565 nla_put_u32(msg, NL80211_ATTR_GENERATION, sinfo->generation))
3566 goto nla_put_failure;
Johannes Bergf5ea9122009-08-07 16:17:38 +02003567
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003568 sinfoattr = nla_nest_start(msg, NL80211_ATTR_STA_INFO);
3569 if (!sinfoattr)
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003570 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04003571 if ((sinfo->filled & STATION_INFO_CONNECTED_TIME) &&
3572 nla_put_u32(msg, NL80211_STA_INFO_CONNECTED_TIME,
3573 sinfo->connected_time))
3574 goto nla_put_failure;
3575 if ((sinfo->filled & STATION_INFO_INACTIVE_TIME) &&
3576 nla_put_u32(msg, NL80211_STA_INFO_INACTIVE_TIME,
3577 sinfo->inactive_time))
3578 goto nla_put_failure;
Vladimir Kondratiev42745e02013-02-04 13:53:11 +02003579 if ((sinfo->filled & (STATION_INFO_RX_BYTES |
3580 STATION_INFO_RX_BYTES64)) &&
David S. Miller9360ffd2012-03-29 04:41:26 -04003581 nla_put_u32(msg, NL80211_STA_INFO_RX_BYTES,
Vladimir Kondratiev42745e02013-02-04 13:53:11 +02003582 (u32)sinfo->rx_bytes))
3583 goto nla_put_failure;
3584 if ((sinfo->filled & (STATION_INFO_TX_BYTES |
Felix Fietkau4325d722013-05-23 15:05:59 +02003585 STATION_INFO_TX_BYTES64)) &&
Vladimir Kondratiev42745e02013-02-04 13:53:11 +02003586 nla_put_u32(msg, NL80211_STA_INFO_TX_BYTES,
3587 (u32)sinfo->tx_bytes))
3588 goto nla_put_failure;
3589 if ((sinfo->filled & STATION_INFO_RX_BYTES64) &&
3590 nla_put_u64(msg, NL80211_STA_INFO_RX_BYTES64,
David S. Miller9360ffd2012-03-29 04:41:26 -04003591 sinfo->rx_bytes))
3592 goto nla_put_failure;
Vladimir Kondratiev42745e02013-02-04 13:53:11 +02003593 if ((sinfo->filled & STATION_INFO_TX_BYTES64) &&
3594 nla_put_u64(msg, NL80211_STA_INFO_TX_BYTES64,
David S. Miller9360ffd2012-03-29 04:41:26 -04003595 sinfo->tx_bytes))
3596 goto nla_put_failure;
3597 if ((sinfo->filled & STATION_INFO_LLID) &&
3598 nla_put_u16(msg, NL80211_STA_INFO_LLID, sinfo->llid))
3599 goto nla_put_failure;
3600 if ((sinfo->filled & STATION_INFO_PLID) &&
3601 nla_put_u16(msg, NL80211_STA_INFO_PLID, sinfo->plid))
3602 goto nla_put_failure;
3603 if ((sinfo->filled & STATION_INFO_PLINK_STATE) &&
3604 nla_put_u8(msg, NL80211_STA_INFO_PLINK_STATE,
3605 sinfo->plink_state))
3606 goto nla_put_failure;
John W. Linville66266b32012-03-15 13:25:41 -04003607 switch (rdev->wiphy.signal_type) {
3608 case CFG80211_SIGNAL_TYPE_MBM:
David S. Miller9360ffd2012-03-29 04:41:26 -04003609 if ((sinfo->filled & STATION_INFO_SIGNAL) &&
3610 nla_put_u8(msg, NL80211_STA_INFO_SIGNAL,
3611 sinfo->signal))
3612 goto nla_put_failure;
3613 if ((sinfo->filled & STATION_INFO_SIGNAL_AVG) &&
3614 nla_put_u8(msg, NL80211_STA_INFO_SIGNAL_AVG,
3615 sinfo->signal_avg))
3616 goto nla_put_failure;
John W. Linville66266b32012-03-15 13:25:41 -04003617 break;
3618 default:
3619 break;
3620 }
Felix Fietkau119363c2013-04-22 16:29:30 +02003621 if (sinfo->filled & STATION_INFO_CHAIN_SIGNAL) {
3622 if (!nl80211_put_signal(msg, sinfo->chains,
3623 sinfo->chain_signal,
3624 NL80211_STA_INFO_CHAIN_SIGNAL))
3625 goto nla_put_failure;
3626 }
3627 if (sinfo->filled & STATION_INFO_CHAIN_SIGNAL_AVG) {
3628 if (!nl80211_put_signal(msg, sinfo->chains,
3629 sinfo->chain_signal_avg,
3630 NL80211_STA_INFO_CHAIN_SIGNAL_AVG))
3631 goto nla_put_failure;
3632 }
Henning Rogge420e7fa2008-12-11 22:04:19 +01003633 if (sinfo->filled & STATION_INFO_TX_BITRATE) {
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003634 if (!nl80211_put_sta_rate(msg, &sinfo->txrate,
3635 NL80211_STA_INFO_TX_BITRATE))
Henning Rogge420e7fa2008-12-11 22:04:19 +01003636 goto nla_put_failure;
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003637 }
3638 if (sinfo->filled & STATION_INFO_RX_BITRATE) {
3639 if (!nl80211_put_sta_rate(msg, &sinfo->rxrate,
3640 NL80211_STA_INFO_RX_BITRATE))
3641 goto nla_put_failure;
Henning Rogge420e7fa2008-12-11 22:04:19 +01003642 }
David S. Miller9360ffd2012-03-29 04:41:26 -04003643 if ((sinfo->filled & STATION_INFO_RX_PACKETS) &&
3644 nla_put_u32(msg, NL80211_STA_INFO_RX_PACKETS,
3645 sinfo->rx_packets))
3646 goto nla_put_failure;
3647 if ((sinfo->filled & STATION_INFO_TX_PACKETS) &&
3648 nla_put_u32(msg, NL80211_STA_INFO_TX_PACKETS,
3649 sinfo->tx_packets))
3650 goto nla_put_failure;
3651 if ((sinfo->filled & STATION_INFO_TX_RETRIES) &&
3652 nla_put_u32(msg, NL80211_STA_INFO_TX_RETRIES,
3653 sinfo->tx_retries))
3654 goto nla_put_failure;
3655 if ((sinfo->filled & STATION_INFO_TX_FAILED) &&
3656 nla_put_u32(msg, NL80211_STA_INFO_TX_FAILED,
3657 sinfo->tx_failed))
3658 goto nla_put_failure;
Antonio Quartulli867d8492014-05-19 21:53:19 +02003659 if ((sinfo->filled & STATION_INFO_EXPECTED_THROUGHPUT) &&
3660 nla_put_u32(msg, NL80211_STA_INFO_EXPECTED_THROUGHPUT,
3661 sinfo->expected_throughput))
3662 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04003663 if ((sinfo->filled & STATION_INFO_BEACON_LOSS_COUNT) &&
3664 nla_put_u32(msg, NL80211_STA_INFO_BEACON_LOSS,
3665 sinfo->beacon_loss_count))
3666 goto nla_put_failure;
Marco Porsch3b1c5a52013-01-07 16:04:52 +01003667 if ((sinfo->filled & STATION_INFO_LOCAL_PM) &&
3668 nla_put_u32(msg, NL80211_STA_INFO_LOCAL_PM,
3669 sinfo->local_pm))
3670 goto nla_put_failure;
3671 if ((sinfo->filled & STATION_INFO_PEER_PM) &&
3672 nla_put_u32(msg, NL80211_STA_INFO_PEER_PM,
3673 sinfo->peer_pm))
3674 goto nla_put_failure;
3675 if ((sinfo->filled & STATION_INFO_NONPEER_PM) &&
3676 nla_put_u32(msg, NL80211_STA_INFO_NONPEER_PM,
3677 sinfo->nonpeer_pm))
3678 goto nla_put_failure;
Paul Stewartf4263c92011-03-31 09:25:41 -07003679 if (sinfo->filled & STATION_INFO_BSS_PARAM) {
3680 bss_param = nla_nest_start(msg, NL80211_STA_INFO_BSS_PARAM);
3681 if (!bss_param)
3682 goto nla_put_failure;
3683
David S. Miller9360ffd2012-03-29 04:41:26 -04003684 if (((sinfo->bss_param.flags & BSS_PARAM_FLAGS_CTS_PROT) &&
3685 nla_put_flag(msg, NL80211_STA_BSS_PARAM_CTS_PROT)) ||
3686 ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_PREAMBLE) &&
3687 nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_PREAMBLE)) ||
3688 ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_SLOT_TIME) &&
3689 nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_SLOT_TIME)) ||
3690 nla_put_u8(msg, NL80211_STA_BSS_PARAM_DTIM_PERIOD,
3691 sinfo->bss_param.dtim_period) ||
3692 nla_put_u16(msg, NL80211_STA_BSS_PARAM_BEACON_INTERVAL,
3693 sinfo->bss_param.beacon_interval))
3694 goto nla_put_failure;
Paul Stewartf4263c92011-03-31 09:25:41 -07003695
3696 nla_nest_end(msg, bss_param);
3697 }
David S. Miller9360ffd2012-03-29 04:41:26 -04003698 if ((sinfo->filled & STATION_INFO_STA_FLAGS) &&
3699 nla_put(msg, NL80211_STA_INFO_STA_FLAGS,
3700 sizeof(struct nl80211_sta_flag_update),
3701 &sinfo->sta_flags))
3702 goto nla_put_failure;
John W. Linville7eab0f62012-04-12 14:25:14 -04003703 if ((sinfo->filled & STATION_INFO_T_OFFSET) &&
3704 nla_put_u64(msg, NL80211_STA_INFO_T_OFFSET,
3705 sinfo->t_offset))
3706 goto nla_put_failure;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003707 nla_nest_end(msg, sinfoattr);
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003708
David S. Miller9360ffd2012-03-29 04:41:26 -04003709 if ((sinfo->filled & STATION_INFO_ASSOC_REQ_IES) &&
3710 nla_put(msg, NL80211_ATTR_IE, sinfo->assoc_req_ies_len,
3711 sinfo->assoc_req_ies))
3712 goto nla_put_failure;
Jouni Malinen50d3dfb2011-08-08 12:11:52 +03003713
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003714 return genlmsg_end(msg, hdr);
3715
3716 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07003717 genlmsg_cancel(msg, hdr);
3718 return -EMSGSIZE;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003719}
3720
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003721static int nl80211_dump_station(struct sk_buff *skb,
Johannes Bergbba95fe2008-07-29 13:22:51 +02003722 struct netlink_callback *cb)
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003723{
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003724 struct station_info sinfo;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08003725 struct cfg80211_registered_device *rdev;
Johannes Berg97990a02013-04-19 01:02:55 +02003726 struct wireless_dev *wdev;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003727 u8 mac_addr[ETH_ALEN];
Johannes Berg97990a02013-04-19 01:02:55 +02003728 int sta_idx = cb->args[2];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003729 int err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003730
Zhao, Gang1b8ec872014-04-21 12:53:02 +08003731 err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev);
Johannes Berg67748892010-10-04 21:14:06 +02003732 if (err)
3733 return err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02003734
Johannes Berg97990a02013-04-19 01:02:55 +02003735 if (!wdev->netdev) {
3736 err = -EINVAL;
3737 goto out_err;
3738 }
3739
Zhao, Gang1b8ec872014-04-21 12:53:02 +08003740 if (!rdev->ops->dump_station) {
Jouni Malineneec60b02009-03-20 21:21:19 +02003741 err = -EOPNOTSUPP;
Johannes Bergbba95fe2008-07-29 13:22:51 +02003742 goto out_err;
3743 }
3744
Johannes Bergbba95fe2008-07-29 13:22:51 +02003745 while (1) {
Jouni Malinenf612ced2011-08-11 11:46:22 +03003746 memset(&sinfo, 0, sizeof(sinfo));
Zhao, Gang1b8ec872014-04-21 12:53:02 +08003747 err = rdev_dump_station(rdev, wdev->netdev, sta_idx,
Hila Gonene35e4d22012-06-27 17:19:42 +03003748 mac_addr, &sinfo);
Johannes Bergbba95fe2008-07-29 13:22:51 +02003749 if (err == -ENOENT)
3750 break;
3751 if (err)
Johannes Berg3b858752009-03-12 09:55:09 +01003752 goto out_err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02003753
3754 if (nl80211_send_station(skb,
Eric W. Biederman15e47302012-09-07 20:12:54 +00003755 NETLINK_CB(cb->skb).portid,
Johannes Bergbba95fe2008-07-29 13:22:51 +02003756 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08003757 rdev, wdev->netdev, mac_addr,
Johannes Bergbba95fe2008-07-29 13:22:51 +02003758 &sinfo) < 0)
3759 goto out;
3760
3761 sta_idx++;
3762 }
3763
3764
3765 out:
Johannes Berg97990a02013-04-19 01:02:55 +02003766 cb->args[2] = sta_idx;
Johannes Bergbba95fe2008-07-29 13:22:51 +02003767 err = skb->len;
Johannes Bergbba95fe2008-07-29 13:22:51 +02003768 out_err:
Zhao, Gang1b8ec872014-04-21 12:53:02 +08003769 nl80211_finish_wdev_dump(rdev);
Johannes Bergbba95fe2008-07-29 13:22:51 +02003770
3771 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003772}
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003773
Johannes Berg5727ef12007-12-19 02:03:34 +01003774static int nl80211_get_station(struct sk_buff *skb, struct genl_info *info)
3775{
Johannes Berg4c476992010-10-04 21:36:35 +02003776 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3777 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003778 struct station_info sinfo;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003779 struct sk_buff *msg;
3780 u8 *mac_addr = NULL;
Johannes Berg4c476992010-10-04 21:36:35 +02003781 int err;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003782
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003783 memset(&sinfo, 0, sizeof(sinfo));
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003784
3785 if (!info->attrs[NL80211_ATTR_MAC])
3786 return -EINVAL;
3787
3788 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
3789
Johannes Berg4c476992010-10-04 21:36:35 +02003790 if (!rdev->ops->get_station)
3791 return -EOPNOTSUPP;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003792
Hila Gonene35e4d22012-06-27 17:19:42 +03003793 err = rdev_get_station(rdev, dev, mac_addr, &sinfo);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003794 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02003795 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003796
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07003797 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003798 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02003799 return -ENOMEM;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003800
Eric W. Biederman15e47302012-09-07 20:12:54 +00003801 if (nl80211_send_station(msg, info->snd_portid, info->snd_seq, 0,
John W. Linville66266b32012-03-15 13:25:41 -04003802 rdev, dev, mac_addr, &sinfo) < 0) {
Johannes Berg4c476992010-10-04 21:36:35 +02003803 nlmsg_free(msg);
3804 return -ENOBUFS;
3805 }
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003806
Johannes Berg4c476992010-10-04 21:36:35 +02003807 return genlmsg_reply(msg, info);
Johannes Berg5727ef12007-12-19 02:03:34 +01003808}
3809
Johannes Berg77ee7c82013-02-15 00:48:33 +01003810int cfg80211_check_station_change(struct wiphy *wiphy,
3811 struct station_parameters *params,
3812 enum cfg80211_station_type statype)
3813{
3814 if (params->listen_interval != -1)
3815 return -EINVAL;
3816 if (params->aid)
3817 return -EINVAL;
3818
3819 /* When you run into this, adjust the code below for the new flag */
3820 BUILD_BUG_ON(NL80211_STA_FLAG_MAX != 7);
3821
3822 switch (statype) {
Thomas Pederseneef941e2013-03-04 13:06:11 -08003823 case CFG80211_STA_MESH_PEER_KERNEL:
3824 case CFG80211_STA_MESH_PEER_USER:
Johannes Berg77ee7c82013-02-15 00:48:33 +01003825 /*
3826 * No ignoring the TDLS flag here -- the userspace mesh
3827 * code doesn't have the bug of including TDLS in the
3828 * mask everywhere.
3829 */
3830 if (params->sta_flags_mask &
3831 ~(BIT(NL80211_STA_FLAG_AUTHENTICATED) |
3832 BIT(NL80211_STA_FLAG_MFP) |
3833 BIT(NL80211_STA_FLAG_AUTHORIZED)))
3834 return -EINVAL;
3835 break;
3836 case CFG80211_STA_TDLS_PEER_SETUP:
3837 case CFG80211_STA_TDLS_PEER_ACTIVE:
3838 if (!(params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)))
3839 return -EINVAL;
3840 /* ignore since it can't change */
3841 params->sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER);
3842 break;
3843 default:
3844 /* disallow mesh-specific things */
3845 if (params->plink_action != NL80211_PLINK_ACTION_NO_ACTION)
3846 return -EINVAL;
3847 if (params->local_pm)
3848 return -EINVAL;
3849 if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE)
3850 return -EINVAL;
3851 }
3852
3853 if (statype != CFG80211_STA_TDLS_PEER_SETUP &&
3854 statype != CFG80211_STA_TDLS_PEER_ACTIVE) {
3855 /* TDLS can't be set, ... */
3856 if (params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))
3857 return -EINVAL;
3858 /*
3859 * ... but don't bother the driver with it. This works around
3860 * a hostapd/wpa_supplicant issue -- it always includes the
3861 * TLDS_PEER flag in the mask even for AP mode.
3862 */
3863 params->sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER);
3864 }
3865
3866 if (statype != CFG80211_STA_TDLS_PEER_SETUP) {
3867 /* reject other things that can't change */
3868 if (params->sta_modify_mask & STATION_PARAM_APPLY_UAPSD)
3869 return -EINVAL;
3870 if (params->sta_modify_mask & STATION_PARAM_APPLY_CAPABILITY)
3871 return -EINVAL;
3872 if (params->supported_rates)
3873 return -EINVAL;
3874 if (params->ext_capab || params->ht_capa || params->vht_capa)
3875 return -EINVAL;
3876 }
3877
3878 if (statype != CFG80211_STA_AP_CLIENT) {
3879 if (params->vlan)
3880 return -EINVAL;
3881 }
3882
3883 switch (statype) {
3884 case CFG80211_STA_AP_MLME_CLIENT:
3885 /* Use this only for authorizing/unauthorizing a station */
3886 if (!(params->sta_flags_mask & BIT(NL80211_STA_FLAG_AUTHORIZED)))
3887 return -EOPNOTSUPP;
3888 break;
3889 case CFG80211_STA_AP_CLIENT:
3890 /* accept only the listed bits */
3891 if (params->sta_flags_mask &
3892 ~(BIT(NL80211_STA_FLAG_AUTHORIZED) |
3893 BIT(NL80211_STA_FLAG_AUTHENTICATED) |
3894 BIT(NL80211_STA_FLAG_ASSOCIATED) |
3895 BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) |
3896 BIT(NL80211_STA_FLAG_WME) |
3897 BIT(NL80211_STA_FLAG_MFP)))
3898 return -EINVAL;
3899
3900 /* but authenticated/associated only if driver handles it */
3901 if (!(wiphy->features & NL80211_FEATURE_FULL_AP_CLIENT_STATE) &&
3902 params->sta_flags_mask &
3903 (BIT(NL80211_STA_FLAG_AUTHENTICATED) |
3904 BIT(NL80211_STA_FLAG_ASSOCIATED)))
3905 return -EINVAL;
3906 break;
3907 case CFG80211_STA_IBSS:
3908 case CFG80211_STA_AP_STA:
3909 /* reject any changes other than AUTHORIZED */
3910 if (params->sta_flags_mask & ~BIT(NL80211_STA_FLAG_AUTHORIZED))
3911 return -EINVAL;
3912 break;
3913 case CFG80211_STA_TDLS_PEER_SETUP:
3914 /* reject any changes other than AUTHORIZED or WME */
3915 if (params->sta_flags_mask & ~(BIT(NL80211_STA_FLAG_AUTHORIZED) |
3916 BIT(NL80211_STA_FLAG_WME)))
3917 return -EINVAL;
3918 /* force (at least) rates when authorizing */
3919 if (params->sta_flags_set & BIT(NL80211_STA_FLAG_AUTHORIZED) &&
3920 !params->supported_rates)
3921 return -EINVAL;
3922 break;
3923 case CFG80211_STA_TDLS_PEER_ACTIVE:
3924 /* reject any changes */
3925 return -EINVAL;
Thomas Pederseneef941e2013-03-04 13:06:11 -08003926 case CFG80211_STA_MESH_PEER_KERNEL:
Johannes Berg77ee7c82013-02-15 00:48:33 +01003927 if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE)
3928 return -EINVAL;
3929 break;
Thomas Pederseneef941e2013-03-04 13:06:11 -08003930 case CFG80211_STA_MESH_PEER_USER:
Johannes Berg77ee7c82013-02-15 00:48:33 +01003931 if (params->plink_action != NL80211_PLINK_ACTION_NO_ACTION)
3932 return -EINVAL;
3933 break;
3934 }
3935
3936 return 0;
3937}
3938EXPORT_SYMBOL(cfg80211_check_station_change);
3939
Johannes Berg5727ef12007-12-19 02:03:34 +01003940/*
Felix Fietkauc258d2d2009-11-11 17:23:31 +01003941 * Get vlan interface making sure it is running and on the right wiphy.
Johannes Berg5727ef12007-12-19 02:03:34 +01003942 */
Johannes Berg80b99892011-11-18 16:23:01 +01003943static struct net_device *get_vlan(struct genl_info *info,
3944 struct cfg80211_registered_device *rdev)
Johannes Berg5727ef12007-12-19 02:03:34 +01003945{
Johannes Berg463d0182009-07-14 00:33:35 +02003946 struct nlattr *vlanattr = info->attrs[NL80211_ATTR_STA_VLAN];
Johannes Berg80b99892011-11-18 16:23:01 +01003947 struct net_device *v;
3948 int ret;
Johannes Berg5727ef12007-12-19 02:03:34 +01003949
Johannes Berg80b99892011-11-18 16:23:01 +01003950 if (!vlanattr)
3951 return NULL;
3952
3953 v = dev_get_by_index(genl_info_net(info), nla_get_u32(vlanattr));
3954 if (!v)
3955 return ERR_PTR(-ENODEV);
3956
3957 if (!v->ieee80211_ptr || v->ieee80211_ptr->wiphy != &rdev->wiphy) {
3958 ret = -EINVAL;
3959 goto error;
Johannes Berg5727ef12007-12-19 02:03:34 +01003960 }
Johannes Berg80b99892011-11-18 16:23:01 +01003961
Johannes Berg77ee7c82013-02-15 00:48:33 +01003962 if (v->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN &&
3963 v->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
3964 v->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) {
3965 ret = -EINVAL;
3966 goto error;
3967 }
3968
Johannes Berg80b99892011-11-18 16:23:01 +01003969 if (!netif_running(v)) {
3970 ret = -ENETDOWN;
3971 goto error;
3972 }
3973
3974 return v;
3975 error:
3976 dev_put(v);
3977 return ERR_PTR(ret);
Johannes Berg5727ef12007-12-19 02:03:34 +01003978}
3979
Johannes Berg94e860f2014-01-20 23:58:15 +01003980static const struct nla_policy
3981nl80211_sta_wme_policy[NL80211_STA_WME_MAX + 1] = {
Jouni Malinendf881292013-02-14 21:10:54 +02003982 [NL80211_STA_WME_UAPSD_QUEUES] = { .type = NLA_U8 },
3983 [NL80211_STA_WME_MAX_SP] = { .type = NLA_U8 },
3984};
3985
Johannes Bergff276692013-02-15 00:09:01 +01003986static int nl80211_parse_sta_wme(struct genl_info *info,
3987 struct station_parameters *params)
Jouni Malinendf881292013-02-14 21:10:54 +02003988{
Jouni Malinendf881292013-02-14 21:10:54 +02003989 struct nlattr *tb[NL80211_STA_WME_MAX + 1];
3990 struct nlattr *nla;
3991 int err;
3992
Jouni Malinendf881292013-02-14 21:10:54 +02003993 /* parse WME attributes if present */
3994 if (!info->attrs[NL80211_ATTR_STA_WME])
3995 return 0;
3996
3997 nla = info->attrs[NL80211_ATTR_STA_WME];
3998 err = nla_parse_nested(tb, NL80211_STA_WME_MAX, nla,
3999 nl80211_sta_wme_policy);
4000 if (err)
4001 return err;
4002
4003 if (tb[NL80211_STA_WME_UAPSD_QUEUES])
4004 params->uapsd_queues = nla_get_u8(
4005 tb[NL80211_STA_WME_UAPSD_QUEUES]);
4006 if (params->uapsd_queues & ~IEEE80211_WMM_IE_STA_QOSINFO_AC_MASK)
4007 return -EINVAL;
4008
4009 if (tb[NL80211_STA_WME_MAX_SP])
4010 params->max_sp = nla_get_u8(tb[NL80211_STA_WME_MAX_SP]);
4011
4012 if (params->max_sp & ~IEEE80211_WMM_IE_STA_QOSINFO_SP_MASK)
4013 return -EINVAL;
4014
4015 params->sta_modify_mask |= STATION_PARAM_APPLY_UAPSD;
4016
4017 return 0;
4018}
4019
Sunil Duttc01fc9a2013-10-09 20:45:21 +05304020static int nl80211_parse_sta_channel_info(struct genl_info *info,
4021 struct station_parameters *params)
4022{
4023 if (info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]) {
4024 params->supported_channels =
4025 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]);
4026 params->supported_channels_len =
4027 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]);
4028 /*
4029 * Need to include at least one (first channel, number of
4030 * channels) tuple for each subband, and must have proper
4031 * tuples for the rest of the data as well.
4032 */
4033 if (params->supported_channels_len < 2)
4034 return -EINVAL;
4035 if (params->supported_channels_len % 2)
4036 return -EINVAL;
4037 }
4038
4039 if (info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]) {
4040 params->supported_oper_classes =
4041 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]);
4042 params->supported_oper_classes_len =
4043 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]);
4044 /*
4045 * The value of the Length field of the Supported Operating
4046 * Classes element is between 2 and 253.
4047 */
4048 if (params->supported_oper_classes_len < 2 ||
4049 params->supported_oper_classes_len > 253)
4050 return -EINVAL;
4051 }
4052 return 0;
4053}
4054
Johannes Bergff276692013-02-15 00:09:01 +01004055static int nl80211_set_station_tdls(struct genl_info *info,
4056 struct station_parameters *params)
4057{
Sunil Duttc01fc9a2013-10-09 20:45:21 +05304058 int err;
Johannes Bergff276692013-02-15 00:09:01 +01004059 /* Dummy STA entry gets updated once the peer capabilities are known */
Jouni Malinen5e4b6f52013-05-16 20:11:08 +03004060 if (info->attrs[NL80211_ATTR_PEER_AID])
4061 params->aid = nla_get_u16(info->attrs[NL80211_ATTR_PEER_AID]);
Johannes Bergff276692013-02-15 00:09:01 +01004062 if (info->attrs[NL80211_ATTR_HT_CAPABILITY])
4063 params->ht_capa =
4064 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]);
4065 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY])
4066 params->vht_capa =
4067 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]);
4068
Sunil Duttc01fc9a2013-10-09 20:45:21 +05304069 err = nl80211_parse_sta_channel_info(info, params);
4070 if (err)
4071 return err;
4072
Johannes Bergff276692013-02-15 00:09:01 +01004073 return nl80211_parse_sta_wme(info, params);
4074}
4075
Johannes Berg5727ef12007-12-19 02:03:34 +01004076static int nl80211_set_station(struct sk_buff *skb, struct genl_info *info)
4077{
Johannes Berg4c476992010-10-04 21:36:35 +02004078 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg4c476992010-10-04 21:36:35 +02004079 struct net_device *dev = info->user_ptr[1];
Johannes Berg5727ef12007-12-19 02:03:34 +01004080 struct station_parameters params;
Johannes Berg77ee7c82013-02-15 00:48:33 +01004081 u8 *mac_addr;
4082 int err;
Johannes Berg5727ef12007-12-19 02:03:34 +01004083
4084 memset(&params, 0, sizeof(params));
4085
4086 params.listen_interval = -1;
4087
Johannes Berg77ee7c82013-02-15 00:48:33 +01004088 if (!rdev->ops->change_station)
4089 return -EOPNOTSUPP;
4090
Johannes Berg5727ef12007-12-19 02:03:34 +01004091 if (info->attrs[NL80211_ATTR_STA_AID])
4092 return -EINVAL;
4093
4094 if (!info->attrs[NL80211_ATTR_MAC])
4095 return -EINVAL;
4096
4097 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
4098
4099 if (info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) {
4100 params.supported_rates =
4101 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
4102 params.supported_rates_len =
4103 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
4104 }
4105
Jouni Malinen9d62a982013-02-14 21:10:13 +02004106 if (info->attrs[NL80211_ATTR_STA_CAPABILITY]) {
4107 params.capability =
4108 nla_get_u16(info->attrs[NL80211_ATTR_STA_CAPABILITY]);
4109 params.sta_modify_mask |= STATION_PARAM_APPLY_CAPABILITY;
4110 }
4111
4112 if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]) {
4113 params.ext_capab =
4114 nla_data(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
4115 params.ext_capab_len =
4116 nla_len(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
4117 }
4118
Jouni Malinendf881292013-02-14 21:10:54 +02004119 if (info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL])
Johannes Bergba23d202012-12-27 17:32:09 +01004120 return -EINVAL;
Jouni Malinen36aedc92008-08-25 11:58:58 +03004121
Johannes Bergbdd3ae32012-01-02 13:30:03 +01004122 if (parse_station_flags(info, dev->ieee80211_ptr->iftype, &params))
Johannes Berg5727ef12007-12-19 02:03:34 +01004123 return -EINVAL;
4124
Johannes Bergf8bacc22013-02-14 23:27:01 +01004125 if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) {
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004126 params.plink_action =
Johannes Bergf8bacc22013-02-14 23:27:01 +01004127 nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]);
4128 if (params.plink_action >= NUM_NL80211_PLINK_ACTIONS)
4129 return -EINVAL;
4130 }
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004131
Johannes Bergf8bacc22013-02-14 23:27:01 +01004132 if (info->attrs[NL80211_ATTR_STA_PLINK_STATE]) {
Javier Cardona9c3990a2011-05-03 16:57:11 -07004133 params.plink_state =
Johannes Bergf8bacc22013-02-14 23:27:01 +01004134 nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_STATE]);
4135 if (params.plink_state >= NUM_NL80211_PLINK_STATES)
4136 return -EINVAL;
4137 params.sta_modify_mask |= STATION_PARAM_APPLY_PLINK_STATE;
4138 }
Javier Cardona9c3990a2011-05-03 16:57:11 -07004139
Marco Porsch3b1c5a52013-01-07 16:04:52 +01004140 if (info->attrs[NL80211_ATTR_LOCAL_MESH_POWER_MODE]) {
4141 enum nl80211_mesh_power_mode pm = nla_get_u32(
4142 info->attrs[NL80211_ATTR_LOCAL_MESH_POWER_MODE]);
4143
4144 if (pm <= NL80211_MESH_POWER_UNKNOWN ||
4145 pm > NL80211_MESH_POWER_MAX)
4146 return -EINVAL;
4147
4148 params.local_pm = pm;
4149 }
4150
Johannes Berg77ee7c82013-02-15 00:48:33 +01004151 /* Include parameters for TDLS peer (will check later) */
4152 err = nl80211_set_station_tdls(info, &params);
4153 if (err)
4154 return err;
4155
4156 params.vlan = get_vlan(info, rdev);
4157 if (IS_ERR(params.vlan))
4158 return PTR_ERR(params.vlan);
4159
Johannes Berga97f4422009-06-18 17:23:43 +02004160 switch (dev->ieee80211_ptr->iftype) {
4161 case NL80211_IFTYPE_AP:
4162 case NL80211_IFTYPE_AP_VLAN:
Johannes Berg074ac8d2010-09-16 14:58:22 +02004163 case NL80211_IFTYPE_P2P_GO:
Johannes Berg074ac8d2010-09-16 14:58:22 +02004164 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Berga97f4422009-06-18 17:23:43 +02004165 case NL80211_IFTYPE_STATION:
Antonio Quartulli267335d2012-01-31 20:25:47 +01004166 case NL80211_IFTYPE_ADHOC:
Johannes Berga97f4422009-06-18 17:23:43 +02004167 case NL80211_IFTYPE_MESH_POINT:
Johannes Berga97f4422009-06-18 17:23:43 +02004168 break;
4169 default:
Johannes Berg77ee7c82013-02-15 00:48:33 +01004170 err = -EOPNOTSUPP;
4171 goto out_put_vlan;
Johannes Berg034d6552009-05-27 10:35:29 +02004172 }
4173
Johannes Berg77ee7c82013-02-15 00:48:33 +01004174 /* driver will call cfg80211_check_station_change() */
Hila Gonene35e4d22012-06-27 17:19:42 +03004175 err = rdev_change_station(rdev, dev, mac_addr, &params);
Johannes Berg5727ef12007-12-19 02:03:34 +01004176
Johannes Berg77ee7c82013-02-15 00:48:33 +01004177 out_put_vlan:
Johannes Berg5727ef12007-12-19 02:03:34 +01004178 if (params.vlan)
4179 dev_put(params.vlan);
Johannes Berg3b858752009-03-12 09:55:09 +01004180
Johannes Berg5727ef12007-12-19 02:03:34 +01004181 return err;
4182}
4183
4184static int nl80211_new_station(struct sk_buff *skb, struct genl_info *info)
4185{
Johannes Berg4c476992010-10-04 21:36:35 +02004186 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg5727ef12007-12-19 02:03:34 +01004187 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02004188 struct net_device *dev = info->user_ptr[1];
Johannes Berg5727ef12007-12-19 02:03:34 +01004189 struct station_parameters params;
4190 u8 *mac_addr = NULL;
4191
4192 memset(&params, 0, sizeof(params));
4193
Johannes Berg984c3112013-02-14 23:43:25 +01004194 if (!rdev->ops->add_station)
4195 return -EOPNOTSUPP;
4196
Johannes Berg5727ef12007-12-19 02:03:34 +01004197 if (!info->attrs[NL80211_ATTR_MAC])
4198 return -EINVAL;
4199
Johannes Berg5727ef12007-12-19 02:03:34 +01004200 if (!info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL])
4201 return -EINVAL;
4202
4203 if (!info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES])
4204 return -EINVAL;
4205
Jouni Malinen5e4b6f52013-05-16 20:11:08 +03004206 if (!info->attrs[NL80211_ATTR_STA_AID] &&
4207 !info->attrs[NL80211_ATTR_PEER_AID])
Thadeu Lima de Souza Cascardo0e956c12010-02-12 12:34:50 -02004208 return -EINVAL;
4209
Johannes Berg5727ef12007-12-19 02:03:34 +01004210 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
4211 params.supported_rates =
4212 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
4213 params.supported_rates_len =
4214 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
4215 params.listen_interval =
4216 nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]);
Johannes Berg51b50fb2009-05-24 16:42:30 +02004217
Jouni Malinen3d124ea2013-05-27 18:24:02 +03004218 if (info->attrs[NL80211_ATTR_PEER_AID])
Jouni Malinen5e4b6f52013-05-16 20:11:08 +03004219 params.aid = nla_get_u16(info->attrs[NL80211_ATTR_PEER_AID]);
Jouni Malinen3d124ea2013-05-27 18:24:02 +03004220 else
4221 params.aid = nla_get_u16(info->attrs[NL80211_ATTR_STA_AID]);
Thadeu Lima de Souza Cascardo0e956c12010-02-12 12:34:50 -02004222 if (!params.aid || params.aid > IEEE80211_MAX_AID)
4223 return -EINVAL;
Johannes Berg51b50fb2009-05-24 16:42:30 +02004224
Jouni Malinen9d62a982013-02-14 21:10:13 +02004225 if (info->attrs[NL80211_ATTR_STA_CAPABILITY]) {
4226 params.capability =
4227 nla_get_u16(info->attrs[NL80211_ATTR_STA_CAPABILITY]);
4228 params.sta_modify_mask |= STATION_PARAM_APPLY_CAPABILITY;
4229 }
4230
4231 if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]) {
4232 params.ext_capab =
4233 nla_data(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
4234 params.ext_capab_len =
4235 nla_len(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
4236 }
4237
Jouni Malinen36aedc92008-08-25 11:58:58 +03004238 if (info->attrs[NL80211_ATTR_HT_CAPABILITY])
4239 params.ht_capa =
4240 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]);
Johannes Berg5727ef12007-12-19 02:03:34 +01004241
Mahesh Palivelaf461be3e2012-10-11 08:04:52 +00004242 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY])
4243 params.vht_capa =
4244 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]);
4245
Marek Kwaczynski60f4a7b2013-12-03 10:04:59 +01004246 if (info->attrs[NL80211_ATTR_OPMODE_NOTIF]) {
4247 params.opmode_notif_used = true;
4248 params.opmode_notif =
4249 nla_get_u8(info->attrs[NL80211_ATTR_OPMODE_NOTIF]);
4250 }
4251
Johannes Bergf8bacc22013-02-14 23:27:01 +01004252 if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) {
Javier Cardona96b78df2011-04-07 15:08:33 -07004253 params.plink_action =
Johannes Bergf8bacc22013-02-14 23:27:01 +01004254 nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]);
4255 if (params.plink_action >= NUM_NL80211_PLINK_ACTIONS)
4256 return -EINVAL;
4257 }
Javier Cardona96b78df2011-04-07 15:08:33 -07004258
Sunil Duttc01fc9a2013-10-09 20:45:21 +05304259 err = nl80211_parse_sta_channel_info(info, &params);
4260 if (err)
4261 return err;
4262
Johannes Bergff276692013-02-15 00:09:01 +01004263 err = nl80211_parse_sta_wme(info, &params);
4264 if (err)
4265 return err;
Johannes Bergbdd90d52011-12-14 12:20:27 +01004266
Johannes Bergbdd3ae32012-01-02 13:30:03 +01004267 if (parse_station_flags(info, dev->ieee80211_ptr->iftype, &params))
Johannes Berg5727ef12007-12-19 02:03:34 +01004268 return -EINVAL;
4269
Johannes Berg77ee7c82013-02-15 00:48:33 +01004270 /* When you run into this, adjust the code below for the new flag */
4271 BUILD_BUG_ON(NL80211_STA_FLAG_MAX != 7);
4272
Johannes Bergbdd90d52011-12-14 12:20:27 +01004273 switch (dev->ieee80211_ptr->iftype) {
4274 case NL80211_IFTYPE_AP:
4275 case NL80211_IFTYPE_AP_VLAN:
4276 case NL80211_IFTYPE_P2P_GO:
Johannes Berg984c3112013-02-14 23:43:25 +01004277 /* ignore WME attributes if iface/sta is not capable */
4278 if (!(rdev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) ||
4279 !(params.sta_flags_set & BIT(NL80211_STA_FLAG_WME)))
4280 params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD;
Eliad Pellerc75786c2011-08-23 14:37:46 +03004281
Johannes Bergbdd90d52011-12-14 12:20:27 +01004282 /* TDLS peers cannot be added */
Jouni Malinen3d124ea2013-05-27 18:24:02 +03004283 if ((params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) ||
4284 info->attrs[NL80211_ATTR_PEER_AID])
Johannes Berg4319e192011-09-07 11:50:48 +02004285 return -EINVAL;
Johannes Bergbdd90d52011-12-14 12:20:27 +01004286 /* but don't bother the driver with it */
4287 params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER);
Eliad Pellerc75786c2011-08-23 14:37:46 +03004288
Johannes Bergd582cff2012-10-26 17:53:44 +02004289 /* allow authenticated/associated only if driver handles it */
4290 if (!(rdev->wiphy.features &
4291 NL80211_FEATURE_FULL_AP_CLIENT_STATE) &&
4292 params.sta_flags_mask &
4293 (BIT(NL80211_STA_FLAG_AUTHENTICATED) |
4294 BIT(NL80211_STA_FLAG_ASSOCIATED)))
4295 return -EINVAL;
4296
Johannes Bergbdd90d52011-12-14 12:20:27 +01004297 /* must be last in here for error handling */
4298 params.vlan = get_vlan(info, rdev);
4299 if (IS_ERR(params.vlan))
4300 return PTR_ERR(params.vlan);
4301 break;
4302 case NL80211_IFTYPE_MESH_POINT:
Johannes Berg984c3112013-02-14 23:43:25 +01004303 /* ignore uAPSD data */
4304 params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD;
4305
Johannes Bergd582cff2012-10-26 17:53:44 +02004306 /* associated is disallowed */
4307 if (params.sta_flags_mask & BIT(NL80211_STA_FLAG_ASSOCIATED))
4308 return -EINVAL;
Johannes Bergbdd90d52011-12-14 12:20:27 +01004309 /* TDLS peers cannot be added */
Jouni Malinen3d124ea2013-05-27 18:24:02 +03004310 if ((params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) ||
4311 info->attrs[NL80211_ATTR_PEER_AID])
Johannes Berg4319e192011-09-07 11:50:48 +02004312 return -EINVAL;
Johannes Bergbdd90d52011-12-14 12:20:27 +01004313 break;
4314 case NL80211_IFTYPE_STATION:
Johannes Berg93d08f02013-03-04 09:29:46 +01004315 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Berg984c3112013-02-14 23:43:25 +01004316 /* ignore uAPSD data */
4317 params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD;
4318
Johannes Berg77ee7c82013-02-15 00:48:33 +01004319 /* these are disallowed */
4320 if (params.sta_flags_mask &
4321 (BIT(NL80211_STA_FLAG_ASSOCIATED) |
4322 BIT(NL80211_STA_FLAG_AUTHENTICATED)))
Johannes Bergd582cff2012-10-26 17:53:44 +02004323 return -EINVAL;
Johannes Bergbdd90d52011-12-14 12:20:27 +01004324 /* Only TDLS peers can be added */
4325 if (!(params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)))
4326 return -EINVAL;
4327 /* Can only add if TDLS ... */
4328 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS))
4329 return -EOPNOTSUPP;
4330 /* ... with external setup is supported */
4331 if (!(rdev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP))
4332 return -EOPNOTSUPP;
Johannes Berg77ee7c82013-02-15 00:48:33 +01004333 /*
4334 * Older wpa_supplicant versions always mark the TDLS peer
4335 * as authorized, but it shouldn't yet be.
4336 */
4337 params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_AUTHORIZED);
Johannes Bergbdd90d52011-12-14 12:20:27 +01004338 break;
4339 default:
4340 return -EOPNOTSUPP;
Eliad Pellerc75786c2011-08-23 14:37:46 +03004341 }
4342
Johannes Bergbdd90d52011-12-14 12:20:27 +01004343 /* be aware of params.vlan when changing code here */
Johannes Berg5727ef12007-12-19 02:03:34 +01004344
Hila Gonene35e4d22012-06-27 17:19:42 +03004345 err = rdev_add_station(rdev, dev, mac_addr, &params);
Johannes Berg5727ef12007-12-19 02:03:34 +01004346
Johannes Berg5727ef12007-12-19 02:03:34 +01004347 if (params.vlan)
4348 dev_put(params.vlan);
Johannes Berg5727ef12007-12-19 02:03:34 +01004349 return err;
4350}
4351
4352static int nl80211_del_station(struct sk_buff *skb, struct genl_info *info)
4353{
Johannes Berg4c476992010-10-04 21:36:35 +02004354 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4355 struct net_device *dev = info->user_ptr[1];
Johannes Berg5727ef12007-12-19 02:03:34 +01004356 u8 *mac_addr = NULL;
4357
4358 if (info->attrs[NL80211_ATTR_MAC])
4359 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
4360
Johannes Berge80cf852009-05-11 14:43:13 +02004361 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
Marco Porschd5d9de02010-03-30 10:00:16 +02004362 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN &&
Johannes Berg074ac8d2010-09-16 14:58:22 +02004363 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT &&
Johannes Berg4c476992010-10-04 21:36:35 +02004364 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
4365 return -EINVAL;
Johannes Berge80cf852009-05-11 14:43:13 +02004366
Johannes Berg4c476992010-10-04 21:36:35 +02004367 if (!rdev->ops->del_station)
4368 return -EOPNOTSUPP;
Johannes Berg5727ef12007-12-19 02:03:34 +01004369
Hila Gonene35e4d22012-06-27 17:19:42 +03004370 return rdev_del_station(rdev, dev, mac_addr);
Johannes Berg5727ef12007-12-19 02:03:34 +01004371}
4372
Eric W. Biederman15e47302012-09-07 20:12:54 +00004373static int nl80211_send_mpath(struct sk_buff *msg, u32 portid, u32 seq,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004374 int flags, struct net_device *dev,
4375 u8 *dst, u8 *next_hop,
4376 struct mpath_info *pinfo)
4377{
4378 void *hdr;
4379 struct nlattr *pinfoattr;
4380
Eric W. Biederman15e47302012-09-07 20:12:54 +00004381 hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_STATION);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004382 if (!hdr)
4383 return -1;
4384
David S. Miller9360ffd2012-03-29 04:41:26 -04004385 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
4386 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, dst) ||
4387 nla_put(msg, NL80211_ATTR_MPATH_NEXT_HOP, ETH_ALEN, next_hop) ||
4388 nla_put_u32(msg, NL80211_ATTR_GENERATION, pinfo->generation))
4389 goto nla_put_failure;
Johannes Bergf5ea9122009-08-07 16:17:38 +02004390
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004391 pinfoattr = nla_nest_start(msg, NL80211_ATTR_MPATH_INFO);
4392 if (!pinfoattr)
4393 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04004394 if ((pinfo->filled & MPATH_INFO_FRAME_QLEN) &&
4395 nla_put_u32(msg, NL80211_MPATH_INFO_FRAME_QLEN,
4396 pinfo->frame_qlen))
4397 goto nla_put_failure;
4398 if (((pinfo->filled & MPATH_INFO_SN) &&
4399 nla_put_u32(msg, NL80211_MPATH_INFO_SN, pinfo->sn)) ||
4400 ((pinfo->filled & MPATH_INFO_METRIC) &&
4401 nla_put_u32(msg, NL80211_MPATH_INFO_METRIC,
4402 pinfo->metric)) ||
4403 ((pinfo->filled & MPATH_INFO_EXPTIME) &&
4404 nla_put_u32(msg, NL80211_MPATH_INFO_EXPTIME,
4405 pinfo->exptime)) ||
4406 ((pinfo->filled & MPATH_INFO_FLAGS) &&
4407 nla_put_u8(msg, NL80211_MPATH_INFO_FLAGS,
4408 pinfo->flags)) ||
4409 ((pinfo->filled & MPATH_INFO_DISCOVERY_TIMEOUT) &&
4410 nla_put_u32(msg, NL80211_MPATH_INFO_DISCOVERY_TIMEOUT,
4411 pinfo->discovery_timeout)) ||
4412 ((pinfo->filled & MPATH_INFO_DISCOVERY_RETRIES) &&
4413 nla_put_u8(msg, NL80211_MPATH_INFO_DISCOVERY_RETRIES,
4414 pinfo->discovery_retries)))
4415 goto nla_put_failure;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004416
4417 nla_nest_end(msg, pinfoattr);
4418
4419 return genlmsg_end(msg, hdr);
4420
4421 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07004422 genlmsg_cancel(msg, hdr);
4423 return -EMSGSIZE;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004424}
4425
4426static int nl80211_dump_mpath(struct sk_buff *skb,
Johannes Bergbba95fe2008-07-29 13:22:51 +02004427 struct netlink_callback *cb)
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004428{
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004429 struct mpath_info pinfo;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08004430 struct cfg80211_registered_device *rdev;
Johannes Berg97990a02013-04-19 01:02:55 +02004431 struct wireless_dev *wdev;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004432 u8 dst[ETH_ALEN];
4433 u8 next_hop[ETH_ALEN];
Johannes Berg97990a02013-04-19 01:02:55 +02004434 int path_idx = cb->args[2];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004435 int err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004436
Zhao, Gang1b8ec872014-04-21 12:53:02 +08004437 err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev);
Johannes Berg67748892010-10-04 21:14:06 +02004438 if (err)
4439 return err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004440
Zhao, Gang1b8ec872014-04-21 12:53:02 +08004441 if (!rdev->ops->dump_mpath) {
Jouni Malineneec60b02009-03-20 21:21:19 +02004442 err = -EOPNOTSUPP;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004443 goto out_err;
4444 }
4445
Johannes Berg97990a02013-04-19 01:02:55 +02004446 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) {
Jouni Malineneec60b02009-03-20 21:21:19 +02004447 err = -EOPNOTSUPP;
Roel Kluin0448b5f2009-08-22 21:15:49 +02004448 goto out_err;
Jouni Malineneec60b02009-03-20 21:21:19 +02004449 }
4450
Johannes Bergbba95fe2008-07-29 13:22:51 +02004451 while (1) {
Zhao, Gang1b8ec872014-04-21 12:53:02 +08004452 err = rdev_dump_mpath(rdev, wdev->netdev, path_idx, dst,
Johannes Berg97990a02013-04-19 01:02:55 +02004453 next_hop, &pinfo);
Johannes Bergbba95fe2008-07-29 13:22:51 +02004454 if (err == -ENOENT)
4455 break;
4456 if (err)
Johannes Berg3b858752009-03-12 09:55:09 +01004457 goto out_err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004458
Eric W. Biederman15e47302012-09-07 20:12:54 +00004459 if (nl80211_send_mpath(skb, NETLINK_CB(cb->skb).portid,
Johannes Bergbba95fe2008-07-29 13:22:51 +02004460 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Johannes Berg97990a02013-04-19 01:02:55 +02004461 wdev->netdev, dst, next_hop,
Johannes Bergbba95fe2008-07-29 13:22:51 +02004462 &pinfo) < 0)
4463 goto out;
4464
4465 path_idx++;
4466 }
4467
4468
4469 out:
Johannes Berg97990a02013-04-19 01:02:55 +02004470 cb->args[2] = path_idx;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004471 err = skb->len;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004472 out_err:
Zhao, Gang1b8ec872014-04-21 12:53:02 +08004473 nl80211_finish_wdev_dump(rdev);
Johannes Bergbba95fe2008-07-29 13:22:51 +02004474 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004475}
4476
4477static int nl80211_get_mpath(struct sk_buff *skb, struct genl_info *info)
4478{
Johannes Berg4c476992010-10-04 21:36:35 +02004479 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004480 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02004481 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004482 struct mpath_info pinfo;
4483 struct sk_buff *msg;
4484 u8 *dst = NULL;
4485 u8 next_hop[ETH_ALEN];
4486
4487 memset(&pinfo, 0, sizeof(pinfo));
4488
4489 if (!info->attrs[NL80211_ATTR_MAC])
4490 return -EINVAL;
4491
4492 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
4493
Johannes Berg4c476992010-10-04 21:36:35 +02004494 if (!rdev->ops->get_mpath)
4495 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01004496
Johannes Berg4c476992010-10-04 21:36:35 +02004497 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
4498 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02004499
Hila Gonene35e4d22012-06-27 17:19:42 +03004500 err = rdev_get_mpath(rdev, dev, dst, next_hop, &pinfo);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004501 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02004502 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004503
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07004504 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004505 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02004506 return -ENOMEM;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004507
Eric W. Biederman15e47302012-09-07 20:12:54 +00004508 if (nl80211_send_mpath(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berg4c476992010-10-04 21:36:35 +02004509 dev, dst, next_hop, &pinfo) < 0) {
4510 nlmsg_free(msg);
4511 return -ENOBUFS;
4512 }
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004513
Johannes Berg4c476992010-10-04 21:36:35 +02004514 return genlmsg_reply(msg, info);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004515}
4516
4517static int nl80211_set_mpath(struct sk_buff *skb, struct genl_info *info)
4518{
Johannes Berg4c476992010-10-04 21:36:35 +02004519 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4520 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004521 u8 *dst = NULL;
4522 u8 *next_hop = NULL;
4523
4524 if (!info->attrs[NL80211_ATTR_MAC])
4525 return -EINVAL;
4526
4527 if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP])
4528 return -EINVAL;
4529
4530 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
4531 next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]);
4532
Johannes Berg4c476992010-10-04 21:36:35 +02004533 if (!rdev->ops->change_mpath)
4534 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01004535
Johannes Berg4c476992010-10-04 21:36:35 +02004536 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
4537 return -EOPNOTSUPP;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004538
Hila Gonene35e4d22012-06-27 17:19:42 +03004539 return rdev_change_mpath(rdev, dev, dst, next_hop);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004540}
Johannes Berg4c476992010-10-04 21:36:35 +02004541
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004542static int nl80211_new_mpath(struct sk_buff *skb, struct genl_info *info)
4543{
Johannes Berg4c476992010-10-04 21:36:35 +02004544 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4545 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004546 u8 *dst = NULL;
4547 u8 *next_hop = NULL;
4548
4549 if (!info->attrs[NL80211_ATTR_MAC])
4550 return -EINVAL;
4551
4552 if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP])
4553 return -EINVAL;
4554
4555 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
4556 next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]);
4557
Johannes Berg4c476992010-10-04 21:36:35 +02004558 if (!rdev->ops->add_mpath)
4559 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01004560
Johannes Berg4c476992010-10-04 21:36:35 +02004561 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
4562 return -EOPNOTSUPP;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004563
Hila Gonene35e4d22012-06-27 17:19:42 +03004564 return rdev_add_mpath(rdev, dev, dst, next_hop);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004565}
4566
4567static int nl80211_del_mpath(struct sk_buff *skb, struct genl_info *info)
4568{
Johannes Berg4c476992010-10-04 21:36:35 +02004569 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4570 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004571 u8 *dst = NULL;
4572
4573 if (info->attrs[NL80211_ATTR_MAC])
4574 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
4575
Johannes Berg4c476992010-10-04 21:36:35 +02004576 if (!rdev->ops->del_mpath)
4577 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01004578
Hila Gonene35e4d22012-06-27 17:19:42 +03004579 return rdev_del_mpath(rdev, dev, dst);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004580}
4581
Jouni Malinen9f1ba902008-08-07 20:07:01 +03004582static int nl80211_set_bss(struct sk_buff *skb, struct genl_info *info)
4583{
Johannes Berg4c476992010-10-04 21:36:35 +02004584 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4585 struct net_device *dev = info->user_ptr[1];
Simon Wunderlichc56589e2013-11-21 18:19:49 +01004586 struct wireless_dev *wdev = dev->ieee80211_ptr;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03004587 struct bss_parameters params;
Simon Wunderlichc56589e2013-11-21 18:19:49 +01004588 int err;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03004589
4590 memset(&params, 0, sizeof(params));
4591 /* default to not changing parameters */
4592 params.use_cts_prot = -1;
4593 params.use_short_preamble = -1;
4594 params.use_short_slot_time = -1;
Felix Fietkaufd8aaaf2010-04-27 01:23:35 +02004595 params.ap_isolate = -1;
Helmut Schaa50b12f52010-11-19 12:40:25 +01004596 params.ht_opmode = -1;
Johannes Berg53cabad2012-11-14 15:17:28 +01004597 params.p2p_ctwindow = -1;
4598 params.p2p_opp_ps = -1;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03004599
4600 if (info->attrs[NL80211_ATTR_BSS_CTS_PROT])
4601 params.use_cts_prot =
4602 nla_get_u8(info->attrs[NL80211_ATTR_BSS_CTS_PROT]);
4603 if (info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE])
4604 params.use_short_preamble =
4605 nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]);
4606 if (info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME])
4607 params.use_short_slot_time =
4608 nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]);
Jouni Malinen90c97a02008-10-30 16:59:22 +02004609 if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) {
4610 params.basic_rates =
4611 nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
4612 params.basic_rates_len =
4613 nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
4614 }
Felix Fietkaufd8aaaf2010-04-27 01:23:35 +02004615 if (info->attrs[NL80211_ATTR_AP_ISOLATE])
4616 params.ap_isolate = !!nla_get_u8(info->attrs[NL80211_ATTR_AP_ISOLATE]);
Helmut Schaa50b12f52010-11-19 12:40:25 +01004617 if (info->attrs[NL80211_ATTR_BSS_HT_OPMODE])
4618 params.ht_opmode =
4619 nla_get_u16(info->attrs[NL80211_ATTR_BSS_HT_OPMODE]);
Jouni Malinen9f1ba902008-08-07 20:07:01 +03004620
Johannes Berg53cabad2012-11-14 15:17:28 +01004621 if (info->attrs[NL80211_ATTR_P2P_CTWINDOW]) {
4622 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
4623 return -EINVAL;
4624 params.p2p_ctwindow =
4625 nla_get_s8(info->attrs[NL80211_ATTR_P2P_CTWINDOW]);
4626 if (params.p2p_ctwindow < 0)
4627 return -EINVAL;
4628 if (params.p2p_ctwindow != 0 &&
4629 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_CTWIN))
4630 return -EINVAL;
4631 }
4632
4633 if (info->attrs[NL80211_ATTR_P2P_OPPPS]) {
4634 u8 tmp;
4635
4636 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
4637 return -EINVAL;
4638 tmp = nla_get_u8(info->attrs[NL80211_ATTR_P2P_OPPPS]);
4639 if (tmp > 1)
4640 return -EINVAL;
4641 params.p2p_opp_ps = tmp;
4642 if (params.p2p_opp_ps &&
4643 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_OPPPS))
4644 return -EINVAL;
4645 }
4646
Johannes Berg4c476992010-10-04 21:36:35 +02004647 if (!rdev->ops->change_bss)
4648 return -EOPNOTSUPP;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03004649
Johannes Berg074ac8d2010-09-16 14:58:22 +02004650 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
Johannes Berg4c476992010-10-04 21:36:35 +02004651 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
4652 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02004653
Simon Wunderlichc56589e2013-11-21 18:19:49 +01004654 wdev_lock(wdev);
4655 err = rdev_change_bss(rdev, dev, &params);
4656 wdev_unlock(wdev);
4657
4658 return err;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03004659}
4660
Alexey Dobriyanb54452b2010-02-18 08:14:31 +00004661static const struct nla_policy reg_rule_policy[NL80211_REG_RULE_ATTR_MAX + 1] = {
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004662 [NL80211_ATTR_REG_RULE_FLAGS] = { .type = NLA_U32 },
4663 [NL80211_ATTR_FREQ_RANGE_START] = { .type = NLA_U32 },
4664 [NL80211_ATTR_FREQ_RANGE_END] = { .type = NLA_U32 },
4665 [NL80211_ATTR_FREQ_RANGE_MAX_BW] = { .type = NLA_U32 },
4666 [NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN] = { .type = NLA_U32 },
4667 [NL80211_ATTR_POWER_RULE_MAX_EIRP] = { .type = NLA_U32 },
Janusz Dziedzic089027e2014-02-21 19:46:12 +01004668 [NL80211_ATTR_DFS_CAC_TIME] = { .type = NLA_U32 },
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004669};
4670
4671static int parse_reg_rule(struct nlattr *tb[],
4672 struct ieee80211_reg_rule *reg_rule)
4673{
4674 struct ieee80211_freq_range *freq_range = &reg_rule->freq_range;
4675 struct ieee80211_power_rule *power_rule = &reg_rule->power_rule;
4676
4677 if (!tb[NL80211_ATTR_REG_RULE_FLAGS])
4678 return -EINVAL;
4679 if (!tb[NL80211_ATTR_FREQ_RANGE_START])
4680 return -EINVAL;
4681 if (!tb[NL80211_ATTR_FREQ_RANGE_END])
4682 return -EINVAL;
Janusz Dziedzicb0dfd2e2014-02-20 13:52:16 +01004683 if (!tb[NL80211_ATTR_FREQ_RANGE_MAX_BW])
4684 return -EINVAL;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004685 if (!tb[NL80211_ATTR_POWER_RULE_MAX_EIRP])
4686 return -EINVAL;
4687
4688 reg_rule->flags = nla_get_u32(tb[NL80211_ATTR_REG_RULE_FLAGS]);
4689
4690 freq_range->start_freq_khz =
4691 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_START]);
4692 freq_range->end_freq_khz =
4693 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_END]);
Janusz Dziedzicb0dfd2e2014-02-20 13:52:16 +01004694 freq_range->max_bandwidth_khz =
4695 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]);
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004696
4697 power_rule->max_eirp =
4698 nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]);
4699
4700 if (tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN])
4701 power_rule->max_antenna_gain =
4702 nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]);
4703
Janusz Dziedzic089027e2014-02-21 19:46:12 +01004704 if (tb[NL80211_ATTR_DFS_CAC_TIME])
4705 reg_rule->dfs_cac_ms =
4706 nla_get_u32(tb[NL80211_ATTR_DFS_CAC_TIME]);
4707
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004708 return 0;
4709}
4710
4711static int nl80211_req_set_reg(struct sk_buff *skb, struct genl_info *info)
4712{
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004713 char *data = NULL;
Luis R. Rodriguez57b5ce02012-07-12 11:49:18 -07004714 enum nl80211_user_reg_hint_type user_reg_hint_type;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004715
Luis R. Rodriguez80778f12009-02-21 00:04:22 -05004716 /*
4717 * You should only get this when cfg80211 hasn't yet initialized
4718 * completely when built-in to the kernel right between the time
4719 * window between nl80211_init() and regulatory_init(), if that is
4720 * even possible.
4721 */
Johannes Berg458f4f92012-12-06 15:47:38 +01004722 if (unlikely(!rcu_access_pointer(cfg80211_regdomain)))
Luis R. Rodriguezfe33eb32009-02-21 00:04:30 -05004723 return -EINPROGRESS;
Luis R. Rodriguez80778f12009-02-21 00:04:22 -05004724
Luis R. Rodriguez57b5ce02012-07-12 11:49:18 -07004725 if (info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE])
4726 user_reg_hint_type =
4727 nla_get_u32(info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE]);
4728 else
4729 user_reg_hint_type = NL80211_USER_REG_HINT_USER;
4730
4731 switch (user_reg_hint_type) {
4732 case NL80211_USER_REG_HINT_USER:
4733 case NL80211_USER_REG_HINT_CELL_BASE:
Ilan Peer52616f22014-02-25 16:26:00 +02004734 if (!info->attrs[NL80211_ATTR_REG_ALPHA2])
4735 return -EINVAL;
4736
4737 data = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]);
4738 return regulatory_hint_user(data, user_reg_hint_type);
4739 case NL80211_USER_REG_HINT_INDOOR:
4740 return regulatory_hint_indoor_user();
Luis R. Rodriguez57b5ce02012-07-12 11:49:18 -07004741 default:
4742 return -EINVAL;
4743 }
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004744}
4745
Javier Cardona24bdd9f2010-12-16 17:37:48 -08004746static int nl80211_get_mesh_config(struct sk_buff *skb,
Johannes Berg29cbe682010-12-03 09:20:44 +01004747 struct genl_info *info)
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004748{
Johannes Berg4c476992010-10-04 21:36:35 +02004749 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg4c476992010-10-04 21:36:35 +02004750 struct net_device *dev = info->user_ptr[1];
Johannes Berg29cbe682010-12-03 09:20:44 +01004751 struct wireless_dev *wdev = dev->ieee80211_ptr;
4752 struct mesh_config cur_params;
4753 int err = 0;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004754 void *hdr;
4755 struct nlattr *pinfoattr;
4756 struct sk_buff *msg;
4757
Johannes Berg29cbe682010-12-03 09:20:44 +01004758 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT)
4759 return -EOPNOTSUPP;
4760
Javier Cardona24bdd9f2010-12-16 17:37:48 -08004761 if (!rdev->ops->get_mesh_config)
Johannes Berg4c476992010-10-04 21:36:35 +02004762 return -EOPNOTSUPP;
Jouni Malinenf3f92582009-03-20 17:57:36 +02004763
Johannes Berg29cbe682010-12-03 09:20:44 +01004764 wdev_lock(wdev);
4765 /* If not connected, get default parameters */
4766 if (!wdev->mesh_id_len)
4767 memcpy(&cur_params, &default_mesh_config, sizeof(cur_params));
4768 else
Hila Gonene35e4d22012-06-27 17:19:42 +03004769 err = rdev_get_mesh_config(rdev, dev, &cur_params);
Johannes Berg29cbe682010-12-03 09:20:44 +01004770 wdev_unlock(wdev);
4771
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004772 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02004773 return err;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004774
4775 /* Draw up a netlink message to send back */
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07004776 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02004777 if (!msg)
4778 return -ENOMEM;
Eric W. Biederman15e47302012-09-07 20:12:54 +00004779 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Javier Cardona24bdd9f2010-12-16 17:37:48 -08004780 NL80211_CMD_GET_MESH_CONFIG);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004781 if (!hdr)
Julia Lawallefe1cf02011-01-28 15:17:11 +01004782 goto out;
Javier Cardona24bdd9f2010-12-16 17:37:48 -08004783 pinfoattr = nla_nest_start(msg, NL80211_ATTR_MESH_CONFIG);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004784 if (!pinfoattr)
4785 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04004786 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
4787 nla_put_u16(msg, NL80211_MESHCONF_RETRY_TIMEOUT,
4788 cur_params.dot11MeshRetryTimeout) ||
4789 nla_put_u16(msg, NL80211_MESHCONF_CONFIRM_TIMEOUT,
4790 cur_params.dot11MeshConfirmTimeout) ||
4791 nla_put_u16(msg, NL80211_MESHCONF_HOLDING_TIMEOUT,
4792 cur_params.dot11MeshHoldingTimeout) ||
4793 nla_put_u16(msg, NL80211_MESHCONF_MAX_PEER_LINKS,
4794 cur_params.dot11MeshMaxPeerLinks) ||
4795 nla_put_u8(msg, NL80211_MESHCONF_MAX_RETRIES,
4796 cur_params.dot11MeshMaxRetries) ||
4797 nla_put_u8(msg, NL80211_MESHCONF_TTL,
4798 cur_params.dot11MeshTTL) ||
4799 nla_put_u8(msg, NL80211_MESHCONF_ELEMENT_TTL,
4800 cur_params.element_ttl) ||
4801 nla_put_u8(msg, NL80211_MESHCONF_AUTO_OPEN_PLINKS,
4802 cur_params.auto_open_plinks) ||
John W. Linville7eab0f62012-04-12 14:25:14 -04004803 nla_put_u32(msg, NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR,
4804 cur_params.dot11MeshNbrOffsetMaxNeighbor) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04004805 nla_put_u8(msg, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES,
4806 cur_params.dot11MeshHWMPmaxPREQretries) ||
4807 nla_put_u32(msg, NL80211_MESHCONF_PATH_REFRESH_TIME,
4808 cur_params.path_refresh_time) ||
4809 nla_put_u16(msg, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT,
4810 cur_params.min_discovery_timeout) ||
4811 nla_put_u32(msg, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT,
4812 cur_params.dot11MeshHWMPactivePathTimeout) ||
4813 nla_put_u16(msg, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL,
4814 cur_params.dot11MeshHWMPpreqMinInterval) ||
4815 nla_put_u16(msg, NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL,
4816 cur_params.dot11MeshHWMPperrMinInterval) ||
4817 nla_put_u16(msg, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME,
4818 cur_params.dot11MeshHWMPnetDiameterTraversalTime) ||
4819 nla_put_u8(msg, NL80211_MESHCONF_HWMP_ROOTMODE,
4820 cur_params.dot11MeshHWMPRootMode) ||
4821 nla_put_u16(msg, NL80211_MESHCONF_HWMP_RANN_INTERVAL,
4822 cur_params.dot11MeshHWMPRannInterval) ||
4823 nla_put_u8(msg, NL80211_MESHCONF_GATE_ANNOUNCEMENTS,
4824 cur_params.dot11MeshGateAnnouncementProtocol) ||
4825 nla_put_u8(msg, NL80211_MESHCONF_FORWARDING,
4826 cur_params.dot11MeshForwarding) ||
4827 nla_put_u32(msg, NL80211_MESHCONF_RSSI_THRESHOLD,
Ashok Nagarajan70c33ea2012-04-30 14:20:32 -07004828 cur_params.rssi_threshold) ||
4829 nla_put_u32(msg, NL80211_MESHCONF_HT_OPMODE,
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08004830 cur_params.ht_opmode) ||
4831 nla_put_u32(msg, NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT,
4832 cur_params.dot11MeshHWMPactivePathToRootTimeout) ||
4833 nla_put_u16(msg, NL80211_MESHCONF_HWMP_ROOT_INTERVAL,
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +08004834 cur_params.dot11MeshHWMProotInterval) ||
4835 nla_put_u16(msg, NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL,
Marco Porsch3b1c5a52013-01-07 16:04:52 +01004836 cur_params.dot11MeshHWMPconfirmationInterval) ||
4837 nla_put_u32(msg, NL80211_MESHCONF_POWER_MODE,
4838 cur_params.power_mode) ||
4839 nla_put_u16(msg, NL80211_MESHCONF_AWAKE_WINDOW,
Colleen Twitty8e7c0532013-06-03 09:53:39 -07004840 cur_params.dot11MeshAwakeWindowDuration) ||
4841 nla_put_u32(msg, NL80211_MESHCONF_PLINK_TIMEOUT,
4842 cur_params.plink_timeout))
David S. Miller9360ffd2012-03-29 04:41:26 -04004843 goto nla_put_failure;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004844 nla_nest_end(msg, pinfoattr);
4845 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02004846 return genlmsg_reply(msg, info);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004847
Johannes Berg3b858752009-03-12 09:55:09 +01004848 nla_put_failure:
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004849 genlmsg_cancel(msg, hdr);
Julia Lawallefe1cf02011-01-28 15:17:11 +01004850 out:
Yuri Ershovd080e272010-06-29 15:08:07 +04004851 nlmsg_free(msg);
Johannes Berg4c476992010-10-04 21:36:35 +02004852 return -ENOBUFS;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004853}
4854
Alexey Dobriyanb54452b2010-02-18 08:14:31 +00004855static const struct nla_policy nl80211_meshconf_params_policy[NL80211_MESHCONF_ATTR_MAX+1] = {
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004856 [NL80211_MESHCONF_RETRY_TIMEOUT] = { .type = NLA_U16 },
4857 [NL80211_MESHCONF_CONFIRM_TIMEOUT] = { .type = NLA_U16 },
4858 [NL80211_MESHCONF_HOLDING_TIMEOUT] = { .type = NLA_U16 },
4859 [NL80211_MESHCONF_MAX_PEER_LINKS] = { .type = NLA_U16 },
4860 [NL80211_MESHCONF_MAX_RETRIES] = { .type = NLA_U8 },
4861 [NL80211_MESHCONF_TTL] = { .type = NLA_U8 },
Javier Cardona45904f22010-12-03 09:20:40 +01004862 [NL80211_MESHCONF_ELEMENT_TTL] = { .type = NLA_U8 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004863 [NL80211_MESHCONF_AUTO_OPEN_PLINKS] = { .type = NLA_U8 },
Javier Cardonad299a1f2012-03-31 11:31:33 -07004864 [NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR] = { .type = NLA_U32 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004865 [NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES] = { .type = NLA_U8 },
4866 [NL80211_MESHCONF_PATH_REFRESH_TIME] = { .type = NLA_U32 },
4867 [NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT] = { .type = NLA_U16 },
4868 [NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT] = { .type = NLA_U32 },
4869 [NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL] = { .type = NLA_U16 },
Thomas Pedersendca7e942011-11-24 17:15:24 -08004870 [NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL] = { .type = NLA_U16 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004871 [NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME] = { .type = NLA_U16 },
Javier Cardona699403d2011-08-09 16:45:09 -07004872 [NL80211_MESHCONF_HWMP_ROOTMODE] = { .type = NLA_U8 },
Javier Cardona0507e152011-08-09 16:45:10 -07004873 [NL80211_MESHCONF_HWMP_RANN_INTERVAL] = { .type = NLA_U16 },
Javier Cardona16dd7262011-08-09 16:45:11 -07004874 [NL80211_MESHCONF_GATE_ANNOUNCEMENTS] = { .type = NLA_U8 },
Chun-Yeow Yeoh94f90652012-01-21 01:02:16 +08004875 [NL80211_MESHCONF_FORWARDING] = { .type = NLA_U8 },
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004876 [NL80211_MESHCONF_RSSI_THRESHOLD] = { .type = NLA_U32 },
4877 [NL80211_MESHCONF_HT_OPMODE] = { .type = NLA_U16 },
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08004878 [NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT] = { .type = NLA_U32 },
4879 [NL80211_MESHCONF_HWMP_ROOT_INTERVAL] = { .type = NLA_U16 },
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +08004880 [NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL] = { .type = NLA_U16 },
Marco Porsch3b1c5a52013-01-07 16:04:52 +01004881 [NL80211_MESHCONF_POWER_MODE] = { .type = NLA_U32 },
4882 [NL80211_MESHCONF_AWAKE_WINDOW] = { .type = NLA_U16 },
Colleen Twitty8e7c0532013-06-03 09:53:39 -07004883 [NL80211_MESHCONF_PLINK_TIMEOUT] = { .type = NLA_U32 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004884};
4885
Javier Cardonac80d5452010-12-16 17:37:49 -08004886static const struct nla_policy
4887 nl80211_mesh_setup_params_policy[NL80211_MESH_SETUP_ATTR_MAX+1] = {
Javier Cardonad299a1f2012-03-31 11:31:33 -07004888 [NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC] = { .type = NLA_U8 },
Javier Cardonac80d5452010-12-16 17:37:49 -08004889 [NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL] = { .type = NLA_U8 },
4890 [NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC] = { .type = NLA_U8 },
Javier Cardona15d5dda2011-04-07 15:08:28 -07004891 [NL80211_MESH_SETUP_USERSPACE_AUTH] = { .type = NLA_FLAG },
Colleen Twitty6e16d902013-05-08 11:45:59 -07004892 [NL80211_MESH_SETUP_AUTH_PROTOCOL] = { .type = NLA_U8 },
Thomas Pedersenbb2798d2013-03-04 13:06:10 -08004893 [NL80211_MESH_SETUP_USERSPACE_MPM] = { .type = NLA_FLAG },
Javier Cardona581a8b02011-04-07 15:08:27 -07004894 [NL80211_MESH_SETUP_IE] = { .type = NLA_BINARY,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004895 .len = IEEE80211_MAX_DATA_LEN },
Javier Cardonab130e5c2011-05-03 16:57:07 -07004896 [NL80211_MESH_SETUP_USERSPACE_AMPE] = { .type = NLA_FLAG },
Javier Cardonac80d5452010-12-16 17:37:49 -08004897};
4898
Javier Cardona24bdd9f2010-12-16 17:37:48 -08004899static int nl80211_parse_mesh_config(struct genl_info *info,
Johannes Bergbd90fdc2010-12-03 09:20:43 +01004900 struct mesh_config *cfg,
4901 u32 *mask_out)
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004902{
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004903 struct nlattr *tb[NL80211_MESHCONF_ATTR_MAX + 1];
Johannes Bergbd90fdc2010-12-03 09:20:43 +01004904 u32 mask = 0;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004905
Marco Porschea54fba2013-01-07 16:04:48 +01004906#define FILL_IN_MESH_PARAM_IF_SET(tb, cfg, param, min, max, mask, attr, fn) \
4907do { \
4908 if (tb[attr]) { \
4909 if (fn(tb[attr]) < min || fn(tb[attr]) > max) \
4910 return -EINVAL; \
4911 cfg->param = fn(tb[attr]); \
4912 mask |= (1 << (attr - 1)); \
4913 } \
4914} while (0)
Johannes Bergbd90fdc2010-12-03 09:20:43 +01004915
4916
Javier Cardona24bdd9f2010-12-16 17:37:48 -08004917 if (!info->attrs[NL80211_ATTR_MESH_CONFIG])
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004918 return -EINVAL;
4919 if (nla_parse_nested(tb, NL80211_MESHCONF_ATTR_MAX,
Javier Cardona24bdd9f2010-12-16 17:37:48 -08004920 info->attrs[NL80211_ATTR_MESH_CONFIG],
Johannes Bergbd90fdc2010-12-03 09:20:43 +01004921 nl80211_meshconf_params_policy))
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004922 return -EINVAL;
4923
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004924 /* This makes sure that there aren't more than 32 mesh config
4925 * parameters (otherwise our bitfield scheme would not work.) */
4926 BUILD_BUG_ON(NL80211_MESHCONF_ATTR_MAX > 32);
4927
4928 /* Fill in the params struct */
Marco Porschea54fba2013-01-07 16:04:48 +01004929 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshRetryTimeout, 1, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004930 mask, NL80211_MESHCONF_RETRY_TIMEOUT,
4931 nla_get_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01004932 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshConfirmTimeout, 1, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004933 mask, NL80211_MESHCONF_CONFIRM_TIMEOUT,
4934 nla_get_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01004935 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHoldingTimeout, 1, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004936 mask, NL80211_MESHCONF_HOLDING_TIMEOUT,
4937 nla_get_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01004938 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxPeerLinks, 0, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004939 mask, NL80211_MESHCONF_MAX_PEER_LINKS,
4940 nla_get_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01004941 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxRetries, 0, 16,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004942 mask, NL80211_MESHCONF_MAX_RETRIES,
4943 nla_get_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01004944 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshTTL, 1, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004945 mask, NL80211_MESHCONF_TTL, nla_get_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01004946 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, element_ttl, 1, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004947 mask, NL80211_MESHCONF_ELEMENT_TTL,
4948 nla_get_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01004949 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, auto_open_plinks, 0, 1,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004950 mask, NL80211_MESHCONF_AUTO_OPEN_PLINKS,
4951 nla_get_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01004952 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshNbrOffsetMaxNeighbor,
4953 1, 255, mask,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004954 NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR,
4955 nla_get_u32);
Marco Porschea54fba2013-01-07 16:04:48 +01004956 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPmaxPREQretries, 0, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004957 mask, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES,
4958 nla_get_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01004959 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, path_refresh_time, 1, 65535,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004960 mask, NL80211_MESHCONF_PATH_REFRESH_TIME,
4961 nla_get_u32);
Marco Porschea54fba2013-01-07 16:04:48 +01004962 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, min_discovery_timeout, 1, 65535,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004963 mask, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT,
4964 nla_get_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01004965 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathTimeout,
4966 1, 65535, mask,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004967 NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT,
4968 nla_get_u32);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004969 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPpreqMinInterval,
Marco Porschea54fba2013-01-07 16:04:48 +01004970 1, 65535, mask,
4971 NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004972 nla_get_u16);
Thomas Pedersendca7e942011-11-24 17:15:24 -08004973 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPperrMinInterval,
Marco Porschea54fba2013-01-07 16:04:48 +01004974 1, 65535, mask,
4975 NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004976 nla_get_u16);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004977 FILL_IN_MESH_PARAM_IF_SET(tb, cfg,
Marco Porschea54fba2013-01-07 16:04:48 +01004978 dot11MeshHWMPnetDiameterTraversalTime,
4979 1, 65535, mask,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004980 NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME,
4981 nla_get_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01004982 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRootMode, 0, 4,
4983 mask, NL80211_MESHCONF_HWMP_ROOTMODE,
4984 nla_get_u8);
4985 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRannInterval, 1, 65535,
4986 mask, NL80211_MESHCONF_HWMP_RANN_INTERVAL,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004987 nla_get_u16);
Rui Paulo63c57232009-11-09 23:46:57 +00004988 FILL_IN_MESH_PARAM_IF_SET(tb, cfg,
Marco Porschea54fba2013-01-07 16:04:48 +01004989 dot11MeshGateAnnouncementProtocol, 0, 1,
4990 mask, NL80211_MESHCONF_GATE_ANNOUNCEMENTS,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004991 nla_get_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01004992 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshForwarding, 0, 1,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004993 mask, NL80211_MESHCONF_FORWARDING,
4994 nla_get_u8);
Chun-Yeow Yeoh83374fe2013-07-11 18:24:03 +08004995 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, rssi_threshold, -255, 0,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004996 mask, NL80211_MESHCONF_RSSI_THRESHOLD,
Chun-Yeow Yeoh83374fe2013-07-11 18:24:03 +08004997 nla_get_s32);
Marco Porschea54fba2013-01-07 16:04:48 +01004998 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, ht_opmode, 0, 16,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004999 mask, NL80211_MESHCONF_HT_OPMODE,
5000 nla_get_u16);
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08005001 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathToRootTimeout,
Marco Porschea54fba2013-01-07 16:04:48 +01005002 1, 65535, mask,
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08005003 NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT,
5004 nla_get_u32);
Marco Porschea54fba2013-01-07 16:04:48 +01005005 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMProotInterval, 1, 65535,
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08005006 mask, NL80211_MESHCONF_HWMP_ROOT_INTERVAL,
5007 nla_get_u16);
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +08005008 FILL_IN_MESH_PARAM_IF_SET(tb, cfg,
Marco Porschea54fba2013-01-07 16:04:48 +01005009 dot11MeshHWMPconfirmationInterval,
5010 1, 65535, mask,
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +08005011 NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL,
5012 nla_get_u16);
Marco Porsch3b1c5a52013-01-07 16:04:52 +01005013 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, power_mode,
5014 NL80211_MESH_POWER_ACTIVE,
5015 NL80211_MESH_POWER_MAX,
5016 mask, NL80211_MESHCONF_POWER_MODE,
5017 nla_get_u32);
5018 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshAwakeWindowDuration,
5019 0, 65535, mask,
5020 NL80211_MESHCONF_AWAKE_WINDOW, nla_get_u16);
Colleen Twitty8e7c0532013-06-03 09:53:39 -07005021 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, plink_timeout, 1, 0xffffffff,
5022 mask, NL80211_MESHCONF_PLINK_TIMEOUT,
5023 nla_get_u32);
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005024 if (mask_out)
5025 *mask_out = mask;
Javier Cardonac80d5452010-12-16 17:37:49 -08005026
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005027 return 0;
5028
5029#undef FILL_IN_MESH_PARAM_IF_SET
5030}
5031
Javier Cardonac80d5452010-12-16 17:37:49 -08005032static int nl80211_parse_mesh_setup(struct genl_info *info,
5033 struct mesh_setup *setup)
5034{
Thomas Pedersenbb2798d2013-03-04 13:06:10 -08005035 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Javier Cardonac80d5452010-12-16 17:37:49 -08005036 struct nlattr *tb[NL80211_MESH_SETUP_ATTR_MAX + 1];
5037
5038 if (!info->attrs[NL80211_ATTR_MESH_SETUP])
5039 return -EINVAL;
5040 if (nla_parse_nested(tb, NL80211_MESH_SETUP_ATTR_MAX,
5041 info->attrs[NL80211_ATTR_MESH_SETUP],
5042 nl80211_mesh_setup_params_policy))
5043 return -EINVAL;
5044
Javier Cardonad299a1f2012-03-31 11:31:33 -07005045 if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC])
5046 setup->sync_method =
5047 (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC])) ?
5048 IEEE80211_SYNC_METHOD_VENDOR :
5049 IEEE80211_SYNC_METHOD_NEIGHBOR_OFFSET;
5050
Javier Cardonac80d5452010-12-16 17:37:49 -08005051 if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL])
5052 setup->path_sel_proto =
5053 (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL])) ?
5054 IEEE80211_PATH_PROTOCOL_VENDOR :
5055 IEEE80211_PATH_PROTOCOL_HWMP;
5056
5057 if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC])
5058 setup->path_metric =
5059 (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC])) ?
5060 IEEE80211_PATH_METRIC_VENDOR :
5061 IEEE80211_PATH_METRIC_AIRTIME;
5062
Javier Cardona581a8b02011-04-07 15:08:27 -07005063
5064 if (tb[NL80211_MESH_SETUP_IE]) {
Javier Cardonac80d5452010-12-16 17:37:49 -08005065 struct nlattr *ieattr =
Javier Cardona581a8b02011-04-07 15:08:27 -07005066 tb[NL80211_MESH_SETUP_IE];
Javier Cardonac80d5452010-12-16 17:37:49 -08005067 if (!is_valid_ie_attr(ieattr))
5068 return -EINVAL;
Javier Cardona581a8b02011-04-07 15:08:27 -07005069 setup->ie = nla_data(ieattr);
5070 setup->ie_len = nla_len(ieattr);
Javier Cardonac80d5452010-12-16 17:37:49 -08005071 }
Thomas Pedersenbb2798d2013-03-04 13:06:10 -08005072 if (tb[NL80211_MESH_SETUP_USERSPACE_MPM] &&
5073 !(rdev->wiphy.features & NL80211_FEATURE_USERSPACE_MPM))
5074 return -EINVAL;
5075 setup->user_mpm = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_MPM]);
Javier Cardonab130e5c2011-05-03 16:57:07 -07005076 setup->is_authenticated = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AUTH]);
5077 setup->is_secure = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AMPE]);
Thomas Pedersenbb2798d2013-03-04 13:06:10 -08005078 if (setup->is_secure)
5079 setup->user_mpm = true;
Javier Cardonac80d5452010-12-16 17:37:49 -08005080
Colleen Twitty6e16d902013-05-08 11:45:59 -07005081 if (tb[NL80211_MESH_SETUP_AUTH_PROTOCOL]) {
5082 if (!setup->user_mpm)
5083 return -EINVAL;
5084 setup->auth_id =
5085 nla_get_u8(tb[NL80211_MESH_SETUP_AUTH_PROTOCOL]);
5086 }
5087
Javier Cardonac80d5452010-12-16 17:37:49 -08005088 return 0;
5089}
5090
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005091static int nl80211_update_mesh_config(struct sk_buff *skb,
Johannes Berg29cbe682010-12-03 09:20:44 +01005092 struct genl_info *info)
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005093{
5094 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5095 struct net_device *dev = info->user_ptr[1];
Johannes Berg29cbe682010-12-03 09:20:44 +01005096 struct wireless_dev *wdev = dev->ieee80211_ptr;
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005097 struct mesh_config cfg;
5098 u32 mask;
5099 int err;
5100
Johannes Berg29cbe682010-12-03 09:20:44 +01005101 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT)
5102 return -EOPNOTSUPP;
5103
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005104 if (!rdev->ops->update_mesh_config)
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005105 return -EOPNOTSUPP;
5106
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005107 err = nl80211_parse_mesh_config(info, &cfg, &mask);
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005108 if (err)
5109 return err;
5110
Johannes Berg29cbe682010-12-03 09:20:44 +01005111 wdev_lock(wdev);
5112 if (!wdev->mesh_id_len)
5113 err = -ENOLINK;
5114
5115 if (!err)
Hila Gonene35e4d22012-06-27 17:19:42 +03005116 err = rdev_update_mesh_config(rdev, dev, mask, &cfg);
Johannes Berg29cbe682010-12-03 09:20:44 +01005117
5118 wdev_unlock(wdev);
5119
5120 return err;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005121}
5122
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005123static int nl80211_get_reg(struct sk_buff *skb, struct genl_info *info)
5124{
Johannes Berg458f4f92012-12-06 15:47:38 +01005125 const struct ieee80211_regdomain *regdom;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005126 struct sk_buff *msg;
5127 void *hdr = NULL;
5128 struct nlattr *nl_reg_rules;
5129 unsigned int i;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005130
5131 if (!cfg80211_regdomain)
Johannes Berg5fe231e2013-05-08 21:45:15 +02005132 return -EINVAL;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005133
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07005134 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg5fe231e2013-05-08 21:45:15 +02005135 if (!msg)
5136 return -ENOBUFS;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005137
Eric W. Biederman15e47302012-09-07 20:12:54 +00005138 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005139 NL80211_CMD_GET_REG);
5140 if (!hdr)
Julia Lawallefe1cf02011-01-28 15:17:11 +01005141 goto put_failure;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005142
Luis R. Rodriguez57b5ce02012-07-12 11:49:18 -07005143 if (reg_last_request_cell_base() &&
5144 nla_put_u32(msg, NL80211_ATTR_USER_REG_HINT_TYPE,
5145 NL80211_USER_REG_HINT_CELL_BASE))
5146 goto nla_put_failure;
5147
Johannes Berg458f4f92012-12-06 15:47:38 +01005148 rcu_read_lock();
5149 regdom = rcu_dereference(cfg80211_regdomain);
5150
5151 if (nla_put_string(msg, NL80211_ATTR_REG_ALPHA2, regdom->alpha2) ||
5152 (regdom->dfs_region &&
5153 nla_put_u8(msg, NL80211_ATTR_DFS_REGION, regdom->dfs_region)))
5154 goto nla_put_failure_rcu;
5155
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005156 nl_reg_rules = nla_nest_start(msg, NL80211_ATTR_REG_RULES);
5157 if (!nl_reg_rules)
Johannes Berg458f4f92012-12-06 15:47:38 +01005158 goto nla_put_failure_rcu;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005159
Johannes Berg458f4f92012-12-06 15:47:38 +01005160 for (i = 0; i < regdom->n_reg_rules; i++) {
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005161 struct nlattr *nl_reg_rule;
5162 const struct ieee80211_reg_rule *reg_rule;
5163 const struct ieee80211_freq_range *freq_range;
5164 const struct ieee80211_power_rule *power_rule;
Janusz Dziedzic97524822014-01-30 09:52:20 +01005165 unsigned int max_bandwidth_khz;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005166
Johannes Berg458f4f92012-12-06 15:47:38 +01005167 reg_rule = &regdom->reg_rules[i];
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005168 freq_range = &reg_rule->freq_range;
5169 power_rule = &reg_rule->power_rule;
5170
5171 nl_reg_rule = nla_nest_start(msg, i);
5172 if (!nl_reg_rule)
Johannes Berg458f4f92012-12-06 15:47:38 +01005173 goto nla_put_failure_rcu;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005174
Janusz Dziedzic97524822014-01-30 09:52:20 +01005175 max_bandwidth_khz = freq_range->max_bandwidth_khz;
5176 if (!max_bandwidth_khz)
5177 max_bandwidth_khz = reg_get_max_bandwidth(regdom,
5178 reg_rule);
5179
David S. Miller9360ffd2012-03-29 04:41:26 -04005180 if (nla_put_u32(msg, NL80211_ATTR_REG_RULE_FLAGS,
5181 reg_rule->flags) ||
5182 nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_START,
5183 freq_range->start_freq_khz) ||
5184 nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_END,
5185 freq_range->end_freq_khz) ||
5186 nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_MAX_BW,
Janusz Dziedzic97524822014-01-30 09:52:20 +01005187 max_bandwidth_khz) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04005188 nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN,
5189 power_rule->max_antenna_gain) ||
5190 nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_EIRP,
Janusz Dziedzic089027e2014-02-21 19:46:12 +01005191 power_rule->max_eirp) ||
5192 nla_put_u32(msg, NL80211_ATTR_DFS_CAC_TIME,
5193 reg_rule->dfs_cac_ms))
Johannes Berg458f4f92012-12-06 15:47:38 +01005194 goto nla_put_failure_rcu;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005195
5196 nla_nest_end(msg, nl_reg_rule);
5197 }
Johannes Berg458f4f92012-12-06 15:47:38 +01005198 rcu_read_unlock();
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005199
5200 nla_nest_end(msg, nl_reg_rules);
5201
5202 genlmsg_end(msg, hdr);
Johannes Berg5fe231e2013-05-08 21:45:15 +02005203 return genlmsg_reply(msg, info);
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005204
Johannes Berg458f4f92012-12-06 15:47:38 +01005205nla_put_failure_rcu:
5206 rcu_read_unlock();
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005207nla_put_failure:
5208 genlmsg_cancel(msg, hdr);
Julia Lawallefe1cf02011-01-28 15:17:11 +01005209put_failure:
Yuri Ershovd080e272010-06-29 15:08:07 +04005210 nlmsg_free(msg);
Johannes Berg5fe231e2013-05-08 21:45:15 +02005211 return -EMSGSIZE;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005212}
5213
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005214static int nl80211_set_reg(struct sk_buff *skb, struct genl_info *info)
5215{
5216 struct nlattr *tb[NL80211_REG_RULE_ATTR_MAX + 1];
5217 struct nlattr *nl_reg_rule;
5218 char *alpha2 = NULL;
5219 int rem_reg_rules = 0, r = 0;
5220 u32 num_rules = 0, rule_idx = 0, size_of_regd;
Luis R. Rodriguez4c7d3982013-11-13 18:54:02 +01005221 enum nl80211_dfs_regions dfs_region = NL80211_DFS_UNSET;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005222 struct ieee80211_regdomain *rd = NULL;
5223
5224 if (!info->attrs[NL80211_ATTR_REG_ALPHA2])
5225 return -EINVAL;
5226
5227 if (!info->attrs[NL80211_ATTR_REG_RULES])
5228 return -EINVAL;
5229
5230 alpha2 = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]);
5231
Luis R. Rodriguez8b60b072011-10-11 10:59:02 -07005232 if (info->attrs[NL80211_ATTR_DFS_REGION])
5233 dfs_region = nla_get_u8(info->attrs[NL80211_ATTR_DFS_REGION]);
5234
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005235 nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES],
Johannes Berg1a919312012-12-03 17:21:11 +01005236 rem_reg_rules) {
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005237 num_rules++;
5238 if (num_rules > NL80211_MAX_SUPP_REG_RULES)
Luis R. Rodriguez4776c6e2009-05-13 17:04:39 -04005239 return -EINVAL;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005240 }
5241
Luis R. Rodrigueze4387682013-11-05 09:18:01 -08005242 if (!reg_is_valid_request(alpha2))
5243 return -EINVAL;
5244
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005245 size_of_regd = sizeof(struct ieee80211_regdomain) +
Johannes Berg1a919312012-12-03 17:21:11 +01005246 num_rules * sizeof(struct ieee80211_reg_rule);
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005247
5248 rd = kzalloc(size_of_regd, GFP_KERNEL);
Johannes Berg6913b492012-12-04 00:48:59 +01005249 if (!rd)
5250 return -ENOMEM;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005251
5252 rd->n_reg_rules = num_rules;
5253 rd->alpha2[0] = alpha2[0];
5254 rd->alpha2[1] = alpha2[1];
5255
Luis R. Rodriguez8b60b072011-10-11 10:59:02 -07005256 /*
5257 * Disable DFS master mode if the DFS region was
5258 * not supported or known on this kernel.
5259 */
5260 if (reg_supported_dfs_region(dfs_region))
5261 rd->dfs_region = dfs_region;
5262
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005263 nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES],
Johannes Berg1a919312012-12-03 17:21:11 +01005264 rem_reg_rules) {
Johannes Bergae811e22014-01-24 10:17:47 +01005265 r = nla_parse(tb, NL80211_REG_RULE_ATTR_MAX,
5266 nla_data(nl_reg_rule), nla_len(nl_reg_rule),
5267 reg_rule_policy);
5268 if (r)
5269 goto bad_reg;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005270 r = parse_reg_rule(tb, &rd->reg_rules[rule_idx]);
5271 if (r)
5272 goto bad_reg;
5273
5274 rule_idx++;
5275
Luis R. Rodriguezd0e18f82009-05-13 17:04:40 -04005276 if (rule_idx > NL80211_MAX_SUPP_REG_RULES) {
5277 r = -EINVAL;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005278 goto bad_reg;
Luis R. Rodriguezd0e18f82009-05-13 17:04:40 -04005279 }
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005280 }
5281
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005282 r = set_regdom(rd);
Johannes Berg6913b492012-12-04 00:48:59 +01005283 /* set_regdom took ownership */
Johannes Berg1a919312012-12-03 17:21:11 +01005284 rd = NULL;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005285
Johannes Bergd2372b32008-10-24 20:32:20 +02005286 bad_reg:
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005287 kfree(rd);
Luis R. Rodriguezd0e18f82009-05-13 17:04:40 -04005288 return r;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005289}
5290
Johannes Berg83f5e2c2009-06-17 17:41:49 +02005291static int validate_scan_freqs(struct nlattr *freqs)
5292{
5293 struct nlattr *attr1, *attr2;
5294 int n_channels = 0, tmp1, tmp2;
5295
5296 nla_for_each_nested(attr1, freqs, tmp1) {
5297 n_channels++;
5298 /*
5299 * Some hardware has a limited channel list for
5300 * scanning, and it is pretty much nonsensical
5301 * to scan for a channel twice, so disallow that
5302 * and don't require drivers to check that the
5303 * channel list they get isn't longer than what
5304 * they can scan, as long as they can scan all
5305 * the channels they registered at once.
5306 */
5307 nla_for_each_nested(attr2, freqs, tmp2)
5308 if (attr1 != attr2 &&
5309 nla_get_u32(attr1) == nla_get_u32(attr2))
5310 return 0;
5311 }
5312
5313 return n_channels;
5314}
5315
Johannes Berg2a519312009-02-10 21:25:55 +01005316static int nl80211_trigger_scan(struct sk_buff *skb, struct genl_info *info)
5317{
Johannes Berg4c476992010-10-04 21:36:35 +02005318 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Bergfd014282012-06-18 19:17:03 +02005319 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg2a519312009-02-10 21:25:55 +01005320 struct cfg80211_scan_request *request;
Johannes Berg2a519312009-02-10 21:25:55 +01005321 struct nlattr *attr;
5322 struct wiphy *wiphy;
Johannes Berg83f5e2c2009-06-17 17:41:49 +02005323 int err, tmp, n_ssids = 0, n_channels, i;
Jouni Malinen70692ad2009-02-16 19:39:13 +02005324 size_t ie_len;
Johannes Berg2a519312009-02-10 21:25:55 +01005325
Johannes Bergf4a11bb2009-03-27 12:40:28 +01005326 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
5327 return -EINVAL;
5328
Johannes Berg79c97e92009-07-07 03:56:12 +02005329 wiphy = &rdev->wiphy;
Johannes Berg2a519312009-02-10 21:25:55 +01005330
Johannes Berg4c476992010-10-04 21:36:35 +02005331 if (!rdev->ops->scan)
5332 return -EOPNOTSUPP;
Johannes Berg2a519312009-02-10 21:25:55 +01005333
Johannes Bergf9d15d12014-01-22 11:14:19 +02005334 if (rdev->scan_req || rdev->scan_msg) {
Johannes Bergf9f47522013-03-19 15:04:07 +01005335 err = -EBUSY;
5336 goto unlock;
5337 }
Johannes Berg2a519312009-02-10 21:25:55 +01005338
5339 if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
Johannes Berg83f5e2c2009-06-17 17:41:49 +02005340 n_channels = validate_scan_freqs(
5341 info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]);
Johannes Bergf9f47522013-03-19 15:04:07 +01005342 if (!n_channels) {
5343 err = -EINVAL;
5344 goto unlock;
5345 }
Johannes Berg2a519312009-02-10 21:25:55 +01005346 } else {
Ilan Peerbdfbec22014-01-09 11:37:23 +02005347 n_channels = ieee80211_get_num_supported_channels(wiphy);
Johannes Berg2a519312009-02-10 21:25:55 +01005348 }
5349
5350 if (info->attrs[NL80211_ATTR_SCAN_SSIDS])
5351 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp)
5352 n_ssids++;
5353
Johannes Bergf9f47522013-03-19 15:04:07 +01005354 if (n_ssids > wiphy->max_scan_ssids) {
5355 err = -EINVAL;
5356 goto unlock;
5357 }
Johannes Berg2a519312009-02-10 21:25:55 +01005358
Jouni Malinen70692ad2009-02-16 19:39:13 +02005359 if (info->attrs[NL80211_ATTR_IE])
5360 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
5361 else
5362 ie_len = 0;
5363
Johannes Bergf9f47522013-03-19 15:04:07 +01005364 if (ie_len > wiphy->max_scan_ie_len) {
5365 err = -EINVAL;
5366 goto unlock;
5367 }
Johannes Berg18a83652009-03-31 12:12:05 +02005368
Johannes Berg2a519312009-02-10 21:25:55 +01005369 request = kzalloc(sizeof(*request)
Luciano Coelhoa2cd43c2011-05-18 11:42:03 +03005370 + sizeof(*request->ssids) * n_ssids
5371 + sizeof(*request->channels) * n_channels
Jouni Malinen70692ad2009-02-16 19:39:13 +02005372 + ie_len, GFP_KERNEL);
Johannes Bergf9f47522013-03-19 15:04:07 +01005373 if (!request) {
5374 err = -ENOMEM;
5375 goto unlock;
5376 }
Johannes Berg2a519312009-02-10 21:25:55 +01005377
Johannes Berg2a519312009-02-10 21:25:55 +01005378 if (n_ssids)
Johannes Berg5ba63532009-08-07 17:54:07 +02005379 request->ssids = (void *)&request->channels[n_channels];
Johannes Berg2a519312009-02-10 21:25:55 +01005380 request->n_ssids = n_ssids;
Jouni Malinen70692ad2009-02-16 19:39:13 +02005381 if (ie_len) {
5382 if (request->ssids)
5383 request->ie = (void *)(request->ssids + n_ssids);
5384 else
5385 request->ie = (void *)(request->channels + n_channels);
5386 }
Johannes Berg2a519312009-02-10 21:25:55 +01005387
Johannes Berg584991d2009-11-02 13:32:03 +01005388 i = 0;
Johannes Berg2a519312009-02-10 21:25:55 +01005389 if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
5390 /* user specified, bail out if channel not found */
Johannes Berg2a519312009-02-10 21:25:55 +01005391 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_FREQUENCIES], tmp) {
Johannes Berg584991d2009-11-02 13:32:03 +01005392 struct ieee80211_channel *chan;
5393
5394 chan = ieee80211_get_channel(wiphy, nla_get_u32(attr));
5395
5396 if (!chan) {
Johannes Berg2a519312009-02-10 21:25:55 +01005397 err = -EINVAL;
5398 goto out_free;
5399 }
Johannes Berg584991d2009-11-02 13:32:03 +01005400
5401 /* ignore disabled channels */
5402 if (chan->flags & IEEE80211_CHAN_DISABLED)
5403 continue;
5404
5405 request->channels[i] = chan;
Johannes Berg2a519312009-02-10 21:25:55 +01005406 i++;
5407 }
5408 } else {
Johannes Berg34850ab2011-07-18 18:08:35 +02005409 enum ieee80211_band band;
5410
Johannes Berg2a519312009-02-10 21:25:55 +01005411 /* all channels */
Johannes Berg2a519312009-02-10 21:25:55 +01005412 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
5413 int j;
5414 if (!wiphy->bands[band])
5415 continue;
5416 for (j = 0; j < wiphy->bands[band]->n_channels; j++) {
Johannes Berg584991d2009-11-02 13:32:03 +01005417 struct ieee80211_channel *chan;
5418
5419 chan = &wiphy->bands[band]->channels[j];
5420
5421 if (chan->flags & IEEE80211_CHAN_DISABLED)
5422 continue;
5423
5424 request->channels[i] = chan;
Johannes Berg2a519312009-02-10 21:25:55 +01005425 i++;
5426 }
5427 }
5428 }
5429
Johannes Berg584991d2009-11-02 13:32:03 +01005430 if (!i) {
5431 err = -EINVAL;
5432 goto out_free;
5433 }
5434
5435 request->n_channels = i;
5436
Johannes Berg2a519312009-02-10 21:25:55 +01005437 i = 0;
5438 if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) {
5439 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) {
Luciano Coelho57a27e12011-06-07 20:42:26 +03005440 if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) {
Johannes Berg2a519312009-02-10 21:25:55 +01005441 err = -EINVAL;
5442 goto out_free;
5443 }
Luciano Coelho57a27e12011-06-07 20:42:26 +03005444 request->ssids[i].ssid_len = nla_len(attr);
Johannes Berg2a519312009-02-10 21:25:55 +01005445 memcpy(request->ssids[i].ssid, nla_data(attr), nla_len(attr));
Johannes Berg2a519312009-02-10 21:25:55 +01005446 i++;
5447 }
5448 }
5449
Jouni Malinen70692ad2009-02-16 19:39:13 +02005450 if (info->attrs[NL80211_ATTR_IE]) {
5451 request->ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Johannes Bergde95a542009-04-01 11:58:36 +02005452 memcpy((void *)request->ie,
5453 nla_data(info->attrs[NL80211_ATTR_IE]),
Jouni Malinen70692ad2009-02-16 19:39:13 +02005454 request->ie_len);
5455 }
5456
Johannes Berg34850ab2011-07-18 18:08:35 +02005457 for (i = 0; i < IEEE80211_NUM_BANDS; i++)
Johannes Berga401d2b2011-07-20 00:52:16 +02005458 if (wiphy->bands[i])
5459 request->rates[i] =
5460 (1 << wiphy->bands[i]->n_bitrates) - 1;
Johannes Berg34850ab2011-07-18 18:08:35 +02005461
5462 if (info->attrs[NL80211_ATTR_SCAN_SUPP_RATES]) {
5463 nla_for_each_nested(attr,
5464 info->attrs[NL80211_ATTR_SCAN_SUPP_RATES],
5465 tmp) {
5466 enum ieee80211_band band = nla_type(attr);
5467
Dan Carpenter84404622011-07-29 11:52:18 +03005468 if (band < 0 || band >= IEEE80211_NUM_BANDS) {
Johannes Berg34850ab2011-07-18 18:08:35 +02005469 err = -EINVAL;
5470 goto out_free;
5471 }
Felix Fietkau1b09cd82013-11-20 19:40:41 +01005472
5473 if (!wiphy->bands[band])
5474 continue;
5475
Johannes Berg34850ab2011-07-18 18:08:35 +02005476 err = ieee80211_get_ratemask(wiphy->bands[band],
5477 nla_data(attr),
5478 nla_len(attr),
5479 &request->rates[band]);
5480 if (err)
5481 goto out_free;
5482 }
5483 }
5484
Sam Leffler46856bb2012-10-11 21:03:32 -07005485 if (info->attrs[NL80211_ATTR_SCAN_FLAGS]) {
Sam Lefflered4737712012-10-11 21:03:31 -07005486 request->flags = nla_get_u32(
5487 info->attrs[NL80211_ATTR_SCAN_FLAGS]);
Johannes Berg00c3a6e2013-10-26 17:14:38 +02005488 if ((request->flags & NL80211_SCAN_FLAG_LOW_PRIORITY) &&
5489 !(wiphy->features & NL80211_FEATURE_LOW_PRIORITY_SCAN)) {
Sam Leffler46856bb2012-10-11 21:03:32 -07005490 err = -EOPNOTSUPP;
5491 goto out_free;
5492 }
5493 }
Sam Lefflered4737712012-10-11 21:03:31 -07005494
Rajkumar Manoharane9f935e2011-09-25 14:53:30 +05305495 request->no_cck =
5496 nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]);
5497
Johannes Bergfd014282012-06-18 19:17:03 +02005498 request->wdev = wdev;
Johannes Berg79c97e92009-07-07 03:56:12 +02005499 request->wiphy = &rdev->wiphy;
Sam Leffler15d60302012-10-11 21:03:34 -07005500 request->scan_start = jiffies;
Johannes Berg2a519312009-02-10 21:25:55 +01005501
Johannes Berg79c97e92009-07-07 03:56:12 +02005502 rdev->scan_req = request;
Hila Gonene35e4d22012-06-27 17:19:42 +03005503 err = rdev_scan(rdev, request);
Johannes Berg2a519312009-02-10 21:25:55 +01005504
Johannes Berg463d0182009-07-14 00:33:35 +02005505 if (!err) {
Johannes Bergfd014282012-06-18 19:17:03 +02005506 nl80211_send_scan_start(rdev, wdev);
5507 if (wdev->netdev)
5508 dev_hold(wdev->netdev);
Johannes Berg4c476992010-10-04 21:36:35 +02005509 } else {
Johannes Berg2a519312009-02-10 21:25:55 +01005510 out_free:
Johannes Berg79c97e92009-07-07 03:56:12 +02005511 rdev->scan_req = NULL;
Johannes Berg2a519312009-02-10 21:25:55 +01005512 kfree(request);
5513 }
Johannes Berg3b858752009-03-12 09:55:09 +01005514
Johannes Bergf9f47522013-03-19 15:04:07 +01005515 unlock:
Johannes Berg2a519312009-02-10 21:25:55 +01005516 return err;
5517}
5518
Luciano Coelho807f8a82011-05-11 17:09:35 +03005519static int nl80211_start_sched_scan(struct sk_buff *skb,
5520 struct genl_info *info)
5521{
5522 struct cfg80211_sched_scan_request *request;
5523 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5524 struct net_device *dev = info->user_ptr[1];
Luciano Coelho807f8a82011-05-11 17:09:35 +03005525 struct nlattr *attr;
5526 struct wiphy *wiphy;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005527 int err, tmp, n_ssids = 0, n_match_sets = 0, n_channels, i;
Luciano Coelhobbe6ad62011-05-11 17:09:37 +03005528 u32 interval;
Luciano Coelho807f8a82011-05-11 17:09:35 +03005529 enum ieee80211_band band;
5530 size_t ie_len;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005531 struct nlattr *tb[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1];
Johannes Bergea73cbc2014-01-24 10:53:53 +01005532 s32 default_match_rssi = NL80211_SCAN_RSSI_THOLD_OFF;
Luciano Coelho807f8a82011-05-11 17:09:35 +03005533
5534 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) ||
5535 !rdev->ops->sched_scan_start)
5536 return -EOPNOTSUPP;
5537
5538 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
5539 return -EINVAL;
5540
Luciano Coelhobbe6ad62011-05-11 17:09:37 +03005541 if (!info->attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL])
5542 return -EINVAL;
5543
5544 interval = nla_get_u32(info->attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]);
5545 if (interval == 0)
5546 return -EINVAL;
5547
Luciano Coelho807f8a82011-05-11 17:09:35 +03005548 wiphy = &rdev->wiphy;
5549
5550 if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
5551 n_channels = validate_scan_freqs(
5552 info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]);
5553 if (!n_channels)
5554 return -EINVAL;
5555 } else {
Ilan Peerbdfbec22014-01-09 11:37:23 +02005556 n_channels = ieee80211_get_num_supported_channels(wiphy);
Luciano Coelho807f8a82011-05-11 17:09:35 +03005557 }
5558
5559 if (info->attrs[NL80211_ATTR_SCAN_SSIDS])
5560 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS],
5561 tmp)
5562 n_ssids++;
5563
Luciano Coelho93b6aa62011-07-13 14:57:28 +03005564 if (n_ssids > wiphy->max_sched_scan_ssids)
Luciano Coelho807f8a82011-05-11 17:09:35 +03005565 return -EINVAL;
5566
Johannes Bergea73cbc2014-01-24 10:53:53 +01005567 /*
5568 * First, count the number of 'real' matchsets. Due to an issue with
5569 * the old implementation, matchsets containing only the RSSI attribute
5570 * (NL80211_SCHED_SCAN_MATCH_ATTR_RSSI) are considered as the 'default'
5571 * RSSI for all matchsets, rather than their own matchset for reporting
5572 * all APs with a strong RSSI. This is needed to be compatible with
5573 * older userspace that treated a matchset with only the RSSI as the
5574 * global RSSI for all other matchsets - if there are other matchsets.
5575 */
5576 if (info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) {
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005577 nla_for_each_nested(attr,
5578 info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH],
Johannes Bergea73cbc2014-01-24 10:53:53 +01005579 tmp) {
5580 struct nlattr *rssi;
5581
5582 err = nla_parse(tb, NL80211_SCHED_SCAN_MATCH_ATTR_MAX,
5583 nla_data(attr), nla_len(attr),
5584 nl80211_match_policy);
5585 if (err)
5586 return err;
5587 /* add other standalone attributes here */
5588 if (tb[NL80211_SCHED_SCAN_MATCH_ATTR_SSID]) {
5589 n_match_sets++;
5590 continue;
5591 }
5592 rssi = tb[NL80211_SCHED_SCAN_MATCH_ATTR_RSSI];
5593 if (rssi)
5594 default_match_rssi = nla_get_s32(rssi);
5595 }
5596 }
5597
5598 /* However, if there's no other matchset, add the RSSI one */
5599 if (!n_match_sets && default_match_rssi != NL80211_SCAN_RSSI_THOLD_OFF)
5600 n_match_sets = 1;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005601
5602 if (n_match_sets > wiphy->max_match_sets)
5603 return -EINVAL;
5604
Luciano Coelho807f8a82011-05-11 17:09:35 +03005605 if (info->attrs[NL80211_ATTR_IE])
5606 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
5607 else
5608 ie_len = 0;
5609
Luciano Coelho5a865ba2011-07-13 14:57:29 +03005610 if (ie_len > wiphy->max_sched_scan_ie_len)
Luciano Coelho807f8a82011-05-11 17:09:35 +03005611 return -EINVAL;
5612
Luciano Coelhoc10841c2011-06-30 08:32:41 +03005613 if (rdev->sched_scan_req) {
5614 err = -EINPROGRESS;
5615 goto out;
5616 }
5617
Luciano Coelho807f8a82011-05-11 17:09:35 +03005618 request = kzalloc(sizeof(*request)
Luciano Coelhoa2cd43c2011-05-18 11:42:03 +03005619 + sizeof(*request->ssids) * n_ssids
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005620 + sizeof(*request->match_sets) * n_match_sets
Luciano Coelhoa2cd43c2011-05-18 11:42:03 +03005621 + sizeof(*request->channels) * n_channels
Luciano Coelho807f8a82011-05-11 17:09:35 +03005622 + ie_len, GFP_KERNEL);
Luciano Coelhoc10841c2011-06-30 08:32:41 +03005623 if (!request) {
5624 err = -ENOMEM;
5625 goto out;
5626 }
Luciano Coelho807f8a82011-05-11 17:09:35 +03005627
5628 if (n_ssids)
5629 request->ssids = (void *)&request->channels[n_channels];
5630 request->n_ssids = n_ssids;
5631 if (ie_len) {
5632 if (request->ssids)
5633 request->ie = (void *)(request->ssids + n_ssids);
5634 else
5635 request->ie = (void *)(request->channels + n_channels);
5636 }
5637
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005638 if (n_match_sets) {
5639 if (request->ie)
5640 request->match_sets = (void *)(request->ie + ie_len);
5641 else if (request->ssids)
5642 request->match_sets =
5643 (void *)(request->ssids + n_ssids);
5644 else
5645 request->match_sets =
5646 (void *)(request->channels + n_channels);
5647 }
5648 request->n_match_sets = n_match_sets;
5649
Luciano Coelho807f8a82011-05-11 17:09:35 +03005650 i = 0;
5651 if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
5652 /* user specified, bail out if channel not found */
5653 nla_for_each_nested(attr,
5654 info->attrs[NL80211_ATTR_SCAN_FREQUENCIES],
5655 tmp) {
5656 struct ieee80211_channel *chan;
5657
5658 chan = ieee80211_get_channel(wiphy, nla_get_u32(attr));
5659
5660 if (!chan) {
5661 err = -EINVAL;
5662 goto out_free;
5663 }
5664
5665 /* ignore disabled channels */
5666 if (chan->flags & IEEE80211_CHAN_DISABLED)
5667 continue;
5668
5669 request->channels[i] = chan;
5670 i++;
5671 }
5672 } else {
5673 /* all channels */
5674 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
5675 int j;
5676 if (!wiphy->bands[band])
5677 continue;
5678 for (j = 0; j < wiphy->bands[band]->n_channels; j++) {
5679 struct ieee80211_channel *chan;
5680
5681 chan = &wiphy->bands[band]->channels[j];
5682
5683 if (chan->flags & IEEE80211_CHAN_DISABLED)
5684 continue;
5685
5686 request->channels[i] = chan;
5687 i++;
5688 }
5689 }
5690 }
5691
5692 if (!i) {
5693 err = -EINVAL;
5694 goto out_free;
5695 }
5696
5697 request->n_channels = i;
5698
5699 i = 0;
5700 if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) {
5701 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS],
5702 tmp) {
Luciano Coelho57a27e12011-06-07 20:42:26 +03005703 if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) {
Luciano Coelho807f8a82011-05-11 17:09:35 +03005704 err = -EINVAL;
5705 goto out_free;
5706 }
Luciano Coelho57a27e12011-06-07 20:42:26 +03005707 request->ssids[i].ssid_len = nla_len(attr);
Luciano Coelho807f8a82011-05-11 17:09:35 +03005708 memcpy(request->ssids[i].ssid, nla_data(attr),
5709 nla_len(attr));
Luciano Coelho807f8a82011-05-11 17:09:35 +03005710 i++;
5711 }
5712 }
5713
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005714 i = 0;
5715 if (info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) {
5716 nla_for_each_nested(attr,
5717 info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH],
5718 tmp) {
Thomas Pedersen88e920b2012-06-21 11:09:54 -07005719 struct nlattr *ssid, *rssi;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005720
Johannes Bergae811e22014-01-24 10:17:47 +01005721 err = nla_parse(tb, NL80211_SCHED_SCAN_MATCH_ATTR_MAX,
5722 nla_data(attr), nla_len(attr),
5723 nl80211_match_policy);
5724 if (err)
5725 goto out_free;
Johannes Berg4a4ab0d2012-06-13 11:17:11 +02005726 ssid = tb[NL80211_SCHED_SCAN_MATCH_ATTR_SSID];
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005727 if (ssid) {
Johannes Bergea73cbc2014-01-24 10:53:53 +01005728 if (WARN_ON(i >= n_match_sets)) {
5729 /* this indicates a programming error,
5730 * the loop above should have verified
5731 * things properly
5732 */
5733 err = -EINVAL;
5734 goto out_free;
5735 }
5736
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005737 if (nla_len(ssid) > IEEE80211_MAX_SSID_LEN) {
5738 err = -EINVAL;
5739 goto out_free;
5740 }
5741 memcpy(request->match_sets[i].ssid.ssid,
5742 nla_data(ssid), nla_len(ssid));
5743 request->match_sets[i].ssid.ssid_len =
5744 nla_len(ssid);
Johannes Bergea73cbc2014-01-24 10:53:53 +01005745 /* special attribute - old implemenation w/a */
5746 request->match_sets[i].rssi_thold =
5747 default_match_rssi;
5748 rssi = tb[NL80211_SCHED_SCAN_MATCH_ATTR_RSSI];
5749 if (rssi)
5750 request->match_sets[i].rssi_thold =
5751 nla_get_s32(rssi);
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005752 }
5753 i++;
5754 }
Johannes Bergea73cbc2014-01-24 10:53:53 +01005755
5756 /* there was no other matchset, so the RSSI one is alone */
5757 if (i == 0)
5758 request->match_sets[0].rssi_thold = default_match_rssi;
5759
5760 request->min_rssi_thold = INT_MAX;
5761 for (i = 0; i < n_match_sets; i++)
5762 request->min_rssi_thold =
5763 min(request->match_sets[i].rssi_thold,
5764 request->min_rssi_thold);
5765 } else {
5766 request->min_rssi_thold = NL80211_SCAN_RSSI_THOLD_OFF;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005767 }
5768
Johannes Berg9900e482014-02-04 21:01:25 +01005769 if (ie_len) {
5770 request->ie_len = ie_len;
Luciano Coelho807f8a82011-05-11 17:09:35 +03005771 memcpy((void *)request->ie,
5772 nla_data(info->attrs[NL80211_ATTR_IE]),
5773 request->ie_len);
5774 }
5775
Sam Leffler46856bb2012-10-11 21:03:32 -07005776 if (info->attrs[NL80211_ATTR_SCAN_FLAGS]) {
Sam Lefflered4737712012-10-11 21:03:31 -07005777 request->flags = nla_get_u32(
5778 info->attrs[NL80211_ATTR_SCAN_FLAGS]);
Johannes Berg00c3a6e2013-10-26 17:14:38 +02005779 if ((request->flags & NL80211_SCAN_FLAG_LOW_PRIORITY) &&
5780 !(wiphy->features & NL80211_FEATURE_LOW_PRIORITY_SCAN)) {
Sam Leffler46856bb2012-10-11 21:03:32 -07005781 err = -EOPNOTSUPP;
5782 goto out_free;
5783 }
5784 }
Sam Lefflered4737712012-10-11 21:03:31 -07005785
Luciano Coelho807f8a82011-05-11 17:09:35 +03005786 request->dev = dev;
5787 request->wiphy = &rdev->wiphy;
Luciano Coelhobbe6ad62011-05-11 17:09:37 +03005788 request->interval = interval;
Sam Leffler15d60302012-10-11 21:03:34 -07005789 request->scan_start = jiffies;
Luciano Coelho807f8a82011-05-11 17:09:35 +03005790
Hila Gonene35e4d22012-06-27 17:19:42 +03005791 err = rdev_sched_scan_start(rdev, dev, request);
Luciano Coelho807f8a82011-05-11 17:09:35 +03005792 if (!err) {
5793 rdev->sched_scan_req = request;
5794 nl80211_send_sched_scan(rdev, dev,
5795 NL80211_CMD_START_SCHED_SCAN);
5796 goto out;
5797 }
5798
5799out_free:
5800 kfree(request);
5801out:
5802 return err;
5803}
5804
5805static int nl80211_stop_sched_scan(struct sk_buff *skb,
5806 struct genl_info *info)
5807{
5808 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5809
5810 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) ||
5811 !rdev->ops->sched_scan_stop)
5812 return -EOPNOTSUPP;
5813
Johannes Berg5fe231e2013-05-08 21:45:15 +02005814 return __cfg80211_stop_sched_scan(rdev, false);
Luciano Coelho807f8a82011-05-11 17:09:35 +03005815}
5816
Simon Wunderlich04f39042013-02-08 18:16:19 +01005817static int nl80211_start_radar_detection(struct sk_buff *skb,
5818 struct genl_info *info)
5819{
5820 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5821 struct net_device *dev = info->user_ptr[1];
5822 struct wireless_dev *wdev = dev->ieee80211_ptr;
5823 struct cfg80211_chan_def chandef;
Luis R. Rodriguez55f74352013-11-25 20:56:10 +01005824 enum nl80211_dfs_regions dfs_region;
Janusz Dziedzic31559f32014-02-21 19:46:13 +01005825 unsigned int cac_time_ms;
Simon Wunderlich04f39042013-02-08 18:16:19 +01005826 int err;
5827
Luis R. Rodriguez55f74352013-11-25 20:56:10 +01005828 dfs_region = reg_get_dfs_region(wdev->wiphy);
5829 if (dfs_region == NL80211_DFS_UNSET)
5830 return -EINVAL;
5831
Simon Wunderlich04f39042013-02-08 18:16:19 +01005832 err = nl80211_parse_chandef(rdev, info, &chandef);
5833 if (err)
5834 return err;
5835
Simon Wunderlichff311bc2013-09-03 19:43:18 +02005836 if (netif_carrier_ok(dev))
5837 return -EBUSY;
5838
Simon Wunderlich04f39042013-02-08 18:16:19 +01005839 if (wdev->cac_started)
5840 return -EBUSY;
5841
Luciano Coelho2beb6dab2014-02-18 11:40:36 +02005842 err = cfg80211_chandef_dfs_required(wdev->wiphy, &chandef,
Luciano Coelho00ec75f2014-05-15 13:05:39 +03005843 wdev->iftype);
Simon Wunderlich04f39042013-02-08 18:16:19 +01005844 if (err < 0)
5845 return err;
5846
5847 if (err == 0)
5848 return -EINVAL;
5849
Janusz Dziedzicfe7c3a12013-11-05 14:48:48 +01005850 if (!cfg80211_chandef_dfs_usable(wdev->wiphy, &chandef))
Simon Wunderlich04f39042013-02-08 18:16:19 +01005851 return -EINVAL;
5852
5853 if (!rdev->ops->start_radar_detection)
5854 return -EOPNOTSUPP;
5855
Janusz Dziedzic31559f32014-02-21 19:46:13 +01005856 cac_time_ms = cfg80211_chandef_dfs_cac_time(&rdev->wiphy, &chandef);
5857 if (WARN_ON(!cac_time_ms))
5858 cac_time_ms = IEEE80211_DFS_MIN_CAC_TIME_MS;
5859
5860 err = rdev->ops->start_radar_detection(&rdev->wiphy, dev, &chandef,
5861 cac_time_ms);
Simon Wunderlich04f39042013-02-08 18:16:19 +01005862 if (!err) {
Michal Kazior9e0e2962014-01-29 14:22:27 +01005863 wdev->chandef = chandef;
Simon Wunderlich04f39042013-02-08 18:16:19 +01005864 wdev->cac_started = true;
5865 wdev->cac_start_time = jiffies;
Janusz Dziedzic31559f32014-02-21 19:46:13 +01005866 wdev->cac_time_ms = cac_time_ms;
Simon Wunderlich04f39042013-02-08 18:16:19 +01005867 }
Simon Wunderlich04f39042013-02-08 18:16:19 +01005868 return err;
5869}
5870
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02005871static int nl80211_channel_switch(struct sk_buff *skb, struct genl_info *info)
5872{
5873 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5874 struct net_device *dev = info->user_ptr[1];
5875 struct wireless_dev *wdev = dev->ieee80211_ptr;
5876 struct cfg80211_csa_settings params;
5877 /* csa_attrs is defined static to avoid waste of stack size - this
5878 * function is called under RTNL lock, so this should not be a problem.
5879 */
5880 static struct nlattr *csa_attrs[NL80211_ATTR_MAX+1];
5881 u8 radar_detect_width = 0;
5882 int err;
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02005883 bool need_new_beacon = false;
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03005884 int len, i;
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02005885
5886 if (!rdev->ops->channel_switch ||
5887 !(rdev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH))
5888 return -EOPNOTSUPP;
5889
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02005890 switch (dev->ieee80211_ptr->iftype) {
5891 case NL80211_IFTYPE_AP:
5892 case NL80211_IFTYPE_P2P_GO:
5893 need_new_beacon = true;
5894
5895 /* useless if AP is not running */
5896 if (!wdev->beacon_interval)
Johannes Berg1ff79df2014-01-22 10:05:27 +01005897 return -ENOTCONN;
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02005898 break;
5899 case NL80211_IFTYPE_ADHOC:
Johannes Berg1ff79df2014-01-22 10:05:27 +01005900 if (!wdev->ssid_len)
5901 return -ENOTCONN;
5902 break;
Chun-Yeow Yeohc6da6742013-10-14 19:08:28 -07005903 case NL80211_IFTYPE_MESH_POINT:
Johannes Berg1ff79df2014-01-22 10:05:27 +01005904 if (!wdev->mesh_id_len)
5905 return -ENOTCONN;
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02005906 break;
5907 default:
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02005908 return -EOPNOTSUPP;
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02005909 }
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02005910
5911 memset(&params, 0, sizeof(params));
5912
5913 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] ||
5914 !info->attrs[NL80211_ATTR_CH_SWITCH_COUNT])
5915 return -EINVAL;
5916
5917 /* only important for AP, IBSS and mesh create IEs internally */
Andrei Otcheretianskid0a361a2013-10-17 10:52:17 +02005918 if (need_new_beacon && !info->attrs[NL80211_ATTR_CSA_IES])
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02005919 return -EINVAL;
5920
5921 params.count = nla_get_u32(info->attrs[NL80211_ATTR_CH_SWITCH_COUNT]);
5922
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02005923 if (!need_new_beacon)
5924 goto skip_beacons;
5925
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02005926 err = nl80211_parse_beacon(info->attrs, &params.beacon_after);
5927 if (err)
5928 return err;
5929
5930 err = nla_parse_nested(csa_attrs, NL80211_ATTR_MAX,
5931 info->attrs[NL80211_ATTR_CSA_IES],
5932 nl80211_policy);
5933 if (err)
5934 return err;
5935
5936 err = nl80211_parse_beacon(csa_attrs, &params.beacon_csa);
5937 if (err)
5938 return err;
5939
5940 if (!csa_attrs[NL80211_ATTR_CSA_C_OFF_BEACON])
5941 return -EINVAL;
5942
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03005943 len = nla_len(csa_attrs[NL80211_ATTR_CSA_C_OFF_BEACON]);
5944 if (!len || (len % sizeof(u16)))
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02005945 return -EINVAL;
5946
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03005947 params.n_counter_offsets_beacon = len / sizeof(u16);
5948 if (rdev->wiphy.max_num_csa_counters &&
5949 (params.n_counter_offsets_beacon >
5950 rdev->wiphy.max_num_csa_counters))
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02005951 return -EINVAL;
5952
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03005953 params.counter_offsets_beacon =
5954 nla_data(csa_attrs[NL80211_ATTR_CSA_C_OFF_BEACON]);
5955
5956 /* sanity checks - counters should fit and be the same */
5957 for (i = 0; i < params.n_counter_offsets_beacon; i++) {
5958 u16 offset = params.counter_offsets_beacon[i];
5959
5960 if (offset >= params.beacon_csa.tail_len)
5961 return -EINVAL;
5962
5963 if (params.beacon_csa.tail[offset] != params.count)
5964 return -EINVAL;
5965 }
5966
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02005967 if (csa_attrs[NL80211_ATTR_CSA_C_OFF_PRESP]) {
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03005968 len = nla_len(csa_attrs[NL80211_ATTR_CSA_C_OFF_PRESP]);
5969 if (!len || (len % sizeof(u16)))
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02005970 return -EINVAL;
5971
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03005972 params.n_counter_offsets_presp = len / sizeof(u16);
5973 if (rdev->wiphy.max_num_csa_counters &&
5974 (params.n_counter_offsets_beacon >
5975 rdev->wiphy.max_num_csa_counters))
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02005976 return -EINVAL;
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03005977
5978 params.counter_offsets_presp =
5979 nla_data(csa_attrs[NL80211_ATTR_CSA_C_OFF_PRESP]);
5980
5981 /* sanity checks - counters should fit and be the same */
5982 for (i = 0; i < params.n_counter_offsets_presp; i++) {
5983 u16 offset = params.counter_offsets_presp[i];
5984
5985 if (offset >= params.beacon_csa.probe_resp_len)
5986 return -EINVAL;
5987
5988 if (params.beacon_csa.probe_resp[offset] !=
5989 params.count)
5990 return -EINVAL;
5991 }
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02005992 }
5993
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02005994skip_beacons:
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02005995 err = nl80211_parse_chandef(rdev, info, &params.chandef);
5996 if (err)
5997 return err;
5998
Ilan Peer174e0cd2014-02-23 09:13:01 +02005999 if (!cfg80211_reg_can_beacon(&rdev->wiphy, &params.chandef,
6000 wdev->iftype))
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006001 return -EINVAL;
6002
Luciano Coelho2beb6dab2014-02-18 11:40:36 +02006003 err = cfg80211_chandef_dfs_required(wdev->wiphy,
6004 &params.chandef,
6005 wdev->iftype);
6006 if (err < 0)
6007 return err;
6008
6009 if (err > 0) {
6010 radar_detect_width = BIT(params.chandef.width);
6011 params.radar_required = true;
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006012 }
6013
Luciano Coelho73de86a2014-02-13 11:31:59 +02006014 /* TODO: I left this here for now. With channel switch, the
6015 * verification is a bit more complicated, because we only do
6016 * it later when the channel switch really happens.
6017 */
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006018 err = cfg80211_can_use_iftype_chan(rdev, wdev, wdev->iftype,
6019 params.chandef.chan,
6020 CHAN_MODE_SHARED,
6021 radar_detect_width);
6022 if (err)
6023 return err;
6024
6025 if (info->attrs[NL80211_ATTR_CH_SWITCH_BLOCK_TX])
6026 params.block_tx = true;
6027
Simon Wunderlichc56589e2013-11-21 18:19:49 +01006028 wdev_lock(wdev);
6029 err = rdev_channel_switch(rdev, dev, &params);
6030 wdev_unlock(wdev);
6031
6032 return err;
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006033}
6034
Johannes Berg9720bb32011-06-21 09:45:33 +02006035static int nl80211_send_bss(struct sk_buff *msg, struct netlink_callback *cb,
6036 u32 seq, int flags,
Johannes Berg2a519312009-02-10 21:25:55 +01006037 struct cfg80211_registered_device *rdev,
Johannes Berg48ab9052009-07-10 18:42:31 +02006038 struct wireless_dev *wdev,
6039 struct cfg80211_internal_bss *intbss)
Johannes Berg2a519312009-02-10 21:25:55 +01006040{
Johannes Berg48ab9052009-07-10 18:42:31 +02006041 struct cfg80211_bss *res = &intbss->pub;
Johannes Berg9caf0362012-11-29 01:25:20 +01006042 const struct cfg80211_bss_ies *ies;
Johannes Berg2a519312009-02-10 21:25:55 +01006043 void *hdr;
6044 struct nlattr *bss;
Johannes Berg8cef2c92013-02-05 16:54:31 +01006045 bool tsf = false;
Johannes Berg48ab9052009-07-10 18:42:31 +02006046
6047 ASSERT_WDEV_LOCK(wdev);
Johannes Berg2a519312009-02-10 21:25:55 +01006048
Eric W. Biederman15e47302012-09-07 20:12:54 +00006049 hdr = nl80211hdr_put(msg, NETLINK_CB(cb->skb).portid, seq, flags,
Johannes Berg2a519312009-02-10 21:25:55 +01006050 NL80211_CMD_NEW_SCAN_RESULTS);
6051 if (!hdr)
6052 return -1;
6053
Johannes Berg9720bb32011-06-21 09:45:33 +02006054 genl_dump_check_consistent(cb, hdr, &nl80211_fam);
6055
Johannes Berg97990a02013-04-19 01:02:55 +02006056 if (nla_put_u32(msg, NL80211_ATTR_GENERATION, rdev->bss_generation))
6057 goto nla_put_failure;
6058 if (wdev->netdev &&
David S. Miller9360ffd2012-03-29 04:41:26 -04006059 nla_put_u32(msg, NL80211_ATTR_IFINDEX, wdev->netdev->ifindex))
6060 goto nla_put_failure;
Johannes Berg97990a02013-04-19 01:02:55 +02006061 if (nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)))
6062 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01006063
6064 bss = nla_nest_start(msg, NL80211_ATTR_BSS);
6065 if (!bss)
6066 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04006067 if ((!is_zero_ether_addr(res->bssid) &&
Johannes Berg9caf0362012-11-29 01:25:20 +01006068 nla_put(msg, NL80211_BSS_BSSID, ETH_ALEN, res->bssid)))
David S. Miller9360ffd2012-03-29 04:41:26 -04006069 goto nla_put_failure;
Johannes Berg9caf0362012-11-29 01:25:20 +01006070
6071 rcu_read_lock();
6072 ies = rcu_dereference(res->ies);
Johannes Berg8cef2c92013-02-05 16:54:31 +01006073 if (ies) {
6074 if (nla_put_u64(msg, NL80211_BSS_TSF, ies->tsf))
6075 goto fail_unlock_rcu;
6076 tsf = true;
6077 if (ies->len && nla_put(msg, NL80211_BSS_INFORMATION_ELEMENTS,
6078 ies->len, ies->data))
6079 goto fail_unlock_rcu;
Johannes Berg9caf0362012-11-29 01:25:20 +01006080 }
6081 ies = rcu_dereference(res->beacon_ies);
Johannes Berg8cef2c92013-02-05 16:54:31 +01006082 if (ies) {
6083 if (!tsf && nla_put_u64(msg, NL80211_BSS_TSF, ies->tsf))
6084 goto fail_unlock_rcu;
6085 if (ies->len && nla_put(msg, NL80211_BSS_BEACON_IES,
6086 ies->len, ies->data))
6087 goto fail_unlock_rcu;
Johannes Berg9caf0362012-11-29 01:25:20 +01006088 }
6089 rcu_read_unlock();
6090
David S. Miller9360ffd2012-03-29 04:41:26 -04006091 if (res->beacon_interval &&
6092 nla_put_u16(msg, NL80211_BSS_BEACON_INTERVAL, res->beacon_interval))
6093 goto nla_put_failure;
6094 if (nla_put_u16(msg, NL80211_BSS_CAPABILITY, res->capability) ||
6095 nla_put_u32(msg, NL80211_BSS_FREQUENCY, res->channel->center_freq) ||
Simon Wunderlichdcd6eac2013-07-08 16:55:49 +02006096 nla_put_u32(msg, NL80211_BSS_CHAN_WIDTH, res->scan_width) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04006097 nla_put_u32(msg, NL80211_BSS_SEEN_MS_AGO,
6098 jiffies_to_msecs(jiffies - intbss->ts)))
6099 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01006100
Johannes Berg77965c92009-02-18 18:45:06 +01006101 switch (rdev->wiphy.signal_type) {
Johannes Berg2a519312009-02-10 21:25:55 +01006102 case CFG80211_SIGNAL_TYPE_MBM:
David S. Miller9360ffd2012-03-29 04:41:26 -04006103 if (nla_put_u32(msg, NL80211_BSS_SIGNAL_MBM, res->signal))
6104 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01006105 break;
6106 case CFG80211_SIGNAL_TYPE_UNSPEC:
David S. Miller9360ffd2012-03-29 04:41:26 -04006107 if (nla_put_u8(msg, NL80211_BSS_SIGNAL_UNSPEC, res->signal))
6108 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01006109 break;
6110 default:
6111 break;
6112 }
6113
Johannes Berg48ab9052009-07-10 18:42:31 +02006114 switch (wdev->iftype) {
Johannes Berg074ac8d2010-09-16 14:58:22 +02006115 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Berg48ab9052009-07-10 18:42:31 +02006116 case NL80211_IFTYPE_STATION:
David S. Miller9360ffd2012-03-29 04:41:26 -04006117 if (intbss == wdev->current_bss &&
6118 nla_put_u32(msg, NL80211_BSS_STATUS,
6119 NL80211_BSS_STATUS_ASSOCIATED))
6120 goto nla_put_failure;
Johannes Berg48ab9052009-07-10 18:42:31 +02006121 break;
6122 case NL80211_IFTYPE_ADHOC:
David S. Miller9360ffd2012-03-29 04:41:26 -04006123 if (intbss == wdev->current_bss &&
6124 nla_put_u32(msg, NL80211_BSS_STATUS,
6125 NL80211_BSS_STATUS_IBSS_JOINED))
6126 goto nla_put_failure;
Johannes Berg48ab9052009-07-10 18:42:31 +02006127 break;
6128 default:
6129 break;
6130 }
6131
Johannes Berg2a519312009-02-10 21:25:55 +01006132 nla_nest_end(msg, bss);
6133
6134 return genlmsg_end(msg, hdr);
6135
Johannes Berg8cef2c92013-02-05 16:54:31 +01006136 fail_unlock_rcu:
6137 rcu_read_unlock();
Johannes Berg2a519312009-02-10 21:25:55 +01006138 nla_put_failure:
6139 genlmsg_cancel(msg, hdr);
6140 return -EMSGSIZE;
6141}
6142
Johannes Berg97990a02013-04-19 01:02:55 +02006143static int nl80211_dump_scan(struct sk_buff *skb, struct netlink_callback *cb)
Johannes Berg2a519312009-02-10 21:25:55 +01006144{
Johannes Berg48ab9052009-07-10 18:42:31 +02006145 struct cfg80211_registered_device *rdev;
Johannes Berg2a519312009-02-10 21:25:55 +01006146 struct cfg80211_internal_bss *scan;
Johannes Berg48ab9052009-07-10 18:42:31 +02006147 struct wireless_dev *wdev;
Johannes Berg97990a02013-04-19 01:02:55 +02006148 int start = cb->args[2], idx = 0;
Johannes Berg2a519312009-02-10 21:25:55 +01006149 int err;
6150
Johannes Berg97990a02013-04-19 01:02:55 +02006151 err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev);
Johannes Berg67748892010-10-04 21:14:06 +02006152 if (err)
6153 return err;
Johannes Berg2a519312009-02-10 21:25:55 +01006154
Johannes Berg48ab9052009-07-10 18:42:31 +02006155 wdev_lock(wdev);
6156 spin_lock_bh(&rdev->bss_lock);
6157 cfg80211_bss_expire(rdev);
6158
Johannes Berg9720bb32011-06-21 09:45:33 +02006159 cb->seq = rdev->bss_generation;
6160
Johannes Berg48ab9052009-07-10 18:42:31 +02006161 list_for_each_entry(scan, &rdev->bss_list, list) {
Johannes Berg2a519312009-02-10 21:25:55 +01006162 if (++idx <= start)
6163 continue;
Johannes Berg9720bb32011-06-21 09:45:33 +02006164 if (nl80211_send_bss(skb, cb,
Johannes Berg2a519312009-02-10 21:25:55 +01006165 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Johannes Berg48ab9052009-07-10 18:42:31 +02006166 rdev, wdev, scan) < 0) {
Johannes Berg2a519312009-02-10 21:25:55 +01006167 idx--;
Johannes Berg67748892010-10-04 21:14:06 +02006168 break;
Johannes Berg2a519312009-02-10 21:25:55 +01006169 }
6170 }
6171
Johannes Berg48ab9052009-07-10 18:42:31 +02006172 spin_unlock_bh(&rdev->bss_lock);
6173 wdev_unlock(wdev);
Johannes Berg2a519312009-02-10 21:25:55 +01006174
Johannes Berg97990a02013-04-19 01:02:55 +02006175 cb->args[2] = idx;
6176 nl80211_finish_wdev_dump(rdev);
Johannes Berg2a519312009-02-10 21:25:55 +01006177
Johannes Berg67748892010-10-04 21:14:06 +02006178 return skb->len;
Johannes Berg2a519312009-02-10 21:25:55 +01006179}
6180
Eric W. Biederman15e47302012-09-07 20:12:54 +00006181static int nl80211_send_survey(struct sk_buff *msg, u32 portid, u32 seq,
Holger Schurig61fa7132009-11-11 12:25:40 +01006182 int flags, struct net_device *dev,
6183 struct survey_info *survey)
6184{
6185 void *hdr;
6186 struct nlattr *infoattr;
6187
Eric W. Biederman15e47302012-09-07 20:12:54 +00006188 hdr = nl80211hdr_put(msg, portid, seq, flags,
Holger Schurig61fa7132009-11-11 12:25:40 +01006189 NL80211_CMD_NEW_SURVEY_RESULTS);
6190 if (!hdr)
6191 return -ENOMEM;
6192
David S. Miller9360ffd2012-03-29 04:41:26 -04006193 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex))
6194 goto nla_put_failure;
Holger Schurig61fa7132009-11-11 12:25:40 +01006195
6196 infoattr = nla_nest_start(msg, NL80211_ATTR_SURVEY_INFO);
6197 if (!infoattr)
6198 goto nla_put_failure;
6199
David S. Miller9360ffd2012-03-29 04:41:26 -04006200 if (nla_put_u32(msg, NL80211_SURVEY_INFO_FREQUENCY,
6201 survey->channel->center_freq))
6202 goto nla_put_failure;
6203
6204 if ((survey->filled & SURVEY_INFO_NOISE_DBM) &&
6205 nla_put_u8(msg, NL80211_SURVEY_INFO_NOISE, survey->noise))
6206 goto nla_put_failure;
6207 if ((survey->filled & SURVEY_INFO_IN_USE) &&
6208 nla_put_flag(msg, NL80211_SURVEY_INFO_IN_USE))
6209 goto nla_put_failure;
6210 if ((survey->filled & SURVEY_INFO_CHANNEL_TIME) &&
6211 nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME,
6212 survey->channel_time))
6213 goto nla_put_failure;
6214 if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_BUSY) &&
6215 nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_BUSY,
6216 survey->channel_time_busy))
6217 goto nla_put_failure;
6218 if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_EXT_BUSY) &&
6219 nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_EXT_BUSY,
6220 survey->channel_time_ext_busy))
6221 goto nla_put_failure;
6222 if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_RX) &&
6223 nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_RX,
6224 survey->channel_time_rx))
6225 goto nla_put_failure;
6226 if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_TX) &&
6227 nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_TX,
6228 survey->channel_time_tx))
6229 goto nla_put_failure;
Holger Schurig61fa7132009-11-11 12:25:40 +01006230
6231 nla_nest_end(msg, infoattr);
6232
6233 return genlmsg_end(msg, hdr);
6234
6235 nla_put_failure:
6236 genlmsg_cancel(msg, hdr);
6237 return -EMSGSIZE;
6238}
6239
6240static int nl80211_dump_survey(struct sk_buff *skb,
6241 struct netlink_callback *cb)
6242{
6243 struct survey_info survey;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08006244 struct cfg80211_registered_device *rdev;
Johannes Berg97990a02013-04-19 01:02:55 +02006245 struct wireless_dev *wdev;
6246 int survey_idx = cb->args[2];
Holger Schurig61fa7132009-11-11 12:25:40 +01006247 int res;
6248
Zhao, Gang1b8ec872014-04-21 12:53:02 +08006249 res = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev);
Johannes Berg67748892010-10-04 21:14:06 +02006250 if (res)
6251 return res;
Holger Schurig61fa7132009-11-11 12:25:40 +01006252
Johannes Berg97990a02013-04-19 01:02:55 +02006253 if (!wdev->netdev) {
6254 res = -EINVAL;
6255 goto out_err;
6256 }
6257
Zhao, Gang1b8ec872014-04-21 12:53:02 +08006258 if (!rdev->ops->dump_survey) {
Holger Schurig61fa7132009-11-11 12:25:40 +01006259 res = -EOPNOTSUPP;
6260 goto out_err;
6261 }
6262
6263 while (1) {
Luis R. Rodriguez180cdc72011-05-27 07:24:02 -07006264 struct ieee80211_channel *chan;
6265
Zhao, Gang1b8ec872014-04-21 12:53:02 +08006266 res = rdev_dump_survey(rdev, wdev->netdev, survey_idx, &survey);
Holger Schurig61fa7132009-11-11 12:25:40 +01006267 if (res == -ENOENT)
6268 break;
6269 if (res)
6270 goto out_err;
6271
Luis R. Rodriguez180cdc72011-05-27 07:24:02 -07006272 /* Survey without a channel doesn't make sense */
6273 if (!survey.channel) {
6274 res = -EINVAL;
6275 goto out;
6276 }
6277
Zhao, Gang1b8ec872014-04-21 12:53:02 +08006278 chan = ieee80211_get_channel(&rdev->wiphy,
Luis R. Rodriguez180cdc72011-05-27 07:24:02 -07006279 survey.channel->center_freq);
6280 if (!chan || chan->flags & IEEE80211_CHAN_DISABLED) {
6281 survey_idx++;
6282 continue;
6283 }
6284
Holger Schurig61fa7132009-11-11 12:25:40 +01006285 if (nl80211_send_survey(skb,
Eric W. Biederman15e47302012-09-07 20:12:54 +00006286 NETLINK_CB(cb->skb).portid,
Holger Schurig61fa7132009-11-11 12:25:40 +01006287 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Johannes Berg97990a02013-04-19 01:02:55 +02006288 wdev->netdev, &survey) < 0)
Holger Schurig61fa7132009-11-11 12:25:40 +01006289 goto out;
6290 survey_idx++;
6291 }
6292
6293 out:
Johannes Berg97990a02013-04-19 01:02:55 +02006294 cb->args[2] = survey_idx;
Holger Schurig61fa7132009-11-11 12:25:40 +01006295 res = skb->len;
6296 out_err:
Zhao, Gang1b8ec872014-04-21 12:53:02 +08006297 nl80211_finish_wdev_dump(rdev);
Holger Schurig61fa7132009-11-11 12:25:40 +01006298 return res;
6299}
6300
Samuel Ortizb23aa672009-07-01 21:26:54 +02006301static bool nl80211_valid_wpa_versions(u32 wpa_versions)
6302{
6303 return !(wpa_versions & ~(NL80211_WPA_VERSION_1 |
6304 NL80211_WPA_VERSION_2));
6305}
6306
Jouni Malinen636a5d32009-03-19 13:39:22 +02006307static int nl80211_authenticate(struct sk_buff *skb, struct genl_info *info)
6308{
Johannes Berg4c476992010-10-04 21:36:35 +02006309 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6310 struct net_device *dev = info->user_ptr[1];
Johannes Berg19957bb2009-07-02 17:20:43 +02006311 struct ieee80211_channel *chan;
Jouni Malinene39e5b52012-09-30 19:29:39 +03006312 const u8 *bssid, *ssid, *ie = NULL, *sae_data = NULL;
6313 int err, ssid_len, ie_len = 0, sae_data_len = 0;
Johannes Berg19957bb2009-07-02 17:20:43 +02006314 enum nl80211_auth_type auth_type;
Johannes Bergfffd0932009-07-08 14:22:54 +02006315 struct key_parse key;
Jouni Malinend5cdfac2010-04-04 09:37:19 +03006316 bool local_state_change;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006317
Johannes Bergf4a11bb2009-03-27 12:40:28 +01006318 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
6319 return -EINVAL;
6320
6321 if (!info->attrs[NL80211_ATTR_MAC])
6322 return -EINVAL;
6323
Jouni Malinen17780922009-03-27 20:52:47 +02006324 if (!info->attrs[NL80211_ATTR_AUTH_TYPE])
6325 return -EINVAL;
6326
Johannes Berg19957bb2009-07-02 17:20:43 +02006327 if (!info->attrs[NL80211_ATTR_SSID])
6328 return -EINVAL;
6329
6330 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ])
6331 return -EINVAL;
6332
Johannes Bergfffd0932009-07-08 14:22:54 +02006333 err = nl80211_parse_key(info, &key);
6334 if (err)
6335 return err;
6336
6337 if (key.idx >= 0) {
Johannes Berge31b8212010-10-05 19:39:30 +02006338 if (key.type != -1 && key.type != NL80211_KEYTYPE_GROUP)
6339 return -EINVAL;
Johannes Bergfffd0932009-07-08 14:22:54 +02006340 if (!key.p.key || !key.p.key_len)
6341 return -EINVAL;
6342 if ((key.p.cipher != WLAN_CIPHER_SUITE_WEP40 ||
6343 key.p.key_len != WLAN_KEY_LEN_WEP40) &&
6344 (key.p.cipher != WLAN_CIPHER_SUITE_WEP104 ||
6345 key.p.key_len != WLAN_KEY_LEN_WEP104))
6346 return -EINVAL;
6347 if (key.idx > 4)
6348 return -EINVAL;
6349 } else {
6350 key.p.key_len = 0;
6351 key.p.key = NULL;
6352 }
6353
Johannes Bergafea0b72010-08-10 09:46:42 +02006354 if (key.idx >= 0) {
6355 int i;
6356 bool ok = false;
6357 for (i = 0; i < rdev->wiphy.n_cipher_suites; i++) {
6358 if (key.p.cipher == rdev->wiphy.cipher_suites[i]) {
6359 ok = true;
6360 break;
6361 }
6362 }
Johannes Berg4c476992010-10-04 21:36:35 +02006363 if (!ok)
6364 return -EINVAL;
Johannes Bergafea0b72010-08-10 09:46:42 +02006365 }
6366
Johannes Berg4c476992010-10-04 21:36:35 +02006367 if (!rdev->ops->auth)
6368 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006369
Johannes Berg074ac8d2010-09-16 14:58:22 +02006370 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02006371 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
6372 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02006373
Johannes Berg19957bb2009-07-02 17:20:43 +02006374 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen664834d2014-01-15 00:01:44 +02006375 chan = nl80211_get_valid_chan(&rdev->wiphy,
6376 info->attrs[NL80211_ATTR_WIPHY_FREQ]);
6377 if (!chan)
Johannes Berg4c476992010-10-04 21:36:35 +02006378 return -EINVAL;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006379
Johannes Berg19957bb2009-07-02 17:20:43 +02006380 ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
6381 ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
6382
6383 if (info->attrs[NL80211_ATTR_IE]) {
6384 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
6385 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
6386 }
6387
6388 auth_type = nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]);
Jouni Malinene39e5b52012-09-30 19:29:39 +03006389 if (!nl80211_valid_auth_type(rdev, auth_type, NL80211_CMD_AUTHENTICATE))
Johannes Berg4c476992010-10-04 21:36:35 +02006390 return -EINVAL;
Johannes Berg19957bb2009-07-02 17:20:43 +02006391
Jouni Malinene39e5b52012-09-30 19:29:39 +03006392 if (auth_type == NL80211_AUTHTYPE_SAE &&
6393 !info->attrs[NL80211_ATTR_SAE_DATA])
6394 return -EINVAL;
6395
6396 if (info->attrs[NL80211_ATTR_SAE_DATA]) {
6397 if (auth_type != NL80211_AUTHTYPE_SAE)
6398 return -EINVAL;
6399 sae_data = nla_data(info->attrs[NL80211_ATTR_SAE_DATA]);
6400 sae_data_len = nla_len(info->attrs[NL80211_ATTR_SAE_DATA]);
6401 /* need to include at least Auth Transaction and Status Code */
6402 if (sae_data_len < 4)
6403 return -EINVAL;
6404 }
6405
Jouni Malinend5cdfac2010-04-04 09:37:19 +03006406 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE];
6407
Johannes Berg95de8172012-01-20 13:55:25 +01006408 /*
6409 * Since we no longer track auth state, ignore
6410 * requests to only change local state.
6411 */
6412 if (local_state_change)
6413 return 0;
6414
Johannes Berg91bf9b22013-05-15 17:44:01 +02006415 wdev_lock(dev->ieee80211_ptr);
6416 err = cfg80211_mlme_auth(rdev, dev, chan, auth_type, bssid,
6417 ssid, ssid_len, ie, ie_len,
6418 key.p.key, key.p.key_len, key.idx,
6419 sae_data, sae_data_len);
6420 wdev_unlock(dev->ieee80211_ptr);
6421 return err;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006422}
6423
Johannes Bergc0692b82010-08-27 14:26:53 +03006424static int nl80211_crypto_settings(struct cfg80211_registered_device *rdev,
6425 struct genl_info *info,
Johannes Berg3dc27d22009-07-02 21:36:37 +02006426 struct cfg80211_crypto_settings *settings,
6427 int cipher_limit)
Samuel Ortizb23aa672009-07-01 21:26:54 +02006428{
Johannes Bergc0b2bbd2009-07-25 16:54:36 +02006429 memset(settings, 0, sizeof(*settings));
6430
Samuel Ortizb23aa672009-07-01 21:26:54 +02006431 settings->control_port = info->attrs[NL80211_ATTR_CONTROL_PORT];
6432
Johannes Bergc0692b82010-08-27 14:26:53 +03006433 if (info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]) {
6434 u16 proto;
6435 proto = nla_get_u16(
6436 info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]);
6437 settings->control_port_ethertype = cpu_to_be16(proto);
6438 if (!(rdev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) &&
6439 proto != ETH_P_PAE)
6440 return -EINVAL;
6441 if (info->attrs[NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT])
6442 settings->control_port_no_encrypt = true;
6443 } else
6444 settings->control_port_ethertype = cpu_to_be16(ETH_P_PAE);
6445
Samuel Ortizb23aa672009-07-01 21:26:54 +02006446 if (info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]) {
6447 void *data;
6448 int len, i;
6449
6450 data = nla_data(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]);
6451 len = nla_len(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]);
6452 settings->n_ciphers_pairwise = len / sizeof(u32);
6453
6454 if (len % sizeof(u32))
6455 return -EINVAL;
6456
Johannes Berg3dc27d22009-07-02 21:36:37 +02006457 if (settings->n_ciphers_pairwise > cipher_limit)
Samuel Ortizb23aa672009-07-01 21:26:54 +02006458 return -EINVAL;
6459
6460 memcpy(settings->ciphers_pairwise, data, len);
6461
6462 for (i = 0; i < settings->n_ciphers_pairwise; i++)
Jouni Malinen38ba3c52011-09-21 18:14:56 +03006463 if (!cfg80211_supported_cipher_suite(
6464 &rdev->wiphy,
Samuel Ortizb23aa672009-07-01 21:26:54 +02006465 settings->ciphers_pairwise[i]))
6466 return -EINVAL;
6467 }
6468
6469 if (info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]) {
6470 settings->cipher_group =
6471 nla_get_u32(info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]);
Jouni Malinen38ba3c52011-09-21 18:14:56 +03006472 if (!cfg80211_supported_cipher_suite(&rdev->wiphy,
6473 settings->cipher_group))
Samuel Ortizb23aa672009-07-01 21:26:54 +02006474 return -EINVAL;
6475 }
6476
6477 if (info->attrs[NL80211_ATTR_WPA_VERSIONS]) {
6478 settings->wpa_versions =
6479 nla_get_u32(info->attrs[NL80211_ATTR_WPA_VERSIONS]);
6480 if (!nl80211_valid_wpa_versions(settings->wpa_versions))
6481 return -EINVAL;
6482 }
6483
6484 if (info->attrs[NL80211_ATTR_AKM_SUITES]) {
6485 void *data;
Jouni Malinen6d302402011-09-21 18:11:33 +03006486 int len;
Samuel Ortizb23aa672009-07-01 21:26:54 +02006487
6488 data = nla_data(info->attrs[NL80211_ATTR_AKM_SUITES]);
6489 len = nla_len(info->attrs[NL80211_ATTR_AKM_SUITES]);
6490 settings->n_akm_suites = len / sizeof(u32);
6491
6492 if (len % sizeof(u32))
6493 return -EINVAL;
6494
Jouni Malinen1b9ca022011-09-21 16:13:07 +03006495 if (settings->n_akm_suites > NL80211_MAX_NR_AKM_SUITES)
6496 return -EINVAL;
6497
Samuel Ortizb23aa672009-07-01 21:26:54 +02006498 memcpy(settings->akm_suites, data, len);
Samuel Ortizb23aa672009-07-01 21:26:54 +02006499 }
6500
6501 return 0;
6502}
6503
Jouni Malinen636a5d32009-03-19 13:39:22 +02006504static int nl80211_associate(struct sk_buff *skb, struct genl_info *info)
6505{
Johannes Berg4c476992010-10-04 21:36:35 +02006506 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6507 struct net_device *dev = info->user_ptr[1];
Johannes Bergf444de02010-05-05 15:25:02 +02006508 struct ieee80211_channel *chan;
Johannes Bergf62fab72013-02-21 20:09:09 +01006509 struct cfg80211_assoc_request req = {};
6510 const u8 *bssid, *ssid;
6511 int err, ssid_len = 0;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006512
Johannes Bergf4a11bb2009-03-27 12:40:28 +01006513 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
6514 return -EINVAL;
6515
6516 if (!info->attrs[NL80211_ATTR_MAC] ||
Johannes Berg19957bb2009-07-02 17:20:43 +02006517 !info->attrs[NL80211_ATTR_SSID] ||
6518 !info->attrs[NL80211_ATTR_WIPHY_FREQ])
Johannes Bergf4a11bb2009-03-27 12:40:28 +01006519 return -EINVAL;
6520
Johannes Berg4c476992010-10-04 21:36:35 +02006521 if (!rdev->ops->assoc)
6522 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006523
Johannes Berg074ac8d2010-09-16 14:58:22 +02006524 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02006525 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
6526 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02006527
Johannes Berg19957bb2009-07-02 17:20:43 +02006528 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02006529
Jouni Malinen664834d2014-01-15 00:01:44 +02006530 chan = nl80211_get_valid_chan(&rdev->wiphy,
6531 info->attrs[NL80211_ATTR_WIPHY_FREQ]);
6532 if (!chan)
Johannes Berg4c476992010-10-04 21:36:35 +02006533 return -EINVAL;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006534
Johannes Berg19957bb2009-07-02 17:20:43 +02006535 ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
6536 ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02006537
6538 if (info->attrs[NL80211_ATTR_IE]) {
Johannes Bergf62fab72013-02-21 20:09:09 +01006539 req.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
6540 req.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02006541 }
6542
Jouni Malinendc6382ce2009-05-06 22:09:37 +03006543 if (info->attrs[NL80211_ATTR_USE_MFP]) {
Johannes Berg4f5dadc2009-07-07 03:56:10 +02006544 enum nl80211_mfp mfp =
Jouni Malinendc6382ce2009-05-06 22:09:37 +03006545 nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]);
Johannes Berg4f5dadc2009-07-07 03:56:10 +02006546 if (mfp == NL80211_MFP_REQUIRED)
Johannes Bergf62fab72013-02-21 20:09:09 +01006547 req.use_mfp = true;
Johannes Berg4c476992010-10-04 21:36:35 +02006548 else if (mfp != NL80211_MFP_NO)
6549 return -EINVAL;
Jouni Malinendc6382ce2009-05-06 22:09:37 +03006550 }
6551
Johannes Berg3e5d7642009-07-07 14:37:26 +02006552 if (info->attrs[NL80211_ATTR_PREV_BSSID])
Johannes Bergf62fab72013-02-21 20:09:09 +01006553 req.prev_bssid = nla_data(info->attrs[NL80211_ATTR_PREV_BSSID]);
Johannes Berg3e5d7642009-07-07 14:37:26 +02006554
Ben Greear7e7c8922011-11-18 11:31:59 -08006555 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT]))
Johannes Bergf62fab72013-02-21 20:09:09 +01006556 req.flags |= ASSOC_REQ_DISABLE_HT;
Ben Greear7e7c8922011-11-18 11:31:59 -08006557
6558 if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
Johannes Bergf62fab72013-02-21 20:09:09 +01006559 memcpy(&req.ht_capa_mask,
6560 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]),
6561 sizeof(req.ht_capa_mask));
Ben Greear7e7c8922011-11-18 11:31:59 -08006562
6563 if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) {
Johannes Bergf62fab72013-02-21 20:09:09 +01006564 if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
Ben Greear7e7c8922011-11-18 11:31:59 -08006565 return -EINVAL;
Johannes Bergf62fab72013-02-21 20:09:09 +01006566 memcpy(&req.ht_capa,
6567 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]),
6568 sizeof(req.ht_capa));
Ben Greear7e7c8922011-11-18 11:31:59 -08006569 }
6570
Johannes Bergee2aca32013-02-21 17:36:01 +01006571 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_VHT]))
Johannes Bergf62fab72013-02-21 20:09:09 +01006572 req.flags |= ASSOC_REQ_DISABLE_VHT;
Johannes Bergee2aca32013-02-21 17:36:01 +01006573
6574 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK])
Johannes Bergf62fab72013-02-21 20:09:09 +01006575 memcpy(&req.vht_capa_mask,
6576 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]),
6577 sizeof(req.vht_capa_mask));
Johannes Bergee2aca32013-02-21 17:36:01 +01006578
6579 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) {
Johannes Bergf62fab72013-02-21 20:09:09 +01006580 if (!info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK])
Johannes Bergee2aca32013-02-21 17:36:01 +01006581 return -EINVAL;
Johannes Bergf62fab72013-02-21 20:09:09 +01006582 memcpy(&req.vht_capa,
6583 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]),
6584 sizeof(req.vht_capa));
Johannes Bergee2aca32013-02-21 17:36:01 +01006585 }
6586
Johannes Bergf62fab72013-02-21 20:09:09 +01006587 err = nl80211_crypto_settings(rdev, info, &req.crypto, 1);
Johannes Berg91bf9b22013-05-15 17:44:01 +02006588 if (!err) {
6589 wdev_lock(dev->ieee80211_ptr);
Johannes Bergf62fab72013-02-21 20:09:09 +01006590 err = cfg80211_mlme_assoc(rdev, dev, chan, bssid,
6591 ssid, ssid_len, &req);
Johannes Berg91bf9b22013-05-15 17:44:01 +02006592 wdev_unlock(dev->ieee80211_ptr);
6593 }
Jouni Malinen636a5d32009-03-19 13:39:22 +02006594
Jouni Malinen636a5d32009-03-19 13:39:22 +02006595 return err;
6596}
6597
6598static int nl80211_deauthenticate(struct sk_buff *skb, struct genl_info *info)
6599{
Johannes Berg4c476992010-10-04 21:36:35 +02006600 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6601 struct net_device *dev = info->user_ptr[1];
Johannes Berg19957bb2009-07-02 17:20:43 +02006602 const u8 *ie = NULL, *bssid;
Johannes Berg91bf9b22013-05-15 17:44:01 +02006603 int ie_len = 0, err;
Johannes Berg19957bb2009-07-02 17:20:43 +02006604 u16 reason_code;
Jouni Malinend5cdfac2010-04-04 09:37:19 +03006605 bool local_state_change;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006606
Johannes Bergf4a11bb2009-03-27 12:40:28 +01006607 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
6608 return -EINVAL;
6609
6610 if (!info->attrs[NL80211_ATTR_MAC])
6611 return -EINVAL;
6612
6613 if (!info->attrs[NL80211_ATTR_REASON_CODE])
6614 return -EINVAL;
6615
Johannes Berg4c476992010-10-04 21:36:35 +02006616 if (!rdev->ops->deauth)
6617 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006618
Johannes Berg074ac8d2010-09-16 14:58:22 +02006619 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02006620 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
6621 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02006622
Johannes Berg19957bb2009-07-02 17:20:43 +02006623 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02006624
Johannes Berg19957bb2009-07-02 17:20:43 +02006625 reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
6626 if (reason_code == 0) {
Johannes Bergf4a11bb2009-03-27 12:40:28 +01006627 /* Reason Code 0 is reserved */
Johannes Berg4c476992010-10-04 21:36:35 +02006628 return -EINVAL;
Jouni Malinen255e7372009-03-20 21:21:17 +02006629 }
Jouni Malinen636a5d32009-03-19 13:39:22 +02006630
6631 if (info->attrs[NL80211_ATTR_IE]) {
Johannes Berg19957bb2009-07-02 17:20:43 +02006632 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
6633 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02006634 }
6635
Jouni Malinend5cdfac2010-04-04 09:37:19 +03006636 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE];
6637
Johannes Berg91bf9b22013-05-15 17:44:01 +02006638 wdev_lock(dev->ieee80211_ptr);
6639 err = cfg80211_mlme_deauth(rdev, dev, bssid, ie, ie_len, reason_code,
6640 local_state_change);
6641 wdev_unlock(dev->ieee80211_ptr);
6642 return err;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006643}
6644
6645static int nl80211_disassociate(struct sk_buff *skb, struct genl_info *info)
6646{
Johannes Berg4c476992010-10-04 21:36:35 +02006647 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6648 struct net_device *dev = info->user_ptr[1];
Johannes Berg19957bb2009-07-02 17:20:43 +02006649 const u8 *ie = NULL, *bssid;
Johannes Berg91bf9b22013-05-15 17:44:01 +02006650 int ie_len = 0, err;
Johannes Berg19957bb2009-07-02 17:20:43 +02006651 u16 reason_code;
Jouni Malinend5cdfac2010-04-04 09:37:19 +03006652 bool local_state_change;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006653
Johannes Bergf4a11bb2009-03-27 12:40:28 +01006654 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
6655 return -EINVAL;
6656
6657 if (!info->attrs[NL80211_ATTR_MAC])
6658 return -EINVAL;
6659
6660 if (!info->attrs[NL80211_ATTR_REASON_CODE])
6661 return -EINVAL;
6662
Johannes Berg4c476992010-10-04 21:36:35 +02006663 if (!rdev->ops->disassoc)
6664 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006665
Johannes Berg074ac8d2010-09-16 14:58:22 +02006666 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02006667 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
6668 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02006669
Johannes Berg19957bb2009-07-02 17:20:43 +02006670 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02006671
Johannes Berg19957bb2009-07-02 17:20:43 +02006672 reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
6673 if (reason_code == 0) {
Johannes Bergf4a11bb2009-03-27 12:40:28 +01006674 /* Reason Code 0 is reserved */
Johannes Berg4c476992010-10-04 21:36:35 +02006675 return -EINVAL;
Jouni Malinen255e7372009-03-20 21:21:17 +02006676 }
Jouni Malinen636a5d32009-03-19 13:39:22 +02006677
6678 if (info->attrs[NL80211_ATTR_IE]) {
Johannes Berg19957bb2009-07-02 17:20:43 +02006679 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
6680 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02006681 }
6682
Jouni Malinend5cdfac2010-04-04 09:37:19 +03006683 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE];
6684
Johannes Berg91bf9b22013-05-15 17:44:01 +02006685 wdev_lock(dev->ieee80211_ptr);
6686 err = cfg80211_mlme_disassoc(rdev, dev, bssid, ie, ie_len, reason_code,
6687 local_state_change);
6688 wdev_unlock(dev->ieee80211_ptr);
6689 return err;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006690}
6691
Felix Fietkaudd5b4cc2010-11-22 20:58:24 +01006692static bool
6693nl80211_parse_mcast_rate(struct cfg80211_registered_device *rdev,
6694 int mcast_rate[IEEE80211_NUM_BANDS],
6695 int rateval)
6696{
6697 struct wiphy *wiphy = &rdev->wiphy;
6698 bool found = false;
6699 int band, i;
6700
6701 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
6702 struct ieee80211_supported_band *sband;
6703
6704 sband = wiphy->bands[band];
6705 if (!sband)
6706 continue;
6707
6708 for (i = 0; i < sband->n_bitrates; i++) {
6709 if (sband->bitrates[i].bitrate == rateval) {
6710 mcast_rate[band] = i + 1;
6711 found = true;
6712 break;
6713 }
6714 }
6715 }
6716
6717 return found;
6718}
6719
Johannes Berg04a773a2009-04-19 21:24:32 +02006720static int nl80211_join_ibss(struct sk_buff *skb, struct genl_info *info)
6721{
Johannes Berg4c476992010-10-04 21:36:35 +02006722 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6723 struct net_device *dev = info->user_ptr[1];
Johannes Berg04a773a2009-04-19 21:24:32 +02006724 struct cfg80211_ibss_params ibss;
6725 struct wiphy *wiphy;
Johannes Bergfffd0932009-07-08 14:22:54 +02006726 struct cfg80211_cached_keys *connkeys = NULL;
Johannes Berg04a773a2009-04-19 21:24:32 +02006727 int err;
6728
Johannes Berg8e30bc52009-04-22 17:45:38 +02006729 memset(&ibss, 0, sizeof(ibss));
6730
Johannes Berg04a773a2009-04-19 21:24:32 +02006731 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
6732 return -EINVAL;
6733
Johannes Berg683b6d32012-11-08 21:25:48 +01006734 if (!info->attrs[NL80211_ATTR_SSID] ||
Johannes Berg04a773a2009-04-19 21:24:32 +02006735 !nla_len(info->attrs[NL80211_ATTR_SSID]))
6736 return -EINVAL;
6737
Johannes Berg8e30bc52009-04-22 17:45:38 +02006738 ibss.beacon_interval = 100;
6739
6740 if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) {
6741 ibss.beacon_interval =
6742 nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]);
6743 if (ibss.beacon_interval < 1 || ibss.beacon_interval > 10000)
6744 return -EINVAL;
6745 }
6746
Johannes Berg4c476992010-10-04 21:36:35 +02006747 if (!rdev->ops->join_ibss)
6748 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02006749
Johannes Berg4c476992010-10-04 21:36:35 +02006750 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC)
6751 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02006752
Johannes Berg79c97e92009-07-07 03:56:12 +02006753 wiphy = &rdev->wiphy;
Johannes Berg04a773a2009-04-19 21:24:32 +02006754
Johannes Berg39193492011-09-16 13:45:25 +02006755 if (info->attrs[NL80211_ATTR_MAC]) {
Johannes Berg04a773a2009-04-19 21:24:32 +02006756 ibss.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Johannes Berg39193492011-09-16 13:45:25 +02006757
6758 if (!is_valid_ether_addr(ibss.bssid))
6759 return -EINVAL;
6760 }
Johannes Berg04a773a2009-04-19 21:24:32 +02006761 ibss.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
6762 ibss.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
6763
6764 if (info->attrs[NL80211_ATTR_IE]) {
6765 ibss.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
6766 ibss.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
6767 }
6768
Johannes Berg683b6d32012-11-08 21:25:48 +01006769 err = nl80211_parse_chandef(rdev, info, &ibss.chandef);
6770 if (err)
6771 return err;
Alexander Simon54858ee5b2011-11-30 16:56:32 +01006772
Ilan Peer174e0cd2014-02-23 09:13:01 +02006773 if (!cfg80211_reg_can_beacon(&rdev->wiphy, &ibss.chandef,
6774 NL80211_IFTYPE_ADHOC))
Alexander Simon54858ee5b2011-11-30 16:56:32 +01006775 return -EINVAL;
6776
Simon Wunderlich2f301ab2013-05-16 13:00:28 +02006777 switch (ibss.chandef.width) {
Simon Wunderlichbf372642013-07-08 16:55:58 +02006778 case NL80211_CHAN_WIDTH_5:
6779 case NL80211_CHAN_WIDTH_10:
Simon Wunderlich2f301ab2013-05-16 13:00:28 +02006780 case NL80211_CHAN_WIDTH_20_NOHT:
6781 break;
6782 case NL80211_CHAN_WIDTH_20:
6783 case NL80211_CHAN_WIDTH_40:
6784 if (rdev->wiphy.features & NL80211_FEATURE_HT_IBSS)
6785 break;
6786 default:
Johannes Bergdb9c64c2012-11-09 14:56:41 +01006787 return -EINVAL;
Simon Wunderlich2f301ab2013-05-16 13:00:28 +02006788 }
Johannes Bergdb9c64c2012-11-09 14:56:41 +01006789
Johannes Berg04a773a2009-04-19 21:24:32 +02006790 ibss.channel_fixed = !!info->attrs[NL80211_ATTR_FREQ_FIXED];
Johannes Bergfffd0932009-07-08 14:22:54 +02006791 ibss.privacy = !!info->attrs[NL80211_ATTR_PRIVACY];
Johannes Berg04a773a2009-04-19 21:24:32 +02006792
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03006793 if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) {
6794 u8 *rates =
6795 nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
6796 int n_rates =
6797 nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
6798 struct ieee80211_supported_band *sband =
Johannes Berg683b6d32012-11-08 21:25:48 +01006799 wiphy->bands[ibss.chandef.chan->band];
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03006800
Johannes Berg34850ab2011-07-18 18:08:35 +02006801 err = ieee80211_get_ratemask(sband, rates, n_rates,
6802 &ibss.basic_rates);
6803 if (err)
6804 return err;
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03006805 }
Felix Fietkaudd5b4cc2010-11-22 20:58:24 +01006806
Simon Wunderlich803768f2013-06-28 10:39:58 +02006807 if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
6808 memcpy(&ibss.ht_capa_mask,
6809 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]),
6810 sizeof(ibss.ht_capa_mask));
6811
6812 if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) {
6813 if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
6814 return -EINVAL;
6815 memcpy(&ibss.ht_capa,
6816 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]),
6817 sizeof(ibss.ht_capa));
6818 }
6819
Felix Fietkaudd5b4cc2010-11-22 20:58:24 +01006820 if (info->attrs[NL80211_ATTR_MCAST_RATE] &&
6821 !nl80211_parse_mcast_rate(rdev, ibss.mcast_rate,
6822 nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE])))
6823 return -EINVAL;
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03006824
Johannes Berg4c476992010-10-04 21:36:35 +02006825 if (ibss.privacy && info->attrs[NL80211_ATTR_KEYS]) {
Sujith Manoharande7044e2012-10-18 10:19:28 +05306826 bool no_ht = false;
6827
Johannes Berg4c476992010-10-04 21:36:35 +02006828 connkeys = nl80211_parse_connkeys(rdev,
Sujith Manoharande7044e2012-10-18 10:19:28 +05306829 info->attrs[NL80211_ATTR_KEYS],
6830 &no_ht);
Johannes Berg4c476992010-10-04 21:36:35 +02006831 if (IS_ERR(connkeys))
6832 return PTR_ERR(connkeys);
Sujith Manoharande7044e2012-10-18 10:19:28 +05306833
Johannes Berg3d9d1d62012-11-08 23:14:50 +01006834 if ((ibss.chandef.width != NL80211_CHAN_WIDTH_20_NOHT) &&
6835 no_ht) {
Sujith Manoharande7044e2012-10-18 10:19:28 +05306836 kfree(connkeys);
6837 return -EINVAL;
6838 }
Johannes Berg4c476992010-10-04 21:36:35 +02006839 }
Johannes Berg04a773a2009-04-19 21:24:32 +02006840
Antonio Quartulli267335d2012-01-31 20:25:47 +01006841 ibss.control_port =
6842 nla_get_flag(info->attrs[NL80211_ATTR_CONTROL_PORT]);
6843
Simon Wunderlich5336fa82013-10-07 18:41:05 +02006844 ibss.userspace_handles_dfs =
6845 nla_get_flag(info->attrs[NL80211_ATTR_HANDLE_DFS]);
6846
Johannes Berg4c476992010-10-04 21:36:35 +02006847 err = cfg80211_join_ibss(rdev, dev, &ibss, connkeys);
Johannes Bergfffd0932009-07-08 14:22:54 +02006848 if (err)
6849 kfree(connkeys);
Johannes Berg04a773a2009-04-19 21:24:32 +02006850 return err;
6851}
6852
6853static int nl80211_leave_ibss(struct sk_buff *skb, struct genl_info *info)
6854{
Johannes Berg4c476992010-10-04 21:36:35 +02006855 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6856 struct net_device *dev = info->user_ptr[1];
Johannes Berg04a773a2009-04-19 21:24:32 +02006857
Johannes Berg4c476992010-10-04 21:36:35 +02006858 if (!rdev->ops->leave_ibss)
6859 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02006860
Johannes Berg4c476992010-10-04 21:36:35 +02006861 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC)
6862 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02006863
Johannes Berg4c476992010-10-04 21:36:35 +02006864 return cfg80211_leave_ibss(rdev, dev, false);
Johannes Berg04a773a2009-04-19 21:24:32 +02006865}
6866
Antonio Quartullif4e583c2012-11-02 13:27:48 +01006867static int nl80211_set_mcast_rate(struct sk_buff *skb, struct genl_info *info)
6868{
6869 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6870 struct net_device *dev = info->user_ptr[1];
6871 int mcast_rate[IEEE80211_NUM_BANDS];
6872 u32 nla_rate;
6873 int err;
6874
6875 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC &&
6876 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
6877 return -EOPNOTSUPP;
6878
6879 if (!rdev->ops->set_mcast_rate)
6880 return -EOPNOTSUPP;
6881
6882 memset(mcast_rate, 0, sizeof(mcast_rate));
6883
6884 if (!info->attrs[NL80211_ATTR_MCAST_RATE])
6885 return -EINVAL;
6886
6887 nla_rate = nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]);
6888 if (!nl80211_parse_mcast_rate(rdev, mcast_rate, nla_rate))
6889 return -EINVAL;
6890
6891 err = rdev->ops->set_mcast_rate(&rdev->wiphy, dev, mcast_rate);
6892
6893 return err;
6894}
6895
Johannes Bergad7e7182013-11-13 13:37:47 +01006896static struct sk_buff *
6897__cfg80211_alloc_vendor_skb(struct cfg80211_registered_device *rdev,
6898 int approxlen, u32 portid, u32 seq,
6899 enum nl80211_commands cmd,
Johannes Berg567ffc32013-12-18 14:43:31 +01006900 enum nl80211_attrs attr,
6901 const struct nl80211_vendor_cmd_info *info,
6902 gfp_t gfp)
Johannes Bergad7e7182013-11-13 13:37:47 +01006903{
6904 struct sk_buff *skb;
6905 void *hdr;
6906 struct nlattr *data;
6907
6908 skb = nlmsg_new(approxlen + 100, gfp);
6909 if (!skb)
6910 return NULL;
6911
6912 hdr = nl80211hdr_put(skb, portid, seq, 0, cmd);
6913 if (!hdr) {
6914 kfree_skb(skb);
6915 return NULL;
6916 }
6917
6918 if (nla_put_u32(skb, NL80211_ATTR_WIPHY, rdev->wiphy_idx))
6919 goto nla_put_failure;
Johannes Berg567ffc32013-12-18 14:43:31 +01006920
6921 if (info) {
6922 if (nla_put_u32(skb, NL80211_ATTR_VENDOR_ID,
6923 info->vendor_id))
6924 goto nla_put_failure;
6925 if (nla_put_u32(skb, NL80211_ATTR_VENDOR_SUBCMD,
6926 info->subcmd))
6927 goto nla_put_failure;
6928 }
6929
Johannes Bergad7e7182013-11-13 13:37:47 +01006930 data = nla_nest_start(skb, attr);
6931
6932 ((void **)skb->cb)[0] = rdev;
6933 ((void **)skb->cb)[1] = hdr;
6934 ((void **)skb->cb)[2] = data;
6935
6936 return skb;
6937
6938 nla_put_failure:
6939 kfree_skb(skb);
6940 return NULL;
6941}
Antonio Quartullif4e583c2012-11-02 13:27:48 +01006942
Johannes Berge03ad6e2014-01-01 17:22:30 +01006943struct sk_buff *__cfg80211_alloc_event_skb(struct wiphy *wiphy,
6944 enum nl80211_commands cmd,
6945 enum nl80211_attrs attr,
6946 int vendor_event_idx,
6947 int approxlen, gfp_t gfp)
6948{
Zhao, Gangf26cbf42014-04-21 12:53:03 +08006949 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berge03ad6e2014-01-01 17:22:30 +01006950 const struct nl80211_vendor_cmd_info *info;
6951
6952 switch (cmd) {
6953 case NL80211_CMD_TESTMODE:
6954 if (WARN_ON(vendor_event_idx != -1))
6955 return NULL;
6956 info = NULL;
6957 break;
6958 case NL80211_CMD_VENDOR:
6959 if (WARN_ON(vendor_event_idx < 0 ||
6960 vendor_event_idx >= wiphy->n_vendor_events))
6961 return NULL;
6962 info = &wiphy->vendor_events[vendor_event_idx];
6963 break;
6964 default:
6965 WARN_ON(1);
6966 return NULL;
6967 }
6968
6969 return __cfg80211_alloc_vendor_skb(rdev, approxlen, 0, 0,
6970 cmd, attr, info, gfp);
6971}
6972EXPORT_SYMBOL(__cfg80211_alloc_event_skb);
6973
6974void __cfg80211_send_event_skb(struct sk_buff *skb, gfp_t gfp)
6975{
6976 struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0];
6977 void *hdr = ((void **)skb->cb)[1];
6978 struct nlattr *data = ((void **)skb->cb)[2];
6979 enum nl80211_multicast_groups mcgrp = NL80211_MCGRP_TESTMODE;
6980
6981 nla_nest_end(skb, data);
6982 genlmsg_end(skb, hdr);
6983
6984 if (data->nla_type == NL80211_ATTR_VENDOR_DATA)
6985 mcgrp = NL80211_MCGRP_VENDOR;
6986
6987 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), skb, 0,
6988 mcgrp, gfp);
6989}
6990EXPORT_SYMBOL(__cfg80211_send_event_skb);
6991
Johannes Bergaff89a92009-07-01 21:26:51 +02006992#ifdef CONFIG_NL80211_TESTMODE
Johannes Bergaff89a92009-07-01 21:26:51 +02006993static int nl80211_testmode_do(struct sk_buff *skb, struct genl_info *info)
6994{
Johannes Berg4c476992010-10-04 21:36:35 +02006995 struct cfg80211_registered_device *rdev = info->user_ptr[0];
David Spinadelfc73f112013-07-31 18:04:15 +03006996 struct wireless_dev *wdev =
6997 __cfg80211_wdev_from_attrs(genl_info_net(info), info->attrs);
Johannes Bergaff89a92009-07-01 21:26:51 +02006998 int err;
6999
David Spinadelfc73f112013-07-31 18:04:15 +03007000 if (!rdev->ops->testmode_cmd)
7001 return -EOPNOTSUPP;
7002
7003 if (IS_ERR(wdev)) {
7004 err = PTR_ERR(wdev);
7005 if (err != -EINVAL)
7006 return err;
7007 wdev = NULL;
7008 } else if (wdev->wiphy != &rdev->wiphy) {
7009 return -EINVAL;
7010 }
7011
Johannes Bergaff89a92009-07-01 21:26:51 +02007012 if (!info->attrs[NL80211_ATTR_TESTDATA])
7013 return -EINVAL;
7014
Johannes Bergad7e7182013-11-13 13:37:47 +01007015 rdev->cur_cmd_info = info;
David Spinadelfc73f112013-07-31 18:04:15 +03007016 err = rdev_testmode_cmd(rdev, wdev,
Johannes Bergaff89a92009-07-01 21:26:51 +02007017 nla_data(info->attrs[NL80211_ATTR_TESTDATA]),
7018 nla_len(info->attrs[NL80211_ATTR_TESTDATA]));
Johannes Bergad7e7182013-11-13 13:37:47 +01007019 rdev->cur_cmd_info = NULL;
Johannes Bergaff89a92009-07-01 21:26:51 +02007020
Johannes Bergaff89a92009-07-01 21:26:51 +02007021 return err;
7022}
7023
Wey-Yi Guy71063f02011-05-20 09:05:54 -07007024static int nl80211_testmode_dump(struct sk_buff *skb,
7025 struct netlink_callback *cb)
7026{
Johannes Berg00918d32011-12-13 17:22:05 +01007027 struct cfg80211_registered_device *rdev;
Wey-Yi Guy71063f02011-05-20 09:05:54 -07007028 int err;
7029 long phy_idx;
7030 void *data = NULL;
7031 int data_len = 0;
7032
Johannes Berg5fe231e2013-05-08 21:45:15 +02007033 rtnl_lock();
7034
Wey-Yi Guy71063f02011-05-20 09:05:54 -07007035 if (cb->args[0]) {
7036 /*
7037 * 0 is a valid index, but not valid for args[0],
7038 * so we need to offset by 1.
7039 */
7040 phy_idx = cb->args[0] - 1;
7041 } else {
7042 err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize,
7043 nl80211_fam.attrbuf, nl80211_fam.maxattr,
7044 nl80211_policy);
7045 if (err)
Johannes Berg5fe231e2013-05-08 21:45:15 +02007046 goto out_err;
Johannes Berg00918d32011-12-13 17:22:05 +01007047
Johannes Berg2bd7e352012-06-15 14:23:16 +02007048 rdev = __cfg80211_rdev_from_attrs(sock_net(skb->sk),
7049 nl80211_fam.attrbuf);
7050 if (IS_ERR(rdev)) {
Johannes Berg5fe231e2013-05-08 21:45:15 +02007051 err = PTR_ERR(rdev);
7052 goto out_err;
Johannes Berg00918d32011-12-13 17:22:05 +01007053 }
Johannes Berg2bd7e352012-06-15 14:23:16 +02007054 phy_idx = rdev->wiphy_idx;
7055 rdev = NULL;
Johannes Berg2bd7e352012-06-15 14:23:16 +02007056
Wey-Yi Guy71063f02011-05-20 09:05:54 -07007057 if (nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA])
7058 cb->args[1] =
7059 (long)nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA];
7060 }
7061
7062 if (cb->args[1]) {
7063 data = nla_data((void *)cb->args[1]);
7064 data_len = nla_len((void *)cb->args[1]);
7065 }
7066
Johannes Berg00918d32011-12-13 17:22:05 +01007067 rdev = cfg80211_rdev_by_wiphy_idx(phy_idx);
7068 if (!rdev) {
Johannes Berg5fe231e2013-05-08 21:45:15 +02007069 err = -ENOENT;
7070 goto out_err;
Wey-Yi Guy71063f02011-05-20 09:05:54 -07007071 }
Wey-Yi Guy71063f02011-05-20 09:05:54 -07007072
Johannes Berg00918d32011-12-13 17:22:05 +01007073 if (!rdev->ops->testmode_dump) {
Wey-Yi Guy71063f02011-05-20 09:05:54 -07007074 err = -EOPNOTSUPP;
7075 goto out_err;
7076 }
7077
7078 while (1) {
Eric W. Biederman15e47302012-09-07 20:12:54 +00007079 void *hdr = nl80211hdr_put(skb, NETLINK_CB(cb->skb).portid,
Wey-Yi Guy71063f02011-05-20 09:05:54 -07007080 cb->nlh->nlmsg_seq, NLM_F_MULTI,
7081 NL80211_CMD_TESTMODE);
7082 struct nlattr *tmdata;
7083
Dan Carpentercb35fba2013-08-14 14:50:01 +03007084 if (!hdr)
7085 break;
7086
David S. Miller9360ffd2012-03-29 04:41:26 -04007087 if (nla_put_u32(skb, NL80211_ATTR_WIPHY, phy_idx)) {
Wey-Yi Guy71063f02011-05-20 09:05:54 -07007088 genlmsg_cancel(skb, hdr);
7089 break;
7090 }
7091
7092 tmdata = nla_nest_start(skb, NL80211_ATTR_TESTDATA);
7093 if (!tmdata) {
7094 genlmsg_cancel(skb, hdr);
7095 break;
7096 }
Hila Gonene35e4d22012-06-27 17:19:42 +03007097 err = rdev_testmode_dump(rdev, skb, cb, data, data_len);
Wey-Yi Guy71063f02011-05-20 09:05:54 -07007098 nla_nest_end(skb, tmdata);
7099
7100 if (err == -ENOBUFS || err == -ENOENT) {
7101 genlmsg_cancel(skb, hdr);
7102 break;
7103 } else if (err) {
7104 genlmsg_cancel(skb, hdr);
7105 goto out_err;
7106 }
7107
7108 genlmsg_end(skb, hdr);
7109 }
7110
7111 err = skb->len;
7112 /* see above */
7113 cb->args[0] = phy_idx + 1;
7114 out_err:
Johannes Berg5fe231e2013-05-08 21:45:15 +02007115 rtnl_unlock();
Wey-Yi Guy71063f02011-05-20 09:05:54 -07007116 return err;
7117}
Johannes Bergaff89a92009-07-01 21:26:51 +02007118#endif
7119
Samuel Ortizb23aa672009-07-01 21:26:54 +02007120static int nl80211_connect(struct sk_buff *skb, struct genl_info *info)
7121{
Johannes Berg4c476992010-10-04 21:36:35 +02007122 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7123 struct net_device *dev = info->user_ptr[1];
Samuel Ortizb23aa672009-07-01 21:26:54 +02007124 struct cfg80211_connect_params connect;
7125 struct wiphy *wiphy;
Johannes Bergfffd0932009-07-08 14:22:54 +02007126 struct cfg80211_cached_keys *connkeys = NULL;
Samuel Ortizb23aa672009-07-01 21:26:54 +02007127 int err;
7128
7129 memset(&connect, 0, sizeof(connect));
7130
7131 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
7132 return -EINVAL;
7133
7134 if (!info->attrs[NL80211_ATTR_SSID] ||
7135 !nla_len(info->attrs[NL80211_ATTR_SSID]))
7136 return -EINVAL;
7137
7138 if (info->attrs[NL80211_ATTR_AUTH_TYPE]) {
7139 connect.auth_type =
7140 nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]);
Jouni Malinene39e5b52012-09-30 19:29:39 +03007141 if (!nl80211_valid_auth_type(rdev, connect.auth_type,
7142 NL80211_CMD_CONNECT))
Samuel Ortizb23aa672009-07-01 21:26:54 +02007143 return -EINVAL;
7144 } else
7145 connect.auth_type = NL80211_AUTHTYPE_AUTOMATIC;
7146
7147 connect.privacy = info->attrs[NL80211_ATTR_PRIVACY];
7148
Johannes Bergc0692b82010-08-27 14:26:53 +03007149 err = nl80211_crypto_settings(rdev, info, &connect.crypto,
Johannes Berg3dc27d22009-07-02 21:36:37 +02007150 NL80211_MAX_NR_CIPHER_SUITES);
Samuel Ortizb23aa672009-07-01 21:26:54 +02007151 if (err)
7152 return err;
Samuel Ortizb23aa672009-07-01 21:26:54 +02007153
Johannes Berg074ac8d2010-09-16 14:58:22 +02007154 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02007155 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
7156 return -EOPNOTSUPP;
Samuel Ortizb23aa672009-07-01 21:26:54 +02007157
Johannes Berg79c97e92009-07-07 03:56:12 +02007158 wiphy = &rdev->wiphy;
Samuel Ortizb23aa672009-07-01 21:26:54 +02007159
Bala Shanmugam4486ea92012-03-07 17:27:12 +05307160 connect.bg_scan_period = -1;
7161 if (info->attrs[NL80211_ATTR_BG_SCAN_PERIOD] &&
7162 (wiphy->flags & WIPHY_FLAG_SUPPORTS_FW_ROAM)) {
7163 connect.bg_scan_period =
7164 nla_get_u16(info->attrs[NL80211_ATTR_BG_SCAN_PERIOD]);
7165 }
7166
Samuel Ortizb23aa672009-07-01 21:26:54 +02007167 if (info->attrs[NL80211_ATTR_MAC])
7168 connect.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen1df4a512014-01-15 00:00:47 +02007169 else if (info->attrs[NL80211_ATTR_MAC_HINT])
7170 connect.bssid_hint =
7171 nla_data(info->attrs[NL80211_ATTR_MAC_HINT]);
Samuel Ortizb23aa672009-07-01 21:26:54 +02007172 connect.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
7173 connect.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
7174
7175 if (info->attrs[NL80211_ATTR_IE]) {
7176 connect.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
7177 connect.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
7178 }
7179
Jouni Malinencee00a92013-01-15 17:15:57 +02007180 if (info->attrs[NL80211_ATTR_USE_MFP]) {
7181 connect.mfp = nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]);
7182 if (connect.mfp != NL80211_MFP_REQUIRED &&
7183 connect.mfp != NL80211_MFP_NO)
7184 return -EINVAL;
7185 } else {
7186 connect.mfp = NL80211_MFP_NO;
7187 }
7188
Samuel Ortizb23aa672009-07-01 21:26:54 +02007189 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
Jouni Malinen664834d2014-01-15 00:01:44 +02007190 connect.channel = nl80211_get_valid_chan(
7191 wiphy, info->attrs[NL80211_ATTR_WIPHY_FREQ]);
7192 if (!connect.channel)
Johannes Berg4c476992010-10-04 21:36:35 +02007193 return -EINVAL;
Jouni Malinen1df4a512014-01-15 00:00:47 +02007194 } else if (info->attrs[NL80211_ATTR_WIPHY_FREQ_HINT]) {
Jouni Malinen664834d2014-01-15 00:01:44 +02007195 connect.channel_hint = nl80211_get_valid_chan(
7196 wiphy, info->attrs[NL80211_ATTR_WIPHY_FREQ_HINT]);
7197 if (!connect.channel_hint)
Jouni Malinen1df4a512014-01-15 00:00:47 +02007198 return -EINVAL;
Samuel Ortizb23aa672009-07-01 21:26:54 +02007199 }
7200
Johannes Bergfffd0932009-07-08 14:22:54 +02007201 if (connect.privacy && info->attrs[NL80211_ATTR_KEYS]) {
7202 connkeys = nl80211_parse_connkeys(rdev,
Sujith Manoharande7044e2012-10-18 10:19:28 +05307203 info->attrs[NL80211_ATTR_KEYS], NULL);
Johannes Berg4c476992010-10-04 21:36:35 +02007204 if (IS_ERR(connkeys))
7205 return PTR_ERR(connkeys);
Johannes Bergfffd0932009-07-08 14:22:54 +02007206 }
7207
Ben Greear7e7c8922011-11-18 11:31:59 -08007208 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT]))
7209 connect.flags |= ASSOC_REQ_DISABLE_HT;
7210
7211 if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
7212 memcpy(&connect.ht_capa_mask,
7213 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]),
7214 sizeof(connect.ht_capa_mask));
7215
7216 if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) {
Wei Yongjunb4e4f472012-09-02 21:41:04 +08007217 if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) {
7218 kfree(connkeys);
Ben Greear7e7c8922011-11-18 11:31:59 -08007219 return -EINVAL;
Wei Yongjunb4e4f472012-09-02 21:41:04 +08007220 }
Ben Greear7e7c8922011-11-18 11:31:59 -08007221 memcpy(&connect.ht_capa,
7222 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]),
7223 sizeof(connect.ht_capa));
7224 }
7225
Johannes Bergee2aca32013-02-21 17:36:01 +01007226 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_VHT]))
7227 connect.flags |= ASSOC_REQ_DISABLE_VHT;
7228
7229 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK])
7230 memcpy(&connect.vht_capa_mask,
7231 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]),
7232 sizeof(connect.vht_capa_mask));
7233
7234 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) {
7235 if (!info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) {
7236 kfree(connkeys);
7237 return -EINVAL;
7238 }
7239 memcpy(&connect.vht_capa,
7240 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]),
7241 sizeof(connect.vht_capa));
7242 }
7243
Johannes Berg83739b02013-05-15 17:44:01 +02007244 wdev_lock(dev->ieee80211_ptr);
7245 err = cfg80211_connect(rdev, dev, &connect, connkeys, NULL);
7246 wdev_unlock(dev->ieee80211_ptr);
Johannes Bergfffd0932009-07-08 14:22:54 +02007247 if (err)
7248 kfree(connkeys);
Samuel Ortizb23aa672009-07-01 21:26:54 +02007249 return err;
7250}
7251
7252static int nl80211_disconnect(struct sk_buff *skb, struct genl_info *info)
7253{
Johannes Berg4c476992010-10-04 21:36:35 +02007254 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7255 struct net_device *dev = info->user_ptr[1];
Samuel Ortizb23aa672009-07-01 21:26:54 +02007256 u16 reason;
Johannes Berg83739b02013-05-15 17:44:01 +02007257 int ret;
Samuel Ortizb23aa672009-07-01 21:26:54 +02007258
7259 if (!info->attrs[NL80211_ATTR_REASON_CODE])
7260 reason = WLAN_REASON_DEAUTH_LEAVING;
7261 else
7262 reason = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
7263
7264 if (reason == 0)
7265 return -EINVAL;
7266
Johannes Berg074ac8d2010-09-16 14:58:22 +02007267 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02007268 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
7269 return -EOPNOTSUPP;
Samuel Ortizb23aa672009-07-01 21:26:54 +02007270
Johannes Berg83739b02013-05-15 17:44:01 +02007271 wdev_lock(dev->ieee80211_ptr);
7272 ret = cfg80211_disconnect(rdev, dev, reason, true);
7273 wdev_unlock(dev->ieee80211_ptr);
7274 return ret;
Samuel Ortizb23aa672009-07-01 21:26:54 +02007275}
7276
Johannes Berg463d0182009-07-14 00:33:35 +02007277static int nl80211_wiphy_netns(struct sk_buff *skb, struct genl_info *info)
7278{
Johannes Berg4c476992010-10-04 21:36:35 +02007279 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg463d0182009-07-14 00:33:35 +02007280 struct net *net;
7281 int err;
7282 u32 pid;
7283
7284 if (!info->attrs[NL80211_ATTR_PID])
7285 return -EINVAL;
7286
7287 pid = nla_get_u32(info->attrs[NL80211_ATTR_PID]);
7288
Johannes Berg463d0182009-07-14 00:33:35 +02007289 net = get_net_ns_by_pid(pid);
Johannes Berg4c476992010-10-04 21:36:35 +02007290 if (IS_ERR(net))
7291 return PTR_ERR(net);
Johannes Berg463d0182009-07-14 00:33:35 +02007292
7293 err = 0;
7294
7295 /* check if anything to do */
Johannes Berg4c476992010-10-04 21:36:35 +02007296 if (!net_eq(wiphy_net(&rdev->wiphy), net))
7297 err = cfg80211_switch_netns(rdev, net);
Johannes Berg463d0182009-07-14 00:33:35 +02007298
Johannes Berg463d0182009-07-14 00:33:35 +02007299 put_net(net);
Johannes Berg463d0182009-07-14 00:33:35 +02007300 return err;
7301}
7302
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007303static int nl80211_setdel_pmksa(struct sk_buff *skb, struct genl_info *info)
7304{
Johannes Berg4c476992010-10-04 21:36:35 +02007305 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007306 int (*rdev_ops)(struct wiphy *wiphy, struct net_device *dev,
7307 struct cfg80211_pmksa *pmksa) = NULL;
Johannes Berg4c476992010-10-04 21:36:35 +02007308 struct net_device *dev = info->user_ptr[1];
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007309 struct cfg80211_pmksa pmksa;
7310
7311 memset(&pmksa, 0, sizeof(struct cfg80211_pmksa));
7312
7313 if (!info->attrs[NL80211_ATTR_MAC])
7314 return -EINVAL;
7315
7316 if (!info->attrs[NL80211_ATTR_PMKID])
7317 return -EINVAL;
7318
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007319 pmksa.pmkid = nla_data(info->attrs[NL80211_ATTR_PMKID]);
7320 pmksa.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
7321
Johannes Berg074ac8d2010-09-16 14:58:22 +02007322 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02007323 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
7324 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007325
7326 switch (info->genlhdr->cmd) {
7327 case NL80211_CMD_SET_PMKSA:
7328 rdev_ops = rdev->ops->set_pmksa;
7329 break;
7330 case NL80211_CMD_DEL_PMKSA:
7331 rdev_ops = rdev->ops->del_pmksa;
7332 break;
7333 default:
7334 WARN_ON(1);
7335 break;
7336 }
7337
Johannes Berg4c476992010-10-04 21:36:35 +02007338 if (!rdev_ops)
7339 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007340
Johannes Berg4c476992010-10-04 21:36:35 +02007341 return rdev_ops(&rdev->wiphy, dev, &pmksa);
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007342}
7343
7344static int nl80211_flush_pmksa(struct sk_buff *skb, struct genl_info *info)
7345{
Johannes Berg4c476992010-10-04 21:36:35 +02007346 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7347 struct net_device *dev = info->user_ptr[1];
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007348
Johannes Berg074ac8d2010-09-16 14:58:22 +02007349 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02007350 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
7351 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007352
Johannes Berg4c476992010-10-04 21:36:35 +02007353 if (!rdev->ops->flush_pmksa)
7354 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007355
Hila Gonene35e4d22012-06-27 17:19:42 +03007356 return rdev_flush_pmksa(rdev, dev);
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007357}
7358
Arik Nemtsov109086c2011-09-28 14:12:50 +03007359static int nl80211_tdls_mgmt(struct sk_buff *skb, struct genl_info *info)
7360{
7361 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7362 struct net_device *dev = info->user_ptr[1];
7363 u8 action_code, dialog_token;
Sunil Dutt Undekaridf942e72014-02-20 16:22:09 +05307364 u32 peer_capability = 0;
Arik Nemtsov109086c2011-09-28 14:12:50 +03007365 u16 status_code;
7366 u8 *peer;
7367
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]);
Sunil Dutt Undekaridf942e72014-02-20 16:22:09 +05307383 if (info->attrs[NL80211_ATTR_TDLS_PEER_CAPABILITY])
7384 peer_capability =
7385 nla_get_u32(info->attrs[NL80211_ATTR_TDLS_PEER_CAPABILITY]);
Arik Nemtsov109086c2011-09-28 14:12:50 +03007386
Hila Gonene35e4d22012-06-27 17:19:42 +03007387 return rdev_tdls_mgmt(rdev, dev, peer, action_code,
Sunil Dutt Undekaridf942e72014-02-20 16:22:09 +05307388 dialog_token, status_code, peer_capability,
Hila Gonene35e4d22012-06-27 17:19:42 +03007389 nla_data(info->attrs[NL80211_ATTR_IE]),
7390 nla_len(info->attrs[NL80211_ATTR_IE]));
Arik Nemtsov109086c2011-09-28 14:12:50 +03007391}
7392
7393static int nl80211_tdls_oper(struct sk_buff *skb, struct genl_info *info)
7394{
7395 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7396 struct net_device *dev = info->user_ptr[1];
7397 enum nl80211_tdls_operation operation;
7398 u8 *peer;
7399
7400 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) ||
7401 !rdev->ops->tdls_oper)
7402 return -EOPNOTSUPP;
7403
7404 if (!info->attrs[NL80211_ATTR_TDLS_OPERATION] ||
7405 !info->attrs[NL80211_ATTR_MAC])
7406 return -EINVAL;
7407
7408 operation = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_OPERATION]);
7409 peer = nla_data(info->attrs[NL80211_ATTR_MAC]);
7410
Hila Gonene35e4d22012-06-27 17:19:42 +03007411 return rdev_tdls_oper(rdev, dev, peer, operation);
Arik Nemtsov109086c2011-09-28 14:12:50 +03007412}
7413
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007414static int nl80211_remain_on_channel(struct sk_buff *skb,
7415 struct genl_info *info)
7416{
Johannes Berg4c476992010-10-04 21:36:35 +02007417 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02007418 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg683b6d32012-11-08 21:25:48 +01007419 struct cfg80211_chan_def chandef;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007420 struct sk_buff *msg;
7421 void *hdr;
7422 u64 cookie;
Johannes Berg683b6d32012-11-08 21:25:48 +01007423 u32 duration;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007424 int err;
7425
7426 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] ||
7427 !info->attrs[NL80211_ATTR_DURATION])
7428 return -EINVAL;
7429
7430 duration = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]);
7431
Johannes Berg7c4ef712011-11-18 15:33:48 +01007432 if (!rdev->ops->remain_on_channel ||
7433 !(rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL))
Johannes Berg4c476992010-10-04 21:36:35 +02007434 return -EOPNOTSUPP;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007435
Johannes Bergebf348f2012-06-01 12:50:54 +02007436 /*
7437 * We should be on that channel for at least a minimum amount of
7438 * time (10ms) but no longer than the driver supports.
7439 */
7440 if (duration < NL80211_MIN_REMAIN_ON_CHANNEL_TIME ||
7441 duration > rdev->wiphy.max_remain_on_channel_duration)
7442 return -EINVAL;
7443
Johannes Berg683b6d32012-11-08 21:25:48 +01007444 err = nl80211_parse_chandef(rdev, info, &chandef);
7445 if (err)
7446 return err;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007447
7448 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02007449 if (!msg)
7450 return -ENOMEM;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007451
Eric W. Biederman15e47302012-09-07 20:12:54 +00007452 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007453 NL80211_CMD_REMAIN_ON_CHANNEL);
Dan Carpentercb35fba2013-08-14 14:50:01 +03007454 if (!hdr) {
7455 err = -ENOBUFS;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007456 goto free_msg;
7457 }
7458
Johannes Berg683b6d32012-11-08 21:25:48 +01007459 err = rdev_remain_on_channel(rdev, wdev, chandef.chan,
7460 duration, &cookie);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007461
7462 if (err)
7463 goto free_msg;
7464
David S. Miller9360ffd2012-03-29 04:41:26 -04007465 if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie))
7466 goto nla_put_failure;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007467
7468 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02007469
7470 return genlmsg_reply(msg, info);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007471
7472 nla_put_failure:
7473 err = -ENOBUFS;
7474 free_msg:
7475 nlmsg_free(msg);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007476 return err;
7477}
7478
7479static int nl80211_cancel_remain_on_channel(struct sk_buff *skb,
7480 struct genl_info *info)
7481{
Johannes Berg4c476992010-10-04 21:36:35 +02007482 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02007483 struct wireless_dev *wdev = info->user_ptr[1];
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007484 u64 cookie;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007485
7486 if (!info->attrs[NL80211_ATTR_COOKIE])
7487 return -EINVAL;
7488
Johannes Berg4c476992010-10-04 21:36:35 +02007489 if (!rdev->ops->cancel_remain_on_channel)
7490 return -EOPNOTSUPP;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007491
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007492 cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]);
7493
Hila Gonene35e4d22012-06-27 17:19:42 +03007494 return rdev_cancel_remain_on_channel(rdev, wdev, cookie);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007495}
7496
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007497static u32 rateset_to_mask(struct ieee80211_supported_band *sband,
7498 u8 *rates, u8 rates_len)
7499{
7500 u8 i;
7501 u32 mask = 0;
7502
7503 for (i = 0; i < rates_len; i++) {
7504 int rate = (rates[i] & 0x7f) * 5;
7505 int ridx;
7506 for (ridx = 0; ridx < sband->n_bitrates; ridx++) {
7507 struct ieee80211_rate *srate =
7508 &sband->bitrates[ridx];
7509 if (rate == srate->bitrate) {
7510 mask |= 1 << ridx;
7511 break;
7512 }
7513 }
7514 if (ridx == sband->n_bitrates)
7515 return 0; /* rate not found */
7516 }
7517
7518 return mask;
7519}
7520
Simon Wunderlich24db78c2012-01-28 17:25:32 +01007521static bool ht_rateset_to_mask(struct ieee80211_supported_band *sband,
7522 u8 *rates, u8 rates_len,
7523 u8 mcs[IEEE80211_HT_MCS_MASK_LEN])
7524{
7525 u8 i;
7526
7527 memset(mcs, 0, IEEE80211_HT_MCS_MASK_LEN);
7528
7529 for (i = 0; i < rates_len; i++) {
7530 int ridx, rbit;
7531
7532 ridx = rates[i] / 8;
7533 rbit = BIT(rates[i] % 8);
7534
7535 /* check validity */
Dan Carpenter910570b52012-02-01 10:42:11 +03007536 if ((ridx < 0) || (ridx >= IEEE80211_HT_MCS_MASK_LEN))
Simon Wunderlich24db78c2012-01-28 17:25:32 +01007537 return false;
7538
7539 /* check availability */
7540 if (sband->ht_cap.mcs.rx_mask[ridx] & rbit)
7541 mcs[ridx] |= rbit;
7542 else
7543 return false;
7544 }
7545
7546 return true;
7547}
7548
Janusz Dziedzic204e35a2013-12-05 20:42:58 +01007549static u16 vht_mcs_map_to_mcs_mask(u8 vht_mcs_map)
7550{
7551 u16 mcs_mask = 0;
7552
7553 switch (vht_mcs_map) {
7554 case IEEE80211_VHT_MCS_NOT_SUPPORTED:
7555 break;
7556 case IEEE80211_VHT_MCS_SUPPORT_0_7:
7557 mcs_mask = 0x00FF;
7558 break;
7559 case IEEE80211_VHT_MCS_SUPPORT_0_8:
7560 mcs_mask = 0x01FF;
7561 break;
7562 case IEEE80211_VHT_MCS_SUPPORT_0_9:
7563 mcs_mask = 0x03FF;
7564 break;
7565 default:
7566 break;
7567 }
7568
7569 return mcs_mask;
7570}
7571
7572static void vht_build_mcs_mask(u16 vht_mcs_map,
7573 u16 vht_mcs_mask[NL80211_VHT_NSS_MAX])
7574{
7575 u8 nss;
7576
7577 for (nss = 0; nss < NL80211_VHT_NSS_MAX; nss++) {
7578 vht_mcs_mask[nss] = vht_mcs_map_to_mcs_mask(vht_mcs_map & 0x03);
7579 vht_mcs_map >>= 2;
7580 }
7581}
7582
7583static bool vht_set_mcs_mask(struct ieee80211_supported_band *sband,
7584 struct nl80211_txrate_vht *txrate,
7585 u16 mcs[NL80211_VHT_NSS_MAX])
7586{
7587 u16 tx_mcs_map = le16_to_cpu(sband->vht_cap.vht_mcs.tx_mcs_map);
7588 u16 tx_mcs_mask[NL80211_VHT_NSS_MAX] = {};
7589 u8 i;
7590
7591 if (!sband->vht_cap.vht_supported)
7592 return false;
7593
7594 memset(mcs, 0, sizeof(u16) * NL80211_VHT_NSS_MAX);
7595
7596 /* Build vht_mcs_mask from VHT capabilities */
7597 vht_build_mcs_mask(tx_mcs_map, tx_mcs_mask);
7598
7599 for (i = 0; i < NL80211_VHT_NSS_MAX; i++) {
7600 if ((tx_mcs_mask[i] & txrate->mcs[i]) == txrate->mcs[i])
7601 mcs[i] = txrate->mcs[i];
7602 else
7603 return false;
7604 }
7605
7606 return true;
7607}
7608
Alexey Dobriyanb54452b2010-02-18 08:14:31 +00007609static const struct nla_policy nl80211_txattr_policy[NL80211_TXRATE_MAX + 1] = {
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007610 [NL80211_TXRATE_LEGACY] = { .type = NLA_BINARY,
7611 .len = NL80211_MAX_SUPP_RATES },
Janusz Dziedzicd1e33e62013-12-05 10:02:15 +01007612 [NL80211_TXRATE_HT] = { .type = NLA_BINARY,
7613 .len = NL80211_MAX_SUPP_HT_RATES },
Janusz Dziedzic204e35a2013-12-05 20:42:58 +01007614 [NL80211_TXRATE_VHT] = { .len = sizeof(struct nl80211_txrate_vht)},
Janusz Dziedzic0b9323f2014-01-08 08:46:02 +01007615 [NL80211_TXRATE_GI] = { .type = NLA_U8 },
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007616};
7617
7618static int nl80211_set_tx_bitrate_mask(struct sk_buff *skb,
7619 struct genl_info *info)
7620{
7621 struct nlattr *tb[NL80211_TXRATE_MAX + 1];
Johannes Berg4c476992010-10-04 21:36:35 +02007622 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007623 struct cfg80211_bitrate_mask mask;
Johannes Berg4c476992010-10-04 21:36:35 +02007624 int rem, i;
7625 struct net_device *dev = info->user_ptr[1];
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007626 struct nlattr *tx_rates;
7627 struct ieee80211_supported_band *sband;
Janusz Dziedzic204e35a2013-12-05 20:42:58 +01007628 u16 vht_tx_mcs_map;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007629
Johannes Berg4c476992010-10-04 21:36:35 +02007630 if (!rdev->ops->set_bitrate_mask)
7631 return -EOPNOTSUPP;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007632
7633 memset(&mask, 0, sizeof(mask));
7634 /* Default to all rates enabled */
7635 for (i = 0; i < IEEE80211_NUM_BANDS; i++) {
7636 sband = rdev->wiphy.bands[i];
Janusz Dziedzic78693032013-12-03 09:50:44 +01007637
7638 if (!sband)
7639 continue;
7640
7641 mask.control[i].legacy = (1 << sband->n_bitrates) - 1;
Janusz Dziedzicd1e33e62013-12-05 10:02:15 +01007642 memcpy(mask.control[i].ht_mcs,
Janusz Dziedzic78693032013-12-03 09:50:44 +01007643 sband->ht_cap.mcs.rx_mask,
Janusz Dziedzicd1e33e62013-12-05 10:02:15 +01007644 sizeof(mask.control[i].ht_mcs));
Janusz Dziedzic204e35a2013-12-05 20:42:58 +01007645
7646 if (!sband->vht_cap.vht_supported)
7647 continue;
7648
7649 vht_tx_mcs_map = le16_to_cpu(sband->vht_cap.vht_mcs.tx_mcs_map);
7650 vht_build_mcs_mask(vht_tx_mcs_map, mask.control[i].vht_mcs);
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007651 }
7652
Janusz Dziedzicb9243ab2013-12-05 10:02:14 +01007653 /* if no rates are given set it back to the defaults */
7654 if (!info->attrs[NL80211_ATTR_TX_RATES])
7655 goto out;
7656
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007657 /*
7658 * The nested attribute uses enum nl80211_band as the index. This maps
7659 * directly to the enum ieee80211_band values used in cfg80211.
7660 */
Simon Wunderlich24db78c2012-01-28 17:25:32 +01007661 BUILD_BUG_ON(NL80211_MAX_SUPP_HT_RATES > IEEE80211_HT_MCS_MASK_LEN * 8);
Johannes Bergae811e22014-01-24 10:17:47 +01007662 nla_for_each_nested(tx_rates, info->attrs[NL80211_ATTR_TX_RATES], rem) {
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007663 enum ieee80211_band band = nla_type(tx_rates);
Johannes Bergae811e22014-01-24 10:17:47 +01007664 int err;
7665
Johannes Berg4c476992010-10-04 21:36:35 +02007666 if (band < 0 || band >= IEEE80211_NUM_BANDS)
7667 return -EINVAL;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007668 sband = rdev->wiphy.bands[band];
Johannes Berg4c476992010-10-04 21:36:35 +02007669 if (sband == NULL)
7670 return -EINVAL;
Johannes Bergae811e22014-01-24 10:17:47 +01007671 err = nla_parse(tb, NL80211_TXRATE_MAX, nla_data(tx_rates),
7672 nla_len(tx_rates), nl80211_txattr_policy);
7673 if (err)
7674 return err;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007675 if (tb[NL80211_TXRATE_LEGACY]) {
7676 mask.control[band].legacy = rateset_to_mask(
7677 sband,
7678 nla_data(tb[NL80211_TXRATE_LEGACY]),
7679 nla_len(tb[NL80211_TXRATE_LEGACY]));
Bala Shanmugam218d2e22012-04-20 19:12:58 +05307680 if ((mask.control[band].legacy == 0) &&
7681 nla_len(tb[NL80211_TXRATE_LEGACY]))
7682 return -EINVAL;
Simon Wunderlich24db78c2012-01-28 17:25:32 +01007683 }
Janusz Dziedzicd1e33e62013-12-05 10:02:15 +01007684 if (tb[NL80211_TXRATE_HT]) {
Simon Wunderlich24db78c2012-01-28 17:25:32 +01007685 if (!ht_rateset_to_mask(
7686 sband,
Janusz Dziedzicd1e33e62013-12-05 10:02:15 +01007687 nla_data(tb[NL80211_TXRATE_HT]),
7688 nla_len(tb[NL80211_TXRATE_HT]),
7689 mask.control[band].ht_mcs))
Simon Wunderlich24db78c2012-01-28 17:25:32 +01007690 return -EINVAL;
7691 }
Janusz Dziedzic204e35a2013-12-05 20:42:58 +01007692 if (tb[NL80211_TXRATE_VHT]) {
7693 if (!vht_set_mcs_mask(
7694 sband,
7695 nla_data(tb[NL80211_TXRATE_VHT]),
7696 mask.control[band].vht_mcs))
7697 return -EINVAL;
7698 }
Janusz Dziedzic0b9323f2014-01-08 08:46:02 +01007699 if (tb[NL80211_TXRATE_GI]) {
7700 mask.control[band].gi =
7701 nla_get_u8(tb[NL80211_TXRATE_GI]);
7702 if (mask.control[band].gi > NL80211_TXRATE_FORCE_LGI)
7703 return -EINVAL;
7704 }
Simon Wunderlich24db78c2012-01-28 17:25:32 +01007705
7706 if (mask.control[band].legacy == 0) {
Janusz Dziedzic204e35a2013-12-05 20:42:58 +01007707 /* don't allow empty legacy rates if HT or VHT
7708 * are not even supported.
7709 */
7710 if (!(rdev->wiphy.bands[band]->ht_cap.ht_supported ||
7711 rdev->wiphy.bands[band]->vht_cap.vht_supported))
Simon Wunderlich24db78c2012-01-28 17:25:32 +01007712 return -EINVAL;
7713
7714 for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++)
Janusz Dziedzicd1e33e62013-12-05 10:02:15 +01007715 if (mask.control[band].ht_mcs[i])
Janusz Dziedzic204e35a2013-12-05 20:42:58 +01007716 goto out;
7717
7718 for (i = 0; i < NL80211_VHT_NSS_MAX; i++)
7719 if (mask.control[band].vht_mcs[i])
7720 goto out;
Simon Wunderlich24db78c2012-01-28 17:25:32 +01007721
7722 /* legacy and mcs rates may not be both empty */
Janusz Dziedzic204e35a2013-12-05 20:42:58 +01007723 return -EINVAL;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007724 }
7725 }
7726
Janusz Dziedzicb9243ab2013-12-05 10:02:14 +01007727out:
Hila Gonene35e4d22012-06-27 17:19:42 +03007728 return rdev_set_bitrate_mask(rdev, dev, NULL, &mask);
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007729}
7730
Johannes Berg2e161f72010-08-12 15:38:38 +02007731static int nl80211_register_mgmt(struct sk_buff *skb, struct genl_info *info)
Jouni Malinen026331c2010-02-15 12:53:10 +02007732{
Johannes Berg4c476992010-10-04 21:36:35 +02007733 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02007734 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg2e161f72010-08-12 15:38:38 +02007735 u16 frame_type = IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_ACTION;
Jouni Malinen026331c2010-02-15 12:53:10 +02007736
7737 if (!info->attrs[NL80211_ATTR_FRAME_MATCH])
7738 return -EINVAL;
7739
Johannes Berg2e161f72010-08-12 15:38:38 +02007740 if (info->attrs[NL80211_ATTR_FRAME_TYPE])
7741 frame_type = nla_get_u16(info->attrs[NL80211_ATTR_FRAME_TYPE]);
Jouni Malinen026331c2010-02-15 12:53:10 +02007742
Johannes Berg71bbc992012-06-15 15:30:18 +02007743 switch (wdev->iftype) {
7744 case NL80211_IFTYPE_STATION:
7745 case NL80211_IFTYPE_ADHOC:
7746 case NL80211_IFTYPE_P2P_CLIENT:
7747 case NL80211_IFTYPE_AP:
7748 case NL80211_IFTYPE_AP_VLAN:
7749 case NL80211_IFTYPE_MESH_POINT:
7750 case NL80211_IFTYPE_P2P_GO:
Johannes Berg98104fde2012-06-16 00:19:54 +02007751 case NL80211_IFTYPE_P2P_DEVICE:
Johannes Berg71bbc992012-06-15 15:30:18 +02007752 break;
7753 default:
Johannes Berg4c476992010-10-04 21:36:35 +02007754 return -EOPNOTSUPP;
Johannes Berg71bbc992012-06-15 15:30:18 +02007755 }
Jouni Malinen026331c2010-02-15 12:53:10 +02007756
7757 /* not much point in registering if we can't reply */
Johannes Berg4c476992010-10-04 21:36:35 +02007758 if (!rdev->ops->mgmt_tx)
7759 return -EOPNOTSUPP;
Jouni Malinen026331c2010-02-15 12:53:10 +02007760
Eric W. Biederman15e47302012-09-07 20:12:54 +00007761 return cfg80211_mlme_register_mgmt(wdev, info->snd_portid, frame_type,
Jouni Malinen026331c2010-02-15 12:53:10 +02007762 nla_data(info->attrs[NL80211_ATTR_FRAME_MATCH]),
7763 nla_len(info->attrs[NL80211_ATTR_FRAME_MATCH]));
Jouni Malinen026331c2010-02-15 12:53:10 +02007764}
7765
Johannes Berg2e161f72010-08-12 15:38:38 +02007766static int nl80211_tx_mgmt(struct sk_buff *skb, struct genl_info *info)
Jouni Malinen026331c2010-02-15 12:53:10 +02007767{
Johannes Berg4c476992010-10-04 21:36:35 +02007768 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02007769 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg683b6d32012-11-08 21:25:48 +01007770 struct cfg80211_chan_def chandef;
Jouni Malinen026331c2010-02-15 12:53:10 +02007771 int err;
Johannes Bergd64d3732011-11-10 09:44:46 +01007772 void *hdr = NULL;
Jouni Malinen026331c2010-02-15 12:53:10 +02007773 u64 cookie;
Johannes Berge247bd902011-11-04 11:18:21 +01007774 struct sk_buff *msg = NULL;
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02007775 struct cfg80211_mgmt_tx_params params = {
7776 .dont_wait_for_ack =
7777 info->attrs[NL80211_ATTR_DONT_WAIT_FOR_ACK],
7778 };
Jouni Malinen026331c2010-02-15 12:53:10 +02007779
Johannes Berg683b6d32012-11-08 21:25:48 +01007780 if (!info->attrs[NL80211_ATTR_FRAME])
Jouni Malinen026331c2010-02-15 12:53:10 +02007781 return -EINVAL;
7782
Johannes Berg4c476992010-10-04 21:36:35 +02007783 if (!rdev->ops->mgmt_tx)
7784 return -EOPNOTSUPP;
Jouni Malinen026331c2010-02-15 12:53:10 +02007785
Johannes Berg71bbc992012-06-15 15:30:18 +02007786 switch (wdev->iftype) {
Antonio Quartulliea141b752013-06-11 14:20:03 +02007787 case NL80211_IFTYPE_P2P_DEVICE:
7788 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ])
7789 return -EINVAL;
Johannes Berg71bbc992012-06-15 15:30:18 +02007790 case NL80211_IFTYPE_STATION:
7791 case NL80211_IFTYPE_ADHOC:
7792 case NL80211_IFTYPE_P2P_CLIENT:
7793 case NL80211_IFTYPE_AP:
7794 case NL80211_IFTYPE_AP_VLAN:
7795 case NL80211_IFTYPE_MESH_POINT:
7796 case NL80211_IFTYPE_P2P_GO:
7797 break;
7798 default:
Johannes Berg4c476992010-10-04 21:36:35 +02007799 return -EOPNOTSUPP;
Johannes Berg71bbc992012-06-15 15:30:18 +02007800 }
Jouni Malinen026331c2010-02-15 12:53:10 +02007801
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007802 if (info->attrs[NL80211_ATTR_DURATION]) {
Johannes Berg7c4ef712011-11-18 15:33:48 +01007803 if (!(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX))
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007804 return -EINVAL;
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02007805 params.wait = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]);
Johannes Bergebf348f2012-06-01 12:50:54 +02007806
7807 /*
7808 * We should wait on the channel for at least a minimum amount
7809 * of time (10ms) but no longer than the driver supports.
7810 */
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02007811 if (params.wait < NL80211_MIN_REMAIN_ON_CHANNEL_TIME ||
7812 params.wait > rdev->wiphy.max_remain_on_channel_duration)
Johannes Bergebf348f2012-06-01 12:50:54 +02007813 return -EINVAL;
7814
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007815 }
7816
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02007817 params.offchan = info->attrs[NL80211_ATTR_OFFCHANNEL_TX_OK];
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007818
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02007819 if (params.offchan && !(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX))
Johannes Berg7c4ef712011-11-18 15:33:48 +01007820 return -EINVAL;
7821
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02007822 params.no_cck = nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]);
Rajkumar Manoharane9f935e2011-09-25 14:53:30 +05307823
Antonio Quartulliea141b752013-06-11 14:20:03 +02007824 /* get the channel if any has been specified, otherwise pass NULL to
7825 * the driver. The latter will use the current one
7826 */
7827 chandef.chan = NULL;
7828 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
7829 err = nl80211_parse_chandef(rdev, info, &chandef);
7830 if (err)
7831 return err;
7832 }
7833
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02007834 if (!chandef.chan && params.offchan)
Antonio Quartulliea141b752013-06-11 14:20:03 +02007835 return -EINVAL;
Jouni Malinen026331c2010-02-15 12:53:10 +02007836
Andrei Otcheretianski34d22ce2014-05-09 14:11:44 +03007837 params.buf = nla_data(info->attrs[NL80211_ATTR_FRAME]);
7838 params.len = nla_len(info->attrs[NL80211_ATTR_FRAME]);
7839
7840 if (info->attrs[NL80211_ATTR_CSA_C_OFFSETS_TX]) {
7841 int len = nla_len(info->attrs[NL80211_ATTR_CSA_C_OFFSETS_TX]);
7842 int i;
7843
7844 if (len % sizeof(u16))
7845 return -EINVAL;
7846
7847 params.n_csa_offsets = len / sizeof(u16);
7848 params.csa_offsets =
7849 nla_data(info->attrs[NL80211_ATTR_CSA_C_OFFSETS_TX]);
7850
7851 /* check that all the offsets fit the frame */
7852 for (i = 0; i < params.n_csa_offsets; i++) {
7853 if (params.csa_offsets[i] >= params.len)
7854 return -EINVAL;
7855 }
7856 }
7857
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02007858 if (!params.dont_wait_for_ack) {
Johannes Berge247bd902011-11-04 11:18:21 +01007859 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
7860 if (!msg)
7861 return -ENOMEM;
Jouni Malinen026331c2010-02-15 12:53:10 +02007862
Eric W. Biederman15e47302012-09-07 20:12:54 +00007863 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berge247bd902011-11-04 11:18:21 +01007864 NL80211_CMD_FRAME);
Dan Carpentercb35fba2013-08-14 14:50:01 +03007865 if (!hdr) {
7866 err = -ENOBUFS;
Johannes Berge247bd902011-11-04 11:18:21 +01007867 goto free_msg;
7868 }
Jouni Malinen026331c2010-02-15 12:53:10 +02007869 }
Johannes Berge247bd902011-11-04 11:18:21 +01007870
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02007871 params.chan = chandef.chan;
7872 err = cfg80211_mlme_mgmt_tx(rdev, wdev, &params, &cookie);
Jouni Malinen026331c2010-02-15 12:53:10 +02007873 if (err)
7874 goto free_msg;
7875
Johannes Berge247bd902011-11-04 11:18:21 +01007876 if (msg) {
David S. Miller9360ffd2012-03-29 04:41:26 -04007877 if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie))
7878 goto nla_put_failure;
Jouni Malinen026331c2010-02-15 12:53:10 +02007879
Johannes Berge247bd902011-11-04 11:18:21 +01007880 genlmsg_end(msg, hdr);
7881 return genlmsg_reply(msg, info);
7882 }
7883
7884 return 0;
Jouni Malinen026331c2010-02-15 12:53:10 +02007885
7886 nla_put_failure:
7887 err = -ENOBUFS;
7888 free_msg:
7889 nlmsg_free(msg);
Jouni Malinen026331c2010-02-15 12:53:10 +02007890 return err;
7891}
7892
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007893static int nl80211_tx_mgmt_cancel_wait(struct sk_buff *skb, struct genl_info *info)
7894{
7895 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02007896 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007897 u64 cookie;
7898
7899 if (!info->attrs[NL80211_ATTR_COOKIE])
7900 return -EINVAL;
7901
7902 if (!rdev->ops->mgmt_tx_cancel_wait)
7903 return -EOPNOTSUPP;
7904
Johannes Berg71bbc992012-06-15 15:30:18 +02007905 switch (wdev->iftype) {
7906 case NL80211_IFTYPE_STATION:
7907 case NL80211_IFTYPE_ADHOC:
7908 case NL80211_IFTYPE_P2P_CLIENT:
7909 case NL80211_IFTYPE_AP:
7910 case NL80211_IFTYPE_AP_VLAN:
7911 case NL80211_IFTYPE_P2P_GO:
Johannes Berg98104fde2012-06-16 00:19:54 +02007912 case NL80211_IFTYPE_P2P_DEVICE:
Johannes Berg71bbc992012-06-15 15:30:18 +02007913 break;
7914 default:
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007915 return -EOPNOTSUPP;
Johannes Berg71bbc992012-06-15 15:30:18 +02007916 }
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007917
7918 cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]);
7919
Hila Gonene35e4d22012-06-27 17:19:42 +03007920 return rdev_mgmt_tx_cancel_wait(rdev, wdev, cookie);
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007921}
7922
Kalle Valoffb9eb32010-02-17 17:58:10 +02007923static int nl80211_set_power_save(struct sk_buff *skb, struct genl_info *info)
7924{
Johannes Berg4c476992010-10-04 21:36:35 +02007925 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Kalle Valoffb9eb32010-02-17 17:58:10 +02007926 struct wireless_dev *wdev;
Johannes Berg4c476992010-10-04 21:36:35 +02007927 struct net_device *dev = info->user_ptr[1];
Kalle Valoffb9eb32010-02-17 17:58:10 +02007928 u8 ps_state;
7929 bool state;
7930 int err;
7931
Johannes Berg4c476992010-10-04 21:36:35 +02007932 if (!info->attrs[NL80211_ATTR_PS_STATE])
7933 return -EINVAL;
Kalle Valoffb9eb32010-02-17 17:58:10 +02007934
7935 ps_state = nla_get_u32(info->attrs[NL80211_ATTR_PS_STATE]);
7936
Johannes Berg4c476992010-10-04 21:36:35 +02007937 if (ps_state != NL80211_PS_DISABLED && ps_state != NL80211_PS_ENABLED)
7938 return -EINVAL;
Kalle Valoffb9eb32010-02-17 17:58:10 +02007939
7940 wdev = dev->ieee80211_ptr;
7941
Johannes Berg4c476992010-10-04 21:36:35 +02007942 if (!rdev->ops->set_power_mgmt)
7943 return -EOPNOTSUPP;
Kalle Valoffb9eb32010-02-17 17:58:10 +02007944
7945 state = (ps_state == NL80211_PS_ENABLED) ? true : false;
7946
7947 if (state == wdev->ps)
Johannes Berg4c476992010-10-04 21:36:35 +02007948 return 0;
Kalle Valoffb9eb32010-02-17 17:58:10 +02007949
Hila Gonene35e4d22012-06-27 17:19:42 +03007950 err = rdev_set_power_mgmt(rdev, dev, state, wdev->ps_timeout);
Johannes Berg4c476992010-10-04 21:36:35 +02007951 if (!err)
7952 wdev->ps = state;
Kalle Valoffb9eb32010-02-17 17:58:10 +02007953 return err;
7954}
7955
7956static int nl80211_get_power_save(struct sk_buff *skb, struct genl_info *info)
7957{
Johannes Berg4c476992010-10-04 21:36:35 +02007958 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Kalle Valoffb9eb32010-02-17 17:58:10 +02007959 enum nl80211_ps_state ps_state;
7960 struct wireless_dev *wdev;
Johannes Berg4c476992010-10-04 21:36:35 +02007961 struct net_device *dev = info->user_ptr[1];
Kalle Valoffb9eb32010-02-17 17:58:10 +02007962 struct sk_buff *msg;
7963 void *hdr;
7964 int err;
7965
Kalle Valoffb9eb32010-02-17 17:58:10 +02007966 wdev = dev->ieee80211_ptr;
7967
Johannes Berg4c476992010-10-04 21:36:35 +02007968 if (!rdev->ops->set_power_mgmt)
7969 return -EOPNOTSUPP;
Kalle Valoffb9eb32010-02-17 17:58:10 +02007970
7971 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02007972 if (!msg)
7973 return -ENOMEM;
Kalle Valoffb9eb32010-02-17 17:58:10 +02007974
Eric W. Biederman15e47302012-09-07 20:12:54 +00007975 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Kalle Valoffb9eb32010-02-17 17:58:10 +02007976 NL80211_CMD_GET_POWER_SAVE);
7977 if (!hdr) {
Johannes Berg4c476992010-10-04 21:36:35 +02007978 err = -ENOBUFS;
Kalle Valoffb9eb32010-02-17 17:58:10 +02007979 goto free_msg;
7980 }
7981
7982 if (wdev->ps)
7983 ps_state = NL80211_PS_ENABLED;
7984 else
7985 ps_state = NL80211_PS_DISABLED;
7986
David S. Miller9360ffd2012-03-29 04:41:26 -04007987 if (nla_put_u32(msg, NL80211_ATTR_PS_STATE, ps_state))
7988 goto nla_put_failure;
Kalle Valoffb9eb32010-02-17 17:58:10 +02007989
7990 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02007991 return genlmsg_reply(msg, info);
Kalle Valoffb9eb32010-02-17 17:58:10 +02007992
Johannes Berg4c476992010-10-04 21:36:35 +02007993 nla_put_failure:
Kalle Valoffb9eb32010-02-17 17:58:10 +02007994 err = -ENOBUFS;
Johannes Berg4c476992010-10-04 21:36:35 +02007995 free_msg:
Kalle Valoffb9eb32010-02-17 17:58:10 +02007996 nlmsg_free(msg);
Kalle Valoffb9eb32010-02-17 17:58:10 +02007997 return err;
7998}
7999
Johannes Berg94e860f2014-01-20 23:58:15 +01008000static const struct nla_policy
8001nl80211_attr_cqm_policy[NL80211_ATTR_CQM_MAX + 1] = {
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008002 [NL80211_ATTR_CQM_RSSI_THOLD] = { .type = NLA_U32 },
8003 [NL80211_ATTR_CQM_RSSI_HYST] = { .type = NLA_U32 },
8004 [NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT] = { .type = NLA_U32 },
Thomas Pedersen84f10702012-07-12 16:17:33 -07008005 [NL80211_ATTR_CQM_TXE_RATE] = { .type = NLA_U32 },
8006 [NL80211_ATTR_CQM_TXE_PKTS] = { .type = NLA_U32 },
8007 [NL80211_ATTR_CQM_TXE_INTVL] = { .type = NLA_U32 },
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008008};
8009
Thomas Pedersen84f10702012-07-12 16:17:33 -07008010static int nl80211_set_cqm_txe(struct genl_info *info,
Johannes Bergd9d8b012012-11-26 12:51:52 +01008011 u32 rate, u32 pkts, u32 intvl)
Thomas Pedersen84f10702012-07-12 16:17:33 -07008012{
8013 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Thomas Pedersen84f10702012-07-12 16:17:33 -07008014 struct net_device *dev = info->user_ptr[1];
Johannes Berg1da5fcc2013-08-06 14:10:48 +02008015 struct wireless_dev *wdev = dev->ieee80211_ptr;
Thomas Pedersen84f10702012-07-12 16:17:33 -07008016
Johannes Bergd9d8b012012-11-26 12:51:52 +01008017 if (rate > 100 || intvl > NL80211_CQM_TXE_MAX_INTVL)
Thomas Pedersen84f10702012-07-12 16:17:33 -07008018 return -EINVAL;
8019
Thomas Pedersen84f10702012-07-12 16:17:33 -07008020 if (!rdev->ops->set_cqm_txe_config)
8021 return -EOPNOTSUPP;
8022
8023 if (wdev->iftype != NL80211_IFTYPE_STATION &&
8024 wdev->iftype != NL80211_IFTYPE_P2P_CLIENT)
8025 return -EOPNOTSUPP;
8026
Hila Gonene35e4d22012-06-27 17:19:42 +03008027 return rdev_set_cqm_txe_config(rdev, dev, rate, pkts, intvl);
Thomas Pedersen84f10702012-07-12 16:17:33 -07008028}
8029
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008030static int nl80211_set_cqm_rssi(struct genl_info *info,
8031 s32 threshold, u32 hysteresis)
8032{
Johannes Berg4c476992010-10-04 21:36:35 +02008033 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg4c476992010-10-04 21:36:35 +02008034 struct net_device *dev = info->user_ptr[1];
Johannes Berg1da5fcc2013-08-06 14:10:48 +02008035 struct wireless_dev *wdev = dev->ieee80211_ptr;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008036
8037 if (threshold > 0)
8038 return -EINVAL;
8039
Johannes Berg1da5fcc2013-08-06 14:10:48 +02008040 /* disabling - hysteresis should also be zero then */
8041 if (threshold == 0)
8042 hysteresis = 0;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008043
Johannes Berg4c476992010-10-04 21:36:35 +02008044 if (!rdev->ops->set_cqm_rssi_config)
8045 return -EOPNOTSUPP;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008046
Johannes Berg074ac8d2010-09-16 14:58:22 +02008047 if (wdev->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02008048 wdev->iftype != NL80211_IFTYPE_P2P_CLIENT)
8049 return -EOPNOTSUPP;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008050
Hila Gonene35e4d22012-06-27 17:19:42 +03008051 return rdev_set_cqm_rssi_config(rdev, dev, threshold, hysteresis);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008052}
8053
8054static int nl80211_set_cqm(struct sk_buff *skb, struct genl_info *info)
8055{
8056 struct nlattr *attrs[NL80211_ATTR_CQM_MAX + 1];
8057 struct nlattr *cqm;
8058 int err;
8059
8060 cqm = info->attrs[NL80211_ATTR_CQM];
Johannes Berg1da5fcc2013-08-06 14:10:48 +02008061 if (!cqm)
8062 return -EINVAL;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008063
8064 err = nla_parse_nested(attrs, NL80211_ATTR_CQM_MAX, cqm,
8065 nl80211_attr_cqm_policy);
8066 if (err)
Johannes Berg1da5fcc2013-08-06 14:10:48 +02008067 return err;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008068
8069 if (attrs[NL80211_ATTR_CQM_RSSI_THOLD] &&
8070 attrs[NL80211_ATTR_CQM_RSSI_HYST]) {
Johannes Berg1da5fcc2013-08-06 14:10:48 +02008071 s32 threshold = nla_get_s32(attrs[NL80211_ATTR_CQM_RSSI_THOLD]);
8072 u32 hysteresis = nla_get_u32(attrs[NL80211_ATTR_CQM_RSSI_HYST]);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008073
Johannes Berg1da5fcc2013-08-06 14:10:48 +02008074 return nl80211_set_cqm_rssi(info, threshold, hysteresis);
8075 }
8076
8077 if (attrs[NL80211_ATTR_CQM_TXE_RATE] &&
8078 attrs[NL80211_ATTR_CQM_TXE_PKTS] &&
8079 attrs[NL80211_ATTR_CQM_TXE_INTVL]) {
8080 u32 rate = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_RATE]);
8081 u32 pkts = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_PKTS]);
8082 u32 intvl = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_INTVL]);
8083
8084 return nl80211_set_cqm_txe(info, rate, pkts, intvl);
8085 }
8086
8087 return -EINVAL;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008088}
8089
Johannes Berg29cbe682010-12-03 09:20:44 +01008090static int nl80211_join_mesh(struct sk_buff *skb, struct genl_info *info)
8091{
8092 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8093 struct net_device *dev = info->user_ptr[1];
8094 struct mesh_config cfg;
Javier Cardonac80d5452010-12-16 17:37:49 -08008095 struct mesh_setup setup;
Johannes Berg29cbe682010-12-03 09:20:44 +01008096 int err;
8097
8098 /* start with default */
8099 memcpy(&cfg, &default_mesh_config, sizeof(cfg));
Javier Cardonac80d5452010-12-16 17:37:49 -08008100 memcpy(&setup, &default_mesh_setup, sizeof(setup));
Johannes Berg29cbe682010-12-03 09:20:44 +01008101
Javier Cardona24bdd9f2010-12-16 17:37:48 -08008102 if (info->attrs[NL80211_ATTR_MESH_CONFIG]) {
Johannes Berg29cbe682010-12-03 09:20:44 +01008103 /* and parse parameters if given */
Javier Cardona24bdd9f2010-12-16 17:37:48 -08008104 err = nl80211_parse_mesh_config(info, &cfg, NULL);
Johannes Berg29cbe682010-12-03 09:20:44 +01008105 if (err)
8106 return err;
8107 }
8108
8109 if (!info->attrs[NL80211_ATTR_MESH_ID] ||
8110 !nla_len(info->attrs[NL80211_ATTR_MESH_ID]))
8111 return -EINVAL;
8112
Javier Cardonac80d5452010-12-16 17:37:49 -08008113 setup.mesh_id = nla_data(info->attrs[NL80211_ATTR_MESH_ID]);
8114 setup.mesh_id_len = nla_len(info->attrs[NL80211_ATTR_MESH_ID]);
8115
Chun-Yeow Yeoh4bb62342011-11-24 17:15:20 -08008116 if (info->attrs[NL80211_ATTR_MCAST_RATE] &&
8117 !nl80211_parse_mcast_rate(rdev, setup.mcast_rate,
8118 nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE])))
8119 return -EINVAL;
8120
Marco Porsch9bdbf042013-01-07 16:04:51 +01008121 if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) {
8122 setup.beacon_interval =
8123 nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]);
8124 if (setup.beacon_interval < 10 ||
8125 setup.beacon_interval > 10000)
8126 return -EINVAL;
8127 }
8128
8129 if (info->attrs[NL80211_ATTR_DTIM_PERIOD]) {
8130 setup.dtim_period =
8131 nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]);
8132 if (setup.dtim_period < 1 || setup.dtim_period > 100)
8133 return -EINVAL;
8134 }
8135
Javier Cardonac80d5452010-12-16 17:37:49 -08008136 if (info->attrs[NL80211_ATTR_MESH_SETUP]) {
8137 /* parse additional setup parameters if given */
8138 err = nl80211_parse_mesh_setup(info, &setup);
8139 if (err)
8140 return err;
8141 }
8142
Thomas Pedersend37bb182013-03-04 13:06:13 -08008143 if (setup.user_mpm)
8144 cfg.auto_open_plinks = false;
8145
Johannes Bergcc1d2802012-05-16 23:50:20 +02008146 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
Johannes Berg683b6d32012-11-08 21:25:48 +01008147 err = nl80211_parse_chandef(rdev, info, &setup.chandef);
8148 if (err)
8149 return err;
Johannes Bergcc1d2802012-05-16 23:50:20 +02008150 } else {
8151 /* cfg80211_join_mesh() will sort it out */
Johannes Berg683b6d32012-11-08 21:25:48 +01008152 setup.chandef.chan = NULL;
Johannes Bergcc1d2802012-05-16 23:50:20 +02008153 }
8154
Ashok Nagarajanffb3cf32013-06-03 10:33:36 -07008155 if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) {
8156 u8 *rates = nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
8157 int n_rates =
8158 nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
8159 struct ieee80211_supported_band *sband;
8160
8161 if (!setup.chandef.chan)
8162 return -EINVAL;
8163
8164 sband = rdev->wiphy.bands[setup.chandef.chan->band];
8165
8166 err = ieee80211_get_ratemask(sband, rates, n_rates,
8167 &setup.basic_rates);
8168 if (err)
8169 return err;
8170 }
8171
Javier Cardonac80d5452010-12-16 17:37:49 -08008172 return cfg80211_join_mesh(rdev, dev, &setup, &cfg);
Johannes Berg29cbe682010-12-03 09:20:44 +01008173}
8174
8175static int nl80211_leave_mesh(struct sk_buff *skb, struct genl_info *info)
8176{
8177 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8178 struct net_device *dev = info->user_ptr[1];
8179
8180 return cfg80211_leave_mesh(rdev, dev);
8181}
8182
Johannes Bergdfb89c52012-06-27 09:23:48 +02008183#ifdef CONFIG_PM
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08008184static int nl80211_send_wowlan_patterns(struct sk_buff *msg,
8185 struct cfg80211_registered_device *rdev)
8186{
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008187 struct cfg80211_wowlan *wowlan = rdev->wiphy.wowlan_config;
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08008188 struct nlattr *nl_pats, *nl_pat;
8189 int i, pat_len;
8190
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008191 if (!wowlan->n_patterns)
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08008192 return 0;
8193
8194 nl_pats = nla_nest_start(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN);
8195 if (!nl_pats)
8196 return -ENOBUFS;
8197
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008198 for (i = 0; i < wowlan->n_patterns; i++) {
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08008199 nl_pat = nla_nest_start(msg, i + 1);
8200 if (!nl_pat)
8201 return -ENOBUFS;
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008202 pat_len = wowlan->patterns[i].pattern_len;
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07008203 if (nla_put(msg, NL80211_PKTPAT_MASK, DIV_ROUND_UP(pat_len, 8),
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008204 wowlan->patterns[i].mask) ||
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07008205 nla_put(msg, NL80211_PKTPAT_PATTERN, pat_len,
8206 wowlan->patterns[i].pattern) ||
8207 nla_put_u32(msg, NL80211_PKTPAT_OFFSET,
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008208 wowlan->patterns[i].pkt_offset))
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08008209 return -ENOBUFS;
8210 nla_nest_end(msg, nl_pat);
8211 }
8212 nla_nest_end(msg, nl_pats);
8213
8214 return 0;
8215}
8216
Johannes Berg2a0e0472013-01-23 22:57:40 +01008217static int nl80211_send_wowlan_tcp(struct sk_buff *msg,
8218 struct cfg80211_wowlan_tcp *tcp)
8219{
8220 struct nlattr *nl_tcp;
8221
8222 if (!tcp)
8223 return 0;
8224
8225 nl_tcp = nla_nest_start(msg, NL80211_WOWLAN_TRIG_TCP_CONNECTION);
8226 if (!nl_tcp)
8227 return -ENOBUFS;
8228
8229 if (nla_put_be32(msg, NL80211_WOWLAN_TCP_SRC_IPV4, tcp->src) ||
8230 nla_put_be32(msg, NL80211_WOWLAN_TCP_DST_IPV4, tcp->dst) ||
8231 nla_put(msg, NL80211_WOWLAN_TCP_DST_MAC, ETH_ALEN, tcp->dst_mac) ||
8232 nla_put_u16(msg, NL80211_WOWLAN_TCP_SRC_PORT, tcp->src_port) ||
8233 nla_put_u16(msg, NL80211_WOWLAN_TCP_DST_PORT, tcp->dst_port) ||
8234 nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD,
8235 tcp->payload_len, tcp->payload) ||
8236 nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_INTERVAL,
8237 tcp->data_interval) ||
8238 nla_put(msg, NL80211_WOWLAN_TCP_WAKE_PAYLOAD,
8239 tcp->wake_len, tcp->wake_data) ||
8240 nla_put(msg, NL80211_WOWLAN_TCP_WAKE_MASK,
8241 DIV_ROUND_UP(tcp->wake_len, 8), tcp->wake_mask))
8242 return -ENOBUFS;
8243
8244 if (tcp->payload_seq.len &&
8245 nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ,
8246 sizeof(tcp->payload_seq), &tcp->payload_seq))
8247 return -ENOBUFS;
8248
8249 if (tcp->payload_tok.len &&
8250 nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN,
8251 sizeof(tcp->payload_tok) + tcp->tokens_size,
8252 &tcp->payload_tok))
8253 return -ENOBUFS;
8254
Johannes Berge248ad32013-05-16 10:24:28 +02008255 nla_nest_end(msg, nl_tcp);
8256
Johannes Berg2a0e0472013-01-23 22:57:40 +01008257 return 0;
8258}
8259
Johannes Bergff1b6e62011-05-04 15:37:28 +02008260static int nl80211_get_wowlan(struct sk_buff *skb, struct genl_info *info)
8261{
8262 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8263 struct sk_buff *msg;
8264 void *hdr;
Johannes Berg2a0e0472013-01-23 22:57:40 +01008265 u32 size = NLMSG_DEFAULT_SIZE;
Johannes Bergff1b6e62011-05-04 15:37:28 +02008266
Johannes Berg964dc9e2013-06-03 17:25:34 +02008267 if (!rdev->wiphy.wowlan)
Johannes Bergff1b6e62011-05-04 15:37:28 +02008268 return -EOPNOTSUPP;
8269
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008270 if (rdev->wiphy.wowlan_config && rdev->wiphy.wowlan_config->tcp) {
Johannes Berg2a0e0472013-01-23 22:57:40 +01008271 /* adjust size to have room for all the data */
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008272 size += rdev->wiphy.wowlan_config->tcp->tokens_size +
8273 rdev->wiphy.wowlan_config->tcp->payload_len +
8274 rdev->wiphy.wowlan_config->tcp->wake_len +
8275 rdev->wiphy.wowlan_config->tcp->wake_len / 8;
Johannes Berg2a0e0472013-01-23 22:57:40 +01008276 }
8277
8278 msg = nlmsg_new(size, GFP_KERNEL);
Johannes Bergff1b6e62011-05-04 15:37:28 +02008279 if (!msg)
8280 return -ENOMEM;
8281
Eric W. Biederman15e47302012-09-07 20:12:54 +00008282 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Johannes Bergff1b6e62011-05-04 15:37:28 +02008283 NL80211_CMD_GET_WOWLAN);
8284 if (!hdr)
8285 goto nla_put_failure;
8286
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008287 if (rdev->wiphy.wowlan_config) {
Johannes Bergff1b6e62011-05-04 15:37:28 +02008288 struct nlattr *nl_wowlan;
8289
8290 nl_wowlan = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS);
8291 if (!nl_wowlan)
8292 goto nla_put_failure;
8293
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008294 if ((rdev->wiphy.wowlan_config->any &&
David S. Miller9360ffd2012-03-29 04:41:26 -04008295 nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008296 (rdev->wiphy.wowlan_config->disconnect &&
David S. Miller9360ffd2012-03-29 04:41:26 -04008297 nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008298 (rdev->wiphy.wowlan_config->magic_pkt &&
David S. Miller9360ffd2012-03-29 04:41:26 -04008299 nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008300 (rdev->wiphy.wowlan_config->gtk_rekey_failure &&
David S. Miller9360ffd2012-03-29 04:41:26 -04008301 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008302 (rdev->wiphy.wowlan_config->eap_identity_req &&
David S. Miller9360ffd2012-03-29 04:41:26 -04008303 nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008304 (rdev->wiphy.wowlan_config->four_way_handshake &&
David S. Miller9360ffd2012-03-29 04:41:26 -04008305 nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008306 (rdev->wiphy.wowlan_config->rfkill_release &&
David S. Miller9360ffd2012-03-29 04:41:26 -04008307 nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE)))
8308 goto nla_put_failure;
Johannes Berg2a0e0472013-01-23 22:57:40 +01008309
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08008310 if (nl80211_send_wowlan_patterns(msg, rdev))
8311 goto nla_put_failure;
Johannes Berg2a0e0472013-01-23 22:57:40 +01008312
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008313 if (nl80211_send_wowlan_tcp(msg,
8314 rdev->wiphy.wowlan_config->tcp))
Johannes Berg2a0e0472013-01-23 22:57:40 +01008315 goto nla_put_failure;
8316
Johannes Bergff1b6e62011-05-04 15:37:28 +02008317 nla_nest_end(msg, nl_wowlan);
8318 }
8319
8320 genlmsg_end(msg, hdr);
8321 return genlmsg_reply(msg, info);
8322
8323nla_put_failure:
8324 nlmsg_free(msg);
8325 return -ENOBUFS;
8326}
8327
Johannes Berg2a0e0472013-01-23 22:57:40 +01008328static int nl80211_parse_wowlan_tcp(struct cfg80211_registered_device *rdev,
8329 struct nlattr *attr,
8330 struct cfg80211_wowlan *trig)
8331{
8332 struct nlattr *tb[NUM_NL80211_WOWLAN_TCP];
8333 struct cfg80211_wowlan_tcp *cfg;
8334 struct nl80211_wowlan_tcp_data_token *tok = NULL;
8335 struct nl80211_wowlan_tcp_data_seq *seq = NULL;
8336 u32 size;
8337 u32 data_size, wake_size, tokens_size = 0, wake_mask_size;
8338 int err, port;
8339
Johannes Berg964dc9e2013-06-03 17:25:34 +02008340 if (!rdev->wiphy.wowlan->tcp)
Johannes Berg2a0e0472013-01-23 22:57:40 +01008341 return -EINVAL;
8342
8343 err = nla_parse(tb, MAX_NL80211_WOWLAN_TCP,
8344 nla_data(attr), nla_len(attr),
8345 nl80211_wowlan_tcp_policy);
8346 if (err)
8347 return err;
8348
8349 if (!tb[NL80211_WOWLAN_TCP_SRC_IPV4] ||
8350 !tb[NL80211_WOWLAN_TCP_DST_IPV4] ||
8351 !tb[NL80211_WOWLAN_TCP_DST_MAC] ||
8352 !tb[NL80211_WOWLAN_TCP_DST_PORT] ||
8353 !tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD] ||
8354 !tb[NL80211_WOWLAN_TCP_DATA_INTERVAL] ||
8355 !tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD] ||
8356 !tb[NL80211_WOWLAN_TCP_WAKE_MASK])
8357 return -EINVAL;
8358
8359 data_size = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]);
Johannes Berg964dc9e2013-06-03 17:25:34 +02008360 if (data_size > rdev->wiphy.wowlan->tcp->data_payload_max)
Johannes Berg2a0e0472013-01-23 22:57:40 +01008361 return -EINVAL;
8362
8363 if (nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]) >
Johannes Berg964dc9e2013-06-03 17:25:34 +02008364 rdev->wiphy.wowlan->tcp->data_interval_max ||
Johannes Berg723d5682013-02-26 13:56:40 +01008365 nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]) == 0)
Johannes Berg2a0e0472013-01-23 22:57:40 +01008366 return -EINVAL;
8367
8368 wake_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]);
Johannes Berg964dc9e2013-06-03 17:25:34 +02008369 if (wake_size > rdev->wiphy.wowlan->tcp->wake_payload_max)
Johannes Berg2a0e0472013-01-23 22:57:40 +01008370 return -EINVAL;
8371
8372 wake_mask_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_MASK]);
8373 if (wake_mask_size != DIV_ROUND_UP(wake_size, 8))
8374 return -EINVAL;
8375
8376 if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]) {
8377 u32 tokln = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]);
8378
8379 tok = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]);
8380 tokens_size = tokln - sizeof(*tok);
8381
8382 if (!tok->len || tokens_size % tok->len)
8383 return -EINVAL;
Johannes Berg964dc9e2013-06-03 17:25:34 +02008384 if (!rdev->wiphy.wowlan->tcp->tok)
Johannes Berg2a0e0472013-01-23 22:57:40 +01008385 return -EINVAL;
Johannes Berg964dc9e2013-06-03 17:25:34 +02008386 if (tok->len > rdev->wiphy.wowlan->tcp->tok->max_len)
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->min_len)
Johannes Berg2a0e0472013-01-23 22:57:40 +01008389 return -EINVAL;
Johannes Berg964dc9e2013-06-03 17:25:34 +02008390 if (tokens_size > rdev->wiphy.wowlan->tcp->tok->bufsize)
Johannes Berg2a0e0472013-01-23 22:57:40 +01008391 return -EINVAL;
8392 if (tok->offset + tok->len > data_size)
8393 return -EINVAL;
8394 }
8395
8396 if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]) {
8397 seq = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]);
Johannes Berg964dc9e2013-06-03 17:25:34 +02008398 if (!rdev->wiphy.wowlan->tcp->seq)
Johannes Berg2a0e0472013-01-23 22:57:40 +01008399 return -EINVAL;
8400 if (seq->len == 0 || seq->len > 4)
8401 return -EINVAL;
8402 if (seq->len + seq->offset > data_size)
8403 return -EINVAL;
8404 }
8405
8406 size = sizeof(*cfg);
8407 size += data_size;
8408 size += wake_size + wake_mask_size;
8409 size += tokens_size;
8410
8411 cfg = kzalloc(size, GFP_KERNEL);
8412 if (!cfg)
8413 return -ENOMEM;
8414 cfg->src = nla_get_be32(tb[NL80211_WOWLAN_TCP_SRC_IPV4]);
8415 cfg->dst = nla_get_be32(tb[NL80211_WOWLAN_TCP_DST_IPV4]);
8416 memcpy(cfg->dst_mac, nla_data(tb[NL80211_WOWLAN_TCP_DST_MAC]),
8417 ETH_ALEN);
8418 if (tb[NL80211_WOWLAN_TCP_SRC_PORT])
8419 port = nla_get_u16(tb[NL80211_WOWLAN_TCP_SRC_PORT]);
8420 else
8421 port = 0;
8422#ifdef CONFIG_INET
8423 /* allocate a socket and port for it and use it */
8424 err = __sock_create(wiphy_net(&rdev->wiphy), PF_INET, SOCK_STREAM,
8425 IPPROTO_TCP, &cfg->sock, 1);
8426 if (err) {
8427 kfree(cfg);
8428 return err;
8429 }
8430 if (inet_csk_get_port(cfg->sock->sk, port)) {
8431 sock_release(cfg->sock);
8432 kfree(cfg);
8433 return -EADDRINUSE;
8434 }
8435 cfg->src_port = inet_sk(cfg->sock->sk)->inet_num;
8436#else
8437 if (!port) {
8438 kfree(cfg);
8439 return -EINVAL;
8440 }
8441 cfg->src_port = port;
8442#endif
8443
8444 cfg->dst_port = nla_get_u16(tb[NL80211_WOWLAN_TCP_DST_PORT]);
8445 cfg->payload_len = data_size;
8446 cfg->payload = (u8 *)cfg + sizeof(*cfg) + tokens_size;
8447 memcpy((void *)cfg->payload,
8448 nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]),
8449 data_size);
8450 if (seq)
8451 cfg->payload_seq = *seq;
8452 cfg->data_interval = nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]);
8453 cfg->wake_len = wake_size;
8454 cfg->wake_data = (u8 *)cfg + sizeof(*cfg) + tokens_size + data_size;
8455 memcpy((void *)cfg->wake_data,
8456 nla_data(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]),
8457 wake_size);
8458 cfg->wake_mask = (u8 *)cfg + sizeof(*cfg) + tokens_size +
8459 data_size + wake_size;
8460 memcpy((void *)cfg->wake_mask,
8461 nla_data(tb[NL80211_WOWLAN_TCP_WAKE_MASK]),
8462 wake_mask_size);
8463 if (tok) {
8464 cfg->tokens_size = tokens_size;
8465 memcpy(&cfg->payload_tok, tok, sizeof(*tok) + tokens_size);
8466 }
8467
8468 trig->tcp = cfg;
8469
8470 return 0;
8471}
8472
Johannes Bergff1b6e62011-05-04 15:37:28 +02008473static int nl80211_set_wowlan(struct sk_buff *skb, struct genl_info *info)
8474{
8475 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8476 struct nlattr *tb[NUM_NL80211_WOWLAN_TRIG];
Johannes Bergff1b6e62011-05-04 15:37:28 +02008477 struct cfg80211_wowlan new_triggers = {};
Johannes Bergae33bd82012-07-12 16:25:02 +02008478 struct cfg80211_wowlan *ntrig;
Johannes Berg964dc9e2013-06-03 17:25:34 +02008479 const struct wiphy_wowlan_support *wowlan = rdev->wiphy.wowlan;
Johannes Bergff1b6e62011-05-04 15:37:28 +02008480 int err, i;
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008481 bool prev_enabled = rdev->wiphy.wowlan_config;
Johannes Bergff1b6e62011-05-04 15:37:28 +02008482
Johannes Berg964dc9e2013-06-03 17:25:34 +02008483 if (!wowlan)
Johannes Bergff1b6e62011-05-04 15:37:28 +02008484 return -EOPNOTSUPP;
8485
Johannes Bergae33bd82012-07-12 16:25:02 +02008486 if (!info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]) {
8487 cfg80211_rdev_free_wowlan(rdev);
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008488 rdev->wiphy.wowlan_config = NULL;
Johannes Bergae33bd82012-07-12 16:25:02 +02008489 goto set_wakeup;
8490 }
Johannes Bergff1b6e62011-05-04 15:37:28 +02008491
8492 err = nla_parse(tb, MAX_NL80211_WOWLAN_TRIG,
8493 nla_data(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]),
8494 nla_len(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]),
8495 nl80211_wowlan_policy);
8496 if (err)
8497 return err;
8498
8499 if (tb[NL80211_WOWLAN_TRIG_ANY]) {
8500 if (!(wowlan->flags & WIPHY_WOWLAN_ANY))
8501 return -EINVAL;
8502 new_triggers.any = true;
8503 }
8504
8505 if (tb[NL80211_WOWLAN_TRIG_DISCONNECT]) {
8506 if (!(wowlan->flags & WIPHY_WOWLAN_DISCONNECT))
8507 return -EINVAL;
8508 new_triggers.disconnect = true;
8509 }
8510
8511 if (tb[NL80211_WOWLAN_TRIG_MAGIC_PKT]) {
8512 if (!(wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT))
8513 return -EINVAL;
8514 new_triggers.magic_pkt = true;
8515 }
8516
Johannes Berg77dbbb12011-07-13 10:48:55 +02008517 if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED])
8518 return -EINVAL;
8519
8520 if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE]) {
8521 if (!(wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE))
8522 return -EINVAL;
8523 new_triggers.gtk_rekey_failure = true;
8524 }
8525
8526 if (tb[NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST]) {
8527 if (!(wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ))
8528 return -EINVAL;
8529 new_triggers.eap_identity_req = true;
8530 }
8531
8532 if (tb[NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE]) {
8533 if (!(wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE))
8534 return -EINVAL;
8535 new_triggers.four_way_handshake = true;
8536 }
8537
8538 if (tb[NL80211_WOWLAN_TRIG_RFKILL_RELEASE]) {
8539 if (!(wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE))
8540 return -EINVAL;
8541 new_triggers.rfkill_release = true;
8542 }
8543
Johannes Bergff1b6e62011-05-04 15:37:28 +02008544 if (tb[NL80211_WOWLAN_TRIG_PKT_PATTERN]) {
8545 struct nlattr *pat;
8546 int n_patterns = 0;
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08008547 int rem, pat_len, mask_len, pkt_offset;
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07008548 struct nlattr *pat_tb[NUM_NL80211_PKTPAT];
Johannes Bergff1b6e62011-05-04 15:37:28 +02008549
8550 nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN],
8551 rem)
8552 n_patterns++;
8553 if (n_patterns > wowlan->n_patterns)
8554 return -EINVAL;
8555
8556 new_triggers.patterns = kcalloc(n_patterns,
8557 sizeof(new_triggers.patterns[0]),
8558 GFP_KERNEL);
8559 if (!new_triggers.patterns)
8560 return -ENOMEM;
8561
8562 new_triggers.n_patterns = n_patterns;
8563 i = 0;
8564
8565 nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN],
8566 rem) {
Johannes Berg922bd802014-05-19 17:59:50 +02008567 u8 *mask_pat;
8568
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07008569 nla_parse(pat_tb, MAX_NL80211_PKTPAT, nla_data(pat),
8570 nla_len(pat), NULL);
Johannes Bergff1b6e62011-05-04 15:37:28 +02008571 err = -EINVAL;
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07008572 if (!pat_tb[NL80211_PKTPAT_MASK] ||
8573 !pat_tb[NL80211_PKTPAT_PATTERN])
Johannes Bergff1b6e62011-05-04 15:37:28 +02008574 goto error;
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07008575 pat_len = nla_len(pat_tb[NL80211_PKTPAT_PATTERN]);
Johannes Bergff1b6e62011-05-04 15:37:28 +02008576 mask_len = DIV_ROUND_UP(pat_len, 8);
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07008577 if (nla_len(pat_tb[NL80211_PKTPAT_MASK]) != mask_len)
Johannes Bergff1b6e62011-05-04 15:37:28 +02008578 goto error;
8579 if (pat_len > wowlan->pattern_max_len ||
8580 pat_len < wowlan->pattern_min_len)
8581 goto error;
8582
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07008583 if (!pat_tb[NL80211_PKTPAT_OFFSET])
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08008584 pkt_offset = 0;
8585 else
8586 pkt_offset = nla_get_u32(
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07008587 pat_tb[NL80211_PKTPAT_OFFSET]);
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08008588 if (pkt_offset > wowlan->max_pkt_offset)
8589 goto error;
8590 new_triggers.patterns[i].pkt_offset = pkt_offset;
8591
Johannes Berg922bd802014-05-19 17:59:50 +02008592 mask_pat = kmalloc(mask_len + pat_len, GFP_KERNEL);
8593 if (!mask_pat) {
Johannes Bergff1b6e62011-05-04 15:37:28 +02008594 err = -ENOMEM;
8595 goto error;
8596 }
Johannes Berg922bd802014-05-19 17:59:50 +02008597 new_triggers.patterns[i].mask = mask_pat;
8598 memcpy(mask_pat, nla_data(pat_tb[NL80211_PKTPAT_MASK]),
Johannes Bergff1b6e62011-05-04 15:37:28 +02008599 mask_len);
Johannes Berg922bd802014-05-19 17:59:50 +02008600 mask_pat += mask_len;
8601 new_triggers.patterns[i].pattern = mask_pat;
Johannes Bergff1b6e62011-05-04 15:37:28 +02008602 new_triggers.patterns[i].pattern_len = pat_len;
Johannes Berg922bd802014-05-19 17:59:50 +02008603 memcpy(mask_pat,
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07008604 nla_data(pat_tb[NL80211_PKTPAT_PATTERN]),
Johannes Bergff1b6e62011-05-04 15:37:28 +02008605 pat_len);
8606 i++;
8607 }
8608 }
8609
Johannes Berg2a0e0472013-01-23 22:57:40 +01008610 if (tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION]) {
8611 err = nl80211_parse_wowlan_tcp(
8612 rdev, tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION],
8613 &new_triggers);
8614 if (err)
8615 goto error;
8616 }
8617
Johannes Bergae33bd82012-07-12 16:25:02 +02008618 ntrig = kmemdup(&new_triggers, sizeof(new_triggers), GFP_KERNEL);
8619 if (!ntrig) {
8620 err = -ENOMEM;
8621 goto error;
Johannes Bergff1b6e62011-05-04 15:37:28 +02008622 }
Johannes Bergae33bd82012-07-12 16:25:02 +02008623 cfg80211_rdev_free_wowlan(rdev);
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008624 rdev->wiphy.wowlan_config = ntrig;
Johannes Bergff1b6e62011-05-04 15:37:28 +02008625
Johannes Bergae33bd82012-07-12 16:25:02 +02008626 set_wakeup:
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008627 if (rdev->ops->set_wakeup &&
8628 prev_enabled != !!rdev->wiphy.wowlan_config)
8629 rdev_set_wakeup(rdev, rdev->wiphy.wowlan_config);
Johannes Berg6d525632012-04-04 15:05:25 +02008630
Johannes Bergff1b6e62011-05-04 15:37:28 +02008631 return 0;
8632 error:
8633 for (i = 0; i < new_triggers.n_patterns; i++)
8634 kfree(new_triggers.patterns[i].mask);
8635 kfree(new_triggers.patterns);
Johannes Berg2a0e0472013-01-23 22:57:40 +01008636 if (new_triggers.tcp && new_triggers.tcp->sock)
8637 sock_release(new_triggers.tcp->sock);
8638 kfree(new_triggers.tcp);
Johannes Bergff1b6e62011-05-04 15:37:28 +02008639 return err;
8640}
Johannes Bergdfb89c52012-06-27 09:23:48 +02008641#endif
Johannes Bergff1b6e62011-05-04 15:37:28 +02008642
Amitkumar Karwarbe29b992013-06-28 11:51:26 -07008643static int nl80211_send_coalesce_rules(struct sk_buff *msg,
8644 struct cfg80211_registered_device *rdev)
8645{
8646 struct nlattr *nl_pats, *nl_pat, *nl_rule, *nl_rules;
8647 int i, j, pat_len;
8648 struct cfg80211_coalesce_rules *rule;
8649
8650 if (!rdev->coalesce->n_rules)
8651 return 0;
8652
8653 nl_rules = nla_nest_start(msg, NL80211_ATTR_COALESCE_RULE);
8654 if (!nl_rules)
8655 return -ENOBUFS;
8656
8657 for (i = 0; i < rdev->coalesce->n_rules; i++) {
8658 nl_rule = nla_nest_start(msg, i + 1);
8659 if (!nl_rule)
8660 return -ENOBUFS;
8661
8662 rule = &rdev->coalesce->rules[i];
8663 if (nla_put_u32(msg, NL80211_ATTR_COALESCE_RULE_DELAY,
8664 rule->delay))
8665 return -ENOBUFS;
8666
8667 if (nla_put_u32(msg, NL80211_ATTR_COALESCE_RULE_CONDITION,
8668 rule->condition))
8669 return -ENOBUFS;
8670
8671 nl_pats = nla_nest_start(msg,
8672 NL80211_ATTR_COALESCE_RULE_PKT_PATTERN);
8673 if (!nl_pats)
8674 return -ENOBUFS;
8675
8676 for (j = 0; j < rule->n_patterns; j++) {
8677 nl_pat = nla_nest_start(msg, j + 1);
8678 if (!nl_pat)
8679 return -ENOBUFS;
8680 pat_len = rule->patterns[j].pattern_len;
8681 if (nla_put(msg, NL80211_PKTPAT_MASK,
8682 DIV_ROUND_UP(pat_len, 8),
8683 rule->patterns[j].mask) ||
8684 nla_put(msg, NL80211_PKTPAT_PATTERN, pat_len,
8685 rule->patterns[j].pattern) ||
8686 nla_put_u32(msg, NL80211_PKTPAT_OFFSET,
8687 rule->patterns[j].pkt_offset))
8688 return -ENOBUFS;
8689 nla_nest_end(msg, nl_pat);
8690 }
8691 nla_nest_end(msg, nl_pats);
8692 nla_nest_end(msg, nl_rule);
8693 }
8694 nla_nest_end(msg, nl_rules);
8695
8696 return 0;
8697}
8698
8699static int nl80211_get_coalesce(struct sk_buff *skb, struct genl_info *info)
8700{
8701 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8702 struct sk_buff *msg;
8703 void *hdr;
8704
8705 if (!rdev->wiphy.coalesce)
8706 return -EOPNOTSUPP;
8707
8708 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
8709 if (!msg)
8710 return -ENOMEM;
8711
8712 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
8713 NL80211_CMD_GET_COALESCE);
8714 if (!hdr)
8715 goto nla_put_failure;
8716
8717 if (rdev->coalesce && nl80211_send_coalesce_rules(msg, rdev))
8718 goto nla_put_failure;
8719
8720 genlmsg_end(msg, hdr);
8721 return genlmsg_reply(msg, info);
8722
8723nla_put_failure:
8724 nlmsg_free(msg);
8725 return -ENOBUFS;
8726}
8727
8728void cfg80211_rdev_free_coalesce(struct cfg80211_registered_device *rdev)
8729{
8730 struct cfg80211_coalesce *coalesce = rdev->coalesce;
8731 int i, j;
8732 struct cfg80211_coalesce_rules *rule;
8733
8734 if (!coalesce)
8735 return;
8736
8737 for (i = 0; i < coalesce->n_rules; i++) {
8738 rule = &coalesce->rules[i];
8739 for (j = 0; j < rule->n_patterns; j++)
8740 kfree(rule->patterns[j].mask);
8741 kfree(rule->patterns);
8742 }
8743 kfree(coalesce->rules);
8744 kfree(coalesce);
8745 rdev->coalesce = NULL;
8746}
8747
8748static int nl80211_parse_coalesce_rule(struct cfg80211_registered_device *rdev,
8749 struct nlattr *rule,
8750 struct cfg80211_coalesce_rules *new_rule)
8751{
8752 int err, i;
8753 const struct wiphy_coalesce_support *coalesce = rdev->wiphy.coalesce;
8754 struct nlattr *tb[NUM_NL80211_ATTR_COALESCE_RULE], *pat;
8755 int rem, pat_len, mask_len, pkt_offset, n_patterns = 0;
8756 struct nlattr *pat_tb[NUM_NL80211_PKTPAT];
8757
8758 err = nla_parse(tb, NL80211_ATTR_COALESCE_RULE_MAX, nla_data(rule),
8759 nla_len(rule), nl80211_coalesce_policy);
8760 if (err)
8761 return err;
8762
8763 if (tb[NL80211_ATTR_COALESCE_RULE_DELAY])
8764 new_rule->delay =
8765 nla_get_u32(tb[NL80211_ATTR_COALESCE_RULE_DELAY]);
8766 if (new_rule->delay > coalesce->max_delay)
8767 return -EINVAL;
8768
8769 if (tb[NL80211_ATTR_COALESCE_RULE_CONDITION])
8770 new_rule->condition =
8771 nla_get_u32(tb[NL80211_ATTR_COALESCE_RULE_CONDITION]);
8772 if (new_rule->condition != NL80211_COALESCE_CONDITION_MATCH &&
8773 new_rule->condition != NL80211_COALESCE_CONDITION_NO_MATCH)
8774 return -EINVAL;
8775
8776 if (!tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN])
8777 return -EINVAL;
8778
8779 nla_for_each_nested(pat, tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN],
8780 rem)
8781 n_patterns++;
8782 if (n_patterns > coalesce->n_patterns)
8783 return -EINVAL;
8784
8785 new_rule->patterns = kcalloc(n_patterns, sizeof(new_rule->patterns[0]),
8786 GFP_KERNEL);
8787 if (!new_rule->patterns)
8788 return -ENOMEM;
8789
8790 new_rule->n_patterns = n_patterns;
8791 i = 0;
8792
8793 nla_for_each_nested(pat, tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN],
8794 rem) {
Johannes Berg922bd802014-05-19 17:59:50 +02008795 u8 *mask_pat;
8796
Amitkumar Karwarbe29b992013-06-28 11:51:26 -07008797 nla_parse(pat_tb, MAX_NL80211_PKTPAT, nla_data(pat),
8798 nla_len(pat), NULL);
8799 if (!pat_tb[NL80211_PKTPAT_MASK] ||
8800 !pat_tb[NL80211_PKTPAT_PATTERN])
8801 return -EINVAL;
8802 pat_len = nla_len(pat_tb[NL80211_PKTPAT_PATTERN]);
8803 mask_len = DIV_ROUND_UP(pat_len, 8);
8804 if (nla_len(pat_tb[NL80211_PKTPAT_MASK]) != mask_len)
8805 return -EINVAL;
8806 if (pat_len > coalesce->pattern_max_len ||
8807 pat_len < coalesce->pattern_min_len)
8808 return -EINVAL;
8809
8810 if (!pat_tb[NL80211_PKTPAT_OFFSET])
8811 pkt_offset = 0;
8812 else
8813 pkt_offset = nla_get_u32(pat_tb[NL80211_PKTPAT_OFFSET]);
8814 if (pkt_offset > coalesce->max_pkt_offset)
8815 return -EINVAL;
8816 new_rule->patterns[i].pkt_offset = pkt_offset;
8817
Johannes Berg922bd802014-05-19 17:59:50 +02008818 mask_pat = kmalloc(mask_len + pat_len, GFP_KERNEL);
8819 if (!mask_pat)
Amitkumar Karwarbe29b992013-06-28 11:51:26 -07008820 return -ENOMEM;
Johannes Berg922bd802014-05-19 17:59:50 +02008821
8822 new_rule->patterns[i].mask = mask_pat;
8823 memcpy(mask_pat, nla_data(pat_tb[NL80211_PKTPAT_MASK]),
8824 mask_len);
8825
8826 mask_pat += mask_len;
8827 new_rule->patterns[i].pattern = mask_pat;
Amitkumar Karwarbe29b992013-06-28 11:51:26 -07008828 new_rule->patterns[i].pattern_len = pat_len;
Johannes Berg922bd802014-05-19 17:59:50 +02008829 memcpy(mask_pat, nla_data(pat_tb[NL80211_PKTPAT_PATTERN]),
8830 pat_len);
Amitkumar Karwarbe29b992013-06-28 11:51:26 -07008831 i++;
8832 }
8833
8834 return 0;
8835}
8836
8837static int nl80211_set_coalesce(struct sk_buff *skb, struct genl_info *info)
8838{
8839 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8840 const struct wiphy_coalesce_support *coalesce = rdev->wiphy.coalesce;
8841 struct cfg80211_coalesce new_coalesce = {};
8842 struct cfg80211_coalesce *n_coalesce;
8843 int err, rem_rule, n_rules = 0, i, j;
8844 struct nlattr *rule;
8845 struct cfg80211_coalesce_rules *tmp_rule;
8846
8847 if (!rdev->wiphy.coalesce || !rdev->ops->set_coalesce)
8848 return -EOPNOTSUPP;
8849
8850 if (!info->attrs[NL80211_ATTR_COALESCE_RULE]) {
8851 cfg80211_rdev_free_coalesce(rdev);
8852 rdev->ops->set_coalesce(&rdev->wiphy, NULL);
8853 return 0;
8854 }
8855
8856 nla_for_each_nested(rule, info->attrs[NL80211_ATTR_COALESCE_RULE],
8857 rem_rule)
8858 n_rules++;
8859 if (n_rules > coalesce->n_rules)
8860 return -EINVAL;
8861
8862 new_coalesce.rules = kcalloc(n_rules, sizeof(new_coalesce.rules[0]),
8863 GFP_KERNEL);
8864 if (!new_coalesce.rules)
8865 return -ENOMEM;
8866
8867 new_coalesce.n_rules = n_rules;
8868 i = 0;
8869
8870 nla_for_each_nested(rule, info->attrs[NL80211_ATTR_COALESCE_RULE],
8871 rem_rule) {
8872 err = nl80211_parse_coalesce_rule(rdev, rule,
8873 &new_coalesce.rules[i]);
8874 if (err)
8875 goto error;
8876
8877 i++;
8878 }
8879
8880 err = rdev->ops->set_coalesce(&rdev->wiphy, &new_coalesce);
8881 if (err)
8882 goto error;
8883
8884 n_coalesce = kmemdup(&new_coalesce, sizeof(new_coalesce), GFP_KERNEL);
8885 if (!n_coalesce) {
8886 err = -ENOMEM;
8887 goto error;
8888 }
8889 cfg80211_rdev_free_coalesce(rdev);
8890 rdev->coalesce = n_coalesce;
8891
8892 return 0;
8893error:
8894 for (i = 0; i < new_coalesce.n_rules; i++) {
8895 tmp_rule = &new_coalesce.rules[i];
8896 for (j = 0; j < tmp_rule->n_patterns; j++)
8897 kfree(tmp_rule->patterns[j].mask);
8898 kfree(tmp_rule->patterns);
8899 }
8900 kfree(new_coalesce.rules);
8901
8902 return err;
8903}
8904
Johannes Berge5497d72011-07-05 16:35:40 +02008905static int nl80211_set_rekey_data(struct sk_buff *skb, struct genl_info *info)
8906{
8907 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8908 struct net_device *dev = info->user_ptr[1];
8909 struct wireless_dev *wdev = dev->ieee80211_ptr;
8910 struct nlattr *tb[NUM_NL80211_REKEY_DATA];
8911 struct cfg80211_gtk_rekey_data rekey_data;
8912 int err;
8913
8914 if (!info->attrs[NL80211_ATTR_REKEY_DATA])
8915 return -EINVAL;
8916
8917 err = nla_parse(tb, MAX_NL80211_REKEY_DATA,
8918 nla_data(info->attrs[NL80211_ATTR_REKEY_DATA]),
8919 nla_len(info->attrs[NL80211_ATTR_REKEY_DATA]),
8920 nl80211_rekey_policy);
8921 if (err)
8922 return err;
8923
8924 if (nla_len(tb[NL80211_REKEY_DATA_REPLAY_CTR]) != NL80211_REPLAY_CTR_LEN)
8925 return -ERANGE;
8926 if (nla_len(tb[NL80211_REKEY_DATA_KEK]) != NL80211_KEK_LEN)
8927 return -ERANGE;
8928 if (nla_len(tb[NL80211_REKEY_DATA_KCK]) != NL80211_KCK_LEN)
8929 return -ERANGE;
8930
8931 memcpy(rekey_data.kek, nla_data(tb[NL80211_REKEY_DATA_KEK]),
8932 NL80211_KEK_LEN);
8933 memcpy(rekey_data.kck, nla_data(tb[NL80211_REKEY_DATA_KCK]),
8934 NL80211_KCK_LEN);
8935 memcpy(rekey_data.replay_ctr,
8936 nla_data(tb[NL80211_REKEY_DATA_REPLAY_CTR]),
8937 NL80211_REPLAY_CTR_LEN);
8938
8939 wdev_lock(wdev);
8940 if (!wdev->current_bss) {
8941 err = -ENOTCONN;
8942 goto out;
8943 }
8944
8945 if (!rdev->ops->set_rekey_data) {
8946 err = -EOPNOTSUPP;
8947 goto out;
8948 }
8949
Hila Gonene35e4d22012-06-27 17:19:42 +03008950 err = rdev_set_rekey_data(rdev, dev, &rekey_data);
Johannes Berge5497d72011-07-05 16:35:40 +02008951 out:
8952 wdev_unlock(wdev);
8953 return err;
8954}
8955
Johannes Berg28946da2011-11-04 11:18:12 +01008956static int nl80211_register_unexpected_frame(struct sk_buff *skb,
8957 struct genl_info *info)
8958{
8959 struct net_device *dev = info->user_ptr[1];
8960 struct wireless_dev *wdev = dev->ieee80211_ptr;
8961
8962 if (wdev->iftype != NL80211_IFTYPE_AP &&
8963 wdev->iftype != NL80211_IFTYPE_P2P_GO)
8964 return -EINVAL;
8965
Eric W. Biederman15e47302012-09-07 20:12:54 +00008966 if (wdev->ap_unexpected_nlportid)
Johannes Berg28946da2011-11-04 11:18:12 +01008967 return -EBUSY;
8968
Eric W. Biederman15e47302012-09-07 20:12:54 +00008969 wdev->ap_unexpected_nlportid = info->snd_portid;
Johannes Berg28946da2011-11-04 11:18:12 +01008970 return 0;
8971}
8972
Johannes Berg7f6cf312011-11-04 11:18:15 +01008973static int nl80211_probe_client(struct sk_buff *skb,
8974 struct genl_info *info)
8975{
8976 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8977 struct net_device *dev = info->user_ptr[1];
8978 struct wireless_dev *wdev = dev->ieee80211_ptr;
8979 struct sk_buff *msg;
8980 void *hdr;
8981 const u8 *addr;
8982 u64 cookie;
8983 int err;
8984
8985 if (wdev->iftype != NL80211_IFTYPE_AP &&
8986 wdev->iftype != NL80211_IFTYPE_P2P_GO)
8987 return -EOPNOTSUPP;
8988
8989 if (!info->attrs[NL80211_ATTR_MAC])
8990 return -EINVAL;
8991
8992 if (!rdev->ops->probe_client)
8993 return -EOPNOTSUPP;
8994
8995 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
8996 if (!msg)
8997 return -ENOMEM;
8998
Eric W. Biederman15e47302012-09-07 20:12:54 +00008999 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berg7f6cf312011-11-04 11:18:15 +01009000 NL80211_CMD_PROBE_CLIENT);
Dan Carpentercb35fba2013-08-14 14:50:01 +03009001 if (!hdr) {
9002 err = -ENOBUFS;
Johannes Berg7f6cf312011-11-04 11:18:15 +01009003 goto free_msg;
9004 }
9005
9006 addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
9007
Hila Gonene35e4d22012-06-27 17:19:42 +03009008 err = rdev_probe_client(rdev, dev, addr, &cookie);
Johannes Berg7f6cf312011-11-04 11:18:15 +01009009 if (err)
9010 goto free_msg;
9011
David S. Miller9360ffd2012-03-29 04:41:26 -04009012 if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie))
9013 goto nla_put_failure;
Johannes Berg7f6cf312011-11-04 11:18:15 +01009014
9015 genlmsg_end(msg, hdr);
9016
9017 return genlmsg_reply(msg, info);
9018
9019 nla_put_failure:
9020 err = -ENOBUFS;
9021 free_msg:
9022 nlmsg_free(msg);
9023 return err;
9024}
9025
Johannes Berg5e760232011-11-04 11:18:17 +01009026static int nl80211_register_beacons(struct sk_buff *skb, struct genl_info *info)
9027{
9028 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Ben Greear37c73b52012-10-26 14:49:25 -07009029 struct cfg80211_beacon_registration *reg, *nreg;
9030 int rv;
Johannes Berg5e760232011-11-04 11:18:17 +01009031
9032 if (!(rdev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS))
9033 return -EOPNOTSUPP;
9034
Ben Greear37c73b52012-10-26 14:49:25 -07009035 nreg = kzalloc(sizeof(*nreg), GFP_KERNEL);
9036 if (!nreg)
9037 return -ENOMEM;
Johannes Berg5e760232011-11-04 11:18:17 +01009038
Ben Greear37c73b52012-10-26 14:49:25 -07009039 /* First, check if already registered. */
9040 spin_lock_bh(&rdev->beacon_registrations_lock);
9041 list_for_each_entry(reg, &rdev->beacon_registrations, list) {
9042 if (reg->nlportid == info->snd_portid) {
9043 rv = -EALREADY;
9044 goto out_err;
9045 }
9046 }
9047 /* Add it to the list */
9048 nreg->nlportid = info->snd_portid;
9049 list_add(&nreg->list, &rdev->beacon_registrations);
9050
9051 spin_unlock_bh(&rdev->beacon_registrations_lock);
Johannes Berg5e760232011-11-04 11:18:17 +01009052
9053 return 0;
Ben Greear37c73b52012-10-26 14:49:25 -07009054out_err:
9055 spin_unlock_bh(&rdev->beacon_registrations_lock);
9056 kfree(nreg);
9057 return rv;
Johannes Berg5e760232011-11-04 11:18:17 +01009058}
9059
Johannes Berg98104fde2012-06-16 00:19:54 +02009060static int nl80211_start_p2p_device(struct sk_buff *skb, struct genl_info *info)
9061{
9062 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9063 struct wireless_dev *wdev = info->user_ptr[1];
9064 int err;
9065
9066 if (!rdev->ops->start_p2p_device)
9067 return -EOPNOTSUPP;
9068
9069 if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE)
9070 return -EOPNOTSUPP;
9071
9072 if (wdev->p2p_started)
9073 return 0;
9074
Luciano Coelhob6a55012014-02-27 11:07:21 +02009075 if (rfkill_blocked(rdev->rfkill))
9076 return -ERFKILL;
Johannes Berg98104fde2012-06-16 00:19:54 +02009077
Johannes Bergeeb126e2012-10-23 15:16:50 +02009078 err = rdev_start_p2p_device(rdev, wdev);
Johannes Berg98104fde2012-06-16 00:19:54 +02009079 if (err)
9080 return err;
9081
9082 wdev->p2p_started = true;
Johannes Berg98104fde2012-06-16 00:19:54 +02009083 rdev->opencount++;
Johannes Berg98104fde2012-06-16 00:19:54 +02009084
9085 return 0;
9086}
9087
9088static int nl80211_stop_p2p_device(struct sk_buff *skb, struct genl_info *info)
9089{
9090 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9091 struct wireless_dev *wdev = info->user_ptr[1];
9092
9093 if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE)
9094 return -EOPNOTSUPP;
9095
9096 if (!rdev->ops->stop_p2p_device)
9097 return -EOPNOTSUPP;
9098
Johannes Bergf9f47522013-03-19 15:04:07 +01009099 cfg80211_stop_p2p_device(rdev, wdev);
Johannes Berg98104fde2012-06-16 00:19:54 +02009100
9101 return 0;
9102}
9103
Johannes Berg3713b4e2013-02-14 16:19:38 +01009104static int nl80211_get_protocol_features(struct sk_buff *skb,
9105 struct genl_info *info)
9106{
9107 void *hdr;
9108 struct sk_buff *msg;
9109
9110 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
9111 if (!msg)
9112 return -ENOMEM;
9113
9114 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
9115 NL80211_CMD_GET_PROTOCOL_FEATURES);
9116 if (!hdr)
9117 goto nla_put_failure;
9118
9119 if (nla_put_u32(msg, NL80211_ATTR_PROTOCOL_FEATURES,
9120 NL80211_PROTOCOL_FEATURE_SPLIT_WIPHY_DUMP))
9121 goto nla_put_failure;
9122
9123 genlmsg_end(msg, hdr);
9124 return genlmsg_reply(msg, info);
9125
9126 nla_put_failure:
9127 kfree_skb(msg);
9128 return -ENOBUFS;
9129}
9130
Jouni Malinen355199e2013-02-27 17:14:27 +02009131static int nl80211_update_ft_ies(struct sk_buff *skb, struct genl_info *info)
9132{
9133 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9134 struct cfg80211_update_ft_ies_params ft_params;
9135 struct net_device *dev = info->user_ptr[1];
9136
9137 if (!rdev->ops->update_ft_ies)
9138 return -EOPNOTSUPP;
9139
9140 if (!info->attrs[NL80211_ATTR_MDID] ||
9141 !is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
9142 return -EINVAL;
9143
9144 memset(&ft_params, 0, sizeof(ft_params));
9145 ft_params.md = nla_get_u16(info->attrs[NL80211_ATTR_MDID]);
9146 ft_params.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
9147 ft_params.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
9148
9149 return rdev_update_ft_ies(rdev, dev, &ft_params);
9150}
9151
Arend van Spriel5de17982013-04-18 15:49:00 +02009152static int nl80211_crit_protocol_start(struct sk_buff *skb,
9153 struct genl_info *info)
9154{
9155 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9156 struct wireless_dev *wdev = info->user_ptr[1];
9157 enum nl80211_crit_proto_id proto = NL80211_CRIT_PROTO_UNSPEC;
9158 u16 duration;
9159 int ret;
9160
9161 if (!rdev->ops->crit_proto_start)
9162 return -EOPNOTSUPP;
9163
9164 if (WARN_ON(!rdev->ops->crit_proto_stop))
9165 return -EINVAL;
9166
9167 if (rdev->crit_proto_nlportid)
9168 return -EBUSY;
9169
9170 /* determine protocol if provided */
9171 if (info->attrs[NL80211_ATTR_CRIT_PROT_ID])
9172 proto = nla_get_u16(info->attrs[NL80211_ATTR_CRIT_PROT_ID]);
9173
9174 if (proto >= NUM_NL80211_CRIT_PROTO)
9175 return -EINVAL;
9176
9177 /* timeout must be provided */
9178 if (!info->attrs[NL80211_ATTR_MAX_CRIT_PROT_DURATION])
9179 return -EINVAL;
9180
9181 duration =
9182 nla_get_u16(info->attrs[NL80211_ATTR_MAX_CRIT_PROT_DURATION]);
9183
9184 if (duration > NL80211_CRIT_PROTO_MAX_DURATION)
9185 return -ERANGE;
9186
9187 ret = rdev_crit_proto_start(rdev, wdev, proto, duration);
9188 if (!ret)
9189 rdev->crit_proto_nlportid = info->snd_portid;
9190
9191 return ret;
9192}
9193
9194static int nl80211_crit_protocol_stop(struct sk_buff *skb,
9195 struct genl_info *info)
9196{
9197 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9198 struct wireless_dev *wdev = info->user_ptr[1];
9199
9200 if (!rdev->ops->crit_proto_stop)
9201 return -EOPNOTSUPP;
9202
9203 if (rdev->crit_proto_nlportid) {
9204 rdev->crit_proto_nlportid = 0;
9205 rdev_crit_proto_stop(rdev, wdev);
9206 }
9207 return 0;
9208}
9209
Johannes Bergad7e7182013-11-13 13:37:47 +01009210static int nl80211_vendor_cmd(struct sk_buff *skb, struct genl_info *info)
9211{
9212 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9213 struct wireless_dev *wdev =
9214 __cfg80211_wdev_from_attrs(genl_info_net(info), info->attrs);
9215 int i, err;
9216 u32 vid, subcmd;
9217
9218 if (!rdev->wiphy.vendor_commands)
9219 return -EOPNOTSUPP;
9220
9221 if (IS_ERR(wdev)) {
9222 err = PTR_ERR(wdev);
9223 if (err != -EINVAL)
9224 return err;
9225 wdev = NULL;
9226 } else if (wdev->wiphy != &rdev->wiphy) {
9227 return -EINVAL;
9228 }
9229
9230 if (!info->attrs[NL80211_ATTR_VENDOR_ID] ||
9231 !info->attrs[NL80211_ATTR_VENDOR_SUBCMD])
9232 return -EINVAL;
9233
9234 vid = nla_get_u32(info->attrs[NL80211_ATTR_VENDOR_ID]);
9235 subcmd = nla_get_u32(info->attrs[NL80211_ATTR_VENDOR_SUBCMD]);
9236 for (i = 0; i < rdev->wiphy.n_vendor_commands; i++) {
9237 const struct wiphy_vendor_command *vcmd;
9238 void *data = NULL;
9239 int len = 0;
9240
9241 vcmd = &rdev->wiphy.vendor_commands[i];
9242
9243 if (vcmd->info.vendor_id != vid || vcmd->info.subcmd != subcmd)
9244 continue;
9245
9246 if (vcmd->flags & (WIPHY_VENDOR_CMD_NEED_WDEV |
9247 WIPHY_VENDOR_CMD_NEED_NETDEV)) {
9248 if (!wdev)
9249 return -EINVAL;
9250 if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_NETDEV &&
9251 !wdev->netdev)
9252 return -EINVAL;
9253
9254 if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_RUNNING) {
9255 if (wdev->netdev &&
9256 !netif_running(wdev->netdev))
9257 return -ENETDOWN;
9258 if (!wdev->netdev && !wdev->p2p_started)
9259 return -ENETDOWN;
9260 }
9261 } else {
9262 wdev = NULL;
9263 }
9264
9265 if (info->attrs[NL80211_ATTR_VENDOR_DATA]) {
9266 data = nla_data(info->attrs[NL80211_ATTR_VENDOR_DATA]);
9267 len = nla_len(info->attrs[NL80211_ATTR_VENDOR_DATA]);
9268 }
9269
9270 rdev->cur_cmd_info = info;
9271 err = rdev->wiphy.vendor_commands[i].doit(&rdev->wiphy, wdev,
9272 data, len);
9273 rdev->cur_cmd_info = NULL;
9274 return err;
9275 }
9276
9277 return -EOPNOTSUPP;
9278}
9279
9280struct sk_buff *__cfg80211_alloc_reply_skb(struct wiphy *wiphy,
9281 enum nl80211_commands cmd,
9282 enum nl80211_attrs attr,
9283 int approxlen)
9284{
Zhao, Gangf26cbf42014-04-21 12:53:03 +08009285 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Bergad7e7182013-11-13 13:37:47 +01009286
9287 if (WARN_ON(!rdev->cur_cmd_info))
9288 return NULL;
9289
9290 return __cfg80211_alloc_vendor_skb(rdev, approxlen,
9291 rdev->cur_cmd_info->snd_portid,
9292 rdev->cur_cmd_info->snd_seq,
Johannes Berg567ffc32013-12-18 14:43:31 +01009293 cmd, attr, NULL, GFP_KERNEL);
Johannes Bergad7e7182013-11-13 13:37:47 +01009294}
9295EXPORT_SYMBOL(__cfg80211_alloc_reply_skb);
9296
9297int cfg80211_vendor_cmd_reply(struct sk_buff *skb)
9298{
9299 struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0];
9300 void *hdr = ((void **)skb->cb)[1];
9301 struct nlattr *data = ((void **)skb->cb)[2];
9302
9303 if (WARN_ON(!rdev->cur_cmd_info)) {
9304 kfree_skb(skb);
9305 return -EINVAL;
9306 }
9307
9308 nla_nest_end(skb, data);
9309 genlmsg_end(skb, hdr);
9310 return genlmsg_reply(skb, rdev->cur_cmd_info);
9311}
9312EXPORT_SYMBOL_GPL(cfg80211_vendor_cmd_reply);
9313
9314
Kyeyoon Parkfa9ffc72013-12-16 23:01:30 -08009315static int nl80211_set_qos_map(struct sk_buff *skb,
9316 struct genl_info *info)
9317{
9318 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9319 struct cfg80211_qos_map *qos_map = NULL;
9320 struct net_device *dev = info->user_ptr[1];
9321 u8 *pos, len, num_des, des_len, des;
9322 int ret;
9323
9324 if (!rdev->ops->set_qos_map)
9325 return -EOPNOTSUPP;
9326
9327 if (info->attrs[NL80211_ATTR_QOS_MAP]) {
9328 pos = nla_data(info->attrs[NL80211_ATTR_QOS_MAP]);
9329 len = nla_len(info->attrs[NL80211_ATTR_QOS_MAP]);
9330
9331 if (len % 2 || len < IEEE80211_QOS_MAP_LEN_MIN ||
9332 len > IEEE80211_QOS_MAP_LEN_MAX)
9333 return -EINVAL;
9334
9335 qos_map = kzalloc(sizeof(struct cfg80211_qos_map), GFP_KERNEL);
9336 if (!qos_map)
9337 return -ENOMEM;
9338
9339 num_des = (len - IEEE80211_QOS_MAP_LEN_MIN) >> 1;
9340 if (num_des) {
9341 des_len = num_des *
9342 sizeof(struct cfg80211_dscp_exception);
9343 memcpy(qos_map->dscp_exception, pos, des_len);
9344 qos_map->num_des = num_des;
9345 for (des = 0; des < num_des; des++) {
9346 if (qos_map->dscp_exception[des].up > 7) {
9347 kfree(qos_map);
9348 return -EINVAL;
9349 }
9350 }
9351 pos += des_len;
9352 }
9353 memcpy(qos_map->up, pos, IEEE80211_QOS_MAP_LEN_MIN);
9354 }
9355
9356 wdev_lock(dev->ieee80211_ptr);
9357 ret = nl80211_key_allowed(dev->ieee80211_ptr);
9358 if (!ret)
9359 ret = rdev_set_qos_map(rdev, dev, qos_map);
9360 wdev_unlock(dev->ieee80211_ptr);
9361
9362 kfree(qos_map);
9363 return ret;
9364}
9365
Johannes Berg4c476992010-10-04 21:36:35 +02009366#define NL80211_FLAG_NEED_WIPHY 0x01
9367#define NL80211_FLAG_NEED_NETDEV 0x02
9368#define NL80211_FLAG_NEED_RTNL 0x04
Johannes Berg41265712010-10-04 21:14:05 +02009369#define NL80211_FLAG_CHECK_NETDEV_UP 0x08
9370#define NL80211_FLAG_NEED_NETDEV_UP (NL80211_FLAG_NEED_NETDEV |\
9371 NL80211_FLAG_CHECK_NETDEV_UP)
Johannes Berg1bf614e2012-06-15 15:23:36 +02009372#define NL80211_FLAG_NEED_WDEV 0x10
Johannes Berg98104fde2012-06-16 00:19:54 +02009373/* If a netdev is associated, it must be UP, P2P must be started */
Johannes Berg1bf614e2012-06-15 15:23:36 +02009374#define NL80211_FLAG_NEED_WDEV_UP (NL80211_FLAG_NEED_WDEV |\
9375 NL80211_FLAG_CHECK_NETDEV_UP)
Johannes Berg4c476992010-10-04 21:36:35 +02009376
Johannes Bergf84f7712013-11-14 17:14:45 +01009377static int nl80211_pre_doit(const struct genl_ops *ops, struct sk_buff *skb,
Johannes Berg4c476992010-10-04 21:36:35 +02009378 struct genl_info *info)
9379{
9380 struct cfg80211_registered_device *rdev;
Johannes Berg89a54e42012-06-15 14:33:17 +02009381 struct wireless_dev *wdev;
Johannes Berg4c476992010-10-04 21:36:35 +02009382 struct net_device *dev;
Johannes Berg4c476992010-10-04 21:36:35 +02009383 bool rtnl = ops->internal_flags & NL80211_FLAG_NEED_RTNL;
9384
9385 if (rtnl)
9386 rtnl_lock();
9387
9388 if (ops->internal_flags & NL80211_FLAG_NEED_WIPHY) {
Johannes Berg4f7eff12012-06-15 14:14:22 +02009389 rdev = cfg80211_get_dev_from_info(genl_info_net(info), info);
Johannes Berg4c476992010-10-04 21:36:35 +02009390 if (IS_ERR(rdev)) {
9391 if (rtnl)
9392 rtnl_unlock();
9393 return PTR_ERR(rdev);
9394 }
9395 info->user_ptr[0] = rdev;
Johannes Berg1bf614e2012-06-15 15:23:36 +02009396 } else if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV ||
9397 ops->internal_flags & NL80211_FLAG_NEED_WDEV) {
Johannes Berg5fe231e2013-05-08 21:45:15 +02009398 ASSERT_RTNL();
9399
Johannes Berg89a54e42012-06-15 14:33:17 +02009400 wdev = __cfg80211_wdev_from_attrs(genl_info_net(info),
9401 info->attrs);
9402 if (IS_ERR(wdev)) {
Johannes Berg4c476992010-10-04 21:36:35 +02009403 if (rtnl)
9404 rtnl_unlock();
Johannes Berg89a54e42012-06-15 14:33:17 +02009405 return PTR_ERR(wdev);
Johannes Berg4c476992010-10-04 21:36:35 +02009406 }
Johannes Berg89a54e42012-06-15 14:33:17 +02009407
Johannes Berg89a54e42012-06-15 14:33:17 +02009408 dev = wdev->netdev;
Zhao, Gangf26cbf42014-04-21 12:53:03 +08009409 rdev = wiphy_to_rdev(wdev->wiphy);
Johannes Berg89a54e42012-06-15 14:33:17 +02009410
Johannes Berg1bf614e2012-06-15 15:23:36 +02009411 if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV) {
9412 if (!dev) {
Johannes Berg1bf614e2012-06-15 15:23:36 +02009413 if (rtnl)
9414 rtnl_unlock();
9415 return -EINVAL;
9416 }
9417
9418 info->user_ptr[1] = dev;
9419 } else {
9420 info->user_ptr[1] = wdev;
Johannes Berg41265712010-10-04 21:14:05 +02009421 }
Johannes Berg89a54e42012-06-15 14:33:17 +02009422
Johannes Berg1bf614e2012-06-15 15:23:36 +02009423 if (dev) {
9424 if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP &&
9425 !netif_running(dev)) {
Johannes Berg1bf614e2012-06-15 15:23:36 +02009426 if (rtnl)
9427 rtnl_unlock();
9428 return -ENETDOWN;
9429 }
9430
9431 dev_hold(dev);
Johannes Berg98104fde2012-06-16 00:19:54 +02009432 } else if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP) {
9433 if (!wdev->p2p_started) {
Johannes Berg98104fde2012-06-16 00:19:54 +02009434 if (rtnl)
9435 rtnl_unlock();
9436 return -ENETDOWN;
9437 }
Johannes Berg1bf614e2012-06-15 15:23:36 +02009438 }
9439
Johannes Berg4c476992010-10-04 21:36:35 +02009440 info->user_ptr[0] = rdev;
Johannes Berg4c476992010-10-04 21:36:35 +02009441 }
9442
9443 return 0;
9444}
9445
Johannes Bergf84f7712013-11-14 17:14:45 +01009446static void nl80211_post_doit(const struct genl_ops *ops, struct sk_buff *skb,
Johannes Berg4c476992010-10-04 21:36:35 +02009447 struct genl_info *info)
9448{
Johannes Berg1bf614e2012-06-15 15:23:36 +02009449 if (info->user_ptr[1]) {
9450 if (ops->internal_flags & NL80211_FLAG_NEED_WDEV) {
9451 struct wireless_dev *wdev = info->user_ptr[1];
9452
9453 if (wdev->netdev)
9454 dev_put(wdev->netdev);
9455 } else {
9456 dev_put(info->user_ptr[1]);
9457 }
9458 }
Johannes Berg4c476992010-10-04 21:36:35 +02009459 if (ops->internal_flags & NL80211_FLAG_NEED_RTNL)
9460 rtnl_unlock();
9461}
9462
Johannes Berg4534de82013-11-14 17:14:46 +01009463static const struct genl_ops nl80211_ops[] = {
Johannes Berg55682962007-09-20 13:09:35 -04009464 {
9465 .cmd = NL80211_CMD_GET_WIPHY,
9466 .doit = nl80211_get_wiphy,
9467 .dumpit = nl80211_dump_wiphy,
Johannes Berg86e8cf92013-06-19 10:57:22 +02009468 .done = nl80211_dump_wiphy_done,
Johannes Berg55682962007-09-20 13:09:35 -04009469 .policy = nl80211_policy,
9470 /* can be retrieved by unprivileged users */
Johannes Berg5fe231e2013-05-08 21:45:15 +02009471 .internal_flags = NL80211_FLAG_NEED_WIPHY |
9472 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -04009473 },
9474 {
9475 .cmd = NL80211_CMD_SET_WIPHY,
9476 .doit = nl80211_set_wiphy,
9477 .policy = nl80211_policy,
9478 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02009479 .internal_flags = NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -04009480 },
9481 {
9482 .cmd = NL80211_CMD_GET_INTERFACE,
9483 .doit = nl80211_get_interface,
9484 .dumpit = nl80211_dump_interface,
9485 .policy = nl80211_policy,
9486 /* can be retrieved by unprivileged users */
Johannes Berg5fe231e2013-05-08 21:45:15 +02009487 .internal_flags = NL80211_FLAG_NEED_WDEV |
9488 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -04009489 },
9490 {
9491 .cmd = NL80211_CMD_SET_INTERFACE,
9492 .doit = nl80211_set_interface,
9493 .policy = nl80211_policy,
9494 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02009495 .internal_flags = NL80211_FLAG_NEED_NETDEV |
9496 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -04009497 },
9498 {
9499 .cmd = NL80211_CMD_NEW_INTERFACE,
9500 .doit = nl80211_new_interface,
9501 .policy = nl80211_policy,
9502 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02009503 .internal_flags = NL80211_FLAG_NEED_WIPHY |
9504 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -04009505 },
9506 {
9507 .cmd = NL80211_CMD_DEL_INTERFACE,
9508 .doit = nl80211_del_interface,
9509 .policy = nl80211_policy,
9510 .flags = GENL_ADMIN_PERM,
Johannes Berg84efbb82012-06-16 00:00:26 +02009511 .internal_flags = NL80211_FLAG_NEED_WDEV |
Johannes Berg4c476992010-10-04 21:36:35 +02009512 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -04009513 },
Johannes Berg41ade002007-12-19 02:03:29 +01009514 {
9515 .cmd = NL80211_CMD_GET_KEY,
9516 .doit = nl80211_get_key,
9517 .policy = nl80211_policy,
9518 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02009519 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009520 NL80211_FLAG_NEED_RTNL,
Johannes Berg41ade002007-12-19 02:03:29 +01009521 },
9522 {
9523 .cmd = NL80211_CMD_SET_KEY,
9524 .doit = nl80211_set_key,
9525 .policy = nl80211_policy,
9526 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02009527 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009528 NL80211_FLAG_NEED_RTNL,
Johannes Berg41ade002007-12-19 02:03:29 +01009529 },
9530 {
9531 .cmd = NL80211_CMD_NEW_KEY,
9532 .doit = nl80211_new_key,
9533 .policy = nl80211_policy,
9534 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02009535 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009536 NL80211_FLAG_NEED_RTNL,
Johannes Berg41ade002007-12-19 02:03:29 +01009537 },
9538 {
9539 .cmd = NL80211_CMD_DEL_KEY,
9540 .doit = nl80211_del_key,
9541 .policy = nl80211_policy,
9542 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02009543 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009544 NL80211_FLAG_NEED_RTNL,
Johannes Berg41ade002007-12-19 02:03:29 +01009545 },
Johannes Berged1b6cc2007-12-19 02:03:32 +01009546 {
9547 .cmd = NL80211_CMD_SET_BEACON,
9548 .policy = nl80211_policy,
9549 .flags = GENL_ADMIN_PERM,
Johannes Berg88600202012-02-13 15:17:18 +01009550 .doit = nl80211_set_beacon,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02009551 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009552 NL80211_FLAG_NEED_RTNL,
Johannes Berged1b6cc2007-12-19 02:03:32 +01009553 },
9554 {
Johannes Berg88600202012-02-13 15:17:18 +01009555 .cmd = NL80211_CMD_START_AP,
Johannes Berged1b6cc2007-12-19 02:03:32 +01009556 .policy = nl80211_policy,
9557 .flags = GENL_ADMIN_PERM,
Johannes Berg88600202012-02-13 15:17:18 +01009558 .doit = nl80211_start_ap,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02009559 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009560 NL80211_FLAG_NEED_RTNL,
Johannes Berged1b6cc2007-12-19 02:03:32 +01009561 },
9562 {
Johannes Berg88600202012-02-13 15:17:18 +01009563 .cmd = NL80211_CMD_STOP_AP,
Johannes Berged1b6cc2007-12-19 02:03:32 +01009564 .policy = nl80211_policy,
9565 .flags = GENL_ADMIN_PERM,
Johannes Berg88600202012-02-13 15:17:18 +01009566 .doit = nl80211_stop_ap,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02009567 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009568 NL80211_FLAG_NEED_RTNL,
Johannes Berged1b6cc2007-12-19 02:03:32 +01009569 },
Johannes Berg5727ef12007-12-19 02:03:34 +01009570 {
9571 .cmd = NL80211_CMD_GET_STATION,
9572 .doit = nl80211_get_station,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01009573 .dumpit = nl80211_dump_station,
Johannes Berg5727ef12007-12-19 02:03:34 +01009574 .policy = nl80211_policy,
Johannes Berg4c476992010-10-04 21:36:35 +02009575 .internal_flags = NL80211_FLAG_NEED_NETDEV |
9576 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +01009577 },
9578 {
9579 .cmd = NL80211_CMD_SET_STATION,
9580 .doit = nl80211_set_station,
9581 .policy = nl80211_policy,
9582 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02009583 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009584 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +01009585 },
9586 {
9587 .cmd = NL80211_CMD_NEW_STATION,
9588 .doit = nl80211_new_station,
9589 .policy = nl80211_policy,
9590 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02009591 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009592 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +01009593 },
9594 {
9595 .cmd = NL80211_CMD_DEL_STATION,
9596 .doit = nl80211_del_station,
9597 .policy = nl80211_policy,
9598 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02009599 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009600 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +01009601 },
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01009602 {
9603 .cmd = NL80211_CMD_GET_MPATH,
9604 .doit = nl80211_get_mpath,
9605 .dumpit = nl80211_dump_mpath,
9606 .policy = nl80211_policy,
9607 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02009608 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009609 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01009610 },
9611 {
9612 .cmd = NL80211_CMD_SET_MPATH,
9613 .doit = nl80211_set_mpath,
9614 .policy = nl80211_policy,
9615 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02009616 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009617 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01009618 },
9619 {
9620 .cmd = NL80211_CMD_NEW_MPATH,
9621 .doit = nl80211_new_mpath,
9622 .policy = nl80211_policy,
9623 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02009624 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009625 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01009626 },
9627 {
9628 .cmd = NL80211_CMD_DEL_MPATH,
9629 .doit = nl80211_del_mpath,
9630 .policy = nl80211_policy,
9631 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02009632 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009633 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01009634 },
Jouni Malinen9f1ba902008-08-07 20:07:01 +03009635 {
9636 .cmd = NL80211_CMD_SET_BSS,
9637 .doit = nl80211_set_bss,
9638 .policy = nl80211_policy,
9639 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02009640 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009641 NL80211_FLAG_NEED_RTNL,
Jouni Malinen9f1ba902008-08-07 20:07:01 +03009642 },
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07009643 {
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08009644 .cmd = NL80211_CMD_GET_REG,
9645 .doit = nl80211_get_reg,
9646 .policy = nl80211_policy,
Johannes Berg5fe231e2013-05-08 21:45:15 +02009647 .internal_flags = NL80211_FLAG_NEED_RTNL,
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08009648 /* can be retrieved by unprivileged users */
9649 },
9650 {
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07009651 .cmd = NL80211_CMD_SET_REG,
9652 .doit = nl80211_set_reg,
9653 .policy = nl80211_policy,
9654 .flags = GENL_ADMIN_PERM,
Johannes Berg5fe231e2013-05-08 21:45:15 +02009655 .internal_flags = NL80211_FLAG_NEED_RTNL,
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07009656 },
9657 {
9658 .cmd = NL80211_CMD_REQ_SET_REG,
9659 .doit = nl80211_req_set_reg,
9660 .policy = nl80211_policy,
9661 .flags = GENL_ADMIN_PERM,
9662 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07009663 {
Javier Cardona24bdd9f2010-12-16 17:37:48 -08009664 .cmd = NL80211_CMD_GET_MESH_CONFIG,
9665 .doit = nl80211_get_mesh_config,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07009666 .policy = nl80211_policy,
9667 /* can be retrieved by unprivileged users */
Johannes Berg2b5f8b02012-04-02 10:51:55 +02009668 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009669 NL80211_FLAG_NEED_RTNL,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07009670 },
9671 {
Javier Cardona24bdd9f2010-12-16 17:37:48 -08009672 .cmd = NL80211_CMD_SET_MESH_CONFIG,
9673 .doit = nl80211_update_mesh_config,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07009674 .policy = nl80211_policy,
9675 .flags = GENL_ADMIN_PERM,
Johannes Berg29cbe682010-12-03 09:20:44 +01009676 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009677 NL80211_FLAG_NEED_RTNL,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07009678 },
Jouni Malinen9aed3cc2009-01-13 16:03:29 +02009679 {
Johannes Berg2a519312009-02-10 21:25:55 +01009680 .cmd = NL80211_CMD_TRIGGER_SCAN,
9681 .doit = nl80211_trigger_scan,
9682 .policy = nl80211_policy,
9683 .flags = GENL_ADMIN_PERM,
Johannes Bergfd014282012-06-18 19:17:03 +02009684 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009685 NL80211_FLAG_NEED_RTNL,
Johannes Berg2a519312009-02-10 21:25:55 +01009686 },
9687 {
9688 .cmd = NL80211_CMD_GET_SCAN,
9689 .policy = nl80211_policy,
9690 .dumpit = nl80211_dump_scan,
9691 },
Jouni Malinen636a5d32009-03-19 13:39:22 +02009692 {
Luciano Coelho807f8a82011-05-11 17:09:35 +03009693 .cmd = NL80211_CMD_START_SCHED_SCAN,
9694 .doit = nl80211_start_sched_scan,
9695 .policy = nl80211_policy,
9696 .flags = GENL_ADMIN_PERM,
9697 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
9698 NL80211_FLAG_NEED_RTNL,
9699 },
9700 {
9701 .cmd = NL80211_CMD_STOP_SCHED_SCAN,
9702 .doit = nl80211_stop_sched_scan,
9703 .policy = nl80211_policy,
9704 .flags = GENL_ADMIN_PERM,
9705 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
9706 NL80211_FLAG_NEED_RTNL,
9707 },
9708 {
Jouni Malinen636a5d32009-03-19 13:39:22 +02009709 .cmd = NL80211_CMD_AUTHENTICATE,
9710 .doit = nl80211_authenticate,
9711 .policy = nl80211_policy,
9712 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02009713 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009714 NL80211_FLAG_NEED_RTNL,
Jouni Malinen636a5d32009-03-19 13:39:22 +02009715 },
9716 {
9717 .cmd = NL80211_CMD_ASSOCIATE,
9718 .doit = nl80211_associate,
9719 .policy = nl80211_policy,
9720 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02009721 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009722 NL80211_FLAG_NEED_RTNL,
Jouni Malinen636a5d32009-03-19 13:39:22 +02009723 },
9724 {
9725 .cmd = NL80211_CMD_DEAUTHENTICATE,
9726 .doit = nl80211_deauthenticate,
9727 .policy = nl80211_policy,
9728 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02009729 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009730 NL80211_FLAG_NEED_RTNL,
Jouni Malinen636a5d32009-03-19 13:39:22 +02009731 },
9732 {
9733 .cmd = NL80211_CMD_DISASSOCIATE,
9734 .doit = nl80211_disassociate,
9735 .policy = nl80211_policy,
9736 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02009737 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009738 NL80211_FLAG_NEED_RTNL,
Jouni Malinen636a5d32009-03-19 13:39:22 +02009739 },
Johannes Berg04a773a2009-04-19 21:24:32 +02009740 {
9741 .cmd = NL80211_CMD_JOIN_IBSS,
9742 .doit = nl80211_join_ibss,
9743 .policy = nl80211_policy,
9744 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02009745 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009746 NL80211_FLAG_NEED_RTNL,
Johannes Berg04a773a2009-04-19 21:24:32 +02009747 },
9748 {
9749 .cmd = NL80211_CMD_LEAVE_IBSS,
9750 .doit = nl80211_leave_ibss,
9751 .policy = nl80211_policy,
9752 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02009753 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009754 NL80211_FLAG_NEED_RTNL,
Johannes Berg04a773a2009-04-19 21:24:32 +02009755 },
Johannes Bergaff89a92009-07-01 21:26:51 +02009756#ifdef CONFIG_NL80211_TESTMODE
9757 {
9758 .cmd = NL80211_CMD_TESTMODE,
9759 .doit = nl80211_testmode_do,
Wey-Yi Guy71063f02011-05-20 09:05:54 -07009760 .dumpit = nl80211_testmode_dump,
Johannes Bergaff89a92009-07-01 21:26:51 +02009761 .policy = nl80211_policy,
9762 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02009763 .internal_flags = NL80211_FLAG_NEED_WIPHY |
9764 NL80211_FLAG_NEED_RTNL,
Johannes Bergaff89a92009-07-01 21:26:51 +02009765 },
9766#endif
Samuel Ortizb23aa672009-07-01 21:26:54 +02009767 {
9768 .cmd = NL80211_CMD_CONNECT,
9769 .doit = nl80211_connect,
9770 .policy = nl80211_policy,
9771 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02009772 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009773 NL80211_FLAG_NEED_RTNL,
Samuel Ortizb23aa672009-07-01 21:26:54 +02009774 },
9775 {
9776 .cmd = NL80211_CMD_DISCONNECT,
9777 .doit = nl80211_disconnect,
9778 .policy = nl80211_policy,
9779 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02009780 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009781 NL80211_FLAG_NEED_RTNL,
Samuel Ortizb23aa672009-07-01 21:26:54 +02009782 },
Johannes Berg463d0182009-07-14 00:33:35 +02009783 {
9784 .cmd = NL80211_CMD_SET_WIPHY_NETNS,
9785 .doit = nl80211_wiphy_netns,
9786 .policy = nl80211_policy,
9787 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02009788 .internal_flags = NL80211_FLAG_NEED_WIPHY |
9789 NL80211_FLAG_NEED_RTNL,
Johannes Berg463d0182009-07-14 00:33:35 +02009790 },
Holger Schurig61fa7132009-11-11 12:25:40 +01009791 {
9792 .cmd = NL80211_CMD_GET_SURVEY,
9793 .policy = nl80211_policy,
9794 .dumpit = nl80211_dump_survey,
9795 },
Samuel Ortiz67fbb162009-11-24 23:59:15 +01009796 {
9797 .cmd = NL80211_CMD_SET_PMKSA,
9798 .doit = nl80211_setdel_pmksa,
9799 .policy = nl80211_policy,
9800 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02009801 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009802 NL80211_FLAG_NEED_RTNL,
Samuel Ortiz67fbb162009-11-24 23:59:15 +01009803 },
9804 {
9805 .cmd = NL80211_CMD_DEL_PMKSA,
9806 .doit = nl80211_setdel_pmksa,
9807 .policy = nl80211_policy,
9808 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02009809 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009810 NL80211_FLAG_NEED_RTNL,
Samuel Ortiz67fbb162009-11-24 23:59:15 +01009811 },
9812 {
9813 .cmd = NL80211_CMD_FLUSH_PMKSA,
9814 .doit = nl80211_flush_pmksa,
9815 .policy = nl80211_policy,
9816 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02009817 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009818 NL80211_FLAG_NEED_RTNL,
Samuel Ortiz67fbb162009-11-24 23:59:15 +01009819 },
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009820 {
9821 .cmd = NL80211_CMD_REMAIN_ON_CHANNEL,
9822 .doit = nl80211_remain_on_channel,
9823 .policy = nl80211_policy,
9824 .flags = GENL_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +02009825 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009826 NL80211_FLAG_NEED_RTNL,
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009827 },
9828 {
9829 .cmd = NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL,
9830 .doit = nl80211_cancel_remain_on_channel,
9831 .policy = nl80211_policy,
9832 .flags = GENL_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +02009833 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009834 NL80211_FLAG_NEED_RTNL,
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009835 },
Jouni Malinen13ae75b2009-12-29 12:59:45 +02009836 {
9837 .cmd = NL80211_CMD_SET_TX_BITRATE_MASK,
9838 .doit = nl80211_set_tx_bitrate_mask,
9839 .policy = nl80211_policy,
9840 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02009841 .internal_flags = NL80211_FLAG_NEED_NETDEV |
9842 NL80211_FLAG_NEED_RTNL,
Jouni Malinen13ae75b2009-12-29 12:59:45 +02009843 },
Jouni Malinen026331c2010-02-15 12:53:10 +02009844 {
Johannes Berg2e161f72010-08-12 15:38:38 +02009845 .cmd = NL80211_CMD_REGISTER_FRAME,
9846 .doit = nl80211_register_mgmt,
Jouni Malinen026331c2010-02-15 12:53:10 +02009847 .policy = nl80211_policy,
9848 .flags = GENL_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +02009849 .internal_flags = NL80211_FLAG_NEED_WDEV |
Johannes Berg4c476992010-10-04 21:36:35 +02009850 NL80211_FLAG_NEED_RTNL,
Jouni Malinen026331c2010-02-15 12:53:10 +02009851 },
9852 {
Johannes Berg2e161f72010-08-12 15:38:38 +02009853 .cmd = NL80211_CMD_FRAME,
9854 .doit = nl80211_tx_mgmt,
Jouni Malinen026331c2010-02-15 12:53:10 +02009855 .policy = nl80211_policy,
9856 .flags = GENL_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +02009857 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009858 NL80211_FLAG_NEED_RTNL,
Jouni Malinen026331c2010-02-15 12:53:10 +02009859 },
Kalle Valoffb9eb32010-02-17 17:58:10 +02009860 {
Johannes Bergf7ca38d2010-11-25 10:02:29 +01009861 .cmd = NL80211_CMD_FRAME_WAIT_CANCEL,
9862 .doit = nl80211_tx_mgmt_cancel_wait,
9863 .policy = nl80211_policy,
9864 .flags = GENL_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +02009865 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Bergf7ca38d2010-11-25 10:02:29 +01009866 NL80211_FLAG_NEED_RTNL,
9867 },
9868 {
Kalle Valoffb9eb32010-02-17 17:58:10 +02009869 .cmd = NL80211_CMD_SET_POWER_SAVE,
9870 .doit = nl80211_set_power_save,
9871 .policy = nl80211_policy,
9872 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02009873 .internal_flags = NL80211_FLAG_NEED_NETDEV |
9874 NL80211_FLAG_NEED_RTNL,
Kalle Valoffb9eb32010-02-17 17:58:10 +02009875 },
9876 {
9877 .cmd = NL80211_CMD_GET_POWER_SAVE,
9878 .doit = nl80211_get_power_save,
9879 .policy = nl80211_policy,
9880 /* can be retrieved by unprivileged users */
Johannes Berg4c476992010-10-04 21:36:35 +02009881 .internal_flags = NL80211_FLAG_NEED_NETDEV |
9882 NL80211_FLAG_NEED_RTNL,
Kalle Valoffb9eb32010-02-17 17:58:10 +02009883 },
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02009884 {
9885 .cmd = NL80211_CMD_SET_CQM,
9886 .doit = nl80211_set_cqm,
9887 .policy = nl80211_policy,
9888 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02009889 .internal_flags = NL80211_FLAG_NEED_NETDEV |
9890 NL80211_FLAG_NEED_RTNL,
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02009891 },
Johannes Bergf444de02010-05-05 15:25:02 +02009892 {
9893 .cmd = NL80211_CMD_SET_CHANNEL,
9894 .doit = nl80211_set_channel,
9895 .policy = nl80211_policy,
9896 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02009897 .internal_flags = NL80211_FLAG_NEED_NETDEV |
9898 NL80211_FLAG_NEED_RTNL,
Johannes Bergf444de02010-05-05 15:25:02 +02009899 },
Bill Jordane8347eb2010-10-01 13:54:28 -04009900 {
9901 .cmd = NL80211_CMD_SET_WDS_PEER,
9902 .doit = nl80211_set_wds_peer,
9903 .policy = nl80211_policy,
9904 .flags = GENL_ADMIN_PERM,
Johannes Berg43b19952010-10-07 13:10:30 +02009905 .internal_flags = NL80211_FLAG_NEED_NETDEV |
9906 NL80211_FLAG_NEED_RTNL,
Bill Jordane8347eb2010-10-01 13:54:28 -04009907 },
Johannes Berg29cbe682010-12-03 09:20:44 +01009908 {
9909 .cmd = NL80211_CMD_JOIN_MESH,
9910 .doit = nl80211_join_mesh,
9911 .policy = nl80211_policy,
9912 .flags = GENL_ADMIN_PERM,
9913 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
9914 NL80211_FLAG_NEED_RTNL,
9915 },
9916 {
9917 .cmd = NL80211_CMD_LEAVE_MESH,
9918 .doit = nl80211_leave_mesh,
9919 .policy = nl80211_policy,
9920 .flags = GENL_ADMIN_PERM,
9921 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
9922 NL80211_FLAG_NEED_RTNL,
9923 },
Johannes Bergdfb89c52012-06-27 09:23:48 +02009924#ifdef CONFIG_PM
Johannes Bergff1b6e62011-05-04 15:37:28 +02009925 {
9926 .cmd = NL80211_CMD_GET_WOWLAN,
9927 .doit = nl80211_get_wowlan,
9928 .policy = nl80211_policy,
9929 /* can be retrieved by unprivileged users */
9930 .internal_flags = NL80211_FLAG_NEED_WIPHY |
9931 NL80211_FLAG_NEED_RTNL,
9932 },
9933 {
9934 .cmd = NL80211_CMD_SET_WOWLAN,
9935 .doit = nl80211_set_wowlan,
9936 .policy = nl80211_policy,
9937 .flags = GENL_ADMIN_PERM,
9938 .internal_flags = NL80211_FLAG_NEED_WIPHY |
9939 NL80211_FLAG_NEED_RTNL,
9940 },
Johannes Bergdfb89c52012-06-27 09:23:48 +02009941#endif
Johannes Berge5497d72011-07-05 16:35:40 +02009942 {
9943 .cmd = NL80211_CMD_SET_REKEY_OFFLOAD,
9944 .doit = nl80211_set_rekey_data,
9945 .policy = nl80211_policy,
9946 .flags = GENL_ADMIN_PERM,
9947 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
9948 NL80211_FLAG_NEED_RTNL,
9949 },
Arik Nemtsov109086c2011-09-28 14:12:50 +03009950 {
9951 .cmd = NL80211_CMD_TDLS_MGMT,
9952 .doit = nl80211_tdls_mgmt,
9953 .policy = nl80211_policy,
9954 .flags = GENL_ADMIN_PERM,
9955 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
9956 NL80211_FLAG_NEED_RTNL,
9957 },
9958 {
9959 .cmd = NL80211_CMD_TDLS_OPER,
9960 .doit = nl80211_tdls_oper,
9961 .policy = nl80211_policy,
9962 .flags = GENL_ADMIN_PERM,
9963 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
9964 NL80211_FLAG_NEED_RTNL,
9965 },
Johannes Berg28946da2011-11-04 11:18:12 +01009966 {
9967 .cmd = NL80211_CMD_UNEXPECTED_FRAME,
9968 .doit = nl80211_register_unexpected_frame,
9969 .policy = nl80211_policy,
9970 .flags = GENL_ADMIN_PERM,
9971 .internal_flags = NL80211_FLAG_NEED_NETDEV |
9972 NL80211_FLAG_NEED_RTNL,
9973 },
Johannes Berg7f6cf312011-11-04 11:18:15 +01009974 {
9975 .cmd = NL80211_CMD_PROBE_CLIENT,
9976 .doit = nl80211_probe_client,
9977 .policy = nl80211_policy,
9978 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02009979 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg7f6cf312011-11-04 11:18:15 +01009980 NL80211_FLAG_NEED_RTNL,
9981 },
Johannes Berg5e760232011-11-04 11:18:17 +01009982 {
9983 .cmd = NL80211_CMD_REGISTER_BEACONS,
9984 .doit = nl80211_register_beacons,
9985 .policy = nl80211_policy,
9986 .flags = GENL_ADMIN_PERM,
9987 .internal_flags = NL80211_FLAG_NEED_WIPHY |
9988 NL80211_FLAG_NEED_RTNL,
9989 },
Simon Wunderlich1d9d9212011-11-18 14:20:43 +01009990 {
9991 .cmd = NL80211_CMD_SET_NOACK_MAP,
9992 .doit = nl80211_set_noack_map,
9993 .policy = nl80211_policy,
9994 .flags = GENL_ADMIN_PERM,
9995 .internal_flags = NL80211_FLAG_NEED_NETDEV |
9996 NL80211_FLAG_NEED_RTNL,
9997 },
Johannes Berg98104fde2012-06-16 00:19:54 +02009998 {
9999 .cmd = NL80211_CMD_START_P2P_DEVICE,
10000 .doit = nl80211_start_p2p_device,
10001 .policy = nl80211_policy,
10002 .flags = GENL_ADMIN_PERM,
10003 .internal_flags = NL80211_FLAG_NEED_WDEV |
10004 NL80211_FLAG_NEED_RTNL,
10005 },
10006 {
10007 .cmd = NL80211_CMD_STOP_P2P_DEVICE,
10008 .doit = nl80211_stop_p2p_device,
10009 .policy = nl80211_policy,
10010 .flags = GENL_ADMIN_PERM,
10011 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
10012 NL80211_FLAG_NEED_RTNL,
10013 },
Antonio Quartullif4e583c2012-11-02 13:27:48 +010010014 {
10015 .cmd = NL80211_CMD_SET_MCAST_RATE,
10016 .doit = nl80211_set_mcast_rate,
10017 .policy = nl80211_policy,
10018 .flags = GENL_ADMIN_PERM,
10019 .internal_flags = NL80211_FLAG_NEED_NETDEV |
10020 NL80211_FLAG_NEED_RTNL,
10021 },
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +053010022 {
10023 .cmd = NL80211_CMD_SET_MAC_ACL,
10024 .doit = nl80211_set_mac_acl,
10025 .policy = nl80211_policy,
10026 .flags = GENL_ADMIN_PERM,
10027 .internal_flags = NL80211_FLAG_NEED_NETDEV |
10028 NL80211_FLAG_NEED_RTNL,
10029 },
Simon Wunderlich04f39042013-02-08 18:16:19 +010010030 {
10031 .cmd = NL80211_CMD_RADAR_DETECT,
10032 .doit = nl80211_start_radar_detection,
10033 .policy = nl80211_policy,
10034 .flags = GENL_ADMIN_PERM,
10035 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
10036 NL80211_FLAG_NEED_RTNL,
10037 },
Johannes Berg3713b4e2013-02-14 16:19:38 +010010038 {
10039 .cmd = NL80211_CMD_GET_PROTOCOL_FEATURES,
10040 .doit = nl80211_get_protocol_features,
10041 .policy = nl80211_policy,
10042 },
Jouni Malinen355199e2013-02-27 17:14:27 +020010043 {
10044 .cmd = NL80211_CMD_UPDATE_FT_IES,
10045 .doit = nl80211_update_ft_ies,
10046 .policy = nl80211_policy,
10047 .flags = GENL_ADMIN_PERM,
10048 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
10049 NL80211_FLAG_NEED_RTNL,
10050 },
Arend van Spriel5de17982013-04-18 15:49:00 +020010051 {
10052 .cmd = NL80211_CMD_CRIT_PROTOCOL_START,
10053 .doit = nl80211_crit_protocol_start,
10054 .policy = nl80211_policy,
10055 .flags = GENL_ADMIN_PERM,
10056 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
10057 NL80211_FLAG_NEED_RTNL,
10058 },
10059 {
10060 .cmd = NL80211_CMD_CRIT_PROTOCOL_STOP,
10061 .doit = nl80211_crit_protocol_stop,
10062 .policy = nl80211_policy,
10063 .flags = GENL_ADMIN_PERM,
10064 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
10065 NL80211_FLAG_NEED_RTNL,
Amitkumar Karwarbe29b992013-06-28 11:51:26 -070010066 },
10067 {
10068 .cmd = NL80211_CMD_GET_COALESCE,
10069 .doit = nl80211_get_coalesce,
10070 .policy = nl80211_policy,
10071 .internal_flags = NL80211_FLAG_NEED_WIPHY |
10072 NL80211_FLAG_NEED_RTNL,
10073 },
10074 {
10075 .cmd = NL80211_CMD_SET_COALESCE,
10076 .doit = nl80211_set_coalesce,
10077 .policy = nl80211_policy,
10078 .flags = GENL_ADMIN_PERM,
10079 .internal_flags = NL80211_FLAG_NEED_WIPHY |
10080 NL80211_FLAG_NEED_RTNL,
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +020010081 },
10082 {
10083 .cmd = NL80211_CMD_CHANNEL_SWITCH,
10084 .doit = nl80211_channel_switch,
10085 .policy = nl80211_policy,
10086 .flags = GENL_ADMIN_PERM,
10087 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
10088 NL80211_FLAG_NEED_RTNL,
10089 },
Johannes Bergad7e7182013-11-13 13:37:47 +010010090 {
10091 .cmd = NL80211_CMD_VENDOR,
10092 .doit = nl80211_vendor_cmd,
10093 .policy = nl80211_policy,
10094 .flags = GENL_ADMIN_PERM,
10095 .internal_flags = NL80211_FLAG_NEED_WIPHY |
10096 NL80211_FLAG_NEED_RTNL,
10097 },
Kyeyoon Parkfa9ffc72013-12-16 23:01:30 -080010098 {
10099 .cmd = NL80211_CMD_SET_QOS_MAP,
10100 .doit = nl80211_set_qos_map,
10101 .policy = nl80211_policy,
10102 .flags = GENL_ADMIN_PERM,
10103 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
10104 NL80211_FLAG_NEED_RTNL,
10105 },
Johannes Berg55682962007-09-20 13:09:35 -040010106};
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010107
Johannes Berg55682962007-09-20 13:09:35 -040010108/* notification functions */
10109
Johannes Berg3bb20552014-05-26 13:52:25 +020010110void nl80211_notify_wiphy(struct cfg80211_registered_device *rdev,
10111 enum nl80211_commands cmd)
Johannes Berg55682962007-09-20 13:09:35 -040010112{
10113 struct sk_buff *msg;
Johannes Berg86e8cf92013-06-19 10:57:22 +020010114 struct nl80211_dump_wiphy_state state = {};
Johannes Berg55682962007-09-20 13:09:35 -040010115
Johannes Berg3bb20552014-05-26 13:52:25 +020010116 WARN_ON(cmd != NL80211_CMD_NEW_WIPHY &&
10117 cmd != NL80211_CMD_DEL_WIPHY);
10118
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -070010119 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -040010120 if (!msg)
10121 return;
10122
Johannes Berg3bb20552014-05-26 13:52:25 +020010123 if (nl80211_send_wiphy(rdev, cmd, msg, 0, 0, 0, &state) < 0) {
Johannes Berg55682962007-09-20 13:09:35 -040010124 nlmsg_free(msg);
10125 return;
10126 }
10127
Johannes Berg68eb5502013-11-19 15:19:38 +010010128 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010010129 NL80211_MCGRP_CONFIG, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -040010130}
10131
Johannes Berg362a4152009-05-24 16:43:15 +020010132static int nl80211_add_scan_req(struct sk_buff *msg,
10133 struct cfg80211_registered_device *rdev)
10134{
10135 struct cfg80211_scan_request *req = rdev->scan_req;
10136 struct nlattr *nest;
10137 int i;
10138
10139 if (WARN_ON(!req))
10140 return 0;
10141
10142 nest = nla_nest_start(msg, NL80211_ATTR_SCAN_SSIDS);
10143 if (!nest)
10144 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -040010145 for (i = 0; i < req->n_ssids; i++) {
10146 if (nla_put(msg, i, req->ssids[i].ssid_len, req->ssids[i].ssid))
10147 goto nla_put_failure;
10148 }
Johannes Berg362a4152009-05-24 16:43:15 +020010149 nla_nest_end(msg, nest);
10150
10151 nest = nla_nest_start(msg, NL80211_ATTR_SCAN_FREQUENCIES);
10152 if (!nest)
10153 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -040010154 for (i = 0; i < req->n_channels; i++) {
10155 if (nla_put_u32(msg, i, req->channels[i]->center_freq))
10156 goto nla_put_failure;
10157 }
Johannes Berg362a4152009-05-24 16:43:15 +020010158 nla_nest_end(msg, nest);
10159
David S. Miller9360ffd2012-03-29 04:41:26 -040010160 if (req->ie &&
10161 nla_put(msg, NL80211_ATTR_IE, req->ie_len, req->ie))
10162 goto nla_put_failure;
Johannes Berg362a4152009-05-24 16:43:15 +020010163
Johannes Bergae917c92013-10-25 11:05:22 +020010164 if (req->flags &&
10165 nla_put_u32(msg, NL80211_ATTR_SCAN_FLAGS, req->flags))
10166 goto nla_put_failure;
Sam Lefflered4737712012-10-11 21:03:31 -070010167
Johannes Berg362a4152009-05-24 16:43:15 +020010168 return 0;
10169 nla_put_failure:
10170 return -ENOBUFS;
10171}
10172
Johannes Berga538e2d2009-06-16 19:56:42 +020010173static int nl80211_send_scan_msg(struct sk_buff *msg,
10174 struct cfg80211_registered_device *rdev,
Johannes Bergfd014282012-06-18 19:17:03 +020010175 struct wireless_dev *wdev,
Eric W. Biederman15e47302012-09-07 20:12:54 +000010176 u32 portid, u32 seq, int flags,
Johannes Berga538e2d2009-06-16 19:56:42 +020010177 u32 cmd)
Johannes Berg2a519312009-02-10 21:25:55 +010010178{
10179 void *hdr;
10180
Eric W. Biederman15e47302012-09-07 20:12:54 +000010181 hdr = nl80211hdr_put(msg, portid, seq, flags, cmd);
Johannes Berg2a519312009-02-10 21:25:55 +010010182 if (!hdr)
10183 return -1;
10184
David S. Miller9360ffd2012-03-29 04:41:26 -040010185 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Bergfd014282012-06-18 19:17:03 +020010186 (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
10187 wdev->netdev->ifindex)) ||
10188 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)))
David S. Miller9360ffd2012-03-29 04:41:26 -040010189 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +010010190
Johannes Berg362a4152009-05-24 16:43:15 +020010191 /* ignore errors and send incomplete event anyway */
10192 nl80211_add_scan_req(msg, rdev);
Johannes Berg2a519312009-02-10 21:25:55 +010010193
10194 return genlmsg_end(msg, hdr);
10195
10196 nla_put_failure:
10197 genlmsg_cancel(msg, hdr);
10198 return -EMSGSIZE;
10199}
10200
Luciano Coelho807f8a82011-05-11 17:09:35 +030010201static int
10202nl80211_send_sched_scan_msg(struct sk_buff *msg,
10203 struct cfg80211_registered_device *rdev,
10204 struct net_device *netdev,
Eric W. Biederman15e47302012-09-07 20:12:54 +000010205 u32 portid, u32 seq, int flags, u32 cmd)
Luciano Coelho807f8a82011-05-11 17:09:35 +030010206{
10207 void *hdr;
10208
Eric W. Biederman15e47302012-09-07 20:12:54 +000010209 hdr = nl80211hdr_put(msg, portid, seq, flags, cmd);
Luciano Coelho807f8a82011-05-11 17:09:35 +030010210 if (!hdr)
10211 return -1;
10212
David S. Miller9360ffd2012-03-29 04:41:26 -040010213 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
10214 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex))
10215 goto nla_put_failure;
Luciano Coelho807f8a82011-05-11 17:09:35 +030010216
10217 return genlmsg_end(msg, hdr);
10218
10219 nla_put_failure:
10220 genlmsg_cancel(msg, hdr);
10221 return -EMSGSIZE;
10222}
10223
Johannes Berga538e2d2009-06-16 19:56:42 +020010224void nl80211_send_scan_start(struct cfg80211_registered_device *rdev,
Johannes Bergfd014282012-06-18 19:17:03 +020010225 struct wireless_dev *wdev)
Johannes Berga538e2d2009-06-16 19:56:42 +020010226{
10227 struct sk_buff *msg;
10228
Thomas Graf58050fc2012-06-28 03:57:45 +000010229 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berga538e2d2009-06-16 19:56:42 +020010230 if (!msg)
10231 return;
10232
Johannes Bergfd014282012-06-18 19:17:03 +020010233 if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0,
Johannes Berga538e2d2009-06-16 19:56:42 +020010234 NL80211_CMD_TRIGGER_SCAN) < 0) {
10235 nlmsg_free(msg);
10236 return;
10237 }
10238
Johannes Berg68eb5502013-11-19 15:19:38 +010010239 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010010240 NL80211_MCGRP_SCAN, GFP_KERNEL);
Johannes Berga538e2d2009-06-16 19:56:42 +020010241}
10242
Johannes Bergf9d15d12014-01-22 11:14:19 +020010243struct sk_buff *nl80211_build_scan_msg(struct cfg80211_registered_device *rdev,
10244 struct wireless_dev *wdev, bool aborted)
Johannes Berg2a519312009-02-10 21:25:55 +010010245{
10246 struct sk_buff *msg;
10247
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -070010248 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg2a519312009-02-10 21:25:55 +010010249 if (!msg)
Johannes Bergf9d15d12014-01-22 11:14:19 +020010250 return NULL;
Johannes Berg2a519312009-02-10 21:25:55 +010010251
Johannes Bergfd014282012-06-18 19:17:03 +020010252 if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0,
Johannes Bergf9d15d12014-01-22 11:14:19 +020010253 aborted ? NL80211_CMD_SCAN_ABORTED :
10254 NL80211_CMD_NEW_SCAN_RESULTS) < 0) {
Johannes Berg2a519312009-02-10 21:25:55 +010010255 nlmsg_free(msg);
Johannes Bergf9d15d12014-01-22 11:14:19 +020010256 return NULL;
Johannes Berg2a519312009-02-10 21:25:55 +010010257 }
10258
Johannes Bergf9d15d12014-01-22 11:14:19 +020010259 return msg;
Johannes Berg2a519312009-02-10 21:25:55 +010010260}
10261
Johannes Bergf9d15d12014-01-22 11:14:19 +020010262void nl80211_send_scan_result(struct cfg80211_registered_device *rdev,
10263 struct sk_buff *msg)
Johannes Berg2a519312009-02-10 21:25:55 +010010264{
Johannes Berg2a519312009-02-10 21:25:55 +010010265 if (!msg)
10266 return;
10267
Johannes Berg68eb5502013-11-19 15:19:38 +010010268 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010010269 NL80211_MCGRP_SCAN, GFP_KERNEL);
Johannes Berg2a519312009-02-10 21:25:55 +010010270}
10271
Luciano Coelho807f8a82011-05-11 17:09:35 +030010272void nl80211_send_sched_scan_results(struct cfg80211_registered_device *rdev,
10273 struct net_device *netdev)
10274{
10275 struct sk_buff *msg;
10276
10277 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
10278 if (!msg)
10279 return;
10280
10281 if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0,
10282 NL80211_CMD_SCHED_SCAN_RESULTS) < 0) {
10283 nlmsg_free(msg);
10284 return;
10285 }
10286
Johannes Berg68eb5502013-11-19 15:19:38 +010010287 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010010288 NL80211_MCGRP_SCAN, GFP_KERNEL);
Luciano Coelho807f8a82011-05-11 17:09:35 +030010289}
10290
10291void nl80211_send_sched_scan(struct cfg80211_registered_device *rdev,
10292 struct net_device *netdev, u32 cmd)
10293{
10294 struct sk_buff *msg;
10295
Thomas Graf58050fc2012-06-28 03:57:45 +000010296 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Luciano Coelho807f8a82011-05-11 17:09:35 +030010297 if (!msg)
10298 return;
10299
10300 if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0, cmd) < 0) {
10301 nlmsg_free(msg);
10302 return;
10303 }
10304
Johannes Berg68eb5502013-11-19 15:19:38 +010010305 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010010306 NL80211_MCGRP_SCAN, GFP_KERNEL);
Luciano Coelho807f8a82011-05-11 17:09:35 +030010307}
10308
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040010309/*
10310 * This can happen on global regulatory changes or device specific settings
10311 * based on custom world regulatory domains.
10312 */
10313void nl80211_send_reg_change_event(struct regulatory_request *request)
10314{
10315 struct sk_buff *msg;
10316 void *hdr;
10317
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -070010318 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040010319 if (!msg)
10320 return;
10321
10322 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_CHANGE);
10323 if (!hdr) {
10324 nlmsg_free(msg);
10325 return;
10326 }
10327
10328 /* Userspace can always count this one always being set */
David S. Miller9360ffd2012-03-29 04:41:26 -040010329 if (nla_put_u8(msg, NL80211_ATTR_REG_INITIATOR, request->initiator))
10330 goto nla_put_failure;
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040010331
David S. Miller9360ffd2012-03-29 04:41:26 -040010332 if (request->alpha2[0] == '0' && request->alpha2[1] == '0') {
10333 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
10334 NL80211_REGDOM_TYPE_WORLD))
10335 goto nla_put_failure;
10336 } else if (request->alpha2[0] == '9' && request->alpha2[1] == '9') {
10337 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
10338 NL80211_REGDOM_TYPE_CUSTOM_WORLD))
10339 goto nla_put_failure;
10340 } else if ((request->alpha2[0] == '9' && request->alpha2[1] == '8') ||
10341 request->intersect) {
10342 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
10343 NL80211_REGDOM_TYPE_INTERSECTION))
10344 goto nla_put_failure;
10345 } else {
10346 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
10347 NL80211_REGDOM_TYPE_COUNTRY) ||
10348 nla_put_string(msg, NL80211_ATTR_REG_ALPHA2,
10349 request->alpha2))
10350 goto nla_put_failure;
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040010351 }
10352
Johannes Bergf4173762012-12-03 18:23:37 +010010353 if (request->wiphy_idx != WIPHY_IDX_INVALID &&
David S. Miller9360ffd2012-03-29 04:41:26 -040010354 nla_put_u32(msg, NL80211_ATTR_WIPHY, request->wiphy_idx))
10355 goto nla_put_failure;
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040010356
Johannes Berg3b7b72e2011-10-22 19:05:51 +020010357 genlmsg_end(msg, hdr);
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040010358
Johannes Bergbc43b282009-07-25 10:54:13 +020010359 rcu_read_lock();
Johannes Berg68eb5502013-11-19 15:19:38 +010010360 genlmsg_multicast_allns(&nl80211_fam, msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010010361 NL80211_MCGRP_REGULATORY, GFP_ATOMIC);
Johannes Bergbc43b282009-07-25 10:54:13 +020010362 rcu_read_unlock();
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040010363
10364 return;
10365
10366nla_put_failure:
10367 genlmsg_cancel(msg, hdr);
10368 nlmsg_free(msg);
10369}
10370
Jouni Malinen6039f6d2009-03-19 13:39:21 +020010371static void nl80211_send_mlme_event(struct cfg80211_registered_device *rdev,
10372 struct net_device *netdev,
10373 const u8 *buf, size_t len,
Johannes Berge6d6e342009-07-01 21:26:47 +020010374 enum nl80211_commands cmd, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +020010375{
10376 struct sk_buff *msg;
10377 void *hdr;
10378
Johannes Berge6d6e342009-07-01 21:26:47 +020010379 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020010380 if (!msg)
10381 return;
10382
10383 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
10384 if (!hdr) {
10385 nlmsg_free(msg);
10386 return;
10387 }
10388
David S. Miller9360ffd2012-03-29 04:41:26 -040010389 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
10390 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
10391 nla_put(msg, NL80211_ATTR_FRAME, len, buf))
10392 goto nla_put_failure;
Jouni Malinen6039f6d2009-03-19 13:39:21 +020010393
Johannes Berg3b7b72e2011-10-22 19:05:51 +020010394 genlmsg_end(msg, hdr);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020010395
Johannes Berg68eb5502013-11-19 15:19:38 +010010396 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010010397 NL80211_MCGRP_MLME, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020010398 return;
10399
10400 nla_put_failure:
10401 genlmsg_cancel(msg, hdr);
10402 nlmsg_free(msg);
10403}
10404
10405void nl80211_send_rx_auth(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +020010406 struct net_device *netdev, const u8 *buf,
10407 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +020010408{
10409 nl80211_send_mlme_event(rdev, netdev, buf, len,
Johannes Berge6d6e342009-07-01 21:26:47 +020010410 NL80211_CMD_AUTHENTICATE, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020010411}
10412
10413void nl80211_send_rx_assoc(struct cfg80211_registered_device *rdev,
10414 struct net_device *netdev, const u8 *buf,
Johannes Berge6d6e342009-07-01 21:26:47 +020010415 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +020010416{
Johannes Berge6d6e342009-07-01 21:26:47 +020010417 nl80211_send_mlme_event(rdev, netdev, buf, len,
10418 NL80211_CMD_ASSOCIATE, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020010419}
10420
Jouni Malinen53b46b82009-03-27 20:53:56 +020010421void nl80211_send_deauth(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +020010422 struct net_device *netdev, const u8 *buf,
10423 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +020010424{
10425 nl80211_send_mlme_event(rdev, netdev, buf, len,
Johannes Berge6d6e342009-07-01 21:26:47 +020010426 NL80211_CMD_DEAUTHENTICATE, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020010427}
10428
Jouni Malinen53b46b82009-03-27 20:53:56 +020010429void nl80211_send_disassoc(struct cfg80211_registered_device *rdev,
10430 struct net_device *netdev, const u8 *buf,
Johannes Berge6d6e342009-07-01 21:26:47 +020010431 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +020010432{
10433 nl80211_send_mlme_event(rdev, netdev, buf, len,
Johannes Berge6d6e342009-07-01 21:26:47 +020010434 NL80211_CMD_DISASSOCIATE, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020010435}
10436
Johannes Berg6ff57cf2013-05-16 00:55:00 +020010437void cfg80211_rx_unprot_mlme_mgmt(struct net_device *dev, const u8 *buf,
10438 size_t len)
Jouni Malinencf4e5942010-12-16 00:52:40 +020010439{
Johannes Berg947add32013-02-22 22:05:20 +010010440 struct wireless_dev *wdev = dev->ieee80211_ptr;
10441 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080010442 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg6ff57cf2013-05-16 00:55:00 +020010443 const struct ieee80211_mgmt *mgmt = (void *)buf;
10444 u32 cmd;
Jouni Malinencf4e5942010-12-16 00:52:40 +020010445
Johannes Berg6ff57cf2013-05-16 00:55:00 +020010446 if (WARN_ON(len < 2))
10447 return;
10448
10449 if (ieee80211_is_deauth(mgmt->frame_control))
10450 cmd = NL80211_CMD_UNPROT_DEAUTHENTICATE;
10451 else
10452 cmd = NL80211_CMD_UNPROT_DISASSOCIATE;
10453
10454 trace_cfg80211_rx_unprot_mlme_mgmt(dev, buf, len);
10455 nl80211_send_mlme_event(rdev, dev, buf, len, cmd, GFP_ATOMIC);
Jouni Malinencf4e5942010-12-16 00:52:40 +020010456}
Johannes Berg6ff57cf2013-05-16 00:55:00 +020010457EXPORT_SYMBOL(cfg80211_rx_unprot_mlme_mgmt);
Jouni Malinencf4e5942010-12-16 00:52:40 +020010458
Luis R. Rodriguez1b06bb42009-05-02 00:34:48 -040010459static void nl80211_send_mlme_timeout(struct cfg80211_registered_device *rdev,
10460 struct net_device *netdev, int cmd,
Johannes Berge6d6e342009-07-01 21:26:47 +020010461 const u8 *addr, gfp_t gfp)
Jouni Malinen1965c852009-04-22 21:38:25 +030010462{
10463 struct sk_buff *msg;
10464 void *hdr;
10465
Johannes Berge6d6e342009-07-01 21:26:47 +020010466 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +030010467 if (!msg)
10468 return;
10469
10470 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
10471 if (!hdr) {
10472 nlmsg_free(msg);
10473 return;
10474 }
10475
David S. Miller9360ffd2012-03-29 04:41:26 -040010476 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
10477 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
10478 nla_put_flag(msg, NL80211_ATTR_TIMED_OUT) ||
10479 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr))
10480 goto nla_put_failure;
Jouni Malinen1965c852009-04-22 21:38:25 +030010481
Johannes Berg3b7b72e2011-10-22 19:05:51 +020010482 genlmsg_end(msg, hdr);
Jouni Malinen1965c852009-04-22 21:38:25 +030010483
Johannes Berg68eb5502013-11-19 15:19:38 +010010484 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010010485 NL80211_MCGRP_MLME, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +030010486 return;
10487
10488 nla_put_failure:
10489 genlmsg_cancel(msg, hdr);
10490 nlmsg_free(msg);
10491}
10492
10493void nl80211_send_auth_timeout(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +020010494 struct net_device *netdev, const u8 *addr,
10495 gfp_t gfp)
Jouni Malinen1965c852009-04-22 21:38:25 +030010496{
10497 nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_AUTHENTICATE,
Johannes Berge6d6e342009-07-01 21:26:47 +020010498 addr, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +030010499}
10500
10501void nl80211_send_assoc_timeout(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +020010502 struct net_device *netdev, const u8 *addr,
10503 gfp_t gfp)
Jouni Malinen1965c852009-04-22 21:38:25 +030010504{
Johannes Berge6d6e342009-07-01 21:26:47 +020010505 nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_ASSOCIATE,
10506 addr, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +030010507}
10508
Samuel Ortizb23aa672009-07-01 21:26:54 +020010509void nl80211_send_connect_result(struct cfg80211_registered_device *rdev,
10510 struct net_device *netdev, const u8 *bssid,
10511 const u8 *req_ie, size_t req_ie_len,
10512 const u8 *resp_ie, size_t resp_ie_len,
10513 u16 status, gfp_t gfp)
10514{
10515 struct sk_buff *msg;
10516 void *hdr;
10517
Thomas Graf58050fc2012-06-28 03:57:45 +000010518 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +020010519 if (!msg)
10520 return;
10521
10522 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONNECT);
10523 if (!hdr) {
10524 nlmsg_free(msg);
10525 return;
10526 }
10527
David S. Miller9360ffd2012-03-29 04:41:26 -040010528 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
10529 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
10530 (bssid && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) ||
10531 nla_put_u16(msg, NL80211_ATTR_STATUS_CODE, status) ||
10532 (req_ie &&
10533 nla_put(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie)) ||
10534 (resp_ie &&
10535 nla_put(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie)))
10536 goto nla_put_failure;
Samuel Ortizb23aa672009-07-01 21:26:54 +020010537
Johannes Berg3b7b72e2011-10-22 19:05:51 +020010538 genlmsg_end(msg, hdr);
Samuel Ortizb23aa672009-07-01 21:26:54 +020010539
Johannes Berg68eb5502013-11-19 15:19:38 +010010540 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010010541 NL80211_MCGRP_MLME, gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +020010542 return;
10543
10544 nla_put_failure:
10545 genlmsg_cancel(msg, hdr);
10546 nlmsg_free(msg);
10547
10548}
10549
10550void nl80211_send_roamed(struct cfg80211_registered_device *rdev,
10551 struct net_device *netdev, const u8 *bssid,
10552 const u8 *req_ie, size_t req_ie_len,
10553 const u8 *resp_ie, size_t resp_ie_len, gfp_t gfp)
10554{
10555 struct sk_buff *msg;
10556 void *hdr;
10557
Thomas Graf58050fc2012-06-28 03:57:45 +000010558 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +020010559 if (!msg)
10560 return;
10561
10562 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_ROAM);
10563 if (!hdr) {
10564 nlmsg_free(msg);
10565 return;
10566 }
10567
David S. Miller9360ffd2012-03-29 04:41:26 -040010568 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
10569 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
10570 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid) ||
10571 (req_ie &&
10572 nla_put(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie)) ||
10573 (resp_ie &&
10574 nla_put(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie)))
10575 goto nla_put_failure;
Samuel Ortizb23aa672009-07-01 21:26:54 +020010576
Johannes Berg3b7b72e2011-10-22 19:05:51 +020010577 genlmsg_end(msg, hdr);
Samuel Ortizb23aa672009-07-01 21:26:54 +020010578
Johannes Berg68eb5502013-11-19 15:19:38 +010010579 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010010580 NL80211_MCGRP_MLME, gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +020010581 return;
10582
10583 nla_put_failure:
10584 genlmsg_cancel(msg, hdr);
10585 nlmsg_free(msg);
10586
10587}
10588
10589void nl80211_send_disconnected(struct cfg80211_registered_device *rdev,
10590 struct net_device *netdev, u16 reason,
Johannes Berg667503d2009-07-07 03:56:11 +020010591 const u8 *ie, size_t ie_len, bool from_ap)
Samuel Ortizb23aa672009-07-01 21:26:54 +020010592{
10593 struct sk_buff *msg;
10594 void *hdr;
10595
Thomas Graf58050fc2012-06-28 03:57:45 +000010596 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Samuel Ortizb23aa672009-07-01 21:26:54 +020010597 if (!msg)
10598 return;
10599
10600 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DISCONNECT);
10601 if (!hdr) {
10602 nlmsg_free(msg);
10603 return;
10604 }
10605
David S. Miller9360ffd2012-03-29 04:41:26 -040010606 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
10607 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
10608 (from_ap && reason &&
10609 nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason)) ||
10610 (from_ap &&
10611 nla_put_flag(msg, NL80211_ATTR_DISCONNECTED_BY_AP)) ||
10612 (ie && nla_put(msg, NL80211_ATTR_IE, ie_len, ie)))
10613 goto nla_put_failure;
Samuel Ortizb23aa672009-07-01 21:26:54 +020010614
Johannes Berg3b7b72e2011-10-22 19:05:51 +020010615 genlmsg_end(msg, hdr);
Samuel Ortizb23aa672009-07-01 21:26:54 +020010616
Johannes Berg68eb5502013-11-19 15:19:38 +010010617 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010010618 NL80211_MCGRP_MLME, GFP_KERNEL);
Samuel Ortizb23aa672009-07-01 21:26:54 +020010619 return;
10620
10621 nla_put_failure:
10622 genlmsg_cancel(msg, hdr);
10623 nlmsg_free(msg);
10624
10625}
10626
Johannes Berg04a773a2009-04-19 21:24:32 +020010627void nl80211_send_ibss_bssid(struct cfg80211_registered_device *rdev,
10628 struct net_device *netdev, const u8 *bssid,
10629 gfp_t gfp)
10630{
10631 struct sk_buff *msg;
10632 void *hdr;
10633
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -070010634 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Johannes Berg04a773a2009-04-19 21:24:32 +020010635 if (!msg)
10636 return;
10637
10638 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_JOIN_IBSS);
10639 if (!hdr) {
10640 nlmsg_free(msg);
10641 return;
10642 }
10643
David S. Miller9360ffd2012-03-29 04:41:26 -040010644 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
10645 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
10646 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid))
10647 goto nla_put_failure;
Johannes Berg04a773a2009-04-19 21:24:32 +020010648
Johannes Berg3b7b72e2011-10-22 19:05:51 +020010649 genlmsg_end(msg, hdr);
Johannes Berg04a773a2009-04-19 21:24:32 +020010650
Johannes Berg68eb5502013-11-19 15:19:38 +010010651 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010010652 NL80211_MCGRP_MLME, gfp);
Johannes Berg04a773a2009-04-19 21:24:32 +020010653 return;
10654
10655 nla_put_failure:
10656 genlmsg_cancel(msg, hdr);
10657 nlmsg_free(msg);
10658}
10659
Johannes Berg947add32013-02-22 22:05:20 +010010660void cfg80211_notify_new_peer_candidate(struct net_device *dev, const u8 *addr,
10661 const u8* ie, u8 ie_len, gfp_t gfp)
Javier Cardonac93b5e72011-04-07 15:08:34 -070010662{
Johannes Berg947add32013-02-22 22:05:20 +010010663 struct wireless_dev *wdev = dev->ieee80211_ptr;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080010664 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Javier Cardonac93b5e72011-04-07 15:08:34 -070010665 struct sk_buff *msg;
10666 void *hdr;
10667
Johannes Berg947add32013-02-22 22:05:20 +010010668 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_MESH_POINT))
10669 return;
10670
10671 trace_cfg80211_notify_new_peer_candidate(dev, addr);
10672
Javier Cardonac93b5e72011-04-07 15:08:34 -070010673 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
10674 if (!msg)
10675 return;
10676
10677 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NEW_PEER_CANDIDATE);
10678 if (!hdr) {
10679 nlmsg_free(msg);
10680 return;
10681 }
10682
David S. Miller9360ffd2012-03-29 04:41:26 -040010683 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg947add32013-02-22 22:05:20 +010010684 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
10685 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040010686 (ie_len && ie &&
10687 nla_put(msg, NL80211_ATTR_IE, ie_len , ie)))
10688 goto nla_put_failure;
Javier Cardonac93b5e72011-04-07 15:08:34 -070010689
Johannes Berg3b7b72e2011-10-22 19:05:51 +020010690 genlmsg_end(msg, hdr);
Javier Cardonac93b5e72011-04-07 15:08:34 -070010691
Johannes Berg68eb5502013-11-19 15:19:38 +010010692 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010010693 NL80211_MCGRP_MLME, gfp);
Javier Cardonac93b5e72011-04-07 15:08:34 -070010694 return;
10695
10696 nla_put_failure:
10697 genlmsg_cancel(msg, hdr);
10698 nlmsg_free(msg);
10699}
Johannes Berg947add32013-02-22 22:05:20 +010010700EXPORT_SYMBOL(cfg80211_notify_new_peer_candidate);
Javier Cardonac93b5e72011-04-07 15:08:34 -070010701
Jouni Malinena3b8b052009-03-27 21:59:49 +020010702void nl80211_michael_mic_failure(struct cfg80211_registered_device *rdev,
10703 struct net_device *netdev, const u8 *addr,
10704 enum nl80211_key_type key_type, int key_id,
Johannes Berge6d6e342009-07-01 21:26:47 +020010705 const u8 *tsc, gfp_t gfp)
Jouni Malinena3b8b052009-03-27 21:59:49 +020010706{
10707 struct sk_buff *msg;
10708 void *hdr;
10709
Johannes Berge6d6e342009-07-01 21:26:47 +020010710 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinena3b8b052009-03-27 21:59:49 +020010711 if (!msg)
10712 return;
10713
10714 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_MICHAEL_MIC_FAILURE);
10715 if (!hdr) {
10716 nlmsg_free(msg);
10717 return;
10718 }
10719
David S. Miller9360ffd2012-03-29 04:41:26 -040010720 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
10721 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
10722 (addr && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) ||
10723 nla_put_u32(msg, NL80211_ATTR_KEY_TYPE, key_type) ||
10724 (key_id != -1 &&
10725 nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_id)) ||
10726 (tsc && nla_put(msg, NL80211_ATTR_KEY_SEQ, 6, tsc)))
10727 goto nla_put_failure;
Jouni Malinena3b8b052009-03-27 21:59:49 +020010728
Johannes Berg3b7b72e2011-10-22 19:05:51 +020010729 genlmsg_end(msg, hdr);
Jouni Malinena3b8b052009-03-27 21:59:49 +020010730
Johannes Berg68eb5502013-11-19 15:19:38 +010010731 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010010732 NL80211_MCGRP_MLME, gfp);
Jouni Malinena3b8b052009-03-27 21:59:49 +020010733 return;
10734
10735 nla_put_failure:
10736 genlmsg_cancel(msg, hdr);
10737 nlmsg_free(msg);
10738}
10739
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040010740void nl80211_send_beacon_hint_event(struct wiphy *wiphy,
10741 struct ieee80211_channel *channel_before,
10742 struct ieee80211_channel *channel_after)
10743{
10744 struct sk_buff *msg;
10745 void *hdr;
10746 struct nlattr *nl_freq;
10747
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -070010748 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_ATOMIC);
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040010749 if (!msg)
10750 return;
10751
10752 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_BEACON_HINT);
10753 if (!hdr) {
10754 nlmsg_free(msg);
10755 return;
10756 }
10757
10758 /*
10759 * Since we are applying the beacon hint to a wiphy we know its
10760 * wiphy_idx is valid
10761 */
David S. Miller9360ffd2012-03-29 04:41:26 -040010762 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy)))
10763 goto nla_put_failure;
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040010764
10765 /* Before */
10766 nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_BEFORE);
10767 if (!nl_freq)
10768 goto nla_put_failure;
Johannes Bergcdc89b92013-02-18 23:54:36 +010010769 if (nl80211_msg_put_channel(msg, channel_before, false))
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040010770 goto nla_put_failure;
10771 nla_nest_end(msg, nl_freq);
10772
10773 /* After */
10774 nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_AFTER);
10775 if (!nl_freq)
10776 goto nla_put_failure;
Johannes Bergcdc89b92013-02-18 23:54:36 +010010777 if (nl80211_msg_put_channel(msg, channel_after, false))
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040010778 goto nla_put_failure;
10779 nla_nest_end(msg, nl_freq);
10780
Johannes Berg3b7b72e2011-10-22 19:05:51 +020010781 genlmsg_end(msg, hdr);
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040010782
Johannes Berg463d0182009-07-14 00:33:35 +020010783 rcu_read_lock();
Johannes Berg68eb5502013-11-19 15:19:38 +010010784 genlmsg_multicast_allns(&nl80211_fam, msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010010785 NL80211_MCGRP_REGULATORY, GFP_ATOMIC);
Johannes Berg463d0182009-07-14 00:33:35 +020010786 rcu_read_unlock();
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040010787
10788 return;
10789
10790nla_put_failure:
10791 genlmsg_cancel(msg, hdr);
10792 nlmsg_free(msg);
10793}
10794
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010795static void nl80211_send_remain_on_chan_event(
10796 int cmd, struct cfg80211_registered_device *rdev,
Johannes Berg71bbc992012-06-15 15:30:18 +020010797 struct wireless_dev *wdev, u64 cookie,
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010798 struct ieee80211_channel *chan,
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010799 unsigned int duration, gfp_t gfp)
10800{
10801 struct sk_buff *msg;
10802 void *hdr;
10803
10804 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
10805 if (!msg)
10806 return;
10807
10808 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
10809 if (!hdr) {
10810 nlmsg_free(msg);
10811 return;
10812 }
10813
David S. Miller9360ffd2012-03-29 04:41:26 -040010814 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg71bbc992012-06-15 15:30:18 +020010815 (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
10816 wdev->netdev->ifindex)) ||
Johannes Berg00f53352012-07-17 11:53:12 +020010817 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040010818 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, chan->center_freq) ||
Johannes Berg42d97a52012-11-08 18:31:02 +010010819 nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE,
10820 NL80211_CHAN_NO_HT) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040010821 nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie))
10822 goto nla_put_failure;
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010823
David S. Miller9360ffd2012-03-29 04:41:26 -040010824 if (cmd == NL80211_CMD_REMAIN_ON_CHANNEL &&
10825 nla_put_u32(msg, NL80211_ATTR_DURATION, duration))
10826 goto nla_put_failure;
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010827
Johannes Berg3b7b72e2011-10-22 19:05:51 +020010828 genlmsg_end(msg, hdr);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010829
Johannes Berg68eb5502013-11-19 15:19:38 +010010830 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010010831 NL80211_MCGRP_MLME, gfp);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010832 return;
10833
10834 nla_put_failure:
10835 genlmsg_cancel(msg, hdr);
10836 nlmsg_free(msg);
10837}
10838
Johannes Berg947add32013-02-22 22:05:20 +010010839void cfg80211_ready_on_channel(struct wireless_dev *wdev, u64 cookie,
10840 struct ieee80211_channel *chan,
10841 unsigned int duration, gfp_t gfp)
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010842{
Johannes Berg947add32013-02-22 22:05:20 +010010843 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080010844 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg947add32013-02-22 22:05:20 +010010845
10846 trace_cfg80211_ready_on_channel(wdev, cookie, chan, duration);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010847 nl80211_send_remain_on_chan_event(NL80211_CMD_REMAIN_ON_CHANNEL,
Johannes Berg71bbc992012-06-15 15:30:18 +020010848 rdev, wdev, cookie, chan,
Johannes Berg42d97a52012-11-08 18:31:02 +010010849 duration, gfp);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010850}
Johannes Berg947add32013-02-22 22:05:20 +010010851EXPORT_SYMBOL(cfg80211_ready_on_channel);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010852
Johannes Berg947add32013-02-22 22:05:20 +010010853void cfg80211_remain_on_channel_expired(struct wireless_dev *wdev, u64 cookie,
10854 struct ieee80211_channel *chan,
10855 gfp_t gfp)
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010856{
Johannes Berg947add32013-02-22 22:05:20 +010010857 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080010858 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg947add32013-02-22 22:05:20 +010010859
10860 trace_cfg80211_ready_on_channel_expired(wdev, cookie, chan);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010861 nl80211_send_remain_on_chan_event(NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL,
Johannes Berg42d97a52012-11-08 18:31:02 +010010862 rdev, wdev, cookie, chan, 0, gfp);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010863}
Johannes Berg947add32013-02-22 22:05:20 +010010864EXPORT_SYMBOL(cfg80211_remain_on_channel_expired);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010865
Johannes Berg947add32013-02-22 22:05:20 +010010866void cfg80211_new_sta(struct net_device *dev, const u8 *mac_addr,
10867 struct station_info *sinfo, gfp_t gfp)
Johannes Berg98b62182009-12-23 13:15:44 +010010868{
Johannes Berg947add32013-02-22 22:05:20 +010010869 struct wiphy *wiphy = dev->ieee80211_ptr->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080010870 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg98b62182009-12-23 13:15:44 +010010871 struct sk_buff *msg;
10872
Johannes Berg947add32013-02-22 22:05:20 +010010873 trace_cfg80211_new_sta(dev, mac_addr, sinfo);
10874
Thomas Graf58050fc2012-06-28 03:57:45 +000010875 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Johannes Berg98b62182009-12-23 13:15:44 +010010876 if (!msg)
10877 return;
10878
John W. Linville66266b32012-03-15 13:25:41 -040010879 if (nl80211_send_station(msg, 0, 0, 0,
10880 rdev, dev, mac_addr, sinfo) < 0) {
Johannes Berg98b62182009-12-23 13:15:44 +010010881 nlmsg_free(msg);
10882 return;
10883 }
10884
Johannes Berg68eb5502013-11-19 15:19:38 +010010885 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010010886 NL80211_MCGRP_MLME, gfp);
Johannes Berg98b62182009-12-23 13:15:44 +010010887}
Johannes Berg947add32013-02-22 22:05:20 +010010888EXPORT_SYMBOL(cfg80211_new_sta);
Johannes Berg98b62182009-12-23 13:15:44 +010010889
Johannes Berg947add32013-02-22 22:05:20 +010010890void cfg80211_del_sta(struct net_device *dev, const u8 *mac_addr, gfp_t gfp)
Jouni Malinenec15e682011-03-23 15:29:52 +020010891{
Johannes Berg947add32013-02-22 22:05:20 +010010892 struct wiphy *wiphy = dev->ieee80211_ptr->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080010893 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Jouni Malinenec15e682011-03-23 15:29:52 +020010894 struct sk_buff *msg;
10895 void *hdr;
10896
Johannes Berg947add32013-02-22 22:05:20 +010010897 trace_cfg80211_del_sta(dev, mac_addr);
10898
Thomas Graf58050fc2012-06-28 03:57:45 +000010899 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinenec15e682011-03-23 15:29:52 +020010900 if (!msg)
10901 return;
10902
10903 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DEL_STATION);
10904 if (!hdr) {
10905 nlmsg_free(msg);
10906 return;
10907 }
10908
David S. Miller9360ffd2012-03-29 04:41:26 -040010909 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
10910 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr))
10911 goto nla_put_failure;
Jouni Malinenec15e682011-03-23 15:29:52 +020010912
Johannes Berg3b7b72e2011-10-22 19:05:51 +020010913 genlmsg_end(msg, hdr);
Jouni Malinenec15e682011-03-23 15:29:52 +020010914
Johannes Berg68eb5502013-11-19 15:19:38 +010010915 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010010916 NL80211_MCGRP_MLME, gfp);
Jouni Malinenec15e682011-03-23 15:29:52 +020010917 return;
10918
10919 nla_put_failure:
10920 genlmsg_cancel(msg, hdr);
10921 nlmsg_free(msg);
10922}
Johannes Berg947add32013-02-22 22:05:20 +010010923EXPORT_SYMBOL(cfg80211_del_sta);
Jouni Malinenec15e682011-03-23 15:29:52 +020010924
Johannes Berg947add32013-02-22 22:05:20 +010010925void cfg80211_conn_failed(struct net_device *dev, const u8 *mac_addr,
10926 enum nl80211_connect_failed_reason reason,
10927 gfp_t gfp)
Pandiyarajan Pitchaimuthued44a952012-09-18 16:50:49 +053010928{
Johannes Berg947add32013-02-22 22:05:20 +010010929 struct wiphy *wiphy = dev->ieee80211_ptr->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080010930 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Pandiyarajan Pitchaimuthued44a952012-09-18 16:50:49 +053010931 struct sk_buff *msg;
10932 void *hdr;
10933
10934 msg = nlmsg_new(NLMSG_GOODSIZE, gfp);
10935 if (!msg)
10936 return;
10937
10938 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONN_FAILED);
10939 if (!hdr) {
10940 nlmsg_free(msg);
10941 return;
10942 }
10943
10944 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
10945 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) ||
10946 nla_put_u32(msg, NL80211_ATTR_CONN_FAILED_REASON, reason))
10947 goto nla_put_failure;
10948
10949 genlmsg_end(msg, hdr);
10950
Johannes Berg68eb5502013-11-19 15:19:38 +010010951 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010010952 NL80211_MCGRP_MLME, gfp);
Pandiyarajan Pitchaimuthued44a952012-09-18 16:50:49 +053010953 return;
10954
10955 nla_put_failure:
10956 genlmsg_cancel(msg, hdr);
10957 nlmsg_free(msg);
10958}
Johannes Berg947add32013-02-22 22:05:20 +010010959EXPORT_SYMBOL(cfg80211_conn_failed);
Pandiyarajan Pitchaimuthued44a952012-09-18 16:50:49 +053010960
Johannes Bergb92ab5d2011-11-04 11:18:19 +010010961static bool __nl80211_unexpected_frame(struct net_device *dev, u8 cmd,
10962 const u8 *addr, gfp_t gfp)
Johannes Berg28946da2011-11-04 11:18:12 +010010963{
10964 struct wireless_dev *wdev = dev->ieee80211_ptr;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080010965 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Johannes Berg28946da2011-11-04 11:18:12 +010010966 struct sk_buff *msg;
10967 void *hdr;
Eric W. Biederman15e47302012-09-07 20:12:54 +000010968 u32 nlportid = ACCESS_ONCE(wdev->ap_unexpected_nlportid);
Johannes Berg28946da2011-11-04 11:18:12 +010010969
Eric W. Biederman15e47302012-09-07 20:12:54 +000010970 if (!nlportid)
Johannes Berg28946da2011-11-04 11:18:12 +010010971 return false;
10972
10973 msg = nlmsg_new(100, gfp);
10974 if (!msg)
10975 return true;
10976
Johannes Bergb92ab5d2011-11-04 11:18:19 +010010977 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
Johannes Berg28946da2011-11-04 11:18:12 +010010978 if (!hdr) {
10979 nlmsg_free(msg);
10980 return true;
10981 }
10982
David S. Miller9360ffd2012-03-29 04:41:26 -040010983 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
10984 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
10985 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr))
10986 goto nla_put_failure;
Johannes Berg28946da2011-11-04 11:18:12 +010010987
Johannes Berg9c90a9f2013-06-04 12:46:03 +020010988 genlmsg_end(msg, hdr);
Eric W. Biederman15e47302012-09-07 20:12:54 +000010989 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid);
Johannes Berg28946da2011-11-04 11:18:12 +010010990 return true;
10991
10992 nla_put_failure:
10993 genlmsg_cancel(msg, hdr);
10994 nlmsg_free(msg);
10995 return true;
10996}
10997
Johannes Berg947add32013-02-22 22:05:20 +010010998bool cfg80211_rx_spurious_frame(struct net_device *dev,
10999 const u8 *addr, gfp_t gfp)
Johannes Bergb92ab5d2011-11-04 11:18:19 +010011000{
Johannes Berg947add32013-02-22 22:05:20 +010011001 struct wireless_dev *wdev = dev->ieee80211_ptr;
11002 bool ret;
Johannes Bergb92ab5d2011-11-04 11:18:19 +010011003
Johannes Berg947add32013-02-22 22:05:20 +010011004 trace_cfg80211_rx_spurious_frame(dev, addr);
11005
11006 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP &&
11007 wdev->iftype != NL80211_IFTYPE_P2P_GO)) {
11008 trace_cfg80211_return_bool(false);
11009 return false;
11010 }
11011 ret = __nl80211_unexpected_frame(dev, NL80211_CMD_UNEXPECTED_FRAME,
11012 addr, gfp);
11013 trace_cfg80211_return_bool(ret);
11014 return ret;
Johannes Bergb92ab5d2011-11-04 11:18:19 +010011015}
Johannes Berg947add32013-02-22 22:05:20 +010011016EXPORT_SYMBOL(cfg80211_rx_spurious_frame);
11017
11018bool cfg80211_rx_unexpected_4addr_frame(struct net_device *dev,
11019 const u8 *addr, gfp_t gfp)
11020{
11021 struct wireless_dev *wdev = dev->ieee80211_ptr;
11022 bool ret;
11023
11024 trace_cfg80211_rx_unexpected_4addr_frame(dev, addr);
11025
11026 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP &&
11027 wdev->iftype != NL80211_IFTYPE_P2P_GO &&
11028 wdev->iftype != NL80211_IFTYPE_AP_VLAN)) {
11029 trace_cfg80211_return_bool(false);
11030 return false;
11031 }
11032 ret = __nl80211_unexpected_frame(dev,
11033 NL80211_CMD_UNEXPECTED_4ADDR_FRAME,
11034 addr, gfp);
11035 trace_cfg80211_return_bool(ret);
11036 return ret;
11037}
11038EXPORT_SYMBOL(cfg80211_rx_unexpected_4addr_frame);
Johannes Bergb92ab5d2011-11-04 11:18:19 +010011039
Johannes Berg2e161f72010-08-12 15:38:38 +020011040int nl80211_send_mgmt(struct cfg80211_registered_device *rdev,
Eric W. Biederman15e47302012-09-07 20:12:54 +000011041 struct wireless_dev *wdev, u32 nlportid,
Johannes Berg804483e2012-03-05 22:18:41 +010011042 int freq, int sig_dbm,
Vladimir Kondratiev19504cf2013-08-15 14:51:28 +030011043 const u8 *buf, size_t len, u32 flags, gfp_t gfp)
Jouni Malinen026331c2010-02-15 12:53:10 +020011044{
Johannes Berg71bbc992012-06-15 15:30:18 +020011045 struct net_device *netdev = wdev->netdev;
Jouni Malinen026331c2010-02-15 12:53:10 +020011046 struct sk_buff *msg;
11047 void *hdr;
Jouni Malinen026331c2010-02-15 12:53:10 +020011048
11049 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
11050 if (!msg)
11051 return -ENOMEM;
11052
Johannes Berg2e161f72010-08-12 15:38:38 +020011053 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME);
Jouni Malinen026331c2010-02-15 12:53:10 +020011054 if (!hdr) {
11055 nlmsg_free(msg);
11056 return -ENOMEM;
11057 }
11058
David S. Miller9360ffd2012-03-29 04:41:26 -040011059 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg71bbc992012-06-15 15:30:18 +020011060 (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
11061 netdev->ifindex)) ||
Ilan Peera8384902013-05-08 16:35:55 +030011062 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040011063 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq) ||
11064 (sig_dbm &&
11065 nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) ||
Vladimir Kondratiev19504cf2013-08-15 14:51:28 +030011066 nla_put(msg, NL80211_ATTR_FRAME, len, buf) ||
11067 (flags &&
11068 nla_put_u32(msg, NL80211_ATTR_RXMGMT_FLAGS, flags)))
David S. Miller9360ffd2012-03-29 04:41:26 -040011069 goto nla_put_failure;
Jouni Malinen026331c2010-02-15 12:53:10 +020011070
Johannes Berg3b7b72e2011-10-22 19:05:51 +020011071 genlmsg_end(msg, hdr);
Jouni Malinen026331c2010-02-15 12:53:10 +020011072
Eric W. Biederman15e47302012-09-07 20:12:54 +000011073 return genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid);
Jouni Malinen026331c2010-02-15 12:53:10 +020011074
11075 nla_put_failure:
11076 genlmsg_cancel(msg, hdr);
11077 nlmsg_free(msg);
11078 return -ENOBUFS;
11079}
11080
Johannes Berg947add32013-02-22 22:05:20 +010011081void cfg80211_mgmt_tx_status(struct wireless_dev *wdev, u64 cookie,
11082 const u8 *buf, size_t len, bool ack, gfp_t gfp)
Jouni Malinen026331c2010-02-15 12:53:10 +020011083{
Johannes Berg947add32013-02-22 22:05:20 +010011084 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080011085 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg71bbc992012-06-15 15:30:18 +020011086 struct net_device *netdev = wdev->netdev;
Jouni Malinen026331c2010-02-15 12:53:10 +020011087 struct sk_buff *msg;
11088 void *hdr;
11089
Johannes Berg947add32013-02-22 22:05:20 +010011090 trace_cfg80211_mgmt_tx_status(wdev, cookie, ack);
11091
Jouni Malinen026331c2010-02-15 12:53:10 +020011092 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
11093 if (!msg)
11094 return;
11095
Johannes Berg2e161f72010-08-12 15:38:38 +020011096 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME_TX_STATUS);
Jouni Malinen026331c2010-02-15 12:53:10 +020011097 if (!hdr) {
11098 nlmsg_free(msg);
11099 return;
11100 }
11101
David S. Miller9360ffd2012-03-29 04:41:26 -040011102 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg71bbc992012-06-15 15:30:18 +020011103 (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
11104 netdev->ifindex)) ||
Ilan Peera8384902013-05-08 16:35:55 +030011105 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040011106 nla_put(msg, NL80211_ATTR_FRAME, len, buf) ||
11107 nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie) ||
11108 (ack && nla_put_flag(msg, NL80211_ATTR_ACK)))
11109 goto nla_put_failure;
Jouni Malinen026331c2010-02-15 12:53:10 +020011110
Johannes Berg3b7b72e2011-10-22 19:05:51 +020011111 genlmsg_end(msg, hdr);
Jouni Malinen026331c2010-02-15 12:53:10 +020011112
Johannes Berg68eb5502013-11-19 15:19:38 +010011113 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011114 NL80211_MCGRP_MLME, gfp);
Jouni Malinen026331c2010-02-15 12:53:10 +020011115 return;
11116
11117 nla_put_failure:
11118 genlmsg_cancel(msg, hdr);
11119 nlmsg_free(msg);
11120}
Johannes Berg947add32013-02-22 22:05:20 +010011121EXPORT_SYMBOL(cfg80211_mgmt_tx_status);
Jouni Malinen026331c2010-02-15 12:53:10 +020011122
Johannes Berg947add32013-02-22 22:05:20 +010011123void cfg80211_cqm_rssi_notify(struct net_device *dev,
11124 enum nl80211_cqm_rssi_threshold_event rssi_event,
11125 gfp_t gfp)
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020011126{
Johannes Berg947add32013-02-22 22:05:20 +010011127 struct wireless_dev *wdev = dev->ieee80211_ptr;
11128 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080011129 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020011130 struct sk_buff *msg;
11131 struct nlattr *pinfoattr;
11132 void *hdr;
11133
Johannes Berg947add32013-02-22 22:05:20 +010011134 trace_cfg80211_cqm_rssi_notify(dev, rssi_event);
11135
Thomas Graf58050fc2012-06-28 03:57:45 +000011136 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020011137 if (!msg)
11138 return;
11139
11140 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM);
11141 if (!hdr) {
11142 nlmsg_free(msg);
11143 return;
11144 }
11145
David S. Miller9360ffd2012-03-29 04:41:26 -040011146 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg947add32013-02-22 22:05:20 +010011147 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex))
David S. Miller9360ffd2012-03-29 04:41:26 -040011148 goto nla_put_failure;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020011149
11150 pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM);
11151 if (!pinfoattr)
11152 goto nla_put_failure;
11153
David S. Miller9360ffd2012-03-29 04:41:26 -040011154 if (nla_put_u32(msg, NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT,
11155 rssi_event))
11156 goto nla_put_failure;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020011157
11158 nla_nest_end(msg, pinfoattr);
11159
Johannes Berg3b7b72e2011-10-22 19:05:51 +020011160 genlmsg_end(msg, hdr);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020011161
Johannes Berg68eb5502013-11-19 15:19:38 +010011162 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011163 NL80211_MCGRP_MLME, gfp);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020011164 return;
11165
11166 nla_put_failure:
11167 genlmsg_cancel(msg, hdr);
11168 nlmsg_free(msg);
11169}
Johannes Berg947add32013-02-22 22:05:20 +010011170EXPORT_SYMBOL(cfg80211_cqm_rssi_notify);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020011171
Johannes Berg947add32013-02-22 22:05:20 +010011172static void nl80211_gtk_rekey_notify(struct cfg80211_registered_device *rdev,
11173 struct net_device *netdev, const u8 *bssid,
11174 const u8 *replay_ctr, gfp_t gfp)
Johannes Berge5497d72011-07-05 16:35:40 +020011175{
11176 struct sk_buff *msg;
11177 struct nlattr *rekey_attr;
11178 void *hdr;
11179
Thomas Graf58050fc2012-06-28 03:57:45 +000011180 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Johannes Berge5497d72011-07-05 16:35:40 +020011181 if (!msg)
11182 return;
11183
11184 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_REKEY_OFFLOAD);
11185 if (!hdr) {
11186 nlmsg_free(msg);
11187 return;
11188 }
11189
David S. Miller9360ffd2012-03-29 04:41:26 -040011190 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
11191 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
11192 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid))
11193 goto nla_put_failure;
Johannes Berge5497d72011-07-05 16:35:40 +020011194
11195 rekey_attr = nla_nest_start(msg, NL80211_ATTR_REKEY_DATA);
11196 if (!rekey_attr)
11197 goto nla_put_failure;
11198
David S. Miller9360ffd2012-03-29 04:41:26 -040011199 if (nla_put(msg, NL80211_REKEY_DATA_REPLAY_CTR,
11200 NL80211_REPLAY_CTR_LEN, replay_ctr))
11201 goto nla_put_failure;
Johannes Berge5497d72011-07-05 16:35:40 +020011202
11203 nla_nest_end(msg, rekey_attr);
11204
Johannes Berg3b7b72e2011-10-22 19:05:51 +020011205 genlmsg_end(msg, hdr);
Johannes Berge5497d72011-07-05 16:35:40 +020011206
Johannes Berg68eb5502013-11-19 15:19:38 +010011207 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011208 NL80211_MCGRP_MLME, gfp);
Johannes Berge5497d72011-07-05 16:35:40 +020011209 return;
11210
11211 nla_put_failure:
11212 genlmsg_cancel(msg, hdr);
11213 nlmsg_free(msg);
11214}
11215
Johannes Berg947add32013-02-22 22:05:20 +010011216void cfg80211_gtk_rekey_notify(struct net_device *dev, const u8 *bssid,
11217 const u8 *replay_ctr, gfp_t gfp)
11218{
11219 struct wireless_dev *wdev = dev->ieee80211_ptr;
11220 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080011221 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg947add32013-02-22 22:05:20 +010011222
11223 trace_cfg80211_gtk_rekey_notify(dev, bssid);
11224 nl80211_gtk_rekey_notify(rdev, dev, bssid, replay_ctr, gfp);
11225}
11226EXPORT_SYMBOL(cfg80211_gtk_rekey_notify);
11227
11228static void
11229nl80211_pmksa_candidate_notify(struct cfg80211_registered_device *rdev,
11230 struct net_device *netdev, int index,
11231 const u8 *bssid, bool preauth, gfp_t gfp)
Jouni Malinenc9df56b2011-09-16 18:56:23 +030011232{
11233 struct sk_buff *msg;
11234 struct nlattr *attr;
11235 void *hdr;
11236
Thomas Graf58050fc2012-06-28 03:57:45 +000011237 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinenc9df56b2011-09-16 18:56:23 +030011238 if (!msg)
11239 return;
11240
11241 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PMKSA_CANDIDATE);
11242 if (!hdr) {
11243 nlmsg_free(msg);
11244 return;
11245 }
11246
David S. Miller9360ffd2012-03-29 04:41:26 -040011247 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
11248 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex))
11249 goto nla_put_failure;
Jouni Malinenc9df56b2011-09-16 18:56:23 +030011250
11251 attr = nla_nest_start(msg, NL80211_ATTR_PMKSA_CANDIDATE);
11252 if (!attr)
11253 goto nla_put_failure;
11254
David S. Miller9360ffd2012-03-29 04:41:26 -040011255 if (nla_put_u32(msg, NL80211_PMKSA_CANDIDATE_INDEX, index) ||
11256 nla_put(msg, NL80211_PMKSA_CANDIDATE_BSSID, ETH_ALEN, bssid) ||
11257 (preauth &&
11258 nla_put_flag(msg, NL80211_PMKSA_CANDIDATE_PREAUTH)))
11259 goto nla_put_failure;
Jouni Malinenc9df56b2011-09-16 18:56:23 +030011260
11261 nla_nest_end(msg, attr);
11262
Johannes Berg3b7b72e2011-10-22 19:05:51 +020011263 genlmsg_end(msg, hdr);
Jouni Malinenc9df56b2011-09-16 18:56:23 +030011264
Johannes Berg68eb5502013-11-19 15:19:38 +010011265 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011266 NL80211_MCGRP_MLME, gfp);
Jouni Malinenc9df56b2011-09-16 18:56:23 +030011267 return;
11268
11269 nla_put_failure:
11270 genlmsg_cancel(msg, hdr);
11271 nlmsg_free(msg);
11272}
11273
Johannes Berg947add32013-02-22 22:05:20 +010011274void cfg80211_pmksa_candidate_notify(struct net_device *dev, int index,
11275 const u8 *bssid, bool preauth, gfp_t gfp)
11276{
11277 struct wireless_dev *wdev = dev->ieee80211_ptr;
11278 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080011279 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg947add32013-02-22 22:05:20 +010011280
11281 trace_cfg80211_pmksa_candidate_notify(dev, index, bssid, preauth);
11282 nl80211_pmksa_candidate_notify(rdev, dev, index, bssid, preauth, gfp);
11283}
11284EXPORT_SYMBOL(cfg80211_pmksa_candidate_notify);
11285
11286static void nl80211_ch_switch_notify(struct cfg80211_registered_device *rdev,
11287 struct net_device *netdev,
11288 struct cfg80211_chan_def *chandef,
11289 gfp_t gfp)
Thomas Pedersen53145262012-04-06 13:35:47 -070011290{
11291 struct sk_buff *msg;
11292 void *hdr;
11293
Thomas Graf58050fc2012-06-28 03:57:45 +000011294 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Thomas Pedersen53145262012-04-06 13:35:47 -070011295 if (!msg)
11296 return;
11297
11298 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CH_SWITCH_NOTIFY);
11299 if (!hdr) {
11300 nlmsg_free(msg);
11301 return;
11302 }
11303
Johannes Berg683b6d32012-11-08 21:25:48 +010011304 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex))
11305 goto nla_put_failure;
11306
11307 if (nl80211_send_chandef(msg, chandef))
John W. Linville7eab0f62012-04-12 14:25:14 -040011308 goto nla_put_failure;
Thomas Pedersen53145262012-04-06 13:35:47 -070011309
11310 genlmsg_end(msg, hdr);
11311
Johannes Berg68eb5502013-11-19 15:19:38 +010011312 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011313 NL80211_MCGRP_MLME, gfp);
Thomas Pedersen53145262012-04-06 13:35:47 -070011314 return;
11315
11316 nla_put_failure:
11317 genlmsg_cancel(msg, hdr);
11318 nlmsg_free(msg);
11319}
11320
Johannes Berg947add32013-02-22 22:05:20 +010011321void cfg80211_ch_switch_notify(struct net_device *dev,
11322 struct cfg80211_chan_def *chandef)
Thomas Pedersen84f10702012-07-12 16:17:33 -070011323{
Johannes Berg947add32013-02-22 22:05:20 +010011324 struct wireless_dev *wdev = dev->ieee80211_ptr;
11325 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080011326 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg947add32013-02-22 22:05:20 +010011327
Simon Wunderliche487eae2013-11-21 18:19:51 +010011328 ASSERT_WDEV_LOCK(wdev);
Johannes Berg947add32013-02-22 22:05:20 +010011329
Simon Wunderliche487eae2013-11-21 18:19:51 +010011330 trace_cfg80211_ch_switch_notify(dev, chandef);
Johannes Berg947add32013-02-22 22:05:20 +010011331
11332 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP &&
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +020011333 wdev->iftype != NL80211_IFTYPE_P2P_GO &&
Chun-Yeow Yeohb8456a12013-10-17 15:55:02 -070011334 wdev->iftype != NL80211_IFTYPE_ADHOC &&
11335 wdev->iftype != NL80211_IFTYPE_MESH_POINT))
Simon Wunderliche487eae2013-11-21 18:19:51 +010011336 return;
Johannes Berg947add32013-02-22 22:05:20 +010011337
Michal Kazior9e0e2962014-01-29 14:22:27 +010011338 wdev->chandef = *chandef;
Janusz Dziedzic96f55f12014-01-24 14:29:21 +010011339 wdev->preset_chandef = *chandef;
Johannes Berg947add32013-02-22 22:05:20 +010011340 nl80211_ch_switch_notify(rdev, dev, chandef, GFP_KERNEL);
Johannes Berg947add32013-02-22 22:05:20 +010011341}
11342EXPORT_SYMBOL(cfg80211_ch_switch_notify);
11343
11344void cfg80211_cqm_txe_notify(struct net_device *dev,
11345 const u8 *peer, u32 num_packets,
11346 u32 rate, u32 intvl, gfp_t gfp)
11347{
11348 struct wireless_dev *wdev = dev->ieee80211_ptr;
11349 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080011350 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Thomas Pedersen84f10702012-07-12 16:17:33 -070011351 struct sk_buff *msg;
11352 struct nlattr *pinfoattr;
11353 void *hdr;
11354
11355 msg = nlmsg_new(NLMSG_GOODSIZE, gfp);
11356 if (!msg)
11357 return;
11358
11359 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM);
11360 if (!hdr) {
11361 nlmsg_free(msg);
11362 return;
11363 }
11364
11365 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg947add32013-02-22 22:05:20 +010011366 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
Thomas Pedersen84f10702012-07-12 16:17:33 -070011367 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer))
11368 goto nla_put_failure;
11369
11370 pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM);
11371 if (!pinfoattr)
11372 goto nla_put_failure;
11373
11374 if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_PKTS, num_packets))
11375 goto nla_put_failure;
11376
11377 if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_RATE, rate))
11378 goto nla_put_failure;
11379
11380 if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_INTVL, intvl))
11381 goto nla_put_failure;
11382
11383 nla_nest_end(msg, pinfoattr);
11384
11385 genlmsg_end(msg, hdr);
11386
Johannes Berg68eb5502013-11-19 15:19:38 +010011387 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011388 NL80211_MCGRP_MLME, gfp);
Thomas Pedersen84f10702012-07-12 16:17:33 -070011389 return;
11390
11391 nla_put_failure:
11392 genlmsg_cancel(msg, hdr);
11393 nlmsg_free(msg);
11394}
Johannes Berg947add32013-02-22 22:05:20 +010011395EXPORT_SYMBOL(cfg80211_cqm_txe_notify);
Thomas Pedersen84f10702012-07-12 16:17:33 -070011396
11397void
Simon Wunderlich04f39042013-02-08 18:16:19 +010011398nl80211_radar_notify(struct cfg80211_registered_device *rdev,
Janusz Dziedzicd2859df2013-11-06 13:55:51 +010011399 const struct cfg80211_chan_def *chandef,
Simon Wunderlich04f39042013-02-08 18:16:19 +010011400 enum nl80211_radar_event event,
11401 struct net_device *netdev, gfp_t gfp)
11402{
11403 struct sk_buff *msg;
11404 void *hdr;
11405
11406 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
11407 if (!msg)
11408 return;
11409
11410 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_RADAR_DETECT);
11411 if (!hdr) {
11412 nlmsg_free(msg);
11413 return;
11414 }
11415
11416 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx))
11417 goto nla_put_failure;
11418
11419 /* NOP and radar events don't need a netdev parameter */
11420 if (netdev) {
11421 struct wireless_dev *wdev = netdev->ieee80211_ptr;
11422
11423 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
11424 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)))
11425 goto nla_put_failure;
11426 }
11427
11428 if (nla_put_u32(msg, NL80211_ATTR_RADAR_EVENT, event))
11429 goto nla_put_failure;
11430
11431 if (nl80211_send_chandef(msg, chandef))
11432 goto nla_put_failure;
11433
Johannes Berg9c90a9f2013-06-04 12:46:03 +020011434 genlmsg_end(msg, hdr);
Simon Wunderlich04f39042013-02-08 18:16:19 +010011435
Johannes Berg68eb5502013-11-19 15:19:38 +010011436 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011437 NL80211_MCGRP_MLME, gfp);
Simon Wunderlich04f39042013-02-08 18:16:19 +010011438 return;
11439
11440 nla_put_failure:
11441 genlmsg_cancel(msg, hdr);
11442 nlmsg_free(msg);
11443}
11444
Johannes Berg947add32013-02-22 22:05:20 +010011445void cfg80211_cqm_pktloss_notify(struct net_device *dev,
11446 const u8 *peer, u32 num_packets, gfp_t gfp)
Johannes Bergc063dbf2010-11-24 08:10:05 +010011447{
Johannes Berg947add32013-02-22 22:05:20 +010011448 struct wireless_dev *wdev = dev->ieee80211_ptr;
11449 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080011450 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Bergc063dbf2010-11-24 08:10:05 +010011451 struct sk_buff *msg;
11452 struct nlattr *pinfoattr;
11453 void *hdr;
11454
Johannes Berg947add32013-02-22 22:05:20 +010011455 trace_cfg80211_cqm_pktloss_notify(dev, peer, num_packets);
11456
Thomas Graf58050fc2012-06-28 03:57:45 +000011457 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Johannes Bergc063dbf2010-11-24 08:10:05 +010011458 if (!msg)
11459 return;
11460
11461 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM);
11462 if (!hdr) {
11463 nlmsg_free(msg);
11464 return;
11465 }
11466
David S. Miller9360ffd2012-03-29 04:41:26 -040011467 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg947add32013-02-22 22:05:20 +010011468 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040011469 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer))
11470 goto nla_put_failure;
Johannes Bergc063dbf2010-11-24 08:10:05 +010011471
11472 pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM);
11473 if (!pinfoattr)
11474 goto nla_put_failure;
11475
David S. Miller9360ffd2012-03-29 04:41:26 -040011476 if (nla_put_u32(msg, NL80211_ATTR_CQM_PKT_LOSS_EVENT, num_packets))
11477 goto nla_put_failure;
Johannes Bergc063dbf2010-11-24 08:10:05 +010011478
11479 nla_nest_end(msg, pinfoattr);
11480
Johannes Berg3b7b72e2011-10-22 19:05:51 +020011481 genlmsg_end(msg, hdr);
Johannes Bergc063dbf2010-11-24 08:10:05 +010011482
Johannes Berg68eb5502013-11-19 15:19:38 +010011483 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011484 NL80211_MCGRP_MLME, gfp);
Johannes Bergc063dbf2010-11-24 08:10:05 +010011485 return;
11486
11487 nla_put_failure:
11488 genlmsg_cancel(msg, hdr);
11489 nlmsg_free(msg);
11490}
Johannes Berg947add32013-02-22 22:05:20 +010011491EXPORT_SYMBOL(cfg80211_cqm_pktloss_notify);
Johannes Bergc063dbf2010-11-24 08:10:05 +010011492
Johannes Berg7f6cf312011-11-04 11:18:15 +010011493void cfg80211_probe_status(struct net_device *dev, const u8 *addr,
11494 u64 cookie, bool acked, gfp_t gfp)
11495{
11496 struct wireless_dev *wdev = dev->ieee80211_ptr;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080011497 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Johannes Berg7f6cf312011-11-04 11:18:15 +010011498 struct sk_buff *msg;
11499 void *hdr;
Johannes Berg7f6cf312011-11-04 11:18:15 +010011500
Beni Lev4ee3e062012-08-27 12:49:39 +030011501 trace_cfg80211_probe_status(dev, addr, cookie, acked);
11502
Thomas Graf58050fc2012-06-28 03:57:45 +000011503 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Beni Lev4ee3e062012-08-27 12:49:39 +030011504
Johannes Berg7f6cf312011-11-04 11:18:15 +010011505 if (!msg)
11506 return;
11507
11508 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PROBE_CLIENT);
11509 if (!hdr) {
11510 nlmsg_free(msg);
11511 return;
11512 }
11513
David S. Miller9360ffd2012-03-29 04:41:26 -040011514 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
11515 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
11516 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) ||
11517 nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie) ||
11518 (acked && nla_put_flag(msg, NL80211_ATTR_ACK)))
11519 goto nla_put_failure;
Johannes Berg7f6cf312011-11-04 11:18:15 +010011520
Johannes Berg9c90a9f2013-06-04 12:46:03 +020011521 genlmsg_end(msg, hdr);
Johannes Berg7f6cf312011-11-04 11:18:15 +010011522
Johannes Berg68eb5502013-11-19 15:19:38 +010011523 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011524 NL80211_MCGRP_MLME, gfp);
Johannes Berg7f6cf312011-11-04 11:18:15 +010011525 return;
11526
11527 nla_put_failure:
11528 genlmsg_cancel(msg, hdr);
11529 nlmsg_free(msg);
11530}
11531EXPORT_SYMBOL(cfg80211_probe_status);
11532
Johannes Berg5e760232011-11-04 11:18:17 +010011533void cfg80211_report_obss_beacon(struct wiphy *wiphy,
11534 const u8 *frame, size_t len,
Ben Greear37c73b52012-10-26 14:49:25 -070011535 int freq, int sig_dbm)
Johannes Berg5e760232011-11-04 11:18:17 +010011536{
Zhao, Gangf26cbf42014-04-21 12:53:03 +080011537 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg5e760232011-11-04 11:18:17 +010011538 struct sk_buff *msg;
11539 void *hdr;
Ben Greear37c73b52012-10-26 14:49:25 -070011540 struct cfg80211_beacon_registration *reg;
Johannes Berg5e760232011-11-04 11:18:17 +010011541
Beni Lev4ee3e062012-08-27 12:49:39 +030011542 trace_cfg80211_report_obss_beacon(wiphy, frame, len, freq, sig_dbm);
11543
Ben Greear37c73b52012-10-26 14:49:25 -070011544 spin_lock_bh(&rdev->beacon_registrations_lock);
11545 list_for_each_entry(reg, &rdev->beacon_registrations, list) {
11546 msg = nlmsg_new(len + 100, GFP_ATOMIC);
11547 if (!msg) {
11548 spin_unlock_bh(&rdev->beacon_registrations_lock);
11549 return;
11550 }
Johannes Berg5e760232011-11-04 11:18:17 +010011551
Ben Greear37c73b52012-10-26 14:49:25 -070011552 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME);
11553 if (!hdr)
11554 goto nla_put_failure;
Johannes Berg5e760232011-11-04 11:18:17 +010011555
Ben Greear37c73b52012-10-26 14:49:25 -070011556 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
11557 (freq &&
11558 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq)) ||
11559 (sig_dbm &&
11560 nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) ||
11561 nla_put(msg, NL80211_ATTR_FRAME, len, frame))
11562 goto nla_put_failure;
11563
11564 genlmsg_end(msg, hdr);
11565
11566 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, reg->nlportid);
Johannes Berg5e760232011-11-04 11:18:17 +010011567 }
Ben Greear37c73b52012-10-26 14:49:25 -070011568 spin_unlock_bh(&rdev->beacon_registrations_lock);
Johannes Berg5e760232011-11-04 11:18:17 +010011569 return;
11570
11571 nla_put_failure:
Ben Greear37c73b52012-10-26 14:49:25 -070011572 spin_unlock_bh(&rdev->beacon_registrations_lock);
11573 if (hdr)
11574 genlmsg_cancel(msg, hdr);
Johannes Berg5e760232011-11-04 11:18:17 +010011575 nlmsg_free(msg);
11576}
11577EXPORT_SYMBOL(cfg80211_report_obss_beacon);
11578
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010011579#ifdef CONFIG_PM
11580void cfg80211_report_wowlan_wakeup(struct wireless_dev *wdev,
11581 struct cfg80211_wowlan_wakeup *wakeup,
11582 gfp_t gfp)
11583{
Zhao, Gangf26cbf42014-04-21 12:53:03 +080011584 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010011585 struct sk_buff *msg;
11586 void *hdr;
Johannes Berg9c90a9f2013-06-04 12:46:03 +020011587 int size = 200;
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010011588
11589 trace_cfg80211_report_wowlan_wakeup(wdev->wiphy, wdev, wakeup);
11590
11591 if (wakeup)
11592 size += wakeup->packet_present_len;
11593
11594 msg = nlmsg_new(size, gfp);
11595 if (!msg)
11596 return;
11597
11598 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_WOWLAN);
11599 if (!hdr)
11600 goto free_msg;
11601
11602 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
11603 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)))
11604 goto free_msg;
11605
11606 if (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
11607 wdev->netdev->ifindex))
11608 goto free_msg;
11609
11610 if (wakeup) {
11611 struct nlattr *reasons;
11612
11613 reasons = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS);
Johannes Berg7fa322c2013-10-25 11:16:58 +020011614 if (!reasons)
11615 goto free_msg;
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010011616
11617 if (wakeup->disconnect &&
11618 nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT))
11619 goto free_msg;
11620 if (wakeup->magic_pkt &&
11621 nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT))
11622 goto free_msg;
11623 if (wakeup->gtk_rekey_failure &&
11624 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE))
11625 goto free_msg;
11626 if (wakeup->eap_identity_req &&
11627 nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST))
11628 goto free_msg;
11629 if (wakeup->four_way_handshake &&
11630 nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE))
11631 goto free_msg;
11632 if (wakeup->rfkill_release &&
11633 nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE))
11634 goto free_msg;
11635
11636 if (wakeup->pattern_idx >= 0 &&
11637 nla_put_u32(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN,
11638 wakeup->pattern_idx))
11639 goto free_msg;
11640
Johannes Bergae917c92013-10-25 11:05:22 +020011641 if (wakeup->tcp_match &&
11642 nla_put_flag(msg, NL80211_WOWLAN_TRIG_WAKEUP_TCP_MATCH))
11643 goto free_msg;
Johannes Berg2a0e0472013-01-23 22:57:40 +010011644
Johannes Bergae917c92013-10-25 11:05:22 +020011645 if (wakeup->tcp_connlost &&
11646 nla_put_flag(msg, NL80211_WOWLAN_TRIG_WAKEUP_TCP_CONNLOST))
11647 goto free_msg;
Johannes Berg2a0e0472013-01-23 22:57:40 +010011648
Johannes Bergae917c92013-10-25 11:05:22 +020011649 if (wakeup->tcp_nomoretokens &&
11650 nla_put_flag(msg,
11651 NL80211_WOWLAN_TRIG_WAKEUP_TCP_NOMORETOKENS))
11652 goto free_msg;
Johannes Berg2a0e0472013-01-23 22:57:40 +010011653
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010011654 if (wakeup->packet) {
11655 u32 pkt_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211;
11656 u32 len_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211_LEN;
11657
11658 if (!wakeup->packet_80211) {
11659 pkt_attr =
11660 NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023;
11661 len_attr =
11662 NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023_LEN;
11663 }
11664
11665 if (wakeup->packet_len &&
11666 nla_put_u32(msg, len_attr, wakeup->packet_len))
11667 goto free_msg;
11668
11669 if (nla_put(msg, pkt_attr, wakeup->packet_present_len,
11670 wakeup->packet))
11671 goto free_msg;
11672 }
11673
11674 nla_nest_end(msg, reasons);
11675 }
11676
Johannes Berg9c90a9f2013-06-04 12:46:03 +020011677 genlmsg_end(msg, hdr);
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010011678
Johannes Berg68eb5502013-11-19 15:19:38 +010011679 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011680 NL80211_MCGRP_MLME, gfp);
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010011681 return;
11682
11683 free_msg:
11684 nlmsg_free(msg);
11685}
11686EXPORT_SYMBOL(cfg80211_report_wowlan_wakeup);
11687#endif
11688
Jouni Malinen3475b092012-11-16 22:49:57 +020011689void cfg80211_tdls_oper_request(struct net_device *dev, const u8 *peer,
11690 enum nl80211_tdls_operation oper,
11691 u16 reason_code, gfp_t gfp)
11692{
11693 struct wireless_dev *wdev = dev->ieee80211_ptr;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080011694 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Jouni Malinen3475b092012-11-16 22:49:57 +020011695 struct sk_buff *msg;
11696 void *hdr;
Jouni Malinen3475b092012-11-16 22:49:57 +020011697
11698 trace_cfg80211_tdls_oper_request(wdev->wiphy, dev, peer, oper,
11699 reason_code);
11700
11701 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
11702 if (!msg)
11703 return;
11704
11705 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_TDLS_OPER);
11706 if (!hdr) {
11707 nlmsg_free(msg);
11708 return;
11709 }
11710
11711 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
11712 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
11713 nla_put_u8(msg, NL80211_ATTR_TDLS_OPERATION, oper) ||
11714 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer) ||
11715 (reason_code > 0 &&
11716 nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason_code)))
11717 goto nla_put_failure;
11718
Johannes Berg9c90a9f2013-06-04 12:46:03 +020011719 genlmsg_end(msg, hdr);
Jouni Malinen3475b092012-11-16 22:49:57 +020011720
Johannes Berg68eb5502013-11-19 15:19:38 +010011721 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011722 NL80211_MCGRP_MLME, gfp);
Jouni Malinen3475b092012-11-16 22:49:57 +020011723 return;
11724
11725 nla_put_failure:
11726 genlmsg_cancel(msg, hdr);
11727 nlmsg_free(msg);
11728}
11729EXPORT_SYMBOL(cfg80211_tdls_oper_request);
11730
Jouni Malinen026331c2010-02-15 12:53:10 +020011731static int nl80211_netlink_notify(struct notifier_block * nb,
11732 unsigned long state,
11733 void *_notify)
11734{
11735 struct netlink_notify *notify = _notify;
11736 struct cfg80211_registered_device *rdev;
11737 struct wireless_dev *wdev;
Ben Greear37c73b52012-10-26 14:49:25 -070011738 struct cfg80211_beacon_registration *reg, *tmp;
Jouni Malinen026331c2010-02-15 12:53:10 +020011739
11740 if (state != NETLINK_URELEASE)
11741 return NOTIFY_DONE;
11742
11743 rcu_read_lock();
11744
Johannes Berg5e760232011-11-04 11:18:17 +010011745 list_for_each_entry_rcu(rdev, &cfg80211_rdev_list, list) {
Johannes Berg78f22b62014-03-24 17:57:27 +010011746 bool schedule_destroy_work = false;
11747
11748 list_for_each_entry_rcu(wdev, &rdev->wdev_list, list) {
Eric W. Biederman15e47302012-09-07 20:12:54 +000011749 cfg80211_mlme_unregister_socket(wdev, notify->portid);
Ben Greear37c73b52012-10-26 14:49:25 -070011750
Johannes Berg78f22b62014-03-24 17:57:27 +010011751 if (wdev->owner_nlportid == notify->portid)
11752 schedule_destroy_work = true;
11753 }
11754
Ben Greear37c73b52012-10-26 14:49:25 -070011755 spin_lock_bh(&rdev->beacon_registrations_lock);
11756 list_for_each_entry_safe(reg, tmp, &rdev->beacon_registrations,
11757 list) {
11758 if (reg->nlportid == notify->portid) {
11759 list_del(&reg->list);
11760 kfree(reg);
11761 break;
11762 }
11763 }
11764 spin_unlock_bh(&rdev->beacon_registrations_lock);
Johannes Berg78f22b62014-03-24 17:57:27 +010011765
11766 if (schedule_destroy_work) {
11767 struct cfg80211_iface_destroy *destroy;
11768
11769 destroy = kzalloc(sizeof(*destroy), GFP_ATOMIC);
11770 if (destroy) {
11771 destroy->nlportid = notify->portid;
11772 spin_lock(&rdev->destroy_list_lock);
11773 list_add(&destroy->list, &rdev->destroy_list);
11774 spin_unlock(&rdev->destroy_list_lock);
11775 schedule_work(&rdev->destroy_work);
11776 }
11777 }
Johannes Berg5e760232011-11-04 11:18:17 +010011778 }
Jouni Malinen026331c2010-02-15 12:53:10 +020011779
11780 rcu_read_unlock();
11781
Zhao, Gang6784c7d2014-04-21 12:53:04 +080011782 return NOTIFY_OK;
Jouni Malinen026331c2010-02-15 12:53:10 +020011783}
11784
11785static struct notifier_block nl80211_netlink_notifier = {
11786 .notifier_call = nl80211_netlink_notify,
11787};
11788
Jouni Malinen355199e2013-02-27 17:14:27 +020011789void cfg80211_ft_event(struct net_device *netdev,
11790 struct cfg80211_ft_event_params *ft_event)
11791{
11792 struct wiphy *wiphy = netdev->ieee80211_ptr->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080011793 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Jouni Malinen355199e2013-02-27 17:14:27 +020011794 struct sk_buff *msg;
11795 void *hdr;
Jouni Malinen355199e2013-02-27 17:14:27 +020011796
11797 trace_cfg80211_ft_event(wiphy, netdev, ft_event);
11798
11799 if (!ft_event->target_ap)
11800 return;
11801
11802 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
11803 if (!msg)
11804 return;
11805
11806 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FT_EVENT);
Johannes Bergae917c92013-10-25 11:05:22 +020011807 if (!hdr)
11808 goto out;
Jouni Malinen355199e2013-02-27 17:14:27 +020011809
Johannes Bergae917c92013-10-25 11:05:22 +020011810 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
11811 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
11812 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, ft_event->target_ap))
11813 goto out;
11814
11815 if (ft_event->ies &&
11816 nla_put(msg, NL80211_ATTR_IE, ft_event->ies_len, ft_event->ies))
11817 goto out;
11818 if (ft_event->ric_ies &&
11819 nla_put(msg, NL80211_ATTR_IE_RIC, ft_event->ric_ies_len,
11820 ft_event->ric_ies))
11821 goto out;
Jouni Malinen355199e2013-02-27 17:14:27 +020011822
Johannes Berg9c90a9f2013-06-04 12:46:03 +020011823 genlmsg_end(msg, hdr);
Jouni Malinen355199e2013-02-27 17:14:27 +020011824
Johannes Berg68eb5502013-11-19 15:19:38 +010011825 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011826 NL80211_MCGRP_MLME, GFP_KERNEL);
Johannes Bergae917c92013-10-25 11:05:22 +020011827 return;
11828 out:
11829 nlmsg_free(msg);
Jouni Malinen355199e2013-02-27 17:14:27 +020011830}
11831EXPORT_SYMBOL(cfg80211_ft_event);
11832
Arend van Spriel5de17982013-04-18 15:49:00 +020011833void cfg80211_crit_proto_stopped(struct wireless_dev *wdev, gfp_t gfp)
11834{
11835 struct cfg80211_registered_device *rdev;
11836 struct sk_buff *msg;
11837 void *hdr;
11838 u32 nlportid;
11839
Zhao, Gangf26cbf42014-04-21 12:53:03 +080011840 rdev = wiphy_to_rdev(wdev->wiphy);
Arend van Spriel5de17982013-04-18 15:49:00 +020011841 if (!rdev->crit_proto_nlportid)
11842 return;
11843
11844 nlportid = rdev->crit_proto_nlportid;
11845 rdev->crit_proto_nlportid = 0;
11846
11847 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
11848 if (!msg)
11849 return;
11850
11851 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CRIT_PROTOCOL_STOP);
11852 if (!hdr)
11853 goto nla_put_failure;
11854
11855 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
11856 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)))
11857 goto nla_put_failure;
11858
11859 genlmsg_end(msg, hdr);
11860
11861 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid);
11862 return;
11863
11864 nla_put_failure:
11865 if (hdr)
11866 genlmsg_cancel(msg, hdr);
11867 nlmsg_free(msg);
11868
11869}
11870EXPORT_SYMBOL(cfg80211_crit_proto_stopped);
11871
Johannes Berg348baf02014-01-24 14:06:29 +010011872void nl80211_send_ap_stopped(struct wireless_dev *wdev)
11873{
11874 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080011875 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg348baf02014-01-24 14:06:29 +010011876 struct sk_buff *msg;
11877 void *hdr;
11878
11879 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
11880 if (!msg)
11881 return;
11882
11883 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_STOP_AP);
11884 if (!hdr)
11885 goto out;
11886
11887 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
11888 nla_put_u32(msg, NL80211_ATTR_IFINDEX, wdev->netdev->ifindex) ||
11889 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)))
11890 goto out;
11891
11892 genlmsg_end(msg, hdr);
11893
11894 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(wiphy), msg, 0,
11895 NL80211_MCGRP_MLME, GFP_KERNEL);
11896 return;
11897 out:
11898 nlmsg_free(msg);
11899}
11900
Johannes Berg55682962007-09-20 13:09:35 -040011901/* initialisation/exit functions */
11902
11903int nl80211_init(void)
11904{
Michał Mirosław0d63cbb2009-05-21 10:34:06 +000011905 int err;
Johannes Berg55682962007-09-20 13:09:35 -040011906
Johannes Berg2a94fe42013-11-19 15:19:39 +010011907 err = genl_register_family_with_ops_groups(&nl80211_fam, nl80211_ops,
11908 nl80211_mcgrps);
Johannes Berg55682962007-09-20 13:09:35 -040011909 if (err)
11910 return err;
11911
Jouni Malinen026331c2010-02-15 12:53:10 +020011912 err = netlink_register_notifier(&nl80211_netlink_notifier);
11913 if (err)
11914 goto err_out;
11915
Johannes Berg55682962007-09-20 13:09:35 -040011916 return 0;
11917 err_out:
11918 genl_unregister_family(&nl80211_fam);
11919 return err;
11920}
11921
11922void nl80211_exit(void)
11923{
Jouni Malinen026331c2010-02-15 12:53:10 +020011924 netlink_unregister_notifier(&nl80211_netlink_notifier);
Johannes Berg55682962007-09-20 13:09:35 -040011925 genl_unregister_family(&nl80211_fam);
11926}