blob: ba4f1723c83ad2eb094c15a8794fedb7b6f7a404 [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 Malinen36aedc902008-08-25 11:58:58 +0300272
Javier Cardona24bdd9f2010-12-16 17:37:48 -0800273 [NL80211_ATTR_MESH_CONFIG] = { .type = NLA_NESTED },
Javier Cardona15d5dda2011-04-07 15:08:28 -0700274 [NL80211_ATTR_SUPPORT_MESH_AUTH] = { .type = NLA_FLAG },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -0700275
Johannes Berg6c739412011-11-03 09:27:01 +0100276 [NL80211_ATTR_HT_CAPABILITY] = { .len = NL80211_HT_CAPABILITY_LEN },
Jouni Malinen9aed3cc2009-01-13 16:03:29 +0200277
278 [NL80211_ATTR_MGMT_SUBTYPE] = { .type = NLA_U8 },
279 [NL80211_ATTR_IE] = { .type = NLA_BINARY,
280 .len = IEEE80211_MAX_DATA_LEN },
Johannes Berg2a519312009-02-10 21:25:55 +0100281 [NL80211_ATTR_SCAN_FREQUENCIES] = { .type = NLA_NESTED },
282 [NL80211_ATTR_SCAN_SSIDS] = { .type = NLA_NESTED },
Jouni Malinen636a5d32009-03-19 13:39:22 +0200283
284 [NL80211_ATTR_SSID] = { .type = NLA_BINARY,
285 .len = IEEE80211_MAX_SSID_LEN },
286 [NL80211_ATTR_AUTH_TYPE] = { .type = NLA_U32 },
287 [NL80211_ATTR_REASON_CODE] = { .type = NLA_U16 },
Johannes Berg04a773a2009-04-19 21:24:32 +0200288 [NL80211_ATTR_FREQ_FIXED] = { .type = NLA_FLAG },
Jouni Malinen1965c852009-04-22 21:38:25 +0300289 [NL80211_ATTR_TIMED_OUT] = { .type = NLA_FLAG },
Jouni Malinendc6382c2009-05-06 22:09:37 +0300290 [NL80211_ATTR_USE_MFP] = { .type = NLA_U32 },
Johannes Bergeccb8e82009-05-11 21:57:56 +0300291 [NL80211_ATTR_STA_FLAGS2] = {
292 .len = sizeof(struct nl80211_sta_flag_update),
293 },
Jouni Malinen3f77316c2009-05-11 21:57:57 +0300294 [NL80211_ATTR_CONTROL_PORT] = { .type = NLA_FLAG },
Johannes Bergc0692b82010-08-27 14:26:53 +0300295 [NL80211_ATTR_CONTROL_PORT_ETHERTYPE] = { .type = NLA_U16 },
296 [NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT] = { .type = NLA_FLAG },
Samuel Ortizb23aa672009-07-01 21:26:54 +0200297 [NL80211_ATTR_PRIVACY] = { .type = NLA_FLAG },
298 [NL80211_ATTR_CIPHER_SUITE_GROUP] = { .type = NLA_U32 },
299 [NL80211_ATTR_WPA_VERSIONS] = { .type = NLA_U32 },
Johannes Berg463d0182009-07-14 00:33:35 +0200300 [NL80211_ATTR_PID] = { .type = NLA_U32 },
Felix Fietkau8b787642009-11-10 18:53:10 +0100301 [NL80211_ATTR_4ADDR] = { .type = NLA_U8 },
Samuel Ortiz67fbb162009-11-24 23:59:15 +0100302 [NL80211_ATTR_PMKID] = { .type = NLA_BINARY,
303 .len = WLAN_PMKID_LEN },
Jouni Malinen9588bbd2009-12-23 13:15:41 +0100304 [NL80211_ATTR_DURATION] = { .type = NLA_U32 },
305 [NL80211_ATTR_COOKIE] = { .type = NLA_U64 },
Jouni Malinen13ae75b2009-12-29 12:59:45 +0200306 [NL80211_ATTR_TX_RATES] = { .type = NLA_NESTED },
Jouni Malinen026331c2010-02-15 12:53:10 +0200307 [NL80211_ATTR_FRAME] = { .type = NLA_BINARY,
308 .len = IEEE80211_MAX_DATA_LEN },
309 [NL80211_ATTR_FRAME_MATCH] = { .type = NLA_BINARY, },
Kalle Valoffb9eb32010-02-17 17:58:10 +0200310 [NL80211_ATTR_PS_STATE] = { .type = NLA_U32 },
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +0200311 [NL80211_ATTR_CQM] = { .type = NLA_NESTED, },
Jouni Malinend5cdfac2010-04-04 09:37:19 +0300312 [NL80211_ATTR_LOCAL_STATE_CHANGE] = { .type = NLA_FLAG },
Felix Fietkaufd8aaaf2010-04-27 01:23:35 +0200313 [NL80211_ATTR_AP_ISOLATE] = { .type = NLA_U8 },
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +0300314 [NL80211_ATTR_WIPHY_TX_POWER_SETTING] = { .type = NLA_U32 },
315 [NL80211_ATTR_WIPHY_TX_POWER_LEVEL] = { .type = NLA_U32 },
Johannes Berg2e161f72010-08-12 15:38:38 +0200316 [NL80211_ATTR_FRAME_TYPE] = { .type = NLA_U16 },
Bruno Randolfafe0cbf2010-11-10 12:50:50 +0900317 [NL80211_ATTR_WIPHY_ANTENNA_TX] = { .type = NLA_U32 },
318 [NL80211_ATTR_WIPHY_ANTENNA_RX] = { .type = NLA_U32 },
Felix Fietkau885a46d2010-11-11 15:07:22 +0100319 [NL80211_ATTR_MCAST_RATE] = { .type = NLA_U32 },
Johannes Bergf7ca38d2010-11-25 10:02:29 +0100320 [NL80211_ATTR_OFFCHANNEL_TX_OK] = { .type = NLA_FLAG },
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100321 [NL80211_ATTR_KEY_DEFAULT_TYPES] = { .type = NLA_NESTED },
Johannes Bergff1b6e62011-05-04 15:37:28 +0200322 [NL80211_ATTR_WOWLAN_TRIGGERS] = { .type = NLA_NESTED },
Javier Cardona9c3990a2011-05-03 16:57:11 -0700323 [NL80211_ATTR_STA_PLINK_STATE] = { .type = NLA_U8 },
Luciano Coelhobbe6ad62011-05-11 17:09:37 +0300324 [NL80211_ATTR_SCHED_SCAN_INTERVAL] = { .type = NLA_U32 },
Johannes Berge5497d72011-07-05 16:35:40 +0200325 [NL80211_ATTR_REKEY_DATA] = { .type = NLA_NESTED },
Johannes Berg34850ab2011-07-18 18:08:35 +0200326 [NL80211_ATTR_SCAN_SUPP_RATES] = { .type = NLA_NESTED },
Jouni Malinen32e9de82011-08-10 23:53:31 +0300327 [NL80211_ATTR_HIDDEN_SSID] = { .type = NLA_U32 },
Jouni Malinen9946ecf2011-08-10 23:55:56 +0300328 [NL80211_ATTR_IE_PROBE_RESP] = { .type = NLA_BINARY,
329 .len = IEEE80211_MAX_DATA_LEN },
330 [NL80211_ATTR_IE_ASSOC_RESP] = { .type = NLA_BINARY,
331 .len = IEEE80211_MAX_DATA_LEN },
Vivek Natarajanf4b34b52011-08-29 14:23:03 +0530332 [NL80211_ATTR_ROAM_SUPPORT] = { .type = NLA_FLAG },
Luciano Coelhoa1f1c212011-08-31 16:01:48 +0300333 [NL80211_ATTR_SCHED_SCAN_MATCH] = { .type = NLA_NESTED },
Rajkumar Manoharane9f935e2011-09-25 14:53:30 +0530334 [NL80211_ATTR_TX_NO_CCK_RATE] = { .type = NLA_FLAG },
Arik Nemtsov109086c2011-09-28 14:12:50 +0300335 [NL80211_ATTR_TDLS_ACTION] = { .type = NLA_U8 },
336 [NL80211_ATTR_TDLS_DIALOG_TOKEN] = { .type = NLA_U8 },
337 [NL80211_ATTR_TDLS_OPERATION] = { .type = NLA_U8 },
338 [NL80211_ATTR_TDLS_SUPPORT] = { .type = NLA_FLAG },
339 [NL80211_ATTR_TDLS_EXTERNAL_SETUP] = { .type = NLA_FLAG },
Johannes Berge247bd902011-11-04 11:18:21 +0100340 [NL80211_ATTR_DONT_WAIT_FOR_ACK] = { .type = NLA_FLAG },
Arik Nemtsov00f740e2011-11-10 11:28:56 +0200341 [NL80211_ATTR_PROBE_RESP] = { .type = NLA_BINARY,
342 .len = IEEE80211_MAX_DATA_LEN },
Luis R. Rodriguez8b60b072011-10-11 10:59:02 -0700343 [NL80211_ATTR_DFS_REGION] = { .type = NLA_U8 },
Ben Greear7e7c8922011-11-18 11:31:59 -0800344 [NL80211_ATTR_DISABLE_HT] = { .type = NLA_FLAG },
345 [NL80211_ATTR_HT_CAPABILITY_MASK] = {
346 .len = NL80211_HT_CAPABILITY_LEN
347 },
Simon Wunderlich1d9d9212011-11-18 14:20:43 +0100348 [NL80211_ATTR_NOACK_MAP] = { .type = NLA_U16 },
Vasanthakumar Thiagarajan1b658f12012-03-02 15:50:02 +0530349 [NL80211_ATTR_INACTIVITY_TIMEOUT] = { .type = NLA_U16 },
Bala Shanmugam4486ea92012-03-07 17:27:12 +0530350 [NL80211_ATTR_BG_SCAN_PERIOD] = { .type = NLA_U16 },
Johannes Berg89a54e42012-06-15 14:33:17 +0200351 [NL80211_ATTR_WDEV] = { .type = NLA_U64 },
Luis R. Rodriguez57b5ce02012-07-12 11:49:18 -0700352 [NL80211_ATTR_USER_REG_HINT_TYPE] = { .type = NLA_U32 },
Jouni Malinene39e5b52012-09-30 19:29:39 +0300353 [NL80211_ATTR_SAE_DATA] = { .type = NLA_BINARY, },
Mahesh Palivelaf461be3e2012-10-11 08:04:52 +0000354 [NL80211_ATTR_VHT_CAPABILITY] = { .len = NL80211_VHT_CAPABILITY_LEN },
Sam Lefflered4737712012-10-11 21:03:31 -0700355 [NL80211_ATTR_SCAN_FLAGS] = { .type = NLA_U32 },
Johannes Berg53cabad2012-11-14 15:17:28 +0100356 [NL80211_ATTR_P2P_CTWINDOW] = { .type = NLA_U8 },
357 [NL80211_ATTR_P2P_OPPPS] = { .type = NLA_U8 },
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +0530358 [NL80211_ATTR_ACL_POLICY] = {. type = NLA_U32 },
359 [NL80211_ATTR_MAC_ADDRS] = { .type = NLA_NESTED },
Jouni Malinen9d62a982013-02-14 21:10:13 +0200360 [NL80211_ATTR_STA_CAPABILITY] = { .type = NLA_U16 },
361 [NL80211_ATTR_STA_EXT_CAPABILITY] = { .type = NLA_BINARY, },
Johannes Berg3713b4e2013-02-14 16:19:38 +0100362 [NL80211_ATTR_SPLIT_WIPHY_DUMP] = { .type = NLA_FLAG, },
Johannes Bergee2aca32013-02-21 17:36:01 +0100363 [NL80211_ATTR_DISABLE_VHT] = { .type = NLA_FLAG },
364 [NL80211_ATTR_VHT_CAPABILITY_MASK] = {
365 .len = NL80211_VHT_CAPABILITY_LEN,
366 },
Jouni Malinen355199e2013-02-27 17:14:27 +0200367 [NL80211_ATTR_MDID] = { .type = NLA_U16 },
368 [NL80211_ATTR_IE_RIC] = { .type = NLA_BINARY,
369 .len = IEEE80211_MAX_DATA_LEN },
Jouni Malinen5e4b6f52013-05-16 20:11:08 +0300370 [NL80211_ATTR_PEER_AID] = { .type = NLA_U16 },
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +0200371 [NL80211_ATTR_CH_SWITCH_COUNT] = { .type = NLA_U32 },
372 [NL80211_ATTR_CH_SWITCH_BLOCK_TX] = { .type = NLA_FLAG },
373 [NL80211_ATTR_CSA_IES] = { .type = NLA_NESTED },
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 Berg86e8cf92013-06-19 10:57:22 +02001500 if (state->split) {
Arend van Spriel5de17982013-04-18 15:49:00 +02001501 CMD(crit_proto_start, CRIT_PROTOCOL_START);
1502 CMD(crit_proto_stop, CRIT_PROTOCOL_STOP);
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001503 if (rdev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH)
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02001504 CMD(channel_switch, CHANNEL_SWITCH);
Arend van Spriel5de17982013-04-18 15:49:00 +02001505 }
Kyeyoon Parkfa9ffc72013-12-16 23:01:30 -08001506 CMD(set_qos_map, SET_QOS_MAP);
Johannes Berg8fdc6212009-03-14 09:34:01 +01001507
Kalle Valo4745fc02011-11-17 19:06:10 +02001508#ifdef CONFIG_NL80211_TESTMODE
Johannes Berg3713b4e2013-02-14 16:19:38 +01001509 CMD(testmode_cmd, TESTMODE);
Kalle Valo4745fc02011-11-17 19:06:10 +02001510#endif
1511
Johannes Berg8fdc6212009-03-14 09:34:01 +01001512#undef CMD
Samuel Ortizb23aa672009-07-01 21:26:54 +02001513
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001514 if (rdev->ops->connect || rdev->ops->auth) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001515 i++;
1516 if (nla_put_u32(msg, i, NL80211_CMD_CONNECT))
Johannes Berg2e161f72010-08-12 15:38:38 +02001517 goto nla_put_failure;
Johannes Berg2e161f72010-08-12 15:38:38 +02001518 }
1519
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001520 if (rdev->ops->disconnect || rdev->ops->deauth) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001521 i++;
1522 if (nla_put_u32(msg, i, NL80211_CMD_DISCONNECT))
1523 goto nla_put_failure;
1524 }
Johannes Berg74b70a42010-08-24 12:15:53 +02001525
Johannes Berg3713b4e2013-02-14 16:19:38 +01001526 nla_nest_end(msg, nl_cmds);
Johannes Berg86e8cf92013-06-19 10:57:22 +02001527 state->split_start++;
1528 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001529 break;
1530 case 5:
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001531 if (rdev->ops->remain_on_channel &&
1532 (rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001533 nla_put_u32(msg,
1534 NL80211_ATTR_MAX_REMAIN_ON_CHANNEL_DURATION,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001535 rdev->wiphy.max_remain_on_channel_duration))
Johannes Berg2e161f72010-08-12 15:38:38 +02001536 goto nla_put_failure;
1537
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001538 if ((rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001539 nla_put_flag(msg, NL80211_ATTR_OFFCHANNEL_TX_OK))
1540 goto nla_put_failure;
Johannes Berg2e161f72010-08-12 15:38:38 +02001541
Johannes Berg3713b4e2013-02-14 16:19:38 +01001542 if (nl80211_send_mgmt_stypes(msg, mgmt_stypes))
1543 goto nla_put_failure;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001544 state->split_start++;
1545 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001546 break;
1547 case 6:
Johannes Bergdfb89c52012-06-27 09:23:48 +02001548#ifdef CONFIG_PM
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001549 if (nl80211_send_wowlan(msg, rdev, state->split))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001550 goto nla_put_failure;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001551 state->split_start++;
1552 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001553 break;
1554#else
Johannes Berg86e8cf92013-06-19 10:57:22 +02001555 state->split_start++;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001556#endif
1557 case 7:
1558 if (nl80211_put_iftypes(msg, NL80211_ATTR_SOFTWARE_IFTYPES,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001559 rdev->wiphy.software_iftypes))
Johannes Bergff1b6e62011-05-04 15:37:28 +02001560 goto nla_put_failure;
1561
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001562 if (nl80211_put_iface_combinations(&rdev->wiphy, msg,
Johannes Berg86e8cf92013-06-19 10:57:22 +02001563 state->split))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001564 goto nla_put_failure;
Johannes Bergff1b6e62011-05-04 15:37:28 +02001565
Johannes Berg86e8cf92013-06-19 10:57:22 +02001566 state->split_start++;
1567 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001568 break;
1569 case 8:
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001570 if ((rdev->wiphy.flags & WIPHY_FLAG_HAVE_AP_SME) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001571 nla_put_u32(msg, NL80211_ATTR_DEVICE_AP_SME,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001572 rdev->wiphy.ap_sme_capa))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001573 goto nla_put_failure;
1574
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001575 features = rdev->wiphy.features;
Johannes Bergfe1abaf2013-02-27 15:39:45 +01001576 /*
1577 * We can only add the per-channel limit information if the
1578 * dump is split, otherwise it makes it too big. Therefore
1579 * only advertise it in that case.
1580 */
Johannes Berg86e8cf92013-06-19 10:57:22 +02001581 if (state->split)
Johannes Bergfe1abaf2013-02-27 15:39:45 +01001582 features |= NL80211_FEATURE_ADVERTISE_CHAN_LIMITS;
1583 if (nla_put_u32(msg, NL80211_ATTR_FEATURE_FLAGS, features))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001584 goto nla_put_failure;
1585
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001586 if (rdev->wiphy.ht_capa_mod_mask &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001587 nla_put(msg, NL80211_ATTR_HT_CAPABILITY_MASK,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001588 sizeof(*rdev->wiphy.ht_capa_mod_mask),
1589 rdev->wiphy.ht_capa_mod_mask))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001590 goto nla_put_failure;
1591
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001592 if (rdev->wiphy.flags & WIPHY_FLAG_HAVE_AP_SME &&
1593 rdev->wiphy.max_acl_mac_addrs &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001594 nla_put_u32(msg, NL80211_ATTR_MAC_ACL_MAX,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001595 rdev->wiphy.max_acl_mac_addrs))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001596 goto nla_put_failure;
1597
1598 /*
1599 * Any information below this point is only available to
1600 * applications that can deal with it being split. This
1601 * helps ensure that newly added capabilities don't break
1602 * older tools by overrunning their buffers.
1603 *
1604 * We still increment split_start so that in the split
1605 * case we'll continue with more data in the next round,
1606 * but break unconditionally so unsplit data stops here.
1607 */
Johannes Berg86e8cf92013-06-19 10:57:22 +02001608 state->split_start++;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001609 break;
1610 case 9:
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001611 if (rdev->wiphy.extended_capabilities &&
Johannes Bergfe1abaf2013-02-27 15:39:45 +01001612 (nla_put(msg, NL80211_ATTR_EXT_CAPA,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001613 rdev->wiphy.extended_capabilities_len,
1614 rdev->wiphy.extended_capabilities) ||
Johannes Bergfe1abaf2013-02-27 15:39:45 +01001615 nla_put(msg, NL80211_ATTR_EXT_CAPA_MASK,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001616 rdev->wiphy.extended_capabilities_len,
1617 rdev->wiphy.extended_capabilities_mask)))
Johannes Bergfe1abaf2013-02-27 15:39:45 +01001618 goto nla_put_failure;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001619
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001620 if (rdev->wiphy.vht_capa_mod_mask &&
Johannes Bergee2aca32013-02-21 17:36:01 +01001621 nla_put(msg, NL80211_ATTR_VHT_CAPABILITY_MASK,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001622 sizeof(*rdev->wiphy.vht_capa_mod_mask),
1623 rdev->wiphy.vht_capa_mod_mask))
Johannes Bergee2aca32013-02-21 17:36:01 +01001624 goto nla_put_failure;
1625
Amitkumar Karwarbe29b992013-06-28 11:51:26 -07001626 state->split_start++;
1627 break;
1628 case 10:
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001629 if (nl80211_send_coalesce(msg, rdev))
Amitkumar Karwarbe29b992013-06-28 11:51:26 -07001630 goto nla_put_failure;
1631
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001632 if ((rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_5_10_MHZ) &&
Felix Fietkau01e0daa2013-11-09 14:57:54 +01001633 (nla_put_flag(msg, NL80211_ATTR_SUPPORT_5_MHZ) ||
1634 nla_put_flag(msg, NL80211_ATTR_SUPPORT_10_MHZ)))
1635 goto nla_put_failure;
Jouni Malinenb43504c2014-01-15 00:01:08 +02001636
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001637 if (rdev->wiphy.max_ap_assoc_sta &&
Jouni Malinenb43504c2014-01-15 00:01:08 +02001638 nla_put_u32(msg, NL80211_ATTR_MAX_AP_ASSOC_STA,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001639 rdev->wiphy.max_ap_assoc_sta))
Jouni Malinenb43504c2014-01-15 00:01:08 +02001640 goto nla_put_failure;
1641
Johannes Bergad7e7182013-11-13 13:37:47 +01001642 state->split_start++;
1643 break;
1644 case 11:
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001645 if (rdev->wiphy.n_vendor_commands) {
Johannes Berg567ffc32013-12-18 14:43:31 +01001646 const struct nl80211_vendor_cmd_info *info;
1647 struct nlattr *nested;
Johannes Bergad7e7182013-11-13 13:37:47 +01001648
Johannes Berg567ffc32013-12-18 14:43:31 +01001649 nested = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA);
1650 if (!nested)
Johannes Bergad7e7182013-11-13 13:37:47 +01001651 goto nla_put_failure;
Johannes Berg567ffc32013-12-18 14:43:31 +01001652
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001653 for (i = 0; i < rdev->wiphy.n_vendor_commands; i++) {
1654 info = &rdev->wiphy.vendor_commands[i].info;
Johannes Berg567ffc32013-12-18 14:43:31 +01001655 if (nla_put(msg, i + 1, sizeof(*info), info))
1656 goto nla_put_failure;
1657 }
1658 nla_nest_end(msg, nested);
1659 }
1660
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001661 if (rdev->wiphy.n_vendor_events) {
Johannes Berg567ffc32013-12-18 14:43:31 +01001662 const struct nl80211_vendor_cmd_info *info;
1663 struct nlattr *nested;
1664
1665 nested = nla_nest_start(msg,
1666 NL80211_ATTR_VENDOR_EVENTS);
1667 if (!nested)
1668 goto nla_put_failure;
1669
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001670 for (i = 0; i < rdev->wiphy.n_vendor_events; i++) {
1671 info = &rdev->wiphy.vendor_events[i];
Johannes Berg567ffc32013-12-18 14:43:31 +01001672 if (nla_put(msg, i + 1, sizeof(*info), info))
1673 goto nla_put_failure;
1674 }
1675 nla_nest_end(msg, nested);
1676 }
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03001677 state->split_start++;
1678 break;
1679 case 12:
1680 if (rdev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH &&
1681 nla_put_u8(msg, NL80211_ATTR_MAX_CSA_COUNTERS,
1682 rdev->wiphy.max_num_csa_counters))
1683 goto nla_put_failure;
Felix Fietkau01e0daa2013-11-09 14:57:54 +01001684
Johannes Berg3713b4e2013-02-14 16:19:38 +01001685 /* done */
Johannes Berg86e8cf92013-06-19 10:57:22 +02001686 state->split_start = 0;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001687 break;
Johannes Bergff1b6e62011-05-04 15:37:28 +02001688 }
Johannes Berg3bb20552014-05-26 13:52:25 +02001689 finish:
Johannes Berg55682962007-09-20 13:09:35 -04001690 return genlmsg_end(msg, hdr);
1691
1692 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07001693 genlmsg_cancel(msg, hdr);
1694 return -EMSGSIZE;
Johannes Berg55682962007-09-20 13:09:35 -04001695}
1696
Johannes Berg86e8cf92013-06-19 10:57:22 +02001697static int nl80211_dump_wiphy_parse(struct sk_buff *skb,
1698 struct netlink_callback *cb,
1699 struct nl80211_dump_wiphy_state *state)
1700{
1701 struct nlattr **tb = nl80211_fam.attrbuf;
1702 int ret = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize,
1703 tb, nl80211_fam.maxattr, nl80211_policy);
1704 /* ignore parse errors for backward compatibility */
1705 if (ret)
1706 return 0;
1707
1708 state->split = tb[NL80211_ATTR_SPLIT_WIPHY_DUMP];
1709 if (tb[NL80211_ATTR_WIPHY])
1710 state->filter_wiphy = nla_get_u32(tb[NL80211_ATTR_WIPHY]);
1711 if (tb[NL80211_ATTR_WDEV])
1712 state->filter_wiphy = nla_get_u64(tb[NL80211_ATTR_WDEV]) >> 32;
1713 if (tb[NL80211_ATTR_IFINDEX]) {
1714 struct net_device *netdev;
1715 struct cfg80211_registered_device *rdev;
1716 int ifidx = nla_get_u32(tb[NL80211_ATTR_IFINDEX]);
1717
Ying Xue7f2b8562014-01-15 10:23:45 +08001718 netdev = __dev_get_by_index(sock_net(skb->sk), ifidx);
Johannes Berg86e8cf92013-06-19 10:57:22 +02001719 if (!netdev)
1720 return -ENODEV;
1721 if (netdev->ieee80211_ptr) {
Zhao, Gangf26cbf42014-04-21 12:53:03 +08001722 rdev = wiphy_to_rdev(
Johannes Berg86e8cf92013-06-19 10:57:22 +02001723 netdev->ieee80211_ptr->wiphy);
1724 state->filter_wiphy = rdev->wiphy_idx;
1725 }
Johannes Berg86e8cf92013-06-19 10:57:22 +02001726 }
1727
1728 return 0;
1729}
1730
Johannes Berg55682962007-09-20 13:09:35 -04001731static int nl80211_dump_wiphy(struct sk_buff *skb, struct netlink_callback *cb)
1732{
Johannes Berg645e77d2013-03-01 14:03:49 +01001733 int idx = 0, ret;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001734 struct nl80211_dump_wiphy_state *state = (void *)cb->args[0];
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001735 struct cfg80211_registered_device *rdev;
Johannes Berg3a5a4232013-06-19 10:09:57 +02001736
Johannes Berg5fe231e2013-05-08 21:45:15 +02001737 rtnl_lock();
Johannes Berg86e8cf92013-06-19 10:57:22 +02001738 if (!state) {
1739 state = kzalloc(sizeof(*state), GFP_KERNEL);
John W. Linville57ed5cd2013-06-28 13:18:21 -04001740 if (!state) {
1741 rtnl_unlock();
Johannes Berg86e8cf92013-06-19 10:57:22 +02001742 return -ENOMEM;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001743 }
Johannes Berg86e8cf92013-06-19 10:57:22 +02001744 state->filter_wiphy = -1;
1745 ret = nl80211_dump_wiphy_parse(skb, cb, state);
1746 if (ret) {
1747 kfree(state);
1748 rtnl_unlock();
1749 return ret;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001750 }
Johannes Berg86e8cf92013-06-19 10:57:22 +02001751 cb->args[0] = (long)state;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001752 }
1753
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001754 list_for_each_entry(rdev, &cfg80211_rdev_list, list) {
1755 if (!net_eq(wiphy_net(&rdev->wiphy), sock_net(skb->sk)))
Johannes Berg463d0182009-07-14 00:33:35 +02001756 continue;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001757 if (++idx <= state->start)
Johannes Berg55682962007-09-20 13:09:35 -04001758 continue;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001759 if (state->filter_wiphy != -1 &&
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001760 state->filter_wiphy != rdev->wiphy_idx)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001761 continue;
1762 /* attempt to fit multiple wiphy data chunks into the skb */
1763 do {
Johannes Berg3bb20552014-05-26 13:52:25 +02001764 ret = nl80211_send_wiphy(rdev, NL80211_CMD_NEW_WIPHY,
1765 skb,
Johannes Berg3713b4e2013-02-14 16:19:38 +01001766 NETLINK_CB(cb->skb).portid,
1767 cb->nlh->nlmsg_seq,
Johannes Berg86e8cf92013-06-19 10:57:22 +02001768 NLM_F_MULTI, state);
Johannes Berg3713b4e2013-02-14 16:19:38 +01001769 if (ret < 0) {
1770 /*
1771 * If sending the wiphy data didn't fit (ENOBUFS
1772 * or EMSGSIZE returned), this SKB is still
1773 * empty (so it's not too big because another
1774 * wiphy dataset is already in the skb) and
1775 * we've not tried to adjust the dump allocation
1776 * yet ... then adjust the alloc size to be
1777 * bigger, and return 1 but with the empty skb.
1778 * This results in an empty message being RX'ed
1779 * in userspace, but that is ignored.
1780 *
1781 * We can then retry with the larger buffer.
1782 */
1783 if ((ret == -ENOBUFS || ret == -EMSGSIZE) &&
Pontus Fuchsf12cb282014-01-16 15:00:40 +01001784 !skb->len && !state->split &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001785 cb->min_dump_alloc < 4096) {
1786 cb->min_dump_alloc = 4096;
Pontus Fuchsf12cb282014-01-16 15:00:40 +01001787 state->split_start = 0;
David S. Millerd98cae64e2013-06-19 16:49:39 -07001788 rtnl_unlock();
Johannes Berg3713b4e2013-02-14 16:19:38 +01001789 return 1;
1790 }
1791 idx--;
1792 break;
Johannes Berg645e77d2013-03-01 14:03:49 +01001793 }
Johannes Berg86e8cf92013-06-19 10:57:22 +02001794 } while (state->split_start > 0);
Johannes Berg3713b4e2013-02-14 16:19:38 +01001795 break;
Johannes Berg55682962007-09-20 13:09:35 -04001796 }
Johannes Berg5fe231e2013-05-08 21:45:15 +02001797 rtnl_unlock();
Johannes Berg55682962007-09-20 13:09:35 -04001798
Johannes Berg86e8cf92013-06-19 10:57:22 +02001799 state->start = idx;
Johannes Berg55682962007-09-20 13:09:35 -04001800
1801 return skb->len;
1802}
1803
Johannes Berg86e8cf92013-06-19 10:57:22 +02001804static int nl80211_dump_wiphy_done(struct netlink_callback *cb)
1805{
1806 kfree((void *)cb->args[0]);
1807 return 0;
1808}
1809
Johannes Berg55682962007-09-20 13:09:35 -04001810static int nl80211_get_wiphy(struct sk_buff *skb, struct genl_info *info)
1811{
1812 struct sk_buff *msg;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001813 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg86e8cf92013-06-19 10:57:22 +02001814 struct nl80211_dump_wiphy_state state = {};
Johannes Berg55682962007-09-20 13:09:35 -04001815
Johannes Berg645e77d2013-03-01 14:03:49 +01001816 msg = nlmsg_new(4096, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -04001817 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02001818 return -ENOMEM;
Johannes Berg55682962007-09-20 13:09:35 -04001819
Johannes Berg3bb20552014-05-26 13:52:25 +02001820 if (nl80211_send_wiphy(rdev, NL80211_CMD_NEW_WIPHY, msg,
1821 info->snd_portid, info->snd_seq, 0,
Johannes Berg86e8cf92013-06-19 10:57:22 +02001822 &state) < 0) {
Johannes Berg4c476992010-10-04 21:36:35 +02001823 nlmsg_free(msg);
1824 return -ENOBUFS;
1825 }
Johannes Berg55682962007-09-20 13:09:35 -04001826
Johannes Berg134e6372009-07-10 09:51:34 +00001827 return genlmsg_reply(msg, info);
Johannes Berg55682962007-09-20 13:09:35 -04001828}
1829
Jouni Malinen31888482008-10-30 16:59:24 +02001830static const struct nla_policy txq_params_policy[NL80211_TXQ_ATTR_MAX + 1] = {
1831 [NL80211_TXQ_ATTR_QUEUE] = { .type = NLA_U8 },
1832 [NL80211_TXQ_ATTR_TXOP] = { .type = NLA_U16 },
1833 [NL80211_TXQ_ATTR_CWMIN] = { .type = NLA_U16 },
1834 [NL80211_TXQ_ATTR_CWMAX] = { .type = NLA_U16 },
1835 [NL80211_TXQ_ATTR_AIFS] = { .type = NLA_U8 },
1836};
1837
1838static int parse_txq_params(struct nlattr *tb[],
1839 struct ieee80211_txq_params *txq_params)
1840{
Johannes Berga3304b02012-03-28 11:04:24 +02001841 if (!tb[NL80211_TXQ_ATTR_AC] || !tb[NL80211_TXQ_ATTR_TXOP] ||
Jouni Malinen31888482008-10-30 16:59:24 +02001842 !tb[NL80211_TXQ_ATTR_CWMIN] || !tb[NL80211_TXQ_ATTR_CWMAX] ||
1843 !tb[NL80211_TXQ_ATTR_AIFS])
1844 return -EINVAL;
1845
Johannes Berga3304b02012-03-28 11:04:24 +02001846 txq_params->ac = nla_get_u8(tb[NL80211_TXQ_ATTR_AC]);
Jouni Malinen31888482008-10-30 16:59:24 +02001847 txq_params->txop = nla_get_u16(tb[NL80211_TXQ_ATTR_TXOP]);
1848 txq_params->cwmin = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMIN]);
1849 txq_params->cwmax = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMAX]);
1850 txq_params->aifs = nla_get_u8(tb[NL80211_TXQ_ATTR_AIFS]);
1851
Johannes Berga3304b02012-03-28 11:04:24 +02001852 if (txq_params->ac >= NL80211_NUM_ACS)
1853 return -EINVAL;
1854
Jouni Malinen31888482008-10-30 16:59:24 +02001855 return 0;
1856}
1857
Johannes Bergf444de02010-05-05 15:25:02 +02001858static bool nl80211_can_set_dev_channel(struct wireless_dev *wdev)
1859{
1860 /*
Johannes Bergcc1d2802012-05-16 23:50:20 +02001861 * You can only set the channel explicitly for WDS interfaces,
1862 * all others have their channel managed via their respective
1863 * "establish a connection" command (connect, join, ...)
1864 *
1865 * For AP/GO and mesh mode, the channel can be set with the
1866 * channel userspace API, but is only stored and passed to the
1867 * low-level driver when the AP starts or the mesh is joined.
1868 * This is for backward compatibility, userspace can also give
1869 * the channel in the start-ap or join-mesh commands instead.
Johannes Bergf444de02010-05-05 15:25:02 +02001870 *
1871 * Monitors are special as they are normally slaved to
Johannes Berge8c9bd52012-06-06 08:18:22 +02001872 * whatever else is going on, so they have their own special
1873 * operation to set the monitor channel if possible.
Johannes Bergf444de02010-05-05 15:25:02 +02001874 */
1875 return !wdev ||
1876 wdev->iftype == NL80211_IFTYPE_AP ||
Johannes Bergf444de02010-05-05 15:25:02 +02001877 wdev->iftype == NL80211_IFTYPE_MESH_POINT ||
Johannes Berg074ac8d2010-09-16 14:58:22 +02001878 wdev->iftype == NL80211_IFTYPE_MONITOR ||
1879 wdev->iftype == NL80211_IFTYPE_P2P_GO;
Johannes Bergf444de02010-05-05 15:25:02 +02001880}
1881
Johannes Berg683b6d32012-11-08 21:25:48 +01001882static int nl80211_parse_chandef(struct cfg80211_registered_device *rdev,
1883 struct genl_info *info,
1884 struct cfg80211_chan_def *chandef)
1885{
Mahesh Paliveladbeca2e2012-11-29 14:11:07 +05301886 u32 control_freq;
Johannes Berg683b6d32012-11-08 21:25:48 +01001887
1888 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ])
1889 return -EINVAL;
1890
1891 control_freq = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]);
1892
1893 chandef->chan = ieee80211_get_channel(&rdev->wiphy, control_freq);
Johannes Berg3d9d1d62012-11-08 23:14:50 +01001894 chandef->width = NL80211_CHAN_WIDTH_20_NOHT;
1895 chandef->center_freq1 = control_freq;
1896 chandef->center_freq2 = 0;
Johannes Berg683b6d32012-11-08 21:25:48 +01001897
1898 /* Primary channel not allowed */
1899 if (!chandef->chan || chandef->chan->flags & IEEE80211_CHAN_DISABLED)
1900 return -EINVAL;
1901
Johannes Berg3d9d1d62012-11-08 23:14:50 +01001902 if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]) {
1903 enum nl80211_channel_type chantype;
Johannes Berg683b6d32012-11-08 21:25:48 +01001904
Johannes Berg3d9d1d62012-11-08 23:14:50 +01001905 chantype = nla_get_u32(
1906 info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]);
1907
1908 switch (chantype) {
1909 case NL80211_CHAN_NO_HT:
1910 case NL80211_CHAN_HT20:
1911 case NL80211_CHAN_HT40PLUS:
1912 case NL80211_CHAN_HT40MINUS:
1913 cfg80211_chandef_create(chandef, chandef->chan,
1914 chantype);
1915 break;
1916 default:
Johannes Berg683b6d32012-11-08 21:25:48 +01001917 return -EINVAL;
Johannes Berg683b6d32012-11-08 21:25:48 +01001918 }
Johannes Berg3d9d1d62012-11-08 23:14:50 +01001919 } else if (info->attrs[NL80211_ATTR_CHANNEL_WIDTH]) {
1920 chandef->width =
1921 nla_get_u32(info->attrs[NL80211_ATTR_CHANNEL_WIDTH]);
1922 if (info->attrs[NL80211_ATTR_CENTER_FREQ1])
1923 chandef->center_freq1 =
1924 nla_get_u32(
1925 info->attrs[NL80211_ATTR_CENTER_FREQ1]);
1926 if (info->attrs[NL80211_ATTR_CENTER_FREQ2])
1927 chandef->center_freq2 =
1928 nla_get_u32(
1929 info->attrs[NL80211_ATTR_CENTER_FREQ2]);
1930 }
1931
Johannes Berg9f5e8f62012-11-22 16:59:45 +01001932 if (!cfg80211_chandef_valid(chandef))
Johannes Berg3d9d1d62012-11-08 23:14:50 +01001933 return -EINVAL;
1934
Johannes Berg9f5e8f62012-11-22 16:59:45 +01001935 if (!cfg80211_chandef_usable(&rdev->wiphy, chandef,
1936 IEEE80211_CHAN_DISABLED))
Johannes Berg3d9d1d62012-11-08 23:14:50 +01001937 return -EINVAL;
Johannes Berg3d9d1d62012-11-08 23:14:50 +01001938
Simon Wunderlich2f301ab2013-05-16 13:00:28 +02001939 if ((chandef->width == NL80211_CHAN_WIDTH_5 ||
1940 chandef->width == NL80211_CHAN_WIDTH_10) &&
1941 !(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_5_10_MHZ))
1942 return -EINVAL;
1943
Johannes Berg683b6d32012-11-08 21:25:48 +01001944 return 0;
1945}
1946
Johannes Bergf444de02010-05-05 15:25:02 +02001947static int __nl80211_set_channel(struct cfg80211_registered_device *rdev,
Jouni Malinene16821b2014-04-28 11:22:08 +03001948 struct net_device *dev,
Johannes Bergf444de02010-05-05 15:25:02 +02001949 struct genl_info *info)
1950{
Johannes Berg683b6d32012-11-08 21:25:48 +01001951 struct cfg80211_chan_def chandef;
Johannes Bergf444de02010-05-05 15:25:02 +02001952 int result;
Johannes Berge8c9bd52012-06-06 08:18:22 +02001953 enum nl80211_iftype iftype = NL80211_IFTYPE_MONITOR;
Jouni Malinene16821b2014-04-28 11:22:08 +03001954 struct wireless_dev *wdev = NULL;
Johannes Berge8c9bd52012-06-06 08:18:22 +02001955
Jouni Malinene16821b2014-04-28 11:22:08 +03001956 if (dev)
1957 wdev = dev->ieee80211_ptr;
Johannes Bergf444de02010-05-05 15:25:02 +02001958 if (!nl80211_can_set_dev_channel(wdev))
1959 return -EOPNOTSUPP;
Jouni Malinene16821b2014-04-28 11:22:08 +03001960 if (wdev)
1961 iftype = wdev->iftype;
Johannes Bergf444de02010-05-05 15:25:02 +02001962
Johannes Berg683b6d32012-11-08 21:25:48 +01001963 result = nl80211_parse_chandef(rdev, info, &chandef);
1964 if (result)
1965 return result;
Johannes Bergf444de02010-05-05 15:25:02 +02001966
Johannes Berge8c9bd52012-06-06 08:18:22 +02001967 switch (iftype) {
Johannes Bergaa430da2012-05-16 23:50:18 +02001968 case NL80211_IFTYPE_AP:
1969 case NL80211_IFTYPE_P2P_GO:
Ilan Peer174e0cd2014-02-23 09:13:01 +02001970 if (!cfg80211_reg_can_beacon(&rdev->wiphy, &chandef, iftype)) {
Johannes Bergaa430da2012-05-16 23:50:18 +02001971 result = -EINVAL;
1972 break;
1973 }
Jouni Malinene16821b2014-04-28 11:22:08 +03001974 if (wdev->beacon_interval) {
1975 if (!dev || !rdev->ops->set_ap_chanwidth ||
1976 !(rdev->wiphy.features &
1977 NL80211_FEATURE_AP_MODE_CHAN_WIDTH_CHANGE)) {
1978 result = -EBUSY;
1979 break;
1980 }
1981
1982 /* Only allow dynamic channel width changes */
1983 if (chandef.chan != wdev->preset_chandef.chan) {
1984 result = -EBUSY;
1985 break;
1986 }
1987 result = rdev_set_ap_chanwidth(rdev, dev, &chandef);
1988 if (result)
1989 break;
1990 }
Johannes Berg683b6d32012-11-08 21:25:48 +01001991 wdev->preset_chandef = chandef;
Johannes Bergaa430da2012-05-16 23:50:18 +02001992 result = 0;
1993 break;
Johannes Bergcc1d2802012-05-16 23:50:20 +02001994 case NL80211_IFTYPE_MESH_POINT:
Johannes Berg683b6d32012-11-08 21:25:48 +01001995 result = cfg80211_set_mesh_channel(rdev, wdev, &chandef);
Johannes Bergcc1d2802012-05-16 23:50:20 +02001996 break;
Johannes Berge8c9bd52012-06-06 08:18:22 +02001997 case NL80211_IFTYPE_MONITOR:
Johannes Berg683b6d32012-11-08 21:25:48 +01001998 result = cfg80211_set_monitor_channel(rdev, &chandef);
Johannes Berge8c9bd52012-06-06 08:18:22 +02001999 break;
Johannes Bergaa430da2012-05-16 23:50:18 +02002000 default:
Johannes Berge8c9bd52012-06-06 08:18:22 +02002001 result = -EINVAL;
Johannes Bergf444de02010-05-05 15:25:02 +02002002 }
Johannes Bergf444de02010-05-05 15:25:02 +02002003
2004 return result;
2005}
2006
2007static int nl80211_set_channel(struct sk_buff *skb, struct genl_info *info)
2008{
Johannes Berg4c476992010-10-04 21:36:35 +02002009 struct cfg80211_registered_device *rdev = info->user_ptr[0];
2010 struct net_device *netdev = info->user_ptr[1];
Johannes Bergf444de02010-05-05 15:25:02 +02002011
Jouni Malinene16821b2014-04-28 11:22:08 +03002012 return __nl80211_set_channel(rdev, netdev, info);
Johannes Bergf444de02010-05-05 15:25:02 +02002013}
2014
Bill Jordane8347eb2010-10-01 13:54:28 -04002015static int nl80211_set_wds_peer(struct sk_buff *skb, struct genl_info *info)
2016{
Johannes Berg43b19952010-10-07 13:10:30 +02002017 struct cfg80211_registered_device *rdev = info->user_ptr[0];
2018 struct net_device *dev = info->user_ptr[1];
2019 struct wireless_dev *wdev = dev->ieee80211_ptr;
Johannes Berg388ac772010-10-07 13:11:09 +02002020 const u8 *bssid;
Bill Jordane8347eb2010-10-01 13:54:28 -04002021
2022 if (!info->attrs[NL80211_ATTR_MAC])
2023 return -EINVAL;
2024
Johannes Berg43b19952010-10-07 13:10:30 +02002025 if (netif_running(dev))
2026 return -EBUSY;
Bill Jordane8347eb2010-10-01 13:54:28 -04002027
Johannes Berg43b19952010-10-07 13:10:30 +02002028 if (!rdev->ops->set_wds_peer)
2029 return -EOPNOTSUPP;
Bill Jordane8347eb2010-10-01 13:54:28 -04002030
Johannes Berg43b19952010-10-07 13:10:30 +02002031 if (wdev->iftype != NL80211_IFTYPE_WDS)
2032 return -EOPNOTSUPP;
Bill Jordane8347eb2010-10-01 13:54:28 -04002033
2034 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Hila Gonene35e4d22012-06-27 17:19:42 +03002035 return rdev_set_wds_peer(rdev, dev, bssid);
Bill Jordane8347eb2010-10-01 13:54:28 -04002036}
2037
2038
Johannes Berg55682962007-09-20 13:09:35 -04002039static int nl80211_set_wiphy(struct sk_buff *skb, struct genl_info *info)
2040{
2041 struct cfg80211_registered_device *rdev;
Johannes Bergf444de02010-05-05 15:25:02 +02002042 struct net_device *netdev = NULL;
2043 struct wireless_dev *wdev;
Bill Jordana1e567c2010-09-10 11:22:32 -04002044 int result = 0, rem_txq_params = 0;
Jouni Malinen31888482008-10-30 16:59:24 +02002045 struct nlattr *nl_txq_params;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002046 u32 changed;
2047 u8 retry_short = 0, retry_long = 0;
2048 u32 frag_threshold = 0, rts_threshold = 0;
Lukáš Turek81077e82009-12-21 22:50:47 +01002049 u8 coverage_class = 0;
Johannes Berg55682962007-09-20 13:09:35 -04002050
Johannes Berg5fe231e2013-05-08 21:45:15 +02002051 ASSERT_RTNL();
2052
Johannes Bergf444de02010-05-05 15:25:02 +02002053 /*
2054 * Try to find the wiphy and netdev. Normally this
2055 * function shouldn't need the netdev, but this is
2056 * done for backward compatibility -- previously
2057 * setting the channel was done per wiphy, but now
2058 * it is per netdev. Previous userland like hostapd
2059 * also passed a netdev to set_wiphy, so that it is
2060 * possible to let that go to the right netdev!
2061 */
Johannes Berg4bbf4d52009-03-24 09:35:46 +01002062
Johannes Bergf444de02010-05-05 15:25:02 +02002063 if (info->attrs[NL80211_ATTR_IFINDEX]) {
2064 int ifindex = nla_get_u32(info->attrs[NL80211_ATTR_IFINDEX]);
2065
Ying Xue7f2b8562014-01-15 10:23:45 +08002066 netdev = __dev_get_by_index(genl_info_net(info), ifindex);
Johannes Berg5fe231e2013-05-08 21:45:15 +02002067 if (netdev && netdev->ieee80211_ptr)
Zhao, Gangf26cbf42014-04-21 12:53:03 +08002068 rdev = wiphy_to_rdev(netdev->ieee80211_ptr->wiphy);
Johannes Berg5fe231e2013-05-08 21:45:15 +02002069 else
Johannes Bergf444de02010-05-05 15:25:02 +02002070 netdev = NULL;
Johannes Berg4bbf4d52009-03-24 09:35:46 +01002071 }
2072
Johannes Bergf444de02010-05-05 15:25:02 +02002073 if (!netdev) {
Johannes Berg878d9ec2012-06-15 14:18:32 +02002074 rdev = __cfg80211_rdev_from_attrs(genl_info_net(info),
2075 info->attrs);
Johannes Berg5fe231e2013-05-08 21:45:15 +02002076 if (IS_ERR(rdev))
Johannes Berg4c476992010-10-04 21:36:35 +02002077 return PTR_ERR(rdev);
Johannes Bergf444de02010-05-05 15:25:02 +02002078 wdev = NULL;
2079 netdev = NULL;
2080 result = 0;
Johannes Berg71fe96b2012-10-24 10:04:58 +02002081 } else
Johannes Bergf444de02010-05-05 15:25:02 +02002082 wdev = netdev->ieee80211_ptr;
Johannes Bergf444de02010-05-05 15:25:02 +02002083
2084 /*
2085 * end workaround code, by now the rdev is available
2086 * and locked, and wdev may or may not be NULL.
2087 */
Johannes Berg4bbf4d52009-03-24 09:35:46 +01002088
2089 if (info->attrs[NL80211_ATTR_WIPHY_NAME])
Jouni Malinen31888482008-10-30 16:59:24 +02002090 result = cfg80211_dev_rename(
2091 rdev, nla_data(info->attrs[NL80211_ATTR_WIPHY_NAME]));
Johannes Berg4bbf4d52009-03-24 09:35:46 +01002092
Johannes Berg4bbf4d52009-03-24 09:35:46 +01002093 if (result)
Ying Xue7f2b8562014-01-15 10:23:45 +08002094 return result;
Johannes Berg55682962007-09-20 13:09:35 -04002095
Jouni Malinen31888482008-10-30 16:59:24 +02002096 if (info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS]) {
2097 struct ieee80211_txq_params txq_params;
2098 struct nlattr *tb[NL80211_TXQ_ATTR_MAX + 1];
2099
Ying Xue7f2b8562014-01-15 10:23:45 +08002100 if (!rdev->ops->set_txq_params)
2101 return -EOPNOTSUPP;
Jouni Malinen31888482008-10-30 16:59:24 +02002102
Ying Xue7f2b8562014-01-15 10:23:45 +08002103 if (!netdev)
2104 return -EINVAL;
Eliad Pellerf70f01c2011-09-25 20:06:53 +03002105
Johannes Berg133a3ff2011-11-03 14:50:13 +01002106 if (netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
Ying Xue7f2b8562014-01-15 10:23:45 +08002107 netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
2108 return -EINVAL;
Johannes Berg133a3ff2011-11-03 14:50:13 +01002109
Ying Xue7f2b8562014-01-15 10:23:45 +08002110 if (!netif_running(netdev))
2111 return -ENETDOWN;
Johannes Berg2b5f8b02012-04-02 10:51:55 +02002112
Jouni Malinen31888482008-10-30 16:59:24 +02002113 nla_for_each_nested(nl_txq_params,
2114 info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS],
2115 rem_txq_params) {
Johannes Bergae811e22014-01-24 10:17:47 +01002116 result = nla_parse(tb, NL80211_TXQ_ATTR_MAX,
2117 nla_data(nl_txq_params),
2118 nla_len(nl_txq_params),
2119 txq_params_policy);
2120 if (result)
2121 return result;
Jouni Malinen31888482008-10-30 16:59:24 +02002122 result = parse_txq_params(tb, &txq_params);
2123 if (result)
Ying Xue7f2b8562014-01-15 10:23:45 +08002124 return result;
Jouni Malinen31888482008-10-30 16:59:24 +02002125
Hila Gonene35e4d22012-06-27 17:19:42 +03002126 result = rdev_set_txq_params(rdev, netdev,
2127 &txq_params);
Jouni Malinen31888482008-10-30 16:59:24 +02002128 if (result)
Ying Xue7f2b8562014-01-15 10:23:45 +08002129 return result;
Jouni Malinen31888482008-10-30 16:59:24 +02002130 }
2131 }
2132
Jouni Malinen72bdcf32008-11-26 16:15:24 +02002133 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
Jouni Malinene16821b2014-04-28 11:22:08 +03002134 result = __nl80211_set_channel(
2135 rdev,
2136 nl80211_can_set_dev_channel(wdev) ? netdev : NULL,
2137 info);
Jouni Malinen72bdcf32008-11-26 16:15:24 +02002138 if (result)
Ying Xue7f2b8562014-01-15 10:23:45 +08002139 return result;
Jouni Malinen72bdcf32008-11-26 16:15:24 +02002140 }
2141
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03002142 if (info->attrs[NL80211_ATTR_WIPHY_TX_POWER_SETTING]) {
Johannes Bergc8442112012-10-24 10:17:18 +02002143 struct wireless_dev *txp_wdev = wdev;
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03002144 enum nl80211_tx_power_setting type;
2145 int idx, mbm = 0;
2146
Johannes Bergc8442112012-10-24 10:17:18 +02002147 if (!(rdev->wiphy.features & NL80211_FEATURE_VIF_TXPOWER))
2148 txp_wdev = NULL;
2149
Ying Xue7f2b8562014-01-15 10:23:45 +08002150 if (!rdev->ops->set_tx_power)
2151 return -EOPNOTSUPP;
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03002152
2153 idx = NL80211_ATTR_WIPHY_TX_POWER_SETTING;
2154 type = nla_get_u32(info->attrs[idx]);
2155
2156 if (!info->attrs[NL80211_ATTR_WIPHY_TX_POWER_LEVEL] &&
Ying Xue7f2b8562014-01-15 10:23:45 +08002157 (type != NL80211_TX_POWER_AUTOMATIC))
2158 return -EINVAL;
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03002159
2160 if (type != NL80211_TX_POWER_AUTOMATIC) {
2161 idx = NL80211_ATTR_WIPHY_TX_POWER_LEVEL;
2162 mbm = nla_get_u32(info->attrs[idx]);
2163 }
2164
Johannes Bergc8442112012-10-24 10:17:18 +02002165 result = rdev_set_tx_power(rdev, txp_wdev, type, mbm);
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03002166 if (result)
Ying Xue7f2b8562014-01-15 10:23:45 +08002167 return result;
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03002168 }
2169
Bruno Randolfafe0cbf2010-11-10 12:50:50 +09002170 if (info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX] &&
2171 info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]) {
2172 u32 tx_ant, rx_ant;
Bruno Randolf7f531e02010-12-16 11:30:22 +09002173 if ((!rdev->wiphy.available_antennas_tx &&
2174 !rdev->wiphy.available_antennas_rx) ||
Ying Xue7f2b8562014-01-15 10:23:45 +08002175 !rdev->ops->set_antenna)
2176 return -EOPNOTSUPP;
Bruno Randolfafe0cbf2010-11-10 12:50:50 +09002177
2178 tx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX]);
2179 rx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]);
2180
Bruno Randolfa7ffac92010-12-08 13:59:24 +09002181 /* reject antenna configurations which don't match the
Bruno Randolf7f531e02010-12-16 11:30:22 +09002182 * available antenna masks, except for the "all" mask */
2183 if ((~tx_ant && (tx_ant & ~rdev->wiphy.available_antennas_tx)) ||
Ying Xue7f2b8562014-01-15 10:23:45 +08002184 (~rx_ant && (rx_ant & ~rdev->wiphy.available_antennas_rx)))
2185 return -EINVAL;
Bruno Randolfa7ffac92010-12-08 13:59:24 +09002186
Bruno Randolf7f531e02010-12-16 11:30:22 +09002187 tx_ant = tx_ant & rdev->wiphy.available_antennas_tx;
2188 rx_ant = rx_ant & rdev->wiphy.available_antennas_rx;
Bruno Randolfa7ffac92010-12-08 13:59:24 +09002189
Hila Gonene35e4d22012-06-27 17:19:42 +03002190 result = rdev_set_antenna(rdev, tx_ant, rx_ant);
Bruno Randolfafe0cbf2010-11-10 12:50:50 +09002191 if (result)
Ying Xue7f2b8562014-01-15 10:23:45 +08002192 return result;
Bruno Randolfafe0cbf2010-11-10 12:50:50 +09002193 }
2194
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002195 changed = 0;
2196
2197 if (info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]) {
2198 retry_short = nla_get_u8(
2199 info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]);
Ying Xue7f2b8562014-01-15 10:23:45 +08002200 if (retry_short == 0)
2201 return -EINVAL;
2202
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002203 changed |= WIPHY_PARAM_RETRY_SHORT;
2204 }
2205
2206 if (info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]) {
2207 retry_long = nla_get_u8(
2208 info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]);
Ying Xue7f2b8562014-01-15 10:23:45 +08002209 if (retry_long == 0)
2210 return -EINVAL;
2211
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002212 changed |= WIPHY_PARAM_RETRY_LONG;
2213 }
2214
2215 if (info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]) {
2216 frag_threshold = nla_get_u32(
2217 info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]);
Ying Xue7f2b8562014-01-15 10:23:45 +08002218 if (frag_threshold < 256)
2219 return -EINVAL;
2220
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002221 if (frag_threshold != (u32) -1) {
2222 /*
2223 * Fragments (apart from the last one) are required to
2224 * have even length. Make the fragmentation code
2225 * simpler by stripping LSB should someone try to use
2226 * odd threshold value.
2227 */
2228 frag_threshold &= ~0x1;
2229 }
2230 changed |= WIPHY_PARAM_FRAG_THRESHOLD;
2231 }
2232
2233 if (info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]) {
2234 rts_threshold = nla_get_u32(
2235 info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]);
2236 changed |= WIPHY_PARAM_RTS_THRESHOLD;
2237 }
2238
Lukáš Turek81077e82009-12-21 22:50:47 +01002239 if (info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]) {
2240 coverage_class = nla_get_u8(
2241 info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]);
2242 changed |= WIPHY_PARAM_COVERAGE_CLASS;
2243 }
2244
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002245 if (changed) {
2246 u8 old_retry_short, old_retry_long;
2247 u32 old_frag_threshold, old_rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01002248 u8 old_coverage_class;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002249
Ying Xue7f2b8562014-01-15 10:23:45 +08002250 if (!rdev->ops->set_wiphy_params)
2251 return -EOPNOTSUPP;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002252
2253 old_retry_short = rdev->wiphy.retry_short;
2254 old_retry_long = rdev->wiphy.retry_long;
2255 old_frag_threshold = rdev->wiphy.frag_threshold;
2256 old_rts_threshold = rdev->wiphy.rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01002257 old_coverage_class = rdev->wiphy.coverage_class;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002258
2259 if (changed & WIPHY_PARAM_RETRY_SHORT)
2260 rdev->wiphy.retry_short = retry_short;
2261 if (changed & WIPHY_PARAM_RETRY_LONG)
2262 rdev->wiphy.retry_long = retry_long;
2263 if (changed & WIPHY_PARAM_FRAG_THRESHOLD)
2264 rdev->wiphy.frag_threshold = frag_threshold;
2265 if (changed & WIPHY_PARAM_RTS_THRESHOLD)
2266 rdev->wiphy.rts_threshold = rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01002267 if (changed & WIPHY_PARAM_COVERAGE_CLASS)
2268 rdev->wiphy.coverage_class = coverage_class;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002269
Hila Gonene35e4d22012-06-27 17:19:42 +03002270 result = rdev_set_wiphy_params(rdev, changed);
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002271 if (result) {
2272 rdev->wiphy.retry_short = old_retry_short;
2273 rdev->wiphy.retry_long = old_retry_long;
2274 rdev->wiphy.frag_threshold = old_frag_threshold;
2275 rdev->wiphy.rts_threshold = old_rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01002276 rdev->wiphy.coverage_class = old_coverage_class;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002277 }
2278 }
Ying Xue7f2b8562014-01-15 10:23:45 +08002279 return 0;
Johannes Berg55682962007-09-20 13:09:35 -04002280}
2281
Johannes Berg71bbc992012-06-15 15:30:18 +02002282static inline u64 wdev_id(struct wireless_dev *wdev)
2283{
2284 return (u64)wdev->identifier |
Zhao, Gangf26cbf42014-04-21 12:53:03 +08002285 ((u64)wiphy_to_rdev(wdev->wiphy)->wiphy_idx << 32);
Johannes Berg71bbc992012-06-15 15:30:18 +02002286}
Johannes Berg55682962007-09-20 13:09:35 -04002287
Johannes Berg683b6d32012-11-08 21:25:48 +01002288static int nl80211_send_chandef(struct sk_buff *msg,
Janusz Dziedzicd2859df2013-11-06 13:55:51 +01002289 const struct cfg80211_chan_def *chandef)
Johannes Berg683b6d32012-11-08 21:25:48 +01002290{
Johannes Berg9f5e8f62012-11-22 16:59:45 +01002291 WARN_ON(!cfg80211_chandef_valid(chandef));
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002292
Johannes Berg683b6d32012-11-08 21:25:48 +01002293 if (nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ,
2294 chandef->chan->center_freq))
2295 return -ENOBUFS;
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002296 switch (chandef->width) {
2297 case NL80211_CHAN_WIDTH_20_NOHT:
2298 case NL80211_CHAN_WIDTH_20:
2299 case NL80211_CHAN_WIDTH_40:
2300 if (nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE,
2301 cfg80211_get_chandef_type(chandef)))
2302 return -ENOBUFS;
2303 break;
2304 default:
2305 break;
2306 }
2307 if (nla_put_u32(msg, NL80211_ATTR_CHANNEL_WIDTH, chandef->width))
2308 return -ENOBUFS;
2309 if (nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ1, chandef->center_freq1))
2310 return -ENOBUFS;
2311 if (chandef->center_freq2 &&
2312 nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ2, chandef->center_freq2))
Johannes Berg683b6d32012-11-08 21:25:48 +01002313 return -ENOBUFS;
2314 return 0;
2315}
2316
Eric W. Biederman15e47302012-09-07 20:12:54 +00002317static int nl80211_send_iface(struct sk_buff *msg, u32 portid, u32 seq, int flags,
Johannes Bergd7264052009-04-19 16:23:20 +02002318 struct cfg80211_registered_device *rdev,
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002319 struct wireless_dev *wdev)
Johannes Berg55682962007-09-20 13:09:35 -04002320{
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002321 struct net_device *dev = wdev->netdev;
Johannes Berg55682962007-09-20 13:09:35 -04002322 void *hdr;
2323
Eric W. Biederman15e47302012-09-07 20:12:54 +00002324 hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_INTERFACE);
Johannes Berg55682962007-09-20 13:09:35 -04002325 if (!hdr)
2326 return -1;
2327
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002328 if (dev &&
2329 (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
Johannes Berg98104fde2012-06-16 00:19:54 +02002330 nla_put_string(msg, NL80211_ATTR_IFNAME, dev->name)))
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002331 goto nla_put_failure;
2332
2333 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
2334 nla_put_u32(msg, NL80211_ATTR_IFTYPE, wdev->iftype) ||
Johannes Berg71bbc992012-06-15 15:30:18 +02002335 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) ||
Johannes Berg98104fde2012-06-16 00:19:54 +02002336 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, wdev_address(wdev)) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04002337 nla_put_u32(msg, NL80211_ATTR_GENERATION,
2338 rdev->devlist_generation ^
2339 (cfg80211_rdev_list_generation << 2)))
2340 goto nla_put_failure;
Johannes Bergf5ea9122009-08-07 16:17:38 +02002341
Johannes Berg5b7ccaf2012-07-12 19:45:08 +02002342 if (rdev->ops->get_channel) {
Johannes Berg683b6d32012-11-08 21:25:48 +01002343 int ret;
2344 struct cfg80211_chan_def chandef;
Johannes Berg5b7ccaf2012-07-12 19:45:08 +02002345
Johannes Berg683b6d32012-11-08 21:25:48 +01002346 ret = rdev_get_channel(rdev, wdev, &chandef);
2347 if (ret == 0) {
2348 if (nl80211_send_chandef(msg, &chandef))
2349 goto nla_put_failure;
2350 }
Pontus Fuchsd91df0e2012-04-03 16:39:58 +02002351 }
2352
Antonio Quartullib84e7a02012-11-07 12:52:20 +01002353 if (wdev->ssid_len) {
2354 if (nla_put(msg, NL80211_ATTR_SSID, wdev->ssid_len, wdev->ssid))
2355 goto nla_put_failure;
2356 }
2357
Johannes Berg55682962007-09-20 13:09:35 -04002358 return genlmsg_end(msg, hdr);
2359
2360 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07002361 genlmsg_cancel(msg, hdr);
2362 return -EMSGSIZE;
Johannes Berg55682962007-09-20 13:09:35 -04002363}
2364
2365static int nl80211_dump_interface(struct sk_buff *skb, struct netlink_callback *cb)
2366{
2367 int wp_idx = 0;
2368 int if_idx = 0;
2369 int wp_start = cb->args[0];
2370 int if_start = cb->args[1];
Johannes Bergf5ea9122009-08-07 16:17:38 +02002371 struct cfg80211_registered_device *rdev;
Johannes Berg55682962007-09-20 13:09:35 -04002372 struct wireless_dev *wdev;
2373
Johannes Berg5fe231e2013-05-08 21:45:15 +02002374 rtnl_lock();
Johannes Bergf5ea9122009-08-07 16:17:38 +02002375 list_for_each_entry(rdev, &cfg80211_rdev_list, list) {
2376 if (!net_eq(wiphy_net(&rdev->wiphy), sock_net(skb->sk)))
Johannes Berg463d0182009-07-14 00:33:35 +02002377 continue;
Johannes Bergbba95fe2008-07-29 13:22:51 +02002378 if (wp_idx < wp_start) {
2379 wp_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04002380 continue;
Johannes Bergbba95fe2008-07-29 13:22:51 +02002381 }
Johannes Berg55682962007-09-20 13:09:35 -04002382 if_idx = 0;
2383
Johannes Berg89a54e42012-06-15 14:33:17 +02002384 list_for_each_entry(wdev, &rdev->wdev_list, list) {
Johannes Bergbba95fe2008-07-29 13:22:51 +02002385 if (if_idx < if_start) {
2386 if_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04002387 continue;
Johannes Bergbba95fe2008-07-29 13:22:51 +02002388 }
Eric W. Biederman15e47302012-09-07 20:12:54 +00002389 if (nl80211_send_iface(skb, NETLINK_CB(cb->skb).portid,
Johannes Berg55682962007-09-20 13:09:35 -04002390 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002391 rdev, wdev) < 0) {
Johannes Bergbba95fe2008-07-29 13:22:51 +02002392 goto out;
2393 }
2394 if_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04002395 }
Johannes Bergbba95fe2008-07-29 13:22:51 +02002396
2397 wp_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04002398 }
Johannes Bergbba95fe2008-07-29 13:22:51 +02002399 out:
Johannes Berg5fe231e2013-05-08 21:45:15 +02002400 rtnl_unlock();
Johannes Berg55682962007-09-20 13:09:35 -04002401
2402 cb->args[0] = wp_idx;
2403 cb->args[1] = if_idx;
2404
2405 return skb->len;
2406}
2407
2408static int nl80211_get_interface(struct sk_buff *skb, struct genl_info *info)
2409{
2410 struct sk_buff *msg;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002411 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002412 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg55682962007-09-20 13:09:35 -04002413
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07002414 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -04002415 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02002416 return -ENOMEM;
Johannes Berg55682962007-09-20 13:09:35 -04002417
Eric W. Biederman15e47302012-09-07 20:12:54 +00002418 if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002419 rdev, wdev) < 0) {
Johannes Berg4c476992010-10-04 21:36:35 +02002420 nlmsg_free(msg);
2421 return -ENOBUFS;
2422 }
Johannes Berg55682962007-09-20 13:09:35 -04002423
Johannes Berg134e6372009-07-10 09:51:34 +00002424 return genlmsg_reply(msg, info);
Johannes Berg55682962007-09-20 13:09:35 -04002425}
2426
Michael Wu66f7ac52008-01-31 19:48:22 +01002427static const struct nla_policy mntr_flags_policy[NL80211_MNTR_FLAG_MAX + 1] = {
2428 [NL80211_MNTR_FLAG_FCSFAIL] = { .type = NLA_FLAG },
2429 [NL80211_MNTR_FLAG_PLCPFAIL] = { .type = NLA_FLAG },
2430 [NL80211_MNTR_FLAG_CONTROL] = { .type = NLA_FLAG },
2431 [NL80211_MNTR_FLAG_OTHER_BSS] = { .type = NLA_FLAG },
2432 [NL80211_MNTR_FLAG_COOK_FRAMES] = { .type = NLA_FLAG },
Felix Fietkaue057d3c2013-05-28 13:01:52 +02002433 [NL80211_MNTR_FLAG_ACTIVE] = { .type = NLA_FLAG },
Michael Wu66f7ac52008-01-31 19:48:22 +01002434};
2435
2436static int parse_monitor_flags(struct nlattr *nla, u32 *mntrflags)
2437{
2438 struct nlattr *flags[NL80211_MNTR_FLAG_MAX + 1];
2439 int flag;
2440
2441 *mntrflags = 0;
2442
2443 if (!nla)
2444 return -EINVAL;
2445
2446 if (nla_parse_nested(flags, NL80211_MNTR_FLAG_MAX,
2447 nla, mntr_flags_policy))
2448 return -EINVAL;
2449
2450 for (flag = 1; flag <= NL80211_MNTR_FLAG_MAX; flag++)
2451 if (flags[flag])
2452 *mntrflags |= (1<<flag);
2453
2454 return 0;
2455}
2456
Johannes Berg9bc383d2009-11-19 11:55:19 +01002457static int nl80211_valid_4addr(struct cfg80211_registered_device *rdev,
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002458 struct net_device *netdev, u8 use_4addr,
2459 enum nl80211_iftype iftype)
Johannes Berg9bc383d2009-11-19 11:55:19 +01002460{
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002461 if (!use_4addr) {
Jiri Pirkof350a0a82010-06-15 06:50:45 +00002462 if (netdev && (netdev->priv_flags & IFF_BRIDGE_PORT))
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002463 return -EBUSY;
Johannes Berg9bc383d2009-11-19 11:55:19 +01002464 return 0;
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002465 }
Johannes Berg9bc383d2009-11-19 11:55:19 +01002466
2467 switch (iftype) {
2468 case NL80211_IFTYPE_AP_VLAN:
2469 if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_AP)
2470 return 0;
2471 break;
2472 case NL80211_IFTYPE_STATION:
2473 if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_STATION)
2474 return 0;
2475 break;
2476 default:
2477 break;
2478 }
2479
2480 return -EOPNOTSUPP;
2481}
2482
Johannes Berg55682962007-09-20 13:09:35 -04002483static int nl80211_set_interface(struct sk_buff *skb, struct genl_info *info)
2484{
Johannes Berg4c476992010-10-04 21:36:35 +02002485 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002486 struct vif_params params;
Johannes Berge36d56b2009-06-09 21:04:43 +02002487 int err;
Johannes Berg04a773a2009-04-19 21:24:32 +02002488 enum nl80211_iftype otype, ntype;
Johannes Berg4c476992010-10-04 21:36:35 +02002489 struct net_device *dev = info->user_ptr[1];
Johannes Berg92ffe052008-09-16 20:39:36 +02002490 u32 _flags, *flags = NULL;
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002491 bool change = false;
Johannes Berg55682962007-09-20 13:09:35 -04002492
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002493 memset(&params, 0, sizeof(params));
2494
Johannes Berg04a773a2009-04-19 21:24:32 +02002495 otype = ntype = dev->ieee80211_ptr->iftype;
Johannes Berg55682962007-09-20 13:09:35 -04002496
Johannes Berg723b0382008-09-16 20:22:09 +02002497 if (info->attrs[NL80211_ATTR_IFTYPE]) {
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002498 ntype = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]);
Johannes Berg04a773a2009-04-19 21:24:32 +02002499 if (otype != ntype)
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002500 change = true;
Johannes Berg4c476992010-10-04 21:36:35 +02002501 if (ntype > NL80211_IFTYPE_MAX)
2502 return -EINVAL;
Johannes Berg723b0382008-09-16 20:22:09 +02002503 }
2504
Johannes Berg92ffe052008-09-16 20:39:36 +02002505 if (info->attrs[NL80211_ATTR_MESH_ID]) {
Johannes Berg29cbe682010-12-03 09:20:44 +01002506 struct wireless_dev *wdev = dev->ieee80211_ptr;
2507
Johannes Berg4c476992010-10-04 21:36:35 +02002508 if (ntype != NL80211_IFTYPE_MESH_POINT)
2509 return -EINVAL;
Johannes Berg29cbe682010-12-03 09:20:44 +01002510 if (netif_running(dev))
2511 return -EBUSY;
2512
2513 wdev_lock(wdev);
2514 BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN !=
2515 IEEE80211_MAX_MESH_ID_LEN);
2516 wdev->mesh_id_up_len =
2517 nla_len(info->attrs[NL80211_ATTR_MESH_ID]);
2518 memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]),
2519 wdev->mesh_id_up_len);
2520 wdev_unlock(wdev);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002521 }
2522
Felix Fietkau8b787642009-11-10 18:53:10 +01002523 if (info->attrs[NL80211_ATTR_4ADDR]) {
2524 params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]);
2525 change = true;
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002526 err = nl80211_valid_4addr(rdev, dev, params.use_4addr, ntype);
Johannes Berg9bc383d2009-11-19 11:55:19 +01002527 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02002528 return err;
Felix Fietkau8b787642009-11-10 18:53:10 +01002529 } else {
2530 params.use_4addr = -1;
2531 }
2532
Johannes Berg92ffe052008-09-16 20:39:36 +02002533 if (info->attrs[NL80211_ATTR_MNTR_FLAGS]) {
Johannes Berg4c476992010-10-04 21:36:35 +02002534 if (ntype != NL80211_IFTYPE_MONITOR)
2535 return -EINVAL;
Johannes Berg92ffe052008-09-16 20:39:36 +02002536 err = parse_monitor_flags(info->attrs[NL80211_ATTR_MNTR_FLAGS],
2537 &_flags);
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002538 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02002539 return err;
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002540
2541 flags = &_flags;
2542 change = true;
Johannes Berg92ffe052008-09-16 20:39:36 +02002543 }
Johannes Berg3b858752009-03-12 09:55:09 +01002544
Luciano Coelho18003292013-08-29 13:26:57 +03002545 if (flags && (*flags & MONITOR_FLAG_ACTIVE) &&
Felix Fietkaue057d3c2013-05-28 13:01:52 +02002546 !(rdev->wiphy.features & NL80211_FEATURE_ACTIVE_MONITOR))
2547 return -EOPNOTSUPP;
2548
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002549 if (change)
Johannes Berg3d54d252009-08-21 14:51:05 +02002550 err = cfg80211_change_iface(rdev, dev, ntype, flags, &params);
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002551 else
2552 err = 0;
Johannes Berg60719ff2008-09-16 14:55:09 +02002553
Johannes Berg9bc383d2009-11-19 11:55:19 +01002554 if (!err && params.use_4addr != -1)
2555 dev->ieee80211_ptr->use_4addr = params.use_4addr;
2556
Johannes Berg55682962007-09-20 13:09:35 -04002557 return err;
2558}
2559
2560static int nl80211_new_interface(struct sk_buff *skb, struct genl_info *info)
2561{
Johannes Berg4c476992010-10-04 21:36:35 +02002562 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002563 struct vif_params params;
Johannes Berg84efbb82012-06-16 00:00:26 +02002564 struct wireless_dev *wdev;
Johannes Berg1c90f9d2012-06-16 00:05:37 +02002565 struct sk_buff *msg;
Johannes Berg55682962007-09-20 13:09:35 -04002566 int err;
2567 enum nl80211_iftype type = NL80211_IFTYPE_UNSPECIFIED;
Michael Wu66f7ac52008-01-31 19:48:22 +01002568 u32 flags;
Johannes Berg55682962007-09-20 13:09:35 -04002569
Johannes Berg78f22b62014-03-24 17:57:27 +01002570 /* to avoid failing a new interface creation due to pending removal */
2571 cfg80211_destroy_ifaces(rdev);
2572
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002573 memset(&params, 0, sizeof(params));
2574
Johannes Berg55682962007-09-20 13:09:35 -04002575 if (!info->attrs[NL80211_ATTR_IFNAME])
2576 return -EINVAL;
2577
2578 if (info->attrs[NL80211_ATTR_IFTYPE]) {
2579 type = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]);
2580 if (type > NL80211_IFTYPE_MAX)
2581 return -EINVAL;
2582 }
2583
Johannes Berg79c97e92009-07-07 03:56:12 +02002584 if (!rdev->ops->add_virtual_intf ||
Johannes Berg4c476992010-10-04 21:36:35 +02002585 !(rdev->wiphy.interface_modes & (1 << type)))
2586 return -EOPNOTSUPP;
Johannes Berg55682962007-09-20 13:09:35 -04002587
Arend van Spriel1c18f142013-01-08 10:17:27 +01002588 if (type == NL80211_IFTYPE_P2P_DEVICE && info->attrs[NL80211_ATTR_MAC]) {
2589 nla_memcpy(params.macaddr, info->attrs[NL80211_ATTR_MAC],
2590 ETH_ALEN);
2591 if (!is_valid_ether_addr(params.macaddr))
2592 return -EADDRNOTAVAIL;
2593 }
2594
Johannes Berg9bc383d2009-11-19 11:55:19 +01002595 if (info->attrs[NL80211_ATTR_4ADDR]) {
Felix Fietkau8b787642009-11-10 18:53:10 +01002596 params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]);
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002597 err = nl80211_valid_4addr(rdev, NULL, params.use_4addr, type);
Johannes Berg9bc383d2009-11-19 11:55:19 +01002598 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02002599 return err;
Johannes Berg9bc383d2009-11-19 11:55:19 +01002600 }
Felix Fietkau8b787642009-11-10 18:53:10 +01002601
Johannes Berg1c90f9d2012-06-16 00:05:37 +02002602 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
2603 if (!msg)
2604 return -ENOMEM;
2605
Michael Wu66f7ac52008-01-31 19:48:22 +01002606 err = parse_monitor_flags(type == NL80211_IFTYPE_MONITOR ?
2607 info->attrs[NL80211_ATTR_MNTR_FLAGS] : NULL,
2608 &flags);
Felix Fietkaue057d3c2013-05-28 13:01:52 +02002609
Luciano Coelho18003292013-08-29 13:26:57 +03002610 if (!err && (flags & MONITOR_FLAG_ACTIVE) &&
Felix Fietkaue057d3c2013-05-28 13:01:52 +02002611 !(rdev->wiphy.features & NL80211_FEATURE_ACTIVE_MONITOR))
2612 return -EOPNOTSUPP;
2613
Hila Gonene35e4d22012-06-27 17:19:42 +03002614 wdev = rdev_add_virtual_intf(rdev,
2615 nla_data(info->attrs[NL80211_ATTR_IFNAME]),
2616 type, err ? NULL : &flags, &params);
Johannes Berg1c90f9d2012-06-16 00:05:37 +02002617 if (IS_ERR(wdev)) {
2618 nlmsg_free(msg);
Johannes Berg84efbb82012-06-16 00:00:26 +02002619 return PTR_ERR(wdev);
Johannes Berg1c90f9d2012-06-16 00:05:37 +02002620 }
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002621
Johannes Berg78f22b62014-03-24 17:57:27 +01002622 if (info->attrs[NL80211_ATTR_IFACE_SOCKET_OWNER])
2623 wdev->owner_nlportid = info->snd_portid;
2624
Johannes Berg98104fde2012-06-16 00:19:54 +02002625 switch (type) {
2626 case NL80211_IFTYPE_MESH_POINT:
2627 if (!info->attrs[NL80211_ATTR_MESH_ID])
2628 break;
Johannes Berg29cbe682010-12-03 09:20:44 +01002629 wdev_lock(wdev);
2630 BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN !=
2631 IEEE80211_MAX_MESH_ID_LEN);
2632 wdev->mesh_id_up_len =
2633 nla_len(info->attrs[NL80211_ATTR_MESH_ID]);
2634 memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]),
2635 wdev->mesh_id_up_len);
2636 wdev_unlock(wdev);
Johannes Berg98104fde2012-06-16 00:19:54 +02002637 break;
2638 case NL80211_IFTYPE_P2P_DEVICE:
2639 /*
2640 * P2P Device doesn't have a netdev, so doesn't go
2641 * through the netdev notifier and must be added here
2642 */
2643 mutex_init(&wdev->mtx);
2644 INIT_LIST_HEAD(&wdev->event_list);
2645 spin_lock_init(&wdev->event_lock);
2646 INIT_LIST_HEAD(&wdev->mgmt_registrations);
2647 spin_lock_init(&wdev->mgmt_registrations_lock);
2648
Johannes Berg98104fde2012-06-16 00:19:54 +02002649 wdev->identifier = ++rdev->wdev_id;
2650 list_add_rcu(&wdev->list, &rdev->wdev_list);
2651 rdev->devlist_generation++;
Johannes Berg98104fde2012-06-16 00:19:54 +02002652 break;
2653 default:
2654 break;
Johannes Berg29cbe682010-12-03 09:20:44 +01002655 }
2656
Eric W. Biederman15e47302012-09-07 20:12:54 +00002657 if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berg1c90f9d2012-06-16 00:05:37 +02002658 rdev, wdev) < 0) {
2659 nlmsg_free(msg);
2660 return -ENOBUFS;
2661 }
2662
2663 return genlmsg_reply(msg, info);
Johannes Berg55682962007-09-20 13:09:35 -04002664}
2665
2666static int nl80211_del_interface(struct sk_buff *skb, struct genl_info *info)
2667{
Johannes Berg4c476992010-10-04 21:36:35 +02002668 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg84efbb82012-06-16 00:00:26 +02002669 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg55682962007-09-20 13:09:35 -04002670
Johannes Berg4c476992010-10-04 21:36:35 +02002671 if (!rdev->ops->del_virtual_intf)
2672 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01002673
Johannes Berg84efbb82012-06-16 00:00:26 +02002674 /*
2675 * If we remove a wireless device without a netdev then clear
2676 * user_ptr[1] so that nl80211_post_doit won't dereference it
2677 * to check if it needs to do dev_put(). Otherwise it crashes
2678 * since the wdev has been freed, unlike with a netdev where
2679 * we need the dev_put() for the netdev to really be freed.
2680 */
2681 if (!wdev->netdev)
2682 info->user_ptr[1] = NULL;
2683
Hila Gonene35e4d22012-06-27 17:19:42 +03002684 return rdev_del_virtual_intf(rdev, wdev);
Johannes Berg55682962007-09-20 13:09:35 -04002685}
2686
Simon Wunderlich1d9d9212011-11-18 14:20:43 +01002687static int nl80211_set_noack_map(struct sk_buff *skb, struct genl_info *info)
2688{
2689 struct cfg80211_registered_device *rdev = info->user_ptr[0];
2690 struct net_device *dev = info->user_ptr[1];
2691 u16 noack_map;
2692
2693 if (!info->attrs[NL80211_ATTR_NOACK_MAP])
2694 return -EINVAL;
2695
2696 if (!rdev->ops->set_noack_map)
2697 return -EOPNOTSUPP;
2698
2699 noack_map = nla_get_u16(info->attrs[NL80211_ATTR_NOACK_MAP]);
2700
Hila Gonene35e4d22012-06-27 17:19:42 +03002701 return rdev_set_noack_map(rdev, dev, noack_map);
Simon Wunderlich1d9d9212011-11-18 14:20:43 +01002702}
2703
Johannes Berg41ade002007-12-19 02:03:29 +01002704struct get_key_cookie {
2705 struct sk_buff *msg;
2706 int error;
Johannes Bergb9454e82009-07-08 13:29:08 +02002707 int idx;
Johannes Berg41ade002007-12-19 02:03:29 +01002708};
2709
2710static void get_key_callback(void *c, struct key_params *params)
2711{
Johannes Bergb9454e82009-07-08 13:29:08 +02002712 struct nlattr *key;
Johannes Berg41ade002007-12-19 02:03:29 +01002713 struct get_key_cookie *cookie = c;
2714
David S. Miller9360ffd2012-03-29 04:41:26 -04002715 if ((params->key &&
2716 nla_put(cookie->msg, NL80211_ATTR_KEY_DATA,
2717 params->key_len, params->key)) ||
2718 (params->seq &&
2719 nla_put(cookie->msg, NL80211_ATTR_KEY_SEQ,
2720 params->seq_len, params->seq)) ||
2721 (params->cipher &&
2722 nla_put_u32(cookie->msg, NL80211_ATTR_KEY_CIPHER,
2723 params->cipher)))
2724 goto nla_put_failure;
Johannes Berg41ade002007-12-19 02:03:29 +01002725
Johannes Bergb9454e82009-07-08 13:29:08 +02002726 key = nla_nest_start(cookie->msg, NL80211_ATTR_KEY);
2727 if (!key)
2728 goto nla_put_failure;
2729
David S. Miller9360ffd2012-03-29 04:41:26 -04002730 if ((params->key &&
2731 nla_put(cookie->msg, NL80211_KEY_DATA,
2732 params->key_len, params->key)) ||
2733 (params->seq &&
2734 nla_put(cookie->msg, NL80211_KEY_SEQ,
2735 params->seq_len, params->seq)) ||
2736 (params->cipher &&
2737 nla_put_u32(cookie->msg, NL80211_KEY_CIPHER,
2738 params->cipher)))
2739 goto nla_put_failure;
Johannes Bergb9454e82009-07-08 13:29:08 +02002740
David S. Miller9360ffd2012-03-29 04:41:26 -04002741 if (nla_put_u8(cookie->msg, NL80211_ATTR_KEY_IDX, cookie->idx))
2742 goto nla_put_failure;
Johannes Bergb9454e82009-07-08 13:29:08 +02002743
2744 nla_nest_end(cookie->msg, key);
2745
Johannes Berg41ade002007-12-19 02:03:29 +01002746 return;
2747 nla_put_failure:
2748 cookie->error = 1;
2749}
2750
2751static int nl80211_get_key(struct sk_buff *skb, struct genl_info *info)
2752{
Johannes Berg4c476992010-10-04 21:36:35 +02002753 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg41ade002007-12-19 02:03:29 +01002754 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02002755 struct net_device *dev = info->user_ptr[1];
Johannes Berg41ade002007-12-19 02:03:29 +01002756 u8 key_idx = 0;
Johannes Berge31b8212010-10-05 19:39:30 +02002757 const u8 *mac_addr = NULL;
2758 bool pairwise;
Johannes Berg41ade002007-12-19 02:03:29 +01002759 struct get_key_cookie cookie = {
2760 .error = 0,
2761 };
2762 void *hdr;
2763 struct sk_buff *msg;
2764
2765 if (info->attrs[NL80211_ATTR_KEY_IDX])
2766 key_idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]);
2767
Jouni Malinen3cfcf6ac2009-01-08 13:32:02 +02002768 if (key_idx > 5)
Johannes Berg41ade002007-12-19 02:03:29 +01002769 return -EINVAL;
2770
2771 if (info->attrs[NL80211_ATTR_MAC])
2772 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
2773
Johannes Berge31b8212010-10-05 19:39:30 +02002774 pairwise = !!mac_addr;
2775 if (info->attrs[NL80211_ATTR_KEY_TYPE]) {
2776 u32 kt = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]);
2777 if (kt >= NUM_NL80211_KEYTYPES)
2778 return -EINVAL;
2779 if (kt != NL80211_KEYTYPE_GROUP &&
2780 kt != NL80211_KEYTYPE_PAIRWISE)
2781 return -EINVAL;
2782 pairwise = kt == NL80211_KEYTYPE_PAIRWISE;
2783 }
2784
Johannes Berg4c476992010-10-04 21:36:35 +02002785 if (!rdev->ops->get_key)
2786 return -EOPNOTSUPP;
Johannes Berg41ade002007-12-19 02:03:29 +01002787
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07002788 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02002789 if (!msg)
2790 return -ENOMEM;
Johannes Berg41ade002007-12-19 02:03:29 +01002791
Eric W. Biederman15e47302012-09-07 20:12:54 +00002792 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berg41ade002007-12-19 02:03:29 +01002793 NL80211_CMD_NEW_KEY);
Dan Carpentercb35fba2013-08-14 14:50:01 +03002794 if (!hdr)
Johannes Berg9fe271a2013-10-25 11:15:12 +02002795 goto nla_put_failure;
Johannes Berg41ade002007-12-19 02:03:29 +01002796
2797 cookie.msg = msg;
Johannes Bergb9454e82009-07-08 13:29:08 +02002798 cookie.idx = key_idx;
Johannes Berg41ade002007-12-19 02:03:29 +01002799
David S. Miller9360ffd2012-03-29 04:41:26 -04002800 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
2801 nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_idx))
2802 goto nla_put_failure;
2803 if (mac_addr &&
2804 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr))
2805 goto nla_put_failure;
Johannes Berg41ade002007-12-19 02:03:29 +01002806
Johannes Berge31b8212010-10-05 19:39:30 +02002807 if (pairwise && mac_addr &&
2808 !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN))
2809 return -ENOENT;
2810
Hila Gonene35e4d22012-06-27 17:19:42 +03002811 err = rdev_get_key(rdev, dev, key_idx, pairwise, mac_addr, &cookie,
2812 get_key_callback);
Johannes Berg41ade002007-12-19 02:03:29 +01002813
2814 if (err)
Niko Jokinen6c95e2a2009-07-15 11:00:53 +03002815 goto free_msg;
Johannes Berg41ade002007-12-19 02:03:29 +01002816
2817 if (cookie.error)
2818 goto nla_put_failure;
2819
2820 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02002821 return genlmsg_reply(msg, info);
Johannes Berg41ade002007-12-19 02:03:29 +01002822
2823 nla_put_failure:
2824 err = -ENOBUFS;
Niko Jokinen6c95e2a2009-07-15 11:00:53 +03002825 free_msg:
Johannes Berg41ade002007-12-19 02:03:29 +01002826 nlmsg_free(msg);
Johannes Berg41ade002007-12-19 02:03:29 +01002827 return err;
2828}
2829
2830static int nl80211_set_key(struct sk_buff *skb, struct genl_info *info)
2831{
Johannes Berg4c476992010-10-04 21:36:35 +02002832 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Bergb9454e82009-07-08 13:29:08 +02002833 struct key_parse key;
Johannes Berg41ade002007-12-19 02:03:29 +01002834 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02002835 struct net_device *dev = info->user_ptr[1];
Johannes Berg41ade002007-12-19 02:03:29 +01002836
Johannes Bergb9454e82009-07-08 13:29:08 +02002837 err = nl80211_parse_key(info, &key);
2838 if (err)
2839 return err;
2840
2841 if (key.idx < 0)
Johannes Berg41ade002007-12-19 02:03:29 +01002842 return -EINVAL;
2843
Johannes Bergb9454e82009-07-08 13:29:08 +02002844 /* only support setting default key */
2845 if (!key.def && !key.defmgmt)
Johannes Berg41ade002007-12-19 02:03:29 +01002846 return -EINVAL;
2847
Johannes Bergfffd0932009-07-08 14:22:54 +02002848 wdev_lock(dev->ieee80211_ptr);
Johannes Bergdbd2fd62010-12-09 19:58:59 +01002849
2850 if (key.def) {
2851 if (!rdev->ops->set_default_key) {
2852 err = -EOPNOTSUPP;
2853 goto out;
2854 }
2855
2856 err = nl80211_key_allowed(dev->ieee80211_ptr);
2857 if (err)
2858 goto out;
2859
Hila Gonene35e4d22012-06-27 17:19:42 +03002860 err = rdev_set_default_key(rdev, dev, key.idx,
Johannes Bergdbd2fd62010-12-09 19:58:59 +01002861 key.def_uni, key.def_multi);
2862
2863 if (err)
2864 goto out;
Johannes Bergfffd0932009-07-08 14:22:54 +02002865
Johannes Berg3d23e342009-09-29 23:27:28 +02002866#ifdef CONFIG_CFG80211_WEXT
Johannes Bergdbd2fd62010-12-09 19:58:59 +01002867 dev->ieee80211_ptr->wext.default_key = key.idx;
Johannes Berg08645122009-05-11 13:54:58 +02002868#endif
Johannes Bergdbd2fd62010-12-09 19:58:59 +01002869 } else {
2870 if (key.def_uni || !key.def_multi) {
2871 err = -EINVAL;
2872 goto out;
2873 }
2874
2875 if (!rdev->ops->set_default_mgmt_key) {
2876 err = -EOPNOTSUPP;
2877 goto out;
2878 }
2879
2880 err = nl80211_key_allowed(dev->ieee80211_ptr);
2881 if (err)
2882 goto out;
2883
Hila Gonene35e4d22012-06-27 17:19:42 +03002884 err = rdev_set_default_mgmt_key(rdev, dev, key.idx);
Johannes Bergdbd2fd62010-12-09 19:58:59 +01002885 if (err)
2886 goto out;
2887
2888#ifdef CONFIG_CFG80211_WEXT
2889 dev->ieee80211_ptr->wext.default_mgmt_key = key.idx;
2890#endif
2891 }
2892
2893 out:
Johannes Bergfffd0932009-07-08 14:22:54 +02002894 wdev_unlock(dev->ieee80211_ptr);
Johannes Berg41ade002007-12-19 02:03:29 +01002895
Johannes Berg41ade002007-12-19 02:03:29 +01002896 return err;
2897}
2898
2899static int nl80211_new_key(struct sk_buff *skb, struct genl_info *info)
2900{
Johannes Berg4c476992010-10-04 21:36:35 +02002901 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Bergfffd0932009-07-08 14:22:54 +02002902 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02002903 struct net_device *dev = info->user_ptr[1];
Johannes Bergb9454e82009-07-08 13:29:08 +02002904 struct key_parse key;
Johannes Berge31b8212010-10-05 19:39:30 +02002905 const u8 *mac_addr = NULL;
Johannes Berg41ade002007-12-19 02:03:29 +01002906
Johannes Bergb9454e82009-07-08 13:29:08 +02002907 err = nl80211_parse_key(info, &key);
2908 if (err)
2909 return err;
Johannes Berg41ade002007-12-19 02:03:29 +01002910
Johannes Bergb9454e82009-07-08 13:29:08 +02002911 if (!key.p.key)
Johannes Berg41ade002007-12-19 02:03:29 +01002912 return -EINVAL;
2913
Johannes Berg41ade002007-12-19 02:03:29 +01002914 if (info->attrs[NL80211_ATTR_MAC])
2915 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
2916
Johannes Berge31b8212010-10-05 19:39:30 +02002917 if (key.type == -1) {
2918 if (mac_addr)
2919 key.type = NL80211_KEYTYPE_PAIRWISE;
2920 else
2921 key.type = NL80211_KEYTYPE_GROUP;
2922 }
2923
2924 /* for now */
2925 if (key.type != NL80211_KEYTYPE_PAIRWISE &&
2926 key.type != NL80211_KEYTYPE_GROUP)
2927 return -EINVAL;
2928
Johannes Berg4c476992010-10-04 21:36:35 +02002929 if (!rdev->ops->add_key)
2930 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01002931
Johannes Berge31b8212010-10-05 19:39:30 +02002932 if (cfg80211_validate_key_settings(rdev, &key.p, key.idx,
2933 key.type == NL80211_KEYTYPE_PAIRWISE,
2934 mac_addr))
Johannes Berg4c476992010-10-04 21:36:35 +02002935 return -EINVAL;
Johannes Bergfffd0932009-07-08 14:22:54 +02002936
2937 wdev_lock(dev->ieee80211_ptr);
2938 err = nl80211_key_allowed(dev->ieee80211_ptr);
2939 if (!err)
Hila Gonene35e4d22012-06-27 17:19:42 +03002940 err = rdev_add_key(rdev, dev, key.idx,
2941 key.type == NL80211_KEYTYPE_PAIRWISE,
2942 mac_addr, &key.p);
Johannes Bergfffd0932009-07-08 14:22:54 +02002943 wdev_unlock(dev->ieee80211_ptr);
Johannes Berg41ade002007-12-19 02:03:29 +01002944
Johannes Berg41ade002007-12-19 02:03:29 +01002945 return err;
2946}
2947
2948static int nl80211_del_key(struct sk_buff *skb, struct genl_info *info)
2949{
Johannes Berg4c476992010-10-04 21:36:35 +02002950 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg41ade002007-12-19 02:03:29 +01002951 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02002952 struct net_device *dev = info->user_ptr[1];
Johannes Berg41ade002007-12-19 02:03:29 +01002953 u8 *mac_addr = NULL;
Johannes Bergb9454e82009-07-08 13:29:08 +02002954 struct key_parse key;
Johannes Berg41ade002007-12-19 02:03:29 +01002955
Johannes Bergb9454e82009-07-08 13:29:08 +02002956 err = nl80211_parse_key(info, &key);
2957 if (err)
2958 return err;
Johannes Berg41ade002007-12-19 02:03:29 +01002959
2960 if (info->attrs[NL80211_ATTR_MAC])
2961 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
2962
Johannes Berge31b8212010-10-05 19:39:30 +02002963 if (key.type == -1) {
2964 if (mac_addr)
2965 key.type = NL80211_KEYTYPE_PAIRWISE;
2966 else
2967 key.type = NL80211_KEYTYPE_GROUP;
2968 }
2969
2970 /* for now */
2971 if (key.type != NL80211_KEYTYPE_PAIRWISE &&
2972 key.type != NL80211_KEYTYPE_GROUP)
2973 return -EINVAL;
2974
Johannes Berg4c476992010-10-04 21:36:35 +02002975 if (!rdev->ops->del_key)
2976 return -EOPNOTSUPP;
Johannes Berg41ade002007-12-19 02:03:29 +01002977
Johannes Bergfffd0932009-07-08 14:22:54 +02002978 wdev_lock(dev->ieee80211_ptr);
2979 err = nl80211_key_allowed(dev->ieee80211_ptr);
Johannes Berge31b8212010-10-05 19:39:30 +02002980
2981 if (key.type == NL80211_KEYTYPE_PAIRWISE && mac_addr &&
2982 !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN))
2983 err = -ENOENT;
2984
Johannes Bergfffd0932009-07-08 14:22:54 +02002985 if (!err)
Hila Gonene35e4d22012-06-27 17:19:42 +03002986 err = rdev_del_key(rdev, dev, key.idx,
2987 key.type == NL80211_KEYTYPE_PAIRWISE,
2988 mac_addr);
Johannes Berg41ade002007-12-19 02:03:29 +01002989
Johannes Berg3d23e342009-09-29 23:27:28 +02002990#ifdef CONFIG_CFG80211_WEXT
Johannes Berg08645122009-05-11 13:54:58 +02002991 if (!err) {
Johannes Bergb9454e82009-07-08 13:29:08 +02002992 if (key.idx == dev->ieee80211_ptr->wext.default_key)
Johannes Berg08645122009-05-11 13:54:58 +02002993 dev->ieee80211_ptr->wext.default_key = -1;
Johannes Bergb9454e82009-07-08 13:29:08 +02002994 else if (key.idx == dev->ieee80211_ptr->wext.default_mgmt_key)
Johannes Berg08645122009-05-11 13:54:58 +02002995 dev->ieee80211_ptr->wext.default_mgmt_key = -1;
2996 }
2997#endif
Johannes Bergfffd0932009-07-08 14:22:54 +02002998 wdev_unlock(dev->ieee80211_ptr);
Johannes Berg08645122009-05-11 13:54:58 +02002999
Johannes Berg41ade002007-12-19 02:03:29 +01003000 return err;
3001}
3002
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +05303003/* This function returns an error or the number of nested attributes */
3004static int validate_acl_mac_addrs(struct nlattr *nl_attr)
3005{
3006 struct nlattr *attr;
3007 int n_entries = 0, tmp;
3008
3009 nla_for_each_nested(attr, nl_attr, tmp) {
3010 if (nla_len(attr) != ETH_ALEN)
3011 return -EINVAL;
3012
3013 n_entries++;
3014 }
3015
3016 return n_entries;
3017}
3018
3019/*
3020 * This function parses ACL information and allocates memory for ACL data.
3021 * On successful return, the calling function is responsible to free the
3022 * ACL buffer returned by this function.
3023 */
3024static struct cfg80211_acl_data *parse_acl_data(struct wiphy *wiphy,
3025 struct genl_info *info)
3026{
3027 enum nl80211_acl_policy acl_policy;
3028 struct nlattr *attr;
3029 struct cfg80211_acl_data *acl;
3030 int i = 0, n_entries, tmp;
3031
3032 if (!wiphy->max_acl_mac_addrs)
3033 return ERR_PTR(-EOPNOTSUPP);
3034
3035 if (!info->attrs[NL80211_ATTR_ACL_POLICY])
3036 return ERR_PTR(-EINVAL);
3037
3038 acl_policy = nla_get_u32(info->attrs[NL80211_ATTR_ACL_POLICY]);
3039 if (acl_policy != NL80211_ACL_POLICY_ACCEPT_UNLESS_LISTED &&
3040 acl_policy != NL80211_ACL_POLICY_DENY_UNLESS_LISTED)
3041 return ERR_PTR(-EINVAL);
3042
3043 if (!info->attrs[NL80211_ATTR_MAC_ADDRS])
3044 return ERR_PTR(-EINVAL);
3045
3046 n_entries = validate_acl_mac_addrs(info->attrs[NL80211_ATTR_MAC_ADDRS]);
3047 if (n_entries < 0)
3048 return ERR_PTR(n_entries);
3049
3050 if (n_entries > wiphy->max_acl_mac_addrs)
3051 return ERR_PTR(-ENOTSUPP);
3052
3053 acl = kzalloc(sizeof(*acl) + (sizeof(struct mac_address) * n_entries),
3054 GFP_KERNEL);
3055 if (!acl)
3056 return ERR_PTR(-ENOMEM);
3057
3058 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_MAC_ADDRS], tmp) {
3059 memcpy(acl->mac_addrs[i].addr, nla_data(attr), ETH_ALEN);
3060 i++;
3061 }
3062
3063 acl->n_acl_entries = n_entries;
3064 acl->acl_policy = acl_policy;
3065
3066 return acl;
3067}
3068
3069static int nl80211_set_mac_acl(struct sk_buff *skb, struct genl_info *info)
3070{
3071 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3072 struct net_device *dev = info->user_ptr[1];
3073 struct cfg80211_acl_data *acl;
3074 int err;
3075
3076 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
3077 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
3078 return -EOPNOTSUPP;
3079
3080 if (!dev->ieee80211_ptr->beacon_interval)
3081 return -EINVAL;
3082
3083 acl = parse_acl_data(&rdev->wiphy, info);
3084 if (IS_ERR(acl))
3085 return PTR_ERR(acl);
3086
3087 err = rdev_set_mac_acl(rdev, dev, acl);
3088
3089 kfree(acl);
3090
3091 return err;
3092}
3093
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003094static int nl80211_parse_beacon(struct nlattr *attrs[],
Johannes Berg88600202012-02-13 15:17:18 +01003095 struct cfg80211_beacon_data *bcn)
Johannes Berged1b6cc2007-12-19 02:03:32 +01003096{
Johannes Berg88600202012-02-13 15:17:18 +01003097 bool haveinfo = false;
Johannes Berged1b6cc2007-12-19 02:03:32 +01003098
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003099 if (!is_valid_ie_attr(attrs[NL80211_ATTR_BEACON_TAIL]) ||
3100 !is_valid_ie_attr(attrs[NL80211_ATTR_IE]) ||
3101 !is_valid_ie_attr(attrs[NL80211_ATTR_IE_PROBE_RESP]) ||
3102 !is_valid_ie_attr(attrs[NL80211_ATTR_IE_ASSOC_RESP]))
Johannes Bergf4a11bb2009-03-27 12:40:28 +01003103 return -EINVAL;
3104
Johannes Berg88600202012-02-13 15:17:18 +01003105 memset(bcn, 0, sizeof(*bcn));
Johannes Berged1b6cc2007-12-19 02:03:32 +01003106
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003107 if (attrs[NL80211_ATTR_BEACON_HEAD]) {
3108 bcn->head = nla_data(attrs[NL80211_ATTR_BEACON_HEAD]);
3109 bcn->head_len = nla_len(attrs[NL80211_ATTR_BEACON_HEAD]);
Johannes Berg88600202012-02-13 15:17:18 +01003110 if (!bcn->head_len)
3111 return -EINVAL;
3112 haveinfo = true;
Johannes Berged1b6cc2007-12-19 02:03:32 +01003113 }
3114
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003115 if (attrs[NL80211_ATTR_BEACON_TAIL]) {
3116 bcn->tail = nla_data(attrs[NL80211_ATTR_BEACON_TAIL]);
3117 bcn->tail_len = nla_len(attrs[NL80211_ATTR_BEACON_TAIL]);
Johannes Berg88600202012-02-13 15:17:18 +01003118 haveinfo = true;
Johannes Berged1b6cc2007-12-19 02:03:32 +01003119 }
3120
Johannes Berg4c476992010-10-04 21:36:35 +02003121 if (!haveinfo)
3122 return -EINVAL;
Johannes Berged1b6cc2007-12-19 02:03:32 +01003123
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003124 if (attrs[NL80211_ATTR_IE]) {
3125 bcn->beacon_ies = nla_data(attrs[NL80211_ATTR_IE]);
3126 bcn->beacon_ies_len = nla_len(attrs[NL80211_ATTR_IE]);
Jouni Malinen9946ecf2011-08-10 23:55:56 +03003127 }
3128
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003129 if (attrs[NL80211_ATTR_IE_PROBE_RESP]) {
Johannes Berg88600202012-02-13 15:17:18 +01003130 bcn->proberesp_ies =
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003131 nla_data(attrs[NL80211_ATTR_IE_PROBE_RESP]);
Johannes Berg88600202012-02-13 15:17:18 +01003132 bcn->proberesp_ies_len =
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003133 nla_len(attrs[NL80211_ATTR_IE_PROBE_RESP]);
Jouni Malinen9946ecf2011-08-10 23:55:56 +03003134 }
3135
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003136 if (attrs[NL80211_ATTR_IE_ASSOC_RESP]) {
Johannes Berg88600202012-02-13 15:17:18 +01003137 bcn->assocresp_ies =
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003138 nla_data(attrs[NL80211_ATTR_IE_ASSOC_RESP]);
Johannes Berg88600202012-02-13 15:17:18 +01003139 bcn->assocresp_ies_len =
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003140 nla_len(attrs[NL80211_ATTR_IE_ASSOC_RESP]);
Jouni Malinen9946ecf2011-08-10 23:55:56 +03003141 }
3142
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003143 if (attrs[NL80211_ATTR_PROBE_RESP]) {
3144 bcn->probe_resp = nla_data(attrs[NL80211_ATTR_PROBE_RESP]);
3145 bcn->probe_resp_len = nla_len(attrs[NL80211_ATTR_PROBE_RESP]);
Arik Nemtsov00f740e2011-11-10 11:28:56 +02003146 }
3147
Johannes Berg88600202012-02-13 15:17:18 +01003148 return 0;
3149}
3150
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003151static bool nl80211_get_ap_channel(struct cfg80211_registered_device *rdev,
3152 struct cfg80211_ap_settings *params)
3153{
3154 struct wireless_dev *wdev;
3155 bool ret = false;
3156
Johannes Berg89a54e42012-06-15 14:33:17 +02003157 list_for_each_entry(wdev, &rdev->wdev_list, list) {
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003158 if (wdev->iftype != NL80211_IFTYPE_AP &&
3159 wdev->iftype != NL80211_IFTYPE_P2P_GO)
3160 continue;
3161
Johannes Berg683b6d32012-11-08 21:25:48 +01003162 if (!wdev->preset_chandef.chan)
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003163 continue;
3164
Johannes Berg683b6d32012-11-08 21:25:48 +01003165 params->chandef = wdev->preset_chandef;
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003166 ret = true;
3167 break;
3168 }
3169
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003170 return ret;
3171}
3172
Jouni Malinene39e5b52012-09-30 19:29:39 +03003173static bool nl80211_valid_auth_type(struct cfg80211_registered_device *rdev,
3174 enum nl80211_auth_type auth_type,
3175 enum nl80211_commands cmd)
3176{
3177 if (auth_type > NL80211_AUTHTYPE_MAX)
3178 return false;
3179
3180 switch (cmd) {
3181 case NL80211_CMD_AUTHENTICATE:
3182 if (!(rdev->wiphy.features & NL80211_FEATURE_SAE) &&
3183 auth_type == NL80211_AUTHTYPE_SAE)
3184 return false;
3185 return true;
3186 case NL80211_CMD_CONNECT:
3187 case NL80211_CMD_START_AP:
3188 /* SAE not supported yet */
3189 if (auth_type == NL80211_AUTHTYPE_SAE)
3190 return false;
3191 return true;
3192 default:
3193 return false;
3194 }
3195}
3196
Johannes Berg88600202012-02-13 15:17:18 +01003197static int nl80211_start_ap(struct sk_buff *skb, struct genl_info *info)
3198{
3199 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3200 struct net_device *dev = info->user_ptr[1];
3201 struct wireless_dev *wdev = dev->ieee80211_ptr;
3202 struct cfg80211_ap_settings params;
3203 int err;
3204
3205 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
3206 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
3207 return -EOPNOTSUPP;
3208
3209 if (!rdev->ops->start_ap)
3210 return -EOPNOTSUPP;
3211
3212 if (wdev->beacon_interval)
3213 return -EALREADY;
3214
3215 memset(&params, 0, sizeof(params));
3216
3217 /* these are required for START_AP */
3218 if (!info->attrs[NL80211_ATTR_BEACON_INTERVAL] ||
3219 !info->attrs[NL80211_ATTR_DTIM_PERIOD] ||
3220 !info->attrs[NL80211_ATTR_BEACON_HEAD])
3221 return -EINVAL;
3222
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003223 err = nl80211_parse_beacon(info->attrs, &params.beacon);
Johannes Berg88600202012-02-13 15:17:18 +01003224 if (err)
3225 return err;
3226
3227 params.beacon_interval =
3228 nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]);
3229 params.dtim_period =
3230 nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]);
3231
3232 err = cfg80211_validate_beacon_int(rdev, params.beacon_interval);
3233 if (err)
3234 return err;
3235
3236 /*
3237 * In theory, some of these attributes should be required here
3238 * but since they were not used when the command was originally
3239 * added, keep them optional for old user space programs to let
3240 * them continue to work with drivers that do not need the
3241 * additional information -- drivers must check!
3242 */
3243 if (info->attrs[NL80211_ATTR_SSID]) {
3244 params.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
3245 params.ssid_len =
3246 nla_len(info->attrs[NL80211_ATTR_SSID]);
3247 if (params.ssid_len == 0 ||
3248 params.ssid_len > IEEE80211_MAX_SSID_LEN)
3249 return -EINVAL;
3250 }
3251
3252 if (info->attrs[NL80211_ATTR_HIDDEN_SSID]) {
3253 params.hidden_ssid = nla_get_u32(
3254 info->attrs[NL80211_ATTR_HIDDEN_SSID]);
3255 if (params.hidden_ssid != NL80211_HIDDEN_SSID_NOT_IN_USE &&
3256 params.hidden_ssid != NL80211_HIDDEN_SSID_ZERO_LEN &&
3257 params.hidden_ssid != NL80211_HIDDEN_SSID_ZERO_CONTENTS)
3258 return -EINVAL;
3259 }
3260
3261 params.privacy = !!info->attrs[NL80211_ATTR_PRIVACY];
3262
3263 if (info->attrs[NL80211_ATTR_AUTH_TYPE]) {
3264 params.auth_type = nla_get_u32(
3265 info->attrs[NL80211_ATTR_AUTH_TYPE]);
Jouni Malinene39e5b52012-09-30 19:29:39 +03003266 if (!nl80211_valid_auth_type(rdev, params.auth_type,
3267 NL80211_CMD_START_AP))
Johannes Berg88600202012-02-13 15:17:18 +01003268 return -EINVAL;
3269 } else
3270 params.auth_type = NL80211_AUTHTYPE_AUTOMATIC;
3271
3272 err = nl80211_crypto_settings(rdev, info, &params.crypto,
3273 NL80211_MAX_NR_CIPHER_SUITES);
3274 if (err)
3275 return err;
3276
Vasanthakumar Thiagarajan1b658f12012-03-02 15:50:02 +05303277 if (info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]) {
3278 if (!(rdev->wiphy.features & NL80211_FEATURE_INACTIVITY_TIMER))
3279 return -EOPNOTSUPP;
3280 params.inactivity_timeout = nla_get_u16(
3281 info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]);
3282 }
3283
Johannes Berg53cabad2012-11-14 15:17:28 +01003284 if (info->attrs[NL80211_ATTR_P2P_CTWINDOW]) {
3285 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
3286 return -EINVAL;
3287 params.p2p_ctwindow =
3288 nla_get_u8(info->attrs[NL80211_ATTR_P2P_CTWINDOW]);
3289 if (params.p2p_ctwindow > 127)
3290 return -EINVAL;
3291 if (params.p2p_ctwindow != 0 &&
3292 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_CTWIN))
3293 return -EINVAL;
3294 }
3295
3296 if (info->attrs[NL80211_ATTR_P2P_OPPPS]) {
3297 u8 tmp;
3298
3299 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
3300 return -EINVAL;
3301 tmp = nla_get_u8(info->attrs[NL80211_ATTR_P2P_OPPPS]);
3302 if (tmp > 1)
3303 return -EINVAL;
3304 params.p2p_opp_ps = tmp;
3305 if (params.p2p_opp_ps != 0 &&
3306 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_OPPPS))
3307 return -EINVAL;
3308 }
3309
Johannes Bergaa430da2012-05-16 23:50:18 +02003310 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
Johannes Berg683b6d32012-11-08 21:25:48 +01003311 err = nl80211_parse_chandef(rdev, info, &params.chandef);
3312 if (err)
3313 return err;
3314 } else if (wdev->preset_chandef.chan) {
3315 params.chandef = wdev->preset_chandef;
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003316 } else if (!nl80211_get_ap_channel(rdev, &params))
Johannes Bergaa430da2012-05-16 23:50:18 +02003317 return -EINVAL;
3318
Ilan Peer174e0cd2014-02-23 09:13:01 +02003319 if (!cfg80211_reg_can_beacon(&rdev->wiphy, &params.chandef,
3320 wdev->iftype))
Johannes Bergaa430da2012-05-16 23:50:18 +02003321 return -EINVAL;
3322
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +05303323 if (info->attrs[NL80211_ATTR_ACL_POLICY]) {
3324 params.acl = parse_acl_data(&rdev->wiphy, info);
3325 if (IS_ERR(params.acl))
3326 return PTR_ERR(params.acl);
3327 }
3328
Simon Wunderlichc56589e2013-11-21 18:19:49 +01003329 wdev_lock(wdev);
Hila Gonene35e4d22012-06-27 17:19:42 +03003330 err = rdev_start_ap(rdev, dev, &params);
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003331 if (!err) {
Johannes Berg683b6d32012-11-08 21:25:48 +01003332 wdev->preset_chandef = params.chandef;
Johannes Berg88600202012-02-13 15:17:18 +01003333 wdev->beacon_interval = params.beacon_interval;
Michal Kazior9e0e2962014-01-29 14:22:27 +01003334 wdev->chandef = params.chandef;
Antonio Quartulli06e191e2012-11-07 12:52:19 +01003335 wdev->ssid_len = params.ssid_len;
3336 memcpy(wdev->ssid, params.ssid, wdev->ssid_len);
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003337 }
Simon Wunderlichc56589e2013-11-21 18:19:49 +01003338 wdev_unlock(wdev);
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +05303339
3340 kfree(params.acl);
3341
Johannes Berg56d18932011-05-09 18:41:15 +02003342 return err;
Johannes Berged1b6cc2007-12-19 02:03:32 +01003343}
3344
Johannes Berg88600202012-02-13 15:17:18 +01003345static int nl80211_set_beacon(struct sk_buff *skb, struct genl_info *info)
3346{
3347 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3348 struct net_device *dev = info->user_ptr[1];
3349 struct wireless_dev *wdev = dev->ieee80211_ptr;
3350 struct cfg80211_beacon_data params;
3351 int err;
3352
3353 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
3354 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
3355 return -EOPNOTSUPP;
3356
3357 if (!rdev->ops->change_beacon)
3358 return -EOPNOTSUPP;
3359
3360 if (!wdev->beacon_interval)
3361 return -EINVAL;
3362
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003363 err = nl80211_parse_beacon(info->attrs, &params);
Johannes Berg88600202012-02-13 15:17:18 +01003364 if (err)
3365 return err;
3366
Simon Wunderlichc56589e2013-11-21 18:19:49 +01003367 wdev_lock(wdev);
3368 err = rdev_change_beacon(rdev, dev, &params);
3369 wdev_unlock(wdev);
3370
3371 return err;
Johannes Berg88600202012-02-13 15:17:18 +01003372}
3373
3374static int nl80211_stop_ap(struct sk_buff *skb, struct genl_info *info)
Johannes Berged1b6cc2007-12-19 02:03:32 +01003375{
Johannes Berg4c476992010-10-04 21:36:35 +02003376 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3377 struct net_device *dev = info->user_ptr[1];
Johannes Berged1b6cc2007-12-19 02:03:32 +01003378
Ilan Peer7c8d5e02014-02-25 15:33:38 +02003379 return cfg80211_stop_ap(rdev, dev, false);
Johannes Berged1b6cc2007-12-19 02:03:32 +01003380}
3381
Johannes Berg5727ef12007-12-19 02:03:34 +01003382static const struct nla_policy sta_flags_policy[NL80211_STA_FLAG_MAX + 1] = {
3383 [NL80211_STA_FLAG_AUTHORIZED] = { .type = NLA_FLAG },
3384 [NL80211_STA_FLAG_SHORT_PREAMBLE] = { .type = NLA_FLAG },
3385 [NL80211_STA_FLAG_WME] = { .type = NLA_FLAG },
Jouni Malinen0e467242009-05-11 21:57:55 +03003386 [NL80211_STA_FLAG_MFP] = { .type = NLA_FLAG },
Javier Cardonab39c48f2011-04-07 15:08:30 -07003387 [NL80211_STA_FLAG_AUTHENTICATED] = { .type = NLA_FLAG },
Johannes Bergd83023d2011-12-14 09:29:15 +01003388 [NL80211_STA_FLAG_TDLS_PEER] = { .type = NLA_FLAG },
Johannes Berg5727ef12007-12-19 02:03:34 +01003389};
3390
Johannes Bergeccb8e82009-05-11 21:57:56 +03003391static int parse_station_flags(struct genl_info *info,
Johannes Bergbdd3ae32012-01-02 13:30:03 +01003392 enum nl80211_iftype iftype,
Johannes Bergeccb8e82009-05-11 21:57:56 +03003393 struct station_parameters *params)
Johannes Berg5727ef12007-12-19 02:03:34 +01003394{
3395 struct nlattr *flags[NL80211_STA_FLAG_MAX + 1];
Johannes Bergeccb8e82009-05-11 21:57:56 +03003396 struct nlattr *nla;
Johannes Berg5727ef12007-12-19 02:03:34 +01003397 int flag;
3398
Johannes Bergeccb8e82009-05-11 21:57:56 +03003399 /*
3400 * Try parsing the new attribute first so userspace
3401 * can specify both for older kernels.
3402 */
3403 nla = info->attrs[NL80211_ATTR_STA_FLAGS2];
3404 if (nla) {
3405 struct nl80211_sta_flag_update *sta_flags;
Johannes Berg5727ef12007-12-19 02:03:34 +01003406
Johannes Bergeccb8e82009-05-11 21:57:56 +03003407 sta_flags = nla_data(nla);
3408 params->sta_flags_mask = sta_flags->mask;
3409 params->sta_flags_set = sta_flags->set;
Johannes Berg77ee7c82013-02-15 00:48:33 +01003410 params->sta_flags_set &= params->sta_flags_mask;
Johannes Bergeccb8e82009-05-11 21:57:56 +03003411 if ((params->sta_flags_mask |
3412 params->sta_flags_set) & BIT(__NL80211_STA_FLAG_INVALID))
3413 return -EINVAL;
3414 return 0;
3415 }
3416
3417 /* if present, parse the old attribute */
3418
3419 nla = info->attrs[NL80211_ATTR_STA_FLAGS];
Johannes Berg5727ef12007-12-19 02:03:34 +01003420 if (!nla)
3421 return 0;
3422
3423 if (nla_parse_nested(flags, NL80211_STA_FLAG_MAX,
3424 nla, sta_flags_policy))
3425 return -EINVAL;
3426
Johannes Bergbdd3ae32012-01-02 13:30:03 +01003427 /*
3428 * Only allow certain flags for interface types so that
3429 * other attributes are silently ignored. Remember that
3430 * this is backward compatibility code with old userspace
3431 * and shouldn't be hit in other cases anyway.
3432 */
3433 switch (iftype) {
3434 case NL80211_IFTYPE_AP:
3435 case NL80211_IFTYPE_AP_VLAN:
3436 case NL80211_IFTYPE_P2P_GO:
3437 params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) |
3438 BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) |
3439 BIT(NL80211_STA_FLAG_WME) |
3440 BIT(NL80211_STA_FLAG_MFP);
3441 break;
3442 case NL80211_IFTYPE_P2P_CLIENT:
3443 case NL80211_IFTYPE_STATION:
3444 params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) |
3445 BIT(NL80211_STA_FLAG_TDLS_PEER);
3446 break;
3447 case NL80211_IFTYPE_MESH_POINT:
3448 params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHENTICATED) |
3449 BIT(NL80211_STA_FLAG_MFP) |
3450 BIT(NL80211_STA_FLAG_AUTHORIZED);
3451 default:
3452 return -EINVAL;
3453 }
Johannes Berg5727ef12007-12-19 02:03:34 +01003454
Johannes Berg3383b5a2012-05-10 20:14:43 +02003455 for (flag = 1; flag <= NL80211_STA_FLAG_MAX; flag++) {
3456 if (flags[flag]) {
Johannes Bergeccb8e82009-05-11 21:57:56 +03003457 params->sta_flags_set |= (1<<flag);
Johannes Berg5727ef12007-12-19 02:03:34 +01003458
Johannes Berg3383b5a2012-05-10 20:14:43 +02003459 /* no longer support new API additions in old API */
3460 if (flag > NL80211_STA_FLAG_MAX_OLD_API)
3461 return -EINVAL;
3462 }
3463 }
3464
Johannes Berg5727ef12007-12-19 02:03:34 +01003465 return 0;
3466}
3467
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003468static bool nl80211_put_sta_rate(struct sk_buff *msg, struct rate_info *info,
3469 int attr)
3470{
3471 struct nlattr *rate;
Vladimir Kondratiev8eb41c82012-07-05 14:25:49 +03003472 u32 bitrate;
3473 u16 bitrate_compat;
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003474
3475 rate = nla_nest_start(msg, attr);
3476 if (!rate)
Johannes Bergdb9c64c2012-11-09 14:56:41 +01003477 return false;
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003478
3479 /* cfg80211_calculate_bitrate will return 0 for mcs >= 32 */
3480 bitrate = cfg80211_calculate_bitrate(info);
Vladimir Kondratiev8eb41c82012-07-05 14:25:49 +03003481 /* report 16-bit bitrate only if we can */
3482 bitrate_compat = bitrate < (1UL << 16) ? bitrate : 0;
Johannes Bergdb9c64c2012-11-09 14:56:41 +01003483 if (bitrate > 0 &&
3484 nla_put_u32(msg, NL80211_RATE_INFO_BITRATE32, bitrate))
3485 return false;
3486 if (bitrate_compat > 0 &&
3487 nla_put_u16(msg, NL80211_RATE_INFO_BITRATE, bitrate_compat))
3488 return false;
3489
3490 if (info->flags & RATE_INFO_FLAGS_MCS) {
3491 if (nla_put_u8(msg, NL80211_RATE_INFO_MCS, info->mcs))
3492 return false;
3493 if (info->flags & RATE_INFO_FLAGS_40_MHZ_WIDTH &&
3494 nla_put_flag(msg, NL80211_RATE_INFO_40_MHZ_WIDTH))
3495 return false;
3496 if (info->flags & RATE_INFO_FLAGS_SHORT_GI &&
3497 nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI))
3498 return false;
3499 } else if (info->flags & RATE_INFO_FLAGS_VHT_MCS) {
3500 if (nla_put_u8(msg, NL80211_RATE_INFO_VHT_MCS, info->mcs))
3501 return false;
3502 if (nla_put_u8(msg, NL80211_RATE_INFO_VHT_NSS, info->nss))
3503 return false;
3504 if (info->flags & RATE_INFO_FLAGS_40_MHZ_WIDTH &&
3505 nla_put_flag(msg, NL80211_RATE_INFO_40_MHZ_WIDTH))
3506 return false;
3507 if (info->flags & RATE_INFO_FLAGS_80_MHZ_WIDTH &&
3508 nla_put_flag(msg, NL80211_RATE_INFO_80_MHZ_WIDTH))
3509 return false;
3510 if (info->flags & RATE_INFO_FLAGS_80P80_MHZ_WIDTH &&
3511 nla_put_flag(msg, NL80211_RATE_INFO_80P80_MHZ_WIDTH))
3512 return false;
3513 if (info->flags & RATE_INFO_FLAGS_160_MHZ_WIDTH &&
3514 nla_put_flag(msg, NL80211_RATE_INFO_160_MHZ_WIDTH))
3515 return false;
3516 if (info->flags & RATE_INFO_FLAGS_SHORT_GI &&
3517 nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI))
3518 return false;
3519 }
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003520
3521 nla_nest_end(msg, rate);
3522 return true;
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003523}
3524
Felix Fietkau119363c2013-04-22 16:29:30 +02003525static bool nl80211_put_signal(struct sk_buff *msg, u8 mask, s8 *signal,
3526 int id)
3527{
3528 void *attr;
3529 int i = 0;
3530
3531 if (!mask)
3532 return true;
3533
3534 attr = nla_nest_start(msg, id);
3535 if (!attr)
3536 return false;
3537
3538 for (i = 0; i < IEEE80211_MAX_CHAINS; i++) {
3539 if (!(mask & BIT(i)))
3540 continue;
3541
3542 if (nla_put_u8(msg, i, signal[i]))
3543 return false;
3544 }
3545
3546 nla_nest_end(msg, attr);
3547
3548 return true;
3549}
3550
Eric W. Biederman15e47302012-09-07 20:12:54 +00003551static int nl80211_send_station(struct sk_buff *msg, u32 portid, u32 seq,
John W. Linville66266b32012-03-15 13:25:41 -04003552 int flags,
3553 struct cfg80211_registered_device *rdev,
3554 struct net_device *dev,
Johannes Berg98b62182009-12-23 13:15:44 +01003555 const u8 *mac_addr, struct station_info *sinfo)
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003556{
3557 void *hdr;
Paul Stewartf4263c92011-03-31 09:25:41 -07003558 struct nlattr *sinfoattr, *bss_param;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003559
Eric W. Biederman15e47302012-09-07 20:12:54 +00003560 hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_STATION);
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003561 if (!hdr)
3562 return -1;
3563
David S. Miller9360ffd2012-03-29 04:41:26 -04003564 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
3565 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) ||
3566 nla_put_u32(msg, NL80211_ATTR_GENERATION, sinfo->generation))
3567 goto nla_put_failure;
Johannes Bergf5ea9122009-08-07 16:17:38 +02003568
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003569 sinfoattr = nla_nest_start(msg, NL80211_ATTR_STA_INFO);
3570 if (!sinfoattr)
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003571 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04003572 if ((sinfo->filled & STATION_INFO_CONNECTED_TIME) &&
3573 nla_put_u32(msg, NL80211_STA_INFO_CONNECTED_TIME,
3574 sinfo->connected_time))
3575 goto nla_put_failure;
3576 if ((sinfo->filled & STATION_INFO_INACTIVE_TIME) &&
3577 nla_put_u32(msg, NL80211_STA_INFO_INACTIVE_TIME,
3578 sinfo->inactive_time))
3579 goto nla_put_failure;
Vladimir Kondratiev42745e02013-02-04 13:53:11 +02003580 if ((sinfo->filled & (STATION_INFO_RX_BYTES |
3581 STATION_INFO_RX_BYTES64)) &&
David S. Miller9360ffd2012-03-29 04:41:26 -04003582 nla_put_u32(msg, NL80211_STA_INFO_RX_BYTES,
Vladimir Kondratiev42745e02013-02-04 13:53:11 +02003583 (u32)sinfo->rx_bytes))
3584 goto nla_put_failure;
3585 if ((sinfo->filled & (STATION_INFO_TX_BYTES |
Felix Fietkau4325d722013-05-23 15:05:59 +02003586 STATION_INFO_TX_BYTES64)) &&
Vladimir Kondratiev42745e02013-02-04 13:53:11 +02003587 nla_put_u32(msg, NL80211_STA_INFO_TX_BYTES,
3588 (u32)sinfo->tx_bytes))
3589 goto nla_put_failure;
3590 if ((sinfo->filled & STATION_INFO_RX_BYTES64) &&
3591 nla_put_u64(msg, NL80211_STA_INFO_RX_BYTES64,
David S. Miller9360ffd2012-03-29 04:41:26 -04003592 sinfo->rx_bytes))
3593 goto nla_put_failure;
Vladimir Kondratiev42745e02013-02-04 13:53:11 +02003594 if ((sinfo->filled & STATION_INFO_TX_BYTES64) &&
3595 nla_put_u64(msg, NL80211_STA_INFO_TX_BYTES64,
David S. Miller9360ffd2012-03-29 04:41:26 -04003596 sinfo->tx_bytes))
3597 goto nla_put_failure;
3598 if ((sinfo->filled & STATION_INFO_LLID) &&
3599 nla_put_u16(msg, NL80211_STA_INFO_LLID, sinfo->llid))
3600 goto nla_put_failure;
3601 if ((sinfo->filled & STATION_INFO_PLID) &&
3602 nla_put_u16(msg, NL80211_STA_INFO_PLID, sinfo->plid))
3603 goto nla_put_failure;
3604 if ((sinfo->filled & STATION_INFO_PLINK_STATE) &&
3605 nla_put_u8(msg, NL80211_STA_INFO_PLINK_STATE,
3606 sinfo->plink_state))
3607 goto nla_put_failure;
John W. Linville66266b32012-03-15 13:25:41 -04003608 switch (rdev->wiphy.signal_type) {
3609 case CFG80211_SIGNAL_TYPE_MBM:
David S. Miller9360ffd2012-03-29 04:41:26 -04003610 if ((sinfo->filled & STATION_INFO_SIGNAL) &&
3611 nla_put_u8(msg, NL80211_STA_INFO_SIGNAL,
3612 sinfo->signal))
3613 goto nla_put_failure;
3614 if ((sinfo->filled & STATION_INFO_SIGNAL_AVG) &&
3615 nla_put_u8(msg, NL80211_STA_INFO_SIGNAL_AVG,
3616 sinfo->signal_avg))
3617 goto nla_put_failure;
John W. Linville66266b32012-03-15 13:25:41 -04003618 break;
3619 default:
3620 break;
3621 }
Felix Fietkau119363c2013-04-22 16:29:30 +02003622 if (sinfo->filled & STATION_INFO_CHAIN_SIGNAL) {
3623 if (!nl80211_put_signal(msg, sinfo->chains,
3624 sinfo->chain_signal,
3625 NL80211_STA_INFO_CHAIN_SIGNAL))
3626 goto nla_put_failure;
3627 }
3628 if (sinfo->filled & STATION_INFO_CHAIN_SIGNAL_AVG) {
3629 if (!nl80211_put_signal(msg, sinfo->chains,
3630 sinfo->chain_signal_avg,
3631 NL80211_STA_INFO_CHAIN_SIGNAL_AVG))
3632 goto nla_put_failure;
3633 }
Henning Rogge420e7fa2008-12-11 22:04:19 +01003634 if (sinfo->filled & STATION_INFO_TX_BITRATE) {
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003635 if (!nl80211_put_sta_rate(msg, &sinfo->txrate,
3636 NL80211_STA_INFO_TX_BITRATE))
Henning Rogge420e7fa2008-12-11 22:04:19 +01003637 goto nla_put_failure;
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003638 }
3639 if (sinfo->filled & STATION_INFO_RX_BITRATE) {
3640 if (!nl80211_put_sta_rate(msg, &sinfo->rxrate,
3641 NL80211_STA_INFO_RX_BITRATE))
3642 goto nla_put_failure;
Henning Rogge420e7fa2008-12-11 22:04:19 +01003643 }
David S. Miller9360ffd2012-03-29 04:41:26 -04003644 if ((sinfo->filled & STATION_INFO_RX_PACKETS) &&
3645 nla_put_u32(msg, NL80211_STA_INFO_RX_PACKETS,
3646 sinfo->rx_packets))
3647 goto nla_put_failure;
3648 if ((sinfo->filled & STATION_INFO_TX_PACKETS) &&
3649 nla_put_u32(msg, NL80211_STA_INFO_TX_PACKETS,
3650 sinfo->tx_packets))
3651 goto nla_put_failure;
3652 if ((sinfo->filled & STATION_INFO_TX_RETRIES) &&
3653 nla_put_u32(msg, NL80211_STA_INFO_TX_RETRIES,
3654 sinfo->tx_retries))
3655 goto nla_put_failure;
3656 if ((sinfo->filled & STATION_INFO_TX_FAILED) &&
3657 nla_put_u32(msg, NL80211_STA_INFO_TX_FAILED,
3658 sinfo->tx_failed))
3659 goto nla_put_failure;
Antonio Quartulli867d8492014-05-19 21:53:19 +02003660 if ((sinfo->filled & STATION_INFO_EXPECTED_THROUGHPUT) &&
3661 nla_put_u32(msg, NL80211_STA_INFO_EXPECTED_THROUGHPUT,
3662 sinfo->expected_throughput))
3663 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04003664 if ((sinfo->filled & STATION_INFO_BEACON_LOSS_COUNT) &&
3665 nla_put_u32(msg, NL80211_STA_INFO_BEACON_LOSS,
3666 sinfo->beacon_loss_count))
3667 goto nla_put_failure;
Marco Porsch3b1c5a52013-01-07 16:04:52 +01003668 if ((sinfo->filled & STATION_INFO_LOCAL_PM) &&
3669 nla_put_u32(msg, NL80211_STA_INFO_LOCAL_PM,
3670 sinfo->local_pm))
3671 goto nla_put_failure;
3672 if ((sinfo->filled & STATION_INFO_PEER_PM) &&
3673 nla_put_u32(msg, NL80211_STA_INFO_PEER_PM,
3674 sinfo->peer_pm))
3675 goto nla_put_failure;
3676 if ((sinfo->filled & STATION_INFO_NONPEER_PM) &&
3677 nla_put_u32(msg, NL80211_STA_INFO_NONPEER_PM,
3678 sinfo->nonpeer_pm))
3679 goto nla_put_failure;
Paul Stewartf4263c92011-03-31 09:25:41 -07003680 if (sinfo->filled & STATION_INFO_BSS_PARAM) {
3681 bss_param = nla_nest_start(msg, NL80211_STA_INFO_BSS_PARAM);
3682 if (!bss_param)
3683 goto nla_put_failure;
3684
David S. Miller9360ffd2012-03-29 04:41:26 -04003685 if (((sinfo->bss_param.flags & BSS_PARAM_FLAGS_CTS_PROT) &&
3686 nla_put_flag(msg, NL80211_STA_BSS_PARAM_CTS_PROT)) ||
3687 ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_PREAMBLE) &&
3688 nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_PREAMBLE)) ||
3689 ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_SLOT_TIME) &&
3690 nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_SLOT_TIME)) ||
3691 nla_put_u8(msg, NL80211_STA_BSS_PARAM_DTIM_PERIOD,
3692 sinfo->bss_param.dtim_period) ||
3693 nla_put_u16(msg, NL80211_STA_BSS_PARAM_BEACON_INTERVAL,
3694 sinfo->bss_param.beacon_interval))
3695 goto nla_put_failure;
Paul Stewartf4263c92011-03-31 09:25:41 -07003696
3697 nla_nest_end(msg, bss_param);
3698 }
David S. Miller9360ffd2012-03-29 04:41:26 -04003699 if ((sinfo->filled & STATION_INFO_STA_FLAGS) &&
3700 nla_put(msg, NL80211_STA_INFO_STA_FLAGS,
3701 sizeof(struct nl80211_sta_flag_update),
3702 &sinfo->sta_flags))
3703 goto nla_put_failure;
John W. Linville7eab0f62012-04-12 14:25:14 -04003704 if ((sinfo->filled & STATION_INFO_T_OFFSET) &&
3705 nla_put_u64(msg, NL80211_STA_INFO_T_OFFSET,
3706 sinfo->t_offset))
3707 goto nla_put_failure;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003708 nla_nest_end(msg, sinfoattr);
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003709
David S. Miller9360ffd2012-03-29 04:41:26 -04003710 if ((sinfo->filled & STATION_INFO_ASSOC_REQ_IES) &&
3711 nla_put(msg, NL80211_ATTR_IE, sinfo->assoc_req_ies_len,
3712 sinfo->assoc_req_ies))
3713 goto nla_put_failure;
Jouni Malinen50d3dfb2011-08-08 12:11:52 +03003714
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003715 return genlmsg_end(msg, hdr);
3716
3717 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07003718 genlmsg_cancel(msg, hdr);
3719 return -EMSGSIZE;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003720}
3721
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003722static int nl80211_dump_station(struct sk_buff *skb,
Johannes Bergbba95fe2008-07-29 13:22:51 +02003723 struct netlink_callback *cb)
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003724{
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003725 struct station_info sinfo;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08003726 struct cfg80211_registered_device *rdev;
Johannes Berg97990a02013-04-19 01:02:55 +02003727 struct wireless_dev *wdev;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003728 u8 mac_addr[ETH_ALEN];
Johannes Berg97990a02013-04-19 01:02:55 +02003729 int sta_idx = cb->args[2];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003730 int err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003731
Zhao, Gang1b8ec872014-04-21 12:53:02 +08003732 err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev);
Johannes Berg67748892010-10-04 21:14:06 +02003733 if (err)
3734 return err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02003735
Johannes Berg97990a02013-04-19 01:02:55 +02003736 if (!wdev->netdev) {
3737 err = -EINVAL;
3738 goto out_err;
3739 }
3740
Zhao, Gang1b8ec872014-04-21 12:53:02 +08003741 if (!rdev->ops->dump_station) {
Jouni Malineneec60b02009-03-20 21:21:19 +02003742 err = -EOPNOTSUPP;
Johannes Bergbba95fe2008-07-29 13:22:51 +02003743 goto out_err;
3744 }
3745
Johannes Bergbba95fe2008-07-29 13:22:51 +02003746 while (1) {
Jouni Malinenf612ced2011-08-11 11:46:22 +03003747 memset(&sinfo, 0, sizeof(sinfo));
Zhao, Gang1b8ec872014-04-21 12:53:02 +08003748 err = rdev_dump_station(rdev, wdev->netdev, sta_idx,
Hila Gonene35e4d22012-06-27 17:19:42 +03003749 mac_addr, &sinfo);
Johannes Bergbba95fe2008-07-29 13:22:51 +02003750 if (err == -ENOENT)
3751 break;
3752 if (err)
Johannes Berg3b858752009-03-12 09:55:09 +01003753 goto out_err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02003754
3755 if (nl80211_send_station(skb,
Eric W. Biederman15e47302012-09-07 20:12:54 +00003756 NETLINK_CB(cb->skb).portid,
Johannes Bergbba95fe2008-07-29 13:22:51 +02003757 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08003758 rdev, wdev->netdev, mac_addr,
Johannes Bergbba95fe2008-07-29 13:22:51 +02003759 &sinfo) < 0)
3760 goto out;
3761
3762 sta_idx++;
3763 }
3764
3765
3766 out:
Johannes Berg97990a02013-04-19 01:02:55 +02003767 cb->args[2] = sta_idx;
Johannes Bergbba95fe2008-07-29 13:22:51 +02003768 err = skb->len;
Johannes Bergbba95fe2008-07-29 13:22:51 +02003769 out_err:
Zhao, Gang1b8ec872014-04-21 12:53:02 +08003770 nl80211_finish_wdev_dump(rdev);
Johannes Bergbba95fe2008-07-29 13:22:51 +02003771
3772 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003773}
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003774
Johannes Berg5727ef12007-12-19 02:03:34 +01003775static int nl80211_get_station(struct sk_buff *skb, struct genl_info *info)
3776{
Johannes Berg4c476992010-10-04 21:36:35 +02003777 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3778 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003779 struct station_info sinfo;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003780 struct sk_buff *msg;
3781 u8 *mac_addr = NULL;
Johannes Berg4c476992010-10-04 21:36:35 +02003782 int err;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003783
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003784 memset(&sinfo, 0, sizeof(sinfo));
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003785
3786 if (!info->attrs[NL80211_ATTR_MAC])
3787 return -EINVAL;
3788
3789 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
3790
Johannes Berg4c476992010-10-04 21:36:35 +02003791 if (!rdev->ops->get_station)
3792 return -EOPNOTSUPP;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003793
Hila Gonene35e4d22012-06-27 17:19:42 +03003794 err = rdev_get_station(rdev, dev, mac_addr, &sinfo);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003795 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02003796 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003797
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07003798 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003799 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02003800 return -ENOMEM;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003801
Eric W. Biederman15e47302012-09-07 20:12:54 +00003802 if (nl80211_send_station(msg, info->snd_portid, info->snd_seq, 0,
John W. Linville66266b32012-03-15 13:25:41 -04003803 rdev, dev, mac_addr, &sinfo) < 0) {
Johannes Berg4c476992010-10-04 21:36:35 +02003804 nlmsg_free(msg);
3805 return -ENOBUFS;
3806 }
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003807
Johannes Berg4c476992010-10-04 21:36:35 +02003808 return genlmsg_reply(msg, info);
Johannes Berg5727ef12007-12-19 02:03:34 +01003809}
3810
Johannes Berg77ee7c82013-02-15 00:48:33 +01003811int cfg80211_check_station_change(struct wiphy *wiphy,
3812 struct station_parameters *params,
3813 enum cfg80211_station_type statype)
3814{
3815 if (params->listen_interval != -1)
3816 return -EINVAL;
3817 if (params->aid)
3818 return -EINVAL;
3819
3820 /* When you run into this, adjust the code below for the new flag */
3821 BUILD_BUG_ON(NL80211_STA_FLAG_MAX != 7);
3822
3823 switch (statype) {
Thomas Pederseneef941e2013-03-04 13:06:11 -08003824 case CFG80211_STA_MESH_PEER_KERNEL:
3825 case CFG80211_STA_MESH_PEER_USER:
Johannes Berg77ee7c82013-02-15 00:48:33 +01003826 /*
3827 * No ignoring the TDLS flag here -- the userspace mesh
3828 * code doesn't have the bug of including TDLS in the
3829 * mask everywhere.
3830 */
3831 if (params->sta_flags_mask &
3832 ~(BIT(NL80211_STA_FLAG_AUTHENTICATED) |
3833 BIT(NL80211_STA_FLAG_MFP) |
3834 BIT(NL80211_STA_FLAG_AUTHORIZED)))
3835 return -EINVAL;
3836 break;
3837 case CFG80211_STA_TDLS_PEER_SETUP:
3838 case CFG80211_STA_TDLS_PEER_ACTIVE:
3839 if (!(params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)))
3840 return -EINVAL;
3841 /* ignore since it can't change */
3842 params->sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER);
3843 break;
3844 default:
3845 /* disallow mesh-specific things */
3846 if (params->plink_action != NL80211_PLINK_ACTION_NO_ACTION)
3847 return -EINVAL;
3848 if (params->local_pm)
3849 return -EINVAL;
3850 if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE)
3851 return -EINVAL;
3852 }
3853
3854 if (statype != CFG80211_STA_TDLS_PEER_SETUP &&
3855 statype != CFG80211_STA_TDLS_PEER_ACTIVE) {
3856 /* TDLS can't be set, ... */
3857 if (params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))
3858 return -EINVAL;
3859 /*
3860 * ... but don't bother the driver with it. This works around
3861 * a hostapd/wpa_supplicant issue -- it always includes the
3862 * TLDS_PEER flag in the mask even for AP mode.
3863 */
3864 params->sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER);
3865 }
3866
3867 if (statype != CFG80211_STA_TDLS_PEER_SETUP) {
3868 /* reject other things that can't change */
3869 if (params->sta_modify_mask & STATION_PARAM_APPLY_UAPSD)
3870 return -EINVAL;
3871 if (params->sta_modify_mask & STATION_PARAM_APPLY_CAPABILITY)
3872 return -EINVAL;
3873 if (params->supported_rates)
3874 return -EINVAL;
3875 if (params->ext_capab || params->ht_capa || params->vht_capa)
3876 return -EINVAL;
3877 }
3878
3879 if (statype != CFG80211_STA_AP_CLIENT) {
3880 if (params->vlan)
3881 return -EINVAL;
3882 }
3883
3884 switch (statype) {
3885 case CFG80211_STA_AP_MLME_CLIENT:
3886 /* Use this only for authorizing/unauthorizing a station */
3887 if (!(params->sta_flags_mask & BIT(NL80211_STA_FLAG_AUTHORIZED)))
3888 return -EOPNOTSUPP;
3889 break;
3890 case CFG80211_STA_AP_CLIENT:
3891 /* accept only the listed bits */
3892 if (params->sta_flags_mask &
3893 ~(BIT(NL80211_STA_FLAG_AUTHORIZED) |
3894 BIT(NL80211_STA_FLAG_AUTHENTICATED) |
3895 BIT(NL80211_STA_FLAG_ASSOCIATED) |
3896 BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) |
3897 BIT(NL80211_STA_FLAG_WME) |
3898 BIT(NL80211_STA_FLAG_MFP)))
3899 return -EINVAL;
3900
3901 /* but authenticated/associated only if driver handles it */
3902 if (!(wiphy->features & NL80211_FEATURE_FULL_AP_CLIENT_STATE) &&
3903 params->sta_flags_mask &
3904 (BIT(NL80211_STA_FLAG_AUTHENTICATED) |
3905 BIT(NL80211_STA_FLAG_ASSOCIATED)))
3906 return -EINVAL;
3907 break;
3908 case CFG80211_STA_IBSS:
3909 case CFG80211_STA_AP_STA:
3910 /* reject any changes other than AUTHORIZED */
3911 if (params->sta_flags_mask & ~BIT(NL80211_STA_FLAG_AUTHORIZED))
3912 return -EINVAL;
3913 break;
3914 case CFG80211_STA_TDLS_PEER_SETUP:
3915 /* reject any changes other than AUTHORIZED or WME */
3916 if (params->sta_flags_mask & ~(BIT(NL80211_STA_FLAG_AUTHORIZED) |
3917 BIT(NL80211_STA_FLAG_WME)))
3918 return -EINVAL;
3919 /* force (at least) rates when authorizing */
3920 if (params->sta_flags_set & BIT(NL80211_STA_FLAG_AUTHORIZED) &&
3921 !params->supported_rates)
3922 return -EINVAL;
3923 break;
3924 case CFG80211_STA_TDLS_PEER_ACTIVE:
3925 /* reject any changes */
3926 return -EINVAL;
Thomas Pederseneef941e2013-03-04 13:06:11 -08003927 case CFG80211_STA_MESH_PEER_KERNEL:
Johannes Berg77ee7c82013-02-15 00:48:33 +01003928 if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE)
3929 return -EINVAL;
3930 break;
Thomas Pederseneef941e2013-03-04 13:06:11 -08003931 case CFG80211_STA_MESH_PEER_USER:
Johannes Berg77ee7c82013-02-15 00:48:33 +01003932 if (params->plink_action != NL80211_PLINK_ACTION_NO_ACTION)
3933 return -EINVAL;
3934 break;
3935 }
3936
3937 return 0;
3938}
3939EXPORT_SYMBOL(cfg80211_check_station_change);
3940
Johannes Berg5727ef12007-12-19 02:03:34 +01003941/*
Felix Fietkauc258d2d2009-11-11 17:23:31 +01003942 * Get vlan interface making sure it is running and on the right wiphy.
Johannes Berg5727ef12007-12-19 02:03:34 +01003943 */
Johannes Berg80b99892011-11-18 16:23:01 +01003944static struct net_device *get_vlan(struct genl_info *info,
3945 struct cfg80211_registered_device *rdev)
Johannes Berg5727ef12007-12-19 02:03:34 +01003946{
Johannes Berg463d0182009-07-14 00:33:35 +02003947 struct nlattr *vlanattr = info->attrs[NL80211_ATTR_STA_VLAN];
Johannes Berg80b99892011-11-18 16:23:01 +01003948 struct net_device *v;
3949 int ret;
Johannes Berg5727ef12007-12-19 02:03:34 +01003950
Johannes Berg80b99892011-11-18 16:23:01 +01003951 if (!vlanattr)
3952 return NULL;
3953
3954 v = dev_get_by_index(genl_info_net(info), nla_get_u32(vlanattr));
3955 if (!v)
3956 return ERR_PTR(-ENODEV);
3957
3958 if (!v->ieee80211_ptr || v->ieee80211_ptr->wiphy != &rdev->wiphy) {
3959 ret = -EINVAL;
3960 goto error;
Johannes Berg5727ef12007-12-19 02:03:34 +01003961 }
Johannes Berg80b99892011-11-18 16:23:01 +01003962
Johannes Berg77ee7c82013-02-15 00:48:33 +01003963 if (v->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN &&
3964 v->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
3965 v->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) {
3966 ret = -EINVAL;
3967 goto error;
3968 }
3969
Johannes Berg80b99892011-11-18 16:23:01 +01003970 if (!netif_running(v)) {
3971 ret = -ENETDOWN;
3972 goto error;
3973 }
3974
3975 return v;
3976 error:
3977 dev_put(v);
3978 return ERR_PTR(ret);
Johannes Berg5727ef12007-12-19 02:03:34 +01003979}
3980
Johannes Berg94e860f2014-01-20 23:58:15 +01003981static const struct nla_policy
3982nl80211_sta_wme_policy[NL80211_STA_WME_MAX + 1] = {
Jouni Malinendf881292013-02-14 21:10:54 +02003983 [NL80211_STA_WME_UAPSD_QUEUES] = { .type = NLA_U8 },
3984 [NL80211_STA_WME_MAX_SP] = { .type = NLA_U8 },
3985};
3986
Johannes Bergff276692013-02-15 00:09:01 +01003987static int nl80211_parse_sta_wme(struct genl_info *info,
3988 struct station_parameters *params)
Jouni Malinendf881292013-02-14 21:10:54 +02003989{
Jouni Malinendf881292013-02-14 21:10:54 +02003990 struct nlattr *tb[NL80211_STA_WME_MAX + 1];
3991 struct nlattr *nla;
3992 int err;
3993
Jouni Malinendf881292013-02-14 21:10:54 +02003994 /* parse WME attributes if present */
3995 if (!info->attrs[NL80211_ATTR_STA_WME])
3996 return 0;
3997
3998 nla = info->attrs[NL80211_ATTR_STA_WME];
3999 err = nla_parse_nested(tb, NL80211_STA_WME_MAX, nla,
4000 nl80211_sta_wme_policy);
4001 if (err)
4002 return err;
4003
4004 if (tb[NL80211_STA_WME_UAPSD_QUEUES])
4005 params->uapsd_queues = nla_get_u8(
4006 tb[NL80211_STA_WME_UAPSD_QUEUES]);
4007 if (params->uapsd_queues & ~IEEE80211_WMM_IE_STA_QOSINFO_AC_MASK)
4008 return -EINVAL;
4009
4010 if (tb[NL80211_STA_WME_MAX_SP])
4011 params->max_sp = nla_get_u8(tb[NL80211_STA_WME_MAX_SP]);
4012
4013 if (params->max_sp & ~IEEE80211_WMM_IE_STA_QOSINFO_SP_MASK)
4014 return -EINVAL;
4015
4016 params->sta_modify_mask |= STATION_PARAM_APPLY_UAPSD;
4017
4018 return 0;
4019}
4020
Sunil Duttc01fc9a2013-10-09 20:45:21 +05304021static int nl80211_parse_sta_channel_info(struct genl_info *info,
4022 struct station_parameters *params)
4023{
4024 if (info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]) {
4025 params->supported_channels =
4026 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]);
4027 params->supported_channels_len =
4028 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]);
4029 /*
4030 * Need to include at least one (first channel, number of
4031 * channels) tuple for each subband, and must have proper
4032 * tuples for the rest of the data as well.
4033 */
4034 if (params->supported_channels_len < 2)
4035 return -EINVAL;
4036 if (params->supported_channels_len % 2)
4037 return -EINVAL;
4038 }
4039
4040 if (info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]) {
4041 params->supported_oper_classes =
4042 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]);
4043 params->supported_oper_classes_len =
4044 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]);
4045 /*
4046 * The value of the Length field of the Supported Operating
4047 * Classes element is between 2 and 253.
4048 */
4049 if (params->supported_oper_classes_len < 2 ||
4050 params->supported_oper_classes_len > 253)
4051 return -EINVAL;
4052 }
4053 return 0;
4054}
4055
Johannes Bergff276692013-02-15 00:09:01 +01004056static int nl80211_set_station_tdls(struct genl_info *info,
4057 struct station_parameters *params)
4058{
Sunil Duttc01fc9a2013-10-09 20:45:21 +05304059 int err;
Johannes Bergff276692013-02-15 00:09:01 +01004060 /* Dummy STA entry gets updated once the peer capabilities are known */
Jouni Malinen5e4b6f52013-05-16 20:11:08 +03004061 if (info->attrs[NL80211_ATTR_PEER_AID])
4062 params->aid = nla_get_u16(info->attrs[NL80211_ATTR_PEER_AID]);
Johannes Bergff276692013-02-15 00:09:01 +01004063 if (info->attrs[NL80211_ATTR_HT_CAPABILITY])
4064 params->ht_capa =
4065 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]);
4066 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY])
4067 params->vht_capa =
4068 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]);
4069
Sunil Duttc01fc9a2013-10-09 20:45:21 +05304070 err = nl80211_parse_sta_channel_info(info, params);
4071 if (err)
4072 return err;
4073
Johannes Bergff276692013-02-15 00:09:01 +01004074 return nl80211_parse_sta_wme(info, params);
4075}
4076
Johannes Berg5727ef12007-12-19 02:03:34 +01004077static int nl80211_set_station(struct sk_buff *skb, struct genl_info *info)
4078{
Johannes Berg4c476992010-10-04 21:36:35 +02004079 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg4c476992010-10-04 21:36:35 +02004080 struct net_device *dev = info->user_ptr[1];
Johannes Berg5727ef12007-12-19 02:03:34 +01004081 struct station_parameters params;
Johannes Berg77ee7c82013-02-15 00:48:33 +01004082 u8 *mac_addr;
4083 int err;
Johannes Berg5727ef12007-12-19 02:03:34 +01004084
4085 memset(&params, 0, sizeof(params));
4086
4087 params.listen_interval = -1;
4088
Johannes Berg77ee7c82013-02-15 00:48:33 +01004089 if (!rdev->ops->change_station)
4090 return -EOPNOTSUPP;
4091
Johannes Berg5727ef12007-12-19 02:03:34 +01004092 if (info->attrs[NL80211_ATTR_STA_AID])
4093 return -EINVAL;
4094
4095 if (!info->attrs[NL80211_ATTR_MAC])
4096 return -EINVAL;
4097
4098 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
4099
4100 if (info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) {
4101 params.supported_rates =
4102 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
4103 params.supported_rates_len =
4104 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
4105 }
4106
Jouni Malinen9d62a982013-02-14 21:10:13 +02004107 if (info->attrs[NL80211_ATTR_STA_CAPABILITY]) {
4108 params.capability =
4109 nla_get_u16(info->attrs[NL80211_ATTR_STA_CAPABILITY]);
4110 params.sta_modify_mask |= STATION_PARAM_APPLY_CAPABILITY;
4111 }
4112
4113 if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]) {
4114 params.ext_capab =
4115 nla_data(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
4116 params.ext_capab_len =
4117 nla_len(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
4118 }
4119
Jouni Malinendf881292013-02-14 21:10:54 +02004120 if (info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL])
Johannes Bergba23d202012-12-27 17:32:09 +01004121 return -EINVAL;
Jouni Malinen36aedc902008-08-25 11:58:58 +03004122
Johannes Bergbdd3ae32012-01-02 13:30:03 +01004123 if (parse_station_flags(info, dev->ieee80211_ptr->iftype, &params))
Johannes Berg5727ef12007-12-19 02:03:34 +01004124 return -EINVAL;
4125
Johannes Bergf8bacc22013-02-14 23:27:01 +01004126 if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) {
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004127 params.plink_action =
Johannes Bergf8bacc22013-02-14 23:27:01 +01004128 nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]);
4129 if (params.plink_action >= NUM_NL80211_PLINK_ACTIONS)
4130 return -EINVAL;
4131 }
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004132
Johannes Bergf8bacc22013-02-14 23:27:01 +01004133 if (info->attrs[NL80211_ATTR_STA_PLINK_STATE]) {
Javier Cardona9c3990a2011-05-03 16:57:11 -07004134 params.plink_state =
Johannes Bergf8bacc22013-02-14 23:27:01 +01004135 nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_STATE]);
4136 if (params.plink_state >= NUM_NL80211_PLINK_STATES)
4137 return -EINVAL;
4138 params.sta_modify_mask |= STATION_PARAM_APPLY_PLINK_STATE;
4139 }
Javier Cardona9c3990a2011-05-03 16:57:11 -07004140
Marco Porsch3b1c5a52013-01-07 16:04:52 +01004141 if (info->attrs[NL80211_ATTR_LOCAL_MESH_POWER_MODE]) {
4142 enum nl80211_mesh_power_mode pm = nla_get_u32(
4143 info->attrs[NL80211_ATTR_LOCAL_MESH_POWER_MODE]);
4144
4145 if (pm <= NL80211_MESH_POWER_UNKNOWN ||
4146 pm > NL80211_MESH_POWER_MAX)
4147 return -EINVAL;
4148
4149 params.local_pm = pm;
4150 }
4151
Johannes Berg77ee7c82013-02-15 00:48:33 +01004152 /* Include parameters for TDLS peer (will check later) */
4153 err = nl80211_set_station_tdls(info, &params);
4154 if (err)
4155 return err;
4156
4157 params.vlan = get_vlan(info, rdev);
4158 if (IS_ERR(params.vlan))
4159 return PTR_ERR(params.vlan);
4160
Johannes Berga97f4422009-06-18 17:23:43 +02004161 switch (dev->ieee80211_ptr->iftype) {
4162 case NL80211_IFTYPE_AP:
4163 case NL80211_IFTYPE_AP_VLAN:
Johannes Berg074ac8d2010-09-16 14:58:22 +02004164 case NL80211_IFTYPE_P2P_GO:
Johannes Berg074ac8d2010-09-16 14:58:22 +02004165 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Berga97f4422009-06-18 17:23:43 +02004166 case NL80211_IFTYPE_STATION:
Antonio Quartulli267335d2012-01-31 20:25:47 +01004167 case NL80211_IFTYPE_ADHOC:
Johannes Berga97f4422009-06-18 17:23:43 +02004168 case NL80211_IFTYPE_MESH_POINT:
Johannes Berga97f4422009-06-18 17:23:43 +02004169 break;
4170 default:
Johannes Berg77ee7c82013-02-15 00:48:33 +01004171 err = -EOPNOTSUPP;
4172 goto out_put_vlan;
Johannes Berg034d6552009-05-27 10:35:29 +02004173 }
4174
Johannes Berg77ee7c82013-02-15 00:48:33 +01004175 /* driver will call cfg80211_check_station_change() */
Hila Gonene35e4d22012-06-27 17:19:42 +03004176 err = rdev_change_station(rdev, dev, mac_addr, &params);
Johannes Berg5727ef12007-12-19 02:03:34 +01004177
Johannes Berg77ee7c82013-02-15 00:48:33 +01004178 out_put_vlan:
Johannes Berg5727ef12007-12-19 02:03:34 +01004179 if (params.vlan)
4180 dev_put(params.vlan);
Johannes Berg3b858752009-03-12 09:55:09 +01004181
Johannes Berg5727ef12007-12-19 02:03:34 +01004182 return err;
4183}
4184
4185static int nl80211_new_station(struct sk_buff *skb, struct genl_info *info)
4186{
Johannes Berg4c476992010-10-04 21:36:35 +02004187 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg5727ef12007-12-19 02:03:34 +01004188 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02004189 struct net_device *dev = info->user_ptr[1];
Johannes Berg5727ef12007-12-19 02:03:34 +01004190 struct station_parameters params;
4191 u8 *mac_addr = NULL;
4192
4193 memset(&params, 0, sizeof(params));
4194
Johannes Berg984c3112013-02-14 23:43:25 +01004195 if (!rdev->ops->add_station)
4196 return -EOPNOTSUPP;
4197
Johannes Berg5727ef12007-12-19 02:03:34 +01004198 if (!info->attrs[NL80211_ATTR_MAC])
4199 return -EINVAL;
4200
Johannes Berg5727ef12007-12-19 02:03:34 +01004201 if (!info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL])
4202 return -EINVAL;
4203
4204 if (!info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES])
4205 return -EINVAL;
4206
Jouni Malinen5e4b6f52013-05-16 20:11:08 +03004207 if (!info->attrs[NL80211_ATTR_STA_AID] &&
4208 !info->attrs[NL80211_ATTR_PEER_AID])
Thadeu Lima de Souza Cascardo0e956c12010-02-12 12:34:50 -02004209 return -EINVAL;
4210
Johannes Berg5727ef12007-12-19 02:03:34 +01004211 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
4212 params.supported_rates =
4213 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
4214 params.supported_rates_len =
4215 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
4216 params.listen_interval =
4217 nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]);
Johannes Berg51b50fb2009-05-24 16:42:30 +02004218
Jouni Malinen3d124ea2013-05-27 18:24:02 +03004219 if (info->attrs[NL80211_ATTR_PEER_AID])
Jouni Malinen5e4b6f52013-05-16 20:11:08 +03004220 params.aid = nla_get_u16(info->attrs[NL80211_ATTR_PEER_AID]);
Jouni Malinen3d124ea2013-05-27 18:24:02 +03004221 else
4222 params.aid = nla_get_u16(info->attrs[NL80211_ATTR_STA_AID]);
Thadeu Lima de Souza Cascardo0e956c12010-02-12 12:34:50 -02004223 if (!params.aid || params.aid > IEEE80211_MAX_AID)
4224 return -EINVAL;
Johannes Berg51b50fb2009-05-24 16:42:30 +02004225
Jouni Malinen9d62a982013-02-14 21:10:13 +02004226 if (info->attrs[NL80211_ATTR_STA_CAPABILITY]) {
4227 params.capability =
4228 nla_get_u16(info->attrs[NL80211_ATTR_STA_CAPABILITY]);
4229 params.sta_modify_mask |= STATION_PARAM_APPLY_CAPABILITY;
4230 }
4231
4232 if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]) {
4233 params.ext_capab =
4234 nla_data(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
4235 params.ext_capab_len =
4236 nla_len(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
4237 }
4238
Jouni Malinen36aedc902008-08-25 11:58:58 +03004239 if (info->attrs[NL80211_ATTR_HT_CAPABILITY])
4240 params.ht_capa =
4241 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]);
Johannes Berg5727ef12007-12-19 02:03:34 +01004242
Mahesh Palivelaf461be3e2012-10-11 08:04:52 +00004243 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY])
4244 params.vht_capa =
4245 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]);
4246
Marek Kwaczynski60f4a7b2013-12-03 10:04:59 +01004247 if (info->attrs[NL80211_ATTR_OPMODE_NOTIF]) {
4248 params.opmode_notif_used = true;
4249 params.opmode_notif =
4250 nla_get_u8(info->attrs[NL80211_ATTR_OPMODE_NOTIF]);
4251 }
4252
Johannes Bergf8bacc22013-02-14 23:27:01 +01004253 if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) {
Javier Cardona96b78df2011-04-07 15:08:33 -07004254 params.plink_action =
Johannes Bergf8bacc22013-02-14 23:27:01 +01004255 nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]);
4256 if (params.plink_action >= NUM_NL80211_PLINK_ACTIONS)
4257 return -EINVAL;
4258 }
Javier Cardona96b78df2011-04-07 15:08:33 -07004259
Sunil Duttc01fc9a2013-10-09 20:45:21 +05304260 err = nl80211_parse_sta_channel_info(info, &params);
4261 if (err)
4262 return err;
4263
Johannes Bergff276692013-02-15 00:09:01 +01004264 err = nl80211_parse_sta_wme(info, &params);
4265 if (err)
4266 return err;
Johannes Bergbdd90d52011-12-14 12:20:27 +01004267
Johannes Bergbdd3ae32012-01-02 13:30:03 +01004268 if (parse_station_flags(info, dev->ieee80211_ptr->iftype, &params))
Johannes Berg5727ef12007-12-19 02:03:34 +01004269 return -EINVAL;
4270
Johannes Berg77ee7c82013-02-15 00:48:33 +01004271 /* When you run into this, adjust the code below for the new flag */
4272 BUILD_BUG_ON(NL80211_STA_FLAG_MAX != 7);
4273
Johannes Bergbdd90d52011-12-14 12:20:27 +01004274 switch (dev->ieee80211_ptr->iftype) {
4275 case NL80211_IFTYPE_AP:
4276 case NL80211_IFTYPE_AP_VLAN:
4277 case NL80211_IFTYPE_P2P_GO:
Johannes Berg984c3112013-02-14 23:43:25 +01004278 /* ignore WME attributes if iface/sta is not capable */
4279 if (!(rdev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) ||
4280 !(params.sta_flags_set & BIT(NL80211_STA_FLAG_WME)))
4281 params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD;
Eliad Pellerc75786c2011-08-23 14:37:46 +03004282
Johannes Bergbdd90d52011-12-14 12:20:27 +01004283 /* TDLS peers cannot be added */
Jouni Malinen3d124ea2013-05-27 18:24:02 +03004284 if ((params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) ||
4285 info->attrs[NL80211_ATTR_PEER_AID])
Johannes Berg4319e192011-09-07 11:50:48 +02004286 return -EINVAL;
Johannes Bergbdd90d52011-12-14 12:20:27 +01004287 /* but don't bother the driver with it */
4288 params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER);
Eliad Pellerc75786c2011-08-23 14:37:46 +03004289
Johannes Bergd582cff2012-10-26 17:53:44 +02004290 /* allow authenticated/associated only if driver handles it */
4291 if (!(rdev->wiphy.features &
4292 NL80211_FEATURE_FULL_AP_CLIENT_STATE) &&
4293 params.sta_flags_mask &
4294 (BIT(NL80211_STA_FLAG_AUTHENTICATED) |
4295 BIT(NL80211_STA_FLAG_ASSOCIATED)))
4296 return -EINVAL;
4297
Johannes Bergbdd90d52011-12-14 12:20:27 +01004298 /* must be last in here for error handling */
4299 params.vlan = get_vlan(info, rdev);
4300 if (IS_ERR(params.vlan))
4301 return PTR_ERR(params.vlan);
4302 break;
4303 case NL80211_IFTYPE_MESH_POINT:
Johannes Berg984c3112013-02-14 23:43:25 +01004304 /* ignore uAPSD data */
4305 params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD;
4306
Johannes Bergd582cff2012-10-26 17:53:44 +02004307 /* associated is disallowed */
4308 if (params.sta_flags_mask & BIT(NL80211_STA_FLAG_ASSOCIATED))
4309 return -EINVAL;
Johannes Bergbdd90d52011-12-14 12:20:27 +01004310 /* TDLS peers cannot be added */
Jouni Malinen3d124ea2013-05-27 18:24:02 +03004311 if ((params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) ||
4312 info->attrs[NL80211_ATTR_PEER_AID])
Johannes Berg4319e192011-09-07 11:50:48 +02004313 return -EINVAL;
Johannes Bergbdd90d52011-12-14 12:20:27 +01004314 break;
4315 case NL80211_IFTYPE_STATION:
Johannes Berg93d08f02013-03-04 09:29:46 +01004316 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Berg984c3112013-02-14 23:43:25 +01004317 /* ignore uAPSD data */
4318 params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD;
4319
Johannes Berg77ee7c82013-02-15 00:48:33 +01004320 /* these are disallowed */
4321 if (params.sta_flags_mask &
4322 (BIT(NL80211_STA_FLAG_ASSOCIATED) |
4323 BIT(NL80211_STA_FLAG_AUTHENTICATED)))
Johannes Bergd582cff2012-10-26 17:53:44 +02004324 return -EINVAL;
Johannes Bergbdd90d52011-12-14 12:20:27 +01004325 /* Only TDLS peers can be added */
4326 if (!(params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)))
4327 return -EINVAL;
4328 /* Can only add if TDLS ... */
4329 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS))
4330 return -EOPNOTSUPP;
4331 /* ... with external setup is supported */
4332 if (!(rdev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP))
4333 return -EOPNOTSUPP;
Johannes Berg77ee7c82013-02-15 00:48:33 +01004334 /*
4335 * Older wpa_supplicant versions always mark the TDLS peer
4336 * as authorized, but it shouldn't yet be.
4337 */
4338 params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_AUTHORIZED);
Johannes Bergbdd90d52011-12-14 12:20:27 +01004339 break;
4340 default:
4341 return -EOPNOTSUPP;
Eliad Pellerc75786c2011-08-23 14:37:46 +03004342 }
4343
Johannes Bergbdd90d52011-12-14 12:20:27 +01004344 /* be aware of params.vlan when changing code here */
Johannes Berg5727ef12007-12-19 02:03:34 +01004345
Hila Gonene35e4d22012-06-27 17:19:42 +03004346 err = rdev_add_station(rdev, dev, mac_addr, &params);
Johannes Berg5727ef12007-12-19 02:03:34 +01004347
Johannes Berg5727ef12007-12-19 02:03:34 +01004348 if (params.vlan)
4349 dev_put(params.vlan);
Johannes Berg5727ef12007-12-19 02:03:34 +01004350 return err;
4351}
4352
4353static int nl80211_del_station(struct sk_buff *skb, struct genl_info *info)
4354{
Johannes Berg4c476992010-10-04 21:36:35 +02004355 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4356 struct net_device *dev = info->user_ptr[1];
Johannes Berg5727ef12007-12-19 02:03:34 +01004357 u8 *mac_addr = NULL;
4358
4359 if (info->attrs[NL80211_ATTR_MAC])
4360 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
4361
Johannes Berge80cf852009-05-11 14:43:13 +02004362 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
Marco Porschd5d9de02010-03-30 10:00:16 +02004363 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN &&
Johannes Berg074ac8d2010-09-16 14:58:22 +02004364 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT &&
Johannes Berg4c476992010-10-04 21:36:35 +02004365 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
4366 return -EINVAL;
Johannes Berge80cf852009-05-11 14:43:13 +02004367
Johannes Berg4c476992010-10-04 21:36:35 +02004368 if (!rdev->ops->del_station)
4369 return -EOPNOTSUPP;
Johannes Berg5727ef12007-12-19 02:03:34 +01004370
Hila Gonene35e4d22012-06-27 17:19:42 +03004371 return rdev_del_station(rdev, dev, mac_addr);
Johannes Berg5727ef12007-12-19 02:03:34 +01004372}
4373
Eric W. Biederman15e47302012-09-07 20:12:54 +00004374static int nl80211_send_mpath(struct sk_buff *msg, u32 portid, u32 seq,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004375 int flags, struct net_device *dev,
4376 u8 *dst, u8 *next_hop,
4377 struct mpath_info *pinfo)
4378{
4379 void *hdr;
4380 struct nlattr *pinfoattr;
4381
Eric W. Biederman15e47302012-09-07 20:12:54 +00004382 hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_STATION);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004383 if (!hdr)
4384 return -1;
4385
David S. Miller9360ffd2012-03-29 04:41:26 -04004386 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
4387 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, dst) ||
4388 nla_put(msg, NL80211_ATTR_MPATH_NEXT_HOP, ETH_ALEN, next_hop) ||
4389 nla_put_u32(msg, NL80211_ATTR_GENERATION, pinfo->generation))
4390 goto nla_put_failure;
Johannes Bergf5ea9122009-08-07 16:17:38 +02004391
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004392 pinfoattr = nla_nest_start(msg, NL80211_ATTR_MPATH_INFO);
4393 if (!pinfoattr)
4394 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04004395 if ((pinfo->filled & MPATH_INFO_FRAME_QLEN) &&
4396 nla_put_u32(msg, NL80211_MPATH_INFO_FRAME_QLEN,
4397 pinfo->frame_qlen))
4398 goto nla_put_failure;
4399 if (((pinfo->filled & MPATH_INFO_SN) &&
4400 nla_put_u32(msg, NL80211_MPATH_INFO_SN, pinfo->sn)) ||
4401 ((pinfo->filled & MPATH_INFO_METRIC) &&
4402 nla_put_u32(msg, NL80211_MPATH_INFO_METRIC,
4403 pinfo->metric)) ||
4404 ((pinfo->filled & MPATH_INFO_EXPTIME) &&
4405 nla_put_u32(msg, NL80211_MPATH_INFO_EXPTIME,
4406 pinfo->exptime)) ||
4407 ((pinfo->filled & MPATH_INFO_FLAGS) &&
4408 nla_put_u8(msg, NL80211_MPATH_INFO_FLAGS,
4409 pinfo->flags)) ||
4410 ((pinfo->filled & MPATH_INFO_DISCOVERY_TIMEOUT) &&
4411 nla_put_u32(msg, NL80211_MPATH_INFO_DISCOVERY_TIMEOUT,
4412 pinfo->discovery_timeout)) ||
4413 ((pinfo->filled & MPATH_INFO_DISCOVERY_RETRIES) &&
4414 nla_put_u8(msg, NL80211_MPATH_INFO_DISCOVERY_RETRIES,
4415 pinfo->discovery_retries)))
4416 goto nla_put_failure;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004417
4418 nla_nest_end(msg, pinfoattr);
4419
4420 return genlmsg_end(msg, hdr);
4421
4422 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07004423 genlmsg_cancel(msg, hdr);
4424 return -EMSGSIZE;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004425}
4426
4427static int nl80211_dump_mpath(struct sk_buff *skb,
Johannes Bergbba95fe2008-07-29 13:22:51 +02004428 struct netlink_callback *cb)
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004429{
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004430 struct mpath_info pinfo;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08004431 struct cfg80211_registered_device *rdev;
Johannes Berg97990a02013-04-19 01:02:55 +02004432 struct wireless_dev *wdev;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004433 u8 dst[ETH_ALEN];
4434 u8 next_hop[ETH_ALEN];
Johannes Berg97990a02013-04-19 01:02:55 +02004435 int path_idx = cb->args[2];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004436 int err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004437
Zhao, Gang1b8ec872014-04-21 12:53:02 +08004438 err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev);
Johannes Berg67748892010-10-04 21:14:06 +02004439 if (err)
4440 return err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004441
Zhao, Gang1b8ec872014-04-21 12:53:02 +08004442 if (!rdev->ops->dump_mpath) {
Jouni Malineneec60b02009-03-20 21:21:19 +02004443 err = -EOPNOTSUPP;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004444 goto out_err;
4445 }
4446
Johannes Berg97990a02013-04-19 01:02:55 +02004447 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) {
Jouni Malineneec60b02009-03-20 21:21:19 +02004448 err = -EOPNOTSUPP;
Roel Kluin0448b5f2009-08-22 21:15:49 +02004449 goto out_err;
Jouni Malineneec60b02009-03-20 21:21:19 +02004450 }
4451
Johannes Bergbba95fe2008-07-29 13:22:51 +02004452 while (1) {
Zhao, Gang1b8ec872014-04-21 12:53:02 +08004453 err = rdev_dump_mpath(rdev, wdev->netdev, path_idx, dst,
Johannes Berg97990a02013-04-19 01:02:55 +02004454 next_hop, &pinfo);
Johannes Bergbba95fe2008-07-29 13:22:51 +02004455 if (err == -ENOENT)
4456 break;
4457 if (err)
Johannes Berg3b858752009-03-12 09:55:09 +01004458 goto out_err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004459
Eric W. Biederman15e47302012-09-07 20:12:54 +00004460 if (nl80211_send_mpath(skb, NETLINK_CB(cb->skb).portid,
Johannes Bergbba95fe2008-07-29 13:22:51 +02004461 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Johannes Berg97990a02013-04-19 01:02:55 +02004462 wdev->netdev, dst, next_hop,
Johannes Bergbba95fe2008-07-29 13:22:51 +02004463 &pinfo) < 0)
4464 goto out;
4465
4466 path_idx++;
4467 }
4468
4469
4470 out:
Johannes Berg97990a02013-04-19 01:02:55 +02004471 cb->args[2] = path_idx;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004472 err = skb->len;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004473 out_err:
Zhao, Gang1b8ec872014-04-21 12:53:02 +08004474 nl80211_finish_wdev_dump(rdev);
Johannes Bergbba95fe2008-07-29 13:22:51 +02004475 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004476}
4477
4478static int nl80211_get_mpath(struct sk_buff *skb, struct genl_info *info)
4479{
Johannes Berg4c476992010-10-04 21:36:35 +02004480 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004481 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02004482 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004483 struct mpath_info pinfo;
4484 struct sk_buff *msg;
4485 u8 *dst = NULL;
4486 u8 next_hop[ETH_ALEN];
4487
4488 memset(&pinfo, 0, sizeof(pinfo));
4489
4490 if (!info->attrs[NL80211_ATTR_MAC])
4491 return -EINVAL;
4492
4493 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
4494
Johannes Berg4c476992010-10-04 21:36:35 +02004495 if (!rdev->ops->get_mpath)
4496 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01004497
Johannes Berg4c476992010-10-04 21:36:35 +02004498 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
4499 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02004500
Hila Gonene35e4d22012-06-27 17:19:42 +03004501 err = rdev_get_mpath(rdev, dev, dst, next_hop, &pinfo);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004502 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02004503 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004504
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07004505 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004506 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02004507 return -ENOMEM;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004508
Eric W. Biederman15e47302012-09-07 20:12:54 +00004509 if (nl80211_send_mpath(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berg4c476992010-10-04 21:36:35 +02004510 dev, dst, next_hop, &pinfo) < 0) {
4511 nlmsg_free(msg);
4512 return -ENOBUFS;
4513 }
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004514
Johannes Berg4c476992010-10-04 21:36:35 +02004515 return genlmsg_reply(msg, info);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004516}
4517
4518static int nl80211_set_mpath(struct sk_buff *skb, struct genl_info *info)
4519{
Johannes Berg4c476992010-10-04 21:36:35 +02004520 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4521 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004522 u8 *dst = NULL;
4523 u8 *next_hop = NULL;
4524
4525 if (!info->attrs[NL80211_ATTR_MAC])
4526 return -EINVAL;
4527
4528 if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP])
4529 return -EINVAL;
4530
4531 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
4532 next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]);
4533
Johannes Berg4c476992010-10-04 21:36:35 +02004534 if (!rdev->ops->change_mpath)
4535 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01004536
Johannes Berg4c476992010-10-04 21:36:35 +02004537 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
4538 return -EOPNOTSUPP;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004539
Hila Gonene35e4d22012-06-27 17:19:42 +03004540 return rdev_change_mpath(rdev, dev, dst, next_hop);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004541}
Johannes Berg4c476992010-10-04 21:36:35 +02004542
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004543static int nl80211_new_mpath(struct sk_buff *skb, struct genl_info *info)
4544{
Johannes Berg4c476992010-10-04 21:36:35 +02004545 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4546 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004547 u8 *dst = NULL;
4548 u8 *next_hop = NULL;
4549
4550 if (!info->attrs[NL80211_ATTR_MAC])
4551 return -EINVAL;
4552
4553 if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP])
4554 return -EINVAL;
4555
4556 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
4557 next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]);
4558
Johannes Berg4c476992010-10-04 21:36:35 +02004559 if (!rdev->ops->add_mpath)
4560 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01004561
Johannes Berg4c476992010-10-04 21:36:35 +02004562 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
4563 return -EOPNOTSUPP;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004564
Hila Gonene35e4d22012-06-27 17:19:42 +03004565 return rdev_add_mpath(rdev, dev, dst, next_hop);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004566}
4567
4568static int nl80211_del_mpath(struct sk_buff *skb, struct genl_info *info)
4569{
Johannes Berg4c476992010-10-04 21:36:35 +02004570 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4571 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004572 u8 *dst = NULL;
4573
4574 if (info->attrs[NL80211_ATTR_MAC])
4575 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
4576
Johannes Berg4c476992010-10-04 21:36:35 +02004577 if (!rdev->ops->del_mpath)
4578 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01004579
Hila Gonene35e4d22012-06-27 17:19:42 +03004580 return rdev_del_mpath(rdev, dev, dst);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004581}
4582
Jouni Malinen9f1ba902008-08-07 20:07:01 +03004583static int nl80211_set_bss(struct sk_buff *skb, struct genl_info *info)
4584{
Johannes Berg4c476992010-10-04 21:36:35 +02004585 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4586 struct net_device *dev = info->user_ptr[1];
Simon Wunderlichc56589e2013-11-21 18:19:49 +01004587 struct wireless_dev *wdev = dev->ieee80211_ptr;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03004588 struct bss_parameters params;
Simon Wunderlichc56589e2013-11-21 18:19:49 +01004589 int err;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03004590
4591 memset(&params, 0, sizeof(params));
4592 /* default to not changing parameters */
4593 params.use_cts_prot = -1;
4594 params.use_short_preamble = -1;
4595 params.use_short_slot_time = -1;
Felix Fietkaufd8aaaf2010-04-27 01:23:35 +02004596 params.ap_isolate = -1;
Helmut Schaa50b12f52010-11-19 12:40:25 +01004597 params.ht_opmode = -1;
Johannes Berg53cabad2012-11-14 15:17:28 +01004598 params.p2p_ctwindow = -1;
4599 params.p2p_opp_ps = -1;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03004600
4601 if (info->attrs[NL80211_ATTR_BSS_CTS_PROT])
4602 params.use_cts_prot =
4603 nla_get_u8(info->attrs[NL80211_ATTR_BSS_CTS_PROT]);
4604 if (info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE])
4605 params.use_short_preamble =
4606 nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]);
4607 if (info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME])
4608 params.use_short_slot_time =
4609 nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]);
Jouni Malinen90c97a02008-10-30 16:59:22 +02004610 if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) {
4611 params.basic_rates =
4612 nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
4613 params.basic_rates_len =
4614 nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
4615 }
Felix Fietkaufd8aaaf2010-04-27 01:23:35 +02004616 if (info->attrs[NL80211_ATTR_AP_ISOLATE])
4617 params.ap_isolate = !!nla_get_u8(info->attrs[NL80211_ATTR_AP_ISOLATE]);
Helmut Schaa50b12f52010-11-19 12:40:25 +01004618 if (info->attrs[NL80211_ATTR_BSS_HT_OPMODE])
4619 params.ht_opmode =
4620 nla_get_u16(info->attrs[NL80211_ATTR_BSS_HT_OPMODE]);
Jouni Malinen9f1ba902008-08-07 20:07:01 +03004621
Johannes Berg53cabad2012-11-14 15:17:28 +01004622 if (info->attrs[NL80211_ATTR_P2P_CTWINDOW]) {
4623 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
4624 return -EINVAL;
4625 params.p2p_ctwindow =
4626 nla_get_s8(info->attrs[NL80211_ATTR_P2P_CTWINDOW]);
4627 if (params.p2p_ctwindow < 0)
4628 return -EINVAL;
4629 if (params.p2p_ctwindow != 0 &&
4630 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_CTWIN))
4631 return -EINVAL;
4632 }
4633
4634 if (info->attrs[NL80211_ATTR_P2P_OPPPS]) {
4635 u8 tmp;
4636
4637 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
4638 return -EINVAL;
4639 tmp = nla_get_u8(info->attrs[NL80211_ATTR_P2P_OPPPS]);
4640 if (tmp > 1)
4641 return -EINVAL;
4642 params.p2p_opp_ps = tmp;
4643 if (params.p2p_opp_ps &&
4644 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_OPPPS))
4645 return -EINVAL;
4646 }
4647
Johannes Berg4c476992010-10-04 21:36:35 +02004648 if (!rdev->ops->change_bss)
4649 return -EOPNOTSUPP;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03004650
Johannes Berg074ac8d2010-09-16 14:58:22 +02004651 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
Johannes Berg4c476992010-10-04 21:36:35 +02004652 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
4653 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02004654
Simon Wunderlichc56589e2013-11-21 18:19:49 +01004655 wdev_lock(wdev);
4656 err = rdev_change_bss(rdev, dev, &params);
4657 wdev_unlock(wdev);
4658
4659 return err;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03004660}
4661
Alexey Dobriyanb54452b2010-02-18 08:14:31 +00004662static const struct nla_policy reg_rule_policy[NL80211_REG_RULE_ATTR_MAX + 1] = {
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004663 [NL80211_ATTR_REG_RULE_FLAGS] = { .type = NLA_U32 },
4664 [NL80211_ATTR_FREQ_RANGE_START] = { .type = NLA_U32 },
4665 [NL80211_ATTR_FREQ_RANGE_END] = { .type = NLA_U32 },
4666 [NL80211_ATTR_FREQ_RANGE_MAX_BW] = { .type = NLA_U32 },
4667 [NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN] = { .type = NLA_U32 },
4668 [NL80211_ATTR_POWER_RULE_MAX_EIRP] = { .type = NLA_U32 },
Janusz Dziedzic089027e2014-02-21 19:46:12 +01004669 [NL80211_ATTR_DFS_CAC_TIME] = { .type = NLA_U32 },
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004670};
4671
4672static int parse_reg_rule(struct nlattr *tb[],
4673 struct ieee80211_reg_rule *reg_rule)
4674{
4675 struct ieee80211_freq_range *freq_range = &reg_rule->freq_range;
4676 struct ieee80211_power_rule *power_rule = &reg_rule->power_rule;
4677
4678 if (!tb[NL80211_ATTR_REG_RULE_FLAGS])
4679 return -EINVAL;
4680 if (!tb[NL80211_ATTR_FREQ_RANGE_START])
4681 return -EINVAL;
4682 if (!tb[NL80211_ATTR_FREQ_RANGE_END])
4683 return -EINVAL;
Janusz Dziedzicb0dfd2e2014-02-20 13:52:16 +01004684 if (!tb[NL80211_ATTR_FREQ_RANGE_MAX_BW])
4685 return -EINVAL;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004686 if (!tb[NL80211_ATTR_POWER_RULE_MAX_EIRP])
4687 return -EINVAL;
4688
4689 reg_rule->flags = nla_get_u32(tb[NL80211_ATTR_REG_RULE_FLAGS]);
4690
4691 freq_range->start_freq_khz =
4692 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_START]);
4693 freq_range->end_freq_khz =
4694 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_END]);
Janusz Dziedzicb0dfd2e2014-02-20 13:52:16 +01004695 freq_range->max_bandwidth_khz =
4696 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]);
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004697
4698 power_rule->max_eirp =
4699 nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]);
4700
4701 if (tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN])
4702 power_rule->max_antenna_gain =
4703 nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]);
4704
Janusz Dziedzic089027e2014-02-21 19:46:12 +01004705 if (tb[NL80211_ATTR_DFS_CAC_TIME])
4706 reg_rule->dfs_cac_ms =
4707 nla_get_u32(tb[NL80211_ATTR_DFS_CAC_TIME]);
4708
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004709 return 0;
4710}
4711
4712static int nl80211_req_set_reg(struct sk_buff *skb, struct genl_info *info)
4713{
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004714 char *data = NULL;
Luis R. Rodriguez57b5ce02012-07-12 11:49:18 -07004715 enum nl80211_user_reg_hint_type user_reg_hint_type;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004716
Luis R. Rodriguez80778f12009-02-21 00:04:22 -05004717 /*
4718 * You should only get this when cfg80211 hasn't yet initialized
4719 * completely when built-in to the kernel right between the time
4720 * window between nl80211_init() and regulatory_init(), if that is
4721 * even possible.
4722 */
Johannes Berg458f4f92012-12-06 15:47:38 +01004723 if (unlikely(!rcu_access_pointer(cfg80211_regdomain)))
Luis R. Rodriguezfe33eb32009-02-21 00:04:30 -05004724 return -EINPROGRESS;
Luis R. Rodriguez80778f12009-02-21 00:04:22 -05004725
Luis R. Rodriguez57b5ce02012-07-12 11:49:18 -07004726 if (info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE])
4727 user_reg_hint_type =
4728 nla_get_u32(info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE]);
4729 else
4730 user_reg_hint_type = NL80211_USER_REG_HINT_USER;
4731
4732 switch (user_reg_hint_type) {
4733 case NL80211_USER_REG_HINT_USER:
4734 case NL80211_USER_REG_HINT_CELL_BASE:
Ilan Peer52616f22014-02-25 16:26:00 +02004735 if (!info->attrs[NL80211_ATTR_REG_ALPHA2])
4736 return -EINVAL;
4737
4738 data = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]);
4739 return regulatory_hint_user(data, user_reg_hint_type);
4740 case NL80211_USER_REG_HINT_INDOOR:
4741 return regulatory_hint_indoor_user();
Luis R. Rodriguez57b5ce02012-07-12 11:49:18 -07004742 default:
4743 return -EINVAL;
4744 }
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004745}
4746
Javier Cardona24bdd9f2010-12-16 17:37:48 -08004747static int nl80211_get_mesh_config(struct sk_buff *skb,
Johannes Berg29cbe682010-12-03 09:20:44 +01004748 struct genl_info *info)
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004749{
Johannes Berg4c476992010-10-04 21:36:35 +02004750 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg4c476992010-10-04 21:36:35 +02004751 struct net_device *dev = info->user_ptr[1];
Johannes Berg29cbe682010-12-03 09:20:44 +01004752 struct wireless_dev *wdev = dev->ieee80211_ptr;
4753 struct mesh_config cur_params;
4754 int err = 0;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004755 void *hdr;
4756 struct nlattr *pinfoattr;
4757 struct sk_buff *msg;
4758
Johannes Berg29cbe682010-12-03 09:20:44 +01004759 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT)
4760 return -EOPNOTSUPP;
4761
Javier Cardona24bdd9f2010-12-16 17:37:48 -08004762 if (!rdev->ops->get_mesh_config)
Johannes Berg4c476992010-10-04 21:36:35 +02004763 return -EOPNOTSUPP;
Jouni Malinenf3f92582009-03-20 17:57:36 +02004764
Johannes Berg29cbe682010-12-03 09:20:44 +01004765 wdev_lock(wdev);
4766 /* If not connected, get default parameters */
4767 if (!wdev->mesh_id_len)
4768 memcpy(&cur_params, &default_mesh_config, sizeof(cur_params));
4769 else
Hila Gonene35e4d22012-06-27 17:19:42 +03004770 err = rdev_get_mesh_config(rdev, dev, &cur_params);
Johannes Berg29cbe682010-12-03 09:20:44 +01004771 wdev_unlock(wdev);
4772
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004773 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02004774 return err;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004775
4776 /* Draw up a netlink message to send back */
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07004777 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02004778 if (!msg)
4779 return -ENOMEM;
Eric W. Biederman15e47302012-09-07 20:12:54 +00004780 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Javier Cardona24bdd9f2010-12-16 17:37:48 -08004781 NL80211_CMD_GET_MESH_CONFIG);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004782 if (!hdr)
Julia Lawallefe1cf02011-01-28 15:17:11 +01004783 goto out;
Javier Cardona24bdd9f2010-12-16 17:37:48 -08004784 pinfoattr = nla_nest_start(msg, NL80211_ATTR_MESH_CONFIG);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004785 if (!pinfoattr)
4786 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04004787 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
4788 nla_put_u16(msg, NL80211_MESHCONF_RETRY_TIMEOUT,
4789 cur_params.dot11MeshRetryTimeout) ||
4790 nla_put_u16(msg, NL80211_MESHCONF_CONFIRM_TIMEOUT,
4791 cur_params.dot11MeshConfirmTimeout) ||
4792 nla_put_u16(msg, NL80211_MESHCONF_HOLDING_TIMEOUT,
4793 cur_params.dot11MeshHoldingTimeout) ||
4794 nla_put_u16(msg, NL80211_MESHCONF_MAX_PEER_LINKS,
4795 cur_params.dot11MeshMaxPeerLinks) ||
4796 nla_put_u8(msg, NL80211_MESHCONF_MAX_RETRIES,
4797 cur_params.dot11MeshMaxRetries) ||
4798 nla_put_u8(msg, NL80211_MESHCONF_TTL,
4799 cur_params.dot11MeshTTL) ||
4800 nla_put_u8(msg, NL80211_MESHCONF_ELEMENT_TTL,
4801 cur_params.element_ttl) ||
4802 nla_put_u8(msg, NL80211_MESHCONF_AUTO_OPEN_PLINKS,
4803 cur_params.auto_open_plinks) ||
John W. Linville7eab0f62012-04-12 14:25:14 -04004804 nla_put_u32(msg, NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR,
4805 cur_params.dot11MeshNbrOffsetMaxNeighbor) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04004806 nla_put_u8(msg, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES,
4807 cur_params.dot11MeshHWMPmaxPREQretries) ||
4808 nla_put_u32(msg, NL80211_MESHCONF_PATH_REFRESH_TIME,
4809 cur_params.path_refresh_time) ||
4810 nla_put_u16(msg, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT,
4811 cur_params.min_discovery_timeout) ||
4812 nla_put_u32(msg, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT,
4813 cur_params.dot11MeshHWMPactivePathTimeout) ||
4814 nla_put_u16(msg, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL,
4815 cur_params.dot11MeshHWMPpreqMinInterval) ||
4816 nla_put_u16(msg, NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL,
4817 cur_params.dot11MeshHWMPperrMinInterval) ||
4818 nla_put_u16(msg, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME,
4819 cur_params.dot11MeshHWMPnetDiameterTraversalTime) ||
4820 nla_put_u8(msg, NL80211_MESHCONF_HWMP_ROOTMODE,
4821 cur_params.dot11MeshHWMPRootMode) ||
4822 nla_put_u16(msg, NL80211_MESHCONF_HWMP_RANN_INTERVAL,
4823 cur_params.dot11MeshHWMPRannInterval) ||
4824 nla_put_u8(msg, NL80211_MESHCONF_GATE_ANNOUNCEMENTS,
4825 cur_params.dot11MeshGateAnnouncementProtocol) ||
4826 nla_put_u8(msg, NL80211_MESHCONF_FORWARDING,
4827 cur_params.dot11MeshForwarding) ||
4828 nla_put_u32(msg, NL80211_MESHCONF_RSSI_THRESHOLD,
Ashok Nagarajan70c33ea2012-04-30 14:20:32 -07004829 cur_params.rssi_threshold) ||
4830 nla_put_u32(msg, NL80211_MESHCONF_HT_OPMODE,
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08004831 cur_params.ht_opmode) ||
4832 nla_put_u32(msg, NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT,
4833 cur_params.dot11MeshHWMPactivePathToRootTimeout) ||
4834 nla_put_u16(msg, NL80211_MESHCONF_HWMP_ROOT_INTERVAL,
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +08004835 cur_params.dot11MeshHWMProotInterval) ||
4836 nla_put_u16(msg, NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL,
Marco Porsch3b1c5a52013-01-07 16:04:52 +01004837 cur_params.dot11MeshHWMPconfirmationInterval) ||
4838 nla_put_u32(msg, NL80211_MESHCONF_POWER_MODE,
4839 cur_params.power_mode) ||
4840 nla_put_u16(msg, NL80211_MESHCONF_AWAKE_WINDOW,
Colleen Twitty8e7c0532013-06-03 09:53:39 -07004841 cur_params.dot11MeshAwakeWindowDuration) ||
4842 nla_put_u32(msg, NL80211_MESHCONF_PLINK_TIMEOUT,
4843 cur_params.plink_timeout))
David S. Miller9360ffd2012-03-29 04:41:26 -04004844 goto nla_put_failure;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004845 nla_nest_end(msg, pinfoattr);
4846 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02004847 return genlmsg_reply(msg, info);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004848
Johannes Berg3b858752009-03-12 09:55:09 +01004849 nla_put_failure:
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004850 genlmsg_cancel(msg, hdr);
Julia Lawallefe1cf02011-01-28 15:17:11 +01004851 out:
Yuri Ershovd080e272010-06-29 15:08:07 +04004852 nlmsg_free(msg);
Johannes Berg4c476992010-10-04 21:36:35 +02004853 return -ENOBUFS;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004854}
4855
Alexey Dobriyanb54452b2010-02-18 08:14:31 +00004856static const struct nla_policy nl80211_meshconf_params_policy[NL80211_MESHCONF_ATTR_MAX+1] = {
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004857 [NL80211_MESHCONF_RETRY_TIMEOUT] = { .type = NLA_U16 },
4858 [NL80211_MESHCONF_CONFIRM_TIMEOUT] = { .type = NLA_U16 },
4859 [NL80211_MESHCONF_HOLDING_TIMEOUT] = { .type = NLA_U16 },
4860 [NL80211_MESHCONF_MAX_PEER_LINKS] = { .type = NLA_U16 },
4861 [NL80211_MESHCONF_MAX_RETRIES] = { .type = NLA_U8 },
4862 [NL80211_MESHCONF_TTL] = { .type = NLA_U8 },
Javier Cardona45904f22010-12-03 09:20:40 +01004863 [NL80211_MESHCONF_ELEMENT_TTL] = { .type = NLA_U8 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004864 [NL80211_MESHCONF_AUTO_OPEN_PLINKS] = { .type = NLA_U8 },
Javier Cardonad299a1f2012-03-31 11:31:33 -07004865 [NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR] = { .type = NLA_U32 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004866 [NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES] = { .type = NLA_U8 },
4867 [NL80211_MESHCONF_PATH_REFRESH_TIME] = { .type = NLA_U32 },
4868 [NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT] = { .type = NLA_U16 },
4869 [NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT] = { .type = NLA_U32 },
4870 [NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL] = { .type = NLA_U16 },
Thomas Pedersendca7e942011-11-24 17:15:24 -08004871 [NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL] = { .type = NLA_U16 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004872 [NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME] = { .type = NLA_U16 },
Javier Cardona699403d2011-08-09 16:45:09 -07004873 [NL80211_MESHCONF_HWMP_ROOTMODE] = { .type = NLA_U8 },
Javier Cardona0507e152011-08-09 16:45:10 -07004874 [NL80211_MESHCONF_HWMP_RANN_INTERVAL] = { .type = NLA_U16 },
Javier Cardona16dd7262011-08-09 16:45:11 -07004875 [NL80211_MESHCONF_GATE_ANNOUNCEMENTS] = { .type = NLA_U8 },
Chun-Yeow Yeoh94f90652012-01-21 01:02:16 +08004876 [NL80211_MESHCONF_FORWARDING] = { .type = NLA_U8 },
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004877 [NL80211_MESHCONF_RSSI_THRESHOLD] = { .type = NLA_U32 },
4878 [NL80211_MESHCONF_HT_OPMODE] = { .type = NLA_U16 },
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08004879 [NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT] = { .type = NLA_U32 },
4880 [NL80211_MESHCONF_HWMP_ROOT_INTERVAL] = { .type = NLA_U16 },
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +08004881 [NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL] = { .type = NLA_U16 },
Marco Porsch3b1c5a52013-01-07 16:04:52 +01004882 [NL80211_MESHCONF_POWER_MODE] = { .type = NLA_U32 },
4883 [NL80211_MESHCONF_AWAKE_WINDOW] = { .type = NLA_U16 },
Colleen Twitty8e7c0532013-06-03 09:53:39 -07004884 [NL80211_MESHCONF_PLINK_TIMEOUT] = { .type = NLA_U32 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004885};
4886
Javier Cardonac80d5452010-12-16 17:37:49 -08004887static const struct nla_policy
4888 nl80211_mesh_setup_params_policy[NL80211_MESH_SETUP_ATTR_MAX+1] = {
Javier Cardonad299a1f2012-03-31 11:31:33 -07004889 [NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC] = { .type = NLA_U8 },
Javier Cardonac80d5452010-12-16 17:37:49 -08004890 [NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL] = { .type = NLA_U8 },
4891 [NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC] = { .type = NLA_U8 },
Javier Cardona15d5dda2011-04-07 15:08:28 -07004892 [NL80211_MESH_SETUP_USERSPACE_AUTH] = { .type = NLA_FLAG },
Colleen Twitty6e16d902013-05-08 11:45:59 -07004893 [NL80211_MESH_SETUP_AUTH_PROTOCOL] = { .type = NLA_U8 },
Thomas Pedersenbb2798d2013-03-04 13:06:10 -08004894 [NL80211_MESH_SETUP_USERSPACE_MPM] = { .type = NLA_FLAG },
Javier Cardona581a8b02011-04-07 15:08:27 -07004895 [NL80211_MESH_SETUP_IE] = { .type = NLA_BINARY,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004896 .len = IEEE80211_MAX_DATA_LEN },
Javier Cardonab130e5c2011-05-03 16:57:07 -07004897 [NL80211_MESH_SETUP_USERSPACE_AMPE] = { .type = NLA_FLAG },
Javier Cardonac80d5452010-12-16 17:37:49 -08004898};
4899
Javier Cardona24bdd9f2010-12-16 17:37:48 -08004900static int nl80211_parse_mesh_config(struct genl_info *info,
Johannes Bergbd90fdc2010-12-03 09:20:43 +01004901 struct mesh_config *cfg,
4902 u32 *mask_out)
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004903{
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004904 struct nlattr *tb[NL80211_MESHCONF_ATTR_MAX + 1];
Johannes Bergbd90fdc2010-12-03 09:20:43 +01004905 u32 mask = 0;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004906
Marco Porschea54fba2013-01-07 16:04:48 +01004907#define FILL_IN_MESH_PARAM_IF_SET(tb, cfg, param, min, max, mask, attr, fn) \
4908do { \
4909 if (tb[attr]) { \
4910 if (fn(tb[attr]) < min || fn(tb[attr]) > max) \
4911 return -EINVAL; \
4912 cfg->param = fn(tb[attr]); \
4913 mask |= (1 << (attr - 1)); \
4914 } \
4915} while (0)
Johannes Bergbd90fdc2010-12-03 09:20:43 +01004916
4917
Javier Cardona24bdd9f2010-12-16 17:37:48 -08004918 if (!info->attrs[NL80211_ATTR_MESH_CONFIG])
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004919 return -EINVAL;
4920 if (nla_parse_nested(tb, NL80211_MESHCONF_ATTR_MAX,
Javier Cardona24bdd9f2010-12-16 17:37:48 -08004921 info->attrs[NL80211_ATTR_MESH_CONFIG],
Johannes Bergbd90fdc2010-12-03 09:20:43 +01004922 nl80211_meshconf_params_policy))
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004923 return -EINVAL;
4924
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004925 /* This makes sure that there aren't more than 32 mesh config
4926 * parameters (otherwise our bitfield scheme would not work.) */
4927 BUILD_BUG_ON(NL80211_MESHCONF_ATTR_MAX > 32);
4928
4929 /* Fill in the params struct */
Marco Porschea54fba2013-01-07 16:04:48 +01004930 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshRetryTimeout, 1, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004931 mask, NL80211_MESHCONF_RETRY_TIMEOUT,
4932 nla_get_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01004933 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshConfirmTimeout, 1, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004934 mask, NL80211_MESHCONF_CONFIRM_TIMEOUT,
4935 nla_get_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01004936 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHoldingTimeout, 1, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004937 mask, NL80211_MESHCONF_HOLDING_TIMEOUT,
4938 nla_get_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01004939 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxPeerLinks, 0, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004940 mask, NL80211_MESHCONF_MAX_PEER_LINKS,
4941 nla_get_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01004942 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxRetries, 0, 16,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004943 mask, NL80211_MESHCONF_MAX_RETRIES,
4944 nla_get_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01004945 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshTTL, 1, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004946 mask, NL80211_MESHCONF_TTL, nla_get_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01004947 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, element_ttl, 1, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004948 mask, NL80211_MESHCONF_ELEMENT_TTL,
4949 nla_get_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01004950 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, auto_open_plinks, 0, 1,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004951 mask, NL80211_MESHCONF_AUTO_OPEN_PLINKS,
4952 nla_get_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01004953 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshNbrOffsetMaxNeighbor,
4954 1, 255, mask,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004955 NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR,
4956 nla_get_u32);
Marco Porschea54fba2013-01-07 16:04:48 +01004957 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPmaxPREQretries, 0, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004958 mask, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES,
4959 nla_get_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01004960 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, path_refresh_time, 1, 65535,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004961 mask, NL80211_MESHCONF_PATH_REFRESH_TIME,
4962 nla_get_u32);
Marco Porschea54fba2013-01-07 16:04:48 +01004963 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, min_discovery_timeout, 1, 65535,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004964 mask, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT,
4965 nla_get_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01004966 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathTimeout,
4967 1, 65535, mask,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004968 NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT,
4969 nla_get_u32);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004970 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPpreqMinInterval,
Marco Porschea54fba2013-01-07 16:04:48 +01004971 1, 65535, mask,
4972 NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004973 nla_get_u16);
Thomas Pedersendca7e942011-11-24 17:15:24 -08004974 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPperrMinInterval,
Marco Porschea54fba2013-01-07 16:04:48 +01004975 1, 65535, mask,
4976 NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004977 nla_get_u16);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004978 FILL_IN_MESH_PARAM_IF_SET(tb, cfg,
Marco Porschea54fba2013-01-07 16:04:48 +01004979 dot11MeshHWMPnetDiameterTraversalTime,
4980 1, 65535, mask,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004981 NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME,
4982 nla_get_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01004983 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRootMode, 0, 4,
4984 mask, NL80211_MESHCONF_HWMP_ROOTMODE,
4985 nla_get_u8);
4986 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRannInterval, 1, 65535,
4987 mask, NL80211_MESHCONF_HWMP_RANN_INTERVAL,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004988 nla_get_u16);
Rui Paulo63c57232009-11-09 23:46:57 +00004989 FILL_IN_MESH_PARAM_IF_SET(tb, cfg,
Marco Porschea54fba2013-01-07 16:04:48 +01004990 dot11MeshGateAnnouncementProtocol, 0, 1,
4991 mask, NL80211_MESHCONF_GATE_ANNOUNCEMENTS,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004992 nla_get_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01004993 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshForwarding, 0, 1,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004994 mask, NL80211_MESHCONF_FORWARDING,
4995 nla_get_u8);
Chun-Yeow Yeoh83374fe2013-07-11 18:24:03 +08004996 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, rssi_threshold, -255, 0,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004997 mask, NL80211_MESHCONF_RSSI_THRESHOLD,
Chun-Yeow Yeoh83374fe2013-07-11 18:24:03 +08004998 nla_get_s32);
Marco Porschea54fba2013-01-07 16:04:48 +01004999 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, ht_opmode, 0, 16,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005000 mask, NL80211_MESHCONF_HT_OPMODE,
5001 nla_get_u16);
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08005002 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathToRootTimeout,
Marco Porschea54fba2013-01-07 16:04:48 +01005003 1, 65535, mask,
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08005004 NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT,
5005 nla_get_u32);
Marco Porschea54fba2013-01-07 16:04:48 +01005006 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMProotInterval, 1, 65535,
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08005007 mask, NL80211_MESHCONF_HWMP_ROOT_INTERVAL,
5008 nla_get_u16);
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +08005009 FILL_IN_MESH_PARAM_IF_SET(tb, cfg,
Marco Porschea54fba2013-01-07 16:04:48 +01005010 dot11MeshHWMPconfirmationInterval,
5011 1, 65535, mask,
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +08005012 NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL,
5013 nla_get_u16);
Marco Porsch3b1c5a52013-01-07 16:04:52 +01005014 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, power_mode,
5015 NL80211_MESH_POWER_ACTIVE,
5016 NL80211_MESH_POWER_MAX,
5017 mask, NL80211_MESHCONF_POWER_MODE,
5018 nla_get_u32);
5019 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshAwakeWindowDuration,
5020 0, 65535, mask,
5021 NL80211_MESHCONF_AWAKE_WINDOW, nla_get_u16);
Colleen Twitty8e7c0532013-06-03 09:53:39 -07005022 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, plink_timeout, 1, 0xffffffff,
5023 mask, NL80211_MESHCONF_PLINK_TIMEOUT,
5024 nla_get_u32);
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005025 if (mask_out)
5026 *mask_out = mask;
Javier Cardonac80d5452010-12-16 17:37:49 -08005027
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005028 return 0;
5029
5030#undef FILL_IN_MESH_PARAM_IF_SET
5031}
5032
Javier Cardonac80d5452010-12-16 17:37:49 -08005033static int nl80211_parse_mesh_setup(struct genl_info *info,
5034 struct mesh_setup *setup)
5035{
Thomas Pedersenbb2798d2013-03-04 13:06:10 -08005036 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Javier Cardonac80d5452010-12-16 17:37:49 -08005037 struct nlattr *tb[NL80211_MESH_SETUP_ATTR_MAX + 1];
5038
5039 if (!info->attrs[NL80211_ATTR_MESH_SETUP])
5040 return -EINVAL;
5041 if (nla_parse_nested(tb, NL80211_MESH_SETUP_ATTR_MAX,
5042 info->attrs[NL80211_ATTR_MESH_SETUP],
5043 nl80211_mesh_setup_params_policy))
5044 return -EINVAL;
5045
Javier Cardonad299a1f2012-03-31 11:31:33 -07005046 if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC])
5047 setup->sync_method =
5048 (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC])) ?
5049 IEEE80211_SYNC_METHOD_VENDOR :
5050 IEEE80211_SYNC_METHOD_NEIGHBOR_OFFSET;
5051
Javier Cardonac80d5452010-12-16 17:37:49 -08005052 if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL])
5053 setup->path_sel_proto =
5054 (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL])) ?
5055 IEEE80211_PATH_PROTOCOL_VENDOR :
5056 IEEE80211_PATH_PROTOCOL_HWMP;
5057
5058 if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC])
5059 setup->path_metric =
5060 (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC])) ?
5061 IEEE80211_PATH_METRIC_VENDOR :
5062 IEEE80211_PATH_METRIC_AIRTIME;
5063
Javier Cardona581a8b02011-04-07 15:08:27 -07005064
5065 if (tb[NL80211_MESH_SETUP_IE]) {
Javier Cardonac80d5452010-12-16 17:37:49 -08005066 struct nlattr *ieattr =
Javier Cardona581a8b02011-04-07 15:08:27 -07005067 tb[NL80211_MESH_SETUP_IE];
Javier Cardonac80d5452010-12-16 17:37:49 -08005068 if (!is_valid_ie_attr(ieattr))
5069 return -EINVAL;
Javier Cardona581a8b02011-04-07 15:08:27 -07005070 setup->ie = nla_data(ieattr);
5071 setup->ie_len = nla_len(ieattr);
Javier Cardonac80d5452010-12-16 17:37:49 -08005072 }
Thomas Pedersenbb2798d2013-03-04 13:06:10 -08005073 if (tb[NL80211_MESH_SETUP_USERSPACE_MPM] &&
5074 !(rdev->wiphy.features & NL80211_FEATURE_USERSPACE_MPM))
5075 return -EINVAL;
5076 setup->user_mpm = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_MPM]);
Javier Cardonab130e5c2011-05-03 16:57:07 -07005077 setup->is_authenticated = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AUTH]);
5078 setup->is_secure = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AMPE]);
Thomas Pedersenbb2798d2013-03-04 13:06:10 -08005079 if (setup->is_secure)
5080 setup->user_mpm = true;
Javier Cardonac80d5452010-12-16 17:37:49 -08005081
Colleen Twitty6e16d902013-05-08 11:45:59 -07005082 if (tb[NL80211_MESH_SETUP_AUTH_PROTOCOL]) {
5083 if (!setup->user_mpm)
5084 return -EINVAL;
5085 setup->auth_id =
5086 nla_get_u8(tb[NL80211_MESH_SETUP_AUTH_PROTOCOL]);
5087 }
5088
Javier Cardonac80d5452010-12-16 17:37:49 -08005089 return 0;
5090}
5091
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005092static int nl80211_update_mesh_config(struct sk_buff *skb,
Johannes Berg29cbe682010-12-03 09:20:44 +01005093 struct genl_info *info)
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005094{
5095 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5096 struct net_device *dev = info->user_ptr[1];
Johannes Berg29cbe682010-12-03 09:20:44 +01005097 struct wireless_dev *wdev = dev->ieee80211_ptr;
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005098 struct mesh_config cfg;
5099 u32 mask;
5100 int err;
5101
Johannes Berg29cbe682010-12-03 09:20:44 +01005102 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT)
5103 return -EOPNOTSUPP;
5104
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005105 if (!rdev->ops->update_mesh_config)
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005106 return -EOPNOTSUPP;
5107
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005108 err = nl80211_parse_mesh_config(info, &cfg, &mask);
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005109 if (err)
5110 return err;
5111
Johannes Berg29cbe682010-12-03 09:20:44 +01005112 wdev_lock(wdev);
5113 if (!wdev->mesh_id_len)
5114 err = -ENOLINK;
5115
5116 if (!err)
Hila Gonene35e4d22012-06-27 17:19:42 +03005117 err = rdev_update_mesh_config(rdev, dev, mask, &cfg);
Johannes Berg29cbe682010-12-03 09:20:44 +01005118
5119 wdev_unlock(wdev);
5120
5121 return err;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005122}
5123
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005124static int nl80211_get_reg(struct sk_buff *skb, struct genl_info *info)
5125{
Johannes Berg458f4f92012-12-06 15:47:38 +01005126 const struct ieee80211_regdomain *regdom;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005127 struct sk_buff *msg;
5128 void *hdr = NULL;
5129 struct nlattr *nl_reg_rules;
5130 unsigned int i;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005131
5132 if (!cfg80211_regdomain)
Johannes Berg5fe231e2013-05-08 21:45:15 +02005133 return -EINVAL;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005134
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07005135 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg5fe231e2013-05-08 21:45:15 +02005136 if (!msg)
5137 return -ENOBUFS;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005138
Eric W. Biederman15e47302012-09-07 20:12:54 +00005139 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005140 NL80211_CMD_GET_REG);
5141 if (!hdr)
Julia Lawallefe1cf02011-01-28 15:17:11 +01005142 goto put_failure;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005143
Luis R. Rodriguez57b5ce02012-07-12 11:49:18 -07005144 if (reg_last_request_cell_base() &&
5145 nla_put_u32(msg, NL80211_ATTR_USER_REG_HINT_TYPE,
5146 NL80211_USER_REG_HINT_CELL_BASE))
5147 goto nla_put_failure;
5148
Johannes Berg458f4f92012-12-06 15:47:38 +01005149 rcu_read_lock();
5150 regdom = rcu_dereference(cfg80211_regdomain);
5151
5152 if (nla_put_string(msg, NL80211_ATTR_REG_ALPHA2, regdom->alpha2) ||
5153 (regdom->dfs_region &&
5154 nla_put_u8(msg, NL80211_ATTR_DFS_REGION, regdom->dfs_region)))
5155 goto nla_put_failure_rcu;
5156
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005157 nl_reg_rules = nla_nest_start(msg, NL80211_ATTR_REG_RULES);
5158 if (!nl_reg_rules)
Johannes Berg458f4f92012-12-06 15:47:38 +01005159 goto nla_put_failure_rcu;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005160
Johannes Berg458f4f92012-12-06 15:47:38 +01005161 for (i = 0; i < regdom->n_reg_rules; i++) {
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005162 struct nlattr *nl_reg_rule;
5163 const struct ieee80211_reg_rule *reg_rule;
5164 const struct ieee80211_freq_range *freq_range;
5165 const struct ieee80211_power_rule *power_rule;
Janusz Dziedzic97524822014-01-30 09:52:20 +01005166 unsigned int max_bandwidth_khz;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005167
Johannes Berg458f4f92012-12-06 15:47:38 +01005168 reg_rule = &regdom->reg_rules[i];
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005169 freq_range = &reg_rule->freq_range;
5170 power_rule = &reg_rule->power_rule;
5171
5172 nl_reg_rule = nla_nest_start(msg, i);
5173 if (!nl_reg_rule)
Johannes Berg458f4f92012-12-06 15:47:38 +01005174 goto nla_put_failure_rcu;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005175
Janusz Dziedzic97524822014-01-30 09:52:20 +01005176 max_bandwidth_khz = freq_range->max_bandwidth_khz;
5177 if (!max_bandwidth_khz)
5178 max_bandwidth_khz = reg_get_max_bandwidth(regdom,
5179 reg_rule);
5180
David S. Miller9360ffd2012-03-29 04:41:26 -04005181 if (nla_put_u32(msg, NL80211_ATTR_REG_RULE_FLAGS,
5182 reg_rule->flags) ||
5183 nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_START,
5184 freq_range->start_freq_khz) ||
5185 nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_END,
5186 freq_range->end_freq_khz) ||
5187 nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_MAX_BW,
Janusz Dziedzic97524822014-01-30 09:52:20 +01005188 max_bandwidth_khz) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04005189 nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN,
5190 power_rule->max_antenna_gain) ||
5191 nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_EIRP,
Janusz Dziedzic089027e2014-02-21 19:46:12 +01005192 power_rule->max_eirp) ||
5193 nla_put_u32(msg, NL80211_ATTR_DFS_CAC_TIME,
5194 reg_rule->dfs_cac_ms))
Johannes Berg458f4f92012-12-06 15:47:38 +01005195 goto nla_put_failure_rcu;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005196
5197 nla_nest_end(msg, nl_reg_rule);
5198 }
Johannes Berg458f4f92012-12-06 15:47:38 +01005199 rcu_read_unlock();
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005200
5201 nla_nest_end(msg, nl_reg_rules);
5202
5203 genlmsg_end(msg, hdr);
Johannes Berg5fe231e2013-05-08 21:45:15 +02005204 return genlmsg_reply(msg, info);
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005205
Johannes Berg458f4f92012-12-06 15:47:38 +01005206nla_put_failure_rcu:
5207 rcu_read_unlock();
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005208nla_put_failure:
5209 genlmsg_cancel(msg, hdr);
Julia Lawallefe1cf02011-01-28 15:17:11 +01005210put_failure:
Yuri Ershovd080e272010-06-29 15:08:07 +04005211 nlmsg_free(msg);
Johannes Berg5fe231e2013-05-08 21:45:15 +02005212 return -EMSGSIZE;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005213}
5214
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005215static int nl80211_set_reg(struct sk_buff *skb, struct genl_info *info)
5216{
5217 struct nlattr *tb[NL80211_REG_RULE_ATTR_MAX + 1];
5218 struct nlattr *nl_reg_rule;
5219 char *alpha2 = NULL;
5220 int rem_reg_rules = 0, r = 0;
5221 u32 num_rules = 0, rule_idx = 0, size_of_regd;
Luis R. Rodriguez4c7d3982013-11-13 18:54:02 +01005222 enum nl80211_dfs_regions dfs_region = NL80211_DFS_UNSET;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005223 struct ieee80211_regdomain *rd = NULL;
5224
5225 if (!info->attrs[NL80211_ATTR_REG_ALPHA2])
5226 return -EINVAL;
5227
5228 if (!info->attrs[NL80211_ATTR_REG_RULES])
5229 return -EINVAL;
5230
5231 alpha2 = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]);
5232
Luis R. Rodriguez8b60b072011-10-11 10:59:02 -07005233 if (info->attrs[NL80211_ATTR_DFS_REGION])
5234 dfs_region = nla_get_u8(info->attrs[NL80211_ATTR_DFS_REGION]);
5235
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005236 nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES],
Johannes Berg1a919312012-12-03 17:21:11 +01005237 rem_reg_rules) {
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005238 num_rules++;
5239 if (num_rules > NL80211_MAX_SUPP_REG_RULES)
Luis R. Rodriguez4776c6e2009-05-13 17:04:39 -04005240 return -EINVAL;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005241 }
5242
Luis R. Rodrigueze4387682013-11-05 09:18:01 -08005243 if (!reg_is_valid_request(alpha2))
5244 return -EINVAL;
5245
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005246 size_of_regd = sizeof(struct ieee80211_regdomain) +
Johannes Berg1a919312012-12-03 17:21:11 +01005247 num_rules * sizeof(struct ieee80211_reg_rule);
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005248
5249 rd = kzalloc(size_of_regd, GFP_KERNEL);
Johannes Berg6913b492012-12-04 00:48:59 +01005250 if (!rd)
5251 return -ENOMEM;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005252
5253 rd->n_reg_rules = num_rules;
5254 rd->alpha2[0] = alpha2[0];
5255 rd->alpha2[1] = alpha2[1];
5256
Luis R. Rodriguez8b60b072011-10-11 10:59:02 -07005257 /*
5258 * Disable DFS master mode if the DFS region was
5259 * not supported or known on this kernel.
5260 */
5261 if (reg_supported_dfs_region(dfs_region))
5262 rd->dfs_region = dfs_region;
5263
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005264 nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES],
Johannes Berg1a919312012-12-03 17:21:11 +01005265 rem_reg_rules) {
Johannes Bergae811e22014-01-24 10:17:47 +01005266 r = nla_parse(tb, NL80211_REG_RULE_ATTR_MAX,
5267 nla_data(nl_reg_rule), nla_len(nl_reg_rule),
5268 reg_rule_policy);
5269 if (r)
5270 goto bad_reg;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005271 r = parse_reg_rule(tb, &rd->reg_rules[rule_idx]);
5272 if (r)
5273 goto bad_reg;
5274
5275 rule_idx++;
5276
Luis R. Rodriguezd0e18f82009-05-13 17:04:40 -04005277 if (rule_idx > NL80211_MAX_SUPP_REG_RULES) {
5278 r = -EINVAL;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005279 goto bad_reg;
Luis R. Rodriguezd0e18f82009-05-13 17:04:40 -04005280 }
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005281 }
5282
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005283 r = set_regdom(rd);
Johannes Berg6913b492012-12-04 00:48:59 +01005284 /* set_regdom took ownership */
Johannes Berg1a919312012-12-03 17:21:11 +01005285 rd = NULL;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005286
Johannes Bergd2372b32008-10-24 20:32:20 +02005287 bad_reg:
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005288 kfree(rd);
Luis R. Rodriguezd0e18f82009-05-13 17:04:40 -04005289 return r;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005290}
5291
Johannes Berg83f5e2c2009-06-17 17:41:49 +02005292static int validate_scan_freqs(struct nlattr *freqs)
5293{
5294 struct nlattr *attr1, *attr2;
5295 int n_channels = 0, tmp1, tmp2;
5296
5297 nla_for_each_nested(attr1, freqs, tmp1) {
5298 n_channels++;
5299 /*
5300 * Some hardware has a limited channel list for
5301 * scanning, and it is pretty much nonsensical
5302 * to scan for a channel twice, so disallow that
5303 * and don't require drivers to check that the
5304 * channel list they get isn't longer than what
5305 * they can scan, as long as they can scan all
5306 * the channels they registered at once.
5307 */
5308 nla_for_each_nested(attr2, freqs, tmp2)
5309 if (attr1 != attr2 &&
5310 nla_get_u32(attr1) == nla_get_u32(attr2))
5311 return 0;
5312 }
5313
5314 return n_channels;
5315}
5316
Johannes Berg2a519312009-02-10 21:25:55 +01005317static int nl80211_trigger_scan(struct sk_buff *skb, struct genl_info *info)
5318{
Johannes Berg4c476992010-10-04 21:36:35 +02005319 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Bergfd014282012-06-18 19:17:03 +02005320 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg2a519312009-02-10 21:25:55 +01005321 struct cfg80211_scan_request *request;
Johannes Berg2a519312009-02-10 21:25:55 +01005322 struct nlattr *attr;
5323 struct wiphy *wiphy;
Johannes Berg83f5e2c2009-06-17 17:41:49 +02005324 int err, tmp, n_ssids = 0, n_channels, i;
Jouni Malinen70692ad2009-02-16 19:39:13 +02005325 size_t ie_len;
Johannes Berg2a519312009-02-10 21:25:55 +01005326
Johannes Bergf4a11bb2009-03-27 12:40:28 +01005327 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
5328 return -EINVAL;
5329
Johannes Berg79c97e92009-07-07 03:56:12 +02005330 wiphy = &rdev->wiphy;
Johannes Berg2a519312009-02-10 21:25:55 +01005331
Johannes Berg4c476992010-10-04 21:36:35 +02005332 if (!rdev->ops->scan)
5333 return -EOPNOTSUPP;
Johannes Berg2a519312009-02-10 21:25:55 +01005334
Johannes Bergf9d15d12014-01-22 11:14:19 +02005335 if (rdev->scan_req || rdev->scan_msg) {
Johannes Bergf9f47522013-03-19 15:04:07 +01005336 err = -EBUSY;
5337 goto unlock;
5338 }
Johannes Berg2a519312009-02-10 21:25:55 +01005339
5340 if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
Johannes Berg83f5e2c2009-06-17 17:41:49 +02005341 n_channels = validate_scan_freqs(
5342 info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]);
Johannes Bergf9f47522013-03-19 15:04:07 +01005343 if (!n_channels) {
5344 err = -EINVAL;
5345 goto unlock;
5346 }
Johannes Berg2a519312009-02-10 21:25:55 +01005347 } else {
Ilan Peerbdfbec22014-01-09 11:37:23 +02005348 n_channels = ieee80211_get_num_supported_channels(wiphy);
Johannes Berg2a519312009-02-10 21:25:55 +01005349 }
5350
5351 if (info->attrs[NL80211_ATTR_SCAN_SSIDS])
5352 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp)
5353 n_ssids++;
5354
Johannes Bergf9f47522013-03-19 15:04:07 +01005355 if (n_ssids > wiphy->max_scan_ssids) {
5356 err = -EINVAL;
5357 goto unlock;
5358 }
Johannes Berg2a519312009-02-10 21:25:55 +01005359
Jouni Malinen70692ad2009-02-16 19:39:13 +02005360 if (info->attrs[NL80211_ATTR_IE])
5361 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
5362 else
5363 ie_len = 0;
5364
Johannes Bergf9f47522013-03-19 15:04:07 +01005365 if (ie_len > wiphy->max_scan_ie_len) {
5366 err = -EINVAL;
5367 goto unlock;
5368 }
Johannes Berg18a83652009-03-31 12:12:05 +02005369
Johannes Berg2a519312009-02-10 21:25:55 +01005370 request = kzalloc(sizeof(*request)
Luciano Coelhoa2cd43c2011-05-18 11:42:03 +03005371 + sizeof(*request->ssids) * n_ssids
5372 + sizeof(*request->channels) * n_channels
Jouni Malinen70692ad2009-02-16 19:39:13 +02005373 + ie_len, GFP_KERNEL);
Johannes Bergf9f47522013-03-19 15:04:07 +01005374 if (!request) {
5375 err = -ENOMEM;
5376 goto unlock;
5377 }
Johannes Berg2a519312009-02-10 21:25:55 +01005378
Johannes Berg2a519312009-02-10 21:25:55 +01005379 if (n_ssids)
Johannes Berg5ba63532009-08-07 17:54:07 +02005380 request->ssids = (void *)&request->channels[n_channels];
Johannes Berg2a519312009-02-10 21:25:55 +01005381 request->n_ssids = n_ssids;
Jouni Malinen70692ad2009-02-16 19:39:13 +02005382 if (ie_len) {
5383 if (request->ssids)
5384 request->ie = (void *)(request->ssids + n_ssids);
5385 else
5386 request->ie = (void *)(request->channels + n_channels);
5387 }
Johannes Berg2a519312009-02-10 21:25:55 +01005388
Johannes Berg584991d2009-11-02 13:32:03 +01005389 i = 0;
Johannes Berg2a519312009-02-10 21:25:55 +01005390 if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
5391 /* user specified, bail out if channel not found */
Johannes Berg2a519312009-02-10 21:25:55 +01005392 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_FREQUENCIES], tmp) {
Johannes Berg584991d2009-11-02 13:32:03 +01005393 struct ieee80211_channel *chan;
5394
5395 chan = ieee80211_get_channel(wiphy, nla_get_u32(attr));
5396
5397 if (!chan) {
Johannes Berg2a519312009-02-10 21:25:55 +01005398 err = -EINVAL;
5399 goto out_free;
5400 }
Johannes Berg584991d2009-11-02 13:32:03 +01005401
5402 /* ignore disabled channels */
5403 if (chan->flags & IEEE80211_CHAN_DISABLED)
5404 continue;
5405
5406 request->channels[i] = chan;
Johannes Berg2a519312009-02-10 21:25:55 +01005407 i++;
5408 }
5409 } else {
Johannes Berg34850ab2011-07-18 18:08:35 +02005410 enum ieee80211_band band;
5411
Johannes Berg2a519312009-02-10 21:25:55 +01005412 /* all channels */
Johannes Berg2a519312009-02-10 21:25:55 +01005413 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
5414 int j;
5415 if (!wiphy->bands[band])
5416 continue;
5417 for (j = 0; j < wiphy->bands[band]->n_channels; j++) {
Johannes Berg584991d2009-11-02 13:32:03 +01005418 struct ieee80211_channel *chan;
5419
5420 chan = &wiphy->bands[band]->channels[j];
5421
5422 if (chan->flags & IEEE80211_CHAN_DISABLED)
5423 continue;
5424
5425 request->channels[i] = chan;
Johannes Berg2a519312009-02-10 21:25:55 +01005426 i++;
5427 }
5428 }
5429 }
5430
Johannes Berg584991d2009-11-02 13:32:03 +01005431 if (!i) {
5432 err = -EINVAL;
5433 goto out_free;
5434 }
5435
5436 request->n_channels = i;
5437
Johannes Berg2a519312009-02-10 21:25:55 +01005438 i = 0;
5439 if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) {
5440 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) {
Luciano Coelho57a27e12011-06-07 20:42:26 +03005441 if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) {
Johannes Berg2a519312009-02-10 21:25:55 +01005442 err = -EINVAL;
5443 goto out_free;
5444 }
Luciano Coelho57a27e12011-06-07 20:42:26 +03005445 request->ssids[i].ssid_len = nla_len(attr);
Johannes Berg2a519312009-02-10 21:25:55 +01005446 memcpy(request->ssids[i].ssid, nla_data(attr), nla_len(attr));
Johannes Berg2a519312009-02-10 21:25:55 +01005447 i++;
5448 }
5449 }
5450
Jouni Malinen70692ad2009-02-16 19:39:13 +02005451 if (info->attrs[NL80211_ATTR_IE]) {
5452 request->ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Johannes Bergde95a542009-04-01 11:58:36 +02005453 memcpy((void *)request->ie,
5454 nla_data(info->attrs[NL80211_ATTR_IE]),
Jouni Malinen70692ad2009-02-16 19:39:13 +02005455 request->ie_len);
5456 }
5457
Johannes Berg34850ab2011-07-18 18:08:35 +02005458 for (i = 0; i < IEEE80211_NUM_BANDS; i++)
Johannes Berga401d2b2011-07-20 00:52:16 +02005459 if (wiphy->bands[i])
5460 request->rates[i] =
5461 (1 << wiphy->bands[i]->n_bitrates) - 1;
Johannes Berg34850ab2011-07-18 18:08:35 +02005462
5463 if (info->attrs[NL80211_ATTR_SCAN_SUPP_RATES]) {
5464 nla_for_each_nested(attr,
5465 info->attrs[NL80211_ATTR_SCAN_SUPP_RATES],
5466 tmp) {
5467 enum ieee80211_band band = nla_type(attr);
5468
Dan Carpenter84404622011-07-29 11:52:18 +03005469 if (band < 0 || band >= IEEE80211_NUM_BANDS) {
Johannes Berg34850ab2011-07-18 18:08:35 +02005470 err = -EINVAL;
5471 goto out_free;
5472 }
Felix Fietkau1b09cd82013-11-20 19:40:41 +01005473
5474 if (!wiphy->bands[band])
5475 continue;
5476
Johannes Berg34850ab2011-07-18 18:08:35 +02005477 err = ieee80211_get_ratemask(wiphy->bands[band],
5478 nla_data(attr),
5479 nla_len(attr),
5480 &request->rates[band]);
5481 if (err)
5482 goto out_free;
5483 }
5484 }
5485
Sam Leffler46856bb2012-10-11 21:03:32 -07005486 if (info->attrs[NL80211_ATTR_SCAN_FLAGS]) {
Sam Lefflered4737712012-10-11 21:03:31 -07005487 request->flags = nla_get_u32(
5488 info->attrs[NL80211_ATTR_SCAN_FLAGS]);
Johannes Berg00c3a6e2013-10-26 17:14:38 +02005489 if ((request->flags & NL80211_SCAN_FLAG_LOW_PRIORITY) &&
5490 !(wiphy->features & NL80211_FEATURE_LOW_PRIORITY_SCAN)) {
Sam Leffler46856bb2012-10-11 21:03:32 -07005491 err = -EOPNOTSUPP;
5492 goto out_free;
5493 }
5494 }
Sam Lefflered4737712012-10-11 21:03:31 -07005495
Rajkumar Manoharane9f935e2011-09-25 14:53:30 +05305496 request->no_cck =
5497 nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]);
5498
Johannes Bergfd014282012-06-18 19:17:03 +02005499 request->wdev = wdev;
Johannes Berg79c97e92009-07-07 03:56:12 +02005500 request->wiphy = &rdev->wiphy;
Sam Leffler15d60302012-10-11 21:03:34 -07005501 request->scan_start = jiffies;
Johannes Berg2a519312009-02-10 21:25:55 +01005502
Johannes Berg79c97e92009-07-07 03:56:12 +02005503 rdev->scan_req = request;
Hila Gonene35e4d22012-06-27 17:19:42 +03005504 err = rdev_scan(rdev, request);
Johannes Berg2a519312009-02-10 21:25:55 +01005505
Johannes Berg463d0182009-07-14 00:33:35 +02005506 if (!err) {
Johannes Bergfd014282012-06-18 19:17:03 +02005507 nl80211_send_scan_start(rdev, wdev);
5508 if (wdev->netdev)
5509 dev_hold(wdev->netdev);
Johannes Berg4c476992010-10-04 21:36:35 +02005510 } else {
Johannes Berg2a519312009-02-10 21:25:55 +01005511 out_free:
Johannes Berg79c97e92009-07-07 03:56:12 +02005512 rdev->scan_req = NULL;
Johannes Berg2a519312009-02-10 21:25:55 +01005513 kfree(request);
5514 }
Johannes Berg3b858752009-03-12 09:55:09 +01005515
Johannes Bergf9f47522013-03-19 15:04:07 +01005516 unlock:
Johannes Berg2a519312009-02-10 21:25:55 +01005517 return err;
5518}
5519
Luciano Coelho807f8a82011-05-11 17:09:35 +03005520static int nl80211_start_sched_scan(struct sk_buff *skb,
5521 struct genl_info *info)
5522{
5523 struct cfg80211_sched_scan_request *request;
5524 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5525 struct net_device *dev = info->user_ptr[1];
Luciano Coelho807f8a82011-05-11 17:09:35 +03005526 struct nlattr *attr;
5527 struct wiphy *wiphy;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005528 int err, tmp, n_ssids = 0, n_match_sets = 0, n_channels, i;
Luciano Coelhobbe6ad62011-05-11 17:09:37 +03005529 u32 interval;
Luciano Coelho807f8a82011-05-11 17:09:35 +03005530 enum ieee80211_band band;
5531 size_t ie_len;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005532 struct nlattr *tb[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1];
Johannes Bergea73cbc2014-01-24 10:53:53 +01005533 s32 default_match_rssi = NL80211_SCAN_RSSI_THOLD_OFF;
Luciano Coelho807f8a82011-05-11 17:09:35 +03005534
5535 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) ||
5536 !rdev->ops->sched_scan_start)
5537 return -EOPNOTSUPP;
5538
5539 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
5540 return -EINVAL;
5541
Luciano Coelhobbe6ad62011-05-11 17:09:37 +03005542 if (!info->attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL])
5543 return -EINVAL;
5544
5545 interval = nla_get_u32(info->attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]);
5546 if (interval == 0)
5547 return -EINVAL;
5548
Luciano Coelho807f8a82011-05-11 17:09:35 +03005549 wiphy = &rdev->wiphy;
5550
5551 if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
5552 n_channels = validate_scan_freqs(
5553 info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]);
5554 if (!n_channels)
5555 return -EINVAL;
5556 } else {
Ilan Peerbdfbec22014-01-09 11:37:23 +02005557 n_channels = ieee80211_get_num_supported_channels(wiphy);
Luciano Coelho807f8a82011-05-11 17:09:35 +03005558 }
5559
5560 if (info->attrs[NL80211_ATTR_SCAN_SSIDS])
5561 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS],
5562 tmp)
5563 n_ssids++;
5564
Luciano Coelho93b6aa62011-07-13 14:57:28 +03005565 if (n_ssids > wiphy->max_sched_scan_ssids)
Luciano Coelho807f8a82011-05-11 17:09:35 +03005566 return -EINVAL;
5567
Johannes Bergea73cbc2014-01-24 10:53:53 +01005568 /*
5569 * First, count the number of 'real' matchsets. Due to an issue with
5570 * the old implementation, matchsets containing only the RSSI attribute
5571 * (NL80211_SCHED_SCAN_MATCH_ATTR_RSSI) are considered as the 'default'
5572 * RSSI for all matchsets, rather than their own matchset for reporting
5573 * all APs with a strong RSSI. This is needed to be compatible with
5574 * older userspace that treated a matchset with only the RSSI as the
5575 * global RSSI for all other matchsets - if there are other matchsets.
5576 */
5577 if (info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) {
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005578 nla_for_each_nested(attr,
5579 info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH],
Johannes Bergea73cbc2014-01-24 10:53:53 +01005580 tmp) {
5581 struct nlattr *rssi;
5582
5583 err = nla_parse(tb, NL80211_SCHED_SCAN_MATCH_ATTR_MAX,
5584 nla_data(attr), nla_len(attr),
5585 nl80211_match_policy);
5586 if (err)
5587 return err;
5588 /* add other standalone attributes here */
5589 if (tb[NL80211_SCHED_SCAN_MATCH_ATTR_SSID]) {
5590 n_match_sets++;
5591 continue;
5592 }
5593 rssi = tb[NL80211_SCHED_SCAN_MATCH_ATTR_RSSI];
5594 if (rssi)
5595 default_match_rssi = nla_get_s32(rssi);
5596 }
5597 }
5598
5599 /* However, if there's no other matchset, add the RSSI one */
5600 if (!n_match_sets && default_match_rssi != NL80211_SCAN_RSSI_THOLD_OFF)
5601 n_match_sets = 1;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005602
5603 if (n_match_sets > wiphy->max_match_sets)
5604 return -EINVAL;
5605
Luciano Coelho807f8a82011-05-11 17:09:35 +03005606 if (info->attrs[NL80211_ATTR_IE])
5607 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
5608 else
5609 ie_len = 0;
5610
Luciano Coelho5a865ba2011-07-13 14:57:29 +03005611 if (ie_len > wiphy->max_sched_scan_ie_len)
Luciano Coelho807f8a82011-05-11 17:09:35 +03005612 return -EINVAL;
5613
Luciano Coelhoc10841c2011-06-30 08:32:41 +03005614 if (rdev->sched_scan_req) {
5615 err = -EINPROGRESS;
5616 goto out;
5617 }
5618
Luciano Coelho807f8a82011-05-11 17:09:35 +03005619 request = kzalloc(sizeof(*request)
Luciano Coelhoa2cd43c2011-05-18 11:42:03 +03005620 + sizeof(*request->ssids) * n_ssids
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005621 + sizeof(*request->match_sets) * n_match_sets
Luciano Coelhoa2cd43c2011-05-18 11:42:03 +03005622 + sizeof(*request->channels) * n_channels
Luciano Coelho807f8a82011-05-11 17:09:35 +03005623 + ie_len, GFP_KERNEL);
Luciano Coelhoc10841c2011-06-30 08:32:41 +03005624 if (!request) {
5625 err = -ENOMEM;
5626 goto out;
5627 }
Luciano Coelho807f8a82011-05-11 17:09:35 +03005628
5629 if (n_ssids)
5630 request->ssids = (void *)&request->channels[n_channels];
5631 request->n_ssids = n_ssids;
5632 if (ie_len) {
5633 if (request->ssids)
5634 request->ie = (void *)(request->ssids + n_ssids);
5635 else
5636 request->ie = (void *)(request->channels + n_channels);
5637 }
5638
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005639 if (n_match_sets) {
5640 if (request->ie)
5641 request->match_sets = (void *)(request->ie + ie_len);
5642 else if (request->ssids)
5643 request->match_sets =
5644 (void *)(request->ssids + n_ssids);
5645 else
5646 request->match_sets =
5647 (void *)(request->channels + n_channels);
5648 }
5649 request->n_match_sets = n_match_sets;
5650
Luciano Coelho807f8a82011-05-11 17:09:35 +03005651 i = 0;
5652 if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
5653 /* user specified, bail out if channel not found */
5654 nla_for_each_nested(attr,
5655 info->attrs[NL80211_ATTR_SCAN_FREQUENCIES],
5656 tmp) {
5657 struct ieee80211_channel *chan;
5658
5659 chan = ieee80211_get_channel(wiphy, nla_get_u32(attr));
5660
5661 if (!chan) {
5662 err = -EINVAL;
5663 goto out_free;
5664 }
5665
5666 /* ignore disabled channels */
5667 if (chan->flags & IEEE80211_CHAN_DISABLED)
5668 continue;
5669
5670 request->channels[i] = chan;
5671 i++;
5672 }
5673 } else {
5674 /* all channels */
5675 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
5676 int j;
5677 if (!wiphy->bands[band])
5678 continue;
5679 for (j = 0; j < wiphy->bands[band]->n_channels; j++) {
5680 struct ieee80211_channel *chan;
5681
5682 chan = &wiphy->bands[band]->channels[j];
5683
5684 if (chan->flags & IEEE80211_CHAN_DISABLED)
5685 continue;
5686
5687 request->channels[i] = chan;
5688 i++;
5689 }
5690 }
5691 }
5692
5693 if (!i) {
5694 err = -EINVAL;
5695 goto out_free;
5696 }
5697
5698 request->n_channels = i;
5699
5700 i = 0;
5701 if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) {
5702 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS],
5703 tmp) {
Luciano Coelho57a27e12011-06-07 20:42:26 +03005704 if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) {
Luciano Coelho807f8a82011-05-11 17:09:35 +03005705 err = -EINVAL;
5706 goto out_free;
5707 }
Luciano Coelho57a27e12011-06-07 20:42:26 +03005708 request->ssids[i].ssid_len = nla_len(attr);
Luciano Coelho807f8a82011-05-11 17:09:35 +03005709 memcpy(request->ssids[i].ssid, nla_data(attr),
5710 nla_len(attr));
Luciano Coelho807f8a82011-05-11 17:09:35 +03005711 i++;
5712 }
5713 }
5714
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005715 i = 0;
5716 if (info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) {
5717 nla_for_each_nested(attr,
5718 info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH],
5719 tmp) {
Thomas Pedersen88e920b2012-06-21 11:09:54 -07005720 struct nlattr *ssid, *rssi;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005721
Johannes Bergae811e22014-01-24 10:17:47 +01005722 err = nla_parse(tb, NL80211_SCHED_SCAN_MATCH_ATTR_MAX,
5723 nla_data(attr), nla_len(attr),
5724 nl80211_match_policy);
5725 if (err)
5726 goto out_free;
Johannes Berg4a4ab0d2012-06-13 11:17:11 +02005727 ssid = tb[NL80211_SCHED_SCAN_MATCH_ATTR_SSID];
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005728 if (ssid) {
Johannes Bergea73cbc2014-01-24 10:53:53 +01005729 if (WARN_ON(i >= n_match_sets)) {
5730 /* this indicates a programming error,
5731 * the loop above should have verified
5732 * things properly
5733 */
5734 err = -EINVAL;
5735 goto out_free;
5736 }
5737
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005738 if (nla_len(ssid) > IEEE80211_MAX_SSID_LEN) {
5739 err = -EINVAL;
5740 goto out_free;
5741 }
5742 memcpy(request->match_sets[i].ssid.ssid,
5743 nla_data(ssid), nla_len(ssid));
5744 request->match_sets[i].ssid.ssid_len =
5745 nla_len(ssid);
Johannes Bergea73cbc2014-01-24 10:53:53 +01005746 /* special attribute - old implemenation w/a */
5747 request->match_sets[i].rssi_thold =
5748 default_match_rssi;
5749 rssi = tb[NL80211_SCHED_SCAN_MATCH_ATTR_RSSI];
5750 if (rssi)
5751 request->match_sets[i].rssi_thold =
5752 nla_get_s32(rssi);
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005753 }
5754 i++;
5755 }
Johannes Bergea73cbc2014-01-24 10:53:53 +01005756
5757 /* there was no other matchset, so the RSSI one is alone */
5758 if (i == 0)
5759 request->match_sets[0].rssi_thold = default_match_rssi;
5760
5761 request->min_rssi_thold = INT_MAX;
5762 for (i = 0; i < n_match_sets; i++)
5763 request->min_rssi_thold =
5764 min(request->match_sets[i].rssi_thold,
5765 request->min_rssi_thold);
5766 } else {
5767 request->min_rssi_thold = NL80211_SCAN_RSSI_THOLD_OFF;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005768 }
5769
Johannes Berg9900e482014-02-04 21:01:25 +01005770 if (ie_len) {
5771 request->ie_len = ie_len;
Luciano Coelho807f8a82011-05-11 17:09:35 +03005772 memcpy((void *)request->ie,
5773 nla_data(info->attrs[NL80211_ATTR_IE]),
5774 request->ie_len);
5775 }
5776
Sam Leffler46856bb2012-10-11 21:03:32 -07005777 if (info->attrs[NL80211_ATTR_SCAN_FLAGS]) {
Sam Lefflered4737712012-10-11 21:03:31 -07005778 request->flags = nla_get_u32(
5779 info->attrs[NL80211_ATTR_SCAN_FLAGS]);
Johannes Berg00c3a6e2013-10-26 17:14:38 +02005780 if ((request->flags & NL80211_SCAN_FLAG_LOW_PRIORITY) &&
5781 !(wiphy->features & NL80211_FEATURE_LOW_PRIORITY_SCAN)) {
Sam Leffler46856bb2012-10-11 21:03:32 -07005782 err = -EOPNOTSUPP;
5783 goto out_free;
5784 }
5785 }
Sam Lefflered4737712012-10-11 21:03:31 -07005786
Luciano Coelho807f8a82011-05-11 17:09:35 +03005787 request->dev = dev;
5788 request->wiphy = &rdev->wiphy;
Luciano Coelhobbe6ad62011-05-11 17:09:37 +03005789 request->interval = interval;
Sam Leffler15d60302012-10-11 21:03:34 -07005790 request->scan_start = jiffies;
Luciano Coelho807f8a82011-05-11 17:09:35 +03005791
Hila Gonene35e4d22012-06-27 17:19:42 +03005792 err = rdev_sched_scan_start(rdev, dev, request);
Luciano Coelho807f8a82011-05-11 17:09:35 +03005793 if (!err) {
5794 rdev->sched_scan_req = request;
5795 nl80211_send_sched_scan(rdev, dev,
5796 NL80211_CMD_START_SCHED_SCAN);
5797 goto out;
5798 }
5799
5800out_free:
5801 kfree(request);
5802out:
5803 return err;
5804}
5805
5806static int nl80211_stop_sched_scan(struct sk_buff *skb,
5807 struct genl_info *info)
5808{
5809 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5810
5811 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) ||
5812 !rdev->ops->sched_scan_stop)
5813 return -EOPNOTSUPP;
5814
Johannes Berg5fe231e2013-05-08 21:45:15 +02005815 return __cfg80211_stop_sched_scan(rdev, false);
Luciano Coelho807f8a82011-05-11 17:09:35 +03005816}
5817
Simon Wunderlich04f39042013-02-08 18:16:19 +01005818static int nl80211_start_radar_detection(struct sk_buff *skb,
5819 struct genl_info *info)
5820{
5821 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5822 struct net_device *dev = info->user_ptr[1];
5823 struct wireless_dev *wdev = dev->ieee80211_ptr;
5824 struct cfg80211_chan_def chandef;
Luis R. Rodriguez55f74352013-11-25 20:56:10 +01005825 enum nl80211_dfs_regions dfs_region;
Janusz Dziedzic31559f32014-02-21 19:46:13 +01005826 unsigned int cac_time_ms;
Simon Wunderlich04f39042013-02-08 18:16:19 +01005827 int err;
5828
Luis R. Rodriguez55f74352013-11-25 20:56:10 +01005829 dfs_region = reg_get_dfs_region(wdev->wiphy);
5830 if (dfs_region == NL80211_DFS_UNSET)
5831 return -EINVAL;
5832
Simon Wunderlich04f39042013-02-08 18:16:19 +01005833 err = nl80211_parse_chandef(rdev, info, &chandef);
5834 if (err)
5835 return err;
5836
Simon Wunderlichff311bc2013-09-03 19:43:18 +02005837 if (netif_carrier_ok(dev))
5838 return -EBUSY;
5839
Simon Wunderlich04f39042013-02-08 18:16:19 +01005840 if (wdev->cac_started)
5841 return -EBUSY;
5842
Luciano Coelho2beb6dab2014-02-18 11:40:36 +02005843 err = cfg80211_chandef_dfs_required(wdev->wiphy, &chandef,
Luciano Coelho00ec75f2014-05-15 13:05:39 +03005844 wdev->iftype);
Simon Wunderlich04f39042013-02-08 18:16:19 +01005845 if (err < 0)
5846 return err;
5847
5848 if (err == 0)
5849 return -EINVAL;
5850
Janusz Dziedzicfe7c3a12013-11-05 14:48:48 +01005851 if (!cfg80211_chandef_dfs_usable(wdev->wiphy, &chandef))
Simon Wunderlich04f39042013-02-08 18:16:19 +01005852 return -EINVAL;
5853
5854 if (!rdev->ops->start_radar_detection)
5855 return -EOPNOTSUPP;
5856
Janusz Dziedzic31559f32014-02-21 19:46:13 +01005857 cac_time_ms = cfg80211_chandef_dfs_cac_time(&rdev->wiphy, &chandef);
5858 if (WARN_ON(!cac_time_ms))
5859 cac_time_ms = IEEE80211_DFS_MIN_CAC_TIME_MS;
5860
5861 err = rdev->ops->start_radar_detection(&rdev->wiphy, dev, &chandef,
5862 cac_time_ms);
Simon Wunderlich04f39042013-02-08 18:16:19 +01005863 if (!err) {
Michal Kazior9e0e2962014-01-29 14:22:27 +01005864 wdev->chandef = chandef;
Simon Wunderlich04f39042013-02-08 18:16:19 +01005865 wdev->cac_started = true;
5866 wdev->cac_start_time = jiffies;
Janusz Dziedzic31559f32014-02-21 19:46:13 +01005867 wdev->cac_time_ms = cac_time_ms;
Simon Wunderlich04f39042013-02-08 18:16:19 +01005868 }
Simon Wunderlich04f39042013-02-08 18:16:19 +01005869 return err;
5870}
5871
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02005872static int nl80211_channel_switch(struct sk_buff *skb, struct genl_info *info)
5873{
5874 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5875 struct net_device *dev = info->user_ptr[1];
5876 struct wireless_dev *wdev = dev->ieee80211_ptr;
5877 struct cfg80211_csa_settings params;
5878 /* csa_attrs is defined static to avoid waste of stack size - this
5879 * function is called under RTNL lock, so this should not be a problem.
5880 */
5881 static struct nlattr *csa_attrs[NL80211_ATTR_MAX+1];
5882 u8 radar_detect_width = 0;
5883 int err;
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02005884 bool need_new_beacon = false;
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03005885 int len, i;
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02005886
5887 if (!rdev->ops->channel_switch ||
5888 !(rdev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH))
5889 return -EOPNOTSUPP;
5890
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02005891 switch (dev->ieee80211_ptr->iftype) {
5892 case NL80211_IFTYPE_AP:
5893 case NL80211_IFTYPE_P2P_GO:
5894 need_new_beacon = true;
5895
5896 /* useless if AP is not running */
5897 if (!wdev->beacon_interval)
Johannes Berg1ff79df2014-01-22 10:05:27 +01005898 return -ENOTCONN;
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02005899 break;
5900 case NL80211_IFTYPE_ADHOC:
Johannes Berg1ff79df2014-01-22 10:05:27 +01005901 if (!wdev->ssid_len)
5902 return -ENOTCONN;
5903 break;
Chun-Yeow Yeohc6da6742013-10-14 19:08:28 -07005904 case NL80211_IFTYPE_MESH_POINT:
Johannes Berg1ff79df2014-01-22 10:05:27 +01005905 if (!wdev->mesh_id_len)
5906 return -ENOTCONN;
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02005907 break;
5908 default:
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02005909 return -EOPNOTSUPP;
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02005910 }
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02005911
5912 memset(&params, 0, sizeof(params));
5913
5914 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] ||
5915 !info->attrs[NL80211_ATTR_CH_SWITCH_COUNT])
5916 return -EINVAL;
5917
5918 /* only important for AP, IBSS and mesh create IEs internally */
Andrei Otcheretianskid0a361a2013-10-17 10:52:17 +02005919 if (need_new_beacon && !info->attrs[NL80211_ATTR_CSA_IES])
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02005920 return -EINVAL;
5921
5922 params.count = nla_get_u32(info->attrs[NL80211_ATTR_CH_SWITCH_COUNT]);
5923
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02005924 if (!need_new_beacon)
5925 goto skip_beacons;
5926
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02005927 err = nl80211_parse_beacon(info->attrs, &params.beacon_after);
5928 if (err)
5929 return err;
5930
5931 err = nla_parse_nested(csa_attrs, NL80211_ATTR_MAX,
5932 info->attrs[NL80211_ATTR_CSA_IES],
5933 nl80211_policy);
5934 if (err)
5935 return err;
5936
5937 err = nl80211_parse_beacon(csa_attrs, &params.beacon_csa);
5938 if (err)
5939 return err;
5940
5941 if (!csa_attrs[NL80211_ATTR_CSA_C_OFF_BEACON])
5942 return -EINVAL;
5943
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03005944 len = nla_len(csa_attrs[NL80211_ATTR_CSA_C_OFF_BEACON]);
5945 if (!len || (len % sizeof(u16)))
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02005946 return -EINVAL;
5947
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03005948 params.n_counter_offsets_beacon = len / sizeof(u16);
5949 if (rdev->wiphy.max_num_csa_counters &&
5950 (params.n_counter_offsets_beacon >
5951 rdev->wiphy.max_num_csa_counters))
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02005952 return -EINVAL;
5953
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03005954 params.counter_offsets_beacon =
5955 nla_data(csa_attrs[NL80211_ATTR_CSA_C_OFF_BEACON]);
5956
5957 /* sanity checks - counters should fit and be the same */
5958 for (i = 0; i < params.n_counter_offsets_beacon; i++) {
5959 u16 offset = params.counter_offsets_beacon[i];
5960
5961 if (offset >= params.beacon_csa.tail_len)
5962 return -EINVAL;
5963
5964 if (params.beacon_csa.tail[offset] != params.count)
5965 return -EINVAL;
5966 }
5967
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02005968 if (csa_attrs[NL80211_ATTR_CSA_C_OFF_PRESP]) {
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03005969 len = nla_len(csa_attrs[NL80211_ATTR_CSA_C_OFF_PRESP]);
5970 if (!len || (len % sizeof(u16)))
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02005971 return -EINVAL;
5972
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03005973 params.n_counter_offsets_presp = len / sizeof(u16);
5974 if (rdev->wiphy.max_num_csa_counters &&
5975 (params.n_counter_offsets_beacon >
5976 rdev->wiphy.max_num_csa_counters))
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02005977 return -EINVAL;
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03005978
5979 params.counter_offsets_presp =
5980 nla_data(csa_attrs[NL80211_ATTR_CSA_C_OFF_PRESP]);
5981
5982 /* sanity checks - counters should fit and be the same */
5983 for (i = 0; i < params.n_counter_offsets_presp; i++) {
5984 u16 offset = params.counter_offsets_presp[i];
5985
5986 if (offset >= params.beacon_csa.probe_resp_len)
5987 return -EINVAL;
5988
5989 if (params.beacon_csa.probe_resp[offset] !=
5990 params.count)
5991 return -EINVAL;
5992 }
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02005993 }
5994
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02005995skip_beacons:
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02005996 err = nl80211_parse_chandef(rdev, info, &params.chandef);
5997 if (err)
5998 return err;
5999
Ilan Peer174e0cd2014-02-23 09:13:01 +02006000 if (!cfg80211_reg_can_beacon(&rdev->wiphy, &params.chandef,
6001 wdev->iftype))
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006002 return -EINVAL;
6003
Luciano Coelho2beb6dab2014-02-18 11:40:36 +02006004 err = cfg80211_chandef_dfs_required(wdev->wiphy,
6005 &params.chandef,
6006 wdev->iftype);
6007 if (err < 0)
6008 return err;
6009
6010 if (err > 0) {
6011 radar_detect_width = BIT(params.chandef.width);
6012 params.radar_required = true;
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006013 }
6014
Luciano Coelho73de86a2014-02-13 11:31:59 +02006015 /* TODO: I left this here for now. With channel switch, the
6016 * verification is a bit more complicated, because we only do
6017 * it later when the channel switch really happens.
6018 */
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006019 err = cfg80211_can_use_iftype_chan(rdev, wdev, wdev->iftype,
6020 params.chandef.chan,
6021 CHAN_MODE_SHARED,
6022 radar_detect_width);
6023 if (err)
6024 return err;
6025
6026 if (info->attrs[NL80211_ATTR_CH_SWITCH_BLOCK_TX])
6027 params.block_tx = true;
6028
Simon Wunderlichc56589e2013-11-21 18:19:49 +01006029 wdev_lock(wdev);
6030 err = rdev_channel_switch(rdev, dev, &params);
6031 wdev_unlock(wdev);
6032
6033 return err;
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006034}
6035
Johannes Berg9720bb32011-06-21 09:45:33 +02006036static int nl80211_send_bss(struct sk_buff *msg, struct netlink_callback *cb,
6037 u32 seq, int flags,
Johannes Berg2a519312009-02-10 21:25:55 +01006038 struct cfg80211_registered_device *rdev,
Johannes Berg48ab9052009-07-10 18:42:31 +02006039 struct wireless_dev *wdev,
6040 struct cfg80211_internal_bss *intbss)
Johannes Berg2a519312009-02-10 21:25:55 +01006041{
Johannes Berg48ab9052009-07-10 18:42:31 +02006042 struct cfg80211_bss *res = &intbss->pub;
Johannes Berg9caf0362012-11-29 01:25:20 +01006043 const struct cfg80211_bss_ies *ies;
Johannes Berg2a519312009-02-10 21:25:55 +01006044 void *hdr;
6045 struct nlattr *bss;
Johannes Berg8cef2c92013-02-05 16:54:31 +01006046 bool tsf = false;
Johannes Berg48ab9052009-07-10 18:42:31 +02006047
6048 ASSERT_WDEV_LOCK(wdev);
Johannes Berg2a519312009-02-10 21:25:55 +01006049
Eric W. Biederman15e47302012-09-07 20:12:54 +00006050 hdr = nl80211hdr_put(msg, NETLINK_CB(cb->skb).portid, seq, flags,
Johannes Berg2a519312009-02-10 21:25:55 +01006051 NL80211_CMD_NEW_SCAN_RESULTS);
6052 if (!hdr)
6053 return -1;
6054
Johannes Berg9720bb32011-06-21 09:45:33 +02006055 genl_dump_check_consistent(cb, hdr, &nl80211_fam);
6056
Johannes Berg97990a02013-04-19 01:02:55 +02006057 if (nla_put_u32(msg, NL80211_ATTR_GENERATION, rdev->bss_generation))
6058 goto nla_put_failure;
6059 if (wdev->netdev &&
David S. Miller9360ffd2012-03-29 04:41:26 -04006060 nla_put_u32(msg, NL80211_ATTR_IFINDEX, wdev->netdev->ifindex))
6061 goto nla_put_failure;
Johannes Berg97990a02013-04-19 01:02:55 +02006062 if (nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)))
6063 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01006064
6065 bss = nla_nest_start(msg, NL80211_ATTR_BSS);
6066 if (!bss)
6067 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04006068 if ((!is_zero_ether_addr(res->bssid) &&
Johannes Berg9caf0362012-11-29 01:25:20 +01006069 nla_put(msg, NL80211_BSS_BSSID, ETH_ALEN, res->bssid)))
David S. Miller9360ffd2012-03-29 04:41:26 -04006070 goto nla_put_failure;
Johannes Berg9caf0362012-11-29 01:25:20 +01006071
6072 rcu_read_lock();
6073 ies = rcu_dereference(res->ies);
Johannes Berg8cef2c92013-02-05 16:54:31 +01006074 if (ies) {
6075 if (nla_put_u64(msg, NL80211_BSS_TSF, ies->tsf))
6076 goto fail_unlock_rcu;
6077 tsf = true;
6078 if (ies->len && nla_put(msg, NL80211_BSS_INFORMATION_ELEMENTS,
6079 ies->len, ies->data))
6080 goto fail_unlock_rcu;
Johannes Berg9caf0362012-11-29 01:25:20 +01006081 }
6082 ies = rcu_dereference(res->beacon_ies);
Johannes Berg8cef2c92013-02-05 16:54:31 +01006083 if (ies) {
6084 if (!tsf && nla_put_u64(msg, NL80211_BSS_TSF, ies->tsf))
6085 goto fail_unlock_rcu;
6086 if (ies->len && nla_put(msg, NL80211_BSS_BEACON_IES,
6087 ies->len, ies->data))
6088 goto fail_unlock_rcu;
Johannes Berg9caf0362012-11-29 01:25:20 +01006089 }
6090 rcu_read_unlock();
6091
David S. Miller9360ffd2012-03-29 04:41:26 -04006092 if (res->beacon_interval &&
6093 nla_put_u16(msg, NL80211_BSS_BEACON_INTERVAL, res->beacon_interval))
6094 goto nla_put_failure;
6095 if (nla_put_u16(msg, NL80211_BSS_CAPABILITY, res->capability) ||
6096 nla_put_u32(msg, NL80211_BSS_FREQUENCY, res->channel->center_freq) ||
Simon Wunderlichdcd6eac2013-07-08 16:55:49 +02006097 nla_put_u32(msg, NL80211_BSS_CHAN_WIDTH, res->scan_width) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04006098 nla_put_u32(msg, NL80211_BSS_SEEN_MS_AGO,
6099 jiffies_to_msecs(jiffies - intbss->ts)))
6100 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01006101
Johannes Berg77965c92009-02-18 18:45:06 +01006102 switch (rdev->wiphy.signal_type) {
Johannes Berg2a519312009-02-10 21:25:55 +01006103 case CFG80211_SIGNAL_TYPE_MBM:
David S. Miller9360ffd2012-03-29 04:41:26 -04006104 if (nla_put_u32(msg, NL80211_BSS_SIGNAL_MBM, res->signal))
6105 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01006106 break;
6107 case CFG80211_SIGNAL_TYPE_UNSPEC:
David S. Miller9360ffd2012-03-29 04:41:26 -04006108 if (nla_put_u8(msg, NL80211_BSS_SIGNAL_UNSPEC, res->signal))
6109 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01006110 break;
6111 default:
6112 break;
6113 }
6114
Johannes Berg48ab9052009-07-10 18:42:31 +02006115 switch (wdev->iftype) {
Johannes Berg074ac8d2010-09-16 14:58:22 +02006116 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Berg48ab9052009-07-10 18:42:31 +02006117 case NL80211_IFTYPE_STATION:
David S. Miller9360ffd2012-03-29 04:41:26 -04006118 if (intbss == wdev->current_bss &&
6119 nla_put_u32(msg, NL80211_BSS_STATUS,
6120 NL80211_BSS_STATUS_ASSOCIATED))
6121 goto nla_put_failure;
Johannes Berg48ab9052009-07-10 18:42:31 +02006122 break;
6123 case NL80211_IFTYPE_ADHOC:
David S. Miller9360ffd2012-03-29 04:41:26 -04006124 if (intbss == wdev->current_bss &&
6125 nla_put_u32(msg, NL80211_BSS_STATUS,
6126 NL80211_BSS_STATUS_IBSS_JOINED))
6127 goto nla_put_failure;
Johannes Berg48ab9052009-07-10 18:42:31 +02006128 break;
6129 default:
6130 break;
6131 }
6132
Johannes Berg2a519312009-02-10 21:25:55 +01006133 nla_nest_end(msg, bss);
6134
6135 return genlmsg_end(msg, hdr);
6136
Johannes Berg8cef2c92013-02-05 16:54:31 +01006137 fail_unlock_rcu:
6138 rcu_read_unlock();
Johannes Berg2a519312009-02-10 21:25:55 +01006139 nla_put_failure:
6140 genlmsg_cancel(msg, hdr);
6141 return -EMSGSIZE;
6142}
6143
Johannes Berg97990a02013-04-19 01:02:55 +02006144static int nl80211_dump_scan(struct sk_buff *skb, struct netlink_callback *cb)
Johannes Berg2a519312009-02-10 21:25:55 +01006145{
Johannes Berg48ab9052009-07-10 18:42:31 +02006146 struct cfg80211_registered_device *rdev;
Johannes Berg2a519312009-02-10 21:25:55 +01006147 struct cfg80211_internal_bss *scan;
Johannes Berg48ab9052009-07-10 18:42:31 +02006148 struct wireless_dev *wdev;
Johannes Berg97990a02013-04-19 01:02:55 +02006149 int start = cb->args[2], idx = 0;
Johannes Berg2a519312009-02-10 21:25:55 +01006150 int err;
6151
Johannes Berg97990a02013-04-19 01:02:55 +02006152 err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev);
Johannes Berg67748892010-10-04 21:14:06 +02006153 if (err)
6154 return err;
Johannes Berg2a519312009-02-10 21:25:55 +01006155
Johannes Berg48ab9052009-07-10 18:42:31 +02006156 wdev_lock(wdev);
6157 spin_lock_bh(&rdev->bss_lock);
6158 cfg80211_bss_expire(rdev);
6159
Johannes Berg9720bb32011-06-21 09:45:33 +02006160 cb->seq = rdev->bss_generation;
6161
Johannes Berg48ab9052009-07-10 18:42:31 +02006162 list_for_each_entry(scan, &rdev->bss_list, list) {
Johannes Berg2a519312009-02-10 21:25:55 +01006163 if (++idx <= start)
6164 continue;
Johannes Berg9720bb32011-06-21 09:45:33 +02006165 if (nl80211_send_bss(skb, cb,
Johannes Berg2a519312009-02-10 21:25:55 +01006166 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Johannes Berg48ab9052009-07-10 18:42:31 +02006167 rdev, wdev, scan) < 0) {
Johannes Berg2a519312009-02-10 21:25:55 +01006168 idx--;
Johannes Berg67748892010-10-04 21:14:06 +02006169 break;
Johannes Berg2a519312009-02-10 21:25:55 +01006170 }
6171 }
6172
Johannes Berg48ab9052009-07-10 18:42:31 +02006173 spin_unlock_bh(&rdev->bss_lock);
6174 wdev_unlock(wdev);
Johannes Berg2a519312009-02-10 21:25:55 +01006175
Johannes Berg97990a02013-04-19 01:02:55 +02006176 cb->args[2] = idx;
6177 nl80211_finish_wdev_dump(rdev);
Johannes Berg2a519312009-02-10 21:25:55 +01006178
Johannes Berg67748892010-10-04 21:14:06 +02006179 return skb->len;
Johannes Berg2a519312009-02-10 21:25:55 +01006180}
6181
Eric W. Biederman15e47302012-09-07 20:12:54 +00006182static int nl80211_send_survey(struct sk_buff *msg, u32 portid, u32 seq,
Holger Schurig61fa7132009-11-11 12:25:40 +01006183 int flags, struct net_device *dev,
6184 struct survey_info *survey)
6185{
6186 void *hdr;
6187 struct nlattr *infoattr;
6188
Eric W. Biederman15e47302012-09-07 20:12:54 +00006189 hdr = nl80211hdr_put(msg, portid, seq, flags,
Holger Schurig61fa7132009-11-11 12:25:40 +01006190 NL80211_CMD_NEW_SURVEY_RESULTS);
6191 if (!hdr)
6192 return -ENOMEM;
6193
David S. Miller9360ffd2012-03-29 04:41:26 -04006194 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex))
6195 goto nla_put_failure;
Holger Schurig61fa7132009-11-11 12:25:40 +01006196
6197 infoattr = nla_nest_start(msg, NL80211_ATTR_SURVEY_INFO);
6198 if (!infoattr)
6199 goto nla_put_failure;
6200
David S. Miller9360ffd2012-03-29 04:41:26 -04006201 if (nla_put_u32(msg, NL80211_SURVEY_INFO_FREQUENCY,
6202 survey->channel->center_freq))
6203 goto nla_put_failure;
6204
6205 if ((survey->filled & SURVEY_INFO_NOISE_DBM) &&
6206 nla_put_u8(msg, NL80211_SURVEY_INFO_NOISE, survey->noise))
6207 goto nla_put_failure;
6208 if ((survey->filled & SURVEY_INFO_IN_USE) &&
6209 nla_put_flag(msg, NL80211_SURVEY_INFO_IN_USE))
6210 goto nla_put_failure;
6211 if ((survey->filled & SURVEY_INFO_CHANNEL_TIME) &&
6212 nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME,
6213 survey->channel_time))
6214 goto nla_put_failure;
6215 if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_BUSY) &&
6216 nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_BUSY,
6217 survey->channel_time_busy))
6218 goto nla_put_failure;
6219 if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_EXT_BUSY) &&
6220 nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_EXT_BUSY,
6221 survey->channel_time_ext_busy))
6222 goto nla_put_failure;
6223 if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_RX) &&
6224 nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_RX,
6225 survey->channel_time_rx))
6226 goto nla_put_failure;
6227 if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_TX) &&
6228 nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_TX,
6229 survey->channel_time_tx))
6230 goto nla_put_failure;
Holger Schurig61fa7132009-11-11 12:25:40 +01006231
6232 nla_nest_end(msg, infoattr);
6233
6234 return genlmsg_end(msg, hdr);
6235
6236 nla_put_failure:
6237 genlmsg_cancel(msg, hdr);
6238 return -EMSGSIZE;
6239}
6240
6241static int nl80211_dump_survey(struct sk_buff *skb,
6242 struct netlink_callback *cb)
6243{
6244 struct survey_info survey;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08006245 struct cfg80211_registered_device *rdev;
Johannes Berg97990a02013-04-19 01:02:55 +02006246 struct wireless_dev *wdev;
6247 int survey_idx = cb->args[2];
Holger Schurig61fa7132009-11-11 12:25:40 +01006248 int res;
6249
Zhao, Gang1b8ec872014-04-21 12:53:02 +08006250 res = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev);
Johannes Berg67748892010-10-04 21:14:06 +02006251 if (res)
6252 return res;
Holger Schurig61fa7132009-11-11 12:25:40 +01006253
Johannes Berg97990a02013-04-19 01:02:55 +02006254 if (!wdev->netdev) {
6255 res = -EINVAL;
6256 goto out_err;
6257 }
6258
Zhao, Gang1b8ec872014-04-21 12:53:02 +08006259 if (!rdev->ops->dump_survey) {
Holger Schurig61fa7132009-11-11 12:25:40 +01006260 res = -EOPNOTSUPP;
6261 goto out_err;
6262 }
6263
6264 while (1) {
Luis R. Rodriguez180cdc72011-05-27 07:24:02 -07006265 struct ieee80211_channel *chan;
6266
Zhao, Gang1b8ec872014-04-21 12:53:02 +08006267 res = rdev_dump_survey(rdev, wdev->netdev, survey_idx, &survey);
Holger Schurig61fa7132009-11-11 12:25:40 +01006268 if (res == -ENOENT)
6269 break;
6270 if (res)
6271 goto out_err;
6272
Luis R. Rodriguez180cdc72011-05-27 07:24:02 -07006273 /* Survey without a channel doesn't make sense */
6274 if (!survey.channel) {
6275 res = -EINVAL;
6276 goto out;
6277 }
6278
Zhao, Gang1b8ec872014-04-21 12:53:02 +08006279 chan = ieee80211_get_channel(&rdev->wiphy,
Luis R. Rodriguez180cdc72011-05-27 07:24:02 -07006280 survey.channel->center_freq);
6281 if (!chan || chan->flags & IEEE80211_CHAN_DISABLED) {
6282 survey_idx++;
6283 continue;
6284 }
6285
Holger Schurig61fa7132009-11-11 12:25:40 +01006286 if (nl80211_send_survey(skb,
Eric W. Biederman15e47302012-09-07 20:12:54 +00006287 NETLINK_CB(cb->skb).portid,
Holger Schurig61fa7132009-11-11 12:25:40 +01006288 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Johannes Berg97990a02013-04-19 01:02:55 +02006289 wdev->netdev, &survey) < 0)
Holger Schurig61fa7132009-11-11 12:25:40 +01006290 goto out;
6291 survey_idx++;
6292 }
6293
6294 out:
Johannes Berg97990a02013-04-19 01:02:55 +02006295 cb->args[2] = survey_idx;
Holger Schurig61fa7132009-11-11 12:25:40 +01006296 res = skb->len;
6297 out_err:
Zhao, Gang1b8ec872014-04-21 12:53:02 +08006298 nl80211_finish_wdev_dump(rdev);
Holger Schurig61fa7132009-11-11 12:25:40 +01006299 return res;
6300}
6301
Samuel Ortizb23aa672009-07-01 21:26:54 +02006302static bool nl80211_valid_wpa_versions(u32 wpa_versions)
6303{
6304 return !(wpa_versions & ~(NL80211_WPA_VERSION_1 |
6305 NL80211_WPA_VERSION_2));
6306}
6307
Jouni Malinen636a5d32009-03-19 13:39:22 +02006308static int nl80211_authenticate(struct sk_buff *skb, struct genl_info *info)
6309{
Johannes Berg4c476992010-10-04 21:36:35 +02006310 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6311 struct net_device *dev = info->user_ptr[1];
Johannes Berg19957bb2009-07-02 17:20:43 +02006312 struct ieee80211_channel *chan;
Jouni Malinene39e5b52012-09-30 19:29:39 +03006313 const u8 *bssid, *ssid, *ie = NULL, *sae_data = NULL;
6314 int err, ssid_len, ie_len = 0, sae_data_len = 0;
Johannes Berg19957bb2009-07-02 17:20:43 +02006315 enum nl80211_auth_type auth_type;
Johannes Bergfffd0932009-07-08 14:22:54 +02006316 struct key_parse key;
Jouni Malinend5cdfac2010-04-04 09:37:19 +03006317 bool local_state_change;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006318
Johannes Bergf4a11bb2009-03-27 12:40:28 +01006319 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
6320 return -EINVAL;
6321
6322 if (!info->attrs[NL80211_ATTR_MAC])
6323 return -EINVAL;
6324
Jouni Malinen17780922009-03-27 20:52:47 +02006325 if (!info->attrs[NL80211_ATTR_AUTH_TYPE])
6326 return -EINVAL;
6327
Johannes Berg19957bb2009-07-02 17:20:43 +02006328 if (!info->attrs[NL80211_ATTR_SSID])
6329 return -EINVAL;
6330
6331 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ])
6332 return -EINVAL;
6333
Johannes Bergfffd0932009-07-08 14:22:54 +02006334 err = nl80211_parse_key(info, &key);
6335 if (err)
6336 return err;
6337
6338 if (key.idx >= 0) {
Johannes Berge31b8212010-10-05 19:39:30 +02006339 if (key.type != -1 && key.type != NL80211_KEYTYPE_GROUP)
6340 return -EINVAL;
Johannes Bergfffd0932009-07-08 14:22:54 +02006341 if (!key.p.key || !key.p.key_len)
6342 return -EINVAL;
6343 if ((key.p.cipher != WLAN_CIPHER_SUITE_WEP40 ||
6344 key.p.key_len != WLAN_KEY_LEN_WEP40) &&
6345 (key.p.cipher != WLAN_CIPHER_SUITE_WEP104 ||
6346 key.p.key_len != WLAN_KEY_LEN_WEP104))
6347 return -EINVAL;
6348 if (key.idx > 4)
6349 return -EINVAL;
6350 } else {
6351 key.p.key_len = 0;
6352 key.p.key = NULL;
6353 }
6354
Johannes Bergafea0b72010-08-10 09:46:42 +02006355 if (key.idx >= 0) {
6356 int i;
6357 bool ok = false;
6358 for (i = 0; i < rdev->wiphy.n_cipher_suites; i++) {
6359 if (key.p.cipher == rdev->wiphy.cipher_suites[i]) {
6360 ok = true;
6361 break;
6362 }
6363 }
Johannes Berg4c476992010-10-04 21:36:35 +02006364 if (!ok)
6365 return -EINVAL;
Johannes Bergafea0b72010-08-10 09:46:42 +02006366 }
6367
Johannes Berg4c476992010-10-04 21:36:35 +02006368 if (!rdev->ops->auth)
6369 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006370
Johannes Berg074ac8d2010-09-16 14:58:22 +02006371 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02006372 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
6373 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02006374
Johannes Berg19957bb2009-07-02 17:20:43 +02006375 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen664834d2014-01-15 00:01:44 +02006376 chan = nl80211_get_valid_chan(&rdev->wiphy,
6377 info->attrs[NL80211_ATTR_WIPHY_FREQ]);
6378 if (!chan)
Johannes Berg4c476992010-10-04 21:36:35 +02006379 return -EINVAL;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006380
Johannes Berg19957bb2009-07-02 17:20:43 +02006381 ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
6382 ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
6383
6384 if (info->attrs[NL80211_ATTR_IE]) {
6385 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
6386 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
6387 }
6388
6389 auth_type = nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]);
Jouni Malinene39e5b52012-09-30 19:29:39 +03006390 if (!nl80211_valid_auth_type(rdev, auth_type, NL80211_CMD_AUTHENTICATE))
Johannes Berg4c476992010-10-04 21:36:35 +02006391 return -EINVAL;
Johannes Berg19957bb2009-07-02 17:20:43 +02006392
Jouni Malinene39e5b52012-09-30 19:29:39 +03006393 if (auth_type == NL80211_AUTHTYPE_SAE &&
6394 !info->attrs[NL80211_ATTR_SAE_DATA])
6395 return -EINVAL;
6396
6397 if (info->attrs[NL80211_ATTR_SAE_DATA]) {
6398 if (auth_type != NL80211_AUTHTYPE_SAE)
6399 return -EINVAL;
6400 sae_data = nla_data(info->attrs[NL80211_ATTR_SAE_DATA]);
6401 sae_data_len = nla_len(info->attrs[NL80211_ATTR_SAE_DATA]);
6402 /* need to include at least Auth Transaction and Status Code */
6403 if (sae_data_len < 4)
6404 return -EINVAL;
6405 }
6406
Jouni Malinend5cdfac2010-04-04 09:37:19 +03006407 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE];
6408
Johannes Berg95de8172012-01-20 13:55:25 +01006409 /*
6410 * Since we no longer track auth state, ignore
6411 * requests to only change local state.
6412 */
6413 if (local_state_change)
6414 return 0;
6415
Johannes Berg91bf9b22013-05-15 17:44:01 +02006416 wdev_lock(dev->ieee80211_ptr);
6417 err = cfg80211_mlme_auth(rdev, dev, chan, auth_type, bssid,
6418 ssid, ssid_len, ie, ie_len,
6419 key.p.key, key.p.key_len, key.idx,
6420 sae_data, sae_data_len);
6421 wdev_unlock(dev->ieee80211_ptr);
6422 return err;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006423}
6424
Johannes Bergc0692b82010-08-27 14:26:53 +03006425static int nl80211_crypto_settings(struct cfg80211_registered_device *rdev,
6426 struct genl_info *info,
Johannes Berg3dc27d22009-07-02 21:36:37 +02006427 struct cfg80211_crypto_settings *settings,
6428 int cipher_limit)
Samuel Ortizb23aa672009-07-01 21:26:54 +02006429{
Johannes Bergc0b2bbd2009-07-25 16:54:36 +02006430 memset(settings, 0, sizeof(*settings));
6431
Samuel Ortizb23aa672009-07-01 21:26:54 +02006432 settings->control_port = info->attrs[NL80211_ATTR_CONTROL_PORT];
6433
Johannes Bergc0692b82010-08-27 14:26:53 +03006434 if (info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]) {
6435 u16 proto;
6436 proto = nla_get_u16(
6437 info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]);
6438 settings->control_port_ethertype = cpu_to_be16(proto);
6439 if (!(rdev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) &&
6440 proto != ETH_P_PAE)
6441 return -EINVAL;
6442 if (info->attrs[NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT])
6443 settings->control_port_no_encrypt = true;
6444 } else
6445 settings->control_port_ethertype = cpu_to_be16(ETH_P_PAE);
6446
Samuel Ortizb23aa672009-07-01 21:26:54 +02006447 if (info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]) {
6448 void *data;
6449 int len, i;
6450
6451 data = nla_data(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]);
6452 len = nla_len(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]);
6453 settings->n_ciphers_pairwise = len / sizeof(u32);
6454
6455 if (len % sizeof(u32))
6456 return -EINVAL;
6457
Johannes Berg3dc27d22009-07-02 21:36:37 +02006458 if (settings->n_ciphers_pairwise > cipher_limit)
Samuel Ortizb23aa672009-07-01 21:26:54 +02006459 return -EINVAL;
6460
6461 memcpy(settings->ciphers_pairwise, data, len);
6462
6463 for (i = 0; i < settings->n_ciphers_pairwise; i++)
Jouni Malinen38ba3c52011-09-21 18:14:56 +03006464 if (!cfg80211_supported_cipher_suite(
6465 &rdev->wiphy,
Samuel Ortizb23aa672009-07-01 21:26:54 +02006466 settings->ciphers_pairwise[i]))
6467 return -EINVAL;
6468 }
6469
6470 if (info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]) {
6471 settings->cipher_group =
6472 nla_get_u32(info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]);
Jouni Malinen38ba3c52011-09-21 18:14:56 +03006473 if (!cfg80211_supported_cipher_suite(&rdev->wiphy,
6474 settings->cipher_group))
Samuel Ortizb23aa672009-07-01 21:26:54 +02006475 return -EINVAL;
6476 }
6477
6478 if (info->attrs[NL80211_ATTR_WPA_VERSIONS]) {
6479 settings->wpa_versions =
6480 nla_get_u32(info->attrs[NL80211_ATTR_WPA_VERSIONS]);
6481 if (!nl80211_valid_wpa_versions(settings->wpa_versions))
6482 return -EINVAL;
6483 }
6484
6485 if (info->attrs[NL80211_ATTR_AKM_SUITES]) {
6486 void *data;
Jouni Malinen6d302402011-09-21 18:11:33 +03006487 int len;
Samuel Ortizb23aa672009-07-01 21:26:54 +02006488
6489 data = nla_data(info->attrs[NL80211_ATTR_AKM_SUITES]);
6490 len = nla_len(info->attrs[NL80211_ATTR_AKM_SUITES]);
6491 settings->n_akm_suites = len / sizeof(u32);
6492
6493 if (len % sizeof(u32))
6494 return -EINVAL;
6495
Jouni Malinen1b9ca022011-09-21 16:13:07 +03006496 if (settings->n_akm_suites > NL80211_MAX_NR_AKM_SUITES)
6497 return -EINVAL;
6498
Samuel Ortizb23aa672009-07-01 21:26:54 +02006499 memcpy(settings->akm_suites, data, len);
Samuel Ortizb23aa672009-07-01 21:26:54 +02006500 }
6501
6502 return 0;
6503}
6504
Jouni Malinen636a5d32009-03-19 13:39:22 +02006505static int nl80211_associate(struct sk_buff *skb, struct genl_info *info)
6506{
Johannes Berg4c476992010-10-04 21:36:35 +02006507 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6508 struct net_device *dev = info->user_ptr[1];
Johannes Bergf444de02010-05-05 15:25:02 +02006509 struct ieee80211_channel *chan;
Johannes Bergf62fab72013-02-21 20:09:09 +01006510 struct cfg80211_assoc_request req = {};
6511 const u8 *bssid, *ssid;
6512 int err, ssid_len = 0;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006513
Johannes Bergf4a11bb2009-03-27 12:40:28 +01006514 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
6515 return -EINVAL;
6516
6517 if (!info->attrs[NL80211_ATTR_MAC] ||
Johannes Berg19957bb2009-07-02 17:20:43 +02006518 !info->attrs[NL80211_ATTR_SSID] ||
6519 !info->attrs[NL80211_ATTR_WIPHY_FREQ])
Johannes Bergf4a11bb2009-03-27 12:40:28 +01006520 return -EINVAL;
6521
Johannes Berg4c476992010-10-04 21:36:35 +02006522 if (!rdev->ops->assoc)
6523 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006524
Johannes Berg074ac8d2010-09-16 14:58:22 +02006525 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02006526 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
6527 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02006528
Johannes Berg19957bb2009-07-02 17:20:43 +02006529 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02006530
Jouni Malinen664834d2014-01-15 00:01:44 +02006531 chan = nl80211_get_valid_chan(&rdev->wiphy,
6532 info->attrs[NL80211_ATTR_WIPHY_FREQ]);
6533 if (!chan)
Johannes Berg4c476992010-10-04 21:36:35 +02006534 return -EINVAL;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006535
Johannes Berg19957bb2009-07-02 17:20:43 +02006536 ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
6537 ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02006538
6539 if (info->attrs[NL80211_ATTR_IE]) {
Johannes Bergf62fab72013-02-21 20:09:09 +01006540 req.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
6541 req.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02006542 }
6543
Jouni Malinendc6382c2009-05-06 22:09:37 +03006544 if (info->attrs[NL80211_ATTR_USE_MFP]) {
Johannes Berg4f5dadc2009-07-07 03:56:10 +02006545 enum nl80211_mfp mfp =
Jouni Malinendc6382c2009-05-06 22:09:37 +03006546 nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]);
Johannes Berg4f5dadc2009-07-07 03:56:10 +02006547 if (mfp == NL80211_MFP_REQUIRED)
Johannes Bergf62fab72013-02-21 20:09:09 +01006548 req.use_mfp = true;
Johannes Berg4c476992010-10-04 21:36:35 +02006549 else if (mfp != NL80211_MFP_NO)
6550 return -EINVAL;
Jouni Malinendc6382c2009-05-06 22:09:37 +03006551 }
6552
Johannes Berg3e5d7642009-07-07 14:37:26 +02006553 if (info->attrs[NL80211_ATTR_PREV_BSSID])
Johannes Bergf62fab72013-02-21 20:09:09 +01006554 req.prev_bssid = nla_data(info->attrs[NL80211_ATTR_PREV_BSSID]);
Johannes Berg3e5d7642009-07-07 14:37:26 +02006555
Ben Greear7e7c8922011-11-18 11:31:59 -08006556 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT]))
Johannes Bergf62fab72013-02-21 20:09:09 +01006557 req.flags |= ASSOC_REQ_DISABLE_HT;
Ben Greear7e7c8922011-11-18 11:31:59 -08006558
6559 if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
Johannes Bergf62fab72013-02-21 20:09:09 +01006560 memcpy(&req.ht_capa_mask,
6561 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]),
6562 sizeof(req.ht_capa_mask));
Ben Greear7e7c8922011-11-18 11:31:59 -08006563
6564 if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) {
Johannes Bergf62fab72013-02-21 20:09:09 +01006565 if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
Ben Greear7e7c8922011-11-18 11:31:59 -08006566 return -EINVAL;
Johannes Bergf62fab72013-02-21 20:09:09 +01006567 memcpy(&req.ht_capa,
6568 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]),
6569 sizeof(req.ht_capa));
Ben Greear7e7c8922011-11-18 11:31:59 -08006570 }
6571
Johannes Bergee2aca32013-02-21 17:36:01 +01006572 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_VHT]))
Johannes Bergf62fab72013-02-21 20:09:09 +01006573 req.flags |= ASSOC_REQ_DISABLE_VHT;
Johannes Bergee2aca32013-02-21 17:36:01 +01006574
6575 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK])
Johannes Bergf62fab72013-02-21 20:09:09 +01006576 memcpy(&req.vht_capa_mask,
6577 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]),
6578 sizeof(req.vht_capa_mask));
Johannes Bergee2aca32013-02-21 17:36:01 +01006579
6580 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) {
Johannes Bergf62fab72013-02-21 20:09:09 +01006581 if (!info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK])
Johannes Bergee2aca32013-02-21 17:36:01 +01006582 return -EINVAL;
Johannes Bergf62fab72013-02-21 20:09:09 +01006583 memcpy(&req.vht_capa,
6584 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]),
6585 sizeof(req.vht_capa));
Johannes Bergee2aca32013-02-21 17:36:01 +01006586 }
6587
Johannes Bergf62fab72013-02-21 20:09:09 +01006588 err = nl80211_crypto_settings(rdev, info, &req.crypto, 1);
Johannes Berg91bf9b22013-05-15 17:44:01 +02006589 if (!err) {
6590 wdev_lock(dev->ieee80211_ptr);
Johannes Bergf62fab72013-02-21 20:09:09 +01006591 err = cfg80211_mlme_assoc(rdev, dev, chan, bssid,
6592 ssid, ssid_len, &req);
Johannes Berg91bf9b22013-05-15 17:44:01 +02006593 wdev_unlock(dev->ieee80211_ptr);
6594 }
Jouni Malinen636a5d32009-03-19 13:39:22 +02006595
Jouni Malinen636a5d32009-03-19 13:39:22 +02006596 return err;
6597}
6598
6599static int nl80211_deauthenticate(struct sk_buff *skb, struct genl_info *info)
6600{
Johannes Berg4c476992010-10-04 21:36:35 +02006601 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6602 struct net_device *dev = info->user_ptr[1];
Johannes Berg19957bb2009-07-02 17:20:43 +02006603 const u8 *ie = NULL, *bssid;
Johannes Berg91bf9b22013-05-15 17:44:01 +02006604 int ie_len = 0, err;
Johannes Berg19957bb2009-07-02 17:20:43 +02006605 u16 reason_code;
Jouni Malinend5cdfac2010-04-04 09:37:19 +03006606 bool local_state_change;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006607
Johannes Bergf4a11bb2009-03-27 12:40:28 +01006608 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
6609 return -EINVAL;
6610
6611 if (!info->attrs[NL80211_ATTR_MAC])
6612 return -EINVAL;
6613
6614 if (!info->attrs[NL80211_ATTR_REASON_CODE])
6615 return -EINVAL;
6616
Johannes Berg4c476992010-10-04 21:36:35 +02006617 if (!rdev->ops->deauth)
6618 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006619
Johannes Berg074ac8d2010-09-16 14:58:22 +02006620 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02006621 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
6622 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02006623
Johannes Berg19957bb2009-07-02 17:20:43 +02006624 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02006625
Johannes Berg19957bb2009-07-02 17:20:43 +02006626 reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
6627 if (reason_code == 0) {
Johannes Bergf4a11bb2009-03-27 12:40:28 +01006628 /* Reason Code 0 is reserved */
Johannes Berg4c476992010-10-04 21:36:35 +02006629 return -EINVAL;
Jouni Malinen255e7372009-03-20 21:21:17 +02006630 }
Jouni Malinen636a5d32009-03-19 13:39:22 +02006631
6632 if (info->attrs[NL80211_ATTR_IE]) {
Johannes Berg19957bb2009-07-02 17:20:43 +02006633 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
6634 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02006635 }
6636
Jouni Malinend5cdfac2010-04-04 09:37:19 +03006637 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE];
6638
Johannes Berg91bf9b22013-05-15 17:44:01 +02006639 wdev_lock(dev->ieee80211_ptr);
6640 err = cfg80211_mlme_deauth(rdev, dev, bssid, ie, ie_len, reason_code,
6641 local_state_change);
6642 wdev_unlock(dev->ieee80211_ptr);
6643 return err;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006644}
6645
6646static int nl80211_disassociate(struct sk_buff *skb, struct genl_info *info)
6647{
Johannes Berg4c476992010-10-04 21:36:35 +02006648 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6649 struct net_device *dev = info->user_ptr[1];
Johannes Berg19957bb2009-07-02 17:20:43 +02006650 const u8 *ie = NULL, *bssid;
Johannes Berg91bf9b22013-05-15 17:44:01 +02006651 int ie_len = 0, err;
Johannes Berg19957bb2009-07-02 17:20:43 +02006652 u16 reason_code;
Jouni Malinend5cdfac2010-04-04 09:37:19 +03006653 bool local_state_change;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006654
Johannes Bergf4a11bb2009-03-27 12:40:28 +01006655 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
6656 return -EINVAL;
6657
6658 if (!info->attrs[NL80211_ATTR_MAC])
6659 return -EINVAL;
6660
6661 if (!info->attrs[NL80211_ATTR_REASON_CODE])
6662 return -EINVAL;
6663
Johannes Berg4c476992010-10-04 21:36:35 +02006664 if (!rdev->ops->disassoc)
6665 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006666
Johannes Berg074ac8d2010-09-16 14:58:22 +02006667 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02006668 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
6669 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02006670
Johannes Berg19957bb2009-07-02 17:20:43 +02006671 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02006672
Johannes Berg19957bb2009-07-02 17:20:43 +02006673 reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
6674 if (reason_code == 0) {
Johannes Bergf4a11bb2009-03-27 12:40:28 +01006675 /* Reason Code 0 is reserved */
Johannes Berg4c476992010-10-04 21:36:35 +02006676 return -EINVAL;
Jouni Malinen255e7372009-03-20 21:21:17 +02006677 }
Jouni Malinen636a5d32009-03-19 13:39:22 +02006678
6679 if (info->attrs[NL80211_ATTR_IE]) {
Johannes Berg19957bb2009-07-02 17:20:43 +02006680 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
6681 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02006682 }
6683
Jouni Malinend5cdfac2010-04-04 09:37:19 +03006684 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE];
6685
Johannes Berg91bf9b22013-05-15 17:44:01 +02006686 wdev_lock(dev->ieee80211_ptr);
6687 err = cfg80211_mlme_disassoc(rdev, dev, bssid, ie, ie_len, reason_code,
6688 local_state_change);
6689 wdev_unlock(dev->ieee80211_ptr);
6690 return err;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006691}
6692
Felix Fietkaudd5b4cc2010-11-22 20:58:24 +01006693static bool
6694nl80211_parse_mcast_rate(struct cfg80211_registered_device *rdev,
6695 int mcast_rate[IEEE80211_NUM_BANDS],
6696 int rateval)
6697{
6698 struct wiphy *wiphy = &rdev->wiphy;
6699 bool found = false;
6700 int band, i;
6701
6702 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
6703 struct ieee80211_supported_band *sband;
6704
6705 sband = wiphy->bands[band];
6706 if (!sband)
6707 continue;
6708
6709 for (i = 0; i < sband->n_bitrates; i++) {
6710 if (sband->bitrates[i].bitrate == rateval) {
6711 mcast_rate[band] = i + 1;
6712 found = true;
6713 break;
6714 }
6715 }
6716 }
6717
6718 return found;
6719}
6720
Johannes Berg04a773a2009-04-19 21:24:32 +02006721static int nl80211_join_ibss(struct sk_buff *skb, struct genl_info *info)
6722{
Johannes Berg4c476992010-10-04 21:36:35 +02006723 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6724 struct net_device *dev = info->user_ptr[1];
Johannes Berg04a773a2009-04-19 21:24:32 +02006725 struct cfg80211_ibss_params ibss;
6726 struct wiphy *wiphy;
Johannes Bergfffd0932009-07-08 14:22:54 +02006727 struct cfg80211_cached_keys *connkeys = NULL;
Johannes Berg04a773a2009-04-19 21:24:32 +02006728 int err;
6729
Johannes Berg8e30bc52009-04-22 17:45:38 +02006730 memset(&ibss, 0, sizeof(ibss));
6731
Johannes Berg04a773a2009-04-19 21:24:32 +02006732 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
6733 return -EINVAL;
6734
Johannes Berg683b6d32012-11-08 21:25:48 +01006735 if (!info->attrs[NL80211_ATTR_SSID] ||
Johannes Berg04a773a2009-04-19 21:24:32 +02006736 !nla_len(info->attrs[NL80211_ATTR_SSID]))
6737 return -EINVAL;
6738
Johannes Berg8e30bc52009-04-22 17:45:38 +02006739 ibss.beacon_interval = 100;
6740
6741 if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) {
6742 ibss.beacon_interval =
6743 nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]);
6744 if (ibss.beacon_interval < 1 || ibss.beacon_interval > 10000)
6745 return -EINVAL;
6746 }
6747
Johannes Berg4c476992010-10-04 21:36:35 +02006748 if (!rdev->ops->join_ibss)
6749 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02006750
Johannes Berg4c476992010-10-04 21:36:35 +02006751 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC)
6752 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02006753
Johannes Berg79c97e92009-07-07 03:56:12 +02006754 wiphy = &rdev->wiphy;
Johannes Berg04a773a2009-04-19 21:24:32 +02006755
Johannes Berg39193492011-09-16 13:45:25 +02006756 if (info->attrs[NL80211_ATTR_MAC]) {
Johannes Berg04a773a2009-04-19 21:24:32 +02006757 ibss.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Johannes Berg39193492011-09-16 13:45:25 +02006758
6759 if (!is_valid_ether_addr(ibss.bssid))
6760 return -EINVAL;
6761 }
Johannes Berg04a773a2009-04-19 21:24:32 +02006762 ibss.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
6763 ibss.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
6764
6765 if (info->attrs[NL80211_ATTR_IE]) {
6766 ibss.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
6767 ibss.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
6768 }
6769
Johannes Berg683b6d32012-11-08 21:25:48 +01006770 err = nl80211_parse_chandef(rdev, info, &ibss.chandef);
6771 if (err)
6772 return err;
Alexander Simon54858ee5b2011-11-30 16:56:32 +01006773
Ilan Peer174e0cd2014-02-23 09:13:01 +02006774 if (!cfg80211_reg_can_beacon(&rdev->wiphy, &ibss.chandef,
6775 NL80211_IFTYPE_ADHOC))
Alexander Simon54858ee5b2011-11-30 16:56:32 +01006776 return -EINVAL;
6777
Simon Wunderlich2f301ab2013-05-16 13:00:28 +02006778 switch (ibss.chandef.width) {
Simon Wunderlichbf372642013-07-08 16:55:58 +02006779 case NL80211_CHAN_WIDTH_5:
6780 case NL80211_CHAN_WIDTH_10:
Simon Wunderlich2f301ab2013-05-16 13:00:28 +02006781 case NL80211_CHAN_WIDTH_20_NOHT:
6782 break;
6783 case NL80211_CHAN_WIDTH_20:
6784 case NL80211_CHAN_WIDTH_40:
6785 if (rdev->wiphy.features & NL80211_FEATURE_HT_IBSS)
6786 break;
6787 default:
Johannes Bergdb9c64c2012-11-09 14:56:41 +01006788 return -EINVAL;
Simon Wunderlich2f301ab2013-05-16 13:00:28 +02006789 }
Johannes Bergdb9c64c2012-11-09 14:56:41 +01006790
Johannes Berg04a773a2009-04-19 21:24:32 +02006791 ibss.channel_fixed = !!info->attrs[NL80211_ATTR_FREQ_FIXED];
Johannes Bergfffd0932009-07-08 14:22:54 +02006792 ibss.privacy = !!info->attrs[NL80211_ATTR_PRIVACY];
Johannes Berg04a773a2009-04-19 21:24:32 +02006793
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03006794 if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) {
6795 u8 *rates =
6796 nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
6797 int n_rates =
6798 nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
6799 struct ieee80211_supported_band *sband =
Johannes Berg683b6d32012-11-08 21:25:48 +01006800 wiphy->bands[ibss.chandef.chan->band];
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03006801
Johannes Berg34850ab2011-07-18 18:08:35 +02006802 err = ieee80211_get_ratemask(sband, rates, n_rates,
6803 &ibss.basic_rates);
6804 if (err)
6805 return err;
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03006806 }
Felix Fietkaudd5b4cc2010-11-22 20:58:24 +01006807
Simon Wunderlich803768f2013-06-28 10:39:58 +02006808 if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
6809 memcpy(&ibss.ht_capa_mask,
6810 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]),
6811 sizeof(ibss.ht_capa_mask));
6812
6813 if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) {
6814 if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
6815 return -EINVAL;
6816 memcpy(&ibss.ht_capa,
6817 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]),
6818 sizeof(ibss.ht_capa));
6819 }
6820
Felix Fietkaudd5b4cc2010-11-22 20:58:24 +01006821 if (info->attrs[NL80211_ATTR_MCAST_RATE] &&
6822 !nl80211_parse_mcast_rate(rdev, ibss.mcast_rate,
6823 nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE])))
6824 return -EINVAL;
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03006825
Johannes Berg4c476992010-10-04 21:36:35 +02006826 if (ibss.privacy && info->attrs[NL80211_ATTR_KEYS]) {
Sujith Manoharande7044e2012-10-18 10:19:28 +05306827 bool no_ht = false;
6828
Johannes Berg4c476992010-10-04 21:36:35 +02006829 connkeys = nl80211_parse_connkeys(rdev,
Sujith Manoharande7044e2012-10-18 10:19:28 +05306830 info->attrs[NL80211_ATTR_KEYS],
6831 &no_ht);
Johannes Berg4c476992010-10-04 21:36:35 +02006832 if (IS_ERR(connkeys))
6833 return PTR_ERR(connkeys);
Sujith Manoharande7044e2012-10-18 10:19:28 +05306834
Johannes Berg3d9d1d62012-11-08 23:14:50 +01006835 if ((ibss.chandef.width != NL80211_CHAN_WIDTH_20_NOHT) &&
6836 no_ht) {
Sujith Manoharande7044e2012-10-18 10:19:28 +05306837 kfree(connkeys);
6838 return -EINVAL;
6839 }
Johannes Berg4c476992010-10-04 21:36:35 +02006840 }
Johannes Berg04a773a2009-04-19 21:24:32 +02006841
Antonio Quartulli267335d2012-01-31 20:25:47 +01006842 ibss.control_port =
6843 nla_get_flag(info->attrs[NL80211_ATTR_CONTROL_PORT]);
6844
Simon Wunderlich5336fa82013-10-07 18:41:05 +02006845 ibss.userspace_handles_dfs =
6846 nla_get_flag(info->attrs[NL80211_ATTR_HANDLE_DFS]);
6847
Johannes Berg4c476992010-10-04 21:36:35 +02006848 err = cfg80211_join_ibss(rdev, dev, &ibss, connkeys);
Johannes Bergfffd0932009-07-08 14:22:54 +02006849 if (err)
6850 kfree(connkeys);
Johannes Berg04a773a2009-04-19 21:24:32 +02006851 return err;
6852}
6853
6854static int nl80211_leave_ibss(struct sk_buff *skb, struct genl_info *info)
6855{
Johannes Berg4c476992010-10-04 21:36:35 +02006856 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6857 struct net_device *dev = info->user_ptr[1];
Johannes Berg04a773a2009-04-19 21:24:32 +02006858
Johannes Berg4c476992010-10-04 21:36:35 +02006859 if (!rdev->ops->leave_ibss)
6860 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02006861
Johannes Berg4c476992010-10-04 21:36:35 +02006862 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC)
6863 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02006864
Johannes Berg4c476992010-10-04 21:36:35 +02006865 return cfg80211_leave_ibss(rdev, dev, false);
Johannes Berg04a773a2009-04-19 21:24:32 +02006866}
6867
Antonio Quartullif4e583c2012-11-02 13:27:48 +01006868static int nl80211_set_mcast_rate(struct sk_buff *skb, struct genl_info *info)
6869{
6870 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6871 struct net_device *dev = info->user_ptr[1];
6872 int mcast_rate[IEEE80211_NUM_BANDS];
6873 u32 nla_rate;
6874 int err;
6875
6876 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC &&
6877 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
6878 return -EOPNOTSUPP;
6879
6880 if (!rdev->ops->set_mcast_rate)
6881 return -EOPNOTSUPP;
6882
6883 memset(mcast_rate, 0, sizeof(mcast_rate));
6884
6885 if (!info->attrs[NL80211_ATTR_MCAST_RATE])
6886 return -EINVAL;
6887
6888 nla_rate = nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]);
6889 if (!nl80211_parse_mcast_rate(rdev, mcast_rate, nla_rate))
6890 return -EINVAL;
6891
6892 err = rdev->ops->set_mcast_rate(&rdev->wiphy, dev, mcast_rate);
6893
6894 return err;
6895}
6896
Johannes Bergad7e7182013-11-13 13:37:47 +01006897static struct sk_buff *
6898__cfg80211_alloc_vendor_skb(struct cfg80211_registered_device *rdev,
6899 int approxlen, u32 portid, u32 seq,
6900 enum nl80211_commands cmd,
Johannes Berg567ffc32013-12-18 14:43:31 +01006901 enum nl80211_attrs attr,
6902 const struct nl80211_vendor_cmd_info *info,
6903 gfp_t gfp)
Johannes Bergad7e7182013-11-13 13:37:47 +01006904{
6905 struct sk_buff *skb;
6906 void *hdr;
6907 struct nlattr *data;
6908
6909 skb = nlmsg_new(approxlen + 100, gfp);
6910 if (!skb)
6911 return NULL;
6912
6913 hdr = nl80211hdr_put(skb, portid, seq, 0, cmd);
6914 if (!hdr) {
6915 kfree_skb(skb);
6916 return NULL;
6917 }
6918
6919 if (nla_put_u32(skb, NL80211_ATTR_WIPHY, rdev->wiphy_idx))
6920 goto nla_put_failure;
Johannes Berg567ffc32013-12-18 14:43:31 +01006921
6922 if (info) {
6923 if (nla_put_u32(skb, NL80211_ATTR_VENDOR_ID,
6924 info->vendor_id))
6925 goto nla_put_failure;
6926 if (nla_put_u32(skb, NL80211_ATTR_VENDOR_SUBCMD,
6927 info->subcmd))
6928 goto nla_put_failure;
6929 }
6930
Johannes Bergad7e7182013-11-13 13:37:47 +01006931 data = nla_nest_start(skb, attr);
6932
6933 ((void **)skb->cb)[0] = rdev;
6934 ((void **)skb->cb)[1] = hdr;
6935 ((void **)skb->cb)[2] = data;
6936
6937 return skb;
6938
6939 nla_put_failure:
6940 kfree_skb(skb);
6941 return NULL;
6942}
Antonio Quartullif4e583c2012-11-02 13:27:48 +01006943
Johannes Berge03ad6e2014-01-01 17:22:30 +01006944struct sk_buff *__cfg80211_alloc_event_skb(struct wiphy *wiphy,
6945 enum nl80211_commands cmd,
6946 enum nl80211_attrs attr,
6947 int vendor_event_idx,
6948 int approxlen, gfp_t gfp)
6949{
Zhao, Gangf26cbf42014-04-21 12:53:03 +08006950 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berge03ad6e2014-01-01 17:22:30 +01006951 const struct nl80211_vendor_cmd_info *info;
6952
6953 switch (cmd) {
6954 case NL80211_CMD_TESTMODE:
6955 if (WARN_ON(vendor_event_idx != -1))
6956 return NULL;
6957 info = NULL;
6958 break;
6959 case NL80211_CMD_VENDOR:
6960 if (WARN_ON(vendor_event_idx < 0 ||
6961 vendor_event_idx >= wiphy->n_vendor_events))
6962 return NULL;
6963 info = &wiphy->vendor_events[vendor_event_idx];
6964 break;
6965 default:
6966 WARN_ON(1);
6967 return NULL;
6968 }
6969
6970 return __cfg80211_alloc_vendor_skb(rdev, approxlen, 0, 0,
6971 cmd, attr, info, gfp);
6972}
6973EXPORT_SYMBOL(__cfg80211_alloc_event_skb);
6974
6975void __cfg80211_send_event_skb(struct sk_buff *skb, gfp_t gfp)
6976{
6977 struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0];
6978 void *hdr = ((void **)skb->cb)[1];
6979 struct nlattr *data = ((void **)skb->cb)[2];
6980 enum nl80211_multicast_groups mcgrp = NL80211_MCGRP_TESTMODE;
6981
6982 nla_nest_end(skb, data);
6983 genlmsg_end(skb, hdr);
6984
6985 if (data->nla_type == NL80211_ATTR_VENDOR_DATA)
6986 mcgrp = NL80211_MCGRP_VENDOR;
6987
6988 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), skb, 0,
6989 mcgrp, gfp);
6990}
6991EXPORT_SYMBOL(__cfg80211_send_event_skb);
6992
Johannes Bergaff89a92009-07-01 21:26:51 +02006993#ifdef CONFIG_NL80211_TESTMODE
Johannes Bergaff89a92009-07-01 21:26:51 +02006994static int nl80211_testmode_do(struct sk_buff *skb, struct genl_info *info)
6995{
Johannes Berg4c476992010-10-04 21:36:35 +02006996 struct cfg80211_registered_device *rdev = info->user_ptr[0];
David Spinadelfc73f112013-07-31 18:04:15 +03006997 struct wireless_dev *wdev =
6998 __cfg80211_wdev_from_attrs(genl_info_net(info), info->attrs);
Johannes Bergaff89a92009-07-01 21:26:51 +02006999 int err;
7000
David Spinadelfc73f112013-07-31 18:04:15 +03007001 if (!rdev->ops->testmode_cmd)
7002 return -EOPNOTSUPP;
7003
7004 if (IS_ERR(wdev)) {
7005 err = PTR_ERR(wdev);
7006 if (err != -EINVAL)
7007 return err;
7008 wdev = NULL;
7009 } else if (wdev->wiphy != &rdev->wiphy) {
7010 return -EINVAL;
7011 }
7012
Johannes Bergaff89a92009-07-01 21:26:51 +02007013 if (!info->attrs[NL80211_ATTR_TESTDATA])
7014 return -EINVAL;
7015
Johannes Bergad7e7182013-11-13 13:37:47 +01007016 rdev->cur_cmd_info = info;
David Spinadelfc73f112013-07-31 18:04:15 +03007017 err = rdev_testmode_cmd(rdev, wdev,
Johannes Bergaff89a92009-07-01 21:26:51 +02007018 nla_data(info->attrs[NL80211_ATTR_TESTDATA]),
7019 nla_len(info->attrs[NL80211_ATTR_TESTDATA]));
Johannes Bergad7e7182013-11-13 13:37:47 +01007020 rdev->cur_cmd_info = NULL;
Johannes Bergaff89a92009-07-01 21:26:51 +02007021
Johannes Bergaff89a92009-07-01 21:26:51 +02007022 return err;
7023}
7024
Wey-Yi Guy71063f02011-05-20 09:05:54 -07007025static int nl80211_testmode_dump(struct sk_buff *skb,
7026 struct netlink_callback *cb)
7027{
Johannes Berg00918d32011-12-13 17:22:05 +01007028 struct cfg80211_registered_device *rdev;
Wey-Yi Guy71063f02011-05-20 09:05:54 -07007029 int err;
7030 long phy_idx;
7031 void *data = NULL;
7032 int data_len = 0;
7033
Johannes Berg5fe231e2013-05-08 21:45:15 +02007034 rtnl_lock();
7035
Wey-Yi Guy71063f02011-05-20 09:05:54 -07007036 if (cb->args[0]) {
7037 /*
7038 * 0 is a valid index, but not valid for args[0],
7039 * so we need to offset by 1.
7040 */
7041 phy_idx = cb->args[0] - 1;
7042 } else {
7043 err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize,
7044 nl80211_fam.attrbuf, nl80211_fam.maxattr,
7045 nl80211_policy);
7046 if (err)
Johannes Berg5fe231e2013-05-08 21:45:15 +02007047 goto out_err;
Johannes Berg00918d32011-12-13 17:22:05 +01007048
Johannes Berg2bd7e352012-06-15 14:23:16 +02007049 rdev = __cfg80211_rdev_from_attrs(sock_net(skb->sk),
7050 nl80211_fam.attrbuf);
7051 if (IS_ERR(rdev)) {
Johannes Berg5fe231e2013-05-08 21:45:15 +02007052 err = PTR_ERR(rdev);
7053 goto out_err;
Johannes Berg00918d32011-12-13 17:22:05 +01007054 }
Johannes Berg2bd7e352012-06-15 14:23:16 +02007055 phy_idx = rdev->wiphy_idx;
7056 rdev = NULL;
Johannes Berg2bd7e352012-06-15 14:23:16 +02007057
Wey-Yi Guy71063f02011-05-20 09:05:54 -07007058 if (nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA])
7059 cb->args[1] =
7060 (long)nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA];
7061 }
7062
7063 if (cb->args[1]) {
7064 data = nla_data((void *)cb->args[1]);
7065 data_len = nla_len((void *)cb->args[1]);
7066 }
7067
Johannes Berg00918d32011-12-13 17:22:05 +01007068 rdev = cfg80211_rdev_by_wiphy_idx(phy_idx);
7069 if (!rdev) {
Johannes Berg5fe231e2013-05-08 21:45:15 +02007070 err = -ENOENT;
7071 goto out_err;
Wey-Yi Guy71063f02011-05-20 09:05:54 -07007072 }
Wey-Yi Guy71063f02011-05-20 09:05:54 -07007073
Johannes Berg00918d32011-12-13 17:22:05 +01007074 if (!rdev->ops->testmode_dump) {
Wey-Yi Guy71063f02011-05-20 09:05:54 -07007075 err = -EOPNOTSUPP;
7076 goto out_err;
7077 }
7078
7079 while (1) {
Eric W. Biederman15e47302012-09-07 20:12:54 +00007080 void *hdr = nl80211hdr_put(skb, NETLINK_CB(cb->skb).portid,
Wey-Yi Guy71063f02011-05-20 09:05:54 -07007081 cb->nlh->nlmsg_seq, NLM_F_MULTI,
7082 NL80211_CMD_TESTMODE);
7083 struct nlattr *tmdata;
7084
Dan Carpentercb35fba2013-08-14 14:50:01 +03007085 if (!hdr)
7086 break;
7087
David S. Miller9360ffd2012-03-29 04:41:26 -04007088 if (nla_put_u32(skb, NL80211_ATTR_WIPHY, phy_idx)) {
Wey-Yi Guy71063f02011-05-20 09:05:54 -07007089 genlmsg_cancel(skb, hdr);
7090 break;
7091 }
7092
7093 tmdata = nla_nest_start(skb, NL80211_ATTR_TESTDATA);
7094 if (!tmdata) {
7095 genlmsg_cancel(skb, hdr);
7096 break;
7097 }
Hila Gonene35e4d22012-06-27 17:19:42 +03007098 err = rdev_testmode_dump(rdev, skb, cb, data, data_len);
Wey-Yi Guy71063f02011-05-20 09:05:54 -07007099 nla_nest_end(skb, tmdata);
7100
7101 if (err == -ENOBUFS || err == -ENOENT) {
7102 genlmsg_cancel(skb, hdr);
7103 break;
7104 } else if (err) {
7105 genlmsg_cancel(skb, hdr);
7106 goto out_err;
7107 }
7108
7109 genlmsg_end(skb, hdr);
7110 }
7111
7112 err = skb->len;
7113 /* see above */
7114 cb->args[0] = phy_idx + 1;
7115 out_err:
Johannes Berg5fe231e2013-05-08 21:45:15 +02007116 rtnl_unlock();
Wey-Yi Guy71063f02011-05-20 09:05:54 -07007117 return err;
7118}
Johannes Bergaff89a92009-07-01 21:26:51 +02007119#endif
7120
Samuel Ortizb23aa672009-07-01 21:26:54 +02007121static int nl80211_connect(struct sk_buff *skb, struct genl_info *info)
7122{
Johannes Berg4c476992010-10-04 21:36:35 +02007123 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7124 struct net_device *dev = info->user_ptr[1];
Samuel Ortizb23aa672009-07-01 21:26:54 +02007125 struct cfg80211_connect_params connect;
7126 struct wiphy *wiphy;
Johannes Bergfffd0932009-07-08 14:22:54 +02007127 struct cfg80211_cached_keys *connkeys = NULL;
Samuel Ortizb23aa672009-07-01 21:26:54 +02007128 int err;
7129
7130 memset(&connect, 0, sizeof(connect));
7131
7132 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
7133 return -EINVAL;
7134
7135 if (!info->attrs[NL80211_ATTR_SSID] ||
7136 !nla_len(info->attrs[NL80211_ATTR_SSID]))
7137 return -EINVAL;
7138
7139 if (info->attrs[NL80211_ATTR_AUTH_TYPE]) {
7140 connect.auth_type =
7141 nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]);
Jouni Malinene39e5b52012-09-30 19:29:39 +03007142 if (!nl80211_valid_auth_type(rdev, connect.auth_type,
7143 NL80211_CMD_CONNECT))
Samuel Ortizb23aa672009-07-01 21:26:54 +02007144 return -EINVAL;
7145 } else
7146 connect.auth_type = NL80211_AUTHTYPE_AUTOMATIC;
7147
7148 connect.privacy = info->attrs[NL80211_ATTR_PRIVACY];
7149
Johannes Bergc0692b82010-08-27 14:26:53 +03007150 err = nl80211_crypto_settings(rdev, info, &connect.crypto,
Johannes Berg3dc27d22009-07-02 21:36:37 +02007151 NL80211_MAX_NR_CIPHER_SUITES);
Samuel Ortizb23aa672009-07-01 21:26:54 +02007152 if (err)
7153 return err;
Samuel Ortizb23aa672009-07-01 21:26:54 +02007154
Johannes Berg074ac8d2010-09-16 14:58:22 +02007155 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02007156 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
7157 return -EOPNOTSUPP;
Samuel Ortizb23aa672009-07-01 21:26:54 +02007158
Johannes Berg79c97e92009-07-07 03:56:12 +02007159 wiphy = &rdev->wiphy;
Samuel Ortizb23aa672009-07-01 21:26:54 +02007160
Bala Shanmugam4486ea92012-03-07 17:27:12 +05307161 connect.bg_scan_period = -1;
7162 if (info->attrs[NL80211_ATTR_BG_SCAN_PERIOD] &&
7163 (wiphy->flags & WIPHY_FLAG_SUPPORTS_FW_ROAM)) {
7164 connect.bg_scan_period =
7165 nla_get_u16(info->attrs[NL80211_ATTR_BG_SCAN_PERIOD]);
7166 }
7167
Samuel Ortizb23aa672009-07-01 21:26:54 +02007168 if (info->attrs[NL80211_ATTR_MAC])
7169 connect.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen1df4a512014-01-15 00:00:47 +02007170 else if (info->attrs[NL80211_ATTR_MAC_HINT])
7171 connect.bssid_hint =
7172 nla_data(info->attrs[NL80211_ATTR_MAC_HINT]);
Samuel Ortizb23aa672009-07-01 21:26:54 +02007173 connect.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
7174 connect.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
7175
7176 if (info->attrs[NL80211_ATTR_IE]) {
7177 connect.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
7178 connect.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
7179 }
7180
Jouni Malinencee00a92013-01-15 17:15:57 +02007181 if (info->attrs[NL80211_ATTR_USE_MFP]) {
7182 connect.mfp = nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]);
7183 if (connect.mfp != NL80211_MFP_REQUIRED &&
7184 connect.mfp != NL80211_MFP_NO)
7185 return -EINVAL;
7186 } else {
7187 connect.mfp = NL80211_MFP_NO;
7188 }
7189
Samuel Ortizb23aa672009-07-01 21:26:54 +02007190 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
Jouni Malinen664834d2014-01-15 00:01:44 +02007191 connect.channel = nl80211_get_valid_chan(
7192 wiphy, info->attrs[NL80211_ATTR_WIPHY_FREQ]);
7193 if (!connect.channel)
Johannes Berg4c476992010-10-04 21:36:35 +02007194 return -EINVAL;
Jouni Malinen1df4a512014-01-15 00:00:47 +02007195 } else if (info->attrs[NL80211_ATTR_WIPHY_FREQ_HINT]) {
Jouni Malinen664834d2014-01-15 00:01:44 +02007196 connect.channel_hint = nl80211_get_valid_chan(
7197 wiphy, info->attrs[NL80211_ATTR_WIPHY_FREQ_HINT]);
7198 if (!connect.channel_hint)
Jouni Malinen1df4a512014-01-15 00:00:47 +02007199 return -EINVAL;
Samuel Ortizb23aa672009-07-01 21:26:54 +02007200 }
7201
Johannes Bergfffd0932009-07-08 14:22:54 +02007202 if (connect.privacy && info->attrs[NL80211_ATTR_KEYS]) {
7203 connkeys = nl80211_parse_connkeys(rdev,
Sujith Manoharande7044e2012-10-18 10:19:28 +05307204 info->attrs[NL80211_ATTR_KEYS], NULL);
Johannes Berg4c476992010-10-04 21:36:35 +02007205 if (IS_ERR(connkeys))
7206 return PTR_ERR(connkeys);
Johannes Bergfffd0932009-07-08 14:22:54 +02007207 }
7208
Ben Greear7e7c8922011-11-18 11:31:59 -08007209 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT]))
7210 connect.flags |= ASSOC_REQ_DISABLE_HT;
7211
7212 if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
7213 memcpy(&connect.ht_capa_mask,
7214 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]),
7215 sizeof(connect.ht_capa_mask));
7216
7217 if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) {
Wei Yongjunb4e4f472012-09-02 21:41:04 +08007218 if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) {
7219 kfree(connkeys);
Ben Greear7e7c8922011-11-18 11:31:59 -08007220 return -EINVAL;
Wei Yongjunb4e4f472012-09-02 21:41:04 +08007221 }
Ben Greear7e7c8922011-11-18 11:31:59 -08007222 memcpy(&connect.ht_capa,
7223 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]),
7224 sizeof(connect.ht_capa));
7225 }
7226
Johannes Bergee2aca32013-02-21 17:36:01 +01007227 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_VHT]))
7228 connect.flags |= ASSOC_REQ_DISABLE_VHT;
7229
7230 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK])
7231 memcpy(&connect.vht_capa_mask,
7232 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]),
7233 sizeof(connect.vht_capa_mask));
7234
7235 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) {
7236 if (!info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) {
7237 kfree(connkeys);
7238 return -EINVAL;
7239 }
7240 memcpy(&connect.vht_capa,
7241 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]),
7242 sizeof(connect.vht_capa));
7243 }
7244
Johannes Berg83739b02013-05-15 17:44:01 +02007245 wdev_lock(dev->ieee80211_ptr);
7246 err = cfg80211_connect(rdev, dev, &connect, connkeys, NULL);
7247 wdev_unlock(dev->ieee80211_ptr);
Johannes Bergfffd0932009-07-08 14:22:54 +02007248 if (err)
7249 kfree(connkeys);
Samuel Ortizb23aa672009-07-01 21:26:54 +02007250 return err;
7251}
7252
7253static int nl80211_disconnect(struct sk_buff *skb, struct genl_info *info)
7254{
Johannes Berg4c476992010-10-04 21:36:35 +02007255 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7256 struct net_device *dev = info->user_ptr[1];
Samuel Ortizb23aa672009-07-01 21:26:54 +02007257 u16 reason;
Johannes Berg83739b02013-05-15 17:44:01 +02007258 int ret;
Samuel Ortizb23aa672009-07-01 21:26:54 +02007259
7260 if (!info->attrs[NL80211_ATTR_REASON_CODE])
7261 reason = WLAN_REASON_DEAUTH_LEAVING;
7262 else
7263 reason = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
7264
7265 if (reason == 0)
7266 return -EINVAL;
7267
Johannes Berg074ac8d2010-09-16 14:58:22 +02007268 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02007269 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
7270 return -EOPNOTSUPP;
Samuel Ortizb23aa672009-07-01 21:26:54 +02007271
Johannes Berg83739b02013-05-15 17:44:01 +02007272 wdev_lock(dev->ieee80211_ptr);
7273 ret = cfg80211_disconnect(rdev, dev, reason, true);
7274 wdev_unlock(dev->ieee80211_ptr);
7275 return ret;
Samuel Ortizb23aa672009-07-01 21:26:54 +02007276}
7277
Johannes Berg463d0182009-07-14 00:33:35 +02007278static int nl80211_wiphy_netns(struct sk_buff *skb, struct genl_info *info)
7279{
Johannes Berg4c476992010-10-04 21:36:35 +02007280 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg463d0182009-07-14 00:33:35 +02007281 struct net *net;
7282 int err;
7283 u32 pid;
7284
7285 if (!info->attrs[NL80211_ATTR_PID])
7286 return -EINVAL;
7287
7288 pid = nla_get_u32(info->attrs[NL80211_ATTR_PID]);
7289
Johannes Berg463d0182009-07-14 00:33:35 +02007290 net = get_net_ns_by_pid(pid);
Johannes Berg4c476992010-10-04 21:36:35 +02007291 if (IS_ERR(net))
7292 return PTR_ERR(net);
Johannes Berg463d0182009-07-14 00:33:35 +02007293
7294 err = 0;
7295
7296 /* check if anything to do */
Johannes Berg4c476992010-10-04 21:36:35 +02007297 if (!net_eq(wiphy_net(&rdev->wiphy), net))
7298 err = cfg80211_switch_netns(rdev, net);
Johannes Berg463d0182009-07-14 00:33:35 +02007299
Johannes Berg463d0182009-07-14 00:33:35 +02007300 put_net(net);
Johannes Berg463d0182009-07-14 00:33:35 +02007301 return err;
7302}
7303
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007304static int nl80211_setdel_pmksa(struct sk_buff *skb, struct genl_info *info)
7305{
Johannes Berg4c476992010-10-04 21:36:35 +02007306 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007307 int (*rdev_ops)(struct wiphy *wiphy, struct net_device *dev,
7308 struct cfg80211_pmksa *pmksa) = NULL;
Johannes Berg4c476992010-10-04 21:36:35 +02007309 struct net_device *dev = info->user_ptr[1];
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007310 struct cfg80211_pmksa pmksa;
7311
7312 memset(&pmksa, 0, sizeof(struct cfg80211_pmksa));
7313
7314 if (!info->attrs[NL80211_ATTR_MAC])
7315 return -EINVAL;
7316
7317 if (!info->attrs[NL80211_ATTR_PMKID])
7318 return -EINVAL;
7319
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007320 pmksa.pmkid = nla_data(info->attrs[NL80211_ATTR_PMKID]);
7321 pmksa.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
7322
Johannes Berg074ac8d2010-09-16 14:58:22 +02007323 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02007324 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
7325 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007326
7327 switch (info->genlhdr->cmd) {
7328 case NL80211_CMD_SET_PMKSA:
7329 rdev_ops = rdev->ops->set_pmksa;
7330 break;
7331 case NL80211_CMD_DEL_PMKSA:
7332 rdev_ops = rdev->ops->del_pmksa;
7333 break;
7334 default:
7335 WARN_ON(1);
7336 break;
7337 }
7338
Johannes Berg4c476992010-10-04 21:36:35 +02007339 if (!rdev_ops)
7340 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007341
Johannes Berg4c476992010-10-04 21:36:35 +02007342 return rdev_ops(&rdev->wiphy, dev, &pmksa);
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007343}
7344
7345static int nl80211_flush_pmksa(struct sk_buff *skb, struct genl_info *info)
7346{
Johannes Berg4c476992010-10-04 21:36:35 +02007347 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7348 struct net_device *dev = info->user_ptr[1];
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007349
Johannes Berg074ac8d2010-09-16 14:58:22 +02007350 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02007351 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
7352 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007353
Johannes Berg4c476992010-10-04 21:36:35 +02007354 if (!rdev->ops->flush_pmksa)
7355 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007356
Hila Gonene35e4d22012-06-27 17:19:42 +03007357 return rdev_flush_pmksa(rdev, dev);
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007358}
7359
Arik Nemtsov109086c2011-09-28 14:12:50 +03007360static int nl80211_tdls_mgmt(struct sk_buff *skb, struct genl_info *info)
7361{
7362 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7363 struct net_device *dev = info->user_ptr[1];
7364 u8 action_code, dialog_token;
Sunil Dutt Undekaridf942e72014-02-20 16:22:09 +05307365 u32 peer_capability = 0;
Arik Nemtsov109086c2011-09-28 14:12:50 +03007366 u16 status_code;
7367 u8 *peer;
7368
7369 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) ||
7370 !rdev->ops->tdls_mgmt)
7371 return -EOPNOTSUPP;
7372
7373 if (!info->attrs[NL80211_ATTR_TDLS_ACTION] ||
7374 !info->attrs[NL80211_ATTR_STATUS_CODE] ||
7375 !info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN] ||
7376 !info->attrs[NL80211_ATTR_IE] ||
7377 !info->attrs[NL80211_ATTR_MAC])
7378 return -EINVAL;
7379
7380 peer = nla_data(info->attrs[NL80211_ATTR_MAC]);
7381 action_code = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_ACTION]);
7382 status_code = nla_get_u16(info->attrs[NL80211_ATTR_STATUS_CODE]);
7383 dialog_token = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN]);
Sunil Dutt Undekaridf942e72014-02-20 16:22:09 +05307384 if (info->attrs[NL80211_ATTR_TDLS_PEER_CAPABILITY])
7385 peer_capability =
7386 nla_get_u32(info->attrs[NL80211_ATTR_TDLS_PEER_CAPABILITY]);
Arik Nemtsov109086c2011-09-28 14:12:50 +03007387
Hila Gonene35e4d22012-06-27 17:19:42 +03007388 return rdev_tdls_mgmt(rdev, dev, peer, action_code,
Sunil Dutt Undekaridf942e72014-02-20 16:22:09 +05307389 dialog_token, status_code, peer_capability,
Hila Gonene35e4d22012-06-27 17:19:42 +03007390 nla_data(info->attrs[NL80211_ATTR_IE]),
7391 nla_len(info->attrs[NL80211_ATTR_IE]));
Arik Nemtsov109086c2011-09-28 14:12:50 +03007392}
7393
7394static int nl80211_tdls_oper(struct sk_buff *skb, struct genl_info *info)
7395{
7396 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7397 struct net_device *dev = info->user_ptr[1];
7398 enum nl80211_tdls_operation operation;
7399 u8 *peer;
7400
7401 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) ||
7402 !rdev->ops->tdls_oper)
7403 return -EOPNOTSUPP;
7404
7405 if (!info->attrs[NL80211_ATTR_TDLS_OPERATION] ||
7406 !info->attrs[NL80211_ATTR_MAC])
7407 return -EINVAL;
7408
7409 operation = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_OPERATION]);
7410 peer = nla_data(info->attrs[NL80211_ATTR_MAC]);
7411
Hila Gonene35e4d22012-06-27 17:19:42 +03007412 return rdev_tdls_oper(rdev, dev, peer, operation);
Arik Nemtsov109086c2011-09-28 14:12:50 +03007413}
7414
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007415static int nl80211_remain_on_channel(struct sk_buff *skb,
7416 struct genl_info *info)
7417{
Johannes Berg4c476992010-10-04 21:36:35 +02007418 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02007419 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg683b6d32012-11-08 21:25:48 +01007420 struct cfg80211_chan_def chandef;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007421 struct sk_buff *msg;
7422 void *hdr;
7423 u64 cookie;
Johannes Berg683b6d32012-11-08 21:25:48 +01007424 u32 duration;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007425 int err;
7426
7427 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] ||
7428 !info->attrs[NL80211_ATTR_DURATION])
7429 return -EINVAL;
7430
7431 duration = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]);
7432
Johannes Berg7c4ef712011-11-18 15:33:48 +01007433 if (!rdev->ops->remain_on_channel ||
7434 !(rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL))
Johannes Berg4c476992010-10-04 21:36:35 +02007435 return -EOPNOTSUPP;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007436
Johannes Bergebf348f2012-06-01 12:50:54 +02007437 /*
7438 * We should be on that channel for at least a minimum amount of
7439 * time (10ms) but no longer than the driver supports.
7440 */
7441 if (duration < NL80211_MIN_REMAIN_ON_CHANNEL_TIME ||
7442 duration > rdev->wiphy.max_remain_on_channel_duration)
7443 return -EINVAL;
7444
Johannes Berg683b6d32012-11-08 21:25:48 +01007445 err = nl80211_parse_chandef(rdev, info, &chandef);
7446 if (err)
7447 return err;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007448
7449 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02007450 if (!msg)
7451 return -ENOMEM;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007452
Eric W. Biederman15e47302012-09-07 20:12:54 +00007453 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007454 NL80211_CMD_REMAIN_ON_CHANNEL);
Dan Carpentercb35fba2013-08-14 14:50:01 +03007455 if (!hdr) {
7456 err = -ENOBUFS;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007457 goto free_msg;
7458 }
7459
Johannes Berg683b6d32012-11-08 21:25:48 +01007460 err = rdev_remain_on_channel(rdev, wdev, chandef.chan,
7461 duration, &cookie);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007462
7463 if (err)
7464 goto free_msg;
7465
David S. Miller9360ffd2012-03-29 04:41:26 -04007466 if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie))
7467 goto nla_put_failure;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007468
7469 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02007470
7471 return genlmsg_reply(msg, info);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007472
7473 nla_put_failure:
7474 err = -ENOBUFS;
7475 free_msg:
7476 nlmsg_free(msg);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007477 return err;
7478}
7479
7480static int nl80211_cancel_remain_on_channel(struct sk_buff *skb,
7481 struct genl_info *info)
7482{
Johannes Berg4c476992010-10-04 21:36:35 +02007483 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02007484 struct wireless_dev *wdev = info->user_ptr[1];
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007485 u64 cookie;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007486
7487 if (!info->attrs[NL80211_ATTR_COOKIE])
7488 return -EINVAL;
7489
Johannes Berg4c476992010-10-04 21:36:35 +02007490 if (!rdev->ops->cancel_remain_on_channel)
7491 return -EOPNOTSUPP;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007492
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007493 cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]);
7494
Hila Gonene35e4d22012-06-27 17:19:42 +03007495 return rdev_cancel_remain_on_channel(rdev, wdev, cookie);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007496}
7497
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007498static u32 rateset_to_mask(struct ieee80211_supported_band *sband,
7499 u8 *rates, u8 rates_len)
7500{
7501 u8 i;
7502 u32 mask = 0;
7503
7504 for (i = 0; i < rates_len; i++) {
7505 int rate = (rates[i] & 0x7f) * 5;
7506 int ridx;
7507 for (ridx = 0; ridx < sband->n_bitrates; ridx++) {
7508 struct ieee80211_rate *srate =
7509 &sband->bitrates[ridx];
7510 if (rate == srate->bitrate) {
7511 mask |= 1 << ridx;
7512 break;
7513 }
7514 }
7515 if (ridx == sband->n_bitrates)
7516 return 0; /* rate not found */
7517 }
7518
7519 return mask;
7520}
7521
Simon Wunderlich24db78c2012-01-28 17:25:32 +01007522static bool ht_rateset_to_mask(struct ieee80211_supported_band *sband,
7523 u8 *rates, u8 rates_len,
7524 u8 mcs[IEEE80211_HT_MCS_MASK_LEN])
7525{
7526 u8 i;
7527
7528 memset(mcs, 0, IEEE80211_HT_MCS_MASK_LEN);
7529
7530 for (i = 0; i < rates_len; i++) {
7531 int ridx, rbit;
7532
7533 ridx = rates[i] / 8;
7534 rbit = BIT(rates[i] % 8);
7535
7536 /* check validity */
Dan Carpenter910570b52012-02-01 10:42:11 +03007537 if ((ridx < 0) || (ridx >= IEEE80211_HT_MCS_MASK_LEN))
Simon Wunderlich24db78c2012-01-28 17:25:32 +01007538 return false;
7539
7540 /* check availability */
7541 if (sband->ht_cap.mcs.rx_mask[ridx] & rbit)
7542 mcs[ridx] |= rbit;
7543 else
7544 return false;
7545 }
7546
7547 return true;
7548}
7549
Janusz Dziedzic204e35a2013-12-05 20:42:58 +01007550static u16 vht_mcs_map_to_mcs_mask(u8 vht_mcs_map)
7551{
7552 u16 mcs_mask = 0;
7553
7554 switch (vht_mcs_map) {
7555 case IEEE80211_VHT_MCS_NOT_SUPPORTED:
7556 break;
7557 case IEEE80211_VHT_MCS_SUPPORT_0_7:
7558 mcs_mask = 0x00FF;
7559 break;
7560 case IEEE80211_VHT_MCS_SUPPORT_0_8:
7561 mcs_mask = 0x01FF;
7562 break;
7563 case IEEE80211_VHT_MCS_SUPPORT_0_9:
7564 mcs_mask = 0x03FF;
7565 break;
7566 default:
7567 break;
7568 }
7569
7570 return mcs_mask;
7571}
7572
7573static void vht_build_mcs_mask(u16 vht_mcs_map,
7574 u16 vht_mcs_mask[NL80211_VHT_NSS_MAX])
7575{
7576 u8 nss;
7577
7578 for (nss = 0; nss < NL80211_VHT_NSS_MAX; nss++) {
7579 vht_mcs_mask[nss] = vht_mcs_map_to_mcs_mask(vht_mcs_map & 0x03);
7580 vht_mcs_map >>= 2;
7581 }
7582}
7583
7584static bool vht_set_mcs_mask(struct ieee80211_supported_band *sband,
7585 struct nl80211_txrate_vht *txrate,
7586 u16 mcs[NL80211_VHT_NSS_MAX])
7587{
7588 u16 tx_mcs_map = le16_to_cpu(sband->vht_cap.vht_mcs.tx_mcs_map);
7589 u16 tx_mcs_mask[NL80211_VHT_NSS_MAX] = {};
7590 u8 i;
7591
7592 if (!sband->vht_cap.vht_supported)
7593 return false;
7594
7595 memset(mcs, 0, sizeof(u16) * NL80211_VHT_NSS_MAX);
7596
7597 /* Build vht_mcs_mask from VHT capabilities */
7598 vht_build_mcs_mask(tx_mcs_map, tx_mcs_mask);
7599
7600 for (i = 0; i < NL80211_VHT_NSS_MAX; i++) {
7601 if ((tx_mcs_mask[i] & txrate->mcs[i]) == txrate->mcs[i])
7602 mcs[i] = txrate->mcs[i];
7603 else
7604 return false;
7605 }
7606
7607 return true;
7608}
7609
Alexey Dobriyanb54452b2010-02-18 08:14:31 +00007610static const struct nla_policy nl80211_txattr_policy[NL80211_TXRATE_MAX + 1] = {
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007611 [NL80211_TXRATE_LEGACY] = { .type = NLA_BINARY,
7612 .len = NL80211_MAX_SUPP_RATES },
Janusz Dziedzicd1e33e62013-12-05 10:02:15 +01007613 [NL80211_TXRATE_HT] = { .type = NLA_BINARY,
7614 .len = NL80211_MAX_SUPP_HT_RATES },
Janusz Dziedzic204e35a2013-12-05 20:42:58 +01007615 [NL80211_TXRATE_VHT] = { .len = sizeof(struct nl80211_txrate_vht)},
Janusz Dziedzic0b9323f2014-01-08 08:46:02 +01007616 [NL80211_TXRATE_GI] = { .type = NLA_U8 },
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007617};
7618
7619static int nl80211_set_tx_bitrate_mask(struct sk_buff *skb,
7620 struct genl_info *info)
7621{
7622 struct nlattr *tb[NL80211_TXRATE_MAX + 1];
Johannes Berg4c476992010-10-04 21:36:35 +02007623 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007624 struct cfg80211_bitrate_mask mask;
Johannes Berg4c476992010-10-04 21:36:35 +02007625 int rem, i;
7626 struct net_device *dev = info->user_ptr[1];
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007627 struct nlattr *tx_rates;
7628 struct ieee80211_supported_band *sband;
Janusz Dziedzic204e35a2013-12-05 20:42:58 +01007629 u16 vht_tx_mcs_map;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007630
Johannes Berg4c476992010-10-04 21:36:35 +02007631 if (!rdev->ops->set_bitrate_mask)
7632 return -EOPNOTSUPP;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007633
7634 memset(&mask, 0, sizeof(mask));
7635 /* Default to all rates enabled */
7636 for (i = 0; i < IEEE80211_NUM_BANDS; i++) {
7637 sband = rdev->wiphy.bands[i];
Janusz Dziedzic78693032013-12-03 09:50:44 +01007638
7639 if (!sband)
7640 continue;
7641
7642 mask.control[i].legacy = (1 << sband->n_bitrates) - 1;
Janusz Dziedzicd1e33e62013-12-05 10:02:15 +01007643 memcpy(mask.control[i].ht_mcs,
Janusz Dziedzic78693032013-12-03 09:50:44 +01007644 sband->ht_cap.mcs.rx_mask,
Janusz Dziedzicd1e33e62013-12-05 10:02:15 +01007645 sizeof(mask.control[i].ht_mcs));
Janusz Dziedzic204e35a2013-12-05 20:42:58 +01007646
7647 if (!sband->vht_cap.vht_supported)
7648 continue;
7649
7650 vht_tx_mcs_map = le16_to_cpu(sband->vht_cap.vht_mcs.tx_mcs_map);
7651 vht_build_mcs_mask(vht_tx_mcs_map, mask.control[i].vht_mcs);
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007652 }
7653
Janusz Dziedzicb9243ab2013-12-05 10:02:14 +01007654 /* if no rates are given set it back to the defaults */
7655 if (!info->attrs[NL80211_ATTR_TX_RATES])
7656 goto out;
7657
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007658 /*
7659 * The nested attribute uses enum nl80211_band as the index. This maps
7660 * directly to the enum ieee80211_band values used in cfg80211.
7661 */
Simon Wunderlich24db78c2012-01-28 17:25:32 +01007662 BUILD_BUG_ON(NL80211_MAX_SUPP_HT_RATES > IEEE80211_HT_MCS_MASK_LEN * 8);
Johannes Bergae811e22014-01-24 10:17:47 +01007663 nla_for_each_nested(tx_rates, info->attrs[NL80211_ATTR_TX_RATES], rem) {
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007664 enum ieee80211_band band = nla_type(tx_rates);
Johannes Bergae811e22014-01-24 10:17:47 +01007665 int err;
7666
Johannes Berg4c476992010-10-04 21:36:35 +02007667 if (band < 0 || band >= IEEE80211_NUM_BANDS)
7668 return -EINVAL;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007669 sband = rdev->wiphy.bands[band];
Johannes Berg4c476992010-10-04 21:36:35 +02007670 if (sband == NULL)
7671 return -EINVAL;
Johannes Bergae811e22014-01-24 10:17:47 +01007672 err = nla_parse(tb, NL80211_TXRATE_MAX, nla_data(tx_rates),
7673 nla_len(tx_rates), nl80211_txattr_policy);
7674 if (err)
7675 return err;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007676 if (tb[NL80211_TXRATE_LEGACY]) {
7677 mask.control[band].legacy = rateset_to_mask(
7678 sband,
7679 nla_data(tb[NL80211_TXRATE_LEGACY]),
7680 nla_len(tb[NL80211_TXRATE_LEGACY]));
Bala Shanmugam218d2e22012-04-20 19:12:58 +05307681 if ((mask.control[band].legacy == 0) &&
7682 nla_len(tb[NL80211_TXRATE_LEGACY]))
7683 return -EINVAL;
Simon Wunderlich24db78c2012-01-28 17:25:32 +01007684 }
Janusz Dziedzicd1e33e62013-12-05 10:02:15 +01007685 if (tb[NL80211_TXRATE_HT]) {
Simon Wunderlich24db78c2012-01-28 17:25:32 +01007686 if (!ht_rateset_to_mask(
7687 sband,
Janusz Dziedzicd1e33e62013-12-05 10:02:15 +01007688 nla_data(tb[NL80211_TXRATE_HT]),
7689 nla_len(tb[NL80211_TXRATE_HT]),
7690 mask.control[band].ht_mcs))
Simon Wunderlich24db78c2012-01-28 17:25:32 +01007691 return -EINVAL;
7692 }
Janusz Dziedzic204e35a2013-12-05 20:42:58 +01007693 if (tb[NL80211_TXRATE_VHT]) {
7694 if (!vht_set_mcs_mask(
7695 sband,
7696 nla_data(tb[NL80211_TXRATE_VHT]),
7697 mask.control[band].vht_mcs))
7698 return -EINVAL;
7699 }
Janusz Dziedzic0b9323f2014-01-08 08:46:02 +01007700 if (tb[NL80211_TXRATE_GI]) {
7701 mask.control[band].gi =
7702 nla_get_u8(tb[NL80211_TXRATE_GI]);
7703 if (mask.control[band].gi > NL80211_TXRATE_FORCE_LGI)
7704 return -EINVAL;
7705 }
Simon Wunderlich24db78c2012-01-28 17:25:32 +01007706
7707 if (mask.control[band].legacy == 0) {
Janusz Dziedzic204e35a2013-12-05 20:42:58 +01007708 /* don't allow empty legacy rates if HT or VHT
7709 * are not even supported.
7710 */
7711 if (!(rdev->wiphy.bands[band]->ht_cap.ht_supported ||
7712 rdev->wiphy.bands[band]->vht_cap.vht_supported))
Simon Wunderlich24db78c2012-01-28 17:25:32 +01007713 return -EINVAL;
7714
7715 for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++)
Janusz Dziedzicd1e33e62013-12-05 10:02:15 +01007716 if (mask.control[band].ht_mcs[i])
Janusz Dziedzic204e35a2013-12-05 20:42:58 +01007717 goto out;
7718
7719 for (i = 0; i < NL80211_VHT_NSS_MAX; i++)
7720 if (mask.control[band].vht_mcs[i])
7721 goto out;
Simon Wunderlich24db78c2012-01-28 17:25:32 +01007722
7723 /* legacy and mcs rates may not be both empty */
Janusz Dziedzic204e35a2013-12-05 20:42:58 +01007724 return -EINVAL;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007725 }
7726 }
7727
Janusz Dziedzicb9243ab2013-12-05 10:02:14 +01007728out:
Hila Gonene35e4d22012-06-27 17:19:42 +03007729 return rdev_set_bitrate_mask(rdev, dev, NULL, &mask);
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007730}
7731
Johannes Berg2e161f72010-08-12 15:38:38 +02007732static int nl80211_register_mgmt(struct sk_buff *skb, struct genl_info *info)
Jouni Malinen026331c2010-02-15 12:53:10 +02007733{
Johannes Berg4c476992010-10-04 21:36:35 +02007734 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02007735 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg2e161f72010-08-12 15:38:38 +02007736 u16 frame_type = IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_ACTION;
Jouni Malinen026331c2010-02-15 12:53:10 +02007737
7738 if (!info->attrs[NL80211_ATTR_FRAME_MATCH])
7739 return -EINVAL;
7740
Johannes Berg2e161f72010-08-12 15:38:38 +02007741 if (info->attrs[NL80211_ATTR_FRAME_TYPE])
7742 frame_type = nla_get_u16(info->attrs[NL80211_ATTR_FRAME_TYPE]);
Jouni Malinen026331c2010-02-15 12:53:10 +02007743
Johannes Berg71bbc992012-06-15 15:30:18 +02007744 switch (wdev->iftype) {
7745 case NL80211_IFTYPE_STATION:
7746 case NL80211_IFTYPE_ADHOC:
7747 case NL80211_IFTYPE_P2P_CLIENT:
7748 case NL80211_IFTYPE_AP:
7749 case NL80211_IFTYPE_AP_VLAN:
7750 case NL80211_IFTYPE_MESH_POINT:
7751 case NL80211_IFTYPE_P2P_GO:
Johannes Berg98104fde2012-06-16 00:19:54 +02007752 case NL80211_IFTYPE_P2P_DEVICE:
Johannes Berg71bbc992012-06-15 15:30:18 +02007753 break;
7754 default:
Johannes Berg4c476992010-10-04 21:36:35 +02007755 return -EOPNOTSUPP;
Johannes Berg71bbc992012-06-15 15:30:18 +02007756 }
Jouni Malinen026331c2010-02-15 12:53:10 +02007757
7758 /* not much point in registering if we can't reply */
Johannes Berg4c476992010-10-04 21:36:35 +02007759 if (!rdev->ops->mgmt_tx)
7760 return -EOPNOTSUPP;
Jouni Malinen026331c2010-02-15 12:53:10 +02007761
Eric W. Biederman15e47302012-09-07 20:12:54 +00007762 return cfg80211_mlme_register_mgmt(wdev, info->snd_portid, frame_type,
Jouni Malinen026331c2010-02-15 12:53:10 +02007763 nla_data(info->attrs[NL80211_ATTR_FRAME_MATCH]),
7764 nla_len(info->attrs[NL80211_ATTR_FRAME_MATCH]));
Jouni Malinen026331c2010-02-15 12:53:10 +02007765}
7766
Johannes Berg2e161f72010-08-12 15:38:38 +02007767static int nl80211_tx_mgmt(struct sk_buff *skb, struct genl_info *info)
Jouni Malinen026331c2010-02-15 12:53:10 +02007768{
Johannes Berg4c476992010-10-04 21:36:35 +02007769 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02007770 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg683b6d32012-11-08 21:25:48 +01007771 struct cfg80211_chan_def chandef;
Jouni Malinen026331c2010-02-15 12:53:10 +02007772 int err;
Johannes Bergd64d3732011-11-10 09:44:46 +01007773 void *hdr = NULL;
Jouni Malinen026331c2010-02-15 12:53:10 +02007774 u64 cookie;
Johannes Berge247bd902011-11-04 11:18:21 +01007775 struct sk_buff *msg = NULL;
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02007776 struct cfg80211_mgmt_tx_params params = {
7777 .dont_wait_for_ack =
7778 info->attrs[NL80211_ATTR_DONT_WAIT_FOR_ACK],
7779 };
Jouni Malinen026331c2010-02-15 12:53:10 +02007780
Johannes Berg683b6d32012-11-08 21:25:48 +01007781 if (!info->attrs[NL80211_ATTR_FRAME])
Jouni Malinen026331c2010-02-15 12:53:10 +02007782 return -EINVAL;
7783
Johannes Berg4c476992010-10-04 21:36:35 +02007784 if (!rdev->ops->mgmt_tx)
7785 return -EOPNOTSUPP;
Jouni Malinen026331c2010-02-15 12:53:10 +02007786
Johannes Berg71bbc992012-06-15 15:30:18 +02007787 switch (wdev->iftype) {
Antonio Quartulliea141b752013-06-11 14:20:03 +02007788 case NL80211_IFTYPE_P2P_DEVICE:
7789 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ])
7790 return -EINVAL;
Johannes Berg71bbc992012-06-15 15:30:18 +02007791 case NL80211_IFTYPE_STATION:
7792 case NL80211_IFTYPE_ADHOC:
7793 case NL80211_IFTYPE_P2P_CLIENT:
7794 case NL80211_IFTYPE_AP:
7795 case NL80211_IFTYPE_AP_VLAN:
7796 case NL80211_IFTYPE_MESH_POINT:
7797 case NL80211_IFTYPE_P2P_GO:
7798 break;
7799 default:
Johannes Berg4c476992010-10-04 21:36:35 +02007800 return -EOPNOTSUPP;
Johannes Berg71bbc992012-06-15 15:30:18 +02007801 }
Jouni Malinen026331c2010-02-15 12:53:10 +02007802
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007803 if (info->attrs[NL80211_ATTR_DURATION]) {
Johannes Berg7c4ef712011-11-18 15:33:48 +01007804 if (!(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX))
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007805 return -EINVAL;
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02007806 params.wait = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]);
Johannes Bergebf348f2012-06-01 12:50:54 +02007807
7808 /*
7809 * We should wait on the channel for at least a minimum amount
7810 * of time (10ms) but no longer than the driver supports.
7811 */
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02007812 if (params.wait < NL80211_MIN_REMAIN_ON_CHANNEL_TIME ||
7813 params.wait > rdev->wiphy.max_remain_on_channel_duration)
Johannes Bergebf348f2012-06-01 12:50:54 +02007814 return -EINVAL;
7815
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007816 }
7817
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02007818 params.offchan = info->attrs[NL80211_ATTR_OFFCHANNEL_TX_OK];
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007819
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02007820 if (params.offchan && !(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX))
Johannes Berg7c4ef712011-11-18 15:33:48 +01007821 return -EINVAL;
7822
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02007823 params.no_cck = nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]);
Rajkumar Manoharane9f935e2011-09-25 14:53:30 +05307824
Antonio Quartulliea141b752013-06-11 14:20:03 +02007825 /* get the channel if any has been specified, otherwise pass NULL to
7826 * the driver. The latter will use the current one
7827 */
7828 chandef.chan = NULL;
7829 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
7830 err = nl80211_parse_chandef(rdev, info, &chandef);
7831 if (err)
7832 return err;
7833 }
7834
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02007835 if (!chandef.chan && params.offchan)
Antonio Quartulliea141b752013-06-11 14:20:03 +02007836 return -EINVAL;
Jouni Malinen026331c2010-02-15 12:53:10 +02007837
Andrei Otcheretianski34d22ce2014-05-09 14:11:44 +03007838 params.buf = nla_data(info->attrs[NL80211_ATTR_FRAME]);
7839 params.len = nla_len(info->attrs[NL80211_ATTR_FRAME]);
7840
7841 if (info->attrs[NL80211_ATTR_CSA_C_OFFSETS_TX]) {
7842 int len = nla_len(info->attrs[NL80211_ATTR_CSA_C_OFFSETS_TX]);
7843 int i;
7844
7845 if (len % sizeof(u16))
7846 return -EINVAL;
7847
7848 params.n_csa_offsets = len / sizeof(u16);
7849 params.csa_offsets =
7850 nla_data(info->attrs[NL80211_ATTR_CSA_C_OFFSETS_TX]);
7851
7852 /* check that all the offsets fit the frame */
7853 for (i = 0; i < params.n_csa_offsets; i++) {
7854 if (params.csa_offsets[i] >= params.len)
7855 return -EINVAL;
7856 }
7857 }
7858
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02007859 if (!params.dont_wait_for_ack) {
Johannes Berge247bd902011-11-04 11:18:21 +01007860 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
7861 if (!msg)
7862 return -ENOMEM;
Jouni Malinen026331c2010-02-15 12:53:10 +02007863
Eric W. Biederman15e47302012-09-07 20:12:54 +00007864 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berge247bd902011-11-04 11:18:21 +01007865 NL80211_CMD_FRAME);
Dan Carpentercb35fba2013-08-14 14:50:01 +03007866 if (!hdr) {
7867 err = -ENOBUFS;
Johannes Berge247bd902011-11-04 11:18:21 +01007868 goto free_msg;
7869 }
Jouni Malinen026331c2010-02-15 12:53:10 +02007870 }
Johannes Berge247bd902011-11-04 11:18:21 +01007871
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02007872 params.chan = chandef.chan;
7873 err = cfg80211_mlme_mgmt_tx(rdev, wdev, &params, &cookie);
Jouni Malinen026331c2010-02-15 12:53:10 +02007874 if (err)
7875 goto free_msg;
7876
Johannes Berge247bd902011-11-04 11:18:21 +01007877 if (msg) {
David S. Miller9360ffd2012-03-29 04:41:26 -04007878 if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie))
7879 goto nla_put_failure;
Jouni Malinen026331c2010-02-15 12:53:10 +02007880
Johannes Berge247bd902011-11-04 11:18:21 +01007881 genlmsg_end(msg, hdr);
7882 return genlmsg_reply(msg, info);
7883 }
7884
7885 return 0;
Jouni Malinen026331c2010-02-15 12:53:10 +02007886
7887 nla_put_failure:
7888 err = -ENOBUFS;
7889 free_msg:
7890 nlmsg_free(msg);
Jouni Malinen026331c2010-02-15 12:53:10 +02007891 return err;
7892}
7893
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007894static int nl80211_tx_mgmt_cancel_wait(struct sk_buff *skb, struct genl_info *info)
7895{
7896 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02007897 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007898 u64 cookie;
7899
7900 if (!info->attrs[NL80211_ATTR_COOKIE])
7901 return -EINVAL;
7902
7903 if (!rdev->ops->mgmt_tx_cancel_wait)
7904 return -EOPNOTSUPP;
7905
Johannes Berg71bbc992012-06-15 15:30:18 +02007906 switch (wdev->iftype) {
7907 case NL80211_IFTYPE_STATION:
7908 case NL80211_IFTYPE_ADHOC:
7909 case NL80211_IFTYPE_P2P_CLIENT:
7910 case NL80211_IFTYPE_AP:
7911 case NL80211_IFTYPE_AP_VLAN:
7912 case NL80211_IFTYPE_P2P_GO:
Johannes Berg98104fde2012-06-16 00:19:54 +02007913 case NL80211_IFTYPE_P2P_DEVICE:
Johannes Berg71bbc992012-06-15 15:30:18 +02007914 break;
7915 default:
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007916 return -EOPNOTSUPP;
Johannes Berg71bbc992012-06-15 15:30:18 +02007917 }
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007918
7919 cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]);
7920
Hila Gonene35e4d22012-06-27 17:19:42 +03007921 return rdev_mgmt_tx_cancel_wait(rdev, wdev, cookie);
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007922}
7923
Kalle Valoffb9eb32010-02-17 17:58:10 +02007924static int nl80211_set_power_save(struct sk_buff *skb, struct genl_info *info)
7925{
Johannes Berg4c476992010-10-04 21:36:35 +02007926 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Kalle Valoffb9eb32010-02-17 17:58:10 +02007927 struct wireless_dev *wdev;
Johannes Berg4c476992010-10-04 21:36:35 +02007928 struct net_device *dev = info->user_ptr[1];
Kalle Valoffb9eb32010-02-17 17:58:10 +02007929 u8 ps_state;
7930 bool state;
7931 int err;
7932
Johannes Berg4c476992010-10-04 21:36:35 +02007933 if (!info->attrs[NL80211_ATTR_PS_STATE])
7934 return -EINVAL;
Kalle Valoffb9eb32010-02-17 17:58:10 +02007935
7936 ps_state = nla_get_u32(info->attrs[NL80211_ATTR_PS_STATE]);
7937
Johannes Berg4c476992010-10-04 21:36:35 +02007938 if (ps_state != NL80211_PS_DISABLED && ps_state != NL80211_PS_ENABLED)
7939 return -EINVAL;
Kalle Valoffb9eb32010-02-17 17:58:10 +02007940
7941 wdev = dev->ieee80211_ptr;
7942
Johannes Berg4c476992010-10-04 21:36:35 +02007943 if (!rdev->ops->set_power_mgmt)
7944 return -EOPNOTSUPP;
Kalle Valoffb9eb32010-02-17 17:58:10 +02007945
7946 state = (ps_state == NL80211_PS_ENABLED) ? true : false;
7947
7948 if (state == wdev->ps)
Johannes Berg4c476992010-10-04 21:36:35 +02007949 return 0;
Kalle Valoffb9eb32010-02-17 17:58:10 +02007950
Hila Gonene35e4d22012-06-27 17:19:42 +03007951 err = rdev_set_power_mgmt(rdev, dev, state, wdev->ps_timeout);
Johannes Berg4c476992010-10-04 21:36:35 +02007952 if (!err)
7953 wdev->ps = state;
Kalle Valoffb9eb32010-02-17 17:58:10 +02007954 return err;
7955}
7956
7957static int nl80211_get_power_save(struct sk_buff *skb, struct genl_info *info)
7958{
Johannes Berg4c476992010-10-04 21:36:35 +02007959 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Kalle Valoffb9eb32010-02-17 17:58:10 +02007960 enum nl80211_ps_state ps_state;
7961 struct wireless_dev *wdev;
Johannes Berg4c476992010-10-04 21:36:35 +02007962 struct net_device *dev = info->user_ptr[1];
Kalle Valoffb9eb32010-02-17 17:58:10 +02007963 struct sk_buff *msg;
7964 void *hdr;
7965 int err;
7966
Kalle Valoffb9eb32010-02-17 17:58:10 +02007967 wdev = dev->ieee80211_ptr;
7968
Johannes Berg4c476992010-10-04 21:36:35 +02007969 if (!rdev->ops->set_power_mgmt)
7970 return -EOPNOTSUPP;
Kalle Valoffb9eb32010-02-17 17:58:10 +02007971
7972 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02007973 if (!msg)
7974 return -ENOMEM;
Kalle Valoffb9eb32010-02-17 17:58:10 +02007975
Eric W. Biederman15e47302012-09-07 20:12:54 +00007976 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Kalle Valoffb9eb32010-02-17 17:58:10 +02007977 NL80211_CMD_GET_POWER_SAVE);
7978 if (!hdr) {
Johannes Berg4c476992010-10-04 21:36:35 +02007979 err = -ENOBUFS;
Kalle Valoffb9eb32010-02-17 17:58:10 +02007980 goto free_msg;
7981 }
7982
7983 if (wdev->ps)
7984 ps_state = NL80211_PS_ENABLED;
7985 else
7986 ps_state = NL80211_PS_DISABLED;
7987
David S. Miller9360ffd2012-03-29 04:41:26 -04007988 if (nla_put_u32(msg, NL80211_ATTR_PS_STATE, ps_state))
7989 goto nla_put_failure;
Kalle Valoffb9eb32010-02-17 17:58:10 +02007990
7991 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02007992 return genlmsg_reply(msg, info);
Kalle Valoffb9eb32010-02-17 17:58:10 +02007993
Johannes Berg4c476992010-10-04 21:36:35 +02007994 nla_put_failure:
Kalle Valoffb9eb32010-02-17 17:58:10 +02007995 err = -ENOBUFS;
Johannes Berg4c476992010-10-04 21:36:35 +02007996 free_msg:
Kalle Valoffb9eb32010-02-17 17:58:10 +02007997 nlmsg_free(msg);
Kalle Valoffb9eb32010-02-17 17:58:10 +02007998 return err;
7999}
8000
Johannes Berg94e860f2014-01-20 23:58:15 +01008001static const struct nla_policy
8002nl80211_attr_cqm_policy[NL80211_ATTR_CQM_MAX + 1] = {
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008003 [NL80211_ATTR_CQM_RSSI_THOLD] = { .type = NLA_U32 },
8004 [NL80211_ATTR_CQM_RSSI_HYST] = { .type = NLA_U32 },
8005 [NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT] = { .type = NLA_U32 },
Thomas Pedersen84f10702012-07-12 16:17:33 -07008006 [NL80211_ATTR_CQM_TXE_RATE] = { .type = NLA_U32 },
8007 [NL80211_ATTR_CQM_TXE_PKTS] = { .type = NLA_U32 },
8008 [NL80211_ATTR_CQM_TXE_INTVL] = { .type = NLA_U32 },
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008009};
8010
Thomas Pedersen84f10702012-07-12 16:17:33 -07008011static int nl80211_set_cqm_txe(struct genl_info *info,
Johannes Bergd9d8b012012-11-26 12:51:52 +01008012 u32 rate, u32 pkts, u32 intvl)
Thomas Pedersen84f10702012-07-12 16:17:33 -07008013{
8014 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Thomas Pedersen84f10702012-07-12 16:17:33 -07008015 struct net_device *dev = info->user_ptr[1];
Johannes Berg1da5fcc2013-08-06 14:10:48 +02008016 struct wireless_dev *wdev = dev->ieee80211_ptr;
Thomas Pedersen84f10702012-07-12 16:17:33 -07008017
Johannes Bergd9d8b012012-11-26 12:51:52 +01008018 if (rate > 100 || intvl > NL80211_CQM_TXE_MAX_INTVL)
Thomas Pedersen84f10702012-07-12 16:17:33 -07008019 return -EINVAL;
8020
Thomas Pedersen84f10702012-07-12 16:17:33 -07008021 if (!rdev->ops->set_cqm_txe_config)
8022 return -EOPNOTSUPP;
8023
8024 if (wdev->iftype != NL80211_IFTYPE_STATION &&
8025 wdev->iftype != NL80211_IFTYPE_P2P_CLIENT)
8026 return -EOPNOTSUPP;
8027
Hila Gonene35e4d22012-06-27 17:19:42 +03008028 return rdev_set_cqm_txe_config(rdev, dev, rate, pkts, intvl);
Thomas Pedersen84f10702012-07-12 16:17:33 -07008029}
8030
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008031static int nl80211_set_cqm_rssi(struct genl_info *info,
8032 s32 threshold, u32 hysteresis)
8033{
Johannes Berg4c476992010-10-04 21:36:35 +02008034 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg4c476992010-10-04 21:36:35 +02008035 struct net_device *dev = info->user_ptr[1];
Johannes Berg1da5fcc2013-08-06 14:10:48 +02008036 struct wireless_dev *wdev = dev->ieee80211_ptr;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008037
8038 if (threshold > 0)
8039 return -EINVAL;
8040
Johannes Berg1da5fcc2013-08-06 14:10:48 +02008041 /* disabling - hysteresis should also be zero then */
8042 if (threshold == 0)
8043 hysteresis = 0;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008044
Johannes Berg4c476992010-10-04 21:36:35 +02008045 if (!rdev->ops->set_cqm_rssi_config)
8046 return -EOPNOTSUPP;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008047
Johannes Berg074ac8d2010-09-16 14:58:22 +02008048 if (wdev->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02008049 wdev->iftype != NL80211_IFTYPE_P2P_CLIENT)
8050 return -EOPNOTSUPP;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008051
Hila Gonene35e4d22012-06-27 17:19:42 +03008052 return rdev_set_cqm_rssi_config(rdev, dev, threshold, hysteresis);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008053}
8054
8055static int nl80211_set_cqm(struct sk_buff *skb, struct genl_info *info)
8056{
8057 struct nlattr *attrs[NL80211_ATTR_CQM_MAX + 1];
8058 struct nlattr *cqm;
8059 int err;
8060
8061 cqm = info->attrs[NL80211_ATTR_CQM];
Johannes Berg1da5fcc2013-08-06 14:10:48 +02008062 if (!cqm)
8063 return -EINVAL;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008064
8065 err = nla_parse_nested(attrs, NL80211_ATTR_CQM_MAX, cqm,
8066 nl80211_attr_cqm_policy);
8067 if (err)
Johannes Berg1da5fcc2013-08-06 14:10:48 +02008068 return err;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008069
8070 if (attrs[NL80211_ATTR_CQM_RSSI_THOLD] &&
8071 attrs[NL80211_ATTR_CQM_RSSI_HYST]) {
Johannes Berg1da5fcc2013-08-06 14:10:48 +02008072 s32 threshold = nla_get_s32(attrs[NL80211_ATTR_CQM_RSSI_THOLD]);
8073 u32 hysteresis = nla_get_u32(attrs[NL80211_ATTR_CQM_RSSI_HYST]);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008074
Johannes Berg1da5fcc2013-08-06 14:10:48 +02008075 return nl80211_set_cqm_rssi(info, threshold, hysteresis);
8076 }
8077
8078 if (attrs[NL80211_ATTR_CQM_TXE_RATE] &&
8079 attrs[NL80211_ATTR_CQM_TXE_PKTS] &&
8080 attrs[NL80211_ATTR_CQM_TXE_INTVL]) {
8081 u32 rate = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_RATE]);
8082 u32 pkts = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_PKTS]);
8083 u32 intvl = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_INTVL]);
8084
8085 return nl80211_set_cqm_txe(info, rate, pkts, intvl);
8086 }
8087
8088 return -EINVAL;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008089}
8090
Johannes Berg29cbe682010-12-03 09:20:44 +01008091static int nl80211_join_mesh(struct sk_buff *skb, struct genl_info *info)
8092{
8093 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8094 struct net_device *dev = info->user_ptr[1];
8095 struct mesh_config cfg;
Javier Cardonac80d5452010-12-16 17:37:49 -08008096 struct mesh_setup setup;
Johannes Berg29cbe682010-12-03 09:20:44 +01008097 int err;
8098
8099 /* start with default */
8100 memcpy(&cfg, &default_mesh_config, sizeof(cfg));
Javier Cardonac80d5452010-12-16 17:37:49 -08008101 memcpy(&setup, &default_mesh_setup, sizeof(setup));
Johannes Berg29cbe682010-12-03 09:20:44 +01008102
Javier Cardona24bdd9f2010-12-16 17:37:48 -08008103 if (info->attrs[NL80211_ATTR_MESH_CONFIG]) {
Johannes Berg29cbe682010-12-03 09:20:44 +01008104 /* and parse parameters if given */
Javier Cardona24bdd9f2010-12-16 17:37:48 -08008105 err = nl80211_parse_mesh_config(info, &cfg, NULL);
Johannes Berg29cbe682010-12-03 09:20:44 +01008106 if (err)
8107 return err;
8108 }
8109
8110 if (!info->attrs[NL80211_ATTR_MESH_ID] ||
8111 !nla_len(info->attrs[NL80211_ATTR_MESH_ID]))
8112 return -EINVAL;
8113
Javier Cardonac80d5452010-12-16 17:37:49 -08008114 setup.mesh_id = nla_data(info->attrs[NL80211_ATTR_MESH_ID]);
8115 setup.mesh_id_len = nla_len(info->attrs[NL80211_ATTR_MESH_ID]);
8116
Chun-Yeow Yeoh4bb62342011-11-24 17:15:20 -08008117 if (info->attrs[NL80211_ATTR_MCAST_RATE] &&
8118 !nl80211_parse_mcast_rate(rdev, setup.mcast_rate,
8119 nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE])))
8120 return -EINVAL;
8121
Marco Porsch9bdbf042013-01-07 16:04:51 +01008122 if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) {
8123 setup.beacon_interval =
8124 nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]);
8125 if (setup.beacon_interval < 10 ||
8126 setup.beacon_interval > 10000)
8127 return -EINVAL;
8128 }
8129
8130 if (info->attrs[NL80211_ATTR_DTIM_PERIOD]) {
8131 setup.dtim_period =
8132 nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]);
8133 if (setup.dtim_period < 1 || setup.dtim_period > 100)
8134 return -EINVAL;
8135 }
8136
Javier Cardonac80d5452010-12-16 17:37:49 -08008137 if (info->attrs[NL80211_ATTR_MESH_SETUP]) {
8138 /* parse additional setup parameters if given */
8139 err = nl80211_parse_mesh_setup(info, &setup);
8140 if (err)
8141 return err;
8142 }
8143
Thomas Pedersend37bb182013-03-04 13:06:13 -08008144 if (setup.user_mpm)
8145 cfg.auto_open_plinks = false;
8146
Johannes Bergcc1d2802012-05-16 23:50:20 +02008147 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
Johannes Berg683b6d32012-11-08 21:25:48 +01008148 err = nl80211_parse_chandef(rdev, info, &setup.chandef);
8149 if (err)
8150 return err;
Johannes Bergcc1d2802012-05-16 23:50:20 +02008151 } else {
8152 /* cfg80211_join_mesh() will sort it out */
Johannes Berg683b6d32012-11-08 21:25:48 +01008153 setup.chandef.chan = NULL;
Johannes Bergcc1d2802012-05-16 23:50:20 +02008154 }
8155
Ashok Nagarajanffb3cf32013-06-03 10:33:36 -07008156 if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) {
8157 u8 *rates = nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
8158 int n_rates =
8159 nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
8160 struct ieee80211_supported_band *sband;
8161
8162 if (!setup.chandef.chan)
8163 return -EINVAL;
8164
8165 sband = rdev->wiphy.bands[setup.chandef.chan->band];
8166
8167 err = ieee80211_get_ratemask(sband, rates, n_rates,
8168 &setup.basic_rates);
8169 if (err)
8170 return err;
8171 }
8172
Javier Cardonac80d5452010-12-16 17:37:49 -08008173 return cfg80211_join_mesh(rdev, dev, &setup, &cfg);
Johannes Berg29cbe682010-12-03 09:20:44 +01008174}
8175
8176static int nl80211_leave_mesh(struct sk_buff *skb, struct genl_info *info)
8177{
8178 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8179 struct net_device *dev = info->user_ptr[1];
8180
8181 return cfg80211_leave_mesh(rdev, dev);
8182}
8183
Johannes Bergdfb89c52012-06-27 09:23:48 +02008184#ifdef CONFIG_PM
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08008185static int nl80211_send_wowlan_patterns(struct sk_buff *msg,
8186 struct cfg80211_registered_device *rdev)
8187{
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008188 struct cfg80211_wowlan *wowlan = rdev->wiphy.wowlan_config;
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08008189 struct nlattr *nl_pats, *nl_pat;
8190 int i, pat_len;
8191
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008192 if (!wowlan->n_patterns)
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08008193 return 0;
8194
8195 nl_pats = nla_nest_start(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN);
8196 if (!nl_pats)
8197 return -ENOBUFS;
8198
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008199 for (i = 0; i < wowlan->n_patterns; i++) {
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08008200 nl_pat = nla_nest_start(msg, i + 1);
8201 if (!nl_pat)
8202 return -ENOBUFS;
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008203 pat_len = wowlan->patterns[i].pattern_len;
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07008204 if (nla_put(msg, NL80211_PKTPAT_MASK, DIV_ROUND_UP(pat_len, 8),
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008205 wowlan->patterns[i].mask) ||
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07008206 nla_put(msg, NL80211_PKTPAT_PATTERN, pat_len,
8207 wowlan->patterns[i].pattern) ||
8208 nla_put_u32(msg, NL80211_PKTPAT_OFFSET,
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008209 wowlan->patterns[i].pkt_offset))
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08008210 return -ENOBUFS;
8211 nla_nest_end(msg, nl_pat);
8212 }
8213 nla_nest_end(msg, nl_pats);
8214
8215 return 0;
8216}
8217
Johannes Berg2a0e0472013-01-23 22:57:40 +01008218static int nl80211_send_wowlan_tcp(struct sk_buff *msg,
8219 struct cfg80211_wowlan_tcp *tcp)
8220{
8221 struct nlattr *nl_tcp;
8222
8223 if (!tcp)
8224 return 0;
8225
8226 nl_tcp = nla_nest_start(msg, NL80211_WOWLAN_TRIG_TCP_CONNECTION);
8227 if (!nl_tcp)
8228 return -ENOBUFS;
8229
8230 if (nla_put_be32(msg, NL80211_WOWLAN_TCP_SRC_IPV4, tcp->src) ||
8231 nla_put_be32(msg, NL80211_WOWLAN_TCP_DST_IPV4, tcp->dst) ||
8232 nla_put(msg, NL80211_WOWLAN_TCP_DST_MAC, ETH_ALEN, tcp->dst_mac) ||
8233 nla_put_u16(msg, NL80211_WOWLAN_TCP_SRC_PORT, tcp->src_port) ||
8234 nla_put_u16(msg, NL80211_WOWLAN_TCP_DST_PORT, tcp->dst_port) ||
8235 nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD,
8236 tcp->payload_len, tcp->payload) ||
8237 nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_INTERVAL,
8238 tcp->data_interval) ||
8239 nla_put(msg, NL80211_WOWLAN_TCP_WAKE_PAYLOAD,
8240 tcp->wake_len, tcp->wake_data) ||
8241 nla_put(msg, NL80211_WOWLAN_TCP_WAKE_MASK,
8242 DIV_ROUND_UP(tcp->wake_len, 8), tcp->wake_mask))
8243 return -ENOBUFS;
8244
8245 if (tcp->payload_seq.len &&
8246 nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ,
8247 sizeof(tcp->payload_seq), &tcp->payload_seq))
8248 return -ENOBUFS;
8249
8250 if (tcp->payload_tok.len &&
8251 nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN,
8252 sizeof(tcp->payload_tok) + tcp->tokens_size,
8253 &tcp->payload_tok))
8254 return -ENOBUFS;
8255
Johannes Berge248ad32013-05-16 10:24:28 +02008256 nla_nest_end(msg, nl_tcp);
8257
Johannes Berg2a0e0472013-01-23 22:57:40 +01008258 return 0;
8259}
8260
Johannes Bergff1b6e62011-05-04 15:37:28 +02008261static int nl80211_get_wowlan(struct sk_buff *skb, struct genl_info *info)
8262{
8263 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8264 struct sk_buff *msg;
8265 void *hdr;
Johannes Berg2a0e0472013-01-23 22:57:40 +01008266 u32 size = NLMSG_DEFAULT_SIZE;
Johannes Bergff1b6e62011-05-04 15:37:28 +02008267
Johannes Berg964dc9e2013-06-03 17:25:34 +02008268 if (!rdev->wiphy.wowlan)
Johannes Bergff1b6e62011-05-04 15:37:28 +02008269 return -EOPNOTSUPP;
8270
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008271 if (rdev->wiphy.wowlan_config && rdev->wiphy.wowlan_config->tcp) {
Johannes Berg2a0e0472013-01-23 22:57:40 +01008272 /* adjust size to have room for all the data */
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008273 size += rdev->wiphy.wowlan_config->tcp->tokens_size +
8274 rdev->wiphy.wowlan_config->tcp->payload_len +
8275 rdev->wiphy.wowlan_config->tcp->wake_len +
8276 rdev->wiphy.wowlan_config->tcp->wake_len / 8;
Johannes Berg2a0e0472013-01-23 22:57:40 +01008277 }
8278
8279 msg = nlmsg_new(size, GFP_KERNEL);
Johannes Bergff1b6e62011-05-04 15:37:28 +02008280 if (!msg)
8281 return -ENOMEM;
8282
Eric W. Biederman15e47302012-09-07 20:12:54 +00008283 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Johannes Bergff1b6e62011-05-04 15:37:28 +02008284 NL80211_CMD_GET_WOWLAN);
8285 if (!hdr)
8286 goto nla_put_failure;
8287
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008288 if (rdev->wiphy.wowlan_config) {
Johannes Bergff1b6e62011-05-04 15:37:28 +02008289 struct nlattr *nl_wowlan;
8290
8291 nl_wowlan = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS);
8292 if (!nl_wowlan)
8293 goto nla_put_failure;
8294
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008295 if ((rdev->wiphy.wowlan_config->any &&
David S. Miller9360ffd2012-03-29 04:41:26 -04008296 nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008297 (rdev->wiphy.wowlan_config->disconnect &&
David S. Miller9360ffd2012-03-29 04:41:26 -04008298 nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008299 (rdev->wiphy.wowlan_config->magic_pkt &&
David S. Miller9360ffd2012-03-29 04:41:26 -04008300 nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008301 (rdev->wiphy.wowlan_config->gtk_rekey_failure &&
David S. Miller9360ffd2012-03-29 04:41:26 -04008302 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008303 (rdev->wiphy.wowlan_config->eap_identity_req &&
David S. Miller9360ffd2012-03-29 04:41:26 -04008304 nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008305 (rdev->wiphy.wowlan_config->four_way_handshake &&
David S. Miller9360ffd2012-03-29 04:41:26 -04008306 nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008307 (rdev->wiphy.wowlan_config->rfkill_release &&
David S. Miller9360ffd2012-03-29 04:41:26 -04008308 nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE)))
8309 goto nla_put_failure;
Johannes Berg2a0e0472013-01-23 22:57:40 +01008310
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08008311 if (nl80211_send_wowlan_patterns(msg, rdev))
8312 goto nla_put_failure;
Johannes Berg2a0e0472013-01-23 22:57:40 +01008313
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008314 if (nl80211_send_wowlan_tcp(msg,
8315 rdev->wiphy.wowlan_config->tcp))
Johannes Berg2a0e0472013-01-23 22:57:40 +01008316 goto nla_put_failure;
8317
Johannes Bergff1b6e62011-05-04 15:37:28 +02008318 nla_nest_end(msg, nl_wowlan);
8319 }
8320
8321 genlmsg_end(msg, hdr);
8322 return genlmsg_reply(msg, info);
8323
8324nla_put_failure:
8325 nlmsg_free(msg);
8326 return -ENOBUFS;
8327}
8328
Johannes Berg2a0e0472013-01-23 22:57:40 +01008329static int nl80211_parse_wowlan_tcp(struct cfg80211_registered_device *rdev,
8330 struct nlattr *attr,
8331 struct cfg80211_wowlan *trig)
8332{
8333 struct nlattr *tb[NUM_NL80211_WOWLAN_TCP];
8334 struct cfg80211_wowlan_tcp *cfg;
8335 struct nl80211_wowlan_tcp_data_token *tok = NULL;
8336 struct nl80211_wowlan_tcp_data_seq *seq = NULL;
8337 u32 size;
8338 u32 data_size, wake_size, tokens_size = 0, wake_mask_size;
8339 int err, port;
8340
Johannes Berg964dc9e2013-06-03 17:25:34 +02008341 if (!rdev->wiphy.wowlan->tcp)
Johannes Berg2a0e0472013-01-23 22:57:40 +01008342 return -EINVAL;
8343
8344 err = nla_parse(tb, MAX_NL80211_WOWLAN_TCP,
8345 nla_data(attr), nla_len(attr),
8346 nl80211_wowlan_tcp_policy);
8347 if (err)
8348 return err;
8349
8350 if (!tb[NL80211_WOWLAN_TCP_SRC_IPV4] ||
8351 !tb[NL80211_WOWLAN_TCP_DST_IPV4] ||
8352 !tb[NL80211_WOWLAN_TCP_DST_MAC] ||
8353 !tb[NL80211_WOWLAN_TCP_DST_PORT] ||
8354 !tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD] ||
8355 !tb[NL80211_WOWLAN_TCP_DATA_INTERVAL] ||
8356 !tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD] ||
8357 !tb[NL80211_WOWLAN_TCP_WAKE_MASK])
8358 return -EINVAL;
8359
8360 data_size = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]);
Johannes Berg964dc9e2013-06-03 17:25:34 +02008361 if (data_size > rdev->wiphy.wowlan->tcp->data_payload_max)
Johannes Berg2a0e0472013-01-23 22:57:40 +01008362 return -EINVAL;
8363
8364 if (nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]) >
Johannes Berg964dc9e2013-06-03 17:25:34 +02008365 rdev->wiphy.wowlan->tcp->data_interval_max ||
Johannes Berg723d5682013-02-26 13:56:40 +01008366 nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]) == 0)
Johannes Berg2a0e0472013-01-23 22:57:40 +01008367 return -EINVAL;
8368
8369 wake_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]);
Johannes Berg964dc9e2013-06-03 17:25:34 +02008370 if (wake_size > rdev->wiphy.wowlan->tcp->wake_payload_max)
Johannes Berg2a0e0472013-01-23 22:57:40 +01008371 return -EINVAL;
8372
8373 wake_mask_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_MASK]);
8374 if (wake_mask_size != DIV_ROUND_UP(wake_size, 8))
8375 return -EINVAL;
8376
8377 if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]) {
8378 u32 tokln = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]);
8379
8380 tok = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]);
8381 tokens_size = tokln - sizeof(*tok);
8382
8383 if (!tok->len || tokens_size % tok->len)
8384 return -EINVAL;
Johannes Berg964dc9e2013-06-03 17:25:34 +02008385 if (!rdev->wiphy.wowlan->tcp->tok)
Johannes Berg2a0e0472013-01-23 22:57:40 +01008386 return -EINVAL;
Johannes Berg964dc9e2013-06-03 17:25:34 +02008387 if (tok->len > rdev->wiphy.wowlan->tcp->tok->max_len)
Johannes Berg2a0e0472013-01-23 22:57:40 +01008388 return -EINVAL;
Johannes Berg964dc9e2013-06-03 17:25:34 +02008389 if (tok->len < rdev->wiphy.wowlan->tcp->tok->min_len)
Johannes Berg2a0e0472013-01-23 22:57:40 +01008390 return -EINVAL;
Johannes Berg964dc9e2013-06-03 17:25:34 +02008391 if (tokens_size > rdev->wiphy.wowlan->tcp->tok->bufsize)
Johannes Berg2a0e0472013-01-23 22:57:40 +01008392 return -EINVAL;
8393 if (tok->offset + tok->len > data_size)
8394 return -EINVAL;
8395 }
8396
8397 if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]) {
8398 seq = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]);
Johannes Berg964dc9e2013-06-03 17:25:34 +02008399 if (!rdev->wiphy.wowlan->tcp->seq)
Johannes Berg2a0e0472013-01-23 22:57:40 +01008400 return -EINVAL;
8401 if (seq->len == 0 || seq->len > 4)
8402 return -EINVAL;
8403 if (seq->len + seq->offset > data_size)
8404 return -EINVAL;
8405 }
8406
8407 size = sizeof(*cfg);
8408 size += data_size;
8409 size += wake_size + wake_mask_size;
8410 size += tokens_size;
8411
8412 cfg = kzalloc(size, GFP_KERNEL);
8413 if (!cfg)
8414 return -ENOMEM;
8415 cfg->src = nla_get_be32(tb[NL80211_WOWLAN_TCP_SRC_IPV4]);
8416 cfg->dst = nla_get_be32(tb[NL80211_WOWLAN_TCP_DST_IPV4]);
8417 memcpy(cfg->dst_mac, nla_data(tb[NL80211_WOWLAN_TCP_DST_MAC]),
8418 ETH_ALEN);
8419 if (tb[NL80211_WOWLAN_TCP_SRC_PORT])
8420 port = nla_get_u16(tb[NL80211_WOWLAN_TCP_SRC_PORT]);
8421 else
8422 port = 0;
8423#ifdef CONFIG_INET
8424 /* allocate a socket and port for it and use it */
8425 err = __sock_create(wiphy_net(&rdev->wiphy), PF_INET, SOCK_STREAM,
8426 IPPROTO_TCP, &cfg->sock, 1);
8427 if (err) {
8428 kfree(cfg);
8429 return err;
8430 }
8431 if (inet_csk_get_port(cfg->sock->sk, port)) {
8432 sock_release(cfg->sock);
8433 kfree(cfg);
8434 return -EADDRINUSE;
8435 }
8436 cfg->src_port = inet_sk(cfg->sock->sk)->inet_num;
8437#else
8438 if (!port) {
8439 kfree(cfg);
8440 return -EINVAL;
8441 }
8442 cfg->src_port = port;
8443#endif
8444
8445 cfg->dst_port = nla_get_u16(tb[NL80211_WOWLAN_TCP_DST_PORT]);
8446 cfg->payload_len = data_size;
8447 cfg->payload = (u8 *)cfg + sizeof(*cfg) + tokens_size;
8448 memcpy((void *)cfg->payload,
8449 nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]),
8450 data_size);
8451 if (seq)
8452 cfg->payload_seq = *seq;
8453 cfg->data_interval = nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]);
8454 cfg->wake_len = wake_size;
8455 cfg->wake_data = (u8 *)cfg + sizeof(*cfg) + tokens_size + data_size;
8456 memcpy((void *)cfg->wake_data,
8457 nla_data(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]),
8458 wake_size);
8459 cfg->wake_mask = (u8 *)cfg + sizeof(*cfg) + tokens_size +
8460 data_size + wake_size;
8461 memcpy((void *)cfg->wake_mask,
8462 nla_data(tb[NL80211_WOWLAN_TCP_WAKE_MASK]),
8463 wake_mask_size);
8464 if (tok) {
8465 cfg->tokens_size = tokens_size;
8466 memcpy(&cfg->payload_tok, tok, sizeof(*tok) + tokens_size);
8467 }
8468
8469 trig->tcp = cfg;
8470
8471 return 0;
8472}
8473
Johannes Bergff1b6e62011-05-04 15:37:28 +02008474static int nl80211_set_wowlan(struct sk_buff *skb, struct genl_info *info)
8475{
8476 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8477 struct nlattr *tb[NUM_NL80211_WOWLAN_TRIG];
Johannes Bergff1b6e62011-05-04 15:37:28 +02008478 struct cfg80211_wowlan new_triggers = {};
Johannes Bergae33bd82012-07-12 16:25:02 +02008479 struct cfg80211_wowlan *ntrig;
Johannes Berg964dc9e2013-06-03 17:25:34 +02008480 const struct wiphy_wowlan_support *wowlan = rdev->wiphy.wowlan;
Johannes Bergff1b6e62011-05-04 15:37:28 +02008481 int err, i;
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008482 bool prev_enabled = rdev->wiphy.wowlan_config;
Johannes Bergff1b6e62011-05-04 15:37:28 +02008483
Johannes Berg964dc9e2013-06-03 17:25:34 +02008484 if (!wowlan)
Johannes Bergff1b6e62011-05-04 15:37:28 +02008485 return -EOPNOTSUPP;
8486
Johannes Bergae33bd82012-07-12 16:25:02 +02008487 if (!info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]) {
8488 cfg80211_rdev_free_wowlan(rdev);
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008489 rdev->wiphy.wowlan_config = NULL;
Johannes Bergae33bd82012-07-12 16:25:02 +02008490 goto set_wakeup;
8491 }
Johannes Bergff1b6e62011-05-04 15:37:28 +02008492
8493 err = nla_parse(tb, MAX_NL80211_WOWLAN_TRIG,
8494 nla_data(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]),
8495 nla_len(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]),
8496 nl80211_wowlan_policy);
8497 if (err)
8498 return err;
8499
8500 if (tb[NL80211_WOWLAN_TRIG_ANY]) {
8501 if (!(wowlan->flags & WIPHY_WOWLAN_ANY))
8502 return -EINVAL;
8503 new_triggers.any = true;
8504 }
8505
8506 if (tb[NL80211_WOWLAN_TRIG_DISCONNECT]) {
8507 if (!(wowlan->flags & WIPHY_WOWLAN_DISCONNECT))
8508 return -EINVAL;
8509 new_triggers.disconnect = true;
8510 }
8511
8512 if (tb[NL80211_WOWLAN_TRIG_MAGIC_PKT]) {
8513 if (!(wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT))
8514 return -EINVAL;
8515 new_triggers.magic_pkt = true;
8516 }
8517
Johannes Berg77dbbb12011-07-13 10:48:55 +02008518 if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED])
8519 return -EINVAL;
8520
8521 if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE]) {
8522 if (!(wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE))
8523 return -EINVAL;
8524 new_triggers.gtk_rekey_failure = true;
8525 }
8526
8527 if (tb[NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST]) {
8528 if (!(wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ))
8529 return -EINVAL;
8530 new_triggers.eap_identity_req = true;
8531 }
8532
8533 if (tb[NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE]) {
8534 if (!(wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE))
8535 return -EINVAL;
8536 new_triggers.four_way_handshake = true;
8537 }
8538
8539 if (tb[NL80211_WOWLAN_TRIG_RFKILL_RELEASE]) {
8540 if (!(wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE))
8541 return -EINVAL;
8542 new_triggers.rfkill_release = true;
8543 }
8544
Johannes Bergff1b6e62011-05-04 15:37:28 +02008545 if (tb[NL80211_WOWLAN_TRIG_PKT_PATTERN]) {
8546 struct nlattr *pat;
8547 int n_patterns = 0;
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08008548 int rem, pat_len, mask_len, pkt_offset;
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07008549 struct nlattr *pat_tb[NUM_NL80211_PKTPAT];
Johannes Bergff1b6e62011-05-04 15:37:28 +02008550
8551 nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN],
8552 rem)
8553 n_patterns++;
8554 if (n_patterns > wowlan->n_patterns)
8555 return -EINVAL;
8556
8557 new_triggers.patterns = kcalloc(n_patterns,
8558 sizeof(new_triggers.patterns[0]),
8559 GFP_KERNEL);
8560 if (!new_triggers.patterns)
8561 return -ENOMEM;
8562
8563 new_triggers.n_patterns = n_patterns;
8564 i = 0;
8565
8566 nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN],
8567 rem) {
Johannes Berg922bd802014-05-19 17:59:50 +02008568 u8 *mask_pat;
8569
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07008570 nla_parse(pat_tb, MAX_NL80211_PKTPAT, nla_data(pat),
8571 nla_len(pat), NULL);
Johannes Bergff1b6e62011-05-04 15:37:28 +02008572 err = -EINVAL;
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07008573 if (!pat_tb[NL80211_PKTPAT_MASK] ||
8574 !pat_tb[NL80211_PKTPAT_PATTERN])
Johannes Bergff1b6e62011-05-04 15:37:28 +02008575 goto error;
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07008576 pat_len = nla_len(pat_tb[NL80211_PKTPAT_PATTERN]);
Johannes Bergff1b6e62011-05-04 15:37:28 +02008577 mask_len = DIV_ROUND_UP(pat_len, 8);
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07008578 if (nla_len(pat_tb[NL80211_PKTPAT_MASK]) != mask_len)
Johannes Bergff1b6e62011-05-04 15:37:28 +02008579 goto error;
8580 if (pat_len > wowlan->pattern_max_len ||
8581 pat_len < wowlan->pattern_min_len)
8582 goto error;
8583
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07008584 if (!pat_tb[NL80211_PKTPAT_OFFSET])
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08008585 pkt_offset = 0;
8586 else
8587 pkt_offset = nla_get_u32(
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07008588 pat_tb[NL80211_PKTPAT_OFFSET]);
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08008589 if (pkt_offset > wowlan->max_pkt_offset)
8590 goto error;
8591 new_triggers.patterns[i].pkt_offset = pkt_offset;
8592
Johannes Berg922bd802014-05-19 17:59:50 +02008593 mask_pat = kmalloc(mask_len + pat_len, GFP_KERNEL);
8594 if (!mask_pat) {
Johannes Bergff1b6e62011-05-04 15:37:28 +02008595 err = -ENOMEM;
8596 goto error;
8597 }
Johannes Berg922bd802014-05-19 17:59:50 +02008598 new_triggers.patterns[i].mask = mask_pat;
8599 memcpy(mask_pat, nla_data(pat_tb[NL80211_PKTPAT_MASK]),
Johannes Bergff1b6e62011-05-04 15:37:28 +02008600 mask_len);
Johannes Berg922bd802014-05-19 17:59:50 +02008601 mask_pat += mask_len;
8602 new_triggers.patterns[i].pattern = mask_pat;
Johannes Bergff1b6e62011-05-04 15:37:28 +02008603 new_triggers.patterns[i].pattern_len = pat_len;
Johannes Berg922bd802014-05-19 17:59:50 +02008604 memcpy(mask_pat,
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07008605 nla_data(pat_tb[NL80211_PKTPAT_PATTERN]),
Johannes Bergff1b6e62011-05-04 15:37:28 +02008606 pat_len);
8607 i++;
8608 }
8609 }
8610
Johannes Berg2a0e0472013-01-23 22:57:40 +01008611 if (tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION]) {
8612 err = nl80211_parse_wowlan_tcp(
8613 rdev, tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION],
8614 &new_triggers);
8615 if (err)
8616 goto error;
8617 }
8618
Johannes Bergae33bd82012-07-12 16:25:02 +02008619 ntrig = kmemdup(&new_triggers, sizeof(new_triggers), GFP_KERNEL);
8620 if (!ntrig) {
8621 err = -ENOMEM;
8622 goto error;
Johannes Bergff1b6e62011-05-04 15:37:28 +02008623 }
Johannes Bergae33bd82012-07-12 16:25:02 +02008624 cfg80211_rdev_free_wowlan(rdev);
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008625 rdev->wiphy.wowlan_config = ntrig;
Johannes Bergff1b6e62011-05-04 15:37:28 +02008626
Johannes Bergae33bd82012-07-12 16:25:02 +02008627 set_wakeup:
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008628 if (rdev->ops->set_wakeup &&
8629 prev_enabled != !!rdev->wiphy.wowlan_config)
8630 rdev_set_wakeup(rdev, rdev->wiphy.wowlan_config);
Johannes Berg6d525632012-04-04 15:05:25 +02008631
Johannes Bergff1b6e62011-05-04 15:37:28 +02008632 return 0;
8633 error:
8634 for (i = 0; i < new_triggers.n_patterns; i++)
8635 kfree(new_triggers.patterns[i].mask);
8636 kfree(new_triggers.patterns);
Johannes Berg2a0e0472013-01-23 22:57:40 +01008637 if (new_triggers.tcp && new_triggers.tcp->sock)
8638 sock_release(new_triggers.tcp->sock);
8639 kfree(new_triggers.tcp);
Johannes Bergff1b6e62011-05-04 15:37:28 +02008640 return err;
8641}
Johannes Bergdfb89c52012-06-27 09:23:48 +02008642#endif
Johannes Bergff1b6e62011-05-04 15:37:28 +02008643
Amitkumar Karwarbe29b992013-06-28 11:51:26 -07008644static int nl80211_send_coalesce_rules(struct sk_buff *msg,
8645 struct cfg80211_registered_device *rdev)
8646{
8647 struct nlattr *nl_pats, *nl_pat, *nl_rule, *nl_rules;
8648 int i, j, pat_len;
8649 struct cfg80211_coalesce_rules *rule;
8650
8651 if (!rdev->coalesce->n_rules)
8652 return 0;
8653
8654 nl_rules = nla_nest_start(msg, NL80211_ATTR_COALESCE_RULE);
8655 if (!nl_rules)
8656 return -ENOBUFS;
8657
8658 for (i = 0; i < rdev->coalesce->n_rules; i++) {
8659 nl_rule = nla_nest_start(msg, i + 1);
8660 if (!nl_rule)
8661 return -ENOBUFS;
8662
8663 rule = &rdev->coalesce->rules[i];
8664 if (nla_put_u32(msg, NL80211_ATTR_COALESCE_RULE_DELAY,
8665 rule->delay))
8666 return -ENOBUFS;
8667
8668 if (nla_put_u32(msg, NL80211_ATTR_COALESCE_RULE_CONDITION,
8669 rule->condition))
8670 return -ENOBUFS;
8671
8672 nl_pats = nla_nest_start(msg,
8673 NL80211_ATTR_COALESCE_RULE_PKT_PATTERN);
8674 if (!nl_pats)
8675 return -ENOBUFS;
8676
8677 for (j = 0; j < rule->n_patterns; j++) {
8678 nl_pat = nla_nest_start(msg, j + 1);
8679 if (!nl_pat)
8680 return -ENOBUFS;
8681 pat_len = rule->patterns[j].pattern_len;
8682 if (nla_put(msg, NL80211_PKTPAT_MASK,
8683 DIV_ROUND_UP(pat_len, 8),
8684 rule->patterns[j].mask) ||
8685 nla_put(msg, NL80211_PKTPAT_PATTERN, pat_len,
8686 rule->patterns[j].pattern) ||
8687 nla_put_u32(msg, NL80211_PKTPAT_OFFSET,
8688 rule->patterns[j].pkt_offset))
8689 return -ENOBUFS;
8690 nla_nest_end(msg, nl_pat);
8691 }
8692 nla_nest_end(msg, nl_pats);
8693 nla_nest_end(msg, nl_rule);
8694 }
8695 nla_nest_end(msg, nl_rules);
8696
8697 return 0;
8698}
8699
8700static int nl80211_get_coalesce(struct sk_buff *skb, struct genl_info *info)
8701{
8702 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8703 struct sk_buff *msg;
8704 void *hdr;
8705
8706 if (!rdev->wiphy.coalesce)
8707 return -EOPNOTSUPP;
8708
8709 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
8710 if (!msg)
8711 return -ENOMEM;
8712
8713 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
8714 NL80211_CMD_GET_COALESCE);
8715 if (!hdr)
8716 goto nla_put_failure;
8717
8718 if (rdev->coalesce && nl80211_send_coalesce_rules(msg, rdev))
8719 goto nla_put_failure;
8720
8721 genlmsg_end(msg, hdr);
8722 return genlmsg_reply(msg, info);
8723
8724nla_put_failure:
8725 nlmsg_free(msg);
8726 return -ENOBUFS;
8727}
8728
8729void cfg80211_rdev_free_coalesce(struct cfg80211_registered_device *rdev)
8730{
8731 struct cfg80211_coalesce *coalesce = rdev->coalesce;
8732 int i, j;
8733 struct cfg80211_coalesce_rules *rule;
8734
8735 if (!coalesce)
8736 return;
8737
8738 for (i = 0; i < coalesce->n_rules; i++) {
8739 rule = &coalesce->rules[i];
8740 for (j = 0; j < rule->n_patterns; j++)
8741 kfree(rule->patterns[j].mask);
8742 kfree(rule->patterns);
8743 }
8744 kfree(coalesce->rules);
8745 kfree(coalesce);
8746 rdev->coalesce = NULL;
8747}
8748
8749static int nl80211_parse_coalesce_rule(struct cfg80211_registered_device *rdev,
8750 struct nlattr *rule,
8751 struct cfg80211_coalesce_rules *new_rule)
8752{
8753 int err, i;
8754 const struct wiphy_coalesce_support *coalesce = rdev->wiphy.coalesce;
8755 struct nlattr *tb[NUM_NL80211_ATTR_COALESCE_RULE], *pat;
8756 int rem, pat_len, mask_len, pkt_offset, n_patterns = 0;
8757 struct nlattr *pat_tb[NUM_NL80211_PKTPAT];
8758
8759 err = nla_parse(tb, NL80211_ATTR_COALESCE_RULE_MAX, nla_data(rule),
8760 nla_len(rule), nl80211_coalesce_policy);
8761 if (err)
8762 return err;
8763
8764 if (tb[NL80211_ATTR_COALESCE_RULE_DELAY])
8765 new_rule->delay =
8766 nla_get_u32(tb[NL80211_ATTR_COALESCE_RULE_DELAY]);
8767 if (new_rule->delay > coalesce->max_delay)
8768 return -EINVAL;
8769
8770 if (tb[NL80211_ATTR_COALESCE_RULE_CONDITION])
8771 new_rule->condition =
8772 nla_get_u32(tb[NL80211_ATTR_COALESCE_RULE_CONDITION]);
8773 if (new_rule->condition != NL80211_COALESCE_CONDITION_MATCH &&
8774 new_rule->condition != NL80211_COALESCE_CONDITION_NO_MATCH)
8775 return -EINVAL;
8776
8777 if (!tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN])
8778 return -EINVAL;
8779
8780 nla_for_each_nested(pat, tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN],
8781 rem)
8782 n_patterns++;
8783 if (n_patterns > coalesce->n_patterns)
8784 return -EINVAL;
8785
8786 new_rule->patterns = kcalloc(n_patterns, sizeof(new_rule->patterns[0]),
8787 GFP_KERNEL);
8788 if (!new_rule->patterns)
8789 return -ENOMEM;
8790
8791 new_rule->n_patterns = n_patterns;
8792 i = 0;
8793
8794 nla_for_each_nested(pat, tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN],
8795 rem) {
Johannes Berg922bd802014-05-19 17:59:50 +02008796 u8 *mask_pat;
8797
Amitkumar Karwarbe29b992013-06-28 11:51:26 -07008798 nla_parse(pat_tb, MAX_NL80211_PKTPAT, nla_data(pat),
8799 nla_len(pat), NULL);
8800 if (!pat_tb[NL80211_PKTPAT_MASK] ||
8801 !pat_tb[NL80211_PKTPAT_PATTERN])
8802 return -EINVAL;
8803 pat_len = nla_len(pat_tb[NL80211_PKTPAT_PATTERN]);
8804 mask_len = DIV_ROUND_UP(pat_len, 8);
8805 if (nla_len(pat_tb[NL80211_PKTPAT_MASK]) != mask_len)
8806 return -EINVAL;
8807 if (pat_len > coalesce->pattern_max_len ||
8808 pat_len < coalesce->pattern_min_len)
8809 return -EINVAL;
8810
8811 if (!pat_tb[NL80211_PKTPAT_OFFSET])
8812 pkt_offset = 0;
8813 else
8814 pkt_offset = nla_get_u32(pat_tb[NL80211_PKTPAT_OFFSET]);
8815 if (pkt_offset > coalesce->max_pkt_offset)
8816 return -EINVAL;
8817 new_rule->patterns[i].pkt_offset = pkt_offset;
8818
Johannes Berg922bd802014-05-19 17:59:50 +02008819 mask_pat = kmalloc(mask_len + pat_len, GFP_KERNEL);
8820 if (!mask_pat)
Amitkumar Karwarbe29b992013-06-28 11:51:26 -07008821 return -ENOMEM;
Johannes Berg922bd802014-05-19 17:59:50 +02008822
8823 new_rule->patterns[i].mask = mask_pat;
8824 memcpy(mask_pat, nla_data(pat_tb[NL80211_PKTPAT_MASK]),
8825 mask_len);
8826
8827 mask_pat += mask_len;
8828 new_rule->patterns[i].pattern = mask_pat;
Amitkumar Karwarbe29b992013-06-28 11:51:26 -07008829 new_rule->patterns[i].pattern_len = pat_len;
Johannes Berg922bd802014-05-19 17:59:50 +02008830 memcpy(mask_pat, nla_data(pat_tb[NL80211_PKTPAT_PATTERN]),
8831 pat_len);
Amitkumar Karwarbe29b992013-06-28 11:51:26 -07008832 i++;
8833 }
8834
8835 return 0;
8836}
8837
8838static int nl80211_set_coalesce(struct sk_buff *skb, struct genl_info *info)
8839{
8840 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8841 const struct wiphy_coalesce_support *coalesce = rdev->wiphy.coalesce;
8842 struct cfg80211_coalesce new_coalesce = {};
8843 struct cfg80211_coalesce *n_coalesce;
8844 int err, rem_rule, n_rules = 0, i, j;
8845 struct nlattr *rule;
8846 struct cfg80211_coalesce_rules *tmp_rule;
8847
8848 if (!rdev->wiphy.coalesce || !rdev->ops->set_coalesce)
8849 return -EOPNOTSUPP;
8850
8851 if (!info->attrs[NL80211_ATTR_COALESCE_RULE]) {
8852 cfg80211_rdev_free_coalesce(rdev);
8853 rdev->ops->set_coalesce(&rdev->wiphy, NULL);
8854 return 0;
8855 }
8856
8857 nla_for_each_nested(rule, info->attrs[NL80211_ATTR_COALESCE_RULE],
8858 rem_rule)
8859 n_rules++;
8860 if (n_rules > coalesce->n_rules)
8861 return -EINVAL;
8862
8863 new_coalesce.rules = kcalloc(n_rules, sizeof(new_coalesce.rules[0]),
8864 GFP_KERNEL);
8865 if (!new_coalesce.rules)
8866 return -ENOMEM;
8867
8868 new_coalesce.n_rules = n_rules;
8869 i = 0;
8870
8871 nla_for_each_nested(rule, info->attrs[NL80211_ATTR_COALESCE_RULE],
8872 rem_rule) {
8873 err = nl80211_parse_coalesce_rule(rdev, rule,
8874 &new_coalesce.rules[i]);
8875 if (err)
8876 goto error;
8877
8878 i++;
8879 }
8880
8881 err = rdev->ops->set_coalesce(&rdev->wiphy, &new_coalesce);
8882 if (err)
8883 goto error;
8884
8885 n_coalesce = kmemdup(&new_coalesce, sizeof(new_coalesce), GFP_KERNEL);
8886 if (!n_coalesce) {
8887 err = -ENOMEM;
8888 goto error;
8889 }
8890 cfg80211_rdev_free_coalesce(rdev);
8891 rdev->coalesce = n_coalesce;
8892
8893 return 0;
8894error:
8895 for (i = 0; i < new_coalesce.n_rules; i++) {
8896 tmp_rule = &new_coalesce.rules[i];
8897 for (j = 0; j < tmp_rule->n_patterns; j++)
8898 kfree(tmp_rule->patterns[j].mask);
8899 kfree(tmp_rule->patterns);
8900 }
8901 kfree(new_coalesce.rules);
8902
8903 return err;
8904}
8905
Johannes Berge5497d72011-07-05 16:35:40 +02008906static int nl80211_set_rekey_data(struct sk_buff *skb, struct genl_info *info)
8907{
8908 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8909 struct net_device *dev = info->user_ptr[1];
8910 struct wireless_dev *wdev = dev->ieee80211_ptr;
8911 struct nlattr *tb[NUM_NL80211_REKEY_DATA];
8912 struct cfg80211_gtk_rekey_data rekey_data;
8913 int err;
8914
8915 if (!info->attrs[NL80211_ATTR_REKEY_DATA])
8916 return -EINVAL;
8917
8918 err = nla_parse(tb, MAX_NL80211_REKEY_DATA,
8919 nla_data(info->attrs[NL80211_ATTR_REKEY_DATA]),
8920 nla_len(info->attrs[NL80211_ATTR_REKEY_DATA]),
8921 nl80211_rekey_policy);
8922 if (err)
8923 return err;
8924
8925 if (nla_len(tb[NL80211_REKEY_DATA_REPLAY_CTR]) != NL80211_REPLAY_CTR_LEN)
8926 return -ERANGE;
8927 if (nla_len(tb[NL80211_REKEY_DATA_KEK]) != NL80211_KEK_LEN)
8928 return -ERANGE;
8929 if (nla_len(tb[NL80211_REKEY_DATA_KCK]) != NL80211_KCK_LEN)
8930 return -ERANGE;
8931
8932 memcpy(rekey_data.kek, nla_data(tb[NL80211_REKEY_DATA_KEK]),
8933 NL80211_KEK_LEN);
8934 memcpy(rekey_data.kck, nla_data(tb[NL80211_REKEY_DATA_KCK]),
8935 NL80211_KCK_LEN);
8936 memcpy(rekey_data.replay_ctr,
8937 nla_data(tb[NL80211_REKEY_DATA_REPLAY_CTR]),
8938 NL80211_REPLAY_CTR_LEN);
8939
8940 wdev_lock(wdev);
8941 if (!wdev->current_bss) {
8942 err = -ENOTCONN;
8943 goto out;
8944 }
8945
8946 if (!rdev->ops->set_rekey_data) {
8947 err = -EOPNOTSUPP;
8948 goto out;
8949 }
8950
Hila Gonene35e4d22012-06-27 17:19:42 +03008951 err = rdev_set_rekey_data(rdev, dev, &rekey_data);
Johannes Berge5497d72011-07-05 16:35:40 +02008952 out:
8953 wdev_unlock(wdev);
8954 return err;
8955}
8956
Johannes Berg28946da2011-11-04 11:18:12 +01008957static int nl80211_register_unexpected_frame(struct sk_buff *skb,
8958 struct genl_info *info)
8959{
8960 struct net_device *dev = info->user_ptr[1];
8961 struct wireless_dev *wdev = dev->ieee80211_ptr;
8962
8963 if (wdev->iftype != NL80211_IFTYPE_AP &&
8964 wdev->iftype != NL80211_IFTYPE_P2P_GO)
8965 return -EINVAL;
8966
Eric W. Biederman15e47302012-09-07 20:12:54 +00008967 if (wdev->ap_unexpected_nlportid)
Johannes Berg28946da2011-11-04 11:18:12 +01008968 return -EBUSY;
8969
Eric W. Biederman15e47302012-09-07 20:12:54 +00008970 wdev->ap_unexpected_nlportid = info->snd_portid;
Johannes Berg28946da2011-11-04 11:18:12 +01008971 return 0;
8972}
8973
Johannes Berg7f6cf312011-11-04 11:18:15 +01008974static int nl80211_probe_client(struct sk_buff *skb,
8975 struct genl_info *info)
8976{
8977 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8978 struct net_device *dev = info->user_ptr[1];
8979 struct wireless_dev *wdev = dev->ieee80211_ptr;
8980 struct sk_buff *msg;
8981 void *hdr;
8982 const u8 *addr;
8983 u64 cookie;
8984 int err;
8985
8986 if (wdev->iftype != NL80211_IFTYPE_AP &&
8987 wdev->iftype != NL80211_IFTYPE_P2P_GO)
8988 return -EOPNOTSUPP;
8989
8990 if (!info->attrs[NL80211_ATTR_MAC])
8991 return -EINVAL;
8992
8993 if (!rdev->ops->probe_client)
8994 return -EOPNOTSUPP;
8995
8996 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
8997 if (!msg)
8998 return -ENOMEM;
8999
Eric W. Biederman15e47302012-09-07 20:12:54 +00009000 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berg7f6cf312011-11-04 11:18:15 +01009001 NL80211_CMD_PROBE_CLIENT);
Dan Carpentercb35fba2013-08-14 14:50:01 +03009002 if (!hdr) {
9003 err = -ENOBUFS;
Johannes Berg7f6cf312011-11-04 11:18:15 +01009004 goto free_msg;
9005 }
9006
9007 addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
9008
Hila Gonene35e4d22012-06-27 17:19:42 +03009009 err = rdev_probe_client(rdev, dev, addr, &cookie);
Johannes Berg7f6cf312011-11-04 11:18:15 +01009010 if (err)
9011 goto free_msg;
9012
David S. Miller9360ffd2012-03-29 04:41:26 -04009013 if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie))
9014 goto nla_put_failure;
Johannes Berg7f6cf312011-11-04 11:18:15 +01009015
9016 genlmsg_end(msg, hdr);
9017
9018 return genlmsg_reply(msg, info);
9019
9020 nla_put_failure:
9021 err = -ENOBUFS;
9022 free_msg:
9023 nlmsg_free(msg);
9024 return err;
9025}
9026
Johannes Berg5e7602302011-11-04 11:18:17 +01009027static int nl80211_register_beacons(struct sk_buff *skb, struct genl_info *info)
9028{
9029 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Ben Greear37c73b52012-10-26 14:49:25 -07009030 struct cfg80211_beacon_registration *reg, *nreg;
9031 int rv;
Johannes Berg5e7602302011-11-04 11:18:17 +01009032
9033 if (!(rdev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS))
9034 return -EOPNOTSUPP;
9035
Ben Greear37c73b52012-10-26 14:49:25 -07009036 nreg = kzalloc(sizeof(*nreg), GFP_KERNEL);
9037 if (!nreg)
9038 return -ENOMEM;
Johannes Berg5e7602302011-11-04 11:18:17 +01009039
Ben Greear37c73b52012-10-26 14:49:25 -07009040 /* First, check if already registered. */
9041 spin_lock_bh(&rdev->beacon_registrations_lock);
9042 list_for_each_entry(reg, &rdev->beacon_registrations, list) {
9043 if (reg->nlportid == info->snd_portid) {
9044 rv = -EALREADY;
9045 goto out_err;
9046 }
9047 }
9048 /* Add it to the list */
9049 nreg->nlportid = info->snd_portid;
9050 list_add(&nreg->list, &rdev->beacon_registrations);
9051
9052 spin_unlock_bh(&rdev->beacon_registrations_lock);
Johannes Berg5e7602302011-11-04 11:18:17 +01009053
9054 return 0;
Ben Greear37c73b52012-10-26 14:49:25 -07009055out_err:
9056 spin_unlock_bh(&rdev->beacon_registrations_lock);
9057 kfree(nreg);
9058 return rv;
Johannes Berg5e7602302011-11-04 11:18:17 +01009059}
9060
Johannes Berg98104fde2012-06-16 00:19:54 +02009061static int nl80211_start_p2p_device(struct sk_buff *skb, struct genl_info *info)
9062{
9063 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9064 struct wireless_dev *wdev = info->user_ptr[1];
9065 int err;
9066
9067 if (!rdev->ops->start_p2p_device)
9068 return -EOPNOTSUPP;
9069
9070 if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE)
9071 return -EOPNOTSUPP;
9072
9073 if (wdev->p2p_started)
9074 return 0;
9075
Luciano Coelhob6a55012014-02-27 11:07:21 +02009076 if (rfkill_blocked(rdev->rfkill))
9077 return -ERFKILL;
Johannes Berg98104fde2012-06-16 00:19:54 +02009078
Johannes Bergeeb126e2012-10-23 15:16:50 +02009079 err = rdev_start_p2p_device(rdev, wdev);
Johannes Berg98104fde2012-06-16 00:19:54 +02009080 if (err)
9081 return err;
9082
9083 wdev->p2p_started = true;
Johannes Berg98104fde2012-06-16 00:19:54 +02009084 rdev->opencount++;
Johannes Berg98104fde2012-06-16 00:19:54 +02009085
9086 return 0;
9087}
9088
9089static int nl80211_stop_p2p_device(struct sk_buff *skb, struct genl_info *info)
9090{
9091 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9092 struct wireless_dev *wdev = info->user_ptr[1];
9093
9094 if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE)
9095 return -EOPNOTSUPP;
9096
9097 if (!rdev->ops->stop_p2p_device)
9098 return -EOPNOTSUPP;
9099
Johannes Bergf9f47522013-03-19 15:04:07 +01009100 cfg80211_stop_p2p_device(rdev, wdev);
Johannes Berg98104fde2012-06-16 00:19:54 +02009101
9102 return 0;
9103}
9104
Johannes Berg3713b4e2013-02-14 16:19:38 +01009105static int nl80211_get_protocol_features(struct sk_buff *skb,
9106 struct genl_info *info)
9107{
9108 void *hdr;
9109 struct sk_buff *msg;
9110
9111 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
9112 if (!msg)
9113 return -ENOMEM;
9114
9115 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
9116 NL80211_CMD_GET_PROTOCOL_FEATURES);
9117 if (!hdr)
9118 goto nla_put_failure;
9119
9120 if (nla_put_u32(msg, NL80211_ATTR_PROTOCOL_FEATURES,
9121 NL80211_PROTOCOL_FEATURE_SPLIT_WIPHY_DUMP))
9122 goto nla_put_failure;
9123
9124 genlmsg_end(msg, hdr);
9125 return genlmsg_reply(msg, info);
9126
9127 nla_put_failure:
9128 kfree_skb(msg);
9129 return -ENOBUFS;
9130}
9131
Jouni Malinen355199e2013-02-27 17:14:27 +02009132static int nl80211_update_ft_ies(struct sk_buff *skb, struct genl_info *info)
9133{
9134 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9135 struct cfg80211_update_ft_ies_params ft_params;
9136 struct net_device *dev = info->user_ptr[1];
9137
9138 if (!rdev->ops->update_ft_ies)
9139 return -EOPNOTSUPP;
9140
9141 if (!info->attrs[NL80211_ATTR_MDID] ||
9142 !is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
9143 return -EINVAL;
9144
9145 memset(&ft_params, 0, sizeof(ft_params));
9146 ft_params.md = nla_get_u16(info->attrs[NL80211_ATTR_MDID]);
9147 ft_params.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
9148 ft_params.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
9149
9150 return rdev_update_ft_ies(rdev, dev, &ft_params);
9151}
9152
Arend van Spriel5de17982013-04-18 15:49:00 +02009153static int nl80211_crit_protocol_start(struct sk_buff *skb,
9154 struct genl_info *info)
9155{
9156 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9157 struct wireless_dev *wdev = info->user_ptr[1];
9158 enum nl80211_crit_proto_id proto = NL80211_CRIT_PROTO_UNSPEC;
9159 u16 duration;
9160 int ret;
9161
9162 if (!rdev->ops->crit_proto_start)
9163 return -EOPNOTSUPP;
9164
9165 if (WARN_ON(!rdev->ops->crit_proto_stop))
9166 return -EINVAL;
9167
9168 if (rdev->crit_proto_nlportid)
9169 return -EBUSY;
9170
9171 /* determine protocol if provided */
9172 if (info->attrs[NL80211_ATTR_CRIT_PROT_ID])
9173 proto = nla_get_u16(info->attrs[NL80211_ATTR_CRIT_PROT_ID]);
9174
9175 if (proto >= NUM_NL80211_CRIT_PROTO)
9176 return -EINVAL;
9177
9178 /* timeout must be provided */
9179 if (!info->attrs[NL80211_ATTR_MAX_CRIT_PROT_DURATION])
9180 return -EINVAL;
9181
9182 duration =
9183 nla_get_u16(info->attrs[NL80211_ATTR_MAX_CRIT_PROT_DURATION]);
9184
9185 if (duration > NL80211_CRIT_PROTO_MAX_DURATION)
9186 return -ERANGE;
9187
9188 ret = rdev_crit_proto_start(rdev, wdev, proto, duration);
9189 if (!ret)
9190 rdev->crit_proto_nlportid = info->snd_portid;
9191
9192 return ret;
9193}
9194
9195static int nl80211_crit_protocol_stop(struct sk_buff *skb,
9196 struct genl_info *info)
9197{
9198 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9199 struct wireless_dev *wdev = info->user_ptr[1];
9200
9201 if (!rdev->ops->crit_proto_stop)
9202 return -EOPNOTSUPP;
9203
9204 if (rdev->crit_proto_nlportid) {
9205 rdev->crit_proto_nlportid = 0;
9206 rdev_crit_proto_stop(rdev, wdev);
9207 }
9208 return 0;
9209}
9210
Johannes Bergad7e7182013-11-13 13:37:47 +01009211static int nl80211_vendor_cmd(struct sk_buff *skb, struct genl_info *info)
9212{
9213 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9214 struct wireless_dev *wdev =
9215 __cfg80211_wdev_from_attrs(genl_info_net(info), info->attrs);
9216 int i, err;
9217 u32 vid, subcmd;
9218
9219 if (!rdev->wiphy.vendor_commands)
9220 return -EOPNOTSUPP;
9221
9222 if (IS_ERR(wdev)) {
9223 err = PTR_ERR(wdev);
9224 if (err != -EINVAL)
9225 return err;
9226 wdev = NULL;
9227 } else if (wdev->wiphy != &rdev->wiphy) {
9228 return -EINVAL;
9229 }
9230
9231 if (!info->attrs[NL80211_ATTR_VENDOR_ID] ||
9232 !info->attrs[NL80211_ATTR_VENDOR_SUBCMD])
9233 return -EINVAL;
9234
9235 vid = nla_get_u32(info->attrs[NL80211_ATTR_VENDOR_ID]);
9236 subcmd = nla_get_u32(info->attrs[NL80211_ATTR_VENDOR_SUBCMD]);
9237 for (i = 0; i < rdev->wiphy.n_vendor_commands; i++) {
9238 const struct wiphy_vendor_command *vcmd;
9239 void *data = NULL;
9240 int len = 0;
9241
9242 vcmd = &rdev->wiphy.vendor_commands[i];
9243
9244 if (vcmd->info.vendor_id != vid || vcmd->info.subcmd != subcmd)
9245 continue;
9246
9247 if (vcmd->flags & (WIPHY_VENDOR_CMD_NEED_WDEV |
9248 WIPHY_VENDOR_CMD_NEED_NETDEV)) {
9249 if (!wdev)
9250 return -EINVAL;
9251 if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_NETDEV &&
9252 !wdev->netdev)
9253 return -EINVAL;
9254
9255 if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_RUNNING) {
9256 if (wdev->netdev &&
9257 !netif_running(wdev->netdev))
9258 return -ENETDOWN;
9259 if (!wdev->netdev && !wdev->p2p_started)
9260 return -ENETDOWN;
9261 }
9262 } else {
9263 wdev = NULL;
9264 }
9265
9266 if (info->attrs[NL80211_ATTR_VENDOR_DATA]) {
9267 data = nla_data(info->attrs[NL80211_ATTR_VENDOR_DATA]);
9268 len = nla_len(info->attrs[NL80211_ATTR_VENDOR_DATA]);
9269 }
9270
9271 rdev->cur_cmd_info = info;
9272 err = rdev->wiphy.vendor_commands[i].doit(&rdev->wiphy, wdev,
9273 data, len);
9274 rdev->cur_cmd_info = NULL;
9275 return err;
9276 }
9277
9278 return -EOPNOTSUPP;
9279}
9280
9281struct sk_buff *__cfg80211_alloc_reply_skb(struct wiphy *wiphy,
9282 enum nl80211_commands cmd,
9283 enum nl80211_attrs attr,
9284 int approxlen)
9285{
Zhao, Gangf26cbf42014-04-21 12:53:03 +08009286 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Bergad7e7182013-11-13 13:37:47 +01009287
9288 if (WARN_ON(!rdev->cur_cmd_info))
9289 return NULL;
9290
9291 return __cfg80211_alloc_vendor_skb(rdev, approxlen,
9292 rdev->cur_cmd_info->snd_portid,
9293 rdev->cur_cmd_info->snd_seq,
Johannes Berg567ffc32013-12-18 14:43:31 +01009294 cmd, attr, NULL, GFP_KERNEL);
Johannes Bergad7e7182013-11-13 13:37:47 +01009295}
9296EXPORT_SYMBOL(__cfg80211_alloc_reply_skb);
9297
9298int cfg80211_vendor_cmd_reply(struct sk_buff *skb)
9299{
9300 struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0];
9301 void *hdr = ((void **)skb->cb)[1];
9302 struct nlattr *data = ((void **)skb->cb)[2];
9303
9304 if (WARN_ON(!rdev->cur_cmd_info)) {
9305 kfree_skb(skb);
9306 return -EINVAL;
9307 }
9308
9309 nla_nest_end(skb, data);
9310 genlmsg_end(skb, hdr);
9311 return genlmsg_reply(skb, rdev->cur_cmd_info);
9312}
9313EXPORT_SYMBOL_GPL(cfg80211_vendor_cmd_reply);
9314
9315
Kyeyoon Parkfa9ffc72013-12-16 23:01:30 -08009316static int nl80211_set_qos_map(struct sk_buff *skb,
9317 struct genl_info *info)
9318{
9319 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9320 struct cfg80211_qos_map *qos_map = NULL;
9321 struct net_device *dev = info->user_ptr[1];
9322 u8 *pos, len, num_des, des_len, des;
9323 int ret;
9324
9325 if (!rdev->ops->set_qos_map)
9326 return -EOPNOTSUPP;
9327
9328 if (info->attrs[NL80211_ATTR_QOS_MAP]) {
9329 pos = nla_data(info->attrs[NL80211_ATTR_QOS_MAP]);
9330 len = nla_len(info->attrs[NL80211_ATTR_QOS_MAP]);
9331
9332 if (len % 2 || len < IEEE80211_QOS_MAP_LEN_MIN ||
9333 len > IEEE80211_QOS_MAP_LEN_MAX)
9334 return -EINVAL;
9335
9336 qos_map = kzalloc(sizeof(struct cfg80211_qos_map), GFP_KERNEL);
9337 if (!qos_map)
9338 return -ENOMEM;
9339
9340 num_des = (len - IEEE80211_QOS_MAP_LEN_MIN) >> 1;
9341 if (num_des) {
9342 des_len = num_des *
9343 sizeof(struct cfg80211_dscp_exception);
9344 memcpy(qos_map->dscp_exception, pos, des_len);
9345 qos_map->num_des = num_des;
9346 for (des = 0; des < num_des; des++) {
9347 if (qos_map->dscp_exception[des].up > 7) {
9348 kfree(qos_map);
9349 return -EINVAL;
9350 }
9351 }
9352 pos += des_len;
9353 }
9354 memcpy(qos_map->up, pos, IEEE80211_QOS_MAP_LEN_MIN);
9355 }
9356
9357 wdev_lock(dev->ieee80211_ptr);
9358 ret = nl80211_key_allowed(dev->ieee80211_ptr);
9359 if (!ret)
9360 ret = rdev_set_qos_map(rdev, dev, qos_map);
9361 wdev_unlock(dev->ieee80211_ptr);
9362
9363 kfree(qos_map);
9364 return ret;
9365}
9366
Johannes Berg4c476992010-10-04 21:36:35 +02009367#define NL80211_FLAG_NEED_WIPHY 0x01
9368#define NL80211_FLAG_NEED_NETDEV 0x02
9369#define NL80211_FLAG_NEED_RTNL 0x04
Johannes Berg41265712010-10-04 21:14:05 +02009370#define NL80211_FLAG_CHECK_NETDEV_UP 0x08
9371#define NL80211_FLAG_NEED_NETDEV_UP (NL80211_FLAG_NEED_NETDEV |\
9372 NL80211_FLAG_CHECK_NETDEV_UP)
Johannes Berg1bf614e2012-06-15 15:23:36 +02009373#define NL80211_FLAG_NEED_WDEV 0x10
Johannes Berg98104fde2012-06-16 00:19:54 +02009374/* If a netdev is associated, it must be UP, P2P must be started */
Johannes Berg1bf614e2012-06-15 15:23:36 +02009375#define NL80211_FLAG_NEED_WDEV_UP (NL80211_FLAG_NEED_WDEV |\
9376 NL80211_FLAG_CHECK_NETDEV_UP)
Johannes Berg4c476992010-10-04 21:36:35 +02009377
Johannes Bergf84f7712013-11-14 17:14:45 +01009378static int nl80211_pre_doit(const struct genl_ops *ops, struct sk_buff *skb,
Johannes Berg4c476992010-10-04 21:36:35 +02009379 struct genl_info *info)
9380{
9381 struct cfg80211_registered_device *rdev;
Johannes Berg89a54e42012-06-15 14:33:17 +02009382 struct wireless_dev *wdev;
Johannes Berg4c476992010-10-04 21:36:35 +02009383 struct net_device *dev;
Johannes Berg4c476992010-10-04 21:36:35 +02009384 bool rtnl = ops->internal_flags & NL80211_FLAG_NEED_RTNL;
9385
9386 if (rtnl)
9387 rtnl_lock();
9388
9389 if (ops->internal_flags & NL80211_FLAG_NEED_WIPHY) {
Johannes Berg4f7eff12012-06-15 14:14:22 +02009390 rdev = cfg80211_get_dev_from_info(genl_info_net(info), info);
Johannes Berg4c476992010-10-04 21:36:35 +02009391 if (IS_ERR(rdev)) {
9392 if (rtnl)
9393 rtnl_unlock();
9394 return PTR_ERR(rdev);
9395 }
9396 info->user_ptr[0] = rdev;
Johannes Berg1bf614e2012-06-15 15:23:36 +02009397 } else if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV ||
9398 ops->internal_flags & NL80211_FLAG_NEED_WDEV) {
Johannes Berg5fe231e2013-05-08 21:45:15 +02009399 ASSERT_RTNL();
9400
Johannes Berg89a54e42012-06-15 14:33:17 +02009401 wdev = __cfg80211_wdev_from_attrs(genl_info_net(info),
9402 info->attrs);
9403 if (IS_ERR(wdev)) {
Johannes Berg4c476992010-10-04 21:36:35 +02009404 if (rtnl)
9405 rtnl_unlock();
Johannes Berg89a54e42012-06-15 14:33:17 +02009406 return PTR_ERR(wdev);
Johannes Berg4c476992010-10-04 21:36:35 +02009407 }
Johannes Berg89a54e42012-06-15 14:33:17 +02009408
Johannes Berg89a54e42012-06-15 14:33:17 +02009409 dev = wdev->netdev;
Zhao, Gangf26cbf42014-04-21 12:53:03 +08009410 rdev = wiphy_to_rdev(wdev->wiphy);
Johannes Berg89a54e42012-06-15 14:33:17 +02009411
Johannes Berg1bf614e2012-06-15 15:23:36 +02009412 if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV) {
9413 if (!dev) {
Johannes Berg1bf614e2012-06-15 15:23:36 +02009414 if (rtnl)
9415 rtnl_unlock();
9416 return -EINVAL;
9417 }
9418
9419 info->user_ptr[1] = dev;
9420 } else {
9421 info->user_ptr[1] = wdev;
Johannes Berg41265712010-10-04 21:14:05 +02009422 }
Johannes Berg89a54e42012-06-15 14:33:17 +02009423
Johannes Berg1bf614e2012-06-15 15:23:36 +02009424 if (dev) {
9425 if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP &&
9426 !netif_running(dev)) {
Johannes Berg1bf614e2012-06-15 15:23:36 +02009427 if (rtnl)
9428 rtnl_unlock();
9429 return -ENETDOWN;
9430 }
9431
9432 dev_hold(dev);
Johannes Berg98104fde2012-06-16 00:19:54 +02009433 } else if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP) {
9434 if (!wdev->p2p_started) {
Johannes Berg98104fde2012-06-16 00:19:54 +02009435 if (rtnl)
9436 rtnl_unlock();
9437 return -ENETDOWN;
9438 }
Johannes Berg1bf614e2012-06-15 15:23:36 +02009439 }
9440
Johannes Berg4c476992010-10-04 21:36:35 +02009441 info->user_ptr[0] = rdev;
Johannes Berg4c476992010-10-04 21:36:35 +02009442 }
9443
9444 return 0;
9445}
9446
Johannes Bergf84f7712013-11-14 17:14:45 +01009447static void nl80211_post_doit(const struct genl_ops *ops, struct sk_buff *skb,
Johannes Berg4c476992010-10-04 21:36:35 +02009448 struct genl_info *info)
9449{
Johannes Berg1bf614e2012-06-15 15:23:36 +02009450 if (info->user_ptr[1]) {
9451 if (ops->internal_flags & NL80211_FLAG_NEED_WDEV) {
9452 struct wireless_dev *wdev = info->user_ptr[1];
9453
9454 if (wdev->netdev)
9455 dev_put(wdev->netdev);
9456 } else {
9457 dev_put(info->user_ptr[1]);
9458 }
9459 }
Johannes Berg4c476992010-10-04 21:36:35 +02009460 if (ops->internal_flags & NL80211_FLAG_NEED_RTNL)
9461 rtnl_unlock();
9462}
9463
Johannes Berg4534de82013-11-14 17:14:46 +01009464static const struct genl_ops nl80211_ops[] = {
Johannes Berg55682962007-09-20 13:09:35 -04009465 {
9466 .cmd = NL80211_CMD_GET_WIPHY,
9467 .doit = nl80211_get_wiphy,
9468 .dumpit = nl80211_dump_wiphy,
Johannes Berg86e8cf92013-06-19 10:57:22 +02009469 .done = nl80211_dump_wiphy_done,
Johannes Berg55682962007-09-20 13:09:35 -04009470 .policy = nl80211_policy,
9471 /* can be retrieved by unprivileged users */
Johannes Berg5fe231e2013-05-08 21:45:15 +02009472 .internal_flags = NL80211_FLAG_NEED_WIPHY |
9473 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -04009474 },
9475 {
9476 .cmd = NL80211_CMD_SET_WIPHY,
9477 .doit = nl80211_set_wiphy,
9478 .policy = nl80211_policy,
9479 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02009480 .internal_flags = NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -04009481 },
9482 {
9483 .cmd = NL80211_CMD_GET_INTERFACE,
9484 .doit = nl80211_get_interface,
9485 .dumpit = nl80211_dump_interface,
9486 .policy = nl80211_policy,
9487 /* can be retrieved by unprivileged users */
Johannes Berg5fe231e2013-05-08 21:45:15 +02009488 .internal_flags = NL80211_FLAG_NEED_WDEV |
9489 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -04009490 },
9491 {
9492 .cmd = NL80211_CMD_SET_INTERFACE,
9493 .doit = nl80211_set_interface,
9494 .policy = nl80211_policy,
9495 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02009496 .internal_flags = NL80211_FLAG_NEED_NETDEV |
9497 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -04009498 },
9499 {
9500 .cmd = NL80211_CMD_NEW_INTERFACE,
9501 .doit = nl80211_new_interface,
9502 .policy = nl80211_policy,
9503 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02009504 .internal_flags = NL80211_FLAG_NEED_WIPHY |
9505 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -04009506 },
9507 {
9508 .cmd = NL80211_CMD_DEL_INTERFACE,
9509 .doit = nl80211_del_interface,
9510 .policy = nl80211_policy,
9511 .flags = GENL_ADMIN_PERM,
Johannes Berg84efbb82012-06-16 00:00:26 +02009512 .internal_flags = NL80211_FLAG_NEED_WDEV |
Johannes Berg4c476992010-10-04 21:36:35 +02009513 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -04009514 },
Johannes Berg41ade002007-12-19 02:03:29 +01009515 {
9516 .cmd = NL80211_CMD_GET_KEY,
9517 .doit = nl80211_get_key,
9518 .policy = nl80211_policy,
9519 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02009520 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009521 NL80211_FLAG_NEED_RTNL,
Johannes Berg41ade002007-12-19 02:03:29 +01009522 },
9523 {
9524 .cmd = NL80211_CMD_SET_KEY,
9525 .doit = nl80211_set_key,
9526 .policy = nl80211_policy,
9527 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02009528 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009529 NL80211_FLAG_NEED_RTNL,
Johannes Berg41ade002007-12-19 02:03:29 +01009530 },
9531 {
9532 .cmd = NL80211_CMD_NEW_KEY,
9533 .doit = nl80211_new_key,
9534 .policy = nl80211_policy,
9535 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02009536 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009537 NL80211_FLAG_NEED_RTNL,
Johannes Berg41ade002007-12-19 02:03:29 +01009538 },
9539 {
9540 .cmd = NL80211_CMD_DEL_KEY,
9541 .doit = nl80211_del_key,
9542 .policy = nl80211_policy,
9543 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02009544 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009545 NL80211_FLAG_NEED_RTNL,
Johannes Berg41ade002007-12-19 02:03:29 +01009546 },
Johannes Berged1b6cc2007-12-19 02:03:32 +01009547 {
9548 .cmd = NL80211_CMD_SET_BEACON,
9549 .policy = nl80211_policy,
9550 .flags = GENL_ADMIN_PERM,
Johannes Berg88600202012-02-13 15:17:18 +01009551 .doit = nl80211_set_beacon,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02009552 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009553 NL80211_FLAG_NEED_RTNL,
Johannes Berged1b6cc2007-12-19 02:03:32 +01009554 },
9555 {
Johannes Berg88600202012-02-13 15:17:18 +01009556 .cmd = NL80211_CMD_START_AP,
Johannes Berged1b6cc2007-12-19 02:03:32 +01009557 .policy = nl80211_policy,
9558 .flags = GENL_ADMIN_PERM,
Johannes Berg88600202012-02-13 15:17:18 +01009559 .doit = nl80211_start_ap,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02009560 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009561 NL80211_FLAG_NEED_RTNL,
Johannes Berged1b6cc2007-12-19 02:03:32 +01009562 },
9563 {
Johannes Berg88600202012-02-13 15:17:18 +01009564 .cmd = NL80211_CMD_STOP_AP,
Johannes Berged1b6cc2007-12-19 02:03:32 +01009565 .policy = nl80211_policy,
9566 .flags = GENL_ADMIN_PERM,
Johannes Berg88600202012-02-13 15:17:18 +01009567 .doit = nl80211_stop_ap,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02009568 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009569 NL80211_FLAG_NEED_RTNL,
Johannes Berged1b6cc2007-12-19 02:03:32 +01009570 },
Johannes Berg5727ef12007-12-19 02:03:34 +01009571 {
9572 .cmd = NL80211_CMD_GET_STATION,
9573 .doit = nl80211_get_station,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01009574 .dumpit = nl80211_dump_station,
Johannes Berg5727ef12007-12-19 02:03:34 +01009575 .policy = nl80211_policy,
Johannes Berg4c476992010-10-04 21:36:35 +02009576 .internal_flags = NL80211_FLAG_NEED_NETDEV |
9577 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +01009578 },
9579 {
9580 .cmd = NL80211_CMD_SET_STATION,
9581 .doit = nl80211_set_station,
9582 .policy = nl80211_policy,
9583 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02009584 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009585 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +01009586 },
9587 {
9588 .cmd = NL80211_CMD_NEW_STATION,
9589 .doit = nl80211_new_station,
9590 .policy = nl80211_policy,
9591 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02009592 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009593 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +01009594 },
9595 {
9596 .cmd = NL80211_CMD_DEL_STATION,
9597 .doit = nl80211_del_station,
9598 .policy = nl80211_policy,
9599 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02009600 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009601 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +01009602 },
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01009603 {
9604 .cmd = NL80211_CMD_GET_MPATH,
9605 .doit = nl80211_get_mpath,
9606 .dumpit = nl80211_dump_mpath,
9607 .policy = nl80211_policy,
9608 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02009609 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009610 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01009611 },
9612 {
9613 .cmd = NL80211_CMD_SET_MPATH,
9614 .doit = nl80211_set_mpath,
9615 .policy = nl80211_policy,
9616 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02009617 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009618 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01009619 },
9620 {
9621 .cmd = NL80211_CMD_NEW_MPATH,
9622 .doit = nl80211_new_mpath,
9623 .policy = nl80211_policy,
9624 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02009625 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009626 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01009627 },
9628 {
9629 .cmd = NL80211_CMD_DEL_MPATH,
9630 .doit = nl80211_del_mpath,
9631 .policy = nl80211_policy,
9632 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02009633 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009634 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01009635 },
Jouni Malinen9f1ba902008-08-07 20:07:01 +03009636 {
9637 .cmd = NL80211_CMD_SET_BSS,
9638 .doit = nl80211_set_bss,
9639 .policy = nl80211_policy,
9640 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02009641 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009642 NL80211_FLAG_NEED_RTNL,
Jouni Malinen9f1ba902008-08-07 20:07:01 +03009643 },
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07009644 {
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08009645 .cmd = NL80211_CMD_GET_REG,
9646 .doit = nl80211_get_reg,
9647 .policy = nl80211_policy,
Johannes Berg5fe231e2013-05-08 21:45:15 +02009648 .internal_flags = NL80211_FLAG_NEED_RTNL,
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08009649 /* can be retrieved by unprivileged users */
9650 },
9651 {
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07009652 .cmd = NL80211_CMD_SET_REG,
9653 .doit = nl80211_set_reg,
9654 .policy = nl80211_policy,
9655 .flags = GENL_ADMIN_PERM,
Johannes Berg5fe231e2013-05-08 21:45:15 +02009656 .internal_flags = NL80211_FLAG_NEED_RTNL,
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07009657 },
9658 {
9659 .cmd = NL80211_CMD_REQ_SET_REG,
9660 .doit = nl80211_req_set_reg,
9661 .policy = nl80211_policy,
9662 .flags = GENL_ADMIN_PERM,
9663 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07009664 {
Javier Cardona24bdd9f2010-12-16 17:37:48 -08009665 .cmd = NL80211_CMD_GET_MESH_CONFIG,
9666 .doit = nl80211_get_mesh_config,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07009667 .policy = nl80211_policy,
9668 /* can be retrieved by unprivileged users */
Johannes Berg2b5f8b02012-04-02 10:51:55 +02009669 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009670 NL80211_FLAG_NEED_RTNL,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07009671 },
9672 {
Javier Cardona24bdd9f2010-12-16 17:37:48 -08009673 .cmd = NL80211_CMD_SET_MESH_CONFIG,
9674 .doit = nl80211_update_mesh_config,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07009675 .policy = nl80211_policy,
9676 .flags = GENL_ADMIN_PERM,
Johannes Berg29cbe682010-12-03 09:20:44 +01009677 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009678 NL80211_FLAG_NEED_RTNL,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07009679 },
Jouni Malinen9aed3cc2009-01-13 16:03:29 +02009680 {
Johannes Berg2a519312009-02-10 21:25:55 +01009681 .cmd = NL80211_CMD_TRIGGER_SCAN,
9682 .doit = nl80211_trigger_scan,
9683 .policy = nl80211_policy,
9684 .flags = GENL_ADMIN_PERM,
Johannes Bergfd014282012-06-18 19:17:03 +02009685 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009686 NL80211_FLAG_NEED_RTNL,
Johannes Berg2a519312009-02-10 21:25:55 +01009687 },
9688 {
9689 .cmd = NL80211_CMD_GET_SCAN,
9690 .policy = nl80211_policy,
9691 .dumpit = nl80211_dump_scan,
9692 },
Jouni Malinen636a5d32009-03-19 13:39:22 +02009693 {
Luciano Coelho807f8a82011-05-11 17:09:35 +03009694 .cmd = NL80211_CMD_START_SCHED_SCAN,
9695 .doit = nl80211_start_sched_scan,
9696 .policy = nl80211_policy,
9697 .flags = GENL_ADMIN_PERM,
9698 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
9699 NL80211_FLAG_NEED_RTNL,
9700 },
9701 {
9702 .cmd = NL80211_CMD_STOP_SCHED_SCAN,
9703 .doit = nl80211_stop_sched_scan,
9704 .policy = nl80211_policy,
9705 .flags = GENL_ADMIN_PERM,
9706 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
9707 NL80211_FLAG_NEED_RTNL,
9708 },
9709 {
Jouni Malinen636a5d32009-03-19 13:39:22 +02009710 .cmd = NL80211_CMD_AUTHENTICATE,
9711 .doit = nl80211_authenticate,
9712 .policy = nl80211_policy,
9713 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02009714 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009715 NL80211_FLAG_NEED_RTNL,
Jouni Malinen636a5d32009-03-19 13:39:22 +02009716 },
9717 {
9718 .cmd = NL80211_CMD_ASSOCIATE,
9719 .doit = nl80211_associate,
9720 .policy = nl80211_policy,
9721 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02009722 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009723 NL80211_FLAG_NEED_RTNL,
Jouni Malinen636a5d32009-03-19 13:39:22 +02009724 },
9725 {
9726 .cmd = NL80211_CMD_DEAUTHENTICATE,
9727 .doit = nl80211_deauthenticate,
9728 .policy = nl80211_policy,
9729 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02009730 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009731 NL80211_FLAG_NEED_RTNL,
Jouni Malinen636a5d32009-03-19 13:39:22 +02009732 },
9733 {
9734 .cmd = NL80211_CMD_DISASSOCIATE,
9735 .doit = nl80211_disassociate,
9736 .policy = nl80211_policy,
9737 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02009738 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009739 NL80211_FLAG_NEED_RTNL,
Jouni Malinen636a5d32009-03-19 13:39:22 +02009740 },
Johannes Berg04a773a2009-04-19 21:24:32 +02009741 {
9742 .cmd = NL80211_CMD_JOIN_IBSS,
9743 .doit = nl80211_join_ibss,
9744 .policy = nl80211_policy,
9745 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02009746 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009747 NL80211_FLAG_NEED_RTNL,
Johannes Berg04a773a2009-04-19 21:24:32 +02009748 },
9749 {
9750 .cmd = NL80211_CMD_LEAVE_IBSS,
9751 .doit = nl80211_leave_ibss,
9752 .policy = nl80211_policy,
9753 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02009754 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009755 NL80211_FLAG_NEED_RTNL,
Johannes Berg04a773a2009-04-19 21:24:32 +02009756 },
Johannes Bergaff89a92009-07-01 21:26:51 +02009757#ifdef CONFIG_NL80211_TESTMODE
9758 {
9759 .cmd = NL80211_CMD_TESTMODE,
9760 .doit = nl80211_testmode_do,
Wey-Yi Guy71063f02011-05-20 09:05:54 -07009761 .dumpit = nl80211_testmode_dump,
Johannes Bergaff89a92009-07-01 21:26:51 +02009762 .policy = nl80211_policy,
9763 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02009764 .internal_flags = NL80211_FLAG_NEED_WIPHY |
9765 NL80211_FLAG_NEED_RTNL,
Johannes Bergaff89a92009-07-01 21:26:51 +02009766 },
9767#endif
Samuel Ortizb23aa672009-07-01 21:26:54 +02009768 {
9769 .cmd = NL80211_CMD_CONNECT,
9770 .doit = nl80211_connect,
9771 .policy = nl80211_policy,
9772 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02009773 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009774 NL80211_FLAG_NEED_RTNL,
Samuel Ortizb23aa672009-07-01 21:26:54 +02009775 },
9776 {
9777 .cmd = NL80211_CMD_DISCONNECT,
9778 .doit = nl80211_disconnect,
9779 .policy = nl80211_policy,
9780 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02009781 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009782 NL80211_FLAG_NEED_RTNL,
Samuel Ortizb23aa672009-07-01 21:26:54 +02009783 },
Johannes Berg463d0182009-07-14 00:33:35 +02009784 {
9785 .cmd = NL80211_CMD_SET_WIPHY_NETNS,
9786 .doit = nl80211_wiphy_netns,
9787 .policy = nl80211_policy,
9788 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02009789 .internal_flags = NL80211_FLAG_NEED_WIPHY |
9790 NL80211_FLAG_NEED_RTNL,
Johannes Berg463d0182009-07-14 00:33:35 +02009791 },
Holger Schurig61fa7132009-11-11 12:25:40 +01009792 {
9793 .cmd = NL80211_CMD_GET_SURVEY,
9794 .policy = nl80211_policy,
9795 .dumpit = nl80211_dump_survey,
9796 },
Samuel Ortiz67fbb162009-11-24 23:59:15 +01009797 {
9798 .cmd = NL80211_CMD_SET_PMKSA,
9799 .doit = nl80211_setdel_pmksa,
9800 .policy = nl80211_policy,
9801 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02009802 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009803 NL80211_FLAG_NEED_RTNL,
Samuel Ortiz67fbb162009-11-24 23:59:15 +01009804 },
9805 {
9806 .cmd = NL80211_CMD_DEL_PMKSA,
9807 .doit = nl80211_setdel_pmksa,
9808 .policy = nl80211_policy,
9809 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02009810 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009811 NL80211_FLAG_NEED_RTNL,
Samuel Ortiz67fbb162009-11-24 23:59:15 +01009812 },
9813 {
9814 .cmd = NL80211_CMD_FLUSH_PMKSA,
9815 .doit = nl80211_flush_pmksa,
9816 .policy = nl80211_policy,
9817 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02009818 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009819 NL80211_FLAG_NEED_RTNL,
Samuel Ortiz67fbb162009-11-24 23:59:15 +01009820 },
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009821 {
9822 .cmd = NL80211_CMD_REMAIN_ON_CHANNEL,
9823 .doit = nl80211_remain_on_channel,
9824 .policy = nl80211_policy,
9825 .flags = GENL_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +02009826 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009827 NL80211_FLAG_NEED_RTNL,
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009828 },
9829 {
9830 .cmd = NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL,
9831 .doit = nl80211_cancel_remain_on_channel,
9832 .policy = nl80211_policy,
9833 .flags = GENL_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +02009834 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009835 NL80211_FLAG_NEED_RTNL,
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009836 },
Jouni Malinen13ae75b2009-12-29 12:59:45 +02009837 {
9838 .cmd = NL80211_CMD_SET_TX_BITRATE_MASK,
9839 .doit = nl80211_set_tx_bitrate_mask,
9840 .policy = nl80211_policy,
9841 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02009842 .internal_flags = NL80211_FLAG_NEED_NETDEV |
9843 NL80211_FLAG_NEED_RTNL,
Jouni Malinen13ae75b2009-12-29 12:59:45 +02009844 },
Jouni Malinen026331c2010-02-15 12:53:10 +02009845 {
Johannes Berg2e161f72010-08-12 15:38:38 +02009846 .cmd = NL80211_CMD_REGISTER_FRAME,
9847 .doit = nl80211_register_mgmt,
Jouni Malinen026331c2010-02-15 12:53:10 +02009848 .policy = nl80211_policy,
9849 .flags = GENL_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +02009850 .internal_flags = NL80211_FLAG_NEED_WDEV |
Johannes Berg4c476992010-10-04 21:36:35 +02009851 NL80211_FLAG_NEED_RTNL,
Jouni Malinen026331c2010-02-15 12:53:10 +02009852 },
9853 {
Johannes Berg2e161f72010-08-12 15:38:38 +02009854 .cmd = NL80211_CMD_FRAME,
9855 .doit = nl80211_tx_mgmt,
Jouni Malinen026331c2010-02-15 12:53:10 +02009856 .policy = nl80211_policy,
9857 .flags = GENL_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +02009858 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009859 NL80211_FLAG_NEED_RTNL,
Jouni Malinen026331c2010-02-15 12:53:10 +02009860 },
Kalle Valoffb9eb32010-02-17 17:58:10 +02009861 {
Johannes Bergf7ca38d2010-11-25 10:02:29 +01009862 .cmd = NL80211_CMD_FRAME_WAIT_CANCEL,
9863 .doit = nl80211_tx_mgmt_cancel_wait,
9864 .policy = nl80211_policy,
9865 .flags = GENL_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +02009866 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Bergf7ca38d2010-11-25 10:02:29 +01009867 NL80211_FLAG_NEED_RTNL,
9868 },
9869 {
Kalle Valoffb9eb32010-02-17 17:58:10 +02009870 .cmd = NL80211_CMD_SET_POWER_SAVE,
9871 .doit = nl80211_set_power_save,
9872 .policy = nl80211_policy,
9873 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02009874 .internal_flags = NL80211_FLAG_NEED_NETDEV |
9875 NL80211_FLAG_NEED_RTNL,
Kalle Valoffb9eb32010-02-17 17:58:10 +02009876 },
9877 {
9878 .cmd = NL80211_CMD_GET_POWER_SAVE,
9879 .doit = nl80211_get_power_save,
9880 .policy = nl80211_policy,
9881 /* can be retrieved by unprivileged users */
Johannes Berg4c476992010-10-04 21:36:35 +02009882 .internal_flags = NL80211_FLAG_NEED_NETDEV |
9883 NL80211_FLAG_NEED_RTNL,
Kalle Valoffb9eb32010-02-17 17:58:10 +02009884 },
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02009885 {
9886 .cmd = NL80211_CMD_SET_CQM,
9887 .doit = nl80211_set_cqm,
9888 .policy = nl80211_policy,
9889 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02009890 .internal_flags = NL80211_FLAG_NEED_NETDEV |
9891 NL80211_FLAG_NEED_RTNL,
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02009892 },
Johannes Bergf444de02010-05-05 15:25:02 +02009893 {
9894 .cmd = NL80211_CMD_SET_CHANNEL,
9895 .doit = nl80211_set_channel,
9896 .policy = nl80211_policy,
9897 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02009898 .internal_flags = NL80211_FLAG_NEED_NETDEV |
9899 NL80211_FLAG_NEED_RTNL,
Johannes Bergf444de02010-05-05 15:25:02 +02009900 },
Bill Jordane8347eb2010-10-01 13:54:28 -04009901 {
9902 .cmd = NL80211_CMD_SET_WDS_PEER,
9903 .doit = nl80211_set_wds_peer,
9904 .policy = nl80211_policy,
9905 .flags = GENL_ADMIN_PERM,
Johannes Berg43b19952010-10-07 13:10:30 +02009906 .internal_flags = NL80211_FLAG_NEED_NETDEV |
9907 NL80211_FLAG_NEED_RTNL,
Bill Jordane8347eb2010-10-01 13:54:28 -04009908 },
Johannes Berg29cbe682010-12-03 09:20:44 +01009909 {
9910 .cmd = NL80211_CMD_JOIN_MESH,
9911 .doit = nl80211_join_mesh,
9912 .policy = nl80211_policy,
9913 .flags = GENL_ADMIN_PERM,
9914 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
9915 NL80211_FLAG_NEED_RTNL,
9916 },
9917 {
9918 .cmd = NL80211_CMD_LEAVE_MESH,
9919 .doit = nl80211_leave_mesh,
9920 .policy = nl80211_policy,
9921 .flags = GENL_ADMIN_PERM,
9922 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
9923 NL80211_FLAG_NEED_RTNL,
9924 },
Johannes Bergdfb89c52012-06-27 09:23:48 +02009925#ifdef CONFIG_PM
Johannes Bergff1b6e62011-05-04 15:37:28 +02009926 {
9927 .cmd = NL80211_CMD_GET_WOWLAN,
9928 .doit = nl80211_get_wowlan,
9929 .policy = nl80211_policy,
9930 /* can be retrieved by unprivileged users */
9931 .internal_flags = NL80211_FLAG_NEED_WIPHY |
9932 NL80211_FLAG_NEED_RTNL,
9933 },
9934 {
9935 .cmd = NL80211_CMD_SET_WOWLAN,
9936 .doit = nl80211_set_wowlan,
9937 .policy = nl80211_policy,
9938 .flags = GENL_ADMIN_PERM,
9939 .internal_flags = NL80211_FLAG_NEED_WIPHY |
9940 NL80211_FLAG_NEED_RTNL,
9941 },
Johannes Bergdfb89c52012-06-27 09:23:48 +02009942#endif
Johannes Berge5497d72011-07-05 16:35:40 +02009943 {
9944 .cmd = NL80211_CMD_SET_REKEY_OFFLOAD,
9945 .doit = nl80211_set_rekey_data,
9946 .policy = nl80211_policy,
9947 .flags = GENL_ADMIN_PERM,
9948 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
9949 NL80211_FLAG_NEED_RTNL,
9950 },
Arik Nemtsov109086c2011-09-28 14:12:50 +03009951 {
9952 .cmd = NL80211_CMD_TDLS_MGMT,
9953 .doit = nl80211_tdls_mgmt,
9954 .policy = nl80211_policy,
9955 .flags = GENL_ADMIN_PERM,
9956 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
9957 NL80211_FLAG_NEED_RTNL,
9958 },
9959 {
9960 .cmd = NL80211_CMD_TDLS_OPER,
9961 .doit = nl80211_tdls_oper,
9962 .policy = nl80211_policy,
9963 .flags = GENL_ADMIN_PERM,
9964 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
9965 NL80211_FLAG_NEED_RTNL,
9966 },
Johannes Berg28946da2011-11-04 11:18:12 +01009967 {
9968 .cmd = NL80211_CMD_UNEXPECTED_FRAME,
9969 .doit = nl80211_register_unexpected_frame,
9970 .policy = nl80211_policy,
9971 .flags = GENL_ADMIN_PERM,
9972 .internal_flags = NL80211_FLAG_NEED_NETDEV |
9973 NL80211_FLAG_NEED_RTNL,
9974 },
Johannes Berg7f6cf312011-11-04 11:18:15 +01009975 {
9976 .cmd = NL80211_CMD_PROBE_CLIENT,
9977 .doit = nl80211_probe_client,
9978 .policy = nl80211_policy,
9979 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02009980 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg7f6cf312011-11-04 11:18:15 +01009981 NL80211_FLAG_NEED_RTNL,
9982 },
Johannes Berg5e7602302011-11-04 11:18:17 +01009983 {
9984 .cmd = NL80211_CMD_REGISTER_BEACONS,
9985 .doit = nl80211_register_beacons,
9986 .policy = nl80211_policy,
9987 .flags = GENL_ADMIN_PERM,
9988 .internal_flags = NL80211_FLAG_NEED_WIPHY |
9989 NL80211_FLAG_NEED_RTNL,
9990 },
Simon Wunderlich1d9d9212011-11-18 14:20:43 +01009991 {
9992 .cmd = NL80211_CMD_SET_NOACK_MAP,
9993 .doit = nl80211_set_noack_map,
9994 .policy = nl80211_policy,
9995 .flags = GENL_ADMIN_PERM,
9996 .internal_flags = NL80211_FLAG_NEED_NETDEV |
9997 NL80211_FLAG_NEED_RTNL,
9998 },
Johannes Berg98104fde2012-06-16 00:19:54 +02009999 {
10000 .cmd = NL80211_CMD_START_P2P_DEVICE,
10001 .doit = nl80211_start_p2p_device,
10002 .policy = nl80211_policy,
10003 .flags = GENL_ADMIN_PERM,
10004 .internal_flags = NL80211_FLAG_NEED_WDEV |
10005 NL80211_FLAG_NEED_RTNL,
10006 },
10007 {
10008 .cmd = NL80211_CMD_STOP_P2P_DEVICE,
10009 .doit = nl80211_stop_p2p_device,
10010 .policy = nl80211_policy,
10011 .flags = GENL_ADMIN_PERM,
10012 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
10013 NL80211_FLAG_NEED_RTNL,
10014 },
Antonio Quartullif4e583c2012-11-02 13:27:48 +010010015 {
10016 .cmd = NL80211_CMD_SET_MCAST_RATE,
10017 .doit = nl80211_set_mcast_rate,
10018 .policy = nl80211_policy,
10019 .flags = GENL_ADMIN_PERM,
10020 .internal_flags = NL80211_FLAG_NEED_NETDEV |
10021 NL80211_FLAG_NEED_RTNL,
10022 },
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +053010023 {
10024 .cmd = NL80211_CMD_SET_MAC_ACL,
10025 .doit = nl80211_set_mac_acl,
10026 .policy = nl80211_policy,
10027 .flags = GENL_ADMIN_PERM,
10028 .internal_flags = NL80211_FLAG_NEED_NETDEV |
10029 NL80211_FLAG_NEED_RTNL,
10030 },
Simon Wunderlich04f39042013-02-08 18:16:19 +010010031 {
10032 .cmd = NL80211_CMD_RADAR_DETECT,
10033 .doit = nl80211_start_radar_detection,
10034 .policy = nl80211_policy,
10035 .flags = GENL_ADMIN_PERM,
10036 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
10037 NL80211_FLAG_NEED_RTNL,
10038 },
Johannes Berg3713b4e2013-02-14 16:19:38 +010010039 {
10040 .cmd = NL80211_CMD_GET_PROTOCOL_FEATURES,
10041 .doit = nl80211_get_protocol_features,
10042 .policy = nl80211_policy,
10043 },
Jouni Malinen355199e2013-02-27 17:14:27 +020010044 {
10045 .cmd = NL80211_CMD_UPDATE_FT_IES,
10046 .doit = nl80211_update_ft_ies,
10047 .policy = nl80211_policy,
10048 .flags = GENL_ADMIN_PERM,
10049 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
10050 NL80211_FLAG_NEED_RTNL,
10051 },
Arend van Spriel5de17982013-04-18 15:49:00 +020010052 {
10053 .cmd = NL80211_CMD_CRIT_PROTOCOL_START,
10054 .doit = nl80211_crit_protocol_start,
10055 .policy = nl80211_policy,
10056 .flags = GENL_ADMIN_PERM,
10057 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
10058 NL80211_FLAG_NEED_RTNL,
10059 },
10060 {
10061 .cmd = NL80211_CMD_CRIT_PROTOCOL_STOP,
10062 .doit = nl80211_crit_protocol_stop,
10063 .policy = nl80211_policy,
10064 .flags = GENL_ADMIN_PERM,
10065 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
10066 NL80211_FLAG_NEED_RTNL,
Amitkumar Karwarbe29b992013-06-28 11:51:26 -070010067 },
10068 {
10069 .cmd = NL80211_CMD_GET_COALESCE,
10070 .doit = nl80211_get_coalesce,
10071 .policy = nl80211_policy,
10072 .internal_flags = NL80211_FLAG_NEED_WIPHY |
10073 NL80211_FLAG_NEED_RTNL,
10074 },
10075 {
10076 .cmd = NL80211_CMD_SET_COALESCE,
10077 .doit = nl80211_set_coalesce,
10078 .policy = nl80211_policy,
10079 .flags = GENL_ADMIN_PERM,
10080 .internal_flags = NL80211_FLAG_NEED_WIPHY |
10081 NL80211_FLAG_NEED_RTNL,
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +020010082 },
10083 {
10084 .cmd = NL80211_CMD_CHANNEL_SWITCH,
10085 .doit = nl80211_channel_switch,
10086 .policy = nl80211_policy,
10087 .flags = GENL_ADMIN_PERM,
10088 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
10089 NL80211_FLAG_NEED_RTNL,
10090 },
Johannes Bergad7e7182013-11-13 13:37:47 +010010091 {
10092 .cmd = NL80211_CMD_VENDOR,
10093 .doit = nl80211_vendor_cmd,
10094 .policy = nl80211_policy,
10095 .flags = GENL_ADMIN_PERM,
10096 .internal_flags = NL80211_FLAG_NEED_WIPHY |
10097 NL80211_FLAG_NEED_RTNL,
10098 },
Kyeyoon Parkfa9ffc72013-12-16 23:01:30 -080010099 {
10100 .cmd = NL80211_CMD_SET_QOS_MAP,
10101 .doit = nl80211_set_qos_map,
10102 .policy = nl80211_policy,
10103 .flags = GENL_ADMIN_PERM,
10104 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
10105 NL80211_FLAG_NEED_RTNL,
10106 },
Johannes Berg55682962007-09-20 13:09:35 -040010107};
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010108
Johannes Berg55682962007-09-20 13:09:35 -040010109/* notification functions */
10110
Johannes Berg3bb20552014-05-26 13:52:25 +020010111void nl80211_notify_wiphy(struct cfg80211_registered_device *rdev,
10112 enum nl80211_commands cmd)
Johannes Berg55682962007-09-20 13:09:35 -040010113{
10114 struct sk_buff *msg;
Johannes Berg86e8cf92013-06-19 10:57:22 +020010115 struct nl80211_dump_wiphy_state state = {};
Johannes Berg55682962007-09-20 13:09:35 -040010116
Johannes Berg3bb20552014-05-26 13:52:25 +020010117 WARN_ON(cmd != NL80211_CMD_NEW_WIPHY &&
10118 cmd != NL80211_CMD_DEL_WIPHY);
10119
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -070010120 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -040010121 if (!msg)
10122 return;
10123
Johannes Berg3bb20552014-05-26 13:52:25 +020010124 if (nl80211_send_wiphy(rdev, cmd, msg, 0, 0, 0, &state) < 0) {
Johannes Berg55682962007-09-20 13:09:35 -040010125 nlmsg_free(msg);
10126 return;
10127 }
10128
Johannes Berg68eb5502013-11-19 15:19:38 +010010129 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010010130 NL80211_MCGRP_CONFIG, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -040010131}
10132
Johannes Berg362a4152009-05-24 16:43:15 +020010133static int nl80211_add_scan_req(struct sk_buff *msg,
10134 struct cfg80211_registered_device *rdev)
10135{
10136 struct cfg80211_scan_request *req = rdev->scan_req;
10137 struct nlattr *nest;
10138 int i;
10139
10140 if (WARN_ON(!req))
10141 return 0;
10142
10143 nest = nla_nest_start(msg, NL80211_ATTR_SCAN_SSIDS);
10144 if (!nest)
10145 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -040010146 for (i = 0; i < req->n_ssids; i++) {
10147 if (nla_put(msg, i, req->ssids[i].ssid_len, req->ssids[i].ssid))
10148 goto nla_put_failure;
10149 }
Johannes Berg362a4152009-05-24 16:43:15 +020010150 nla_nest_end(msg, nest);
10151
10152 nest = nla_nest_start(msg, NL80211_ATTR_SCAN_FREQUENCIES);
10153 if (!nest)
10154 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -040010155 for (i = 0; i < req->n_channels; i++) {
10156 if (nla_put_u32(msg, i, req->channels[i]->center_freq))
10157 goto nla_put_failure;
10158 }
Johannes Berg362a4152009-05-24 16:43:15 +020010159 nla_nest_end(msg, nest);
10160
David S. Miller9360ffd2012-03-29 04:41:26 -040010161 if (req->ie &&
10162 nla_put(msg, NL80211_ATTR_IE, req->ie_len, req->ie))
10163 goto nla_put_failure;
Johannes Berg362a4152009-05-24 16:43:15 +020010164
Johannes Bergae917c92013-10-25 11:05:22 +020010165 if (req->flags &&
10166 nla_put_u32(msg, NL80211_ATTR_SCAN_FLAGS, req->flags))
10167 goto nla_put_failure;
Sam Lefflered4737712012-10-11 21:03:31 -070010168
Johannes Berg362a4152009-05-24 16:43:15 +020010169 return 0;
10170 nla_put_failure:
10171 return -ENOBUFS;
10172}
10173
Johannes Berga538e2d2009-06-16 19:56:42 +020010174static int nl80211_send_scan_msg(struct sk_buff *msg,
10175 struct cfg80211_registered_device *rdev,
Johannes Bergfd014282012-06-18 19:17:03 +020010176 struct wireless_dev *wdev,
Eric W. Biederman15e47302012-09-07 20:12:54 +000010177 u32 portid, u32 seq, int flags,
Johannes Berga538e2d2009-06-16 19:56:42 +020010178 u32 cmd)
Johannes Berg2a519312009-02-10 21:25:55 +010010179{
10180 void *hdr;
10181
Eric W. Biederman15e47302012-09-07 20:12:54 +000010182 hdr = nl80211hdr_put(msg, portid, seq, flags, cmd);
Johannes Berg2a519312009-02-10 21:25:55 +010010183 if (!hdr)
10184 return -1;
10185
David S. Miller9360ffd2012-03-29 04:41:26 -040010186 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Bergfd014282012-06-18 19:17:03 +020010187 (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
10188 wdev->netdev->ifindex)) ||
10189 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)))
David S. Miller9360ffd2012-03-29 04:41:26 -040010190 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +010010191
Johannes Berg362a4152009-05-24 16:43:15 +020010192 /* ignore errors and send incomplete event anyway */
10193 nl80211_add_scan_req(msg, rdev);
Johannes Berg2a519312009-02-10 21:25:55 +010010194
10195 return genlmsg_end(msg, hdr);
10196
10197 nla_put_failure:
10198 genlmsg_cancel(msg, hdr);
10199 return -EMSGSIZE;
10200}
10201
Luciano Coelho807f8a82011-05-11 17:09:35 +030010202static int
10203nl80211_send_sched_scan_msg(struct sk_buff *msg,
10204 struct cfg80211_registered_device *rdev,
10205 struct net_device *netdev,
Eric W. Biederman15e47302012-09-07 20:12:54 +000010206 u32 portid, u32 seq, int flags, u32 cmd)
Luciano Coelho807f8a82011-05-11 17:09:35 +030010207{
10208 void *hdr;
10209
Eric W. Biederman15e47302012-09-07 20:12:54 +000010210 hdr = nl80211hdr_put(msg, portid, seq, flags, cmd);
Luciano Coelho807f8a82011-05-11 17:09:35 +030010211 if (!hdr)
10212 return -1;
10213
David S. Miller9360ffd2012-03-29 04:41:26 -040010214 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
10215 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex))
10216 goto nla_put_failure;
Luciano Coelho807f8a82011-05-11 17:09:35 +030010217
10218 return genlmsg_end(msg, hdr);
10219
10220 nla_put_failure:
10221 genlmsg_cancel(msg, hdr);
10222 return -EMSGSIZE;
10223}
10224
Johannes Berga538e2d2009-06-16 19:56:42 +020010225void nl80211_send_scan_start(struct cfg80211_registered_device *rdev,
Johannes Bergfd014282012-06-18 19:17:03 +020010226 struct wireless_dev *wdev)
Johannes Berga538e2d2009-06-16 19:56:42 +020010227{
10228 struct sk_buff *msg;
10229
Thomas Graf58050fc2012-06-28 03:57:45 +000010230 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berga538e2d2009-06-16 19:56:42 +020010231 if (!msg)
10232 return;
10233
Johannes Bergfd014282012-06-18 19:17:03 +020010234 if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0,
Johannes Berga538e2d2009-06-16 19:56:42 +020010235 NL80211_CMD_TRIGGER_SCAN) < 0) {
10236 nlmsg_free(msg);
10237 return;
10238 }
10239
Johannes Berg68eb5502013-11-19 15:19:38 +010010240 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010010241 NL80211_MCGRP_SCAN, GFP_KERNEL);
Johannes Berga538e2d2009-06-16 19:56:42 +020010242}
10243
Johannes Bergf9d15d12014-01-22 11:14:19 +020010244struct sk_buff *nl80211_build_scan_msg(struct cfg80211_registered_device *rdev,
10245 struct wireless_dev *wdev, bool aborted)
Johannes Berg2a519312009-02-10 21:25:55 +010010246{
10247 struct sk_buff *msg;
10248
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -070010249 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg2a519312009-02-10 21:25:55 +010010250 if (!msg)
Johannes Bergf9d15d12014-01-22 11:14:19 +020010251 return NULL;
Johannes Berg2a519312009-02-10 21:25:55 +010010252
Johannes Bergfd014282012-06-18 19:17:03 +020010253 if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0,
Johannes Bergf9d15d12014-01-22 11:14:19 +020010254 aborted ? NL80211_CMD_SCAN_ABORTED :
10255 NL80211_CMD_NEW_SCAN_RESULTS) < 0) {
Johannes Berg2a519312009-02-10 21:25:55 +010010256 nlmsg_free(msg);
Johannes Bergf9d15d12014-01-22 11:14:19 +020010257 return NULL;
Johannes Berg2a519312009-02-10 21:25:55 +010010258 }
10259
Johannes Bergf9d15d12014-01-22 11:14:19 +020010260 return msg;
Johannes Berg2a519312009-02-10 21:25:55 +010010261}
10262
Johannes Bergf9d15d12014-01-22 11:14:19 +020010263void nl80211_send_scan_result(struct cfg80211_registered_device *rdev,
10264 struct sk_buff *msg)
Johannes Berg2a519312009-02-10 21:25:55 +010010265{
Johannes Berg2a519312009-02-10 21:25:55 +010010266 if (!msg)
10267 return;
10268
Johannes Berg68eb5502013-11-19 15:19:38 +010010269 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010010270 NL80211_MCGRP_SCAN, GFP_KERNEL);
Johannes Berg2a519312009-02-10 21:25:55 +010010271}
10272
Luciano Coelho807f8a82011-05-11 17:09:35 +030010273void nl80211_send_sched_scan_results(struct cfg80211_registered_device *rdev,
10274 struct net_device *netdev)
10275{
10276 struct sk_buff *msg;
10277
10278 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
10279 if (!msg)
10280 return;
10281
10282 if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0,
10283 NL80211_CMD_SCHED_SCAN_RESULTS) < 0) {
10284 nlmsg_free(msg);
10285 return;
10286 }
10287
Johannes Berg68eb5502013-11-19 15:19:38 +010010288 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010010289 NL80211_MCGRP_SCAN, GFP_KERNEL);
Luciano Coelho807f8a82011-05-11 17:09:35 +030010290}
10291
10292void nl80211_send_sched_scan(struct cfg80211_registered_device *rdev,
10293 struct net_device *netdev, u32 cmd)
10294{
10295 struct sk_buff *msg;
10296
Thomas Graf58050fc2012-06-28 03:57:45 +000010297 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Luciano Coelho807f8a82011-05-11 17:09:35 +030010298 if (!msg)
10299 return;
10300
10301 if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0, cmd) < 0) {
10302 nlmsg_free(msg);
10303 return;
10304 }
10305
Johannes Berg68eb5502013-11-19 15:19:38 +010010306 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010010307 NL80211_MCGRP_SCAN, GFP_KERNEL);
Luciano Coelho807f8a82011-05-11 17:09:35 +030010308}
10309
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040010310/*
10311 * This can happen on global regulatory changes or device specific settings
10312 * based on custom world regulatory domains.
10313 */
10314void nl80211_send_reg_change_event(struct regulatory_request *request)
10315{
10316 struct sk_buff *msg;
10317 void *hdr;
10318
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -070010319 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040010320 if (!msg)
10321 return;
10322
10323 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_CHANGE);
10324 if (!hdr) {
10325 nlmsg_free(msg);
10326 return;
10327 }
10328
10329 /* Userspace can always count this one always being set */
David S. Miller9360ffd2012-03-29 04:41:26 -040010330 if (nla_put_u8(msg, NL80211_ATTR_REG_INITIATOR, request->initiator))
10331 goto nla_put_failure;
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040010332
David S. Miller9360ffd2012-03-29 04:41:26 -040010333 if (request->alpha2[0] == '0' && request->alpha2[1] == '0') {
10334 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
10335 NL80211_REGDOM_TYPE_WORLD))
10336 goto nla_put_failure;
10337 } else if (request->alpha2[0] == '9' && request->alpha2[1] == '9') {
10338 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
10339 NL80211_REGDOM_TYPE_CUSTOM_WORLD))
10340 goto nla_put_failure;
10341 } else if ((request->alpha2[0] == '9' && request->alpha2[1] == '8') ||
10342 request->intersect) {
10343 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
10344 NL80211_REGDOM_TYPE_INTERSECTION))
10345 goto nla_put_failure;
10346 } else {
10347 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
10348 NL80211_REGDOM_TYPE_COUNTRY) ||
10349 nla_put_string(msg, NL80211_ATTR_REG_ALPHA2,
10350 request->alpha2))
10351 goto nla_put_failure;
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040010352 }
10353
Johannes Bergf4173762012-12-03 18:23:37 +010010354 if (request->wiphy_idx != WIPHY_IDX_INVALID &&
David S. Miller9360ffd2012-03-29 04:41:26 -040010355 nla_put_u32(msg, NL80211_ATTR_WIPHY, request->wiphy_idx))
10356 goto nla_put_failure;
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040010357
Johannes Berg3b7b72e2011-10-22 19:05:51 +020010358 genlmsg_end(msg, hdr);
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040010359
Johannes Bergbc43b282009-07-25 10:54:13 +020010360 rcu_read_lock();
Johannes Berg68eb5502013-11-19 15:19:38 +010010361 genlmsg_multicast_allns(&nl80211_fam, msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010010362 NL80211_MCGRP_REGULATORY, GFP_ATOMIC);
Johannes Bergbc43b282009-07-25 10:54:13 +020010363 rcu_read_unlock();
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040010364
10365 return;
10366
10367nla_put_failure:
10368 genlmsg_cancel(msg, hdr);
10369 nlmsg_free(msg);
10370}
10371
Jouni Malinen6039f6d2009-03-19 13:39:21 +020010372static void nl80211_send_mlme_event(struct cfg80211_registered_device *rdev,
10373 struct net_device *netdev,
10374 const u8 *buf, size_t len,
Johannes Berge6d6e342009-07-01 21:26:47 +020010375 enum nl80211_commands cmd, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +020010376{
10377 struct sk_buff *msg;
10378 void *hdr;
10379
Johannes Berge6d6e342009-07-01 21:26:47 +020010380 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020010381 if (!msg)
10382 return;
10383
10384 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
10385 if (!hdr) {
10386 nlmsg_free(msg);
10387 return;
10388 }
10389
David S. Miller9360ffd2012-03-29 04:41:26 -040010390 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
10391 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
10392 nla_put(msg, NL80211_ATTR_FRAME, len, buf))
10393 goto nla_put_failure;
Jouni Malinen6039f6d2009-03-19 13:39:21 +020010394
Johannes Berg3b7b72e2011-10-22 19:05:51 +020010395 genlmsg_end(msg, hdr);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020010396
Johannes Berg68eb5502013-11-19 15:19:38 +010010397 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010010398 NL80211_MCGRP_MLME, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020010399 return;
10400
10401 nla_put_failure:
10402 genlmsg_cancel(msg, hdr);
10403 nlmsg_free(msg);
10404}
10405
10406void nl80211_send_rx_auth(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +020010407 struct net_device *netdev, const u8 *buf,
10408 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +020010409{
10410 nl80211_send_mlme_event(rdev, netdev, buf, len,
Johannes Berge6d6e342009-07-01 21:26:47 +020010411 NL80211_CMD_AUTHENTICATE, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020010412}
10413
10414void nl80211_send_rx_assoc(struct cfg80211_registered_device *rdev,
10415 struct net_device *netdev, const u8 *buf,
Johannes Berge6d6e342009-07-01 21:26:47 +020010416 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +020010417{
Johannes Berge6d6e342009-07-01 21:26:47 +020010418 nl80211_send_mlme_event(rdev, netdev, buf, len,
10419 NL80211_CMD_ASSOCIATE, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020010420}
10421
Jouni Malinen53b46b82009-03-27 20:53:56 +020010422void nl80211_send_deauth(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +020010423 struct net_device *netdev, const u8 *buf,
10424 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +020010425{
10426 nl80211_send_mlme_event(rdev, netdev, buf, len,
Johannes Berge6d6e342009-07-01 21:26:47 +020010427 NL80211_CMD_DEAUTHENTICATE, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020010428}
10429
Jouni Malinen53b46b82009-03-27 20:53:56 +020010430void nl80211_send_disassoc(struct cfg80211_registered_device *rdev,
10431 struct net_device *netdev, const u8 *buf,
Johannes Berge6d6e342009-07-01 21:26:47 +020010432 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +020010433{
10434 nl80211_send_mlme_event(rdev, netdev, buf, len,
Johannes Berge6d6e342009-07-01 21:26:47 +020010435 NL80211_CMD_DISASSOCIATE, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020010436}
10437
Johannes Berg6ff57cf2013-05-16 00:55:00 +020010438void cfg80211_rx_unprot_mlme_mgmt(struct net_device *dev, const u8 *buf,
10439 size_t len)
Jouni Malinencf4e5942010-12-16 00:52:40 +020010440{
Johannes Berg947add32013-02-22 22:05:20 +010010441 struct wireless_dev *wdev = dev->ieee80211_ptr;
10442 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080010443 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg6ff57cf2013-05-16 00:55:00 +020010444 const struct ieee80211_mgmt *mgmt = (void *)buf;
10445 u32 cmd;
Jouni Malinencf4e5942010-12-16 00:52:40 +020010446
Johannes Berg6ff57cf2013-05-16 00:55:00 +020010447 if (WARN_ON(len < 2))
10448 return;
10449
10450 if (ieee80211_is_deauth(mgmt->frame_control))
10451 cmd = NL80211_CMD_UNPROT_DEAUTHENTICATE;
10452 else
10453 cmd = NL80211_CMD_UNPROT_DISASSOCIATE;
10454
10455 trace_cfg80211_rx_unprot_mlme_mgmt(dev, buf, len);
10456 nl80211_send_mlme_event(rdev, dev, buf, len, cmd, GFP_ATOMIC);
Jouni Malinencf4e5942010-12-16 00:52:40 +020010457}
Johannes Berg6ff57cf2013-05-16 00:55:00 +020010458EXPORT_SYMBOL(cfg80211_rx_unprot_mlme_mgmt);
Jouni Malinencf4e5942010-12-16 00:52:40 +020010459
Luis R. Rodriguez1b06bb42009-05-02 00:34:48 -040010460static void nl80211_send_mlme_timeout(struct cfg80211_registered_device *rdev,
10461 struct net_device *netdev, int cmd,
Johannes Berge6d6e342009-07-01 21:26:47 +020010462 const u8 *addr, gfp_t gfp)
Jouni Malinen1965c852009-04-22 21:38:25 +030010463{
10464 struct sk_buff *msg;
10465 void *hdr;
10466
Johannes Berge6d6e342009-07-01 21:26:47 +020010467 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +030010468 if (!msg)
10469 return;
10470
10471 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
10472 if (!hdr) {
10473 nlmsg_free(msg);
10474 return;
10475 }
10476
David S. Miller9360ffd2012-03-29 04:41:26 -040010477 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
10478 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
10479 nla_put_flag(msg, NL80211_ATTR_TIMED_OUT) ||
10480 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr))
10481 goto nla_put_failure;
Jouni Malinen1965c852009-04-22 21:38:25 +030010482
Johannes Berg3b7b72e2011-10-22 19:05:51 +020010483 genlmsg_end(msg, hdr);
Jouni Malinen1965c852009-04-22 21:38:25 +030010484
Johannes Berg68eb5502013-11-19 15:19:38 +010010485 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010010486 NL80211_MCGRP_MLME, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +030010487 return;
10488
10489 nla_put_failure:
10490 genlmsg_cancel(msg, hdr);
10491 nlmsg_free(msg);
10492}
10493
10494void nl80211_send_auth_timeout(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +020010495 struct net_device *netdev, const u8 *addr,
10496 gfp_t gfp)
Jouni Malinen1965c852009-04-22 21:38:25 +030010497{
10498 nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_AUTHENTICATE,
Johannes Berge6d6e342009-07-01 21:26:47 +020010499 addr, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +030010500}
10501
10502void nl80211_send_assoc_timeout(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +020010503 struct net_device *netdev, const u8 *addr,
10504 gfp_t gfp)
Jouni Malinen1965c852009-04-22 21:38:25 +030010505{
Johannes Berge6d6e342009-07-01 21:26:47 +020010506 nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_ASSOCIATE,
10507 addr, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +030010508}
10509
Samuel Ortizb23aa672009-07-01 21:26:54 +020010510void nl80211_send_connect_result(struct cfg80211_registered_device *rdev,
10511 struct net_device *netdev, const u8 *bssid,
10512 const u8 *req_ie, size_t req_ie_len,
10513 const u8 *resp_ie, size_t resp_ie_len,
10514 u16 status, gfp_t gfp)
10515{
10516 struct sk_buff *msg;
10517 void *hdr;
10518
Thomas Graf58050fc2012-06-28 03:57:45 +000010519 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +020010520 if (!msg)
10521 return;
10522
10523 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONNECT);
10524 if (!hdr) {
10525 nlmsg_free(msg);
10526 return;
10527 }
10528
David S. Miller9360ffd2012-03-29 04:41:26 -040010529 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
10530 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
10531 (bssid && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) ||
10532 nla_put_u16(msg, NL80211_ATTR_STATUS_CODE, status) ||
10533 (req_ie &&
10534 nla_put(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie)) ||
10535 (resp_ie &&
10536 nla_put(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie)))
10537 goto nla_put_failure;
Samuel Ortizb23aa672009-07-01 21:26:54 +020010538
Johannes Berg3b7b72e2011-10-22 19:05:51 +020010539 genlmsg_end(msg, hdr);
Samuel Ortizb23aa672009-07-01 21:26:54 +020010540
Johannes Berg68eb5502013-11-19 15:19:38 +010010541 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010010542 NL80211_MCGRP_MLME, gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +020010543 return;
10544
10545 nla_put_failure:
10546 genlmsg_cancel(msg, hdr);
10547 nlmsg_free(msg);
10548
10549}
10550
10551void nl80211_send_roamed(struct cfg80211_registered_device *rdev,
10552 struct net_device *netdev, const u8 *bssid,
10553 const u8 *req_ie, size_t req_ie_len,
10554 const u8 *resp_ie, size_t resp_ie_len, gfp_t gfp)
10555{
10556 struct sk_buff *msg;
10557 void *hdr;
10558
Thomas Graf58050fc2012-06-28 03:57:45 +000010559 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +020010560 if (!msg)
10561 return;
10562
10563 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_ROAM);
10564 if (!hdr) {
10565 nlmsg_free(msg);
10566 return;
10567 }
10568
David S. Miller9360ffd2012-03-29 04:41:26 -040010569 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
10570 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
10571 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid) ||
10572 (req_ie &&
10573 nla_put(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie)) ||
10574 (resp_ie &&
10575 nla_put(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie)))
10576 goto nla_put_failure;
Samuel Ortizb23aa672009-07-01 21:26:54 +020010577
Johannes Berg3b7b72e2011-10-22 19:05:51 +020010578 genlmsg_end(msg, hdr);
Samuel Ortizb23aa672009-07-01 21:26:54 +020010579
Johannes Berg68eb5502013-11-19 15:19:38 +010010580 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010010581 NL80211_MCGRP_MLME, gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +020010582 return;
10583
10584 nla_put_failure:
10585 genlmsg_cancel(msg, hdr);
10586 nlmsg_free(msg);
10587
10588}
10589
10590void nl80211_send_disconnected(struct cfg80211_registered_device *rdev,
10591 struct net_device *netdev, u16 reason,
Johannes Berg667503dd2009-07-07 03:56:11 +020010592 const u8 *ie, size_t ie_len, bool from_ap)
Samuel Ortizb23aa672009-07-01 21:26:54 +020010593{
10594 struct sk_buff *msg;
10595 void *hdr;
10596
Thomas Graf58050fc2012-06-28 03:57:45 +000010597 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Samuel Ortizb23aa672009-07-01 21:26:54 +020010598 if (!msg)
10599 return;
10600
10601 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DISCONNECT);
10602 if (!hdr) {
10603 nlmsg_free(msg);
10604 return;
10605 }
10606
David S. Miller9360ffd2012-03-29 04:41:26 -040010607 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
10608 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
10609 (from_ap && reason &&
10610 nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason)) ||
10611 (from_ap &&
10612 nla_put_flag(msg, NL80211_ATTR_DISCONNECTED_BY_AP)) ||
10613 (ie && nla_put(msg, NL80211_ATTR_IE, ie_len, ie)))
10614 goto nla_put_failure;
Samuel Ortizb23aa672009-07-01 21:26:54 +020010615
Johannes Berg3b7b72e2011-10-22 19:05:51 +020010616 genlmsg_end(msg, hdr);
Samuel Ortizb23aa672009-07-01 21:26:54 +020010617
Johannes Berg68eb5502013-11-19 15:19:38 +010010618 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010010619 NL80211_MCGRP_MLME, GFP_KERNEL);
Samuel Ortizb23aa672009-07-01 21:26:54 +020010620 return;
10621
10622 nla_put_failure:
10623 genlmsg_cancel(msg, hdr);
10624 nlmsg_free(msg);
10625
10626}
10627
Johannes Berg04a773a2009-04-19 21:24:32 +020010628void nl80211_send_ibss_bssid(struct cfg80211_registered_device *rdev,
10629 struct net_device *netdev, const u8 *bssid,
10630 gfp_t gfp)
10631{
10632 struct sk_buff *msg;
10633 void *hdr;
10634
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -070010635 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Johannes Berg04a773a2009-04-19 21:24:32 +020010636 if (!msg)
10637 return;
10638
10639 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_JOIN_IBSS);
10640 if (!hdr) {
10641 nlmsg_free(msg);
10642 return;
10643 }
10644
David S. Miller9360ffd2012-03-29 04:41:26 -040010645 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
10646 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
10647 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid))
10648 goto nla_put_failure;
Johannes Berg04a773a2009-04-19 21:24:32 +020010649
Johannes Berg3b7b72e2011-10-22 19:05:51 +020010650 genlmsg_end(msg, hdr);
Johannes Berg04a773a2009-04-19 21:24:32 +020010651
Johannes Berg68eb5502013-11-19 15:19:38 +010010652 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010010653 NL80211_MCGRP_MLME, gfp);
Johannes Berg04a773a2009-04-19 21:24:32 +020010654 return;
10655
10656 nla_put_failure:
10657 genlmsg_cancel(msg, hdr);
10658 nlmsg_free(msg);
10659}
10660
Johannes Berg947add32013-02-22 22:05:20 +010010661void cfg80211_notify_new_peer_candidate(struct net_device *dev, const u8 *addr,
10662 const u8* ie, u8 ie_len, gfp_t gfp)
Javier Cardonac93b5e72011-04-07 15:08:34 -070010663{
Johannes Berg947add32013-02-22 22:05:20 +010010664 struct wireless_dev *wdev = dev->ieee80211_ptr;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080010665 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Javier Cardonac93b5e72011-04-07 15:08:34 -070010666 struct sk_buff *msg;
10667 void *hdr;
10668
Johannes Berg947add32013-02-22 22:05:20 +010010669 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_MESH_POINT))
10670 return;
10671
10672 trace_cfg80211_notify_new_peer_candidate(dev, addr);
10673
Javier Cardonac93b5e72011-04-07 15:08:34 -070010674 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
10675 if (!msg)
10676 return;
10677
10678 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NEW_PEER_CANDIDATE);
10679 if (!hdr) {
10680 nlmsg_free(msg);
10681 return;
10682 }
10683
David S. Miller9360ffd2012-03-29 04:41:26 -040010684 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg947add32013-02-22 22:05:20 +010010685 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
10686 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040010687 (ie_len && ie &&
10688 nla_put(msg, NL80211_ATTR_IE, ie_len , ie)))
10689 goto nla_put_failure;
Javier Cardonac93b5e72011-04-07 15:08:34 -070010690
Johannes Berg3b7b72e2011-10-22 19:05:51 +020010691 genlmsg_end(msg, hdr);
Javier Cardonac93b5e72011-04-07 15:08:34 -070010692
Johannes Berg68eb5502013-11-19 15:19:38 +010010693 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010010694 NL80211_MCGRP_MLME, gfp);
Javier Cardonac93b5e72011-04-07 15:08:34 -070010695 return;
10696
10697 nla_put_failure:
10698 genlmsg_cancel(msg, hdr);
10699 nlmsg_free(msg);
10700}
Johannes Berg947add32013-02-22 22:05:20 +010010701EXPORT_SYMBOL(cfg80211_notify_new_peer_candidate);
Javier Cardonac93b5e72011-04-07 15:08:34 -070010702
Jouni Malinena3b8b052009-03-27 21:59:49 +020010703void nl80211_michael_mic_failure(struct cfg80211_registered_device *rdev,
10704 struct net_device *netdev, const u8 *addr,
10705 enum nl80211_key_type key_type, int key_id,
Johannes Berge6d6e342009-07-01 21:26:47 +020010706 const u8 *tsc, gfp_t gfp)
Jouni Malinena3b8b052009-03-27 21:59:49 +020010707{
10708 struct sk_buff *msg;
10709 void *hdr;
10710
Johannes Berge6d6e342009-07-01 21:26:47 +020010711 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinena3b8b052009-03-27 21:59:49 +020010712 if (!msg)
10713 return;
10714
10715 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_MICHAEL_MIC_FAILURE);
10716 if (!hdr) {
10717 nlmsg_free(msg);
10718 return;
10719 }
10720
David S. Miller9360ffd2012-03-29 04:41:26 -040010721 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
10722 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
10723 (addr && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) ||
10724 nla_put_u32(msg, NL80211_ATTR_KEY_TYPE, key_type) ||
10725 (key_id != -1 &&
10726 nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_id)) ||
10727 (tsc && nla_put(msg, NL80211_ATTR_KEY_SEQ, 6, tsc)))
10728 goto nla_put_failure;
Jouni Malinena3b8b052009-03-27 21:59:49 +020010729
Johannes Berg3b7b72e2011-10-22 19:05:51 +020010730 genlmsg_end(msg, hdr);
Jouni Malinena3b8b052009-03-27 21:59:49 +020010731
Johannes Berg68eb5502013-11-19 15:19:38 +010010732 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010010733 NL80211_MCGRP_MLME, gfp);
Jouni Malinena3b8b052009-03-27 21:59:49 +020010734 return;
10735
10736 nla_put_failure:
10737 genlmsg_cancel(msg, hdr);
10738 nlmsg_free(msg);
10739}
10740
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040010741void nl80211_send_beacon_hint_event(struct wiphy *wiphy,
10742 struct ieee80211_channel *channel_before,
10743 struct ieee80211_channel *channel_after)
10744{
10745 struct sk_buff *msg;
10746 void *hdr;
10747 struct nlattr *nl_freq;
10748
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -070010749 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_ATOMIC);
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040010750 if (!msg)
10751 return;
10752
10753 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_BEACON_HINT);
10754 if (!hdr) {
10755 nlmsg_free(msg);
10756 return;
10757 }
10758
10759 /*
10760 * Since we are applying the beacon hint to a wiphy we know its
10761 * wiphy_idx is valid
10762 */
David S. Miller9360ffd2012-03-29 04:41:26 -040010763 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy)))
10764 goto nla_put_failure;
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040010765
10766 /* Before */
10767 nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_BEFORE);
10768 if (!nl_freq)
10769 goto nla_put_failure;
Johannes Bergcdc89b92013-02-18 23:54:36 +010010770 if (nl80211_msg_put_channel(msg, channel_before, false))
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040010771 goto nla_put_failure;
10772 nla_nest_end(msg, nl_freq);
10773
10774 /* After */
10775 nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_AFTER);
10776 if (!nl_freq)
10777 goto nla_put_failure;
Johannes Bergcdc89b92013-02-18 23:54:36 +010010778 if (nl80211_msg_put_channel(msg, channel_after, false))
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040010779 goto nla_put_failure;
10780 nla_nest_end(msg, nl_freq);
10781
Johannes Berg3b7b72e2011-10-22 19:05:51 +020010782 genlmsg_end(msg, hdr);
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040010783
Johannes Berg463d0182009-07-14 00:33:35 +020010784 rcu_read_lock();
Johannes Berg68eb5502013-11-19 15:19:38 +010010785 genlmsg_multicast_allns(&nl80211_fam, msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010010786 NL80211_MCGRP_REGULATORY, GFP_ATOMIC);
Johannes Berg463d0182009-07-14 00:33:35 +020010787 rcu_read_unlock();
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040010788
10789 return;
10790
10791nla_put_failure:
10792 genlmsg_cancel(msg, hdr);
10793 nlmsg_free(msg);
10794}
10795
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010796static void nl80211_send_remain_on_chan_event(
10797 int cmd, struct cfg80211_registered_device *rdev,
Johannes Berg71bbc992012-06-15 15:30:18 +020010798 struct wireless_dev *wdev, u64 cookie,
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010799 struct ieee80211_channel *chan,
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010800 unsigned int duration, gfp_t gfp)
10801{
10802 struct sk_buff *msg;
10803 void *hdr;
10804
10805 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
10806 if (!msg)
10807 return;
10808
10809 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
10810 if (!hdr) {
10811 nlmsg_free(msg);
10812 return;
10813 }
10814
David S. Miller9360ffd2012-03-29 04:41:26 -040010815 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg71bbc992012-06-15 15:30:18 +020010816 (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
10817 wdev->netdev->ifindex)) ||
Johannes Berg00f53352012-07-17 11:53:12 +020010818 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040010819 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, chan->center_freq) ||
Johannes Berg42d97a52012-11-08 18:31:02 +010010820 nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE,
10821 NL80211_CHAN_NO_HT) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040010822 nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie))
10823 goto nla_put_failure;
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010824
David S. Miller9360ffd2012-03-29 04:41:26 -040010825 if (cmd == NL80211_CMD_REMAIN_ON_CHANNEL &&
10826 nla_put_u32(msg, NL80211_ATTR_DURATION, duration))
10827 goto nla_put_failure;
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010828
Johannes Berg3b7b72e2011-10-22 19:05:51 +020010829 genlmsg_end(msg, hdr);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010830
Johannes Berg68eb5502013-11-19 15:19:38 +010010831 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010010832 NL80211_MCGRP_MLME, gfp);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010833 return;
10834
10835 nla_put_failure:
10836 genlmsg_cancel(msg, hdr);
10837 nlmsg_free(msg);
10838}
10839
Johannes Berg947add32013-02-22 22:05:20 +010010840void cfg80211_ready_on_channel(struct wireless_dev *wdev, u64 cookie,
10841 struct ieee80211_channel *chan,
10842 unsigned int duration, gfp_t gfp)
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010843{
Johannes Berg947add32013-02-22 22:05:20 +010010844 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080010845 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg947add32013-02-22 22:05:20 +010010846
10847 trace_cfg80211_ready_on_channel(wdev, cookie, chan, duration);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010848 nl80211_send_remain_on_chan_event(NL80211_CMD_REMAIN_ON_CHANNEL,
Johannes Berg71bbc992012-06-15 15:30:18 +020010849 rdev, wdev, cookie, chan,
Johannes Berg42d97a52012-11-08 18:31:02 +010010850 duration, gfp);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010851}
Johannes Berg947add32013-02-22 22:05:20 +010010852EXPORT_SYMBOL(cfg80211_ready_on_channel);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010853
Johannes Berg947add32013-02-22 22:05:20 +010010854void cfg80211_remain_on_channel_expired(struct wireless_dev *wdev, u64 cookie,
10855 struct ieee80211_channel *chan,
10856 gfp_t gfp)
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010857{
Johannes Berg947add32013-02-22 22:05:20 +010010858 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080010859 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg947add32013-02-22 22:05:20 +010010860
10861 trace_cfg80211_ready_on_channel_expired(wdev, cookie, chan);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010862 nl80211_send_remain_on_chan_event(NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL,
Johannes Berg42d97a52012-11-08 18:31:02 +010010863 rdev, wdev, cookie, chan, 0, gfp);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010864}
Johannes Berg947add32013-02-22 22:05:20 +010010865EXPORT_SYMBOL(cfg80211_remain_on_channel_expired);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010866
Johannes Berg947add32013-02-22 22:05:20 +010010867void cfg80211_new_sta(struct net_device *dev, const u8 *mac_addr,
10868 struct station_info *sinfo, gfp_t gfp)
Johannes Berg98b62182009-12-23 13:15:44 +010010869{
Johannes Berg947add32013-02-22 22:05:20 +010010870 struct wiphy *wiphy = dev->ieee80211_ptr->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080010871 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg98b62182009-12-23 13:15:44 +010010872 struct sk_buff *msg;
10873
Johannes Berg947add32013-02-22 22:05:20 +010010874 trace_cfg80211_new_sta(dev, mac_addr, sinfo);
10875
Thomas Graf58050fc2012-06-28 03:57:45 +000010876 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Johannes Berg98b62182009-12-23 13:15:44 +010010877 if (!msg)
10878 return;
10879
John W. Linville66266b32012-03-15 13:25:41 -040010880 if (nl80211_send_station(msg, 0, 0, 0,
10881 rdev, dev, mac_addr, sinfo) < 0) {
Johannes Berg98b62182009-12-23 13:15:44 +010010882 nlmsg_free(msg);
10883 return;
10884 }
10885
Johannes Berg68eb5502013-11-19 15:19:38 +010010886 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010010887 NL80211_MCGRP_MLME, gfp);
Johannes Berg98b62182009-12-23 13:15:44 +010010888}
Johannes Berg947add32013-02-22 22:05:20 +010010889EXPORT_SYMBOL(cfg80211_new_sta);
Johannes Berg98b62182009-12-23 13:15:44 +010010890
Johannes Berg947add32013-02-22 22:05:20 +010010891void cfg80211_del_sta(struct net_device *dev, const u8 *mac_addr, gfp_t gfp)
Jouni Malinenec15e682011-03-23 15:29:52 +020010892{
Johannes Berg947add32013-02-22 22:05:20 +010010893 struct wiphy *wiphy = dev->ieee80211_ptr->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080010894 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Jouni Malinenec15e682011-03-23 15:29:52 +020010895 struct sk_buff *msg;
10896 void *hdr;
10897
Johannes Berg947add32013-02-22 22:05:20 +010010898 trace_cfg80211_del_sta(dev, mac_addr);
10899
Thomas Graf58050fc2012-06-28 03:57:45 +000010900 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinenec15e682011-03-23 15:29:52 +020010901 if (!msg)
10902 return;
10903
10904 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DEL_STATION);
10905 if (!hdr) {
10906 nlmsg_free(msg);
10907 return;
10908 }
10909
David S. Miller9360ffd2012-03-29 04:41:26 -040010910 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
10911 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr))
10912 goto nla_put_failure;
Jouni Malinenec15e682011-03-23 15:29:52 +020010913
Johannes Berg3b7b72e2011-10-22 19:05:51 +020010914 genlmsg_end(msg, hdr);
Jouni Malinenec15e682011-03-23 15:29:52 +020010915
Johannes Berg68eb5502013-11-19 15:19:38 +010010916 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010010917 NL80211_MCGRP_MLME, gfp);
Jouni Malinenec15e682011-03-23 15:29:52 +020010918 return;
10919
10920 nla_put_failure:
10921 genlmsg_cancel(msg, hdr);
10922 nlmsg_free(msg);
10923}
Johannes Berg947add32013-02-22 22:05:20 +010010924EXPORT_SYMBOL(cfg80211_del_sta);
Jouni Malinenec15e682011-03-23 15:29:52 +020010925
Johannes Berg947add32013-02-22 22:05:20 +010010926void cfg80211_conn_failed(struct net_device *dev, const u8 *mac_addr,
10927 enum nl80211_connect_failed_reason reason,
10928 gfp_t gfp)
Pandiyarajan Pitchaimuthued44a952012-09-18 16:50:49 +053010929{
Johannes Berg947add32013-02-22 22:05:20 +010010930 struct wiphy *wiphy = dev->ieee80211_ptr->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080010931 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Pandiyarajan Pitchaimuthued44a952012-09-18 16:50:49 +053010932 struct sk_buff *msg;
10933 void *hdr;
10934
10935 msg = nlmsg_new(NLMSG_GOODSIZE, gfp);
10936 if (!msg)
10937 return;
10938
10939 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONN_FAILED);
10940 if (!hdr) {
10941 nlmsg_free(msg);
10942 return;
10943 }
10944
10945 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
10946 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) ||
10947 nla_put_u32(msg, NL80211_ATTR_CONN_FAILED_REASON, reason))
10948 goto nla_put_failure;
10949
10950 genlmsg_end(msg, hdr);
10951
Johannes Berg68eb5502013-11-19 15:19:38 +010010952 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010010953 NL80211_MCGRP_MLME, gfp);
Pandiyarajan Pitchaimuthued44a952012-09-18 16:50:49 +053010954 return;
10955
10956 nla_put_failure:
10957 genlmsg_cancel(msg, hdr);
10958 nlmsg_free(msg);
10959}
Johannes Berg947add32013-02-22 22:05:20 +010010960EXPORT_SYMBOL(cfg80211_conn_failed);
Pandiyarajan Pitchaimuthued44a952012-09-18 16:50:49 +053010961
Johannes Bergb92ab5d2011-11-04 11:18:19 +010010962static bool __nl80211_unexpected_frame(struct net_device *dev, u8 cmd,
10963 const u8 *addr, gfp_t gfp)
Johannes Berg28946da2011-11-04 11:18:12 +010010964{
10965 struct wireless_dev *wdev = dev->ieee80211_ptr;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080010966 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Johannes Berg28946da2011-11-04 11:18:12 +010010967 struct sk_buff *msg;
10968 void *hdr;
Eric W. Biederman15e47302012-09-07 20:12:54 +000010969 u32 nlportid = ACCESS_ONCE(wdev->ap_unexpected_nlportid);
Johannes Berg28946da2011-11-04 11:18:12 +010010970
Eric W. Biederman15e47302012-09-07 20:12:54 +000010971 if (!nlportid)
Johannes Berg28946da2011-11-04 11:18:12 +010010972 return false;
10973
10974 msg = nlmsg_new(100, gfp);
10975 if (!msg)
10976 return true;
10977
Johannes Bergb92ab5d2011-11-04 11:18:19 +010010978 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
Johannes Berg28946da2011-11-04 11:18:12 +010010979 if (!hdr) {
10980 nlmsg_free(msg);
10981 return true;
10982 }
10983
David S. Miller9360ffd2012-03-29 04:41:26 -040010984 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
10985 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
10986 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr))
10987 goto nla_put_failure;
Johannes Berg28946da2011-11-04 11:18:12 +010010988
Johannes Berg9c90a9f2013-06-04 12:46:03 +020010989 genlmsg_end(msg, hdr);
Eric W. Biederman15e47302012-09-07 20:12:54 +000010990 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid);
Johannes Berg28946da2011-11-04 11:18:12 +010010991 return true;
10992
10993 nla_put_failure:
10994 genlmsg_cancel(msg, hdr);
10995 nlmsg_free(msg);
10996 return true;
10997}
10998
Johannes Berg947add32013-02-22 22:05:20 +010010999bool cfg80211_rx_spurious_frame(struct net_device *dev,
11000 const u8 *addr, gfp_t gfp)
Johannes Bergb92ab5d2011-11-04 11:18:19 +010011001{
Johannes Berg947add32013-02-22 22:05:20 +010011002 struct wireless_dev *wdev = dev->ieee80211_ptr;
11003 bool ret;
Johannes Bergb92ab5d2011-11-04 11:18:19 +010011004
Johannes Berg947add32013-02-22 22:05:20 +010011005 trace_cfg80211_rx_spurious_frame(dev, addr);
11006
11007 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP &&
11008 wdev->iftype != NL80211_IFTYPE_P2P_GO)) {
11009 trace_cfg80211_return_bool(false);
11010 return false;
11011 }
11012 ret = __nl80211_unexpected_frame(dev, NL80211_CMD_UNEXPECTED_FRAME,
11013 addr, gfp);
11014 trace_cfg80211_return_bool(ret);
11015 return ret;
Johannes Bergb92ab5d2011-11-04 11:18:19 +010011016}
Johannes Berg947add32013-02-22 22:05:20 +010011017EXPORT_SYMBOL(cfg80211_rx_spurious_frame);
11018
11019bool cfg80211_rx_unexpected_4addr_frame(struct net_device *dev,
11020 const u8 *addr, gfp_t gfp)
11021{
11022 struct wireless_dev *wdev = dev->ieee80211_ptr;
11023 bool ret;
11024
11025 trace_cfg80211_rx_unexpected_4addr_frame(dev, addr);
11026
11027 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP &&
11028 wdev->iftype != NL80211_IFTYPE_P2P_GO &&
11029 wdev->iftype != NL80211_IFTYPE_AP_VLAN)) {
11030 trace_cfg80211_return_bool(false);
11031 return false;
11032 }
11033 ret = __nl80211_unexpected_frame(dev,
11034 NL80211_CMD_UNEXPECTED_4ADDR_FRAME,
11035 addr, gfp);
11036 trace_cfg80211_return_bool(ret);
11037 return ret;
11038}
11039EXPORT_SYMBOL(cfg80211_rx_unexpected_4addr_frame);
Johannes Bergb92ab5d2011-11-04 11:18:19 +010011040
Johannes Berg2e161f72010-08-12 15:38:38 +020011041int nl80211_send_mgmt(struct cfg80211_registered_device *rdev,
Eric W. Biederman15e47302012-09-07 20:12:54 +000011042 struct wireless_dev *wdev, u32 nlportid,
Johannes Berg804483e2012-03-05 22:18:41 +010011043 int freq, int sig_dbm,
Vladimir Kondratiev19504cf2013-08-15 14:51:28 +030011044 const u8 *buf, size_t len, u32 flags, gfp_t gfp)
Jouni Malinen026331c2010-02-15 12:53:10 +020011045{
Johannes Berg71bbc992012-06-15 15:30:18 +020011046 struct net_device *netdev = wdev->netdev;
Jouni Malinen026331c2010-02-15 12:53:10 +020011047 struct sk_buff *msg;
11048 void *hdr;
Jouni Malinen026331c2010-02-15 12:53:10 +020011049
11050 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
11051 if (!msg)
11052 return -ENOMEM;
11053
Johannes Berg2e161f72010-08-12 15:38:38 +020011054 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME);
Jouni Malinen026331c2010-02-15 12:53:10 +020011055 if (!hdr) {
11056 nlmsg_free(msg);
11057 return -ENOMEM;
11058 }
11059
David S. Miller9360ffd2012-03-29 04:41:26 -040011060 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg71bbc992012-06-15 15:30:18 +020011061 (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
11062 netdev->ifindex)) ||
Ilan Peera8384902013-05-08 16:35:55 +030011063 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040011064 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq) ||
11065 (sig_dbm &&
11066 nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) ||
Vladimir Kondratiev19504cf2013-08-15 14:51:28 +030011067 nla_put(msg, NL80211_ATTR_FRAME, len, buf) ||
11068 (flags &&
11069 nla_put_u32(msg, NL80211_ATTR_RXMGMT_FLAGS, flags)))
David S. Miller9360ffd2012-03-29 04:41:26 -040011070 goto nla_put_failure;
Jouni Malinen026331c2010-02-15 12:53:10 +020011071
Johannes Berg3b7b72e2011-10-22 19:05:51 +020011072 genlmsg_end(msg, hdr);
Jouni Malinen026331c2010-02-15 12:53:10 +020011073
Eric W. Biederman15e47302012-09-07 20:12:54 +000011074 return genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid);
Jouni Malinen026331c2010-02-15 12:53:10 +020011075
11076 nla_put_failure:
11077 genlmsg_cancel(msg, hdr);
11078 nlmsg_free(msg);
11079 return -ENOBUFS;
11080}
11081
Johannes Berg947add32013-02-22 22:05:20 +010011082void cfg80211_mgmt_tx_status(struct wireless_dev *wdev, u64 cookie,
11083 const u8 *buf, size_t len, bool ack, gfp_t gfp)
Jouni Malinen026331c2010-02-15 12:53:10 +020011084{
Johannes Berg947add32013-02-22 22:05:20 +010011085 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080011086 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg71bbc992012-06-15 15:30:18 +020011087 struct net_device *netdev = wdev->netdev;
Jouni Malinen026331c2010-02-15 12:53:10 +020011088 struct sk_buff *msg;
11089 void *hdr;
11090
Johannes Berg947add32013-02-22 22:05:20 +010011091 trace_cfg80211_mgmt_tx_status(wdev, cookie, ack);
11092
Jouni Malinen026331c2010-02-15 12:53:10 +020011093 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
11094 if (!msg)
11095 return;
11096
Johannes Berg2e161f72010-08-12 15:38:38 +020011097 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME_TX_STATUS);
Jouni Malinen026331c2010-02-15 12:53:10 +020011098 if (!hdr) {
11099 nlmsg_free(msg);
11100 return;
11101 }
11102
David S. Miller9360ffd2012-03-29 04:41:26 -040011103 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg71bbc992012-06-15 15:30:18 +020011104 (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
11105 netdev->ifindex)) ||
Ilan Peera8384902013-05-08 16:35:55 +030011106 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040011107 nla_put(msg, NL80211_ATTR_FRAME, len, buf) ||
11108 nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie) ||
11109 (ack && nla_put_flag(msg, NL80211_ATTR_ACK)))
11110 goto nla_put_failure;
Jouni Malinen026331c2010-02-15 12:53:10 +020011111
Johannes Berg3b7b72e2011-10-22 19:05:51 +020011112 genlmsg_end(msg, hdr);
Jouni Malinen026331c2010-02-15 12:53:10 +020011113
Johannes Berg68eb5502013-11-19 15:19:38 +010011114 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011115 NL80211_MCGRP_MLME, gfp);
Jouni Malinen026331c2010-02-15 12:53:10 +020011116 return;
11117
11118 nla_put_failure:
11119 genlmsg_cancel(msg, hdr);
11120 nlmsg_free(msg);
11121}
Johannes Berg947add32013-02-22 22:05:20 +010011122EXPORT_SYMBOL(cfg80211_mgmt_tx_status);
Jouni Malinen026331c2010-02-15 12:53:10 +020011123
Johannes Berg947add32013-02-22 22:05:20 +010011124void cfg80211_cqm_rssi_notify(struct net_device *dev,
11125 enum nl80211_cqm_rssi_threshold_event rssi_event,
11126 gfp_t gfp)
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020011127{
Johannes Berg947add32013-02-22 22:05:20 +010011128 struct wireless_dev *wdev = dev->ieee80211_ptr;
11129 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080011130 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020011131 struct sk_buff *msg;
11132 struct nlattr *pinfoattr;
11133 void *hdr;
11134
Johannes Berg947add32013-02-22 22:05:20 +010011135 trace_cfg80211_cqm_rssi_notify(dev, rssi_event);
11136
Thomas Graf58050fc2012-06-28 03:57:45 +000011137 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020011138 if (!msg)
11139 return;
11140
11141 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM);
11142 if (!hdr) {
11143 nlmsg_free(msg);
11144 return;
11145 }
11146
David S. Miller9360ffd2012-03-29 04:41:26 -040011147 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg947add32013-02-22 22:05:20 +010011148 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex))
David S. Miller9360ffd2012-03-29 04:41:26 -040011149 goto nla_put_failure;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020011150
11151 pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM);
11152 if (!pinfoattr)
11153 goto nla_put_failure;
11154
David S. Miller9360ffd2012-03-29 04:41:26 -040011155 if (nla_put_u32(msg, NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT,
11156 rssi_event))
11157 goto nla_put_failure;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020011158
11159 nla_nest_end(msg, pinfoattr);
11160
Johannes Berg3b7b72e2011-10-22 19:05:51 +020011161 genlmsg_end(msg, hdr);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020011162
Johannes Berg68eb5502013-11-19 15:19:38 +010011163 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011164 NL80211_MCGRP_MLME, gfp);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020011165 return;
11166
11167 nla_put_failure:
11168 genlmsg_cancel(msg, hdr);
11169 nlmsg_free(msg);
11170}
Johannes Berg947add32013-02-22 22:05:20 +010011171EXPORT_SYMBOL(cfg80211_cqm_rssi_notify);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020011172
Johannes Berg947add32013-02-22 22:05:20 +010011173static void nl80211_gtk_rekey_notify(struct cfg80211_registered_device *rdev,
11174 struct net_device *netdev, const u8 *bssid,
11175 const u8 *replay_ctr, gfp_t gfp)
Johannes Berge5497d72011-07-05 16:35:40 +020011176{
11177 struct sk_buff *msg;
11178 struct nlattr *rekey_attr;
11179 void *hdr;
11180
Thomas Graf58050fc2012-06-28 03:57:45 +000011181 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Johannes Berge5497d72011-07-05 16:35:40 +020011182 if (!msg)
11183 return;
11184
11185 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_REKEY_OFFLOAD);
11186 if (!hdr) {
11187 nlmsg_free(msg);
11188 return;
11189 }
11190
David S. Miller9360ffd2012-03-29 04:41:26 -040011191 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
11192 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
11193 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid))
11194 goto nla_put_failure;
Johannes Berge5497d72011-07-05 16:35:40 +020011195
11196 rekey_attr = nla_nest_start(msg, NL80211_ATTR_REKEY_DATA);
11197 if (!rekey_attr)
11198 goto nla_put_failure;
11199
David S. Miller9360ffd2012-03-29 04:41:26 -040011200 if (nla_put(msg, NL80211_REKEY_DATA_REPLAY_CTR,
11201 NL80211_REPLAY_CTR_LEN, replay_ctr))
11202 goto nla_put_failure;
Johannes Berge5497d72011-07-05 16:35:40 +020011203
11204 nla_nest_end(msg, rekey_attr);
11205
Johannes Berg3b7b72e2011-10-22 19:05:51 +020011206 genlmsg_end(msg, hdr);
Johannes Berge5497d72011-07-05 16:35:40 +020011207
Johannes Berg68eb5502013-11-19 15:19:38 +010011208 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011209 NL80211_MCGRP_MLME, gfp);
Johannes Berge5497d72011-07-05 16:35:40 +020011210 return;
11211
11212 nla_put_failure:
11213 genlmsg_cancel(msg, hdr);
11214 nlmsg_free(msg);
11215}
11216
Johannes Berg947add32013-02-22 22:05:20 +010011217void cfg80211_gtk_rekey_notify(struct net_device *dev, const u8 *bssid,
11218 const u8 *replay_ctr, gfp_t gfp)
11219{
11220 struct wireless_dev *wdev = dev->ieee80211_ptr;
11221 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080011222 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg947add32013-02-22 22:05:20 +010011223
11224 trace_cfg80211_gtk_rekey_notify(dev, bssid);
11225 nl80211_gtk_rekey_notify(rdev, dev, bssid, replay_ctr, gfp);
11226}
11227EXPORT_SYMBOL(cfg80211_gtk_rekey_notify);
11228
11229static void
11230nl80211_pmksa_candidate_notify(struct cfg80211_registered_device *rdev,
11231 struct net_device *netdev, int index,
11232 const u8 *bssid, bool preauth, gfp_t gfp)
Jouni Malinenc9df56b2011-09-16 18:56:23 +030011233{
11234 struct sk_buff *msg;
11235 struct nlattr *attr;
11236 void *hdr;
11237
Thomas Graf58050fc2012-06-28 03:57:45 +000011238 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinenc9df56b2011-09-16 18:56:23 +030011239 if (!msg)
11240 return;
11241
11242 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PMKSA_CANDIDATE);
11243 if (!hdr) {
11244 nlmsg_free(msg);
11245 return;
11246 }
11247
David S. Miller9360ffd2012-03-29 04:41:26 -040011248 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
11249 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex))
11250 goto nla_put_failure;
Jouni Malinenc9df56b2011-09-16 18:56:23 +030011251
11252 attr = nla_nest_start(msg, NL80211_ATTR_PMKSA_CANDIDATE);
11253 if (!attr)
11254 goto nla_put_failure;
11255
David S. Miller9360ffd2012-03-29 04:41:26 -040011256 if (nla_put_u32(msg, NL80211_PMKSA_CANDIDATE_INDEX, index) ||
11257 nla_put(msg, NL80211_PMKSA_CANDIDATE_BSSID, ETH_ALEN, bssid) ||
11258 (preauth &&
11259 nla_put_flag(msg, NL80211_PMKSA_CANDIDATE_PREAUTH)))
11260 goto nla_put_failure;
Jouni Malinenc9df56b2011-09-16 18:56:23 +030011261
11262 nla_nest_end(msg, attr);
11263
Johannes Berg3b7b72e2011-10-22 19:05:51 +020011264 genlmsg_end(msg, hdr);
Jouni Malinenc9df56b2011-09-16 18:56:23 +030011265
Johannes Berg68eb5502013-11-19 15:19:38 +010011266 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011267 NL80211_MCGRP_MLME, gfp);
Jouni Malinenc9df56b2011-09-16 18:56:23 +030011268 return;
11269
11270 nla_put_failure:
11271 genlmsg_cancel(msg, hdr);
11272 nlmsg_free(msg);
11273}
11274
Johannes Berg947add32013-02-22 22:05:20 +010011275void cfg80211_pmksa_candidate_notify(struct net_device *dev, int index,
11276 const u8 *bssid, bool preauth, gfp_t gfp)
11277{
11278 struct wireless_dev *wdev = dev->ieee80211_ptr;
11279 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080011280 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg947add32013-02-22 22:05:20 +010011281
11282 trace_cfg80211_pmksa_candidate_notify(dev, index, bssid, preauth);
11283 nl80211_pmksa_candidate_notify(rdev, dev, index, bssid, preauth, gfp);
11284}
11285EXPORT_SYMBOL(cfg80211_pmksa_candidate_notify);
11286
11287static void nl80211_ch_switch_notify(struct cfg80211_registered_device *rdev,
11288 struct net_device *netdev,
11289 struct cfg80211_chan_def *chandef,
11290 gfp_t gfp)
Thomas Pedersen53145262012-04-06 13:35:47 -070011291{
11292 struct sk_buff *msg;
11293 void *hdr;
11294
Thomas Graf58050fc2012-06-28 03:57:45 +000011295 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Thomas Pedersen53145262012-04-06 13:35:47 -070011296 if (!msg)
11297 return;
11298
11299 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CH_SWITCH_NOTIFY);
11300 if (!hdr) {
11301 nlmsg_free(msg);
11302 return;
11303 }
11304
Johannes Berg683b6d32012-11-08 21:25:48 +010011305 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex))
11306 goto nla_put_failure;
11307
11308 if (nl80211_send_chandef(msg, chandef))
John W. Linville7eab0f62012-04-12 14:25:14 -040011309 goto nla_put_failure;
Thomas Pedersen53145262012-04-06 13:35:47 -070011310
11311 genlmsg_end(msg, hdr);
11312
Johannes Berg68eb5502013-11-19 15:19:38 +010011313 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011314 NL80211_MCGRP_MLME, gfp);
Thomas Pedersen53145262012-04-06 13:35:47 -070011315 return;
11316
11317 nla_put_failure:
11318 genlmsg_cancel(msg, hdr);
11319 nlmsg_free(msg);
11320}
11321
Johannes Berg947add32013-02-22 22:05:20 +010011322void cfg80211_ch_switch_notify(struct net_device *dev,
11323 struct cfg80211_chan_def *chandef)
Thomas Pedersen84f10702012-07-12 16:17:33 -070011324{
Johannes Berg947add32013-02-22 22:05:20 +010011325 struct wireless_dev *wdev = dev->ieee80211_ptr;
11326 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080011327 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg947add32013-02-22 22:05:20 +010011328
Simon Wunderliche487eae2013-11-21 18:19:51 +010011329 ASSERT_WDEV_LOCK(wdev);
Johannes Berg947add32013-02-22 22:05:20 +010011330
Simon Wunderliche487eae2013-11-21 18:19:51 +010011331 trace_cfg80211_ch_switch_notify(dev, chandef);
Johannes Berg947add32013-02-22 22:05:20 +010011332
11333 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP &&
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +020011334 wdev->iftype != NL80211_IFTYPE_P2P_GO &&
Chun-Yeow Yeohb8456a12013-10-17 15:55:02 -070011335 wdev->iftype != NL80211_IFTYPE_ADHOC &&
11336 wdev->iftype != NL80211_IFTYPE_MESH_POINT))
Simon Wunderliche487eae2013-11-21 18:19:51 +010011337 return;
Johannes Berg947add32013-02-22 22:05:20 +010011338
Michal Kazior9e0e2962014-01-29 14:22:27 +010011339 wdev->chandef = *chandef;
Janusz Dziedzic96f55f12014-01-24 14:29:21 +010011340 wdev->preset_chandef = *chandef;
Johannes Berg947add32013-02-22 22:05:20 +010011341 nl80211_ch_switch_notify(rdev, dev, chandef, GFP_KERNEL);
Johannes Berg947add32013-02-22 22:05:20 +010011342}
11343EXPORT_SYMBOL(cfg80211_ch_switch_notify);
11344
11345void cfg80211_cqm_txe_notify(struct net_device *dev,
11346 const u8 *peer, u32 num_packets,
11347 u32 rate, u32 intvl, gfp_t gfp)
11348{
11349 struct wireless_dev *wdev = dev->ieee80211_ptr;
11350 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080011351 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Thomas Pedersen84f10702012-07-12 16:17:33 -070011352 struct sk_buff *msg;
11353 struct nlattr *pinfoattr;
11354 void *hdr;
11355
11356 msg = nlmsg_new(NLMSG_GOODSIZE, gfp);
11357 if (!msg)
11358 return;
11359
11360 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM);
11361 if (!hdr) {
11362 nlmsg_free(msg);
11363 return;
11364 }
11365
11366 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg947add32013-02-22 22:05:20 +010011367 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
Thomas Pedersen84f10702012-07-12 16:17:33 -070011368 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer))
11369 goto nla_put_failure;
11370
11371 pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM);
11372 if (!pinfoattr)
11373 goto nla_put_failure;
11374
11375 if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_PKTS, num_packets))
11376 goto nla_put_failure;
11377
11378 if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_RATE, rate))
11379 goto nla_put_failure;
11380
11381 if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_INTVL, intvl))
11382 goto nla_put_failure;
11383
11384 nla_nest_end(msg, pinfoattr);
11385
11386 genlmsg_end(msg, hdr);
11387
Johannes Berg68eb5502013-11-19 15:19:38 +010011388 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011389 NL80211_MCGRP_MLME, gfp);
Thomas Pedersen84f10702012-07-12 16:17:33 -070011390 return;
11391
11392 nla_put_failure:
11393 genlmsg_cancel(msg, hdr);
11394 nlmsg_free(msg);
11395}
Johannes Berg947add32013-02-22 22:05:20 +010011396EXPORT_SYMBOL(cfg80211_cqm_txe_notify);
Thomas Pedersen84f10702012-07-12 16:17:33 -070011397
11398void
Simon Wunderlich04f39042013-02-08 18:16:19 +010011399nl80211_radar_notify(struct cfg80211_registered_device *rdev,
Janusz Dziedzicd2859df2013-11-06 13:55:51 +010011400 const struct cfg80211_chan_def *chandef,
Simon Wunderlich04f39042013-02-08 18:16:19 +010011401 enum nl80211_radar_event event,
11402 struct net_device *netdev, gfp_t gfp)
11403{
11404 struct sk_buff *msg;
11405 void *hdr;
11406
11407 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
11408 if (!msg)
11409 return;
11410
11411 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_RADAR_DETECT);
11412 if (!hdr) {
11413 nlmsg_free(msg);
11414 return;
11415 }
11416
11417 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx))
11418 goto nla_put_failure;
11419
11420 /* NOP and radar events don't need a netdev parameter */
11421 if (netdev) {
11422 struct wireless_dev *wdev = netdev->ieee80211_ptr;
11423
11424 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
11425 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)))
11426 goto nla_put_failure;
11427 }
11428
11429 if (nla_put_u32(msg, NL80211_ATTR_RADAR_EVENT, event))
11430 goto nla_put_failure;
11431
11432 if (nl80211_send_chandef(msg, chandef))
11433 goto nla_put_failure;
11434
Johannes Berg9c90a9f2013-06-04 12:46:03 +020011435 genlmsg_end(msg, hdr);
Simon Wunderlich04f39042013-02-08 18:16:19 +010011436
Johannes Berg68eb5502013-11-19 15:19:38 +010011437 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011438 NL80211_MCGRP_MLME, gfp);
Simon Wunderlich04f39042013-02-08 18:16:19 +010011439 return;
11440
11441 nla_put_failure:
11442 genlmsg_cancel(msg, hdr);
11443 nlmsg_free(msg);
11444}
11445
Johannes Berg947add32013-02-22 22:05:20 +010011446void cfg80211_cqm_pktloss_notify(struct net_device *dev,
11447 const u8 *peer, u32 num_packets, gfp_t gfp)
Johannes Bergc063dbf2010-11-24 08:10:05 +010011448{
Johannes Berg947add32013-02-22 22:05:20 +010011449 struct wireless_dev *wdev = dev->ieee80211_ptr;
11450 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080011451 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Bergc063dbf2010-11-24 08:10:05 +010011452 struct sk_buff *msg;
11453 struct nlattr *pinfoattr;
11454 void *hdr;
11455
Johannes Berg947add32013-02-22 22:05:20 +010011456 trace_cfg80211_cqm_pktloss_notify(dev, peer, num_packets);
11457
Thomas Graf58050fc2012-06-28 03:57:45 +000011458 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Johannes Bergc063dbf2010-11-24 08:10:05 +010011459 if (!msg)
11460 return;
11461
11462 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM);
11463 if (!hdr) {
11464 nlmsg_free(msg);
11465 return;
11466 }
11467
David S. Miller9360ffd2012-03-29 04:41:26 -040011468 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg947add32013-02-22 22:05:20 +010011469 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040011470 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer))
11471 goto nla_put_failure;
Johannes Bergc063dbf2010-11-24 08:10:05 +010011472
11473 pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM);
11474 if (!pinfoattr)
11475 goto nla_put_failure;
11476
David S. Miller9360ffd2012-03-29 04:41:26 -040011477 if (nla_put_u32(msg, NL80211_ATTR_CQM_PKT_LOSS_EVENT, num_packets))
11478 goto nla_put_failure;
Johannes Bergc063dbf2010-11-24 08:10:05 +010011479
11480 nla_nest_end(msg, pinfoattr);
11481
Johannes Berg3b7b72e2011-10-22 19:05:51 +020011482 genlmsg_end(msg, hdr);
Johannes Bergc063dbf2010-11-24 08:10:05 +010011483
Johannes Berg68eb5502013-11-19 15:19:38 +010011484 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011485 NL80211_MCGRP_MLME, gfp);
Johannes Bergc063dbf2010-11-24 08:10:05 +010011486 return;
11487
11488 nla_put_failure:
11489 genlmsg_cancel(msg, hdr);
11490 nlmsg_free(msg);
11491}
Johannes Berg947add32013-02-22 22:05:20 +010011492EXPORT_SYMBOL(cfg80211_cqm_pktloss_notify);
Johannes Bergc063dbf2010-11-24 08:10:05 +010011493
Johannes Berg7f6cf312011-11-04 11:18:15 +010011494void cfg80211_probe_status(struct net_device *dev, const u8 *addr,
11495 u64 cookie, bool acked, gfp_t gfp)
11496{
11497 struct wireless_dev *wdev = dev->ieee80211_ptr;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080011498 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Johannes Berg7f6cf312011-11-04 11:18:15 +010011499 struct sk_buff *msg;
11500 void *hdr;
Johannes Berg7f6cf312011-11-04 11:18:15 +010011501
Beni Lev4ee3e062012-08-27 12:49:39 +030011502 trace_cfg80211_probe_status(dev, addr, cookie, acked);
11503
Thomas Graf58050fc2012-06-28 03:57:45 +000011504 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Beni Lev4ee3e062012-08-27 12:49:39 +030011505
Johannes Berg7f6cf312011-11-04 11:18:15 +010011506 if (!msg)
11507 return;
11508
11509 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PROBE_CLIENT);
11510 if (!hdr) {
11511 nlmsg_free(msg);
11512 return;
11513 }
11514
David S. Miller9360ffd2012-03-29 04:41:26 -040011515 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
11516 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
11517 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) ||
11518 nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie) ||
11519 (acked && nla_put_flag(msg, NL80211_ATTR_ACK)))
11520 goto nla_put_failure;
Johannes Berg7f6cf312011-11-04 11:18:15 +010011521
Johannes Berg9c90a9f2013-06-04 12:46:03 +020011522 genlmsg_end(msg, hdr);
Johannes Berg7f6cf312011-11-04 11:18:15 +010011523
Johannes Berg68eb5502013-11-19 15:19:38 +010011524 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011525 NL80211_MCGRP_MLME, gfp);
Johannes Berg7f6cf312011-11-04 11:18:15 +010011526 return;
11527
11528 nla_put_failure:
11529 genlmsg_cancel(msg, hdr);
11530 nlmsg_free(msg);
11531}
11532EXPORT_SYMBOL(cfg80211_probe_status);
11533
Johannes Berg5e7602302011-11-04 11:18:17 +010011534void cfg80211_report_obss_beacon(struct wiphy *wiphy,
11535 const u8 *frame, size_t len,
Ben Greear37c73b52012-10-26 14:49:25 -070011536 int freq, int sig_dbm)
Johannes Berg5e7602302011-11-04 11:18:17 +010011537{
Zhao, Gangf26cbf42014-04-21 12:53:03 +080011538 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg5e7602302011-11-04 11:18:17 +010011539 struct sk_buff *msg;
11540 void *hdr;
Ben Greear37c73b52012-10-26 14:49:25 -070011541 struct cfg80211_beacon_registration *reg;
Johannes Berg5e7602302011-11-04 11:18:17 +010011542
Beni Lev4ee3e062012-08-27 12:49:39 +030011543 trace_cfg80211_report_obss_beacon(wiphy, frame, len, freq, sig_dbm);
11544
Ben Greear37c73b52012-10-26 14:49:25 -070011545 spin_lock_bh(&rdev->beacon_registrations_lock);
11546 list_for_each_entry(reg, &rdev->beacon_registrations, list) {
11547 msg = nlmsg_new(len + 100, GFP_ATOMIC);
11548 if (!msg) {
11549 spin_unlock_bh(&rdev->beacon_registrations_lock);
11550 return;
11551 }
Johannes Berg5e7602302011-11-04 11:18:17 +010011552
Ben Greear37c73b52012-10-26 14:49:25 -070011553 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME);
11554 if (!hdr)
11555 goto nla_put_failure;
Johannes Berg5e7602302011-11-04 11:18:17 +010011556
Ben Greear37c73b52012-10-26 14:49:25 -070011557 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
11558 (freq &&
11559 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq)) ||
11560 (sig_dbm &&
11561 nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) ||
11562 nla_put(msg, NL80211_ATTR_FRAME, len, frame))
11563 goto nla_put_failure;
11564
11565 genlmsg_end(msg, hdr);
11566
11567 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, reg->nlportid);
Johannes Berg5e7602302011-11-04 11:18:17 +010011568 }
Ben Greear37c73b52012-10-26 14:49:25 -070011569 spin_unlock_bh(&rdev->beacon_registrations_lock);
Johannes Berg5e7602302011-11-04 11:18:17 +010011570 return;
11571
11572 nla_put_failure:
Ben Greear37c73b52012-10-26 14:49:25 -070011573 spin_unlock_bh(&rdev->beacon_registrations_lock);
11574 if (hdr)
11575 genlmsg_cancel(msg, hdr);
Johannes Berg5e7602302011-11-04 11:18:17 +010011576 nlmsg_free(msg);
11577}
11578EXPORT_SYMBOL(cfg80211_report_obss_beacon);
11579
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010011580#ifdef CONFIG_PM
11581void cfg80211_report_wowlan_wakeup(struct wireless_dev *wdev,
11582 struct cfg80211_wowlan_wakeup *wakeup,
11583 gfp_t gfp)
11584{
Zhao, Gangf26cbf42014-04-21 12:53:03 +080011585 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010011586 struct sk_buff *msg;
11587 void *hdr;
Johannes Berg9c90a9f2013-06-04 12:46:03 +020011588 int size = 200;
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010011589
11590 trace_cfg80211_report_wowlan_wakeup(wdev->wiphy, wdev, wakeup);
11591
11592 if (wakeup)
11593 size += wakeup->packet_present_len;
11594
11595 msg = nlmsg_new(size, gfp);
11596 if (!msg)
11597 return;
11598
11599 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_WOWLAN);
11600 if (!hdr)
11601 goto free_msg;
11602
11603 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
11604 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)))
11605 goto free_msg;
11606
11607 if (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
11608 wdev->netdev->ifindex))
11609 goto free_msg;
11610
11611 if (wakeup) {
11612 struct nlattr *reasons;
11613
11614 reasons = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS);
Johannes Berg7fa322c2013-10-25 11:16:58 +020011615 if (!reasons)
11616 goto free_msg;
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010011617
11618 if (wakeup->disconnect &&
11619 nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT))
11620 goto free_msg;
11621 if (wakeup->magic_pkt &&
11622 nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT))
11623 goto free_msg;
11624 if (wakeup->gtk_rekey_failure &&
11625 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE))
11626 goto free_msg;
11627 if (wakeup->eap_identity_req &&
11628 nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST))
11629 goto free_msg;
11630 if (wakeup->four_way_handshake &&
11631 nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE))
11632 goto free_msg;
11633 if (wakeup->rfkill_release &&
11634 nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE))
11635 goto free_msg;
11636
11637 if (wakeup->pattern_idx >= 0 &&
11638 nla_put_u32(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN,
11639 wakeup->pattern_idx))
11640 goto free_msg;
11641
Johannes Bergae917c92013-10-25 11:05:22 +020011642 if (wakeup->tcp_match &&
11643 nla_put_flag(msg, NL80211_WOWLAN_TRIG_WAKEUP_TCP_MATCH))
11644 goto free_msg;
Johannes Berg2a0e0472013-01-23 22:57:40 +010011645
Johannes Bergae917c92013-10-25 11:05:22 +020011646 if (wakeup->tcp_connlost &&
11647 nla_put_flag(msg, NL80211_WOWLAN_TRIG_WAKEUP_TCP_CONNLOST))
11648 goto free_msg;
Johannes Berg2a0e0472013-01-23 22:57:40 +010011649
Johannes Bergae917c92013-10-25 11:05:22 +020011650 if (wakeup->tcp_nomoretokens &&
11651 nla_put_flag(msg,
11652 NL80211_WOWLAN_TRIG_WAKEUP_TCP_NOMORETOKENS))
11653 goto free_msg;
Johannes Berg2a0e0472013-01-23 22:57:40 +010011654
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010011655 if (wakeup->packet) {
11656 u32 pkt_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211;
11657 u32 len_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211_LEN;
11658
11659 if (!wakeup->packet_80211) {
11660 pkt_attr =
11661 NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023;
11662 len_attr =
11663 NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023_LEN;
11664 }
11665
11666 if (wakeup->packet_len &&
11667 nla_put_u32(msg, len_attr, wakeup->packet_len))
11668 goto free_msg;
11669
11670 if (nla_put(msg, pkt_attr, wakeup->packet_present_len,
11671 wakeup->packet))
11672 goto free_msg;
11673 }
11674
11675 nla_nest_end(msg, reasons);
11676 }
11677
Johannes Berg9c90a9f2013-06-04 12:46:03 +020011678 genlmsg_end(msg, hdr);
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010011679
Johannes Berg68eb5502013-11-19 15:19:38 +010011680 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011681 NL80211_MCGRP_MLME, gfp);
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010011682 return;
11683
11684 free_msg:
11685 nlmsg_free(msg);
11686}
11687EXPORT_SYMBOL(cfg80211_report_wowlan_wakeup);
11688#endif
11689
Jouni Malinen3475b092012-11-16 22:49:57 +020011690void cfg80211_tdls_oper_request(struct net_device *dev, const u8 *peer,
11691 enum nl80211_tdls_operation oper,
11692 u16 reason_code, gfp_t gfp)
11693{
11694 struct wireless_dev *wdev = dev->ieee80211_ptr;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080011695 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Jouni Malinen3475b092012-11-16 22:49:57 +020011696 struct sk_buff *msg;
11697 void *hdr;
Jouni Malinen3475b092012-11-16 22:49:57 +020011698
11699 trace_cfg80211_tdls_oper_request(wdev->wiphy, dev, peer, oper,
11700 reason_code);
11701
11702 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
11703 if (!msg)
11704 return;
11705
11706 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_TDLS_OPER);
11707 if (!hdr) {
11708 nlmsg_free(msg);
11709 return;
11710 }
11711
11712 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
11713 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
11714 nla_put_u8(msg, NL80211_ATTR_TDLS_OPERATION, oper) ||
11715 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer) ||
11716 (reason_code > 0 &&
11717 nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason_code)))
11718 goto nla_put_failure;
11719
Johannes Berg9c90a9f2013-06-04 12:46:03 +020011720 genlmsg_end(msg, hdr);
Jouni Malinen3475b092012-11-16 22:49:57 +020011721
Johannes Berg68eb5502013-11-19 15:19:38 +010011722 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011723 NL80211_MCGRP_MLME, gfp);
Jouni Malinen3475b092012-11-16 22:49:57 +020011724 return;
11725
11726 nla_put_failure:
11727 genlmsg_cancel(msg, hdr);
11728 nlmsg_free(msg);
11729}
11730EXPORT_SYMBOL(cfg80211_tdls_oper_request);
11731
Jouni Malinen026331c2010-02-15 12:53:10 +020011732static int nl80211_netlink_notify(struct notifier_block * nb,
11733 unsigned long state,
11734 void *_notify)
11735{
11736 struct netlink_notify *notify = _notify;
11737 struct cfg80211_registered_device *rdev;
11738 struct wireless_dev *wdev;
Ben Greear37c73b52012-10-26 14:49:25 -070011739 struct cfg80211_beacon_registration *reg, *tmp;
Jouni Malinen026331c2010-02-15 12:53:10 +020011740
11741 if (state != NETLINK_URELEASE)
11742 return NOTIFY_DONE;
11743
11744 rcu_read_lock();
11745
Johannes Berg5e7602302011-11-04 11:18:17 +010011746 list_for_each_entry_rcu(rdev, &cfg80211_rdev_list, list) {
Johannes Berg78f22b62014-03-24 17:57:27 +010011747 bool schedule_destroy_work = false;
11748
11749 list_for_each_entry_rcu(wdev, &rdev->wdev_list, list) {
Eric W. Biederman15e47302012-09-07 20:12:54 +000011750 cfg80211_mlme_unregister_socket(wdev, notify->portid);
Ben Greear37c73b52012-10-26 14:49:25 -070011751
Johannes Berg78f22b62014-03-24 17:57:27 +010011752 if (wdev->owner_nlportid == notify->portid)
11753 schedule_destroy_work = true;
11754 }
11755
Ben Greear37c73b52012-10-26 14:49:25 -070011756 spin_lock_bh(&rdev->beacon_registrations_lock);
11757 list_for_each_entry_safe(reg, tmp, &rdev->beacon_registrations,
11758 list) {
11759 if (reg->nlportid == notify->portid) {
11760 list_del(&reg->list);
11761 kfree(reg);
11762 break;
11763 }
11764 }
11765 spin_unlock_bh(&rdev->beacon_registrations_lock);
Johannes Berg78f22b62014-03-24 17:57:27 +010011766
11767 if (schedule_destroy_work) {
11768 struct cfg80211_iface_destroy *destroy;
11769
11770 destroy = kzalloc(sizeof(*destroy), GFP_ATOMIC);
11771 if (destroy) {
11772 destroy->nlportid = notify->portid;
11773 spin_lock(&rdev->destroy_list_lock);
11774 list_add(&destroy->list, &rdev->destroy_list);
11775 spin_unlock(&rdev->destroy_list_lock);
11776 schedule_work(&rdev->destroy_work);
11777 }
11778 }
Johannes Berg5e7602302011-11-04 11:18:17 +010011779 }
Jouni Malinen026331c2010-02-15 12:53:10 +020011780
11781 rcu_read_unlock();
11782
Zhao, Gang6784c7d2014-04-21 12:53:04 +080011783 return NOTIFY_OK;
Jouni Malinen026331c2010-02-15 12:53:10 +020011784}
11785
11786static struct notifier_block nl80211_netlink_notifier = {
11787 .notifier_call = nl80211_netlink_notify,
11788};
11789
Jouni Malinen355199e2013-02-27 17:14:27 +020011790void cfg80211_ft_event(struct net_device *netdev,
11791 struct cfg80211_ft_event_params *ft_event)
11792{
11793 struct wiphy *wiphy = netdev->ieee80211_ptr->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080011794 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Jouni Malinen355199e2013-02-27 17:14:27 +020011795 struct sk_buff *msg;
11796 void *hdr;
Jouni Malinen355199e2013-02-27 17:14:27 +020011797
11798 trace_cfg80211_ft_event(wiphy, netdev, ft_event);
11799
11800 if (!ft_event->target_ap)
11801 return;
11802
11803 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
11804 if (!msg)
11805 return;
11806
11807 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FT_EVENT);
Johannes Bergae917c92013-10-25 11:05:22 +020011808 if (!hdr)
11809 goto out;
Jouni Malinen355199e2013-02-27 17:14:27 +020011810
Johannes Bergae917c92013-10-25 11:05:22 +020011811 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
11812 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
11813 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, ft_event->target_ap))
11814 goto out;
11815
11816 if (ft_event->ies &&
11817 nla_put(msg, NL80211_ATTR_IE, ft_event->ies_len, ft_event->ies))
11818 goto out;
11819 if (ft_event->ric_ies &&
11820 nla_put(msg, NL80211_ATTR_IE_RIC, ft_event->ric_ies_len,
11821 ft_event->ric_ies))
11822 goto out;
Jouni Malinen355199e2013-02-27 17:14:27 +020011823
Johannes Berg9c90a9f2013-06-04 12:46:03 +020011824 genlmsg_end(msg, hdr);
Jouni Malinen355199e2013-02-27 17:14:27 +020011825
Johannes Berg68eb5502013-11-19 15:19:38 +010011826 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011827 NL80211_MCGRP_MLME, GFP_KERNEL);
Johannes Bergae917c92013-10-25 11:05:22 +020011828 return;
11829 out:
11830 nlmsg_free(msg);
Jouni Malinen355199e2013-02-27 17:14:27 +020011831}
11832EXPORT_SYMBOL(cfg80211_ft_event);
11833
Arend van Spriel5de17982013-04-18 15:49:00 +020011834void cfg80211_crit_proto_stopped(struct wireless_dev *wdev, gfp_t gfp)
11835{
11836 struct cfg80211_registered_device *rdev;
11837 struct sk_buff *msg;
11838 void *hdr;
11839 u32 nlportid;
11840
Zhao, Gangf26cbf42014-04-21 12:53:03 +080011841 rdev = wiphy_to_rdev(wdev->wiphy);
Arend van Spriel5de17982013-04-18 15:49:00 +020011842 if (!rdev->crit_proto_nlportid)
11843 return;
11844
11845 nlportid = rdev->crit_proto_nlportid;
11846 rdev->crit_proto_nlportid = 0;
11847
11848 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
11849 if (!msg)
11850 return;
11851
11852 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CRIT_PROTOCOL_STOP);
11853 if (!hdr)
11854 goto nla_put_failure;
11855
11856 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
11857 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)))
11858 goto nla_put_failure;
11859
11860 genlmsg_end(msg, hdr);
11861
11862 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid);
11863 return;
11864
11865 nla_put_failure:
11866 if (hdr)
11867 genlmsg_cancel(msg, hdr);
11868 nlmsg_free(msg);
11869
11870}
11871EXPORT_SYMBOL(cfg80211_crit_proto_stopped);
11872
Johannes Berg348baf02014-01-24 14:06:29 +010011873void nl80211_send_ap_stopped(struct wireless_dev *wdev)
11874{
11875 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080011876 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg348baf02014-01-24 14:06:29 +010011877 struct sk_buff *msg;
11878 void *hdr;
11879
11880 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
11881 if (!msg)
11882 return;
11883
11884 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_STOP_AP);
11885 if (!hdr)
11886 goto out;
11887
11888 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
11889 nla_put_u32(msg, NL80211_ATTR_IFINDEX, wdev->netdev->ifindex) ||
11890 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)))
11891 goto out;
11892
11893 genlmsg_end(msg, hdr);
11894
11895 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(wiphy), msg, 0,
11896 NL80211_MCGRP_MLME, GFP_KERNEL);
11897 return;
11898 out:
11899 nlmsg_free(msg);
11900}
11901
Johannes Berg55682962007-09-20 13:09:35 -040011902/* initialisation/exit functions */
11903
11904int nl80211_init(void)
11905{
Michał Mirosław0d63cbb2009-05-21 10:34:06 +000011906 int err;
Johannes Berg55682962007-09-20 13:09:35 -040011907
Johannes Berg2a94fe42013-11-19 15:19:39 +010011908 err = genl_register_family_with_ops_groups(&nl80211_fam, nl80211_ops,
11909 nl80211_mcgrps);
Johannes Berg55682962007-09-20 13:09:35 -040011910 if (err)
11911 return err;
11912
Jouni Malinen026331c2010-02-15 12:53:10 +020011913 err = netlink_register_notifier(&nl80211_netlink_notifier);
11914 if (err)
11915 goto err_out;
11916
Johannes Berg55682962007-09-20 13:09:35 -040011917 return 0;
11918 err_out:
11919 genl_unregister_family(&nl80211_fam);
11920 return err;
11921}
11922
11923void nl80211_exit(void)
11924{
Jouni Malinen026331c2010-02-15 12:53:10 +020011925 netlink_unregister_notifier(&nl80211_netlink_notifier);
Johannes Berg55682962007-09-20 13:09:35 -040011926 genl_unregister_family(&nl80211_fam);
11927}