blob: 0f1b18f209d6254800ac50f28b4d454017fe7e62 [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 Berg7fee47782012-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 Berg7fee47782012-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 Berg7fee47782012-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 Berg7fee47782012-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 Berg7fee47782012-06-15 14:09:58 +0200173 else
174 tmp = NULL;
175
Johannes Berg7fee47782012-06-15 14:09:58 +0200176 /* not wireless device -- return error */
177 if (!tmp)
178 return ERR_PTR(-EINVAL);
179
180 /* mismatch -- return error */
181 if (rdev && tmp != rdev)
182 return ERR_PTR(-EINVAL);
183
184 rdev = tmp;
Johannes Berga9455402012-06-15 13:32:49 +0200185 }
Johannes Berga9455402012-06-15 13:32:49 +0200186 }
187
Johannes Berg4f7eff12012-06-15 14:14:22 +0200188 if (!rdev)
189 return ERR_PTR(-ENODEV);
Johannes Berga9455402012-06-15 13:32:49 +0200190
Johannes Berg4f7eff12012-06-15 14:14:22 +0200191 if (netns != wiphy_net(&rdev->wiphy))
192 return ERR_PTR(-ENODEV);
193
194 return rdev;
Johannes Berga9455402012-06-15 13:32:49 +0200195}
196
197/*
198 * This function returns a pointer to the driver
199 * that the genl_info item that is passed refers to.
Johannes Berga9455402012-06-15 13:32:49 +0200200 *
201 * The result of this can be a PTR_ERR and hence must
202 * be checked with IS_ERR() for errors.
203 */
204static struct cfg80211_registered_device *
Johannes Berg4f7eff12012-06-15 14:14:22 +0200205cfg80211_get_dev_from_info(struct net *netns, struct genl_info *info)
Johannes Berga9455402012-06-15 13:32:49 +0200206{
Johannes Berg5fe231e2013-05-08 21:45:15 +0200207 return __cfg80211_rdev_from_attrs(netns, info->attrs);
Johannes Berga9455402012-06-15 13:32:49 +0200208}
209
Johannes Berg55682962007-09-20 13:09:35 -0400210/* policy for the attributes */
Alexey Dobriyanb54452b2010-02-18 08:14:31 +0000211static const struct nla_policy nl80211_policy[NL80211_ATTR_MAX+1] = {
Johannes Berg55682962007-09-20 13:09:35 -0400212 [NL80211_ATTR_WIPHY] = { .type = NLA_U32 },
213 [NL80211_ATTR_WIPHY_NAME] = { .type = NLA_NUL_STRING,
David S. Miller079e24e2009-05-26 21:15:00 -0700214 .len = 20-1 },
Jouni Malinen31888482008-10-30 16:59:24 +0200215 [NL80211_ATTR_WIPHY_TXQ_PARAMS] = { .type = NLA_NESTED },
Johannes Berg3d9d1d62012-11-08 23:14:50 +0100216
Jouni Malinen72bdcf32008-11-26 16:15:24 +0200217 [NL80211_ATTR_WIPHY_FREQ] = { .type = NLA_U32 },
Sujith094d05d2008-12-12 11:57:43 +0530218 [NL80211_ATTR_WIPHY_CHANNEL_TYPE] = { .type = NLA_U32 },
Johannes Berg3d9d1d62012-11-08 23:14:50 +0100219 [NL80211_ATTR_CHANNEL_WIDTH] = { .type = NLA_U32 },
220 [NL80211_ATTR_CENTER_FREQ1] = { .type = NLA_U32 },
221 [NL80211_ATTR_CENTER_FREQ2] = { .type = NLA_U32 },
222
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +0200223 [NL80211_ATTR_WIPHY_RETRY_SHORT] = { .type = NLA_U8 },
224 [NL80211_ATTR_WIPHY_RETRY_LONG] = { .type = NLA_U8 },
225 [NL80211_ATTR_WIPHY_FRAG_THRESHOLD] = { .type = NLA_U32 },
226 [NL80211_ATTR_WIPHY_RTS_THRESHOLD] = { .type = NLA_U32 },
Lukáš Turek81077e82009-12-21 22:50:47 +0100227 [NL80211_ATTR_WIPHY_COVERAGE_CLASS] = { .type = NLA_U8 },
Johannes Berg55682962007-09-20 13:09:35 -0400228
229 [NL80211_ATTR_IFTYPE] = { .type = NLA_U32 },
230 [NL80211_ATTR_IFINDEX] = { .type = NLA_U32 },
231 [NL80211_ATTR_IFNAME] = { .type = NLA_NUL_STRING, .len = IFNAMSIZ-1 },
Johannes Berg41ade002007-12-19 02:03:29 +0100232
Eliad Pellere007b852011-11-24 18:13:56 +0200233 [NL80211_ATTR_MAC] = { .len = ETH_ALEN },
234 [NL80211_ATTR_PREV_BSSID] = { .len = ETH_ALEN },
Johannes Berg41ade002007-12-19 02:03:29 +0100235
Johannes Bergb9454e82009-07-08 13:29:08 +0200236 [NL80211_ATTR_KEY] = { .type = NLA_NESTED, },
Johannes Berg41ade002007-12-19 02:03:29 +0100237 [NL80211_ATTR_KEY_DATA] = { .type = NLA_BINARY,
238 .len = WLAN_MAX_KEY_LEN },
239 [NL80211_ATTR_KEY_IDX] = { .type = NLA_U8 },
240 [NL80211_ATTR_KEY_CIPHER] = { .type = NLA_U32 },
241 [NL80211_ATTR_KEY_DEFAULT] = { .type = NLA_FLAG },
Jouni Malinen81962262011-11-02 23:36:31 +0200242 [NL80211_ATTR_KEY_SEQ] = { .type = NLA_BINARY, .len = 16 },
Johannes Berge31b8212010-10-05 19:39:30 +0200243 [NL80211_ATTR_KEY_TYPE] = { .type = NLA_U32 },
Johannes Berged1b6cc2007-12-19 02:03:32 +0100244
245 [NL80211_ATTR_BEACON_INTERVAL] = { .type = NLA_U32 },
246 [NL80211_ATTR_DTIM_PERIOD] = { .type = NLA_U32 },
247 [NL80211_ATTR_BEACON_HEAD] = { .type = NLA_BINARY,
248 .len = IEEE80211_MAX_DATA_LEN },
249 [NL80211_ATTR_BEACON_TAIL] = { .type = NLA_BINARY,
250 .len = IEEE80211_MAX_DATA_LEN },
Johannes Berg5727ef12007-12-19 02:03:34 +0100251 [NL80211_ATTR_STA_AID] = { .type = NLA_U16 },
252 [NL80211_ATTR_STA_FLAGS] = { .type = NLA_NESTED },
253 [NL80211_ATTR_STA_LISTEN_INTERVAL] = { .type = NLA_U16 },
254 [NL80211_ATTR_STA_SUPPORTED_RATES] = { .type = NLA_BINARY,
255 .len = NL80211_MAX_SUPP_RATES },
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +0100256 [NL80211_ATTR_STA_PLINK_ACTION] = { .type = NLA_U8 },
Johannes Berg5727ef12007-12-19 02:03:34 +0100257 [NL80211_ATTR_STA_VLAN] = { .type = NLA_U32 },
Johannes Berg0a9542e2008-10-15 11:54:04 +0200258 [NL80211_ATTR_MNTR_FLAGS] = { /* NLA_NESTED can't be empty */ },
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +0100259 [NL80211_ATTR_MESH_ID] = { .type = NLA_BINARY,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +0800260 .len = IEEE80211_MAX_MESH_ID_LEN },
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +0100261 [NL80211_ATTR_MPATH_NEXT_HOP] = { .type = NLA_U32 },
Jouni Malinen9f1ba902008-08-07 20:07:01 +0300262
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -0700263 [NL80211_ATTR_REG_ALPHA2] = { .type = NLA_STRING, .len = 2 },
264 [NL80211_ATTR_REG_RULES] = { .type = NLA_NESTED },
265
Jouni Malinen9f1ba902008-08-07 20:07:01 +0300266 [NL80211_ATTR_BSS_CTS_PROT] = { .type = NLA_U8 },
267 [NL80211_ATTR_BSS_SHORT_PREAMBLE] = { .type = NLA_U8 },
268 [NL80211_ATTR_BSS_SHORT_SLOT_TIME] = { .type = NLA_U8 },
Jouni Malinen90c97a02008-10-30 16:59:22 +0200269 [NL80211_ATTR_BSS_BASIC_RATES] = { .type = NLA_BINARY,
270 .len = NL80211_MAX_SUPP_RATES },
Helmut Schaa50b12f52010-11-19 12:40:25 +0100271 [NL80211_ATTR_BSS_HT_OPMODE] = { .type = NLA_U16 },
Jouni Malinen36aedc92008-08-25 11:58:58 +0300272
Javier Cardona24bdd9f2010-12-16 17:37:48 -0800273 [NL80211_ATTR_MESH_CONFIG] = { .type = NLA_NESTED },
Javier Cardona15d5dda2011-04-07 15:08:28 -0700274 [NL80211_ATTR_SUPPORT_MESH_AUTH] = { .type = NLA_FLAG },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -0700275
Johannes Berg6c739412011-11-03 09:27:01 +0100276 [NL80211_ATTR_HT_CAPABILITY] = { .len = NL80211_HT_CAPABILITY_LEN },
Jouni Malinen9aed3cc2009-01-13 16:03:29 +0200277
278 [NL80211_ATTR_MGMT_SUBTYPE] = { .type = NLA_U8 },
279 [NL80211_ATTR_IE] = { .type = NLA_BINARY,
280 .len = IEEE80211_MAX_DATA_LEN },
Johannes Berg2a519312009-02-10 21:25:55 +0100281 [NL80211_ATTR_SCAN_FREQUENCIES] = { .type = NLA_NESTED },
282 [NL80211_ATTR_SCAN_SSIDS] = { .type = NLA_NESTED },
Jouni Malinen636a5d32009-03-19 13:39:22 +0200283
284 [NL80211_ATTR_SSID] = { .type = NLA_BINARY,
285 .len = IEEE80211_MAX_SSID_LEN },
286 [NL80211_ATTR_AUTH_TYPE] = { .type = NLA_U32 },
287 [NL80211_ATTR_REASON_CODE] = { .type = NLA_U16 },
Johannes Berg04a773a2009-04-19 21:24:32 +0200288 [NL80211_ATTR_FREQ_FIXED] = { .type = NLA_FLAG },
Jouni Malinen1965c852009-04-22 21:38:25 +0300289 [NL80211_ATTR_TIMED_OUT] = { .type = NLA_FLAG },
Jouni Malinendc6382ce2009-05-06 22:09:37 +0300290 [NL80211_ATTR_USE_MFP] = { .type = NLA_U32 },
Johannes Bergeccb8e82009-05-11 21:57:56 +0300291 [NL80211_ATTR_STA_FLAGS2] = {
292 .len = sizeof(struct nl80211_sta_flag_update),
293 },
Jouni Malinen3f77316c2009-05-11 21:57:57 +0300294 [NL80211_ATTR_CONTROL_PORT] = { .type = NLA_FLAG },
Johannes Bergc0692b82010-08-27 14:26:53 +0300295 [NL80211_ATTR_CONTROL_PORT_ETHERTYPE] = { .type = NLA_U16 },
296 [NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT] = { .type = NLA_FLAG },
Samuel Ortizb23aa672009-07-01 21:26:54 +0200297 [NL80211_ATTR_PRIVACY] = { .type = NLA_FLAG },
298 [NL80211_ATTR_CIPHER_SUITE_GROUP] = { .type = NLA_U32 },
299 [NL80211_ATTR_WPA_VERSIONS] = { .type = NLA_U32 },
Johannes Berg463d0182009-07-14 00:33:35 +0200300 [NL80211_ATTR_PID] = { .type = NLA_U32 },
Felix Fietkau8b787642009-11-10 18:53:10 +0100301 [NL80211_ATTR_4ADDR] = { .type = NLA_U8 },
Samuel Ortiz67fbb162009-11-24 23:59:15 +0100302 [NL80211_ATTR_PMKID] = { .type = NLA_BINARY,
303 .len = WLAN_PMKID_LEN },
Jouni Malinen9588bbd2009-12-23 13:15:41 +0100304 [NL80211_ATTR_DURATION] = { .type = NLA_U32 },
305 [NL80211_ATTR_COOKIE] = { .type = NLA_U64 },
Jouni Malinen13ae75b2009-12-29 12:59:45 +0200306 [NL80211_ATTR_TX_RATES] = { .type = NLA_NESTED },
Jouni Malinen026331c2010-02-15 12:53:10 +0200307 [NL80211_ATTR_FRAME] = { .type = NLA_BINARY,
308 .len = IEEE80211_MAX_DATA_LEN },
309 [NL80211_ATTR_FRAME_MATCH] = { .type = NLA_BINARY, },
Kalle Valoffb9eb32010-02-17 17:58:10 +0200310 [NL80211_ATTR_PS_STATE] = { .type = NLA_U32 },
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +0200311 [NL80211_ATTR_CQM] = { .type = NLA_NESTED, },
Jouni Malinend5cdfac2010-04-04 09:37:19 +0300312 [NL80211_ATTR_LOCAL_STATE_CHANGE] = { .type = NLA_FLAG },
Felix Fietkaufd8aaaf2010-04-27 01:23:35 +0200313 [NL80211_ATTR_AP_ISOLATE] = { .type = NLA_U8 },
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +0300314 [NL80211_ATTR_WIPHY_TX_POWER_SETTING] = { .type = NLA_U32 },
315 [NL80211_ATTR_WIPHY_TX_POWER_LEVEL] = { .type = NLA_U32 },
Johannes Berg2e161f782010-08-12 15:38:38 +0200316 [NL80211_ATTR_FRAME_TYPE] = { .type = NLA_U16 },
Bruno Randolfafe0cbf2010-11-10 12:50:50 +0900317 [NL80211_ATTR_WIPHY_ANTENNA_TX] = { .type = NLA_U32 },
318 [NL80211_ATTR_WIPHY_ANTENNA_RX] = { .type = NLA_U32 },
Felix Fietkau885a46d2010-11-11 15:07:22 +0100319 [NL80211_ATTR_MCAST_RATE] = { .type = NLA_U32 },
Johannes Bergf7ca38d2010-11-25 10:02:29 +0100320 [NL80211_ATTR_OFFCHANNEL_TX_OK] = { .type = NLA_FLAG },
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100321 [NL80211_ATTR_KEY_DEFAULT_TYPES] = { .type = NLA_NESTED },
Johannes Bergff1b6e62011-05-04 15:37:28 +0200322 [NL80211_ATTR_WOWLAN_TRIGGERS] = { .type = NLA_NESTED },
Javier Cardona9c3990a2011-05-03 16:57:11 -0700323 [NL80211_ATTR_STA_PLINK_STATE] = { .type = NLA_U8 },
Luciano Coelhobbe6ad62011-05-11 17:09:37 +0300324 [NL80211_ATTR_SCHED_SCAN_INTERVAL] = { .type = NLA_U32 },
Johannes Berge5497d72011-07-05 16:35:40 +0200325 [NL80211_ATTR_REKEY_DATA] = { .type = NLA_NESTED },
Johannes Berg34850ab2011-07-18 18:08:35 +0200326 [NL80211_ATTR_SCAN_SUPP_RATES] = { .type = NLA_NESTED },
Jouni Malinen32e9de82011-08-10 23:53:31 +0300327 [NL80211_ATTR_HIDDEN_SSID] = { .type = NLA_U32 },
Jouni Malinen9946ecf2011-08-10 23:55:56 +0300328 [NL80211_ATTR_IE_PROBE_RESP] = { .type = NLA_BINARY,
329 .len = IEEE80211_MAX_DATA_LEN },
330 [NL80211_ATTR_IE_ASSOC_RESP] = { .type = NLA_BINARY,
331 .len = IEEE80211_MAX_DATA_LEN },
Vivek Natarajanf4b34b52011-08-29 14:23:03 +0530332 [NL80211_ATTR_ROAM_SUPPORT] = { .type = NLA_FLAG },
Luciano Coelhoa1f1c212011-08-31 16:01:48 +0300333 [NL80211_ATTR_SCHED_SCAN_MATCH] = { .type = NLA_NESTED },
Rajkumar Manoharane9f935e2011-09-25 14:53:30 +0530334 [NL80211_ATTR_TX_NO_CCK_RATE] = { .type = NLA_FLAG },
Arik Nemtsov109086c2011-09-28 14:12:50 +0300335 [NL80211_ATTR_TDLS_ACTION] = { .type = NLA_U8 },
336 [NL80211_ATTR_TDLS_DIALOG_TOKEN] = { .type = NLA_U8 },
337 [NL80211_ATTR_TDLS_OPERATION] = { .type = NLA_U8 },
338 [NL80211_ATTR_TDLS_SUPPORT] = { .type = NLA_FLAG },
339 [NL80211_ATTR_TDLS_EXTERNAL_SETUP] = { .type = NLA_FLAG },
Johannes Berge247bd902011-11-04 11:18:21 +0100340 [NL80211_ATTR_DONT_WAIT_FOR_ACK] = { .type = NLA_FLAG },
Arik Nemtsov00f740e2011-11-10 11:28:56 +0200341 [NL80211_ATTR_PROBE_RESP] = { .type = NLA_BINARY,
342 .len = IEEE80211_MAX_DATA_LEN },
Luis R. Rodriguez8b60b072011-10-11 10:59:02 -0700343 [NL80211_ATTR_DFS_REGION] = { .type = NLA_U8 },
Ben Greear7e7c8922011-11-18 11:31:59 -0800344 [NL80211_ATTR_DISABLE_HT] = { .type = NLA_FLAG },
345 [NL80211_ATTR_HT_CAPABILITY_MASK] = {
346 .len = NL80211_HT_CAPABILITY_LEN
347 },
Simon Wunderlich1d9d9212011-11-18 14:20:43 +0100348 [NL80211_ATTR_NOACK_MAP] = { .type = NLA_U16 },
Vasanthakumar Thiagarajan1b658f12012-03-02 15:50:02 +0530349 [NL80211_ATTR_INACTIVITY_TIMEOUT] = { .type = NLA_U16 },
Bala Shanmugam4486ea92012-03-07 17:27:12 +0530350 [NL80211_ATTR_BG_SCAN_PERIOD] = { .type = NLA_U16 },
Johannes Berg89a54e42012-06-15 14:33:17 +0200351 [NL80211_ATTR_WDEV] = { .type = NLA_U64 },
Luis R. Rodriguez57b5ce02012-07-12 11:49:18 -0700352 [NL80211_ATTR_USER_REG_HINT_TYPE] = { .type = NLA_U32 },
Jouni Malinene39e5b52012-09-30 19:29:39 +0300353 [NL80211_ATTR_SAE_DATA] = { .type = NLA_BINARY, },
Mahesh Palivelaf461be3e2012-10-11 08:04:52 +0000354 [NL80211_ATTR_VHT_CAPABILITY] = { .len = NL80211_VHT_CAPABILITY_LEN },
Sam Lefflered4737712012-10-11 21:03:31 -0700355 [NL80211_ATTR_SCAN_FLAGS] = { .type = NLA_U32 },
Johannes Berg53cabad2012-11-14 15:17:28 +0100356 [NL80211_ATTR_P2P_CTWINDOW] = { .type = NLA_U8 },
357 [NL80211_ATTR_P2P_OPPPS] = { .type = NLA_U8 },
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +0530358 [NL80211_ATTR_ACL_POLICY] = {. type = NLA_U32 },
359 [NL80211_ATTR_MAC_ADDRS] = { .type = NLA_NESTED },
Jouni Malinen9d62a982013-02-14 21:10:13 +0200360 [NL80211_ATTR_STA_CAPABILITY] = { .type = NLA_U16 },
361 [NL80211_ATTR_STA_EXT_CAPABILITY] = { .type = NLA_BINARY, },
Johannes Berg3713b4e2013-02-14 16:19:38 +0100362 [NL80211_ATTR_SPLIT_WIPHY_DUMP] = { .type = NLA_FLAG, },
Johannes Bergee2aca32013-02-21 17:36:01 +0100363 [NL80211_ATTR_DISABLE_VHT] = { .type = NLA_FLAG },
364 [NL80211_ATTR_VHT_CAPABILITY_MASK] = {
365 .len = NL80211_VHT_CAPABILITY_LEN,
366 },
Jouni Malinen355199e2013-02-27 17:14:27 +0200367 [NL80211_ATTR_MDID] = { .type = NLA_U16 },
368 [NL80211_ATTR_IE_RIC] = { .type = NLA_BINARY,
369 .len = IEEE80211_MAX_DATA_LEN },
Jouni Malinen5e4b6f52013-05-16 20:11:08 +0300370 [NL80211_ATTR_PEER_AID] = { .type = NLA_U16 },
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +0200371 [NL80211_ATTR_CH_SWITCH_COUNT] = { .type = NLA_U32 },
372 [NL80211_ATTR_CH_SWITCH_BLOCK_TX] = { .type = NLA_FLAG },
373 [NL80211_ATTR_CSA_IES] = { .type = NLA_NESTED },
374 [NL80211_ATTR_CSA_C_OFF_BEACON] = { .type = NLA_U16 },
375 [NL80211_ATTR_CSA_C_OFF_PRESP] = { .type = NLA_U16 },
Sunil Duttc01fc9a2013-10-09 20:45:21 +0530376 [NL80211_ATTR_STA_SUPPORTED_CHANNELS] = { .type = NLA_BINARY },
377 [NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES] = { .type = NLA_BINARY },
Simon Wunderlich5336fa82013-10-07 18:41:05 +0200378 [NL80211_ATTR_HANDLE_DFS] = { .type = NLA_FLAG },
Marek Kwaczynski60f4a7b2013-12-03 10:04:59 +0100379 [NL80211_ATTR_OPMODE_NOTIF] = { .type = NLA_U8 },
Johannes Bergad7e7182013-11-13 13:37:47 +0100380 [NL80211_ATTR_VENDOR_ID] = { .type = NLA_U32 },
381 [NL80211_ATTR_VENDOR_SUBCMD] = { .type = NLA_U32 },
382 [NL80211_ATTR_VENDOR_DATA] = { .type = NLA_BINARY },
Kyeyoon Parkfa9ffc72013-12-16 23:01:30 -0800383 [NL80211_ATTR_QOS_MAP] = { .type = NLA_BINARY,
384 .len = IEEE80211_QOS_MAP_LEN_MAX },
Jouni Malinen1df4a512014-01-15 00:00:47 +0200385 [NL80211_ATTR_MAC_HINT] = { .len = ETH_ALEN },
386 [NL80211_ATTR_WIPHY_FREQ_HINT] = { .type = NLA_U32 },
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 },
Johannes Berg55682962007-09-20 13:09:35 -0400389};
390
Johannes Berge31b8212010-10-05 19:39:30 +0200391/* policy for the key attributes */
Alexey Dobriyanb54452b2010-02-18 08:14:31 +0000392static const struct nla_policy nl80211_key_policy[NL80211_KEY_MAX + 1] = {
Johannes Bergfffd0932009-07-08 14:22:54 +0200393 [NL80211_KEY_DATA] = { .type = NLA_BINARY, .len = WLAN_MAX_KEY_LEN },
Johannes Bergb9454e82009-07-08 13:29:08 +0200394 [NL80211_KEY_IDX] = { .type = NLA_U8 },
395 [NL80211_KEY_CIPHER] = { .type = NLA_U32 },
Jouni Malinen81962262011-11-02 23:36:31 +0200396 [NL80211_KEY_SEQ] = { .type = NLA_BINARY, .len = 16 },
Johannes Bergb9454e82009-07-08 13:29:08 +0200397 [NL80211_KEY_DEFAULT] = { .type = NLA_FLAG },
398 [NL80211_KEY_DEFAULT_MGMT] = { .type = NLA_FLAG },
Johannes Berge31b8212010-10-05 19:39:30 +0200399 [NL80211_KEY_TYPE] = { .type = NLA_U32 },
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100400 [NL80211_KEY_DEFAULT_TYPES] = { .type = NLA_NESTED },
401};
402
403/* policy for the key default flags */
404static const struct nla_policy
405nl80211_key_default_policy[NUM_NL80211_KEY_DEFAULT_TYPES] = {
406 [NL80211_KEY_DEFAULT_TYPE_UNICAST] = { .type = NLA_FLAG },
407 [NL80211_KEY_DEFAULT_TYPE_MULTICAST] = { .type = NLA_FLAG },
Johannes Bergb9454e82009-07-08 13:29:08 +0200408};
409
Johannes Bergff1b6e62011-05-04 15:37:28 +0200410/* policy for WoWLAN attributes */
411static const struct nla_policy
412nl80211_wowlan_policy[NUM_NL80211_WOWLAN_TRIG] = {
413 [NL80211_WOWLAN_TRIG_ANY] = { .type = NLA_FLAG },
414 [NL80211_WOWLAN_TRIG_DISCONNECT] = { .type = NLA_FLAG },
415 [NL80211_WOWLAN_TRIG_MAGIC_PKT] = { .type = NLA_FLAG },
416 [NL80211_WOWLAN_TRIG_PKT_PATTERN] = { .type = NLA_NESTED },
Johannes Berg77dbbb12011-07-13 10:48:55 +0200417 [NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE] = { .type = NLA_FLAG },
418 [NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST] = { .type = NLA_FLAG },
419 [NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE] = { .type = NLA_FLAG },
420 [NL80211_WOWLAN_TRIG_RFKILL_RELEASE] = { .type = NLA_FLAG },
Johannes Berg2a0e0472013-01-23 22:57:40 +0100421 [NL80211_WOWLAN_TRIG_TCP_CONNECTION] = { .type = NLA_NESTED },
422};
423
424static const struct nla_policy
425nl80211_wowlan_tcp_policy[NUM_NL80211_WOWLAN_TCP] = {
426 [NL80211_WOWLAN_TCP_SRC_IPV4] = { .type = NLA_U32 },
427 [NL80211_WOWLAN_TCP_DST_IPV4] = { .type = NLA_U32 },
428 [NL80211_WOWLAN_TCP_DST_MAC] = { .len = ETH_ALEN },
429 [NL80211_WOWLAN_TCP_SRC_PORT] = { .type = NLA_U16 },
430 [NL80211_WOWLAN_TCP_DST_PORT] = { .type = NLA_U16 },
431 [NL80211_WOWLAN_TCP_DATA_PAYLOAD] = { .len = 1 },
432 [NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ] = {
433 .len = sizeof(struct nl80211_wowlan_tcp_data_seq)
434 },
435 [NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN] = {
436 .len = sizeof(struct nl80211_wowlan_tcp_data_token)
437 },
438 [NL80211_WOWLAN_TCP_DATA_INTERVAL] = { .type = NLA_U32 },
439 [NL80211_WOWLAN_TCP_WAKE_PAYLOAD] = { .len = 1 },
440 [NL80211_WOWLAN_TCP_WAKE_MASK] = { .len = 1 },
Johannes Bergff1b6e62011-05-04 15:37:28 +0200441};
442
Amitkumar Karwarbe29b99a2013-06-28 11:51:26 -0700443/* policy for coalesce rule attributes */
444static const struct nla_policy
445nl80211_coalesce_policy[NUM_NL80211_ATTR_COALESCE_RULE] = {
446 [NL80211_ATTR_COALESCE_RULE_DELAY] = { .type = NLA_U32 },
447 [NL80211_ATTR_COALESCE_RULE_CONDITION] = { .type = NLA_U32 },
448 [NL80211_ATTR_COALESCE_RULE_PKT_PATTERN] = { .type = NLA_NESTED },
449};
450
Johannes Berge5497d72011-07-05 16:35:40 +0200451/* policy for GTK rekey offload attributes */
452static const struct nla_policy
453nl80211_rekey_policy[NUM_NL80211_REKEY_DATA] = {
454 [NL80211_REKEY_DATA_KEK] = { .len = NL80211_KEK_LEN },
455 [NL80211_REKEY_DATA_KCK] = { .len = NL80211_KCK_LEN },
456 [NL80211_REKEY_DATA_REPLAY_CTR] = { .len = NL80211_REPLAY_CTR_LEN },
457};
458
Luciano Coelhoa1f1c212011-08-31 16:01:48 +0300459static const struct nla_policy
460nl80211_match_policy[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1] = {
Johannes Berg4a4ab0d2012-06-13 11:17:11 +0200461 [NL80211_SCHED_SCAN_MATCH_ATTR_SSID] = { .type = NLA_BINARY,
Luciano Coelhoa1f1c212011-08-31 16:01:48 +0300462 .len = IEEE80211_MAX_SSID_LEN },
Thomas Pedersen88e920b2012-06-21 11:09:54 -0700463 [NL80211_SCHED_SCAN_MATCH_ATTR_RSSI] = { .type = NLA_U32 },
Luciano Coelhoa1f1c212011-08-31 16:01:48 +0300464};
465
Johannes Berg97990a02013-04-19 01:02:55 +0200466static int nl80211_prepare_wdev_dump(struct sk_buff *skb,
467 struct netlink_callback *cb,
468 struct cfg80211_registered_device **rdev,
469 struct wireless_dev **wdev)
Holger Schuriga0438972009-11-11 11:30:02 +0100470{
Johannes Berg67748892010-10-04 21:14:06 +0200471 int err;
472
Johannes Berg67748892010-10-04 21:14:06 +0200473 rtnl_lock();
474
Johannes Berg97990a02013-04-19 01:02:55 +0200475 if (!cb->args[0]) {
476 err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize,
477 nl80211_fam.attrbuf, nl80211_fam.maxattr,
478 nl80211_policy);
479 if (err)
480 goto out_unlock;
481
482 *wdev = __cfg80211_wdev_from_attrs(sock_net(skb->sk),
483 nl80211_fam.attrbuf);
484 if (IS_ERR(*wdev)) {
485 err = PTR_ERR(*wdev);
486 goto out_unlock;
487 }
Zhao, Gangf26cbf42014-04-21 12:53:03 +0800488 *rdev = wiphy_to_rdev((*wdev)->wiphy);
Johannes Bergc319d502013-07-30 22:34:28 +0200489 /* 0 is the first index - add 1 to parse only once */
490 cb->args[0] = (*rdev)->wiphy_idx + 1;
Johannes Berg97990a02013-04-19 01:02:55 +0200491 cb->args[1] = (*wdev)->identifier;
492 } else {
Johannes Bergc319d502013-07-30 22:34:28 +0200493 /* subtract the 1 again here */
494 struct wiphy *wiphy = wiphy_idx_to_wiphy(cb->args[0] - 1);
Johannes Berg97990a02013-04-19 01:02:55 +0200495 struct wireless_dev *tmp;
496
497 if (!wiphy) {
498 err = -ENODEV;
499 goto out_unlock;
500 }
Zhao, Gangf26cbf42014-04-21 12:53:03 +0800501 *rdev = wiphy_to_rdev(wiphy);
Johannes Berg97990a02013-04-19 01:02:55 +0200502 *wdev = NULL;
503
Johannes Berg97990a02013-04-19 01:02:55 +0200504 list_for_each_entry(tmp, &(*rdev)->wdev_list, list) {
505 if (tmp->identifier == cb->args[1]) {
506 *wdev = tmp;
507 break;
508 }
509 }
Johannes Berg97990a02013-04-19 01:02:55 +0200510
511 if (!*wdev) {
512 err = -ENODEV;
513 goto out_unlock;
514 }
Johannes Berg67748892010-10-04 21:14:06 +0200515 }
516
Johannes Berg67748892010-10-04 21:14:06 +0200517 return 0;
Johannes Berg97990a02013-04-19 01:02:55 +0200518 out_unlock:
Johannes Berg67748892010-10-04 21:14:06 +0200519 rtnl_unlock();
520 return err;
521}
522
Johannes Berg97990a02013-04-19 01:02:55 +0200523static void nl80211_finish_wdev_dump(struct cfg80211_registered_device *rdev)
Johannes Berg67748892010-10-04 21:14:06 +0200524{
Johannes Berg67748892010-10-04 21:14:06 +0200525 rtnl_unlock();
526}
527
Johannes Bergf4a11bb2009-03-27 12:40:28 +0100528/* IE validation */
529static bool is_valid_ie_attr(const struct nlattr *attr)
530{
531 const u8 *pos;
532 int len;
533
534 if (!attr)
535 return true;
536
537 pos = nla_data(attr);
538 len = nla_len(attr);
539
540 while (len) {
541 u8 elemlen;
542
543 if (len < 2)
544 return false;
545 len -= 2;
546
547 elemlen = pos[1];
548 if (elemlen > len)
549 return false;
550
551 len -= elemlen;
552 pos += 2 + elemlen;
553 }
554
555 return true;
556}
557
Johannes Berg55682962007-09-20 13:09:35 -0400558/* message building helper */
Eric W. Biederman15e47302012-09-07 20:12:54 +0000559static inline void *nl80211hdr_put(struct sk_buff *skb, u32 portid, u32 seq,
Johannes Berg55682962007-09-20 13:09:35 -0400560 int flags, u8 cmd)
561{
562 /* since there is no private header just add the generic one */
Eric W. Biederman15e47302012-09-07 20:12:54 +0000563 return genlmsg_put(skb, portid, seq, &nl80211_fam, flags, cmd);
Johannes Berg55682962007-09-20 13:09:35 -0400564}
565
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400566static int nl80211_msg_put_channel(struct sk_buff *msg,
Johannes Bergcdc89b92013-02-18 23:54:36 +0100567 struct ieee80211_channel *chan,
568 bool large)
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400569{
Rostislav Lisovyea077c12014-04-15 14:37:55 +0200570 /* Some channels must be completely excluded from the
571 * list to protect old user-space tools from breaking
572 */
573 if (!large && chan->flags &
574 (IEEE80211_CHAN_NO_10MHZ | IEEE80211_CHAN_NO_20MHZ))
575 return 0;
576
David S. Miller9360ffd2012-03-29 04:41:26 -0400577 if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_FREQ,
578 chan->center_freq))
579 goto nla_put_failure;
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400580
David S. Miller9360ffd2012-03-29 04:41:26 -0400581 if ((chan->flags & IEEE80211_CHAN_DISABLED) &&
582 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_DISABLED))
583 goto nla_put_failure;
Luis R. Rodriguez8fe02e12013-10-21 19:22:25 +0200584 if (chan->flags & IEEE80211_CHAN_NO_IR) {
585 if (nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_IR))
586 goto nla_put_failure;
587 if (nla_put_flag(msg, __NL80211_FREQUENCY_ATTR_NO_IBSS))
588 goto nla_put_failure;
589 }
Johannes Bergcdc89b92013-02-18 23:54:36 +0100590 if (chan->flags & IEEE80211_CHAN_RADAR) {
591 if (nla_put_flag(msg, NL80211_FREQUENCY_ATTR_RADAR))
592 goto nla_put_failure;
593 if (large) {
594 u32 time;
595
596 time = elapsed_jiffies_msecs(chan->dfs_state_entered);
597
598 if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_DFS_STATE,
599 chan->dfs_state))
600 goto nla_put_failure;
601 if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_DFS_TIME,
602 time))
603 goto nla_put_failure;
Janusz Dziedzic089027e2014-02-21 19:46:12 +0100604 if (nla_put_u32(msg,
605 NL80211_FREQUENCY_ATTR_DFS_CAC_TIME,
606 chan->dfs_cac_ms))
607 goto nla_put_failure;
Johannes Bergcdc89b92013-02-18 23:54:36 +0100608 }
609 }
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400610
Johannes Bergfe1abaf2013-02-27 15:39:45 +0100611 if (large) {
612 if ((chan->flags & IEEE80211_CHAN_NO_HT40MINUS) &&
613 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_HT40_MINUS))
614 goto nla_put_failure;
615 if ((chan->flags & IEEE80211_CHAN_NO_HT40PLUS) &&
616 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_HT40_PLUS))
617 goto nla_put_failure;
618 if ((chan->flags & IEEE80211_CHAN_NO_80MHZ) &&
619 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_80MHZ))
620 goto nla_put_failure;
621 if ((chan->flags & IEEE80211_CHAN_NO_160MHZ) &&
622 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_160MHZ))
623 goto nla_put_failure;
David Spinadel570dbde2014-02-23 09:12:59 +0200624 if ((chan->flags & IEEE80211_CHAN_INDOOR_ONLY) &&
625 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_INDOOR_ONLY))
626 goto nla_put_failure;
627 if ((chan->flags & IEEE80211_CHAN_GO_CONCURRENT) &&
628 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_GO_CONCURRENT))
629 goto nla_put_failure;
Rostislav Lisovyea077c12014-04-15 14:37:55 +0200630 if ((chan->flags & IEEE80211_CHAN_NO_20MHZ) &&
631 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_20MHZ))
632 goto nla_put_failure;
633 if ((chan->flags & IEEE80211_CHAN_NO_10MHZ) &&
634 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_10MHZ))
635 goto nla_put_failure;
Johannes Bergfe1abaf2013-02-27 15:39:45 +0100636 }
637
David S. Miller9360ffd2012-03-29 04:41:26 -0400638 if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_MAX_TX_POWER,
639 DBM_TO_MBM(chan->max_power)))
640 goto nla_put_failure;
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400641
642 return 0;
643
644 nla_put_failure:
645 return -ENOBUFS;
646}
647
Johannes Berg55682962007-09-20 13:09:35 -0400648/* netlink command implementations */
649
Johannes Bergb9454e82009-07-08 13:29:08 +0200650struct key_parse {
651 struct key_params p;
652 int idx;
Johannes Berge31b8212010-10-05 19:39:30 +0200653 int type;
Johannes Bergb9454e82009-07-08 13:29:08 +0200654 bool def, defmgmt;
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100655 bool def_uni, def_multi;
Johannes Bergb9454e82009-07-08 13:29:08 +0200656};
657
658static int nl80211_parse_key_new(struct nlattr *key, struct key_parse *k)
659{
660 struct nlattr *tb[NL80211_KEY_MAX + 1];
661 int err = nla_parse_nested(tb, NL80211_KEY_MAX, key,
662 nl80211_key_policy);
663 if (err)
664 return err;
665
666 k->def = !!tb[NL80211_KEY_DEFAULT];
667 k->defmgmt = !!tb[NL80211_KEY_DEFAULT_MGMT];
668
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100669 if (k->def) {
670 k->def_uni = true;
671 k->def_multi = true;
672 }
673 if (k->defmgmt)
674 k->def_multi = true;
675
Johannes Bergb9454e82009-07-08 13:29:08 +0200676 if (tb[NL80211_KEY_IDX])
677 k->idx = nla_get_u8(tb[NL80211_KEY_IDX]);
678
679 if (tb[NL80211_KEY_DATA]) {
680 k->p.key = nla_data(tb[NL80211_KEY_DATA]);
681 k->p.key_len = nla_len(tb[NL80211_KEY_DATA]);
682 }
683
684 if (tb[NL80211_KEY_SEQ]) {
685 k->p.seq = nla_data(tb[NL80211_KEY_SEQ]);
686 k->p.seq_len = nla_len(tb[NL80211_KEY_SEQ]);
687 }
688
689 if (tb[NL80211_KEY_CIPHER])
690 k->p.cipher = nla_get_u32(tb[NL80211_KEY_CIPHER]);
691
Johannes Berge31b8212010-10-05 19:39:30 +0200692 if (tb[NL80211_KEY_TYPE]) {
693 k->type = nla_get_u32(tb[NL80211_KEY_TYPE]);
694 if (k->type < 0 || k->type >= NUM_NL80211_KEYTYPES)
695 return -EINVAL;
696 }
697
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100698 if (tb[NL80211_KEY_DEFAULT_TYPES]) {
699 struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES];
Johannes Berg2da8f412012-01-20 13:52:37 +0100700 err = nla_parse_nested(kdt, NUM_NL80211_KEY_DEFAULT_TYPES - 1,
701 tb[NL80211_KEY_DEFAULT_TYPES],
702 nl80211_key_default_policy);
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100703 if (err)
704 return err;
705
706 k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST];
707 k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST];
708 }
709
Johannes Bergb9454e82009-07-08 13:29:08 +0200710 return 0;
711}
712
713static int nl80211_parse_key_old(struct genl_info *info, struct key_parse *k)
714{
715 if (info->attrs[NL80211_ATTR_KEY_DATA]) {
716 k->p.key = nla_data(info->attrs[NL80211_ATTR_KEY_DATA]);
717 k->p.key_len = nla_len(info->attrs[NL80211_ATTR_KEY_DATA]);
718 }
719
720 if (info->attrs[NL80211_ATTR_KEY_SEQ]) {
721 k->p.seq = nla_data(info->attrs[NL80211_ATTR_KEY_SEQ]);
722 k->p.seq_len = nla_len(info->attrs[NL80211_ATTR_KEY_SEQ]);
723 }
724
725 if (info->attrs[NL80211_ATTR_KEY_IDX])
726 k->idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]);
727
728 if (info->attrs[NL80211_ATTR_KEY_CIPHER])
729 k->p.cipher = nla_get_u32(info->attrs[NL80211_ATTR_KEY_CIPHER]);
730
731 k->def = !!info->attrs[NL80211_ATTR_KEY_DEFAULT];
732 k->defmgmt = !!info->attrs[NL80211_ATTR_KEY_DEFAULT_MGMT];
733
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100734 if (k->def) {
735 k->def_uni = true;
736 k->def_multi = true;
737 }
738 if (k->defmgmt)
739 k->def_multi = true;
740
Johannes Berge31b8212010-10-05 19:39:30 +0200741 if (info->attrs[NL80211_ATTR_KEY_TYPE]) {
742 k->type = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]);
743 if (k->type < 0 || k->type >= NUM_NL80211_KEYTYPES)
744 return -EINVAL;
745 }
746
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100747 if (info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES]) {
748 struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES];
749 int err = nla_parse_nested(
750 kdt, NUM_NL80211_KEY_DEFAULT_TYPES - 1,
751 info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES],
752 nl80211_key_default_policy);
753 if (err)
754 return err;
755
756 k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST];
757 k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST];
758 }
759
Johannes Bergb9454e82009-07-08 13:29:08 +0200760 return 0;
761}
762
763static int nl80211_parse_key(struct genl_info *info, struct key_parse *k)
764{
765 int err;
766
767 memset(k, 0, sizeof(*k));
768 k->idx = -1;
Johannes Berge31b8212010-10-05 19:39:30 +0200769 k->type = -1;
Johannes Bergb9454e82009-07-08 13:29:08 +0200770
771 if (info->attrs[NL80211_ATTR_KEY])
772 err = nl80211_parse_key_new(info->attrs[NL80211_ATTR_KEY], k);
773 else
774 err = nl80211_parse_key_old(info, k);
775
776 if (err)
777 return err;
778
779 if (k->def && k->defmgmt)
780 return -EINVAL;
781
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100782 if (k->defmgmt) {
783 if (k->def_uni || !k->def_multi)
784 return -EINVAL;
785 }
786
Johannes Bergb9454e82009-07-08 13:29:08 +0200787 if (k->idx != -1) {
788 if (k->defmgmt) {
789 if (k->idx < 4 || k->idx > 5)
790 return -EINVAL;
791 } else if (k->def) {
792 if (k->idx < 0 || k->idx > 3)
793 return -EINVAL;
794 } else {
795 if (k->idx < 0 || k->idx > 5)
796 return -EINVAL;
797 }
798 }
799
800 return 0;
801}
802
Johannes Bergfffd0932009-07-08 14:22:54 +0200803static struct cfg80211_cached_keys *
804nl80211_parse_connkeys(struct cfg80211_registered_device *rdev,
Sujith Manoharande7044e2012-10-18 10:19:28 +0530805 struct nlattr *keys, bool *no_ht)
Johannes Bergfffd0932009-07-08 14:22:54 +0200806{
807 struct key_parse parse;
808 struct nlattr *key;
809 struct cfg80211_cached_keys *result;
810 int rem, err, def = 0;
811
812 result = kzalloc(sizeof(*result), GFP_KERNEL);
813 if (!result)
814 return ERR_PTR(-ENOMEM);
815
816 result->def = -1;
817 result->defmgmt = -1;
818
819 nla_for_each_nested(key, keys, rem) {
820 memset(&parse, 0, sizeof(parse));
821 parse.idx = -1;
822
823 err = nl80211_parse_key_new(key, &parse);
824 if (err)
825 goto error;
826 err = -EINVAL;
827 if (!parse.p.key)
828 goto error;
829 if (parse.idx < 0 || parse.idx > 4)
830 goto error;
831 if (parse.def) {
832 if (def)
833 goto error;
834 def = 1;
835 result->def = parse.idx;
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100836 if (!parse.def_uni || !parse.def_multi)
837 goto error;
Johannes Bergfffd0932009-07-08 14:22:54 +0200838 } else if (parse.defmgmt)
839 goto error;
840 err = cfg80211_validate_key_settings(rdev, &parse.p,
Johannes Berge31b8212010-10-05 19:39:30 +0200841 parse.idx, false, NULL);
Johannes Bergfffd0932009-07-08 14:22:54 +0200842 if (err)
843 goto error;
844 result->params[parse.idx].cipher = parse.p.cipher;
845 result->params[parse.idx].key_len = parse.p.key_len;
846 result->params[parse.idx].key = result->data[parse.idx];
847 memcpy(result->data[parse.idx], parse.p.key, parse.p.key_len);
Sujith Manoharande7044e2012-10-18 10:19:28 +0530848
849 if (parse.p.cipher == WLAN_CIPHER_SUITE_WEP40 ||
850 parse.p.cipher == WLAN_CIPHER_SUITE_WEP104) {
851 if (no_ht)
852 *no_ht = true;
853 }
Johannes Bergfffd0932009-07-08 14:22:54 +0200854 }
855
856 return result;
857 error:
858 kfree(result);
859 return ERR_PTR(err);
860}
861
862static int nl80211_key_allowed(struct wireless_dev *wdev)
863{
864 ASSERT_WDEV_LOCK(wdev);
865
Johannes Bergfffd0932009-07-08 14:22:54 +0200866 switch (wdev->iftype) {
867 case NL80211_IFTYPE_AP:
868 case NL80211_IFTYPE_AP_VLAN:
Johannes Berg074ac8d2010-09-16 14:58:22 +0200869 case NL80211_IFTYPE_P2P_GO:
Thomas Pedersenff973af2011-05-03 16:57:12 -0700870 case NL80211_IFTYPE_MESH_POINT:
Johannes Bergfffd0932009-07-08 14:22:54 +0200871 break;
872 case NL80211_IFTYPE_ADHOC:
Johannes Bergfffd0932009-07-08 14:22:54 +0200873 case NL80211_IFTYPE_STATION:
Johannes Berg074ac8d2010-09-16 14:58:22 +0200874 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Bergceca7b72013-05-16 00:55:45 +0200875 if (!wdev->current_bss)
Johannes Bergfffd0932009-07-08 14:22:54 +0200876 return -ENOLINK;
877 break;
878 default:
879 return -EINVAL;
880 }
881
882 return 0;
883}
884
Jouni Malinen664834d2014-01-15 00:01:44 +0200885static struct ieee80211_channel *nl80211_get_valid_chan(struct wiphy *wiphy,
886 struct nlattr *tb)
887{
888 struct ieee80211_channel *chan;
889
890 if (tb == NULL)
891 return NULL;
892 chan = ieee80211_get_channel(wiphy, nla_get_u32(tb));
893 if (!chan || chan->flags & IEEE80211_CHAN_DISABLED)
894 return NULL;
895 return chan;
896}
897
Johannes Berg7527a782011-05-13 10:58:57 +0200898static int nl80211_put_iftypes(struct sk_buff *msg, u32 attr, u16 ifmodes)
899{
900 struct nlattr *nl_modes = nla_nest_start(msg, attr);
901 int i;
902
903 if (!nl_modes)
904 goto nla_put_failure;
905
906 i = 0;
907 while (ifmodes) {
David S. Miller9360ffd2012-03-29 04:41:26 -0400908 if ((ifmodes & 1) && nla_put_flag(msg, i))
909 goto nla_put_failure;
Johannes Berg7527a782011-05-13 10:58:57 +0200910 ifmodes >>= 1;
911 i++;
912 }
913
914 nla_nest_end(msg, nl_modes);
915 return 0;
916
917nla_put_failure:
918 return -ENOBUFS;
919}
920
921static int nl80211_put_iface_combinations(struct wiphy *wiphy,
Johannes Bergcdc89b92013-02-18 23:54:36 +0100922 struct sk_buff *msg,
923 bool large)
Johannes Berg7527a782011-05-13 10:58:57 +0200924{
925 struct nlattr *nl_combis;
926 int i, j;
927
928 nl_combis = nla_nest_start(msg,
929 NL80211_ATTR_INTERFACE_COMBINATIONS);
930 if (!nl_combis)
931 goto nla_put_failure;
932
933 for (i = 0; i < wiphy->n_iface_combinations; i++) {
934 const struct ieee80211_iface_combination *c;
935 struct nlattr *nl_combi, *nl_limits;
936
937 c = &wiphy->iface_combinations[i];
938
939 nl_combi = nla_nest_start(msg, i + 1);
940 if (!nl_combi)
941 goto nla_put_failure;
942
943 nl_limits = nla_nest_start(msg, NL80211_IFACE_COMB_LIMITS);
944 if (!nl_limits)
945 goto nla_put_failure;
946
947 for (j = 0; j < c->n_limits; j++) {
948 struct nlattr *nl_limit;
949
950 nl_limit = nla_nest_start(msg, j + 1);
951 if (!nl_limit)
952 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -0400953 if (nla_put_u32(msg, NL80211_IFACE_LIMIT_MAX,
954 c->limits[j].max))
955 goto nla_put_failure;
Johannes Berg7527a782011-05-13 10:58:57 +0200956 if (nl80211_put_iftypes(msg, NL80211_IFACE_LIMIT_TYPES,
957 c->limits[j].types))
958 goto nla_put_failure;
959 nla_nest_end(msg, nl_limit);
960 }
961
962 nla_nest_end(msg, nl_limits);
963
David S. Miller9360ffd2012-03-29 04:41:26 -0400964 if (c->beacon_int_infra_match &&
965 nla_put_flag(msg, NL80211_IFACE_COMB_STA_AP_BI_MATCH))
966 goto nla_put_failure;
967 if (nla_put_u32(msg, NL80211_IFACE_COMB_NUM_CHANNELS,
968 c->num_different_channels) ||
969 nla_put_u32(msg, NL80211_IFACE_COMB_MAXNUM,
970 c->max_interfaces))
971 goto nla_put_failure;
Johannes Bergcdc89b92013-02-18 23:54:36 +0100972 if (large &&
973 nla_put_u32(msg, NL80211_IFACE_COMB_RADAR_DETECT_WIDTHS,
974 c->radar_detect_widths))
975 goto nla_put_failure;
Johannes Berg7527a782011-05-13 10:58:57 +0200976
977 nla_nest_end(msg, nl_combi);
978 }
979
980 nla_nest_end(msg, nl_combis);
981
982 return 0;
983nla_put_failure:
984 return -ENOBUFS;
985}
986
Johannes Berg3713b4e2013-02-14 16:19:38 +0100987#ifdef CONFIG_PM
Johannes Bergb56cf722013-02-20 01:02:38 +0100988static int nl80211_send_wowlan_tcp_caps(struct cfg80211_registered_device *rdev,
989 struct sk_buff *msg)
990{
Johannes Berg964dc9e2013-06-03 17:25:34 +0200991 const struct wiphy_wowlan_tcp_support *tcp = rdev->wiphy.wowlan->tcp;
Johannes Bergb56cf722013-02-20 01:02:38 +0100992 struct nlattr *nl_tcp;
993
994 if (!tcp)
995 return 0;
996
997 nl_tcp = nla_nest_start(msg, NL80211_WOWLAN_TRIG_TCP_CONNECTION);
998 if (!nl_tcp)
999 return -ENOBUFS;
1000
1001 if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD,
1002 tcp->data_payload_max))
1003 return -ENOBUFS;
1004
1005 if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD,
1006 tcp->data_payload_max))
1007 return -ENOBUFS;
1008
1009 if (tcp->seq && nla_put_flag(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ))
1010 return -ENOBUFS;
1011
1012 if (tcp->tok && nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN,
1013 sizeof(*tcp->tok), tcp->tok))
1014 return -ENOBUFS;
1015
1016 if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_INTERVAL,
1017 tcp->data_interval_max))
1018 return -ENOBUFS;
1019
1020 if (nla_put_u32(msg, NL80211_WOWLAN_TCP_WAKE_PAYLOAD,
1021 tcp->wake_payload_max))
1022 return -ENOBUFS;
1023
1024 nla_nest_end(msg, nl_tcp);
1025 return 0;
1026}
1027
Johannes Berg3713b4e2013-02-14 16:19:38 +01001028static int nl80211_send_wowlan(struct sk_buff *msg,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001029 struct cfg80211_registered_device *rdev,
Johannes Bergb56cf722013-02-20 01:02:38 +01001030 bool large)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001031{
1032 struct nlattr *nl_wowlan;
1033
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001034 if (!rdev->wiphy.wowlan)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001035 return 0;
1036
1037 nl_wowlan = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS_SUPPORTED);
1038 if (!nl_wowlan)
1039 return -ENOBUFS;
1040
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001041 if (((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_ANY) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001042 nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) ||
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001043 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_DISCONNECT) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001044 nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) ||
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001045 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001046 nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) ||
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001047 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_SUPPORTS_GTK_REKEY) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001048 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED)) ||
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001049 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001050 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) ||
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001051 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001052 nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) ||
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001053 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001054 nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) ||
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001055 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001056 nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE)))
1057 return -ENOBUFS;
1058
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001059 if (rdev->wiphy.wowlan->n_patterns) {
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07001060 struct nl80211_pattern_support pat = {
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001061 .max_patterns = rdev->wiphy.wowlan->n_patterns,
1062 .min_pattern_len = rdev->wiphy.wowlan->pattern_min_len,
1063 .max_pattern_len = rdev->wiphy.wowlan->pattern_max_len,
1064 .max_pkt_offset = rdev->wiphy.wowlan->max_pkt_offset,
Johannes Berg3713b4e2013-02-14 16:19:38 +01001065 };
1066
1067 if (nla_put(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN,
1068 sizeof(pat), &pat))
1069 return -ENOBUFS;
1070 }
1071
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001072 if (large && nl80211_send_wowlan_tcp_caps(rdev, msg))
Johannes Bergb56cf722013-02-20 01:02:38 +01001073 return -ENOBUFS;
1074
Johannes Berg3713b4e2013-02-14 16:19:38 +01001075 nla_nest_end(msg, nl_wowlan);
1076
1077 return 0;
1078}
1079#endif
1080
Amitkumar Karwarbe29b99a2013-06-28 11:51:26 -07001081static int nl80211_send_coalesce(struct sk_buff *msg,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001082 struct cfg80211_registered_device *rdev)
Amitkumar Karwarbe29b99a2013-06-28 11:51:26 -07001083{
1084 struct nl80211_coalesce_rule_support rule;
1085
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001086 if (!rdev->wiphy.coalesce)
Amitkumar Karwarbe29b99a2013-06-28 11:51:26 -07001087 return 0;
1088
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001089 rule.max_rules = rdev->wiphy.coalesce->n_rules;
1090 rule.max_delay = rdev->wiphy.coalesce->max_delay;
1091 rule.pat.max_patterns = rdev->wiphy.coalesce->n_patterns;
1092 rule.pat.min_pattern_len = rdev->wiphy.coalesce->pattern_min_len;
1093 rule.pat.max_pattern_len = rdev->wiphy.coalesce->pattern_max_len;
1094 rule.pat.max_pkt_offset = rdev->wiphy.coalesce->max_pkt_offset;
Amitkumar Karwarbe29b99a2013-06-28 11:51:26 -07001095
1096 if (nla_put(msg, NL80211_ATTR_COALESCE_RULE, sizeof(rule), &rule))
1097 return -ENOBUFS;
1098
1099 return 0;
1100}
1101
Johannes Berg3713b4e2013-02-14 16:19:38 +01001102static int nl80211_send_band_rateinfo(struct sk_buff *msg,
1103 struct ieee80211_supported_band *sband)
1104{
1105 struct nlattr *nl_rates, *nl_rate;
1106 struct ieee80211_rate *rate;
1107 int i;
1108
1109 /* add HT info */
1110 if (sband->ht_cap.ht_supported &&
1111 (nla_put(msg, NL80211_BAND_ATTR_HT_MCS_SET,
1112 sizeof(sband->ht_cap.mcs),
1113 &sband->ht_cap.mcs) ||
1114 nla_put_u16(msg, NL80211_BAND_ATTR_HT_CAPA,
1115 sband->ht_cap.cap) ||
1116 nla_put_u8(msg, NL80211_BAND_ATTR_HT_AMPDU_FACTOR,
1117 sband->ht_cap.ampdu_factor) ||
1118 nla_put_u8(msg, NL80211_BAND_ATTR_HT_AMPDU_DENSITY,
1119 sband->ht_cap.ampdu_density)))
1120 return -ENOBUFS;
1121
1122 /* add VHT info */
1123 if (sband->vht_cap.vht_supported &&
1124 (nla_put(msg, NL80211_BAND_ATTR_VHT_MCS_SET,
1125 sizeof(sband->vht_cap.vht_mcs),
1126 &sband->vht_cap.vht_mcs) ||
1127 nla_put_u32(msg, NL80211_BAND_ATTR_VHT_CAPA,
1128 sband->vht_cap.cap)))
1129 return -ENOBUFS;
1130
1131 /* add bitrates */
1132 nl_rates = nla_nest_start(msg, NL80211_BAND_ATTR_RATES);
1133 if (!nl_rates)
1134 return -ENOBUFS;
1135
1136 for (i = 0; i < sband->n_bitrates; i++) {
1137 nl_rate = nla_nest_start(msg, i);
1138 if (!nl_rate)
1139 return -ENOBUFS;
1140
1141 rate = &sband->bitrates[i];
1142 if (nla_put_u32(msg, NL80211_BITRATE_ATTR_RATE,
1143 rate->bitrate))
1144 return -ENOBUFS;
1145 if ((rate->flags & IEEE80211_RATE_SHORT_PREAMBLE) &&
1146 nla_put_flag(msg,
1147 NL80211_BITRATE_ATTR_2GHZ_SHORTPREAMBLE))
1148 return -ENOBUFS;
1149
1150 nla_nest_end(msg, nl_rate);
1151 }
1152
1153 nla_nest_end(msg, nl_rates);
1154
1155 return 0;
1156}
1157
1158static int
1159nl80211_send_mgmt_stypes(struct sk_buff *msg,
1160 const struct ieee80211_txrx_stypes *mgmt_stypes)
1161{
1162 u16 stypes;
1163 struct nlattr *nl_ftypes, *nl_ifs;
1164 enum nl80211_iftype ift;
1165 int i;
1166
1167 if (!mgmt_stypes)
1168 return 0;
1169
1170 nl_ifs = nla_nest_start(msg, NL80211_ATTR_TX_FRAME_TYPES);
1171 if (!nl_ifs)
1172 return -ENOBUFS;
1173
1174 for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) {
1175 nl_ftypes = nla_nest_start(msg, ift);
1176 if (!nl_ftypes)
1177 return -ENOBUFS;
1178 i = 0;
1179 stypes = mgmt_stypes[ift].tx;
1180 while (stypes) {
1181 if ((stypes & 1) &&
1182 nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE,
1183 (i << 4) | IEEE80211_FTYPE_MGMT))
1184 return -ENOBUFS;
1185 stypes >>= 1;
1186 i++;
1187 }
1188 nla_nest_end(msg, nl_ftypes);
1189 }
1190
1191 nla_nest_end(msg, nl_ifs);
1192
1193 nl_ifs = nla_nest_start(msg, NL80211_ATTR_RX_FRAME_TYPES);
1194 if (!nl_ifs)
1195 return -ENOBUFS;
1196
1197 for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) {
1198 nl_ftypes = nla_nest_start(msg, ift);
1199 if (!nl_ftypes)
1200 return -ENOBUFS;
1201 i = 0;
1202 stypes = mgmt_stypes[ift].rx;
1203 while (stypes) {
1204 if ((stypes & 1) &&
1205 nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE,
1206 (i << 4) | IEEE80211_FTYPE_MGMT))
1207 return -ENOBUFS;
1208 stypes >>= 1;
1209 i++;
1210 }
1211 nla_nest_end(msg, nl_ftypes);
1212 }
1213 nla_nest_end(msg, nl_ifs);
1214
1215 return 0;
1216}
1217
Johannes Berg86e8cf92013-06-19 10:57:22 +02001218struct nl80211_dump_wiphy_state {
1219 s64 filter_wiphy;
1220 long start;
1221 long split_start, band_start, chan_start;
1222 bool split;
1223};
1224
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001225static int nl80211_send_wiphy(struct cfg80211_registered_device *rdev,
Johannes Berg3713b4e2013-02-14 16:19:38 +01001226 struct sk_buff *msg, u32 portid, u32 seq,
Johannes Berg86e8cf92013-06-19 10:57:22 +02001227 int flags, struct nl80211_dump_wiphy_state *state)
Johannes Berg55682962007-09-20 13:09:35 -04001228{
1229 void *hdr;
Johannes Bergee688b002008-01-24 19:38:39 +01001230 struct nlattr *nl_bands, *nl_band;
1231 struct nlattr *nl_freqs, *nl_freq;
Johannes Berg8fdc6212009-03-14 09:34:01 +01001232 struct nlattr *nl_cmds;
Johannes Bergee688b002008-01-24 19:38:39 +01001233 enum ieee80211_band band;
1234 struct ieee80211_channel *chan;
Johannes Bergee688b002008-01-24 19:38:39 +01001235 int i;
Johannes Berg2e161f782010-08-12 15:38:38 +02001236 const struct ieee80211_txrx_stypes *mgmt_stypes =
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001237 rdev->wiphy.mgmt_stypes;
Johannes Bergfe1abaf2013-02-27 15:39:45 +01001238 u32 features;
Johannes Berg55682962007-09-20 13:09:35 -04001239
Eric W. Biederman15e47302012-09-07 20:12:54 +00001240 hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_WIPHY);
Johannes Berg55682962007-09-20 13:09:35 -04001241 if (!hdr)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001242 return -ENOBUFS;
1243
Johannes Berg86e8cf92013-06-19 10:57:22 +02001244 if (WARN_ON(!state))
1245 return -EINVAL;
Johannes Berg55682962007-09-20 13:09:35 -04001246
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001247 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001248 nla_put_string(msg, NL80211_ATTR_WIPHY_NAME,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001249 wiphy_name(&rdev->wiphy)) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04001250 nla_put_u32(msg, NL80211_ATTR_GENERATION,
Johannes Berg3713b4e2013-02-14 16:19:38 +01001251 cfg80211_rdev_list_generation))
David S. Miller9360ffd2012-03-29 04:41:26 -04001252 goto nla_put_failure;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02001253
Johannes Berg86e8cf92013-06-19 10:57:22 +02001254 switch (state->split_start) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001255 case 0:
1256 if (nla_put_u8(msg, NL80211_ATTR_WIPHY_RETRY_SHORT,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001257 rdev->wiphy.retry_short) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001258 nla_put_u8(msg, NL80211_ATTR_WIPHY_RETRY_LONG,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001259 rdev->wiphy.retry_long) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001260 nla_put_u32(msg, NL80211_ATTR_WIPHY_FRAG_THRESHOLD,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001261 rdev->wiphy.frag_threshold) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001262 nla_put_u32(msg, NL80211_ATTR_WIPHY_RTS_THRESHOLD,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001263 rdev->wiphy.rts_threshold) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001264 nla_put_u8(msg, NL80211_ATTR_WIPHY_COVERAGE_CLASS,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001265 rdev->wiphy.coverage_class) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001266 nla_put_u8(msg, NL80211_ATTR_MAX_NUM_SCAN_SSIDS,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001267 rdev->wiphy.max_scan_ssids) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001268 nla_put_u8(msg, NL80211_ATTR_MAX_NUM_SCHED_SCAN_SSIDS,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001269 rdev->wiphy.max_sched_scan_ssids) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001270 nla_put_u16(msg, NL80211_ATTR_MAX_SCAN_IE_LEN,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001271 rdev->wiphy.max_scan_ie_len) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001272 nla_put_u16(msg, NL80211_ATTR_MAX_SCHED_SCAN_IE_LEN,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001273 rdev->wiphy.max_sched_scan_ie_len) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001274 nla_put_u8(msg, NL80211_ATTR_MAX_MATCH_SETS,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001275 rdev->wiphy.max_match_sets))
Johannes Bergee688b002008-01-24 19:38:39 +01001276 goto nla_put_failure;
1277
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001278 if ((rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001279 nla_put_flag(msg, NL80211_ATTR_SUPPORT_IBSS_RSN))
1280 goto nla_put_failure;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001281 if ((rdev->wiphy.flags & WIPHY_FLAG_MESH_AUTH) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001282 nla_put_flag(msg, NL80211_ATTR_SUPPORT_MESH_AUTH))
1283 goto nla_put_failure;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001284 if ((rdev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001285 nla_put_flag(msg, NL80211_ATTR_SUPPORT_AP_UAPSD))
1286 goto nla_put_failure;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001287 if ((rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_FW_ROAM) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001288 nla_put_flag(msg, NL80211_ATTR_ROAM_SUPPORT))
1289 goto nla_put_failure;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001290 if ((rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001291 nla_put_flag(msg, NL80211_ATTR_TDLS_SUPPORT))
1292 goto nla_put_failure;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001293 if ((rdev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001294 nla_put_flag(msg, NL80211_ATTR_TDLS_EXTERNAL_SETUP))
David S. Miller9360ffd2012-03-29 04:41:26 -04001295 goto nla_put_failure;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001296 state->split_start++;
1297 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001298 break;
1299 case 1:
1300 if (nla_put(msg, NL80211_ATTR_CIPHER_SUITES,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001301 sizeof(u32) * rdev->wiphy.n_cipher_suites,
1302 rdev->wiphy.cipher_suites))
Mahesh Palivelabf0c111e2012-06-22 07:27:46 +00001303 goto nla_put_failure;
1304
Johannes Berg3713b4e2013-02-14 16:19:38 +01001305 if (nla_put_u8(msg, NL80211_ATTR_MAX_NUM_PMKIDS,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001306 rdev->wiphy.max_num_pmkids))
Johannes Bergee688b002008-01-24 19:38:39 +01001307 goto nla_put_failure;
1308
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001309 if ((rdev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001310 nla_put_flag(msg, NL80211_ATTR_CONTROL_PORT_ETHERTYPE))
1311 goto nla_put_failure;
Johannes Bergee688b002008-01-24 19:38:39 +01001312
Johannes Berg3713b4e2013-02-14 16:19:38 +01001313 if (nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_TX,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001314 rdev->wiphy.available_antennas_tx) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001315 nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_RX,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001316 rdev->wiphy.available_antennas_rx))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001317 goto nla_put_failure;
Johannes Bergee688b002008-01-24 19:38:39 +01001318
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001319 if ((rdev->wiphy.flags & WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001320 nla_put_u32(msg, NL80211_ATTR_PROBE_RESP_OFFLOAD,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001321 rdev->wiphy.probe_resp_offload))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001322 goto nla_put_failure;
Jouni Malinene2f367f262008-11-21 19:01:30 +02001323
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001324 if ((rdev->wiphy.available_antennas_tx ||
1325 rdev->wiphy.available_antennas_rx) &&
1326 rdev->ops->get_antenna) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001327 u32 tx_ant = 0, rx_ant = 0;
1328 int res;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001329 res = rdev_get_antenna(rdev, &tx_ant, &rx_ant);
Johannes Berg3713b4e2013-02-14 16:19:38 +01001330 if (!res) {
1331 if (nla_put_u32(msg,
1332 NL80211_ATTR_WIPHY_ANTENNA_TX,
1333 tx_ant) ||
1334 nla_put_u32(msg,
1335 NL80211_ATTR_WIPHY_ANTENNA_RX,
1336 rx_ant))
1337 goto nla_put_failure;
1338 }
Johannes Bergee688b002008-01-24 19:38:39 +01001339 }
1340
Johannes Berg86e8cf92013-06-19 10:57:22 +02001341 state->split_start++;
1342 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001343 break;
1344 case 2:
1345 if (nl80211_put_iftypes(msg, NL80211_ATTR_SUPPORTED_IFTYPES,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001346 rdev->wiphy.interface_modes))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001347 goto nla_put_failure;
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 3:
1352 nl_bands = nla_nest_start(msg, NL80211_ATTR_WIPHY_BANDS);
1353 if (!nl_bands)
Johannes Bergee688b002008-01-24 19:38:39 +01001354 goto nla_put_failure;
1355
Johannes Berg86e8cf92013-06-19 10:57:22 +02001356 for (band = state->band_start;
1357 band < IEEE80211_NUM_BANDS; band++) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001358 struct ieee80211_supported_band *sband;
1359
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001360 sband = rdev->wiphy.bands[band];
Johannes Berg3713b4e2013-02-14 16:19:38 +01001361
1362 if (!sband)
1363 continue;
1364
1365 nl_band = nla_nest_start(msg, band);
1366 if (!nl_band)
Johannes Bergee688b002008-01-24 19:38:39 +01001367 goto nla_put_failure;
1368
Johannes Berg86e8cf92013-06-19 10:57:22 +02001369 switch (state->chan_start) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001370 case 0:
1371 if (nl80211_send_band_rateinfo(msg, sband))
1372 goto nla_put_failure;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001373 state->chan_start++;
1374 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001375 break;
1376 default:
1377 /* add frequencies */
1378 nl_freqs = nla_nest_start(
1379 msg, NL80211_BAND_ATTR_FREQS);
1380 if (!nl_freqs)
1381 goto nla_put_failure;
Johannes Bergee688b002008-01-24 19:38:39 +01001382
Johannes Berg86e8cf92013-06-19 10:57:22 +02001383 for (i = state->chan_start - 1;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001384 i < sband->n_channels;
1385 i++) {
1386 nl_freq = nla_nest_start(msg, i);
1387 if (!nl_freq)
1388 goto nla_put_failure;
1389
1390 chan = &sband->channels[i];
1391
Johannes Berg86e8cf92013-06-19 10:57:22 +02001392 if (nl80211_msg_put_channel(
1393 msg, chan,
1394 state->split))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001395 goto nla_put_failure;
1396
1397 nla_nest_end(msg, nl_freq);
Johannes Berg86e8cf92013-06-19 10:57:22 +02001398 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001399 break;
1400 }
1401 if (i < sband->n_channels)
Johannes Berg86e8cf92013-06-19 10:57:22 +02001402 state->chan_start = i + 2;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001403 else
Johannes Berg86e8cf92013-06-19 10:57:22 +02001404 state->chan_start = 0;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001405 nla_nest_end(msg, nl_freqs);
1406 }
1407
1408 nla_nest_end(msg, nl_band);
1409
Johannes Berg86e8cf92013-06-19 10:57:22 +02001410 if (state->split) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001411 /* start again here */
Johannes Berg86e8cf92013-06-19 10:57:22 +02001412 if (state->chan_start)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001413 band--;
1414 break;
1415 }
Johannes Bergee688b002008-01-24 19:38:39 +01001416 }
Johannes Berg3713b4e2013-02-14 16:19:38 +01001417 nla_nest_end(msg, nl_bands);
Johannes Bergee688b002008-01-24 19:38:39 +01001418
Johannes Berg3713b4e2013-02-14 16:19:38 +01001419 if (band < IEEE80211_NUM_BANDS)
Johannes Berg86e8cf92013-06-19 10:57:22 +02001420 state->band_start = band + 1;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001421 else
Johannes Berg86e8cf92013-06-19 10:57:22 +02001422 state->band_start = 0;
Johannes Bergee688b002008-01-24 19:38:39 +01001423
Johannes Berg3713b4e2013-02-14 16:19:38 +01001424 /* if bands & channels are done, continue outside */
Johannes Berg86e8cf92013-06-19 10:57:22 +02001425 if (state->band_start == 0 && state->chan_start == 0)
1426 state->split_start++;
1427 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001428 break;
1429 case 4:
1430 nl_cmds = nla_nest_start(msg, NL80211_ATTR_SUPPORTED_COMMANDS);
1431 if (!nl_cmds)
David S. Miller9360ffd2012-03-29 04:41:26 -04001432 goto nla_put_failure;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001433
1434 i = 0;
1435#define CMD(op, n) \
1436 do { \
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001437 if (rdev->ops->op) { \
Johannes Berg3713b4e2013-02-14 16:19:38 +01001438 i++; \
1439 if (nla_put_u32(msg, i, NL80211_CMD_ ## n)) \
1440 goto nla_put_failure; \
1441 } \
1442 } while (0)
1443
1444 CMD(add_virtual_intf, NEW_INTERFACE);
1445 CMD(change_virtual_intf, SET_INTERFACE);
1446 CMD(add_key, NEW_KEY);
1447 CMD(start_ap, START_AP);
1448 CMD(add_station, NEW_STATION);
1449 CMD(add_mpath, NEW_MPATH);
1450 CMD(update_mesh_config, SET_MESH_CONFIG);
1451 CMD(change_bss, SET_BSS);
1452 CMD(auth, AUTHENTICATE);
1453 CMD(assoc, ASSOCIATE);
1454 CMD(deauth, DEAUTHENTICATE);
1455 CMD(disassoc, DISASSOCIATE);
1456 CMD(join_ibss, JOIN_IBSS);
1457 CMD(join_mesh, JOIN_MESH);
1458 CMD(set_pmksa, SET_PMKSA);
1459 CMD(del_pmksa, DEL_PMKSA);
1460 CMD(flush_pmksa, FLUSH_PMKSA);
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001461 if (rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001462 CMD(remain_on_channel, REMAIN_ON_CHANNEL);
1463 CMD(set_bitrate_mask, SET_TX_BITRATE_MASK);
1464 CMD(mgmt_tx, FRAME);
1465 CMD(mgmt_tx_cancel_wait, FRAME_WAIT_CANCEL);
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001466 if (rdev->wiphy.flags & WIPHY_FLAG_NETNS_OK) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001467 i++;
1468 if (nla_put_u32(msg, i, NL80211_CMD_SET_WIPHY_NETNS))
1469 goto nla_put_failure;
1470 }
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001471 if (rdev->ops->set_monitor_channel || rdev->ops->start_ap ||
1472 rdev->ops->join_mesh) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001473 i++;
1474 if (nla_put_u32(msg, i, NL80211_CMD_SET_CHANNEL))
1475 goto nla_put_failure;
1476 }
1477 CMD(set_wds_peer, SET_WDS_PEER);
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001478 if (rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001479 CMD(tdls_mgmt, TDLS_MGMT);
1480 CMD(tdls_oper, TDLS_OPER);
1481 }
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001482 if (rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001483 CMD(sched_scan_start, START_SCHED_SCAN);
1484 CMD(probe_client, PROBE_CLIENT);
1485 CMD(set_noack_map, SET_NOACK_MAP);
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001486 if (rdev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001487 i++;
1488 if (nla_put_u32(msg, i, NL80211_CMD_REGISTER_BEACONS))
1489 goto nla_put_failure;
1490 }
1491 CMD(start_p2p_device, START_P2P_DEVICE);
1492 CMD(set_mcast_rate, SET_MCAST_RATE);
Johannes Berg86e8cf92013-06-19 10:57:22 +02001493 if (state->split) {
Arend van Spriel5de17982013-04-18 15:49:00 +02001494 CMD(crit_proto_start, CRIT_PROTOCOL_START);
1495 CMD(crit_proto_stop, CRIT_PROTOCOL_STOP);
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001496 if (rdev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH)
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02001497 CMD(channel_switch, CHANNEL_SWITCH);
Arend van Spriel5de17982013-04-18 15:49:00 +02001498 }
Kyeyoon Parkfa9ffc72013-12-16 23:01:30 -08001499 CMD(set_qos_map, SET_QOS_MAP);
Johannes Berg8fdc6212009-03-14 09:34:01 +01001500
Kalle Valo4745fc02011-11-17 19:06:10 +02001501#ifdef CONFIG_NL80211_TESTMODE
Johannes Berg3713b4e2013-02-14 16:19:38 +01001502 CMD(testmode_cmd, TESTMODE);
Kalle Valo4745fc02011-11-17 19:06:10 +02001503#endif
1504
Johannes Berg8fdc6212009-03-14 09:34:01 +01001505#undef CMD
Samuel Ortizb23aa672009-07-01 21:26:54 +02001506
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001507 if (rdev->ops->connect || rdev->ops->auth) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001508 i++;
1509 if (nla_put_u32(msg, i, NL80211_CMD_CONNECT))
Johannes Berg2e161f782010-08-12 15:38:38 +02001510 goto nla_put_failure;
Johannes Berg2e161f782010-08-12 15:38:38 +02001511 }
1512
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001513 if (rdev->ops->disconnect || rdev->ops->deauth) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001514 i++;
1515 if (nla_put_u32(msg, i, NL80211_CMD_DISCONNECT))
1516 goto nla_put_failure;
1517 }
Johannes Berg74b70a42010-08-24 12:15:53 +02001518
Johannes Berg3713b4e2013-02-14 16:19:38 +01001519 nla_nest_end(msg, nl_cmds);
Johannes Berg86e8cf92013-06-19 10:57:22 +02001520 state->split_start++;
1521 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001522 break;
1523 case 5:
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001524 if (rdev->ops->remain_on_channel &&
1525 (rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001526 nla_put_u32(msg,
1527 NL80211_ATTR_MAX_REMAIN_ON_CHANNEL_DURATION,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001528 rdev->wiphy.max_remain_on_channel_duration))
Johannes Berg2e161f782010-08-12 15:38:38 +02001529 goto nla_put_failure;
1530
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001531 if ((rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001532 nla_put_flag(msg, NL80211_ATTR_OFFCHANNEL_TX_OK))
1533 goto nla_put_failure;
Johannes Berg2e161f782010-08-12 15:38:38 +02001534
Johannes Berg3713b4e2013-02-14 16:19:38 +01001535 if (nl80211_send_mgmt_stypes(msg, mgmt_stypes))
1536 goto nla_put_failure;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001537 state->split_start++;
1538 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001539 break;
1540 case 6:
Johannes Bergdfb89c52012-06-27 09:23:48 +02001541#ifdef CONFIG_PM
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001542 if (nl80211_send_wowlan(msg, rdev, state->split))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001543 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#else
Johannes Berg86e8cf92013-06-19 10:57:22 +02001548 state->split_start++;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001549#endif
1550 case 7:
1551 if (nl80211_put_iftypes(msg, NL80211_ATTR_SOFTWARE_IFTYPES,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001552 rdev->wiphy.software_iftypes))
Johannes Bergff1b6e62011-05-04 15:37:28 +02001553 goto nla_put_failure;
1554
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001555 if (nl80211_put_iface_combinations(&rdev->wiphy, msg,
Johannes Berg86e8cf92013-06-19 10:57:22 +02001556 state->split))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001557 goto nla_put_failure;
Johannes Bergff1b6e62011-05-04 15:37:28 +02001558
Johannes Berg86e8cf92013-06-19 10:57:22 +02001559 state->split_start++;
1560 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001561 break;
1562 case 8:
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001563 if ((rdev->wiphy.flags & WIPHY_FLAG_HAVE_AP_SME) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001564 nla_put_u32(msg, NL80211_ATTR_DEVICE_AP_SME,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001565 rdev->wiphy.ap_sme_capa))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001566 goto nla_put_failure;
1567
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001568 features = rdev->wiphy.features;
Johannes Bergfe1abaf2013-02-27 15:39:45 +01001569 /*
1570 * We can only add the per-channel limit information if the
1571 * dump is split, otherwise it makes it too big. Therefore
1572 * only advertise it in that case.
1573 */
Johannes Berg86e8cf92013-06-19 10:57:22 +02001574 if (state->split)
Johannes Bergfe1abaf2013-02-27 15:39:45 +01001575 features |= NL80211_FEATURE_ADVERTISE_CHAN_LIMITS;
1576 if (nla_put_u32(msg, NL80211_ATTR_FEATURE_FLAGS, features))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001577 goto nla_put_failure;
1578
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001579 if (rdev->wiphy.ht_capa_mod_mask &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001580 nla_put(msg, NL80211_ATTR_HT_CAPABILITY_MASK,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001581 sizeof(*rdev->wiphy.ht_capa_mod_mask),
1582 rdev->wiphy.ht_capa_mod_mask))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001583 goto nla_put_failure;
1584
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001585 if (rdev->wiphy.flags & WIPHY_FLAG_HAVE_AP_SME &&
1586 rdev->wiphy.max_acl_mac_addrs &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001587 nla_put_u32(msg, NL80211_ATTR_MAC_ACL_MAX,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001588 rdev->wiphy.max_acl_mac_addrs))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001589 goto nla_put_failure;
1590
1591 /*
1592 * Any information below this point is only available to
1593 * applications that can deal with it being split. This
1594 * helps ensure that newly added capabilities don't break
1595 * older tools by overrunning their buffers.
1596 *
1597 * We still increment split_start so that in the split
1598 * case we'll continue with more data in the next round,
1599 * but break unconditionally so unsplit data stops here.
1600 */
Johannes Berg86e8cf92013-06-19 10:57:22 +02001601 state->split_start++;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001602 break;
1603 case 9:
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001604 if (rdev->wiphy.extended_capabilities &&
Johannes Bergfe1abaf2013-02-27 15:39:45 +01001605 (nla_put(msg, NL80211_ATTR_EXT_CAPA,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001606 rdev->wiphy.extended_capabilities_len,
1607 rdev->wiphy.extended_capabilities) ||
Johannes Bergfe1abaf2013-02-27 15:39:45 +01001608 nla_put(msg, NL80211_ATTR_EXT_CAPA_MASK,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001609 rdev->wiphy.extended_capabilities_len,
1610 rdev->wiphy.extended_capabilities_mask)))
Johannes Bergfe1abaf2013-02-27 15:39:45 +01001611 goto nla_put_failure;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001612
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001613 if (rdev->wiphy.vht_capa_mod_mask &&
Johannes Bergee2aca32013-02-21 17:36:01 +01001614 nla_put(msg, NL80211_ATTR_VHT_CAPABILITY_MASK,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001615 sizeof(*rdev->wiphy.vht_capa_mod_mask),
1616 rdev->wiphy.vht_capa_mod_mask))
Johannes Bergee2aca32013-02-21 17:36:01 +01001617 goto nla_put_failure;
1618
Amitkumar Karwarbe29b99a2013-06-28 11:51:26 -07001619 state->split_start++;
1620 break;
1621 case 10:
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001622 if (nl80211_send_coalesce(msg, rdev))
Amitkumar Karwarbe29b99a2013-06-28 11:51:26 -07001623 goto nla_put_failure;
1624
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001625 if ((rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_5_10_MHZ) &&
Felix Fietkau01e0daa2013-11-09 14:57:54 +01001626 (nla_put_flag(msg, NL80211_ATTR_SUPPORT_5_MHZ) ||
1627 nla_put_flag(msg, NL80211_ATTR_SUPPORT_10_MHZ)))
1628 goto nla_put_failure;
Jouni Malinenb43504c2014-01-15 00:01:08 +02001629
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001630 if (rdev->wiphy.max_ap_assoc_sta &&
Jouni Malinenb43504c2014-01-15 00:01:08 +02001631 nla_put_u32(msg, NL80211_ATTR_MAX_AP_ASSOC_STA,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001632 rdev->wiphy.max_ap_assoc_sta))
Jouni Malinenb43504c2014-01-15 00:01:08 +02001633 goto nla_put_failure;
1634
Johannes Bergad7e7182013-11-13 13:37:47 +01001635 state->split_start++;
1636 break;
1637 case 11:
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001638 if (rdev->wiphy.n_vendor_commands) {
Johannes Berg567ffc32013-12-18 14:43:31 +01001639 const struct nl80211_vendor_cmd_info *info;
1640 struct nlattr *nested;
Johannes Bergad7e7182013-11-13 13:37:47 +01001641
Johannes Berg567ffc32013-12-18 14:43:31 +01001642 nested = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA);
1643 if (!nested)
Johannes Bergad7e7182013-11-13 13:37:47 +01001644 goto nla_put_failure;
Johannes Berg567ffc32013-12-18 14:43:31 +01001645
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001646 for (i = 0; i < rdev->wiphy.n_vendor_commands; i++) {
1647 info = &rdev->wiphy.vendor_commands[i].info;
Johannes Berg567ffc32013-12-18 14:43:31 +01001648 if (nla_put(msg, i + 1, sizeof(*info), info))
1649 goto nla_put_failure;
1650 }
1651 nla_nest_end(msg, nested);
1652 }
1653
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001654 if (rdev->wiphy.n_vendor_events) {
Johannes Berg567ffc32013-12-18 14:43:31 +01001655 const struct nl80211_vendor_cmd_info *info;
1656 struct nlattr *nested;
1657
1658 nested = nla_nest_start(msg,
1659 NL80211_ATTR_VENDOR_EVENTS);
1660 if (!nested)
1661 goto nla_put_failure;
1662
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001663 for (i = 0; i < rdev->wiphy.n_vendor_events; i++) {
1664 info = &rdev->wiphy.vendor_events[i];
Johannes Berg567ffc32013-12-18 14:43:31 +01001665 if (nla_put(msg, i + 1, sizeof(*info), info))
1666 goto nla_put_failure;
1667 }
1668 nla_nest_end(msg, nested);
1669 }
Felix Fietkau01e0daa2013-11-09 14:57:54 +01001670
Johannes Berg3713b4e2013-02-14 16:19:38 +01001671 /* done */
Johannes Berg86e8cf92013-06-19 10:57:22 +02001672 state->split_start = 0;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001673 break;
Johannes Bergff1b6e62011-05-04 15:37:28 +02001674 }
Johannes Berg55682962007-09-20 13:09:35 -04001675 return genlmsg_end(msg, hdr);
1676
1677 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07001678 genlmsg_cancel(msg, hdr);
1679 return -EMSGSIZE;
Johannes Berg55682962007-09-20 13:09:35 -04001680}
1681
Johannes Berg86e8cf92013-06-19 10:57:22 +02001682static int nl80211_dump_wiphy_parse(struct sk_buff *skb,
1683 struct netlink_callback *cb,
1684 struct nl80211_dump_wiphy_state *state)
1685{
1686 struct nlattr **tb = nl80211_fam.attrbuf;
1687 int ret = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize,
1688 tb, nl80211_fam.maxattr, nl80211_policy);
1689 /* ignore parse errors for backward compatibility */
1690 if (ret)
1691 return 0;
1692
1693 state->split = tb[NL80211_ATTR_SPLIT_WIPHY_DUMP];
1694 if (tb[NL80211_ATTR_WIPHY])
1695 state->filter_wiphy = nla_get_u32(tb[NL80211_ATTR_WIPHY]);
1696 if (tb[NL80211_ATTR_WDEV])
1697 state->filter_wiphy = nla_get_u64(tb[NL80211_ATTR_WDEV]) >> 32;
1698 if (tb[NL80211_ATTR_IFINDEX]) {
1699 struct net_device *netdev;
1700 struct cfg80211_registered_device *rdev;
1701 int ifidx = nla_get_u32(tb[NL80211_ATTR_IFINDEX]);
1702
Ying Xue7f2b8562014-01-15 10:23:45 +08001703 netdev = __dev_get_by_index(sock_net(skb->sk), ifidx);
Johannes Berg86e8cf92013-06-19 10:57:22 +02001704 if (!netdev)
1705 return -ENODEV;
1706 if (netdev->ieee80211_ptr) {
Zhao, Gangf26cbf42014-04-21 12:53:03 +08001707 rdev = wiphy_to_rdev(
Johannes Berg86e8cf92013-06-19 10:57:22 +02001708 netdev->ieee80211_ptr->wiphy);
1709 state->filter_wiphy = rdev->wiphy_idx;
1710 }
Johannes Berg86e8cf92013-06-19 10:57:22 +02001711 }
1712
1713 return 0;
1714}
1715
Johannes Berg55682962007-09-20 13:09:35 -04001716static int nl80211_dump_wiphy(struct sk_buff *skb, struct netlink_callback *cb)
1717{
Johannes Berg645e77d2013-03-01 14:03:49 +01001718 int idx = 0, ret;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001719 struct nl80211_dump_wiphy_state *state = (void *)cb->args[0];
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001720 struct cfg80211_registered_device *rdev;
Johannes Berg3a5a4232013-06-19 10:09:57 +02001721
Johannes Berg5fe231e2013-05-08 21:45:15 +02001722 rtnl_lock();
Johannes Berg86e8cf92013-06-19 10:57:22 +02001723 if (!state) {
1724 state = kzalloc(sizeof(*state), GFP_KERNEL);
John W. Linville57ed5cd2013-06-28 13:18:21 -04001725 if (!state) {
1726 rtnl_unlock();
Johannes Berg86e8cf92013-06-19 10:57:22 +02001727 return -ENOMEM;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001728 }
Johannes Berg86e8cf92013-06-19 10:57:22 +02001729 state->filter_wiphy = -1;
1730 ret = nl80211_dump_wiphy_parse(skb, cb, state);
1731 if (ret) {
1732 kfree(state);
1733 rtnl_unlock();
1734 return ret;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001735 }
Johannes Berg86e8cf92013-06-19 10:57:22 +02001736 cb->args[0] = (long)state;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001737 }
1738
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001739 list_for_each_entry(rdev, &cfg80211_rdev_list, list) {
1740 if (!net_eq(wiphy_net(&rdev->wiphy), sock_net(skb->sk)))
Johannes Berg463d0182009-07-14 00:33:35 +02001741 continue;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001742 if (++idx <= state->start)
Johannes Berg55682962007-09-20 13:09:35 -04001743 continue;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001744 if (state->filter_wiphy != -1 &&
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001745 state->filter_wiphy != rdev->wiphy_idx)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001746 continue;
1747 /* attempt to fit multiple wiphy data chunks into the skb */
1748 do {
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001749 ret = nl80211_send_wiphy(rdev, skb,
Johannes Berg3713b4e2013-02-14 16:19:38 +01001750 NETLINK_CB(cb->skb).portid,
1751 cb->nlh->nlmsg_seq,
Johannes Berg86e8cf92013-06-19 10:57:22 +02001752 NLM_F_MULTI, state);
Johannes Berg3713b4e2013-02-14 16:19:38 +01001753 if (ret < 0) {
1754 /*
1755 * If sending the wiphy data didn't fit (ENOBUFS
1756 * or EMSGSIZE returned), this SKB is still
1757 * empty (so it's not too big because another
1758 * wiphy dataset is already in the skb) and
1759 * we've not tried to adjust the dump allocation
1760 * yet ... then adjust the alloc size to be
1761 * bigger, and return 1 but with the empty skb.
1762 * This results in an empty message being RX'ed
1763 * in userspace, but that is ignored.
1764 *
1765 * We can then retry with the larger buffer.
1766 */
1767 if ((ret == -ENOBUFS || ret == -EMSGSIZE) &&
Pontus Fuchsf12cb282014-01-16 15:00:40 +01001768 !skb->len && !state->split &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001769 cb->min_dump_alloc < 4096) {
1770 cb->min_dump_alloc = 4096;
Pontus Fuchsf12cb282014-01-16 15:00:40 +01001771 state->split_start = 0;
David S. Millerd98cae64e2013-06-19 16:49:39 -07001772 rtnl_unlock();
Johannes Berg3713b4e2013-02-14 16:19:38 +01001773 return 1;
1774 }
1775 idx--;
1776 break;
Johannes Berg645e77d2013-03-01 14:03:49 +01001777 }
Johannes Berg86e8cf92013-06-19 10:57:22 +02001778 } while (state->split_start > 0);
Johannes Berg3713b4e2013-02-14 16:19:38 +01001779 break;
Johannes Berg55682962007-09-20 13:09:35 -04001780 }
Johannes Berg5fe231e2013-05-08 21:45:15 +02001781 rtnl_unlock();
Johannes Berg55682962007-09-20 13:09:35 -04001782
Johannes Berg86e8cf92013-06-19 10:57:22 +02001783 state->start = idx;
Johannes Berg55682962007-09-20 13:09:35 -04001784
1785 return skb->len;
1786}
1787
Johannes Berg86e8cf92013-06-19 10:57:22 +02001788static int nl80211_dump_wiphy_done(struct netlink_callback *cb)
1789{
1790 kfree((void *)cb->args[0]);
1791 return 0;
1792}
1793
Johannes Berg55682962007-09-20 13:09:35 -04001794static int nl80211_get_wiphy(struct sk_buff *skb, struct genl_info *info)
1795{
1796 struct sk_buff *msg;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001797 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg86e8cf92013-06-19 10:57:22 +02001798 struct nl80211_dump_wiphy_state state = {};
Johannes Berg55682962007-09-20 13:09:35 -04001799
Johannes Berg645e77d2013-03-01 14:03:49 +01001800 msg = nlmsg_new(4096, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -04001801 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02001802 return -ENOMEM;
Johannes Berg55682962007-09-20 13:09:35 -04001803
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001804 if (nl80211_send_wiphy(rdev, msg, info->snd_portid, info->snd_seq, 0,
Johannes Berg86e8cf92013-06-19 10:57:22 +02001805 &state) < 0) {
Johannes Berg4c476992010-10-04 21:36:35 +02001806 nlmsg_free(msg);
1807 return -ENOBUFS;
1808 }
Johannes Berg55682962007-09-20 13:09:35 -04001809
Johannes Berg134e6372009-07-10 09:51:34 +00001810 return genlmsg_reply(msg, info);
Johannes Berg55682962007-09-20 13:09:35 -04001811}
1812
Jouni Malinen31888482008-10-30 16:59:24 +02001813static const struct nla_policy txq_params_policy[NL80211_TXQ_ATTR_MAX + 1] = {
1814 [NL80211_TXQ_ATTR_QUEUE] = { .type = NLA_U8 },
1815 [NL80211_TXQ_ATTR_TXOP] = { .type = NLA_U16 },
1816 [NL80211_TXQ_ATTR_CWMIN] = { .type = NLA_U16 },
1817 [NL80211_TXQ_ATTR_CWMAX] = { .type = NLA_U16 },
1818 [NL80211_TXQ_ATTR_AIFS] = { .type = NLA_U8 },
1819};
1820
1821static int parse_txq_params(struct nlattr *tb[],
1822 struct ieee80211_txq_params *txq_params)
1823{
Johannes Berga3304b02012-03-28 11:04:24 +02001824 if (!tb[NL80211_TXQ_ATTR_AC] || !tb[NL80211_TXQ_ATTR_TXOP] ||
Jouni Malinen31888482008-10-30 16:59:24 +02001825 !tb[NL80211_TXQ_ATTR_CWMIN] || !tb[NL80211_TXQ_ATTR_CWMAX] ||
1826 !tb[NL80211_TXQ_ATTR_AIFS])
1827 return -EINVAL;
1828
Johannes Berga3304b02012-03-28 11:04:24 +02001829 txq_params->ac = nla_get_u8(tb[NL80211_TXQ_ATTR_AC]);
Jouni Malinen31888482008-10-30 16:59:24 +02001830 txq_params->txop = nla_get_u16(tb[NL80211_TXQ_ATTR_TXOP]);
1831 txq_params->cwmin = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMIN]);
1832 txq_params->cwmax = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMAX]);
1833 txq_params->aifs = nla_get_u8(tb[NL80211_TXQ_ATTR_AIFS]);
1834
Johannes Berga3304b02012-03-28 11:04:24 +02001835 if (txq_params->ac >= NL80211_NUM_ACS)
1836 return -EINVAL;
1837
Jouni Malinen31888482008-10-30 16:59:24 +02001838 return 0;
1839}
1840
Johannes Bergf444de02010-05-05 15:25:02 +02001841static bool nl80211_can_set_dev_channel(struct wireless_dev *wdev)
1842{
1843 /*
Johannes Bergcc1d2802012-05-16 23:50:20 +02001844 * You can only set the channel explicitly for WDS interfaces,
1845 * all others have their channel managed via their respective
1846 * "establish a connection" command (connect, join, ...)
1847 *
1848 * For AP/GO and mesh mode, the channel can be set with the
1849 * channel userspace API, but is only stored and passed to the
1850 * low-level driver when the AP starts or the mesh is joined.
1851 * This is for backward compatibility, userspace can also give
1852 * the channel in the start-ap or join-mesh commands instead.
Johannes Bergf444de02010-05-05 15:25:02 +02001853 *
1854 * Monitors are special as they are normally slaved to
Johannes Berge8c9bd52012-06-06 08:18:22 +02001855 * whatever else is going on, so they have their own special
1856 * operation to set the monitor channel if possible.
Johannes Bergf444de02010-05-05 15:25:02 +02001857 */
1858 return !wdev ||
1859 wdev->iftype == NL80211_IFTYPE_AP ||
Johannes Bergf444de02010-05-05 15:25:02 +02001860 wdev->iftype == NL80211_IFTYPE_MESH_POINT ||
Johannes Berg074ac8d2010-09-16 14:58:22 +02001861 wdev->iftype == NL80211_IFTYPE_MONITOR ||
1862 wdev->iftype == NL80211_IFTYPE_P2P_GO;
Johannes Bergf444de02010-05-05 15:25:02 +02001863}
1864
Johannes Berg683b6d32012-11-08 21:25:48 +01001865static int nl80211_parse_chandef(struct cfg80211_registered_device *rdev,
1866 struct genl_info *info,
1867 struct cfg80211_chan_def *chandef)
1868{
Mahesh Paliveladbeca2e2012-11-29 14:11:07 +05301869 u32 control_freq;
Johannes Berg683b6d32012-11-08 21:25:48 +01001870
1871 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ])
1872 return -EINVAL;
1873
1874 control_freq = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]);
1875
1876 chandef->chan = ieee80211_get_channel(&rdev->wiphy, control_freq);
Johannes Berg3d9d1d62012-11-08 23:14:50 +01001877 chandef->width = NL80211_CHAN_WIDTH_20_NOHT;
1878 chandef->center_freq1 = control_freq;
1879 chandef->center_freq2 = 0;
Johannes Berg683b6d32012-11-08 21:25:48 +01001880
1881 /* Primary channel not allowed */
1882 if (!chandef->chan || chandef->chan->flags & IEEE80211_CHAN_DISABLED)
1883 return -EINVAL;
1884
Johannes Berg3d9d1d62012-11-08 23:14:50 +01001885 if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]) {
1886 enum nl80211_channel_type chantype;
Johannes Berg683b6d32012-11-08 21:25:48 +01001887
Johannes Berg3d9d1d62012-11-08 23:14:50 +01001888 chantype = nla_get_u32(
1889 info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]);
1890
1891 switch (chantype) {
1892 case NL80211_CHAN_NO_HT:
1893 case NL80211_CHAN_HT20:
1894 case NL80211_CHAN_HT40PLUS:
1895 case NL80211_CHAN_HT40MINUS:
1896 cfg80211_chandef_create(chandef, chandef->chan,
1897 chantype);
1898 break;
1899 default:
Johannes Berg683b6d32012-11-08 21:25:48 +01001900 return -EINVAL;
Johannes Berg683b6d32012-11-08 21:25:48 +01001901 }
Johannes Berg3d9d1d62012-11-08 23:14:50 +01001902 } else if (info->attrs[NL80211_ATTR_CHANNEL_WIDTH]) {
1903 chandef->width =
1904 nla_get_u32(info->attrs[NL80211_ATTR_CHANNEL_WIDTH]);
1905 if (info->attrs[NL80211_ATTR_CENTER_FREQ1])
1906 chandef->center_freq1 =
1907 nla_get_u32(
1908 info->attrs[NL80211_ATTR_CENTER_FREQ1]);
1909 if (info->attrs[NL80211_ATTR_CENTER_FREQ2])
1910 chandef->center_freq2 =
1911 nla_get_u32(
1912 info->attrs[NL80211_ATTR_CENTER_FREQ2]);
1913 }
1914
Johannes Berg9f5e8f62012-11-22 16:59:45 +01001915 if (!cfg80211_chandef_valid(chandef))
Johannes Berg3d9d1d62012-11-08 23:14:50 +01001916 return -EINVAL;
1917
Johannes Berg9f5e8f62012-11-22 16:59:45 +01001918 if (!cfg80211_chandef_usable(&rdev->wiphy, chandef,
1919 IEEE80211_CHAN_DISABLED))
Johannes Berg3d9d1d62012-11-08 23:14:50 +01001920 return -EINVAL;
Johannes Berg3d9d1d62012-11-08 23:14:50 +01001921
Simon Wunderlich2f301ab2013-05-16 13:00:28 +02001922 if ((chandef->width == NL80211_CHAN_WIDTH_5 ||
1923 chandef->width == NL80211_CHAN_WIDTH_10) &&
1924 !(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_5_10_MHZ))
1925 return -EINVAL;
1926
Johannes Berg683b6d32012-11-08 21:25:48 +01001927 return 0;
1928}
1929
Johannes Bergf444de02010-05-05 15:25:02 +02001930static int __nl80211_set_channel(struct cfg80211_registered_device *rdev,
Jouni Malinene16821b2014-04-28 11:22:08 +03001931 struct net_device *dev,
Johannes Bergf444de02010-05-05 15:25:02 +02001932 struct genl_info *info)
1933{
Johannes Berg683b6d32012-11-08 21:25:48 +01001934 struct cfg80211_chan_def chandef;
Johannes Bergf444de02010-05-05 15:25:02 +02001935 int result;
Johannes Berge8c9bd52012-06-06 08:18:22 +02001936 enum nl80211_iftype iftype = NL80211_IFTYPE_MONITOR;
Jouni Malinene16821b2014-04-28 11:22:08 +03001937 struct wireless_dev *wdev = NULL;
Johannes Berge8c9bd52012-06-06 08:18:22 +02001938
Jouni Malinene16821b2014-04-28 11:22:08 +03001939 if (dev)
1940 wdev = dev->ieee80211_ptr;
Johannes Bergf444de02010-05-05 15:25:02 +02001941 if (!nl80211_can_set_dev_channel(wdev))
1942 return -EOPNOTSUPP;
Jouni Malinene16821b2014-04-28 11:22:08 +03001943 if (wdev)
1944 iftype = wdev->iftype;
Johannes Bergf444de02010-05-05 15:25:02 +02001945
Johannes Berg683b6d32012-11-08 21:25:48 +01001946 result = nl80211_parse_chandef(rdev, info, &chandef);
1947 if (result)
1948 return result;
Johannes Bergf444de02010-05-05 15:25:02 +02001949
Johannes Berge8c9bd52012-06-06 08:18:22 +02001950 switch (iftype) {
Johannes Bergaa430da2012-05-16 23:50:18 +02001951 case NL80211_IFTYPE_AP:
1952 case NL80211_IFTYPE_P2P_GO:
Ilan Peer174e0cd2014-02-23 09:13:01 +02001953 if (!cfg80211_reg_can_beacon(&rdev->wiphy, &chandef, iftype)) {
Johannes Bergaa430da2012-05-16 23:50:18 +02001954 result = -EINVAL;
1955 break;
1956 }
Jouni Malinene16821b2014-04-28 11:22:08 +03001957 if (wdev->beacon_interval) {
1958 if (!dev || !rdev->ops->set_ap_chanwidth ||
1959 !(rdev->wiphy.features &
1960 NL80211_FEATURE_AP_MODE_CHAN_WIDTH_CHANGE)) {
1961 result = -EBUSY;
1962 break;
1963 }
1964
1965 /* Only allow dynamic channel width changes */
1966 if (chandef.chan != wdev->preset_chandef.chan) {
1967 result = -EBUSY;
1968 break;
1969 }
1970 result = rdev_set_ap_chanwidth(rdev, dev, &chandef);
1971 if (result)
1972 break;
1973 }
Johannes Berg683b6d32012-11-08 21:25:48 +01001974 wdev->preset_chandef = chandef;
Johannes Bergaa430da2012-05-16 23:50:18 +02001975 result = 0;
1976 break;
Johannes Bergcc1d2802012-05-16 23:50:20 +02001977 case NL80211_IFTYPE_MESH_POINT:
Johannes Berg683b6d32012-11-08 21:25:48 +01001978 result = cfg80211_set_mesh_channel(rdev, wdev, &chandef);
Johannes Bergcc1d2802012-05-16 23:50:20 +02001979 break;
Johannes Berge8c9bd52012-06-06 08:18:22 +02001980 case NL80211_IFTYPE_MONITOR:
Johannes Berg683b6d32012-11-08 21:25:48 +01001981 result = cfg80211_set_monitor_channel(rdev, &chandef);
Johannes Berge8c9bd52012-06-06 08:18:22 +02001982 break;
Johannes Bergaa430da2012-05-16 23:50:18 +02001983 default:
Johannes Berge8c9bd52012-06-06 08:18:22 +02001984 result = -EINVAL;
Johannes Bergf444de02010-05-05 15:25:02 +02001985 }
Johannes Bergf444de02010-05-05 15:25:02 +02001986
1987 return result;
1988}
1989
1990static int nl80211_set_channel(struct sk_buff *skb, struct genl_info *info)
1991{
Johannes Berg4c476992010-10-04 21:36:35 +02001992 struct cfg80211_registered_device *rdev = info->user_ptr[0];
1993 struct net_device *netdev = info->user_ptr[1];
Johannes Bergf444de02010-05-05 15:25:02 +02001994
Jouni Malinene16821b2014-04-28 11:22:08 +03001995 return __nl80211_set_channel(rdev, netdev, info);
Johannes Bergf444de02010-05-05 15:25:02 +02001996}
1997
Bill Jordane8347eb2010-10-01 13:54:28 -04001998static int nl80211_set_wds_peer(struct sk_buff *skb, struct genl_info *info)
1999{
Johannes Berg43b19952010-10-07 13:10:30 +02002000 struct cfg80211_registered_device *rdev = info->user_ptr[0];
2001 struct net_device *dev = info->user_ptr[1];
2002 struct wireless_dev *wdev = dev->ieee80211_ptr;
Johannes Berg388ac772010-10-07 13:11:09 +02002003 const u8 *bssid;
Bill Jordane8347eb2010-10-01 13:54:28 -04002004
2005 if (!info->attrs[NL80211_ATTR_MAC])
2006 return -EINVAL;
2007
Johannes Berg43b19952010-10-07 13:10:30 +02002008 if (netif_running(dev))
2009 return -EBUSY;
Bill Jordane8347eb2010-10-01 13:54:28 -04002010
Johannes Berg43b19952010-10-07 13:10:30 +02002011 if (!rdev->ops->set_wds_peer)
2012 return -EOPNOTSUPP;
Bill Jordane8347eb2010-10-01 13:54:28 -04002013
Johannes Berg43b19952010-10-07 13:10:30 +02002014 if (wdev->iftype != NL80211_IFTYPE_WDS)
2015 return -EOPNOTSUPP;
Bill Jordane8347eb2010-10-01 13:54:28 -04002016
2017 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Hila Gonene35e4d22012-06-27 17:19:42 +03002018 return rdev_set_wds_peer(rdev, dev, bssid);
Bill Jordane8347eb2010-10-01 13:54:28 -04002019}
2020
2021
Johannes Berg55682962007-09-20 13:09:35 -04002022static int nl80211_set_wiphy(struct sk_buff *skb, struct genl_info *info)
2023{
2024 struct cfg80211_registered_device *rdev;
Johannes Bergf444de02010-05-05 15:25:02 +02002025 struct net_device *netdev = NULL;
2026 struct wireless_dev *wdev;
Bill Jordana1e567c2010-09-10 11:22:32 -04002027 int result = 0, rem_txq_params = 0;
Jouni Malinen31888482008-10-30 16:59:24 +02002028 struct nlattr *nl_txq_params;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002029 u32 changed;
2030 u8 retry_short = 0, retry_long = 0;
2031 u32 frag_threshold = 0, rts_threshold = 0;
Lukáš Turek81077e82009-12-21 22:50:47 +01002032 u8 coverage_class = 0;
Johannes Berg55682962007-09-20 13:09:35 -04002033
Johannes Berg5fe231e2013-05-08 21:45:15 +02002034 ASSERT_RTNL();
2035
Johannes Bergf444de02010-05-05 15:25:02 +02002036 /*
2037 * Try to find the wiphy and netdev. Normally this
2038 * function shouldn't need the netdev, but this is
2039 * done for backward compatibility -- previously
2040 * setting the channel was done per wiphy, but now
2041 * it is per netdev. Previous userland like hostapd
2042 * also passed a netdev to set_wiphy, so that it is
2043 * possible to let that go to the right netdev!
2044 */
Johannes Berg4bbf4d52009-03-24 09:35:46 +01002045
Johannes Bergf444de02010-05-05 15:25:02 +02002046 if (info->attrs[NL80211_ATTR_IFINDEX]) {
2047 int ifindex = nla_get_u32(info->attrs[NL80211_ATTR_IFINDEX]);
2048
Ying Xue7f2b8562014-01-15 10:23:45 +08002049 netdev = __dev_get_by_index(genl_info_net(info), ifindex);
Johannes Berg5fe231e2013-05-08 21:45:15 +02002050 if (netdev && netdev->ieee80211_ptr)
Zhao, Gangf26cbf42014-04-21 12:53:03 +08002051 rdev = wiphy_to_rdev(netdev->ieee80211_ptr->wiphy);
Johannes Berg5fe231e2013-05-08 21:45:15 +02002052 else
Johannes Bergf444de02010-05-05 15:25:02 +02002053 netdev = NULL;
Johannes Berg4bbf4d52009-03-24 09:35:46 +01002054 }
2055
Johannes Bergf444de02010-05-05 15:25:02 +02002056 if (!netdev) {
Johannes Berg878d9ec2012-06-15 14:18:32 +02002057 rdev = __cfg80211_rdev_from_attrs(genl_info_net(info),
2058 info->attrs);
Johannes Berg5fe231e2013-05-08 21:45:15 +02002059 if (IS_ERR(rdev))
Johannes Berg4c476992010-10-04 21:36:35 +02002060 return PTR_ERR(rdev);
Johannes Bergf444de02010-05-05 15:25:02 +02002061 wdev = NULL;
2062 netdev = NULL;
2063 result = 0;
Johannes Berg71fe96b2012-10-24 10:04:58 +02002064 } else
Johannes Bergf444de02010-05-05 15:25:02 +02002065 wdev = netdev->ieee80211_ptr;
Johannes Bergf444de02010-05-05 15:25:02 +02002066
2067 /*
2068 * end workaround code, by now the rdev is available
2069 * and locked, and wdev may or may not be NULL.
2070 */
Johannes Berg4bbf4d52009-03-24 09:35:46 +01002071
2072 if (info->attrs[NL80211_ATTR_WIPHY_NAME])
Jouni Malinen31888482008-10-30 16:59:24 +02002073 result = cfg80211_dev_rename(
2074 rdev, nla_data(info->attrs[NL80211_ATTR_WIPHY_NAME]));
Johannes Berg4bbf4d52009-03-24 09:35:46 +01002075
Johannes Berg4bbf4d52009-03-24 09:35:46 +01002076 if (result)
Ying Xue7f2b8562014-01-15 10:23:45 +08002077 return result;
Johannes Berg55682962007-09-20 13:09:35 -04002078
Jouni Malinen31888482008-10-30 16:59:24 +02002079 if (info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS]) {
2080 struct ieee80211_txq_params txq_params;
2081 struct nlattr *tb[NL80211_TXQ_ATTR_MAX + 1];
2082
Ying Xue7f2b8562014-01-15 10:23:45 +08002083 if (!rdev->ops->set_txq_params)
2084 return -EOPNOTSUPP;
Jouni Malinen31888482008-10-30 16:59:24 +02002085
Ying Xue7f2b8562014-01-15 10:23:45 +08002086 if (!netdev)
2087 return -EINVAL;
Eliad Pellerf70f01c2011-09-25 20:06:53 +03002088
Johannes Berg133a3ff2011-11-03 14:50:13 +01002089 if (netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
Ying Xue7f2b8562014-01-15 10:23:45 +08002090 netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
2091 return -EINVAL;
Johannes Berg133a3ff2011-11-03 14:50:13 +01002092
Ying Xue7f2b8562014-01-15 10:23:45 +08002093 if (!netif_running(netdev))
2094 return -ENETDOWN;
Johannes Berg2b5f8b02012-04-02 10:51:55 +02002095
Jouni Malinen31888482008-10-30 16:59:24 +02002096 nla_for_each_nested(nl_txq_params,
2097 info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS],
2098 rem_txq_params) {
Johannes Bergae811e22014-01-24 10:17:47 +01002099 result = nla_parse(tb, NL80211_TXQ_ATTR_MAX,
2100 nla_data(nl_txq_params),
2101 nla_len(nl_txq_params),
2102 txq_params_policy);
2103 if (result)
2104 return result;
Jouni Malinen31888482008-10-30 16:59:24 +02002105 result = parse_txq_params(tb, &txq_params);
2106 if (result)
Ying Xue7f2b8562014-01-15 10:23:45 +08002107 return result;
Jouni Malinen31888482008-10-30 16:59:24 +02002108
Hila Gonene35e4d22012-06-27 17:19:42 +03002109 result = rdev_set_txq_params(rdev, netdev,
2110 &txq_params);
Jouni Malinen31888482008-10-30 16:59:24 +02002111 if (result)
Ying Xue7f2b8562014-01-15 10:23:45 +08002112 return result;
Jouni Malinen31888482008-10-30 16:59:24 +02002113 }
2114 }
2115
Jouni Malinen72bdcf32008-11-26 16:15:24 +02002116 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
Jouni Malinene16821b2014-04-28 11:22:08 +03002117 result = __nl80211_set_channel(
2118 rdev,
2119 nl80211_can_set_dev_channel(wdev) ? netdev : NULL,
2120 info);
Jouni Malinen72bdcf32008-11-26 16:15:24 +02002121 if (result)
Ying Xue7f2b8562014-01-15 10:23:45 +08002122 return result;
Jouni Malinen72bdcf32008-11-26 16:15:24 +02002123 }
2124
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03002125 if (info->attrs[NL80211_ATTR_WIPHY_TX_POWER_SETTING]) {
Johannes Bergc8442112012-10-24 10:17:18 +02002126 struct wireless_dev *txp_wdev = wdev;
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03002127 enum nl80211_tx_power_setting type;
2128 int idx, mbm = 0;
2129
Johannes Bergc8442112012-10-24 10:17:18 +02002130 if (!(rdev->wiphy.features & NL80211_FEATURE_VIF_TXPOWER))
2131 txp_wdev = NULL;
2132
Ying Xue7f2b8562014-01-15 10:23:45 +08002133 if (!rdev->ops->set_tx_power)
2134 return -EOPNOTSUPP;
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03002135
2136 idx = NL80211_ATTR_WIPHY_TX_POWER_SETTING;
2137 type = nla_get_u32(info->attrs[idx]);
2138
2139 if (!info->attrs[NL80211_ATTR_WIPHY_TX_POWER_LEVEL] &&
Ying Xue7f2b8562014-01-15 10:23:45 +08002140 (type != NL80211_TX_POWER_AUTOMATIC))
2141 return -EINVAL;
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03002142
2143 if (type != NL80211_TX_POWER_AUTOMATIC) {
2144 idx = NL80211_ATTR_WIPHY_TX_POWER_LEVEL;
2145 mbm = nla_get_u32(info->attrs[idx]);
2146 }
2147
Johannes Bergc8442112012-10-24 10:17:18 +02002148 result = rdev_set_tx_power(rdev, txp_wdev, type, mbm);
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03002149 if (result)
Ying Xue7f2b8562014-01-15 10:23:45 +08002150 return result;
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03002151 }
2152
Bruno Randolfafe0cbf2010-11-10 12:50:50 +09002153 if (info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX] &&
2154 info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]) {
2155 u32 tx_ant, rx_ant;
Bruno Randolf7f531e02010-12-16 11:30:22 +09002156 if ((!rdev->wiphy.available_antennas_tx &&
2157 !rdev->wiphy.available_antennas_rx) ||
Ying Xue7f2b8562014-01-15 10:23:45 +08002158 !rdev->ops->set_antenna)
2159 return -EOPNOTSUPP;
Bruno Randolfafe0cbf2010-11-10 12:50:50 +09002160
2161 tx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX]);
2162 rx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]);
2163
Bruno Randolfa7ffac92010-12-08 13:59:24 +09002164 /* reject antenna configurations which don't match the
Bruno Randolf7f531e02010-12-16 11:30:22 +09002165 * available antenna masks, except for the "all" mask */
2166 if ((~tx_ant && (tx_ant & ~rdev->wiphy.available_antennas_tx)) ||
Ying Xue7f2b8562014-01-15 10:23:45 +08002167 (~rx_ant && (rx_ant & ~rdev->wiphy.available_antennas_rx)))
2168 return -EINVAL;
Bruno Randolfa7ffac92010-12-08 13:59:24 +09002169
Bruno Randolf7f531e02010-12-16 11:30:22 +09002170 tx_ant = tx_ant & rdev->wiphy.available_antennas_tx;
2171 rx_ant = rx_ant & rdev->wiphy.available_antennas_rx;
Bruno Randolfa7ffac92010-12-08 13:59:24 +09002172
Hila Gonene35e4d22012-06-27 17:19:42 +03002173 result = rdev_set_antenna(rdev, tx_ant, rx_ant);
Bruno Randolfafe0cbf2010-11-10 12:50:50 +09002174 if (result)
Ying Xue7f2b8562014-01-15 10:23:45 +08002175 return result;
Bruno Randolfafe0cbf2010-11-10 12:50:50 +09002176 }
2177
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002178 changed = 0;
2179
2180 if (info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]) {
2181 retry_short = nla_get_u8(
2182 info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]);
Ying Xue7f2b8562014-01-15 10:23:45 +08002183 if (retry_short == 0)
2184 return -EINVAL;
2185
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002186 changed |= WIPHY_PARAM_RETRY_SHORT;
2187 }
2188
2189 if (info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]) {
2190 retry_long = nla_get_u8(
2191 info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]);
Ying Xue7f2b8562014-01-15 10:23:45 +08002192 if (retry_long == 0)
2193 return -EINVAL;
2194
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002195 changed |= WIPHY_PARAM_RETRY_LONG;
2196 }
2197
2198 if (info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]) {
2199 frag_threshold = nla_get_u32(
2200 info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]);
Ying Xue7f2b8562014-01-15 10:23:45 +08002201 if (frag_threshold < 256)
2202 return -EINVAL;
2203
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002204 if (frag_threshold != (u32) -1) {
2205 /*
2206 * Fragments (apart from the last one) are required to
2207 * have even length. Make the fragmentation code
2208 * simpler by stripping LSB should someone try to use
2209 * odd threshold value.
2210 */
2211 frag_threshold &= ~0x1;
2212 }
2213 changed |= WIPHY_PARAM_FRAG_THRESHOLD;
2214 }
2215
2216 if (info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]) {
2217 rts_threshold = nla_get_u32(
2218 info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]);
2219 changed |= WIPHY_PARAM_RTS_THRESHOLD;
2220 }
2221
Lukáš Turek81077e82009-12-21 22:50:47 +01002222 if (info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]) {
2223 coverage_class = nla_get_u8(
2224 info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]);
2225 changed |= WIPHY_PARAM_COVERAGE_CLASS;
2226 }
2227
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002228 if (changed) {
2229 u8 old_retry_short, old_retry_long;
2230 u32 old_frag_threshold, old_rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01002231 u8 old_coverage_class;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002232
Ying Xue7f2b8562014-01-15 10:23:45 +08002233 if (!rdev->ops->set_wiphy_params)
2234 return -EOPNOTSUPP;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002235
2236 old_retry_short = rdev->wiphy.retry_short;
2237 old_retry_long = rdev->wiphy.retry_long;
2238 old_frag_threshold = rdev->wiphy.frag_threshold;
2239 old_rts_threshold = rdev->wiphy.rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01002240 old_coverage_class = rdev->wiphy.coverage_class;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002241
2242 if (changed & WIPHY_PARAM_RETRY_SHORT)
2243 rdev->wiphy.retry_short = retry_short;
2244 if (changed & WIPHY_PARAM_RETRY_LONG)
2245 rdev->wiphy.retry_long = retry_long;
2246 if (changed & WIPHY_PARAM_FRAG_THRESHOLD)
2247 rdev->wiphy.frag_threshold = frag_threshold;
2248 if (changed & WIPHY_PARAM_RTS_THRESHOLD)
2249 rdev->wiphy.rts_threshold = rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01002250 if (changed & WIPHY_PARAM_COVERAGE_CLASS)
2251 rdev->wiphy.coverage_class = coverage_class;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002252
Hila Gonene35e4d22012-06-27 17:19:42 +03002253 result = rdev_set_wiphy_params(rdev, changed);
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002254 if (result) {
2255 rdev->wiphy.retry_short = old_retry_short;
2256 rdev->wiphy.retry_long = old_retry_long;
2257 rdev->wiphy.frag_threshold = old_frag_threshold;
2258 rdev->wiphy.rts_threshold = old_rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01002259 rdev->wiphy.coverage_class = old_coverage_class;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002260 }
2261 }
Ying Xue7f2b8562014-01-15 10:23:45 +08002262 return 0;
Johannes Berg55682962007-09-20 13:09:35 -04002263}
2264
Johannes Berg71bbc992012-06-15 15:30:18 +02002265static inline u64 wdev_id(struct wireless_dev *wdev)
2266{
2267 return (u64)wdev->identifier |
Zhao, Gangf26cbf42014-04-21 12:53:03 +08002268 ((u64)wiphy_to_rdev(wdev->wiphy)->wiphy_idx << 32);
Johannes Berg71bbc992012-06-15 15:30:18 +02002269}
Johannes Berg55682962007-09-20 13:09:35 -04002270
Johannes Berg683b6d32012-11-08 21:25:48 +01002271static int nl80211_send_chandef(struct sk_buff *msg,
Janusz Dziedzicd2859df2013-11-06 13:55:51 +01002272 const struct cfg80211_chan_def *chandef)
Johannes Berg683b6d32012-11-08 21:25:48 +01002273{
Johannes Berg9f5e8f62012-11-22 16:59:45 +01002274 WARN_ON(!cfg80211_chandef_valid(chandef));
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002275
Johannes Berg683b6d32012-11-08 21:25:48 +01002276 if (nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ,
2277 chandef->chan->center_freq))
2278 return -ENOBUFS;
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002279 switch (chandef->width) {
2280 case NL80211_CHAN_WIDTH_20_NOHT:
2281 case NL80211_CHAN_WIDTH_20:
2282 case NL80211_CHAN_WIDTH_40:
2283 if (nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE,
2284 cfg80211_get_chandef_type(chandef)))
2285 return -ENOBUFS;
2286 break;
2287 default:
2288 break;
2289 }
2290 if (nla_put_u32(msg, NL80211_ATTR_CHANNEL_WIDTH, chandef->width))
2291 return -ENOBUFS;
2292 if (nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ1, chandef->center_freq1))
2293 return -ENOBUFS;
2294 if (chandef->center_freq2 &&
2295 nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ2, chandef->center_freq2))
Johannes Berg683b6d32012-11-08 21:25:48 +01002296 return -ENOBUFS;
2297 return 0;
2298}
2299
Eric W. Biederman15e47302012-09-07 20:12:54 +00002300static int nl80211_send_iface(struct sk_buff *msg, u32 portid, u32 seq, int flags,
Johannes Bergd7264052009-04-19 16:23:20 +02002301 struct cfg80211_registered_device *rdev,
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002302 struct wireless_dev *wdev)
Johannes Berg55682962007-09-20 13:09:35 -04002303{
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002304 struct net_device *dev = wdev->netdev;
Johannes Berg55682962007-09-20 13:09:35 -04002305 void *hdr;
2306
Eric W. Biederman15e47302012-09-07 20:12:54 +00002307 hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_INTERFACE);
Johannes Berg55682962007-09-20 13:09:35 -04002308 if (!hdr)
2309 return -1;
2310
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002311 if (dev &&
2312 (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
Johannes Berg98104fde2012-06-16 00:19:54 +02002313 nla_put_string(msg, NL80211_ATTR_IFNAME, dev->name)))
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002314 goto nla_put_failure;
2315
2316 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
2317 nla_put_u32(msg, NL80211_ATTR_IFTYPE, wdev->iftype) ||
Johannes Berg71bbc992012-06-15 15:30:18 +02002318 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) ||
Johannes Berg98104fde2012-06-16 00:19:54 +02002319 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, wdev_address(wdev)) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04002320 nla_put_u32(msg, NL80211_ATTR_GENERATION,
2321 rdev->devlist_generation ^
2322 (cfg80211_rdev_list_generation << 2)))
2323 goto nla_put_failure;
Johannes Bergf5ea9122009-08-07 16:17:38 +02002324
Johannes Berg5b7ccaf2012-07-12 19:45:08 +02002325 if (rdev->ops->get_channel) {
Johannes Berg683b6d32012-11-08 21:25:48 +01002326 int ret;
2327 struct cfg80211_chan_def chandef;
Johannes Berg5b7ccaf2012-07-12 19:45:08 +02002328
Johannes Berg683b6d32012-11-08 21:25:48 +01002329 ret = rdev_get_channel(rdev, wdev, &chandef);
2330 if (ret == 0) {
2331 if (nl80211_send_chandef(msg, &chandef))
2332 goto nla_put_failure;
2333 }
Pontus Fuchsd91df0e2012-04-03 16:39:58 +02002334 }
2335
Antonio Quartullib84e7a02012-11-07 12:52:20 +01002336 if (wdev->ssid_len) {
2337 if (nla_put(msg, NL80211_ATTR_SSID, wdev->ssid_len, wdev->ssid))
2338 goto nla_put_failure;
2339 }
2340
Johannes Berg55682962007-09-20 13:09:35 -04002341 return genlmsg_end(msg, hdr);
2342
2343 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07002344 genlmsg_cancel(msg, hdr);
2345 return -EMSGSIZE;
Johannes Berg55682962007-09-20 13:09:35 -04002346}
2347
2348static int nl80211_dump_interface(struct sk_buff *skb, struct netlink_callback *cb)
2349{
2350 int wp_idx = 0;
2351 int if_idx = 0;
2352 int wp_start = cb->args[0];
2353 int if_start = cb->args[1];
Johannes Bergf5ea9122009-08-07 16:17:38 +02002354 struct cfg80211_registered_device *rdev;
Johannes Berg55682962007-09-20 13:09:35 -04002355 struct wireless_dev *wdev;
2356
Johannes Berg5fe231e2013-05-08 21:45:15 +02002357 rtnl_lock();
Johannes Bergf5ea9122009-08-07 16:17:38 +02002358 list_for_each_entry(rdev, &cfg80211_rdev_list, list) {
2359 if (!net_eq(wiphy_net(&rdev->wiphy), sock_net(skb->sk)))
Johannes Berg463d0182009-07-14 00:33:35 +02002360 continue;
Johannes Bergbba95fe2008-07-29 13:22:51 +02002361 if (wp_idx < wp_start) {
2362 wp_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04002363 continue;
Johannes Bergbba95fe2008-07-29 13:22:51 +02002364 }
Johannes Berg55682962007-09-20 13:09:35 -04002365 if_idx = 0;
2366
Johannes Berg89a54e42012-06-15 14:33:17 +02002367 list_for_each_entry(wdev, &rdev->wdev_list, list) {
Johannes Bergbba95fe2008-07-29 13:22:51 +02002368 if (if_idx < if_start) {
2369 if_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04002370 continue;
Johannes Bergbba95fe2008-07-29 13:22:51 +02002371 }
Eric W. Biederman15e47302012-09-07 20:12:54 +00002372 if (nl80211_send_iface(skb, NETLINK_CB(cb->skb).portid,
Johannes Berg55682962007-09-20 13:09:35 -04002373 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002374 rdev, wdev) < 0) {
Johannes Bergbba95fe2008-07-29 13:22:51 +02002375 goto out;
2376 }
2377 if_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04002378 }
Johannes Bergbba95fe2008-07-29 13:22:51 +02002379
2380 wp_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04002381 }
Johannes Bergbba95fe2008-07-29 13:22:51 +02002382 out:
Johannes Berg5fe231e2013-05-08 21:45:15 +02002383 rtnl_unlock();
Johannes Berg55682962007-09-20 13:09:35 -04002384
2385 cb->args[0] = wp_idx;
2386 cb->args[1] = if_idx;
2387
2388 return skb->len;
2389}
2390
2391static int nl80211_get_interface(struct sk_buff *skb, struct genl_info *info)
2392{
2393 struct sk_buff *msg;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002394 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002395 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg55682962007-09-20 13:09:35 -04002396
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07002397 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -04002398 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02002399 return -ENOMEM;
Johannes Berg55682962007-09-20 13:09:35 -04002400
Eric W. Biederman15e47302012-09-07 20:12:54 +00002401 if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002402 rdev, wdev) < 0) {
Johannes Berg4c476992010-10-04 21:36:35 +02002403 nlmsg_free(msg);
2404 return -ENOBUFS;
2405 }
Johannes Berg55682962007-09-20 13:09:35 -04002406
Johannes Berg134e6372009-07-10 09:51:34 +00002407 return genlmsg_reply(msg, info);
Johannes Berg55682962007-09-20 13:09:35 -04002408}
2409
Michael Wu66f7ac52008-01-31 19:48:22 +01002410static const struct nla_policy mntr_flags_policy[NL80211_MNTR_FLAG_MAX + 1] = {
2411 [NL80211_MNTR_FLAG_FCSFAIL] = { .type = NLA_FLAG },
2412 [NL80211_MNTR_FLAG_PLCPFAIL] = { .type = NLA_FLAG },
2413 [NL80211_MNTR_FLAG_CONTROL] = { .type = NLA_FLAG },
2414 [NL80211_MNTR_FLAG_OTHER_BSS] = { .type = NLA_FLAG },
2415 [NL80211_MNTR_FLAG_COOK_FRAMES] = { .type = NLA_FLAG },
Felix Fietkaue057d3c2013-05-28 13:01:52 +02002416 [NL80211_MNTR_FLAG_ACTIVE] = { .type = NLA_FLAG },
Michael Wu66f7ac52008-01-31 19:48:22 +01002417};
2418
2419static int parse_monitor_flags(struct nlattr *nla, u32 *mntrflags)
2420{
2421 struct nlattr *flags[NL80211_MNTR_FLAG_MAX + 1];
2422 int flag;
2423
2424 *mntrflags = 0;
2425
2426 if (!nla)
2427 return -EINVAL;
2428
2429 if (nla_parse_nested(flags, NL80211_MNTR_FLAG_MAX,
2430 nla, mntr_flags_policy))
2431 return -EINVAL;
2432
2433 for (flag = 1; flag <= NL80211_MNTR_FLAG_MAX; flag++)
2434 if (flags[flag])
2435 *mntrflags |= (1<<flag);
2436
2437 return 0;
2438}
2439
Johannes Berg9bc383d2009-11-19 11:55:19 +01002440static int nl80211_valid_4addr(struct cfg80211_registered_device *rdev,
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002441 struct net_device *netdev, u8 use_4addr,
2442 enum nl80211_iftype iftype)
Johannes Berg9bc383d2009-11-19 11:55:19 +01002443{
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002444 if (!use_4addr) {
Jiri Pirkof350a0a82010-06-15 06:50:45 +00002445 if (netdev && (netdev->priv_flags & IFF_BRIDGE_PORT))
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002446 return -EBUSY;
Johannes Berg9bc383d2009-11-19 11:55:19 +01002447 return 0;
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002448 }
Johannes Berg9bc383d2009-11-19 11:55:19 +01002449
2450 switch (iftype) {
2451 case NL80211_IFTYPE_AP_VLAN:
2452 if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_AP)
2453 return 0;
2454 break;
2455 case NL80211_IFTYPE_STATION:
2456 if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_STATION)
2457 return 0;
2458 break;
2459 default:
2460 break;
2461 }
2462
2463 return -EOPNOTSUPP;
2464}
2465
Johannes Berg55682962007-09-20 13:09:35 -04002466static int nl80211_set_interface(struct sk_buff *skb, struct genl_info *info)
2467{
Johannes Berg4c476992010-10-04 21:36:35 +02002468 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002469 struct vif_params params;
Johannes Berge36d56b2009-06-09 21:04:43 +02002470 int err;
Johannes Berg04a773a2009-04-19 21:24:32 +02002471 enum nl80211_iftype otype, ntype;
Johannes Berg4c476992010-10-04 21:36:35 +02002472 struct net_device *dev = info->user_ptr[1];
Johannes Berg92ffe052008-09-16 20:39:36 +02002473 u32 _flags, *flags = NULL;
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002474 bool change = false;
Johannes Berg55682962007-09-20 13:09:35 -04002475
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002476 memset(&params, 0, sizeof(params));
2477
Johannes Berg04a773a2009-04-19 21:24:32 +02002478 otype = ntype = dev->ieee80211_ptr->iftype;
Johannes Berg55682962007-09-20 13:09:35 -04002479
Johannes Berg723b0382008-09-16 20:22:09 +02002480 if (info->attrs[NL80211_ATTR_IFTYPE]) {
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002481 ntype = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]);
Johannes Berg04a773a2009-04-19 21:24:32 +02002482 if (otype != ntype)
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002483 change = true;
Johannes Berg4c476992010-10-04 21:36:35 +02002484 if (ntype > NL80211_IFTYPE_MAX)
2485 return -EINVAL;
Johannes Berg723b0382008-09-16 20:22:09 +02002486 }
2487
Johannes Berg92ffe052008-09-16 20:39:36 +02002488 if (info->attrs[NL80211_ATTR_MESH_ID]) {
Johannes Berg29cbe682010-12-03 09:20:44 +01002489 struct wireless_dev *wdev = dev->ieee80211_ptr;
2490
Johannes Berg4c476992010-10-04 21:36:35 +02002491 if (ntype != NL80211_IFTYPE_MESH_POINT)
2492 return -EINVAL;
Johannes Berg29cbe682010-12-03 09:20:44 +01002493 if (netif_running(dev))
2494 return -EBUSY;
2495
2496 wdev_lock(wdev);
2497 BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN !=
2498 IEEE80211_MAX_MESH_ID_LEN);
2499 wdev->mesh_id_up_len =
2500 nla_len(info->attrs[NL80211_ATTR_MESH_ID]);
2501 memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]),
2502 wdev->mesh_id_up_len);
2503 wdev_unlock(wdev);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002504 }
2505
Felix Fietkau8b787642009-11-10 18:53:10 +01002506 if (info->attrs[NL80211_ATTR_4ADDR]) {
2507 params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]);
2508 change = true;
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002509 err = nl80211_valid_4addr(rdev, dev, params.use_4addr, ntype);
Johannes Berg9bc383d2009-11-19 11:55:19 +01002510 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02002511 return err;
Felix Fietkau8b787642009-11-10 18:53:10 +01002512 } else {
2513 params.use_4addr = -1;
2514 }
2515
Johannes Berg92ffe052008-09-16 20:39:36 +02002516 if (info->attrs[NL80211_ATTR_MNTR_FLAGS]) {
Johannes Berg4c476992010-10-04 21:36:35 +02002517 if (ntype != NL80211_IFTYPE_MONITOR)
2518 return -EINVAL;
Johannes Berg92ffe052008-09-16 20:39:36 +02002519 err = parse_monitor_flags(info->attrs[NL80211_ATTR_MNTR_FLAGS],
2520 &_flags);
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002521 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02002522 return err;
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002523
2524 flags = &_flags;
2525 change = true;
Johannes Berg92ffe052008-09-16 20:39:36 +02002526 }
Johannes Berg3b858752009-03-12 09:55:09 +01002527
Luciano Coelho18003292013-08-29 13:26:57 +03002528 if (flags && (*flags & MONITOR_FLAG_ACTIVE) &&
Felix Fietkaue057d3c2013-05-28 13:01:52 +02002529 !(rdev->wiphy.features & NL80211_FEATURE_ACTIVE_MONITOR))
2530 return -EOPNOTSUPP;
2531
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002532 if (change)
Johannes Berg3d54d252009-08-21 14:51:05 +02002533 err = cfg80211_change_iface(rdev, dev, ntype, flags, &params);
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002534 else
2535 err = 0;
Johannes Berg60719ff2008-09-16 14:55:09 +02002536
Johannes Berg9bc383d2009-11-19 11:55:19 +01002537 if (!err && params.use_4addr != -1)
2538 dev->ieee80211_ptr->use_4addr = params.use_4addr;
2539
Johannes Berg55682962007-09-20 13:09:35 -04002540 return err;
2541}
2542
2543static int nl80211_new_interface(struct sk_buff *skb, struct genl_info *info)
2544{
Johannes Berg4c476992010-10-04 21:36:35 +02002545 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002546 struct vif_params params;
Johannes Berg84efbb82012-06-16 00:00:26 +02002547 struct wireless_dev *wdev;
Johannes Berg1c90f9d2012-06-16 00:05:37 +02002548 struct sk_buff *msg;
Johannes Berg55682962007-09-20 13:09:35 -04002549 int err;
2550 enum nl80211_iftype type = NL80211_IFTYPE_UNSPECIFIED;
Michael Wu66f7ac52008-01-31 19:48:22 +01002551 u32 flags;
Johannes Berg55682962007-09-20 13:09:35 -04002552
Johannes Berg78f22b62014-03-24 17:57:27 +01002553 /* to avoid failing a new interface creation due to pending removal */
2554 cfg80211_destroy_ifaces(rdev);
2555
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002556 memset(&params, 0, sizeof(params));
2557
Johannes Berg55682962007-09-20 13:09:35 -04002558 if (!info->attrs[NL80211_ATTR_IFNAME])
2559 return -EINVAL;
2560
2561 if (info->attrs[NL80211_ATTR_IFTYPE]) {
2562 type = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]);
2563 if (type > NL80211_IFTYPE_MAX)
2564 return -EINVAL;
2565 }
2566
Johannes Berg79c97e92009-07-07 03:56:12 +02002567 if (!rdev->ops->add_virtual_intf ||
Johannes Berg4c476992010-10-04 21:36:35 +02002568 !(rdev->wiphy.interface_modes & (1 << type)))
2569 return -EOPNOTSUPP;
Johannes Berg55682962007-09-20 13:09:35 -04002570
Arend van Spriel1c18f142013-01-08 10:17:27 +01002571 if (type == NL80211_IFTYPE_P2P_DEVICE && info->attrs[NL80211_ATTR_MAC]) {
2572 nla_memcpy(params.macaddr, info->attrs[NL80211_ATTR_MAC],
2573 ETH_ALEN);
2574 if (!is_valid_ether_addr(params.macaddr))
2575 return -EADDRNOTAVAIL;
2576 }
2577
Johannes Berg9bc383d2009-11-19 11:55:19 +01002578 if (info->attrs[NL80211_ATTR_4ADDR]) {
Felix Fietkau8b787642009-11-10 18:53:10 +01002579 params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]);
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002580 err = nl80211_valid_4addr(rdev, NULL, params.use_4addr, type);
Johannes Berg9bc383d2009-11-19 11:55:19 +01002581 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02002582 return err;
Johannes Berg9bc383d2009-11-19 11:55:19 +01002583 }
Felix Fietkau8b787642009-11-10 18:53:10 +01002584
Johannes Berg1c90f9d2012-06-16 00:05:37 +02002585 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
2586 if (!msg)
2587 return -ENOMEM;
2588
Michael Wu66f7ac52008-01-31 19:48:22 +01002589 err = parse_monitor_flags(type == NL80211_IFTYPE_MONITOR ?
2590 info->attrs[NL80211_ATTR_MNTR_FLAGS] : NULL,
2591 &flags);
Felix Fietkaue057d3c2013-05-28 13:01:52 +02002592
Luciano Coelho18003292013-08-29 13:26:57 +03002593 if (!err && (flags & MONITOR_FLAG_ACTIVE) &&
Felix Fietkaue057d3c2013-05-28 13:01:52 +02002594 !(rdev->wiphy.features & NL80211_FEATURE_ACTIVE_MONITOR))
2595 return -EOPNOTSUPP;
2596
Hila Gonene35e4d22012-06-27 17:19:42 +03002597 wdev = rdev_add_virtual_intf(rdev,
2598 nla_data(info->attrs[NL80211_ATTR_IFNAME]),
2599 type, err ? NULL : &flags, &params);
Johannes Berg1c90f9d2012-06-16 00:05:37 +02002600 if (IS_ERR(wdev)) {
2601 nlmsg_free(msg);
Johannes Berg84efbb82012-06-16 00:00:26 +02002602 return PTR_ERR(wdev);
Johannes Berg1c90f9d2012-06-16 00:05:37 +02002603 }
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002604
Johannes Berg78f22b62014-03-24 17:57:27 +01002605 if (info->attrs[NL80211_ATTR_IFACE_SOCKET_OWNER])
2606 wdev->owner_nlportid = info->snd_portid;
2607
Johannes Berg98104fde2012-06-16 00:19:54 +02002608 switch (type) {
2609 case NL80211_IFTYPE_MESH_POINT:
2610 if (!info->attrs[NL80211_ATTR_MESH_ID])
2611 break;
Johannes Berg29cbe682010-12-03 09:20:44 +01002612 wdev_lock(wdev);
2613 BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN !=
2614 IEEE80211_MAX_MESH_ID_LEN);
2615 wdev->mesh_id_up_len =
2616 nla_len(info->attrs[NL80211_ATTR_MESH_ID]);
2617 memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]),
2618 wdev->mesh_id_up_len);
2619 wdev_unlock(wdev);
Johannes Berg98104fde2012-06-16 00:19:54 +02002620 break;
2621 case NL80211_IFTYPE_P2P_DEVICE:
2622 /*
2623 * P2P Device doesn't have a netdev, so doesn't go
2624 * through the netdev notifier and must be added here
2625 */
2626 mutex_init(&wdev->mtx);
2627 INIT_LIST_HEAD(&wdev->event_list);
2628 spin_lock_init(&wdev->event_lock);
2629 INIT_LIST_HEAD(&wdev->mgmt_registrations);
2630 spin_lock_init(&wdev->mgmt_registrations_lock);
2631
Johannes Berg98104fde2012-06-16 00:19:54 +02002632 wdev->identifier = ++rdev->wdev_id;
2633 list_add_rcu(&wdev->list, &rdev->wdev_list);
2634 rdev->devlist_generation++;
Johannes Berg98104fde2012-06-16 00:19:54 +02002635 break;
2636 default:
2637 break;
Johannes Berg29cbe682010-12-03 09:20:44 +01002638 }
2639
Eric W. Biederman15e47302012-09-07 20:12:54 +00002640 if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berg1c90f9d2012-06-16 00:05:37 +02002641 rdev, wdev) < 0) {
2642 nlmsg_free(msg);
2643 return -ENOBUFS;
2644 }
2645
2646 return genlmsg_reply(msg, info);
Johannes Berg55682962007-09-20 13:09:35 -04002647}
2648
2649static int nl80211_del_interface(struct sk_buff *skb, struct genl_info *info)
2650{
Johannes Berg4c476992010-10-04 21:36:35 +02002651 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg84efbb82012-06-16 00:00:26 +02002652 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg55682962007-09-20 13:09:35 -04002653
Johannes Berg4c476992010-10-04 21:36:35 +02002654 if (!rdev->ops->del_virtual_intf)
2655 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01002656
Johannes Berg84efbb82012-06-16 00:00:26 +02002657 /*
2658 * If we remove a wireless device without a netdev then clear
2659 * user_ptr[1] so that nl80211_post_doit won't dereference it
2660 * to check if it needs to do dev_put(). Otherwise it crashes
2661 * since the wdev has been freed, unlike with a netdev where
2662 * we need the dev_put() for the netdev to really be freed.
2663 */
2664 if (!wdev->netdev)
2665 info->user_ptr[1] = NULL;
2666
Hila Gonene35e4d22012-06-27 17:19:42 +03002667 return rdev_del_virtual_intf(rdev, wdev);
Johannes Berg55682962007-09-20 13:09:35 -04002668}
2669
Simon Wunderlich1d9d9212011-11-18 14:20:43 +01002670static int nl80211_set_noack_map(struct sk_buff *skb, struct genl_info *info)
2671{
2672 struct cfg80211_registered_device *rdev = info->user_ptr[0];
2673 struct net_device *dev = info->user_ptr[1];
2674 u16 noack_map;
2675
2676 if (!info->attrs[NL80211_ATTR_NOACK_MAP])
2677 return -EINVAL;
2678
2679 if (!rdev->ops->set_noack_map)
2680 return -EOPNOTSUPP;
2681
2682 noack_map = nla_get_u16(info->attrs[NL80211_ATTR_NOACK_MAP]);
2683
Hila Gonene35e4d22012-06-27 17:19:42 +03002684 return rdev_set_noack_map(rdev, dev, noack_map);
Simon Wunderlich1d9d9212011-11-18 14:20:43 +01002685}
2686
Johannes Berg41ade002007-12-19 02:03:29 +01002687struct get_key_cookie {
2688 struct sk_buff *msg;
2689 int error;
Johannes Bergb9454e82009-07-08 13:29:08 +02002690 int idx;
Johannes Berg41ade002007-12-19 02:03:29 +01002691};
2692
2693static void get_key_callback(void *c, struct key_params *params)
2694{
Johannes Bergb9454e82009-07-08 13:29:08 +02002695 struct nlattr *key;
Johannes Berg41ade002007-12-19 02:03:29 +01002696 struct get_key_cookie *cookie = c;
2697
David S. Miller9360ffd2012-03-29 04:41:26 -04002698 if ((params->key &&
2699 nla_put(cookie->msg, NL80211_ATTR_KEY_DATA,
2700 params->key_len, params->key)) ||
2701 (params->seq &&
2702 nla_put(cookie->msg, NL80211_ATTR_KEY_SEQ,
2703 params->seq_len, params->seq)) ||
2704 (params->cipher &&
2705 nla_put_u32(cookie->msg, NL80211_ATTR_KEY_CIPHER,
2706 params->cipher)))
2707 goto nla_put_failure;
Johannes Berg41ade002007-12-19 02:03:29 +01002708
Johannes Bergb9454e82009-07-08 13:29:08 +02002709 key = nla_nest_start(cookie->msg, NL80211_ATTR_KEY);
2710 if (!key)
2711 goto nla_put_failure;
2712
David S. Miller9360ffd2012-03-29 04:41:26 -04002713 if ((params->key &&
2714 nla_put(cookie->msg, NL80211_KEY_DATA,
2715 params->key_len, params->key)) ||
2716 (params->seq &&
2717 nla_put(cookie->msg, NL80211_KEY_SEQ,
2718 params->seq_len, params->seq)) ||
2719 (params->cipher &&
2720 nla_put_u32(cookie->msg, NL80211_KEY_CIPHER,
2721 params->cipher)))
2722 goto nla_put_failure;
Johannes Bergb9454e82009-07-08 13:29:08 +02002723
David S. Miller9360ffd2012-03-29 04:41:26 -04002724 if (nla_put_u8(cookie->msg, NL80211_ATTR_KEY_IDX, cookie->idx))
2725 goto nla_put_failure;
Johannes Bergb9454e82009-07-08 13:29:08 +02002726
2727 nla_nest_end(cookie->msg, key);
2728
Johannes Berg41ade002007-12-19 02:03:29 +01002729 return;
2730 nla_put_failure:
2731 cookie->error = 1;
2732}
2733
2734static int nl80211_get_key(struct sk_buff *skb, struct genl_info *info)
2735{
Johannes Berg4c476992010-10-04 21:36:35 +02002736 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg41ade002007-12-19 02:03:29 +01002737 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02002738 struct net_device *dev = info->user_ptr[1];
Johannes Berg41ade002007-12-19 02:03:29 +01002739 u8 key_idx = 0;
Johannes Berge31b8212010-10-05 19:39:30 +02002740 const u8 *mac_addr = NULL;
2741 bool pairwise;
Johannes Berg41ade002007-12-19 02:03:29 +01002742 struct get_key_cookie cookie = {
2743 .error = 0,
2744 };
2745 void *hdr;
2746 struct sk_buff *msg;
2747
2748 if (info->attrs[NL80211_ATTR_KEY_IDX])
2749 key_idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]);
2750
Jouni Malinen3cfcf6ac2009-01-08 13:32:02 +02002751 if (key_idx > 5)
Johannes Berg41ade002007-12-19 02:03:29 +01002752 return -EINVAL;
2753
2754 if (info->attrs[NL80211_ATTR_MAC])
2755 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
2756
Johannes Berge31b8212010-10-05 19:39:30 +02002757 pairwise = !!mac_addr;
2758 if (info->attrs[NL80211_ATTR_KEY_TYPE]) {
2759 u32 kt = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]);
2760 if (kt >= NUM_NL80211_KEYTYPES)
2761 return -EINVAL;
2762 if (kt != NL80211_KEYTYPE_GROUP &&
2763 kt != NL80211_KEYTYPE_PAIRWISE)
2764 return -EINVAL;
2765 pairwise = kt == NL80211_KEYTYPE_PAIRWISE;
2766 }
2767
Johannes Berg4c476992010-10-04 21:36:35 +02002768 if (!rdev->ops->get_key)
2769 return -EOPNOTSUPP;
Johannes Berg41ade002007-12-19 02:03:29 +01002770
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07002771 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02002772 if (!msg)
2773 return -ENOMEM;
Johannes Berg41ade002007-12-19 02:03:29 +01002774
Eric W. Biederman15e47302012-09-07 20:12:54 +00002775 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berg41ade002007-12-19 02:03:29 +01002776 NL80211_CMD_NEW_KEY);
Dan Carpentercb35fba2013-08-14 14:50:01 +03002777 if (!hdr)
Johannes Berg9fe271a2013-10-25 11:15:12 +02002778 goto nla_put_failure;
Johannes Berg41ade002007-12-19 02:03:29 +01002779
2780 cookie.msg = msg;
Johannes Bergb9454e82009-07-08 13:29:08 +02002781 cookie.idx = key_idx;
Johannes Berg41ade002007-12-19 02:03:29 +01002782
David S. Miller9360ffd2012-03-29 04:41:26 -04002783 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
2784 nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_idx))
2785 goto nla_put_failure;
2786 if (mac_addr &&
2787 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr))
2788 goto nla_put_failure;
Johannes Berg41ade002007-12-19 02:03:29 +01002789
Johannes Berge31b8212010-10-05 19:39:30 +02002790 if (pairwise && mac_addr &&
2791 !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN))
2792 return -ENOENT;
2793
Hila Gonene35e4d22012-06-27 17:19:42 +03002794 err = rdev_get_key(rdev, dev, key_idx, pairwise, mac_addr, &cookie,
2795 get_key_callback);
Johannes Berg41ade002007-12-19 02:03:29 +01002796
2797 if (err)
Niko Jokinen6c95e2a2009-07-15 11:00:53 +03002798 goto free_msg;
Johannes Berg41ade002007-12-19 02:03:29 +01002799
2800 if (cookie.error)
2801 goto nla_put_failure;
2802
2803 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02002804 return genlmsg_reply(msg, info);
Johannes Berg41ade002007-12-19 02:03:29 +01002805
2806 nla_put_failure:
2807 err = -ENOBUFS;
Niko Jokinen6c95e2a2009-07-15 11:00:53 +03002808 free_msg:
Johannes Berg41ade002007-12-19 02:03:29 +01002809 nlmsg_free(msg);
Johannes Berg41ade002007-12-19 02:03:29 +01002810 return err;
2811}
2812
2813static int nl80211_set_key(struct sk_buff *skb, struct genl_info *info)
2814{
Johannes Berg4c476992010-10-04 21:36:35 +02002815 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Bergb9454e82009-07-08 13:29:08 +02002816 struct key_parse key;
Johannes Berg41ade002007-12-19 02:03:29 +01002817 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02002818 struct net_device *dev = info->user_ptr[1];
Johannes Berg41ade002007-12-19 02:03:29 +01002819
Johannes Bergb9454e82009-07-08 13:29:08 +02002820 err = nl80211_parse_key(info, &key);
2821 if (err)
2822 return err;
2823
2824 if (key.idx < 0)
Johannes Berg41ade002007-12-19 02:03:29 +01002825 return -EINVAL;
2826
Johannes Bergb9454e82009-07-08 13:29:08 +02002827 /* only support setting default key */
2828 if (!key.def && !key.defmgmt)
Johannes Berg41ade002007-12-19 02:03:29 +01002829 return -EINVAL;
2830
Johannes Bergfffd0932009-07-08 14:22:54 +02002831 wdev_lock(dev->ieee80211_ptr);
Johannes Bergdbd2fd62010-12-09 19:58:59 +01002832
2833 if (key.def) {
2834 if (!rdev->ops->set_default_key) {
2835 err = -EOPNOTSUPP;
2836 goto out;
2837 }
2838
2839 err = nl80211_key_allowed(dev->ieee80211_ptr);
2840 if (err)
2841 goto out;
2842
Hila Gonene35e4d22012-06-27 17:19:42 +03002843 err = rdev_set_default_key(rdev, dev, key.idx,
Johannes Bergdbd2fd62010-12-09 19:58:59 +01002844 key.def_uni, key.def_multi);
2845
2846 if (err)
2847 goto out;
Johannes Bergfffd0932009-07-08 14:22:54 +02002848
Johannes Berg3d23e342009-09-29 23:27:28 +02002849#ifdef CONFIG_CFG80211_WEXT
Johannes Bergdbd2fd62010-12-09 19:58:59 +01002850 dev->ieee80211_ptr->wext.default_key = key.idx;
Johannes Berg08645122009-05-11 13:54:58 +02002851#endif
Johannes Bergdbd2fd62010-12-09 19:58:59 +01002852 } else {
2853 if (key.def_uni || !key.def_multi) {
2854 err = -EINVAL;
2855 goto out;
2856 }
2857
2858 if (!rdev->ops->set_default_mgmt_key) {
2859 err = -EOPNOTSUPP;
2860 goto out;
2861 }
2862
2863 err = nl80211_key_allowed(dev->ieee80211_ptr);
2864 if (err)
2865 goto out;
2866
Hila Gonene35e4d22012-06-27 17:19:42 +03002867 err = rdev_set_default_mgmt_key(rdev, dev, key.idx);
Johannes Bergdbd2fd62010-12-09 19:58:59 +01002868 if (err)
2869 goto out;
2870
2871#ifdef CONFIG_CFG80211_WEXT
2872 dev->ieee80211_ptr->wext.default_mgmt_key = key.idx;
2873#endif
2874 }
2875
2876 out:
Johannes Bergfffd0932009-07-08 14:22:54 +02002877 wdev_unlock(dev->ieee80211_ptr);
Johannes Berg41ade002007-12-19 02:03:29 +01002878
Johannes Berg41ade002007-12-19 02:03:29 +01002879 return err;
2880}
2881
2882static int nl80211_new_key(struct sk_buff *skb, struct genl_info *info)
2883{
Johannes Berg4c476992010-10-04 21:36:35 +02002884 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Bergfffd0932009-07-08 14:22:54 +02002885 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02002886 struct net_device *dev = info->user_ptr[1];
Johannes Bergb9454e82009-07-08 13:29:08 +02002887 struct key_parse key;
Johannes Berge31b8212010-10-05 19:39:30 +02002888 const u8 *mac_addr = NULL;
Johannes Berg41ade002007-12-19 02:03:29 +01002889
Johannes Bergb9454e82009-07-08 13:29:08 +02002890 err = nl80211_parse_key(info, &key);
2891 if (err)
2892 return err;
Johannes Berg41ade002007-12-19 02:03:29 +01002893
Johannes Bergb9454e82009-07-08 13:29:08 +02002894 if (!key.p.key)
Johannes Berg41ade002007-12-19 02:03:29 +01002895 return -EINVAL;
2896
Johannes Berg41ade002007-12-19 02:03:29 +01002897 if (info->attrs[NL80211_ATTR_MAC])
2898 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
2899
Johannes Berge31b8212010-10-05 19:39:30 +02002900 if (key.type == -1) {
2901 if (mac_addr)
2902 key.type = NL80211_KEYTYPE_PAIRWISE;
2903 else
2904 key.type = NL80211_KEYTYPE_GROUP;
2905 }
2906
2907 /* for now */
2908 if (key.type != NL80211_KEYTYPE_PAIRWISE &&
2909 key.type != NL80211_KEYTYPE_GROUP)
2910 return -EINVAL;
2911
Johannes Berg4c476992010-10-04 21:36:35 +02002912 if (!rdev->ops->add_key)
2913 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01002914
Johannes Berge31b8212010-10-05 19:39:30 +02002915 if (cfg80211_validate_key_settings(rdev, &key.p, key.idx,
2916 key.type == NL80211_KEYTYPE_PAIRWISE,
2917 mac_addr))
Johannes Berg4c476992010-10-04 21:36:35 +02002918 return -EINVAL;
Johannes Bergfffd0932009-07-08 14:22:54 +02002919
2920 wdev_lock(dev->ieee80211_ptr);
2921 err = nl80211_key_allowed(dev->ieee80211_ptr);
2922 if (!err)
Hila Gonene35e4d22012-06-27 17:19:42 +03002923 err = rdev_add_key(rdev, dev, key.idx,
2924 key.type == NL80211_KEYTYPE_PAIRWISE,
2925 mac_addr, &key.p);
Johannes Bergfffd0932009-07-08 14:22:54 +02002926 wdev_unlock(dev->ieee80211_ptr);
Johannes Berg41ade002007-12-19 02:03:29 +01002927
Johannes Berg41ade002007-12-19 02:03:29 +01002928 return err;
2929}
2930
2931static int nl80211_del_key(struct sk_buff *skb, struct genl_info *info)
2932{
Johannes Berg4c476992010-10-04 21:36:35 +02002933 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg41ade002007-12-19 02:03:29 +01002934 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02002935 struct net_device *dev = info->user_ptr[1];
Johannes Berg41ade002007-12-19 02:03:29 +01002936 u8 *mac_addr = NULL;
Johannes Bergb9454e82009-07-08 13:29:08 +02002937 struct key_parse key;
Johannes Berg41ade002007-12-19 02:03:29 +01002938
Johannes Bergb9454e82009-07-08 13:29:08 +02002939 err = nl80211_parse_key(info, &key);
2940 if (err)
2941 return err;
Johannes Berg41ade002007-12-19 02:03:29 +01002942
2943 if (info->attrs[NL80211_ATTR_MAC])
2944 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
2945
Johannes Berge31b8212010-10-05 19:39:30 +02002946 if (key.type == -1) {
2947 if (mac_addr)
2948 key.type = NL80211_KEYTYPE_PAIRWISE;
2949 else
2950 key.type = NL80211_KEYTYPE_GROUP;
2951 }
2952
2953 /* for now */
2954 if (key.type != NL80211_KEYTYPE_PAIRWISE &&
2955 key.type != NL80211_KEYTYPE_GROUP)
2956 return -EINVAL;
2957
Johannes Berg4c476992010-10-04 21:36:35 +02002958 if (!rdev->ops->del_key)
2959 return -EOPNOTSUPP;
Johannes Berg41ade002007-12-19 02:03:29 +01002960
Johannes Bergfffd0932009-07-08 14:22:54 +02002961 wdev_lock(dev->ieee80211_ptr);
2962 err = nl80211_key_allowed(dev->ieee80211_ptr);
Johannes Berge31b8212010-10-05 19:39:30 +02002963
2964 if (key.type == NL80211_KEYTYPE_PAIRWISE && mac_addr &&
2965 !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN))
2966 err = -ENOENT;
2967
Johannes Bergfffd0932009-07-08 14:22:54 +02002968 if (!err)
Hila Gonene35e4d22012-06-27 17:19:42 +03002969 err = rdev_del_key(rdev, dev, key.idx,
2970 key.type == NL80211_KEYTYPE_PAIRWISE,
2971 mac_addr);
Johannes Berg41ade002007-12-19 02:03:29 +01002972
Johannes Berg3d23e342009-09-29 23:27:28 +02002973#ifdef CONFIG_CFG80211_WEXT
Johannes Berg08645122009-05-11 13:54:58 +02002974 if (!err) {
Johannes Bergb9454e82009-07-08 13:29:08 +02002975 if (key.idx == dev->ieee80211_ptr->wext.default_key)
Johannes Berg08645122009-05-11 13:54:58 +02002976 dev->ieee80211_ptr->wext.default_key = -1;
Johannes Bergb9454e82009-07-08 13:29:08 +02002977 else if (key.idx == dev->ieee80211_ptr->wext.default_mgmt_key)
Johannes Berg08645122009-05-11 13:54:58 +02002978 dev->ieee80211_ptr->wext.default_mgmt_key = -1;
2979 }
2980#endif
Johannes Bergfffd0932009-07-08 14:22:54 +02002981 wdev_unlock(dev->ieee80211_ptr);
Johannes Berg08645122009-05-11 13:54:58 +02002982
Johannes Berg41ade002007-12-19 02:03:29 +01002983 return err;
2984}
2985
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +05302986/* This function returns an error or the number of nested attributes */
2987static int validate_acl_mac_addrs(struct nlattr *nl_attr)
2988{
2989 struct nlattr *attr;
2990 int n_entries = 0, tmp;
2991
2992 nla_for_each_nested(attr, nl_attr, tmp) {
2993 if (nla_len(attr) != ETH_ALEN)
2994 return -EINVAL;
2995
2996 n_entries++;
2997 }
2998
2999 return n_entries;
3000}
3001
3002/*
3003 * This function parses ACL information and allocates memory for ACL data.
3004 * On successful return, the calling function is responsible to free the
3005 * ACL buffer returned by this function.
3006 */
3007static struct cfg80211_acl_data *parse_acl_data(struct wiphy *wiphy,
3008 struct genl_info *info)
3009{
3010 enum nl80211_acl_policy acl_policy;
3011 struct nlattr *attr;
3012 struct cfg80211_acl_data *acl;
3013 int i = 0, n_entries, tmp;
3014
3015 if (!wiphy->max_acl_mac_addrs)
3016 return ERR_PTR(-EOPNOTSUPP);
3017
3018 if (!info->attrs[NL80211_ATTR_ACL_POLICY])
3019 return ERR_PTR(-EINVAL);
3020
3021 acl_policy = nla_get_u32(info->attrs[NL80211_ATTR_ACL_POLICY]);
3022 if (acl_policy != NL80211_ACL_POLICY_ACCEPT_UNLESS_LISTED &&
3023 acl_policy != NL80211_ACL_POLICY_DENY_UNLESS_LISTED)
3024 return ERR_PTR(-EINVAL);
3025
3026 if (!info->attrs[NL80211_ATTR_MAC_ADDRS])
3027 return ERR_PTR(-EINVAL);
3028
3029 n_entries = validate_acl_mac_addrs(info->attrs[NL80211_ATTR_MAC_ADDRS]);
3030 if (n_entries < 0)
3031 return ERR_PTR(n_entries);
3032
3033 if (n_entries > wiphy->max_acl_mac_addrs)
3034 return ERR_PTR(-ENOTSUPP);
3035
3036 acl = kzalloc(sizeof(*acl) + (sizeof(struct mac_address) * n_entries),
3037 GFP_KERNEL);
3038 if (!acl)
3039 return ERR_PTR(-ENOMEM);
3040
3041 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_MAC_ADDRS], tmp) {
3042 memcpy(acl->mac_addrs[i].addr, nla_data(attr), ETH_ALEN);
3043 i++;
3044 }
3045
3046 acl->n_acl_entries = n_entries;
3047 acl->acl_policy = acl_policy;
3048
3049 return acl;
3050}
3051
3052static int nl80211_set_mac_acl(struct sk_buff *skb, struct genl_info *info)
3053{
3054 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3055 struct net_device *dev = info->user_ptr[1];
3056 struct cfg80211_acl_data *acl;
3057 int err;
3058
3059 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
3060 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
3061 return -EOPNOTSUPP;
3062
3063 if (!dev->ieee80211_ptr->beacon_interval)
3064 return -EINVAL;
3065
3066 acl = parse_acl_data(&rdev->wiphy, info);
3067 if (IS_ERR(acl))
3068 return PTR_ERR(acl);
3069
3070 err = rdev_set_mac_acl(rdev, dev, acl);
3071
3072 kfree(acl);
3073
3074 return err;
3075}
3076
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003077static int nl80211_parse_beacon(struct nlattr *attrs[],
Johannes Berg88600202012-02-13 15:17:18 +01003078 struct cfg80211_beacon_data *bcn)
Johannes Berged1b6cc2007-12-19 02:03:32 +01003079{
Johannes Berg88600202012-02-13 15:17:18 +01003080 bool haveinfo = false;
Johannes Berged1b6cc2007-12-19 02:03:32 +01003081
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003082 if (!is_valid_ie_attr(attrs[NL80211_ATTR_BEACON_TAIL]) ||
3083 !is_valid_ie_attr(attrs[NL80211_ATTR_IE]) ||
3084 !is_valid_ie_attr(attrs[NL80211_ATTR_IE_PROBE_RESP]) ||
3085 !is_valid_ie_attr(attrs[NL80211_ATTR_IE_ASSOC_RESP]))
Johannes Bergf4a11bb2009-03-27 12:40:28 +01003086 return -EINVAL;
3087
Johannes Berg88600202012-02-13 15:17:18 +01003088 memset(bcn, 0, sizeof(*bcn));
Johannes Berged1b6cc2007-12-19 02:03:32 +01003089
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003090 if (attrs[NL80211_ATTR_BEACON_HEAD]) {
3091 bcn->head = nla_data(attrs[NL80211_ATTR_BEACON_HEAD]);
3092 bcn->head_len = nla_len(attrs[NL80211_ATTR_BEACON_HEAD]);
Johannes Berg88600202012-02-13 15:17:18 +01003093 if (!bcn->head_len)
3094 return -EINVAL;
3095 haveinfo = true;
Johannes Berged1b6cc2007-12-19 02:03:32 +01003096 }
3097
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003098 if (attrs[NL80211_ATTR_BEACON_TAIL]) {
3099 bcn->tail = nla_data(attrs[NL80211_ATTR_BEACON_TAIL]);
3100 bcn->tail_len = nla_len(attrs[NL80211_ATTR_BEACON_TAIL]);
Johannes Berg88600202012-02-13 15:17:18 +01003101 haveinfo = true;
Johannes Berged1b6cc2007-12-19 02:03:32 +01003102 }
3103
Johannes Berg4c476992010-10-04 21:36:35 +02003104 if (!haveinfo)
3105 return -EINVAL;
Johannes Berged1b6cc2007-12-19 02:03:32 +01003106
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003107 if (attrs[NL80211_ATTR_IE]) {
3108 bcn->beacon_ies = nla_data(attrs[NL80211_ATTR_IE]);
3109 bcn->beacon_ies_len = nla_len(attrs[NL80211_ATTR_IE]);
Jouni Malinen9946ecf2011-08-10 23:55:56 +03003110 }
3111
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003112 if (attrs[NL80211_ATTR_IE_PROBE_RESP]) {
Johannes Berg88600202012-02-13 15:17:18 +01003113 bcn->proberesp_ies =
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003114 nla_data(attrs[NL80211_ATTR_IE_PROBE_RESP]);
Johannes Berg88600202012-02-13 15:17:18 +01003115 bcn->proberesp_ies_len =
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003116 nla_len(attrs[NL80211_ATTR_IE_PROBE_RESP]);
Jouni Malinen9946ecf2011-08-10 23:55:56 +03003117 }
3118
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003119 if (attrs[NL80211_ATTR_IE_ASSOC_RESP]) {
Johannes Berg88600202012-02-13 15:17:18 +01003120 bcn->assocresp_ies =
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003121 nla_data(attrs[NL80211_ATTR_IE_ASSOC_RESP]);
Johannes Berg88600202012-02-13 15:17:18 +01003122 bcn->assocresp_ies_len =
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003123 nla_len(attrs[NL80211_ATTR_IE_ASSOC_RESP]);
Jouni Malinen9946ecf2011-08-10 23:55:56 +03003124 }
3125
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003126 if (attrs[NL80211_ATTR_PROBE_RESP]) {
3127 bcn->probe_resp = nla_data(attrs[NL80211_ATTR_PROBE_RESP]);
3128 bcn->probe_resp_len = nla_len(attrs[NL80211_ATTR_PROBE_RESP]);
Arik Nemtsov00f740e2011-11-10 11:28:56 +02003129 }
3130
Johannes Berg88600202012-02-13 15:17:18 +01003131 return 0;
3132}
3133
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003134static bool nl80211_get_ap_channel(struct cfg80211_registered_device *rdev,
3135 struct cfg80211_ap_settings *params)
3136{
3137 struct wireless_dev *wdev;
3138 bool ret = false;
3139
Johannes Berg89a54e42012-06-15 14:33:17 +02003140 list_for_each_entry(wdev, &rdev->wdev_list, list) {
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003141 if (wdev->iftype != NL80211_IFTYPE_AP &&
3142 wdev->iftype != NL80211_IFTYPE_P2P_GO)
3143 continue;
3144
Johannes Berg683b6d32012-11-08 21:25:48 +01003145 if (!wdev->preset_chandef.chan)
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003146 continue;
3147
Johannes Berg683b6d32012-11-08 21:25:48 +01003148 params->chandef = wdev->preset_chandef;
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003149 ret = true;
3150 break;
3151 }
3152
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003153 return ret;
3154}
3155
Jouni Malinene39e5b52012-09-30 19:29:39 +03003156static bool nl80211_valid_auth_type(struct cfg80211_registered_device *rdev,
3157 enum nl80211_auth_type auth_type,
3158 enum nl80211_commands cmd)
3159{
3160 if (auth_type > NL80211_AUTHTYPE_MAX)
3161 return false;
3162
3163 switch (cmd) {
3164 case NL80211_CMD_AUTHENTICATE:
3165 if (!(rdev->wiphy.features & NL80211_FEATURE_SAE) &&
3166 auth_type == NL80211_AUTHTYPE_SAE)
3167 return false;
3168 return true;
3169 case NL80211_CMD_CONNECT:
3170 case NL80211_CMD_START_AP:
3171 /* SAE not supported yet */
3172 if (auth_type == NL80211_AUTHTYPE_SAE)
3173 return false;
3174 return true;
3175 default:
3176 return false;
3177 }
3178}
3179
Johannes Berg88600202012-02-13 15:17:18 +01003180static int nl80211_start_ap(struct sk_buff *skb, struct genl_info *info)
3181{
3182 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3183 struct net_device *dev = info->user_ptr[1];
3184 struct wireless_dev *wdev = dev->ieee80211_ptr;
3185 struct cfg80211_ap_settings params;
3186 int err;
3187
3188 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
3189 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
3190 return -EOPNOTSUPP;
3191
3192 if (!rdev->ops->start_ap)
3193 return -EOPNOTSUPP;
3194
3195 if (wdev->beacon_interval)
3196 return -EALREADY;
3197
3198 memset(&params, 0, sizeof(params));
3199
3200 /* these are required for START_AP */
3201 if (!info->attrs[NL80211_ATTR_BEACON_INTERVAL] ||
3202 !info->attrs[NL80211_ATTR_DTIM_PERIOD] ||
3203 !info->attrs[NL80211_ATTR_BEACON_HEAD])
3204 return -EINVAL;
3205
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003206 err = nl80211_parse_beacon(info->attrs, &params.beacon);
Johannes Berg88600202012-02-13 15:17:18 +01003207 if (err)
3208 return err;
3209
3210 params.beacon_interval =
3211 nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]);
3212 params.dtim_period =
3213 nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]);
3214
3215 err = cfg80211_validate_beacon_int(rdev, params.beacon_interval);
3216 if (err)
3217 return err;
3218
3219 /*
3220 * In theory, some of these attributes should be required here
3221 * but since they were not used when the command was originally
3222 * added, keep them optional for old user space programs to let
3223 * them continue to work with drivers that do not need the
3224 * additional information -- drivers must check!
3225 */
3226 if (info->attrs[NL80211_ATTR_SSID]) {
3227 params.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
3228 params.ssid_len =
3229 nla_len(info->attrs[NL80211_ATTR_SSID]);
3230 if (params.ssid_len == 0 ||
3231 params.ssid_len > IEEE80211_MAX_SSID_LEN)
3232 return -EINVAL;
3233 }
3234
3235 if (info->attrs[NL80211_ATTR_HIDDEN_SSID]) {
3236 params.hidden_ssid = nla_get_u32(
3237 info->attrs[NL80211_ATTR_HIDDEN_SSID]);
3238 if (params.hidden_ssid != NL80211_HIDDEN_SSID_NOT_IN_USE &&
3239 params.hidden_ssid != NL80211_HIDDEN_SSID_ZERO_LEN &&
3240 params.hidden_ssid != NL80211_HIDDEN_SSID_ZERO_CONTENTS)
3241 return -EINVAL;
3242 }
3243
3244 params.privacy = !!info->attrs[NL80211_ATTR_PRIVACY];
3245
3246 if (info->attrs[NL80211_ATTR_AUTH_TYPE]) {
3247 params.auth_type = nla_get_u32(
3248 info->attrs[NL80211_ATTR_AUTH_TYPE]);
Jouni Malinene39e5b52012-09-30 19:29:39 +03003249 if (!nl80211_valid_auth_type(rdev, params.auth_type,
3250 NL80211_CMD_START_AP))
Johannes Berg88600202012-02-13 15:17:18 +01003251 return -EINVAL;
3252 } else
3253 params.auth_type = NL80211_AUTHTYPE_AUTOMATIC;
3254
3255 err = nl80211_crypto_settings(rdev, info, &params.crypto,
3256 NL80211_MAX_NR_CIPHER_SUITES);
3257 if (err)
3258 return err;
3259
Vasanthakumar Thiagarajan1b658f12012-03-02 15:50:02 +05303260 if (info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]) {
3261 if (!(rdev->wiphy.features & NL80211_FEATURE_INACTIVITY_TIMER))
3262 return -EOPNOTSUPP;
3263 params.inactivity_timeout = nla_get_u16(
3264 info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]);
3265 }
3266
Johannes Berg53cabad2012-11-14 15:17:28 +01003267 if (info->attrs[NL80211_ATTR_P2P_CTWINDOW]) {
3268 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
3269 return -EINVAL;
3270 params.p2p_ctwindow =
3271 nla_get_u8(info->attrs[NL80211_ATTR_P2P_CTWINDOW]);
3272 if (params.p2p_ctwindow > 127)
3273 return -EINVAL;
3274 if (params.p2p_ctwindow != 0 &&
3275 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_CTWIN))
3276 return -EINVAL;
3277 }
3278
3279 if (info->attrs[NL80211_ATTR_P2P_OPPPS]) {
3280 u8 tmp;
3281
3282 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
3283 return -EINVAL;
3284 tmp = nla_get_u8(info->attrs[NL80211_ATTR_P2P_OPPPS]);
3285 if (tmp > 1)
3286 return -EINVAL;
3287 params.p2p_opp_ps = tmp;
3288 if (params.p2p_opp_ps != 0 &&
3289 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_OPPPS))
3290 return -EINVAL;
3291 }
3292
Johannes Bergaa430da2012-05-16 23:50:18 +02003293 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
Johannes Berg683b6d32012-11-08 21:25:48 +01003294 err = nl80211_parse_chandef(rdev, info, &params.chandef);
3295 if (err)
3296 return err;
3297 } else if (wdev->preset_chandef.chan) {
3298 params.chandef = wdev->preset_chandef;
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003299 } else if (!nl80211_get_ap_channel(rdev, &params))
Johannes Bergaa430da2012-05-16 23:50:18 +02003300 return -EINVAL;
3301
Ilan Peer174e0cd2014-02-23 09:13:01 +02003302 if (!cfg80211_reg_can_beacon(&rdev->wiphy, &params.chandef,
3303 wdev->iftype))
Johannes Bergaa430da2012-05-16 23:50:18 +02003304 return -EINVAL;
3305
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +05303306 if (info->attrs[NL80211_ATTR_ACL_POLICY]) {
3307 params.acl = parse_acl_data(&rdev->wiphy, info);
3308 if (IS_ERR(params.acl))
3309 return PTR_ERR(params.acl);
3310 }
3311
Simon Wunderlichc56589e2013-11-21 18:19:49 +01003312 wdev_lock(wdev);
Hila Gonene35e4d22012-06-27 17:19:42 +03003313 err = rdev_start_ap(rdev, dev, &params);
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003314 if (!err) {
Johannes Berg683b6d32012-11-08 21:25:48 +01003315 wdev->preset_chandef = params.chandef;
Johannes Berg88600202012-02-13 15:17:18 +01003316 wdev->beacon_interval = params.beacon_interval;
Michal Kazior9e0e2962014-01-29 14:22:27 +01003317 wdev->chandef = params.chandef;
Antonio Quartulli06e191e2012-11-07 12:52:19 +01003318 wdev->ssid_len = params.ssid_len;
3319 memcpy(wdev->ssid, params.ssid, wdev->ssid_len);
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003320 }
Simon Wunderlichc56589e2013-11-21 18:19:49 +01003321 wdev_unlock(wdev);
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +05303322
3323 kfree(params.acl);
3324
Johannes Berg56d18932011-05-09 18:41:15 +02003325 return err;
Johannes Berged1b6cc2007-12-19 02:03:32 +01003326}
3327
Johannes Berg88600202012-02-13 15:17:18 +01003328static int nl80211_set_beacon(struct sk_buff *skb, struct genl_info *info)
3329{
3330 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3331 struct net_device *dev = info->user_ptr[1];
3332 struct wireless_dev *wdev = dev->ieee80211_ptr;
3333 struct cfg80211_beacon_data params;
3334 int err;
3335
3336 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
3337 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
3338 return -EOPNOTSUPP;
3339
3340 if (!rdev->ops->change_beacon)
3341 return -EOPNOTSUPP;
3342
3343 if (!wdev->beacon_interval)
3344 return -EINVAL;
3345
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003346 err = nl80211_parse_beacon(info->attrs, &params);
Johannes Berg88600202012-02-13 15:17:18 +01003347 if (err)
3348 return err;
3349
Simon Wunderlichc56589e2013-11-21 18:19:49 +01003350 wdev_lock(wdev);
3351 err = rdev_change_beacon(rdev, dev, &params);
3352 wdev_unlock(wdev);
3353
3354 return err;
Johannes Berg88600202012-02-13 15:17:18 +01003355}
3356
3357static int nl80211_stop_ap(struct sk_buff *skb, struct genl_info *info)
Johannes Berged1b6cc2007-12-19 02:03:32 +01003358{
Johannes Berg4c476992010-10-04 21:36:35 +02003359 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3360 struct net_device *dev = info->user_ptr[1];
Johannes Berged1b6cc2007-12-19 02:03:32 +01003361
Ilan Peer7c8d5e02014-02-25 15:33:38 +02003362 return cfg80211_stop_ap(rdev, dev, false);
Johannes Berged1b6cc2007-12-19 02:03:32 +01003363}
3364
Johannes Berg5727ef12007-12-19 02:03:34 +01003365static const struct nla_policy sta_flags_policy[NL80211_STA_FLAG_MAX + 1] = {
3366 [NL80211_STA_FLAG_AUTHORIZED] = { .type = NLA_FLAG },
3367 [NL80211_STA_FLAG_SHORT_PREAMBLE] = { .type = NLA_FLAG },
3368 [NL80211_STA_FLAG_WME] = { .type = NLA_FLAG },
Jouni Malinen0e467242009-05-11 21:57:55 +03003369 [NL80211_STA_FLAG_MFP] = { .type = NLA_FLAG },
Javier Cardonab39c48f2011-04-07 15:08:30 -07003370 [NL80211_STA_FLAG_AUTHENTICATED] = { .type = NLA_FLAG },
Johannes Bergd83023d2011-12-14 09:29:15 +01003371 [NL80211_STA_FLAG_TDLS_PEER] = { .type = NLA_FLAG },
Johannes Berg5727ef12007-12-19 02:03:34 +01003372};
3373
Johannes Bergeccb8e82009-05-11 21:57:56 +03003374static int parse_station_flags(struct genl_info *info,
Johannes Bergbdd3ae32012-01-02 13:30:03 +01003375 enum nl80211_iftype iftype,
Johannes Bergeccb8e82009-05-11 21:57:56 +03003376 struct station_parameters *params)
Johannes Berg5727ef12007-12-19 02:03:34 +01003377{
3378 struct nlattr *flags[NL80211_STA_FLAG_MAX + 1];
Johannes Bergeccb8e82009-05-11 21:57:56 +03003379 struct nlattr *nla;
Johannes Berg5727ef12007-12-19 02:03:34 +01003380 int flag;
3381
Johannes Bergeccb8e82009-05-11 21:57:56 +03003382 /*
3383 * Try parsing the new attribute first so userspace
3384 * can specify both for older kernels.
3385 */
3386 nla = info->attrs[NL80211_ATTR_STA_FLAGS2];
3387 if (nla) {
3388 struct nl80211_sta_flag_update *sta_flags;
Johannes Berg5727ef12007-12-19 02:03:34 +01003389
Johannes Bergeccb8e82009-05-11 21:57:56 +03003390 sta_flags = nla_data(nla);
3391 params->sta_flags_mask = sta_flags->mask;
3392 params->sta_flags_set = sta_flags->set;
Johannes Berg77ee7c82013-02-15 00:48:33 +01003393 params->sta_flags_set &= params->sta_flags_mask;
Johannes Bergeccb8e82009-05-11 21:57:56 +03003394 if ((params->sta_flags_mask |
3395 params->sta_flags_set) & BIT(__NL80211_STA_FLAG_INVALID))
3396 return -EINVAL;
3397 return 0;
3398 }
3399
3400 /* if present, parse the old attribute */
3401
3402 nla = info->attrs[NL80211_ATTR_STA_FLAGS];
Johannes Berg5727ef12007-12-19 02:03:34 +01003403 if (!nla)
3404 return 0;
3405
3406 if (nla_parse_nested(flags, NL80211_STA_FLAG_MAX,
3407 nla, sta_flags_policy))
3408 return -EINVAL;
3409
Johannes Bergbdd3ae32012-01-02 13:30:03 +01003410 /*
3411 * Only allow certain flags for interface types so that
3412 * other attributes are silently ignored. Remember that
3413 * this is backward compatibility code with old userspace
3414 * and shouldn't be hit in other cases anyway.
3415 */
3416 switch (iftype) {
3417 case NL80211_IFTYPE_AP:
3418 case NL80211_IFTYPE_AP_VLAN:
3419 case NL80211_IFTYPE_P2P_GO:
3420 params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) |
3421 BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) |
3422 BIT(NL80211_STA_FLAG_WME) |
3423 BIT(NL80211_STA_FLAG_MFP);
3424 break;
3425 case NL80211_IFTYPE_P2P_CLIENT:
3426 case NL80211_IFTYPE_STATION:
3427 params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) |
3428 BIT(NL80211_STA_FLAG_TDLS_PEER);
3429 break;
3430 case NL80211_IFTYPE_MESH_POINT:
3431 params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHENTICATED) |
3432 BIT(NL80211_STA_FLAG_MFP) |
3433 BIT(NL80211_STA_FLAG_AUTHORIZED);
3434 default:
3435 return -EINVAL;
3436 }
Johannes Berg5727ef12007-12-19 02:03:34 +01003437
Johannes Berg3383b5a2012-05-10 20:14:43 +02003438 for (flag = 1; flag <= NL80211_STA_FLAG_MAX; flag++) {
3439 if (flags[flag]) {
Johannes Bergeccb8e82009-05-11 21:57:56 +03003440 params->sta_flags_set |= (1<<flag);
Johannes Berg5727ef12007-12-19 02:03:34 +01003441
Johannes Berg3383b5a2012-05-10 20:14:43 +02003442 /* no longer support new API additions in old API */
3443 if (flag > NL80211_STA_FLAG_MAX_OLD_API)
3444 return -EINVAL;
3445 }
3446 }
3447
Johannes Berg5727ef12007-12-19 02:03:34 +01003448 return 0;
3449}
3450
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003451static bool nl80211_put_sta_rate(struct sk_buff *msg, struct rate_info *info,
3452 int attr)
3453{
3454 struct nlattr *rate;
Vladimir Kondratiev8eb41c82012-07-05 14:25:49 +03003455 u32 bitrate;
3456 u16 bitrate_compat;
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003457
3458 rate = nla_nest_start(msg, attr);
3459 if (!rate)
Johannes Bergdb9c64c2012-11-09 14:56:41 +01003460 return false;
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003461
3462 /* cfg80211_calculate_bitrate will return 0 for mcs >= 32 */
3463 bitrate = cfg80211_calculate_bitrate(info);
Vladimir Kondratiev8eb41c82012-07-05 14:25:49 +03003464 /* report 16-bit bitrate only if we can */
3465 bitrate_compat = bitrate < (1UL << 16) ? bitrate : 0;
Johannes Bergdb9c64c2012-11-09 14:56:41 +01003466 if (bitrate > 0 &&
3467 nla_put_u32(msg, NL80211_RATE_INFO_BITRATE32, bitrate))
3468 return false;
3469 if (bitrate_compat > 0 &&
3470 nla_put_u16(msg, NL80211_RATE_INFO_BITRATE, bitrate_compat))
3471 return false;
3472
3473 if (info->flags & RATE_INFO_FLAGS_MCS) {
3474 if (nla_put_u8(msg, NL80211_RATE_INFO_MCS, info->mcs))
3475 return false;
3476 if (info->flags & RATE_INFO_FLAGS_40_MHZ_WIDTH &&
3477 nla_put_flag(msg, NL80211_RATE_INFO_40_MHZ_WIDTH))
3478 return false;
3479 if (info->flags & RATE_INFO_FLAGS_SHORT_GI &&
3480 nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI))
3481 return false;
3482 } else if (info->flags & RATE_INFO_FLAGS_VHT_MCS) {
3483 if (nla_put_u8(msg, NL80211_RATE_INFO_VHT_MCS, info->mcs))
3484 return false;
3485 if (nla_put_u8(msg, NL80211_RATE_INFO_VHT_NSS, info->nss))
3486 return false;
3487 if (info->flags & RATE_INFO_FLAGS_40_MHZ_WIDTH &&
3488 nla_put_flag(msg, NL80211_RATE_INFO_40_MHZ_WIDTH))
3489 return false;
3490 if (info->flags & RATE_INFO_FLAGS_80_MHZ_WIDTH &&
3491 nla_put_flag(msg, NL80211_RATE_INFO_80_MHZ_WIDTH))
3492 return false;
3493 if (info->flags & RATE_INFO_FLAGS_80P80_MHZ_WIDTH &&
3494 nla_put_flag(msg, NL80211_RATE_INFO_80P80_MHZ_WIDTH))
3495 return false;
3496 if (info->flags & RATE_INFO_FLAGS_160_MHZ_WIDTH &&
3497 nla_put_flag(msg, NL80211_RATE_INFO_160_MHZ_WIDTH))
3498 return false;
3499 if (info->flags & RATE_INFO_FLAGS_SHORT_GI &&
3500 nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI))
3501 return false;
3502 }
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003503
3504 nla_nest_end(msg, rate);
3505 return true;
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003506}
3507
Felix Fietkau119363c2013-04-22 16:29:30 +02003508static bool nl80211_put_signal(struct sk_buff *msg, u8 mask, s8 *signal,
3509 int id)
3510{
3511 void *attr;
3512 int i = 0;
3513
3514 if (!mask)
3515 return true;
3516
3517 attr = nla_nest_start(msg, id);
3518 if (!attr)
3519 return false;
3520
3521 for (i = 0; i < IEEE80211_MAX_CHAINS; i++) {
3522 if (!(mask & BIT(i)))
3523 continue;
3524
3525 if (nla_put_u8(msg, i, signal[i]))
3526 return false;
3527 }
3528
3529 nla_nest_end(msg, attr);
3530
3531 return true;
3532}
3533
Eric W. Biederman15e47302012-09-07 20:12:54 +00003534static int nl80211_send_station(struct sk_buff *msg, u32 portid, u32 seq,
John W. Linville66266b32012-03-15 13:25:41 -04003535 int flags,
3536 struct cfg80211_registered_device *rdev,
3537 struct net_device *dev,
Johannes Berg98b62182009-12-23 13:15:44 +01003538 const u8 *mac_addr, struct station_info *sinfo)
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003539{
3540 void *hdr;
Paul Stewartf4263c92011-03-31 09:25:41 -07003541 struct nlattr *sinfoattr, *bss_param;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003542
Eric W. Biederman15e47302012-09-07 20:12:54 +00003543 hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_STATION);
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003544 if (!hdr)
3545 return -1;
3546
David S. Miller9360ffd2012-03-29 04:41:26 -04003547 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
3548 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) ||
3549 nla_put_u32(msg, NL80211_ATTR_GENERATION, sinfo->generation))
3550 goto nla_put_failure;
Johannes Bergf5ea9122009-08-07 16:17:38 +02003551
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003552 sinfoattr = nla_nest_start(msg, NL80211_ATTR_STA_INFO);
3553 if (!sinfoattr)
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003554 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04003555 if ((sinfo->filled & STATION_INFO_CONNECTED_TIME) &&
3556 nla_put_u32(msg, NL80211_STA_INFO_CONNECTED_TIME,
3557 sinfo->connected_time))
3558 goto nla_put_failure;
3559 if ((sinfo->filled & STATION_INFO_INACTIVE_TIME) &&
3560 nla_put_u32(msg, NL80211_STA_INFO_INACTIVE_TIME,
3561 sinfo->inactive_time))
3562 goto nla_put_failure;
Vladimir Kondratiev42745e02013-02-04 13:53:11 +02003563 if ((sinfo->filled & (STATION_INFO_RX_BYTES |
3564 STATION_INFO_RX_BYTES64)) &&
David S. Miller9360ffd2012-03-29 04:41:26 -04003565 nla_put_u32(msg, NL80211_STA_INFO_RX_BYTES,
Vladimir Kondratiev42745e02013-02-04 13:53:11 +02003566 (u32)sinfo->rx_bytes))
3567 goto nla_put_failure;
3568 if ((sinfo->filled & (STATION_INFO_TX_BYTES |
Felix Fietkau4325d722013-05-23 15:05:59 +02003569 STATION_INFO_TX_BYTES64)) &&
Vladimir Kondratiev42745e02013-02-04 13:53:11 +02003570 nla_put_u32(msg, NL80211_STA_INFO_TX_BYTES,
3571 (u32)sinfo->tx_bytes))
3572 goto nla_put_failure;
3573 if ((sinfo->filled & STATION_INFO_RX_BYTES64) &&
3574 nla_put_u64(msg, NL80211_STA_INFO_RX_BYTES64,
David S. Miller9360ffd2012-03-29 04:41:26 -04003575 sinfo->rx_bytes))
3576 goto nla_put_failure;
Vladimir Kondratiev42745e02013-02-04 13:53:11 +02003577 if ((sinfo->filled & STATION_INFO_TX_BYTES64) &&
3578 nla_put_u64(msg, NL80211_STA_INFO_TX_BYTES64,
David S. Miller9360ffd2012-03-29 04:41:26 -04003579 sinfo->tx_bytes))
3580 goto nla_put_failure;
3581 if ((sinfo->filled & STATION_INFO_LLID) &&
3582 nla_put_u16(msg, NL80211_STA_INFO_LLID, sinfo->llid))
3583 goto nla_put_failure;
3584 if ((sinfo->filled & STATION_INFO_PLID) &&
3585 nla_put_u16(msg, NL80211_STA_INFO_PLID, sinfo->plid))
3586 goto nla_put_failure;
3587 if ((sinfo->filled & STATION_INFO_PLINK_STATE) &&
3588 nla_put_u8(msg, NL80211_STA_INFO_PLINK_STATE,
3589 sinfo->plink_state))
3590 goto nla_put_failure;
John W. Linville66266b32012-03-15 13:25:41 -04003591 switch (rdev->wiphy.signal_type) {
3592 case CFG80211_SIGNAL_TYPE_MBM:
David S. Miller9360ffd2012-03-29 04:41:26 -04003593 if ((sinfo->filled & STATION_INFO_SIGNAL) &&
3594 nla_put_u8(msg, NL80211_STA_INFO_SIGNAL,
3595 sinfo->signal))
3596 goto nla_put_failure;
3597 if ((sinfo->filled & STATION_INFO_SIGNAL_AVG) &&
3598 nla_put_u8(msg, NL80211_STA_INFO_SIGNAL_AVG,
3599 sinfo->signal_avg))
3600 goto nla_put_failure;
John W. Linville66266b32012-03-15 13:25:41 -04003601 break;
3602 default:
3603 break;
3604 }
Felix Fietkau119363c2013-04-22 16:29:30 +02003605 if (sinfo->filled & STATION_INFO_CHAIN_SIGNAL) {
3606 if (!nl80211_put_signal(msg, sinfo->chains,
3607 sinfo->chain_signal,
3608 NL80211_STA_INFO_CHAIN_SIGNAL))
3609 goto nla_put_failure;
3610 }
3611 if (sinfo->filled & STATION_INFO_CHAIN_SIGNAL_AVG) {
3612 if (!nl80211_put_signal(msg, sinfo->chains,
3613 sinfo->chain_signal_avg,
3614 NL80211_STA_INFO_CHAIN_SIGNAL_AVG))
3615 goto nla_put_failure;
3616 }
Henning Rogge420e7fa2008-12-11 22:04:19 +01003617 if (sinfo->filled & STATION_INFO_TX_BITRATE) {
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003618 if (!nl80211_put_sta_rate(msg, &sinfo->txrate,
3619 NL80211_STA_INFO_TX_BITRATE))
Henning Rogge420e7fa2008-12-11 22:04:19 +01003620 goto nla_put_failure;
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003621 }
3622 if (sinfo->filled & STATION_INFO_RX_BITRATE) {
3623 if (!nl80211_put_sta_rate(msg, &sinfo->rxrate,
3624 NL80211_STA_INFO_RX_BITRATE))
3625 goto nla_put_failure;
Henning Rogge420e7fa2008-12-11 22:04:19 +01003626 }
David S. Miller9360ffd2012-03-29 04:41:26 -04003627 if ((sinfo->filled & STATION_INFO_RX_PACKETS) &&
3628 nla_put_u32(msg, NL80211_STA_INFO_RX_PACKETS,
3629 sinfo->rx_packets))
3630 goto nla_put_failure;
3631 if ((sinfo->filled & STATION_INFO_TX_PACKETS) &&
3632 nla_put_u32(msg, NL80211_STA_INFO_TX_PACKETS,
3633 sinfo->tx_packets))
3634 goto nla_put_failure;
3635 if ((sinfo->filled & STATION_INFO_TX_RETRIES) &&
3636 nla_put_u32(msg, NL80211_STA_INFO_TX_RETRIES,
3637 sinfo->tx_retries))
3638 goto nla_put_failure;
3639 if ((sinfo->filled & STATION_INFO_TX_FAILED) &&
3640 nla_put_u32(msg, NL80211_STA_INFO_TX_FAILED,
3641 sinfo->tx_failed))
3642 goto nla_put_failure;
3643 if ((sinfo->filled & STATION_INFO_BEACON_LOSS_COUNT) &&
3644 nla_put_u32(msg, NL80211_STA_INFO_BEACON_LOSS,
3645 sinfo->beacon_loss_count))
3646 goto nla_put_failure;
Marco Porsch3b1c5a52013-01-07 16:04:52 +01003647 if ((sinfo->filled & STATION_INFO_LOCAL_PM) &&
3648 nla_put_u32(msg, NL80211_STA_INFO_LOCAL_PM,
3649 sinfo->local_pm))
3650 goto nla_put_failure;
3651 if ((sinfo->filled & STATION_INFO_PEER_PM) &&
3652 nla_put_u32(msg, NL80211_STA_INFO_PEER_PM,
3653 sinfo->peer_pm))
3654 goto nla_put_failure;
3655 if ((sinfo->filled & STATION_INFO_NONPEER_PM) &&
3656 nla_put_u32(msg, NL80211_STA_INFO_NONPEER_PM,
3657 sinfo->nonpeer_pm))
3658 goto nla_put_failure;
Paul Stewartf4263c92011-03-31 09:25:41 -07003659 if (sinfo->filled & STATION_INFO_BSS_PARAM) {
3660 bss_param = nla_nest_start(msg, NL80211_STA_INFO_BSS_PARAM);
3661 if (!bss_param)
3662 goto nla_put_failure;
3663
David S. Miller9360ffd2012-03-29 04:41:26 -04003664 if (((sinfo->bss_param.flags & BSS_PARAM_FLAGS_CTS_PROT) &&
3665 nla_put_flag(msg, NL80211_STA_BSS_PARAM_CTS_PROT)) ||
3666 ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_PREAMBLE) &&
3667 nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_PREAMBLE)) ||
3668 ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_SLOT_TIME) &&
3669 nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_SLOT_TIME)) ||
3670 nla_put_u8(msg, NL80211_STA_BSS_PARAM_DTIM_PERIOD,
3671 sinfo->bss_param.dtim_period) ||
3672 nla_put_u16(msg, NL80211_STA_BSS_PARAM_BEACON_INTERVAL,
3673 sinfo->bss_param.beacon_interval))
3674 goto nla_put_failure;
Paul Stewartf4263c92011-03-31 09:25:41 -07003675
3676 nla_nest_end(msg, bss_param);
3677 }
David S. Miller9360ffd2012-03-29 04:41:26 -04003678 if ((sinfo->filled & STATION_INFO_STA_FLAGS) &&
3679 nla_put(msg, NL80211_STA_INFO_STA_FLAGS,
3680 sizeof(struct nl80211_sta_flag_update),
3681 &sinfo->sta_flags))
3682 goto nla_put_failure;
John W. Linville7eab0f62012-04-12 14:25:14 -04003683 if ((sinfo->filled & STATION_INFO_T_OFFSET) &&
3684 nla_put_u64(msg, NL80211_STA_INFO_T_OFFSET,
3685 sinfo->t_offset))
3686 goto nla_put_failure;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003687 nla_nest_end(msg, sinfoattr);
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003688
David S. Miller9360ffd2012-03-29 04:41:26 -04003689 if ((sinfo->filled & STATION_INFO_ASSOC_REQ_IES) &&
3690 nla_put(msg, NL80211_ATTR_IE, sinfo->assoc_req_ies_len,
3691 sinfo->assoc_req_ies))
3692 goto nla_put_failure;
Jouni Malinen50d3dfb2011-08-08 12:11:52 +03003693
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003694 return genlmsg_end(msg, hdr);
3695
3696 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07003697 genlmsg_cancel(msg, hdr);
3698 return -EMSGSIZE;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003699}
3700
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003701static int nl80211_dump_station(struct sk_buff *skb,
Johannes Bergbba95fe2008-07-29 13:22:51 +02003702 struct netlink_callback *cb)
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003703{
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003704 struct station_info sinfo;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08003705 struct cfg80211_registered_device *rdev;
Johannes Berg97990a02013-04-19 01:02:55 +02003706 struct wireless_dev *wdev;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003707 u8 mac_addr[ETH_ALEN];
Johannes Berg97990a02013-04-19 01:02:55 +02003708 int sta_idx = cb->args[2];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003709 int err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003710
Zhao, Gang1b8ec872014-04-21 12:53:02 +08003711 err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev);
Johannes Berg67748892010-10-04 21:14:06 +02003712 if (err)
3713 return err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02003714
Johannes Berg97990a02013-04-19 01:02:55 +02003715 if (!wdev->netdev) {
3716 err = -EINVAL;
3717 goto out_err;
3718 }
3719
Zhao, Gang1b8ec872014-04-21 12:53:02 +08003720 if (!rdev->ops->dump_station) {
Jouni Malineneec60b02009-03-20 21:21:19 +02003721 err = -EOPNOTSUPP;
Johannes Bergbba95fe2008-07-29 13:22:51 +02003722 goto out_err;
3723 }
3724
Johannes Bergbba95fe2008-07-29 13:22:51 +02003725 while (1) {
Jouni Malinenf612ced2011-08-11 11:46:22 +03003726 memset(&sinfo, 0, sizeof(sinfo));
Zhao, Gang1b8ec872014-04-21 12:53:02 +08003727 err = rdev_dump_station(rdev, wdev->netdev, sta_idx,
Hila Gonene35e4d22012-06-27 17:19:42 +03003728 mac_addr, &sinfo);
Johannes Bergbba95fe2008-07-29 13:22:51 +02003729 if (err == -ENOENT)
3730 break;
3731 if (err)
Johannes Berg3b858752009-03-12 09:55:09 +01003732 goto out_err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02003733
3734 if (nl80211_send_station(skb,
Eric W. Biederman15e47302012-09-07 20:12:54 +00003735 NETLINK_CB(cb->skb).portid,
Johannes Bergbba95fe2008-07-29 13:22:51 +02003736 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08003737 rdev, wdev->netdev, mac_addr,
Johannes Bergbba95fe2008-07-29 13:22:51 +02003738 &sinfo) < 0)
3739 goto out;
3740
3741 sta_idx++;
3742 }
3743
3744
3745 out:
Johannes Berg97990a02013-04-19 01:02:55 +02003746 cb->args[2] = sta_idx;
Johannes Bergbba95fe2008-07-29 13:22:51 +02003747 err = skb->len;
Johannes Bergbba95fe2008-07-29 13:22:51 +02003748 out_err:
Zhao, Gang1b8ec872014-04-21 12:53:02 +08003749 nl80211_finish_wdev_dump(rdev);
Johannes Bergbba95fe2008-07-29 13:22:51 +02003750
3751 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003752}
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003753
Johannes Berg5727ef12007-12-19 02:03:34 +01003754static int nl80211_get_station(struct sk_buff *skb, struct genl_info *info)
3755{
Johannes Berg4c476992010-10-04 21:36:35 +02003756 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3757 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003758 struct station_info sinfo;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003759 struct sk_buff *msg;
3760 u8 *mac_addr = NULL;
Johannes Berg4c476992010-10-04 21:36:35 +02003761 int err;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003762
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003763 memset(&sinfo, 0, sizeof(sinfo));
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003764
3765 if (!info->attrs[NL80211_ATTR_MAC])
3766 return -EINVAL;
3767
3768 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
3769
Johannes Berg4c476992010-10-04 21:36:35 +02003770 if (!rdev->ops->get_station)
3771 return -EOPNOTSUPP;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003772
Hila Gonene35e4d22012-06-27 17:19:42 +03003773 err = rdev_get_station(rdev, dev, mac_addr, &sinfo);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003774 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02003775 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003776
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07003777 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003778 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02003779 return -ENOMEM;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003780
Eric W. Biederman15e47302012-09-07 20:12:54 +00003781 if (nl80211_send_station(msg, info->snd_portid, info->snd_seq, 0,
John W. Linville66266b32012-03-15 13:25:41 -04003782 rdev, dev, mac_addr, &sinfo) < 0) {
Johannes Berg4c476992010-10-04 21:36:35 +02003783 nlmsg_free(msg);
3784 return -ENOBUFS;
3785 }
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003786
Johannes Berg4c476992010-10-04 21:36:35 +02003787 return genlmsg_reply(msg, info);
Johannes Berg5727ef12007-12-19 02:03:34 +01003788}
3789
Johannes Berg77ee7c82013-02-15 00:48:33 +01003790int cfg80211_check_station_change(struct wiphy *wiphy,
3791 struct station_parameters *params,
3792 enum cfg80211_station_type statype)
3793{
3794 if (params->listen_interval != -1)
3795 return -EINVAL;
3796 if (params->aid)
3797 return -EINVAL;
3798
3799 /* When you run into this, adjust the code below for the new flag */
3800 BUILD_BUG_ON(NL80211_STA_FLAG_MAX != 7);
3801
3802 switch (statype) {
Thomas Pederseneef941e2013-03-04 13:06:11 -08003803 case CFG80211_STA_MESH_PEER_KERNEL:
3804 case CFG80211_STA_MESH_PEER_USER:
Johannes Berg77ee7c82013-02-15 00:48:33 +01003805 /*
3806 * No ignoring the TDLS flag here -- the userspace mesh
3807 * code doesn't have the bug of including TDLS in the
3808 * mask everywhere.
3809 */
3810 if (params->sta_flags_mask &
3811 ~(BIT(NL80211_STA_FLAG_AUTHENTICATED) |
3812 BIT(NL80211_STA_FLAG_MFP) |
3813 BIT(NL80211_STA_FLAG_AUTHORIZED)))
3814 return -EINVAL;
3815 break;
3816 case CFG80211_STA_TDLS_PEER_SETUP:
3817 case CFG80211_STA_TDLS_PEER_ACTIVE:
3818 if (!(params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)))
3819 return -EINVAL;
3820 /* ignore since it can't change */
3821 params->sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER);
3822 break;
3823 default:
3824 /* disallow mesh-specific things */
3825 if (params->plink_action != NL80211_PLINK_ACTION_NO_ACTION)
3826 return -EINVAL;
3827 if (params->local_pm)
3828 return -EINVAL;
3829 if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE)
3830 return -EINVAL;
3831 }
3832
3833 if (statype != CFG80211_STA_TDLS_PEER_SETUP &&
3834 statype != CFG80211_STA_TDLS_PEER_ACTIVE) {
3835 /* TDLS can't be set, ... */
3836 if (params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))
3837 return -EINVAL;
3838 /*
3839 * ... but don't bother the driver with it. This works around
3840 * a hostapd/wpa_supplicant issue -- it always includes the
3841 * TLDS_PEER flag in the mask even for AP mode.
3842 */
3843 params->sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER);
3844 }
3845
3846 if (statype != CFG80211_STA_TDLS_PEER_SETUP) {
3847 /* reject other things that can't change */
3848 if (params->sta_modify_mask & STATION_PARAM_APPLY_UAPSD)
3849 return -EINVAL;
3850 if (params->sta_modify_mask & STATION_PARAM_APPLY_CAPABILITY)
3851 return -EINVAL;
3852 if (params->supported_rates)
3853 return -EINVAL;
3854 if (params->ext_capab || params->ht_capa || params->vht_capa)
3855 return -EINVAL;
3856 }
3857
3858 if (statype != CFG80211_STA_AP_CLIENT) {
3859 if (params->vlan)
3860 return -EINVAL;
3861 }
3862
3863 switch (statype) {
3864 case CFG80211_STA_AP_MLME_CLIENT:
3865 /* Use this only for authorizing/unauthorizing a station */
3866 if (!(params->sta_flags_mask & BIT(NL80211_STA_FLAG_AUTHORIZED)))
3867 return -EOPNOTSUPP;
3868 break;
3869 case CFG80211_STA_AP_CLIENT:
3870 /* accept only the listed bits */
3871 if (params->sta_flags_mask &
3872 ~(BIT(NL80211_STA_FLAG_AUTHORIZED) |
3873 BIT(NL80211_STA_FLAG_AUTHENTICATED) |
3874 BIT(NL80211_STA_FLAG_ASSOCIATED) |
3875 BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) |
3876 BIT(NL80211_STA_FLAG_WME) |
3877 BIT(NL80211_STA_FLAG_MFP)))
3878 return -EINVAL;
3879
3880 /* but authenticated/associated only if driver handles it */
3881 if (!(wiphy->features & NL80211_FEATURE_FULL_AP_CLIENT_STATE) &&
3882 params->sta_flags_mask &
3883 (BIT(NL80211_STA_FLAG_AUTHENTICATED) |
3884 BIT(NL80211_STA_FLAG_ASSOCIATED)))
3885 return -EINVAL;
3886 break;
3887 case CFG80211_STA_IBSS:
3888 case CFG80211_STA_AP_STA:
3889 /* reject any changes other than AUTHORIZED */
3890 if (params->sta_flags_mask & ~BIT(NL80211_STA_FLAG_AUTHORIZED))
3891 return -EINVAL;
3892 break;
3893 case CFG80211_STA_TDLS_PEER_SETUP:
3894 /* reject any changes other than AUTHORIZED or WME */
3895 if (params->sta_flags_mask & ~(BIT(NL80211_STA_FLAG_AUTHORIZED) |
3896 BIT(NL80211_STA_FLAG_WME)))
3897 return -EINVAL;
3898 /* force (at least) rates when authorizing */
3899 if (params->sta_flags_set & BIT(NL80211_STA_FLAG_AUTHORIZED) &&
3900 !params->supported_rates)
3901 return -EINVAL;
3902 break;
3903 case CFG80211_STA_TDLS_PEER_ACTIVE:
3904 /* reject any changes */
3905 return -EINVAL;
Thomas Pederseneef941e2013-03-04 13:06:11 -08003906 case CFG80211_STA_MESH_PEER_KERNEL:
Johannes Berg77ee7c82013-02-15 00:48:33 +01003907 if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE)
3908 return -EINVAL;
3909 break;
Thomas Pederseneef941e2013-03-04 13:06:11 -08003910 case CFG80211_STA_MESH_PEER_USER:
Johannes Berg77ee7c82013-02-15 00:48:33 +01003911 if (params->plink_action != NL80211_PLINK_ACTION_NO_ACTION)
3912 return -EINVAL;
3913 break;
3914 }
3915
3916 return 0;
3917}
3918EXPORT_SYMBOL(cfg80211_check_station_change);
3919
Johannes Berg5727ef12007-12-19 02:03:34 +01003920/*
Felix Fietkauc258d2d2009-11-11 17:23:31 +01003921 * Get vlan interface making sure it is running and on the right wiphy.
Johannes Berg5727ef12007-12-19 02:03:34 +01003922 */
Johannes Berg80b99892011-11-18 16:23:01 +01003923static struct net_device *get_vlan(struct genl_info *info,
3924 struct cfg80211_registered_device *rdev)
Johannes Berg5727ef12007-12-19 02:03:34 +01003925{
Johannes Berg463d0182009-07-14 00:33:35 +02003926 struct nlattr *vlanattr = info->attrs[NL80211_ATTR_STA_VLAN];
Johannes Berg80b99892011-11-18 16:23:01 +01003927 struct net_device *v;
3928 int ret;
Johannes Berg5727ef12007-12-19 02:03:34 +01003929
Johannes Berg80b99892011-11-18 16:23:01 +01003930 if (!vlanattr)
3931 return NULL;
3932
3933 v = dev_get_by_index(genl_info_net(info), nla_get_u32(vlanattr));
3934 if (!v)
3935 return ERR_PTR(-ENODEV);
3936
3937 if (!v->ieee80211_ptr || v->ieee80211_ptr->wiphy != &rdev->wiphy) {
3938 ret = -EINVAL;
3939 goto error;
Johannes Berg5727ef12007-12-19 02:03:34 +01003940 }
Johannes Berg80b99892011-11-18 16:23:01 +01003941
Johannes Berg77ee7c82013-02-15 00:48:33 +01003942 if (v->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN &&
3943 v->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
3944 v->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) {
3945 ret = -EINVAL;
3946 goto error;
3947 }
3948
Johannes Berg80b99892011-11-18 16:23:01 +01003949 if (!netif_running(v)) {
3950 ret = -ENETDOWN;
3951 goto error;
3952 }
3953
3954 return v;
3955 error:
3956 dev_put(v);
3957 return ERR_PTR(ret);
Johannes Berg5727ef12007-12-19 02:03:34 +01003958}
3959
Johannes Berg94e860f2014-01-20 23:58:15 +01003960static const struct nla_policy
3961nl80211_sta_wme_policy[NL80211_STA_WME_MAX + 1] = {
Jouni Malinendf881292013-02-14 21:10:54 +02003962 [NL80211_STA_WME_UAPSD_QUEUES] = { .type = NLA_U8 },
3963 [NL80211_STA_WME_MAX_SP] = { .type = NLA_U8 },
3964};
3965
Johannes Bergff276692013-02-15 00:09:01 +01003966static int nl80211_parse_sta_wme(struct genl_info *info,
3967 struct station_parameters *params)
Jouni Malinendf881292013-02-14 21:10:54 +02003968{
Jouni Malinendf881292013-02-14 21:10:54 +02003969 struct nlattr *tb[NL80211_STA_WME_MAX + 1];
3970 struct nlattr *nla;
3971 int err;
3972
Jouni Malinendf881292013-02-14 21:10:54 +02003973 /* parse WME attributes if present */
3974 if (!info->attrs[NL80211_ATTR_STA_WME])
3975 return 0;
3976
3977 nla = info->attrs[NL80211_ATTR_STA_WME];
3978 err = nla_parse_nested(tb, NL80211_STA_WME_MAX, nla,
3979 nl80211_sta_wme_policy);
3980 if (err)
3981 return err;
3982
3983 if (tb[NL80211_STA_WME_UAPSD_QUEUES])
3984 params->uapsd_queues = nla_get_u8(
3985 tb[NL80211_STA_WME_UAPSD_QUEUES]);
3986 if (params->uapsd_queues & ~IEEE80211_WMM_IE_STA_QOSINFO_AC_MASK)
3987 return -EINVAL;
3988
3989 if (tb[NL80211_STA_WME_MAX_SP])
3990 params->max_sp = nla_get_u8(tb[NL80211_STA_WME_MAX_SP]);
3991
3992 if (params->max_sp & ~IEEE80211_WMM_IE_STA_QOSINFO_SP_MASK)
3993 return -EINVAL;
3994
3995 params->sta_modify_mask |= STATION_PARAM_APPLY_UAPSD;
3996
3997 return 0;
3998}
3999
Sunil Duttc01fc9a2013-10-09 20:45:21 +05304000static int nl80211_parse_sta_channel_info(struct genl_info *info,
4001 struct station_parameters *params)
4002{
4003 if (info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]) {
4004 params->supported_channels =
4005 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]);
4006 params->supported_channels_len =
4007 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]);
4008 /*
4009 * Need to include at least one (first channel, number of
4010 * channels) tuple for each subband, and must have proper
4011 * tuples for the rest of the data as well.
4012 */
4013 if (params->supported_channels_len < 2)
4014 return -EINVAL;
4015 if (params->supported_channels_len % 2)
4016 return -EINVAL;
4017 }
4018
4019 if (info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]) {
4020 params->supported_oper_classes =
4021 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]);
4022 params->supported_oper_classes_len =
4023 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]);
4024 /*
4025 * The value of the Length field of the Supported Operating
4026 * Classes element is between 2 and 253.
4027 */
4028 if (params->supported_oper_classes_len < 2 ||
4029 params->supported_oper_classes_len > 253)
4030 return -EINVAL;
4031 }
4032 return 0;
4033}
4034
Johannes Bergff276692013-02-15 00:09:01 +01004035static int nl80211_set_station_tdls(struct genl_info *info,
4036 struct station_parameters *params)
4037{
Sunil Duttc01fc9a2013-10-09 20:45:21 +05304038 int err;
Johannes Bergff276692013-02-15 00:09:01 +01004039 /* Dummy STA entry gets updated once the peer capabilities are known */
Jouni Malinen5e4b6f52013-05-16 20:11:08 +03004040 if (info->attrs[NL80211_ATTR_PEER_AID])
4041 params->aid = nla_get_u16(info->attrs[NL80211_ATTR_PEER_AID]);
Johannes Bergff276692013-02-15 00:09:01 +01004042 if (info->attrs[NL80211_ATTR_HT_CAPABILITY])
4043 params->ht_capa =
4044 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]);
4045 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY])
4046 params->vht_capa =
4047 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]);
4048
Sunil Duttc01fc9a2013-10-09 20:45:21 +05304049 err = nl80211_parse_sta_channel_info(info, params);
4050 if (err)
4051 return err;
4052
Johannes Bergff276692013-02-15 00:09:01 +01004053 return nl80211_parse_sta_wme(info, params);
4054}
4055
Johannes Berg5727ef12007-12-19 02:03:34 +01004056static int nl80211_set_station(struct sk_buff *skb, struct genl_info *info)
4057{
Johannes Berg4c476992010-10-04 21:36:35 +02004058 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg4c476992010-10-04 21:36:35 +02004059 struct net_device *dev = info->user_ptr[1];
Johannes Berg5727ef12007-12-19 02:03:34 +01004060 struct station_parameters params;
Johannes Berg77ee7c82013-02-15 00:48:33 +01004061 u8 *mac_addr;
4062 int err;
Johannes Berg5727ef12007-12-19 02:03:34 +01004063
4064 memset(&params, 0, sizeof(params));
4065
4066 params.listen_interval = -1;
4067
Johannes Berg77ee7c82013-02-15 00:48:33 +01004068 if (!rdev->ops->change_station)
4069 return -EOPNOTSUPP;
4070
Johannes Berg5727ef12007-12-19 02:03:34 +01004071 if (info->attrs[NL80211_ATTR_STA_AID])
4072 return -EINVAL;
4073
4074 if (!info->attrs[NL80211_ATTR_MAC])
4075 return -EINVAL;
4076
4077 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
4078
4079 if (info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) {
4080 params.supported_rates =
4081 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
4082 params.supported_rates_len =
4083 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
4084 }
4085
Jouni Malinen9d62a982013-02-14 21:10:13 +02004086 if (info->attrs[NL80211_ATTR_STA_CAPABILITY]) {
4087 params.capability =
4088 nla_get_u16(info->attrs[NL80211_ATTR_STA_CAPABILITY]);
4089 params.sta_modify_mask |= STATION_PARAM_APPLY_CAPABILITY;
4090 }
4091
4092 if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]) {
4093 params.ext_capab =
4094 nla_data(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
4095 params.ext_capab_len =
4096 nla_len(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
4097 }
4098
Jouni Malinendf881292013-02-14 21:10:54 +02004099 if (info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL])
Johannes Bergba23d202012-12-27 17:32:09 +01004100 return -EINVAL;
Jouni Malinen36aedc92008-08-25 11:58:58 +03004101
Johannes Bergbdd3ae32012-01-02 13:30:03 +01004102 if (parse_station_flags(info, dev->ieee80211_ptr->iftype, &params))
Johannes Berg5727ef12007-12-19 02:03:34 +01004103 return -EINVAL;
4104
Johannes Bergf8bacc22013-02-14 23:27:01 +01004105 if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) {
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004106 params.plink_action =
Johannes Bergf8bacc22013-02-14 23:27:01 +01004107 nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]);
4108 if (params.plink_action >= NUM_NL80211_PLINK_ACTIONS)
4109 return -EINVAL;
4110 }
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004111
Johannes Bergf8bacc22013-02-14 23:27:01 +01004112 if (info->attrs[NL80211_ATTR_STA_PLINK_STATE]) {
Javier Cardona9c3990a2011-05-03 16:57:11 -07004113 params.plink_state =
Johannes Bergf8bacc22013-02-14 23:27:01 +01004114 nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_STATE]);
4115 if (params.plink_state >= NUM_NL80211_PLINK_STATES)
4116 return -EINVAL;
4117 params.sta_modify_mask |= STATION_PARAM_APPLY_PLINK_STATE;
4118 }
Javier Cardona9c3990a2011-05-03 16:57:11 -07004119
Marco Porsch3b1c5a52013-01-07 16:04:52 +01004120 if (info->attrs[NL80211_ATTR_LOCAL_MESH_POWER_MODE]) {
4121 enum nl80211_mesh_power_mode pm = nla_get_u32(
4122 info->attrs[NL80211_ATTR_LOCAL_MESH_POWER_MODE]);
4123
4124 if (pm <= NL80211_MESH_POWER_UNKNOWN ||
4125 pm > NL80211_MESH_POWER_MAX)
4126 return -EINVAL;
4127
4128 params.local_pm = pm;
4129 }
4130
Johannes Berg77ee7c82013-02-15 00:48:33 +01004131 /* Include parameters for TDLS peer (will check later) */
4132 err = nl80211_set_station_tdls(info, &params);
4133 if (err)
4134 return err;
4135
4136 params.vlan = get_vlan(info, rdev);
4137 if (IS_ERR(params.vlan))
4138 return PTR_ERR(params.vlan);
4139
Johannes Berga97f4422009-06-18 17:23:43 +02004140 switch (dev->ieee80211_ptr->iftype) {
4141 case NL80211_IFTYPE_AP:
4142 case NL80211_IFTYPE_AP_VLAN:
Johannes Berg074ac8d2010-09-16 14:58:22 +02004143 case NL80211_IFTYPE_P2P_GO:
Johannes Berg074ac8d2010-09-16 14:58:22 +02004144 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Berga97f4422009-06-18 17:23:43 +02004145 case NL80211_IFTYPE_STATION:
Antonio Quartulli267335d2012-01-31 20:25:47 +01004146 case NL80211_IFTYPE_ADHOC:
Johannes Berga97f4422009-06-18 17:23:43 +02004147 case NL80211_IFTYPE_MESH_POINT:
Johannes Berga97f4422009-06-18 17:23:43 +02004148 break;
4149 default:
Johannes Berg77ee7c82013-02-15 00:48:33 +01004150 err = -EOPNOTSUPP;
4151 goto out_put_vlan;
Johannes Berg034d6552009-05-27 10:35:29 +02004152 }
4153
Johannes Berg77ee7c82013-02-15 00:48:33 +01004154 /* driver will call cfg80211_check_station_change() */
Hila Gonene35e4d22012-06-27 17:19:42 +03004155 err = rdev_change_station(rdev, dev, mac_addr, &params);
Johannes Berg5727ef12007-12-19 02:03:34 +01004156
Johannes Berg77ee7c82013-02-15 00:48:33 +01004157 out_put_vlan:
Johannes Berg5727ef12007-12-19 02:03:34 +01004158 if (params.vlan)
4159 dev_put(params.vlan);
Johannes Berg3b858752009-03-12 09:55:09 +01004160
Johannes Berg5727ef12007-12-19 02:03:34 +01004161 return err;
4162}
4163
4164static int nl80211_new_station(struct sk_buff *skb, struct genl_info *info)
4165{
Johannes Berg4c476992010-10-04 21:36:35 +02004166 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg5727ef12007-12-19 02:03:34 +01004167 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02004168 struct net_device *dev = info->user_ptr[1];
Johannes Berg5727ef12007-12-19 02:03:34 +01004169 struct station_parameters params;
4170 u8 *mac_addr = NULL;
4171
4172 memset(&params, 0, sizeof(params));
4173
Johannes Berg984c3112013-02-14 23:43:25 +01004174 if (!rdev->ops->add_station)
4175 return -EOPNOTSUPP;
4176
Johannes Berg5727ef12007-12-19 02:03:34 +01004177 if (!info->attrs[NL80211_ATTR_MAC])
4178 return -EINVAL;
4179
Johannes Berg5727ef12007-12-19 02:03:34 +01004180 if (!info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL])
4181 return -EINVAL;
4182
4183 if (!info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES])
4184 return -EINVAL;
4185
Jouni Malinen5e4b6f52013-05-16 20:11:08 +03004186 if (!info->attrs[NL80211_ATTR_STA_AID] &&
4187 !info->attrs[NL80211_ATTR_PEER_AID])
Thadeu Lima de Souza Cascardo0e956c12010-02-12 12:34:50 -02004188 return -EINVAL;
4189
Johannes Berg5727ef12007-12-19 02:03:34 +01004190 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
4191 params.supported_rates =
4192 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
4193 params.supported_rates_len =
4194 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
4195 params.listen_interval =
4196 nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]);
Johannes Berg51b50fb2009-05-24 16:42:30 +02004197
Jouni Malinen3d124ea2013-05-27 18:24:02 +03004198 if (info->attrs[NL80211_ATTR_PEER_AID])
Jouni Malinen5e4b6f52013-05-16 20:11:08 +03004199 params.aid = nla_get_u16(info->attrs[NL80211_ATTR_PEER_AID]);
Jouni Malinen3d124ea2013-05-27 18:24:02 +03004200 else
4201 params.aid = nla_get_u16(info->attrs[NL80211_ATTR_STA_AID]);
Thadeu Lima de Souza Cascardo0e956c12010-02-12 12:34:50 -02004202 if (!params.aid || params.aid > IEEE80211_MAX_AID)
4203 return -EINVAL;
Johannes Berg51b50fb2009-05-24 16:42:30 +02004204
Jouni Malinen9d62a982013-02-14 21:10:13 +02004205 if (info->attrs[NL80211_ATTR_STA_CAPABILITY]) {
4206 params.capability =
4207 nla_get_u16(info->attrs[NL80211_ATTR_STA_CAPABILITY]);
4208 params.sta_modify_mask |= STATION_PARAM_APPLY_CAPABILITY;
4209 }
4210
4211 if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]) {
4212 params.ext_capab =
4213 nla_data(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
4214 params.ext_capab_len =
4215 nla_len(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
4216 }
4217
Jouni Malinen36aedc92008-08-25 11:58:58 +03004218 if (info->attrs[NL80211_ATTR_HT_CAPABILITY])
4219 params.ht_capa =
4220 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]);
Johannes Berg5727ef12007-12-19 02:03:34 +01004221
Mahesh Palivelaf461be3e2012-10-11 08:04:52 +00004222 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY])
4223 params.vht_capa =
4224 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]);
4225
Marek Kwaczynski60f4a7b2013-12-03 10:04:59 +01004226 if (info->attrs[NL80211_ATTR_OPMODE_NOTIF]) {
4227 params.opmode_notif_used = true;
4228 params.opmode_notif =
4229 nla_get_u8(info->attrs[NL80211_ATTR_OPMODE_NOTIF]);
4230 }
4231
Johannes Bergf8bacc22013-02-14 23:27:01 +01004232 if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) {
Javier Cardona96b78df2011-04-07 15:08:33 -07004233 params.plink_action =
Johannes Bergf8bacc22013-02-14 23:27:01 +01004234 nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]);
4235 if (params.plink_action >= NUM_NL80211_PLINK_ACTIONS)
4236 return -EINVAL;
4237 }
Javier Cardona96b78df2011-04-07 15:08:33 -07004238
Sunil Duttc01fc9a2013-10-09 20:45:21 +05304239 err = nl80211_parse_sta_channel_info(info, &params);
4240 if (err)
4241 return err;
4242
Johannes Bergff276692013-02-15 00:09:01 +01004243 err = nl80211_parse_sta_wme(info, &params);
4244 if (err)
4245 return err;
Johannes Bergbdd90d52011-12-14 12:20:27 +01004246
Johannes Bergbdd3ae32012-01-02 13:30:03 +01004247 if (parse_station_flags(info, dev->ieee80211_ptr->iftype, &params))
Johannes Berg5727ef12007-12-19 02:03:34 +01004248 return -EINVAL;
4249
Johannes Berg77ee7c82013-02-15 00:48:33 +01004250 /* When you run into this, adjust the code below for the new flag */
4251 BUILD_BUG_ON(NL80211_STA_FLAG_MAX != 7);
4252
Johannes Bergbdd90d52011-12-14 12:20:27 +01004253 switch (dev->ieee80211_ptr->iftype) {
4254 case NL80211_IFTYPE_AP:
4255 case NL80211_IFTYPE_AP_VLAN:
4256 case NL80211_IFTYPE_P2P_GO:
Johannes Berg984c3112013-02-14 23:43:25 +01004257 /* ignore WME attributes if iface/sta is not capable */
4258 if (!(rdev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) ||
4259 !(params.sta_flags_set & BIT(NL80211_STA_FLAG_WME)))
4260 params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD;
Eliad Pellerc75786c2011-08-23 14:37:46 +03004261
Johannes Bergbdd90d52011-12-14 12:20:27 +01004262 /* TDLS peers cannot be added */
Jouni Malinen3d124ea2013-05-27 18:24:02 +03004263 if ((params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) ||
4264 info->attrs[NL80211_ATTR_PEER_AID])
Johannes Berg4319e192011-09-07 11:50:48 +02004265 return -EINVAL;
Johannes Bergbdd90d52011-12-14 12:20:27 +01004266 /* but don't bother the driver with it */
4267 params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER);
Eliad Pellerc75786c2011-08-23 14:37:46 +03004268
Johannes Bergd582cff2012-10-26 17:53:44 +02004269 /* allow authenticated/associated only if driver handles it */
4270 if (!(rdev->wiphy.features &
4271 NL80211_FEATURE_FULL_AP_CLIENT_STATE) &&
4272 params.sta_flags_mask &
4273 (BIT(NL80211_STA_FLAG_AUTHENTICATED) |
4274 BIT(NL80211_STA_FLAG_ASSOCIATED)))
4275 return -EINVAL;
4276
Johannes Bergbdd90d52011-12-14 12:20:27 +01004277 /* must be last in here for error handling */
4278 params.vlan = get_vlan(info, rdev);
4279 if (IS_ERR(params.vlan))
4280 return PTR_ERR(params.vlan);
4281 break;
4282 case NL80211_IFTYPE_MESH_POINT:
Johannes Berg984c3112013-02-14 23:43:25 +01004283 /* ignore uAPSD data */
4284 params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD;
4285
Johannes Bergd582cff2012-10-26 17:53:44 +02004286 /* associated is disallowed */
4287 if (params.sta_flags_mask & BIT(NL80211_STA_FLAG_ASSOCIATED))
4288 return -EINVAL;
Johannes Bergbdd90d52011-12-14 12:20:27 +01004289 /* TDLS peers cannot be added */
Jouni Malinen3d124ea2013-05-27 18:24:02 +03004290 if ((params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) ||
4291 info->attrs[NL80211_ATTR_PEER_AID])
Johannes Berg4319e192011-09-07 11:50:48 +02004292 return -EINVAL;
Johannes Bergbdd90d52011-12-14 12:20:27 +01004293 break;
4294 case NL80211_IFTYPE_STATION:
Johannes Berg93d08f02013-03-04 09:29:46 +01004295 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Berg984c3112013-02-14 23:43:25 +01004296 /* ignore uAPSD data */
4297 params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD;
4298
Johannes Berg77ee7c82013-02-15 00:48:33 +01004299 /* these are disallowed */
4300 if (params.sta_flags_mask &
4301 (BIT(NL80211_STA_FLAG_ASSOCIATED) |
4302 BIT(NL80211_STA_FLAG_AUTHENTICATED)))
Johannes Bergd582cff2012-10-26 17:53:44 +02004303 return -EINVAL;
Johannes Bergbdd90d52011-12-14 12:20:27 +01004304 /* Only TDLS peers can be added */
4305 if (!(params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)))
4306 return -EINVAL;
4307 /* Can only add if TDLS ... */
4308 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS))
4309 return -EOPNOTSUPP;
4310 /* ... with external setup is supported */
4311 if (!(rdev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP))
4312 return -EOPNOTSUPP;
Johannes Berg77ee7c82013-02-15 00:48:33 +01004313 /*
4314 * Older wpa_supplicant versions always mark the TDLS peer
4315 * as authorized, but it shouldn't yet be.
4316 */
4317 params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_AUTHORIZED);
Johannes Bergbdd90d52011-12-14 12:20:27 +01004318 break;
4319 default:
4320 return -EOPNOTSUPP;
Eliad Pellerc75786c2011-08-23 14:37:46 +03004321 }
4322
Johannes Bergbdd90d52011-12-14 12:20:27 +01004323 /* be aware of params.vlan when changing code here */
Johannes Berg5727ef12007-12-19 02:03:34 +01004324
Hila Gonene35e4d22012-06-27 17:19:42 +03004325 err = rdev_add_station(rdev, dev, mac_addr, &params);
Johannes Berg5727ef12007-12-19 02:03:34 +01004326
Johannes Berg5727ef12007-12-19 02:03:34 +01004327 if (params.vlan)
4328 dev_put(params.vlan);
Johannes Berg5727ef12007-12-19 02:03:34 +01004329 return err;
4330}
4331
4332static int nl80211_del_station(struct sk_buff *skb, struct genl_info *info)
4333{
Johannes Berg4c476992010-10-04 21:36:35 +02004334 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4335 struct net_device *dev = info->user_ptr[1];
Johannes Berg5727ef12007-12-19 02:03:34 +01004336 u8 *mac_addr = NULL;
4337
4338 if (info->attrs[NL80211_ATTR_MAC])
4339 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
4340
Johannes Berge80cf852009-05-11 14:43:13 +02004341 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
Marco Porschd5d9de02010-03-30 10:00:16 +02004342 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN &&
Johannes Berg074ac8d2010-09-16 14:58:22 +02004343 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT &&
Johannes Berg4c476992010-10-04 21:36:35 +02004344 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
4345 return -EINVAL;
Johannes Berge80cf852009-05-11 14:43:13 +02004346
Johannes Berg4c476992010-10-04 21:36:35 +02004347 if (!rdev->ops->del_station)
4348 return -EOPNOTSUPP;
Johannes Berg5727ef12007-12-19 02:03:34 +01004349
Hila Gonene35e4d22012-06-27 17:19:42 +03004350 return rdev_del_station(rdev, dev, mac_addr);
Johannes Berg5727ef12007-12-19 02:03:34 +01004351}
4352
Eric W. Biederman15e47302012-09-07 20:12:54 +00004353static int nl80211_send_mpath(struct sk_buff *msg, u32 portid, u32 seq,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004354 int flags, struct net_device *dev,
4355 u8 *dst, u8 *next_hop,
4356 struct mpath_info *pinfo)
4357{
4358 void *hdr;
4359 struct nlattr *pinfoattr;
4360
Eric W. Biederman15e47302012-09-07 20:12:54 +00004361 hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_STATION);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004362 if (!hdr)
4363 return -1;
4364
David S. Miller9360ffd2012-03-29 04:41:26 -04004365 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
4366 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, dst) ||
4367 nla_put(msg, NL80211_ATTR_MPATH_NEXT_HOP, ETH_ALEN, next_hop) ||
4368 nla_put_u32(msg, NL80211_ATTR_GENERATION, pinfo->generation))
4369 goto nla_put_failure;
Johannes Bergf5ea9122009-08-07 16:17:38 +02004370
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004371 pinfoattr = nla_nest_start(msg, NL80211_ATTR_MPATH_INFO);
4372 if (!pinfoattr)
4373 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04004374 if ((pinfo->filled & MPATH_INFO_FRAME_QLEN) &&
4375 nla_put_u32(msg, NL80211_MPATH_INFO_FRAME_QLEN,
4376 pinfo->frame_qlen))
4377 goto nla_put_failure;
4378 if (((pinfo->filled & MPATH_INFO_SN) &&
4379 nla_put_u32(msg, NL80211_MPATH_INFO_SN, pinfo->sn)) ||
4380 ((pinfo->filled & MPATH_INFO_METRIC) &&
4381 nla_put_u32(msg, NL80211_MPATH_INFO_METRIC,
4382 pinfo->metric)) ||
4383 ((pinfo->filled & MPATH_INFO_EXPTIME) &&
4384 nla_put_u32(msg, NL80211_MPATH_INFO_EXPTIME,
4385 pinfo->exptime)) ||
4386 ((pinfo->filled & MPATH_INFO_FLAGS) &&
4387 nla_put_u8(msg, NL80211_MPATH_INFO_FLAGS,
4388 pinfo->flags)) ||
4389 ((pinfo->filled & MPATH_INFO_DISCOVERY_TIMEOUT) &&
4390 nla_put_u32(msg, NL80211_MPATH_INFO_DISCOVERY_TIMEOUT,
4391 pinfo->discovery_timeout)) ||
4392 ((pinfo->filled & MPATH_INFO_DISCOVERY_RETRIES) &&
4393 nla_put_u8(msg, NL80211_MPATH_INFO_DISCOVERY_RETRIES,
4394 pinfo->discovery_retries)))
4395 goto nla_put_failure;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004396
4397 nla_nest_end(msg, pinfoattr);
4398
4399 return genlmsg_end(msg, hdr);
4400
4401 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07004402 genlmsg_cancel(msg, hdr);
4403 return -EMSGSIZE;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004404}
4405
4406static int nl80211_dump_mpath(struct sk_buff *skb,
Johannes Bergbba95fe2008-07-29 13:22:51 +02004407 struct netlink_callback *cb)
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004408{
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004409 struct mpath_info pinfo;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08004410 struct cfg80211_registered_device *rdev;
Johannes Berg97990a02013-04-19 01:02:55 +02004411 struct wireless_dev *wdev;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004412 u8 dst[ETH_ALEN];
4413 u8 next_hop[ETH_ALEN];
Johannes Berg97990a02013-04-19 01:02:55 +02004414 int path_idx = cb->args[2];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004415 int err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004416
Zhao, Gang1b8ec872014-04-21 12:53:02 +08004417 err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev);
Johannes Berg67748892010-10-04 21:14:06 +02004418 if (err)
4419 return err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004420
Zhao, Gang1b8ec872014-04-21 12:53:02 +08004421 if (!rdev->ops->dump_mpath) {
Jouni Malineneec60b02009-03-20 21:21:19 +02004422 err = -EOPNOTSUPP;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004423 goto out_err;
4424 }
4425
Johannes Berg97990a02013-04-19 01:02:55 +02004426 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) {
Jouni Malineneec60b02009-03-20 21:21:19 +02004427 err = -EOPNOTSUPP;
Roel Kluin0448b5f2009-08-22 21:15:49 +02004428 goto out_err;
Jouni Malineneec60b02009-03-20 21:21:19 +02004429 }
4430
Johannes Bergbba95fe2008-07-29 13:22:51 +02004431 while (1) {
Zhao, Gang1b8ec872014-04-21 12:53:02 +08004432 err = rdev_dump_mpath(rdev, wdev->netdev, path_idx, dst,
Johannes Berg97990a02013-04-19 01:02:55 +02004433 next_hop, &pinfo);
Johannes Bergbba95fe2008-07-29 13:22:51 +02004434 if (err == -ENOENT)
4435 break;
4436 if (err)
Johannes Berg3b858752009-03-12 09:55:09 +01004437 goto out_err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004438
Eric W. Biederman15e47302012-09-07 20:12:54 +00004439 if (nl80211_send_mpath(skb, NETLINK_CB(cb->skb).portid,
Johannes Bergbba95fe2008-07-29 13:22:51 +02004440 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Johannes Berg97990a02013-04-19 01:02:55 +02004441 wdev->netdev, dst, next_hop,
Johannes Bergbba95fe2008-07-29 13:22:51 +02004442 &pinfo) < 0)
4443 goto out;
4444
4445 path_idx++;
4446 }
4447
4448
4449 out:
Johannes Berg97990a02013-04-19 01:02:55 +02004450 cb->args[2] = path_idx;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004451 err = skb->len;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004452 out_err:
Zhao, Gang1b8ec872014-04-21 12:53:02 +08004453 nl80211_finish_wdev_dump(rdev);
Johannes Bergbba95fe2008-07-29 13:22:51 +02004454 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004455}
4456
4457static int nl80211_get_mpath(struct sk_buff *skb, struct genl_info *info)
4458{
Johannes Berg4c476992010-10-04 21:36:35 +02004459 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004460 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02004461 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004462 struct mpath_info pinfo;
4463 struct sk_buff *msg;
4464 u8 *dst = NULL;
4465 u8 next_hop[ETH_ALEN];
4466
4467 memset(&pinfo, 0, sizeof(pinfo));
4468
4469 if (!info->attrs[NL80211_ATTR_MAC])
4470 return -EINVAL;
4471
4472 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
4473
Johannes Berg4c476992010-10-04 21:36:35 +02004474 if (!rdev->ops->get_mpath)
4475 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01004476
Johannes Berg4c476992010-10-04 21:36:35 +02004477 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
4478 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02004479
Hila Gonene35e4d22012-06-27 17:19:42 +03004480 err = rdev_get_mpath(rdev, dev, dst, next_hop, &pinfo);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004481 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02004482 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004483
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07004484 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004485 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02004486 return -ENOMEM;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004487
Eric W. Biederman15e47302012-09-07 20:12:54 +00004488 if (nl80211_send_mpath(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berg4c476992010-10-04 21:36:35 +02004489 dev, dst, next_hop, &pinfo) < 0) {
4490 nlmsg_free(msg);
4491 return -ENOBUFS;
4492 }
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004493
Johannes Berg4c476992010-10-04 21:36:35 +02004494 return genlmsg_reply(msg, info);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004495}
4496
4497static int nl80211_set_mpath(struct sk_buff *skb, struct genl_info *info)
4498{
Johannes Berg4c476992010-10-04 21:36:35 +02004499 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4500 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004501 u8 *dst = NULL;
4502 u8 *next_hop = NULL;
4503
4504 if (!info->attrs[NL80211_ATTR_MAC])
4505 return -EINVAL;
4506
4507 if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP])
4508 return -EINVAL;
4509
4510 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
4511 next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]);
4512
Johannes Berg4c476992010-10-04 21:36:35 +02004513 if (!rdev->ops->change_mpath)
4514 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01004515
Johannes Berg4c476992010-10-04 21:36:35 +02004516 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
4517 return -EOPNOTSUPP;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004518
Hila Gonene35e4d22012-06-27 17:19:42 +03004519 return rdev_change_mpath(rdev, dev, dst, next_hop);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004520}
Johannes Berg4c476992010-10-04 21:36:35 +02004521
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004522static int nl80211_new_mpath(struct sk_buff *skb, struct genl_info *info)
4523{
Johannes Berg4c476992010-10-04 21:36:35 +02004524 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4525 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004526 u8 *dst = NULL;
4527 u8 *next_hop = NULL;
4528
4529 if (!info->attrs[NL80211_ATTR_MAC])
4530 return -EINVAL;
4531
4532 if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP])
4533 return -EINVAL;
4534
4535 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
4536 next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]);
4537
Johannes Berg4c476992010-10-04 21:36:35 +02004538 if (!rdev->ops->add_mpath)
4539 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01004540
Johannes Berg4c476992010-10-04 21:36:35 +02004541 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
4542 return -EOPNOTSUPP;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004543
Hila Gonene35e4d22012-06-27 17:19:42 +03004544 return rdev_add_mpath(rdev, dev, dst, next_hop);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004545}
4546
4547static int nl80211_del_mpath(struct sk_buff *skb, struct genl_info *info)
4548{
Johannes Berg4c476992010-10-04 21:36:35 +02004549 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4550 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004551 u8 *dst = NULL;
4552
4553 if (info->attrs[NL80211_ATTR_MAC])
4554 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
4555
Johannes Berg4c476992010-10-04 21:36:35 +02004556 if (!rdev->ops->del_mpath)
4557 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01004558
Hila Gonene35e4d22012-06-27 17:19:42 +03004559 return rdev_del_mpath(rdev, dev, dst);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004560}
4561
Jouni Malinen9f1ba902008-08-07 20:07:01 +03004562static int nl80211_set_bss(struct sk_buff *skb, struct genl_info *info)
4563{
Johannes Berg4c476992010-10-04 21:36:35 +02004564 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4565 struct net_device *dev = info->user_ptr[1];
Simon Wunderlichc56589e2013-11-21 18:19:49 +01004566 struct wireless_dev *wdev = dev->ieee80211_ptr;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03004567 struct bss_parameters params;
Simon Wunderlichc56589e2013-11-21 18:19:49 +01004568 int err;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03004569
4570 memset(&params, 0, sizeof(params));
4571 /* default to not changing parameters */
4572 params.use_cts_prot = -1;
4573 params.use_short_preamble = -1;
4574 params.use_short_slot_time = -1;
Felix Fietkaufd8aaaf2010-04-27 01:23:35 +02004575 params.ap_isolate = -1;
Helmut Schaa50b12f52010-11-19 12:40:25 +01004576 params.ht_opmode = -1;
Johannes Berg53cabad2012-11-14 15:17:28 +01004577 params.p2p_ctwindow = -1;
4578 params.p2p_opp_ps = -1;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03004579
4580 if (info->attrs[NL80211_ATTR_BSS_CTS_PROT])
4581 params.use_cts_prot =
4582 nla_get_u8(info->attrs[NL80211_ATTR_BSS_CTS_PROT]);
4583 if (info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE])
4584 params.use_short_preamble =
4585 nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]);
4586 if (info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME])
4587 params.use_short_slot_time =
4588 nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]);
Jouni Malinen90c97a02008-10-30 16:59:22 +02004589 if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) {
4590 params.basic_rates =
4591 nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
4592 params.basic_rates_len =
4593 nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
4594 }
Felix Fietkaufd8aaaf2010-04-27 01:23:35 +02004595 if (info->attrs[NL80211_ATTR_AP_ISOLATE])
4596 params.ap_isolate = !!nla_get_u8(info->attrs[NL80211_ATTR_AP_ISOLATE]);
Helmut Schaa50b12f52010-11-19 12:40:25 +01004597 if (info->attrs[NL80211_ATTR_BSS_HT_OPMODE])
4598 params.ht_opmode =
4599 nla_get_u16(info->attrs[NL80211_ATTR_BSS_HT_OPMODE]);
Jouni Malinen9f1ba902008-08-07 20:07:01 +03004600
Johannes Berg53cabad2012-11-14 15:17:28 +01004601 if (info->attrs[NL80211_ATTR_P2P_CTWINDOW]) {
4602 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
4603 return -EINVAL;
4604 params.p2p_ctwindow =
4605 nla_get_s8(info->attrs[NL80211_ATTR_P2P_CTWINDOW]);
4606 if (params.p2p_ctwindow < 0)
4607 return -EINVAL;
4608 if (params.p2p_ctwindow != 0 &&
4609 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_CTWIN))
4610 return -EINVAL;
4611 }
4612
4613 if (info->attrs[NL80211_ATTR_P2P_OPPPS]) {
4614 u8 tmp;
4615
4616 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
4617 return -EINVAL;
4618 tmp = nla_get_u8(info->attrs[NL80211_ATTR_P2P_OPPPS]);
4619 if (tmp > 1)
4620 return -EINVAL;
4621 params.p2p_opp_ps = tmp;
4622 if (params.p2p_opp_ps &&
4623 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_OPPPS))
4624 return -EINVAL;
4625 }
4626
Johannes Berg4c476992010-10-04 21:36:35 +02004627 if (!rdev->ops->change_bss)
4628 return -EOPNOTSUPP;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03004629
Johannes Berg074ac8d2010-09-16 14:58:22 +02004630 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
Johannes Berg4c476992010-10-04 21:36:35 +02004631 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
4632 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02004633
Simon Wunderlichc56589e2013-11-21 18:19:49 +01004634 wdev_lock(wdev);
4635 err = rdev_change_bss(rdev, dev, &params);
4636 wdev_unlock(wdev);
4637
4638 return err;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03004639}
4640
Alexey Dobriyanb54452b2010-02-18 08:14:31 +00004641static const struct nla_policy reg_rule_policy[NL80211_REG_RULE_ATTR_MAX + 1] = {
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004642 [NL80211_ATTR_REG_RULE_FLAGS] = { .type = NLA_U32 },
4643 [NL80211_ATTR_FREQ_RANGE_START] = { .type = NLA_U32 },
4644 [NL80211_ATTR_FREQ_RANGE_END] = { .type = NLA_U32 },
4645 [NL80211_ATTR_FREQ_RANGE_MAX_BW] = { .type = NLA_U32 },
4646 [NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN] = { .type = NLA_U32 },
4647 [NL80211_ATTR_POWER_RULE_MAX_EIRP] = { .type = NLA_U32 },
Janusz Dziedzic089027e2014-02-21 19:46:12 +01004648 [NL80211_ATTR_DFS_CAC_TIME] = { .type = NLA_U32 },
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004649};
4650
4651static int parse_reg_rule(struct nlattr *tb[],
4652 struct ieee80211_reg_rule *reg_rule)
4653{
4654 struct ieee80211_freq_range *freq_range = &reg_rule->freq_range;
4655 struct ieee80211_power_rule *power_rule = &reg_rule->power_rule;
4656
4657 if (!tb[NL80211_ATTR_REG_RULE_FLAGS])
4658 return -EINVAL;
4659 if (!tb[NL80211_ATTR_FREQ_RANGE_START])
4660 return -EINVAL;
4661 if (!tb[NL80211_ATTR_FREQ_RANGE_END])
4662 return -EINVAL;
Janusz Dziedzicb0dfd2e2014-02-20 13:52:16 +01004663 if (!tb[NL80211_ATTR_FREQ_RANGE_MAX_BW])
4664 return -EINVAL;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004665 if (!tb[NL80211_ATTR_POWER_RULE_MAX_EIRP])
4666 return -EINVAL;
4667
4668 reg_rule->flags = nla_get_u32(tb[NL80211_ATTR_REG_RULE_FLAGS]);
4669
4670 freq_range->start_freq_khz =
4671 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_START]);
4672 freq_range->end_freq_khz =
4673 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_END]);
Janusz Dziedzicb0dfd2e2014-02-20 13:52:16 +01004674 freq_range->max_bandwidth_khz =
4675 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]);
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004676
4677 power_rule->max_eirp =
4678 nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]);
4679
4680 if (tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN])
4681 power_rule->max_antenna_gain =
4682 nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]);
4683
Janusz Dziedzic089027e2014-02-21 19:46:12 +01004684 if (tb[NL80211_ATTR_DFS_CAC_TIME])
4685 reg_rule->dfs_cac_ms =
4686 nla_get_u32(tb[NL80211_ATTR_DFS_CAC_TIME]);
4687
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004688 return 0;
4689}
4690
4691static int nl80211_req_set_reg(struct sk_buff *skb, struct genl_info *info)
4692{
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004693 char *data = NULL;
Luis R. Rodriguez57b5ce02012-07-12 11:49:18 -07004694 enum nl80211_user_reg_hint_type user_reg_hint_type;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004695
Luis R. Rodriguez80778f12009-02-21 00:04:22 -05004696 /*
4697 * You should only get this when cfg80211 hasn't yet initialized
4698 * completely when built-in to the kernel right between the time
4699 * window between nl80211_init() and regulatory_init(), if that is
4700 * even possible.
4701 */
Johannes Berg458f4f92012-12-06 15:47:38 +01004702 if (unlikely(!rcu_access_pointer(cfg80211_regdomain)))
Luis R. Rodriguezfe33eb32009-02-21 00:04:30 -05004703 return -EINPROGRESS;
Luis R. Rodriguez80778f12009-02-21 00:04:22 -05004704
Luis R. Rodriguez57b5ce02012-07-12 11:49:18 -07004705 if (info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE])
4706 user_reg_hint_type =
4707 nla_get_u32(info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE]);
4708 else
4709 user_reg_hint_type = NL80211_USER_REG_HINT_USER;
4710
4711 switch (user_reg_hint_type) {
4712 case NL80211_USER_REG_HINT_USER:
4713 case NL80211_USER_REG_HINT_CELL_BASE:
Ilan Peer52616f22014-02-25 16:26:00 +02004714 if (!info->attrs[NL80211_ATTR_REG_ALPHA2])
4715 return -EINVAL;
4716
4717 data = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]);
4718 return regulatory_hint_user(data, user_reg_hint_type);
4719 case NL80211_USER_REG_HINT_INDOOR:
4720 return regulatory_hint_indoor_user();
Luis R. Rodriguez57b5ce02012-07-12 11:49:18 -07004721 default:
4722 return -EINVAL;
4723 }
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004724}
4725
Javier Cardona24bdd9f2010-12-16 17:37:48 -08004726static int nl80211_get_mesh_config(struct sk_buff *skb,
Johannes Berg29cbe682010-12-03 09:20:44 +01004727 struct genl_info *info)
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004728{
Johannes Berg4c476992010-10-04 21:36:35 +02004729 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg4c476992010-10-04 21:36:35 +02004730 struct net_device *dev = info->user_ptr[1];
Johannes Berg29cbe682010-12-03 09:20:44 +01004731 struct wireless_dev *wdev = dev->ieee80211_ptr;
4732 struct mesh_config cur_params;
4733 int err = 0;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004734 void *hdr;
4735 struct nlattr *pinfoattr;
4736 struct sk_buff *msg;
4737
Johannes Berg29cbe682010-12-03 09:20:44 +01004738 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT)
4739 return -EOPNOTSUPP;
4740
Javier Cardona24bdd9f2010-12-16 17:37:48 -08004741 if (!rdev->ops->get_mesh_config)
Johannes Berg4c476992010-10-04 21:36:35 +02004742 return -EOPNOTSUPP;
Jouni Malinenf3f92582009-03-20 17:57:36 +02004743
Johannes Berg29cbe682010-12-03 09:20:44 +01004744 wdev_lock(wdev);
4745 /* If not connected, get default parameters */
4746 if (!wdev->mesh_id_len)
4747 memcpy(&cur_params, &default_mesh_config, sizeof(cur_params));
4748 else
Hila Gonene35e4d22012-06-27 17:19:42 +03004749 err = rdev_get_mesh_config(rdev, dev, &cur_params);
Johannes Berg29cbe682010-12-03 09:20:44 +01004750 wdev_unlock(wdev);
4751
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004752 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02004753 return err;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004754
4755 /* Draw up a netlink message to send back */
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07004756 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02004757 if (!msg)
4758 return -ENOMEM;
Eric W. Biederman15e47302012-09-07 20:12:54 +00004759 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Javier Cardona24bdd9f2010-12-16 17:37:48 -08004760 NL80211_CMD_GET_MESH_CONFIG);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004761 if (!hdr)
Julia Lawallefe1cf02011-01-28 15:17:11 +01004762 goto out;
Javier Cardona24bdd9f2010-12-16 17:37:48 -08004763 pinfoattr = nla_nest_start(msg, NL80211_ATTR_MESH_CONFIG);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004764 if (!pinfoattr)
4765 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04004766 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
4767 nla_put_u16(msg, NL80211_MESHCONF_RETRY_TIMEOUT,
4768 cur_params.dot11MeshRetryTimeout) ||
4769 nla_put_u16(msg, NL80211_MESHCONF_CONFIRM_TIMEOUT,
4770 cur_params.dot11MeshConfirmTimeout) ||
4771 nla_put_u16(msg, NL80211_MESHCONF_HOLDING_TIMEOUT,
4772 cur_params.dot11MeshHoldingTimeout) ||
4773 nla_put_u16(msg, NL80211_MESHCONF_MAX_PEER_LINKS,
4774 cur_params.dot11MeshMaxPeerLinks) ||
4775 nla_put_u8(msg, NL80211_MESHCONF_MAX_RETRIES,
4776 cur_params.dot11MeshMaxRetries) ||
4777 nla_put_u8(msg, NL80211_MESHCONF_TTL,
4778 cur_params.dot11MeshTTL) ||
4779 nla_put_u8(msg, NL80211_MESHCONF_ELEMENT_TTL,
4780 cur_params.element_ttl) ||
4781 nla_put_u8(msg, NL80211_MESHCONF_AUTO_OPEN_PLINKS,
4782 cur_params.auto_open_plinks) ||
John W. Linville7eab0f62012-04-12 14:25:14 -04004783 nla_put_u32(msg, NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR,
4784 cur_params.dot11MeshNbrOffsetMaxNeighbor) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04004785 nla_put_u8(msg, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES,
4786 cur_params.dot11MeshHWMPmaxPREQretries) ||
4787 nla_put_u32(msg, NL80211_MESHCONF_PATH_REFRESH_TIME,
4788 cur_params.path_refresh_time) ||
4789 nla_put_u16(msg, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT,
4790 cur_params.min_discovery_timeout) ||
4791 nla_put_u32(msg, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT,
4792 cur_params.dot11MeshHWMPactivePathTimeout) ||
4793 nla_put_u16(msg, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL,
4794 cur_params.dot11MeshHWMPpreqMinInterval) ||
4795 nla_put_u16(msg, NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL,
4796 cur_params.dot11MeshHWMPperrMinInterval) ||
4797 nla_put_u16(msg, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME,
4798 cur_params.dot11MeshHWMPnetDiameterTraversalTime) ||
4799 nla_put_u8(msg, NL80211_MESHCONF_HWMP_ROOTMODE,
4800 cur_params.dot11MeshHWMPRootMode) ||
4801 nla_put_u16(msg, NL80211_MESHCONF_HWMP_RANN_INTERVAL,
4802 cur_params.dot11MeshHWMPRannInterval) ||
4803 nla_put_u8(msg, NL80211_MESHCONF_GATE_ANNOUNCEMENTS,
4804 cur_params.dot11MeshGateAnnouncementProtocol) ||
4805 nla_put_u8(msg, NL80211_MESHCONF_FORWARDING,
4806 cur_params.dot11MeshForwarding) ||
4807 nla_put_u32(msg, NL80211_MESHCONF_RSSI_THRESHOLD,
Ashok Nagarajan70c33ea2012-04-30 14:20:32 -07004808 cur_params.rssi_threshold) ||
4809 nla_put_u32(msg, NL80211_MESHCONF_HT_OPMODE,
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08004810 cur_params.ht_opmode) ||
4811 nla_put_u32(msg, NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT,
4812 cur_params.dot11MeshHWMPactivePathToRootTimeout) ||
4813 nla_put_u16(msg, NL80211_MESHCONF_HWMP_ROOT_INTERVAL,
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +08004814 cur_params.dot11MeshHWMProotInterval) ||
4815 nla_put_u16(msg, NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL,
Marco Porsch3b1c5a52013-01-07 16:04:52 +01004816 cur_params.dot11MeshHWMPconfirmationInterval) ||
4817 nla_put_u32(msg, NL80211_MESHCONF_POWER_MODE,
4818 cur_params.power_mode) ||
4819 nla_put_u16(msg, NL80211_MESHCONF_AWAKE_WINDOW,
Colleen Twitty8e7c0532013-06-03 09:53:39 -07004820 cur_params.dot11MeshAwakeWindowDuration) ||
4821 nla_put_u32(msg, NL80211_MESHCONF_PLINK_TIMEOUT,
4822 cur_params.plink_timeout))
David S. Miller9360ffd2012-03-29 04:41:26 -04004823 goto nla_put_failure;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004824 nla_nest_end(msg, pinfoattr);
4825 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02004826 return genlmsg_reply(msg, info);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004827
Johannes Berg3b858752009-03-12 09:55:09 +01004828 nla_put_failure:
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004829 genlmsg_cancel(msg, hdr);
Julia Lawallefe1cf02011-01-28 15:17:11 +01004830 out:
Yuri Ershovd080e272010-06-29 15:08:07 +04004831 nlmsg_free(msg);
Johannes Berg4c476992010-10-04 21:36:35 +02004832 return -ENOBUFS;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004833}
4834
Alexey Dobriyanb54452b2010-02-18 08:14:31 +00004835static const struct nla_policy nl80211_meshconf_params_policy[NL80211_MESHCONF_ATTR_MAX+1] = {
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004836 [NL80211_MESHCONF_RETRY_TIMEOUT] = { .type = NLA_U16 },
4837 [NL80211_MESHCONF_CONFIRM_TIMEOUT] = { .type = NLA_U16 },
4838 [NL80211_MESHCONF_HOLDING_TIMEOUT] = { .type = NLA_U16 },
4839 [NL80211_MESHCONF_MAX_PEER_LINKS] = { .type = NLA_U16 },
4840 [NL80211_MESHCONF_MAX_RETRIES] = { .type = NLA_U8 },
4841 [NL80211_MESHCONF_TTL] = { .type = NLA_U8 },
Javier Cardona45904f22010-12-03 09:20:40 +01004842 [NL80211_MESHCONF_ELEMENT_TTL] = { .type = NLA_U8 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004843 [NL80211_MESHCONF_AUTO_OPEN_PLINKS] = { .type = NLA_U8 },
Javier Cardonad299a1f2012-03-31 11:31:33 -07004844 [NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR] = { .type = NLA_U32 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004845 [NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES] = { .type = NLA_U8 },
4846 [NL80211_MESHCONF_PATH_REFRESH_TIME] = { .type = NLA_U32 },
4847 [NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT] = { .type = NLA_U16 },
4848 [NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT] = { .type = NLA_U32 },
4849 [NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL] = { .type = NLA_U16 },
Thomas Pedersendca7e942011-11-24 17:15:24 -08004850 [NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL] = { .type = NLA_U16 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004851 [NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME] = { .type = NLA_U16 },
Javier Cardona699403d2011-08-09 16:45:09 -07004852 [NL80211_MESHCONF_HWMP_ROOTMODE] = { .type = NLA_U8 },
Javier Cardona0507e152011-08-09 16:45:10 -07004853 [NL80211_MESHCONF_HWMP_RANN_INTERVAL] = { .type = NLA_U16 },
Javier Cardona16dd7262011-08-09 16:45:11 -07004854 [NL80211_MESHCONF_GATE_ANNOUNCEMENTS] = { .type = NLA_U8 },
Chun-Yeow Yeoh94f90652012-01-21 01:02:16 +08004855 [NL80211_MESHCONF_FORWARDING] = { .type = NLA_U8 },
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004856 [NL80211_MESHCONF_RSSI_THRESHOLD] = { .type = NLA_U32 },
4857 [NL80211_MESHCONF_HT_OPMODE] = { .type = NLA_U16 },
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08004858 [NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT] = { .type = NLA_U32 },
4859 [NL80211_MESHCONF_HWMP_ROOT_INTERVAL] = { .type = NLA_U16 },
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +08004860 [NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL] = { .type = NLA_U16 },
Marco Porsch3b1c5a52013-01-07 16:04:52 +01004861 [NL80211_MESHCONF_POWER_MODE] = { .type = NLA_U32 },
4862 [NL80211_MESHCONF_AWAKE_WINDOW] = { .type = NLA_U16 },
Colleen Twitty8e7c0532013-06-03 09:53:39 -07004863 [NL80211_MESHCONF_PLINK_TIMEOUT] = { .type = NLA_U32 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004864};
4865
Javier Cardonac80d5452010-12-16 17:37:49 -08004866static const struct nla_policy
4867 nl80211_mesh_setup_params_policy[NL80211_MESH_SETUP_ATTR_MAX+1] = {
Javier Cardonad299a1f2012-03-31 11:31:33 -07004868 [NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC] = { .type = NLA_U8 },
Javier Cardonac80d5452010-12-16 17:37:49 -08004869 [NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL] = { .type = NLA_U8 },
4870 [NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC] = { .type = NLA_U8 },
Javier Cardona15d5dda2011-04-07 15:08:28 -07004871 [NL80211_MESH_SETUP_USERSPACE_AUTH] = { .type = NLA_FLAG },
Colleen Twitty6e16d902013-05-08 11:45:59 -07004872 [NL80211_MESH_SETUP_AUTH_PROTOCOL] = { .type = NLA_U8 },
Thomas Pedersenbb2798d2013-03-04 13:06:10 -08004873 [NL80211_MESH_SETUP_USERSPACE_MPM] = { .type = NLA_FLAG },
Javier Cardona581a8b02011-04-07 15:08:27 -07004874 [NL80211_MESH_SETUP_IE] = { .type = NLA_BINARY,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004875 .len = IEEE80211_MAX_DATA_LEN },
Javier Cardonab130e5c2011-05-03 16:57:07 -07004876 [NL80211_MESH_SETUP_USERSPACE_AMPE] = { .type = NLA_FLAG },
Javier Cardonac80d5452010-12-16 17:37:49 -08004877};
4878
Javier Cardona24bdd9f2010-12-16 17:37:48 -08004879static int nl80211_parse_mesh_config(struct genl_info *info,
Johannes Bergbd90fdc2010-12-03 09:20:43 +01004880 struct mesh_config *cfg,
4881 u32 *mask_out)
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004882{
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004883 struct nlattr *tb[NL80211_MESHCONF_ATTR_MAX + 1];
Johannes Bergbd90fdc2010-12-03 09:20:43 +01004884 u32 mask = 0;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004885
Marco Porschea54fba2013-01-07 16:04:48 +01004886#define FILL_IN_MESH_PARAM_IF_SET(tb, cfg, param, min, max, mask, attr, fn) \
4887do { \
4888 if (tb[attr]) { \
4889 if (fn(tb[attr]) < min || fn(tb[attr]) > max) \
4890 return -EINVAL; \
4891 cfg->param = fn(tb[attr]); \
4892 mask |= (1 << (attr - 1)); \
4893 } \
4894} while (0)
Johannes Bergbd90fdc2010-12-03 09:20:43 +01004895
4896
Javier Cardona24bdd9f2010-12-16 17:37:48 -08004897 if (!info->attrs[NL80211_ATTR_MESH_CONFIG])
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004898 return -EINVAL;
4899 if (nla_parse_nested(tb, NL80211_MESHCONF_ATTR_MAX,
Javier Cardona24bdd9f2010-12-16 17:37:48 -08004900 info->attrs[NL80211_ATTR_MESH_CONFIG],
Johannes Bergbd90fdc2010-12-03 09:20:43 +01004901 nl80211_meshconf_params_policy))
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004902 return -EINVAL;
4903
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004904 /* This makes sure that there aren't more than 32 mesh config
4905 * parameters (otherwise our bitfield scheme would not work.) */
4906 BUILD_BUG_ON(NL80211_MESHCONF_ATTR_MAX > 32);
4907
4908 /* Fill in the params struct */
Marco Porschea54fba2013-01-07 16:04:48 +01004909 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshRetryTimeout, 1, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004910 mask, NL80211_MESHCONF_RETRY_TIMEOUT,
4911 nla_get_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01004912 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshConfirmTimeout, 1, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004913 mask, NL80211_MESHCONF_CONFIRM_TIMEOUT,
4914 nla_get_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01004915 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHoldingTimeout, 1, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004916 mask, NL80211_MESHCONF_HOLDING_TIMEOUT,
4917 nla_get_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01004918 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxPeerLinks, 0, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004919 mask, NL80211_MESHCONF_MAX_PEER_LINKS,
4920 nla_get_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01004921 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxRetries, 0, 16,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004922 mask, NL80211_MESHCONF_MAX_RETRIES,
4923 nla_get_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01004924 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshTTL, 1, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004925 mask, NL80211_MESHCONF_TTL, nla_get_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01004926 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, element_ttl, 1, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004927 mask, NL80211_MESHCONF_ELEMENT_TTL,
4928 nla_get_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01004929 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, auto_open_plinks, 0, 1,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004930 mask, NL80211_MESHCONF_AUTO_OPEN_PLINKS,
4931 nla_get_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01004932 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshNbrOffsetMaxNeighbor,
4933 1, 255, mask,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004934 NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR,
4935 nla_get_u32);
Marco Porschea54fba2013-01-07 16:04:48 +01004936 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPmaxPREQretries, 0, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004937 mask, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES,
4938 nla_get_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01004939 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, path_refresh_time, 1, 65535,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004940 mask, NL80211_MESHCONF_PATH_REFRESH_TIME,
4941 nla_get_u32);
Marco Porschea54fba2013-01-07 16:04:48 +01004942 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, min_discovery_timeout, 1, 65535,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004943 mask, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT,
4944 nla_get_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01004945 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathTimeout,
4946 1, 65535, mask,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004947 NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT,
4948 nla_get_u32);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004949 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPpreqMinInterval,
Marco Porschea54fba2013-01-07 16:04:48 +01004950 1, 65535, mask,
4951 NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004952 nla_get_u16);
Thomas Pedersendca7e942011-11-24 17:15:24 -08004953 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPperrMinInterval,
Marco Porschea54fba2013-01-07 16:04:48 +01004954 1, 65535, mask,
4955 NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004956 nla_get_u16);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004957 FILL_IN_MESH_PARAM_IF_SET(tb, cfg,
Marco Porschea54fba2013-01-07 16:04:48 +01004958 dot11MeshHWMPnetDiameterTraversalTime,
4959 1, 65535, mask,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004960 NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME,
4961 nla_get_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01004962 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRootMode, 0, 4,
4963 mask, NL80211_MESHCONF_HWMP_ROOTMODE,
4964 nla_get_u8);
4965 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRannInterval, 1, 65535,
4966 mask, NL80211_MESHCONF_HWMP_RANN_INTERVAL,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004967 nla_get_u16);
Rui Paulo63c57232009-11-09 23:46:57 +00004968 FILL_IN_MESH_PARAM_IF_SET(tb, cfg,
Marco Porschea54fba2013-01-07 16:04:48 +01004969 dot11MeshGateAnnouncementProtocol, 0, 1,
4970 mask, NL80211_MESHCONF_GATE_ANNOUNCEMENTS,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004971 nla_get_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01004972 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshForwarding, 0, 1,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004973 mask, NL80211_MESHCONF_FORWARDING,
4974 nla_get_u8);
Chun-Yeow Yeoh83374fe2013-07-11 18:24:03 +08004975 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, rssi_threshold, -255, 0,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004976 mask, NL80211_MESHCONF_RSSI_THRESHOLD,
Chun-Yeow Yeoh83374fe2013-07-11 18:24:03 +08004977 nla_get_s32);
Marco Porschea54fba2013-01-07 16:04:48 +01004978 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, ht_opmode, 0, 16,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004979 mask, NL80211_MESHCONF_HT_OPMODE,
4980 nla_get_u16);
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08004981 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathToRootTimeout,
Marco Porschea54fba2013-01-07 16:04:48 +01004982 1, 65535, mask,
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08004983 NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT,
4984 nla_get_u32);
Marco Porschea54fba2013-01-07 16:04:48 +01004985 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMProotInterval, 1, 65535,
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08004986 mask, NL80211_MESHCONF_HWMP_ROOT_INTERVAL,
4987 nla_get_u16);
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +08004988 FILL_IN_MESH_PARAM_IF_SET(tb, cfg,
Marco Porschea54fba2013-01-07 16:04:48 +01004989 dot11MeshHWMPconfirmationInterval,
4990 1, 65535, mask,
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +08004991 NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL,
4992 nla_get_u16);
Marco Porsch3b1c5a52013-01-07 16:04:52 +01004993 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, power_mode,
4994 NL80211_MESH_POWER_ACTIVE,
4995 NL80211_MESH_POWER_MAX,
4996 mask, NL80211_MESHCONF_POWER_MODE,
4997 nla_get_u32);
4998 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshAwakeWindowDuration,
4999 0, 65535, mask,
5000 NL80211_MESHCONF_AWAKE_WINDOW, nla_get_u16);
Colleen Twitty8e7c0532013-06-03 09:53:39 -07005001 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, plink_timeout, 1, 0xffffffff,
5002 mask, NL80211_MESHCONF_PLINK_TIMEOUT,
5003 nla_get_u32);
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005004 if (mask_out)
5005 *mask_out = mask;
Javier Cardonac80d5452010-12-16 17:37:49 -08005006
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005007 return 0;
5008
5009#undef FILL_IN_MESH_PARAM_IF_SET
5010}
5011
Javier Cardonac80d5452010-12-16 17:37:49 -08005012static int nl80211_parse_mesh_setup(struct genl_info *info,
5013 struct mesh_setup *setup)
5014{
Thomas Pedersenbb2798d2013-03-04 13:06:10 -08005015 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Javier Cardonac80d5452010-12-16 17:37:49 -08005016 struct nlattr *tb[NL80211_MESH_SETUP_ATTR_MAX + 1];
5017
5018 if (!info->attrs[NL80211_ATTR_MESH_SETUP])
5019 return -EINVAL;
5020 if (nla_parse_nested(tb, NL80211_MESH_SETUP_ATTR_MAX,
5021 info->attrs[NL80211_ATTR_MESH_SETUP],
5022 nl80211_mesh_setup_params_policy))
5023 return -EINVAL;
5024
Javier Cardonad299a1f2012-03-31 11:31:33 -07005025 if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC])
5026 setup->sync_method =
5027 (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC])) ?
5028 IEEE80211_SYNC_METHOD_VENDOR :
5029 IEEE80211_SYNC_METHOD_NEIGHBOR_OFFSET;
5030
Javier Cardonac80d5452010-12-16 17:37:49 -08005031 if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL])
5032 setup->path_sel_proto =
5033 (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL])) ?
5034 IEEE80211_PATH_PROTOCOL_VENDOR :
5035 IEEE80211_PATH_PROTOCOL_HWMP;
5036
5037 if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC])
5038 setup->path_metric =
5039 (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC])) ?
5040 IEEE80211_PATH_METRIC_VENDOR :
5041 IEEE80211_PATH_METRIC_AIRTIME;
5042
Javier Cardona581a8b02011-04-07 15:08:27 -07005043
5044 if (tb[NL80211_MESH_SETUP_IE]) {
Javier Cardonac80d5452010-12-16 17:37:49 -08005045 struct nlattr *ieattr =
Javier Cardona581a8b02011-04-07 15:08:27 -07005046 tb[NL80211_MESH_SETUP_IE];
Javier Cardonac80d5452010-12-16 17:37:49 -08005047 if (!is_valid_ie_attr(ieattr))
5048 return -EINVAL;
Javier Cardona581a8b02011-04-07 15:08:27 -07005049 setup->ie = nla_data(ieattr);
5050 setup->ie_len = nla_len(ieattr);
Javier Cardonac80d5452010-12-16 17:37:49 -08005051 }
Thomas Pedersenbb2798d2013-03-04 13:06:10 -08005052 if (tb[NL80211_MESH_SETUP_USERSPACE_MPM] &&
5053 !(rdev->wiphy.features & NL80211_FEATURE_USERSPACE_MPM))
5054 return -EINVAL;
5055 setup->user_mpm = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_MPM]);
Javier Cardonab130e5c2011-05-03 16:57:07 -07005056 setup->is_authenticated = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AUTH]);
5057 setup->is_secure = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AMPE]);
Thomas Pedersenbb2798d2013-03-04 13:06:10 -08005058 if (setup->is_secure)
5059 setup->user_mpm = true;
Javier Cardonac80d5452010-12-16 17:37:49 -08005060
Colleen Twitty6e16d902013-05-08 11:45:59 -07005061 if (tb[NL80211_MESH_SETUP_AUTH_PROTOCOL]) {
5062 if (!setup->user_mpm)
5063 return -EINVAL;
5064 setup->auth_id =
5065 nla_get_u8(tb[NL80211_MESH_SETUP_AUTH_PROTOCOL]);
5066 }
5067
Javier Cardonac80d5452010-12-16 17:37:49 -08005068 return 0;
5069}
5070
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005071static int nl80211_update_mesh_config(struct sk_buff *skb,
Johannes Berg29cbe682010-12-03 09:20:44 +01005072 struct genl_info *info)
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005073{
5074 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5075 struct net_device *dev = info->user_ptr[1];
Johannes Berg29cbe682010-12-03 09:20:44 +01005076 struct wireless_dev *wdev = dev->ieee80211_ptr;
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005077 struct mesh_config cfg;
5078 u32 mask;
5079 int err;
5080
Johannes Berg29cbe682010-12-03 09:20:44 +01005081 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT)
5082 return -EOPNOTSUPP;
5083
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005084 if (!rdev->ops->update_mesh_config)
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005085 return -EOPNOTSUPP;
5086
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005087 err = nl80211_parse_mesh_config(info, &cfg, &mask);
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005088 if (err)
5089 return err;
5090
Johannes Berg29cbe682010-12-03 09:20:44 +01005091 wdev_lock(wdev);
5092 if (!wdev->mesh_id_len)
5093 err = -ENOLINK;
5094
5095 if (!err)
Hila Gonene35e4d22012-06-27 17:19:42 +03005096 err = rdev_update_mesh_config(rdev, dev, mask, &cfg);
Johannes Berg29cbe682010-12-03 09:20:44 +01005097
5098 wdev_unlock(wdev);
5099
5100 return err;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005101}
5102
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005103static int nl80211_get_reg(struct sk_buff *skb, struct genl_info *info)
5104{
Johannes Berg458f4f92012-12-06 15:47:38 +01005105 const struct ieee80211_regdomain *regdom;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005106 struct sk_buff *msg;
5107 void *hdr = NULL;
5108 struct nlattr *nl_reg_rules;
5109 unsigned int i;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005110
5111 if (!cfg80211_regdomain)
Johannes Berg5fe231e2013-05-08 21:45:15 +02005112 return -EINVAL;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005113
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07005114 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg5fe231e2013-05-08 21:45:15 +02005115 if (!msg)
5116 return -ENOBUFS;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005117
Eric W. Biederman15e47302012-09-07 20:12:54 +00005118 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005119 NL80211_CMD_GET_REG);
5120 if (!hdr)
Julia Lawallefe1cf02011-01-28 15:17:11 +01005121 goto put_failure;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005122
Luis R. Rodriguez57b5ce02012-07-12 11:49:18 -07005123 if (reg_last_request_cell_base() &&
5124 nla_put_u32(msg, NL80211_ATTR_USER_REG_HINT_TYPE,
5125 NL80211_USER_REG_HINT_CELL_BASE))
5126 goto nla_put_failure;
5127
Johannes Berg458f4f92012-12-06 15:47:38 +01005128 rcu_read_lock();
5129 regdom = rcu_dereference(cfg80211_regdomain);
5130
5131 if (nla_put_string(msg, NL80211_ATTR_REG_ALPHA2, regdom->alpha2) ||
5132 (regdom->dfs_region &&
5133 nla_put_u8(msg, NL80211_ATTR_DFS_REGION, regdom->dfs_region)))
5134 goto nla_put_failure_rcu;
5135
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005136 nl_reg_rules = nla_nest_start(msg, NL80211_ATTR_REG_RULES);
5137 if (!nl_reg_rules)
Johannes Berg458f4f92012-12-06 15:47:38 +01005138 goto nla_put_failure_rcu;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005139
Johannes Berg458f4f92012-12-06 15:47:38 +01005140 for (i = 0; i < regdom->n_reg_rules; i++) {
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005141 struct nlattr *nl_reg_rule;
5142 const struct ieee80211_reg_rule *reg_rule;
5143 const struct ieee80211_freq_range *freq_range;
5144 const struct ieee80211_power_rule *power_rule;
Janusz Dziedzic97524822014-01-30 09:52:20 +01005145 unsigned int max_bandwidth_khz;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005146
Johannes Berg458f4f92012-12-06 15:47:38 +01005147 reg_rule = &regdom->reg_rules[i];
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005148 freq_range = &reg_rule->freq_range;
5149 power_rule = &reg_rule->power_rule;
5150
5151 nl_reg_rule = nla_nest_start(msg, i);
5152 if (!nl_reg_rule)
Johannes Berg458f4f92012-12-06 15:47:38 +01005153 goto nla_put_failure_rcu;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005154
Janusz Dziedzic97524822014-01-30 09:52:20 +01005155 max_bandwidth_khz = freq_range->max_bandwidth_khz;
5156 if (!max_bandwidth_khz)
5157 max_bandwidth_khz = reg_get_max_bandwidth(regdom,
5158 reg_rule);
5159
David S. Miller9360ffd2012-03-29 04:41:26 -04005160 if (nla_put_u32(msg, NL80211_ATTR_REG_RULE_FLAGS,
5161 reg_rule->flags) ||
5162 nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_START,
5163 freq_range->start_freq_khz) ||
5164 nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_END,
5165 freq_range->end_freq_khz) ||
5166 nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_MAX_BW,
Janusz Dziedzic97524822014-01-30 09:52:20 +01005167 max_bandwidth_khz) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04005168 nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN,
5169 power_rule->max_antenna_gain) ||
5170 nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_EIRP,
Janusz Dziedzic089027e2014-02-21 19:46:12 +01005171 power_rule->max_eirp) ||
5172 nla_put_u32(msg, NL80211_ATTR_DFS_CAC_TIME,
5173 reg_rule->dfs_cac_ms))
Johannes Berg458f4f92012-12-06 15:47:38 +01005174 goto nla_put_failure_rcu;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005175
5176 nla_nest_end(msg, nl_reg_rule);
5177 }
Johannes Berg458f4f92012-12-06 15:47:38 +01005178 rcu_read_unlock();
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005179
5180 nla_nest_end(msg, nl_reg_rules);
5181
5182 genlmsg_end(msg, hdr);
Johannes Berg5fe231e2013-05-08 21:45:15 +02005183 return genlmsg_reply(msg, info);
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005184
Johannes Berg458f4f92012-12-06 15:47:38 +01005185nla_put_failure_rcu:
5186 rcu_read_unlock();
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005187nla_put_failure:
5188 genlmsg_cancel(msg, hdr);
Julia Lawallefe1cf02011-01-28 15:17:11 +01005189put_failure:
Yuri Ershovd080e272010-06-29 15:08:07 +04005190 nlmsg_free(msg);
Johannes Berg5fe231e2013-05-08 21:45:15 +02005191 return -EMSGSIZE;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005192}
5193
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005194static int nl80211_set_reg(struct sk_buff *skb, struct genl_info *info)
5195{
5196 struct nlattr *tb[NL80211_REG_RULE_ATTR_MAX + 1];
5197 struct nlattr *nl_reg_rule;
5198 char *alpha2 = NULL;
5199 int rem_reg_rules = 0, r = 0;
5200 u32 num_rules = 0, rule_idx = 0, size_of_regd;
Luis R. Rodriguez4c7d3982013-11-13 18:54:02 +01005201 enum nl80211_dfs_regions dfs_region = NL80211_DFS_UNSET;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005202 struct ieee80211_regdomain *rd = NULL;
5203
5204 if (!info->attrs[NL80211_ATTR_REG_ALPHA2])
5205 return -EINVAL;
5206
5207 if (!info->attrs[NL80211_ATTR_REG_RULES])
5208 return -EINVAL;
5209
5210 alpha2 = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]);
5211
Luis R. Rodriguez8b60b072011-10-11 10:59:02 -07005212 if (info->attrs[NL80211_ATTR_DFS_REGION])
5213 dfs_region = nla_get_u8(info->attrs[NL80211_ATTR_DFS_REGION]);
5214
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005215 nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES],
Johannes Berg1a919312012-12-03 17:21:11 +01005216 rem_reg_rules) {
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005217 num_rules++;
5218 if (num_rules > NL80211_MAX_SUPP_REG_RULES)
Luis R. Rodriguez4776c6e2009-05-13 17:04:39 -04005219 return -EINVAL;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005220 }
5221
Luis R. Rodrigueze4387682013-11-05 09:18:01 -08005222 if (!reg_is_valid_request(alpha2))
5223 return -EINVAL;
5224
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005225 size_of_regd = sizeof(struct ieee80211_regdomain) +
Johannes Berg1a919312012-12-03 17:21:11 +01005226 num_rules * sizeof(struct ieee80211_reg_rule);
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005227
5228 rd = kzalloc(size_of_regd, GFP_KERNEL);
Johannes Berg6913b492012-12-04 00:48:59 +01005229 if (!rd)
5230 return -ENOMEM;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005231
5232 rd->n_reg_rules = num_rules;
5233 rd->alpha2[0] = alpha2[0];
5234 rd->alpha2[1] = alpha2[1];
5235
Luis R. Rodriguez8b60b072011-10-11 10:59:02 -07005236 /*
5237 * Disable DFS master mode if the DFS region was
5238 * not supported or known on this kernel.
5239 */
5240 if (reg_supported_dfs_region(dfs_region))
5241 rd->dfs_region = dfs_region;
5242
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005243 nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES],
Johannes Berg1a919312012-12-03 17:21:11 +01005244 rem_reg_rules) {
Johannes Bergae811e22014-01-24 10:17:47 +01005245 r = nla_parse(tb, NL80211_REG_RULE_ATTR_MAX,
5246 nla_data(nl_reg_rule), nla_len(nl_reg_rule),
5247 reg_rule_policy);
5248 if (r)
5249 goto bad_reg;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005250 r = parse_reg_rule(tb, &rd->reg_rules[rule_idx]);
5251 if (r)
5252 goto bad_reg;
5253
5254 rule_idx++;
5255
Luis R. Rodriguezd0e18f82009-05-13 17:04:40 -04005256 if (rule_idx > NL80211_MAX_SUPP_REG_RULES) {
5257 r = -EINVAL;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005258 goto bad_reg;
Luis R. Rodriguezd0e18f82009-05-13 17:04:40 -04005259 }
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005260 }
5261
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005262 r = set_regdom(rd);
Johannes Berg6913b492012-12-04 00:48:59 +01005263 /* set_regdom took ownership */
Johannes Berg1a919312012-12-03 17:21:11 +01005264 rd = NULL;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005265
Johannes Bergd2372b32008-10-24 20:32:20 +02005266 bad_reg:
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005267 kfree(rd);
Luis R. Rodriguezd0e18f82009-05-13 17:04:40 -04005268 return r;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005269}
5270
Johannes Berg83f5e2c2009-06-17 17:41:49 +02005271static int validate_scan_freqs(struct nlattr *freqs)
5272{
5273 struct nlattr *attr1, *attr2;
5274 int n_channels = 0, tmp1, tmp2;
5275
5276 nla_for_each_nested(attr1, freqs, tmp1) {
5277 n_channels++;
5278 /*
5279 * Some hardware has a limited channel list for
5280 * scanning, and it is pretty much nonsensical
5281 * to scan for a channel twice, so disallow that
5282 * and don't require drivers to check that the
5283 * channel list they get isn't longer than what
5284 * they can scan, as long as they can scan all
5285 * the channels they registered at once.
5286 */
5287 nla_for_each_nested(attr2, freqs, tmp2)
5288 if (attr1 != attr2 &&
5289 nla_get_u32(attr1) == nla_get_u32(attr2))
5290 return 0;
5291 }
5292
5293 return n_channels;
5294}
5295
Johannes Berg2a519312009-02-10 21:25:55 +01005296static int nl80211_trigger_scan(struct sk_buff *skb, struct genl_info *info)
5297{
Johannes Berg4c476992010-10-04 21:36:35 +02005298 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Bergfd014282012-06-18 19:17:03 +02005299 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg2a519312009-02-10 21:25:55 +01005300 struct cfg80211_scan_request *request;
Johannes Berg2a519312009-02-10 21:25:55 +01005301 struct nlattr *attr;
5302 struct wiphy *wiphy;
Johannes Berg83f5e2c2009-06-17 17:41:49 +02005303 int err, tmp, n_ssids = 0, n_channels, i;
Jouni Malinen70692ad2009-02-16 19:39:13 +02005304 size_t ie_len;
Johannes Berg2a519312009-02-10 21:25:55 +01005305
Johannes Bergf4a11bb2009-03-27 12:40:28 +01005306 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
5307 return -EINVAL;
5308
Johannes Berg79c97e92009-07-07 03:56:12 +02005309 wiphy = &rdev->wiphy;
Johannes Berg2a519312009-02-10 21:25:55 +01005310
Johannes Berg4c476992010-10-04 21:36:35 +02005311 if (!rdev->ops->scan)
5312 return -EOPNOTSUPP;
Johannes Berg2a519312009-02-10 21:25:55 +01005313
Johannes Bergf9d15d12014-01-22 11:14:19 +02005314 if (rdev->scan_req || rdev->scan_msg) {
Johannes Bergf9f47522013-03-19 15:04:07 +01005315 err = -EBUSY;
5316 goto unlock;
5317 }
Johannes Berg2a519312009-02-10 21:25:55 +01005318
5319 if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
Johannes Berg83f5e2c2009-06-17 17:41:49 +02005320 n_channels = validate_scan_freqs(
5321 info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]);
Johannes Bergf9f47522013-03-19 15:04:07 +01005322 if (!n_channels) {
5323 err = -EINVAL;
5324 goto unlock;
5325 }
Johannes Berg2a519312009-02-10 21:25:55 +01005326 } else {
Ilan Peerbdfbec22014-01-09 11:37:23 +02005327 n_channels = ieee80211_get_num_supported_channels(wiphy);
Johannes Berg2a519312009-02-10 21:25:55 +01005328 }
5329
5330 if (info->attrs[NL80211_ATTR_SCAN_SSIDS])
5331 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp)
5332 n_ssids++;
5333
Johannes Bergf9f47522013-03-19 15:04:07 +01005334 if (n_ssids > wiphy->max_scan_ssids) {
5335 err = -EINVAL;
5336 goto unlock;
5337 }
Johannes Berg2a519312009-02-10 21:25:55 +01005338
Jouni Malinen70692ad2009-02-16 19:39:13 +02005339 if (info->attrs[NL80211_ATTR_IE])
5340 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
5341 else
5342 ie_len = 0;
5343
Johannes Bergf9f47522013-03-19 15:04:07 +01005344 if (ie_len > wiphy->max_scan_ie_len) {
5345 err = -EINVAL;
5346 goto unlock;
5347 }
Johannes Berg18a83652009-03-31 12:12:05 +02005348
Johannes Berg2a519312009-02-10 21:25:55 +01005349 request = kzalloc(sizeof(*request)
Luciano Coelhoa2cd43c2011-05-18 11:42:03 +03005350 + sizeof(*request->ssids) * n_ssids
5351 + sizeof(*request->channels) * n_channels
Jouni Malinen70692ad2009-02-16 19:39:13 +02005352 + ie_len, GFP_KERNEL);
Johannes Bergf9f47522013-03-19 15:04:07 +01005353 if (!request) {
5354 err = -ENOMEM;
5355 goto unlock;
5356 }
Johannes Berg2a519312009-02-10 21:25:55 +01005357
Johannes Berg2a519312009-02-10 21:25:55 +01005358 if (n_ssids)
Johannes Berg5ba63532009-08-07 17:54:07 +02005359 request->ssids = (void *)&request->channels[n_channels];
Johannes Berg2a519312009-02-10 21:25:55 +01005360 request->n_ssids = n_ssids;
Jouni Malinen70692ad2009-02-16 19:39:13 +02005361 if (ie_len) {
5362 if (request->ssids)
5363 request->ie = (void *)(request->ssids + n_ssids);
5364 else
5365 request->ie = (void *)(request->channels + n_channels);
5366 }
Johannes Berg2a519312009-02-10 21:25:55 +01005367
Johannes Berg584991d2009-11-02 13:32:03 +01005368 i = 0;
Johannes Berg2a519312009-02-10 21:25:55 +01005369 if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
5370 /* user specified, bail out if channel not found */
Johannes Berg2a519312009-02-10 21:25:55 +01005371 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_FREQUENCIES], tmp) {
Johannes Berg584991d2009-11-02 13:32:03 +01005372 struct ieee80211_channel *chan;
5373
5374 chan = ieee80211_get_channel(wiphy, nla_get_u32(attr));
5375
5376 if (!chan) {
Johannes Berg2a519312009-02-10 21:25:55 +01005377 err = -EINVAL;
5378 goto out_free;
5379 }
Johannes Berg584991d2009-11-02 13:32:03 +01005380
5381 /* ignore disabled channels */
5382 if (chan->flags & IEEE80211_CHAN_DISABLED)
5383 continue;
5384
5385 request->channels[i] = chan;
Johannes Berg2a519312009-02-10 21:25:55 +01005386 i++;
5387 }
5388 } else {
Johannes Berg34850ab2011-07-18 18:08:35 +02005389 enum ieee80211_band band;
5390
Johannes Berg2a519312009-02-10 21:25:55 +01005391 /* all channels */
Johannes Berg2a519312009-02-10 21:25:55 +01005392 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
5393 int j;
5394 if (!wiphy->bands[band])
5395 continue;
5396 for (j = 0; j < wiphy->bands[band]->n_channels; j++) {
Johannes Berg584991d2009-11-02 13:32:03 +01005397 struct ieee80211_channel *chan;
5398
5399 chan = &wiphy->bands[band]->channels[j];
5400
5401 if (chan->flags & IEEE80211_CHAN_DISABLED)
5402 continue;
5403
5404 request->channels[i] = chan;
Johannes Berg2a519312009-02-10 21:25:55 +01005405 i++;
5406 }
5407 }
5408 }
5409
Johannes Berg584991d2009-11-02 13:32:03 +01005410 if (!i) {
5411 err = -EINVAL;
5412 goto out_free;
5413 }
5414
5415 request->n_channels = i;
5416
Johannes Berg2a519312009-02-10 21:25:55 +01005417 i = 0;
5418 if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) {
5419 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) {
Luciano Coelho57a27e12011-06-07 20:42:26 +03005420 if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) {
Johannes Berg2a519312009-02-10 21:25:55 +01005421 err = -EINVAL;
5422 goto out_free;
5423 }
Luciano Coelho57a27e12011-06-07 20:42:26 +03005424 request->ssids[i].ssid_len = nla_len(attr);
Johannes Berg2a519312009-02-10 21:25:55 +01005425 memcpy(request->ssids[i].ssid, nla_data(attr), nla_len(attr));
Johannes Berg2a519312009-02-10 21:25:55 +01005426 i++;
5427 }
5428 }
5429
Jouni Malinen70692ad2009-02-16 19:39:13 +02005430 if (info->attrs[NL80211_ATTR_IE]) {
5431 request->ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Johannes Bergde95a54b2009-04-01 11:58:36 +02005432 memcpy((void *)request->ie,
5433 nla_data(info->attrs[NL80211_ATTR_IE]),
Jouni Malinen70692ad2009-02-16 19:39:13 +02005434 request->ie_len);
5435 }
5436
Johannes Berg34850ab2011-07-18 18:08:35 +02005437 for (i = 0; i < IEEE80211_NUM_BANDS; i++)
Johannes Berga401d2b2011-07-20 00:52:16 +02005438 if (wiphy->bands[i])
5439 request->rates[i] =
5440 (1 << wiphy->bands[i]->n_bitrates) - 1;
Johannes Berg34850ab2011-07-18 18:08:35 +02005441
5442 if (info->attrs[NL80211_ATTR_SCAN_SUPP_RATES]) {
5443 nla_for_each_nested(attr,
5444 info->attrs[NL80211_ATTR_SCAN_SUPP_RATES],
5445 tmp) {
5446 enum ieee80211_band band = nla_type(attr);
5447
Dan Carpenter84404622011-07-29 11:52:18 +03005448 if (band < 0 || band >= IEEE80211_NUM_BANDS) {
Johannes Berg34850ab2011-07-18 18:08:35 +02005449 err = -EINVAL;
5450 goto out_free;
5451 }
Felix Fietkau1b09cd82013-11-20 19:40:41 +01005452
5453 if (!wiphy->bands[band])
5454 continue;
5455
Johannes Berg34850ab2011-07-18 18:08:35 +02005456 err = ieee80211_get_ratemask(wiphy->bands[band],
5457 nla_data(attr),
5458 nla_len(attr),
5459 &request->rates[band]);
5460 if (err)
5461 goto out_free;
5462 }
5463 }
5464
Sam Leffler46856bb2012-10-11 21:03:32 -07005465 if (info->attrs[NL80211_ATTR_SCAN_FLAGS]) {
Sam Lefflered4737712012-10-11 21:03:31 -07005466 request->flags = nla_get_u32(
5467 info->attrs[NL80211_ATTR_SCAN_FLAGS]);
Johannes Berg00c3a6e2013-10-26 17:14:38 +02005468 if ((request->flags & NL80211_SCAN_FLAG_LOW_PRIORITY) &&
5469 !(wiphy->features & NL80211_FEATURE_LOW_PRIORITY_SCAN)) {
Sam Leffler46856bb2012-10-11 21:03:32 -07005470 err = -EOPNOTSUPP;
5471 goto out_free;
5472 }
5473 }
Sam Lefflered4737712012-10-11 21:03:31 -07005474
Rajkumar Manoharane9f935e2011-09-25 14:53:30 +05305475 request->no_cck =
5476 nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]);
5477
Johannes Bergfd014282012-06-18 19:17:03 +02005478 request->wdev = wdev;
Johannes Berg79c97e92009-07-07 03:56:12 +02005479 request->wiphy = &rdev->wiphy;
Sam Leffler15d60302012-10-11 21:03:34 -07005480 request->scan_start = jiffies;
Johannes Berg2a519312009-02-10 21:25:55 +01005481
Johannes Berg79c97e92009-07-07 03:56:12 +02005482 rdev->scan_req = request;
Hila Gonene35e4d22012-06-27 17:19:42 +03005483 err = rdev_scan(rdev, request);
Johannes Berg2a519312009-02-10 21:25:55 +01005484
Johannes Berg463d0182009-07-14 00:33:35 +02005485 if (!err) {
Johannes Bergfd014282012-06-18 19:17:03 +02005486 nl80211_send_scan_start(rdev, wdev);
5487 if (wdev->netdev)
5488 dev_hold(wdev->netdev);
Johannes Berg4c476992010-10-04 21:36:35 +02005489 } else {
Johannes Berg2a519312009-02-10 21:25:55 +01005490 out_free:
Johannes Berg79c97e92009-07-07 03:56:12 +02005491 rdev->scan_req = NULL;
Johannes Berg2a519312009-02-10 21:25:55 +01005492 kfree(request);
5493 }
Johannes Berg3b858752009-03-12 09:55:09 +01005494
Johannes Bergf9f47522013-03-19 15:04:07 +01005495 unlock:
Johannes Berg2a519312009-02-10 21:25:55 +01005496 return err;
5497}
5498
Luciano Coelho807f8a82011-05-11 17:09:35 +03005499static int nl80211_start_sched_scan(struct sk_buff *skb,
5500 struct genl_info *info)
5501{
5502 struct cfg80211_sched_scan_request *request;
5503 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5504 struct net_device *dev = info->user_ptr[1];
Luciano Coelho807f8a82011-05-11 17:09:35 +03005505 struct nlattr *attr;
5506 struct wiphy *wiphy;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005507 int err, tmp, n_ssids = 0, n_match_sets = 0, n_channels, i;
Luciano Coelhobbe6ad62011-05-11 17:09:37 +03005508 u32 interval;
Luciano Coelho807f8a82011-05-11 17:09:35 +03005509 enum ieee80211_band band;
5510 size_t ie_len;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005511 struct nlattr *tb[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1];
Johannes Bergea73cbc2014-01-24 10:53:53 +01005512 s32 default_match_rssi = NL80211_SCAN_RSSI_THOLD_OFF;
Luciano Coelho807f8a82011-05-11 17:09:35 +03005513
5514 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) ||
5515 !rdev->ops->sched_scan_start)
5516 return -EOPNOTSUPP;
5517
5518 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
5519 return -EINVAL;
5520
Luciano Coelhobbe6ad62011-05-11 17:09:37 +03005521 if (!info->attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL])
5522 return -EINVAL;
5523
5524 interval = nla_get_u32(info->attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]);
5525 if (interval == 0)
5526 return -EINVAL;
5527
Luciano Coelho807f8a82011-05-11 17:09:35 +03005528 wiphy = &rdev->wiphy;
5529
5530 if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
5531 n_channels = validate_scan_freqs(
5532 info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]);
5533 if (!n_channels)
5534 return -EINVAL;
5535 } else {
Ilan Peerbdfbec22014-01-09 11:37:23 +02005536 n_channels = ieee80211_get_num_supported_channels(wiphy);
Luciano Coelho807f8a82011-05-11 17:09:35 +03005537 }
5538
5539 if (info->attrs[NL80211_ATTR_SCAN_SSIDS])
5540 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS],
5541 tmp)
5542 n_ssids++;
5543
Luciano Coelho93b6aa62011-07-13 14:57:28 +03005544 if (n_ssids > wiphy->max_sched_scan_ssids)
Luciano Coelho807f8a82011-05-11 17:09:35 +03005545 return -EINVAL;
5546
Johannes Bergea73cbc2014-01-24 10:53:53 +01005547 /*
5548 * First, count the number of 'real' matchsets. Due to an issue with
5549 * the old implementation, matchsets containing only the RSSI attribute
5550 * (NL80211_SCHED_SCAN_MATCH_ATTR_RSSI) are considered as the 'default'
5551 * RSSI for all matchsets, rather than their own matchset for reporting
5552 * all APs with a strong RSSI. This is needed to be compatible with
5553 * older userspace that treated a matchset with only the RSSI as the
5554 * global RSSI for all other matchsets - if there are other matchsets.
5555 */
5556 if (info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) {
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005557 nla_for_each_nested(attr,
5558 info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH],
Johannes Bergea73cbc2014-01-24 10:53:53 +01005559 tmp) {
5560 struct nlattr *rssi;
5561
5562 err = nla_parse(tb, NL80211_SCHED_SCAN_MATCH_ATTR_MAX,
5563 nla_data(attr), nla_len(attr),
5564 nl80211_match_policy);
5565 if (err)
5566 return err;
5567 /* add other standalone attributes here */
5568 if (tb[NL80211_SCHED_SCAN_MATCH_ATTR_SSID]) {
5569 n_match_sets++;
5570 continue;
5571 }
5572 rssi = tb[NL80211_SCHED_SCAN_MATCH_ATTR_RSSI];
5573 if (rssi)
5574 default_match_rssi = nla_get_s32(rssi);
5575 }
5576 }
5577
5578 /* However, if there's no other matchset, add the RSSI one */
5579 if (!n_match_sets && default_match_rssi != NL80211_SCAN_RSSI_THOLD_OFF)
5580 n_match_sets = 1;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005581
5582 if (n_match_sets > wiphy->max_match_sets)
5583 return -EINVAL;
5584
Luciano Coelho807f8a82011-05-11 17:09:35 +03005585 if (info->attrs[NL80211_ATTR_IE])
5586 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
5587 else
5588 ie_len = 0;
5589
Luciano Coelho5a865ba2011-07-13 14:57:29 +03005590 if (ie_len > wiphy->max_sched_scan_ie_len)
Luciano Coelho807f8a82011-05-11 17:09:35 +03005591 return -EINVAL;
5592
Luciano Coelhoc10841c2011-06-30 08:32:41 +03005593 if (rdev->sched_scan_req) {
5594 err = -EINPROGRESS;
5595 goto out;
5596 }
5597
Luciano Coelho807f8a82011-05-11 17:09:35 +03005598 request = kzalloc(sizeof(*request)
Luciano Coelhoa2cd43c2011-05-18 11:42:03 +03005599 + sizeof(*request->ssids) * n_ssids
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005600 + sizeof(*request->match_sets) * n_match_sets
Luciano Coelhoa2cd43c2011-05-18 11:42:03 +03005601 + sizeof(*request->channels) * n_channels
Luciano Coelho807f8a82011-05-11 17:09:35 +03005602 + ie_len, GFP_KERNEL);
Luciano Coelhoc10841c2011-06-30 08:32:41 +03005603 if (!request) {
5604 err = -ENOMEM;
5605 goto out;
5606 }
Luciano Coelho807f8a82011-05-11 17:09:35 +03005607
5608 if (n_ssids)
5609 request->ssids = (void *)&request->channels[n_channels];
5610 request->n_ssids = n_ssids;
5611 if (ie_len) {
5612 if (request->ssids)
5613 request->ie = (void *)(request->ssids + n_ssids);
5614 else
5615 request->ie = (void *)(request->channels + n_channels);
5616 }
5617
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005618 if (n_match_sets) {
5619 if (request->ie)
5620 request->match_sets = (void *)(request->ie + ie_len);
5621 else if (request->ssids)
5622 request->match_sets =
5623 (void *)(request->ssids + n_ssids);
5624 else
5625 request->match_sets =
5626 (void *)(request->channels + n_channels);
5627 }
5628 request->n_match_sets = n_match_sets;
5629
Luciano Coelho807f8a82011-05-11 17:09:35 +03005630 i = 0;
5631 if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
5632 /* user specified, bail out if channel not found */
5633 nla_for_each_nested(attr,
5634 info->attrs[NL80211_ATTR_SCAN_FREQUENCIES],
5635 tmp) {
5636 struct ieee80211_channel *chan;
5637
5638 chan = ieee80211_get_channel(wiphy, nla_get_u32(attr));
5639
5640 if (!chan) {
5641 err = -EINVAL;
5642 goto out_free;
5643 }
5644
5645 /* ignore disabled channels */
5646 if (chan->flags & IEEE80211_CHAN_DISABLED)
5647 continue;
5648
5649 request->channels[i] = chan;
5650 i++;
5651 }
5652 } else {
5653 /* all channels */
5654 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
5655 int j;
5656 if (!wiphy->bands[band])
5657 continue;
5658 for (j = 0; j < wiphy->bands[band]->n_channels; j++) {
5659 struct ieee80211_channel *chan;
5660
5661 chan = &wiphy->bands[band]->channels[j];
5662
5663 if (chan->flags & IEEE80211_CHAN_DISABLED)
5664 continue;
5665
5666 request->channels[i] = chan;
5667 i++;
5668 }
5669 }
5670 }
5671
5672 if (!i) {
5673 err = -EINVAL;
5674 goto out_free;
5675 }
5676
5677 request->n_channels = i;
5678
5679 i = 0;
5680 if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) {
5681 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS],
5682 tmp) {
Luciano Coelho57a27e12011-06-07 20:42:26 +03005683 if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) {
Luciano Coelho807f8a82011-05-11 17:09:35 +03005684 err = -EINVAL;
5685 goto out_free;
5686 }
Luciano Coelho57a27e12011-06-07 20:42:26 +03005687 request->ssids[i].ssid_len = nla_len(attr);
Luciano Coelho807f8a82011-05-11 17:09:35 +03005688 memcpy(request->ssids[i].ssid, nla_data(attr),
5689 nla_len(attr));
Luciano Coelho807f8a82011-05-11 17:09:35 +03005690 i++;
5691 }
5692 }
5693
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005694 i = 0;
5695 if (info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) {
5696 nla_for_each_nested(attr,
5697 info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH],
5698 tmp) {
Thomas Pedersen88e920b2012-06-21 11:09:54 -07005699 struct nlattr *ssid, *rssi;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005700
Johannes Bergae811e22014-01-24 10:17:47 +01005701 err = nla_parse(tb, NL80211_SCHED_SCAN_MATCH_ATTR_MAX,
5702 nla_data(attr), nla_len(attr),
5703 nl80211_match_policy);
5704 if (err)
5705 goto out_free;
Johannes Berg4a4ab0d2012-06-13 11:17:11 +02005706 ssid = tb[NL80211_SCHED_SCAN_MATCH_ATTR_SSID];
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005707 if (ssid) {
Johannes Bergea73cbc2014-01-24 10:53:53 +01005708 if (WARN_ON(i >= n_match_sets)) {
5709 /* this indicates a programming error,
5710 * the loop above should have verified
5711 * things properly
5712 */
5713 err = -EINVAL;
5714 goto out_free;
5715 }
5716
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005717 if (nla_len(ssid) > IEEE80211_MAX_SSID_LEN) {
5718 err = -EINVAL;
5719 goto out_free;
5720 }
5721 memcpy(request->match_sets[i].ssid.ssid,
5722 nla_data(ssid), nla_len(ssid));
5723 request->match_sets[i].ssid.ssid_len =
5724 nla_len(ssid);
Johannes Bergea73cbc2014-01-24 10:53:53 +01005725 /* special attribute - old implemenation w/a */
5726 request->match_sets[i].rssi_thold =
5727 default_match_rssi;
5728 rssi = tb[NL80211_SCHED_SCAN_MATCH_ATTR_RSSI];
5729 if (rssi)
5730 request->match_sets[i].rssi_thold =
5731 nla_get_s32(rssi);
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005732 }
5733 i++;
5734 }
Johannes Bergea73cbc2014-01-24 10:53:53 +01005735
5736 /* there was no other matchset, so the RSSI one is alone */
5737 if (i == 0)
5738 request->match_sets[0].rssi_thold = default_match_rssi;
5739
5740 request->min_rssi_thold = INT_MAX;
5741 for (i = 0; i < n_match_sets; i++)
5742 request->min_rssi_thold =
5743 min(request->match_sets[i].rssi_thold,
5744 request->min_rssi_thold);
5745 } else {
5746 request->min_rssi_thold = NL80211_SCAN_RSSI_THOLD_OFF;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005747 }
5748
Johannes Berg9900e482014-02-04 21:01:25 +01005749 if (ie_len) {
5750 request->ie_len = ie_len;
Luciano Coelho807f8a82011-05-11 17:09:35 +03005751 memcpy((void *)request->ie,
5752 nla_data(info->attrs[NL80211_ATTR_IE]),
5753 request->ie_len);
5754 }
5755
Sam Leffler46856bb2012-10-11 21:03:32 -07005756 if (info->attrs[NL80211_ATTR_SCAN_FLAGS]) {
Sam Lefflered4737712012-10-11 21:03:31 -07005757 request->flags = nla_get_u32(
5758 info->attrs[NL80211_ATTR_SCAN_FLAGS]);
Johannes Berg00c3a6e2013-10-26 17:14:38 +02005759 if ((request->flags & NL80211_SCAN_FLAG_LOW_PRIORITY) &&
5760 !(wiphy->features & NL80211_FEATURE_LOW_PRIORITY_SCAN)) {
Sam Leffler46856bb2012-10-11 21:03:32 -07005761 err = -EOPNOTSUPP;
5762 goto out_free;
5763 }
5764 }
Sam Lefflered4737712012-10-11 21:03:31 -07005765
Luciano Coelho807f8a82011-05-11 17:09:35 +03005766 request->dev = dev;
5767 request->wiphy = &rdev->wiphy;
Luciano Coelhobbe6ad62011-05-11 17:09:37 +03005768 request->interval = interval;
Sam Leffler15d60302012-10-11 21:03:34 -07005769 request->scan_start = jiffies;
Luciano Coelho807f8a82011-05-11 17:09:35 +03005770
Hila Gonene35e4d22012-06-27 17:19:42 +03005771 err = rdev_sched_scan_start(rdev, dev, request);
Luciano Coelho807f8a82011-05-11 17:09:35 +03005772 if (!err) {
5773 rdev->sched_scan_req = request;
5774 nl80211_send_sched_scan(rdev, dev,
5775 NL80211_CMD_START_SCHED_SCAN);
5776 goto out;
5777 }
5778
5779out_free:
5780 kfree(request);
5781out:
5782 return err;
5783}
5784
5785static int nl80211_stop_sched_scan(struct sk_buff *skb,
5786 struct genl_info *info)
5787{
5788 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5789
5790 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) ||
5791 !rdev->ops->sched_scan_stop)
5792 return -EOPNOTSUPP;
5793
Johannes Berg5fe231e2013-05-08 21:45:15 +02005794 return __cfg80211_stop_sched_scan(rdev, false);
Luciano Coelho807f8a82011-05-11 17:09:35 +03005795}
5796
Simon Wunderlich04f39042013-02-08 18:16:19 +01005797static int nl80211_start_radar_detection(struct sk_buff *skb,
5798 struct genl_info *info)
5799{
5800 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5801 struct net_device *dev = info->user_ptr[1];
5802 struct wireless_dev *wdev = dev->ieee80211_ptr;
5803 struct cfg80211_chan_def chandef;
Luis R. Rodriguez55f74352013-11-25 20:56:10 +01005804 enum nl80211_dfs_regions dfs_region;
Janusz Dziedzic31559f32014-02-21 19:46:13 +01005805 unsigned int cac_time_ms;
Simon Wunderlich04f39042013-02-08 18:16:19 +01005806 int err;
5807
Luis R. Rodriguez55f74352013-11-25 20:56:10 +01005808 dfs_region = reg_get_dfs_region(wdev->wiphy);
5809 if (dfs_region == NL80211_DFS_UNSET)
5810 return -EINVAL;
5811
Simon Wunderlich04f39042013-02-08 18:16:19 +01005812 err = nl80211_parse_chandef(rdev, info, &chandef);
5813 if (err)
5814 return err;
5815
Simon Wunderlichff311bc2013-09-03 19:43:18 +02005816 if (netif_carrier_ok(dev))
5817 return -EBUSY;
5818
Simon Wunderlich04f39042013-02-08 18:16:19 +01005819 if (wdev->cac_started)
5820 return -EBUSY;
5821
Luciano Coelho2beb6dab2014-02-18 11:40:36 +02005822 err = cfg80211_chandef_dfs_required(wdev->wiphy, &chandef,
5823 NL80211_IFTYPE_UNSPECIFIED);
Simon Wunderlich04f39042013-02-08 18:16:19 +01005824 if (err < 0)
5825 return err;
5826
5827 if (err == 0)
5828 return -EINVAL;
5829
Janusz Dziedzicfe7c3a12013-11-05 14:48:48 +01005830 if (!cfg80211_chandef_dfs_usable(wdev->wiphy, &chandef))
Simon Wunderlich04f39042013-02-08 18:16:19 +01005831 return -EINVAL;
5832
5833 if (!rdev->ops->start_radar_detection)
5834 return -EOPNOTSUPP;
5835
Janusz Dziedzic31559f32014-02-21 19:46:13 +01005836 cac_time_ms = cfg80211_chandef_dfs_cac_time(&rdev->wiphy, &chandef);
5837 if (WARN_ON(!cac_time_ms))
5838 cac_time_ms = IEEE80211_DFS_MIN_CAC_TIME_MS;
5839
5840 err = rdev->ops->start_radar_detection(&rdev->wiphy, dev, &chandef,
5841 cac_time_ms);
Simon Wunderlich04f39042013-02-08 18:16:19 +01005842 if (!err) {
Michal Kazior9e0e2962014-01-29 14:22:27 +01005843 wdev->chandef = chandef;
Simon Wunderlich04f39042013-02-08 18:16:19 +01005844 wdev->cac_started = true;
5845 wdev->cac_start_time = jiffies;
Janusz Dziedzic31559f32014-02-21 19:46:13 +01005846 wdev->cac_time_ms = cac_time_ms;
Simon Wunderlich04f39042013-02-08 18:16:19 +01005847 }
Simon Wunderlich04f39042013-02-08 18:16:19 +01005848 return err;
5849}
5850
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02005851static int nl80211_channel_switch(struct sk_buff *skb, struct genl_info *info)
5852{
5853 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5854 struct net_device *dev = info->user_ptr[1];
5855 struct wireless_dev *wdev = dev->ieee80211_ptr;
5856 struct cfg80211_csa_settings params;
5857 /* csa_attrs is defined static to avoid waste of stack size - this
5858 * function is called under RTNL lock, so this should not be a problem.
5859 */
5860 static struct nlattr *csa_attrs[NL80211_ATTR_MAX+1];
5861 u8 radar_detect_width = 0;
5862 int err;
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02005863 bool need_new_beacon = false;
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02005864
5865 if (!rdev->ops->channel_switch ||
5866 !(rdev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH))
5867 return -EOPNOTSUPP;
5868
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02005869 switch (dev->ieee80211_ptr->iftype) {
5870 case NL80211_IFTYPE_AP:
5871 case NL80211_IFTYPE_P2P_GO:
5872 need_new_beacon = true;
5873
5874 /* useless if AP is not running */
5875 if (!wdev->beacon_interval)
Johannes Berg1ff79df2014-01-22 10:05:27 +01005876 return -ENOTCONN;
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02005877 break;
5878 case NL80211_IFTYPE_ADHOC:
Johannes Berg1ff79df2014-01-22 10:05:27 +01005879 if (!wdev->ssid_len)
5880 return -ENOTCONN;
5881 break;
Chun-Yeow Yeohc6da6742013-10-14 19:08:28 -07005882 case NL80211_IFTYPE_MESH_POINT:
Johannes Berg1ff79df2014-01-22 10:05:27 +01005883 if (!wdev->mesh_id_len)
5884 return -ENOTCONN;
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02005885 break;
5886 default:
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02005887 return -EOPNOTSUPP;
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02005888 }
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02005889
5890 memset(&params, 0, sizeof(params));
5891
5892 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] ||
5893 !info->attrs[NL80211_ATTR_CH_SWITCH_COUNT])
5894 return -EINVAL;
5895
5896 /* only important for AP, IBSS and mesh create IEs internally */
Andrei Otcheretianskid0a361a2013-10-17 10:52:17 +02005897 if (need_new_beacon && !info->attrs[NL80211_ATTR_CSA_IES])
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02005898 return -EINVAL;
5899
5900 params.count = nla_get_u32(info->attrs[NL80211_ATTR_CH_SWITCH_COUNT]);
5901
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02005902 if (!need_new_beacon)
5903 goto skip_beacons;
5904
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02005905 err = nl80211_parse_beacon(info->attrs, &params.beacon_after);
5906 if (err)
5907 return err;
5908
5909 err = nla_parse_nested(csa_attrs, NL80211_ATTR_MAX,
5910 info->attrs[NL80211_ATTR_CSA_IES],
5911 nl80211_policy);
5912 if (err)
5913 return err;
5914
5915 err = nl80211_parse_beacon(csa_attrs, &params.beacon_csa);
5916 if (err)
5917 return err;
5918
5919 if (!csa_attrs[NL80211_ATTR_CSA_C_OFF_BEACON])
5920 return -EINVAL;
5921
5922 params.counter_offset_beacon =
5923 nla_get_u16(csa_attrs[NL80211_ATTR_CSA_C_OFF_BEACON]);
5924 if (params.counter_offset_beacon >= params.beacon_csa.tail_len)
5925 return -EINVAL;
5926
5927 /* sanity check - counters should be the same */
5928 if (params.beacon_csa.tail[params.counter_offset_beacon] !=
5929 params.count)
5930 return -EINVAL;
5931
5932 if (csa_attrs[NL80211_ATTR_CSA_C_OFF_PRESP]) {
5933 params.counter_offset_presp =
5934 nla_get_u16(csa_attrs[NL80211_ATTR_CSA_C_OFF_PRESP]);
5935 if (params.counter_offset_presp >=
5936 params.beacon_csa.probe_resp_len)
5937 return -EINVAL;
5938
5939 if (params.beacon_csa.probe_resp[params.counter_offset_presp] !=
5940 params.count)
5941 return -EINVAL;
5942 }
5943
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02005944skip_beacons:
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02005945 err = nl80211_parse_chandef(rdev, info, &params.chandef);
5946 if (err)
5947 return err;
5948
Ilan Peer174e0cd2014-02-23 09:13:01 +02005949 if (!cfg80211_reg_can_beacon(&rdev->wiphy, &params.chandef,
5950 wdev->iftype))
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02005951 return -EINVAL;
5952
Luciano Coelho2beb6dab2014-02-18 11:40:36 +02005953 err = cfg80211_chandef_dfs_required(wdev->wiphy,
5954 &params.chandef,
5955 wdev->iftype);
5956 if (err < 0)
5957 return err;
5958
5959 if (err > 0) {
5960 radar_detect_width = BIT(params.chandef.width);
5961 params.radar_required = true;
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02005962 }
5963
Luciano Coelho73de86a2014-02-13 11:31:59 +02005964 /* TODO: I left this here for now. With channel switch, the
5965 * verification is a bit more complicated, because we only do
5966 * it later when the channel switch really happens.
5967 */
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02005968 err = cfg80211_can_use_iftype_chan(rdev, wdev, wdev->iftype,
5969 params.chandef.chan,
5970 CHAN_MODE_SHARED,
5971 radar_detect_width);
5972 if (err)
5973 return err;
5974
5975 if (info->attrs[NL80211_ATTR_CH_SWITCH_BLOCK_TX])
5976 params.block_tx = true;
5977
Simon Wunderlichc56589e2013-11-21 18:19:49 +01005978 wdev_lock(wdev);
5979 err = rdev_channel_switch(rdev, dev, &params);
5980 wdev_unlock(wdev);
5981
5982 return err;
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02005983}
5984
Johannes Berg9720bb32011-06-21 09:45:33 +02005985static int nl80211_send_bss(struct sk_buff *msg, struct netlink_callback *cb,
5986 u32 seq, int flags,
Johannes Berg2a519312009-02-10 21:25:55 +01005987 struct cfg80211_registered_device *rdev,
Johannes Berg48ab9052009-07-10 18:42:31 +02005988 struct wireless_dev *wdev,
5989 struct cfg80211_internal_bss *intbss)
Johannes Berg2a519312009-02-10 21:25:55 +01005990{
Johannes Berg48ab9052009-07-10 18:42:31 +02005991 struct cfg80211_bss *res = &intbss->pub;
Johannes Berg9caf0362012-11-29 01:25:20 +01005992 const struct cfg80211_bss_ies *ies;
Johannes Berg2a519312009-02-10 21:25:55 +01005993 void *hdr;
5994 struct nlattr *bss;
Johannes Berg8cef2c92013-02-05 16:54:31 +01005995 bool tsf = false;
Johannes Berg48ab9052009-07-10 18:42:31 +02005996
5997 ASSERT_WDEV_LOCK(wdev);
Johannes Berg2a519312009-02-10 21:25:55 +01005998
Eric W. Biederman15e47302012-09-07 20:12:54 +00005999 hdr = nl80211hdr_put(msg, NETLINK_CB(cb->skb).portid, seq, flags,
Johannes Berg2a519312009-02-10 21:25:55 +01006000 NL80211_CMD_NEW_SCAN_RESULTS);
6001 if (!hdr)
6002 return -1;
6003
Johannes Berg9720bb32011-06-21 09:45:33 +02006004 genl_dump_check_consistent(cb, hdr, &nl80211_fam);
6005
Johannes Berg97990a02013-04-19 01:02:55 +02006006 if (nla_put_u32(msg, NL80211_ATTR_GENERATION, rdev->bss_generation))
6007 goto nla_put_failure;
6008 if (wdev->netdev &&
David S. Miller9360ffd2012-03-29 04:41:26 -04006009 nla_put_u32(msg, NL80211_ATTR_IFINDEX, wdev->netdev->ifindex))
6010 goto nla_put_failure;
Johannes Berg97990a02013-04-19 01:02:55 +02006011 if (nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)))
6012 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01006013
6014 bss = nla_nest_start(msg, NL80211_ATTR_BSS);
6015 if (!bss)
6016 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04006017 if ((!is_zero_ether_addr(res->bssid) &&
Johannes Berg9caf0362012-11-29 01:25:20 +01006018 nla_put(msg, NL80211_BSS_BSSID, ETH_ALEN, res->bssid)))
David S. Miller9360ffd2012-03-29 04:41:26 -04006019 goto nla_put_failure;
Johannes Berg9caf0362012-11-29 01:25:20 +01006020
6021 rcu_read_lock();
6022 ies = rcu_dereference(res->ies);
Johannes Berg8cef2c92013-02-05 16:54:31 +01006023 if (ies) {
6024 if (nla_put_u64(msg, NL80211_BSS_TSF, ies->tsf))
6025 goto fail_unlock_rcu;
6026 tsf = true;
6027 if (ies->len && nla_put(msg, NL80211_BSS_INFORMATION_ELEMENTS,
6028 ies->len, ies->data))
6029 goto fail_unlock_rcu;
Johannes Berg9caf0362012-11-29 01:25:20 +01006030 }
6031 ies = rcu_dereference(res->beacon_ies);
Johannes Berg8cef2c92013-02-05 16:54:31 +01006032 if (ies) {
6033 if (!tsf && nla_put_u64(msg, NL80211_BSS_TSF, ies->tsf))
6034 goto fail_unlock_rcu;
6035 if (ies->len && nla_put(msg, NL80211_BSS_BEACON_IES,
6036 ies->len, ies->data))
6037 goto fail_unlock_rcu;
Johannes Berg9caf0362012-11-29 01:25:20 +01006038 }
6039 rcu_read_unlock();
6040
David S. Miller9360ffd2012-03-29 04:41:26 -04006041 if (res->beacon_interval &&
6042 nla_put_u16(msg, NL80211_BSS_BEACON_INTERVAL, res->beacon_interval))
6043 goto nla_put_failure;
6044 if (nla_put_u16(msg, NL80211_BSS_CAPABILITY, res->capability) ||
6045 nla_put_u32(msg, NL80211_BSS_FREQUENCY, res->channel->center_freq) ||
Simon Wunderlichdcd6eac2013-07-08 16:55:49 +02006046 nla_put_u32(msg, NL80211_BSS_CHAN_WIDTH, res->scan_width) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04006047 nla_put_u32(msg, NL80211_BSS_SEEN_MS_AGO,
6048 jiffies_to_msecs(jiffies - intbss->ts)))
6049 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01006050
Johannes Berg77965c972009-02-18 18:45:06 +01006051 switch (rdev->wiphy.signal_type) {
Johannes Berg2a519312009-02-10 21:25:55 +01006052 case CFG80211_SIGNAL_TYPE_MBM:
David S. Miller9360ffd2012-03-29 04:41:26 -04006053 if (nla_put_u32(msg, NL80211_BSS_SIGNAL_MBM, res->signal))
6054 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01006055 break;
6056 case CFG80211_SIGNAL_TYPE_UNSPEC:
David S. Miller9360ffd2012-03-29 04:41:26 -04006057 if (nla_put_u8(msg, NL80211_BSS_SIGNAL_UNSPEC, res->signal))
6058 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01006059 break;
6060 default:
6061 break;
6062 }
6063
Johannes Berg48ab9052009-07-10 18:42:31 +02006064 switch (wdev->iftype) {
Johannes Berg074ac8d2010-09-16 14:58:22 +02006065 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Berg48ab9052009-07-10 18:42:31 +02006066 case NL80211_IFTYPE_STATION:
David S. Miller9360ffd2012-03-29 04:41:26 -04006067 if (intbss == wdev->current_bss &&
6068 nla_put_u32(msg, NL80211_BSS_STATUS,
6069 NL80211_BSS_STATUS_ASSOCIATED))
6070 goto nla_put_failure;
Johannes Berg48ab9052009-07-10 18:42:31 +02006071 break;
6072 case NL80211_IFTYPE_ADHOC:
David S. Miller9360ffd2012-03-29 04:41:26 -04006073 if (intbss == wdev->current_bss &&
6074 nla_put_u32(msg, NL80211_BSS_STATUS,
6075 NL80211_BSS_STATUS_IBSS_JOINED))
6076 goto nla_put_failure;
Johannes Berg48ab9052009-07-10 18:42:31 +02006077 break;
6078 default:
6079 break;
6080 }
6081
Johannes Berg2a519312009-02-10 21:25:55 +01006082 nla_nest_end(msg, bss);
6083
6084 return genlmsg_end(msg, hdr);
6085
Johannes Berg8cef2c92013-02-05 16:54:31 +01006086 fail_unlock_rcu:
6087 rcu_read_unlock();
Johannes Berg2a519312009-02-10 21:25:55 +01006088 nla_put_failure:
6089 genlmsg_cancel(msg, hdr);
6090 return -EMSGSIZE;
6091}
6092
Johannes Berg97990a02013-04-19 01:02:55 +02006093static int nl80211_dump_scan(struct sk_buff *skb, struct netlink_callback *cb)
Johannes Berg2a519312009-02-10 21:25:55 +01006094{
Johannes Berg48ab9052009-07-10 18:42:31 +02006095 struct cfg80211_registered_device *rdev;
Johannes Berg2a519312009-02-10 21:25:55 +01006096 struct cfg80211_internal_bss *scan;
Johannes Berg48ab9052009-07-10 18:42:31 +02006097 struct wireless_dev *wdev;
Johannes Berg97990a02013-04-19 01:02:55 +02006098 int start = cb->args[2], idx = 0;
Johannes Berg2a519312009-02-10 21:25:55 +01006099 int err;
6100
Johannes Berg97990a02013-04-19 01:02:55 +02006101 err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev);
Johannes Berg67748892010-10-04 21:14:06 +02006102 if (err)
6103 return err;
Johannes Berg2a519312009-02-10 21:25:55 +01006104
Johannes Berg48ab9052009-07-10 18:42:31 +02006105 wdev_lock(wdev);
6106 spin_lock_bh(&rdev->bss_lock);
6107 cfg80211_bss_expire(rdev);
6108
Johannes Berg9720bb32011-06-21 09:45:33 +02006109 cb->seq = rdev->bss_generation;
6110
Johannes Berg48ab9052009-07-10 18:42:31 +02006111 list_for_each_entry(scan, &rdev->bss_list, list) {
Johannes Berg2a519312009-02-10 21:25:55 +01006112 if (++idx <= start)
6113 continue;
Johannes Berg9720bb32011-06-21 09:45:33 +02006114 if (nl80211_send_bss(skb, cb,
Johannes Berg2a519312009-02-10 21:25:55 +01006115 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Johannes Berg48ab9052009-07-10 18:42:31 +02006116 rdev, wdev, scan) < 0) {
Johannes Berg2a519312009-02-10 21:25:55 +01006117 idx--;
Johannes Berg67748892010-10-04 21:14:06 +02006118 break;
Johannes Berg2a519312009-02-10 21:25:55 +01006119 }
6120 }
6121
Johannes Berg48ab9052009-07-10 18:42:31 +02006122 spin_unlock_bh(&rdev->bss_lock);
6123 wdev_unlock(wdev);
Johannes Berg2a519312009-02-10 21:25:55 +01006124
Johannes Berg97990a02013-04-19 01:02:55 +02006125 cb->args[2] = idx;
6126 nl80211_finish_wdev_dump(rdev);
Johannes Berg2a519312009-02-10 21:25:55 +01006127
Johannes Berg67748892010-10-04 21:14:06 +02006128 return skb->len;
Johannes Berg2a519312009-02-10 21:25:55 +01006129}
6130
Eric W. Biederman15e47302012-09-07 20:12:54 +00006131static int nl80211_send_survey(struct sk_buff *msg, u32 portid, u32 seq,
Holger Schurig61fa7132009-11-11 12:25:40 +01006132 int flags, struct net_device *dev,
6133 struct survey_info *survey)
6134{
6135 void *hdr;
6136 struct nlattr *infoattr;
6137
Eric W. Biederman15e47302012-09-07 20:12:54 +00006138 hdr = nl80211hdr_put(msg, portid, seq, flags,
Holger Schurig61fa7132009-11-11 12:25:40 +01006139 NL80211_CMD_NEW_SURVEY_RESULTS);
6140 if (!hdr)
6141 return -ENOMEM;
6142
David S. Miller9360ffd2012-03-29 04:41:26 -04006143 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex))
6144 goto nla_put_failure;
Holger Schurig61fa7132009-11-11 12:25:40 +01006145
6146 infoattr = nla_nest_start(msg, NL80211_ATTR_SURVEY_INFO);
6147 if (!infoattr)
6148 goto nla_put_failure;
6149
David S. Miller9360ffd2012-03-29 04:41:26 -04006150 if (nla_put_u32(msg, NL80211_SURVEY_INFO_FREQUENCY,
6151 survey->channel->center_freq))
6152 goto nla_put_failure;
6153
6154 if ((survey->filled & SURVEY_INFO_NOISE_DBM) &&
6155 nla_put_u8(msg, NL80211_SURVEY_INFO_NOISE, survey->noise))
6156 goto nla_put_failure;
6157 if ((survey->filled & SURVEY_INFO_IN_USE) &&
6158 nla_put_flag(msg, NL80211_SURVEY_INFO_IN_USE))
6159 goto nla_put_failure;
6160 if ((survey->filled & SURVEY_INFO_CHANNEL_TIME) &&
6161 nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME,
6162 survey->channel_time))
6163 goto nla_put_failure;
6164 if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_BUSY) &&
6165 nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_BUSY,
6166 survey->channel_time_busy))
6167 goto nla_put_failure;
6168 if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_EXT_BUSY) &&
6169 nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_EXT_BUSY,
6170 survey->channel_time_ext_busy))
6171 goto nla_put_failure;
6172 if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_RX) &&
6173 nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_RX,
6174 survey->channel_time_rx))
6175 goto nla_put_failure;
6176 if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_TX) &&
6177 nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_TX,
6178 survey->channel_time_tx))
6179 goto nla_put_failure;
Holger Schurig61fa7132009-11-11 12:25:40 +01006180
6181 nla_nest_end(msg, infoattr);
6182
6183 return genlmsg_end(msg, hdr);
6184
6185 nla_put_failure:
6186 genlmsg_cancel(msg, hdr);
6187 return -EMSGSIZE;
6188}
6189
6190static int nl80211_dump_survey(struct sk_buff *skb,
6191 struct netlink_callback *cb)
6192{
6193 struct survey_info survey;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08006194 struct cfg80211_registered_device *rdev;
Johannes Berg97990a02013-04-19 01:02:55 +02006195 struct wireless_dev *wdev;
6196 int survey_idx = cb->args[2];
Holger Schurig61fa7132009-11-11 12:25:40 +01006197 int res;
6198
Zhao, Gang1b8ec872014-04-21 12:53:02 +08006199 res = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev);
Johannes Berg67748892010-10-04 21:14:06 +02006200 if (res)
6201 return res;
Holger Schurig61fa7132009-11-11 12:25:40 +01006202
Johannes Berg97990a02013-04-19 01:02:55 +02006203 if (!wdev->netdev) {
6204 res = -EINVAL;
6205 goto out_err;
6206 }
6207
Zhao, Gang1b8ec872014-04-21 12:53:02 +08006208 if (!rdev->ops->dump_survey) {
Holger Schurig61fa7132009-11-11 12:25:40 +01006209 res = -EOPNOTSUPP;
6210 goto out_err;
6211 }
6212
6213 while (1) {
Luis R. Rodriguez180cdc72011-05-27 07:24:02 -07006214 struct ieee80211_channel *chan;
6215
Zhao, Gang1b8ec872014-04-21 12:53:02 +08006216 res = rdev_dump_survey(rdev, wdev->netdev, survey_idx, &survey);
Holger Schurig61fa7132009-11-11 12:25:40 +01006217 if (res == -ENOENT)
6218 break;
6219 if (res)
6220 goto out_err;
6221
Luis R. Rodriguez180cdc72011-05-27 07:24:02 -07006222 /* Survey without a channel doesn't make sense */
6223 if (!survey.channel) {
6224 res = -EINVAL;
6225 goto out;
6226 }
6227
Zhao, Gang1b8ec872014-04-21 12:53:02 +08006228 chan = ieee80211_get_channel(&rdev->wiphy,
Luis R. Rodriguez180cdc72011-05-27 07:24:02 -07006229 survey.channel->center_freq);
6230 if (!chan || chan->flags & IEEE80211_CHAN_DISABLED) {
6231 survey_idx++;
6232 continue;
6233 }
6234
Holger Schurig61fa7132009-11-11 12:25:40 +01006235 if (nl80211_send_survey(skb,
Eric W. Biederman15e47302012-09-07 20:12:54 +00006236 NETLINK_CB(cb->skb).portid,
Holger Schurig61fa7132009-11-11 12:25:40 +01006237 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Johannes Berg97990a02013-04-19 01:02:55 +02006238 wdev->netdev, &survey) < 0)
Holger Schurig61fa7132009-11-11 12:25:40 +01006239 goto out;
6240 survey_idx++;
6241 }
6242
6243 out:
Johannes Berg97990a02013-04-19 01:02:55 +02006244 cb->args[2] = survey_idx;
Holger Schurig61fa7132009-11-11 12:25:40 +01006245 res = skb->len;
6246 out_err:
Zhao, Gang1b8ec872014-04-21 12:53:02 +08006247 nl80211_finish_wdev_dump(rdev);
Holger Schurig61fa7132009-11-11 12:25:40 +01006248 return res;
6249}
6250
Samuel Ortizb23aa672009-07-01 21:26:54 +02006251static bool nl80211_valid_wpa_versions(u32 wpa_versions)
6252{
6253 return !(wpa_versions & ~(NL80211_WPA_VERSION_1 |
6254 NL80211_WPA_VERSION_2));
6255}
6256
Jouni Malinen636a5d32009-03-19 13:39:22 +02006257static int nl80211_authenticate(struct sk_buff *skb, struct genl_info *info)
6258{
Johannes Berg4c476992010-10-04 21:36:35 +02006259 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6260 struct net_device *dev = info->user_ptr[1];
Johannes Berg19957bb2009-07-02 17:20:43 +02006261 struct ieee80211_channel *chan;
Jouni Malinene39e5b52012-09-30 19:29:39 +03006262 const u8 *bssid, *ssid, *ie = NULL, *sae_data = NULL;
6263 int err, ssid_len, ie_len = 0, sae_data_len = 0;
Johannes Berg19957bb2009-07-02 17:20:43 +02006264 enum nl80211_auth_type auth_type;
Johannes Bergfffd0932009-07-08 14:22:54 +02006265 struct key_parse key;
Jouni Malinend5cdfac2010-04-04 09:37:19 +03006266 bool local_state_change;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006267
Johannes Bergf4a11bb2009-03-27 12:40:28 +01006268 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
6269 return -EINVAL;
6270
6271 if (!info->attrs[NL80211_ATTR_MAC])
6272 return -EINVAL;
6273
Jouni Malinen17780922009-03-27 20:52:47 +02006274 if (!info->attrs[NL80211_ATTR_AUTH_TYPE])
6275 return -EINVAL;
6276
Johannes Berg19957bb2009-07-02 17:20:43 +02006277 if (!info->attrs[NL80211_ATTR_SSID])
6278 return -EINVAL;
6279
6280 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ])
6281 return -EINVAL;
6282
Johannes Bergfffd0932009-07-08 14:22:54 +02006283 err = nl80211_parse_key(info, &key);
6284 if (err)
6285 return err;
6286
6287 if (key.idx >= 0) {
Johannes Berge31b8212010-10-05 19:39:30 +02006288 if (key.type != -1 && key.type != NL80211_KEYTYPE_GROUP)
6289 return -EINVAL;
Johannes Bergfffd0932009-07-08 14:22:54 +02006290 if (!key.p.key || !key.p.key_len)
6291 return -EINVAL;
6292 if ((key.p.cipher != WLAN_CIPHER_SUITE_WEP40 ||
6293 key.p.key_len != WLAN_KEY_LEN_WEP40) &&
6294 (key.p.cipher != WLAN_CIPHER_SUITE_WEP104 ||
6295 key.p.key_len != WLAN_KEY_LEN_WEP104))
6296 return -EINVAL;
6297 if (key.idx > 4)
6298 return -EINVAL;
6299 } else {
6300 key.p.key_len = 0;
6301 key.p.key = NULL;
6302 }
6303
Johannes Bergafea0b72010-08-10 09:46:42 +02006304 if (key.idx >= 0) {
6305 int i;
6306 bool ok = false;
6307 for (i = 0; i < rdev->wiphy.n_cipher_suites; i++) {
6308 if (key.p.cipher == rdev->wiphy.cipher_suites[i]) {
6309 ok = true;
6310 break;
6311 }
6312 }
Johannes Berg4c476992010-10-04 21:36:35 +02006313 if (!ok)
6314 return -EINVAL;
Johannes Bergafea0b72010-08-10 09:46:42 +02006315 }
6316
Johannes Berg4c476992010-10-04 21:36:35 +02006317 if (!rdev->ops->auth)
6318 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006319
Johannes Berg074ac8d2010-09-16 14:58:22 +02006320 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02006321 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
6322 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02006323
Johannes Berg19957bb2009-07-02 17:20:43 +02006324 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen664834d2014-01-15 00:01:44 +02006325 chan = nl80211_get_valid_chan(&rdev->wiphy,
6326 info->attrs[NL80211_ATTR_WIPHY_FREQ]);
6327 if (!chan)
Johannes Berg4c476992010-10-04 21:36:35 +02006328 return -EINVAL;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006329
Johannes Berg19957bb2009-07-02 17:20:43 +02006330 ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
6331 ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
6332
6333 if (info->attrs[NL80211_ATTR_IE]) {
6334 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
6335 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
6336 }
6337
6338 auth_type = nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]);
Jouni Malinene39e5b52012-09-30 19:29:39 +03006339 if (!nl80211_valid_auth_type(rdev, auth_type, NL80211_CMD_AUTHENTICATE))
Johannes Berg4c476992010-10-04 21:36:35 +02006340 return -EINVAL;
Johannes Berg19957bb2009-07-02 17:20:43 +02006341
Jouni Malinene39e5b52012-09-30 19:29:39 +03006342 if (auth_type == NL80211_AUTHTYPE_SAE &&
6343 !info->attrs[NL80211_ATTR_SAE_DATA])
6344 return -EINVAL;
6345
6346 if (info->attrs[NL80211_ATTR_SAE_DATA]) {
6347 if (auth_type != NL80211_AUTHTYPE_SAE)
6348 return -EINVAL;
6349 sae_data = nla_data(info->attrs[NL80211_ATTR_SAE_DATA]);
6350 sae_data_len = nla_len(info->attrs[NL80211_ATTR_SAE_DATA]);
6351 /* need to include at least Auth Transaction and Status Code */
6352 if (sae_data_len < 4)
6353 return -EINVAL;
6354 }
6355
Jouni Malinend5cdfac2010-04-04 09:37:19 +03006356 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE];
6357
Johannes Berg95de8172012-01-20 13:55:25 +01006358 /*
6359 * Since we no longer track auth state, ignore
6360 * requests to only change local state.
6361 */
6362 if (local_state_change)
6363 return 0;
6364
Johannes Berg91bf9b22013-05-15 17:44:01 +02006365 wdev_lock(dev->ieee80211_ptr);
6366 err = cfg80211_mlme_auth(rdev, dev, chan, auth_type, bssid,
6367 ssid, ssid_len, ie, ie_len,
6368 key.p.key, key.p.key_len, key.idx,
6369 sae_data, sae_data_len);
6370 wdev_unlock(dev->ieee80211_ptr);
6371 return err;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006372}
6373
Johannes Bergc0692b82010-08-27 14:26:53 +03006374static int nl80211_crypto_settings(struct cfg80211_registered_device *rdev,
6375 struct genl_info *info,
Johannes Berg3dc27d22009-07-02 21:36:37 +02006376 struct cfg80211_crypto_settings *settings,
6377 int cipher_limit)
Samuel Ortizb23aa672009-07-01 21:26:54 +02006378{
Johannes Bergc0b2bbd2009-07-25 16:54:36 +02006379 memset(settings, 0, sizeof(*settings));
6380
Samuel Ortizb23aa672009-07-01 21:26:54 +02006381 settings->control_port = info->attrs[NL80211_ATTR_CONTROL_PORT];
6382
Johannes Bergc0692b82010-08-27 14:26:53 +03006383 if (info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]) {
6384 u16 proto;
6385 proto = nla_get_u16(
6386 info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]);
6387 settings->control_port_ethertype = cpu_to_be16(proto);
6388 if (!(rdev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) &&
6389 proto != ETH_P_PAE)
6390 return -EINVAL;
6391 if (info->attrs[NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT])
6392 settings->control_port_no_encrypt = true;
6393 } else
6394 settings->control_port_ethertype = cpu_to_be16(ETH_P_PAE);
6395
Samuel Ortizb23aa672009-07-01 21:26:54 +02006396 if (info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]) {
6397 void *data;
6398 int len, i;
6399
6400 data = nla_data(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]);
6401 len = nla_len(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]);
6402 settings->n_ciphers_pairwise = len / sizeof(u32);
6403
6404 if (len % sizeof(u32))
6405 return -EINVAL;
6406
Johannes Berg3dc27d22009-07-02 21:36:37 +02006407 if (settings->n_ciphers_pairwise > cipher_limit)
Samuel Ortizb23aa672009-07-01 21:26:54 +02006408 return -EINVAL;
6409
6410 memcpy(settings->ciphers_pairwise, data, len);
6411
6412 for (i = 0; i < settings->n_ciphers_pairwise; i++)
Jouni Malinen38ba3c52011-09-21 18:14:56 +03006413 if (!cfg80211_supported_cipher_suite(
6414 &rdev->wiphy,
Samuel Ortizb23aa672009-07-01 21:26:54 +02006415 settings->ciphers_pairwise[i]))
6416 return -EINVAL;
6417 }
6418
6419 if (info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]) {
6420 settings->cipher_group =
6421 nla_get_u32(info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]);
Jouni Malinen38ba3c52011-09-21 18:14:56 +03006422 if (!cfg80211_supported_cipher_suite(&rdev->wiphy,
6423 settings->cipher_group))
Samuel Ortizb23aa672009-07-01 21:26:54 +02006424 return -EINVAL;
6425 }
6426
6427 if (info->attrs[NL80211_ATTR_WPA_VERSIONS]) {
6428 settings->wpa_versions =
6429 nla_get_u32(info->attrs[NL80211_ATTR_WPA_VERSIONS]);
6430 if (!nl80211_valid_wpa_versions(settings->wpa_versions))
6431 return -EINVAL;
6432 }
6433
6434 if (info->attrs[NL80211_ATTR_AKM_SUITES]) {
6435 void *data;
Jouni Malinen6d302402011-09-21 18:11:33 +03006436 int len;
Samuel Ortizb23aa672009-07-01 21:26:54 +02006437
6438 data = nla_data(info->attrs[NL80211_ATTR_AKM_SUITES]);
6439 len = nla_len(info->attrs[NL80211_ATTR_AKM_SUITES]);
6440 settings->n_akm_suites = len / sizeof(u32);
6441
6442 if (len % sizeof(u32))
6443 return -EINVAL;
6444
Jouni Malinen1b9ca022011-09-21 16:13:07 +03006445 if (settings->n_akm_suites > NL80211_MAX_NR_AKM_SUITES)
6446 return -EINVAL;
6447
Samuel Ortizb23aa672009-07-01 21:26:54 +02006448 memcpy(settings->akm_suites, data, len);
Samuel Ortizb23aa672009-07-01 21:26:54 +02006449 }
6450
6451 return 0;
6452}
6453
Jouni Malinen636a5d32009-03-19 13:39:22 +02006454static int nl80211_associate(struct sk_buff *skb, struct genl_info *info)
6455{
Johannes Berg4c476992010-10-04 21:36:35 +02006456 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6457 struct net_device *dev = info->user_ptr[1];
Johannes Bergf444de02010-05-05 15:25:02 +02006458 struct ieee80211_channel *chan;
Johannes Bergf62fab72013-02-21 20:09:09 +01006459 struct cfg80211_assoc_request req = {};
6460 const u8 *bssid, *ssid;
6461 int err, ssid_len = 0;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006462
Johannes Bergf4a11bb2009-03-27 12:40:28 +01006463 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
6464 return -EINVAL;
6465
6466 if (!info->attrs[NL80211_ATTR_MAC] ||
Johannes Berg19957bb2009-07-02 17:20:43 +02006467 !info->attrs[NL80211_ATTR_SSID] ||
6468 !info->attrs[NL80211_ATTR_WIPHY_FREQ])
Johannes Bergf4a11bb2009-03-27 12:40:28 +01006469 return -EINVAL;
6470
Johannes Berg4c476992010-10-04 21:36:35 +02006471 if (!rdev->ops->assoc)
6472 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006473
Johannes Berg074ac8d2010-09-16 14:58:22 +02006474 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02006475 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
6476 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02006477
Johannes Berg19957bb2009-07-02 17:20:43 +02006478 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02006479
Jouni Malinen664834d2014-01-15 00:01:44 +02006480 chan = nl80211_get_valid_chan(&rdev->wiphy,
6481 info->attrs[NL80211_ATTR_WIPHY_FREQ]);
6482 if (!chan)
Johannes Berg4c476992010-10-04 21:36:35 +02006483 return -EINVAL;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006484
Johannes Berg19957bb2009-07-02 17:20:43 +02006485 ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
6486 ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02006487
6488 if (info->attrs[NL80211_ATTR_IE]) {
Johannes Bergf62fab72013-02-21 20:09:09 +01006489 req.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
6490 req.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02006491 }
6492
Jouni Malinendc6382ce2009-05-06 22:09:37 +03006493 if (info->attrs[NL80211_ATTR_USE_MFP]) {
Johannes Berg4f5dadc2009-07-07 03:56:10 +02006494 enum nl80211_mfp mfp =
Jouni Malinendc6382ce2009-05-06 22:09:37 +03006495 nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]);
Johannes Berg4f5dadc2009-07-07 03:56:10 +02006496 if (mfp == NL80211_MFP_REQUIRED)
Johannes Bergf62fab72013-02-21 20:09:09 +01006497 req.use_mfp = true;
Johannes Berg4c476992010-10-04 21:36:35 +02006498 else if (mfp != NL80211_MFP_NO)
6499 return -EINVAL;
Jouni Malinendc6382ce2009-05-06 22:09:37 +03006500 }
6501
Johannes Berg3e5d7642009-07-07 14:37:26 +02006502 if (info->attrs[NL80211_ATTR_PREV_BSSID])
Johannes Bergf62fab72013-02-21 20:09:09 +01006503 req.prev_bssid = nla_data(info->attrs[NL80211_ATTR_PREV_BSSID]);
Johannes Berg3e5d7642009-07-07 14:37:26 +02006504
Ben Greear7e7c8922011-11-18 11:31:59 -08006505 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT]))
Johannes Bergf62fab72013-02-21 20:09:09 +01006506 req.flags |= ASSOC_REQ_DISABLE_HT;
Ben Greear7e7c8922011-11-18 11:31:59 -08006507
6508 if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
Johannes Bergf62fab72013-02-21 20:09:09 +01006509 memcpy(&req.ht_capa_mask,
6510 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]),
6511 sizeof(req.ht_capa_mask));
Ben Greear7e7c8922011-11-18 11:31:59 -08006512
6513 if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) {
Johannes Bergf62fab72013-02-21 20:09:09 +01006514 if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
Ben Greear7e7c8922011-11-18 11:31:59 -08006515 return -EINVAL;
Johannes Bergf62fab72013-02-21 20:09:09 +01006516 memcpy(&req.ht_capa,
6517 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]),
6518 sizeof(req.ht_capa));
Ben Greear7e7c8922011-11-18 11:31:59 -08006519 }
6520
Johannes Bergee2aca32013-02-21 17:36:01 +01006521 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_VHT]))
Johannes Bergf62fab72013-02-21 20:09:09 +01006522 req.flags |= ASSOC_REQ_DISABLE_VHT;
Johannes Bergee2aca32013-02-21 17:36:01 +01006523
6524 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK])
Johannes Bergf62fab72013-02-21 20:09:09 +01006525 memcpy(&req.vht_capa_mask,
6526 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]),
6527 sizeof(req.vht_capa_mask));
Johannes Bergee2aca32013-02-21 17:36:01 +01006528
6529 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) {
Johannes Bergf62fab72013-02-21 20:09:09 +01006530 if (!info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK])
Johannes Bergee2aca32013-02-21 17:36:01 +01006531 return -EINVAL;
Johannes Bergf62fab72013-02-21 20:09:09 +01006532 memcpy(&req.vht_capa,
6533 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]),
6534 sizeof(req.vht_capa));
Johannes Bergee2aca32013-02-21 17:36:01 +01006535 }
6536
Johannes Bergf62fab72013-02-21 20:09:09 +01006537 err = nl80211_crypto_settings(rdev, info, &req.crypto, 1);
Johannes Berg91bf9b22013-05-15 17:44:01 +02006538 if (!err) {
6539 wdev_lock(dev->ieee80211_ptr);
Johannes Bergf62fab72013-02-21 20:09:09 +01006540 err = cfg80211_mlme_assoc(rdev, dev, chan, bssid,
6541 ssid, ssid_len, &req);
Johannes Berg91bf9b22013-05-15 17:44:01 +02006542 wdev_unlock(dev->ieee80211_ptr);
6543 }
Jouni Malinen636a5d32009-03-19 13:39:22 +02006544
Jouni Malinen636a5d32009-03-19 13:39:22 +02006545 return err;
6546}
6547
6548static int nl80211_deauthenticate(struct sk_buff *skb, struct genl_info *info)
6549{
Johannes Berg4c476992010-10-04 21:36:35 +02006550 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6551 struct net_device *dev = info->user_ptr[1];
Johannes Berg19957bb2009-07-02 17:20:43 +02006552 const u8 *ie = NULL, *bssid;
Johannes Berg91bf9b22013-05-15 17:44:01 +02006553 int ie_len = 0, err;
Johannes Berg19957bb2009-07-02 17:20:43 +02006554 u16 reason_code;
Jouni Malinend5cdfac2010-04-04 09:37:19 +03006555 bool local_state_change;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006556
Johannes Bergf4a11bb2009-03-27 12:40:28 +01006557 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
6558 return -EINVAL;
6559
6560 if (!info->attrs[NL80211_ATTR_MAC])
6561 return -EINVAL;
6562
6563 if (!info->attrs[NL80211_ATTR_REASON_CODE])
6564 return -EINVAL;
6565
Johannes Berg4c476992010-10-04 21:36:35 +02006566 if (!rdev->ops->deauth)
6567 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006568
Johannes Berg074ac8d2010-09-16 14:58:22 +02006569 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02006570 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
6571 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02006572
Johannes Berg19957bb2009-07-02 17:20:43 +02006573 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02006574
Johannes Berg19957bb2009-07-02 17:20:43 +02006575 reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
6576 if (reason_code == 0) {
Johannes Bergf4a11bb2009-03-27 12:40:28 +01006577 /* Reason Code 0 is reserved */
Johannes Berg4c476992010-10-04 21:36:35 +02006578 return -EINVAL;
Jouni Malinen255e7372009-03-20 21:21:17 +02006579 }
Jouni Malinen636a5d32009-03-19 13:39:22 +02006580
6581 if (info->attrs[NL80211_ATTR_IE]) {
Johannes Berg19957bb2009-07-02 17:20:43 +02006582 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
6583 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02006584 }
6585
Jouni Malinend5cdfac2010-04-04 09:37:19 +03006586 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE];
6587
Johannes Berg91bf9b22013-05-15 17:44:01 +02006588 wdev_lock(dev->ieee80211_ptr);
6589 err = cfg80211_mlme_deauth(rdev, dev, bssid, ie, ie_len, reason_code,
6590 local_state_change);
6591 wdev_unlock(dev->ieee80211_ptr);
6592 return err;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006593}
6594
6595static int nl80211_disassociate(struct sk_buff *skb, struct genl_info *info)
6596{
Johannes Berg4c476992010-10-04 21:36:35 +02006597 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6598 struct net_device *dev = info->user_ptr[1];
Johannes Berg19957bb2009-07-02 17:20:43 +02006599 const u8 *ie = NULL, *bssid;
Johannes Berg91bf9b22013-05-15 17:44:01 +02006600 int ie_len = 0, err;
Johannes Berg19957bb2009-07-02 17:20:43 +02006601 u16 reason_code;
Jouni Malinend5cdfac2010-04-04 09:37:19 +03006602 bool local_state_change;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006603
Johannes Bergf4a11bb2009-03-27 12:40:28 +01006604 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
6605 return -EINVAL;
6606
6607 if (!info->attrs[NL80211_ATTR_MAC])
6608 return -EINVAL;
6609
6610 if (!info->attrs[NL80211_ATTR_REASON_CODE])
6611 return -EINVAL;
6612
Johannes Berg4c476992010-10-04 21:36:35 +02006613 if (!rdev->ops->disassoc)
6614 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006615
Johannes Berg074ac8d2010-09-16 14:58:22 +02006616 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02006617 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
6618 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02006619
Johannes Berg19957bb2009-07-02 17:20:43 +02006620 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02006621
Johannes Berg19957bb2009-07-02 17:20:43 +02006622 reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
6623 if (reason_code == 0) {
Johannes Bergf4a11bb2009-03-27 12:40:28 +01006624 /* Reason Code 0 is reserved */
Johannes Berg4c476992010-10-04 21:36:35 +02006625 return -EINVAL;
Jouni Malinen255e7372009-03-20 21:21:17 +02006626 }
Jouni Malinen636a5d32009-03-19 13:39:22 +02006627
6628 if (info->attrs[NL80211_ATTR_IE]) {
Johannes Berg19957bb2009-07-02 17:20:43 +02006629 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
6630 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02006631 }
6632
Jouni Malinend5cdfac2010-04-04 09:37:19 +03006633 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE];
6634
Johannes Berg91bf9b22013-05-15 17:44:01 +02006635 wdev_lock(dev->ieee80211_ptr);
6636 err = cfg80211_mlme_disassoc(rdev, dev, bssid, ie, ie_len, reason_code,
6637 local_state_change);
6638 wdev_unlock(dev->ieee80211_ptr);
6639 return err;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006640}
6641
Felix Fietkaudd5b4cc2010-11-22 20:58:24 +01006642static bool
6643nl80211_parse_mcast_rate(struct cfg80211_registered_device *rdev,
6644 int mcast_rate[IEEE80211_NUM_BANDS],
6645 int rateval)
6646{
6647 struct wiphy *wiphy = &rdev->wiphy;
6648 bool found = false;
6649 int band, i;
6650
6651 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
6652 struct ieee80211_supported_band *sband;
6653
6654 sband = wiphy->bands[band];
6655 if (!sband)
6656 continue;
6657
6658 for (i = 0; i < sband->n_bitrates; i++) {
6659 if (sband->bitrates[i].bitrate == rateval) {
6660 mcast_rate[band] = i + 1;
6661 found = true;
6662 break;
6663 }
6664 }
6665 }
6666
6667 return found;
6668}
6669
Johannes Berg04a773a2009-04-19 21:24:32 +02006670static int nl80211_join_ibss(struct sk_buff *skb, struct genl_info *info)
6671{
Johannes Berg4c476992010-10-04 21:36:35 +02006672 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6673 struct net_device *dev = info->user_ptr[1];
Johannes Berg04a773a2009-04-19 21:24:32 +02006674 struct cfg80211_ibss_params ibss;
6675 struct wiphy *wiphy;
Johannes Bergfffd0932009-07-08 14:22:54 +02006676 struct cfg80211_cached_keys *connkeys = NULL;
Johannes Berg04a773a2009-04-19 21:24:32 +02006677 int err;
6678
Johannes Berg8e30bc52009-04-22 17:45:38 +02006679 memset(&ibss, 0, sizeof(ibss));
6680
Johannes Berg04a773a2009-04-19 21:24:32 +02006681 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
6682 return -EINVAL;
6683
Johannes Berg683b6d32012-11-08 21:25:48 +01006684 if (!info->attrs[NL80211_ATTR_SSID] ||
Johannes Berg04a773a2009-04-19 21:24:32 +02006685 !nla_len(info->attrs[NL80211_ATTR_SSID]))
6686 return -EINVAL;
6687
Johannes Berg8e30bc52009-04-22 17:45:38 +02006688 ibss.beacon_interval = 100;
6689
6690 if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) {
6691 ibss.beacon_interval =
6692 nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]);
6693 if (ibss.beacon_interval < 1 || ibss.beacon_interval > 10000)
6694 return -EINVAL;
6695 }
6696
Johannes Berg4c476992010-10-04 21:36:35 +02006697 if (!rdev->ops->join_ibss)
6698 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02006699
Johannes Berg4c476992010-10-04 21:36:35 +02006700 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC)
6701 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02006702
Johannes Berg79c97e92009-07-07 03:56:12 +02006703 wiphy = &rdev->wiphy;
Johannes Berg04a773a2009-04-19 21:24:32 +02006704
Johannes Berg39193492011-09-16 13:45:25 +02006705 if (info->attrs[NL80211_ATTR_MAC]) {
Johannes Berg04a773a2009-04-19 21:24:32 +02006706 ibss.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Johannes Berg39193492011-09-16 13:45:25 +02006707
6708 if (!is_valid_ether_addr(ibss.bssid))
6709 return -EINVAL;
6710 }
Johannes Berg04a773a2009-04-19 21:24:32 +02006711 ibss.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
6712 ibss.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
6713
6714 if (info->attrs[NL80211_ATTR_IE]) {
6715 ibss.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
6716 ibss.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
6717 }
6718
Johannes Berg683b6d32012-11-08 21:25:48 +01006719 err = nl80211_parse_chandef(rdev, info, &ibss.chandef);
6720 if (err)
6721 return err;
Alexander Simon54858ee5b2011-11-30 16:56:32 +01006722
Ilan Peer174e0cd2014-02-23 09:13:01 +02006723 if (!cfg80211_reg_can_beacon(&rdev->wiphy, &ibss.chandef,
6724 NL80211_IFTYPE_ADHOC))
Alexander Simon54858ee5b2011-11-30 16:56:32 +01006725 return -EINVAL;
6726
Simon Wunderlich2f301ab2013-05-16 13:00:28 +02006727 switch (ibss.chandef.width) {
Simon Wunderlichbf372642013-07-08 16:55:58 +02006728 case NL80211_CHAN_WIDTH_5:
6729 case NL80211_CHAN_WIDTH_10:
Simon Wunderlich2f301ab2013-05-16 13:00:28 +02006730 case NL80211_CHAN_WIDTH_20_NOHT:
6731 break;
6732 case NL80211_CHAN_WIDTH_20:
6733 case NL80211_CHAN_WIDTH_40:
6734 if (rdev->wiphy.features & NL80211_FEATURE_HT_IBSS)
6735 break;
6736 default:
Johannes Bergdb9c64c2012-11-09 14:56:41 +01006737 return -EINVAL;
Simon Wunderlich2f301ab2013-05-16 13:00:28 +02006738 }
Johannes Bergdb9c64c2012-11-09 14:56:41 +01006739
Johannes Berg04a773a2009-04-19 21:24:32 +02006740 ibss.channel_fixed = !!info->attrs[NL80211_ATTR_FREQ_FIXED];
Johannes Bergfffd0932009-07-08 14:22:54 +02006741 ibss.privacy = !!info->attrs[NL80211_ATTR_PRIVACY];
Johannes Berg04a773a2009-04-19 21:24:32 +02006742
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03006743 if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) {
6744 u8 *rates =
6745 nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
6746 int n_rates =
6747 nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
6748 struct ieee80211_supported_band *sband =
Johannes Berg683b6d32012-11-08 21:25:48 +01006749 wiphy->bands[ibss.chandef.chan->band];
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03006750
Johannes Berg34850ab2011-07-18 18:08:35 +02006751 err = ieee80211_get_ratemask(sband, rates, n_rates,
6752 &ibss.basic_rates);
6753 if (err)
6754 return err;
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03006755 }
Felix Fietkaudd5b4cc2010-11-22 20:58:24 +01006756
Simon Wunderlich803768f2013-06-28 10:39:58 +02006757 if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
6758 memcpy(&ibss.ht_capa_mask,
6759 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]),
6760 sizeof(ibss.ht_capa_mask));
6761
6762 if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) {
6763 if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
6764 return -EINVAL;
6765 memcpy(&ibss.ht_capa,
6766 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]),
6767 sizeof(ibss.ht_capa));
6768 }
6769
Felix Fietkaudd5b4cc2010-11-22 20:58:24 +01006770 if (info->attrs[NL80211_ATTR_MCAST_RATE] &&
6771 !nl80211_parse_mcast_rate(rdev, ibss.mcast_rate,
6772 nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE])))
6773 return -EINVAL;
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03006774
Johannes Berg4c476992010-10-04 21:36:35 +02006775 if (ibss.privacy && info->attrs[NL80211_ATTR_KEYS]) {
Sujith Manoharande7044e2012-10-18 10:19:28 +05306776 bool no_ht = false;
6777
Johannes Berg4c476992010-10-04 21:36:35 +02006778 connkeys = nl80211_parse_connkeys(rdev,
Sujith Manoharande7044e2012-10-18 10:19:28 +05306779 info->attrs[NL80211_ATTR_KEYS],
6780 &no_ht);
Johannes Berg4c476992010-10-04 21:36:35 +02006781 if (IS_ERR(connkeys))
6782 return PTR_ERR(connkeys);
Sujith Manoharande7044e2012-10-18 10:19:28 +05306783
Johannes Berg3d9d1d62012-11-08 23:14:50 +01006784 if ((ibss.chandef.width != NL80211_CHAN_WIDTH_20_NOHT) &&
6785 no_ht) {
Sujith Manoharande7044e2012-10-18 10:19:28 +05306786 kfree(connkeys);
6787 return -EINVAL;
6788 }
Johannes Berg4c476992010-10-04 21:36:35 +02006789 }
Johannes Berg04a773a2009-04-19 21:24:32 +02006790
Antonio Quartulli267335d2012-01-31 20:25:47 +01006791 ibss.control_port =
6792 nla_get_flag(info->attrs[NL80211_ATTR_CONTROL_PORT]);
6793
Simon Wunderlich5336fa82013-10-07 18:41:05 +02006794 ibss.userspace_handles_dfs =
6795 nla_get_flag(info->attrs[NL80211_ATTR_HANDLE_DFS]);
6796
Johannes Berg4c476992010-10-04 21:36:35 +02006797 err = cfg80211_join_ibss(rdev, dev, &ibss, connkeys);
Johannes Bergfffd0932009-07-08 14:22:54 +02006798 if (err)
6799 kfree(connkeys);
Johannes Berg04a773a2009-04-19 21:24:32 +02006800 return err;
6801}
6802
6803static int nl80211_leave_ibss(struct sk_buff *skb, struct genl_info *info)
6804{
Johannes Berg4c476992010-10-04 21:36:35 +02006805 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6806 struct net_device *dev = info->user_ptr[1];
Johannes Berg04a773a2009-04-19 21:24:32 +02006807
Johannes Berg4c476992010-10-04 21:36:35 +02006808 if (!rdev->ops->leave_ibss)
6809 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02006810
Johannes Berg4c476992010-10-04 21:36:35 +02006811 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC)
6812 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02006813
Johannes Berg4c476992010-10-04 21:36:35 +02006814 return cfg80211_leave_ibss(rdev, dev, false);
Johannes Berg04a773a2009-04-19 21:24:32 +02006815}
6816
Antonio Quartullif4e583c2012-11-02 13:27:48 +01006817static int nl80211_set_mcast_rate(struct sk_buff *skb, struct genl_info *info)
6818{
6819 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6820 struct net_device *dev = info->user_ptr[1];
6821 int mcast_rate[IEEE80211_NUM_BANDS];
6822 u32 nla_rate;
6823 int err;
6824
6825 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC &&
6826 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
6827 return -EOPNOTSUPP;
6828
6829 if (!rdev->ops->set_mcast_rate)
6830 return -EOPNOTSUPP;
6831
6832 memset(mcast_rate, 0, sizeof(mcast_rate));
6833
6834 if (!info->attrs[NL80211_ATTR_MCAST_RATE])
6835 return -EINVAL;
6836
6837 nla_rate = nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]);
6838 if (!nl80211_parse_mcast_rate(rdev, mcast_rate, nla_rate))
6839 return -EINVAL;
6840
6841 err = rdev->ops->set_mcast_rate(&rdev->wiphy, dev, mcast_rate);
6842
6843 return err;
6844}
6845
Johannes Bergad7e7182013-11-13 13:37:47 +01006846static struct sk_buff *
6847__cfg80211_alloc_vendor_skb(struct cfg80211_registered_device *rdev,
6848 int approxlen, u32 portid, u32 seq,
6849 enum nl80211_commands cmd,
Johannes Berg567ffc32013-12-18 14:43:31 +01006850 enum nl80211_attrs attr,
6851 const struct nl80211_vendor_cmd_info *info,
6852 gfp_t gfp)
Johannes Bergad7e7182013-11-13 13:37:47 +01006853{
6854 struct sk_buff *skb;
6855 void *hdr;
6856 struct nlattr *data;
6857
6858 skb = nlmsg_new(approxlen + 100, gfp);
6859 if (!skb)
6860 return NULL;
6861
6862 hdr = nl80211hdr_put(skb, portid, seq, 0, cmd);
6863 if (!hdr) {
6864 kfree_skb(skb);
6865 return NULL;
6866 }
6867
6868 if (nla_put_u32(skb, NL80211_ATTR_WIPHY, rdev->wiphy_idx))
6869 goto nla_put_failure;
Johannes Berg567ffc32013-12-18 14:43:31 +01006870
6871 if (info) {
6872 if (nla_put_u32(skb, NL80211_ATTR_VENDOR_ID,
6873 info->vendor_id))
6874 goto nla_put_failure;
6875 if (nla_put_u32(skb, NL80211_ATTR_VENDOR_SUBCMD,
6876 info->subcmd))
6877 goto nla_put_failure;
6878 }
6879
Johannes Bergad7e7182013-11-13 13:37:47 +01006880 data = nla_nest_start(skb, attr);
6881
6882 ((void **)skb->cb)[0] = rdev;
6883 ((void **)skb->cb)[1] = hdr;
6884 ((void **)skb->cb)[2] = data;
6885
6886 return skb;
6887
6888 nla_put_failure:
6889 kfree_skb(skb);
6890 return NULL;
6891}
Antonio Quartullif4e583c2012-11-02 13:27:48 +01006892
Johannes Berge03ad6e2014-01-01 17:22:30 +01006893struct sk_buff *__cfg80211_alloc_event_skb(struct wiphy *wiphy,
6894 enum nl80211_commands cmd,
6895 enum nl80211_attrs attr,
6896 int vendor_event_idx,
6897 int approxlen, gfp_t gfp)
6898{
Zhao, Gangf26cbf42014-04-21 12:53:03 +08006899 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berge03ad6e2014-01-01 17:22:30 +01006900 const struct nl80211_vendor_cmd_info *info;
6901
6902 switch (cmd) {
6903 case NL80211_CMD_TESTMODE:
6904 if (WARN_ON(vendor_event_idx != -1))
6905 return NULL;
6906 info = NULL;
6907 break;
6908 case NL80211_CMD_VENDOR:
6909 if (WARN_ON(vendor_event_idx < 0 ||
6910 vendor_event_idx >= wiphy->n_vendor_events))
6911 return NULL;
6912 info = &wiphy->vendor_events[vendor_event_idx];
6913 break;
6914 default:
6915 WARN_ON(1);
6916 return NULL;
6917 }
6918
6919 return __cfg80211_alloc_vendor_skb(rdev, approxlen, 0, 0,
6920 cmd, attr, info, gfp);
6921}
6922EXPORT_SYMBOL(__cfg80211_alloc_event_skb);
6923
6924void __cfg80211_send_event_skb(struct sk_buff *skb, gfp_t gfp)
6925{
6926 struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0];
6927 void *hdr = ((void **)skb->cb)[1];
6928 struct nlattr *data = ((void **)skb->cb)[2];
6929 enum nl80211_multicast_groups mcgrp = NL80211_MCGRP_TESTMODE;
6930
6931 nla_nest_end(skb, data);
6932 genlmsg_end(skb, hdr);
6933
6934 if (data->nla_type == NL80211_ATTR_VENDOR_DATA)
6935 mcgrp = NL80211_MCGRP_VENDOR;
6936
6937 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), skb, 0,
6938 mcgrp, gfp);
6939}
6940EXPORT_SYMBOL(__cfg80211_send_event_skb);
6941
Johannes Bergaff89a92009-07-01 21:26:51 +02006942#ifdef CONFIG_NL80211_TESTMODE
Johannes Bergaff89a92009-07-01 21:26:51 +02006943static int nl80211_testmode_do(struct sk_buff *skb, struct genl_info *info)
6944{
Johannes Berg4c476992010-10-04 21:36:35 +02006945 struct cfg80211_registered_device *rdev = info->user_ptr[0];
David Spinadelfc73f112013-07-31 18:04:15 +03006946 struct wireless_dev *wdev =
6947 __cfg80211_wdev_from_attrs(genl_info_net(info), info->attrs);
Johannes Bergaff89a92009-07-01 21:26:51 +02006948 int err;
6949
David Spinadelfc73f112013-07-31 18:04:15 +03006950 if (!rdev->ops->testmode_cmd)
6951 return -EOPNOTSUPP;
6952
6953 if (IS_ERR(wdev)) {
6954 err = PTR_ERR(wdev);
6955 if (err != -EINVAL)
6956 return err;
6957 wdev = NULL;
6958 } else if (wdev->wiphy != &rdev->wiphy) {
6959 return -EINVAL;
6960 }
6961
Johannes Bergaff89a92009-07-01 21:26:51 +02006962 if (!info->attrs[NL80211_ATTR_TESTDATA])
6963 return -EINVAL;
6964
Johannes Bergad7e7182013-11-13 13:37:47 +01006965 rdev->cur_cmd_info = info;
David Spinadelfc73f112013-07-31 18:04:15 +03006966 err = rdev_testmode_cmd(rdev, wdev,
Johannes Bergaff89a92009-07-01 21:26:51 +02006967 nla_data(info->attrs[NL80211_ATTR_TESTDATA]),
6968 nla_len(info->attrs[NL80211_ATTR_TESTDATA]));
Johannes Bergad7e7182013-11-13 13:37:47 +01006969 rdev->cur_cmd_info = NULL;
Johannes Bergaff89a92009-07-01 21:26:51 +02006970
Johannes Bergaff89a92009-07-01 21:26:51 +02006971 return err;
6972}
6973
Wey-Yi Guy71063f02011-05-20 09:05:54 -07006974static int nl80211_testmode_dump(struct sk_buff *skb,
6975 struct netlink_callback *cb)
6976{
Johannes Berg00918d32011-12-13 17:22:05 +01006977 struct cfg80211_registered_device *rdev;
Wey-Yi Guy71063f02011-05-20 09:05:54 -07006978 int err;
6979 long phy_idx;
6980 void *data = NULL;
6981 int data_len = 0;
6982
Johannes Berg5fe231e2013-05-08 21:45:15 +02006983 rtnl_lock();
6984
Wey-Yi Guy71063f02011-05-20 09:05:54 -07006985 if (cb->args[0]) {
6986 /*
6987 * 0 is a valid index, but not valid for args[0],
6988 * so we need to offset by 1.
6989 */
6990 phy_idx = cb->args[0] - 1;
6991 } else {
6992 err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize,
6993 nl80211_fam.attrbuf, nl80211_fam.maxattr,
6994 nl80211_policy);
6995 if (err)
Johannes Berg5fe231e2013-05-08 21:45:15 +02006996 goto out_err;
Johannes Berg00918d32011-12-13 17:22:05 +01006997
Johannes Berg2bd7e352012-06-15 14:23:16 +02006998 rdev = __cfg80211_rdev_from_attrs(sock_net(skb->sk),
6999 nl80211_fam.attrbuf);
7000 if (IS_ERR(rdev)) {
Johannes Berg5fe231e2013-05-08 21:45:15 +02007001 err = PTR_ERR(rdev);
7002 goto out_err;
Johannes Berg00918d32011-12-13 17:22:05 +01007003 }
Johannes Berg2bd7e352012-06-15 14:23:16 +02007004 phy_idx = rdev->wiphy_idx;
7005 rdev = NULL;
Johannes Berg2bd7e352012-06-15 14:23:16 +02007006
Wey-Yi Guy71063f02011-05-20 09:05:54 -07007007 if (nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA])
7008 cb->args[1] =
7009 (long)nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA];
7010 }
7011
7012 if (cb->args[1]) {
7013 data = nla_data((void *)cb->args[1]);
7014 data_len = nla_len((void *)cb->args[1]);
7015 }
7016
Johannes Berg00918d32011-12-13 17:22:05 +01007017 rdev = cfg80211_rdev_by_wiphy_idx(phy_idx);
7018 if (!rdev) {
Johannes Berg5fe231e2013-05-08 21:45:15 +02007019 err = -ENOENT;
7020 goto out_err;
Wey-Yi Guy71063f02011-05-20 09:05:54 -07007021 }
Wey-Yi Guy71063f02011-05-20 09:05:54 -07007022
Johannes Berg00918d32011-12-13 17:22:05 +01007023 if (!rdev->ops->testmode_dump) {
Wey-Yi Guy71063f02011-05-20 09:05:54 -07007024 err = -EOPNOTSUPP;
7025 goto out_err;
7026 }
7027
7028 while (1) {
Eric W. Biederman15e47302012-09-07 20:12:54 +00007029 void *hdr = nl80211hdr_put(skb, NETLINK_CB(cb->skb).portid,
Wey-Yi Guy71063f02011-05-20 09:05:54 -07007030 cb->nlh->nlmsg_seq, NLM_F_MULTI,
7031 NL80211_CMD_TESTMODE);
7032 struct nlattr *tmdata;
7033
Dan Carpentercb35fba2013-08-14 14:50:01 +03007034 if (!hdr)
7035 break;
7036
David S. Miller9360ffd2012-03-29 04:41:26 -04007037 if (nla_put_u32(skb, NL80211_ATTR_WIPHY, phy_idx)) {
Wey-Yi Guy71063f02011-05-20 09:05:54 -07007038 genlmsg_cancel(skb, hdr);
7039 break;
7040 }
7041
7042 tmdata = nla_nest_start(skb, NL80211_ATTR_TESTDATA);
7043 if (!tmdata) {
7044 genlmsg_cancel(skb, hdr);
7045 break;
7046 }
Hila Gonene35e4d22012-06-27 17:19:42 +03007047 err = rdev_testmode_dump(rdev, skb, cb, data, data_len);
Wey-Yi Guy71063f02011-05-20 09:05:54 -07007048 nla_nest_end(skb, tmdata);
7049
7050 if (err == -ENOBUFS || err == -ENOENT) {
7051 genlmsg_cancel(skb, hdr);
7052 break;
7053 } else if (err) {
7054 genlmsg_cancel(skb, hdr);
7055 goto out_err;
7056 }
7057
7058 genlmsg_end(skb, hdr);
7059 }
7060
7061 err = skb->len;
7062 /* see above */
7063 cb->args[0] = phy_idx + 1;
7064 out_err:
Johannes Berg5fe231e2013-05-08 21:45:15 +02007065 rtnl_unlock();
Wey-Yi Guy71063f02011-05-20 09:05:54 -07007066 return err;
7067}
Johannes Bergaff89a92009-07-01 21:26:51 +02007068#endif
7069
Samuel Ortizb23aa672009-07-01 21:26:54 +02007070static int nl80211_connect(struct sk_buff *skb, struct genl_info *info)
7071{
Johannes Berg4c476992010-10-04 21:36:35 +02007072 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7073 struct net_device *dev = info->user_ptr[1];
Samuel Ortizb23aa672009-07-01 21:26:54 +02007074 struct cfg80211_connect_params connect;
7075 struct wiphy *wiphy;
Johannes Bergfffd0932009-07-08 14:22:54 +02007076 struct cfg80211_cached_keys *connkeys = NULL;
Samuel Ortizb23aa672009-07-01 21:26:54 +02007077 int err;
7078
7079 memset(&connect, 0, sizeof(connect));
7080
7081 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
7082 return -EINVAL;
7083
7084 if (!info->attrs[NL80211_ATTR_SSID] ||
7085 !nla_len(info->attrs[NL80211_ATTR_SSID]))
7086 return -EINVAL;
7087
7088 if (info->attrs[NL80211_ATTR_AUTH_TYPE]) {
7089 connect.auth_type =
7090 nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]);
Jouni Malinene39e5b52012-09-30 19:29:39 +03007091 if (!nl80211_valid_auth_type(rdev, connect.auth_type,
7092 NL80211_CMD_CONNECT))
Samuel Ortizb23aa672009-07-01 21:26:54 +02007093 return -EINVAL;
7094 } else
7095 connect.auth_type = NL80211_AUTHTYPE_AUTOMATIC;
7096
7097 connect.privacy = info->attrs[NL80211_ATTR_PRIVACY];
7098
Johannes Bergc0692b82010-08-27 14:26:53 +03007099 err = nl80211_crypto_settings(rdev, info, &connect.crypto,
Johannes Berg3dc27d22009-07-02 21:36:37 +02007100 NL80211_MAX_NR_CIPHER_SUITES);
Samuel Ortizb23aa672009-07-01 21:26:54 +02007101 if (err)
7102 return err;
Samuel Ortizb23aa672009-07-01 21:26:54 +02007103
Johannes Berg074ac8d2010-09-16 14:58:22 +02007104 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02007105 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
7106 return -EOPNOTSUPP;
Samuel Ortizb23aa672009-07-01 21:26:54 +02007107
Johannes Berg79c97e92009-07-07 03:56:12 +02007108 wiphy = &rdev->wiphy;
Samuel Ortizb23aa672009-07-01 21:26:54 +02007109
Bala Shanmugam4486ea92012-03-07 17:27:12 +05307110 connect.bg_scan_period = -1;
7111 if (info->attrs[NL80211_ATTR_BG_SCAN_PERIOD] &&
7112 (wiphy->flags & WIPHY_FLAG_SUPPORTS_FW_ROAM)) {
7113 connect.bg_scan_period =
7114 nla_get_u16(info->attrs[NL80211_ATTR_BG_SCAN_PERIOD]);
7115 }
7116
Samuel Ortizb23aa672009-07-01 21:26:54 +02007117 if (info->attrs[NL80211_ATTR_MAC])
7118 connect.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen1df4a512014-01-15 00:00:47 +02007119 else if (info->attrs[NL80211_ATTR_MAC_HINT])
7120 connect.bssid_hint =
7121 nla_data(info->attrs[NL80211_ATTR_MAC_HINT]);
Samuel Ortizb23aa672009-07-01 21:26:54 +02007122 connect.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
7123 connect.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
7124
7125 if (info->attrs[NL80211_ATTR_IE]) {
7126 connect.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
7127 connect.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
7128 }
7129
Jouni Malinencee00a92013-01-15 17:15:57 +02007130 if (info->attrs[NL80211_ATTR_USE_MFP]) {
7131 connect.mfp = nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]);
7132 if (connect.mfp != NL80211_MFP_REQUIRED &&
7133 connect.mfp != NL80211_MFP_NO)
7134 return -EINVAL;
7135 } else {
7136 connect.mfp = NL80211_MFP_NO;
7137 }
7138
Samuel Ortizb23aa672009-07-01 21:26:54 +02007139 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
Jouni Malinen664834d2014-01-15 00:01:44 +02007140 connect.channel = nl80211_get_valid_chan(
7141 wiphy, info->attrs[NL80211_ATTR_WIPHY_FREQ]);
7142 if (!connect.channel)
Johannes Berg4c476992010-10-04 21:36:35 +02007143 return -EINVAL;
Jouni Malinen1df4a512014-01-15 00:00:47 +02007144 } else if (info->attrs[NL80211_ATTR_WIPHY_FREQ_HINT]) {
Jouni Malinen664834d2014-01-15 00:01:44 +02007145 connect.channel_hint = nl80211_get_valid_chan(
7146 wiphy, info->attrs[NL80211_ATTR_WIPHY_FREQ_HINT]);
7147 if (!connect.channel_hint)
Jouni Malinen1df4a512014-01-15 00:00:47 +02007148 return -EINVAL;
Samuel Ortizb23aa672009-07-01 21:26:54 +02007149 }
7150
Johannes Bergfffd0932009-07-08 14:22:54 +02007151 if (connect.privacy && info->attrs[NL80211_ATTR_KEYS]) {
7152 connkeys = nl80211_parse_connkeys(rdev,
Sujith Manoharande7044e2012-10-18 10:19:28 +05307153 info->attrs[NL80211_ATTR_KEYS], NULL);
Johannes Berg4c476992010-10-04 21:36:35 +02007154 if (IS_ERR(connkeys))
7155 return PTR_ERR(connkeys);
Johannes Bergfffd0932009-07-08 14:22:54 +02007156 }
7157
Ben Greear7e7c8922011-11-18 11:31:59 -08007158 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT]))
7159 connect.flags |= ASSOC_REQ_DISABLE_HT;
7160
7161 if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
7162 memcpy(&connect.ht_capa_mask,
7163 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]),
7164 sizeof(connect.ht_capa_mask));
7165
7166 if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) {
Wei Yongjunb4e4f472012-09-02 21:41:04 +08007167 if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) {
7168 kfree(connkeys);
Ben Greear7e7c8922011-11-18 11:31:59 -08007169 return -EINVAL;
Wei Yongjunb4e4f472012-09-02 21:41:04 +08007170 }
Ben Greear7e7c8922011-11-18 11:31:59 -08007171 memcpy(&connect.ht_capa,
7172 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]),
7173 sizeof(connect.ht_capa));
7174 }
7175
Johannes Bergee2aca32013-02-21 17:36:01 +01007176 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_VHT]))
7177 connect.flags |= ASSOC_REQ_DISABLE_VHT;
7178
7179 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK])
7180 memcpy(&connect.vht_capa_mask,
7181 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]),
7182 sizeof(connect.vht_capa_mask));
7183
7184 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) {
7185 if (!info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) {
7186 kfree(connkeys);
7187 return -EINVAL;
7188 }
7189 memcpy(&connect.vht_capa,
7190 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]),
7191 sizeof(connect.vht_capa));
7192 }
7193
Johannes Berg83739b02013-05-15 17:44:01 +02007194 wdev_lock(dev->ieee80211_ptr);
7195 err = cfg80211_connect(rdev, dev, &connect, connkeys, NULL);
7196 wdev_unlock(dev->ieee80211_ptr);
Johannes Bergfffd0932009-07-08 14:22:54 +02007197 if (err)
7198 kfree(connkeys);
Samuel Ortizb23aa672009-07-01 21:26:54 +02007199 return err;
7200}
7201
7202static int nl80211_disconnect(struct sk_buff *skb, struct genl_info *info)
7203{
Johannes Berg4c476992010-10-04 21:36:35 +02007204 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7205 struct net_device *dev = info->user_ptr[1];
Samuel Ortizb23aa672009-07-01 21:26:54 +02007206 u16 reason;
Johannes Berg83739b02013-05-15 17:44:01 +02007207 int ret;
Samuel Ortizb23aa672009-07-01 21:26:54 +02007208
7209 if (!info->attrs[NL80211_ATTR_REASON_CODE])
7210 reason = WLAN_REASON_DEAUTH_LEAVING;
7211 else
7212 reason = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
7213
7214 if (reason == 0)
7215 return -EINVAL;
7216
Johannes Berg074ac8d2010-09-16 14:58:22 +02007217 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02007218 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
7219 return -EOPNOTSUPP;
Samuel Ortizb23aa672009-07-01 21:26:54 +02007220
Johannes Berg83739b02013-05-15 17:44:01 +02007221 wdev_lock(dev->ieee80211_ptr);
7222 ret = cfg80211_disconnect(rdev, dev, reason, true);
7223 wdev_unlock(dev->ieee80211_ptr);
7224 return ret;
Samuel Ortizb23aa672009-07-01 21:26:54 +02007225}
7226
Johannes Berg463d0182009-07-14 00:33:35 +02007227static int nl80211_wiphy_netns(struct sk_buff *skb, struct genl_info *info)
7228{
Johannes Berg4c476992010-10-04 21:36:35 +02007229 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg463d0182009-07-14 00:33:35 +02007230 struct net *net;
7231 int err;
7232 u32 pid;
7233
7234 if (!info->attrs[NL80211_ATTR_PID])
7235 return -EINVAL;
7236
7237 pid = nla_get_u32(info->attrs[NL80211_ATTR_PID]);
7238
Johannes Berg463d0182009-07-14 00:33:35 +02007239 net = get_net_ns_by_pid(pid);
Johannes Berg4c476992010-10-04 21:36:35 +02007240 if (IS_ERR(net))
7241 return PTR_ERR(net);
Johannes Berg463d0182009-07-14 00:33:35 +02007242
7243 err = 0;
7244
7245 /* check if anything to do */
Johannes Berg4c476992010-10-04 21:36:35 +02007246 if (!net_eq(wiphy_net(&rdev->wiphy), net))
7247 err = cfg80211_switch_netns(rdev, net);
Johannes Berg463d0182009-07-14 00:33:35 +02007248
Johannes Berg463d0182009-07-14 00:33:35 +02007249 put_net(net);
Johannes Berg463d0182009-07-14 00:33:35 +02007250 return err;
7251}
7252
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007253static int nl80211_setdel_pmksa(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];
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007256 int (*rdev_ops)(struct wiphy *wiphy, struct net_device *dev,
7257 struct cfg80211_pmksa *pmksa) = NULL;
Johannes Berg4c476992010-10-04 21:36:35 +02007258 struct net_device *dev = info->user_ptr[1];
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007259 struct cfg80211_pmksa pmksa;
7260
7261 memset(&pmksa, 0, sizeof(struct cfg80211_pmksa));
7262
7263 if (!info->attrs[NL80211_ATTR_MAC])
7264 return -EINVAL;
7265
7266 if (!info->attrs[NL80211_ATTR_PMKID])
7267 return -EINVAL;
7268
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007269 pmksa.pmkid = nla_data(info->attrs[NL80211_ATTR_PMKID]);
7270 pmksa.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
7271
Johannes Berg074ac8d2010-09-16 14:58:22 +02007272 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02007273 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
7274 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007275
7276 switch (info->genlhdr->cmd) {
7277 case NL80211_CMD_SET_PMKSA:
7278 rdev_ops = rdev->ops->set_pmksa;
7279 break;
7280 case NL80211_CMD_DEL_PMKSA:
7281 rdev_ops = rdev->ops->del_pmksa;
7282 break;
7283 default:
7284 WARN_ON(1);
7285 break;
7286 }
7287
Johannes Berg4c476992010-10-04 21:36:35 +02007288 if (!rdev_ops)
7289 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007290
Johannes Berg4c476992010-10-04 21:36:35 +02007291 return rdev_ops(&rdev->wiphy, dev, &pmksa);
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007292}
7293
7294static int nl80211_flush_pmksa(struct sk_buff *skb, struct genl_info *info)
7295{
Johannes Berg4c476992010-10-04 21:36:35 +02007296 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7297 struct net_device *dev = info->user_ptr[1];
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007298
Johannes Berg074ac8d2010-09-16 14:58:22 +02007299 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02007300 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
7301 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007302
Johannes Berg4c476992010-10-04 21:36:35 +02007303 if (!rdev->ops->flush_pmksa)
7304 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007305
Hila Gonene35e4d22012-06-27 17:19:42 +03007306 return rdev_flush_pmksa(rdev, dev);
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007307}
7308
Arik Nemtsov109086c2011-09-28 14:12:50 +03007309static int nl80211_tdls_mgmt(struct sk_buff *skb, struct genl_info *info)
7310{
7311 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7312 struct net_device *dev = info->user_ptr[1];
7313 u8 action_code, dialog_token;
Sunil Dutt Undekaridf942e72014-02-20 16:22:09 +05307314 u32 peer_capability = 0;
Arik Nemtsov109086c2011-09-28 14:12:50 +03007315 u16 status_code;
7316 u8 *peer;
7317
7318 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) ||
7319 !rdev->ops->tdls_mgmt)
7320 return -EOPNOTSUPP;
7321
7322 if (!info->attrs[NL80211_ATTR_TDLS_ACTION] ||
7323 !info->attrs[NL80211_ATTR_STATUS_CODE] ||
7324 !info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN] ||
7325 !info->attrs[NL80211_ATTR_IE] ||
7326 !info->attrs[NL80211_ATTR_MAC])
7327 return -EINVAL;
7328
7329 peer = nla_data(info->attrs[NL80211_ATTR_MAC]);
7330 action_code = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_ACTION]);
7331 status_code = nla_get_u16(info->attrs[NL80211_ATTR_STATUS_CODE]);
7332 dialog_token = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN]);
Sunil Dutt Undekaridf942e72014-02-20 16:22:09 +05307333 if (info->attrs[NL80211_ATTR_TDLS_PEER_CAPABILITY])
7334 peer_capability =
7335 nla_get_u32(info->attrs[NL80211_ATTR_TDLS_PEER_CAPABILITY]);
Arik Nemtsov109086c2011-09-28 14:12:50 +03007336
Hila Gonene35e4d22012-06-27 17:19:42 +03007337 return rdev_tdls_mgmt(rdev, dev, peer, action_code,
Sunil Dutt Undekaridf942e72014-02-20 16:22:09 +05307338 dialog_token, status_code, peer_capability,
Hila Gonene35e4d22012-06-27 17:19:42 +03007339 nla_data(info->attrs[NL80211_ATTR_IE]),
7340 nla_len(info->attrs[NL80211_ATTR_IE]));
Arik Nemtsov109086c2011-09-28 14:12:50 +03007341}
7342
7343static int nl80211_tdls_oper(struct sk_buff *skb, struct genl_info *info)
7344{
7345 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7346 struct net_device *dev = info->user_ptr[1];
7347 enum nl80211_tdls_operation operation;
7348 u8 *peer;
7349
7350 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) ||
7351 !rdev->ops->tdls_oper)
7352 return -EOPNOTSUPP;
7353
7354 if (!info->attrs[NL80211_ATTR_TDLS_OPERATION] ||
7355 !info->attrs[NL80211_ATTR_MAC])
7356 return -EINVAL;
7357
7358 operation = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_OPERATION]);
7359 peer = nla_data(info->attrs[NL80211_ATTR_MAC]);
7360
Hila Gonene35e4d22012-06-27 17:19:42 +03007361 return rdev_tdls_oper(rdev, dev, peer, operation);
Arik Nemtsov109086c2011-09-28 14:12:50 +03007362}
7363
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007364static int nl80211_remain_on_channel(struct sk_buff *skb,
7365 struct genl_info *info)
7366{
Johannes Berg4c476992010-10-04 21:36:35 +02007367 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02007368 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg683b6d32012-11-08 21:25:48 +01007369 struct cfg80211_chan_def chandef;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007370 struct sk_buff *msg;
7371 void *hdr;
7372 u64 cookie;
Johannes Berg683b6d32012-11-08 21:25:48 +01007373 u32 duration;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007374 int err;
7375
7376 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] ||
7377 !info->attrs[NL80211_ATTR_DURATION])
7378 return -EINVAL;
7379
7380 duration = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]);
7381
Johannes Berg7c4ef712011-11-18 15:33:48 +01007382 if (!rdev->ops->remain_on_channel ||
7383 !(rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL))
Johannes Berg4c476992010-10-04 21:36:35 +02007384 return -EOPNOTSUPP;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007385
Johannes Bergebf348f2012-06-01 12:50:54 +02007386 /*
7387 * We should be on that channel for at least a minimum amount of
7388 * time (10ms) but no longer than the driver supports.
7389 */
7390 if (duration < NL80211_MIN_REMAIN_ON_CHANNEL_TIME ||
7391 duration > rdev->wiphy.max_remain_on_channel_duration)
7392 return -EINVAL;
7393
Johannes Berg683b6d32012-11-08 21:25:48 +01007394 err = nl80211_parse_chandef(rdev, info, &chandef);
7395 if (err)
7396 return err;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007397
7398 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02007399 if (!msg)
7400 return -ENOMEM;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007401
Eric W. Biederman15e47302012-09-07 20:12:54 +00007402 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007403 NL80211_CMD_REMAIN_ON_CHANNEL);
Dan Carpentercb35fba2013-08-14 14:50:01 +03007404 if (!hdr) {
7405 err = -ENOBUFS;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007406 goto free_msg;
7407 }
7408
Johannes Berg683b6d32012-11-08 21:25:48 +01007409 err = rdev_remain_on_channel(rdev, wdev, chandef.chan,
7410 duration, &cookie);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007411
7412 if (err)
7413 goto free_msg;
7414
David S. Miller9360ffd2012-03-29 04:41:26 -04007415 if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie))
7416 goto nla_put_failure;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007417
7418 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02007419
7420 return genlmsg_reply(msg, info);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007421
7422 nla_put_failure:
7423 err = -ENOBUFS;
7424 free_msg:
7425 nlmsg_free(msg);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007426 return err;
7427}
7428
7429static int nl80211_cancel_remain_on_channel(struct sk_buff *skb,
7430 struct genl_info *info)
7431{
Johannes Berg4c476992010-10-04 21:36:35 +02007432 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02007433 struct wireless_dev *wdev = info->user_ptr[1];
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007434 u64 cookie;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007435
7436 if (!info->attrs[NL80211_ATTR_COOKIE])
7437 return -EINVAL;
7438
Johannes Berg4c476992010-10-04 21:36:35 +02007439 if (!rdev->ops->cancel_remain_on_channel)
7440 return -EOPNOTSUPP;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007441
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007442 cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]);
7443
Hila Gonene35e4d22012-06-27 17:19:42 +03007444 return rdev_cancel_remain_on_channel(rdev, wdev, cookie);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007445}
7446
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007447static u32 rateset_to_mask(struct ieee80211_supported_band *sband,
7448 u8 *rates, u8 rates_len)
7449{
7450 u8 i;
7451 u32 mask = 0;
7452
7453 for (i = 0; i < rates_len; i++) {
7454 int rate = (rates[i] & 0x7f) * 5;
7455 int ridx;
7456 for (ridx = 0; ridx < sband->n_bitrates; ridx++) {
7457 struct ieee80211_rate *srate =
7458 &sband->bitrates[ridx];
7459 if (rate == srate->bitrate) {
7460 mask |= 1 << ridx;
7461 break;
7462 }
7463 }
7464 if (ridx == sband->n_bitrates)
7465 return 0; /* rate not found */
7466 }
7467
7468 return mask;
7469}
7470
Simon Wunderlich24db78c2012-01-28 17:25:32 +01007471static bool ht_rateset_to_mask(struct ieee80211_supported_band *sband,
7472 u8 *rates, u8 rates_len,
7473 u8 mcs[IEEE80211_HT_MCS_MASK_LEN])
7474{
7475 u8 i;
7476
7477 memset(mcs, 0, IEEE80211_HT_MCS_MASK_LEN);
7478
7479 for (i = 0; i < rates_len; i++) {
7480 int ridx, rbit;
7481
7482 ridx = rates[i] / 8;
7483 rbit = BIT(rates[i] % 8);
7484
7485 /* check validity */
Dan Carpenter910570b52012-02-01 10:42:11 +03007486 if ((ridx < 0) || (ridx >= IEEE80211_HT_MCS_MASK_LEN))
Simon Wunderlich24db78c2012-01-28 17:25:32 +01007487 return false;
7488
7489 /* check availability */
7490 if (sband->ht_cap.mcs.rx_mask[ridx] & rbit)
7491 mcs[ridx] |= rbit;
7492 else
7493 return false;
7494 }
7495
7496 return true;
7497}
7498
Janusz Dziedzic204e35a2013-12-05 20:42:58 +01007499static u16 vht_mcs_map_to_mcs_mask(u8 vht_mcs_map)
7500{
7501 u16 mcs_mask = 0;
7502
7503 switch (vht_mcs_map) {
7504 case IEEE80211_VHT_MCS_NOT_SUPPORTED:
7505 break;
7506 case IEEE80211_VHT_MCS_SUPPORT_0_7:
7507 mcs_mask = 0x00FF;
7508 break;
7509 case IEEE80211_VHT_MCS_SUPPORT_0_8:
7510 mcs_mask = 0x01FF;
7511 break;
7512 case IEEE80211_VHT_MCS_SUPPORT_0_9:
7513 mcs_mask = 0x03FF;
7514 break;
7515 default:
7516 break;
7517 }
7518
7519 return mcs_mask;
7520}
7521
7522static void vht_build_mcs_mask(u16 vht_mcs_map,
7523 u16 vht_mcs_mask[NL80211_VHT_NSS_MAX])
7524{
7525 u8 nss;
7526
7527 for (nss = 0; nss < NL80211_VHT_NSS_MAX; nss++) {
7528 vht_mcs_mask[nss] = vht_mcs_map_to_mcs_mask(vht_mcs_map & 0x03);
7529 vht_mcs_map >>= 2;
7530 }
7531}
7532
7533static bool vht_set_mcs_mask(struct ieee80211_supported_band *sband,
7534 struct nl80211_txrate_vht *txrate,
7535 u16 mcs[NL80211_VHT_NSS_MAX])
7536{
7537 u16 tx_mcs_map = le16_to_cpu(sband->vht_cap.vht_mcs.tx_mcs_map);
7538 u16 tx_mcs_mask[NL80211_VHT_NSS_MAX] = {};
7539 u8 i;
7540
7541 if (!sband->vht_cap.vht_supported)
7542 return false;
7543
7544 memset(mcs, 0, sizeof(u16) * NL80211_VHT_NSS_MAX);
7545
7546 /* Build vht_mcs_mask from VHT capabilities */
7547 vht_build_mcs_mask(tx_mcs_map, tx_mcs_mask);
7548
7549 for (i = 0; i < NL80211_VHT_NSS_MAX; i++) {
7550 if ((tx_mcs_mask[i] & txrate->mcs[i]) == txrate->mcs[i])
7551 mcs[i] = txrate->mcs[i];
7552 else
7553 return false;
7554 }
7555
7556 return true;
7557}
7558
Alexey Dobriyanb54452b2010-02-18 08:14:31 +00007559static const struct nla_policy nl80211_txattr_policy[NL80211_TXRATE_MAX + 1] = {
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007560 [NL80211_TXRATE_LEGACY] = { .type = NLA_BINARY,
7561 .len = NL80211_MAX_SUPP_RATES },
Janusz Dziedzicd1e33e62013-12-05 10:02:15 +01007562 [NL80211_TXRATE_HT] = { .type = NLA_BINARY,
7563 .len = NL80211_MAX_SUPP_HT_RATES },
Janusz Dziedzic204e35a2013-12-05 20:42:58 +01007564 [NL80211_TXRATE_VHT] = { .len = sizeof(struct nl80211_txrate_vht)},
Janusz Dziedzic0b9323f2014-01-08 08:46:02 +01007565 [NL80211_TXRATE_GI] = { .type = NLA_U8 },
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007566};
7567
7568static int nl80211_set_tx_bitrate_mask(struct sk_buff *skb,
7569 struct genl_info *info)
7570{
7571 struct nlattr *tb[NL80211_TXRATE_MAX + 1];
Johannes Berg4c476992010-10-04 21:36:35 +02007572 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007573 struct cfg80211_bitrate_mask mask;
Johannes Berg4c476992010-10-04 21:36:35 +02007574 int rem, i;
7575 struct net_device *dev = info->user_ptr[1];
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007576 struct nlattr *tx_rates;
7577 struct ieee80211_supported_band *sband;
Janusz Dziedzic204e35a2013-12-05 20:42:58 +01007578 u16 vht_tx_mcs_map;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007579
Johannes Berg4c476992010-10-04 21:36:35 +02007580 if (!rdev->ops->set_bitrate_mask)
7581 return -EOPNOTSUPP;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007582
7583 memset(&mask, 0, sizeof(mask));
7584 /* Default to all rates enabled */
7585 for (i = 0; i < IEEE80211_NUM_BANDS; i++) {
7586 sband = rdev->wiphy.bands[i];
Janusz Dziedzic78693032013-12-03 09:50:44 +01007587
7588 if (!sband)
7589 continue;
7590
7591 mask.control[i].legacy = (1 << sband->n_bitrates) - 1;
Janusz Dziedzicd1e33e62013-12-05 10:02:15 +01007592 memcpy(mask.control[i].ht_mcs,
Janusz Dziedzic78693032013-12-03 09:50:44 +01007593 sband->ht_cap.mcs.rx_mask,
Janusz Dziedzicd1e33e62013-12-05 10:02:15 +01007594 sizeof(mask.control[i].ht_mcs));
Janusz Dziedzic204e35a2013-12-05 20:42:58 +01007595
7596 if (!sband->vht_cap.vht_supported)
7597 continue;
7598
7599 vht_tx_mcs_map = le16_to_cpu(sband->vht_cap.vht_mcs.tx_mcs_map);
7600 vht_build_mcs_mask(vht_tx_mcs_map, mask.control[i].vht_mcs);
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007601 }
7602
Janusz Dziedzicb9243ab2013-12-05 10:02:14 +01007603 /* if no rates are given set it back to the defaults */
7604 if (!info->attrs[NL80211_ATTR_TX_RATES])
7605 goto out;
7606
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007607 /*
7608 * The nested attribute uses enum nl80211_band as the index. This maps
7609 * directly to the enum ieee80211_band values used in cfg80211.
7610 */
Simon Wunderlich24db78c2012-01-28 17:25:32 +01007611 BUILD_BUG_ON(NL80211_MAX_SUPP_HT_RATES > IEEE80211_HT_MCS_MASK_LEN * 8);
Johannes Bergae811e22014-01-24 10:17:47 +01007612 nla_for_each_nested(tx_rates, info->attrs[NL80211_ATTR_TX_RATES], rem) {
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007613 enum ieee80211_band band = nla_type(tx_rates);
Johannes Bergae811e22014-01-24 10:17:47 +01007614 int err;
7615
Johannes Berg4c476992010-10-04 21:36:35 +02007616 if (band < 0 || band >= IEEE80211_NUM_BANDS)
7617 return -EINVAL;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007618 sband = rdev->wiphy.bands[band];
Johannes Berg4c476992010-10-04 21:36:35 +02007619 if (sband == NULL)
7620 return -EINVAL;
Johannes Bergae811e22014-01-24 10:17:47 +01007621 err = nla_parse(tb, NL80211_TXRATE_MAX, nla_data(tx_rates),
7622 nla_len(tx_rates), nl80211_txattr_policy);
7623 if (err)
7624 return err;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007625 if (tb[NL80211_TXRATE_LEGACY]) {
7626 mask.control[band].legacy = rateset_to_mask(
7627 sband,
7628 nla_data(tb[NL80211_TXRATE_LEGACY]),
7629 nla_len(tb[NL80211_TXRATE_LEGACY]));
Bala Shanmugam218d2e22012-04-20 19:12:58 +05307630 if ((mask.control[band].legacy == 0) &&
7631 nla_len(tb[NL80211_TXRATE_LEGACY]))
7632 return -EINVAL;
Simon Wunderlich24db78c2012-01-28 17:25:32 +01007633 }
Janusz Dziedzicd1e33e62013-12-05 10:02:15 +01007634 if (tb[NL80211_TXRATE_HT]) {
Simon Wunderlich24db78c2012-01-28 17:25:32 +01007635 if (!ht_rateset_to_mask(
7636 sband,
Janusz Dziedzicd1e33e62013-12-05 10:02:15 +01007637 nla_data(tb[NL80211_TXRATE_HT]),
7638 nla_len(tb[NL80211_TXRATE_HT]),
7639 mask.control[band].ht_mcs))
Simon Wunderlich24db78c2012-01-28 17:25:32 +01007640 return -EINVAL;
7641 }
Janusz Dziedzic204e35a2013-12-05 20:42:58 +01007642 if (tb[NL80211_TXRATE_VHT]) {
7643 if (!vht_set_mcs_mask(
7644 sband,
7645 nla_data(tb[NL80211_TXRATE_VHT]),
7646 mask.control[band].vht_mcs))
7647 return -EINVAL;
7648 }
Janusz Dziedzic0b9323f2014-01-08 08:46:02 +01007649 if (tb[NL80211_TXRATE_GI]) {
7650 mask.control[band].gi =
7651 nla_get_u8(tb[NL80211_TXRATE_GI]);
7652 if (mask.control[band].gi > NL80211_TXRATE_FORCE_LGI)
7653 return -EINVAL;
7654 }
Simon Wunderlich24db78c2012-01-28 17:25:32 +01007655
7656 if (mask.control[band].legacy == 0) {
Janusz Dziedzic204e35a2013-12-05 20:42:58 +01007657 /* don't allow empty legacy rates if HT or VHT
7658 * are not even supported.
7659 */
7660 if (!(rdev->wiphy.bands[band]->ht_cap.ht_supported ||
7661 rdev->wiphy.bands[band]->vht_cap.vht_supported))
Simon Wunderlich24db78c2012-01-28 17:25:32 +01007662 return -EINVAL;
7663
7664 for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++)
Janusz Dziedzicd1e33e62013-12-05 10:02:15 +01007665 if (mask.control[band].ht_mcs[i])
Janusz Dziedzic204e35a2013-12-05 20:42:58 +01007666 goto out;
7667
7668 for (i = 0; i < NL80211_VHT_NSS_MAX; i++)
7669 if (mask.control[band].vht_mcs[i])
7670 goto out;
Simon Wunderlich24db78c2012-01-28 17:25:32 +01007671
7672 /* legacy and mcs rates may not be both empty */
Janusz Dziedzic204e35a2013-12-05 20:42:58 +01007673 return -EINVAL;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007674 }
7675 }
7676
Janusz Dziedzicb9243ab2013-12-05 10:02:14 +01007677out:
Hila Gonene35e4d22012-06-27 17:19:42 +03007678 return rdev_set_bitrate_mask(rdev, dev, NULL, &mask);
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007679}
7680
Johannes Berg2e161f782010-08-12 15:38:38 +02007681static int nl80211_register_mgmt(struct sk_buff *skb, struct genl_info *info)
Jouni Malinen026331c2010-02-15 12:53:10 +02007682{
Johannes Berg4c476992010-10-04 21:36:35 +02007683 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02007684 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg2e161f782010-08-12 15:38:38 +02007685 u16 frame_type = IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_ACTION;
Jouni Malinen026331c2010-02-15 12:53:10 +02007686
7687 if (!info->attrs[NL80211_ATTR_FRAME_MATCH])
7688 return -EINVAL;
7689
Johannes Berg2e161f782010-08-12 15:38:38 +02007690 if (info->attrs[NL80211_ATTR_FRAME_TYPE])
7691 frame_type = nla_get_u16(info->attrs[NL80211_ATTR_FRAME_TYPE]);
Jouni Malinen026331c2010-02-15 12:53:10 +02007692
Johannes Berg71bbc992012-06-15 15:30:18 +02007693 switch (wdev->iftype) {
7694 case NL80211_IFTYPE_STATION:
7695 case NL80211_IFTYPE_ADHOC:
7696 case NL80211_IFTYPE_P2P_CLIENT:
7697 case NL80211_IFTYPE_AP:
7698 case NL80211_IFTYPE_AP_VLAN:
7699 case NL80211_IFTYPE_MESH_POINT:
7700 case NL80211_IFTYPE_P2P_GO:
Johannes Berg98104fde2012-06-16 00:19:54 +02007701 case NL80211_IFTYPE_P2P_DEVICE:
Johannes Berg71bbc992012-06-15 15:30:18 +02007702 break;
7703 default:
Johannes Berg4c476992010-10-04 21:36:35 +02007704 return -EOPNOTSUPP;
Johannes Berg71bbc992012-06-15 15:30:18 +02007705 }
Jouni Malinen026331c2010-02-15 12:53:10 +02007706
7707 /* not much point in registering if we can't reply */
Johannes Berg4c476992010-10-04 21:36:35 +02007708 if (!rdev->ops->mgmt_tx)
7709 return -EOPNOTSUPP;
Jouni Malinen026331c2010-02-15 12:53:10 +02007710
Eric W. Biederman15e47302012-09-07 20:12:54 +00007711 return cfg80211_mlme_register_mgmt(wdev, info->snd_portid, frame_type,
Jouni Malinen026331c2010-02-15 12:53:10 +02007712 nla_data(info->attrs[NL80211_ATTR_FRAME_MATCH]),
7713 nla_len(info->attrs[NL80211_ATTR_FRAME_MATCH]));
Jouni Malinen026331c2010-02-15 12:53:10 +02007714}
7715
Johannes Berg2e161f782010-08-12 15:38:38 +02007716static int nl80211_tx_mgmt(struct sk_buff *skb, struct genl_info *info)
Jouni Malinen026331c2010-02-15 12:53:10 +02007717{
Johannes Berg4c476992010-10-04 21:36:35 +02007718 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02007719 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg683b6d32012-11-08 21:25:48 +01007720 struct cfg80211_chan_def chandef;
Jouni Malinen026331c2010-02-15 12:53:10 +02007721 int err;
Johannes Bergd64d3732011-11-10 09:44:46 +01007722 void *hdr = NULL;
Jouni Malinen026331c2010-02-15 12:53:10 +02007723 u64 cookie;
Johannes Berge247bd902011-11-04 11:18:21 +01007724 struct sk_buff *msg = NULL;
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02007725 struct cfg80211_mgmt_tx_params params = {
7726 .dont_wait_for_ack =
7727 info->attrs[NL80211_ATTR_DONT_WAIT_FOR_ACK],
7728 };
Jouni Malinen026331c2010-02-15 12:53:10 +02007729
Johannes Berg683b6d32012-11-08 21:25:48 +01007730 if (!info->attrs[NL80211_ATTR_FRAME])
Jouni Malinen026331c2010-02-15 12:53:10 +02007731 return -EINVAL;
7732
Johannes Berg4c476992010-10-04 21:36:35 +02007733 if (!rdev->ops->mgmt_tx)
7734 return -EOPNOTSUPP;
Jouni Malinen026331c2010-02-15 12:53:10 +02007735
Johannes Berg71bbc992012-06-15 15:30:18 +02007736 switch (wdev->iftype) {
Antonio Quartulliea141b752013-06-11 14:20:03 +02007737 case NL80211_IFTYPE_P2P_DEVICE:
7738 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ])
7739 return -EINVAL;
Johannes Berg71bbc992012-06-15 15:30:18 +02007740 case NL80211_IFTYPE_STATION:
7741 case NL80211_IFTYPE_ADHOC:
7742 case NL80211_IFTYPE_P2P_CLIENT:
7743 case NL80211_IFTYPE_AP:
7744 case NL80211_IFTYPE_AP_VLAN:
7745 case NL80211_IFTYPE_MESH_POINT:
7746 case NL80211_IFTYPE_P2P_GO:
7747 break;
7748 default:
Johannes Berg4c476992010-10-04 21:36:35 +02007749 return -EOPNOTSUPP;
Johannes Berg71bbc992012-06-15 15:30:18 +02007750 }
Jouni Malinen026331c2010-02-15 12:53:10 +02007751
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007752 if (info->attrs[NL80211_ATTR_DURATION]) {
Johannes Berg7c4ef712011-11-18 15:33:48 +01007753 if (!(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX))
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007754 return -EINVAL;
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02007755 params.wait = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]);
Johannes Bergebf348f2012-06-01 12:50:54 +02007756
7757 /*
7758 * We should wait on the channel for at least a minimum amount
7759 * of time (10ms) but no longer than the driver supports.
7760 */
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02007761 if (params.wait < NL80211_MIN_REMAIN_ON_CHANNEL_TIME ||
7762 params.wait > rdev->wiphy.max_remain_on_channel_duration)
Johannes Bergebf348f2012-06-01 12:50:54 +02007763 return -EINVAL;
7764
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007765 }
7766
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02007767 params.offchan = info->attrs[NL80211_ATTR_OFFCHANNEL_TX_OK];
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007768
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02007769 if (params.offchan && !(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX))
Johannes Berg7c4ef712011-11-18 15:33:48 +01007770 return -EINVAL;
7771
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02007772 params.no_cck = nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]);
Rajkumar Manoharane9f935e2011-09-25 14:53:30 +05307773
Antonio Quartulliea141b752013-06-11 14:20:03 +02007774 /* get the channel if any has been specified, otherwise pass NULL to
7775 * the driver. The latter will use the current one
7776 */
7777 chandef.chan = NULL;
7778 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
7779 err = nl80211_parse_chandef(rdev, info, &chandef);
7780 if (err)
7781 return err;
7782 }
7783
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02007784 if (!chandef.chan && params.offchan)
Antonio Quartulliea141b752013-06-11 14:20:03 +02007785 return -EINVAL;
Jouni Malinen026331c2010-02-15 12:53:10 +02007786
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02007787 if (!params.dont_wait_for_ack) {
Johannes Berge247bd902011-11-04 11:18:21 +01007788 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
7789 if (!msg)
7790 return -ENOMEM;
Jouni Malinen026331c2010-02-15 12:53:10 +02007791
Eric W. Biederman15e47302012-09-07 20:12:54 +00007792 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berge247bd902011-11-04 11:18:21 +01007793 NL80211_CMD_FRAME);
Dan Carpentercb35fba2013-08-14 14:50:01 +03007794 if (!hdr) {
7795 err = -ENOBUFS;
Johannes Berge247bd902011-11-04 11:18:21 +01007796 goto free_msg;
7797 }
Jouni Malinen026331c2010-02-15 12:53:10 +02007798 }
Johannes Berge247bd902011-11-04 11:18:21 +01007799
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02007800 params.buf = nla_data(info->attrs[NL80211_ATTR_FRAME]);
7801 params.len = nla_len(info->attrs[NL80211_ATTR_FRAME]);
7802 params.chan = chandef.chan;
7803 err = cfg80211_mlme_mgmt_tx(rdev, wdev, &params, &cookie);
Jouni Malinen026331c2010-02-15 12:53:10 +02007804 if (err)
7805 goto free_msg;
7806
Johannes Berge247bd902011-11-04 11:18:21 +01007807 if (msg) {
David S. Miller9360ffd2012-03-29 04:41:26 -04007808 if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie))
7809 goto nla_put_failure;
Jouni Malinen026331c2010-02-15 12:53:10 +02007810
Johannes Berge247bd902011-11-04 11:18:21 +01007811 genlmsg_end(msg, hdr);
7812 return genlmsg_reply(msg, info);
7813 }
7814
7815 return 0;
Jouni Malinen026331c2010-02-15 12:53:10 +02007816
7817 nla_put_failure:
7818 err = -ENOBUFS;
7819 free_msg:
7820 nlmsg_free(msg);
Jouni Malinen026331c2010-02-15 12:53:10 +02007821 return err;
7822}
7823
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007824static int nl80211_tx_mgmt_cancel_wait(struct sk_buff *skb, struct genl_info *info)
7825{
7826 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02007827 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007828 u64 cookie;
7829
7830 if (!info->attrs[NL80211_ATTR_COOKIE])
7831 return -EINVAL;
7832
7833 if (!rdev->ops->mgmt_tx_cancel_wait)
7834 return -EOPNOTSUPP;
7835
Johannes Berg71bbc992012-06-15 15:30:18 +02007836 switch (wdev->iftype) {
7837 case NL80211_IFTYPE_STATION:
7838 case NL80211_IFTYPE_ADHOC:
7839 case NL80211_IFTYPE_P2P_CLIENT:
7840 case NL80211_IFTYPE_AP:
7841 case NL80211_IFTYPE_AP_VLAN:
7842 case NL80211_IFTYPE_P2P_GO:
Johannes Berg98104fde2012-06-16 00:19:54 +02007843 case NL80211_IFTYPE_P2P_DEVICE:
Johannes Berg71bbc992012-06-15 15:30:18 +02007844 break;
7845 default:
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007846 return -EOPNOTSUPP;
Johannes Berg71bbc992012-06-15 15:30:18 +02007847 }
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007848
7849 cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]);
7850
Hila Gonene35e4d22012-06-27 17:19:42 +03007851 return rdev_mgmt_tx_cancel_wait(rdev, wdev, cookie);
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007852}
7853
Kalle Valoffb9eb32010-02-17 17:58:10 +02007854static int nl80211_set_power_save(struct sk_buff *skb, struct genl_info *info)
7855{
Johannes Berg4c476992010-10-04 21:36:35 +02007856 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Kalle Valoffb9eb32010-02-17 17:58:10 +02007857 struct wireless_dev *wdev;
Johannes Berg4c476992010-10-04 21:36:35 +02007858 struct net_device *dev = info->user_ptr[1];
Kalle Valoffb9eb32010-02-17 17:58:10 +02007859 u8 ps_state;
7860 bool state;
7861 int err;
7862
Johannes Berg4c476992010-10-04 21:36:35 +02007863 if (!info->attrs[NL80211_ATTR_PS_STATE])
7864 return -EINVAL;
Kalle Valoffb9eb32010-02-17 17:58:10 +02007865
7866 ps_state = nla_get_u32(info->attrs[NL80211_ATTR_PS_STATE]);
7867
Johannes Berg4c476992010-10-04 21:36:35 +02007868 if (ps_state != NL80211_PS_DISABLED && ps_state != NL80211_PS_ENABLED)
7869 return -EINVAL;
Kalle Valoffb9eb32010-02-17 17:58:10 +02007870
7871 wdev = dev->ieee80211_ptr;
7872
Johannes Berg4c476992010-10-04 21:36:35 +02007873 if (!rdev->ops->set_power_mgmt)
7874 return -EOPNOTSUPP;
Kalle Valoffb9eb32010-02-17 17:58:10 +02007875
7876 state = (ps_state == NL80211_PS_ENABLED) ? true : false;
7877
7878 if (state == wdev->ps)
Johannes Berg4c476992010-10-04 21:36:35 +02007879 return 0;
Kalle Valoffb9eb32010-02-17 17:58:10 +02007880
Hila Gonene35e4d22012-06-27 17:19:42 +03007881 err = rdev_set_power_mgmt(rdev, dev, state, wdev->ps_timeout);
Johannes Berg4c476992010-10-04 21:36:35 +02007882 if (!err)
7883 wdev->ps = state;
Kalle Valoffb9eb32010-02-17 17:58:10 +02007884 return err;
7885}
7886
7887static int nl80211_get_power_save(struct sk_buff *skb, struct genl_info *info)
7888{
Johannes Berg4c476992010-10-04 21:36:35 +02007889 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Kalle Valoffb9eb32010-02-17 17:58:10 +02007890 enum nl80211_ps_state ps_state;
7891 struct wireless_dev *wdev;
Johannes Berg4c476992010-10-04 21:36:35 +02007892 struct net_device *dev = info->user_ptr[1];
Kalle Valoffb9eb32010-02-17 17:58:10 +02007893 struct sk_buff *msg;
7894 void *hdr;
7895 int err;
7896
Kalle Valoffb9eb32010-02-17 17:58:10 +02007897 wdev = dev->ieee80211_ptr;
7898
Johannes Berg4c476992010-10-04 21:36:35 +02007899 if (!rdev->ops->set_power_mgmt)
7900 return -EOPNOTSUPP;
Kalle Valoffb9eb32010-02-17 17:58:10 +02007901
7902 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02007903 if (!msg)
7904 return -ENOMEM;
Kalle Valoffb9eb32010-02-17 17:58:10 +02007905
Eric W. Biederman15e47302012-09-07 20:12:54 +00007906 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Kalle Valoffb9eb32010-02-17 17:58:10 +02007907 NL80211_CMD_GET_POWER_SAVE);
7908 if (!hdr) {
Johannes Berg4c476992010-10-04 21:36:35 +02007909 err = -ENOBUFS;
Kalle Valoffb9eb32010-02-17 17:58:10 +02007910 goto free_msg;
7911 }
7912
7913 if (wdev->ps)
7914 ps_state = NL80211_PS_ENABLED;
7915 else
7916 ps_state = NL80211_PS_DISABLED;
7917
David S. Miller9360ffd2012-03-29 04:41:26 -04007918 if (nla_put_u32(msg, NL80211_ATTR_PS_STATE, ps_state))
7919 goto nla_put_failure;
Kalle Valoffb9eb32010-02-17 17:58:10 +02007920
7921 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02007922 return genlmsg_reply(msg, info);
Kalle Valoffb9eb32010-02-17 17:58:10 +02007923
Johannes Berg4c476992010-10-04 21:36:35 +02007924 nla_put_failure:
Kalle Valoffb9eb32010-02-17 17:58:10 +02007925 err = -ENOBUFS;
Johannes Berg4c476992010-10-04 21:36:35 +02007926 free_msg:
Kalle Valoffb9eb32010-02-17 17:58:10 +02007927 nlmsg_free(msg);
Kalle Valoffb9eb32010-02-17 17:58:10 +02007928 return err;
7929}
7930
Johannes Berg94e860f2014-01-20 23:58:15 +01007931static const struct nla_policy
7932nl80211_attr_cqm_policy[NL80211_ATTR_CQM_MAX + 1] = {
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02007933 [NL80211_ATTR_CQM_RSSI_THOLD] = { .type = NLA_U32 },
7934 [NL80211_ATTR_CQM_RSSI_HYST] = { .type = NLA_U32 },
7935 [NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT] = { .type = NLA_U32 },
Thomas Pedersen84f10702012-07-12 16:17:33 -07007936 [NL80211_ATTR_CQM_TXE_RATE] = { .type = NLA_U32 },
7937 [NL80211_ATTR_CQM_TXE_PKTS] = { .type = NLA_U32 },
7938 [NL80211_ATTR_CQM_TXE_INTVL] = { .type = NLA_U32 },
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02007939};
7940
Thomas Pedersen84f10702012-07-12 16:17:33 -07007941static int nl80211_set_cqm_txe(struct genl_info *info,
Johannes Bergd9d8b012012-11-26 12:51:52 +01007942 u32 rate, u32 pkts, u32 intvl)
Thomas Pedersen84f10702012-07-12 16:17:33 -07007943{
7944 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Thomas Pedersen84f10702012-07-12 16:17:33 -07007945 struct net_device *dev = info->user_ptr[1];
Johannes Berg1da5fcc2013-08-06 14:10:48 +02007946 struct wireless_dev *wdev = dev->ieee80211_ptr;
Thomas Pedersen84f10702012-07-12 16:17:33 -07007947
Johannes Bergd9d8b012012-11-26 12:51:52 +01007948 if (rate > 100 || intvl > NL80211_CQM_TXE_MAX_INTVL)
Thomas Pedersen84f10702012-07-12 16:17:33 -07007949 return -EINVAL;
7950
Thomas Pedersen84f10702012-07-12 16:17:33 -07007951 if (!rdev->ops->set_cqm_txe_config)
7952 return -EOPNOTSUPP;
7953
7954 if (wdev->iftype != NL80211_IFTYPE_STATION &&
7955 wdev->iftype != NL80211_IFTYPE_P2P_CLIENT)
7956 return -EOPNOTSUPP;
7957
Hila Gonene35e4d22012-06-27 17:19:42 +03007958 return rdev_set_cqm_txe_config(rdev, dev, rate, pkts, intvl);
Thomas Pedersen84f10702012-07-12 16:17:33 -07007959}
7960
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02007961static int nl80211_set_cqm_rssi(struct genl_info *info,
7962 s32 threshold, u32 hysteresis)
7963{
Johannes Berg4c476992010-10-04 21:36:35 +02007964 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg4c476992010-10-04 21:36:35 +02007965 struct net_device *dev = info->user_ptr[1];
Johannes Berg1da5fcc2013-08-06 14:10:48 +02007966 struct wireless_dev *wdev = dev->ieee80211_ptr;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02007967
7968 if (threshold > 0)
7969 return -EINVAL;
7970
Johannes Berg1da5fcc2013-08-06 14:10:48 +02007971 /* disabling - hysteresis should also be zero then */
7972 if (threshold == 0)
7973 hysteresis = 0;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02007974
Johannes Berg4c476992010-10-04 21:36:35 +02007975 if (!rdev->ops->set_cqm_rssi_config)
7976 return -EOPNOTSUPP;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02007977
Johannes Berg074ac8d2010-09-16 14:58:22 +02007978 if (wdev->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02007979 wdev->iftype != NL80211_IFTYPE_P2P_CLIENT)
7980 return -EOPNOTSUPP;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02007981
Hila Gonene35e4d22012-06-27 17:19:42 +03007982 return rdev_set_cqm_rssi_config(rdev, dev, threshold, hysteresis);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02007983}
7984
7985static int nl80211_set_cqm(struct sk_buff *skb, struct genl_info *info)
7986{
7987 struct nlattr *attrs[NL80211_ATTR_CQM_MAX + 1];
7988 struct nlattr *cqm;
7989 int err;
7990
7991 cqm = info->attrs[NL80211_ATTR_CQM];
Johannes Berg1da5fcc2013-08-06 14:10:48 +02007992 if (!cqm)
7993 return -EINVAL;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02007994
7995 err = nla_parse_nested(attrs, NL80211_ATTR_CQM_MAX, cqm,
7996 nl80211_attr_cqm_policy);
7997 if (err)
Johannes Berg1da5fcc2013-08-06 14:10:48 +02007998 return err;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02007999
8000 if (attrs[NL80211_ATTR_CQM_RSSI_THOLD] &&
8001 attrs[NL80211_ATTR_CQM_RSSI_HYST]) {
Johannes Berg1da5fcc2013-08-06 14:10:48 +02008002 s32 threshold = nla_get_s32(attrs[NL80211_ATTR_CQM_RSSI_THOLD]);
8003 u32 hysteresis = nla_get_u32(attrs[NL80211_ATTR_CQM_RSSI_HYST]);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008004
Johannes Berg1da5fcc2013-08-06 14:10:48 +02008005 return nl80211_set_cqm_rssi(info, threshold, hysteresis);
8006 }
8007
8008 if (attrs[NL80211_ATTR_CQM_TXE_RATE] &&
8009 attrs[NL80211_ATTR_CQM_TXE_PKTS] &&
8010 attrs[NL80211_ATTR_CQM_TXE_INTVL]) {
8011 u32 rate = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_RATE]);
8012 u32 pkts = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_PKTS]);
8013 u32 intvl = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_INTVL]);
8014
8015 return nl80211_set_cqm_txe(info, rate, pkts, intvl);
8016 }
8017
8018 return -EINVAL;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008019}
8020
Johannes Berg29cbe682010-12-03 09:20:44 +01008021static int nl80211_join_mesh(struct sk_buff *skb, struct genl_info *info)
8022{
8023 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8024 struct net_device *dev = info->user_ptr[1];
8025 struct mesh_config cfg;
Javier Cardonac80d5452010-12-16 17:37:49 -08008026 struct mesh_setup setup;
Johannes Berg29cbe682010-12-03 09:20:44 +01008027 int err;
8028
8029 /* start with default */
8030 memcpy(&cfg, &default_mesh_config, sizeof(cfg));
Javier Cardonac80d5452010-12-16 17:37:49 -08008031 memcpy(&setup, &default_mesh_setup, sizeof(setup));
Johannes Berg29cbe682010-12-03 09:20:44 +01008032
Javier Cardona24bdd9f2010-12-16 17:37:48 -08008033 if (info->attrs[NL80211_ATTR_MESH_CONFIG]) {
Johannes Berg29cbe682010-12-03 09:20:44 +01008034 /* and parse parameters if given */
Javier Cardona24bdd9f2010-12-16 17:37:48 -08008035 err = nl80211_parse_mesh_config(info, &cfg, NULL);
Johannes Berg29cbe682010-12-03 09:20:44 +01008036 if (err)
8037 return err;
8038 }
8039
8040 if (!info->attrs[NL80211_ATTR_MESH_ID] ||
8041 !nla_len(info->attrs[NL80211_ATTR_MESH_ID]))
8042 return -EINVAL;
8043
Javier Cardonac80d5452010-12-16 17:37:49 -08008044 setup.mesh_id = nla_data(info->attrs[NL80211_ATTR_MESH_ID]);
8045 setup.mesh_id_len = nla_len(info->attrs[NL80211_ATTR_MESH_ID]);
8046
Chun-Yeow Yeoh4bb62342011-11-24 17:15:20 -08008047 if (info->attrs[NL80211_ATTR_MCAST_RATE] &&
8048 !nl80211_parse_mcast_rate(rdev, setup.mcast_rate,
8049 nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE])))
8050 return -EINVAL;
8051
Marco Porsch9bdbf042013-01-07 16:04:51 +01008052 if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) {
8053 setup.beacon_interval =
8054 nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]);
8055 if (setup.beacon_interval < 10 ||
8056 setup.beacon_interval > 10000)
8057 return -EINVAL;
8058 }
8059
8060 if (info->attrs[NL80211_ATTR_DTIM_PERIOD]) {
8061 setup.dtim_period =
8062 nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]);
8063 if (setup.dtim_period < 1 || setup.dtim_period > 100)
8064 return -EINVAL;
8065 }
8066
Javier Cardonac80d5452010-12-16 17:37:49 -08008067 if (info->attrs[NL80211_ATTR_MESH_SETUP]) {
8068 /* parse additional setup parameters if given */
8069 err = nl80211_parse_mesh_setup(info, &setup);
8070 if (err)
8071 return err;
8072 }
8073
Thomas Pedersend37bb182013-03-04 13:06:13 -08008074 if (setup.user_mpm)
8075 cfg.auto_open_plinks = false;
8076
Johannes Bergcc1d2802012-05-16 23:50:20 +02008077 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
Johannes Berg683b6d32012-11-08 21:25:48 +01008078 err = nl80211_parse_chandef(rdev, info, &setup.chandef);
8079 if (err)
8080 return err;
Johannes Bergcc1d2802012-05-16 23:50:20 +02008081 } else {
8082 /* cfg80211_join_mesh() will sort it out */
Johannes Berg683b6d32012-11-08 21:25:48 +01008083 setup.chandef.chan = NULL;
Johannes Bergcc1d2802012-05-16 23:50:20 +02008084 }
8085
Ashok Nagarajanffb3cf32013-06-03 10:33:36 -07008086 if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) {
8087 u8 *rates = nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
8088 int n_rates =
8089 nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
8090 struct ieee80211_supported_band *sband;
8091
8092 if (!setup.chandef.chan)
8093 return -EINVAL;
8094
8095 sband = rdev->wiphy.bands[setup.chandef.chan->band];
8096
8097 err = ieee80211_get_ratemask(sband, rates, n_rates,
8098 &setup.basic_rates);
8099 if (err)
8100 return err;
8101 }
8102
Javier Cardonac80d5452010-12-16 17:37:49 -08008103 return cfg80211_join_mesh(rdev, dev, &setup, &cfg);
Johannes Berg29cbe682010-12-03 09:20:44 +01008104}
8105
8106static int nl80211_leave_mesh(struct sk_buff *skb, struct genl_info *info)
8107{
8108 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8109 struct net_device *dev = info->user_ptr[1];
8110
8111 return cfg80211_leave_mesh(rdev, dev);
8112}
8113
Johannes Bergdfb89c52012-06-27 09:23:48 +02008114#ifdef CONFIG_PM
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08008115static int nl80211_send_wowlan_patterns(struct sk_buff *msg,
8116 struct cfg80211_registered_device *rdev)
8117{
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008118 struct cfg80211_wowlan *wowlan = rdev->wiphy.wowlan_config;
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08008119 struct nlattr *nl_pats, *nl_pat;
8120 int i, pat_len;
8121
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008122 if (!wowlan->n_patterns)
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08008123 return 0;
8124
8125 nl_pats = nla_nest_start(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN);
8126 if (!nl_pats)
8127 return -ENOBUFS;
8128
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008129 for (i = 0; i < wowlan->n_patterns; i++) {
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08008130 nl_pat = nla_nest_start(msg, i + 1);
8131 if (!nl_pat)
8132 return -ENOBUFS;
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008133 pat_len = wowlan->patterns[i].pattern_len;
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07008134 if (nla_put(msg, NL80211_PKTPAT_MASK, DIV_ROUND_UP(pat_len, 8),
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008135 wowlan->patterns[i].mask) ||
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07008136 nla_put(msg, NL80211_PKTPAT_PATTERN, pat_len,
8137 wowlan->patterns[i].pattern) ||
8138 nla_put_u32(msg, NL80211_PKTPAT_OFFSET,
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008139 wowlan->patterns[i].pkt_offset))
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08008140 return -ENOBUFS;
8141 nla_nest_end(msg, nl_pat);
8142 }
8143 nla_nest_end(msg, nl_pats);
8144
8145 return 0;
8146}
8147
Johannes Berg2a0e0472013-01-23 22:57:40 +01008148static int nl80211_send_wowlan_tcp(struct sk_buff *msg,
8149 struct cfg80211_wowlan_tcp *tcp)
8150{
8151 struct nlattr *nl_tcp;
8152
8153 if (!tcp)
8154 return 0;
8155
8156 nl_tcp = nla_nest_start(msg, NL80211_WOWLAN_TRIG_TCP_CONNECTION);
8157 if (!nl_tcp)
8158 return -ENOBUFS;
8159
8160 if (nla_put_be32(msg, NL80211_WOWLAN_TCP_SRC_IPV4, tcp->src) ||
8161 nla_put_be32(msg, NL80211_WOWLAN_TCP_DST_IPV4, tcp->dst) ||
8162 nla_put(msg, NL80211_WOWLAN_TCP_DST_MAC, ETH_ALEN, tcp->dst_mac) ||
8163 nla_put_u16(msg, NL80211_WOWLAN_TCP_SRC_PORT, tcp->src_port) ||
8164 nla_put_u16(msg, NL80211_WOWLAN_TCP_DST_PORT, tcp->dst_port) ||
8165 nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD,
8166 tcp->payload_len, tcp->payload) ||
8167 nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_INTERVAL,
8168 tcp->data_interval) ||
8169 nla_put(msg, NL80211_WOWLAN_TCP_WAKE_PAYLOAD,
8170 tcp->wake_len, tcp->wake_data) ||
8171 nla_put(msg, NL80211_WOWLAN_TCP_WAKE_MASK,
8172 DIV_ROUND_UP(tcp->wake_len, 8), tcp->wake_mask))
8173 return -ENOBUFS;
8174
8175 if (tcp->payload_seq.len &&
8176 nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ,
8177 sizeof(tcp->payload_seq), &tcp->payload_seq))
8178 return -ENOBUFS;
8179
8180 if (tcp->payload_tok.len &&
8181 nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN,
8182 sizeof(tcp->payload_tok) + tcp->tokens_size,
8183 &tcp->payload_tok))
8184 return -ENOBUFS;
8185
Johannes Berge248ad32013-05-16 10:24:28 +02008186 nla_nest_end(msg, nl_tcp);
8187
Johannes Berg2a0e0472013-01-23 22:57:40 +01008188 return 0;
8189}
8190
Johannes Bergff1b6e62011-05-04 15:37:28 +02008191static int nl80211_get_wowlan(struct sk_buff *skb, struct genl_info *info)
8192{
8193 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8194 struct sk_buff *msg;
8195 void *hdr;
Johannes Berg2a0e0472013-01-23 22:57:40 +01008196 u32 size = NLMSG_DEFAULT_SIZE;
Johannes Bergff1b6e62011-05-04 15:37:28 +02008197
Johannes Berg964dc9e2013-06-03 17:25:34 +02008198 if (!rdev->wiphy.wowlan)
Johannes Bergff1b6e62011-05-04 15:37:28 +02008199 return -EOPNOTSUPP;
8200
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008201 if (rdev->wiphy.wowlan_config && rdev->wiphy.wowlan_config->tcp) {
Johannes Berg2a0e0472013-01-23 22:57:40 +01008202 /* adjust size to have room for all the data */
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008203 size += rdev->wiphy.wowlan_config->tcp->tokens_size +
8204 rdev->wiphy.wowlan_config->tcp->payload_len +
8205 rdev->wiphy.wowlan_config->tcp->wake_len +
8206 rdev->wiphy.wowlan_config->tcp->wake_len / 8;
Johannes Berg2a0e0472013-01-23 22:57:40 +01008207 }
8208
8209 msg = nlmsg_new(size, GFP_KERNEL);
Johannes Bergff1b6e62011-05-04 15:37:28 +02008210 if (!msg)
8211 return -ENOMEM;
8212
Eric W. Biederman15e47302012-09-07 20:12:54 +00008213 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Johannes Bergff1b6e62011-05-04 15:37:28 +02008214 NL80211_CMD_GET_WOWLAN);
8215 if (!hdr)
8216 goto nla_put_failure;
8217
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008218 if (rdev->wiphy.wowlan_config) {
Johannes Bergff1b6e62011-05-04 15:37:28 +02008219 struct nlattr *nl_wowlan;
8220
8221 nl_wowlan = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS);
8222 if (!nl_wowlan)
8223 goto nla_put_failure;
8224
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008225 if ((rdev->wiphy.wowlan_config->any &&
David S. Miller9360ffd2012-03-29 04:41:26 -04008226 nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008227 (rdev->wiphy.wowlan_config->disconnect &&
David S. Miller9360ffd2012-03-29 04:41:26 -04008228 nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008229 (rdev->wiphy.wowlan_config->magic_pkt &&
David S. Miller9360ffd2012-03-29 04:41:26 -04008230 nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008231 (rdev->wiphy.wowlan_config->gtk_rekey_failure &&
David S. Miller9360ffd2012-03-29 04:41:26 -04008232 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008233 (rdev->wiphy.wowlan_config->eap_identity_req &&
David S. Miller9360ffd2012-03-29 04:41:26 -04008234 nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008235 (rdev->wiphy.wowlan_config->four_way_handshake &&
David S. Miller9360ffd2012-03-29 04:41:26 -04008236 nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008237 (rdev->wiphy.wowlan_config->rfkill_release &&
David S. Miller9360ffd2012-03-29 04:41:26 -04008238 nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE)))
8239 goto nla_put_failure;
Johannes Berg2a0e0472013-01-23 22:57:40 +01008240
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08008241 if (nl80211_send_wowlan_patterns(msg, rdev))
8242 goto nla_put_failure;
Johannes Berg2a0e0472013-01-23 22:57:40 +01008243
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008244 if (nl80211_send_wowlan_tcp(msg,
8245 rdev->wiphy.wowlan_config->tcp))
Johannes Berg2a0e0472013-01-23 22:57:40 +01008246 goto nla_put_failure;
8247
Johannes Bergff1b6e62011-05-04 15:37:28 +02008248 nla_nest_end(msg, nl_wowlan);
8249 }
8250
8251 genlmsg_end(msg, hdr);
8252 return genlmsg_reply(msg, info);
8253
8254nla_put_failure:
8255 nlmsg_free(msg);
8256 return -ENOBUFS;
8257}
8258
Johannes Berg2a0e0472013-01-23 22:57:40 +01008259static int nl80211_parse_wowlan_tcp(struct cfg80211_registered_device *rdev,
8260 struct nlattr *attr,
8261 struct cfg80211_wowlan *trig)
8262{
8263 struct nlattr *tb[NUM_NL80211_WOWLAN_TCP];
8264 struct cfg80211_wowlan_tcp *cfg;
8265 struct nl80211_wowlan_tcp_data_token *tok = NULL;
8266 struct nl80211_wowlan_tcp_data_seq *seq = NULL;
8267 u32 size;
8268 u32 data_size, wake_size, tokens_size = 0, wake_mask_size;
8269 int err, port;
8270
Johannes Berg964dc9e2013-06-03 17:25:34 +02008271 if (!rdev->wiphy.wowlan->tcp)
Johannes Berg2a0e0472013-01-23 22:57:40 +01008272 return -EINVAL;
8273
8274 err = nla_parse(tb, MAX_NL80211_WOWLAN_TCP,
8275 nla_data(attr), nla_len(attr),
8276 nl80211_wowlan_tcp_policy);
8277 if (err)
8278 return err;
8279
8280 if (!tb[NL80211_WOWLAN_TCP_SRC_IPV4] ||
8281 !tb[NL80211_WOWLAN_TCP_DST_IPV4] ||
8282 !tb[NL80211_WOWLAN_TCP_DST_MAC] ||
8283 !tb[NL80211_WOWLAN_TCP_DST_PORT] ||
8284 !tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD] ||
8285 !tb[NL80211_WOWLAN_TCP_DATA_INTERVAL] ||
8286 !tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD] ||
8287 !tb[NL80211_WOWLAN_TCP_WAKE_MASK])
8288 return -EINVAL;
8289
8290 data_size = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]);
Johannes Berg964dc9e2013-06-03 17:25:34 +02008291 if (data_size > rdev->wiphy.wowlan->tcp->data_payload_max)
Johannes Berg2a0e0472013-01-23 22:57:40 +01008292 return -EINVAL;
8293
8294 if (nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]) >
Johannes Berg964dc9e2013-06-03 17:25:34 +02008295 rdev->wiphy.wowlan->tcp->data_interval_max ||
Johannes Berg723d5682013-02-26 13:56:40 +01008296 nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]) == 0)
Johannes Berg2a0e0472013-01-23 22:57:40 +01008297 return -EINVAL;
8298
8299 wake_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]);
Johannes Berg964dc9e2013-06-03 17:25:34 +02008300 if (wake_size > rdev->wiphy.wowlan->tcp->wake_payload_max)
Johannes Berg2a0e0472013-01-23 22:57:40 +01008301 return -EINVAL;
8302
8303 wake_mask_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_MASK]);
8304 if (wake_mask_size != DIV_ROUND_UP(wake_size, 8))
8305 return -EINVAL;
8306
8307 if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]) {
8308 u32 tokln = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]);
8309
8310 tok = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]);
8311 tokens_size = tokln - sizeof(*tok);
8312
8313 if (!tok->len || tokens_size % tok->len)
8314 return -EINVAL;
Johannes Berg964dc9e2013-06-03 17:25:34 +02008315 if (!rdev->wiphy.wowlan->tcp->tok)
Johannes Berg2a0e0472013-01-23 22:57:40 +01008316 return -EINVAL;
Johannes Berg964dc9e2013-06-03 17:25:34 +02008317 if (tok->len > rdev->wiphy.wowlan->tcp->tok->max_len)
Johannes Berg2a0e0472013-01-23 22:57:40 +01008318 return -EINVAL;
Johannes Berg964dc9e2013-06-03 17:25:34 +02008319 if (tok->len < rdev->wiphy.wowlan->tcp->tok->min_len)
Johannes Berg2a0e0472013-01-23 22:57:40 +01008320 return -EINVAL;
Johannes Berg964dc9e2013-06-03 17:25:34 +02008321 if (tokens_size > rdev->wiphy.wowlan->tcp->tok->bufsize)
Johannes Berg2a0e0472013-01-23 22:57:40 +01008322 return -EINVAL;
8323 if (tok->offset + tok->len > data_size)
8324 return -EINVAL;
8325 }
8326
8327 if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]) {
8328 seq = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]);
Johannes Berg964dc9e2013-06-03 17:25:34 +02008329 if (!rdev->wiphy.wowlan->tcp->seq)
Johannes Berg2a0e0472013-01-23 22:57:40 +01008330 return -EINVAL;
8331 if (seq->len == 0 || seq->len > 4)
8332 return -EINVAL;
8333 if (seq->len + seq->offset > data_size)
8334 return -EINVAL;
8335 }
8336
8337 size = sizeof(*cfg);
8338 size += data_size;
8339 size += wake_size + wake_mask_size;
8340 size += tokens_size;
8341
8342 cfg = kzalloc(size, GFP_KERNEL);
8343 if (!cfg)
8344 return -ENOMEM;
8345 cfg->src = nla_get_be32(tb[NL80211_WOWLAN_TCP_SRC_IPV4]);
8346 cfg->dst = nla_get_be32(tb[NL80211_WOWLAN_TCP_DST_IPV4]);
8347 memcpy(cfg->dst_mac, nla_data(tb[NL80211_WOWLAN_TCP_DST_MAC]),
8348 ETH_ALEN);
8349 if (tb[NL80211_WOWLAN_TCP_SRC_PORT])
8350 port = nla_get_u16(tb[NL80211_WOWLAN_TCP_SRC_PORT]);
8351 else
8352 port = 0;
8353#ifdef CONFIG_INET
8354 /* allocate a socket and port for it and use it */
8355 err = __sock_create(wiphy_net(&rdev->wiphy), PF_INET, SOCK_STREAM,
8356 IPPROTO_TCP, &cfg->sock, 1);
8357 if (err) {
8358 kfree(cfg);
8359 return err;
8360 }
8361 if (inet_csk_get_port(cfg->sock->sk, port)) {
8362 sock_release(cfg->sock);
8363 kfree(cfg);
8364 return -EADDRINUSE;
8365 }
8366 cfg->src_port = inet_sk(cfg->sock->sk)->inet_num;
8367#else
8368 if (!port) {
8369 kfree(cfg);
8370 return -EINVAL;
8371 }
8372 cfg->src_port = port;
8373#endif
8374
8375 cfg->dst_port = nla_get_u16(tb[NL80211_WOWLAN_TCP_DST_PORT]);
8376 cfg->payload_len = data_size;
8377 cfg->payload = (u8 *)cfg + sizeof(*cfg) + tokens_size;
8378 memcpy((void *)cfg->payload,
8379 nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]),
8380 data_size);
8381 if (seq)
8382 cfg->payload_seq = *seq;
8383 cfg->data_interval = nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]);
8384 cfg->wake_len = wake_size;
8385 cfg->wake_data = (u8 *)cfg + sizeof(*cfg) + tokens_size + data_size;
8386 memcpy((void *)cfg->wake_data,
8387 nla_data(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]),
8388 wake_size);
8389 cfg->wake_mask = (u8 *)cfg + sizeof(*cfg) + tokens_size +
8390 data_size + wake_size;
8391 memcpy((void *)cfg->wake_mask,
8392 nla_data(tb[NL80211_WOWLAN_TCP_WAKE_MASK]),
8393 wake_mask_size);
8394 if (tok) {
8395 cfg->tokens_size = tokens_size;
8396 memcpy(&cfg->payload_tok, tok, sizeof(*tok) + tokens_size);
8397 }
8398
8399 trig->tcp = cfg;
8400
8401 return 0;
8402}
8403
Johannes Bergff1b6e62011-05-04 15:37:28 +02008404static int nl80211_set_wowlan(struct sk_buff *skb, struct genl_info *info)
8405{
8406 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8407 struct nlattr *tb[NUM_NL80211_WOWLAN_TRIG];
Johannes Bergff1b6e62011-05-04 15:37:28 +02008408 struct cfg80211_wowlan new_triggers = {};
Johannes Bergae33bd82012-07-12 16:25:02 +02008409 struct cfg80211_wowlan *ntrig;
Johannes Berg964dc9e2013-06-03 17:25:34 +02008410 const struct wiphy_wowlan_support *wowlan = rdev->wiphy.wowlan;
Johannes Bergff1b6e62011-05-04 15:37:28 +02008411 int err, i;
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008412 bool prev_enabled = rdev->wiphy.wowlan_config;
Johannes Bergff1b6e62011-05-04 15:37:28 +02008413
Johannes Berg964dc9e2013-06-03 17:25:34 +02008414 if (!wowlan)
Johannes Bergff1b6e62011-05-04 15:37:28 +02008415 return -EOPNOTSUPP;
8416
Johannes Bergae33bd82012-07-12 16:25:02 +02008417 if (!info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]) {
8418 cfg80211_rdev_free_wowlan(rdev);
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008419 rdev->wiphy.wowlan_config = NULL;
Johannes Bergae33bd82012-07-12 16:25:02 +02008420 goto set_wakeup;
8421 }
Johannes Bergff1b6e62011-05-04 15:37:28 +02008422
8423 err = nla_parse(tb, MAX_NL80211_WOWLAN_TRIG,
8424 nla_data(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]),
8425 nla_len(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]),
8426 nl80211_wowlan_policy);
8427 if (err)
8428 return err;
8429
8430 if (tb[NL80211_WOWLAN_TRIG_ANY]) {
8431 if (!(wowlan->flags & WIPHY_WOWLAN_ANY))
8432 return -EINVAL;
8433 new_triggers.any = true;
8434 }
8435
8436 if (tb[NL80211_WOWLAN_TRIG_DISCONNECT]) {
8437 if (!(wowlan->flags & WIPHY_WOWLAN_DISCONNECT))
8438 return -EINVAL;
8439 new_triggers.disconnect = true;
8440 }
8441
8442 if (tb[NL80211_WOWLAN_TRIG_MAGIC_PKT]) {
8443 if (!(wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT))
8444 return -EINVAL;
8445 new_triggers.magic_pkt = true;
8446 }
8447
Johannes Berg77dbbb12011-07-13 10:48:55 +02008448 if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED])
8449 return -EINVAL;
8450
8451 if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE]) {
8452 if (!(wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE))
8453 return -EINVAL;
8454 new_triggers.gtk_rekey_failure = true;
8455 }
8456
8457 if (tb[NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST]) {
8458 if (!(wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ))
8459 return -EINVAL;
8460 new_triggers.eap_identity_req = true;
8461 }
8462
8463 if (tb[NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE]) {
8464 if (!(wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE))
8465 return -EINVAL;
8466 new_triggers.four_way_handshake = true;
8467 }
8468
8469 if (tb[NL80211_WOWLAN_TRIG_RFKILL_RELEASE]) {
8470 if (!(wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE))
8471 return -EINVAL;
8472 new_triggers.rfkill_release = true;
8473 }
8474
Johannes Bergff1b6e62011-05-04 15:37:28 +02008475 if (tb[NL80211_WOWLAN_TRIG_PKT_PATTERN]) {
8476 struct nlattr *pat;
8477 int n_patterns = 0;
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08008478 int rem, pat_len, mask_len, pkt_offset;
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07008479 struct nlattr *pat_tb[NUM_NL80211_PKTPAT];
Johannes Bergff1b6e62011-05-04 15:37:28 +02008480
8481 nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN],
8482 rem)
8483 n_patterns++;
8484 if (n_patterns > wowlan->n_patterns)
8485 return -EINVAL;
8486
8487 new_triggers.patterns = kcalloc(n_patterns,
8488 sizeof(new_triggers.patterns[0]),
8489 GFP_KERNEL);
8490 if (!new_triggers.patterns)
8491 return -ENOMEM;
8492
8493 new_triggers.n_patterns = n_patterns;
8494 i = 0;
8495
8496 nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN],
8497 rem) {
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07008498 nla_parse(pat_tb, MAX_NL80211_PKTPAT, nla_data(pat),
8499 nla_len(pat), NULL);
Johannes Bergff1b6e62011-05-04 15:37:28 +02008500 err = -EINVAL;
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07008501 if (!pat_tb[NL80211_PKTPAT_MASK] ||
8502 !pat_tb[NL80211_PKTPAT_PATTERN])
Johannes Bergff1b6e62011-05-04 15:37:28 +02008503 goto error;
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07008504 pat_len = nla_len(pat_tb[NL80211_PKTPAT_PATTERN]);
Johannes Bergff1b6e62011-05-04 15:37:28 +02008505 mask_len = DIV_ROUND_UP(pat_len, 8);
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07008506 if (nla_len(pat_tb[NL80211_PKTPAT_MASK]) != mask_len)
Johannes Bergff1b6e62011-05-04 15:37:28 +02008507 goto error;
8508 if (pat_len > wowlan->pattern_max_len ||
8509 pat_len < wowlan->pattern_min_len)
8510 goto error;
8511
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07008512 if (!pat_tb[NL80211_PKTPAT_OFFSET])
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08008513 pkt_offset = 0;
8514 else
8515 pkt_offset = nla_get_u32(
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07008516 pat_tb[NL80211_PKTPAT_OFFSET]);
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08008517 if (pkt_offset > wowlan->max_pkt_offset)
8518 goto error;
8519 new_triggers.patterns[i].pkt_offset = pkt_offset;
8520
Johannes Bergff1b6e62011-05-04 15:37:28 +02008521 new_triggers.patterns[i].mask =
8522 kmalloc(mask_len + pat_len, GFP_KERNEL);
8523 if (!new_triggers.patterns[i].mask) {
8524 err = -ENOMEM;
8525 goto error;
8526 }
8527 new_triggers.patterns[i].pattern =
8528 new_triggers.patterns[i].mask + mask_len;
8529 memcpy(new_triggers.patterns[i].mask,
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07008530 nla_data(pat_tb[NL80211_PKTPAT_MASK]),
Johannes Bergff1b6e62011-05-04 15:37:28 +02008531 mask_len);
8532 new_triggers.patterns[i].pattern_len = pat_len;
8533 memcpy(new_triggers.patterns[i].pattern,
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07008534 nla_data(pat_tb[NL80211_PKTPAT_PATTERN]),
Johannes Bergff1b6e62011-05-04 15:37:28 +02008535 pat_len);
8536 i++;
8537 }
8538 }
8539
Johannes Berg2a0e0472013-01-23 22:57:40 +01008540 if (tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION]) {
8541 err = nl80211_parse_wowlan_tcp(
8542 rdev, tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION],
8543 &new_triggers);
8544 if (err)
8545 goto error;
8546 }
8547
Johannes Bergae33bd82012-07-12 16:25:02 +02008548 ntrig = kmemdup(&new_triggers, sizeof(new_triggers), GFP_KERNEL);
8549 if (!ntrig) {
8550 err = -ENOMEM;
8551 goto error;
Johannes Bergff1b6e62011-05-04 15:37:28 +02008552 }
Johannes Bergae33bd82012-07-12 16:25:02 +02008553 cfg80211_rdev_free_wowlan(rdev);
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008554 rdev->wiphy.wowlan_config = ntrig;
Johannes Bergff1b6e62011-05-04 15:37:28 +02008555
Johannes Bergae33bd82012-07-12 16:25:02 +02008556 set_wakeup:
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008557 if (rdev->ops->set_wakeup &&
8558 prev_enabled != !!rdev->wiphy.wowlan_config)
8559 rdev_set_wakeup(rdev, rdev->wiphy.wowlan_config);
Johannes Berg6d525632012-04-04 15:05:25 +02008560
Johannes Bergff1b6e62011-05-04 15:37:28 +02008561 return 0;
8562 error:
8563 for (i = 0; i < new_triggers.n_patterns; i++)
8564 kfree(new_triggers.patterns[i].mask);
8565 kfree(new_triggers.patterns);
Johannes Berg2a0e0472013-01-23 22:57:40 +01008566 if (new_triggers.tcp && new_triggers.tcp->sock)
8567 sock_release(new_triggers.tcp->sock);
8568 kfree(new_triggers.tcp);
Johannes Bergff1b6e62011-05-04 15:37:28 +02008569 return err;
8570}
Johannes Bergdfb89c52012-06-27 09:23:48 +02008571#endif
Johannes Bergff1b6e62011-05-04 15:37:28 +02008572
Amitkumar Karwarbe29b99a2013-06-28 11:51:26 -07008573static int nl80211_send_coalesce_rules(struct sk_buff *msg,
8574 struct cfg80211_registered_device *rdev)
8575{
8576 struct nlattr *nl_pats, *nl_pat, *nl_rule, *nl_rules;
8577 int i, j, pat_len;
8578 struct cfg80211_coalesce_rules *rule;
8579
8580 if (!rdev->coalesce->n_rules)
8581 return 0;
8582
8583 nl_rules = nla_nest_start(msg, NL80211_ATTR_COALESCE_RULE);
8584 if (!nl_rules)
8585 return -ENOBUFS;
8586
8587 for (i = 0; i < rdev->coalesce->n_rules; i++) {
8588 nl_rule = nla_nest_start(msg, i + 1);
8589 if (!nl_rule)
8590 return -ENOBUFS;
8591
8592 rule = &rdev->coalesce->rules[i];
8593 if (nla_put_u32(msg, NL80211_ATTR_COALESCE_RULE_DELAY,
8594 rule->delay))
8595 return -ENOBUFS;
8596
8597 if (nla_put_u32(msg, NL80211_ATTR_COALESCE_RULE_CONDITION,
8598 rule->condition))
8599 return -ENOBUFS;
8600
8601 nl_pats = nla_nest_start(msg,
8602 NL80211_ATTR_COALESCE_RULE_PKT_PATTERN);
8603 if (!nl_pats)
8604 return -ENOBUFS;
8605
8606 for (j = 0; j < rule->n_patterns; j++) {
8607 nl_pat = nla_nest_start(msg, j + 1);
8608 if (!nl_pat)
8609 return -ENOBUFS;
8610 pat_len = rule->patterns[j].pattern_len;
8611 if (nla_put(msg, NL80211_PKTPAT_MASK,
8612 DIV_ROUND_UP(pat_len, 8),
8613 rule->patterns[j].mask) ||
8614 nla_put(msg, NL80211_PKTPAT_PATTERN, pat_len,
8615 rule->patterns[j].pattern) ||
8616 nla_put_u32(msg, NL80211_PKTPAT_OFFSET,
8617 rule->patterns[j].pkt_offset))
8618 return -ENOBUFS;
8619 nla_nest_end(msg, nl_pat);
8620 }
8621 nla_nest_end(msg, nl_pats);
8622 nla_nest_end(msg, nl_rule);
8623 }
8624 nla_nest_end(msg, nl_rules);
8625
8626 return 0;
8627}
8628
8629static int nl80211_get_coalesce(struct sk_buff *skb, struct genl_info *info)
8630{
8631 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8632 struct sk_buff *msg;
8633 void *hdr;
8634
8635 if (!rdev->wiphy.coalesce)
8636 return -EOPNOTSUPP;
8637
8638 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
8639 if (!msg)
8640 return -ENOMEM;
8641
8642 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
8643 NL80211_CMD_GET_COALESCE);
8644 if (!hdr)
8645 goto nla_put_failure;
8646
8647 if (rdev->coalesce && nl80211_send_coalesce_rules(msg, rdev))
8648 goto nla_put_failure;
8649
8650 genlmsg_end(msg, hdr);
8651 return genlmsg_reply(msg, info);
8652
8653nla_put_failure:
8654 nlmsg_free(msg);
8655 return -ENOBUFS;
8656}
8657
8658void cfg80211_rdev_free_coalesce(struct cfg80211_registered_device *rdev)
8659{
8660 struct cfg80211_coalesce *coalesce = rdev->coalesce;
8661 int i, j;
8662 struct cfg80211_coalesce_rules *rule;
8663
8664 if (!coalesce)
8665 return;
8666
8667 for (i = 0; i < coalesce->n_rules; i++) {
8668 rule = &coalesce->rules[i];
8669 for (j = 0; j < rule->n_patterns; j++)
8670 kfree(rule->patterns[j].mask);
8671 kfree(rule->patterns);
8672 }
8673 kfree(coalesce->rules);
8674 kfree(coalesce);
8675 rdev->coalesce = NULL;
8676}
8677
8678static int nl80211_parse_coalesce_rule(struct cfg80211_registered_device *rdev,
8679 struct nlattr *rule,
8680 struct cfg80211_coalesce_rules *new_rule)
8681{
8682 int err, i;
8683 const struct wiphy_coalesce_support *coalesce = rdev->wiphy.coalesce;
8684 struct nlattr *tb[NUM_NL80211_ATTR_COALESCE_RULE], *pat;
8685 int rem, pat_len, mask_len, pkt_offset, n_patterns = 0;
8686 struct nlattr *pat_tb[NUM_NL80211_PKTPAT];
8687
8688 err = nla_parse(tb, NL80211_ATTR_COALESCE_RULE_MAX, nla_data(rule),
8689 nla_len(rule), nl80211_coalesce_policy);
8690 if (err)
8691 return err;
8692
8693 if (tb[NL80211_ATTR_COALESCE_RULE_DELAY])
8694 new_rule->delay =
8695 nla_get_u32(tb[NL80211_ATTR_COALESCE_RULE_DELAY]);
8696 if (new_rule->delay > coalesce->max_delay)
8697 return -EINVAL;
8698
8699 if (tb[NL80211_ATTR_COALESCE_RULE_CONDITION])
8700 new_rule->condition =
8701 nla_get_u32(tb[NL80211_ATTR_COALESCE_RULE_CONDITION]);
8702 if (new_rule->condition != NL80211_COALESCE_CONDITION_MATCH &&
8703 new_rule->condition != NL80211_COALESCE_CONDITION_NO_MATCH)
8704 return -EINVAL;
8705
8706 if (!tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN])
8707 return -EINVAL;
8708
8709 nla_for_each_nested(pat, tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN],
8710 rem)
8711 n_patterns++;
8712 if (n_patterns > coalesce->n_patterns)
8713 return -EINVAL;
8714
8715 new_rule->patterns = kcalloc(n_patterns, sizeof(new_rule->patterns[0]),
8716 GFP_KERNEL);
8717 if (!new_rule->patterns)
8718 return -ENOMEM;
8719
8720 new_rule->n_patterns = n_patterns;
8721 i = 0;
8722
8723 nla_for_each_nested(pat, tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN],
8724 rem) {
8725 nla_parse(pat_tb, MAX_NL80211_PKTPAT, nla_data(pat),
8726 nla_len(pat), NULL);
8727 if (!pat_tb[NL80211_PKTPAT_MASK] ||
8728 !pat_tb[NL80211_PKTPAT_PATTERN])
8729 return -EINVAL;
8730 pat_len = nla_len(pat_tb[NL80211_PKTPAT_PATTERN]);
8731 mask_len = DIV_ROUND_UP(pat_len, 8);
8732 if (nla_len(pat_tb[NL80211_PKTPAT_MASK]) != mask_len)
8733 return -EINVAL;
8734 if (pat_len > coalesce->pattern_max_len ||
8735 pat_len < coalesce->pattern_min_len)
8736 return -EINVAL;
8737
8738 if (!pat_tb[NL80211_PKTPAT_OFFSET])
8739 pkt_offset = 0;
8740 else
8741 pkt_offset = nla_get_u32(pat_tb[NL80211_PKTPAT_OFFSET]);
8742 if (pkt_offset > coalesce->max_pkt_offset)
8743 return -EINVAL;
8744 new_rule->patterns[i].pkt_offset = pkt_offset;
8745
8746 new_rule->patterns[i].mask =
8747 kmalloc(mask_len + pat_len, GFP_KERNEL);
8748 if (!new_rule->patterns[i].mask)
8749 return -ENOMEM;
8750 new_rule->patterns[i].pattern =
8751 new_rule->patterns[i].mask + mask_len;
8752 memcpy(new_rule->patterns[i].mask,
8753 nla_data(pat_tb[NL80211_PKTPAT_MASK]), mask_len);
8754 new_rule->patterns[i].pattern_len = pat_len;
8755 memcpy(new_rule->patterns[i].pattern,
8756 nla_data(pat_tb[NL80211_PKTPAT_PATTERN]), pat_len);
8757 i++;
8758 }
8759
8760 return 0;
8761}
8762
8763static int nl80211_set_coalesce(struct sk_buff *skb, struct genl_info *info)
8764{
8765 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8766 const struct wiphy_coalesce_support *coalesce = rdev->wiphy.coalesce;
8767 struct cfg80211_coalesce new_coalesce = {};
8768 struct cfg80211_coalesce *n_coalesce;
8769 int err, rem_rule, n_rules = 0, i, j;
8770 struct nlattr *rule;
8771 struct cfg80211_coalesce_rules *tmp_rule;
8772
8773 if (!rdev->wiphy.coalesce || !rdev->ops->set_coalesce)
8774 return -EOPNOTSUPP;
8775
8776 if (!info->attrs[NL80211_ATTR_COALESCE_RULE]) {
8777 cfg80211_rdev_free_coalesce(rdev);
8778 rdev->ops->set_coalesce(&rdev->wiphy, NULL);
8779 return 0;
8780 }
8781
8782 nla_for_each_nested(rule, info->attrs[NL80211_ATTR_COALESCE_RULE],
8783 rem_rule)
8784 n_rules++;
8785 if (n_rules > coalesce->n_rules)
8786 return -EINVAL;
8787
8788 new_coalesce.rules = kcalloc(n_rules, sizeof(new_coalesce.rules[0]),
8789 GFP_KERNEL);
8790 if (!new_coalesce.rules)
8791 return -ENOMEM;
8792
8793 new_coalesce.n_rules = n_rules;
8794 i = 0;
8795
8796 nla_for_each_nested(rule, info->attrs[NL80211_ATTR_COALESCE_RULE],
8797 rem_rule) {
8798 err = nl80211_parse_coalesce_rule(rdev, rule,
8799 &new_coalesce.rules[i]);
8800 if (err)
8801 goto error;
8802
8803 i++;
8804 }
8805
8806 err = rdev->ops->set_coalesce(&rdev->wiphy, &new_coalesce);
8807 if (err)
8808 goto error;
8809
8810 n_coalesce = kmemdup(&new_coalesce, sizeof(new_coalesce), GFP_KERNEL);
8811 if (!n_coalesce) {
8812 err = -ENOMEM;
8813 goto error;
8814 }
8815 cfg80211_rdev_free_coalesce(rdev);
8816 rdev->coalesce = n_coalesce;
8817
8818 return 0;
8819error:
8820 for (i = 0; i < new_coalesce.n_rules; i++) {
8821 tmp_rule = &new_coalesce.rules[i];
8822 for (j = 0; j < tmp_rule->n_patterns; j++)
8823 kfree(tmp_rule->patterns[j].mask);
8824 kfree(tmp_rule->patterns);
8825 }
8826 kfree(new_coalesce.rules);
8827
8828 return err;
8829}
8830
Johannes Berge5497d72011-07-05 16:35:40 +02008831static int nl80211_set_rekey_data(struct sk_buff *skb, struct genl_info *info)
8832{
8833 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8834 struct net_device *dev = info->user_ptr[1];
8835 struct wireless_dev *wdev = dev->ieee80211_ptr;
8836 struct nlattr *tb[NUM_NL80211_REKEY_DATA];
8837 struct cfg80211_gtk_rekey_data rekey_data;
8838 int err;
8839
8840 if (!info->attrs[NL80211_ATTR_REKEY_DATA])
8841 return -EINVAL;
8842
8843 err = nla_parse(tb, MAX_NL80211_REKEY_DATA,
8844 nla_data(info->attrs[NL80211_ATTR_REKEY_DATA]),
8845 nla_len(info->attrs[NL80211_ATTR_REKEY_DATA]),
8846 nl80211_rekey_policy);
8847 if (err)
8848 return err;
8849
8850 if (nla_len(tb[NL80211_REKEY_DATA_REPLAY_CTR]) != NL80211_REPLAY_CTR_LEN)
8851 return -ERANGE;
8852 if (nla_len(tb[NL80211_REKEY_DATA_KEK]) != NL80211_KEK_LEN)
8853 return -ERANGE;
8854 if (nla_len(tb[NL80211_REKEY_DATA_KCK]) != NL80211_KCK_LEN)
8855 return -ERANGE;
8856
8857 memcpy(rekey_data.kek, nla_data(tb[NL80211_REKEY_DATA_KEK]),
8858 NL80211_KEK_LEN);
8859 memcpy(rekey_data.kck, nla_data(tb[NL80211_REKEY_DATA_KCK]),
8860 NL80211_KCK_LEN);
8861 memcpy(rekey_data.replay_ctr,
8862 nla_data(tb[NL80211_REKEY_DATA_REPLAY_CTR]),
8863 NL80211_REPLAY_CTR_LEN);
8864
8865 wdev_lock(wdev);
8866 if (!wdev->current_bss) {
8867 err = -ENOTCONN;
8868 goto out;
8869 }
8870
8871 if (!rdev->ops->set_rekey_data) {
8872 err = -EOPNOTSUPP;
8873 goto out;
8874 }
8875
Hila Gonene35e4d22012-06-27 17:19:42 +03008876 err = rdev_set_rekey_data(rdev, dev, &rekey_data);
Johannes Berge5497d72011-07-05 16:35:40 +02008877 out:
8878 wdev_unlock(wdev);
8879 return err;
8880}
8881
Johannes Berg28946da2011-11-04 11:18:12 +01008882static int nl80211_register_unexpected_frame(struct sk_buff *skb,
8883 struct genl_info *info)
8884{
8885 struct net_device *dev = info->user_ptr[1];
8886 struct wireless_dev *wdev = dev->ieee80211_ptr;
8887
8888 if (wdev->iftype != NL80211_IFTYPE_AP &&
8889 wdev->iftype != NL80211_IFTYPE_P2P_GO)
8890 return -EINVAL;
8891
Eric W. Biederman15e47302012-09-07 20:12:54 +00008892 if (wdev->ap_unexpected_nlportid)
Johannes Berg28946da2011-11-04 11:18:12 +01008893 return -EBUSY;
8894
Eric W. Biederman15e47302012-09-07 20:12:54 +00008895 wdev->ap_unexpected_nlportid = info->snd_portid;
Johannes Berg28946da2011-11-04 11:18:12 +01008896 return 0;
8897}
8898
Johannes Berg7f6cf312011-11-04 11:18:15 +01008899static int nl80211_probe_client(struct sk_buff *skb,
8900 struct genl_info *info)
8901{
8902 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8903 struct net_device *dev = info->user_ptr[1];
8904 struct wireless_dev *wdev = dev->ieee80211_ptr;
8905 struct sk_buff *msg;
8906 void *hdr;
8907 const u8 *addr;
8908 u64 cookie;
8909 int err;
8910
8911 if (wdev->iftype != NL80211_IFTYPE_AP &&
8912 wdev->iftype != NL80211_IFTYPE_P2P_GO)
8913 return -EOPNOTSUPP;
8914
8915 if (!info->attrs[NL80211_ATTR_MAC])
8916 return -EINVAL;
8917
8918 if (!rdev->ops->probe_client)
8919 return -EOPNOTSUPP;
8920
8921 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
8922 if (!msg)
8923 return -ENOMEM;
8924
Eric W. Biederman15e47302012-09-07 20:12:54 +00008925 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berg7f6cf312011-11-04 11:18:15 +01008926 NL80211_CMD_PROBE_CLIENT);
Dan Carpentercb35fba2013-08-14 14:50:01 +03008927 if (!hdr) {
8928 err = -ENOBUFS;
Johannes Berg7f6cf312011-11-04 11:18:15 +01008929 goto free_msg;
8930 }
8931
8932 addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
8933
Hila Gonene35e4d22012-06-27 17:19:42 +03008934 err = rdev_probe_client(rdev, dev, addr, &cookie);
Johannes Berg7f6cf312011-11-04 11:18:15 +01008935 if (err)
8936 goto free_msg;
8937
David S. Miller9360ffd2012-03-29 04:41:26 -04008938 if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie))
8939 goto nla_put_failure;
Johannes Berg7f6cf312011-11-04 11:18:15 +01008940
8941 genlmsg_end(msg, hdr);
8942
8943 return genlmsg_reply(msg, info);
8944
8945 nla_put_failure:
8946 err = -ENOBUFS;
8947 free_msg:
8948 nlmsg_free(msg);
8949 return err;
8950}
8951
Johannes Berg5e760232011-11-04 11:18:17 +01008952static int nl80211_register_beacons(struct sk_buff *skb, struct genl_info *info)
8953{
8954 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Ben Greear37c73b52012-10-26 14:49:25 -07008955 struct cfg80211_beacon_registration *reg, *nreg;
8956 int rv;
Johannes Berg5e760232011-11-04 11:18:17 +01008957
8958 if (!(rdev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS))
8959 return -EOPNOTSUPP;
8960
Ben Greear37c73b52012-10-26 14:49:25 -07008961 nreg = kzalloc(sizeof(*nreg), GFP_KERNEL);
8962 if (!nreg)
8963 return -ENOMEM;
Johannes Berg5e760232011-11-04 11:18:17 +01008964
Ben Greear37c73b52012-10-26 14:49:25 -07008965 /* First, check if already registered. */
8966 spin_lock_bh(&rdev->beacon_registrations_lock);
8967 list_for_each_entry(reg, &rdev->beacon_registrations, list) {
8968 if (reg->nlportid == info->snd_portid) {
8969 rv = -EALREADY;
8970 goto out_err;
8971 }
8972 }
8973 /* Add it to the list */
8974 nreg->nlportid = info->snd_portid;
8975 list_add(&nreg->list, &rdev->beacon_registrations);
8976
8977 spin_unlock_bh(&rdev->beacon_registrations_lock);
Johannes Berg5e760232011-11-04 11:18:17 +01008978
8979 return 0;
Ben Greear37c73b52012-10-26 14:49:25 -07008980out_err:
8981 spin_unlock_bh(&rdev->beacon_registrations_lock);
8982 kfree(nreg);
8983 return rv;
Johannes Berg5e760232011-11-04 11:18:17 +01008984}
8985
Johannes Berg98104fde2012-06-16 00:19:54 +02008986static int nl80211_start_p2p_device(struct sk_buff *skb, struct genl_info *info)
8987{
8988 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8989 struct wireless_dev *wdev = info->user_ptr[1];
8990 int err;
8991
8992 if (!rdev->ops->start_p2p_device)
8993 return -EOPNOTSUPP;
8994
8995 if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE)
8996 return -EOPNOTSUPP;
8997
8998 if (wdev->p2p_started)
8999 return 0;
9000
Luciano Coelhob6a55012014-02-27 11:07:21 +02009001 if (rfkill_blocked(rdev->rfkill))
9002 return -ERFKILL;
Johannes Berg98104fde2012-06-16 00:19:54 +02009003
Johannes Bergeeb126e2012-10-23 15:16:50 +02009004 err = rdev_start_p2p_device(rdev, wdev);
Johannes Berg98104fde2012-06-16 00:19:54 +02009005 if (err)
9006 return err;
9007
9008 wdev->p2p_started = true;
Johannes Berg98104fde2012-06-16 00:19:54 +02009009 rdev->opencount++;
Johannes Berg98104fde2012-06-16 00:19:54 +02009010
9011 return 0;
9012}
9013
9014static int nl80211_stop_p2p_device(struct sk_buff *skb, struct genl_info *info)
9015{
9016 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9017 struct wireless_dev *wdev = info->user_ptr[1];
9018
9019 if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE)
9020 return -EOPNOTSUPP;
9021
9022 if (!rdev->ops->stop_p2p_device)
9023 return -EOPNOTSUPP;
9024
Johannes Bergf9f47522013-03-19 15:04:07 +01009025 cfg80211_stop_p2p_device(rdev, wdev);
Johannes Berg98104fde2012-06-16 00:19:54 +02009026
9027 return 0;
9028}
9029
Johannes Berg3713b4e2013-02-14 16:19:38 +01009030static int nl80211_get_protocol_features(struct sk_buff *skb,
9031 struct genl_info *info)
9032{
9033 void *hdr;
9034 struct sk_buff *msg;
9035
9036 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
9037 if (!msg)
9038 return -ENOMEM;
9039
9040 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
9041 NL80211_CMD_GET_PROTOCOL_FEATURES);
9042 if (!hdr)
9043 goto nla_put_failure;
9044
9045 if (nla_put_u32(msg, NL80211_ATTR_PROTOCOL_FEATURES,
9046 NL80211_PROTOCOL_FEATURE_SPLIT_WIPHY_DUMP))
9047 goto nla_put_failure;
9048
9049 genlmsg_end(msg, hdr);
9050 return genlmsg_reply(msg, info);
9051
9052 nla_put_failure:
9053 kfree_skb(msg);
9054 return -ENOBUFS;
9055}
9056
Jouni Malinen355199e2013-02-27 17:14:27 +02009057static int nl80211_update_ft_ies(struct sk_buff *skb, struct genl_info *info)
9058{
9059 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9060 struct cfg80211_update_ft_ies_params ft_params;
9061 struct net_device *dev = info->user_ptr[1];
9062
9063 if (!rdev->ops->update_ft_ies)
9064 return -EOPNOTSUPP;
9065
9066 if (!info->attrs[NL80211_ATTR_MDID] ||
9067 !is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
9068 return -EINVAL;
9069
9070 memset(&ft_params, 0, sizeof(ft_params));
9071 ft_params.md = nla_get_u16(info->attrs[NL80211_ATTR_MDID]);
9072 ft_params.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
9073 ft_params.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
9074
9075 return rdev_update_ft_ies(rdev, dev, &ft_params);
9076}
9077
Arend van Spriel5de17982013-04-18 15:49:00 +02009078static int nl80211_crit_protocol_start(struct sk_buff *skb,
9079 struct genl_info *info)
9080{
9081 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9082 struct wireless_dev *wdev = info->user_ptr[1];
9083 enum nl80211_crit_proto_id proto = NL80211_CRIT_PROTO_UNSPEC;
9084 u16 duration;
9085 int ret;
9086
9087 if (!rdev->ops->crit_proto_start)
9088 return -EOPNOTSUPP;
9089
9090 if (WARN_ON(!rdev->ops->crit_proto_stop))
9091 return -EINVAL;
9092
9093 if (rdev->crit_proto_nlportid)
9094 return -EBUSY;
9095
9096 /* determine protocol if provided */
9097 if (info->attrs[NL80211_ATTR_CRIT_PROT_ID])
9098 proto = nla_get_u16(info->attrs[NL80211_ATTR_CRIT_PROT_ID]);
9099
9100 if (proto >= NUM_NL80211_CRIT_PROTO)
9101 return -EINVAL;
9102
9103 /* timeout must be provided */
9104 if (!info->attrs[NL80211_ATTR_MAX_CRIT_PROT_DURATION])
9105 return -EINVAL;
9106
9107 duration =
9108 nla_get_u16(info->attrs[NL80211_ATTR_MAX_CRIT_PROT_DURATION]);
9109
9110 if (duration > NL80211_CRIT_PROTO_MAX_DURATION)
9111 return -ERANGE;
9112
9113 ret = rdev_crit_proto_start(rdev, wdev, proto, duration);
9114 if (!ret)
9115 rdev->crit_proto_nlportid = info->snd_portid;
9116
9117 return ret;
9118}
9119
9120static int nl80211_crit_protocol_stop(struct sk_buff *skb,
9121 struct genl_info *info)
9122{
9123 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9124 struct wireless_dev *wdev = info->user_ptr[1];
9125
9126 if (!rdev->ops->crit_proto_stop)
9127 return -EOPNOTSUPP;
9128
9129 if (rdev->crit_proto_nlportid) {
9130 rdev->crit_proto_nlportid = 0;
9131 rdev_crit_proto_stop(rdev, wdev);
9132 }
9133 return 0;
9134}
9135
Johannes Bergad7e7182013-11-13 13:37:47 +01009136static int nl80211_vendor_cmd(struct sk_buff *skb, struct genl_info *info)
9137{
9138 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9139 struct wireless_dev *wdev =
9140 __cfg80211_wdev_from_attrs(genl_info_net(info), info->attrs);
9141 int i, err;
9142 u32 vid, subcmd;
9143
9144 if (!rdev->wiphy.vendor_commands)
9145 return -EOPNOTSUPP;
9146
9147 if (IS_ERR(wdev)) {
9148 err = PTR_ERR(wdev);
9149 if (err != -EINVAL)
9150 return err;
9151 wdev = NULL;
9152 } else if (wdev->wiphy != &rdev->wiphy) {
9153 return -EINVAL;
9154 }
9155
9156 if (!info->attrs[NL80211_ATTR_VENDOR_ID] ||
9157 !info->attrs[NL80211_ATTR_VENDOR_SUBCMD])
9158 return -EINVAL;
9159
9160 vid = nla_get_u32(info->attrs[NL80211_ATTR_VENDOR_ID]);
9161 subcmd = nla_get_u32(info->attrs[NL80211_ATTR_VENDOR_SUBCMD]);
9162 for (i = 0; i < rdev->wiphy.n_vendor_commands; i++) {
9163 const struct wiphy_vendor_command *vcmd;
9164 void *data = NULL;
9165 int len = 0;
9166
9167 vcmd = &rdev->wiphy.vendor_commands[i];
9168
9169 if (vcmd->info.vendor_id != vid || vcmd->info.subcmd != subcmd)
9170 continue;
9171
9172 if (vcmd->flags & (WIPHY_VENDOR_CMD_NEED_WDEV |
9173 WIPHY_VENDOR_CMD_NEED_NETDEV)) {
9174 if (!wdev)
9175 return -EINVAL;
9176 if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_NETDEV &&
9177 !wdev->netdev)
9178 return -EINVAL;
9179
9180 if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_RUNNING) {
9181 if (wdev->netdev &&
9182 !netif_running(wdev->netdev))
9183 return -ENETDOWN;
9184 if (!wdev->netdev && !wdev->p2p_started)
9185 return -ENETDOWN;
9186 }
9187 } else {
9188 wdev = NULL;
9189 }
9190
9191 if (info->attrs[NL80211_ATTR_VENDOR_DATA]) {
9192 data = nla_data(info->attrs[NL80211_ATTR_VENDOR_DATA]);
9193 len = nla_len(info->attrs[NL80211_ATTR_VENDOR_DATA]);
9194 }
9195
9196 rdev->cur_cmd_info = info;
9197 err = rdev->wiphy.vendor_commands[i].doit(&rdev->wiphy, wdev,
9198 data, len);
9199 rdev->cur_cmd_info = NULL;
9200 return err;
9201 }
9202
9203 return -EOPNOTSUPP;
9204}
9205
9206struct sk_buff *__cfg80211_alloc_reply_skb(struct wiphy *wiphy,
9207 enum nl80211_commands cmd,
9208 enum nl80211_attrs attr,
9209 int approxlen)
9210{
Zhao, Gangf26cbf42014-04-21 12:53:03 +08009211 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Bergad7e7182013-11-13 13:37:47 +01009212
9213 if (WARN_ON(!rdev->cur_cmd_info))
9214 return NULL;
9215
9216 return __cfg80211_alloc_vendor_skb(rdev, approxlen,
9217 rdev->cur_cmd_info->snd_portid,
9218 rdev->cur_cmd_info->snd_seq,
Johannes Berg567ffc32013-12-18 14:43:31 +01009219 cmd, attr, NULL, GFP_KERNEL);
Johannes Bergad7e7182013-11-13 13:37:47 +01009220}
9221EXPORT_SYMBOL(__cfg80211_alloc_reply_skb);
9222
9223int cfg80211_vendor_cmd_reply(struct sk_buff *skb)
9224{
9225 struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0];
9226 void *hdr = ((void **)skb->cb)[1];
9227 struct nlattr *data = ((void **)skb->cb)[2];
9228
9229 if (WARN_ON(!rdev->cur_cmd_info)) {
9230 kfree_skb(skb);
9231 return -EINVAL;
9232 }
9233
9234 nla_nest_end(skb, data);
9235 genlmsg_end(skb, hdr);
9236 return genlmsg_reply(skb, rdev->cur_cmd_info);
9237}
9238EXPORT_SYMBOL_GPL(cfg80211_vendor_cmd_reply);
9239
9240
Kyeyoon Parkfa9ffc72013-12-16 23:01:30 -08009241static int nl80211_set_qos_map(struct sk_buff *skb,
9242 struct genl_info *info)
9243{
9244 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9245 struct cfg80211_qos_map *qos_map = NULL;
9246 struct net_device *dev = info->user_ptr[1];
9247 u8 *pos, len, num_des, des_len, des;
9248 int ret;
9249
9250 if (!rdev->ops->set_qos_map)
9251 return -EOPNOTSUPP;
9252
9253 if (info->attrs[NL80211_ATTR_QOS_MAP]) {
9254 pos = nla_data(info->attrs[NL80211_ATTR_QOS_MAP]);
9255 len = nla_len(info->attrs[NL80211_ATTR_QOS_MAP]);
9256
9257 if (len % 2 || len < IEEE80211_QOS_MAP_LEN_MIN ||
9258 len > IEEE80211_QOS_MAP_LEN_MAX)
9259 return -EINVAL;
9260
9261 qos_map = kzalloc(sizeof(struct cfg80211_qos_map), GFP_KERNEL);
9262 if (!qos_map)
9263 return -ENOMEM;
9264
9265 num_des = (len - IEEE80211_QOS_MAP_LEN_MIN) >> 1;
9266 if (num_des) {
9267 des_len = num_des *
9268 sizeof(struct cfg80211_dscp_exception);
9269 memcpy(qos_map->dscp_exception, pos, des_len);
9270 qos_map->num_des = num_des;
9271 for (des = 0; des < num_des; des++) {
9272 if (qos_map->dscp_exception[des].up > 7) {
9273 kfree(qos_map);
9274 return -EINVAL;
9275 }
9276 }
9277 pos += des_len;
9278 }
9279 memcpy(qos_map->up, pos, IEEE80211_QOS_MAP_LEN_MIN);
9280 }
9281
9282 wdev_lock(dev->ieee80211_ptr);
9283 ret = nl80211_key_allowed(dev->ieee80211_ptr);
9284 if (!ret)
9285 ret = rdev_set_qos_map(rdev, dev, qos_map);
9286 wdev_unlock(dev->ieee80211_ptr);
9287
9288 kfree(qos_map);
9289 return ret;
9290}
9291
Johannes Berg4c476992010-10-04 21:36:35 +02009292#define NL80211_FLAG_NEED_WIPHY 0x01
9293#define NL80211_FLAG_NEED_NETDEV 0x02
9294#define NL80211_FLAG_NEED_RTNL 0x04
Johannes Berg41265712010-10-04 21:14:05 +02009295#define NL80211_FLAG_CHECK_NETDEV_UP 0x08
9296#define NL80211_FLAG_NEED_NETDEV_UP (NL80211_FLAG_NEED_NETDEV |\
9297 NL80211_FLAG_CHECK_NETDEV_UP)
Johannes Berg1bf614e2012-06-15 15:23:36 +02009298#define NL80211_FLAG_NEED_WDEV 0x10
Johannes Berg98104fde2012-06-16 00:19:54 +02009299/* If a netdev is associated, it must be UP, P2P must be started */
Johannes Berg1bf614e2012-06-15 15:23:36 +02009300#define NL80211_FLAG_NEED_WDEV_UP (NL80211_FLAG_NEED_WDEV |\
9301 NL80211_FLAG_CHECK_NETDEV_UP)
Johannes Berg4c476992010-10-04 21:36:35 +02009302
Johannes Bergf84f7712013-11-14 17:14:45 +01009303static int nl80211_pre_doit(const struct genl_ops *ops, struct sk_buff *skb,
Johannes Berg4c476992010-10-04 21:36:35 +02009304 struct genl_info *info)
9305{
9306 struct cfg80211_registered_device *rdev;
Johannes Berg89a54e42012-06-15 14:33:17 +02009307 struct wireless_dev *wdev;
Johannes Berg4c476992010-10-04 21:36:35 +02009308 struct net_device *dev;
Johannes Berg4c476992010-10-04 21:36:35 +02009309 bool rtnl = ops->internal_flags & NL80211_FLAG_NEED_RTNL;
9310
9311 if (rtnl)
9312 rtnl_lock();
9313
9314 if (ops->internal_flags & NL80211_FLAG_NEED_WIPHY) {
Johannes Berg4f7eff12012-06-15 14:14:22 +02009315 rdev = cfg80211_get_dev_from_info(genl_info_net(info), info);
Johannes Berg4c476992010-10-04 21:36:35 +02009316 if (IS_ERR(rdev)) {
9317 if (rtnl)
9318 rtnl_unlock();
9319 return PTR_ERR(rdev);
9320 }
9321 info->user_ptr[0] = rdev;
Johannes Berg1bf614e2012-06-15 15:23:36 +02009322 } else if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV ||
9323 ops->internal_flags & NL80211_FLAG_NEED_WDEV) {
Johannes Berg5fe231e2013-05-08 21:45:15 +02009324 ASSERT_RTNL();
9325
Johannes Berg89a54e42012-06-15 14:33:17 +02009326 wdev = __cfg80211_wdev_from_attrs(genl_info_net(info),
9327 info->attrs);
9328 if (IS_ERR(wdev)) {
Johannes Berg4c476992010-10-04 21:36:35 +02009329 if (rtnl)
9330 rtnl_unlock();
Johannes Berg89a54e42012-06-15 14:33:17 +02009331 return PTR_ERR(wdev);
Johannes Berg4c476992010-10-04 21:36:35 +02009332 }
Johannes Berg89a54e42012-06-15 14:33:17 +02009333
Johannes Berg89a54e42012-06-15 14:33:17 +02009334 dev = wdev->netdev;
Zhao, Gangf26cbf42014-04-21 12:53:03 +08009335 rdev = wiphy_to_rdev(wdev->wiphy);
Johannes Berg89a54e42012-06-15 14:33:17 +02009336
Johannes Berg1bf614e2012-06-15 15:23:36 +02009337 if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV) {
9338 if (!dev) {
Johannes Berg1bf614e2012-06-15 15:23:36 +02009339 if (rtnl)
9340 rtnl_unlock();
9341 return -EINVAL;
9342 }
9343
9344 info->user_ptr[1] = dev;
9345 } else {
9346 info->user_ptr[1] = wdev;
Johannes Berg41265712010-10-04 21:14:05 +02009347 }
Johannes Berg89a54e42012-06-15 14:33:17 +02009348
Johannes Berg1bf614e2012-06-15 15:23:36 +02009349 if (dev) {
9350 if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP &&
9351 !netif_running(dev)) {
Johannes Berg1bf614e2012-06-15 15:23:36 +02009352 if (rtnl)
9353 rtnl_unlock();
9354 return -ENETDOWN;
9355 }
9356
9357 dev_hold(dev);
Johannes Berg98104fde2012-06-16 00:19:54 +02009358 } else if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP) {
9359 if (!wdev->p2p_started) {
Johannes Berg98104fde2012-06-16 00:19:54 +02009360 if (rtnl)
9361 rtnl_unlock();
9362 return -ENETDOWN;
9363 }
Johannes Berg1bf614e2012-06-15 15:23:36 +02009364 }
9365
Johannes Berg4c476992010-10-04 21:36:35 +02009366 info->user_ptr[0] = rdev;
Johannes Berg4c476992010-10-04 21:36:35 +02009367 }
9368
9369 return 0;
9370}
9371
Johannes Bergf84f7712013-11-14 17:14:45 +01009372static void nl80211_post_doit(const struct genl_ops *ops, struct sk_buff *skb,
Johannes Berg4c476992010-10-04 21:36:35 +02009373 struct genl_info *info)
9374{
Johannes Berg1bf614e2012-06-15 15:23:36 +02009375 if (info->user_ptr[1]) {
9376 if (ops->internal_flags & NL80211_FLAG_NEED_WDEV) {
9377 struct wireless_dev *wdev = info->user_ptr[1];
9378
9379 if (wdev->netdev)
9380 dev_put(wdev->netdev);
9381 } else {
9382 dev_put(info->user_ptr[1]);
9383 }
9384 }
Johannes Berg4c476992010-10-04 21:36:35 +02009385 if (ops->internal_flags & NL80211_FLAG_NEED_RTNL)
9386 rtnl_unlock();
9387}
9388
Johannes Berg4534de82013-11-14 17:14:46 +01009389static const struct genl_ops nl80211_ops[] = {
Johannes Berg55682962007-09-20 13:09:35 -04009390 {
9391 .cmd = NL80211_CMD_GET_WIPHY,
9392 .doit = nl80211_get_wiphy,
9393 .dumpit = nl80211_dump_wiphy,
Johannes Berg86e8cf92013-06-19 10:57:22 +02009394 .done = nl80211_dump_wiphy_done,
Johannes Berg55682962007-09-20 13:09:35 -04009395 .policy = nl80211_policy,
9396 /* can be retrieved by unprivileged users */
Johannes Berg5fe231e2013-05-08 21:45:15 +02009397 .internal_flags = NL80211_FLAG_NEED_WIPHY |
9398 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -04009399 },
9400 {
9401 .cmd = NL80211_CMD_SET_WIPHY,
9402 .doit = nl80211_set_wiphy,
9403 .policy = nl80211_policy,
9404 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02009405 .internal_flags = NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -04009406 },
9407 {
9408 .cmd = NL80211_CMD_GET_INTERFACE,
9409 .doit = nl80211_get_interface,
9410 .dumpit = nl80211_dump_interface,
9411 .policy = nl80211_policy,
9412 /* can be retrieved by unprivileged users */
Johannes Berg5fe231e2013-05-08 21:45:15 +02009413 .internal_flags = NL80211_FLAG_NEED_WDEV |
9414 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -04009415 },
9416 {
9417 .cmd = NL80211_CMD_SET_INTERFACE,
9418 .doit = nl80211_set_interface,
9419 .policy = nl80211_policy,
9420 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02009421 .internal_flags = NL80211_FLAG_NEED_NETDEV |
9422 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -04009423 },
9424 {
9425 .cmd = NL80211_CMD_NEW_INTERFACE,
9426 .doit = nl80211_new_interface,
9427 .policy = nl80211_policy,
9428 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02009429 .internal_flags = NL80211_FLAG_NEED_WIPHY |
9430 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -04009431 },
9432 {
9433 .cmd = NL80211_CMD_DEL_INTERFACE,
9434 .doit = nl80211_del_interface,
9435 .policy = nl80211_policy,
9436 .flags = GENL_ADMIN_PERM,
Johannes Berg84efbb82012-06-16 00:00:26 +02009437 .internal_flags = NL80211_FLAG_NEED_WDEV |
Johannes Berg4c476992010-10-04 21:36:35 +02009438 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -04009439 },
Johannes Berg41ade002007-12-19 02:03:29 +01009440 {
9441 .cmd = NL80211_CMD_GET_KEY,
9442 .doit = nl80211_get_key,
9443 .policy = nl80211_policy,
9444 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02009445 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009446 NL80211_FLAG_NEED_RTNL,
Johannes Berg41ade002007-12-19 02:03:29 +01009447 },
9448 {
9449 .cmd = NL80211_CMD_SET_KEY,
9450 .doit = nl80211_set_key,
9451 .policy = nl80211_policy,
9452 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02009453 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009454 NL80211_FLAG_NEED_RTNL,
Johannes Berg41ade002007-12-19 02:03:29 +01009455 },
9456 {
9457 .cmd = NL80211_CMD_NEW_KEY,
9458 .doit = nl80211_new_key,
9459 .policy = nl80211_policy,
9460 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02009461 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009462 NL80211_FLAG_NEED_RTNL,
Johannes Berg41ade002007-12-19 02:03:29 +01009463 },
9464 {
9465 .cmd = NL80211_CMD_DEL_KEY,
9466 .doit = nl80211_del_key,
9467 .policy = nl80211_policy,
9468 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02009469 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009470 NL80211_FLAG_NEED_RTNL,
Johannes Berg41ade002007-12-19 02:03:29 +01009471 },
Johannes Berged1b6cc2007-12-19 02:03:32 +01009472 {
9473 .cmd = NL80211_CMD_SET_BEACON,
9474 .policy = nl80211_policy,
9475 .flags = GENL_ADMIN_PERM,
Johannes Berg88600202012-02-13 15:17:18 +01009476 .doit = nl80211_set_beacon,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02009477 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009478 NL80211_FLAG_NEED_RTNL,
Johannes Berged1b6cc2007-12-19 02:03:32 +01009479 },
9480 {
Johannes Berg88600202012-02-13 15:17:18 +01009481 .cmd = NL80211_CMD_START_AP,
Johannes Berged1b6cc2007-12-19 02:03:32 +01009482 .policy = nl80211_policy,
9483 .flags = GENL_ADMIN_PERM,
Johannes Berg88600202012-02-13 15:17:18 +01009484 .doit = nl80211_start_ap,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02009485 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009486 NL80211_FLAG_NEED_RTNL,
Johannes Berged1b6cc2007-12-19 02:03:32 +01009487 },
9488 {
Johannes Berg88600202012-02-13 15:17:18 +01009489 .cmd = NL80211_CMD_STOP_AP,
Johannes Berged1b6cc2007-12-19 02:03:32 +01009490 .policy = nl80211_policy,
9491 .flags = GENL_ADMIN_PERM,
Johannes Berg88600202012-02-13 15:17:18 +01009492 .doit = nl80211_stop_ap,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02009493 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009494 NL80211_FLAG_NEED_RTNL,
Johannes Berged1b6cc2007-12-19 02:03:32 +01009495 },
Johannes Berg5727ef12007-12-19 02:03:34 +01009496 {
9497 .cmd = NL80211_CMD_GET_STATION,
9498 .doit = nl80211_get_station,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01009499 .dumpit = nl80211_dump_station,
Johannes Berg5727ef12007-12-19 02:03:34 +01009500 .policy = nl80211_policy,
Johannes Berg4c476992010-10-04 21:36:35 +02009501 .internal_flags = NL80211_FLAG_NEED_NETDEV |
9502 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +01009503 },
9504 {
9505 .cmd = NL80211_CMD_SET_STATION,
9506 .doit = nl80211_set_station,
9507 .policy = nl80211_policy,
9508 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02009509 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009510 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +01009511 },
9512 {
9513 .cmd = NL80211_CMD_NEW_STATION,
9514 .doit = nl80211_new_station,
9515 .policy = nl80211_policy,
9516 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02009517 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009518 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +01009519 },
9520 {
9521 .cmd = NL80211_CMD_DEL_STATION,
9522 .doit = nl80211_del_station,
9523 .policy = nl80211_policy,
9524 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02009525 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009526 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +01009527 },
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01009528 {
9529 .cmd = NL80211_CMD_GET_MPATH,
9530 .doit = nl80211_get_mpath,
9531 .dumpit = nl80211_dump_mpath,
9532 .policy = nl80211_policy,
9533 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02009534 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009535 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01009536 },
9537 {
9538 .cmd = NL80211_CMD_SET_MPATH,
9539 .doit = nl80211_set_mpath,
9540 .policy = nl80211_policy,
9541 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02009542 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009543 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01009544 },
9545 {
9546 .cmd = NL80211_CMD_NEW_MPATH,
9547 .doit = nl80211_new_mpath,
9548 .policy = nl80211_policy,
9549 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02009550 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009551 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01009552 },
9553 {
9554 .cmd = NL80211_CMD_DEL_MPATH,
9555 .doit = nl80211_del_mpath,
9556 .policy = nl80211_policy,
9557 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02009558 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009559 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01009560 },
Jouni Malinen9f1ba902008-08-07 20:07:01 +03009561 {
9562 .cmd = NL80211_CMD_SET_BSS,
9563 .doit = nl80211_set_bss,
9564 .policy = nl80211_policy,
9565 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02009566 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009567 NL80211_FLAG_NEED_RTNL,
Jouni Malinen9f1ba902008-08-07 20:07:01 +03009568 },
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07009569 {
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08009570 .cmd = NL80211_CMD_GET_REG,
9571 .doit = nl80211_get_reg,
9572 .policy = nl80211_policy,
Johannes Berg5fe231e2013-05-08 21:45:15 +02009573 .internal_flags = NL80211_FLAG_NEED_RTNL,
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08009574 /* can be retrieved by unprivileged users */
9575 },
9576 {
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07009577 .cmd = NL80211_CMD_SET_REG,
9578 .doit = nl80211_set_reg,
9579 .policy = nl80211_policy,
9580 .flags = GENL_ADMIN_PERM,
Johannes Berg5fe231e2013-05-08 21:45:15 +02009581 .internal_flags = NL80211_FLAG_NEED_RTNL,
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07009582 },
9583 {
9584 .cmd = NL80211_CMD_REQ_SET_REG,
9585 .doit = nl80211_req_set_reg,
9586 .policy = nl80211_policy,
9587 .flags = GENL_ADMIN_PERM,
9588 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07009589 {
Javier Cardona24bdd9f2010-12-16 17:37:48 -08009590 .cmd = NL80211_CMD_GET_MESH_CONFIG,
9591 .doit = nl80211_get_mesh_config,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07009592 .policy = nl80211_policy,
9593 /* can be retrieved by unprivileged users */
Johannes Berg2b5f8b02012-04-02 10:51:55 +02009594 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009595 NL80211_FLAG_NEED_RTNL,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07009596 },
9597 {
Javier Cardona24bdd9f2010-12-16 17:37:48 -08009598 .cmd = NL80211_CMD_SET_MESH_CONFIG,
9599 .doit = nl80211_update_mesh_config,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07009600 .policy = nl80211_policy,
9601 .flags = GENL_ADMIN_PERM,
Johannes Berg29cbe682010-12-03 09:20:44 +01009602 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009603 NL80211_FLAG_NEED_RTNL,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07009604 },
Jouni Malinen9aed3cc2009-01-13 16:03:29 +02009605 {
Johannes Berg2a519312009-02-10 21:25:55 +01009606 .cmd = NL80211_CMD_TRIGGER_SCAN,
9607 .doit = nl80211_trigger_scan,
9608 .policy = nl80211_policy,
9609 .flags = GENL_ADMIN_PERM,
Johannes Bergfd014282012-06-18 19:17:03 +02009610 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009611 NL80211_FLAG_NEED_RTNL,
Johannes Berg2a519312009-02-10 21:25:55 +01009612 },
9613 {
9614 .cmd = NL80211_CMD_GET_SCAN,
9615 .policy = nl80211_policy,
9616 .dumpit = nl80211_dump_scan,
9617 },
Jouni Malinen636a5d32009-03-19 13:39:22 +02009618 {
Luciano Coelho807f8a82011-05-11 17:09:35 +03009619 .cmd = NL80211_CMD_START_SCHED_SCAN,
9620 .doit = nl80211_start_sched_scan,
9621 .policy = nl80211_policy,
9622 .flags = GENL_ADMIN_PERM,
9623 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
9624 NL80211_FLAG_NEED_RTNL,
9625 },
9626 {
9627 .cmd = NL80211_CMD_STOP_SCHED_SCAN,
9628 .doit = nl80211_stop_sched_scan,
9629 .policy = nl80211_policy,
9630 .flags = GENL_ADMIN_PERM,
9631 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
9632 NL80211_FLAG_NEED_RTNL,
9633 },
9634 {
Jouni Malinen636a5d32009-03-19 13:39:22 +02009635 .cmd = NL80211_CMD_AUTHENTICATE,
9636 .doit = nl80211_authenticate,
9637 .policy = nl80211_policy,
9638 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02009639 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009640 NL80211_FLAG_NEED_RTNL,
Jouni Malinen636a5d32009-03-19 13:39:22 +02009641 },
9642 {
9643 .cmd = NL80211_CMD_ASSOCIATE,
9644 .doit = nl80211_associate,
9645 .policy = nl80211_policy,
9646 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02009647 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009648 NL80211_FLAG_NEED_RTNL,
Jouni Malinen636a5d32009-03-19 13:39:22 +02009649 },
9650 {
9651 .cmd = NL80211_CMD_DEAUTHENTICATE,
9652 .doit = nl80211_deauthenticate,
9653 .policy = nl80211_policy,
9654 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02009655 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009656 NL80211_FLAG_NEED_RTNL,
Jouni Malinen636a5d32009-03-19 13:39:22 +02009657 },
9658 {
9659 .cmd = NL80211_CMD_DISASSOCIATE,
9660 .doit = nl80211_disassociate,
9661 .policy = nl80211_policy,
9662 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02009663 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009664 NL80211_FLAG_NEED_RTNL,
Jouni Malinen636a5d32009-03-19 13:39:22 +02009665 },
Johannes Berg04a773a2009-04-19 21:24:32 +02009666 {
9667 .cmd = NL80211_CMD_JOIN_IBSS,
9668 .doit = nl80211_join_ibss,
9669 .policy = nl80211_policy,
9670 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02009671 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009672 NL80211_FLAG_NEED_RTNL,
Johannes Berg04a773a2009-04-19 21:24:32 +02009673 },
9674 {
9675 .cmd = NL80211_CMD_LEAVE_IBSS,
9676 .doit = nl80211_leave_ibss,
9677 .policy = nl80211_policy,
9678 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02009679 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009680 NL80211_FLAG_NEED_RTNL,
Johannes Berg04a773a2009-04-19 21:24:32 +02009681 },
Johannes Bergaff89a92009-07-01 21:26:51 +02009682#ifdef CONFIG_NL80211_TESTMODE
9683 {
9684 .cmd = NL80211_CMD_TESTMODE,
9685 .doit = nl80211_testmode_do,
Wey-Yi Guy71063f02011-05-20 09:05:54 -07009686 .dumpit = nl80211_testmode_dump,
Johannes Bergaff89a92009-07-01 21:26:51 +02009687 .policy = nl80211_policy,
9688 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02009689 .internal_flags = NL80211_FLAG_NEED_WIPHY |
9690 NL80211_FLAG_NEED_RTNL,
Johannes Bergaff89a92009-07-01 21:26:51 +02009691 },
9692#endif
Samuel Ortizb23aa672009-07-01 21:26:54 +02009693 {
9694 .cmd = NL80211_CMD_CONNECT,
9695 .doit = nl80211_connect,
9696 .policy = nl80211_policy,
9697 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02009698 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009699 NL80211_FLAG_NEED_RTNL,
Samuel Ortizb23aa672009-07-01 21:26:54 +02009700 },
9701 {
9702 .cmd = NL80211_CMD_DISCONNECT,
9703 .doit = nl80211_disconnect,
9704 .policy = nl80211_policy,
9705 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02009706 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009707 NL80211_FLAG_NEED_RTNL,
Samuel Ortizb23aa672009-07-01 21:26:54 +02009708 },
Johannes Berg463d0182009-07-14 00:33:35 +02009709 {
9710 .cmd = NL80211_CMD_SET_WIPHY_NETNS,
9711 .doit = nl80211_wiphy_netns,
9712 .policy = nl80211_policy,
9713 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02009714 .internal_flags = NL80211_FLAG_NEED_WIPHY |
9715 NL80211_FLAG_NEED_RTNL,
Johannes Berg463d0182009-07-14 00:33:35 +02009716 },
Holger Schurig61fa7132009-11-11 12:25:40 +01009717 {
9718 .cmd = NL80211_CMD_GET_SURVEY,
9719 .policy = nl80211_policy,
9720 .dumpit = nl80211_dump_survey,
9721 },
Samuel Ortiz67fbb162009-11-24 23:59:15 +01009722 {
9723 .cmd = NL80211_CMD_SET_PMKSA,
9724 .doit = nl80211_setdel_pmksa,
9725 .policy = nl80211_policy,
9726 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02009727 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009728 NL80211_FLAG_NEED_RTNL,
Samuel Ortiz67fbb162009-11-24 23:59:15 +01009729 },
9730 {
9731 .cmd = NL80211_CMD_DEL_PMKSA,
9732 .doit = nl80211_setdel_pmksa,
9733 .policy = nl80211_policy,
9734 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02009735 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009736 NL80211_FLAG_NEED_RTNL,
Samuel Ortiz67fbb162009-11-24 23:59:15 +01009737 },
9738 {
9739 .cmd = NL80211_CMD_FLUSH_PMKSA,
9740 .doit = nl80211_flush_pmksa,
9741 .policy = nl80211_policy,
9742 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02009743 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009744 NL80211_FLAG_NEED_RTNL,
Samuel Ortiz67fbb162009-11-24 23:59:15 +01009745 },
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009746 {
9747 .cmd = NL80211_CMD_REMAIN_ON_CHANNEL,
9748 .doit = nl80211_remain_on_channel,
9749 .policy = nl80211_policy,
9750 .flags = GENL_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +02009751 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009752 NL80211_FLAG_NEED_RTNL,
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009753 },
9754 {
9755 .cmd = NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL,
9756 .doit = nl80211_cancel_remain_on_channel,
9757 .policy = nl80211_policy,
9758 .flags = GENL_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +02009759 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009760 NL80211_FLAG_NEED_RTNL,
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009761 },
Jouni Malinen13ae75b2009-12-29 12:59:45 +02009762 {
9763 .cmd = NL80211_CMD_SET_TX_BITRATE_MASK,
9764 .doit = nl80211_set_tx_bitrate_mask,
9765 .policy = nl80211_policy,
9766 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02009767 .internal_flags = NL80211_FLAG_NEED_NETDEV |
9768 NL80211_FLAG_NEED_RTNL,
Jouni Malinen13ae75b2009-12-29 12:59:45 +02009769 },
Jouni Malinen026331c2010-02-15 12:53:10 +02009770 {
Johannes Berg2e161f782010-08-12 15:38:38 +02009771 .cmd = NL80211_CMD_REGISTER_FRAME,
9772 .doit = nl80211_register_mgmt,
Jouni Malinen026331c2010-02-15 12:53:10 +02009773 .policy = nl80211_policy,
9774 .flags = GENL_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +02009775 .internal_flags = NL80211_FLAG_NEED_WDEV |
Johannes Berg4c476992010-10-04 21:36:35 +02009776 NL80211_FLAG_NEED_RTNL,
Jouni Malinen026331c2010-02-15 12:53:10 +02009777 },
9778 {
Johannes Berg2e161f782010-08-12 15:38:38 +02009779 .cmd = NL80211_CMD_FRAME,
9780 .doit = nl80211_tx_mgmt,
Jouni Malinen026331c2010-02-15 12:53:10 +02009781 .policy = nl80211_policy,
9782 .flags = GENL_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +02009783 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009784 NL80211_FLAG_NEED_RTNL,
Jouni Malinen026331c2010-02-15 12:53:10 +02009785 },
Kalle Valoffb9eb32010-02-17 17:58:10 +02009786 {
Johannes Bergf7ca38d2010-11-25 10:02:29 +01009787 .cmd = NL80211_CMD_FRAME_WAIT_CANCEL,
9788 .doit = nl80211_tx_mgmt_cancel_wait,
9789 .policy = nl80211_policy,
9790 .flags = GENL_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +02009791 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Bergf7ca38d2010-11-25 10:02:29 +01009792 NL80211_FLAG_NEED_RTNL,
9793 },
9794 {
Kalle Valoffb9eb32010-02-17 17:58:10 +02009795 .cmd = NL80211_CMD_SET_POWER_SAVE,
9796 .doit = nl80211_set_power_save,
9797 .policy = nl80211_policy,
9798 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02009799 .internal_flags = NL80211_FLAG_NEED_NETDEV |
9800 NL80211_FLAG_NEED_RTNL,
Kalle Valoffb9eb32010-02-17 17:58:10 +02009801 },
9802 {
9803 .cmd = NL80211_CMD_GET_POWER_SAVE,
9804 .doit = nl80211_get_power_save,
9805 .policy = nl80211_policy,
9806 /* can be retrieved by unprivileged users */
Johannes Berg4c476992010-10-04 21:36:35 +02009807 .internal_flags = NL80211_FLAG_NEED_NETDEV |
9808 NL80211_FLAG_NEED_RTNL,
Kalle Valoffb9eb32010-02-17 17:58:10 +02009809 },
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02009810 {
9811 .cmd = NL80211_CMD_SET_CQM,
9812 .doit = nl80211_set_cqm,
9813 .policy = nl80211_policy,
9814 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02009815 .internal_flags = NL80211_FLAG_NEED_NETDEV |
9816 NL80211_FLAG_NEED_RTNL,
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02009817 },
Johannes Bergf444de02010-05-05 15:25:02 +02009818 {
9819 .cmd = NL80211_CMD_SET_CHANNEL,
9820 .doit = nl80211_set_channel,
9821 .policy = nl80211_policy,
9822 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02009823 .internal_flags = NL80211_FLAG_NEED_NETDEV |
9824 NL80211_FLAG_NEED_RTNL,
Johannes Bergf444de02010-05-05 15:25:02 +02009825 },
Bill Jordane8347eb2010-10-01 13:54:28 -04009826 {
9827 .cmd = NL80211_CMD_SET_WDS_PEER,
9828 .doit = nl80211_set_wds_peer,
9829 .policy = nl80211_policy,
9830 .flags = GENL_ADMIN_PERM,
Johannes Berg43b19952010-10-07 13:10:30 +02009831 .internal_flags = NL80211_FLAG_NEED_NETDEV |
9832 NL80211_FLAG_NEED_RTNL,
Bill Jordane8347eb2010-10-01 13:54:28 -04009833 },
Johannes Berg29cbe682010-12-03 09:20:44 +01009834 {
9835 .cmd = NL80211_CMD_JOIN_MESH,
9836 .doit = nl80211_join_mesh,
9837 .policy = nl80211_policy,
9838 .flags = GENL_ADMIN_PERM,
9839 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
9840 NL80211_FLAG_NEED_RTNL,
9841 },
9842 {
9843 .cmd = NL80211_CMD_LEAVE_MESH,
9844 .doit = nl80211_leave_mesh,
9845 .policy = nl80211_policy,
9846 .flags = GENL_ADMIN_PERM,
9847 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
9848 NL80211_FLAG_NEED_RTNL,
9849 },
Johannes Bergdfb89c52012-06-27 09:23:48 +02009850#ifdef CONFIG_PM
Johannes Bergff1b6e62011-05-04 15:37:28 +02009851 {
9852 .cmd = NL80211_CMD_GET_WOWLAN,
9853 .doit = nl80211_get_wowlan,
9854 .policy = nl80211_policy,
9855 /* can be retrieved by unprivileged users */
9856 .internal_flags = NL80211_FLAG_NEED_WIPHY |
9857 NL80211_FLAG_NEED_RTNL,
9858 },
9859 {
9860 .cmd = NL80211_CMD_SET_WOWLAN,
9861 .doit = nl80211_set_wowlan,
9862 .policy = nl80211_policy,
9863 .flags = GENL_ADMIN_PERM,
9864 .internal_flags = NL80211_FLAG_NEED_WIPHY |
9865 NL80211_FLAG_NEED_RTNL,
9866 },
Johannes Bergdfb89c52012-06-27 09:23:48 +02009867#endif
Johannes Berge5497d72011-07-05 16:35:40 +02009868 {
9869 .cmd = NL80211_CMD_SET_REKEY_OFFLOAD,
9870 .doit = nl80211_set_rekey_data,
9871 .policy = nl80211_policy,
9872 .flags = GENL_ADMIN_PERM,
9873 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
9874 NL80211_FLAG_NEED_RTNL,
9875 },
Arik Nemtsov109086c2011-09-28 14:12:50 +03009876 {
9877 .cmd = NL80211_CMD_TDLS_MGMT,
9878 .doit = nl80211_tdls_mgmt,
9879 .policy = nl80211_policy,
9880 .flags = GENL_ADMIN_PERM,
9881 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
9882 NL80211_FLAG_NEED_RTNL,
9883 },
9884 {
9885 .cmd = NL80211_CMD_TDLS_OPER,
9886 .doit = nl80211_tdls_oper,
9887 .policy = nl80211_policy,
9888 .flags = GENL_ADMIN_PERM,
9889 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
9890 NL80211_FLAG_NEED_RTNL,
9891 },
Johannes Berg28946da2011-11-04 11:18:12 +01009892 {
9893 .cmd = NL80211_CMD_UNEXPECTED_FRAME,
9894 .doit = nl80211_register_unexpected_frame,
9895 .policy = nl80211_policy,
9896 .flags = GENL_ADMIN_PERM,
9897 .internal_flags = NL80211_FLAG_NEED_NETDEV |
9898 NL80211_FLAG_NEED_RTNL,
9899 },
Johannes Berg7f6cf312011-11-04 11:18:15 +01009900 {
9901 .cmd = NL80211_CMD_PROBE_CLIENT,
9902 .doit = nl80211_probe_client,
9903 .policy = nl80211_policy,
9904 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02009905 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg7f6cf312011-11-04 11:18:15 +01009906 NL80211_FLAG_NEED_RTNL,
9907 },
Johannes Berg5e760232011-11-04 11:18:17 +01009908 {
9909 .cmd = NL80211_CMD_REGISTER_BEACONS,
9910 .doit = nl80211_register_beacons,
9911 .policy = nl80211_policy,
9912 .flags = GENL_ADMIN_PERM,
9913 .internal_flags = NL80211_FLAG_NEED_WIPHY |
9914 NL80211_FLAG_NEED_RTNL,
9915 },
Simon Wunderlich1d9d9212011-11-18 14:20:43 +01009916 {
9917 .cmd = NL80211_CMD_SET_NOACK_MAP,
9918 .doit = nl80211_set_noack_map,
9919 .policy = nl80211_policy,
9920 .flags = GENL_ADMIN_PERM,
9921 .internal_flags = NL80211_FLAG_NEED_NETDEV |
9922 NL80211_FLAG_NEED_RTNL,
9923 },
Johannes Berg98104fde2012-06-16 00:19:54 +02009924 {
9925 .cmd = NL80211_CMD_START_P2P_DEVICE,
9926 .doit = nl80211_start_p2p_device,
9927 .policy = nl80211_policy,
9928 .flags = GENL_ADMIN_PERM,
9929 .internal_flags = NL80211_FLAG_NEED_WDEV |
9930 NL80211_FLAG_NEED_RTNL,
9931 },
9932 {
9933 .cmd = NL80211_CMD_STOP_P2P_DEVICE,
9934 .doit = nl80211_stop_p2p_device,
9935 .policy = nl80211_policy,
9936 .flags = GENL_ADMIN_PERM,
9937 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
9938 NL80211_FLAG_NEED_RTNL,
9939 },
Antonio Quartullif4e583c2012-11-02 13:27:48 +01009940 {
9941 .cmd = NL80211_CMD_SET_MCAST_RATE,
9942 .doit = nl80211_set_mcast_rate,
9943 .policy = nl80211_policy,
9944 .flags = GENL_ADMIN_PERM,
9945 .internal_flags = NL80211_FLAG_NEED_NETDEV |
9946 NL80211_FLAG_NEED_RTNL,
9947 },
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +05309948 {
9949 .cmd = NL80211_CMD_SET_MAC_ACL,
9950 .doit = nl80211_set_mac_acl,
9951 .policy = nl80211_policy,
9952 .flags = GENL_ADMIN_PERM,
9953 .internal_flags = NL80211_FLAG_NEED_NETDEV |
9954 NL80211_FLAG_NEED_RTNL,
9955 },
Simon Wunderlich04f39042013-02-08 18:16:19 +01009956 {
9957 .cmd = NL80211_CMD_RADAR_DETECT,
9958 .doit = nl80211_start_radar_detection,
9959 .policy = nl80211_policy,
9960 .flags = GENL_ADMIN_PERM,
9961 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
9962 NL80211_FLAG_NEED_RTNL,
9963 },
Johannes Berg3713b4e2013-02-14 16:19:38 +01009964 {
9965 .cmd = NL80211_CMD_GET_PROTOCOL_FEATURES,
9966 .doit = nl80211_get_protocol_features,
9967 .policy = nl80211_policy,
9968 },
Jouni Malinen355199e2013-02-27 17:14:27 +02009969 {
9970 .cmd = NL80211_CMD_UPDATE_FT_IES,
9971 .doit = nl80211_update_ft_ies,
9972 .policy = nl80211_policy,
9973 .flags = GENL_ADMIN_PERM,
9974 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
9975 NL80211_FLAG_NEED_RTNL,
9976 },
Arend van Spriel5de17982013-04-18 15:49:00 +02009977 {
9978 .cmd = NL80211_CMD_CRIT_PROTOCOL_START,
9979 .doit = nl80211_crit_protocol_start,
9980 .policy = nl80211_policy,
9981 .flags = GENL_ADMIN_PERM,
9982 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
9983 NL80211_FLAG_NEED_RTNL,
9984 },
9985 {
9986 .cmd = NL80211_CMD_CRIT_PROTOCOL_STOP,
9987 .doit = nl80211_crit_protocol_stop,
9988 .policy = nl80211_policy,
9989 .flags = GENL_ADMIN_PERM,
9990 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
9991 NL80211_FLAG_NEED_RTNL,
Amitkumar Karwarbe29b99a2013-06-28 11:51:26 -07009992 },
9993 {
9994 .cmd = NL80211_CMD_GET_COALESCE,
9995 .doit = nl80211_get_coalesce,
9996 .policy = nl80211_policy,
9997 .internal_flags = NL80211_FLAG_NEED_WIPHY |
9998 NL80211_FLAG_NEED_RTNL,
9999 },
10000 {
10001 .cmd = NL80211_CMD_SET_COALESCE,
10002 .doit = nl80211_set_coalesce,
10003 .policy = nl80211_policy,
10004 .flags = GENL_ADMIN_PERM,
10005 .internal_flags = NL80211_FLAG_NEED_WIPHY |
10006 NL80211_FLAG_NEED_RTNL,
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +020010007 },
10008 {
10009 .cmd = NL80211_CMD_CHANNEL_SWITCH,
10010 .doit = nl80211_channel_switch,
10011 .policy = nl80211_policy,
10012 .flags = GENL_ADMIN_PERM,
10013 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
10014 NL80211_FLAG_NEED_RTNL,
10015 },
Johannes Bergad7e7182013-11-13 13:37:47 +010010016 {
10017 .cmd = NL80211_CMD_VENDOR,
10018 .doit = nl80211_vendor_cmd,
10019 .policy = nl80211_policy,
10020 .flags = GENL_ADMIN_PERM,
10021 .internal_flags = NL80211_FLAG_NEED_WIPHY |
10022 NL80211_FLAG_NEED_RTNL,
10023 },
Kyeyoon Parkfa9ffc72013-12-16 23:01:30 -080010024 {
10025 .cmd = NL80211_CMD_SET_QOS_MAP,
10026 .doit = nl80211_set_qos_map,
10027 .policy = nl80211_policy,
10028 .flags = GENL_ADMIN_PERM,
10029 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
10030 NL80211_FLAG_NEED_RTNL,
10031 },
Johannes Berg55682962007-09-20 13:09:35 -040010032};
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010033
Johannes Berg55682962007-09-20 13:09:35 -040010034/* notification functions */
10035
10036void nl80211_notify_dev_rename(struct cfg80211_registered_device *rdev)
10037{
10038 struct sk_buff *msg;
Johannes Berg86e8cf92013-06-19 10:57:22 +020010039 struct nl80211_dump_wiphy_state state = {};
Johannes Berg55682962007-09-20 13:09:35 -040010040
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -070010041 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -040010042 if (!msg)
10043 return;
10044
Johannes Berg86e8cf92013-06-19 10:57:22 +020010045 if (nl80211_send_wiphy(rdev, msg, 0, 0, 0, &state) < 0) {
Johannes Berg55682962007-09-20 13:09:35 -040010046 nlmsg_free(msg);
10047 return;
10048 }
10049
Johannes Berg68eb5502013-11-19 15:19:38 +010010050 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010010051 NL80211_MCGRP_CONFIG, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -040010052}
10053
Johannes Berg362a4152009-05-24 16:43:15 +020010054static int nl80211_add_scan_req(struct sk_buff *msg,
10055 struct cfg80211_registered_device *rdev)
10056{
10057 struct cfg80211_scan_request *req = rdev->scan_req;
10058 struct nlattr *nest;
10059 int i;
10060
10061 if (WARN_ON(!req))
10062 return 0;
10063
10064 nest = nla_nest_start(msg, NL80211_ATTR_SCAN_SSIDS);
10065 if (!nest)
10066 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -040010067 for (i = 0; i < req->n_ssids; i++) {
10068 if (nla_put(msg, i, req->ssids[i].ssid_len, req->ssids[i].ssid))
10069 goto nla_put_failure;
10070 }
Johannes Berg362a4152009-05-24 16:43:15 +020010071 nla_nest_end(msg, nest);
10072
10073 nest = nla_nest_start(msg, NL80211_ATTR_SCAN_FREQUENCIES);
10074 if (!nest)
10075 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -040010076 for (i = 0; i < req->n_channels; i++) {
10077 if (nla_put_u32(msg, i, req->channels[i]->center_freq))
10078 goto nla_put_failure;
10079 }
Johannes Berg362a4152009-05-24 16:43:15 +020010080 nla_nest_end(msg, nest);
10081
David S. Miller9360ffd2012-03-29 04:41:26 -040010082 if (req->ie &&
10083 nla_put(msg, NL80211_ATTR_IE, req->ie_len, req->ie))
10084 goto nla_put_failure;
Johannes Berg362a4152009-05-24 16:43:15 +020010085
Johannes Bergae917c92013-10-25 11:05:22 +020010086 if (req->flags &&
10087 nla_put_u32(msg, NL80211_ATTR_SCAN_FLAGS, req->flags))
10088 goto nla_put_failure;
Sam Lefflered4737712012-10-11 21:03:31 -070010089
Johannes Berg362a4152009-05-24 16:43:15 +020010090 return 0;
10091 nla_put_failure:
10092 return -ENOBUFS;
10093}
10094
Johannes Berga538e2d2009-06-16 19:56:42 +020010095static int nl80211_send_scan_msg(struct sk_buff *msg,
10096 struct cfg80211_registered_device *rdev,
Johannes Bergfd014282012-06-18 19:17:03 +020010097 struct wireless_dev *wdev,
Eric W. Biederman15e47302012-09-07 20:12:54 +000010098 u32 portid, u32 seq, int flags,
Johannes Berga538e2d2009-06-16 19:56:42 +020010099 u32 cmd)
Johannes Berg2a519312009-02-10 21:25:55 +010010100{
10101 void *hdr;
10102
Eric W. Biederman15e47302012-09-07 20:12:54 +000010103 hdr = nl80211hdr_put(msg, portid, seq, flags, cmd);
Johannes Berg2a519312009-02-10 21:25:55 +010010104 if (!hdr)
10105 return -1;
10106
David S. Miller9360ffd2012-03-29 04:41:26 -040010107 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Bergfd014282012-06-18 19:17:03 +020010108 (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
10109 wdev->netdev->ifindex)) ||
10110 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)))
David S. Miller9360ffd2012-03-29 04:41:26 -040010111 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +010010112
Johannes Berg362a4152009-05-24 16:43:15 +020010113 /* ignore errors and send incomplete event anyway */
10114 nl80211_add_scan_req(msg, rdev);
Johannes Berg2a519312009-02-10 21:25:55 +010010115
10116 return genlmsg_end(msg, hdr);
10117
10118 nla_put_failure:
10119 genlmsg_cancel(msg, hdr);
10120 return -EMSGSIZE;
10121}
10122
Luciano Coelho807f8a82011-05-11 17:09:35 +030010123static int
10124nl80211_send_sched_scan_msg(struct sk_buff *msg,
10125 struct cfg80211_registered_device *rdev,
10126 struct net_device *netdev,
Eric W. Biederman15e47302012-09-07 20:12:54 +000010127 u32 portid, u32 seq, int flags, u32 cmd)
Luciano Coelho807f8a82011-05-11 17:09:35 +030010128{
10129 void *hdr;
10130
Eric W. Biederman15e47302012-09-07 20:12:54 +000010131 hdr = nl80211hdr_put(msg, portid, seq, flags, cmd);
Luciano Coelho807f8a82011-05-11 17:09:35 +030010132 if (!hdr)
10133 return -1;
10134
David S. Miller9360ffd2012-03-29 04:41:26 -040010135 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
10136 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex))
10137 goto nla_put_failure;
Luciano Coelho807f8a82011-05-11 17:09:35 +030010138
10139 return genlmsg_end(msg, hdr);
10140
10141 nla_put_failure:
10142 genlmsg_cancel(msg, hdr);
10143 return -EMSGSIZE;
10144}
10145
Johannes Berga538e2d2009-06-16 19:56:42 +020010146void nl80211_send_scan_start(struct cfg80211_registered_device *rdev,
Johannes Bergfd014282012-06-18 19:17:03 +020010147 struct wireless_dev *wdev)
Johannes Berga538e2d2009-06-16 19:56:42 +020010148{
10149 struct sk_buff *msg;
10150
Thomas Graf58050fc2012-06-28 03:57:45 +000010151 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berga538e2d2009-06-16 19:56:42 +020010152 if (!msg)
10153 return;
10154
Johannes Bergfd014282012-06-18 19:17:03 +020010155 if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0,
Johannes Berga538e2d2009-06-16 19:56:42 +020010156 NL80211_CMD_TRIGGER_SCAN) < 0) {
10157 nlmsg_free(msg);
10158 return;
10159 }
10160
Johannes Berg68eb5502013-11-19 15:19:38 +010010161 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010010162 NL80211_MCGRP_SCAN, GFP_KERNEL);
Johannes Berga538e2d2009-06-16 19:56:42 +020010163}
10164
Johannes Bergf9d15d12014-01-22 11:14:19 +020010165struct sk_buff *nl80211_build_scan_msg(struct cfg80211_registered_device *rdev,
10166 struct wireless_dev *wdev, bool aborted)
Johannes Berg2a519312009-02-10 21:25:55 +010010167{
10168 struct sk_buff *msg;
10169
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -070010170 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg2a519312009-02-10 21:25:55 +010010171 if (!msg)
Johannes Bergf9d15d12014-01-22 11:14:19 +020010172 return NULL;
Johannes Berg2a519312009-02-10 21:25:55 +010010173
Johannes Bergfd014282012-06-18 19:17:03 +020010174 if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0,
Johannes Bergf9d15d12014-01-22 11:14:19 +020010175 aborted ? NL80211_CMD_SCAN_ABORTED :
10176 NL80211_CMD_NEW_SCAN_RESULTS) < 0) {
Johannes Berg2a519312009-02-10 21:25:55 +010010177 nlmsg_free(msg);
Johannes Bergf9d15d12014-01-22 11:14:19 +020010178 return NULL;
Johannes Berg2a519312009-02-10 21:25:55 +010010179 }
10180
Johannes Bergf9d15d12014-01-22 11:14:19 +020010181 return msg;
Johannes Berg2a519312009-02-10 21:25:55 +010010182}
10183
Johannes Bergf9d15d12014-01-22 11:14:19 +020010184void nl80211_send_scan_result(struct cfg80211_registered_device *rdev,
10185 struct sk_buff *msg)
Johannes Berg2a519312009-02-10 21:25:55 +010010186{
Johannes Berg2a519312009-02-10 21:25:55 +010010187 if (!msg)
10188 return;
10189
Johannes Berg68eb5502013-11-19 15:19:38 +010010190 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010010191 NL80211_MCGRP_SCAN, GFP_KERNEL);
Johannes Berg2a519312009-02-10 21:25:55 +010010192}
10193
Luciano Coelho807f8a82011-05-11 17:09:35 +030010194void nl80211_send_sched_scan_results(struct cfg80211_registered_device *rdev,
10195 struct net_device *netdev)
10196{
10197 struct sk_buff *msg;
10198
10199 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
10200 if (!msg)
10201 return;
10202
10203 if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0,
10204 NL80211_CMD_SCHED_SCAN_RESULTS) < 0) {
10205 nlmsg_free(msg);
10206 return;
10207 }
10208
Johannes Berg68eb5502013-11-19 15:19:38 +010010209 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010010210 NL80211_MCGRP_SCAN, GFP_KERNEL);
Luciano Coelho807f8a82011-05-11 17:09:35 +030010211}
10212
10213void nl80211_send_sched_scan(struct cfg80211_registered_device *rdev,
10214 struct net_device *netdev, u32 cmd)
10215{
10216 struct sk_buff *msg;
10217
Thomas Graf58050fc2012-06-28 03:57:45 +000010218 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Luciano Coelho807f8a82011-05-11 17:09:35 +030010219 if (!msg)
10220 return;
10221
10222 if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0, cmd) < 0) {
10223 nlmsg_free(msg);
10224 return;
10225 }
10226
Johannes Berg68eb5502013-11-19 15:19:38 +010010227 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010010228 NL80211_MCGRP_SCAN, GFP_KERNEL);
Luciano Coelho807f8a82011-05-11 17:09:35 +030010229}
10230
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040010231/*
10232 * This can happen on global regulatory changes or device specific settings
10233 * based on custom world regulatory domains.
10234 */
10235void nl80211_send_reg_change_event(struct regulatory_request *request)
10236{
10237 struct sk_buff *msg;
10238 void *hdr;
10239
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -070010240 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040010241 if (!msg)
10242 return;
10243
10244 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_CHANGE);
10245 if (!hdr) {
10246 nlmsg_free(msg);
10247 return;
10248 }
10249
10250 /* Userspace can always count this one always being set */
David S. Miller9360ffd2012-03-29 04:41:26 -040010251 if (nla_put_u8(msg, NL80211_ATTR_REG_INITIATOR, request->initiator))
10252 goto nla_put_failure;
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040010253
David S. Miller9360ffd2012-03-29 04:41:26 -040010254 if (request->alpha2[0] == '0' && request->alpha2[1] == '0') {
10255 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
10256 NL80211_REGDOM_TYPE_WORLD))
10257 goto nla_put_failure;
10258 } else if (request->alpha2[0] == '9' && request->alpha2[1] == '9') {
10259 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
10260 NL80211_REGDOM_TYPE_CUSTOM_WORLD))
10261 goto nla_put_failure;
10262 } else if ((request->alpha2[0] == '9' && request->alpha2[1] == '8') ||
10263 request->intersect) {
10264 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
10265 NL80211_REGDOM_TYPE_INTERSECTION))
10266 goto nla_put_failure;
10267 } else {
10268 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
10269 NL80211_REGDOM_TYPE_COUNTRY) ||
10270 nla_put_string(msg, NL80211_ATTR_REG_ALPHA2,
10271 request->alpha2))
10272 goto nla_put_failure;
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040010273 }
10274
Johannes Bergf4173762012-12-03 18:23:37 +010010275 if (request->wiphy_idx != WIPHY_IDX_INVALID &&
David S. Miller9360ffd2012-03-29 04:41:26 -040010276 nla_put_u32(msg, NL80211_ATTR_WIPHY, request->wiphy_idx))
10277 goto nla_put_failure;
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040010278
Johannes Berg3b7b72e2011-10-22 19:05:51 +020010279 genlmsg_end(msg, hdr);
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040010280
Johannes Bergbc43b282009-07-25 10:54:13 +020010281 rcu_read_lock();
Johannes Berg68eb5502013-11-19 15:19:38 +010010282 genlmsg_multicast_allns(&nl80211_fam, msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010010283 NL80211_MCGRP_REGULATORY, GFP_ATOMIC);
Johannes Bergbc43b282009-07-25 10:54:13 +020010284 rcu_read_unlock();
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040010285
10286 return;
10287
10288nla_put_failure:
10289 genlmsg_cancel(msg, hdr);
10290 nlmsg_free(msg);
10291}
10292
Jouni Malinen6039f6d2009-03-19 13:39:21 +020010293static void nl80211_send_mlme_event(struct cfg80211_registered_device *rdev,
10294 struct net_device *netdev,
10295 const u8 *buf, size_t len,
Johannes Berge6d6e342009-07-01 21:26:47 +020010296 enum nl80211_commands cmd, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +020010297{
10298 struct sk_buff *msg;
10299 void *hdr;
10300
Johannes Berge6d6e342009-07-01 21:26:47 +020010301 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020010302 if (!msg)
10303 return;
10304
10305 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
10306 if (!hdr) {
10307 nlmsg_free(msg);
10308 return;
10309 }
10310
David S. Miller9360ffd2012-03-29 04:41:26 -040010311 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
10312 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
10313 nla_put(msg, NL80211_ATTR_FRAME, len, buf))
10314 goto nla_put_failure;
Jouni Malinen6039f6d2009-03-19 13:39:21 +020010315
Johannes Berg3b7b72e2011-10-22 19:05:51 +020010316 genlmsg_end(msg, hdr);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020010317
Johannes Berg68eb5502013-11-19 15:19:38 +010010318 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010010319 NL80211_MCGRP_MLME, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020010320 return;
10321
10322 nla_put_failure:
10323 genlmsg_cancel(msg, hdr);
10324 nlmsg_free(msg);
10325}
10326
10327void nl80211_send_rx_auth(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +020010328 struct net_device *netdev, const u8 *buf,
10329 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +020010330{
10331 nl80211_send_mlme_event(rdev, netdev, buf, len,
Johannes Berge6d6e342009-07-01 21:26:47 +020010332 NL80211_CMD_AUTHENTICATE, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020010333}
10334
10335void nl80211_send_rx_assoc(struct cfg80211_registered_device *rdev,
10336 struct net_device *netdev, const u8 *buf,
Johannes Berge6d6e342009-07-01 21:26:47 +020010337 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +020010338{
Johannes Berge6d6e342009-07-01 21:26:47 +020010339 nl80211_send_mlme_event(rdev, netdev, buf, len,
10340 NL80211_CMD_ASSOCIATE, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020010341}
10342
Jouni Malinen53b46b82009-03-27 20:53:56 +020010343void nl80211_send_deauth(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +020010344 struct net_device *netdev, const u8 *buf,
10345 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +020010346{
10347 nl80211_send_mlme_event(rdev, netdev, buf, len,
Johannes Berge6d6e342009-07-01 21:26:47 +020010348 NL80211_CMD_DEAUTHENTICATE, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020010349}
10350
Jouni Malinen53b46b82009-03-27 20:53:56 +020010351void nl80211_send_disassoc(struct cfg80211_registered_device *rdev,
10352 struct net_device *netdev, const u8 *buf,
Johannes Berge6d6e342009-07-01 21:26:47 +020010353 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +020010354{
10355 nl80211_send_mlme_event(rdev, netdev, buf, len,
Johannes Berge6d6e342009-07-01 21:26:47 +020010356 NL80211_CMD_DISASSOCIATE, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020010357}
10358
Johannes Berg6ff57cf2013-05-16 00:55:00 +020010359void cfg80211_rx_unprot_mlme_mgmt(struct net_device *dev, const u8 *buf,
10360 size_t len)
Jouni Malinencf4e5942010-12-16 00:52:40 +020010361{
Johannes Berg947add32013-02-22 22:05:20 +010010362 struct wireless_dev *wdev = dev->ieee80211_ptr;
10363 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080010364 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg6ff57cf2013-05-16 00:55:00 +020010365 const struct ieee80211_mgmt *mgmt = (void *)buf;
10366 u32 cmd;
Jouni Malinencf4e5942010-12-16 00:52:40 +020010367
Johannes Berg6ff57cf2013-05-16 00:55:00 +020010368 if (WARN_ON(len < 2))
10369 return;
10370
10371 if (ieee80211_is_deauth(mgmt->frame_control))
10372 cmd = NL80211_CMD_UNPROT_DEAUTHENTICATE;
10373 else
10374 cmd = NL80211_CMD_UNPROT_DISASSOCIATE;
10375
10376 trace_cfg80211_rx_unprot_mlme_mgmt(dev, buf, len);
10377 nl80211_send_mlme_event(rdev, dev, buf, len, cmd, GFP_ATOMIC);
Jouni Malinencf4e5942010-12-16 00:52:40 +020010378}
Johannes Berg6ff57cf2013-05-16 00:55:00 +020010379EXPORT_SYMBOL(cfg80211_rx_unprot_mlme_mgmt);
Jouni Malinencf4e5942010-12-16 00:52:40 +020010380
Luis R. Rodriguez1b06bb42009-05-02 00:34:48 -040010381static void nl80211_send_mlme_timeout(struct cfg80211_registered_device *rdev,
10382 struct net_device *netdev, int cmd,
Johannes Berge6d6e342009-07-01 21:26:47 +020010383 const u8 *addr, gfp_t gfp)
Jouni Malinen1965c852009-04-22 21:38:25 +030010384{
10385 struct sk_buff *msg;
10386 void *hdr;
10387
Johannes Berge6d6e342009-07-01 21:26:47 +020010388 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +030010389 if (!msg)
10390 return;
10391
10392 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
10393 if (!hdr) {
10394 nlmsg_free(msg);
10395 return;
10396 }
10397
David S. Miller9360ffd2012-03-29 04:41:26 -040010398 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
10399 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
10400 nla_put_flag(msg, NL80211_ATTR_TIMED_OUT) ||
10401 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr))
10402 goto nla_put_failure;
Jouni Malinen1965c852009-04-22 21:38:25 +030010403
Johannes Berg3b7b72e2011-10-22 19:05:51 +020010404 genlmsg_end(msg, hdr);
Jouni Malinen1965c852009-04-22 21:38:25 +030010405
Johannes Berg68eb5502013-11-19 15:19:38 +010010406 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010010407 NL80211_MCGRP_MLME, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +030010408 return;
10409
10410 nla_put_failure:
10411 genlmsg_cancel(msg, hdr);
10412 nlmsg_free(msg);
10413}
10414
10415void nl80211_send_auth_timeout(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +020010416 struct net_device *netdev, const u8 *addr,
10417 gfp_t gfp)
Jouni Malinen1965c852009-04-22 21:38:25 +030010418{
10419 nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_AUTHENTICATE,
Johannes Berge6d6e342009-07-01 21:26:47 +020010420 addr, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +030010421}
10422
10423void nl80211_send_assoc_timeout(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +020010424 struct net_device *netdev, const u8 *addr,
10425 gfp_t gfp)
Jouni Malinen1965c852009-04-22 21:38:25 +030010426{
Johannes Berge6d6e342009-07-01 21:26:47 +020010427 nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_ASSOCIATE,
10428 addr, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +030010429}
10430
Samuel Ortizb23aa672009-07-01 21:26:54 +020010431void nl80211_send_connect_result(struct cfg80211_registered_device *rdev,
10432 struct net_device *netdev, const u8 *bssid,
10433 const u8 *req_ie, size_t req_ie_len,
10434 const u8 *resp_ie, size_t resp_ie_len,
10435 u16 status, gfp_t gfp)
10436{
10437 struct sk_buff *msg;
10438 void *hdr;
10439
Thomas Graf58050fc2012-06-28 03:57:45 +000010440 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +020010441 if (!msg)
10442 return;
10443
10444 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONNECT);
10445 if (!hdr) {
10446 nlmsg_free(msg);
10447 return;
10448 }
10449
David S. Miller9360ffd2012-03-29 04:41:26 -040010450 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
10451 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
10452 (bssid && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) ||
10453 nla_put_u16(msg, NL80211_ATTR_STATUS_CODE, status) ||
10454 (req_ie &&
10455 nla_put(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie)) ||
10456 (resp_ie &&
10457 nla_put(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie)))
10458 goto nla_put_failure;
Samuel Ortizb23aa672009-07-01 21:26:54 +020010459
Johannes Berg3b7b72e2011-10-22 19:05:51 +020010460 genlmsg_end(msg, hdr);
Samuel Ortizb23aa672009-07-01 21:26:54 +020010461
Johannes Berg68eb5502013-11-19 15:19:38 +010010462 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010010463 NL80211_MCGRP_MLME, gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +020010464 return;
10465
10466 nla_put_failure:
10467 genlmsg_cancel(msg, hdr);
10468 nlmsg_free(msg);
10469
10470}
10471
10472void nl80211_send_roamed(struct cfg80211_registered_device *rdev,
10473 struct net_device *netdev, const u8 *bssid,
10474 const u8 *req_ie, size_t req_ie_len,
10475 const u8 *resp_ie, size_t resp_ie_len, gfp_t gfp)
10476{
10477 struct sk_buff *msg;
10478 void *hdr;
10479
Thomas Graf58050fc2012-06-28 03:57:45 +000010480 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +020010481 if (!msg)
10482 return;
10483
10484 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_ROAM);
10485 if (!hdr) {
10486 nlmsg_free(msg);
10487 return;
10488 }
10489
David S. Miller9360ffd2012-03-29 04:41:26 -040010490 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
10491 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
10492 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid) ||
10493 (req_ie &&
10494 nla_put(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie)) ||
10495 (resp_ie &&
10496 nla_put(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie)))
10497 goto nla_put_failure;
Samuel Ortizb23aa672009-07-01 21:26:54 +020010498
Johannes Berg3b7b72e2011-10-22 19:05:51 +020010499 genlmsg_end(msg, hdr);
Samuel Ortizb23aa672009-07-01 21:26:54 +020010500
Johannes Berg68eb5502013-11-19 15:19:38 +010010501 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010010502 NL80211_MCGRP_MLME, gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +020010503 return;
10504
10505 nla_put_failure:
10506 genlmsg_cancel(msg, hdr);
10507 nlmsg_free(msg);
10508
10509}
10510
10511void nl80211_send_disconnected(struct cfg80211_registered_device *rdev,
10512 struct net_device *netdev, u16 reason,
Johannes Berg667503d2009-07-07 03:56:11 +020010513 const u8 *ie, size_t ie_len, bool from_ap)
Samuel Ortizb23aa672009-07-01 21:26:54 +020010514{
10515 struct sk_buff *msg;
10516 void *hdr;
10517
Thomas Graf58050fc2012-06-28 03:57:45 +000010518 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Samuel Ortizb23aa672009-07-01 21:26:54 +020010519 if (!msg)
10520 return;
10521
10522 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DISCONNECT);
10523 if (!hdr) {
10524 nlmsg_free(msg);
10525 return;
10526 }
10527
David S. Miller9360ffd2012-03-29 04:41:26 -040010528 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
10529 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
10530 (from_ap && reason &&
10531 nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason)) ||
10532 (from_ap &&
10533 nla_put_flag(msg, NL80211_ATTR_DISCONNECTED_BY_AP)) ||
10534 (ie && nla_put(msg, NL80211_ATTR_IE, ie_len, ie)))
10535 goto nla_put_failure;
Samuel Ortizb23aa672009-07-01 21:26:54 +020010536
Johannes Berg3b7b72e2011-10-22 19:05:51 +020010537 genlmsg_end(msg, hdr);
Samuel Ortizb23aa672009-07-01 21:26:54 +020010538
Johannes Berg68eb5502013-11-19 15:19:38 +010010539 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010010540 NL80211_MCGRP_MLME, GFP_KERNEL);
Samuel Ortizb23aa672009-07-01 21:26:54 +020010541 return;
10542
10543 nla_put_failure:
10544 genlmsg_cancel(msg, hdr);
10545 nlmsg_free(msg);
10546
10547}
10548
Johannes Berg04a773a2009-04-19 21:24:32 +020010549void nl80211_send_ibss_bssid(struct cfg80211_registered_device *rdev,
10550 struct net_device *netdev, const u8 *bssid,
10551 gfp_t gfp)
10552{
10553 struct sk_buff *msg;
10554 void *hdr;
10555
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -070010556 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Johannes Berg04a773a2009-04-19 21:24:32 +020010557 if (!msg)
10558 return;
10559
10560 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_JOIN_IBSS);
10561 if (!hdr) {
10562 nlmsg_free(msg);
10563 return;
10564 }
10565
David S. Miller9360ffd2012-03-29 04:41:26 -040010566 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
10567 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
10568 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid))
10569 goto nla_put_failure;
Johannes Berg04a773a2009-04-19 21:24:32 +020010570
Johannes Berg3b7b72e2011-10-22 19:05:51 +020010571 genlmsg_end(msg, hdr);
Johannes Berg04a773a2009-04-19 21:24:32 +020010572
Johannes Berg68eb5502013-11-19 15:19:38 +010010573 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010010574 NL80211_MCGRP_MLME, gfp);
Johannes Berg04a773a2009-04-19 21:24:32 +020010575 return;
10576
10577 nla_put_failure:
10578 genlmsg_cancel(msg, hdr);
10579 nlmsg_free(msg);
10580}
10581
Johannes Berg947add32013-02-22 22:05:20 +010010582void cfg80211_notify_new_peer_candidate(struct net_device *dev, const u8 *addr,
10583 const u8* ie, u8 ie_len, gfp_t gfp)
Javier Cardonac93b5e72011-04-07 15:08:34 -070010584{
Johannes Berg947add32013-02-22 22:05:20 +010010585 struct wireless_dev *wdev = dev->ieee80211_ptr;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080010586 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Javier Cardonac93b5e72011-04-07 15:08:34 -070010587 struct sk_buff *msg;
10588 void *hdr;
10589
Johannes Berg947add32013-02-22 22:05:20 +010010590 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_MESH_POINT))
10591 return;
10592
10593 trace_cfg80211_notify_new_peer_candidate(dev, addr);
10594
Javier Cardonac93b5e72011-04-07 15:08:34 -070010595 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
10596 if (!msg)
10597 return;
10598
10599 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NEW_PEER_CANDIDATE);
10600 if (!hdr) {
10601 nlmsg_free(msg);
10602 return;
10603 }
10604
David S. Miller9360ffd2012-03-29 04:41:26 -040010605 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg947add32013-02-22 22:05:20 +010010606 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
10607 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040010608 (ie_len && ie &&
10609 nla_put(msg, NL80211_ATTR_IE, ie_len , ie)))
10610 goto nla_put_failure;
Javier Cardonac93b5e72011-04-07 15:08:34 -070010611
Johannes Berg3b7b72e2011-10-22 19:05:51 +020010612 genlmsg_end(msg, hdr);
Javier Cardonac93b5e72011-04-07 15:08:34 -070010613
Johannes Berg68eb5502013-11-19 15:19:38 +010010614 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010010615 NL80211_MCGRP_MLME, gfp);
Javier Cardonac93b5e72011-04-07 15:08:34 -070010616 return;
10617
10618 nla_put_failure:
10619 genlmsg_cancel(msg, hdr);
10620 nlmsg_free(msg);
10621}
Johannes Berg947add32013-02-22 22:05:20 +010010622EXPORT_SYMBOL(cfg80211_notify_new_peer_candidate);
Javier Cardonac93b5e72011-04-07 15:08:34 -070010623
Jouni Malinena3b8b052009-03-27 21:59:49 +020010624void nl80211_michael_mic_failure(struct cfg80211_registered_device *rdev,
10625 struct net_device *netdev, const u8 *addr,
10626 enum nl80211_key_type key_type, int key_id,
Johannes Berge6d6e342009-07-01 21:26:47 +020010627 const u8 *tsc, gfp_t gfp)
Jouni Malinena3b8b052009-03-27 21:59:49 +020010628{
10629 struct sk_buff *msg;
10630 void *hdr;
10631
Johannes Berge6d6e342009-07-01 21:26:47 +020010632 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinena3b8b052009-03-27 21:59:49 +020010633 if (!msg)
10634 return;
10635
10636 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_MICHAEL_MIC_FAILURE);
10637 if (!hdr) {
10638 nlmsg_free(msg);
10639 return;
10640 }
10641
David S. Miller9360ffd2012-03-29 04:41:26 -040010642 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
10643 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
10644 (addr && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) ||
10645 nla_put_u32(msg, NL80211_ATTR_KEY_TYPE, key_type) ||
10646 (key_id != -1 &&
10647 nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_id)) ||
10648 (tsc && nla_put(msg, NL80211_ATTR_KEY_SEQ, 6, tsc)))
10649 goto nla_put_failure;
Jouni Malinena3b8b052009-03-27 21:59:49 +020010650
Johannes Berg3b7b72e2011-10-22 19:05:51 +020010651 genlmsg_end(msg, hdr);
Jouni Malinena3b8b052009-03-27 21:59:49 +020010652
Johannes Berg68eb5502013-11-19 15:19:38 +010010653 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010010654 NL80211_MCGRP_MLME, gfp);
Jouni Malinena3b8b052009-03-27 21:59:49 +020010655 return;
10656
10657 nla_put_failure:
10658 genlmsg_cancel(msg, hdr);
10659 nlmsg_free(msg);
10660}
10661
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040010662void nl80211_send_beacon_hint_event(struct wiphy *wiphy,
10663 struct ieee80211_channel *channel_before,
10664 struct ieee80211_channel *channel_after)
10665{
10666 struct sk_buff *msg;
10667 void *hdr;
10668 struct nlattr *nl_freq;
10669
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -070010670 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_ATOMIC);
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040010671 if (!msg)
10672 return;
10673
10674 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_BEACON_HINT);
10675 if (!hdr) {
10676 nlmsg_free(msg);
10677 return;
10678 }
10679
10680 /*
10681 * Since we are applying the beacon hint to a wiphy we know its
10682 * wiphy_idx is valid
10683 */
David S. Miller9360ffd2012-03-29 04:41:26 -040010684 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy)))
10685 goto nla_put_failure;
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040010686
10687 /* Before */
10688 nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_BEFORE);
10689 if (!nl_freq)
10690 goto nla_put_failure;
Johannes Bergcdc89b92013-02-18 23:54:36 +010010691 if (nl80211_msg_put_channel(msg, channel_before, false))
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040010692 goto nla_put_failure;
10693 nla_nest_end(msg, nl_freq);
10694
10695 /* After */
10696 nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_AFTER);
10697 if (!nl_freq)
10698 goto nla_put_failure;
Johannes Bergcdc89b92013-02-18 23:54:36 +010010699 if (nl80211_msg_put_channel(msg, channel_after, false))
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040010700 goto nla_put_failure;
10701 nla_nest_end(msg, nl_freq);
10702
Johannes Berg3b7b72e2011-10-22 19:05:51 +020010703 genlmsg_end(msg, hdr);
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040010704
Johannes Berg463d0182009-07-14 00:33:35 +020010705 rcu_read_lock();
Johannes Berg68eb5502013-11-19 15:19:38 +010010706 genlmsg_multicast_allns(&nl80211_fam, msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010010707 NL80211_MCGRP_REGULATORY, GFP_ATOMIC);
Johannes Berg463d0182009-07-14 00:33:35 +020010708 rcu_read_unlock();
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040010709
10710 return;
10711
10712nla_put_failure:
10713 genlmsg_cancel(msg, hdr);
10714 nlmsg_free(msg);
10715}
10716
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010717static void nl80211_send_remain_on_chan_event(
10718 int cmd, struct cfg80211_registered_device *rdev,
Johannes Berg71bbc992012-06-15 15:30:18 +020010719 struct wireless_dev *wdev, u64 cookie,
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010720 struct ieee80211_channel *chan,
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010721 unsigned int duration, gfp_t gfp)
10722{
10723 struct sk_buff *msg;
10724 void *hdr;
10725
10726 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
10727 if (!msg)
10728 return;
10729
10730 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
10731 if (!hdr) {
10732 nlmsg_free(msg);
10733 return;
10734 }
10735
David S. Miller9360ffd2012-03-29 04:41:26 -040010736 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg71bbc992012-06-15 15:30:18 +020010737 (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
10738 wdev->netdev->ifindex)) ||
Johannes Berg00f53352012-07-17 11:53:12 +020010739 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040010740 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, chan->center_freq) ||
Johannes Berg42d97a52012-11-08 18:31:02 +010010741 nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE,
10742 NL80211_CHAN_NO_HT) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040010743 nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie))
10744 goto nla_put_failure;
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010745
David S. Miller9360ffd2012-03-29 04:41:26 -040010746 if (cmd == NL80211_CMD_REMAIN_ON_CHANNEL &&
10747 nla_put_u32(msg, NL80211_ATTR_DURATION, duration))
10748 goto nla_put_failure;
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010749
Johannes Berg3b7b72e2011-10-22 19:05:51 +020010750 genlmsg_end(msg, hdr);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010751
Johannes Berg68eb5502013-11-19 15:19:38 +010010752 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010010753 NL80211_MCGRP_MLME, gfp);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010754 return;
10755
10756 nla_put_failure:
10757 genlmsg_cancel(msg, hdr);
10758 nlmsg_free(msg);
10759}
10760
Johannes Berg947add32013-02-22 22:05:20 +010010761void cfg80211_ready_on_channel(struct wireless_dev *wdev, u64 cookie,
10762 struct ieee80211_channel *chan,
10763 unsigned int duration, gfp_t gfp)
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010764{
Johannes Berg947add32013-02-22 22:05:20 +010010765 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080010766 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg947add32013-02-22 22:05:20 +010010767
10768 trace_cfg80211_ready_on_channel(wdev, cookie, chan, duration);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010769 nl80211_send_remain_on_chan_event(NL80211_CMD_REMAIN_ON_CHANNEL,
Johannes Berg71bbc992012-06-15 15:30:18 +020010770 rdev, wdev, cookie, chan,
Johannes Berg42d97a52012-11-08 18:31:02 +010010771 duration, gfp);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010772}
Johannes Berg947add32013-02-22 22:05:20 +010010773EXPORT_SYMBOL(cfg80211_ready_on_channel);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010774
Johannes Berg947add32013-02-22 22:05:20 +010010775void cfg80211_remain_on_channel_expired(struct wireless_dev *wdev, u64 cookie,
10776 struct ieee80211_channel *chan,
10777 gfp_t gfp)
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010778{
Johannes Berg947add32013-02-22 22:05:20 +010010779 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080010780 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg947add32013-02-22 22:05:20 +010010781
10782 trace_cfg80211_ready_on_channel_expired(wdev, cookie, chan);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010783 nl80211_send_remain_on_chan_event(NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL,
Johannes Berg42d97a52012-11-08 18:31:02 +010010784 rdev, wdev, cookie, chan, 0, gfp);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010785}
Johannes Berg947add32013-02-22 22:05:20 +010010786EXPORT_SYMBOL(cfg80211_remain_on_channel_expired);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010787
Johannes Berg947add32013-02-22 22:05:20 +010010788void cfg80211_new_sta(struct net_device *dev, const u8 *mac_addr,
10789 struct station_info *sinfo, gfp_t gfp)
Johannes Berg98b62182009-12-23 13:15:44 +010010790{
Johannes Berg947add32013-02-22 22:05:20 +010010791 struct wiphy *wiphy = dev->ieee80211_ptr->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080010792 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg98b62182009-12-23 13:15:44 +010010793 struct sk_buff *msg;
10794
Johannes Berg947add32013-02-22 22:05:20 +010010795 trace_cfg80211_new_sta(dev, mac_addr, sinfo);
10796
Thomas Graf58050fc2012-06-28 03:57:45 +000010797 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Johannes Berg98b62182009-12-23 13:15:44 +010010798 if (!msg)
10799 return;
10800
John W. Linville66266b32012-03-15 13:25:41 -040010801 if (nl80211_send_station(msg, 0, 0, 0,
10802 rdev, dev, mac_addr, sinfo) < 0) {
Johannes Berg98b62182009-12-23 13:15:44 +010010803 nlmsg_free(msg);
10804 return;
10805 }
10806
Johannes Berg68eb5502013-11-19 15:19:38 +010010807 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010010808 NL80211_MCGRP_MLME, gfp);
Johannes Berg98b62182009-12-23 13:15:44 +010010809}
Johannes Berg947add32013-02-22 22:05:20 +010010810EXPORT_SYMBOL(cfg80211_new_sta);
Johannes Berg98b62182009-12-23 13:15:44 +010010811
Johannes Berg947add32013-02-22 22:05:20 +010010812void cfg80211_del_sta(struct net_device *dev, const u8 *mac_addr, gfp_t gfp)
Jouni Malinenec15e682011-03-23 15:29:52 +020010813{
Johannes Berg947add32013-02-22 22:05:20 +010010814 struct wiphy *wiphy = dev->ieee80211_ptr->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080010815 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Jouni Malinenec15e682011-03-23 15:29:52 +020010816 struct sk_buff *msg;
10817 void *hdr;
10818
Johannes Berg947add32013-02-22 22:05:20 +010010819 trace_cfg80211_del_sta(dev, mac_addr);
10820
Thomas Graf58050fc2012-06-28 03:57:45 +000010821 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinenec15e682011-03-23 15:29:52 +020010822 if (!msg)
10823 return;
10824
10825 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DEL_STATION);
10826 if (!hdr) {
10827 nlmsg_free(msg);
10828 return;
10829 }
10830
David S. Miller9360ffd2012-03-29 04:41:26 -040010831 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
10832 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr))
10833 goto nla_put_failure;
Jouni Malinenec15e682011-03-23 15:29:52 +020010834
Johannes Berg3b7b72e2011-10-22 19:05:51 +020010835 genlmsg_end(msg, hdr);
Jouni Malinenec15e682011-03-23 15:29:52 +020010836
Johannes Berg68eb5502013-11-19 15:19:38 +010010837 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010010838 NL80211_MCGRP_MLME, gfp);
Jouni Malinenec15e682011-03-23 15:29:52 +020010839 return;
10840
10841 nla_put_failure:
10842 genlmsg_cancel(msg, hdr);
10843 nlmsg_free(msg);
10844}
Johannes Berg947add32013-02-22 22:05:20 +010010845EXPORT_SYMBOL(cfg80211_del_sta);
Jouni Malinenec15e682011-03-23 15:29:52 +020010846
Johannes Berg947add32013-02-22 22:05:20 +010010847void cfg80211_conn_failed(struct net_device *dev, const u8 *mac_addr,
10848 enum nl80211_connect_failed_reason reason,
10849 gfp_t gfp)
Pandiyarajan Pitchaimuthued44a952012-09-18 16:50:49 +053010850{
Johannes Berg947add32013-02-22 22:05:20 +010010851 struct wiphy *wiphy = dev->ieee80211_ptr->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080010852 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Pandiyarajan Pitchaimuthued44a952012-09-18 16:50:49 +053010853 struct sk_buff *msg;
10854 void *hdr;
10855
10856 msg = nlmsg_new(NLMSG_GOODSIZE, gfp);
10857 if (!msg)
10858 return;
10859
10860 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONN_FAILED);
10861 if (!hdr) {
10862 nlmsg_free(msg);
10863 return;
10864 }
10865
10866 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
10867 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) ||
10868 nla_put_u32(msg, NL80211_ATTR_CONN_FAILED_REASON, reason))
10869 goto nla_put_failure;
10870
10871 genlmsg_end(msg, hdr);
10872
Johannes Berg68eb5502013-11-19 15:19:38 +010010873 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010010874 NL80211_MCGRP_MLME, gfp);
Pandiyarajan Pitchaimuthued44a952012-09-18 16:50:49 +053010875 return;
10876
10877 nla_put_failure:
10878 genlmsg_cancel(msg, hdr);
10879 nlmsg_free(msg);
10880}
Johannes Berg947add32013-02-22 22:05:20 +010010881EXPORT_SYMBOL(cfg80211_conn_failed);
Pandiyarajan Pitchaimuthued44a952012-09-18 16:50:49 +053010882
Johannes Bergb92ab5d2011-11-04 11:18:19 +010010883static bool __nl80211_unexpected_frame(struct net_device *dev, u8 cmd,
10884 const u8 *addr, gfp_t gfp)
Johannes Berg28946da2011-11-04 11:18:12 +010010885{
10886 struct wireless_dev *wdev = dev->ieee80211_ptr;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080010887 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Johannes Berg28946da2011-11-04 11:18:12 +010010888 struct sk_buff *msg;
10889 void *hdr;
Eric W. Biederman15e47302012-09-07 20:12:54 +000010890 u32 nlportid = ACCESS_ONCE(wdev->ap_unexpected_nlportid);
Johannes Berg28946da2011-11-04 11:18:12 +010010891
Eric W. Biederman15e47302012-09-07 20:12:54 +000010892 if (!nlportid)
Johannes Berg28946da2011-11-04 11:18:12 +010010893 return false;
10894
10895 msg = nlmsg_new(100, gfp);
10896 if (!msg)
10897 return true;
10898
Johannes Bergb92ab5d2011-11-04 11:18:19 +010010899 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
Johannes Berg28946da2011-11-04 11:18:12 +010010900 if (!hdr) {
10901 nlmsg_free(msg);
10902 return true;
10903 }
10904
David S. Miller9360ffd2012-03-29 04:41:26 -040010905 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
10906 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
10907 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr))
10908 goto nla_put_failure;
Johannes Berg28946da2011-11-04 11:18:12 +010010909
Johannes Berg9c90a9f2013-06-04 12:46:03 +020010910 genlmsg_end(msg, hdr);
Eric W. Biederman15e47302012-09-07 20:12:54 +000010911 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid);
Johannes Berg28946da2011-11-04 11:18:12 +010010912 return true;
10913
10914 nla_put_failure:
10915 genlmsg_cancel(msg, hdr);
10916 nlmsg_free(msg);
10917 return true;
10918}
10919
Johannes Berg947add32013-02-22 22:05:20 +010010920bool cfg80211_rx_spurious_frame(struct net_device *dev,
10921 const u8 *addr, gfp_t gfp)
Johannes Bergb92ab5d2011-11-04 11:18:19 +010010922{
Johannes Berg947add32013-02-22 22:05:20 +010010923 struct wireless_dev *wdev = dev->ieee80211_ptr;
10924 bool ret;
Johannes Bergb92ab5d2011-11-04 11:18:19 +010010925
Johannes Berg947add32013-02-22 22:05:20 +010010926 trace_cfg80211_rx_spurious_frame(dev, addr);
10927
10928 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP &&
10929 wdev->iftype != NL80211_IFTYPE_P2P_GO)) {
10930 trace_cfg80211_return_bool(false);
10931 return false;
10932 }
10933 ret = __nl80211_unexpected_frame(dev, NL80211_CMD_UNEXPECTED_FRAME,
10934 addr, gfp);
10935 trace_cfg80211_return_bool(ret);
10936 return ret;
Johannes Bergb92ab5d2011-11-04 11:18:19 +010010937}
Johannes Berg947add32013-02-22 22:05:20 +010010938EXPORT_SYMBOL(cfg80211_rx_spurious_frame);
10939
10940bool cfg80211_rx_unexpected_4addr_frame(struct net_device *dev,
10941 const u8 *addr, gfp_t gfp)
10942{
10943 struct wireless_dev *wdev = dev->ieee80211_ptr;
10944 bool ret;
10945
10946 trace_cfg80211_rx_unexpected_4addr_frame(dev, addr);
10947
10948 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP &&
10949 wdev->iftype != NL80211_IFTYPE_P2P_GO &&
10950 wdev->iftype != NL80211_IFTYPE_AP_VLAN)) {
10951 trace_cfg80211_return_bool(false);
10952 return false;
10953 }
10954 ret = __nl80211_unexpected_frame(dev,
10955 NL80211_CMD_UNEXPECTED_4ADDR_FRAME,
10956 addr, gfp);
10957 trace_cfg80211_return_bool(ret);
10958 return ret;
10959}
10960EXPORT_SYMBOL(cfg80211_rx_unexpected_4addr_frame);
Johannes Bergb92ab5d2011-11-04 11:18:19 +010010961
Johannes Berg2e161f782010-08-12 15:38:38 +020010962int nl80211_send_mgmt(struct cfg80211_registered_device *rdev,
Eric W. Biederman15e47302012-09-07 20:12:54 +000010963 struct wireless_dev *wdev, u32 nlportid,
Johannes Berg804483e2012-03-05 22:18:41 +010010964 int freq, int sig_dbm,
Vladimir Kondratiev19504cf2013-08-15 14:51:28 +030010965 const u8 *buf, size_t len, u32 flags, gfp_t gfp)
Jouni Malinen026331c2010-02-15 12:53:10 +020010966{
Johannes Berg71bbc992012-06-15 15:30:18 +020010967 struct net_device *netdev = wdev->netdev;
Jouni Malinen026331c2010-02-15 12:53:10 +020010968 struct sk_buff *msg;
10969 void *hdr;
Jouni Malinen026331c2010-02-15 12:53:10 +020010970
10971 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
10972 if (!msg)
10973 return -ENOMEM;
10974
Johannes Berg2e161f782010-08-12 15:38:38 +020010975 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME);
Jouni Malinen026331c2010-02-15 12:53:10 +020010976 if (!hdr) {
10977 nlmsg_free(msg);
10978 return -ENOMEM;
10979 }
10980
David S. Miller9360ffd2012-03-29 04:41:26 -040010981 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg71bbc992012-06-15 15:30:18 +020010982 (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
10983 netdev->ifindex)) ||
Ilan Peera8384902013-05-08 16:35:55 +030010984 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040010985 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq) ||
10986 (sig_dbm &&
10987 nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) ||
Vladimir Kondratiev19504cf2013-08-15 14:51:28 +030010988 nla_put(msg, NL80211_ATTR_FRAME, len, buf) ||
10989 (flags &&
10990 nla_put_u32(msg, NL80211_ATTR_RXMGMT_FLAGS, flags)))
David S. Miller9360ffd2012-03-29 04:41:26 -040010991 goto nla_put_failure;
Jouni Malinen026331c2010-02-15 12:53:10 +020010992
Johannes Berg3b7b72e2011-10-22 19:05:51 +020010993 genlmsg_end(msg, hdr);
Jouni Malinen026331c2010-02-15 12:53:10 +020010994
Eric W. Biederman15e47302012-09-07 20:12:54 +000010995 return genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid);
Jouni Malinen026331c2010-02-15 12:53:10 +020010996
10997 nla_put_failure:
10998 genlmsg_cancel(msg, hdr);
10999 nlmsg_free(msg);
11000 return -ENOBUFS;
11001}
11002
Johannes Berg947add32013-02-22 22:05:20 +010011003void cfg80211_mgmt_tx_status(struct wireless_dev *wdev, u64 cookie,
11004 const u8 *buf, size_t len, bool ack, gfp_t gfp)
Jouni Malinen026331c2010-02-15 12:53:10 +020011005{
Johannes Berg947add32013-02-22 22:05:20 +010011006 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080011007 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg71bbc992012-06-15 15:30:18 +020011008 struct net_device *netdev = wdev->netdev;
Jouni Malinen026331c2010-02-15 12:53:10 +020011009 struct sk_buff *msg;
11010 void *hdr;
11011
Johannes Berg947add32013-02-22 22:05:20 +010011012 trace_cfg80211_mgmt_tx_status(wdev, cookie, ack);
11013
Jouni Malinen026331c2010-02-15 12:53:10 +020011014 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
11015 if (!msg)
11016 return;
11017
Johannes Berg2e161f782010-08-12 15:38:38 +020011018 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME_TX_STATUS);
Jouni Malinen026331c2010-02-15 12:53:10 +020011019 if (!hdr) {
11020 nlmsg_free(msg);
11021 return;
11022 }
11023
David S. Miller9360ffd2012-03-29 04:41:26 -040011024 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg71bbc992012-06-15 15:30:18 +020011025 (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
11026 netdev->ifindex)) ||
Ilan Peera8384902013-05-08 16:35:55 +030011027 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040011028 nla_put(msg, NL80211_ATTR_FRAME, len, buf) ||
11029 nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie) ||
11030 (ack && nla_put_flag(msg, NL80211_ATTR_ACK)))
11031 goto nla_put_failure;
Jouni Malinen026331c2010-02-15 12:53:10 +020011032
Johannes Berg3b7b72e2011-10-22 19:05:51 +020011033 genlmsg_end(msg, hdr);
Jouni Malinen026331c2010-02-15 12:53:10 +020011034
Johannes Berg68eb5502013-11-19 15:19:38 +010011035 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011036 NL80211_MCGRP_MLME, gfp);
Jouni Malinen026331c2010-02-15 12:53:10 +020011037 return;
11038
11039 nla_put_failure:
11040 genlmsg_cancel(msg, hdr);
11041 nlmsg_free(msg);
11042}
Johannes Berg947add32013-02-22 22:05:20 +010011043EXPORT_SYMBOL(cfg80211_mgmt_tx_status);
Jouni Malinen026331c2010-02-15 12:53:10 +020011044
Johannes Berg947add32013-02-22 22:05:20 +010011045void cfg80211_cqm_rssi_notify(struct net_device *dev,
11046 enum nl80211_cqm_rssi_threshold_event rssi_event,
11047 gfp_t gfp)
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020011048{
Johannes Berg947add32013-02-22 22:05:20 +010011049 struct wireless_dev *wdev = dev->ieee80211_ptr;
11050 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080011051 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020011052 struct sk_buff *msg;
11053 struct nlattr *pinfoattr;
11054 void *hdr;
11055
Johannes Berg947add32013-02-22 22:05:20 +010011056 trace_cfg80211_cqm_rssi_notify(dev, rssi_event);
11057
Thomas Graf58050fc2012-06-28 03:57:45 +000011058 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020011059 if (!msg)
11060 return;
11061
11062 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM);
11063 if (!hdr) {
11064 nlmsg_free(msg);
11065 return;
11066 }
11067
David S. Miller9360ffd2012-03-29 04:41:26 -040011068 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg947add32013-02-22 22:05:20 +010011069 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex))
David S. Miller9360ffd2012-03-29 04:41:26 -040011070 goto nla_put_failure;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020011071
11072 pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM);
11073 if (!pinfoattr)
11074 goto nla_put_failure;
11075
David S. Miller9360ffd2012-03-29 04:41:26 -040011076 if (nla_put_u32(msg, NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT,
11077 rssi_event))
11078 goto nla_put_failure;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020011079
11080 nla_nest_end(msg, pinfoattr);
11081
Johannes Berg3b7b72e2011-10-22 19:05:51 +020011082 genlmsg_end(msg, hdr);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020011083
Johannes Berg68eb5502013-11-19 15:19:38 +010011084 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011085 NL80211_MCGRP_MLME, gfp);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020011086 return;
11087
11088 nla_put_failure:
11089 genlmsg_cancel(msg, hdr);
11090 nlmsg_free(msg);
11091}
Johannes Berg947add32013-02-22 22:05:20 +010011092EXPORT_SYMBOL(cfg80211_cqm_rssi_notify);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020011093
Johannes Berg947add32013-02-22 22:05:20 +010011094static void nl80211_gtk_rekey_notify(struct cfg80211_registered_device *rdev,
11095 struct net_device *netdev, const u8 *bssid,
11096 const u8 *replay_ctr, gfp_t gfp)
Johannes Berge5497d72011-07-05 16:35:40 +020011097{
11098 struct sk_buff *msg;
11099 struct nlattr *rekey_attr;
11100 void *hdr;
11101
Thomas Graf58050fc2012-06-28 03:57:45 +000011102 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Johannes Berge5497d72011-07-05 16:35:40 +020011103 if (!msg)
11104 return;
11105
11106 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_REKEY_OFFLOAD);
11107 if (!hdr) {
11108 nlmsg_free(msg);
11109 return;
11110 }
11111
David S. Miller9360ffd2012-03-29 04:41:26 -040011112 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
11113 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
11114 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid))
11115 goto nla_put_failure;
Johannes Berge5497d72011-07-05 16:35:40 +020011116
11117 rekey_attr = nla_nest_start(msg, NL80211_ATTR_REKEY_DATA);
11118 if (!rekey_attr)
11119 goto nla_put_failure;
11120
David S. Miller9360ffd2012-03-29 04:41:26 -040011121 if (nla_put(msg, NL80211_REKEY_DATA_REPLAY_CTR,
11122 NL80211_REPLAY_CTR_LEN, replay_ctr))
11123 goto nla_put_failure;
Johannes Berge5497d72011-07-05 16:35:40 +020011124
11125 nla_nest_end(msg, rekey_attr);
11126
Johannes Berg3b7b72e2011-10-22 19:05:51 +020011127 genlmsg_end(msg, hdr);
Johannes Berge5497d72011-07-05 16:35:40 +020011128
Johannes Berg68eb5502013-11-19 15:19:38 +010011129 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011130 NL80211_MCGRP_MLME, gfp);
Johannes Berge5497d72011-07-05 16:35:40 +020011131 return;
11132
11133 nla_put_failure:
11134 genlmsg_cancel(msg, hdr);
11135 nlmsg_free(msg);
11136}
11137
Johannes Berg947add32013-02-22 22:05:20 +010011138void cfg80211_gtk_rekey_notify(struct net_device *dev, const u8 *bssid,
11139 const u8 *replay_ctr, gfp_t gfp)
11140{
11141 struct wireless_dev *wdev = dev->ieee80211_ptr;
11142 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080011143 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg947add32013-02-22 22:05:20 +010011144
11145 trace_cfg80211_gtk_rekey_notify(dev, bssid);
11146 nl80211_gtk_rekey_notify(rdev, dev, bssid, replay_ctr, gfp);
11147}
11148EXPORT_SYMBOL(cfg80211_gtk_rekey_notify);
11149
11150static void
11151nl80211_pmksa_candidate_notify(struct cfg80211_registered_device *rdev,
11152 struct net_device *netdev, int index,
11153 const u8 *bssid, bool preauth, gfp_t gfp)
Jouni Malinenc9df56b2011-09-16 18:56:23 +030011154{
11155 struct sk_buff *msg;
11156 struct nlattr *attr;
11157 void *hdr;
11158
Thomas Graf58050fc2012-06-28 03:57:45 +000011159 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinenc9df56b2011-09-16 18:56:23 +030011160 if (!msg)
11161 return;
11162
11163 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PMKSA_CANDIDATE);
11164 if (!hdr) {
11165 nlmsg_free(msg);
11166 return;
11167 }
11168
David S. Miller9360ffd2012-03-29 04:41:26 -040011169 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
11170 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex))
11171 goto nla_put_failure;
Jouni Malinenc9df56b2011-09-16 18:56:23 +030011172
11173 attr = nla_nest_start(msg, NL80211_ATTR_PMKSA_CANDIDATE);
11174 if (!attr)
11175 goto nla_put_failure;
11176
David S. Miller9360ffd2012-03-29 04:41:26 -040011177 if (nla_put_u32(msg, NL80211_PMKSA_CANDIDATE_INDEX, index) ||
11178 nla_put(msg, NL80211_PMKSA_CANDIDATE_BSSID, ETH_ALEN, bssid) ||
11179 (preauth &&
11180 nla_put_flag(msg, NL80211_PMKSA_CANDIDATE_PREAUTH)))
11181 goto nla_put_failure;
Jouni Malinenc9df56b2011-09-16 18:56:23 +030011182
11183 nla_nest_end(msg, attr);
11184
Johannes Berg3b7b72e2011-10-22 19:05:51 +020011185 genlmsg_end(msg, hdr);
Jouni Malinenc9df56b2011-09-16 18:56:23 +030011186
Johannes Berg68eb5502013-11-19 15:19:38 +010011187 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011188 NL80211_MCGRP_MLME, gfp);
Jouni Malinenc9df56b2011-09-16 18:56:23 +030011189 return;
11190
11191 nla_put_failure:
11192 genlmsg_cancel(msg, hdr);
11193 nlmsg_free(msg);
11194}
11195
Johannes Berg947add32013-02-22 22:05:20 +010011196void cfg80211_pmksa_candidate_notify(struct net_device *dev, int index,
11197 const u8 *bssid, bool preauth, gfp_t gfp)
11198{
11199 struct wireless_dev *wdev = dev->ieee80211_ptr;
11200 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080011201 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg947add32013-02-22 22:05:20 +010011202
11203 trace_cfg80211_pmksa_candidate_notify(dev, index, bssid, preauth);
11204 nl80211_pmksa_candidate_notify(rdev, dev, index, bssid, preauth, gfp);
11205}
11206EXPORT_SYMBOL(cfg80211_pmksa_candidate_notify);
11207
11208static void nl80211_ch_switch_notify(struct cfg80211_registered_device *rdev,
11209 struct net_device *netdev,
11210 struct cfg80211_chan_def *chandef,
11211 gfp_t gfp)
Thomas Pedersen53145262012-04-06 13:35:47 -070011212{
11213 struct sk_buff *msg;
11214 void *hdr;
11215
Thomas Graf58050fc2012-06-28 03:57:45 +000011216 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Thomas Pedersen53145262012-04-06 13:35:47 -070011217 if (!msg)
11218 return;
11219
11220 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CH_SWITCH_NOTIFY);
11221 if (!hdr) {
11222 nlmsg_free(msg);
11223 return;
11224 }
11225
Johannes Berg683b6d32012-11-08 21:25:48 +010011226 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex))
11227 goto nla_put_failure;
11228
11229 if (nl80211_send_chandef(msg, chandef))
John W. Linville7eab0f62012-04-12 14:25:14 -040011230 goto nla_put_failure;
Thomas Pedersen53145262012-04-06 13:35:47 -070011231
11232 genlmsg_end(msg, hdr);
11233
Johannes Berg68eb5502013-11-19 15:19:38 +010011234 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011235 NL80211_MCGRP_MLME, gfp);
Thomas Pedersen53145262012-04-06 13:35:47 -070011236 return;
11237
11238 nla_put_failure:
11239 genlmsg_cancel(msg, hdr);
11240 nlmsg_free(msg);
11241}
11242
Johannes Berg947add32013-02-22 22:05:20 +010011243void cfg80211_ch_switch_notify(struct net_device *dev,
11244 struct cfg80211_chan_def *chandef)
Thomas Pedersen84f10702012-07-12 16:17:33 -070011245{
Johannes Berg947add32013-02-22 22:05:20 +010011246 struct wireless_dev *wdev = dev->ieee80211_ptr;
11247 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080011248 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg947add32013-02-22 22:05:20 +010011249
Simon Wunderliche487eae2013-11-21 18:19:51 +010011250 ASSERT_WDEV_LOCK(wdev);
Johannes Berg947add32013-02-22 22:05:20 +010011251
Simon Wunderliche487eae2013-11-21 18:19:51 +010011252 trace_cfg80211_ch_switch_notify(dev, chandef);
Johannes Berg947add32013-02-22 22:05:20 +010011253
11254 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP &&
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +020011255 wdev->iftype != NL80211_IFTYPE_P2P_GO &&
Chun-Yeow Yeohb8456a12013-10-17 15:55:02 -070011256 wdev->iftype != NL80211_IFTYPE_ADHOC &&
11257 wdev->iftype != NL80211_IFTYPE_MESH_POINT))
Simon Wunderliche487eae2013-11-21 18:19:51 +010011258 return;
Johannes Berg947add32013-02-22 22:05:20 +010011259
Michal Kazior9e0e2962014-01-29 14:22:27 +010011260 wdev->chandef = *chandef;
Janusz Dziedzic96f55f12014-01-24 14:29:21 +010011261 wdev->preset_chandef = *chandef;
Johannes Berg947add32013-02-22 22:05:20 +010011262 nl80211_ch_switch_notify(rdev, dev, chandef, GFP_KERNEL);
Johannes Berg947add32013-02-22 22:05:20 +010011263}
11264EXPORT_SYMBOL(cfg80211_ch_switch_notify);
11265
11266void cfg80211_cqm_txe_notify(struct net_device *dev,
11267 const u8 *peer, u32 num_packets,
11268 u32 rate, u32 intvl, gfp_t gfp)
11269{
11270 struct wireless_dev *wdev = dev->ieee80211_ptr;
11271 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080011272 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Thomas Pedersen84f10702012-07-12 16:17:33 -070011273 struct sk_buff *msg;
11274 struct nlattr *pinfoattr;
11275 void *hdr;
11276
11277 msg = nlmsg_new(NLMSG_GOODSIZE, gfp);
11278 if (!msg)
11279 return;
11280
11281 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM);
11282 if (!hdr) {
11283 nlmsg_free(msg);
11284 return;
11285 }
11286
11287 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg947add32013-02-22 22:05:20 +010011288 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
Thomas Pedersen84f10702012-07-12 16:17:33 -070011289 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer))
11290 goto nla_put_failure;
11291
11292 pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM);
11293 if (!pinfoattr)
11294 goto nla_put_failure;
11295
11296 if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_PKTS, num_packets))
11297 goto nla_put_failure;
11298
11299 if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_RATE, rate))
11300 goto nla_put_failure;
11301
11302 if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_INTVL, intvl))
11303 goto nla_put_failure;
11304
11305 nla_nest_end(msg, pinfoattr);
11306
11307 genlmsg_end(msg, hdr);
11308
Johannes Berg68eb5502013-11-19 15:19:38 +010011309 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011310 NL80211_MCGRP_MLME, gfp);
Thomas Pedersen84f10702012-07-12 16:17:33 -070011311 return;
11312
11313 nla_put_failure:
11314 genlmsg_cancel(msg, hdr);
11315 nlmsg_free(msg);
11316}
Johannes Berg947add32013-02-22 22:05:20 +010011317EXPORT_SYMBOL(cfg80211_cqm_txe_notify);
Thomas Pedersen84f10702012-07-12 16:17:33 -070011318
11319void
Simon Wunderlich04f39042013-02-08 18:16:19 +010011320nl80211_radar_notify(struct cfg80211_registered_device *rdev,
Janusz Dziedzicd2859df2013-11-06 13:55:51 +010011321 const struct cfg80211_chan_def *chandef,
Simon Wunderlich04f39042013-02-08 18:16:19 +010011322 enum nl80211_radar_event event,
11323 struct net_device *netdev, gfp_t gfp)
11324{
11325 struct sk_buff *msg;
11326 void *hdr;
11327
11328 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
11329 if (!msg)
11330 return;
11331
11332 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_RADAR_DETECT);
11333 if (!hdr) {
11334 nlmsg_free(msg);
11335 return;
11336 }
11337
11338 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx))
11339 goto nla_put_failure;
11340
11341 /* NOP and radar events don't need a netdev parameter */
11342 if (netdev) {
11343 struct wireless_dev *wdev = netdev->ieee80211_ptr;
11344
11345 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
11346 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)))
11347 goto nla_put_failure;
11348 }
11349
11350 if (nla_put_u32(msg, NL80211_ATTR_RADAR_EVENT, event))
11351 goto nla_put_failure;
11352
11353 if (nl80211_send_chandef(msg, chandef))
11354 goto nla_put_failure;
11355
Johannes Berg9c90a9f2013-06-04 12:46:03 +020011356 genlmsg_end(msg, hdr);
Simon Wunderlich04f39042013-02-08 18:16:19 +010011357
Johannes Berg68eb5502013-11-19 15:19:38 +010011358 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011359 NL80211_MCGRP_MLME, gfp);
Simon Wunderlich04f39042013-02-08 18:16:19 +010011360 return;
11361
11362 nla_put_failure:
11363 genlmsg_cancel(msg, hdr);
11364 nlmsg_free(msg);
11365}
11366
Johannes Berg947add32013-02-22 22:05:20 +010011367void cfg80211_cqm_pktloss_notify(struct net_device *dev,
11368 const u8 *peer, u32 num_packets, gfp_t gfp)
Johannes Bergc063dbf2010-11-24 08:10:05 +010011369{
Johannes Berg947add32013-02-22 22:05:20 +010011370 struct wireless_dev *wdev = dev->ieee80211_ptr;
11371 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080011372 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Bergc063dbf2010-11-24 08:10:05 +010011373 struct sk_buff *msg;
11374 struct nlattr *pinfoattr;
11375 void *hdr;
11376
Johannes Berg947add32013-02-22 22:05:20 +010011377 trace_cfg80211_cqm_pktloss_notify(dev, peer, num_packets);
11378
Thomas Graf58050fc2012-06-28 03:57:45 +000011379 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Johannes Bergc063dbf2010-11-24 08:10:05 +010011380 if (!msg)
11381 return;
11382
11383 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM);
11384 if (!hdr) {
11385 nlmsg_free(msg);
11386 return;
11387 }
11388
David S. Miller9360ffd2012-03-29 04:41:26 -040011389 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg947add32013-02-22 22:05:20 +010011390 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040011391 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer))
11392 goto nla_put_failure;
Johannes Bergc063dbf2010-11-24 08:10:05 +010011393
11394 pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM);
11395 if (!pinfoattr)
11396 goto nla_put_failure;
11397
David S. Miller9360ffd2012-03-29 04:41:26 -040011398 if (nla_put_u32(msg, NL80211_ATTR_CQM_PKT_LOSS_EVENT, num_packets))
11399 goto nla_put_failure;
Johannes Bergc063dbf2010-11-24 08:10:05 +010011400
11401 nla_nest_end(msg, pinfoattr);
11402
Johannes Berg3b7b72e2011-10-22 19:05:51 +020011403 genlmsg_end(msg, hdr);
Johannes Bergc063dbf2010-11-24 08:10:05 +010011404
Johannes Berg68eb5502013-11-19 15:19:38 +010011405 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011406 NL80211_MCGRP_MLME, gfp);
Johannes Bergc063dbf2010-11-24 08:10:05 +010011407 return;
11408
11409 nla_put_failure:
11410 genlmsg_cancel(msg, hdr);
11411 nlmsg_free(msg);
11412}
Johannes Berg947add32013-02-22 22:05:20 +010011413EXPORT_SYMBOL(cfg80211_cqm_pktloss_notify);
Johannes Bergc063dbf2010-11-24 08:10:05 +010011414
Johannes Berg7f6cf312011-11-04 11:18:15 +010011415void cfg80211_probe_status(struct net_device *dev, const u8 *addr,
11416 u64 cookie, bool acked, gfp_t gfp)
11417{
11418 struct wireless_dev *wdev = dev->ieee80211_ptr;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080011419 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Johannes Berg7f6cf312011-11-04 11:18:15 +010011420 struct sk_buff *msg;
11421 void *hdr;
Johannes Berg7f6cf312011-11-04 11:18:15 +010011422
Beni Lev4ee3e062012-08-27 12:49:39 +030011423 trace_cfg80211_probe_status(dev, addr, cookie, acked);
11424
Thomas Graf58050fc2012-06-28 03:57:45 +000011425 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Beni Lev4ee3e062012-08-27 12:49:39 +030011426
Johannes Berg7f6cf312011-11-04 11:18:15 +010011427 if (!msg)
11428 return;
11429
11430 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PROBE_CLIENT);
11431 if (!hdr) {
11432 nlmsg_free(msg);
11433 return;
11434 }
11435
David S. Miller9360ffd2012-03-29 04:41:26 -040011436 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
11437 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
11438 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) ||
11439 nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie) ||
11440 (acked && nla_put_flag(msg, NL80211_ATTR_ACK)))
11441 goto nla_put_failure;
Johannes Berg7f6cf312011-11-04 11:18:15 +010011442
Johannes Berg9c90a9f2013-06-04 12:46:03 +020011443 genlmsg_end(msg, hdr);
Johannes Berg7f6cf312011-11-04 11:18:15 +010011444
Johannes Berg68eb5502013-11-19 15:19:38 +010011445 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011446 NL80211_MCGRP_MLME, gfp);
Johannes Berg7f6cf312011-11-04 11:18:15 +010011447 return;
11448
11449 nla_put_failure:
11450 genlmsg_cancel(msg, hdr);
11451 nlmsg_free(msg);
11452}
11453EXPORT_SYMBOL(cfg80211_probe_status);
11454
Johannes Berg5e760232011-11-04 11:18:17 +010011455void cfg80211_report_obss_beacon(struct wiphy *wiphy,
11456 const u8 *frame, size_t len,
Ben Greear37c73b52012-10-26 14:49:25 -070011457 int freq, int sig_dbm)
Johannes Berg5e760232011-11-04 11:18:17 +010011458{
Zhao, Gangf26cbf42014-04-21 12:53:03 +080011459 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg5e760232011-11-04 11:18:17 +010011460 struct sk_buff *msg;
11461 void *hdr;
Ben Greear37c73b52012-10-26 14:49:25 -070011462 struct cfg80211_beacon_registration *reg;
Johannes Berg5e760232011-11-04 11:18:17 +010011463
Beni Lev4ee3e062012-08-27 12:49:39 +030011464 trace_cfg80211_report_obss_beacon(wiphy, frame, len, freq, sig_dbm);
11465
Ben Greear37c73b52012-10-26 14:49:25 -070011466 spin_lock_bh(&rdev->beacon_registrations_lock);
11467 list_for_each_entry(reg, &rdev->beacon_registrations, list) {
11468 msg = nlmsg_new(len + 100, GFP_ATOMIC);
11469 if (!msg) {
11470 spin_unlock_bh(&rdev->beacon_registrations_lock);
11471 return;
11472 }
Johannes Berg5e760232011-11-04 11:18:17 +010011473
Ben Greear37c73b52012-10-26 14:49:25 -070011474 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME);
11475 if (!hdr)
11476 goto nla_put_failure;
Johannes Berg5e760232011-11-04 11:18:17 +010011477
Ben Greear37c73b52012-10-26 14:49:25 -070011478 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
11479 (freq &&
11480 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq)) ||
11481 (sig_dbm &&
11482 nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) ||
11483 nla_put(msg, NL80211_ATTR_FRAME, len, frame))
11484 goto nla_put_failure;
11485
11486 genlmsg_end(msg, hdr);
11487
11488 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, reg->nlportid);
Johannes Berg5e760232011-11-04 11:18:17 +010011489 }
Ben Greear37c73b52012-10-26 14:49:25 -070011490 spin_unlock_bh(&rdev->beacon_registrations_lock);
Johannes Berg5e760232011-11-04 11:18:17 +010011491 return;
11492
11493 nla_put_failure:
Ben Greear37c73b52012-10-26 14:49:25 -070011494 spin_unlock_bh(&rdev->beacon_registrations_lock);
11495 if (hdr)
11496 genlmsg_cancel(msg, hdr);
Johannes Berg5e760232011-11-04 11:18:17 +010011497 nlmsg_free(msg);
11498}
11499EXPORT_SYMBOL(cfg80211_report_obss_beacon);
11500
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010011501#ifdef CONFIG_PM
11502void cfg80211_report_wowlan_wakeup(struct wireless_dev *wdev,
11503 struct cfg80211_wowlan_wakeup *wakeup,
11504 gfp_t gfp)
11505{
Zhao, Gangf26cbf42014-04-21 12:53:03 +080011506 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010011507 struct sk_buff *msg;
11508 void *hdr;
Johannes Berg9c90a9f2013-06-04 12:46:03 +020011509 int size = 200;
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010011510
11511 trace_cfg80211_report_wowlan_wakeup(wdev->wiphy, wdev, wakeup);
11512
11513 if (wakeup)
11514 size += wakeup->packet_present_len;
11515
11516 msg = nlmsg_new(size, gfp);
11517 if (!msg)
11518 return;
11519
11520 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_WOWLAN);
11521 if (!hdr)
11522 goto free_msg;
11523
11524 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
11525 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)))
11526 goto free_msg;
11527
11528 if (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
11529 wdev->netdev->ifindex))
11530 goto free_msg;
11531
11532 if (wakeup) {
11533 struct nlattr *reasons;
11534
11535 reasons = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS);
Johannes Berg7fa322c2013-10-25 11:16:58 +020011536 if (!reasons)
11537 goto free_msg;
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010011538
11539 if (wakeup->disconnect &&
11540 nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT))
11541 goto free_msg;
11542 if (wakeup->magic_pkt &&
11543 nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT))
11544 goto free_msg;
11545 if (wakeup->gtk_rekey_failure &&
11546 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE))
11547 goto free_msg;
11548 if (wakeup->eap_identity_req &&
11549 nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST))
11550 goto free_msg;
11551 if (wakeup->four_way_handshake &&
11552 nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE))
11553 goto free_msg;
11554 if (wakeup->rfkill_release &&
11555 nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE))
11556 goto free_msg;
11557
11558 if (wakeup->pattern_idx >= 0 &&
11559 nla_put_u32(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN,
11560 wakeup->pattern_idx))
11561 goto free_msg;
11562
Johannes Bergae917c92013-10-25 11:05:22 +020011563 if (wakeup->tcp_match &&
11564 nla_put_flag(msg, NL80211_WOWLAN_TRIG_WAKEUP_TCP_MATCH))
11565 goto free_msg;
Johannes Berg2a0e0472013-01-23 22:57:40 +010011566
Johannes Bergae917c92013-10-25 11:05:22 +020011567 if (wakeup->tcp_connlost &&
11568 nla_put_flag(msg, NL80211_WOWLAN_TRIG_WAKEUP_TCP_CONNLOST))
11569 goto free_msg;
Johannes Berg2a0e0472013-01-23 22:57:40 +010011570
Johannes Bergae917c92013-10-25 11:05:22 +020011571 if (wakeup->tcp_nomoretokens &&
11572 nla_put_flag(msg,
11573 NL80211_WOWLAN_TRIG_WAKEUP_TCP_NOMORETOKENS))
11574 goto free_msg;
Johannes Berg2a0e0472013-01-23 22:57:40 +010011575
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010011576 if (wakeup->packet) {
11577 u32 pkt_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211;
11578 u32 len_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211_LEN;
11579
11580 if (!wakeup->packet_80211) {
11581 pkt_attr =
11582 NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023;
11583 len_attr =
11584 NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023_LEN;
11585 }
11586
11587 if (wakeup->packet_len &&
11588 nla_put_u32(msg, len_attr, wakeup->packet_len))
11589 goto free_msg;
11590
11591 if (nla_put(msg, pkt_attr, wakeup->packet_present_len,
11592 wakeup->packet))
11593 goto free_msg;
11594 }
11595
11596 nla_nest_end(msg, reasons);
11597 }
11598
Johannes Berg9c90a9f2013-06-04 12:46:03 +020011599 genlmsg_end(msg, hdr);
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010011600
Johannes Berg68eb5502013-11-19 15:19:38 +010011601 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011602 NL80211_MCGRP_MLME, gfp);
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010011603 return;
11604
11605 free_msg:
11606 nlmsg_free(msg);
11607}
11608EXPORT_SYMBOL(cfg80211_report_wowlan_wakeup);
11609#endif
11610
Jouni Malinen3475b092012-11-16 22:49:57 +020011611void cfg80211_tdls_oper_request(struct net_device *dev, const u8 *peer,
11612 enum nl80211_tdls_operation oper,
11613 u16 reason_code, gfp_t gfp)
11614{
11615 struct wireless_dev *wdev = dev->ieee80211_ptr;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080011616 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Jouni Malinen3475b092012-11-16 22:49:57 +020011617 struct sk_buff *msg;
11618 void *hdr;
Jouni Malinen3475b092012-11-16 22:49:57 +020011619
11620 trace_cfg80211_tdls_oper_request(wdev->wiphy, dev, peer, oper,
11621 reason_code);
11622
11623 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
11624 if (!msg)
11625 return;
11626
11627 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_TDLS_OPER);
11628 if (!hdr) {
11629 nlmsg_free(msg);
11630 return;
11631 }
11632
11633 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
11634 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
11635 nla_put_u8(msg, NL80211_ATTR_TDLS_OPERATION, oper) ||
11636 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer) ||
11637 (reason_code > 0 &&
11638 nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason_code)))
11639 goto nla_put_failure;
11640
Johannes Berg9c90a9f2013-06-04 12:46:03 +020011641 genlmsg_end(msg, hdr);
Jouni Malinen3475b092012-11-16 22:49:57 +020011642
Johannes Berg68eb5502013-11-19 15:19:38 +010011643 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011644 NL80211_MCGRP_MLME, gfp);
Jouni Malinen3475b092012-11-16 22:49:57 +020011645 return;
11646
11647 nla_put_failure:
11648 genlmsg_cancel(msg, hdr);
11649 nlmsg_free(msg);
11650}
11651EXPORT_SYMBOL(cfg80211_tdls_oper_request);
11652
Jouni Malinen026331c2010-02-15 12:53:10 +020011653static int nl80211_netlink_notify(struct notifier_block * nb,
11654 unsigned long state,
11655 void *_notify)
11656{
11657 struct netlink_notify *notify = _notify;
11658 struct cfg80211_registered_device *rdev;
11659 struct wireless_dev *wdev;
Ben Greear37c73b52012-10-26 14:49:25 -070011660 struct cfg80211_beacon_registration *reg, *tmp;
Jouni Malinen026331c2010-02-15 12:53:10 +020011661
11662 if (state != NETLINK_URELEASE)
11663 return NOTIFY_DONE;
11664
11665 rcu_read_lock();
11666
Johannes Berg5e760232011-11-04 11:18:17 +010011667 list_for_each_entry_rcu(rdev, &cfg80211_rdev_list, list) {
Johannes Berg78f22b62014-03-24 17:57:27 +010011668 bool schedule_destroy_work = false;
11669
11670 list_for_each_entry_rcu(wdev, &rdev->wdev_list, list) {
Eric W. Biederman15e47302012-09-07 20:12:54 +000011671 cfg80211_mlme_unregister_socket(wdev, notify->portid);
Ben Greear37c73b52012-10-26 14:49:25 -070011672
Johannes Berg78f22b62014-03-24 17:57:27 +010011673 if (wdev->owner_nlportid == notify->portid)
11674 schedule_destroy_work = true;
11675 }
11676
Ben Greear37c73b52012-10-26 14:49:25 -070011677 spin_lock_bh(&rdev->beacon_registrations_lock);
11678 list_for_each_entry_safe(reg, tmp, &rdev->beacon_registrations,
11679 list) {
11680 if (reg->nlportid == notify->portid) {
11681 list_del(&reg->list);
11682 kfree(reg);
11683 break;
11684 }
11685 }
11686 spin_unlock_bh(&rdev->beacon_registrations_lock);
Johannes Berg78f22b62014-03-24 17:57:27 +010011687
11688 if (schedule_destroy_work) {
11689 struct cfg80211_iface_destroy *destroy;
11690
11691 destroy = kzalloc(sizeof(*destroy), GFP_ATOMIC);
11692 if (destroy) {
11693 destroy->nlportid = notify->portid;
11694 spin_lock(&rdev->destroy_list_lock);
11695 list_add(&destroy->list, &rdev->destroy_list);
11696 spin_unlock(&rdev->destroy_list_lock);
11697 schedule_work(&rdev->destroy_work);
11698 }
11699 }
Johannes Berg5e760232011-11-04 11:18:17 +010011700 }
Jouni Malinen026331c2010-02-15 12:53:10 +020011701
11702 rcu_read_unlock();
11703
Zhao, Gang6784c7d2014-04-21 12:53:04 +080011704 return NOTIFY_OK;
Jouni Malinen026331c2010-02-15 12:53:10 +020011705}
11706
11707static struct notifier_block nl80211_netlink_notifier = {
11708 .notifier_call = nl80211_netlink_notify,
11709};
11710
Jouni Malinen355199e2013-02-27 17:14:27 +020011711void cfg80211_ft_event(struct net_device *netdev,
11712 struct cfg80211_ft_event_params *ft_event)
11713{
11714 struct wiphy *wiphy = netdev->ieee80211_ptr->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080011715 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Jouni Malinen355199e2013-02-27 17:14:27 +020011716 struct sk_buff *msg;
11717 void *hdr;
Jouni Malinen355199e2013-02-27 17:14:27 +020011718
11719 trace_cfg80211_ft_event(wiphy, netdev, ft_event);
11720
11721 if (!ft_event->target_ap)
11722 return;
11723
11724 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
11725 if (!msg)
11726 return;
11727
11728 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FT_EVENT);
Johannes Bergae917c92013-10-25 11:05:22 +020011729 if (!hdr)
11730 goto out;
Jouni Malinen355199e2013-02-27 17:14:27 +020011731
Johannes Bergae917c92013-10-25 11:05:22 +020011732 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
11733 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
11734 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, ft_event->target_ap))
11735 goto out;
11736
11737 if (ft_event->ies &&
11738 nla_put(msg, NL80211_ATTR_IE, ft_event->ies_len, ft_event->ies))
11739 goto out;
11740 if (ft_event->ric_ies &&
11741 nla_put(msg, NL80211_ATTR_IE_RIC, ft_event->ric_ies_len,
11742 ft_event->ric_ies))
11743 goto out;
Jouni Malinen355199e2013-02-27 17:14:27 +020011744
Johannes Berg9c90a9f2013-06-04 12:46:03 +020011745 genlmsg_end(msg, hdr);
Jouni Malinen355199e2013-02-27 17:14:27 +020011746
Johannes Berg68eb5502013-11-19 15:19:38 +010011747 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011748 NL80211_MCGRP_MLME, GFP_KERNEL);
Johannes Bergae917c92013-10-25 11:05:22 +020011749 return;
11750 out:
11751 nlmsg_free(msg);
Jouni Malinen355199e2013-02-27 17:14:27 +020011752}
11753EXPORT_SYMBOL(cfg80211_ft_event);
11754
Arend van Spriel5de17982013-04-18 15:49:00 +020011755void cfg80211_crit_proto_stopped(struct wireless_dev *wdev, gfp_t gfp)
11756{
11757 struct cfg80211_registered_device *rdev;
11758 struct sk_buff *msg;
11759 void *hdr;
11760 u32 nlportid;
11761
Zhao, Gangf26cbf42014-04-21 12:53:03 +080011762 rdev = wiphy_to_rdev(wdev->wiphy);
Arend van Spriel5de17982013-04-18 15:49:00 +020011763 if (!rdev->crit_proto_nlportid)
11764 return;
11765
11766 nlportid = rdev->crit_proto_nlportid;
11767 rdev->crit_proto_nlportid = 0;
11768
11769 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
11770 if (!msg)
11771 return;
11772
11773 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CRIT_PROTOCOL_STOP);
11774 if (!hdr)
11775 goto nla_put_failure;
11776
11777 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
11778 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)))
11779 goto nla_put_failure;
11780
11781 genlmsg_end(msg, hdr);
11782
11783 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid);
11784 return;
11785
11786 nla_put_failure:
11787 if (hdr)
11788 genlmsg_cancel(msg, hdr);
11789 nlmsg_free(msg);
11790
11791}
11792EXPORT_SYMBOL(cfg80211_crit_proto_stopped);
11793
Johannes Berg348baf02014-01-24 14:06:29 +010011794void nl80211_send_ap_stopped(struct wireless_dev *wdev)
11795{
11796 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080011797 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg348baf02014-01-24 14:06:29 +010011798 struct sk_buff *msg;
11799 void *hdr;
11800
11801 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
11802 if (!msg)
11803 return;
11804
11805 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_STOP_AP);
11806 if (!hdr)
11807 goto out;
11808
11809 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
11810 nla_put_u32(msg, NL80211_ATTR_IFINDEX, wdev->netdev->ifindex) ||
11811 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)))
11812 goto out;
11813
11814 genlmsg_end(msg, hdr);
11815
11816 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(wiphy), msg, 0,
11817 NL80211_MCGRP_MLME, GFP_KERNEL);
11818 return;
11819 out:
11820 nlmsg_free(msg);
11821}
11822
Johannes Berg55682962007-09-20 13:09:35 -040011823/* initialisation/exit functions */
11824
11825int nl80211_init(void)
11826{
Michał Mirosław0d63cbb2009-05-21 10:34:06 +000011827 int err;
Johannes Berg55682962007-09-20 13:09:35 -040011828
Johannes Berg2a94fe42013-11-19 15:19:39 +010011829 err = genl_register_family_with_ops_groups(&nl80211_fam, nl80211_ops,
11830 nl80211_mcgrps);
Johannes Berg55682962007-09-20 13:09:35 -040011831 if (err)
11832 return err;
11833
Jouni Malinen026331c2010-02-15 12:53:10 +020011834 err = netlink_register_notifier(&nl80211_netlink_notifier);
11835 if (err)
11836 goto err_out;
11837
Johannes Berg55682962007-09-20 13:09:35 -040011838 return 0;
11839 err_out:
11840 genl_unregister_family(&nl80211_fam);
11841 return err;
11842}
11843
11844void nl80211_exit(void)
11845{
Jouni Malinen026331c2010-02-15 12:53:10 +020011846 netlink_unregister_notifier(&nl80211_netlink_notifier);
Johannes Berg55682962007-09-20 13:09:35 -040011847 genl_unregister_family(&nl80211_fam);
11848}